@contui/ui 0.0.0-stage → 0.1.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 (427) hide show
  1. package/LICENSE +30 -0
  2. package/README.md +150 -2
  3. package/cli/contui.mjs +250 -0
  4. package/dist/charts/area-chart.d.ts +8 -0
  5. package/dist/charts/area-chart.js +9 -0
  6. package/dist/charts/bar-chart.d.ts +9 -0
  7. package/dist/charts/bar-chart.js +10 -0
  8. package/dist/charts/bubble-chart.d.ts +60 -0
  9. package/dist/charts/bubble-chart.js +392 -0
  10. package/dist/charts/bullet-chart.d.ts +53 -0
  11. package/dist/charts/bullet-chart.js +123 -0
  12. package/dist/charts/candlestick-chart.d.ts +77 -0
  13. package/dist/charts/candlestick-chart.js +558 -0
  14. package/dist/charts/cartesian.d.ts +121 -0
  15. package/dist/charts/cartesian.js +625 -0
  16. package/dist/charts/chart-card.d.ts +80 -0
  17. package/dist/charts/chart-card.js +114 -0
  18. package/dist/charts/donut-chart.d.ts +40 -0
  19. package/dist/charts/donut-chart.js +88 -0
  20. package/dist/charts/funnel-chart.d.ts +16 -0
  21. package/dist/charts/funnel-chart.js +164 -0
  22. package/dist/charts/horizontal-bar-chart.d.ts +67 -0
  23. package/dist/charts/horizontal-bar-chart.js +481 -0
  24. package/dist/charts/index.d.ts +21 -0
  25. package/dist/charts/index.js +32 -0
  26. package/dist/charts/legend.d.ts +23 -0
  27. package/dist/charts/legend.js +22 -0
  28. package/dist/charts/lib/candlestick-window.d.ts +15 -0
  29. package/dist/charts/lib/candlestick-window.js +23 -0
  30. package/dist/charts/lib/color.d.ts +39 -0
  31. package/dist/charts/lib/color.js +83 -0
  32. package/dist/charts/lib/format.d.ts +11 -0
  33. package/dist/charts/lib/format.js +33 -0
  34. package/dist/charts/lib/frame.d.ts +6 -0
  35. package/dist/charts/lib/frame.js +6 -0
  36. package/dist/charts/lib/layout.d.ts +11 -0
  37. package/dist/charts/lib/layout.js +71 -0
  38. package/dist/charts/lib/path.d.ts +35 -0
  39. package/dist/charts/lib/path.js +203 -0
  40. package/dist/charts/lib/scale.d.ts +41 -0
  41. package/dist/charts/lib/scale.js +80 -0
  42. package/dist/charts/lib/use-active.d.ts +18 -0
  43. package/dist/charts/lib/use-active.js +71 -0
  44. package/dist/charts/lib/use-size.d.ts +9 -0
  45. package/dist/charts/lib/use-size.js +40 -0
  46. package/dist/charts/line-chart.d.ts +7 -0
  47. package/dist/charts/line-chart.js +8 -0
  48. package/dist/charts/radar-chart.d.ts +27 -0
  49. package/dist/charts/radar-chart.js +165 -0
  50. package/dist/charts/rose-chart.d.ts +35 -0
  51. package/dist/charts/rose-chart.js +242 -0
  52. package/dist/charts/sparkline.d.ts +35 -0
  53. package/dist/charts/sparkline.js +110 -0
  54. package/dist/charts/tooltip.d.ts +35 -0
  55. package/dist/charts/tooltip.js +22 -0
  56. package/dist/charts/treemap.d.ts +28 -0
  57. package/dist/charts/treemap.js +103 -0
  58. package/dist/charts/uptime-strip.d.ts +40 -0
  59. package/dist/charts/uptime-strip.js +178 -0
  60. package/dist/components/accordion.d.ts +31 -0
  61. package/dist/components/accordion.js +34 -0
  62. package/dist/components/activity-item.d.ts +12 -0
  63. package/dist/components/activity-item.js +6 -0
  64. package/dist/components/alert.d.ts +21 -0
  65. package/dist/components/alert.js +58 -0
  66. package/dist/components/assistant-answer.d.ts +52 -0
  67. package/dist/components/assistant-answer.js +40 -0
  68. package/dist/components/assistant-prompt.d.ts +63 -0
  69. package/dist/components/assistant-prompt.js +122 -0
  70. package/dist/components/avatar.d.ts +28 -0
  71. package/dist/components/avatar.js +75 -0
  72. package/dist/components/badge.d.ts +16 -0
  73. package/dist/components/badge.js +33 -0
  74. package/dist/components/bar-list.d.ts +65 -0
  75. package/dist/components/bar-list.js +119 -0
  76. package/dist/components/block-slider.d.ts +43 -0
  77. package/dist/components/block-slider.js +63 -0
  78. package/dist/components/branch-graph.d.ts +87 -0
  79. package/dist/components/branch-graph.js +231 -0
  80. package/dist/components/breadcrumb.d.ts +41 -0
  81. package/dist/components/breadcrumb.js +53 -0
  82. package/dist/components/button.d.ts +23 -0
  83. package/dist/components/button.js +108 -0
  84. package/dist/components/calendar.d.ts +5 -0
  85. package/dist/components/calendar.js +90 -0
  86. package/dist/components/card.d.ts +65 -0
  87. package/dist/components/card.js +104 -0
  88. package/dist/components/chat-attachment.d.ts +47 -0
  89. package/dist/components/chat-attachment.js +63 -0
  90. package/dist/components/chat-event.d.ts +7 -0
  91. package/dist/components/chat-event.js +7 -0
  92. package/dist/components/chat-message.d.ts +59 -0
  93. package/dist/components/chat-message.js +91 -0
  94. package/dist/components/chat-reference.d.ts +20 -0
  95. package/dist/components/chat-reference.js +41 -0
  96. package/dist/components/chat-shared.d.ts +21 -0
  97. package/dist/components/chat-shared.js +23 -0
  98. package/dist/components/chat-suggestions.d.ts +59 -0
  99. package/dist/components/chat-suggestions.js +88 -0
  100. package/dist/components/chat-thread.d.ts +39 -0
  101. package/dist/components/chat-thread.js +172 -0
  102. package/dist/components/chat-typing.d.ts +35 -0
  103. package/dist/components/chat-typing.js +66 -0
  104. package/dist/components/checkbox.d.ts +18 -0
  105. package/dist/components/checkbox.js +33 -0
  106. package/dist/components/checklist.d.ts +26 -0
  107. package/dist/components/checklist.js +18 -0
  108. package/dist/components/chip.d.ts +29 -0
  109. package/dist/components/chip.js +61 -0
  110. package/dist/components/code-input.d.ts +40 -0
  111. package/dist/components/code-input.js +285 -0
  112. package/dist/components/color-picker.d.ts +38 -0
  113. package/dist/components/color-picker.js +855 -0
  114. package/dist/components/combobox.d.ts +75 -0
  115. package/dist/components/combobox.js +112 -0
  116. package/dist/components/command-menu.d.ts +58 -0
  117. package/dist/components/command-menu.js +166 -0
  118. package/dist/components/copy-button.d.ts +16 -0
  119. package/dist/components/copy-button.js +31 -0
  120. package/dist/components/data-grid.d.ts +50 -0
  121. package/dist/components/data-grid.js +599 -0
  122. package/dist/components/date-picker.d.ts +109 -0
  123. package/dist/components/date-picker.js +268 -0
  124. package/dist/components/description-list.d.ts +12 -0
  125. package/dist/components/description-list.js +10 -0
  126. package/dist/components/dialog.d.ts +57 -0
  127. package/dist/components/dialog.js +140 -0
  128. package/dist/components/dock.d.ts +45 -0
  129. package/dist/components/dock.js +79 -0
  130. package/dist/components/drop-zone.d.ts +46 -0
  131. package/dist/components/drop-zone.js +101 -0
  132. package/dist/components/dropdown-menu.d.ts +50 -0
  133. package/dist/components/dropdown-menu.js +78 -0
  134. package/dist/components/editable-cell.d.ts +34 -0
  135. package/dist/components/editable-cell.js +89 -0
  136. package/dist/components/empty-state.d.ts +17 -0
  137. package/dist/components/empty-state.js +9 -0
  138. package/dist/components/field.d.ts +43 -0
  139. package/dist/components/field.js +75 -0
  140. package/dist/components/filter-condition.d.ts +188 -0
  141. package/dist/components/filter-condition.js +113 -0
  142. package/dist/components/filter-menu.d.ts +57 -0
  143. package/dist/components/filter-menu.js +46 -0
  144. package/dist/components/header-bar.d.ts +84 -0
  145. package/dist/components/header-bar.js +94 -0
  146. package/dist/components/hold-button.d.ts +15 -0
  147. package/dist/components/hold-button.js +88 -0
  148. package/dist/components/icon-tile.d.ts +12 -0
  149. package/dist/components/icon-tile.js +29 -0
  150. package/dist/components/info-tip.d.ts +13 -0
  151. package/dist/components/info-tip.js +26 -0
  152. package/dist/components/input.d.ts +17 -0
  153. package/dist/components/input.js +83 -0
  154. package/dist/components/kbd.d.ts +6 -0
  155. package/dist/components/kbd.js +7 -0
  156. package/dist/components/menu-item.d.ts +56 -0
  157. package/dist/components/menu-item.js +94 -0
  158. package/dist/components/message-composer.d.ts +75 -0
  159. package/dist/components/message-composer.js +199 -0
  160. package/dist/components/nav-rail.d.ts +31 -0
  161. package/dist/components/nav-rail.js +85 -0
  162. package/dist/components/notice.d.ts +45 -0
  163. package/dist/components/notice.js +66 -0
  164. package/dist/components/optimistic-undo.d.ts +28 -0
  165. package/dist/components/optimistic-undo.js +43 -0
  166. package/dist/components/option-row.d.ts +15 -0
  167. package/dist/components/option-row.js +14 -0
  168. package/dist/components/page-content.d.ts +11 -0
  169. package/dist/components/page-content.js +31 -0
  170. package/dist/components/pagination.d.ts +34 -0
  171. package/dist/components/pagination.js +41 -0
  172. package/dist/components/popover.d.ts +27 -0
  173. package/dist/components/popover.js +25 -0
  174. package/dist/components/progress.d.ts +33 -0
  175. package/dist/components/progress.js +75 -0
  176. package/dist/components/radio-group.d.ts +7 -0
  177. package/dist/components/radio-group.js +33 -0
  178. package/dist/components/readonly-field.d.ts +33 -0
  179. package/dist/components/readonly-field.js +80 -0
  180. package/dist/components/segmented-control.d.ts +21 -0
  181. package/dist/components/segmented-control.js +108 -0
  182. package/dist/components/select.d.ts +42 -0
  183. package/dist/components/select.js +86 -0
  184. package/dist/components/separator.d.ts +10 -0
  185. package/dist/components/separator.js +7 -0
  186. package/dist/components/setting-row.d.ts +53 -0
  187. package/dist/components/setting-row.js +93 -0
  188. package/dist/components/sidebar-switcher.d.ts +47 -0
  189. package/dist/components/sidebar-switcher.js +20 -0
  190. package/dist/components/sidebar.d.ts +220 -0
  191. package/dist/components/sidebar.js +327 -0
  192. package/dist/components/skeleton.d.ts +18 -0
  193. package/dist/components/skeleton.js +23 -0
  194. package/dist/components/slider.d.ts +15 -0
  195. package/dist/components/slider.js +28 -0
  196. package/dist/components/spinner.d.ts +14 -0
  197. package/dist/components/spinner.js +19 -0
  198. package/dist/components/status-dot.d.ts +24 -0
  199. package/dist/components/status-dot.js +35 -0
  200. package/dist/components/stepper.d.ts +60 -0
  201. package/dist/components/stepper.js +197 -0
  202. package/dist/components/switch.d.ts +9 -0
  203. package/dist/components/switch.js +26 -0
  204. package/dist/components/table-cell.d.ts +38 -0
  205. package/dist/components/table-cell.js +107 -0
  206. package/dist/components/table-context.d.ts +48 -0
  207. package/dist/components/table-context.js +69 -0
  208. package/dist/components/table-head.d.ts +42 -0
  209. package/dist/components/table-head.js +188 -0
  210. package/dist/components/table-tree.d.ts +96 -0
  211. package/dist/components/table-tree.js +137 -0
  212. package/dist/components/table.d.ts +78 -0
  213. package/dist/components/table.js +119 -0
  214. package/dist/components/tabs.d.ts +27 -0
  215. package/dist/components/tabs.js +79 -0
  216. package/dist/components/textarea.d.ts +3 -0
  217. package/dist/components/textarea.js +20 -0
  218. package/dist/components/theme.d.ts +41 -0
  219. package/dist/components/theme.js +60 -0
  220. package/dist/components/thinking.d.ts +68 -0
  221. package/dist/components/thinking.js +94 -0
  222. package/dist/components/toast.d.ts +39 -0
  223. package/dist/components/toast.js +110 -0
  224. package/dist/components/toolbar.d.ts +25 -0
  225. package/dist/components/toolbar.js +92 -0
  226. package/dist/components/tooltip.d.ts +23 -0
  227. package/dist/components/tooltip.js +27 -0
  228. package/dist/components/top-nav.d.ts +129 -0
  229. package/dist/components/top-nav.js +211 -0
  230. package/dist/components/truncate.d.ts +29 -0
  231. package/dist/components/truncate.js +138 -0
  232. package/dist/deprecated.d.ts +43 -0
  233. package/dist/deprecated.js +47 -0
  234. package/dist/index.d.ts +93 -0
  235. package/dist/index.js +93 -0
  236. package/dist/lib/cn.d.ts +5 -0
  237. package/dist/lib/cn.js +14 -0
  238. package/dist/lib/color.d.ts +136 -0
  239. package/dist/lib/color.js +307 -0
  240. package/dist/lib/contrast.d.ts +53 -0
  241. package/dist/lib/contrast.js +169 -0
  242. package/dist/lib/create-theme.d.ts +240 -0
  243. package/dist/lib/create-theme.js +461 -0
  244. package/dist/lib/harmony.d.ts +102 -0
  245. package/dist/lib/harmony.js +426 -0
  246. package/dist/lib/import-theme.d.ts +22 -0
  247. package/dist/lib/import-theme.js +221 -0
  248. package/dist/lib/overflow-scroll.d.ts +25 -0
  249. package/dist/lib/overflow-scroll.js +66 -0
  250. package/dist/lib/radio-toggle-render.d.ts +3 -0
  251. package/dist/lib/radio-toggle-render.js +9 -0
  252. package/dist/lib/reorder.d.ts +38 -0
  253. package/dist/lib/reorder.js +193 -0
  254. package/dist/lib/spacing.d.ts +101 -0
  255. package/dist/lib/spacing.js +118 -0
  256. package/dist/lib/tailwind-palette.d.ts +5 -0
  257. package/dist/lib/tailwind-palette.js +351 -0
  258. package/dist/lib/truncate.d.ts +18 -0
  259. package/dist/lib/truncate.js +69 -0
  260. package/dist/lib/use-single-value.d.ts +5 -0
  261. package/dist/lib/use-single-value.js +17 -0
  262. package/dist/styles.css +7988 -0
  263. package/mcp/server.mjs +87590 -0
  264. package/package.json +58 -5
  265. package/skills/continuum-fix-padding/SKILL.md +69 -0
  266. package/skills/continuum-fix-padding/scripts/compute.ts +155 -0
  267. package/skills/continuum-fix-padding/scripts/spacing.ts +189 -0
  268. package/skills/continuum-taste/SKILL.md +186 -0
  269. package/skills/continuum-taste/assets/tokens.css +647 -0
  270. package/skills/continuum-taste/references/charts.md +375 -0
  271. package/skills/continuum-taste/references/components.md +1369 -0
  272. package/skills/continuum-taste/references/foundations.md +539 -0
  273. package/skills/continuum-taste/references/media/canvas.md +75 -0
  274. package/skills/continuum-taste/references/media/css.md +61 -0
  275. package/skills/continuum-taste/references/media/react.md +161 -0
  276. package/skills/continuum-taste/references/method.md +87 -0
  277. package/skills/continuum-taste/references/pages.md +391 -0
  278. package/skills/continuum-taste/references/patterns.md +77 -0
  279. package/skills/continuum-taste/references/screens/agent.tsx +450 -0
  280. package/skills/continuum-taste/references/screens/analytics-overview.tsx +377 -0
  281. package/skills/continuum-taste/references/screens/checkout-funnel.tsx +193 -0
  282. package/skills/continuum-taste/references/screens/customer.tsx +475 -0
  283. package/skills/continuum-taste/references/screens/customers.tsx +608 -0
  284. package/skills/continuum-taste/references/screens/index.tsx +72 -0
  285. package/skills/continuum-taste/references/screens/invoice-editor.tsx +558 -0
  286. package/skills/continuum-taste/references/screens/new-customer.tsx +205 -0
  287. package/skills/continuum-taste/references/screens/overview.tsx +196 -0
  288. package/skills/continuum-taste/references/screens/report-generator.tsx +329 -0
  289. package/skills/continuum-taste/references/screens/risk-report.tsx +577 -0
  290. package/skills/continuum-taste/references/screens/sequence-editor.tsx +455 -0
  291. package/skills/continuum-taste/references/screens/settings.tsx +288 -0
  292. package/skills/continuum-taste/references/screens/shared.tsx +204 -0
  293. package/skills/continuum-taste/references/screens/sign-in.tsx +104 -0
  294. package/skills/continuum-taste/references/screens/workspace.tsx +596 -0
  295. package/skills/continuum-taste/references/theming.md +95 -0
  296. package/src/charts/area-chart.tsx +17 -0
  297. package/src/charts/bar-chart.tsx +15 -0
  298. package/src/charts/bubble-chart.tsx +913 -0
  299. package/src/charts/bullet-chart.tsx +419 -0
  300. package/src/charts/candlestick-chart.tsx +1242 -0
  301. package/src/charts/cartesian.tsx +1437 -0
  302. package/src/charts/chart-card.tsx +394 -0
  303. package/src/charts/donut-chart.tsx +299 -0
  304. package/src/charts/funnel-chart.tsx +373 -0
  305. package/src/charts/horizontal-bar-chart.tsx +991 -0
  306. package/src/charts/index.ts +76 -0
  307. package/src/charts/legend.tsx +59 -0
  308. package/src/charts/lib/candlestick-window.ts +42 -0
  309. package/src/charts/lib/color.ts +110 -0
  310. package/src/charts/lib/format.ts +42 -0
  311. package/src/charts/lib/frame.ts +6 -0
  312. package/src/charts/lib/layout.ts +78 -0
  313. package/src/charts/lib/path.ts +225 -0
  314. package/src/charts/lib/scale.ts +91 -0
  315. package/src/charts/lib/use-active.ts +87 -0
  316. package/src/charts/lib/use-size.ts +45 -0
  317. package/src/charts/line-chart.tsx +16 -0
  318. package/src/charts/radar-chart.tsx +485 -0
  319. package/src/charts/rose-chart.tsx +553 -0
  320. package/src/charts/sparkline.tsx +293 -0
  321. package/src/charts/tooltip.tsx +105 -0
  322. package/src/charts/treemap.tsx +271 -0
  323. package/src/charts/uptime-strip.tsx +469 -0
  324. package/src/components/accordion.tsx +136 -0
  325. package/src/components/activity-item.tsx +43 -0
  326. package/src/components/alert.tsx +135 -0
  327. package/src/components/assistant-answer.tsx +185 -0
  328. package/src/components/assistant-prompt.tsx +352 -0
  329. package/src/components/avatar.tsx +157 -0
  330. package/src/components/badge.tsx +55 -0
  331. package/src/components/bar-list.tsx +350 -0
  332. package/src/components/block-slider.tsx +189 -0
  333. package/src/components/branch-graph.tsx +580 -0
  334. package/src/components/breadcrumb.tsx +173 -0
  335. package/src/components/button.tsx +157 -0
  336. package/src/components/calendar.tsx +154 -0
  337. package/src/components/card.tsx +296 -0
  338. package/src/components/chat-attachment.tsx +255 -0
  339. package/src/components/chat-event.tsx +34 -0
  340. package/src/components/chat-message.tsx +332 -0
  341. package/src/components/chat-reference.tsx +100 -0
  342. package/src/components/chat-shared.ts +41 -0
  343. package/src/components/chat-suggestions.tsx +188 -0
  344. package/src/components/chat-thread.tsx +348 -0
  345. package/src/components/chat-typing.tsx +155 -0
  346. package/src/components/checkbox.tsx +83 -0
  347. package/src/components/checklist.tsx +146 -0
  348. package/src/components/chip.tsx +152 -0
  349. package/src/components/code-input.tsx +406 -0
  350. package/src/components/color-picker.tsx +1385 -0
  351. package/src/components/combobox.tsx +420 -0
  352. package/src/components/command-menu.tsx +405 -0
  353. package/src/components/copy-button.tsx +87 -0
  354. package/src/components/data-grid.tsx +965 -0
  355. package/src/components/date-picker.tsx +652 -0
  356. package/src/components/description-list.tsx +39 -0
  357. package/src/components/dialog.tsx +367 -0
  358. package/src/components/dock.tsx +192 -0
  359. package/src/components/drop-zone.tsx +283 -0
  360. package/src/components/dropdown-menu.tsx +323 -0
  361. package/src/components/editable-cell.tsx +219 -0
  362. package/src/components/empty-state.tsx +50 -0
  363. package/src/components/field.tsx +148 -0
  364. package/src/components/filter-condition.tsx +463 -0
  365. package/src/components/filter-menu.tsx +196 -0
  366. package/src/components/header-bar.tsx +220 -0
  367. package/src/components/hold-button.tsx +146 -0
  368. package/src/components/icon-tile.tsx +43 -0
  369. package/src/components/info-tip.tsx +87 -0
  370. package/src/components/input.tsx +136 -0
  371. package/src/components/kbd.tsx +17 -0
  372. package/src/components/menu-item.tsx +216 -0
  373. package/src/components/message-composer.tsx +458 -0
  374. package/src/components/nav-rail.tsx +235 -0
  375. package/src/components/notice.tsx +133 -0
  376. package/src/components/optimistic-undo.ts +68 -0
  377. package/src/components/option-row.tsx +54 -0
  378. package/src/components/page-content.tsx +44 -0
  379. package/src/components/pagination.tsx +182 -0
  380. package/src/components/popover.tsx +113 -0
  381. package/src/components/progress.tsx +222 -0
  382. package/src/components/radio-group.tsx +80 -0
  383. package/src/components/readonly-field.tsx +251 -0
  384. package/src/components/segmented-control.tsx +205 -0
  385. package/src/components/select.tsx +259 -0
  386. package/src/components/separator.tsx +30 -0
  387. package/src/components/setting-row.tsx +277 -0
  388. package/src/components/sidebar-switcher.tsx +134 -0
  389. package/src/components/sidebar.tsx +804 -0
  390. package/src/components/skeleton.tsx +57 -0
  391. package/src/components/slider.tsx +106 -0
  392. package/src/components/spinner.tsx +43 -0
  393. package/src/components/status-dot.tsx +100 -0
  394. package/src/components/stepper.tsx +459 -0
  395. package/src/components/switch.tsx +54 -0
  396. package/src/components/table-cell.tsx +239 -0
  397. package/src/components/table-context.ts +135 -0
  398. package/src/components/table-head.tsx +393 -0
  399. package/src/components/table-tree.tsx +357 -0
  400. package/src/components/table.tsx +295 -0
  401. package/src/components/tabs.tsx +191 -0
  402. package/src/components/textarea.tsx +44 -0
  403. package/src/components/theme.tsx +120 -0
  404. package/src/components/thinking.tsx +295 -0
  405. package/src/components/toast.tsx +308 -0
  406. package/src/components/toolbar.tsx +166 -0
  407. package/src/components/tooltip.tsx +84 -0
  408. package/src/components/top-nav.tsx +660 -0
  409. package/src/components/truncate.tsx +234 -0
  410. package/src/deprecated.ts +61 -0
  411. package/src/index.ts +184 -0
  412. package/src/lib/cn.ts +22 -0
  413. package/src/lib/color.ts +469 -0
  414. package/src/lib/contrast.ts +220 -0
  415. package/src/lib/create-theme.ts +659 -0
  416. package/src/lib/harmony.ts +609 -0
  417. package/src/lib/import-theme.ts +272 -0
  418. package/src/lib/overflow-scroll.tsx +108 -0
  419. package/src/lib/radio-toggle-render.tsx +15 -0
  420. package/src/lib/reorder.ts +222 -0
  421. package/src/lib/spacing.ts +189 -0
  422. package/src/lib/tailwind-palette.ts +355 -0
  423. package/src/lib/truncate.ts +79 -0
  424. package/src/lib/use-single-value.ts +23 -0
  425. package/src/styles/continuum.css +3 -0
  426. package/src/styles/theme.css +524 -0
  427. package/src/styles/tokens.css +647 -0
