@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,550 @@
1
+ import * as t from '@babel/types';
2
+ import { containsJSX, lowerModuleFragments, unwrap } from './lower.js';
3
+ import { pureModuleFunctions } from './markup-values.js';
4
+ /** The module's functions kept as code, by name, with the statement that declares each. */
5
+ function moduleFunctions(mod) {
6
+ const out = new Map();
7
+ for (const stmt of mod.moduleBody) {
8
+ const exported = t.isExportNamedDeclaration(stmt);
9
+ const d = t.isExportNamedDeclaration(stmt) ? stmt.declaration : stmt;
10
+ if (t.isFunctionDeclaration(d) && d.id)
11
+ out.set(d.id.name, { stmt, fn: d, exported, declared: true });
12
+ if (t.isVariableDeclaration(d) && d.kind === 'const' && d.declarations.length === 1) {
13
+ const v = d.declarations[0];
14
+ const init = v?.init ? unwrap(v.init) : null;
15
+ if (v && t.isIdentifier(v.id) && (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init)))
16
+ out.set(v.id.name, { stmt, fn: init, exported, declared: false });
17
+ }
18
+ }
19
+ return out;
20
+ }
21
+ /** The names React's `isValidElement` is imported under, and React's namespace names. */
22
+ function elementTestNames(mod) {
23
+ const named = new Set();
24
+ const namespaces = new Set();
25
+ for (const d of mod.imports) {
26
+ if (d.source.value !== 'react' || d.importKind === 'type')
27
+ continue;
28
+ for (const s of d.specifiers) {
29
+ if (t.isImportSpecifier(s) && s.importKind !== 'type' && (t.isIdentifier(s.imported) ? s.imported.name : s.imported.value) === 'isValidElement')
30
+ named.add(s.local.name);
31
+ else if (!t.isImportSpecifier(s))
32
+ namespaces.add(s.local.name);
33
+ }
34
+ }
35
+ return { named, namespaces };
36
+ }
37
+ /** Whether the code reads one of the names as a value (not as a property key or a member name). */
38
+ function readsAny(root, names) {
39
+ let found = false;
40
+ const walk = (n, parent, key) => {
41
+ if (found)
42
+ return;
43
+ if (t.isIdentifier(n) && names.has(n.name)) {
44
+ const member = parent && (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && key === 'property' && !parent.computed;
45
+ const prop = parent && (t.isObjectProperty(parent) || t.isObjectMethod(parent)) && key === 'key' && !parent.computed;
46
+ const typeKey = parent && (t.isTSPropertySignature(parent) || t.isTSMethodSignature(parent)) && key === 'key';
47
+ if (!member && !prop && !typeKey)
48
+ found = true;
49
+ }
50
+ for (const k of t.VISITOR_KEYS[n.type] ?? []) {
51
+ const child = Reflect.get(n, k);
52
+ for (const c of Array.isArray(child) ? child : [child])
53
+ if (t.isNode(c))
54
+ walk(c, n, k);
55
+ }
56
+ };
57
+ walk(root, null, null);
58
+ return found;
59
+ }
60
+ const BOOLEAN_OPS = new Set(['===', '!==', '==', '!=', '<', '>', '<=', '>=', 'in', 'instanceof']);
61
+ /** Whether a predicate's expression is already a boolean (a comparison, a negation, another predicate's call). */
62
+ function isBoolean(e, shows) {
63
+ if (t.isBooleanLiteral(e) || t.isUnaryExpression(e, { operator: '!' }))
64
+ return true;
65
+ if (t.isBinaryExpression(e))
66
+ return BOOLEAN_OPS.has(e.operator);
67
+ if (t.isLogicalExpression(e) && e.operator !== '??')
68
+ return isBoolean(e.left, shows) && isBoolean(e.right, shows);
69
+ if (t.isCallExpression(e) && t.isIdentifier(e.callee) && shows.has(e.callee.name))
70
+ return true;
71
+ return t.isParenthesizedExpression(e) && isBoolean(e.expression, shows);
72
+ }
73
+ /** `isValidElement(x)` (React's element test) → `typeof x === 'function'` (Svelte's: an element value is a snippet). */
74
+ function svelteTests(e, ctx) {
75
+ if (readsAny(e, ctx.helpers) || containsJSX(e))
76
+ return null;
77
+ const copy = t.cloneNode(e, true);
78
+ const out = replaceTests(copy, ctx);
79
+ return out;
80
+ }
81
+ function elementTestArg(e, ctx) {
82
+ if (!t.isCallExpression(e) || e.arguments.length !== 1)
83
+ return null;
84
+ const c = e.callee;
85
+ const named = t.isIdentifier(c) && ctx.tests.named.has(c.name);
86
+ const spaced = t.isMemberExpression(c) && !c.computed && t.isIdentifier(c.object) && ctx.tests.namespaces.has(c.object.name) && t.isIdentifier(c.property, { name: 'isValidElement' });
87
+ const arg = e.arguments[0];
88
+ return (named || spaced) && t.isExpression(arg) ? arg : null;
89
+ }
90
+ function replaceTests(e, ctx) {
91
+ const arg = elementTestArg(e, ctx);
92
+ if (arg)
93
+ return t.binaryExpression('===', t.unaryExpression('typeof', replaceTests(arg, ctx)), t.stringLiteral('function'));
94
+ for (const k of t.VISITOR_KEYS[e.type] ?? []) {
95
+ const child = Reflect.get(e, k);
96
+ if (Array.isArray(child))
97
+ child.forEach((c, i) => t.isNode(c) && t.isExpression(c) && (child[i] = replaceTests(c, ctx)));
98
+ else if (t.isNode(child) && t.isExpression(child))
99
+ Reflect.set(e, k, replaceTests(child, ctx));
100
+ }
101
+ return e;
102
+ }
103
+ /** `!!x` unless it already is a boolean. */
104
+ function bool(e, ctx) {
105
+ return isBoolean(e, new Set([...ctx.shows.values()].map((s) => s.name))) ? e : t.unaryExpression('!', t.unaryExpression('!', e));
106
+ }
107
+ const FLIPPED = { '===': '!==', '!==': '===', '==': '!=', '!=': '==' };
108
+ /** `!test`, a comparison flipped (`icon !== 'none'`). */
109
+ function not(e) {
110
+ const flipped = t.isBinaryExpression(e) ? FLIPPED[e.operator] : undefined;
111
+ if (t.isBinaryExpression(e) && flipped && t.isExpression(e.left))
112
+ return t.binaryExpression(flipped, e.left, e.right);
113
+ return t.unaryExpression('!', e);
114
+ }
115
+ /** `test ? a : b` for booleans, written as plainly as it reads. */
116
+ function choose(test, a, b, ctx) {
117
+ const lit = (e) => (t.isBooleanLiteral(e) ? e.value : null);
118
+ const [la, lb] = [lit(a), lit(b)];
119
+ if (la !== null && la === lb)
120
+ return a;
121
+ if (la === true && lb === false)
122
+ return bool(test, ctx);
123
+ if (la === false && lb === true)
124
+ return not(test);
125
+ if (la === true)
126
+ return t.logicalExpression('||', bool(test, ctx), b);
127
+ if (la === false)
128
+ return t.logicalExpression('&&', not(test), b);
129
+ if (lb === false)
130
+ return t.logicalExpression('&&', bool(test, ctx), a);
131
+ if (lb === true)
132
+ return t.logicalExpression('||', not(test), a);
133
+ return t.conditionalExpression(test, a, b);
134
+ }
135
+ /**
136
+ * Whether the value a helper returns renders anything, as a boolean expression of the same names: an element always
137
+ * does, `null`, `undefined` and `false` never, literal text when it is not empty, another helper's call as its
138
+ * predicate says, and a test picks between its arms; a value an element test holds to be an element always does. Null
139
+ * for any other value (one passed through may be a number React renders where it is tested).
140
+ */
141
+ function presence(e, ctx) {
142
+ const x = unwrap(e);
143
+ if (t.isJSXElement(x) || t.isJSXFragment(x))
144
+ return t.booleanLiteral(true);
145
+ if (t.isNullLiteral(x) || t.isIdentifier(x, { name: 'undefined' }) || t.isBooleanLiteral(x, { value: false }))
146
+ return t.booleanLiteral(false);
147
+ if (t.isConditionalExpression(x)) {
148
+ const test = svelteTests(x.test, ctx);
149
+ const element = elementTestArg(x.test, ctx);
150
+ // `isValidElement(icon) ? icon : null`: the element (a snippet here) is always there
151
+ const a = element && t.isNodesEquivalent(unwrap(x.consequent), element) ? t.booleanLiteral(true) : presence(x.consequent, ctx);
152
+ const b = presence(x.alternate, ctx);
153
+ return test && a && b ? choose(test, a, b, ctx) : null;
154
+ }
155
+ if (t.isLogicalExpression(x) && x.operator === '&&') {
156
+ const left = svelteTests(x.left, ctx);
157
+ const right = presence(x.right, ctx);
158
+ return left && right ? choose(left, right, t.booleanLiteral(false), ctx) : null;
159
+ }
160
+ if (t.isCallExpression(x) && t.isIdentifier(x.callee) && ctx.helpers.has(x.callee.name)) {
161
+ const shows = ctx.shows.get(x.callee.name);
162
+ const args = x.arguments.filter((a) => t.isExpression(a) && !containsJSX(a) && !readsAny(a, ctx.helpers));
163
+ if (!shows || args.length !== x.arguments.length)
164
+ return null;
165
+ return t.callExpression(t.identifier(shows.name), args.slice(0, shows.arity).map((a) => replaceTests(t.cloneNode(a, true), ctx)));
166
+ }
167
+ // text written as a literal is there when it is not empty
168
+ if (t.isStringLiteral(x) || t.isNumericLiteral(x))
169
+ return t.booleanLiteral(!!x.value);
170
+ if (t.isTemplateLiteral(x) && !x.expressions.length)
171
+ return t.booleanLiteral(!!x.quasis[0]?.value.cooked);
172
+ // any other value passed through may be a number: React passes 0 on, and the receiver's test of the prop renders it,
173
+ // where a predicate would pass nothing
174
+ return null;
175
+ }
176
+ /** The predicate's statements: the helper's, each return giving whether its value renders anything. */
177
+ function presenceStatements(list, ctx) {
178
+ const out = [];
179
+ for (const s of list) {
180
+ const one = presenceStatement(s, ctx);
181
+ if (!one)
182
+ return null;
183
+ out.push(one);
184
+ }
185
+ return out;
186
+ }
187
+ function presenceStatement(s, ctx) {
188
+ if (t.isReturnStatement(s)) {
189
+ const value = presence(s.argument ?? t.nullLiteral(), ctx);
190
+ return value ? t.returnStatement(value) : null;
191
+ }
192
+ if (t.isBlockStatement(s)) {
193
+ const body = presenceStatements(s.body, ctx);
194
+ return body ? t.blockStatement(body) : null;
195
+ }
196
+ if (t.isIfStatement(s)) {
197
+ const test = svelteTests(s.test, ctx);
198
+ const yes = presenceStatement(s.consequent, ctx);
199
+ const no = s.alternate ? presenceStatement(s.alternate, ctx) : null;
200
+ return test && yes && (!s.alternate || no) ? t.ifStatement(test, yes, no) : null;
201
+ }
202
+ if (t.isSwitchStatement(s)) {
203
+ const on = svelteTests(s.discriminant, ctx);
204
+ const cases = [];
205
+ for (const c of s.cases) {
206
+ const test = c.test ? svelteTests(c.test, ctx) : null;
207
+ const body = presenceStatements(c.consequent, ctx);
208
+ if ((c.test && !test) || !body)
209
+ return null;
210
+ cases.push(t.switchCase(test, body));
211
+ }
212
+ return on ? t.switchStatement(on, cases) : null;
213
+ }
214
+ if (t.isVariableDeclaration(s) && s.kind === 'const') {
215
+ const decls = [];
216
+ for (const d of s.declarations) {
217
+ const init = d.init ? svelteTests(d.init, ctx) : null;
218
+ if (!init)
219
+ return null;
220
+ decls.push(t.variableDeclarator(t.cloneNode(d.id, true), init));
221
+ }
222
+ return t.variableDeclaration('const', decls);
223
+ }
224
+ return null;
225
+ }
226
+ /** The predicate of a helper: same parameters (the unread ones at the end left out), `: boolean`. */
227
+ function predicate(name, h, ctx) {
228
+ const params = h.fn.params.filter((p) => t.isIdentifier(p));
229
+ if (params.length !== h.fn.params.length)
230
+ return null;
231
+ let body;
232
+ if (t.isBlockStatement(h.fn.body))
233
+ body = presenceStatements(h.fn.body.body, ctx);
234
+ else
235
+ body = presence(h.fn.body, ctx);
236
+ if (!body)
237
+ return null;
238
+ const holder = Array.isArray(body) ? t.blockStatement(body) : body;
239
+ // a parameter the predicate never reads: left out at the end (a call passes fewer arguments), named `_x` before
240
+ const read = (p) => readsAny(holder, new Set([p.name]));
241
+ let arity = params.length;
242
+ for (let last = params[arity - 1]; last && !read(last); last = params[arity - 1])
243
+ arity--;
244
+ const kept = params.slice(0, arity).map((p) => {
245
+ const id = t.cloneNode(p, true);
246
+ if (!read(p))
247
+ id.name = `_${id.name}`;
248
+ return id;
249
+ });
250
+ const returnType = t.tsTypeAnnotation(t.tsBooleanKeyword());
251
+ let decl;
252
+ if (h.declared) {
253
+ const fn = t.functionDeclaration(t.identifier(name), kept, Array.isArray(body) ? t.blockStatement(body) : t.blockStatement([t.returnStatement(body)]));
254
+ fn.returnType = returnType;
255
+ decl = fn;
256
+ }
257
+ else {
258
+ const fn = t.arrowFunctionExpression(kept, Array.isArray(body) ? t.blockStatement(body) : body);
259
+ fn.returnType = returnType;
260
+ decl = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(name), fn)]);
261
+ }
262
+ return { stmt: h.exported ? t.exportNamedDeclaration(decl) : decl, arity };
263
+ }
264
+ /**
265
+ * Decides which of the module's helpers kept as code become snippets (see the file comment): pure ones that build
266
+ * markup or return another such helper's call, read by no other module code, with a fragment form and a predicate.
267
+ * Each one's statement is replaced by its predicate. Only a module with a component has a file to declare snippets in.
268
+ */
269
+ export function settleSnippetHelpers(mod) {
270
+ const fns = moduleFunctions(mod);
271
+ // why each helper that builds markup stays code, said by its module-jsx error
272
+ const reasons = new Map();
273
+ const refuse = (n, why) => {
274
+ if (!reasons.has(n) && containsJSX(fns.get(n)?.fn ?? t.nullLiteral()))
275
+ reasons.set(n, why);
276
+ };
277
+ const settle = () => {
278
+ if (reasons.size)
279
+ mod.snippetRefusals = reasons;
280
+ };
281
+ if (!mod.components.length) {
282
+ for (const n of fns.keys())
283
+ refuse(n, 'the file has no component whose markup could declare it');
284
+ return settle();
285
+ }
286
+ const pure = pureModuleFunctions(mod, new Set());
287
+ for (const n of fns.keys())
288
+ if (!pure.has(n))
289
+ refuse(n, 'its call does more than compute its value (it changes something, or calls a function other than the file\'s own pure ones), so the test could not repeat it');
290
+ const returnsCall = (fn, names) => readsAny(fn.body, names);
291
+ const cands = new Set([...fns].filter(([n, h]) => pure.has(n) && containsJSX(h.fn)).map(([n]) => n));
292
+ if (!cands.size)
293
+ return settle();
294
+ for (let grew = true; grew;) {
295
+ grew = false;
296
+ for (const [n, h] of fns) {
297
+ if (!cands.has(n) && pure.has(n) && returnsCall(h.fn, cands)) {
298
+ cands.add(n);
299
+ grew = true;
300
+ }
301
+ }
302
+ }
303
+ const taken = new Set([...mod.moduleJsx.moduleNames, ...mod.components.map((c) => c.name), ...mod.hooks.map((h) => h.name)]);
304
+ const showsName = (n) => {
305
+ const base = `shows${n.charAt(0).toUpperCase()}${n.slice(1)}`;
306
+ let name = base;
307
+ for (let i = 2; taken.has(name); i++)
308
+ name = `${base}${i}`;
309
+ taken.add(name);
310
+ return name;
311
+ };
312
+ const names = new Map([...cands].map((n) => [n, showsName(n)]));
313
+ const tests = elementTestNames(mod);
314
+ let defs = null;
315
+ let preds = new Map();
316
+ for (let changed = true; changed && cands.size;) {
317
+ changed = false;
318
+ const drop = (n, why) => {
319
+ cands.delete(n);
320
+ refuse(n, why);
321
+ changed = true;
322
+ };
323
+ // read by other module code or a hook: it stays a value there
324
+ for (const s of mod.moduleBody) {
325
+ const own = [...fns].find(([n, h]) => h.stmt === s && cands.has(n));
326
+ if (own)
327
+ continue;
328
+ for (const n of [...cands])
329
+ if (readsAny(s, new Set([n])))
330
+ drop(n, 'other code of the file reads it as a value, which a snippet is not');
331
+ }
332
+ for (const hook of mod.hooks)
333
+ for (const n of [...cands])
334
+ if (hook.items.some((i) => 'node' in i && t.isNode(i.node) && readsAny(i.node, new Set([n]))))
335
+ drop(n, `the hook ${hook.name} reads it as a value, which a snippet is not`);
336
+ // a helper that calls one that is not a snippet (or builds markup in another helper kept as code)
337
+ for (const n of [...cands]) {
338
+ const h = fns.get(n);
339
+ const others = new Set([...fns.keys()].filter((o) => o !== n && !cands.has(o) && containsJSX(fns.get(o)?.fn ?? t.nullLiteral())));
340
+ if (h && readsAny(h.fn, others))
341
+ drop(n, 'it calls another helper of the file that builds markup and is not converted');
342
+ }
343
+ if (changed)
344
+ continue;
345
+ // the predicates, callees first (a predicate calls the predicates of the helpers it returns)
346
+ preds = new Map();
347
+ const shows = new Map();
348
+ const ctx = { helpers: new Set(cands), shows, tests };
349
+ for (let progress = true; progress;) {
350
+ progress = false;
351
+ for (const n of cands) {
352
+ if (preds.has(n))
353
+ continue;
354
+ const h = fns.get(n);
355
+ const callees = [...cands].filter((o) => o !== n && h && readsAny(h.fn, new Set([o])));
356
+ if (!h || callees.some((o) => !preds.has(o)))
357
+ continue;
358
+ const p = predicate(names.get(n) ?? n, h, ctx);
359
+ if (!p)
360
+ continue;
361
+ preds.set(n, p);
362
+ shows.set(n, { name: names.get(n) ?? n, arity: p.arity });
363
+ progress = true;
364
+ }
365
+ }
366
+ for (const n of [...cands])
367
+ if (!preds.has(n))
368
+ drop(n, 'whether it renders anything has no exact test: it returns a value it is given (which may be a number React passes on and a receiver renders), or a value of another form');
369
+ if (changed)
370
+ continue;
371
+ defs = lowerModuleFragments(mod, new Map([...cands].map((n) => [n, fns.get(n)?.fn ?? t.functionExpression(null, [], t.blockStatement([]))])));
372
+ if (!defs) {
373
+ // one at a time, with the helpers it calls, to keep those that convert
374
+ const alone = [...cands].filter((n) => {
375
+ const h = fns.get(n);
376
+ const closure = new Map();
377
+ const add = (m) => {
378
+ const f = fns.get(m);
379
+ if (!f || closure.has(m))
380
+ return;
381
+ closure.set(m, f.fn);
382
+ for (const o of cands)
383
+ if (o !== m && readsAny(f.fn, new Set([o])))
384
+ add(o);
385
+ };
386
+ if (h)
387
+ add(n);
388
+ return !lowerModuleFragments(mod, closure);
389
+ });
390
+ const why = 'its body has no snippet form (only `const` values, `if` and `switch` with early returns, and returned markup convert)';
391
+ if (!alone.length) {
392
+ for (const n of cands)
393
+ refuse(n, why);
394
+ return settle();
395
+ }
396
+ for (const n of alone)
397
+ drop(n, why);
398
+ }
399
+ }
400
+ settle();
401
+ if (!defs || !cands.size)
402
+ return;
403
+ mod.moduleBody = mod.moduleBody.map((s) => {
404
+ const own = [...cands].find((n) => fns.get(n)?.stmt === s);
405
+ return own ? (preds.get(own)?.stmt ?? s) : s;
406
+ });
407
+ for (const n of names.values())
408
+ mod.moduleJsx.moduleNames.add(n);
409
+ mod.snippetHelpers = {
410
+ defs,
411
+ exported: new Set([...cands].filter((n) => fns.get(n)?.exported)),
412
+ shows: new Map([...cands].map((n) => [n, { name: names.get(n) ?? n, arity: preds.get(n)?.arity ?? 0 }])),
413
+ };
414
+ }
415
+ /**
416
+ * Converts what a module's components do with snippet helpers (its own and the ones it imports): a call in markup
417
+ * renders the snippet; a call passed whole as a component's prop is markup passed while its predicate holds; a call in
418
+ * the test of passed markup (`when`) reads the predicate. Returns the helpers whose predicate it reads, and every other
419
+ * read, which has no Svelte form (a snippet is no value a function returns).
420
+ */
421
+ export function useSnippetHelpers(mod, helpers) {
422
+ const used = new Set();
423
+ const leftover = [];
424
+ if (!helpers.size)
425
+ return { used, leftover };
426
+ for (const comp of mod.components) {
427
+ const live = new Map([...helpers].filter(([n]) => !comp.bindings.has(n)));
428
+ if (!live.size)
429
+ continue;
430
+ const call = (e) => {
431
+ const x = t.isExpression(e) ? unwrap(e) : e;
432
+ return t.isCallExpression(x) && t.isIdentifier(x.callee) && live.has(x.callee.name) && x.arguments.every((a) => t.isExpression(a)) ? x : null;
433
+ };
434
+ const shows = (c) => {
435
+ const name = t.isIdentifier(c.callee) ? c.callee.name : '';
436
+ const h = live.get(name);
437
+ used.add(name);
438
+ const args = c.arguments.filter((a) => t.isExpression(a));
439
+ return t.callExpression(t.identifier(h?.shows ?? name), args.slice(0, h?.arity ?? 0).map((a) => t.cloneNode(a, true)));
440
+ };
441
+ const render = (c) => ({ type: 'render', name: t.isIdentifier(c.callee) ? c.callee.name : '', args: c.arguments.filter((a) => t.isExpression(a)) });
442
+ // a helper's call where only its truthiness counts: its predicate
443
+ const truthiness = (e) => {
444
+ const c = call(e);
445
+ if (c)
446
+ return shows(c);
447
+ const x = unwrap(e);
448
+ if (t.isConditionalExpression(x))
449
+ return t.conditionalExpression(truthiness(x.test), truthiness(x.consequent), truthiness(x.alternate));
450
+ if (t.isLogicalExpression(x))
451
+ return t.logicalExpression(x.operator, truthiness(x.left), truthiness(x.right));
452
+ if (t.isUnaryExpression(x, { operator: '!' }))
453
+ return t.unaryExpression('!', truthiness(x.argument));
454
+ return e;
455
+ };
456
+ const nodes = (list) => list.map(node);
457
+ const node = (n) => {
458
+ switch (n.type) {
459
+ case 'expr': {
460
+ const c = call(n.expr);
461
+ return c ? render(c) : n;
462
+ }
463
+ case 'element':
464
+ n.attrs = n.attrs.map((a) => {
465
+ if (a.kind === 'slotProp') {
466
+ a.children = nodes(a.children);
467
+ if (a.when)
468
+ a.when = truthiness(a.when);
469
+ return a;
470
+ }
471
+ const c = a.kind === 'expr' && n.component ? call(a.expr) : null;
472
+ return c && a.kind === 'expr' ? { kind: 'slotProp', name: a.name, children: [render(c)], when: shows(c) } : a;
473
+ });
474
+ n.children = nodes(n.children);
475
+ return n;
476
+ case 'if':
477
+ for (const b of n.branches)
478
+ b.children = nodes(b.children);
479
+ return n;
480
+ case 'slot':
481
+ n.fallback = nodes(n.fallback);
482
+ return n;
483
+ case 'for':
484
+ case 'fragment':
485
+ case 'keyed':
486
+ case 'presence':
487
+ n.children = nodes(n.children);
488
+ return n;
489
+ default:
490
+ return n;
491
+ }
492
+ };
493
+ comp.template = node(comp.template);
494
+ for (const f of comp.fragments)
495
+ f.template = node(f.template);
496
+ for (const v of comp.markupValues ?? [])
497
+ v.template = node(v.template);
498
+ // any other read: script code, a DOM attribute, an argument
499
+ const names = new Set(live.keys());
500
+ const seen = new Set();
501
+ const report = (root) => {
502
+ for (const n of nodesIn(root)) {
503
+ for (const name of names) {
504
+ if (seen.has(name) || !readsAny(n, new Set([name])))
505
+ continue;
506
+ seen.add(name);
507
+ leftover.push({ name, comp: comp.name, ...(n.loc ? { line: n.loc.start.line } : {}) });
508
+ }
509
+ }
510
+ };
511
+ report(comp.items);
512
+ report(comp.template);
513
+ report(comp.fragments);
514
+ report(comp.markupValues ?? []);
515
+ }
516
+ for (const hook of mod.hooks) {
517
+ const names = new Set([...helpers.keys()].filter((n) => !hook.bindings.has(n)));
518
+ for (const i of hook.items) {
519
+ const n = 'node' in i && t.isNode(i.node) ? i.node : null;
520
+ const name = n ? [...names].find((x) => readsAny(n, new Set([x]))) : undefined;
521
+ if (n && name)
522
+ leftover.push({ name, comp: hook.name, ...(n.loc ? { line: n.loc.start.line } : {}) });
523
+ }
524
+ }
525
+ return { used, leftover };
526
+ }
527
+ /** The Babel nodes held anywhere in IR data (arrays and plain objects), outermost first. */
528
+ function nodesIn(root, out = [], seen = new WeakSet()) {
529
+ if (Array.isArray(root)) {
530
+ for (const v of root)
531
+ nodesIn(v, out, seen);
532
+ return out;
533
+ }
534
+ if (!root || typeof root !== 'object' || seen.has(root))
535
+ return out;
536
+ seen.add(root);
537
+ if (t.isNode(root)) {
538
+ out.push(root);
539
+ return out;
540
+ }
541
+ if (root instanceof Map || root instanceof Set || root instanceof WeakMap)
542
+ return out;
543
+ for (const v of Object.values(root))
544
+ nodesIn(v, out, seen);
545
+ return out;
546
+ }
547
+ /** The module-level helpers, as the function holder Svelte's element test replacement reads (`fragments`). */
548
+ export function snippetHelperHolder(mod) {
549
+ return { name: '', file: mod.file, items: [], bindings: new Map(), refs: new WeakMap(), diagnostics: [], moduleNames: new Set(), fragments: mod.snippetHelpers?.defs ?? [] };
550
+ }
@@ -0,0 +1,11 @@
1
+ import type { ModuleIR } from './model.js';
2
+ /**
3
+ * React's "latest value" ref: `const onChangeRef = useRef(onChange); onChangeRef.current = onChange;`, read later as
4
+ * `onChangeRef.current` in a callback, so the callback sees the value of the last render without being re-created.
5
+ * A Vue or Svelte callback reads props and live arguments as they are now, so the ref says nothing there: each
6
+ * `onChangeRef.current` reads `onChange` itself, and the ref and the watcher that kept it in step go.
7
+ *
8
+ * Only a ref written in that one render statement, from a plain read (`onChange`, `options.onChange`), and otherwise
9
+ * only read through `.current`.
10
+ */
11
+ export declare function inlineLatestRefs(mod: ModuleIR): void;