diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-12 14:51:34 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-12 14:51:34 +0100 |
commit | bf6e2aeb13f9a4bee2be1f8f7a70ca1a73215245 (patch) | |
tree | 0614edfac92e0ab9ff44144b79aa5802211ef5e0 /src/types | |
parent | 334d9c73c2f74679a93b1d7b3e39b614f6444faa (diff) | |
download | svg.js-bf6e2aeb13f9a4bee2be1f8f7a70ca1a73215245.tar.gz svg.js-bf6e2aeb13f9a4bee2be1f8f7a70ca1a73215245.zip |
remove native() methods, add methods of types directly to elemenet
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/Box.js | 22 | ||||
-rw-r--r-- | src/types/Matrix.js | 58 | ||||
-rw-r--r-- | src/types/Point.js | 25 |
3 files changed, 30 insertions, 75 deletions
diff --git a/src/types/Box.js b/src/types/Box.js index 8c1c4ca..e55f114 100644 --- a/src/types/Box.js +++ b/src/types/Box.js @@ -125,19 +125,17 @@ function getBox (cb) { return box } +export function bbox () { + return new Box(getBox.call(this, (node) => node.getBBox())) +} + +export function rbox (el) { + let box = new Box(getBox.call(this, (node) => node.getBoundingClientRect())) + if (el) return box.transform(el.screenCTM().inverse()) + return box.addOffset() +} + registerMethods({ - Element: { - // Get bounding box - bbox () { - return new Box(getBox.call(this, (node) => node.getBBox())) - }, - - rbox (el) { - let box = new Box(getBox.call(this, (node) => node.getBoundingClientRect())) - if (el) return box.transform(el.screenCTM().inverse()) - return box.addOffset() - } - }, viewbox: { viewbox (x, y, width, height) { // act as getter diff --git a/src/types/Matrix.js b/src/types/Matrix.js index ee12488..a1eb317 100644 --- a/src/types/Matrix.js +++ b/src/types/Matrix.js @@ -1,12 +1,7 @@ import { delimiter } from '../modules/core/regex.js' import { radians } from '../utils/utils.js' -import { registerMethods } from '../utils/methods.js' import Element from '../elements/Element.js' import Point from './Point.js' -import parser from '../modules/core/parser.js' - -// Create matrix array for looping -const abcdef = 'abcdef'.split('') function closeEnough (a, b, threshold) { return Math.abs(b - a) < (threshold || 1e-6) @@ -379,19 +374,6 @@ export default class Matrix { return this.clone().aroundO(cx, cy, matrix) } - // Convert to native SVGMatrix - native () { - // create new matrix - var matrix = parser().svg.node.createSVGMatrix() - - // update with current values - for (var i = abcdef.length - 1; i >= 0; i--) { - matrix[abcdef[i]] = this[abcdef[i]] - } - - return matrix - } - // Check if two matrices are equal equals (other) { var comp = new Matrix(other) @@ -499,26 +481,20 @@ export default class Matrix { } } -registerMethods({ - Element: { - // Get current matrix - ctm () { - return new Matrix(this.node.getCTM()) - }, - - // Get current screen matrix - screenCTM () { - /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537 - This is needed because FF does not return the transformation matrix - for the inner coordinate system when getScreenCTM() is called on nested svgs. - However all other Browsers do that */ - if (typeof this.isRoot === 'function' && !this.isRoot()) { - var rect = this.rect(1, 1) - var m = rect.node.getScreenCTM() - rect.remove() - return new Matrix(m) - } - return new Matrix(this.node.getScreenCTM()) - } - } -}) +export function ctm () { + return new Matrix(this.node.getCTM()) +} + +export function screenCTM () { + /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537 + This is needed because FF does not return the transformation matrix + for the inner coordinate system when getScreenCTM() is called on nested svgs. + However all other Browsers do that */ + if (typeof this.isRoot === 'function' && !this.isRoot()) { + var rect = this.rect(1, 1) + var m = rect.node.getScreenCTM() + rect.remove() + return new Matrix(m) + } + return new Matrix(this.node.getScreenCTM()) +} diff --git a/src/types/Point.js b/src/types/Point.js index 6a2b968..27d81ea 100644 --- a/src/types/Point.js +++ b/src/types/Point.js @@ -1,6 +1,3 @@ -import { registerMethods } from '../utils/methods.js' -import parser from '../modules/core/parser.js' - export default class Point { // Initialize constructor (...args) { @@ -28,17 +25,6 @@ export default class Point { return new Point(this) } - // Convert to native SVGPoint - native () { - // create new point - var point = parser().svg.node.createSVGPoint() - - // update with current values - point.x = this.x - point.y = this.y - return point - } - // transform point with matrix transform (m) { // Perform the matrix multiplication @@ -54,11 +40,6 @@ export default class Point { } } -registerMethods({ - Element: { - // Get point - point: function (x, y) { - return new Point(x, y).transform(this.screenCTM().inverse()) - } - } -}) +export function point (x, y) { + return new Point(x, y).transform(this.screenCTM().inverse()) +} |