@3plate/graph-core 0.1.16 → 0.1.18
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/index.cjs +70 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2812,6 +2812,10 @@ var Canvas = class {
|
|
|
2812
2812
|
curNodes;
|
|
2813
2813
|
curSegs;
|
|
2814
2814
|
updating;
|
|
2815
|
+
// Settle check state
|
|
2816
|
+
settleTimer;
|
|
2817
|
+
settleCount = 0;
|
|
2818
|
+
settleMaxRebuilds = 2;
|
|
2815
2819
|
// Unique marker ID prefix for this canvas instance
|
|
2816
2820
|
markerPrefix;
|
|
2817
2821
|
// Dynamic style element for this instance (for cleanup)
|
|
@@ -2941,7 +2945,17 @@ var Canvas = class {
|
|
|
2941
2945
|
}
|
|
2942
2946
|
}
|
|
2943
2947
|
}
|
|
2944
|
-
await new Promise(
|
|
2948
|
+
await new Promise((resolve) => {
|
|
2949
|
+
let resolved = false;
|
|
2950
|
+
const done = () => {
|
|
2951
|
+
if (!resolved) {
|
|
2952
|
+
resolved = true;
|
|
2953
|
+
resolve();
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
requestAnimationFrame(done);
|
|
2957
|
+
setTimeout(done, 50);
|
|
2958
|
+
});
|
|
2945
2959
|
const isVertical = this.orientation === "TB" || this.orientation === "BT";
|
|
2946
2960
|
for (const node of newNodes.values()) {
|
|
2947
2961
|
node.measure(isVertical);
|
|
@@ -3467,8 +3481,62 @@ var Canvas = class {
|
|
|
3467
3481
|
this.container.classList.add(`g3p-${colorMode}`);
|
|
3468
3482
|
}
|
|
3469
3483
|
}
|
|
3484
|
+
/**
|
|
3485
|
+
* Schedule a settle check: periodically re-measure nodes in case
|
|
3486
|
+
* async style injection (e.g. CSS-in-JS) changed their size after
|
|
3487
|
+
* the initial measurement. If any node's size changed, triggers a
|
|
3488
|
+
* rebuild to relayout the graph with correct dimensions.
|
|
3489
|
+
*/
|
|
3490
|
+
scheduleSettleCheck() {
|
|
3491
|
+
this.cancelSettleCheck();
|
|
3492
|
+
this.settleCount = 0;
|
|
3493
|
+
this.doSettleCheck();
|
|
3494
|
+
}
|
|
3495
|
+
cancelSettleCheck() {
|
|
3496
|
+
if (this.settleTimer) {
|
|
3497
|
+
clearTimeout(this.settleTimer);
|
|
3498
|
+
this.settleTimer = void 0;
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
doSettleCheck() {
|
|
3502
|
+
const delay = this.settleCount === 0 ? 50 : 150;
|
|
3503
|
+
this.settleTimer = setTimeout(() => {
|
|
3504
|
+
this.settleTimer = void 0;
|
|
3505
|
+
if (this.checkNodeSizes()) {
|
|
3506
|
+
if (this.settleCount < this.settleMaxRebuilds) {
|
|
3507
|
+
this.settleCount++;
|
|
3508
|
+
this.api.rebuild();
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
}, delay);
|
|
3512
|
+
}
|
|
3513
|
+
/**
|
|
3514
|
+
* Re-measure every live non-dummy node by temporarily moving its
|
|
3515
|
+
* content to the off-screen measurement container (synchronous,
|
|
3516
|
+
* no visual flash). Returns true if any node's size changed.
|
|
3517
|
+
*/
|
|
3518
|
+
checkNodeSizes() {
|
|
3519
|
+
if (!this.measurement) return false;
|
|
3520
|
+
const isVertical = this.orientation === "TB" || this.orientation === "BT";
|
|
3521
|
+
let changed = false;
|
|
3522
|
+
for (const node of this.curNodes.values()) {
|
|
3523
|
+
if (node.isDummy || !node.content) continue;
|
|
3524
|
+
const oldDims = node.data?.dims;
|
|
3525
|
+
if (!oldDims) continue;
|
|
3526
|
+
const parent = node.content.parentElement;
|
|
3527
|
+
this.measurement.appendChild(node.content);
|
|
3528
|
+
const rect = node.content.getBoundingClientRect();
|
|
3529
|
+
if (parent) parent.appendChild(node.content);
|
|
3530
|
+
if (Math.abs(oldDims.w - rect.width) > 0.5 || Math.abs(oldDims.h - rect.height) > 0.5) {
|
|
3531
|
+
changed = true;
|
|
3532
|
+
break;
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
return changed;
|
|
3536
|
+
}
|
|
3470
3537
|
/** Cleanup resources when the canvas is destroyed */
|
|
3471
3538
|
destroy() {
|
|
3539
|
+
this.cancelSettleCheck();
|
|
3472
3540
|
this.dynamicStyleEl?.remove();
|
|
3473
3541
|
this.dynamicStyleEl = void 0;
|
|
3474
3542
|
this.measurement?.remove();
|
|
@@ -4186,6 +4254,7 @@ var API = class {
|
|
|
4186
4254
|
this.nav("last");
|
|
4187
4255
|
if (this.events.historyChange)
|
|
4188
4256
|
this.events.historyChange(this.index, this.seq.length);
|
|
4257
|
+
this.canvas.scheduleSettleCheck();
|
|
4189
4258
|
}
|
|
4190
4259
|
setNodePositions() {
|
|
4191
4260
|
const { graph: graph2 } = this.state;
|