@antheo/morph 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (464) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +266 -2
  3. package/SKILL.md +61 -0
  4. package/dist/ai/cli-provider.d.ts +80 -0
  5. package/dist/ai/cli-provider.js +250 -0
  6. package/dist/ai/gate.d.ts +39 -0
  7. package/dist/ai/gate.js +124 -0
  8. package/dist/ai/provider.d.ts +36 -0
  9. package/dist/ai/provider.js +168 -0
  10. package/dist/ai/repair.d.ts +90 -0
  11. package/dist/ai/repair.js +172 -0
  12. package/dist/analyzer/deps.d.ts +30 -0
  13. package/dist/analyzer/deps.js +265 -0
  14. package/dist/analyzer/manifest.d.ts +5 -0
  15. package/dist/analyzer/manifest.js +119 -0
  16. package/dist/analyzer/parse.d.ts +21 -0
  17. package/dist/analyzer/parse.js +29 -0
  18. package/dist/batch-worker.d.ts +16 -0
  19. package/dist/batch-worker.js +10 -0
  20. package/dist/batch.d.ts +26 -0
  21. package/dist/batch.js +227 -0
  22. package/dist/bridge/index.d.ts +26 -0
  23. package/dist/bridge/index.js +138 -0
  24. package/dist/bridge/props.d.ts +56 -0
  25. package/dist/bridge/props.js +191 -0
  26. package/dist/bridge/wrappers.d.ts +24 -0
  27. package/dist/bridge/wrappers.js +276 -0
  28. package/dist/cli/format.d.ts +7 -0
  29. package/dist/cli/format.js +30 -0
  30. package/dist/cli.d.ts +2 -0
  31. package/dist/cli.js +492 -0
  32. package/dist/fonts/carry.d.ts +34 -0
  33. package/dist/fonts/carry.js +113 -0
  34. package/dist/fonts/fallback.d.ts +11 -0
  35. package/dist/fonts/fallback.js +21 -0
  36. package/dist/fonts/google.d.ts +65 -0
  37. package/dist/fonts/google.js +343 -0
  38. package/dist/fonts/index.d.ts +27 -0
  39. package/dist/fonts/index.js +48 -0
  40. package/dist/fonts/local.d.ts +46 -0
  41. package/dist/fonts/local.js +150 -0
  42. package/dist/fonts/sfnt.d.ts +19 -0
  43. package/dist/fonts/sfnt.js +174 -0
  44. package/dist/fonts/shim.d.ts +14 -0
  45. package/dist/fonts/shim.js +96 -0
  46. package/dist/gate.d.ts +105 -0
  47. package/dist/gate.js +157 -0
  48. package/dist/index.d.ts +55 -0
  49. package/dist/index.js +74 -0
  50. package/dist/ir/annotate.d.ts +16 -0
  51. package/dist/ir/annotate.js +145 -0
  52. package/dist/ir/as-child.d.ts +18 -0
  53. package/dist/ir/as-child.js +239 -0
  54. package/dist/ir/compounds.d.ts +27 -0
  55. package/dist/ir/compounds.js +183 -0
  56. package/dist/ir/contexts.d.ts +26 -0
  57. package/dist/ir/contexts.js +185 -0
  58. package/dist/ir/dom.d.ts +11 -0
  59. package/dist/ir/dom.js +60 -0
  60. package/dist/ir/effect-returns.d.ts +10 -0
  61. package/dist/ir/effect-returns.js +25 -0
  62. package/dist/ir/extract-ui-types.d.ts +33 -0
  63. package/dist/ir/extract-ui-types.js +224 -0
  64. package/dist/ir/extract-ui.d.ts +34 -0
  65. package/dist/ir/extract-ui.js +567 -0
  66. package/dist/ir/falsy.d.ts +13 -0
  67. package/dist/ir/falsy.js +66 -0
  68. package/dist/ir/forward-refs.d.ts +11 -0
  69. package/dist/ir/forward-refs.js +155 -0
  70. package/dist/ir/fragment-source.d.ts +4 -0
  71. package/dist/ir/fragment-source.js +13 -0
  72. package/dist/ir/fragments.d.ts +32 -0
  73. package/dist/ir/fragments.js +192 -0
  74. package/dist/ir/helper-snippets.d.ts +30 -0
  75. package/dist/ir/helper-snippets.js +550 -0
  76. package/dist/ir/latest-refs.d.ts +11 -0
  77. package/dist/ir/latest-refs.js +187 -0
  78. package/dist/ir/live-args.d.ts +26 -0
  79. package/dist/ir/live-args.js +335 -0
  80. package/dist/ir/lower.d.ts +83 -0
  81. package/dist/ir/lower.js +6016 -0
  82. package/dist/ir/markup-values.d.ts +16 -0
  83. package/dist/ir/markup-values.js +188 -0
  84. package/dist/ir/model.d.ts +605 -0
  85. package/dist/ir/model.js +1 -0
  86. package/dist/ir/oracle.d.ts +91 -0
  87. package/dist/ir/oracle.js +610 -0
  88. package/dist/ir/radix.d.ts +122 -0
  89. package/dist/ir/radix.js +344 -0
  90. package/dist/ir/rename.d.ts +15 -0
  91. package/dist/ir/rename.js +151 -0
  92. package/dist/ir/render-props.d.ts +31 -0
  93. package/dist/ir/render-props.js +67 -0
  94. package/dist/ir/rewrite.d.ts +44 -0
  95. package/dist/ir/rewrite.js +381 -0
  96. package/dist/ir/running-index.d.ts +11 -0
  97. package/dist/ir/running-index.js +217 -0
  98. package/dist/ir/snapshots.d.ts +12 -0
  99. package/dist/ir/snapshots.js +140 -0
  100. package/dist/ir/style.d.ts +19 -0
  101. package/dist/ir/style.js +76 -0
  102. package/dist/ir/types.d.ts +42 -0
  103. package/dist/ir/types.js +271 -0
  104. package/dist/ir/walk.d.ts +11 -0
  105. package/dist/ir/walk.js +18 -0
  106. package/dist/mcp/server.d.ts +81 -0
  107. package/dist/mcp/server.js +518 -0
  108. package/dist/pipeline.d.ts +26 -0
  109. package/dist/pipeline.js +750 -0
  110. package/dist/registry/add.d.ts +91 -0
  111. package/dist/registry/add.js +273 -0
  112. package/dist/registry/fetch.d.ts +40 -0
  113. package/dist/registry/fetch.js +186 -0
  114. package/dist/registry/ip.d.ts +18 -0
  115. package/dist/registry/ip.js +153 -0
  116. package/dist/registry/item.d.ts +39 -0
  117. package/dist/registry/item.js +131 -0
  118. package/dist/registry/load.d.ts +35 -0
  119. package/dist/registry/load.js +106 -0
  120. package/dist/registry/paths.d.ts +8 -0
  121. package/dist/registry/paths.js +43 -0
  122. package/dist/registry/publish.d.ts +119 -0
  123. package/dist/registry/publish.js +439 -0
  124. package/dist/targets/angular/bank/bank.d.ts +39 -0
  125. package/dist/targets/angular/bank/bank.js +61 -0
  126. package/dist/targets/angular/bank/helpers.d.ts +64 -0
  127. package/dist/targets/angular/bank/helpers.js +246 -0
  128. package/dist/targets/angular/bank/kept.d.ts +98 -0
  129. package/dist/targets/angular/bank/kept.js +791 -0
  130. package/dist/targets/angular/bank/plan-helpers.d.ts +17 -0
  131. package/dist/targets/angular/bank/plan-helpers.js +286 -0
  132. package/dist/targets/angular/bank/plan.d.ts +22 -0
  133. package/dist/targets/angular/bank/plan.js +152 -0
  134. package/dist/targets/angular/bank/receivers.d.ts +66 -0
  135. package/dist/targets/angular/bank/receivers.js +293 -0
  136. package/dist/targets/angular/bank/runtime.d.ts +14 -0
  137. package/dist/targets/angular/bank/runtime.js +152 -0
  138. package/dist/targets/angular/controlled.d.ts +7 -0
  139. package/dist/targets/angular/controlled.js +37 -0
  140. package/dist/targets/angular/dynamic-tags.d.ts +34 -0
  141. package/dist/targets/angular/dynamic-tags.js +192 -0
  142. package/dist/targets/angular/emit.d.ts +41 -0
  143. package/dist/targets/angular/emit.js +5970 -0
  144. package/dist/targets/angular/exports.d.ts +48 -0
  145. package/dist/targets/angular/exports.js +243 -0
  146. package/dist/targets/angular/helpers.d.ts +15 -0
  147. package/dist/targets/angular/helpers.js +33 -0
  148. package/dist/targets/angular/host-boundary.d.ts +5 -0
  149. package/dist/targets/angular/host-boundary.js +166 -0
  150. package/dist/targets/angular/host-form.d.ts +150 -0
  151. package/dist/targets/angular/host-form.js +727 -0
  152. package/dist/targets/angular/markup-values.d.ts +58 -0
  153. package/dist/targets/angular/markup-values.js +661 -0
  154. package/dist/targets/angular/motion-directive.d.ts +12 -0
  155. package/dist/targets/angular/motion-directive.js +257 -0
  156. package/dist/targets/angular/motion-hooks.d.ts +73 -0
  157. package/dist/targets/angular/motion-hooks.js +293 -0
  158. package/dist/targets/angular/motion-layout.d.ts +14 -0
  159. package/dist/targets/angular/motion-layout.js +74 -0
  160. package/dist/targets/angular/motion-templates.d.ts +10 -0
  161. package/dist/targets/angular/motion-templates.js +65 -0
  162. package/dist/targets/angular/motion.d.ts +57 -0
  163. package/dist/targets/angular/motion.js +202 -0
  164. package/dist/targets/angular/narrowing.d.ts +24 -0
  165. package/dist/targets/angular/narrowing.js +205 -0
  166. package/dist/targets/angular/ngc.d.ts +23 -0
  167. package/dist/targets/angular/ngc.js +134 -0
  168. package/dist/targets/angular/passed-handle.d.ts +39 -0
  169. package/dist/targets/angular/passed-handle.js +154 -0
  170. package/dist/targets/angular/projected.d.ts +9 -0
  171. package/dist/targets/angular/projected.js +63 -0
  172. package/dist/targets/angular/radix/cores/alert-dialog.d.ts +13 -0
  173. package/dist/targets/angular/radix/cores/alert-dialog.js +388 -0
  174. package/dist/targets/angular/radix/cores/index.d.ts +17 -0
  175. package/dist/targets/angular/radix/cores/index.js +50 -0
  176. package/dist/targets/angular/radix/cores/slider.d.ts +8 -0
  177. package/dist/targets/angular/radix/cores/slider.js +202 -0
  178. package/dist/targets/angular/radix/index.d.ts +21 -0
  179. package/dist/targets/angular/radix/index.js +35 -0
  180. package/dist/targets/angular/radix/packages.d.ts +3 -0
  181. package/dist/targets/angular/radix/packages.js +558 -0
  182. package/dist/targets/angular/radix/part.d.ts +236 -0
  183. package/dist/targets/angular/radix/part.js +71 -0
  184. package/dist/targets/angular/radix/prepare.d.ts +66 -0
  185. package/dist/targets/angular/radix/prepare.js +548 -0
  186. package/dist/targets/angular/radix/template.d.ts +43 -0
  187. package/dist/targets/angular/radix/template.js +172 -0
  188. package/dist/targets/angular/refs.d.ts +68 -0
  189. package/dist/targets/angular/refs.js +443 -0
  190. package/dist/targets/angular/slots.d.ts +22 -0
  191. package/dist/targets/angular/slots.js +60 -0
  192. package/dist/targets/angular/source-types.d.ts +10 -0
  193. package/dist/targets/angular/source-types.js +45 -0
  194. package/dist/targets/angular/spread-forward.d.ts +24 -0
  195. package/dist/targets/angular/spread-forward.js +72 -0
  196. package/dist/targets/angular/spread.d.ts +32 -0
  197. package/dist/targets/angular/spread.js +182 -0
  198. package/dist/targets/angular/svg-hosts.d.ts +25 -0
  199. package/dist/targets/angular/svg-hosts.js +107 -0
  200. package/dist/targets/angular/template-expr.d.ts +36 -0
  201. package/dist/targets/angular/template-expr.js +287 -0
  202. package/dist/targets/angular/types.d.ts +9 -0
  203. package/dist/targets/angular/types.js +63 -0
  204. package/dist/targets/angular/walk.d.ts +11 -0
  205. package/dist/targets/angular/walk.js +26 -0
  206. package/dist/targets/react-native/emit.d.ts +14 -0
  207. package/dist/targets/react-native/emit.js +585 -0
  208. package/dist/targets/react-native/fidelity.d.ts +5 -0
  209. package/dist/targets/react-native/fidelity.js +43 -0
  210. package/dist/targets/react-native/motion.d.ts +10 -0
  211. package/dist/targets/react-native/motion.js +290 -0
  212. package/dist/targets/react-native/skia.d.ts +30 -0
  213. package/dist/targets/react-native/skia.js +358 -0
  214. package/dist/targets/shared/context.d.ts +47 -0
  215. package/dist/targets/shared/context.js +195 -0
  216. package/dist/targets/shared/foreign.d.ts +10 -0
  217. package/dist/targets/shared/foreign.js +72 -0
  218. package/dist/targets/shared/fragments.d.ts +21 -0
  219. package/dist/targets/shared/fragments.js +309 -0
  220. package/dist/targets/shared/handles.d.ts +65 -0
  221. package/dist/targets/shared/handles.js +299 -0
  222. package/dist/targets/shared/inline.d.ts +53 -0
  223. package/dist/targets/shared/inline.js +524 -0
  224. package/dist/targets/shared/layout.d.ts +70 -0
  225. package/dist/targets/shared/layout.js +224 -0
  226. package/dist/targets/shared/markup.d.ts +26 -0
  227. package/dist/targets/shared/markup.js +65 -0
  228. package/dist/targets/shared/module.d.ts +84 -0
  229. package/dist/targets/shared/module.js +468 -0
  230. package/dist/targets/shared/motion-hooks.d.ts +37 -0
  231. package/dist/targets/shared/motion-hooks.js +87 -0
  232. package/dist/targets/shared/motion-layout.d.ts +70 -0
  233. package/dist/targets/shared/motion-layout.js +392 -0
  234. package/dist/targets/shared/portal.d.ts +10 -0
  235. package/dist/targets/shared/portal.js +23 -0
  236. package/dist/targets/shared/prop-writes.d.ts +11 -0
  237. package/dist/targets/shared/prop-writes.js +32 -0
  238. package/dist/targets/shared/prune.d.ts +54 -0
  239. package/dist/targets/shared/prune.js +405 -0
  240. package/dist/targets/shared/react-libs.d.ts +25 -0
  241. package/dist/targets/shared/react-libs.js +142 -0
  242. package/dist/targets/shared/react-types.d.ts +16 -0
  243. package/dist/targets/shared/react-types.js +374 -0
  244. package/dist/targets/shared/react-values.d.ts +20 -0
  245. package/dist/targets/shared/react-values.js +145 -0
  246. package/dist/targets/shared/ref-callback.d.ts +16 -0
  247. package/dist/targets/shared/ref-callback.js +114 -0
  248. package/dist/targets/shared/script.d.ts +65 -0
  249. package/dist/targets/shared/script.js +406 -0
  250. package/dist/targets/shared/unused.d.ts +12 -0
  251. package/dist/targets/shared/unused.js +146 -0
  252. package/dist/targets/svelte/dom-spread.d.ts +27 -0
  253. package/dist/targets/svelte/dom-spread.js +146 -0
  254. package/dist/targets/svelte/emit.d.ts +15 -0
  255. package/dist/targets/svelte/emit.js +3784 -0
  256. package/dist/targets/svelte/handle-branches.d.ts +22 -0
  257. package/dist/targets/svelte/handle-branches.js +146 -0
  258. package/dist/targets/svelte/html-keys.d.ts +9 -0
  259. package/dist/targets/svelte/html-keys.js +40 -0
  260. package/dist/targets/svelte/markup-data/data.d.ts +51 -0
  261. package/dist/targets/svelte/markup-data/data.js +305 -0
  262. package/dist/targets/svelte/markup-data/helper.d.ts +12 -0
  263. package/dist/targets/svelte/markup-data/helper.js +81 -0
  264. package/dist/targets/svelte/markup-data/module-data.d.ts +21 -0
  265. package/dist/targets/svelte/markup-data/module-data.js +473 -0
  266. package/dist/targets/svelte/markup-data/sites.d.ts +52 -0
  267. package/dist/targets/svelte/markup-data/sites.js +303 -0
  268. package/dist/targets/svelte/motion-layout.d.ts +13 -0
  269. package/dist/targets/svelte/motion-layout.js +70 -0
  270. package/dist/targets/svelte/motion-table.d.ts +14 -0
  271. package/dist/targets/svelte/motion-table.js +308 -0
  272. package/dist/targets/svelte/motion.d.ts +46 -0
  273. package/dist/targets/svelte/motion.js +405 -0
  274. package/dist/targets/svelte/presence.d.ts +71 -0
  275. package/dist/targets/svelte/presence.js +318 -0
  276. package/dist/targets/svelte/radix/accordion.d.ts +9 -0
  277. package/dist/targets/svelte/radix/accordion.js +24 -0
  278. package/dist/targets/svelte/radix/aspect-ratio.d.ts +6 -0
  279. package/dist/targets/svelte/radix/aspect-ratio.js +8 -0
  280. package/dist/targets/svelte/radix/avatar.d.ts +6 -0
  281. package/dist/targets/svelte/radix/avatar.js +10 -0
  282. package/dist/targets/svelte/radix/checkbox.d.ts +10 -0
  283. package/dist/targets/svelte/radix/checkbox.js +24 -0
  284. package/dist/targets/svelte/radix/collapsible.d.ts +7 -0
  285. package/dist/targets/svelte/radix/collapsible.js +16 -0
  286. package/dist/targets/svelte/radix/context-menu.d.ts +8 -0
  287. package/dist/targets/svelte/radix/context-menu.js +49 -0
  288. package/dist/targets/svelte/radix/cores/alert-dialog.d.ts +17 -0
  289. package/dist/targets/svelte/radix/cores/alert-dialog.js +449 -0
  290. package/dist/targets/svelte/radix/cores/collapsible.d.ts +12 -0
  291. package/dist/targets/svelte/radix/cores/collapsible.js +214 -0
  292. package/dist/targets/svelte/radix/cores/core.d.ts +32 -0
  293. package/dist/targets/svelte/radix/cores/core.js +80 -0
  294. package/dist/targets/svelte/radix/cores/direction.d.ts +10 -0
  295. package/dist/targets/svelte/radix/cores/direction.js +64 -0
  296. package/dist/targets/svelte/radix/cores/index.d.ts +19 -0
  297. package/dist/targets/svelte/radix/cores/index.js +85 -0
  298. package/dist/targets/svelte/radix/cores/modal-layer.d.ts +11 -0
  299. package/dist/targets/svelte/radix/cores/modal-layer.js +244 -0
  300. package/dist/targets/svelte/radix/cores/presence.d.ts +12 -0
  301. package/dist/targets/svelte/radix/cores/presence.js +129 -0
  302. package/dist/targets/svelte/radix/cores/slider-logic.d.ts +10 -0
  303. package/dist/targets/svelte/radix/cores/slider-logic.js +287 -0
  304. package/dist/targets/svelte/radix/cores/slider.d.ts +13 -0
  305. package/dist/targets/svelte/radix/cores/slider.js +267 -0
  306. package/dist/targets/svelte/radix/dialog.d.ts +8 -0
  307. package/dist/targets/svelte/radix/dialog.js +20 -0
  308. package/dist/targets/svelte/radix/dropdown-menu.d.ts +9 -0
  309. package/dist/targets/svelte/radix/dropdown-menu.js +38 -0
  310. package/dist/targets/svelte/radix/emit.d.ts +12 -0
  311. package/dist/targets/svelte/radix/emit.js +1339 -0
  312. package/dist/targets/svelte/radix/hover-card.d.ts +7 -0
  313. package/dist/targets/svelte/radix/hover-card.js +22 -0
  314. package/dist/targets/svelte/radix/index.d.ts +12 -0
  315. package/dist/targets/svelte/radix/index.js +28 -0
  316. package/dist/targets/svelte/radix/label.d.ts +3 -0
  317. package/dist/targets/svelte/radix/label.js +5 -0
  318. package/dist/targets/svelte/radix/menubar.d.ts +7 -0
  319. package/dist/targets/svelte/radix/menubar.js +34 -0
  320. package/dist/targets/svelte/radix/navigation-menu.d.ts +8 -0
  321. package/dist/targets/svelte/radix/navigation-menu.js +25 -0
  322. package/dist/targets/svelte/radix/packages.d.ts +34 -0
  323. package/dist/targets/svelte/radix/packages.js +100 -0
  324. package/dist/targets/svelte/radix/part.d.ts +161 -0
  325. package/dist/targets/svelte/radix/part.js +85 -0
  326. package/dist/targets/svelte/radix/popover.d.ts +7 -0
  327. package/dist/targets/svelte/radix/popover.js +15 -0
  328. package/dist/targets/svelte/radix/progress.d.ts +11 -0
  329. package/dist/targets/svelte/radix/progress.js +27 -0
  330. package/dist/targets/svelte/radix/radio-group.d.ts +9 -0
  331. package/dist/targets/svelte/radix/radio-group.js +26 -0
  332. package/dist/targets/svelte/radix/scroll-area.d.ts +7 -0
  333. package/dist/targets/svelte/radix/scroll-area.js +19 -0
  334. package/dist/targets/svelte/radix/select.d.ts +13 -0
  335. package/dist/targets/svelte/radix/select.js +81 -0
  336. package/dist/targets/svelte/radix/separator.d.ts +3 -0
  337. package/dist/targets/svelte/radix/separator.js +5 -0
  338. package/dist/targets/svelte/radix/slider.d.ts +6 -0
  339. package/dist/targets/svelte/radix/slider.js +8 -0
  340. package/dist/targets/svelte/radix/switch.d.ts +6 -0
  341. package/dist/targets/svelte/radix/switch.js +10 -0
  342. package/dist/targets/svelte/radix/tabs.d.ts +8 -0
  343. package/dist/targets/svelte/radix/tabs.js +15 -0
  344. package/dist/targets/svelte/radix/toggle-group.d.ts +9 -0
  345. package/dist/targets/svelte/radix/toggle-group.js +17 -0
  346. package/dist/targets/svelte/radix/toggle.d.ts +6 -0
  347. package/dist/targets/svelte/radix/toggle.js +9 -0
  348. package/dist/targets/svelte/radix/tooltip.d.ts +6 -0
  349. package/dist/targets/svelte/radix/tooltip.js +24 -0
  350. package/dist/targets/svelte/strip.d.ts +2 -0
  351. package/dist/targets/svelte/strip.js +5 -0
  352. package/dist/targets/vue/emit.d.ts +15 -0
  353. package/dist/targets/vue/emit.js +4092 -0
  354. package/dist/targets/vue/events.d.ts +11 -0
  355. package/dist/targets/vue/events.js +13 -0
  356. package/dist/targets/vue/module-builders.d.ts +28 -0
  357. package/dist/targets/vue/module-builders.js +258 -0
  358. package/dist/targets/vue/motion-layout.d.ts +19 -0
  359. package/dist/targets/vue/motion-layout.js +79 -0
  360. package/dist/targets/vue/motion.d.ts +12 -0
  361. package/dist/targets/vue/motion.js +46 -0
  362. package/dist/targets/vue/radix/accordion.d.ts +3 -0
  363. package/dist/targets/vue/radix/accordion.js +12 -0
  364. package/dist/targets/vue/radix/alert-dialog.d.ts +6 -0
  365. package/dist/targets/vue/radix/alert-dialog.js +18 -0
  366. package/dist/targets/vue/radix/aspect-ratio.d.ts +6 -0
  367. package/dist/targets/vue/radix/aspect-ratio.js +8 -0
  368. package/dist/targets/vue/radix/avatar.d.ts +3 -0
  369. package/dist/targets/vue/radix/avatar.js +7 -0
  370. package/dist/targets/vue/radix/checkbox.d.ts +3 -0
  371. package/dist/targets/vue/radix/checkbox.js +9 -0
  372. package/dist/targets/vue/radix/collapsible.d.ts +7 -0
  373. package/dist/targets/vue/radix/collapsible.js +11 -0
  374. package/dist/targets/vue/radix/context-menu.d.ts +3 -0
  375. package/dist/targets/vue/radix/context-menu.js +30 -0
  376. package/dist/targets/vue/radix/dialog.d.ts +3 -0
  377. package/dist/targets/vue/radix/dialog.js +12 -0
  378. package/dist/targets/vue/radix/direction.d.ts +7 -0
  379. package/dist/targets/vue/radix/direction.js +9 -0
  380. package/dist/targets/vue/radix/dropdown-menu.d.ts +3 -0
  381. package/dist/targets/vue/radix/dropdown-menu.js +29 -0
  382. package/dist/targets/vue/radix/hover-card.d.ts +3 -0
  383. package/dist/targets/vue/radix/hover-card.js +11 -0
  384. package/dist/targets/vue/radix/index.d.ts +65 -0
  385. package/dist/targets/vue/radix/index.js +225 -0
  386. package/dist/targets/vue/radix/label.d.ts +3 -0
  387. package/dist/targets/vue/radix/label.js +5 -0
  388. package/dist/targets/vue/radix/menubar.d.ts +6 -0
  389. package/dist/targets/vue/radix/menubar.js +29 -0
  390. package/dist/targets/vue/radix/navigation-menu.d.ts +6 -0
  391. package/dist/targets/vue/radix/navigation-menu.js +21 -0
  392. package/dist/targets/vue/radix/part.d.ts +41 -0
  393. package/dist/targets/vue/radix/part.js +46 -0
  394. package/dist/targets/vue/radix/popover.d.ts +3 -0
  395. package/dist/targets/vue/radix/popover.js +11 -0
  396. package/dist/targets/vue/radix/progress.d.ts +3 -0
  397. package/dist/targets/vue/radix/progress.js +6 -0
  398. package/dist/targets/vue/radix/radio-group.d.ts +3 -0
  399. package/dist/targets/vue/radix/radio-group.js +10 -0
  400. package/dist/targets/vue/radix/scroll-area.d.ts +3 -0
  401. package/dist/targets/vue/radix/scroll-area.js +11 -0
  402. package/dist/targets/vue/radix/select.d.ts +3 -0
  403. package/dist/targets/vue/radix/select.js +29 -0
  404. package/dist/targets/vue/radix/separator.d.ts +3 -0
  405. package/dist/targets/vue/radix/separator.js +5 -0
  406. package/dist/targets/vue/radix/slider.d.ts +3 -0
  407. package/dist/targets/vue/radix/slider.js +13 -0
  408. package/dist/targets/vue/radix/switch.d.ts +3 -0
  409. package/dist/targets/vue/radix/switch.js +9 -0
  410. package/dist/targets/vue/radix/tabs.d.ts +3 -0
  411. package/dist/targets/vue/radix/tabs.js +12 -0
  412. package/dist/targets/vue/radix/toggle-group.d.ts +3 -0
  413. package/dist/targets/vue/radix/toggle-group.js +10 -0
  414. package/dist/targets/vue/radix/toggle.d.ts +3 -0
  415. package/dist/targets/vue/radix/toggle.js +8 -0
  416. package/dist/targets/vue/radix/tooltip.d.ts +3 -0
  417. package/dist/targets/vue/radix/tooltip.js +14 -0
  418. package/dist/targets/vue/render-fn/h.d.ts +52 -0
  419. package/dist/targets/vue/render-fn/h.js +442 -0
  420. package/dist/targets/vue/render-fn.d.ts +21 -0
  421. package/dist/targets/vue/render-fn.js +357 -0
  422. package/dist/targets/vue/slot.d.ts +9 -0
  423. package/dist/targets/vue/slot.js +57 -0
  424. package/dist/typecheck/host.d.ts +45 -0
  425. package/dist/typecheck/host.js +309 -0
  426. package/dist/typecheck/index.d.ts +16 -0
  427. package/dist/typecheck/index.js +17 -0
  428. package/dist/typecheck/lucide.d.ts +8 -0
  429. package/dist/typecheck/lucide.js +45 -0
  430. package/dist/typecheck/sourcemap.d.ts +9 -0
  431. package/dist/typecheck/sourcemap.js +54 -0
  432. package/dist/typecheck/svelte.d.ts +9 -0
  433. package/dist/typecheck/svelte.js +116 -0
  434. package/dist/typecheck/vue.d.ts +8 -0
  435. package/dist/typecheck/vue.js +78 -0
  436. package/dist/types.d.ts +446 -0
  437. package/dist/types.js +11 -0
  438. package/dist/utils/cleanup.d.ts +32 -0
  439. package/dist/utils/cleanup.js +119 -0
  440. package/dist/utils/errors.d.ts +7 -0
  441. package/dist/utils/errors.js +15 -0
  442. package/dist/utils/fs-safe.d.ts +14 -0
  443. package/dist/utils/fs-safe.js +64 -0
  444. package/dist/validate.d.ts +16 -0
  445. package/dist/validate.js +204 -0
  446. package/dist/verify/auto-steps.d.ts +107 -0
  447. package/dist/verify/auto-steps.js +471 -0
  448. package/dist/verify/bundle.d.ts +68 -0
  449. package/dist/verify/bundle.js +548 -0
  450. package/dist/verify/diff.d.ts +31 -0
  451. package/dist/verify/diff.js +133 -0
  452. package/dist/verify/leaks.d.ts +25 -0
  453. package/dist/verify/leaks.js +261 -0
  454. package/dist/verify/link-worker.d.ts +1 -0
  455. package/dist/verify/link-worker.js +27 -0
  456. package/dist/verify/runner.d.ts +57 -0
  457. package/dist/verify/runner.js +867 -0
  458. package/dist/verify/sandbox.d.ts +40 -0
  459. package/dist/verify/sandbox.js +496 -0
  460. package/dist/verify/steps.d.ts +42 -0
  461. package/dist/verify/steps.js +475 -0
  462. package/dist/verify/verdict.d.ts +15 -0
  463. package/dist/verify/verdict.js +19 -0
  464. package/package.json +118 -4
