summaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-12 23:09:25 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-28 13:42:25 +0100
commit675847a99f1640c87df0a6187eeb34b90d903666 (patch)
tree78483c739c2b164cd6b098d952658d636e3be745 /src/types
parentfa0461eeddf65a249e1a674305684ae756a69965 (diff)
downloadsvg.js-675847a99f1640c87df0a6187eeb34b90d903666.tar.gz
svg.js-675847a99f1640c87df0a6187eeb34b90d903666.zip
plumber differences between node and browser so that tests run on both
Diffstat (limited to 'src/types')
-rw-r--r--src/types/Box.js26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/types/Box.js b/src/types/Box.js
index e55f114..a08ad67 100644
--- a/src/types/Box.js
+++ b/src/types/Box.js
@@ -104,7 +104,7 @@ export default class Box {
}
}
-function getBox (cb) {
+function getBox (cb, retry) {
let box
try {
@@ -114,23 +114,29 @@ function getBox (cb) {
throw new Error('Element not in the dom')
}
} catch (e) {
- try {
- let clone = this.clone().addTo(parser().svg).show()
- box = cb(clone.node)
- clone.remove()
- } catch (e) {
- throw new Error('Getting a bounding box of element "' + this.node.nodeName + '" is not possible')
- }
+ box = retry(this)
}
+
return box
}
export function bbox () {
- return new Box(getBox.call(this, (node) => node.getBBox()))
+ return new Box(getBox.call(this, (node) => node.getBBox(), (el) => {
+ try {
+ let clone = el.clone().addTo(parser().svg).show()
+ let box = clone.node.getBBox()
+ clone.remove()
+ return box
+ } catch (e) {
+ throw new Error('Getting bbox of element "' + el.node.nodeName + '" is not possible')
+ }
+ }))
}
export function rbox (el) {
- let box = new Box(getBox.call(this, (node) => node.getBoundingClientRect()))
+ let box = new Box(getBox.call(this, (node) => node.getBoundingClientRect(), (el) => {
+ throw new Error('Getting rbox of element "' + el.node.nodeName + '" is not possible')
+ }))
if (el) return box.transform(el.screenCTM().inverse())
return box.addOffset()
}