@reqvire-org/ads 0.3.50 → 0.3.52
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 +1 -1
- package/dist/browser-audit/axe-run.mjs +17 -0
- package/dist/browser-audit/first-render.mjs +18 -0
- package/dist/browser-audit/layout-overflow.mjs +88 -41
- package/dist/browser-audit/non-text-contrast.mjs +12 -7
- package/dist/browser-audit/render-states.mjs +182 -0
- package/dist/browser-audit/worker.mjs +23 -12
- package/dist/browser-audit.mjs +56 -13
- package/dist/bun-compiler.mjs +9 -1
- package/dist/capture/worker.mjs +2 -5
- package/dist/check.mjs +5 -3
- package/dist/cli.mjs +11 -5
- package/dist/config.mjs +2 -2
- package/dist/finding-rules.mjs +11 -0
- package/dist/layout-widths.mjs +132 -79
- package/dist/mcp/preview-watch.mjs +2 -2
- package/dist/mcp/server.mjs +2 -2
- package/dist/preview-resources.mjs +4 -1
- package/dist/scenarios-compiler.mjs +2 -2
- package/dist/skills/ads-break-ui/SKILL.md +2 -1
- package/dist/skills/ads-break-ui/references/design-data.md +34 -14
- package/dist/skills/ads-break-ui/references/validation.md +1 -1
- package/dist/skills/ads-designer/SKILL.md +6 -4
- package/dist/skills/ads-designer/references/design-data.md +34 -14
- package/dist/skills/ads-designer/references/validation.md +1 -1
- package/dist/skills/ads-import/references/design-data.md +34 -14
- package/dist/skills/ads-import/references/validation.md +1 -1
- package/dist/skills/ads-motion/references/design-data.md +34 -14
- package/dist/skills/ads-motion/references/validation.md +1 -1
- package/dist/skills/ads-port/references/design-data.md +34 -14
- package/dist/skills/ads-port/references/validation.md +1 -1
- package/dist/starters/preact/ds.config.json +0 -1
- package/dist/starters/react/README.md +6 -4
- package/dist/starters/react/design-system/components/Content/Image/Image.tsx +7 -4
- package/dist/starters/react/design-system/components/Content/Image/README.md +2 -2
- package/dist/starters/react/design-system/tokens/spacing.css +1 -1
- package/dist/starters/react/ds.config.json +0 -1
- package/docs/ADS.md +2 -2
- package/docs/ARCHITECTURE.md +9 -6
- package/docs/CHANGELOG.md +81 -12
- package/docs/GUIDE.md +77 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ There is no warning level.
|
|
|
78
78
|
| **Rendered accessibility** | `ads audit` runs axe-core (WCAG 2.2 AA rules) in every rendered UI scenario, once per theme and brand, plus ADS's own non-text contrast check (WCAG 1.4.11, which axe does not cover): a field or other control without its own text or icon, whose border is its only boundary, needs that border at 3:1 against the background around it, and an icon-only control needs its icon at 3:1 against its background. The audit gates `ads validate` by default, and MCP draft acceptance and guarded patches audit the candidate's affected scenarios (all of them after configuration, foundation, token or asset changes); `browserAudit: false` in a policy turns it off. It needs the project's Playwright and browser (`npx playwright install chromium`); without them the policy fails and names what to install. |
|
|
79
79
|
| **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
80
|
| **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
|
-
| **Layout** | Widths are fluid on the grid. `layout-fixed-width` fails a width, `
|
|
81
|
+
| **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
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
83
|
| **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
84
|
| **Tokens** | Ownership, naming, rhythm, missing and scenario references; equal values in different roles are flagged for review. |
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One axe-core run inside the scenario document, cut down to what a report keeps. `include` is the
|
|
3
|
+
* selector to audit, `rules` narrows it to named rules. It must stay self-contained: Playwright
|
|
4
|
+
* serializes the function into the page.
|
|
5
|
+
*/
|
|
6
|
+
export async function axeRun({ tags, nodeLimit, include = "#root", rules }) {
|
|
7
|
+
// Asking for a group is what keeps its nodes: axe cuts every other group to one.
|
|
8
|
+
const runOnly = rules ? { type: "rule", values: rules } : { type: "tag", values: tags };
|
|
9
|
+
const outcome = await window.axe.run({ include: [[include]], exclude: [["#ads-preview-status"]] }, { runOnly, resultTypes: ["violations", "incomplete"], elementRef: false, ancestry: false });
|
|
10
|
+
const clip = (text, size) => typeof text === "string" ? text.replace(/\s+/g, " ").trim().slice(0, size) : "";
|
|
11
|
+
const selector = node => clip(node.target.flat().join(" "), 300), html = node => clip(node.html, 200);
|
|
12
|
+
const group = item => ({ id: item.id, impact: item.impact, tags: item.tags, help: clip(item.help, 300), helpUrl: clip(item.helpUrl, 300), nodeCount: item.nodes.length });
|
|
13
|
+
// axe's own key for why it could not decide, such as bgGradient or pseudoContent.
|
|
14
|
+
const reason = node => { const check = [...node.any, ...node.all, ...node.none].find(item => item.data?.messageKey) ?? [...node.any, ...node.all, ...node.none][0]; return clip(check?.data?.messageKey ?? check?.id ?? "", 80); };
|
|
15
|
+
return { violations: outcome.violations.map(violation => ({ ...group(violation), nodes: violation.nodes.slice(0, nodeLimit).map(node => ({ selector: selector(node), html: html(node), summary: clip(node.failureSummary, 500) })) })),
|
|
16
|
+
incomplete: outcome.incomplete.map(item => ({ ...group(item), nodes: item.nodes.slice(0, nodeLimit).map(node => ({ selector: selector(node), html: html(node), reason: reason(node) })) })) };
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits for a rendered scenario's first render: its fonts, the images it is loading, and two frames.
|
|
3
|
+
* A lazy image outside the viewport or not rendered has not started loading, and decode() on it
|
|
4
|
+
* never settles, so it is not waited on. It cannot shift the first view either: the browser scores
|
|
5
|
+
* only movement inside the viewport. One overall limit stops a slow file from holding the audit up;
|
|
6
|
+
* what arrives after it is simply not measured.
|
|
7
|
+
* It must stay self-contained: Playwright serializes the function into the page.
|
|
8
|
+
*/
|
|
9
|
+
export async function firstRender() {
|
|
10
|
+
const started = image => {
|
|
11
|
+
if (image.loading !== "lazy") return true;
|
|
12
|
+
const box = image.getBoundingClientRect();
|
|
13
|
+
return image.checkVisibility() && box.bottom >= 0 && box.right >= 0 && box.top <= window.innerHeight && box.left <= window.innerWidth;
|
|
14
|
+
};
|
|
15
|
+
const ready = Promise.all([document.fonts.ready, ...[...document.images].filter(started).map(image => image.decode().catch(() => {}))]);
|
|
16
|
+
await Promise.race([ready, new Promise(resolve => setTimeout(resolve, 5000))]);
|
|
17
|
+
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
18
|
+
}
|
|
@@ -1,57 +1,104 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ADS's rendered layout check, run in the scenario document once per audited viewport width
|
|
2
|
+
* ADS's rendered layout check, run in the scenario document once per audited viewport width, and
|
|
3
|
+
* once with #root narrowed to `container` px wide by the worker, as a pane would.
|
|
3
4
|
* It must stay self-contained: Playwright serializes the function into the page.
|
|
4
5
|
*
|
|
5
6
|
* - "document": the scenario document scrolls horizontally (scrollWidth > clientWidth).
|
|
6
7
|
* - "viewport": an element in #root reaches past the viewport's inline edges while its parent
|
|
7
8
|
* does not, the element that pushes content out.
|
|
9
|
+
* - "container": the same, past the edges of the narrowed #root. In this render, "container" and
|
|
10
|
+
* "clipped" need a width that forces it: the element or something in it has a fixed width above
|
|
11
|
+
* a small part's limit. A row of buttons that is simply too long for a pane is not reported.
|
|
8
12
|
* - "clipped": an element with overflow-x hidden or clip whose content is more than 4 px wider
|
|
9
13
|
* than its box, so content is cut off (a small negative margin cuts nothing).
|
|
10
|
-
* Intended scrollers (overflow-x auto or scroll) and their content, text-overflow: ellipsis,
|
|
11
|
-
* carousels (aria-roledescription="carousel"),
|
|
14
|
+
* Intended scrollers (overflow-x auto or scroll, other than the outermost window-tall one) and their content, text-overflow: ellipsis,
|
|
15
|
+
* carousels (aria-roledescription="carousel"), pannable widgets (role="application"),
|
|
12
16
|
* native text fields, visually hidden content (a box of 1 px or less, clip or clip-path) and
|
|
13
17
|
* fixed-position layers are exempt.
|
|
18
|
+
*
|
|
19
|
+
* A resize reaches the frame a frame later, and a component that refits through ResizeObserver and
|
|
20
|
+
* requestAnimationFrame refits later still. So layout is measured once it has stopped moving for a
|
|
21
|
+
* few frames, bounded for a page that never stops. A page that looks wrong gets more frames, for a
|
|
22
|
+
* refit on a timer: only a change in layout can clear what was found.
|
|
14
23
|
*/
|
|
15
|
-
export async function layoutOverflow({ nodeLimit, width: expected }) {
|
|
16
|
-
// The resized frame lays out on its next frames.
|
|
17
|
-
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
18
|
-
if (window.innerWidth !== expected) throw new Error(`The scenario document is ${window.innerWidth} px wide, not the audited ${expected} px.`);
|
|
24
|
+
export async function layoutOverflow({ nodeLimit, width: expected, container, smallPart }) {
|
|
19
25
|
const root = document.querySelector("#root");
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// A frame, or a time limit for a document that has stopped getting frames.
|
|
27
|
+
const nextFrame = () => new Promise(resolve => { const limit = setTimeout(resolve, 500); requestAnimationFrame(() => { clearTimeout(limit); resolve(); }); });
|
|
28
|
+
// Layout boxes only: a transform, such as a spinner's, is not layout moving.
|
|
29
|
+
const layout = () => { let sum = document.documentElement.scrollWidth; for (const element of root?.querySelectorAll("*") ?? []) if (element.offsetWidth !== undefined) sum = (sum * 31 + element.offsetWidth * 7 + element.offsetLeft) | 0; return sum; };
|
|
30
|
+
async function settled() {
|
|
31
|
+
let previous, quiet = 0;
|
|
32
|
+
for (let count = 0; count < 20 && (quiet < 2 || window.innerWidth !== expected); count++) {
|
|
33
|
+
await nextFrame();
|
|
34
|
+
const current = layout();
|
|
35
|
+
quiet = current === previous ? quiet + 1 : 0;
|
|
36
|
+
previous = current;
|
|
27
37
|
}
|
|
28
|
-
return ["#root", ...parts].join(" > ");
|
|
29
|
-
};
|
|
30
|
-
const report = (kind, element, detail) => { if (counts[kind]++ < nodeLimit) issues.push({ kind, selector: element === document.documentElement ? "html" : selector(element).slice(0, 300), html: element === document.documentElement ? "" : element.outerHTML.replace(/\s+/g, " ").slice(0, 200), ...detail }); };
|
|
31
|
-
if (document.documentElement.scrollWidth > width + 1) report("document", document.documentElement, { overflow: document.documentElement.scrollWidth - width });
|
|
32
|
-
const exempt = new Map();
|
|
33
|
-
/** Whether an element is inside an intended scroller, a fixed layer or hidden content. */
|
|
34
|
-
function excluded(element) {
|
|
35
|
-
if (!element || element === root) return false;
|
|
36
|
-
if (exempt.has(element)) return exempt.get(element);
|
|
37
|
-
const style = getComputedStyle(element), box = element.getBoundingClientRect();
|
|
38
|
-
const value = /^(?:auto|scroll)$/.test(style.overflowX) || style.position === "fixed" || style.clip !== "auto" && style.position === "absolute" || style.clipPath !== "none"
|
|
39
|
-
|| (box.width <= 1 || box.height <= 1) && style.overflow !== "visible" || excluded(element.parentElement);
|
|
40
|
-
exempt.set(element, value); return value;
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
await settled();
|
|
40
|
+
if (window.innerWidth !== expected) throw new Error(`The scenario document is ${window.innerWidth} px wide, not the audited ${expected} px.`);
|
|
41
|
+
if (!root) return { issues: [], counts: {} };
|
|
42
|
+
const found = measure();
|
|
43
|
+
if (!found.issues.length) return found;
|
|
44
|
+
const seen = layout();
|
|
45
|
+
for (let count = 0; count < 12; count++) {
|
|
46
|
+
await nextFrame();
|
|
47
|
+
if (layout() !== seen) { await settled(); return measure(); }
|
|
48
|
+
}
|
|
49
|
+
return found;
|
|
50
|
+
function measure() {
|
|
51
|
+
const width = document.documentElement.clientWidth, issues = [], counts = { document: 0, viewport: 0, container: 0, clipped: 0 };
|
|
52
|
+
const pane = container ? root.getBoundingClientRect() : { left: 0, right: width }, edge = container ? "container" : "viewport";
|
|
53
|
+
const selector = element => {
|
|
54
|
+
const parts = [];
|
|
55
|
+
for (let node = element; node && node !== root; node = node.parentElement) {
|
|
56
|
+
const siblings = [...node.parentElement.children].filter(child => child.localName === node.localName);
|
|
57
|
+
parts.unshift(`${node.localName}${siblings.length > 1 ? `:nth-of-type(${siblings.indexOf(node) + 1})` : ""}`);
|
|
58
|
+
}
|
|
59
|
+
return ["#root", ...parts].join(" > ");
|
|
60
|
+
};
|
|
61
|
+
const report = (kind, element, detail) => { if (counts[kind]++ < nodeLimit) issues.push({ kind, selector: element === document.documentElement ? "html" : selector(element).slice(0, 300), html: element === document.documentElement ? "" : element.outerHTML.replace(/\s+/g, " ").slice(0, 200), ...detail }); };
|
|
62
|
+
if (!container && document.documentElement.scrollWidth > width + 1) report("document", document.documentElement, { overflow: document.documentElement.scrollWidth - width });
|
|
63
|
+
const exempt = new Map();
|
|
64
|
+
/** Whether a set width, not content, holds this element open: a length above the small-part limit. */
|
|
65
|
+
function setWide(element) {
|
|
66
|
+
if (!element.computedStyleMap) return true;
|
|
67
|
+
const wide = property => { const value = element.computedStyleMap().get(property); return value instanceof CSSUnitValue && value.unit === "px" && value.value > smallPart; };
|
|
68
|
+
return element.getBoundingClientRect().width > smallPart && element.checkVisibility() && (wide("width") || wide("min-width") || wide("flex-basis") && getComputedStyle(element).flexShrink === "0");
|
|
69
|
+
}
|
|
70
|
+
const forced = element => !container || setWide(element) || [...element.querySelectorAll("*")].some(inner => !excluded(inner.parentElement) && setWide(inner));
|
|
71
|
+
// The outermost box as tall as the window is the page or the project's preview frame, not an
|
|
72
|
+
// intended scroller or clip: overflow-y: auto computes overflow-x to auto, and a page that scrolls
|
|
73
|
+
// sideways is what this check is for. A scroller inside it is a real one.
|
|
74
|
+
const frame = element => {
|
|
75
|
+
if (Math.abs(element.getBoundingClientRect().height - window.innerHeight) > 1) return false;
|
|
76
|
+
for (let node = element.parentElement; node && node !== root; node = node.parentElement) if (/^(?:auto|scroll)$/.test(getComputedStyle(node).overflowX)) return false;
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
/** Whether an element is inside an intended scroller, a fixed layer or hidden content. */
|
|
80
|
+
function excluded(element) {
|
|
81
|
+
if (!element || element === root) return false;
|
|
82
|
+
if (exempt.has(element)) return exempt.get(element);
|
|
83
|
+
const style = getComputedStyle(element), box = element.getBoundingClientRect();
|
|
84
|
+
const value = /^(?:auto|scroll)$/.test(style.overflowX) && !frame(element) || style.position === "fixed" || style.clip !== "auto" && style.position === "absolute" || style.clipPath !== "none"
|
|
85
|
+
|| (box.width <= 1 || box.height <= 1) && style.overflow !== "visible" || excluded(element.parentElement);
|
|
86
|
+
exempt.set(element, value); return value;
|
|
87
|
+
}
|
|
88
|
+
for (const element of root.querySelectorAll("*")) {
|
|
89
|
+
if (element.closest("#ads-preview-status") || element.closest("svg") && element.localName !== "svg") continue;
|
|
90
|
+
if (excluded(element.parentElement)) continue;
|
|
91
|
+
const style = getComputedStyle(element);
|
|
92
|
+
if (style.position === "fixed" || !element.checkVisibility({ visibilityProperty: true })) continue;
|
|
93
|
+
const box = element.getBoundingClientRect();
|
|
94
|
+
if (box.width <= 1 || box.height <= 1) continue;
|
|
95
|
+
// A clipping ancestor already reports the content it cuts off, and nothing paints past it.
|
|
96
|
+
const contained = () => { for (let node = element.parentElement; node && node !== root; node = node.parentElement) if (/^(?:hidden|clip)$/.test(getComputedStyle(node).overflowX) && !frame(node)) return true; return false; };
|
|
97
|
+
const parent = element.parentElement === root ? pane : element.parentElement.getBoundingClientRect();
|
|
98
|
+
if ((box.right > pane.right + 1 || box.left < pane.left - 1) && !(parent.right > pane.right + 1 || parent.left < pane.left - 1) && !contained() && forced(element)) report(edge, element, { overflow: Math.round(Math.max(box.right - pane.right, pane.left - box.left)) });
|
|
99
|
+
if (/^(?:hidden|clip)$/.test(style.overflowX) && element.scrollWidth > element.clientWidth + 4 && style.textOverflow !== "ellipsis" && !element.closest('[aria-roledescription="carousel"], [role="application"]') && !/^(?:input|textarea|select)$/.test(element.localName) && style.clip === "auto" && style.clipPath === "none" && forced(element))
|
|
100
|
+
report("clipped", element, { overflow: element.scrollWidth - element.clientWidth });
|
|
101
|
+
}
|
|
102
|
+
return { issues, counts };
|
|
55
103
|
}
|
|
56
|
-
return { issues, counts };
|
|
57
104
|
}
|
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
* surrounding background ("border"). A button, link or tab with text or an icon is exempt: WCAG
|
|
11
11
|
* 1.4.11 needs no boundary when that content identifies the control.
|
|
12
12
|
* An icon-only control (an svg and no text) needs its icon's paint at 3:1 against the control's
|
|
13
|
-
* effective background ("icon").
|
|
13
|
+
* effective background ("icon"). A busy control (aria-busy="true") is checked even when disabled,
|
|
14
|
+
* and its icon even when it has text: the spinner is the state it reports.
|
|
14
15
|
* A control whose background contrasts 3:1 with its surroundings is identified by its background;
|
|
15
16
|
* an icon-only one is still checked against that background. Disabled controls are exempt.
|
|
16
17
|
* Browser-drawn native checkboxes, radios and ranges and backgrounds under an image or gradient
|
|
17
18
|
* are skipped. Colors are read through a 1×1 canvas, so every CSS color syntax resolves to sRGB.
|
|
19
|
+
* `scope` measures one element and what is in it instead of #root.
|
|
18
20
|
*/
|
|
19
|
-
export function nonTextContrast({ nodeLimit }) {
|
|
20
|
-
const root = document.querySelector("#root");
|
|
21
|
+
export function nonTextContrast({ nodeLimit, scope }) {
|
|
22
|
+
const root = document.querySelector(scope ?? "#root");
|
|
21
23
|
if (!root) return { issues: [], counts: {} };
|
|
22
24
|
const canvas = document.createElement("canvas"); canvas.width = canvas.height = 1;
|
|
23
25
|
const context = canvas.getContext("2d", { willReadFrequently: true }), cache = new Map();
|
|
@@ -48,12 +50,15 @@ export function nonTextContrast({ nodeLimit }) {
|
|
|
48
50
|
const siblings = [...node.parentElement.children].filter(child => child.localName === node.localName);
|
|
49
51
|
parts.unshift(`${node.localName}${siblings.length > 1 ? `:nth-of-type(${siblings.indexOf(node) + 1})` : ""}`);
|
|
50
52
|
}
|
|
51
|
-
return ["#root", ...parts].join(" > ");
|
|
53
|
+
return [scope ? root.localName : "#root", ...parts].join(" > ");
|
|
52
54
|
};
|
|
53
55
|
const native = /^(?:checkbox|radio|range|color|file|hidden)$/;
|
|
54
56
|
const issues = [], counts = { border: 0, icon: 0 };
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
const controls = 'button, input, select, textarea, a[href], [role="switch"], [role="checkbox"], [role="radio"], [role="slider"], [role="tab"]';
|
|
58
|
+
for (const element of [...(scope && root.matches(controls) ? [root] : []), ...root.querySelectorAll(controls)]) {
|
|
59
|
+
// A busy control is disabled while it works, and its spinner still has to be seen.
|
|
60
|
+
const busy = element.getAttribute("aria-busy") === "true";
|
|
61
|
+
if (element.closest("#ads-preview-status") || !busy && element.matches(":disabled") || !busy && element.closest('[aria-disabled="true"]') || element.closest("[inert]")) continue;
|
|
57
62
|
if (!element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) continue;
|
|
58
63
|
const box = element.getBoundingClientRect();
|
|
59
64
|
if (box.width < 1 || box.height < 1) continue;
|
|
@@ -72,7 +77,7 @@ export function nonTextContrast({ nodeLimit }) {
|
|
|
72
77
|
if (best[0] + 1e-9 < 3) report("border", best[0], over(best[1], around), around);
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
|
-
const icon = !text(element) && [...element.querySelectorAll("svg")].find(svg => svg.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }));
|
|
80
|
+
const icon = (busy || !text(element)) && [...element.querySelectorAll("svg")].find(svg => svg.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true }));
|
|
76
81
|
if (icon) {
|
|
77
82
|
const shape = [...icon.querySelectorAll("path, circle, rect, ellipse, line, polyline, polygon, use, text")].find(node => { const paint = getComputedStyle(node); return paint.stroke !== "none" && rgba(paint.stroke)[3] > 0 || paint.fill !== "none" && !paint.fill.startsWith("url(") && rgba(paint.fill)[3] > 0; });
|
|
78
83
|
if (shape) {
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { axeRun } from "./axe-run.mjs";
|
|
2
|
+
import { nonTextContrast } from "./non-text-contrast.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Renders what a scenario shows only after someone acts on it, and measures it with the same checks.
|
|
6
|
+
*
|
|
7
|
+
* Overlays: each control marked aria-haspopup is clicked, up to `overlayLimit` not yet opened, and what
|
|
8
|
+
* opens is audited by axe and non-text contrast, then held to the phone viewport. Fixed layers are
|
|
9
|
+
* exempt from the overflow check of the page, so this is the only place their width is measured. An
|
|
10
|
+
* overlay a scenario renders open is measured the same way. Accessibility trees are read through
|
|
11
|
+
* ARIA, not names: a trigger with no aria-haspopup is not found, and its scenario can render it open.
|
|
12
|
+
*
|
|
13
|
+
* Hover and keyboard focus: up to `stateLimit` controls not yet measured in this theme are hovered with the real mouse and
|
|
14
|
+
* focused as the keyboard would, for contrast only: axe color-contrast when a quick reading looks
|
|
15
|
+
* wrong, non-text contrast in that state, and the focus outline against what is around it. What
|
|
16
|
+
* already fails at rest is not repeated.
|
|
17
|
+
*
|
|
18
|
+
* Results join the render's own, with selectors that say which state they were found in.
|
|
19
|
+
*/
|
|
20
|
+
const overlays = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"], dialog[open], [popover]:popover-open';
|
|
21
|
+
|
|
22
|
+
function markTargets({ selector, attribute, limit, signature, known = [] }) {
|
|
23
|
+
const seen = new Set(known), targets = [], keys = [];
|
|
24
|
+
for (const element of document.querySelector("#root").querySelectorAll(selector)) {
|
|
25
|
+
if (targets.length >= limit) break;
|
|
26
|
+
const box = element.getBoundingClientRect();
|
|
27
|
+
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
|
+
const name = (element.getAttribute("aria-label") ?? element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 60) || element.localName;
|
|
29
|
+
const key = `${signature.map(name => element.getAttribute(name) ?? "").join("|")}|${element.localName}|${attribute === "data-ads-audit-trigger" ? name : getComputedStyle(element.parentElement).backgroundColor}`;
|
|
30
|
+
if (seen.has(key)) continue;
|
|
31
|
+
seen.add(key); keys.push(key);
|
|
32
|
+
element.setAttribute(attribute, String(targets.length));
|
|
33
|
+
targets.push(name);
|
|
34
|
+
}
|
|
35
|
+
return { targets, keys };
|
|
36
|
+
}
|
|
37
|
+
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
|
+
|
|
39
|
+
/** A quick reading of a hovered control's text against its background, so axe, which sets up the whole
|
|
40
|
+
* document on every run, only confirms what looks wrong. Unreadable backgrounds go to axe too. */
|
|
41
|
+
function hoverTextSuspect(selector) {
|
|
42
|
+
const element = document.querySelector(selector);
|
|
43
|
+
const canvas = document.createElement("canvas"); canvas.width = canvas.height = 1;
|
|
44
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
45
|
+
const rgba = value => { context.clearRect(0, 0, 1, 1); context.fillStyle = "#000"; context.fillStyle = value; context.fillRect(0, 0, 1, 1); const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data; return [r, g, b, a / 255]; };
|
|
46
|
+
const over = (top, bottom) => [0, 1, 2].map(index => top[index] * top[3] + bottom[index] * (1 - top[3])).concat(1);
|
|
47
|
+
const lum = ([r, g, b]) => { const channel = value => { value /= 255; return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4; }; return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b); };
|
|
48
|
+
const behind = node => { if (!node) return [255, 255, 255, 1]; const style = getComputedStyle(node); if (style.backgroundImage !== "none") return null; const below = behind(node.parentElement); return below && over(rgba(style.backgroundColor), below); };
|
|
49
|
+
const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
|
|
50
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
51
|
+
if (!node.data.trim() || !node.parentElement.checkVisibility()) continue;
|
|
52
|
+
const back = behind(node.parentElement);
|
|
53
|
+
if (!back) return true;
|
|
54
|
+
const [a, b] = [lum(over(rgba(getComputedStyle(node.parentElement).color), back)), lum(back)];
|
|
55
|
+
if ((Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05) < 4.5) return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Marks the overlay that is open and was not known before; true when there is one. */
|
|
61
|
+
function markOpened({ overlays, known }) {
|
|
62
|
+
for (const element of document.querySelectorAll(overlays)) {
|
|
63
|
+
if (element.closest("#ads-preview-status") || known && element.hasAttribute("data-ads-audit-known") || !element.checkVisibility({ checkOpacity: true, checkVisibilityCSS: true })) continue;
|
|
64
|
+
const box = element.getBoundingClientRect();
|
|
65
|
+
if (box.width < 1 || box.height < 1) continue;
|
|
66
|
+
element.setAttribute("data-ads-audit-overlay", "");
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
function overlayPastViewport() {
|
|
72
|
+
const element = document.querySelector("[data-ads-audit-overlay]");
|
|
73
|
+
if (!element) return null;
|
|
74
|
+
const box = element.getBoundingClientRect(), width = document.documentElement.clientWidth, past = Math.round(Math.max(box.right - width, -box.left));
|
|
75
|
+
return past > 1 ? { overflow: past, html: element.outerHTML.replace(/\s+/g, " ").slice(0, 200) } : null;
|
|
76
|
+
}
|
|
77
|
+
/** The focus outline's contrast with what is around it, when the focus shows as an outline. */
|
|
78
|
+
function focusOutline() {
|
|
79
|
+
const element = document.querySelector("[data-ads-audit-state]");
|
|
80
|
+
element.focus({ focusVisible: true });
|
|
81
|
+
if (document.activeElement !== element || !element.matches(":focus-visible")) return null;
|
|
82
|
+
const style = getComputedStyle(element);
|
|
83
|
+
// A ring drawn with box-shadow is not read, so an outline beside one is not taken for the only indicator.
|
|
84
|
+
if (style.outlineStyle === "none" || parseFloat(style.outlineWidth) <= 0 || style.boxShadow !== "none") return null;
|
|
85
|
+
const canvas = document.createElement("canvas"); canvas.width = canvas.height = 1;
|
|
86
|
+
const context = canvas.getContext("2d", { willReadFrequently: true });
|
|
87
|
+
const rgba = value => { context.clearRect(0, 0, 1, 1); context.fillStyle = "#000"; context.fillStyle = value; context.fillRect(0, 0, 1, 1); const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data; return [r, g, b, a / 255]; };
|
|
88
|
+
const over = (top, bottom) => [0, 1, 2].map(index => top[index] * top[3] + bottom[index] * (1 - top[3])).concat(1);
|
|
89
|
+
const lum = ([r, g, b]) => { const channel = value => { value /= 255; return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4; }; return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b); };
|
|
90
|
+
const around = element => { if (!element) return [255, 255, 255, 1]; const parent = getComputedStyle(element); if (parent.backgroundImage !== "none") return null; const below = around(element.parentElement); return below && over(rgba(parent.backgroundColor), below); };
|
|
91
|
+
const back = around(element.parentElement);
|
|
92
|
+
if (!back) return null;
|
|
93
|
+
const color = over(rgba(style.outlineColor), back), [a, b] = [lum(color), lum(back)], ratio = (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
|
|
94
|
+
const hex = value => `#${value.slice(0, 3).map(part => Math.round(part).toString(16).padStart(2, "0")).join("")}`;
|
|
95
|
+
return ratio + 1e-9 < 3 ? { ratio: Math.round(ratio * 100) / 100, foreground: hex(color), background: hex(back), html: element.outerHTML.replace(/\s+/g, " ").slice(0, 200) } : null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const unmarked = text => text?.replace(/\[?data-ads-audit-[a-z.]+(?:="[^"]*")?\]?/g, "").replace(/\s+>/g, " >").trim();
|
|
99
|
+
const named = (nodes, label) => nodes.map(node => ({ ...node, selector: `${label}: ${unmarked(node.selector)}`.slice(0, 300), ...(node.html ? { html: unmarked(node.html) } : {}) }));
|
|
100
|
+
const labelled = (groups, label) => groups.map(group => ({ ...group, nodes: named(group.nodes, label) }));
|
|
101
|
+
|
|
102
|
+
/** Runs both, adding what it finds to `result`. One failing control ends only its own part. */
|
|
103
|
+
export async function auditRenderStates({ page, frame, result, request, phoneWidth, measuredControls }) {
|
|
104
|
+
const { nodeLimit, tags, overlayLimit, stateLimit } = request, desktop = page.viewportSize();
|
|
105
|
+
const isClosed = () => frame.waitForFunction(() => { const element = document.querySelector("[data-ads-audit-overlay]"); return !element || !element.checkVisibility(); }, undefined, { timeout: 1000 }).then(() => true, () => false);
|
|
106
|
+
const unmark = () => frame.evaluate(() => { for (const element of document.querySelectorAll("[data-ads-audit-overlay]")) element.removeAttribute("data-ads-audit-overlay"); });
|
|
107
|
+
const measureOverlay = async (label, reopen) => {
|
|
108
|
+
await frame.evaluate(settle);
|
|
109
|
+
const found = await frame.evaluate(axeRun, { tags, nodeLimit, include: "[data-ads-audit-overlay]" });
|
|
110
|
+
result.violations.push(...labelled(found.violations, label)); result.incomplete.push(...labelled(found.incomplete, label));
|
|
111
|
+
const nonText = await frame.evaluate(nonTextContrast, { nodeLimit, scope: "[data-ads-audit-overlay]" });
|
|
112
|
+
result.nonText.issues.push(...named(nonText.issues, label));
|
|
113
|
+
for (const [kind, count] of Object.entries(nonText.counts)) result.nonText.counts[kind] = (result.nonText.counts[kind] ?? 0) + count;
|
|
114
|
+
await page.setViewportSize({ width: phoneWidth, height: desktop.height });
|
|
115
|
+
await frame.evaluate(settle);
|
|
116
|
+
let past = await frame.evaluate(overlayPastViewport);
|
|
117
|
+
// A menu is placed when it opens, so one opened on the desktop may be stale: open it here to be sure.
|
|
118
|
+
if (past && reopen) {
|
|
119
|
+
await page.keyboard.press("Escape");
|
|
120
|
+
if (await isClosed()) { await unmark(); past = await reopen() ? await frame.evaluate(settle).then(() => frame.evaluate(overlayPastViewport)) : null; }
|
|
121
|
+
}
|
|
122
|
+
if (past) result.layout.push({ width: phoneWidth, issues: [{ kind: "viewport", selector: label, ...past }], counts: { viewport: 1 } });
|
|
123
|
+
await page.setViewportSize(desktop);
|
|
124
|
+
await frame.evaluate(settle);
|
|
125
|
+
result.overlays = (result.overlays ?? 0) + 1;
|
|
126
|
+
};
|
|
127
|
+
// Already open: nothing to click, and nothing to close.
|
|
128
|
+
if (await frame.evaluate(markOpened, { overlays, known: false })) {
|
|
129
|
+
await measureOverlay("open overlay");
|
|
130
|
+
await unmark();
|
|
131
|
+
}
|
|
132
|
+
// A shell repeated across scenarios opens the same menu in each: one audit measures it once per theme and brand.
|
|
133
|
+
const { targets: triggers, keys: triggerKeys } = await frame.evaluate(markTargets, { selector: '[aria-haspopup]:not([aria-haspopup="false"])', attribute: "data-ads-audit-trigger", limit: overlayLimit, signature: ["aria-haspopup", "class"], known: [...measuredControls] });
|
|
134
|
+
for (const key of triggerKeys) measuredControls.add(key);
|
|
135
|
+
for (const [index, name] of triggers.entries()) {
|
|
136
|
+
try {
|
|
137
|
+
await frame.evaluate(overlays => { for (const element of document.querySelectorAll(overlays)) element.setAttribute("data-ads-audit-known", ""); }, overlays);
|
|
138
|
+
const open = async () => {
|
|
139
|
+
await frame.locator(`[data-ads-audit-trigger="${index}"]`).click({ timeout: 2000 });
|
|
140
|
+
return frame.waitForFunction(markOpened, { overlays, known: true }, { timeout: 1500 }).then(() => true, () => false);
|
|
141
|
+
};
|
|
142
|
+
if (!await open()) continue;
|
|
143
|
+
await measureOverlay(`open overlay "${name}"`, open);
|
|
144
|
+
await page.keyboard.press("Escape");
|
|
145
|
+
const closed = await isClosed();
|
|
146
|
+
await unmark();
|
|
147
|
+
// One that stays open covers the page, so the next trigger cannot be reached.
|
|
148
|
+
if (!closed) break;
|
|
149
|
+
} catch { /* A trigger that cannot be used says nothing about what it opens. */ }
|
|
150
|
+
}
|
|
151
|
+
// What already fails at rest: axe names elements the same way each run, and non-text findings are the same colors.
|
|
152
|
+
const pair = issue => JSON.stringify([issue.kind, issue.foreground, issue.background]);
|
|
153
|
+
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
|
+
// The same control on the same surface measures the same everywhere, so one audit measures it once per theme and brand.
|
|
155
|
+
const { targets, keys } = await frame.evaluate(markTargets, { 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", limit: stateLimit, signature: ["class", "role", "type"], known: [...measuredControls] });
|
|
156
|
+
for (const key of keys) measuredControls.add(key);
|
|
157
|
+
for (const [index] of targets.entries()) {
|
|
158
|
+
const target = `[data-ads-audit-control="${index}"]`;
|
|
159
|
+
try {
|
|
160
|
+
await frame.locator(target).hover({ timeout: 1000, force: true });
|
|
161
|
+
await frame.evaluate(target => document.querySelector(target).setAttribute("data-ads-audit-state", ""), target);
|
|
162
|
+
await frame.evaluate(settle);
|
|
163
|
+
if (await frame.evaluate(hoverTextSuspect, target)) {
|
|
164
|
+
const found = await frame.evaluate(axeRun, { tags, nodeLimit, include: target, rules: ["color-contrast"] });
|
|
165
|
+
const fresh = group => ({ ...group, nodes: group.nodes.filter(node => !rest.has(node.selector)) });
|
|
166
|
+
result.violations.push(...labelled(found.violations.map(fresh).filter(group => group.nodes.length), "hover"));
|
|
167
|
+
}
|
|
168
|
+
const nonText = await frame.evaluate(nonTextContrast, { nodeLimit, scope: target });
|
|
169
|
+
const issues = nonText.issues.filter(issue => !rest.has(pair(issue)));
|
|
170
|
+
result.nonText.issues.push(...named(issues, "hover"));
|
|
171
|
+
for (const issue of issues) result.nonText.counts[issue.kind] = (result.nonText.counts[issue.kind] ?? 0) + 1;
|
|
172
|
+
const outline = await frame.evaluate(focusOutline);
|
|
173
|
+
if (outline) {
|
|
174
|
+
result.nonText.issues.push({ kind: "focus", selector: `focus: ${await frame.locator(target).evaluate(element => element.localName)}`, ...outline });
|
|
175
|
+
result.nonText.counts.focus = (result.nonText.counts.focus ?? 0) + 1;
|
|
176
|
+
}
|
|
177
|
+
await frame.evaluate(target => { const element = document.querySelector(target); element.removeAttribute("data-ads-audit-state"); element.blur(); }, target);
|
|
178
|
+
} catch { /* A control that cannot be reached has no state to measure. */ }
|
|
179
|
+
}
|
|
180
|
+
await page.mouse.move(desktop.width - 1, desktop.height - 1);
|
|
181
|
+
result.controls = (result.controls ?? 0) + targets.length;
|
|
182
|
+
}
|
|
@@ -2,9 +2,12 @@ import { readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { openPreviewScenario } from "../verification/browser.mjs";
|
|
5
|
+
import { axeRun } from "./axe-run.mjs";
|
|
6
|
+
import { firstRender } from "./first-render.mjs";
|
|
5
7
|
import { nonTextContrast } from "./non-text-contrast.mjs";
|
|
6
8
|
import { layoutOverflow } from "./layout-overflow.mjs";
|
|
7
9
|
import { layoutShift } from "./layout-shift.mjs";
|
|
10
|
+
import { auditRenderStates } from "./render-states.mjs";
|
|
8
11
|
|
|
9
12
|
// Runs only as an owned child, using the receiving project's browser dependency.
|
|
10
13
|
const request = JSON.parse(readFileSync(process.argv[2], "utf8"));
|
|
@@ -25,6 +28,7 @@ try {
|
|
|
25
28
|
const apps = request.apps.filter(app => app.theme === theme);
|
|
26
29
|
// The audit injects its own script; bypassCSP keeps project CSP from blocking it.
|
|
27
30
|
const context = await browser.newContext({ viewport: request.viewport, deviceScaleFactor: 1, colorScheme: apps[0].scheme, bypassCSP: true, reducedMotion: "reduce" });
|
|
31
|
+
const measuredControls = new Set();
|
|
28
32
|
try {
|
|
29
33
|
// A bounded number of pages render at once; results keep request order.
|
|
30
34
|
const results = [];
|
|
@@ -46,21 +50,13 @@ try {
|
|
|
46
50
|
const frame = await openPreviewScenario(page, app.url, app.scenario, { timeout });
|
|
47
51
|
await frame.waitForFunction(theme => document.documentElement.dataset.theme === theme, app.theme, { timeout });
|
|
48
52
|
if (app.brand) await frame.waitForFunction(brand => document.documentElement.dataset.brand === brand, app.brand, { timeout });
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
53
|
-
});
|
|
53
|
+
// Nothing is hovered at rest: the mouse starts over whatever sits at the page's corner.
|
|
54
|
+
await page.mouse.move(request.viewport.width - 1, request.viewport.height - 1);
|
|
55
|
+
await frame.evaluate(firstRender);
|
|
54
56
|
// Before the audit touches the page: resizing below would shift it.
|
|
55
57
|
partial.layoutShift = await frame.evaluate(layoutShift, { nodeLimit: request.nodeLimit });
|
|
56
58
|
if (!await frame.evaluate(() => !!window.axe)) await frame.addScriptTag({ content: axe });
|
|
57
|
-
const result = await frame.evaluate(
|
|
58
|
-
// Scenario content only: the preview status aside and document-level chrome are ADS-owned.
|
|
59
|
-
const outcome = await window.axe.run({ include: [["#root"]], exclude: [["#ads-preview-status"]] }, { runOnly: { type: "tag", values: tags }, resultTypes: ["violations"], elementRef: false, ancestry: false });
|
|
60
|
-
const clip = (text, size) => typeof text === "string" ? text.replace(/\s+/g, " ").trim().slice(0, size) : "";
|
|
61
|
-
return { violations: outcome.violations.map(violation => ({ id: violation.id, impact: violation.impact, tags: violation.tags, help: clip(violation.help, 300), helpUrl: clip(violation.helpUrl, 300), nodeCount: violation.nodes.length,
|
|
62
|
-
nodes: violation.nodes.slice(0, nodeLimit).map(node => ({ selector: clip(node.target.flat().join(" "), 300), html: clip(node.html, 200), summary: clip(node.failureSummary, 500) })) })), incomplete: outcome.incomplete.length };
|
|
63
|
-
}, { tags: request.tags, nodeLimit: request.nodeLimit });
|
|
59
|
+
const result = await frame.evaluate(axeRun, { tags: request.tags, nodeLimit: request.nodeLimit });
|
|
64
60
|
result.layoutShift = partial.layoutShift;
|
|
65
61
|
Object.assign(partial, result);
|
|
66
62
|
result.nonText = await frame.evaluate(nonTextContrast, { nodeLimit: request.nodeLimit });
|
|
@@ -70,6 +66,21 @@ try {
|
|
|
70
66
|
await page.setViewportSize({ width, height: request.viewport.height });
|
|
71
67
|
result.layout.push({ width, ...await frame.evaluate(layoutOverflow, { nodeLimit: request.nodeLimit, width }) });
|
|
72
68
|
}
|
|
69
|
+
await auditRenderStates({ page, frame, result, request, phoneWidth: request.overflowWidths[0], measuredControls });
|
|
70
|
+
// Last: it narrows #root for good, at the widest viewport, as a pane in a window would be.
|
|
71
|
+
// A scenario with the main landmark is a whole page, which no pane hosts.
|
|
72
|
+
if (app.container && !await frame.evaluate(() => !!document.querySelector('main, [role="main"]'))) {
|
|
73
|
+
await frame.addStyleTag({ content: `#root { inline-size: ${app.container}px; }` });
|
|
74
|
+
const options = { nodeLimit: request.nodeLimit, container: app.container, smallPart: request.smallPart };
|
|
75
|
+
let narrowed = await frame.evaluate(layoutOverflow, { ...options, width: request.overflowWidths.at(-1) });
|
|
76
|
+
// What clears at the phone viewport folds on a media query, as full-width site chrome does.
|
|
77
|
+
if (narrowed.issues.length) {
|
|
78
|
+
await page.setViewportSize({ width: request.overflowWidths[0], height: request.viewport.height });
|
|
79
|
+
const folded = await frame.evaluate(layoutOverflow, { ...options, width: request.overflowWidths[0] });
|
|
80
|
+
if (!folded.issues.length) narrowed = folded;
|
|
81
|
+
}
|
|
82
|
+
result.layout.push({ width: app.container, container: true, ...narrowed });
|
|
83
|
+
}
|
|
73
84
|
if (await frame.locator("html").getAttribute("data-ads-preview-state") !== "ready") throw new Error(`Scenario ${app.scenario} stopped being ready during the audit.`);
|
|
74
85
|
return { scenario: app.scenario, theme: app.theme, ...(app.brand ? { brand: app.brand } : {}), ...result };
|
|
75
86
|
} finally { await page.close().catch(() => {}); }
|