@jcsoftdev/ui 0.2.3 → 0.3.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 (375) hide show
  1. package/CHANGELOG.md +288 -7
  2. package/README.md +2 -1
  3. package/bin/ui-theme.mjs +1151 -25
  4. package/dist/ai/attachment/attachment.js +1 -1
  5. package/dist/ai/chat-list/group.js +3 -1
  6. package/dist/ai/conversation/conversation.js +1 -1
  7. package/dist/ai/internal/use-copy.d.ts +1 -5
  8. package/dist/ai/internal/use-copy.js +1 -32
  9. package/dist/ai/markdown/parse.js +59 -17
  10. package/dist/ai/source/source.js +1 -1
  11. package/dist/atoms/avatar/avatar.d.ts +13 -3
  12. package/dist/atoms/avatar/avatar.js +40 -2
  13. package/dist/atoms/avatar/index.d.ts +1 -1
  14. package/dist/atoms/avatar/index.js +3 -1
  15. package/dist/atoms/button/button.d.ts +4 -1
  16. package/dist/atoms/button/button.js +4 -2
  17. package/dist/atoms/checkbox/checkbox.d.ts +8 -3
  18. package/dist/atoms/checkbox/checkbox.js +23 -2
  19. package/dist/atoms/chip/chip.d.ts +9 -3
  20. package/dist/atoms/chip/chip.js +26 -4
  21. package/dist/atoms/chip/index.d.ts +1 -1
  22. package/dist/atoms/chip/index.js +4 -1
  23. package/dist/atoms/status-dot/index.d.ts +1 -1
  24. package/dist/atoms/status-dot/status-dot.d.ts +4 -2
  25. package/dist/atoms/status-dot/status-dot.js +5 -1
  26. package/dist/charts/bar-chart/bar-race-chart.js +1 -0
  27. package/dist/charts/beeswarm-chart/beeswarm-chart.js +1 -1
  28. package/dist/charts/chord-chart/chord-chart.js +13 -5
  29. package/dist/charts/core/cartesian/cartesian-chart.d.ts +1 -1
  30. package/dist/charts/core/cartesian/cartesian-chart.js +48 -11
  31. package/dist/charts/core/cartesian/layout.d.ts +6 -1
  32. package/dist/charts/core/cartesian/layout.js +14 -5
  33. package/dist/charts/core/cartesian/marks.d.ts +2 -2
  34. package/dist/charts/core/cartesian/marks.js +1 -1
  35. package/dist/charts/core/cartesian/types.d.ts +28 -2
  36. package/dist/charts/core/category-explorer.d.ts +2 -2
  37. package/dist/charts/core/category-explorer.js +8 -4
  38. package/dist/charts/core/chart-dock.d.ts +26 -0
  39. package/dist/charts/core/chart-dock.js +45 -0
  40. package/dist/charts/core/chart-frame.d.ts +9 -2
  41. package/dist/charts/core/chart-frame.js +105 -25
  42. package/dist/charts/core/distribution/explorer.d.ts +5 -2
  43. package/dist/charts/core/distribution/explorer.js +12 -5
  44. package/dist/charts/core/distribution/xy-points.js +1 -1
  45. package/dist/charts/core/index.d.ts +3 -0
  46. package/dist/charts/core/index.js +3 -0
  47. package/dist/charts/core/leave-grace.d.ts +11 -0
  48. package/dist/charts/core/leave-grace.js +26 -0
  49. package/dist/charts/core/nearest.d.ts +14 -0
  50. package/dist/charts/core/nearest.js +22 -0
  51. package/dist/charts/core/plot-overlay.js +9 -3
  52. package/dist/charts/core/pointer.test-utils.d.ts +38 -0
  53. package/dist/charts/core/pointer.test-utils.js +123 -0
  54. package/dist/charts/core/tooltip.d.ts +25 -2
  55. package/dist/charts/core/tooltip.js +115 -40
  56. package/dist/charts/core/touch-select.d.ts +20 -0
  57. package/dist/charts/core/touch-select.js +184 -0
  58. package/dist/charts/core/types.d.ts +8 -4
  59. package/dist/charts/core/types.js +5 -0
  60. package/dist/charts/core/use-index-navigation.d.ts +17 -6
  61. package/dist/charts/core/use-index-navigation.js +47 -10
  62. package/dist/charts/donut-chart/donut-chart.d.ts +5 -1
  63. package/dist/charts/donut-chart/donut-chart.js +40 -1
  64. package/dist/charts/donut-chart/slice-labels.d.ts +20 -0
  65. package/dist/charts/donut-chart/slice-labels.js +20 -0
  66. package/dist/charts/dumbbell-chart/dumbbell-chart.js +6 -3
  67. package/dist/charts/fill-gauge-chart/fill-gauge-chart.js +1 -0
  68. package/dist/charts/funnel-chart/funnel-chart.js +2 -1
  69. package/dist/charts/gauge-chart/gauge-chart.js +2 -1
  70. package/dist/charts/heatmap-chart/heatmap-chart.d.ts +4 -1
  71. package/dist/charts/heatmap-chart/heatmap-chart.js +3 -1
  72. package/dist/charts/heatmap-chart/heatmap-grid.d.ts +4 -1
  73. package/dist/charts/heatmap-chart/heatmap-grid.js +3 -1
  74. package/dist/charts/hex-tile-map/hex-tile-map.js +124 -115
  75. package/dist/charts/hierarchy-morph/hierarchy-morph.js +2 -1
  76. package/dist/charts/icicle-chart/icicle-chart.js +7 -9
  77. package/dist/charts/lollipop-chart/lollipop-chart.js +6 -3
  78. package/dist/charts/maps/geo/map-viewport.js +1 -1
  79. package/dist/charts/polar-area-chart/polar-area-chart.js +42 -12
  80. package/dist/charts/progress-units/progress-units.js +1 -0
  81. package/dist/charts/radar-chart/radar-chart.js +1 -1
  82. package/dist/charts/radial-bar-chart/radial-bar-chart.js +2 -1
  83. package/dist/charts/range-area-chart/range-area-chart.js +3 -2
  84. package/dist/charts/sankey-chart/sankey-chart.js +12 -4
  85. package/dist/charts/tree-chart/tree-chart.js +1 -0
  86. package/dist/charts/treemap-chart/treemap-chart.js +2 -7
  87. package/dist/charts/waterfall-chart/waterfall-chart.js +6 -3
  88. package/dist/containers/action-bar/action-bar.d.ts +11 -2
  89. package/dist/containers/action-bar/action-bar.js +4 -1
  90. package/dist/containers/card/card.d.ts +21 -3
  91. package/dist/containers/card/card.js +20 -5
  92. package/dist/containers/grid/grid.d.ts +15 -0
  93. package/dist/containers/grid/grid.js +24 -0
  94. package/dist/containers/grid/index.d.ts +1 -0
  95. package/dist/containers/grid/index.js +4 -0
  96. package/dist/containers/index.d.ts +3 -0
  97. package/dist/containers/index.js +3 -0
  98. package/dist/containers/kpi/kpi.d.ts +13 -2
  99. package/dist/containers/kpi/kpi.js +86 -24
  100. package/dist/containers/kpi-group/index.d.ts +1 -1
  101. package/dist/containers/kpi-group/index.js +3 -1
  102. package/dist/containers/kpi-group/kpi-group.d.ts +9 -1
  103. package/dist/containers/kpi-group/kpi-group.js +11 -1
  104. package/dist/containers/page/index.d.ts +1 -0
  105. package/dist/containers/page/index.js +4 -0
  106. package/dist/containers/page/page.d.ts +7 -0
  107. package/dist/containers/page/page.js +14 -0
  108. package/dist/containers/page-header/page-header.d.ts +8 -3
  109. package/dist/containers/page-header/page-header.js +35 -8
  110. package/dist/containers/responsive-list/responsive-list.d.ts +1 -1
  111. package/dist/containers/responsive-list/responsive-list.js +6 -3
  112. package/dist/containers/stack/index.d.ts +1 -0
  113. package/dist/containers/stack/index.js +6 -0
  114. package/dist/containers/stack/stack.d.ts +15 -0
  115. package/dist/containers/stack/stack.js +43 -0
  116. package/dist/forms/copy-field/copy-field.d.ts +17 -0
  117. package/dist/forms/copy-field/copy-field.js +72 -0
  118. package/dist/forms/copy-field/index.d.ts +1 -0
  119. package/dist/forms/copy-field/index.js +4 -0
  120. package/dist/forms/emoji-picker/emoji-picker.js +1 -1
  121. package/dist/forms/form/form.d.ts +15 -0
  122. package/dist/forms/form/form.js +29 -0
  123. package/dist/forms/form/index.d.ts +1 -0
  124. package/dist/forms/form/index.js +10 -0
  125. package/dist/forms/index.d.ts +2 -0
  126. package/dist/forms/index.js +2 -0
  127. package/dist/forms/input/index.d.ts +1 -1
  128. package/dist/forms/input/index.js +3 -2
  129. package/dist/forms/input/input.d.ts +6 -2
  130. package/dist/forms/input/input.js +9 -3
  131. package/dist/glass/crystal-map.d.ts +70 -0
  132. package/dist/glass/crystal-map.js +88 -0
  133. package/dist/glass/displacement-map.d.ts +117 -0
  134. package/dist/glass/displacement-map.js +201 -0
  135. package/dist/glass/index.d.ts +8 -0
  136. package/dist/glass/index.js +63 -0
  137. package/dist/glass/lens-crystal.d.ts +29 -0
  138. package/dist/glass/lens-crystal.js +161 -0
  139. package/dist/glass/lens-dispersion.d.ts +11 -0
  140. package/dist/glass/lens-dispersion.js +19 -0
  141. package/dist/glass/liquid-glass.d.ts +41 -0
  142. package/dist/glass/liquid-glass.js +256 -0
  143. package/dist/glass/liquid-motion.d.ts +53 -0
  144. package/dist/glass/liquid-motion.js +302 -0
  145. package/dist/glass/liquid-options.d.ts +162 -0
  146. package/dist/glass/liquid-options.js +179 -0
  147. package/dist/glass/refraction.d.ts +100 -0
  148. package/dist/glass/refraction.js +714 -0
  149. package/dist/glass/specular-map.d.ts +26 -0
  150. package/dist/glass/specular-map.js +75 -0
  151. package/dist/glass/spring.d.ts +79 -0
  152. package/dist/glass/spring.js +58 -0
  153. package/dist/glass/support.d.ts +13 -0
  154. package/dist/glass/support.js +14 -0
  155. package/dist/glass/use-glass-refraction.d.ts +8 -0
  156. package/dist/glass/use-glass-refraction.js +16 -0
  157. package/dist/i18n/strings.d.ts +24 -0
  158. package/dist/i18n/strings.js +18 -2
  159. package/dist/icons/index.d.ts +2 -0
  160. package/dist/icons/index.js +4 -0
  161. package/dist/icons/key.d.ts +2 -0
  162. package/dist/icons/key.js +12 -0
  163. package/dist/icons/webhook.d.ts +2 -0
  164. package/dist/icons/webhook.js +12 -0
  165. package/dist/liquid/index.d.ts +3 -0
  166. package/dist/liquid/index.js +29 -0
  167. package/dist/navigation/breadcrumbs/breadcrumbs.d.ts +29 -0
  168. package/dist/navigation/breadcrumbs/breadcrumbs.js +70 -0
  169. package/dist/navigation/breadcrumbs/index.d.ts +1 -0
  170. package/dist/navigation/breadcrumbs/index.js +6 -0
  171. package/dist/navigation/index.d.ts +1 -0
  172. package/dist/navigation/index.js +1 -0
  173. package/dist/navigation/segmented/index.d.ts +1 -1
  174. package/dist/navigation/segmented/model.d.ts +5 -0
  175. package/dist/navigation/segmented/model.js +6 -0
  176. package/dist/navigation/segmented/segmented.d.ts +17 -3
  177. package/dist/navigation/segmented/segmented.js +20 -4
  178. package/dist/overlays/context-menu/context-menu.d.ts +9 -1
  179. package/dist/overlays/context-menu/context-menu.js +4 -1
  180. package/dist/overlays/dialog/dialog.d.ts +9 -1
  181. package/dist/overlays/dialog/dialog.js +3 -0
  182. package/dist/overlays/drawer/drawer.d.ts +9 -1
  183. package/dist/overlays/drawer/drawer.js +3 -0
  184. package/dist/overlays/dropdown-menu/dropdown-menu.d.ts +9 -1
  185. package/dist/overlays/dropdown-menu/dropdown-menu.js +3 -1
  186. package/dist/overlays/hover-card/hover-card.d.ts +10 -1
  187. package/dist/overlays/hover-card/hover-card.js +4 -1
  188. package/dist/overlays/popover/popover.d.ts +9 -1
  189. package/dist/overlays/popover/popover.js +3 -0
  190. package/dist/palette/command-palette/command-palette.d.ts +12 -2
  191. package/dist/palette/command-palette/command-palette.js +5 -0
  192. package/dist/primitives/command/command.d.ts +3 -2
  193. package/dist/primitives/command/command.js +2 -0
  194. package/dist/primitives/menu/menu.js +1 -1
  195. package/dist/primitives/popper/popper.js +5 -0
  196. package/dist/rich-text/rich-text-editor.js +94 -8
  197. package/dist/rich-text/sanitize.js +70 -20
  198. package/dist/shell/app-shell/app-shell.d.ts +17 -0
  199. package/dist/shell/app-shell/app-shell.js +44 -4
  200. package/dist/shell/bottom-nav/bottom-nav.d.ts +34 -0
  201. package/dist/shell/bottom-nav/bottom-nav.js +124 -0
  202. package/dist/shell/bottom-nav/index.d.ts +2 -0
  203. package/dist/shell/bottom-nav/index.js +9 -0
  204. package/dist/shell/bottom-nav/split.d.ts +11 -0
  205. package/dist/shell/bottom-nav/split.js +10 -0
  206. package/dist/shell/sidebar/sidebar.d.ts +16 -2
  207. package/dist/shell/sidebar/sidebar.js +46 -4
  208. package/dist/shell/topbar/topbar.d.ts +20 -9
  209. package/dist/shell/topbar/topbar.js +16 -9
  210. package/dist/states/empty-state/empty-state.d.ts +3 -1
  211. package/dist/states/empty-state/empty-state.js +9 -1
  212. package/dist/states/error-state/error-state.d.ts +3 -1
  213. package/dist/states/error-state/error-state.js +2 -0
  214. package/dist/states/index.d.ts +1 -0
  215. package/dist/states/index.js +1 -0
  216. package/dist/states/live-status-bar/index.d.ts +1 -0
  217. package/dist/states/live-status-bar/index.js +6 -0
  218. package/dist/states/live-status-bar/live-status-bar.d.ts +17 -0
  219. package/dist/states/live-status-bar/live-status-bar.js +49 -0
  220. package/dist/states/offline-banner/offline-banner.d.ts +3 -1
  221. package/dist/states/offline-banner/offline-banner.js +8 -4
  222. package/dist/utils/class-groups.js +17 -0
  223. package/dist/utils/index.d.ts +1 -0
  224. package/dist/utils/index.js +2 -0
  225. package/dist/utils/material.d.ts +13 -0
  226. package/dist/utils/material.js +6 -0
  227. package/dist/utils/tone.d.ts +8 -0
  228. package/dist/utils/tone.js +17 -0
  229. package/dist/utils/use-copy.d.ts +5 -0
  230. package/dist/utils/use-copy.js +35 -0
  231. package/icons/svg/key.svg +5 -0
  232. package/icons/svg/webhook.svg +5 -0
  233. package/package.json +31 -21
  234. package/scripts/build-theme.d.mts +22 -0
  235. package/scripts/build-theme.mjs +236 -4
  236. package/src/ai/attachment/attachment.tsx +1 -1
  237. package/src/ai/chat-list/group.ts +3 -1
  238. package/src/ai/conversation/conversation.tsx +1 -1
  239. package/src/ai/internal/use-copy.ts +1 -38
  240. package/src/ai/markdown/parse.ts +74 -17
  241. package/src/ai/source/source.tsx +1 -1
  242. package/src/atoms/avatar/avatar.tsx +57 -4
  243. package/src/atoms/avatar/index.ts +8 -1
  244. package/src/atoms/button/button.tsx +8 -3
  245. package/src/atoms/checkbox/checkbox.tsx +30 -3
  246. package/src/atoms/chip/chip.tsx +37 -5
  247. package/src/atoms/chip/index.ts +7 -1
  248. package/src/atoms/status-dot/index.ts +1 -0
  249. package/src/atoms/status-dot/status-dot.tsx +15 -3
  250. package/src/charts/README.md +21 -0
  251. package/src/charts/bar-chart/bar-race-chart.tsx +1 -0
  252. package/src/charts/beeswarm-chart/beeswarm-chart.tsx +1 -1
  253. package/src/charts/chord-chart/chord-chart.tsx +13 -5
  254. package/src/charts/core/cartesian/cartesian-chart.tsx +55 -10
  255. package/src/charts/core/cartesian/layout.ts +29 -10
  256. package/src/charts/core/cartesian/marks.tsx +3 -3
  257. package/src/charts/core/cartesian/types.ts +30 -2
  258. package/src/charts/core/category-explorer.tsx +12 -6
  259. package/src/charts/core/chart-dock.tsx +68 -0
  260. package/src/charts/core/chart-frame.tsx +116 -27
  261. package/src/charts/core/distribution/explorer.tsx +17 -7
  262. package/src/charts/core/distribution/xy-points.tsx +1 -1
  263. package/src/charts/core/index.ts +3 -0
  264. package/src/charts/core/leave-grace.ts +35 -0
  265. package/src/charts/core/nearest.ts +38 -0
  266. package/src/charts/core/plot-overlay.tsx +9 -3
  267. package/src/charts/core/pointer.test-utils.ts +146 -0
  268. package/src/charts/core/tooltip.tsx +129 -15
  269. package/src/charts/core/touch-select.ts +250 -0
  270. package/src/charts/core/types.ts +13 -4
  271. package/src/charts/core/use-index-navigation.ts +70 -11
  272. package/src/charts/donut-chart/donut-chart.tsx +53 -3
  273. package/src/charts/donut-chart/slice-labels.ts +39 -0
  274. package/src/charts/dumbbell-chart/dumbbell-chart.tsx +8 -3
  275. package/src/charts/fill-gauge-chart/fill-gauge-chart.tsx +1 -0
  276. package/src/charts/funnel-chart/funnel-chart.tsx +2 -1
  277. package/src/charts/gauge-chart/gauge-chart.tsx +2 -1
  278. package/src/charts/heatmap-chart/heatmap-chart.tsx +5 -0
  279. package/src/charts/heatmap-chart/heatmap-grid.tsx +5 -1
  280. package/src/charts/hex-tile-map/hex-tile-map.tsx +6 -1
  281. package/src/charts/hierarchy-morph/hierarchy-morph.tsx +2 -1
  282. package/src/charts/icicle-chart/icicle-chart.tsx +8 -9
  283. package/src/charts/lollipop-chart/lollipop-chart.tsx +8 -3
  284. package/src/charts/maps/geo/map-viewport.tsx +1 -1
  285. package/src/charts/polar-area-chart/polar-area-chart.tsx +37 -12
  286. package/src/charts/progress-units/progress-units.tsx +1 -0
  287. package/src/charts/radar-chart/radar-chart.tsx +1 -1
  288. package/src/charts/radial-bar-chart/radial-bar-chart.tsx +2 -1
  289. package/src/charts/range-area-chart/range-area-chart.tsx +3 -2
  290. package/src/charts/sankey-chart/sankey-chart.tsx +12 -4
  291. package/src/charts/tree-chart/tree-chart.tsx +1 -0
  292. package/src/charts/treemap-chart/treemap-chart.tsx +2 -7
  293. package/src/charts/waterfall-chart/waterfall-chart.tsx +8 -3
  294. package/src/containers/action-bar/action-bar.tsx +13 -2
  295. package/src/containers/card/card.tsx +43 -4
  296. package/src/containers/grid/grid.tsx +37 -0
  297. package/src/containers/grid/index.ts +1 -0
  298. package/src/containers/index.ts +3 -0
  299. package/src/containers/kpi/kpi.tsx +116 -22
  300. package/src/containers/kpi-group/index.ts +7 -1
  301. package/src/containers/kpi-group/kpi-group.tsx +26 -1
  302. package/src/containers/page/index.ts +1 -0
  303. package/src/containers/page/page.tsx +17 -0
  304. package/src/containers/page-header/page-header.tsx +38 -8
  305. package/src/containers/responsive-list/responsive-list.tsx +7 -4
  306. package/src/containers/stack/index.ts +7 -0
  307. package/src/containers/stack/stack.tsx +55 -0
  308. package/src/forms/copy-field/copy-field.tsx +88 -0
  309. package/src/forms/copy-field/index.ts +1 -0
  310. package/src/forms/emoji-picker/emoji-picker.tsx +1 -1
  311. package/src/forms/form/form.tsx +46 -0
  312. package/src/forms/form/index.ts +8 -0
  313. package/src/forms/index.ts +2 -0
  314. package/src/forms/input/index.ts +1 -1
  315. package/src/forms/input/input.tsx +14 -3
  316. package/src/glass/crystal-map.ts +150 -0
  317. package/src/glass/displacement-map.ts +317 -0
  318. package/src/glass/index.ts +43 -0
  319. package/src/glass/lens-crystal.ts +226 -0
  320. package/src/glass/lens-dispersion.ts +34 -0
  321. package/src/glass/liquid-glass.tsx +371 -0
  322. package/src/glass/liquid-motion.ts +395 -0
  323. package/src/glass/liquid-options.ts +306 -0
  324. package/src/glass/refraction.ts +1010 -0
  325. package/src/glass/specular-map.ts +95 -0
  326. package/src/glass/spring.ts +98 -0
  327. package/src/glass/support.ts +27 -0
  328. package/src/glass/use-glass-refraction.ts +21 -0
  329. package/src/i18n/strings.ts +24 -0
  330. package/src/icons/index.ts +2 -0
  331. package/src/icons/key.tsx +13 -0
  332. package/src/icons/webhook.tsx +13 -0
  333. package/src/liquid/index.ts +24 -0
  334. package/src/navigation/breadcrumbs/breadcrumbs.tsx +103 -0
  335. package/src/navigation/breadcrumbs/index.ts +8 -0
  336. package/src/navigation/index.ts +1 -0
  337. package/src/navigation/segmented/index.ts +1 -0
  338. package/src/navigation/segmented/model.ts +11 -0
  339. package/src/navigation/segmented/segmented.tsx +45 -6
  340. package/src/overlays/context-menu/context-menu.tsx +11 -1
  341. package/src/overlays/dialog/dialog.tsx +10 -0
  342. package/src/overlays/drawer/drawer.tsx +10 -0
  343. package/src/overlays/dropdown-menu/dropdown-menu.tsx +10 -1
  344. package/src/overlays/hover-card/hover-card.tsx +12 -1
  345. package/src/overlays/popover/popover.tsx +10 -0
  346. package/src/palette/command-palette/command-palette.tsx +15 -1
  347. package/src/primitives/command/command.tsx +4 -0
  348. package/src/primitives/menu/menu.tsx +1 -1
  349. package/src/primitives/popper/popper.tsx +10 -0
  350. package/src/rich-text/rich-text-editor.tsx +116 -13
  351. package/src/rich-text/sanitize.ts +94 -23
  352. package/src/shell/app-shell/app-shell.tsx +60 -4
  353. package/src/shell/bottom-nav/bottom-nav.tsx +187 -0
  354. package/src/shell/bottom-nav/index.ts +8 -0
  355. package/src/shell/bottom-nav/split.ts +20 -0
  356. package/src/shell/sidebar/sidebar.tsx +51 -5
  357. package/src/shell/topbar/topbar.tsx +81 -58
  358. package/src/states/empty-state/empty-state.tsx +11 -1
  359. package/src/states/error-state/error-state.tsx +4 -0
  360. package/src/states/index.ts +1 -0
  361. package/src/states/live-status-bar/index.ts +6 -0
  362. package/src/states/live-status-bar/live-status-bar.tsx +62 -0
  363. package/src/states/offline-banner/offline-banner.tsx +13 -5
  364. package/src/utils/class-groups.ts +17 -0
  365. package/src/utils/index.ts +1 -0
  366. package/src/utils/material.ts +16 -0
  367. package/src/utils/tone.ts +29 -0
  368. package/src/utils/use-copy.ts +38 -0
  369. package/styles/Theme.kt +64 -3
  370. package/styles/base.css +51 -0
  371. package/styles/tailwind.css +833 -0
  372. package/styles/theme.css +546 -4
  373. package/styles/tokens.css +788 -15
  374. package/tokens/default.json +918 -29
  375. package/scripts/build-theme.d.ts +0 -18
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcsoftdev/ui",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Token-driven React component library: React 19, Tailwind v4.",
5
5
  "author": "jcsoftdev",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "bin",
