@almadar/ui 5.118.0 → 5.119.0

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.
@@ -35367,11 +35367,11 @@ var init_DocumentViewer = __esm({
35367
35367
  DocumentViewer.displayName = "DocumentViewer";
35368
35368
  }
35369
35369
  });
35370
- function measureLabelWidth(text) {
35370
+ function measureLabelWidth(text, fontFamily = "system-ui") {
35371
35371
  if (typeof document === "undefined") return text.length * 6;
35372
35372
  if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
35373
35373
  if (!labelMeasureCtx) return text.length * 6;
35374
- labelMeasureCtx.font = "12px system-ui";
35374
+ labelMeasureCtx.font = `12px ${fontFamily}`;
35375
35375
  return labelMeasureCtx.measureText(text).width + 4;
35376
35376
  }
35377
35377
  function getGroupColor(group, groups) {
@@ -35396,6 +35396,9 @@ function mulberry32(a) {
35396
35396
  return ((t ^ t >>> 14) >>> 0) / 4294967296;
35397
35397
  };
35398
35398
  }
35399
+ function edgeKeyOf(a, b) {
35400
+ return a < b ? `${a}\0${b}` : `${b}\0${a}`;
35401
+ }
35399
35402
  function resolveColor3(color, el) {
35400
35403
  const m = /^var\((--[^,)]+)(?:,\s*([^)]+))?\)$/.exec(color.trim());
35401
35404
  if (!m) return color;
