@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,567 @@
1
+ import { dirname, relative } from 'node:path';
2
+ import * as t from '@babel/types';
3
+ import { resolveLocal } from '../analyzer/deps.js';
4
+ import { parseSource, traverse } from '../analyzer/parse.js';
5
+ import { toPosix } from '../utils/fs-safe.js';
6
+ import { SliceChecker } from './extract-ui-types.js';
7
+ /**
8
+ * M6, `--extract-ui` (opt-in, CompileOptions.extractUi): program slicing at the app boundary. A component that reads
9
+ * the app around it (Next's router, a store hook, a server action, data it awaits while it renders) is refused by
10
+ * default. With the option on, the entry file's own component is sliced first, before anything is lowered: each value
11
+ * it read from the app becomes a value prop, each call into the app a callback prop, and the rest of the pipeline
12
+ * converts that pure component as any other.
13
+ *
14
+ * What is sliced is decided by what it is, never by a name: Next's hooks by their module (`next/navigation`), a store
15
+ * hook by its declaration (an export of a project file whose value is zustand's `create(...)`), a server action by its
16
+ * module's `'use server'` directive, awaited data by the component being `async`. Each kind slices only in the shapes
17
+ * below; any other shape leaves the file exactly as without the option (refused as before), with one `ui-extract-skipped`
18
+ * note saying what stopped it.
19
+ *
20
+ * The slice is a source edit that keeps every line where it was (removed code becomes spaces), so every later
21
+ * diagnostic's line is the source's. The lifted props' types come from TypeScript's checker on the source (the project's
22
+ * own types and the installed ones), written out in full (extract-ui-types); a type that cannot be written exactly
23
+ * refuses the slice.
24
+ */
25
+ /** The `next/navigation` hooks that slice, by their exported name. */
26
+ const NAV_HOOKS = new Set(['useRouter', 'usePathname', 'useSearchParams', 'useParams']);
27
+ /** The router's methods a call may use; each used one becomes a callback prop `onRouter<Method>`. */
28
+ const ROUTER_METHODS = new Set(['push', 'replace', 'back', 'forward', 'refresh', 'prefetch']);
29
+ /** zustand's store factory (`create` from 'zustand'): its result is a store hook. */
30
+ const STORE_FACTORIES = { zustand: new Set(['create']) };
31
+ class Skip extends Error {
32
+ line;
33
+ constructor(message, line) {
34
+ super(message);
35
+ this.line = line;
36
+ }
37
+ }
38
+ const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
39
+ const lineOf = (n) => n.loc?.start.line ?? 0;
40
+ /**
41
+ * Slices the entry of a graph in place (its code, its deps, and the nodes only it reached through a sliced import).
42
+ * Returns null when the entry reads nothing from the app: the conversion is then exactly what it is without the option.
43
+ */
44
+ export function extractUi(entry, nodes, project) {
45
+ const node = nodes.find((n) => n.file === entry);
46
+ if (!node || node.css || node.data || !/\.(tsx|jsx|ts|js)$/.test(entry))
47
+ return null;
48
+ const rel = toPosix(relative(project.root, entry));
49
+ let plan;
50
+ try {
51
+ plan = planSlice(node, nodes, project);
52
+ }
53
+ catch (error) {
54
+ if (!(error instanceof Skip))
55
+ throw error;
56
+ return { component: '', lifted: [], contract: null, diagnostics: [{ code: 'ui-extract-skipped', severity: 'info', message: `--extract-ui did not slice this file: ${error.message} It converts as it does without the option.`, file: rel, ...(error.line ? { line: error.line } : {}) }] };
57
+ }
58
+ if (!plan)
59
+ return null;
60
+ node.code = plan.code;
61
+ node.deps = node.deps.filter((d) => !plan.dropped.has(d));
62
+ // the files reached only through a sliced import leave the graph (the store module and what it imports)
63
+ const byFile = new Map(nodes.map((n) => [n.file, n]));
64
+ const reach = new Set();
65
+ const walk = (file) => {
66
+ if (reach.has(file))
67
+ return;
68
+ reach.add(file);
69
+ for (const d of byFile.get(file)?.deps ?? [])
70
+ walk(d);
71
+ };
72
+ walk(entry);
73
+ for (let i = nodes.length - 1; i >= 0; i--)
74
+ if (!reach.has(nodes[i]?.file ?? ''))
75
+ nodes.splice(i, 1);
76
+ const listed = plan.lifted.map((p) => `${p.name}: ${p.type} (${p.from}, line${p.lines.length > 1 ? 's' : ''} ${p.lines.join(', ')})`).join('; ');
77
+ const contractPath = `${dirname(node.rel) === '.' ? '' : `${toPosix(dirname(node.rel))}/`}${plan.component}.contract.ts`;
78
+ const notes = plan.notes.length ? ` Types: ${[...new Set(plan.notes)].join('; ')}.` : '';
79
+ const message = `${plan.component} was sliced from its app (--extract-ui): it no longer reads the router, a store or the server itself, and it takes these props in their place, which the caller must now pass and wire up: ${listed}.${notes} The exact boundary is ${contractPath} (ExtractedContract). Its props are wider than the source's, so this is not the source component.`;
80
+ const contract = contractFile(contractPath, plan, rel);
81
+ return { component: plan.component, lifted: plan.lifted, contract, diagnostics: [{ code: 'ui-extracted', severity: 'warning', message, file: rel, line: plan.line }] };
82
+ }
83
+ function contractFile(path, plan, sourceRel) {
84
+ const members = plan.lifted.map((p) => ` /** ${p.from} (${sourceRel}, line${p.lines.length > 1 ? 's' : ''} ${p.lines.join(', ')}) */\n ${p.name}: ${p.type};`).join('\n');
85
+ const contents = `// antheo-morph --extract-ui: the props ${plan.component} takes in place of the app APIs it read in ${sourceRel}.\n// Its own props are unchanged; these are new, and the caller must pass every one.\nexport interface ExtractedContract {\n${members}\n}\n`;
86
+ return { path, contents, kind: 'module' };
87
+ }
88
+ function planSlice(node, nodes, project) {
89
+ const code = node.code;
90
+ const ast = parseSource(code, node.file);
91
+ const roles = new Map(); // local name -> role
92
+ const sliceDecls = new Set();
93
+ for (const stmt of ast.program.body) {
94
+ if (!t.isImportDeclaration(stmt) || stmt.importKind === 'type')
95
+ continue;
96
+ const source = stmt.source.value;
97
+ const values = stmt.specifiers.filter((s) => !(t.isImportSpecifier(s) && s.importKind === 'type'));
98
+ if (source === 'next/navigation') {
99
+ for (const s of values) {
100
+ const imported = t.isImportSpecifier(s) ? (t.isIdentifier(s.imported) ? s.imported.name : s.imported.value) : null;
101
+ if (!imported || !NAV_HOOKS.has(imported))
102
+ throw new Skip(`it imports ${imported ?? s.local.name} from next/navigation, which is not one of the hooks it lifts (${[...NAV_HOOKS].join(', ')}).`, lineOf(stmt));
103
+ roles.set(s.local.name, { role: 'nav', decl: stmt });
104
+ }
105
+ sliceDecls.add(stmt);
106
+ continue;
107
+ }
108
+ const file = resolveLocal(node.file, source, project);
109
+ const target = file ? nodes.find((n) => n.file === file) : undefined;
110
+ if (!file || !target || target.css || target.data)
111
+ continue;
112
+ const mod = parseSource(target.code, target.file);
113
+ const server = mod.program.directives.some((d) => d.value.value === 'use server');
114
+ let sliced = 0;
115
+ for (const s of values) {
116
+ if (server) {
117
+ if (!t.isImportSpecifier(s))
118
+ throw new Skip(`it imports the 'use server' module ${source} as a whole; only named server actions are lifted.`, lineOf(stmt));
119
+ roles.set(s.local.name, { role: 'action', decl: stmt, file });
120
+ sliced++;
121
+ continue;
122
+ }
123
+ const name = t.isImportSpecifier(s) ? (t.isIdentifier(s.imported) ? s.imported.name : s.imported.value) : t.isImportDefaultSpecifier(s) ? 'default' : null;
124
+ const store = name ? storeDeclaration(mod, name) : null;
125
+ if (store) {
126
+ roles.set(s.local.name, { role: 'store', decl: stmt, file, stateType: store.stateType === null ? null : { file, offset: store.stateType } });
127
+ sliced++;
128
+ }
129
+ }
130
+ if (sliced && sliced !== values.length)
131
+ throw new Skip(`it imports ${source} for more than the store hooks or server actions it lifts.`, lineOf(stmt));
132
+ if (sliced && values.length !== stmt.specifiers.length)
133
+ throw new Skip(`it imports types from ${source} beside what it lifts; that module leaves the conversion.`, lineOf(stmt));
134
+ if (sliced)
135
+ sliceDecls.add(stmt);
136
+ }
137
+ // the component: the top-level function whose body reads the app (or that is async)
138
+ let program = null;
139
+ traverse(ast, {
140
+ Program(path) {
141
+ program = path;
142
+ path.stop();
143
+ },
144
+ });
145
+ if (!program)
146
+ return null;
147
+ const prog = program;
148
+ const components = [];
149
+ for (const stmt of prog.get('body')) {
150
+ const fn = componentFunction(stmt);
151
+ if (fn)
152
+ components.push(fn);
153
+ }
154
+ const uses = components.filter((fn) => fn.node.async || [...roles.keys()].some((local) => referencedIn(prog, local, fn)));
155
+ if (!uses.length)
156
+ return null;
157
+ if (uses.length > 1)
158
+ throw new Skip(`more than one component reads the app (${uses.map((f) => functionName(f)).join(', ')}); only one is sliced per file.`, lineOf(uses[1]?.node ?? ast));
159
+ const fn = uses[0];
160
+ const component = functionName(fn);
161
+ // every read of a lifted import is inside that component
162
+ for (const local of roles.keys()) {
163
+ const binding = prog.scope.getBinding(local);
164
+ for (const ref of binding?.referencePaths ?? []) {
165
+ if (!ref.findParent((p) => p === fn))
166
+ throw new Skip(`${local} is read outside ${component}.`, lineOf(ref.node));
167
+ }
168
+ }
169
+ const checker = new SliceChecker(project, nodes.filter((n) => !n.css && !n.data).map((n) => n.file));
170
+ const edits = [];
171
+ const blanked = [];
172
+ const blank = (n) => {
173
+ const start = n.start ?? 0;
174
+ const end = n.end ?? 0;
175
+ edits.push({ start, end, text: code.slice(start, end).replace(/[^\r\n]/g, ' ') });
176
+ blanked.push([start, end]);
177
+ };
178
+ const lifted = [];
179
+ const notes = [];
180
+ const typeOf = (id, what) => {
181
+ const type = checker.typeAt(node.file, id.start ?? -1);
182
+ if (!type)
183
+ throw new Skip(`TypeScript gives ${what} no type it can write (any or unknown).`, lineOf(id));
184
+ checker.notes = [];
185
+ const text = checker.print(type);
186
+ notes.push(...checker.notes);
187
+ if (text === null)
188
+ throw new Skip(`the type of ${what} cannot be written out in full (it refers to itself, is overloaded, or is a library type with no standard counterpart).`, lineOf(id));
189
+ return { text, fn: checker.isFunction(type) };
190
+ };
191
+ const taken = (name) => fn.scope.hasBinding(name) && !roles.has(name);
192
+ const add = (p) => {
193
+ if (lifted.some((x) => x.name === p.name))
194
+ throw new Skip(`two app values would both become the prop ${p.name}.`, p.lines[0]);
195
+ lifted.push(p);
196
+ };
197
+ const renameRefs = (local, to, scope) => {
198
+ const binding = scope.scope.getBinding(local);
199
+ for (const ref of binding?.referencePaths ?? [])
200
+ edits.push({ start: ref.node.start ?? 0, end: ref.node.end ?? 0, text: to });
201
+ };
202
+ const body = fn.get('body');
203
+ if (!body.isBlockStatement())
204
+ throw new Skip(`${component} returns its markup without a body; it has no app reads to lift.`, lineOf(fn.node));
205
+ for (const stmt of body.get('body')) {
206
+ if (!stmt.isVariableDeclaration())
207
+ continue;
208
+ const decls = stmt.node.declarations;
209
+ const call = (d) => (d && t.isCallExpression(d.init) && t.isIdentifier(d.init.callee) && roles.has(d.init.callee.name) ? d.init : null);
210
+ const awaited = decls.some((d) => t.isAwaitExpression(d.init));
211
+ if (!decls.some((d) => call(d)) && !awaited)
212
+ continue;
213
+ if (decls.length !== 1)
214
+ throw new Skip(`one declaration reads the app beside other values; write each on its own line.`, lineOf(stmt.node));
215
+ const d = decls[0];
216
+ if (awaited) {
217
+ // `const orders = await getOrders()`: the awaited value is a prop
218
+ if (!fn.node.async || !t.isIdentifier(d.id))
219
+ throw new Skip(`an await that is not \`const name = await …\` in an async component.`, lineOf(stmt.node));
220
+ const { text } = typeOf(d.id, d.id.name);
221
+ add({ name: d.id.name, type: text, kind: 'value', from: `the value ${component} awaited while it rendered`, lines: [lineOf(stmt.node)] });
222
+ blank(stmt.node);
223
+ continue;
224
+ }
225
+ const c = call(d);
226
+ const role = roles.get(c.callee.name);
227
+ const hook = c.callee.name;
228
+ if (role.role === 'action')
229
+ throw new Skip(`the server action ${hook} is called while ${component} renders; only calls from its handlers are lifted.`, lineOf(stmt.node));
230
+ if (role.role === 'nav') {
231
+ const imported = importedName(role.decl, hook);
232
+ if (imported === 'useRouter') {
233
+ if (!t.isIdentifier(d.id))
234
+ throw new Skip(`useRouter()'s router is destructured; only \`const router = useRouter()\` is lifted.`, lineOf(stmt.node));
235
+ const routerType = checker.typeAt(node.file, d.id.start ?? -1);
236
+ const binding = stmt.scope.getBinding(d.id.name);
237
+ const methods = new Map();
238
+ for (const ref of binding?.referencePaths ?? []) {
239
+ const member = ref.parentPath;
240
+ const prop = member?.isMemberExpression() && member.node.object === ref.node && !member.node.computed && t.isIdentifier(member.node.property) ? member.node.property.name : null;
241
+ const callPath = member?.parentPath;
242
+ if (!prop || !ROUTER_METHODS.has(prop) || !callPath?.isCallExpression() || callPath.node.callee !== member?.node)
243
+ throw new Skip(`${d.id.name} (useRouter()) is used other than by calling one of its methods (${[...ROUTER_METHODS].join(', ')}).`, lineOf(ref.node));
244
+ const m = methods.get(prop) ?? { arity: 0, lines: [] };
245
+ m.arity = Math.max(m.arity, callPath.node.arguments.length);
246
+ if (callPath.node.arguments.some((a) => t.isSpreadElement(a)))
247
+ throw new Skip(`${d.id.name}.${prop} is called with a spread argument.`, lineOf(ref.node));
248
+ m.lines.push(lineOf(ref.node));
249
+ methods.set(prop, m);
250
+ const name = `onRouter${cap(prop)}`;
251
+ if (taken(name))
252
+ throw new Skip(`${component} already declares ${name}.`, lineOf(ref.node));
253
+ edits.push({ start: member?.node.start ?? 0, end: member?.node.end ?? 0, text: name });
254
+ }
255
+ for (const [method, m] of methods) {
256
+ const sig = routerType ? checker.member(routerType, method)?.getCallSignatures()[0] : undefined;
257
+ const type = sig ? checker.signature(sig, m.arity) : null;
258
+ if (type === null)
259
+ throw new Skip(`router.${method}'s type did not resolve from next/navigation's declarations.`, m.lines[0]);
260
+ add({ name: `onRouter${cap(method)}`, type: type.replace(/=> [^=]*$/, '=> void'), kind: 'callback', from: `router.${method} of useRouter() from next/navigation`, lines: m.lines });
261
+ }
262
+ blank(stmt.node);
263
+ continue;
264
+ }
265
+ if (!t.isIdentifier(d.id))
266
+ throw new Skip(`${imported}()'s value is destructured; only \`const name = ${imported}()\` is lifted.`, lineOf(stmt.node));
267
+ const { text } = typeOf(d.id, `${imported}()`);
268
+ add({ name: d.id.name, type: text, kind: 'value', from: `${imported}() from next/navigation`, lines: [lineOf(stmt.node)] });
269
+ blank(stmt.node);
270
+ continue;
271
+ }
272
+ // a store hook: `const user = useStore((s) => s.user)` or `const { user, logout } = useStore()`
273
+ const lift = (local, path) => {
274
+ let type = checker.typeAt(node.file, local.start ?? -1);
275
+ let note = '';
276
+ // the store library's types did not resolve: the state type the store declares (`create<State>()`), read along
277
+ // the selector's path
278
+ if (!type && role.stateType && path) {
279
+ const stateNode = checker.typeNodeAt(role.stateType.file, role.stateType.offset);
280
+ let at = stateNode ? checker.checker.getTypeFromTypeNode(stateNode) : null;
281
+ for (const key of path)
282
+ at = at ? checker.member(at, key) : null;
283
+ type = at;
284
+ note = `${local.name} is typed from the state type the store declares, as the store library's own types did not resolve`;
285
+ }
286
+ if (!type)
287
+ throw new Skip(`TypeScript gives ${local.name} (from the store hook ${hook}) no type, and the store declares no state type morph can read along this selector.`, lineOf(local));
288
+ checker.notes = [];
289
+ const text = checker.print(type);
290
+ notes.push(...checker.notes, ...(note ? [note] : []));
291
+ if (text === null)
292
+ throw new Skip(`the type of ${local.name} (from the store hook ${hook}) cannot be written out in full.`, lineOf(local));
293
+ const isFn = checker.isFunction(type);
294
+ const name = isFn && !/^on[A-Z]/.test(local.name) ? `on${cap(local.name)}` : local.name;
295
+ if (name !== local.name) {
296
+ if (taken(name))
297
+ throw new Skip(`${component} already declares ${name}.`, lineOf(local));
298
+ renameRefs(local.name, name, stmt);
299
+ }
300
+ add({ name, type: text, kind: isFn ? 'callback' : 'value', from: `${path ? `${path.join('.')} of ` : ''}the store hook ${hook} (${relPath(node.file, role.role === 'store' ? role.file : '')})`, lines: [lineOf(stmt.node)] });
301
+ };
302
+ if (t.isIdentifier(d.id)) {
303
+ const selector = c.arguments[0];
304
+ if (c.arguments.length > 1)
305
+ throw new Skip(`${hook} is called with more than a selector.`, lineOf(stmt.node));
306
+ if (!selector)
307
+ throw new Skip(`${hook}() is read whole into ${d.id.name}; only a selector (\`${hook}((s) => s.user)\`) or destructured fields are lifted.`, lineOf(stmt.node));
308
+ lift(d.id, selectorPath(selector));
309
+ }
310
+ else if (t.isObjectPattern(d.id) && c.arguments.length === 0) {
311
+ for (const p of d.id.properties) {
312
+ if (!t.isObjectProperty(p) || p.computed || !t.isIdentifier(p.key) || !t.isIdentifier(p.value))
313
+ throw new Skip(`${hook}()'s fields are destructured in a shape other than \`{ a, b: c }\`.`, lineOf(stmt.node));
314
+ lift(p.value, [p.key.name]);
315
+ }
316
+ }
317
+ else
318
+ throw new Skip(`${hook}'s value is read in a shape other than \`const x = ${hook}(selector)\` or \`const { a, b } = ${hook}()\`.`, lineOf(stmt.node));
319
+ blank(stmt.node);
320
+ }
321
+ // server actions: each becomes a callback prop `on<Action>`
322
+ for (const [local, role] of roles) {
323
+ if (role.role !== 'action')
324
+ continue;
325
+ const binding = prog.scope.getBinding(local);
326
+ const refs = binding?.referencePaths ?? [];
327
+ if (!refs.length)
328
+ continue;
329
+ const id = binding?.identifier;
330
+ if (!id)
331
+ continue;
332
+ const type = checker.typeAt(node.file, id.start ?? -1);
333
+ if (!type)
334
+ throw new Skip(`TypeScript gives the server action ${local} no type.`, lineOf(id));
335
+ checker.notes = [];
336
+ const text = checker.print(type);
337
+ notes.push(...checker.notes);
338
+ if (text === null || !checker.isFunction(type))
339
+ throw new Skip(`the server action ${local}'s type cannot be written out as a function type.`, lineOf(id));
340
+ const name = /^on[A-Z]/.test(local) ? local : `on${cap(local)}`;
341
+ if (taken(name))
342
+ throw new Skip(`${component} already declares ${name}.`, lineOf(id));
343
+ for (const ref of refs)
344
+ edits.push({ start: ref.node.start ?? 0, end: ref.node.end ?? 0, text: name });
345
+ add({ name, type: text, kind: 'callback', from: `the server action ${local} ('use server' in ${relPath(node.file, role.file)})`, lines: refs.map((r) => lineOf(r.node)) });
346
+ }
347
+ // the awaits left are not `const x = await …` at the top of the body
348
+ if (fn.node.async) {
349
+ let stray = null;
350
+ fn.traverse({
351
+ AwaitExpression(p) {
352
+ if (!stray && p.getFunctionParent() === fn && !blanked.some(([s, e]) => (p.node.start ?? 0) >= s && (p.node.end ?? 0) <= e))
353
+ stray = p.node;
354
+ },
355
+ ForOfStatement(p) {
356
+ if (!stray && p.node.await && p.getFunctionParent() === fn)
357
+ stray = p.node;
358
+ },
359
+ });
360
+ if (stray)
361
+ throw new Skip(`${component} awaits other than in \`const name = await …\` at the top of its body.`, lineOf(stray));
362
+ const start = fn.node.start ?? 0;
363
+ const at = code.indexOf('async', start);
364
+ if (at < 0 || at > (fn.node.body.start ?? 0))
365
+ throw new Skip(`the async keyword of ${component} was not found.`, lineOf(fn.node));
366
+ edits.push({ start: at, end: at + 5, text: ' ' });
367
+ }
368
+ if (!lifted.length)
369
+ return null;
370
+ // the imports the slice no longer reads: the app's, and any whose every read was in removed code
371
+ const inBlank = (n) => blanked.some(([s, e]) => (n.start ?? 0) >= s && (n.end ?? 0) <= e);
372
+ const dropped = new Set();
373
+ for (const stmt of ast.program.body) {
374
+ if (!t.isImportDeclaration(stmt) || !stmt.specifiers.length)
375
+ continue;
376
+ const unread = stmt.specifiers.every((s) => {
377
+ const refs = prog.scope.getBinding(s.local.name)?.referencePaths ?? [];
378
+ return refs.length > 0 && refs.every((r) => inBlank(r.node));
379
+ });
380
+ if (!sliceDecls.has(stmt) && !(unread && stmt.importKind !== 'type' && fn.node.async))
381
+ continue;
382
+ // a server action's import is gone once its reads are props
383
+ blank(stmt);
384
+ const file = resolveLocal(node.file, stmt.source.value, project);
385
+ if (file)
386
+ dropped.add(file);
387
+ }
388
+ // a file still imported by another declaration stays
389
+ for (const stmt of ast.program.body) {
390
+ if (!t.isImportDeclaration(stmt) || blanked.some(([s]) => s === stmt.start))
391
+ continue;
392
+ const file = resolveLocal(node.file, stmt.source.value, project);
393
+ if (file)
394
+ dropped.delete(file);
395
+ }
396
+ addProps(fn, code, lifted, edits);
397
+ const sliced = applyEdits(code, edits);
398
+ try {
399
+ parseSource(sliced, node.file);
400
+ }
401
+ catch {
402
+ throw new Skip(`the sliced source did not parse.`, lineOf(fn.node));
403
+ }
404
+ return { code: sliced, component, line: lineOf(fn.node), lifted, dropped, notes };
405
+ }
406
+ /** `(s) => s.user.name` as ['user', 'name']; null for any other selector. */
407
+ function selectorPath(selector) {
408
+ if (!t.isArrowFunctionExpression(selector) || selector.params.length !== 1 || !t.isIdentifier(selector.params[0]))
409
+ return null;
410
+ const param = selector.params[0].name;
411
+ const path = [];
412
+ let e = selector.body;
413
+ while (t.isMemberExpression(e) && !e.computed && t.isIdentifier(e.property)) {
414
+ path.unshift(e.property.name);
415
+ e = e.object;
416
+ }
417
+ return t.isIdentifier(e) && e.name === param && path.length ? path : null;
418
+ }
419
+ /** The declaration of an export of a store module: `export const useX = create<State>()(…)` (zustand), or null. */
420
+ function storeDeclaration(mod, exported) {
421
+ const factories = new Set();
422
+ for (const stmt of mod.program.body) {
423
+ if (!t.isImportDeclaration(stmt) || stmt.importKind === 'type')
424
+ continue;
425
+ const names = STORE_FACTORIES[stmt.source.value];
426
+ if (!names)
427
+ continue;
428
+ for (const s of stmt.specifiers) {
429
+ if (t.isImportSpecifier(s) && names.has(t.isIdentifier(s.imported) ? s.imported.name : s.imported.value))
430
+ factories.add(s.local.name);
431
+ }
432
+ }
433
+ if (!factories.size)
434
+ return null;
435
+ let local = exported;
436
+ if (exported === 'default') {
437
+ const d = mod.program.body.find((s) => t.isExportDefaultDeclaration(s));
438
+ if (!d || !t.isIdentifier(d.declaration))
439
+ return null;
440
+ local = d.declaration.name;
441
+ }
442
+ for (const stmt of mod.program.body) {
443
+ const decl = t.isExportNamedDeclaration(stmt) ? stmt.declaration : stmt;
444
+ if (!t.isVariableDeclaration(decl))
445
+ continue;
446
+ for (const d of decl.declarations) {
447
+ if (!t.isIdentifier(d.id) || d.id.name !== local || !t.isCallExpression(d.init))
448
+ continue;
449
+ // create(fn), create<State>(fn), create<State>()(fn)
450
+ const outer = d.init;
451
+ const inner = t.isCallExpression(outer.callee) ? outer.callee : outer;
452
+ if (!t.isIdentifier(inner.callee) || !factories.has(inner.callee.name))
453
+ return null;
454
+ const arg = inner.typeParameters?.params[0];
455
+ return { stateType: arg?.start ?? null };
456
+ }
457
+ }
458
+ // `export { useX }` of a local declared above is found by the loop (the declaration need not be exported in place)
459
+ return null;
460
+ }
461
+ function importedName(decl, local) {
462
+ for (const s of decl.specifiers)
463
+ if (s.local.name === local && t.isImportSpecifier(s))
464
+ return t.isIdentifier(s.imported) ? s.imported.name : s.imported.value;
465
+ return null;
466
+ }
467
+ function relPath(from, to) {
468
+ const r = toPosix(relative(dirname(from), to)).replace(/\.(tsx|ts|jsx|js)$/, '');
469
+ return r.startsWith('.') ? r : `./${r}`;
470
+ }
471
+ /** A top-level component: a capitalised function declaration (exported or not) or `const Name = (…) => {…}`. */
472
+ function componentFunction(stmt) {
473
+ let target = stmt;
474
+ if (stmt.isExportNamedDeclaration() || stmt.isExportDefaultDeclaration()) {
475
+ const d = stmt.get('declaration');
476
+ if (Array.isArray(d) || !d.node)
477
+ return null;
478
+ target = d;
479
+ }
480
+ if (target.isFunctionDeclaration())
481
+ return /^[A-Z]/.test(target.node.id?.name ?? (stmt.isExportDefaultDeclaration() ? 'Default' : '')) ? target : null;
482
+ if (target.isVariableDeclaration() && target.node.declarations.length === 1) {
483
+ const d = target.get('declarations')[0];
484
+ const init = d?.get('init');
485
+ if (d && t.isIdentifier(d.node.id) && /^[A-Z]/.test(d.node.id.name) && init && !Array.isArray(init) && (init.isArrowFunctionExpression() || init.isFunctionExpression()))
486
+ return init;
487
+ }
488
+ return null;
489
+ }
490
+ function functionName(fn) {
491
+ if (t.isFunctionDeclaration(fn.node) && fn.node.id)
492
+ return fn.node.id.name;
493
+ const parent = fn.parentPath?.node;
494
+ if (parent && t.isVariableDeclarator(parent) && t.isIdentifier(parent.id))
495
+ return parent.id.name;
496
+ return 'Component';
497
+ }
498
+ function referencedIn(prog, local, fn) {
499
+ return (prog.scope.getBinding(local)?.referencePaths ?? []).some((r) => !!r.findParent((p) => p === fn));
500
+ }
501
+ /** Adds the lifted props to the component's first parameter and to its props type, on the lines they are written on. */
502
+ function addProps(fn, code, lifted, edits) {
503
+ const members = lifted.map((p) => `${p.name}: ${p.type};`).join(' ');
504
+ const names = lifted.map((p) => p.name).join(', ');
505
+ const param = fn.node.params[0];
506
+ const name = functionName(fn);
507
+ if (!param) {
508
+ // `function Page() {`: the parameter list is empty
509
+ const from = t.isFunctionDeclaration(fn.node) && fn.node.id ? (fn.node.typeParameters?.end ?? fn.node.id.end ?? 0) : (fn.node.start ?? 0);
510
+ const open = code.indexOf('(', from);
511
+ if (open < 0)
512
+ throw new Skip(`${name}'s parameter list was not found.`, lineOf(fn.node));
513
+ edits.push({ start: open + 1, end: open + 1, text: `{ ${names} }: { ${members} }` });
514
+ return;
515
+ }
516
+ if (!t.isObjectPattern(param))
517
+ throw new Skip(`${name} reads its props as one object (${t.isIdentifier(param) ? param.name : 'a pattern'}); only destructured props (\`{ a, b }: Props\`) take lifted props.`, lineOf(param));
518
+ if (param.properties.some((p) => t.isRestElement(p)))
519
+ throw new Skip(`${name} gathers its other props with a rest element; lifted props would land in it.`, lineOf(param));
520
+ const last = param.properties[param.properties.length - 1];
521
+ if (last)
522
+ edits.push({ start: last.end ?? 0, end: last.end ?? 0, text: `, ${names}` });
523
+ else {
524
+ const open = code.indexOf('{', param.start ?? 0);
525
+ edits.push({ start: open + 1, end: open + 1, text: ` ${names} ` });
526
+ }
527
+ const annotation = t.isTSTypeAnnotation(param.typeAnnotation) ? param.typeAnnotation.typeAnnotation : null;
528
+ if (!annotation)
529
+ throw new Skip(`${name}'s props have no type annotation for the lifted props' types.`, lineOf(param));
530
+ let body = null;
531
+ if (t.isTSTypeLiteral(annotation))
532
+ body = annotation;
533
+ else if (t.isTSTypeReference(annotation) && t.isIdentifier(annotation.typeName) && !annotation.typeParameters) {
534
+ const typeName = annotation.typeName.name;
535
+ const program = fn.findParent((p) => p.isProgram())?.node;
536
+ for (const stmt of t.isProgram(program) ? program.body : []) {
537
+ const d = t.isExportNamedDeclaration(stmt) ? stmt.declaration : stmt;
538
+ if (t.isTSInterfaceDeclaration(d) && d.id.name === typeName && !d.extends?.length && !d.typeParameters)
539
+ body = d.body;
540
+ if (t.isTSTypeAliasDeclaration(d) && d.id.name === typeName && t.isTSTypeLiteral(d.typeAnnotation) && !d.typeParameters)
541
+ body = d.typeAnnotation;
542
+ }
543
+ }
544
+ if (!body)
545
+ throw new Skip(`${name}'s props type is not a type literal or an interface of this file, so the lifted props have no place to be declared.`, lineOf(param));
546
+ const close = (body.end ?? 0) - 1;
547
+ let i = close - 1;
548
+ while (i > 0 && /\s/.test(code[i] ?? ''))
549
+ i--;
550
+ const sep = code[i] === ';' || code[i] === ',' || code[i] === '{' ? '' : ';';
551
+ edits.push({ start: i + 1, end: i + 1, text: `${sep} ${members}` });
552
+ }
553
+ function applyEdits(code, edits) {
554
+ // an edit inside a blanked range (a rename inside a removed declaration) goes with it
555
+ const blanks = edits.filter((e) => e.end > e.start && /^\s*$/.test(e.text) && e.text.length === e.end - e.start);
556
+ const kept = edits.filter((e) => blanks.includes(e) || !blanks.some((b) => e.start >= b.start && e.end <= b.end));
557
+ const sorted = [...kept].sort((a, b) => b.start - a.start || b.end - a.end);
558
+ let out = code;
559
+ let floor = Number.POSITIVE_INFINITY;
560
+ for (const e of sorted) {
561
+ if (e.end > floor)
562
+ throw new Skip('two edits of the slice overlap.');
563
+ out = out.slice(0, e.start) + e.text + out.slice(e.end);
564
+ floor = e.start;
565
+ }
566
+ return out;
567
+ }
@@ -0,0 +1,13 @@
1
+ import type { ModuleIR } from './model.js';
2
+ import type { TypeOracle } from './oracle.js';
3
+ /**
4
+ * `{count && <Badge/>}` renders `0` in React when `count` is 0 (and `NaN` when it is NaN): React renders a falsy number,
5
+ * and nothing for `false`, `''`, null or undefined. A template's conditional renders nothing when its test fails, so a
6
+ * conditional lowered from `&&` (marked `rendersFalsy`) gets the missing branch here, by the type the checker gives the
7
+ * test where React wrote it:
8
+ * - always a number (or null/undefined, which render nothing): an else branch that renders the value;
9
+ * - sometimes a number (`number | boolean`, an unknown type): an else branch for when it is a number;
10
+ * - never a number (a boolean, a string, an object): nothing to add.
11
+ * Runs on every web target's IR before layout, so every target prints the branch its own way.
12
+ */
13
+ export declare function resolveFalsyRenders(mod: ModuleIR, oracle: TypeOracle): void;
@@ -0,0 +1,66 @@
1
+ import * as t from '@babel/types';
2
+ import { cloneWithRefs } from './rewrite.js';
3
+ /**
4
+ * `{count && <Badge/>}` renders `0` in React when `count` is 0 (and `NaN` when it is NaN): React renders a falsy number,
5
+ * and nothing for `false`, `''`, null or undefined. A template's conditional renders nothing when its test fails, so a
6
+ * conditional lowered from `&&` (marked `rendersFalsy`) gets the missing branch here, by the type the checker gives the
7
+ * test where React wrote it:
8
+ * - always a number (or null/undefined, which render nothing): an else branch that renders the value;
9
+ * - sometimes a number (`number | boolean`, an unknown type): an else branch for when it is a number;
10
+ * - never a number (a boolean, a string, an object): nothing to add.
11
+ * Runs on every web target's IR before layout, so every target prints the branch its own way.
12
+ */
13
+ export function resolveFalsyRenders(mod, oracle) {
14
+ for (const c of mod.components) {
15
+ visit(c.template, c, mod.file, oracle);
16
+ for (const f of c.fragments)
17
+ visit(f.template, c, mod.file, oracle);
18
+ }
19
+ }
20
+ function visit(n, ir, file, oracle) {
21
+ switch (n.type) {
22
+ case 'if': {
23
+ for (const b of n.branches)
24
+ for (const c of b.children)
25
+ visit(c, ir, file, oracle);
26
+ if (!n.rendersFalsy)
27
+ return;
28
+ delete n.rendersFalsy;
29
+ const first = n.branches[0];
30
+ // a later branch (`a && b` never has one) would already render something for the falsy value
31
+ if (!first?.test || n.branches.length !== 1)
32
+ return;
33
+ const kind = oracle.numberKind(file, first.test.loc);
34
+ if (kind === 'never')
35
+ return;
36
+ const value = { type: 'expr', expr: cloneWithRefs(first.test, ir) };
37
+ const test = kind === 'number' ? null : t.binaryExpression('===', t.unaryExpression('typeof', cloneWithRefs(first.test, ir)), t.stringLiteral('number'));
38
+ n.branches.push({ test, children: [value] });
39
+ return;
40
+ }
41
+ case 'element':
42
+ for (const a of n.attrs)
43
+ if (a.kind === 'slotProp')
44
+ for (const c of a.children)
45
+ visit(c, ir, file, oracle);
46
+ for (const c of n.children)
47
+ visit(c, ir, file, oracle);
48
+ return;
49
+ case 'slot':
50
+ for (const c of n.fallback)
51
+ visit(c, ir, file, oracle);
52
+ return;
53
+ case 'for':
54
+ case 'fragment':
55
+ case 'keyed':
56
+ case 'presence':
57
+ for (const c of n.children)
58
+ visit(c, ir, file, oracle);
59
+ return;
60
+ case 'text':
61
+ case 'expr':
62
+ case 'render':
63
+ case 'unconverted':
64
+ return;
65
+ }
66
+ }
@@ -0,0 +1,11 @@
1
+ import type { ModuleIR } from './model.js';
2
+ /**
3
+ * A forwardRef component that keeps the element in a ref of its own and hands it on in a callback ref:
4
+ *
5
+ * ref={(node) => { innerRef.current = node; if (typeof ref === 'function') ref(node); else if (ref) ref.current = node; }}
6
+ *
7
+ * The parent's ref and `innerRef` hold the same element. That is what `useImperativeHandle(ref, () => innerRef.current!)`
8
+ * says, which Vue and Svelte already print (an exposed `el`, a bindable `ref`): the callback becomes `ref={innerRef}` and
9
+ * the component gets that `forward` item. Anything else in the callback, or another use of `ref`, leaves it as written.
10
+ */
11
+ export declare function foldForwardingRefs(mod: ModuleIR): void;