@reqvire-org/ads 0.3.52 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -9
- package/dist/assets.mjs +16 -2
- package/dist/behaviors.mjs +6 -5
- package/dist/boundaries.mjs +5 -5
- package/dist/browser-audit/first-render.mjs +22 -0
- package/dist/browser-audit/image-shape.mjs +36 -0
- package/dist/browser-audit/render-states.mjs +61 -35
- package/dist/browser-audit/worker.mjs +47 -12
- package/dist/browser-audit.mjs +75 -12
- package/dist/bun-compiler.mjs +14 -7
- package/dist/check-service.mjs +83 -0
- package/dist/check.mjs +20 -18
- package/dist/cli.mjs +5 -3
- package/dist/config.mjs +20 -41
- package/dist/contracts.d.mts +9 -0
- package/dist/finding-rules.mjs +8 -1
- package/dist/font-rules.mjs +103 -0
- package/dist/fonts-generated.mjs +32 -12
- package/dist/generated-entries.mjs +131 -0
- package/dist/icons.mjs +1 -1
- package/dist/init.mjs +11 -32
- package/dist/layers.mjs +7 -3
- package/dist/lint-config.mjs +4 -2
- package/dist/mcp/catalog.mjs +2 -1
- package/dist/mcp/context.mjs +3 -3
- package/dist/mcp/drafts.mjs +136 -121
- package/dist/mcp/mutations.mjs +65 -19
- package/dist/mcp/preview-watch.mjs +31 -5
- package/dist/mcp/preview-widget.bundle.js +50 -47
- package/dist/mcp/project-widget.bundle.js +45 -42
- package/dist/mcp/prompts.mjs +1 -1
- package/dist/mcp/server.mjs +81 -40
- package/dist/mcp/showcase-host.mjs +20 -7
- package/dist/mcp/widget.bundle.js +49 -46
- package/dist/oxlint.mjs +3 -2
- package/dist/program-cache.mjs +36 -0
- package/dist/public-api.mjs +2 -1
- package/dist/scenarios-compiler.mjs +82 -14
- package/dist/scenarios-vite.mjs +1 -1
- package/dist/scenarios.mjs +4 -3
- package/dist/showcase/client.bundle.js +27 -27
- package/dist/showcase/index.html +2 -2
- package/dist/skills/ads-break-ui/SKILL.md +25 -28
- package/dist/skills/ads-break-ui/references/behaviors.md +7 -6
- package/dist/skills/ads-break-ui/references/captures.md +7 -32
- package/dist/skills/ads-break-ui/references/contracts.md +58 -25
- package/dist/skills/ads-break-ui/references/drafts.md +59 -43
- package/dist/skills/ads-break-ui/references/evidence.md +1 -1
- package/dist/skills/ads-break-ui/references/guarded-editing.md +58 -47
- package/dist/skills/ads-break-ui/references/review.md +9 -8
- package/dist/skills/ads-break-ui/references/scenarios.md +1 -1
- package/dist/skills/ads-break-ui/references/validation.md +8 -4
- package/dist/skills/ads-break-ui/references/workflows.md +15 -8
- package/dist/skills/ads-designer/SKILL.md +30 -31
- package/dist/skills/ads-designer/references/accessibility.md +9 -5
- package/dist/skills/ads-designer/references/behaviors.md +7 -6
- package/dist/skills/ads-designer/references/branding.md +2 -2
- package/dist/skills/ads-designer/references/captures.md +7 -32
- package/dist/skills/ads-designer/references/cli.md +5 -1
- package/dist/skills/ads-designer/references/contracts.md +58 -25
- package/dist/skills/ads-designer/references/drafts.md +59 -43
- package/dist/skills/ads-designer/references/evidence.md +1 -1
- package/dist/skills/ads-designer/references/guarded-editing.md +58 -47
- package/dist/skills/ads-designer/references/performance.md +57 -6
- package/dist/skills/ads-designer/references/review.md +9 -8
- package/dist/skills/ads-designer/references/scenarios.md +1 -1
- package/dist/skills/ads-designer/references/validation.md +8 -4
- package/dist/skills/ads-designer/references/workflows.md +15 -8
- package/dist/skills/ads-import/SKILL.md +25 -28
- package/dist/skills/ads-import/references/behaviors.md +7 -6
- package/dist/skills/ads-import/references/captures.md +7 -32
- package/dist/skills/ads-import/references/cli.md +5 -1
- package/dist/skills/ads-import/references/contracts.md +58 -25
- package/dist/skills/ads-import/references/drafts.md +59 -43
- package/dist/skills/ads-import/references/evidence.md +1 -1
- package/dist/skills/ads-import/references/guarded-editing.md +58 -47
- package/dist/skills/ads-import/references/review.md +9 -8
- package/dist/skills/ads-import/references/scenarios.md +1 -1
- package/dist/skills/ads-import/references/validation.md +8 -4
- package/dist/skills/ads-import/references/workflows.md +15 -8
- package/dist/skills/ads-motion/SKILL.md +25 -28
- package/dist/skills/ads-motion/references/behaviors.md +7 -6
- package/dist/skills/ads-motion/references/captures.md +7 -32
- package/dist/skills/ads-motion/references/contracts.md +58 -25
- package/dist/skills/ads-motion/references/drafts.md +59 -43
- package/dist/skills/ads-motion/references/evidence.md +1 -1
- package/dist/skills/ads-motion/references/guarded-editing.md +58 -47
- package/dist/skills/ads-motion/references/review.md +9 -8
- package/dist/skills/ads-motion/references/scenarios.md +1 -1
- package/dist/skills/ads-motion/references/validation.md +8 -4
- package/dist/skills/ads-motion/references/workflows.md +15 -8
- package/dist/skills/ads-port/SKILL.md +25 -28
- package/dist/skills/ads-port/references/behaviors.md +7 -6
- package/dist/skills/ads-port/references/captures.md +7 -32
- package/dist/skills/ads-port/references/cli.md +5 -1
- package/dist/skills/ads-port/references/contracts.md +58 -25
- package/dist/skills/ads-port/references/drafts.md +59 -43
- package/dist/skills/ads-port/references/evidence.md +1 -1
- package/dist/skills/ads-port/references/guarded-editing.md +58 -47
- package/dist/skills/ads-port/references/native-implementation.md +6 -6
- package/dist/skills/ads-port/references/review.md +9 -8
- package/dist/skills/ads-port/references/scenarios.md +1 -1
- package/dist/skills/ads-port/references/validation.md +8 -4
- package/dist/skills/ads-port/references/workflows.md +15 -8
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
- package/dist/starters/preact/ds.config.json +0 -14
- package/dist/starters/react/README.md +9 -5
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +1 -1
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +2 -2
- 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/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/Content/Logo/Logo.tsx +2 -2
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +6 -0
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/controllers/Palette/Palette.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/index.ts +3 -7
- package/dist/starters/react/design-system/patterns/Search/SearchBar/SearchBar.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/index.ts +4 -3
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +6 -0
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/styles.css +1 -0
- package/dist/starters/react/ds.config.json +0 -14
- package/dist/style-boundaries.mjs +7 -6
- package/dist/test-boundaries.mjs +2 -2
- package/dist/themes-watch.mjs +9 -3
- package/dist/token-fixtures.mjs +1 -1
- package/dist/unit-contracts.mjs +38 -4
- package/dist/units.mjs +16 -91
- package/dist/validation-checks.mjs +7 -1
- package/docs/ADS.md +10 -10
- package/docs/ARCHITECTURE.md +104 -44
- package/docs/BEHAVIORS.md +8 -7
- package/docs/CACHING.md +15 -6
- package/docs/CHANGELOG.md +107 -12
- package/docs/COMPARISON.md +1 -1
- package/docs/CONTRACTS.md +10 -25
- package/docs/GUIDE.md +98 -57
- package/docs/MCP.md +116 -151
- package/package.json +7 -7
- package/dist/contract-migration.mjs +0 -110
- package/dist/mcp/draft-exports.mjs +0 -40
- package/dist/mcp/edit-preparation.mjs +0 -115
package/README.md
CHANGED
|
@@ -39,8 +39,9 @@ uses Preact. See [implementation support](docs/GUIDE.md#implementation-support).
|
|
|
39
39
|
project-owned scenarios and fixtures.
|
|
40
40
|
- **Edit directly or through MCP**: use your editor with MCP preview/checks, or
|
|
41
41
|
choose MCP-only tracked proposals and acceptance. See [editing access](docs/MCP.md#editing-access-and-compiler-ownership).
|
|
42
|
-
- **Edit with guards**
|
|
43
|
-
|
|
42
|
+
- **Edit with guards** through drafts: one or more owners per draft, acceptance dry
|
|
43
|
+
runs that validate architecture, lint and registered project checks, and a stage
|
|
44
|
+
check that audits everything a series of drafts reached.
|
|
44
45
|
- **Compare visual changes** with on-demand screenshots of current source and
|
|
45
46
|
proposed candidates, exposed as MCP image resources.
|
|
46
47
|
- **Iterate in tracked drafts** without rerunning acceptance checks after every
|
|
@@ -79,7 +80,7 @@ There is no warning level.
|
|
|
79
80
|
| **Static accessibility** | Focus styles, icon-only labels, image alt text, reduced motion, target size, text resize and text spacing are checked from source and tokens, without a browser. |
|
|
80
81
|
| **Contrast** | `token-contrast` checks the role pairs that meet on screen (text on surfaces, fills with their foreground, status text on tints, focus indicators and control borders) in every theme and brand. `component-contrast` checks the pairs components and patterns make themselves: a style block (including a nested state such as `&:hover` or `&[aria-selected="true"]`) that sets both `color` and `background` to tokens, such as a status color as text on its own tint. Both resolve every CSS color syntax, including `oklch()` and `color-mix()`, and composite translucent fills over the canvas. Text needs 4.5:1; focus indicators and control borders need 3:1; disabled states are exempt. |
|
|
81
82
|
| **Layout** | Widths are fluid on the grid. `layout-fixed-width` fails a width, `flex-basis` or grid track that cannot shrink below 96 px, in any unit, whether raw, from a token or by arithmetic; small parts use plain sizes, `min(100%, 280px)` and `%` shrink, a maximum is not read, and widths declared in `layout.widthTokens` pass and are listed for review. `layout-overflow` renders every UI scenario at 390, 768 and 1280 px and fails on horizontal page overflow and clipped content, and renders components and patterns in a 240 px container, where a set width above 96 px must fit; scrollers and ellipsis are exempt. |
|
|
82
|
-
| **Web performance** | `img-attributes` fails a raw `<img>` without dimensions or a `loading` choice, and a `srcset` with width descriptors and no `sizes`; `asset-image-budget` fails oversized images in `assets/` (SVG 100 KB, WebP and AVIF 300 KB, JPEG 400 KB, PNG and GIF 500 KB, or `assets.imageBudgetKb`); `layout-shift` fails a rendered scenario above 0.1. `ads assets` generates preloads for the fonts the first text uses, on the URLs the stylesheet requests. Page metadata, sitemaps, hosting and Lighthouse stay with the application. |
|
|
83
|
+
| **Web performance** | `img-attributes` fails a raw `<img>` without dimensions or a `loading` choice, and a `srcset` with width descriptors and no `sizes`; `asset-image-budget` fails oversized images in `assets/` (SVG 100 KB, WebP and AVIF 300 KB, JPEG 400 KB, PNG and GIF 500 KB, or `assets.imageBudgetKb`); `layout-shift` fails a rendered scenario above 0.1; `img-shape` fails an image rendered at another shape than it declares; `font-weight-missing` and `asset-font-budget` hold fonts to what is declared and a size. `ads assets` generates preloads for the fonts the first text uses, on the URLs the stylesheet requests. Page metadata, sitemaps, hosting and Lighthouse stay with the application. |
|
|
83
84
|
| **Themes and brands** | One mechanism: per-theme halves (`--x-light`, `--x-dark`) and brands on `[data-brand]`. `ads assets` generates `themes.generated.css` and `.ts`; missing or conflicting halves, empty themes, stale generated files, `light-dark()` and ancestor theme selectors are errors. |
|
|
84
85
|
| **Tokens** | Ownership, naming, rhythm, missing and scenario references; equal values in different roles are flagged for review. |
|
|
85
86
|
| **Architecture** | Data, UX and Skin ownership, project structure, unit and paint contracts, binding and variable ownership; Linaria atomic composition risks are flagged for review. |
|
|
@@ -185,12 +186,12 @@ downloads the published package. See the [MCP guide](docs/MCP.md#connect-codex-o
|
|
|
185
186
|
for config files and Claude Desktop setup.
|
|
186
187
|
|
|
187
188
|
To let the agent edit the ADS through enforced checks, append `--mutations` to
|
|
188
|
-
the MCP command.
|
|
189
|
-
fixtures,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
candidate.
|
|
193
|
-
|
|
189
|
+
the MCP command. Every change is a draft (file contents or a Git patch for its owners,
|
|
190
|
+
including their scenarios and fixtures), reviewed in the showcase and accepted after
|
|
191
|
+
the guards pass. Foundation styles, original assets, guides and project
|
|
192
|
+
configuration/guard extensions have editable units too. Coupled owners share one
|
|
193
|
+
draft, checked as one complete candidate. One runtime and one compiler serve the
|
|
194
|
+
project and all its draft previews. See
|
|
194
195
|
[guarded editing](docs/MCP.md#guarded-editing).
|
|
195
196
|
|
|
196
197
|
The server exposes public components/patterns, token values,
|
package/dist/assets.mjs
CHANGED
|
@@ -20,7 +20,7 @@ function assetFiles(directory, prefix = "") {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const sourceExtensions = /\.(?:[cm]?[jt]sx?|css|html|svg)$/;
|
|
23
|
-
const previewFile =
|
|
23
|
+
const previewFile = /\.ads\.(?:scenario\.tsx?|fixture\.ts)$/;
|
|
24
24
|
/** Text of the project's own source files, for finding which brand artwork is referenced. */
|
|
25
25
|
function sourceTexts(directories, skipped) {
|
|
26
26
|
const texts = [];
|
|
@@ -69,6 +69,20 @@ export function inspectGlyphs({ root, dsRoot, config }) {
|
|
|
69
69
|
* PNG and GIF are for flat art and icons, where a 1024 px master fits in 500; an SVG over 100 is
|
|
70
70
|
* usually an embedded bitmap or unoptimized paths. assets.imageBudgetKb replaces them all. */
|
|
71
71
|
export const imageBudgets = Object.freeze({ ".svg": 100, ".webp": 300, ".avif": 300, ".jpg": 400, ".jpeg": 400, ".png": 500, ".gif": 500 });
|
|
72
|
+
/** A font file above this is rarely one Latin subset: the largest of a set of real projects' fonts, a
|
|
73
|
+
* variable font covering two scripts, is 108 KB. assets.fontBudgetKb replaces it. */
|
|
74
|
+
export const fontBudgetKb = 150;
|
|
75
|
+
function inspectFontBudget({ root, dsRoot, config }) {
|
|
76
|
+
const directory = path.join(dsRoot, "assets"), findings = [];
|
|
77
|
+
for (const relative of assetFiles(directory)) {
|
|
78
|
+
if (!/\.(?:woff2?|ttf|otf)$/i.test(relative)) continue;
|
|
79
|
+
const limit = config.assets.fontBudgetKb ?? fontBudgetKb, file = path.join(directory, relative), kb = Math.ceil(lstatSync(file).size / 1024);
|
|
80
|
+
if (kb <= limit) continue;
|
|
81
|
+
findings.push({ rule: "asset-font-budget", severity: findingSeverity("asset-font-budget"), file: path.relative(root, file).replaceAll("\\", "/"), line: 1, column: 1, guidanceUri: "ads://guides/performance",
|
|
82
|
+
message: `${path.basename(file)} is ${kb} KB; a font file stays within ${limit} KB. Use WOFF2, subset it to the script the page uses, and put other scripts in their own unicode-range files. assets.fontBudgetKb in ds.config.json changes the limit.` });
|
|
83
|
+
}
|
|
84
|
+
return findings;
|
|
85
|
+
}
|
|
72
86
|
function inspectImageBudget({ root, dsRoot, config }) {
|
|
73
87
|
const directory = path.join(dsRoot, "assets"), findings = [];
|
|
74
88
|
for (const relative of assetFiles(directory)) {
|
|
@@ -113,7 +127,7 @@ export function inspectAssets({ root, dsRoot, config, trackingRoot = root }) {
|
|
|
113
127
|
const diagnostics = [];
|
|
114
128
|
const sourceDiagnostic = brandSourceDiagnostic({ root, dsRoot, config });
|
|
115
129
|
if (sourceDiagnostic) diagnostics.push(sourceDiagnostic);
|
|
116
|
-
diagnostics.push(...inspectBrand({ root, dsRoot, config }), ...inspectGlyphs({ root, dsRoot, config }), ...inspectImageBudget({ root, dsRoot, config }));
|
|
130
|
+
diagnostics.push(...inspectBrand({ root, dsRoot, config }), ...inspectGlyphs({ root, dsRoot, config }), ...inspectImageBudget({ root, dsRoot, config }), ...inspectFontBudget({ root, dsRoot, config }));
|
|
117
131
|
function report(rule, file, message) { diagnostics.push({ rule, file: path.relative(root, file).replaceAll("\\", "/") || ".", line: 1, column: 1, message }); }
|
|
118
132
|
const assetRoot = path.join(dsRoot, "assets");
|
|
119
133
|
// Every mount is compared with the canonical ADS assets. Public mounts are
|
package/dist/behaviors.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { existsSync,
|
|
1
|
+
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
5
|
+
import { isDevelopmentFile, isInside, sourceFiles, isReviewFile, isTestFile } from "./config.mjs";
|
|
6
6
|
import { importResolver, projectCompilerOptions } from "./boundaries.mjs";
|
|
7
7
|
import { inspectUnits } from "./units.mjs";
|
|
8
|
+
import { cachedProgram } from "./program-cache.mjs";
|
|
8
9
|
import { scenarioApi } from "./public-api.mjs";
|
|
9
10
|
import { inspectScenarios } from "./scenarios.mjs";
|
|
10
11
|
import { uiOperation } from "./ui-framework.mjs";
|
|
@@ -29,9 +30,9 @@ export function inspectBehaviors(options, suppliedProgram, suppliedRegistry) {
|
|
|
29
30
|
const inventory = inspectUnits(options);
|
|
30
31
|
const declarations = inspectUnitContracts(options);
|
|
31
32
|
const typed = declarations.contracts.filter(entry => entry.behavior);
|
|
32
|
-
const files =
|
|
33
|
+
const files = typed.map(entry => path.resolve(root, entry.file));
|
|
33
34
|
if (!files.length) return { contracts: [], diagnostics: [] };
|
|
34
|
-
const program = suppliedProgram ?? declarations.program ??
|
|
35
|
+
const program = suppliedProgram ?? declarations.program ?? cachedProgram(`behaviors:${root}`, sourceFiles(dsRoot).filter(file => /\.[cm]?[jt]sx?$/.test(file)), { ...projectCompilerOptions(options), allowJs: true });
|
|
35
36
|
const checker = program.getTypeChecker();
|
|
36
37
|
const apis = new Map(scenarioApi(program, options).map(item => [item.name, item]));
|
|
37
38
|
const scenarios = (suppliedRegistry ?? inspectScenarios(options, program)).scenarios;
|
|
@@ -42,7 +43,7 @@ export function inspectBehaviors(options, suppliedProgram, suppliedRegistry) {
|
|
|
42
43
|
let value;
|
|
43
44
|
try {
|
|
44
45
|
if (statSync(file).size > 128 * 1024 || realpathSync(file) !== file) throw new Error("Behavior contracts must be regular files of at most 128 KiB.");
|
|
45
|
-
const parsed = behaviorSchema.safeParse(typed.find(entry => path.resolve(root, entry.file) === file)
|
|
46
|
+
const parsed = behaviorSchema.safeParse(typed.find(entry => path.resolve(root, entry.file) === file).behavior);
|
|
46
47
|
if (!parsed.success) throw new Error(parsed.error.issues.slice(0, 5).map(issue => `${issue.path.join(".")}: ${issue.message}`).join("; "));
|
|
47
48
|
value = parsed.data;
|
|
48
49
|
} catch (error) { report(error.message); continue; }
|
package/dist/boundaries.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import ts from "typescript";
|
|
|
4
4
|
import { importedUiName } from "./ui-framework.mjs";
|
|
5
5
|
import { isInside, isStateVariable, isTestFile, isDevelopmentFile } from "./config.mjs";
|
|
6
6
|
import { isSharedToken } from "./token-policy.mjs";
|
|
7
|
-
import { runtimeBindingOwner } from "./unit-contracts.mjs";
|
|
7
|
+
import { ownerStylePolicy, runtimeBindingOwner } from "./unit-contracts.mjs";
|
|
8
8
|
|
|
9
9
|
export function projectCompilerOptions({ root, config, dsRoot }) {
|
|
10
10
|
const file = ts.findConfigFile(root, ts.sys.fileExists, "tsconfig.json");
|
|
@@ -77,7 +77,7 @@ export function checkComponentVariable(name, filename, options) {
|
|
|
77
77
|
if (components) return null;
|
|
78
78
|
if (isStateVariable(name)) return { rule: "primitive-state", message: "Primitive interaction variables belong to components. Add a typed primitive variant instead of overriding state policy." };
|
|
79
79
|
if (tokens) return { rule: "variable-ownership", message: "Component --ds-* variables belong to components, not shared token files." };
|
|
80
|
-
if (!
|
|
80
|
+
if (!ownerStylePolicy(options).componentVariables.includes(name)) return { rule: "component-variable", message: `Undocumented component customization ${name}. The component publishes it in its contract (customization), or use a public prop.` };
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -120,11 +120,11 @@ export function styleAccessProperty(node) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
// Aliases, computed keys, cssText and bulk writes cannot widen an exception.
|
|
123
|
-
export function styleWriteViolation(node, filename,
|
|
123
|
+
export function styleWriteViolation(node, filename, options) {
|
|
124
124
|
const property = styleAccessProperty(node);
|
|
125
125
|
if (property !== undefined && property !== false && !(property && property !== "css-text"
|
|
126
|
-
&&
|
|
127
|
-
return "Imperative styles require
|
|
126
|
+
&& ownerStylePolicy(options).styleWrites.find((boundary) => path.resolve(options.root, boundary.file) === filename)?.properties?.includes(property))) {
|
|
127
|
+
return "Imperative styles require the owner contract's styles.writes entry for this file and property. Bulk writes, computed property names, and style-object escapes are forbidden.";
|
|
128
128
|
}
|
|
129
129
|
if (ts.isCallExpression(node) && isMember(node.expression) && ["setAttribute", "setAttributeNS"].includes(memberName(node.expression))) {
|
|
130
130
|
const index = memberName(node.expression) === "setAttributeNS" ? 1 : 0;
|
|
@@ -16,3 +16,25 @@ export async function firstRender() {
|
|
|
16
16
|
await Promise.race([ready, new Promise(resolve => setTimeout(resolve, 5000))]);
|
|
17
17
|
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Waits until the page has stopped changing: no mutation in the scenario for `quietMs` and no finite
|
|
22
|
+
* animation running, up to `limitMs`. Content that arrives after first render, such as syntax colours
|
|
23
|
+
* from a grammar loaded late, is otherwise measured in some runs and missed in others. Nothing here
|
|
24
|
+
* knows a project's signals. Returns whether it got quiet. Self-contained, like firstRender.
|
|
25
|
+
*/
|
|
26
|
+
export async function contentQuiet({ quietMs, limitMs }) {
|
|
27
|
+
const started = performance.now();
|
|
28
|
+
let last = started;
|
|
29
|
+
const observer = new MutationObserver(records => { if (records.some(record => !record.target.closest?.("#ads-preview-status") && !record.target.parentElement?.closest("#ads-preview-status"))) last = performance.now(); });
|
|
30
|
+
observer.observe(document.body, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
31
|
+
const moving = () => document.getAnimations().some(animation => animation.playState === "running" && animation.effect?.getComputedTiming().iterations !== Infinity);
|
|
32
|
+
try {
|
|
33
|
+
while (performance.now() - started < limitMs) {
|
|
34
|
+
if (moving()) last = performance.now();
|
|
35
|
+
else if (performance.now() - last >= quietMs) return true;
|
|
36
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
} finally { observer.disconnect(); }
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Images rendered at a shape other than the one they declare. Self-contained: Playwright serializes
|
|
3
|
+
* it into the page. The declared shape is the CSS aspect-ratio or, without one, the width and height
|
|
4
|
+
* attributes. A height attribute beats aspect-ratio unless the CSS says height: auto, so an image can
|
|
5
|
+
* reserve its space, pass layout-shift, and still be cropped to the wrong shape. With no aspect-ratio,
|
|
6
|
+
* object-fit: cover, contain or none is a deliberate crop in a box of its own; only a fill stretches.
|
|
7
|
+
*/
|
|
8
|
+
export function imageShape({ nodeLimit }) {
|
|
9
|
+
const root = document.querySelector("#root");
|
|
10
|
+
if (!root) return { issues: [], counts: {} };
|
|
11
|
+
const selector = element => {
|
|
12
|
+
const parts = [];
|
|
13
|
+
for (let node = element; node && node !== root; node = node.parentElement) {
|
|
14
|
+
const siblings = [...node.parentElement.children].filter(child => child.localName === node.localName);
|
|
15
|
+
parts.unshift(`${node.localName}${siblings.length > 1 ? `:nth-of-type(${siblings.indexOf(node) + 1})` : ""}`);
|
|
16
|
+
}
|
|
17
|
+
return ["#root", ...parts].join(" > ").slice(0, 300);
|
|
18
|
+
};
|
|
19
|
+
const issues = [], counts = { shape: 0 };
|
|
20
|
+
for (const image of root.querySelectorAll("img")) {
|
|
21
|
+
if (!image.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }) || (image.complete && !image.naturalWidth)) continue;
|
|
22
|
+
const box = image.getBoundingClientRect();
|
|
23
|
+
if (box.width < 8 || box.height < 8) continue;
|
|
24
|
+
const style = getComputedStyle(image), authored = /^(?:auto\s+)?([\d.]+)\s*\/\s*([\d.]+)$/.exec(style.aspectRatio);
|
|
25
|
+
// The browser reports the attributes' ratio as "auto W / H"; only a value without auto is the author's.
|
|
26
|
+
const explicit = authored && !style.aspectRatio.startsWith("auto") ? Number(authored[1]) / Number(authored[2]) : undefined;
|
|
27
|
+
const width = Number(image.getAttribute("width")), height = Number(image.getAttribute("height"));
|
|
28
|
+
const attributes = width > 0 && height > 0 ? width / height : undefined;
|
|
29
|
+
if (explicit === undefined && (attributes === undefined || style.objectFit !== "fill")) continue;
|
|
30
|
+
const declared = explicit ?? attributes, rendered = box.width / box.height;
|
|
31
|
+
// Rounding moves a small box by a pixel or so; 3% and 2 px of height is not rounding.
|
|
32
|
+
if (Math.abs(rendered / declared - 1) <= 0.03 || Math.abs(box.width / declared - box.height) <= 2) continue;
|
|
33
|
+
if (counts.shape++ < nodeLimit) issues.push({ kind: "shape", selector: selector(image), html: image.outerHTML.replace(/\s+/g, " ").slice(0, 200), rendered: `${Math.round(box.width)}x${Math.round(box.height)}`, declared: explicit !== undefined ? `aspect-ratio ${style.aspectRatio}` : `width and height ${width}x${height}` });
|
|
34
|
+
}
|
|
35
|
+
return { issues, counts };
|
|
36
|
+
}
|
|
@@ -4,36 +4,43 @@ import { nonTextContrast } from "./non-text-contrast.mjs";
|
|
|
4
4
|
/**
|
|
5
5
|
* Renders what a scenario shows only after someone acts on it, and measures it with the same checks.
|
|
6
6
|
*
|
|
7
|
-
* Overlays: each control marked aria-haspopup
|
|
7
|
+
* Overlays: each control marked aria-haspopup that this render was assigned is clicked, and what
|
|
8
8
|
* opens is audited by axe and non-text contrast, then held to the phone viewport. Fixed layers are
|
|
9
9
|
* exempt from the overflow check of the page, so this is the only place their width is measured. An
|
|
10
10
|
* overlay a scenario renders open is measured the same way. Accessibility trees are read through
|
|
11
11
|
* ARIA, not names: a trigger with no aria-haspopup is not found, and its scenario can render it open.
|
|
12
12
|
*
|
|
13
|
-
* Hover and keyboard focus:
|
|
13
|
+
* Hover and keyboard focus: each control this render was assigned is hovered with the real mouse and
|
|
14
14
|
* focused as the keyboard would, for contrast only: axe color-contrast when a quick reading looks
|
|
15
15
|
* wrong, non-text contrast in that state, and the focus outline against what is around it. What
|
|
16
16
|
* already fails at rest is not repeated.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* The worker assigns targets in request order, so which render measures what does not depend on
|
|
19
|
+
* which page got there first. Results join the render's own, with selectors that say which state they
|
|
20
|
+
* were found in, and `result.coverage` says what was measured and what was skipped and why.
|
|
19
21
|
*/
|
|
20
22
|
const overlays = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"], dialog[open], [popover]:popover-open';
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
/** Lists what could be measured, in document order, each distinct one once; with `only`, marks those. */
|
|
25
|
+
function findTargets({ selector, attribute, signature, trigger, only }) {
|
|
26
|
+
const seen = new Set(), targets = [];
|
|
24
27
|
for (const element of document.querySelector("#root").querySelectorAll(selector)) {
|
|
25
|
-
if (targets.length >= limit) break;
|
|
26
28
|
const box = element.getBoundingClientRect();
|
|
27
29
|
if (box.width < 1 || box.height < 1 || element.closest('#ads-preview-status, [inert], [aria-disabled="true"]') || element.matches(":disabled") || !element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) continue;
|
|
28
30
|
const name = (element.getAttribute("aria-label") ?? element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 60) || element.localName;
|
|
29
|
-
const key = `${signature.map(
|
|
31
|
+
const key = `${signature.map(item => element.getAttribute(item) ?? "").join("|")}|${element.localName}|${trigger ? name : getComputedStyle(element.parentElement).backgroundColor}`;
|
|
30
32
|
if (seen.has(key)) continue;
|
|
31
|
-
seen.add(key);
|
|
32
|
-
|
|
33
|
-
targets.
|
|
33
|
+
seen.add(key);
|
|
34
|
+
if (only && !only.includes(key)) continue;
|
|
35
|
+
if (only) element.setAttribute(attribute, String(targets.length));
|
|
36
|
+
targets.push({ key, name });
|
|
34
37
|
}
|
|
35
|
-
return
|
|
38
|
+
return targets;
|
|
36
39
|
}
|
|
40
|
+
export const triggerTargets = { selector: '[aria-haspopup]:not([aria-haspopup="false"])', attribute: "data-ads-audit-trigger", signature: ["aria-haspopup", "class"], trigger: true };
|
|
41
|
+
export const controlTargets = { selector: 'button, a[href], input:not([type="hidden"]), select, textarea, [role="switch"], [role="checkbox"], [role="radio"], [role="slider"], [role="tab"]', attribute: "data-ads-audit-control", signature: ["class", "role", "type"] };
|
|
42
|
+
/** What this render could measure, read before anything acts on the page. */
|
|
43
|
+
export const listTargets = async frame => ({ triggers: await frame.evaluate(findTargets, triggerTargets), controls: await frame.evaluate(findTargets, controlTargets) });
|
|
37
44
|
const settle = () => new Promise(resolve => requestAnimationFrame(() => { for (const animation of document.getAnimations()) { try { animation.finish(); } catch { /* An endless one has no end to reach. */ } } requestAnimationFrame(resolve); }));
|
|
38
45
|
|
|
39
46
|
/** A quick reading of a hovered control's text against its background, so axe, which sets up the whole
|
|
@@ -74,10 +81,19 @@ function overlayPastViewport() {
|
|
|
74
81
|
const box = element.getBoundingClientRect(), width = document.documentElement.clientWidth, past = Math.round(Math.max(box.right - width, -box.left));
|
|
75
82
|
return past > 1 ? { overflow: past, html: element.outerHTML.replace(/\s+/g, " ").slice(0, 200) } : null;
|
|
76
83
|
}
|
|
77
|
-
/** The focus outline's contrast with what is around it, when the focus shows as an outline
|
|
78
|
-
|
|
84
|
+
/** The focus outline's contrast with what is around it, when the focus shows as an outline, and only
|
|
85
|
+
* where a keyboard can bring it. A negative tabindex is reachable only as an item of a composite widget
|
|
86
|
+
* that holds the roving tab stop, which arrow keys move through. */
|
|
87
|
+
async function focusOutline() {
|
|
79
88
|
const element = document.querySelector("[data-ads-audit-state]");
|
|
89
|
+
if (element.closest('[aria-hidden="true"], [inert]')) return { unreachable: true };
|
|
90
|
+
if (element.tabIndex < 0) {
|
|
91
|
+
const widget = element.closest('[role="group"], [role="tablist"], [role="menu"], [role="menubar"], [role="radiogroup"], [role="toolbar"], [role="listbox"], [role="tree"], [role="grid"]');
|
|
92
|
+
if (!widget?.querySelector('[tabindex="0"]')) return { unreachable: true };
|
|
93
|
+
}
|
|
80
94
|
element.focus({ focusVisible: true });
|
|
95
|
+
// An outline that transitions in is read where it ends, the same every run.
|
|
96
|
+
await new Promise(resolve => requestAnimationFrame(() => { for (const animation of document.getAnimations()) { try { animation.finish(); } catch { /* An endless one has no end to reach. */ } } requestAnimationFrame(resolve); }));
|
|
81
97
|
if (document.activeElement !== element || !element.matches(":focus-visible")) return null;
|
|
82
98
|
const style = getComputedStyle(element);
|
|
83
99
|
// A ring drawn with box-shadow is not read, so an outline beside one is not taken for the only indicator.
|
|
@@ -99,9 +115,14 @@ const unmarked = text => text?.replace(/\[?data-ads-audit-[a-z.]+(?:="[^"]*")?\]
|
|
|
99
115
|
const named = (nodes, label) => nodes.map(node => ({ ...node, selector: `${label}: ${unmarked(node.selector)}`.slice(0, 300), ...(node.html ? { html: unmarked(node.html) } : {}) }));
|
|
100
116
|
const labelled = (groups, label) => groups.map(group => ({ ...group, nodes: named(group.nodes, label) }));
|
|
101
117
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
const failure = error => /detached|not attached|intercept/i.test(error.message) ? "detached" : /timeout/i.test(error.message) ? "timeout" : "failed";
|
|
119
|
+
|
|
120
|
+
/** Runs both on what this render was assigned, adding what it finds to `result`. One failing target
|
|
121
|
+
* ends only its own part, and is recorded in `result.coverage`. */
|
|
122
|
+
export async function auditRenderStates({ page, frame, result, request, phoneWidth, assigned }) {
|
|
123
|
+
const { nodeLimit, tags } = request, desktop = page.viewportSize();
|
|
124
|
+
const coverage = result.coverage = { overlays: 0, controls: 0, skipped: [] };
|
|
125
|
+
const skip = (reason, name) => coverage.skipped.push({ reason, name });
|
|
105
126
|
const isClosed = () => frame.waitForFunction(() => { const element = document.querySelector("[data-ads-audit-overlay]"); return !element || !element.checkVisibility(); }, undefined, { timeout: 1000 }).then(() => true, () => false);
|
|
106
127
|
const unmark = () => frame.evaluate(() => { for (const element of document.querySelectorAll("[data-ads-audit-overlay]")) element.removeAttribute("data-ads-audit-overlay"); });
|
|
107
128
|
const measureOverlay = async (label, reopen) => {
|
|
@@ -122,42 +143,46 @@ export async function auditRenderStates({ page, frame, result, request, phoneWid
|
|
|
122
143
|
if (past) result.layout.push({ width: phoneWidth, issues: [{ kind: "viewport", selector: label, ...past }], counts: { viewport: 1 } });
|
|
123
144
|
await page.setViewportSize(desktop);
|
|
124
145
|
await frame.evaluate(settle);
|
|
125
|
-
|
|
146
|
+
coverage.overlays++;
|
|
126
147
|
};
|
|
127
148
|
// Already open: nothing to click, and nothing to close.
|
|
128
149
|
if (await frame.evaluate(markOpened, { overlays, known: false })) {
|
|
129
150
|
await measureOverlay("open overlay");
|
|
130
151
|
await unmark();
|
|
131
152
|
}
|
|
132
|
-
|
|
133
|
-
const {
|
|
134
|
-
for (const
|
|
135
|
-
for (const [index, name] of triggers.entries()) {
|
|
153
|
+
const triggers = await frame.evaluate(findTargets, { ...triggerTargets, only: assigned.triggers.map(item => item.key) });
|
|
154
|
+
for (const { key, name } of assigned.triggers) if (!triggers.some(item => item.key === key)) skip("overlay-trigger-gone", name);
|
|
155
|
+
for (const [index, { name }] of triggers.entries()) {
|
|
136
156
|
try {
|
|
137
|
-
|
|
157
|
+
// Only what is open now is known: a closed overlay's element is often reused by the next one.
|
|
158
|
+
await frame.evaluate(overlays => { for (const element of document.querySelectorAll(overlays)) element.toggleAttribute("data-ads-audit-known", element.checkVisibility()); }, overlays);
|
|
138
159
|
const open = async () => {
|
|
139
|
-
|
|
140
|
-
|
|
160
|
+
// A click while the last overlay is still going away only dismisses it, so a second one opens.
|
|
161
|
+
for (const wait of [3000, 1500]) {
|
|
162
|
+
await frame.locator(`[data-ads-audit-trigger="${index}"]`).click({ timeout: 5000 });
|
|
163
|
+
if (await frame.waitForFunction(markOpened, { overlays, known: true }, { timeout: wait }).then(() => true, () => false)) return true;
|
|
164
|
+
await frame.evaluate(settle);
|
|
165
|
+
}
|
|
166
|
+
return false;
|
|
141
167
|
};
|
|
142
|
-
if (!await open()) continue;
|
|
168
|
+
if (!await open()) { skip("overlay-did-not-open", name); continue; }
|
|
143
169
|
await measureOverlay(`open overlay "${name}"`, open);
|
|
144
170
|
await page.keyboard.press("Escape");
|
|
145
171
|
const closed = await isClosed();
|
|
146
172
|
await unmark();
|
|
147
173
|
// One that stays open covers the page, so the next trigger cannot be reached.
|
|
148
|
-
if (!closed) break;
|
|
149
|
-
} catch {
|
|
174
|
+
if (!closed) { for (const { name: next } of triggers.slice(index + 1)) skip("overlay-left-open", next); break; }
|
|
175
|
+
} catch (error) { skip(`overlay-${failure(error)}`, name); }
|
|
150
176
|
}
|
|
151
177
|
// What already fails at rest: axe names elements the same way each run, and non-text findings are the same colors.
|
|
152
178
|
const pair = issue => JSON.stringify([issue.kind, issue.foreground, issue.background]);
|
|
153
179
|
const rest = new Set([...result.nonText.issues.map(pair), ...result.violations.filter(item => item.id === "color-contrast").flatMap(item => item.nodes.map(node => node.selector))]);
|
|
154
|
-
|
|
155
|
-
const {
|
|
156
|
-
for (const
|
|
157
|
-
for (const [index] of targets.entries()) {
|
|
180
|
+
const targets = await frame.evaluate(findTargets, { ...controlTargets, only: assigned.controls.map(item => item.key) });
|
|
181
|
+
for (const { key, name } of assigned.controls) if (!targets.some(item => item.key === key)) skip("control-gone", name);
|
|
182
|
+
for (const [index, { name }] of targets.entries()) {
|
|
158
183
|
const target = `[data-ads-audit-control="${index}"]`;
|
|
159
184
|
try {
|
|
160
|
-
await frame.locator(target).hover({ timeout:
|
|
185
|
+
await frame.locator(target).hover({ timeout: 3000, force: true });
|
|
161
186
|
await frame.evaluate(target => document.querySelector(target).setAttribute("data-ads-audit-state", ""), target);
|
|
162
187
|
await frame.evaluate(settle);
|
|
163
188
|
if (await frame.evaluate(hoverTextSuspect, target)) {
|
|
@@ -170,13 +195,14 @@ export async function auditRenderStates({ page, frame, result, request, phoneWid
|
|
|
170
195
|
result.nonText.issues.push(...named(issues, "hover"));
|
|
171
196
|
for (const issue of issues) result.nonText.counts[issue.kind] = (result.nonText.counts[issue.kind] ?? 0) + 1;
|
|
172
197
|
const outline = await frame.evaluate(focusOutline);
|
|
173
|
-
if (outline)
|
|
198
|
+
if (outline?.unreachable) skip("focus-not-reachable", name);
|
|
199
|
+
else if (outline) {
|
|
174
200
|
result.nonText.issues.push({ kind: "focus", selector: `focus: ${await frame.locator(target).evaluate(element => element.localName)}`, ...outline });
|
|
175
201
|
result.nonText.counts.focus = (result.nonText.counts.focus ?? 0) + 1;
|
|
176
202
|
}
|
|
177
203
|
await frame.evaluate(target => { const element = document.querySelector(target); element.removeAttribute("data-ads-audit-state"); element.blur(); }, target);
|
|
178
|
-
|
|
204
|
+
coverage.controls++;
|
|
205
|
+
} catch (error) { skip(`control-${failure(error)}`, name); }
|
|
179
206
|
}
|
|
180
207
|
await page.mouse.move(desktop.width - 1, desktop.height - 1);
|
|
181
|
-
result.controls = (result.controls ?? 0) + targets.length;
|
|
182
208
|
}
|
|
@@ -3,21 +3,22 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { openPreviewScenario } from "../verification/browser.mjs";
|
|
5
5
|
import { axeRun } from "./axe-run.mjs";
|
|
6
|
-
import { firstRender } from "./first-render.mjs";
|
|
6
|
+
import { contentQuiet, firstRender } from "./first-render.mjs";
|
|
7
7
|
import { nonTextContrast } from "./non-text-contrast.mjs";
|
|
8
8
|
import { layoutOverflow } from "./layout-overflow.mjs";
|
|
9
9
|
import { layoutShift } from "./layout-shift.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { imageShape } from "./image-shape.mjs";
|
|
11
|
+
import { auditRenderStates, listTargets } from "./render-states.mjs";
|
|
11
12
|
|
|
12
13
|
// Runs only as an owned child, using the receiving project's browser dependency.
|
|
13
14
|
const request = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
14
15
|
const playwright = createRequire(import.meta.url)(request.playwright);
|
|
15
16
|
const axe = readFileSync(request.axe, "utf8");
|
|
16
|
-
const runs = [];
|
|
17
|
+
const runs = [], capped = new Map(), claimed = new Set(request.claimed ?? []);
|
|
17
18
|
/** Atomic, so a worker that dies leaves the renders it finished readable. */
|
|
18
19
|
function publish() {
|
|
19
20
|
const file = path.join(request.output, "report.json"), temporary = `${file}.tmp`;
|
|
20
|
-
writeFileSync(temporary, JSON.stringify({ schemaVersion: 1, runId: request.runId, runs }));
|
|
21
|
+
writeFileSync(temporary, JSON.stringify({ schemaVersion: 1, runId: request.runId, runs, capped: [...capped.values()] }));
|
|
21
22
|
renameSync(temporary, file);
|
|
22
23
|
}
|
|
23
24
|
let browser;
|
|
@@ -28,31 +29,60 @@ try {
|
|
|
28
29
|
const apps = request.apps.filter(app => app.theme === theme);
|
|
29
30
|
// The audit injects its own script; bypassCSP keeps project CSP from blocking it.
|
|
30
31
|
const context = await browser.newContext({ viewport: request.viewport, deviceScaleFactor: 1, colorScheme: apps[0].scheme, bypassCSP: true, reducedMotion: "reduce" });
|
|
31
|
-
|
|
32
|
+
// Each render lists what it could measure, then takes its turn in request order: a shared control is
|
|
33
|
+
// measured by the first scenario that has it, however fast the pages load. A cap leaves the rest for later renders.
|
|
34
|
+
const lists = apps.map(() => { let resolve; const promise = new Promise(done => { resolve = done; }); return { promise, resolve }; });
|
|
35
|
+
const assign = (kind, { scenario, theme, brand }, items, limit) => {
|
|
36
|
+
const scope = JSON.stringify([theme, brand ?? null]), fresh = items.map(item => ({ ...item, claim: `${scope}${kind}${item.key}` })).filter(item => !claimed.has(item.claim));
|
|
37
|
+
for (const item of fresh.slice(0, limit)) { claimed.add(item.claim); capped.delete(item.claim); }
|
|
38
|
+
for (const item of fresh.slice(limit)) if (!capped.has(item.claim)) capped.set(item.claim, { claim: item.claim, reason: `${kind}-cap`, name: item.name, scenario, theme, ...(brand ? { brand } : {}) });
|
|
39
|
+
return fresh.slice(0, limit);
|
|
40
|
+
};
|
|
41
|
+
const turns = [];
|
|
42
|
+
apps.forEach((app, index) => { turns[index] = (turns[index - 1] ?? Promise.resolve()).then(() => lists[index].promise).then(({ triggers, controls }) => ({ triggers: assign("overlay", app, triggers, request.overlayLimit), controls: assign("control", app, controls, request.stateLimit) })); });
|
|
32
43
|
try {
|
|
33
44
|
// A bounded number of pages render at once; results keep request order.
|
|
34
45
|
const results = [];
|
|
35
46
|
let next = 0;
|
|
36
|
-
async function lane() { while (next < apps.length) { const index = next++; results[index] = await attempt(apps[index]); runs.push(results[index]); publish(); } }
|
|
47
|
+
async function lane() { while (next < apps.length) { const index = next++; results[index] = await attempt(apps[index], index); runs.push(results[index]); publish(); } }
|
|
37
48
|
await Promise.all(Array.from({ length: Math.min(apps.length, request.concurrency ?? 1) }, lane));
|
|
38
49
|
// One render failing is that render's result; what it found before failing is kept.
|
|
39
|
-
async function attempt(app) {
|
|
50
|
+
async function attempt(app, index) {
|
|
40
51
|
const partial = {};
|
|
41
|
-
try { return await audit(app, partial); }
|
|
52
|
+
try { return await audit(app, partial, index); }
|
|
42
53
|
catch (error) {
|
|
54
|
+
lists[index].resolve({ triggers: [], controls: [] });
|
|
43
55
|
const code = error.failure?.code;
|
|
44
56
|
return { scenario: app.scenario, theme: app.theme, ...(app.brand ? { brand: app.brand } : {}), failed: true, cause: `${String(error.message).replace(/\s+/g, " ").trim().slice(0, 460)}${code ? ` (${code})` : ""}`, ...partial };
|
|
45
57
|
}
|
|
46
58
|
}
|
|
47
|
-
async function audit(app, partial) {
|
|
59
|
+
async function audit(app, partial, index) {
|
|
48
60
|
const page = await context.newPage();
|
|
61
|
+
// What the page is still loading: its files, also through the preview's asset reads. Streams and the host's status polling never end, so they do not count.
|
|
62
|
+
const loading = new Set(), loads = request => ["script", "stylesheet", "image", "font"].includes(request.resourceType()) || /resources\/read.*ads:\/\/assets\//.test(request.postData() ?? "");
|
|
63
|
+
page.on("request", request => { if (loads(request)) loading.add(request); });
|
|
64
|
+
for (const event of ["requestfinished", "requestfailed"]) page.on(event, request => loading.delete(request));
|
|
65
|
+
/** Quiet in the page and nothing loading, up to the limit: an async grammar shows up as both. */
|
|
66
|
+
const settled = async () => {
|
|
67
|
+
const end = Date.now() + request.contentLimitMs;
|
|
68
|
+
while (Date.now() < end) {
|
|
69
|
+
const quiet = await frame.evaluate(contentQuiet, { quietMs: request.contentQuietMs, limitMs: Math.max(end - Date.now(), 1) });
|
|
70
|
+
if (quiet && !loading.size) return true;
|
|
71
|
+
if (!quiet) return false;
|
|
72
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
let frame;
|
|
49
77
|
try {
|
|
50
|
-
|
|
78
|
+
frame = await openPreviewScenario(page, app.url, app.scenario, { timeout });
|
|
51
79
|
await frame.waitForFunction(theme => document.documentElement.dataset.theme === theme, app.theme, { timeout });
|
|
52
80
|
if (app.brand) await frame.waitForFunction(brand => document.documentElement.dataset.brand === brand, app.brand, { timeout });
|
|
53
81
|
// Nothing is hovered at rest: the mouse starts over whatever sits at the page's corner.
|
|
54
82
|
await page.mouse.move(request.viewport.width - 1, request.viewport.height - 1);
|
|
55
83
|
await frame.evaluate(firstRender);
|
|
84
|
+
const contentSettled = await settled();
|
|
85
|
+
lists[index].resolve(await listTargets(frame));
|
|
56
86
|
// Before the audit touches the page: resizing below would shift it.
|
|
57
87
|
partial.layoutShift = await frame.evaluate(layoutShift, { nodeLimit: request.nodeLimit });
|
|
58
88
|
if (!await frame.evaluate(() => !!window.axe)) await frame.addScriptTag({ content: axe });
|
|
@@ -61,12 +91,17 @@ try {
|
|
|
61
91
|
Object.assign(partial, result);
|
|
62
92
|
result.nonText = await frame.evaluate(nonTextContrast, { nodeLimit: request.nodeLimit });
|
|
63
93
|
// The same page is resized: one evaluate per width, no new render.
|
|
64
|
-
result.layout = [];
|
|
94
|
+
result.layout = []; result.imageShape = new Map();
|
|
65
95
|
for (const width of request.overflowWidths) {
|
|
66
96
|
await page.setViewportSize({ width, height: request.viewport.height });
|
|
67
97
|
result.layout.push({ width, ...await frame.evaluate(layoutOverflow, { nodeLimit: request.nodeLimit, width }) });
|
|
98
|
+
for (const issue of (await frame.evaluate(imageShape, { nodeLimit: request.nodeLimit })).issues) result.imageShape.set(issue.selector, { ...issue, width });
|
|
68
99
|
}
|
|
69
|
-
|
|
100
|
+
const assigned = await turns[index];
|
|
101
|
+
await auditRenderStates({ page, frame, result, request, phoneWidth: request.overflowWidths[0], assigned });
|
|
102
|
+
if (!contentSettled) result.coverage.skipped.push({ reason: "content-still-changing", name: "the page" });
|
|
103
|
+
result.coverage.claimed = [...assigned.triggers, ...assigned.controls].map(item => item.claim);
|
|
104
|
+
result.imageShape = [...result.imageShape.values()];
|
|
70
105
|
// Last: it narrows #root for good, at the widest viewport, as a pane in a window would be.
|
|
71
106
|
// A scenario with the main landmark is a whole page, which no pane hosts.
|
|
72
107
|
if (app.container && !await frame.evaluate(() => !!document.querySelector('main, [role="main"]'))) {
|