@zonsh/ui 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -1
  3. package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
  4. package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
  5. package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
  6. package/assets/illustrations/drawing/bracket-construction.svg +77 -0
  7. package/assets/illustrations/drawing/crescent-dark.svg +28 -0
  8. package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
  9. package/assets/illustrations/drawing/crescent-guides.svg +33 -0
  10. package/assets/illustrations/drawing/crescent.svg +28 -0
  11. package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
  12. package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
  13. package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
  14. package/assets/illustrations/drawing/eclipse.svg +187 -0
  15. package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
  16. package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
  17. package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
  18. package/assets/illustrations/drawing/elevation-guides.svg +31 -0
  19. package/assets/illustrations/drawing/horizon-dark.svg +30 -0
  20. package/assets/illustrations/drawing/horizon.svg +30 -0
  21. package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
  22. package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
  23. package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
  24. package/assets/illustrations/drawing/nib-study.svg +107 -0
  25. package/assets/illustrations/editorial/assistant-640.webp +0 -0
  26. package/assets/illustrations/editorial/assistant.webp +0 -0
  27. package/assets/illustrations/editorial/automation-640.webp +0 -0
  28. package/assets/illustrations/editorial/automation.webp +0 -0
  29. package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
  30. package/assets/illustrations/editorial/bracket-left.webp +0 -0
  31. package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
  32. package/assets/illustrations/editorial/bracket-right.webp +0 -0
  33. package/assets/illustrations/editorial/custom-software-640.webp +0 -0
  34. package/assets/illustrations/editorial/custom-software.webp +0 -0
  35. package/assets/illustrations/editorial/digitalization-640.webp +0 -0
  36. package/assets/illustrations/editorial/digitalization.webp +0 -0
  37. package/assets/illustrations/editorial/integration-640.webp +0 -0
  38. package/assets/illustrations/editorial/integration.webp +0 -0
  39. package/assets/illustrations/editorial/problem-640.webp +0 -0
  40. package/assets/illustrations/editorial/problem.webp +0 -0
  41. package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
  42. package/assets/illustrations/editorial/process-analysis.webp +0 -0
  43. package/assets/illustrations/editorial/process-concept-640.webp +0 -0
  44. package/assets/illustrations/editorial/process-concept.webp +0 -0
  45. package/assets/illustrations/editorial/process-development-640.webp +0 -0
  46. package/assets/illustrations/editorial/process-development.webp +0 -0
  47. package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
  48. package/assets/illustrations/editorial/process-discovery.webp +0 -0
  49. package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
  50. package/assets/illustrations/editorial/process-maintenance.webp +0 -0
  51. package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
  52. package/assets/illustrations/editorial/process-prototype.webp +0 -0
  53. package/assets/illustrations/editorial/process-testing-640.webp +0 -0
  54. package/assets/illustrations/editorial/process-testing.webp +0 -0
  55. package/assets/illustrations/iso/automation-dark.svg +6 -0
  56. package/assets/illustrations/iso/automation.svg +6 -0
  57. package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
  58. package/assets/illustrations/iso/bar-chart.svg +6 -0
  59. package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
  60. package/assets/illustrations/iso/brackets-classic.svg +6 -0
  61. package/assets/illustrations/iso/brackets-dark.svg +6 -0
  62. package/assets/illustrations/iso/brackets.svg +6 -0
  63. package/assets/illustrations/iso/city-dark.svg +6 -0
  64. package/assets/illustrations/iso/city.svg +6 -0
  65. package/assets/illustrations/iso/conveyor-dark.svg +6 -0
  66. package/assets/illustrations/iso/conveyor.svg +6 -0
  67. package/assets/illustrations/iso/database-dark.svg +6 -0
  68. package/assets/illustrations/iso/database.svg +6 -0
  69. package/assets/illustrations/iso/documents-dark.svg +6 -0
  70. package/assets/illustrations/iso/documents.svg +6 -0
  71. package/assets/illustrations/iso/inbox-dark.svg +6 -0
  72. package/assets/illustrations/iso/inbox.svg +6 -0
  73. package/assets/illustrations/iso/laptop-dark.svg +6 -0
  74. package/assets/illustrations/iso/laptop.svg +6 -0
  75. package/assets/illustrations/iso/monitor-dark.svg +6 -0
  76. package/assets/illustrations/iso/monitor.svg +6 -0
  77. package/assets/illustrations/iso/pipeline-dark.svg +6 -0
  78. package/assets/illustrations/iso/pipeline.svg +6 -0
  79. package/assets/illustrations/iso/platform-dark.svg +6 -0
  80. package/assets/illustrations/iso/platform.svg +6 -0
  81. package/assets/illustrations/iso/server-dark.svg +6 -0
  82. package/assets/illustrations/iso/server.svg +6 -0
  83. package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
  84. package/assets/illustrations/iso/spreadsheet.svg +6 -0
  85. package/assets/illustrations/iso/timeline-dark.svg +6 -0
  86. package/assets/illustrations/iso/timeline.svg +6 -0
  87. package/assets/illustrations/sheet/construction.svg +115 -0
  88. package/assets/illustrations/sheet/crescent.svg +40 -0
  89. package/assets/illustrations/sheet/limb.svg +42 -0
  90. package/assets/illustrations/sheet/stress-axis.svg +119 -0
  91. package/assets/illustrations/sheet/totality.svg +215 -0
  92. package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
  93. package/assets/logo-left.svg +1 -0
  94. package/assets/logo-right.svg +1 -0
  95. package/assets/logo.svg +1 -0
  96. package/dist/components/_overlay.d.ts +47 -0
  97. package/dist/components/_overlay.js +59 -0
  98. package/dist/components/accordion.d.ts +32 -0
  99. package/dist/components/accordion.js +39 -0
  100. package/dist/components/alert-dialog.d.ts +45 -0
  101. package/dist/components/alert-dialog.js +56 -0
  102. package/dist/components/alert.d.ts +35 -0
  103. package/dist/components/alert.js +42 -0
  104. package/dist/components/ascii-field.d.ts +34 -0
  105. package/dist/components/ascii-field.js +410 -0
  106. package/dist/components/aspect-ratio.d.ts +14 -0
  107. package/dist/components/aspect-ratio.js +17 -0
  108. package/dist/components/avatar.d.ts +42 -0
  109. package/dist/components/avatar.js +55 -0
  110. package/dist/components/badge.d.ts +70 -0
  111. package/dist/components/badge.js +62 -0
  112. package/dist/components/breadcrumb.d.ts +22 -0
  113. package/dist/components/breadcrumb.js +32 -0
  114. package/dist/components/button-group.d.ts +30 -0
  115. package/dist/components/button-group.js +47 -0
  116. package/dist/components/button.d.ts +53 -0
  117. package/dist/components/button.js +130 -0
  118. package/dist/components/calendar.d.ts +26 -0
  119. package/dist/components/calendar.js +164 -0
  120. package/dist/components/card.d.ts +42 -0
  121. package/dist/components/card.js +76 -0
  122. package/dist/components/carousel.d.ts +90 -0
  123. package/dist/components/carousel.js +213 -0
  124. package/dist/components/chart.d.ts +180 -0
  125. package/dist/components/chart.js +286 -0
  126. package/dist/components/checkbox.d.ts +23 -0
  127. package/dist/components/checkbox.js +43 -0
  128. package/dist/components/code-block.d.ts +45 -0
  129. package/dist/components/code-block.js +58 -0
  130. package/dist/components/code-highlight.d.ts +13 -0
  131. package/dist/components/code-highlight.js +107 -0
  132. package/dist/components/collapsible.d.ts +20 -0
  133. package/dist/components/collapsible.js +32 -0
  134. package/dist/components/color-picker.d.ts +85 -0
  135. package/dist/components/color-picker.js +407 -0
  136. package/dist/components/combobox.d.ts +81 -0
  137. package/dist/components/combobox.js +100 -0
  138. package/dist/components/command.d.ts +112 -0
  139. package/dist/components/command.js +212 -0
  140. package/dist/components/context-menu.d.ts +29 -0
  141. package/dist/components/context-menu.js +35 -0
  142. package/dist/components/conversation.d.ts +27 -0
  143. package/dist/components/conversation.js +293 -0
  144. package/dist/components/copy-button.d.ts +46 -0
  145. package/dist/components/copy-button.js +118 -0
  146. package/dist/components/data-table.d.ts +175 -0
  147. package/dist/components/data-table.js +302 -0
  148. package/dist/components/date-picker.d.ts +91 -0
  149. package/dist/components/date-picker.js +207 -0
  150. package/dist/components/dialog.d.ts +48 -0
  151. package/dist/components/dialog.js +92 -0
  152. package/dist/components/direction.d.ts +16 -0
  153. package/dist/components/direction.js +18 -0
  154. package/dist/components/drawer.d.ts +60 -0
  155. package/dist/components/drawer.js +76 -0
  156. package/dist/components/empty.d.ts +31 -0
  157. package/dist/components/empty.js +50 -0
  158. package/dist/components/feature-list.d.ts +54 -0
  159. package/dist/components/feature-list.js +43 -0
  160. package/dist/components/field.d.ts +15 -0
  161. package/dist/components/field.js +36 -0
  162. package/dist/components/file-drop.d.ts +55 -0
  163. package/dist/components/file-drop.js +197 -0
  164. package/dist/components/filter-bar.d.ts +106 -0
  165. package/dist/components/filter-bar.js +296 -0
  166. package/dist/components/form.d.ts +33 -0
  167. package/dist/components/form.js +34 -0
  168. package/dist/components/graph.d.ts +105 -0
  169. package/dist/components/graph.js +786 -0
  170. package/dist/components/illustration.d.ts +85 -0
  171. package/dist/components/illustration.js +165 -0
  172. package/dist/components/input-group.d.ts +127 -0
  173. package/dist/components/input-group.js +292 -0
  174. package/dist/components/input.d.ts +16 -0
  175. package/dist/components/input.js +25 -0
  176. package/dist/components/item.d.ts +64 -0
  177. package/dist/components/item.js +116 -0
  178. package/dist/components/kbd.d.ts +33 -0
  179. package/dist/components/kbd.js +38 -0
  180. package/dist/components/label.d.ts +12 -0
  181. package/dist/components/label.js +24 -0
  182. package/dist/components/layout.d.ts +136 -0
  183. package/dist/components/layout.js +162 -0
  184. package/dist/components/logo.d.ts +54 -0
  185. package/dist/components/logo.js +96 -0
  186. package/dist/components/menu.d.ts +60 -0
  187. package/dist/components/menu.js +138 -0
  188. package/dist/components/menubar.d.ts +62 -0
  189. package/dist/components/menubar.js +223 -0
  190. package/dist/components/message.d.ts +42 -0
  191. package/dist/components/message.js +56 -0
  192. package/dist/components/meter.d.ts +31 -0
  193. package/dist/components/meter.js +25 -0
  194. package/dist/components/native-select.d.ts +26 -0
  195. package/dist/components/native-select.js +35 -0
  196. package/dist/components/navigation-menu.d.ts +42 -0
  197. package/dist/components/navigation-menu.js +97 -0
  198. package/dist/components/number-field.d.ts +36 -0
  199. package/dist/components/number-field.js +153 -0
  200. package/dist/components/otp-field.d.ts +35 -0
  201. package/dist/components/otp-field.js +94 -0
  202. package/dist/components/pagination.d.ts +31 -0
  203. package/dist/components/pagination.js +70 -0
  204. package/dist/components/pdf-viewer.d.ts +69 -0
  205. package/dist/components/pdf-viewer.js +929 -0
  206. package/dist/components/popover.d.ts +33 -0
  207. package/dist/components/popover.js +48 -0
  208. package/dist/components/preview-card.d.ts +25 -0
  209. package/dist/components/preview-card.js +22 -0
  210. package/dist/components/progress.d.ts +27 -0
  211. package/dist/components/progress.js +23 -0
  212. package/dist/components/prompt-input.d.ts +131 -0
  213. package/dist/components/prompt-input.js +403 -0
  214. package/dist/components/quote.d.ts +22 -0
  215. package/dist/components/quote.js +15 -0
  216. package/dist/components/radio-group.d.ts +18 -0
  217. package/dist/components/radio-group.js +34 -0
  218. package/dist/components/reasoning.d.ts +31 -0
  219. package/dist/components/reasoning.js +70 -0
  220. package/dist/components/resizable.d.ts +38 -0
  221. package/dist/components/resizable.js +41 -0
  222. package/dist/components/response.d.ts +30 -0
  223. package/dist/components/response.js +538 -0
  224. package/dist/components/scroll-area.d.ts +33 -0
  225. package/dist/components/scroll-area.js +31 -0
  226. package/dist/components/select.d.ts +35 -0
  227. package/dist/components/select.js +60 -0
  228. package/dist/components/separator.d.ts +14 -0
  229. package/dist/components/separator.js +17 -0
  230. package/dist/components/sidebar.d.ts +147 -0
  231. package/dist/components/sidebar.js +489 -0
  232. package/dist/components/site-header.d.ts +59 -0
  233. package/dist/components/site-header.js +67 -0
  234. package/dist/components/skeleton.d.ts +31 -0
  235. package/dist/components/skeleton.js +29 -0
  236. package/dist/components/slider.d.ts +24 -0
  237. package/dist/components/slider.js +129 -0
  238. package/dist/components/sources.d.ts +25 -0
  239. package/dist/components/sources.js +35 -0
  240. package/dist/components/spinner.d.ts +36 -0
  241. package/dist/components/spinner.js +72 -0
  242. package/dist/components/suggestions.d.ts +20 -0
  243. package/dist/components/suggestions.js +18 -0
  244. package/dist/components/switch.d.ts +14 -0
  245. package/dist/components/switch.js +26 -0
  246. package/dist/components/table.d.ts +162 -0
  247. package/dist/components/table.js +758 -0
  248. package/dist/components/tabs.d.ts +25 -0
  249. package/dist/components/tabs.js +162 -0
  250. package/dist/components/tag.d.ts +41 -0
  251. package/dist/components/tag.js +88 -0
  252. package/dist/components/tags-input.d.ts +40 -0
  253. package/dist/components/tags-input.js +239 -0
  254. package/dist/components/textarea.d.ts +13 -0
  255. package/dist/components/textarea.js +16 -0
  256. package/dist/components/theme.d.ts +41 -0
  257. package/dist/components/theme.js +112 -0
  258. package/dist/components/time-field.d.ts +51 -0
  259. package/dist/components/time-field.js +437 -0
  260. package/dist/components/timeline.d.ts +76 -0
  261. package/dist/components/timeline.js +99 -0
  262. package/dist/components/toast.d.ts +72 -0
  263. package/dist/components/toast.js +196 -0
  264. package/dist/components/toggle-group.d.ts +41 -0
  265. package/dist/components/toggle-group.js +140 -0
  266. package/dist/components/toggle.d.ts +23 -0
  267. package/dist/components/toggle.js +35 -0
  268. package/dist/components/tool-call.d.ts +52 -0
  269. package/dist/components/tool-call.js +57 -0
  270. package/dist/components/toolbar.d.ts +17 -0
  271. package/dist/components/toolbar.js +34 -0
  272. package/dist/components/tooltip.d.ts +42 -0
  273. package/dist/components/tooltip.js +47 -0
  274. package/dist/components/tree.d.ts +75 -0
  275. package/dist/components/tree.js +636 -0
  276. package/dist/components/typography.d.ts +134 -0
  277. package/dist/components/typography.js +176 -0
  278. package/dist/components/video-player.d.ts +276 -0
  279. package/dist/components/video-player.js +1352 -0
  280. package/dist/components/whiteboard.d.ts +80 -0
  281. package/dist/components/whiteboard.js +389 -0
  282. package/dist/index.d.ts +85 -0
  283. package/dist/index.js +86 -0
  284. package/dist/lib/cn.d.ts +20 -0
  285. package/dist/lib/cn.js +38 -0
  286. package/dist/lib/code-highlight.d.ts +31 -0
  287. package/dist/lib/code-highlight.js +24 -0
  288. package/dist/lib/code-theme.d.ts +19 -0
  289. package/dist/lib/code-theme.js +140 -0
  290. package/dist/lib/collapse-row.d.ts +9 -0
  291. package/dist/lib/collapse-row.js +129 -0
  292. package/dist/lib/digit-roll.d.ts +21 -0
  293. package/dist/lib/digit-roll.js +31 -0
  294. package/dist/lib/editorial-assets.d.ts +16 -0
  295. package/dist/lib/editorial-assets.js +56 -0
  296. package/dist/lib/figure/catalog.d.ts +127 -0
  297. package/dist/lib/figure/catalog.js +130 -0
  298. package/dist/lib/figure/figures/automation.d.ts +7 -0
  299. package/dist/lib/figure/figures/automation.js +143 -0
  300. package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
  301. package/dist/lib/figure/figures/bar-chart.js +99 -0
  302. package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
  303. package/dist/lib/figure/figures/brackets-classic.js +170 -0
  304. package/dist/lib/figure/figures/brackets.d.ts +8 -0
  305. package/dist/lib/figure/figures/brackets.js +84 -0
  306. package/dist/lib/figure/figures/city.d.ts +7 -0
  307. package/dist/lib/figure/figures/city.js +93 -0
  308. package/dist/lib/figure/figures/conveyor.d.ts +7 -0
  309. package/dist/lib/figure/figures/conveyor.js +97 -0
  310. package/dist/lib/figure/figures/database.d.ts +7 -0
  311. package/dist/lib/figure/figures/database.js +65 -0
  312. package/dist/lib/figure/figures/documents.d.ts +7 -0
  313. package/dist/lib/figure/figures/documents.js +83 -0
  314. package/dist/lib/figure/figures/inbox.d.ts +7 -0
  315. package/dist/lib/figure/figures/inbox.js +92 -0
  316. package/dist/lib/figure/figures/laptop.d.ts +7 -0
  317. package/dist/lib/figure/figures/laptop.js +67 -0
  318. package/dist/lib/figure/figures/monitor.d.ts +7 -0
  319. package/dist/lib/figure/figures/monitor.js +59 -0
  320. package/dist/lib/figure/figures/pipeline.d.ts +8 -0
  321. package/dist/lib/figure/figures/pipeline.js +117 -0
  322. package/dist/lib/figure/figures/platform.d.ts +7 -0
  323. package/dist/lib/figure/figures/platform.js +117 -0
  324. package/dist/lib/figure/figures/server.d.ts +7 -0
  325. package/dist/lib/figure/figures/server.js +115 -0
  326. package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
  327. package/dist/lib/figure/figures/spreadsheet.js +87 -0
  328. package/dist/lib/figure/figures/timeline.d.ts +7 -0
  329. package/dist/lib/figure/figures/timeline.js +65 -0
  330. package/dist/lib/figure/kernel.d.ts +152 -0
  331. package/dist/lib/figure/kernel.js +576 -0
  332. package/dist/lib/figure/parts.d.ts +42 -0
  333. package/dist/lib/figure/parts.js +126 -0
  334. package/dist/lib/form-reset.d.ts +11 -0
  335. package/dist/lib/form-reset.js +22 -0
  336. package/dist/lib/glide.d.ts +53 -0
  337. package/dist/lib/glide.js +138 -0
  338. package/dist/lib/graph-layout.d.ts +58 -0
  339. package/dist/lib/graph-layout.js +200 -0
  340. package/dist/lib/illustration-drawings.d.ts +89 -0
  341. package/dist/lib/illustration-drawings.js +539 -0
  342. package/dist/lib/illustration-info.d.ts +37 -0
  343. package/dist/lib/illustration-info.js +22 -0
  344. package/dist/lib/illustration-library.d.ts +87 -0
  345. package/dist/lib/illustration-library.js +352 -0
  346. package/dist/lib/logo-geometry.d.ts +29 -0
  347. package/dist/lib/logo-geometry.js +67 -0
  348. package/dist/lib/markdown-guard.d.ts +16 -0
  349. package/dist/lib/markdown-guard.js +123 -0
  350. package/dist/lib/merge-refs.d.ts +10 -0
  351. package/dist/lib/merge-refs.js +26 -0
  352. package/dist/lib/motion.d.ts +6 -0
  353. package/dist/lib/motion.js +12 -0
  354. package/dist/lib/pdf-worker.d.ts +1 -0
  355. package/dist/lib/pdf-worker.js +6 -0
  356. package/dist/lib/pdf.d.ts +19 -0
  357. package/dist/lib/pdf.js +58 -0
  358. package/dist/lib/platform.d.ts +33 -0
  359. package/dist/lib/platform.js +68 -0
  360. package/dist/lib/room.d.ts +25 -0
  361. package/dist/lib/room.js +46 -0
  362. package/dist/lib/table-fit.d.ts +143 -0
  363. package/dist/lib/table-fit.js +577 -0
  364. package/dist/lib/theme-script.d.ts +18 -0
  365. package/dist/lib/theme-script.js +29 -0
  366. package/dist/styles/expressive.css +188 -0
  367. package/dist/styles/fonts.css +145 -0
  368. package/dist/styles/index.css +206 -0
  369. package/dist/styles/material.css +313 -0
  370. package/dist/styles/parts/ai.css +360 -0
  371. package/dist/styles/parts/brand.css +75 -0
  372. package/dist/styles/parts/controls.css +725 -0
  373. package/dist/styles/parts/data.css +222 -0
  374. package/dist/styles/parts/editorial.css +120 -0
  375. package/dist/styles/parts/feedback.css +273 -0
  376. package/dist/styles/parts/foundations.css +166 -0
  377. package/dist/styles/parts/graph.css +214 -0
  378. package/dist/styles/parts/inputs.css +261 -0
  379. package/dist/styles/parts/isometric.css +124 -0
  380. package/dist/styles/parts/navigation.css +232 -0
  381. package/dist/styles/parts/overlays.css +250 -0
  382. package/dist/styles/parts/pdf.css +154 -0
  383. package/dist/styles/parts/react-flow.css +519 -0
  384. package/dist/styles/parts/whiteboard.css +855 -0
  385. package/dist/styles/tokens.css +290 -0
  386. package/dist/vite.d.ts +116 -0
  387. package/dist/vite.js +129 -0
  388. package/package.json +188 -5
