@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,114 @@
1
+ import * as t from '@babel/types';
2
+ /**
3
+ * React calls a callback ref written inline (a new function every render) again after every render of its component:
4
+ * with null for the old function, then with the element for the new one. A target that runs the converted callback
5
+ * once when the element mounts (and again only when something it read changes, or with null when the element goes)
6
+ * ends in the same state as React when a null call followed by an element call leaves everything as the element call
7
+ * alone does. That holds for the forms below, and is not claimed for any other body (a counter, a write in the null
8
+ * branch the element branch does not undo, a call):
9
+ *
10
+ * - `target = el`, `holder.current = el`, `list[i] = el` (the element, or null, stored in one place);
11
+ * - `if (el) map.set(key, el); else map.delete(key)` (the same map and key), with or without the else;
12
+ * - `if (el) el.prop = value` (writes to the element itself, read again from current values).
13
+ *
14
+ * Shared by the targets (moved from the Svelte target, where it began).
15
+ */
16
+ export function settlesLikeReact(fn) {
17
+ const [param] = fn.params;
18
+ if (fn.params.length !== 1 || !t.isIdentifier(param) || fn.async || fn.generator)
19
+ return false;
20
+ const el = param.name;
21
+ const body = t.isBlockStatement(fn.body) ? fn.body.body : [t.expressionStatement(fn.body)];
22
+ return body.every((s) => statementSettles(s, el));
23
+ }
24
+ function statementSettles(s, el) {
25
+ if (t.isExpressionStatement(s))
26
+ return storesElement(s.expression, el);
27
+ if (t.isIfStatement(s) && t.isIdentifier(s.test, { name: el })) {
28
+ const yes = single(s.consequent);
29
+ const no = s.alternate ? single(s.alternate) : null;
30
+ if (!yes)
31
+ return false;
32
+ // `if (el) map.set(k, el); else map.delete(k)`
33
+ const set = mapCall(yes, 'set');
34
+ if (set && t.isIdentifier(set.args[1], { name: el }) && !mentions(set.target, el) && !mentions(set.args[0], el)) {
35
+ if (!s.alternate)
36
+ return true;
37
+ const del = no ? mapCall(no, 'delete') : null;
38
+ return !!del && del.args.length === 1 && sameExpression(del.target, set.target) && sameExpression(del.args[0], set.args[0]);
39
+ }
40
+ // `if (el) el.inert = !on`: the element's own properties, from current values
41
+ if (!s.alternate && t.isExpressionStatement(yes))
42
+ return writesOwnProperty(yes.expression, el);
43
+ }
44
+ return false;
45
+ }
46
+ function single(s) {
47
+ if (t.isBlockStatement(s))
48
+ return s.body.length === 1 ? (s.body[0] ?? null) : null;
49
+ return s;
50
+ }
51
+ /** `target = el` with a target that does not read el or call anything. */
52
+ function storesElement(e, el) {
53
+ // `void (paths.current[i] = el)`: the same store, its value discarded
54
+ if (t.isUnaryExpression(e, { operator: 'void' }))
55
+ return storesElement(t.isParenthesizedExpression(e.argument) ? e.argument.expression : e.argument, el);
56
+ if (t.isParenthesizedExpression(e))
57
+ return storesElement(e.expression, el);
58
+ // (`el as SVGCircleElement | null`: the same value, typed)
59
+ let right = t.isAssignmentExpression(e) ? e.right : e;
60
+ while (t.isTSAsExpression(right) || t.isTSTypeAssertion(right) || t.isTSNonNullExpression(right) || t.isTSSatisfiesExpression(right) || t.isParenthesizedExpression(right))
61
+ right = right.expression;
62
+ if (!t.isAssignmentExpression(e) || e.operator !== '=' || !t.isIdentifier(right, { name: el }))
63
+ return false;
64
+ const left = e.left;
65
+ return (t.isIdentifier(left) && left.name !== el) || (t.isMemberExpression(left) && plainPath(left) && !mentions(left, el));
66
+ }
67
+ function writesOwnProperty(e, el) {
68
+ if (!t.isAssignmentExpression(e) || e.operator !== '=' || !t.isMemberExpression(e.left) || e.left.computed)
69
+ return false;
70
+ return t.isIdentifier(e.left.object, { name: el }) && !hasCall(e.right) && !mentions(e.right, el);
71
+ }
72
+ function mapCall(s, method) {
73
+ if (!t.isExpressionStatement(s) || !t.isCallExpression(s.expression))
74
+ return null;
75
+ const callee = s.expression.callee;
76
+ if (!t.isMemberExpression(callee) || callee.computed || !t.isIdentifier(callee.property, { name: method }) || !plainPath(callee.object))
77
+ return null;
78
+ const args = s.expression.arguments;
79
+ if (!args.every((a) => t.isExpression(a)) || args.some((a) => hasCall(a)))
80
+ return null;
81
+ return { target: callee.object, args };
82
+ }
83
+ /** identifiers, `.name` and `[key]` steps with no call in them */
84
+ function plainPath(e) {
85
+ if (t.isIdentifier(e))
86
+ return true;
87
+ if (t.isMemberExpression(e))
88
+ return plainPath(e.object) && (!e.computed || (t.isExpression(e.property) && !hasCall(e.property)));
89
+ return false;
90
+ }
91
+ function hasCall(n) {
92
+ let found = false;
93
+ t.traverseFast(n, (x) => {
94
+ if (t.isCallExpression(x) || t.isNewExpression(x) || t.isOptionalCallExpression(x) || t.isUpdateExpression(x) || t.isAssignmentExpression(x) || t.isFunction(x))
95
+ found = true;
96
+ });
97
+ return found;
98
+ }
99
+ function mentions(n, name) {
100
+ if (!n)
101
+ return false;
102
+ let found = false;
103
+ t.traverseFast(n, (x) => {
104
+ if (t.isIdentifier(x, { name }))
105
+ found = true;
106
+ });
107
+ return found;
108
+ }
109
+ function sameExpression(a, b) {
110
+ if (!a || !b)
111
+ return false;
112
+ const strip = (n) => JSON.parse(JSON.stringify(n, (k, v) => (['start', 'end', 'loc', 'range', 'extra', 'leadingComments', 'trailingComments', 'innerComments'].includes(k) ? undefined : v)));
113
+ return JSON.stringify(strip(a)) === JSON.stringify(strip(b));
114
+ }
@@ -0,0 +1,65 @@
1
+ import * as t from '@babel/types';
2
+ import type { WebTarget } from '../../types.js';
3
+ import type { ComponentIR, CoreExtraction, FunctionIR, ScriptItem } from '../../ir/model.js';
4
+ /** Hands out names that do not clash with anything already in the file. */
5
+ export declare class NameAllocator {
6
+ private readonly used;
7
+ constructor(used: Iterable<string>);
8
+ alloc(base: string): string;
9
+ reserve(name: string): void;
10
+ has(name: string): boolean;
11
+ }
12
+ /**
13
+ * Rewrites every `return X` of a function body (not of functions nested inside it) with `make(X)`; plain `return;`
14
+ * is left alone. Used to turn an effect's returned cleanup into the target's cleanup registration.
15
+ */
16
+ export declare function replaceReturns(body: t.BlockStatement, make: (value: t.Expression) => t.Statement[]): t.BlockStatement;
17
+ /** Drops a trailing bare `return;` (left by replaceReturns at the end of a body). */
18
+ export declare function trimTrailingReturn(body: t.BlockStatement): t.BlockStatement;
19
+ /** Whether a function body returns a value anywhere (outside nested functions). */
20
+ export declare function returnsValue(body: t.BlockStatement): boolean;
21
+ /** The effect dependencies that are reactive (props, state, reactive derived values, reactive hook results). */
22
+ export declare function reactiveDeps(deps: t.Expression[], ir: FunctionIR, seen?: Set<string>): t.Expression[];
23
+ /** A best-effort TypeScript type for a component binding, for the core module's input interface. */
24
+ /** A type nobody wrote down: TypeScript's answer for the binding in the React source, when there is one. */
25
+ export type InferType = (name: string) => t.TSType | null;
26
+ export interface CoreModule {
27
+ /** statements of the core file (imports are added by the caller) */
28
+ statements: t.Statement[];
29
+ /** module-level names the core body reads, to import */
30
+ moduleNames: Set<string>;
31
+ /** the effect body that replaces the original: one statement returning the core's cleanup */
32
+ call: (target: WebTarget, read: (name: string) => t.Expression, element: t.Expression, box: (name: string) => t.Expression, setter: (name: string) => t.Expression) => t.BlockStatement;
33
+ }
34
+ /**
35
+ * Moves an effect that drives a canvas or animation-frame loop into a framework-free function
36
+ * `mountX(element, input): cleanup`, so the Vue and Svelte components only wire it up.
37
+ */
38
+ export declare function buildCore(ir: ComponentIR, item: Extract<ScriptItem, {
39
+ kind: 'effect';
40
+ }>, core: CoreExtraction, infer?: InferType): CoreModule;
41
+ /**
42
+ * JSX that reached script code (a hook returning elements, a value assembled from elements) has no form outside a
43
+ * template: it becomes `null` with a comment saying so, and the caller reports an error. Returns how many were cut.
44
+ */
45
+ export declare function cutLeftoverJsx(stmts: t.Statement[]): number;
46
+ /**
47
+ * Writes to module-level `let`s that moved into a shared module (ES imports are read-only): `seq = v` becomes
48
+ * `setSeq(v)`, `++seq` `setSeq(seq + 1)`. Returns the names written, so the shared module can export their setters.
49
+ */
50
+ export declare function routeModuleWrites(nodes: t.Node[], names: Set<string>, shadowed: Set<string>): Set<string>;
51
+ /** `export function setSeq(value) { return (seq = value); }` for each name a component writes. */
52
+ export declare function moduleSetters(names: Iterable<string>): t.Statement[];
53
+ /** Module-level names declared with `let` or `var` (the ones a component might reassign). */
54
+ export declare function moduleLets(body: t.Statement[]): Set<string>;
55
+ /** A typed `ref<T>()` / `$state<T>()` call. */
56
+ export declare function typedCall(callee: string, type: t.TSType | null, args: t.Expression[]): t.CallExpression;
57
+ /** Names bound by a derived item's pattern, or the block's single name. */
58
+ export declare function itemNames(item: ScriptItem): string[];
59
+ /** A type that admits null: as written when it already does (`HTMLElement | null`), else with null added. */
60
+ export declare function orNull(type: t.TSType): t.TSType;
61
+ /**
62
+ * What `useRef<T>(init)` holds, as React's types say: `T | null` from `null`, `T | undefined` from nothing or
63
+ * `undefined` (`useRef<ReturnType<typeof setTimeout>>(undefined)`), and `T` from any other value.
64
+ */
65
+ export declare function refHolds(type: t.TSType, init: t.Expression | null): t.TSType;
@@ -0,0 +1,406 @@
1
+ import * as t from '@babel/types';
2
+ import { childAt, setChildAt } from '../../ir/walk.js';
3
+ import { patternNames, unwrap } from '../../ir/lower.js';
4
+ import { transform } from '../../ir/rewrite.js';
5
+ /** Hands out names that do not clash with anything already in the file. */
6
+ export class NameAllocator {
7
+ used;
8
+ constructor(used) {
9
+ this.used = new Set(used);
10
+ }
11
+ alloc(base) {
12
+ let name = base;
13
+ for (let i = 2; this.used.has(name); i++)
14
+ name = `${base}${i}`;
15
+ this.used.add(name);
16
+ return name;
17
+ }
18
+ reserve(name) {
19
+ this.used.add(name);
20
+ }
21
+ has(name) {
22
+ return this.used.has(name);
23
+ }
24
+ }
25
+ /**
26
+ * Rewrites every `return X` of a function body (not of functions nested inside it) with `make(X)`; plain `return;`
27
+ * is left alone. Used to turn an effect's returned cleanup into the target's cleanup registration.
28
+ */
29
+ export function replaceReturns(body, make) {
30
+ const visit = (node) => {
31
+ if (t.isFunction(node))
32
+ return node;
33
+ for (const key of t.VISITOR_KEYS[node.type] ?? []) {
34
+ const value = childAt(node, key);
35
+ if (Array.isArray(value)) {
36
+ const next = value.flatMap((child) => {
37
+ if (!child || typeof child !== 'object' || !('type' in child))
38
+ return [child];
39
+ const c = child;
40
+ if (t.isReturnStatement(c) && c.argument && !t.isIdentifier(c.argument, { name: 'undefined' })) {
41
+ const stmts = make(c.argument);
42
+ return [...stmts, t.returnStatement()];
43
+ }
44
+ return [visit(c)];
45
+ });
46
+ setChildAt(node, key, next);
47
+ }
48
+ else if (value && typeof value === 'object' && 'type' in value) {
49
+ const c = value;
50
+ if (t.isReturnStatement(c) && c.argument && !t.isIdentifier(c.argument, { name: 'undefined' })) {
51
+ setChildAt(node, key, t.blockStatement([...make(c.argument), t.returnStatement()]));
52
+ }
53
+ else
54
+ setChildAt(node, key, visit(c));
55
+ }
56
+ }
57
+ return node;
58
+ };
59
+ return visit(body);
60
+ }
61
+ /** Drops a trailing bare `return;` (left by replaceReturns at the end of a body). */
62
+ export function trimTrailingReturn(body) {
63
+ const last = body.body[body.body.length - 1];
64
+ if (t.isReturnStatement(last) && !last.argument)
65
+ body.body.pop();
66
+ return body;
67
+ }
68
+ /** Whether a function body returns a value anywhere (outside nested functions). */
69
+ export function returnsValue(body) {
70
+ let found = false;
71
+ const visit = (node) => {
72
+ if (found || t.isFunction(node))
73
+ return;
74
+ if (t.isReturnStatement(node) && node.argument && !t.isIdentifier(node.argument, { name: 'undefined' })) {
75
+ found = true;
76
+ return;
77
+ }
78
+ for (const key of t.VISITOR_KEYS[node.type] ?? []) {
79
+ const value = childAt(node, key);
80
+ if (Array.isArray(value))
81
+ value.forEach((v) => v && typeof v === 'object' && 'type' in v && visit(v));
82
+ else if (value && typeof value === 'object' && 'type' in value)
83
+ visit(value);
84
+ }
85
+ };
86
+ visit(body);
87
+ return found;
88
+ }
89
+ /** The effect dependencies that are reactive (props, state, reactive derived values, reactive hook results). */
90
+ export function reactiveDeps(deps, ir, seen = new Set()) {
91
+ // a useCallback function in the list stands for its own dependencies: it is a plain function now, so the effect
92
+ // follows what React re-created it on
93
+ const expanded = deps.flatMap((dep) => {
94
+ const name = t.isIdentifier(dep) ? ir.refs.get(dep) : undefined;
95
+ const b = name ? ir.bindings.get(name) : undefined;
96
+ if (!name || b?.kind !== 'function' || !b.deps || seen.has(name))
97
+ return [dep];
98
+ seen.add(name);
99
+ return reactiveDeps(b.deps, ir, seen);
100
+ });
101
+ return expanded.filter((dep) => {
102
+ let reactive = false;
103
+ t.traverseFast(dep, (n) => {
104
+ if (!t.isIdentifier(n))
105
+ return;
106
+ const name = ir.refs.get(n);
107
+ const b = name ? ir.bindings.get(name) : undefined;
108
+ if (!b)
109
+ return;
110
+ if (b.kind === 'prop' || b.kind === 'propsObject' || b.kind === 'state' || b.kind === 'reducer' || b.kind === 'rest' || ((b.kind === 'derived' || b.kind === 'hook' || b.kind === 'param') && b.reactive))
111
+ reactive = true;
112
+ });
113
+ return reactive;
114
+ });
115
+ }
116
+ function bindingType(ir, name, infer) {
117
+ const written = writtenType(ir, name);
118
+ // a function with no written return type (`useCallback((t: number) => clamp01(t), [])`) returns what React's checker
119
+ // says it does, not `unknown`
120
+ const openReturn = t.isTSFunctionType(written) && t.isTSUnknownKeyword(written.typeAnnotation?.typeAnnotation);
121
+ if (!t.isTSUnknownKeyword(written) && !openReturn)
122
+ return written;
123
+ const inferred = infer?.(name);
124
+ if (openReturn)
125
+ return inferred && t.isTSFunctionType(inferred) ? inferred : written;
126
+ return inferred ?? written;
127
+ }
128
+ function writtenType(ir, name) {
129
+ const prop = ir.props.find((p) => p.local === name);
130
+ // an optional prop with no default may be undefined, as React's type of it says
131
+ if (prop?.type)
132
+ return prop.optional && !prop.defaultValue ? t.tsUnionType([t.cloneNode(prop.type, true), t.tsUndefinedKeyword()]) : t.cloneNode(prop.type, true);
133
+ for (const item of ir.items) {
134
+ if (item.kind === 'state' && item.name === name)
135
+ return item.type ? t.cloneNode(item.type, true) : literalType(item.init);
136
+ if (item.kind === 'derived' && item.names.includes(name))
137
+ return item.type && item.names.length === 1 ? t.cloneNode(item.type, true) : literalType(item.init);
138
+ if (item.kind === 'function' && item.name === name)
139
+ return functionType(item.node);
140
+ if (item.kind === 'id' && item.name === name)
141
+ return t.tsStringKeyword();
142
+ }
143
+ return t.tsUnknownKeyword();
144
+ }
145
+ function literalType(init) {
146
+ const e = init ? unwrap(init) : null;
147
+ if (t.isNumericLiteral(e) || (t.isUnaryExpression(e) && t.isNumericLiteral(e.argument)))
148
+ return t.tsNumberKeyword();
149
+ if (t.isStringLiteral(e) || t.isTemplateLiteral(e))
150
+ return t.tsStringKeyword();
151
+ if (t.isBooleanLiteral(e))
152
+ return t.tsBooleanKeyword();
153
+ return t.tsUnknownKeyword();
154
+ }
155
+ function functionType(fn) {
156
+ const params = fn.params.map((p, i) => {
157
+ const id = t.identifier(t.isIdentifier(p) ? p.name : `arg${i}`);
158
+ const ann = 'typeAnnotation' in p && t.isTSTypeAnnotation(p.typeAnnotation) ? t.cloneNode(p.typeAnnotation, true) : t.tsTypeAnnotation(t.tsUnknownKeyword());
159
+ id.typeAnnotation = ann;
160
+ return id;
161
+ });
162
+ const ret = t.isTSTypeAnnotation(fn.returnType) ? t.cloneNode(fn.returnType, true) : t.tsTypeAnnotation(t.tsUnknownKeyword());
163
+ return t.tsFunctionType(null, params, ret);
164
+ }
165
+ function refType(ir, name, infer) {
166
+ for (const item of ir.items) {
167
+ if (item.kind !== 'ref' || item.name !== name)
168
+ continue;
169
+ if (item.type)
170
+ return t.cloneNode(item.type, true);
171
+ // useRef(look) with no type argument: the ref holds what the binding it starts from holds
172
+ const init = item.init ? unwrap(item.init) : null;
173
+ // the checker sees MutableRefObject<T>: the box's `current` is T, exactly what the ref holds (`useRef(onError)`
174
+ // with an optional `onError` holds `… | undefined`)
175
+ const box = infer?.(name);
176
+ const checked = box && t.isTSTypeReference(box) ? box.typeParameters?.params[0] : undefined;
177
+ if (t.isIdentifier(init) && init.name !== name)
178
+ return checked ?? bindingType(ir, init.name, infer);
179
+ const literal = literalType(item.init);
180
+ if (!t.isTSUnknownKeyword(literal))
181
+ return literal;
182
+ return checked ?? literal;
183
+ }
184
+ return t.tsUnknownKeyword();
185
+ }
186
+ /** A setter function `(value) => …value…` that first applies `value` to `current` when it is a function. */
187
+ function applyUpdater(set, param, current) {
188
+ const resolved = () => t.conditionalExpression(t.binaryExpression('===', t.unaryExpression('typeof', t.identifier(param)), t.stringLiteral('function')), t.callExpression(t.identifier(param), [t.cloneNode(current, true)]), t.identifier(param));
189
+ const body = transform(t.cloneNode(set.body, true), (n, parent) => {
190
+ if (!t.isIdentifier(n, { name: param }))
191
+ return null;
192
+ if (parent && (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.property === n && !parent.computed)
193
+ return null;
194
+ return resolved();
195
+ });
196
+ return t.arrowFunctionExpression([t.identifier(param)], t.isBlockStatement(body) || t.isExpression(body) ? body : set.body);
197
+ }
198
+ /**
199
+ * Moves an effect that drives a canvas or animation-frame loop into a framework-free function
200
+ * `mountX(element, input): cleanup`, so the Vue and Svelte components only wire it up.
201
+ */
202
+ export function buildCore(ir, item, core, infer) {
203
+ const body = t.cloneNode(item.body, true);
204
+ const moduleNames = new Set();
205
+ // clone keeps no identity: map references by name, respecting nested parameters
206
+ const own = new Set([...core.inputs, ...core.setters, ...core.boxes, core.elementRef]);
207
+ const rewritten = transform(body, (n, parent) => {
208
+ if ((t.isMemberExpression(n) || t.isOptionalMemberExpression(n)) && t.isIdentifier(n.object, { name: core.elementRef }) && t.isIdentifier(n.property, { name: 'current' }) && !n.computed) {
209
+ return t.identifier('element');
210
+ }
211
+ if (t.isIdentifier(n) && !own.has(n.name) && parent && !(t.isMemberExpression(parent) && parent.property === n && !parent.computed) && !(t.isObjectProperty(parent) && parent.key === n && !parent.computed)) {
212
+ if (ir.moduleNames.has(n.name))
213
+ moduleNames.add(n.name);
214
+ }
215
+ return null;
216
+ });
217
+ const inputName = `${core.name.charAt(0).toUpperCase()}${core.name.slice(1)}Input`;
218
+ const members = [];
219
+ const sig = (name, type) => t.tsPropertySignature(t.identifier(name), t.tsTypeAnnotation(type));
220
+ for (const name of core.inputs)
221
+ members.push(sig(name, bindingType(ir, name, infer)));
222
+ // setters the core calls with an updater (`setEnds((e) => …)`): they take one, and apply it to the current state
223
+ const updaters = new Set();
224
+ t.traverseFast(rewritten, (n) => {
225
+ if (t.isCallExpression(n) && t.isIdentifier(n.callee) && core.setters.includes(n.callee.name) && n.arguments[0] && t.isFunction(n.arguments[0]))
226
+ updaters.add(n.callee.name);
227
+ });
228
+ for (const name of core.setters) {
229
+ const b = ir.bindings.get(name);
230
+ const stateType = b?.state ? bindingType(ir, b.state, infer) : t.tsUnknownKeyword();
231
+ const value = t.identifier('value');
232
+ const prev = Object.assign(t.identifier('prev'), { typeAnnotation: t.tsTypeAnnotation(t.cloneNode(stateType, true)) });
233
+ value.typeAnnotation = t.tsTypeAnnotation(updaters.has(name) ? t.tsUnionType([stateType, t.tsParenthesizedType(t.tsFunctionType(null, [prev], t.tsTypeAnnotation(t.cloneNode(stateType, true))))]) : stateType);
234
+ members.push(sig(name, t.tsFunctionType(null, [value], t.tsTypeAnnotation(t.tsVoidKeyword()))));
235
+ }
236
+ for (const name of core.boxes) {
237
+ // `useRef<HTMLSpanElement>(null)`: the box starts empty, and an element box is empty again once its element goes
238
+ const ref = ir.items.find((i) => i.kind === 'ref' && i.name === name);
239
+ const startsEmpty = !!ref?.type && !!ref.init && t.isNullLiteral(unwrap(ref.init));
240
+ const held = refType(ir, name, infer);
241
+ members.push(sig(name, t.tsTypeLiteral([t.tsPropertySignature(t.identifier('current'), t.tsTypeAnnotation(startsEmpty ? orNull(held) : held))])));
242
+ }
243
+ const elementType = (() => {
244
+ const type = refType(ir, core.elementRef, infer);
245
+ return t.isTSUnknownKeyword(type) ? t.tsTypeReference(t.identifier('HTMLElement')) : type;
246
+ })();
247
+ const names = [...core.inputs, ...core.setters, ...core.boxes];
248
+ const elementParam = t.identifier('element');
249
+ elementParam.typeAnnotation = t.tsTypeAnnotation(elementType);
250
+ const inputParam = t.identifier('input');
251
+ inputParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(inputName)));
252
+ const fnBody = t.blockStatement([
253
+ ...(names.length ? [t.variableDeclaration('const', [t.variableDeclarator(t.objectPattern(names.map((n) => t.objectProperty(t.identifier(n), t.identifier(n), false, true))), t.identifier('input'))])] : []),
254
+ ...rewritten.body,
255
+ ]);
256
+ // a body that may end without a cleanup says so: the declared type admits undefined, which TypeScript wants returned
257
+ const last = fnBody.body[fnBody.body.length - 1];
258
+ if (!t.isReturnStatement(last) && !t.isThrowStatement(last))
259
+ fnBody.body.push(t.returnStatement(t.identifier('undefined')));
260
+ const fn = t.functionDeclaration(t.identifier(core.name), names.length ? [elementParam, inputParam] : [elementParam], fnBody);
261
+ fn.returnType = t.tsTypeAnnotation(t.tsUnionType([t.tsParenthesizedType(t.tsFunctionType(null, [], t.tsTypeAnnotation(t.tsVoidKeyword()))), t.tsUndefinedKeyword()]));
262
+ const statements = [];
263
+ if (names.length)
264
+ statements.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(inputName), null, null, t.tsInterfaceBody(members))));
265
+ const doc = t.exportNamedDeclaration(fn);
266
+ t.addComment(doc, 'leading', `* Starts the ${ir.name} loop on its element; returns the cleanup. Framework-free: wrap it in any component. `, false);
267
+ statements.push(doc);
268
+ return {
269
+ statements,
270
+ moduleNames,
271
+ call: (_target, read, element, box, setter) => {
272
+ const props = [];
273
+ for (const name of core.inputs)
274
+ props.push(t.objectProperty(t.identifier(name), read(name), false, false));
275
+ for (const name of core.setters) {
276
+ const set = setter(name);
277
+ const state = ir.bindings.get(name)?.state;
278
+ // an updater is applied to the state as it is now: `(value) => (x.value = typeof value === 'function' ? value(x.value) : value)`
279
+ const applied = updaters.has(name) && state && t.isArrowFunctionExpression(set) && t.isIdentifier(set.params[0]) ? applyUpdater(set, set.params[0].name, read(state)) : set;
280
+ props.push(t.objectProperty(t.identifier(name), applied));
281
+ }
282
+ for (const name of core.boxes)
283
+ props.push(t.objectProperty(t.identifier(name), box(name)));
284
+ for (const p of props)
285
+ if (t.isIdentifier(p.value) && t.isIdentifier(p.key) && p.value.name === p.key.name)
286
+ p.shorthand = true;
287
+ const args = names.length ? [element, t.objectExpression(props)] : [element];
288
+ return t.blockStatement([t.returnStatement(t.callExpression(t.identifier(core.name), args))]);
289
+ },
290
+ };
291
+ }
292
+ /**
293
+ * JSX that reached script code (a hook returning elements, a value assembled from elements) has no form outside a
294
+ * template: it becomes `null` with a comment saying so, and the caller reports an error. Returns how many were cut.
295
+ */
296
+ export function cutLeftoverJsx(stmts) {
297
+ let count = 0;
298
+ for (const s of stmts) {
299
+ transform(s, (n) => {
300
+ if (!t.isJSXElement(n) && !t.isJSXFragment(n))
301
+ return null;
302
+ count++;
303
+ const replacement = t.nullLiteral();
304
+ t.addComment(replacement, 'leading', ' antheo-morph: elements in script code are not converted ', false);
305
+ return replacement;
306
+ });
307
+ }
308
+ return count;
309
+ }
310
+ /**
311
+ * Writes to module-level `let`s that moved into a shared module (ES imports are read-only): `seq = v` becomes
312
+ * `setSeq(v)`, `++seq` `setSeq(seq + 1)`. Returns the names written, so the shared module can export their setters.
313
+ */
314
+ export function routeModuleWrites(nodes, names, shadowed) {
315
+ const written = new Set();
316
+ if (!names.size)
317
+ return written;
318
+ const setter = (name) => `set${name.charAt(0).toUpperCase()}${name.slice(1)}`;
319
+ for (const node of nodes) {
320
+ transform(node, (n) => {
321
+ if (t.isAssignmentExpression(n) && t.isIdentifier(n.left) && names.has(n.left.name) && !shadowed.has(n.left.name)) {
322
+ const name = n.left.name;
323
+ written.add(name);
324
+ const value = n.operator === '=' ? n.right : t.binaryExpression(n.operator.slice(0, -1), t.identifier(name), n.right);
325
+ return t.callExpression(t.identifier(setter(name)), [value]);
326
+ }
327
+ if (t.isUpdateExpression(n) && t.isIdentifier(n.argument) && names.has(n.argument.name) && !shadowed.has(n.argument.name)) {
328
+ const name = n.argument.name;
329
+ written.add(name);
330
+ const next = t.binaryExpression(n.operator === '++' ? '+' : '-', t.identifier(name), t.numericLiteral(1));
331
+ const call = t.callExpression(t.identifier(setter(name)), [next]);
332
+ // postfix: the value before the update
333
+ return n.prefix ? call : t.binaryExpression(n.operator === '++' ? '-' : '+', call, t.numericLiteral(1));
334
+ }
335
+ return null;
336
+ });
337
+ }
338
+ return written;
339
+ }
340
+ /** `export function setSeq(value) { return (seq = value); }` for each name a component writes. */
341
+ export function moduleSetters(names) {
342
+ return [...names].sort().map((name) => {
343
+ const value = t.identifier('value');
344
+ const fn = t.functionDeclaration(t.identifier(`set${name.charAt(0).toUpperCase()}${name.slice(1)}`), [value], t.blockStatement([t.returnStatement(t.assignmentExpression('=', t.identifier(name), t.identifier('value')))]));
345
+ return t.exportNamedDeclaration(fn);
346
+ });
347
+ }
348
+ /** Module-level names declared with `let` or `var` (the ones a component might reassign). */
349
+ export function moduleLets(body) {
350
+ const out = new Set();
351
+ for (const s of body) {
352
+ const decl = t.isExportNamedDeclaration(s) ? s.declaration : s;
353
+ if (t.isVariableDeclaration(decl) && decl.kind !== 'const')
354
+ for (const n of Object.keys(t.getOuterBindingIdentifiers(decl)))
355
+ out.add(n);
356
+ }
357
+ return out;
358
+ }
359
+ /** A typed `ref<T>()` / `$state<T>()` call. */
360
+ export function typedCall(callee, type, args) {
361
+ const call = t.callExpression(t.identifier(callee), args);
362
+ if (type)
363
+ call.typeParameters = t.tsTypeParameterInstantiation([t.cloneNode(type, true)]);
364
+ return call;
365
+ }
366
+ /** Names bound by a derived item's pattern, or the block's single name. */
367
+ export function itemNames(item) {
368
+ switch (item.kind) {
369
+ case 'derived':
370
+ return item.names;
371
+ case 'block':
372
+ case 'state':
373
+ case 'ref':
374
+ case 'function':
375
+ case 'id':
376
+ case 'context':
377
+ return [item.name];
378
+ case 'reducer':
379
+ return [item.name, item.dispatch];
380
+ case 'hook':
381
+ return item.id ? patternNames(item.id) : [];
382
+ default:
383
+ return [];
384
+ }
385
+ }
386
+ /** A type that admits null: as written when it already does (`HTMLElement | null`), else with null added. */
387
+ export function orNull(type) {
388
+ const admits = (x) => t.isTSNullKeyword(x) || t.isTSAnyKeyword(x) || t.isTSUnknownKeyword(x) || (t.isTSUnionType(x) && x.types.some(admits)) || (t.isTSParenthesizedType(x) && admits(x.typeAnnotation));
389
+ return admits(type) ? type : t.tsUnionType([type, t.tsNullKeyword()]);
390
+ }
391
+ /** A type that admits undefined: as written when it already does, else with undefined added. */
392
+ function orUndefined(type) {
393
+ const admits = (x) => t.isTSUndefinedKeyword(x) || t.isTSVoidKeyword(x) || t.isTSAnyKeyword(x) || t.isTSUnknownKeyword(x) || (t.isTSUnionType(x) && x.types.some(admits)) || (t.isTSParenthesizedType(x) && admits(x.typeAnnotation));
394
+ return admits(type) ? type : t.tsUnionType([type, t.tsUndefinedKeyword()]);
395
+ }
396
+ /**
397
+ * What `useRef<T>(init)` holds, as React's types say: `T | null` from `null`, `T | undefined` from nothing or
398
+ * `undefined` (`useRef<ReturnType<typeof setTimeout>>(undefined)`), and `T` from any other value.
399
+ */
400
+ export function refHolds(type, init) {
401
+ if (t.isNullLiteral(init))
402
+ return orNull(type);
403
+ if (!init || t.isIdentifier(init, { name: 'undefined' }))
404
+ return orUndefined(type);
405
+ return type;
406
+ }
@@ -0,0 +1,12 @@
1
+ import type { Diagnostic } from '../../types.js';
2
+ import { type Project } from '../../analyzer/deps.js';
3
+ import { type SourceFile } from './react-libs.js';
4
+ /**
5
+ * An error found in a component (or any declaration) of an imported file that nothing the converted file uses reaches,
6
+ * through what it renders, calls or reads (shadcn's `pagination.tsx` imports only `buttonVariants` from `button.tsx`,
7
+ * whose `Button` renders a Radix Slot): that declaration is not converted as it should be, but the converted file does
8
+ * not need it, so it does not refuse the conversion. The error becomes a warning that says so. An error with no line
9
+ * (not attributable to one declaration), in the entry file, or in a file read whole (a namespace or side-effect import)
10
+ * stays an error.
11
+ */
12
+ export declare function sparesUnusedComponents(diagnostics: Diagnostic[], sources: SourceFile[], entry: string, project: Project, fileOf: (diagnosticFile: string) => string | null): void;