@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,41 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Group, Panel, Separator, } from "react-resizable-panels";
5
+ import { cn } from "../lib/cn.js";
6
+ const OrientationContext = React.createContext("horizontal");
7
+ /**
8
+ * ResizablePanelGroup — split panes the user can resize: an editor beside its preview, a list
9
+ * beside its detail, a console under a canvas.
10
+ *
11
+ * Panels are divided by a 1px hairline that turns `--control-focus` on hover, drag and focus,
12
+ * with a hit area of at least 10px (20px on touch). Every handle is a keyboard separator: Tab to
13
+ * it, then arrow keys resize, Home/End jump to the limits and Enter collapses a collapsible panel.
14
+ *
15
+ * The rule people break: boxing every pane. The group is one region — put the material on the
16
+ * group (`surface-container`, or `surface-card` when it is an object) and let hairlines divide it.
17
+ * The group fills its parent, so give the parent (or the group) a height.
18
+ */
19
+ export function ResizablePanelGroup({ orientation = "horizontal", className, ...props }) {
20
+ return (_jsx(OrientationContext.Provider, { value: orientation, children: _jsx(Group, { "data-slot": "resizable-panel-group", "data-orientation": orientation, orientation: orientation, className: cn("h-full w-full", className), ...props }) }));
21
+ }
22
+ /**
23
+ * One pane. Sizes take numbers (pixels) or strings: `"30%"`, `"30"` (percent), `"240px"`, `"16rem"`.
24
+ * Give each panel an `id` when the layout is persisted with `defaultLayout`.
25
+ */
26
+ export function ResizablePanel({ className, ...props }) {
27
+ return _jsx(Panel, { "data-slot": "resizable-panel", className: cn("min-h-0 min-w-0", className), ...props });
28
+ }
29
+ /**
30
+ * The divider between two panels: a 1px hairline in `--border` that becomes `--control-focus`
31
+ * while hovered, dragged or focused. `withHandle` adds a tiny raised pill with mono dots — use it
32
+ * when the split is not obviously draggable (a narrow pane, a touch layout).
33
+ */
34
+ export function ResizableHandle({ withHandle = false, className, children, ...props }) {
35
+ const orientation = React.useContext(OrientationContext);
36
+ return (_jsxs(Separator, { "data-slot": "resizable-handle", "data-orientation": orientation, "aria-label": "Resize", className: cn("group/handle relative z-10 flex shrink-0 items-center justify-center bg-border outline-none", "transition-[background-color] duration-(--duration) ease-brand", orientation === "horizontal" ? "w-px self-stretch" : "h-px w-full", "data-[separator=active]:bg-control-focus data-[separator=focus]:bg-control-focus data-[separator=hover]:bg-control-focus",
37
+ // The visible line is 1px; the focus outline is drawn on a 3px band so it stays legible.
38
+ "focus-visible:outline-none focus-visible:after:absolute focus-visible:after:bg-control-focus focus-visible:after:content-['']", orientation === "horizontal"
39
+ ? "focus-visible:after:inset-y-0 focus-visible:after:left-1/2 focus-visible:after:w-[2px] focus-visible:after:-translate-x-1/2"
40
+ : "focus-visible:after:inset-x-0 focus-visible:after:top-1/2 focus-visible:after:h-[2px] focus-visible:after:-translate-y-1/2", "data-[separator=disabled]:opacity-50", className), ...props, children: [withHandle ? (_jsxs("span", { "data-slot": "resizable-grip", "aria-hidden": true, className: cn("pointer-events-none z-10 flex shrink-0 items-center justify-center gap-[3px] rounded-full bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-key", "transition-[background-color] duration-(--duration) ease-brand group-data-[separator=active]/handle:bg-control-hover group-data-[separator=hover]/handle:bg-control-hover", orientation === "horizontal" ? "h-6 w-3 flex-col" : "h-3 w-6 flex-row"), children: [_jsx("span", { className: "size-[3px] rounded-full bg-muted-foreground" }), _jsx("span", { className: "size-[3px] rounded-full bg-muted-foreground" }), _jsx("span", { className: "size-[3px] rounded-full bg-muted-foreground" })] })) : null, children] }));
41
+ }
@@ -0,0 +1,30 @@
1
+ import * as React from "react";
2
+ export interface ResponseProps extends Omit<React.ComponentProps<"div">, "children"> {
3
+ /** The reply, as markdown. */
4
+ children: string;
5
+ /** The reply is still arriving: unfinished markdown is closed as it would be, and it writes itself out evenly. */
6
+ streaming?: boolean;
7
+ /**
8
+ * Reveal the text at an even pace, a word at a time with each word coming into focus, instead
9
+ * of in the bursts it arrives in. Default `true`; off under reduced motion.
10
+ */
11
+ smooth?: boolean;
12
+ /**
13
+ * Colour fenced code by the language its fence names, in the zon theme. Needs a
14
+ * `CodeHighlightProvider` (from `@zonsh/ui/code-highlight`) above it; otherwise it stays mono.
15
+ */
16
+ highlight?: boolean;
17
+ }
18
+ /**
19
+ * Response — an assistant's reply, rendered from markdown in the brand's reading type: Licht Sans at
20
+ * 15px, Licht Light headings, mono inline code, hairline tables and rules, and fenced code as a
21
+ * `CodeBlock` — coloured by its language with `highlight`.
22
+ *
23
+ * While `streaming`, the reply writes itself out evenly at the pace it is arriving, a word at a
24
+ * time, each word coming into focus from a soft blur as it rises into place; half-written
25
+ * markdown renders as it will end up. Raw HTML in the markdown is shown as text, unsafe link
26
+ * targets are dropped and images become links, because model output is untrusted; a paragraph that
27
+ * would take the parser too long shows as plain text.
28
+ * The rule people break: rendering the reply with their own `dangerouslySetInnerHTML` and none of these rules.
29
+ */
30
+ export declare function Response({ children, streaming, smooth, highlight, className, ...props }: ResponseProps): React.JSX.Element;
@@ -0,0 +1,538 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Lexer, Marked } from "marked";
4
+ import * as React from "react";
5
+ import { cn } from "../lib/cn.js";
6
+ import { capNesting, overBudget } from "../lib/markdown-guard.js";
7
+ import { CodeBlock } from "./code-block.js";
8
+ /* ── Rendering ─────────────────────────────────────────────────────────────── */
9
+ const ESCAPES = {
10
+ "&": "&amp;",
11
+ "<": "&lt;",
12
+ ">": "&gt;",
13
+ '"': "&quot;",
14
+ "'": "&#39;",
15
+ };
16
+ const escapeHtml = (text) => text.replace(/[&<>"']/g, (c) => ESCAPES[c]);
17
+ /** Text as marked escapes it: `<>"'`, and any `&` that does not start an entity, so `&copy;` still shows ©. */
18
+ const escapeText = (text) => text.replace(/[<>"']|&(?!(?:#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, (c) => ESCAPES[c]);
19
+ /** Links a reply may carry: web, mail, in-page and relative. `javascript:`, `data:` and the rest are dropped. */
20
+ const SAFE_URL = /^(?:https?:|mailto:|#|\/(?!\/)|\.{1,2}\/)/i;
21
+ /**
22
+ * The URL a reply's link or image may point to, or null. A backslash, a space or a control
23
+ * character is refused outright: browsers read `/\evil.com` and `/<tab>/evil.com` as
24
+ * `//evil.com`, another site, which would slip past the same-site rule.
25
+ */
26
+ function safeUrl(href) {
27
+ // eslint-disable-next-line no-control-regex
28
+ if (/[\\\u0000- \u007f]/.test(href) || !SAFE_URL.test(href))
29
+ return null;
30
+ return href;
31
+ }
32
+ /*
33
+ * Model output is untrusted: it can repeat whatever was in the pages, files and prompts the model
34
+ * read, including text written to attack the app that shows it. Raw HTML in it is shown as text,
35
+ * links keep only safe URLs (external ones open in a new tab without an opener), and images become
36
+ * links, so a reply never loads a remote file — or sends data out in an image URL — on its own.
37
+ */
38
+ const markdown = new Marked({
39
+ gfm: true,
40
+ renderer: {
41
+ html({ text }) {
42
+ return escapeHtml(text);
43
+ },
44
+ // After an inline pre, code, kbd or script tag, marked passes the text on unescaped (its
45
+ // `escaped` flag): never trust it, or an img with an onerror later in the reply would run.
46
+ text(token) {
47
+ return "tokens" in token && token.tokens
48
+ ? this.parser.parseInline(token.tokens)
49
+ : escapeText(token.text);
50
+ },
51
+ link({ href, title, tokens }) {
52
+ const text = this.parser.parseInline(tokens);
53
+ const url = safeUrl(href);
54
+ if (!url)
55
+ return text;
56
+ const external = /^https?:/i.test(url);
57
+ return `<a href="${escapeHtml(url)}"${title ? ` title="${escapeHtml(title)}"` : ""}${external ? ' target="_blank" rel="noopener noreferrer"' : ""}>${text}</a>`;
58
+ },
59
+ image({ href, text, tokens }) {
60
+ // The alt text as plain text: its markdown read, its entities shown once.
61
+ const alt = tokens ? this.parser.parseInline(tokens, this.parser.textRenderer) : text;
62
+ const label = escapeText(alt || href);
63
+ const url = safeUrl(href);
64
+ if (!url)
65
+ return label;
66
+ return `<a href="${escapeHtml(url)}" target="_blank" rel="noopener noreferrer">${label}</a>`;
67
+ },
68
+ // Fenced code inside a list item or quote stays in this HTML and scrolls sideways: a tab stop,
69
+ // as CodeBlock's own `<pre>` is, so the keyboard can scroll it.
70
+ code({ text, lang }) {
71
+ const language = lang?.match(/^\S*/)?.[0];
72
+ const code = `${escapeHtml(text.replace(/\n$/, ""))}\n`;
73
+ return `<pre tabindex="0"><code${language ? ` class="language-${escapeHtml(language)}"` : ""}>${code}</code></pre>\n`;
74
+ },
75
+ // A task list item's box: the checkbox's own look (ai.css), named for what it says.
76
+ checkbox({ checked }) {
77
+ return `<input type="checkbox" disabled${checked ? ' checked aria-label="Done"' : ' aria-label="To do"'}> `;
78
+ },
79
+ },
80
+ extensions: [
81
+ {
82
+ // A paragraph (or a heading, a cell) the guard kept from the parser: the text as written,
83
+ // its line breaks kept.
84
+ name: "plain",
85
+ renderer: ({ text }) => escapeHtml(text).replace(/\n/g, "<br>"),
86
+ },
87
+ ],
88
+ });
89
+ /**
90
+ * marked's lexer, guarded: an inline run that would take the parser too long (lib/markdown-guard)
91
+ * is not parsed but kept whole, as one `plain` token. Any other run is lexed exactly as before.
92
+ * Only whole runs are judged — a paragraph, a heading, a cell — not the emphasis and link text
93
+ * marked lexes again inside them, which their run's estimate already counts.
94
+ */
95
+ class GuardedLexer extends Lexer {
96
+ depth = 0;
97
+ inlineTokens(src, tokens = []) {
98
+ if (this.depth === 0 && overBudget(src)) {
99
+ tokens.push({ type: "plain", raw: src, text: src });
100
+ return tokens;
101
+ }
102
+ this.depth++;
103
+ try {
104
+ return super.inlineTokens(src, tokens);
105
+ }
106
+ finally {
107
+ this.depth--;
108
+ }
109
+ }
110
+ }
111
+ /**
112
+ * A fence line, after what holds it: a quote's `>`, a list item's marker or indent. List markers
113
+ * count only when a space follows them.
114
+ */
115
+ const FENCE = /^((?:[ \t]*(?:>|(?:[-+*]|\d{1,9}[.)])(?=[ \t])))*[ \t]*)(`{3,}|~{3,})(.*)$/;
116
+ /** A fence's prefix as the lines inside it continue: a list marker becomes its width in spaces. */
117
+ const continuation = (prefix) => prefix.replace(/[-+*]|\d{1,9}[.)]/g, (m) => " ".repeat(m.length));
118
+ /** How far in a prefix reaches, quotes left out. */
119
+ const indentOf = (prefix) => continuation(prefix).replace(/>/g, "").replace(/\t/g, " ").length;
120
+ /**
121
+ * The code fence opened and not yet closed (with what continues its lines, to close it in the
122
+ * same list item or quote), and where the last closed one ends. A closer indented more than three
123
+ * columns past its opener is content, as in CommonMark.
124
+ */
125
+ function fences(text) {
126
+ let open = null;
127
+ let end = 0;
128
+ let offset = 0;
129
+ for (const line of text.split("\n")) {
130
+ const fence = FENCE.exec(line);
131
+ if (fence) {
132
+ const [, prefix = "", run = "", rest = ""] = fence;
133
+ if (!open) {
134
+ if (!(run[0] === "`" && rest.includes("`")))
135
+ open = { prefix: continuation(prefix), run, indent: indentOf(prefix) };
136
+ }
137
+ else if (run[0] === open.run[0] &&
138
+ run.length >= open.run.length &&
139
+ !rest.trim() &&
140
+ indentOf(prefix) <= open.indent + 3) {
141
+ open = null;
142
+ end = offset + line.length + 1;
143
+ }
144
+ }
145
+ offset += line.length + 1;
146
+ }
147
+ return { open, end };
148
+ }
149
+ /**
150
+ * A link or image whose URL is still arriving, `[text](https://exa`, as its text: what
151
+ * `/!?\[([^\]\n]*)\]\([^)\s]*$/` replaces with `$1`, found without a pattern that would backtrack
152
+ * over a long line on every frame.
153
+ */
154
+ function openLink(text) {
155
+ // The URL so far: the run at the end with no `)` or space in it, and no line break either.
156
+ let from = text.length;
157
+ while (from > 0 && !/[)\s]/.test(text[from - 1]))
158
+ from--;
159
+ const line = text.lastIndexOf("\n", from - 1);
160
+ for (let close = text.indexOf("](", from); close !== -1; close = text.indexOf("](", close + 1)) {
161
+ // Its text: from the first `[` after the last `]` or line break before it.
162
+ const start = Math.max(text.lastIndexOf("]", close - 1), line) + 1;
163
+ const open = text.slice(start, close).indexOf("[");
164
+ if (open === -1)
165
+ continue;
166
+ const at = start + open - (text[start + open - 1] === "!" ? 1 : 0);
167
+ return text.slice(0, at) + text.slice(start + open + 1, close);
168
+ }
169
+ return text;
170
+ }
171
+ /**
172
+ * A line of `-` or `=` under a line of text would make that line a heading: it is left out until
173
+ * what follows it arrives. What `/(\S[^\n]*\n[ \t>]*) {0,3}[-=]+[ \t]*$/` replaces with `$1`,
174
+ * without backtracking over a long line.
175
+ */
176
+ function underline(text) {
177
+ const cut = text.lastIndexOf("\n");
178
+ const rule = cut === -1 ? null : /^[ \t>]*(?=[-=]+[ \t]*$)/.exec(text.slice(cut + 1));
179
+ if (!rule || !/\S/.test(text.slice(text.lastIndexOf("\n", cut - 1) + 1, cut)))
180
+ return text;
181
+ return text.slice(0, cut + 1 + rule[0].length);
182
+ }
183
+ /** Puts a closing marker before any trailing space: `**word **` would not close. */
184
+ const close = (text, marker) => {
185
+ const space = /\s*$/.exec(text)[0];
186
+ return text.slice(0, text.length - space.length) + marker + space;
187
+ };
188
+ /**
189
+ * Closes what a reply cut off mid-stream would leave open, so it renders as it will look once
190
+ * finished: a code fence (with its own fence, dropping a closing one still being typed), a link or
191
+ * image whose URL is still arriving, an inline code span, bold and bold italic. A marker that has
192
+ * only just opened, with nothing after it yet — or a line of `-` that would turn the line above
193
+ * into a heading — is left out until what follows arrives: closing it at once would draw `****`,
194
+ * a rule or a heading.
195
+ */
196
+ function complete(text) {
197
+ const { open, end } = fences(text);
198
+ if (open) {
199
+ const partial = new RegExp(`\n[ \t>]*[${open.run[0]}]{1,${open.run.length}}$`);
200
+ const body = text.replace(partial, "");
201
+ return `${body}${body.endsWith("\n") ? "" : "\n"}${open.prefix}${open.run}`;
202
+ }
203
+ let out = underline(openLink(text).replace(/(^|[\s([{"'])(?:[*_]{1,3}`{0,2}|`{1,2})$/, "$1"));
204
+ // The paragraph being written — never reaching back into a code block that just closed.
205
+ const start = Math.max(out.lastIndexOf("\n\n") + 1, end);
206
+ if ((out.slice(start).match(/`/g)?.length ?? 0) % 2 === 1)
207
+ out += "`";
208
+ // Code spans stand in as a word: their `**` is literal, and bold around one still closes.
209
+ const plain = out.slice(start).replace(/`[^`]*`/g, "x");
210
+ // Bold and italic at once, opened and not closed yet, or its closer only half typed.
211
+ const both = /(^|\s)\*\*\*(?=\S)[^*]*?(\**)$/.exec(plain);
212
+ if (both && both[2].length < 3)
213
+ return close(out, "*".repeat(3 - both[2].length));
214
+ if ((plain.match(/\*\*/g)?.length ?? 0) % 2 === 1) {
215
+ // A single `*` at the end is half of the closer — unless it closes an italic of its own.
216
+ const singles = plain.replace(/\*\*/g, "").match(/\*/g)?.length ?? 0;
217
+ const half = /[^*]\*$/.test(plain) && singles % 2 === 1;
218
+ out = close(out, half ? "*" : "**");
219
+ }
220
+ return out;
221
+ }
222
+ /**
223
+ * One block per top-level token — a paragraph, a list, a table, a code fence — so that while a
224
+ * reply streams in only its last block is redrawn, and text above it stays put (and selectable).
225
+ *
226
+ * The blocks before the last two are final: while the reply grows, the next render keeps them and
227
+ * parses only the text after them, so a word costs as little at the end of a long reply as at its
228
+ * start. Not once the reply defines a link reference (`[a]: https://…`), which reaches back to the
229
+ * links above it: then all of it is parsed each time.
230
+ */
231
+ function render(source, live, parsed) {
232
+ try {
233
+ // Line breaks as marked reads them, so the tokens' text adds up to this one.
234
+ const text = capNesting((live ? complete(source) : source).replace(/\r\n?/g, "\n"));
235
+ const reuse = parsed.current && text.startsWith(parsed.current.text) ? parsed.current : null;
236
+ const from = reuse ? reuse.text.length : 0;
237
+ const tokens = new GuardedLexer(markdown.defaults).lex(text.slice(from));
238
+ const links = Object.keys(tokens.links).length > 0;
239
+ if (reuse && links) {
240
+ parsed.current = null;
241
+ return render(source, live, parsed);
242
+ }
243
+ const blocks = reuse ? reuse.blocks.slice() : [];
244
+ const settled = tokens.length - 2;
245
+ let covered = from;
246
+ let kept = blocks.length;
247
+ tokens.forEach((token, i) => {
248
+ if (token.type === "code") {
249
+ const code = token;
250
+ blocks.push({ kind: "code", text: code.text, lang: code.lang || undefined });
251
+ }
252
+ else if (token.type !== "space") {
253
+ const html = markdown.parser([token]);
254
+ if (html.trim())
255
+ blocks.push({ kind: "html", html, table: token.type === "table" });
256
+ }
257
+ if (i < settled) {
258
+ covered += token.raw.length;
259
+ kept = blocks.length;
260
+ }
261
+ });
262
+ parsed.current = links ? null : { text: text.slice(0, covered), blocks: blocks.slice(0, kept) };
263
+ return blocks;
264
+ }
265
+ catch {
266
+ parsed.current = null;
267
+ // Should the parser fail anyway (the guard keeps nesting shallow, but this is model output):
268
+ // the reply as plain text, rather than an error that takes the conversation down with it.
269
+ return [{ kind: "html", html: `<p>${escapeHtml(source).replace(/\n/g, "<br>")}</p>`, table: false }];
270
+ }
271
+ }
272
+ /** A code block redraws only when its own code changes, not on every frame of the text after it. */
273
+ const ResponseCode = React.memo(CodeBlock);
274
+ /* ── The paced reveal ──────────────────────────────────────────────────────── */
275
+ /*
276
+ * Models stream in bursts: forty characters, a pause, eighty more. Shown as they arrive, the text
277
+ * jerks. Instead the reply is revealed at an even pace on every frame — the pace the text has been
278
+ * arriving at (an average of the last bursts) plus a share of whatever is waiting, so it never
279
+ * falls far behind — a whole word at a time. Each new word comes into focus: from transparent,
280
+ * blurred and a little low, to sharp and in place, over BLUR_MS. When the stream ends, what is
281
+ * left is revealed quickly.
282
+ *
283
+ * The timing follows what is on screen, not the markdown source: after every frame that drew
284
+ * more, it notes how many visible characters there are and when. Syntax (`**`, `|`, a code
285
+ * fence) and code blocks, which take no part, never make a word that is already there come in again.
286
+ */
287
+ /** How long a new word takes to come into focus. */
288
+ const BLUR_MS = 520;
289
+ /** At most this many trailing characters take part; any before them show settled. */
290
+ const BLUR_CHARS = 360;
291
+ /** The slowest pace, in characters per second, so a slow stream still flows. */
292
+ const MIN_PACE = 32;
293
+ const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
294
+ const commonPrefix = (a, b) => {
295
+ let i = 0;
296
+ while (i < a.length && i < b.length && a[i] === b[i])
297
+ i++;
298
+ return i;
299
+ };
300
+ /** How many characters of a text the reveal counts: spaces are left out. */
301
+ const visibleLength = (text) => text.replace(/\s/g, "").length;
302
+ const smoothstep = (t) => t * t * (3 - 2 * t);
303
+ const graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl
304
+ ? new Intl.Segmenter(undefined, { granularity: "grapheme" })
305
+ : null;
306
+ /** Where the character (grapheme) that `index` falls in starts: an emoji or an accented letter stays whole. */
307
+ function graphemeStart(text, index) {
308
+ if (graphemeSegmenter)
309
+ return graphemeSegmenter.segment(text).containing(index)?.index ?? index;
310
+ const code = text.charCodeAt(index);
311
+ return code >= 0xdc00 && code <= 0xdfff ? index - 1 : index;
312
+ }
313
+ /**
314
+ * The text nodes the reveal may touch, in order: only the markdown's, which this component writes
315
+ * as HTML and owns. Code blocks are React's own nodes; splitting them would duplicate text on the next update.
316
+ */
317
+ function textNodes(root) {
318
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
319
+ acceptNode: (node) => {
320
+ if (!node.parentElement?.closest('[data-slot="response-markdown"]'))
321
+ return NodeFilter.FILTER_REJECT;
322
+ return /\S/.test(node.data) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
323
+ },
324
+ });
325
+ const nodes = [];
326
+ while (walker.nextNode())
327
+ nodes.push(walker.currentNode);
328
+ return nodes;
329
+ }
330
+ /** Puts back the text a previous frame wrapped, where the markup did not change since. */
331
+ function unwrapWords(root) {
332
+ const parents = new Set();
333
+ for (const span of root.querySelectorAll("[data-word]")) {
334
+ if (span.parentNode)
335
+ parents.add(span.parentNode);
336
+ span.replaceWith(...span.childNodes);
337
+ }
338
+ for (const parent of parents)
339
+ parent.normalize();
340
+ }
341
+ /** Wraps each word that ends after visible position `from` in a span, newest first. Spaces stay unwrapped. */
342
+ function wrapWords(nodes, total, from) {
343
+ const words = [];
344
+ let end = total;
345
+ for (let k = nodes.length - 1; k >= 0 && end > from; k--) {
346
+ const node = nodes[k];
347
+ // The node's words, last first: a run of non-space characters each.
348
+ const runs = [...node.data.matchAll(/\S+/g)];
349
+ for (let j = runs.length - 1; j >= 0 && end > from; j--) {
350
+ const run = runs[j];
351
+ node.splitText(run.index + run[0].length);
352
+ const piece = node.splitText(run.index);
353
+ const span = document.createElement("span");
354
+ span.setAttribute("data-word", "");
355
+ piece.replaceWith(span);
356
+ span.append(piece);
357
+ words.push({ span, end });
358
+ end -= visibleLength(run[0]);
359
+ }
360
+ }
361
+ return words;
362
+ }
363
+ /**
364
+ * Response — an assistant's reply, rendered from markdown in the brand's reading type: Licht Sans at
365
+ * 15px, Licht Light headings, mono inline code, hairline tables and rules, and fenced code as a
366
+ * `CodeBlock` — coloured by its language with `highlight`.
367
+ *
368
+ * While `streaming`, the reply writes itself out evenly at the pace it is arriving, a word at a
369
+ * time, each word coming into focus from a soft blur as it rises into place; half-written
370
+ * markdown renders as it will end up. Raw HTML in the markdown is shown as text, unsafe link
371
+ * targets are dropped and images become links, because model output is untrusted; a paragraph that
372
+ * would take the parser too long shows as plain text.
373
+ * The rule people break: rendering the reply with their own `dangerouslySetInnerHTML` and none of these rules.
374
+ */
375
+ export function Response({ children, streaming = false, smooth = true, highlight = false, className, ...props }) {
376
+ const root = React.useRef(null);
377
+ const [shown, setShown] = React.useState(children.length);
378
+ const pace = React.useRef({
379
+ shown: children.length,
380
+ text: children,
381
+ streaming,
382
+ rate: 0,
383
+ arrivedAt: 0,
384
+ stamps: [],
385
+ settled: -1,
386
+ frame: 0,
387
+ last: 0,
388
+ });
389
+ const words = React.useRef([]);
390
+ /** What the last render parsed: kept, and grown from, while the reply grows. */
391
+ const parsed = React.useRef(null);
392
+ const paced = smooth && !reducedMotion();
393
+ /** Draws each new word for the time since it appeared. */
394
+ const paint = React.useCallback((now) => {
395
+ const { stamps, settled } = pace.current;
396
+ // Words run newest first and stamps oldest first: walk the stamps back alongside.
397
+ let s = stamps.length - 1;
398
+ for (const { span, end } of words.current) {
399
+ while (s > 0 && stamps[s - 1].count >= end)
400
+ s--;
401
+ const at = end > settled && s >= 0 && stamps[s].count >= end ? stamps[s].at : undefined;
402
+ const e = at == null ? 1 : smoothstep(Math.min(1, (now - at) / BLUR_MS));
403
+ const style = span.style;
404
+ if (e >= 1) {
405
+ style.cssText = "";
406
+ continue;
407
+ }
408
+ style.opacity = String(e);
409
+ style.filter = `blur(${((1 - e) * 5).toFixed(2)}px)`;
410
+ // Relative, so the rise works on an inline word without breaking how the line wraps.
411
+ style.position = "relative";
412
+ style.top = `${((1 - e) * 0.3).toFixed(3)}em`;
413
+ }
414
+ }, []);
415
+ const tick = React.useCallback((now) => {
416
+ const p = pace.current;
417
+ const dt = Math.min(0.05, (now - (p.last || now)) / 1000);
418
+ p.last = now;
419
+ const target = p.text.length;
420
+ if (p.shown < target) {
421
+ const backlog = target - p.shown;
422
+ const speed = p.streaming
423
+ ? Math.max(MIN_PACE, p.rate * 0.95 + backlog * 2.2)
424
+ : Math.max(MIN_PACE * 4, backlog * 6);
425
+ const before = Math.floor(p.shown);
426
+ p.shown = Math.min(target, p.shown + speed * dt);
427
+ const after = Math.floor(p.shown);
428
+ if (after !== before)
429
+ setShown(after);
430
+ }
431
+ while (p.stamps.length && now - p.stamps[0].at >= BLUR_MS)
432
+ p.settled = Math.max(p.settled, p.stamps.shift().count);
433
+ paint(now);
434
+ if (p.shown < target || p.stamps.length) {
435
+ p.frame = requestAnimationFrame(tick);
436
+ return;
437
+ }
438
+ p.frame = 0;
439
+ p.last = 0;
440
+ // All in focus: put the text back as it was written, without the reveal's spans.
441
+ if (root.current && words.current.length)
442
+ unwrapWords(root.current);
443
+ words.current = [];
444
+ }, [paint]);
445
+ const run = React.useCallback(() => {
446
+ const p = pace.current;
447
+ if (p.frame)
448
+ return;
449
+ p.last = 0;
450
+ p.frame = requestAnimationFrame(tick);
451
+ }, [tick]);
452
+ // New text: learn the pace it arrives at, and keep the reveal running.
453
+ React.useEffect(() => {
454
+ const p = pace.current;
455
+ p.streaming = streaming;
456
+ const previous = p.text;
457
+ p.text = children;
458
+ if (!paced) {
459
+ p.shown = children.length;
460
+ setShown(children.length);
461
+ return;
462
+ }
463
+ const now = performance.now();
464
+ if (!children.startsWith(previous)) {
465
+ // Not a continuation (a new reply, a regenerated one): start again from what they share,
466
+ // which is already written.
467
+ p.shown = Math.min(p.shown, commonPrefix(previous, children));
468
+ p.stamps = [];
469
+ p.settled = -1;
470
+ p.rate = 0;
471
+ setShown(Math.floor(p.shown));
472
+ }
473
+ else if (children.length > previous.length) {
474
+ const added = children.length - previous.length;
475
+ const since = p.arrivedAt ? (now - p.arrivedAt) / 1000 : 0.25;
476
+ const instant = added / Math.max(0.03, since);
477
+ p.rate = p.rate ? p.rate * 0.7 + instant * 0.3 : instant;
478
+ }
479
+ p.arrivedAt = now;
480
+ if (p.shown < children.length)
481
+ run();
482
+ }, [children, streaming, paced, run]);
483
+ React.useEffect(() => () => {
484
+ const p = pace.current;
485
+ cancelAnimationFrame(p.frame);
486
+ p.frame = 0;
487
+ }, []);
488
+ // A text that does not continue the last one shows only what they share until the reveal catches up.
489
+ const previous = pace.current.text;
490
+ let limit = children.startsWith(previous) ? shown : Math.min(shown, commonPrefix(previous, children));
491
+ if (limit < children.length) {
492
+ // Whole words: up to the last space, never into a word (nor half an emoji).
493
+ limit = Math.max(0, children.slice(0, graphemeStart(children, limit)).search(/\s\S*$/));
494
+ }
495
+ const visible = paced ? children.slice(0, limit) : children;
496
+ const live = streaming || visible.length < children.length;
497
+ const blocks = React.useMemo(() => render(visible, live, parsed), [visible, live]);
498
+ // After each render: count what is on screen, stamp what is new, wrap the new words and paint them.
499
+ React.useLayoutEffect(() => {
500
+ const el = root.current;
501
+ if (!el)
502
+ return;
503
+ const p = pace.current;
504
+ if (words.current.length)
505
+ unwrapWords(el);
506
+ words.current = [];
507
+ if (!paced) {
508
+ p.stamps = [];
509
+ p.settled = -1;
510
+ return;
511
+ }
512
+ const nodes = textNodes(el);
513
+ let total = 0;
514
+ for (const node of nodes)
515
+ total += visibleLength(node.data);
516
+ const drawn = p.stamps.at(-1)?.count ?? p.settled;
517
+ // The first frame counted: what is there is already written.
518
+ if (p.settled < 0)
519
+ p.settled = total;
520
+ else if (total > drawn)
521
+ p.stamps.push({ count: total, at: performance.now() });
522
+ else if (total < drawn) {
523
+ // The markup drew shorter (a row of pipes became a table): keep the clock in step.
524
+ for (const stamp of p.stamps)
525
+ stamp.count = Math.min(stamp.count, total);
526
+ p.settled = Math.min(p.settled, total);
527
+ }
528
+ if (!p.stamps.length)
529
+ return;
530
+ words.current = wrapWords(nodes, total, Math.max(p.settled, total - BLUR_CHARS));
531
+ paint(performance.now());
532
+ run();
533
+ });
534
+ return (_jsx("div", { ref: root, "data-slot": "response", "data-streaming": live ? "" : undefined, "aria-busy": live || undefined, className: cn("min-w-0 text-[15px] leading-relaxed text-foreground-soft", className), ...props, children: blocks.map((block, index) => block.kind === "code" ? (_jsx(ResponseCode, { code: block.text, language: block.lang, highlight: highlight, className: "my-4 first:mt-0 last:mb-0" }, index)) : (_jsx("div", { "data-slot": "response-markdown", "data-table": block.table ? "" : undefined,
535
+ // A table is a block of its own that scrolls sideways when it is wider than the reply,
536
+ // so its cells never break inside a word. Focusable, so the keyboard can scroll it.
537
+ tabIndex: block.table ? 0 : undefined, className: block.table ? "focus-ring" : "contents", dangerouslySetInnerHTML: { __html: block.html } }, index))) }));
538
+ }
@@ -0,0 +1,33 @@
1
+ import { ScrollArea as BaseScrollArea } from "@base-ui/react/scroll-area";
2
+ export interface ScrollAreaProps extends BaseScrollArea.Root.Props {
3
+ /** Which scrollbars to render. Defaults to `vertical`. */
4
+ orientation?: "vertical" | "horizontal" | "both";
5
+ /** Fade the content out at edges that have more to scroll. Defaults to `true`. */
6
+ fade?: boolean;
7
+ /**
8
+ * Draw the scrollbar. Defaults to `true`. Sidebars pass `false`: they scroll without a bar,
9
+ * and the edge fade says there is more.
10
+ */
11
+ scrollbar?: boolean;
12
+ /** Class for the scrolling viewport (padding usually goes on the content instead). */
13
+ viewportClassName?: string;
14
+ /** Class for the content wrapper inside the viewport. */
15
+ contentClassName?: string;
16
+ /**
17
+ * Render the viewport as another part, so that part is the element that scrolls: a Select,
18
+ * Combobox or Autocomplete list, which scrolls its highlighted item into view itself. Give it
19
+ * `data-has-overflow-y:pr-3` so its rows stop beside the bar instead of running under it.
20
+ */
21
+ viewportRender?: BaseScrollArea.Viewport.Props["render"];
22
+ }
23
+ /**
24
+ * ScrollArea — a scrolling region with a thin, quiet scrollbar.
25
+ *
26
+ * The thumb is a 4px round bar in `--field-edge` that appears while the pointer is over the
27
+ * area or while scrolling. Edges with more content fade out using Base UI's overflow CSS
28
+ * variables, so the fade grows as you scroll away from an edge. The rule people break:
29
+ * nesting scroll areas or putting the main page in one. Let the page scroll natively; use
30
+ * this for bounded panels (a sidebar, a code listing, a long select). Sidebars never show a
31
+ * scrollbar: pass `scrollbar={false}`.
32
+ */
33
+ export declare function ScrollArea({ orientation, fade, scrollbar, viewportClassName, contentClassName, viewportRender, className, children, ...props }: ScrollAreaProps): import("react").JSX.Element;