From 675847a99f1640c87df0a6187eeb34b90d903666 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Mon, 12 Nov 2018 23:09:25 +0100 Subject: plumber differences between node and browser so that tests run on both --- src/types/Box.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/types') 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() } -- cgit v1.2.3