@statelyai/flow-dom 3.5.2 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +25 -18
- package/package.json +2 -2
package/dist/esm/index.js
CHANGED
|
@@ -541,15 +541,15 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
541
541
|
let rafId = null;
|
|
542
542
|
function flush() {
|
|
543
543
|
rafId = null;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
544
|
+
const measurements = pendingMeasurements.filter(({ element, registration }) => elementMap.get(element) === registration).map(({ measurement }) => measurement);
|
|
545
|
+
pendingMeasurements = [];
|
|
546
|
+
if (measurements.length > 0) store.trigger.updateMeasurements({ measurements });
|
|
548
547
|
}
|
|
549
548
|
function scheduleFlush() {
|
|
550
549
|
if (rafId === null) rafId = requestAnimationFrame(flush);
|
|
551
550
|
}
|
|
552
|
-
function pushMeasurement(element,
|
|
551
|
+
function pushMeasurement(element, registration, layoutSize) {
|
|
552
|
+
const { target } = registration;
|
|
553
553
|
const viewport = store.getSnapshot().context.viewport;
|
|
554
554
|
const zoom = viewport.zoom || 1;
|
|
555
555
|
const rect = element.getBoundingClientRect();
|
|
@@ -565,15 +565,20 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
565
565
|
const existing = store.getSnapshot().context.measurements.get(id);
|
|
566
566
|
if (existing && Math.abs(existing.x - measurement.x) < equalityThreshold && Math.abs(existing.y - measurement.y) < equalityThreshold && Math.abs(existing.width - measurement.width) < equalityThreshold && Math.abs(existing.height - measurement.height) < equalityThreshold) return;
|
|
567
567
|
pendingMeasurements.push({
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
element,
|
|
569
|
+
registration,
|
|
570
|
+
measurement: {
|
|
571
|
+
id,
|
|
572
|
+
rect: measurement
|
|
573
|
+
}
|
|
570
574
|
});
|
|
571
575
|
scheduleFlush();
|
|
572
576
|
}
|
|
573
|
-
const handleResize = (entries) => {
|
|
577
|
+
const handleResize = (entries, source) => {
|
|
578
|
+
if (source !== observer) return;
|
|
574
579
|
for (const entry of entries) {
|
|
575
|
-
const
|
|
576
|
-
if (!
|
|
580
|
+
const registration = elementMap.get(entry.target);
|
|
581
|
+
if (!registration) continue;
|
|
577
582
|
const box = entry.borderBoxSize?.[0];
|
|
578
583
|
const layoutSize = box ? {
|
|
579
584
|
width: box.inlineSize,
|
|
@@ -582,7 +587,7 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
582
587
|
width: entry.contentRect.width,
|
|
583
588
|
height: entry.contentRect.height
|
|
584
589
|
} : void 0;
|
|
585
|
-
pushMeasurement(entry.target,
|
|
590
|
+
pushMeasurement(entry.target, registration, layoutSize);
|
|
586
591
|
}
|
|
587
592
|
};
|
|
588
593
|
let observer = null;
|
|
@@ -593,8 +598,11 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
593
598
|
}
|
|
594
599
|
return {
|
|
595
600
|
observe(element, target) {
|
|
596
|
-
elementMap.
|
|
601
|
+
const replacing = elementMap.has(element);
|
|
602
|
+
const registration = { target };
|
|
603
|
+
elementMap.set(element, registration);
|
|
597
604
|
getObserver(element).observe(element);
|
|
605
|
+
if (replacing) pushMeasurement(element, registration);
|
|
598
606
|
},
|
|
599
607
|
/**
|
|
600
608
|
* Re-measure an observed element immediately. ResizeObserver only fires
|
|
@@ -602,20 +610,19 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
602
610
|
* a port moving within its node) need an explicit re-measure.
|
|
603
611
|
*/
|
|
604
612
|
measure(element) {
|
|
605
|
-
const
|
|
606
|
-
if (
|
|
613
|
+
const registration = elementMap.get(element);
|
|
614
|
+
if (registration) pushMeasurement(element, registration);
|
|
607
615
|
},
|
|
608
616
|
refresh(targets) {
|
|
609
617
|
const requested = targets ? new Set(targets) : null;
|
|
610
|
-
for (const [element,
|
|
618
|
+
for (const [element, registration] of elementMap) {
|
|
619
|
+
const { target } = registration;
|
|
611
620
|
const id = "appearanceId" in target ? target.appearanceId : "portName" in target ? `${target.nodeId}:${target.portName}` : "nodeId" in target ? target.nodeId : target.edgeId;
|
|
612
621
|
if (requested && !requested.has(element) && !requested.has(id)) continue;
|
|
613
|
-
pushMeasurement(element,
|
|
622
|
+
pushMeasurement(element, registration);
|
|
614
623
|
}
|
|
615
624
|
},
|
|
616
625
|
unobserve(element) {
|
|
617
|
-
const target = elementMap.get(element);
|
|
618
|
-
if (target && "appearanceId" in target) pendingMeasurements = pendingMeasurements.filter(({ id }) => id !== target.appearanceId);
|
|
619
626
|
elementMap.delete(element);
|
|
620
627
|
observer?.unobserve(element);
|
|
621
628
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/flow-dom",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "DOM-specific helpers for @statelyai/flow with core re-exports.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@statelyai/flow": "0.13.
|
|
30
|
+
"@statelyai/flow": "0.13.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@vitest/coverage-v8": "^4.1.0",
|