46
46
  "icons",
47
47
  "scripts/build-theme.mjs",
48
- "scripts/build-theme.d.ts",
48
+ "scripts/build-theme.d.mts",
49
49
  "README.md",
50
50
  "CHANGELOG.md",
51
51
  "THIRD_PARTY_NOTICES.md",
@@ -56,7 +56,7 @@
56
56
  "./tokens/*": "./tokens/*",
57
57
  "./package.json": "./package.json",
58
58
  "./theme-builder": {
59
- "types": "./scripts/build-theme.d.ts",
59
+ "types": "./scripts/build-theme.d.mts",
60
60
  "import": "./scripts/build-theme.mjs"
61
61
  },
62
62
  "./rich-text": {
@@ -76,22 +76,6 @@
76
76
  "import": "./dist/*/index.js"
77
77
  }
78
78
  },
79
- "scripts": {
80
- "build": "pnpm build:styles && pnpm build:class-tokens && tsup && tsc -p tsconfig.build.json",
81
- "build:icons": "node scripts/build-icons.mjs",
82
- "build:class-tokens": "node scripts/build-class-tokens.mjs",
83
- "build:styles": "node bin/ui-theme.mjs build tokens/default.json --out styles",
84
- "lint": "biome check .",
85
- "storybook": "storybook dev -p 6006",
86
- "build-storybook": "storybook build -o storybook-static",
87
- "format": "biome check --write .",
88
- "typecheck": "tsc --noEmit",
89
- "test": "node --test \"test/*.test.mjs\"",
90
- "test:stories": "vitest run --project stories",
91
- "check:treeshake": "node test/treeshake.mjs",
92
- "check:dist-imports": "node test/dist-imports.mjs",
93
- "check:docs-examples": "tsc -p tsconfig.docs.json && node test/docs-examples.mjs"
94
- },
95
79
  "peerDependencies": {
96
80
  "react": "^19.0.0",
97
81
  "react-dom": "^19.0.0"
@@ -117,9 +101,35 @@
117
101
  "tsup": "^8.5.0",
118
102
  "typescript": "^5.5.4",
119
103
  "vite": "7.3.6",
120
- "vitest": "4.1.11"
104
+ "vitest": "4.1.11",
105
+ "@jcsoftdev/ui-tokens": "^0.3.0"
121
106
  },
