@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,867 @@
1
+ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
2
+ import { basename, dirname, join, resolve } from 'node:path';
3
+ import { makeProject } from '../analyzer/deps.js';
4
+ import { compileFile } from '../pipeline.js';
5
+ import { makeTempDir } from '../utils/cleanup.js';
6
+ import { writeInside } from '../utils/fs-safe.js';
7
+ import { MorphError } from '../utils/errors.js';
8
+ import { validateFiles } from '../validate.js';
9
+ import { compileAngular } from '../targets/angular/ngc.js';
10
+ import { bundleEntry, buildTailwind, themedAngularStyles } from './bundle.js';
11
+ import { launchBrowser, newSandboxPage, startServer } from './sandbox.js';
12
+ import { changedRegion, compare, decodePng, htmlReport, variance } from './diff.js';
13
+ import { LEAK_PROBE_SCRIPT, describeLeaks, noLeaks, readLeakReport, subtractLeaks } from './leaks.js';
14
+ import { StepError, checkSteps, collectFacts, describeMismatches, diffFacts, performStep } from './steps.js';
15
+ import { discoverSteps, resolveMaxSteps } from './auto-steps.js';
16
+ const MAX_PAGE_TIMEOUT = 10_000;
17
+ const MAX_TOTAL_TIMEOUT = 60_000;
18
+ /** virtual ms after unmount (past a few frames) for cleanups and one last timeout to run before the leak window opens */
19
+ const UNMOUNT_SETTLE_MS = 500;
20
+ /** the leak window lasts until every timeout pending when it opens is due, at most this many virtual ms */
21
+ const UNMOUNT_WINDOW_MS = 10_000;
22
+ /** The page each framework renders in: centred in the viewport, or, for a component that fills its box, given the whole viewport as its box. */
23
+ const PAGE_HTML = (framework, fill) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${framework}</title><link rel="stylesheet" href="tw.css"><link rel="stylesheet" href="${framework}.css"><style>html,body{margin:0;background:#ffffff}${fill ? '#root{position:fixed;inset:0;display:grid}' : '#root{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:32px;box-sizing:border-box}'}</style></head><body><div id="root"></div><script src="${framework}.js"></script></body></html>`;
24
+ /** The box of the component on a page: its first element, or what a host that lays out as nothing holds. */
25
+ function componentBox(page) {
26
+ return page.evaluate(() => {
27
+ const root = document.getElementById('root');
28
+ let el = root?.firstElementChild ?? root;
29
+ // a host element that lays out as nothing (Angular's, display: contents): measure what it holds
30
+ while (el && el !== root && getComputedStyle(el).display === 'contents' && el.firstElementChild)
31
+ el = el.firstElementChild;
32
+ const r = el?.getBoundingClientRect();
33
+ return { x: r?.x ?? 0, y: r?.y ?? 0, width: r?.width ?? 0, height: r?.height ?? 0 };
34
+ });
35
+ }
36
+ /** The viewport as a PNG, and the component's box. */
37
+ async function shootPage(page, width, height) {
38
+ return { png: await page.screenshot({ clip: { x: 0, y: 0, width, height }, animations: 'allow', caret: 'hide' }), box: await componentBox(page) };
39
+ }
40
+ function isBlank(shot, v) {
41
+ return v === 0 || shot.box.width === 0 || shot.box.height === 0;
42
+ }
43
+ /**
44
+ * Unmounts the component on a rendered page and returns what is still running: a few frames and a short settle let the
45
+ * cleanups run (and one last frame or timeout fire), then the window opens and lasts until every pending timeout is due
46
+ * (at most UNMOUNT_WINDOW_MS), then three more frames show which requestAnimationFrame loops are still going.
47
+ */
48
+ async function measureUnmount(page, run) {
49
+ const advance = async (ms) => {
50
+ await page.evaluate((m) => window.__morphClock?.advance(m), ms);
51
+ run.alive();
52
+ };
53
+ const elapse = async (ms) => {
54
+ await page.evaluate((m) => window.__morphClock?.elapse(m), ms);
55
+ run.alive();
56
+ };
57
+ await page.evaluate(async () => {
58
+ if (!window.__morphUnmount)
59
+ throw new Error('the page has no unmount');
60
+ await window.__morphUnmount();
61
+ });
62
+ run.alive();
63
+ await advance(64);
64
+ await elapse(UNMOUNT_SETTLE_MS);
65
+ await advance(32);
66
+ const horizon = await page.evaluate(() => {
67
+ if (!window.__morphLeaks)
68
+ throw new Error('the leak probe is not installed');
69
+ window.__morphLeaks.mark();
70
+ return window.__morphLeaks.horizon();
71
+ });
72
+ run.alive();
73
+ await elapse(Math.min(Math.max(0, horizon), UNMOUNT_WINDOW_MS) + 1);
74
+ await advance(48);
75
+ const report = await page.evaluate(() => window.__morphLeaks?.report() ?? null);
76
+ run.alive();
77
+ return readLeakReport(report);
78
+ }
79
+ /** An empty component in each framework: what it leaves after unmount is the framework runtime's own. */
80
+ const EMPTY_COMPONENTS = {
81
+ react: { path: 'MorphEmpty.js', contents: "import { createElement } from 'react';\nexport function MorphEmpty() { return createElement('div'); }\n" },
82
+ vue: { path: 'MorphEmpty.vue', contents: "<script setup lang=\"ts\">\ndefineOptions({ name: 'MorphEmpty' });\n</script>\n\n<template>\n <div></div>\n</template>\n" },
83
+ svelte: { path: 'MorphEmpty.svelte', contents: '<div></div>\n' },
84
+ angular: { path: 'morph-empty.ts', contents: "import { ChangeDetectionStrategy, Component } from '@angular/core';\n\n@Component({ selector: 'morph-empty', changeDetection: ChangeDetectionStrategy.OnPush, template: '<div></div>' })\nexport class MorphEmpty {}\n" },
85
+ };
86
+ /** Each framework runtime's own leftovers (the same for every component, so measured once per process). */
87
+ const runtimeLeftovers = new Map();
88
+ /**
89
+ * Mounts and unmounts an empty component in `framework`, driven the way the component's page was (settle, hover,
90
+ * press), and measures what is left: the runtime's own listeners and timers, which are not the component's.
91
+ */
92
+ async function runtimeBaseline(framework, b) {
93
+ // driven like the component's page: with or without a hover and a press
94
+ const key = `${framework}:${b.states.includes('hover') || b.states.includes('active') ? 'hover' : ''}${b.states.includes('active') ? 'active' : ''}`;
95
+ const cached = runtimeLeftovers.get(key);
96
+ if (cached)
97
+ return cached;
98
+ const empty = EMPTY_COMPONENTS[framework];
99
+ const src = join(b.temp, `empty-src-${framework}`);
100
+ let file = writeInside(src, empty.path, empty.contents);
101
+ if (framework === 'angular') {
102
+ const { outputs, problems } = await compileAngular([{ path: empty.path, contents: empty.contents, kind: 'component' }], true);
103
+ b.run.alive();
104
+ if (problems.length)
105
+ throw new Error(`the empty Angular component did not compile: ${problems[0]?.message}`);
106
+ for (const [rel, code] of outputs)
107
+ writeInside(join(b.temp, 'empty-js-angular'), rel, code);
108
+ file = join(b.temp, 'empty-js-angular', empty.path.replace(/\.ts$/, '.js'));
109
+ }
110
+ const dir = `empty-${framework}`;
111
+ const out = join(b.www, dir);
112
+ mkdirSync(out, { recursive: true });
113
+ const { css } = await bundleEntry({ framework, file, exportName: 'MorphEmpty', props: {}, children: null, outDir: out, project: b.project, nextFonts: [], unmount: true, oneTimeWork: (phase) => b.run.excuse(phase) }, b.run.signal);
114
+ b.run.alive();
115
+ if (!css)
116
+ writeFileSync(join(out, `${framework}.css`), '');
117
+ writeFileSync(join(out, 'tw.css'), '');
118
+ writeFileSync(join(out, `${framework}.html`), PAGE_HTML(framework, false));
119
+ const sp = await newSandboxPage(b.browser, b.origin, b.width, b.height, b.pageTimeout, LEAK_PROBE_SCRIPT);
120
+ const page = sp.page;
121
+ // every step, then the run's check
122
+ const then = async (step) => {
123
+ await step;
124
+ b.run.alive();
125
+ };
126
+ const advance = (ms) => then(page.evaluate((m) => window.__morphClock?.advance(m), ms));
127
+ try {
128
+ b.run.alive();
129
+ await then(page.goto(`${b.origin}/${dir}/${framework}.html`, { waitUntil: 'load' }));
130
+ await then(page.waitForFunction(() => window.__morphReady === true, undefined, { timeout: b.pageTimeout }));
131
+ await advance(b.settle);
132
+ if (b.states.includes('hover') || b.states.includes('active')) {
133
+ await then(page.mouse.move(b.width / 2, b.height / 2));
134
+ await advance(b.step);
135
+ }
136
+ if (b.states.includes('active')) {
137
+ await then(page.mouse.down());
138
+ await advance(Math.round(b.step / 2));
139
+ await then(page.mouse.up());
140
+ }
141
+ const counts = await measureUnmount(page, b.run);
142
+ // a runtime baseline taken on a page that threw is no baseline
143
+ if (sp.errors.length)
144
+ throw new Error(`the empty ${framework} page reported errors: ${sp.errors.slice(0, 2).join(' | ')}`);
145
+ runtimeLeftovers.set(key, counts);
146
+ return counts;
147
+ }
148
+ finally {
149
+ await sp.context.close().catch(() => undefined);
150
+ }
151
+ }
152
+ /** The Angular file that declares a component class (Angular files hold every component of a source file). */
153
+ export function angularComponentFile(files, exportName) {
154
+ const pattern = new RegExp(`\\bclass ${exportName}\\b`);
155
+ return files.find((f) => f.path.endsWith('.ts') && pattern.test(f.contents))?.path ?? null;
156
+ }
157
+ /**
158
+ * The text of each stylesheet the emitted Angular components name (`styleUrl: './theme.css'`, `styleUrls: [...]`),
159
+ * resolved beside the component file, in the order they are named, each once; a name that is not an emitted file is
160
+ * skipped (the Angular compiler reports it).
161
+ */
162
+ export function angularStylesheets(files) {
163
+ const byPath = new Map(files.map((f) => [f.path.replace(/\\/g, '/'), f.contents]));
164
+ const seen = new Set();
165
+ const out = [];
166
+ for (const f of files) {
167
+ if (!f.path.endsWith('.ts'))
168
+ continue;
169
+ const dir = dirname(f.path.replace(/\\/g, '/'));
170
+ for (const m of f.contents.matchAll(/\bstyleUrls?\s*:\s*(\[[^\]]*\]|'[^']*'|"[^"]*")/g)) {
171
+ for (const name of (m[1] ?? '').matchAll(/'([^']*)'|"([^"]*)"/g)) {
172
+ const rel = name[1] ?? name[2] ?? '';
173
+ const parts = [];
174
+ for (const p of `${dir === '.' ? '' : `${dir}/`}${rel}`.split('/')) {
175
+ if (p === '..')
176
+ parts.pop();
177
+ else if (p && p !== '.')
178
+ parts.push(p);
179
+ }
180
+ const key = parts.join('/');
181
+ const text = byPath.get(key);
182
+ if (text === undefined || seen.has(key))
183
+ continue;
184
+ seen.add(key);
185
+ out.push(text);
186
+ }
187
+ }
188
+ }
189
+ return out;
190
+ }
191
+ /** The component file a target emitted for an export: the .vue/.svelte named after it, nearest the source. */
192
+ export function componentFile(files, exportName, ext, sourceRel) {
193
+ const wanted = `${exportName}${ext}`;
194
+ const dir = dirname(sourceRel).replace(/\\/g, '/');
195
+ // a source at the project root has dirname '.', which no emitted path starts with
196
+ const prefix = dir === '.' ? '' : `${dir}/`;
197
+ const matches = files.filter((f) => f.kind === 'component' && basename(f.path) === wanted && f.path.startsWith(prefix));
198
+ matches.sort((a, b) => a.path.length - b.path.length);
199
+ return matches[0]?.path ?? null;
200
+ }
201
+ /** next/font loader names anywhere in the compiled graph (the React bundle gets matching shims). */
202
+ function nextFontNames(root, graph) {
203
+ const names = new Set();
204
+ for (const rel of graph) {
205
+ if (rel.endsWith('.css'))
206
+ continue;
207
+ const code = readFileSync(join(root, rel), 'utf8');
208
+ for (const m of code.matchAll(/import\s*\{([^}]*)\}\s*from\s*['"]next\/font\/google['"]/g)) {
209
+ for (const part of (m[1] ?? '').split(',')) {
210
+ const name = part.trim().split(/\s+as\s+/)[0]?.trim();
211
+ if (name)
212
+ names.add(name);
213
+ }
214
+ }
215
+ }
216
+ return [...names];
217
+ }
218
+ /**
219
+ * Renders the React original and its Vue 3 and Svelte 5 output in sandboxed headless Chrome, at rest and after a hover
220
+ * and a press stepped on a virtual clock, and compares each against React pixel by pixel.
221
+ */
222
+ export async function runVerify(file, options = {}) {
223
+ const pageTimeout = Math.min(options.pageTimeoutMs ?? MAX_PAGE_TIMEOUT, MAX_PAGE_TIMEOUT);
224
+ const totalTimeout = Math.min(options.totalTimeoutMs ?? MAX_TOTAL_TIMEOUT, MAX_TOTAL_TIMEOUT);
225
+ const run = new VerifyRun();
226
+ let cancel;
227
+ const timeout = new Promise((_, reject) => {
228
+ cancel = armTotalClock(totalTimeout, MAX_EXCUSED_MS, () => run.takeExcused(), (message) => {
229
+ const error = new MorphError('verify-timeout', message);
230
+ // stopped before the caller hears of it: the run's next step (and any build in flight) sees it first
231
+ run.stop(error);
232
+ reject(error);
233
+ });
234
+ });
235
+ let result;
236
+ try {
237
+ result = await Promise.race([verifyInner(file, options, pageTimeout, run), timeout]);
238
+ return result;
239
+ }
240
+ finally {
241
+ cancel?.();
242
+ const failures = await run.close();
243
+ // a cleanup that failed stays registered with the process-exit cleanup (utils/cleanup), which tries it again; a
244
+ // finished run also says so in its result. A failed or stopped run already rejects with its own error.
245
+ if (failures.length && result)
246
+ result.diagnostics.push({ code: 'cleanup-failed', severity: 'warning', message: `verify could not close everything it opened: ${failures.join('; ')}` });
247
+ }
248
+ }
249
+ /**
250
+ * The most a run's total clock leaves out for waits on once-per-process work (VerifyRun.excuse). Measured worst cases:
251
+ * linking `@lucide/angular` held the main thread 32.6 s on a cold start, and took 66 s on the linker's own thread on a
252
+ * loaded machine; 180 s is a generous multiple of both. Past it the clock fires as before, so a linker thread that is
253
+ * alive but never answers cannot hang verify.
254
+ */
255
+ export const MAX_EXCUSED_MS = 180_000;
256
+ /**
257
+ * Starts a run's total clock: after `totalMs`, `fire` is called with the timeout's message, unless `takeExcused` reports
258
+ * time the run waited on once-per-process work, which postpones it by that much, up to `allowanceMs` in all. Returns a
259
+ * function that stops the clock.
260
+ */
261
+ export function armTotalClock(totalMs, allowanceMs, takeExcused, fire) {
262
+ let granted = 0;
263
+ let exhausted = false;
264
+ let timer;
265
+ const arm = (ms) => {
266
+ timer = setTimeout(() => {
267
+ const asked = takeExcused();
268
+ const grant = Math.min(asked, allowanceMs - granted);
269
+ if (grant > 0) {
270
+ granted += grant;
271
+ arm(grant);
272
+ return;
273
+ }
274
+ if (asked > 0)
275
+ exhausted = true;
276
+ fire(exhausted
277
+ ? `verify took longer than ${totalMs / 1000}s and was stopped: the wait on once-per-process work (the Angular linker) exceeded its allowance of ${allowanceMs / 1000}s`
278
+ : `verify took longer than ${totalMs / 1000}s and was stopped`);
279
+ }, ms);
280
+ };
281
+ arm(totalMs);
282
+ return () => {
283
+ if (timer)
284
+ clearTimeout(timer);
285
+ };
286
+ }
287
+ /**
288
+ * One verify run and everything it opened. A timeout cannot halt code that is running, so the abandoned run goes on in
289
+ * the background until its next step: every step checks `alive()` first (and bundles get the abort signal, which
290
+ * cancels the build in flight), so after `stop` it writes nothing and starts nothing. Whatever it had already started
291
+ * when it was stopped (a browser still launching, a server) is closed the moment it is handed to `own`.
292
+ */
293
+ class VerifyRun {
294
+ controller = new AbortController();
295
+ disposers = [];
296
+ closed = false;
297
+ excused = 0;
298
+ waits = 0;
299
+ waitingSince = 0;
300
+ /**
301
+ * Leaves a wait out of the run's total clock, from 'start' to 'end': time a build waits on work done once per process,
302
+ * whoever asks first (the Angular linker's first link of a library, over 30 s for `@lucide/angular` on a cold start).
303
+ * The page clocks never include it: every bundle is built before its pages load.
304
+ */
305
+ excuse(phase) {
306
+ if (phase === 'start') {
307
+ if (this.waits++ === 0)
308
+ this.waitingSince = Date.now();
309
+ }
310
+ else if (this.waits > 0 && --this.waits === 0)
311
+ this.excused += Date.now() - this.waitingSince;
312
+ }
313
+ /** The time excused since the last call; during a wait, at least a second (the clock looks again then). */
314
+ takeExcused() {
315
+ let ms = this.excused;
316
+ this.excused = 0;
317
+ if (this.waits > 0) {
318
+ const now = Date.now();
319
+ ms = Math.max(1000, ms + now - this.waitingSince);
320
+ this.waitingSince = now;
321
+ }
322
+ return ms;
323
+ }
324
+ get signal() {
325
+ return this.controller.signal;
326
+ }
327
+ stop(reason) {
328
+ if (!this.controller.signal.aborted)
329
+ this.controller.abort(reason);
330
+ }
331
+ /** Throws the reason the run was stopped; call it after every await, before the next step touches disk or starts anything. */
332
+ alive() {
333
+ this.controller.signal.throwIfAborted();
334
+ }
335
+ /** Registers something to close when the run ends (closed newest first); after the end, closes it at once. */
336
+ own(dispose) {
337
+ if (!this.closed) {
338
+ this.disposers.push(dispose);
339
+ return;
340
+ }
341
+ // the run was over before this finished starting: nobody is left to use it
342
+ void dispose().catch(() => undefined);
343
+ }
344
+ /**
345
+ * Stops the run (if it is still going) and closes what it opened, newest first: browser, then server, then the
346
+ * temporary folder. Returns what could not be closed.
347
+ */
348
+ async close() {
349
+ this.stop(new MorphError('verify-stopped', 'verify had already ended'));
350
+ this.closed = true;
351
+ const failures = [];
352
+ for (const dispose of this.disposers.splice(0).reverse()) {
353
+ await dispose().catch((error) => {
354
+ failures.push(error instanceof Error ? error.message : String(error));
355
+ });
356
+ }
357
+ return failures;
358
+ }
359
+ }
360
+ /**
361
+ * Takes each framework runtime's own leftovers off what its page left, then holds every target to React: a target is
362
+ * clean when it leaves nothing React does not leave for the same component. What React leaves is the original's own
363
+ * (its source's, or a library's that keeps one listener per page), and is said so, never hidden.
364
+ */
365
+ /** `a` with the page-wide leftovers of `b` added (listeners not on an element, observers, frames and timers). */
366
+ function addPageWide(a, b) {
367
+ const pageWide = (target) => target === 'window' || target === 'document' || target === 'visualViewport' || target.startsWith('matchMedia(');
368
+ const listeners = a.listeners.map((l) => ({ ...l }));
369
+ for (const l of b.listeners) {
370
+ if (!pageWide(l.target))
371
+ continue;
372
+ const same = listeners.find((x) => x.target === l.target && x.type === l.type);
373
+ if (same)
374
+ same.count += l.count;
375
+ else
376
+ listeners.push({ ...l });
377
+ }
378
+ const observers = a.observers.map((o) => ({ ...o }));
379
+ for (const o of b.observers) {
380
+ const same = observers.find((x) => x.kind === o.kind);
381
+ if (same)
382
+ same.count += o.count;
383
+ else
384
+ observers.push({ ...o });
385
+ }
386
+ return { raf: a.raf + b.raf, intervals: a.intervals + b.intervals, timeouts: a.timeouts + b.timeouts, listeners, observers };
387
+ }
388
+ async function unmountLeaks(leftovers, b, diagnostics, unmountFailed) {
389
+ const measured = new Map();
390
+ for (const [framework, raw] of leftovers) {
391
+ try {
392
+ let runtime = await runtimeBaseline(framework, b);
393
+ b.run.alive();
394
+ // a page that also runs React (bridge mode: a wrapper mounts the React original) carries React's runtime too: its
395
+ // page-wide leftovers (on window, document, visualViewport, matchMedia), as measured for React's own page
396
+ if (framework !== 'react' && b.reactRuntime?.has(framework)) {
397
+ runtime = addPageWide(runtime, await runtimeBaseline('react', b));
398
+ b.run.alive();
399
+ }
400
+ measured.set(framework, { counts: subtractLeaks(raw, runtime), runtime });
401
+ }
402
+ catch (error) {
403
+ b.run.alive();
404
+ unmountFailed(framework, `the ${framework} runtime's own leftovers could not be measured: ${(error instanceof Error ? error.message : String(error)).split('\n').slice(0, 2).join(' ')}`);
405
+ }
406
+ }
407
+ const react = measured.get('react')?.counts ?? null;
408
+ const out = [];
409
+ for (const [framework, { counts, runtime }] of measured) {
410
+ if (framework === 'react') {
411
+ const clean = noLeaks(counts);
412
+ if (!clean)
413
+ diagnostics.push({ code: 'react-unmount-leak', severity: 'warning', message: `the React original itself leaves this running after unmount (its source, or a library it uses, never tears it down; not the conversion's doing): ${describeLeaks(counts)}` });
414
+ out.push({ framework, ...counts, runtime, beyondReact: null, clean });
415
+ continue;
416
+ }
417
+ const beyondReact = react ? subtractLeaks(counts, react) : null;
418
+ const clean = beyondReact !== null && noLeaks(beyondReact);
419
+ if (beyondReact && !clean)
420
+ diagnostics.push({ code: 'unmount-leak', severity: 'error', message: `${framework} leaves this running after unmount that React does not: ${describeLeaks(beyondReact)}`, target: framework });
421
+ if (!react)
422
+ diagnostics.push({ code: 'unmount-unmeasured', severity: 'error', message: `${framework}: React could not be measured after unmount, so nothing can be held to it`, target: framework });
423
+ out.push({ framework, ...counts, runtime, beyondReact, clean });
424
+ }
425
+ return out;
426
+ }
427
+ async function verifyInner(file, options, pageTimeout, run) {
428
+ const entry = resolve(file);
429
+ const project = makeProject(entry, options);
430
+ const targets = options.targets ?? ['vue', 'svelte'];
431
+ const states = options.states ?? ['idle', 'hover', 'active'];
432
+ const width = options.width ?? 480;
433
+ const height = options.height ?? 320;
434
+ const settle = options.settleMs ?? 800;
435
+ const step = options.stepMs ?? 300;
436
+ const leakCheck = options.unmount === true;
437
+ let steps = options.steps ?? [];
438
+ // a script is checked before anything is compiled or rendered: a bad one is the caller's error, not a target's
439
+ if (steps.length)
440
+ checkSteps(steps);
441
+ // auto-steps (v0.2 M1): only without a given script; its option is checked up front like a script
442
+ const autoMax = options.steps === undefined ? resolveMaxSteps(options.autoSteps) : 0;
443
+ const props = { ...(options.props ?? {}) };
444
+ const children = typeof props['children'] === 'string' ? props['children'] : null;
445
+ delete props['children'];
446
+ const temp = makeTempDir();
447
+ run.own(temp.dispose);
448
+ const reuse = options.compiled && targets.every((t) => options.compiled?.targets.some((x) => x.target === t)) ? options.compiled : null;
449
+ // verify measures pixels: the output must pass its compiler (validate), but the type check is not needed here, and its
450
+ // cold start (TypeScript, Volar, svelte2tsx) would come out of the render budget
451
+ const compiled = reuse ? { ...reuse, targets: reuse.targets.filter((x) => targets.includes(x.target)) } : await compileFile(entry, { ...options, targets, validate: true, typecheck: false, signal: run.signal });
452
+ run.alive();
453
+ const diagnostics = compiled.targets.flatMap((tr) => tr.diagnostics.filter((d) => d.severity === 'error'));
454
+ const exportName = options.exportName ?? compiled.analysis.components.find((c) => c.isDefault)?.name ?? compiled.analysis.components.find((c) => c.exported)?.name ?? compiled.analysis.components[0]?.name;
455
+ if (!exportName)
456
+ throw new MorphError('no-component', `${compiled.file} has no component to render.`);
457
+ const www = join(temp.dir, 'www');
458
+ mkdirSync(www, { recursive: true });
459
+ const nextFonts = nextFontNames(project.root, compiled.analysis.graph);
460
+ const frameworks = [{ framework: 'react', file: entry }];
461
+ // targets whose files mount React themselves (bridge mode): their leak baseline includes React's runtime
462
+ const reactRuntime = new Set();
463
+ // the stylesheets the Angular components name (styleUrl), which the Angular compiler inlines as they are written
464
+ let angularSheets = [];
465
+ for (const tr of compiled.targets) {
466
+ if (tr.target === 'react-native')
467
+ continue;
468
+ const out = join(temp.dir, tr.target);
469
+ const override = options.files?.[tr.target];
470
+ const files = override ?? tr.files;
471
+ // Angular files given in place of the output are checked by the Angular compiler below (validateFiles has no
472
+ // Angular check: it would read them as React Native code)
473
+ const validated = override ? tr.target === 'angular' || validateFiles(override, tr.target).length === 0 : tr.validated;
474
+ if (files.some((f) => /from ['"]react-dom\/client['"]/.test(f.contents)))
475
+ reactRuntime.add(tr.target);
476
+ for (const f of files)
477
+ writeInside(out, f.path, f.contents);
478
+ const path = tr.target === 'angular' ? angularComponentFile(files, exportName) : componentFile(files, exportName, tr.target === 'vue' ? '.vue' : '.svelte', compiled.file);
479
+ if (!path || !validated) {
480
+ diagnostics.push({ code: 'verify-skipped', severity: 'error', message: `${tr.target}: ${path ? 'the output did not pass its compiler' : `no ${exportName} component was emitted`}, so it was not rendered.`, target: tr.target });
481
+ continue;
482
+ }
483
+ if (tr.target === 'angular') {
484
+ // Angular renders ahead-of-time compiled code: the real compiler's output is what gets bundled
485
+ const { outputs, problems } = await compileAngular(files, true, project.root);
486
+ run.alive();
487
+ if (problems.length) {
488
+ diagnostics.push({ code: 'verify-skipped', severity: 'error', message: `angular: ${problems[0]?.path}: ${problems[0]?.message}`, target: 'angular' });
489
+ continue;
490
+ }
491
+ const js = join(temp.dir, 'angular-js');
492
+ for (const [rel, code] of outputs)
493
+ writeInside(js, rel, code);
494
+ frameworks.push({ framework: 'angular', file: join(js, path.replace(/\.ts$/, '.js')) });
495
+ angularSheets = angularStylesheets(files);
496
+ continue;
497
+ }
498
+ frameworks.push({ framework: tr.target, file: join(out, path) });
499
+ }
500
+ const bundles = [];
501
+ // one framework that fails to build or render is that target's failure, reported, not the end of the run: the others
502
+ // (and React, which every comparison needs) still render. Only React failing stops verify.
503
+ const failed = new Set();
504
+ const fail = (framework, message) => {
505
+ if (framework === 'react')
506
+ throw new MorphError('render-failed', message);
507
+ failed.add(framework);
508
+ diagnostics.push({ code: 'render-failed', severity: 'error', message, target: framework });
509
+ };
510
+ for (const fw of frameworks) {
511
+ try {
512
+ const { js, css } = await bundleEntry({ framework: fw.framework, file: fw.file, exportName, props, children, outDir: www, project, nextFonts, ...(options.probe ? { probe: options.probe } : {}), ...(leakCheck ? { unmount: true } : {}), ...(options.fonts ? { fonts: true } : {}), oneTimeWork: (phase) => run.excuse(phase) }, run.signal);
513
+ run.alive();
514
+ bundles.push(readFileSync(js, 'utf8'));
515
+ if (!css)
516
+ writeFileSync(join(www, `${fw.framework}.css`), '');
517
+ // an Angular stylesheet with a Tailwind `@theme` gets the Tailwind build every other bundle's CSS gets (an Angular
518
+ // CLI build with Tailwind compiles component stylesheets too); one without `@theme` changes nothing
519
+ if (fw.framework === 'angular' && !css) {
520
+ const themed = await themedAngularStyles(angularSheets, readFileSync(js, 'utf8'));
521
+ run.alive();
522
+ if (themed !== null)
523
+ writeFileSync(join(www, 'angular.css'), themed);
524
+ }
525
+ writeFileSync(join(www, `${fw.framework}.html`), PAGE_HTML(fw.framework, options.fill ?? false));
526
+ }
527
+ catch (error) {
528
+ if (error instanceof MorphError)
529
+ throw error;
530
+ fail(fw.framework, `${fw.framework} did not build: ${(error instanceof Error ? error.message : String(error)).split('\n').slice(0, 2).join(' ')}`);
531
+ }
532
+ }
533
+ const tailwind = await buildTailwind(bundles);
534
+ run.alive();
535
+ writeFileSync(join(www, 'tw.css'), tailwind);
536
+ // owned before the check: a server or browser that finished starting after the stop is closed, not left running
537
+ const server = await startServer(www, options.assetsDir ? resolve(options.assetsDir) : null);
538
+ run.own(server.close);
539
+ run.alive();
540
+ const browser = await launchBrowser(options.executablePath);
541
+ run.own(browser.close);
542
+ run.alive();
543
+ const shots = new Map();
544
+ const blocked = [];
545
+ const pageErrors = [];
546
+ let discoveredSteps = null;
547
+ if (autoMax > 0) {
548
+ // the script is discovered on a fresh React page of its own; the pages that are compared never see discovery
549
+ const sp = await newSandboxPage(browser.browser, server.origin, width, height, pageTimeout);
550
+ try {
551
+ run.alive();
552
+ try {
553
+ await sp.page.goto(`${server.origin}/react.html`, { waitUntil: 'load' });
554
+ run.alive();
555
+ await sp.page.waitForFunction(() => window.__morphReady === true, undefined, { timeout: pageTimeout });
556
+ run.alive();
557
+ }
558
+ catch (error) {
559
+ run.alive();
560
+ fail('react', `react: the auto-steps page did not render within ${pageTimeout / 1000}s: ${sp.errors.length ? sp.errors.slice(0, 3).join(' | ') : firstLine(error)}`);
561
+ }
562
+ await sp.page.evaluate((m) => window.__morphClock?.advance(m) ?? Promise.resolve(0), settle);
563
+ run.alive();
564
+ const found = await discoverSteps(sp, { maxSteps: autoMax, stepMs: step, width, height, alive: () => run.alive() });
565
+ discoveredSteps = found.steps;
566
+ // what discovery found is held to the same check as a script given by hand
567
+ if (found.steps.length)
568
+ checkSteps(found.steps);
569
+ steps = found.steps;
570
+ diagnostics.push(found.steps.length
571
+ ? { code: 'auto-steps', severity: 'info', message: `${found.steps.length} step(s) discovered on the React page (${found.attempts} tried${found.animated ? '; the page moves on its own, so a change was judged on the DOM facts alone' : ''}).` }
572
+ : { code: 'auto-steps-none', severity: 'warning', message: `no control on the React page changed its render or its DOM state (${found.attempts} tried), so no step was discovered.` });
573
+ }
574
+ finally {
575
+ blocked.push(...sp.blocked);
576
+ pageErrors.push(...sp.errors.map((e) => `react: auto-steps: ${e}`));
577
+ await sp.context.close().catch(() => undefined);
578
+ }
579
+ }
580
+ // with the leak check: what each framework's page still runs after unmount, before the runtime's share is taken off
581
+ const leftovers = new Map();
582
+ const unmountFailed = (framework, message) => {
583
+ diagnostics.push({ code: 'unmount-failed', severity: 'error', message: `${framework}: the unmount leak check could not run: ${message}`, ...(framework === 'react' ? {} : { target: framework }) });
584
+ };
585
+ // with steps: each framework's run of the script, and how many steps React itself could carry out (a step React
586
+ // cannot carry out is the script's error, and no target is asked to do it)
587
+ const stepRuns = new Map();
588
+ let reactSteps = steps.length;
589
+ const alive = () => run.alive();
590
+ /**
591
+ * Runs the script on a fresh page (the fixed states have already hovered and pressed the main one): load, settle,
592
+ * then for each step its action, its virtual wait, a shot and the DOM facts. It stops at the first step that cannot
593
+ * be carried out there.
594
+ */
595
+ const runSteps = async (framework) => {
596
+ const record = { start: null, shots: new Map(), facts: new Map(), failure: null };
597
+ stepRuns.set(framework, record);
598
+ const limit = framework === 'react' ? steps.length : reactSteps;
599
+ if (!limit)
600
+ return;
601
+ const sp = await newSandboxPage(browser.browser, server.origin, width, height, pageTimeout);
602
+ let i = 0;
603
+ try {
604
+ run.alive();
605
+ try {
606
+ await sp.page.goto(`${server.origin}/${framework}.html`, { waitUntil: 'load' });
607
+ run.alive();
608
+ await sp.page.waitForFunction(() => window.__morphReady === true, undefined, { timeout: pageTimeout });
609
+ run.alive();
610
+ }
611
+ catch (error) {
612
+ run.alive();
613
+ const why = sp.errors.length ? sp.errors.slice(0, 3).join(' | ') : firstLine(error);
614
+ throw new Error(`the steps page did not render within ${pageTimeout / 1000}s: ${why}`);
615
+ }
616
+ const advance = async (ms) => {
617
+ await sp.page.evaluate((m) => window.__morphClock?.advance(m) ?? Promise.resolve(0), ms);
618
+ run.alive();
619
+ };
620
+ await advance(settle);
621
+ if (framework === 'react') {
622
+ record.start = await shootPage(sp.page, width, height);
623
+ run.alive();
624
+ }
625
+ for (; i < limit; i++) {
626
+ const current = steps[i];
627
+ if (!current)
628
+ break;
629
+ try {
630
+ await performStep(sp.page, current, alive);
631
+ }
632
+ catch (error) {
633
+ run.alive();
634
+ if (!(error instanceof StepError))
635
+ throw error;
636
+ record.failure = { index: i, kind: error.kind, message: error.message };
637
+ break;
638
+ }
639
+ await advance(current.wait ?? step);
640
+ record.shots.set(i, await shootPage(sp.page, width, height));
641
+ run.alive();
642
+ record.facts.set(i, await collectFacts(sp.page, alive));
643
+ }
644
+ }
645
+ catch (error) {
646
+ // a page that broke because the run was stopped is the stop
647
+ run.alive();
648
+ record.failure = { index: i, kind: 'page', message: firstLine(error) };
649
+ }
650
+ finally {
651
+ blocked.push(...sp.blocked);
652
+ pageErrors.push(...sp.errors.map((e) => `${framework}: steps: ${e}`));
653
+ await sp.context.close().catch(() => undefined);
654
+ }
655
+ run.alive();
656
+ if (framework !== 'react' || !record.failure)
657
+ return;
658
+ const { index, kind, message } = record.failure;
659
+ // React's steps page failing to load is React failing to render, as on the main page
660
+ if (kind === 'page')
661
+ fail('react', `react: ${message}`);
662
+ reactSteps = index;
663
+ const name = steps[index]?.name ?? String(index + 1);
664
+ diagnostics.push({ code: 'step-script', severity: 'error', message: `step "${name}": ${kind === 'missing' ? `${message} in React, so the script is wrong here` : `it could not be carried out in React (${message})`}; it and the ${steps.length - index - 1} step(s) after it were not run anywhere.` });
665
+ };
666
+ for (const fw of frameworks) {
667
+ if (failed.has(fw.framework))
668
+ continue;
669
+ run.alive();
670
+ const sp = await newSandboxPage(browser.browser, server.origin, width, height, pageTimeout, leakCheck ? LEAK_PROBE_SCRIPT : undefined);
671
+ try {
672
+ try {
673
+ await sp.page.goto(`${server.origin}/${fw.framework}.html`, { waitUntil: 'load' });
674
+ }
675
+ catch (error) {
676
+ const why = sp.errors.length ? sp.errors.slice(0, 3).join(' | ') : error instanceof Error ? (error.message.split('\n')[0] ?? error.message) : String(error);
677
+ throw new MorphError('render-failed', `${fw.framework} did not render within ${pageTimeout / 1000}s: ${why}`);
678
+ }
679
+ try {
680
+ await sp.page.waitForFunction(() => window.__morphReady === true, undefined, { timeout: pageTimeout });
681
+ }
682
+ catch (error) {
683
+ const why = sp.errors.length ? sp.errors.slice(0, 3).join(' | ') : error instanceof Error ? error.message.split('\n')[0] : String(error);
684
+ throw new MorphError('render-failed', `${fw.framework} did not render within ${pageTimeout / 1000}s: ${why}`);
685
+ }
686
+ const advance = (ms) => sp.page.evaluate((m) => window.__morphClock?.advance(m) ?? Promise.resolve(0), ms);
687
+ const box = () => componentBox(sp.page);
688
+ const shoot = () => shootPage(sp.page, width, height);
689
+ await advance(settle);
690
+ shots.set(`idle:${fw.framework}`, await shoot());
691
+ const b = await box();
692
+ const cx = b.x + b.width / 2;
693
+ const cy = b.y + b.height / 2;
694
+ if (states.includes('hover') || states.includes('active')) {
695
+ await sp.page.mouse.move(cx, cy);
696
+ await advance(step);
697
+ if (states.includes('hover'))
698
+ shots.set(`hover:${fw.framework}`, await shoot());
699
+ }
700
+ if (states.includes('active')) {
701
+ await sp.page.mouse.down();
702
+ await advance(Math.round(step / 2));
703
+ shots.set(`active:${fw.framework}`, await shoot());
704
+ await sp.page.mouse.up();
705
+ }
706
+ if (leakCheck) {
707
+ // the renders stand whatever the unmount does: a failed check is reported on its own
708
+ try {
709
+ run.alive();
710
+ leftovers.set(fw.framework, await measureUnmount(sp.page, run));
711
+ }
712
+ catch (error) {
713
+ run.alive();
714
+ unmountFailed(fw.framework, error instanceof Error ? (error.message.split('\n')[0] ?? error.message) : String(error));
715
+ }
716
+ }
717
+ }
718
+ catch (error) {
719
+ // a page that broke because the run was stopped (its browser closed) is the stop, not that target's failure
720
+ run.alive();
721
+ // a target that fails part way has no comparison at all (no state is compared on a half run)
722
+ for (const state of states)
723
+ shots.delete(`${state}:${fw.framework}`);
724
+ fail(fw.framework, error instanceof Error ? (error.message.split('\n')[0] ?? error.message) : String(error));
725
+ }
726
+ finally {
727
+ blocked.push(...sp.blocked);
728
+ pageErrors.push(...sp.errors.map((e) => `${fw.framework}: ${e}`));
729
+ await sp.context.close().catch(() => undefined);
730
+ }
731
+ if (steps.length && !failed.has(fw.framework)) {
732
+ run.alive();
733
+ await runSteps(fw.framework);
734
+ }
735
+ }
736
+ const leaks = leakCheck ? await unmountLeaks(leftovers, { run, temp: temp.dir, www, project, browser: browser.browser, origin: server.origin, pageTimeout, settle, step, states, width, height, reactRuntime }, diagnostics, unmountFailed) : null;
737
+ run.alive();
738
+ const result = { file: compiled.file, exportName, comparisons: [], shots: [], blocked, pageErrors, minMatch: 0, diagnostics, ...(leaks ? { leaks } : {}), ...(discoveredSteps ? { discoveredSteps } : {}) };
739
+ const diffs = new Map();
740
+ const blank = new Set();
741
+ for (const [key, shot] of shots) {
742
+ const [state, framework] = key.split(':');
743
+ const v = variance(decodePng(shot.png));
744
+ result.shots.push({ state, framework, png: shot.png, box: { width: shot.box.width, height: shot.box.height }, variance: v });
745
+ if (v === 0 || shot.box.width === 0 || shot.box.height === 0)
746
+ blank.add(key);
747
+ }
748
+ // two blank renders match perfectly and prove nothing: a comparison with a blank side scores 0
749
+ const blankSides = (state, framework) => [`${state}:react`, `${state}:${framework}`].filter((k) => blank.has(k)).map((k) => k.split(':')[1]);
750
+ const idleReact = shots.get('idle:react');
751
+ for (const state of states) {
752
+ const react = shots.get(`${state}:react`);
753
+ if (!react)
754
+ continue;
755
+ const changed = state === 'idle' || !idleReact ? null : compare(idleReact.png, react.png).diffPixels > 0;
756
+ for (const fw of frameworks) {
757
+ if (fw.framework === 'react')
758
+ continue;
759
+ const other = shots.get(`${state}:${fw.framework}`);
760
+ if (!other)
761
+ continue;
762
+ const d = compare(react.png, other.png);
763
+ diffs.set(`${state}:${fw.framework}`, d.png);
764
+ const empty = blankSides(state, fw.framework);
765
+ if (empty.length)
766
+ diagnostics.push({ code: 'verify-blank', severity: 'error', message: `${state}: ${empty.length === 2 ? 'both renders are' : `the ${empty[0]} render is`} blank, so it cannot count as a match.`, target: fw.framework });
767
+ const comparison = { state, target: fw.framework, match: empty.length ? 0 : d.match, diffPixels: d.diffPixels, totalPixels: d.totalPixels, changedFromIdle: changed };
768
+ result.comparisons.push(comparison);
769
+ }
770
+ }
771
+ if (steps.length) {
772
+ const compared = compareSteps(steps, reactSteps, stepRuns, diagnostics, diffs);
773
+ result.steps = compared.comparisons;
774
+ result.stepShots = compared.shots;
775
+ }
776
+ // steps count only when there are any: without them minMatch is the fixed states' alone, as it always was
777
+ const matches = [...result.comparisons.map((c) => c.match), ...(result.steps ?? []).map((c) => c.match)];
778
+ result.minMatch = matches.length ? Math.min(...matches) : 0;
779
+ run.alive();
780
+ if (options.reportDir) {
781
+ const dir = resolve(options.reportDir);
782
+ mkdirSync(dir, { recursive: true });
783
+ const name = `${exportName}.verify.html`;
784
+ writeFileSync(join(dir, name), htmlReport(result, diffs));
785
+ result.reportPath = join(dir, name);
786
+ }
787
+ return result;
788
+ }
789
+ function firstLine(error) {
790
+ const message = error instanceof Error ? error.message : String(error);
791
+ return message.split('\n')[0] ?? message;
792
+ }
793
+ /**
794
+ * Compares each step's shot in every target with React's after the same step (the pixel rule and the blank rule of the
795
+ * fixed states), and its DOM facts with React's. A step a target could not carry out scores 0 and says why, and so does
796
+ * every step after it (they were not run there).
797
+ */
798
+ function compareSteps(steps, reactSteps, runs, diagnostics, diffs) {
799
+ const shots = [];
800
+ const variances = new Map();
801
+ const varianceOf = (shot) => {
802
+ let v = variances.get(shot);
803
+ if (v === undefined)
804
+ variances.set(shot, (v = variance(decodePng(shot.png))));
805
+ return v;
806
+ };
807
+ for (const [framework, record] of runs) {
808
+ for (const [i, shot] of record.shots)
809
+ shots.push({ step: steps[i]?.name ?? String(i + 1), framework, png: shot.png, box: { width: shot.box.width, height: shot.box.height }, variance: varianceOf(shot) });
810
+ }
811
+ const comparisons = [];
812
+ const react = runs.get('react');
813
+ if (!react)
814
+ return { comparisons, shots };
815
+ let before = react.start;
816
+ for (let i = 0; i < reactSteps; i++) {
817
+ const step = steps[i];
818
+ const ours = react.shots.get(i);
819
+ if (!step || !ours)
820
+ break;
821
+ const previous = before;
822
+ const changedInReact = previous ? compare(previous.png, ours.png).diffPixels > 0 : true;
823
+ before = ours;
824
+ if (isBlank(ours, varianceOf(ours))) {
825
+ diagnostics.push({ code: 'step-script', severity: 'error', message: `step "${step.name}": the React shot after it is blank, so nothing can be compared on this step.` });
826
+ continue;
827
+ }
828
+ for (const [framework, record] of runs) {
829
+ if (framework === 'react')
830
+ continue;
831
+ const base = { step: step.name, index: i, target: framework, changedInReact };
832
+ const failure = record.failure;
833
+ if (failure && failure.index <= i) {
834
+ const message = failure.index < i
835
+ ? `not run: step "${steps[failure.index]?.name ?? failure.index + 1}" could not be carried out before it`
836
+ : failure.kind === 'missing'
837
+ ? `${failure.message} in ${framework} (it does in React)`
838
+ : failure.kind === 'failed'
839
+ ? `it could not be carried out in ${framework}: ${failure.message}`
840
+ : `the ${framework} steps page failed: ${failure.message}`;
841
+ if (failure.index === i)
842
+ diagnostics.push({ code: failure.kind === 'missing' ? 'step-missing' : 'step-failed', severity: 'error', message: `step "${step.name}": ${message}${i + 1 < reactSteps ? `; the ${reactSteps - i - 1} step(s) after it were not run` : ''}.`, target: framework });
843
+ comparisons.push({ ...base, match: 0, diffPixels: 0, totalPixels: 0, changedPixels: 0, changedMatch: null, state: [], failure: message });
844
+ continue;
845
+ }
846
+ const theirs = record.shots.get(i);
847
+ if (!theirs)
848
+ continue;
849
+ const d = compare(ours.png, theirs.png);
850
+ diffs.set(`step:${i}:${framework}`, d.png);
851
+ // judged on the whole shot and on the pixels the step changed in React, whichever is lower
852
+ const region = previous ? changedRegion(previous.png, ours.png, theirs.png) : { changedPixels: 0, match: null };
853
+ const match = Math.min(d.match, region.match ?? 1);
854
+ const changed = { changedPixels: region.changedPixels, changedMatch: region.match };
855
+ const state = diffFacts(react.facts.get(i) ?? [], record.facts.get(i) ?? []);
856
+ if (state.length)
857
+ diagnostics.push({ code: 'step-state', severity: 'warning', message: `step "${step.name}": ${framework} differs from React in ${describeMismatches(state)}.`, target: framework });
858
+ if (isBlank(theirs, varianceOf(theirs))) {
859
+ diagnostics.push({ code: 'step-blank', severity: 'error', message: `step "${step.name}": the ${framework} shot after it is blank, so it cannot count as a match.`, target: framework });
860
+ comparisons.push({ ...base, match: 0, diffPixels: d.diffPixels, totalPixels: d.totalPixels, ...changed, state, failure: `the ${framework} shot is blank` });
861
+ continue;
862
+ }
863
+ comparisons.push({ ...base, match, diffPixels: d.diffPixels, totalPixels: d.totalPixels, ...changed, state });
864
+ }
865
+ }
866
+ return { comparisons, shots };
867
+ }