diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-27 20:43:35 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-27 20:43:35 +0200 |
commit | 1c75fcaf02ceb144152d59557643c6fdd7264065 (patch) | |
tree | 5184af75f2fd27ca6b81c24a06b1676d17ca2c76 /src/Box.js | |
parent | b1b776a710d0ce0a6259043b8ce0665e205195fa (diff) | |
download | svg.js-1c75fcaf02ceb144152d59557643c6fdd7264065.tar.gz svg.js-1c75fcaf02ceb144152d59557643c6fdd7264065.zip |
resolve circular references and make example working again
Diffstat (limited to 'src/Box.js')
-rw-r--r-- | src/Box.js | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -1,11 +1,16 @@ -import {Parent, Doc, Symbol, Image, Pattern, Marker, Point} from './classes.js' +//import {Parent, Doc, Symbol, Image, Pattern, Marker, Point} from './classes.js' +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' export default class Box { - constructor (source) { + constructor (...args) { + this.init(...args) + } + + init (source) { var base = [0, 0, 0, 0] source = typeof source === 'string' ? source.split(delimiter).map(parseFloat) : Array.isArray(source) ? source @@ -77,20 +82,6 @@ export default class Box { } } - -extend(Parent, { - // Get bounding box - bbox () { - return new Box(getBox((node) => node.getBBox())) - }, - - rbox (el) { - let box = new Box(getBox((node) => node.getBoundingClientRect())) - if (el) return box.transform(el.screenCTM().inverse()) - return box.addOffset() - } -}) - function getBox(cb) { let box @@ -106,14 +97,26 @@ function getBox(cb) { box = cb(clone.node) clone.remove() } catch (e) { + throw (e) console.warn('Getting a bounding box of this element is not possible') } } return box } - -extend([Doc, Symbol, Image, Pattern, Marker], { +Box.constructors = { + 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: function (x, y, width, height) { // act as getter if (x == null) return new Box(this.attr('viewBox')) @@ -121,4 +124,4 @@ extend([Doc, Symbol, Image, Pattern, Marker], { // act as setter return this.attr('viewBox', new Box(x, y, width, height)) } -}) +} |