122
107
  "publishConfig": {
123
108
  "access": "public"
109
+ },
110
+ "scripts": {
111
+ "build": "pnpm sync:tokens && pnpm build:class-tokens && tsup && tsc -p tsconfig.build.json",
112
+ "build:icons": "node scripts/build-icons.mjs",
113
+ "build:class-tokens": "node scripts/build-class-tokens.mjs",
114
+ "lint": "biome check .",
115
+ "prestorybook": "node scripts/sync-tokens.mjs",
116
+ "storybook": "storybook dev -p 6006",
117
+ "prebuild-storybook": "node scripts/sync-tokens.mjs",
118
+ "build-storybook": "storybook build -o storybook-static",
119
+ "format": "biome check --write .",
120
+ "typecheck": "tsc --noEmit",
121
+ "test": "node --test \"test/*.test.mjs\"",
122
+ "test:stories": "vitest run --project stories",
123
+ "test:glass": "vitest run --project glass",
124
+ "check:treeshake": "node test/treeshake.mjs",
125
+ "check:dist-imports": "node test/dist-imports.mjs",
126
+ "check:pack": "node test/pack-consumer.mjs",
127
+ "check:docs-examples": "tsc -p tsconfig.docs.json && node test/docs-examples.mjs",
128
+ "check:rsc": "node test/rsc.mjs",
129
+ "sync:tokens": "node scripts/sync-tokens.mjs",
130
+ "pretest": "node scripts/sync-tokens.mjs",
131
+ "pretest:stories": "node scripts/sync-tokens.mjs",
132
+ "pretest:glass": "node scripts/sync-tokens.mjs",
133
+ "pretypecheck": "node scripts/sync-tokens.mjs"
124
134
  }
