Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/utils.js')
-rw-r--r--src/modules/utils.js27
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 = '';