@mizchi/vlmkit-core 0.9.1 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/apng.d.mts +42 -0
  2. package/dist/apng.mjs +199 -0
  3. package/dist/auth-state.d.mts +14 -3
  4. package/dist/auth-state.mjs +30 -6
  5. package/dist/bitmap-font.d.mts +48 -0
  6. package/dist/bitmap-font.mjs +945 -0
  7. package/dist/browser-launch.d.mts +65 -0
  8. package/dist/browser-launch.mjs +194 -0
  9. package/dist/cli-error.d.mts +73 -1
  10. package/dist/cli-error.mjs +164 -32
  11. package/dist/element-compare.mjs +8 -11
  12. package/dist/filmstrip.d.mts +121 -0
  13. package/dist/filmstrip.mjs +181 -0
  14. package/dist/gate-config.d.mts +107 -22
  15. package/dist/gate-config.mjs +138 -9
  16. package/dist/heatmap.d.mts +48 -4
  17. package/dist/heatmap.mjs +157 -12
  18. package/dist/index.d.mts +6 -4
  19. package/dist/index.mjs +4 -2
  20. package/dist/mask.d.mts +66 -2
  21. package/dist/mask.mjs +91 -4
  22. package/dist/page-load.d.mts +83 -0
  23. package/dist/page-load.mjs +116 -0
  24. package/dist/page-open.d.mts +123 -2
  25. package/dist/page-open.mjs +176 -6
  26. package/dist/plugin/args.d.mts +86 -0
  27. package/dist/plugin/args.mjs +162 -0
  28. package/dist/plugin/browser.d.mts +6 -0
  29. package/dist/plugin/browser.mjs +6 -0
  30. package/dist/plugin/cli-entry.d.mts +11 -0
  31. package/dist/plugin/cli-entry.mjs +69 -0
  32. package/dist/plugin/contract.d.mts +270 -0
  33. package/dist/plugin/contract.mjs +51 -0
  34. package/dist/plugin/index.d.mts +82 -0
  35. package/dist/plugin/index.mjs +81 -0
  36. package/dist/plugin/load.d.mts +36 -0
  37. package/dist/plugin/load.mjs +98 -0
  38. package/dist/plugin/registry.d.mts +60 -0
  39. package/dist/plugin/registry.mjs +160 -0
  40. package/dist/plugin/rule-tier.d.mts +65 -0
  41. package/dist/plugin/rule-tier.mjs +77 -0
  42. package/dist/plugin/rules.d.mts +112 -0
  43. package/dist/plugin/rules.mjs +188 -0
  44. package/dist/plugin/runner.d.mts +198 -0
  45. package/dist/plugin/runner.mjs +440 -0
  46. package/dist/png-utils.d.mts +31 -1
  47. package/dist/png-utils.mjs +24 -1
  48. package/dist/rect-overlap.d.mts +41 -0
  49. package/dist/rect-overlap.mjs +28 -0
  50. package/dist/run-ledger.d.mts +56 -2
  51. package/dist/run-ledger.mjs +102 -11
  52. package/dist/types.d.mts +60 -1
  53. package/dist/version.d.mts +20 -0
  54. package/dist/version.mjs +20 -0
  55. package/dist/webp.d.mts +31 -0
  56. package/dist/webp.mjs +105 -0
  57. package/package.json +17 -3
package/dist/mask.d.mts CHANGED
@@ -1,11 +1,75 @@
1
1
  import { Page } from "playwright";
2
2
 
3
3
  //#region src/mask.d.ts
