@3plate/graph-core 0.1.17 → 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 +59 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -0
- 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)
|
|
@@ -3477,8 +3481,62 @@ var Canvas = class {
|
|
|
3477
3481
|
this.container.classList.add(`g3p-${colorMode}`);
|
|
3478
3482
|
}
|
|
3479
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
|
+
}
|
|
3480
3537
|
/** Cleanup resources when the canvas is destroyed */
|
|
3481
3538
|
destroy() {
|
|
3539
|
+
this.cancelSettleCheck();
|
|
3482
3540
|
this.dynamicStyleEl?.remove();
|
|
3483
3541
|
this.dynamicStyleEl = void 0;
|
|
3484
3542
|
this.measurement?.remove();
|
|
@@ -4196,6 +4254,7 @@ var API = class {
|
|
|
4196
4254
|
this.nav("last");
|
|
4197
4255
|
if (this.events.historyChange)
|
|
4198
4256
|
this.events.historyChange(this.index, this.seq.length);
|
|
4257
|
+
this.canvas.scheduleSettleCheck();
|
|
4199
4258
|
}
|
|
4200
4259
|
setNodePositions() {
|
|
4201
4260
|
const { graph: graph2 } = this.state;
|