Web Dev Solutions

Catalin Mititiuc

From 25eca15a3007c76c4e444b859683feb29edfa183 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Tue, 18 Mar 2025 13:43:26 -0700 Subject: WIP: translate an object to zoomed position without scaling --- src/modules/utils.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/modules/utils.js') 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 = ''; -- cgit v1.2.3