@@ -0,0 +1,625 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { createContext, useCallback, useContext, useEffect, useId, useMemo, } from 'react';
4
+ import { cn } from '../lib/cn.js';
5
+ import { chartColor, seriesColor } from './lib/color.js';
6
+ import { formatCompact, formatNumber, formatX as formatXValue } from './lib/format.js';
7
+ import { PLOT_FRAME } from './lib/frame.js';
8
+ import { areaPath, curvePath, lineAreaPath, linePath, stepAreaPath, stepPath, } from './lib/path.js';
9
+ import { extent, niceTicks, scalePoint, scaleY, slotScale } from './lib/scale.js';
10
+ import { useActive } from './lib/use-active.js';
11
+ import { useLabelWidth, useWidth } from './lib/use-size.js';
12
+ import { ChartTooltip } from './tooltip.js';
13
+ /** Room for the labels, and the sizes of the marks. Everything else follows the theme. */
14
+ const GUTTER_GAP = 8;
15
+ /** The row of x labels under the plot: the gap to it and one line of labels, no more. */
16
+ const AXIS_HEIGHT = 20;
17
+ /** The room between the plot's frame and the marks in it: none, the frame holds the data tight. */
18
+ const PAD = 0;
19
+ const TOP = 8;
20
+ /** A marker's label: its inset above the plot's foot, and its gap from the rule. */
21
+ const LABEL_INSET = 4;
22
+ const LABEL_GAP = 4;
23
+ /** Labels that would touch stack upward a row at a time, 4 apart, never over each other. */
24
+ const LABEL_ROW = 20;
25
+ const LABEL_SPACE = 4;
26
+ const X_LABEL_GAP = 16;
27
+ const TOOLTIP_OFFSET = 12;
28
+ const DOT_RADIUS = 4;
29
+ const BAR_GAP = 2;
30
+ const BAR_MAX = 28;
31
+ const BAR_MIN = 2;
32
+ /** A bar takes half its slot, and a group of bars seven tenths of it. */
33
+ const BAR_SHARE = 0.5;
34
+ const GROUP_SHARE = 0.7;
35
+ /** A date axis is read in five places at most: a reader counts dates, not ticks. */
36
+ const DATE_TICKS = 5;
37
+ /**
38
+ * Past this many points the marks are drawn finer. A 2px stroke is right for a week, where
39
+ * the line is the subject; over a year it is a rope, and the shape of the data is lost inside
40
+ * its own weight. The hairline the rest of the system is built from is right at that density.
41
+ */
42
+ const DENSE = 120;
43
+ /**
44
+ * The most marks a plot draws. Past this the readings are gathered into even periods and the
45
+ * period's average is drawn, because a year of daily readings has a weekly rhythm in it and
46
+ * that rhythm is all a reader sees: the trend, the slump and the bad week it is made of are
47
+ * lost inside a sawtooth. The spread each average came from is drawn behind it, so nothing
48
+ * is hidden — the shape of the data is the band, not a line through the middle of it.
49
+ */
50
+ const MARKS = 60;
51
+ /**
52
+ * The least a mark may be given. Sixty readings are comfortable across a card and a crowd on a
53
+ * phone, so how many are drawn follows the room there is: the same data gathers into longer
54
+ * periods on a narrow plot rather than turning to hatching.
55
+ */
56
+ const MARK_GAP = 8;
57
+ const LEAST_MARKS = 12;
58
+ /** Nothing to gather while the readings are few enough for the room to draw one by one. */
59
+ const periodsFor = (count, plotWidth) => {
60
+ const marks = Math.max(LEAST_MARKS, Math.min(MARKS, Math.floor(plotWidth / MARK_GAP)));
61
+ // Gathering two readings into one is not worth the lie; it starts once there are half again.
62
+ if (count <= marks * 1.5)
63
+ return null;
64
+ const size = count / marks;
65
+ return Array.from({ length: marks }, (_, i) => ({
66
+ from: Math.round(i * size),
67
+ to: Math.max(Math.round(i * size) + 1, Math.round((i + 1) * size)),
68
+ }));
69
+ };
70
+ const mean = (values, { from, to }) => {
71
+ let total = 0;
72
+ for (let i = from; i < to; i++)
73
+ total += values[i] ?? 0;
74
+ return total / Math.max(1, to - from);
75
+ };
76
+ const ChartContext = createContext(null);
77
+ /** The plot's coordinates, for an overlay drawn as a chart's child. */
78
+ export const useChart = () => {
79
+ const value = useContext(ChartContext);
80
+ if (!value)
81
+ throw new Error('useChart() is only for a chart’s own children.');
82
+ return value;
83
+ };
84
+ const toNumber = (value) => typeof value === 'number' && Number.isFinite(value) ? value : 0;
85
+ const colorOf = (line, index) => line.muted ? chartColor('neutral') : chartColor(line.color ?? seriesColor(index));
86
+ /** The indices to label, spread evenly, the first and last always among them. */
87
+ const labelIndices = (count, wanted) => {
88
+ if (count === 0)
89
+ return [];
90
+ const take = Math.max(1, Math.min(wanted, count));
91
+ if (take === 1)
92
+ return [0];
93
+ const indices = new Set();
94
+ for (let i = 0; i < take; i++)
95
+ indices.add(Math.round((i * (count - 1)) / (take - 1)));
96
+ return [...indices].sort((a, b) => a - b);
97
+ };
98
+ export const Cartesian = ({ 'aria-label': label, data: rows, x: xKey, series, kind, stacked = false, height = 240, formatX, formatTitle, formatY, formatValue, yMax, xTicks, yTicks = 4, markers, curve = 'smooth', points: showPoints = false, texture, fill = 'solid', incompleteFrom, tooltip = true, grid = true, xAxis = true, yAxis = true, onSelect, onRead, loading = false, emptyLabel = 'No data yet', className, style, children, }) => {
99
+ // React's own ids carry characters a URL fragment should not, so they are stripped.
100
+ const gradientId = useId().replace(/[^a-zA-Z0-9_-]/g, '');
101
+ const [containerRef, width] = useWidth();
102
+ const [yProbeRef, yLabelWidth] = useLabelWidth();
103
+ const [xProbeRef, xLabelWidth] = useLabelWidth();
104
+ /*
105
+ * While it loads a chart draws its skeleton and nothing else. Holding the last rows at half
106
+ * strength is not a loading state: it is the old answer looking unwell, and a reader cannot
107
+ * tell whether to trust it.
108
+ */
109
+ const data = loading ? [] : rows;
110
+ const empty = data.length === 0;
111
+ const writeAxis = formatY ?? formatCompact;
112
+ const writeValue = formatValue ?? formatY ?? formatNumber;
113
+ const bars = kind === 'bar';
114
+ // The plot is what the labels leave. It is known before the marks, because how many marks
115
+ // there is room for decides how the readings are gathered.
116
+ // While loading, the value axis keeps its column, so the plot does not widen and then narrow
117
+ // when the data lands: measured from the rows' labels when there are rows, else a short one.
118
+ const left = (yAxis && (!empty || loading) ? yLabelWidth + GUTTER_GAP : 0) + PAD;
119
+ const top = TOP;
120
+ const bottom = (xAxis ? AXIS_HEIGHT : 0) + PAD;
121
+ const plotWidth = Math.max(0, width - left - PAD);
122
+ const plotHeight = Math.max(0, height - top - bottom);
123
+ // Every series' numbers as given, before any gathering.
124
+ const readings = useMemo(() => series.map(line => data.map(row => toNumber(row[line.key]))), [data, series]);
125
+ /*
126
+ * What is actually drawn. Few enough readings and it is the readings themselves; past that
127
+ * it is one mark per period, holding the period's average and the spread it came from.
128
+ */
129
+ const periods = useMemo(() => (bars ? null : periodsFor(data.length, plotWidth)), [bars, data.length, plotWidth]);
130
+ const columns = useMemo(() => periods
131
+ ? readings.map(values => periods.map(period => mean(values, period)))
132
+ : readings, [periods, readings]);
133
+ /** The row each mark stands for: the reading itself, or the period's first. */
134
+ const rowAt = useCallback((index) => data[periods ? (periods[index]?.from ?? 0) : index], [data, periods]);
135
+ const marksCount = periods ? periods.length : data.length;
136
+ /**
137
+ * A row of the data as the mark that now carries it. Anything a caller points at — a marker,
138
+ * the row a period stops being measured at — names a row, and must follow it into its period.
139
+ */
140
+ const markOf = (row) => {
141
+ if (!periods)
142
+ return Math.max(0, Math.min(marksCount - 1, row));
143
+ const found = periods.findIndex(period => row < period.to);
144
+ return found === -1 ? periods.length - 1 : found;
145
+ };
146
+ const cutAt = incompleteFrom === undefined ? undefined : markOf(incompleteFrom);
147
+ const sums = useMemo(() => stacked && bars
148
+ ? data.map((_, i) => columns.reduce((total, column) => total + (column[i] ?? 0), 0))
149
+ : [], [bars, columns, data, stacked]);
150
+ const ticks = useMemo(() => {
151
+ const span = extent(stacked && bars ? sums : columns.flat());
152
+ return niceTicks(span.min, span.max, yTicks, yMax);
153
+ }, [bars, columns, stacked, sums, yMax, yTicks]);
154
+ const yLabels = useMemo(() => ticks.values.map(writeAxis), [ticks, writeAxis]);
155
+ // The labels the value axis is measured from while loading: the ones the given rows will have,
156
+ // or a short stand-in when there are none yet. They are measured, never drawn.
157
+ const heldLabels = useMemo(() => {
158
+ if (!loading)
159
+ return yLabels;
160
+ if (rows.length === 0)
161
+ return [writeAxis(1000)];
162
+ const values = rows.map(row => series.map(line => toNumber(row[line.key])));
163
+ const span = extent(stacked && bars
164
+ ? values.map(row => row.reduce((total, value) => total + value, 0))
165
+ : values.flat());
166
+ return niceTicks(span.min, span.max, yTicks, yMax).values.map(writeAxis);
167
+ }, [bars, loading, rows, series, stacked, writeAxis, yLabels, yMax, yTicks]);
168
+ const labelOf = useCallback((row, i) => {
169
+ const value = row?.[xKey];
170
+ return row && formatX ? formatX(value, row, i) : formatXValue(value);
171
+ }, [formatX, xKey]);
172
+ // One label per mark; the table below keeps a label for every reading.
173
+ const xLabels = useMemo(() => Array.from({ length: marksCount }, (_, i) => labelOf(rowAt(i), i)), [labelOf, marksCount, rowAt]);
174
+ const rawLabels = useMemo(() => data.map(labelOf), [data, labelOf]);
175
+ const slots = useMemo(() => slotScale(data.length, plotWidth), [data.length, plotWidth]);
176
+ const xOf = useMemo(() => (index) => left + (bars ? slots.center(index) : scalePoint(index, marksCount, plotWidth)), [bars, marksCount, left, plotWidth, slots]);
177
+ const yOf = useMemo(() => (value) => top + scaleY(value, ticks, plotHeight), [plotHeight, ticks]);
178
+ const baseline = yOf(Math.max(ticks.min, 0));
179
+ const { active, handlers } = useActive(marksCount, xOf);
180
+ const readable = tooltip !== false && !empty;
181
+ // The plot still answers the pointer when a card reads it out in place of the panel.
182
+ const hoverable = (readable || !!onRead) && !empty;
183
+ const activeRow = active !== null ? rowAt(active) : undefined;
184
+ // Only as many x labels as fit without touching, however many were asked for.
185
+ const shown = useMemo(() => {
186
+ if (!xAxis || empty)
187
+ return [];
188
+ const room = Math.max(1, Math.floor((plotWidth + X_LABEL_GAP) / Math.max(1, xLabelWidth + X_LABEL_GAP)));
189
+ const dates = data[0]?.[xKey] instanceof Date;
190
+ const wanted = xTicks ?? (dates ? DATE_TICKS : marksCount);
191
+ return labelIndices(marksCount, Math.min(wanted, room));
192
+ }, [data, empty, marksCount, plotWidth, xAxis, xKey, xLabelWidth, xTicks]);
193
+ // The marks do not depend on the pointer, so moving it never redraws them.
194
+ const marks = useMemo(() => {
195
+ if (empty || bars || plotWidth <= 0 || plotHeight <= 0)
196
+ return null;
197
+ // A muted series sits under the rest, whatever order it was given in.
198
+ const order = series.map((line, index) => ({ line, index }));
199
+ order.sort((a, b) => Number(b.line.muted ?? false) - Number(a.line.muted ?? false));
200
+ return order.map(({ line, index }) => {
201
+ const column = columns[index] ?? [];
202
+ const color = colorOf(line, index);
203
+ const points = Array.from({ length: marksCount }, (_, i) => ({
204
+ x: xOf(i),
205
+ y: yOf(column[i] ?? 0),
206
+ }));
207
+ const solid = cutAt === undefined ? points : points.slice(0, cutAt + 1);
208
+ const dashed = cutAt === undefined ? [] : points.slice(cutAt);
209
+ const dense = marksCount > DENSE;
210
+ const stroke = dense ? 1 : line.muted ? 1.5 : 2;
211
+ // Many readings are drawn straight whatever was asked: see the curve prop.
212
+ const shape = dense ? 'linear' : curve;
213
+ const draw = shape === 'step' ? stepPath : shape === 'linear' ? linePath : curvePath;
214
+ const fillUnder = shape === 'step' ? stepAreaPath : shape === 'linear' ? lineAreaPath : areaPath;
215
+ /*
216
+ * A fill reads under one or two series; past that they are lines. Dense, it reads
217
+ * under one alone: a year of daily readings has a weekly rhythm in it, and two
218
+ * sawtooth washes over each other are mud whatever colours they are.
219
+ */
220
+ const filled = kind === 'area' && !line.muted && series.length <= (dense ? 1 : 2);
221
+ return (_jsxs("g", { "data-slot": "chart-series", children: [filled && (
222
+ /*
223
+ * The tint holds all the way down rather than fading out, and stands
224
+ * on a rounded foot: the fill's own edge is the baseline.
225
+ */
226
+ _jsxs("g", { style: {
227
+ clipPath: 'inset(0 round 0 0 var(--radius-item) var(--radius-item))',
228
+ }, children: [_jsxs("defs", { children: [_jsxs("linearGradient", { gradientUnits: "userSpaceOnUse", id: `${gradientId}-${index}`, x1: 0, x2: 0, y1: yOf(extent(column).max), y2: baseline, children: [_jsx("stop", { offset: "0%", stopColor: color, stopOpacity: 0.2 }), _jsx("stop", { offset: "100%", stopColor: color, stopOpacity: 0.08 })] }), _jsx("pattern", { height: 7, id: `${gradientId}-${index}-stripes`, patternTransform: "rotate(45)", patternUnits: "userSpaceOnUse", width: 7, children: _jsx("line", { stroke: color, strokeWidth: 1.2, x1: 0, x2: 0, y1: 0, y2: 7 }) }), _jsx("pattern", { height: 6, id: `${gradientId}-${index}-dots`, patternUnits: "userSpaceOnUse", width: 6, children: _jsx("circle", { cx: 3, cy: 3, fill: color, r: 1.1 }) }), _jsxs("linearGradient", { id: `${gradientId}-fade`, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: "white", stopOpacity: 0.55 }), _jsx("stop", { offset: "100%", stopColor: "white", stopOpacity: 0.12 })] }), _jsx("mask", { id: `${gradientId}-${index}-thin`, maskContentUnits: "objectBoundingBox", children: _jsx("rect", { fill: `url(#${gradientId}-fade)`, height: 1, width: 1 }) })] }), _jsx("path", { d: fillUnder(points, baseline), fill: `url(#${gradientId}-${index})` }), (line.texture ?? texture) !== 'none' &&
229
+ ['stripes', 'dots']
230
+ .filter(kindOf => !(line.texture ?? texture) ||
231
+ (line.texture ?? texture) === kindOf)
232
+ .map(kindOf => (_jsx("path", { d: fillUnder(points, baseline), fill: `url(#${gradientId}-${index}-${kindOf})`, mask: `url(#${gradientId}-${index}-thin)`,
233
+ // Asked for outright it shows; otherwise the theme says.
234
+ style: (line.texture ?? texture)
235
+ ? undefined
236
+ : {
237
+ opacity: `var(--chart-texture-${kindOf}, 0)`,
238
+ } }, kindOf)))] })), points.length === 1 && points[0] ? (
239
+ // One reading has no line in it; drawn as a line it would be nothing at all.
240
+ _jsx("circle", { cx: points[0].x, cy: points[0].y, fill: color, r: 3 })) : (_jsx("path", { d: draw(solid), fill: "none", stroke: color, strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: stroke })), showPoints &&
241
+ !dense &&
242
+ points.map(point => (
243
+ // Where a reading was actually taken, for a chart of few enough of them.
244
+ _jsx("circle", { cx: point.x, cy: point.y, fill: "var(--color-chart-background)", r: 2.5, stroke: color, strokeWidth: 1.5 }, `${point.x},${point.y}`))), dashed.length > 1 && (
245
+ // The period is not over, so its last stretch is not a measured value.
246
+ _jsx("path", { d: draw(dashed), fill: "none", stroke: color, strokeDasharray: "6 4", strokeLinecap: "round", strokeWidth: stroke }))] }, line.key));
247
+ });
248
+ }, [
249
+ bars,
250
+ baseline,
251
+ columns,
252
+ curve,
253
+ cutAt,
254
+ empty,
255
+ showPoints,
256
+ texture,
257
+ gradientId,
258
+ kind,
259
+ marksCount,
260
+ plotHeight,
261
+ plotWidth,
262
+ series,
263
+ xOf,
264
+ yOf,
265
+ ]);
266
+ const barLayout = useMemo(() => {
267
+ if (!bars || empty || plotWidth <= 0)
268
+ return [];
269
+ const count = series.length;
270
+ const grouped = !stacked && count > 1;
271
+ const groupWidth = grouped
272
+ ? Math.min(slots.slot * GROUP_SHARE, BAR_MAX * count + BAR_GAP * (count - 1))
273
+ : Math.min(slots.slot * BAR_SHARE, BAR_MAX);
274
+ const barWidth = Math.max(BAR_MIN, grouped ? (groupWidth - BAR_GAP * (count - 1)) / count : groupWidth);
275
+ return data.flatMap((_, row) => {
276
+ let up = baseline;
277
+ let down = baseline;
278
+ return series.map((line, index) => {
279
+ const value = columns[index]?.[row] ?? 0;
280
+ const positive = value >= 0;
281
+ const size = Math.abs(yOf(value) - baseline);
282
+ const center = xOf(row);
283
+ const x = grouped
284
+ ? center - groupWidth / 2 + index * (barWidth + BAR_GAP)
285
+ : center - barWidth / 2;
286
+ const shared = {
287
+ key: `${row}-${line.key}`,
288
+ color: colorOf(line, index),
289
+ tinted: (line.fill ?? fill) === 'tint',
290
+ texture: line.texture ?? texture,
291
+ width: barWidth,
292
+ positive,
293
+ x,
294
+ };
295
+ if (!stacked)
296
+ return {
297
+ ...shared,
298
+ height: size,
299
+ head: true,
300
+ y: positive ? yOf(value) : baseline,
301
+ };
302
+ // A stacked segment starts where the one under it stopped, two pixels clear of it.
303
+ const from = positive ? up : down;
304
+ const gap = from === baseline ? 0 : BAR_GAP;
305
+ if (positive)
306
+ up = from - size;
307
+ else
308
+ down = from + size;
309
+ return {
310
+ ...shared,
311
+ height: Math.max(0, size - gap),
312
+ // Only the stack's head is rounded; where two segments meet it is square.
313
+ head: index === count - 1,
314
+ y: positive ? from - size : from + gap,
315
+ };
316
+ });
317
+ });
318
+ }, [
319
+ bars,
320
+ baseline,
321
+ columns,
322
+ data,
323
+ empty,
324
+ fill,
325
+ plotWidth,
326
+ series,
327
+ slots,
328
+ stacked,
329
+ texture,
330
+ xOf,
331
+ yOf,
332
+ ]);
333
+ const context = {
334
+ data,
335
+ width,
336
+ height,
337
+ plot: { left, top, width: plotWidth, height: plotHeight },
338
+ xOf,
339
+ yOf,
340
+ activeIndex: active,
341
+ };
342
+ const tooltipRows = (index) => series.map((line, i) => ({
343
+ color: (line.muted ? 'neutral' : (line.color ?? seriesColor(i))),
344
+ name: line.name ?? line.key,
345
+ value: writeValue(columns[i]?.[index] ?? 0),
346
+ }));
347
+ /**
348
+ * A gathered chart says so: the readout names the period it covers and the low to high the
349
+ * average was taken from, which is the only place the band behind the line is explained.
350
+ */
351
+ const periodFooter = (index) => {
352
+ const period = periods?.[index];
353
+ if (!period || series.length !== 1)
354
+ return undefined;
355
+ const low = Math.min(...(readings[0] ?? []).slice(period.from, period.to));
356
+ const high = Math.max(...(readings[0] ?? []).slice(period.from, period.to));
357
+ const days = period.to - period.from;
358
+ return (_jsxs("span", { className: "flex items-center justify-between gap-4", children: [_jsxs("span", { className: "text-neutral-600 text-xs", children: [days, " days, low to high"] }), _jsxs("span", { className: "font-medium text-neutral-950 text-xs tabular-nums", children: [writeValue(low), "\u2013", writeValue(high)] })] }));
359
+ };
360
+ const titleOf = (index) => {
361
+ const row = rowAt(index);
362
+ if (!row)
363
+ return '';
364
+ const value = row[xKey];
365
+ if (formatTitle)
366
+ return formatTitle(value, row, index);
367
+ const period = periods?.[index];
368
+ if (period) {
369
+ const last = data[period.to - 1];
370
+ const from = labelOf(row, index);
371
+ const to = last ? labelOf(last, period.to - 1) : from;
372
+ return from === to ? from : `${from} – ${to}`;
373
+ }
374
+ if (formatX)
375
+ return formatX(value, row, index);
376
+ return formatXValue(value, true);
377
+ };
378
+ // biome-ignore lint/correctness/useExhaustiveDependencies: a reading is told when the point changes, not on every render
379
+ useEffect(() => {
380
+ if (!onRead)
381
+ return;
382
+ onRead(active === null || !rowAt(active)
383
+ ? null
384
+ : {
385
+ title: titleOf(active),
386
+ values: series.map((_, i) => writeValue(columns[i]?.[active] ?? 0)),
387
+ });
388
+ }, [active, columns]);
389
+ const readoutOf = (index) => `${titleOf(index)}: ${series
390
+ .map((line, i) => `${line.name ?? line.key} ${writeValue(columns[i]?.[index] ?? 0)}`)
391
+ .join(', ')}`;
392
+ return (_jsx(ChartContext.Provider, { value: context, children: _jsxs("figure", { "aria-busy": loading || undefined, "aria-label": label, className: cn('relative m-0 w-full', className), "data-slot": "chart", style: { height, ...style }, children: [_jsx("div", { "aria-hidden": true, className: "pointer-events-none invisible absolute top-0 left-0 w-max text-xxs tabular-nums", ref: yProbeRef, children: heldLabels.map(text => (_jsx("div", { children: text }, text))) }), _jsx("div", { "aria-hidden": true, className: "pointer-events-none invisible absolute top-0 left-0 w-max text-xxs tabular-nums", ref: xProbeRef, children: xLabels.map((text, i) => (_jsx("div", { children: text }, `${i}-${text}`))) }), _jsx("div", { className: cn('relative size-full transition-opacity duration-200 motion-reduce:transition-none',
393
+ // It appears once it knows how wide it is, rather than jumping into place.
394
+ width > 0 ? 'opacity-100' : 'opacity-0'), ref: containerRef, children: width > 0 && (_jsxs(_Fragment, { children: [_jsxs("svg", { "aria-hidden": "true", className: "block overflow-visible", height: height, width: width, children: [_jsx("defs", { children: _jsx("clipPath", { id: `${gradientId}-plot`, children: _jsx("rect", { height: plotHeight, style: {
395
+ rx: 'var(--radius-item)',
396
+ ry: 'var(--radius-item)',
397
+ }, width: plotWidth, x: left, y: top }) }) }), _jsx("g", { clipPath: `url(#${gradientId}-plot)`, children: grid &&
398
+ !loading &&
399
+ ticks.values
400
+ .filter(tick => !(kind === 'area' &&
401
+ series.length <= 2 &&
402
+ tick === Math.max(ticks.min, 0)))
403
+ .map(tick => (
404
+ // Half a pixel off the whole one, so a 1px rule lands crisp.
405
+ _jsx("line", { shapeRendering: "crispEdges", stroke: "var(--color-chart-grid)", x1: left, x2: left + plotWidth, y1: Math.round(yOf(tick)) + 0.5, y2: Math.round(yOf(tick)) + 0.5 }, tick))) }), yAxis &&
406
+ !empty &&
407
+ ticks.values.map((tick, i) => (_jsx("text", { className: "text-xxs tabular-nums", dominantBaseline: "middle", fill: "var(--color-chart-label)", textAnchor: "end", x: left - PAD - GUTTER_GAP, y: yOf(tick), children: yLabels[i] }, tick))), shown.map(index => (_jsx("text", { className: "text-xxs tabular-nums", fill: "var(--color-chart-label)", textAnchor: bars || (index > 0 && index < data.length - 1)
408
+ ? 'middle'
409
+ : index === 0
410
+ ? 'start'
411
+ : 'end', x: xOf(index), y: top + plotHeight + PAD + 16, children: xLabels[index] }, index))), _jsx("g", { clipPath: `url(#${gradientId}-plot)`, children: _jsx("g", { className: "motion-safe:animate-reveal", children: marks }) }), !bars && active !== null && (_jsxs("g", { "data-slot": "chart-crosshair", children: [_jsx("defs", { children: _jsxs("linearGradient", { id: `${gradientId}-crosshair`, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: "var(--color-chart-crosshair)", stopOpacity: "0" }), _jsx("stop", { offset: "14%", stopColor: "var(--color-chart-crosshair)", stopOpacity: "1" }), _jsx("stop", { offset: "86%", stopColor: "var(--color-chart-crosshair)", stopOpacity: "1" }), _jsx("stop", { offset: "100%", stopColor: "var(--color-chart-crosshair)", stopOpacity: "0" })] }) }), _jsx("rect", { fill: `url(#${gradientId}-crosshair)`, height: plotHeight, shapeRendering: "crispEdges", width: 1, x: Math.round(xOf(active)), y: top }), series.map((line, index) => (_jsx("circle", { cx: xOf(active), cy: yOf(columns[index]?.[active] ?? 0), fill: colorOf(line, index), r: DOT_RADIUS, stroke: "var(--color-chart-background)", strokeWidth: 2 }, line.key)))] })), markers?.map(marker => {
412
+ const at = markOf(marker.index);
413
+ const cx = xOf(at);
414
+ const foot = top + plotHeight;
415
+ return (
416
+ // A quiet rule over the plot's full height: a note about the
417
+ // data, never louder than the series it sits on.
418
+ _jsx("line", { shapeRendering: "crispEdges", stroke: "var(--color-neutral-400)", strokeDasharray: "3 3", x1: Math.round(cx) + 0.5, x2: Math.round(cx) + 0.5, y1: top, y2: foot }, `${marker.index}-${marker.label}`));
419
+ }), children] }), bars && (
420
+ // Held to the frame's rect and corner, as the SVG marks are.
421
+ _jsxs("div", { className: "pointer-events-none absolute overflow-hidden rounded-item", "data-slot": "chart-bars", style: { height: plotHeight, left, top, width: plotWidth }, children: [active !== null && (
422
+ // The hovered slot, on the item corner as a hovered row is.
423
+ _jsx("div", { className: "absolute rounded-item", style: {
424
+ background: 'var(--color-chart-band)',
425
+ height: plotHeight,
426
+ left: slots.slot * active + 2,
427
+ top: 0,
428
+ width: Math.max(0, slots.slot - 4),
429
+ } })), barLayout.map(bar => {
430
+ /*
431
+ * A bar stands flat on the baseline and is rounded at its
432
+ * head, on the item corner: rounded at one end, it never
433
+ * turns into a pill.
434
+ */
435
+ const head = bar.head
436
+ ? `min(var(--radius-item), ${bar.width / 2}px)`
437
+ : '0px';
438
+ const { tinted, texture: grain } = bar;
439
+ return (_jsx("div", { className: "absolute overflow-hidden", style: {
440
+ background: tinted
441
+ ? `color-mix(in oklab, ${bar.color} 20%, transparent)`
442
+ : bar.color,
443
+ borderRadius: bar.positive
444
+ ? `${head} ${head} 0 0`
445
+ : `0 0 ${head} ${head}`,
446
+ // The bar's own line at its data end, as a
447
+ // line stands over the tint under it.
448
+ boxShadow: tinted
449
+ ? `inset 0 ${bar.positive ? 2 : -2}px 0 ${bar.color}`
450
+ : undefined,
451
+ height: bar.height,
452
+ left: bar.x - left,
453
+ top: bar.y - top,
454
+ width: bar.width,
455
+ }, children: tinted &&
456
+ grain !== 'none' &&
457
+ ['stripes', 'dots']
458
+ .filter(kindOf => !grain || grain === kindOf)
459
+ .map(kindOf => (_jsx("span", { "aria-hidden": true, className: "absolute inset-0", style: {
460
+ background: TEXTURES[kindOf](bar.color),
461
+ // Asked for outright it shows; otherwise the theme says.
462
+ opacity: grain
463
+ ? 1
464
+ : `var(--chart-texture-${kindOf}, 0)`,
465
+ } }, kindOf))) }, bar.key));
466
+ })] })), markers &&
467
+ placeMarkerLabels(markers.map(marker => xOf(markOf(marker.index))), markers, left, left + plotWidth).map(({ marker, x, before, row }) => (_jsx(ChartMarkerLabel, { before: before, marker: marker, x: x, y: top + plotHeight - LABEL_INSET - row * LABEL_ROW }, `${marker.index}-${marker.label}`))), (!empty || loading) && (
468
+ // The plot's own place in the card: the marks and their grid inside, the labels out.
469
+ _jsx("div", { "aria-hidden": true, className: PLOT_FRAME, "data-slot": "chart-plot", style: {
470
+ height: plotHeight + PAD * 2,
471
+ left: left - PAD,
472
+ top: top - PAD,
473
+ width: plotWidth + PAD * 2,
474
+ } })), loading && (_jsx(ChartSkeleton, { height: plotHeight, kind: kind, left: left, top: top, width: plotWidth })), empty && !loading && (_jsx("p", { className: "absolute flex items-center justify-center text-neutral-600 text-xs", style: { height: plotHeight, left, top, width: plotWidth }, children: emptyLabel })), readable && active !== null && activeRow && (
475
+ /*
476
+ * The readout sits at the plot's top, on the side of the
477
+ * crosshair with more room. It holds that height whatever the
478
+ * pointer does: with two series there is no empty half to duck
479
+ * into, and a panel that jumps is worse than one that covers a
480
+ * little of a line the reader is not looking at.
481
+ */
482
+ _jsx("div", { className: "pointer-events-none absolute z-10", style: {
483
+ left: xOf(active) > width / 2
484
+ ? undefined
485
+ : xOf(active) + TOOLTIP_OFFSET,
486
+ right: xOf(active) > width / 2
487
+ ? width - (xOf(active) - TOOLTIP_OFFSET)
488
+ : undefined,
489
+ top,
490
+ }, children: typeof tooltip === 'function' ? (tooltip(activeRow, active)) : (_jsx(ChartTooltip, { footer: stacked && series.length > 1 ? (_jsx(ChartTooltipTotal, { value: writeValue(sums[active] ?? 0) })) : (periodFooter(active)), rows: tooltipRows(active),
491
+ // A bubble only where there is a rule to say it from.
492
+ tail: bars
493
+ ? 'none'
494
+ : xOf(active) > width / 2
495
+ ? 'right'
496
+ : 'left', title: titleOf(active) })) })), hoverable && (
497
+ // One tab stop over the plot: the arrow keys walk the points, and
498
+ // Enter picks the one being read, as a click on it would.
499
+ _jsx("button", { "aria-label": `${label}. Read each point with the arrow keys.`, className: cn('absolute rounded-xs outline-none focus-visible:outline-2 focus-visible:outline-focus focus-visible:outline-solid focus-visible:outline-offset-2', onSelect ? 'cursor-pointer' : 'cursor-default'), "data-slot": "chart-hover-layer", onClick: () => {
500
+ const row = active !== null ? data[active] : undefined;
501
+ if (row && active !== null)
502
+ onSelect?.(row, active);
503
+ }, style: {
504
+ height: plotHeight,
505
+ left,
506
+ top,
507
+ touchAction: 'pan-y',
508
+ width: plotWidth,
509
+ }, type: "button", ...handlers }))] })) }), _jsx("p", { "aria-live": "polite", className: "sr-only", children: active !== null && activeRow ? readoutOf(active) : '' }), _jsx("div", { className: "sr-only", children: _jsxs("table", { children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: xKey }), series.map(line => (_jsx("th", { scope: "col", children: line.name ?? line.key }, line.key)))] }) }), _jsx("tbody", { children: rawLabels.map((text, index) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: text }), series.map((line, i) => (_jsx("td", { children: writeValue(readings[i]?.[index] ?? 0) }, line.key)))] }, `${index}-${text}`))) })] }) })] }) }));
510
+ };
511
+ /**
512
+ * The stand-in's heights, as shares of the plot: a week that climbs, peaks late and falls back,
513
+ * as a measure over time tends to, so the shape reads as data waiting rather than a wave.
514
+ */
515
+ const SKELETON_LEVELS = [0.5, 0.62, 0.58, 0.82, 0.76, 0.42, 0.5];
516
+ /** Where the stand-in's grid sits, as shares of the plot's height: the rules a loaded chart draws. */
517
+ const SKELETON_RULES = [0.08, 0.38, 0.68];
518
+ /** The edge of the stand-in's curve, a step stronger than its wash, as a line is over its tint. */
519
+ const SKELETON_EDGE = 'color-mix(in oklab, var(--color-neutral-950) 14%, transparent)';
520
+ /**
521
+ * A chart that is loading, with the depth of a loaded one: its frame and grid stay, and the
522
+ * shape of its kind stands in the skeleton wash with the light crossing it. An area is a curve
523
+ * with a firm edge over a wash that fades towards the baseline, as the real one does; a line is
524
+ * the edge alone; a bar chart its bars. It takes the plot's room, so nothing moves when the data
525
+ * lands.
526
+ */
527
+ const ChartSkeleton = ({ kind, left, top, width, height, }) => {
528
+ if (width <= 0 || height <= 0)
529
+ return null;
530
+ const step = width / (SKELETON_LEVELS.length - 1);
531
+ const points = SKELETON_LEVELS.map((level, i) => ({ x: i * step, y: height * (1 - level) }));
532
+ // The edge: a 2px ribbon along the curve.
533
+ const edge = `${curvePath(points)} L${width},${(points.at(-1)?.y ?? 0) + 2} ${curvePath(points.map(point => ({ ...point, y: point.y + 2 })).reverse()).replace(/^M/, 'L')} Z`;
534
+ // About one bar per 48px, never fewer than five.
535
+ const bars = Math.max(5, Math.round(width / 48));
536
+ const slot = width / bars;
537
+ return (_jsxs("div", { "aria-hidden": true, className: "absolute", "data-slot": "chart-skeleton", style: { height, left, top, width }, children: [SKELETON_RULES.map(share => (_jsx("div", { className: "absolute inset-x-0 h-px", style: {
538
+ backgroundColor: 'var(--color-chart-grid)',
539
+ top: Math.round(height * share),
540
+ } }, share))), kind === 'bar' ? (Array.from({ length: bars }, (_, i) => {
541
+ const at = Math.round((i / Math.max(1, bars - 1)) * (SKELETON_LEVELS.length - 1));
542
+ return (_jsx("div", { className: "skeleton absolute bottom-0 rounded-t-chip", style: {
543
+ height: height * (SKELETON_LEVELS[at] ?? 0.5),
544
+ left: i * slot + slot * 0.2,
545
+ width: slot * 0.6,
546
+ } }, i));
547
+ })) : (_jsxs(_Fragment, { children: [kind === 'area' && (_jsx("div", { className: "skeleton absolute inset-0", style: {
548
+ clipPath: `path('${areaPath(points, height)}')`,
549
+ // The wash fades towards the baseline, as an area's tint does.
550
+ maskImage: 'linear-gradient(to bottom, black 20%, transparent 100%)',
551
+ } })), _jsx("div", { className: "skeleton absolute inset-0", style: { backgroundColor: SKELETON_EDGE, clipPath: `path('${edge}')` } })] }))] }));
552
+ };
553
+ /** The two textures as CSS, for marks drawn in HTML: the same stripes and dots as the SVG fills. */
554
+ const TEXTURES = {
555
+ stripes: (color) => `repeating-linear-gradient(135deg, color-mix(in oklab, ${color} 50%, transparent) 0 1.2px, transparent 1.2px 6px)`,
556
+ dots: (color) => `radial-gradient(color-mix(in oklab, ${color} 55%, transparent) 1.1px, transparent 1.4px) 0 0 / 6px 6px`,
557
+ };
558
+ const ChartTooltipTotal = ({ value }) => (_jsxs("span", { className: "flex items-center justify-between gap-4", children: [_jsx("span", { className: "text-neutral-600 text-xs", children: "Total" }), _jsx("span", { className: "font-medium text-neutral-950 text-xs tabular-nums", children: value })] }));
559
+ const toneFill = {
560
+ success: 'bg-success-500',
561
+ warning: 'bg-warning-500',
562
+ error: 'bg-error-500',
563
+ neutral: 'bg-neutral-400',
564
+ };
565
+ /** A label's width, near enough to keep two apart: 11 type, its dot or icon, its padding. */
566
+ const labelWidth = (marker) => Math.ceil(marker.label.length * 6.2) + (marker.icon ? 12 : 6) + 4 + 8;
567
+ /**
568
+ * Where each marker's label goes. Beside its rule at the plot's foot, on the rule's right before the
569
+ * middle and its left past it, so it never runs off the frame. A label that would touch one already
570
+ * placed takes the rule's other side, and when neither side is clear it steps up a row: two labels
571
+ * never sit over each other, however close their markers are. A label also keeps off the other
572
+ * markers' rules when a side lets it.
573
+ */
574
+ const placeMarkerLabels = (xs, markers, start, end) => {
575
+ const placed = [];
576
+ const order = markers.map((_, index) => index).sort((a, b) => (xs[a] ?? 0) - (xs[b] ?? 0));
577
+ const result = [];
578
+ for (const index of order) {
579
+ const marker = markers[index];
580
+ const x = xs[index] ?? 0;
581
+ const width = labelWidth(marker);
582
+ const span = (before) => before
583
+ ? { from: x - LABEL_GAP - width, to: x - LABEL_GAP }
584
+ : { from: x + LABEL_GAP, to: x + LABEL_GAP + width };
585
+ const preferred = x > start + (end - start) / 2;
586
+ // Another marker's rule runs the plot's full height, so no row clears it: a side whose label
587
+ // would cross one comes last, and is taken only when both sides do.
588
+ const crossesRule = (before) => {
589
+ const { from, to } = span(before);
590
+ return xs.some((other, at) => at !== index && other >= from - LABEL_SPACE && other <= to + LABEL_SPACE);
591
+ };
592
+ const sides = [preferred, !preferred]
593
+ .filter(before => {
594
+ const { from, to } = span(before);
595
+ return from >= start && to <= end;
596
+ })
597
+ .sort((a, b) => Number(crossesRule(a)) - Number(crossesRule(b)));
598
+ if (sides.length === 0)
599
+ sides.push(preferred);
600
+ const clear = (before, row) => {
601
+ const { from, to } = span(before);
602
+ return placed.every(other => other.row !== row ||
603
+ to + LABEL_SPACE <= other.from ||
604
+ from >= other.to + LABEL_SPACE);
605
+ };
606
+ let choice = { before: preferred, row: 0 };
607
+ search: for (let row = 0; row < markers.length; row += 1) {
608
+ for (const before of sides) {
609
+ if (clear(before, row)) {
610
+ choice = { before, row };
611
+ break search;
612
+ }
613
+ }
614
+ }
615
+ placed.push({ ...span(choice.before), row: choice.row });
616
+ result.push({ marker, x, ...choice });
617
+ }
618
+ return result;
619
+ };
620
+ /**
621
+ * A marker's note, always shown: 11 type beside its rule at the plot's foot, a 6 dot of its tone in
622
+ * front (or its icon at 12), on the chart's own background so it reads over the series. No pin, no
623
+ * shadow: a note about the data, never louder than the data.
624
+ */
625
+ const ChartMarkerLabel = ({ marker, x, y, before, }) => (_jsxs("span", { className: cn('pointer-events-none absolute z-10 flex -translate-y-full items-center gap-1 whitespace-nowrap rounded-chip bg-chart-background px-1 py-0.5 text-neutral-600 text-xxs [&_svg]:size-3', before ? '-translate-x-full' : ''), "data-slot": "chart-marker", style: { left: before ? x - LABEL_GAP : x + LABEL_GAP, top: y }, children: [marker.icon ?? (_jsx("span", { "aria-hidden": true, className: cn('size-1.5 shrink-0 rounded-full', toneFill[marker.tone ?? 'neutral']) })), marker.label] }));