@@ -0,0 +1,41 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ThemeMode } from "../lib/theme-script.js";
3
+ import { type ButtonProps } from "./button.js";
4
+ export { createThemeScript, themeScript, THEME_STORAGE_KEY, type ThemeMode } from "../lib/theme-script.js";
5
+ export type ResolvedTheme = "light" | "dark";
6
+ export interface ThemeContextValue {
7
+ /** The stored preference: `light`, `dark` or `system`. */
8
+ theme: ThemeMode;
9
+ /** What is actually applied: `system` resolved against `prefers-color-scheme`. */
10
+ resolvedTheme: ResolvedTheme;
11
+ setTheme: (theme: ThemeMode) => void;
12
+ }
13
+ export interface ThemeProviderProps {
14
+ children: ReactNode;
15
+ /** Used when nothing is stored yet. Default `system`. */
16
+ defaultTheme?: ThemeMode;
17
+ /** localStorage key. Default `zon-theme`. */
18
+ storageKey?: string;
19
+ }
20
+ /**
21
+ * ThemeProvider — light, dark or system theme for the whole document. It toggles `.dark` on
22
+ * `<html>`, remembers the choice in localStorage and follows `prefers-color-scheme` while set
23
+ * to `system`.
24
+ *
25
+ * Mount it once at the root and inline `themeScript` in `<head>` so the first paint is
26
+ * already correct. The rule people break: forgetting the script, which flashes light
27
+ * before React hydrates.
28
+ */
29
+ export declare function ThemeProvider({ children, defaultTheme, storageKey, }: ThemeProviderProps): import("react").JSX.Element;
30
+ /** Read and change the theme. Must be used inside `ThemeProvider`. */
31
+ export declare function useTheme(): ThemeContextValue;
32
+ export interface ThemeToggleProps extends Omit<ButtonProps, "children" | "variant" | "size"> {
33
+ }
34
+ /**
35
+ * ThemeToggle — a circular secondary icon button that switches between light and dark.
36
+ * It shows the moon in light mode and the sun in dark mode; the icon is chosen by CSS, so it
37
+ * is right on the first paint even before React hydrates.
38
+ *
39
+ * The rule people break: placing two toggles on a page. One lives in the header.
40
+ */
41
+ export declare function ThemeToggle({ onClick, ...props }: ThemeToggleProps): import("react").JSX.Element;
@@ -0,0 +1,112 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { MoonIcon, SunIcon } from "lucide-react";
4
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
5
+ import { DARK_QUERY, THEME_STORAGE_KEY } from "../lib/theme-script.js";
6
+ import { Button } from "./button.js";
7
+ export { createThemeScript, themeScript, THEME_STORAGE_KEY } from "../lib/theme-script.js";
8
+ const ThemeContext = createContext(null);
9
+ const isMode = (v) => v === "light" || v === "dark" || v === "system";
10
+ function readStored(key) {
11
+ try {
12
+ const v = window.localStorage.getItem(key);
13
+ return isMode(v) ? v : null;
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+ function writeStored(key, value) {
20
+ try {
21
+ window.localStorage.setItem(key, value);
22
+ }
23
+ catch {
24
+ /* storage unavailable (private mode, blocked cookies) — the choice lasts for the session */
25
+ }
26
+ }
27
+ function systemDark() {
28
+ try {
29
+ return window.matchMedia(DARK_QUERY).matches;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
35
+ /**
36
+ * ThemeProvider — light, dark or system theme for the whole document. It toggles `.dark` on
37
+ * `<html>`, remembers the choice in localStorage and follows `prefers-color-scheme` while set
38
+ * to `system`.
39
+ *
40
+ * Mount it once at the root and inline `themeScript` in `<head>` so the first paint is
41
+ * already correct. The rule people break: forgetting the script, which flashes light
42
+ * before React hydrates.
43
+ */
44
+ export function ThemeProvider({ children, defaultTheme = "system", storageKey = THEME_STORAGE_KEY, }) {
45
+ const [theme, setThemeState] = useState(defaultTheme);
46
+ const [prefersDark, setPrefersDark] = useState(false);
47
+ const [mounted, setMounted] = useState(false);
48
+ // Read the stored preference and the system scheme after mount (SSR-safe).
49
+ useEffect(() => {
50
+ setThemeState(readStored(storageKey) ?? defaultTheme);
51
+ setPrefersDark(systemDark());
52
+ setMounted(true);
53
+ }, [storageKey, defaultTheme]);
54
+ // Follow the OS while on `system`, and other tabs when they change the preference.
55
+ useEffect(() => {
56
+ let mq = null;
57
+ const onScheme = (e) => setPrefersDark(e.matches);
58
+ const onStorage = (e) => {
59
+ if (e.key === storageKey)
60
+ setThemeState(isMode(e.newValue) ? e.newValue : defaultTheme);
61
+ };
62
+ try {
63
+ mq = window.matchMedia(DARK_QUERY);
64
+ mq.addEventListener("change", onScheme);
65
+ }
66
+ catch {
67
+ mq = null;
68
+ }
69
+ window.addEventListener("storage", onStorage);
70
+ return () => {
71
+ mq?.removeEventListener("change", onScheme);
72
+ window.removeEventListener("storage", onStorage);
73
+ };
74
+ }, [storageKey, defaultTheme]);
75
+ const resolvedTheme = theme === "system" ? (prefersDark ? "dark" : "light") : theme;
76
+ useEffect(() => {
77
+ if (!mounted)
78
+ return;
79
+ document.documentElement.classList.toggle("dark", resolvedTheme === "dark");
80
+ }, [mounted, resolvedTheme]);
81
+ const setTheme = useCallback((next) => {
82
+ setThemeState(next);
83
+ writeStored(storageKey, next);
84
+ // Applied at once too: the effect above runs only when the resolved theme changes, and
85
+ // something outside this provider may have changed the class since.
86
+ document.documentElement.classList.toggle("dark", next === "dark" || (next === "system" && systemDark()));
87
+ }, [storageKey]);
88
+ const value = useMemo(() => ({ theme, resolvedTheme, setTheme }), [theme, resolvedTheme, setTheme]);
89
+ return _jsx(ThemeContext.Provider, { value: value, children: children });
90
+ }
91
+ /** Read and change the theme. Must be used inside `ThemeProvider`. */
92
+ export function useTheme() {
93
+ const ctx = useContext(ThemeContext);
94
+ if (!ctx)
95
+ throw new Error("useTheme must be used within a <ThemeProvider>.");
96
+ return ctx;
97
+ }
98
+ /**
99
+ * ThemeToggle — a circular secondary icon button that switches between light and dark.
100
+ * It shows the moon in light mode and the sun in dark mode; the icon is chosen by CSS, so it
101
+ * is right on the first paint even before React hydrates.
102
+ *
103
+ * The rule people break: placing two toggles on a page. One lives in the header.
104
+ */
105
+ export function ThemeToggle({ onClick, ...props }) {
106
+ const { setTheme } = useTheme();
107
+ return (_jsxs(Button, { "data-slot": "theme-toggle", type: "button", variant: "secondary", size: "icon", "aria-label": "Toggle light and dark theme", ...props, onClick: (e) => {
108
+ onClick?.(e);
109
+ // Read the applied class rather than state: it is correct even before hydration.
110
+ setTheme(document.documentElement.classList.contains("dark") ? "light" : "dark");
111
+ }, children: [_jsx(MoonIcon, { className: "dark:hidden", "aria-hidden": "true" }), _jsx(SunIcon, { className: "hidden dark:block", "aria-hidden": "true" })] }));
112
+ }
@@ -0,0 +1,51 @@
1
+ import * as React from "react";
2
+ declare const groupSizes: {
3
+ readonly sm: "min-h-(--control-h-sm) gap-2 pe-2.5 ps-2 text-[13px] [&>svg]:size-3.5";
4
+ readonly default: "min-h-(--control-h) gap-3 pe-3 ps-3 text-base sm:text-[15px] [&>svg]:size-4";
5
+ };
6
+ type SegmentType = "hour" | "minute" | "second" | "dayPeriod";
7
+ export interface TimeFieldProps extends Omit<React.ComponentProps<"div">, "defaultValue" | "onChange" | "children" | "dir"> {
8
+ /** The time as `"HH:mm"` (or `"HH:mm:ss"` with `seconds`), always 24-hour; `null` while empty or incomplete. */
9
+ value?: string | null;
10
+ defaultValue?: string | null;
11
+ /** Called with the new time once every segment is filled, and with `null` when one is cleared. */
12
+ onValueChange?: (value: string | null) => void;
13
+ /** `sm` (30px) for dense surfaces; `default` (38px) everywhere else. */
14
+ size?: keyof typeof groupSizes;
15
+ /** `12` adds an AM/PM segment, `24` leaves it out. Default: the locale's own clock. */
16
+ hourCycle?: 12 | 24;
17
+ /** A BCP 47 locale for the clock, the separator and the AM/PM labels. Default: the browser's. */
18
+ locale?: string;
19
+ /** Show a seconds segment. Default: when the initial value has seconds. */
20
+ seconds?: boolean;
21
+ /** Minutes moved by one arrow press on the minutes, e.g. `15` for quarter hours. */
22
+ step?: number;
23
+ /** The earliest and latest times, `"HH:mm"`. A finished time outside them is clamped when focus leaves the field. */
24
+ min?: string;
25
+ max?: string;
26
+ /** Submitted with a form as a hidden input holding the value (`""` while empty). */
27
+ name?: string;
28
+ /**
29
+ * A time must be entered: while the field is empty or unfinished it is `valueMissing`, which
30
+ * stops a form's submit and marks the `Field` invalid.
31
+ */
32
+ required?: boolean;
33
+ disabled?: boolean;
34
+ readOnly?: boolean;
35
+ /** The clock icon at the end of the field. */
36
+ icon?: boolean;
37
+ /** Names for each segment, read out with the field's label. */
38
+ segmentLabels?: Partial<Record<SegmentType, string>>;
39
+ }
40
+ /**
41
+ * TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
42
+ * mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
43
+ *
44
+ * Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField),
45
+ * typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
46
+ * string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
47
+ * departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
48
+ * of 96 quarter hours. Set `step={15}` instead, and let people type.
49
+ */
50
+ export declare function TimeField({ value: valueProp, defaultValue, onValueChange, size, hourCycle, locale, seconds: secondsProp, step, min, max, name, required, disabled: disabledProp, readOnly, icon, segmentLabels, id: idProp, className, onBlur, onMouseDown, onPaste, ...props }: TimeFieldProps): React.JSX.Element;
51
+ export {};
@@ -0,0 +1,437 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Field as BaseField } from "@base-ui/react/field";
4
+ import { ClockIcon } from "lucide-react";
5
+ import * as React from "react";
6
+ import { cn } from "../lib/cn.js";
7
+ import { DigitRoll, reducedMotion } from "../lib/digit-roll.js";
8
+ const groupSizes = {
9
+ sm: "min-h-(--control-h-sm) gap-2 pe-2.5 ps-2 text-[13px] [&>svg]:size-3.5",
10
+ default: "min-h-(--control-h) gap-3 pe-3 ps-3 text-base sm:text-[15px] [&>svg]:size-4",
11
+ };
12
+ const EMPTY = { hour: null, minute: null, second: null, period: null };
13
+ const pad = (n) => String(n).padStart(2, "0");
14
+ /** The zeros of the digits people type besides 0–9: Arabic-Indic, Persian, Devanagari, Bengali, Thai. */
15
+ const DIGIT_ZEROS = [0x0660, 0x06f0, 0x0966, 0x09e6, 0x0e50];
16
+ /** Text as 0–9 and ASCII punctuation: full-width digits and colons, and the digits of other scripts. */
17
+ const latin = (text) => text
18
+ .normalize("NFKC")
19
+ .replace(/[\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0e50-\u0e59]/g, (ch) => {
20
+ const code = ch.charCodeAt(0);
21
+ return String(code - DIGIT_ZEROS.find((zero) => code >= zero && code <= zero + 9));
22
+ });
23
+ const noSubscribe = () => () => { };
24
+ const defaultSegmentLabels = {
25
+ hour: "Hours",
26
+ minute: "Minutes",
27
+ second: "Seconds",
28
+ dayPeriod: "AM/PM",
29
+ };
30
+ function parse(value, h12) {
31
+ const m = value ? /^(\d{1,2}):(\d{2})(?::(\d{2}))?/.exec(value) : null;
32
+ if (!m)
33
+ return EMPTY;
34
+ const h = Math.min(23, Number(m[1]));
35
+ return {
36
+ hour: h12 ? h % 12 || 12 : h,
37
+ minute: Math.min(59, Number(m[2])),
38
+ second: m[3] ? Math.min(59, Number(m[3])) : 0,
39
+ period: h >= 12 ? "pm" : "am",
40
+ };
41
+ }
42
+ /** The same time on the other clock: a 24-hour hour as 1–12 with AM/PM, or back. */
43
+ function toClock(s, h12) {
44
+ if (s.hour == null)
45
+ return s;
46
+ if (h12)
47
+ return { ...s, hour: s.hour % 12 || 12, period: s.hour >= 12 ? "pm" : "am" };
48
+ return { ...s, hour: (s.hour % 12) + (s.period === "pm" ? 12 : 0) };
49
+ }
50
+ function format(s, h12, seconds) {
51
+ if (s.hour == null || s.minute == null || (seconds && s.second == null) || (h12 && s.period == null))
52
+ return null;
53
+ const h = h12 ? (s.hour % 12) + (s.period === "pm" ? 12 : 0) : s.hour;
54
+ return `${pad(h)}:${pad(s.minute)}${seconds ? `:${pad(s.second)}` : ""}`;
55
+ }
56
+ /** Seconds since midnight, for comparing a value with `min` / `max`. */
57
+ const toSeconds = (v) => {
58
+ const [h = 0, m = 0, s = 0] = v.split(":").map(Number);
59
+ return h * 3600 + m * 60 + s;
60
+ };
61
+ /** The locale's clock: 12 or 24 hours, the order of the segments, the separator and the AM/PM names. */
62
+ function useClock(locale, hourCycle, seconds) {
63
+ return React.useMemo(() => {
64
+ const options = { hour: "2-digit", minute: "2-digit" };
65
+ if (seconds)
66
+ options.second = "2-digit";
67
+ if (hourCycle)
68
+ options.hourCycle = hourCycle === 12 ? "h12" : "h23";
69
+ let fmt;
70
+ try {
71
+ fmt = new Intl.DateTimeFormat(locale, options);
72
+ }
73
+ catch {
74
+ fmt = new Intl.DateTimeFormat("en", options);
75
+ }
76
+ const cycle = fmt.resolvedOptions().hourCycle;
77
+ const h12 = cycle === "h11" || cycle === "h12";
78
+ // A fixed date: only the parts' order and literals are read, never the clock.
79
+ const parts = fmt.formatToParts(new Date(2026, 0, 1, 21, 5, 7));
80
+ const order = parts
81
+ .map((p) => p.type)
82
+ .filter((t) => t === "hour" || t === "minute" || t === "second" || t === "dayPeriod");
83
+ const between = parts.findIndex((p) => p.type === "hour");
84
+ const separator = parts[between + 1]?.type === "literal" ? parts[between + 1].value.trim() || ":" : ":";
85
+ const periodName = (h) => fmt.formatToParts(new Date(2026, 0, 1, h)).find((p) => p.type === "dayPeriod")?.value ??
86
+ (h < 12 ? "AM" : "PM");
87
+ return { h12, order, separator, periods: { am: periodName(9), pm: periodName(21) } };
88
+ }, [locale, hourCycle, seconds]);
89
+ }
90
+ /**
91
+ * TimeField — a time of day entered as segments, `14 : 30`, in a recessed field like `Input`:
92
+ * mono, tabular digits, an AM/PM segment where the clock has 12 hours, and an optional clock icon.
93
+ *
94
+ * Each segment is a spinbutton: ↑ ↓ step it (wrapping, and rolling its digits like a NumberField),
95
+ * typing fills it and moves on, Backspace clears it. The value is always a 24-hour `"HH:mm"`
96
+ * string, whatever the display. Use it for a time on its own — opening hours, a reminder, a
97
+ * departure — and beside a `DatePicker` for a date and time. The rule people break: a `Select`
98
+ * of 96 quarter hours. Set `step={15}` instead, and let people type.
99
+ */
100
+ export function TimeField({ value: valueProp, defaultValue, onValueChange, size = "default", hourCycle, locale, seconds: secondsProp, step = 1, min, max, name, required = false, disabled: disabledProp = false, readOnly = false, icon = true, segmentLabels, id: idProp, className, onBlur, onMouseDown, onPaste, ...props }) {
101
+ const initial = valueProp !== undefined ? valueProp : defaultValue;
102
+ // Decided by the first value: the seconds don't go when a segment is cleared and the value is null.
103
+ const [initialSeconds] = React.useState(() => /^\d{1,2}:\d{2}:\d{2}/.test(initial ?? ""));
104
+ const seconds = secondsProp ?? initialSeconds;
105
+ // Without a `locale` the clock is the browser's, which a server can't know: the server and the
106
+ // hydrating render draw the en-US clock, and the browser's takes over straight after.
107
+ const hydrated = React.useSyncExternalStore(noSubscribe, () => true, () => false);
108
+ const clock = useClock(locale ?? (hydrated ? undefined : "en-US"), hourCycle, seconds);
109
+ const { h12 } = clock;
110
+ const labels = { ...defaultSegmentLabels, ...segmentLabels };
111
+ const generatedId = React.useId();
112
+ const id = idProp ?? generatedId;
113
+ const [segs, setSegs] = React.useState(() => parse(initial, h12));
114
+ // A new clock (another `locale` or `hourCycle`) carries the hour across, so the time stays.
115
+ const [segsH12, setSegsH12] = React.useState(h12);
116
+ if (segsH12 !== h12) {
117
+ setSegsH12(h12);
118
+ setSegs(toClock(segs, h12));
119
+ }
120
+ // A controlled value that changes from outside resets the segments; one we emitted does not.
121
+ const [synced, setSynced] = React.useState(valueProp);
122
+ if (valueProp !== undefined && valueProp !== synced) {
123
+ setSynced(valueProp);
124
+ if (valueProp !== format(segs, h12, seconds))
125
+ setSegs(parse(valueProp, h12));
126
+ }
127
+ const segsRef = React.useRef(segs);
128
+ segsRef.current = segs;
129
+ const value = format(segs, h12, seconds);
130
+ const update = (next) => {
131
+ const before = format(segsRef.current, h12, seconds);
132
+ segsRef.current = next;
133
+ setSegs(next);
134
+ const after = format(next, h12, seconds);
135
+ if (after !== before)
136
+ onValueChange?.(after);
137
+ };
138
+ const order = clock.order.filter((t) => (t === "second" ? seconds : t === "dayPeriod" ? h12 : true));
139
+ const refs = React.useRef({});
140
+ const focusSegment = (type) => type && refs.current[type]?.focus();
141
+ const neighbour = (type, by) => order[order.indexOf(type) + by];
142
+ /** The digits typed into the focused segment so far ("1" while waiting to see if it is 1 or 12). */
143
+ const typed = React.useRef("");
144
+ const range = (type) => type === "hour" ? (h12 ? [1, 12] : [0, 23]) : type === "dayPeriod" ? [0, 1] : [0, 59];
145
+ const display = (type, s) => {
146
+ if (type === "dayPeriod")
147
+ return s.period ? clock.periods[s.period] : "––";
148
+ const n = s[type];
149
+ return n == null ? "––" : pad(n);
150
+ };
151
+ /* The digit roll: a step remembers the segment's text before and after, and which way it went. */
152
+ const [rolls, setRolls] = React.useState({});
153
+ const endRoll = React.useMemo(() => {
154
+ const end = (type) => () => setRolls((r) => ({ ...r, [type]: undefined }));
155
+ return { hour: end("hour"), minute: end("minute"), second: end("second"), dayPeriod: end("dayPeriod") };
156
+ }, []);
157
+ const stepSegment = (type, dir) => {
158
+ typed.current = "";
159
+ const s = segsRef.current;
160
+ let next;
161
+ if (type === "dayPeriod") {
162
+ next = { ...s, period: s.period == null ? (dir > 0 ? "am" : "pm") : s.period === "am" ? "pm" : "am" };
163
+ }
164
+ else {
165
+ const [lo, hi] = range(type);
166
+ const by = type === "minute" ? Math.max(1, Math.floor(step)) : 1;
167
+ const cur = s[type];
168
+ // The last value a step lands on: 45 for quarter hours.
169
+ const top = lo + Math.floor((hi - lo) / by) * by;
170
+ let n;
171
+ if (cur == null)
172
+ n = dir > 0 ? lo : top;
173
+ else if (dir > 0)
174
+ n = cur >= top ? lo : lo + (Math.floor((cur - lo) / by) + 1) * by;
175
+ else
176
+ n = cur <= lo ? top : lo + (Math.ceil((cur - lo) / by) - 1) * by;
177
+ next = { ...s, [type]: n };
178
+ }
179
+ const from = rolls[type]?.to ?? display(type, s);
180
+ const to = display(type, next);
181
+ if (from !== to && !from.includes("–") && !reducedMotion())
182
+ setRolls((r) => ({ ...r, [type]: { from, to, dir, key: performance.now() } }));
183
+ update(next);
184
+ };
185
+ const setSegment = (type, n) => {
186
+ if (type === "dayPeriod")
187
+ update({ ...segsRef.current, period: n == null ? null : n ? "pm" : "am" });
188
+ else
189
+ update({ ...segsRef.current, [type]: n });
190
+ };
191
+ const typeChar = (type, key) => {
192
+ // A digit typed on another script's keyboard (Arabic, Persian, full-width) is the same digit.
193
+ const ch = latin(key);
194
+ const s = segsRef.current;
195
+ if (/[\s:.,/-]/.test(ch) || ch === clock.separator) {
196
+ // A separator moves on, once there is something to move on from.
197
+ if (type === "dayPeriod" ? s.period : s[type] != null)
198
+ focusSegment(neighbour(type, 1));
199
+ return;
200
+ }
201
+ if (type === "dayPeriod") {
202
+ const c = ch.toLowerCase();
203
+ const am = clock.periods.am.toLowerCase();
204
+ const pm = clock.periods.pm.toLowerCase();
205
+ if (c === "a" || am.startsWith(c))
206
+ setSegment(type, 0);
207
+ else if (c === "p" || pm.startsWith(c))
208
+ setSegment(type, 1);
209
+ return;
210
+ }
211
+ if (!/\d/.test(ch))
212
+ return;
213
+ const [lo, hi] = range(type);
214
+ let buffer = typed.current + ch;
215
+ let n = Number(buffer);
216
+ if (typed.current === "" || n > hi) {
217
+ buffer = ch;
218
+ n = Number(ch);
219
+ }
220
+ const done = buffer.length >= 2 || n * 10 > hi;
221
+ typed.current = done ? "" : buffer;
222
+ setSegment(type, n >= lo ? n : null);
223
+ if (done)
224
+ focusSegment(neighbour(type, 1));
225
+ };
226
+ // Disabled by the prop or by a disabled Field (known once the Field's control renders).
227
+ const disabledRef = React.useRef(disabledProp);
228
+ const isEditable = () => !disabledRef.current && !readOnly;
229
+ const handleKeyDown = (type) => (event) => {
230
+ const { key } = event;
231
+ // An IME's keys are its own while it composes (229 marks them in Safari and on phones).
232
+ if (key === "Tab" ||
233
+ event.metaKey ||
234
+ event.ctrlKey ||
235
+ event.nativeEvent.isComposing ||
236
+ event.keyCode === 229)
237
+ return;
238
+ if (key === "ArrowLeft" || key === "ArrowRight") {
239
+ event.preventDefault();
240
+ focusSegment(neighbour(type, key === "ArrowLeft" ? -1 : 1));
241
+ return;
242
+ }
243
+ // Every other key is ours: the segment is contenteditable only so phones open a keyboard.
244
+ if (key.length === 1 ||
245
+ key === "Enter" ||
246
+ key.startsWith("Arrow") ||
247
+ key === "Backspace" ||
248
+ key === "Delete" ||
249
+ key === "Home" ||
250
+ key === "End")
251
+ event.preventDefault();
252
+ if (!isEditable())
253
+ return;
254
+ if (key === "ArrowUp")
255
+ stepSegment(type, 1);
256
+ else if (key === "ArrowDown")
257
+ stepSegment(type, -1);
258
+ else if (key === "Home" || key === "End") {
259
+ typed.current = "";
260
+ setSegment(type, range(type)[key === "Home" ? 0 : 1]);
261
+ }
262
+ else if (key === "Backspace" || key === "Delete") {
263
+ const s = segsRef.current;
264
+ const empty = type === "dayPeriod" ? s.period == null : s[type] == null;
265
+ typed.current = "";
266
+ if (empty && key === "Backspace")
267
+ focusSegment(neighbour(type, -1));
268
+ else
269
+ setSegment(type, null);
270
+ }
271
+ else if (key.length === 1 && !event.altKey)
272
+ typeChar(type, key);
273
+ };
274
+ /*
275
+ * Phones send their keyboard's input as beforeinput (their keydown carries no key): read it there.
276
+ * An IME (Japanese, Chinese, a phone's text keyboard) writes into the segment as it composes, which
277
+ * can't be cancelled: whatever it writes is put back to the segment's own text, and what the
278
+ * composition settles on is typed when it ends — AM or PM at once, as phones compose even a letter.
279
+ */
280
+ const handlers = React.useRef({ typeChar, setSegment, text: (type) => display(type, segs) });
281
+ handlers.current = { typeChar, setSegment, text: (type) => display(type, segsRef.current) };
282
+ const segmentRef = (type) => (el) => {
283
+ refs.current[type] = el;
284
+ if (!el)
285
+ return;
286
+ const restore = () => {
287
+ const text = handlers.current.text(type);
288
+ if (el.textContent !== text)
289
+ el.textContent = text;
290
+ };
291
+ const onBeforeInput = (e) => {
292
+ if (e.inputType === "insertCompositionText" || e.inputType === "deleteCompositionText")
293
+ return;
294
+ e.preventDefault();
295
+ if (!isEditable() || e.inputType.includes("Composition"))
296
+ return;
297
+ if (e.inputType === "insertText" && e.data)
298
+ for (const ch of e.data)
299
+ handlers.current.typeChar(type, ch);
300
+ else if (e.inputType.startsWith("delete"))
301
+ handlers.current.setSegment(type, null);
302
+ };
303
+ const onInput = (e) => {
304
+ restore();
305
+ const { inputType, data } = e;
306
+ if (type === "dayPeriod" && inputType === "insertCompositionText" && data && isEditable())
307
+ handlers.current.typeChar(type, data[0]);
308
+ };
309
+ const onCompositionEnd = (e) => {
310
+ restore();
311
+ if (isEditable())
312
+ for (const ch of e.data)
313
+ handlers.current.typeChar(type, ch);
314
+ };
315
+ el.addEventListener("beforeinput", onBeforeInput);
316
+ el.addEventListener("input", onInput);
317
+ el.addEventListener("compositionend", onCompositionEnd);
318
+ return () => {
319
+ el.removeEventListener("beforeinput", onBeforeInput);
320
+ el.removeEventListener("input", onInput);
321
+ el.removeEventListener("compositionend", onCompositionEnd);
322
+ };
323
+ };
324
+ /* A pasted time ("14:30", "2:30 pm") fills every segment at once. */
325
+ const handlePaste = (event) => {
326
+ onPaste?.(event);
327
+ event.preventDefault();
328
+ if (!isEditable())
329
+ return;
330
+ const text = latin(event.clipboardData.getData("text")).trim();
331
+ const m = /^(\d{1,2})[:.](\d{2})(?:[:.](\d{2}))?\s*([ap])?\.?m?\.?$/i.exec(text);
332
+ if (!m)
333
+ return;
334
+ let h = Number(m[1]);
335
+ if (m[4])
336
+ h = (h % 12) + (m[4].toLowerCase() === "p" ? 12 : 0);
337
+ if (h > 23 || Number(m[2]) > 59)
338
+ return;
339
+ update(parse(`${pad(h)}:${m[2]}${m[3] ? `:${m[3]}` : ""}`, h12));
340
+ };
341
+ /** The Field's input: it holds the value the Field validates. */
342
+ const fieldInput = React.useRef(null);
343
+ /*
344
+ * Leaving the field: a finished time outside min / max is brought back inside, as NumberField does.
345
+ * Then the Field hears the blur — the group's, not a segment's — with the value from its input.
346
+ */
347
+ const handleBlur = (event, fieldBlur) => {
348
+ onBlur?.(event);
349
+ if (event.currentTarget.contains(event.relatedTarget))
350
+ return;
351
+ typed.current = "";
352
+ if (value && isEditable()) {
353
+ const t = toSeconds(value);
354
+ const bound = min && t < toSeconds(min) ? min : max && t > toSeconds(max) ? max : null;
355
+ if (bound)
356
+ update(parse(bound, h12));
357
+ }
358
+ if (fieldInput.current)
359
+ fieldBlur?.({ currentTarget: fieldInput.current });
360
+ };
361
+ /** The first segment still empty, or the first one: where a click on the field puts the caret. */
362
+ const focusFirstEmpty = () => {
363
+ const s = segsRef.current;
364
+ focusSegment(order.find((t) => (t === "dayPeriod" ? s.period == null : s[t] == null)) ?? order[0]);
365
+ };
366
+ /* A press on the field's padding or icon goes to the first empty segment, as a click on a text field would. */
367
+ const handleMouseDown = (event) => {
368
+ onMouseDown?.(event);
369
+ if (event.defaultPrevented || disabledRef.current)
370
+ return;
371
+ if (event.target.closest('[data-slot="time-field-segment"]'))
372
+ return;
373
+ event.preventDefault();
374
+ focusFirstEmpty();
375
+ };
376
+ // A FieldLabel points at the group, which a label cannot focus: send its clicks to the first segment.
377
+ // (Listened for on the document: the Field links its label to the group only after this mounts.)
378
+ const firstSegment = React.useRef(order[0]);
379
+ firstSegment.current = order[0];
380
+ React.useEffect(() => {
381
+ const onClick = (event) => {
382
+ const label = event.target?.closest?.("label");
383
+ if (label?.htmlFor === id && !disabledRef.current)
384
+ refs.current[firstSegment.current]?.focus();
385
+ };
386
+ document.addEventListener("click", onClick);
387
+ return () => document.removeEventListener("click", onClick);
388
+ }, [id]);
389
+ /* A form's reset puts back the time it started with, as it does a native input's (uncontrolled). */
390
+ const reset = React.useRef(() => { });
391
+ reset.current = () => {
392
+ if (valueProp !== undefined)
393
+ return;
394
+ typed.current = "";
395
+ segsRef.current = parse(defaultValue, h12);
396
+ setSegs(segsRef.current);
397
+ };
398
+ React.useEffect(() => {
399
+ const form = refs.current[firstSegment.current]?.closest("form");
400
+ if (!form)
401
+ return;
402
+ const onReset = () => reset.current();
403
+ form.addEventListener("reset", onReset);
404
+ return () => form.removeEventListener("reset", onReset);
405
+ }, []);
406
+ return (_jsx(BaseField.Control, { ref: fieldInput, id: id, name: name, value: value ?? "", disabled: disabledProp,
407
+ // The group is what the label names and the descriptions and validity mark. The Field's own
408
+ // input, out of sight, keeps the value for forms and carries `required`, as Base UI's Select
409
+ // does: a submit that finds it empty focuses it, and it hands focus on to a segment.
410
+ render: (control) => {
411
+ const { ref, id: controlId, name: controlName, value: controlValue, disabled, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, onChange: fieldChange, onFocus: fieldFocus, onBlur: fieldBlur, onKeyDown: _onKeyDown, className: _className, defaultValue: _defaultValue, autoFocus: _autoFocus, ...state } = control;
412
+ const off = Boolean(disabled);
413
+ disabledRef.current = off;
414
+ const editable = !off && !readOnly;
415
+ const groupLabel = labelledBy ?? (props["aria-label"] || props["aria-labelledby"] ? controlId : undefined);
416
+ return (_jsxs("div", { role: "group", "data-slot": "time-field", "data-size": size, "data-readonly": readOnly ? "" : undefined, "data-disabled": off ? "" : undefined, "aria-disabled": off || undefined, ...state, ...props, id: controlId, "aria-labelledby": labelledBy ?? props["aria-labelledby"], "aria-describedby": describedBy, className: cn("group/time-field flex w-full min-w-0 material-field cursor-text items-center rounded-control font-mono text-foreground tabular-nums",
417
+ // A focused segment gives the field the softer edge of a focused text field.
418
+ "not-data-invalid:has-[[data-slot=time-field-segment]:focus]:border-[color-mix(in_oklab,var(--field-edge),var(--control-focus))]", "[&>svg]:shrink-0 [&>svg]:text-muted-foreground", groupSizes[size], className), onMouseDown: handleMouseDown, onPaste: handlePaste, onFocus: (event) => {
419
+ props.onFocus?.(event);
420
+ fieldFocus?.(event);
421
+ }, onBlur: (event) => handleBlur(event, fieldBlur), children: [_jsx("span", { dir: "ltr", className: "flex min-w-0 flex-1 items-center", children: order.map((type, i) => {
422
+ const prev = order[i - 1];
423
+ const gap = prev && (type === "dayPeriod" || prev === "dayPeriod");
424
+ const s = segs;
425
+ const n = type === "dayPeriod" ? (s.period == null ? null : s.period === "pm" ? 1 : 0) : s[type];
426
+ const text = display(type, s);
427
+ const roll = rolls[type];
428
+ const [lo, hi] = range(type);
429
+ return (_jsxs(React.Fragment, { children: [prev && !gap && (_jsx("span", { "aria-hidden": true, "data-slot": "time-field-separator", className: "px-px text-muted-foreground", children: clock.separator })), _jsxs("span", { className: cn("relative flex", gap && "ml-1.5"), children: [_jsx("span", { ref: segmentRef(type), id: `${controlId}-${type}`, role: "spinbutton", "data-slot": "time-field-segment", "data-type": type, "data-placeholder": n == null ? "" : undefined, tabIndex: off ? undefined : 0, contentEditable: editable ? "true" : undefined, suppressContentEditableWarning: true, inputMode: type === "dayPeriod" ? "text" : "numeric", enterKeyHint: "next", spellCheck: false, autoCorrect: "off", autoCapitalize: "off", "aria-label": labels[type], "aria-labelledby": groupLabel ? `${groupLabel} ${controlId}-${type}` : undefined, "aria-describedby": describedBy, "aria-invalid": invalid, "aria-readonly": readOnly || undefined, "aria-required": required || undefined, "aria-disabled": off || undefined, "aria-valuemin": lo, "aria-valuemax": hi, "aria-valuenow": n ?? undefined, "aria-valuetext": n == null ? "Empty" : type === "dayPeriod" ? text : String(n), onKeyDown: handleKeyDown(type), onFocus: () => (typed.current = ""), className: cn(
430
+ // Focused, outline-hidden rather than none: a contrast theme drops the fill
431
+ // that marks the focused segment, and shows this outline instead.
432
+ "rounded-checkbox px-0.5 whitespace-nowrap caret-transparent outline-none focus:outline-hidden", "transition-[background-color,color] duration-(--duration) ease-(--ease) selection:bg-transparent", "focus:bg-control-hover focus:text-foreground", "data-placeholder:text-control-muted focus:data-placeholder:text-muted-foreground",
433
+ // While the digits roll, the overlay draws them.
434
+ roll && "text-transparent focus:text-transparent"), children: text }), roll && (_jsx(DigitRoll, { roll: roll, slot: "time-field-roll", onDone: endRoll[type] }, roll.key))] })] }, type));
435
+ }) }), icon && _jsx(ClockIcon, { "aria-hidden": true }), _jsx("input", { ref: ref, name: controlName, value: controlValue ?? "", onChange: fieldChange, required: required, disabled: off, readOnly: readOnly, "aria-hidden": true, tabIndex: -1, autoComplete: "off", onFocus: focusFirstEmpty, className: "sr-only" })] }));
436
+ } }));
437
+ }