@peerproblem/sw3-ui 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -2
  3. package/agent/components/accordion.md +95 -0
  4. package/agent/components/action-square.md +106 -0
  5. package/agent/components/agent-bridge.md +87 -0
  6. package/agent/components/agent-console.md +123 -0
  7. package/agent/components/alert-dialog.md +82 -0
  8. package/agent/components/app-shell.md +105 -0
  9. package/agent/components/area-chart.md +56 -0
  10. package/agent/components/async-options.md +47 -0
  11. package/agent/components/autocomplete.md +69 -0
  12. package/agent/components/avatar.md +88 -0
  13. package/agent/components/badge.md +51 -0
  14. package/agent/components/bar-chart.md +56 -0
  15. package/agent/components/bar-list.md +49 -0
  16. package/agent/components/breadcrumbs.md +43 -0
  17. package/agent/components/button.md +109 -0
  18. package/agent/components/calendar.md +114 -0
  19. package/agent/components/canvas.md +105 -0
  20. package/agent/components/card.md +78 -0
  21. package/agent/components/carousel.md +113 -0
  22. package/agent/components/chart-card.md +41 -0
  23. package/agent/components/chart-surface.md +56 -0
  24. package/agent/components/checkbox.md +88 -0
  25. package/agent/components/citation-chip.md +61 -0
  26. package/agent/components/collapsible.md +69 -0
  27. package/agent/components/color-picker.md +82 -0
  28. package/agent/components/combobox.md +104 -0
  29. package/agent/components/command.md +92 -0
  30. package/agent/components/dashboard-grid.md +73 -0
  31. package/agent/components/date-input.md +87 -0
  32. package/agent/components/date-picker.md +122 -0
  33. package/agent/components/dialog.md +97 -0
  34. package/agent/components/donut-chart.md +50 -0
  35. package/agent/components/drawer.md +101 -0
  36. package/agent/components/empty-state.md +52 -0
  37. package/agent/components/field.md +80 -0
  38. package/agent/components/file-input.md +84 -0
  39. package/agent/components/hover-card.md +64 -0
  40. package/agent/components/image-cropper.md +77 -0
  41. package/agent/components/input.md +49 -0
  42. package/agent/components/label.md +53 -0
  43. package/agent/components/line-chart.md +60 -0
  44. package/agent/components/listbox.md +84 -0
  45. package/agent/components/map-view.md +104 -0
  46. package/agent/components/menu.md +117 -0
  47. package/agent/components/menubar.md +67 -0
  48. package/agent/components/meter.md +59 -0
  49. package/agent/components/navigation-menu.md +98 -0
  50. package/agent/components/number-input.md +81 -0
  51. package/agent/components/otp-input.md +67 -0
  52. package/agent/components/pagination.md +80 -0
  53. package/agent/components/password-input.md +67 -0
  54. package/agent/components/pill-button.md +116 -0
  55. package/agent/components/popover.md +85 -0
  56. package/agent/components/poster-card.md +61 -0
  57. package/agent/components/preferences.md +92 -0
  58. package/agent/components/progress.md +63 -0
  59. package/agent/components/provider.md +47 -0
  60. package/agent/components/radio.md +91 -0
  61. package/agent/components/rating.md +66 -0
  62. package/agent/components/reorder.md +61 -0
  63. package/agent/components/resizable.md +87 -0
  64. package/agent/components/scatter-chart.md +49 -0
  65. package/agent/components/scroll-area.md +81 -0
  66. package/agent/components/segmented-control.md +56 -0
  67. package/agent/components/select.md +130 -0
  68. package/agent/components/separator.md +60 -0
  69. package/agent/components/shortcuts.md +50 -0
  70. package/agent/components/sidebar-nav.md +68 -0
  71. package/agent/components/skeleton.md +58 -0
  72. package/agent/components/slider.md +79 -0
  73. package/agent/components/sparkline.md +39 -0
  74. package/agent/components/squircle.md +58 -0
  75. package/agent/components/stat.md +58 -0
  76. package/agent/components/switch.md +48 -0
  77. package/agent/components/table.md +58 -0
  78. package/agent/components/tabs.md +108 -0
  79. package/agent/components/textarea.md +68 -0
  80. package/agent/components/time-input.md +84 -0
  81. package/agent/components/timeline.md +91 -0
  82. package/agent/components/toast.md +85 -0
  83. package/agent/components/toggle.md +76 -0
  84. package/agent/components/token-input.md +66 -0
  85. package/agent/components/toolbar.md +76 -0
  86. package/agent/components/tooltip.md +83 -0
  87. package/agent/components/tracker.md +47 -0
  88. package/agent/components/tree.md +87 -0
  89. package/agent/components/treemap.md +72 -0
  90. package/agent/components/trend-chart.md +80 -0
  91. package/agent/components/trigger-menu.md +67 -0
  92. package/agent/components/typography.md +51 -0
  93. package/agent/components/waterfall.md +78 -0
  94. package/agent/components/week-schedule.md +113 -0
  95. package/agent/llms/actions-and-layout.txt +1749 -0
  96. package/agent/llms/agents.txt +505 -0
  97. package/agent/llms/charts.txt +778 -0
  98. package/agent/llms/dashboards.txt +457 -0
  99. package/agent/llms/extend.txt +132 -0
  100. package/agent/llms/extras.txt +527 -0
  101. package/agent/llms/forms.txt +2152 -0
  102. package/agent/llms/foundations.txt +674 -0
  103. package/agent/llms/hooks.txt +178 -0
  104. package/agent/llms/maps.txt +229 -0
  105. package/agent/llms/overlays-and-navigation.txt +1167 -0
  106. package/agent/llms-full.txt +8717 -0
  107. package/agent/llms.txt +145 -0
  108. package/agent/registry.json +11289 -0
  109. package/agent/tokens.md +66 -0
  110. package/dist/agent/index.d.ts +235 -0
  111. package/dist/agent/index.js +21 -0
  112. package/dist/card-Ipm-Cj5f.d.ts +490 -0
  113. package/dist/charts/index.d.ts +289 -0
  114. package/dist/charts/index.js +815 -0
  115. package/dist/check/cli.d.ts +1 -0
  116. package/dist/check/cli.js +48 -0
  117. package/dist/check/rendered.d.ts +11 -0
  118. package/dist/check/rendered.js +77 -0
  119. package/dist/check/source.d.ts +13 -0
  120. package/dist/check/source.js +182 -0
  121. package/dist/chunk-3DXBM65D.js +65 -0
  122. package/dist/chunk-3H5X4ZP6.js +55 -0
  123. package/dist/chunk-6XC4BC5C.js +92 -0
  124. package/dist/chunk-7H6TEAWD.js +507 -0
  125. package/dist/chunk-I63ZTJOI.js +1089 -0
  126. package/dist/chunk-JCIRUM4W.js +33 -0
  127. package/dist/chunk-LTBEHZ3P.js +25 -0
  128. package/dist/chunk-QDPPLO4U.js +60 -0
  129. package/dist/chunk-U2XFBPU4.js +56 -0
  130. package/dist/chunk-UY2WH5AY.js +681 -0
  131. package/dist/extras.d.ts +203 -0
  132. package/dist/extras.js +904 -0
  133. package/dist/icons-BJiGEAnU.d.ts +68 -0
  134. package/dist/index.d.ts +3737 -0
  135. package/dist/index.js +14477 -0
  136. package/dist/map/index.d.ts +115 -0
  137. package/dist/map/index.js +394 -0
  138. package/dist/meta/index.d.ts +3314 -0
  139. package/dist/meta/index.js +5106 -0
  140. package/dist/rules-1RIZ_JZr.d.ts +38 -0
  141. package/dist/styles.css +4037 -0
  142. package/dist/themes/calm.css +42 -0
  143. package/dist/themes/frost.css +40 -0
  144. package/package.json +142 -4