@@ -0,0 +1,22 @@
1
+ import type { ComponentIR, ElementNode } from '../../ir/model.js';
2
+ /**
3
+ * A forwarded ref put on one of several child components, each in its own branch (`if (a) return <A ref={ref}/>;
4
+ * return b ? <B ref={ref}/> : <C ref={ref}/>`), where every way through the markup renders exactly one of them. React's
5
+ * ref.current is the handle of the one rendered now. In Svelte each branch binds the same local (`bind:this={inner}`):
6
+ * the branch that mounts sets it, and the one that goes clears it only while it still holds its own instance, so the
7
+ * local holds the mounted child's exports, as React's ref holds its handle. Each member a parent reaches is exported as
8
+ * a getter (`const m = $derived(inner?.m); export { m }`), read when the parent reads it: the mounted child's function,
9
+ * or undefined when that child's handle has no such member, as `ref.current.m` reads in React.
10
+ */
11
+ /** The children the ref is put on, when there are two or more and every way through the markup renders one of them. */
12
+ export declare function branchTargets(comp: ComponentIR): ElementNode[] | null;
13
+ /**
14
+ * The members a parent's ref reaches on a component: its own handle's (see handleMemberNames), or, when it passes its
15
+ * ref on to one of several branch children, every member any of them has. Null when any of them is not known.
16
+ */
17
+ export declare function reachedMembers(comp: ComponentIR, childOf: (c: ComponentIR, tag: string) => ComponentIR | null, depth?: number): {
18
+ name: string;
19
+ fn: boolean;
20
+ }[] | null;
21
+ /** For each member, whether every target's exports have it (read plainly) or only some (read behind an `in` test). */
22
+ export declare function membersInEvery(comp: ComponentIR, childOf: (c: ComponentIR, tag: string) => ComponentIR | null): Map<string, boolean> | null;
@@ -0,0 +1,146 @@
1
+ import * as t from '@babel/types';
2
+ import { unwrap } from '../../ir/lower.js';
3
+ import { handleMemberNames, passesHandle, passesHandleEach } from '../shared/handles.js';
4
+ /**
5
+ * A forwarded ref put on one of several child components, each in its own branch (`if (a) return <A ref={ref}/>;
6
+ * return b ? <B ref={ref}/> : <C ref={ref}/>`), where every way through the markup renders exactly one of them. React's
7
+ * ref.current is the handle of the one rendered now. In Svelte each branch binds the same local (`bind:this={inner}`):
8
+ * the branch that mounts sets it, and the one that goes clears it only while it still holds its own instance, so the
9
+ * local holds the mounted child's exports, as React's ref holds its handle. Each member a parent reaches is exported as
10
+ * a getter (`const m = $derived(inner?.m); export { m }`), read when the parent reads it: the mounted child's function,
11
+ * or undefined when that child's handle has no such member, as `ref.current.m` reads in React.
12
+ */
13
+ /** The children the ref is put on, when there are two or more and every way through the markup renders one of them. */
14
+ export function branchTargets(comp) {
15
+ const name = comp.forwardRef;
16
+ if (!name)
17
+ return null;
18
+ const targets = [];
19
+ let other = false;
20
+ const collect = (n) => {
21
+ if (n.type === 'element') {
22
+ for (const a of n.attrs) {
23
+ if (a.kind === 'ref' && t.isIdentifier(unwrap(a.expr), { name })) {
24
+ if (n.component)
25
+ targets.push(n);
26
+ else
27
+ other = true;
28
+ }
29
+ if (a.kind === 'slotProp')
30
+ a.children.forEach(collect);
31
+ }
32
+ }
33
+ const kids = n.type === 'if' ? n.branches.flatMap((b) => b.children) : n.type === 'slot' ? n.fallback : 'children' in n ? n.children : [];
34
+ kids.forEach(collect);
35
+ };
36
+ collect(comp.template);
37
+ if (other || targets.length < 2 || scriptReads(comp, name))
38
+ return null;
39
+ // the same children by the shared rule (the ref read nowhere else in the markup either)
40
+ const each = passesHandleEach(comp);
41
+ if (!each || each.length !== targets.length || !each.every((n) => targets.includes(n)))
42
+ return null;
43
+ const set = new Set(targets);
44
+ // exactly one target on every way through: an if needs an else, and each branch reaches one
45
+ const count = (n) => {
46
+ if (set.has(n))
47
+ return 1;
48
+ if (n.type === 'element') {
49
+ // markup handed to a child as a prop renders when the child decides
50
+ if (n.attrs.some((a) => a.kind === 'slotProp' && a.children.some((c) => containsTarget(c, set))))
51
+ return null;
52
+ return sumOf(n.children);
53
+ }
54
+ if (n.type === 'fragment' || n.type === 'keyed')
55
+ return sumOf(n.children);
56
+ if (n.type === 'if') {
57
+ // with no else, the way through that renders nothing must hold no target either
58
+ if (n.branches[n.branches.length - 1]?.test !== null)
59
+ return n.branches.some((b) => b.children.some((c) => containsTarget(c, set))) ? null : 0;
60
+ const counts = n.branches.map((b) => sumOf(b.children));
61
+ const [first] = counts;
62
+ return first !== undefined && counts.every((c) => c === first) ? first : null;
63
+ }
64
+ // a loop, a slot, a value: the target is not inside it (collect found it elsewhere), or it is and the count is unknown
65
+ return containsTarget(n, set) ? null : 0;
66
+ };
67
+ const sumOf = (kids) => {
68
+ let total = 0;
69
+ for (const k of kids) {
70
+ const c = count(k);
71
+ if (c === null)
72
+ return null;
73
+ total += c;
74
+ }
75
+ return total;
76
+ };
77
+ return count(comp.template) === 1 ? targets : null;
78
+ }
79
+ /** Whether the component's own code reads the forwarded ref (it would then hold this component's exports, not React's). */
80
+ function scriptReads(comp, name) {
81
+ let found = false;
82
+ for (const item of comp.items) {
83
+ for (const value of Object.values(item)) {
84
+ for (const v of Array.isArray(value) ? value : [value]) {
85
+ if (!t.isNode(v))
86
+ continue;
87
+ t.traverseFast(v, (n) => {
88
+ if (t.isIdentifier(n) && comp.refs.get(n) === name)
89
+ found = true;
90
+ });
91
+ }
92
+ }
93
+ }
94
+ return found;
95
+ }
96
+ function containsTarget(n, set) {
97
+ if (set.has(n))
98
+ return true;
99
+ if (n.type === 'element' && n.attrs.some((a) => a.kind === 'slotProp' && a.children.some((c) => containsTarget(c, set))))
100
+ return true;
101
+ const kids = n.type === 'if' ? n.branches.flatMap((b) => b.children) : n.type === 'slot' ? n.fallback : 'children' in n ? n.children : [];
102
+ return kids.some((k) => containsTarget(k, set));
103
+ }
104
+ /**
105
+ * The members a parent's ref reaches on a component: its own handle's (see handleMemberNames), or, when it passes its
106
+ * ref on to one of several branch children, every member any of them has. Null when any of them is not known.
107
+ */
108
+ export function reachedMembers(comp, childOf, depth = 0) {
109
+ const own = handleMemberNames(comp, childOf);
110
+ if (own)
111
+ return own;
112
+ if (depth > 4 || passesHandle(comp))
113
+ return null;
114
+ const targets = branchTargets(comp);
115
+ if (!targets)
116
+ return null;
117
+ const all = new Map();
118
+ for (const target of targets) {
119
+ const child = childOf(comp, target.tag);
120
+ const members = child ? reachedMembers(child, childOf, depth + 1) : null;
121
+ if (!members)
122
+ return null;
123
+ for (const m of members)
124
+ all.set(m.name, (all.get(m.name) ?? true) && m.fn);
125
+ }
126
+ return [...all].map(([name, fn]) => ({ name, fn }));
127
+ }
128
+ /** For each member, whether every target's exports have it (read plainly) or only some (read behind an `in` test). */
129
+ export function membersInEvery(comp, childOf) {
130
+ const targets = branchTargets(comp);
131
+ if (!targets)
132
+ return null;
133
+ const sets = [];
134
+ for (const target of targets) {
135
+ const child = childOf(comp, target.tag);
136
+ const members = child ? reachedMembers(child, childOf) : null;
137
+ if (!members)
138
+ return null;
139
+ sets.push(new Set(members.map((m) => m.name)));
140
+ }
141
+ const out = new Map();
142
+ for (const s of sets)
143
+ for (const name of s)
144
+ out.set(name, sets.every((x) => x.has(name)));
145
+ return out;
146
+ }
@@ -0,0 +1,9 @@
1
+ import * as t from '@babel/types';
2
+ import type { WebContext } from '../shared/module.js';
3
+ /**
4
+ * `Pick<CardProps, 'value' | 'className'>` where CardProps takes React's HTML attributes (`extends
5
+ * React.HTMLAttributes<HTMLDivElement>`): Svelte's attribute types (svelte/elements) name the class attribute `class`,
6
+ * so the key React wrote as `className` is `class` there, in Pick and in Omit alike (an Omit of `className` would
7
+ * otherwise leave `class` in). Only when the type does not declare a `className` of its own.
8
+ */
9
+ export declare function svelteHtmlKeys<T extends t.Node>(node: T, ctx: WebContext): T;
@@ -0,0 +1,40 @@
1
+ import * as t from '@babel/types';
2
+ /**
3
+ * `Pick<CardProps, 'value' | 'className'>` where CardProps takes React's HTML attributes (`extends
4
+ * React.HTMLAttributes<HTMLDivElement>`): Svelte's attribute types (svelte/elements) name the class attribute `class`,
5
+ * so the key React wrote as `className` is `class` there, in Pick and in Omit alike (an Omit of `className` would
6
+ * otherwise leave `class` in). Only when the type does not declare a `className` of its own.
7
+ */
8
+ export function svelteHtmlKeys(node, ctx) {
9
+ t.traverseFast(node, (n) => {
10
+ if (!t.isTSTypeReference(n) || !t.isIdentifier(n.typeName) || (n.typeName.name !== 'Pick' && n.typeName.name !== 'Omit'))
11
+ return;
12
+ const [base, keys] = n.typeParameters?.params ?? [];
13
+ if (!base || !keys || !hasClassName(keys))
14
+ return;
15
+ if (!ctx.types.extendsHtml(base, ctx.sourceFile))
16
+ return;
17
+ const own = ctx.types.members(base, ctx.sourceFile);
18
+ if (!own || own.has('className') || own.has('class'))
19
+ return;
20
+ const rename = (k) => {
21
+ if (t.isTSLiteralType(k) && t.isStringLiteral(k.literal, { value: 'className' }))
22
+ k.literal = t.stringLiteral('class');
23
+ else if (t.isTSUnionType(k))
24
+ k.types.forEach(rename);
25
+ else if (t.isTSParenthesizedType(k))
26
+ rename(k.typeAnnotation);
27
+ };
28
+ rename(keys);
29
+ });
30
+ return node;
31
+ }
32
+ function hasClassName(k) {
33
+ if (t.isTSLiteralType(k))
34
+ return t.isStringLiteral(k.literal, { value: 'className' });
35
+ if (t.isTSUnionType(k))
36
+ return k.types.some(hasClassName);
37
+ if (t.isTSParenthesizedType(k))
38
+ return hasClassName(k.typeAnnotation);
39
+ return false;
40
+ }
@@ -0,0 +1,51 @@
1
+ import * as t from '@babel/types';
2
+ import type { ComponentIR, FragmentDef, KeptMarkup, ModuleIR } from '../../../ir/model.js';
3
+ import type { WebContext } from '../../shared/module.js';
4
+ /**
5
+ * One component's elements held as data on Svelte (see sites.ts): the code lowering kept because a template has no
6
+ * form for it (FunctionIR.keptMarkup), written as script code that builds records, and the sites as snippets. Each
7
+ * kept piece is written only when every element in it can be (otherwise its error stays as lowering reported it).
8
+ */
9
+ export declare class MarkupData {
10
+ private readonly mod;
11
+ private readonly comp;
12
+ private readonly ctx;
13
+ /** a name is free in the file */
14
+ private readonly free;
15
+ private readonly reserve;
16
+ /** the sites, as render helpers the template prints as snippets */
17
+ readonly sites: FragmentDef[];
18
+ /** the kept values written, by the names they declare */
19
+ readonly written: Set<string>;
20
+ /** a site or the template draws a value through MarkupView */
21
+ view: boolean;
22
+ /** the code names `Markup` (a type React wrote as ReactNode, or a site's child value) */
23
+ type: boolean;
24
+ private readonly kept;
25
+ /** the kept expressions already written, each once (a template printed twice finds it here) */
26
+ private readonly drawn;
27
+ constructor(mod: ModuleIR, comp: ComponentIR, ctx: WebContext,
28
+ /** a name is free in the file */
29
+ free: (name: string) => boolean, reserve: (name: string) => void);
30
+ /** The kept values this component writes, each planned and rewritten in place; the rest keep their error. */
31
+ values(): Extract<KeptMarkup, {
32
+ kind: 'value';
33
+ }>[];
34
+ /**
35
+ * A value the template renders where lowering left an `unconverted` node: the expression MarkupView draws (its
36
+ * elements rewritten as records), or null when it has none.
37
+ */
38
+ /** The expression reads a kept value this component wrote as data. */
39
+ readsWritten(expr: t.Node): boolean;
40
+ rendered(node: {
41
+ kept?: string;
42
+ value?: string;
43
+ }): t.Expression | null;
44
+ /**
45
+ * Names the source declares that the Svelte script does not: render helpers written as snippets or inlined, markup
46
+ * values, module markup, kept values not written. Code that reads one cannot run as script.
47
+ */
48
+ private templateOnly;
49
+ private plan;
50
+ private withdraw;
51
+ }
@@ -0,0 +1,305 @@
1
+ import * as t from '@babel/types';
2
+ import { lowerModuleFragments } from '../../../ir/lower.js';
3
+ import { MARKUP_ELEMENT_TYPE, MARKUP_TYPE, MARKUP_VIEW, useMarkupHelper } from './helper.js';
4
+ import { markupTypes, planSites } from './sites.js';
5
+ /**
6
+ * One component's elements held as data on Svelte (see sites.ts): the code lowering kept because a template has no
7
+ * form for it (FunctionIR.keptMarkup), written as script code that builds records, and the sites as snippets. Each
8
+ * kept piece is written only when every element in it can be (otherwise its error stays as lowering reported it).
9
+ */
10
+ export class MarkupData {
11
+ mod;
12
+ comp;
13
+ ctx;
14
+ free;
15
+ reserve;
16
+ /** the sites, as render helpers the template prints as snippets */
17
+ sites = [];
18
+ /** the kept values written, by the names they declare */
19
+ written = new Set();
20
+ /** a site or the template draws a value through MarkupView */
21
+ view = false;
22
+ /** the code names `Markup` (a type React wrote as ReactNode, or a site's child value) */
23
+ type = false;
24
+ kept;
25
+ /** the kept expressions already written, each once (a template printed twice finds it here) */
26
+ drawn = new Map();
27
+ constructor(mod, comp, ctx,
28
+ /** a name is free in the file */
29
+ free, reserve) {
30
+ this.mod = mod;
31
+ this.comp = comp;
32
+ this.ctx = ctx;
33
+ this.free = free;
34
+ this.reserve = reserve;
35
+ this.kept = comp.keptMarkup ?? [];
36
+ }
37
+ /** The kept values this component writes, each planned and rewritten in place; the rest keep their error. */
38
+ values() {
39
+ if (!this.kept.length || ![MARKUP_VIEW, MARKUP_TYPE, MARKUP_ELEMENT_TYPE].every((n) => this.free(n)))
40
+ return [];
41
+ const out = [];
42
+ // a value the template reads anywhere but where lowering left it unconverted (`{items.length}` is fine in script,
43
+ // but `{cell(r, c)}` printed as text would show an object): not written
44
+ const templates = [this.comp.template, ...this.comp.fragments.map((f) => f.template)];
45
+ const outside = readsOutsideUnconverted(templates);
46
+ // the kept expressions the template renders (`{cell(r, c)}`): each must be drawable once the value is written
47
+ const slots = inSlotProps(templates);
48
+ const reads = this.kept.filter((k) => k.kind === 'expression');
49
+ for (const kept of this.kept) {
50
+ if (kept.kind !== 'value' || kept.names.some((n) => outside.has(n)))
51
+ continue;
52
+ // M4: a block computing several values at once (`{ out, n }`, each read from the object after it): the template
53
+ // reads the values, not the object, and would print the records as text; not written, the error stays
54
+ if (kept.item.kind === 'block' && kept.item.members)
55
+ continue;
56
+ // M4: script code that reads the value (`const first = out[0]`, `out.length`) would read the records, and read
57
+ // them once: not written, the error stays
58
+ if (readByScript(this.comp, new Set(kept.names)))
59
+ continue;
60
+ const names = new Set(kept.names);
61
+ const readers = reads.filter((r) => {
62
+ let hit = false;
63
+ t.traverseFast(r.expr, (n) => {
64
+ if (t.isIdentifier(n) && names.has(n.name))
65
+ hit = true;
66
+ });
67
+ return hit;
68
+ });
69
+ // a read that holds elements of its own, or passes the value to a component's prop, would not be drawn
70
+ if (readers.some((r) => slots.has(r.id) || containsJsx(r.expr)))
71
+ continue;
72
+ const item = kept.item;
73
+ // an expression is planned inside a statement that holds it, so an element written as the whole value is a site too
74
+ const holder = item.kind === 'derived' ? t.expressionStatement(item.init) : item.kind === 'function' && !t.isFunctionDeclaration(item.node) ? t.expressionStatement(item.node) : null;
75
+ const roots = item.kind === 'block' ? item.statements : holder ? [holder] : item.kind === 'function' ? [item.node] : [];
76
+ // the render helpers it calls that lowering kept only for it (KeptMarkup `calls`): written the same way, as script
77
+ // functions of their own in front of it, each returning what React's returned with its elements as records
78
+ const called = (kept.calls ?? []).filter((c) => !this.written.has(c.name));
79
+ const calledHolders = called.map((c) => (t.isFunctionDeclaration(c.node) ? c.node : t.expressionStatement(c.node)));
80
+ // its own names are declared by the code being written
81
+ for (const n of [...kept.names, ...called.map((c) => c.name)])
82
+ this.written.add(n);
83
+ if (!this.plan([...roots, ...calledHolders], item.kind === 'derived' ? (kept.names[0] ?? 'value') : item.name, true)) {
84
+ for (const n of [...kept.names, ...called.map((c) => c.name)])
85
+ this.written.delete(n);
86
+ continue;
87
+ }
88
+ if (item.kind === 'derived' && holder)
89
+ item.init = holder.expression;
90
+ if ((item.kind === 'block' || item.kind === 'derived') && item.type)
91
+ this.type = markupTypes([item.type]) || this.type;
92
+ this.withdraw(kept.diagnostic);
93
+ called.forEach((c, i) => {
94
+ const h = calledHolders[i];
95
+ const node = h && t.isExpressionStatement(h) && (t.isArrowFunctionExpression(h.expression) || t.isFunctionExpression(h.expression)) ? h.expression : c.node;
96
+ out.push({ kind: 'value', item: { kind: 'function', name: c.name, node }, names: [c.name], reactive: false, after: kept.after, diagnostic: kept.diagnostic });
97
+ });
98
+ out.push(kept);
99
+ }
100
+ return out;
101
+ }
102
+ /**
103
+ * A value the template renders where lowering left an `unconverted` node: the expression MarkupView draws (its
104
+ * elements rewritten as records), or null when it has none.
105
+ */
106
+ /** The expression reads a kept value this component wrote as data. */
107
+ readsWritten(expr) {
108
+ let found = false;
109
+ t.traverseFast(expr, (n) => {
110
+ if (t.isIdentifier(n) && this.written.has(n.name))
111
+ found = true;
112
+ });
113
+ return found;
114
+ }
115
+ rendered(node) {
116
+ if (node.value) {
117
+ if (!this.written.has(node.value))
118
+ return null;
119
+ this.view = true;
120
+ return t.identifier(node.value);
121
+ }
122
+ // markup the template renders where it has no form for it (`{(() => { … return <b/>; })()}`): drawn when every
123
+ // value it reads that lowering kept is written and every element inside it can be a record
124
+ // markup passed to a component's prop (a snippet in Svelte, which the receiver may call with arguments): not a child
125
+ if (node.kept !== undefined && inSlotProps([this.comp.template, ...this.comp.fragments.map((f) => f.template)]).has(node.kept))
126
+ return null;
127
+ const entry = node.kept === undefined ? undefined : this.kept.find((k) => k.kind === 'expression' && k.id === node.kept);
128
+ const done = entry ? this.drawn.get(entry) : undefined;
129
+ if (done)
130
+ return t.cloneNode(done, true);
131
+ const expr = entry?.expr;
132
+ if (!entry || !expr || ![MARKUP_VIEW, MARKUP_TYPE, MARKUP_ELEMENT_TYPE].every((n) => this.free(n)))
133
+ return null;
134
+ let reads = false;
135
+ let unwritten = false;
136
+ const kept = new Set(this.kept.flatMap((k) => (k.kind === 'value' ? k.names : [])));
137
+ t.traverseFast(expr, (n) => {
138
+ if (!t.isIdentifier(n) || !kept.has(n.name))
139
+ return;
140
+ reads = true;
141
+ if (!this.written.has(n.name))
142
+ unwritten = true;
143
+ });
144
+ let jsx = false;
145
+ t.traverseFast(expr, (n) => {
146
+ if (t.isJSXElement(n) || t.isJSXFragment(n))
147
+ jsx = true;
148
+ });
149
+ if (unwritten || (!reads && !jsx) || this.templateOnly([expr]))
150
+ return null;
151
+ const holder = t.expressionStatement(expr);
152
+ if (jsx && !this.plan([holder], 'value', false))
153
+ return null;
154
+ this.withdraw(entry.diagnostic);
155
+ this.view = true;
156
+ this.drawn.set(entry, holder.expression);
157
+ return holder.expression;
158
+ }
159
+ /**
160
+ * Names the source declares that the Svelte script does not: render helpers written as snippets or inlined, markup
161
+ * values, module markup, kept values not written. Code that reads one cannot run as script.
162
+ */
163
+ templateOnly(roots) {
164
+ const jsx = this.mod.moduleJsx;
165
+ const names = new Set([
166
+ ...this.comp.fragments.map((f) => f.name),
167
+ ...(this.comp.markupValues ?? []).map((v) => v.name),
168
+ ...(this.mod.markupValues ?? []).map((v) => v.name),
169
+ ...(this.mod.snippetHelpers?.defs ?? []).map((d) => d.name),
170
+ ...jsx.renderFns.keys(),
171
+ ...jsx.constants.keys(),
172
+ ...jsx.maps.keys(),
173
+ ...this.kept.flatMap((k) => (k.kind === 'value' ? k.names.filter((n) => !this.written.has(n)) : [])),
174
+ ]);
175
+ let found = false;
176
+ for (const root of roots) {
177
+ t.traverseFast(root, (n) => {
178
+ if (!t.isIdentifier(n))
179
+ return;
180
+ // a name of the component's own that lowering wrote into the template only (a render helper it inlined)
181
+ const own = this.comp.refs.get(n);
182
+ if (names.has(n.name) || (own !== undefined && !this.comp.bindings.has(own) && !this.written.has(own)))
183
+ found = true;
184
+ });
185
+ }
186
+ return found;
187
+ }
188
+ plan(roots, prefix, script) {
189
+ if (this.templateOnly(roots))
190
+ return false;
191
+ const taken = new Set();
192
+ const snippetProps = new Set(this.comp.props.filter((p) => p.kind === 'children' || p.kind === 'node').map((p) => p.local));
193
+ const imports = this.mod.imports.flatMap((d) => d.specifiers.map((s) => s.local.name));
194
+ const result = planSites(roots, {
195
+ moduleNames: new Set([...this.mod.moduleJsx.moduleNames, ...imports, ...this.mod.components.map((c) => c.name)]),
196
+ motionNames: this.mod.motionNames,
197
+ snippetProps,
198
+ taken: {
199
+ has: (n) => taken.has(n) || !this.free(n),
200
+ add: (n) => {
201
+ taken.add(n);
202
+ },
203
+ },
204
+ typeOf: (e) => this.ctx.oracle?.typeOfExpression(this.ctx.sourceFile, e.loc) ?? null,
205
+ prefix,
206
+ script,
207
+ });
208
+ if (!result.ok)
209
+ return false;
210
+ const fns = new Map(result.sites.map((s) => [s.name, s.fn]));
211
+ const defs = lowerModuleFragments(this.mod, fns);
212
+ if (!defs)
213
+ return false;
214
+ result.commit();
215
+ for (const s of result.sites)
216
+ this.reserve(s.name);
217
+ this.sites.push(...defs);
218
+ if (result.view)
219
+ this.view = this.type = true;
220
+ this.type = markupTypes(roots) || this.type;
221
+ if (this.sites.length || this.view)
222
+ useMarkupHelper(this.ctx.diagnostics);
223
+ return true;
224
+ }
225
+ withdraw(d) {
226
+ // an error is withdrawn once: a second read of the same value finds it gone
227
+ const at = this.ctx.diagnostics.findIndex((x) => x === d);
228
+ if (at >= 0)
229
+ this.ctx.diagnostics.splice(at, 1);
230
+ }
231
+ }
232
+ /** The names an expression of these templates reads, leaving out the nodes lowering left unconverted. */
233
+ function readsOutsideUnconverted(templates) {
234
+ const out = new Set();
235
+ const visit = (value) => {
236
+ if (Array.isArray(value)) {
237
+ for (const v of value)
238
+ visit(v);
239
+ return;
240
+ }
241
+ if (typeof value !== 'object' || value === null)
242
+ return;
243
+ if (t.isNode(value)) {
244
+ t.traverseFast(value, (n) => {
245
+ if (t.isIdentifier(n))
246
+ out.add(n.name);
247
+ });
248
+ return;
249
+ }
250
+ // an unconverted node, or a value read that lowering kept (`{cell(r, c)}`): drawn by MarkupView, not read here
251
+ if (Reflect.get(value, 'type') === 'unconverted' || (Reflect.get(value, 'type') === 'expr' && typeof Reflect.get(value, 'kept') === 'string'))
252
+ return;
253
+ for (const v of Object.values(value))
254
+ visit(v);
255
+ };
256
+ visit(templates);
257
+ return out;
258
+ }
259
+ /** The kept expressions these templates pass to a component's prop as its markup (`art={…}`), by id. */
260
+ function inSlotProps(templates) {
261
+ const out = new Set();
262
+ const visit = (value, inSlot) => {
263
+ if (Array.isArray(value)) {
264
+ for (const v of value)
265
+ visit(v, inSlot);
266
+ return;
267
+ }
268
+ if (typeof value !== 'object' || value === null || t.isNode(value))
269
+ return;
270
+ const kind = Reflect.get(value, 'kind');
271
+ const type = Reflect.get(value, 'type');
272
+ const kept = Reflect.get(value, 'kept');
273
+ if (type === 'unconverted' && inSlot && typeof kept === 'string')
274
+ out.add(kept);
275
+ for (const v of Object.values(value))
276
+ visit(v, inSlot || kind === 'slotProp');
277
+ };
278
+ visit(templates, false);
279
+ return out;
280
+ }
281
+ /** M4. Whether a script item of the component (its code, not its template) reads one of these names. */
282
+ function readByScript(comp, names) {
283
+ let found = false;
284
+ for (const item of comp.items) {
285
+ for (const value of Object.values(item)) {
286
+ for (const v of Array.isArray(value) ? value : [value]) {
287
+ if (!t.isNode(v))
288
+ continue;
289
+ t.traverseFast(v, (n) => {
290
+ if (t.isIdentifier(n) && names.has(comp.refs.get(n) ?? ''))
291
+ found = true;
292
+ });
293
+ }
294
+ }
295
+ }
296
+ return found;
297
+ }
298
+ function containsJsx(node) {
299
+ let found = false;
300
+ t.traverseFast(node, (n) => {
301
+ if (t.isJSXElement(n) || t.isJSXFragment(n))
302
+ found = true;
303
+ });
304
+ return found;
305
+ }
@@ -0,0 +1,12 @@
1
+ import type { EmittedFile } from '../../../types.js';
2
+ /** The module that types elements held as data and tests them, written once per conversion that uses it. */
3
+ export declare const MARKUP_MODULE_FILE = "markup.ts";
4
+ /** The component that renders such a value as React renders a child, written once per conversion that uses it. */
5
+ export declare const MARKUP_VIEW_FILE = "MarkupView.svelte";
6
+ export declare const MARKUP_VIEW = "MarkupView";
7
+ export declare const MARKUP_TYPE = "Markup";
8
+ export declare const MARKUP_ELEMENT_TYPE = "MarkupElement";
9
+ /** A component of the conversion holds elements as data: the two files are written once for it. */
10
+ export declare function useMarkupHelper(conversion: object): void;
11
+ /** The module and the renderer, when a component of the conversion holds elements as data; nothing otherwise. */
12
+ export declare function markupHelperFiles(conversion: object, modulePath: string, viewPath: string): EmittedFile[];
@@ -0,0 +1,81 @@
1
+ import { importPath } from '../../shared/layout.js';
2
+ /** The module that types elements held as data and tests them, written once per conversion that uses it. */
3
+ export const MARKUP_MODULE_FILE = 'markup.ts';
4
+ /** The component that renders such a value as React renders a child, written once per conversion that uses it. */
5
+ export const MARKUP_VIEW_FILE = 'MarkupView.svelte';
6
+ export const MARKUP_VIEW = 'MarkupView';
7
+ export const MARKUP_TYPE = 'Markup';
8
+ export const MARKUP_ELEMENT_TYPE = 'MarkupElement';
9
+ const MODULE_SOURCE = `import type { Snippet } from 'svelte';
10
+
11
+ /**
12
+ * An element built by script code, as React builds one: the snippet that draws it, React's key, and the values the
13
+ * snippet reads, taken when the element was built.
14
+ */
15
+ export interface MarkupElement {
16
+ readonly key?: string | number | null;
17
+ draw(element: MarkupElement): ReturnType<Snippet>;
18
+ readonly [field: string]: unknown;
19
+ }
20
+
21
+ /** What React renders from a value: an element, text, a number, nothing, or a list of them. */
22
+ export type Markup = MarkupElement | string | number | bigint | boolean | null | undefined | readonly Markup[];
23
+
24
+ export function isElement(value: Markup): value is MarkupElement {
25
+ return typeof value === 'object' && value !== null && 'draw' in value;
26
+ }
27
+
28
+ export function isList(value: Markup): value is readonly Markup[] {
29
+ return Array.isArray(value);
30
+ }
31
+
32
+ /** The key a list item keeps from one render to the next: its own key, else its place (React's rule). */
33
+ export function keyOf(value: Markup, index: number): string {
34
+ return isElement(value) && value.key != null ? \`k\${String(value.key)}\` : \`i\${index}\`;
35
+ }
36
+ `;
37
+ // M4: the list branch puts the focus back where React's commit does (a keyed item moved while focused)
38
+ function viewSource(modulePath, viewPath) {
39
+ const source = importPath(viewPath, modulePath);
40
+ return `<script lang="ts">
41
+ import ${MARKUP_VIEW} from './${viewPath.split('/').pop() ?? MARKUP_VIEW_FILE}';
42
+ import { isElement, isList, keyOf, type Markup } from '${source}';
43
+
44
+ let { value }: { value: Markup } = $props();
45
+
46
+ // React puts the focus back on the element that had it once an update has moved it (a keyed item reordered)
47
+ let focused: Element | null = null;
48
+ $effect.pre(() => {
49
+ if (isList(value)) focused = document.activeElement;
50
+ });
51
+ $effect(() => {
52
+ if (!isList(value)) return;
53
+ const el = focused;
54
+ focused = null;
55
+ if (el instanceof HTMLElement && el !== document.activeElement && el.isConnected) el.focus();
56
+ });
57
+ </script>
58
+
59
+ {#if isList(value)}
60
+ {#each value as item, i (keyOf(item, i))}<${MARKUP_VIEW} value={item} />{/each}
61
+ {:else if isElement(value)}
62
+ {@render value.draw(value)}
63
+ {:else if typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint'}
64
+ {value}
65
+ {/if}
66
+ `;
67
+ }
68
+ const used = new WeakSet();
69
+ /** A component of the conversion holds elements as data: the two files are written once for it. */
70
+ export function useMarkupHelper(conversion) {
71
+ used.add(conversion);
72
+ }
73
+ /** The module and the renderer, when a component of the conversion holds elements as data; nothing otherwise. */
74
+ export function markupHelperFiles(conversion, modulePath, viewPath) {
75
+ if (!used.has(conversion))
76
+ return [];
77
+ return [
78
+ { path: modulePath, contents: MODULE_SOURCE, kind: 'module' },
79
+ { path: viewPath, contents: viewSource(modulePath, viewPath), kind: 'component' },
80
+ ];
81
+ }