@reqvire-org/ads 0.3.53 → 0.4.2
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.
- package/README.md +114 -94
- package/dist/a11y.mjs +108 -29
- package/dist/analysis/compiler-options.mjs +13 -0
- package/dist/analysis/context.mjs +46 -0
- package/dist/analysis/file-tree.mjs +52 -0
- package/dist/analysis/helpers.mjs +140 -0
- package/dist/analysis/impact.mjs +20 -0
- package/dist/analysis/inputs.mjs +15 -0
- package/dist/analysis/native-adapter.mjs +180 -0
- package/dist/analysis/native-project.mjs +323 -0
- package/dist/analysis/queries.mjs +133 -0
- package/dist/analysis/service.mjs +146 -0
- package/dist/analysis/standalone.mjs +57 -0
- package/dist/analysis/syntax.mjs +164 -0
- package/dist/analysis/worker.mjs +182 -0
- package/dist/assets.mjs +6 -6
- package/dist/atomic-composition.mjs +191 -70
- package/dist/atomic-trace.mjs +120 -50
- package/dist/behavior-libraries.mjs +106 -37
- package/dist/behaviors.mjs +222 -79
- package/dist/boundaries.mjs +137 -40
- package/dist/brand-assets.mjs +219 -47
- package/dist/brands.mjs +86 -27
- package/dist/bun-compiler.mjs +34 -13
- package/dist/bun-worker.mjs +7 -5
- package/dist/capture/worker.mjs +15 -4
- package/dist/capture-store.mjs +4 -2
- package/dist/capture.mjs +17 -14
- package/dist/check-service.mjs +66 -0
- package/dist/check.mjs +756 -196
- package/dist/cli.mjs +203 -100
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +2 -2
- package/dist/config.mjs +308 -163
- package/dist/construction-styles.cjs +10 -0
- package/dist/contracts.d.mts +9 -0
- package/dist/control-padding.mjs +45 -25
- package/dist/css-values.mjs +3 -2
- package/dist/declarative-flow.mjs +209 -109
- package/dist/design-values.mjs +136 -51
- package/dist/development-runtime.mjs +4 -6
- package/dist/draft-boundary.mjs +11 -6
- package/dist/evidence.mjs +1 -1
- package/dist/finding-rules.mjs +7 -5
- package/dist/font-rules.mjs +2 -2
- package/dist/fonts-generated.mjs +4 -2
- package/dist/foundation-views.mjs +238 -0
- package/dist/foundation.mjs +63 -39
- package/dist/generated-entries.mjs +198 -0
- package/dist/icons.mjs +80 -33
- package/dist/image-attributes.mjs +109 -36
- package/dist/image-size.mjs +1 -1
- package/dist/index.mjs +0 -2
- package/dist/init.mjs +128 -68
- package/dist/investigations.mjs +2 -2
- package/dist/layers.mjs +300 -127
- package/dist/layout-widths.mjs +180 -85
- package/dist/linaria/preserve-values.cjs +7 -0
- package/dist/linaria/spatial-inputs.cjs +56 -0
- package/dist/lockup-composition.mjs +44 -0
- package/dist/lockup-model.cjs +64 -0
- package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
- package/dist/mcp/apps.mjs +4 -30
- package/dist/mcp/behavior-pages.mjs +72 -24
- package/dist/mcp/build-status.mjs +257 -64
- package/dist/mcp/catalog.mjs +91 -26
- package/dist/mcp/context.mjs +17 -18
- package/dist/mcp/draft-discovery.mjs +44 -21
- package/dist/mcp/drafts.mjs +978 -343
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +701 -219
- package/dist/mcp/preview-watch.mjs +465 -161
- package/dist/mcp/preview-widget.bundle.js +44 -50
- package/dist/mcp/prompts.mjs +6 -6
- package/dist/mcp/result-pages.mjs +1 -1
- package/dist/mcp/sandbox-host.mjs +1 -1
- package/dist/mcp/server.mjs +2436 -570
- package/dist/mcp/showcase-host.mjs +176 -39
- package/dist/mcp/skills.mjs +1 -1
- package/dist/mcp/text-diff.mjs +29 -10
- package/dist/paint-contracts.mjs +174 -81
- package/dist/palette-generated.mjs +2 -2
- package/dist/preview-bun.mjs +493 -187
- package/dist/preview-failure.mjs +1 -1
- package/dist/preview-files.mjs +13 -13
- package/dist/preview-imports.mjs +104 -55
- package/dist/preview-inputs.mjs +2 -2
- package/dist/preview-requests.mjs +24 -0
- package/dist/preview-resources.mjs +288 -147
- package/dist/preview-scope.mjs +5 -4
- package/dist/program-cache.mjs +10 -0
- package/dist/project-documents.mjs +1 -1
- package/dist/public-api.mjs +70 -31
- package/dist/public-props.mjs +39 -22
- package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
- package/dist/{browser-audit → render-audit}/image-shape.mjs +2 -2
- package/dist/{browser-audit → render-audit}/layout-overflow.mjs +86 -23
- package/dist/{browser-audit → render-audit}/non-text-contrast.mjs +86 -27
- package/dist/{browser-audit → render-audit}/render-states.mjs +208 -52
- package/dist/{browser-audit → render-audit}/worker.mjs +86 -30
- package/dist/render-audit.mjs +828 -0
- package/dist/render-color-probe.mjs +96 -42
- package/dist/resource-limits.mjs +229 -97
- package/dist/runtime-contracts.mjs +467 -185
- package/dist/scenario-groups.mjs +22 -10
- package/dist/scenario-inspector.mjs +6 -43
- package/dist/scenario-program.mjs +8 -25
- package/dist/scenario-registry.mjs +72 -30
- package/dist/scenario-selectors.mjs +161 -64
- package/dist/scenario-slots.mjs +149 -56
- package/dist/scenario-trace.mjs +215 -109
- package/dist/scenarios-compiler.mjs +768 -359
- package/dist/scenarios-vite.d.mts +1 -3
- package/dist/scenarios-vite.mjs +2 -81
- package/dist/scenarios.mjs +424 -159
- package/dist/selector-match.mjs +2 -2
- package/dist/showcase/client.bundle.js +57 -56
- package/dist/showcase/draft-navigation.js +18 -0
- package/dist/showcase/favicon.ico +0 -0
- package/dist/showcase/favicon.svg +1 -0
- package/dist/showcase/foundation-view.css +55 -0
- package/dist/showcase/foundation-view.mjs +252 -0
- package/dist/showcase/guide-controls.ads.review.mjs +32 -0
- package/dist/showcase/icons.js +1 -145
- package/dist/showcase/index.html +3 -31
- package/dist/showcase/preview-frame.ads.review.css +46 -0
- package/dist/showcase/preview-frame.ads.review.d.mts +11 -0
- package/dist/showcase/preview-frame.ads.review.mjs +22 -0
- package/dist/showcase/preview-state.js +0 -9
- package/dist/showcase/refresh-scheduler.js +23 -0
- package/dist/showcase/style.css +5 -47
- package/dist/showcase/ui/ui.css +1353 -0
- package/dist/showcase/ui/ui.js +1062 -0
- package/dist/showcase-coverage.mjs +58 -37
- package/dist/skills/README.md +24 -23
- package/dist/skills/ads-designer/README.md +8 -2
- package/dist/skills/ads-designer/SKILL.md +152 -144
- package/dist/skills/ads-designer/references/accessibility.md +14 -11
- package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
- package/dist/skills/ads-designer/references/behaviors.md +34 -30
- package/dist/skills/ads-designer/references/branding.md +98 -10
- package/dist/skills/ads-designer/references/captures.md +31 -31
- package/dist/skills/ads-designer/references/cli.md +21 -20
- package/dist/skills/ads-designer/references/contracts.md +63 -29
- package/dist/skills/ads-designer/references/design-data.md +49 -52
- package/dist/skills/ads-designer/references/drafts.md +71 -52
- package/dist/skills/ads-designer/references/evidence.md +1 -5
- package/dist/skills/ads-designer/references/guarded-editing.md +58 -51
- package/dist/skills/ads-designer/references/layers.md +1 -1
- package/dist/skills/ads-designer/references/layout.md +347 -0
- package/dist/skills/ads-designer/references/mobile.md +2 -1
- package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
- package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
- package/dist/skills/ads-designer/references/performance.md +3 -2
- package/dist/skills/ads-designer/references/review.md +42 -38
- package/dist/skills/ads-designer/references/runtimes.md +33 -30
- package/dist/skills/ads-designer/references/scenarios.md +17 -19
- package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
- package/dist/skills/ads-designer/references/stress-test.md +68 -0
- package/dist/skills/ads-designer/references/validation.md +83 -71
- package/dist/skills/ads-designer/references/workflows.md +19 -37
- package/dist/skills/ads-import/SKILL.md +43 -328
- package/dist/skills/ads-import/references/atomic-styles.md +4 -4
- package/dist/skills/ads-import/references/behaviors.md +34 -30
- package/dist/skills/ads-import/references/branding.md +5 -5
- package/dist/skills/ads-import/references/captures.md +31 -31
- package/dist/skills/ads-import/references/cli.md +21 -20
- package/dist/skills/ads-import/references/compatibility.md +1 -1
- package/dist/skills/ads-import/references/contracts.md +63 -29
- package/dist/skills/ads-import/references/design-data.md +49 -52
- package/dist/skills/ads-import/references/drafts.md +71 -52
- package/dist/skills/ads-import/references/evidence.md +1 -5
- package/dist/skills/ads-import/references/guarded-editing.md +58 -51
- package/dist/skills/ads-import/references/implementation.md +2 -1
- package/dist/skills/ads-import/references/layers.md +1 -1
- package/dist/skills/ads-import/references/layout.md +347 -0
- package/dist/skills/ads-import/references/review.md +42 -38
- package/dist/skills/ads-import/references/runtimes.md +33 -30
- package/dist/skills/ads-import/references/scenarios.md +17 -19
- package/dist/skills/ads-import/references/tokens.md +3 -3
- package/dist/skills/ads-import/references/validation.md +83 -71
- package/dist/skills/ads-import/references/workflows.md +19 -37
- package/dist/skills/ads-migrate/SKILL.md +56 -0
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
- package/dist/skills/ads-port/SKILL.md +54 -346
- package/dist/skills/ads-port/references/atomic-styles.md +4 -4
- package/dist/skills/ads-port/references/behaviors.md +34 -30
- package/dist/skills/ads-port/references/captures.md +31 -31
- package/dist/skills/ads-port/references/cli.md +21 -20
- package/dist/skills/ads-port/references/contracts.md +63 -29
- package/dist/skills/ads-port/references/design-data.md +49 -52
- package/dist/skills/ads-port/references/drafts.md +71 -52
- package/dist/skills/ads-port/references/evidence.md +1 -5
- package/dist/skills/ads-port/references/guarded-editing.md +58 -51
- package/dist/skills/ads-port/references/layers.md +1 -1
- package/dist/skills/ads-port/references/layout.md +347 -0
- package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
- package/dist/skills/ads-port/references/native-implementation.md +8 -7
- package/dist/skills/ads-port/references/review.md +42 -38
- package/dist/skills/ads-port/references/runtimes.md +33 -30
- package/dist/skills/ads-port/references/scenarios.md +17 -19
- package/dist/skills/ads-port/references/validation.md +83 -71
- package/dist/skills/ads-port/references/workflows.md +19 -37
- package/dist/source-symbols.mjs +1 -8
- package/dist/source-values.mjs +266 -128
- package/dist/spatial-composition.mjs +322 -0
- package/dist/spatial-contexts.cjs +56 -0
- package/dist/spatial-css.cjs +351 -0
- package/dist/spatial-inputs.cjs +80 -0
- package/dist/spatial-metadata.mjs +18 -0
- package/dist/spatial-model.cjs +322 -0
- package/dist/spatial.mjs +21 -0
- package/dist/stage-timing.cjs +20 -0
- package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +275 -0
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +8 -0
- package/dist/starters/preact/ds.config.json +24 -19
- package/dist/starters/preact/package.json +4 -8
- package/dist/starters/preact/tsconfig.json +4 -5
- package/dist/starters/preact/vite.config.ts +3 -3
- package/dist/starters/react/ADS.md +42 -47
- package/dist/starters/react/README.md +54 -52
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +18 -2
- package/dist/starters/react/design-system/components/Actions/IconButton/README.md +3 -0
- package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +5 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
- package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/index.ts +5 -8
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
- package/dist/starters/react/design-system/styles.css +1 -0
- package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
- package/dist/starters/react/design-system/tokens/colors.css +1 -1
- package/dist/starters/react/design-system/tokens/spacing.css +22 -32
- package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
- package/dist/starters/react/ds.config.json +24 -19
- package/dist/starters/react/package.json +2 -6
- package/dist/starters/react/tsconfig.json +2 -3
- package/dist/starters/react/vite.config.ts +3 -3
- package/dist/style-boundaries.mjs +73 -27
- package/dist/task-cache.mjs +173 -72
- package/dist/task-worker.mjs +22 -11
- package/dist/test-boundaries.mjs +133 -60
- package/dist/themes-generated.mjs +1 -1
- package/dist/themes-watch.mjs +60 -19
- package/dist/themes.mjs +176 -73
- package/dist/token-export.mjs +39 -14
- package/dist/token-policy.mjs +6 -3
- package/dist/token-quality.mjs +6 -6
- package/dist/token-samples.mjs +16 -5
- package/dist/tokens.mjs +71 -26
- package/dist/ui-framework.mjs +16 -14
- package/dist/unit-contracts.mjs +270 -89
- package/dist/units.mjs +215 -180
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +121 -38
- package/dist/validation-inputs.mjs +187 -78
- package/dist/validation.mjs +268 -102
- package/dist/verification/browser.mjs +27 -5
- package/dist/verification.mjs +711 -187
- package/docs/ADS.md +100 -89
- package/docs/ARCHITECTURE.md +353 -159
- package/docs/BEHAVIORS.md +33 -28
- package/docs/CACHING.md +55 -11
- package/docs/CHANGELOG.md +358 -17
- package/docs/COMPARISON.md +1 -1
- package/docs/CONTRACTS.md +22 -29
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +313 -292
- package/docs/MCP.md +261 -439
- package/docs/SPATIAL-CHECKS.md +69 -0
- package/docs/benchmarks/README.md +39 -0
- package/package.json +42 -34
- package/dist/browser-audit.mjs +0 -424
- package/dist/contract-migration.mjs +0 -110
- package/dist/create.mjs +0 -48
- package/dist/lint-config.mjs +0 -48
- package/dist/mcp/draft-exports.mjs +0 -40
- package/dist/mcp/edit-preparation.mjs +0 -115
- package/dist/mcp/project-widget.bundle.js +0 -114
- package/dist/mcp/reports.mjs +0 -101
- package/dist/mcp/widget.bundle.js +0 -147
- package/dist/oxlint.mjs +0 -88
- package/dist/preview-builder.mjs +0 -133
- package/dist/preview-workers.mjs +0 -184
- package/dist/showcase.mjs +0 -77
- package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
- package/dist/skills/ads-break-ui/README.md +0 -16
- package/dist/skills/ads-break-ui/SKILL.md +0 -415
- package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
- package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
- package/dist/skills/ads-break-ui/references/behaviors.md +0 -411
- package/dist/skills/ads-break-ui/references/captures.md +0 -160
- package/dist/skills/ads-break-ui/references/contracts.md +0 -284
- package/dist/skills/ads-break-ui/references/design-data.md +0 -354
- package/dist/skills/ads-break-ui/references/drafts.md +0 -178
- package/dist/skills/ads-break-ui/references/evidence.md +0 -128
- package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -154
- package/dist/skills/ads-break-ui/references/layers.md +0 -145
- package/dist/skills/ads-break-ui/references/reporting.md +0 -101
- package/dist/skills/ads-break-ui/references/review.md +0 -96
- package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
- package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
- package/dist/skills/ads-break-ui/references/validation.md +0 -162
- package/dist/skills/ads-break-ui/references/verification.md +0 -58
- package/dist/skills/ads-break-ui/references/workflows.md +0 -83
- package/dist/skills/ads-designer/references/reporting.md +0 -101
- package/dist/skills/ads-import/references/reporting.md +0 -101
- package/dist/skills/ads-motion/LICENSE.upstream +0 -21
- package/dist/skills/ads-motion/README.md +0 -22
- package/dist/skills/ads-motion/SKILL.md +0 -388
- package/dist/skills/ads-motion/agents/openai.yaml +0 -4
- package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
- package/dist/skills/ads-motion/references/audit.md +0 -44
- package/dist/skills/ads-motion/references/behaviors.md +0 -411
- package/dist/skills/ads-motion/references/captures.md +0 -160
- package/dist/skills/ads-motion/references/contracts.md +0 -284
- package/dist/skills/ads-motion/references/design-data.md +0 -354
- package/dist/skills/ads-motion/references/drafts.md +0 -178
- package/dist/skills/ads-motion/references/evidence.md +0 -128
- package/dist/skills/ads-motion/references/guarded-editing.md +0 -154
- package/dist/skills/ads-motion/references/layers.md +0 -145
- package/dist/skills/ads-motion/references/motion-review.md +0 -35
- package/dist/skills/ads-motion/references/reporting.md +0 -101
- package/dist/skills/ads-motion/references/review.md +0 -96
- package/dist/skills/ads-motion/references/runtimes.md +0 -203
- package/dist/skills/ads-motion/references/scenarios.md +0 -246
- package/dist/skills/ads-motion/references/validation.md +0 -162
- package/dist/skills/ads-motion/references/verification.md +0 -39
- package/dist/skills/ads-motion/references/workflows.md +0 -83
- package/dist/skills/ads-port/references/reporting.md +0 -101
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
- package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
- package/dist/starters/react/design-system/review/index.ts +0 -5
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
- package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
- package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
- package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
- package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
- package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
- package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
- package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
- package/dist/starters/react/package-lock.json +0 -4707
- package/dist/token-fixtures.mjs +0 -30
- package/docs/benchmarks/bun-previews.md +0 -91
- package/docs/benchmarks/preview-memory.md +0 -147
- package/docs/benchmarks/turbo-poc.md +0 -284
- package/docs/plans/execution-coordination.md +0 -57
- /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
- /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { analyze } from "./analysis/service.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { loadConfig } from "./config.mjs";
|
|
8
|
+
|
|
9
|
+
import { executeDevelopmentCommand } from "./verification.mjs";
|
|
10
|
+
import { findingSeverity, routeFindings } from "./finding-rules.mjs";
|
|
11
|
+
import { inspectScenarios } from "./scenarios.mjs";
|
|
12
|
+
import { inspectUnits } from "./units.mjs";
|
|
13
|
+
import { globMatcher } from "./layout-widths.mjs";
|
|
14
|
+
import { affectedScenarios } from "./verification.mjs";
|
|
15
|
+
|
|
16
|
+
// Render audit: axe-core (Deque, MPL-2.0, an unmodified ADS dependency
|
|
17
|
+
// injected at run time, never bundled) runs inside each rendered scenario document, once per
|
|
18
|
+
// declared brand and theme, followed by ADS's own non-text contrast check (WCAG 1.4.11),
|
|
19
|
+
// which axe does not cover, and its layout-overflow check, which resizes the same page. Only the scenario's #root is audited; the preview status chrome is excluded.
|
|
20
|
+
// Findings are errors: they fail `ads audit`, ads_validate (which audits everything its change set
|
|
21
|
+
// reaches) and draft acceptance (the draft owners' scenarios, unless acceptance.audit is false).
|
|
22
|
+
// Automated rules catch a subset of WCAG failures; passing proves nothing more.
|
|
23
|
+
|
|
24
|
+
export const AUDIT_RULE = "a11y-axe";
|
|
25
|
+
/** What axe could not decide on its own, such as contrast over a gradient: to check by hand. */
|
|
26
|
+
export const INCOMPLETE_RULE = "a11y-incomplete";
|
|
27
|
+
/** ADS's own rendered check: WCAG 1.4.11 non-text contrast of control boundaries and icons (axe does not check it). */
|
|
28
|
+
export const NON_TEXT_RULE = "a11y-non-text-contrast";
|
|
29
|
+
/** ADS's own rendered layout check: horizontal overflow at each of overflowWidths. */
|
|
30
|
+
export const OVERFLOW_RULE = "layout-overflow";
|
|
31
|
+
export const NARROW_RULE = "layout-overflow-narrow";
|
|
32
|
+
/** ADS's own rendered check: a scenario's layout shift above the Core Web Vitals 0.1 threshold. */
|
|
33
|
+
export const SHIFT_RULE = "layout-shift";
|
|
34
|
+
const shiftLimit = 0.1;
|
|
35
|
+
/** WCAG A/AA rule tags. Best-practice and page-level rules (landmarks, one h1) don't fit isolated scenarios. */
|
|
36
|
+
export const auditTags = Object.freeze(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]);
|
|
37
|
+
const viewport = { width: 1280, height: 800 };
|
|
38
|
+
/** Viewport widths layout-overflow renders every scenario at: phone, tablet and desktop. */
|
|
39
|
+
export const overflowWidths = Object.freeze([390, 768, 1280]);
|
|
40
|
+
export const auditedKinds = Object.freeze(["components", "patterns", "composition"]);
|
|
41
|
+
/** The width layout-overflow also renders scenarios of these kinds at, inside the widest viewport
|
|
42
|
+
* and in the first theme, since layout does not follow color: a narrow side pane. A composition is
|
|
43
|
+
* a whole screen, and is never hosted in one. */
|
|
44
|
+
export const containerWidth = 240;
|
|
45
|
+
export const containerKinds = Object.freeze(["components", "patterns"]);
|
|
46
|
+
/** Attempts for one render, against a dropped preview connection or a slow preview. */
|
|
47
|
+
export const auditAttempts = 3;
|
|
48
|
+
/** overlays and controls bound what each render opens and hovers: distinct ones, in document order. */
|
|
49
|
+
const limits = { scenarios: 500, nodes: 5, findings: 2000, reportBytes: 8 * 1024 * 1024, overlays: 3, controls: 6, contentQuietMs: 500, contentLimitMs: 5000 };
|
|
50
|
+
|
|
51
|
+
/** WCAG success criteria named by axe tags such as wcag143 or wcag1412. */
|
|
52
|
+
export function wcagCriteria(tags) {
|
|
53
|
+
return [
|
|
54
|
+
...new Set(
|
|
55
|
+
tags
|
|
56
|
+
.map((tag) => tag.match(/^wcag(\d)(\d)(\d{1,2})$/))
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.map(([, a, b, c]) => `${a}.${b}.${c}`),
|
|
59
|
+
),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Collapse per-brand, per-theme axe violations into ADS errors: one per scenario, rule and failing element set. */
|
|
64
|
+
export function auditFindings(runs, scenarios) {
|
|
65
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
66
|
+
groups = new Map();
|
|
67
|
+
const add = (list, value) => {
|
|
68
|
+
if (value !== undefined && !list.includes(value)) list.push(value);
|
|
69
|
+
};
|
|
70
|
+
for (const run of runs)
|
|
71
|
+
for (const violation of run.violations) {
|
|
72
|
+
const selectors = violation.nodes.map((node) => node.selector);
|
|
73
|
+
const key = JSON.stringify([run.scenario, violation.id, [...selectors].sort()]);
|
|
74
|
+
const group = groups.get(key) ?? { scenario: run.scenario, themes: [], brands: [], violation };
|
|
75
|
+
groups.set(key, group);
|
|
76
|
+
add(group.themes, run.theme);
|
|
77
|
+
add(group.brands, run.brand);
|
|
78
|
+
}
|
|
79
|
+
return [...groups.values()].slice(0, limits.findings).map(({ scenario, themes, brands, violation }) => {
|
|
80
|
+
const wcag = wcagCriteria(violation.tags),
|
|
81
|
+
contrast = violation.id === "color-contrast";
|
|
82
|
+
const where =
|
|
83
|
+
violation.nodes
|
|
84
|
+
.map((node) => node.selector)
|
|
85
|
+
.slice(0, 3)
|
|
86
|
+
.join(", ") + (violation.nodeCount > 3 ? ` and ${violation.nodeCount - 3} more` : "");
|
|
87
|
+
return {
|
|
88
|
+
rule: AUDIT_RULE,
|
|
89
|
+
severity: findingSeverity(AUDIT_RULE),
|
|
90
|
+
file: files.get(scenario) ?? scenario,
|
|
91
|
+
line: 1,
|
|
92
|
+
column: 1,
|
|
93
|
+
source: "axe-core",
|
|
94
|
+
axeRule: violation.id,
|
|
95
|
+
impact: violation.impact ?? null,
|
|
96
|
+
wcag,
|
|
97
|
+
tags: violation.tags,
|
|
98
|
+
scenario,
|
|
99
|
+
themes,
|
|
100
|
+
...(brands.length ? { brands } : {}),
|
|
101
|
+
nodes: violation.nodes,
|
|
102
|
+
nodeCount: violation.nodeCount,
|
|
103
|
+
helpUrl: violation.helpUrl,
|
|
104
|
+
guidanceUri: "ads://guides/accessibility",
|
|
105
|
+
...(contrast ? { overlaps: "token-contrast" } : {}),
|
|
106
|
+
message: `${contrast ? "Rendered contrast (render audit; token-contrast checks declared token pairs statically): " : ""}axe ${violation.id}${violation.impact ? ` (${violation.impact})` : ""}${wcag.length ? `, WCAG ${wcag.join("/")}` : ""} in ${scenario} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}]: ${violation.help}. ${violation.nodeCount} element${violation.nodeCount === 1 ? "" : "s"}: ${where}. ${violation.helpUrl}`,
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** One info item per scenario, axe rule and element set, across brands and themes. */
|
|
112
|
+
export function incompleteFindings(runs, scenarios) {
|
|
113
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
114
|
+
groups = new Map();
|
|
115
|
+
const add = (list, value) => {
|
|
116
|
+
if (value !== undefined && !list.includes(value)) list.push(value);
|
|
117
|
+
};
|
|
118
|
+
for (const run of runs)
|
|
119
|
+
for (const item of run.incomplete ?? []) {
|
|
120
|
+
const key = JSON.stringify([run.scenario, item.id, item.nodes.map((node) => node.selector).sort()]);
|
|
121
|
+
const group = groups.get(key) ?? { scenario: run.scenario, themes: [], brands: [], item };
|
|
122
|
+
groups.set(key, group);
|
|
123
|
+
add(group.themes, run.theme);
|
|
124
|
+
add(group.brands, run.brand);
|
|
125
|
+
}
|
|
126
|
+
return [...groups.values()].slice(0, limits.findings).map(({ scenario, themes, brands, item }) => {
|
|
127
|
+
const where =
|
|
128
|
+
item.nodes
|
|
129
|
+
.slice(0, 3)
|
|
130
|
+
.map((node) => `${node.selector}${node.reason ? ` (${node.reason})` : ""}`)
|
|
131
|
+
.join(", ") + (item.nodeCount > 3 ? ` and ${item.nodeCount - 3} more` : "");
|
|
132
|
+
return {
|
|
133
|
+
rule: INCOMPLETE_RULE,
|
|
134
|
+
severity: findingSeverity(INCOMPLETE_RULE),
|
|
135
|
+
file: files.get(scenario) ?? scenario,
|
|
136
|
+
line: 1,
|
|
137
|
+
column: 1,
|
|
138
|
+
source: "axe-core",
|
|
139
|
+
axeRule: item.id,
|
|
140
|
+
impact: item.impact ?? null,
|
|
141
|
+
scenario,
|
|
142
|
+
themes,
|
|
143
|
+
...(brands.length ? { brands } : {}),
|
|
144
|
+
nodes: item.nodes,
|
|
145
|
+
nodeCount: item.nodeCount,
|
|
146
|
+
helpUrl: item.helpUrl,
|
|
147
|
+
guidanceUri: "ads://guides/accessibility",
|
|
148
|
+
message: `axe could not decide ${item.id} in ${scenario} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}]: check it by hand. ${item.help}. ${item.nodeCount} element${item.nodeCount === 1 ? "" : "s"}: ${where}. ${item.helpUrl}`,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const nonTextKinds = {
|
|
154
|
+
border: {
|
|
155
|
+
what: (count) => (count === 1 ? "control's border is its only boundary and has" : "controls' borders are their only boundary and have"),
|
|
156
|
+
against: "the background around it",
|
|
157
|
+
fix: "Give the boundary a border token with 3:1 against the surface it sits on, such as --border-strong, or a background with 3:1 against it.",
|
|
158
|
+
},
|
|
159
|
+
icon: {
|
|
160
|
+
what: (count) => (count === 1 ? "icon-only control's icon has" : "icon-only controls' icons have"),
|
|
161
|
+
against: "its control's background",
|
|
162
|
+
fix: "Paint the icon with a text or foreground token that has 3:1 against the control's background.",
|
|
163
|
+
},
|
|
164
|
+
focus: {
|
|
165
|
+
what: (count) => (count === 1 ? "control's focus outline has" : "controls' focus outlines have"),
|
|
166
|
+
against: "the background around it",
|
|
167
|
+
fix: "Paint the focus outline with --border-focus or a token with 3:1 against the surface it sits on.",
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/** Collapse per-brand, per-theme non-text contrast issues into ADS errors: one per scenario, kind
|
|
172
|
+
* and failing element set, keeping each element's lowest ratio. */
|
|
173
|
+
export function nonTextContrastFindings(runs, scenarios) {
|
|
174
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
175
|
+
groups = new Map();
|
|
176
|
+
const add = (list, value) => {
|
|
177
|
+
if (value !== undefined && !list.includes(value)) list.push(value);
|
|
178
|
+
};
|
|
179
|
+
for (const run of runs)
|
|
180
|
+
for (const kind of Object.keys(nonTextKinds)) {
|
|
181
|
+
const issues = (run.nonText?.issues ?? []).filter((issue) => issue.kind === kind);
|
|
182
|
+
if (!issues.length) continue;
|
|
183
|
+
const key = JSON.stringify([run.scenario, kind, issues.map((issue) => issue.selector).sort()]);
|
|
184
|
+
const group = groups.get(key) ?? { scenario: run.scenario, kind, themes: [], brands: [], nodes: new Map(), nodeCount: 0 };
|
|
185
|
+
groups.set(key, group);
|
|
186
|
+
add(group.themes, run.theme);
|
|
187
|
+
add(group.brands, run.brand);
|
|
188
|
+
group.nodeCount = Math.max(group.nodeCount, run.nonText.counts?.[kind] ?? issues.length);
|
|
189
|
+
for (const issue of issues) {
|
|
190
|
+
const previous = group.nodes.get(issue.selector);
|
|
191
|
+
if (!previous || issue.ratio < previous.ratio)
|
|
192
|
+
group.nodes.set(issue.selector, { ...issue, theme: run.theme, ...(run.brand ? { brand: run.brand } : {}) });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return [...groups.values()].slice(0, limits.findings).map(({ scenario, kind, themes, brands, nodes, nodeCount }) => {
|
|
196
|
+
const list = [...nodes.values()],
|
|
197
|
+
ratio = Math.min(...list.map((node) => node.ratio));
|
|
198
|
+
const where =
|
|
199
|
+
list
|
|
200
|
+
.slice(0, 3)
|
|
201
|
+
.map((node) => `${node.selector} (${node.ratio.toFixed(2)}:1, ${node.foreground} on ${node.background})`)
|
|
202
|
+
.join(", ") + (nodeCount > 3 ? ` and ${nodeCount - 3} more` : "");
|
|
203
|
+
return {
|
|
204
|
+
rule: NON_TEXT_RULE,
|
|
205
|
+
severity: findingSeverity(NON_TEXT_RULE),
|
|
206
|
+
file: files.get(scenario) ?? scenario,
|
|
207
|
+
line: 1,
|
|
208
|
+
column: 1,
|
|
209
|
+
source: "ads",
|
|
210
|
+
kind,
|
|
211
|
+
wcag: ["1.4.11"],
|
|
212
|
+
scenario,
|
|
213
|
+
themes,
|
|
214
|
+
...(brands.length ? { brands } : {}),
|
|
215
|
+
ratio,
|
|
216
|
+
nodes: list,
|
|
217
|
+
nodeCount,
|
|
218
|
+
guidanceUri: "ads://guides/accessibility",
|
|
219
|
+
message: `Non-text contrast (WCAG 1.4.11) in ${scenario} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}]: ${nodeCount} ${nonTextKinds[kind].what(nodeCount)} less than 3:1 against ${nonTextKinds[kind].against}: ${where}. ${nonTextKinds[kind].fix}`,
|
|
220
|
+
};
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const skipReasons = {
|
|
225
|
+
"overlay-did-not-open": "a control with aria-haspopup opened nothing with a dialog, menu or listbox role",
|
|
226
|
+
"overlay-trigger-gone": "a trigger left the page before its turn",
|
|
227
|
+
"overlay-left-open": "an overlay did not close on Escape, so later triggers could not be reached",
|
|
228
|
+
"overlay-timeout": "a trigger could not be clicked in time",
|
|
229
|
+
"overlay-detached": "a trigger left the page or was covered while it was being clicked",
|
|
230
|
+
"overlay-failed": "opening an overlay failed",
|
|
231
|
+
"overlay-cap": "the limit of 3 triggers per render was reached and no other scenario has them",
|
|
232
|
+
"control-gone": "a control left the page before its turn",
|
|
233
|
+
"control-timeout": "a control could not be hovered in time",
|
|
234
|
+
"control-detached": "a control left the page while it was being measured",
|
|
235
|
+
"control-failed": "measuring a control failed",
|
|
236
|
+
"control-cap": "the limit of 6 controls per render was reached and no other scenario has them",
|
|
237
|
+
"content-still-changing": "the page kept changing past 5 s, so what it measured may be mid-change",
|
|
238
|
+
"focus-not-reachable": "a control a keyboard cannot reach (aria-hidden, inert, or tabindex -1 outside a roving widget): hover measured, focus not",
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const overflowKinds = {
|
|
242
|
+
document: {
|
|
243
|
+
what: "the page scrolls horizontally",
|
|
244
|
+
fix: "Find the element wider than its container; use fluid widths, min-width: 0 on flex and grid children, and let long text wrap.",
|
|
245
|
+
},
|
|
246
|
+
viewport: {
|
|
247
|
+
what: "content reaches past the viewport",
|
|
248
|
+
fix: "Make the element fluid (%, fr, a --grid-span-N token in a container query), wrap it, or put it in an overflow-x: auto scroller.",
|
|
249
|
+
},
|
|
250
|
+
container: {
|
|
251
|
+
what: "content reaches past its container",
|
|
252
|
+
fix: "Make the element fluid (%, fr, min(100%, ...)), wrap it, or put it in an overflow-x: auto scroller. A width that truly stays this wide only fits an overlay: list its owner in layout.fixedWidthUnits.",
|
|
253
|
+
},
|
|
254
|
+
clipped: {
|
|
255
|
+
what: "content is cut off by overflow hidden or clip",
|
|
256
|
+
fix: "Make the content fit, truncate it with text-overflow: ellipsis, or use overflow-x: auto if it should scroll.",
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** Collapse overflow issues into ADS errors: one per scenario, kind and failing element set, with
|
|
261
|
+
* the widths, themes and brands it fails in. */
|
|
262
|
+
export function layoutOverflowFindings(runs, scenarios) {
|
|
263
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
264
|
+
groups = new Map();
|
|
265
|
+
const add = (list, value) => {
|
|
266
|
+
if (value !== undefined && !list.includes(value)) list.push(value);
|
|
267
|
+
};
|
|
268
|
+
for (const run of runs)
|
|
269
|
+
for (const { width, container = false, issues = [], counts = {} } of run.layout ?? [])
|
|
270
|
+
for (const kind of Object.keys(overflowKinds)) {
|
|
271
|
+
const found = issues.filter((issue) => issue.kind === kind);
|
|
272
|
+
if (!found.length) continue;
|
|
273
|
+
const key = JSON.stringify([run.scenario, kind, container, found.map((issue) => issue.selector).sort()]);
|
|
274
|
+
const group = groups.get(key) ?? { scenario: run.scenario, kind, container, widths: [], themes: [], brands: [], nodes: new Map(), nodeCount: 0 };
|
|
275
|
+
groups.set(key, group);
|
|
276
|
+
add(group.widths, width);
|
|
277
|
+
add(group.themes, run.theme);
|
|
278
|
+
add(group.brands, run.brand);
|
|
279
|
+
group.nodeCount = Math.max(group.nodeCount, counts[kind] ?? found.length);
|
|
280
|
+
for (const issue of found) if (!(group.nodes.get(issue.selector)?.overflow >= issue.overflow)) group.nodes.set(issue.selector, { ...issue, width });
|
|
281
|
+
}
|
|
282
|
+
return [...groups.values()].slice(0, limits.findings).map(({ scenario, kind, container, widths, themes, brands, nodes, nodeCount }) => {
|
|
283
|
+
const list = [...nodes.values()],
|
|
284
|
+
sorted = [...widths].sort((a, b) => a - b);
|
|
285
|
+
const where =
|
|
286
|
+
list
|
|
287
|
+
.slice(0, 3)
|
|
288
|
+
.map((node) => `${node.selector} (${node.overflow}px at ${node.width}px)`)
|
|
289
|
+
.join(", ") + (nodeCount > 3 ? ` and ${nodeCount - 3} more` : "");
|
|
290
|
+
return {
|
|
291
|
+
rule: container ? NARROW_RULE : OVERFLOW_RULE,
|
|
292
|
+
severity: findingSeverity(container ? NARROW_RULE : OVERFLOW_RULE),
|
|
293
|
+
file: files.get(scenario) ?? scenario,
|
|
294
|
+
line: 1,
|
|
295
|
+
column: 1,
|
|
296
|
+
source: "ads",
|
|
297
|
+
kind,
|
|
298
|
+
...(container ? { container: sorted[0] } : { widths: sorted }),
|
|
299
|
+
scenario,
|
|
300
|
+
themes,
|
|
301
|
+
...(brands.length ? { brands } : {}),
|
|
302
|
+
nodes: list,
|
|
303
|
+
nodeCount,
|
|
304
|
+
guidanceUri: "ads://guides/tokens",
|
|
305
|
+
message: `Layout overflow in ${scenario} ${container ? `in a ${sorted[0]} px container` : `at ${sorted.join(", ")} px wide`} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}]: ${overflowKinds[kind].what}: ${where}. ${overflowKinds[kind].fix}`,
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** One error per scenario and image rendered at a shape other than the one it declares. */
|
|
311
|
+
export function imageShapeFindings(runs, scenarios) {
|
|
312
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
313
|
+
groups = new Map();
|
|
314
|
+
const add = (list, value) => {
|
|
315
|
+
if (value !== undefined && !list.includes(value)) list.push(value);
|
|
316
|
+
};
|
|
317
|
+
for (const run of runs)
|
|
318
|
+
for (const issue of run.imageShape ?? []) {
|
|
319
|
+
const key = JSON.stringify([run.scenario, issue.selector]);
|
|
320
|
+
const group = groups.get(key) ?? { scenario: run.scenario, issue, themes: [], brands: [] };
|
|
321
|
+
groups.set(key, group);
|
|
322
|
+
add(group.themes, run.theme);
|
|
323
|
+
add(group.brands, run.brand);
|
|
324
|
+
}
|
|
325
|
+
return [...groups.values()].slice(0, limits.findings).map(({ scenario, issue, themes, brands }) => ({
|
|
326
|
+
rule: "img-shape",
|
|
327
|
+
severity: findingSeverity("img-shape"),
|
|
328
|
+
file: files.get(scenario) ?? scenario,
|
|
329
|
+
line: 1,
|
|
330
|
+
column: 1,
|
|
331
|
+
source: "ads",
|
|
332
|
+
scenario,
|
|
333
|
+
themes,
|
|
334
|
+
...(brands.length ? { brands } : {}),
|
|
335
|
+
nodes: [issue],
|
|
336
|
+
rendered: issue.rendered,
|
|
337
|
+
declared: issue.declared,
|
|
338
|
+
guidanceUri: "ads://guides/performance",
|
|
339
|
+
message: `Image shape in ${scenario} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}]: ${issue.selector} renders at ${issue.rendered} at the ${issue.width} px viewport but declares ${issue.declared}, so it is cropped or stretched. A height attribute beats aspect-ratio: add height: auto. For a deliberate crop in a box of its own, set object-fit and no aspect-ratio.`,
|
|
340
|
+
}));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** What a run measured, and what it skipped and why: per reason, with a few examples. An info finding
|
|
344
|
+
* for each reason, and a review item for a render assigned targets that measured none of them. */
|
|
345
|
+
export function auditCoverage(runs, capped, scenarios) {
|
|
346
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
347
|
+
reasons = new Map();
|
|
348
|
+
const claimedNow = new Set(runs.flatMap((run) => run.coverage?.claimed ?? []));
|
|
349
|
+
const note = (reason, example) => {
|
|
350
|
+
const entry = reasons.get(reason) ?? { count: 0, examples: [] };
|
|
351
|
+
reasons.set(reason, entry);
|
|
352
|
+
entry.count++;
|
|
353
|
+
if (entry.examples.length < limits.nodes) entry.examples.push(example);
|
|
354
|
+
};
|
|
355
|
+
for (const run of runs)
|
|
356
|
+
for (const { reason, name } of run.coverage?.skipped ?? [])
|
|
357
|
+
note(reason, { scenario: run.scenario, theme: run.theme, ...(run.brand ? { brand: run.brand } : {}), name });
|
|
358
|
+
for (const { claim, reason, ...example } of capped) if (!claimedNow.has(claim)) note(reason, example);
|
|
359
|
+
const coverage = {
|
|
360
|
+
renders: runs.length,
|
|
361
|
+
overlaysOpened: 0,
|
|
362
|
+
controlsMeasured: 0,
|
|
363
|
+
skipped: Object.fromEntries([...reasons].sort(([a], [b]) => a.localeCompare(b))),
|
|
364
|
+
};
|
|
365
|
+
const empty = [];
|
|
366
|
+
for (const run of runs)
|
|
367
|
+
if (run.coverage) {
|
|
368
|
+
coverage.overlaysOpened += run.coverage.overlays;
|
|
369
|
+
coverage.controlsMeasured += run.coverage.controls;
|
|
370
|
+
// A trigger that opened nothing is not a failure to measure: that is a skip, and the rest of the render stands.
|
|
371
|
+
const failed = run.coverage.skipped.filter((item) => /^(?:overlay|control)-(?:gone|timeout|detached|failed)$/.test(item.reason)).length;
|
|
372
|
+
if (failed && !run.coverage.overlays && !run.coverage.controls) empty.push(run);
|
|
373
|
+
}
|
|
374
|
+
const findings = [...reasons].map(([reason, { count, examples }]) => ({
|
|
375
|
+
rule: "render-audit-skipped",
|
|
376
|
+
severity: findingSeverity("render-audit-skipped"),
|
|
377
|
+
file: files.get(examples[0].scenario) ?? examples[0].scenario,
|
|
378
|
+
line: 1,
|
|
379
|
+
column: 1,
|
|
380
|
+
source: "ads",
|
|
381
|
+
reason,
|
|
382
|
+
count,
|
|
383
|
+
examples,
|
|
384
|
+
guidanceUri: "ads://guides/accessibility",
|
|
385
|
+
message: `The audit skipped ${count} target${count === 1 ? "" : "s"}: ${skipReasons[reason] ?? reason}. ${examples
|
|
386
|
+
.slice(0, 3)
|
|
387
|
+
.map((item) => `"${item.name}" in ${item.scenario} [${item.theme}]`)
|
|
388
|
+
.join(", ")}${count > 3 ? ` and ${count - 3} more` : ""}.`,
|
|
389
|
+
}));
|
|
390
|
+
for (const run of empty)
|
|
391
|
+
findings.push({
|
|
392
|
+
rule: "render-audit-nothing-measured",
|
|
393
|
+
severity: findingSeverity("render-audit-nothing-measured"),
|
|
394
|
+
file: files.get(run.scenario) ?? run.scenario,
|
|
395
|
+
line: 1,
|
|
396
|
+
column: 1,
|
|
397
|
+
source: "ads",
|
|
398
|
+
scenario: run.scenario,
|
|
399
|
+
themes: [run.theme],
|
|
400
|
+
message: `Nothing the audit tried to open or hover in ${run.scenario} [${run.theme}] could be measured: ${[...new Set(run.coverage.skipped.map((item) => item.reason))].join(", ")}.`,
|
|
401
|
+
});
|
|
402
|
+
return { coverage, findings };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** One error per scenario above the threshold, with its worst score, themes, brands and elements. */
|
|
406
|
+
export function layoutShiftFindings(runs, scenarios) {
|
|
407
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
408
|
+
groups = new Map();
|
|
409
|
+
const add = (list, value) => {
|
|
410
|
+
if (value !== undefined && !list.includes(value)) list.push(value);
|
|
411
|
+
};
|
|
412
|
+
for (const run of runs) {
|
|
413
|
+
if (!(run.layoutShift?.value > shiftLimit)) continue;
|
|
414
|
+
const group = groups.get(run.scenario) ?? { scenario: run.scenario, themes: [], brands: [], value: 0, nodes: [] };
|
|
415
|
+
groups.set(run.scenario, group);
|
|
416
|
+
add(group.themes, run.theme);
|
|
417
|
+
add(group.brands, run.brand);
|
|
418
|
+
group.value = Math.max(group.value, run.layoutShift.value);
|
|
419
|
+
for (const node of run.layoutShift.nodes) add(group.nodes, node);
|
|
420
|
+
}
|
|
421
|
+
return [...groups.values()].slice(0, limits.findings).map(({ scenario, themes, brands, value, nodes }) => ({
|
|
422
|
+
rule: SHIFT_RULE,
|
|
423
|
+
severity: findingSeverity(SHIFT_RULE),
|
|
424
|
+
file: files.get(scenario) ?? scenario,
|
|
425
|
+
line: 1,
|
|
426
|
+
column: 1,
|
|
427
|
+
source: "ads",
|
|
428
|
+
scenario,
|
|
429
|
+
value,
|
|
430
|
+
themes,
|
|
431
|
+
...(brands.length ? { brands } : {}),
|
|
432
|
+
nodes: nodes.slice(0, limits.nodes).map((selector) => ({ selector })),
|
|
433
|
+
guidanceUri: "ads://guides/performance",
|
|
434
|
+
message: `Layout shift ${value} in ${scenario} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}], above ${shiftLimit}${nodes.length ? `: ${nodes.slice(0, 3).join(", ")}` : ""}. Give images and media width and height, reserve space for late content, and load the fonts the first text uses early.`,
|
|
435
|
+
}));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* UI scenarios a candidate change can affect, for acceptance audits. Changes to configuration,
|
|
440
|
+
* foundation, tokens, assets or files outside every unit affect all rendering and select every UI
|
|
441
|
+
* scenario; so does a failure to trace imports. Public/review entry re-exports are bookkeeping
|
|
442
|
+
* for their own units and do not widen the selection.
|
|
443
|
+
*/
|
|
444
|
+
/** "owners": the changed owners' own scenarios. "affected": every scenario the change reaches. */
|
|
445
|
+
export async function auditScenarioSelection(options, changedFiles, { mode = "affected", owners = [], before } = {}) {
|
|
446
|
+
const scenarios = (await inspectScenarios(options)).scenarios.filter((scenario) => auditedKinds.includes(scenario.kind));
|
|
447
|
+
const all = (reason) => ({ mode: "all", reason, scenarios: scenarios.map((scenario) => scenario.id) });
|
|
448
|
+
const inventory = await inspectUnits(options),
|
|
449
|
+
entries = [inventory.publicEntry, inventory.reviewEntry];
|
|
450
|
+
if (mode === "owners") {
|
|
451
|
+
const changed = new Set([...owners, ...changedFiles.map((file) => inventory.owner(inventory.relative(file))).filter(Boolean)]);
|
|
452
|
+
return {
|
|
453
|
+
mode: "owners",
|
|
454
|
+
reason: "Owners' own scenarios; the validation stage audits everything they affect.",
|
|
455
|
+
scenarios: scenarios.filter((scenario) => changed.has(inventory.owner(inventory.relative(scenario.file)))).map((scenario) => scenario.id),
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
const traced = changedFiles.filter((file) => !entries.includes(inventory.relative(file)));
|
|
459
|
+
const shared = traced.find((file) => {
|
|
460
|
+
const owner = inventory.owner(inventory.relative(file));
|
|
461
|
+
return [null, "configuration", "foundation", "tokens"].includes(owner) || owner.startsWith("assets") || !inventory.units.some((unit) => unit.id === owner);
|
|
462
|
+
});
|
|
463
|
+
if (shared) return all(`${shared} is shared configuration, foundation, token, asset or unowned input.`);
|
|
464
|
+
if (!before && traced.some((file) => !existsSync(path.resolve(options.root, file)))) return all("Deleted inputs have no previous dependency evidence.");
|
|
465
|
+
try {
|
|
466
|
+
return { mode: "affected", scenarios: await affectedScenarios(options, traced, scenarios, before) };
|
|
467
|
+
} catch (error) {
|
|
468
|
+
return all(`Affected scenario selection failed: ${error.message}`);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Policy check entry and routed findings for one audit result. */
|
|
473
|
+
export function auditCheck(audit, extra = {}) {
|
|
474
|
+
const routed = routeFindings([], audit.findings);
|
|
475
|
+
return {
|
|
476
|
+
routed,
|
|
477
|
+
check: {
|
|
478
|
+
name: "render-audit",
|
|
479
|
+
passed: !routed.diagnostics.length,
|
|
480
|
+
engine: audit.engine,
|
|
481
|
+
scenarios: audit.scenarios,
|
|
482
|
+
themes: audit.themes,
|
|
483
|
+
...(audit.brands ? { brands: audit.brands } : {}),
|
|
484
|
+
renders: audit.runs,
|
|
485
|
+
...(audit.coverage ? { coverage: audit.coverage } : {}),
|
|
486
|
+
...(audit.retries ? { retries: audit.retries } : {}),
|
|
487
|
+
errors: routed.diagnostics.length,
|
|
488
|
+
reviews: routed.advisories.filter((item) => item.severity === "review").length,
|
|
489
|
+
infos: routed.advisories.filter((item) => item.severity === "info").length,
|
|
490
|
+
elapsedMs: audit.elapsedMs,
|
|
491
|
+
...extra,
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function projectPlaywright(root) {
|
|
497
|
+
const require = createRequire(path.join(root, "package.json"));
|
|
498
|
+
for (const name of ["@playwright/test", "playwright"]) {
|
|
499
|
+
try {
|
|
500
|
+
return require.resolve(name);
|
|
501
|
+
} catch {
|
|
502
|
+
/* Try the other supported project-installed entry. */
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const installHint =
|
|
509
|
+
"`npm install -D @playwright/test` and `npx playwright install chromium` (Bun: `bun add -d @playwright/test` and `bunx playwright install chromium`)";
|
|
510
|
+
|
|
511
|
+
/** Whether the project can run the audit: project-local Playwright, as for captures. */
|
|
512
|
+
export const renderAuditAvailable = (root) => !!projectPlaywright(path.resolve(root));
|
|
513
|
+
|
|
514
|
+
/** Scenarios of an owner in layout.fixedWidthUnits float above the layout, and have no container to fit. */
|
|
515
|
+
async function floatingScenarios(options, scenarios) {
|
|
516
|
+
const globs = options.config.layout.fixedWidthUnits,
|
|
517
|
+
floating = globMatcher(globs);
|
|
518
|
+
if (!globs.length) return new Set();
|
|
519
|
+
const inventory = await inspectUnits(options);
|
|
520
|
+
return new Set(
|
|
521
|
+
scenarios
|
|
522
|
+
.filter((scenario) => {
|
|
523
|
+
const owner = inventory.owner(inventory.relative(scenario.file));
|
|
524
|
+
return owner && (floating(owner) || inventory.units.find((unit) => unit.id === owner)?.files.some(floating));
|
|
525
|
+
})
|
|
526
|
+
.map((scenario) => scenario.id),
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const renderKey = ({ scenario, theme, brand }) => JSON.stringify([scenario, theme, brand ?? null]);
|
|
531
|
+
const clipCause = (text) => String(text).replace(/\s+/g, " ").trim().slice(0, 500);
|
|
532
|
+
|
|
533
|
+
/** Warm scenarios, separating those that cannot build. A project that fails validation fails
|
|
534
|
+
* every scenario the same way, so it stops the audit as it always has; anything else is one
|
|
535
|
+
* scenario's trouble (a slow or dropped build) and comes back as its cause. */
|
|
536
|
+
async function warmScenariosApart(host, ids, signal) {
|
|
537
|
+
const unbuilt = new Map();
|
|
538
|
+
const projectWide = (error) => signal.aborted || error.build?.failure?.scope === "project" || error.build?.failure?.phase === "validation";
|
|
539
|
+
try {
|
|
540
|
+
await host.warmScenarios?.(ids, signal);
|
|
541
|
+
return unbuilt;
|
|
542
|
+
} catch (error) {
|
|
543
|
+
if (projectWide(error)) throw error;
|
|
544
|
+
}
|
|
545
|
+
for (const id of ids) {
|
|
546
|
+
try {
|
|
547
|
+
await host.warmScenarios?.([id], signal);
|
|
548
|
+
} catch (error) {
|
|
549
|
+
if (projectWide(error)) throw error;
|
|
550
|
+
unbuilt.set(id, clipCause(error.message));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return unbuilt;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/** One browser process over the given renders. Its report grows as they finish, so a worker that
|
|
557
|
+
* dies keeps what it finished. A browser that is not installed stops the audit. */
|
|
558
|
+
async function runAuditWorker({ root, temporary, playwright, settings, apps, signal, claimed, pages }) {
|
|
559
|
+
const request = path.join(temporary, "request.json"),
|
|
560
|
+
report = path.join(temporary, "report.json"),
|
|
561
|
+
runId = randomUUID();
|
|
562
|
+
rmSync(report, { force: true });
|
|
563
|
+
writeFileSync(
|
|
564
|
+
request,
|
|
565
|
+
JSON.stringify({
|
|
566
|
+
schemaVersion: 1,
|
|
567
|
+
runId,
|
|
568
|
+
playwright,
|
|
569
|
+
axe: requireTool.resolve("axe-core/axe.min.js"),
|
|
570
|
+
settings,
|
|
571
|
+
viewport,
|
|
572
|
+
overflowWidths,
|
|
573
|
+
smallPart: 96, // Existing browser-only narrow-container review threshold; source sizing uses roles.
|
|
574
|
+
overlayLimit: limits.overlays,
|
|
575
|
+
stateLimit: limits.controls,
|
|
576
|
+
contentQuietMs: limits.contentQuietMs,
|
|
577
|
+
contentLimitMs: limits.contentLimitMs,
|
|
578
|
+
claimed,
|
|
579
|
+
tags: auditTags,
|
|
580
|
+
nodeLimit: limits.nodes,
|
|
581
|
+
concurrency: pages,
|
|
582
|
+
apps,
|
|
583
|
+
output: temporary,
|
|
584
|
+
}),
|
|
585
|
+
);
|
|
586
|
+
const timeoutMs = Math.min(30 * 60 * 1000, settings.timeoutMs + apps.length * Math.min(settings.timeoutMs, 15000));
|
|
587
|
+
let cause;
|
|
588
|
+
try {
|
|
589
|
+
const run = await executeDevelopmentCommand(
|
|
590
|
+
{ command: "runtime", timeoutMs, label: "Accessibility audit" },
|
|
591
|
+
[fileURLToPath(new URL("./render-audit/worker.mjs", import.meta.url)), request],
|
|
592
|
+
root,
|
|
593
|
+
{},
|
|
594
|
+
signal,
|
|
595
|
+
);
|
|
596
|
+
if (run.code !== 0 && /Executable doesn't exist|playwright install/i.test(run.output))
|
|
597
|
+
throw Object.assign(
|
|
598
|
+
new Error(
|
|
599
|
+
`The render audit needs Playwright's ${settings.browser} browser. Install it with \`npx playwright install ${settings.browser}\` (Bun: \`bunx playwright install ${settings.browser}\`), or select an installed Chrome with mcp.capture.channel "chrome".`,
|
|
600
|
+
),
|
|
601
|
+
{ code: "ADS_AUDIT_UNAVAILABLE" },
|
|
602
|
+
);
|
|
603
|
+
if (run.code !== 0) cause = `Accessibility audit browser failed (${run.code}): ${clipCause(run.output.slice(-400))}`;
|
|
604
|
+
} catch (error) {
|
|
605
|
+
if (signal.aborted || error.code === "ADS_AUDIT_UNAVAILABLE") throw error;
|
|
606
|
+
cause = clipCause(error.message);
|
|
607
|
+
}
|
|
608
|
+
if (!existsSync(report) || realpathSync(report) !== report || lstatSync(report).size > limits.reportBytes)
|
|
609
|
+
return { runs: [], capped: [], cause: cause ?? "Accessibility audit produced no bounded report." };
|
|
610
|
+
const value = JSON.parse(readFileSync(report, "utf8"));
|
|
611
|
+
if (value.schemaVersion !== 1 || value.runId !== runId || !Array.isArray(value.runs))
|
|
612
|
+
return { runs: [], capped: [], cause: cause ?? "Accessibility audit returned the wrong run identity." };
|
|
613
|
+
return { runs: value.runs, capped: value.capped ?? [], cause };
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/** A scenario that could not be audited is an error naming it and its last cause, never a pass. */
|
|
617
|
+
function unauditedFindings(renders, scenarios) {
|
|
618
|
+
const files = new Map(scenarios.map((scenario) => [scenario.id, scenario.file])),
|
|
619
|
+
groups = new Map();
|
|
620
|
+
for (const { app, attempts, causes } of renders) {
|
|
621
|
+
const group = groups.get(app.scenario) ?? { scenario: app.scenario, themes: [], brands: [], attempts, cause: "" };
|
|
622
|
+
groups.set(app.scenario, group);
|
|
623
|
+
if (!group.themes.includes(app.theme)) group.themes.push(app.theme);
|
|
624
|
+
if (app.brand && !group.brands.includes(app.brand)) group.brands.push(app.brand);
|
|
625
|
+
group.cause = causes.at(-1) ?? group.cause;
|
|
626
|
+
}
|
|
627
|
+
return [...groups.values()].map(({ scenario, themes, brands, attempts, cause }) => ({
|
|
628
|
+
rule: "render-audit",
|
|
629
|
+
severity: findingSeverity("render-audit"),
|
|
630
|
+
file: files.get(scenario) ?? scenario,
|
|
631
|
+
line: 1,
|
|
632
|
+
column: 1,
|
|
633
|
+
source: "ads",
|
|
634
|
+
scenario,
|
|
635
|
+
themes,
|
|
636
|
+
...(brands.length ? { brands } : {}),
|
|
637
|
+
attempts,
|
|
638
|
+
cause,
|
|
639
|
+
guidanceUri: "ads://guides/accessibility",
|
|
640
|
+
message: `Could not audit ${scenario} [${themes.join(", ")}${brands.length ? `; ${brands.join(", ")}` : ""}] in ${attempts} attempt${attempts === 1 ? "" : "s"}: ${cause}`,
|
|
641
|
+
}));
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Render every selected scenario in every declared brand and theme and run axe-core on it.
|
|
646
|
+
* Without declared brands it renders the single default brand.
|
|
647
|
+
* Reuses a showcase-serving preview host when given one; otherwise starts and closes its own.
|
|
648
|
+
* A render that fails is retried on its own, up to auditAttempts, and the rest keep their results.
|
|
649
|
+
* Findings never cause a retry; a retried pass is listed in retries.
|
|
650
|
+
*/
|
|
651
|
+
export async function runRenderAudit(
|
|
652
|
+
root,
|
|
653
|
+
{ scenarios: selected, themes: selectedThemes, brands: selectedBrands, previewHost, signal = new AbortController().signal, onProgress } = {},
|
|
654
|
+
) {
|
|
655
|
+
root = path.resolve(root);
|
|
656
|
+
const startedAt = Date.now(),
|
|
657
|
+
options = loadConfig(root);
|
|
658
|
+
const playwright = projectPlaywright(root);
|
|
659
|
+
if (!playwright)
|
|
660
|
+
throw Object.assign(
|
|
661
|
+
new Error(
|
|
662
|
+
`The render audit needs Playwright in the project. Install it with ${installHint}; ads validate always runs it, and acceptance.audit: false turns it off for draft acceptance.`,
|
|
663
|
+
),
|
|
664
|
+
{ code: "ADS_AUDIT_UNAVAILABLE" },
|
|
665
|
+
);
|
|
666
|
+
const registry = await analyze(root, "registry", [], signal);
|
|
667
|
+
if (registry.diagnostics.length) throw new Error(`Scenario registration failed: ${registry.diagnostics[0].message}`);
|
|
668
|
+
const unknown = (selected ?? []).filter((id) => !registry.scenarios.some((scenario) => scenario.id === id));
|
|
669
|
+
if (unknown.length) throw new Error(`Unknown scenario ${unknown[0]}. Discover exact IDs with ads_scenarios.`);
|
|
670
|
+
// Token and brand scenarios display raw values (token-contrast reviews those pairs); UI scenarios are audited.
|
|
671
|
+
// An explicit selection may still name one.
|
|
672
|
+
const scenarios = registry.scenarios
|
|
673
|
+
.filter((scenario) => (selected?.length ? selected.includes(scenario.id) : auditedKinds.includes(scenario.kind)))
|
|
674
|
+
.slice(0, limits.scenarios);
|
|
675
|
+
const themes = options.config.themes.filter((theme) => !selectedThemes?.length || selectedThemes.includes(theme.name));
|
|
676
|
+
if (selectedThemes?.length && themes.length !== new Set(selectedThemes).size)
|
|
677
|
+
throw new Error(`Unknown theme; the project declares ${options.config.themes.map((theme) => theme.name).join(", ")}.`);
|
|
678
|
+
const declaredBrands = options.config.brands ?? [];
|
|
679
|
+
if (selectedBrands?.length && !declaredBrands.length) throw new Error("Unknown brand; the project declares no brands.");
|
|
680
|
+
const brands = declaredBrands.filter((brand) => !selectedBrands?.length || selectedBrands.includes(brand.name));
|
|
681
|
+
if (selectedBrands?.length && brands.length !== new Set(selectedBrands).size)
|
|
682
|
+
throw new Error(`Unknown brand; the project declares ${declaredBrands.map((brand) => brand.name).join(", ")}.`);
|
|
683
|
+
const summary = {
|
|
684
|
+
scenarios: scenarios.length,
|
|
685
|
+
themes: themes.map((theme) => theme.name),
|
|
686
|
+
...(brands.length ? { brands: brands.map((brand) => brand.name) } : {}),
|
|
687
|
+
tags: auditTags,
|
|
688
|
+
engine: `axe-core ${axeVersion()}`,
|
|
689
|
+
};
|
|
690
|
+
if (!scenarios.length) return { ...summary, runs: 0, findings: [], elapsedMs: Date.now() - startedAt };
|
|
691
|
+
const outputRoot = path.join(root, ".ds");
|
|
692
|
+
mkdirSync(outputRoot, { recursive: true });
|
|
693
|
+
if (realpathSync(outputRoot) !== outputRoot) throw new Error("Audit work output cannot resolve through a symlink.");
|
|
694
|
+
const temporary = mkdtempSync(path.join(outputRoot, "audit-work-"));
|
|
695
|
+
let host = previewHost;
|
|
696
|
+
try {
|
|
697
|
+
onProgress?.({ stage: "render-audit", message: `Accessibility audit: building ${scenarios.length} scenario previews.`, elapsedMs: Date.now() - startedAt });
|
|
698
|
+
const startHost = async () => {
|
|
699
|
+
const { startAdsMcp } = await import("./mcp/server.mjs");
|
|
700
|
+
return startAdsMcp(root, { stdio: false, showcase: true, despitePolicy: true });
|
|
701
|
+
};
|
|
702
|
+
if (!host?.url) host = await startHost();
|
|
703
|
+
const settings = { browser: "chromium", timeoutMs: 60000, ...options.config.mcp.capture };
|
|
704
|
+
const floating = await floatingScenarios(options, scenarios);
|
|
705
|
+
const wanted = themes.flatMap((theme) =>
|
|
706
|
+
(brands.length ? brands : [undefined]).flatMap((brand) =>
|
|
707
|
+
scenarios.map((scenario) => ({
|
|
708
|
+
scenario: scenario.id,
|
|
709
|
+
theme: theme.name,
|
|
710
|
+
...(brand ? { brand: brand.name } : {}),
|
|
711
|
+
scheme: theme.scheme,
|
|
712
|
+
...(theme === themes[0] && containerKinds.includes(scenario.kind) && !floating.has(scenario.id) ? { container: containerWidth } : {}),
|
|
713
|
+
})),
|
|
714
|
+
),
|
|
715
|
+
);
|
|
716
|
+
const renders = new Map(wanted.map((app) => [renderKey(app), { app, attempts: 0, causes: [] }])),
|
|
717
|
+
capped = new Map();
|
|
718
|
+
onProgress?.({
|
|
719
|
+
stage: "render-audit",
|
|
720
|
+
message: `Accessibility audit: ${wanted.length} renders (${scenarios.length} scenarios × ${themes.length} themes${brands.length ? ` × ${brands.length} brands` : ""}).`,
|
|
721
|
+
elapsedMs: Date.now() - startedAt,
|
|
722
|
+
});
|
|
723
|
+
for (let attempt = 1; attempt <= auditAttempts; attempt++) {
|
|
724
|
+
const pending = [...renders.values()].filter((render) => !render.result);
|
|
725
|
+
if (!pending.length) break;
|
|
726
|
+
signal.throwIfAborted();
|
|
727
|
+
for (const render of pending) render.attempts = attempt;
|
|
728
|
+
if (!host) {
|
|
729
|
+
try {
|
|
730
|
+
host = await startHost();
|
|
731
|
+
} catch (error) {
|
|
732
|
+
if (signal.aborted) throw error;
|
|
733
|
+
for (const render of pending) render.causes.push(clipCause(error.message));
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
const unbuilt = await warmScenariosApart(host, [...new Set(pending.map((render) => render.app.scenario))], signal);
|
|
738
|
+
for (const render of pending) if (unbuilt.has(render.app.scenario)) render.causes.push(unbuilt.get(render.app.scenario));
|
|
739
|
+
const apps = pending
|
|
740
|
+
.filter((render) => !unbuilt.has(render.app.scenario))
|
|
741
|
+
.map(({ app }) => {
|
|
742
|
+
const url = new URL(host.url);
|
|
743
|
+
url.searchParams.set("scenario", app.scenario);
|
|
744
|
+
url.searchParams.set("capture", "1");
|
|
745
|
+
url.searchParams.set("theme", app.theme);
|
|
746
|
+
if (app.brand) url.searchParams.set("brand", app.brand);
|
|
747
|
+
return { ...app, url: url.href };
|
|
748
|
+
});
|
|
749
|
+
const reached = apps.length
|
|
750
|
+
? await runAuditWorker({
|
|
751
|
+
root,
|
|
752
|
+
temporary,
|
|
753
|
+
playwright,
|
|
754
|
+
settings,
|
|
755
|
+
apps,
|
|
756
|
+
signal,
|
|
757
|
+
pages: options.config.mcp.auditPages,
|
|
758
|
+
claimed: [...renders.values()].flatMap((render) => render.result?.coverage?.claimed ?? []),
|
|
759
|
+
})
|
|
760
|
+
: { runs: [], capped: [] };
|
|
761
|
+
for (const item of reached.capped ?? []) capped.set(item.claim, item);
|
|
762
|
+
for (const run of reached.runs) {
|
|
763
|
+
const render = renders.get(renderKey(run));
|
|
764
|
+
if (!render) continue;
|
|
765
|
+
if (run.failed) {
|
|
766
|
+
render.causes.push(run.cause);
|
|
767
|
+
if (run.violations) render.partial = run;
|
|
768
|
+
} else render.result = run;
|
|
769
|
+
}
|
|
770
|
+
for (const { app } of pending.filter(
|
|
771
|
+
(render) =>
|
|
772
|
+
!render.result &&
|
|
773
|
+
apps.some((app) => renderKey(app) === renderKey(render.app)) &&
|
|
774
|
+
!reached.runs.some((run) => renderKey(run) === renderKey(render.app)),
|
|
775
|
+
))
|
|
776
|
+
renders.get(renderKey(app)).causes.push(reached.cause ?? "The audit browser stopped before this render.");
|
|
777
|
+
// The next attempt gets a new browser and, when this audit owns it, a new preview host.
|
|
778
|
+
if (attempt < auditAttempts && host !== previewHost && [...renders.values()].some((render) => !render.result)) {
|
|
779
|
+
const previous = host;
|
|
780
|
+
host = undefined;
|
|
781
|
+
await previous.close().catch(() => {});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const all = [...renders.values()],
|
|
785
|
+
runs = all.map((render) => render.result ?? render.partial).filter(Boolean);
|
|
786
|
+
const retries = all
|
|
787
|
+
.filter((render) => render.result && render.attempts > 1)
|
|
788
|
+
.map(({ app, attempts, causes }) => ({ scenario: app.scenario, theme: app.theme, ...(app.brand ? { brand: app.brand } : {}), attempts, causes }));
|
|
789
|
+
const { coverage, findings: coverageItems } = auditCoverage(all.map((render) => render.result).filter(Boolean), [...capped.values()], scenarios);
|
|
790
|
+
const findings = [
|
|
791
|
+
...coverageItems,
|
|
792
|
+
...auditFindings(runs, scenarios),
|
|
793
|
+
...nonTextContrastFindings(runs, scenarios),
|
|
794
|
+
...layoutOverflowFindings(runs, scenarios),
|
|
795
|
+
...layoutShiftFindings(runs, scenarios),
|
|
796
|
+
...imageShapeFindings(runs, scenarios),
|
|
797
|
+
...unauditedFindings(
|
|
798
|
+
all.filter((render) => !render.result),
|
|
799
|
+
scenarios,
|
|
800
|
+
),
|
|
801
|
+
...incompleteFindings(runs, scenarios),
|
|
802
|
+
];
|
|
803
|
+
const shifts = runs.filter((run) => run.layoutShift).sort((a, b) => b.layoutShift.value - a.layoutShift.value);
|
|
804
|
+
return {
|
|
805
|
+
...summary,
|
|
806
|
+
...(shifts.length ? { worstLayoutShift: { value: shifts[0].layoutShift.value, scenario: shifts[0].scenario } } : {}),
|
|
807
|
+
runs: all.filter((render) => render.result).length,
|
|
808
|
+
incomplete: findings.filter((finding) => finding.rule === INCOMPLETE_RULE).length,
|
|
809
|
+
overlaysOpened: coverage.overlaysOpened,
|
|
810
|
+
controlsMeasured: coverage.controlsMeasured,
|
|
811
|
+
coverage,
|
|
812
|
+
findings,
|
|
813
|
+
...(retries.length ? { retries } : {}),
|
|
814
|
+
elapsedMs: Date.now() - startedAt,
|
|
815
|
+
};
|
|
816
|
+
} finally {
|
|
817
|
+
try {
|
|
818
|
+
if (host !== previewHost) await host?.close();
|
|
819
|
+
} finally {
|
|
820
|
+
rmSync(temporary, { recursive: true, force: true });
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
const requireTool = createRequire(import.meta.url);
|
|
826
|
+
function axeVersion() {
|
|
827
|
+
return JSON.parse(readFileSync(requireTool.resolve("axe-core/package.json"), "utf8")).version;
|
|
828
|
+
}
|