@derelicious/ds 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 (579) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE +21 -0
  3. package/README.md +147 -2
  4. package/dist/a2ui/Surface.css +140 -0
  5. package/dist/a2ui/Surface.css.d.ts +22 -0
  6. package/dist/a2ui/Surface.css.js +29 -0
  7. package/dist/a2ui/Surface.d.ts +56 -0
  8. package/dist/a2ui/Surface.js +1411 -0
  9. package/dist/a2ui/catalog.d.ts +93 -0
  10. package/dist/a2ui/catalog.js +1666 -0
  11. package/dist/a2ui/clientMessages.d.ts +36 -0
  12. package/dist/a2ui/clientMessages.js +65 -0
  13. package/dist/a2ui/examples.d.ts +8 -0
  14. package/dist/a2ui/examples.js +877 -0
  15. package/dist/a2ui/functions.d.ts +55 -0
  16. package/dist/a2ui/functions.js +341 -0
  17. package/dist/a2ui/ids.d.ts +5 -0
  18. package/dist/a2ui/ids.js +7 -0
  19. package/dist/a2ui/index.d.ts +16 -0
  20. package/dist/a2ui/index.js +12 -0
  21. package/dist/a2ui/jsonl.d.ts +41 -0
  22. package/dist/a2ui/jsonl.js +127 -0
  23. package/dist/a2ui/links.d.ts +17 -0
  24. package/dist/a2ui/links.js +29 -0
  25. package/dist/a2ui/pointer.d.ts +22 -0
  26. package/dist/a2ui/pointer.js +85 -0
  27. package/dist/a2ui/processor.d.ts +126 -0
  28. package/dist/a2ui/processor.js +497 -0
  29. package/dist/a2ui/react.d.ts +2 -0
  30. package/dist/a2ui/react.js +1 -0
  31. package/dist/a2ui/toTsx.d.ts +9 -0
  32. package/dist/a2ui/toTsx.js +1389 -0
  33. package/dist/a2ui/types.d.ts +96 -0
  34. package/dist/a2ui/validate.d.ts +90 -0
  35. package/dist/a2ui/validate.js +750 -0
  36. package/dist/a2ui-catalog.json +4369 -0
  37. package/dist/a2ui-conformance.json +71 -0
  38. package/dist/components/Accordion/Accordion.css +58 -0
  39. package/dist/components/Accordion/Accordion.css.d.ts +5 -0
  40. package/dist/components/Accordion/Accordion.css.js +10 -0
  41. package/dist/components/Accordion/Accordion.d.ts +23 -0
  42. package/dist/components/Accordion/Accordion.docs.d.ts +19 -0
  43. package/dist/components/Accordion/Accordion.docs.js +43 -0
  44. package/dist/components/Accordion/Accordion.js +55 -0
  45. package/dist/components/Accordion/index.d.ts +1 -0
  46. package/dist/components/Accordion/index.js +1 -0
  47. package/dist/components/AiLabel/AiLabel.css +70 -0
  48. package/dist/components/AiLabel/AiLabel.css.d.ts +8 -0
  49. package/dist/components/AiLabel/AiLabel.css.js +11 -0
  50. package/dist/components/AiLabel/AiLabel.d.ts +29 -0
  51. package/dist/components/AiLabel/AiLabel.docs.d.ts +19 -0
  52. package/dist/components/AiLabel/AiLabel.docs.js +51 -0
  53. package/dist/components/AiLabel/AiLabel.js +41 -0
  54. package/dist/components/AiLabel/index.d.ts +1 -0
  55. package/dist/components/AiLabel/index.js +1 -0
  56. package/dist/components/Alert/Alert.css +76 -0
  57. package/dist/components/Alert/Alert.css.d.ts +9 -0
  58. package/dist/components/Alert/Alert.css.js +23 -0
  59. package/dist/components/Alert/Alert.d.ts +21 -0
  60. package/dist/components/Alert/Alert.docs.d.ts +19 -0
  61. package/dist/components/Alert/Alert.docs.js +57 -0
  62. package/dist/components/Alert/Alert.js +55 -0
  63. package/dist/components/Alert/index.d.ts +1 -0
  64. package/dist/components/Alert/index.js +1 -0
  65. package/dist/components/Avatar/Avatar.css +42 -0
  66. package/dist/components/Avatar/Avatar.css.d.ts +3 -0
  67. package/dist/components/Avatar/Avatar.css.js +12 -0
  68. package/dist/components/Avatar/Avatar.d.ts +13 -0
  69. package/dist/components/Avatar/Avatar.docs.d.ts +19 -0
  70. package/dist/components/Avatar/Avatar.docs.js +43 -0
  71. package/dist/components/Avatar/Avatar.js +31 -0
  72. package/dist/components/Avatar/index.d.ts +1 -0
  73. package/dist/components/Avatar/index.js +1 -0
  74. package/dist/components/Avatar/initials.d.ts +2 -0
  75. package/dist/components/Avatar/initials.js +8 -0
  76. package/dist/components/Badge/Badge.css +63 -0
  77. package/dist/components/Badge/Badge.css.d.ts +5 -0
  78. package/dist/components/Badge/Badge.css.js +16 -0
  79. package/dist/components/Badge/Badge.d.ts +15 -0
  80. package/dist/components/Badge/Badge.docs.d.ts +19 -0
  81. package/dist/components/Badge/Badge.docs.js +52 -0
  82. package/dist/components/Badge/Badge.js +24 -0
  83. package/dist/components/Badge/index.d.ts +1 -0
  84. package/dist/components/Badge/index.js +1 -0
  85. package/dist/components/Breadcrumbs/Breadcrumbs.css +40 -0
  86. package/dist/components/Breadcrumbs/Breadcrumbs.css.d.ts +5 -0
  87. package/dist/components/Breadcrumbs/Breadcrumbs.css.js +10 -0
  88. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +17 -0
  89. package/dist/components/Breadcrumbs/Breadcrumbs.docs.d.ts +19 -0
  90. package/dist/components/Breadcrumbs/Breadcrumbs.docs.js +38 -0
  91. package/dist/components/Breadcrumbs/Breadcrumbs.js +48 -0
  92. package/dist/components/Breadcrumbs/index.d.ts +1 -0
  93. package/dist/components/Breadcrumbs/index.js +1 -0
  94. package/dist/components/Button/Button.css +101 -0
  95. package/dist/components/Button/Button.css.d.ts +72 -0
  96. package/dist/components/Button/Button.css.js +35 -0
  97. package/dist/components/Button/Button.d.ts +53 -0
  98. package/dist/components/Button/Button.docs.d.ts +19 -0
  99. package/dist/components/Button/Button.docs.js +71 -0
  100. package/dist/components/Button/Button.js +68 -0
  101. package/dist/components/Button/index.d.ts +1 -0
  102. package/dist/components/Button/index.js +1 -0
  103. package/dist/components/Card/Card.css +122 -0
  104. package/dist/components/Card/Card.css.d.ts +12 -0
  105. package/dist/components/Card/Card.css.js +25 -0
  106. package/dist/components/Card/Card.d.ts +306 -0
  107. package/dist/components/Card/Card.docs.d.ts +19 -0
  108. package/dist/components/Card/Card.docs.js +65 -0
  109. package/dist/components/Card/Card.js +53 -0
  110. package/dist/components/Card/index.d.ts +1 -0
  111. package/dist/components/Card/index.js +1 -0
  112. package/dist/components/ChatMessage/ChatMessage.css +56 -0
  113. package/dist/components/ChatMessage/ChatMessage.css.d.ts +7 -0
  114. package/dist/components/ChatMessage/ChatMessage.css.js +15 -0
  115. package/dist/components/ChatMessage/ChatMessage.d.ts +35 -0
  116. package/dist/components/ChatMessage/ChatMessage.docs.d.ts +19 -0
  117. package/dist/components/ChatMessage/ChatMessage.docs.js +45 -0
  118. package/dist/components/ChatMessage/ChatMessage.js +49 -0
  119. package/dist/components/ChatMessage/index.d.ts +1 -0
  120. package/dist/components/ChatMessage/index.js +1 -0
  121. package/dist/components/Checkbox/Checkbox.css +70 -0
  122. package/dist/components/Checkbox/Checkbox.css.d.ts +1 -0
  123. package/dist/components/Checkbox/Checkbox.css.js +6 -0
  124. package/dist/components/Checkbox/Checkbox.d.ts +28 -0
  125. package/dist/components/Checkbox/Checkbox.docs.d.ts +19 -0
  126. package/dist/components/Checkbox/Checkbox.docs.js +53 -0
  127. package/dist/components/Checkbox/Checkbox.js +63 -0
  128. package/dist/components/Checkbox/index.d.ts +1 -0
  129. package/dist/components/Checkbox/index.js +1 -0
  130. package/dist/components/Code/Code.css +12 -0
  131. package/dist/components/Code/Code.css.d.ts +1 -0
  132. package/dist/components/Code/Code.css.js +5 -0
  133. package/dist/components/Code/Code.d.ts +7 -0
  134. package/dist/components/Code/Code.docs.d.ts +19 -0
  135. package/dist/components/Code/Code.docs.js +26 -0
  136. package/dist/components/Code/Code.js +12 -0
  137. package/dist/components/Code/index.d.ts +1 -0
  138. package/dist/components/Code/index.js +1 -0
  139. package/dist/components/CodeBlock/CodeBlock.css +76 -0
  140. package/dist/components/CodeBlock/CodeBlock.css.d.ts +12 -0
  141. package/dist/components/CodeBlock/CodeBlock.css.js +21 -0
  142. package/dist/components/CodeBlock/CodeBlock.d.ts +19 -0
  143. package/dist/components/CodeBlock/CodeBlock.docs.d.ts +19 -0
  144. package/dist/components/CodeBlock/CodeBlock.docs.js +47 -0
  145. package/dist/components/CodeBlock/CodeBlock.js +82 -0
  146. package/dist/components/CodeBlock/highlight.d.ts +28 -0
  147. package/dist/components/CodeBlock/highlight.js +118 -0
  148. package/dist/components/CodeBlock/index.d.ts +1 -0
  149. package/dist/components/CodeBlock/index.js +1 -0
  150. package/dist/components/Container/Container.css +21 -0
  151. package/dist/components/Container/Container.css.d.ts +3 -0
  152. package/dist/components/Container/Container.css.js +12 -0
  153. package/dist/components/Container/Container.d.ts +295 -0
  154. package/dist/components/Container/Container.docs.d.ts +19 -0
  155. package/dist/components/Container/Container.docs.js +31 -0
  156. package/dist/components/Container/Container.js +12 -0
  157. package/dist/components/Container/index.d.ts +1 -0
  158. package/dist/components/Container/index.js +1 -0
  159. package/dist/components/Dialog/Dialog.css +94 -0
  160. package/dist/components/Dialog/Dialog.css.d.ts +9 -0
  161. package/dist/components/Dialog/Dialog.css.js +17 -0
  162. package/dist/components/Dialog/Dialog.d.ts +29 -0
  163. package/dist/components/Dialog/Dialog.docs.d.ts +19 -0
  164. package/dist/components/Dialog/Dialog.docs.js +50 -0
  165. package/dist/components/Dialog/Dialog.js +90 -0
  166. package/dist/components/Dialog/index.d.ts +1 -0
  167. package/dist/components/Dialog/index.js +1 -0
  168. package/dist/components/Divider/Divider.css +41 -0
  169. package/dist/components/Divider/Divider.css.d.ts +6 -0
  170. package/dist/components/Divider/Divider.css.js +16 -0
  171. package/dist/components/Divider/Divider.d.ts +11 -0
  172. package/dist/components/Divider/Divider.docs.d.ts +19 -0
  173. package/dist/components/Divider/Divider.docs.js +43 -0
  174. package/dist/components/Divider/Divider.js +30 -0
  175. package/dist/components/Divider/index.d.ts +1 -0
  176. package/dist/components/Divider/index.js +1 -0
  177. package/dist/components/Grid/Grid.css +11 -0
  178. package/dist/components/Grid/Grid.css.d.ts +8 -0
  179. package/dist/components/Grid/Grid.css.js +8 -0
  180. package/dist/components/Grid/Grid.d.ts +18 -0
  181. package/dist/components/Grid/Grid.docs.d.ts +19 -0
  182. package/dist/components/Grid/Grid.docs.js +41 -0
  183. package/dist/components/Grid/Grid.js +22 -0
  184. package/dist/components/Grid/index.d.ts +1 -0
  185. package/dist/components/Grid/index.js +1 -0
  186. package/dist/components/Heading/Heading.css +44 -0
  187. package/dist/components/Heading/Heading.css.d.ts +3 -0
  188. package/dist/components/Heading/Heading.css.js +17 -0
  189. package/dist/components/Heading/Heading.d.ts +298 -0
  190. package/dist/components/Heading/Heading.docs.d.ts +19 -0
  191. package/dist/components/Heading/Heading.docs.js +48 -0
  192. package/dist/components/Heading/Heading.js +20 -0
  193. package/dist/components/Heading/index.d.ts +1 -0
  194. package/dist/components/Heading/index.js +1 -0
  195. package/dist/components/Icon/Icon.css +25 -0
  196. package/dist/components/Icon/Icon.css.d.ts +4 -0
  197. package/dist/components/Icon/Icon.css.js +13 -0
  198. package/dist/components/Icon/Icon.d.ts +16 -0
  199. package/dist/components/Icon/Icon.docs.d.ts +19 -0
  200. package/dist/components/Icon/Icon.docs.js +56 -0
  201. package/dist/components/Icon/Icon.js +25 -0
  202. package/dist/components/Icon/index.d.ts +1 -0
  203. package/dist/components/Icon/index.js +1 -0
  204. package/dist/components/IconButton/IconButton.css +70 -0
  205. package/dist/components/IconButton/IconButton.css.d.ts +57 -0
  206. package/dist/components/IconButton/IconButton.css.js +27 -0
  207. package/dist/components/IconButton/IconButton.d.ts +46 -0
  208. package/dist/components/IconButton/IconButton.docs.d.ts +19 -0
  209. package/dist/components/IconButton/IconButton.docs.js +48 -0
  210. package/dist/components/IconButton/IconButton.js +44 -0
  211. package/dist/components/IconButton/index.d.ts +1 -0
  212. package/dist/components/IconButton/index.js +1 -0
  213. package/dist/components/Image/Image.css +53 -0
  214. package/dist/components/Image/Image.css.d.ts +7 -0
  215. package/dist/components/Image/Image.css.js +18 -0
  216. package/dist/components/Image/Image.d.ts +23 -0
  217. package/dist/components/Image/Image.docs.d.ts +19 -0
  218. package/dist/components/Image/Image.docs.js +48 -0
  219. package/dist/components/Image/Image.js +75 -0
  220. package/dist/components/Image/index.d.ts +1 -0
  221. package/dist/components/Image/index.js +1 -0
  222. package/dist/components/Inline/Inline.css +38 -0
  223. package/dist/components/Inline/Inline.css.d.ts +4 -0
  224. package/dist/components/Inline/Inline.css.js +18 -0
  225. package/dist/components/Inline/Inline.d.ts +300 -0
  226. package/dist/components/Inline/Inline.docs.d.ts +19 -0
  227. package/dist/components/Inline/Inline.docs.js +48 -0
  228. package/dist/components/Inline/Inline.js +13 -0
  229. package/dist/components/Inline/index.d.ts +1 -0
  230. package/dist/components/Inline/index.js +1 -0
  231. package/dist/components/Link/Link.css +57 -0
  232. package/dist/components/Link/Link.css.d.ts +5 -0
  233. package/dist/components/Link/Link.css.js +14 -0
  234. package/dist/components/Link/Link.d.ts +19 -0
  235. package/dist/components/Link/Link.docs.d.ts +19 -0
  236. package/dist/components/Link/Link.docs.js +51 -0
  237. package/dist/components/Link/Link.js +39 -0
  238. package/dist/components/Link/index.d.ts +1 -0
  239. package/dist/components/Link/index.js +1 -0
  240. package/dist/components/List/List.css +39 -0
  241. package/dist/components/List/List.css.d.ts +5 -0
  242. package/dist/components/List/List.css.js +14 -0
  243. package/dist/components/List/List.d.ts +294 -0
  244. package/dist/components/List/List.docs.d.ts +19 -0
  245. package/dist/components/List/List.docs.js +43 -0
  246. package/dist/components/List/List.js +25 -0
  247. package/dist/components/List/index.d.ts +1 -0
  248. package/dist/components/List/index.js +1 -0
  249. package/dist/components/Menu/Menu.css +65 -0
  250. package/dist/components/Menu/Menu.css.d.ts +5 -0
  251. package/dist/components/Menu/Menu.css.js +9 -0
  252. package/dist/components/Menu/Menu.d.ts +60 -0
  253. package/dist/components/Menu/Menu.docs.d.ts +19 -0
  254. package/dist/components/Menu/Menu.docs.js +53 -0
  255. package/dist/components/Menu/Menu.js +192 -0
  256. package/dist/components/Menu/index.d.ts +1 -0
  257. package/dist/components/Menu/index.js +1 -0
  258. package/dist/components/NavBar/NavBar.css +187 -0
  259. package/dist/components/NavBar/NavBar.css.d.ts +16 -0
  260. package/dist/components/NavBar/NavBar.css.js +19 -0
  261. package/dist/components/NavBar/NavBar.d.ts +31 -0
  262. package/dist/components/NavBar/NavBar.docs.d.ts +19 -0
  263. package/dist/components/NavBar/NavBar.docs.js +53 -0
  264. package/dist/components/NavBar/NavBar.js +110 -0
  265. package/dist/components/NavBar/index.d.ts +1 -0
  266. package/dist/components/NavBar/index.js +1 -0
  267. package/dist/components/Popover/Popover.css +28 -0
  268. package/dist/components/Popover/Popover.css.d.ts +3 -0
  269. package/dist/components/Popover/Popover.css.js +8 -0
  270. package/dist/components/Popover/Popover.d.ts +40 -0
  271. package/dist/components/Popover/Popover.docs.d.ts +19 -0
  272. package/dist/components/Popover/Popover.docs.js +50 -0
  273. package/dist/components/Popover/Popover.js +69 -0
  274. package/dist/components/Popover/index.d.ts +1 -0
  275. package/dist/components/Popover/index.js +1 -0
  276. package/dist/components/Progress/Progress.css +106 -0
  277. package/dist/components/Progress/Progress.css.d.ts +10 -0
  278. package/dist/components/Progress/Progress.css.js +24 -0
  279. package/dist/components/Progress/Progress.d.ts +23 -0
  280. package/dist/components/Progress/Progress.docs.d.ts +19 -0
  281. package/dist/components/Progress/Progress.docs.js +43 -0
  282. package/dist/components/Progress/Progress.js +54 -0
  283. package/dist/components/Progress/index.d.ts +1 -0
  284. package/dist/components/Progress/index.js +1 -0
  285. package/dist/components/PromptInput/PromptInput.css +25 -0
  286. package/dist/components/PromptInput/PromptInput.css.d.ts +5 -0
  287. package/dist/components/PromptInput/PromptInput.css.js +8 -0
  288. package/dist/components/PromptInput/PromptInput.d.ts +65 -0
  289. package/dist/components/PromptInput/PromptInput.docs.d.ts +19 -0
  290. package/dist/components/PromptInput/PromptInput.docs.js +45 -0
  291. package/dist/components/PromptInput/PromptInput.js +91 -0
  292. package/dist/components/PromptInput/index.d.ts +1 -0
  293. package/dist/components/PromptInput/index.js +1 -0
  294. package/dist/components/Quote/Quote.css +31 -0
  295. package/dist/components/Quote/Quote.css.d.ts +5 -0
  296. package/dist/components/Quote/Quote.css.js +9 -0
  297. package/dist/components/Quote/Quote.d.ts +13 -0
  298. package/dist/components/Quote/Quote.docs.d.ts +19 -0
  299. package/dist/components/Quote/Quote.docs.js +30 -0
  300. package/dist/components/Quote/Quote.js +26 -0
  301. package/dist/components/Quote/index.d.ts +1 -0
  302. package/dist/components/Quote/index.js +1 -0
  303. package/dist/components/RadioGroup/RadioGroup.css +70 -0
  304. package/dist/components/RadioGroup/RadioGroup.css.d.ts +4 -0
  305. package/dist/components/RadioGroup/RadioGroup.css.js +12 -0
  306. package/dist/components/RadioGroup/RadioGroup.d.ts +32 -0
  307. package/dist/components/RadioGroup/RadioGroup.docs.d.ts +19 -0
  308. package/dist/components/RadioGroup/RadioGroup.docs.js +47 -0
  309. package/dist/components/RadioGroup/RadioGroup.js +85 -0
  310. package/dist/components/RadioGroup/index.d.ts +1 -0
  311. package/dist/components/RadioGroup/index.js +1 -0
  312. package/dist/components/Select/Select.css +17 -0
  313. package/dist/components/Select/Select.css.d.ts +3 -0
  314. package/dist/components/Select/Select.css.js +7 -0
  315. package/dist/components/Select/Select.d.ts +26 -0
  316. package/dist/components/Select/Select.docs.d.ts +19 -0
  317. package/dist/components/Select/Select.docs.js +35 -0
  318. package/dist/components/Select/Select.js +57 -0
  319. package/dist/components/Select/index.d.ts +1 -0
  320. package/dist/components/Select/index.js +1 -0
  321. package/dist/components/SideNav/SideNav.css +74 -0
  322. package/dist/components/SideNav/SideNav.css.d.ts +7 -0
  323. package/dist/components/SideNav/SideNav.css.js +12 -0
  324. package/dist/components/SideNav/SideNav.d.ts +23 -0
  325. package/dist/components/SideNav/SideNav.docs.d.ts +19 -0
  326. package/dist/components/SideNav/SideNav.docs.js +43 -0
  327. package/dist/components/SideNav/SideNav.js +55 -0
  328. package/dist/components/SideNav/index.d.ts +1 -0
  329. package/dist/components/SideNav/index.js +1 -0
  330. package/dist/components/Skeleton/Skeleton.css +45 -0
  331. package/dist/components/Skeleton/Skeleton.css.d.ts +3 -0
  332. package/dist/components/Skeleton/Skeleton.css.js +11 -0
  333. package/dist/components/Skeleton/Skeleton.d.ts +25 -0
  334. package/dist/components/Skeleton/Skeleton.docs.d.ts +19 -0
  335. package/dist/components/Skeleton/Skeleton.docs.js +43 -0
  336. package/dist/components/Skeleton/Skeleton.js +27 -0
  337. package/dist/components/Skeleton/index.d.ts +1 -0
  338. package/dist/components/Skeleton/index.js +1 -0
  339. package/dist/components/Spinner/Spinner.css +46 -0
  340. package/dist/components/Spinner/Spinner.css.d.ts +5 -0
  341. package/dist/components/Spinner/Spinner.css.js +13 -0
  342. package/dist/components/Spinner/Spinner.d.ts +24 -0
  343. package/dist/components/Spinner/Spinner.docs.d.ts +19 -0
  344. package/dist/components/Spinner/Spinner.docs.js +44 -0
  345. package/dist/components/Spinner/Spinner.js +46 -0
  346. package/dist/components/Spinner/index.d.ts +1 -0
  347. package/dist/components/Spinner/index.js +1 -0
  348. package/dist/components/Stack/Stack.css +21 -0
  349. package/dist/components/Stack/Stack.css.d.ts +2 -0
  350. package/dist/components/Stack/Stack.css.js +10 -0
  351. package/dist/components/Stack/Stack.d.ts +296 -0
  352. package/dist/components/Stack/Stack.docs.d.ts +19 -0
  353. package/dist/components/Stack/Stack.docs.js +48 -0
  354. package/dist/components/Stack/Stack.js +13 -0
  355. package/dist/components/Stack/index.d.ts +1 -0
  356. package/dist/components/Stack/index.js +1 -0
  357. package/dist/components/Stat/Stat.css +59 -0
  358. package/dist/components/Stat/Stat.css.d.ts +13 -0
  359. package/dist/components/Stat/Stat.css.js +18 -0
  360. package/dist/components/Stat/Stat.d.ts +20 -0
  361. package/dist/components/Stat/Stat.docs.d.ts +19 -0
  362. package/dist/components/Stat/Stat.docs.js +52 -0
  363. package/dist/components/Stat/Stat.js +49 -0
  364. package/dist/components/Stat/index.d.ts +1 -0
  365. package/dist/components/Stat/index.js +1 -0
  366. package/dist/components/StreamingIndicator/StreamingIndicator.css +46 -0
  367. package/dist/components/StreamingIndicator/StreamingIndicator.css.d.ts +5 -0
  368. package/dist/components/StreamingIndicator/StreamingIndicator.css.js +13 -0
  369. package/dist/components/StreamingIndicator/StreamingIndicator.d.ts +22 -0
  370. package/dist/components/StreamingIndicator/StreamingIndicator.docs.d.ts +19 -0
  371. package/dist/components/StreamingIndicator/StreamingIndicator.docs.js +43 -0
  372. package/dist/components/StreamingIndicator/StreamingIndicator.js +31 -0
  373. package/dist/components/StreamingIndicator/index.d.ts +1 -0
  374. package/dist/components/StreamingIndicator/index.js +1 -0
  375. package/dist/components/Switch/Switch.css +89 -0
  376. package/dist/components/Switch/Switch.css.d.ts +4 -0
  377. package/dist/components/Switch/Switch.css.js +9 -0
  378. package/dist/components/Switch/Switch.d.ts +21 -0
  379. package/dist/components/Switch/Switch.docs.d.ts +19 -0
  380. package/dist/components/Switch/Switch.docs.js +36 -0
  381. package/dist/components/Switch/Switch.js +51 -0
  382. package/dist/components/Switch/index.d.ts +1 -0
  383. package/dist/components/Switch/index.js +1 -0
  384. package/dist/components/TabBar/TabBar.css +94 -0
  385. package/dist/components/TabBar/TabBar.css.d.ts +7 -0
  386. package/dist/components/TabBar/TabBar.css.js +12 -0
  387. package/dist/components/TabBar/TabBar.d.ts +23 -0
  388. package/dist/components/TabBar/TabBar.docs.d.ts +19 -0
  389. package/dist/components/TabBar/TabBar.docs.js +43 -0
  390. package/dist/components/TabBar/TabBar.js +50 -0
  391. package/dist/components/TabBar/index.d.ts +1 -0
  392. package/dist/components/TabBar/index.js +1 -0
  393. package/dist/components/Table/Table.css +75 -0
  394. package/dist/components/Table/Table.css.d.ts +10 -0
  395. package/dist/components/Table/Table.css.js +22 -0
  396. package/dist/components/Table/Table.d.ts +32 -0
  397. package/dist/components/Table/Table.docs.d.ts +19 -0
  398. package/dist/components/Table/Table.docs.js +49 -0
  399. package/dist/components/Table/Table.js +69 -0
  400. package/dist/components/Table/index.d.ts +1 -0
  401. package/dist/components/Table/index.js +1 -0
  402. package/dist/components/Tabs/Tabs.css +79 -0
  403. package/dist/components/Tabs/Tabs.css.d.ts +6 -0
  404. package/dist/components/Tabs/Tabs.css.js +14 -0
  405. package/dist/components/Tabs/Tabs.d.ts +33 -0
  406. package/dist/components/Tabs/Tabs.docs.d.ts +19 -0
  407. package/dist/components/Tabs/Tabs.docs.js +56 -0
  408. package/dist/components/Tabs/Tabs.js +90 -0
  409. package/dist/components/Tabs/index.d.ts +1 -0
  410. package/dist/components/Tabs/index.js +1 -0
  411. package/dist/components/Tag/Tag.css +63 -0
  412. package/dist/components/Tag/Tag.css.d.ts +5 -0
  413. package/dist/components/Tag/Tag.css.js +10 -0
  414. package/dist/components/Tag/Tag.d.ts +13 -0
  415. package/dist/components/Tag/Tag.docs.d.ts +19 -0
  416. package/dist/components/Tag/Tag.docs.js +39 -0
  417. package/dist/components/Tag/Tag.js +35 -0
  418. package/dist/components/Tag/index.d.ts +1 -0
  419. package/dist/components/Tag/index.js +1 -0
  420. package/dist/components/Text/Text.css +86 -0
  421. package/dist/components/Text/Text.css.d.ts +6 -0
  422. package/dist/components/Text/Text.css.js +39 -0
  423. package/dist/components/Text/Text.d.ts +310 -0
  424. package/dist/components/Text/Text.docs.d.ts +19 -0
  425. package/dist/components/Text/Text.docs.js +52 -0
  426. package/dist/components/Text/Text.js +12 -0
  427. package/dist/components/Text/index.d.ts +1 -0
  428. package/dist/components/Text/index.js +1 -0
  429. package/dist/components/TextArea/TextArea.css +8 -0
  430. package/dist/components/TextArea/TextArea.css.d.ts +1 -0
  431. package/dist/components/TextArea/TextArea.css.js +5 -0
  432. package/dist/components/TextArea/TextArea.d.ts +15 -0
  433. package/dist/components/TextArea/TextArea.docs.d.ts +19 -0
  434. package/dist/components/TextArea/TextArea.docs.js +31 -0
  435. package/dist/components/TextArea/TextArea.js +33 -0
  436. package/dist/components/TextArea/index.d.ts +1 -0
  437. package/dist/components/TextArea/index.js +1 -0
  438. package/dist/components/TextField/TextField.d.ts +14 -0
  439. package/dist/components/TextField/TextField.docs.d.ts +19 -0
  440. package/dist/components/TextField/TextField.docs.js +59 -0
  441. package/dist/components/TextField/TextField.js +32 -0
  442. package/dist/components/TextField/index.d.ts +1 -0
  443. package/dist/components/TextField/index.js +1 -0
  444. package/dist/components/Timeline/Timeline.css +100 -0
  445. package/dist/components/Timeline/Timeline.css.d.ts +10 -0
  446. package/dist/components/Timeline/Timeline.css.js +15 -0
  447. package/dist/components/Timeline/Timeline.d.ts +22 -0
  448. package/dist/components/Timeline/Timeline.docs.d.ts +19 -0
  449. package/dist/components/Timeline/Timeline.docs.js +39 -0
  450. package/dist/components/Timeline/Timeline.js +42 -0
  451. package/dist/components/Timeline/index.d.ts +1 -0
  452. package/dist/components/Timeline/index.js +1 -0
  453. package/dist/components/Toast/Toast.css +106 -0
  454. package/dist/components/Toast/Toast.css.d.ts +11 -0
  455. package/dist/components/Toast/Toast.css.js +25 -0
  456. package/dist/components/Toast/Toast.d.ts +30 -0
  457. package/dist/components/Toast/Toast.docs.d.ts +19 -0
  458. package/dist/components/Toast/Toast.docs.js +49 -0
  459. package/dist/components/Toast/Toast.js +68 -0
  460. package/dist/components/Toast/ToastProvider.d.ts +12 -0
  461. package/dist/components/Toast/ToastProvider.js +140 -0
  462. package/dist/components/Toast/index.d.ts +3 -0
  463. package/dist/components/Toast/index.js +4 -0
  464. package/dist/components/Toast/toast-context.d.ts +21 -0
  465. package/dist/components/Toast/toast-context.js +11 -0
  466. package/dist/components/Tooltip/Tooltip.css +18 -0
  467. package/dist/components/Tooltip/Tooltip.css.d.ts +1 -0
  468. package/dist/components/Tooltip/Tooltip.css.js +5 -0
  469. package/dist/components/Tooltip/Tooltip.d.ts +45 -0
  470. package/dist/components/Tooltip/Tooltip.docs.d.ts +19 -0
  471. package/dist/components/Tooltip/Tooltip.docs.js +47 -0
  472. package/dist/components/Tooltip/Tooltip.js +93 -0
  473. package/dist/components/Tooltip/index.d.ts +1 -0
  474. package/dist/components/Tooltip/index.js +1 -0
  475. package/dist/icons/index.d.ts +293 -0
  476. package/dist/icons/index.js +395 -0
  477. package/dist/index.d.ts +66 -0
  478. package/dist/index.js +59 -0
  479. package/dist/internal/Field.d.ts +31 -0
  480. package/dist/internal/Field.js +54 -0
  481. package/dist/internal/field-ids.d.ts +7 -0
  482. package/dist/internal/field-ids.js +18 -0
  483. package/dist/internal/field.css +131 -0
  484. package/dist/internal/field.css.d.ts +16 -0
  485. package/dist/internal/field.css.js +22 -0
  486. package/dist/internal/floating-geometry.d.ts +42 -0
  487. package/dist/internal/floating-geometry.js +55 -0
  488. package/dist/internal/floating.css +36 -0
  489. package/dist/internal/floating.css.d.ts +8 -0
  490. package/dist/internal/floating.css.js +6 -0
  491. package/dist/internal/floating.d.ts +27 -0
  492. package/dist/internal/floating.js +118 -0
  493. package/dist/internal/useControllableState.d.ts +16 -0
  494. package/dist/internal/useControllableState.js +28 -0
  495. package/dist/internal/useOverflow.d.ts +7 -0
  496. package/dist/internal/useOverflow.js +24 -0
  497. package/dist/internal/usePopover.d.ts +28 -0
  498. package/dist/internal/usePopover.js +91 -0
  499. package/dist/manifest.json +12308 -0
  500. package/dist/patterns/dashboard-overview.docs.d.ts +22 -0
  501. package/dist/patterns/dashboard-overview.docs.js +80 -0
  502. package/dist/patterns/empty-state.docs.d.ts +22 -0
  503. package/dist/patterns/empty-state.docs.js +60 -0
  504. package/dist/patterns/index.d.ts +6 -0
  505. package/dist/patterns/index.js +14 -0
  506. package/dist/patterns/profile-card.docs.d.ts +22 -0
  507. package/dist/patterns/profile-card.docs.js +72 -0
  508. package/dist/patterns/settings-page.docs.d.ts +22 -0
  509. package/dist/patterns/settings-page.docs.js +76 -0
  510. package/dist/patterns/sign-in-form.docs.d.ts +22 -0
  511. package/dist/patterns/sign-in-form.docs.js +84 -0
  512. package/dist/primitives/VisuallyHidden.d.ts +13 -0
  513. package/dist/primitives/VisuallyHidden.js +18 -0
  514. package/dist/providers/LinkProvider.d.ts +18 -0
  515. package/dist/providers/LinkProvider.js +23 -0
  516. package/dist/providers/StringsProvider.d.ts +14 -0
  517. package/dist/providers/StringsProvider.js +25 -0
  518. package/dist/providers/link-context.d.ts +12 -0
  519. package/dist/providers/link-context.js +15 -0
  520. package/dist/providers/strings.d.ts +64 -0
  521. package/dist/providers/strings.js +38 -0
  522. package/dist/registry/gaps.d.ts +30 -0
  523. package/dist/registry/gaps.js +208 -0
  524. package/dist/registry/generated.d.ts +5 -0
  525. package/dist/registry/generated.js +2821 -0
  526. package/dist/registry/index.d.ts +36 -0
  527. package/dist/registry/index.js +201 -0
  528. package/dist/registry/types.d.ts +84 -0
  529. package/dist/styles/base.css +9 -0
  530. package/dist/styles/base.css.d.ts +1 -0
  531. package/dist/styles/base.css.js +1 -0
  532. package/dist/styles/layout.css +33 -0
  533. package/dist/styles/layout.css.d.ts +1 -0
  534. package/dist/styles/layout.css.js +17 -0
  535. package/dist/styles/shared.css +16 -0
  536. package/dist/styles/shared.css.d.ts +35 -0
  537. package/dist/styles/shared.css.js +5 -0
  538. package/dist/styles.css +3406 -0
  539. package/dist/themes/blueprint.css +115 -0
  540. package/dist/themes/contrast.d.ts +26 -0
  541. package/dist/themes/contrast.js +114 -0
  542. package/dist/themes/define.d.ts +9 -0
  543. package/dist/themes/define.js +29 -0
  544. package/dist/themes/dtcg.d.ts +126 -0
  545. package/dist/themes/dtcg.js +268 -0
  546. package/dist/themes/index.d.ts +19 -0
  547. package/dist/themes/index.js +21 -0
  548. package/dist/themes/letterpress.css +115 -0
  549. package/dist/themes/letterpress.d.ts +7 -0
  550. package/dist/themes/letterpress.js +187 -0
  551. package/dist/themes/presets/blueprint.d.ts +6 -0
  552. package/dist/themes/presets/blueprint.js +183 -0
  553. package/dist/themes/runtime/browser.d.ts +47 -0
  554. package/dist/themes/runtime/browser.js +164 -0
  555. package/dist/themes/runtime/cache.d.ts +43 -0
  556. package/dist/themes/runtime/cache.js +87 -0
  557. package/dist/themes/runtime/css.d.ts +43 -0
  558. package/dist/themes/runtime/css.js +89 -0
  559. package/dist/themes/runtime/diff.d.ts +22 -0
  560. package/dist/themes/runtime/diff.js +43 -0
  561. package/dist/themes/types.d.ts +59 -0
  562. package/dist/themes/values.d.ts +12 -0
  563. package/dist/themes/values.js +40 -0
  564. package/dist/tokens/blueprint.dark.tokens.json +1361 -0
  565. package/dist/tokens/blueprint.light.tokens.json +1361 -0
  566. package/dist/tokens/contract.d.ts +252 -0
  567. package/dist/tokens/contract.js +249 -0
  568. package/dist/tokens/index.d.ts +6 -0
  569. package/dist/tokens/index.js +1 -0
  570. package/dist/tokens/letterpress.dark.tokens.json +1391 -0
  571. package/dist/tokens/letterpress.light.tokens.json +1391 -0
  572. package/dist/tokens/tokens.css +117 -0
  573. package/dist/tokens/tokens.css.d.ts +128 -0
  574. package/dist/tokens/tokens.css.js +121 -0
  575. package/dist/utils/cx.d.ts +7 -0
  576. package/dist/utils/cx.js +14 -0
  577. package/dist/utils/space.d.ts +5 -0
  578. package/dist/utils/space.js +7 -0
  579. package/package.json +104 -3