4
+ /** What `applyMask` could and could not do, for the caller to report. */
5
+ interface MaskResult {
6
+ /** Selectors that matched at least one element and are now hidden. */
7
+ applied: string[];
8
+ /**
9
+ * Selectors that are not valid CSS. They mask nothing, and before this they also
10
+ * took their neighbours down with them — see `applyMask`.
11
+ */
12
+ invalid: string[];
13
+ /**
14
+ * Valid, but matched no element on this page. Almost always a typo, and the mask is a
15
+ * silent no-op: the region the caller meant to exclude stays in the diff. Not fatal,
16
+ * because a mask may legitimately target a region that only exists on some pages or
17
+ * viewports, so this is for the caller to report rather than to fail on.
18
+ */
19
+ unmatched: string[];
20
+ }
4
21
  /**
5
22
  * Inject mask styles into the page.
6
23
  * Sets visibility: hidden on target selectors including descendants.
24
+ *
25
+ * **One style tag per selector, not one for all of them.** The joined form was
26
+ * `sel { visibility: hidden !important; }` per line in a single `addStyleTag`, and CSS
27
+ * error recovery on a malformed selector consumes until it can resynchronize — which
28
+ * takes the *following* rules with it. Measured with `[".a", ".b:not(", ".c"]`: the
29
+ * browser kept exactly one rule, `.a`, and `.b` AND `.c` were both left visible. So a
30
+ * single stray paren — the kind a shell quote produces — silently disabled every mask
31
+ * after it while the CLI printed all three as applied.
32
+ *
33
+ * The harm runs the other way from most of this file's bugs: an unmasked dynamic region
34
+ * makes the diff fail, which is loud. It becomes quiet when the operator responds by
35
+ * raising the threshold to compensate, and that hides real regressions.
36
+ *
37
+ * Selectors are validated in the page rather than parsed here: `querySelectorAll` throws
38
+ * on exactly the thing we need to detect, and it is the same engine that will apply the
39
+ * CSS.
40
+ */
41
+ declare function applyMask(page: Page, selectors: string[]): Promise<MaskResult>;
42
+ /**
43
+ * Accumulates mask outcomes across a run so the report is per-run, not per-page.
44
+ *
45
+ * Every caller applies masks inside a loop over pages × viewports, so reporting each
46
+ * result where it happens would print the same problem dozens of times. The two states
47
+ * also need different treatment:
48
+ *
49
+ * - invalid CSS is page-independent, so it is said once and is a user error to fix;
50
+ * - "matched nothing" is page-dependent — a mask may legitimately target a region that
51
+ * exists on one route only — so it is worth reporting only for a selector that
52
+ * matched nothing *anywhere*, which is not knowable until the run ends.
53
+ */
54
+ declare class MaskTally {
55
+ private readonly invalid;
56
+ private readonly everMatched;
57
+ private readonly everTried;
58
+ add(result: MaskResult): void;
59
+ /** Invalid selectors not yet reported, so a caller can say them once. */
60
+ takeNewInvalid(): string[];
61
+ private readonly reportedInvalid;
62
+ /** Selectors that were valid everywhere and matched nothing anywhere. */
63
+ neverMatched(): string[];
64
+ }
65
+ /**
66
+ * One line naming what a mask could not do, or `null` when every selector applied.
67
+ *
68
+ * Shared so the call sites word it the same way; each of them already prints a
69
+ * `Mask: <selectors>` line, which was a claim about state that a malformed selector made
70
+ * false.
7
71
  */
8
- declare function applyMask(page: Page, selectors: string[]): Promise<void>;
72
+ declare function formatMaskProblems(invalid: string[], neverMatched: string[]): string | null;
9
73
  /**
10
74
  * Parse selector array from CLI --mask flags.
11
75
  * Supports comma-separated or multiple --mask flags.
@@ -15,4 +79,4 @@ declare function applyMask(page: Page, selectors: string[]): Promise<void>;
15
79
  */
16
80
  declare function parseMaskSelectors(args: string[]): string[];
17
81
  //#endregion
18
- export { applyMask, parseMaskSelectors };
82
+ export { MaskResult, MaskTally, applyMask, formatMaskProblems, parseMaskSelectors };
package/dist/mask.mjs CHANGED
@@ -2,11 +2,98 @@
2
2
  /**
3
3
  * Inject mask styles into the page.
4
4
  * Sets visibility: hidden on target selectors including descendants.
5
+ *
6
+ * **One style tag per selector, not one for all of them.** The joined form was
7
+ * `sel { visibility: hidden !important; }` per line in a single `addStyleTag`, and CSS
8
+ * error recovery on a malformed selector consumes until it can resynchronize — which
9
+ * takes the *following* rules with it. Measured with `[".a", ".b:not(", ".c"]`: the
10
+ * browser kept exactly one rule, `.a`, and `.b` AND `.c` were both left visible. So a
11
+ * single stray paren — the kind a shell quote produces — silently disabled every mask
12
+ * after it while the CLI printed all three as applied.
13
+ *
14
+ * The harm runs the other way from most of this file's bugs: an unmasked dynamic region
15
+ * makes the diff fail, which is loud. It becomes quiet when the operator responds by
16
+ * raising the threshold to compensate, and that hides real regressions.
17
+ *
18
+ * Selectors are validated in the page rather than parsed here: `querySelectorAll` throws
19
+ * on exactly the thing we need to detect, and it is the same engine that will apply the
20
+ * CSS.
5
21
  */
