@luxalgo/vela-ui 0.0.0-stage → 0.2.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 (269) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +28 -0
  4. package/README.md +86 -3
  5. package/cli/engine.mjs +282 -0
  6. package/cli/index.mjs +154 -0
  7. package/dist/badge.d.ts +26 -0
  8. package/dist/badge.js +44 -0
  9. package/dist/bar-chart.d.ts +40 -0
  10. package/dist/bar-chart.js +105 -0
  11. package/dist/button.d.ts +55 -0
  12. package/dist/button.js +11 -0
  13. package/dist/calendar.d.ts +24 -0
  14. package/dist/calendar.js +1 -0
  15. package/dist/callout-bubble.d.ts +103 -0
  16. package/dist/callout-bubble.js +177 -0
  17. package/dist/chart.d.ts +30 -0
  18. package/dist/chart.js +1 -0
  19. package/dist/checkbox.d.ts +60 -0
  20. package/dist/checkbox.js +12 -0
  21. package/dist/chunk-2GQIZM5Z.js +28 -0
  22. package/dist/chunk-3Q32K4PE.js +85 -0
  23. package/dist/chunk-6QCILIT2.js +52 -0
  24. package/dist/chunk-7VMN7NKJ.js +133 -0
  25. package/dist/chunk-A2FJ7Y7D.js +55 -0
  26. package/dist/chunk-A72NWYNP.js +26 -0
  27. package/dist/chunk-B5ZSRUDQ.js +227 -0
  28. package/dist/chunk-BXMWQIBO.js +66 -0
  29. package/dist/chunk-C3ICYMI3.js +25 -0
  30. package/dist/chunk-CC3DDNFC.js +117 -0
  31. package/dist/chunk-E2FE6V2N.js +81 -0
  32. package/dist/chunk-FN2BUFNM.js +10 -0
  33. package/dist/chunk-FVH6L7FM.js +18 -0
  34. package/dist/chunk-G7IQLY3A.js +183 -0
  35. package/dist/chunk-GVRX3UAV.js +82 -0
  36. package/dist/chunk-J2QJATCD.js +12 -0
  37. package/dist/chunk-LZWZV2ZS.js +18 -0
  38. package/dist/chunk-MJ4RUGX7.js +403 -0
  39. package/dist/chunk-MMTMOV6R.js +31 -0
  40. package/dist/chunk-P4MTEMT7.js +23 -0
  41. package/dist/chunk-Q6WTDVH6.js +31 -0
  42. package/dist/chunk-S7USVSYP.js +50 -0
  43. package/dist/chunk-TAKSIV57.js +90 -0
  44. package/dist/chunk-U3EH42YY.js +72 -0
  45. package/dist/chunk-V2Q4MRMS.js +573 -0
  46. package/dist/chunk-VMCR3S2A.js +22 -0
  47. package/dist/chunk-WBGSYCV2.js +101 -0
  48. package/dist/chunk-WGULXRWD.js +351 -0
  49. package/dist/chunk-WXH3EFV5.js +219 -0
  50. package/dist/chunk-X66RJAIS.js +14 -0
  51. package/dist/chunk-XBEL4K33.js +142 -0
  52. package/dist/chunk-Z5PINFQO.js +280 -0
  53. package/dist/collapsible.d.ts +49 -0
  54. package/dist/collapsible.js +106 -0
  55. package/dist/color-picker.d.ts +103 -0
  56. package/dist/color-picker.js +19 -0
  57. package/dist/color.d.ts +24 -0
  58. package/dist/color.js +1 -0
  59. package/dist/context-menu.d.ts +72 -0
  60. package/dist/context-menu.js +161 -0
  61. package/dist/css.d.ts +17 -0
  62. package/dist/css.js +4 -0
  63. package/dist/data-table.d.ts +40 -0
  64. package/dist/data-table.js +88 -0
  65. package/dist/date-picker.d.ts +90 -0
  66. package/dist/date-picker.js +257 -0
  67. package/dist/define-D5u3F5Dj.d.ts +21 -0
  68. package/dist/dialog.d.ts +89 -0
  69. package/dist/dialog.js +258 -0
  70. package/dist/dispose.d.ts +9 -0
  71. package/dist/dispose.js +2 -0
  72. package/dist/donut.d.ts +27 -0
  73. package/dist/donut.js +67 -0
  74. package/dist/drawer.d.ts +119 -0
  75. package/dist/drawer.js +326 -0
  76. package/dist/dropdown-menu.d.ts +114 -0
  77. package/dist/dropdown-menu.js +18 -0
  78. package/dist/empty.d.ts +21 -0
  79. package/dist/empty.js +38 -0
  80. package/dist/field.d.ts +147 -0
  81. package/dist/field.js +328 -0
  82. package/dist/glyph-select.d.ts +57 -0
  83. package/dist/glyph-select.js +17 -0
  84. package/dist/h-Bl37qUis.d.ts +24 -0
  85. package/dist/headless.d.ts +6 -0
  86. package/dist/headless.js +9 -0
  87. package/dist/hover-card.d.ts +43 -0
  88. package/dist/hover-card.js +97 -0
  89. package/dist/i18n.d.ts +20 -0
  90. package/dist/i18n.js +1 -0
  91. package/dist/icons.d.ts +20 -0
  92. package/dist/icons.js +2 -0
  93. package/dist/index.d.ts +51 -0
  94. package/dist/index.js +13 -0
  95. package/dist/input-group.d.ts +57 -0
  96. package/dist/input-group.js +87 -0
  97. package/dist/input.d.ts +54 -0
  98. package/dist/input.js +9 -0
  99. package/dist/item.d.ts +72 -0
  100. package/dist/item.js +131 -0
  101. package/dist/kbd.d.ts +19 -0
  102. package/dist/kbd.js +8 -0
  103. package/dist/kit-text.d.ts +8 -0
  104. package/dist/kit-text.js +2 -0
  105. package/dist/line-chart.d.ts +32 -0
  106. package/dist/line-chart.js +120 -0
  107. package/dist/manifest.json +4508 -0
  108. package/dist/month-grid.d.ts +45 -0
  109. package/dist/month-grid.js +157 -0
  110. package/dist/number-input.d.ts +99 -0
  111. package/dist/number-input.js +14 -0
  112. package/dist/page.d.ts +7 -0
  113. package/dist/page.js +1 -0
  114. package/dist/palette.d.ts +55 -0
  115. package/dist/palette.js +1 -0
  116. package/dist/placement.d.ts +98 -0
  117. package/dist/placement.js +1 -0
  118. package/dist/popover.d.ts +107 -0
  119. package/dist/popover.js +15 -0
  120. package/dist/scatter-chart.d.ts +32 -0
  121. package/dist/scatter-chart.js +121 -0
  122. package/dist/select.d.ts +112 -0
  123. package/dist/select.js +19 -0
  124. package/dist/slider.d.ts +46 -0
  125. package/dist/slider.js +111 -0
  126. package/dist/sort-button.d.ts +41 -0
  127. package/dist/sort-button.js +88 -0
  128. package/dist/sparkline.d.ts +22 -0
  129. package/dist/sparkline.js +72 -0
  130. package/dist/stat.d.ts +29 -0
  131. package/dist/stat.js +41 -0
  132. package/dist/styles.d.ts +22 -0
  133. package/dist/styles.js +2 -0
  134. package/dist/surface-events.d.ts +17 -0
  135. package/dist/surface-events.js +1 -0
  136. package/dist/surface-exit.d.ts +25 -0
  137. package/dist/surface-exit.js +1 -0
  138. package/dist/switch.d.ts +54 -0
  139. package/dist/switch.js +92 -0
  140. package/dist/t.d.ts +89 -0
  141. package/dist/t.js +1 -0
  142. package/dist/tabs.d.ts +65 -0
  143. package/dist/tabs.js +155 -0
  144. package/dist/text-area.d.ts +54 -0
  145. package/dist/text-area.js +9 -0
  146. package/dist/theme.d.ts +199 -0
  147. package/dist/theme.js +8 -0
  148. package/dist/theme.schema.json +1994 -0
  149. package/dist/themes/dark.css +3 -0
  150. package/dist/themes/light.css +3 -0
  151. package/dist/toggle-group.d.ts +56 -0
  152. package/dist/toggle-group.js +130 -0
  153. package/dist/tokens.d.ts +16 -0
  154. package/dist/tokens.js +3 -0
  155. package/dist/tooltip.d.ts +47 -0
  156. package/dist/tooltip.js +74 -0
  157. package/dist/variants-B4stUBnY.d.ts +16 -0
  158. package/dist/zag.d.ts +19 -0
  159. package/dist/zag.js +2 -0
  160. package/docs/theming.md +217 -0
  161. package/docs/what-to-change.md +20 -0
  162. package/docs/writing-a-component.md +250 -0
  163. package/llms.txt +71 -0
  164. package/package.json +90 -6
  165. package/registry/badge.ts +119 -0
  166. package/registry/bar-chart.ts +215 -0
  167. package/registry/button.ts +379 -0
  168. package/registry/callout-bubble.ts +347 -0
  169. package/registry/checkbox.ts +234 -0
  170. package/registry/collapsible.ts +271 -0
  171. package/registry/color-picker.ts +582 -0
  172. package/registry/context-menu.ts +208 -0
  173. package/registry/data-table.ts +215 -0
  174. package/registry/date-picker.ts +483 -0
  175. package/registry/dialog.ts +535 -0
  176. package/registry/donut.ts +145 -0
  177. package/registry/drawer.ts +636 -0
  178. package/registry/dropdown-menu.ts +762 -0
  179. package/registry/empty.ts +91 -0
  180. package/registry/field.ts +585 -0
  181. package/registry/glyph-select.ts +268 -0
  182. package/registry/hover-card.ts +222 -0
  183. package/registry/input-group.ts +229 -0
  184. package/registry/input.ts +181 -0
  185. package/registry/item.ts +376 -0
  186. package/registry/kbd.ts +64 -0
  187. package/registry/line-chart.ts +218 -0
  188. package/registry/month-grid.ts +328 -0
  189. package/registry/number-input.ts +443 -0
  190. package/registry/popover.ts +368 -0
  191. package/registry/scatter-chart.ts +221 -0
  192. package/registry/select.ts +620 -0
  193. package/registry/slider.ts +259 -0
  194. package/registry/sort-button.ts +189 -0
  195. package/registry/sparkline.ts +114 -0
  196. package/registry/stat.ts +96 -0
  197. package/registry/switch.ts +205 -0
  198. package/registry/tabs.ts +426 -0
  199. package/registry/text-area.ts +186 -0
  200. package/registry/toggle-group.ts +295 -0
  201. package/registry/tooltip.ts +156 -0
  202. package/skills/theming-vela-ui/SKILL.md +137 -0
  203. package/skills/using-vela-ui-components/SKILL.md +137 -0
  204. package/skills/writing-vela-ui-components/SKILL.md +163 -0
  205. package/src/components/badge.ts +119 -0
  206. package/src/components/bar-chart.ts +215 -0
  207. package/src/components/button.ts +379 -0
  208. package/src/components/callout-bubble.ts +347 -0
  209. package/src/components/checkbox.ts +234 -0
  210. package/src/components/collapsible.ts +271 -0
  211. package/src/components/color-picker.ts +582 -0
  212. package/src/components/context-menu.ts +208 -0
  213. package/src/components/data-table.ts +215 -0
  214. package/src/components/date-picker.ts +483 -0
  215. package/src/components/dialog.ts +535 -0
  216. package/src/components/donut.ts +145 -0
  217. package/src/components/drawer.ts +636 -0
  218. package/src/components/dropdown-menu.ts +762 -0
  219. package/src/components/empty.ts +91 -0
  220. package/src/components/field.ts +585 -0
  221. package/src/components/glyph-select.ts +268 -0
  222. package/src/components/hover-card.ts +222 -0
  223. package/src/components/input-group.ts +229 -0
  224. package/src/components/input.ts +181 -0
  225. package/src/components/item.ts +376 -0
  226. package/src/components/kbd.ts +64 -0
  227. package/src/components/line-chart.ts +218 -0
  228. package/src/components/month-grid.ts +328 -0
  229. package/src/components/number-input.ts +443 -0
  230. package/src/components/popover.ts +368 -0
  231. package/src/components/scatter-chart.ts +221 -0
  232. package/src/components/select.ts +620 -0
  233. package/src/components/slider.ts +259 -0
  234. package/src/components/sort-button.ts +189 -0
  235. package/src/components/sparkline.ts +114 -0
  236. package/src/components/stat.ts +96 -0
  237. package/src/components/switch.ts +205 -0
  238. package/src/components/tabs.ts +426 -0
  239. package/src/components/text-area.ts +186 -0
  240. package/src/components/toggle-group.ts +295 -0
  241. package/src/components/tooltip.ts +156 -0
  242. package/src/index.ts +24 -0
  243. package/src/lib/calendar.ts +117 -0
  244. package/src/lib/chart.ts +72 -0
  245. package/src/lib/color.ts +89 -0
  246. package/src/lib/component-index.ts +151 -0
  247. package/src/lib/css.ts +48 -0
  248. package/src/lib/define.ts +45 -0
  249. package/src/lib/dispose.ts +36 -0
  250. package/src/lib/h.ts +55 -0
  251. package/src/lib/headless.ts +16 -0
  252. package/src/lib/i18n.ts +30 -0
  253. package/src/lib/icons.ts +237 -0
  254. package/src/lib/kit-text.ts +26 -0
  255. package/src/lib/page.ts +24 -0
  256. package/src/lib/palette.ts +81 -0
  257. package/src/lib/placement.ts +188 -0
  258. package/src/lib/scope.ts +135 -0
  259. package/src/lib/styles.ts +53 -0
  260. package/src/lib/surface-events.ts +31 -0
  261. package/src/lib/surface-exit.ts +87 -0
  262. package/src/lib/t.ts +68 -0
  263. package/src/lib/theme.ts +664 -0
  264. package/src/lib/tokens.ts +111 -0
  265. package/src/lib/variants.ts +32 -0
  266. package/src/lib/zag.ts +46 -0
  267. package/stylelint/index.mjs +60 -0
  268. package/stylelint/lint.mjs +81 -0
  269. package/stylelint/plugin.mjs +115 -0
