diff options
Diffstat (limited to 'src')
67 files changed, 465 insertions, 525 deletions
@@ -1,8 +1,8 @@ import Container from './Container.js' -import {nodeOrNew} from './tools.js' -import {xlink} from './namespaces.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew } from './tools.js' +import { xlink } from './namespaces.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class A extends Container { constructor (node) { diff --git a/src/Animator.js b/src/Animator.js index eca6ee3..b015163 100644 --- a/src/Animator.js +++ b/src/Animator.js @@ -77,8 +77,8 @@ const Animator = { // If we have remaining timeouts or frames, draw until we don't anymore Animator.nextDraw = Animator.timeouts.first() || Animator.frames.first() - ? window.requestAnimationFrame(Animator._draw) - : null + ? window.requestAnimationFrame(Animator._draw) + : null } } diff --git a/src/ArrayPolyfill.js b/src/ArrayPolyfill.js index 19c1ede..cf95d54 100644 --- a/src/ArrayPolyfill.js +++ b/src/ArrayPolyfill.js @@ -1,18 +1,18 @@ +/* eslint no-new-func: "off" */ export const subClassArray = (function () { try { // try es6 subclassing return Function('name', 'baseClass', '_constructor', [ 'baseClass = baseClass || Array', 'return {', - '[name]: class extends baseClass {', - 'constructor (...args) {', - 'super(...args)', - '_constructor && _constructor.apply(this, args)', - '}', - '}', + '[name]: class extends baseClass {', + 'constructor (...args) {', + 'super(...args)', + '_constructor && _constructor.apply(this, args)', + '}', + '}', '}[name]' ].join('\n')) - } catch (e) { // Use es5 approach return (name, baseClass = Array, _constructor) => { diff --git a/src/Bare.js b/src/Bare.js index c08d8fc..7b3be98 100644 --- a/src/Bare.js +++ b/src/Bare.js @@ -1,8 +1,7 @@ -import {nodeOrNew} from './tools.js' -import {register} from './adopter.js' +import { nodeOrNew } from './tools.js' +import { register } from './adopter.js' import Container from './Container.js' -import {registerMethods} from './methods.js' -import {extend} from './tools.js' +import { registerMethods } from './methods.js' export default class Bare extends Container { constructor (node) { diff --git a/src/Base.js b/src/Base.js index 1e76bb4..d2897a1 100644 --- a/src/Base.js +++ b/src/Base.js @@ -1,14 +1,10 @@ export default class Base { - constructor (node/*, {extensions = []}*/) { - // this.tags = [] - // - // for (let extension of extensions) { - // extension.setup.call(this, node) - // this.tags.push(extension.name) - // } - } - - is (ability) { - return this.tags.includes(ability) - } + // constructor (node/*, {extensions = []} */) { + // // this.tags = [] + // // + // // for (let extension of extensions) { + // // extension.setup.call(this, node) + // // this.tags.push(extension.name) + // // } + // } } @@ -1,9 +1,8 @@ import Point from './Point.js' import parser from './parser.js' -import {fullBox, domContains, isNulledBox} from './helpers.js' -import {extend} from './tools.js' -import {delimiter} from './regex.js' -import {registerMethods} from './methods.js' +import { fullBox, domContains, isNulledBox } from './helpers.js' +import { delimiter } from './regex.js' +import { registerMethods } from './methods.js' export default class Box { constructor (...args) { @@ -14,10 +13,10 @@ export default class Box { var base = [0, 0, 0, 0] source = typeof source === 'string' ? source.split(delimiter).map(parseFloat) : Array.isArray(source) ? source - : typeof source === 'object' ? [source.left != null ? source.left - : source.x, source.top != null ? source.top : source.y, source.width, source.height] - : arguments.length === 4 ? [].slice.call(arguments) - : base + : typeof source === 'object' ? [source.left != null ? source.left + : source.x, source.top != null ? source.top : source.y, source.width, source.height] + : arguments.length === 4 ? [].slice.call(arguments) + : base this.x = source[0] this.y = source[1] @@ -82,7 +81,7 @@ export default class Box { } } -function getBox(cb) { +function getBox (cb) { let box try { diff --git a/src/Circle.js b/src/Circle.js index 9d0c4db..8879eec 100644 --- a/src/Circle.js +++ b/src/Circle.js @@ -1,9 +1,9 @@ import Shape from './Shape.js' -import {nodeOrNew, extend} from './tools.js' -import {x, y, cx, cy, width, height, size} from './circled.js' +import { nodeOrNew, extend } from './tools.js' +import { x, y, cx, cy, width, height, size } from './circled.js' import SVGNumber from './SVGNumber.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Circle extends Shape { constructor (node) { @@ -25,7 +25,7 @@ export default class Circle extends Shape { } } -extend(Circle, {x, y, cx, cy, width, height, size}) +extend(Circle, { x, y, cx, cy, width, height, size }) registerMethods({ Element: { diff --git a/src/ClipPath.js b/src/ClipPath.js index 1801c67..2321656 100644 --- a/src/ClipPath.js +++ b/src/ClipPath.js @@ -1,9 +1,9 @@ import Container from './Container.js' -import {nodeOrNew, extend} from './tools.js' +import { nodeOrNew } from './tools.js' import find from './selector.js' -//import {remove} from './Element.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +// import {remove} from './Element.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class ClipPath extends Container { constructor (node) { @@ -19,7 +19,7 @@ export default class ClipPath extends Container { // remove clipPath from parent return super.remove() - //return remove.call(this) + // return remove.call(this) } targets () { @@ -27,12 +27,11 @@ export default class ClipPath extends Container { } } - registerMethods({ Container: { // Create clipping element - clip: function() { - return this.defs().put(new ClipPath) + clip: function () { + return this.defs().put(new ClipPath()) } }, Element: { diff --git a/src/Color.js b/src/Color.js index de65750..ed3531c 100644 --- a/src/Color.js +++ b/src/Color.js @@ -1,5 +1,3 @@ -/* globals fullHex, compToHex */ - /* Color { @@ -29,8 +27,8 @@ SVG.hsl() SVG.lab('rgb(100, 100, 100)') */ -import {isHex, isRgb, whitespace, rgb, hex} from './regex.js' -import {fullHex, compToHex} from './helpers.js' +import { isHex, isRgb, whitespace, rgb, hex } from './regex.js' +import { fullHex, compToHex } from './helpers.js' export default class Color { constructor (...args) { diff --git a/src/Controller.js b/src/Controller.js index e3f2ab9..0bf5ac0 100644 --- a/src/Controller.js +++ b/src/Controller.js @@ -1,6 +1,6 @@ -import {timeline} from './defaults.js' -import {extend} from './tools.js' +import { timeline } from './defaults.js' +import { extend } from './tools.js' /*** Base Class @@ -29,7 +29,6 @@ export let easing = { } } - export class Stepper { done () { return false } } @@ -53,7 +52,6 @@ export class Ease extends Stepper { } } - /*** Controller Types ================ diff --git a/src/Defs.js b/src/Defs.js index 8cafb49..ddcf733 100644 --- a/src/Defs.js +++ b/src/Defs.js @@ -1,6 +1,6 @@ import Container from './Container.js' -import {nodeOrNew} from './tools.js' -import {register} from './adopter.js' +import { nodeOrNew } from './tools.js' +import { register } from './adopter.js' export default class Defs extends Container { constructor (node) { @@ -1,33 +1,32 @@ import Container from './Container.js' import Defs from './Defs.js' -import { extend, nodeOrNew } from './tools.js' +import { nodeOrNew } from './tools.js' import { ns, xlink, xmlns, svgjs } from './namespaces.js' -import {adopt, register} from './adopter.js' -import {registerMethods} from './methods.js' -//import {remove, parent, doc} from './Element.js' +import { adopt, register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Doc extends Container { - constructor(node) { + constructor (node) { super(nodeOrNew('svg', node), Doc) this.namespace() } - isRoot() { - return !this.node.parentNode - || !(this.node.parentNode instanceof window.SVGElement) - || this.node.parentNode.nodeName === '#document' + isRoot () { + return !this.node.parentNode || + !(this.node.parentNode instanceof window.SVGElement) || + this.node.parentNode.nodeName === '#document' } // Check if this is a root svg // If not, call docs from this element - doc() { + doc () { if (this.isRoot()) return this return super.doc() - //return doc.call(this) + // return doc.call(this) } // Add namespaces - namespace() { + namespace () { if (!this.isRoot()) return this.doc().namespace() return this .attr({ xmlns: ns, version: '1.1' }) @@ -36,7 +35,7 @@ export default class Doc extends Container { } // Creates and returns defs element - defs() { + defs () { if (!this.isRoot()) return this.doc().defs() return adopt(this.node.getElementsByTagName('defs')[0]) || @@ -44,7 +43,7 @@ export default class Doc extends Container { } // custom parent method - parent(type) { + parent (type) { if (this.isRoot()) { return this.node.parentNode.nodeName === '#document' ? null @@ -52,7 +51,7 @@ export default class Doc extends Container { } return super.parent(type) - //return parent.call(this, type) + // return parent.call(this, type) } // Removes the doc from the DOM @@ -68,7 +67,7 @@ export default class Doc extends Container { // return this // } - clear() { + clear () { // remove children while (this.node.hasChildNodes()) { this.node.removeChild(this.node.lastChild) @@ -80,7 +79,7 @@ export default class Doc extends Container { registerMethods({ Container: { // Create nested svg document - nested() { + nested () { return this.put(new Doc()) } } @@ -1,8 +1,11 @@ import EventTarget from './EventTarget.js' -import {assignNewId, adopt, makeInstance, eid} from './adopter.js' -import {map} from './utils.js' -import {matcher} from './helpers.js' -import {ns} from './namespaces.js' +import { assignNewId, adopt, makeInstance, eid } from './adopter.js' +import { map } from './utils.js' +import { matcher } from './helpers.js' +import { ns } from './namespaces.js' + +import { extend } from './tools.js' +import attr from './attr.js' export default class Dom extends EventTarget { constructor (node) { @@ -231,7 +234,4 @@ export default class Dom extends EventTarget { return this } } - -import {extend} from './tools.js' -import attr from './attr.js' -extend(Dom, {attr}) +extend(Dom, { attr }) diff --git a/src/Element.js b/src/Element.js index e7944fc..8161b6a 100644 --- a/src/Element.js +++ b/src/Element.js @@ -1,7 +1,5 @@ -import {proportionalSize, matcher, idFromReference} from './helpers.js' -import {makeInstance, root, getClass} from './adopter.js' -import {delimiter} from './regex.js' -import {ns} from './namespaces.js' +import { proportionalSize, idFromReference } from './helpers.js' +import { makeInstance, root, getClass } from './adopter.js' import SVGNumber from './SVGNumber.js' import Dom from './Dom.js' @@ -139,8 +137,6 @@ export default class Element extends Dom { } } - - // registerMethods('Element', { // x, y, cx, cy, move, center, width, height, size, clone, remove, replace, // addTo, putIn, id, inside, toString, classes, hasClass, addClass, removeClass, diff --git a/src/Ellipse.js b/src/Ellipse.js index 21a1018..2cc1d09 100644 --- a/src/Ellipse.js +++ b/src/Ellipse.js @@ -1,8 +1,8 @@ import Shape from './Shape.js' import * as circled from './circled.js' -import {extend, nodeOrNew} from './tools.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { extend, nodeOrNew } from './tools.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Ellipse extends Shape { constructor (node) { diff --git a/src/EventTarget.js b/src/EventTarget.js index 637f7f8..e306271 100644 --- a/src/EventTarget.js +++ b/src/EventTarget.js @@ -1,9 +1,9 @@ import Base from './Base.js' -import {on, off, dispatch} from './event.js' -import {extend} from './tools.js' +import { on, off, dispatch } from './event.js' +import { extend } from './tools.js' -export default class EventTarget extends Base{ - constructor ({events = {}} = {}) { +export default class EventTarget extends Base { + constructor ({ events = {} } = {}) { super() this.events = events } @@ -58,7 +58,6 @@ export default class EventTarget extends Base{ removeEventListener () {} } - // Add events to elements const methods = [ 'click', 'dblclick', @@ -74,23 +73,22 @@ const methods = [ 'click', '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 + // 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 - }, {}) + last[event] = fn + return last +}, {}) extend(EventTarget, methods) - // registerMethods('EventTarget', { // on, off, dispatch, fire // }) @@ -1,7 +1,7 @@ import Container from './Container.js' -import {nodeOrNew} from './tools.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew } from './tools.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class G extends Container { constructor (node) { diff --git a/src/Gradient.js b/src/Gradient.js index 0f20173..7e8075e 100644 --- a/src/Gradient.js +++ b/src/Gradient.js @@ -1,11 +1,12 @@ import Stop from './Stop.js' import Container from './Container.js' import * as gradiented from './gradiented.js' -import {nodeOrNew, extend} from './tools.js' -//import attr from './attr.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew, extend } from './tools.js' +// import attr from './attr.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' import Box from './Box.js' +import { find } from './selector.js' export default class Gradient extends Container { constructor (type) { @@ -47,7 +48,7 @@ export default class Gradient extends Container { attr (a, b, c) { if (a === 'transform') a = 'gradientTransform' return super.attr(a, b, c) - //return attr.call(this, a, b, c) + // return attr.call(this, a, b, c) } targets () { diff --git a/src/HtmlNode.js b/src/HtmlNode.js index ff45984..ced223f 100644 --- a/src/HtmlNode.js +++ b/src/HtmlNode.js @@ -1,5 +1,5 @@ import Dom from './Dom.js' -import {register} from './adopter.js' +import { register } from './adopter.js' export default class HtmlNode extends Dom { constructor (node) { diff --git a/src/Image.js b/src/Image.js index ea46a57..f257492 100644 --- a/src/Image.js +++ b/src/Image.js @@ -1,10 +1,10 @@ import Shape from './Shape.js' import Pattern from './Pattern.js' -import {on, off} from './event.js' -import {nodeOrNew} from './tools.js' -import {xlink} from './namespaces.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { on, off } from './event.js' +import { nodeOrNew } from './tools.js' +import { xlink } from './namespaces.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Image extends Shape { constructor (node) { diff --git a/src/Line.js b/src/Line.js index 660b4f5..4028e48 100644 --- a/src/Line.js +++ b/src/Line.js @@ -1,9 +1,9 @@ -import {proportionalSize} from './helpers.js' -import {nodeOrNew, extend} from './tools.js' +import { proportionalSize } from './helpers.js' +import { nodeOrNew, extend } from './tools.js' import PointArray from './PointArray.js' import Shape from './Shape.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' import * as pointed from './pointed.js' export default class Line extends Shape { @@ -55,7 +55,7 @@ registerMethods({ // 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] + , args[0] != null ? args : [0, 0, 0, 0] ) } } diff --git a/src/Marker.js b/src/Marker.js index df19f20..16b2480 100644 --- a/src/Marker.js +++ b/src/Marker.js @@ -1,7 +1,7 @@ import Container from './Container.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' -import {nodeOrNew} from './tools.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' +import { nodeOrNew } from './tools.js' export default class Marker extends Container { // Initialize node diff --git a/src/Mask.js b/src/Mask.js index 40ebce7..fb599b9 100644 --- a/src/Mask.js +++ b/src/Mask.js @@ -1,9 +1,9 @@ import Container from './Container.js' -import {nodeOrNew} from './tools.js' +import { nodeOrNew } from './tools.js' import find from './selector.js' -//import {remove} from './Element.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +// import {remove} from './Element.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Mask extends Container { // Initialize node @@ -20,16 +20,14 @@ export default class Mask extends Container { // remove mask from parent return super.remove() - //return remove.call(this) + // return remove.call(this) } targets () { return find('svg [mask*="' + this.id() + '"]') } - } - registerMethods({ Container: { mask () { diff --git a/src/Matrix.js b/src/Matrix.js index e6d3da0..00e4448 100644 --- a/src/Matrix.js +++ b/src/Matrix.js @@ -1,10 +1,10 @@ -import {abcdef, arrayToMatrix, closeEnough, isMatrixLike} from './helpers.js' +import { abcdef, arrayToMatrix, closeEnough, isMatrixLike } from './helpers.js' import Point from './Point.js' -import {delimiter} from './regex.js' -import {radians} from './utils.js' +import { delimiter } from './regex.js' +import { radians } from './utils.js' import parser from './parser.js' import Element from './Element.js' -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' export default class Matrix { constructor (...args) { @@ -18,11 +18,11 @@ export default class Matrix { // ensure source as object source = source instanceof Element ? source.matrixify() : typeof source === 'string' ? arrayToMatrix(source.split(delimiter).map(parseFloat)) - : Array.isArray(source) ? arrayToMatrix(source) - : (typeof source === 'object' && isMatrixLike(source)) ? source - : (typeof source === 'object') ? new Matrix().transform(source) - : arguments.length === 6 ? arrayToMatrix([].slice.call(arguments)) - : base + : Array.isArray(source) ? arrayToMatrix(source) + : (typeof source === 'object' && isMatrixLike(source)) ? source + : (typeof source === 'object') ? new Matrix().transform(source) + : arguments.length === 6 ? arrayToMatrix([].slice.call(arguments)) + : base // Merge the source matrix with the base matrix this.a = source.a != null ? source.a : base.a @@ -33,7 +33,6 @@ export default class Matrix { this.f = source.f != null ? source.f : base.f } - // Clones this matrix clone () { return new Matrix(this) @@ -249,7 +248,7 @@ export default class Matrix { y = x } - let {a, b, c, d, e, f} = this + let { a, b, c, d, e, f } = this this.a = a * x this.b = b * y @@ -273,7 +272,7 @@ export default class Matrix { let cos = Math.cos(r) let sin = Math.sin(r) - let {a, b, c, d, e, f} = this + let { a, b, c, d, e, f } = this this.a = a * cos - b * sin this.b = b * cos + a * sin @@ -293,7 +292,7 @@ export default class Matrix { flipO (axis, around) { return axis === 'x' ? this.scaleO(-1, 1, around, 0) : axis === 'y' ? this.scaleO(1, -1, 0, around) - : this.scaleO(-1, -1, axis, around || axis) // Define an x, y flip point + : this.scaleO(-1, -1, axis, around || axis) // Define an x, y flip point } // Shear matrix @@ -302,7 +301,7 @@ export default class Matrix { } shearO (lx, cx = 0, cy = 0) { - let {a, b, c, d, e, f} = this + let { a, b, c, d, e, f } = this this.a = a + b * lx this.c = c + d * lx @@ -331,7 +330,7 @@ export default class Matrix { let lx = Math.tan(x) let ly = Math.tan(y) - let {a, b, c, d, e, f} = this + let { a, b, c, d, e, f } = this this.a = a + b * lx this.b = b + a * ly @@ -413,7 +412,6 @@ export default class Matrix { } } - // TODO: Refactor this to a static function of matrix.js static formatTransforms (o) { // Get all of the parameters required to form the matrix @@ -422,20 +420,20 @@ export default class Matrix { var flipY = o.flip && (flipBoth || o.flip === 'y') ? -1 : 1 var skewX = o.skew && o.skew.length ? o.skew[0] : isFinite(o.skew) ? o.skew - : isFinite(o.skewX) ? o.skewX - : 0 + : isFinite(o.skewX) ? o.skewX + : 0 var skewY = o.skew && o.skew.length ? o.skew[1] : isFinite(o.skew) ? o.skew - : isFinite(o.skewY) ? o.skewY - : 0 + : isFinite(o.skewY) ? o.skewY + : 0 var scaleX = o.scale && o.scale.length ? o.scale[0] * flipX : isFinite(o.scale) ? o.scale * flipX - : isFinite(o.scaleX) ? o.scaleX * flipX - : flipX + : isFinite(o.scaleX) ? o.scaleX * flipX + : flipX var scaleY = o.scale && o.scale.length ? o.scale[1] * flipY : isFinite(o.scale) ? o.scale * flipY - : isFinite(o.scaleY) ? o.scaleY * flipY - : flipY + : isFinite(o.scaleY) ? o.scaleY * flipY + : flipY var shear = o.shear || 0 var theta = o.rotate || o.theta || 0 var origin = new Point(o.origin || o.around || o.ox || o.originX, o.oy || o.originY) diff --git a/src/Morphable.js b/src/Morphable.js index 18f5a3b..f9dd7f0 100644 --- a/src/Morphable.js +++ b/src/Morphable.js @@ -1,13 +1,10 @@ -import {extend} from './tools.js' -import {Ease} from './Controller.js' +import { extend } from './tools.js' +import { Ease } from './Controller.js' import Color from './Color.js' import SVGNumber from './SVGNumber.js' import SVGArray from './SVGArray.js' -import PointArray from './PointArray.js' import PathArray from './PathArray.js' -import Box from './Box.js' -import Matrix from './Matrix.js' -import {delimiter, pathLetters, numberAndUnit} from './regex.js' +import { delimiter, pathLetters, numberAndUnit } from './regex.js' export default class Morphable { constructor (stepper) { diff --git a/src/Path.js b/src/Path.js index 42ab411..3557e22 100644 --- a/src/Path.js +++ b/src/Path.js @@ -1,10 +1,10 @@ -import {proportionalSize} from './helpers.js' -import {nodeOrNew} from './tools.js' +import { proportionalSize } from './helpers.js' +import { nodeOrNew } from './tools.js' import Shape from './Shape.js' import PathArray from './PathArray.js' import find from './selector.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Path extends Shape { // Initialize node diff --git a/src/PathArray.js b/src/PathArray.js index 8529bf9..5c4fa5e 100644 --- a/src/PathArray.js +++ b/src/PathArray.js @@ -1,10 +1,10 @@ -import {arrayToString, pathRegReplace} from './helpers.js' +import { arrayToString, pathRegReplace } from './helpers.js' import parser from './parser.js' -import {numbersWithDots, pathLetters, hyphen, delimiter, isPathLetter} from './regex.js' +import { numbersWithDots, pathLetters, hyphen, delimiter, isPathLetter } from './regex.js' import Point from './Point.js' import SVGArray from './SVGArray.js' -import {subClassArray} from './ArrayPolyfill.js' -import {extend} from './tools.js' +import { subClassArray } from './ArrayPolyfill.js' +import { extend } from './tools.js' const PathArray = subClassArray('PathArray', SVGArray) @@ -83,7 +83,6 @@ for (var i = 0, il = mlhvqtcsaz.length; i < il; ++i) { })(mlhvqtcsaz[i].toUpperCase()) } - extend(PathArray, { // Convert array to string toString () { @@ -246,9 +245,9 @@ extend(PathArray, { array = array .replace(numbersWithDots, pathRegReplace) // convert 45.123.123 to 45.123 .123 .replace(pathLetters, ' $& ') // put some room between letters and numbers - .replace(hyphen, '$1 -') // add space before hyphen - .trim() // trim - .split(delimiter) // split into array + .replace(hyphen, '$1 -') // add space before hyphen + .trim() // trim + .split(delimiter) // split into array } else { array = array.reduce(function (prev, curr) { return [].concat.call(prev, curr) @@ -275,9 +274,9 @@ extend(PathArray, { } result.push(pathHandlers[s].call(null, - array.slice(index, (index = index + paramCnt[s.toUpperCase()])).map(parseFloat), - p, p0 - ) + array.slice(index, (index = index + paramCnt[s.toUpperCase()])).map(parseFloat), + p, p0 + ) ) } while (len > index) diff --git a/src/Pattern.js b/src/Pattern.js index 0c26d79..6f56e58 100644 --- a/src/Pattern.js +++ b/src/Pattern.js @@ -1,9 +1,10 @@ import Container from './Container.js' -import {nodeOrNew} from './tools.js' -//import attr from './attr.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew } from './tools.js' +// import attr from './attr.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' import Box from './Box.js' +import { find } from './selector.js' export default class Pattern extends Container { // Initialize node @@ -38,7 +39,7 @@ export default class Pattern extends Container { attr (a, b, c) { if (a === 'transform') a = 'patternTransform' return super.attr(a, b, c) - //return attr.call(this, a, b, c) + // return attr.call(this, a, b, c) } targets () { diff --git a/src/Point.js b/src/Point.js index 7f8e2c3..a2b119c 100644 --- a/src/Point.js +++ b/src/Point.js @@ -1,16 +1,16 @@ import parser from './parser.js' -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' export default class Point { // Initialize constructor (x, y, base) { let source - base = base || {x: 0, y: 0} + base = base || { x: 0, y: 0 } // ensure source as object - source = Array.isArray(x) ? {x: x[0], y: x[1]} - : typeof x === 'object' ? {x: x.x, y: x.y} - : {x: x, y: y} + 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 diff --git a/src/PointArray.js b/src/PointArray.js index 1bf5460..68aeddc 100644 --- a/src/PointArray.js +++ b/src/PointArray.js @@ -1,7 +1,7 @@ import SVGArray from './SVGArray.js' -import {delimiter} from './regex.js' -import {subClassArray} from './ArrayPolyfill.js' -import {extend} from './tools.js' +import { delimiter } from './regex.js' +import { subClassArray } from './ArrayPolyfill.js' +import { extend } from './tools.js' const PointArray = subClassArray('PointArray', SVGArray) @@ -115,7 +115,7 @@ extend(PointArray, { minX = Math.min(el[0], minX) minY = Math.min(el[1], minY) }) - return {x: minX, y: minY, width: maxX - minX, height: maxY - minY} + return { x: minX, y: minY, width: maxX - minX, height: maxY - minY } } }) diff --git a/src/Polygon.js b/src/Polygon.js index 1272e44..c4afac6 100644 --- a/src/Polygon.js +++ b/src/Polygon.js @@ -1,11 +1,10 @@ -import {proportionalSize} from './helpers.js' import Shape from './Shape.js' -import {nodeOrNew, extend} from './tools.js' +import { nodeOrNew, extend } from './tools.js' import * as pointed from './pointed.js' import * as poly from './poly.js' import PointArray from './PointArray.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Polygon extends Shape { // Initialize node diff --git a/src/Polyline.js b/src/Polyline.js index d651abd..7d1664e 100644 --- a/src/Polyline.js +++ b/src/Polyline.js @@ -1,10 +1,10 @@ import Shape from './Shape.js' -import {nodeOrNew, extend} from './tools.js' +import { nodeOrNew, extend } from './tools.js' import PointArray from './PointArray.js' import * as pointed from './pointed.js' import * as poly from './poly.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Polyline extends Shape { // Initialize node diff --git a/src/Rect.js b/src/Rect.js index 232f591..535f562 100644 --- a/src/Rect.js +++ b/src/Rect.js @@ -1,7 +1,7 @@ import Shape from './Shape.js' -import {nodeOrNew, extend} from './tools.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew } from './tools.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Rect extends Shape { // Initialize node diff --git a/src/Runner.js b/src/Runner.js index b8bafa6..00ddf97 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -1,15 +1,16 @@ -import {isMatrixLike, getOrigin} from './helpers.js' +import { isMatrixLike, getOrigin } from './helpers.js' import Matrix from './Matrix.js' -import {default as Morphable, TransformBag} from './Morphable.js' +import Morphable, { TransformBag } from './Morphable.js' import SVGNumber from './SVGNumber.js' import Timeline from './Timeline.js' -import {Controller, Ease, Stepper} from './Controller.js' -import {noop, timeline} from './defaults.js' -import {extend} from './tools.js' +import { Controller, Ease, Stepper } from './Controller.js' +import { noop, timeline } from './defaults.js' +import { extend } from './tools.js' import Animator from './Animator.js' import Point from './Point.js' -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' import EventTarget from './EventTarget.js' +import Box from './Box.js' // FIXME: What is this doing here? // easing = { @@ -231,7 +232,7 @@ export default class Runner extends EventTarget { var endTime = t * (w + d) - w position = x <= 0 ? Math.round(f(1e-5)) : x < endTime ? f(x) - : Math.round(f(endTime - 1e-5)) + : Math.round(f(endTime - 1e-5)) return position } @@ -269,7 +270,7 @@ export default class Runner extends EventTarget { var justFinished = this._lastTime < this._time && this.time > duration this._lastTime = this._time if (justStarted) { - this.fire('start', this) + this.fire('start', this) } // Work out if the runner is finished set the done flag here so animations @@ -441,7 +442,7 @@ export default class Runner extends EventTarget { Runner.id = 0 -class FakeRunner{ +class FakeRunner { constructor (transforms = new Matrix(), id = -1, done = true) { this.transforms = transforms this.id = id @@ -601,7 +602,6 @@ registerMethods({ } }) - extend(Runner, { attr (a, v) { return this.styleAttr('attr', a, v) @@ -707,9 +707,9 @@ extend(Runner, { // on this runner. We are absolute. We dont need these! if (!relative) this.clearTransform() - let {x, y} = new Point(origin).transform(element._currentTransform(this)) + let { x, y } = new Point(origin).transform(element._currentTransform(this)) - let target = new Matrix({...transforms, origin: [x, y]}) + let target = new Matrix({ ...transforms, origin: [x, y] }) let start = this._isDeclarative && current ? current : startTransform @@ -762,7 +762,7 @@ extend(Runner, { } // overwrite the old transformations with the new ones - transforms = {...newTransforms, origin} + transforms = { ...newTransforms, origin } } this.queue(setup, run, retarget) diff --git a/src/SVGArray.js b/src/SVGArray.js index a442aad..247f0b2 100644 --- a/src/SVGArray.js +++ b/src/SVGArray.js @@ -1,7 +1,6 @@ -/* global arrayClone */ -import {delimiter} from './regex.js' -import {subClassArray} from './ArrayPolyfill.js' -import {extend} from './tools.js' +import { delimiter } from './regex.js' +import { subClassArray } from './ArrayPolyfill.js' +import { extend } from './tools.js' const SVGArray = subClassArray('SVGArray', Array, function (...args) { this.init(...args) @@ -11,7 +10,7 @@ export default SVGArray extend(SVGArray, { init (...args) { - //this.splice(0, this.length) + // this.splice(0, this.length) this.length = 0 this.push(...this.parse(...args)) }, @@ -37,7 +36,7 @@ extend(SVGArray, { // Parse whitespace separated string parse (array = []) { - //array = array.valueOf() + // array = array.valueOf() // If already is an array, no need to parse it if (array instanceof Array) return array @@ -51,7 +50,7 @@ extend(SVGArray, { toSet () { return new Set(this) - }, + } }) // export default class SVGArray extends BaseArray { diff --git a/src/SVGNumber.js b/src/SVGNumber.js index e07b521..095e2e7 100644 --- a/src/SVGNumber.js +++ b/src/SVGNumber.js @@ -1,4 +1,4 @@ -import {numberAndUnit} from './regex.js' +import { numberAndUnit } from './regex.js' // Module for unit convertions export default class SVGNumber { @@ -45,7 +45,7 @@ export default class SVGNumber { toString () { return (this.unit === '%' ? ~~(this.value * 1e8) / 1e6 : this.unit === 's' ? this.value / 1e3 - : this.value + : this.value ) + this.unit } @@ -53,7 +53,6 @@ export default class SVGNumber { return this.toString() } - toArray () { return [this.value, this.unit] } diff --git a/src/Stop.js b/src/Stop.js index 7db6027..df33dbf 100644 --- a/src/Stop.js +++ b/src/Stop.js @@ -1,7 +1,7 @@ import Element from './Element.js' import SVGNumber from './SVGNumber.js' -import {nodeOrNew} from './tools.js' -import {register} from './adopter.js' +import { nodeOrNew } from './tools.js' +import { register } from './adopter.js' export default class Stop extends Element { constructor (node) { diff --git a/src/Symbol.js b/src/Symbol.js index 22d85da..9efb86c 100644 --- a/src/Symbol.js +++ b/src/Symbol.js @@ -1,7 +1,7 @@ import Container from './Container.js' -import {nodeOrNew} from './tools.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew } from './tools.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Symbol extends Container { // Initialize node diff --git a/src/Text.js b/src/Text.js index 55fed22..1b4c442 100644 --- a/src/Text.js +++ b/src/Text.js @@ -1,19 +1,19 @@ import Shape from './Shape.js' import SVGNumber from './SVGNumber.js' -import {nodeOrNew, extend} from './tools.js' -import {attrs} from './defaults.js' +import { nodeOrNew, extend } from './tools.js' +import { attrs } from './defaults.js' import * as textable from './textable.js' -import {register, adopt} from './adopter.js' -import {registerMethods} from './methods.js' +import { register, adopt } from './adopter.js' +import { registerMethods } from './methods.js' export default class Text extends Shape { // Initialize node constructor (node) { super(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 - this._build = false // disable build mode for adding multiple lines + this.dom.leading = new SVGNumber(1.3) // store leading value for rebuilding + this._rebuild = true // enable automatic updating of dy values + this._build = false // disable build mode for adding multiple lines // set default font this.attr('font-family', attrs['font-family']) diff --git a/src/TextPath.js b/src/TextPath.js index df5b690..ce5115b 100644 --- a/src/TextPath.js +++ b/src/TextPath.js @@ -1,10 +1,10 @@ import Path from './Path.js' import Text from './Text.js' import PathArray from './PathArray.js' -import {nodeOrNew} from './tools.js' -import {xlink} from './namespaces.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { nodeOrNew } from './tools.js' +import { xlink } from './namespaces.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class TextPath extends Text { // Initialize node @@ -44,7 +44,7 @@ registerMethods({ } }, Text: { - // Create path for text to run on + // Create path for text to run on path: function (track) { var path = new TextPath() diff --git a/src/Timeline.js b/src/Timeline.js index e6e9e43..c5ce9d3 100644 --- a/src/Timeline.js +++ b/src/Timeline.js @@ -1,5 +1,5 @@ import Animator from './Animator.js' -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' var time = window.performance || Date @@ -7,7 +7,7 @@ var makeSchedule = function (runnerInfo) { var start = runnerInfo.start var duration = runnerInfo.runner.duration() var end = start + duration - return {start: start, duration: duration, end: end, runner: runnerInfo.runner} + return { start: start, duration: duration, end: end, runner: runnerInfo.runner } } export default class Timeline { diff --git a/src/Tspan.js b/src/Tspan.js index 148fb16..f3a9469 100644 --- a/src/Tspan.js +++ b/src/Tspan.js @@ -1,8 +1,8 @@ import Text from './Text.js' -import {nodeOrNew, extend} from './tools.js' +import { nodeOrNew, extend } from './tools.js' import * as textable from './textable.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' export default class Tspan extends Text { // Initialize node @@ -1,8 +1,8 @@ import Shape from './Shape.js' -import {xlink} from './namespaces.js' -import {register} from './adopter.js' -import {registerMethods} from './methods.js' -import {nodeOrNew} from './tools.js' +import { xlink } from './namespaces.js' +import { register } from './adopter.js' +import { registerMethods } from './methods.js' +import { nodeOrNew } from './tools.js' export default class Use extends Shape { constructor (node) { diff --git a/src/adopter.js b/src/adopter.js index 61b1e83..ed692b8 100644 --- a/src/adopter.js +++ b/src/adopter.js @@ -1,6 +1,6 @@ import Base from './Base.js' -import {capitalize} from './helpers.js' -import {makeNode} from './tools.js' +import { capitalize } from './helpers.js' +import { makeNode } from './tools.js' const elements = {} export const root = Symbol('root') @@ -30,7 +30,6 @@ export function makeInstance (element) { return element } - // Adopt existing svg elements export function adopt (node) { // check for presence of node @@ -66,7 +65,7 @@ export function register (element, name = element.name, asRoot = false) { return element } -export function getClass(name) { +export function getClass (name) { return elements[name] } diff --git a/src/arrange.js b/src/arrange.js index d0a5b23..169cf93 100644 --- a/src/arrange.js +++ b/src/arrange.js @@ -1,5 +1,5 @@ // ### This module adds backward / forward functionality to elements. -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' // Get all siblings, including myself export function siblings () { @@ -30,7 +30,7 @@ export function forward () { p.removeElement(this).add(this, i) // make sure defs node is always at the top - if (typeof p.isRoot == 'function' && p.isRoot()) { + if (typeof p.isRoot === 'function' && p.isRoot()) { p.node.appendChild(p.defs().node) } @@ -56,7 +56,7 @@ export function front () { p.node.appendChild(this.node) // Make sure defs node is always at the top - if (typeof p.isRoot == 'function' && p.isRoot()) { + if (typeof p.isRoot === 'function' && p.isRoot()) { p.node.appendChild(p.defs().node) } diff --git a/src/attr.js b/src/attr.js index c44fa68..cccc340 100644 --- a/src/attr.js +++ b/src/attr.js @@ -1,9 +1,9 @@ -import {isNumber, isImage} from './regex.js' -import {attrs as defaults} from './defaults.js' +import { isNumber, isImage } from './regex.js' +import { attrs as defaults } from './defaults.js' import Color from './Color.js' import SVGArray from './SVGArray.js' import SVGNumber from './SVGNumber.js' -//import {registerMethods} from './methods.js' +// import {registerMethods} from './methods.js' // Set svg element attribute export default function attr (attr, val, ns) { @@ -26,14 +26,14 @@ export default function attr (attr, val, ns) { // apply every attribute individually if an object is passed for (val in attr) this.attr(val, attr[val]) } else if (val === null) { - // remove value + // remove value this.node.removeAttribute(attr) } else if (val == null) { // act as a getter if the first and only argument is not an object val = this.node.getAttribute(attr) return val == null ? defaults[attr] // FIXME: do we need to return defaults? : isNumber.test(val) ? parseFloat(val) - : val + : val } else { // convert image fill and stroke to patterns if (attr === 'fill' || attr === 'stroke') { @@ -44,7 +44,7 @@ export default function attr (attr, val, ns) { // FIXME: This is fine, but what about the lines above? // How does attr know about image()? - while (typeof val.attrHook == 'function') { + while (typeof val.attrHook === 'function') { val = val.attrHook(this, attr) } @@ -80,4 +80,4 @@ export default function attr (attr, val, ns) { return this } -//registerMethods('Element', {attr}) +// registerMethods('Element', {attr}) diff --git a/src/circled.js b/src/circled.js index 70fafef..7df7a5b 100644 --- a/src/circled.js +++ b/src/circled.js @@ -1,5 +1,5 @@ // FIXME: import this to runner -import {proportionalSize} from './helpers.js' +import { proportionalSize } from './helpers.js' import SVGNumber from './SVGNumber.js' // Radius x value diff --git a/src/classHandling.js b/src/classHandling.js index 27bf11a..fd148b7 100644 --- a/src/classHandling.js +++ b/src/classHandling.js @@ -1,5 +1,5 @@ -import {registerMethods} from './methods.js' -import {delimiter} from './regex.js' +import { registerMethods } from './methods.js' +import { delimiter } from './regex.js' // Return array of classes on the node function classes () { diff --git a/src/classes.js b/src/classes.js index 283baaa..a4cc758 100644 --- a/src/classes.js +++ b/src/classes.js @@ -1,47 +1,47 @@ -export {default as EventTarget} from './EventTarget.js' -export {default as Dom} from './Dom.js' -export {default as Element} from './Element.js' -export {default as Shape} from './Shape.js' -export {default as Container} from './Container.js' -export {default as HtmlNode} from './HtmlNode.js' -export {default as Doc} from './Doc.js' -export {default as Defs} from './Defs.js' -export {default as G} from './G.js' -export {default as Animator} from './Animator.js' -export {default as Bare} from './Bare.js' -export {default as Circle} from './Circle.js' -export {default as ClipPath} from './ClipPath.js' -export {default as A} from './A.js' -export {default as Ellipse} from './Ellipse.js' -export {default as Stop} from './Stop.js' -export {default as Gradient} from './Gradient.js' -export {default as Image} from './Image.js' -export {default as Line} from './Line.js' -export {default as Marker} from './Marker.js' -export {default as Mask} from './Mask.js' -export {default as Path} from './Path.js' -export {default as Pattern} from './Pattern.js' -export {default as Polygon} from './Polygon.js' -export {default as Polyline} from './Polyline.js' -export {default as Rect} from './Rect.js' -export {default as Symbol} from './Symbol.js' -export {default as Text} from './Text.js' -export {default as TextPath} from './TextPath.js' -export {default as Tspan} from './Tspan.js' -export {default as Use} from './Use.js' -export {default as SVGNumber} from './SVGNumber.js' -export {default as SVGArray} from './SVGArray.js' -export {default as PathArray} from './PathArray.js' -export {default as PointArray} from './PointArray.js' -export {default as Matrix} from './Matrix.js' -export {default as Point} from './Point.js' -export {default as Box} from './Box.js' -export {default as Color} from './Color.js' -export {default as Morphable} from './Morphable.js' -export {default as Queue} from './Queue.js' -export {default as Runner} from './Runner.js' -export {default as Timeline} from './Timeline.js' -export {Controller, Ease, PID, Spring} from './Controller.js' +export { default as EventTarget } from './EventTarget.js' +export { default as Dom } from './Dom.js' +export { default as Element } from './Element.js' +export { default as Shape } from './Shape.js' +export { default as Container } from './Container.js' +export { default as HtmlNode } from './HtmlNode.js' +export { default as Doc } from './Doc.js' +export { default as Defs } from './Defs.js' +export { default as G } from './G.js' +export { default as Animator } from './Animator.js' +export { default as Bare } from './Bare.js' +export { default as Circle } from './Circle.js' +export { default as ClipPath } from './ClipPath.js' +export { default as A } from './A.js' +export { default as Ellipse } from './Ellipse.js' +export { default as Stop } from './Stop.js' +export { default as Gradient } from './Gradient.js' +export { default as Image } from './Image.js' +export { default as Line } from './Line.js' +export { default as Marker } from './Marker.js' +export { default as Mask } from './Mask.js' +export { default as Path } from './Path.js' +export { default as Pattern } from './Pattern.js' +export { default as Polygon } from './Polygon.js' +export { default as Polyline } from './Polyline.js' +export { default as Rect } from './Rect.js' +export { default as Symbol } from './Symbol.js' +export { default as Text } from './Text.js' +export { default as TextPath } from './TextPath.js' +export { default as Tspan } from './Tspan.js' +export { default as Use } from './Use.js' +export { default as SVGNumber } from './SVGNumber.js' +export { default as SVGArray } from './SVGArray.js' +export { default as PathArray } from './PathArray.js' +export { default as PointArray } from './PointArray.js' +export { default as Matrix } from './Matrix.js' +export { default as Point } from './Point.js' +export { default as Box } from './Box.js' +export { default as Color } from './Color.js' +export { default as Morphable } from './Morphable.js' +export { default as Queue } from './Queue.js' +export { default as Runner } from './Runner.js' +export { default as Timeline } from './Timeline.js' +export { Controller, Ease, PID, Spring } from './Controller.js' // export {default as Animator} from './Animator.js' // export {default as SVGArray} from './SVGArray.js' diff --git a/src/containers.js b/src/containers.js index 675c307..02869e4 100644 --- a/src/containers.js +++ b/src/containers.js @@ -1,15 +1,15 @@ -export {default as Bare} from './Bare.js' -export {default as ClipPath} from './ClipPath.js' -export {default as Defs} from './Defs.js' -export {default as Doc} from './Doc.js' -export {default as Gradient} from './Gradient.js' -export {default as G} from './G.js' -export {default as A} from './A.js' -export {default as Marker} from './Marker.js' -export {default as Mask} from './Mask.js' -export {default as Pattern} from './Pattern.js' -export {default as Symbol} from './Symbol.js' +export { default as Bare } from './Bare.js' +export { default as ClipPath } from './ClipPath.js' +export { default as Defs } from './Defs.js' +export { default as Doc } from './Doc.js' +export { default as Gradient } from './Gradient.js' +export { default as G } from './G.js' +export { default as A } from './A.js' +export { default as Marker } from './Marker.js' +export { default as Mask } from './Mask.js' +export { default as Pattern } from './Pattern.js' +export { default as Symbol } from './Symbol.js' -export {default as Text} from './Text.js' -export {default as Tspan} from './Tspan.js' -export {default as TextPath} from './TextPath.js' +export { default as Text } from './Text.js' +export { default as Tspan } from './Tspan.js' +export { default as TextPath } from './TextPath.js' @@ -1,21 +1,20 @@ -import {camelCase} from './helpers.js' -import {isBlank} from './regex.js' -import {registerMethods} from './methods.js' +import { camelCase } from './helpers.js' +import { isBlank } from './regex.js' +import { registerMethods } from './methods.js' // FIXME: We dont need exports - // Dynamic style generator +// Dynamic style generator export function css (style, val) { let ret = {} - let i if (arguments.length === 0) { // get full style as object this.node.style.cssText.split(/\s*;\s*/) .filter(function (el) { return !!el.length }) .forEach(function (el) { - let t = el.split(/\s*:\s*/) - ret[t[0]] = t[1] - }) + let t = el.split(/\s*:\s*/) + ret[t[0]] = t[1] + }) return ret } @@ -36,7 +35,7 @@ export function css (style, val) { // set styles in object if (typeof style === 'object') { - for (name in style) { + for (let name in style) { // set empty string if null/undefined/'' was given this.node.style[camelCase(name)] = (style[name] == null || isBlank.test(style[name])) ? '' : style[name] @@ -53,17 +52,17 @@ export function css (style, val) { return this } - // Show element +// Show element export function show () { return this.css('display', '') } - // Hide element +// Hide element export function hide () { return this.css('display', 'none') } - // Is element visible? +// Is element visible? export function visible () { return this.css('display') !== 'none' } diff --git a/src/data.js b/src/data.js index 6374987..ce50abb 100644 --- a/src/data.js +++ b/src/data.js @@ -1,4 +1,4 @@ -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' // Store data values on svg nodes export function data (a, v, r) { @@ -15,12 +15,12 @@ export function data (a, v, r) { } else { this.attr('data-' + a, v === null ? null - : r === true || typeof v === 'string' || typeof v === 'number' ? v - : JSON.stringify(v) + : r === true || typeof v === 'string' || typeof v === 'number' ? v + : JSON.stringify(v) ) } return this } -registerMethods('Dom', {data}) +registerMethods('Dom', { data }) diff --git a/src/elements.js b/src/elements.js index c251f25..b09d6e8 100644 --- a/src/elements.js +++ b/src/elements.js @@ -1,25 +1,25 @@ -export {default as Bare} from './Bare.js' -export {default as Circle} from './Circle.js' -export {default as ClipPath} from './ClipPath.js' -export {default as Defs} from './Defs.js' -export {default as Doc} from './Doc.js' -export {default as Ellipse} from './Ellipse.js' -export {default as Gradient} from './Gradient.js' -export {default as G} from './G.js' -export {default as HtmlNode} from './HtmlNode.js' -export {default as A} from './A.js' -export {default as Image} from './Image.js' -export {default as Line} from './Line.js' -export {default as Marker} from './Marker.js' -export {default as Mask} from './Mask.js' -export {default as Path} from './Path.js' -export {default as Pattern} from './Pattern.js' -export {default as Polygon} from './Polygon.js' -export {default as Polyline} from './Polyline.js' -export {default as Rect} from './Rect.js' -export {default as Stop} from './Stop.js' -export {default as Symbol} from './Symbol.js' -export {default as Text} from './Text.js' -export {default as TextPath} from './TextPath.js' -export {default as Tspan} from './Tspan.js' -export {default as Use} from './Use.js' +export { default as Bare } from './Bare.js' +export { default as Circle } from './Circle.js' +export { default as ClipPath } from './ClipPath.js' +export { default as Defs } from './Defs.js' +export { default as Doc } from './Doc.js' +export { default as Ellipse } from './Ellipse.js' +export { default as Gradient } from './Gradient.js' +export { default as G } from './G.js' +export { default as HtmlNode } from './HtmlNode.js' +export { default as A } from './A.js' +export { default as Image } from './Image.js' +export { default as Line } from './Line.js' +export { default as Marker } from './Marker.js' +export { default as Mask } from './Mask.js' +export { default as Path } from './Path.js' +export { default as Pattern } from './Pattern.js' +export { default as Polygon } from './Polygon.js' +export { default as Polyline } from './Polyline.js' +export { default as Rect } from './Rect.js' +export { default as Stop } from './Stop.js' +export { default as Symbol } from './Symbol.js' +export { default as Text } from './Text.js' +export { default as TextPath } from './TextPath.js' +export { default as Tspan } from './Tspan.js' +export { default as Use } from './Use.js' diff --git a/src/elemnts-svg.js b/src/elemnts-svg.js index 5ee97b7..b5b2542 100644 --- a/src/elemnts-svg.js +++ b/src/elemnts-svg.js @@ -1,63 +1,68 @@ - // Import raw svg - svg: function (svg, fn = false) { - var well, len - - // act as getter if no svg string is given - if(svg == null || svg === true || typeof svg == 'function') { - // write svgjs data to the dom - this.writeDataToDom() - let current = this - - // An export modifier was passed - if (typeof svg == 'function') { - // Juggle arguments - [fn, svg] = [svg, fn] - - // If the user wants outerHTML we need to process this node, too - if (!svg) { - current = fn(current) - - // The user does not want this node? Well, then he gets nothing - if (current === false) return '' - } +import { ns } from './namespaces.js' - // Deep loop through all children and apply modifier - current.each(function () { - let result = fn(this) +/* eslint no-unused-vars: "off" */ +var a = { + // Import raw svg + svg (svg, fn = false) { + var well, len, fragment - // If modifier returns false, discard node - if (result === false) { - this.remove() + // act as getter if no svg string is given + if (svg == null || svg === true || typeof svg === 'function') { + // write svgjs data to the dom + this.writeDataToDom() + let current = this - // If modifier returns new node, use it - } else if (result !== this) { - this.replace(result) - } - }, true) + // An export modifier was passed + if (typeof svg === 'function') { + // Juggle arguments + [fn, svg] = [svg, fn] + + // If the user wants outerHTML we need to process this node, too + if (!svg) { + current = fn(current) + + // The user does not want this node? Well, then he gets nothing + if (current === false) return '' } - // Return outer or inner content - return svg - ? current.node.innerHTML - : current.node.outerHTML + // Deep loop through all children and apply modifier + current.each(function () { + let result = fn(this) + + // If modifier returns false, discard node + if (result === false) { + this.remove() + + // If modifier returns new node, use it + } else if (result !== this) { + this.replace(result) + } + }, true) } - // Act as setter if we got a string + // Return outer or inner content + return svg + ? current.node.innerHTML + : current.node.outerHTML + } - // Create temporary holder - well = document.createElementNS(SVG.ns, 'svg') - fragment = document.createDocumentFragment() + // Act as setter if we got a string - // Dump raw svg - well.innerHTML = svg + // Create temporary holder + well = document.createElementNS(ns, 'svg') + fragment = document.createDocumentFragment() - // Transplant nodes into the fragment - for (len = well.children.length; len--;) { - fragment.appendChild(well.firstElementChild) - } + // Dump raw svg + well.innerHTML = svg + + // Transplant nodes into the fragment + for (len = well.children.length; len--;) { + fragment.appendChild(well.firstElementChild) + } - // Add the whole fragment at once - this.node.appendChild(fragment) + // Add the whole fragment at once + this.node.appendChild(fragment) - return this - }, + return this + } +} diff --git a/src/event.js b/src/event.js index 2aa9daf..8cd4188 100644 --- a/src/event.js +++ b/src/event.js @@ -1,6 +1,5 @@ -import {delimiter} from './regex.js' -import {registerMethods} from './methods.js' -import {makeInstance} from './adopter.js' +import { delimiter } from './regex.js' +import { makeInstance } from './adopter.js' let listenerId = 0 @@ -125,7 +124,7 @@ export function dispatch (node, event, data) { if (event instanceof window.Event) { n.dispatchEvent(event) } else { - event = new window.CustomEvent(event, {detail: data, cancelable: true}) + event = new window.CustomEvent(event, { detail: data, cancelable: true }) n.dispatchEvent(event) } return event diff --git a/src/helpers.js b/src/helpers.js index 2248ea9..9bf393c 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,4 +1,4 @@ -import {dots, reference} from './regex.js' +import { dots, reference } from './regex.js' export function isNulledBox (box) { return !box.w && !box.h && !box.x && !box.y @@ -188,10 +188,10 @@ export function getOrigin (o, element) { // Calculate the transformed x and y coordinates let bx = string.includes('left') ? x : string.includes('right') ? x + width - : x + width / 2 + : x + width / 2 let by = string.includes('top') ? y : string.includes('bottom') ? y + height - : y + height / 2 + : y + height / 2 // Set the bounds eg : "bottom-left", "Top right", "middle" etc... ox = o.ox != null ? o.ox : bx diff --git a/src/memory.js b/src/memory.js index a94f0e2..3f81c6f 100644 --- a/src/memory.js +++ b/src/memory.js @@ -1,5 +1,4 @@ -import {registerMethods} from './methods.js' -import {registerConstructor} from './methods.js' +import { registerMethods } from './methods.js' // export const name = 'Memory' // @@ -25,7 +24,7 @@ export function remember (k, v) { return this } - // Erase a given memory +// Erase a given memory export function forget () { if (arguments.length === 0) { this._memory = {} @@ -37,10 +36,10 @@ export function forget () { return this } - // return local memory object +// return local memory object export function memory () { return (this._memory = this._memory || {}) } -registerMethods('Dom', {remember, forget, memory}) -//registerConstructor('Memory', setup) +registerMethods('Dom', { remember, forget, memory }) +// registerConstructor('Memory', setup) diff --git a/src/methods.js b/src/methods.js index 4eb92b9..f926598 100644 --- a/src/methods.js +++ b/src/methods.js @@ -9,7 +9,7 @@ export function registerMethods (name, m) { return } - if (typeof name == 'object') { + if (typeof name === 'object') { for (let [_name, _m] of Object.entries(name)) { registerMethods(_name, _m) } @@ -24,15 +24,14 @@ export function getMethodsFor (name) { } // FIXME: save memory? -export function cleanMethods () { - methods = {} -} - +// export function cleanMethods () { +// methods = {} +// } export function registerConstructor (name, setup) { constructors[name] = setup } export function getConstructor (name) { - return constructors[name] ? {setup: constructors[name], name} : {} + return constructors[name] ? { setup: constructors[name], name } : {} } diff --git a/src/parser.js b/src/parser.js index 9a64dbc..aa58db4 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,7 +1,6 @@ import Doc from './Doc.js' export default function parser () { - // Reuse cached element if possible if (!parser.nodes) { let svg = new Doc().size(2, 0).css({ @@ -14,7 +13,7 @@ export default function parser () { let path = svg.path().node - parser.nodes = {svg, path} + parser.nodes = { svg, path } } if (!parser.nodes.svg.node.parentNode) { diff --git a/src/poly.js b/src/poly.js index 937247a..269b0c9 100644 --- a/src/poly.js +++ b/src/poly.js @@ -1,6 +1,6 @@ // Add polygon-specific functions import PointArray from './PointArray.js' -import {proportionalSize} from './helpers.js' +import { proportionalSize } from './helpers.js' // Get array export function array () { @@ -11,7 +11,7 @@ export function array () { export function plot (p) { return (p == null) ? this.array() : this.clear().attr('points', typeof p === 'string' ? p - : (this._array = new PointArray(p))) + : (this._array = new PointArray(p))) } // Clear array cache diff --git a/src/selector.js b/src/selector.js index c6717fb..6ee1207 100644 --- a/src/selector.js +++ b/src/selector.js @@ -1,7 +1,6 @@ -import {idFromReference} from './helpers.js' -import {map} from './utils.js' -import {adopt} from './adopter.js' -import {registerMethods} from './methods.js' +import { map } from './utils.js' +import { adopt } from './adopter.js' +import { registerMethods } from './methods.js' // // Method for getting an element by id // SVG.get = function (id) { @@ -37,4 +36,4 @@ export function find (query) { return baseFind(query, this.node) } -registerMethods('Dom', {find}) +registerMethods('Dom', { find }) @@ -1,4 +1,5 @@ -SVG.Set = class extends Set { +/* eslint no-unused-vars: "off" */ +class SVGSet extends Set { // constructor (arr) { // super(arr) // } diff --git a/src/sugar.js b/src/sugar.js index 6465985..7d34cee 100644 --- a/src/sugar.js +++ b/src/sugar.js @@ -4,7 +4,7 @@ import SVGNumber from './SVGNumber.js' import Matrix from './Matrix.js' import Point from './Point.js' import Element from './Element.js' -import {registerMethods} from './methods.js' +import { registerMethods } from './methods.js' // Define list of available attributes for stroke and fill var sugar = { @@ -55,18 +55,18 @@ registerMethods(['Element', 'Runner'], { // Map rotation to transform rotate: function (angle, cx, cy) { - return this.transform({rotate: angle, ox: cx, oy: cy}, true) + return this.transform({ rotate: angle, ox: cx, oy: cy }, true) }, // Map skew to transform skew: function (x, y, cx, cy) { return arguments.length === 1 || arguments.length === 3 - ? this.transform({skew: x, ox: y, oy: cx}, true) - : this.transform({skew: [x, y], ox: cx, oy: cy}, true) + ? this.transform({ skew: x, ox: y, oy: cx }, true) + : this.transform({ skew: [x, y], ox: cx, oy: cy }, true) }, shear: function (lam, cx, cy) { - return this.transform({shear: lam, ox: cx, oy: cy}, true) + return this.transform({ shear: lam, ox: cx, oy: cy }, true) }, // Map scale to transform @@ -90,13 +90,13 @@ registerMethods(['Element', 'Runner'], { flip: function (direction, around) { var directionString = typeof direction === 'string' ? direction : isFinite(direction) ? 'both' - : 'both' + : 'both' var origin = (direction === 'both' && isFinite(around)) ? [around, around] : (direction === 'x') ? [around, 0] - : (direction === 'y') ? [0, around] - : isFinite(direction) ? [direction, direction] - : [0, 0] - this.transform({flip: directionString, origin: origin}, true) + : (direction === 'y') ? [0, around] + : isFinite(direction) ? [direction, direction] + : [0, 0] + this.transform({ flip: directionString, origin: origin }, true) }, // Opacity @@ -149,11 +149,11 @@ registerMethods(['Element', 'Runner'], { } return a === 'leading' - ? this.leading(v) + ? this.leading(v) : a === 'anchor' ? this.attr('text-anchor', v) - : a === 'size' || a === 'family' || a === 'weight' || a === 'stretch' || a === 'variant' || a === 'style' - ? this.attr('font-' + a, v) - : this.attr(a, v) + : a === 'size' || a === 'family' || a === 'weight' || a === 'stretch' || a === 'variant' || a === 'style' + ? this.attr('font-' + a, v) + : this.attr(a, v) } }) @@ -1,9 +1,6 @@ -import {makeInstance} from './adopter.js' import * as Classes from './classes.js' import * as adopter from './adopter.js' import * as tools from './tools.js' -import * as containers from './containers.js' -import * as elements from './elements.js' import './attr.js' import './arrange.js' import './data.js' @@ -13,13 +10,24 @@ import './css.js' import './transform.js' import './memory.js' import './sugar.js' -import {getMethodsFor, getConstructor} from './methods.js' -import {registerMorphableType, makeMorphable} from './Morphable.js' -const extend = tools.extend +import { getMethodsFor } from './methods.js' +import { registerMorphableType, makeMorphable, TransformBag, ObjectBag, NonMorphable } from './Morphable.js' import './EventTarget.js' import './Element.js' +import * as utils from './utils.js' + +import * as regex from './regex.js' + +// satisfy tests, fix later +import * as ns from './namespaces.js' +import { easing } from './Controller.js' +import * as events from './event.js' +import parser from './parser.js' +import * as defaults from './defaults.js' +const extend = tools.extend + extend([ Classes.Doc, Classes.Symbol, @@ -56,7 +64,7 @@ extend(Classes.EventTarget, getMethodsFor('EventTarget')) extend(Classes.Dom, getMethodsFor('Dom')) extend(Classes.Element, getMethodsFor('Element')) extend(Classes.Shape, getMethodsFor('Shape')) -//extend(Classes.Element, getConstructor('Memory')) +// extend(Classes.Element, getConstructor('Memory')) extend(Classes.Container, getMethodsFor('Container')) registerMorphableType([ @@ -73,34 +81,21 @@ makeMorphable() // The main wrapping element export default function SVG (element) { - return makeInstance(element) + return adopter.makeInstance(element) } Object.assign(SVG, Classes) Object.assign(SVG, tools) Object.assign(SVG, adopter) - -import * as utils from './utils.js' SVG.utils = utils - -import * as regex from './regex.js' SVG.regex = regex - - -// satisfy tests, fix later -import * as ns from './namespaces.js' SVG.get = SVG SVG.find = find Object.assign(SVG, ns) -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 -import * as defaults from './defaults.js' SVG.defaults = defaults diff --git a/src/tools.js b/src/tools.js index 898f016..14e19a3 100644 --- a/src/tools.js +++ b/src/tools.js @@ -1,5 +1,5 @@ -import {ns} from './namespaces.js' -import {capitalize} from './helpers.js' +import { ns } from './namespaces.js' +import { getClass } from './adopter.js' export function nodeOrNew (name, node) { return node || makeNode(name) @@ -39,6 +39,7 @@ export function invent (config) { // Inherit prototype if (config.inherit) { + /* eslint new-cap: "off" */ initializer.prototype = new config.inherit() initializer.prototype.constructor = initializer } @@ -49,7 +50,7 @@ export function invent (config) { } // Attach construct method to parent - if (config.construct) { extend(config.parent || Container, config.construct) } + if (config.construct) { extend(config.parent || getClass('Container'), config.construct) } return initializer } diff --git a/src/transform.js b/src/transform.js index 907bbfa..ff3364e 100644 --- a/src/transform.js +++ b/src/transform.js @@ -1,7 +1,7 @@ -import {arrayToMatrix, getOrigin, isMatrixLike} from './helpers.js' +import { arrayToMatrix, getOrigin, isMatrixLike } from './helpers.js' import Matrix from './Matrix.js' -import {delimiter, transforms} from './regex.js' -import {registerMethods} from './methods.js' +import { delimiter, transforms } from './regex.js' +import { registerMethods } from './methods.js' // Reset all transformations export function untransform () { @@ -58,7 +58,7 @@ export function transform (o, relative) { if (!isMatrixLike(o)) { // Set the origin according to the defined transform - o = {...o, origin: getOrigin(o, this)} + o = { ...o, origin: getOrigin(o, this) } } // The user can pass a boolean, an Element or an Matrix or nothing diff --git a/src/umd.js b/src/umd.js deleted file mode 100644 index bb8e300..0000000 --- a/src/umd.js +++ /dev/null @@ -1,28 +0,0 @@ - -(function(root, factory) { - /* istanbul ignore next */ - if (typeof define === 'function' && define.amd) { - define(function(){ - return factory(root, root.document) - }) - } else if (typeof exports === 'object') { - module.exports = root.document ? factory(root, root.document) : function(w){ return factory(w, w.document) } - } else { - root.SVG = factory(root, root.document) - } -}(typeof window !== "undefined" ? window : this, function(window, document) { - -// Check that our browser supports svg -var supported = !! document.createElementNS && - !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect - -// If we don't support svg, just exit without doing anything -if (!supported) - return {supported: false} - -// Otherwise, the library will be here -<%= contents %> - -return SVG - -})); |