6
22
  async function applyMask(page, selectors) {
7
- if (selectors.length === 0) return;
8
- const css = selectors.map((s) => `${s} { visibility: hidden !important; }`).join("\n");
9
- await page.addStyleTag({ content: css });
23
+ const result = {
24
+ applied: [],
25
+ invalid: [],
26
+ unmatched: []
27
+ };
28
+ if (selectors.length === 0) return result;
29
+ const counts = await page.evaluate((list) => list.map((s) => {
30
+ try {
31
+ return document.querySelectorAll(s).length;
32
+ } catch {
33
+ return -1;
34
+ }
35
+ }), selectors);
36
+ for (let i = 0; i < selectors.length; i++) {
37
+ const selector = selectors[i];
38
+ const count = counts[i] ?? -1;
39
+ if (count < 0) {
40
+ result.invalid.push(selector);
41
+ continue;
42
+ }
43
+ if (count === 0) result.unmatched.push(selector);
44
+ else result.applied.push(selector);
45
+ await page.addStyleTag({ content: `${selector} { visibility: hidden !important; }` });
46
+ }
47
+ return result;
48
+ }
49
+ /**
50
+ * Accumulates mask outcomes across a run so the report is per-run, not per-page.
51
+ *
52
+ * Every caller applies masks inside a loop over pages × viewports, so reporting each
53
+ * result where it happens would print the same problem dozens of times. The two states
54
+ * also need different treatment:
55
+ *
56
+ * - invalid CSS is page-independent, so it is said once and is a user error to fix;
57
+ * - "matched nothing" is page-dependent — a mask may legitimately target a region that
58
+ * exists on one route only — so it is worth reporting only for a selector that
59
+ * matched nothing *anywhere*, which is not knowable until the run ends.
60
+ */
61
+ var MaskTally = class {
62
+ invalid = /* @__PURE__ */ new Set();
63
+ everMatched = /* @__PURE__ */ new Set();
64
+ everTried = /* @__PURE__ */ new Set();
65
+ add(result) {
66
+ for (const s of result.invalid) this.invalid.add(s);
67
+ for (const s of result.applied) {
68
+ this.everMatched.add(s);
69
+ this.everTried.add(s);
70
+ }
71
+ for (const s of result.unmatched) this.everTried.add(s);
72
+ }
73
+ /** Invalid selectors not yet reported, so a caller can say them once. */
74
+ takeNewInvalid() {
75
+ const fresh = [...this.invalid].filter((s) => !this.reportedInvalid.has(s));
76
+ for (const s of fresh) this.reportedInvalid.add(s);
77
+ return fresh;
78
+ }
79
+ reportedInvalid = /* @__PURE__ */ new Set();
80
+ /** Selectors that were valid everywhere and matched nothing anywhere. */
81
+ neverMatched() {
82
+ return [...this.everTried].filter((s) => !this.everMatched.has(s));
83
+ }
84
+ };
85
+ /**
86
+ * One line naming what a mask could not do, or `null` when every selector applied.
87
+ *
88
+ * Shared so the call sites word it the same way; each of them already prints a
89
+ * `Mask: <selectors>` line, which was a claim about state that a malformed selector made
90
+ * false.
91
+ */
92
+ function formatMaskProblems(invalid, neverMatched) {
93
+ const parts = [];
94
+ if (invalid.length > 0) parts.push(`invalid CSS, masking nothing: ${invalid.join(", ")}`);
95
+ if (neverMatched.length > 0) parts.push(`matched no element on any page: ${neverMatched.join(", ")}`);
96
+ return parts.length > 0 ? parts.join("; ") : null;
10
97
  }
