vizmatic 0.2.0 → 0.3.1

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.js CHANGED
@@ -223,7 +223,7 @@ function getReadableToneColor(tone, c, background = c.bgCard, backdrop = c.bgCar
223
223
  return colorContrast(color, background, backdrop) >= 4.5 ? color : getReadableTextColor(background, c, backdrop);
224
224
  }
225
225
  function getToneFill(tone, c) {
226
- if (c.preset !== "engineering") return `${getToneColor(tone, c)}16`;
226
+ if (c.preset !== "engineering") return withColorAlpha(getToneColor(tone, c), 22 / 255);
227
227
  return {
228
228
  blue: "#cddcfa",
229
229
  purple: "#dfcff8",
@@ -360,6 +360,17 @@ function parseColor(color) {
360
360
  alpha: parsed.alpha
361
361
  };
362
362
  }
363
+ function withColorAlpha(color, opacity) {
364
+ if (typeof color !== "string" || !Number.isFinite(opacity)) return "transparent";
365
+ const parsed = parseColor(color);
366
+ if (!parsed) return "transparent";
367
+ const alpha = Math.min(1, Math.max(0, parsed.alpha * Math.min(1, Math.max(0, opacity))));
368
+ const hex = color.trim();
369
+ if (/^#[\da-f]{6}$/i.test(hex)) {
370
+ return `${hex}${Math.round(alpha * 255).toString(16).padStart(2, "0")}`;
371
+ }
372
+ return `rgba(${parsed.channels.join(", ")}, ${Number(alpha.toFixed(6))})`;
373
+ }
363
374
  function colorLuminance(color, backdrop) {
364
375
  const parsed = parseColor(color);
365
376
  if (!parsed) return void 0;
@@ -439,9 +450,12 @@ __export(primitives_exports, {
439
450
  Badge: () => Badge,
440
451
  BadgePill: () => BadgePill,
441
452
  BarChart: () => BarChart,
453
+ Board: () => Board,
442
454
  Box: () => Box,
455
+ CANVAS_ITEM_COMPONENT: () => CANVAS_ITEM_COMPONENT,
443
456
  CalloutCard: () => CalloutCard,
444
457
  Canvas: () => Canvas,
458
+ CanvasItem: () => CanvasItem,
445
459
  Card: () => Card,
446
460
  ChartFrame: () => ChartFrame,
447
461
  CodeBlock: () => CodeBlock,
@@ -473,7 +487,9 @@ __export(primitives_exports, {
473
487
  MetricCard: () => MetricCard,
474
488
  MiniBarChart: () => MiniBarChart,
475
489
  Panel: () => Panel,
490
+ ParetoBarChart: () => ParetoBarChart,
476
491
  ParetoChart: () => ParetoChart,
492
+ PieChart: () => PieChart,
477
493
  Pipeline: () => Pipeline,
478
494
  ProgressList: () => ProgressList,
479
495
  ProgressRow: () => ProgressRow,
@@ -1269,10 +1285,10 @@ function Box({
1269
1285
  style.backgroundColor = "transparent";
1270
1286
  } else if (gradient) {
1271
1287
  style.backgroundImage = gradientBg;
1272
- style.boxShadow = `0 4px 20px ${solidColor}30`;
1288
+ style.boxShadow = `0 4px 20px ${withColorAlpha(solidColor, 48 / 255)}`;
1273
1289
  } else {
1274
1290
  style.backgroundColor = solidColor;
1275
- style.boxShadow = `0 4px 20px ${solidColor}30`;
1291
+ style.boxShadow = `0 4px 20px ${withColorAlpha(solidColor, 48 / 255)}`;
1276
1292
  }
1277
1293
  return React2.createElement(
1278
1294
  "div",
@@ -1294,7 +1310,7 @@ function Box({
1294
1310
  style: {
1295
1311
  fontSize: fontSize - 2,
1296
1312
  fontWeight: 400,
1297
- color: outlined ? c.textMuted : gradient ? `${c.textOnColor}b3` : solidTextColor,
1313
+ color: outlined ? c.textMuted : gradient ? withColorAlpha(c.textOnColor, 179 / 255) : solidTextColor,
1298
1314
  fontFamily: c.fontMono,
1299
1315
  textAlign: "center"
1300
1316
  }
@@ -1824,8 +1840,8 @@ function BadgePill({
1824
1840
  ...height != null ? { height } : {},
1825
1841
  padding,
1826
1842
  borderRadius: engineering ? Math.min(radius, 5) : radius,
1827
- ...engineering ? { backgroundColor: getToneFill(tone, c) } : filled ? { backgroundImage: getToneGradient(tone) } : { backgroundColor: `${accent}18` },
1828
- border: `1px solid ${engineering ? accent : filled ? `${accent}00` : `${accent}55`}`,
1843
+ ...engineering ? { backgroundColor: getToneFill(tone, c) } : filled ? { backgroundImage: getToneGradient(tone) } : { backgroundColor: withColorAlpha(accent, 24 / 255) },
1844
+ border: `1px solid ${engineering ? accent : filled ? withColorAlpha(accent, 0) : withColorAlpha(accent, 85 / 255)}`,
1829
1845
  color: engineering ? c.textPrimary : filled ? c.textOnColor : accentText,
1830
1846
  fontSize,
1831
1847
  fontWeight: 800,
@@ -1927,7 +1943,7 @@ function StepCard({
1927
1943
  radius: engineering ? 5 : radius,
1928
1944
  shadow: engineering ? false : shadow,
1929
1945
  background: engineering ? getToneFill(tone, c) : void 0,
1930
- borderColor: engineering ? accent : `${accent}88`,
1946
+ borderColor: engineering ? accent : withColorAlpha(accent, 136 / 255),
1931
1947
  children: React3.createElement(
1932
1948
  "div",
1933
1949
  {
@@ -2003,7 +2019,7 @@ function MetricCard({
2003
2019
  padding,
2004
2020
  radius,
2005
2021
  shadow,
2006
- borderColor: `${accent}66`,
2022
+ borderColor: withColorAlpha(accent, 102 / 255),
2007
2023
  children: React3.createElement(
2008
2024
  "div",
2009
2025
  {
@@ -2253,7 +2269,7 @@ function DetailList({
2253
2269
  padding,
2254
2270
  borderRadius: 8,
2255
2271
  backgroundColor: c.bgSubtle,
2256
- border: `1px solid ${tone ? `${accent}44` : c.borderSubtle}`,
2272
+ border: `1px solid ${tone ? withColorAlpha(accent, 68 / 255) : c.borderSubtle}`,
2257
2273
  color: c.textSecondary,
2258
2274
  fontSize,
2259
2275
  lineHeight: 1.3,
@@ -2317,7 +2333,7 @@ function Tile({
2317
2333
  padding,
2318
2334
  radius,
2319
2335
  shadow,
2320
- borderColor: `${accent}88`,
2336
+ borderColor: withColorAlpha(accent, 136 / 255),
2321
2337
  children: React4.createElement(
2322
2338
  "div",
2323
2339
  {
@@ -2451,7 +2467,7 @@ function CodeBlock({
2451
2467
  width: "100%",
2452
2468
  padding: accent ? "3px 7px" : "1px 0",
2453
2469
  borderRadius: accent ? 5 : 0,
2454
- ...accent ? { backgroundColor: `${accent}1f` } : {},
2470
+ ...accent ? { backgroundColor: withColorAlpha(accent, 31 / 255) } : {},
2455
2471
  boxSizing: "border-box"
2456
2472
  }
2457
2473
  },
@@ -2507,7 +2523,7 @@ function CodeBlock({
2507
2523
  padding,
2508
2524
  borderRadius: radius,
2509
2525
  backgroundColor: background ?? c.bgSubtle,
2510
- border: `1px solid ${tone ? `${headerAccent}44` : c.borderSubtle}`,
2526
+ border: `1px solid ${tone ? withColorAlpha(headerAccent, 68 / 255) : c.borderSubtle}`,
2511
2527
  boxSizing: "border-box",
2512
2528
  ...shadow ? { boxShadow: `0 9px 24px ${c.shadow}` } : {}
2513
2529
  }
@@ -2590,7 +2606,7 @@ function renderComparisonDivider(divider, c, key) {
2590
2606
  );
2591
2607
  }
2592
2608
  function Comparison({
2593
- sides,
2609
+ sides: sides2,
2594
2610
  c,
2595
2611
  divider = false,
2596
2612
  gap = 14,
@@ -2599,7 +2615,7 @@ function Comparison({
2599
2615
  align = "stretch",
2600
2616
  math = false
2601
2617
  }) {
2602
- const children = sides.flatMap((side, index) => {
2618
+ const children = sides2.flatMap((side, index) => {
2603
2619
  const tone = side.tone ?? "blue";
2604
2620
  const panel = React4.createElement(
2605
2621
  React4.Fragment,
@@ -2629,7 +2645,7 @@ function Comparison({
2629
2645
  ) : side.children ?? DetailList({ items: side.lines ?? [], c, tone, math })
2630
2646
  })
2631
2647
  );
2632
- if (divider && index < sides.length - 1) {
2648
+ if (divider && index < sides2.length - 1) {
2633
2649
  return [panel, renderComparisonDivider(divider, c, `comparison-divider-${index}`)];
2634
2650
  }
2635
2651
  return [panel];
@@ -2869,7 +2885,7 @@ function StatusRow({
2869
2885
  const markerAlpha = 38 / 255;
2870
2886
  const rowAlpha = boxed ? 18 / 255 : 0;
2871
2887
  const markerBackgroundAlpha = Math.round((rowAlpha + markerAlpha * (1 - rowAlpha)) * 255);
2872
- const markerBackground = `${accent}${markerBackgroundAlpha.toString(16).padStart(2, "0")}`;
2888
+ const markerBackground = withColorAlpha(accent, markerBackgroundAlpha / 255);
2873
2889
  const accentText = getReadableToneColor(resolvedTone, c, markerBackground, c.bgCard);
2874
2890
  const glyph = statusGlyphs[status];
2875
2891
  const marker = React5.createElement("div", {
@@ -2881,7 +2897,7 @@ function StatusRow({
2881
2897
  height: 18,
2882
2898
  flexShrink: 0,
2883
2899
  borderRadius: 999,
2884
- backgroundColor: status === "dot" ? accent : `${accent}26`,
2900
+ backgroundColor: status === "dot" ? accent : withColorAlpha(accent, 38 / 255),
2885
2901
  border: `1px solid ${accent}`,
2886
2902
  color: accentText,
2887
2903
  fontFamily: "Inter",
@@ -2902,8 +2918,8 @@ function StatusRow({
2902
2918
  ...boxed ? {
2903
2919
  padding: "7px 10px",
2904
2920
  borderRadius: 8,
2905
- backgroundColor: `${accent}12`,
2906
- border: `1px solid ${accent}3a`
2921
+ backgroundColor: withColorAlpha(accent, 18 / 255),
2922
+ border: `1px solid ${withColorAlpha(accent, 58 / 255)}`
2907
2923
  } : { padding: "3px 0" }
2908
2924
  }
2909
2925
  },
@@ -2968,7 +2984,7 @@ function renderTimelineCard(event, c, math, width) {
2968
2984
  ...typeof resolvedWidth === "string" ? { minWidth: 0 } : {},
2969
2985
  padding: "10px 12px",
2970
2986
  borderRadius: 8,
2971
- border: `1px solid ${accent}44`,
2987
+ border: `1px solid ${withColorAlpha(accent, 68 / 255)}`,
2972
2988
  backgroundColor: c.bgCard,
2973
2989
  boxShadow: `0 7px 18px ${c.shadow}`,
2974
2990
  boxSizing: "border-box"
@@ -3485,6 +3501,284 @@ function addSvgAccessibility(svg, graphs, layoutNodes) {
3485
3501
  ).replace(/<\/svg>\s*$/, `${groupMarkup}</svg>`);
3486
3502
  }
3487
3503
 
3504
+ // src/graph-routing.ts
3505
+ var EPSILON = 1e-3;
3506
+ var MAX_GRID_POINTS = 18e3;
3507
+ var MAX_SEARCH_STATES = 54e3;
3508
+ var MAX_TOTAL_SEARCH_STATES = 16e4;
3509
+ var MAX_ROUTED_EDGES = 256;
3510
+ var MAX_OBSTACLES = 64;
3511
+ var sides = ["right", "bottom", "left", "top"];
3512
+ function box(node, clearance = 0) {
3513
+ return {
3514
+ left: node.cx - node.width / 2 - clearance,
3515
+ right: node.cx + node.width / 2 + clearance,
3516
+ top: node.cy - node.height / 2 - clearance,
3517
+ bottom: node.cy + node.height / 2 + clearance
3518
+ };
3519
+ }
3520
+ function inside(point, obstacle) {
3521
+ return point.x > obstacle.left + EPSILON && point.x < obstacle.right - EPSILON && point.y > obstacle.top + EPSILON && point.y < obstacle.bottom - EPSILON;
3522
+ }
3523
+ function routingSegmentBlocked(a, b, obstacle) {
3524
+ if (Math.abs(a.y - b.y) < EPSILON) {
3525
+ return a.y > obstacle.top + EPSILON && a.y < obstacle.bottom - EPSILON && Math.max(a.x, b.x) > obstacle.left + EPSILON && Math.min(a.x, b.x) < obstacle.right - EPSILON;
3526
+ }
3527
+ if (Math.abs(a.x - b.x) < EPSILON) {
3528
+ return a.x > obstacle.left + EPSILON && a.x < obstacle.right - EPSILON && Math.max(a.y, b.y) > obstacle.top + EPSILON && Math.min(a.y, b.y) < obstacle.bottom - EPSILON;
3529
+ }
3530
+ return true;
3531
+ }
3532
+ function preferredSide(from, to) {
3533
+ if (Math.abs(to.cx - from.cx) >= Math.abs(to.cy - from.cy)) return to.cx >= from.cx ? "right" : "left";
3534
+ return to.cy >= from.cy ? "bottom" : "top";
3535
+ }
3536
+ function routingAnchor(node, side, offset = 0.5) {
3537
+ const bounds = box(node);
3538
+ if (side === "left" || side === "right") return { x: bounds[side], y: bounds.top + node.height * offset };
3539
+ return { x: bounds.left + node.width * offset, y: bounds[side] };
3540
+ }
3541
+ function outward(point, side, distance) {
3542
+ return {
3543
+ x: point.x + (side === "right" ? distance : side === "left" ? -distance : 0),
3544
+ y: point.y + (side === "bottom" ? distance : side === "top" ? -distance : 0)
3545
+ };
3546
+ }
3547
+ function simplify(points) {
3548
+ const result = [];
3549
+ for (const point of points) {
3550
+ const last = result[result.length - 1];
3551
+ if (last && Math.abs(last.x - point.x) < EPSILON && Math.abs(last.y - point.y) < EPSILON) continue;
3552
+ const previous = result[result.length - 2];
3553
+ if (previous && last && (previous.x === last.x && last.x === point.x || previous.y === last.y && last.y === point.y)) {
3554
+ result[result.length - 1] = point;
3555
+ } else result.push(point);
3556
+ }
3557
+ return result;
3558
+ }
3559
+ function overlappingLength(a, b, c, d) {
3560
+ if (a.y === b.y && c.y === d.y && Math.abs(a.y - c.y) < EPSILON) {
3561
+ return Math.max(0, Math.min(Math.max(a.x, b.x), Math.max(c.x, d.x)) - Math.max(Math.min(a.x, b.x), Math.min(c.x, d.x)));
3562
+ }
3563
+ if (a.x === b.x && c.x === d.x && Math.abs(a.x - c.x) < EPSILON) {
3564
+ return Math.max(0, Math.min(Math.max(a.y, b.y), Math.max(c.y, d.y)) - Math.max(Math.min(a.y, b.y), Math.min(c.y, d.y)));
3565
+ }
3566
+ return 0;
3567
+ }
3568
+ var MinQueue = class {
3569
+ items = [];
3570
+ get length() {
3571
+ return this.items.length;
3572
+ }
3573
+ push(value) {
3574
+ const items = this.items;
3575
+ items.push(value);
3576
+ let index = items.length - 1;
3577
+ while (index > 0) {
3578
+ const parent = index - 1 >> 1;
3579
+ if (items[parent].priority <= value.priority) break;
3580
+ items[index] = items[parent];
3581
+ index = parent;
3582
+ }
3583
+ items[index] = value;
3584
+ }
3585
+ pop() {
3586
+ const items = this.items;
3587
+ const first = items[0];
3588
+ const last = items.pop();
3589
+ if (items.length === 0) return first;
3590
+ let index = 0;
3591
+ while (index * 2 + 1 < items.length) {
3592
+ const left = index * 2 + 1;
3593
+ const right = left + 1;
3594
+ const child = right < items.length && items[right].priority < items[left].priority ? right : left;
3595
+ if (items[child].priority >= last.priority) break;
3596
+ items[index] = items[child];
3597
+ index = child;
3598
+ }
3599
+ items[index] = last;
3600
+ return first;
3601
+ }
3602
+ };
3603
+ function findPath(start, end, obstacles, width, height, previousRoutes, gap, budget) {
3604
+ const within = (point) => point.x >= 0 && point.x <= width && point.y >= 0 && point.y <= height;
3605
+ if (!within(start) || !within(end) || obstacles.some((obstacle) => inside(start, obstacle) || inside(end, obstacle))) {
3606
+ return { reason: "an endpoint has no clear exit inside the canvas" };
3607
+ }
3608
+ const xs = /* @__PURE__ */ new Set([0, width, start.x, end.x]);
3609
+ const ys = /* @__PURE__ */ new Set([0, height, start.y, end.y]);
3610
+ for (const obstacle of obstacles) {
3611
+ if (obstacle.left >= 0 && obstacle.left <= width) xs.add(obstacle.left);
3612
+ if (obstacle.right >= 0 && obstacle.right <= width) xs.add(obstacle.right);
3613
+ if (obstacle.top >= 0 && obstacle.top <= height) ys.add(obstacle.top);
3614
+ if (obstacle.bottom >= 0 && obstacle.bottom <= height) ys.add(obstacle.bottom);
3615
+ }
3616
+ for (const route of previousRoutes.slice(-8)) for (const point of route) {
3617
+ for (const offset of [-gap, gap]) {
3618
+ if (point.x + offset >= 0 && point.x + offset <= width) xs.add(point.x + offset);
3619
+ if (point.y + offset >= 0 && point.y + offset <= height) ys.add(point.y + offset);
3620
+ }
3621
+ }
3622
+ const xValues = [...xs].sort((a, b) => a - b);
3623
+ const yValues = [...ys].sort((a, b) => a - b);
3624
+ const columns = xValues.length;
3625
+ const gridSize = columns * yValues.length;
3626
+ if (gridSize > MAX_GRID_POINTS) return { reason: `routing grid exceeds ${MAX_GRID_POINTS} points; simplify the graph` };
3627
+ const startIndex = yValues.indexOf(start.y) * columns + xValues.indexOf(start.x);
3628
+ const endIndex = yValues.indexOf(end.y) * columns + xValues.indexOf(end.x);
3629
+ const pointAt = (index) => ({ x: xValues[index % columns], y: yValues[Math.floor(index / columns)] });
3630
+ const costs = new Float64Array(gridSize * 3).fill(Infinity);
3631
+ const parents = new Int32Array(gridSize * 3).fill(-1);
3632
+ const queue = new MinQueue();
3633
+ costs[startIndex * 3] = 0;
3634
+ queue.push({ state: startIndex * 3, cost: 0, priority: 0 });
3635
+ let visits = 0;
3636
+ while (queue.length > 0) {
3637
+ if (--budget.remaining < 0) return { reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` };
3638
+ if (++visits > MAX_SEARCH_STATES) return { reason: `routing search exceeds ${MAX_SEARCH_STATES} states; simplify the graph` };
3639
+ const current = queue.pop();
3640
+ if (current.cost !== costs[current.state]) continue;
3641
+ const index = Math.floor(current.state / 3);
3642
+ const axis = current.state % 3;
3643
+ if (index === endIndex) {
3644
+ const points = [];
3645
+ for (let state = current.state; state >= 0; state = parents[state]) points.push(pointAt(Math.floor(state / 3)));
3646
+ return { points: simplify(points.reverse()) };
3647
+ }
3648
+ const a = pointAt(index);
3649
+ const column = index % columns;
3650
+ const row = Math.floor(index / columns);
3651
+ const neighbors = [
3652
+ column > 0 ? index - 1 : -1,
3653
+ column < columns - 1 ? index + 1 : -1,
3654
+ row > 0 ? index - columns : -1,
3655
+ row < yValues.length - 1 ? index + columns : -1
3656
+ ];
3657
+ for (const neighbor of neighbors) {
3658
+ if (neighbor < 0) continue;
3659
+ const b = pointAt(neighbor);
3660
+ if (obstacles.some((obstacle) => routingSegmentBlocked(a, b, obstacle))) continue;
3661
+ const nextAxis = a.y === b.y ? 1 : 2;
3662
+ const state = neighbor * 3 + nextAxis;
3663
+ let overlap = 0;
3664
+ for (const route of previousRoutes) for (let i = 1; i < route.length; i++) overlap += overlappingLength(a, b, route[i - 1], route[i]);
3665
+ const cost = current.cost + Math.abs(b.x - a.x) + Math.abs(b.y - a.y) + (axis !== 0 && axis !== nextAxis ? 18 : 0) + overlap * 5;
3666
+ if (cost >= costs[state]) continue;
3667
+ costs[state] = cost;
3668
+ parents[state] = current.state;
3669
+ queue.push({ state, cost, priority: cost + Math.abs(end.x - b.x) + Math.abs(end.y - b.y) });
3670
+ }
3671
+ }
3672
+ return { reason: "no obstacle-free route exists inside the canvas" };
3673
+ }
3674
+ function endpoint(node, other, portId, requestedSide, selfLoop, target, ordinal, count, gap) {
3675
+ const port = node.ports?.find((candidate) => candidate.id === portId);
3676
+ const side = port?.side ?? requestedSide ?? (selfLoop ? target ? "top" : "right" : preferredSide(node, other));
3677
+ const length = side === "left" || side === "right" ? node.height : node.width;
3678
+ const separation = count > 1 ? Math.min(gap, length * 0.7 / (count - 1)) : 0;
3679
+ const offset = port ? port.offset ?? 0.5 : 0.5 + (ordinal - (count - 1) / 2) * separation / length;
3680
+ return { side, anchor: routingAnchor(node, side, offset), explicit: portId != null || requestedSide != null };
3681
+ }
3682
+ function straightGraphRoute(from, to, edge) {
3683
+ return [
3684
+ endpoint(from, to, edge.fromPort, edge.fromSide, false, false, 0, 1, 0).anchor,
3685
+ endpoint(to, from, edge.toPort, edge.toSide, false, true, 0, 1, 0).anchor
3686
+ ];
3687
+ }
3688
+ function routeOrthogonalGraph(nodes, edges, width, height, clearance = 12, gap = 14, extraObstacles = []) {
3689
+ const routes = /* @__PURE__ */ new Map();
3690
+ const failures = [];
3691
+ const byId = new Map(nodes.map((node) => [node.id, node]));
3692
+ const obstacles = [...nodes.map((node) => box(node, clearance)), ...extraObstacles.map((obstacle) => ({
3693
+ left: obstacle.left - clearance,
3694
+ right: obstacle.right + clearance,
3695
+ top: obstacle.top - clearance,
3696
+ bottom: obstacle.bottom + clearance
3697
+ }))];
3698
+ const routeKey = (edge) => [edge.from, edge.to].sort().join("\0");
3699
+ const counts2 = /* @__PURE__ */ new Map();
3700
+ for (const edge of edges) counts2.set(routeKey(edge), (counts2.get(routeKey(edge)) ?? 0) + 1);
3701
+ const occurrences = /* @__PURE__ */ new Map();
3702
+ const previous = /* @__PURE__ */ new Map();
3703
+ const budget = { remaining: MAX_TOTAL_SEARCH_STATES };
3704
+ edges.forEach((edge, index) => {
3705
+ if (index >= MAX_ROUTED_EDGES) {
3706
+ failures.push({ index, reason: `orthogonal routing supports at most ${MAX_ROUTED_EDGES} edges per diagram` });
3707
+ return;
3708
+ }
3709
+ if (obstacles.length > MAX_OBSTACLES) {
3710
+ failures.push({ index, reason: `orthogonal routing supports at most ${MAX_OBSTACLES} node and header obstacles per diagram` });
3711
+ return;
3712
+ }
3713
+ if (budget.remaining < 0) {
3714
+ failures.push({ index, reason: `diagram routing budget exceeds ${MAX_TOTAL_SEARCH_STATES} search states; simplify the graph` });
3715
+ return;
3716
+ }
3717
+ const from = byId.get(edge.from);
3718
+ const to = byId.get(edge.to);
3719
+ const key = routeKey(edge);
3720
+ const ordinal = occurrences.get(key) ?? 0;
3721
+ occurrences.set(key, ordinal + 1);
3722
+ const count = counts2.get(key) ?? 1;
3723
+ const source = endpoint(from, to, edge.fromPort, edge.fromSide, from === to, false, ordinal, count, gap);
3724
+ const target = endpoint(to, from, edge.toPort, edge.toSide, from === to, true, ordinal, count, gap);
3725
+ const sourceSides = source.explicit ? [source.side] : [source.side, ...sides.filter((side) => side !== source.side)];
3726
+ const targetSides = target.explicit ? [target.side] : [target.side, ...sides.filter((side) => side !== target.side)];
3727
+ let failure = "no obstacle-free route exists inside the canvas";
3728
+ for (const sourceSide of sourceSides) {
3729
+ for (const targetSide of targetSides) {
3730
+ const start = sourceSide === source.side ? source.anchor : routingAnchor(from, sourceSide);
3731
+ const end = targetSide === target.side ? target.anchor : routingAnchor(to, targetSide);
3732
+ if (from === to && start.x === end.x && start.y === end.y) {
3733
+ failure = "a self-loop requires distinct endpoint anchors";
3734
+ continue;
3735
+ }
3736
+ const leadStart = outward(start, sourceSide, clearance);
3737
+ const leadEnd = outward(end, targetSide, clearance);
3738
+ if (obstacles.some((obstacle, obstacleIndex) => obstacleIndex !== nodes.indexOf(from) && routingSegmentBlocked(start, leadStart, obstacle) || obstacleIndex !== nodes.indexOf(to) && routingSegmentBlocked(leadEnd, end, obstacle))) {
3739
+ failure = "another obstacle blocks an endpoint exit";
3740
+ continue;
3741
+ }
3742
+ const result = findPath(leadStart, leadEnd, obstacles, width, height, previous.get(key) ?? [], Math.max(1, gap), budget);
3743
+ if (!result.points) {
3744
+ failure = result.reason;
3745
+ if (/routing (grid|search|budget)/.test(failure)) {
3746
+ failures.push({ index, reason: failure });
3747
+ return;
3748
+ }
3749
+ continue;
3750
+ }
3751
+ const points = simplify([start, ...result.points, end]);
3752
+ if (points.length < 2) continue;
3753
+ const repeated = (previous.get(key) ?? []).some((route) => route.length === points.length && (route.every((point, position) => point.x === points[position].x && point.y === points[position].y) || route.every((point, position) => point.x === points[points.length - 1 - position].x && point.y === points[points.length - 1 - position].y)));
3754
+ if (repeated) {
3755
+ failure = "parallel connectors have no separate lane at the requested clearance";
3756
+ continue;
3757
+ }
3758
+ routes.set(index, points);
3759
+ previous.set(key, [...previous.get(key) ?? [], points]);
3760
+ return;
3761
+ }
3762
+ }
3763
+ failures.push({ index, reason: failure });
3764
+ });
3765
+ return { routes, failures };
3766
+ }
3767
+ function routingLabelPosition(points) {
3768
+ let longest = 0;
3769
+ let position = points[0];
3770
+ for (let i = 1; i < points.length; i++) {
3771
+ const a = points[i - 1];
3772
+ const b = points[i];
3773
+ const length = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
3774
+ if (length > longest) {
3775
+ longest = length;
3776
+ position = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
3777
+ }
3778
+ }
3779
+ return position;
3780
+ }
3781
+
3488
3782
  // src/primitives/diagrams.ts
3489
3783
  function distributeValues(count, start, end) {
3490
3784
  if (count <= 0) return [];
@@ -3568,10 +3862,10 @@ function LayeredNetwork({
3568
3862
  width: nodeSize + 28,
3569
3863
  height: nodeSize + 28,
3570
3864
  borderRadius: 999,
3571
- backgroundColor: `${c.warningLight}2e`,
3865
+ backgroundColor: withColorAlpha(c.warningLight, 46 / 255),
3572
3866
  border: `4px solid ${c.warningLight}`,
3573
3867
  boxSizing: "border-box",
3574
- boxShadow: `0 0 18px ${c.warningLight}66`
3868
+ boxShadow: `0 0 18px ${withColorAlpha(c.warningLight, 102 / 255)}`
3575
3869
  }
3576
3870
  }),
3577
3871
  React6.createElement("div", {
@@ -3590,7 +3884,7 @@ function LayeredNetwork({
3590
3884
  color: getReadableTextColor(color, c),
3591
3885
  border: active ? `3px solid ${c.warningLight}` : `1.5px solid ${color}`,
3592
3886
  boxSizing: "border-box",
3593
- boxShadow: active ? `0 0 16px ${c.warningLight}70` : `0 8px 14px ${c.shadow}`,
3887
+ boxShadow: active ? `0 0 16px ${withColorAlpha(c.warningLight, 112 / 255)}` : `0 8px 14px ${c.shadow}`,
3594
3888
  fontFamily: "JetBrains Mono",
3595
3889
  fontSize: 16,
3596
3890
  fontWeight: 900,
@@ -3821,6 +4115,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
3821
4115
  for (const node of nodes) {
3822
4116
  if (nodeIds.has(node.id)) throw new Error(`GraphDiagram received duplicate node id "${node.id}".`);
3823
4117
  nodeIds.add(node.id);
4118
+ const portIds = /* @__PURE__ */ new Set();
4119
+ for (const port of node.ports ?? []) {
4120
+ if (typeof port.id !== "string" || port.id.trim().length === 0) {
4121
+ throw new Error(`GraphDiagram node "${node.id}" port id must be a non-empty string.`);
4122
+ }
4123
+ if (portIds.has(port.id)) throw new Error(`GraphDiagram node "${node.id}" received duplicate port "${port.id}".`);
4124
+ portIds.add(port.id);
4125
+ if (!["top", "right", "bottom", "left"].includes(port.side)) {
4126
+ throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" must use side "top", "right", "bottom", or "left".`);
4127
+ }
4128
+ if (port.offset != null && (!Number.isFinite(port.offset) || port.offset < 0 || port.offset > 1)) {
4129
+ throw new Error(`GraphDiagram node "${node.id}" port "${port.id}" offset must be between 0 and 1.`);
4130
+ }
4131
+ }
3824
4132
  }
3825
4133
  const groupsById = /* @__PURE__ */ new Map();
3826
4134
  for (const group of groups) {
@@ -3864,6 +4172,20 @@ function validateGraphDiagramSpec(nodes, edges, groups, layoutMode) {
3864
4172
  if (edgeIds.has(edge.id)) throw new Error(`GraphDiagram received duplicate edge id "${edge.id}".`);
3865
4173
  edgeIds.add(edge.id);
3866
4174
  }
4175
+ for (const side of ["from", "to"]) {
4176
+ const reference = side === "from" ? edge.fromPort : edge.toPort;
4177
+ const endpointSide = side === "from" ? edge.fromSide : edge.toSide;
4178
+ const node = nodes.find((candidate) => candidate.id === edge[side]);
4179
+ if (reference != null && !node.ports?.some((port) => port.id === reference)) {
4180
+ throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" references missing ${side} port "${reference}" on node "${node.id}".`);
4181
+ }
4182
+ if (endpointSide != null && !["top", "right", "bottom", "left"].includes(endpointSide)) {
4183
+ throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" ${side}Side must be "top", "right", "bottom", or "left".`);
4184
+ }
4185
+ if (reference != null && endpointSide != null) {
4186
+ throw new Error(`GraphDiagram edge "${edge.from}" -> "${edge.to}" cannot combine ${side}Port and ${side}Side.`);
4187
+ }
4188
+ }
3867
4189
  validateDiagramHref(edge.href, `edge "${edge.id ?? `${edge.from}" -> "${edge.to}`}"`);
3868
4190
  }
3869
4191
  for (const node of nodes) {
@@ -3939,6 +4261,8 @@ function GraphDiagram({
3939
4261
  nodeGap = 34,
3940
4262
  rankGap = 64,
3941
4263
  edgeGap = 14,
4264
+ routing = "dagre",
4265
+ routingClearance = 12,
3942
4266
  sizing = "content",
3943
4267
  iconSize = 20,
3944
4268
  id,
@@ -3947,6 +4271,8 @@ function GraphDiagram({
3947
4271
  description
3948
4272
  }) {
3949
4273
  if (id != null && id.trim().length === 0) throw new Error("GraphDiagram id must not be empty.");
4274
+ if (!["dagre", "straight", "orthogonal"].includes(routing)) throw new Error('GraphDiagram routing must be "dagre", "straight", or "orthogonal".');
4275
+ if (!Number.isFinite(routingClearance) || routingClearance <= 0) throw new Error("GraphDiagram routingClearance must be a finite positive number.");
3950
4276
  const fullyPositioned = nodes.filter((node) => node.x != null && node.y != null).length;
3951
4277
  const partiallyPositioned = nodes.some((node) => node.x == null !== (node.y == null));
3952
4278
  if (partiallyPositioned || fullyPositioned > 0 && fullyPositioned < nodes.length) {
@@ -4041,7 +4367,30 @@ function GraphDiagram({
4041
4367
  } else {
4042
4368
  layout = manualGraphLayout(nodes, resolvedWidth, resolvedHeight, nodeWidth, nodeHeight, padding);
4043
4369
  }
4370
+ const anchored = (edge) => edge.fromPort != null || edge.toPort != null || edge.fromSide != null || edge.toSide != null;
4371
+ const orthogonalEdges = edges.flatMap((edge, index) => routing === "orthogonal" || routing === "dagre" && anchored(edge) || routing === "straight" && edge.from === edge.to ? [{ edge, index }] : []);
4372
+ const routed = routeOrthogonalGraph(
4373
+ Array.from(layout.values()),
4374
+ orthogonalEdges.map(({ edge }) => edge),
4375
+ resolvedWidth,
4376
+ resolvedHeight,
4377
+ routingClearance,
4378
+ edgeGap,
4379
+ groupLayout.map((group) => ({
4380
+ left: group.cx - group.width / 2,
4381
+ right: group.cx + group.width / 2,
4382
+ top: group.cy - group.height / 2,
4383
+ bottom: group.cy - group.height / 2 + 26
4384
+ }))
4385
+ );
4386
+ const orthogonalPoints = new Map(Array.from(routed.routes, ([index, points]) => [orthogonalEdges[index].index, points]));
4387
+ const failedIndexes = new Set(routed.failures.map((failure) => orthogonalEdges[failure.index].index));
4388
+ const routingFailures = routed.failures.map((failure) => {
4389
+ const { edge } = orthogonalEdges[failure.index];
4390
+ return `Connector "${edge.from}" -> "${edge.to}" was not drawn: ${failure.reason}.`;
4391
+ });
4044
4392
  const edgeLayouts = edges.flatMap((edge, index) => {
4393
+ if (failedIndexes.has(index)) return [];
4045
4394
  const from = layout.get(edge.from);
4046
4395
  const to = layout.get(edge.to);
4047
4396
  if (!from || !to) return [];
@@ -4070,14 +4419,16 @@ function GraphDiagram({
4070
4419
  { x: from.cx + 10, y: from.cy - from.height / 2 - loopClearance },
4071
4420
  { x: from.cx + 10, y: from.cy - from.height / 2 }
4072
4421
  ] : void 0;
4073
- const points = automatic?.points.length ? automatic.points : manualLoopPoints ?? [
4422
+ const routedPoints = orthogonalPoints.get(index);
4423
+ const points = routedPoints ?? (routing === "straight" ? straightGraphRoute(from, to, edge) : automatic?.points.length ? automatic.points : manualLoopPoints ?? [
4074
4424
  { x: from.cx + dx * fromScale, y: from.cy + dy * fromScale },
4075
4425
  { x: to.cx - dx * toScale, y: to.cy - dy * toScale }
4076
- ];
4426
+ ]);
4077
4427
  const manualLoopLabel = manualLoopPoints ? {
4078
4428
  x: from.cx + from.width / 2 + loopClearance,
4079
4429
  y: from.cy - from.height / 2 - loopClearance / 2
4080
4430
  } : void 0;
4431
+ const routedLabel = routedPoints || routing === "straight" ? routingLabelPosition(points) : void 0;
4081
4432
  return [{
4082
4433
  ...edge,
4083
4434
  index,
@@ -4085,14 +4436,14 @@ function GraphDiagram({
4085
4436
  color,
4086
4437
  markerId,
4087
4438
  points,
4088
- labelX: automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
4089
- labelY: automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
4439
+ labelX: routedLabel?.x ?? automatic?.labelX ?? manualLoopLabel?.x ?? (points[0].x + points[points.length - 1].x) / 2,
4440
+ labelY: routedLabel?.y ?? automatic?.labelY ?? manualLoopLabel?.y ?? (points[0].y + points[points.length - 1].y) / 2
4090
4441
  }];
4091
4442
  });
4092
4443
  const crossings = connectorCrossings(edgeLayouts);
4093
4444
  const labelCollisions = connectorLabelCollisions(edgeLayouts, layout, groupLayout);
4094
4445
  const crowdedEndpoints = crowdedConnectorEndpoints(edgeLayouts);
4095
- const parallelGroups = parallelConnectorGroups(edgeLayouts);
4446
+ const parallelGroups = parallelConnectorGroups(edgeLayouts.filter((edge) => !orthogonalPoints.has(edge.index)));
4096
4447
  const groupElements = groupLayout.map((group) => {
4097
4448
  const accent = group.muted ? c.textMuted : getToneColor(group.tone ?? "blue", c);
4098
4449
  return React6.createElement("div", {
@@ -4107,8 +4458,8 @@ function GraphDiagram({
4107
4458
  display: "flex",
4108
4459
  boxSizing: "border-box",
4109
4460
  borderRadius: c.preset === "engineering" ? 6 : 12,
4110
- border: `${c.preset === "engineering" ? 1.25 : 1.5}px ${group.muted ? "dashed" : "solid"} ${accent}${group.muted ? "55" : "77"}`,
4111
- backgroundColor: `${accent}${c.preset === "engineering" ? "08" : "0d"}`,
4461
+ border: `${c.preset === "engineering" ? 1.25 : 1.5}px ${group.muted ? "dashed" : "solid"} ${withColorAlpha(accent, (group.muted ? 85 : 119) / 255)}`,
4462
+ backgroundColor: withColorAlpha(accent, (c.preset === "engineering" ? 8 : 13) / 255),
4112
4463
  opacity: group.muted ? 0.68 : 1
4113
4464
  }
4114
4465
  }, React6.createElement(
@@ -4158,6 +4509,8 @@ function GraphDiagram({
4158
4509
  "data-vizmatic-connector-label-collisions": labelCollisions,
4159
4510
  "data-vizmatic-crowded-connector-endpoints": crowdedEndpoints,
4160
4511
  "data-vizmatic-parallel-connector-groups": parallelGroups,
4512
+ "data-vizmatic-unrouted-connectors": routingFailures.length,
4513
+ "data-vizmatic-routing-failures": routingFailures.length ? JSON.stringify(routingFailures) : void 0,
4161
4514
  style: {
4162
4515
  position: "relative",
4163
4516
  display: "flex",
@@ -4276,7 +4629,7 @@ function GraphDiagram({
4276
4629
  boxSizing: "border-box",
4277
4630
  borderRadius: c.preset === "engineering" ? 5 : 10,
4278
4631
  backgroundColor: node.muted ? c.bgSubtle : fill,
4279
- border: `${c.preset === "engineering" ? 1.25 : 1.5}px solid ${node.muted ? c.borderLight : `${accent}${c.preset === "engineering" ? "" : "88"}`}`,
4632
+ border: `${c.preset === "engineering" ? 1.25 : 1.5}px solid ${node.muted ? c.borderLight : c.preset === "engineering" ? accent : withColorAlpha(accent, 136 / 255)}`,
4280
4633
  ...!node.muted && c.preset !== "engineering" ? { boxShadow: `0 8px 18px ${c.shadow}` } : {},
4281
4634
  opacity: node.muted ? 0.62 : 1,
4282
4635
  color: c.preset === "engineering" ? c.textPrimary : accentText,
@@ -4500,7 +4853,7 @@ function TreeDiagram({
4500
4853
  boxSizing: "border-box",
4501
4854
  borderRadius: 8,
4502
4855
  backgroundColor: node.muted ? c.bgSubtle : c.bgCard,
4503
- border: `1.5px solid ${node.muted ? c.borderLight : `${accent}88`}`,
4856
+ border: `1.5px solid ${node.muted ? c.borderLight : withColorAlpha(accent, 136 / 255)}`,
4504
4857
  ...!node.muted ? { boxShadow: `0 8px 18px ${c.shadow}` } : {},
4505
4858
  opacity: node.muted ? 0.62 : 1,
4506
4859
  color: accentText,
@@ -4560,7 +4913,7 @@ function CalloutCard({
4560
4913
  padding,
4561
4914
  borderRadius: engineering ? 5 : 10,
4562
4915
  boxSizing: "border-box",
4563
- ...engineering ? { backgroundColor: getToneFill(tone, c), color: c.textPrimary, border: `1px solid ${accent}` } : filled ? { backgroundImage: getToneGradient(tone), color: c.textOnColor, border: `1px solid ${accent}00` } : { backgroundColor: c.bgCard, color: c.textPrimary, border: `1px solid ${accent}66` },
4916
+ ...engineering ? { backgroundColor: getToneFill(tone, c), color: c.textPrimary, border: `1px solid ${accent}` } : filled ? { backgroundImage: getToneGradient(tone), color: c.textOnColor, border: `1px solid ${withColorAlpha(accent, 0)}` } : { backgroundColor: c.bgCard, color: c.textPrimary, border: `1px solid ${withColorAlpha(accent, 102 / 255)}` },
4564
4917
  display: "flex",
4565
4918
  flexDirection: "column",
4566
4919
  alignItems: align === "center" ? "center" : "flex-start",
@@ -4906,8 +5259,8 @@ function SequenceDiagram({
4906
5259
  height: spanHeight,
4907
5260
  display: "flex",
4908
5261
  boxSizing: "border-box",
4909
- border: `1.25px ${span.fragment.muted ? "dotted" : "dashed"} ${accent}${span.fragment.muted ? "55" : "99"}`,
4910
- backgroundColor: `${accent}0b`,
5262
+ border: `1.25px ${span.fragment.muted ? "dotted" : "dashed"} ${withColorAlpha(accent, (span.fragment.muted ? 85 : 153) / 255)}`,
5263
+ backgroundColor: withColorAlpha(accent, 11 / 255),
4911
5264
  borderRadius: c.preset === "engineering" ? 4 : 8,
4912
5265
  pointerEvents: "none"
4913
5266
  }
@@ -5057,7 +5410,7 @@ function SequenceDiagram({
5057
5410
  padding: "6px 9px",
5058
5411
  borderRadius: c.preset === "engineering" ? 3 : 7,
5059
5412
  backgroundColor: note.muted ? c.bgSubtle : getToneFill(tone, c),
5060
- border: `1px solid ${accent}${note.muted ? "66" : "99"}`,
5413
+ border: `1px solid ${withColorAlpha(accent, (note.muted ? 102 : 153) / 255)}`,
5061
5414
  color: note.muted ? c.textMuted : getReadableTextColor(getToneFill(tone, c), c),
5062
5415
  fontFamily: c.fontSans,
5063
5416
  fontSize: 11,
@@ -5415,6 +5768,8 @@ function DataflowDiagram({
5415
5768
  nodeGap,
5416
5769
  rankGap,
5417
5770
  edgeGap,
5771
+ routing,
5772
+ routingClearance,
5418
5773
  sizing,
5419
5774
  iconSize
5420
5775
  }) {
@@ -5440,6 +5795,8 @@ function DataflowDiagram({
5440
5795
  nodeGap,
5441
5796
  rankGap,
5442
5797
  edgeGap,
5798
+ routing,
5799
+ routingClearance,
5443
5800
  sizing,
5444
5801
  iconSize
5445
5802
  });
@@ -5568,8 +5925,8 @@ function portIdentity(port) {
5568
5925
  function portText(port) {
5569
5926
  if (typeof port === "string" || typeof port === "number") return String(port);
5570
5927
  if (port.label) return port.label;
5571
- const endpoint = port.port ?? port.id;
5572
- return [port.protocol, endpoint == null ? void 0 : String(endpoint)].filter(Boolean).join("/") || port.direction || "port";
5928
+ const endpoint2 = port.port ?? port.id;
5929
+ return [port.protocol, endpoint2 == null ? void 0 : String(endpoint2)].filter(Boolean).join("/") || port.direction || "port";
5573
5930
  }
5574
5931
  function portForReference(node, reference) {
5575
5932
  if (reference == null) return void 0;
@@ -5679,6 +6036,9 @@ function compileDeployment(spec) {
5679
6036
  const boundaries = spec.boundaries ?? [];
5680
6037
  const connections = spec.connections ?? [];
5681
6038
  validateDeploymentSpec(boundaries, spec.nodes, connections);
6039
+ const anchorPorts = spec.routing != null && spec.routing !== "dagre";
6040
+ const incomingSide = spec.direction === "TB" ? "top" : spec.direction === "BT" ? "bottom" : spec.direction === "RL" ? "right" : "left";
6041
+ const outgoingSide = spec.direction === "TB" ? "bottom" : spec.direction === "BT" ? "top" : spec.direction === "RL" ? "left" : "right";
5682
6042
  const groups = boundaries.map((boundary) => ({
5683
6043
  id: boundary.id,
5684
6044
  label: boundary.label,
@@ -5705,7 +6065,16 @@ function compileDeployment(spec) {
5705
6065
  height: node.height,
5706
6066
  group: node.boundary,
5707
6067
  icon: node.icon ?? nodeKindIcons[kind],
5708
- iconSize: node.iconSize
6068
+ iconSize: node.iconSize,
6069
+ ports: anchorPorts ? nodePorts.map((port, index) => {
6070
+ const incoming = typeof port === "object" ? port.direction === "ingress" : false;
6071
+ const targetOnly = connections.some((connection) => connection.to === node.id && String(connection.toPort) === portIdentity(port)) && !connections.some((connection) => connection.from === node.id && String(connection.fromPort) === portIdentity(port));
6072
+ return {
6073
+ id: portIdentity(port),
6074
+ side: typeof port === "object" && port.side != null ? port.side : incoming || targetOnly ? incomingSide : outgoingSide,
6075
+ offset: typeof port === "object" && port.offset != null ? port.offset : (index + 1) / (nodePorts.length + 1)
6076
+ };
6077
+ }) : void 0
5709
6078
  };
5710
6079
  });
5711
6080
  const edges = connections.map((connection) => {
@@ -5729,7 +6098,11 @@ function compileDeployment(spec) {
5729
6098
  arrow: connection.arrow ?? "forward",
5730
6099
  label: connectionLabel(connection, sourcePort ?? fallbackFromPort, targetPort ?? fallbackToPort),
5731
6100
  href: connection.href,
5732
- title: connection.title
6101
+ title: connection.title,
6102
+ fromPort: anchorPorts && fromReference != null ? String(fromReference) : void 0,
6103
+ toPort: anchorPorts && toReference != null ? String(toReference) : void 0,
6104
+ fromSide: connection.fromSide,
6105
+ toSide: connection.toSide
5733
6106
  };
5734
6107
  });
5735
6108
  return {
@@ -5747,7 +6120,7 @@ function DeploymentDiagram({
5747
6120
  ariaLabel = "Deployment diagram",
5748
6121
  ...graphProps
5749
6122
  }) {
5750
- const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel });
6123
+ const compiled = compileDeployment({ nodes, boundaries, connections, ariaLabel, direction: graphProps.direction, routing: graphProps.routing });
5751
6124
  return GraphDiagram({
5752
6125
  ...graphProps,
5753
6126
  c,
@@ -5973,11 +6346,11 @@ function compileTransformer(spec) {
5973
6346
  for (const route of routes) {
5974
6347
  const kind = resolveRouteKind(route);
5975
6348
  const endpoints = expandedRouteEndpoints(route, repeatCounts, expandRepeats);
5976
- for (const [index, endpoint] of endpoints.entries()) {
6349
+ for (const [index, endpoint2] of endpoints.entries()) {
5977
6350
  edges.push({
5978
6351
  id: route.id == null ? void 0 : endpoints.length === 1 ? route.id : `${route.id}-${index + 1}`,
5979
- from: endpoint.from,
5980
- to: endpoint.to,
6352
+ from: endpoint2.from,
6353
+ to: endpoint2.to,
5981
6354
  tone: route.tone ?? routeTones[kind],
5982
6355
  muted: route.muted,
5983
6356
  kind: graphRouteKind(kind),
@@ -6212,8 +6585,8 @@ function TiledMatrix({
6212
6585
  height: cellSize,
6213
6586
  boxSizing: "border-box",
6214
6587
  borderRadius: Math.max(2, Math.min(6, Math.round(cellSize * 0.18))),
6215
- backgroundColor: region ? `${accent}42` : muted ? c.bgSubtle : `${baseAccent}0f`,
6216
- border: `1px solid ${region ? `${accent}aa` : c.borderSubtle}`,
6588
+ backgroundColor: region ? withColorAlpha(accent, 66 / 255) : muted ? c.bgSubtle : withColorAlpha(baseAccent, 15 / 255),
6589
+ border: `1px solid ${region ? withColorAlpha(accent, 170 / 255) : c.borderSubtle}`,
6217
6590
  opacity: muted ? 0.55 : 1
6218
6591
  }
6219
6592
  });
@@ -6388,7 +6761,7 @@ function Grid({
6388
6761
  const config = isGridCell(cell) ? cell : {};
6389
6762
  const toneColor = config.tone ? getToneColor(config.tone, c) : void 0;
6390
6763
  const isHeader = rowIndex < headerRows || colIndex < headerCols;
6391
- const backgroundColor = config.backgroundColor ?? (toneColor ? `${toneColor}22` : isHeader ? c.bgSubtle : c.bgHover);
6764
+ const backgroundColor = config.backgroundColor ?? (toneColor ? withColorAlpha(toneColor, 34 / 255) : isHeader ? c.bgSubtle : c.bgHover);
6392
6765
  const toneTextColor = config.tone ? getReadableToneColor(config.tone, c, backgroundColor, c.bgHover) : void 0;
6393
6766
  return {
6394
6767
  width: cellWidth,
@@ -6398,7 +6771,7 @@ function Grid({
6398
6771
  justifyContent: "center",
6399
6772
  borderRadius: radius,
6400
6773
  backgroundColor,
6401
- border: `1px solid ${config.borderColor ?? (toneColor ? `${toneColor}55` : c.borderSubtle)}`,
6774
+ border: `1px solid ${config.borderColor ?? (toneColor ? withColorAlpha(toneColor, 85 / 255) : c.borderSubtle)}`,
6402
6775
  color: config.color ?? (toneTextColor ?? (isHeader ? c.textPrimary : c.textSecondary)),
6403
6776
  ...config.opacity !== void 0 ? { opacity: config.opacity } : {},
6404
6777
  fontFamily: "JetBrains Mono",
@@ -6652,7 +7025,138 @@ function AxisPlot({
6652
7025
  }
6653
7026
 
6654
7027
  // src/primitives/charts.ts
6655
- import React10 from "react";
7028
+ import React11 from "react";
7029
+
7030
+ // src/canvas-chart-fit.ts
7031
+ import React10, { isValidElement as isValidElement2 } from "react";
7032
+ var CANVAS_CHART_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvasChartComponent");
7033
+ var CHART_FRAME_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.chartFrameComponent");
7034
+ var FIT_PROP = "__vizmaticCanvasChartFit";
7035
+ var SCOPE_PROP = "data-vizmatic-chart-fit-scope";
7036
+ var VIEWPORT_PROP = "data-vizmatic-chart-fit-viewport";
7037
+ function isCanvasChart(component) {
7038
+ return typeof component === "function" && Boolean(component[CANVAS_CHART_COMPONENT]);
7039
+ }
7040
+ function CanvasChartFit({ children, width, height }) {
7041
+ let chart = children;
7042
+ for (let depth = 0; isValidElement2(chart) && typeof chart.type === "function" && depth < 16; depth += 1) {
7043
+ if (chart.type[CHART_FRAME_COMPONENT]) {
7044
+ const props = chart.props;
7045
+ const padding = typeof props.padding === "number" ? props.padding : 16;
7046
+ chart = React10.cloneElement(chart, {
7047
+ ...props,
7048
+ width: typeof props.width === "number" ? props.width + 2 * (padding + 1) : props.width,
7049
+ height: void 0
7050
+ });
7051
+ break;
7052
+ }
7053
+ chart = chart.type(chart.props);
7054
+ }
7055
+ return React10.createElement("div", {
7056
+ [FIT_PROP]: { width, height },
7057
+ style: { position: "relative", display: "flex", width, height, flexShrink: 0 }
7058
+ }, React10.createElement("div", {
7059
+ style: { position: "absolute", left: 0, top: 0, display: "flex", alignItems: "flex-start" }
7060
+ }, chart));
7061
+ }
7062
+ function prepareChartFits(element) {
7063
+ const sizes = /* @__PURE__ */ new Map();
7064
+ const visit = (node, scope) => {
7065
+ if (Array.isArray(node)) return node.map((child) => visit(child, scope));
7066
+ if (!isValidElement2(node)) return node;
7067
+ if (typeof node.type === "function") {
7068
+ const resolved = visit(node.type(node.props), scope);
7069
+ return node.key != null && isValidElement2(resolved) ? React10.cloneElement(resolved, { key: node.key }) : resolved;
7070
+ }
7071
+ const size = node.props[FIT_PROP];
7072
+ const props = { ...node.props };
7073
+ delete props[FIT_PROP];
7074
+ if (size) {
7075
+ const id = String(sizes.size);
7076
+ sizes.set(id, size);
7077
+ props[VIEWPORT_PROP] = id;
7078
+ return React10.cloneElement(node, props, visit(node.props.children, id));
7079
+ }
7080
+ if (scope !== void 0 && typeof node.type === "string") props[SCOPE_PROP] = scope;
7081
+ const children = node.props.children;
7082
+ return children === void 0 ? React10.cloneElement(node, props) : React10.cloneElement(node, props, visit(children, scope));
7083
+ };
7084
+ return { element: visit(element), sizes };
7085
+ }
7086
+ function fittedTree(element, geometry) {
7087
+ if (Array.isArray(element)) return element.map((child) => fittedTree(child, geometry));
7088
+ if (!isValidElement2(element)) return element;
7089
+ const id = element.props[VIEWPORT_PROP];
7090
+ const children = element.props.children;
7091
+ if (typeof id === "string") {
7092
+ const fit = geometry.get(id);
7093
+ const content = React10.Children.only(children);
7094
+ return React10.cloneElement(element, {}, React10.cloneElement(content, { style: {
7095
+ ...content.props.style,
7096
+ left: fit.left,
7097
+ top: fit.top,
7098
+ transform: `scale(${fit.scale})`,
7099
+ transformOrigin: "top left"
7100
+ } }));
7101
+ }
7102
+ return children === void 0 ? element : React10.cloneElement(element, {}, fittedTree(children, geometry));
7103
+ }
7104
+ async function renderWithCanvasChartFit(render, element, options) {
7105
+ const prepared = prepareChartFits(element);
7106
+ if (!prepared.sizes.size) return render(prepared.element, options);
7107
+ const viewports = /* @__PURE__ */ new Map();
7108
+ const bounds = /* @__PURE__ */ new Map();
7109
+ await render(prepared.element, { ...options, onNodeDetected(node) {
7110
+ const viewport = node.props[VIEWPORT_PROP];
7111
+ if (typeof viewport === "string") viewports.set(viewport, node);
7112
+ const id = node.props[SCOPE_PROP];
7113
+ if (typeof id !== "string" || node.width <= 0 || node.height <= 0) return;
7114
+ const prior = bounds.get(id);
7115
+ bounds.set(id, {
7116
+ left: Math.min(prior?.left ?? Infinity, node.left),
7117
+ top: Math.min(prior?.top ?? Infinity, node.top),
7118
+ right: Math.max(prior?.right ?? -Infinity, node.left + node.width),
7119
+ bottom: Math.max(prior?.bottom ?? -Infinity, node.top + node.height)
7120
+ });
7121
+ } });
7122
+ const geometry = /* @__PURE__ */ new Map();
7123
+ for (const [id, size] of prepared.sizes) {
7124
+ const viewport = viewports.get(id);
7125
+ const measured = bounds.get(id);
7126
+ if (!viewport || !measured) throw new Error("Could not measure the chart inside CanvasItem.");
7127
+ const width = measured.right - measured.left, height = measured.bottom - measured.top;
7128
+ const scale = Math.min(size.width / width, size.height / height);
7129
+ if (!Number.isFinite(scale) || scale <= 0) throw new Error("CanvasItem charts require positive, finite dimensions.");
7130
+ geometry.set(id, {
7131
+ ...size,
7132
+ scale,
7133
+ left: (size.width - width * scale) / 2 - (measured.left - viewport.left) * scale,
7134
+ top: (size.height - height * scale) / 2 - (measured.top - viewport.top) * scale
7135
+ });
7136
+ }
7137
+ const finalViewports = /* @__PURE__ */ new Map();
7138
+ return render(fittedTree(prepared.element, geometry), { ...options, onNodeDetected(node) {
7139
+ const viewport = node.props[VIEWPORT_PROP];
7140
+ if (typeof viewport === "string") finalViewports.set(viewport, node);
7141
+ const id = node.props[SCOPE_PROP];
7142
+ const fit = typeof id === "string" ? geometry.get(id) : void 0;
7143
+ const origin = typeof id === "string" ? finalViewports.get(id) : void 0;
7144
+ if (fit && origin) {
7145
+ const left = origin.left + fit.left, top = origin.top + fit.top;
7146
+ const style = node.props.style ?? {};
7147
+ options.onNodeDetected?.({
7148
+ ...node,
7149
+ left: left + (node.left - left) * fit.scale,
7150
+ top: top + (node.top - top) * fit.scale,
7151
+ width: node.width * fit.scale,
7152
+ height: node.height * fit.scale,
7153
+ props: { ...node.props, style: { ...style, ...typeof style.fontSize === "number" ? { fontSize: style.fontSize * fit.scale } : {} } }
7154
+ });
7155
+ } else options.onNodeDetected?.(node);
7156
+ } });
7157
+ }
7158
+
7159
+ // src/primitives/charts.ts
6656
7160
  var chartPalette = ["primary", "secondary", "positive", "warning", "info", "accent", "critical"];
6657
7161
  function isColorName(value) {
6658
7162
  return chartPalette.includes(value) || value === "neutral";
@@ -6742,7 +7246,7 @@ function chartLabel(key, text, x, y, c, options = {}) {
6742
7246
  );
6743
7247
  transform = void 0;
6744
7248
  }
6745
- return React10.createElement("div", {
7249
+ return React11.createElement("div", {
6746
7250
  key,
6747
7251
  style: {
6748
7252
  position: "absolute",
@@ -6784,7 +7288,10 @@ function pointLabelPlacement(x, y, plot, index, width = 70) {
6784
7288
  }
6785
7289
  };
6786
7290
  }
6787
- function ChartFrame({
7291
+ function ChartFrame(props) {
7292
+ return React11.createElement(ChartFrameContent, props);
7293
+ }
7294
+ function ChartFrameContent({
6788
7295
  children,
6789
7296
  c,
6790
7297
  title,
@@ -6795,7 +7302,7 @@ function ChartFrame({
6795
7302
  height,
6796
7303
  padding = 16
6797
7304
  }) {
6798
- return React10.createElement(
7305
+ return React11.createElement(
6799
7306
  "div",
6800
7307
  {
6801
7308
  style: {
@@ -6812,20 +7319,20 @@ function ChartFrame({
6812
7319
  boxShadow: `0 9px 24px ${c.shadow}`
6813
7320
  }
6814
7321
  },
6815
- (title || subtitle) && React10.createElement(
7322
+ (title || subtitle) && React11.createElement(
6816
7323
  "div",
6817
7324
  {
6818
7325
  style: { display: "flex", flexDirection: "column", gap: 4, minWidth: 0, maxWidth: "100%" }
6819
7326
  },
6820
- title && React10.createElement("div", {
7327
+ title && React11.createElement("div", {
6821
7328
  style: { ...typography.small, ...textFitStyle(), color: c.textPrimary, fontWeight: 900 }
6822
7329
  }, title),
6823
- subtitle && React10.createElement("div", {
7330
+ subtitle && React11.createElement("div", {
6824
7331
  style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, lineHeight: 1.35 }
6825
7332
  }, subtitle)
6826
7333
  ),
6827
7334
  children,
6828
- (legend || footer) && React10.createElement(
7335
+ (legend || footer) && React11.createElement(
6829
7336
  "div",
6830
7337
  {
6831
7338
  style: {
@@ -6836,18 +7343,18 @@ function ChartFrame({
6836
7343
  minHeight: 18
6837
7344
  }
6838
7345
  },
6839
- legend && React10.createElement(
7346
+ legend && React11.createElement(
6840
7347
  "div",
6841
7348
  {
6842
7349
  style: { display: "flex", alignItems: "center", gap: 12, flexWrap: "wrap", minWidth: 0 }
6843
7350
  },
6844
- ...legend.map((item, index) => React10.createElement(
7351
+ ...legend.map((item, index) => React11.createElement(
6845
7352
  "div",
6846
7353
  {
6847
7354
  key: `${item.label}-${index}`,
6848
7355
  style: { display: "flex", alignItems: "center", gap: 6, minWidth: 0 }
6849
7356
  },
6850
- React10.createElement("span", {
7357
+ React11.createElement("span", {
6851
7358
  style: {
6852
7359
  width: 14,
6853
7360
  height: 3,
@@ -6856,17 +7363,18 @@ function ChartFrame({
6856
7363
  display: "flex"
6857
7364
  }
6858
7365
  }),
6859
- React10.createElement("span", {
7366
+ React11.createElement("span", {
6860
7367
  style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary }
6861
7368
  }, item.label)
6862
7369
  ))
6863
7370
  ),
6864
- footer && React10.createElement("div", {
7371
+ footer && React11.createElement("div", {
6865
7372
  style: { ...typography.tiny, ...textFitStyle("right"), color: c.textMuted }
6866
7373
  }, footer)
6867
7374
  )
6868
7375
  );
6869
7376
  }
7377
+ Object.defineProperty(ChartFrameContent, CHART_FRAME_COMPONENT, { value: true });
6870
7378
  function polarPoint(cx, cy, radius, angleDegrees) {
6871
7379
  const radians = angleDegrees * Math.PI / 180;
6872
7380
  return {
@@ -6890,6 +7398,153 @@ function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
6890
7398
  "Z"
6891
7399
  ].join(" ");
6892
7400
  }
7401
+ function validateNonNegativeSegments(segments, chartName) {
7402
+ let total = 0;
7403
+ for (const segment of segments) {
7404
+ if (!Number.isFinite(segment.value) || segment.value < 0) {
7405
+ throw new RangeError(`${chartName} values must be finite, non-negative numbers.`);
7406
+ }
7407
+ total += segment.value;
7408
+ if (!Number.isFinite(total)) {
7409
+ throw new RangeError(`${chartName} total must be finite.`);
7410
+ }
7411
+ }
7412
+ return total;
7413
+ }
7414
+ function pieSectorPath(cx, cy, radius, startAngle, endAngle) {
7415
+ const span = endAngle - startAngle;
7416
+ const start = polarPoint(cx, cy, radius, startAngle);
7417
+ if (span >= 359.999) {
7418
+ const opposite = polarPoint(cx, cy, radius, startAngle + 180);
7419
+ return [
7420
+ `M ${cx} ${cy}`,
7421
+ `L ${start.x} ${start.y}`,
7422
+ `A ${radius} ${radius} 0 1 1 ${opposite.x} ${opposite.y}`,
7423
+ `A ${radius} ${radius} 0 1 1 ${start.x} ${start.y}`,
7424
+ "Z"
7425
+ ].join(" ");
7426
+ }
7427
+ const end = polarPoint(cx, cy, radius, endAngle);
7428
+ const largeArc = span > 180 ? 1 : 0;
7429
+ return `M ${cx} ${cy} L ${start.x} ${start.y} A ${radius} ${radius} 0 ${largeArc} 1 ${end.x} ${end.y} Z`;
7430
+ }
7431
+ function PieChart({
7432
+ segments,
7433
+ c,
7434
+ title,
7435
+ subtitle,
7436
+ width = 360,
7437
+ height = 240,
7438
+ size,
7439
+ format = "decimal",
7440
+ showLegend = true,
7441
+ footer
7442
+ }) {
7443
+ const total = validateNonNegativeSegments(segments, "PieChart");
7444
+ const positiveSegments = segments.filter((segment) => segment.value > 0);
7445
+ const resolvedSize = size ?? Math.min(184, Math.max(132, height - 44), Math.max(132, width * 0.5));
7446
+ const radius = resolvedSize / 2 - 2;
7447
+ const cx = resolvedSize / 2;
7448
+ const cy = resolvedSize / 2;
7449
+ let cursor = -90;
7450
+ const paths = positiveSegments.map((segment, index) => {
7451
+ const span = total > 0 ? segment.value / total * 360 : 0;
7452
+ const start = cursor;
7453
+ const end = index === positiveSegments.length - 1 ? 270 : cursor + span;
7454
+ cursor += span;
7455
+ return React11.createElement("path", {
7456
+ key: `pie-segment-${segment.label}-${index}`,
7457
+ d: pieSectorPath(cx, cy, radius, start, end),
7458
+ fill: chartColor(segment.color, c, index),
7459
+ stroke: c.bgCard,
7460
+ strokeWidth: positiveSegments.length > 1 ? 2 : 0,
7461
+ "data-pie-label": segment.label,
7462
+ "data-pie-value": segment.value,
7463
+ "data-pie-share": total > 0 ? segment.value / total : 0
7464
+ });
7465
+ });
7466
+ const legend = showLegend && positiveSegments.length > 0 && React11.createElement("div", {
7467
+ style: {
7468
+ display: "flex",
7469
+ flexDirection: "column",
7470
+ gap: 8,
7471
+ flex: 1,
7472
+ minWidth: 112
7473
+ }
7474
+ }, ...positiveSegments.map((segment, index) => {
7475
+ const formattedValue = formatChartValue(segment.value, format);
7476
+ const share = formatChartValue(segment.value / total, "percent");
7477
+ const label = segment.valueLabel ?? (format === "percent" ? formattedValue : `${formattedValue} \xB7 ${share}`);
7478
+ return React11.createElement(
7479
+ "div",
7480
+ {
7481
+ key: `pie-legend-${segment.label}-${index}`,
7482
+ style: { display: "flex", alignItems: "center", gap: 8, minWidth: 0 }
7483
+ },
7484
+ React11.createElement("span", {
7485
+ style: {
7486
+ display: "flex",
7487
+ width: 10,
7488
+ height: 10,
7489
+ borderRadius: 3,
7490
+ backgroundColor: chartColor(segment.color, c, index),
7491
+ flexShrink: 0
7492
+ }
7493
+ }),
7494
+ React11.createElement("span", {
7495
+ style: { ...typography.tiny, ...textFitStyle(), color: c.textSecondary, flex: 1 }
7496
+ }, segment.label),
7497
+ React11.createElement("span", {
7498
+ style: {
7499
+ ...typography.tiny,
7500
+ color: c.textPrimary,
7501
+ fontFamily: "JetBrains Mono",
7502
+ fontWeight: 850,
7503
+ flexShrink: 0
7504
+ }
7505
+ }, label)
7506
+ );
7507
+ }));
7508
+ return ChartFrame({
7509
+ c,
7510
+ title,
7511
+ subtitle,
7512
+ footer,
7513
+ width,
7514
+ children: React11.createElement(
7515
+ "div",
7516
+ {
7517
+ style: {
7518
+ display: "flex",
7519
+ alignItems: "center",
7520
+ justifyContent: showLegend ? "space-between" : "center",
7521
+ gap: 18,
7522
+ minHeight: resolvedSize,
7523
+ width: "100%"
7524
+ }
7525
+ },
7526
+ React11.createElement(
7527
+ "svg",
7528
+ {
7529
+ width: resolvedSize,
7530
+ height: resolvedSize,
7531
+ viewBox: `0 0 ${resolvedSize} ${resolvedSize}`,
7532
+ role: "img",
7533
+ "aria-label": title ?? "Pie chart"
7534
+ },
7535
+ positiveSegments.length === 0 ? React11.createElement("circle", {
7536
+ cx,
7537
+ cy,
7538
+ r: radius,
7539
+ fill: "none",
7540
+ stroke: c.borderLight,
7541
+ strokeWidth: 2
7542
+ }) : paths
7543
+ ),
7544
+ legend
7545
+ )
7546
+ });
7547
+ }
6893
7548
  function DonutChart({
6894
7549
  segments,
6895
7550
  c,
@@ -6922,13 +7577,13 @@ function DonutChart({
6922
7577
  const end = cursor + rawSpan - gap / 2;
6923
7578
  cursor += rawSpan;
6924
7579
  if (end <= start) return null;
6925
- return React10.createElement("path", {
7580
+ return React11.createElement("path", {
6926
7581
  key: `donut-segment-${segment.label}-${index}`,
6927
7582
  d: donutArcPath(cx, cy, outerRadius, innerRadius, start, end),
6928
7583
  fill: chartColor(segment.color, c, index)
6929
7584
  });
6930
7585
  }).filter(Boolean);
6931
- const legend = showLegend && positiveSegments.length > 0 && React10.createElement("div", {
7586
+ const legend = showLegend && positiveSegments.length > 0 && React11.createElement("div", {
6932
7587
  style: {
6933
7588
  display: "flex",
6934
7589
  flexDirection: "column",
@@ -6936,7 +7591,7 @@ function DonutChart({
6936
7591
  flex: 1,
6937
7592
  minWidth: 112
6938
7593
  }
6939
- }, ...positiveSegments.map((segment, index) => React10.createElement(
7594
+ }, ...positiveSegments.map((segment, index) => React11.createElement(
6940
7595
  "div",
6941
7596
  {
6942
7597
  key: `donut-legend-${segment.label}-${index}`,
@@ -6947,7 +7602,7 @@ function DonutChart({
6947
7602
  minWidth: 0
6948
7603
  }
6949
7604
  },
6950
- React10.createElement("span", {
7605
+ React11.createElement("span", {
6951
7606
  style: {
6952
7607
  display: "flex",
6953
7608
  width: 10,
@@ -6957,7 +7612,7 @@ function DonutChart({
6957
7612
  flexShrink: 0
6958
7613
  }
6959
7614
  }),
6960
- React10.createElement("span", {
7615
+ React11.createElement("span", {
6961
7616
  style: {
6962
7617
  ...typography.tiny,
6963
7618
  ...textFitStyle(),
@@ -6965,7 +7620,7 @@ function DonutChart({
6965
7620
  flex: 1
6966
7621
  }
6967
7622
  }, segment.label),
6968
- React10.createElement("span", {
7623
+ React11.createElement("span", {
6969
7624
  style: {
6970
7625
  ...typography.tiny,
6971
7626
  color: c.textPrimary,
@@ -6983,7 +7638,7 @@ function DonutChart({
6983
7638
  width,
6984
7639
  height,
6985
7640
  padding: 16,
6986
- children: React10.createElement(
7641
+ children: React11.createElement(
6987
7642
  "div",
6988
7643
  {
6989
7644
  style: {
@@ -6995,7 +7650,7 @@ function DonutChart({
6995
7650
  width: "100%"
6996
7651
  }
6997
7652
  },
6998
- React10.createElement(
7653
+ React11.createElement(
6999
7654
  "div",
7000
7655
  {
7001
7656
  style: {
@@ -7006,14 +7661,14 @@ function DonutChart({
7006
7661
  flexShrink: 0
7007
7662
  }
7008
7663
  },
7009
- React10.createElement(
7664
+ React11.createElement(
7010
7665
  "svg",
7011
7666
  {
7012
7667
  width: resolvedSize,
7013
7668
  height: resolvedSize,
7014
7669
  viewBox: `0 0 ${resolvedSize} ${resolvedSize}`
7015
7670
  },
7016
- positiveSegments.length === 0 ? React10.createElement("circle", {
7671
+ positiveSegments.length === 0 ? React11.createElement("circle", {
7017
7672
  cx,
7018
7673
  cy,
7019
7674
  r: (outerRadius + innerRadius) / 2,
@@ -7022,7 +7677,7 @@ function DonutChart({
7022
7677
  strokeWidth: resolvedThickness
7023
7678
  }) : paths
7024
7679
  ),
7025
- (centerLabel != null || resolvedCenterValue != null) && React10.createElement(
7680
+ (centerLabel != null || resolvedCenterValue != null) && React11.createElement(
7026
7681
  "div",
7027
7682
  {
7028
7683
  style: {
@@ -7041,7 +7696,7 @@ function DonutChart({
7041
7696
  textAlign: "center"
7042
7697
  }
7043
7698
  },
7044
- resolvedCenterValue != null && React10.createElement("div", {
7699
+ resolvedCenterValue != null && React11.createElement("div", {
7045
7700
  style: {
7046
7701
  ...typography.small,
7047
7702
  color: c.textPrimary,
@@ -7052,7 +7707,7 @@ function DonutChart({
7052
7707
  ...textFitStyle("center")
7053
7708
  }
7054
7709
  }, resolvedCenterValue),
7055
- centerLabel != null && React10.createElement("div", {
7710
+ centerLabel != null && React11.createElement("div", {
7056
7711
  style: {
7057
7712
  ...typography.tiny,
7058
7713
  color: c.textMuted,
@@ -7077,7 +7732,7 @@ function StackedBar({
7077
7732
  }) {
7078
7733
  const positiveSegments = segments.filter((segment) => segment.value > 0);
7079
7734
  const total = positiveSegments.reduce((sum, segment) => sum + segment.value, 0);
7080
- return React10.createElement(
7735
+ return React11.createElement(
7081
7736
  "div",
7082
7737
  {
7083
7738
  style: {
@@ -7087,7 +7742,7 @@ function StackedBar({
7087
7742
  gap: 10
7088
7743
  }
7089
7744
  },
7090
- (title || subtitle) && React10.createElement(
7745
+ (title || subtitle) && React11.createElement(
7091
7746
  "div",
7092
7747
  {
7093
7748
  style: {
@@ -7096,14 +7751,14 @@ function StackedBar({
7096
7751
  gap: 3
7097
7752
  }
7098
7753
  },
7099
- title && React10.createElement("div", {
7754
+ title && React11.createElement("div", {
7100
7755
  style: { ...typography.label, color: c.textPrimary, fontWeight: 850 }
7101
7756
  }, title),
7102
- subtitle && React10.createElement("div", {
7757
+ subtitle && React11.createElement("div", {
7103
7758
  style: { ...typography.tiny, color: c.textSecondary }
7104
7759
  }, subtitle)
7105
7760
  ),
7106
- React10.createElement(
7761
+ React11.createElement(
7107
7762
  "div",
7108
7763
  {
7109
7764
  style: {
@@ -7121,7 +7776,7 @@ function StackedBar({
7121
7776
  const share = total > 0 ? segment.value / total : 0;
7122
7777
  const segmentWidth = width * share;
7123
7778
  const color = chartColor(segment.color, c, index);
7124
- return React10.createElement(
7779
+ return React11.createElement(
7125
7780
  "div",
7126
7781
  {
7127
7782
  key: `${segment.label}-${index}`,
@@ -7135,7 +7790,7 @@ function StackedBar({
7135
7790
  ...index < positiveSegments.length - 1 ? { borderRight: `2px solid ${c.bgSubtle}` } : {}
7136
7791
  }
7137
7792
  },
7138
- segmentWidth >= 64 && React10.createElement("span", {
7793
+ segmentWidth >= 64 && React11.createElement("span", {
7139
7794
  style: {
7140
7795
  ...typography.small,
7141
7796
  color: getReadableTextColor(color, c),
@@ -7146,7 +7801,7 @@ function StackedBar({
7146
7801
  );
7147
7802
  })
7148
7803
  ),
7149
- showLegend && React10.createElement(
7804
+ showLegend && React11.createElement(
7150
7805
  "div",
7151
7806
  {
7152
7807
  style: {
@@ -7158,13 +7813,13 @@ function StackedBar({
7158
7813
  },
7159
7814
  ...positiveSegments.map((segment, index) => {
7160
7815
  const share = total > 0 ? segment.value / total : 0;
7161
- return React10.createElement(
7816
+ return React11.createElement(
7162
7817
  "div",
7163
7818
  {
7164
7819
  key: `legend-${segment.label}-${index}`,
7165
7820
  style: { display: "flex", alignItems: "center", gap: 7 }
7166
7821
  },
7167
- React10.createElement("span", {
7822
+ React11.createElement("span", {
7168
7823
  style: {
7169
7824
  width: 12,
7170
7825
  height: 12,
@@ -7173,7 +7828,7 @@ function StackedBar({
7173
7828
  backgroundColor: chartColor(segment.color, c, index)
7174
7829
  }
7175
7830
  }),
7176
- React10.createElement("span", {
7831
+ React11.createElement("span", {
7177
7832
  style: { ...typography.tiny, color: c.textSecondary }
7178
7833
  }, `${segment.label} ${segment.valueLabel ?? formatChartValue(share, "percent")}`)
7179
7834
  );
@@ -7219,18 +7874,18 @@ function BarChart({
7219
7874
  subtitle,
7220
7875
  width,
7221
7876
  footer,
7222
- children: React10.createElement(
7877
+ children: React11.createElement(
7223
7878
  "div",
7224
7879
  { style: { position: "relative", width, height, display: "flex" } },
7225
- React10.createElement(
7880
+ React11.createElement(
7226
7881
  "svg",
7227
7882
  { width, height, viewBox: `0 0 ${width} ${height}` },
7228
- showGrid && React10.createElement(
7883
+ showGrid && React11.createElement(
7229
7884
  "g",
7230
7885
  {},
7231
7886
  ...ticks.map((tick) => {
7232
7887
  const y = yInPlot(tick, domain, plot);
7233
- return React10.createElement("line", {
7888
+ return React11.createElement("line", {
7234
7889
  key: `tick-${tick}`,
7235
7890
  x1: plot.x,
7236
7891
  y1: y,
@@ -7241,10 +7896,10 @@ function BarChart({
7241
7896
  });
7242
7897
  })
7243
7898
  ),
7244
- React10.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
7245
- React10.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: 1.2 }),
7899
+ React11.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
7900
+ React11.createElement("line", { x1: plot.x, y1: baselineY, x2: plot.right, y2: baselineY, stroke: c.borderLight, strokeWidth: 1.2 }),
7246
7901
  ...barGeometries.map(
7247
- ({ item, index, x, y, barHeight, color }) => React10.createElement("rect", {
7902
+ ({ item, index, x, y, barHeight, color }) => React11.createElement("rect", {
7248
7903
  key: `${item.label}-${index}`,
7249
7904
  x,
7250
7905
  y,
@@ -7280,6 +7935,186 @@ function BarChart({
7280
7935
  )
7281
7936
  });
7282
7937
  }
7938
+ function ParetoBarChart({
7939
+ data,
7940
+ c,
7941
+ title,
7942
+ subtitle,
7943
+ width = 520,
7944
+ height = 300,
7945
+ format = "integer",
7946
+ showGrid = true,
7947
+ showValues = true,
7948
+ footer
7949
+ }) {
7950
+ let total = 0;
7951
+ for (const item of data) {
7952
+ if (!Number.isFinite(item.value) || item.value < 0) {
7953
+ throw new RangeError("ParetoBarChart values must be finite, non-negative numbers.");
7954
+ }
7955
+ total += item.value;
7956
+ if (!Number.isFinite(total)) {
7957
+ throw new RangeError("ParetoBarChart total must be finite.");
7958
+ }
7959
+ }
7960
+ const sorted = data.map((item, index) => ({ item, index })).sort((left, right) => right.item.value - left.item.value || left.index - right.index);
7961
+ const maximum = Math.max(1, ...sorted.map(({ item }) => item.value));
7962
+ const margin = { top: 24, right: 48, bottom: 48, left: 48 };
7963
+ const plot = createPlotArea(width, height, margin);
7964
+ const valueDomain = {
7965
+ min: 0,
7966
+ range: maximum > Number.MAX_VALUE / 1.16 ? maximum : maximum * 1.16
7967
+ };
7968
+ const countTicks = chartTicks(0, maximum, 4);
7969
+ const slot = plot.innerWidth / Math.max(sorted.length, 1);
7970
+ const barWidth = Math.max(6, Math.min(68, slot * 0.68));
7971
+ let accumulated = 0;
7972
+ const bars = sorted.map(({ item, index }, order) => {
7973
+ accumulated += item.value;
7974
+ const cumulative = total === 0 ? 0 : order === sorted.length - 1 ? 1 : accumulated / total;
7975
+ const x = plot.x + order * slot + (slot - barWidth) / 2;
7976
+ const top = yInPlot(item.value, valueDomain, plot);
7977
+ return {
7978
+ item,
7979
+ sourceIndex: index,
7980
+ order,
7981
+ x,
7982
+ y: top,
7983
+ height: Math.max(0, plot.bottom - top),
7984
+ color: chartColor(item.color, c, order),
7985
+ centerX: x + barWidth / 2,
7986
+ cumulative,
7987
+ cumulativeY: plot.bottom - cumulative * plot.innerHeight
7988
+ };
7989
+ });
7990
+ const cumulativePath = bars.map(({ centerX, cumulativeY }, index) => `${index === 0 ? "M" : "L"} ${centerX.toFixed(1)} ${cumulativeY.toFixed(1)}`).join(" ");
7991
+ return ChartFrame({
7992
+ c,
7993
+ title,
7994
+ subtitle,
7995
+ width,
7996
+ footer,
7997
+ children: React11.createElement(
7998
+ "div",
7999
+ {
8000
+ style: { position: "relative", width, height, display: "flex" }
8001
+ },
8002
+ React11.createElement(
8003
+ "svg",
8004
+ {
8005
+ width,
8006
+ height,
8007
+ viewBox: `0 0 ${width} ${height}`,
8008
+ role: "img",
8009
+ "aria-label": title ?? "Pareto bar chart"
8010
+ },
8011
+ showGrid && React11.createElement(
8012
+ "g",
8013
+ {},
8014
+ ...countTicks.map((tick) => {
8015
+ const y = yInPlot(tick, valueDomain, plot);
8016
+ return React11.createElement("line", {
8017
+ key: `pareto-count-grid-${tick}`,
8018
+ x1: plot.x,
8019
+ y1: y,
8020
+ x2: plot.right,
8021
+ y2: y,
8022
+ stroke: c.borderSubtle,
8023
+ strokeWidth: 1
8024
+ });
8025
+ })
8026
+ ),
8027
+ React11.createElement("line", {
8028
+ x1: plot.x,
8029
+ y1: plot.bottom,
8030
+ x2: plot.right,
8031
+ y2: plot.bottom,
8032
+ stroke: c.borderLight,
8033
+ strokeWidth: 1.2
8034
+ }),
8035
+ React11.createElement("line", {
8036
+ x1: plot.right,
8037
+ y1: plot.y,
8038
+ x2: plot.right,
8039
+ y2: plot.bottom,
8040
+ stroke: c.borderLight,
8041
+ strokeWidth: 1.2
8042
+ }),
8043
+ ...bars.map(({ item, order, x, y, height: barHeight, color }) => React11.createElement("rect", {
8044
+ key: `pareto-bar-${item.label}-${order}`,
8045
+ x,
8046
+ y,
8047
+ width: barWidth,
8048
+ height: barHeight,
8049
+ rx: 4,
8050
+ fill: color,
8051
+ opacity: 0.86,
8052
+ "data-pareto-bar": item.label,
8053
+ "data-pareto-value": item.value,
8054
+ "data-pareto-order": order
8055
+ })),
8056
+ cumulativePath && React11.createElement("path", {
8057
+ d: cumulativePath,
8058
+ fill: "none",
8059
+ stroke: chartColor("critical", c),
8060
+ strokeWidth: 3,
8061
+ strokeLinecap: "round",
8062
+ strokeLinejoin: "round",
8063
+ "data-pareto-cumulative-line": true
8064
+ }),
8065
+ ...bars.map(({ item, sourceIndex, centerX, cumulativeY, cumulative, order }) => React11.createElement("circle", {
8066
+ key: `pareto-cumulative-point-${order}`,
8067
+ cx: centerX,
8068
+ cy: cumulativeY,
8069
+ r: 4,
8070
+ fill: chartColor("critical", c),
8071
+ stroke: c.bgCard,
8072
+ strokeWidth: 2,
8073
+ "data-pareto-category": item.label,
8074
+ "data-pareto-source-index": sourceIndex,
8075
+ "data-pareto-cumulative-percent": cumulative * 100
8076
+ }))
8077
+ ),
8078
+ ...countTicks.map((tick) => chartLabel(
8079
+ `pareto-count-label-${tick}`,
8080
+ formatChartValue(tick, format),
8081
+ plot.x - 7,
8082
+ yInPlot(tick, valueDomain, plot),
8083
+ c,
8084
+ { align: "right", width: 36 }
8085
+ )),
8086
+ ...[0, 0.5, 1].map((share) => chartLabel(
8087
+ `pareto-percent-label-${share}`,
8088
+ `${Math.round(share * 100)}%`,
8089
+ plot.right + 7,
8090
+ plot.bottom - share * plot.innerHeight,
8091
+ c,
8092
+ { align: "left", width: 38 }
8093
+ )),
8094
+ ...bars.flatMap(({ item, order, centerX, y }) => [
8095
+ ...showValues ? [chartLabel(
8096
+ `pareto-value-${order}`,
8097
+ item.valueLabel ?? formatChartValue(item.value, format),
8098
+ centerX,
8099
+ clamp(y - 8, plot.y + 8, plot.bottom - 12),
8100
+ c,
8101
+ { color: c.textPrimary, fontWeight: 800, width: Math.min(slot, 64), bounds: { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight } }
8102
+ )] : [],
8103
+ chartLabel(
8104
+ `pareto-category-${order}`,
8105
+ item.label,
8106
+ centerX,
8107
+ height - 17,
8108
+ c,
8109
+ {
8110
+ width: Math.max(1, Math.min(96, slot - 2)),
8111
+ bounds: { x: plot.x, y: plot.bottom + 1, width: plot.innerWidth, height: Math.max(1, height - plot.bottom - 2), padding: 0 }
8112
+ }
8113
+ )
8114
+ ])
8115
+ )
8116
+ });
8117
+ }
7283
8118
  function LineChart({
7284
8119
  series,
7285
8120
  c,
@@ -7323,18 +8158,18 @@ function LineChart({
7323
8158
  width,
7324
8159
  footer,
7325
8160
  legend: series.map((item, index) => ({ label: item.name, color: item.color ?? chartPalette[index % chartPalette.length] })),
7326
- children: React10.createElement(
8161
+ children: React11.createElement(
7327
8162
  "div",
7328
8163
  { style: { position: "relative", width, height, display: "flex" } },
7329
- React10.createElement(
8164
+ React11.createElement(
7330
8165
  "svg",
7331
8166
  { width, height, viewBox: `0 0 ${width} ${height}` },
7332
- showGrid && React10.createElement(
8167
+ showGrid && React11.createElement(
7333
8168
  "g",
7334
8169
  {},
7335
8170
  ...ticks.map((tick) => {
7336
8171
  const y = yInPlot(tick, domain, plot);
7337
- return React10.createElement("line", {
8172
+ return React11.createElement("line", {
7338
8173
  key: `line-tick-${tick}`,
7339
8174
  x1: plot.x,
7340
8175
  y1: y,
@@ -7345,8 +8180,8 @@ function LineChart({
7345
8180
  });
7346
8181
  })
7347
8182
  ),
7348
- React10.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
7349
- React10.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
8183
+ React11.createElement("line", { x1: plot.x, y1: plot.y, x2: plot.x, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
8184
+ React11.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
7350
8185
  ...series.flatMap((item, seriesIndex) => {
7351
8186
  if (item.points.length === 0) return [];
7352
8187
  const color = chartColor(item.color, c, seriesIndex);
@@ -7359,9 +8194,9 @@ function LineChart({
7359
8194
  }
7360
8195
  const elements = [];
7361
8196
  if (areaPath) {
7362
- elements.push(React10.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
8197
+ elements.push(React11.createElement("path", { key: `${item.name}-area`, d: areaPath, fill: color, opacity: 0.12 }));
7363
8198
  }
7364
- elements.push(React10.createElement("path", {
8199
+ elements.push(React11.createElement("path", {
7365
8200
  key: `${item.name}-line`,
7366
8201
  d: linePath,
7367
8202
  fill: "none",
@@ -7373,7 +8208,7 @@ function LineChart({
7373
8208
  if (showPoints) {
7374
8209
  elements.push(...item.points.map((value, index) => {
7375
8210
  const point = pointFor(value, index);
7376
- return React10.createElement("circle", {
8211
+ return React11.createElement("circle", {
7377
8212
  key: `${item.name}-point-${index}`,
7378
8213
  cx: point.x,
7379
8214
  cy: point.y,
@@ -7404,9 +8239,15 @@ function LineChart({
7404
8239
  )
7405
8240
  });
7406
8241
  }
8242
+ for (const chart of [PieChart, DonutChart, StackedBar, BarChart, ParetoBarChart, LineChart]) {
8243
+ Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
8244
+ }
7407
8245
 
7408
8246
  // src/primitives/plots.ts
7409
- import React11 from "react";
8247
+ import React12 from "react";
8248
+ for (const chart of [ScatterPlot, ParetoChart, QuadrantChart, IntervalPlot]) {
8249
+ Object.defineProperty(chart, CANVAS_CHART_COMPONENT, { value: true });
8250
+ }
7410
8251
  function xTickLabelAlign(index, count) {
7411
8252
  if (index === 0) return "left";
7412
8253
  if (index === count - 1) return "right";
@@ -7450,18 +8291,18 @@ function ScatterPlot({
7450
8291
  subtitle,
7451
8292
  width,
7452
8293
  footer,
7453
- children: React11.createElement(
8294
+ children: React12.createElement(
7454
8295
  "div",
7455
8296
  { style: { position: "relative", width, height, display: "flex" } },
7456
- React11.createElement(
8297
+ React12.createElement(
7457
8298
  "svg",
7458
8299
  { width, height, viewBox: `0 0 ${width} ${height}` },
7459
- showGrid && React11.createElement(
8300
+ showGrid && React12.createElement(
7460
8301
  "g",
7461
8302
  {},
7462
8303
  ...xTicks.map((tick) => {
7463
8304
  const x = xInPlot(tick, xDomain, plot);
7464
- return React11.createElement("line", {
8305
+ return React12.createElement("line", {
7465
8306
  key: `x-tick-${tick}`,
7466
8307
  x1: x,
7467
8308
  y1: plot.y,
@@ -7473,7 +8314,7 @@ function ScatterPlot({
7473
8314
  }),
7474
8315
  ...yTicks.map((tick) => {
7475
8316
  const y = yInPlot(tick, yDomain, plot);
7476
- return React11.createElement("line", {
8317
+ return React12.createElement("line", {
7477
8318
  key: `y-tick-${tick}`,
7478
8319
  x1: plot.x,
7479
8320
  y1: y,
@@ -7484,9 +8325,9 @@ function ScatterPlot({
7484
8325
  });
7485
8326
  })
7486
8327
  ),
7487
- React11.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
8328
+ React12.createElement("rect", { x: plot.x, y: plot.y, width: plot.innerWidth, height: plot.innerHeight, fill: "transparent", stroke: c.borderLight, strokeWidth: 1.2, rx: 6 }),
7488
8329
  ...pointGeometries.map(
7489
- ({ item, index, point, color }) => React11.createElement("circle", {
8330
+ ({ item, index, point, color }) => React12.createElement("circle", {
7490
8331
  key: `${item.label ?? "point"}-${index}`,
7491
8332
  cx: point.x,
7492
8333
  cy: point.y,
@@ -7637,18 +8478,18 @@ function ParetoChart({
7637
8478
  { label: "Pareto frontier", color: frontier },
7638
8479
  { label: "dominated", color: "neutral" }
7639
8480
  ],
7640
- children: React11.createElement(
8481
+ children: React12.createElement(
7641
8482
  "div",
7642
8483
  { style: { position: "relative", width, height, display: "flex" } },
7643
- React11.createElement(
8484
+ React12.createElement(
7644
8485
  "svg",
7645
8486
  { width, height, viewBox: `0 0 ${width} ${height}` },
7646
- showGrid && React11.createElement(
8487
+ showGrid && React12.createElement(
7647
8488
  "g",
7648
8489
  {},
7649
8490
  ...xTicks.map((tick) => {
7650
8491
  const x = pointFor(tick, yDomain.min).x;
7651
- return React11.createElement("line", {
8492
+ return React12.createElement("line", {
7652
8493
  key: `pareto-x-grid-${tick}`,
7653
8494
  x1: x,
7654
8495
  y1: plot.y,
@@ -7660,7 +8501,7 @@ function ParetoChart({
7660
8501
  }),
7661
8502
  ...yTicks.map((tick) => {
7662
8503
  const y = yInPlot(tick, yDomain, plot);
7663
- return React11.createElement("line", {
8504
+ return React12.createElement("line", {
7664
8505
  key: `pareto-y-grid-${tick}`,
7665
8506
  x1: plot.x,
7666
8507
  y1: y,
@@ -7671,7 +8512,7 @@ function ParetoChart({
7671
8512
  });
7672
8513
  })
7673
8514
  ),
7674
- React11.createElement("rect", {
8515
+ React12.createElement("rect", {
7675
8516
  x: plot.x,
7676
8517
  y: plot.y,
7677
8518
  width: plot.innerWidth,
@@ -7681,17 +8522,17 @@ function ParetoChart({
7681
8522
  strokeWidth: 1.2,
7682
8523
  rx: 6
7683
8524
  }),
7684
- showGoal && React11.createElement(
8525
+ showGoal && React12.createElement(
7685
8526
  "g",
7686
8527
  { "data-pareto-goal": true, stroke: frontier, fill: "none", strokeWidth: 2, strokeLinecap: "round" },
7687
- React11.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
7688
- React11.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
7689
- React11.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
7690
- React11.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
7691
- React11.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
7692
- React11.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
8528
+ React12.createElement("line", { x1: goalXStart, y1: goalY, x2: goalXEnd, y2: goalY }),
8529
+ React12.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY - arrowSize }),
8530
+ React12.createElement("line", { x1: goalXEnd, y1: goalY, x2: goalXEnd + (xObjective === "minimize" ? arrowSize : -arrowSize), y2: goalY + arrowSize }),
8531
+ React12.createElement("line", { x1: goalXStart, y1: goalYStart, x2: goalXStart, y2: goalYEnd }),
8532
+ React12.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart - arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) }),
8533
+ React12.createElement("line", { x1: goalXStart, y1: goalYEnd, x2: goalXStart + arrowSize, y2: goalYEnd + (yObjective === "maximize" ? arrowSize : -arrowSize) })
7693
8534
  ),
7694
- frontierPath && React11.createElement("path", {
8535
+ frontierPath && React12.createElement("path", {
7695
8536
  "data-pareto-frontier": true,
7696
8537
  d: frontierPath,
7697
8538
  fill: "none",
@@ -7700,7 +8541,7 @@ function ParetoChart({
7700
8541
  strokeLinecap: "round",
7701
8542
  strokeLinejoin: "round"
7702
8543
  }),
7703
- ...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => React11.createElement("circle", {
8544
+ ...pointGeometries.filter((geometry) => !geometry.frontier).concat(pointGeometries.filter((geometry) => geometry.frontier)).map(({ point, index, x, y, color, frontier: isFrontier }) => React12.createElement("circle", {
7704
8545
  key: `pareto-point-${point.label ?? "point"}-${index}`,
7705
8546
  "data-pareto-status": isFrontier ? "frontier" : "dominated",
7706
8547
  cx: x,
@@ -7812,18 +8653,18 @@ function QuadrantChart({
7812
8653
  subtitle,
7813
8654
  width,
7814
8655
  footer,
7815
- children: React11.createElement(
8656
+ children: React12.createElement(
7816
8657
  "div",
7817
8658
  {
7818
8659
  style: { position: "relative", width, height, display: "flex" }
7819
8660
  },
7820
- React11.createElement(
8661
+ React12.createElement(
7821
8662
  "svg",
7822
8663
  { width, height, viewBox: `0 0 ${width} ${height}` },
7823
8664
  ...regionEntries.map(({ key, region, x, y, width: regionWidth, height: regionHeight }, index) => {
7824
8665
  const color = chartColor(region.color, c, index);
7825
8666
  const emphasized = region.emphasis === true;
7826
- return React11.createElement("rect", {
8667
+ return React12.createElement("rect", {
7827
8668
  key: `quadrant-${key}`,
7828
8669
  x,
7829
8670
  y,
@@ -7835,12 +8676,12 @@ function QuadrantChart({
7835
8676
  strokeWidth: emphasized ? 2 : 0
7836
8677
  });
7837
8678
  }),
7838
- showGrid && React11.createElement(
8679
+ showGrid && React12.createElement(
7839
8680
  "g",
7840
8681
  {},
7841
8682
  ...xTicks.map((tick) => {
7842
8683
  const x = xInPlot(tick, xDomain, plot);
7843
- return React11.createElement("line", {
8684
+ return React12.createElement("line", {
7844
8685
  key: `quadrant-x-grid-${tick}`,
7845
8686
  x1: x,
7846
8687
  y1: plot.y,
@@ -7852,7 +8693,7 @@ function QuadrantChart({
7852
8693
  }),
7853
8694
  ...yTicks.map((tick) => {
7854
8695
  const y = yInPlot(tick, yDomain, plot);
7855
- return React11.createElement("line", {
8696
+ return React12.createElement("line", {
7856
8697
  key: `quadrant-y-grid-${tick}`,
7857
8698
  x1: plot.x,
7858
8699
  y1: y,
@@ -7863,7 +8704,7 @@ function QuadrantChart({
7863
8704
  });
7864
8705
  })
7865
8706
  ),
7866
- React11.createElement("rect", {
8707
+ React12.createElement("rect", {
7867
8708
  x: plot.x,
7868
8709
  y: plot.y,
7869
8710
  width: plot.innerWidth,
@@ -7873,7 +8714,7 @@ function QuadrantChart({
7873
8714
  strokeWidth: 1.2,
7874
8715
  rx: 8
7875
8716
  }),
7876
- React11.createElement("line", {
8717
+ React12.createElement("line", {
7877
8718
  x1: midX,
7878
8719
  y1: plot.y,
7879
8720
  x2: midX,
@@ -7881,7 +8722,7 @@ function QuadrantChart({
7881
8722
  stroke: c.borderLight,
7882
8723
  strokeWidth: 1.4
7883
8724
  }),
7884
- React11.createElement("line", {
8725
+ React12.createElement("line", {
7885
8726
  x1: plot.x,
7886
8727
  y1: midY,
7887
8728
  x2: plot.right,
@@ -7891,7 +8732,7 @@ function QuadrantChart({
7891
8732
  }),
7892
8733
  ...(showTicks ? xTicks : []).map((tick) => {
7893
8734
  const x = xInPlot(tick, xDomain, plot);
7894
- return React11.createElement("line", {
8735
+ return React12.createElement("line", {
7895
8736
  key: `quadrant-x-tick-${tick}`,
7896
8737
  x1: x,
7897
8738
  y1: plot.bottom,
@@ -7903,7 +8744,7 @@ function QuadrantChart({
7903
8744
  }),
7904
8745
  ...(showTicks ? yTicks : []).map((tick) => {
7905
8746
  const y = yInPlot(tick, yDomain, plot);
7906
- return React11.createElement("line", {
8747
+ return React12.createElement("line", {
7907
8748
  key: `quadrant-y-tick-${tick}`,
7908
8749
  x1: plot.x - 5,
7909
8750
  y1: y,
@@ -7913,7 +8754,7 @@ function QuadrantChart({
7913
8754
  strokeWidth: 1.2
7914
8755
  });
7915
8756
  }),
7916
- ...pointGeometries.map(({ point, index, x, y, color }) => React11.createElement("circle", {
8757
+ ...pointGeometries.map(({ point, index, x, y, color }) => React12.createElement("circle", {
7917
8758
  key: `quadrant-point-${point.label ?? index}`,
7918
8759
  cx: x,
7919
8760
  cy: y,
@@ -8015,15 +8856,15 @@ function IntervalPlot({
8015
8856
  subtitle,
8016
8857
  width,
8017
8858
  footer,
8018
- children: React11.createElement(
8859
+ children: React12.createElement(
8019
8860
  "div",
8020
8861
  { style: { position: "relative", width, height, display: "flex" } },
8021
- React11.createElement(
8862
+ React12.createElement(
8022
8863
  "svg",
8023
8864
  { width, height, viewBox: `0 0 ${width} ${height}` },
8024
8865
  ...ticks.map((tick) => {
8025
8866
  const x = scaleX(tick);
8026
- return React11.createElement("line", {
8867
+ return React12.createElement("line", {
8027
8868
  key: `interval-tick-${tick}`,
8028
8869
  x1: x,
8029
8870
  y1: plot.y,
@@ -8033,10 +8874,10 @@ function IntervalPlot({
8033
8874
  strokeWidth: 1
8034
8875
  });
8035
8876
  }),
8036
- React11.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
8877
+ React12.createElement("line", { x1: plot.x, y1: plot.bottom, x2: plot.right, y2: plot.bottom, stroke: c.borderLight, strokeWidth: 1.2 }),
8037
8878
  ...rows.flatMap(({ item, index, y, color, lowX, midX, highX }) => [
8038
- React11.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
8039
- React11.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
8879
+ React12.createElement("line", { key: `${item.label}-range-${index}`, x1: lowX, y1: y, x2: highX, y2: y, stroke: color, strokeWidth: 9, strokeLinecap: "round", opacity: 0.9 }),
8880
+ React12.createElement("circle", { key: `${item.label}-mid-${index}`, cx: midX, cy: y, r: 10, fill: c.bgCard, stroke: color, strokeWidth: 4 })
8040
8881
  ])
8041
8882
  ),
8042
8883
  ...ticks.map((tick, index) => {
@@ -8073,19 +8914,19 @@ function IntervalPlot({
8073
8914
  }
8074
8915
  function Badge({ label, c, color = "primary" }) {
8075
8916
  const solidColor = getReadableColor(color, c);
8076
- return React11.createElement("div", {
8917
+ return React12.createElement("div", {
8077
8918
  style: {
8078
8919
  display: "flex",
8079
8920
  alignItems: "center",
8080
8921
  justifyContent: "center",
8081
- backgroundColor: `${solidColor}20`,
8922
+ backgroundColor: withColorAlpha(solidColor, 32 / 255),
8082
8923
  color: solidColor,
8083
8924
  borderRadius: 999,
8084
8925
  padding: "4px 12px",
8085
8926
  fontSize: 11,
8086
8927
  fontWeight: 600,
8087
8928
  fontFamily: "Inter",
8088
- border: `1px solid ${solidColor}40`
8929
+ border: `1px solid ${withColorAlpha(solidColor, 64 / 255)}`
8089
8930
  }
8090
8931
  }, label);
8091
8932
  }
@@ -8094,7 +8935,7 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
8094
8935
  const offY = labelOffset?.y ?? -22;
8095
8936
  return [
8096
8937
  // Dot
8097
- React11.createElement("div", {
8938
+ React12.createElement("div", {
8098
8939
  key: `dot-${label}`,
8099
8940
  style: {
8100
8941
  position: "absolute",
@@ -8104,12 +8945,12 @@ function DotPoint({ x, y, label, color, c, size = 12, labelOffset }) {
8104
8945
  height: size,
8105
8946
  borderRadius: "50%",
8106
8947
  backgroundColor: color,
8107
- boxShadow: `0 0 14px ${color}50`,
8948
+ boxShadow: `0 0 14px ${withColorAlpha(color, 80 / 255)}`,
8108
8949
  display: "flex"
8109
8950
  }
8110
8951
  }),
8111
8952
  // Label
8112
- React11.createElement("div", {
8953
+ React12.createElement("div", {
8113
8954
  key: `label-${label}`,
8114
8955
  style: {
8115
8956
  position: "absolute",
@@ -8135,7 +8976,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
8135
8976
  if (i % 2 === 1) continue;
8136
8977
  const t = i / numDots;
8137
8978
  dots.push(
8138
- React11.createElement("div", {
8979
+ React12.createElement("div", {
8139
8980
  key: `dash-${i}`,
8140
8981
  style: {
8141
8982
  position: "absolute",
@@ -8152,7 +8993,7 @@ function DashedLine({ x1, y1, x2, y2, color, dotSpacing = 8, dotSize = 2 }) {
8152
8993
  return dots;
8153
8994
  }
8154
8995
  function Legend({ items, c, title }) {
8155
- return React11.createElement(
8996
+ return React12.createElement(
8156
8997
  "div",
8157
8998
  {
8158
8999
  style: {
@@ -8165,7 +9006,7 @@ function Legend({ items, c, title }) {
8165
9006
  padding: "14px 16px"
8166
9007
  }
8167
9008
  },
8168
- title && React11.createElement("div", {
9009
+ title && React12.createElement("div", {
8169
9010
  style: {
8170
9011
  fontSize: 11,
8171
9012
  fontWeight: 700,
@@ -8176,13 +9017,13 @@ function Legend({ items, c, title }) {
8176
9017
  }
8177
9018
  }, title),
8178
9019
  ...items.map(
8179
- (item, i) => React11.createElement(
9020
+ (item, i) => React12.createElement(
8180
9021
  "div",
8181
9022
  {
8182
9023
  key: `legend-${i}`,
8183
9024
  style: { display: "flex", alignItems: "center", gap: 8 }
8184
9025
  },
8185
- React11.createElement("div", {
9026
+ React12.createElement("div", {
8186
9027
  style: {
8187
9028
  width: 16,
8188
9029
  height: item.style === "dashed" ? 0 : 2,
@@ -8192,7 +9033,7 @@ function Legend({ items, c, title }) {
8192
9033
  } : {}
8193
9034
  }
8194
9035
  }),
8195
- React11.createElement("div", {
9036
+ React12.createElement("div", {
8196
9037
  style: {
8197
9038
  fontSize: 11,
8198
9039
  color: c.textMuted,
@@ -8204,6 +9045,45 @@ function Legend({ items, c, title }) {
8204
9045
  );
8205
9046
  }
8206
9047
 
9048
+ // src/primitives/board.ts
9049
+ import React13 from "react";
9050
+ var CANVAS_ITEM_COMPONENT = /* @__PURE__ */ Symbol.for("vizmatic.canvas-item");
9051
+ function dimension(value, name) {
9052
+ if (value !== void 0 && (!Number.isFinite(value) || value <= 0 || value > 8192)) {
9053
+ throw new Error(`${name} must be a finite number greater than 0 and at most 8192.`);
9054
+ }
9055
+ return value;
9056
+ }
9057
+ function Board({ children, c, width = 960, height = 540, background }) {
9058
+ return React13.createElement("div", { style: {
9059
+ display: "flex",
9060
+ position: "relative",
9061
+ width: dimension(width, "Board width"),
9062
+ height: dimension(height, "Board height"),
9063
+ overflow: "hidden",
9064
+ backgroundColor: background ?? "transparent",
9065
+ color: c.textPrimary
9066
+ } }, children);
9067
+ }
9068
+ function CanvasItem({ children, x, y, width, height }) {
9069
+ if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error("CanvasItem x and y must be finite numbers.");
9070
+ const sizedChildren = React13.Children.map(children, (child) => {
9071
+ if (!React13.isValidElement(child)) return child;
9072
+ const sized = React13.cloneElement(child, { ...width !== void 0 ? { width } : {}, ...height !== void 0 ? { height } : {} });
9073
+ return width !== void 0 && height !== void 0 && isCanvasChart(child.type) ? React13.createElement(CanvasChartFit, { width, height, __vizmaticTextScope: child.props.__vizmaticTextScope }, sized) : sized;
9074
+ });
9075
+ return React13.createElement("div", { style: {
9076
+ display: "flex",
9077
+ position: "absolute",
9078
+ left: x,
9079
+ top: y,
9080
+ width: dimension(width, "CanvasItem width"),
9081
+ height: dimension(height, "CanvasItem height"),
9082
+ alignItems: "stretch"
9083
+ } }, sizedChildren);
9084
+ }
9085
+ Object.defineProperty(CanvasItem, CANVAS_ITEM_COMPONENT, { value: true });
9086
+
8207
9087
  // src/render.ts
8208
9088
  import { Resvg } from "@resvg/resvg-js";
8209
9089
  import { homedir } from "os";
@@ -8214,12 +9094,12 @@ import { fileURLToPath } from "url";
8214
9094
  import { brotliDecompressSync } from "zlib";
8215
9095
 
8216
9096
  // src/brand.ts
8217
- import React12 from "react";
9097
+ import React14 from "react";
8218
9098
  var DEFAULT_WATERMARK_TEXT = "Vizmatic";
8219
9099
  var WATERMARK_COLOR_DARK = "#a78bfa";
8220
9100
  var WATERMARK_COLOR_LIGHT = "#7c3aed";
8221
9101
  function VizmaticIcon({ size = 14, color }) {
8222
- return React12.createElement(
9102
+ return React14.createElement(
8223
9103
  "svg",
8224
9104
  {
8225
9105
  xmlns: "http://www.w3.org/2000/svg",
@@ -8228,19 +9108,19 @@ function VizmaticIcon({ size = 14, color }) {
8228
9108
  viewBox: "0 0 28 28",
8229
9109
  fill: "none"
8230
9110
  },
8231
- React12.createElement("rect", { x: 2.5, y: 2.5, width: 23, height: 23, rx: 6.5, stroke: color, strokeWidth: 2, opacity: 0.54 }),
8232
- React12.createElement("rect", { x: 7, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.35 }),
8233
- React12.createElement("rect", { x: 15.5, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color }),
8234
- React12.createElement("rect", { x: 7, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.82 }),
8235
- React12.createElement("rect", { x: 15.5, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, stroke: color, strokeWidth: 1.5, opacity: 0.72 }),
8236
- React12.createElement("path", { d: "M9.75 9.75h8.5M9.75 18.25h8.5M9.75 9.75v8.5M18.25 9.75v8.5", stroke: color, strokeWidth: 1.6, strokeLinecap: "round", opacity: 0.88 })
9111
+ React14.createElement("rect", { x: 2.5, y: 2.5, width: 23, height: 23, rx: 6.5, stroke: color, strokeWidth: 2, opacity: 0.54 }),
9112
+ React14.createElement("rect", { x: 7, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.35 }),
9113
+ React14.createElement("rect", { x: 15.5, y: 7, width: 5.5, height: 5.5, rx: 1.8, fill: color }),
9114
+ React14.createElement("rect", { x: 7, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, fill: color, opacity: 0.82 }),
9115
+ React14.createElement("rect", { x: 15.5, y: 15.5, width: 5.5, height: 5.5, rx: 1.8, stroke: color, strokeWidth: 1.5, opacity: 0.72 }),
9116
+ React14.createElement("path", { d: "M9.75 9.75h8.5M9.75 18.25h8.5M9.75 9.75v8.5M18.25 9.75v8.5", stroke: color, strokeWidth: 1.6, strokeLinecap: "round", opacity: 0.88 })
8237
9117
  );
8238
9118
  }
8239
9119
  function normalizeWatermark(watermark) {
8240
9120
  if (watermark == null || watermark === false) return void 0;
8241
9121
  if (watermark === true) return {};
8242
9122
  if (typeof watermark === "string") return { text: watermark };
8243
- if (React12.isValidElement(watermark)) {
9123
+ if (React14.isValidElement(watermark)) {
8244
9124
  if (watermark.type !== Watermark) return { element: watermark };
8245
9125
  const { children, ...props } = watermark.props;
8246
9126
  return {
@@ -8269,7 +9149,7 @@ function positionStyle(position) {
8269
9149
  function imageNode(image) {
8270
9150
  if (!image) return void 0;
8271
9151
  const imageOptions = typeof image === "string" ? { src: image } : image;
8272
- return React12.createElement("img", {
9152
+ return React14.createElement("img", {
8273
9153
  src: imageOptions.src,
8274
9154
  alt: imageOptions.alt ?? "",
8275
9155
  width: imageOptions.width ?? 14,
@@ -8284,9 +9164,9 @@ function imageNode(image) {
8284
9164
  }
8285
9165
  function iconNode(icon, color) {
8286
9166
  if (icon === false) return void 0;
8287
- if (icon == null) return React12.createElement(VizmaticIcon, { size: 13, color });
9167
+ if (icon == null) return React14.createElement(VizmaticIcon, { size: 13, color });
8288
9168
  if (typeof icon !== "string") return icon;
8289
- return React12.createElement("div", {
9169
+ return React14.createElement("div", {
8290
9170
  style: {
8291
9171
  minWidth: 13,
8292
9172
  height: 13,
@@ -8311,7 +9191,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
8311
9191
  const text = options?.text ?? DEFAULT_WATERMARK_TEXT;
8312
9192
  const content = options?.element ?? [
8313
9193
  icon,
8314
- text !== false && text && React12.createElement("div", {
9194
+ text !== false && text && React14.createElement("div", {
8315
9195
  key: "text",
8316
9196
  style: {
8317
9197
  fontSize: 11,
@@ -8322,7 +9202,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
8322
9202
  }
8323
9203
  }, text)
8324
9204
  ];
8325
- return React12.createElement(
9205
+ return React14.createElement(
8326
9206
  "div",
8327
9207
  {
8328
9208
  style: {
@@ -8333,7 +9213,7 @@ function wrapWithWatermark(element, width, height, theme = "dark", watermark = t
8333
9213
  }
8334
9214
  },
8335
9215
  element,
8336
- options && React12.createElement(
9216
+ options && React14.createElement(
8337
9217
  "div",
8338
9218
  {
8339
9219
  style: {
@@ -8484,7 +9364,8 @@ function resolveSatori(api) {
8484
9364
  }
8485
9365
  throw new Error("satori export could not be resolved");
8486
9366
  }
8487
- var satori = resolveSatori(satoriModule);
9367
+ var renderSatori = resolveSatori(satoriModule);
9368
+ var satori = (element, options) => renderWithCanvasChartFit(renderSatori, element, options);
8488
9369
 
8489
9370
  // src/render.ts
8490
9371
  var FONT_CACHE_DIR = process.env.VIZMATIC_FONT_DIR ?? join(process.env.XDG_CACHE_HOME ?? join(homedir(), ".cache"), "vizmatic", "fonts");
@@ -9823,30 +10704,30 @@ function readEndpoint(line, from) {
9823
10704
  next: content.next
9824
10705
  };
9825
10706
  }
9826
- function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, explicitlyDeclared) {
9827
- if (state.groupIds.has(endpoint.id)) {
10707
+ function addNode(state, endpoint2, groupId, line, sourceLines, diagnostics, explicitlyDeclared) {
10708
+ if (state.groupIds.has(endpoint2.id)) {
9828
10709
  addImportDiagnostic(
9829
10710
  diagnostics,
9830
10711
  sourceLines,
9831
10712
  line,
9832
10713
  "import.unsupported_semantics",
9833
10714
  "error",
9834
- `Mermaid id "${endpoint.id}" is already used by a subgraph and cannot also be a node.`
10715
+ `Mermaid id "${endpoint2.id}" is already used by a subgraph and cannot also be a node.`
9835
10716
  );
9836
10717
  return false;
9837
10718
  }
9838
- if (labelHasUnsupportedMarkup(endpoint.label)) {
10719
+ if (labelHasUnsupportedMarkup(endpoint2.label)) {
9839
10720
  addImportDiagnostic(
9840
10721
  diagnostics,
9841
10722
  sourceLines,
9842
10723
  line,
9843
10724
  "import.unsupported_semantics",
9844
10725
  "error",
9845
- `Mermaid label for node "${endpoint.id}" uses HTML or Markdown formatting that GraphDiagram cannot preserve.`
10726
+ `Mermaid label for node "${endpoint2.id}" uses HTML or Markdown formatting that GraphDiagram cannot preserve.`
9846
10727
  );
9847
10728
  return false;
9848
10729
  }
9849
- const existingIndex = state.nodeIndexes.get(endpoint.id);
10730
+ const existingIndex = state.nodeIndexes.get(endpoint2.id);
9850
10731
  if (existingIndex !== void 0) {
9851
10732
  const existing = state.nodes[existingIndex];
9852
10733
  if (!existing) return false;
@@ -9857,7 +10738,7 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
9857
10738
  line,
9858
10739
  "import.unsupported_semantics",
9859
10740
  "error",
9860
- `Mermaid node "${endpoint.id}" is assigned to more than one subgraph; GraphDiagram nodes support one group.`
10741
+ `Mermaid node "${endpoint2.id}" is assigned to more than one subgraph; GraphDiagram nodes support one group.`
9861
10742
  );
9862
10743
  return false;
9863
10744
  }
@@ -9868,28 +10749,28 @@ function addNode(state, endpoint, groupId, line, sourceLines, diagnostics, expli
9868
10749
  line,
9869
10750
  "import.unsupported_semantics",
9870
10751
  "error",
9871
- `Mermaid node "${endpoint.id}" is referenced both inside and outside a subgraph; its group membership is ambiguous.`
10752
+ `Mermaid node "${endpoint2.id}" is referenced both inside and outside a subgraph; its group membership is ambiguous.`
9872
10753
  );
9873
10754
  return false;
9874
10755
  }
9875
- if (explicitlyDeclared) existing.label = endpoint.label;
10756
+ if (explicitlyDeclared) existing.label = endpoint2.label;
9876
10757
  } else {
9877
- state.nodeIndexes.set(endpoint.id, state.nodes.length);
10758
+ state.nodeIndexes.set(endpoint2.id, state.nodes.length);
9878
10759
  state.nodes.push({
9879
- id: endpoint.id,
9880
- label: endpoint.label,
10760
+ id: endpoint2.id,
10761
+ label: endpoint2.label,
9881
10762
  ...groupId ? { group: groupId } : {}
9882
10763
  });
9883
10764
  }
9884
- if (endpoint.shape === "lossy" && !state.warnedShapes.has(endpoint.id)) {
9885
- state.warnedShapes.add(endpoint.id);
10765
+ if (endpoint2.shape === "lossy" && !state.warnedShapes.has(endpoint2.id)) {
10766
+ state.warnedShapes.add(endpoint2.id);
9886
10767
  addImportDiagnostic(
9887
10768
  diagnostics,
9888
10769
  sourceLines,
9889
10770
  line,
9890
10771
  "import.lossy_semantics",
9891
10772
  "warning",
9892
- `Mermaid node "${endpoint.id}" uses a non-rectangular shape; it will render as a generic GraphDiagram node.`
10773
+ `Mermaid node "${endpoint2.id}" uses a non-rectangular shape; it will render as a generic GraphDiagram node.`
9893
10774
  );
9894
10775
  }
9895
10776
  return true;
@@ -10288,7 +11169,7 @@ import { join as join2 } from "path";
10288
11169
 
10289
11170
  // src/diagnostics.ts
10290
11171
  import parseCssColor3 from "parse-css-color";
10291
- import { Children, isValidElement as isValidElement2 } from "react";
11172
+ import { Children, isValidElement as isValidElement3 } from "react";
10292
11173
  var CHECK_DIAGNOSTIC_CODES = [
10293
11174
  "accessibility.low_contrast",
10294
11175
  "api.unsupported_prop",
@@ -10297,6 +11178,7 @@ var CHECK_DIAGNOSTIC_CODES = [
10297
11178
  "frame.unknown_preset",
10298
11179
  "layout.auto_size",
10299
11180
  "layout.connector_congestion",
11181
+ "layout.connector_unroutable",
10300
11182
  "layout.overflow",
10301
11183
  "layout.text_overlap",
10302
11184
  "layout.whitespace_imbalance",
@@ -10399,7 +11281,7 @@ function elementId(props) {
10399
11281
  return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
10400
11282
  }
10401
11283
  function resolveFunctionComponent(node, trustedComponents) {
10402
- if (!isValidElement2(node) || typeof node.type !== "function" || trustedComponents.has(node.type)) return void 0;
11284
+ if (!isValidElement3(node) || typeof node.type !== "function" || trustedComponents.has(node.type)) return void 0;
10403
11285
  const component = node.type;
10404
11286
  if (component.__vizmaticPrimitive) return void 0;
10405
11287
  if (component.prototype?.isReactComponent) return void 0;
@@ -10414,7 +11296,7 @@ function analyzeContrast(element, theme, trustedComponents = /* @__PURE__ */ new
10414
11296
  const seen = /* @__PURE__ */ new Set();
10415
11297
  let visited = 0;
10416
11298
  function visit(node, inherited, path) {
10417
- if (visited++ >= MAX_CONTRAST_NODES || !isValidElement2(node)) return;
11299
+ if (visited++ >= MAX_CONTRAST_NODES || !isValidElement3(node)) return;
10418
11300
  const resolved = resolveFunctionComponent(node, trustedComponents);
10419
11301
  if (resolved !== void 0) {
10420
11302
  visit(resolved, inherited, path);
@@ -10591,6 +11473,18 @@ function analyzeRenderedLayout(nodes, theme) {
10591
11473
  const value = node.props[attribute2];
10592
11474
  return typeof value === "number" ? value : Number(value) || 0;
10593
11475
  }));
11476
+ for (const source of nodes.filter((node) => Number(node.props["data-vizmatic-unrouted-connectors"]) > 0)) {
11477
+ const messages = JSON.parse(String(source.props["data-vizmatic-routing-failures"]));
11478
+ for (const message of messages.slice(0, MAX_DIAGNOSTICS_PER_RULE)) diagnostics.push({
11479
+ code: "layout.connector_unroutable",
11480
+ severity: "error",
11481
+ theme,
11482
+ message,
11483
+ suggestion: "Increase canvas size or spacing, reduce routingClearance, or choose a different endpoint side or port.",
11484
+ elementId: elementId(source.props),
11485
+ location: { x: source.left, y: source.top, width: source.width, height: source.height }
11486
+ });
11487
+ }
10594
11488
  const connectorCrossings2 = maxDataNumber("data-vizmatic-connector-crossings");
10595
11489
  if (connectorCrossings2 > 0) {
10596
11490
  const source = nodes.find((node) => Number(node.props["data-vizmatic-connector-crossings"]) > 0);
@@ -11043,10 +11937,13 @@ export {
11043
11937
  Badge,
11044
11938
  BadgePill,
11045
11939
  BarChart,
11940
+ Board,
11046
11941
  Box,
11942
+ CANVAS_ITEM_COMPONENT,
11047
11943
  CHECK_DIAGNOSTIC_CODES,
11048
11944
  CalloutCard,
11049
11945
  Canvas,
11946
+ CanvasItem,
11050
11947
  CanvasOverflowError,
11051
11948
  Card,
11052
11949
  ChartFrame,
@@ -11079,7 +11976,9 @@ export {
11079
11976
  MetricCard,
11080
11977
  MiniBarChart,
11081
11978
  Panel,
11979
+ ParetoBarChart,
11082
11980
  ParetoChart,
11981
+ PieChart,
11083
11982
  Pipeline,
11084
11983
  ProgressList,
11085
11984
  ProgressRow,
@@ -11159,6 +12058,7 @@ export {
11159
12058
  toneGradients,
11160
12059
  tween,
11161
12060
  typography,
12061
+ withColorAlpha,
11162
12062
  wrapWithBrand,
11163
12063
  wrapWithWatermark
11164
12064
  };