@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,202 @@
1
+ import * as t from '@babel/types';
2
+ /**
3
+ * Framer Motion element props on Angular. The `[motion]` directive (motion-directive.ts) takes the props it can play,
4
+ * as written, in one object: the same set the Svelte target's motion action takes, plus `exit`, which Angular plays
5
+ * through `animate.leave`. The rest is reported by name.
6
+ */
7
+ /** Framer element props the directive handles. */
8
+ export const MOTION_PROPS = new Set(['initial', 'animate', 'exit', 'transition', 'variants', 'whileHover', 'whileTap', 'whileFocus', 'whileInView', 'viewport', 'onAnimationComplete', 'onHoverStart', 'onHoverEnd', 'onTap', 'onTapStart', 'onTapCancel']);
9
+ /** Props with no counterpart in the directive: what each one does, for the diagnostic. */
10
+ export const MOTION_UNCONVERTED = new Map([
11
+ ['layout', 'layout animations (layout)'],
12
+ ['layoutId', 'shared layout animations (layoutId)'],
13
+ ['drag', 'drag gestures (drag)'],
14
+ ['dragConstraints', 'drag gestures (dragConstraints)'],
15
+ ['dragElastic', 'drag gestures (dragElastic)'],
16
+ ['dragMomentum', 'drag gestures (dragMomentum)'],
17
+ ['dragSnapToOrigin', 'drag gestures (dragSnapToOrigin)'],
18
+ ['whileDrag', 'drag gestures (whileDrag)'],
19
+ ['onDragStart', 'drag gestures (onDragStart)'],
20
+ ['onDragEnd', 'drag gestures (onDragEnd)'],
21
+ ['onDrag', 'drag gestures (onDrag)'],
22
+ ['onUpdate', 'onUpdate'],
23
+ ['onAnimationStart', 'onAnimationStart'],
24
+ ['transformTemplate', 'transformTemplate'],
25
+ ['custom', 'dynamic variants (custom)'],
26
+ ['inherit', 'variant inheritance (inherit)'],
27
+ ['onViewportEnter', 'viewport callbacks (onViewportEnter)'],
28
+ ['onViewportLeave', 'viewport callbacks (onViewportLeave)'],
29
+ ]);
30
+ /**
31
+ * The object a motion element passes to `[motion]`: its Framer props the directive plays, as written, with the objects
32
+ * of Framer props spread on it (`{...motionProps}`, see motionSpreads) where the source spreads them.
33
+ */
34
+ export function motionParams(motion, styleValues, spreads = []) {
35
+ const props = [];
36
+ for (const [name, value] of Object.entries(motion))
37
+ if (MOTION_PROPS.has(name))
38
+ props.push(t.objectProperty(t.identifier(name), value));
39
+ // the spreads and the props in source order: a later one wins, as in React
40
+ const at = (x) => (t.isSpreadElement(x) ? x.argument : x.value).start ?? 0;
41
+ props.push(...spreads.map((s) => t.spreadElement(s)));
42
+ if (spreads.length)
43
+ props.sort((a, b) => at(a) - at(b));
44
+ if (styleValues.length)
45
+ props.push(t.objectProperty(t.identifier('values'), t.objectExpression(styleValues)));
46
+ // only a transition or variants, with nothing to play them (`layoutId` beside a transition): no directive
47
+ const plays = spreads.length > 0 || props.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key) && !['transition', 'variants', 'viewport'].includes(p.key.name)) || Object.keys(motion).includes('variants');
48
+ return plays ? t.objectExpression(props) : null;
49
+ }
50
+ /**
51
+ * The spreads on a motion element whose object is Framer's `MotionProps` by its declared type (`motionProps?:
52
+ * MotionProps`, `const enter: MotionProps = { … }`): `[motion]` takes them, where `[spreadProps]` would write each key
53
+ * as an attribute. `motionType(e)`: whether the expression is declared with that type. Null when one of them cannot be
54
+ * placed in source order among the element's own Framer props.
55
+ */
56
+ export function motionSpreads(n, motionType) {
57
+ const spreads = n.attrs.filter((a) => a.kind === 'spread' && motionType(a.expr));
58
+ const own = Object.entries(n.motion ?? {}).flatMap(([name, value]) => (MOTION_PROPS.has(name) ? [value] : []));
59
+ if (spreads.length && own.length && [...spreads.map((s) => s.expr), ...own].some((e) => e.start == null))
60
+ return null;
61
+ return spreads;
62
+ }
63
+ /** The directive's props a component takes as inputs where its props type inherits Framer's (its callbacks are not). */
64
+ const MOTION_INPUTS = ['initial', 'animate', 'exit', 'transition', 'variants', 'whileHover', 'whileTap', 'whileFocus', 'whileInView', 'viewport'];
65
+ /**
66
+ * The keys of the directive's props a props heritage type gives, when it is Framer's `MotionProps` (`names`: its local
67
+ * names) or `Omit<MotionProps, 'children' | …>`: those it does not leave out. Null for any other type.
68
+ */
69
+ export function motionHeritage(h, names) {
70
+ if (!t.isTSTypeReference(h) || !t.isIdentifier(h.typeName))
71
+ return null;
72
+ if (names.has(h.typeName.name) && !h.typeParameters)
73
+ return [...MOTION_INPUTS];
74
+ const [base, keys, more] = h.typeParameters?.params ?? [];
75
+ if (h.typeName.name !== 'Omit' || !base || !keys || more || !motionHeritage(base, names))
76
+ return null;
77
+ const left = t.isTSUnionType(keys) ? keys.types : [keys];
78
+ const omitted = left.flatMap((k) => (t.isTSLiteralType(k) && t.isStringLiteral(k.literal) ? [k.literal.value] : []));
79
+ return omitted.length === left.length ? MOTION_INPUTS.filter((k) => !omitted.includes(k)) : null;
80
+ }
81
+ /** Whether a component spreads its rest props once, on a motion element, and nowhere else in its markup. */
82
+ export function restOnMotion(comp) {
83
+ if (!comp.rest)
84
+ return false;
85
+ let onMotion = 0;
86
+ let elsewhere = 0;
87
+ const visit = (n) => {
88
+ if (n.type === 'element') {
89
+ for (const a of n.attrs) {
90
+ if (a.kind === 'spread' && t.isIdentifier(a.expr, { name: comp.rest ?? '' })) {
91
+ if (n.motion && !n.component)
92
+ onMotion++;
93
+ else
94
+ elsewhere++;
95
+ }
96
+ if (a.kind === 'slotProp')
97
+ a.children.forEach(visit);
98
+ }
99
+ }
100
+ const kids = n.type === 'if' ? n.branches.flatMap((b) => b.children) : n.type === 'slot' ? n.fallback : 'children' in n ? n.children : [];
101
+ kids.forEach(visit);
102
+ };
103
+ visit(comp.template);
104
+ return onMotion === 1 && elsewhere === 0;
105
+ }
106
+ /** `<AnimatePresence mode="wait">`: the mode, when it is written as a string. */
107
+ export function presenceMode(attrs) {
108
+ for (const a of attrs) {
109
+ if (a.kind === 'static' && a.name === 'mode')
110
+ return a.value;
111
+ if (a.kind === 'expr' && a.name === 'mode' && t.isStringLiteral(a.expr))
112
+ return a.expr.value;
113
+ }
114
+ return null;
115
+ }
116
+ /** A motion element with an initial animation of its own (`initial` that is not `false`). */
117
+ function animatesIn(n) {
118
+ return !!n.motion?.initial && !t.isBooleanLiteral(n.motion.initial, { value: false });
119
+ }
120
+ /**
121
+ * What the `[motionPresence]` directive cannot time for an AnimatePresence with `initial={false}` or `mode="wait"`: a
122
+ * motion element with an initial animation inside a condition, list or key of a child (or of a component of the file a
123
+ * child renders). React times it by the child it sits in, the directive by when the element itself is created. And with
124
+ * `mode="wait"`, a child that is not a motion element: only a motion element can wait. Each problem, said in words.
125
+ */
126
+ export function presenceGaps(presence, componentOf) {
127
+ const initialFalse = presence.attrs.some((a) => a.kind === 'expr' && a.name === 'initial' && t.isBooleanLiteral(a.expr, { value: false }));
128
+ const wait = presenceMode(presence.attrs) === 'wait';
129
+ if (!initialFalse && !wait)
130
+ return [];
131
+ const gaps = new Set();
132
+ const seen = new Set();
133
+ /** `inBlock`: a condition, list or key inside a child holds the node */
134
+ const visit = (nodes, top, inBlock) => {
135
+ for (const n of nodes) {
136
+ switch (n.type) {
137
+ case 'element': {
138
+ if (top && wait && (n.component || !n.motion))
139
+ gaps.add(`<${n.tag}> is not a motion element, so with mode="wait" it enters at once instead of after the exits`);
140
+ if (inBlock && animatesIn(n))
141
+ gaps.add(`the initial animation of <motion.${n.tag}> inside a condition, list or key of a child plays by when it appears, where React times it by its child`);
142
+ const comp = n.component && !seen.has(n.tag) ? componentOf(n.tag) : null;
143
+ if (comp) {
144
+ seen.add(n.tag);
145
+ visit([comp.template], false, inBlock);
146
+ }
147
+ visit(n.children, false, inBlock);
148
+ for (const a of n.attrs)
149
+ if (a.kind === 'slotProp')
150
+ visit(a.children, false, inBlock);
151
+ break;
152
+ }
153
+ case 'if':
154
+ for (const b of n.branches)
155
+ visit(b.children, top, !top || inBlock);
156
+ break;
157
+ case 'for':
158
+ case 'keyed':
159
+ visit(n.children, top, !top || inBlock);
160
+ break;
161
+ case 'fragment':
162
+ visit(n.children, top, inBlock);
163
+ break;
164
+ case 'presence':
165
+ // a nested AnimatePresence times its own children
166
+ break;
167
+ default:
168
+ if (top && wait && n.type !== 'text')
169
+ gaps.add('a child that is not an element enters at once instead of after the exits');
170
+ break;
171
+ }
172
+ }
173
+ };
174
+ visit(presence.children, true, false);
175
+ return [...gaps];
176
+ }
177
+ /** Framer Motion types with the same name and meaning in `motion` (the framework-free package). */
178
+ const MOTION_TYPES = new Set(['Variants', 'Variant', 'Transition', 'TargetAndTransition', 'Target', 'MotionValue', 'Easing', 'AnimationPlaybackControls', 'SpringOptions', 'ValueAnimationTransition']);
179
+ /** Framer Motion's value hooks as the `motion` functions an Angular class calls once (the Svelte target's mapping). */
180
+ export const MOTION_VALUE_HOOKS = { useMotionValue: 'motionValue', useSpring: 'springValue', useTransform: 'transformValue', useMotionTemplate: 'transformValue' };
181
+ /**
182
+ * A `framer-motion` / `motion/react` import in Angular output: types `motion` shares, and the functions it shares
183
+ * (`animate`, `stagger`, `spring`, `motionValue`), come from `motion`; the hooks are written as their functions where they
184
+ * are declared (see emit.ts); `motion` and `AnimatePresence` are templates' business. A type `motion` does not have is
185
+ * returned, to be reported.
186
+ */
187
+ export function motionImports(decl, named, type) {
188
+ const missing = [];
189
+ for (const s of decl.specifiers) {
190
+ if (!t.isImportSpecifier(s))
191
+ continue;
192
+ const imported = t.isIdentifier(s.imported) ? s.imported.name : s.imported.value;
193
+ const isType = decl.importKind === 'type' || s.importKind === 'type';
194
+ if (MOTION_TYPES.has(imported))
195
+ type('motion', imported, s.local.name);
196
+ else if (isType)
197
+ missing.push(imported);
198
+ else if (imported === 'animate' || imported === 'motionValue' || imported === 'stagger' || imported === 'spring')
199
+ named('motion', imported, s.local.name);
200
+ }
201
+ return missing;
202
+ }
@@ -0,0 +1,24 @@
1
+ import * as t from '@babel/types';
2
+ /**
3
+ * In a hook's code, a value read through a call (a signal, or a parameter passed live as a getter: `imageUrls()`) is
4
+ * read once per function into a local (`const imageUrlsValue = imageUrls();`) when the function reads it more than
5
+ * once: React read the value once, and TypeScript narrows a local but not a repeated call (`imageUrls() &&
6
+ * imageUrls().length`).
7
+ */
8
+ export declare function snapshotCalls(node: t.Node, callables: ReadonlySet<string>): void;
9
+ /**
10
+ * A `function` written inside class code (`function onKeyDown(event) { … this.shortcut() … }`) has its own `this`:
11
+ * once the component's bindings read through `this`, it becomes an arrow function, declared where the function was
12
+ * hoisted to (the top of its block), so every call still finds it.
13
+ */
14
+ export declare function arrowFunctionsReadingThis(node: t.Node): ThisConflict[];
15
+ /** An object-literal method whose `this` means both its own object (in the React source) and the component. */
16
+ export interface ThisConflict {
17
+ method: string;
18
+ line: number | null;
19
+ }
20
+ /**
21
+ * React's `DragEvent` has a `dataTransfer` (and `ClipboardEvent` a `clipboardData`) that is never null; the DOM types
22
+ * say it may be. A handler parameter of that event reads it as React's type promised (`event.dataTransfer!.files`).
23
+ */
24
+ export declare function promisedEventMembers(node: t.Node): void;
@@ -0,0 +1,205 @@
1
+ import { transform } from '../../ir/rewrite.js';
2
+ import * as t from '@babel/types';
3
+ import { childNodes, replaceChildren } from './walk.js';
4
+ /**
5
+ * In a hook's code, a value read through a call (a signal, or a parameter passed live as a getter: `imageUrls()`) is
6
+ * read once per function into a local (`const imageUrlsValue = imageUrls();`) when the function reads it more than
7
+ * once: React read the value once, and TypeScript narrows a local but not a repeated call (`imageUrls() &&
8
+ * imageUrls().length`).
9
+ */
10
+ export function snapshotCalls(node, callables) {
11
+ if (!callables.size)
12
+ return;
13
+ const visit = (n) => {
14
+ if (t.isFunction(n)) {
15
+ snapshotFunction(n, callables);
16
+ return;
17
+ }
18
+ for (const c of childNodes(n))
19
+ visit(c.node);
20
+ };
21
+ visit(node);
22
+ }
23
+ const callOf = (n, callables) => (t.isCallExpression(n) && !n.arguments.length && t.isIdentifier(n.callee) && callables.has(n.callee.name) ? n.callee.name : null);
24
+ function snapshotFunction(fn, callables) {
25
+ // only the function's own reads: a nested function reads at its own time
26
+ const counts = new Map();
27
+ const own = (n, f) => {
28
+ f(n);
29
+ for (const { node: c } of childNodes(n)) {
30
+ if (t.isFunction(c))
31
+ snapshotFunction(c, callables);
32
+ else
33
+ own(c, f);
34
+ }
35
+ };
36
+ own(fn.body, (n) => {
37
+ const name = callOf(n, callables);
38
+ if (name)
39
+ counts.set(name, (counts.get(name) ?? 0) + 1);
40
+ });
41
+ const taken = new Set();
42
+ t.traverseFast(fn, (n) => {
43
+ if (t.isIdentifier(n))
44
+ taken.add(n.name);
45
+ });
46
+ const locals = new Map();
47
+ for (const [name, count] of counts) {
48
+ if (count < 2)
49
+ continue;
50
+ let local = `${name}Value`;
51
+ for (let i = 2; taken.has(local); i++)
52
+ local = `${name}Value${i}`;
53
+ taken.add(local);
54
+ locals.set(name, local);
55
+ }
56
+ if (!locals.size)
57
+ return;
58
+ // nested functions keep their calls (they read at their own time)
59
+ const replace = (n) => {
60
+ const name = callOf(n, callables);
61
+ if (name && locals.has(name))
62
+ return t.identifier(locals.get(name));
63
+ if (t.isFunction(n))
64
+ return n;
65
+ replaceChildren(n, replace);
66
+ return n;
67
+ };
68
+ const reads = [...locals].map(([name, local]) => t.variableDeclaration('const', [t.variableDeclarator(t.identifier(local), t.callExpression(t.identifier(name), []))]));
69
+ if (t.isBlockStatement(fn.body)) {
70
+ fn.body.body = fn.body.body.map((s) => replace(s));
71
+ fn.body.body.unshift(...reads);
72
+ }
73
+ else
74
+ fn.body = t.blockStatement([...reads, t.returnStatement(replace(fn.body))]);
75
+ }
76
+ /**
77
+ * A `function` written inside class code (`function onKeyDown(event) { … this.shortcut() … }`) has its own `this`:
78
+ * once the component's bindings read through `this`, it becomes an arrow function, declared where the function was
79
+ * hoisted to (the top of its block), so every call still finds it.
80
+ */
81
+ export function arrowFunctionsReadingThis(node) {
82
+ const readsThis = (fn) => {
83
+ let found = false;
84
+ const visit = (n) => {
85
+ if (found)
86
+ return;
87
+ if (t.isThisExpression(n))
88
+ found = true;
89
+ // a nested function has its own `this` (an arrow does not)
90
+ if (t.isFunction(n) && !t.isArrowFunctionExpression(n))
91
+ return;
92
+ for (const c of childNodes(n))
93
+ visit(c.node);
94
+ };
95
+ visit(fn.body);
96
+ let usesArguments = false;
97
+ t.traverseFast(fn.body, (n) => {
98
+ if (t.isIdentifier(n, { name: 'arguments' }))
99
+ usesArguments = true;
100
+ });
101
+ return found && !usesArguments && !fn.generator;
102
+ };
103
+ t.traverseFast(node, (n) => {
104
+ if (!t.isBlockStatement(n))
105
+ return;
106
+ const hoisted = [];
107
+ n.body = n.body.filter((st) => {
108
+ if (!t.isFunctionDeclaration(st) || !st.id || !readsThis(st))
109
+ return true;
110
+ const arrow = t.arrowFunctionExpression(st.params, st.body, st.async);
111
+ arrow.returnType = st.returnType ?? null;
112
+ hoisted.push(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(st.id.name), arrow)]));
113
+ return false;
114
+ });
115
+ n.body.unshift(...hoisted);
116
+ });
117
+ // a method of an object literal (`animate(v, to, { onComplete() { … this.hasPlayed = true … } })`): its `this` is
118
+ // the object. A `this` the emitter wrote for a component member (built with no source location) means the component: when every `this` of the method is such a one, the method becomes an arrow property. A `this` that was
119
+ // in the React source means the object, and the method stays. One that has both cannot be written: it is reported.
120
+ const both = [];
121
+ transform(node, (n) => {
122
+ if (!t.isObjectExpression(n))
123
+ return null;
124
+ n.properties = n.properties.map((p) => {
125
+ if (t.isSpreadElement(p) || p.computed)
126
+ return p;
127
+ const fn = t.isObjectMethod(p) ? (p.kind === 'method' ? p : null) : t.isFunctionExpression(p.value) ? p.value : null;
128
+ if (!fn || !readsThis(fn))
129
+ return p;
130
+ let emitted = 0;
131
+ let source = 0;
132
+ const visit = (x) => {
133
+ if (t.isThisExpression(x)) {
134
+ // the emitter builds its `this` (`this.played`) with no location; one parsed from the source keeps its own
135
+ if (x.loc)
136
+ source++;
137
+ else
138
+ emitted++;
139
+ return;
140
+ }
141
+ // a nested function has its own `this` (an arrow does not)
142
+ if (t.isFunction(x) && !t.isArrowFunctionExpression(x))
143
+ return;
144
+ for (const c of childNodes(x))
145
+ visit(c.node);
146
+ };
147
+ visit(fn.body);
148
+ if (!emitted)
149
+ return p;
150
+ if (source) {
151
+ both.push({ method: t.isIdentifier(p.key) ? p.key.name : t.isStringLiteral(p.key) ? p.key.value : 'method', line: fn.loc?.start.line ?? null });
152
+ return p;
153
+ }
154
+ const arrow = t.arrowFunctionExpression(fn.params, fn.body, fn.async);
155
+ arrow.returnType = fn.returnType ?? null;
156
+ return t.objectProperty(p.key, arrow);
157
+ });
158
+ return null;
159
+ });
160
+ return both;
161
+ }
162
+ /** Event members React's types promise and the DOM's leave nullable: a browser always fills them for these events. */
163
+ const PROMISED = { DragEvent: 'dataTransfer', ClipboardEvent: 'clipboardData' };
164
+ /**
165
+ * React's `DragEvent` has a `dataTransfer` (and `ClipboardEvent` a `clipboardData`) that is never null; the DOM types
166
+ * say it may be. A handler parameter of that event reads it as React's type promised (`event.dataTransfer!.files`).
167
+ */
168
+ export function promisedEventMembers(node) {
169
+ t.traverseFast(node, (fn) => {
170
+ if (!t.isFunction(fn))
171
+ return;
172
+ for (const p of fn.params) {
173
+ const type = t.isIdentifier(p) && p.typeAnnotation && t.isTSTypeAnnotation(p.typeAnnotation) ? p.typeAnnotation.typeAnnotation : null;
174
+ const eventName = type && t.isTSTypeReference(type) && t.isIdentifier(type.typeName) && /Event$/.test(type.typeName.name) ? type.typeName.name : null;
175
+ if (!eventName || !t.isIdentifier(p))
176
+ continue;
177
+ // React's event has a target and a current target, an element: the DOM's may say null. Read through, or passed
178
+ // on, they are what React's type promised (code that compiled against React's types read them so)
179
+ const param = p.name;
180
+ const targetOf = (n, name) => t.isMemberExpression(n) && !n.computed && t.isIdentifier(n.object, { name: param }) && t.isIdentifier(n.property, { name });
181
+ transform(fn.body, (n, parent) => {
182
+ if (!targetOf(n, 'currentTarget') && !targetOf(n, 'target'))
183
+ return null;
184
+ if (parent && t.isTSAsExpression(parent))
185
+ return null;
186
+ const passed = !!parent && (t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.arguments.includes(n);
187
+ const through = !!parent && t.isMemberExpression(parent) && parent.object === n;
188
+ if (!passed && !through)
189
+ return null;
190
+ const current = targetOf(n, 'currentTarget');
191
+ return current ? t.tsAsExpression(n, t.tsTypeReference(t.identifier('Element'))) : t.tsNonNullExpression(n);
192
+ });
193
+ const named = PROMISED[eventName];
194
+ if (!named)
195
+ continue;
196
+ t.traverseFast(fn.body, (n) => {
197
+ if (!t.isMemberExpression(n) || n.computed)
198
+ return;
199
+ const obj = n.object;
200
+ if (t.isMemberExpression(obj) && !obj.computed && t.isIdentifier(obj.object, { name: param }) && t.isIdentifier(obj.property, { name: named }))
201
+ n.object = t.tsNonNullExpression(obj);
202
+ });
203
+ }
204
+ });
205
+ }
@@ -0,0 +1,23 @@
1
+ import type { EmittedFile } from '../../types.js';
2
+ export interface AngularCompileResult {
3
+ /** one message per problem, `path: message`, paths relative to the emitted files */
4
+ problems: {
5
+ path: string;
6
+ message: string;
7
+ }[];
8
+ /** emitted JavaScript by output path (`foo.ts` → `foo.js`), when asked to emit */
9
+ outputs: Map<string, string>;
10
+ }
11
+ /**
12
+ * Compiles emitted Angular files with the real Angular compiler (ngtsc), in memory: strict TypeScript and strict
13
+ * template type-checking, and (with `emit`) full ahead-of-time output a bundler can load without the JIT compiler.
14
+ * The files sit in a virtual folder inside the package, so `@angular/*` resolves from its own node_modules. With
15
+ * `projectRoot` (the folder of the React project the output came from), the output's other package imports resolve
16
+ * from that project first (its node_modules, its tsconfig `paths`), as they will once the files are copied into it.
17
+ */
18
+ export declare function compileAngular(files: EmittedFile[], emit?: boolean, projectRoot?: string): Promise<AngularCompileResult>;
19
+ /** The newest ES library edition emitted code calls (`ES2023` for `findLastIndex`), with the calls; null within ES2022. */
20
+ export declare function libraryNeeds(code: string): {
21
+ edition: string;
22
+ calls: string[];
23
+ } | null;
@@ -0,0 +1,134 @@
1
+ import { dirname, join, resolve } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import ts from 'typescript';
4
+ import { projectModuleResolver } from '../../typecheck/host.js';
5
+ /** The package's own folder: Angular and TypeScript types resolve from its node_modules, offline. */
6
+ const MORPH_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
7
+ let ngc = null;
8
+ /** Declaration files every compile reads, parsed once (by path and language version). */
9
+ const declarations = new Map();
10
+ /**
11
+ * Compiles emitted Angular files with the real Angular compiler (ngtsc), in memory: strict TypeScript and strict
12
+ * template type-checking, and (with `emit`) full ahead-of-time output a bundler can load without the JIT compiler.
13
+ * The files sit in a virtual folder inside the package, so `@angular/*` resolves from its own node_modules. With
14
+ * `projectRoot` (the folder of the React project the output came from), the output's other package imports resolve
15
+ * from that project first (its node_modules, its tsconfig `paths`), as they will once the files are copied into it.
16
+ */
17
+ export async function compileAngular(files, emit = false, projectRoot) {
18
+ // Angular is an experimental target and an optional dependency: a missing install says what to add
19
+ ngc ??= import('@angular/compiler-cli').catch(() => {
20
+ ngc = null;
21
+ throw new Error('Angular output needs the optional dependencies @angular/compiler-cli, @angular/core, @angular/common and @angular/compiler (npm install them).');
22
+ });
23
+ const { NgtscProgram } = await ngc;
24
+ // a turn of the event loop first: a compile holds the thread for seconds, and compiles queued back to back (verify
25
+ // runs sharing a process) would otherwise chain into one long stall in which no I/O, page or timer of theirs runs
26
+ await new Promise((resolve) => setImmediate(resolve));
27
+ const root = join(MORPH_ROOT, '.ng-virtual', Math.random().toString(36).slice(2));
28
+ const virtual = new Map();
29
+ for (const f of files)
30
+ virtual.set(resolve(root, f.path).replace(/\\/g, '/'), f.contents);
31
+ const key = (p) => resolve(p).replace(/\\/g, '/');
32
+ const outDir = join(root, '.out');
33
+ const options = {
34
+ target: ts.ScriptTarget.ES2022,
35
+ module: ts.ModuleKind.ES2022,
36
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
37
+ // the library the React code was written against (ES2024: findLast, toSorted, Object.groupBy); an Angular project
38
+ // with the default ES2022 library is told what it needs where the output uses more (see libraryNeeds)
39
+ lib: ['lib.es2024.d.ts', 'lib.dom.d.ts', 'lib.dom.iterable.d.ts'],
40
+ types: [],
41
+ strict: true,
42
+ skipLibCheck: true,
43
+ // data the React code imports (`import data from './path.json'`), as an Angular CLI project reads it
44
+ resolveJsonModule: true,
45
+ allowSyntheticDefaultImports: true,
46
+ experimentalDecorators: true,
47
+ useDefineForClassFields: false,
48
+ noEmitOnError: false,
49
+ sourceMap: false,
50
+ declaration: false,
51
+ outDir,
52
+ rootDir: root,
53
+ strictTemplates: true,
54
+ strictInjectionParameters: true,
55
+ strictInputAccessModifiers: true,
56
+ compilationMode: 'full',
57
+ };
58
+ const host = ts.createCompilerHost(options, true);
59
+ const readFile = host.readFile.bind(host);
60
+ const fileExists = host.fileExists.bind(host);
61
+ const getSourceFile = host.getSourceFile.bind(host);
62
+ const directoryExists = host.directoryExists?.bind(host);
63
+ host.readFile = (f) => virtual.get(key(f)) ?? readFile(f);
64
+ host.fileExists = (f) => virtual.has(key(f)) || fileExists(f);
65
+ host.directoryExists = (d) => [...virtual.keys()].some((k) => k.startsWith(key(d) + '/')) || (directoryExists ? directoryExists(d) : true);
66
+ host.getSourceFile = (f, language, onError, create) => {
67
+ const k = key(f);
68
+ const text = virtual.get(k);
69
+ if (text !== undefined)
70
+ return ts.createSourceFile(f, text, language, true);
71
+ if (!k.endsWith('.d.ts') || !k.includes('/node_modules/'))
72
+ return getSourceFile(f, language, onError, create);
73
+ // installed declaration files (TypeScript's lib, @angular/*, the project's packages) are parsed once per process: re-parsing
74
+ // them was most of every compile (2.5-3.5 s → 0.8-1.1 s per compile measured), time in which this thread runs nothing
75
+ const version = typeof language === 'object' ? `${language.languageVersion}|${language.impliedNodeFormat ?? ''}` : String(language);
76
+ let sf = declarations.get(`${k}|${version}`);
77
+ if (!sf) {
78
+ sf = getSourceFile(f, language, onError, create);
79
+ if (sf)
80
+ declarations.set(`${k}|${version}`, sf);
81
+ }
82
+ return sf;
83
+ };
84
+ if (projectRoot !== undefined) {
85
+ // (resolveModuleNames, not the literal form: Angular's own resolver of decorator imports asks the host by that name)
86
+ const fromProject = projectModuleResolver(projectRoot, root);
87
+ const cache = ts.createModuleResolutionCache(root, (f) => f, options);
88
+ host.resolveModuleNames = (names, containingFile) => names.map((name) => fromProject(name, containingFile) ?? ts.resolveModuleName(name, containingFile, options, host, cache).resolvedModule);
89
+ }
90
+ const outputs = new Map();
91
+ host.writeFile = (f, text) => {
92
+ const rel = key(f).slice(key(outDir).length + 1);
93
+ if (rel.endsWith('.js'))
94
+ outputs.set(rel, text);
95
+ };
96
+ const rootNames = files.filter((f) => f.path.endsWith('.ts')).map((f) => resolve(root, f.path));
97
+ const program = new NgtscProgram(rootNames, options, host);
98
+ await program.loadNgStructureAsync();
99
+ const diagnostics = [
100
+ ...program.getTsOptionDiagnostics(),
101
+ ...program.getNgOptionDiagnostics(),
102
+ ...program.getTsSyntacticDiagnostics(),
103
+ ...program.getTsSemanticDiagnostics(),
104
+ ...program.getNgStructuralDiagnostics(),
105
+ ...program.getNgSemanticDiagnostics(),
106
+ ].filter((d) => d.category === ts.DiagnosticCategory.Error);
107
+ if (emit)
108
+ program.emit();
109
+ const problems = diagnostics.map((d) => {
110
+ const file = 'file' in d && d.file ? d.file.fileName : '';
111
+ const path = file ? key(file).slice(key(root).length + 1) : '';
112
+ const line = 'file' in d && d.file && d.start !== undefined ? d.file.getLineAndCharacterOfPosition(d.start).line + 1 : null;
113
+ return { path: path || '(project)', message: `${line ? `line ${line}: ` : ''}${ts.flattenDiagnosticMessageText(d.messageText, '\n').split('\n')[0] ?? ''}` };
114
+ });
115
+ return { problems, outputs };
116
+ }
117
+ /** JavaScript library calls newer than ES2022, Angular's default `lib`, by the edition that brings them. */
118
+ const NEWER_LIBRARY = [
119
+ [/\.(findLast|findLastIndex|toSorted|toReversed|toSpliced)\(/, 'ES2023'],
120
+ [/\b(?:Object|Map)\.groupBy\(|\bPromise\.withResolvers\(|\.(?:isWellFormed|toWellFormed)\(/, 'ES2024'],
121
+ ];
122
+ /** The newest ES library edition emitted code calls (`ES2023` for `findLastIndex`), with the calls; null within ES2022. */
123
+ export function libraryNeeds(code) {
124
+ let edition = null;
125
+ const calls = new Set();
126
+ for (const [re, ed] of NEWER_LIBRARY) {
127
+ const all = new RegExp(re.source, 'g');
128
+ for (const m of code.matchAll(all)) {
129
+ calls.add(m[0].replace(/^\./, '').replace(/\($/, ''));
130
+ edition = ed;
131
+ }
132
+ }
133
+ return edition ? { edition, calls: [...calls].sort() } : null;
134
+ }
@@ -0,0 +1,39 @@
1
+ import type { ComponentIR, ElementNode, ModuleIR } from '../../ir/model.js';
2
+ import type { WebContext } from '../shared/module.js';
3
+ /**
4
+ * A forwarded ref put on child components (`<TurnStage ref={ref} />`, or one of several by condition:
5
+ * `if (!layers) return <Single ref={ref} />; return <Stack ref={ref} />`). React's ref then holds the handle of the one
6
+ * child rendered now. An Angular parent's query reaches this component's instance, so the instance passes the
7
+ * handle on: one query per child the ref is put on, and one public getter per member the children's handles have,
8
+ * reading it from the child rendered now (undefined where that child's handle lacks it, as React's would).
9
+ *
10
+ * Exact only when exactly one of those children is rendered whenever this component is (each sits under conditions
11
+ * whose every branch, an else included, renders one; none in a loop, a slot, a presence or another component's
12
+ * markup), the ref is used nowhere else, and each child's handle members are known by name: an object literal's,
13
+ * a typed handle's, or another such pass.
14
+ */
15
+ export interface PassedHandle {
16
+ /** the elements the ref is put on */
17
+ readonly targets: ElementNode[];
18
+ /** each target's handle members, by element */
19
+ readonly members: Map<ElementNode, ReadonlySet<string>>;
20
+ /** every member a parent can read, in the order first met */
21
+ readonly names: string[];
22
+ }
23
+ /** A component the given component renders, found from that component's own module. */
24
+ export type ChildOfAny = (parent: ComponentIR, tag: string) => ComponentIR | null;
25
+ /** childOfAny over the compiled files: the module the parent component sits in, then its tag there. */
26
+ export declare function childOfAnyIn(mod: ModuleIR, ctx: WebContext): ChildOfAny;
27
+ /**
28
+ * The elements the forwarded ref is put on when exactly one of them is rendered whenever the component renders, all
29
+ * of them components; null otherwise.
30
+ */
31
+ export declare function exclusiveTargets(comp: ComponentIR): ElementNode[] | null;
32
+ /**
33
+ * The names a parent's ref reads on a component: its handle's members (an object literal's, or a typed handle's), or
34
+ * those of the handles it passes on (see passedHandle). Null when they are not known by name, or when one of them
35
+ * shares its name with a prop or value of the component (its Angular member then has another name).
36
+ */
37
+ export declare function reachedMembers(comp: ComponentIR, childOf: ChildOfAny, ctx: WebContext, depth?: number): ReadonlySet<string> | null;
38
+ /** How a component passes a parent's ref on to the handles of the children it puts the ref on, or null. */
39
+ export declare function passedHandle(comp: ComponentIR, childOf: ChildOfAny, ctx: WebContext, depth?: number): PassedHandle | null;