11
98
  /**
12
99
  * Parse selector array from CLI --mask flags.
@@ -24,4 +111,4 @@ function parseMaskSelectors(args) {
24
111
  return selectors;
25
112
  }
26
113
  //#endregion
27
- export { applyMask, parseMaskSelectors };
114
+ export { MaskTally, applyMask, formatMaskProblems, parseMaskSelectors };
@@ -0,0 +1,83 @@
1
+ import { GateInput } from "./plugin/contract.mjs";
2
+ import { applyHar } from "./page-open.mjs";
3
+ import { Page } from "playwright";
4
+
5
+ //#region src/page-load.d.ts
6
+ /** The navigation milestones a gate exposes. Playwright's `commit` is not one of
7
+ * them: no gate can read a document that has not parsed. */
8
+ declare const PAGE_LOAD_WAIT_UNTIL: readonly ["domcontentloaded", "load", "networkidle"];
9
+ type PageLoadWaitUntil = (typeof PAGE_LOAD_WAIT_UNTIL)[number];
10
+ /** Playwright's own default, restated so callers can name it. */
11
+ declare const DEFAULT_PAGE_LOAD_TIMEOUT_MS = 30000;
12
+ /** The default milestone every gate has always used. */
13
+ declare const DEFAULT_PAGE_LOAD_WAIT_UNTIL: PageLoadWaitUntil;
14
+ /**
15
+ * What a gate carries from argv down to its `page.goto`.
16
+ *
17
+ * Structurally a subset of `OpenPageOptions`, so a measurement module that
18
+ * loads through `openSource` can forward this object as-is.
19
+ */
20
+ interface PageLoadOptions {
21
+ /** Navigation milestone. Defaults to `networkidle`. */
22
+ waitUntil?: PageLoadWaitUntil;
23
+ /** Navigation timeout in milliseconds. Defaults to 30000. */
24
+ timeout?: number;
25
+ /** Replay network responses from a Playwright HAR. See `applyHar`. */
26
+ har?: string;
27
+ }
28
+ /**
29
+ * `inputs` fragment. Spread at the END of a gate's `inputs` array so the
30
+ * gate-specific flags stay first in `--help`.
31
+ */
32
+ declare const PAGE_LOAD_INPUTS: readonly GateInput[];
33
+ /** The flag spellings, for `readPositionals` value-flag lists. */
34
+ declare const PAGE_LOAD_VALUE_FLAGS: readonly string[];
35
+ /**
36
+ * Read the three flags off argv. Absent flags produce absent keys, so spreading
37
+ * the result never overwrites a gate's own default with `undefined`.
38
+ */
39
+ declare function parsePageLoad(argv: readonly string[]): PageLoadOptions;
40
+ /**
41
+ * Narrow a wider options object down to just these three keys.
42
+ *
43
+ * For measurement modules that load through `openSource`: spreading the whole
44
+ * gate options object into it would also hand over `outputDir`, `reportPath` and
45
+ * friends, and `OpenPageOptions` is not an index type, so the extra keys would
46
+ * pass silently today and collide the day one of those names is reused.
47
+ */
48
+ declare function pickPageLoad(options: PageLoadOptions): PageLoadOptions;
49
+ /**
50
+ * The `goto` / `setContent` option object, with the call site's own historical
51
+ * default preserved.
52
+ *
53
+ * `defaultWaitUntil` exists because the gates did not all start from
54
+ * `networkidle`: `check interactions`, `scan handlers` and `verify flow` navigate
55
+ * at `load` and then call `settlePage`, which is why those three already survive
56
+ * a page that never reaches network idle. Passing a single global default here
57
+ * would have silently *broken* them while fixing the others.
58
+ */
59
+ declare function navigationOptions(options?: PageLoadOptions, defaultWaitUntil?: PageLoadWaitUntil): {
60
+ waitUntil: PageLoadWaitUntil;
61
+ timeout: number;
62
+ };
63
+ /**
64
+ * Navigate honouring all three options — the call site that replaces a
65
+ * hardcoded `page.goto(url, { waitUntil: "networkidle", timeout: 30000 })`.
66
+ *
67
+ * The settle is conditional on purpose. With no flags passed this is
68
+ * byte-for-byte the old behaviour, so adopting the helper changes no timings.
69
+ * When the caller *relaxes* the milestone below the call site's own default it
70
+ * settles as well (`settlePage`: bounded 5s network-idle wait, webfonts, one
71
+ * quiet frame), because otherwise `--wait-until domcontentloaded` would hand a
72
+ * gate the pre-render DOM and the gate would report the placeholder as a defect
73
+ * — the failure mode `settle-consistency.test.ts` exists to pin. For the #112
74
+ * SPA that reproduces the hand-rolled harness's behaviour: parse, wait as long
75
+ * as is bounded, then measure the rendered page instead of timing out.
76
+ *
77
+ * Call sites that settle unconditionally already (the `load` three) should call
78
+ * `navigationOptions(options, "load")` + their own `settlePage` instead, so the
79
+ * settle is not done twice.
80
+ */
81
+ declare function navigatePage(page: Page, url: string, options?: PageLoadOptions): Promise<void>;
82
+ //#endregion
83
+ export { DEFAULT_PAGE_LOAD_TIMEOUT_MS, DEFAULT_PAGE_LOAD_WAIT_UNTIL, PAGE_LOAD_INPUTS, PAGE_LOAD_VALUE_FLAGS, PAGE_LOAD_WAIT_UNTIL, PageLoadOptions, PageLoadWaitUntil, applyHar, navigatePage, navigationOptions, parsePageLoad, pickPageLoad };
@@ -0,0 +1,116 @@
1
+ import { readChoice, readFlag, readInt } from "./arg-reader.mjs";
2
+ import { applyHar, settlePage } from "./page-open.mjs";
3
+ //#region src/page-load.ts
4
+ /** The navigation milestones a gate exposes. Playwright's `commit` is not one of
5
+ * them: no gate can read a document that has not parsed. */
6
+ const PAGE_LOAD_WAIT_UNTIL = [
7
+ "domcontentloaded",
8
+ "load",
9
+ "networkidle"
10
+ ];
11
+ /** Playwright's own default, restated so callers can name it. */
12
+ const DEFAULT_PAGE_LOAD_TIMEOUT_MS = 3e4;
13
+ /** The default milestone every gate has always used. */
14
+ const DEFAULT_PAGE_LOAD_WAIT_UNTIL = "networkidle";
15
+ /**
16
+ * `inputs` fragment. Spread at the END of a gate's `inputs` array so the
17
+ * gate-specific flags stay first in `--help`.
18
+ */
19
+ const PAGE_LOAD_INPUTS = [
20
+ {
21
+ name: "timeout",
22
+ placeholder: "ms",
23
+ kind: "number",
24
+ description: "Page navigation timeout",
25
+ defaultDescription: String(DEFAULT_PAGE_LOAD_TIMEOUT_MS)
26
+ },
27
+ {
28
+ name: "wait-until",
29
+ kind: "string",
30
+ description: "Navigation wait state (domcontentloaded for an SPA that never reaches network idle)",
31
+ choices: PAGE_LOAD_WAIT_UNTIL,
32
+ defaultDescription: DEFAULT_PAGE_LOAD_WAIT_UNTIL
33
+ },
34
+ {
35
+ name: "har",
36
+ placeholder: "file",
37
+ kind: "path",
38
+ description: "Replay network responses from a Playwright HAR (requests absent from it are aborted)"
39
+ }
40
+ ];
41
+ /** The flag spellings, for `readPositionals` value-flag lists. */
42
+ const PAGE_LOAD_VALUE_FLAGS = [
43
+ "--timeout",
44
+ "--wait-until",
45
+ "--har"
46
+ ];
47
+ /**
48
+ * Read the three flags off argv. Absent flags produce absent keys, so spreading
49
+ * the result never overwrites a gate's own default with `undefined`.
50
+ */
51
+ function parsePageLoad(argv) {
52
+ const timeout = readInt(argv, "timeout", { min: 1 });
53
+ const waitUntil = readChoice(argv, "wait-until", PAGE_LOAD_WAIT_UNTIL);
54
+ const har = readFlag(argv, "har");
55
+ return {
56
+ ...timeout !== void 0 ? { timeout } : {},
57
+ ...waitUntil ? { waitUntil } : {},
58
+ ...har ? { har } : {}
59
+ };
60
+ }
61
+ /**
62
+ * Narrow a wider options object down to just these three keys.
63
+ *
64
+ * For measurement modules that load through `openSource`: spreading the whole
65
+ * gate options object into it would also hand over `outputDir`, `reportPath` and
66
+ * friends, and `OpenPageOptions` is not an index type, so the extra keys would
67
+ * pass silently today and collide the day one of those names is reused.
68
+ */
69
+ function pickPageLoad(options) {
70
+ return {
71
+ ...options.waitUntil ? { waitUntil: options.waitUntil } : {},
72
+ ...options.timeout !== void 0 ? { timeout: options.timeout } : {},
73
+ ...options.har ? { har: options.har } : {}
74
+ };
75
+ }
76
+ /**
77
+ * The `goto` / `setContent` option object, with the call site's own historical
78
+ * default preserved.
79
+ *
80
+ * `defaultWaitUntil` exists because the gates did not all start from
81
+ * `networkidle`: `check interactions`, `scan handlers` and `verify flow` navigate
82
+ * at `load` and then call `settlePage`, which is why those three already survive
83
+ * a page that never reaches network idle. Passing a single global default here
84
+ * would have silently *broken* them while fixing the others.
85
+ */
86
+ function navigationOptions(options = {}, defaultWaitUntil = DEFAULT_PAGE_LOAD_WAIT_UNTIL) {
87
+ return {
88
+ waitUntil: options.waitUntil ?? defaultWaitUntil,
89
+ timeout: options.timeout ?? 3e4
90
+ };
91
+ }
92
+ /**
93
+ * Navigate honouring all three options — the call site that replaces a
94
+ * hardcoded `page.goto(url, { waitUntil: "networkidle", timeout: 30000 })`.
95
+ *
96
+ * The settle is conditional on purpose. With no flags passed this is
97
+ * byte-for-byte the old behaviour, so adopting the helper changes no timings.
98
+ * When the caller *relaxes* the milestone below the call site's own default it
99
+ * settles as well (`settlePage`: bounded 5s network-idle wait, webfonts, one
100
+ * quiet frame), because otherwise `--wait-until domcontentloaded` would hand a
101
+ * gate the pre-render DOM and the gate would report the placeholder as a defect
102
+ * — the failure mode `settle-consistency.test.ts` exists to pin. For the #112
103
+ * SPA that reproduces the hand-rolled harness's behaviour: parse, wait as long
104
+ * as is bounded, then measure the rendered page instead of timing out.
105
+ *
106
+ * Call sites that settle unconditionally already (the `load` three) should call
107
+ * `navigationOptions(options, "load")` + their own `settlePage` instead, so the
108
+ * settle is not done twice.
109
+ */
110
+ async function navigatePage(page, url, options = {}) {
111
+ await applyHar(page, options.har);
112
+ await page.goto(url, navigationOptions(options));
113
+ if (options.waitUntil && options.waitUntil !== "networkidle") await settlePage(page, 0);
114
+ }
115
+ //#endregion
116
+ export { DEFAULT_PAGE_LOAD_TIMEOUT_MS, DEFAULT_PAGE_LOAD_WAIT_UNTIL, PAGE_LOAD_INPUTS, PAGE_LOAD_VALUE_FLAGS, PAGE_LOAD_WAIT_UNTIL, applyHar, navigatePage, navigationOptions, parsePageLoad, pickPageLoad };
@@ -1,6 +1,33 @@
1
1
  import { Browser, Page, ViewportSize } from "playwright";
