@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,1242 @@
1
+ 'use client';
2
+
3
+ import { Minus, Plus, RotateCcw } from 'lucide-react';
4
+ import {
5
+ Fragment,
6
+ type KeyboardEvent,
7
+ type PointerEvent,
8
+ useEffect,
9
+ useId,
10
+ useMemo,
11
+ useRef,
12
+ useState,
13
+ } from 'react';
14
+ import { cn } from '../lib/cn';
15
+ import { type CandleWindow, clampWindow, panWindow, zoomWindow } from './lib/candlestick-window';
16
+ import { CHANGE_INK, chartColor } from './lib/color';
17
+ import { PLOT_FRAME } from './lib/frame';
18
+ import { lineAreaPath, linePath } from './lib/path';
19
+ import { niceStep } from './lib/scale';
20
+ import { useLabelWidth, useWidth } from './lib/use-size';
21
+
22
+ export type Candle = {
23
+ /** When the period opened. */
24
+ time: Date;
25
+ open: number;
26
+ high: number;
27
+ low: number;
28
+ close: number;
29
+ /** What changed hands in the period; drawn along the foot of the plot. */
30
+ volume?: number;
31
+ };
32
+
33
+ /** A stretch of time offered under the plot: the latest `periods`, or all of them for `null`. */
34
+ export type CandleSpan = { label: string; periods: number | null };
35
+
36
+ export type CandlestickChartProps = {
37
+ /** Says what the chart shows; it names the chart for a screen reader. */
38
+ 'aria-label': string;
39
+ /** The periods, oldest first. */
40
+ data: readonly Candle[];
41
+ /**
42
+ * How the prices are drawn: `line`, the closes as one line over a tint, or `candles`,
43
+ * each period's open, high, low and close. Candles unless asked for a line.
44
+ */
45
+ type?: 'line' | 'candles';
46
+ /** The whole chart's height: the plot, the time axis and the bar of controls under it. */
47
+ height?: number;
48
+ /** What traded, as short bars along the plot's foot, when the candles carry it. */
49
+ volume?: boolean;
50
+ /** A moving average of the closes over this many periods, as a line; left out, none. */
51
+ average?: number;
52
+ /**
53
+ * The periods in view, by index into `data` (`end` not included); `null` for as many of
54
+ * the latest as fit. Given, the chart is controlled and asks for a new one through
55
+ * `onRangeChange` when it is zoomed or panned.
56
+ */
57
+ range?: CandleWindow | null;
58
+ /** The periods in view at first, for a chart that keeps its own. */
59
+ defaultRange?: CandleWindow | null;
60
+ /** Called with the window the chart was zoomed or panned to; `null` once reset. */
61
+ onRangeChange?: (range: CandleWindow | null) => void;
62
+ /** The stretches offered at the left of the bar under the plot: 1W, 1M, 3M, All. */
63
+ spans?: readonly CandleSpan[];
64
+ /** The zoom out, zoom in and reset buttons at the right of that bar. On unless turned off. */
65
+ zoomControls?: boolean;
66
+ /** The decimals a price is written to; from the price's size unless given (1.0842, 182.40). */
67
+ digits?: number;
68
+ /** A price, on the axis and in the readout; the decimals above unless given. */
69
+ formatPrice?: (price: number) => string;
70
+ /** A time on the axis under the plot; the hour within a day, the date across days. */
71
+ formatTime?: (time: Date, previous: Date | undefined) => string;
72
+ /** The time a read period opened, in the label on the time axis. */
73
+ formatTimeLong?: (time: Date) => string;
74
+ /** The line a chart with no data shows in place of its plot. */
75
+ emptyLabel?: string;
76
+ /** While the data loads: the chart's own shape stands in, in the skeleton wash, at the size it will have. */
77
+ loading?: boolean;
78
+ className?: string;
79
+ };
80
+
81
+ /** The row of times under the plot: the gap to it and one line of labels, no more. */
82
+ const AXIS_HEIGHT = 20;
83
+ const GUTTER_GAP = 8;
84
+ /** The bar of controls under the time axis: its 24px controls and the room over them. */
85
+ const BAR = 32;
86
+ /** The room at the plot's head the readout is written in, kept clear of the prices. */
87
+ const READOUT = 28;
88
+ /** A label on the price axis has this much room either side of its figure. */
89
+ const PILL_PAD = 6;
90
+ /** The least room a period is given: a 1px line and a 1px gap. Past it, the oldest are left off. */
91
+ const MIN_SLOT = 2;
92
+ /** The least room between two points of a line: closer than this and they share a pixel. */
93
+ const LINE_PITCH = 0.5;
94
+ /** Below this slot a body is no wider than its wick, and the candle is drawn as a line. */
95
+ const LINE_SLOT = 3;
96
+ const BODY_SHARE = 0.66;
97
+ const BODY_MAX = 15;
98
+ /** The volume's share of the plot's height, between two bounds. */
99
+ const VOLUME_SHARE = 0.18;
100
+ const VOLUME_MIN = 20;
101
+ const VOLUME_MAX = 56;
102
+ /** A time label is given at least this much room. */
103
+ const TIME_ROOM = 72;
104
+ /** The fewest periods a zoom narrows to. */
105
+ const MIN_WINDOW = 5;
106
+ /** One press of zoom in narrows the window by this much. */
107
+ const ZOOM_STEP = 1.6;
108
+
109
+ const DAY = 86_400_000;
110
+
111
+ const timeOfDay = new Intl.DateTimeFormat('en-GB', {
112
+ hour: '2-digit',
113
+ minute: '2-digit',
114
+ timeZone: 'UTC',
115
+ });
116
+ const dayOfMonth = new Intl.DateTimeFormat('en-GB', {
117
+ day: 'numeric',
118
+ month: 'short',
119
+ timeZone: 'UTC',
120
+ });
121
+ const longDay = new Intl.DateTimeFormat('en-GB', {
122
+ weekday: 'short',
123
+ day: 'numeric',
124
+ month: 'short',
125
+ timeZone: 'UTC',
126
+ });
127
+
128
+ /** The decimals a price of this size is usually read to. */
129
+ const digitsFor = (price: number) => {
130
+ const size = Math.abs(price);
131
+ if (size < 10) return 4;
132
+ if (size < 1000) return 2;
133
+ return 0;
134
+ };
135
+
136
+ /** The closes' average over the last `span` periods, from the first period that has them all. */
137
+ const movingAverage = (data: readonly Candle[], span: number) => {
138
+ const out: (number | null)[] = [];
139
+ let sum = 0;
140
+ data.forEach((candle, i) => {
141
+ sum += candle.close;
142
+ const leaving = data[i - span];
143
+ if (leaving) sum -= leaving.close;
144
+ out.push(i >= span - 1 ? sum / span : null);
145
+ });
146
+ return out;
147
+ };
148
+
149
+ /** A change from one price to another, written with its sign: "+0.22%". */
150
+ const changeOf = (from: number, to: number) => {
151
+ const share = from ? Math.round(((to - from) / from) * 1e4) / 1e2 : 0;
152
+ return {
153
+ share,
154
+ text: `${share > 0 ? '+' : share < 0 ? '−' : ''}${Math.abs(share).toFixed(2)}%`,
155
+ };
156
+ };
157
+
158
+ type Drag =
159
+ | { mode: 'pan'; x: number; view: CandleWindow }
160
+ | { mode: 'select'; from: number; to: number };
161
+
162
+ /** The small controls on the bar under the plot: the kit's key toggles, as buttons. */
163
+ const control =
164
+ 'flex h-6 shrink-0 cursor-pointer items-center justify-center rounded-chip font-medium text-xxs outline-none transition-colors duration-150 focus-visible:outline-2 focus-visible:outline-focus focus-visible:outline-solid disabled:pointer-events-none disabled:opacity-40 motion-reduce:transition-none';
165
+ const quiet = 'text-neutral-600 hover:bg-neutral-950/5 hover:text-neutral-950';
166
+
167
+ /**
168
+ * A price over time, put together as a trading screen is. The closes as one line over a
169
+ * tint, or each period as a candle: its open and close as a body, its high and low as the
170
+ * wick through it, a rise drawn as a tint with a solid edge and a fall solid, so the two are
171
+ * told apart by form as well as colour. What traded runs along the foot of the same plot.
172
+ *
173
+ * The prices are read on the right, where the latest period is, and the latest close is
174
+ * tagged there on a dashed rule. The period being read (the one under the pointer, or the
175
+ * latest) is written out in the plot's top corner; a crosshair tags the price and the time
176
+ * it stands on along the two axes.
177
+ *
178
+ * Time is moved through as on any such screen: drag to pan, ctrl or ⌘ with the wheel (or a
179
+ * pinch) to zoom about the pointer, a double click to see it all again, and shift-drag to
180
+ * mark a stretch and zoom to it. The bar under the plot offers the usual stretches and the
181
+ * same zoom as buttons; the prices refit to whatever is in view.
182
+ */
183
+ export const CandlestickChart = ({
184
+ 'aria-label': label,
185
+ data: rows,
186
+ type = 'candles',
187
+ height = 360,
188
+ volume = true,
189
+ average,
190
+ range,
191
+ defaultRange = null,
192
+ onRangeChange,
193
+ spans,
194
+ zoomControls = true,
195
+ digits,
196
+ formatPrice,
197
+ formatTime,
198
+ formatTimeLong,
199
+ emptyLabel = 'No prices to show',
200
+ loading = false,
201
+ className,
202
+ }: CandlestickChartProps) => {
203
+ // While it loads the chart draws its stand-in and nothing else: old prices are not news.
204
+ const data: readonly Candle[] = loading ? [] : rows;
205
+ const id = useId().replace(/[^a-zA-Z0-9_-]/g, '');
206
+ const [ref, width] = useWidth<HTMLDivElement>();
207
+ const [probeRef, labelWidth] = useLabelWidth();
208
+ // Held in state, not a ref: the plot is drawn only once its width is known, and the wheel
209
+ // listener has to be bound when it arrives.
210
+ const [surface, setSurface] = useState<HTMLDivElement | null>(null);
211
+ const [pointer, setPointer] = useState<{ index: number; y: number | null } | null>(null);
212
+ const [ownRange, setOwnRange] = useState<CandleWindow | null>(defaultRange);
213
+ const [drag, setDrag] = useState<Drag | null>(null);
214
+
215
+ const current = range === undefined ? ownRange : range;
216
+ const setRange = (next: CandleWindow | null) => {
217
+ if (range === undefined) setOwnRange(next);
218
+ onRangeChange?.(next);
219
+ };
220
+
221
+ const last = data.at(-1);
222
+ const decimals = digits ?? digitsFor(last?.close ?? 0);
223
+ const price = useMemo(() => {
224
+ if (formatPrice) return formatPrice;
225
+ const format = new Intl.NumberFormat('en-GB', {
226
+ minimumFractionDigits: decimals,
227
+ maximumFractionDigits: decimals,
228
+ });
229
+ return (value: number) => format.format(value);
230
+ }, [formatPrice, decimals]);
231
+
232
+ // How far apart the periods are, so the axis knows whether to count hours or days.
233
+ const interval =
234
+ data.length > 1
235
+ ? ((last?.time.getTime() ?? 0) - (data[0]?.time.getTime() ?? 0)) / (data.length - 1)
236
+ : DAY;
237
+ const intraday = interval < DAY;
238
+ const writeTime =
239
+ formatTime ??
240
+ ((time: Date, previous: Date | undefined) =>
241
+ intraday &&
242
+ previous &&
243
+ Math.floor(previous.getTime() / DAY) === Math.floor(time.getTime() / DAY)
244
+ ? timeOfDay.format(time)
245
+ : dayOfMonth.format(time));
246
+ const writeTimeLong =
247
+ formatTimeLong ??
248
+ ((time: Date) =>
249
+ intraday
250
+ ? `${longDay.format(time).replace(',', '')} ${timeOfDay.format(time)}`
251
+ : longDay.format(time).replace(',', ''));
252
+
253
+ const averages = useMemo(
254
+ () => (average && average > 1 ? movingAverage(data, average) : null),
255
+ [data, average],
256
+ );
257
+
258
+ const empty = data.length === 0;
259
+ const candles = type === 'candles';
260
+ // A loading chart keeps the room its volume and its bar will take, so nothing moves.
261
+ const withVolume = loading ? volume : volume && data.some(candle => candle.volume != null);
262
+ const withBar = (!empty || loading) && (zoomControls || Boolean(spans?.length));
263
+
264
+ // The plot is what the prices on the right, the times under it and the bar leave.
265
+ const gutter = labelWidth + PILL_PAD * 2 + GUTTER_GAP;
266
+ const plotWidth = Math.max(0, width - gutter);
267
+ const plotHeight = Math.max(0, height - AXIS_HEIGHT - (withBar ? BAR : 0));
268
+ const volumeHeight = withVolume
269
+ ? Math.round(Math.min(VOLUME_MAX, Math.max(VOLUME_MIN, plotHeight * VOLUME_SHARE)))
270
+ : 0;
271
+ // The prices keep clear of the readout over them and of the volume under them.
272
+ const priceTop = READOUT;
273
+ const priceFoot = Math.max(priceTop + 1, plotHeight - volumeHeight - 12);
274
+
275
+ // The window asked for, then as many of its latest periods as fit.
276
+ // A candle needs its line and its gap; a line is drawn through points far closer together.
277
+ const fits = Math.max(1, Math.floor(plotWidth / (candles ? MIN_SLOT : LINE_PITCH)));
278
+ const asked = current
279
+ ? clampWindow(current, data.length, MIN_WINDOW)
280
+ : { start: 0, end: data.length };
281
+ const offset = Math.max(asked.start, asked.end - fits);
282
+ const shown = data.slice(offset, asked.end);
283
+ const view: CandleWindow = { start: offset, end: offset + shown.length };
284
+ const widest = Math.min(data.length, fits);
285
+ const whole = view.start === 0 && view.end === data.length;
286
+ const slot = shown.length ? plotWidth / shown.length : plotWidth;
287
+ const lines = slot < LINE_SLOT;
288
+ // An odd width, so the wick runs down the body's middle pixel.
289
+ const rawBody = Math.min(
290
+ BODY_MAX,
291
+ Math.floor(slot) - Math.max(1, Math.round(slot * (1 - BODY_SHARE))),
292
+ );
293
+ const body = lines ? 1 : Math.max(1, rawBody % 2 ? rawBody : rawBody - 1);
294
+ // Candles stand in the middle of their slots; a line runs from edge to edge of the plot.
295
+ const pitch = shown.length > 1 ? plotWidth / (shown.length - 1) : 0;
296
+ const slotted = candles || shown.length < 2;
297
+ const xOf = (i: number) => (slotted ? Math.floor(slot * i + slot / 2) : pitch * i);
298
+ const indexAt = (x: number) =>
299
+ Math.max(
300
+ 0,
301
+ Math.min(shown.length - 1, slotted ? Math.floor(x / slot) : Math.round(x / pitch)),
302
+ );
303
+
304
+ // The prices in view with a little air, ruled at round steps.
305
+ let low = Number.POSITIVE_INFINITY;
306
+ let high = Number.NEGATIVE_INFINITY;
307
+ let most = 0;
308
+ shown.forEach((candle, i) => {
309
+ low = Math.min(low, candles ? candle.low : candle.close);
310
+ high = Math.max(high, candles ? candle.high : candle.close);
311
+ most = Math.max(most, candle.volume ?? 0);
312
+ const mean = averages?.[offset + i];
313
+ if (mean != null) {
314
+ low = Math.min(low, mean);
315
+ high = Math.max(high, mean);
316
+ }
317
+ });
318
+ if (!Number.isFinite(low)) {
319
+ low = 0;
320
+ high = 1;
321
+ }
322
+ if (high - low < 1e-12) high = low + 1;
323
+ const span = priceFoot - priceTop;
324
+ const yOf = (value: number) => priceTop + ((high - value) / (high - low)) * span;
325
+ const valueAt = (y: number) => high - ((y - priceTop) / span) * (high - low);
326
+ const volumeOf = (amount: number) => (most > 0 ? (amount / most) * volumeHeight : 0);
327
+
328
+ // Rules at round prices, wherever they clear the plot's own edges.
329
+ const step = niceStep(((high - low) / Math.max(1, span)) * 44);
330
+ const ticks: number[] = [];
331
+ for (let i = Math.ceil(valueAt(plotHeight - 10) / step); i * step <= valueAt(10); i++)
332
+ ticks.push(i * step);
333
+
334
+ const up = chartColor('success');
335
+ const down = chartColor('error');
336
+ const ink = chartColor('series-1');
337
+ const toneOf = (candle: Candle) => (candle.close >= candle.open ? up : down);
338
+
339
+ // The period being read: the one under the pointer, or the latest.
340
+ const pointed = pointer && shown.length ? Math.min(pointer.index, shown.length - 1) : null;
341
+ const readIndex = pointed !== null ? offset + pointed : data.length - 1;
342
+ const reading = data[readIndex];
343
+ const before = data[readIndex - 1];
344
+ const change = reading && before ? changeOf(before.close, reading.close) : null;
345
+ const mean = averages?.[readIndex];
346
+
347
+ // A stretch being marked with shift held, summed up in the readout while it is.
348
+ const marking =
349
+ drag?.mode === 'select' && drag.from !== drag.to
350
+ ? { start: Math.min(drag.from, drag.to), end: Math.max(drag.from, drag.to) + 1 }
351
+ : null;
352
+ const first = marking ? data[marking.start] : undefined;
353
+ const final = marking ? data[marking.end - 1] : undefined;
354
+
355
+ // Time labels, at least TIME_ROOM apart, counted from the first period so they hold still.
356
+ const every = Math.max(1, Math.ceil(TIME_ROOM / Math.max(slot, 1e-6)));
357
+ const timeTicks: number[] = [];
358
+ for (let i = 0; i < shown.length; i++) if ((offset + i) % every === 0) timeTicks.push(i);
359
+
360
+ /** Sets the window, back to none once it holds every period that fits up to the latest. */
361
+ const show = (next: CandleWindow) => {
362
+ if (next.end >= data.length && next.end - next.start >= widest) setRange(null);
363
+ else setRange(next);
364
+ };
365
+ const zoom = (factor: number, anchor?: number) => {
366
+ if (!shown.length) return;
367
+ // About the latest while it is in view, else about the middle.
368
+ const at = anchor ?? (view.end >= data.length ? 1 : 0.5);
369
+ show(zoomWindow(view, factor, at, data.length, MIN_WINDOW, widest));
370
+ };
371
+ const reset = () => {
372
+ setDrag(null);
373
+ setRange(null);
374
+ };
375
+ const canZoomIn = shown.length > MIN_WINDOW;
376
+ const canZoomOut = shown.length < widest;
377
+
378
+ const spanWindow = (periods: number | null): CandleWindow | null =>
379
+ periods === null || periods >= data.length
380
+ ? null
381
+ : { start: data.length - periods, end: data.length };
382
+ const spanActive = (periods: number | null) => {
383
+ const at = spanWindow(periods);
384
+ return at ? view.start === at.start && view.end === at.end : current === null;
385
+ };
386
+
387
+ const place = (event: PointerEvent<HTMLDivElement>) => {
388
+ const box = event.currentTarget.getBoundingClientRect();
389
+ const x = event.clientX - box.left;
390
+ const y = event.clientY - box.top;
391
+ return { x, y, index: indexAt(x) };
392
+ };
393
+ const onPointerDown = (event: PointerEvent<HTMLDivElement>) => {
394
+ if (event.button !== 0 || !shown.length) return;
395
+ const at = place(event);
396
+ event.currentTarget.setPointerCapture(event.pointerId);
397
+ if (event.shiftKey)
398
+ setDrag({ mode: 'select', from: offset + at.index, to: offset + at.index });
399
+ else if (!whole) setDrag({ mode: 'pan', x: at.x, view });
400
+ };
401
+ const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {
402
+ if (!shown.length) return;
403
+ const at = place(event);
404
+ if (drag?.mode === 'pan') {
405
+ // The plot moves with the hand: a period's width of travel is one period.
406
+ const by = Math.round((drag.x - at.x) / Math.max(slot, 1e-6));
407
+ const next = panWindow(drag.view, by, data.length, MIN_WINDOW);
408
+ if (next.start !== view.start) show(next);
409
+ setPointer(null);
410
+ return;
411
+ }
412
+ if (drag?.mode === 'select') setDrag({ ...drag, to: offset + at.index });
413
+ setPointer({ index: at.index, y: at.y >= 0 && at.y <= plotHeight ? at.y : null });
414
+ };
415
+ const onPointerUp = (event: PointerEvent<HTMLDivElement>) => {
416
+ if (event.currentTarget.hasPointerCapture(event.pointerId))
417
+ event.currentTarget.releasePointerCapture(event.pointerId);
418
+ if (marking && marking.end - marking.start >= 2)
419
+ show(clampWindow(marking, data.length, MIN_WINDOW));
420
+ setDrag(null);
421
+ };
422
+
423
+ // The wheel zooms only with ctrl or ⌘ held (a pinch sends the same), so a page still
424
+ // scrolls past the chart; a sideways scroll pans. Bound by hand: React's is passive.
425
+ const wheel = useRef<(event: WheelEvent) => void>(() => {});
426
+ wheel.current = (event: WheelEvent) => {
427
+ const node = surface;
428
+ if (!node || !shown.length) return;
429
+ if (event.ctrlKey || event.metaKey) {
430
+ event.preventDefault();
431
+ const box = node.getBoundingClientRect();
432
+ const anchor = Math.max(0, Math.min(1, (event.clientX - box.left) / box.width));
433
+ zoom(event.deltaY < 0 ? 1.25 : 0.8, anchor);
434
+ } else if (Math.abs(event.deltaX) > Math.abs(event.deltaY) && !whole) {
435
+ event.preventDefault();
436
+ const by = Math.sign(event.deltaX) * Math.max(1, Math.round(shown.length / 30));
437
+ show(panWindow(view, by, data.length, MIN_WINDOW));
438
+ }
439
+ };
440
+ useEffect(() => {
441
+ if (!surface) return;
442
+ const listener = (event: WheelEvent) => wheel.current(event);
443
+ surface.addEventListener('wheel', listener, { passive: false });
444
+ return () => surface.removeEventListener('wheel', listener);
445
+ }, [surface]);
446
+
447
+ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
448
+ if (!shown.length) return;
449
+ const at = pointed ?? shown.length - 1;
450
+ const step = (by: number) => {
451
+ const next = at + by;
452
+ // Past either end of a narrowed window, the window slides along instead.
453
+ if (next < 0 || next > shown.length - 1) {
454
+ show(panWindow(view, by, data.length, MIN_WINDOW));
455
+ setPointer({ index: at, y: null });
456
+ } else setPointer({ index: next, y: null });
457
+ };
458
+ const keys: Record<string, () => void> = {
459
+ ArrowLeft: () => step(-1),
460
+ ArrowRight: () => step(1),
461
+ Home: () => setPointer({ index: 0, y: null }),
462
+ End: () => setPointer({ index: shown.length - 1, y: null }),
463
+ '+': () => zoom(ZOOM_STEP),
464
+ '=': () => zoom(ZOOM_STEP),
465
+ '-': () => zoom(1 / ZOOM_STEP),
466
+ '0': reset,
467
+ Escape: () => setPointer(null),
468
+ };
469
+ const act = keys[event.key];
470
+ if (!act) return;
471
+ event.preventDefault();
472
+ act();
473
+ };
474
+
475
+ const lastY = last ? yOf(last.close) : 0;
476
+ const lastShown =
477
+ Boolean(last) && view.end === data.length && lastY > 8 && lastY < plotHeight - 8;
478
+ const lastInk = candles && last ? toneOf(last) : ink;
479
+ const crossX = pointed !== null ? xOf(pointed) : null;
480
+ const crossY = pointer?.y ?? null;
481
+ const timeTag = pointed !== null && reading ? writeTimeLong(reading.time) : null;
482
+
483
+ const points = shown.map((candle, i) => ({ x: xOf(i), y: yOf(candle.close) }));
484
+ const averagePoints = averages
485
+ ? shown.flatMap((_, i) => {
486
+ const value = averages[offset + i];
487
+ return value == null ? [] : [{ x: xOf(i), y: yOf(value) }];
488
+ })
489
+ : [];
490
+
491
+ // The stretches and the zoom, under the plot. While the prices load they stand where they
492
+ // will be, switched off, so the bar does not arrive with them.
493
+ const bar = withBar && (
494
+ <div
495
+ className="absolute inset-x-0 bottom-0 flex h-6 items-center justify-between gap-2"
496
+ data-slot="candlestick-chart-bar"
497
+ style={{ paddingRight: gutter }}
498
+ >
499
+ <div className="flex min-w-0 items-center gap-0.5">
500
+ {spans?.map(item => {
501
+ const pressed = !loading && spanActive(item.periods);
502
+ return (
503
+ <button
504
+ aria-pressed={pressed}
505
+ className={cn(
506
+ control,
507
+ 'px-2',
508
+ pressed ? 'bg-neutral-950/8 text-neutral-950' : quiet,
509
+ )}
510
+ disabled={
511
+ loading ||
512
+ (item.periods !== null &&
513
+ (item.periods > data.length || item.periods < MIN_WINDOW))
514
+ }
515
+ key={item.label}
516
+ onClick={() => setRange(spanWindow(item.periods))}
517
+ type="button"
518
+ >
519
+ {item.label}
520
+ </button>
521
+ );
522
+ })}
523
+ </div>
524
+ {zoomControls && (
525
+ <div className="flex shrink-0 items-center gap-0.5 [&_svg]:size-3.5">
526
+ <button
527
+ aria-label="Zoom out"
528
+ className={cn(control, quiet, 'w-6')}
529
+ disabled={loading || !canZoomOut}
530
+ onClick={() => zoom(1 / ZOOM_STEP)}
531
+ type="button"
532
+ >
533
+ <Minus />
534
+ </button>
535
+ <button
536
+ aria-label="Zoom in"
537
+ className={cn(control, quiet, 'w-6')}
538
+ disabled={loading || !canZoomIn}
539
+ onClick={() => zoom(ZOOM_STEP)}
540
+ type="button"
541
+ >
542
+ <Plus />
543
+ </button>
544
+ <button
545
+ aria-label="Show every period"
546
+ className={cn(control, quiet, 'w-6')}
547
+ disabled={loading || current === null}
548
+ onClick={reset}
549
+ type="button"
550
+ >
551
+ <RotateCcw />
552
+ </button>
553
+ </div>
554
+ )}
555
+ </div>
556
+ );
557
+
558
+ return (
559
+ <figure
560
+ aria-busy={loading || undefined}
561
+ aria-label={label}
562
+ className={cn('relative m-0 min-w-0', className)}
563
+ data-slot="candlestick-chart"
564
+ >
565
+ {/* The widest price, measured in the theme's font, sizes the gutter on the right. */}
566
+ <div
567
+ aria-hidden
568
+ className="pointer-events-none invisible absolute top-0 left-0 w-max font-medium text-xxs tabular-nums"
569
+ ref={probeRef}
570
+ >
571
+ {price(high)}
572
+ </div>
573
+ <div className="relative" ref={ref} style={{ height }}>
574
+ {width > 0 && empty && !loading && (
575
+ <p className="absolute inset-0 flex items-center justify-center rounded-item border border-neutral-200 border-dashed text-neutral-600 text-xs">
576
+ {emptyLabel}
577
+ </p>
578
+ )}
579
+ {width > 0 && loading && (
580
+ <>
581
+ <CandleSkeleton
582
+ candles={candles}
583
+ height={plotHeight}
584
+ labelWidth={labelWidth}
585
+ priceFoot={priceFoot}
586
+ priceTop={priceTop}
587
+ volumeHeight={volumeHeight}
588
+ width={plotWidth}
589
+ />
590
+ <div
591
+ aria-hidden
592
+ className={PLOT_FRAME}
593
+ data-slot="candlestick-chart-plot"
594
+ style={{ height: plotHeight, left: 0, top: 0, width: plotWidth }}
595
+ />
596
+ {bar}
597
+ </>
598
+ )}
599
+ {width > 0 && !empty && (
600
+ <>
601
+ <svg
602
+ aria-hidden="true"
603
+ className="block overflow-visible"
604
+ height={plotHeight + AXIS_HEIGHT}
605
+ width={width}
606
+ >
607
+ <defs>
608
+ {/* Everything in the plot stops at its frame, corners and all. */}
609
+ <clipPath id={`${id}-plot`}>
610
+ <rect
611
+ height={plotHeight}
612
+ style={{ rx: 'var(--radius-item)' }}
613
+ width={plotWidth}
614
+ />
615
+ </clipPath>
616
+ <linearGradient
617
+ gradientUnits="userSpaceOnUse"
618
+ id={`${id}-tint`}
619
+ x1={0}
620
+ x2={0}
621
+ y1={priceTop}
622
+ y2={plotHeight}
623
+ >
624
+ <stop offset="0%" stopColor={ink} stopOpacity={0.2} />
625
+ <stop offset="100%" stopColor={ink} stopOpacity={0.04} />
626
+ </linearGradient>
627
+ </defs>
628
+
629
+ <g clipPath={`url(#${id}-plot)`}>
630
+ {ticks.map(tick => (
631
+ <line
632
+ key={tick}
633
+ shapeRendering="crispEdges"
634
+ stroke="var(--color-chart-grid)"
635
+ x1={0}
636
+ x2={plotWidth}
637
+ y1={Math.round(yOf(tick)) + 0.5}
638
+ y2={Math.round(yOf(tick)) + 0.5}
639
+ />
640
+ ))}
641
+
642
+ {marking && (
643
+ <rect
644
+ fill="var(--color-chart-band)"
645
+ height={plotHeight}
646
+ width={Math.max(
647
+ 1,
648
+ xOf(marking.end - 1 - offset) -
649
+ xOf(marking.start - offset),
650
+ )}
651
+ x={xOf(marking.start - offset)}
652
+ />
653
+ )}
654
+
655
+ {withVolume &&
656
+ shown.map((candle, i) => {
657
+ const tall = volumeOf(candle.volume ?? 0);
658
+ const wide = slotted
659
+ ? body
660
+ : Math.max(1, Math.floor(pitch) - 1);
661
+ return tall > 0 ? (
662
+ <rect
663
+ fill={
664
+ candles
665
+ ? toneOf(candle)
666
+ : 'var(--color-neutral-950)'
667
+ }
668
+ fillOpacity={candles ? 0.35 : 0.12}
669
+ height={tall}
670
+ key={candle.time.getTime()}
671
+ shapeRendering="crispEdges"
672
+ width={wide}
673
+ x={Math.round(xOf(i) - wide / 2)}
674
+ y={plotHeight - tall}
675
+ />
676
+ ) : null;
677
+ })}
678
+
679
+ {candles ? (
680
+ shown.map((candle, i) => {
681
+ const tone = toneOf(candle);
682
+ const x = xOf(i);
683
+ const top = yOf(Math.max(candle.open, candle.close));
684
+ const tall = Math.max(
685
+ 1,
686
+ yOf(Math.min(candle.open, candle.close)) - top,
687
+ );
688
+ const risen = candle.close >= candle.open;
689
+ return (
690
+ <g
691
+ key={candle.time.getTime()}
692
+ shapeRendering="crispEdges"
693
+ >
694
+ <line
695
+ stroke={tone}
696
+ x1={x + 0.5}
697
+ x2={x + 0.5}
698
+ y1={yOf(candle.high)}
699
+ y2={yOf(candle.low)}
700
+ />
701
+ {!lines && (
702
+ <rect
703
+ fill={
704
+ risen
705
+ ? `color-mix(in oklab, ${tone} 24%, var(--color-chart-background))`
706
+ : tone
707
+ }
708
+ height={tall}
709
+ stroke={
710
+ risen && body >= 5 ? tone : undefined
711
+ }
712
+ width={body - (risen && body >= 5 ? 1 : 0)}
713
+ x={
714
+ x -
715
+ (body - 1) / 2 +
716
+ (risen && body >= 5 ? 0.5 : 0)
717
+ }
718
+ y={top + (risen && body >= 5 ? 0.5 : 0)}
719
+ />
720
+ )}
721
+ </g>
722
+ );
723
+ })
724
+ ) : (
725
+ <>
726
+ <path
727
+ d={lineAreaPath(points, plotHeight)}
728
+ fill={`url(#${id}-tint)`}
729
+ />
730
+ <path
731
+ d={linePath(points)}
732
+ fill="none"
733
+ stroke={ink}
734
+ strokeLinecap="round"
735
+ strokeLinejoin="round"
736
+ strokeWidth={shown.length > 240 ? 1.5 : 2}
737
+ />
738
+ </>
739
+ )}
740
+
741
+ {averagePoints.length > 1 && (
742
+ <path
743
+ d={linePath(averagePoints)}
744
+ fill="none"
745
+ stroke={candles ? ink : 'var(--color-neutral-600)'}
746
+ strokeDasharray={candles ? undefined : '4 3'}
747
+ strokeLinejoin="round"
748
+ strokeWidth={1.5}
749
+ />
750
+ )}
751
+
752
+ {lastShown && (
753
+ <line
754
+ shapeRendering="crispEdges"
755
+ stroke={lastInk}
756
+ strokeDasharray="2 3"
757
+ x1={0}
758
+ x2={plotWidth}
759
+ y1={Math.round(lastY) + 0.5}
760
+ y2={Math.round(lastY) + 0.5}
761
+ />
762
+ )}
763
+
764
+ {crossX !== null && (
765
+ <g
766
+ shapeRendering="crispEdges"
767
+ stroke="var(--color-chart-crosshair)"
768
+ >
769
+ <line
770
+ x1={Math.round(crossX) + 0.5}
771
+ x2={Math.round(crossX) + 0.5}
772
+ y1={0}
773
+ y2={plotHeight}
774
+ />
775
+ {crossY !== null && (
776
+ <line
777
+ x1={0}
778
+ x2={plotWidth}
779
+ y1={Math.round(crossY) + 0.5}
780
+ y2={Math.round(crossY) + 0.5}
781
+ />
782
+ )}
783
+ </g>
784
+ )}
785
+ {!candles && crossX !== null && reading && (
786
+ <circle
787
+ cx={crossX}
788
+ cy={yOf(reading.close)}
789
+ fill="var(--color-chart-background)"
790
+ r={3.5}
791
+ stroke={ink}
792
+ strokeWidth={2}
793
+ />
794
+ )}
795
+ </g>
796
+
797
+ {/* The prices, outside the frame on the right; under a tag, they give way. */}
798
+ {ticks.map(tick => {
799
+ const y = yOf(tick);
800
+ const hidden =
801
+ (lastShown && Math.abs(y - lastY) < 14) ||
802
+ (crossY !== null && Math.abs(y - crossY) < 14);
803
+ return hidden ? null : (
804
+ <text
805
+ className="text-xxs tabular-nums"
806
+ dominantBaseline="middle"
807
+ fill="var(--color-chart-label)"
808
+ key={tick}
809
+ x={plotWidth + GUTTER_GAP + PILL_PAD}
810
+ y={y}
811
+ >
812
+ {price(tick)}
813
+ </text>
814
+ );
815
+ })}
816
+ {timeTicks.map((i, n) => {
817
+ const candle = shown[i];
818
+ const previous = shown[timeTicks[n - 1] ?? -1];
819
+ const x = xOf(i);
820
+ if (!candle || x > plotWidth - 16) return null;
821
+ // Under the tag of the time being read, a label gives way.
822
+ if (crossX !== null && Math.abs(x - crossX) < 64) return null;
823
+ return (
824
+ <text
825
+ className="text-xxs tabular-nums"
826
+ fill="var(--color-chart-label)"
827
+ key={candle.time.getTime()}
828
+ textAnchor={x < 20 ? 'start' : 'middle'}
829
+ x={x}
830
+ y={plotHeight + 16}
831
+ >
832
+ {writeTime(candle.time, previous?.time)}
833
+ </text>
834
+ );
835
+ })}
836
+ </svg>
837
+
838
+ <div
839
+ aria-hidden
840
+ className={PLOT_FRAME}
841
+ data-slot="candlestick-chart-plot"
842
+ style={{ height: plotHeight, left: 0, top: 0, width: plotWidth }}
843
+ />
844
+
845
+ {/* The period being read, written in the plot's corner as a trading screen does. */}
846
+ <p
847
+ aria-live="polite"
848
+ className="pointer-events-none absolute top-2 left-2.5 flex max-w-full flex-wrap items-center gap-x-2.5 rounded-chip bg-neutral-50/80 px-1 text-xxs tabular-nums leading-5"
849
+ data-slot="candlestick-chart-readout"
850
+ style={{ maxWidth: Math.max(0, plotWidth - 20) }}
851
+ >
852
+ {marking && first && final ? (
853
+ <>
854
+ <span className="text-neutral-600">
855
+ {dayOfMonth.format(first.time)} –{' '}
856
+ {dayOfMonth.format(final.time)}
857
+ </span>
858
+ <span className="font-medium text-neutral-950">
859
+ {price(first.open)} → {price(final.close)}
860
+ </span>
861
+ <Change {...changeOf(first.open, final.close)} />
862
+ </>
863
+ ) : (
864
+ reading && (
865
+ <>
866
+ {candles ? (
867
+ (
868
+ [
869
+ ['O', reading.open],
870
+ ['H', reading.high],
871
+ ['L', reading.low],
872
+ ['C', reading.close],
873
+ ] as const
874
+ ).map(([name, value]) => (
875
+ <span key={name}>
876
+ <span className="text-neutral-600">{name}</span>{' '}
877
+ <span className="font-medium text-neutral-950">
878
+ {price(value)}
879
+ </span>
880
+ </span>
881
+ ))
882
+ ) : (
883
+ <span>
884
+ <span className="text-neutral-600">Close</span>{' '}
885
+ <span className="font-medium text-neutral-950">
886
+ {price(reading.close)}
887
+ </span>
888
+ </span>
889
+ )}
890
+ {change && <Change {...change} />}
891
+ {mean != null && (
892
+ <span>
893
+ <span className="text-neutral-600">
894
+ MA {average}
895
+ </span>{' '}
896
+ <span className="font-medium text-neutral-950">
897
+ {price(mean)}
898
+ </span>
899
+ </span>
900
+ )}
901
+ </>
902
+ )
903
+ )}
904
+ </p>
905
+
906
+ {lastShown && last && (
907
+ // The latest close, tagged on the axis at the end of its rule.
908
+ <span
909
+ className="pointer-events-none absolute -translate-y-1/2 rounded-chip border px-1.5 font-medium text-neutral-950 text-xxs tabular-nums leading-4.5"
910
+ style={{
911
+ background: `color-mix(in oklab, ${lastInk} 16%, var(--color-chart-background))`,
912
+ borderColor: `color-mix(in oklab, ${lastInk} 45%, transparent)`,
913
+ left: plotWidth + GUTTER_GAP,
914
+ top: lastY,
915
+ }}
916
+ >
917
+ {price(last.close)}
918
+ </span>
919
+ )}
920
+ {crossY !== null && (
921
+ <span
922
+ className="pointer-events-none absolute -translate-y-1/2 rounded-chip bg-neutral-950 px-1.5 font-medium text-neutral-50 text-xxs tabular-nums leading-4.5"
923
+ style={{ left: plotWidth + GUTTER_GAP, top: crossY }}
924
+ >
925
+ {price(valueAt(crossY))}
926
+ </span>
927
+ )}
928
+ {crossX !== null && timeTag && (
929
+ <span
930
+ className="pointer-events-none absolute -translate-x-1/2 whitespace-nowrap rounded-chip bg-neutral-950 px-1.5 font-medium text-neutral-50 text-xxs tabular-nums leading-4.5"
931
+ style={{
932
+ left: Math.max(48, Math.min(plotWidth - 48, crossX)),
933
+ top: plotHeight + 4,
934
+ }}
935
+ >
936
+ {timeTag}
937
+ </span>
938
+ )}
939
+
940
+ {/* One surface takes the pointer: the period under it is worked out from x. */}
941
+ <div
942
+ aria-label={`${label}: arrow keys read a period, plus and minus zoom, zero shows all`}
943
+ className={cn(
944
+ 'absolute touch-pan-y rounded-item outline-none focus-visible:outline-2 focus-visible:outline-focus focus-visible:outline-solid',
945
+ drag?.mode === 'pan'
946
+ ? 'cursor-grabbing'
947
+ : whole
948
+ ? 'cursor-crosshair'
949
+ : 'cursor-grab',
950
+ )}
951
+ onBlur={() => setPointer(null)}
952
+ onDoubleClick={reset}
953
+ onKeyDown={onKeyDown}
954
+ onPointerDown={onPointerDown}
955
+ onPointerLeave={() => !drag && setPointer(null)}
956
+ onPointerMove={onPointerMove}
957
+ onPointerUp={onPointerUp}
958
+ ref={setSurface}
959
+ // A slider over the periods in view: the arrow keys read along them.
960
+ aria-valuemax={Math.max(0, shown.length - 1)}
961
+ aria-valuemin={0}
962
+ aria-valuenow={pointed ?? Math.max(0, shown.length - 1)}
963
+ aria-valuetext={
964
+ reading
965
+ ? `${writeTimeLong(reading.time)}, close ${price(reading.close)}`
966
+ : undefined
967
+ }
968
+ role="slider"
969
+ style={{ height: plotHeight, left: 0, top: 0, width: plotWidth }}
970
+ tabIndex={0}
971
+ />
972
+
973
+ {bar}
974
+ </>
975
+ )}
976
+ </div>
977
+
978
+ <div className="sr-only">
979
+ <table>
980
+ <caption>{label}</caption>
981
+ <thead>
982
+ <tr>
983
+ <th scope="col">Opened</th>
984
+ <th scope="col">Open</th>
985
+ <th scope="col">High</th>
986
+ <th scope="col">Low</th>
987
+ <th scope="col">Close</th>
988
+ {withVolume && <th scope="col">Volume</th>}
989
+ </tr>
990
+ </thead>
991
+ <tbody>
992
+ {shown.map(candle => (
993
+ <tr key={candle.time.getTime()}>
994
+ <th scope="row">{writeTimeLong(candle.time)}</th>
995
+ <td>{price(candle.open)}</td>
996
+ <td>{price(candle.high)}</td>
997
+ <td>{price(candle.low)}</td>
998
+ <td>{price(candle.close)}</td>
999
+ {withVolume && <td>{candle.volume ?? ''}</td>}
1000
+ </tr>
1001
+ ))}
1002
+ </tbody>
1003
+ </table>
1004
+ </div>
1005
+ </figure>
1006
+ );
1007
+ };
1008
+
1009
+ /**
1010
+ * The stand-in's closes, a price in no unit: a climb, a sharp fall about three fifths of the way
1011
+ * in and a recovery after it, with the small turns back a price makes on the way.
1012
+ */
1013
+ const SKELETON_CLOSES = [
1014
+ 104.2, 104.8, 104.5, 105.6, 106.1, 105.7, 106.8, 107.4, 107, 108.2, 108.9, 108.4, 109.3, 110.1,
1015
+ 109.6, 110.4, 111.2, 110.7, 109.1, 107.6, 108, 106.4, 105.2, 105.9, 104.6, 105.3, 106.2, 105.8,
1016
+ 106.9, 107.7, 107.3, 108.4, 109, 108.6, 109.5, 110.2,
1017
+ ];
1018
+
1019
+ /** How far the stand-in's wicks reach past their bodies, taken in turn. */
1020
+ const SKELETON_WICKS = [0.3, 0.5, 0.2, 0.6, 0.4, 0.25, 0.45];
1021
+
1022
+ /** The firm ink of the stand-in: a fallen body and every wick, a step over the wash. */
1023
+ const SKELETON_EDGE = 'color-mix(in oklab, var(--color-neutral-950) 14%, transparent)';
1024
+
1025
+ /** The stand-in's periods, each opening where the last closed. */
1026
+ const SKELETON_CANDLES = SKELETON_CLOSES.map((close, i) => {
1027
+ const open = SKELETON_CLOSES[i - 1] ?? close - 0.6;
1028
+ return {
1029
+ open,
1030
+ close,
1031
+ high: Math.max(open, close) + (SKELETON_WICKS[i % SKELETON_WICKS.length] ?? 0.3),
1032
+ low: Math.min(open, close) - (SKELETON_WICKS[(i + 3) % SKELETON_WICKS.length] ?? 0.3),
1033
+ };
1034
+ });
1035
+
1036
+ /**
1037
+ * A chart that is loading, with the depth of a loaded one: the plot's grid at round steps of
1038
+ * its own made-up prices, a few dozen candles (or the line over its tint) in the skeleton wash,
1039
+ * the volume along the foot, and short bars where the prices and the times will be written.
1040
+ * It takes the plot's room, so nothing moves when the prices land.
1041
+ */
1042
+ const CandleSkeleton = ({
1043
+ candles,
1044
+ width,
1045
+ height,
1046
+ priceTop,
1047
+ priceFoot,
1048
+ volumeHeight,
1049
+ labelWidth,
1050
+ }: {
1051
+ candles: boolean;
1052
+ width: number;
1053
+ height: number;
1054
+ priceTop: number;
1055
+ priceFoot: number;
1056
+ volumeHeight: number;
1057
+ labelWidth: number;
1058
+ }) => {
1059
+ if (width <= 0 || height <= 0) return null;
1060
+ const count = SKELETON_CANDLES.length;
1061
+ const low = Math.min(...SKELETON_CANDLES.map(candle => candle.low));
1062
+ const high = Math.max(...SKELETON_CANDLES.map(candle => candle.high));
1063
+ const span = priceFoot - priceTop;
1064
+ const yOf = (value: number) => priceTop + ((high - value) / (high - low)) * span;
1065
+ const valueAt = (y: number) => high - ((y - priceTop) / span) * (high - low);
1066
+
1067
+ // The rules, worked out as the loaded chart works out its own, at the wider spacing a real
1068
+ // price's round steps usually land on: at the least spacing they crowd the stand-in.
1069
+ const step = niceStep(((high - low) / Math.max(1, span)) * 60);
1070
+ const ticks: number[] = [];
1071
+ for (let i = Math.ceil(valueAt(height - 10) / step); i * step <= valueAt(10); i++)
1072
+ ticks.push(i * step);
1073
+
1074
+ // Candles stand in the middle of their slots, a line runs edge to edge, as when loaded.
1075
+ const slot = width / count;
1076
+ const pitch = width / (count - 1);
1077
+ const rawBody = Math.min(
1078
+ BODY_MAX,
1079
+ Math.floor(slot) - Math.max(1, Math.round(slot * (1 - BODY_SHARE))),
1080
+ );
1081
+ const body = Math.max(1, rawBody % 2 ? rawBody : rawBody - 1);
1082
+ const xOf = (i: number) => (candles ? Math.floor(slot * i + slot / 2) : pitch * i);
1083
+ const wide = candles ? body : Math.max(1, Math.floor(pitch) - 1);
1084
+
1085
+ // What traded follows how far the price moved, as it tends to.
1086
+ const moves = SKELETON_CANDLES.map(candle => Math.abs(candle.close - candle.open));
1087
+ const biggest = Math.max(...moves);
1088
+
1089
+ const points = SKELETON_CANDLES.map((candle, i) => ({ x: xOf(i), y: yOf(candle.close) }));
1090
+ // The line's edge: a 2px ribbon along it.
1091
+ const edge = `${linePath(points)} ${linePath(
1092
+ points.map(point => ({ ...point, y: point.y + 2 })).reverse(),
1093
+ ).replace(/^M/, 'L')} Z`;
1094
+
1095
+ // A time every so often under the plot, as far apart as the loaded labels are.
1096
+ const every = Math.max(1, Math.ceil(TIME_ROOM / Math.max(candles ? slot : pitch, 1e-6)));
1097
+ const times: number[] = [];
1098
+ for (let i = 0; i < count; i += every) if (xOf(i) <= width - 16) times.push(xOf(i));
1099
+
1100
+ return (
1101
+ <div
1102
+ aria-hidden
1103
+ className="pointer-events-none absolute inset-0"
1104
+ data-slot="chart-skeleton"
1105
+ >
1106
+ <div
1107
+ className="absolute top-0 left-0 overflow-hidden rounded-item"
1108
+ style={{ height, width }}
1109
+ >
1110
+ {ticks.map(tick => (
1111
+ <div
1112
+ className="absolute inset-x-0 h-px"
1113
+ key={tick}
1114
+ style={{
1115
+ backgroundColor: 'var(--color-chart-grid)',
1116
+ top: Math.round(yOf(tick)),
1117
+ }}
1118
+ />
1119
+ ))}
1120
+ {volumeHeight > 0 &&
1121
+ moves.map((move, i) => {
1122
+ const tall = Math.round(volumeHeight * (0.3 + 0.7 * (move / biggest)));
1123
+ return (
1124
+ <div
1125
+ className="skeleton absolute"
1126
+ // biome-ignore lint/suspicious/noArrayIndexKey: the stand-in never reorders.
1127
+ key={i}
1128
+ style={{
1129
+ height: tall,
1130
+ left: Math.round(xOf(i) - wide / 2),
1131
+ top: height - tall,
1132
+ width: wide,
1133
+ }}
1134
+ />
1135
+ );
1136
+ })}
1137
+ {candles ? (
1138
+ SKELETON_CANDLES.map((candle, i) => {
1139
+ const x = xOf(i);
1140
+ const top = Math.round(yOf(Math.max(candle.open, candle.close)));
1141
+ const foot = Math.round(yOf(Math.min(candle.open, candle.close)));
1142
+ const tall = Math.max(1, foot - top);
1143
+ const risen = candle.close >= candle.open;
1144
+ const wick = 'skeleton absolute w-px';
1145
+ return (
1146
+ // biome-ignore lint/suspicious/noArrayIndexKey: the stand-in never reorders.
1147
+ <Fragment key={i}>
1148
+ {/* The wick in two, above and below the body, so a risen body's wash stays clear. */}
1149
+ <div
1150
+ className={wick}
1151
+ style={{
1152
+ backgroundColor: SKELETON_EDGE,
1153
+ height: Math.max(0, top - Math.round(yOf(candle.high))),
1154
+ left: x,
1155
+ top: Math.round(yOf(candle.high)),
1156
+ }}
1157
+ />
1158
+ <div
1159
+ className={wick}
1160
+ style={{
1161
+ backgroundColor: SKELETON_EDGE,
1162
+ height: Math.max(0, Math.round(yOf(candle.low)) - foot),
1163
+ left: x,
1164
+ top: foot,
1165
+ }}
1166
+ />
1167
+ {/* A rise is the wash with a firm edge, a fall firm, as the loaded candles are. */}
1168
+ <div
1169
+ className={cn(
1170
+ 'skeleton absolute',
1171
+ risen && body >= 5 && 'border',
1172
+ )}
1173
+ style={{
1174
+ backgroundColor: risen ? undefined : SKELETON_EDGE,
1175
+ borderColor: SKELETON_EDGE,
1176
+ height: tall,
1177
+ left: x - (body - 1) / 2,
1178
+ top,
1179
+ width: body,
1180
+ }}
1181
+ />
1182
+ </Fragment>
1183
+ );
1184
+ })
1185
+ ) : (
1186
+ <>
1187
+ <div
1188
+ className="skeleton absolute inset-0"
1189
+ style={{
1190
+ clipPath: `path('${lineAreaPath(points, height)}')`,
1191
+ // The wash fades towards the foot, as the line's tint does.
1192
+ maskImage:
1193
+ 'linear-gradient(to bottom, black 20%, transparent 100%)',
1194
+ }}
1195
+ />
1196
+ <div
1197
+ className="skeleton absolute inset-0"
1198
+ style={{ backgroundColor: SKELETON_EDGE, clipPath: `path('${edge}')` }}
1199
+ />
1200
+ </>
1201
+ )}
1202
+ </div>
1203
+ {/* Where the prices and the times will be written, outside the frame as they are. */}
1204
+ {ticks.map(tick => {
1205
+ const y = yOf(tick);
1206
+ return y < 8 || y > height - 8 ? null : (
1207
+ <div
1208
+ className="skeleton absolute h-2 rounded-chip"
1209
+ key={tick}
1210
+ style={{
1211
+ left: width + GUTTER_GAP + PILL_PAD,
1212
+ top: Math.round(y) - 4,
1213
+ width: Math.max(16, labelWidth * 0.8),
1214
+ }}
1215
+ />
1216
+ );
1217
+ })}
1218
+ {times.map(x => (
1219
+ <div
1220
+ className={cn(
1221
+ 'skeleton absolute h-2 w-9 rounded-chip',
1222
+ x >= 20 && '-translate-x-1/2',
1223
+ )}
1224
+ key={x}
1225
+ style={{ left: x, top: height + 8 }}
1226
+ />
1227
+ ))}
1228
+ </div>
1229
+ );
1230
+ };
1231
+
1232
+ /** A change, in the tone of its direction. */
1233
+ const Change = ({ share, text }: { share: number; text: string }) => (
1234
+ <span
1235
+ className={cn(
1236
+ 'font-medium',
1237
+ share > 0 ? CHANGE_INK.up : share < 0 ? CHANGE_INK.down : CHANGE_INK.neutral,
1238
+ )}
1239
+ >
1240
+ {text}
1241
+ </span>
1242
+ );