@reqvire-org/ads 0.4.0 → 0.4.3

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 (410) hide show
  1. package/README.md +115 -87
  2. package/dist/a11y.mjs +133 -48
  3. package/dist/analysis/compiler-options.mjs +13 -0
  4. package/dist/analysis/context.mjs +46 -0
  5. package/dist/analysis/file-tree.mjs +52 -0
  6. package/dist/analysis/helpers.mjs +142 -0
  7. package/dist/analysis/impact.mjs +20 -0
  8. package/dist/analysis/inputs.mjs +22 -0
  9. package/dist/analysis/module-resolvers.mjs +46 -0
  10. package/dist/analysis/native-adapter.mjs +180 -0
  11. package/dist/analysis/native-project.mjs +323 -0
  12. package/dist/analysis/queries.mjs +133 -0
  13. package/dist/analysis/service.mjs +153 -0
  14. package/dist/analysis/standalone.mjs +57 -0
  15. package/dist/analysis/syntax.mjs +179 -0
  16. package/dist/analysis/worker.mjs +182 -0
  17. package/dist/assets.mjs +6 -6
  18. package/dist/atomic-composition.mjs +191 -70
  19. package/dist/atomic-trace.mjs +120 -50
  20. package/dist/behavior-libraries.mjs +106 -37
  21. package/dist/behaviors.mjs +219 -77
  22. package/dist/boundaries.mjs +140 -41
  23. package/dist/brand-assets.mjs +219 -47
  24. package/dist/brands.mjs +86 -27
  25. package/dist/bun-compiler.mjs +28 -14
  26. package/dist/bun-worker.mjs +7 -5
  27. package/dist/capture/worker.mjs +15 -4
  28. package/dist/capture-store.mjs +4 -2
  29. package/dist/capture.mjs +17 -14
  30. package/dist/check-service.mjs +44 -58
  31. package/dist/check.mjs +754 -188
  32. package/dist/cli.mjs +200 -99
  33. package/dist/color-values.mjs +21 -21
  34. package/dist/component-contrast.mjs +127 -9
  35. package/dist/config.mjs +303 -135
  36. package/dist/construction-styles.cjs +10 -0
  37. package/dist/contrast-composition.mjs +134 -0
  38. package/dist/control-padding.mjs +45 -25
  39. package/dist/css-values.mjs +3 -2
  40. package/dist/declarative-flow.mjs +209 -109
  41. package/dist/design-values.mjs +136 -51
  42. package/dist/development-runtime.mjs +4 -6
  43. package/dist/draft-boundary.mjs +11 -6
  44. package/dist/evidence.mjs +1 -1
  45. package/dist/finding-rules.mjs +9 -5
  46. package/dist/font-rules.mjs +22 -17
  47. package/dist/fonts-generated.mjs +23 -16
  48. package/dist/foundation-views.mjs +242 -0
  49. package/dist/foundation.mjs +63 -39
  50. package/dist/generated-entries.mjs +101 -34
  51. package/dist/icons.mjs +79 -32
  52. package/dist/image-attributes.mjs +143 -66
  53. package/dist/image-size.mjs +1 -1
  54. package/dist/index.mjs +0 -2
  55. package/dist/init.mjs +122 -41
  56. package/dist/investigations.mjs +2 -2
  57. package/dist/layers.mjs +298 -129
  58. package/dist/layout-widths.mjs +180 -85
  59. package/dist/linaria/preserve-values.cjs +7 -0
  60. package/dist/linaria/spatial-inputs.cjs +56 -0
  61. package/dist/lockup-composition.mjs +44 -0
  62. package/dist/lockup-model.cjs +64 -0
  63. package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
  64. package/dist/mcp/apps.mjs +4 -30
  65. package/dist/mcp/behavior-pages.mjs +72 -24
  66. package/dist/mcp/build-status.mjs +257 -64
  67. package/dist/mcp/catalog.mjs +90 -26
  68. package/dist/mcp/context.mjs +17 -18
  69. package/dist/mcp/draft-discovery.mjs +44 -21
  70. package/dist/mcp/drafts.mjs +903 -281
  71. package/dist/mcp/execution-coordinator.mjs +417 -167
  72. package/dist/mcp/execution-results.mjs +7 -7
  73. package/dist/mcp/mutations.mjs +673 -234
  74. package/dist/mcp/preview-watch.mjs +448 -170
  75. package/dist/mcp/preview-widget.bundle.js +44 -50
  76. package/dist/mcp/prompts.mjs +5 -5
  77. package/dist/mcp/result-pages.mjs +1 -1
  78. package/dist/mcp/sandbox-host.mjs +1 -1
  79. package/dist/mcp/server.mjs +2409 -577
  80. package/dist/mcp/showcase-host.mjs +165 -41
  81. package/dist/mcp/skills.mjs +1 -1
  82. package/dist/mcp/text-diff.mjs +29 -10
  83. package/dist/paint-contracts.mjs +174 -81
  84. package/dist/palette-generated.mjs +2 -2
  85. package/dist/pictogram-model.mjs +59 -0
  86. package/dist/pictograms.mjs +52 -0
  87. package/dist/preview-bun.mjs +494 -187
  88. package/dist/preview-failure.mjs +1 -1
  89. package/dist/preview-files.mjs +13 -13
  90. package/dist/preview-imports.mjs +104 -55
  91. package/dist/preview-inputs.mjs +2 -2
  92. package/dist/preview-requests.mjs +24 -0
  93. package/dist/preview-resources.mjs +288 -147
  94. package/dist/preview-scope.mjs +5 -4
  95. package/dist/program-cache.mjs +8 -34
  96. package/dist/project-documents.mjs +1 -1
  97. package/dist/public-api.mjs +69 -31
  98. package/dist/public-props.mjs +39 -22
  99. package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
  100. package/dist/{browser-audit → render-audit}/image-shape.mjs +15 -5
  101. package/dist/{browser-audit → render-audit}/layout-overflow.mjs +86 -23
  102. package/dist/{browser-audit → render-audit}/non-text-contrast.mjs +86 -27
  103. package/dist/render-audit/pictograms.mjs +88 -0
  104. package/dist/{browser-audit → render-audit}/render-states.mjs +208 -52
  105. package/dist/{browser-audit → render-audit}/worker.mjs +98 -30
  106. package/dist/render-audit.mjs +838 -0
  107. package/dist/render-color-probe.mjs +96 -42
  108. package/dist/render-composition.mjs +164 -0
  109. package/dist/resource-limits.mjs +229 -97
  110. package/dist/runtime-contracts.mjs +467 -185
  111. package/dist/scenario-groups.mjs +22 -10
  112. package/dist/scenario-inspector.mjs +6 -43
  113. package/dist/scenario-program.mjs +8 -25
  114. package/dist/scenario-registry.mjs +72 -30
  115. package/dist/scenario-selectors.mjs +161 -64
  116. package/dist/scenario-slots.mjs +149 -56
  117. package/dist/scenario-trace.mjs +215 -109
  118. package/dist/scenarios-compiler.mjs +719 -378
  119. package/dist/scenarios-vite.d.mts +1 -3
  120. package/dist/scenarios-vite.mjs +2 -81
  121. package/dist/scenarios.mjs +421 -157
  122. package/dist/selector-match.mjs +2 -2
  123. package/dist/showcase/client.bundle.js +57 -56
  124. package/dist/showcase/draft-navigation.js +21 -3
  125. package/dist/showcase/favicon.ico +0 -0
  126. package/dist/showcase/favicon.svg +1 -0
  127. package/dist/showcase/foundation-view.css +58 -0
  128. package/dist/showcase/foundation-view.mjs +255 -0
  129. package/dist/showcase/guide-controls.ads.review.mjs +32 -0
  130. package/dist/showcase/icons.js +1 -145
  131. package/dist/showcase/index.html +3 -31
  132. package/dist/showcase/pictogram-view.mjs +53 -0
  133. package/dist/showcase/preview-frame.ads.review.css +46 -0
  134. package/dist/showcase/preview-frame.ads.review.d.mts +11 -0
  135. package/dist/showcase/preview-frame.ads.review.mjs +22 -0
  136. package/dist/showcase/preview-state.js +0 -9
  137. package/dist/showcase/refresh-scheduler.js +23 -0
  138. package/dist/showcase/style.css +5 -47
  139. package/dist/showcase/ui/ui.css +1353 -0
  140. package/dist/showcase/ui/ui.js +1064 -0
  141. package/dist/showcase-coverage.mjs +58 -37
  142. package/dist/skills/README.md +24 -23
  143. package/dist/skills/ads-designer/README.md +8 -2
  144. package/dist/skills/ads-designer/SKILL.md +143 -120
  145. package/dist/skills/ads-designer/references/accessibility.md +78 -15
  146. package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
  147. package/dist/skills/ads-designer/references/behaviors.md +30 -27
  148. package/dist/skills/ads-designer/references/branding.md +101 -24
  149. package/dist/skills/ads-designer/references/captures.md +25 -0
  150. package/dist/skills/ads-designer/references/cli.md +21 -24
  151. package/dist/skills/ads-designer/references/contracts.md +7 -6
  152. package/dist/skills/ads-designer/references/design-data.md +49 -52
  153. package/dist/skills/ads-designer/references/drafts.md +20 -17
  154. package/dist/skills/ads-designer/references/evidence.md +1 -5
  155. package/dist/skills/ads-designer/references/guarded-editing.md +14 -18
  156. package/dist/skills/ads-designer/references/layers.md +1 -1
  157. package/dist/skills/ads-designer/references/layout.md +347 -0
  158. package/dist/skills/ads-designer/references/mobile.md +2 -1
  159. package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
  160. package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
  161. package/dist/skills/ads-designer/references/performance.md +3 -2
  162. package/dist/skills/ads-designer/references/pictograms.md +131 -0
  163. package/dist/skills/ads-designer/references/review.md +37 -34
  164. package/dist/skills/ads-designer/references/runtimes.md +33 -30
  165. package/dist/skills/ads-designer/references/scenarios.md +16 -18
  166. package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
  167. package/dist/skills/ads-designer/references/stress-test.md +68 -0
  168. package/dist/skills/ads-designer/references/validation.md +83 -75
  169. package/dist/skills/ads-designer/references/workflows.md +8 -33
  170. package/dist/skills/ads-import/SKILL.md +43 -325
  171. package/dist/skills/ads-import/references/atomic-styles.md +4 -4
  172. package/dist/skills/ads-import/references/behaviors.md +30 -27
  173. package/dist/skills/ads-import/references/branding.md +5 -5
  174. package/dist/skills/ads-import/references/captures.md +25 -0
  175. package/dist/skills/ads-import/references/cli.md +21 -24
  176. package/dist/skills/ads-import/references/compatibility.md +1 -1
  177. package/dist/skills/ads-import/references/contracts.md +7 -6
  178. package/dist/skills/ads-import/references/design-data.md +49 -52
  179. package/dist/skills/ads-import/references/drafts.md +20 -17
  180. package/dist/skills/ads-import/references/evidence.md +1 -5
  181. package/dist/skills/ads-import/references/guarded-editing.md +14 -18
  182. package/dist/skills/ads-import/references/implementation.md +2 -1
  183. package/dist/skills/ads-import/references/layers.md +1 -1
  184. package/dist/skills/ads-import/references/layout.md +347 -0
  185. package/dist/skills/ads-import/references/review.md +37 -34
  186. package/dist/skills/ads-import/references/runtimes.md +33 -30
  187. package/dist/skills/ads-import/references/scenarios.md +16 -18
  188. package/dist/skills/ads-import/references/tokens.md +3 -3
  189. package/dist/skills/ads-import/references/validation.md +83 -75
  190. package/dist/skills/ads-import/references/workflows.md +8 -33
  191. package/dist/skills/ads-migrate/SKILL.md +56 -0
  192. package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
  193. package/dist/skills/ads-port/SKILL.md +58 -344
  194. package/dist/skills/ads-port/references/atomic-styles.md +4 -4
  195. package/dist/skills/ads-port/references/behaviors.md +30 -27
  196. package/dist/skills/ads-port/references/captures.md +25 -0
  197. package/dist/skills/ads-port/references/cli.md +21 -24
  198. package/dist/skills/ads-port/references/contracts.md +7 -6
  199. package/dist/skills/ads-port/references/design-data.md +49 -52
  200. package/dist/skills/ads-port/references/drafts.md +20 -17
  201. package/dist/skills/ads-port/references/evidence.md +1 -5
  202. package/dist/skills/ads-port/references/guarded-editing.md +14 -18
  203. package/dist/skills/ads-port/references/layers.md +1 -1
  204. package/dist/skills/ads-port/references/layout.md +347 -0
  205. package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
  206. package/dist/skills/ads-port/references/native-implementation.md +2 -1
  207. package/dist/skills/ads-port/references/review.md +37 -34
  208. package/dist/skills/ads-port/references/runtimes.md +33 -30
  209. package/dist/skills/ads-port/references/scenarios.md +16 -18
  210. package/dist/skills/ads-port/references/validation.md +83 -75
  211. package/dist/skills/ads-port/references/workflows.md +8 -33
  212. package/dist/source-symbols.mjs +1 -8
  213. package/dist/source-values.mjs +270 -129
  214. package/dist/spatial-composition.mjs +322 -0
  215. package/dist/spatial-contexts.cjs +56 -0
  216. package/dist/spatial-css.cjs +351 -0
  217. package/dist/spatial-inputs.cjs +80 -0
  218. package/dist/spatial-metadata.mjs +18 -0
  219. package/dist/spatial-model.cjs +322 -0
  220. package/dist/spatial.mjs +21 -0
  221. package/dist/stage-timing.cjs +20 -0
  222. package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +105 -0
  223. package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +275 -0
  224. package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
  225. package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
  226. package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +8 -0
  227. package/dist/starters/preact/ds.config.json +25 -6
  228. package/dist/starters/preact/package.json +4 -8
  229. package/dist/starters/preact/tsconfig.json +4 -5
  230. package/dist/starters/preact/vite.config.ts +3 -3
  231. package/dist/starters/react/ADS.md +42 -47
  232. package/dist/starters/react/README.md +47 -49
  233. package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +13 -0
  234. package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +7 -0
  235. package/dist/starters/react/design-system/assets/pictograms/journey.svg +7 -0
  236. package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +18 -2
  237. package/dist/starters/react/design-system/components/Actions/IconButton/README.md +3 -0
  238. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +1 -0
  239. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +1 -0
  240. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +7 -0
  241. package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +26 -0
  242. package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +5 -0
  243. package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
  244. package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
  245. package/dist/starters/react/design-system/index.ts +2 -1
  246. package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
  247. package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
  248. package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
  249. package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
  250. package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
  251. package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
  252. package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
  253. package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
  254. package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
  255. package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
  256. package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
  257. package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
  258. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -1
  259. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
  260. package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
  261. package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
  262. package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
  263. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -1
  264. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
  265. package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
  266. package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
  267. package/dist/starters/react/design-system/tokens/colors.css +1 -1
  268. package/dist/starters/react/design-system/tokens/spacing.css +22 -32
  269. package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
  270. package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
  271. package/dist/starters/react/ds.config.json +25 -6
  272. package/dist/starters/react/package.json +2 -6
  273. package/dist/starters/react/tsconfig.json +2 -3
  274. package/dist/starters/react/vite.config.ts +3 -3
  275. package/dist/style-boundaries.mjs +70 -25
  276. package/dist/task-cache.mjs +173 -72
  277. package/dist/task-worker.mjs +22 -11
  278. package/dist/test-boundaries.mjs +132 -59
  279. package/dist/themes-generated.mjs +1 -1
  280. package/dist/themes-watch.mjs +57 -22
  281. package/dist/themes.mjs +176 -73
  282. package/dist/token-export.mjs +39 -14
  283. package/dist/token-policy.mjs +6 -3
  284. package/dist/token-quality.mjs +6 -6
  285. package/dist/token-samples.mjs +16 -5
  286. package/dist/tokens.mjs +71 -26
  287. package/dist/ui-framework.mjs +16 -14
  288. package/dist/unit-contracts.mjs +251 -104
  289. package/dist/units.mjs +209 -99
  290. package/dist/usage.mjs +138 -38
  291. package/dist/validation-checks.mjs +115 -38
  292. package/dist/validation-inputs.mjs +191 -78
  293. package/dist/validation.mjs +268 -102
  294. package/dist/verification/browser.mjs +27 -5
  295. package/dist/verification.mjs +711 -187
  296. package/docs/ADS.md +96 -80
  297. package/docs/ARCHITECTURE.md +368 -137
  298. package/docs/BEHAVIORS.md +29 -25
  299. package/docs/CACHING.md +77 -17
  300. package/docs/CHANGELOG.md +332 -17
  301. package/docs/CONTRACTS.md +12 -4
  302. package/docs/DESIGN-REFERENCES.md +40 -0
  303. package/docs/GUIDE.md +300 -263
  304. package/docs/MCP.md +187 -324
  305. package/docs/SPATIAL-CHECKS.md +69 -0
  306. package/docs/benchmarks/README.md +39 -0
  307. package/package.json +43 -34
  308. package/dist/browser-audit.mjs +0 -429
  309. package/dist/create.mjs +0 -48
  310. package/dist/lint-config.mjs +0 -50
  311. package/dist/mcp/project-widget.bundle.js +0 -114
  312. package/dist/mcp/reports.mjs +0 -101
  313. package/dist/mcp/widget.bundle.js +0 -147
  314. package/dist/oxlint.mjs +0 -89
  315. package/dist/preview-builder.mjs +0 -133
  316. package/dist/preview-workers.mjs +0 -184
  317. package/dist/showcase.mjs +0 -77
  318. package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
  319. package/dist/skills/ads-break-ui/README.md +0 -16
  320. package/dist/skills/ads-break-ui/SKILL.md +0 -412
  321. package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
  322. package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
  323. package/dist/skills/ads-break-ui/references/behaviors.md +0 -412
  324. package/dist/skills/ads-break-ui/references/captures.md +0 -135
  325. package/dist/skills/ads-break-ui/references/contracts.md +0 -317
  326. package/dist/skills/ads-break-ui/references/design-data.md +0 -354
  327. package/dist/skills/ads-break-ui/references/drafts.md +0 -194
  328. package/dist/skills/ads-break-ui/references/evidence.md +0 -128
  329. package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -165
  330. package/dist/skills/ads-break-ui/references/layers.md +0 -145
  331. package/dist/skills/ads-break-ui/references/reporting.md +0 -101
  332. package/dist/skills/ads-break-ui/references/review.md +0 -97
  333. package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
  334. package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
  335. package/dist/skills/ads-break-ui/references/validation.md +0 -166
  336. package/dist/skills/ads-break-ui/references/verification.md +0 -58
  337. package/dist/skills/ads-break-ui/references/workflows.md +0 -90
  338. package/dist/skills/ads-designer/references/reporting.md +0 -101
  339. package/dist/skills/ads-import/references/reporting.md +0 -101
  340. package/dist/skills/ads-motion/LICENSE.upstream +0 -21
  341. package/dist/skills/ads-motion/README.md +0 -22
  342. package/dist/skills/ads-motion/SKILL.md +0 -385
  343. package/dist/skills/ads-motion/agents/openai.yaml +0 -4
  344. package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
  345. package/dist/skills/ads-motion/references/audit.md +0 -44
  346. package/dist/skills/ads-motion/references/behaviors.md +0 -412
  347. package/dist/skills/ads-motion/references/captures.md +0 -135
  348. package/dist/skills/ads-motion/references/contracts.md +0 -317
  349. package/dist/skills/ads-motion/references/design-data.md +0 -354
  350. package/dist/skills/ads-motion/references/drafts.md +0 -194
  351. package/dist/skills/ads-motion/references/evidence.md +0 -128
  352. package/dist/skills/ads-motion/references/guarded-editing.md +0 -165
  353. package/dist/skills/ads-motion/references/layers.md +0 -145
  354. package/dist/skills/ads-motion/references/motion-review.md +0 -35
  355. package/dist/skills/ads-motion/references/reporting.md +0 -101
  356. package/dist/skills/ads-motion/references/review.md +0 -97
  357. package/dist/skills/ads-motion/references/runtimes.md +0 -203
  358. package/dist/skills/ads-motion/references/scenarios.md +0 -246
  359. package/dist/skills/ads-motion/references/validation.md +0 -166
  360. package/dist/skills/ads-motion/references/verification.md +0 -39
  361. package/dist/skills/ads-motion/references/workflows.md +0 -90
  362. package/dist/skills/ads-port/references/reporting.md +0 -101
  363. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
  364. package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
  365. package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
  366. package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
  367. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
  368. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
  369. package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
  370. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
  371. package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
  372. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
  373. package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
  374. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
  375. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +0 -1
  376. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
  377. package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
  378. package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
  379. package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
  380. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +0 -1
  381. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
  382. package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
  383. package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +0 -1
  384. package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
  385. package/dist/starters/react/design-system/review/index.ts +0 -6
  386. package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
  387. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
  388. package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +0 -1
  389. package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
  390. package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
  391. package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
  392. package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
  393. package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
  394. package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
  395. package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
  396. package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
  397. package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
  398. package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
  399. package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
  400. package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
  401. package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
  402. package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
  403. package/dist/starters/react/package-lock.json +0 -4707
  404. package/dist/token-fixtures.mjs +0 -30
  405. package/docs/benchmarks/bun-previews.md +0 -91
  406. package/docs/benchmarks/preview-memory.md +0 -147
  407. package/docs/benchmarks/turbo-poc.md +0 -284
  408. package/docs/plans/execution-coordination.md +0 -57
  409. /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
  410. /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
