From: Ulrich-Matthias Schäfer Date: Sun, 4 Nov 2018 16:04:11 +0000 (+0100) Subject: fix even more tests X-Git-Tag: 3.0.0~56^2~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d22dce113a4a61d76b3c0e7c7fb77231f575c6fd;p=svg.js.git fix even more tests --- diff --git a/dist/svg.js b/dist/svg.js index d8edd95..82efb01 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -301,6 +301,10 @@ var SVG = (function () { return c + d.replace(dots, ' .'); } // creates deep clone of array + function matcher(el, selector) { + return (el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(el, selector); + } // Convert dash-separated-string to camelCase + function camelCase(s) { return s.toLowerCase().replace(/-(.)/g, function (m, g) { return g.toUpperCase(); @@ -320,7 +324,7 @@ var SVG = (function () { return hex$$1.length === 1 ? '0' + hex$$1 : hex$$1; } // Calculate proportional width and height values when necessary - function proportionalSize$1(element, width, height) { + function proportionalSize(element, width, height) { if (width == null || height == null) { var box = element.bbox(); @@ -446,25 +450,25 @@ var SVG = (function () { } // Default namespaces - var ns$1 = 'http://www.w3.org/2000/svg'; + var ns = 'http://www.w3.org/2000/svg'; var xmlns = 'http://www.w3.org/2000/xmlns/'; var xlink = 'http://www.w3.org/1999/xlink'; var svgjs = 'http://svgjs.com/svgjs'; - var ns$2 = /*#__PURE__*/Object.freeze({ - ns: ns$1, + var ns$1 = /*#__PURE__*/Object.freeze({ + ns: ns, xmlns: xmlns, xlink: xlink, svgjs: svgjs }); - function nodeOrNew$1(name, node) { + function nodeOrNew(name, node) { return node || makeNode(name); } // Method for element creation function makeNode(name) { // create element - return document.createElementNS(ns$1, name); + return document.createElementNS(ns, name); } // Method for extending objects function extend(modules, methods) { @@ -522,7 +526,7 @@ var SVG = (function () { } var tools = /*#__PURE__*/Object.freeze({ - nodeOrNew: nodeOrNew$1, + nodeOrNew: nodeOrNew, makeNode: makeNode, extend: extend, extend2: extend2, @@ -536,7 +540,7 @@ var SVG = (function () { if (element instanceof Base) return element; if (_typeof(element) === 'object') { - return adopt$1(element); + return adopt(element); } if (element == null) { @@ -544,18 +548,18 @@ var SVG = (function () { } if (typeof element === 'string' && element.charAt(0) !== '<') { - return adopt$1(document.querySelector(element)); + return adopt(document.querySelector(element)); } var node = makeNode('svg'); node.innerHTML = element; // We can use firstChild here because we know, // that the first char is < and thus an element - element = adopt$1(node.firstChild); + element = adopt(node.firstChild); return element; } // Adopt existing svg elements - function adopt$1(node) { + function adopt(node) { // check for presence of node if (!node) return null; // make sure a node isn't already adopted @@ -604,16 +608,16 @@ var SVG = (function () { } if (node.id) { - return adopt$1(node).id(eid(node.nodeName)); + return adopt(node).id(eid(node.nodeName)); } - return adopt$1(node); + return adopt(node); } var adopter = /*#__PURE__*/Object.freeze({ root: root, makeInstance: makeInstance, - adopt: adopt$1, + adopt: adopt, register: register, getClass: getClass, eid: eid, @@ -671,7 +675,7 @@ var SVG = (function () { function Defs(node) { _classCallCheck(this, Defs); - return _possibleConstructorReturn(this, _getPrototypeOf(Defs).call(this, nodeOrNew$1('defs', node), Defs)); + return _possibleConstructorReturn(this, _getPrototypeOf(Defs).call(this, nodeOrNew('defs', node), Defs)); } _createClass(Defs, [{ @@ -849,6 +853,7 @@ var SVG = (function () { }(); var Doc = getClass(root); + var HtmlNode$1 = getClass('HtmlNode'); function setup(node) { // initialize data object this.dom = {}; // create circular reference @@ -896,7 +901,7 @@ var SVG = (function () { } // Set element size to given width and height function size(width, height) { - var p = proportionalSize$1(this, width, height); + var p = proportionalSize(this, width, height); return this.width(new SVGNumber(p.width)).height(new SVGNumber(p.height)); } // Clone element @@ -993,12 +998,12 @@ var SVG = (function () { if (!parent.node.parentNode) return null; // get parent element - parent = adopt$1(parent.node.parentNode); + parent = adopt(parent.node.parentNode); if (!type) return parent; // loop trough ancestors if type is given while (parent && parent.node instanceof window.SVGElement) { if (typeof type === 'string' ? parent.matches(type) : parent instanceof type) return parent; - parent = adopt$1(parent.node.parentNode); + parent = adopt(parent.node.parentNode); } } // Get parent document @@ -1017,7 +1022,7 @@ var SVG = (function () { do { parent = parent.parent(type); - if (!parent || !parent.node) break; + if (!parent || parent instanceof HtmlNode$1) break; parents.push(parent); } while (parent.parent); @@ -1025,7 +1030,7 @@ var SVG = (function () { } // matches the element vs a css selector function matches(selector) { - return matches(this.node, selector); + return matcher(this.node, selector); } // Returns the svg node to call native svg methods on it function native() { @@ -1103,7 +1108,7 @@ var SVG = (function () { _classCallCheck(this, Doc); - _this = _possibleConstructorReturn(this, _getPrototypeOf(Doc).call(this, nodeOrNew$1('svg', node), Doc)); + _this = _possibleConstructorReturn(this, _getPrototypeOf(Doc).call(this, nodeOrNew('svg', node), Doc)); _this.namespace(); @@ -1129,7 +1134,7 @@ var SVG = (function () { value: function namespace() { if (!this.isRoot()) return this.doc().namespace(); return this.attr({ - xmlns: ns$1, + xmlns: ns, version: '1.1' }).attr('xmlns:xlink', xlink, xmlns).attr('xmlns:svgjs', svgjs, xmlns); } // Creates and returns defs element @@ -1138,14 +1143,14 @@ var SVG = (function () { key: "defs", value: function defs$$1() { if (!this.isRoot()) return this.doc().defs(); - return adopt$1(this.node.getElementsByTagName('defs')[0]) || this.put(new Defs()); + return adopt(this.node.getElementsByTagName('defs')[0]) || this.put(new Defs()); } // custom parent method }, { key: "parent", value: function parent$$1(type) { if (this.isRoot()) { - return this.node.parentNode.nodeName === '#document' ? null : adopt$1(this.node.parentNode); + return this.node.parentNode.nodeName === '#document' ? null : adopt(this.node.parentNode); } return parent.call(this, type); @@ -1196,7 +1201,7 @@ var SVG = (function () { function G(node) { _classCallCheck(this, G); - return _possibleConstructorReturn(this, _getPrototypeOf(G).call(this, nodeOrNew$1('g', node), G)); + return _possibleConstructorReturn(this, _getPrototypeOf(G).call(this, nodeOrNew('g', node), G)); } return G; @@ -1373,7 +1378,7 @@ var SVG = (function () { _classCallCheck(this, Bare); - return _possibleConstructorReturn(this, _getPrototypeOf(Bare).call(this, nodeOrNew$1(node, typeof node === 'string' ? null : node), Bare)); //extend(this, inherit) + return _possibleConstructorReturn(this, _getPrototypeOf(Bare).call(this, nodeOrNew(node, typeof node === 'string' ? null : node), Bare)); //extend(this, inherit) } _createClass(Bare, [{ @@ -1435,7 +1440,7 @@ var SVG = (function () { } // Custom size function function size$1(width, height) { - var p = proportionalSize$1(this, width, height); + var p = proportionalSize(this, width, height); return this.rx(new SVGNumber(p.width).divide(2)).ry(new SVGNumber(p.height).divide(2)); } @@ -1459,7 +1464,7 @@ var SVG = (function () { function Circle(node) { _classCallCheck(this, Circle); - return _possibleConstructorReturn(this, _getPrototypeOf(Circle).call(this, nodeOrNew$1('circle', node), Circle)); + return _possibleConstructorReturn(this, _getPrototypeOf(Circle).call(this, nodeOrNew('circle', node), Circle)); } _createClass(Circle, [{ @@ -1574,7 +1579,7 @@ var SVG = (function () { function baseFind(query, parent) { return map((parent || document).querySelectorAll(query), function (node) { - return adopt$1(node); + return adopt(node); }); } // Scoped find method @@ -1593,7 +1598,7 @@ var SVG = (function () { function ClipPath(node) { _classCallCheck(this, ClipPath); - return _possibleConstructorReturn(this, _getPrototypeOf(ClipPath).call(this, nodeOrNew$1('clipPath', node), ClipPath)); + return _possibleConstructorReturn(this, _getPrototypeOf(ClipPath).call(this, nodeOrNew('clipPath', node), ClipPath)); } // Unclip all clipped elements and remove itself @@ -1650,7 +1655,7 @@ var SVG = (function () { function A(node) { _classCallCheck(this, A); - return _possibleConstructorReturn(this, _getPrototypeOf(A).call(this, nodeOrNew$1('a', node), A)); + return _possibleConstructorReturn(this, _getPrototypeOf(A).call(this, nodeOrNew('a', node), A)); } // Link url @@ -1701,7 +1706,7 @@ var SVG = (function () { function Ellipse(node) { _classCallCheck(this, Ellipse); - return _possibleConstructorReturn(this, _getPrototypeOf(Ellipse).call(this, nodeOrNew$1('ellipse', node), Ellipse)); + return _possibleConstructorReturn(this, _getPrototypeOf(Ellipse).call(this, nodeOrNew('ellipse', node), Ellipse)); } return Ellipse; @@ -1723,7 +1728,7 @@ var SVG = (function () { function Stop(node) { _classCallCheck(this, Stop); - return _possibleConstructorReturn(this, _getPrototypeOf(Stop).call(this, nodeOrNew$1('stop', node), Stop)); + return _possibleConstructorReturn(this, _getPrototypeOf(Stop).call(this, nodeOrNew('stop', node), Stop)); } // add color stops @@ -2033,7 +2038,7 @@ var SVG = (function () { try { for (var _iterator = val[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var node = _step.value; - attr[node.nodeName] = isNumer.test(node.nodeValue) ? parseFloat(node.nodeValue) : node.nodeValue; + attr[node.nodeName] = isNumber.test(node.nodeValue) ? parseFloat(node.nodeValue) : node.nodeValue; } } catch (err) { _didIteratorError = true; @@ -2120,7 +2125,7 @@ var SVG = (function () { function Gradient(type) { _classCallCheck(this, Gradient); - return _possibleConstructorReturn(this, _getPrototypeOf(Gradient).call(this, nodeOrNew$1(type + 'Gradient', typeof type === 'string' ? null : type), Gradient)); + return _possibleConstructorReturn(this, _getPrototypeOf(Gradient).call(this, nodeOrNew(type + 'Gradient', typeof type === 'string' ? null : type), Gradient)); } // Add a color stop @@ -2196,7 +2201,7 @@ var SVG = (function () { function Pattern(node) { _classCallCheck(this, Pattern); - return _possibleConstructorReturn(this, _getPrototypeOf(Pattern).call(this, nodeOrNew$1('pattern', node), Pattern)); + return _possibleConstructorReturn(this, _getPrototypeOf(Pattern).call(this, nodeOrNew('pattern', node), Pattern)); } // Return the fill id @@ -2261,31 +2266,22 @@ var SVG = (function () { }); register(Pattern); - // ;[ 'click', - // 'dblclick', - // 'mousedown', - // 'mouseup', - // 'mouseover', - // 'mouseout', - // 'mousemove', - // 'mouseenter', - // 'mouseleave', - // 'touchstart', - // 'touchmove', - // 'touchleave', - // 'touchend', - // 'touchcancel' ].forEach(function (event) { - // // add event to Element - // Element.prototype[event] = function (f) { - // if (f === null) { - // off(this, event) - // } else { - // on(this, event, f) - // } - // return this - // } - // }) + var methods$1 = ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove', 'mouseenter', 'mouseleave', 'touchstart', 'touchmove', 'touchleave', 'touchend', 'touchcancel'].reduce(function (last, event) { + // add event to Element + var fn = function fn(f) { + if (f === null) { + off(this, event); + } else { + on(this, event, f); + } + + return this; + }; + last[event] = fn; + return last; + }, {}); + registerMethods('Element', methods$1); var listenerId = 0; function getEventTarget$1(node) { @@ -2401,6 +2397,12 @@ var SVG = (function () { return event; } + var events = /*#__PURE__*/Object.freeze({ + on: on, + off: off, + dispatch: dispatch + }); + var Image = /*#__PURE__*/ function (_Base) { @@ -2409,7 +2411,7 @@ var SVG = (function () { function Image(node) { _classCallCheck(this, Image); - return _possibleConstructorReturn(this, _getPrototypeOf(Image).call(this, nodeOrNew$1('image', node), Image)); + return _possibleConstructorReturn(this, _getPrototypeOf(Image).call(this, nodeOrNew('image', node), Image)); } // (re)load image @@ -2706,7 +2708,7 @@ var SVG = (function () { function Line(node) { _classCallCheck(this, Line); - return _possibleConstructorReturn(this, _getPrototypeOf(Line).call(this, nodeOrNew$1('line', node), Line)); + return _possibleConstructorReturn(this, _getPrototypeOf(Line).call(this, nodeOrNew('line', node), Line)); } // Get array @@ -2744,7 +2746,7 @@ var SVG = (function () { }, { key: "size", value: function size(width, height) { - var p = proportionalSize$1(this, width, height); + var p = proportionalSize(this, width, height); return this.attr(this.array().size(p.width, p.height).toLine()); } }]); @@ -2858,7 +2860,7 @@ var SVG = (function () { function Mask(node) { _classCallCheck(this, Mask); - return _possibleConstructorReturn(this, _getPrototypeOf(Mask).call(this, nodeOrNew$1('mask', node), Mask)); + return _possibleConstructorReturn(this, _getPrototypeOf(Mask).call(this, nodeOrNew('mask', node), Mask)); } // Unmask all masked elements and remove itself @@ -2931,7 +2933,7 @@ var SVG = (function () { return parser.nodes; } - var Point$1 = + var Point = /*#__PURE__*/ function () { // Initialize @@ -2970,7 +2972,7 @@ var SVG = (function () { key: "native", value: function native() { // create new point - var point = parser().svg.createSVGPoint(); // update with current values + var point = parser().svg.node.createSVGPoint(); // update with current values point.x = this.x; point.y = this.y; @@ -2994,7 +2996,7 @@ var SVG = (function () { Element: { // Get point point: function point(x, y) { - return new Point$1(x, y).transform(this.screenCTM().inverse()); + return new Point(x, y).transform(this.screenCTM().inverse()); } } }); @@ -3241,8 +3243,8 @@ var SVG = (function () { var result = []; - var p = new Point$1(); - var p0 = new Point$1(); + var p = new Point(); + var p0 = new Point(); var index = 0; var len = array.length; @@ -3493,7 +3495,7 @@ var SVG = (function () { function Path(node) { _classCallCheck(this, Path); - return _possibleConstructorReturn(this, _getPrototypeOf(Path).call(this, nodeOrNew$1('path', node), Path)); + return _possibleConstructorReturn(this, _getPrototypeOf(Path).call(this, nodeOrNew('path', node), Path)); } // Get array @@ -3537,7 +3539,7 @@ var SVG = (function () { }, { key: "size", value: function size(width, height) { - var p = proportionalSize$1(this, width, height); + var p = proportionalSize(this, width, height); return this.attr('d', this.array().size(p.width, p.height)); } // Set width of element @@ -3643,7 +3645,7 @@ var SVG = (function () { function Polygon(node) { _classCallCheck(this, Polygon); - return _possibleConstructorReturn(this, _getPrototypeOf(Polygon).call(this, nodeOrNew$1('polygon', node), Polygon)); + return _possibleConstructorReturn(this, _getPrototypeOf(Polygon).call(this, nodeOrNew('polygon', node), Polygon)); } return Polygon; @@ -3670,7 +3672,7 @@ var SVG = (function () { function Polyline(node) { _classCallCheck(this, Polyline); - return _possibleConstructorReturn(this, _getPrototypeOf(Polyline).call(this, nodeOrNew$1('polyline', node), Polyline)); + return _possibleConstructorReturn(this, _getPrototypeOf(Polyline).call(this, nodeOrNew('polyline', node), Polyline)); } return Polyline; @@ -3697,7 +3699,7 @@ var SVG = (function () { function Rect(node) { _classCallCheck(this, Rect); - return _possibleConstructorReturn(this, _getPrototypeOf(Rect).call(this, nodeOrNew$1('rect', node), Rect)); + return _possibleConstructorReturn(this, _getPrototypeOf(Rect).call(this, nodeOrNew('rect', node), Rect)); } return Rect; @@ -3721,7 +3723,7 @@ var SVG = (function () { function _Symbol(node) { _classCallCheck(this, _Symbol); - return _possibleConstructorReturn(this, _getPrototypeOf(_Symbol).call(this, nodeOrNew$1('symbol', node), _Symbol)); + return _possibleConstructorReturn(this, _getPrototypeOf(_Symbol).call(this, nodeOrNew('symbol', node), _Symbol)); } return _Symbol; @@ -3768,7 +3770,7 @@ var SVG = (function () { _classCallCheck(this, Text); - _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).call(this, nodeOrNew$1('text', node), Text)); + _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).call(this, nodeOrNew('text', node), Text)); _this.dom.leading = new SVGNumber(1.3); // store leading value for rebuilding _this._rebuild = true; // enable automatic updating of dy values @@ -3823,6 +3825,7 @@ var SVG = (function () { value: function text(_text) { // act as getter if (_text === undefined) { + // FIXME use children() or each() var children = this.node.childNodes; var firstLine = 0; _text = ''; @@ -3951,7 +3954,7 @@ var SVG = (function () { function TextPath(node) { _classCallCheck(this, TextPath); - return _possibleConstructorReturn(this, _getPrototypeOf(TextPath).call(this, nodeOrNew$1('textPath', node), TextPath)); + return _possibleConstructorReturn(this, _getPrototypeOf(TextPath).call(this, nodeOrNew('textPath', node), TextPath)); } // return the array of the path track element @@ -4008,7 +4011,7 @@ var SVG = (function () { // FIXME: make this plural? // Get the textPath children textPath: function textPath() { - return this.select('textPath'); + return this.find('textPath'); } }, Path: { @@ -4037,7 +4040,7 @@ var SVG = (function () { function Tspan(node) { _classCallCheck(this, Tspan); - return _possibleConstructorReturn(this, _getPrototypeOf(Tspan).call(this, nodeOrNew$1('tspan', node), Tspan)); + return _possibleConstructorReturn(this, _getPrototypeOf(Tspan).call(this, nodeOrNew('tspan', node), Tspan)); } // Set text content @@ -4101,7 +4104,7 @@ var SVG = (function () { function Use(node) { _classCallCheck(this, Use); - return _possibleConstructorReturn(this, _getPrototypeOf(Use).call(this, nodeOrNew$1('use', node), Use)); + return _possibleConstructorReturn(this, _getPrototypeOf(Use).call(this, nodeOrNew('use', node), Use)); } // Use element as a reference @@ -4125,7 +4128,7 @@ var SVG = (function () { }); register(Use); - var Matrix$1 = + var Matrix = /*#__PURE__*/ function () { function Matrix() { @@ -4169,7 +4172,7 @@ var SVG = (function () { var t = Matrix.formatTransforms(o); var current = this; - var _transform = new Point$1(t.ox, t.oy).transform(current), + var _transform = new Point(t.ox, t.oy).transform(current), ox = _transform.x, oy = _transform.y; // Construct the resulting matrix @@ -4177,7 +4180,7 @@ var SVG = (function () { var transformer = new Matrix().translateO(t.rx, t.ry).lmultiplyO(current).translateO(-ox, -oy).scaleO(t.scaleX, t.scaleY).skewO(t.skewX, t.skewY).shearO(t.shear).rotateO(t.theta).translateO(ox, oy); // If we want the origin at a particular place, we force it there if (isFinite(t.px) || isFinite(t.py)) { - var origin = new Point$1(ox, oy).transform(transformer); // TODO: Replace t.px with isFinite(t.px) + var origin = new Point(ox, oy).transform(transformer); // TODO: Replace t.px with isFinite(t.px) var dx = t.px ? t.px - origin.x : 0; var dy = t.py ? t.py - origin.y : 0; @@ -4513,7 +4516,7 @@ var SVG = (function () { key: "native", value: function native() { // create new matrix - var matrix = parser().node.createSVGMatrix(); // update with current values + var matrix = parser().svg.node.createSVGMatrix(); // update with current values for (var i = abcdef.length - 1; i >= 0; i--) { matrix[abcdef[i]] = this[abcdef[i]]; @@ -4565,16 +4568,16 @@ var SVG = (function () { var scaleY = o.scale && o.scale.length ? o.scale[1] * flipY : isFinite(o.scale) ? o.scale * flipY : isFinite(o.scaleY) ? o.scaleY * flipY : flipY; var shear = o.shear || 0; var theta = o.rotate || o.theta || 0; - var origin = new Point$1(o.origin || o.around || o.ox || o.originX, o.oy || o.originY); + var origin = new Point(o.origin || o.around || o.ox || o.originX, o.oy || o.originY); var ox = origin.x; var oy = origin.y; - var position = new Point$1(o.position || o.px || o.positionX, o.py || o.positionY); + var position = new Point(o.position || o.px || o.positionX, o.py || o.positionY); var px = position.x; var py = position.y; - var translate = new Point$1(o.translate || o.tx || o.translateX, o.ty || o.translateY); + var translate = new Point(o.translate || o.tx || o.translateX, o.ty || o.translateY); var tx = translate.x; var ty = translate.y; - var relative = new Point$1(o.relative || o.rx || o.relativeX, o.ry || o.relativeY); + var relative = new Point(o.relative || o.rx || o.relativeX, o.ry || o.relativeY); var rx = relative.x; var ry = relative.y; // Populate all of the values @@ -4623,7 +4626,7 @@ var SVG = (function () { Element: { // Get current matrix ctm: function ctm() { - return new Matrix$1(this.node.getCTM()); + return new Matrix(this.node.getCTM()); }, // Get current screen matrix screenCTM: function screenCTM() { @@ -4635,10 +4638,10 @@ var SVG = (function () { var rect = this.rect(1, 1); var m = rect.node.getScreenCTM(); rect.remove(); - return new Matrix$1(m); + return new Matrix(m); } - return new Matrix$1(this.node.getScreenCTM()); + return new Matrix(this.node.getScreenCTM()); } } }); @@ -4681,7 +4684,7 @@ var SVG = (function () { var xMax = -Infinity; var yMin = Infinity; var yMax = -Infinity; - var pts = [new Point$1(this.x, this.y), new Point$1(this.x2, this.y), new Point$1(this.x, this.y2), new Point$1(this.x2, this.y2)]; + var pts = [new Point(this.x, this.y), new Point(this.x2, this.y), new Point(this.x, this.y2), new Point(this.x2, this.y2)]; pts.forEach(function (p) { p = p.transform(m); xMin = Math.min(xMin, p.x); @@ -5572,7 +5575,7 @@ var SVG = (function () { this._time = 0; this._last = 0; // Save transforms applied to this runner - this.transforms = new Matrix$1(); + this.transforms = new Matrix(); this.transformId = 1; // Looping variables this._haveReversed = false; @@ -5813,7 +5816,7 @@ var SVG = (function () { this._initialise(running); // clear the transforms on this runner so they dont get added again and again - this.transforms = new Matrix$1(); + this.transforms = new Matrix(); var converged = this._run(declarative ? dt : position); // this.fire('step', this) @@ -5947,7 +5950,7 @@ var SVG = (function () { }, { key: "clearTransform", value: function clearTransform() { - this.transforms = new Matrix$1(); + this.transforms = new Matrix(); return this; } }], [{ @@ -5986,7 +5989,7 @@ var SVG = (function () { Runner.id = 0; var FakeRunner = function FakeRunner() { - var transforms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Matrix$1(); + var transforms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Matrix(); var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; var done = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; @@ -6014,7 +6017,7 @@ var SVG = (function () { function mergeTransforms() { // Find the matrix to apply to the element and apply it var runners = this._transformationRunners.runners; - var netTransform = runners.map(getRunnerTransform).reduce(lmultiply, new Matrix$1()); + var netTransform = runners.map(getRunnerTransform).reduce(lmultiply, new Matrix()); this.transform(netTransform); this._transformationRunners.merge(); @@ -6128,7 +6131,7 @@ var SVG = (function () { // taken into account .filter(function (runner) { return runner.id <= current.id; - }).map(getRunnerTransform).reduce(lmultiply, new Matrix$1()); + }).map(getRunnerTransform).reduce(lmultiply, new Matrix()); }, addRunner: function addRunner(runner) { this._transformationRunners.add(runner); @@ -6137,7 +6140,7 @@ var SVG = (function () { }, _prepareRunner: function _prepareRunner() { if (this._frameId == null) { - this._transformationRunners = new RunnerArray().add(new FakeRunner(new Matrix$1(this))); + this._transformationRunners = new RunnerArray().add(new FakeRunner(new Matrix(this))); this._frameId = frameId++; } } @@ -6206,7 +6209,7 @@ var SVG = (function () { var isMatrix = isMatrixLike(transforms); affine = transforms.affine != null ? transforms.affine : affine != null ? affine : !isMatrix; // Create a morepher and set its type - var morpher = new Morphable().type(affine ? TransformBag : Matrix$1).stepper(this._stepper); + var morpher = new Morphable().type(affine ? TransformBag : Matrix).stepper(this._stepper); var origin; var element; var current; @@ -6217,7 +6220,7 @@ var SVG = (function () { // make sure element and origin is defined element = element || this.element(); origin = origin || getOrigin(transforms, element); - startTransform = new Matrix$1(relative ? undefined : element); // add the runner to the element so it can merge transformations + startTransform = new Matrix(relative ? undefined : element); // add the runner to the element so it can merge transformations element.addRunner(this); // Deactivate all transforms that have run so far if we are absolute @@ -6231,11 +6234,11 @@ var SVG = (function () { // on this runner. We are absolute. We dont need these! if (!relative) this.clearTransform(); - var _transform = new Point$1(origin).transform(element._currentTransform(this)), + var _transform = new Point(origin).transform(element._currentTransform(this)), x = _transform.x, y = _transform.y; - var target = new Matrix$1(_objectSpread({}, transforms, { + var target = new Matrix(_objectSpread({}, transforms, { origin: [x, y] })); var start = this._isDeclarative && current ? current : startTransform; @@ -6272,7 +6275,7 @@ var SVG = (function () { morpher.to(target); var affineParameters = morpher.at(pos); currentAngle = affineParameters.rotate; - current = new Matrix$1(affineParameters); + current = new Matrix(affineParameters); this.addTransform(current); return morpher.done(); } @@ -6506,8 +6509,8 @@ var SVG = (function () { SVGArray: SVGArray, PathArray: PathArray, PointArray: PointArray, - Matrix: Matrix$1, - Point: Point$1, + Matrix: Matrix, + Point: Point, Box: Box$1, Color: Color, Morphable: Morphable, @@ -6656,6 +6659,27 @@ var SVG = (function () { after: after }); + function data(a, v, r) { + if (_typeof(a) === 'object') { + for (v in a) { + this.data(v, a[v]); + } + } else if (arguments.length < 2) { + try { + return JSON.parse(this.attr('data-' + a)); + } catch (e) { + return this.attr('data-' + a); + } + } else { + this.attr('data-' + a, v === null ? null : r === true || typeof v === 'string' || typeof v === 'number' ? v : JSON.stringify(v)); + } + + return this; + } + registerMethods('Element', { + data: data + }); + // Dynamic style generator function css(style, val) { @@ -6683,7 +6707,7 @@ var SVG = (function () { for (var _iterator = style[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var _name = _step.value; var cased = camelCase(_name); - ret[cased] = this.node.style(cased); + ret[cased] = this.node.style[cased]; } } catch (err) { _didIteratorError = true; @@ -6762,7 +6786,7 @@ var SVG = (function () { } return matrix[transform[0]].apply(matrix, transform[1]); - }, new Matrix$1()); + }, new Matrix()); return matrix; } // add an element to another parent without changing the visual representation on the screen @@ -6781,7 +6805,7 @@ var SVG = (function () { function transform(o, relative) { // Act as a getter if no object was passed if (o == null || typeof o === 'string') { - var decomposed = new Matrix$1(this).decompose(); + var decomposed = new Matrix(this).decompose(); return decomposed[o] || decomposed; } @@ -6794,7 +6818,7 @@ var SVG = (function () { var cleanRelative = relative === true ? this : relative || false; - var result = new Matrix$1(cleanRelative).transform(o); + var result = new Matrix(cleanRelative).transform(o); return this.attr('transform', result); } registerMethods('Element', { @@ -6986,7 +7010,7 @@ var SVG = (function () { return new Point(this.node.getPointAtLength(length)); } }); - registerMethods(['Parent', 'Runner'], { + registerMethods(['Container', 'Runner'], { // Set font font: function font(a, v) { if (_typeof(a) === 'object') { @@ -7033,7 +7057,7 @@ var SVG = (function () { function children() { return map(this.node.children, function (node) { - return adopt$1(node); + return adopt(node); }); } // Add given element at a position @@ -7063,15 +7087,15 @@ var SVG = (function () { } // Get a element at the given index function get(i) { - return adopt$1(this.node.childNodes[i]); + return adopt(this.node.childNodes[i]); } // Get first child function first() { - return adopt$1(this.node.firstChild); + return adopt(this.node.firstChild); } // Get the last child function last() { - return adopt$1(this.node.lastChild); + return adopt(this.node.lastChild); } // Iterates over all children and invokes a given block function each(block, deep) { @@ -7204,7 +7228,7 @@ var SVG = (function () { extend$1(elements$1[_i], getConstructor('Memory')); } - registerMorphableType([SVGNumber, Color, Box$1, Matrix$1, SVGArray, PointArray, PathArray]); + registerMorphableType([SVGNumber, Color, Box$1, Matrix, SVGArray, PointArray, PathArray]); makeMorphable(); // The main wrapping element function SVG(element) { @@ -7216,9 +7240,15 @@ var SVG = (function () { SVG.utils = utils; SVG.regex = regex$1; // satisfy tests, fix later SVG.get = SVG; - SVG.select = baseFind; - Object.assign(SVG, ns$2); + SVG.find = baseFind; + Object.assign(SVG, ns$1); SVG.Element = SVG.Parent = SVG.Shape = SVG.Container = Base; + SVG.easing = easing; + Object.assign(SVG, events); + SVG.TransformBag = TransformBag; + SVG.ObjectBag = ObjectBag; + SVG.NonMorphable = NonMorphable; + SVG.parser = parser; return SVG; diff --git a/dist/svg.min.js b/dist/svg.min.js index c2bd909..81337c2 100644 --- a/dist/svg.min.js +++ b/dist/svg.min.js @@ -1 +1 @@ -var SVG=function(){"use strict";function l(t){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;nn.x&&e>n.y&&t=e.time?e.run():_t.timeouts.push(e),e!==n););for(var i=null,r=_t.frames.last();i!==r&&(i=_t.frames.shift());)i.run();_t.transforms.forEach(function(t){t()}),_t.nextDraw=_t.timeouts.first()||_t.frames.first()?window.requestAnimationFrame(_t._draw):null}},kt=function(t){function e(t){return c(this,e),a(this,u(e).call(this,B(t,"string"==typeof t?null:t),e))}return r(e,s),o(e,[{key:"words",value:function(t){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this.node.appendChild(document.createTextNode(t)),this}}]),e}();function Ot(t){return null==t?this.cx()-this.rx():this.cx(t+this.rx())}function At(t){return null==t?this.cy()-this.ry():this.cy(t+this.ry())}function Ct(t){return null==t?this.attr("cx"):this.attr("cx",t)}function Mt(t){return null==t?this.attr("cy"):this.attr("cy",t)}function jt(t){return null==t?2*this.rx():this.rx(new vt(t).divide(2))}function Tt(t){return null==t?2*this.ry():this.ry(new vt(t).divide(2))}function St(t,e){var n=D(this,t,e);return this.rx(new vt(n.width).divide(2)).ry(new vt(n.height).divide(2))}tt(kt),lt("Container",{element:function(t,e){return this.put(new kt(t,e))}});var Et=Object.freeze({rx:function(t){return this.attr("rx",t)},ry:function(t){return this.attr("ry",t)},x:Ot,y:At,cx:Ct,cy:Mt,width:jt,height:Tt,size:St}),Nt=function(t){function e(t){return c(this,e),a(this,u(e).call(this,B("circle",t),e))}return r(e,s),o(e,[{key:"radius",value:function(t){return this.attr("r",t)}},{key:"rx",value:function(t){return this.attr("r",t)}},{key:"ry",value:function(t){return this.rx(t)}}]),e}();function Pt(t,e){var n,i=t.length,r=[];for(n=0;n",Bt=0,Vt={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"},Ut=function(){function t(){c(this,t),this.init.apply(this,arguments)}return o(t,[{key:"init",value:function(t,e,n){var i,r;(this.r=0,this.g=0,this.b=0,t)&&("string"==typeof t?g.test(t)?(i=v.exec(t.replace(p,"")),this.r=parseInt(i[1]),this.g=parseInt(i[2]),this.b=parseInt(i[3])):m.test(t)&&(i=d.exec(4===(r=t).length?["#",r.substring(1,2),r.substring(1,2),r.substring(2,3),r.substring(2,3),r.substring(3,4),r.substring(3,4)].join(""):r),this.r=parseInt(i[1],16),this.g=parseInt(i[2],16),this.b=parseInt(i[3],16)):Array.isArray(t)?(this.r=t[0],this.g=t[1],this.b=t[2]):"object"===l(t)?(this.r=t.r,this.g=t.g,this.b=t.b):3===arguments.length&&(this.r=t,this.g=e,this.b=n))}},{key:"toString",value:function(){return this.toHex()}},{key:"toArray",value:function(){return[this.r,this.g,this.b]}},{key:"toHex",value:function(){return"#"+P(Math.round(this.r))+P(Math.round(this.g))+P(Math.round(this.b))}},{key:"toRgb",value:function(){return"rgb("+[this.r,this.g,this.b].join()+")"}},{key:"brightness",value:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11}}],[{key:"test",value:function(t){return t+="",m.test(t)||g.test(t)}},{key:"isRgb",value:function(t){return t&&"number"==typeof t.r&&"number"==typeof t.g&&"number"==typeof t.b}},{key:"isColor",value:function(t){return this.isRgb(t)||this.test(t)}}]),t}(),Qt=function(){try{return Function("name","baseClass","_constructor",["baseClass = baseClass || Array","return {","[name]: class extends baseClass {","constructor (...args) {","super(...args)","_constructor && _constructor.apply(this, args)","}","}","}[name]"].join("\n"))}catch(t){return function(t){var e=1":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)},bezier:function(t,e,n,i){return function(t){}}},Pe=function(){function t(){c(this,t)}return o(t,[{key:"done",value:function(){return!1}}]),t}(),De=function(t){function n(t){var e;return c(this,n),(e=a(this,u(n).call(this))).ease=Ne[t||Ht]||t,e}return r(n,Pe),o(n,[{key:"step",value:function(t,e,n){return"number"!=typeof t?n<1?t:e:t+(e-t)*this.ease(n)}}]),n}(),ze=function(t){function n(t){var e;return c(this,n),(e=a(this,u(n).call(this))).stepper=t,e}return r(n,Pe),o(n,[{key:"step",value:function(t,e,n,i){return this.stepper(t,e,n,i)}},{key:"done",value:function(t){return t.done}}]),n}();function Re(){var t=(this._duration||500)/1e3,e=this._overshoot||0,n=Math.PI,i=Math.log(e/100+1e-10),r=-i/Math.sqrt(n*n+i*i),s=3.9/(r*t);this.d=2*r*s,this.k=s*s}var qe=function(t){function i(t,e){var n;return c(this,i),(n=a(this,u(i).call(this))).duration(t||500).overshoot(e||0),n}return r(i,ze),o(i,[{key:"step",value:function(t,e,n,i){if("string"==typeof t)return t;if(i.done=n===1/0,n===1/0)return e;if(0===n)return t;100i);this._lastTime=this._time;var s=this._isDeclarative;if(this.done=!s&&!r&&this._time>=i,n||s){this._initialise(n),this.transforms=new je;var u=this._run(s?t:e)}return this.done=this.done||u&&s,this}},{key:"finish",value:function(){return this.step(1/0)}},{key:"reverse",value:function(t){return this._reverse=null==t?!this._reverse:t,this}},{key:"ease",value:function(t){return this._stepper=new De(t),this}},{key:"active",value:function(t){return null==t?this.enabled:(this.enabled=t,this)}},{key:"_rememberMorpher",value:function(t,e){this._history[t]={morpher:e,caller:this._queue[this._queue.length-1]}}},{key:"_tryRetarget",value:function(t,e){if(this._history[t]){if(!this._history[t].caller.initialised){var n=this._queue.indexOf(this._history[t].caller);return this._queue.splice(n,1),!1}this._history[t].caller.isTransform?this._history[t].caller.isTransform(e):this._history[t].morpher.to(e),this._history[t].caller.finished=!1;var i=this.timeline();return i&&i._continue(),!0}return!1}},{key:"_initialise",value:function(t){if(t||this._isDeclarative)for(var e=0,n=this._queue.length;en.x&&e>n.y&&t=e.time?e.run():kt.timeouts.push(e),e!==n););for(var i=null,r=kt.frames.last();i!==r&&(i=kt.frames.shift());)i.run();kt.transforms.forEach(function(t){t()}),kt.nextDraw=kt.timeouts.first()||kt.frames.first()?window.requestAnimationFrame(kt._draw):null}},Ot=function(t){function e(t){return c(this,e),a(this,u(e).call(this,H(t,"string"==typeof t?null:t),e))}return r(e,s),o(e,[{key:"words",value:function(t){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this.node.appendChild(document.createTextNode(t)),this}}]),e}();function At(t){return null==t?this.cx()-this.rx():this.cx(t+this.rx())}function Ct(t){return null==t?this.cy()-this.ry():this.cy(t+this.ry())}function Mt(t){return null==t?this.attr("cx"):this.attr("cx",t)}function jt(t){return null==t?this.attr("cy"):this.attr("cy",t)}function Tt(t){return null==t?2*this.rx():this.rx(new vt(t).divide(2))}function St(t){return null==t?2*this.ry():this.ry(new vt(t).divide(2))}function Et(t,e){var n=D(this,t,e);return this.rx(new vt(n.width).divide(2)).ry(new vt(n.height).divide(2))}tt(Ot),lt("Container",{element:function(t,e){return this.put(new Ot(t,e))}});var Nt=Object.freeze({rx:function(t){return this.attr("rx",t)},ry:function(t){return this.attr("ry",t)},x:At,y:Ct,cx:Mt,cy:jt,width:Tt,height:St,size:Et}),Pt=function(t){function e(t){return c(this,e),a(this,u(e).call(this,H("circle",t),e))}return r(e,s),o(e,[{key:"radius",value:function(t){return this.attr("r",t)}},{key:"rx",value:function(t){return this.attr("r",t)}},{key:"ry",value:function(t){return this.rx(t)}}]),e}();function Dt(t,e){var n,i=t.length,r=[];for(n=0;n",Vt=0,Ut={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"},Qt=function(){function t(){c(this,t),this.init.apply(this,arguments)}return o(t,[{key:"init",value:function(t,e,n){var i,r;(this.r=0,this.g=0,this.b=0,t)&&("string"==typeof t?g.test(t)?(i=v.exec(t.replace(p,"")),this.r=parseInt(i[1]),this.g=parseInt(i[2]),this.b=parseInt(i[3])):m.test(t)&&(i=d.exec(4===(r=t).length?["#",r.substring(1,2),r.substring(1,2),r.substring(2,3),r.substring(2,3),r.substring(3,4),r.substring(3,4)].join(""):r),this.r=parseInt(i[1],16),this.g=parseInt(i[2],16),this.b=parseInt(i[3],16)):Array.isArray(t)?(this.r=t[0],this.g=t[1],this.b=t[2]):"object"===l(t)?(this.r=t.r,this.g=t.g,this.b=t.b):3===arguments.length&&(this.r=t,this.g=e,this.b=n))}},{key:"toString",value:function(){return this.toHex()}},{key:"toArray",value:function(){return[this.r,this.g,this.b]}},{key:"toHex",value:function(){return"#"+P(Math.round(this.r))+P(Math.round(this.g))+P(Math.round(this.b))}},{key:"toRgb",value:function(){return"rgb("+[this.r,this.g,this.b].join()+")"}},{key:"brightness",value:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11}}],[{key:"test",value:function(t){return t+="",m.test(t)||g.test(t)}},{key:"isRgb",value:function(t){return t&&"number"==typeof t.r&&"number"==typeof t.g&&"number"==typeof t.b}},{key:"isColor",value:function(t){return this.isRgb(t)||this.test(t)}}]),t}(),$t=function(){try{return Function("name","baseClass","_constructor",["baseClass = baseClass || Array","return {","[name]: class extends baseClass {","constructor (...args) {","super(...args)","_constructor && _constructor.apply(this, args)","}","}","}[name]"].join("\n"))}catch(t){return function(t){var e=1":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)},bezier:function(t,e,n,i){return function(t){}}},Re=function(){function t(){c(this,t)}return o(t,[{key:"done",value:function(){return!1}}]),t}(),qe=function(t){function n(t){var e;return c(this,n),(e=a(this,u(n).call(this))).ease=ze[t||Ht]||t,e}return r(n,Re),o(n,[{key:"step",value:function(t,e,n){return"number"!=typeof t?n<1?t:e:t+(e-t)*this.ease(n)}}]),n}(),Le=function(t){function n(t){var e;return c(this,n),(e=a(this,u(n).call(this))).stepper=t,e}return r(n,Re),o(n,[{key:"step",value:function(t,e,n,i){return this.stepper(t,e,n,i)}},{key:"done",value:function(t){return t.done}}]),n}();function Ie(){var t=(this._duration||500)/1e3,e=this._overshoot||0,n=Math.PI,i=Math.log(e/100+1e-10),r=-i/Math.sqrt(n*n+i*i),s=3.9/(r*t);this.d=2*r*s,this.k=s*s}var Fe=function(t){function i(t,e){var n;return c(this,i),(n=a(this,u(i).call(this))).duration(t||500).overshoot(e||0),n}return r(i,Le),o(i,[{key:"step",value:function(t,e,n,i){if("string"==typeof t)return t;if(i.done=n===1/0,n===1/0)return e;if(0===n)return t;100i);this._lastTime=this._time;var s=this._isDeclarative;if(this.done=!s&&!r&&this._time>=i,n||s){this._initialise(n),this.transforms=new Ee;var u=this._run(s?t:e)}return this.done=this.done||u&&s,this}},{key:"finish",value:function(){return this.step(1/0)}},{key:"reverse",value:function(t){return this._reverse=null==t?!this._reverse:t,this}},{key:"ease",value:function(t){return this._stepper=new qe(t),this}},{key:"active",value:function(t){return null==t?this.enabled:(this.enabled=t,this)}},{key:"_rememberMorpher",value:function(t,e){this._history[t]={morpher:e,caller:this._queue[this._queue.length-1]}}},{key:"_tryRetarget",value:function(t,e){if(this._history[t]){if(!this._history[t].caller.initialised){var n=this._queue.indexOf(this._history[t].caller);return this._queue.splice(n,1),!1}this._history[t].caller.isTransform?this._history[t].caller.isTransform(e):this._history[t].morpher.to(e),this._history[t].caller.finished=!1;var i=this.timeline();return i&&i._continue(),!0}return!1}},{key:"_initialise",value:function(t){if(t||this._isDeclarative)for(var e=0,n=this._queue.length;e': function (pos) { return -Math.cos(pos * Math.PI) / 2 + 0.5 }, '>': function (pos) { return Math.sin(pos * Math.PI / 2) }, diff --git a/src/Element.js b/src/Element.js index 0494965..e8352a8 100644 --- a/src/Element.js +++ b/src/Element.js @@ -7,6 +7,7 @@ import {registerMethods} from './methods.js' import {registerConstructor} from './methods.js' const Doc = getClass(root) +const HtmlNode = getClass('HtmlNode') export const name = 'Element' @@ -223,7 +224,7 @@ export function parents (type) { do { parent = parent.parent(type) - if (!parent || !parent.node) break + if (!parent || parent instanceof HtmlNode) break parents.push(parent) } while (parent.parent) @@ -233,7 +234,7 @@ export function parents (type) { // matches the element vs a css selector export function matches (selector) { - return matches(this.node, selector) + return matcher(this.node, selector) } // Returns the svg node to call native svg methods on it diff --git a/src/Marker.js b/src/Marker.js index bf2b854..403a387 100644 --- a/src/Marker.js +++ b/src/Marker.js @@ -1,6 +1,7 @@ import Base from './Base.js' import {register} from './adopter.js' import {registerMethods} from './methods.js' +import {nodeOrNew} from './tools.js' export default class Marker extends Base { // Initialize node diff --git a/src/Matrix.js b/src/Matrix.js index 7f3afe5..b0a6c48 100644 --- a/src/Matrix.js +++ b/src/Matrix.js @@ -375,7 +375,7 @@ export default class Matrix { // Convert to native SVGMatrix native () { // create new matrix - var matrix = parser().node.createSVGMatrix() + var matrix = parser().svg.node.createSVGMatrix() // update with current values for (var i = abcdef.length - 1; i >= 0; i--) { diff --git a/src/Parent.js b/src/Parent.js index 769cd49..a52b000 100644 --- a/src/Parent.js +++ b/src/Parent.js @@ -2,6 +2,7 @@ import {makeInstance, adopt} from './adopter.js' import {map} from './utils.js' import {registerMethods} from './methods.js' import Base from './Base.js' +import {ns} from './namespaces.js' // Returns all child elements export function children () { diff --git a/src/Point.js b/src/Point.js index 7919d02..7f8e2c3 100644 --- a/src/Point.js +++ b/src/Point.js @@ -25,7 +25,7 @@ export default class Point { // Convert to native SVGPoint native () { // create new point - var point = parser().svg.createSVGPoint() + var point = parser().svg.node.createSVGPoint() // update with current values point.x = this.x diff --git a/src/Text.js b/src/Text.js index fabdbe5..02a601b 100644 --- a/src/Text.js +++ b/src/Text.js @@ -3,7 +3,7 @@ import SVGNumber from './SVGNumber.js' import {nodeOrNew, extend} from './tools.js' import {attrs} from './defaults.js' import * as textable from './textable.js' -import {register} from './adopter.js' +import {register, adopt} from './adopter.js' import {registerMethods} from './methods.js' export default class Text extends Base { @@ -56,6 +56,7 @@ export default class Text extends Base { text (text) { // act as getter if (text === undefined) { + // FIXME use children() or each() var children = this.node.childNodes var firstLine = 0 text = '' diff --git a/src/TextPath.js b/src/TextPath.js index afe29ce..df5b690 100644 --- a/src/TextPath.js +++ b/src/TextPath.js @@ -64,7 +64,7 @@ registerMethods({ // FIXME: make this plural? // Get the textPath children textPath: function () { - return this.select('textPath') + return this.find('textPath') } }, Path: { diff --git a/src/attr.js b/src/attr.js index 9ec9eb0..23baf51 100644 --- a/src/attr.js +++ b/src/attr.js @@ -14,7 +14,7 @@ export default function attr (attr, val, ns) { val = this.node.attributes for (let node of val) { - attr[node.nodeName] = isNumer.test(node.nodeValue) + attr[node.nodeName] = isNumber.test(node.nodeValue) ? parseFloat(node.nodeValue) : node.nodeValue } diff --git a/src/css.js b/src/css.js index 7a3bfbe..795be71 100644 --- a/src/css.js +++ b/src/css.js @@ -24,7 +24,7 @@ export function css (style, val) { if (Array.isArray(style)) { for (let name of style) { let cased = camelCase(name) - ret[cased] = this.node.style(cased) + ret[cased] = this.node.style[cased] } return ret } diff --git a/src/event.js b/src/event.js index dd782c6..9fa99e1 100644 --- a/src/event.js +++ b/src/event.js @@ -2,31 +2,36 @@ import Base from './Base.js' import {delimiter} from './regex.js' import {registerMethods} from './methods.js' -// // Add events to elements -// ;[ 'click', -// 'dblclick', -// 'mousedown', -// 'mouseup', -// 'mouseover', -// 'mouseout', -// 'mousemove', -// 'mouseenter', -// 'mouseleave', -// 'touchstart', -// 'touchmove', -// 'touchleave', -// 'touchend', -// 'touchcancel' ].forEach(function (event) { -// // add event to Element -// Element.prototype[event] = function (f) { -// if (f === null) { -// off(this, event) -// } else { -// on(this, event, f) -// } -// return this -// } -// }) +// Add events to elements +const methods = [ 'click', + 'dblclick', + 'mousedown', + 'mouseup', + 'mouseover', + 'mouseout', + 'mousemove', + 'mouseenter', + 'mouseleave', + 'touchstart', + 'touchmove', + 'touchleave', + 'touchend', + 'touchcancel' ].reduce(function (last, event) { + // add event to Element + const fn = function (f) { + if (f === null) { + off(this, event) + } else { + on(this, event, f) + } + return this + } + + last[event] = fn + return last + }, {}) + +registerMethods('Element', methods) let listenerId = 0 diff --git a/src/poly.js b/src/poly.js index 19643ef..937247a 100644 --- a/src/poly.js +++ b/src/poly.js @@ -1,5 +1,6 @@ // Add polygon-specific functions import PointArray from './PointArray.js' +import {proportionalSize} from './helpers.js' // Get array export function array () { diff --git a/src/sugar.js b/src/sugar.js index 3751f31..9a075a0 100644 --- a/src/sugar.js +++ b/src/sugar.js @@ -1,9 +1,10 @@ import Color from './Color.js' import Runner from './Runner.js' import SVGNumber from './SVGNumber.js' +import Matrix from './Matrix.js' +import Point from './Point.js' import {registerMethods} from './methods.js' - // Define list of available attributes for stroke and fill var sugar = { stroke: ['color', 'width', 'opacity', 'linecap', 'linejoin', 'miterlimit', 'dasharray', 'dashoffset'], @@ -139,7 +140,7 @@ registerMethods('Path', { } }) -registerMethods(['Parent', 'Runner'], { +registerMethods(['Container', 'Runner'], { // Set font font: function (a, v) { if (typeof a === 'object') { diff --git a/src/svg.js b/src/svg.js index de24923..10135b1 100644 --- a/src/svg.js +++ b/src/svg.js @@ -12,6 +12,7 @@ import * as containers from './containers.js' import * as elements from './elements.js' import './attr.js' import './arrange.js' +import './data.js' import find from './selector.js' import './css.js' import './transform.js' @@ -106,7 +107,17 @@ SVG.regex = regex // satisfy tests, fix later import * as ns from './namespaces' SVG.get = SVG -SVG.select = find +SVG.find = find Object.assign(SVG, ns) import Base from './Base.js' SVG.Element = SVG.Parent = SVG.Shape = SVG.Container = Base +import {easing} from './Controller.js' +SVG.easing = easing +import * as events from './event.js' +Object.assign(SVG, events) +import {TransformBag, ObjectBag, NonMorphable} from './Morphable.js' +SVG.TransformBag = TransformBag +SVG.ObjectBag = ObjectBag +SVG.NonMorphable = NonMorphable +import parser from './parser.js' +SVG.parser = parser