diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/animation/Morphable.js (renamed from src/types/Morphable.js) | 10 | ||||
-rw-r--r-- | src/animation/Runner.js | 2 | ||||
-rw-r--r-- | src/elements/Bare.js | 31 | ||||
-rw-r--r-- | src/elements/Dom.js | 15 | ||||
-rw-r--r-- | src/elements/HtmlNode.js | 6 | ||||
-rw-r--r-- | src/elements/Style.js | 6 | ||||
-rw-r--r-- | src/main.js | 4 | ||||
-rw-r--r-- | src/utils/adopter.js | 11 |
8 files changed, 28 insertions, 57 deletions
diff --git a/src/types/Morphable.js b/src/animation/Morphable.js index 703cc00..a02ba31 100644 --- a/src/types/Morphable.js +++ b/src/animation/Morphable.js @@ -1,14 +1,14 @@ -import { Ease } from '../animation/Controller.js' +import { Ease } from './Controller.js' import { delimiter, numberAndUnit, pathLetters } from '../modules/core/regex.js' import { extend } from '../utils/adopter.js' -import Color from './Color.js' -import PathArray from './PathArray.js' -import SVGArray from './SVGArray.js' -import SVGNumber from './SVGNumber.js' +import Color from '../types/Color.js' +import PathArray from '../types/PathArray.js' +import SVGArray from '../types/SVGArray.js' +import SVGNumber from '../types/SVGNumber.js' export default class Morphable { constructor (stepper) { diff --git a/src/animation/Runner.js b/src/animation/Runner.js index 5551162..bb8d5e7 100644 --- a/src/animation/Runner.js +++ b/src/animation/Runner.js @@ -9,7 +9,7 @@ import Animator from './Animator.js' import Box from '../types/Box.js' import EventTarget from '../types/EventTarget.js' import Matrix from '../types/Matrix.js' -import Morphable, { TransformBag } from '../types/Morphable.js' +import Morphable, { TransformBag } from './Morphable.js' import Point from '../types/Point.js' import SVGNumber from '../types/SVGNumber.js' import Timeline from './Timeline.js' diff --git a/src/elements/Bare.js b/src/elements/Bare.js deleted file mode 100644 index a057634..0000000 --- a/src/elements/Bare.js +++ /dev/null @@ -1,31 +0,0 @@ -import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js' -import { registerMethods } from '../utils/methods.js' -import Container from './Container.js' -import { globals } from '../utils/window.js' - -export default class Bare extends Container { - constructor (node, attrs) { - super(nodeOrNew(node, typeof node === 'string' ? null : node), attrs) - } - - words (text) { - // remove contents - while (this.node.hasChildNodes()) { - this.node.removeChild(this.node.lastChild) - } - - // create text node - this.node.appendChild(globals.document.createTextNode(text)) - - return this - } -} - -register(Bare) - -registerMethods('Container', { - // Create an element that is not described by SVG.js - element: wrapWithAttrCheck(function (node) { - return this.put(new Bare(node)) - }) -}) diff --git a/src/elements/Dom.js b/src/elements/Dom.js index 2fcedce..5d7dbac 100644 --- a/src/elements/Dom.js +++ b/src/elements/Dom.js @@ -4,6 +4,7 @@ import { eid, extend, makeInstance, + makeNode, register } from '../utils/adopter.js' import { find } from '../modules/core/selector' @@ -88,6 +89,10 @@ export default class Dom extends EventTarget { return this } + element (nodeName) { + return this.put(new Dom(makeNode(nodeName))) + } + // Get first child first () { return adopt(this.node.firstChild) @@ -285,12 +290,20 @@ export default class Dom extends EventTarget { fragment.appendChild(well.firstElementChild) } + let parent = this.parent() + // Add the whole fragment at once return outerHTML - ? this.replace(fragment) + ? this.replace(fragment) && parent : this.add(fragment) } + words (text) { + // This is faster than removing all children and adding a new one + this.node.textContent = text + return this + } + // write svgjs data to the dom writeDataToDom () { // dump variables recursively diff --git a/src/elements/HtmlNode.js b/src/elements/HtmlNode.js deleted file mode 100644 index 009b122..0000000 --- a/src/elements/HtmlNode.js +++ /dev/null @@ -1,6 +0,0 @@ -import { register } from '../utils/adopter.js' -import Dom from './Dom.js' - -export default class HtmlNode extends Dom {} - -register(HtmlNode) diff --git a/src/elements/Style.js b/src/elements/Style.js index 50ec50e..0b1cdb7 100644 --- a/src/elements/Style.js +++ b/src/elements/Style.js @@ -23,8 +23,8 @@ export default class Style extends Element { super(nodeOrNew('style', node), node) } - words (w) { - this.node.textContent += (w || '') + addText (w = '') { + this.node.textContent += w return this } @@ -37,7 +37,7 @@ export default class Style extends Element { } rule (selector, obj) { - return this.words(cssRule(selector, obj)) + return this.addText(cssRule(selector, obj)) } } diff --git a/src/main.js b/src/main.js index 919fb25..696dfdd 100644 --- a/src/main.js +++ b/src/main.js @@ -30,7 +30,7 @@ import Morphable, { TransformBag, makeMorphable, registerMorphableType -} from './types/Morphable.js' +} from './animation/Morphable.js' import Path from './elements/Path.js' import PathArray from './types/PathArray.js' import Pattern from './elements/Pattern.js' @@ -85,7 +85,6 @@ export { default as PointArray } from './types/PointArray.js' export { default as List } from './types/List.js' /* Elements */ -export { default as Bare } from './elements/Bare.js' export { default as Circle } from './elements/Circle.js' export { default as ClipPath } from './elements/ClipPath.js' export { default as Container } from './elements/Container.js' @@ -95,7 +94,6 @@ export { default as Element } from './elements/Element.js' export { default as Ellipse } from './elements/Ellipse.js' export { default as Gradient } from './elements/Gradient.js' export { default as G } from './elements/G.js' -export { default as HtmlNode } from './elements/HtmlNode.js' export { default as A } from './elements/A.js' export { default as Image } from './elements/Image.js' export { default as Line } from './elements/Line.js' diff --git a/src/utils/adopter.js b/src/utils/adopter.js index 6109f22..52d589e 100644 --- a/src/utils/adopter.js +++ b/src/utils/adopter.js @@ -50,19 +50,16 @@ export function adopt (node) { // make sure a node isn't already adopted if (node.instance instanceof Base) return node.instance - if (!(node instanceof globals.window.SVGElement)) { - return new elements.HtmlNode(node) - } - // initialize variables var className = capitalize(node.nodeName) + // Make sure that gradients are adopted correctly if (className === 'LinearGradient' || className === 'RadialGradient') { className = 'Gradient' - } - if (!elements[className]) { - className = 'Bare' + // Fallback to Dom if element is not known + } else if (!elements[className]) { + className = 'Dom' } return new elements[className](node) |