@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.cjs
CHANGED
|
@@ -2855,6 +2855,10 @@ var Canvas = class {
|
|
|
2855
2855
|
curNodes;
|
|
2856
2856
|
curSegs;
|
|
2857
2857
|
updating;
|
|
2858
|
+
// Settle check state
|
|
2859
|
+
settleTimer;
|
|
2860
|
+
settleCount = 0;
|
|
2861
|
+
settleMaxRebuilds = 2;
|
|
2858
2862
|
// Unique marker ID prefix for this canvas instance
|
|
2859
2863
|
markerPrefix;
|
|
2860
2864
|
// Dynamic style element for this instance (for cleanup)
|
|
@@ -3520,8 +3524,62 @@ var Canvas = class {
|
|
|
3520
3524
|
this.container.classList.add(`g3p-${colorMode}`);
|
|
3521
3525
|
}
|
|
3522
3526
|
}
|
|
3527
|
+
/**
|
|
3528
|
+
* Schedule a settle check: periodically re-measure nodes in case
|
|
3529
|
+
* async style injection (e.g. CSS-in-JS) changed their size after
|
|
3530
|
+
* the initial measurement. If any node's size changed, triggers a
|
|
3531
|
+
* rebuild to relayout the graph with correct dimensions.
|
|
3532
|
+
*/
|
|
3533
|
+
scheduleSettleCheck() {
|
|
3534
|
+
this.cancelSettleCheck();
|
|
3535
|
+
this.settleCount = 0;
|
|
3536
|
+
this.doSettleCheck();
|
|
3537
|
+
}
|
|
3538
|
+
cancelSettleCheck() {
|
|
3539
|
+
if (this.settleTimer) {
|
|
3540
|
+
clearTimeout(this.settleTimer);
|
|
3541
|
+
this.settleTimer = void 0;
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
doSettleCheck() {
|
|
3545
|
+
const delay = this.settleCount === 0 ? 50 : 150;
|
|
3546
|
+
this.settleTimer = setTimeout(() => {
|
|
3547
|
+
this.settleTimer = void 0;
|
|
3548
|
+
if (this.checkNodeSizes()) {
|
|
3549
|
+
if (this.settleCount < this.settleMaxRebuilds) {
|
|
3550
|
+
this.settleCount++;
|
|
3551
|
+
this.api.rebuild();
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
}, delay);
|
|
3555
|
+
}
|
|
3556
|
+
/**
|
|
3557
|
+
* Re-measure every live non-dummy node by temporarily moving its
|
|
3558
|
+
* content to the off-screen measurement container (synchronous,
|
|
3559
|
+
* no visual flash). Returns true if any node's size changed.
|
|
3560
|
+
*/
|
|
3561
|
+
checkNodeSizes() {
|
|
3562
|
+
if (!this.measurement) return false;
|
|
3563
|
+
const isVertical = this.orientation === "TB" || this.orientation === "BT";
|
|
3564
|
+
let changed = false;
|
|
3565
|
+
for (const node of this.curNodes.values()) {
|
|
3566
|
+
if (node.isDummy || !node.content) continue;
|
|
3567
|
+
const oldDims = node.data?.dims;
|
|
3568
|
+
if (!oldDims) continue;
|
|
3569
|
+
const parent = node.content.parentElement;
|
|
3570
|
+
this.measurement.appendChild(node.content);
|
|
3571
|
+
const rect = node.content.getBoundingClientRect();
|
|
3572
|
+
if (parent) parent.appendChild(node.content);
|
|
3573
|
+
if (Math.abs(oldDims.w - rect.width) > 0.5 || Math.abs(oldDims.h - rect.height) > 0.5) {
|
|
3574
|
+
changed = true;
|
|
3575
|
+
break;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
return changed;
|
|
3579
|
+
}
|
|
3523
3580
|
/** Cleanup resources when the canvas is destroyed */
|
|
3524
3581
|
destroy() {
|
|
3582
|
+
this.cancelSettleCheck();
|
|
3525
3583
|
this.dynamicStyleEl?.remove();
|
|
3526
3584
|
this.dynamicStyleEl = void 0;
|
|
3527
3585
|
this.measurement?.remove();
|
|
@@ -4239,6 +4297,7 @@ var API = class {
|
|
|
4239
4297
|
this.nav("last");
|
|
4240
4298
|
if (this.events.historyChange)
|
|
4241
4299
|
this.events.historyChange(this.index, this.seq.length);
|
|
4300
|
+
this.canvas.scheduleSettleCheck();
|
|
4242
4301
|
}
|
|
4243
4302
|
setNodePositions() {
|
|
4244
4303
|
const { graph: graph2 } = this.state;
|