2
2
 
3
3
  //#region src/page-open.d.ts
4
+ /**
5
+ * Is this source already a URL, or is it a path that has to become one?
6
+ *
7
+ * `file:` belongs here and did not use to. This function said `https?` only, so a
8
+ * `file://` source fell into the path branch and `resolve()` mangled it exactly the way
9
+ * the comment on `resolveSource` warns about for `http`:
10
+ *
11
+ * vlmkit check a11y contrast "file:///repo/fixtures/page.html"
12
+ * error: file not found: /repo/file:/repo/fixtures/page.html
13
+ *
14
+ * Measured — the same fixture passed as a plain path inspected 31 elements and found 2
15
+ * contrast failures. Everything reaching a page through `openSource` / `sourceToUrl`
16
+ * carried it: `check a11y contrast` / `touch` / `focus`, `check theme`, `stress i18n`,
17
+ * `stress media`, `check tokens`, `check consistency`.
18
+ *
19
+ * It is also the clearest case of the duplication pattern in the repo. Eight modules
20
+ * wrote their own `isUrl` — animation-eval, motion-detect, breakpoint-check, copy-check,
21
+ * integrity-check, scroll-behavior, scroll-scan, media-variants — and all eight spell it
22
+ * `/^(https?|file):\/\//`. They are right and the shared helper they were meant to
23
+ * replace was wrong, which is why the commands that hand-rolled the check kept working
24
+ * (`check story --gallery "file://$PWD/index.html"`, the recipe in CLAUDE.md, is fine)
25
+ * while the ones written the documented way did not.
26
+ *
27
+ * Scoped to these two schemes rather than "anything with a scheme" on purpose: `data:`
28
+ * and `about:` are not sources any caller resolves, and a bare Windows drive letter
29
+ * (`C:\page.html`) must stay a path.
30
+ */
4
31
  declare const isUrlSource: (source: string) => boolean;
