@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 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)
@@ -2984,7 +2988,17 @@ var Canvas = class {
2984
2988
  }
2985
2989
  }
2986
2990
  }
2987
- await new Promise(requestAnimationFrame);
2991
+ await new Promise((resolve) => {
2992
+ let resolved = false;
2993
+ const done = () => {
2994
+ if (!resolved) {
2995
+ resolved = true;
2996
+ resolve();
2997
+ }
2998
+ };
2999
+ requestAnimationFrame(done);
3000
+ setTimeout(done, 50);
3001
+ });
2988
3002
  const isVertical = this.orientation === "TB" || this.orientation === "BT";
2989
3003
  for (const node of newNodes.values()) {
2990
3004
  node.measure(isVertical);
@@ -3510,8 +3524,62 @@ var Canvas = class {
3510
3524
  this.container.classList.add(`g3p-${colorMode}`);
3511
3525
  }
3512
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
+ }
3513
3580
  /** Cleanup resources when the canvas is destroyed */
3514
3581
  destroy() {
3582
+ this.cancelSettleCheck();
3515
3583
  this.dynamicStyleEl?.remove();
3516
3584
  this.dynamicStyleEl = void 0;
3517
3585
  this.measurement?.remove();
@@ -4229,6 +4297,7 @@ var API = class {
4229
4297
  this.nav("last");
4230
4298
  if (this.events.historyChange)
4231
4299
  this.events.historyChange(this.index, this.seq.length);
4300
+ this.canvas.scheduleSettleCheck();
4232
4301
  }
4233
4302
  setNodePositions() {
4234
4303
  const { graph: graph2 } = this.state;