diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/animation/Animator.js | 3 | ||||
-rw-r--r-- | src/animation/Timeline.js | 2 | ||||
-rw-r--r-- | src/elements/Bare.js | 3 | ||||
-rw-r--r-- | src/elements/Doc.js | 3 | ||||
-rw-r--r-- | src/elements/Dom.js | 4 | ||||
-rw-r--r-- | src/elements/Element.js | 1 | ||||
-rw-r--r-- | src/elements/Image.js | 3 | ||||
-rw-r--r-- | src/elements/Shape.js | 1 | ||||
-rw-r--r-- | src/elements/Style.js | 1 | ||||
-rw-r--r-- | src/elements/Text.js | 3 | ||||
-rw-r--r-- | src/main.js | 1 | ||||
-rw-r--r-- | src/modules/core/event.js | 3 | ||||
-rw-r--r-- | src/modules/core/parser.js | 3 | ||||
-rw-r--r-- | src/modules/core/selector.js | 3 | ||||
-rw-r--r-- | src/modules/core/textable.js | 4 | ||||
-rw-r--r-- | src/types/Box.js | 5 | ||||
-rw-r--r-- | src/types/Color.js | 2 | ||||
-rw-r--r-- | src/types/Matrix.js | 2 | ||||
-rw-r--r-- | src/types/Morphable.js | 3 | ||||
-rw-r--r-- | src/types/Point.js | 2 | ||||
-rw-r--r-- | src/types/SVGArray.js | 1 | ||||
-rw-r--r-- | src/types/SVGNumber.js | 2 | ||||
-rw-r--r-- | src/utils/adopter.js | 3 | ||||
-rw-r--r-- | src/utils/window.js | 10 |
24 files changed, 64 insertions, 4 deletions
diff --git a/src/animation/Animator.js b/src/animation/Animator.js index fdb2326..4e0b112 100644 --- a/src/animation/Animator.js +++ b/src/animation/Animator.js @@ -1,5 +1,8 @@ +import globals from '../utils/window.js' import Queue from './Queue.js' +const { window } = globals + const Animator = { nextDraw: null, frames: new Queue(), diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js index 790033a..ff30a0d 100644 --- a/src/animation/Timeline.js +++ b/src/animation/Timeline.js @@ -1,6 +1,8 @@ import { registerMethods } from '../utils/methods.js' import Animator from './Animator.js' +import globals from '../utils/window.js' +const { window, document } = globals var time = window.performance || Date var makeSchedule = function (runnerInfo) { diff --git a/src/elements/Bare.js b/src/elements/Bare.js index 9415cd4..7162f3a 100644 --- a/src/elements/Bare.js +++ b/src/elements/Bare.js @@ -1,6 +1,9 @@ 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' + +const { document } = globals export default class Bare extends Container { constructor (node, attrs) { diff --git a/src/elements/Doc.js b/src/elements/Doc.js index 0d862ba..952f1d3 100644 --- a/src/elements/Doc.js +++ b/src/elements/Doc.js @@ -8,6 +8,9 @@ import { ns, svgjs, xlink, xmlns } from '../modules/core/namespaces.js' import { registerMethods } from '../utils/methods.js' import Container from './Container.js' import Defs from './Defs.js' +import globals from '../utils/window.js' + +const { window } = globals export default class Doc extends Container { constructor (node) { diff --git a/src/elements/Dom.js b/src/elements/Dom.js index 87d0f5e..8fa053c 100644 --- a/src/elements/Dom.js +++ b/src/elements/Dom.js @@ -8,9 +8,11 @@ import { } from '../utils/adopter.js' import { map } from '../utils/utils.js' import { ns } from '../modules/core/namespaces.js' +import globals from '../utils/window.js' import EventTarget from '../types/EventTarget.js' import attr from '../modules/core/attr.js' +const { window, document } = globals export default class Dom extends EventTarget { constructor (node, attrs) { @@ -154,7 +156,7 @@ export default class Dom extends EventTarget { if (!type) return parent // loop trough ancestors if type is given - while (parent && parent.node instanceof window.SVGElement) { + while (parent && parent.node instanceof window.SVGElement) { // FIXME: That shouldnt be neccessary if (typeof type === 'string' ? parent.matches(type) : parent instanceof type) return parent parent = adopt(parent.node.parentNode) } diff --git a/src/elements/Element.js b/src/elements/Element.js index 7d491f9..03b5f07 100644 --- a/src/elements/Element.js +++ b/src/elements/Element.js @@ -4,7 +4,6 @@ import { reference } from '../modules/core/regex.js' import Dom from './Dom.js' import SVGNumber from '../types/SVGNumber.js' - const Doc = getClass(root) export default class Element extends Dom { diff --git a/src/elements/Image.js b/src/elements/Image.js index c529439..6a01b8f 100644 --- a/src/elements/Image.js +++ b/src/elements/Image.js @@ -6,6 +6,9 @@ import { registerMethods } from '../utils/methods.js' import { xlink } from '../modules/core/namespaces.js' import Pattern from './Pattern.js' import Shape from './Shape.js' +import globals from '../utils/window.js' + +const { window } = globals export default class Image extends Shape { constructor (node) { diff --git a/src/elements/Shape.js b/src/elements/Shape.js index e2821fe..cdddc60 100644 --- a/src/elements/Shape.js +++ b/src/elements/Shape.js @@ -1,7 +1,6 @@ import { register } from '../utils/adopter.js' import Element from './Element.js' - export default class Shape extends Element {} register(Shape) diff --git a/src/elements/Style.js b/src/elements/Style.js index 1883184..50ec50e 100644 --- a/src/elements/Style.js +++ b/src/elements/Style.js @@ -3,7 +3,6 @@ import { registerMethods } from '../utils/methods.js' import { unCamelCase } from '../utils/utils.js' import Element from './Element.js' - function cssRule (selector, rule) { if (!selector) return '' if (!rule) return selector diff --git a/src/elements/Text.js b/src/elements/Text.js index b4ba0ad..41be916 100644 --- a/src/elements/Text.js +++ b/src/elements/Text.js @@ -9,8 +9,11 @@ import { attrs } from '../modules/core/defaults.js' import { registerMethods } from '../utils/methods.js' import SVGNumber from '../types/SVGNumber.js' import Shape from './Shape.js' +import globals from '../utils/window.js' import * as textable from '../modules/core/textable.js' +const { window } = globals + export default class Text extends Shape { // Initialize node constructor (node) { diff --git a/src/main.js b/src/main.js index 8a7fd96..1961604 100644 --- a/src/main.js +++ b/src/main.js @@ -61,6 +61,7 @@ export { default as parser } from './modules/core/parser.js' export { default as find } from './modules/core/selector.js' export * from './modules/core/event.js' export * from './utils/adopter.js' +export { registerWindow } from './utils/window.js' /* Animation Modules */ export { default as Animator } from './animation/Animator.js' diff --git a/src/modules/core/event.js b/src/modules/core/event.js index 2fcaf58..351fe3f 100644 --- a/src/modules/core/event.js +++ b/src/modules/core/event.js @@ -1,5 +1,8 @@ import { delimiter } from './regex.js' import { makeInstance } from '../../utils/adopter.js' +import globals from '../../utils/window.js' + +const { window } = globals let listenerId = 0 diff --git a/src/modules/core/parser.js b/src/modules/core/parser.js index 7a656ef..a490576 100644 --- a/src/modules/core/parser.js +++ b/src/modules/core/parser.js @@ -1,4 +1,7 @@ import Doc from '../../elements/Doc.js' +import globals from '../../utils/window.js' + +const { document } = globals export default function parser () { // Reuse cached element if possible diff --git a/src/modules/core/selector.js b/src/modules/core/selector.js index 1e0b55e..52a7ad1 100644 --- a/src/modules/core/selector.js +++ b/src/modules/core/selector.js @@ -1,6 +1,9 @@ import { adopt } from '../../utils/adopter.js' import { map } from '../../utils/utils.js' import { registerMethods } from '../../utils/methods.js' +import globals from '../../utils/window.js' + +const { document } = globals export default function baseFind (query, parent) { return map((parent || document).querySelectorAll(query), function (node) { diff --git a/src/modules/core/textable.js b/src/modules/core/textable.js index 139d056..cf452c6 100644 --- a/src/modules/core/textable.js +++ b/src/modules/core/textable.js @@ -1,3 +1,7 @@ +import globals from '../../utils/window.js' + +const { document } = globals + // Create plain text node export function plain (text) { // clear if build mode is disabled diff --git a/src/types/Box.js b/src/types/Box.js index 21672b1..97ba699 100644 --- a/src/types/Box.js +++ b/src/types/Box.js @@ -1,8 +1,11 @@ import { delimiter } from '../modules/core/regex.js' import { registerMethods } from '../utils/methods.js' +import globals from '../utils/window.js' import Point from './Point.js' import parser from '../modules/core/parser.js' +const { window, document } = globals + function isNulledBox (box) { return !box.w && !box.h && !box.x && !box.y } @@ -41,6 +44,8 @@ export default class Box { this.y2 = this.y + this.h this.cx = this.x + this.w / 2 this.cy = this.y + this.h / 2 + + return this } // Merge rect box with another, return a new instance diff --git a/src/types/Color.js b/src/types/Color.js index 6bbfd82..a96958b 100644 --- a/src/types/Color.js +++ b/src/types/Color.js @@ -93,6 +93,8 @@ export default class Color { this.g = g this.b = b } + + return this } // Default to hex conversion diff --git a/src/types/Matrix.js b/src/types/Matrix.js index 963fd1a..ee12488 100644 --- a/src/types/Matrix.js +++ b/src/types/Matrix.js @@ -37,6 +37,8 @@ export default class Matrix { this.d = source.d != null ? source.d : base.d this.e = source.e != null ? source.e : base.e this.f = source.f != null ? source.f : base.f + + return this } // Clones this matrix diff --git a/src/types/Morphable.js b/src/types/Morphable.js index 021c5f4..703cc00 100644 --- a/src/types/Morphable.js +++ b/src/types/Morphable.js @@ -121,6 +121,7 @@ export class NonMorphable { init (val) { val = Array.isArray(val) ? val[0] : val this.value = val + return this } valueOf () { @@ -152,6 +153,7 @@ export class TransformBag { } Object.assign(this, TransformBag.defaults, obj) + return this } toArray () { @@ -199,6 +201,7 @@ export class ObjectBag { }) this.values = entries.reduce((last, curr) => last.concat(curr), []) + return this } valueOf () { diff --git a/src/types/Point.js b/src/types/Point.js index 685240b..6a2b968 100644 --- a/src/types/Point.js +++ b/src/types/Point.js @@ -19,6 +19,8 @@ export default class Point { // merge source this.x = source.x == null ? base.x : source.x this.y = source.y == null ? base.y : source.y + + return this } // Clone point diff --git a/src/types/SVGArray.js b/src/types/SVGArray.js index 3894b22..4fcb500 100644 --- a/src/types/SVGArray.js +++ b/src/types/SVGArray.js @@ -12,6 +12,7 @@ extend(SVGArray, { init (arr) { this.length = 0 this.push(...this.parse(arr)) + return this }, toArray () { diff --git a/src/types/SVGNumber.js b/src/types/SVGNumber.js index bba9741..ea21cbd 100644 --- a/src/types/SVGNumber.js +++ b/src/types/SVGNumber.js @@ -40,6 +40,8 @@ export default class SVGNumber { this.unit = value.unit } } + + return this } toString () { diff --git a/src/utils/adopter.js b/src/utils/adopter.js index 88cd383..5d5d1f0 100644 --- a/src/utils/adopter.js +++ b/src/utils/adopter.js @@ -1,7 +1,10 @@ import { capitalize } from './utils.js' import { ns } from '../modules/core/namespaces.js' +import globals from '../utils/window.js' import Base from '../types/Base.js' +const { window, document } = globals + const elements = {} export const root = Symbol('root') diff --git a/src/utils/window.js b/src/utils/window.js new file mode 100644 index 0000000..f44ebb9 --- /dev/null +++ b/src/utils/window.js @@ -0,0 +1,10 @@ +const globals = { + window, document +} + +export default globals + +export function registerWindow (w) { + globals.window = w + globals.document = w.document +} |