5
32
  /**
6
33
  * Normalize a source for storage and display: an absolute path for a file, the
@@ -40,8 +67,86 @@ declare function sourceToUrl(source: string): string;
40
67
  * network idle anyway, so the 8 `load` and 2 `domcontentloaded` call sites are
41
68
  * equivalent to the 71 `networkidle` ones **provided they settle**. The
42
69
  * difference that mattered was always the settle, never the load state.
70
+ *
71
+ * ## The fourth part: entrance animations
72
+ *
73
+ * Added 2026-08-16, from dogfooding `examples/solitaire/`. Idle + fonts + 250ms is not enough
74
+ * for a page that animates itself in, and the failure has the same shape as the three above —
75
+ * reported as a defect in the page rather than as looking too early:
76
+ *
77
+ * - `check integrity` reported `low-contrast-text … 4.12:1` on a card whose colour is 5.8:1.
78
+ * It had measured the card at `opacity: 0.2` **in mid-flight during a 960ms deal
79
+ * animation**, and the finding arrived with a selector, so a reader goes looking for a
80
+ * colour bug that does not exist. With the animation finished the same gate says CLEAN.
81
+ *
82
+ * So this now also waits for every animation that HAS an end to reach it, via
83
+ * `Animation.finished` over `document.getAnimations()`.
84
+ *
85
+ * Infinite animations are excluded rather than waited on, which is the whole reason this is
86
+ * safe to put in the shared settle: a spinner, a marquee or a pulsing badge never finishes, and
87
+ * awaiting it would hang every gate on every page that has one. `animationCapMs` bounds the
88
+ * wait regardless, because a long finite animation is not worth stalling a run for — a page
89
+ * with a 30-second intro gets measured at the cap and that is the correct trade.
90
+ */
91
+ declare function settlePage(page: Page, settleMs?: number, animationCapMs?: number): Promise<void>;
92
+ /**
93
+ * Install HAR replay on a page, when the caller asked for it.
94
+ *
95
+ * `notFound: "abort"` rather than Playwright's default `"fallback"`, and that is
96
+ * a real trade the caller has to know about:
97
+ *
98
+ * - `abort` is what makes `--har` solve the problem it was added for. The hang
99
+ * in issue #112 was a third-party request that never settles; `fallback`
100
+ * would let that same request through to the network and the run would hang
101
+ * exactly as before. `abort` is also what makes a HAR run reproducible
102
+ * offline, which is the other reason to record one.
103
+ * - The cost: an *incomplete* HAR turns every un-recorded subresource into a
104
+ * failed request. On gates that judge resources — `check integrity`'s
105
+ * `broken-image` / `failed-stylesheet` / `broken-font` rules — that reads as
106
+ * a defect in the page rather than as a gap in the recording, so HAR
107
+ * completeness silently becomes part of the verdict. Record with
108
+ * `browser.newContext({ recordHar: { path } })` over the same navigation the
109
+ * gate will perform, and treat new findings under `--har` as suspect until
110
+ * the recording has been refreshed.
111
+ *
112
+ * This was already the behaviour at `check integrity`'s and `check design`'s own
113
+ * goto sites (both hardcoded `notFound: "abort"`); it lives here so the trade is
114
+ * documented once and the gates that have since adopted `--har` cannot disagree
115
+ * about it.
116
+ */
117
+ declare function applyHar(page: Page, har?: string): Promise<HarReplay | null>;
118
+ /**
119
+ * What the recording contains, and what the run asked for that it did not.
120
+ *
121
+ * The paragraph above documents the cost of `notFound: "abort"` and then offers a
122
+ * human instruction as the mitigation — "treat new findings under `--har` as
123
+ * suspect". v5's CI agent hit it from the outside and named what that costs:
124
+ *
125
+ * "there is **no staleness signal**: a new endpoint absent from the HAR is
126
+ * *aborted*, surfacing as a broken-resource **defect** rather than 'your fixture
127
+ * is out of date'. And the HAR is keyed on the full URL, so it is **port-bound**
128
+ * — change the port and it silently stops matching."
129
+ *
130
+ * Both are decidable from the file itself, so they do not have to be a caution in a
131
+ * doc comment. A gate that judges resources can ask which failures were fixture
132
+ * misses and blame the recording instead of the page.
43
133
  */
