@zonsh/ui 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -2
  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 +189 -3
@@ -0,0 +1,577 @@
1
+ /*
2
+ * The engine behind `<Table fit>`: which columns keep their own column at the container's width
3
+ * (the fit), and how cells glide to their new places when that changes (FLIP).
4
+ *
5
+ * Columns step out one at a time, lowest `priority` first, the moment the widest title no longer
6
+ * fits on one line beside them; an `inline` column moves into the title cell instead. Only once
7
+ * every column that can step out has done so may titles wrap.
8
+ */
9
+ /* ── Fit ───────────────────────────────────────────────────────────────────── */
10
+ /** The columns that can step out, in the order they do. The title never does. */
11
+ export function removalOrder(columns, title) {
12
+ return columns
13
+ .map((c, i) => ({ c, i }))
14
+ .filter(({ c }) => c.id !== title && (c.priority != null || c.inline || (c.minWidth ?? 0) > 0))
15
+ .sort((a, b) => (a.c.priority ?? 0) - (b.c.priority ?? 0) || b.i - a.i)
16
+ .map(({ c }) => c);
17
+ }
18
+ /**
19
+ * The order columns are drawn in: those before the title as given, the title, then its inline
20
+ * columns in the order they step out, then the others as given. Rows keep this DOM order at
21
+ * every width, so what is read matches what is seen.
22
+ */
23
+ export function drawOrder(columns, title) {
24
+ const at = columns.findIndex((c) => c.id === title);
25
+ const before = columns.slice(0, Math.max(at, 0));
26
+ const after = columns.slice(at + 1);
27
+ const inline = removalOrder(after, title).filter((c) => c.inline);
28
+ return [...before, ...columns.slice(at, at + 1), ...inline, ...after.filter((c) => !c.inline)];
29
+ }
30
+ export function layoutFor(step, order, columns) {
31
+ const out = new Set(order.slice(0, step).map((c) => c.id));
32
+ const modes = {};
33
+ for (const c of columns)
34
+ modes[c.id] = !out.has(c.id) ? "column" : c.inline ? "inline" : "hidden";
35
+ return {
36
+ step,
37
+ final: step >= order.length,
38
+ modes,
39
+ inlined: Object.values(modes).includes("inline"),
40
+ };
41
+ }
42
+ /** Restoring a column needs this much more room than keeping it: no flicker at the boundary. */
43
+ const HYSTERESIS_PX = 8;
44
+ const UNCLIP = "position:static;display:inline-flex;width:max-content;min-width:0;height:auto;overflow:visible;" +
45
+ "clip:auto;clip-path:none;margin:0;padding:0;white-space:nowrap;";
46
+ /**
47
+ * The rows a fitting table measures: every row — rows of closed groups too, so opening a group
48
+ * never changes the layout. A virtual body (`TableVirtualBody`) holds only the rows in view, and
49
+ * its sizer rows stand in for all the others: there the header and the sizer rows are measured.
50
+ */
51
+ export function measuredRows(body) {
52
+ const virtual = !!body.querySelector("[data-slot=table-sizer]");
53
+ return [
54
+ ...body.querySelectorAll(virtual
55
+ ? "[data-slot=table-header] [data-slot=table-row], [data-slot=table-sizer] [data-slot=table-row]"
56
+ : "[data-slot=table-row]"),
57
+ ];
58
+ }
59
+ /**
60
+ * Clones every measured title and cell (`measuredRows`) into a hidden probe with
61
+ * `white-space: nowrap`, reads all widths in one pass and removes the probe — before anything
62
+ * paints.
63
+ */
64
+ export function measureMetrics(root, body, columns) {
65
+ const probe = document.createElement("div");
66
+ probe.setAttribute("aria-hidden", "true");
67
+ probe.className = "font-body text-sm";
68
+ probe.style.cssText =
69
+ "position:absolute;top:0;left:0;visibility:hidden;pointer-events:none;white-space:nowrap;width:max-content;contain:layout style;";
70
+ // The space a row puts between its title and an inline cell (INLINE_SPACE in table.tsx).
71
+ const space = probe.appendChild(document.createElement("span"));
72
+ space.style.cssText = "white-space:pre;word-spacing:0.215em;";
73
+ space.textContent = " ";
74
+ const grids = new Map();
75
+ for (const c of columns) {
76
+ const grid = probe.appendChild(document.createElement("div"));
77
+ grid.style.cssText = `display:grid;width:max-content;grid-template-columns:${c.width ?? "auto"};`;
78
+ grids.set(c.id, grid);
79
+ }
80
+ // A title takes its type from its cell (an eyebrow in the header, 13px in a dense row).
81
+ const fonts = new Map();
82
+ const fontOf = (cell) => {
83
+ let font = fonts.get(cell.className);
84
+ if (font == null) {
85
+ const cs = getComputedStyle(cell);
86
+ font = `font:${cs.font};letter-spacing:${cs.letterSpacing};text-transform:${cs.textTransform};`;
87
+ fonts.set(cell.className, font);
88
+ }
89
+ return font;
90
+ };
91
+ const rows = measuredRows(body);
92
+ const probes = rows.map((row) => {
93
+ const text = row.querySelector("[data-slot=table-title-text]");
94
+ const cell = text?.closest("[data-title]");
95
+ const title = text ? text.cloneNode(true) : null;
96
+ if (title) {
97
+ title.style.cssText = UNCLIP + (cell ? fontOf(cell) : "");
98
+ probe.append(title);
99
+ }
100
+ const cells = [];
101
+ for (const el of row.querySelectorAll("[data-column]")) {
102
+ const id = el.getAttribute("data-column");
103
+ const clone = el.cloneNode(true);
104
+ clone.style.cssText = UNCLIP;
105
+ grids.get(id)?.append(clone);
106
+ cells.push([id, clone]);
107
+ }
108
+ return { title, cells, head: !!row.closest("[data-slot=table-header]") };
109
+ });
110
+ root.append(probe);
111
+ const metrics = {
112
+ space: space.getBoundingClientRect().width,
113
+ tracks: Object.fromEntries([...grids].map(([id, g]) => [id, g.getBoundingClientRect().width])),
114
+ rows: probes.map((p) => ({
115
+ title: p.title?.getBoundingClientRect().width ?? 0,
116
+ cells: Object.fromEntries(p.cells.map(([id, el]) => [id, el.getBoundingClientRect().width])),
117
+ head: p.head,
118
+ })),
119
+ };
120
+ probe.remove();
121
+ return metrics;
122
+ }
123
+ /** The width a layout needs with every title on one line. */
124
+ function widthNeeded(layout, drawn, title, m, edge, gap) {
125
+ const inline = drawn.filter((c) => layout.modes[c.id] === "inline");
126
+ const own = drawn.filter((c) => layout.modes[c.id] === "column");
127
+ let widest = 0;
128
+ for (const row of m.rows) {
129
+ let w = row.title;
130
+ if (!row.head)
131
+ for (const c of inline)
132
+ w += m.space + (row.cells[c.id] ?? 0);
133
+ widest = Math.max(widest, w);
134
+ }
135
+ // The rows' padding sits inside the edge tracks, which it grows when they size to their
136
+ // content (the title's, an `auto` one) and squeezes into when they are fixed.
137
+ const grows = (c) => !c || c.id === title || (c.width ?? "auto") === "auto";
138
+ const tracks = own.reduce((sum, c) => sum + (c.id === title ? Math.ceil(widest) : (m.tracks[c.id] ?? 0)), 0);
139
+ return (tracks + gap * Math.max(own.length - 1, 0) + (grows(own[0]) ? edge : 0) + (grows(own.at(-1)) ? edge : 0));
140
+ }
141
+ /**
142
+ * The final layout's room for the title's track: the width less the columns that keep their own,
143
+ * the gaps, and the padding of a last track that sizes to its content. Null before the final
144
+ * layout, or when the title is the only column left.
145
+ */
146
+ export function titleRoom(layout, drawn, title, m, available, edge, gap) {
147
+ if (!layout.final)
148
+ return null;
149
+ const own = drawn.filter((c) => layout.modes[c.id] === "column");
150
+ const others = own.filter((c) => c.id !== title);
151
+ if (!others.length)
152
+ return null;
153
+ const last = own.at(-1);
154
+ const tail = last.id !== title && (last.width ?? "auto") === "auto" ? edge : 0;
155
+ const taken = others.reduce((sum, c) => sum + (m.tracks[c.id] ?? 0), 0) + gap * others.length + tail;
156
+ return Math.max(0, Math.floor(available - taken));
157
+ }
158
+ /**
159
+ * The fewest columns to step out so the widest title stays on one line. Stepping out happens
160
+ * the moment it no longer fits; stepping back needs `HYSTERESIS_PX` to spare.
161
+ */
162
+ export function fitStep(options) {
163
+ const { available, current, order, columns, drawn, title, metrics, edge, gap, widthRem } = options;
164
+ let floor = 0;
165
+ order.forEach((c, i) => {
166
+ if ((c.minWidth ?? 0) > widthRem)
167
+ floor = i + 1;
168
+ });
169
+ for (let step = floor; step < order.length; step++) {
170
+ const need = widthNeeded(layoutFor(step, order, columns), drawn, title, metrics, edge, gap);
171
+ if (need + (step < current ? HYSTERESIS_PX : 0) <= available)
172
+ return step;
173
+ }
174
+ return order.length;
175
+ }
176
+ /* ── FLIP ──────────────────────────────────────────────────────────────────── */
177
+ /**
178
+ * One beat for the whole row: a leaving cell fades over exactly the time its neighbours take to
179
+ * glide into the space it frees, on the same curve and from the same start, so the gap closes as
180
+ * the cell goes. Entering cells start a moment later and land with them.
181
+ */
182
+ const MOVE_MS = 280;
183
+ const ENTER_DELAY_MS = 40;
184
+ const ENTER_MS = MOVE_MS - ENTER_DELAY_MS;
185
+ /**
186
+ * Fades run on a gentle standard curve, not the brand's front-loaded ease-out: on that curve a
187
+ * fade is ~85% done in the first frames, so a returning column seemed to pop straight in.
188
+ */
189
+ const FADE_EASING = "cubic-bezier(0.4, 0, 0.2, 1)";
190
+ const EXIT_MS = MOVE_MS;
191
+ /** How far a leaving cell drifts towards its own side as it fades. */
192
+ const EXIT_DRIFT_PX = 8;
193
+ /** Delay between one row (or band) and the next, top to bottom — exits and glides alike. */
194
+ const STAGGER_MS = 30;
195
+ /** The last row in view starts by then, so a long table still settles within ~520ms. */
196
+ const SPREAD_MS = 240;
197
+ const ZERO = { x: 0, y: 0 };
198
+ const keyOf = (el) => el.getAttribute("data-flip-key") ?? el;
199
+ /** Rows of a closed group are not drawn, nor a virtual body's sizer rows. */
200
+ const CLOSED = "[data-slot=table-group][data-closed] > [data-slot=table-row]";
201
+ const isDrawn = (el) => !el.closest("[data-mode=hidden]") && !el.closest(CLOSED) && !el.closest("[data-slot=table-sizer]");
202
+ /** The band or row a piece belongs to: its place in the top-to-bottom cascade. */
203
+ const seqOf = (el) => el.closest("[data-flip=row],[data-flip=band]");
204
+ /** Where a piece is anchored: the side it scales from, and its vertical middle. */
205
+ const anchorOf = (rect, side) => ({
206
+ x: side === "right center" ? rect.right : rect.left,
207
+ y: rect.top + rect.height / 2,
208
+ });
209
+ /**
210
+ * The glide. Tracked pieces carry `data-flip`. Each is measured relative to its nearest tracked
211
+ * parent (bands and rows relative to the scroll content), so a cell glides inside its row while
212
+ * the row glides inside the table, and a stuck band stays stuck.
213
+ *
214
+ * - `tier()` wraps a layout change: measure where everything is drawn, commit the new layout,
215
+ * measure again, animate the difference. The bands and rows in view go top to bottom, up to
216
+ * 30ms apart; every piece of a row starts with its row, its leaving cells included. Entering
217
+ * cells fade and grow in; leaving cells are cloned where they stood and fade out as their
218
+ * neighbours glide over. Interrupted, it starts again from what is drawn: positions
219
+ * mid-glide, cells mid-fade, ghosts still fading out.
220
+ * - `reflow()` runs on every other resize. In the final layout, where titles wrap, a piece that
221
+ * changed line glides there instead of jumping; pieces that only follow the width keep
222
+ * following the pointer.
223
+ *
224
+ * Each pass reads every rect first and writes after, so there is one forced layout per change.
225
+ */
226
+ export class Flip {
227
+ root;
228
+ body;
229
+ layer;
230
+ anims = new Map();
231
+ ghosts = new Map();
232
+ cache = new Map();
233
+ active = 0;
234
+ /** Right to left: a column's end is on the left. Read at the start of every glide. */
235
+ rtl = false;
236
+ constructor(root, body, layer) {
237
+ this.root = root;
238
+ this.body = body;
239
+ this.layer = layer;
240
+ }
241
+ /** The side a piece is anchored to: its column's end (the right, or the left right to left) or start. */
242
+ sideOf(el) {
243
+ return (el.getAttribute("data-align") === "end") !== this.rtl ? "right center" : "left center";
244
+ }
245
+ direction() {
246
+ this.rtl = getComputedStyle(this.root).direction === "rtl";
247
+ }
248
+ easing() {
249
+ return getComputedStyle(this.root).getPropertyValue("--ease").trim() || "cubic-bezier(0.16, 1, 0.3, 1)";
250
+ }
251
+ track(a) {
252
+ if (this.active++ === 0)
253
+ this.root.setAttribute("data-gliding", "");
254
+ const done = () => {
255
+ if (--this.active === 0)
256
+ this.root.removeAttribute("data-gliding");
257
+ };
258
+ a.finished.then(done, done);
259
+ return a;
260
+ }
261
+ run(el, keyframes, options) {
262
+ this.anims.get(el)?.cancel();
263
+ const a = this.track(el.animate(keyframes, { fill: "backwards", ...options }));
264
+ this.anims.set(el, a);
265
+ a.finished.then(() => this.anims.get(el) === a && this.anims.delete(el), () => undefined);
266
+ }
267
+ dropGhost(key) {
268
+ const ghost = this.ghosts.get(key);
269
+ if (!ghost)
270
+ return;
271
+ this.ghosts.delete(key);
272
+ ghost.anim.cancel();
273
+ ghost.clone.remove();
274
+ }
275
+ /**
276
+ * Where a piece's box starts without the scale it is drawn at. A piece fading in is scaled from
277
+ * its side's vertical middle, which moves its drawn top; read as is, that looked like a change
278
+ * of line, and the next resize replaced the fade-in with a glide, so the cell popped in.
279
+ */
280
+ unscaled(el, r) {
281
+ const a = this.anims.get(el);
282
+ const s = a?.playState === "running" ? parseFloat(getComputedStyle(el).scale) : NaN;
283
+ if (!s || s === 1)
284
+ return { x: r.left, y: r.top };
285
+ const { offsetWidth: w, offsetHeight: h } = el;
286
+ return {
287
+ x: this.sideOf(el) === "right center" ? r.right - w : r.left,
288
+ y: r.top + r.height / 2 - h / 2,
289
+ };
290
+ }
291
+ /** Every drawn piece, its rect, and its position in its parent — less `offsets`, a glide in progress. */
292
+ measure(offsets) {
293
+ const box = this.body.getBoundingClientRect();
294
+ const content = { x: box.left - this.body.scrollLeft, y: box.top - this.body.scrollTop };
295
+ const els = [...this.root.querySelectorAll("[data-flip]")].filter(isDrawn);
296
+ const rects = new Map(els.map((el) => [el, el.getBoundingClientRect()]));
297
+ const rel = new Map();
298
+ for (const el of els) {
299
+ const r = this.unscaled(el, rects.get(el));
300
+ const own = offsets?.get(el) ?? ZERO;
301
+ const parent = el.parentElement?.closest("[data-flip]");
302
+ const p = parent ? rects.get(parent) : undefined;
303
+ const base = p ? { x: p.left, y: p.top } : content;
304
+ rel.set(keyOf(el), { x: r.x - own.x - base.x, y: r.y - own.y - base.y });
305
+ }
306
+ return { els, rects, rel, view: box };
307
+ }
308
+ /**
309
+ * The cascade: bands and rows in view count 0, 1, 2… from the top; those above the view start
310
+ * at once, those below with the last one in view.
311
+ */
312
+ cascade(rects, view) {
313
+ const index = new Map();
314
+ const below = [];
315
+ let count = 0;
316
+ for (const el of this.root.querySelectorAll("[data-flip=band],[data-flip=row]")) {
317
+ const r = rects.get(el);
318
+ if (!r)
319
+ continue;
320
+ if (r.bottom <= view.top)
321
+ index.set(el, 0);
322
+ else if (r.top >= view.bottom)
323
+ below.push(el);
324
+ else
325
+ index.set(el, count++);
326
+ }
327
+ for (const el of below)
328
+ index.set(el, Math.max(0, count - 1));
329
+ const gap = count > 1 ? Math.min(STAGGER_MS, SPREAD_MS / (count - 1)) : 0;
330
+ return (seq) => (seq ? (index.get(seq) ?? 0) * gap : 0);
331
+ }
332
+ /** Forget the last positions: something other than the width moved things (scroll, data, a group). */
333
+ invalidate() {
334
+ this.cache.clear();
335
+ }
336
+ cancel() {
337
+ for (const a of this.anims.values())
338
+ a.cancel();
339
+ this.anims.clear();
340
+ for (const key of [...this.ghosts.keys()])
341
+ this.dropGhost(key);
342
+ }
343
+ /** Glides from what is drawn now to the layout that `commit` applies (synchronously) for `next`. */
344
+ tier(next, commit) {
345
+ const easing = this.easing();
346
+ this.direction();
347
+ // Read: positions (mid-glide included), the fade of anything mid-entrance, the ghosts still
348
+ // fading out, and clones of the pieces about to step out.
349
+ const first = this.measure();
350
+ const faded = new Map();
351
+ for (const [el, a] of this.anims) {
352
+ if (a.playState !== "running" || !first.rects.has(el))
353
+ continue;
354
+ const cs = getComputedStyle(el);
355
+ faded.set(keyOf(el), { opacity: parseFloat(cs.opacity), scale: parseFloat(cs.scale) || 1 });
356
+ }
357
+ const fading = new Map();
358
+ for (const [key, { clone }] of this.ghosts) {
359
+ const cs = getComputedStyle(clone);
360
+ fading.set(key, {
361
+ rect: clone.getBoundingClientRect(),
362
+ opacity: parseFloat(cs.opacity),
363
+ scale: parseFloat(cs.scale) || 1,
364
+ });
365
+ }
366
+ const leaving = first.els
367
+ .filter((el) => {
368
+ const column = el.getAttribute("data-column");
369
+ if (!column)
370
+ return false;
371
+ // A header leaves with its column, and when the column moves into the titles.
372
+ const mode = next.modes[column];
373
+ return el.hasAttribute("data-head") ? mode !== "column" : mode === "hidden";
374
+ })
375
+ .map((el) => ({
376
+ el,
377
+ key: el.getAttribute("data-flip-key"),
378
+ seq: seqOf(el),
379
+ side: this.sideOf(el),
380
+ rect: first.rects.get(el),
381
+ size: { w: el.offsetWidth, h: el.offsetHeight },
382
+ from: faded.get(keyOf(el)) ?? { opacity: 1, scale: 1 },
383
+ clone: el.cloneNode(true),
384
+ }));
385
+ for (const a of this.anims.values())
386
+ a.cancel();
387
+ this.anims.clear();
388
+ commit();
389
+ // Read the new layout once, then write every animation.
390
+ const last = this.measure();
391
+ const delay = this.cascade(last.rects, last.view);
392
+ const origin = this.layer.getBoundingClientRect();
393
+ for (const el of last.els) {
394
+ const wait = delay(seqOf(el));
395
+ const side = this.sideOf(el);
396
+ const key = el.getAttribute("data-flip-key");
397
+ let from = first.rel.get(keyOf(el));
398
+ let start = faded.get(keyOf(el));
399
+ const ghost = !from && key ? fading.get(key) : undefined;
400
+ if (!from && ghost) {
401
+ // Back before its ghost faded out: carry on from the ghost, where and as it is drawn.
402
+ const parent = el.parentElement?.closest("[data-flip]");
403
+ const pFirst = parent && first.rects.get(parent);
404
+ const pLast = parent && last.rects.get(parent);
405
+ const g = anchorOf(ghost.rect, side);
406
+ const now = anchorOf(last.rects.get(el), side);
407
+ const shift = pFirst && pLast ? { x: pFirst.left - pLast.left, y: pFirst.top - pLast.top } : ZERO;
408
+ const to = last.rel.get(keyOf(el));
409
+ from = { x: to.x + g.x - now.x - shift.x, y: to.y + g.y - now.y - shift.y };
410
+ start = { opacity: ghost.opacity, scale: ghost.scale };
411
+ this.dropGhost(key);
412
+ }
413
+ if (!from) {
414
+ this.run(el, [
415
+ { opacity: 0, scale: "0.6", transformOrigin: side },
416
+ { opacity: 1, scale: "1", transformOrigin: side },
417
+ ], { duration: ENTER_MS, delay: wait + ENTER_DELAY_MS, easing: FADE_EASING });
418
+ continue;
419
+ }
420
+ const to = last.rel.get(keyOf(el));
421
+ const dx = from.x - to.x;
422
+ const dy = from.y - to.y;
423
+ if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5 && !start)
424
+ continue;
425
+ const fade = start
426
+ ? [
427
+ { opacity: start.opacity, scale: String(start.scale), transformOrigin: side },
428
+ { opacity: 1, scale: "1", transformOrigin: side },
429
+ ]
430
+ : [{}, {}];
431
+ this.run(el, [
432
+ { translate: `${dx}px ${dy}px`, ...fade[0] },
433
+ { translate: "0px 0px", ...fade[1] },
434
+ ], { duration: MOVE_MS, delay: wait, easing });
435
+ }
436
+ for (const l of leaving) {
437
+ if (l.key)
438
+ this.dropGhost(l.key);
439
+ const { clone, rect, size, side } = l;
440
+ clone.removeAttribute("data-flip");
441
+ clone.removeAttribute("id");
442
+ clone.removeAttribute("role");
443
+ Object.assign(clone.style, {
444
+ position: "absolute",
445
+ margin: "0",
446
+ left: `${(side === "right center" ? rect.right - size.w : rect.left) - origin.left}px`,
447
+ top: `${rect.top + rect.height / 2 - size.h / 2 - origin.top}px`,
448
+ width: `${size.w}px`,
449
+ height: `${size.h}px`,
450
+ });
451
+ this.layer.append(clone);
452
+ const anim = this.track(clone.animate([
453
+ {
454
+ opacity: l.from.opacity,
455
+ scale: String(l.from.scale),
456
+ translate: "0px 0px",
457
+ transformOrigin: side,
458
+ offset: 0,
459
+ },
460
+ // Shrink a little and drift towards its own side as it fades, in step with the glide.
461
+ {
462
+ opacity: 0,
463
+ scale: "0.9",
464
+ translate: `${side === "right center" ? EXIT_DRIFT_PX : -EXIT_DRIFT_PX}px 0px`,
465
+ transformOrigin: side,
466
+ offset: 1,
467
+ },
468
+ ], { duration: EXIT_MS, delay: delay(l.seq), easing, fill: "both" }));
469
+ const ghost = { clone, anim };
470
+ if (l.key)
471
+ this.ghosts.set(l.key, ghost);
472
+ anim.finished.then(() => {
473
+ clone.remove();
474
+ if (l.key && this.ghosts.get(l.key) === ghost)
475
+ this.ghosts.delete(l.key);
476
+ }, () => undefined);
477
+ }
478
+ this.cache = last.rel;
479
+ }
480
+ /** A resize within a layout: glide what changed line, from where it is drawn now. */
481
+ reflow() {
482
+ this.direction();
483
+ const offsets = new Map();
484
+ const faded = new Map();
485
+ for (const [el, a] of this.anims) {
486
+ if (a.playState !== "running")
487
+ continue;
488
+ const cs = getComputedStyle(el);
489
+ const [x = "0", y = "0"] = cs.translate.split(" ");
490
+ offsets.set(el, { x: parseFloat(x) || 0, y: parseFloat(y) || 0 });
491
+ const opacity = parseFloat(cs.opacity);
492
+ const scale = parseFloat(cs.scale) || 1;
493
+ if (opacity < 1 || scale !== 1)
494
+ faded.set(el, { opacity, scale });
495
+ }
496
+ const now = this.measure(offsets);
497
+ if (this.cache.size) {
498
+ const easing = this.easing();
499
+ for (const el of now.els) {
500
+ const prev = this.cache.get(keyOf(el));
501
+ if (!prev)
502
+ continue;
503
+ const to = now.rel.get(keyOf(el));
504
+ // A changed line moves a piece; so does any shift of an inline cell, which only moves when
505
+ // a word wraps. Columns shift smoothly with the width and keep following it.
506
+ const inline = el.getAttribute("data-mode") === "inline";
507
+ if (Math.abs(prev.y - to.y) < 1 && !(inline && Math.abs(prev.x - to.x) >= 1))
508
+ continue;
509
+ const own = offsets.get(el) ?? ZERO;
510
+ const dx = prev.x - to.x + own.x;
511
+ const dy = prev.y - to.y + own.y;
512
+ // A piece still fading in carries on fading as it glides.
513
+ const start = faded.get(el);
514
+ const side = this.sideOf(el);
515
+ const fade = start
516
+ ? [
517
+ { opacity: start.opacity, scale: String(start.scale), transformOrigin: side },
518
+ { opacity: 1, scale: "1", transformOrigin: side },
519
+ ]
520
+ : [{}, {}];
521
+ this.run(el, [
522
+ { translate: `${dx}px ${dy}px`, ...fade[0] },
523
+ { translate: "0px 0px", ...fade[1] },
524
+ ], { duration: MOVE_MS, easing });
525
+ }
526
+ }
527
+ this.cache = now.rel;
528
+ }
529
+ }
530
+ export const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
531
+ /* ── Virtual rows ──────────────────────────────────────────────────────────── */
532
+ /** East Asian wide characters (CJK, Hangul, full-width forms): drawn about twice as wide. */
533
+ const WIDE = /[ᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹏＀-⦆¢-₩]/g;
534
+ /** How long a value reads, in characters (wide ones twice): a stand-in for how wide its cell is drawn. */
535
+ function textLength(value) {
536
+ if (value == null)
537
+ return 0;
538
+ if (typeof value === "string")
539
+ return value.length + (value.match(WIDE)?.length ?? 0);
540
+ if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean")
541
+ return String(value).length;
542
+ if (value instanceof Date)
543
+ return 16;
544
+ if (Array.isArray(value))
545
+ return value.reduce((sum, v) => sum + textLength(v) + 2, 0);
546
+ return 0;
547
+ }
548
+ /**
549
+ * The rows that size a virtual table's columns: for each value of a row (`valuesOf`, one per
550
+ * column), the `per` rows where it is longest, and the `per` rows longest in all (a title with
551
+ * its inline cells). Rendered out of view, they stand in for every row, so a column keeps its
552
+ * width while rows scroll in and out. Returns indices into `rows`, in order.
553
+ */
554
+ export function widestRows(rows, valuesOf, per = 2) {
555
+ // Slot 0 is the whole row; slot j + 1 its j-th value. Each keeps its `per` longest, longest first.
556
+ const best = [];
557
+ const keep = (slot, len, at) => {
558
+ const list = (best[slot] ??= []);
559
+ if (list.length === per && len <= list[per - 1].len)
560
+ return;
561
+ const i = list.findIndex((entry) => len > entry.len);
562
+ list.splice(i < 0 ? list.length : i, 0, { len, at });
563
+ if (list.length > per)
564
+ list.pop();
565
+ };
566
+ rows.forEach((row, at) => {
567
+ let total = 0;
568
+ valuesOf(row).forEach((value, j) => {
569
+ const len = textLength(value);
570
+ total += len;
571
+ if (len > 0)
572
+ keep(j + 1, len, at);
573
+ });
574
+ keep(0, total, at);
575
+ });
576
+ return [...new Set(best.flat().map((entry) => entry.at))].sort((a, b) => a - b);
577
+ }
@@ -0,0 +1,18 @@
1
+ export type ThemeMode = "light" | "dark" | "system";
2
+ /** localStorage key the provider and `themeScript` share. */
3
+ export declare const THEME_STORAGE_KEY = "zon-theme";
4
+ /** The media query `system` follows. Not part of the public API. */
5
+ export declare const DARK_QUERY = "(prefers-color-scheme: dark)";
6
+ /**
7
+ * Build the no-flash script for `<head>`. It applies `.dark` before first paint, using the
8
+ * same storage key and default as `ThemeProvider`. Pass the same options to both.
9
+ */
10
+ export declare function createThemeScript({ storageKey, defaultTheme, }?: {
11
+ storageKey?: string;
12
+ defaultTheme?: ThemeMode;
13
+ }): string;
14
+ /**
15
+ * Inline this in `<head>`, before any stylesheet paints, to avoid a flash of the wrong theme:
16
+ * `<script dangerouslySetInnerHTML={{ __html: themeScript }} />`.
17
+ */
18
+ export declare const themeScript: string;
@@ -0,0 +1,29 @@
1
+ /*
2
+ * The theme's no-flash script, kept apart from ThemeProvider so it stays plain code: a server
3
+ * component (a Next.js root layout) can inline it, while the provider is a client component.
4
+ */
5
+ /** localStorage key the provider and `themeScript` share. */
6
+ export const THEME_STORAGE_KEY = "zon-theme";
7
+ /** The media query `system` follows. Not part of the public API. */
8
+ export const DARK_QUERY = "(prefers-color-scheme: dark)";
9
+ /**
10
+ * A value as a JavaScript literal that is safe inside an HTML `<script>`: its JSON, with `<`
11
+ * written as `\u003c`, so a `</script>` or `<!--` in it cannot end the element or change how
12
+ * the browser reads it. `>`, `&` and the two line separators old engines reject in a string
13
+ * are escaped too, as frameworks do when they inline JSON.
14
+ */
15
+ const literal = (value) => JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
16
+ /**
17
+ * Build the no-flash script for `<head>`. It applies `.dark` before first paint, using the
18
+ * same storage key and default as `ThemeProvider`. Pass the same options to both.
19
+ */
20
+ export function createThemeScript({ storageKey = THEME_STORAGE_KEY, defaultTheme = "system", } = {}) {
21
+ const key = literal(storageKey);
22
+ const fallback = literal(defaultTheme);
23
+ return `(function(){var t=null;try{t=localStorage.getItem(${key})}catch(e){}if(t!=="light"&&t!=="dark"&&t!=="system")t=${fallback};var d=t==="dark";if(t==="system"){try{d=matchMedia(${literal(DARK_QUERY)}).matches}catch(e){}}document.documentElement.classList.toggle("dark",d)})();`;
24
+ }
25
+ /**
26
+ * Inline this in `<head>`, before any stylesheet paints, to avoid a flash of the wrong theme:
27
+ * `<script dangerouslySetInnerHTML={{ __html: themeScript }} />`.
28
+ */
29
+ export const themeScript = createThemeScript();