diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-19 20:45:07 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-19 20:45:07 +0100 |
commit | 9943813f3779d2ede508a90dadd087fc0ad12f1f (patch) | |
tree | 9e0d2c1008ed540936ca9675152f6ba79ff4bd64 | |
parent | d5a8faa4d06d2664a7748ea570937751ef5271d5 (diff) | |
download | svg.js-9943813f3779d2ede508a90dadd087fc0ad12f1f.tar.gz svg.js-9943813f3779d2ede508a90dadd087fc0ad12f1f.zip |
renamed `Doc` to `Svg` according to (#932)
-rw-r--r-- | dist/svg.js | 233 | ||||
-rw-r--r-- | spec/spec/adopter.js | 4 | ||||
-rw-r--r-- | spec/spec/boxes.js | 2 | ||||
-rw-r--r-- | spec/spec/doc.js | 12 | ||||
-rw-r--r-- | spec/spec/element.js | 2 | ||||
-rw-r--r-- | spec/spec/svg.js | 16 | ||||
-rw-r--r-- | src/animation/Timeline.js | 19 | ||||
-rw-r--r-- | src/elements/Container.js | 2 | ||||
-rw-r--r-- | src/elements/Element.js | 4 | ||||
-rw-r--r-- | src/elements/Svg.js (renamed from src/elements/Doc.js) | 6 | ||||
-rw-r--r-- | src/main.js | 6 |
11 files changed, 152 insertions, 154 deletions
diff --git a/dist/svg.js b/dist/svg.js index 4cb967f..876caf0 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -6,7 +6,7 @@ * @copyright Wout Fierens <wout@mick-wout.com> * @license MIT * -* BUILT: Sat Nov 17 2018 10:54:31 GMT+0100 (GMT+01:00) +* BUILT: Mon Nov 19 2018 19:49:34 GMT+0100 (GMT+01:00) */; var SVG = (function () { 'use strict'; @@ -2589,7 +2589,7 @@ var SVG = (function () { }); register(Dom); - var Doc = getClass(root); + var Svg = getClass(root); var Element = /*#__PURE__*/ @@ -2643,7 +2643,7 @@ var SVG = (function () { }, { key: "doc", value: function doc() { - var p = this.parent(Doc); + var p = this.parent(Svg); return p && p.doc(); } }, { @@ -3125,7 +3125,7 @@ var SVG = (function () { this.each(function () { if (this instanceof Container) return this.flatten(parent).ungroup(parent); return this.toParent(parent); - }); // we need this so that Doc does not get removed + }); // we need this so that the root does not get removed this.node.firstElementChild || this.remove(); return this; @@ -3173,87 +3173,6 @@ var SVG = (function () { }(Container); register(Defs); - var Doc$1 = - /*#__PURE__*/ - function (_Container) { - _inherits(Doc, _Container); - - function Doc(node) { - var _this; - - _classCallCheck(this, Doc); - - _this = _possibleConstructorReturn(this, _getPrototypeOf(Doc).call(this, nodeOrNew('svg', node), node)); - - _this.namespace(); - - return _this; - } - - _createClass(Doc, [{ - key: "isRoot", - value: function isRoot() { - return !this.node.parentNode || !(this.node.parentNode instanceof globals.window.SVGElement) || this.node.parentNode.nodeName === '#document'; - } // Check if this is a root svg - // If not, call docs from this element - - }, { - key: "doc", - value: function doc() { - if (this.isRoot()) return this; - return _get(_getPrototypeOf(Doc.prototype), "doc", this).call(this); - } // Add namespaces - - }, { - key: "namespace", - value: function namespace() { - if (!this.isRoot()) return this.doc().namespace(); - return this.attr({ - xmlns: ns, - version: '1.1' - }).attr('xmlns:xlink', xlink, xmlns).attr('xmlns:svgjs', svgjs, xmlns); - } // Creates and returns defs element - - }, { - key: "defs", - value: function defs() { - if (!this.isRoot()) return this.doc().defs(); - return adopt(this.node.getElementsByTagName('defs')[0]) || this.put(new Defs()); - } // custom parent method - - }, { - key: "parent", - value: function parent(type) { - if (this.isRoot()) { - return this.node.parentNode.nodeName === '#document' ? null : adopt(this.node.parentNode); - } - - return _get(_getPrototypeOf(Doc.prototype), "parent", this).call(this, type); - } - }, { - key: "clear", - value: function clear() { - // remove children - while (this.node.hasChildNodes()) { - this.node.removeChild(this.node.lastChild); - } - - return this; - } - }]); - - return Doc; - }(Container); - registerMethods({ - Container: { - // Create nested svg document - nested: wrapWithAttrCheck(function () { - return this.put(new Doc$1()); - }) - } - }); - register(Doc$1, 'Doc', true); - var Ellipse = /*#__PURE__*/ function (_Shape) { @@ -5069,8 +4988,6 @@ var SVG = (function () { } }; - var time = globals.window.performance || Date; - var makeSchedule = function makeSchedule(runnerInfo) { var start = runnerInfo.start; var duration = runnerInfo.runner.duration(); @@ -5085,45 +5002,48 @@ var SVG = (function () { var Timeline = /*#__PURE__*/ - function () { + function (_EventTarget) { + _inherits(Timeline, _EventTarget); + // Construct a new timeline on the given element function Timeline() { + var _this; + _classCallCheck(this, Timeline); - this._timeSource = function () { - return time.now(); - }; + _this = _possibleConstructorReturn(this, _getPrototypeOf(Timeline).call(this)); - this._dispatcher = globals.document.createElement('div'); // Store the timing variables + _this._timeSource = function () { + var w = globals.window; + return (w.performance || w.Date).now(); + }; // Store the timing variables - this._startTime = 0; - this._speed = 1.0; // Play control variables control how the animation proceeds - this._reverse = false; - this._persist = 0; // Keep track of the running animations and their starting parameters + _this._startTime = 0; + _this._speed = 1.0; // Play control variables control how the animation proceeds - this._nextFrame = null; - this._paused = false; - this._runners = []; - this._order = []; - this._time = 0; - this._lastSourceTime = 0; - this._lastStepTime = 0; + _this._reverse = false; + _this._persist = 0; // Keep track of the running animations and their starting parameters + + _this._nextFrame = null; + _this._paused = false; + _this._runners = []; + _this._order = []; + _this._time = 0; + _this._lastSourceTime = 0; + _this._lastStepTime = 0; + return _this; } + /** + * + */ + // schedules a runner on the timeline - _createClass(Timeline, [{ - key: "getEventTarget", - value: function getEventTarget() { - return this._dispatcher; - } - /** - * - */ - // schedules a runner on the timeline - }, { + _createClass(Timeline, [{ key: "schedule", value: function schedule(runner, delay, when) { + // FIXME: how to sort? maybe by runner id? if (runner == null) { return this._runners.map(makeSchedule).sort(function (a, b) { return a.start - b.start || a.duration - b.duration; @@ -5351,7 +5271,7 @@ var SVG = (function () { }]); return Timeline; - }(); + }(EventTarget); registerMethods({ Element: { timeline: function timeline() { @@ -6290,6 +6210,87 @@ var SVG = (function () { to: to }); + var Svg$1 = + /*#__PURE__*/ + function (_Container) { + _inherits(Svg, _Container); + + function Svg(node) { + var _this; + + _classCallCheck(this, Svg); + + _this = _possibleConstructorReturn(this, _getPrototypeOf(Svg).call(this, nodeOrNew('svg', node), node)); + + _this.namespace(); + + return _this; + } + + _createClass(Svg, [{ + key: "isRoot", + value: function isRoot() { + return !this.node.parentNode || !(this.node.parentNode instanceof globals.window.SVGElement) || this.node.parentNode.nodeName === '#document'; + } // Check if this is a root svg + // If not, call docs from this element + + }, { + key: "doc", + value: function doc() { + if (this.isRoot()) return this; + return _get(_getPrototypeOf(Svg.prototype), "doc", this).call(this); + } // Add namespaces + + }, { + key: "namespace", + value: function namespace() { + if (!this.isRoot()) return this.doc().namespace(); + return this.attr({ + xmlns: ns, + version: '1.1' + }).attr('xmlns:xlink', xlink, xmlns).attr('xmlns:svgjs', svgjs, xmlns); + } // Creates and returns defs element + + }, { + key: "defs", + value: function defs() { + if (!this.isRoot()) return this.doc().defs(); + return adopt(this.node.getElementsByTagName('defs')[0]) || this.put(new Defs()); + } // custom parent method + + }, { + key: "parent", + value: function parent(type) { + if (this.isRoot()) { + return this.node.parentNode.nodeName === '#document' ? null : adopt(this.node.parentNode); + } + + return _get(_getPrototypeOf(Svg.prototype), "parent", this).call(this, type); + } + }, { + key: "clear", + value: function clear() { + // remove children + while (this.node.hasChildNodes()) { + this.node.removeChild(this.node.lastChild); + } + + return this; + } + }]); + + return Svg; + }(Container); + registerMethods({ + Container: { + // Create nested svg document + nested: wrapWithAttrCheck(function () { + return this.put(new Svg$1()); + }) + } + }); + register(Svg$1, 'Svg', true); + function plain(text) { // clear if build mode is disabled if (this._build === false) { @@ -7001,7 +7002,7 @@ var SVG = (function () { register(Use); /* Optional Modules */ - extend([Doc$1, Symbol, Image, Pattern, Marker], getMethodsFor('viewbox')); + extend([Svg$1, Symbol, Image, Pattern, Marker], getMethodsFor('viewbox')); extend([Line, Polyline, Polygon, Path], getMethodsFor('marker')); extend(Text, getMethodsFor('Text')); extend(Path, getMethodsFor('Path')); @@ -7054,7 +7055,6 @@ var SVG = (function () { ClipPath: ClipPath, Container: Container, Defs: Defs, - Doc: Doc$1, Dom: Dom, Element: Element, Ellipse: Ellipse, @@ -7074,6 +7074,7 @@ var SVG = (function () { Shape: Shape, Stop: Stop, Style: Style, + Svg: Svg$1, Symbol: _Symbol, Text: Text, TextPath: TextPath, diff --git a/spec/spec/adopter.js b/spec/spec/adopter.js index 90e0411..38d55f4 100644 --- a/spec/spec/adopter.js +++ b/spec/spec/adopter.js @@ -9,9 +9,9 @@ describe('Adopter', function() { radialGradient = SVG('#inlineSVG').find('radialGradient')[0] }) - describe('with SVG.Doc instance', function() { + describe('with SVG.Svg instance', function() { it('adopts the main svg document when parent() method is called on first level children', function() { - expect(path.parent() instanceof SVG.Doc).toBeTruthy() + expect(path.parent() instanceof SVG.Svg).toBeTruthy() }) it('defines a xmlns attribute', function() { expect(path.parent().node.getAttribute('xmlns')).toBe(SVG.ns) diff --git a/spec/spec/boxes.js b/spec/spec/boxes.js index 2fcbd8b..d5581b2 100644 --- a/spec/spec/boxes.js +++ b/spec/spec/boxes.js @@ -182,7 +182,7 @@ describe('Boxes', function() { }) - it('returns the elements box in coordinates of given element (doc)', function() { + it('returns the elements box in coordinates of given element (root)', function() { var box = rect.rbox(draw) expect(window.roundBox(box)).toEqual(jasmine.objectContaining({ diff --git a/spec/spec/doc.js b/spec/spec/doc.js index f82f1cb..a875906 100644 --- a/spec/spec/doc.js +++ b/spec/spec/doc.js @@ -1,4 +1,4 @@ -describe('Doc', function() { +describe('Svg', function() { describe('create()', function(){ it('doenst alter size when adopting width SVG()', function() { @@ -12,11 +12,11 @@ describe('Doc', function() { expect(draw instanceof SVG.Container).toBe(true) }) - it('is an instance of SVG.Doc', function() { - expect(draw instanceof SVG.Doc).toBe(true) + it('is an instance of SVG.Svg', function() { + expect(draw instanceof SVG.Svg).toBe(true) }) - it('returns itself as Doc when root', function() { + it('returns itself as Svg when root', function() { expect(draw.doc()).toBe(draw) }) @@ -34,7 +34,7 @@ describe('Doc', function() { }) describe('isRoot()', function() { - it('returns true when the doc is not attached to dom', function() { + it('returns true when the Svg is not attached to dom', function() { expect(SVG().isRoot()).toBe(true) }) it('returns true when its outer element is not an svg element', function () { @@ -49,7 +49,7 @@ describe('Doc', function() { }) describe('remove()', function() { - it('removes the doc from the dom only if doc is not root element', function() { + it('removes the Svg from the dom only if Svg is not root element', function() { var cnt = window.document.querySelectorAll('svg').length draw.remove() if(parserInDoc){ diff --git a/spec/spec/element.js b/spec/spec/element.js index 9afedc6..96d512b 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -633,7 +633,7 @@ describe('Element', function() { it('contains the parent which matches type', function() { var group = draw.group() , rect = group.rect(100,100) - expect(rect.parent(SVG.Doc)).toBe(draw) + expect(rect.parent(SVG.Svg)).toBe(draw) }) it('contains the parent which matches selector', function() { var group1 = draw.group().addClass('test') diff --git a/spec/spec/svg.js b/spec/spec/svg.js index 6acbda4..acdd686 100644 --- a/spec/spec/svg.js +++ b/spec/spec/svg.js @@ -18,8 +18,8 @@ describe('SVG', function() { wrapperHTML.parentNode.removeChild(wrapperHTML) }) - it('creates an instanceof SVG.Doc without any argument', function() { - expect(SVG() instanceof SVG.Doc).toBe(true) + it('creates an instanceof SVG.Svg without any argument', function() { + expect(SVG() instanceof SVG.Svg).toBe(true) expect(SVG().node.nodeName).toBe('svg') }) @@ -35,15 +35,15 @@ describe('SVG', function() { expect(el.node).toBe(wrapperHTML) }) - it('creates an instanceof SVG.Doc with svg node', function() { + it('creates an instanceof SVG.Svg with svg node', function() { var doc = SVG(wrapper) - expect(doc instanceof SVG.Doc).toBe(true) + expect(doc instanceof SVG.Svg).toBe(true) expect(doc.node).toBe(wrapper) }) - it('creates new SVG.Doc when called with css selector pointing to svg node', function() { + it('creates new SVG.Svg when called with css selector pointing to svg node', function() { var doc = SVG('#testSvg') - expect(doc instanceof SVG.Doc).toBe(true) + expect(doc instanceof SVG.Svg).toBe(true) expect(doc.node).toBe(wrapper) }) @@ -52,10 +52,10 @@ describe('SVG', function() { expect(SVG(rect).node).toBe(rect) }) - it('creates an instanceof SVG.Doc when importing a whole svg', function() { + it('creates an instanceof SVG.Svg when importing a whole svg', function() { var doc = SVG('<svg width="200"><rect></rect></svg>') - expect(doc instanceof SVG.Doc).toBe(true) + expect(doc instanceof SVG.Svg).toBe(true) expect(doc.node.nodeName).toBe('svg') expect(doc.width()).toBe(200) expect(doc.get(0).node.nodeName).toBe('rect') diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js index f1d540a..6abcb80 100644 --- a/src/animation/Timeline.js +++ b/src/animation/Timeline.js @@ -1,8 +1,7 @@ +import { globals } from '../utils/window.js' import { registerMethods } from '../utils/methods.js' import Animator from './Animator.js' -import { globals } from '../utils/window.js' - -var time = globals.window.performance || Date +import EventTarget from '../types/EventTarget.js' var makeSchedule = function (runnerInfo) { var start = runnerInfo.start @@ -11,15 +10,16 @@ var makeSchedule = function (runnerInfo) { return { start: start, duration: duration, end: end, runner: runnerInfo.runner } } -export default class Timeline { +export default class Timeline extends EventTarget { // Construct a new timeline on the given element constructor () { + super() + this._timeSource = function () { - return time.now() + let w = globals.window + return (w.performance || w.Date).now() } - this._dispatcher = globals.document.createElement('div') - // Store the timing variables this._startTime = 0 this._speed = 1.0 @@ -38,16 +38,13 @@ export default class Timeline { this._lastStepTime = 0 } - getEventTarget () { - return this._dispatcher - } - /** * */ // schedules a runner on the timeline schedule (runner, delay, when) { + // FIXME: how to sort? maybe by runner id? if (runner == null) { return this._runners.map(makeSchedule).sort(function (a, b) { return (a.start - b.start) || (a.duration - b.duration) diff --git a/src/elements/Container.js b/src/elements/Container.js index 9415341..b47972e 100644 --- a/src/elements/Container.js +++ b/src/elements/Container.js @@ -8,7 +8,7 @@ export default class Container extends Element { return this.toParent(parent) }) - // we need this so that Doc does not get removed + // we need this so that the root does not get removed this.node.firstElementChild || this.remove() return this diff --git a/src/elements/Element.js b/src/elements/Element.js index 456ddad..1f208c5 100644 --- a/src/elements/Element.js +++ b/src/elements/Element.js @@ -15,7 +15,7 @@ import Dom from './Dom.js' import List from '../types/List.js' import SVGNumber from '../types/SVGNumber.js' -const Doc = getClass(root) +const Svg = getClass(root) export default class Element extends Dom { constructor (node, attrs) { @@ -57,7 +57,7 @@ export default class Element extends Dom { // Get parent document doc () { - let p = this.parent(Doc) + let p = this.parent(Svg) return p && p.doc() } diff --git a/src/elements/Doc.js b/src/elements/Svg.js index d56fae3..e634c6a 100644 --- a/src/elements/Doc.js +++ b/src/elements/Svg.js @@ -10,7 +10,7 @@ import Container from './Container.js' import Defs from './Defs.js' import { globals } from '../utils/window.js' -export default class Doc extends Container { +export default class Svg extends Container { constructor (node) { super(nodeOrNew('svg', node), node) this.namespace() @@ -70,9 +70,9 @@ registerMethods({ Container: { // Create nested svg document nested: wrapWithAttrCheck(function () { - return this.put(new Doc()) + return this.put(new Svg()) }) } }) -register(Doc, 'Doc', true) +register(Svg, 'Svg', true) diff --git a/src/main.js b/src/main.js index 701b23b..919fb25 100644 --- a/src/main.js +++ b/src/main.js @@ -14,7 +14,6 @@ import Circle from './elements/Circle.js' import Color from './types/Color.js' import Container from './elements/Container.js' import Defs from './elements/Defs.js' -import Doc from './elements/Doc.js' import Dom from './elements/Dom.js' import Element from './elements/Element.js' import Ellipse from './elements/Ellipse.js' @@ -43,6 +42,7 @@ import Runner from './animation/Runner.js' import SVGArray from './types/SVGArray.js' import SVGNumber from './types/SVGNumber.js' import Shape from './elements/Shape.js' +import Svg from './elements/Svg.js' import Text from './elements/Text.js' import Tspan from './elements/Tspan.js' import * as defaults from './modules/core/defaults.js' @@ -90,7 +90,6 @@ export { default as Circle } from './elements/Circle.js' export { default as ClipPath } from './elements/ClipPath.js' export { default as Container } from './elements/Container.js' export { default as Defs } from './elements/Defs.js' -export { default as Doc } from './elements/Doc.js' export { default as Dom } from './elements/Dom.js' export { default as Element } from './elements/Element.js' export { default as Ellipse } from './elements/Ellipse.js' @@ -110,6 +109,7 @@ export { default as Rect } from './elements/Rect.js' export { default as Shape } from './elements/Shape.js' export { default as Stop } from './elements/Stop.js' export { default as Style } from './elements/Style.js' +export { default as Svg } from './elements/Svg.js' export { default as Symbol } from './elements/Symbol.js' export { default as Text } from './elements/Text.js' export { default as TextPath } from './elements/TextPath.js' @@ -117,7 +117,7 @@ export { default as Tspan } from './elements/Tspan.js' export { default as Use } from './elements/Use.js' extend([ - Doc, + Svg, Symbol, Image, Pattern, |