44
- declare function settlePage(page: Page, settleMs?: number): Promise<void>;
134
+ interface HarReplay {
135
+ /** Absolute path of the recording in use. */
136
+ path: string;
137
+ /** Origins the recording actually contains, deduped, in first-seen order. */
138
+ origins: readonly string[];
139
+ /** True when the recording holds no entry for this exact URL. */
140
+ isMiss(url: string): boolean;
141
+ /** URLs requested so far that the recording does not contain, in request order. */
142
+ misses(): readonly string[];
143
+ /**
144
+ * Set when the recording contains nothing for the origin actually being visited —
145
+ * the port-bound failure mode, where every single request misses and the page
146
+ * measures as entirely broken. Null when at least one origin matches.
147
+ */
148
+ originMismatch(pageUrl: string): string | null;
149
+ }
45
150
  interface OpenPageOptions {
46
151
  viewport?: ViewportSize;
47
152
  deviceScaleFactor?: number;
@@ -51,8 +156,24 @@ interface OpenPageOptions {
51
156
  storageState?: string;
52
157
  waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit";
53
158
  timeout?: number;
159
+ /**
160
+ * Replay network responses from a Playwright HAR. Applied before navigation,
161
+ * so the document request itself comes from the recording. See `applyHar` for
162
+ * why un-recorded requests are aborted rather than passed through.
163
+ */
164
+ har?: string;
54
165
  /** Extra quiet time after load. 0 skips it. */
55
166
  settleMs?: number;
167
+ /**
168
+ * How long to wait for the page's finite animations to finish, before giving up and measuring
169
+ * anyway. 0 skips the wait.
170
+ *
171
+ * Reachable from here because a gate that knows the page it is opening knows better than the
172
+ * default: a build pipeline measuring a page with a deliberately long intro wants a bigger
173
+ * cap, and a gate measuring load timing wants 0. Infinite animations are never waited on at
174
+ * any cap — see `settlePage`.
175
+ */
176
+ animationCapMs?: number;
56
177
  /** Skip settling entirely (a gate that measures load timing does its own). */
57
178
  skipSettle?: boolean;
58
179
  }
@@ -99,4 +220,4 @@ interface OpenHtmlOptions extends OpenPageOptions {
99
220
  */
100
221
  declare function openHtml(browser: Browser, html: string, options?: OpenHtmlOptions): Promise<Page>;
101
222
  //#endregion
102
- export { OpenHtmlOptions, OpenPageOptions, OpenedPage, isUrlSource, openHtml, openSource, resolveSource, settlePage, sourceToUrl };
223
+ export { HarReplay, OpenHtmlOptions, OpenPageOptions, OpenedPage, applyHar, isUrlSource, openHtml, openSource, resolveSource, settlePage, sourceToUrl };