e.g.
- `canvas.rect({x:100})` or
- `canvas.rect(100, 100, {x:100})`
- 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
* @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';
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);
registerMethods({
Container: {
// Create nested svg document
- nested: function nested() {
+ nested: wrapWithAttrCheck(function () {
return this.put(new Doc$1());
- }
+ })
}
});
register(Doc$1, 'Doc', true);
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);
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);
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);
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,
height: height,
patternUnits: 'userSpaceOnUse'
});
- }
+ })
}
});
register(Pattern);
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);
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];
}
// 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);
}(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
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);
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);
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);
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);
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);
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) {
this.node.appendChild(tspan.node);
return tspan.text(text);
- }
+ })
}
});
register(Tspan);
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 =
registerMethods({
Container: {
// Create clipping element
- clip: function clip() {
+ clip: wrapWithAttrCheck(function () {
return this.defs().put(new ClipPath());
- }
+ })
},
Element: {
// Distribute clipPath to svg element
registerMethods({
Element: {
// Create a group element
- group: function group() {
+ group: wrapWithAttrCheck(function () {
return this.put(new G());
- }
+ })
}
});
register(G);
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
}(Container);
registerMethods({
Container: {
- mask: function mask() {
+ mask: wrapWithAttrCheck(function () {
return this.defs().put(new Mask());
- }
+ })
},
Element: {
// Distribute mask to svg element
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 =
}(Container);
registerMethods({
Container: {
- symbol: function symbol() {
+ symbol: wrapWithAttrCheck(function () {
return this.put(new _Symbol());
- }
+ })
}
});
register(_Symbol);
}(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)) {
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];
},
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() + '"]');
}
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);
-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'
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
-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'
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))
+ })
})
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'
registerMethods({
Element: {
// Create circle element
- circle (size) {
+ circle: wrapWithAttrCheck(function (size) {
return this.put(new Circle())
.size(size)
.move(0, 0)
- }
+ })
}
})
-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'
registerMethods({
Container: {
// Create clipping element
- clip: function () {
+ clip: wrapWithAttrCheck(function () {
return this.defs().put(new ClipPath())
- }
+ })
},
Element: {
// Distribute clipPath to svg element
-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'
registerMethods({
Container: {
// Create nested svg document
- nested () {
+ nested: wrapWithAttrCheck(function () {
return this.put(new Doc())
- }
+ })
}
})
-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'
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)
-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'
registerMethods({
Element: {
// Create a group element
- group: function () {
+ group: wrapWithAttrCheck(function () {
return this.put(new G())
- }
+ })
}
})
-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'
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)
- }
+ })
}
})
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'
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)
- }
+ })
}
})
-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'
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]
)
- }
+ })
}
})
-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'
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)
.viewbox(0, 0, width, height)
.attr('orient', 'auto')
.update(block)
- }
+ })
},
marker: {
// Create and attach markers
-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'
registerMethods({
Container: {
- mask () {
+ mask: wrapWithAttrCheck(function () {
return this.defs().put(new Mask())
- }
+ })
},
Element: {
// Distribute mask to svg element
-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'
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())
- }
+ })
}
})
-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'
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,
height: height,
patternUnits: 'userSpaceOnUse'
})
- }
+ })
}
})
-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'
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())
- }
+ })
}
})
-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'
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())
- }
+ })
}
})
-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'
registerMethods({
Container: {
// Create a rect element
- rect (width, height) {
+ rect: wrapWithAttrCheck(function (width, height) {
return this.put(new Rect()).size(width, height)
- }
+ })
}
})
-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'
}
}
-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)
- }
+ })
})
-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'
registerMethods({
Container: {
- symbol () {
+ symbol: wrapWithAttrCheck(function () {
return this.put(new Symbol())
- }
+ })
}
})
-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'
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)
- }
+ })
}
})
-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
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
// add textPath element as child node and return textPath
return this.put(path)
- },
+ }),
// Get the textPath children
textPath () {
},
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() + '"]')
-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'
registerMethods({
Tspan: {
- tspan (text) {
+ tspan: wrapWithAttrCheck(function (text) {
var tspan = new Tspan()
// clear if build mode is disabled
this.node.appendChild(tspan.node)
return tspan.text(text)
- }
+ })
}
})
-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'
registerMethods({
Container: {
// Create a use element
- use: function (element, file) {
+ use: wrapWithAttrCheck(function (element, file) {
return this.put(new Use()).element(element, file)
- }
+ })
}
})
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)