aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-06-27 11:57:42 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-06-27 11:57:42 +0200
commit37750c14d57eabe1d4692b5ec3db431f4cfc9fcb (patch)
tree54ad812f2b64614a4897228b411846ae720e904f /src
parent1a9bfbc6688edaea47f0b011993c1ca2b6509514 (diff)
downloadsvg.js-37750c14d57eabe1d4692b5ec3db431f4cfc9fcb.tar.gz
svg.js-37750c14d57eabe1d4692b5ec3db431f4cfc9fcb.zip
fixing dmove for nested svgs (https://github.com/svgdotjs/svg.draggable.js/issues/127)
Diffstat (limited to 'src')
-rw-r--r--src/modules/core/containerGeometry.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/modules/core/containerGeometry.js b/src/modules/core/containerGeometry.js
index 21139e8..32a3c8e 100644
--- a/src/modules/core/containerGeometry.js
+++ b/src/modules/core/containerGeometry.js
@@ -1,6 +1,8 @@
import Matrix from '../../types/Matrix.js'
import Point from '../../types/Point.js'
+import Box from '../../types/Box.js'
import { proportionalSize } from '../../utils/utils.js'
+import { getWindow } from '../../utils/window.js'
export function dmove(dx, dy) {
this.children().forEach((child) => {
@@ -10,7 +12,12 @@ export function dmove(dx, dy) {
// e.g. title and other descriptive elements
try {
// Get the childs bbox
- bbox = child.bbox()
+ // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1905039
+ // Because bbox for nested svgs returns the contents bbox in the coordinate space of the svg itself (weird!), we cant use bbox for svgs
+ // Therefore we have to use getBoundingClientRect. But THAT is broken (as explained in the bug).
+ // Funnily enough the broken behavior would work for us but that breaks it in chrome
+ // So we have to replicate the broken behavior of FF by just reading the attributes of the svg itself
+ bbox = child.node instanceof getWindow().SVGSVGElement ? new Box(child.attr(['x', 'y', 'width', 'height'])) : child.bbox()
} catch (e) {
return
}