@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,791 @@
1
+ import * as t from '@babel/types';
2
+ import { lowerModuleMarkup, unwrap } from '../../../ir/lower.js';
3
+ // M4: the function a tree helper was lowered from
4
+ import { fragmentSource } from '../../../ir/fragment-source.js';
5
+ import { templateExpressions } from '../../shared/inline.js';
6
+ import { BANK_READS } from './plan.js';
7
+ import { walk } from './receivers.js';
8
+ // M4: the DOM event and element types of a handler carried with its event parameter
9
+ import { elementType, eventType, plainEventParams } from '../emit.js';
10
+ /**
11
+ * Binding kinds a banked element may read through its context: values, and the component's functions (class arrow
12
+ * members, bound). Not a state setter or a callback prop that is an output: the class reads either name as a value as
13
+ * its signal or its output, which the banked template would call as a function.
14
+ */
15
+ const VALUE_KINDS = new Set(['prop', 'state', 'derived', 'param', 'id', 'function']);
16
+ /** The code nodes an item holds (a block's statements, a derived value's initializer). */
17
+ function codeOf(item) {
18
+ if (item.kind === 'block')
19
+ return item.statements;
20
+ if (item.kind === 'derived')
21
+ return [item.init];
22
+ return [item.node];
23
+ }
24
+ /** The names an item binds inside its own code: its variables, loop variables, nested functions' parameters. */
25
+ function boundInside(roots) {
26
+ const out = new Set();
27
+ for (const root of roots)
28
+ t.traverseFast(root, (n) => {
29
+ if (t.isVariableDeclarator(n))
30
+ for (const name of Object.keys(t.getBindingIdentifiers(n.id)))
31
+ out.add(name);
32
+ if (t.isFunction(n))
33
+ for (const p of n.params)
34
+ for (const name of Object.keys(t.getBindingIdentifiers(p)))
35
+ out.add(name);
36
+ if (t.isCatchClause(n) && n.param)
37
+ for (const name of Object.keys(t.getBindingIdentifiers(n.param)))
38
+ out.add(name);
39
+ });
40
+ return out;
41
+ }
42
+ /** A copy of code with the given elements replaced by `null` (for reading the names the rest binds). */
43
+ function withoutJsx(code, roots) {
44
+ const skip = new Set(roots);
45
+ const copy = (n) => {
46
+ if (skip.has(n))
47
+ return t.nullLiteral();
48
+ const out = t.cloneNode(n, false);
49
+ for (const key of t.VISITOR_KEYS[n.type] ?? []) {
50
+ const v = Reflect.get(n, key);
51
+ if (Array.isArray(v))
52
+ Reflect.set(out, key, v.map((c) => (t.isNode(c) ? copy(c) : c)));
53
+ else if (t.isNode(v))
54
+ Reflect.set(out, key, copy(v));
55
+ }
56
+ return out;
57
+ };
58
+ return copy(code);
59
+ }
60
+ /** The outermost elements in code (nested functions entered: an element made there captures its values the same way). */
61
+ function jsxRoots(roots) {
62
+ const out = [];
63
+ const visit = (n) => {
64
+ if (t.isJSXElement(n) || t.isJSXFragment(n)) {
65
+ out.push(n);
66
+ return;
67
+ }
68
+ for (const key of t.VISITOR_KEYS[n.type] ?? []) {
69
+ const v = Reflect.get(n, key);
70
+ for (const c of Array.isArray(v) ? v : [v])
71
+ if (t.isNode(c))
72
+ visit(c);
73
+ }
74
+ };
75
+ for (const r of roots)
76
+ visit(r);
77
+ return out;
78
+ }
79
+ function keyOf(jsx) {
80
+ if (!t.isJSXElement(jsx))
81
+ return null;
82
+ const attr = jsx.openingElement.attributes.find((a) => t.isJSXAttribute(a) && t.isJSXIdentifier(a.name, { name: 'key' }));
83
+ if (!attr)
84
+ return null;
85
+ if (t.isStringLiteral(attr.value))
86
+ return attr.value;
87
+ return t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression) ? attr.value.expression : null;
88
+ }
89
+ /** Whether a lowered template holds something a banked piece of a component cannot carry yet (a handler, a ref). */
90
+ function carriesBehaviour(template, inlined) {
91
+ let found = false;
92
+ walk([template], (n) => {
93
+ if (n.type === 'element' && n.attrs.some((a) => a.kind === 'ref' || a.kind === 'spread' || a.kind === 'html'))
94
+ found = true;
95
+ if (n.type === 'unconverted' || n.type === 'render' || n.type === 'slot')
96
+ found = true;
97
+ // a private component the module writes in place where it is used: its handlers have no typed home in the bank
98
+ if (n.type === 'element' && n.component && inlined.has(n.tag))
99
+ found = true;
100
+ });
101
+ return found;
102
+ }
103
+ /** The value names an item declares. */
104
+ function namesOf(item) {
105
+ if (item.kind === 'derived')
106
+ return item.names;
107
+ if (item.kind === 'block' || item.kind === 'function')
108
+ return [item.name];
109
+ return [];
110
+ }
111
+ function readsAnyIn(nodes, names, comp) {
112
+ let found = false;
113
+ for (const root of nodes)
114
+ t.traverseFast(root, (n) => {
115
+ if (t.isIdentifier(n) && names.has(comp.refs.get(n) ?? ''))
116
+ found = true;
117
+ });
118
+ return found;
119
+ }
120
+ function itemCode(item) {
121
+ const out = [];
122
+ for (const v of Object.values(item)) {
123
+ if (t.isNode(v))
124
+ out.push(v);
125
+ else if (Array.isArray(v))
126
+ for (const x of v)
127
+ if (t.isNode(x))
128
+ out.push(x);
129
+ }
130
+ return out;
131
+ }
132
+ /**
133
+ * Each element in code as a banked piece named `<prefix>_<n>`, or null when one cannot be: it lowers with a diagnostic,
134
+ * holds a ref, a spread or an unconverted part, or reads a component name that is no value (a ref, a hook's result,
135
+ * children).
136
+ */
137
+ function bankPiecesOf(mod, comp, code, prefix, moduleNames, outputs, inlined) {
138
+ const childrenProps = new Set([...comp.props.filter((p) => p.kind === 'children' || p.kind === 'node').map((p) => p.local), ...outputs]);
139
+ const roots = jsxRoots(code);
140
+ // the code's own names, outside its elements (a handler's parameters inside an element are not among them)
141
+ const inside = boundInside(code.map((c) => withoutJsx(c, roots)));
142
+ const locals = new Set([...comp.bindings.keys(), ...inside].filter((n) => !moduleNames.has(n) || inside.has(n)));
143
+ if (!roots.length)
144
+ return null;
145
+ const pieces = [];
146
+ const taken = new Set([...comp.bindings.keys(), ...moduleNames, ...inside]);
147
+ for (const [i, jsx] of roots.entries()) {
148
+ // a DOM handler that sets state or calls a callback prop (`onClick={() => setPicked(item)}`) is carried whole, as a
149
+ // function the class writes (`onClick1: () => this.picked.set(item)`), which the template calls
150
+ const { copy, lifted } = liftHandlers(jsx, comp, taken, outputs);
151
+ // a handler's own parameters (`onChange={(val) => …}`) are the event's, not names the element carries
152
+ const own = boundInside([copy]);
153
+ const lowered = lowerModuleMarkup(mod, copy, new Set([...locals, ...lifted.keys()].filter((n) => !own.has(n))));
154
+ if (lowered.diagnostics.some((d) => d.severity === 'error' || d.severity === 'warning') || carriesBehaviour(lowered.template, inlined))
155
+ return null;
156
+ // (a name both bound inside the element and read from outside it: not followed)
157
+ if ([...own].some((n) => locals.has(n)))
158
+ return null;
159
+ // each context name is a value: a variable of the code, or a prop, state, value or function of the component
160
+ for (const name of lowered.reads) {
161
+ if (inside.has(name) || lifted.has(name))
162
+ continue;
163
+ const b = comp.bindings.get(name);
164
+ if (!b || !VALUE_KINDS.has(b.kind) || childrenProps.has(name))
165
+ return null;
166
+ }
167
+ // React's key is the value's key (the directive keeps or remakes the view by it), not a block of the template
168
+ const key = keyOf(jsx);
169
+ const template = key && lowered.template.type === 'keyed' ? { type: 'fragment', children: lowered.template.children } : lowered.template;
170
+ pieces.push({ name: `${prefix}_${i + 1}`, jsx, template, params: lowered.reads, moduleNames: lowered.moduleNames, key, lifted });
171
+ }
172
+ return pieces;
173
+ }
174
+ /**
175
+ * M4. A handler carried whole that takes the event (`onKeyDown={(e) => { if (e.key === 'ArrowRight') setReversed(…) }}`):
176
+ * the DOM event type and the element it sits on, written on its parameter in class code (as React types it: the event
177
+ * with that element as `currentTarget`, then the plain DOM event the template passes, see plainEventParams).
178
+ */
179
+ const handlerEvents = new WeakMap();
180
+ /**
181
+ * A copy of an element in which each DOM handler that is a function of no parameters and reads a state setter or a
182
+ * callback prop (names the class reads as a signal or an output, not as a function) is replaced by a name of its own;
183
+ * those names and the handlers they stand for. The handler is written in class code, where the class reads the setter
184
+ * and the output as React's code calls them, and made where the element is made, as React makes it on that render.
185
+ */
186
+ function liftHandlers(jsx, comp, taken, outputs) {
187
+ const lifted = new Map();
188
+ const needsClass = (fn) => {
189
+ let found = false;
190
+ t.traverseFast(fn, (n) => {
191
+ if (!t.isIdentifier(n))
192
+ return;
193
+ const own = comp.refs.get(n);
194
+ if (own !== undefined && (comp.bindings.get(own)?.kind === 'setter' || outputs.has(own)))
195
+ found = true;
196
+ });
197
+ return found;
198
+ };
199
+ // `onDom`: the node is an attribute of an element written with a lowercase tag (a DOM element)
200
+ const copy = (n, onDom, parentOf = null) => {
201
+ const out = t.cloneNode(n, false);
202
+ if (onDom && t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && /^on[A-Z]/.test(n.name.name) && t.isJSXExpressionContainer(n.value)) {
203
+ const fn = n.value.expression;
204
+ // M4: or one parameter, the event, of a DOM event the template can type
205
+ const tag = t.isJSXOpeningElement(parentOf) && t.isJSXIdentifier(parentOf.name) && /^[a-z]/.test(parentOf.name.name) ? parentOf.name.name : null;
206
+ const takesEvent = (t.isArrowFunctionExpression(fn) || t.isFunctionExpression(fn)) && fn.params.length === 1 && t.isIdentifier(fn.params[0]) && !fn.params[0].typeAnnotation && !!tag && eventType(n.name.name) !== 'any';
207
+ if ((t.isArrowFunctionExpression(fn) || t.isFunctionExpression(fn)) && (!fn.params.length || takesEvent) && !fn.async && needsClass(fn)) {
208
+ if (takesEvent && tag)
209
+ handlerEvents.set(fn, { event: eventType(n.name.name), element: elementType(tag) });
210
+ const base = n.name.name;
211
+ let name = base;
212
+ for (let k = 1; taken.has(name); k++)
213
+ name = `${base}${k + 1}`;
214
+ taken.add(name);
215
+ lifted.set(name, fn);
216
+ return Object.assign(out, { value: t.jsxExpressionContainer(Object.assign(t.identifier(name), { loc: fn.loc })) });
217
+ }
218
+ }
219
+ // M4: a component's callback prop too (`<Chip onPick={() => setPicked(tag)} />`, an output the template binds)
220
+ const dom = t.isJSXOpeningElement(n) && t.isJSXIdentifier(n.name);
221
+ for (const key of t.VISITOR_KEYS[n.type] ?? []) {
222
+ const v = Reflect.get(n, key);
223
+ const child = (c) => copy(c, dom && key === 'attributes' && t.isJSXAttribute(c), n);
224
+ if (Array.isArray(v))
225
+ Reflect.set(out, key, v.map((c) => (t.isNode(c) ? child(c) : c)));
226
+ else if (t.isNode(v))
227
+ Reflect.set(out, key, child(v));
228
+ }
229
+ return out;
230
+ };
231
+ const result = copy(jsx, false);
232
+ if (!t.isJSXElement(result) && !t.isJSXFragment(result))
233
+ throw new Error('an element copies as an element');
234
+ return { copy: result, lifted };
235
+ }
236
+ /** Each template place lowering left unconverted with its kept expression, outside loops and markup passed to a prop. */
237
+ function keptSites(template) {
238
+ const out = [];
239
+ const visit = (nodes, guards) => {
240
+ for (const n of nodes) {
241
+ if (n.type === 'unconverted' && n.kept !== undefined)
242
+ out.push({ node: n, id: n.kept, guards });
243
+ // (a loop's row, a prop's markup: the expression may read names only the template has)
244
+ if (n.type === 'element')
245
+ visit(n.children, guards);
246
+ else if (n.type === 'if')
247
+ n.branches.forEach((b, i) => visit(b.children, [...guards, { test: b.test, before: n.branches.slice(0, i).flatMap((x) => (x.test ? [x.test] : [])) }]));
248
+ else if (n.type === 'fragment' || n.type === 'keyed' || n.type === 'presence')
249
+ visit(n.children, guards);
250
+ }
251
+ };
252
+ visit([template], []);
253
+ return out;
254
+ }
255
+ /** Whether every name an expression reads (outside its own variables) is the component's, the module's or a global. */
256
+ function readsOnlyClassNames(expr, comp, moduleNames, isGlobal) {
257
+ const inside = boundInside([expr]);
258
+ let ok = true;
259
+ t.traverse(expr, (n, ancestors) => {
260
+ if (!ok || !t.isIdentifier(n))
261
+ return;
262
+ const parent = ancestors[ancestors.length - 1];
263
+ if (parent && (t.isMemberExpression(parent.node) || t.isOptionalMemberExpression(parent.node)) && parent.key === 'property' && !parent.node.computed)
264
+ return;
265
+ if (parent && (t.isObjectProperty(parent.node) || t.isObjectMethod(parent.node)) && parent.key === 'key' && !parent.node.computed)
266
+ return;
267
+ if (inside.has(n.name) || moduleNames.has(n.name) || isGlobal(n.name))
268
+ return;
269
+ const own = comp.refs.get(n);
270
+ if (own === undefined || !comp.bindings.has(own))
271
+ ok = false;
272
+ });
273
+ return ok;
274
+ }
275
+ /**
276
+ * The kept markup of a component this module can write through the bank, planned without changing anything; null when
277
+ * there is none. `moduleNames`: every name the module declares or imports; `callbackInputs`: the callback props (by
278
+ * key) the component takes as function inputs rather than outputs (it tests them, or uses what they return); `inlined`:
279
+ * the private components the module writes in place where they are used.
280
+ */
281
+ export function planKeptValues(mod, comp, oracle, moduleNames, isGlobal, callbackInputs, inlined) {
282
+ if (!oracle)
283
+ return null;
284
+ // callback props that are outputs: the class reads their names as the output, not a function
285
+ const outputs = new Set(comp.props.filter((p) => p.kind === 'event' && !callbackInputs.has(p.key)).map((p) => p.local));
286
+ const kept = (comp.keptMarkup ?? []).filter((k) => k.kind === 'value' && (k.item.kind === 'block' || k.item.kind === 'derived'));
287
+ // markup the template renders in place from an expression (`{(() => { … return <div/>; })()}`): a member of its own
288
+ const sites = [];
289
+ const taken = new Set([...comp.bindings.keys(), ...moduleNames]);
290
+ for (const s of keptSites(comp.template)) {
291
+ const entry = comp.keptMarkup?.find((k) => k.kind === 'expression' && k.id === s.id);
292
+ if (s.node === comp.template || !entry || !readsOnlyClassNames(entry.expr, comp, moduleNames, isGlobal))
293
+ continue;
294
+ // the branch tests the place sits under are written into the member too (they narrow what the expression reads)
295
+ if (!s.guards.every((g) => [...g.before, ...(g.test ? [g.test] : [])].every((e) => readsOnlyClassNames(e, comp, moduleNames, isGlobal))))
296
+ continue;
297
+ // reading a kept value lowering did not hand back as code: not followed
298
+ if ((comp.keptMarkup ?? []).some((k) => k.kind === 'value' && readsAnyIn([entry.expr], new Set(k.names), comp)))
299
+ continue;
300
+ let name = 'view';
301
+ for (let i = 1; taken.has(name); i++)
302
+ name = `view${i + 1}`;
303
+ const pieces = bankPiecesOf(mod, comp, [entry.expr], `${comp.name}_${name}`, moduleNames, outputs, inlined);
304
+ if (!pieces)
305
+ continue;
306
+ taken.add(name);
307
+ sites.push({ kept: entry, node: s.node, name, pieces, guards: s.guards });
308
+ }
309
+ let writes = [];
310
+ for (const k of kept) {
311
+ if (k.after && !comp.items.includes(k.after))
312
+ continue;
313
+ const pieces = bankPiecesOf(mod, comp, codeOf(k.item), `${comp.name}_${namesOf(k.item)[0] ?? 'value'}`, moduleNames, outputs, inlined);
314
+ if (pieces)
315
+ writes.push({ kept: k, pieces });
316
+ }
317
+ // render helpers of the component read as values (`{cell(r, c)}`): functions of the class returning bank values
318
+ const helpers = [];
319
+ for (const k of comp.keptMarkup ?? []) {
320
+ if (k.kind !== 'value' || k.item.kind !== 'function' || (k.after && !comp.items.includes(k.after)))
321
+ continue;
322
+ const names = new Set([k.item.name]);
323
+ const reads = [];
324
+ let ok = true;
325
+ walk([comp.template, ...comp.fragments.map((f) => f.template)], (n) => {
326
+ for (const e of nodeExpressions(n)) {
327
+ if (!readsAnyIn([e], names, comp))
328
+ continue;
329
+ // a value node lowering kept, rendering the helper's value as it is (or one of two)
330
+ if (n.type === 'expr' && n.kept !== undefined && e === n.expr && onlyValueCalls(n.expr, names, comp))
331
+ reads.push(n);
332
+ else
333
+ ok = false;
334
+ }
335
+ });
336
+ // script code, or other kept code, reading it: not followed
337
+ if (comp.items.some((i) => readsAnyIn(itemCode(i), names, comp)))
338
+ ok = false;
339
+ if ((comp.keptMarkup ?? []).some((o) => o !== k && o.kind !== 'expression' && readsAnyIn(o.kind === 'value' ? codeOf(o.item) : [o.node], names, comp)))
340
+ ok = false;
341
+ if (!ok || !reads.length)
342
+ continue;
343
+ const pieces = bankPiecesOf(mod, comp, [k.item.node], `${comp.name}_${k.item.name}`, moduleNames, outputs, inlined);
344
+ if (pieces)
345
+ helpers.push({ kept: k, pieces, reads });
346
+ }
347
+ if (!writes.length && !sites.length && !helpers.length)
348
+ return null;
349
+ // the values made from the written ones (`out = outAndAt.out`, and values computed from those)
350
+ const carrying = new Set(writes.flatMap((w) => namesOf(w.kept.item)));
351
+ let grew = true;
352
+ while (grew) {
353
+ grew = false;
354
+ for (const item of comp.items) {
355
+ if (item.kind !== 'derived' && item.kind !== 'block')
356
+ continue;
357
+ if (namesOf(item).every((n) => carrying.has(n)) || !readsAnyIn(itemCode(item), carrying, comp))
358
+ continue;
359
+ for (const n of namesOf(item))
360
+ carrying.add(n);
361
+ grew = true;
362
+ }
363
+ }
364
+ // every template read of them: a child it renders (through the directive where it may be markup) or a test
365
+ const reads = [];
366
+ let stray = false;
367
+ const touches = (e) => readsAnyIn([e], carrying, comp);
368
+ walk([comp.template], (n) => {
369
+ if (n.type === 'expr') {
370
+ if (!touches(n.expr))
371
+ return;
372
+ const kind = oracle.elementKind(comp.file, n.expr.loc);
373
+ if (kind.element || kind.unknown)
374
+ reads.push(n);
375
+ return;
376
+ }
377
+ if (n.type === 'element') {
378
+ for (const a of n.attrs) {
379
+ const e = a.kind === 'event' ? a.handler : a.kind === 'static' || a.kind === 'bool' || a.kind === 'slotProp' ? null : a.expr;
380
+ if (e && touches(e))
381
+ stray = true;
382
+ }
383
+ return;
384
+ }
385
+ const other = n.type === 'for' ? [n.iterable, ...n.locals] : n.type === 'keyed' ? [n.key] : n.type === 'render' ? n.args : n.type === 'slot' ? (n.args ?? []) : n.type === 'presence' ? n.attrs.flatMap((a) => (a.kind === 'expr' ? [a.expr] : [])) : [];
386
+ if (other.some(touches))
387
+ stray = true;
388
+ });
389
+ // a fragment of the component (a render helper lowering wrote as a template of its own) reading them: not followed
390
+ if (comp.fragments.some((f) => { let hit = false; walk([f.template], (n) => { if (n.type === 'expr' && touches(n.expr))
391
+ hit = true; }); return hit; }))
392
+ stray = true;
393
+ // M4: a written value the template renders where lowering left it unconverted (`{chips}` of a block lowering kept)
394
+ const valueNodes = [];
395
+ walk([comp.template], (n) => {
396
+ if (n.type === 'unconverted' && n.value !== undefined && carrying.has(n.value))
397
+ valueNodes.push(n);
398
+ });
399
+ // M4: each written value must be rendered somewhere (a read or such a place), or it is not written: its error stays;
400
+ // nor when script code reads its elements (`const first = out[0]`: the class would hold bank values there, not
401
+ // React's elements; a block's own picks, `out = outAndAt.out`, and `.length` are fine)
402
+ writes = writes.filter((w) => !scriptReadsElements(comp, w.kept));
403
+ writes = writes.filter((w) => {
404
+ const names = new Set(namesOf(w.kept.item));
405
+ const made = [...carrying].filter((n) => !names.has(n));
406
+ return valueNodes.some((v) => v.value !== undefined && names.has(v.value)) || reads.some((r) => r.type === 'expr' && readsAnyIn([r.expr], new Set([...names, ...made]), comp));
407
+ });
408
+ if (stray || (!reads.length && !valueNodes.length) || !writes.length) {
409
+ writes = [];
410
+ reads.length = 0;
411
+ valueNodes.length = 0;
412
+ carrying.clear();
413
+ }
414
+ if (!writes.length && !sites.length && !helpers.length)
415
+ return null;
416
+ // inside banked markup, a value that may hold markup (`{note}` of a local holding an element) renders through the
417
+ // directive too
418
+ for (const p of [...writes, ...sites, ...helpers].flatMap((w) => w.pieces))
419
+ walk([p.template], (n) => {
420
+ if (n.type !== 'expr')
421
+ return;
422
+ const kind = oracle.elementKind(comp.file, n.expr.loc);
423
+ if (kind.element || kind.unknown)
424
+ reads.push(n);
425
+ });
426
+ return { comp, writes, reads, carrying, sites, helpers, valueNodes };
427
+ }
428
+ /**
429
+ * M4. A render helper that renders itself (a tree: `renderNode(node, depth)` whose markup calls `renderNode(child,
430
+ * depth + 1)` for each child), which a template cannot write in place: kept as a function of the component, as the
431
+ * bank writes the component's render helpers read as values (each element it returns a bank value, the class method
432
+ * returning them, each call rendered through the directive). Its calls in the component's template become value nodes
433
+ * calling it, and its error is reported here (`report`), so it stays when the bank cannot write the helper. Only a
434
+ * helper whose calls all sit in the component's own template (or its own markup), with the function it came from.
435
+ */
436
+ export function keepTreeHelpers(comp, report) {
437
+ for (const def of [...comp.fragments]) {
438
+ const source = fragmentSource(def);
439
+ if (!def.recursive || !source)
440
+ continue;
441
+ const calls = [];
442
+ walk([comp.template], (n) => {
443
+ if (n.type === 'render' && n.name === def.name)
444
+ calls.push(n);
445
+ });
446
+ let elsewhere = false;
447
+ for (const f of comp.fragments) {
448
+ if (f === def)
449
+ continue;
450
+ walk([f.template], (n) => {
451
+ if (n.type === 'render' && n.name === def.name)
452
+ elsewhere = true;
453
+ });
454
+ }
455
+ if (!calls.length || elsewhere || comp.bindings.has(def.name))
456
+ continue;
457
+ const diagnostic = report(`${def.name} renders itself (a tree); a template repeats itself only through a component.`, source.loc?.start.line);
458
+ comp.fragments.splice(comp.fragments.indexOf(def), 1);
459
+ comp.bindings.set(def.name, { name: def.name, kind: 'function', reactive: false });
460
+ const id = `tree:${def.name}`;
461
+ for (const c of calls) {
462
+ const callee = t.identifier(def.name);
463
+ comp.refs.set(callee, def.name);
464
+ const expr = t.callExpression(callee, c.args);
465
+ Reflect.deleteProperty(c, 'name');
466
+ Reflect.deleteProperty(c, 'args');
467
+ Object.assign(c, { type: 'expr', expr, kept: id });
468
+ }
469
+ // the helper's own call of itself inside its markup reads the class method, as the template's calls do
470
+ t.traverseFast(source, (n) => {
471
+ if (t.isIdentifier(n, { name: def.name }) && !comp.refs.has(n))
472
+ comp.refs.set(n, def.name);
473
+ });
474
+ (comp.keptMarkup ??= []).push({ kind: 'value', item: { kind: 'function', name: def.name, node: source }, names: [def.name], reactive: true, after: null, diagnostic: diagnostic });
475
+ }
476
+ }
477
+ /** M4. Whether a component item other than the value's own picks reads the value's entries (anything but `.length`). */
478
+ function scriptReadsElements(comp, kept) {
479
+ const names = new Set(kept.names);
480
+ const block = kept.item.kind === 'block' ? kept.item.name : null;
481
+ let found = false;
482
+ const visit = (n, parent) => {
483
+ if (found)
484
+ return;
485
+ // (by name too: lowering keeps no reference for a name it took out of the component's values; a local of the
486
+ // same name refuses, which only keeps the error)
487
+ if (t.isIdentifier(n) && (names.has(comp.refs.get(n) ?? '') || names.has(n.name))) {
488
+ const length = parent && (t.isMemberExpression(parent) || t.isOptionalMemberExpression(parent)) && parent.object === n && !parent.computed && t.isIdentifier(parent.property, { name: 'length' });
489
+ if (!length)
490
+ found = true;
491
+ return;
492
+ }
493
+ for (const key of t.VISITOR_KEYS[n.type] ?? []) {
494
+ const child = Reflect.get(n, key);
495
+ for (const c of Array.isArray(child) ? child : [child])
496
+ if (t.isNode(c))
497
+ visit(c, n);
498
+ }
499
+ };
500
+ for (const item of comp.items) {
501
+ // `parts = partsAndAt.parts`: a value the block gives out
502
+ if (block && kept.item.kind === 'block' && kept.item.members && item.kind === 'derived' && t.isMemberExpression(item.init) && !item.init.computed && t.isIdentifier(item.init.object) && comp.refs.get(item.init.object) === block)
503
+ continue;
504
+ for (const node of itemCode(item))
505
+ visit(node, null);
506
+ }
507
+ return found;
508
+ }
509
+ /** The code expressions a template node holds itself (not its children's). */
510
+ function nodeExpressions(n) {
511
+ switch (n.type) {
512
+ case 'expr':
513
+ return [n.expr];
514
+ case 'element':
515
+ return n.attrs.flatMap((a) => (a.kind === 'event' ? [a.handler] : a.kind === 'static' || a.kind === 'bool' || a.kind === 'slotProp' ? [] : [a.expr]));
516
+ case 'if':
517
+ return n.branches.flatMap((b) => (b.test ? [b.test] : []));
518
+ case 'for':
519
+ return [n.iterable, ...n.locals];
520
+ case 'keyed':
521
+ return [n.key];
522
+ case 'render':
523
+ return n.args;
524
+ case 'slot':
525
+ return n.args ?? [];
526
+ case 'presence':
527
+ return n.attrs.flatMap((a) => (a.kind === 'expr' ? [a.expr] : []));
528
+ default:
529
+ return [];
530
+ }
531
+ }
532
+ /** Whether every read of `names` in `e` is the callee of a call that is the value of `e` (or of one of its arms). */
533
+ function onlyValueCalls(e, names, comp) {
534
+ const values = new Set();
535
+ const arms = (x) => {
536
+ const n = unwrap(x);
537
+ values.add(n);
538
+ if (t.isConditionalExpression(n)) {
539
+ arms(n.consequent);
540
+ arms(n.alternate);
541
+ }
542
+ else if (t.isLogicalExpression(n))
543
+ arms(n.right);
544
+ };
545
+ arms(e);
546
+ let ok = true;
547
+ t.traverse(e, (n, ancestors) => {
548
+ if (!t.isIdentifier(n) || !names.has(comp.refs.get(n) ?? ''))
549
+ return;
550
+ const parent = ancestors[ancestors.length - 1];
551
+ if (parent && t.isCallExpression(parent.node) && parent.key === 'callee' && values.has(parent.node))
552
+ return;
553
+ // `PARTS[id].map(part)`: the helper called on each entry, the list of its values rendered as React renders an array
554
+ const call = parent?.node;
555
+ if (call && t.isCallExpression(call) && values.has(call) && parent.key === 'arguments' && call.arguments.length === 1 && call.arguments[0] === n && t.isMemberExpression(call.callee) && !call.callee.computed && t.isIdentifier(call.callee.property, { name: 'map' }))
556
+ return;
557
+ ok = false;
558
+ });
559
+ return ok;
560
+ }
561
+ /** A copy of a type with React's element types as the runtime's node type (the source's own node is left as it is). */
562
+ function nodeTypeOf(type, nodeType, reactNames) {
563
+ const copy = t.cloneNode(type, true);
564
+ asNodeTypes(copy, nodeType, reactNames);
565
+ return copy;
566
+ }
567
+ /** React's element types in a type (`ReactNode[]`, `React.ReactElement | null`) as the runtime's node type, in place. */
568
+ function asNodeTypes(root, nodeType, reactNames) {
569
+ t.traverseFast(root, (n) => {
570
+ if (!t.isTSTypeReference(n))
571
+ return;
572
+ const name = n.typeName;
573
+ const react = (t.isIdentifier(name) && reactNames.has(name.name)) || (t.isTSQualifiedName(name) && t.isIdentifier(name.left) && (name.left.name === 'React' || name.left.name === 'JSX'));
574
+ const base = t.isIdentifier(name) ? name.name : t.isTSQualifiedName(name) ? name.right.name : '';
575
+ if (!react || !/^(ReactNode|ReactElement|ReactChild|Element)$/.test(base))
576
+ return;
577
+ n.typeName = t.identifier(nodeType);
578
+ n.typeParameters = null;
579
+ });
580
+ }
581
+ /** Puts `next` where `old` sits among a template's children (the places keptSites visits). */
582
+ function replaceNode(root, old, next) {
583
+ const swap = (nodes) => {
584
+ const at = nodes.indexOf(old);
585
+ if (at >= 0)
586
+ nodes[at] = next;
587
+ for (const n of nodes) {
588
+ if (n.type === 'element')
589
+ swap(n.children);
590
+ else if (n.type === 'if')
591
+ for (const b of n.branches)
592
+ swap(b.children);
593
+ else if (n.type === 'fragment' || n.type === 'keyed' || n.type === 'presence')
594
+ swap(n.children);
595
+ }
596
+ };
597
+ swap([root]);
598
+ }
599
+ /** A copy of a code node with each node in `replace` swapped, keeping every identifier's link to its binding. */
600
+ function copyLinked(node, replace, refs) {
601
+ const copy = (n) => {
602
+ const swap = replace.get(n);
603
+ if (swap)
604
+ return swap;
605
+ const out = t.cloneNode(n, false);
606
+ const ref = refs.get(n);
607
+ if (ref !== undefined)
608
+ refs.set(out, ref);
609
+ for (const key of t.VISITOR_KEYS[n.type] ?? []) {
610
+ const v = Reflect.get(n, key);
611
+ if (Array.isArray(v))
612
+ Reflect.set(out, key, v.map((c) => (t.isNode(c) ? copy(c) : c)));
613
+ else if (t.isNode(v))
614
+ Reflect.set(out, key, copy(v));
615
+ }
616
+ return out;
617
+ };
618
+ const result = copy(node);
619
+ if (result.type !== node.type)
620
+ throw new Error('a node copies as its own kind');
621
+ return result;
622
+ }
623
+ /**
624
+ * Writes the planned values: each element in the code becomes its bank value, React's element types in the code the
625
+ * runtime's node type, the item goes back into the class's items where lowering took it from (computed again when what
626
+ * it reads changes), the values made from it follow it, the reads print through the directive, and lowering's error
627
+ * for the value is withdrawn. `reactNames`: the local names of React's types the module imports.
628
+ */
629
+ export function writeKeptValues(plan, markupFn, bank, nodeType, reactNames, diagnostics) {
630
+ const { comp } = plan;
631
+ const reactive = new Set();
632
+ const valuesOf = (pieces) => {
633
+ const replace = new Map();
634
+ for (const p of pieces) {
635
+ const ctx = t.objectExpression(p.params.map((name) => {
636
+ // a handler carried whole: written here, in class code, as React's code wrote it
637
+ const handler = p.lifted.get(name);
638
+ if (handler) {
639
+ const written = copyLinked(handler, new Map(), comp.refs);
640
+ // M4: its event parameter typed as React types it, then as the template's plain DOM event
641
+ const typed = handlerEvents.get(handler);
642
+ const param = (t.isArrowFunctionExpression(written) || t.isFunctionExpression(written)) && t.isIdentifier(written.params[0]) ? written.params[0] : null;
643
+ if (typed && param) {
644
+ param.typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType([t.tsTypeReference(t.identifier(typed.event)), t.tsTypeLiteral([t.tsPropertySignature(t.identifier('currentTarget'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(typed.element))))])]));
645
+ plainEventParams(written);
646
+ }
647
+ return t.objectProperty(t.identifier(name), written);
648
+ }
649
+ const value = t.identifier(name);
650
+ // the name read where the element read it (a prop or state of the component, or a variable of the code)
651
+ let at;
652
+ t.traverseFast(p.jsx, (n) => {
653
+ if (at === undefined && t.isIdentifier(n, { name }))
654
+ at = comp.refs.get(n);
655
+ });
656
+ if (at !== undefined)
657
+ comp.refs.set(value, at);
658
+ return t.objectProperty(t.identifier(name), value);
659
+ }));
660
+ const key = p.key ? copyLinked(p.key, new Map(), comp.refs) : null;
661
+ replace.set(p.jsx, t.callExpression(t.identifier(markupFn), [t.identifier(bank), t.stringLiteral(p.name), ctx, ...(key ? [key] : [])]));
662
+ }
663
+ return replace;
664
+ };
665
+ const withdraw = (d) => {
666
+ const found = diagnostics.indexOf(d);
667
+ if (found >= 0)
668
+ diagnostics.splice(found, 1);
669
+ };
670
+ // a template place rendering a kept expression: a member computed as React computes the expression on each render
671
+ // (an immediately called function is its body), printed through the directive where the place was
672
+ for (const s of plan.sites) {
673
+ const init = copyLinked(s.kept.expr, valuesOf(s.pieces), comp.refs);
674
+ asNodeTypes(init, nodeType, reactNames);
675
+ const called = t.isCallExpression(init) && !init.arguments.length && (t.isArrowFunctionExpression(init.callee) || t.isFunctionExpression(init.callee)) && !init.callee.params.length && !init.callee.async && !init.callee.generator ? init.callee : null;
676
+ // React evaluates the expression only inside the branches it sits in: the member returns nothing outside them (it is
677
+ // read only inside them), and their tests narrow its names as React's code had them narrowed
678
+ const guards = s.guards.flatMap((g) => [
679
+ ...g.before.map((e) => t.ifStatement(copyLinked(e, new Map(), comp.refs), t.returnStatement(t.nullLiteral()))),
680
+ ...(g.test ? [t.ifStatement(t.unaryExpression('!', copyLinked(g.test, new Map(), comp.refs)), t.returnStatement(t.nullLiteral()))] : []),
681
+ ]);
682
+ const body = called && t.isBlockStatement(called.body) ? called.body.body : null;
683
+ const value = called && t.isExpression(called.body) ? called.body : init;
684
+ const item = body || guards.length
685
+ ? { kind: 'block', name: s.name, statements: [...guards, ...(body ?? [t.returnStatement(value)])], type: null, returns: true }
686
+ : { kind: 'derived', id: t.identifier(s.name), names: [s.name], init: value, memo: false, type: null, declKind: 'const' };
687
+ comp.items.push(item);
688
+ comp.bindings.set(s.name, { name: s.name, kind: 'derived', reactive: s.kept.reactive });
689
+ const read = t.identifier(s.name);
690
+ comp.refs.set(read, s.name);
691
+ const node = { type: 'expr', expr: read };
692
+ replaceNode(comp.template, s.node, node);
693
+ BANK_READS.add(node);
694
+ withdraw(s.kept.diagnostic);
695
+ }
696
+ // a render helper whose value the template renders: a function of the class, each element a bank value
697
+ for (const h of plan.helpers) {
698
+ const item = h.kept.item;
699
+ if (item.kind !== 'function')
700
+ continue;
701
+ const node = copyLinked(item.node, valuesOf(h.pieces), comp.refs);
702
+ asNodeTypes(node, nodeType, reactNames);
703
+ const at = h.kept.after ? comp.items.indexOf(h.kept.after) + 1 : 0;
704
+ comp.items.splice(at, 0, { ...item, node });
705
+ for (const r of h.reads) {
706
+ BANK_READS.add(r);
707
+ const entry = comp.keptMarkup?.find((k) => k.kind === 'expression' && k.id === r.kept);
708
+ if (entry)
709
+ withdraw(entry.diagnostic);
710
+ }
711
+ withdraw(h.kept.diagnostic);
712
+ }
713
+ for (const w of plan.writes) {
714
+ const replace = valuesOf(w.pieces);
715
+ const item = w.kept.item;
716
+ let written;
717
+ // (React's element types in the copied code, `const out: ReactNode[] = []`, are the runtime's node)
718
+ if (item.kind === 'block') {
719
+ written = { ...item, statements: item.statements.map((s) => copyLinked(s, replace, comp.refs)), type: item.type ? nodeTypeOf(item.type, nodeType, reactNames) : null };
720
+ for (const s of written.statements)
721
+ asNodeTypes(s, nodeType, reactNames);
722
+ }
723
+ else if (item.kind === 'derived') {
724
+ const init = copyLinked(item.init, replace, comp.refs);
725
+ asNodeTypes(init, nodeType, reactNames);
726
+ written = { ...item, init, type: item.type ? nodeTypeOf(item.type, nodeType, reactNames) : null };
727
+ }
728
+ else
729
+ continue;
730
+ const at = w.kept.after ? comp.items.indexOf(w.kept.after) + 1 : 0;
731
+ comp.items.splice(at, 0, written);
732
+ if (w.kept.reactive)
733
+ for (const n of namesOf(written))
734
+ reactive.add(n);
735
+ withdraw(w.kept.diagnostic);
736
+ }
737
+ // values computed from a reactive one are reactive too (lowering settled the bindings before the value was kept)
738
+ let grew = reactive.size > 0;
739
+ while (grew) {
740
+ grew = false;
741
+ for (const item of comp.items) {
742
+ if (item.kind !== 'derived' && item.kind !== 'block')
743
+ continue;
744
+ const names = namesOf(item);
745
+ if (names.every((n) => reactive.has(n)) || !readsAnyIn(itemCode(item), reactive, comp))
746
+ continue;
747
+ for (const n of names)
748
+ reactive.add(n);
749
+ grew = true;
750
+ }
751
+ }
752
+ for (const n of reactive) {
753
+ const b = comp.bindings.get(n);
754
+ if (b)
755
+ b.reactive = true;
756
+ }
757
+ // the values made from them keep their declared types, as the runtime's node where React named an element type
758
+ // a value a written block gives out that nothing reads (`at = outAndAt.at`, a loop's cursor) is no member of the class
759
+ const blocks = new Set(plan.writes.flatMap((w) => (w.kept.item.kind === 'block' ? [w.kept.item.name] : [])));
760
+ const pick = (item) => item.kind === 'derived' && t.isMemberExpression(item.init) && t.isIdentifier(item.init.object) && blocks.has(comp.refs.get(item.init.object) ?? '');
761
+ const templates = [comp.template, ...comp.fragments.map((f) => f.template)].flatMap((tpl) => templateExpressions(tpl));
762
+ for (const item of [...comp.items]) {
763
+ if (!pick(item))
764
+ continue;
765
+ const names = new Set(namesOf(item));
766
+ if (readsAnyIn(templates, names, comp) || comp.items.some((other) => other !== item && readsAnyIn(itemCode(other), names, comp)) || (comp.keptMarkup ?? []).some((k) => readsAnyIn(k.kind === 'value' ? itemCode(k.item) : [k.kind === 'statement' ? k.node : k.expr], names, comp)))
767
+ continue;
768
+ comp.items.splice(comp.items.indexOf(item), 1);
769
+ }
770
+ // (the item is this target's own lowering; its type node is the source's, so it is replaced by a copy)
771
+ for (const item of comp.items) {
772
+ if ((item.kind !== 'derived' && item.kind !== 'block') || !item.type || !namesOf(item).some((n) => plan.carrying.has(n)))
773
+ continue;
774
+ item.type = nodeTypeOf(item.type, nodeType, reactNames);
775
+ }
776
+ for (const r of plan.reads)
777
+ BANK_READS.add(r);
778
+ // M4: each unconverted place of a written value becomes a read of it, drawn through the directive
779
+ for (const v of plan.valueNodes) {
780
+ const name = v.value;
781
+ if (name === undefined)
782
+ continue;
783
+ const expr = t.identifier(name);
784
+ comp.refs.set(expr, name);
785
+ Reflect.deleteProperty(v, 'reason');
786
+ Reflect.deleteProperty(v, 'value');
787
+ Reflect.deleteProperty(v, 'kept');
788
+ const read = Object.assign(v, { type: 'expr', expr });
789
+ BANK_READS.add(read);
790
+ }
791
+ }