125
- }
135
+ }
@@ -0,0 +1,22 @@
1
+ export type TokenFile = Record<string, unknown>;
2
+ export interface BuildOptions {
3
+ kotlinPackage?: string;
4
+ kotlinLibrary?: boolean;
5
+ /** Set to false to skip Theme.kt; tokens with var() or oklch() colors then build. */
6
+ kotlin?: boolean;
7
+ }
8
+ /** Generated files by name: tokens.css, theme.css, tailwind.css, fonts.css, and Theme.kt unless `kotlin: false`. */
9
+ export function buildTheme(tokens: TokenFile, options?: BuildOptions): Record<string, string>;
10
+ export function palettesOf(tokens: TokenFile): Map<string, Record<string, string>>;
11
+ export function tonesOf(tokens: TokenFile): { name: string; value: unknown }[];
12
+ export function stylesOf(tokens: TokenFile): unknown;
13
+ export function glassOf(tokens: TokenFile): unknown;
14
+ export function toKotlinColor(value: string): string;
15
+ export function buildTokensCss(tokens: TokenFile): string;
16
+ export function buildThemeCss(tokens: TokenFile): string;
17
+ export function buildFontsCss(tokens: TokenFile): string;
18
+ export function buildThemeKt(
19
+ tokens: TokenFile,
20
+ pkg?: string,
21
+ options?: { library?: boolean },
22
+ ): string;
@@ -1,4 +1,4 @@
1
- // Token generator: tokens.json -> tokens.css, theme.css, fonts.css, Theme.kt.
1
+ // Token generator: tokens.json -> tokens.css, theme.css (= tailwind.css), fonts.css, Theme.kt.
2
2
  // Pure functions, no dependencies. Used by bin/ui-theme.mjs and the tests.
