@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,405 @@
1
+ import { parseExpression } from '@babel/parser';
2
+ import * as t from '@babel/types';
3
+ import { traverse } from '../../analyzer/parse.js';
4
+ const PURE_NEW = new Set(['Set', 'Map', 'WeakMap', 'WeakSet', 'Date', 'RegExp', 'Array', 'Object', 'Float32Array', 'Float64Array', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'Int8Array', 'Int16Array', 'Int32Array']);
5
+ /** Methods of a string or array literal that only build a new value. */
6
+ const PURE_METHODS = new Set(['split', 'join', 'slice', 'concat', 'trim', 'toLowerCase', 'toUpperCase', 'padStart', 'padEnd', 'repeat']);
7
+ /** Namespaces whose functions only compute a value (`Math.max`, `JSON.stringify`, `Array.from`), and the `Object` ones that do. */
8
+ const PURE_STATIC = new Set(['Math', 'JSON', 'Number', 'String', 'Array', 'Boolean']);
9
+ const PURE_OBJECT = new Set(['Object.keys', 'Object.values', 'Object.entries', 'Object.fromEntries', 'Object.freeze']);
10
+ function calleeName(callee) {
11
+ if (t.isIdentifier(callee))
12
+ return callee.name;
13
+ if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.object) && t.isIdentifier(callee.property))
14
+ return `${callee.object.name}.${callee.property.name}`;
15
+ return null;
16
+ }
17
+ /** Whether evaluating the expression only builds a value (so a binding nobody reads may go). */
18
+ export function isPure(e, rules) {
19
+ if (!e)
20
+ return true;
21
+ if (rules.also?.(e))
22
+ return true;
23
+ if (t.isStringLiteral(e) || t.isNumericLiteral(e) || t.isBooleanLiteral(e) || t.isNullLiteral(e) || t.isBigIntLiteral(e) || t.isRegExpLiteral(e))
24
+ return true;
25
+ if (t.isIdentifier(e) || t.isArrowFunctionExpression(e) || t.isFunctionExpression(e) || t.isThisExpression(e))
26
+ return true;
27
+ if (t.isTemplateLiteral(e))
28
+ return e.expressions.every((x) => isPure(x, rules));
29
+ if (t.isTSAsExpression(e) || t.isTSSatisfiesExpression(e) || t.isTSNonNullExpression(e) || t.isParenthesizedExpression(e) || t.isTSTypeAssertion(e))
30
+ return isPure(e.expression, rules);
31
+ if (t.isArrayExpression(e))
32
+ return e.elements.every((x) => x === null || (t.isSpreadElement(x) ? isPure(x.argument, rules) : isPure(x, rules)));
33
+ if (t.isObjectExpression(e)) {
34
+ return e.properties.every((p) => {
35
+ if (t.isSpreadElement(p))
36
+ return isPure(p.argument, rules);
37
+ if (t.isObjectMethod(p))
38
+ return !p.computed || isPure(p.key, rules);
39
+ return (!p.computed || isPure(p.key, rules)) && isPure(p.value, rules);
40
+ });
41
+ }
42
+ if (t.isUnaryExpression(e))
43
+ return e.operator !== 'delete' && isPure(e.argument, rules);
44
+ if (t.isBinaryExpression(e) || t.isLogicalExpression(e))
45
+ return isPure(e.left, rules) && isPure(e.right, rules);
46
+ if (t.isConditionalExpression(e))
47
+ return isPure(e.test, rules) && isPure(e.consequent, rules) && isPure(e.alternate, rules);
48
+ if (t.isMemberExpression(e) || t.isOptionalMemberExpression(e))
49
+ return isPure(e.object, rules) && (!e.computed || isPure(e.property, rules));
50
+ if (t.isNewExpression(e)) {
51
+ const name = t.isIdentifier(e.callee) ? e.callee.name : t.isMemberExpression(e.callee) && t.isIdentifier(e.callee.object, { name: 'Intl' }) ? 'Intl' : '';
52
+ return PURE_NEW.has(name) || name === 'Intl' ? e.arguments.every((x) => isPure(x, rules)) : false;
53
+ }
54
+ if (t.isCallExpression(e)) {
55
+ const callee = e.callee;
56
+ if (t.isMemberExpression(callee) && !callee.computed && t.isIdentifier(callee.property) && PURE_METHODS.has(callee.property.name) && (t.isStringLiteral(callee.object) || t.isArrayExpression(callee.object))) {
57
+ return isPure(callee.object, rules) && e.arguments.every((x) => isPure(x, rules));
58
+ }
59
+ const name = calleeName(e.callee);
60
+ if (!name)
61
+ return false;
62
+ const root = name.split('.')[0] ?? '';
63
+ const ok = rules.calls.has(name) || PURE_OBJECT.has(name) || (name.includes('.') && PURE_STATIC.has(root));
64
+ return ok && e.arguments.every((x) => isPure(x, rules));
65
+ }
66
+ return false;
67
+ }
68
+ /** Every identifier-like word in a piece of text. */
69
+ export function wordsIn(code, into = new Set()) {
70
+ for (const m of code.matchAll(/[A-Za-z_$][\w$]*/g)) {
71
+ into.add(m[0]);
72
+ // `$store` reads `store`
73
+ if (m[0].startsWith('$') && m[0].length > 1)
74
+ into.add(m[0].slice(1));
75
+ }
76
+ return into;
77
+ }
78
+ /** The code with the text of its string literals taken out (words inside a `${}` of a template stay). */
79
+ function withoutStrings(code) {
80
+ let out = '';
81
+ let i = 0;
82
+ while (i < code.length) {
83
+ const c = code[i] ?? '';
84
+ if (c === "'" || c === '"') {
85
+ i++;
86
+ while (i < code.length && code[i] !== c)
87
+ i += code[i] === '\\' ? 2 : 1;
88
+ i++;
89
+ out += ' ';
90
+ }
91
+ else if (c === '`') {
92
+ i++;
93
+ while (i < code.length && code[i] !== '`') {
94
+ if (code[i] === '\\')
95
+ i += 2;
96
+ else if (code[i] === '$' && code[i + 1] === '{') {
97
+ let depth = 1;
98
+ i += 2;
99
+ const start = i;
100
+ while (i < code.length && depth > 0) {
101
+ if (code[i] === '{')
102
+ depth++;
103
+ else if (code[i] === '}')
104
+ depth--;
105
+ i++;
106
+ }
107
+ out += ` ${withoutStrings(code.slice(start, i - 1))} `;
108
+ }
109
+ else
110
+ i++;
111
+ }
112
+ i++;
113
+ }
114
+ else {
115
+ out += c;
116
+ i++;
117
+ }
118
+ }
119
+ return out;
120
+ }
121
+ /** The names an expression read in a template reads: parsed when it is an expression, else its words outside strings. */
122
+ function codeNames(code, into) {
123
+ try {
124
+ const expr = parseExpression(code, { plugins: ['typescript'] });
125
+ const file = t.file(t.program([t.expressionStatement(expr)]));
126
+ for (const n of readNames(file.program.body))
127
+ into.add(n);
128
+ }
129
+ catch {
130
+ wordsIn(withoutStrings(code), into);
131
+ }
132
+ }
133
+ /** The text between the braces of every `{ ... }` in a Svelte template, nested braces included. */
134
+ function braceContents(markup) {
135
+ const out = [];
136
+ let depth = 0;
137
+ let start = 0;
138
+ for (let i = 0; i < markup.length; i++) {
139
+ const c = markup[i];
140
+ if (c === '{') {
141
+ if (depth === 0)
142
+ start = i + 1;
143
+ depth++;
144
+ }
145
+ else if (c === '}' && depth > 0) {
146
+ depth--;
147
+ if (depth === 0)
148
+ out.push(markup.slice(start, i));
149
+ }
150
+ }
151
+ return out;
152
+ }
153
+ const unescape = (s) => s.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
154
+ /**
155
+ * The names a template reads: the code inside its expressions, its component tags, and the actions, transitions and
156
+ * refs it names. Class names, text, static attributes and the inside of string literals read nothing.
157
+ */
158
+ export function markupNames(markup, target) {
159
+ const out = new Set();
160
+ // a component tag: `<Bin`, `<motion.div`
161
+ for (const m of markup.matchAll(/<([A-Z][\w$]*)/g))
162
+ out.add(m[1] ?? '');
163
+ for (const m of markup.matchAll(/<([a-z][\w$]*)\./g))
164
+ out.add(m[1] ?? '');
165
+ if (target === 'vue') {
166
+ for (const m of markup.matchAll(/\{\{([\s\S]*?)\}\}/g))
167
+ codeNames(m[1] ?? '', out);
168
+ // bound attributes and directives (`v-for="row in rows"` too); a static `ref="x"` names a variable
169
+ for (const m of markup.matchAll(/\s(?::[^\s=]+|@[^\s=]+|#[^\s=]+|v-[^\s=]+|ref)="([^"]*)"/g))
170
+ codeNames(unescape(m[1] ?? ''), out);
171
+ // a custom directive `v-focus` reads `vFocus`
172
+ for (const m of markup.matchAll(/\sv-([a-z][\w-]*)/g))
173
+ out.add(`v${(m[1] ?? '').replace(/(^|-)(\w)/g, (_x, _y, c) => c.toUpperCase())}`);
174
+ }
175
+ else {
176
+ for (const inner of braceContents(markup))
177
+ codeNames(inner, out);
178
+ for (const m of markup.matchAll(/\s(?:use|transition|in|out|animate|class|style|bind):([\w$]+)/g))
179
+ out.add(m[1] ?? '');
180
+ }
181
+ return out;
182
+ }
183
+ /** Type-position identifiers that name something rather than read it (Babel's isReferenced does not know TypeScript's). */
184
+ function declaresInType(parent, key) {
185
+ if (!parent.type.startsWith('TS'))
186
+ return false;
187
+ if (key === 'id' || key === 'parameters' || key === 'params' || key === 'parameterName' || key === 'label')
188
+ return true;
189
+ if (key === 'key' && (parent.type === 'TSPropertySignature' || parent.type === 'TSMethodSignature'))
190
+ return !('computed' in parent && parent.computed);
191
+ if (key === 'right' && parent.type === 'TSQualifiedName')
192
+ return true;
193
+ return false;
194
+ }
195
+ /** Names a block reads or writes: values (a local that shadows a top-level name is not one of them) and types. */
196
+ export function readNames(statements, into = new Set()) {
197
+ const file = t.file(t.program(statements.map((s) => t.cloneNode(s, true)), [], 'module'));
198
+ traverse(file, {
199
+ Identifier(path) {
200
+ const { node, parent, parentPath } = path;
201
+ if (declaresInType(parent, path.key))
202
+ return;
203
+ if (!t.isReferenced(node, parent, parentPath?.parent))
204
+ return;
205
+ const binding = path.scope.getBinding(node.name);
206
+ if (binding && !binding.scope.path.isProgram())
207
+ return;
208
+ into.add(node.name);
209
+ },
210
+ // a name that is only assigned still has its writes, which stay: they count as uses
211
+ AssignmentExpression(path) {
212
+ for (const name of Object.keys(t.getBindingIdentifiers(path.node.left))) {
213
+ const binding = path.scope.getBinding(name);
214
+ if (!binding || binding.scope.path.isProgram())
215
+ into.add(name);
216
+ }
217
+ },
218
+ JSXIdentifier(path) {
219
+ into.add(path.node.name);
220
+ },
221
+ });
222
+ return into;
223
+ }
224
+ function typeOrFunctionName(s) {
225
+ if (t.isFunctionDeclaration(s) && s.id)
226
+ return s.id.name;
227
+ if (t.isTSInterfaceDeclaration(s) || t.isTSTypeAliasDeclaration(s))
228
+ return s.id.name;
229
+ return null;
230
+ }
231
+ /**
232
+ * Removes the top-level declarations of the given script blocks that nothing reads, repeating until nothing more goes.
233
+ * Exports are read by definition; so is whatever `fromMarkup` names. A variable goes only when its initializer merely
234
+ * builds a value (`isPure`); a function or a type goes whenever unread.
235
+ */
236
+ export function pruneUnused(blocks, fromMarkup, rules) {
237
+ const out = blocks.map((b) => [...b]);
238
+ for (;;) {
239
+ const reads = new Set(fromMarkup);
240
+ for (const block of out)
241
+ readNames(block, reads);
242
+ let removed = false;
243
+ for (const block of out) {
244
+ for (let i = block.length - 1; i >= 0; i--) {
245
+ const s = block[i];
246
+ if (!s)
247
+ continue;
248
+ const fn = typeOrFunctionName(s);
249
+ if (fn !== null) {
250
+ if (!reads.has(fn)) {
251
+ block.splice(i, 1);
252
+ removed = true;
253
+ }
254
+ continue;
255
+ }
256
+ if (t.isVariableDeclaration(s)) {
257
+ if (rules.props && trimProps(s, reads, rules.props, block, i)) {
258
+ removed = true;
259
+ continue;
260
+ }
261
+ const keep = s.declarations.filter((d) => !(t.isIdentifier(d.id) && !reads.has(d.id.name) && isPure(d.init, rules)));
262
+ if (keep.length === s.declarations.length)
263
+ continue;
264
+ removed = true;
265
+ if (keep.length)
266
+ s.declarations = keep;
267
+ else
268
+ block.splice(i, 1);
269
+ }
270
+ }
271
+ }
272
+ if (!removed)
273
+ return out;
274
+ }
275
+ }
276
+ /** The text of an Angular template with the comments out. */
277
+ const withoutComments = (markup) => markup.replace(/<!--[\s\S]*?-->/g, '');
278
+ /** The source between the parentheses (or up to the `;`, for `@let`) after the control-flow keyword at `from`. */
279
+ function controlFlowHeader(text, from) {
280
+ const open = text.indexOf('(', from);
281
+ if (open < 0)
282
+ return '';
283
+ let depth = 0;
284
+ for (let i = open; i < text.length; i++) {
285
+ if (text[i] === '(')
286
+ depth++;
287
+ else if (text[i] === ')' && --depth === 0)
288
+ return text.slice(open + 1, i);
289
+ }
290
+ return '';
291
+ }
292
+ /**
293
+ * The names an Angular template reads from its class: the code in its bindings, interpolations and control flow. The
294
+ * markup around them, class names, comments and string literals read nothing.
295
+ */
296
+ export function angularNames(markup) {
297
+ const text = withoutComments(markup);
298
+ const out = new Set();
299
+ for (const m of text.matchAll(/\{\{([\s\S]*?)\}\}/g))
300
+ codeNames(m[1] ?? '', out);
301
+ for (const m of text.matchAll(/\s(?:\[[^\]\s=]+\]|\([^)\s=]+\)|\[\([^)\s=]+\)\])="([^"]*)"/g))
302
+ codeNames(unescape(m[1] ?? ''), out);
303
+ for (const m of text.matchAll(/@(?:if|else if|for|switch|case|defer)\b/g))
304
+ codeNames(controlFlowHeader(text, m.index + m[0].length), out);
305
+ for (const m of text.matchAll(/@let\s+[\w$]+\s*=([^;]*);/g))
306
+ codeNames(m[1] ?? '', out);
307
+ return out;
308
+ }
309
+ /** Whether the member is class-private (`private`, `protected`, `#x`) and so read only by the class and its template. */
310
+ function privateName(m) {
311
+ if (t.isClassPrivateProperty(m) || t.isClassPrivateMethod(m))
312
+ return null;
313
+ if (!(t.isClassProperty(m) || t.isClassMethod(m)) || m.static || m.computed || !t.isIdentifier(m.key))
314
+ return null;
315
+ if (m.accessibility !== 'private' && m.accessibility !== 'protected')
316
+ return null;
317
+ if (Array.isArray(m.decorators) && m.decorators.length)
318
+ return null;
319
+ if (t.isClassMethod(m) && m.kind !== 'method')
320
+ return null;
321
+ if (/^ng[A-Z]/.test(m.key.name))
322
+ return null;
323
+ return m.key.name;
324
+ }
325
+ /**
326
+ * Removes the private and protected members of a component class that neither its own code (`this.x`) nor its template
327
+ * reads, repeating until nothing more goes. A property goes only when its initializer merely builds a value.
328
+ */
329
+ export function pruneMembers(members, fromTemplate, rules) {
330
+ for (;;) {
331
+ const reads = new Set(fromTemplate);
332
+ for (const m of members) {
333
+ t.traverseFast(m, (n) => {
334
+ if ((t.isMemberExpression(n) || t.isOptionalMemberExpression(n)) && !n.computed && t.isIdentifier(n.property))
335
+ reads.add(n.property.name);
336
+ });
337
+ }
338
+ let removed = false;
339
+ for (let i = members.length - 1; i >= 0; i--) {
340
+ const m = members[i];
341
+ const name = m ? privateName(m) : null;
342
+ if (!m || name === null || reads.has(name))
343
+ continue;
344
+ if (t.isClassProperty(m) && !isPure(m.value, rules))
345
+ continue;
346
+ members.splice(i, 1);
347
+ removed = true;
348
+ }
349
+ if (!removed)
350
+ return;
351
+ }
352
+ }
353
+ /** The props call a declaration initializes from (`defineProps<P>()`, `withDefaults(defineProps<P>(), {})`, `$props()`), if it is one. */
354
+ function propsCall(init, calls) {
355
+ if (!init || !t.isCallExpression(init) || !t.isIdentifier(init.callee))
356
+ return null;
357
+ if (calls.has(init.callee.name) && init.callee.name !== 'withDefaults')
358
+ return init;
359
+ const first = init.arguments[0];
360
+ return init.callee.name === 'withDefaults' && first && t.isExpression(first) ? propsCall(first, calls) : null;
361
+ }
362
+ /** Takes the props nothing reads out of a props declaration; returns whether anything changed. */
363
+ function trimProps(decl, reads, props, block, index) {
364
+ const d = decl.declarations.length === 1 ? decl.declarations[0] : undefined;
365
+ const call = d && propsCall(d.init, props.calls);
366
+ if (!d || !call)
367
+ return false;
368
+ const bare = () => {
369
+ if (props.whenUnread === 'call' && d.init) {
370
+ block.splice(index, 1, t.expressionStatement(d.init));
371
+ return;
372
+ }
373
+ const empty = t.objectPattern([]);
374
+ const typed = t.isIdentifier(d.id) || t.isObjectPattern(d.id) ? d.id.typeAnnotation : null;
375
+ if (typed)
376
+ empty.typeAnnotation = typed;
377
+ d.id = empty;
378
+ };
379
+ if (t.isIdentifier(d.id)) {
380
+ if (reads.has(d.id.name))
381
+ return false;
382
+ bare();
383
+ return true;
384
+ }
385
+ if (!t.isObjectPattern(d.id) || d.id.properties.some((p) => t.isRestElement(p)))
386
+ return false;
387
+ const named = (p) => {
388
+ if (!t.isObjectProperty(p))
389
+ return null;
390
+ const v = t.isAssignmentPattern(p.value) ? p.value.left : p.value;
391
+ return t.isIdentifier(v) ? v.name : null;
392
+ };
393
+ const declaring = (p) => t.isObjectProperty(p) && t.isAssignmentPattern(p.value) && t.isCallExpression(p.value.right) && t.isIdentifier(p.value.right.callee) && !!props.declares?.has(p.value.right.callee.name);
394
+ const kept = d.id.properties.filter((p) => {
395
+ const name = named(p);
396
+ return name === null || reads.has(name) || declaring(p);
397
+ });
398
+ if (kept.length === d.id.properties.length)
399
+ return false;
400
+ if (kept.length)
401
+ d.id.properties = kept;
402
+ else
403
+ bare();
404
+ return true;
405
+ }
@@ -0,0 +1,25 @@
1
+ import * as t from '@babel/types';
2
+ import type { Diagnostic, WebTarget } from '../../types.js';
3
+ import type { ModuleIR } from '../../ir/model.js';
4
+ import { type Project } from '../../analyzer/deps.js';
5
+ /** One file of the conversion: its absolute path and source (stylesheets and JSON data have no code to read). */
6
+ export interface SourceFile {
7
+ file: string;
8
+ code: string;
9
+ isCode: boolean;
10
+ }
11
+ /** The names each top-level statement of a program declares, and the names it reads (values, not types). */
12
+ export declare function topLevel(program: t.Program): {
13
+ declares: string[];
14
+ reads: Set<string>;
15
+ exported: string[];
16
+ }[];
17
+ /**
18
+ * The bindings a React-only library gives a file (`import { Slot } from 'radix-ui'`) have no form in the target: each
19
+ * is replaced by a placeholder of the same name that compiles and renders nothing (`undefined` members, or a function
20
+ * returning `undefined` where the file calls it), so the output never names something undeclared. The file says why
21
+ * with a `react-library` diagnostic. It is an error for the file being converted, and for a file it imports only when
22
+ * it uses what reads the library: importing a plain value (`buttonVariants`, a `cva` object) from a file whose
23
+ * component renders a Radix `Slot` converts that value as it is (a warning names what was left out).
24
+ */
25
+ export declare function stubReactLibraries(modules: Map<string, ModuleIR>, sources: SourceFile[], entry: string, project: Project, target: WebTarget, diagnostics: Diagnostic[]): void;
@@ -0,0 +1,142 @@
1
+ import * as t from '@babel/types';
2
+ import { classifyImport, resolveLocal } from '../../analyzer/deps.js';
3
+ import { parseSource } from '../../analyzer/parse.js';
4
+ const TARGET_NAME = { vue: 'Vue', svelte: 'Svelte', angular: 'Angular' };
5
+ /** The names each top-level statement of a program declares, and the names it reads (values, not types). */
6
+ export function topLevel(program) {
7
+ return program.body.map((stmt) => {
8
+ const decl = t.isExportNamedDeclaration(stmt) || t.isExportDefaultDeclaration(stmt) ? stmt.declaration : stmt;
9
+ const declares = decl && (t.isDeclaration(decl) || t.isVariableDeclaration(decl)) ? Object.keys(t.getOuterBindingIdentifiers(decl)) : [];
10
+ const exported = t.isExportDefaultDeclaration(stmt) ? ['default', ...declares] : t.isExportNamedDeclaration(stmt) ? [...declares, ...stmt.specifiers.flatMap((s) => (t.isExportSpecifier(s) ? [s.local.name] : []))] : [];
11
+ const reads = new Set();
12
+ const visit = (n) => {
13
+ if (n.type.startsWith('TS'))
14
+ return;
15
+ if (t.isIdentifier(n) || t.isJSXIdentifier(n))
16
+ reads.add(n.name);
17
+ for (const key of t.VISITOR_KEYS[n.type] ?? []) {
18
+ if (key === 'typeAnnotation' || key === 'returnType' || key === 'typeParameters' || key === 'typeArguments' || key === 'superTypeParameters')
19
+ continue;
20
+ const value = Reflect.get(n, key);
21
+ for (const child of Array.isArray(value) ? value : [value])
22
+ if (t.isNode(child))
23
+ visit(child);
24
+ }
25
+ };
26
+ if (!t.isImportDeclaration(stmt))
27
+ visit(stmt);
28
+ return { declares, reads, exported };
29
+ });
30
+ }
31
+ /**
32
+ * The bindings a React-only library gives a file (`import { Slot } from 'radix-ui'`) have no form in the target: each
33
+ * is replaced by a placeholder of the same name that compiles and renders nothing (`undefined` members, or a function
34
+ * returning `undefined` where the file calls it), so the output never names something undeclared. The file says why
35
+ * with a `react-library` diagnostic. It is an error for the file being converted, and for a file it imports only when
36
+ * it uses what reads the library: importing a plain value (`buttonVariants`, a `cva` object) from a file whose
37
+ * component renders a Radix `Slot` converts that value as it is (a warning names what was left out).
38
+ */
39
+ export function stubReactLibraries(modules, sources, entry, project, target, diagnostics) {
40
+ // what each file takes from every other file of the conversion, by exported name ('*': everything)
41
+ const takenFrom = new Map();
42
+ const take = (file, name) => {
43
+ const set = takenFrom.get(file) ?? new Set();
44
+ set.add(name);
45
+ takenFrom.set(file, set);
46
+ };
47
+ const programs = new Map();
48
+ for (const src of sources) {
49
+ if (!src.isCode)
50
+ continue;
51
+ let program;
52
+ try {
53
+ program = parseSource(src.code, src.file).program;
54
+ }
55
+ catch {
56
+ continue;
57
+ }
58
+ programs.set(src.file, program);
59
+ for (const stmt of program.body) {
60
+ const source = t.isImportDeclaration(stmt) || t.isExportAllDeclaration(stmt) || (t.isExportNamedDeclaration(stmt) && stmt.source) ? stmt.source?.value : undefined;
61
+ const resolved = source ? resolveLocal(src.file, source, project) : null;
62
+ if (!resolved)
63
+ continue;
64
+ if (t.isImportDeclaration(stmt)) {
65
+ if (stmt.importKind === 'type')
66
+ continue;
67
+ for (const s of stmt.specifiers) {
68
+ if (t.isImportSpecifier(s)) {
69
+ if (s.importKind !== 'type')
70
+ take(resolved, t.isIdentifier(s.imported) ? s.imported.name : s.imported.value);
71
+ }
72
+ else
73
+ take(resolved, t.isImportDefaultSpecifier(s) ? 'default' : '*');
74
+ }
75
+ if (!stmt.specifiers.length)
76
+ take(resolved, '*');
77
+ }
78
+ else if (t.isExportAllDeclaration(stmt))
79
+ take(resolved, '*');
80
+ else if (t.isExportNamedDeclaration(stmt))
81
+ for (const s of stmt.specifiers)
82
+ take(resolved, t.isExportSpecifier(s) ? s.local.name : '*');
83
+ }
84
+ }
85
+ for (const [file, mod] of modules) {
86
+ const libs = mod.imports.filter((d) => d.importKind !== 'type' && !resolveLocal(file, d.source.value, project) && classifyImport(d.source.value) === 'react-lib');
87
+ if (!libs.length)
88
+ continue;
89
+ const locals = new Set(libs.flatMap((d) => d.specifiers.filter((s) => !(t.isImportSpecifier(s) && s.importKind === 'type')).map((s) => s.local.name)));
90
+ const program = programs.get(file);
91
+ // the top-level declarations that read a library binding, directly or through another such declaration
92
+ const tainted = new Set(locals);
93
+ const statements = program ? topLevel(program) : [];
94
+ for (let changed = true; changed;) {
95
+ changed = false;
96
+ for (const s of statements) {
97
+ if (!s.declares.some((n) => !tainted.has(n)) || ![...s.reads].some((n) => tainted.has(n)))
98
+ continue;
99
+ for (const n of s.declares)
100
+ tainted.add(n);
101
+ changed = true;
102
+ }
103
+ }
104
+ const taken = takenFrom.get(file) ?? new Set();
105
+ const exportedTainted = statements.flatMap((s) => s.exported.filter((n) => tainted.has(n) || (n === 'default' && s.declares.some((d) => tainted.has(d)))));
106
+ const used = file === entry || !program || taken.has('*') || exportedTainted.some((n) => taken.has(n));
107
+ const leftOut = [...new Set(statements.flatMap((s) => s.declares.filter((n) => tainted.has(n) && !locals.has(n))))];
108
+ for (const decl of libs) {
109
+ const rel = decl.source.value;
110
+ const message = used
111
+ ? `${rel} is a React-only library with no automatic ${TARGET_NAME[target]} counterpart.`
112
+ : `${rel} is a React-only library with no automatic ${TARGET_NAME[target]} counterpart: ${leftOut.join(', ') || 'what reads it'} ${leftOut.length === 1 ? 'is' : 'are'} not converted (the converted file does not use ${leftOut.length === 1 ? 'it' : 'them'}).`;
113
+ diagnostics.push({ code: 'react-library', severity: used ? 'error' : 'warning', message, file, target, ...(decl.loc ? { line: decl.loc.start.line } : {}) });
114
+ }
115
+ // the names stay declared: a placeholder per binding, so the file compiles and renders nothing there
116
+ const called = new Set();
117
+ if (program) {
118
+ t.traverseFast(program, (n) => {
119
+ if ((t.isCallExpression(n) || t.isNewExpression(n)) && t.isIdentifier(n.callee) && locals.has(n.callee.name))
120
+ called.add(n.callee.name);
121
+ });
122
+ }
123
+ mod.imports = mod.imports.filter((d) => !libs.includes(d));
124
+ const stubs = [...locals].map((name) => {
125
+ const id = t.identifier(name);
126
+ let value;
127
+ if (called.has(name)) {
128
+ const rest = t.restElement(t.identifier('_args'));
129
+ rest.typeAnnotation = t.tsTypeAnnotation(t.tsArrayType(t.tsUnknownKeyword()));
130
+ value = t.arrowFunctionExpression([rest], t.identifier('undefined'));
131
+ }
132
+ else {
133
+ id.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([t.tsStringKeyword(), t.tsUndefinedKeyword()])));
134
+ value = t.objectExpression([]);
135
+ }
136
+ const stmt = t.variableDeclaration('const', [t.variableDeclarator(id, value)]);
137
+ t.addComment(stmt, 'leading', ` antheo-morph: not converted: ${name} comes from a React-only library (see the react-library diagnostic) `, false);
138
+ return stmt;
139
+ });
140
+ mod.moduleBody.unshift(...stubs);
141
+ }
142
+ }
@@ -0,0 +1,16 @@
1
+ import * as t from '@babel/types';
2
+ import type { WebTarget } from '../../types.js';
3
+ /** A type import a mapped type needs, e.g. { source: 'vue', name: 'CSSProperties' }. */
4
+ export interface TypeImport {
5
+ source: string;
6
+ name: string;
7
+ /** the name it is imported as, when another (a React type of the same name) is taken */
8
+ local?: string;
9
+ }
10
+ export declare function reactAlias(names: Set<string>, local: string, imported: string): void;
11
+ export declare function markReactTypes19(names: Set<string>): void;
12
+ export declare function angularMarkupNode(names: Set<string>, source: string, name: string): void;
13
+ export declare function motionTypeAlias(names: Set<string>, local: string, imported: string): void;
14
+ export declare function mapReactTypes<T extends t.Node>(node: T, target: WebTarget, reactNames: Set<string>, imports: TypeImport[]): T;
15
+ /** A type for an inherited HTML attribute the component destructures without declaring it (from its default, if any). */
16
+ export declare function inheritedAttrType(name: string, defaultValue?: t.Expression | null): t.TSType;