@almadar/ui 5.63.1 → 5.63.2

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.
@@ -41203,6 +41203,13 @@ var init_DocumentViewer = __esm({
41203
41203
  DocumentViewer.displayName = "DocumentViewer";
41204
41204
  }
41205
41205
  });
41206
+ function measureLabelWidth(text) {
41207
+ if (typeof document === "undefined") return text.length * 6;
41208
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
41209
+ if (!labelMeasureCtx) return text.length * 6;
41210
+ labelMeasureCtx.font = "10px system-ui";
41211
+ return labelMeasureCtx.measureText(text).width;
41212
+ }
41206
41213
  function getGroupColor(group, groups) {
41207
41214
  if (!group) return GROUP_COLORS2[0];
41208
41215
  const idx = groups.indexOf(group);
@@ -41214,7 +41221,7 @@ function resolveColor2(color, el) {
41214
41221
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
41215
41222
  return resolved || (m[2]?.trim() ?? "#888888");
41216
41223
  }
41217
- var GROUP_COLORS2, GraphCanvas;
41224
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
41218
41225
  var init_GraphCanvas = __esm({
41219
41226
  "components/core/molecules/GraphCanvas.tsx"() {
41220
41227
  "use client";
@@ -41234,6 +41241,7 @@ var init_GraphCanvas = __esm({
41234
41241
  "var(--color-info)",
41235
41242
  "var(--color-accent)"
41236
41243
  ];
41244
+ labelMeasureCtx = null;
41237
41245
  GraphCanvas = ({
41238
41246
  title,
41239
41247
  nodes: propNodes = [],
@@ -41414,22 +41422,36 @@ var init_GraphCanvas = __esm({
41414
41422
  node.x = Math.max(30, Math.min(w - 30, node.x));
41415
41423
  node.y = Math.max(30, Math.min(h - 30, node.y));
41416
41424
  }
41425
+ const LABEL_GAP = 12;
41426
+ const LABEL_H = 12;
41427
+ const pad = nodeSpacing / 2;
41417
41428
  for (let i = 0; i < nodes.length; i++) {
41418
41429
  for (let j = i + 1; j < nodes.length; j++) {
41419
41430
  const a = nodes[i];
41420
41431
  const b = nodes[j];
41421
- const dx = b.x - a.x;
41422
- const dy = b.y - a.y;
41423
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
41424
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
41425
- if (dist < minDist) {
41426
- const push2 = (minDist - dist) / 2;
41427
- const ux = dx / dist;
41428
- const uy = dy / dist;
41429
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push2));
41430
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push2));
41431
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push2));
41432
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push2));
41432
+ const ar = a.size || 8;
41433
+ const br = b.size || 8;
41434
+ if (showLabels) {
41435
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
41436
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
41437
+ }
41438
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
41439
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
41440
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
41441
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
41442
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
41443
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
41444
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
41445
+ if (overlapX > 0 && overlapY > 0) {
41446
+ if (overlapX <= overlapY) {
41447
+ const push2 = overlapX / 2 * (b.x >= a.x ? 1 : -1);
41448
+ a.x = Math.max(30, Math.min(w - 30, a.x - push2));
41449
+ b.x = Math.max(30, Math.min(w - 30, b.x + push2));
41450
+ } else {
41451
+ const push2 = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
41452
+ a.y = Math.max(30, Math.min(h - 30, a.y - push2));
41453
+ b.y = Math.max(30, Math.min(h - 30, b.y + push2));
41454
+ }
41433
41455
  }
41434
41456
  }
41435
41457
  }
@@ -41446,7 +41468,7 @@ var init_GraphCanvas = __esm({
41446
41468
  return () => {
41447
41469
  cancelAnimationFrame(animRef.current);
41448
41470
  };
41449
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
41471
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
41450
41472
  React93.useEffect(() => {
41451
41473
  const canvas = canvasRef.current;
41452
41474
  if (!canvas) return;
package/dist/avl/index.js CHANGED
@@ -41156,6 +41156,13 @@ var init_DocumentViewer = __esm({
41156
41156
  DocumentViewer.displayName = "DocumentViewer";
41157
41157
  }
41158
41158
  });
41159
+ function measureLabelWidth(text) {
41160
+ if (typeof document === "undefined") return text.length * 6;
41161
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
41162
+ if (!labelMeasureCtx) return text.length * 6;
41163
+ labelMeasureCtx.font = "10px system-ui";
41164
+ return labelMeasureCtx.measureText(text).width;
41165
+ }
41159
41166
  function getGroupColor(group, groups) {
41160
41167
  if (!group) return GROUP_COLORS2[0];
41161
41168
  const idx = groups.indexOf(group);
@@ -41167,7 +41174,7 @@ function resolveColor2(color, el) {
41167
41174
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
41168
41175
  return resolved || (m[2]?.trim() ?? "#888888");
41169
41176
  }
41170
- var GROUP_COLORS2, GraphCanvas;
41177
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
41171
41178
  var init_GraphCanvas = __esm({
41172
41179
  "components/core/molecules/GraphCanvas.tsx"() {
41173
41180
  "use client";
@@ -41187,6 +41194,7 @@ var init_GraphCanvas = __esm({
41187
41194
  "var(--color-info)",
41188
41195
  "var(--color-accent)"
41189
41196
  ];
41197
+ labelMeasureCtx = null;
41190
41198
  GraphCanvas = ({
41191
41199
  title,
41192
41200
  nodes: propNodes = [],
@@ -41367,22 +41375,36 @@ var init_GraphCanvas = __esm({
41367
41375
  node.x = Math.max(30, Math.min(w - 30, node.x));
41368
41376
  node.y = Math.max(30, Math.min(h - 30, node.y));
41369
41377
  }
41378
+ const LABEL_GAP = 12;
41379
+ const LABEL_H = 12;
41380
+ const pad = nodeSpacing / 2;
41370
41381
  for (let i = 0; i < nodes.length; i++) {
41371
41382
  for (let j = i + 1; j < nodes.length; j++) {
41372
41383
  const a = nodes[i];
41373
41384
  const b = nodes[j];
41374
- const dx = b.x - a.x;
41375
- const dy = b.y - a.y;
41376
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
41377
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
41378
- if (dist < minDist) {
41379
- const push2 = (minDist - dist) / 2;
41380
- const ux = dx / dist;
41381
- const uy = dy / dist;
41382
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push2));
41383
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push2));
41384
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push2));
41385
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push2));
41385
+ const ar = a.size || 8;
41386
+ const br = b.size || 8;
41387
+ if (showLabels) {
41388
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
41389
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
41390
+ }
41391
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
41392
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
41393
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
41394
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
41395
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
41396
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
41397
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
41398
+ if (overlapX > 0 && overlapY > 0) {
41399
+ if (overlapX <= overlapY) {
41400
+ const push2 = overlapX / 2 * (b.x >= a.x ? 1 : -1);
41401
+ a.x = Math.max(30, Math.min(w - 30, a.x - push2));
41402
+ b.x = Math.max(30, Math.min(w - 30, b.x + push2));
41403
+ } else {
41404
+ const push2 = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
41405
+ a.y = Math.max(30, Math.min(h - 30, a.y - push2));
41406
+ b.y = Math.max(30, Math.min(h - 30, b.y + push2));
41407
+ }
41386
41408
  }
41387
41409
  }
41388
41410
  }
@@ -41399,7 +41421,7 @@ var init_GraphCanvas = __esm({
41399
41421
  return () => {
41400
41422
  cancelAnimationFrame(animRef.current);
41401
41423
  };
41402
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
41424
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
41403
41425
  useEffect(() => {
41404
41426
  const canvas = canvasRef.current;
41405
41427
  if (!canvas) return;
@@ -39430,6 +39430,13 @@ var init_DocumentViewer = __esm({
39430
39430
  exports.DocumentViewer.displayName = "DocumentViewer";
39431
39431
  }
39432
39432
  });
39433
+ function measureLabelWidth(text) {
39434
+ if (typeof document === "undefined") return text.length * 6;
39435
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
39436
+ if (!labelMeasureCtx) return text.length * 6;
39437
+ labelMeasureCtx.font = "10px system-ui";
39438
+ return labelMeasureCtx.measureText(text).width;
39439
+ }
39433
39440
  function getGroupColor(group, groups) {
39434
39441
  if (!group) return GROUP_COLORS2[0];
39435
39442
  const idx = groups.indexOf(group);
@@ -39441,7 +39448,7 @@ function resolveColor2(color, el) {
39441
39448
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
39442
39449
  return resolved || (m[2]?.trim() ?? "#888888");
39443
39450
  }
39444
- var GROUP_COLORS2; exports.GraphCanvas = void 0;
39451
+ var GROUP_COLORS2, labelMeasureCtx; exports.GraphCanvas = void 0;
39445
39452
  var init_GraphCanvas = __esm({
39446
39453
  "components/core/molecules/GraphCanvas.tsx"() {
39447
39454
  "use client";
@@ -39461,6 +39468,7 @@ var init_GraphCanvas = __esm({
39461
39468
  "var(--color-info)",
39462
39469
  "var(--color-accent)"
39463
39470
  ];
39471
+ labelMeasureCtx = null;
39464
39472
  exports.GraphCanvas = ({
39465
39473
  title,
39466
39474
  nodes: propNodes = [],
@@ -39641,22 +39649,36 @@ var init_GraphCanvas = __esm({
39641
39649
  node.x = Math.max(30, Math.min(w - 30, node.x));
39642
39650
  node.y = Math.max(30, Math.min(h - 30, node.y));
39643
39651
  }
39652
+ const LABEL_GAP = 12;
39653
+ const LABEL_H = 12;
39654
+ const pad = nodeSpacing / 2;
39644
39655
  for (let i = 0; i < nodes.length; i++) {
39645
39656
  for (let j = i + 1; j < nodes.length; j++) {
39646
39657
  const a = nodes[i];
39647
39658
  const b = nodes[j];
39648
- const dx = b.x - a.x;
39649
- const dy = b.y - a.y;
39650
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
39651
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
39652
- if (dist < minDist) {
39653
- const push = (minDist - dist) / 2;
39654
- const ux = dx / dist;
39655
- const uy = dy / dist;
39656
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push));
39657
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push));
39658
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push));
39659
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push));
39659
+ const ar = a.size || 8;
39660
+ const br = b.size || 8;
39661
+ if (showLabels) {
39662
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
39663
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
39664
+ }
39665
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
39666
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
39667
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
39668
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
39669
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
39670
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
39671
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
39672
+ if (overlapX > 0 && overlapY > 0) {
39673
+ if (overlapX <= overlapY) {
39674
+ const push = overlapX / 2 * (b.x >= a.x ? 1 : -1);
39675
+ a.x = Math.max(30, Math.min(w - 30, a.x - push));
39676
+ b.x = Math.max(30, Math.min(w - 30, b.x + push));
39677
+ } else {
39678
+ const push = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
39679
+ a.y = Math.max(30, Math.min(h - 30, a.y - push));
39680
+ b.y = Math.max(30, Math.min(h - 30, b.y + push));
39681
+ }
39660
39682
  }
39661
39683
  }
39662
39684
  }
@@ -39673,7 +39695,7 @@ var init_GraphCanvas = __esm({
39673
39695
  return () => {
39674
39696
  cancelAnimationFrame(animRef.current);
39675
39697
  };
39676
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
39698
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
39677
39699
  React79.useEffect(() => {
39678
39700
  const canvas = canvasRef.current;
39679
39701
  if (!canvas) return;
@@ -39384,6 +39384,13 @@ var init_DocumentViewer = __esm({
39384
39384
  DocumentViewer.displayName = "DocumentViewer";
39385
39385
  }
39386
39386
  });
39387
+ function measureLabelWidth(text) {
39388
+ if (typeof document === "undefined") return text.length * 6;
39389
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
39390
+ if (!labelMeasureCtx) return text.length * 6;
39391
+ labelMeasureCtx.font = "10px system-ui";
39392
+ return labelMeasureCtx.measureText(text).width;
39393
+ }
39387
39394
  function getGroupColor(group, groups) {
39388
39395
  if (!group) return GROUP_COLORS2[0];
39389
39396
  const idx = groups.indexOf(group);
@@ -39395,7 +39402,7 @@ function resolveColor2(color, el) {
39395
39402
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
39396
39403
  return resolved || (m[2]?.trim() ?? "#888888");
39397
39404
  }
39398
- var GROUP_COLORS2, GraphCanvas;
39405
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
39399
39406
  var init_GraphCanvas = __esm({
39400
39407
  "components/core/molecules/GraphCanvas.tsx"() {
39401
39408
  "use client";
@@ -39415,6 +39422,7 @@ var init_GraphCanvas = __esm({
39415
39422
  "var(--color-info)",
39416
39423
  "var(--color-accent)"
39417
39424
  ];
39425
+ labelMeasureCtx = null;
39418
39426
  GraphCanvas = ({
39419
39427
  title,
39420
39428
  nodes: propNodes = [],
@@ -39595,22 +39603,36 @@ var init_GraphCanvas = __esm({
39595
39603
  node.x = Math.max(30, Math.min(w - 30, node.x));
39596
39604
  node.y = Math.max(30, Math.min(h - 30, node.y));
39597
39605
  }
39606
+ const LABEL_GAP = 12;
39607
+ const LABEL_H = 12;
39608
+ const pad = nodeSpacing / 2;
39598
39609
  for (let i = 0; i < nodes.length; i++) {
39599
39610
  for (let j = i + 1; j < nodes.length; j++) {
39600
39611
  const a = nodes[i];
39601
39612
  const b = nodes[j];
39602
- const dx = b.x - a.x;
39603
- const dy = b.y - a.y;
39604
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
39605
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
39606
- if (dist < minDist) {
39607
- const push = (minDist - dist) / 2;
39608
- const ux = dx / dist;
39609
- const uy = dy / dist;
39610
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push));
39611
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push));
39612
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push));
39613
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push));
39613
+ const ar = a.size || 8;
39614
+ const br = b.size || 8;
39615
+ if (showLabels) {
39616
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
39617
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
39618
+ }
39619
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
39620
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
39621
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
39622
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
39623
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
39624
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
39625
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
39626
+ if (overlapX > 0 && overlapY > 0) {
39627
+ if (overlapX <= overlapY) {
39628
+ const push = overlapX / 2 * (b.x >= a.x ? 1 : -1);
39629
+ a.x = Math.max(30, Math.min(w - 30, a.x - push));
39630
+ b.x = Math.max(30, Math.min(w - 30, b.x + push));
39631
+ } else {
39632
+ const push = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
39633
+ a.y = Math.max(30, Math.min(h - 30, a.y - push));
39634
+ b.y = Math.max(30, Math.min(h - 30, b.y + push));
39635
+ }
39614
39636
  }
39615
39637
  }
39616
39638
  }
@@ -39627,7 +39649,7 @@ var init_GraphCanvas = __esm({
39627
39649
  return () => {
39628
39650
  cancelAnimationFrame(animRef.current);
39629
39651
  };
39630
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
39652
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
39631
39653
  useEffect(() => {
39632
39654
  const canvas = canvasRef.current;
39633
39655
  if (!canvas) return;
@@ -39004,6 +39004,13 @@ var init_DocumentViewer = __esm({
39004
39004
  DocumentViewer.displayName = "DocumentViewer";
39005
39005
  }
39006
39006
  });
39007
+ function measureLabelWidth(text) {
39008
+ if (typeof document === "undefined") return text.length * 6;
39009
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
39010
+ if (!labelMeasureCtx) return text.length * 6;
39011
+ labelMeasureCtx.font = "10px system-ui";
39012
+ return labelMeasureCtx.measureText(text).width;
39013
+ }
39007
39014
  function getGroupColor(group, groups) {
39008
39015
  if (!group) return GROUP_COLORS2[0];
39009
39016
  const idx = groups.indexOf(group);
@@ -39015,7 +39022,7 @@ function resolveColor2(color, el) {
39015
39022
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
39016
39023
  return resolved || (m[2]?.trim() ?? "#888888");
39017
39024
  }
39018
- var GROUP_COLORS2, GraphCanvas;
39025
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
39019
39026
  var init_GraphCanvas = __esm({
39020
39027
  "components/core/molecules/GraphCanvas.tsx"() {
39021
39028
  "use client";
@@ -39035,6 +39042,7 @@ var init_GraphCanvas = __esm({
39035
39042
  "var(--color-info)",
39036
39043
  "var(--color-accent)"
39037
39044
  ];
39045
+ labelMeasureCtx = null;
39038
39046
  GraphCanvas = ({
39039
39047
  title,
39040
39048
  nodes: propNodes = [],
@@ -39215,22 +39223,36 @@ var init_GraphCanvas = __esm({
39215
39223
  node.x = Math.max(30, Math.min(w - 30, node.x));
39216
39224
  node.y = Math.max(30, Math.min(h - 30, node.y));
39217
39225
  }
39226
+ const LABEL_GAP = 12;
39227
+ const LABEL_H = 12;
39228
+ const pad = nodeSpacing / 2;
39218
39229
  for (let i = 0; i < nodes.length; i++) {
39219
39230
  for (let j = i + 1; j < nodes.length; j++) {
39220
39231
  const a = nodes[i];
39221
39232
  const b = nodes[j];
39222
- const dx = b.x - a.x;
39223
- const dy = b.y - a.y;
39224
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
39225
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
39226
- if (dist < minDist) {
39227
- const push = (minDist - dist) / 2;
39228
- const ux = dx / dist;
39229
- const uy = dy / dist;
39230
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push));
39231
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push));
39232
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push));
39233
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push));
39233
+ const ar = a.size || 8;
39234
+ const br = b.size || 8;
39235
+ if (showLabels) {
39236
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
39237
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
39238
+ }
39239
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
39240
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
39241
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
39242
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
39243
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
39244
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
39245
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
39246
+ if (overlapX > 0 && overlapY > 0) {
39247
+ if (overlapX <= overlapY) {
39248
+ const push = overlapX / 2 * (b.x >= a.x ? 1 : -1);
39249
+ a.x = Math.max(30, Math.min(w - 30, a.x - push));
39250
+ b.x = Math.max(30, Math.min(w - 30, b.x + push));
39251
+ } else {
39252
+ const push = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
39253
+ a.y = Math.max(30, Math.min(h - 30, a.y - push));
39254
+ b.y = Math.max(30, Math.min(h - 30, b.y + push));
39255
+ }
39234
39256
  }
39235
39257
  }
39236
39258
  }
@@ -39247,7 +39269,7 @@ var init_GraphCanvas = __esm({
39247
39269
  return () => {
39248
39270
  cancelAnimationFrame(animRef.current);
39249
39271
  };
39250
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
39272
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
39251
39273
  React85.useEffect(() => {
39252
39274
  const canvas = canvasRef.current;
39253
39275
  if (!canvas) return;
@@ -38957,6 +38957,13 @@ var init_DocumentViewer = __esm({
38957
38957
  DocumentViewer.displayName = "DocumentViewer";
38958
38958
  }
38959
38959
  });
38960
+ function measureLabelWidth(text) {
38961
+ if (typeof document === "undefined") return text.length * 6;
38962
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
38963
+ if (!labelMeasureCtx) return text.length * 6;
38964
+ labelMeasureCtx.font = "10px system-ui";
38965
+ return labelMeasureCtx.measureText(text).width;
38966
+ }
38960
38967
  function getGroupColor(group, groups) {
38961
38968
  if (!group) return GROUP_COLORS2[0];
38962
38969
  const idx = groups.indexOf(group);
@@ -38968,7 +38975,7 @@ function resolveColor2(color, el) {
38968
38975
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
38969
38976
  return resolved || (m[2]?.trim() ?? "#888888");
38970
38977
  }
38971
- var GROUP_COLORS2, GraphCanvas;
38978
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
38972
38979
  var init_GraphCanvas = __esm({
38973
38980
  "components/core/molecules/GraphCanvas.tsx"() {
38974
38981
  "use client";
@@ -38988,6 +38995,7 @@ var init_GraphCanvas = __esm({
38988
38995
  "var(--color-info)",
38989
38996
  "var(--color-accent)"
38990
38997
  ];
38998
+ labelMeasureCtx = null;
38991
38999
  GraphCanvas = ({
38992
39000
  title,
38993
39001
  nodes: propNodes = [],
@@ -39168,22 +39176,36 @@ var init_GraphCanvas = __esm({
39168
39176
  node.x = Math.max(30, Math.min(w - 30, node.x));
39169
39177
  node.y = Math.max(30, Math.min(h - 30, node.y));
39170
39178
  }
39179
+ const LABEL_GAP = 12;
39180
+ const LABEL_H = 12;
39181
+ const pad = nodeSpacing / 2;
39171
39182
  for (let i = 0; i < nodes.length; i++) {
39172
39183
  for (let j = i + 1; j < nodes.length; j++) {
39173
39184
  const a = nodes[i];
39174
39185
  const b = nodes[j];
39175
- const dx = b.x - a.x;
39176
- const dy = b.y - a.y;
39177
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
39178
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
39179
- if (dist < minDist) {
39180
- const push = (minDist - dist) / 2;
39181
- const ux = dx / dist;
39182
- const uy = dy / dist;
39183
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push));
39184
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push));
39185
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push));
39186
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push));
39186
+ const ar = a.size || 8;
39187
+ const br = b.size || 8;
39188
+ if (showLabels) {
39189
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
39190
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
39191
+ }
39192
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
39193
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
39194
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
39195
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
39196
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
39197
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
39198
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
39199
+ if (overlapX > 0 && overlapY > 0) {
39200
+ if (overlapX <= overlapY) {
39201
+ const push = overlapX / 2 * (b.x >= a.x ? 1 : -1);
39202
+ a.x = Math.max(30, Math.min(w - 30, a.x - push));
39203
+ b.x = Math.max(30, Math.min(w - 30, b.x + push));
39204
+ } else {
39205
+ const push = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
39206
+ a.y = Math.max(30, Math.min(h - 30, a.y - push));
39207
+ b.y = Math.max(30, Math.min(h - 30, b.y + push));
39208
+ }
39187
39209
  }
39188
39210
  }
39189
39211
  }
@@ -39200,7 +39222,7 @@ var init_GraphCanvas = __esm({
39200
39222
  return () => {
39201
39223
  cancelAnimationFrame(animRef.current);
39202
39224
  };
39203
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
39225
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
39204
39226
  useEffect(() => {
39205
39227
  const canvas = canvasRef.current;
39206
39228
  if (!canvas) return;
@@ -38702,6 +38702,13 @@ var init_DocumentViewer = __esm({
38702
38702
  DocumentViewer.displayName = "DocumentViewer";
38703
38703
  }
38704
38704
  });
38705
+ function measureLabelWidth(text) {
38706
+ if (typeof document === "undefined") return text.length * 6;
38707
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
38708
+ if (!labelMeasureCtx) return text.length * 6;
38709
+ labelMeasureCtx.font = "10px system-ui";
38710
+ return labelMeasureCtx.measureText(text).width;
38711
+ }
38705
38712
  function getGroupColor(group, groups) {
38706
38713
  if (!group) return GROUP_COLORS2[0];
38707
38714
  const idx = groups.indexOf(group);
@@ -38713,7 +38720,7 @@ function resolveColor2(color, el) {
38713
38720
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
38714
38721
  return resolved || (m[2]?.trim() ?? "#888888");
38715
38722
  }
38716
- var GROUP_COLORS2, GraphCanvas;
38723
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
38717
38724
  var init_GraphCanvas = __esm({
38718
38725
  "components/core/molecules/GraphCanvas.tsx"() {
38719
38726
  "use client";
@@ -38733,6 +38740,7 @@ var init_GraphCanvas = __esm({
38733
38740
  "var(--color-info)",
38734
38741
  "var(--color-accent)"
38735
38742
  ];
38743
+ labelMeasureCtx = null;
38736
38744
  GraphCanvas = ({
38737
38745
  title,
38738
38746
  nodes: propNodes = [],
@@ -38913,22 +38921,36 @@ var init_GraphCanvas = __esm({
38913
38921
  node.x = Math.max(30, Math.min(w - 30, node.x));
38914
38922
  node.y = Math.max(30, Math.min(h - 30, node.y));
38915
38923
  }
38924
+ const LABEL_GAP = 12;
38925
+ const LABEL_H = 12;
38926
+ const pad = nodeSpacing / 2;
38916
38927
  for (let i = 0; i < nodes.length; i++) {
38917
38928
  for (let j = i + 1; j < nodes.length; j++) {
38918
38929
  const a = nodes[i];
38919
38930
  const b = nodes[j];
38920
- const dx = b.x - a.x;
38921
- const dy = b.y - a.y;
38922
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
38923
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
38924
- if (dist < minDist) {
38925
- const push2 = (minDist - dist) / 2;
38926
- const ux = dx / dist;
38927
- const uy = dy / dist;
38928
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push2));
38929
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push2));
38930
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push2));
38931
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push2));
38931
+ const ar = a.size || 8;
38932
+ const br = b.size || 8;
38933
+ if (showLabels) {
38934
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
38935
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
38936
+ }
38937
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
38938
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
38939
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
38940
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
38941
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
38942
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
38943
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
38944
+ if (overlapX > 0 && overlapY > 0) {
38945
+ if (overlapX <= overlapY) {
38946
+ const push2 = overlapX / 2 * (b.x >= a.x ? 1 : -1);
38947
+ a.x = Math.max(30, Math.min(w - 30, a.x - push2));
38948
+ b.x = Math.max(30, Math.min(w - 30, b.x + push2));
38949
+ } else {
38950
+ const push2 = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
38951
+ a.y = Math.max(30, Math.min(h - 30, a.y - push2));
38952
+ b.y = Math.max(30, Math.min(h - 30, b.y + push2));
38953
+ }
38932
38954
  }
38933
38955
  }
38934
38956
  }
@@ -38945,7 +38967,7 @@ var init_GraphCanvas = __esm({
38945
38967
  return () => {
38946
38968
  cancelAnimationFrame(animRef.current);
38947
38969
  };
38948
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
38970
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
38949
38971
  React84.useEffect(() => {
38950
38972
  const canvas = canvasRef.current;
38951
38973
  if (!canvas) return;
@@ -38655,6 +38655,13 @@ var init_DocumentViewer = __esm({
38655
38655
  DocumentViewer.displayName = "DocumentViewer";
38656
38656
  }
38657
38657
  });
38658
+ function measureLabelWidth(text) {
38659
+ if (typeof document === "undefined") return text.length * 6;
38660
+ if (!labelMeasureCtx) labelMeasureCtx = document.createElement("canvas").getContext("2d");
38661
+ if (!labelMeasureCtx) return text.length * 6;
38662
+ labelMeasureCtx.font = "10px system-ui";
38663
+ return labelMeasureCtx.measureText(text).width;
38664
+ }
38658
38665
  function getGroupColor(group, groups) {
38659
38666
  if (!group) return GROUP_COLORS2[0];
38660
38667
  const idx = groups.indexOf(group);
@@ -38666,7 +38673,7 @@ function resolveColor2(color, el) {
38666
38673
  const resolved = getComputedStyle(el).getPropertyValue(m[1]).trim();
38667
38674
  return resolved || (m[2]?.trim() ?? "#888888");
38668
38675
  }
38669
- var GROUP_COLORS2, GraphCanvas;
38676
+ var GROUP_COLORS2, labelMeasureCtx, GraphCanvas;
38670
38677
  var init_GraphCanvas = __esm({
38671
38678
  "components/core/molecules/GraphCanvas.tsx"() {
38672
38679
  "use client";
@@ -38686,6 +38693,7 @@ var init_GraphCanvas = __esm({
38686
38693
  "var(--color-info)",
38687
38694
  "var(--color-accent)"
38688
38695
  ];
38696
+ labelMeasureCtx = null;
38689
38697
  GraphCanvas = ({
38690
38698
  title,
38691
38699
  nodes: propNodes = [],
@@ -38866,22 +38874,36 @@ var init_GraphCanvas = __esm({
38866
38874
  node.x = Math.max(30, Math.min(w - 30, node.x));
38867
38875
  node.y = Math.max(30, Math.min(h - 30, node.y));
38868
38876
  }
38877
+ const LABEL_GAP = 12;
38878
+ const LABEL_H = 12;
38879
+ const pad = nodeSpacing / 2;
38869
38880
  for (let i = 0; i < nodes.length; i++) {
38870
38881
  for (let j = i + 1; j < nodes.length; j++) {
38871
38882
  const a = nodes[i];
38872
38883
  const b = nodes[j];
38873
- const dx = b.x - a.x;
38874
- const dy = b.y - a.y;
38875
- const dist = Math.sqrt(dx * dx + dy * dy) || 1;
38876
- const minDist = (a.size || 8) + (b.size || 8) + nodeSpacing;
38877
- if (dist < minDist) {
38878
- const push2 = (minDist - dist) / 2;
38879
- const ux = dx / dist;
38880
- const uy = dy / dist;
38881
- a.x = Math.max(30, Math.min(w - 30, a.x - ux * push2));
38882
- a.y = Math.max(30, Math.min(h - 30, a.y - uy * push2));
38883
- b.x = Math.max(30, Math.min(w - 30, b.x + ux * push2));
38884
- b.y = Math.max(30, Math.min(h - 30, b.y + uy * push2));
38884
+ const ar = a.size || 8;
38885
+ const br = b.size || 8;
38886
+ if (showLabels) {
38887
+ if (a.labelW === void 0) a.labelW = a.label ? measureLabelWidth(a.label) : 0;
38888
+ if (b.labelW === void 0) b.labelW = b.label ? measureLabelWidth(b.label) : 0;
38889
+ }
38890
+ const labelBelow = showLabels ? LABEL_GAP + LABEL_H : 0;
38891
+ const aHalfW = Math.max(ar, (a.labelW ?? 0) / 2) + pad;
38892
+ const bHalfW = Math.max(br, (b.labelW ?? 0) / 2) + pad;
38893
+ const aTop = a.y - ar - pad, aBot = a.y + ar + labelBelow + pad;
38894
+ const bTop = b.y - br - pad, bBot = b.y + br + labelBelow + pad;
38895
+ const overlapX = Math.min(a.x + aHalfW, b.x + bHalfW) - Math.max(a.x - aHalfW, b.x - bHalfW);
38896
+ const overlapY = Math.min(aBot, bBot) - Math.max(aTop, bTop);
38897
+ if (overlapX > 0 && overlapY > 0) {
38898
+ if (overlapX <= overlapY) {
38899
+ const push2 = overlapX / 2 * (b.x >= a.x ? 1 : -1);
38900
+ a.x = Math.max(30, Math.min(w - 30, a.x - push2));
38901
+ b.x = Math.max(30, Math.min(w - 30, b.x + push2));
38902
+ } else {
38903
+ const push2 = overlapY / 2 * (bTop + bBot >= aTop + aBot ? 1 : -1);
38904
+ a.y = Math.max(30, Math.min(h - 30, a.y - push2));
38905
+ b.y = Math.max(30, Math.min(h - 30, b.y + push2));
38906
+ }
38885
38907
  }
38886
38908
  }
38887
38909
  }
@@ -38898,7 +38920,7 @@ var init_GraphCanvas = __esm({
38898
38920
  return () => {
38899
38921
  cancelAnimationFrame(animRef.current);
38900
38922
  };
38901
- }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, logicalW, height]);
38923
+ }, [propNodes, propEdges, layout, repulsion, linkDistance, nodeSpacing, showLabels, logicalW, height]);
38902
38924
  useEffect(() => {
38903
38925
  const canvas = canvasRef.current;
38904
38926
  if (!canvas) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "5.63.1",
3
+ "version": "5.63.2",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "sideEffects": [