@@ -35529,6 +35532,7 @@ var init_GraphCanvas = __esm({
35529
35532
  if (!canvas || propNodes.length === 0) return;
35530
35533
  const w = logicalW;
35531
35534
  const h = height;
35535
+ const labelFont = resolveColor3("var(--font-family)", canvas) || "system-ui";
35532
35536
  const prevPos = /* @__PURE__ */ new Map();
35533
35537
  for (const pn of nodesRef.current) if (pn.x != null && pn.y != null) prevPos.set(pn.id, { x: pn.x, y: pn.y });
35534
35538
  const simNodes = propNodes.map((n, idx) => {
@@ -35563,10 +35567,15 @@ var init_GraphCanvas = __esm({
35563
35567
  const fullRelayout = !laidOutRef.current || overlap < 0.5;
35564
35568
  if (layout === "force") {
35565
35569
  const maxIterations = 300;
35566
- const tick = () => {
35570
+ const COOL = 0.12;
35571
+ const COLLIDE_PASSES = 6;
35572
+ const LABEL_GAP = 12;
35573
+ const LABEL_H = 16;
35574
+ const tick = (iter) => {
35567
35575
  const nodes = nodesRef.current;
35568
35576
  const centerX = w / 2;
35569
35577
  const centerY = h / 2;
35578
+ const temp = Math.max(COOL, 1 - iter / maxIterations);
35570
35579
  for (const node of nodes) {
35571
35580
  node.fx = 0;
35572
35581
  node.fy = 0;
@@ -35576,7 +35585,7 @@ var init_GraphCanvas = __esm({
35576
35585
  const dx = nodes[j].x - nodes[i].x;
35577
35586
  const dy = nodes[j].y - nodes[i].y;
35578
35587
  const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35579
- const force = repulsion / (dist * dist);
35588
+ const force = repulsion / (dist * dist) * temp;
35580
35589
  const fx = dx / dist * force;
35581
35590
  const fy = dy / dist * force;
35582
35591
  nodes[i].fx -= fx;
@@ -35586,42 +35595,34 @@ var init_GraphCanvas = __esm({
35586
35595
  }
35587
35596
  }
35588
35597
  const nodeById = new Map(nodes.map((n) => [n.id, n]));
35589
- if (propSimilarity.length > 0) {
35590
- for (const pair of propSimilarity) {
35591
- const source = nodeById.get(pair.source);
35592
- const target = nodeById.get(pair.target);
35593
- if (!source || !target) continue;
35594
- const dx = target.x - source.x;
35595
- const dy = target.y - source.y;
35596
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35597
- const w2 = Math.min(1, Math.max(0, pair.weight));
35598
- const linkTarget = linkDistance * (1 - w2);
35599
- const force = (dist - linkTarget) * (0.04 + 0.1 * w2);
35600
- const fx = dx / dist * force;
35601
- const fy = dy / dist * force;
35602
- source.fx += fx;
35603
- source.fy += fy;
35604
- target.fx -= fx;
35605
- target.fy -= fy;
35606
- }
35607
- } else {
35608
- for (const edge of propEdges) {
35609
- const source = nodeById.get(edge.source);
35610
- const target = nodeById.get(edge.target);
35611
- if (!source || !target) continue;
35612
- const dx = target.x - source.x;
35613
- const dy = target.y - source.y;
35614
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35615
- const w2 = Math.min(1, Math.max(0, edge.weight ?? 1));
35616
- const linkTarget = linkDistance * (0.5 + (1 - w2) * 1.5);
35617
- const force = (dist - linkTarget) * (0.04 + 0.1 * w2);
35618
- const fx = dx / dist * force;
35619
- const fy = dy / dist * force;
35620
- source.fx += fx;
35621
- source.fy += fy;
35622
- target.fx -= fx;
35623
- target.fy -= fy;
35624
- }
35598
+ const spring = (a, b, rest, k) => {
35599
+ const dx = b.x - a.x;
35600
+ const dy = b.y - a.y;
35601
+ const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35602
+ const force = (dist - rest) * k * temp;
35603
+ const fx = dx / dist * force;
35604
+ const fy = dy / dist * force;
35605
+ a.fx += fx;
35606
+ a.fy += fy;
35607
+ b.fx -= fx;
35608
+ b.fy -= fy;
35609
+ };
35610
+ const drawnPairs = /* @__PURE__ */ new Set();
35611
+ for (const edge of propEdges) {
35612
+ const source = nodeById.get(edge.source);
35613
+ const target = nodeById.get(edge.target);
35614
+ if (!source || !target) continue;
35615
+ drawnPairs.add(edgeKeyOf(edge.source, edge.target));
35616
+ const w2 = Math.min(1, Math.max(0, edge.weight ?? 1));
35617
+ spring(source, target, linkDistance * (0.35 + (1 - w2) * 0.3), 0.14);
35618
+ }
35619
+ for (const pair of propSimilarity) {
35620
+ if (drawnPairs.has(edgeKeyOf(pair.source, pair.target))) continue;
35621
+ const source = nodeById.get(pair.source);
35622
+ const target = nodeById.get(pair.target);
35623
+ if (!source || !target) continue;
35624
+ const w2 = Math.min(1, Math.max(0, pair.weight));
35625
+ spring(source, target, linkDistance * (1.35 - 0.55 * w2), 0.015);
35625
35626
  }
35626
35627
  const centroids = /* @__PURE__ */ new Map();
35627
35628
  for (const node of nodes) {
@@ -35635,14 +35636,20 @@ var init_GraphCanvas = __esm({
35635
35636
  c.y += node.y;
35636
35637
  c.n += 1;
35637
35638
  }
35639
+ const multiCluster = centroids.size > 1;
35638
35640
  for (const node of nodes) {
35639
- const c = centroids.get(node.group ?? "__none__");
35640
- if (c && c.n > 1) {
35641
- node.fx += (c.x / c.n - node.x) * 0.04;
35642
- node.fy += (c.y / c.n - node.y) * 0.04;
35641
+ if (multiCluster) {
35642
+ const c = centroids.get(node.group ?? "__none__");
35643
+ if (c && c.n > 1) {
35644
+ node.fx += (c.x / c.n - node.x) * 0.04 * temp;
35645
+ node.fy += (c.y / c.n - node.y) * 0.04 * temp;
35646
+ } else {
35647
+ node.fx += (centerX - node.x) * 0.01 * temp;
35648
+ node.fy += (centerY - node.y) * 0.01 * temp;
35649
+ }
35643
35650
  } else {
35644
- node.fx += (centerX - node.x) * 0.01;
35645
- node.fy += (centerY - node.y) * 0.01;
35651
+ node.fx += (centerX - node.x) * 8e-3 * temp;
35652
+ node.fy += (centerY - node.y) * 8e-3 * temp;
35646
35653
  }
35647
35654
  }
35648
35655
  const damping = 0.9;
@@ -35654,42 +35661,53 @@ var init_GraphCanvas = __esm({
35654
35661
  node.x = Math.max(30, Math.min(w - 30, node.x));
35655
35662
  node.y = Math.max(30, Math.min(h - 30, node.y));
35656
35663
  }
35657
- const LABEL_GAP = 12;
35658
- const LABEL_H = 16;
35659
35664
  const pad = nodeSpacing / 2;
35660
- for (let i = 0; i < nodes.length; i++) {
35661
- for (let j = i + 1; j < nodes.length; j++) {
35662
- const a = nodes[i];
35663
- const b = nodes[j];
35664
- const ar = a.size || 8;
35665
- const br = b.size || 8;
35666
- if (showLabels) {
35667
- if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
35668
- if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
35669
- }
35670
- const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
35671
- const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
35672
- const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
35673
- const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
35674
- const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
35675
- const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
35676
- const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
35677
- if (overlapX > 0 && overlapY > 0) {
35678
- if (overlapX <= overlapY) {
35679
- const push = overlapX / 2 * (b.x >= a.x ? 1 : -1);
35680
- a.x = Math.max(30, Math.min(w - 30, a.x - push));
35681
- b.x = Math.max(30, Math.min(w - 30, b.x + push));
35682
- } else {
35683
- const push = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
35684
- a.y = Math.max(30, Math.min(h - 30, a.y - push));
35685
- b.y = Math.max(30, Math.min(h - 30, b.y + push));
35665
+ const rectsOf = (n) => {
35666
+ const r = n.size || 8;
35667
+ const lw = showLabels ? n.labelW ?? (n.labelW = n.label ? measureLabelWidth(n.label, labelFont) : 0) : 0;
35668
+ return {
35669
+ circle: [n.x - r - pad, n.y - r - pad, n.x + r + pad, n.y + r + pad],
35670
+ label: [n.x - lw / 2 - pad, n.y + r + LABEL_GAP - 8, n.x + lw / 2 + pad, n.y + r + LABEL_GAP + LABEL_H]
35671
+ };
35672
+ };
35673
+ const sep = (r1, r2) => {
35674
+ const ox = Math.min(r1[2], r2[2]) - Math.max(r1[0], r2[0]);
35675
+ const oy = Math.min(r1[3], r2[3]) - Math.max(r1[1], r2[1]);
35676
+ if (ox <= 0 || oy <= 0) return null;
35677
+ return ox <= oy ? { axis: "x", depth: ox, sign: r1[0] + r1[2] < r2[0] + r2[2] ? 1 : -1 } : { axis: "y", depth: oy, sign: r1[1] + r1[3] < r2[1] + r2[3] ? 1 : -1 };
35678
+ };
35679
+ for (let pass = 0; pass < COLLIDE_PASSES; pass++) {
35680
+ for (let i = 0; i < nodes.length; i++) {
35681
+ for (let j = i + 1; j < nodes.length; j++) {
35682
+ const a = nodes[i];
35683
+ const b = nodes[j];
35684
+ const ra = rectsOf(a);
35685
+ const rb = rectsOf(b);
35686
+ let best = null;
35687
+ for (const [r1, r2] of [[ra.circle, rb.circle], [ra.circle, rb.label], [ra.label, rb.circle], [ra.label, rb.label]]) {
35688
+ const s = sep(r1, r2);
35689
+ if (s && (!best || s.depth < best.depth)) best = s;
35690
+ }
35691
+ if (best) {
35692
+ const push = best.depth / 2;
35693
+ if (best.axis === "x") {
35694
+ a.x = Math.max(30, Math.min(w - 30, a.x - push * best.sign));
35695
+ b.x = Math.max(30, Math.min(w - 30, b.x + push * best.sign));
35696
+ a.vx = 0;
35697
+ b.vx = 0;
35698
+ } else {
35699
+ a.y = Math.max(30, Math.min(h - 30, a.y - push * best.sign));
35700
+ b.y = Math.max(30, Math.min(h - 30, b.y + push * best.sign));
35701
+ a.vy = 0;
35702
+ b.vy = 0;
35703
+ }
35686
35704
  }
35687
35705
  }
35688
35706
  }
35689
35707
  }
35690
35708
  };
35691
35709
  if (fullRelayout) {
35692
- for (let i = 0; i < maxIterations; i++) tick();
35710
+ for (let i = 0; i < maxIterations; i++) tick(i);
35693
35711
  laidOutRef.current = true;
35694
35712
  } else {
35695
35713
  const centroids = /* @__PURE__ */ new Map();
@@ -35322,11 +35322,11 @@ var init_DocumentViewer = __esm({
35322
35322
  DocumentViewer.displayName = "DocumentViewer";
35323
35323
  }
35324
35324
  });
35325
- function measureLabelWidth(text) {
35325
+ function measureLabelWidth(text, fontFamily = "system-ui") {
35326
35326
  if (typeof document === "undefined") return text.length * 6;
35327
35327
  if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
35328
35328
  if (!labelMeasureCtx) return text.length * 6;
35329
- labelMeasureCtx.font = "12px system-ui";
35329
+ labelMeasureCtx.font = `12px ${fontFamily}`;
35330
35330
  return labelMeasureCtx.measureText(text).width + 4;
35331
35331
  }
35332
35332
  function getGroupColor(group, groups) {
@@ -35351,6 +35351,9 @@ function mulberry32(a) {
35351
35351
  return ((t ^ t >>> 14) >>> 0) / 4294967296;
35352
35352
  };
35353
35353
  }
35354
+ function edgeKeyOf(a, b) {
35355
+ return a < b ? `${a}\0${b}` : `${b}\0${a}`;
35356
+ }
35354
35357
  function resolveColor3(color, el) {
35355
35358
  const m = /^var\((--[^,)]+)(?:,\s*([^)]+))?\)$/.exec(color.trim());
35356
35359
  if (!m) return color;
@@ -35484,6 +35487,7 @@ var init_GraphCanvas = __esm({
35484
35487
  if (!canvas || propNodes.length === 0) return;
35485
35488
  const w = logicalW;
35486
35489
  const h = height;
35490
+ const labelFont = resolveColor3("var(--font-family)", canvas) || "system-ui";
35487
35491
  const prevPos = /* @__PURE__ */ new Map();
35488
35492
  for (const pn of nodesRef.current) if (pn.x != null && pn.y != null) prevPos.set(pn.id, { x: pn.x, y: pn.y });
35489
35493
  const simNodes = propNodes.map((n, idx) => {
@@ -35518,10 +35522,15 @@ var init_GraphCanvas = __esm({
35518
35522
  const fullRelayout = !laidOutRef.current || overlap < 0.5;
35519
35523
  if (layout === "force") {
35520
35524
  const maxIterations = 300;
35521
- const tick = () => {
35525
+ const COOL = 0.12;
35526
+ const COLLIDE_PASSES = 6;
35527
+ const LABEL_GAP = 12;
35528
+ const LABEL_H = 16;
35529
+ const tick = (iter) => {
35522
35530
  const nodes = nodesRef.current;
35523
35531
  const centerX = w / 2;
35524
35532
  const centerY = h / 2;
35533
+ const temp = Math.max(COOL, 1 - iter / maxIterations);
35525
35534
  for (const node of nodes) {
35526
35535
  node.fx = 0;
35527
35536
  node.fy = 0;
@@ -35531,7 +35540,7 @@ var init_GraphCanvas = __esm({
35531
35540
  const dx = nodes[j].x - nodes[i].x;
35532
35541
  const dy = nodes[j].y - nodes[i].y;
35533
35542
  const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35534
- const force = repulsion / (dist * dist);
35543
+ const force = repulsion / (dist * dist) * temp;
35535
35544
  const fx = dx / dist * force;
35536
35545
  const fy = dy / dist * force;
35537
35546
  nodes[i].fx -= fx;
@@ -35541,42 +35550,34 @@ var init_GraphCanvas = __esm({
35541
35550
  }
35542
35551
  }
35543
35552
  const nodeById = new Map(nodes.map((n) => [n.id, n]));
35544
- if (propSimilarity.length > 0) {
35545
- for (const pair of propSimilarity) {
35546
- const source = nodeById.get(pair.source);
35547
- const target = nodeById.get(pair.target);
35548
- if (!source || !target) continue;
35549
- const dx = target.x - source.x;
35550
- const dy = target.y - source.y;
35551
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35552
- const w2 = Math.min(1, Math.max(0, pair.weight));
35553
- const linkTarget = linkDistance * (1 - w2);
35554
- const force = (dist - linkTarget) * (0.04 + 0.1 * w2);
35555
- const fx = dx / dist * force;
35556
- const fy = dy / dist * force;
35557
- source.fx += fx;
35558
- source.fy += fy;
35559
- target.fx -= fx;
35560
- target.fy -= fy;
35561
- }
35562
- } else {
35563
- for (const edge of propEdges) {
35564
- const source = nodeById.get(edge.source);
35565
- const target = nodeById.get(edge.target);
35566
- if (!source || !target) continue;
35567
- const dx = target.x - source.x;
35568
- const dy = target.y - source.y;
35569
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35570
- const w2 = Math.min(1, Math.max(0, edge.weight ?? 1));
35571
- const linkTarget = linkDistance * (0.5 + (1 - w2) * 1.5);
35572
- const force = (dist - linkTarget) * (0.04 + 0.1 * w2);
35573
- const fx = dx / dist * force;
35574
- const fy = dy / dist * force;
35575
- source.fx += fx;
35576
- source.fy += fy;
35577
- target.fx -= fx;
35578
- target.fy -= fy;
35579
- }
35553
+ const spring = (a, b, rest, k) => {
35554
+ const dx = b.x - a.x;
35555
+ const dy = b.y - a.y;
35556
+ const dist = Math.sqrt(dx * dx + dy * dy) || 1;
35557
+ const force = (dist - rest) * k * temp;
35558
+ const fx = dx / dist * force;
35559
+ const fy = dy / dist * force;
35560
+ a.fx += fx;
35561
+ a.fy += fy;
35562
+ b.fx -= fx;
35563
+ b.fy -= fy;
35564
+ };
35565
+ const drawnPairs = /* @__PURE__ */ new Set();
35566
+ for (const edge of propEdges) {
35567
+ const source = nodeById.get(edge.source);
35568
+ const target = nodeById.get(edge.target);
35569
+ if (!source || !target) continue;
35570
+ drawnPairs.add(edgeKeyOf(edge.source, edge.target));
35571
+ const w2 = Math.min(1, Math.max(0, edge.weight ?? 1));
35572
+ spring(source, target, linkDistance * (0.35 + (1 - w2) * 0.3), 0.14);
35573
+ }
35574
+ for (const pair of propSimilarity) {
35575
+ if (drawnPairs.has(edgeKeyOf(pair.source, pair.target))) continue;
35576
+ const source = nodeById.get(pair.source);
35577
+ const target = nodeById.get(pair.target);
35578
+ if (!source || !target) continue;
35579
+ const w2 = Math.min(1, Math.max(0, pair.weight));
35580
+ spring(source, target, linkDistance * (1.35 - 0.55 * w2), 0.015);
35580
35581
  }
35581
35582
  const centroids = /* @__PURE__ */ new Map();
35582
35583
  for (const node of nodes) {
@@ -35590,14 +35591,20 @@ var init_GraphCanvas = __esm({
35590
35591
  c.y += node.y;
35591
35592
  c.n += 1;
35592
35593
  }
35594
+ const multiCluster = centroids.size > 1;
35593
35595
  for (const node of nodes) {
35594
- const c = centroids.get(node.group ?? "__none__");
35595
- if (c && c.n > 1) {
35596
- node.fx += (c.x / c.n - node.x) * 0.04;
35597
- node.fy += (c.y / c.n - node.y) * 0.04;
35596
+ if (multiCluster) {
35597
+ const c = centroids.get(node.group ?? "__none__");
35598
+ if (c && c.n > 1) {
35599
+ node.fx += (c.x / c.n - node.x) * 0.04 * temp;
35600
+ node.fy += (c.y / c.n - node.y) * 0.04 * temp;
35601
+ } else {
35602
+ node.fx += (centerX - node.x) * 0.01 * temp;
35603
+ node.fy += (centerY - node.y) * 0.01 * temp;
35604
+ }
35598
35605
  } else {
35599
- node.fx += (centerX - node.x) * 0.01;
35600
- node.fy += (centerY - node.y) * 0.01;
35606
+ node.fx += (centerX - node.x) * 8e-3 * temp;
35607
+ node.fy += (centerY - node.y) * 8e-3 * temp;
35601
35608
  }
35602
35609
  }
35603
35610
  const damping = 0.9;
@@ -35609,42 +35616,53 @@ var init_GraphCanvas = __esm({
35609
35616
  node.x = Math.max(30, Math.min(w - 30, node.x));
35610
35617
  node.y = Math.max(30, Math.min(h - 30, node.y));
35611
35618
  }
35612
- const LABEL_GAP = 12;
35613
- const LABEL_H = 16;
35614
35619
  const pad = nodeSpacing / 2;
35615
- for (let i = 0; i < nodes.length; i++) {
35616
- for (let j = i + 1; j < nodes.length; j++) {
35617
- const a = nodes[i];
35618
- const b = nodes[j];
35619
- const ar = a.size || 8;
35620
- const br = b.size || 8;
35621
- if (showLabels) {
35622
- if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
35623
- if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
35624
- }
35625
- const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
35626
- const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
35627
- const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
35628
- const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
35629
- const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
35630
- const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
35631
- const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
35632
- if (overlapX > 0 && overlapY > 0) {
35633
- if (overlapX <= overlapY) {
35634
- const push = overlapX / 2 * (b.x >= a.x ? 1 : -1);
35635
- a.x = Math.max(30, Math.min(w - 30, a.x - push));
35636
- b.x = Math.max(30, Math.min(w - 30, b.x + push));
35637
- } else {
35638
- const push = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
35639
- a.y = Math.max(30, Math.min(h - 30, a.y - push));
35640
- b.y = Math.max(30, Math.min(h - 30, b.y + push));
35620
+ const rectsOf = (n) => {
35621
+ const r = n.size || 8;
35622
+ const lw = showLabels ? n.labelW ?? (n.labelW = n.label ? measureLabelWidth(n.label, labelFont) : 0) : 0;
35623
+ return {
35624
+ circle: [n.x - r - pad, n.y - r - pad, n.x + r + pad, n.y + r + pad],
35625
+ label: [n.x - lw / 2 - pad, n.y + r + LABEL_GAP - 8, n.x + lw / 2 + pad, n.y + r + LABEL_GAP + LABEL_H]
35626
+ };
35627
+ };
35628
+ const sep = (r1, r2) => {
35629
+ const ox = Math.min(r1[2], r2[2]) - Math.max(r1[0], r2[0]);
35630
+ const oy = Math.min(r1[3], r2[3]) - Math.max(r1[1], r2[1]);
35631
+ if (ox <= 0 || oy <= 0) return null;
35632
+ return ox <= oy ? { axis: "x", depth: ox, sign: r1[0] + r1[2] < r2[0] + r2[2] ? 1 : -1 } : { axis: "y", depth: oy, sign: r1[1] + r1[3] < r2[1] + r2[3] ? 1 : -1 };
35633
+ };
35634
+ for (let pass = 0; pass < COLLIDE_PASSES; pass++) {
35635
+ for (let i = 0; i < nodes.length; i++) {
35636
+ for (let j = i + 1; j < nodes.length; j++) {
35637
+ const a = nodes[i];
35638
+ const b = nodes[j];
35639
+ const ra = rectsOf(a);
35640
+ const rb = rectsOf(b);
35641
+ let best = null;
35642
+ for (const [r1, r2] of [[ra.circle, rb.circle], [ra.circle, rb.label], [ra.label, rb.circle], [ra.label, rb.label]]) {
35643
+ const s = sep(r1, r2);
35644
+ if (s && (!best || s.depth < best.depth)) best = s;
35645
+ }
35646
+ if (best) {
35647
+ const push = best.depth / 2;
35648
+ if (best.axis === "x") {
35649
+ a.x = Math.max(30, Math.min(w - 30, a.x - push * best.sign));
35650
+ b.x = Math.max(30, Math.min(w - 30, b.x + push * best.sign));
35651
+ a.vx = 0;
35652
+ b.vx = 0;
35653
+ } else {
35654
+ a.y = Math.max(30, Math.min(h - 30, a.y - push * best.sign));
35655
+ b.y = Math.max(30, Math.min(h - 30, b.y + push * best.sign));
35656
+ a.vy = 0;
35657
+ b.vy = 0;
35658
+ }
35641
35659
  }
35642
35660
  }
35643
35661
  }
35644
35662
  }
35645
35663
  };
35646
35664
  if (fullRelayout) {
35647
- for (let i = 0; i < maxIterations; i++) tick();
35665
+ for (let i = 0; i < maxIterations; i++) tick(i);
35648
35666
  laidOutRef.current = true;
35649
35667
  } else {
35650
35668
  const centroids = /* @__PURE__ */ new Map();