index : pan-zoom | |
SVG pan/zoom library. |
aboutsummaryrefslogtreecommitdiff |
diff options
author | Catalin Mititiuc <webdevcat@proton.me> | 2025-03-18 13:43:26 -0700 |
---|---|---|
committer | Catalin Mititiuc <webdevcat@proton.me> | 2025-03-18 13:47:07 -0700 |
commit | 25eca15a3007c76c4e444b859683feb29edfa183 (patch) | |
tree | d0a867be54ab95f5e138cec9df662fa0ba450544 /src/modules/utils.js | |
parent | 99d137cc0937c0342fc1076eafe609c8aa370087 (diff) |
WIP: translate an object to zoomed position without scalingcm-pan-not-zoom
Diffstat (limited to 'src/modules/utils.js')
-rw-r--r-- | src/modules/utils.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/modules/utils.js b/src/modules/utils.js index e7f5c55..ae63b74 100644 --- a/src/modules/utils.js +++ b/src/modules/utils.js @@ -1,5 +1,32 @@ const digits = /-?\d+\.?\d*/g; +export function extractNum(string) { + return string.replace(/\D/g,''); +} + +export function getTracked(trackedAndTrackerEls) { + const sorted = [...trackedAndTrackerEls] + .sort((a, b) => a.id < b.id || extractNum(a.id) <= extractNum(b.id)); + + const groups = []; + const els = sorted.slice(); + + while (els.length) { + groups.push([els.pop(), els.pop()]); + } + + return groups; +} + +export function track(targetEl, trackingEl, transformMtx) { + let x = targetEl.getAttributeNS(null, 'x'); + let y = targetEl.getAttributeNS(null, 'y'); + let ptBefore = new DOMPoint(x, y); + let ptAfter = ptBefore.matrixTransform(transformMtx); + trackingEl.setAttributeNS(null, 'x', ptAfter.x); + trackingEl.setAttributeNS(null, 'y', ptAfter.y); +} + export default function getComputedTransformMatrix(el) { const matrixSequence = getComputedStyle(el).transform.match(digits), identityMatrix = ''; |