]> source.dussan.org Git - svg.js.git/commitdiff
added possibility to pass in additional attribues to element creators (#796) 924/head
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Thu, 8 Nov 2018 18:49:49 +0000 (19:49 +0100)
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>
Thu, 8 Nov 2018 18:49:49 +0000 (19:49 +0100)
e.g.
- `canvas.rect({x:100})` or
- `canvas.rect(100, 100, {x:100})`

26 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/Doc.js
src/elements/Ellipse.js
src/elements/G.js
src/elements/Gradient.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/Style.js
src/elements/Symbol.js
src/elements/Text.js
src/elements/TextPath.js
src/elements/Tspan.js
src/elements/Use.js
src/utils/adopter.js

index c88389edc16462488386a3ed1907fc03b55a9fb2..b8c78c7adf9b1700f1ca93d7e6151d363ef03041 100644 (file)
@@ -27,7 +27,8 @@ 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})`
+- added possibility to pass attributes into a constructor like: `new SVG.Rect({width:100})`
+- added possibility to pass in additional attribues to element creators e.g. `canvas.rect({x:100})` or `canvas.rect(100, 100, {x:100})` (#796)
 
 ### Removed
 - removed `SVG.Array.split()` function
index 91c140b6506f27fa4a87a9f43963bcada03c75fa..bcaef61b46316d9e4f64c3d5b8e763d7d494e94d 100644 (file)
@@ -6,7 +6,7 @@
 * @copyright Wout Fierens <wout@mick-wout.com>
 * @license MIT
 *
-* BUILT: Thu Nov 08 2018 16:05:07 GMT+0100 (GMT+01:00)
+* BUILT: Thu Nov 08 2018 19:44:36 GMT+0100 (GMT+01:00)
 */;
 var SVG = (function () {
   'use strict';
@@ -443,7 +443,7 @@ var SVG = (function () {
 
       var o = args[args.length - 1];
 
-      if (o && !o.prototype && !(o instanceof Array) && _typeof(o) === 'object') {
+      if (o && o.constructor === Object && !(o instanceof Array)) {
         return fn.apply(this, args.slice(0, -1)).attr(o);
       } else {
         return fn.apply(this, args);
@@ -2053,9 +2053,9 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create nested svg document
-      nested: function nested() {
+      nested: wrapWithAttrCheck(function () {
         return this.put(new Doc$1());
-      }
+      })
     }
   });
   register(Doc$1, 'Doc', true);
@@ -5405,9 +5405,9 @@ var SVG = (function () {
   registerMethods({
     Element: {
       // Create circle element
-      circle: function circle(size) {
+      circle: wrapWithAttrCheck(function (size) {
         return this.put(new Circle()).size(size).move(0, 0);
-      }
+      })
     }
   });
   register(Circle);
@@ -5436,9 +5436,9 @@ var SVG = (function () {
   extend(Ellipse, circled);
   registerMethods('Container', {
     // Create an ellipse
-    ellipse: function ellipse(width$$1, height$$1) {
+    ellipse: wrapWithAttrCheck(function (width$$1, height$$1) {
       return this.put(new Ellipse()).size(width$$1, height$$1).move(0, 0);
-    }
+    })
   });
   register(Ellipse);
 
@@ -5557,15 +5557,15 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create gradient element in defs
-      gradient: function gradient(type, block) {
+      gradient: wrapWithAttrCheck(function (type, block) {
         return this.defs().gradient(type, block);
-      }
+      })
     },
     // define gradient
     Defs: {
-      gradient: function gradient(type, block) {
+      gradient: wrapWithAttrCheck(function (type, block) {
         return this.put(new Gradient(type)).update(block);
-      }
+      })
     }
   });
   register(Gradient);
@@ -5631,12 +5631,14 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create pattern element in defs
-      pattern: function pattern(width, height, block) {
-        return this.defs().pattern(width, height, block);
+      pattern: function pattern() {
+        var _this$defs;
+
+        return (_this$defs = this.defs()).pattern.apply(_this$defs, arguments);
       }
     },
     Defs: {
-      pattern: function pattern(width, height, block) {
+      pattern: wrapWithAttrCheck(function (width, height, block) {
         return this.put(new Pattern()).update(block).attr({
           x: 0,
           y: 0,
@@ -5644,7 +5646,7 @@ var SVG = (function () {
           height: height,
           patternUnits: 'userSpaceOnUse'
         });
-      }
+      })
     }
   });
   register(Pattern);
@@ -5718,9 +5720,9 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // create image element, load image and set its size
-      image: function image(source, callback) {
+      image: wrapWithAttrCheck(function (source, callback) {
         return this.put(new Image()).size(0, 0).load(source, callback);
-      }
+      })
     }
   });
   register(Image);
@@ -5916,7 +5918,7 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a line element
-      line: function line() {
+      line: wrapWithAttrCheck(function () {
         for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
           args[_key] = arguments[_key];
         }
@@ -5924,7 +5926,7 @@ var SVG = (function () {
         // make sure plot is called as a setter
         // x1 is not necessarily a number, it can also be an array, a string and a PointArray
         return Line.prototype.plot.apply(this.put(new Line()), args[0] != null ? args : [0, 0, 0, 0]);
-      }
+      })
     }
   });
   register(Line);
@@ -5984,17 +5986,19 @@ var SVG = (function () {
   }(Container);
   registerMethods({
     Container: {
-      marker: function marker(width, height, block) {
+      marker: function marker() {
+        var _this$defs;
+
         // Create marker element in defs
-        return this.defs().marker(width, height, block);
+        return (_this$defs = this.defs()).marker.apply(_this$defs, arguments);
       }
     },
     Defs: {
       // Create marker
-      marker: function marker(width, height, block) {
+      marker: wrapWithAttrCheck(function (width, height, block) {
         // Set default viewbox to match the width and height, set ref to cx and cy and set orient to auto
         return this.put(new Marker()).size(width, height).ref(width / 2, height / 2).viewbox(0, 0, width, height).attr('orient', 'auto').update(block);
-      }
+      })
     },
     marker: {
       // Create and attach markers
@@ -6093,10 +6097,10 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a wrapped path element
-      path: function path(d) {
+      path: wrapWithAttrCheck(function (d) {
         // make sure plot is called as a setter
         return this.put(new Path()).plot(d || new PathArray());
-      }
+      })
     }
   });
   register(Path);
@@ -6148,10 +6152,10 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a wrapped polygon element
-      polygon: function polygon(p) {
+      polygon: wrapWithAttrCheck(function (p) {
         // make sure plot is called as a setter
         return this.put(new Polygon()).plot(p || new PointArray());
-      }
+      })
     }
   });
   extend(Polygon, pointed);
@@ -6175,10 +6179,10 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a wrapped polygon element
-      polyline: function polyline(p) {
+      polyline: wrapWithAttrCheck(function (p) {
         // make sure plot is called as a setter
         return this.put(new Polyline()).plot(p || new PointArray());
-      }
+      })
     }
   });
   extend(Polyline, pointed);
@@ -6206,9 +6210,9 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a rect element
-      rect: function rect(width$$1, height$$1) {
+      rect: wrapWithAttrCheck(function (width$$1, height$$1) {
         return this.put(new Rect()).size(width$$1, height$$1);
-      }
+      })
     }
   });
   register(Rect);
@@ -6411,13 +6415,13 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create text element
-      text: function text(_text2) {
-        return this.put(new Text()).text(_text2);
-      },
+      text: wrapWithAttrCheck(function (text) {
+        return this.put(new Text()).text(text);
+      }),
       // Create plain text element
-      plain: function plain$$1(text) {
+      plain: wrapWithAttrCheck(function (text) {
         return this.put(new Text()).plain(text);
-      }
+      })
     }
   });
   register(Text);
@@ -6472,7 +6476,7 @@ var SVG = (function () {
   extend(Tspan, textable);
   registerMethods({
     Tspan: {
-      tspan: function tspan(text) {
+      tspan: wrapWithAttrCheck(function (text) {
         var tspan = new Tspan(); // clear if build mode is disabled
 
         if (!this._build) {
@@ -6482,7 +6486,7 @@ var SVG = (function () {
 
         this.node.appendChild(tspan.node);
         return tspan.text(text);
-      }
+      })
     }
   });
   register(Tspan);
@@ -6517,9 +6521,9 @@ var SVG = (function () {
   register(Bare);
   registerMethods('Container', {
     // Create an element that is not described by SVG.js
-    element: function element(node, inherit) {
-      return this.put(new Bare(node, inherit));
-    }
+    element: wrapWithAttrCheck(function (node) {
+      return this.put(new Bare(node));
+    })
   });
 
   var ClipPath =
@@ -6556,9 +6560,9 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create clipping element
-      clip: function clip() {
+      clip: wrapWithAttrCheck(function () {
         return this.defs().put(new ClipPath());
-      }
+      })
     },
     Element: {
       // Distribute clipPath to svg element
@@ -6595,9 +6599,9 @@ var SVG = (function () {
   registerMethods({
     Element: {
       // Create a group element
-      group: function group() {
+      group: wrapWithAttrCheck(function () {
         return this.put(new G());
-      }
+      })
     }
   });
   register(G);
@@ -6647,9 +6651,9 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a hyperlink element
-      link: function link(url) {
+      link: wrapWithAttrCheck(function (url) {
         return this.put(new A()).to(url);
-      }
+      })
     },
     Element: {
       // Create a hyperlink element
@@ -6702,9 +6706,9 @@ var SVG = (function () {
   }(Container);
   registerMethods({
     Container: {
-      mask: function mask() {
+      mask: wrapWithAttrCheck(function () {
         return this.defs().put(new Mask());
-      }
+      })
     },
     Element: {
       // Distribute mask to svg element
@@ -6773,13 +6777,13 @@ var SVG = (function () {
 
     return Style;
   }(Element);
-  registerMethods('Element', {
-    style: function style(selector, obj) {
+  registerMethods('Dom', {
+    style: wrapWithAttrCheck(function (selector, obj) {
       return this.put(new Style()).rule(selector, obj);
-    },
-    fontface: function fontface(name, src, params) {
+    }),
+    fontface: wrapWithAttrCheck(function (name, src, params) {
       return this.put(new Style()).font(name, src, params);
-    }
+    })
   });
 
   var _Symbol =
@@ -6798,9 +6802,9 @@ var SVG = (function () {
   }(Container);
   registerMethods({
     Container: {
-      symbol: function symbol() {
+      symbol: wrapWithAttrCheck(function () {
         return this.put(new _Symbol());
-      }
+      })
     }
   });
   register(_Symbol);
@@ -6849,13 +6853,13 @@ var SVG = (function () {
   }(Text);
   registerMethods({
     Container: {
-      textPath: function textPath(text, path) {
+      textPath: wrapWithAttrCheck(function (text, path) {
         return this.defs().path(path).text(text).addTo(this);
-      }
+      })
     },
     Text: {
       // Create path for text to run on
-      path: function path(track) {
+      path: wrapWithAttrCheck(function (track) {
         var path = new TextPath(); // if track is a path, reuse it
 
         if (!(track instanceof Path)) {
@@ -6867,7 +6871,7 @@ var SVG = (function () {
         path.attr('href', '#' + track, xlink); // add textPath element as child node and return textPath
 
         return this.put(path);
-      },
+      }),
       // Get the textPath children
       textPath: function textPath() {
         return this.find('textPath')[0];
@@ -6875,15 +6879,14 @@ var SVG = (function () {
     },
     Path: {
       // creates a textPath from this path
-      text: function text(_text) {
-        if (_text instanceof Text) {
-          var txt = _text.text();
-
-          return _text.clear().path(this).text(txt);
+      text: wrapWithAttrCheck(function (text) {
+        if (text instanceof Text) {
+          var txt = text.text();
+          return text.clear().path(this).text(txt);
         }
 
-        return this.parent().put(new Text()).path(this).text(_text);
-      },
+        return this.parent().put(new Text()).path(this).text(text);
+      }),
       targets: function targets() {
         return baseFind('svg [href*="' + this.id() + '"]');
       }
@@ -6917,9 +6920,9 @@ var SVG = (function () {
   registerMethods({
     Container: {
       // Create a use element
-      use: function use(element, file) {
+      use: wrapWithAttrCheck(function (element, file) {
         return this.put(new Use()).element(element, file);
-      }
+      })
     }
   });
   register(Use);
index a0d73119748613dff90dfc7de4323d9e0c58079e..722deedb3bf3c492959d7747dead8ebe05a30d98 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import { xlink } from '../modules/core/namespaces.js'
 import Container from './Container.js'
@@ -22,9 +22,9 @@ export default class A extends Container {
 registerMethods({
   Container: {
     // Create a hyperlink element
-    link: function (url) {
+    link: wrapWithAttrCheck(function (url) {
       return this.put(new A()).to(url)
-    }
+    })
   },
   Element: {
     // Create a hyperlink element
index 6264ae2567992f46d208c134e243a87f5c28f362..9415cd4209b7f6be9e7eddcb8c99cd71e3715b5e 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 
@@ -24,7 +24,7 @@ register(Bare)
 
 registerMethods('Container', {
   // Create an element that is not described by SVG.js
-  element (node, inherit) {
-    return this.put(new Bare(node, inherit))
-  }
+  element: wrapWithAttrCheck(function (node) {
+    return this.put(new Bare(node))
+  })
 })
index 2f0d7f2c13f6561a5a1abc377372259dfb8de8a1..3135ada951ef035aea29bd0256e7be823bb53f1f 100644 (file)
@@ -1,5 +1,10 @@
 import { cx, cy, height, width, x, y } from '../modules/core/circled.js'
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import SVGNumber from '../types/SVGNumber.js'
 import Shape from './Shape.js'
@@ -33,11 +38,11 @@ extend(Circle, { x, y, cx, cy, width, height })
 registerMethods({
   Element: {
     // Create circle element
-    circle (size) {
+    circle: wrapWithAttrCheck(function (size) {
       return this.put(new Circle())
         .size(size)
         .move(0, 0)
-    }
+    })
   }
 })
 
index 5164086bb8956d55c22a823838f90806eae6f226..e545baa800515a7a42edb801401b056488dc7a46 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 import baseFind from '../modules/core/selector.js'
@@ -27,9 +27,9 @@ export default class ClipPath extends Container {
 registerMethods({
   Container: {
     // Create clipping element
-    clip: function () {
+    clip: wrapWithAttrCheck(function () {
       return this.defs().put(new ClipPath())
-    }
+    })
   },
   Element: {
     // Distribute clipPath to svg element
index 2132491dc067b71e6fbb904ab8b61f6b86f6cd23..0d862bafce413e0eaf94ac1901de5503612722f3 100644 (file)
@@ -1,4 +1,9 @@
-import { adopt, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  adopt,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { ns, svgjs, xlink, xmlns } from '../modules/core/namespaces.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
@@ -63,9 +68,9 @@ export default class Doc extends Container {
 registerMethods({
   Container: {
     // Create nested svg document
-    nested () {
+    nested: wrapWithAttrCheck(function () {
       return this.put(new Doc())
-    }
+    })
   }
 })
 
index 4ba8771636cadc80bbe4ceca70ce4cbe196c3f14..0350f1f5ae175238d68a9ff10dc58152274bf908 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { proportionalSize } from '../utils/utils.js'
 import { registerMethods } from '../utils/methods.js'
 import SVGNumber from '../types/SVGNumber.js'
@@ -23,9 +28,9 @@ extend(Ellipse, circled)
 
 registerMethods('Container', {
   // Create an ellipse
-  ellipse: function (width, height) {
+  ellipse: wrapWithAttrCheck(function (width, height) {
     return this.put(new Ellipse()).size(width, height).move(0, 0)
-  }
+  })
 })
 
 register(Ellipse)
index 5eeb65aa40e6f0ee72963b488b6f954a8c16e97a..6a93a3f791a902691db0f5565633714d20081a03 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 
@@ -11,9 +11,9 @@ export default class G extends Container {
 registerMethods({
   Element: {
     // Create a group element
-    group: function () {
+    group: wrapWithAttrCheck(function () {
       return this.put(new G())
-    }
+    })
   }
 })
 
index cfa2950fefb8fbe658be902dd4f215b1484e5ba5..23de97dbdf8b2ec5aaa84e3720b87ea9e3bc8d80 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Box from '../types/Box.js'
 import Container from './Container.js'
@@ -62,15 +67,15 @@ extend(Gradient, gradiented)
 registerMethods({
   Container: {
     // Create gradient element in defs
-    gradient (type, block) {
+    gradient: wrapWithAttrCheck(function (type, block) {
       return this.defs().gradient(type, block)
-    }
+    })
   },
   // define gradient
   Defs: {
-    gradient (type, block) {
+    gradient: wrapWithAttrCheck(function (type, block) {
       return this.put(new Gradient(type)).update(block)
-    }
+    })
   }
 })
 
index 469e10ab9fae612a8dc5f9980d564a05c25999bb..c529439b708dc508b342f7138a4d8777a1cf9d4c 100644 (file)
@@ -1,5 +1,5 @@
 import { isImage } from '../modules/core/regex.js'
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { off, on } from '../modules/core/event.js'
 import { registerAttrHook } from '../modules/core/attr.js'
 import { registerMethods } from '../utils/methods.js'
@@ -72,9 +72,9 @@ registerAttrHook(function (attr, val, _this) {
 registerMethods({
   Container: {
     // create image element, load image and set its size
-    image (source, callback) {
+    image: wrapWithAttrCheck(function (source, callback) {
       return this.put(new Image()).size(0, 0).load(source, callback)
-    }
+    })
   }
 })
 
index ba151351354e7acf2d4633f27a517196ad855a6e..99e7497ba907d3a9eab4bcb82fdf82b0345f588a 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { proportionalSize } from '../utils/utils.js'
 import { registerMethods } from '../utils/methods.js'
 import PointArray from '../types/PointArray.js'
@@ -49,14 +54,14 @@ extend(Line, pointed)
 registerMethods({
   Container: {
     // Create a line element
-    line (...args) {
+    line: wrapWithAttrCheck(function (...args) {
       // make sure plot is called as a setter
       // x1 is not necessarily a number, it can also be an array, a string and a PointArray
       return Line.prototype.plot.apply(
         this.put(new Line())
         , args[0] != null ? args : [0, 0, 0, 0]
       )
-    }
+    })
   }
 })
 
index 7e78e7f608aa4504d69d2ef27c55f3cf34d0dc9d..d40d13bb1a8c84f94b29056100d259ac0c3304d3 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 
@@ -42,14 +42,14 @@ export default class Marker extends Container {
 
 registerMethods({
   Container: {
-    marker (width, height, block) {
+    marker (...args) {
       // Create marker element in defs
-      return this.defs().marker(width, height, block)
+      return this.defs().marker(...args)
     }
   },
   Defs: {
     // Create marker
-    marker (width, height, block) {
+    marker: wrapWithAttrCheck(function (width, height, block) {
       // Set default viewbox to match the width and height, set ref to cx and cy and set orient to auto
       return this.put(new Marker())
         .size(width, height)
@@ -57,7 +57,7 @@ registerMethods({
         .viewbox(0, 0, width, height)
         .attr('orient', 'auto')
         .update(block)
-    }
+    })
   },
   marker: {
     // Create and attach markers
index 89eb97ffcf61b99af6c442074d09cface473136f..8dfffd634f84ac858ce27b2ab8434ccc9205bef1 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 import baseFind from '../modules/core/selector.js'
@@ -27,9 +27,9 @@ export default class Mask extends Container {
 
 registerMethods({
   Container: {
-    mask () {
+    mask: wrapWithAttrCheck(function () {
       return this.defs().put(new Mask())
-    }
+    })
   },
   Element: {
     // Distribute mask to svg element
index c8a4de45d02e0e9fe370557c738e4717f5038099..dc27320239cfc94ea375c8f8641c3c14acf3444f 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { proportionalSize } from '../utils/utils.js'
 import { registerMethods } from '../utils/methods.js'
 import PathArray from '../types/PathArray.js'
@@ -71,10 +71,10 @@ Path.prototype.MorphArray = PathArray
 registerMethods({
   Container: {
     // Create a wrapped path element
-    path (d) {
+    path: wrapWithAttrCheck(function (d) {
       // make sure plot is called as a setter
       return this.put(new Path()).plot(d || new PathArray())
-    }
+    })
   }
 })
 
index 4a1eee0155b5c775d05fa0931d961daea248283f..6dd4e016c7e49ae34db3889f2419ab95ce991b30 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Box from '../types/Box.js'
 import Container from './Container.js'
@@ -51,12 +51,12 @@ export default class Pattern extends Container {
 registerMethods({
   Container: {
     // Create pattern element in defs
-    pattern (width, height, block) {
-      return this.defs().pattern(width, height, block)
+    pattern (...args) {
+      return this.defs().pattern(...args)
     }
   },
   Defs: {
-    pattern (width, height, block) {
+    pattern: wrapWithAttrCheck(function (width, height, block) {
       return this.put(new Pattern()).update(block).attr({
         x: 0,
         y: 0,
@@ -64,7 +64,7 @@ registerMethods({
         height: height,
         patternUnits: 'userSpaceOnUse'
       })
-    }
+    })
   }
 })
 
index a7bf59290c30784869226cf7829b0e0f91371378..afa5f31f4add44af0a822bd5080443251778e033 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import PointArray from '../types/PointArray.js'
 import Shape from './Shape.js'
@@ -15,10 +20,10 @@ export default class Polygon extends Shape {
 registerMethods({
   Container: {
     // Create a wrapped polygon element
-    polygon (p) {
+    polygon: wrapWithAttrCheck(function (p) {
       // make sure plot is called as a setter
       return this.put(new Polygon()).plot(p || new PointArray())
-    }
+    })
   }
 })
 
index 079da52dd4fa616c8632f27129bd2a89f33c10d2..5897295dc54cfb45aeacdacd95ee567f96d8d4dc 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import PointArray from '../types/PointArray.js'
 import Shape from './Shape.js'
@@ -15,10 +20,10 @@ export default class Polyline extends Shape {
 registerMethods({
   Container: {
     // Create a wrapped polygon element
-    polyline (p) {
+    polyline: wrapWithAttrCheck(function (p) {
       // make sure plot is called as a setter
       return this.put(new Polyline()).plot(p || new PointArray())
-    }
+    })
   }
 })
 
index 7433993673cbf392eb7bdc09032af7bcc08051e8..6e161c938ef2b8d6f6637431f5c79e71ae84d74e 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import { rx, ry } from '../modules/core/circled.js'
 import Shape from './Shape.js'
@@ -15,9 +20,9 @@ extend(Rect, { rx, ry })
 registerMethods({
   Container: {
     // Create a rect element
-    rect (width, height) {
+    rect: wrapWithAttrCheck(function (width, height) {
       return this.put(new Rect()).size(width, height)
-    }
+    })
   }
 })
 
index 6ac84f40bd05876ef06d224c51449755126d6aed..8c5834648ef396fe18a147c1fc697f4377df1a08 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew } from '../utils/adopter.js'
+import { nodeOrNew, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import { unCamelCase } from '../utils/utils.js'
 import Element from './Element.js'
@@ -41,11 +41,11 @@ export default class Style extends Element {
   }
 }
 
-registerMethods('Element', {
-  style (selector, obj) {
+registerMethods('Dom', {
+  style: wrapWithAttrCheck(function (selector, obj) {
     return this.put(new Style()).rule(selector, obj)
-  },
-  fontface (name, src, params) {
+  }),
+  fontface: wrapWithAttrCheck(function (name, src, params) {
     return this.put(new Style()).font(name, src, params)
-  }
+  })
 })
index cdb5f852105ea29985422bb6922626caca40c5da..f44125c98b4d658a052551364700132299c975be 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Container from './Container.js'
 
@@ -11,9 +11,9 @@ export default class Symbol extends Container {
 
 registerMethods({
   Container: {
-    symbol () {
+    symbol: wrapWithAttrCheck(function () {
       return this.put(new Symbol())
-    }
+    })
   }
 })
 
index bd27428beb3ec3a886d43a1d4e9317b0d5dd9d1a..b4ba0adecd36eb9c6be8a8efb34107b93a91e832 100644 (file)
@@ -1,4 +1,10 @@
-import { adopt, extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  adopt,
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { attrs } from '../modules/core/defaults.js'
 import { registerMethods } from '../utils/methods.js'
 import SVGNumber from '../types/SVGNumber.js'
@@ -166,14 +172,14 @@ extend(Text, textable)
 registerMethods({
   Container: {
     // Create text element
-    text (text) {
+    text: wrapWithAttrCheck(function (text) {
       return this.put(new Text()).text(text)
-    },
+    }),
 
     // Create plain text element
-    plain (text) {
+    plain: wrapWithAttrCheck(function (text) {
       return this.put(new Text()).plain(text)
-    }
+    })
   }
 })
 
index cddeda832ba59e7f52ef4f6f68fecb5d8b839a26..324d7682dc9a4f29c3409a433567b0c1ecbf6889 100644 (file)
@@ -1,10 +1,10 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import { xlink } from '../modules/core/namespaces.js'
-import baseFind from '../modules/core/selector.js'
 import Path from './Path.js'
 import PathArray from '../types/PathArray.js'
 import Text from './Text.js'
+import baseFind from '../modules/core/selector.js'
 
 export default class TextPath extends Text {
   // Initialize node
@@ -39,13 +39,13 @@ export default class TextPath extends Text {
 
 registerMethods({
   Container: {
-    textPath (text, path) {
+    textPath: wrapWithAttrCheck(function (text, path) {
       return this.defs().path(path).text(text).addTo(this)
-    }
+    })
   },
   Text: {
     // Create path for text to run on
-    path (track) {
+    path: wrapWithAttrCheck(function (track) {
       var path = new TextPath()
 
       // if track is a path, reuse it
@@ -59,7 +59,7 @@ registerMethods({
 
       // add textPath element as child node and return textPath
       return this.put(path)
-    },
+    }),
 
     // Get the textPath children
     textPath () {
@@ -68,13 +68,13 @@ registerMethods({
   },
   Path: {
     // creates a textPath from this path
-    text (text) {
+    text: wrapWithAttrCheck(function (text) {
       if (text instanceof Text) {
         var txt = text.text()
         return text.clear().path(this).text(txt)
       }
       return this.parent().put(new Text()).path(this).text(text)
-    },
+    }),
 
     targets () {
       return baseFind('svg [href*="' + this.id() + '"]')
index 9745b953d6cbf4a36a33f02dc5a5cdf678c43acd..abd032fd40bd91d83bc809d739cc550791e5bcb9 100644 (file)
@@ -1,4 +1,9 @@
-import { extend, nodeOrNew, register } from '../utils/adopter.js'
+import {
+  extend,
+  nodeOrNew,
+  register,
+  wrapWithAttrCheck
+} from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import Text from './Text.js'
 import * as textable from '../modules/core/textable.js'
@@ -45,7 +50,7 @@ extend(Tspan, textable)
 
 registerMethods({
   Tspan: {
-    tspan (text) {
+    tspan: wrapWithAttrCheck(function (text) {
       var tspan = new Tspan()
 
       // clear if build mode is disabled
@@ -57,7 +62,7 @@ registerMethods({
       this.node.appendChild(tspan.node)
 
       return tspan.text(text)
-    }
+    })
   }
 })
 
index 5808988bcaf4b51eb6a42e99f04becb54763eb08..7921461bc8fd2a6f8bc68a965b1ebd3b55c52edc 100644 (file)
@@ -1,4 +1,4 @@
-import { nodeOrNew, register } from '../utils/adopter.js'
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
 import { registerMethods } from '../utils/methods.js'
 import { xlink } from '../modules/core/namespaces.js'
 import Shape from './Shape.js'
@@ -18,9 +18,9 @@ export default class Use extends Shape {
 registerMethods({
   Container: {
     // Create a use element
-    use: function (element, file) {
+    use: wrapWithAttrCheck(function (element, file) {
       return this.put(new Use()).element(element, file)
-    }
+    })
   }
 })
 
index 68803998f48275daef45212983784b2cea470ed7..88cd3839bde24a5ccddc60ea6b0c8e4c19db0fcd 100644 (file)
@@ -126,7 +126,7 @@ export function wrapWithAttrCheck (fn) {
   return function (...args) {
     let o = args[args.length - 1]
 
-    if (o && !o.prototype && !(o instanceof Array) && typeof o === 'object') {
+    if (o && o.constructor === Object && !(o instanceof Array)) {
       return fn.apply(this, args.slice(0, -1)).attr(o)
     } else {
       return fn.apply(this, args)