3
3
 
4
4
  const PALETTE_ROLES = {
@@ -23,8 +23,40 @@ const themeOf = (tokens) => {
23
23
  return { base: themes[0], others: themes.slice(1) };
24
24
  };
25
25
 
26
+ const TONE_NAME = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
27
+ const TONE_ROLES = ["fill", "soft", "ink"];
28
+
29
+ /** Tone palettes as color tokens: --tone-<name>, --tone-<name>-soft, --tone-<name>-ink. */
30
+ export function tonesOf(tokens) {
31
+ const out = [];
32
+ for (const [name, roles] of Object.entries(tokens.tonePalettes ?? {})) {
33
+ if (!TONE_NAME.test(name)) {
34
+ throw new Error(
35
+ `tonePalettes: "${name}" must be kebab-case (lowercase letters, digits, hyphens)`,
36
+ );
37
+ }
38
+ for (const role of Object.keys(roles ?? {})) {
39
+ if (!TONE_ROLES.includes(role)) {
40
+ throw new Error(`tonePalettes.${name}: unknown role "${role}" (expected fill, soft, ink)`);
41
+ }
42
+ }
43
+ for (const role of ["fill", "soft"]) {
44
+ if (roles?.[role] === undefined)
45
+ throw new Error(`tonePalettes.${name}: "${role}" is required`);
46
+ }
47
+ const value = { fill: roles.fill, soft: roles.soft, ink: roles.ink ?? roles.fill };
48
+ out.push(
49
+ { name: `tone-${name}`, value: value.fill },
50
+ { name: `tone-${name}-soft`, value: value.soft },
51
+ { name: `tone-${name}-ink`, value: value.ink },
52
+ );
53
+ }
54
+ return out;
55
+ }
56
+
26
57
  const allTokens = (tokens) => [
27
58
  ...(tokens.color?.tokens ?? []),
59
+ ...tonesOf(tokens),
28
60
  ...(tokens.shadow?.tokens ?? []),
29
61
  ...(tokens.radius?.tokens ?? []),
30
62
  ...(tokens.spacing?.tokens ?? []),
@@ -260,6 +292,9 @@ export function buildThemeCss(tokens) {
260
292
  for (const t of tokens.color?.tokens ?? []) {
261
293
  lines.push(` --color-${t.name}: var(--${t.name});`);
262
294
  }
295
+ for (const t of tonesOf(tokens)) {
296
+ lines.push(` --color-${t.name}: var(--${t.name});`);
297
+ }
263
298
  for (const t of tokens.radius?.tokens ?? []) {
264
299
  lines.push(` --radius-${stripPrefix(t.name, "radius")}: var(--${t.name});`);
265
300
  }
@@ -354,7 +389,76 @@ const kotlinColorOf = (token, theme, base) => {
354
389
 
355
390
  const px = (value) => `${Number.parseFloat(value)}.dp`;
356
391
 
357
- export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
392
+ // ---------------------------------------------------------------- Glass
393
+
394
+ const GLASS_VARIANTS = ["regular", "clear"];
395
+
396
+ /**
397
+ * Liquid Glass materials, derived from styles.tokens named glass-<variant>-<part>. Empty when the
398
+ * theme declares none, so themes without glass generate exactly what they did before.
399
+ */
400
+ export function glassOf(tokens) {
401
+ const byName = new Map((tokens.styles?.tokens ?? []).map((t) => [t.name, t]));
402
+ return GLASS_VARIANTS.filter((v) => byName.has(`glass-${v}-tint`)).map((id) => {
403
+ const part = (name) => {
404
+ const t = byName.get(`glass-${id}-${name}`);
405
+ if (!t) throw new Error(`styles: glass variant "${id}" is missing "glass-${id}-${name}"`);
406
+ return t;
407
+ };
408
+ return {
409
+ id,
410
+ tint: part("tint"),
411
+ border: part("border"),
412
+ edge: part("edge"),
413
+ dim: part("dim"),
414
+ blur: part("blur"),
415
+ saturate: part("saturate"),
416
+ };
417
+ });
418
+ }
419
+
420
+ function glassKotlin(tokens, { library }) {
421
+ const variants = glassOf(tokens);
422
+ if (!variants.length) return [];
423
+ const { base, others } = themeOf(tokens);
424
+ const vis = library ? "public " : "";
425
+ const out = [];
426
+ if (library) out.push("@Immutable");
427
+ out.push(
428
+ `${vis}class GlassMaterial(`,
429
+ ` ${vis}val tint: Color,`,
430
+ ` ${vis}val border: Color,`,
431
+ ` ${vis}val edge: Color,`,
432
+ ` ${vis}val dim: Color,`,
433
+ ` ${vis}val blur: ${library ? "Dp" : "androidx.compose.ui.unit.Dp"},`,
434
+ ` ${vis}val saturate: Float,`,
435
+ ")",
436
+ "",
437
+ );
438
+ if (library) out.push("@Immutable");
439
+ out.push(`${vis}object UiGlass {`);
440
+ for (const theme of [base, ...others]) {
441
+ for (const v of variants) {
442
+ const c = (t) => kotlinColorOf(t, theme, base);
443
+ const type = library ? ": GlassMaterial" : "";
444
+ out.push(
445
+ ` ${vis}val ${pascal(v.id)}${pascal(theme)}${type} = GlassMaterial(`,
446
+ ` tint = ${c(v.tint)},`,
447
+ ` border = ${c(v.border)},`,
448
+ ` edge = ${c(v.edge)},`,
449
+ ` dim = ${c(v.dim)},`,
450
+ ` blur = ${px(valueFor(v.blur, theme, base))},`,
451
+ ` saturate = ${Number.parseFloat(valueFor(v.saturate, theme, base))}f,`,
452
+ " )",
453
+ );
454
+ }
455
+ }
456
+ out.push("}", "");
457
+ return out;
458
+ }
459
+
460
+ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme", { library = false } = {}) {
461
+ if (library) return buildLibraryThemeKt(tokens, pkg);
358
462
  const { base, others } = themeOf(tokens);
359
463
  const themes = [base, ...others];
360
464
  const colors = (tokens.color?.tokens ?? []).filter((t) => !t.name.startsWith("pal-"));
@@ -435,15 +539,143 @@ export function buildThemeKt(tokens, pkg = "com.jcsoftdev.ui.theme") {
435
539
  out.push(` val ${camel(s.name)} = TextStyle(${parts.join(", ")})`);
436
540
  }
437
541
  out.push("}", "");
542
+ const sizeScale = tokens.type?.sizeScale ?? [];
543
+ if (sizeScale.length > 0) {
544
+ out.push("object UiFontSizes {");
545
+ for (const s of sizeScale)
546
+ out.push(` val ${camel(s.name)} = ${Number.parseFloat(s.fontSize)}.sp`);
547
+ out.push("}", "");
548
+ }
549
+ out.push(...glassKotlin(tokens, { library: false }));
550
+ return out.join("\n");
551
+ }
552
+
553
+ /**
554
+ * Library flavour of Theme.kt: explicit `public` + types (the kit compiles with explicitApi),
555
+ * @Immutable token holders, and no Map in the API (Compose treats Map as unstable), so accent
556
+ * palettes are resolved with a `when` lookup.
557
+ */
558
+ function buildLibraryThemeKt(tokens, pkg) {
559
+ const { base, others } = themeOf(tokens);
560
+ const themes = [base, ...others];
561
+ const colors = (tokens.color?.tokens ?? []).filter((t) => !t.name.startsWith("pal-"));
562
+ const out = [
563
+ `// Generated by ui-theme from "${tokens.name}". Do not edit.`,
564
+ "",
565
+ `package ${pkg}`,
566
+ "",
567
+ "import androidx.compose.foundation.shape.RoundedCornerShape",
568
+ "import androidx.compose.runtime.Immutable",
569
+ "import androidx.compose.ui.graphics.Color",
570
+ "import androidx.compose.ui.text.TextStyle",
571
+ "import androidx.compose.ui.text.font.FontWeight",
572
+ "import androidx.compose.ui.unit.Dp",
573
+ "import androidx.compose.ui.unit.TextUnit",
574
+ "import androidx.compose.ui.unit.dp",
575
+ "import androidx.compose.ui.unit.em",
576
+ "import androidx.compose.ui.unit.sp",
577
+ "",
578
+ "@Immutable",
579
+ "public class ThemeColors(",
580
+ ...colors.map((t) => ` public val ${camel(t.name)}: Color,`),
581
+ ")",
582
+ "",
583
+ "public object UiColors {",
584
+ ];
585
+ for (const theme of themes) {
586
+ out.push(` public val ${pascal(theme)}: ThemeColors = ThemeColors(`);
587
+ for (const t of colors) {
588
+ out.push(` ${camel(t.name)} = ${kotlinColorOf(t, theme, base)},`);
589
+ }
590
+ out.push(" )");
591
+ }
592
+ out.push("}", "");
593
+
594
+ const palettes = palettesOf(tokens);
595
+ if (palettes.size) {
596
+ const byName = new Map(tokens.color.tokens.map((t) => [t.name, t]));
597
+ out.push("@Immutable", "public class AccentPalette(");
598
+ for (const target of Object.values(PALETTE_ROLES)) {
599
+ out.push(` public val ${camel(target)}: Color,`);
600
+ }
601
+ out.push(")", "", "@Immutable", "public object UiPalettes {");
602
+ out.push(
603
+ ` public val ids: List<String> = listOf(${[...palettes.keys()].map((id) => `"${id}"`).join(", ")})`,
604
+ );
605
+ for (const theme of themes) {
606
+ out.push("");
607
+ for (const [id, roles] of palettes) {
608
+ const args = Object.keys(PALETTE_ROLES).map((role) => {
609
+ const tok = byName.get(roles[role]);
610
+ return tok ? kotlinColorOf(tok, theme, base) : "Color.Unspecified";
611
+ });
612
+ out.push(` private val ${camel(`${theme}-${id}`)} = AccentPalette(${args.join(", ")})`);
613
+ }
614
+ out.push(
615
+ "",
616
+ ` public fun ${camel(theme)}(id: String): AccentPalette? =`,
617
+ " when (id) {",
618
+ );
619
+ for (const id of palettes.keys()) {
620
+ out.push(` "${id}" -> ${camel(`${theme}-${id}`)}`);
621
+ }
622
+ out.push(" else -> null", " }");
623
+ }
624
+ out.push("}", "");
625
+ }
626
+
627
+ out.push("public object UiShapes {");
628
+ for (const t of tokens.radius?.tokens ?? []) {
629
+ const n = camel(stripPrefix(t.name, "radius"));
630
+ const pill = Number.parseFloat(t.value) >= 999;
631
+ out.push(
632
+ ` public val ${n}: RoundedCornerShape = RoundedCornerShape(${pill ? "50" : px(t.value)})`,
633
+ );
634
+ }
635
+ out.push("}", "", "public object UiSizes {");
636
+ for (const t of [...(tokens.spacing?.tokens ?? []), ...(tokens.size?.tokens ?? [])]) {
637
+ out.push(` public val ${camel(t.name)}: Dp = ${px(t.value)}`);
638
+ }
639
+ out.push("}", "");
640
+
641
+ const family = (tokens.type?.fonts ?? [])[0]?.family ?? "";
642
+ out.push(
643
+ `public const val UiFontFamilyName: String = "${family}"`,
644
+ "",
645
+ "public object UiTypography {",
646
+ );
647
+ for (const s of typeStyles(tokens)) {
648
+ const size = Number.parseFloat(s.fontSize);
649
+ const parts = [`fontSize = ${size}.sp`];
650
+ if (s.fontWeight !== undefined) parts.push(`fontWeight = FontWeight(${s.fontWeight})`);
651
+ if (s.lineHeight !== undefined) {
652
+ const lh = String(s.lineHeight).endsWith("px")
653
+ ? Number.parseFloat(s.lineHeight)
654
+ : Number((size * Number(s.lineHeight)).toFixed(2));
655
+ parts.push(`lineHeight = ${lh}.sp`);
656
+ }
657
+ if (s.letterSpacing) parts.push(`letterSpacing = (${Number.parseFloat(s.letterSpacing)}).em`);
658
+ out.push(` public val ${camel(s.name)}: TextStyle = TextStyle(${parts.join(", ")})`);
659
+ }
660
+ out.push("}", "");
661
+ const sizeScale = tokens.type?.sizeScale ?? [];
662
+ if (sizeScale.length > 0) {
663
+ out.push("public object UiFontSizes {");
664
+ for (const s of sizeScale)
665
+ out.push(` public val ${camel(s.name)}: TextUnit = ${Number.parseFloat(s.fontSize)}.sp`);
666
+ out.push("}", "");
667
+ }
668
+ out.push(...glassKotlin(tokens, { library: true }));
438
669
  return out.join("\n");
439
670
  }
440
671
 
441
- export function buildTheme(tokens, { kotlinPackage, kotlin = true } = {}) {
672
+ export function buildTheme(tokens, { kotlinPackage, kotlinLibrary = false, kotlin = true } = {}) {
442
673
  const css = {
443
674
  "tokens.css": buildTokensCss(tokens),
444
675
  "theme.css": buildThemeCss(tokens),
676
+ "tailwind.css": buildThemeCss(tokens),
445
677
  "fonts.css": buildFontsCss(tokens),
446
678
  };
447
679
  if (!kotlin) return css;
448
- return { ...css, "Theme.kt": buildThemeKt(tokens, kotlinPackage) };
680
+ return { ...css, "Theme.kt": buildThemeKt(tokens, kotlinPackage, { library: kotlinLibrary }) };
449
681
  }
@@ -122,7 +122,7 @@ export function Attachment({
122
122
  onClick={onRemove}
123
123
  className={cn(
124
124
  "size-5",
125
- preview && "absolute right-2.5 top-2.5 bg-surface-overlay shadow-control",
125
+ preview && "absolute right-2.5 top-2.5 surface-overlay shadow-control",
126
126
  classNames?.remove,
127
127
  )}
128
128
  >
@@ -35,7 +35,9 @@ export function groupByDate<T extends Dated>(
35
35
  const buckets = new Map<DateGroupId, T[]>();
36
36
  for (const item of items) {
37
37
  const id = groupOf(item.updatedAt, now);
38
- buckets.set(id, [...(buckets.get(id) ?? []), item]);
38
+ const bucket = buckets.get(id);
39
+ if (bucket) bucket.push(item);
40
+ else buckets.set(id, [item]);
39
41
  }
40
42
  return ORDER.flatMap((id) => {
41
43
  const list = buckets.get(id);
@@ -103,7 +103,7 @@ export function Conversation({
103
103
  toBottom(!reduced);
104
104
  }}
105
105
  className={cn(
106
- "absolute bottom-3 left-1/2 inline-flex h-control-sm -translate-x-1/2 cursor-pointer items-center gap-1.5 rounded-button bg-surface-overlay px-3 text-meta text-ink shadow-overlay border-control surface-overlay pressable focus-visible:focus-ring",
106
+ "absolute bottom-3 left-1/2 inline-flex h-control-sm -translate-x-1/2 cursor-pointer items-center gap-1.5 rounded-button px-3 text-meta text-ink shadow-overlay border-control surface-overlay pressable focus-visible:focus-ring",
107
107
  classNames?.jump,
108
108
  )}
109
109
  >
@@ -1,38 +1 @@
1
- "use client";
2
-
3
- import { useCallback, useEffect, useRef, useState } from "react";
4
-
5
- /** Copies text to the clipboard (with a textarea fallback) and flags success for `resetMs`. */
6
- export function useCopy(resetMs = 1600) {
7
- const [copied, setCopied] = useState(false);
8
- const timer = useRef<number | undefined>(undefined);
9
-
10
- useEffect(() => () => window.clearTimeout(timer.current), []);
11
-
12
- const copy = useCallback(
13
- async (text: string) => {
14
- try {
15
- await navigator.clipboard.writeText(text);
16
- } catch {
17
- const area = document.createElement("textarea");
18
- area.value = text;
19
- area.setAttribute("readonly", "");
20
- area.style.position = "fixed";
21
- area.style.opacity = "0";
22
- document.body.append(area);
23
- area.select();
24
- try {
25
- document.execCommand("copy");
26
- } finally {
27
- area.remove();
28
- }
29
- }
30
- setCopied(true);
31
- window.clearTimeout(timer.current);
32
- timer.current = window.setTimeout(() => setCopied(false), resetMs);
33
- },
34
- [resetMs],
35
- );
36
-
37
- return { copied, copy };
38
- }
1
+ export { useCopy } from "../../utils/use-copy.js";
@@ -41,10 +41,20 @@ export function safeHref(raw: string): string | null {
41
41
 
42
42
  const ESCAPABLE = /[\\`*_[\]()#+\-.!|>~]/;
43
43
 
44
+ /** Table columns beyond this are dropped, so cells stay bounded by rows x MAX_COLUMNS. */
45
+ const MAX_COLUMNS = 64;
46
+ const NO_INLINES: Inline[] = [];
47
+
48
+ /** Deeper blockquotes and list items are kept as literal text, so input cannot exhaust the stack. */
49
+ const MAX_NESTING = 32;
50
+ /** A link destination longer than this is not a link, which keeps the scan for `)` bounded. */
51
+ const MAX_LINK_TARGET = 1024;
52
+
44
53
  /** Index of the `)` that closes a link destination, honoring balanced inner parentheses. */
45
54
  function closingParen(src: string, from: number): number {
46
55
  let depth = 0;
47
- for (let i = from; i < src.length; i += 1) {
56
+ const stop = Math.min(src.length, from + MAX_LINK_TARGET);
57
+ for (let i = from; i < stop; i += 1) {
48
58
  if (src[i] === "(") depth += 1;
49
59
  else if (src[i] === ")") {
50
60
  if (depth === 0) return i;
@@ -62,6 +72,7 @@ export function parseInline(src: string): Inline[] {
62
72
  buf = "";
63
73
  };
64
74
  let i = 0;
75
+ let nextMid = -2;
65
76
  while (i < src.length) {
66
77
  const ch = src[i] as string;
67
78
  const next = src[i + 1];
@@ -105,7 +116,9 @@ export function parseInline(src: string): Inline[] {
105
116
  }
106
117
  }
107
118
  if (ch === "[") {
108
- const mid = src.indexOf("](", i + 1);
119
+ // The first "](" after any earlier "[" is still the first one after this "[" while it lies ahead.
120
+ if (nextMid !== -1 && nextMid <= i) nextMid = src.indexOf("](", i + 1);
121
+ const mid = nextMid;
109
122
  const end = mid > i ? closingParen(src, mid + 2) : -1;
110
123
  if (end > mid) {
111
124
  flush();
@@ -119,7 +132,9 @@ export function parseInline(src: string): Inline[] {
119
132
  }
120
133
  }
121
134
  if (ch === "\n") {
122
- buf = buf.replace(/ +$/, "");
135
+ let end = buf.length;
136
+ while (end > 0 && buf[end - 1] === " ") end -= 1;
137
+ buf = buf.slice(0, end);
123
138
  flush();
124
139
  out.push({ t: "br" });
125
140
  i += 1;
@@ -133,10 +148,31 @@ export function parseInline(src: string): Inline[] {
133
148
  }
134
149
 
135
150
  const FENCE = /^\s{0,3}(`{3,}|~{3,})\s*([\w+#.-]*)/;
136
- const HEADING = /^\s{0,3}(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/;
151
+ // Only space and tab count as whitespace here, and `s` lets `.` cross U+2028/U+2029: both keep matching linear.
152
+ const HEADING = /^[ \t]{0,3}(#{1,6})[ \t](.*)$/s;
153
+
154
+ /** Heading level and text; the optional closing `#` run is stripped in code to keep matching linear. */
155
+ function matchHeading(line: string): { level: 1 | 2 | 3 | 4 | 5 | 6; text: string } | null {
156
+ const m = HEADING.exec(line);
157
+ if (!m) return null;
158
+ let text = (m[2] as string).trim();
159
+ let end = text.length;
160
+ while (end > 0 && text[end - 1] === "#") end -= 1;
161
+ if (end > 0 && end < text.length && /\s/.test(text[end - 1] as string)) {
162
+ text = text.slice(0, end).trimEnd();
163
+ }
164
+ return { level: (m[1] as string).length as 1 | 2 | 3 | 4 | 5 | 6, text };
165
+ }
137
166
  const HR = /^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/;
138
- const ITEM = /^(\s*)([-*+]|\d{1,9}[.)])\s+(.*)$/;
139
- const TABLE_RULE = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;
167
+ const ITEM = /^([ \t]*)([-*+]|\d{1,9}[.)])[ \t]+(.*)$/s;
168
+ const TABLE_CELL_RULE = /^:?-+:?$/;
169
+
170
+ function isTableRule(line: string): boolean {
171
+ let row = line.trim();
172
+ if (row.startsWith("|")) row = row.slice(1);
173
+ if (row.endsWith("|")) row = row.slice(0, -1);
174
+ return row !== "" && row.split("|").every((cell) => TABLE_CELL_RULE.test(cell.trim()));
175
+ }
140
176
 
141
177
  function splitRow(line: string): string[] {
142
178
  let row = line.trim();
@@ -154,7 +190,7 @@ function alignOf(cell: string): TableAlign {
154
190
  }
155
191
 
156
192
  function isTableStart(line: string, next: string | undefined): boolean {
157
- return line.includes("|") && !!next?.includes("-") && TABLE_RULE.test(next);
193
+ return line.includes("|") && !!next?.includes("-") && isTableRule(next);
158
194
  }
159
195
 
160
196
  function startsBlock(line: string, next: string | undefined): boolean {
@@ -170,7 +206,23 @@ function startsBlock(line: string, next: string | undefined): boolean {
170
206
 
171
207
  /** Parses Markdown into blocks. An unclosed code fence runs to the end (streaming friendly). */
172
208
  export function parseMarkdown(src: string): Block[] {
209
+ return parseBlocks(src, 0);
210
+ }
211
+
212
+ function literal(src: string): Block[] {
213
+ return [{ t: "p", c: [{ t: "text", v: src }] }];
214
+ }
215
+
216
+ /** List markers indented past what the nesting cap can honor lose the excess, so deep input stays linear. */
217
+ const EXCESS_INDENT = new RegExp(`^\\s{${2 * MAX_NESTING + 4},}(?=([-*+]|\\d{1,9}[.)])\\s)`);
218
+
219
+ function parseBlocks(src: string, depth: number): Block[] {
173
220
  const lines = src.replace(/\r\n?/g, "\n").split("\n");
221
+ if (depth === 0) {
222
+ for (let n = 0; n < lines.length; n += 1) {
223
+ lines[n] = (lines[n] as string).replace(EXCESS_INDENT, " ".repeat(2 * MAX_NESTING + 4));
224
+ }
225
+ }
174
226
  const at = (n: number) => lines[n] as string;
175
227
  const blocks: Block[] = [];
176
228
  let i = 0;
@@ -195,13 +247,9 @@ export function parseMarkdown(src: string): Block[] {
195
247
  blocks.push({ t: "code", lang: fence[2] ?? "", v: body.join("\n") });
196
248
  continue;
197
249
  }
198
- const heading = HEADING.exec(line);
250
+ const heading = matchHeading(line);
199
251
  if (heading) {
200
- blocks.push({
201
- t: "heading",
202
- level: (heading[1] as string).length as 1 | 2 | 3 | 4 | 5 | 6,
203
- c: parseInline(heading[2] as string),
204
- });
252
+ blocks.push({ t: "heading", level: heading.level, c: parseInline(heading.text) });
205
253
  i += 1;
206
254
  continue;
207
255
  }
@@ -216,17 +264,25 @@ export function parseMarkdown(src: string): Block[] {
216
264
  body.push(at(i).replace(/^\s{0,3}>\s?/, ""));
217
265
  i += 1;
218
266
  }
219
- blocks.push({ t: "quote", c: parseMarkdown(body.join("\n")) });
267
+ const inner = body.join("\n");
268
+ blocks.push({
269
+ t: "quote",
270
+ c: depth >= MAX_NESTING ? literal(inner) : parseBlocks(inner, depth + 1),
271
+ });
220
272
  continue;
221
273
  }
222
274
  if (isTableStart(line, lines[i + 1])) {
223
- const head = splitRow(line);
275
+ const head = splitRow(line).slice(0, MAX_COLUMNS);
224
276
  const align = splitRow(at(i + 1)).map(alignOf);
225
277
  const rows: Inline[][][] = [];
226
278
  i += 2;
227
279
  while (i < lines.length && at(i).trim() && at(i).includes("|")) {
228
280
  const cells = splitRow(at(i));
229
- rows.push(head.map((_, col) => parseInline(cells[col] ?? "")));
281
+ rows.push(
282
+ head.map((_, col) =>
283
+ col < cells.length ? parseInline(cells[col] as string) : NO_INLINES,
284
+ ),
285
+ );
230
286
  i += 1;
231
287
  }
232
288
  blocks.push({
@@ -258,7 +314,8 @@ export function parseMarkdown(src: string): Block[] {
258
314
  }
259
315
  items.push({
260
316
  c: parseInline(current[3] as string),
261
- children: parseMarkdown(sub.join("\n")),
317
+ children:
318
+ depth >= MAX_NESTING ? literal(sub.join("\n")) : parseBlocks(sub.join("\n"), depth + 1),
262
319
  });
263
320
  }
264
321
  blocks.push({ t: "list", ordered, start, items });
@@ -91,7 +91,7 @@ export function Source({
91
91
  </HoverCardTrigger>
92
92
  <HoverCardContent
93
93
  className={cn(
94
- "@container/source w-72 max-w-[calc(100vw-1rem)] rounded-popover bg-surface-overlay p-3 text-ink shadow-overlay border-control surface-overlay",
94
+ "@container/source w-72 max-w-[calc(100vw-1rem)] rounded-popover p-3 text-ink shadow-overlay border-control surface-overlay",
95
95
  classNames?.card,
96
96
  )}
97
97
  >