]> source.dussan.org Git - svg.js.git/commitdiff
added possibility to pass attribues into a constructor like: `new SVG.Rect({width...
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Thu, 8 Nov 2018 15:06:39 +0000 (16:06 +0100)
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Thu, 8 Nov 2018 15:06:39 +0000 (16:06 +0100)
32 files changed:
CHANGELOG.md
dist/svg.js
src/elements/A.js
src/elements/Bare.js
src/elements/Circle.js
src/elements/ClipPath.js
src/elements/Defs.js
src/elements/Doc.js
src/elements/Dom.js
src/elements/Element.js
src/elements/Ellipse.js
src/elements/G.js
src/elements/Gradient.js
src/elements/HtmlNode.js
src/elements/Image.js
src/elements/Line.js
src/elements/Marker.js
src/elements/Mask.js
src/elements/Path.js
src/elements/Pattern.js
src/elements/Polygon.js
src/elements/Polyline.js
src/elements/Rect.js
src/elements/Stop.js
src/elements/Style.js
src/elements/Symbol.js
src/elements/Text.js
src/elements/TextPath.js
src/elements/Tspan.js
src/elements/Use.js
src/types/Point.js
src/utils/adopter.js

index 250b7f447a57c6bfbf334cd7c6faf139634902dc..c88389edc16462488386a3ed1907fc03b55a9fb2 100644 (file)
@@ -27,6 +27,7 @@ The document follows the conventions described in [“Keep a CHANGELOG”](http:
 - added `Dom` which is a baseclass to get dom abilities
 - added `round()` which lets you round attribues from a node
 - added `ax(), ay(), amove()` to change texts x and y values directly (#787)
+- added possibility to pass attribues into a constructor like: `new SVG.Rect({width:100})`
 
 ### Removed
 - removed `SVG.Array.split()` function
index bdf49a1f92bbf8e475a0167ed114022b3217e1d7..91c140b6506f27fa4a87a9f43963bcada03c75fa 100644 (file)
@@ -6,7 +6,7 @@
 * @copyright Wout Fierens <wout@mick-wout.com>
 * @license MIT
 *
-* BUILT: Thu Nov 08 2018 14:12:10 GMT+0100 (GMT+01:00)
+* BUILT: Thu Nov 08 2018 16:05:07 GMT+0100 (GMT+01:00)
 */;
 var SVG = (function () {
   'use strict';
@@ -354,7 +354,7 @@ var SVG = (function () {
     return element;
   }
   function nodeOrNew(name, node) {
-    return node || makeNode(name);
+    return node instanceof window.Node ? node : makeNode(name);
   } // Adopt existing svg elements
 
   function adopt(node) {
@@ -412,16 +412,44 @@ var SVG = (function () {
     return adopt(node);
   } // Method for extending objects
 
-  function extend(modules, methods) {
+  function extend(modules, methods, attrCheck) {
     var key, i;
     modules = Array.isArray(modules) ? modules : [modules];
 
     for (i = modules.length - 1; i >= 0; i--) {
       for (key in methods) {
-        modules[i].prototype[key] = methods[key];
+        var method = methods[key];
+
+        if (attrCheck) {
+          method = wrapWithAttrCheck(methods[key]);
+        }
+
+        modules[i].prototype[key] = method;
       }
     }
   }
+  function extendWithAttrCheck() {
+    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
+      args[_key] = arguments[_key];
+    }
+
+    extend.apply(void 0, args.concat([true]));
+  }
+  function wrapWithAttrCheck(fn) {
+    return function () {
+      for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
+        args[_key2] = arguments[_key2];
+      }
+
+      var o = args[args.length - 1];
+
+      if (o && !o.prototype && !(o instanceof Array) && _typeof(o) === 'object') {
+        return fn.apply(this, args.slice(0, -1)).attr(o);
+      } else {
+        return fn.apply(this, args);
+      }
+    };
+  }
 
   var methods = {};
   function registerMethods(name, m) {
@@ -1422,7 +1450,7 @@ var SVG = (function () {
   function (_EventTarget) {
     _inherits(Dom, _EventTarget);
 
-    function Dom(node) {
+    function Dom(node, attrs) {
       var _this2;
 
       _classCallCheck(this, Dom);
@@ -1430,6 +1458,11 @@ var SVG = (function () {
       _this2 = _possibleConstructorReturn(this, _getPrototypeOf(Dom).call(this, node));
       _this2.node = node;
       _this2.type = node.nodeName;
+
+      if (attrs && node !== attrs) {
+        _this2.attr(attrs);
+      }
+
       return _this2;
     } // Add given element at a position
 
@@ -1734,12 +1767,12 @@ var SVG = (function () {
   function (_Dom) {
     _inherits(Element, _Dom);
 
-    function Element(node) {
+    function Element(node, attrs) {
       var _this;
 
       _classCallCheck(this, Element);
 
-      _this = _possibleConstructorReturn(this, _getPrototypeOf(Element).call(this, node)); // initialize data object
+      _this = _possibleConstructorReturn(this, _getPrototypeOf(Element).call(this, node, attrs)); // initialize data object
 
       _this.dom = {}; // create circular reference
 
@@ -1927,7 +1960,7 @@ var SVG = (function () {
     function Defs(node) {
       _classCallCheck(this, Defs);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Defs).call(this, nodeOrNew('defs', node), Defs));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Defs).call(this, nodeOrNew('defs', node), node));
     }
 
     _createClass(Defs, [{
@@ -1956,7 +1989,7 @@ var SVG = (function () {
 
       _classCallCheck(this, Doc);
 
-      _this = _possibleConstructorReturn(this, _getPrototypeOf(Doc).call(this, nodeOrNew('svg', node), Doc));
+      _this = _possibleConstructorReturn(this, _getPrototypeOf(Doc).call(this, nodeOrNew('svg', node), node));
 
       _this.namespace();
 
@@ -2051,32 +2084,37 @@ var SVG = (function () {
   /*#__PURE__*/
   function () {
     // Initialize
-    function Point(x, y, base) {
+    function Point() {
       _classCallCheck(this, Point);
 
-      var source;
-      base = base || {
-        x: 0,
-        y: 0 // ensure source as object
+      this.init.apply(this, arguments);
+    }
 
-      };
-      source = Array.isArray(x) ? {
-        x: x[0],
-        y: x[1]
-      } : _typeof(x) === 'object' ? {
-        x: x.x,
-        y: x.y
-      } : {
-        x: x,
-        y: y // merge source
+    _createClass(Point, [{
+      key: "init",
+      value: function init(x, y) {
+        var source;
+        var base = {
+          x: 0,
+          y: 0 // ensure source as object
 
-      };
-      this.x = source.x == null ? base.x : source.x;
-      this.y = source.y == null ? base.y : source.y;
-    } // Clone point
+        };
+        source = Array.isArray(x) ? {
+          x: x[0],
+          y: x[1]
+        } : _typeof(x) === 'object' ? {
+          x: x.x,
+          y: x.y
+        } : {
+          x: x,
+          y: y // merge source
 
+        };
+        this.x = source.x == null ? base.x : source.x;
+        this.y = source.y == null ? base.y : source.y;
+      } // Clone point
 
-    _createClass(Point, [{
+    }, {
       key: "clone",
       value: function clone() {
         return new Point(this);
@@ -2102,6 +2140,11 @@ var SVG = (function () {
 
         return new Point(x, y);
       }
+    }, {
+      key: "toArray",
+      value: function toArray() {
+        return [this.x, this.y];
+      }
     }]);
 
     return Point;
@@ -5322,7 +5365,7 @@ var SVG = (function () {
     function Circle(node) {
       _classCallCheck(this, Circle);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Circle).call(this, nodeOrNew('circle', node), Circle));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Circle).call(this, nodeOrNew('circle', node), node));
     }
 
     _createClass(Circle, [{
@@ -5377,7 +5420,7 @@ var SVG = (function () {
     function Ellipse(node) {
       _classCallCheck(this, Ellipse);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Ellipse).call(this, nodeOrNew('ellipse', node), Ellipse));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Ellipse).call(this, nodeOrNew('ellipse', node), node));
     }
 
     _createClass(Ellipse, [{
@@ -5407,7 +5450,7 @@ var SVG = (function () {
     function Stop(node) {
       _classCallCheck(this, Stop);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Stop).call(this, nodeOrNew('stop', node), Stop));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Stop).call(this, nodeOrNew('stop', node), node));
     } // add color stops
 
 
@@ -5452,10 +5495,10 @@ var SVG = (function () {
   function (_Container) {
     _inherits(Gradient, _Container);
 
-    function Gradient(type) {
+    function Gradient(type, attrs) {
       _classCallCheck(this, Gradient);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Gradient).call(this, nodeOrNew(type + 'Gradient', typeof type === 'string' ? null : type), Gradient));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Gradient).call(this, nodeOrNew(type + 'Gradient', typeof type === 'string' ? null : type), attrs));
     } // Add a color stop
 
 
@@ -5536,7 +5579,7 @@ var SVG = (function () {
     function Pattern(node) {
       _classCallCheck(this, Pattern);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Pattern).call(this, nodeOrNew('pattern', node), Pattern));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Pattern).call(this, nodeOrNew('pattern', node), node));
     } // Return the fill id
 
 
@@ -5614,7 +5657,7 @@ var SVG = (function () {
     function Image(node) {
       _classCallCheck(this, Image);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Image).call(this, nodeOrNew('image', node), Image));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Image).call(this, nodeOrNew('image', node), node));
     } // (re)load image
 
 
@@ -5824,7 +5867,7 @@ var SVG = (function () {
     function Line(node) {
       _classCallCheck(this, Line);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Line).call(this, nodeOrNew('line', node), Line));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Line).call(this, nodeOrNew('line', node), node));
     } // Get array
 
 
@@ -5895,7 +5938,7 @@ var SVG = (function () {
     function Marker(node) {
       _classCallCheck(this, Marker);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Marker).call(this, nodeOrNew('marker', node), Marker));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Marker).call(this, nodeOrNew('marker', node), node));
     } // Set width of element
 
 
@@ -5977,7 +6020,7 @@ var SVG = (function () {
     function Path(node) {
       _classCallCheck(this, Path);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Path).call(this, nodeOrNew('path', node), Path));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Path).call(this, nodeOrNew('path', node), node));
     } // Get array
 
 
@@ -6097,7 +6140,7 @@ var SVG = (function () {
     function Polygon(node) {
       _classCallCheck(this, Polygon);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Polygon).call(this, nodeOrNew('polygon', node), Polygon));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Polygon).call(this, nodeOrNew('polygon', node), node));
     }
 
     return Polygon;
@@ -6124,7 +6167,7 @@ var SVG = (function () {
     function Polyline(node) {
       _classCallCheck(this, Polyline);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Polyline).call(this, nodeOrNew('polyline', node), Polyline));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Polyline).call(this, nodeOrNew('polyline', node), node));
     }
 
     return Polyline;
@@ -6151,7 +6194,7 @@ var SVG = (function () {
     function Rect(node) {
       _classCallCheck(this, Rect);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Rect).call(this, nodeOrNew('rect', node), Rect));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Rect).call(this, nodeOrNew('rect', node), node));
     }
 
     return Rect;
@@ -6202,7 +6245,7 @@ var SVG = (function () {
 
       _classCallCheck(this, Text);
 
-      _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).call(this, nodeOrNew('text', node), Text));
+      _this = _possibleConstructorReturn(this, _getPrototypeOf(Text).call(this, nodeOrNew('text', node), node));
       _this.dom.leading = new SVGNumber(1.3); // store leading value for rebuilding
 
       _this._rebuild = true; // enable automatic updating of dy values
@@ -6388,7 +6431,7 @@ var SVG = (function () {
     function Tspan(node) {
       _classCallCheck(this, Tspan);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Tspan).call(this, nodeOrNew('tspan', node), Tspan));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Tspan).call(this, nodeOrNew('tspan', node), node));
     } // Set text content
 
 
@@ -6449,10 +6492,10 @@ var SVG = (function () {
   function (_Container) {
     _inherits(Bare, _Container);
 
-    function Bare(node) {
+    function Bare(node, attrs) {
       _classCallCheck(this, Bare);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Bare).call(this, nodeOrNew(node, typeof node === 'string' ? null : node), Bare));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Bare).call(this, nodeOrNew(node, typeof node === 'string' ? null : node), attrs));
     }
 
     _createClass(Bare, [{
@@ -6487,7 +6530,7 @@ var SVG = (function () {
     function ClipPath(node) {
       _classCallCheck(this, ClipPath);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(ClipPath).call(this, nodeOrNew('clipPath', node), ClipPath));
+      return _possibleConstructorReturn(this, _getPrototypeOf(ClipPath).call(this, nodeOrNew('clipPath', node), node));
     } // Unclip all clipped elements and remove itself
 
 
@@ -6544,7 +6587,7 @@ var SVG = (function () {
     function G(node) {
       _classCallCheck(this, G);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(G).call(this, nodeOrNew('g', node), G));
+      return _possibleConstructorReturn(this, _getPrototypeOf(G).call(this, nodeOrNew('g', node), node));
     }
 
     return G;
@@ -6564,10 +6607,10 @@ var SVG = (function () {
   function (_Dom) {
     _inherits(HtmlNode, _Dom);
 
-    function HtmlNode(node) {
+    function HtmlNode() {
       _classCallCheck(this, HtmlNode);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(HtmlNode).call(this, node, HtmlNode));
+      return _possibleConstructorReturn(this, _getPrototypeOf(HtmlNode).apply(this, arguments));
     }
 
     return HtmlNode;
@@ -6582,7 +6625,7 @@ var SVG = (function () {
     function A(node) {
       _classCallCheck(this, A);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(A).call(this, nodeOrNew('a', node), A));
+      return _possibleConstructorReturn(this, _getPrototypeOf(A).call(this, nodeOrNew('a', node), node));
     } // Link url
 
 
@@ -6634,7 +6677,7 @@ var SVG = (function () {
     function Mask(node) {
       _classCallCheck(this, Mask);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Mask).call(this, nodeOrNew('mask', node), Mask));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Mask).call(this, nodeOrNew('mask', node), node));
     } // Unmask all masked elements and remove itself
 
 
@@ -6703,7 +6746,7 @@ var SVG = (function () {
     function Style(node) {
       _classCallCheck(this, Style);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Style).call(this, nodeOrNew('style', node), Style));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Style).call(this, nodeOrNew('style', node), node));
     }
 
     _createClass(Style, [{
@@ -6748,7 +6791,7 @@ var SVG = (function () {
     function _Symbol(node) {
       _classCallCheck(this, _Symbol);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(_Symbol).call(this, nodeOrNew('symbol', node), _Symbol));
+      return _possibleConstructorReturn(this, _getPrototypeOf(_Symbol).call(this, nodeOrNew('symbol', node), node));
     }
 
     return _Symbol;
@@ -6771,7 +6814,7 @@ var SVG = (function () {
     function TextPath(node) {
       _classCallCheck(this, TextPath);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(TextPath).call(this, nodeOrNew('textPath', node), TextPath));
+      return _possibleConstructorReturn(this, _getPrototypeOf(TextPath).call(this, nodeOrNew('textPath', node), node));
     } // return the array of the path track element
 
 
@@ -6857,7 +6900,7 @@ var SVG = (function () {
     function Use(node) {
       _classCallCheck(this, Use);
 
-      return _possibleConstructorReturn(this, _getPrototypeOf(Use).call(this, nodeOrNew('use', node), Use));
+      return _possibleConstructorReturn(this, _getPrototypeOf(Use).call(this, nodeOrNew('use', node), node));
     } // Use element as a reference
 
 
@@ -6981,7 +7024,9 @@ var SVG = (function () {
     getClass: getClass,
     eid: eid,
     assignNewId: assignNewId,
-    extend: extend
+    extend: extend,
+    extendWithAttrCheck: extendWithAttrCheck,
+    wrapWithAttrCheck: wrapWithAttrCheck
   });
 
   function SVG(element) {
index 68da5976da514f2703a7c245b67c6cabce2a4dd8..a0d73119748613dff90dfc7de4323d9e0c58079e 100644 (file)
@@ -5,7 +5,7 @@ import Container from './Container.js'
 
 export default class A extends Container {
   constructor (node) {
-    super(nodeOrNew('a', node), A)
+    super(nodeOrNew('a', node), node)
   }
 
   // Link url
index 43fc07523c73e649e48a047a490ff114d1462edb..6264ae2567992f46d208c134e243a87f5c28f362 100644 (file)
@@ -3,8 +3,8 @@ import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 
 export default class Bare extends Container {
-  constructor (node) {
-    super(nodeOrNew(node, typeof node === 'string' ? null : node), Bare)
+  constructor (node, attrs) {
+    super(nodeOrNew(node, typeof node === 'string' ? null : node), attrs)
   }
 
   words (text) {
index 52aaa3d5f527f65ceb6308c69cc714625fe949ef..2f0d7f2c13f6561a5a1abc377372259dfb8de8a1 100644 (file)
@@ -6,7 +6,7 @@ import Shape from './Shape.js'
 
 export default class Circle extends Shape {
   constructor (node) {
-    super(nodeOrNew('circle', node), Circle)
+    super(nodeOrNew('circle', node), node)
   }
 
   radius (r) {
index 2828d6eb8399df33eb7f308bc6aaa7e771584ae8..5164086bb8956d55c22a823838f90806eae6f226 100644 (file)
@@ -5,7 +5,7 @@ import baseFind from '../modules/core/selector.js'
 
 export default class ClipPath extends Container {
   constructor (node) {
-    super(nodeOrNew('clipPath', node), ClipPath)
+    super(nodeOrNew('clipPath', node), node)
   }
 
   // Unclip all clipped elements and remove itself
index 58932cbdebdcd4355a2b10b033951eadea225e39..28266119f6e89e0ce34d616c610074b2ad54e980 100644 (file)
@@ -3,7 +3,7 @@ import Container from './Container.js'
 
 export default class Defs extends Container {
   constructor (node) {
-    super(nodeOrNew('defs', node), Defs)
+    super(nodeOrNew('defs', node), node)
   }
 
   flatten () { return this }
index 8d450ce5a9746eeaa03f648cf4cebfed36b8a59a..2132491dc067b71e6fbb904ab8b61f6b86f6cd23 100644 (file)
@@ -6,7 +6,7 @@ import Defs from './Defs.js'
 
 export default class Doc extends Container {
   constructor (node) {
-    super(nodeOrNew('svg', node), Doc)
+    super(nodeOrNew('svg', node), node)
     this.namespace()
   }
 
index 75f3e941437a7d8ab5728b365cc3f96b69122af2..899da777b8328df5f2ed448fc379d232682f3120 100644 (file)
@@ -11,10 +11,14 @@ import EventTarget from '../types/EventTarget.js'
 import attr from '../modules/core/attr.js'
 
 export default class Dom extends EventTarget {
-  constructor (node) {
+  constructor (node, attrs) {
     super(node)
     this.node = node
     this.type = node.nodeName
+
+    if (attrs && node !== attrs) {
+      this.attr(attrs)
+    }
   }
 
   // Add given element at a position
index a38b2ac8acc0959fe72e92aea929ec9546eb398b..fe513e9ebd279e8e68bef979c19b2ab7e6838b64 100644 (file)
@@ -7,8 +7,8 @@ import SVGNumber from '../types/SVGNumber.js'
 const Doc = getClass(root)
 
 export default class Element extends Dom {
-  constructor (node) {
-    super(node)
+  constructor (node, attrs) {
+    super(node, attrs)
 
     // initialize data object
     this.dom = {}
index b0ee4bf45993c876e21987dbf608f370fbd28d0b..4ba8771636cadc80bbe4ceca70ce4cbe196c3f14 100644 (file)
@@ -7,7 +7,7 @@ import * as circled from '../modules/core/circled.js'
 
 export default class Ellipse extends Shape {
   constructor (node) {
-    super(nodeOrNew('ellipse', node), Ellipse)
+    super(nodeOrNew('ellipse', node), node)
   }
 
   size (width, height) {
index 00803c09a9cb061a13d2ea568f8c165e4b4a142a..5eeb65aa40e6f0ee72963b488b6f954a8c16e97a 100644 (file)
@@ -4,7 +4,7 @@ import Container from './Container.js'
 
 export default class G extends Container {
   constructor (node) {
-    super(nodeOrNew('g', node), G)
+    super(nodeOrNew('g', node), node)
   }
 }
 
index cf8aeaa4982755ac8af09561f2f95ee1f888c01e..cfa2950fefb8fbe658be902dd4f215b1484e5ba5 100644 (file)
@@ -7,10 +7,10 @@ import baseFind from '../modules/core/selector.js'
 import * as gradiented from '../modules/core/gradiented.js'
 
 export default class Gradient extends Container {
-  constructor (type) {
+  constructor (type, attrs) {
     super(
       nodeOrNew(type + 'Gradient', typeof type === 'string' ? null : type),
-      Gradient
+      attrs
     )
   }
 
index 59152d308a7c4add39d3e138b33e6c28d047d7ea..009b122078013422a1c2b4577534a9d2db26f48a 100644 (file)
@@ -1,10 +1,6 @@
 import { register } from '../utils/adopter.js'
 import Dom from './Dom.js'
 
-export default class HtmlNode extends Dom {
-  constructor (node) {
-    super(node, HtmlNode)
-  }
-}
+export default class HtmlNode extends Dom {}
 
 register(HtmlNode)
index ec9459f2dae546a85b595f7875738a7b389e7fd4..469e10ab9fae612a8dc5f9980d564a05c25999bb 100644 (file)
@@ -9,7 +9,7 @@ import Shape from './Shape.js'
 
 export default class Image extends Shape {
   constructor (node) {
-    super(nodeOrNew('image', node), Image)
+    super(nodeOrNew('image', node), node)
   }
 
   // (re)load image
index b9bc4e820cb3c4b3c913ca1ba48238ed3f6f8a79..ba151351354e7acf2d4633f27a517196ad855a6e 100644 (file)
@@ -8,7 +8,7 @@ import * as pointed from '../modules/core/pointed.js'
 export default class Line extends Shape {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('line', node), Line)
+    super(nodeOrNew('line', node), node)
   }
 
   // Get array
index 2b0541b2df3eb0ce8e6f9f798be1254079d07f2c..7e78e7f608aa4504d69d2ef27c55f3cf34d0dc9d 100644 (file)
@@ -5,7 +5,7 @@ import Container from './Container.js'
 export default class Marker extends Container {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('marker', node), Marker)
+    super(nodeOrNew('marker', node), node)
   }
 
   // Set width of element
index 1ed5a8b4f15a0979d742c8b5da8e38b4d966f2b5..89eb97ffcf61b99af6c442074d09cface473136f 100644 (file)
@@ -6,7 +6,7 @@ import baseFind from '../modules/core/selector.js'
 export default class Mask extends Container {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('mask', node), Mask)
+    super(nodeOrNew('mask', node), node)
   }
 
   // Unmask all masked elements and remove itself
index 71be8a195a3fbdc4b1a8a7fe5f40ec8ea5b674e7..c8a4de45d02e0e9fe370557c738e4717f5038099 100644 (file)
@@ -8,7 +8,7 @@ import baseFind from '../modules/core/selector.js'
 export default class Path extends Shape {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('path', node), Path)
+    super(nodeOrNew('path', node), node)
   }
 
   // Get array
index 91118374351c5511f50c98e9d8fbc9411632fc38..4a1eee0155b5c775d05fa0931d961daea248283f 100644 (file)
@@ -7,7 +7,7 @@ import baseFind from '../modules/core/selector.js'
 export default class Pattern extends Container {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('pattern', node), Pattern)
+    super(nodeOrNew('pattern', node), node)
   }
 
   // Return the fill id
index 6097977ee22b89e58598334389c082fe17995df7..a7bf59290c30784869226cf7829b0e0f91371378 100644 (file)
@@ -8,7 +8,7 @@ import * as poly from '../modules/core/poly.js'
 export default class Polygon extends Shape {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('polygon', node), Polygon)
+    super(nodeOrNew('polygon', node), node)
   }
 }
 
index b2cb15b7b108a799b737f82125a02ed9153d61f6..079da52dd4fa616c8632f27129bd2a89f33c10d2 100644 (file)
@@ -8,7 +8,7 @@ import * as poly from '../modules/core/poly.js'
 export default class Polyline extends Shape {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('polyline', node), Polyline)
+    super(nodeOrNew('polyline', node), node)
   }
 }
 
index fa66fc35019daf01504ecc313d5bf02d7f571331..7433993673cbf392eb7bdc09032af7bcc08051e8 100644 (file)
@@ -6,7 +6,7 @@ import Shape from './Shape.js'
 export default class Rect extends Shape {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('rect', node), Rect)
+    super(nodeOrNew('rect', node), node)
   }
 }
 
index bf919e8b87363bd149b12102802605f4ac54b5a9..9a5acaa5c516ea04214f0c6c67651205427538ab 100644 (file)
@@ -4,7 +4,7 @@ import SVGNumber from '../types/SVGNumber.js'
 
 export default class Stop extends Element {
   constructor (node) {
-    super(nodeOrNew('stop', node), Stop)
+    super(nodeOrNew('stop', node), node)
   }
 
   // add color stops
index 5c25893aae2bc24d933f71a8754560d84a2d1f75..6ac84f40bd05876ef06d224c51449755126d6aed 100644 (file)
@@ -20,7 +20,7 @@ function cssRule (selector, rule) {
 
 export default class Style extends Element {
   constructor (node) {
-    super(nodeOrNew('style', node), Style)
+    super(nodeOrNew('style', node), node)
   }
 
   words (w) {
index 183f449799200f416a22c36d810d60ab84a2fc91..cdb5f852105ea29985422bb6922626caca40c5da 100644 (file)
@@ -5,7 +5,7 @@ import Container from './Container.js'
 export default class Symbol extends Container {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('symbol', node), Symbol)
+    super(nodeOrNew('symbol', node), node)
   }
 }
 
index f221004183b505596aaefb569f2a3071d22d643c..bd27428beb3ec3a886d43a1d4e9317b0d5dd9d1a 100644 (file)
@@ -8,7 +8,7 @@ import * as textable from '../modules/core/textable.js'
 export default class Text extends Shape {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('text', node), Text)
+    super(nodeOrNew('text', node), node)
 
     this.dom.leading = new SVGNumber(1.3) // store leading value for rebuilding
     this._rebuild = true // enable automatic updating of dy values
index 480eca233ff8a8c42e8103e0a636489673ad6678..cddeda832ba59e7f52ef4f6f68fecb5d8b839a26 100644 (file)
@@ -9,7 +9,7 @@ import Text from './Text.js'
 export default class TextPath extends Text {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('textPath', node), TextPath)
+    super(nodeOrNew('textPath', node), node)
   }
 
   // return the array of the path track element
index 69815d462c1a4d2d54bd2bde73082f11c5a035c5..9745b953d6cbf4a36a33f02dc5a5cdf678c43acd 100644 (file)
@@ -6,7 +6,7 @@ import * as textable from '../modules/core/textable.js'
 export default class Tspan extends Text {
   // Initialize node
   constructor (node) {
-    super(nodeOrNew('tspan', node), Tspan)
+    super(nodeOrNew('tspan', node), node)
   }
 
   // Set text content
index 43a4e9ba1f1b9676f017580839e8cec588d43e9f..5808988bcaf4b51eb6a42e99f04becb54763eb08 100644 (file)
@@ -5,7 +5,7 @@ import Shape from './Shape.js'
 
 export default class Use extends Shape {
   constructor (node) {
-    super(nodeOrNew('use', node), Use)
+    super(nodeOrNew('use', node), node)
   }
 
   // Use element as a reference
index 0adcd909912777d09d69b132c3229aa96c1e6f04..685240b5dee30178f34c0d7679d02817de433210 100644 (file)
@@ -3,9 +3,13 @@ import parser from '../modules/core/parser.js'
 
 export default class Point {
   // Initialize
-  constructor (x, y, base) {
+  constructor (...args) {
+    this.init(...args)
+  }
+
+  init (x, y) {
     let source
-    base = base || { x: 0, y: 0 }
+    let base = { x: 0, y: 0 }
 
     // ensure source as object
     source = Array.isArray(x) ? { x: x[0], y: x[1] }
@@ -42,6 +46,10 @@ export default class Point {
     // Return the required point
     return new Point(x, y)
   }
+
+  toArray () {
+    return [this.x, this.y]
+  }
 }
 
 registerMethods({
index 8017359e9216eb729ddb3ce83dedfb19e0c9e565..68803998f48275daef45212983784b2cea470ed7 100644 (file)
@@ -37,7 +37,7 @@ export function makeInstance (element) {
 }
 
 export function nodeOrNew (name, node) {
-  return node || makeNode(name)
+  return node instanceof window.Node ? node : makeNode(name)
 }
 
 // Adopt existing svg elements
@@ -102,14 +102,34 @@ export function assignNewId (node) {
 }
 
 // Method for extending objects
-export function extend (modules, methods) {
+export function extend (modules, methods, attrCheck) {
   var key, i
 
   modules = Array.isArray(modules) ? modules : [modules]
 
   for (i = modules.length - 1; i >= 0; i--) {
     for (key in methods) {
-      modules[i].prototype[key] = methods[key]
+      let method = methods[key]
+      if (attrCheck) {
+        method = wrapWithAttrCheck(methods[key])
+      }
+      modules[i].prototype[key] = method
+    }
+  }
+}
+
+export function extendWithAttrCheck (...args) {
+  extend(...args, true)
+}
+
+export function wrapWithAttrCheck (fn) {
+  return function (...args) {
+    let o = args[args.length - 1]
+
+    if (o && !o.prototype && !(o instanceof Array) && typeof o === 'object') {
+      return fn.apply(this, args.slice(0, -1)).attr(o)
+    } else {
+      return fn.apply(this, args)
     }
   }
 }