@@ -0,0 +1,815 @@
1
+ 'use client';
2
+ import {
3
+ Caption,
4
+ useElementWidth
5
+ } from "../chunk-3H5X4ZP6.js";
6
+ import {
7
+ Card,
8
+ CardDescription,
9
+ CardHeader,
10
+ CardTitle,
11
+ cx,
12
+ resolveRadius,
13
+ resolveSmoothing
14
+ } from "../chunk-UY2WH5AY.js";
15
+ import {
16
+ useAgentBinding
17
+ } from "../chunk-JCIRUM4W.js";
18
+ import "../chunk-6XC4BC5C.js";
19
+
20
+ // src/charts/xy-charts.tsx
21
+ import { VisXYContainer } from "@unovis/react/containers/xy-container";
22
+ import { VisLine } from "@unovis/react/components/line";
23
+ import { VisArea } from "@unovis/react/components/area";
24
+ import { VisAxis } from "@unovis/react/components/axis";
25
+ import { VisCrosshair } from "@unovis/react/components/crosshair";
26
+ import { VisTooltip } from "@unovis/react/components/tooltip";
27
+ import { VisGroupedBar } from "@unovis/react/components/grouped-bar";
28
+ import { VisStackedBar } from "@unovis/react/components/stacked-bar";
29
+ import { VisScatter } from "@unovis/react/components/scatter";
30
+ import { CurveType } from "@unovis/ts/types/curve";
31
+
32
+ // src/charts/shared.tsx
33
+ import { jsx, jsxs } from "react/jsx-runtime";
34
+ var seriesColor = (i, s) => s?.color ?? `var(--sw-chart-${i % 8 + 1})`;
35
+ function resolveX(data, x) {
36
+ const raw = (d, i) => typeof x === "function" ? x(d, i) : d[x];
37
+ const categorical = data.length > 0 && typeof raw(data[0], 0) === "string";
38
+ const labels = data.map((d, i) => raw(d, i));
39
+ const get = (d, i) => {
40
+ const v = raw(d, i);
41
+ if (categorical) return i;
42
+ return v instanceof Date ? v.getTime() : v;
43
+ };
44
+ const isDate = !categorical && data.length > 0 && raw(data[0], 0) instanceof Date;
45
+ return { get, categorical, isDate, labels };
46
+ }
47
+ function defaultXFormat(categorical, isDate, labels, fmt) {
48
+ return (tick) => {
49
+ if (categorical) {
50
+ const l = labels[Math.round(Number(tick))];
51
+ return l == null ? "" : fmt ? fmt(l) : String(l);
52
+ }
53
+ const v = isDate ? new Date(tick) : tick;
54
+ if (fmt) return fmt(v);
55
+ if (v instanceof Date) return v.toLocaleDateString(void 0, { month: "short", day: "numeric" });
56
+ return compact(Number(v));
57
+ };
58
+ }
59
+ var compact = (n) => new Intl.NumberFormat(void 0, { notation: "compact", maximumFractionDigits: 1 }).format(n);
60
+ function tooltipHtml(d, title, series, yFormat) {
61
+ const rows = series.map((s, i) => {
62
+ const v = Number(d[s.key]);
63
+ return `<div class="sw-tt__row"><span class="sw-tt__swatch" style="background:${seriesColor(i, s)}"></span><span class="sw-tt__name">${esc(s.label ?? s.key)}</span><span class="sw-tt__value">${esc(yFormat ? yFormat(v) : v.toLocaleString())}</span></div>`;
64
+ }).join("");
65
+ return `<div class="sw-tt"><div class="sw-tt__title">${esc(title)}</div>${rows}</div>`;
66
+ }
67
+ var esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
68
+ function Legend({ series, className }) {
69
+ return /* @__PURE__ */ jsx("ul", { "data-sw": "chart-legend", className: cx("sw-legend", className), children: series.map((s, i) => /* @__PURE__ */ jsxs("li", { children: [
70
+ /* @__PURE__ */ jsx("span", { className: "sw-legend__swatch", style: { background: seriesColor(i, s) }, "aria-hidden": true }),
71
+ s.label ?? String(s.key)
72
+ ] }, String(s.key))) });
73
+ }
74
+ function ChartFrame({ name, height, className, label, children }) {
75
+ return /* @__PURE__ */ jsx("div", { "data-sw": "chart", "data-chart": name, role: "img", "aria-label": label, className: cx("sw-chart", className), style: { height }, children });
76
+ }
77
+
78
+ // src/charts/xy-charts.tsx
79
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
80
+ var curveMap = { smooth: CurveType.MonotoneX, linear: CurveType.Linear, step: CurveType.StepAfter };
81
+ function Axes({ p, x }) {
82
+ const { showXAxis = true, showYAxis = true, showGrid = true } = p;
83
+ const n = p.data.length;
84
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
85
+ showXAxis && /* @__PURE__ */ jsx2(
86
+ VisAxis,
87
+ {
88
+ type: "x",
89
+ gridLine: false,
90
+ tickLine: false,
91
+ domainLine: false,
92
+ numTicks: x.categorical ? Math.min(n, 12) : 6,
93
+ tickFormat: defaultXFormat(x.categorical, x.isDate, x.labels, p.xFormat)
94
+ }
95
+ ),
96
+ showYAxis && /* @__PURE__ */ jsx2(VisAxis, { type: "y", gridLine: showGrid, tickLine: false, domainLine: false, numTicks: 4, tickFormat: (t) => p.yFormat ? p.yFormat(Number(t)) : compact(Number(t)) }),
97
+ !showYAxis && showGrid && /* @__PURE__ */ jsx2(VisAxis, { type: "y", gridLine: true, tickLine: false, domainLine: false, tickTextColor: "transparent", numTicks: 4, tickFormat: () => "" })
98
+ ] });
99
+ }
100
+ function Hover({ p, x }) {
101
+ if (p.tooltip === false) return null;
102
+ const fmt = defaultXFormat(x.categorical, x.isDate, x.labels, p.xFormat);
103
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
104
+ /* @__PURE__ */ jsx2(
105
+ VisCrosshair,
106
+ {
107
+ color: (_d, i) => seriesColor(i, p.series[i]),
108
+ template: (d) => tooltipHtml(d, fmt(x.get(d, p.data.indexOf(d))), p.series, p.yFormat)
109
+ }
110
+ ),
111
+ /* @__PURE__ */ jsx2(VisTooltip, {})
112
+ ] });
113
+ }
114
+ var margin = { top: 8, right: 4, bottom: 0, left: 0 };
115
+ function LineChart(p) {
116
+ const x = resolveX(p.data, p.x);
117
+ return /* @__PURE__ */ jsx2(ChartFrame, { name: "line", height: p.height ?? 240, className: p.className, label: p["aria-label"], children: /* @__PURE__ */ jsxs2(VisXYContainer, { data: p.data, height: p.height ?? 240, margin, yDomain: p.yDomain, children: [
118
+ /* @__PURE__ */ jsx2(
119
+ VisLine,
120
+ {
121
+ x: x.get,
122
+ y: p.series.map((s) => (d) => Number(d[s.key])),
123
+ color: p.series.map((s, i) => seriesColor(i, s)),
124
+ curveType: curveMap[p.curve ?? "smooth"],
125
+ lineWidth: p.lineWidth ?? 2
126
+ }
127
+ ),
128
+ /* @__PURE__ */ jsx2(Axes, { p, x }),
129
+ /* @__PURE__ */ jsx2(Hover, { p, x })
130
+ ] }) });
131
+ }
132
+ function AreaChart(p) {
133
+ const x = resolveX(p.data, p.x);
134
+ const colors = p.series.map((s, i) => seriesColor(i, s));
135
+ const ys = p.series.map((s) => (d) => Number(d[s.key]));
136
+ const curve = curveMap[p.curve ?? "smooth"];
137
+ const height = p.height ?? 240;
138
+ return /* @__PURE__ */ jsx2(ChartFrame, { name: "area", height, className: cxStacked(p.className, p.stacked), label: p["aria-label"], children: /* @__PURE__ */ jsxs2(VisXYContainer, { data: p.data, height, margin, yDomain: p.yDomain, children: [
139
+ p.stacked ? /* @__PURE__ */ jsx2(VisArea, { x: x.get, y: ys, color: colors, curveType: curve, opacity: 0.9 }) : ys.map((y, i) => /* @__PURE__ */ jsx2(VisArea, { x: x.get, y, color: colors[i], curveType: curve, opacity: 0.14 }, i)),
140
+ p.line !== false && !p.stacked && /* @__PURE__ */ jsx2(VisLine, { x: x.get, y: ys, color: colors, curveType: curve, lineWidth: 2 }),
141
+ /* @__PURE__ */ jsx2(Axes, { p, x }),
142
+ /* @__PURE__ */ jsx2(Hover, { p, x })
143
+ ] }) });
144
+ }
145
+ var cxStacked = (c, s) => [c, s && "sw-chart--stacked"].filter(Boolean).join(" ");
146
+ function BarChart(p) {
147
+ const x = resolveX(p.data, p.x);
148
+ const colors = p.series.map((s, i) => seriesColor(i, s));
149
+ const ys = p.series.map((s) => (d) => Number(d[s.key]));
150
+ const height = p.height ?? 240;
151
+ const common = { x: x.get, y: ys, color: colors, roundedCorners: p.barRadius ?? 4, orientation: p.orientation ?? "vertical" };
152
+ return /* @__PURE__ */ jsx2(ChartFrame, { name: "bar", height, className: p.className, label: p["aria-label"], children: /* @__PURE__ */ jsxs2(VisXYContainer, { data: p.data, height, margin, yDomain: p.yDomain, children: [
153
+ p.mode === "stacked" ? /* @__PURE__ */ jsx2(VisStackedBar, { ...common, barPadding: 0.35 }) : /* @__PURE__ */ jsx2(VisGroupedBar, { ...common, groupPadding: 0.25, barPadding: 0.08 }),
154
+ /* @__PURE__ */ jsx2(Axes, { p, x }),
155
+ /* @__PURE__ */ jsx2(Hover, { p, x })
156
+ ] }) });
157
+ }
158
+ function ScatterChart(p) {
159
+ const x = resolveX(p.data, p.x);
160
+ const height = p.height ?? 240;
161
+ const series = [{ key: p.y, label: p.label ?? p.y, color: p.color }];
162
+ const sizes = p.size ? p.data.map((d) => Number(d[p.size])) : [];
163
+ const max = sizes.length ? Math.max(...sizes) : 1;
164
+ return /* @__PURE__ */ jsx2(ChartFrame, { name: "scatter", height, className: p.className, label: p["aria-label"], children: /* @__PURE__ */ jsxs2(VisXYContainer, { data: p.data, height, margin, yDomain: p.yDomain, children: [
165
+ /* @__PURE__ */ jsx2(
166
+ VisScatter,
167
+ {
168
+ x: x.get,
169
+ y: (d) => Number(d[p.y]),
170
+ color: seriesColor(0, series[0]),
171
+ size: p.size ? (d) => 6 + 18 * (Number(d[p.size]) / max) : 8
172
+ }
173
+ ),
174
+ /* @__PURE__ */ jsx2(Axes, { p: { ...p, series }, x })
175
+ ] }) });
176
+ }
177
+
178
+ // src/charts/single-charts.tsx
179
+ import { VisSingleContainer } from "@unovis/react/containers/single-container";
180
+ import { VisDonut } from "@unovis/react/components/donut";
181
+
182
+ // src/charts/trend-chart.tsx
183
+ import { useId, useMemo, useRef, useState } from "react";
184
+
185
+ // src/primitives/chart-geometry.ts
186
+ var linear = (d0, d1, r0, r1) => {
187
+ const k = d1 === d0 ? 0 : (r1 - r0) / (d1 - d0);
188
+ return (v) => d1 === d0 ? (r0 + r1) / 2 : r0 + (v - d0) * k;
189
+ };
190
+ function monotonePath(pts) {
191
+ const n = pts.length;
192
+ if (!n) return "";
193
+ if (n === 1) return `M${pts[0].x},${pts[0].y}`;
194
+ if (n === 2) return `M${pts[0].x},${pts[0].y}L${pts[1].x},${pts[1].y}`;
195
+ const dx = [];
196
+ const slope = [];
197
+ for (let i = 0; i < n - 1; i++) {
198
+ dx[i] = pts[i + 1].x - pts[i].x;
199
+ slope[i] = dx[i] ? (pts[i + 1].y - pts[i].y) / dx[i] : 0;
200
+ }
201
+ const t = new Array(n);
202
+ t[0] = slope[0];
203
+ t[n - 1] = slope[n - 2];
204
+ for (let i = 1; i < n - 1; i++) {
205
+ const s0 = slope[i - 1];
206
+ const s1 = slope[i];
207
+ if (s0 * s1 <= 0) t[i] = 0;
208
+ else {
209
+ const p = (s0 * dx[i] + s1 * dx[i - 1]) / (dx[i - 1] + dx[i]);
210
+ t[i] = (Math.sign(s0) + Math.sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p));
211
+ }
212
+ }
213
+ let d = `M${r(pts[0].x)},${r(pts[0].y)}`;
214
+ for (let i = 0; i < n - 1; i++) {
215
+ const h = dx[i] / 3;
216
+ d += `C${r(pts[i].x + h)},${r(pts[i].y + t[i] * h)},${r(pts[i + 1].x - h)},${r(pts[i + 1].y - t[i + 1] * h)},${r(pts[i + 1].x)},${r(pts[i + 1].y)}`;
217
+ }
218
+ return d;
219
+ }
220
+ function linearPath(pts) {
221
+ return pts.map((p, i) => `${i ? "L" : "M"}${r(p.x)},${r(p.y)}`).join("");
222
+ }
223
+ function areaPath(line, pts, baseline) {
224
+ if (!pts.length) return "";
225
+ return `${line}L${r(pts[pts.length - 1].x)},${r(baseline)}L${r(pts[0].x)},${r(baseline)}Z`;
226
+ }
227
+ var r = (v) => Math.round(v * 100) / 100;
228
+ function niceTicks(min, max, count = 3) {
229
+ if (!(isFinite(min) && isFinite(max))) return [];
230
+ if (min === max) return [min];
231
+ const span = max - min;
232
+ const step0 = span / Math.max(1, count);
233
+ const mag = 10 ** Math.floor(Math.log10(step0));
234
+ const err = step0 / mag;
235
+ const step = (err >= 7.5 ? 10 : err >= 3.5 ? 5 : err >= 1.5 ? 2 : 1) * mag;
236
+ const out = [];
237
+ for (let v = Math.ceil(min / step) * step; v <= max + step * 1e-9; v += step) out.push(Math.round(v / step) * step);
238
+ return out;
239
+ }
240
+ function valueDomain(values, { zero = true, pad = 0.08 } = {}) {
241
+ const finite = values.filter((v) => isFinite(v));
242
+ if (!finite.length) return [0, 1];
243
+ let lo = Math.min(...finite);
244
+ let hi = Math.max(...finite);
245
+ if (zero && lo >= 0) lo = 0;
246
+ if (hi === lo) hi = lo + (Math.abs(lo) || 1);
247
+ const span = hi - lo;
248
+ return [zero && lo === 0 ? 0 : lo - span * pad, hi + span * pad];
249
+ }
250
+ var compactNumber = (n) => new Intl.NumberFormat(void 0, { notation: "compact", maximumFractionDigits: Math.abs(n) < 10 ? 1 : 0 }).format(n);
251
+
252
+ // src/charts/trend-chart.tsx
253
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
254
+ var toneVar = {
255
+ chart: "var(--sw-chart-1)",
256
+ neutral: "var(--sw-foreground)",
257
+ success: "var(--sw-success)",
258
+ warning: "var(--sw-warning)",
259
+ danger: "var(--sw-danger)"
260
+ };
261
+ function TrendChart({
262
+ values,
263
+ labels,
264
+ compare,
265
+ seriesLabels = ["Now", "Previous"],
266
+ variant = "area",
267
+ tone = "chart",
268
+ height: heightProp,
269
+ spark = false,
270
+ format = compactNumber,
271
+ threshold,
272
+ markers,
273
+ zero,
274
+ onScrub,
275
+ tooltip,
276
+ incomplete = false,
277
+ live = false,
278
+ color: colorProp,
279
+ className,
280
+ style,
281
+ ...rest
282
+ }) {
283
+ const wrapRef = useRef(null);
284
+ const width = useElementWidth(wrapRef);
285
+ const id = useId().replace(/:/g, "");
286
+ const [hover, setHover] = useState(null);
287
+ const height = heightProp ?? (spark ? 36 : 180);
288
+ const showTip = tooltip ?? !spark;
289
+ const n = values.length;
290
+ const axes = !spark;
291
+ const pad = spark ? { t: 3, r: 0, b: 1, l: 0 } : { t: 10, r: 0, b: 20, l: 0 };
292
+ const innerH = Math.max(1, height - pad.t - pad.b);
293
+ const geo = useMemo(() => {
294
+ const all = [...values, ...compare ?? [], ...threshold ? [threshold.value] : []];
295
+ const [lo, hi] = valueDomain(all, { zero: zero ?? !spark, pad: spark ? 0.12 : 0.1 });
296
+ const w = Math.max(1, width - pad.l - pad.r);
297
+ const bars = variant === "bars";
298
+ const band = bars ? w / Math.max(1, n) : 0;
299
+ const x = bars ? (i) => pad.l + band * (i + 0.5) : linear(0, Math.max(1, n - 1), pad.l, pad.l + w);
300
+ const y = linear(lo, hi, pad.t + innerH, pad.t);
301
+ const pts = values.map((v, i) => ({ x: x(i), y: y(v) }));
302
+ const cpts = (compare ?? []).map((v, i) => ({ x: x(i), y: y(v) }));
303
+ const line = monotonePath(pts);
304
+ const split = incomplete && pts.length > 2;
305
+ return {
306
+ lo,
307
+ hi,
308
+ x,
309
+ y,
310
+ band,
311
+ pts,
312
+ line,
313
+ solid: split ? monotonePath(pts.slice(0, -1)) : line,
314
+ tail: split ? linearPath(pts.slice(-2)) : "",
315
+ area: areaPath(line, pts, y(lo)),
316
+ cline: cpts.length ? monotonePath(cpts) : "",
317
+ ticks: axes ? thinTicks(niceTicks(lo, hi, 3).filter((t) => t > lo), 3) : []
318
+ };
319
+ }, [values, compare, threshold, zero, spark, width, n, variant, innerH, axes, incomplete, pad.l, pad.r, pad.t]);
320
+ const color = colorProp ?? toneVar[tone];
321
+ const decorative = !rest["aria-label"];
322
+ const scrub = (i) => {
323
+ setHover(i);
324
+ onScrub?.(i);
325
+ };
326
+ const indexAt = (clientX) => {
327
+ const box = wrapRef.current?.getBoundingClientRect();
328
+ if (!box || !n) return null;
329
+ const px = clientX - box.left;
330
+ if (variant === "bars") return Math.max(0, Math.min(n - 1, Math.floor((px - pad.l) / Math.max(1, geo.band))));
331
+ let best = 0;
332
+ geo.pts.forEach((p, i) => {
333
+ if (Math.abs(p.x - px) < Math.abs(geo.pts[best].x - px)) best = i;
334
+ });
335
+ return best;
336
+ };
337
+ const onMove = (e) => scrub(indexAt(e.clientX));
338
+ const onKey = (e) => {
339
+ if (!n) return;
340
+ const cur = hover ?? n - 1;
341
+ const next = e.key === "ArrowLeft" ? cur - 1 : e.key === "ArrowRight" ? cur + 1 : e.key === "Home" ? 0 : e.key === "End" ? n - 1 : null;
342
+ if (next == null) return;
343
+ e.preventDefault();
344
+ scrub(Math.max(0, Math.min(n - 1, next)));
345
+ };
346
+ const last = n - 1;
347
+ const active = hover ?? null;
348
+ const ap = active != null ? geo.pts[active] : null;
349
+ const xLabels = axes && labels?.length ? pickLabels(labels.length) : [];
350
+ const tipLeft = ap ? ap.x + 12 + 132 <= width ? ap.x + 12 : Math.max(0, ap.x - 12 - 132) : 0;
351
+ const ready = width > 0;
352
+ return /* @__PURE__ */ jsxs3(
353
+ "div",
354
+ {
355
+ ref: wrapRef,
356
+ "data-sw": "trend-chart",
357
+ "data-variant": variant,
358
+ "data-spark": spark ? "" : void 0,
359
+ "data-scrubbing": active != null ? "" : void 0,
360
+ role: decorative ? void 0 : "img",
361
+ "aria-label": rest["aria-label"],
362
+ "aria-hidden": decorative || void 0,
363
+ tabIndex: decorative || spark && !onScrub ? void 0 : 0,
364
+ className: cx("sw-trend", className),
365
+ style: { height, "--sw-trend-color": color, ...style },
366
+ onPointerMove: onMove,
367
+ onPointerLeave: () => scrub(null),
368
+ onBlur: () => scrub(null),
369
+ onFocus: () => hover == null && n && scrub(last),
370
+ onKeyDown: onKey,
371
+ children: [
372
+ ready && /* @__PURE__ */ jsxs3("svg", { className: "sw-trend__svg", width, height, "aria-hidden": true, children: [
373
+ /* @__PURE__ */ jsxs3("defs", { children: [
374
+ /* @__PURE__ */ jsxs3("linearGradient", { id: `${id}-fill`, x1: "0", y1: "0", x2: "0", y2: "1", children: [
375
+ /* @__PURE__ */ jsx3("stop", { offset: "5%", className: "sw-trend__stop-top" }),
376
+ /* @__PURE__ */ jsx3("stop", { offset: "95%", className: "sw-trend__stop-bottom" })
377
+ ] }),
378
+ ap && /* @__PURE__ */ jsx3("clipPath", { id: `${id}-past`, children: /* @__PURE__ */ jsx3("rect", { x: 0, y: 0, width: variant === "bars" ? 0 : ap.x, height }) })
379
+ ] }),
380
+ geo.ticks.map((t) => /* @__PURE__ */ jsxs3("g", { className: "sw-trend__grid", children: [
381
+ /* @__PURE__ */ jsx3("line", { x1: 0, x2: width, y1: geo.y(t), y2: geo.y(t) }),
382
+ /* @__PURE__ */ jsx3("text", { x: 0, y: geo.y(t) - 4, children: format(t) })
383
+ ] }, t)),
384
+ axes && /* @__PURE__ */ jsx3("line", { className: "sw-trend__baseline", x1: 0, x2: width, y1: geo.y(geo.lo), y2: geo.y(geo.lo) }),
385
+ threshold && /* @__PURE__ */ jsxs3("g", { className: "sw-trend__threshold", children: [
386
+ /* @__PURE__ */ jsx3("line", { x1: 0, x2: width, y1: geo.y(threshold.value), y2: geo.y(threshold.value) }),
387
+ threshold.label && !spark && /* @__PURE__ */ jsx3("text", { x: width, y: geo.y(threshold.value) - 4, textAnchor: "end", children: threshold.label })
388
+ ] }),
389
+ geo.cline && /* @__PURE__ */ jsx3("path", { className: "sw-trend__compare", d: geo.cline }),
390
+ variant === "bars" ? values.map((v, i) => {
391
+ const bw = Math.max(2, Math.min(14, geo.band * 0.56));
392
+ const top = geo.y(Math.max(v, geo.lo));
393
+ const h = Math.max(1, geo.y(geo.lo) - top);
394
+ return /* @__PURE__ */ jsx3(
395
+ "rect",
396
+ {
397
+ className: "sw-trend__bar",
398
+ "data-state": active === i ? "active" : active != null ? "dim" : i === last ? "last" : void 0,
399
+ "data-incomplete": incomplete && i === last ? "" : void 0,
400
+ "data-over": threshold && v > threshold.value ? "" : void 0,
401
+ x: geo.x(i) - bw / 2,
402
+ y: top,
403
+ width: bw,
404
+ height: h,
405
+ rx: Math.min(2, bw / 2)
406
+ },
407
+ i
408
+ );
409
+ }) : /* @__PURE__ */ jsxs3(Fragment2, { children: [
410
+ /* @__PURE__ */ jsxs3("g", { className: "sw-trend__series", "data-dim": ap ? "" : void 0, children: [
411
+ variant === "area" && /* @__PURE__ */ jsx3("path", { className: "sw-trend__area", d: geo.area, fill: `url(#${id}-fill)` }),
412
+ /* @__PURE__ */ jsx3("path", { className: "sw-trend__line", d: geo.solid }),
413
+ geo.tail && /* @__PURE__ */ jsx3("path", { className: "sw-trend__tail", d: geo.tail })
414
+ ] }),
415
+ ap && /* @__PURE__ */ jsxs3("g", { clipPath: `url(#${id}-past)`, "aria-hidden": true, children: [
416
+ variant === "area" && /* @__PURE__ */ jsx3("path", { d: geo.area, fill: `url(#${id}-fill)` }),
417
+ /* @__PURE__ */ jsx3("path", { className: "sw-trend__line", d: geo.solid }),
418
+ geo.tail && /* @__PURE__ */ jsx3("path", { className: "sw-trend__tail", d: geo.tail })
419
+ ] })
420
+ ] }),
421
+ markers?.map((m) => {
422
+ const mx = geo.x(Math.max(0, Math.min(last, m.index)));
423
+ return /* @__PURE__ */ jsxs3("g", { className: "sw-trend__marker", "data-state": active === m.index ? "active" : void 0, children: [
424
+ /* @__PURE__ */ jsx3("line", { x1: mx, x2: mx, y1: pad.t, y2: geo.y(geo.lo) }),
425
+ /* @__PURE__ */ jsx3("circle", { cx: mx, cy: geo.y(geo.lo), r: 2.5 })
426
+ ] }, `${m.index}-${m.label}`);
427
+ }),
428
+ xLabels.map((i) => /* @__PURE__ */ jsx3("text", { className: "sw-trend__xlabel", x: geo.x(i), y: height - 5, textAnchor: i === 0 ? "start" : i === labels.length - 1 ? "end" : "middle", children: labels[i] }, i)),
429
+ variant !== "bars" && n > 0 && active == null && /* @__PURE__ */ jsxs3("g", { className: "sw-trend__end", children: [
430
+ live && /* @__PURE__ */ jsx3("circle", { className: "sw-trend__halo", cx: geo.pts[last].x, cy: geo.pts[last].y, r: spark ? 5 : 6 }),
431
+ /* @__PURE__ */ jsx3("circle", { className: "sw-trend__dot", cx: geo.pts[last].x, cy: geo.pts[last].y, r: spark ? 2.5 : 3.5 })
432
+ ] }),
433
+ ap && /* @__PURE__ */ jsxs3("g", { className: "sw-trend__cursor", children: [
434
+ /* @__PURE__ */ jsx3("line", { x1: ap.x, x2: ap.x, y1: pad.t, y2: geo.y(geo.lo) }),
435
+ variant !== "bars" && compare?.[active] != null && /* @__PURE__ */ jsx3("circle", { className: "sw-trend__cursor-compare", cx: ap.x, cy: geo.y(compare[active]), r: 2.5 }),
436
+ variant !== "bars" && /* @__PURE__ */ jsx3("circle", { className: "sw-trend__dot", cx: ap.x, cy: ap.y, r: spark ? 2.5 : 3.5 })
437
+ ] })
438
+ ] }),
439
+ showTip && ap && active != null && /* @__PURE__ */ jsxs3("div", { className: "sw-trend__tip", style: { left: tipLeft }, "aria-hidden": true, children: [
440
+ labels?.[active] && /* @__PURE__ */ jsx3("div", { className: "sw-trend__tip-title", children: labels[active] }),
441
+ /* @__PURE__ */ jsxs3("div", { className: "sw-trend__tip-row", children: [
442
+ /* @__PURE__ */ jsx3("span", { className: "sw-trend__swatch" }),
443
+ /* @__PURE__ */ jsx3("span", { children: seriesLabels[0] }),
444
+ /* @__PURE__ */ jsx3("b", { children: format(values[active]) })
445
+ ] }),
446
+ compare?.[active] != null && /* @__PURE__ */ jsxs3("div", { className: "sw-trend__tip-row", "data-muted": "", children: [
447
+ /* @__PURE__ */ jsx3("span", { className: "sw-trend__swatch", "data-compare": "" }),
448
+ /* @__PURE__ */ jsx3("span", { children: seriesLabels[1] }),
449
+ /* @__PURE__ */ jsx3("b", { children: format(compare[active]) })
450
+ ] }),
451
+ markers?.filter((m) => m.index === active).map((m) => /* @__PURE__ */ jsx3("div", { className: "sw-trend__tip-event", children: m.label }, m.label))
452
+ ] }),
453
+ /* @__PURE__ */ jsx3("span", { className: "sw-sr-only", "aria-live": "polite", children: active != null ? `${labels?.[active] ?? `Point ${active + 1}`}: ${format(values[active])}` : "" })
454
+ ]
455
+ }
456
+ );
457
+ }
458
+ function thinTicks(ticks, max) {
459
+ let out = ticks;
460
+ while (out.length > max) out = out.filter((_, i) => (out.length - 1 - i) % 2 === 0);
461
+ return out;
462
+ }
463
+ function pickLabels(count) {
464
+ if (count <= 1) return [0];
465
+ const slots = Math.min(5, count);
466
+ const out = /* @__PURE__ */ new Set();
467
+ for (let k = 0; k < slots; k++) out.add(Math.round(k * (count - 1) / (slots - 1)));
468
+ return [...out];
469
+ }
470
+
471
+ // src/charts/single-charts.tsx
472
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
473
+ function DonutChart({ data, centralLabel, centralSubLabel, arcWidth = 18, height = 200, className, ...a }) {
474
+ return /* @__PURE__ */ jsxs4(ChartFrame, { name: "donut", height, className, label: a["aria-label"], children: [
475
+ /* @__PURE__ */ jsx4(VisSingleContainer, { data, height, children: /* @__PURE__ */ jsx4(
476
+ VisDonut,
477
+ {
478
+ value: (d) => d.value,
479
+ color: (d, i) => seriesColor(i, d),
480
+ arcWidth,
481
+ padAngle: 0.02,
482
+ cornerRadius: 3,
483
+ showBackground: true
484
+ }
485
+ ) }),
486
+ (centralLabel || centralSubLabel) && /* @__PURE__ */ jsx4("div", { className: "sw-donut__center", style: { "--sw-donut-arc-width": `${arcWidth}px` }, "aria-hidden": true, children: /* @__PURE__ */ jsxs4("div", { className: "sw-donut__labels", children: [
487
+ centralLabel && /* @__PURE__ */ jsx4("span", { className: "sw-donut__value", children: centralLabel }),
488
+ centralSubLabel && /* @__PURE__ */ jsx4(Caption, { className: "sw-donut__caption", children: centralSubLabel })
489
+ ] }) })
490
+ ] });
491
+ }
492
+ function Sparkline({ data, color, height = 36, area = true, className, ...a }) {
493
+ return /* @__PURE__ */ jsx4(TrendChart, { spark: true, values: data, color, tone: "chart", height, variant: area ? "area" : "line", className, "aria-label": a["aria-label"] });
494
+ }
495
+
496
+ // src/charts/bar-list.tsx
497
+ import { useRef as useRef2 } from "react";
498
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
499
+ function BarList({ items, format = compactNumber, max, sorted = true, onItemAction, className, ...rest }) {
500
+ const ref = useRef2(null);
501
+ const rows = sorted ? [...items].sort((a, b) => b.value - a.value) : items;
502
+ const top = max ?? Math.max(0, ...rows.map((r2) => r2.value));
503
+ useAgentBinding(ref, {
504
+ kind: "bar-list",
505
+ label: rest["aria-label"],
506
+ state: () => ({ items: rows.map((r2) => ({ id: r2.id, label: r2.label, value: r2.value })) }),
507
+ actions: onItemAction ? { open: (id) => onItemAction(id) } : {}
508
+ });
509
+ return /* @__PURE__ */ jsx5("ul", { ref, "data-sw": "bar-list", className: cx("sw-bar-list", className), ...rest, children: rows.map((r2, i) => {
510
+ const pct = top > 0 ? Math.max(0, Math.min(1, r2.value / top)) : 0;
511
+ const inner = /* @__PURE__ */ jsxs5(Fragment3, { children: [
512
+ /* @__PURE__ */ jsx5("span", { className: "sw-bar-list__bar", style: { "--sw-bar": pct }, "aria-hidden": true }),
513
+ r2.icon && /* @__PURE__ */ jsx5("span", { className: "sw-bar-list__icon", "aria-hidden": true, children: r2.icon }),
514
+ /* @__PURE__ */ jsx5("span", { className: "sw-bar-list__label", children: r2.label }),
515
+ r2.meta != null && /* @__PURE__ */ jsx5("span", { className: "sw-bar-list__meta", children: r2.meta }),
516
+ /* @__PURE__ */ jsx5("span", { className: "sw-bar-list__value", children: format(r2.value) })
517
+ ] });
518
+ return /* @__PURE__ */ jsx5("li", { "data-sw": "bar-list-row", "data-value": r2.id, "data-rank": i + 1, className: "sw-bar-list__item", children: r2.href ? /* @__PURE__ */ jsx5("a", { className: "sw-bar-list__row", href: r2.href, children: inner }) : onItemAction ? /* @__PURE__ */ jsx5("button", { type: "button", className: "sw-bar-list__row", onClick: () => onItemAction(r2.id), children: inner }) : /* @__PURE__ */ jsx5("div", { className: "sw-bar-list__row", children: inner }) }, r2.id);
519
+ }) });
520
+ }
521
+
522
+ // src/charts/tracker.tsx
523
+ import { useRef as useRef3, useState as useState2 } from "react";
524
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
525
+ function Tracker({ items, height = 24, className, style, ...rest }) {
526
+ const [active, setActive] = useState2(null);
527
+ const ref = useRef3(null);
528
+ const onKey = (e) => {
529
+ const cur = active ?? items.length - 1;
530
+ const next = e.key === "ArrowLeft" ? cur - 1 : e.key === "ArrowRight" ? cur + 1 : e.key === "Home" ? 0 : e.key === "End" ? items.length - 1 : null;
531
+ if (next == null) return;
532
+ e.preventDefault();
533
+ setActive(Math.max(0, Math.min(items.length - 1, next)));
534
+ };
535
+ const tip = active != null ? items[active] : null;
536
+ const left = active != null && items.length ? (active + 0.5) / items.length * 100 : 0;
537
+ return /* @__PURE__ */ jsxs6(
538
+ "div",
539
+ {
540
+ ref,
541
+ role: "img",
542
+ tabIndex: 0,
543
+ "data-sw": "tracker",
544
+ className: cx("sw-tracker", className),
545
+ style: { ...style },
546
+ onKeyDown: onKey,
547
+ onFocus: () => active == null && setActive(items.length - 1),
548
+ onBlur: () => setActive(null),
549
+ onPointerLeave: () => setActive(null),
550
+ ...rest,
551
+ children: [
552
+ /* @__PURE__ */ jsx6("div", { className: "sw-tracker__ticks", style: { height }, children: items.map((it, i) => /* @__PURE__ */ jsx6(
553
+ "span",
554
+ {
555
+ className: "sw-tracker__tick",
556
+ "data-status": it.status,
557
+ "data-active": active === i ? "" : void 0,
558
+ onPointerEnter: () => setActive(i)
559
+ },
560
+ i
561
+ )) }),
562
+ tip && /* @__PURE__ */ jsxs6("div", { className: "sw-tracker__tip", style: { left: `clamp(60px, ${left}%, calc(100% - 60px))` }, "aria-hidden": true, children: [
563
+ /* @__PURE__ */ jsx6("span", { className: "sw-tracker__swatch", "data-status": tip.status }),
564
+ tip.label
565
+ ] }),
566
+ /* @__PURE__ */ jsx6("span", { className: "sw-sr-only", "aria-live": "polite", children: tip?.label ?? "" })
567
+ ]
568
+ }
569
+ );
570
+ }
571
+
572
+ // src/charts/treemap.tsx
573
+ import { useEffect, useLayoutEffect, useMemo as useMemo2, useRef as useRef4, useState as useState3 } from "react";
574
+ import { hierarchy, treemap as d3Treemap } from "d3-hierarchy";
575
+ import { getSvgPath } from "figma-squircle";
576
+ import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
577
+ var read = (d, get) => typeof get === "function" ? get(d) : d[get];
578
+ var HEADER = 28;
579
+ var SIZES = {
580
+ lg: { pad: 12, name: 20, nameLine: 24, value: 13, valueLine: 18 },
581
+ md: { pad: 8, name: 14, nameLine: 18, value: 12, valueLine: 16 },
582
+ sm: { pad: 6, name: 12, nameLine: 15, value: 11, valueLine: 14 }
583
+ };
584
+ var textWidth = (s, px) => s.length * px * 0.58;
585
+ function fitLeaf(w, h, value) {
586
+ const size = w >= 180 && h >= 96 ? "lg" : w >= 88 && h >= 44 ? "md" : w >= 44 && h >= 26 ? "sm" : null;
587
+ if (!size) return null;
588
+ const s = SIZES[size];
589
+ const room = h - s.pad * 2;
590
+ const inner = w - s.pad * 2;
591
+ const showValue = room >= s.nameLine + s.valueLine && textWidth(value, s.value) <= inner;
592
+ const lines = inner < 72 ? 1 : Math.max(1, Math.floor((room - (showValue ? s.valueLine : 0)) / s.nameLine));
593
+ return { size, lines, showValue };
594
+ }
595
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
596
+ function Treemap({
597
+ data,
598
+ value,
599
+ label,
600
+ groupBy,
601
+ groups,
602
+ height = 320,
603
+ valueFormat = compact,
604
+ radius = "sm",
605
+ gap = 4,
606
+ tooltip = true,
607
+ onTileClick,
608
+ className,
609
+ ...a
610
+ }) {
611
+ const ref = useRef4(null);
612
+ const [width, setWidth] = useState3(0);
613
+ const [tip, setTip] = useState3(null);
614
+ useIsoLayoutEffect(() => {
615
+ const el = ref.current;
616
+ if (!el) return;
617
+ setWidth(el.clientWidth);
618
+ const ro = new ResizeObserver(() => setWidth(el.clientWidth));
619
+ ro.observe(el);
620
+ return () => ro.disconnect();
621
+ }, []);
622
+ const R = resolveRadius(radius, "sm");
623
+ const smoothing = resolveSmoothing(void 0);
624
+ const { leaves, parents, total } = useMemo2(() => {
625
+ const empty = { leaves: [], parents: [], total: 0 };
626
+ if (width <= 0 || !data.length) return empty;
627
+ let root;
628
+ if (groupBy) {
629
+ const order = /* @__PURE__ */ new Map();
630
+ groups?.forEach((g, i) => order.set(g.key, { key: g.key, color: seriesColor(i, g), children: [] }));
631
+ for (const d of data) {
632
+ const k = String(read(d, groupBy));
633
+ if (!order.has(k)) order.set(k, { key: k, color: seriesColor(order.size), children: [] });
634
+ const g = order.get(k);
635
+ g.children.push({ key: String(read(d, label)), datum: d, color: g.color });
636
+ }
637
+ root = { key: "", color: "", children: [...order.values()].filter((g) => g.children.length) };
638
+ } else {
639
+ root = { key: "", color: "", children: data.map((d) => ({ key: String(read(d, label)), datum: d, color: seriesColor(0) })) };
640
+ }
641
+ const h = hierarchy(root, (n) => n.children).sum((n) => n.datum ? Math.max(0, Number(read(n.datum, value)) || 0) : 0).sort((x, y) => (y.value ?? 0) - (x.value ?? 0));
642
+ const laid = d3Treemap().size([width, height]).round(true).paddingInner(gap).paddingTop((n) => n.depth === 1 ? HEADER : 0).paddingRight((n) => n.depth === 1 ? gap : 0).paddingBottom((n) => n.depth === 1 ? gap : 0).paddingLeft((n) => n.depth === 1 ? gap : 0)(h);
643
+ const all = laid.descendants().filter((n) => n.depth > 0 && n.x1 - n.x0 >= 1 && n.y1 - n.y0 >= 1);
644
+ return { leaves: all.filter((n) => !n.children), parents: all.filter((n) => n.children), total: laid.value ?? 0 };
645
+ }, [data, value, label, groupBy, groups, width, height, gap]);
646
+ const labelOf = (key) => groups?.find((g) => g.key === key)?.label ?? key;
647
+ const fit = (r2, n) => Math.max(0, Math.min(r2, (n.x1 - n.x0) / 2, (n.y1 - n.y0) / 2));
648
+ const leafRadius = (n) => fit(n.parent && n.depth > 1 ? Math.max(2, fit(R, n.parent) - gap) : R, n);
649
+ const path = (n, r2) => getSvgPath({ width: n.x1 - n.x0, height: n.y1 - n.y0, cornerRadius: r2, cornerSmoothing: smoothing, preserveSmoothing: true });
650
+ const groupMax = /* @__PURE__ */ new Map();
651
+ for (const n of leaves) groupMax.set(n.parent, Math.max(groupMax.get(n.parent) ?? 0, n.value ?? 0));
652
+ const strength = (n) => {
653
+ const max = groupMax.get(n.parent) || 1;
654
+ return `${Math.round(24 + 22 * Math.sqrt((n.value ?? 0) / max))}%`;
655
+ };
656
+ const interactive = !!onTileClick;
657
+ const active = tip ? leaves[tip.i] : void 0;
658
+ const showTip = (i, x, y) => tooltip && setTip({ i, x, y });
659
+ return /* @__PURE__ */ jsxs7(
660
+ "div",
661
+ {
662
+ ref,
663
+ "data-sw": "chart",
664
+ "data-chart": "treemap",
665
+ "data-total": total,
666
+ role: interactive ? "figure" : "img",
667
+ "aria-label": a["aria-label"],
668
+ className: cx("sw-chart sw-treemap", className),
669
+ style: { height },
670
+ onPointerLeave: () => setTip(null),
671
+ children: [
672
+ width > 0 && /* @__PURE__ */ jsxs7("svg", { className: "sw-treemap__svg", width, height, "aria-hidden": true, children: [
673
+ parents.map((n) => /* @__PURE__ */ jsx7(
674
+ "path",
675
+ {
676
+ className: "sw-treemap__group",
677
+ transform: `translate(${n.x0},${n.y0})`,
678
+ d: path(n, fit(R, n)),
679
+ style: { "--_c": n.data.color }
680
+ },
681
+ `g-${n.data.key}`
682
+ )),
683
+ leaves.map((n, i) => /* @__PURE__ */ jsx7(
684
+ "path",
685
+ {
686
+ className: "sw-treemap__tile",
687
+ "data-active": active === n ? "" : void 0,
688
+ transform: `translate(${n.x0},${n.y0})`,
689
+ d: path(n, leafRadius(n)),
690
+ style: { "--_c": n.data.color, "--_p": strength(n) }
691
+ },
692
+ `l-${n.parent?.data.key}-${n.data.key}-${i}`
693
+ ))
694
+ ] }),
695
+ parents.map((n) => {
696
+ const w = n.x1 - n.x0;
697
+ const v = valueFormat(n.value ?? 0);
698
+ if (w < 48) return null;
699
+ return /* @__PURE__ */ jsxs7(
700
+ "div",
701
+ {
702
+ className: "sw-treemap__header",
703
+ style: { left: n.x0, top: n.y0, width: w, height: HEADER, paddingInline: gap + 8 },
704
+ "aria-hidden": true,
705
+ children: [
706
+ /* @__PURE__ */ jsx7("span", { className: "sw-treemap__swatch", style: { background: n.data.color } }),
707
+ /* @__PURE__ */ jsx7("span", { className: "sw-treemap__group-name", children: labelOf(n.data.key) }),
708
+ textWidth(v, 12) + 56 < w && /* @__PURE__ */ jsx7("span", { className: "sw-treemap__group-value", children: v })
709
+ ]
710
+ },
711
+ `gh-${n.data.key}`
712
+ );
713
+ }),
714
+ leaves.map((n, i) => {
715
+ const w = n.x1 - n.x0;
716
+ const h = n.y1 - n.y0;
717
+ const v = valueFormat(n.value ?? 0);
718
+ const f = fitLeaf(w, h, v);
719
+ const group = n.depth > 1 ? n.parent.data.key : void 0;
720
+ const Tag = interactive ? "button" : "div";
721
+ return /* @__PURE__ */ jsx7(
722
+ Tag,
723
+ {
724
+ type: interactive ? "button" : void 0,
725
+ className: "sw-treemap__leaf",
726
+ "data-tile": n.data.key,
727
+ "data-group": group,
728
+ "data-value": n.value,
729
+ "data-size": f?.size,
730
+ "aria-label": interactive ? `${n.data.key}, ${v}${group ? `, ${labelOf(group)}` : ""}` : void 0,
731
+ "aria-hidden": interactive ? void 0 : true,
732
+ style: { left: n.x0, top: n.y0, width: w, height: h, padding: f ? SIZES[f.size].pad : 0, borderRadius: leafRadius(n) },
733
+ onPointerMove: (e) => {
734
+ const box = ref.current.getBoundingClientRect();
735
+ showTip(i, e.clientX - box.left, e.clientY - box.top);
736
+ },
737
+ onFocus: () => showTip(i, n.x0 + w / 2, n.y0 + Math.min(h / 2, 24)),
738
+ onBlur: () => setTip(null),
739
+ onClick: interactive ? () => onTileClick(n.data.datum) : void 0,
740
+ children: f && /* @__PURE__ */ jsxs7(Fragment4, { children: [
741
+ /* @__PURE__ */ jsx7("span", { className: "sw-treemap__name", style: { "--_lines": f.lines }, "data-lines": f.lines === 1 ? "one" : void 0, children: n.data.key }),
742
+ f.showValue && /* @__PURE__ */ jsx7("span", { className: "sw-treemap__value", children: v })
743
+ ] })
744
+ },
745
+ `lt-${group}-${n.data.key}-${i}`
746
+ );
747
+ }),
748
+ tip && active && /* @__PURE__ */ jsx7(
749
+ "div",
750
+ {
751
+ className: "sw-treemap__tip",
752
+ role: "presentation",
753
+ style: {
754
+ left: tip.x,
755
+ top: tip.y,
756
+ transform: `translate(${tip.x > width - 240 ? "calc(-100% - 12px)" : "12px"}, ${tip.y > height - 96 ? "calc(-100% - 12px)" : "12px"})`
757
+ },
758
+ children: /* @__PURE__ */ jsxs7("div", { className: "sw-tt", children: [
759
+ active.depth > 1 && /* @__PURE__ */ jsx7("div", { className: "sw-tt__title", children: labelOf(active.parent.data.key) }),
760
+ /* @__PURE__ */ jsxs7("div", { className: "sw-tt__row", children: [
761
+ /* @__PURE__ */ jsx7("span", { className: "sw-tt__swatch", style: { background: active.data.color } }),
762
+ /* @__PURE__ */ jsx7("span", { className: "sw-tt__name", children: active.data.key }),
763
+ /* @__PURE__ */ jsx7("span", { className: "sw-tt__value", children: valueFormat(active.value ?? 0) })
764
+ ] }),
765
+ total > 0 && /* @__PURE__ */ jsxs7("div", { className: "sw-treemap__share", children: [
766
+ new Intl.NumberFormat(void 0, { style: "percent", maximumFractionDigits: 1 }).format((active.value ?? 0) / total),
767
+ " of total"
768
+ ] })
769
+ ] })
770
+ }
771
+ )
772
+ ]
773
+ }
774
+ );
775
+ }
776
+
777
+ // src/charts/chart-card.tsx
778
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
779
+ function ChartCard({ title, description, value, legend, actions, children, className, ...rest }) {
780
+ return /* @__PURE__ */ jsxs8(Card, { "data-sw": "chart-card", className: cx("sw-chart-card", className), ...rest, children: [
781
+ /* @__PURE__ */ jsxs8(CardHeader, { className: "sw-chart-card__header", children: [
782
+ /* @__PURE__ */ jsxs8("div", { children: [
783
+ /* @__PURE__ */ jsx8(CardTitle, { children: title }),
784
+ description && /* @__PURE__ */ jsx8(CardDescription, { children: description })
785
+ ] }),
786
+ (value || actions) && /* @__PURE__ */ jsxs8("div", { className: "sw-chart-card__aside", children: [
787
+ value && /* @__PURE__ */ jsx8("span", { className: "sw-chart-card__value", children: value }),
788
+ actions
789
+ ] })
790
+ ] }),
791
+ children,
792
+ legend && /* @__PURE__ */ jsx8(Legend, { series: legend })
793
+ ] });
794
+ }
795
+
796
+ // src/charts/surface.tsx
797
+ import { jsx as jsx9 } from "react/jsx-runtime";
798
+ function ChartSurface({ name = "custom", role = "figure", className, children, ...rest }) {
799
+ return /* @__PURE__ */ jsx9("div", { "data-sw": "chart", "data-chart": name, role, className: cx("sw-chart", className), ...rest, children });
800
+ }
801
+ export {
802
+ AreaChart,
803
+ BarChart,
804
+ BarList,
805
+ ChartCard,
806
+ ChartSurface,
807
+ DonutChart,
808
+ Legend,
809
+ LineChart,
810
+ ScatterChart,
811
+ Sparkline,
812
+ Tracker,
813
+ Treemap,
814
+ TrendChart
815
+ };