@@ -0,0 +1,180 @@
1
+ // A snapshot's rule interface: native ASTs and enums, cached async semantic
2
+ // queries, and draft-path relocation. There is no second compiler or parser.
3
+ import path from "node:path";
4
+ import { SyntaxKind } from "typescript/ast";
5
+ import { TypeFlags } from "typescript/async";
6
+ import { declaration, query } from "./queries.mjs";
7
+
8
+ const raw = Symbol("native object");
9
+ function relocateNode(value, root, canonicalRoot, nodes) {
10
+ const node = (item) => relocateNode(item, root, canonicalRoot, nodes);
11
+ const fromCompiler = (file) => (file === canonicalRoot ? root : file?.startsWith(canonicalRoot + path.sep) ? root + file.slice(canonicalRoot.length) : file);
12
+ if (!value || typeof value !== "object") return value;
13
+ if (Array.isArray(value)) return value.map(node);
14
+ if (nodes.has(value)) return nodes.get(value);
15
+ const properties = new Map();
16
+ const proxy = new Proxy(value, {
17
+ get(target, property) {
18
+ if (property === raw) return target;
19
+ if (!properties.has(property)) {
20
+ const item = Reflect.get(target, property, target);
21
+ const result =
22
+ property === "fileName"
23
+ ? fromCompiler(item)
24
+ : property === "forEachChild"
25
+ ? (visit) => target.forEachChild((child) => visit(node(child)))
26
+ : typeof item === "function"
27
+ ? (...args) =>
28
+ node(
29
+ item.apply(
30
+ target,
31
+ args.map((value) => value?.[raw] ?? value),
32
+ ),
33
+ )
34
+ : node(item);
35
+ properties.set(property, result);
36
+ }
37
+ return properties.get(property);
38
+ },
39
+ });
40
+ nodes.set(value, proxy);
41
+ return proxy;
42
+ }
43
+
44
+ export async function adaptProgram({ snapshot, id, root, canonicalRoot = root, compilerOptions, rootNames, nodes = new WeakMap() }) {
45
+ const toCompiler = (file) => (file === root ? canonicalRoot : file?.startsWith(root + path.sep) ? canonicalRoot + file.slice(root.length) : file);
46
+ const fromCompiler = (file) => (file === canonicalRoot ? root : file?.startsWith(canonicalRoot + path.sep) ? root + file.slice(canonicalRoot.length) : file);
47
+ const native = snapshot.getProgram(id),
48
+ checker = snapshot.getProject(id).checker;
49
+ const sourceNames = (await native.getSourceFileNames()).map(fromCompiler),
50
+ sourceNameSet = new Set(sourceNames);
51
+ const sources = new Map(),
52
+ indexes = new Map(),
53
+ values = new WeakMap(),
54
+ symbolFiles = new WeakSet();
55
+ const node = (value) => relocateNode(value, root, canonicalRoot, nodes);
56
+ async function unwrap(value) {
57
+ if (!value || typeof value !== "object") return value;
58
+ if (value[raw]) return value[raw];
59
+ if (Array.isArray(value)) return Promise.all(value.map(unwrap));
60
+ if (typeof value.kind === "number" && typeof value.getSourceFile === "function") {
61
+ const file = value.getSourceFile().fileName;
62
+ if (!indexes.has(file))
63
+ indexes.set(
64
+ file,
65
+ (async () => {
66
+ const source = await native.getSourceFile(toCompiler(file)),
67
+ index = new Map();
68
+ if (!source) throw new Error(`Native program missing ${file}`);
69
+ function visit(current) {
70
+ index.set(`${current.pos}:${current.end}:${current.kind}`, current);
71
+ current.forEachChild(visit);
72
+ }
73
+ visit(source);
74
+ return index;
75
+ })(),
76
+ );
77
+ const result = (await indexes.get(file)).get(`${value.pos}:${value.end}:${value.kind}`);
78
+ if (!result) throw new Error(`Node is outside this program: ${file}:${value.pos}`);
79
+ return result;
80
+ }
81
+ return value;
82
+ }
83
+ async function wrap(value) {
84
+ if (!value || typeof value !== "object") return value;
85
+ if (Array.isArray(value)) return Promise.all(value.map(wrap));
86
+ if (typeof value.resolve === "function") return node(await declaration(value));
87
+ if (typeof value.kind === "number" && typeof value.getSourceFile === "function") return node(value);
88
+ if (values.has(value)) return values.get(value);
89
+ const pending = (async () => {
90
+ const fields = new Map();
91
+ // Resolve only the symbols actually requested by a rule. The AST walks
92
+ // following a semantic lookup remain ordinary local operations.
93
+ if (Array.isArray(value.declarations))
94
+ fields.set("declarations", await Promise.all(value.declarations.map(async (handle) => node(await declaration(handle)))));
95
+ if ("valueDeclaration" in value) fields.set("valueDeclaration", node(await declaration(value.valueDeclaration)));
96
+ const type = typeof value.getCallSignatures === "function";
97
+ if (type) {
98
+ fields.set("isUnion", () => value.isUnionType());
99
+ fields.set("isIntersection", () => value.isIntersectionType());
100
+ if (value.flags & (TypeFlags.Union | TypeFlags.Intersection | TypeFlags.TemplateLiteral))
101
+ fields.set("types", await wrap(await query(value, "getTypes")));
102
+ }
103
+ if (!type && typeof value.getParameters === "function") fields.set("parameters", await wrap(await query(value, "getParameters")));
104
+ return new Proxy(value, {
105
+ get(target, property) {
106
+ if (property === raw) return target;
107
+ if (fields.has(property)) return fields.get(property);
108
+ const item = Reflect.get(target, property, target);
109
+ if (typeof item !== "function") return item;
110
+ const method = async (...args) => wrap(await query(target, property, ...(await Promise.all(args.map(unwrap)))));
111
+ fields.set(property, method);
112
+ return method;
113
+ },
114
+ });
115
+ })();
116
+ values.set(value, pending);
117
+ pending.catch(() => {
118
+ if (values.get(value) === pending) values.delete(value);
119
+ });
120
+ return pending;
121
+ }
122
+ async function source(file) {
123
+ if (!sources.has(file)) sources.set(file, native.getSourceFile(toCompiler(file)).then(node));
124
+ return sources.get(file);
125
+ }
126
+ const checkerMethods = new Map();
127
+ const checkerView = new Proxy(checker, {
128
+ get(target, property) {
129
+ if (checkerMethods.has(property)) return checkerMethods.get(property);
130
+ const method = async (...args) => {
131
+ args = await Promise.all(args.map(unwrap));
132
+ if (property === "getSymbolAtLocation" && compilerOptions.noResolve && compilerOptions.noLib && args[0]?.kind === SyntaxKind.Identifier) {
133
+ const file = args[0].getSourceFile();
134
+ if (!symbolFiles.has(file) && file.fileName.startsWith(canonicalRoot + path.sep) && !file.fileName.includes(`${path.sep}node_modules${path.sep}`)) {
135
+ symbolFiles.add(file);
136
+ const identifiers = [];
137
+ function visit(node) {
138
+ if (node.kind === SyntaxKind.Identifier) identifiers.push(node);
139
+ node.forEachChild(visit);
140
+ }
141
+ visit(file);
142
+ await Promise.all(identifiers.map((identifier) => query(checker, property, identifier)));
143
+ }
144
+ }
145
+ return wrap(await query(target, property, ...args));
146
+ };
147
+ checkerMethods.set(property, method);
148
+ return method;
149
+ },
150
+ });
151
+ const diagnosticMessage = (diagnostic) =>
152
+ diagnostic.messageChain?.length
153
+ ? { messageText: diagnostic.text, code: diagnostic.code, category: diagnostic.category, next: diagnostic.messageChain.map(diagnosticMessage) }
154
+ : diagnostic.text;
155
+ return {
156
+ getDiagnostics: async () =>
157
+ (await Promise.all(["getProgramDiagnostics", "getSyntacticDiagnostics", "getSemanticDiagnostics"].map((method) => query(native, method))))
158
+ .flat()
159
+ .map((diagnostic) => ({ ...diagnostic, fileName: fromCompiler(diagnostic.fileName), messageText: diagnosticMessage(diagnostic) })),
160
+ getTypeChecker: () => checkerView,
161
+ getSourceFile: source,
162
+ hasSourceFile: (file) => sourceNameSet.has(file),
163
+ getSourceFileNames: () => sourceNames,
164
+ getSourceFiles: async () =>
165
+ Promise.all(sourceNames.filter((file) => file.startsWith(root + path.sep) && !file.includes(`${path.sep}node_modules${path.sep}`)).map(source)),
166
+ getCompilerOptions: () => compilerOptions,
167
+ getRootFileNames: () => [...rootNames],
168
+ getCurrentDirectory: () => root,
169
+ getSyntacticDiagnostics: async (file) =>
170
+ (await query(native, "getSyntacticDiagnostics"))
171
+ .filter((diagnostic) => !file || fromCompiler(diagnostic.fileName) === file.fileName)
172
+ .map((diagnostic) => ({
173
+ ...diagnostic,
174
+ fileName: fromCompiler(diagnostic.fileName),
175
+ start: diagnostic.pos,
176
+ length: diagnostic.end - diagnostic.pos,
177
+ messageText: diagnosticMessage(diagnostic),
178
+ })),
179
+ };
180
+ }
@@ -0,0 +1,323 @@
1
+ import path from "node:path";
2
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
3
+ import { API } from "typescript/async";
4
+ import { createFileSystemLayer, serverFS } from "typescript/fs";
5
+ import { FileTree } from "./file-tree.mjs";
6
+ import { adaptProgram } from "./native-adapter.mjs";
7
+ import ts from "./syntax.mjs";
8
+ import { nativeCompilerOptions } from "./compiler-options.mjs";
9
+
10
+ const configuration = (file) => /\.(?:jsonc?|lock|ya?ml|toml)$/.test(file);
11
+ function relocate(value, from, to) {
12
+ if (typeof value === "string") return value === from ? to : value.startsWith(from + path.sep) ? to + value.slice(from.length) : value;
13
+ if (Array.isArray(value)) return value.map((item) => relocate(item, from, to));
14
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, relocate(item, from, to)]));
15
+ return value;
16
+ }
17
+
18
+ /** One compiler owns a live project and isolated source revisions. */
19
+ export class NativeProject {
20
+ #api;
21
+ #baseline;
22
+ #views = new Set();
23
+ #generation = 0;
24
+ #closed = false;
25
+ #external = new Map();
26
+ // Live AST identity survives revisions. Each draft owns its relocated wrappers
27
+ // so shared native trees cannot retain discarded draft paths indefinitely.
28
+ #liveNodes = new WeakMap();
29
+ constructor(root) {
30
+ this.root = path.resolve(root);
31
+ const projectPath = (file) => file === this.root || file.startsWith(this.root + path.sep);
32
+ const dependencyPath = (file) => file === path.join(this.root, "node_modules") || file.startsWith(path.join(this.root, "node_modules") + path.sep);
33
+ const memoryOnly = (file) => projectPath(file) && !dependencyPath(file);
34
+ // Request layers provide the complete project view. A file omitted from a
35
+ // candidate must never become visible through the live filesystem fallback.
36
+ this.#api = new API({
37
+ cwd: this.root,
38
+ runExternalCode: false,
39
+ fs: {
40
+ directoryExists: (file) => (memoryOnly(file) ? false : this.#externalInput("directory", file)),
41
+ fileExists: (file) => (memoryOnly(file) ? false : this.#externalInput("exists", file)),
42
+ getAccessibleEntries: (file) => (memoryOnly(file) ? { files: [], directories: [], symlinks: [] } : JSON.parse(this.#externalInput("entries", file))),
43
+ readFile: (file) => (memoryOnly(file) ? undefined : this.#externalInput("text", file)),
44
+ realpath: (file) => (memoryOnly(file) ? serverFS.identity : this.#externalInput("realpath", file)),
45
+ stat: serverFS.fakeStat,
46
+ writeFile: serverFS.error,
47
+ removeFile: serverFS.error,
48
+ },
49
+ });
50
+ this.stats = { compilerStarts: 1, baselines: 0, branches: 0, programs: 0, compactions: 0, changedFiles: 0, transmittedBytes: 0 };
51
+ }
52
+ #externalValue(kind, file) {
53
+ try {
54
+ if (kind === "text") return readFileSync(file, "utf8");
55
+ if (kind === "realpath") return realpathSync(file);
56
+ if (kind === "directory") return statSync(file).isDirectory();
57
+ if (kind === "exists") return existsSync(file);
58
+ const result = { files: [], directories: [], symlinks: [] };
59
+ for (const entry of readdirSync(file, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
60
+ if (entry.isSymbolicLink()) result.symlinks.push(entry.name);
61
+ const stat = entry.isSymbolicLink() ? statSync(path.join(file, entry.name), { throwIfNoEntry: false }) : entry;
62
+ if (stat?.isFile()) result.files.push(entry.name);
63
+ else if (stat?.isDirectory()) result.directories.push(entry.name);
64
+ }
65
+ return JSON.stringify(result);
66
+ } catch (error) {
67
+ if (!["ENOENT", "ENOTDIR"].includes(error.code)) throw error;
68
+ return kind === "text" ? undefined : kind === "realpath" ? file : kind === "entries" ? '{"files":[],"directories":[],"symlinks":[]}' : false;
69
+ }
70
+ }
71
+ #externalInput(kind, file) {
72
+ const key = `${kind}\0${file}`;
73
+ if (!this.#external.has(key)) this.#external.set(key, { kind, file, value: this.#externalValue(kind, file) });
74
+ return this.#external.get(key).value;
75
+ }
76
+ #refreshExternal() {
77
+ let changed = false;
78
+ // Content comparison catches same-size and preserved-mtime dependency edits,
79
+ // including a module that was missing during the previous resolution.
80
+ for (const input of this.#external.values()) {
81
+ const value = this.#externalValue(input.kind, input.file);
82
+ if (value !== input.value) {
83
+ input.value = value;
84
+ changed = true;
85
+ }
86
+ }
87
+ return changed;
88
+ }
89
+ #normalize(entries) {
90
+ return new Map(
91
+ [...entries].map(([name, content]) => {
92
+ const file = path.resolve(this.root, name);
93
+ if (!file.startsWith(this.root + path.sep) || file.includes(`${path.sep}node_modules${path.sep}`))
94
+ throw new Error("Analysis input must be a project-owned file.");
95
+ if (content !== null && typeof content !== "string") throw new Error("Analysis input must be source text or null.");
96
+ return [file, content];
97
+ }),
98
+ );
99
+ }
100
+ #changes(before, after) {
101
+ return new Map(
102
+ [...new Set([...before.keys(), ...after.keys()])]
103
+ .filter((file) => (before.get(file) ?? null) !== (after.get(file) ?? null))
104
+ .map((file) => [file, after.get(file) ?? null]),
105
+ );
106
+ }
107
+ #layer(changes, previous, invalidateAll = false) {
108
+ const created = [],
109
+ changed = [],
110
+ deleted = [],
111
+ files = [];
112
+ for (const [file, content] of changes) {
113
+ (content === null ? deleted : previous.has(file) ? changed : created).push(file);
114
+ if (content !== null) files.push([file, content]);
115
+ this.stats.changedFiles++;
116
+ this.stats.transmittedBytes += content === null ? 0 : Buffer.byteLength(content);
117
+ }
118
+ return {
119
+ fileSystem: createFileSystemLayer(files, { removedPaths: deleted }),
120
+ fileNotifications: { created, changed, deleted, ...(invalidateAll || [...changes.keys()].some(configuration) ? { invalidateAll: true } : {}) },
121
+ ensurePrograms: true,
122
+ };
123
+ }
124
+ #record(root, snapshot, files, tree, programs = new Map(), generation = this.#generation, nodes) {
125
+ const view = {
126
+ root: path.resolve(root),
127
+ snapshot,
128
+ files,
129
+ tree,
130
+ programs: new Map(programs),
131
+ generation,
132
+ snapshots: new Set([snapshot]),
133
+ adapters: new Map(),
134
+ nodes: nodes ?? (path.resolve(root) === this.root ? this.#liveNodes : new WeakMap()),
135
+ resolvers: new Map(),
136
+ usedPrograms: new Set(),
137
+ closed: false,
138
+ queue: Promise.resolve(),
139
+ };
140
+ this.#views.add(view);
141
+ return view;
142
+ }
143
+ #assert(view) {
144
+ if (this.#closed || view.closed || !this.#views.has(view)) throw new Error("Analysis revision is no longer available.");
145
+ }
146
+ /** Ingest a fenced live inventory. Contents come from the caller's input read. */
147
+ async synchronize(entries, dependencyRevision = "") {
148
+ if (this.#closed) throw new Error("Analysis project is closed.");
149
+ const files = this.#normalize(entries);
150
+ for (const [file, content] of files) if (content === null) files.delete(file);
151
+ const previous = this.#baseline;
152
+ const changes = this.#changes(previous?.files ?? new Map(), files);
153
+ const externalChanged = this.#refreshExternal();
154
+ if (previous && !changes.size && !externalChanged && previous.dependencyRevision === dependencyRevision) return previous;
155
+ const snapshot = previous
156
+ ? await previous.snapshot.update(this.#layer(changes, previous.files, externalChanged || previous.dependencyRevision !== dependencyRevision))
157
+ : await this.#api.createSnapshot({ fileSystem: createFileSystemLayer([...files]) });
158
+ this.#generation++;
159
+ this.stats.baselines++;
160
+ const view = this.#record(
161
+ this.root,
162
+ snapshot,
163
+ files,
164
+ previous ? previous.tree.withChanges(changes) : new FileTree().withChanges(files),
165
+ previous?.programs,
166
+ );
167
+ view.dependencyRevision = dependencyRevision;
168
+ this.#baseline = view;
169
+ if (previous) await this.release(previous);
170
+ return view;
171
+ }
172
+ /** Fork a full candidate inventory; only its delta crosses the compiler API. */
173
+ async branch(root, entries) {
174
+ if (!this.#baseline) throw new Error("Supply a live baseline before a draft.");
175
+ if (this.#views.size >= 32) throw new Error("Too many active analysis revisions.");
176
+ const files = this.#normalize(entries);
177
+ for (const [file, content] of files) if (content === null) files.delete(file);
178
+ const changes = this.#changes(this.#baseline.files, files);
179
+ const snapshot = await this.#baseline.snapshot.update(this.#layer(changes, this.#baseline.files));
180
+ this.stats.branches++;
181
+ return this.#record(root, snapshot, files, this.#baseline.tree.withChanges(changes), this.#baseline.programs);
182
+ }
183
+ async update(view, entries) {
184
+ this.#assert(view);
185
+ if (view === this.#baseline) throw new Error("Use synchronize for live inputs.");
186
+ const files = this.#normalize(entries);
187
+ for (const [file, content] of files) if (content === null) files.delete(file);
188
+ const changes = this.#changes(view.files, files);
189
+ if (!changes.size) return view;
190
+ const snapshot = await view.snapshot.update(this.#layer(changes, view.files));
191
+ const next = this.#record(view.root, snapshot, files, view.tree.withChanges(changes), view.programs, view.generation, view.nodes);
192
+ await this.release(view);
193
+ return next;
194
+ }
195
+ text(view, file) {
196
+ this.#assert(view);
197
+ return view.tree.get(path.resolve(this.root, path.relative(view.root, file)));
198
+ }
199
+ files(view, directory) {
200
+ this.#assert(view);
201
+ return view.tree.files(path.resolve(this.root, path.relative(view.root, directory)))
202
+ .map((file) => path.resolve(view.root, path.relative(this.root, file)));
203
+ }
204
+ async source(view, file) {
205
+ this.#assert(view);
206
+ for (const pending of view.adapters.values()) {
207
+ const program = await pending;
208
+ if (program.hasSourceFile(file)) return program.getSourceFile(file);
209
+ }
210
+ const roots = [...view.files.keys()].filter((file) => /\.[cm]?[jt]sx?$/.test(file)).map((file) => path.resolve(view.root, path.relative(this.root, file)));
211
+ return (
212
+ await this.program(view, "syntax", roots, {
213
+ allowJs: true,
214
+ noResolve: true,
215
+ noLib: true,
216
+ types: [],
217
+ target: ts.ScriptTarget.Latest,
218
+ module: ts.ModuleKind.ESNext,
219
+ jsx: ts.JsxEmit.Preserve,
220
+ })
221
+ ).getSourceFile(file);
222
+ }
223
+ async resolve(view, specifier, file, compilerOptions) {
224
+ this.#assert(view);
225
+ const compiler = nativeCompilerOptions(relocate(compilerOptions, view.root, this.root), this.root),
226
+ key = JSON.stringify(compiler);
227
+ if (!view.resolvers.has(key)) view.resolvers.set(key, this.#api.createModuleResolver(compiler));
228
+ const directory = relocate(path.dirname(file), view.root, this.root);
229
+ const result = await (await view.resolvers.get(key)).resolveModuleName(specifier, directory, undefined, { snapshot: view.snapshot });
230
+ return result.resolvedModule && relocate(result.resolvedModule.resolvedFileName, this.root, view.root);
231
+ }
232
+ /** Rules call through the context; this is the only native program factory. */
233
+ program(view, purpose, rootNames, compilerOptions) {
234
+ const pending = view.queue.then(() => this.#program(view, purpose, rootNames, compilerOptions));
235
+ view.queue = pending.then(
236
+ () => {},
237
+ () => {},
238
+ );
239
+ return pending;
240
+ }
241
+ async #program(view, _purpose, rootNames, compilerOptions) {
242
+ this.#assert(view);
243
+ const canonical = (value) => relocate(value, view.root, this.root);
244
+ const roots = rootNames.map(canonical),
245
+ compiler = nativeCompilerOptions(canonical(compilerOptions), this.root);
246
+ const key = JSON.stringify([roots, compiler]);
247
+ view.usedPrograms.add(key);
248
+ if (view.adapters.has(key)) return view.adapters.get(key);
249
+ let id = view.programs.get(key);
250
+ if (!id) {
251
+ let next;
252
+ if (view.programs.size >= 32) {
253
+ const retained = [...view.programs.keys()].filter((candidate) => view.usedPrograms.has(candidate));
254
+ if (retained.length >= 32) throw new Error("Too many distinct compiler configurations in one analysis revision.");
255
+ // 7.1 beta can crash when removing a dirty program from an incremental
256
+ // snapshot. Compact infrequently into a fresh snapshot on the SAME API
257
+ // process; keep old snapshots alive for facades used by this request.
258
+ const keys = [...retained, key];
259
+ next = await this.#api.createSnapshot({
260
+ fileSystem: createFileSystemLayer([...view.files]),
261
+ createPrograms: keys.map((key) => {
262
+ const [rootFiles, compilerOptions] = JSON.parse(key);
263
+ return { rootFiles, compilerOptions };
264
+ }),
265
+ });
266
+ view.programs = new Map(keys.map((key, index) => [key, next.operation.createdPrograms[index].id]));
267
+ id = view.programs.get(key);
268
+ this.stats.compactions++;
269
+ } else {
270
+ next = await view.snapshot.update({ createPrograms: [{ rootFiles: roots, compilerOptions: compiler }] });
271
+ id = next.operation.createdPrograms[0].id;
272
+ }
273
+ view.snapshot = next;
274
+ view.snapshots.add(next);
275
+ view.programs.set(key, id);
276
+ this.stats.programs++;
277
+ }
278
+ const program = adaptProgram({ snapshot: view.snapshot, id, root: view.root, canonicalRoot: this.root, rootNames, compilerOptions, nodes: view.nodes });
279
+ view.adapters.set(key, program);
280
+ return program;
281
+ }
282
+ async promote(view) {
283
+ this.#assert(view);
284
+ if (view.generation !== this.#generation) throw new Error("Live inputs changed; the draft must be rebased.");
285
+ if (view === this.#baseline) return;
286
+ const previous = this.#baseline;
287
+ view.dependencyRevision = previous.dependencyRevision;
288
+ this.#generation++;
289
+ view.generation = this.#generation;
290
+ this.#baseline = view;
291
+ await this.release(previous);
292
+ // Program inventory is bounded and compacted in program(), without the
293
+ // beta compiler's unsafe removePrograms operation.
294
+ view.root = this.root;
295
+ view.adapters.clear();
296
+ view.nodes = this.#liveNodes;
297
+ for (const snapshot of view.snapshots) if (snapshot !== view.snapshot) await snapshot.dispose();
298
+ view.snapshots = new Set([view.snapshot]);
299
+ }
300
+ async release(view) {
301
+ this.#assert(view);
302
+ if (view === this.#baseline) return;
303
+ view.closed = true;
304
+ view.adapters.clear();
305
+ view.nodes = undefined;
306
+ this.#views.delete(view);
307
+ for (const resolver of view.resolvers.values()) await (await resolver).dispose();
308
+ view.resolvers.clear();
309
+ for (const snapshot of view.snapshots) await snapshot.dispose();
310
+ view.snapshots.clear();
311
+ }
312
+ async close() {
313
+ if (this.#closed) return;
314
+ this.#baseline = undefined;
315
+ try {
316
+ for (const view of this.#views) await this.release(view);
317
+ } finally {
318
+ this.#closed = true;
319
+ this.#liveNodes = new WeakMap();
320
+ await this.#api.close();
321
+ }
322
+ }
323
+ }
@@ -0,0 +1,133 @@
1
+ // Every owner is an object belonging to one immutable native snapshot. Neither
2
+ // successful results nor pending requests can leak into a changed snapshot.
3
+ const owners = new WeakMap();
4
+ const batchMethods = new Set(["getSymbolAtLocation", "getTypeAtLocation"]);
5
+
6
+ function state(owner) {
7
+ let value = owners.get(owner);
8
+ if (!value) owners.set(owner, (value = { calls: new Map(), ids: new WeakMap(), sequence: 0, batches: new Map() }));
9
+ return value;
10
+ }
11
+ function argumentKey(value, cache) {
12
+ if (value && typeof value === "object") {
13
+ if (!cache.ids.has(value)) cache.ids.set(value, ++cache.sequence);
14
+ return `object:${cache.ids.get(value)}`;
15
+ }
16
+ return `${typeof value}:${String(value)}`;
17
+ }
18
+
19
+ /** Memoize pending requests too. Failed requests are retryable, including cancellation. */
20
+ export function query(owner, method, ...args) {
21
+ const cache = state(owner),
22
+ key = JSON.stringify([method, ...args.map((value) => argumentKey(value, cache))]);
23
+ if (cache.calls.has(key)) return cache.calls.get(key);
24
+ let promise;
25
+ if (batchMethods.has(method) && args.length === 1 && args[0] && !Array.isArray(args[0])) {
26
+ promise = new Promise((resolve, reject) => {
27
+ let batch = cache.batches.get(method);
28
+ if (!batch) {
29
+ cache.batches.set(method, (batch = []));
30
+ queueMicrotask(async () => {
31
+ cache.batches.delete(method);
32
+ for (let index = 0; index < batch.length; index += 256) {
33
+ const part = batch.slice(index, index + 256);
34
+ try {
35
+ const results = await owner[method](part.map((item) => item.node));
36
+ if (results.length !== part.length) throw new Error("Native query batch returned an incomplete result.");
37
+ part.forEach((item, offset) => item.resolve(results[offset]));
38
+ } catch (error) {
39
+ part.forEach((item) => item.reject(error));
40
+ }
41
+ }
42
+ });
43
+ }
44
+ batch.push({ node: args[0], resolve, reject });
45
+ });
46
+ } else promise = Promise.resolve().then(() => owner[method](...args));
47
+ cache.calls.set(key, promise);
48
+ promise.catch(() => {
49
+ if (cache.calls.get(key) === promise) cache.calls.delete(key);
50
+ });
51
+ return promise;
52
+ }
53
+
54
+ /** Resolve declaration handles through the same immutable-owner cache. */
55
+ export function declaration(handle) {
56
+ return handle ? query(handle, "resolve") : Promise.resolve(undefined);
57
+ }
58
+
59
+ /** Ordered asynchronous callbacks: short-circuiting and visitor order are preserved. */
60
+ export async function eachChild(node, visit) {
61
+ const children = [];
62
+ node.forEachChild((child) => {
63
+ children.push(child);
64
+ });
65
+ for (const child of children) {
66
+ const result = await visit(child);
67
+ if (result) return result;
68
+ }
69
+ }
70
+ export async function mapAsync(values, visit) {
71
+ const result = [];
72
+ for (let index = 0; index < values.length; index++) result.push(await visit(values[index], index, values));
73
+ return result;
74
+ }
75
+ export async function filterAsync(values, visit) {
76
+ const result = [];
77
+ for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) result.push(values[index]);
78
+ return result;
79
+ }
80
+ export async function someAsync(values, visit) {
81
+ for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) return true;
82
+ return false;
83
+ }
84
+ export async function everyAsync(values, visit) {
85
+ for (let index = 0; index < values.length; index++) if (!(await visit(values[index], index, values))) return false;
86
+ return true;
87
+ }
88
+ export async function findAsync(values, visit) {
89
+ for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) return values[index];
90
+ }
91
+ export async function flatMapAsync(values, visit) {
92
+ return (await mapAsync(values, visit)).flat();
93
+ }
94
+ export async function forEachAsync(values, visit) {
95
+ for (let index = 0; index < values.length; index++) await visit(values[index], index, values);
96
+ }
97
+ export async function findIndexAsync(values, visit) {
98
+ for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) return index;
99
+ return -1;
100
+ }
101
+ export async function reduceAsync(values, visit, ...initial) {
102
+ let index = 0,
103
+ result;
104
+ if (initial.length) result = initial[0];
105
+ else {
106
+ if (!values.length) throw new TypeError("Reduce of empty array with no initial value");
107
+ result = values[index++];
108
+ }
109
+ for (; index < values.length; index++) result = await visit(result, values[index], index, values);
110
+ return result;
111
+ }
112
+ /** Read-only PostCSS walk: false stops the walk, as it does in PostCSS. */
113
+ export async function walkAsync(tree, method, ...args) {
114
+ const visit = args.pop(),
115
+ nodes = [];
116
+ tree[method](...args, (...parameters) => {
117
+ nodes.push(parameters);
118
+ });
119
+ for (const parameters of nodes) if ((await visit(...parameters)) === false) break;
120
+ return tree;
121
+ }
122
+
123
+ /** Value-parser walk: false prunes a function's children, not its siblings. */
124
+ export async function walkValuesAsync(tree, visit) {
125
+ async function walk(nodes) {
126
+ for (let index = 0; index < nodes.length; index++) {
127
+ const node = nodes[index];
128
+ if ((await visit(node, index, nodes)) !== false && node.type === "function" && Array.isArray(node.nodes)) await walk(node.nodes);
129
+ }
130
+ }
131
+ await walk(tree.nodes);
132
+ return tree;
133
+ }