diff --git a/packages/svgcanvas/select.js b/packages/svgcanvas/select.js index d4943d76..811b56f7 100644 --- a/packages/svgcanvas/select.js +++ b/packages/svgcanvas/select.js @@ -8,7 +8,8 @@ import { isWebkit } from '../../src/common/browser.js' import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js' -import { transformListToTransform, transformBox, transformPoint } from './math.js' +import { transformListToTransform, transformBox, transformPoint, matrixMultiply } from './math.js' +import { NS } from './namespaces' let svgCanvas let selectorManager_ // A Singleton @@ -122,9 +123,24 @@ export class Selector { offset += 2 / zoom } + // find the transformations applied to the parent of the selected element + const svg = document.createElementNS(NS.SVG, 'svg') + let parentTransformationMatrix = svg.createSVGMatrix() + let currentElt = selected + while (currentElt.parentNode) { + if (currentElt.parentNode && currentElt.parentNode.tagName === 'g' && currentElt.parentNode.transform) { + if (currentElt.parentNode.transform.baseVal.numberOfItems) { + parentTransformationMatrix = matrixMultiply(transformListToTransform(selected.parentNode.transform.baseVal).matrix, parentTransformationMatrix) + } + } + currentElt = currentElt.parentNode + } + // loop and transform our bounding box until we reach our first rotation const tlist = selected.transform.baseVal - const m = transformListToTransform(tlist).matrix + + // combines the parent transformation with that of the selected element if necessary + const m = parentTransformationMatrix ? matrixMultiply(parentTransformationMatrix, transformListToTransform(tlist).matrix) : transformListToTransform(tlist).matrix // This should probably be handled somewhere else, but for now // it keeps the selection box correctly positioned when zoomed