diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-04 17:04:11 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-04 17:04:11 +0100 |
commit | d22dce113a4a61d76b3c0e7c7fb77231f575c6fd (patch) | |
tree | 7fd98163a8cb2564009a2ed53e7b419ff64cf76f /src | |
parent | 426256d2fcecdca34acf7e15c9b8e79c183f0b5a (diff) | |
download | svg.js-d22dce113a4a61d76b3c0e7c7fb77231f575c6fd.tar.gz svg.js-d22dce113a4a61d76b3c0e7c7fb77231f575c6fd.zip |
fix even more tests
Diffstat (limited to 'src')
-rw-r--r-- | src/Controller.js | 2 | ||||
-rw-r--r-- | src/Element.js | 5 | ||||
-rw-r--r-- | src/Marker.js | 1 | ||||
-rw-r--r-- | src/Matrix.js | 2 | ||||
-rw-r--r-- | src/Parent.js | 1 | ||||
-rw-r--r-- | src/Point.js | 2 | ||||
-rw-r--r-- | src/Text.js | 3 | ||||
-rw-r--r-- | src/TextPath.js | 2 | ||||
-rw-r--r-- | src/attr.js | 2 | ||||
-rw-r--r-- | src/css.js | 2 | ||||
-rw-r--r-- | src/event.js | 55 | ||||
-rw-r--r-- | src/poly.js | 1 | ||||
-rw-r--r-- | src/sugar.js | 5 | ||||
-rw-r--r-- | src/svg.js | 13 |
14 files changed, 59 insertions, 37 deletions
diff --git a/src/Controller.js b/src/Controller.js index a48d946..e3f2ab9 100644 --- a/src/Controller.js +++ b/src/Controller.js @@ -17,7 +17,7 @@ function makeSetterGetter (k, f) { } } -let easing = { +export let easing = { '-': function (pos) { return pos }, '<>': function (pos) { return -Math.cos(pos * Math.PI) / 2 + 0.5 }, '>': function (pos) { return Math.sin(pos * Math.PI / 2) }, diff --git a/src/Element.js b/src/Element.js index 0494965..e8352a8 100644 --- a/src/Element.js +++ b/src/Element.js @@ -7,6 +7,7 @@ import {registerMethods} from './methods.js' import {registerConstructor} from './methods.js' const Doc = getClass(root) +const HtmlNode = getClass('HtmlNode') export const name = 'Element' @@ -223,7 +224,7 @@ export function parents (type) { do { parent = parent.parent(type) - if (!parent || !parent.node) break + if (!parent || parent instanceof HtmlNode) break parents.push(parent) } while (parent.parent) @@ -233,7 +234,7 @@ export function parents (type) { // matches the element vs a css selector export function matches (selector) { - return matches(this.node, selector) + return matcher(this.node, selector) } // Returns the svg node to call native svg methods on it diff --git a/src/Marker.js b/src/Marker.js index bf2b854..403a387 100644 --- a/src/Marker.js +++ b/src/Marker.js @@ -1,6 +1,7 @@ import Base from './Base.js' import {register} from './adopter.js' import {registerMethods} from './methods.js' +import {nodeOrNew} from './tools.js' export default class Marker extends Base { // Initialize node diff --git a/src/Matrix.js b/src/Matrix.js index 7f3afe5..b0a6c48 100644 --- a/src/Matrix.js +++ b/src/Matrix.js @@ -375,7 +375,7 @@ export default class Matrix { // Convert to native SVGMatrix native () { // create new matrix - var matrix = parser().node.createSVGMatrix() + var matrix = parser().svg.node.createSVGMatrix() // update with current values for (var i = abcdef.length - 1; i >= 0; i--) { diff --git a/src/Parent.js b/src/Parent.js index 769cd49..a52b000 100644 --- a/src/Parent.js +++ b/src/Parent.js @@ -2,6 +2,7 @@ import {makeInstance, adopt} from './adopter.js' import {map} from './utils.js' import {registerMethods} from './methods.js' import Base from './Base.js' +import {ns} from './namespaces.js' // Returns all child elements export function children () { diff --git a/src/Point.js b/src/Point.js index 7919d02..7f8e2c3 100644 --- a/src/Point.js +++ b/src/Point.js @@ -25,7 +25,7 @@ export default class Point { // Convert to native SVGPoint native () { // create new point - var point = parser().svg.createSVGPoint() + var point = parser().svg.node.createSVGPoint() // update with current values point.x = this.x diff --git a/src/Text.js b/src/Text.js index fabdbe5..02a601b 100644 --- a/src/Text.js +++ b/src/Text.js @@ -3,7 +3,7 @@ import SVGNumber from './SVGNumber.js' import {nodeOrNew, extend} from './tools.js' import {attrs} from './defaults.js' import * as textable from './textable.js' -import {register} from './adopter.js' +import {register, adopt} from './adopter.js' import {registerMethods} from './methods.js' export default class Text extends Base { @@ -56,6 +56,7 @@ export default class Text extends Base { text (text) { // act as getter if (text === undefined) { + // FIXME use children() or each() var children = this.node.childNodes var firstLine = 0 text = '' diff --git a/src/TextPath.js b/src/TextPath.js index afe29ce..df5b690 100644 --- a/src/TextPath.js +++ b/src/TextPath.js @@ -64,7 +64,7 @@ registerMethods({ // FIXME: make this plural? // Get the textPath children textPath: function () { - return this.select('textPath') + return this.find('textPath') } }, Path: { diff --git a/src/attr.js b/src/attr.js index 9ec9eb0..23baf51 100644 --- a/src/attr.js +++ b/src/attr.js @@ -14,7 +14,7 @@ export default function attr (attr, val, ns) { val = this.node.attributes for (let node of val) { - attr[node.nodeName] = isNumer.test(node.nodeValue) + attr[node.nodeName] = isNumber.test(node.nodeValue) ? parseFloat(node.nodeValue) : node.nodeValue } @@ -24,7 +24,7 @@ export function css (style, val) { if (Array.isArray(style)) { for (let name of style) { let cased = camelCase(name) - ret[cased] = this.node.style(cased) + ret[cased] = this.node.style[cased] } return ret } diff --git a/src/event.js b/src/event.js index dd782c6..9fa99e1 100644 --- a/src/event.js +++ b/src/event.js @@ -2,31 +2,36 @@ import Base from './Base.js' import {delimiter} from './regex.js' import {registerMethods} from './methods.js' -// // Add events to elements -// ;[ 'click', -// 'dblclick', -// 'mousedown', -// 'mouseup', -// 'mouseover', -// 'mouseout', -// 'mousemove', -// 'mouseenter', -// 'mouseleave', -// 'touchstart', -// 'touchmove', -// 'touchleave', -// 'touchend', -// 'touchcancel' ].forEach(function (event) { -// // add event to Element -// Element.prototype[event] = function (f) { -// if (f === null) { -// off(this, event) -// } else { -// on(this, event, f) -// } -// return this -// } -// }) +// Add events to elements +const methods = [ 'click', + 'dblclick', + 'mousedown', + 'mouseup', + 'mouseover', + 'mouseout', + 'mousemove', + 'mouseenter', + 'mouseleave', + 'touchstart', + 'touchmove', + '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 + } + + last[event] = fn + return last + }, {}) + +registerMethods('Element', methods) let listenerId = 0 diff --git a/src/poly.js b/src/poly.js index 19643ef..937247a 100644 --- a/src/poly.js +++ b/src/poly.js @@ -1,5 +1,6 @@ // Add polygon-specific functions import PointArray from './PointArray.js' +import {proportionalSize} from './helpers.js' // Get array export function array () { diff --git a/src/sugar.js b/src/sugar.js index 3751f31..9a075a0 100644 --- a/src/sugar.js +++ b/src/sugar.js @@ -1,9 +1,10 @@ import Color from './Color.js' import Runner from './Runner.js' import SVGNumber from './SVGNumber.js' +import Matrix from './Matrix.js' +import Point from './Point.js' import {registerMethods} from './methods.js' - // Define list of available attributes for stroke and fill var sugar = { stroke: ['color', 'width', 'opacity', 'linecap', 'linejoin', 'miterlimit', 'dasharray', 'dashoffset'], @@ -139,7 +140,7 @@ registerMethods('Path', { } }) -registerMethods(['Parent', 'Runner'], { +registerMethods(['Container', 'Runner'], { // Set font font: function (a, v) { if (typeof a === 'object') { @@ -12,6 +12,7 @@ import * as containers from './containers.js' import * as elements from './elements.js' import './attr.js' import './arrange.js' +import './data.js' import find from './selector.js' import './css.js' import './transform.js' @@ -106,7 +107,17 @@ SVG.regex = regex // satisfy tests, fix later import * as ns from './namespaces' SVG.get = SVG -SVG.select = find +SVG.find = find Object.assign(SVG, ns) import Base from './Base.js' SVG.Element = SVG.Parent = SVG.Shape = SVG.Container = Base +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 |