@@ -0,0 +1,121 @@
1
+ import { chartFrame, compactNumber, escapeXml, showTip, niceStep } from './chunk-A2FJ7Y7D.js';
2
+ import { defineComponent } from './chunk-VMCR3S2A.js';
3
+ import { defineStyles, css } from './chunk-XBEL4K33.js';
4
+ import './chunk-2GQIZM5Z.js';
5
+ import './chunk-BXMWQIBO.js';
6
+ import './chunk-X66RJAIS.js';
7
+ import { t } from './chunk-6QCILIT2.js';
8
+
9
+ // src/components/scatter-chart.ts
10
+ var scatterChartDef = defineComponent({
11
+ name: "scatter-chart",
12
+ parts: ["root", "grid", "label", "point", "trend", "focus", "tip"],
13
+ settings: { "tip-radius": "3px", "tip-shadow": t.shadow, "tip-z": "2", "tip-bg": t.surface.elev }
14
+ });
15
+ var injectStyles = defineStyles(
16
+ "vela-ui-scatter-chart",
17
+ css`@layer vela.ui{[data-slot=scatter-chart]{width:100%;height:100%;position:relative}[data-slot=scatter-chart]>svg{width:100%;height:100%;display:block;overflow:visible}[data-slot=scatter-chart-grid]{stroke:color-mix(in srgb, ${t.fg.bright} 5%, transparent)}[data-slot=scatter-chart-grid][data-zero]{stroke:color-mix(in srgb, ${t.fg.bright} 20%, transparent)}[data-slot=scatter-chart-grid][data-base]{stroke:color-mix(in srgb, ${t.fg.bright} 10%, transparent)}[data-slot=scatter-chart-label]{fill:${t.fg.muted};font-size:10px}[data-slot=scatter-chart-label][data-title]{font-size:11px}[data-slot=scatter-chart-trend]{fill:none;stroke:${t.fg.muted};stroke-width:2px;stroke-dasharray:6 4}[data-slot=scatter-chart-focus]{fill:none;stroke-width:2px;opacity:0}[data-slot=scatter-chart-focus][data-on]{opacity:.6}[data-slot=scatter-chart-tip]{z-index:${scatterChartDef.vars["tip-z"]};pointer-events:none;border-radius:${scatterChartDef.vars["tip-radius"]};border:1px solid ${t.border};background:${scatterChartDef.vars["tip-bg"]};color:${t.fg.bright};box-shadow:${scatterChartDef.vars["tip-shadow"]};white-space:nowrap;font-variant-numeric:tabular-nums;transition:left ${t.dur.fast} ease-out, top ${t.dur.fast} ease-out;padding:8px;font-size:12px;line-height:1.35;position:absolute;top:0}[data-slot=scatter-chart-tip][data-instant]{transition:none}}`
18
+ );
19
+ function createScatterChart(props = {}) {
20
+ injectStyles(document);
21
+ let points = [];
22
+ let trend = [];
23
+ const slot = (part) => `data-slot="${scatterChartDef.slot(part)}"`;
24
+ const geometry = () => {
25
+ const w = frame.el.clientWidth;
26
+ const ht = frame.el.clientHeight;
27
+ if (w < 40 || ht < 40 || points.length === 0) return null;
28
+ const left = props.yTitle ? 58 : 44;
29
+ const top = 8;
30
+ const plotW = w - left - 10;
31
+ const plotH = ht - top - (props.xTitle ? 38 : 22);
32
+ const xs = points.map((p) => p.x);
33
+ const ys = [0, ...points.map((p) => p.y), ...trend.map((p) => p.y)];
34
+ const xStep = niceStep(Math.max(...xs) - Math.min(0, ...xs) || 1, Math.max(2, Math.floor(plotW / 90)));
35
+ const yStep = niceStep(Math.max(...ys) - Math.min(...ys) || 1, Math.max(2, Math.floor(plotH / 50)));
36
+ const x0 = Math.floor(Math.min(0, ...xs) / xStep) * xStep;
37
+ const xMax = Math.max(...xs);
38
+ const g = { w, h: ht, left, top, plotW, plotH, x0, x1: xMax > x0 ? xMax + (xMax - x0) * 0.01 : x0 + xStep, y0: Math.floor(Math.min(...ys) / yStep) * yStep, y1: Math.ceil(Math.max(...ys) / yStep) * yStep || yStep, xStep, yStep };
39
+ return { ...g, sx: (x) => g.left + (x - g.x0) / (g.x1 - g.x0) * g.plotW, sy: (y) => g.top + g.plotH - (y - g.y0) / (g.y1 - g.y0 || 1) * g.plotH };
40
+ };
41
+ const draw = () => {
42
+ const g = geometry();
43
+ if (!g) {
44
+ frame.svg.replaceChildren();
45
+ return;
46
+ }
47
+ const label = (x, y, text, anchor, extra = "") => `<text ${slot("label")} x="${x.toFixed(1)}" y="${y.toFixed(1)}" text-anchor="${anchor}"${extra}>${escapeXml(text)}</text>`;
48
+ let body = "";
49
+ for (let v = g.y0; v <= g.y1 + g.yStep / 2; v += g.yStep) {
50
+ const y = g.sy(v);
51
+ body += `<line ${slot("grid")} x1="${g.left}" x2="${g.left + g.plotW}" y1="${y.toFixed(1)}" y2="${y.toFixed(1)}"/>`;
52
+ body += label(g.left - 6, y + 3, compactNumber(Math.abs(v) < g.yStep / 2 ? 0 : v), "end");
53
+ }
54
+ for (let i = 0; g.x0 + i * g.xStep <= g.x1 + 1e-9; i += 1) {
55
+ const v = g.x0 + i * g.xStep;
56
+ const x = g.sx(v);
57
+ body += `<line ${slot("grid")} x1="${x.toFixed(1)}" x2="${x.toFixed(1)}" y1="${g.top}" y2="${g.top + g.plotH}"/>`;
58
+ body += label(x, g.top + g.plotH + 14, compactNumber(v), "middle");
59
+ }
60
+ const zero = g.sy(0).toFixed(1);
61
+ body += `<line ${slot("grid")} data-zero="" x1="${g.left}" x2="${g.left + g.plotW}" y1="${zero}" y2="${zero}"/>`;
62
+ body += `<line ${slot("grid")} data-base="" x1="${g.left}" x2="${g.left + g.plotW}" y1="${g.top + g.plotH}" y2="${g.top + g.plotH}"/>`;
63
+ if (props.xTitle) body += label(g.left + g.plotW / 2, g.h - 4, props.xTitle, "middle", ' data-title=""');
64
+ if (props.yTitle) {
65
+ const cy = g.top + g.plotH / 2;
66
+ body += label(12, cy, props.yTitle, "middle", ` data-title="" transform="rotate(-90 12 ${cy.toFixed(1)})"`);
67
+ }
68
+ for (const p of points) body += `<circle ${slot("point")} style="fill: ${escapeXml(p.color)}" cx="${g.sx(p.x).toFixed(1)}" cy="${g.sy(p.y).toFixed(1)}" r="4"/>`;
69
+ if (trend.length > 1) body += `<path ${slot("trend")} d="${trend.map((p, i) => `${i ? "L" : "M"}${g.sx(p.x).toFixed(1)},${g.sy(p.y).toFixed(1)}`).join("")}"/>`;
70
+ body += `<circle ${slot("focus")} r="6"/>`;
71
+ frame.svg.setAttribute("viewBox", `0 0 ${g.w} ${g.h}`);
72
+ frame.svg.innerHTML = body;
73
+ };
74
+ const frame = chartFrame(scatterChartDef.slot("root"), scatterChartDef.slot("tip"), props.className, draw);
75
+ const hover = (e) => {
76
+ const g = geometry();
77
+ const focus = frame.svg.querySelector(`[data-slot="${scatterChartDef.slot("focus")}"]`);
78
+ if (!g || !e || !focus) {
79
+ frame.tip.hidden = true;
80
+ focus?.removeAttribute("data-on");
81
+ return;
82
+ }
83
+ const rect = frame.el.getBoundingClientRect();
84
+ let index = -1;
85
+ let best = Infinity;
86
+ points.forEach((p2, i) => {
87
+ const dist = Math.hypot(g.sx(p2.x) - (e.clientX - rect.left), g.sy(p2.y) - (e.clientY - rect.top));
88
+ if (dist < best) {
89
+ best = dist;
90
+ index = i;
91
+ }
92
+ });
93
+ const p = points[index];
94
+ if (!p || best > 24) {
95
+ frame.tip.hidden = true;
96
+ focus.removeAttribute("data-on");
97
+ return;
98
+ }
99
+ focus.setAttribute("cx", String(g.sx(p.x)));
100
+ focus.setAttribute("cy", String(g.sy(p.y)));
101
+ focus.style.stroke = p.color;
102
+ focus.setAttribute("data-on", "");
103
+ showTip(frame.tip, props.format ? props.format(p, index) : `${p.x}, ${p.y}`, g, g.sx(p.x), g.sy(p.y));
104
+ };
105
+ frame.el.addEventListener("pointermove", hover);
106
+ frame.el.addEventListener("pointerleave", () => hover(null));
107
+ return {
108
+ el: frame.el,
109
+ setData(next, nextTrend = []) {
110
+ points = next;
111
+ trend = nextTrend;
112
+ draw();
113
+ },
114
+ destroy() {
115
+ frame.disconnect();
116
+ frame.el.remove();
117
+ }
118
+ };
119
+ }
120
+
121
+ export { createScatterChart, scatterChartDef };
@@ -0,0 +1,112 @@
1
+ import { V as VariantFn } from './variants-B4stUBnY.js';
2
+ import { C as ComponentDef } from './define-D5u3F5Dj.js';
3
+ import { PlacementProps } from './placement.js';
4
+ import { ChartTheme } from './tokens.js';
5
+ import { PopoverBoundary, PopoverOptions, Popover } from './popover.js';
6
+ import './t.js';
7
+
8
+ type SelectSize = 'sm' | 'md';
9
+ interface SelectOption {
10
+ value: string;
11
+ label: string;
12
+ }
13
+ interface SelectControllerOptions {
14
+ options: readonly SelectOption[];
15
+ value?: string;
16
+ /** The value it starts with when `value` is not given. */
17
+ defaultValue?: string;
18
+ /** Shown while no option is picked: the value stays `''` until the user picks one. Without
19
+ * it, the first option is picked to start with. */
20
+ placeholder?: string;
21
+ size?: SelectSize;
22
+ /** Stretch the trigger to its parent. Off: the shared 100px kit column (ellipsis). */
23
+ fill?: boolean;
24
+ disabled?: boolean;
25
+ /** Called when the user picks an option. */
26
+ onValueChange?: (value: string, label: string) => void;
27
+ /** @deprecated Use `onValueChange`. */
28
+ onChange?: (value: string, label: string) => void;
29
+ }
30
+ interface SelectController {
31
+ options: readonly SelectOption[];
32
+ value: string;
33
+ size: SelectSize;
34
+ fill: boolean;
35
+ disabled: boolean;
36
+ setValue(v: string): void;
37
+ labelOf(value: string): string;
38
+ pick(value: string): {
39
+ value: string;
40
+ label: string;
41
+ };
42
+ }
43
+ /** The select's options and current value, without DOM. */
44
+ declare function selectController(opts: SelectControllerOptions): SelectController;
45
+ declare const selectDef: ComponentDef<"select", "root" | "viewport" | "icon" | "trigger" | "content" | "value" | "thumb" | "item" | "sizer" | "native" | "rail", "radius" | "content-radius" | "focus-ring" | "thumb-radius">;
46
+ declare const selectVariants: VariantFn<{
47
+ readonly size: readonly ["md", "sm"];
48
+ }>;
49
+ /** Where the list opens and how (shadcn's placement props, defaults below and start-aligned,
50
+ * 4px away, as wide as the trigger at least). */
51
+ interface SelectListPopoverOpts extends PlacementProps {
52
+ theme?: ChartTheme;
53
+ matchWidth?: boolean;
54
+ /** @deprecated Use `collisionBoundary`. */
55
+ boundary?: PopoverBoundary;
56
+ boundaryInset?: number;
57
+ /** @deprecated Use `sideOffset`. */
58
+ gap?: number;
59
+ host?: HTMLElement;
60
+ position?: PopoverOptions['position'];
61
+ zIndex?: string | number;
62
+ size?: SelectSize;
63
+ /** Move the focus into the open list, for the arrow keys and typeahead (and back to the
64
+ * trigger when it closes). Off by default: a trigger the user types in keeps the focus. */
65
+ focusList?: boolean;
66
+ onClose?: () => void;
67
+ }
68
+ interface SelectOptions extends SelectControllerOptions, PlacementProps {
69
+ id?: string;
70
+ /** Submitted with its form under this name: a hidden native select carries the value. */
71
+ name?: string;
72
+ /** A form does not submit while no option is picked (with `placeholder`). */
73
+ required?: boolean;
74
+ theme?: ChartTheme;
75
+ /** The open list's other options (its host, layer, width). Its placement props are the
76
+ * select's own; set here, they give way to those. */
77
+ list?: SelectListPopoverOpts;
78
+ }
79
+ type SelectProps = SelectOptions;
80
+ declare const SELECT_STYLE_ID = "vela-ui-select-3";
81
+ declare const SELECT_CSS: string;
82
+ /** Fill `menu` with the options, a listbox (Zag's listbox machine: the arrow keys, Home/End,
83
+ * Enter and typeahead while it has the focus). A click picks at once; one pick per fill.
84
+ * Call {@link decorateSelectScroll} after the menu is on screen; call the returned function
85
+ * when the menu goes away. */
86
+ declare function fillSelectList(menu: HTMLElement, options: readonly SelectOption[], current: string, onPick: (value: string, label: string) => void): () => void;
87
+ /** Overlay scrollbar + scroll-into-view — needs a laid-out list (after the popover is shown). */
88
+ declare function decorateSelectScroll(menu: HTMLElement): void;
89
+ /** Open (or re-click close) a themed option list under `trigger`. */
90
+ declare function toggleSelectList(trigger: HTMLElement, options: readonly SelectOption[], current: string, onPick: (value: string, label: string) => void, opts?: SelectListPopoverOpts): Popover | null;
91
+ declare function openSelectList(trigger: HTMLElement, options: readonly SelectOption[], current: string, onPick: (value: string, label: string) => void, opts?: SelectListPopoverOpts): Popover;
92
+ declare class Select {
93
+ readonly el: HTMLElement;
94
+ private readonly trigger;
95
+ private readonly labelEl;
96
+ private readonly ctrl;
97
+ private readonly listOpts;
98
+ private readonly placeholder;
99
+ private readonly native;
100
+ private readonly release;
101
+ private list;
102
+ constructor(opts: SelectOptions);
103
+ get value(): string;
104
+ setValue(v: string): void;
105
+ /** The trigger shows the picked option's label, or the placeholder while none is picked. */
106
+ private paint;
107
+ toggle(): void;
108
+ destroy(): void;
109
+ }
110
+ declare function createSelect(props: SelectProps): Select;
111
+
112
+ export { SELECT_CSS, SELECT_STYLE_ID, Select, type SelectController, type SelectControllerOptions, type SelectListPopoverOpts, type SelectOption, type SelectOptions, type SelectProps, type SelectSize, createSelect, decorateSelectScroll, fillSelectList, openSelectList, selectController, selectDef, selectVariants, toggleSelectList };
package/dist/select.js ADDED
@@ -0,0 +1,19 @@
1
+ export { SELECT_CSS, SELECT_STYLE_ID, Select, createSelect, decorateSelectScroll, fillSelectList, openSelectList, selectController, selectDef, selectVariants, toggleSelectList } from './chunk-Z5PINFQO.js';
2
+ import './chunk-LZWZV2ZS.js';
3
+ import './chunk-G7IQLY3A.js';
4
+ import './chunk-B5ZSRUDQ.js';
5
+ import './chunk-J2QJATCD.js';
6
+ import './chunk-S7USVSYP.js';
7
+ import './chunk-V2Q4MRMS.js';
8
+ import './chunk-TAKSIV57.js';
9
+ import './chunk-MMTMOV6R.js';
10
+ import './chunk-3Q32K4PE.js';
11
+ import './chunk-A72NWYNP.js';
12
+ import './chunk-P4MTEMT7.js';
13
+ import './chunk-Q6WTDVH6.js';
14
+ import './chunk-VMCR3S2A.js';
15
+ import './chunk-XBEL4K33.js';
16
+ import './chunk-2GQIZM5Z.js';
17
+ import './chunk-BXMWQIBO.js';
18
+ import './chunk-X66RJAIS.js';
19
+ import './chunk-6QCILIT2.js';
@@ -0,0 +1,46 @@
1
+ import { C as ComponentDef } from './define-D5u3F5Dj.js';
2
+ import './t.js';
3
+
4
+ declare const sliderDef: ComponentDef<"slider", "root" | "track" | "thumb" | "control" | "range", "radius" | "focus-ring" | "track-height" | "thumb-size">;
5
+ interface SliderProps {
6
+ /** The value it starts with (default `min`). */
7
+ defaultValue?: number;
8
+ /** Default 0. */
9
+ min?: number;
10
+ /** Default 100. */
11
+ max?: number;
12
+ /** Default 1. */
13
+ step?: number;
14
+ /** Every move: while dragging, and on each key. */
15
+ onValueChange?: (value: number) => void;
16
+ /** Once a move settles: the pointer lifted, or a key pressed. */
17
+ onValueCommit?: (value: number) => void;
18
+ /** Its accessible name, when no `<label>` names it. */
19
+ label?: string;
20
+ /** What a screen reader says for a value (`11 Jun 2024`, `35%`). Default: the number. */
21
+ valueText?: (value: number) => string;
22
+ /** Default `horizontal`. A vertical slider takes its height from its parent. */
23
+ orientation?: 'horizontal' | 'vertical';
24
+ /** The text direction the keys and the track follow (default `ltr`). */
25
+ dir?: 'ltr' | 'rtl';
26
+ disabled?: boolean;
27
+ /** Submitted with its form under this name. */
28
+ name?: string;
29
+ /** The id of its thumb, so a `<label for>` reaches it. */
30
+ id?: string;
31
+ /** Extra class names (layout hooks). */
32
+ className?: string;
33
+ }
34
+ interface SliderHandle {
35
+ readonly el: HTMLElement;
36
+ readonly value: number;
37
+ /** While the thumb is held. */
38
+ readonly dragging: boolean;
39
+ /** Move it without reporting. */
40
+ setValue(value: number): void;
41
+ setDisabled(disabled: boolean): void;
42
+ destroy(): void;
43
+ }
44
+ declare function createSlider(props?: SliderProps): SliderHandle;
45
+
46
+ export { type SliderHandle, type SliderProps, createSlider, sliderDef };
package/dist/slider.js ADDED
@@ -0,0 +1,111 @@
1
+ import { ownTeardown } from './chunk-A72NWYNP.js';
2
+ import { nextUid, runMachine, normalizeProps, spreadProps } from './chunk-P4MTEMT7.js';
3
+ import { h } from './chunk-Q6WTDVH6.js';
4
+ import { defineComponent } from './chunk-VMCR3S2A.js';
5
+ import { defineStyles, css } from './chunk-XBEL4K33.js';
6
+ import './chunk-2GQIZM5Z.js';
7
+ import './chunk-BXMWQIBO.js';
8
+ import './chunk-X66RJAIS.js';
9
+ import { t } from './chunk-6QCILIT2.js';
10
+ import * as zagSlider from '@zag-js/slider';
11
+
12
+ var sliderDef = defineComponent({
13
+ name: "slider",
14
+ parts: ["root", "control", "track", "range", "thumb"],
15
+ settings: { "track-height": "4px", "thumb-size": "14px", radius: "999px", "focus-ring": `0 0 0 3px ${t.focus.soft}` }
16
+ });
17
+ var injectStyles = defineStyles(
18
+ "vela-ui-slider",
19
+ css`@layer vela.ui{[data-slot=slider]{--_thumb:${sliderDef.vars["thumb-size"]};--_track:${sliderDef.vars["track-height"]};box-sizing:border-box;width:100%;min-width:0;padding-inline:calc(var(--_thumb) / 2);position:relative}[data-slot=slider]:where(:not([hidden])){align-items:center;display:flex}[data-slot=slider][data-orientation=vertical]{width:auto;height:100%;padding-inline:0;padding-block:calc(var(--_thumb) / 2);flex-direction:column}[data-slot=slider][data-disabled]{opacity:.5}[data-slot=slider-control]{min-height:var(--_thumb);cursor:pointer;flex:1;align-items:center;display:flex}[data-slot=slider-control][data-orientation=vertical]{min-width:var(--_thumb);flex-direction:column;min-height:0}[data-slot=slider-control][data-disabled]{cursor:default}[data-slot=slider-track]{height:var(--_track);border-radius:${sliderDef.vars.radius};background:${t.border};flex:1;position:relative;overflow:hidden}[data-slot=slider-track][data-orientation=vertical]{width:var(--_track);height:auto}[data-slot=slider-range]{border-radius:inherit;background:${t.selected.bg};height:100%}[data-slot=slider-range][data-orientation=vertical]{width:100%;height:auto}[data-slot=slider-thumb]{width:var(--_thumb);height:var(--_thumb);border:2px solid ${t.bg};background:${t.selected.bg};transition:box-shadow ${t.dur.fast} ease;border-radius:50%;outline:2px solid #0000}[data-slot=slider-thumb]:focus-visible{box-shadow:${sliderDef.vars["focus-ring"]}}}`
20
+ );
21
+ var SliderImpl = class {
22
+ constructor(props) {
23
+ /** A write from code is in the machine: its reports, down to the end of the change that
24
+ * always closes a write, are not the user's. */
25
+ this.silent = false;
26
+ injectStyles(document);
27
+ const min = this.min = props.min ?? 0;
28
+ const max = this.max = props.max ?? 100;
29
+ this.current = Math.min(max, Math.max(min, props.defaultValue ?? min));
30
+ this.disabled = props.disabled ?? false;
31
+ this.mid = nextUid("vela-slider");
32
+ this.thumb = h("div", { slot: sliderDef.slot("thumb") });
33
+ this.range = h("div", { slot: sliderDef.slot("range") });
34
+ this.track = h("div", { slot: sliderDef.slot("track") }, this.range);
35
+ this.control = h("div", { slot: sliderDef.slot("control") }, this.track, this.thumb);
36
+ this.input = props.name !== void 0 ? h("input", {}) : null;
37
+ this.el = h("div", { className: props.className ? `vela-slider ${props.className}` : "vela-slider", slot: sliderDef.slot("root") }, this.control, this.input);
38
+ this.machine = runMachine(
39
+ zagSlider.machine,
40
+ () => ({
41
+ id: this.mid,
42
+ ...props.id ? { ids: { thumb: () => props.id } } : {},
43
+ min,
44
+ max,
45
+ step: props.step ?? 1,
46
+ defaultValue: [this.current],
47
+ orientation: props.orientation ?? "horizontal",
48
+ dir: props.dir ?? "ltr",
49
+ disabled: this.disabled,
50
+ // `contain` would measure the thumb, which a slider built before it is on the
51
+ // page cannot do.
52
+ thumbAlignment: "center",
53
+ ...props.name !== void 0 ? { name: props.name } : {},
54
+ ...props.label ? { "aria-label": [props.label] } : {},
55
+ ...props.valueText ? { getAriaValueText: ({ value }) => props.valueText(value) } : {},
56
+ onValueChange: ({ value: [value] }) => {
57
+ if (value === void 0) return;
58
+ this.current = value;
59
+ if (!this.silent) props.onValueChange?.(value);
60
+ },
61
+ onValueChangeEnd: ({ value: [value] }) => {
62
+ if (this.silent) {
63
+ this.silent = false;
64
+ return;
65
+ }
66
+ if (value !== void 0) props.onValueCommit?.(value);
67
+ }
68
+ }),
69
+ (service) => this.render(service)
70
+ );
71
+ this.release = ownTeardown(this.el, () => this.machine.stop());
72
+ }
73
+ get value() {
74
+ return this.current;
75
+ }
76
+ get dragging() {
77
+ return this.api().dragging;
78
+ }
79
+ setValue(value) {
80
+ const next = Math.min(this.max, Math.max(this.min, value));
81
+ if (next === this.current) return;
82
+ this.current = next;
83
+ this.silent = true;
84
+ this.api().setValue([next]);
85
+ }
86
+ setDisabled(disabled) {
87
+ if (disabled === this.disabled) return;
88
+ this.disabled = disabled;
89
+ this.machine.flush();
90
+ }
91
+ destroy() {
92
+ this.release();
93
+ }
94
+ api() {
95
+ return zagSlider.connect(this.machine.service, normalizeProps);
96
+ }
97
+ render(service) {
98
+ const api = zagSlider.connect(service, normalizeProps);
99
+ spreadProps(this.el, api.getRootProps(), this.mid);
100
+ spreadProps(this.control, api.getControlProps(), this.mid);
101
+ spreadProps(this.track, api.getTrackProps(), this.mid);
102
+ spreadProps(this.range, api.getRangeProps(), this.mid);
103
+ spreadProps(this.thumb, api.getThumbProps({ index: 0 }), this.mid);
104
+ if (this.input) spreadProps(this.input, api.getHiddenInputProps({ index: 0 }), this.mid);
105
+ }
106
+ };
107
+ function createSlider(props = {}) {
108
+ return new SliderImpl(props);
109
+ }
110
+
111
+ export { createSlider, sliderDef };
@@ -0,0 +1,41 @@
1
+ import { a as VariantProps, V as VariantFn } from './variants-B4stUBnY.js';
2
+ import { C as ComponentDef } from './define-D5u3F5Dj.js';
3
+ import { Translator } from './i18n.js';
4
+ import './t.js';
5
+
6
+ declare const sortButtonDef: ComponentDef<"sort-button", "root" | "icon" | "state", "radius">;
7
+ declare const sortButtonVariants: VariantFn<{
8
+ readonly align: readonly ["start", "end"];
9
+ }>;
10
+ type SortDirection = 'asc' | 'desc';
11
+ interface SortButtonProps extends VariantProps<typeof sortButtonVariants> {
12
+ /** The column's name. */
13
+ label: string;
14
+ /** The sort it starts with (default none). */
15
+ direction?: SortDirection | null;
16
+ /** What the first press sorts by (default `desc`: the largest first). */
17
+ firstDirection?: SortDirection;
18
+ /** A press after both directions clears the sort (default true). */
19
+ clearable?: boolean;
20
+ /** A press changed the sort; null: unsorted. */
21
+ onSortChange?: (direction: SortDirection | null) => void;
22
+ /** A tooltip (`Sort by Last`). */
23
+ title?: string;
24
+ disabled?: boolean;
25
+ /** The translator of the words a screen reader hears ("sorted ascending"). Default: the
26
+ * kit build's, else English. */
27
+ i18n?: Translator;
28
+ /** Extra class names (layout hooks). */
29
+ className?: string;
30
+ }
31
+ interface SortButtonHandle {
32
+ readonly el: HTMLButtonElement;
33
+ readonly direction: SortDirection | null;
34
+ /** Show a sort without calling `onSortChange`. */
35
+ setDirection(direction: SortDirection | null): void;
36
+ setDisabled(disabled: boolean): void;
37
+ destroy(): void;
38
+ }
39
+ declare function createSortButton(props: SortButtonProps): SortButtonHandle;
40
+
41
+ export { type SortButtonHandle, type SortButtonProps, type SortDirection, createSortButton, sortButtonDef, sortButtonVariants };
@@ -0,0 +1,88 @@
1
+ import { variants } from './chunk-LZWZV2ZS.js';
2
+ import { iconEl } from './chunk-G7IQLY3A.js';
3
+ import { kitTranslator } from './chunk-FVH6L7FM.js';
4
+ import { msg, textOf } from './chunk-FN2BUFNM.js';
5
+ import { nextUid } from './chunk-P4MTEMT7.js';
6
+ import { h } from './chunk-Q6WTDVH6.js';
7
+ import { defineComponent } from './chunk-VMCR3S2A.js';
8
+ import { defineStyles, css } from './chunk-XBEL4K33.js';
9
+ import './chunk-2GQIZM5Z.js';
10
+ import './chunk-BXMWQIBO.js';
11
+ import './chunk-X66RJAIS.js';
12
+ import { t } from './chunk-6QCILIT2.js';
13
+
14
+ // src/components/sort-button.ts
15
+ var sortButtonDef = defineComponent({
16
+ name: "sort-button",
17
+ parts: ["root", "icon", "state"],
18
+ settings: { radius: t.radius.sm }
19
+ });
20
+ var sortButtonVariants = variants({ align: ["start", "end"] });
21
+ var TEXT = {
22
+ asc: msg("ui.sortButton.ascending", "sorted ascending"),
23
+ desc: msg("ui.sortButton.descending", "sorted descending")
24
+ };
25
+ var injectStyles = defineStyles(
26
+ "vela-ui-sort-button",
27
+ css`@layer vela.ui{[data-slot=sort-button]:where(:not([hidden])){all:unset;box-sizing:border-box;border-radius:${sortButtonDef.vars.radius};max-width:100%;color:${t.fg.muted};white-space:nowrap;cursor:pointer;-webkit-user-select:none;user-select:none;transition:color ${t.dur.fast} ease;align-items:center;gap:3px;font-size:11px;font-weight:500;display:inline-flex}[data-slot=sort-button]:where(:not([hidden]))[data-align=end]{text-align:end;justify-content:flex-end}[data-slot=sort-button]:where(:not([hidden])):disabled{cursor:default;opacity:.5}[data-slot=sort-button]:where(:not([hidden])):focus-visible{outline:2px solid ${t.focus};outline-offset:1px}[data-slot=sort-button]:where(:not([hidden])):not(:disabled):hover,[data-slot=sort-button]:where(:not([hidden]))[data-direction]{color:${t.fg.bright}}[data-slot=sort-button-icon]{flex:none;width:1em;height:1em;font-size:11px;line-height:0}[data-slot=sort-button-icon]>svg{width:100%;height:100%}[data-slot=sort-button-state]{clip-path:inset(50%);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}}`
28
+ );
29
+ var SortButtonImpl = class {
30
+ constructor(props) {
31
+ this.props = props;
32
+ injectStyles(document);
33
+ this.i18n = props.i18n ?? kitTranslator();
34
+ this.current = props.direction ?? null;
35
+ const stateId = nextUid("vela-sort");
36
+ this.state = h("span", { slot: sortButtonDef.slot("state"), attrs: { id: stateId } });
37
+ this.el = h(
38
+ "button",
39
+ {
40
+ className: props.className,
41
+ slot: sortButtonDef.slot("root"),
42
+ attrs: { type: "button", title: props.title ?? null, "aria-label": props.label, "aria-describedby": stateId, ...sortButtonVariants(props) },
43
+ on: { click: () => this.step() }
44
+ },
45
+ props.label,
46
+ this.state
47
+ );
48
+ this.el.disabled = props.disabled ?? false;
49
+ this.paint();
50
+ }
51
+ get direction() {
52
+ return this.current;
53
+ }
54
+ setDirection(direction) {
55
+ this.current = direction;
56
+ this.paint();
57
+ }
58
+ setDisabled(disabled) {
59
+ this.el.disabled = disabled;
60
+ }
61
+ destroy() {
62
+ }
63
+ step() {
64
+ const first = this.props.firstDirection ?? "desc";
65
+ const second = first === "desc" ? "asc" : "desc";
66
+ const clearable = this.props.clearable ?? true;
67
+ this.current = this.current === null ? first : this.current === first ? second : clearable ? null : first;
68
+ this.paint();
69
+ this.props.onSortChange?.(this.current);
70
+ }
71
+ paint() {
72
+ const dir = this.current;
73
+ this.el.querySelector(`[data-slot="${sortButtonDef.slot("icon")}"]`)?.remove();
74
+ if (dir) {
75
+ const icon = iconEl(dir === "asc" ? "arrow-up" : "arrow-down", document);
76
+ icon.dataset.slot = sortButtonDef.slot("icon");
77
+ this.state.before(icon);
78
+ }
79
+ this.el.toggleAttribute("data-direction", dir !== null);
80
+ if (dir) this.el.dataset.direction = dir;
81
+ this.state.textContent = dir ? textOf(this.i18n, TEXT[dir]) : "";
82
+ }
83
+ };
84
+ function createSortButton(props) {
85
+ return new SortButtonImpl(props);
86
+ }
87
+
88
+ export { createSortButton, sortButtonDef, sortButtonVariants };
@@ -0,0 +1,22 @@
1
+ import { C as ComponentDef } from './define-D5u3F5Dj.js';
2
+ import './t.js';
3
+
4
+ declare const sparklineDef: ComponentDef<"sparkline", "root" | "line" | "area" | "baseline", "stroke-width">;
5
+ interface SparklineProps {
6
+ values: readonly number[];
7
+ /** px (default 56 × 20). */
8
+ width?: number;
9
+ height?: number;
10
+ /** A soft area under the line. */
11
+ area?: boolean;
12
+ /** A dotted line at this value; the tone compares the last value with it. */
13
+ baseline?: number | null;
14
+ }
15
+ interface SparklineHandle {
16
+ readonly el: SVGSVGElement;
17
+ setValues(values: readonly number[], baseline?: number | null): void;
18
+ destroy(): void;
19
+ }
20
+ declare function createSparkline(props: SparklineProps): SparklineHandle;
21
+
22
+ export { type SparklineHandle, type SparklineProps, createSparkline, sparklineDef };
@@ -0,0 +1,72 @@
1
+ import { defineComponent } from './chunk-VMCR3S2A.js';
2
+ import { defineStyles, css } from './chunk-XBEL4K33.js';
3
+ import './chunk-2GQIZM5Z.js';
4
+ import './chunk-BXMWQIBO.js';
5
+ import './chunk-X66RJAIS.js';
6
+ import { t } from './chunk-6QCILIT2.js';
7
+
8
+ // src/components/sparkline.ts
9
+ var sparklineDef = defineComponent({
10
+ name: "sparkline",
11
+ parts: ["root", "area", "baseline", "line"],
12
+ settings: { "stroke-width": "1.25" }
13
+ });
14
+ var NS = "http://www.w3.org/2000/svg";
15
+ var injectStyles = defineStyles(
16
+ "vela-ui-sparkline",
17
+ css`@layer vela.ui{[data-slot=sparkline]{--_ink:${t.profit};overflow:visible}[data-slot=sparkline][data-tone=loss]{--_ink:${t.loss}}[data-slot=sparkline-line]{fill:none;stroke:var(--_ink);stroke-width:${sparklineDef.vars["stroke-width"]};stroke-linejoin:round}[data-slot=sparkline-area]{fill:color-mix(in srgb, var(--_ink) 14%, transparent)}[data-slot=sparkline-baseline]{stroke:${t.fg.faint};stroke-dasharray:1.5 2}}`
18
+ );
19
+ function part(name) {
20
+ const el = document.createElementNS(NS, name === "baseline" ? "line" : "path");
21
+ el.setAttribute("data-slot", sparklineDef.slot(name));
22
+ return el;
23
+ }
24
+ function createSparkline(props) {
25
+ injectStyles(document);
26
+ const w = props.width ?? 56;
27
+ const ht = props.height ?? 20;
28
+ const el = document.createElementNS(NS, "svg");
29
+ el.setAttribute("viewBox", `0 0 ${w} ${ht}`);
30
+ el.setAttribute("width", String(w));
31
+ el.setAttribute("height", String(ht));
32
+ el.setAttribute("data-slot", sparklineDef.slot("root"));
33
+ el.setAttribute("aria-hidden", "true");
34
+ const draw = (values, baseline) => {
35
+ el.replaceChildren();
36
+ const pts = values.filter((v) => Number.isFinite(v));
37
+ if (pts.length < 2) return;
38
+ const ref = baseline ?? pts[0];
39
+ let lo = Math.min(...pts, baseline ?? Infinity);
40
+ let hi = Math.max(...pts, baseline ?? -Infinity);
41
+ if (hi === lo) {
42
+ hi += 1;
43
+ lo -= 1;
44
+ }
45
+ const y = (v) => 1.5 + (ht - 3) * (1 - (v - lo) / (hi - lo));
46
+ const x = (i) => i / (pts.length - 1) * w;
47
+ const d = pts.map((v, i) => `${i ? "L" : "M"}${x(i).toFixed(1)} ${y(v).toFixed(1)}`).join("");
48
+ el.setAttribute("data-tone", pts[pts.length - 1] >= ref ? "profit" : "loss");
49
+ if (props.area) {
50
+ const area = part("area");
51
+ area.setAttribute("d", `${d}L${w} ${ht}L0 ${ht}Z`);
52
+ el.appendChild(area);
53
+ }
54
+ if (baseline != null) {
55
+ const base = part("baseline");
56
+ const by = y(baseline).toFixed(1);
57
+ for (const [k, v] of [["x1", "0"], ["x2", String(w)], ["y1", by], ["y2", by]]) base.setAttribute(k, v);
58
+ el.appendChild(base);
59
+ }
60
+ const line = part("line");
61
+ line.setAttribute("d", d);
62
+ el.appendChild(line);
63
+ };
64
+ draw(props.values, props.baseline ?? null);
65
+ return {
66
+ el,
67
+ setValues: (values, baseline = props.baseline ?? null) => draw(values, baseline),
68
+ destroy: () => el.remove()
69
+ };
70
+ }
71
+
72
+ export { createSparkline, sparklineDef };