@@ -0,0 +1,1389 @@
1
+ import { basicIconMap } from "./catalog.js";
2
+ import { humanize, isBinding, isFunctionCall, toText } from "./functions.js";
3
+ import { safeHref, safeImage } from "./links.js";
4
+ import { getAt, parsePointer, resolvePath } from "./pointer.js";
5
+ import { safeRegExp } from "./validate.js";
6
+ // src/a2ui/toTsx.ts
7
+ /**
8
+ * Turn a rendered A2UI surface into idiomatic Derelicious TSX: named imports
9
+ * from '@derelicious/ds', one exported component, and the same component
10
+ * mapping the renderer uses.
11
+ *
12
+ * Bindings outside templates become literals with today's data. Template
13
+ * child lists become a hoisted constant and a `.map()`, with relative
14
+ * bindings read from the item. Function calls inside a template are worked
15
+ * out per item and stored on the hoisted items, so the output has no runtime
16
+ * dependency on A2UI.
17
+ */
18
+ /** Input types and the kind of value they keep. */
19
+ var inputKinds = {
20
+ TextField: (c) => c.variant === "number" ? "number" : "text",
21
+ DateTimeInput: () => "text",
22
+ Select: () => "text",
23
+ CheckBox: () => "boolean",
24
+ Switch: () => "boolean",
25
+ Slider: () => "number",
26
+ ChoicePicker: (c) => c.variant === "multipleSelection" ? "list" : "text"
27
+ };
28
+ var lit = (value) => ({
29
+ kind: "lit",
30
+ value
31
+ });
32
+ var code = (text) => ({
33
+ kind: "code",
34
+ code: text
35
+ });
36
+ var isIdentifier = (key) => /^[A-Za-z_$][\w$]*$/.test(key);
37
+ function camel(text) {
38
+ const words = text.replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
39
+ if (words.length === 0) return "value";
40
+ const joined = words.map((word, index) => index === 0 ? word.charAt(0).toLowerCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)).join("");
41
+ return /^\d/.test(joined) ? `v${joined}` : joined;
42
+ }
43
+ function singular(name) {
44
+ if (/ies$/.test(name) && name.length > 4) return `${name.slice(0, -3)}y`;
45
+ if (/[^s]s$/.test(name) && name.length > 3) return name.slice(0, -1);
46
+ return `${name}Item`;
47
+ }
48
+ function accessor(base, path) {
49
+ return parsePointer(path.replace(/^\.\//, "")).reduce((out, token) => /^\d+$/.test(token) ? `${out}[${token}]` : isIdentifier(token) ? `${out}.${token}` : `${out}[${JSON.stringify(token)}]`, base);
50
+ }
51
+ function clone(value) {
52
+ return value === void 0 ? value : JSON.parse(JSON.stringify(value));
53
+ }
54
+ var Writer = class {
55
+ imports = /* @__PURE__ */ new Set();
56
+ reactImports = /* @__PURE__ */ new Set();
57
+ hoisted = /* @__PURE__ */ new Map();
58
+ hooks = [];
59
+ usesActions = false;
60
+ /** A showToast action needs `const { toast } = useToast()`. */
61
+ usesToast = false;
62
+ /** Inputs bound to absolute data paths become one state object. */
63
+ fields = /* @__PURE__ */ new Map();
64
+ names = /* @__PURE__ */ new Set([
65
+ "values",
66
+ "setValues",
67
+ "update"
68
+ ]);
69
+ processor;
70
+ surfaceId;
71
+ headingLevel;
72
+ constructor(processor, surfaceId, headingLevel) {
73
+ this.processor = processor;
74
+ this.surfaceId = surfaceId;
75
+ this.headingLevel = headingLevel;
76
+ }
77
+ uniqueName(base) {
78
+ let name = camel(base);
79
+ if ([
80
+ "index",
81
+ "onAction",
82
+ "props"
83
+ ].includes(name)) name = `${name}Value`;
84
+ let candidate = name;
85
+ let n = 2;
86
+ while (this.names.has(candidate)) {
87
+ candidate = `${name}${n}`;
88
+ n += 1;
89
+ }
90
+ this.names.add(candidate);
91
+ return candidate;
92
+ }
93
+ fieldName(componentId, prop) {
94
+ return camel(`${componentId} ${prop}`);
95
+ }
96
+ component(id) {
97
+ return this.processor.getComponent(this.surfaceId, id);
98
+ }
99
+ resolve(value, scope) {
100
+ return this.processor.resolve(this.surfaceId, value, scope);
101
+ }
102
+ /**
103
+ * Find every input bound to an absolute data path. Each becomes a field of
104
+ * one `values` state object, so inputs are controlled and anything else
105
+ * bound to the same path (text, action context, checks) reads the state.
106
+ */
107
+ collectFields() {
108
+ const surface = this.processor.getSurface(this.surfaceId);
109
+ if (!surface) return;
110
+ for (const component of surface.components.values()) {
111
+ const kindOf = Object.hasOwn(inputKinds, component.component) ? inputKinds[component.component] : void 0;
112
+ const binding = component.value;
113
+ if (!kindOf || !isBinding(binding) || !binding.path.startsWith("/")) continue;
114
+ if (this.fields.has(binding.path)) continue;
115
+ const kind = kindOf(component);
116
+ const current = this.processor.getData(this.surfaceId, binding.path);
117
+ let initial;
118
+ if (kind === "boolean") initial = current === true;
119
+ else if (kind === "list") initial = Array.isArray(current) ? current.map(String) : [];
120
+ else if (kind === "number") initial = typeof current === "number" ? current : Number(current) || 0;
121
+ else if (Array.isArray(current)) initial = toText(current[0]);
122
+ else initial = toText(current);
123
+ const last = parsePointer(binding.path).at(-1) ?? "value";
124
+ this.fields.set(binding.path, {
125
+ name: this.uniqueName(last),
126
+ kind,
127
+ initial
128
+ });
129
+ }
130
+ }
131
+ /** The state field an input or binding reads, if any. */
132
+ field(value, ctx) {
133
+ if (!isBinding(value)) return void 0;
134
+ if (ctx.template && !value.path.startsWith("/")) return void 0;
135
+ return this.fields.get(resolvePath(value.path, ctx.scope));
136
+ }
137
+ /** An expression for a dynamic value at this point in the tree. */
138
+ value(value, ctx, componentId, prop) {
139
+ if (isBinding(value)) {
140
+ if (ctx.template && !value.path.startsWith("/")) return code(accessor(ctx.template.itemVar, value.path));
141
+ const field = this.field(value, ctx);
142
+ if (field) return code(`values.${field.name}`);
143
+ return lit(this.resolve(value, ctx.scope));
144
+ }
145
+ if (isFunctionCall(value)) {
146
+ if (ctx.template && ctx.template.instances.length > 0) {
147
+ const results = ctx.template.instances.map((instance) => this.resolve(value, instance.scope));
148
+ if (!results.every((item) => JSON.stringify(item) === JSON.stringify(results[0])) && ctx.template.instances.every((item) => item.target)) {
149
+ const field = this.fieldName(componentId, prop);
150
+ ctx.template.instances.forEach((instance, index) => {
151
+ if (instance.target) instance.target[field] = results[index];
152
+ });
153
+ return code(`${ctx.template.itemVar}.${field}`);
154
+ }
155
+ return lit(results[0]);
156
+ }
157
+ return lit(this.resolve(value, ctx.scope));
158
+ }
159
+ return lit(value);
160
+ }
161
+ /** Like value, as display text. */
162
+ text(value, ctx, componentId, prop) {
163
+ const expr = this.value(value, ctx, componentId, prop);
164
+ if (expr.kind === "lit") return lit(toText(expr.value));
165
+ return expr;
166
+ }
167
+ textOrUndefined(value, ctx, componentId, prop) {
168
+ if (value === void 0) return void 0;
169
+ const expr = this.text(value, ctx, componentId, prop);
170
+ return expr.kind === "lit" && expr.value === "" ? void 0 : expr;
171
+ }
172
+ };
173
+ function el(writer, tag, props, children = []) {
174
+ if (/^[A-Z]/.test(tag)) writer.imports.add(tag);
175
+ return {
176
+ type: "element",
177
+ tag,
178
+ props: Object.entries(props).filter((entry) => entry[1] !== void 0 && !(entry[1].kind === "lit" && entry[1].value === void 0)),
179
+ children: children.flatMap((child) => child.type === "fragment" ? child.children : [child])
180
+ };
181
+ }
182
+ function textNode(expr) {
183
+ if (expr.kind === "lit") return {
184
+ type: "text",
185
+ value: toText(expr.value)
186
+ };
187
+ return {
188
+ type: "expr",
189
+ expr
190
+ };
191
+ }
192
+ /** Text with the simple Markdown Text supports: bold, italic, and code. */
193
+ function richText(writer, expr) {
194
+ if (expr.kind !== "lit") return [textNode(expr)];
195
+ const text = toText(expr.value);
196
+ const pattern = /(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*\s][^*]*\*)|(_[^_\s][^_]*_)/g;
197
+ const nodes = [];
198
+ let last = 0;
199
+ for (const match of text.matchAll(pattern)) {
200
+ const start = match.index ?? 0;
201
+ if (start > last) nodes.push({
202
+ type: "text",
203
+ value: text.slice(last, start)
204
+ });
205
+ const token = match[0];
206
+ if (match[1]) nodes.push(el(writer, "Code", {}, [{
207
+ type: "text",
208
+ value: token.slice(1, -1)
209
+ }]));
210
+ else if (match[2]) nodes.push(el(writer, "strong", {}, [{
211
+ type: "text",
212
+ value: token.slice(2, -2)
213
+ }]));
214
+ else nodes.push(el(writer, "em", {}, [{
215
+ type: "text",
216
+ value: token.slice(1, -1)
217
+ }]));
218
+ last = start + token.length;
219
+ }
220
+ if (nodes.length === 0) return [textNode(expr)];
221
+ if (last < text.length) nodes.push({
222
+ type: "text",
223
+ value: text.slice(last)
224
+ });
225
+ return nodes;
226
+ }
227
+ function generate(writer, id, ctx) {
228
+ if (typeof id !== "string") return [];
229
+ const component = writer.component(id);
230
+ const marker = `${id}@${ctx.scope}`;
231
+ if (!component) return [{
232
+ type: "comment",
233
+ text: `missing "${id}"`
234
+ }];
235
+ if (ctx.trail.includes(marker) || ctx.trail.length > 40) return [{
236
+ type: "comment",
237
+ text: `"${id}" contains itself`
238
+ }];
239
+ const emit = emitters[component.component];
240
+ if (!emit) return [{
241
+ type: "comment",
242
+ text: `unsupported "${component.component}"`
243
+ }];
244
+ return [emit(writer, component, {
245
+ ...ctx,
246
+ trail: [...ctx.trail, marker]
247
+ })];
248
+ }
249
+ /** Children of a ChildList prop: static ids, or a template as a map. */
250
+ function childList(writer, list, ctx, options = {}) {
251
+ const wrap = (node, childId) => {
252
+ const weight = writer.component(childId)?.weight;
253
+ if (!options.weighted || typeof weight !== "number" || weight <= 0) return node;
254
+ return el(writer, "div", { style: code(`{ flexGrow: ${Number(weight)}, flexBasis: 0, minWidth: 0 }`) }, [node]);
255
+ };
256
+ if (Array.isArray(list)) return list.flatMap((childId) => typeof childId === "string" ? generate(writer, childId, ctx).map((node) => wrap(node, childId)) : []);
257
+ if (list && typeof list === "object" && typeof list.componentId === "string" && typeof list.path === "string") {
258
+ const { componentId, path } = list;
259
+ const mapped = templateMap(writer, componentId, path, ctx);
260
+ return mapped ? [mapped] : [];
261
+ }
262
+ return [];
263
+ }
264
+ function templateMap(writer, componentId, path, ctx) {
265
+ const relative = !path.startsWith("/") && ctx.template;
266
+ const lastToken = parsePointer(path).at(-1) ?? "items";
267
+ let listExpr;
268
+ let instances;
269
+ if (relative && ctx.template) {
270
+ listExpr = accessor(ctx.template.itemVar, path);
271
+ instances = ctx.template.instances.flatMap((outer) => {
272
+ const items = writer.processor.getData(writer.surfaceId, path, outer.scope);
273
+ if (!Array.isArray(items)) return [];
274
+ const targetList = outer.target ? getAt(outer.target, `/${path.replace(/^\.\//, "")}`) : void 0;
275
+ const base = resolvePath(path, outer.scope);
276
+ return items.map((_, index) => ({
277
+ scope: `${base}/${index}`,
278
+ target: Array.isArray(targetList) ? targetList[index] : null
279
+ }));
280
+ });
281
+ } else {
282
+ const absolute = resolvePath(path, ctx.scope);
283
+ const items = writer.processor.getData(writer.surfaceId, absolute);
284
+ const copy = Array.isArray(items) ? clone(items) : [];
285
+ listExpr = writer.uniqueName(lastToken);
286
+ writer.hoisted.set(listExpr, copy);
287
+ const prefix = absolute === "/" ? "" : absolute;
288
+ instances = copy.map((item, index) => ({
289
+ scope: `${prefix}/${index}`,
290
+ target: item && typeof item === "object" && !Array.isArray(item) ? item : null
291
+ }));
292
+ }
293
+ const itemVar = writer.uniqueName(singular(camel(lastToken)));
294
+ const template = {
295
+ itemVar,
296
+ instances
297
+ };
298
+ const body = generate(writer, componentId, {
299
+ scope: instances[0]?.scope ?? `${resolvePath(path, ctx.scope)}/0`,
300
+ template,
301
+ trail: ctx.trail
302
+ });
303
+ if (body.length === 0) return null;
304
+ const sample = instances.map((instance) => instance.target ? instance.target.id : void 0);
305
+ const hasIds = sample.length > 0 && sample.every((item) => typeof item === "string" || typeof item === "number") && new Set(sample).size === sample.length;
306
+ const key = hasIds ? `${itemVar}.id` : "index";
307
+ const keyed = body.map((node) => node.type === "element" ? {
308
+ ...node,
309
+ props: [["key", code(key)], ...node.props]
310
+ } : node);
311
+ const params = hasIds ? `(${itemVar})` : `(${itemVar}, index)`;
312
+ return {
313
+ type: "expr",
314
+ expr: {
315
+ kind: "map",
316
+ list: listExpr,
317
+ params,
318
+ body: keyed
319
+ }
320
+ };
321
+ }
322
+ var choose = (value, allowed) => allowed.includes(value) ? value : void 0;
323
+ var optionalLit = (value, fallback) => value === void 0 || value === fallback ? void 0 : lit(value);
324
+ function iconFor(value) {
325
+ if (typeof value !== "string") return "sparkle";
326
+ return Object.hasOwn(basicIconMap, value) ? basicIconMap[value] : value;
327
+ }
328
+ var headingSizes = {
329
+ 1: "2xl",
330
+ 2: "xl",
331
+ 3: "lg",
332
+ 4: "md"
333
+ };
334
+ function actionHandler(writer, component, ctx) {
335
+ const action = component.action;
336
+ if (action && "event" in action && action.event?.name) {
337
+ writer.usesActions = true;
338
+ const entries = Object.entries(action.event.context ?? {}).map(([key, value]) => [key, writer.value(value, ctx, component.id, `context ${key}`)]);
339
+ const context = entries.length ? `, ${printExpr({
340
+ kind: "object",
341
+ entries
342
+ }, 0)}` : "";
343
+ return { onClick: code(`() => onAction?.(${quote(action.event.name)}${context})`) };
344
+ }
345
+ if (action && "functionCall" in action && action.functionCall?.call === "showToast") {
346
+ const args = action.functionCall.args ?? {};
347
+ const message = toText(writer.resolve(args.message, ctx.scope)).trim();
348
+ if (!message) return {};
349
+ writer.usesToast = true;
350
+ writer.imports.add("useToast");
351
+ const tone = [
352
+ "positive",
353
+ "warning",
354
+ "danger"
355
+ ].includes(String(args.tone)) ? `, tone: ${quote(String(args.tone))}` : "";
356
+ const extra = args.action;
357
+ let button = "";
358
+ if (extra && typeof extra.label === "string" && extra.event) {
359
+ const inner = actionHandler(writer, {
360
+ id: component.id,
361
+ component: "Button",
362
+ action: { event: extra.event }
363
+ }, ctx);
364
+ if (inner.onClick?.kind === "code") button = `, action: { label: ${quote(extra.label)}, onClick: ${inner.onClick.code} }`;
365
+ }
366
+ return { onClick: code(`() => toast({ title: ${quote(message)}${tone}${button} })`) };
367
+ }
368
+ if (action && "functionCall" in action && action.functionCall?.call === "openUrl") {
369
+ const url = safeHref(writer.resolve(action.functionCall.args?.url, ctx.scope));
370
+ if (url) return { href: lit(url) };
371
+ }
372
+ return {};
373
+ }
374
+ /** Code for a value a check reads: state when bound to it, else a literal. */
375
+ function argCode(writer, value, ctx) {
376
+ const field = writer.field(value, ctx);
377
+ if (field) return {
378
+ code: `values.${field.name}`,
379
+ field,
380
+ live: true
381
+ };
382
+ return {
383
+ code: printValue(writer.resolve(value, ctx.scope), 0),
384
+ field: void 0,
385
+ live: false
386
+ };
387
+ }
388
+ var EMAIL = "/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/";
389
+ /**
390
+ * A check's condition as TypeScript that reads the form state, so exported
391
+ * buttons enable and disable as people type. Conditions that read no state
392
+ * are worked out now and become `true` or `false`.
393
+ */
394
+ function conditionCode(writer, value, ctx) {
395
+ const literal = () => String(Boolean(writer.resolve(value, ctx.scope)));
396
+ if (typeof value === "boolean") return String(value);
397
+ if (isBinding(value)) {
398
+ const field = writer.field(value, ctx);
399
+ if (!field) return literal();
400
+ return field.kind === "boolean" ? `values.${field.name}` : `Boolean(values.${field.name})`;
401
+ }
402
+ if (!isFunctionCall(value)) return literal();
403
+ const args = value.args ?? {};
404
+ const join = (items, operator, empty) => {
405
+ const parts = (Array.isArray(items) ? items : []).map((item) => {
406
+ const part = conditionCode(writer, item, ctx);
407
+ return operator === "&&" ? group(part) : `(${part})`;
408
+ });
409
+ return parts.length ? parts.join(` ${operator} `) : empty;
410
+ };
411
+ if (value.call === "and") return join(args.values, "&&", "true");
412
+ if (value.call === "or") return join(args.values, "||", "false");
413
+ if (value.call === "not") return `!(${conditionCode(writer, args.value, ctx)})`;
414
+ const arg = argCode(writer, args.value, ctx);
415
+ if (!arg.live) return literal();
416
+ const number = (key) => typeof args[key] === "number" ? args[key] : void 0;
417
+ const text = arg.field?.kind === "text" ? arg.code : `String(${arg.code})`;
418
+ switch (value.call) {
419
+ case "required":
420
+ if (arg.field?.kind === "list") return `${arg.code}.length > 0`;
421
+ if (arg.field?.kind === "boolean") return arg.code;
422
+ if (arg.field?.kind === "number") return `!Number.isNaN(${arg.code})`;
423
+ return `${arg.code}.trim() !== ''`;
424
+ case "email": return `${EMAIL}.test(${text})`;
425
+ case "regex": return safeRegExp(args.pattern) ? `new RegExp(${quote(String(args.pattern))}, 'u').test(${text})` : "true";
426
+ case "length": {
427
+ const min = number("min");
428
+ const max = number("max");
429
+ const parts = [min === void 0 ? "" : `${text}.length >= ${min}`, max === void 0 ? "" : `${text}.length <= ${max}`].filter(Boolean);
430
+ return parts.length ? parts.join(" && ") : "true";
431
+ }
432
+ case "numeric": {
433
+ const target = arg.field?.kind === "number" ? arg.code : `Number(${arg.code})`;
434
+ const min = number("min");
435
+ const max = number("max");
436
+ return [
437
+ `!Number.isNaN(${target})`,
438
+ min === void 0 ? "" : `${target} >= ${min}`,
439
+ max === void 0 ? "" : `${target} <= ${max}`
440
+ ].filter(Boolean).join(" && ");
441
+ }
442
+ default: return literal();
443
+ }
444
+ }
445
+ /** Parenthesize a condition when it would bind loosely inside `&&`. */
446
+ var group = (part) => /\|\||\?/.test(part) ? `(${part})` : part;
447
+ /**
448
+ * `disabled` for a component with checks. A condition that reads state is
449
+ * hoisted into a named constant, like `const loginReady = …`, and the prop
450
+ * becomes `disabled={!loginReady}`.
451
+ */
452
+ function disabledFor(writer, c, ctx) {
453
+ const checks = c.checks;
454
+ if (!Array.isArray(checks) || checks.length === 0) return void 0;
455
+ const parts = checks.filter((rule) => rule && typeof rule === "object").map((rule) => conditionCode(writer, rule.condition, ctx)).filter((part) => part !== "true");
456
+ if (parts.length === 0) return void 0;
457
+ if (parts.includes("false")) return lit(true);
458
+ const name = writer.uniqueName(`${actionName(c) || c.id} ready`);
459
+ writer.hooks.push(`const ${name} = ${parts.map(group).join(" && ")}`);
460
+ return code(`!${name}`);
461
+ }
462
+ /** Props that bind an input to its state field, or its literal start value. */
463
+ function boundProps(writer, c, ctx, as) {
464
+ const field = writer.field(c.value, ctx);
465
+ if (!field) {
466
+ if (c.value === void 0) return {};
467
+ return as === "checked" ? { defaultChecked: writer.value(c.value, ctx, c.id, "value") } : { defaultValue: writer.text(c.value, ctx, c.id, "value") };
468
+ }
469
+ if (as === "checked") return {
470
+ checked: code(`values.${field.name}`),
471
+ onChange: code(`(event) => update({ ${field.name}: event.currentTarget.checked })`)
472
+ };
473
+ const read = as === "number" ? "event.currentTarget.valueAsNumber" : "event.currentTarget.value";
474
+ return {
475
+ value: code(`values.${field.name}`),
476
+ onChange: code(`(event) => update({ ${field.name}: ${read} })`)
477
+ };
478
+ }
479
+ /** The event name of a component's action, or "". */
480
+ function actionName(c) {
481
+ const action = c.action;
482
+ return typeof action?.event?.name === "string" ? action.event.name : "";
483
+ }
484
+ function buttonLabel(writer, childId, ctx) {
485
+ const child = typeof childId === "string" ? writer.component(childId) : void 0;
486
+ if (!child) return {
487
+ label: void 0,
488
+ icon: void 0
489
+ };
490
+ if (child.component === "Icon") return {
491
+ label: void 0,
492
+ icon: iconFor(child.name)
493
+ };
494
+ if (child.component === "Row" && Array.isArray(child.children)) {
495
+ let icon;
496
+ let label;
497
+ for (const id of child.children) {
498
+ const part = buttonLabel(writer, id, ctx);
499
+ icon ??= part.icon;
500
+ label ??= part.label;
501
+ }
502
+ return {
503
+ label,
504
+ icon
505
+ };
506
+ }
507
+ for (const key of [
508
+ "text",
509
+ "title",
510
+ "label"
511
+ ]) if (child[key] !== void 0) return {
512
+ label: writer.text(child[key], ctx, child.id, key),
513
+ icon: void 0
514
+ };
515
+ return {
516
+ label: void 0,
517
+ icon: void 0
518
+ };
519
+ }
520
+ function oneChild(writer, id, ctx) {
521
+ const nodes = generate(writer, id, ctx);
522
+ return nodes.length === 1 ? nodes[0] : {
523
+ type: "fragment",
524
+ children: nodes
525
+ };
526
+ }
527
+ function listOf(writer, value, ctx, map) {
528
+ if (isBinding(value)) {
529
+ const items = writer.resolve(value, ctx.scope);
530
+ const base = resolvePath(value.path, ctx.scope);
531
+ if (!Array.isArray(items)) return {
532
+ kind: "array",
533
+ items: []
534
+ };
535
+ return {
536
+ kind: "array",
537
+ items: items.map((item, index) => map(item ?? {}, {
538
+ ...ctx,
539
+ scope: `${base}/${index}`,
540
+ template: void 0
541
+ }, index))
542
+ };
543
+ }
544
+ if (!Array.isArray(value)) return {
545
+ kind: "array",
546
+ items: []
547
+ };
548
+ return {
549
+ kind: "array",
550
+ items: value.map((item, index) => map(item ?? {}, ctx, index))
551
+ };
552
+ }
553
+ var emitters = {
554
+ Text(writer, c, ctx) {
555
+ const variant = typeof c.variant === "string" ? c.variant : "body";
556
+ const content = writer.text(c.text, ctx, c.id, "text");
557
+ const tone = optionalLit(choose(c.tone, [
558
+ "muted",
559
+ "accent",
560
+ "positive",
561
+ "warning",
562
+ "danger",
563
+ "info"
564
+ ]));
565
+ const heading = /^h([1-5])$/.exec(variant);
566
+ if (heading && Number(heading[1]) <= 4) {
567
+ const depth = Number(heading[1]);
568
+ const level = Math.min(4, writer.headingLevel + depth - 1);
569
+ const stripped = content.kind === "lit" ? lit(toText(content.value).replace(/^#{1,6}\s+/, "")) : content;
570
+ return el(writer, "Heading", {
571
+ level: lit(level),
572
+ size: lit(headingSizes[depth]),
573
+ tone: c.tone === "accent" ? lit("accent") : void 0
574
+ }, richText(writer, stripped));
575
+ }
576
+ if (heading) return el(writer, "Text", {
577
+ weight: lit("semibold"),
578
+ tone
579
+ }, richText(writer, content));
580
+ if (variant === "caption") return el(writer, "Text", {
581
+ size: lit("sm"),
582
+ tone: tone ?? lit("muted")
583
+ }, richText(writer, content));
584
+ if (variant === "lede" || variant === "eyebrow") return el(writer, "Text", {
585
+ variant: lit(variant),
586
+ tone
587
+ }, richText(writer, content));
588
+ return el(writer, "Text", { tone }, richText(writer, content));
589
+ },
590
+ Image(writer, c, ctx) {
591
+ const variant = typeof c.variant === "string" ? c.variant : "mediumFeature";
592
+ const aspect = {
593
+ icon: "1/1",
594
+ avatar: "1/1",
595
+ smallFeature: "1/1",
596
+ mediumFeature: "4/3",
597
+ largeFeature: "16/9",
598
+ header: "21/9"
599
+ };
600
+ const src = writer.value(c.url, ctx, c.id, "url");
601
+ return el(writer, "Image", {
602
+ src: src.kind === "lit" ? lit(safeImage(src.value)) : src,
603
+ alt: writer.text(c.description ?? "", ctx, c.id, "description"),
604
+ aspect: lit(aspect[variant] ?? "4/3"),
605
+ fit: [
606
+ "contain",
607
+ "none",
608
+ "scaleDown"
609
+ ].includes(String(c.fit)) ? lit("contain") : void 0
610
+ });
611
+ },
612
+ Icon(writer, c, ctx) {
613
+ const name = writer.value(c.name, ctx, c.id, "name");
614
+ const label = writer.textOrUndefined(c.accessibility?.label, ctx, c.id, "label");
615
+ return el(writer, "Icon", {
616
+ name: name.kind === "lit" ? lit(iconFor(name.value)) : name,
617
+ label
618
+ });
619
+ },
620
+ Video: mediaLink,
621
+ AudioPlayer: mediaLink,
622
+ Row(writer, c, ctx) {
623
+ const justify = {
624
+ center: "center",
625
+ end: "end",
626
+ spaceBetween: "between",
627
+ spaceAround: "between",
628
+ spaceEvenly: "between"
629
+ }[String(c.justify)];
630
+ return el(writer, "Inline", {
631
+ gap: optionalLit(c.gap, 3),
632
+ justify: optionalLit(justify),
633
+ align: lit(choose(c.align, [
634
+ "start",
635
+ "center",
636
+ "end",
637
+ "stretch"
638
+ ]) ?? "stretch"),
639
+ wrap: c.wrap === false ? lit(false) : void 0
640
+ }, childList(writer, c.children, ctx, { weighted: true }));
641
+ },
642
+ Column(writer, c, ctx) {
643
+ return el(writer, "Stack", {
644
+ gap: lit(typeof c.gap === "number" ? c.gap : 3),
645
+ align: optionalLit(choose(c.align, [
646
+ "start",
647
+ "center",
648
+ "end"
649
+ ]), void 0)
650
+ }, childList(writer, c.children, ctx, { weighted: true }));
651
+ },
652
+ List(writer, c, ctx) {
653
+ const items = childList(writer, c.children, ctx);
654
+ if (c.direction === "horizontal") return el(writer, "Inline", {
655
+ as: lit("ul"),
656
+ gap: lit(2)
657
+ }, items.map((node) => node.type === "expr" ? node : el(writer, "li", {}, [node])));
658
+ return el(writer, "List", {
659
+ marker: lit(choose(c.marker, [
660
+ "bullet",
661
+ "number",
662
+ "check",
663
+ "none"
664
+ ]) ?? "none"),
665
+ items: listItemsExpr(items)
666
+ });
667
+ },
668
+ Card(writer, c, ctx) {
669
+ const title = writer.textOrUndefined(c.title, ctx, c.id, "title");
670
+ const href = c.href === void 0 ? void 0 : writer.value(c.href, ctx, c.id, "href");
671
+ return el(writer, "Card", {
672
+ eyebrow: writer.textOrUndefined(c.eyebrow, ctx, c.id, "eyebrow"),
673
+ title,
674
+ titleLevel: title ? lit(Math.min(4, Math.max(2, writer.headingLevel + 1))) : void 0,
675
+ href: title && href ? href.kind === "lit" ? optionalLit(safeHref(href.value)) : href : void 0,
676
+ variant: optionalLit(choose(c.variant, ["filled", "elevated"]))
677
+ }, generate(writer, c.child, ctx));
678
+ },
679
+ Tabs(writer, c, ctx) {
680
+ const tabs = Array.isArray(c.tabs) ? c.tabs : [];
681
+ return el(writer, "Tabs", {
682
+ label: lit(typeof c.label === "string" ? c.label : "Views"),
683
+ tabs: {
684
+ kind: "array",
685
+ items: tabs.map((tab, index) => ({
686
+ kind: "object",
687
+ entries: [
688
+ ["id", lit(`${c.id}-${index}`)],
689
+ ["label", writer.text(tab?.title, ctx, c.id, `tab ${index}`)],
690
+ ["content", {
691
+ kind: "jsx",
692
+ node: oneChild(writer, tab?.child, ctx)
693
+ }]
694
+ ]
695
+ }))
696
+ }
697
+ });
698
+ },
699
+ Modal(writer, c, ctx) {
700
+ writer.reactImports.add("useState");
701
+ const name = writer.uniqueName(`${c.id} open`);
702
+ const setter = `set${name.charAt(0).toUpperCase()}${name.slice(1)}`;
703
+ writer.hooks.push(`const [${name}, ${setter}] = useState(false)`);
704
+ const trigger = writer.component(String(c.trigger));
705
+ const label = trigger ? buttonLabel(writer, trigger.child, ctx).label : void 0;
706
+ return {
707
+ type: "fragment",
708
+ children: [el(writer, "Button", {
709
+ tone: lit("secondary"),
710
+ onClick: code(`() => ${setter}(true)`)
711
+ }, [textNode(label ?? lit("Open"))]), el(writer, "Dialog", {
712
+ open: code(name),
713
+ onClose: code(`() => ${setter}(false)`),
714
+ title: writer.text(c.title ?? "Details", ctx, c.id, "title")
715
+ }, generate(writer, c.content, ctx))]
716
+ };
717
+ },
718
+ Divider(writer, c) {
719
+ return el(writer, "Divider", {
720
+ orientation: c.axis === "vertical" ? lit("vertical") : void 0,
721
+ label: optionalLit(typeof c.label === "string" ? c.label : void 0)
722
+ });
723
+ },
724
+ Button(writer, c, ctx) {
725
+ const { label, icon } = buttonLabel(writer, c.child, ctx);
726
+ const handler = actionHandler(writer, c, ctx);
727
+ const hrefValue = c.href === void 0 ? void 0 : writer.value(c.href, ctx, c.id, "href");
728
+ const href = hrefValue && hrefValue.kind === "lit" ? optionalLit(safeHref(hrefValue.value)) : hrefValue ?? handler.href;
729
+ const disabled = href ? void 0 : disabledFor(writer, c, ctx);
730
+ const loadingValue = href || c.loading === void 0 ? void 0 : writer.value(c.loading, ctx, c.id, "loading");
731
+ const loading = loadingValue?.kind === "lit" ? loadingValue.value === true ? lit(true) : void 0 : loadingValue;
732
+ const named = c.accessibility?.label !== void 0 ? writer.text(c.accessibility.label, ctx, c.id, "label") : void 0;
733
+ if (!label && icon) {
734
+ const child = typeof c.child === "string" ? writer.component(c.child) : void 0;
735
+ const iconName = typeof child?.name === "string" ? child.name : icon;
736
+ return el(writer, "IconButton", {
737
+ icon: lit(icon),
738
+ label: named ?? lit(humanize(actionName(c) || iconName)),
739
+ href,
740
+ onClick: href ? void 0 : handler.onClick,
741
+ disabled
742
+ });
743
+ }
744
+ return el(writer, "Button", {
745
+ tone: lit({
746
+ primary: "primary",
747
+ borderless: "ghost"
748
+ }[String(c.variant)] ?? "secondary"),
749
+ leadingIcon: optionalLit(icon ?? (typeof c.icon === "string" ? c.icon : void 0)),
750
+ href,
751
+ onClick: href ? void 0 : handler.onClick,
752
+ disabled,
753
+ loading
754
+ }, [textNode(label ?? named ?? lit(humanize(actionName(c)) || "Button"))]);
755
+ },
756
+ TextField(writer, c, ctx) {
757
+ const numeric = writer.field(c.value, ctx)?.kind === "number";
758
+ const props = {
759
+ label: writer.text(c.label ?? "Text", ctx, c.id, "label"),
760
+ hint: writer.textOrUndefined(c.hint, ctx, c.id, "hint"),
761
+ ...boundProps(writer, c, ctx, numeric ? "number" : "text")
762
+ };
763
+ if (c.variant === "longText") return el(writer, "TextArea", props);
764
+ return el(writer, "TextField", {
765
+ ...props,
766
+ type: c.variant === "obscured" ? lit("password") : c.variant === "number" ? lit("number") : void 0
767
+ });
768
+ },
769
+ CheckBox(writer, c, ctx) {
770
+ return el(writer, "Checkbox", {
771
+ label: writer.text(c.label, ctx, c.id, "label"),
772
+ ...boundProps(writer, c, ctx, "checked")
773
+ });
774
+ },
775
+ ChoicePicker(writer, c, ctx) {
776
+ const options = (Array.isArray(c.options) ? c.options : []).map((item, index) => ({
777
+ kind: "object",
778
+ entries: [["value", lit(String(item?.value ?? ""))], ["label", writer.text(item?.label, ctx, c.id, `option ${index}`)]]
779
+ }));
780
+ const selected = writer.resolve(c.value, ctx.scope);
781
+ const values = Array.isArray(selected) ? selected.map(String) : [];
782
+ const label = writer.text(c.label ?? "Choose", ctx, c.id, "label");
783
+ const field = writer.field(c.value, ctx);
784
+ if (field?.kind === "list") {
785
+ const list = `values.${field.name}`;
786
+ return el(writer, "Stack", {
787
+ as: lit("fieldset"),
788
+ gap: lit(2)
789
+ }, [el(writer, "Text", {
790
+ as: lit("legend"),
791
+ weight: lit("semibold")
792
+ }, [textNode(label)]), ...(Array.isArray(c.options) ? c.options : []).map((item, index) => {
793
+ const option = quote(String(item?.value ?? ""));
794
+ return el(writer, "Checkbox", {
795
+ label: writer.text(item?.label, ctx, c.id, `option ${index}`),
796
+ checked: code(`${list}.includes(${option})`),
797
+ onChange: code(`(event) => update({ ${field.name}: event.currentTarget.checked ? [...${list}, ${option}] : ${list}.filter((item) => item !== ${option}) })`)
798
+ });
799
+ })]);
800
+ }
801
+ if (field) return el(writer, "RadioGroup", {
802
+ label,
803
+ orientation: c.displayStyle === "chips" ? lit("horizontal") : void 0,
804
+ options: {
805
+ kind: "array",
806
+ items: options
807
+ },
808
+ value: code(`values.${field.name}`),
809
+ onValueChange: code(`(value) => update({ ${field.name}: value })`)
810
+ });
811
+ if (c.variant === "multipleSelection") return el(writer, "Stack", {
812
+ as: lit("fieldset"),
813
+ gap: lit(2)
814
+ }, [el(writer, "Text", {
815
+ as: lit("legend"),
816
+ weight: lit("semibold")
817
+ }, [textNode(label)]), ...(Array.isArray(c.options) ? c.options : []).map((item, index) => el(writer, "Checkbox", {
818
+ label: writer.text(item?.label, ctx, c.id, `option ${index}`),
819
+ defaultChecked: values.includes(String(item?.value)) ? lit(true) : void 0
820
+ }))]);
821
+ return el(writer, "RadioGroup", {
822
+ label,
823
+ orientation: c.displayStyle === "chips" ? lit("horizontal") : void 0,
824
+ options: {
825
+ kind: "array",
826
+ items: options
827
+ },
828
+ defaultValue: optionalLit(values[0])
829
+ });
830
+ },
831
+ Slider(writer, c, ctx) {
832
+ const label = c.label ?? c.accessibility?.label ?? humanize(c.id);
833
+ const field = writer.field(c.value, ctx);
834
+ return el(writer, "TextField", {
835
+ label: writer.text(label, ctx, c.id, "label"),
836
+ type: lit("number"),
837
+ min: optionalLit(c.min),
838
+ max: optionalLit(c.max),
839
+ step: lit(typeof c.step === "number" ? c.step : "any"),
840
+ ...field ? boundProps(writer, c, ctx, "number") : { defaultValue: writer.value(c.value, ctx, c.id, "value") }
841
+ });
842
+ },
843
+ DateTimeInput(writer, c, ctx) {
844
+ return el(writer, "TextField", {
845
+ label: writer.text(c.label ?? "Date", ctx, c.id, "label"),
846
+ hint: lit(c.enableTime === true && c.enableDate !== true ? "HH:mm" : c.enableTime === true ? "YYYY-MM-DD HH:mm" : "YYYY-MM-DD"),
847
+ ...boundProps(writer, c, ctx, "text")
848
+ });
849
+ },
850
+ Heading(writer, c, ctx) {
851
+ const relative = typeof c.level === "number" ? c.level : 1;
852
+ return el(writer, "Heading", {
853
+ level: lit(Math.min(4, Math.max(1, writer.headingLevel + relative - 1))),
854
+ size: optionalLit(typeof c.size === "string" ? c.size : void 0),
855
+ tone: c.tone === "accent" ? lit("accent") : void 0
856
+ }, [textNode(writer.text(c.text, ctx, c.id, "text"))]);
857
+ },
858
+ Stat(writer, c, ctx) {
859
+ return el(writer, "Stat", {
860
+ label: writer.text(c.label, ctx, c.id, "label"),
861
+ value: writer.text(c.value, ctx, c.id, "value"),
862
+ delta: writer.textOrUndefined(c.delta, ctx, c.id, "delta"),
863
+ trend: optionalLit(choose(c.trend, [
864
+ "up",
865
+ "down",
866
+ "flat"
867
+ ])),
868
+ tone: optionalLit(choose(c.tone, [
869
+ "positive",
870
+ "danger",
871
+ "neutral"
872
+ ])),
873
+ description: writer.textOrUndefined(c.description, ctx, c.id, "description"),
874
+ variant: c.variant === "plain" ? lit("plain") : void 0
875
+ });
876
+ },
877
+ Badge(writer, c, ctx) {
878
+ return el(writer, "Badge", {
879
+ tone: optionalLit(choose(c.tone, [
880
+ "accent",
881
+ "positive",
882
+ "warning",
883
+ "danger",
884
+ "info"
885
+ ])),
886
+ variant: c.variant === "outline" ? lit("outline") : void 0,
887
+ dot: c.dot === true ? lit(true) : void 0,
888
+ icon: optionalLit(typeof c.icon === "string" ? c.icon : void 0)
889
+ }, [textNode(writer.text(c.text, ctx, c.id, "text"))]);
890
+ },
891
+ Tag(writer, c, ctx) {
892
+ const href = c.href === void 0 ? void 0 : writer.value(c.href, ctx, c.id, "href");
893
+ return el(writer, "Tag", { href: href && href.kind === "lit" ? optionalLit(safeHref(href.value)) : href }, [textNode(writer.text(c.text, ctx, c.id, "text"))]);
894
+ },
895
+ Avatar(writer, c, ctx) {
896
+ const src = c.src === void 0 ? void 0 : writer.value(c.src, ctx, c.id, "src");
897
+ return el(writer, "Avatar", {
898
+ name: writer.text(c.name, ctx, c.id, "name"),
899
+ src: src && src.kind === "lit" ? optionalLit(safeImage(src.value) || void 0) : src,
900
+ size: optionalLit(choose(c.size, [
901
+ "sm",
902
+ "lg",
903
+ "xl"
904
+ ]))
905
+ });
906
+ },
907
+ Quote(writer, c, ctx) {
908
+ return el(writer, "Quote", {
909
+ attribution: writer.textOrUndefined(c.attribution, ctx, c.id, "attribution"),
910
+ source: writer.textOrUndefined(c.source, ctx, c.id, "source")
911
+ }, [textNode(writer.text(c.text, ctx, c.id, "text"))]);
912
+ },
913
+ Timeline(writer, c, ctx) {
914
+ return el(writer, "Timeline", { items: listOf(writer, c.items, ctx, (item, itemCtx, index) => ({
915
+ kind: "object",
916
+ entries: [
917
+ ["title", writer.text(item.title, itemCtx, c.id, `title ${index}`)],
918
+ ["meta", writer.textOrUndefined(item.meta, itemCtx, c.id, `meta ${index}`)],
919
+ ["description", writer.textOrUndefined(item.description, itemCtx, c.id, `description ${index}`)],
920
+ ["current", item.current === true ? lit(true) : void 0]
921
+ ].filter((entry) => entry[1] !== void 0)
922
+ })) });
923
+ },
924
+ Table(writer, c, ctx) {
925
+ const columns = (Array.isArray(c.columns) ? c.columns : []).filter((column) => typeof column?.key === "string");
926
+ return el(writer, "Table", {
927
+ caption: writer.text(c.caption, ctx, c.id, "caption"),
928
+ columns: {
929
+ kind: "array",
930
+ items: columns.map((column) => ({
931
+ kind: "object",
932
+ entries: [
933
+ ["key", lit(column.key)],
934
+ ["header", writer.text(column.header ?? column.key, ctx, c.id, "header")],
935
+ ["align", optionalLit(choose(column.align, ["center", "end"]))]
936
+ ].filter((entry) => entry[1] !== void 0)
937
+ }))
938
+ },
939
+ rows: listOf(writer, c.rows, ctx, (row, rowCtx) => ({
940
+ kind: "object",
941
+ entries: columns.map((column) => [column.key, writer.text(row[column.key], rowCtx, c.id, column.key)])
942
+ })),
943
+ rowHeader: optionalLit(typeof c.rowHeader === "string" ? c.rowHeader : void 0),
944
+ density: c.density === "compact" ? lit("compact") : void 0,
945
+ striped: c.striped === true ? lit(true) : void 0,
946
+ hideCaption: c.hideCaption === true ? lit(true) : void 0
947
+ });
948
+ },
949
+ Alert(writer, c, ctx) {
950
+ const body = writer.textOrUndefined(c.text, ctx, c.id, "text");
951
+ return el(writer, "Alert", {
952
+ tone: optionalLit(choose(c.tone, [
953
+ "positive",
954
+ "warning",
955
+ "danger"
956
+ ])),
957
+ title: writer.textOrUndefined(c.title, ctx, c.id, "title")
958
+ }, body ? [textNode(body)] : []);
959
+ },
960
+ Progress(writer, c, ctx) {
961
+ return el(writer, "Progress", {
962
+ label: writer.text(c.label, ctx, c.id, "label"),
963
+ value: c.value === void 0 ? void 0 : writer.value(c.value, ctx, c.id, "value"),
964
+ max: optionalLit(c.max, 100),
965
+ tone: optionalLit(choose(c.tone, [
966
+ "positive",
967
+ "warning",
968
+ "danger"
969
+ ])),
970
+ valueText: writer.textOrUndefined(c.valueText, ctx, c.id, "valueText"),
971
+ description: writer.textOrUndefined(c.description, ctx, c.id, "description"),
972
+ showValue: c.showValue === false ? lit(false) : void 0
973
+ });
974
+ },
975
+ Link(writer, c, ctx) {
976
+ const href = writer.value(c.href, ctx, c.id, "href");
977
+ const safe = href.kind === "lit" ? safeHref(href.value) : void 0;
978
+ return el(writer, "Link", {
979
+ href: href.kind === "lit" ? lit(safe ?? "#") : href,
980
+ variant: c.variant === "inline" ? void 0 : lit("standalone"),
981
+ icon: c.variant === "inline" ? void 0 : lit(typeof c.icon === "string" ? c.icon : "arrow-right"),
982
+ external: safe?.startsWith("https:") ? lit(true) : void 0
983
+ }, [textNode(writer.text(c.text, ctx, c.id, "text"))]);
984
+ },
985
+ Grid(writer, c, ctx) {
986
+ return el(writer, "Grid", {
987
+ min: optionalLit(typeof c.min === "string" ? c.min : void 0, "16rem"),
988
+ maxColumns: optionalLit(c.maxColumns),
989
+ gap: optionalLit(c.gap, 4)
990
+ }, childList(writer, c.children, ctx));
991
+ },
992
+ Accordion(writer, c, ctx) {
993
+ const items = Array.isArray(c.items) ? c.items : [];
994
+ return el(writer, "Accordion", {
995
+ exclusive: c.exclusive === true ? lit(true) : void 0,
996
+ items: {
997
+ kind: "array",
998
+ items: items.map((item, index) => ({
999
+ kind: "object",
1000
+ entries: [
1001
+ ["id", lit(`${c.id}-${index}`)],
1002
+ ["title", writer.text(item?.title, ctx, c.id, `title ${index}`)],
1003
+ ["content", {
1004
+ kind: "jsx",
1005
+ node: oneChild(writer, item?.child, ctx)
1006
+ }],
1007
+ ["defaultOpen", item?.open === true ? lit(true) : void 0]
1008
+ ].filter((entry) => entry[1] !== void 0)
1009
+ }))
1010
+ }
1011
+ });
1012
+ },
1013
+ CodeBlock(writer, c, ctx) {
1014
+ return el(writer, "CodeBlock", {
1015
+ code: writer.text(c.code, ctx, c.id, "code"),
1016
+ language: optionalLit(typeof c.language === "string" ? c.language : void 0),
1017
+ title: optionalLit(typeof c.title === "string" ? c.title : void 0)
1018
+ });
1019
+ },
1020
+ Switch(writer, c, ctx) {
1021
+ return el(writer, "Switch", {
1022
+ label: writer.text(c.label, ctx, c.id, "label"),
1023
+ hint: writer.textOrUndefined(c.hint, ctx, c.id, "hint"),
1024
+ ...boundProps(writer, c, ctx, "checked")
1025
+ });
1026
+ },
1027
+ Select(writer, c, ctx) {
1028
+ return el(writer, "Select", {
1029
+ label: writer.text(c.label, ctx, c.id, "label"),
1030
+ hint: writer.textOrUndefined(c.hint, ctx, c.id, "hint"),
1031
+ placeholder: optionalLit(typeof c.placeholder === "string" ? c.placeholder : void 0),
1032
+ options: {
1033
+ kind: "array",
1034
+ items: (Array.isArray(c.options) ? c.options : []).map((item, index) => ({
1035
+ kind: "object",
1036
+ entries: [["value", lit(String(item?.value ?? ""))], ["label", writer.text(item?.label, ctx, c.id, `option ${index}`)]]
1037
+ }))
1038
+ },
1039
+ ...boundProps(writer, c, ctx, "text")
1040
+ });
1041
+ },
1042
+ IconButton(writer, c, ctx) {
1043
+ const handler = actionHandler(writer, c, ctx);
1044
+ const href = c.href === void 0 ? handler.href : optionalLit(safeHref(writer.resolve(c.href, ctx.scope)));
1045
+ return el(writer, "IconButton", {
1046
+ icon: lit(iconFor(c.icon)),
1047
+ label: lit(typeof c.label === "string" && c.label ? c.label : humanize(actionName(c) || iconFor(c.icon))),
1048
+ tone: optionalLit(choose(c.tone, [
1049
+ "ghost",
1050
+ "primary",
1051
+ "danger"
1052
+ ])),
1053
+ href,
1054
+ onClick: href ? void 0 : handler.onClick
1055
+ });
1056
+ },
1057
+ NavBar(writer, c, ctx) {
1058
+ const actions = childList(writer, c.actions, ctx);
1059
+ return el(writer, "NavBar", {
1060
+ brand: lit(typeof c.brand === "string" ? c.brand : ""),
1061
+ mark: optionalLit(typeof c.mark === "string" ? c.mark : void 0),
1062
+ links: optionalLit(navLinks(c.links)),
1063
+ actions: actions.length ? {
1064
+ kind: "jsx",
1065
+ node: actions.length === 1 ? actions[0] : {
1066
+ type: "fragment",
1067
+ children: actions
1068
+ }
1069
+ } : void 0
1070
+ });
1071
+ },
1072
+ TabBar(writer, c) {
1073
+ return el(writer, "TabBar", {
1074
+ items: lit((Array.isArray(c.items) ? c.items : []).map((item) => ({
1075
+ label: String(item?.label ?? ""),
1076
+ href: safeHref(item?.href) ?? "#",
1077
+ icon: iconFor(item?.icon),
1078
+ ...item?.current === true ? { current: true } : {}
1079
+ }))),
1080
+ position: lit("static")
1081
+ });
1082
+ },
1083
+ SideNav(writer, c) {
1084
+ const sections = (Array.isArray(c.sections) ? c.sections : []).map((section) => ({
1085
+ ...typeof section?.title === "string" ? { title: section.title } : {},
1086
+ items: navLinks(section?.items)
1087
+ }));
1088
+ return el(writer, "SideNav", {
1089
+ label: lit(typeof c.label === "string" ? c.label : "Navigation"),
1090
+ sections: lit(sections)
1091
+ });
1092
+ },
1093
+ Breadcrumbs(writer, c) {
1094
+ return el(writer, "Breadcrumbs", { items: lit((Array.isArray(c.items) ? c.items : []).map((item) => {
1095
+ const href = safeHref(item?.href);
1096
+ return {
1097
+ label: String(item?.label ?? ""),
1098
+ ...href ? { href } : {}
1099
+ };
1100
+ })) });
1101
+ },
1102
+ Menu(writer, c, ctx) {
1103
+ const items = (Array.isArray(c.items) ? c.items : []).map((item) => {
1104
+ const href = safeHref(item?.href);
1105
+ const handler = href ? {} : actionHandler(writer, {
1106
+ id: c.id,
1107
+ component: "Button",
1108
+ action: item?.action
1109
+ }, ctx);
1110
+ return {
1111
+ kind: "object",
1112
+ entries: [
1113
+ ["label", lit(String(item?.label ?? ""))],
1114
+ ["icon", typeof item?.icon === "string" ? lit(iconFor(item.icon)) : void 0],
1115
+ ["tone", item?.tone === "danger" ? lit("danger") : void 0],
1116
+ ["disabled", item?.disabled === true || !href && !handler.onClick && !handler.href ? lit(true) : void 0],
1117
+ ["href", href ? lit(href) : handler.href],
1118
+ ["onSelect", handler.onClick]
1119
+ ].filter((entry) => entry[1] !== void 0)
1120
+ };
1121
+ });
1122
+ return el(writer, "Menu", {
1123
+ trigger: {
1124
+ kind: "jsx",
1125
+ node: triggerElement(writer, c.trigger, ctx)
1126
+ },
1127
+ items: {
1128
+ kind: "array",
1129
+ items
1130
+ },
1131
+ label: optionalLit(typeof c.label === "string" ? c.label : void 0),
1132
+ placement: optionalLit(choose(c.placement, [
1133
+ "top",
1134
+ "start",
1135
+ "end"
1136
+ ])),
1137
+ align: optionalLit(choose(c.align, ["center", "end"]))
1138
+ });
1139
+ },
1140
+ Popover(writer, c, ctx) {
1141
+ return el(writer, "Popover", {
1142
+ trigger: {
1143
+ kind: "jsx",
1144
+ node: triggerElement(writer, c.trigger, ctx)
1145
+ },
1146
+ title: writer.textOrUndefined(c.title, ctx, c.id, "title"),
1147
+ label: optionalLit(typeof c.label === "string" ? c.label : void 0),
1148
+ placement: optionalLit(choose(c.placement, [
1149
+ "top",
1150
+ "start",
1151
+ "end"
1152
+ ])),
1153
+ align: optionalLit(choose(c.align, ["center", "end"]))
1154
+ }, [oneChild(writer, c.child, ctx)]);
1155
+ },
1156
+ Tooltip(writer, c, ctx) {
1157
+ const child = typeof c.child === "string" ? writer.component(c.child) : void 0;
1158
+ const inner = oneChild(writer, c.child, ctx);
1159
+ if (typeof c.content !== "string" || !(child?.component === "Button" || child?.component === "IconButton")) return inner;
1160
+ return el(writer, "Tooltip", {
1161
+ content: lit(c.content),
1162
+ type: lit("description"),
1163
+ placement: optionalLit(choose(c.placement, [
1164
+ "top",
1165
+ "start",
1166
+ "end"
1167
+ ]))
1168
+ }, [inner]);
1169
+ },
1170
+ Spinner(writer, c, ctx) {
1171
+ return el(writer, "Spinner", {
1172
+ label: writer.textOrUndefined(c.label, ctx, c.id, "label"),
1173
+ size: optionalLit(choose(c.size, ["sm", "lg"]))
1174
+ });
1175
+ },
1176
+ Skeleton(writer, c) {
1177
+ const length = (value) => typeof value === "string" && /^\d+(\.\d+)?(rem|em|ch|px|%)$/.test(value) ? lit(value) : void 0;
1178
+ return el(writer, "Skeleton", {
1179
+ variant: optionalLit(choose(c.variant, ["rect", "circle"])),
1180
+ lines: typeof c.lines === "number" ? lit(c.lines) : void 0,
1181
+ width: length(c.width),
1182
+ height: length(c.height)
1183
+ });
1184
+ }
1185
+ };
1186
+ /** A Menu or Popover trigger: the Button or IconButton without its action. */
1187
+ function triggerElement(writer, id, ctx) {
1188
+ const component = typeof id === "string" ? writer.component(id) : void 0;
1189
+ if (component?.component === "IconButton") return el(writer, "IconButton", {
1190
+ icon: lit(iconFor(component.icon)),
1191
+ label: lit(typeof component.label === "string" && component.label ? component.label : humanize(iconFor(component.icon))),
1192
+ tone: optionalLit(choose(component.tone, [
1193
+ "ghost",
1194
+ "primary",
1195
+ "danger"
1196
+ ]))
1197
+ });
1198
+ const { label, icon } = component?.component === "Button" ? buttonLabel(writer, component.child, ctx) : {
1199
+ label: void 0,
1200
+ icon: void 0
1201
+ };
1202
+ if (!label && icon && component) return el(writer, "IconButton", {
1203
+ icon: lit(icon),
1204
+ label: component.accessibility?.label !== void 0 ? writer.text(component.accessibility.label, ctx, component.id, "label") : lit(humanize(icon))
1205
+ });
1206
+ return el(writer, "Button", {
1207
+ tone: lit({
1208
+ primary: "primary",
1209
+ borderless: "ghost"
1210
+ }[String(component?.variant)] ?? "secondary"),
1211
+ leadingIcon: optionalLit(icon ?? (typeof component?.icon === "string" ? component.icon : void 0))
1212
+ }, [textNode(label ?? lit(humanize(String(id ?? "")) || "Open"))]);
1213
+ }
1214
+ function mediaLink(writer, c, ctx) {
1215
+ const url = safeHref(writer.resolve(c.url, ctx.scope)) ?? "#";
1216
+ return el(writer, "Link", {
1217
+ href: lit(url),
1218
+ variant: lit("standalone"),
1219
+ external: url.startsWith("https:") ? lit(true) : void 0
1220
+ }, [textNode(lit(c.component === "Video" ? "Open the video" : "Open the audio"))]);
1221
+ }
1222
+ function navLinks(value) {
1223
+ if (!Array.isArray(value) || value.length === 0) return void 0;
1224
+ return value.map((item) => ({
1225
+ label: String(item?.label ?? ""),
1226
+ href: safeHref(item?.href) ?? "#",
1227
+ ...item?.current === true ? { current: true } : {}
1228
+ }));
1229
+ }
1230
+ /** List items as a JSX array, or a mapped template passed straight through. */
1231
+ function listItemsExpr(nodes) {
1232
+ if (nodes.length === 1 && nodes[0].type === "expr") return nodes[0].expr;
1233
+ return {
1234
+ kind: "jsxList",
1235
+ nodes: nodes.map((node, index) => node.type === "element" ? {
1236
+ ...node,
1237
+ props: [["key", lit(String(index))], ...node.props]
1238
+ } : node)
1239
+ };
1240
+ }
1241
+ var pad = (depth) => " ".repeat(depth);
1242
+ function quote(text) {
1243
+ const escaped = text.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
1244
+ if (escaped.includes("'") && !escaped.includes("\"")) return `"${escaped}"`;
1245
+ return `'${escaped.replace(/'/g, "\\'")}'`;
1246
+ }
1247
+ function printValue(value, depth) {
1248
+ if (value === void 0) return "undefined";
1249
+ if (value === null) return "null";
1250
+ if (typeof value === "string") return quote(value);
1251
+ if (typeof value !== "object") return String(value);
1252
+ if (Array.isArray(value)) {
1253
+ if (value.length === 0) return "[]";
1254
+ const items = value.map((item) => printValue(item, depth + 1));
1255
+ const flat = `[${items.join(", ")}]`;
1256
+ if (flat.length <= 60 && !flat.includes("\n")) return flat;
1257
+ return `[\n${items.map((item) => `${pad(depth + 1)}${item},`).join("\n")}\n${pad(depth)}]`;
1258
+ }
1259
+ const entries = Object.entries(value).filter(([, item]) => item !== void 0);
1260
+ if (entries.length === 0) return "{}";
1261
+ const parts = entries.map(([key, item]) => `${isIdentifier(key) ? key : quote(key)}: ${printValue(item, depth + 1)}`);
1262
+ const flat = `{ ${parts.join(", ")} }`;
1263
+ if (flat.length <= 60 && !flat.includes("\n")) return flat;
1264
+ return `{\n${parts.map((part) => `${pad(depth + 1)}${part},`).join("\n")}\n${pad(depth)}}`;
1265
+ }
1266
+ function printExpr(expr, depth) {
1267
+ switch (expr.kind) {
1268
+ case "lit": return printValue(expr.value, depth);
1269
+ case "code": return expr.code;
1270
+ case "map": {
1271
+ const body = expr.body.flatMap((node) => printNode(node, depth + 1));
1272
+ return `${expr.list}.map(${expr.params} => (\n${body.join("\n")}\n${pad(depth)}))`;
1273
+ }
1274
+ case "jsx": return printJsxExpression(expr.node, depth);
1275
+ case "jsxList":
1276
+ if (expr.nodes.length === 0) return "[]";
1277
+ return `[\n${expr.nodes.map((node) => `${printNode(node, depth + 1).join("\n")},`).join("\n")}\n${pad(depth)}]`;
1278
+ case "array": {
1279
+ if (expr.items.length === 0) return "[]";
1280
+ const items = expr.items.map((item) => printExpr(item, depth + 1));
1281
+ const flat = `[${items.join(", ")}]`;
1282
+ if (flat.length <= 60 && !flat.includes("\n")) return flat;
1283
+ return `[\n${items.map((item) => `${pad(depth + 1)}${item},`).join("\n")}\n${pad(depth)}]`;
1284
+ }
1285
+ case "object": {
1286
+ if (expr.entries.length === 0) return "{}";
1287
+ const parts = expr.entries.map(([key, item]) => `${isIdentifier(key) ? key : quote(key)}: ${printExpr(item, depth + 1)}`);
1288
+ const flat = `{ ${parts.join(", ")} }`;
1289
+ if (flat.length <= 60 && !flat.includes("\n")) return flat;
1290
+ return `{\n${parts.map((part) => `${pad(depth + 1)}${part},`).join("\n")}\n${pad(depth)}}`;
1291
+ }
1292
+ }
1293
+ }
1294
+ function printJsxExpression(node, depth) {
1295
+ const lines = printNode(node, depth + 1);
1296
+ if (lines.length === 1) return lines[0].trim();
1297
+ return `(\n${lines.join("\n")}\n${pad(depth)})`;
1298
+ }
1299
+ function printProp([name, expr], depth) {
1300
+ if (expr.kind === "lit") {
1301
+ const value = expr.value;
1302
+ if (value === true) return name;
1303
+ if (typeof value === "string" && !/["\\\n{}&<>]/.test(value)) return `${name}="${value}"`;
1304
+ }
1305
+ return `${name}={${printExpr(expr, depth)}}`;
1306
+ }
1307
+ function printText(value) {
1308
+ const text = value.replace(/\s+/g, " ").trim();
1309
+ if (text === "") return "";
1310
+ return /[{}<>&]/.test(text) || text !== value.trim() ? `{${quote(value.trim())}}` : text;
1311
+ }
1312
+ function printNode(node, depth) {
1313
+ const indent = pad(depth);
1314
+ switch (node.type) {
1315
+ case "text": {
1316
+ const text = printText(node.value);
1317
+ return text ? [`${indent}${text}`] : [];
1318
+ }
1319
+ case "comment": return [`${indent}{/* ${node.text.replace(/\*\//g, "* /")} */}`];
1320
+ case "expr": return [`${indent}{${printExpr(node.expr, depth)}}`];
1321
+ case "fragment":
1322
+ if (node.children.length === 1) return printNode(node.children[0], depth);
1323
+ return [
1324
+ `${indent}<>`,
1325
+ ...node.children.flatMap((child) => printNode(child, depth + 1)),
1326
+ `${indent}</>`
1327
+ ];
1328
+ case "element": {
1329
+ const props = node.props.map((prop) => printProp(prop, depth + 1));
1330
+ const inlineProps = props.length ? ` ${props.join(" ")}` : "";
1331
+ const multiline = props.some((prop) => prop.includes("\n")) || indent.length + node.tag.length + inlineProps.length > 76;
1332
+ const open = multiline ? [`${indent}<${node.tag}`, ...props.map((prop) => `${pad(depth + 1)}${prop}`)] : [`${indent}<${node.tag}${inlineProps}`];
1333
+ const children = node.children.flatMap((child) => printNode(child, depth + 1));
1334
+ if (children.length === 0) return multiline ? [...open, `${indent}/>`] : [`${open[0]} />`];
1335
+ if (node.children.length === 1 && (node.children[0].type === "text" || node.children[0].type === "expr" && node.children[0].expr.kind === "code") && children.length === 1 && !multiline) {
1336
+ const line = `${open[0]}>${children[0].trim()}</${node.tag}>`;
1337
+ if (line.length <= 80) return [line];
1338
+ }
1339
+ return [
1340
+ ...multiline ? [...open, `${indent}>`] : [`${open[0]}>`],
1341
+ ...children,
1342
+ `${indent}</${node.tag}>`
1343
+ ];
1344
+ }
1345
+ }
1346
+ }
1347
+ /** Convert a surface to a TSX module that renders it with Derelicious. */
1348
+ function surfaceToTsx(processor, surfaceId, options = {}) {
1349
+ const name = options.componentName ?? "GeneratedScreen";
1350
+ const writer = new Writer(processor, surfaceId, options.headingLevel ?? 1);
1351
+ writer.collectFields();
1352
+ const body = processor.getComponent(surfaceId, "root") ? generate(writer, "root", {
1353
+ scope: "",
1354
+ trail: []
1355
+ }) : [];
1356
+ const root = body.length === 1 ? body[0] : {
1357
+ type: "fragment",
1358
+ children: body
1359
+ };
1360
+ const jsx = body.length ? printNode(root, 2) : [`${pad(2)}null`];
1361
+ const state = [];
1362
+ if (writer.fields.size > 0) {
1363
+ writer.reactImports.add("useState");
1364
+ state.push("const [values, setValues] = useState({");
1365
+ for (const field of writer.fields.values()) {
1366
+ const initial = printValue(field.initial, 1);
1367
+ const cast = field.kind === "list" ? " as string[]" : "";
1368
+ state.push(` ${field.name}: ${initial}${cast},`);
1369
+ }
1370
+ state.push("})", "const update = (patch: Partial<typeof values>) =>", " setValues((current) => ({ ...current, ...patch }))");
1371
+ }
1372
+ const lines = [];
1373
+ if (writer.reactImports.size) lines.push(`import { ${[...writer.reactImports].sort().join(", ")} } from 'react'`);
1374
+ if (writer.imports.size) lines.push(`import { ${[...writer.imports].sort((a, b) => a.localeCompare(b)).join(", ")} } from '@derelicious/ds'`);
1375
+ lines.push("");
1376
+ for (const [constName, value] of writer.hoisted) lines.push(`const ${constName} = ${printValue(value, 0)} as const`, "");
1377
+ if (writer.usesActions) lines.push(`type ${name}Props = {`, " /** Called with the action name and its context when a button is pressed. */", " onAction?: (name: string, context?: Record<string, unknown>) => void", "}", "", `export function ${name}({ onAction }: ${name}Props) {`);
1378
+ else lines.push(`export function ${name}() {`);
1379
+ const toastHook = writer.usesToast ? ["const { toast } = useToast()"] : [];
1380
+ for (const line of [
1381
+ ...state,
1382
+ ...toastHook,
1383
+ ...writer.hooks
1384
+ ]) lines.push(` ${line}`);
1385
+ if (state.length || toastHook.length || writer.hooks.length) lines.push("");
1386
+ lines.push(" return (", ...jsx, " )", "}", "");
1387
+ return lines.join("\n");
1388
+ }
1389
+ export { surfaceToTsx };