@mizchi/vlmkit-core 0.23.2 → 0.28.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.
Files changed (112) hide show
  1. package/dist/a11y-semantic.d.mts +6 -10
  2. package/dist/a11y-semantic.mjs +3 -4
  3. package/dist/animated-image.d.mts +27 -0
  4. package/dist/animated-image.mjs +112 -0
  5. package/dist/apng.d.mts +5 -9
  6. package/dist/apng.mjs +6 -7
  7. package/dist/arg-reader.d.mts +9 -12
  8. package/dist/arg-reader.mjs +1 -2
  9. package/dist/auth-state.d.mts +6 -9
  10. package/dist/auth-state.mjs +1 -2
  11. package/dist/authored-style-capture.d.mts +7 -10
  12. package/dist/authored-style-capture.mjs +1 -2
  13. package/dist/authored-style-diff.d.mts +8 -12
  14. package/dist/authored-style-diff.mjs +1 -2
  15. package/dist/bitmap-font.d.mts +7 -10
  16. package/dist/bitmap-font.mjs +1 -2
  17. package/dist/browser-launch.d.mts +7 -11
  18. package/dist/browser-launch.mjs +1 -2
  19. package/dist/cli-args.d.mts +8 -11
  20. package/dist/cli-args.mjs +1 -2
  21. package/dist/cli-error.d.mts +10 -13
  22. package/dist/cli-error.mjs +2 -3
  23. package/dist/computed-style-capture.d.mts +20 -23
  24. package/dist/computed-style-capture.mjs +4 -5
  25. package/dist/computed-style-diff.d.mts +8 -11
  26. package/dist/computed-style-diff.mjs +2 -3
  27. package/dist/diff-regions.d.mts +3 -7
  28. package/dist/diff-regions.mjs +1 -2
  29. package/dist/dom-equivalence.d.mts +5 -8
  30. package/dist/dom-equivalence.mjs +1 -2
  31. package/dist/dom-position-styles.d.mts +14 -15
  32. package/dist/dom-position-styles.mjs +4 -5
  33. package/dist/element-compare.d.mts +8 -9
  34. package/dist/element-compare.mjs +5 -5
  35. package/dist/filmstrip.d.mts +60 -9
  36. package/dist/filmstrip.mjs +83 -12
  37. package/dist/gate-config.d.mts +18 -22
  38. package/dist/gate-config.mjs +8 -4
  39. package/dist/gate-exit.d.mts +5 -8
  40. package/dist/gate-exit.mjs +1 -2
  41. package/dist/gif.d.mts +41 -0
  42. package/dist/gif.mjs +73 -0
  43. package/dist/heatmap-regions.d.mts +4 -7
  44. package/dist/heatmap-regions.mjs +1 -2
  45. package/dist/heatmap.d.mts +21 -17
  46. package/dist/heatmap.mjs +23 -11
  47. package/dist/image-resize.d.mts +9 -12
  48. package/dist/image-resize.mjs +1 -2
  49. package/dist/image-timing.d.mts +57 -0
  50. package/dist/image-timing.mjs +166 -0
  51. package/dist/index.d.mts +14 -14
  52. package/dist/index.mjs +11 -11
  53. package/dist/mask.d.mts +5 -9
  54. package/dist/mask.mjs +1 -2
  55. package/dist/motion-spec.d.mts +97 -0
  56. package/dist/motion-spec.mjs +145 -0
  57. package/dist/navigation-redirect.d.mts +1 -4
  58. package/dist/navigation-redirect.mjs +1 -2
  59. package/dist/page-load.d.mts +40 -16
  60. package/dist/page-load.mjs +34 -5
  61. package/dist/page-open.d.mts +15 -15
  62. package/dist/page-open.mjs +4 -3
  63. package/dist/plugin/args.d.mts +16 -12
  64. package/dist/plugin/args.mjs +15 -4
  65. package/dist/plugin/browser.d.mts +3 -3
  66. package/dist/plugin/browser.mjs +2 -2
  67. package/dist/plugin/cli-entry.d.mts +1 -4
  68. package/dist/plugin/cli-entry.mjs +1 -2
  69. package/dist/plugin/contract.d.mts +17 -21
  70. package/dist/plugin/contract.mjs +1 -2
  71. package/dist/plugin/index.d.mts +6 -9
  72. package/dist/plugin/index.mjs +7 -8
  73. package/dist/plugin/load.d.mts +7 -11
  74. package/dist/plugin/load.mjs +1 -2
  75. package/dist/plugin/registry.d.mts +8 -12
  76. package/dist/plugin/registry.mjs +1 -2
  77. package/dist/plugin/rule-prose.d.mts +4 -8
  78. package/dist/plugin/rule-prose.mjs +1 -2
  79. package/dist/plugin/rule-tier.d.mts +7 -11
  80. package/dist/plugin/rule-tier.mjs +1 -2
  81. package/dist/plugin/rules.d.mts +18 -22
  82. package/dist/plugin/rules.mjs +1 -2
  83. package/dist/plugin/runner.d.mts +18 -21
  84. package/dist/plugin/runner.mjs +55 -6
  85. package/dist/png-decode.d.mts +17 -0
  86. package/dist/png-decode.mjs +160 -0
  87. package/dist/png-utils.d.mts +7 -10
  88. package/dist/png-utils.mjs +3 -3
  89. package/dist/project-config.d.mts +7 -10
  90. package/dist/project-config.mjs +1 -2
  91. package/dist/rect-overlap.d.mts +3 -6
  92. package/dist/rect-overlap.mjs +1 -2
  93. package/dist/region-shift.d.mts +3 -6
  94. package/dist/region-shift.mjs +1 -2
  95. package/dist/run-ledger.d.mts +10 -13
  96. package/dist/run-ledger.mjs +4 -4
  97. package/dist/stable-selector.d.mts +1 -4
  98. package/dist/stable-selector.mjs +1 -2
  99. package/dist/terminal-colors.d.mts +8 -11
  100. package/dist/terminal-colors.mjs +1 -2
  101. package/dist/text-rows.d.mts +10 -13
  102. package/dist/text-rows.mjs +1 -2
  103. package/dist/types.d.mts +87 -64
  104. package/dist/version.d.mts +1 -4
  105. package/dist/version.mjs +2 -3
  106. package/dist/video-decode.d.mts +144 -0
  107. package/dist/video-decode.mjs +939 -0
  108. package/dist/video-frames.d.mts +310 -0
  109. package/dist/video-frames.mjs +576 -0
  110. package/dist/webp.d.mts +7 -11
  111. package/dist/webp.mjs +3 -3
  112. package/package.json +7 -7
@@ -0,0 +1,97 @@
1
+ /**
2
+ * `{"motion": {...}}` in `vlmkit.gates.json`: what a brief asks of a page's motion, written down
3
+ * per target, and run as `inspect motion` (issue #215).
4
+ *
5
+ * In every motion-authoring round the agents mapped a brief to `--expect-*` flags by hand, each
6
+ * time, and most of the small-model round's friction was that mapping: a flag given once applied
7
+ * to every target, `any` was missing, a per-target list had to be counted. The mapping was then
8
+ * thrown away with the session, so CI could not check it again. Here each target carries its own
9
+ * expectations by name, and the object is compiled to the command line `inspect motion` already
10
+ * takes — the flags stay the one implementation, and `gates list` shows exactly what will run.
11
+ *
12
+ * ```json
13
+ * { "motion": {
14
+ * "actions": [{ "click": ".toggle" }],
15
+ * "targets": [
16
+ * { "selector": ".menu", "origin": "top", "duration": 250, "easing": "ease-out" },
17
+ * { "selector": ".backdrop", "still": true }
18
+ * ],
19
+ * "baseline": ".vlmkit/motion/menu.json" } }
20
+ * ```
21
+ *
22
+ * Targets are put in the order the command line measures them: `selector` targets first, then
23
+ * `track` ones. A key it does not know is a config error naming its JSON path, as everywhere in
24
+ * the file: a misspelt expectation that silently checked nothing is the failure this exists to end.
25
+ *
26
+ * Pure: an object in, a command string out.
27
+ */
28
+ /** One expectation value given as the flag takes it: a number of ms, or a string ("280ms", "+50"). */
29
+ type TimeValue = number | string;
30
+ export interface MotionSpecTarget {
31
+ /** The element that moves (`--selector`). */
32
+ selector?: string;
33
+ /** Or the region it fills in the last frame (`--track x,y,w,h`): a canvas, a recording. */
34
+ track?: string | [number, number, number, number];
35
+ /** Its name in the report and the baseline (`--target`). */
36
+ name?: string;
37
+ /** Its curve, or one per segment (`--expect-easing`). */
38
+ easing?: string | string[];
39
+ /** The point it scales, turns or grows about: a keyword or [x, y] in its own units. */
40
+ origin?: string | [number, number];
41
+ /** When its own animation begins (ms of page time, or "+N" from the last action). */
42
+ start?: TimeValue;
43
+ duration?: TimeValue;
44
+ /** How many runs, or "infinite". */
45
+ iterations?: number | "infinite";
46
+ direction?: string;
47
+ /** Lines its text runs to in every frame. */
48
+ lines?: number;
49
+ /** At rest its left and right edges are this element's (`--expect-span-of`). */
50
+ spanOf?: string;
51
+ /** Its centre must not move (`--still`). A `selector` target only. */
52
+ still?: boolean;
53
+ /** It is meant to leave (`--exit`). A `selector` target only. */
54
+ exit?: boolean;
55
+ }
56
+ export type MotionSpecAction = {
57
+ click: string;
58
+ } | {
59
+ hover: string;
60
+ } | {
61
+ leave: true;
62
+ } | {
63
+ scroll: string | number;
64
+ } | {
65
+ wait: TimeValue;
66
+ };
67
+ export interface MotionSpec {
68
+ targets: MotionSpecTarget[];
69
+ actions?: MotionSpecAction[];
70
+ /** Each target begins this long after the one before (`--expect-stagger`). */
71
+ stagger?: TimeValue;
72
+ /** Every target is meant to leave (`--exits`). */
73
+ exits?: boolean;
74
+ reducedMotion?: boolean;
75
+ /** Every target's angle on screen stays the same (`--expect-upright`). */
76
+ upright?: boolean;
77
+ everyAction?: boolean;
78
+ start?: TimeValue;
79
+ end?: TimeValue;
80
+ /** Instants to shoot, as `--at` takes them ("0..600/50"). */
81
+ at?: string;
82
+ /** "WxH". */
83
+ viewport?: string;
84
+ deviceScale?: number;
85
+ /** Hold the run to an approved one (`--baseline`), relative to the config file. */
86
+ baseline?: string;
87
+ /** Where the frames go (`--frames`). */
88
+ frames?: string;
89
+ }
90
+ /** One argument as `tokenizeCommand` reads it back: quoted when it holds a space or a quote. */
91
+ export declare function quoteArg(value: string): string;
92
+ /**
93
+ * Compile a `{"motion": ...}` entry's value to the `inspect motion` command it stands for.
94
+ * `fail(path, message)` reports a config error at a JSON path (and does not return).
95
+ */
96
+ export declare function motionSpecCommand(raw: unknown, path: string, fail: (path: string, message: string) => never): string;
97
+ export {};
@@ -0,0 +1,145 @@
1
+ // src/motion-spec.ts
2
+ const TARGET_KEYS = /* @__PURE__ */ new Set([
3
+ "selector",
4
+ "track",
5
+ "name",
6
+ "easing",
7
+ "origin",
8
+ "start",
9
+ "duration",
10
+ "iterations",
11
+ "direction",
12
+ "lines",
13
+ "spanOf",
14
+ "still",
15
+ "exit"
16
+ ]);
17
+ const SPEC_KEYS = /* @__PURE__ */ new Set([
18
+ "targets",
19
+ "actions",
20
+ "stagger",
21
+ "exits",
22
+ "reducedMotion",
23
+ "upright",
24
+ "everyAction",
25
+ "start",
26
+ "end",
27
+ "at",
28
+ "viewport",
29
+ "deviceScale",
30
+ "baseline",
31
+ "frames"
32
+ ]);
33
+ /** One argument as `tokenizeCommand` reads it back: quoted when it holds a space or a quote. */
34
+ function quoteArg(value) {
35
+ if (value !== "" && !/[\s'"]/.test(value)) return value;
36
+ return value.includes("'") ? `"${value}"` : `'${value}'`;
37
+ }
38
+ /** The name `inspect motion` gives a --track target it was not given one for. */
39
+ const defaultTrackName = (track) => {
40
+ const [x, y, w, h] = track.split(",").map((v) => Number(v.trim()));
41
+ return `region ${x},${y} ${w}x${h}`;
42
+ };
43
+ const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
44
+ /**
45
+ * Compile a `{"motion": ...}` entry's value to the `inspect motion` command it stands for.
46
+ * `fail(path, message)` reports a config error at a JSON path (and does not return).
47
+ */
48
+ function motionSpecCommand(raw, path, fail) {
49
+ if (!isObject(raw)) fail(path, "must be an object: { \"targets\": [...], \"actions\"?: [...], ... }");
50
+ for (const key of Object.keys(raw)) if (!SPEC_KEYS.has(key)) fail(`${path}.${key}`, `is not a motion expectation (known: ${[...SPEC_KEYS].join(", ")})`);
51
+ const str = (v, at) => {
52
+ if (typeof v !== "string" || !v.trim()) fail(at, "must be a non-empty string");
53
+ return v.trim();
54
+ };
55
+ const time = (v, at) => {
56
+ if (typeof v === "number" && Number.isFinite(v)) return String(v);
57
+ if (typeof v === "string" && v.trim()) return v.trim();
58
+ fail(at, "must be a number of ms or a time string (\"280ms\", \"1.2s\", \"+50\")");
59
+ };
60
+ const bool = (v, at) => {
61
+ if (typeof v !== "boolean") fail(at, "must be true or false");
62
+ return v;
63
+ };
64
+ if (!Array.isArray(raw.targets) || raw.targets.length === 0) fail(`${path}.targets`, "must be a non-empty array: one entry per element (or region) that moves");
65
+ const parsed = raw.targets.map((t, i) => {
66
+ const at = `${path}.targets[${i}]`;
67
+ if (!isObject(t)) fail(at, "must be an object");
68
+ for (const key of Object.keys(t)) if (!TARGET_KEYS.has(key)) fail(`${at}.${key}`, `is not a target expectation (known: ${[...TARGET_KEYS].join(", ")})`);
69
+ if (t.selector === void 0 === (t.track === void 0)) fail(at, "needs exactly one of selector or track");
70
+ let track;
71
+ if (t.track !== void 0) {
72
+ if (Array.isArray(t.track) && t.track.length === 4 && t.track.every((n) => typeof n === "number" && Number.isFinite(n))) track = t.track.join(",");
73
+ else track = str(t.track, `${at}.track`);
74
+ if (t.still !== void 0 || t.exit !== void 0) fail(at, "still and exit name an element: give this target a selector, or drop them");
75
+ }
76
+ return {
77
+ t,
78
+ at,
79
+ selector: t.selector === void 0 ? void 0 : str(t.selector, `${at}.selector`),
80
+ track
81
+ };
82
+ });
83
+ const ordered = [...parsed.filter((p) => p.selector !== void 0), ...parsed.filter((p) => p.track !== void 0)];
84
+ const out = ["inspect", "motion"];
85
+ const flag = (name, value) => out.push(name, ...value === void 0 ? [] : [quoteArg(value)]);
86
+ if (raw.actions !== void 0 && !Array.isArray(raw.actions)) fail(`${path}.actions`, "must be an array");
87
+ for (const [k, a] of (raw.actions ?? []).entries()) {
88
+ const at = `${path}.actions[${k}]`;
89
+ if (!isObject(a) || Object.keys(a).length !== 1) fail(at, "must be one of { \"click\": css }, { \"hover\": css }, { \"leave\": true }, { \"scroll\": css | px }, { \"wait\": ms }");
90
+ const [kind, v] = Object.entries(a)[0];
91
+ if (kind === "click" || kind === "hover") flag(`--${kind}`, str(v, `${at}.${kind}`));
92
+ else if (kind === "leave") {
93
+ if (v !== true) fail(`${at}.leave`, "must be true");
94
+ flag("--leave");
95
+ } else if (kind === "scroll") flag("--scroll", typeof v === "number" ? String(v) : str(v, `${at}.scroll`));
96
+ else if (kind === "wait") flag("--wait", time(v, `${at}.wait`));
97
+ else fail(`${at}.${kind}`, "is not an action (click, hover, leave, scroll, wait)");
98
+ }
99
+ for (const p of ordered) if (p.selector !== void 0) flag("--selector", p.selector);
100
+ else flag("--track", p.track);
101
+ if (ordered.some((p) => p.t.name !== void 0)) for (const p of ordered) flag("--target", p.t.name !== void 0 ? str(p.t.name, `${p.at}.name`) : p.selector ?? defaultTrackName(p.track));
102
+ const any = (key) => ordered.some((p) => p.t[key] !== void 0);
103
+ if (any("easing")) for (const p of ordered) {
104
+ const v = p.t.easing;
105
+ if (v === void 0) flag("--expect-easing", "any");
106
+ else if (Array.isArray(v)) flag("--expect-easing", v.map((e, j) => str(e, `${p.at}.easing[${j}]`)).join(","));
107
+ else flag("--expect-easing", str(v, `${p.at}.easing`));
108
+ }
109
+ if (any("origin")) for (const p of ordered) {
110
+ const v = p.t.origin;
111
+ if (v === void 0) flag("--expect-origin", "any");
112
+ else if (Array.isArray(v) && v.length === 2 && v.every((n) => typeof n === "number" && Number.isFinite(n))) flag("--expect-origin", v.join(","));
113
+ else flag("--expect-origin", str(v, `${p.at}.origin`));
114
+ }
115
+ if (any("spanOf")) for (const p of ordered) flag("--expect-span-of", p.t.spanOf === void 0 ? "any" : str(p.t.spanOf, `${p.at}.spanOf`));
116
+ const list = (key, name, read) => {
117
+ if (any(key)) flag(name, ordered.map((p) => p.t[key] === void 0 ? "any" : read(p.t[key], `${p.at}.${key}`)).join(","));
118
+ };
119
+ list("start", "--expect-start", time);
120
+ list("duration", "--expect-duration", time);
121
+ list("iterations", "--expect-iterations", (v, at) => v === "infinite" ? "infinite" : typeof v === "number" && Number.isInteger(v) && v > 0 ? String(v) : fail(at, "must be a whole number of runs, or \"infinite\""));
122
+ list("direction", "--expect-direction", str);
123
+ list("lines", "--expect-lines", (v, at) => typeof v === "number" && Number.isInteger(v) && v > 0 ? String(v) : fail(at, "must be a whole number of lines"));
124
+ for (const p of ordered) {
125
+ if (p.t.still !== void 0 && bool(p.t.still, `${p.at}.still`)) flag("--still", p.selector);
126
+ if (p.t.exit !== void 0 && bool(p.t.exit, `${p.at}.exit`)) flag("--exit", p.selector);
127
+ }
128
+ if (raw.stagger !== void 0) flag("--expect-stagger", time(raw.stagger, `${path}.stagger`));
129
+ if (raw.exits !== void 0 && bool(raw.exits, `${path}.exits`)) flag("--exits");
130
+ if (raw.reducedMotion !== void 0 && bool(raw.reducedMotion, `${path}.reducedMotion`)) flag("--reduced-motion");
131
+ if (raw.upright !== void 0 && bool(raw.upright, `${path}.upright`)) flag("--expect-upright");
132
+ if (raw.everyAction !== void 0 && bool(raw.everyAction, `${path}.everyAction`)) flag("--every-action");
133
+ if (raw.start !== void 0) flag("--start", time(raw.start, `${path}.start`));
134
+ if (raw.end !== void 0) flag("--end", time(raw.end, `${path}.end`));
135
+ if (raw.at !== void 0) flag("--at", str(raw.at, `${path}.at`));
136
+ if (raw.viewport !== void 0) flag("--viewport", str(raw.viewport, `${path}.viewport`));
137
+ if (raw.deviceScale !== void 0) {
138
+ if (typeof raw.deviceScale !== "number" || !(raw.deviceScale > 0)) fail(`${path}.deviceScale`, "must be a positive number");
139
+ flag("--device-scale", String(raw.deviceScale));
140
+ }
141
+ if (raw.baseline !== void 0) flag("--baseline", str(raw.baseline, `${path}.baseline`));
142
+ if (raw.frames !== void 0) flag("--frames", str(raw.frames, `${path}.frames`));
143
+ return out.join(" ");
144
+ }
145
+ export { motionSpecCommand, quoteArg };
@@ -1,4 +1,3 @@
1
- //#region src/navigation-redirect.d.ts
2
1
  /**
3
2
  * Redirect disclosure for gates that navigate.
4
3
  *
@@ -23,6 +22,4 @@
23
22
  * than the one requested, or `null` when the navigation landed where the
24
23
  * caller intended (or when either URL is unparseable / not http(s)).
25
24
  */
26
- declare function describeRedirect(requested: string, final: string): string | null;
27
- //#endregion
28
- export { describeRedirect };
25
+ export declare function describeRedirect(requested: string, final: string): string | null;
@@ -1,4 +1,4 @@
1
- //#region src/navigation-redirect.ts
1
+ // src/navigation-redirect.ts
2
2
  /**
3
3
  * Redirect disclosure for gates that navigate.
4
4
  *
@@ -43,5 +43,4 @@ function describeRedirect(requested, final) {
43
43
  const hint = /login|signin|sign-in|auth|sso|account\/login/i.test(b.pathname) ? " This looks like a login wall: the gate measured the sign-in page, NOT the page you asked about. Pass a logged-in Playwright storage state (--storage-state <file>, or VLMKIT_STORAGE_STATE), or point the gate at a route that does not need auth." : " The gate measured the destination, not the URL you passed.";
44
44
  return `redirected: requested ${a.pathname}${a.search} but measured ${b.href}.${hint}`;
45
45
  }
46
- //#endregion
47
46
  export { describeRedirect };
@@ -1,51 +1,76 @@
1
1
  import { GateInput } from "./plugin/contract.mjs";
2
2
  import { applyHar } from "./page-open.mjs";
3
3
  import { Page } from "playwright";
4
-
5
- //#region src/page-load.d.ts
6
4
  /** The navigation milestones a gate exposes. Playwright's `commit` is not one of
7
5
  * 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];
6
+ export declare const PAGE_LOAD_WAIT_UNTIL: readonly ["domcontentloaded", "load", "networkidle"];
7
+ export type PageLoadWaitUntil = (typeof PAGE_LOAD_WAIT_UNTIL)[number];
10
8
  /** Playwright's own default, restated so callers can name it. */
11
- declare const DEFAULT_PAGE_LOAD_TIMEOUT_MS = 30000;
9
+ export declare const DEFAULT_PAGE_LOAD_TIMEOUT_MS = 30000;
12
10
  /** The default milestone every gate has always used. */
13
- declare const DEFAULT_PAGE_LOAD_WAIT_UNTIL: PageLoadWaitUntil;
11
+ export declare const DEFAULT_PAGE_LOAD_WAIT_UNTIL: PageLoadWaitUntil;
14
12
  /**
15
13
  * What a gate carries from argv down to its `page.goto`.
16
14
  *
17
15
  * Structurally a subset of `OpenPageOptions`, so a measurement module that
18
16
  * loads through `openSource` can forward this object as-is.
19
17
  */
20
- interface PageLoadOptions {
18
+ export interface PageLoadOptions {
21
19
  /** Navigation milestone. Defaults to `networkidle`. */
22
20
  waitUntil?: PageLoadWaitUntil;
23
21
  /** Navigation timeout in milliseconds. Defaults to 30000. */
24
22
  timeout?: number;
25
23
  /** Replay network responses from a Playwright HAR. See `applyHar`. */
26
24
  har?: string;
25
+ /**
26
+ * `prefers-color-scheme` to emulate. Not one of the three load knobs: it is declared by
27
+ * `COLOR_SCHEME_INPUT`, only on gates that honour it, and carried here so `pickPageLoad`
28
+ * hands it to `openSource` with the rest.
29
+ */
30
+ colorScheme?: ColorScheme;
27
31
  }
32
+ /** The schemes a gate can be asked to judge a page in. */
33
+ export declare const COLOR_SCHEMES: readonly ["light", "dark"];
34
+ export type ColorScheme = (typeof COLOR_SCHEMES)[number];
28
35
  /**
29
36
  * `inputs` fragment. Spread at the END of a gate's `inputs` array so the
30
37
  * gate-specific flags stay first in `--help`.
31
38
  */
32
- declare const PAGE_LOAD_INPUTS: readonly GateInput[];
39
+ export declare const PAGE_LOAD_INPUTS: readonly GateInput[];
40
+ /**
41
+ * `--color-scheme light|dark`, for a gate whose judgement reads paint (contrast, invisible
42
+ * text, palette). Kept apart from `PAGE_LOAD_INPUTS` on purpose: a gate that declares it must
43
+ * honour it (`applyColorScheme` before its navigation, or `pickPageLoad` into `openSource`),
44
+ * and most load-honouring gates have no reason to.
45
+ *
46
+ * Why it exists: no paint-reading gate emulated `prefers-color-scheme`, so a page that follows
47
+ * the OS theme had its dark theme judged by eye only (the demo sites took `?theme=dark` instead).
48
+ */
49
+ export declare const COLOR_SCHEME_INPUT: GateInput;
50
+ /** Read `--color-scheme`; absent gives an absent key. */
51
+ export declare function parseColorScheme(argv: readonly string[]): {
52
+ colorScheme?: ColorScheme;
53
+ };
54
+ /** Emulate the scheme on a page before it navigates, so its first style already matches. */
55
+ export declare function applyColorScheme(page: Page, colorScheme: ColorScheme | undefined): Promise<void>;
33
56
  /** The flag spellings, for `readPositionals` value-flag lists. */
34
- declare const PAGE_LOAD_VALUE_FLAGS: readonly string[];
57
+ export declare const PAGE_LOAD_VALUE_FLAGS: readonly string[];
58
+ /** `--color-scheme`'s spelling, for the value-flag lists of the gates that declare it. */
59
+ export declare const COLOR_SCHEME_VALUE_FLAGS: readonly string[];
35
60
  /**
36
61
  * Read the three flags off argv. Absent flags produce absent keys, so spreading
37
62
  * the result never overwrites a gate's own default with `undefined`.
38
63
  */
39
- declare function parsePageLoad(argv: readonly string[]): PageLoadOptions;
64
+ export declare function parsePageLoad(argv: readonly string[]): PageLoadOptions;
40
65
  /**
41
- * Narrow a wider options object down to just these three keys.
66
+ * Narrow a wider options object down to these three keys, plus `colorScheme` when set.
42
67
  *
43
68
  * For measurement modules that load through `openSource`: spreading the whole
44
69
  * gate options object into it would also hand over `outputDir`, `reportPath` and
45
70
  * friends, and `OpenPageOptions` is not an index type, so the extra keys would
46
71
  * pass silently today and collide the day one of those names is reused.
47
72
  */
48
- declare function pickPageLoad(options: PageLoadOptions): PageLoadOptions;
73
+ export declare function pickPageLoad(options: PageLoadOptions): PageLoadOptions;
49
74
  /**
50
75
  * The `goto` / `setContent` option object, with the call site's own historical
51
76
  * default preserved.
@@ -56,7 +81,7 @@ declare function pickPageLoad(options: PageLoadOptions): PageLoadOptions;
56
81
  * a page that never reaches network idle. Passing a single global default here
57
82
  * would have silently *broken* them while fixing the others.
58
83
  */
59
- declare function navigationOptions(options?: PageLoadOptions, defaultWaitUntil?: PageLoadWaitUntil): {
84
+ export declare function navigationOptions(options?: PageLoadOptions, defaultWaitUntil?: PageLoadWaitUntil): {
60
85
  waitUntil: PageLoadWaitUntil;
61
86
  timeout: number;
62
87
  };
@@ -78,6 +103,5 @@ declare function navigationOptions(options?: PageLoadOptions, defaultWaitUntil?:
78
103
  * `navigationOptions(options, "load")` + their own `settlePage` instead, so the
79
104
  * settle is not done twice.
80
105
  */
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 };
106
+ export declare function navigatePage(page: Page, url: string, options?: PageLoadOptions): Promise<void>;
107
+ export { applyHar };
@@ -1,6 +1,6 @@
1
1
  import { readChoice, readFlag, readInt } from "./arg-reader.mjs";
2
2
  import { applyHar, settlePage } from "./page-open.mjs";
3
- //#region src/page-load.ts
3
+ // src/page-load.ts
4
4
  /** The navigation milestones a gate exposes. Playwright's `commit` is not one of
5
5
  * them: no gate can read a document that has not parsed. */
6
6
  const PAGE_LOAD_WAIT_UNTIL = [
@@ -12,6 +12,8 @@ const PAGE_LOAD_WAIT_UNTIL = [
12
12
  const DEFAULT_PAGE_LOAD_TIMEOUT_MS = 3e4;
13
13
  /** The default milestone every gate has always used. */
14
14
  const DEFAULT_PAGE_LOAD_WAIT_UNTIL = "networkidle";
15
+ /** The schemes a gate can be asked to judge a page in. */
16
+ const COLOR_SCHEMES = ["light", "dark"];
15
17
  /**
16
18
  * `inputs` fragment. Spread at the END of a gate's `inputs` array so the
17
19
  * gate-specific flags stay first in `--help`.
@@ -38,12 +40,39 @@ const PAGE_LOAD_INPUTS = [
38
40
  description: "Replay network responses from a Playwright HAR (requests absent from it are aborted)"
39
41
  }
40
42
  ];
43
+ /**
44
+ * `--color-scheme light|dark`, for a gate whose judgement reads paint (contrast, invisible
45
+ * text, palette). Kept apart from `PAGE_LOAD_INPUTS` on purpose: a gate that declares it must
46
+ * honour it (`applyColorScheme` before its navigation, or `pickPageLoad` into `openSource`),
47
+ * and most load-honouring gates have no reason to.
48
+ *
49
+ * Why it exists: no paint-reading gate emulated `prefers-color-scheme`, so a page that follows
50
+ * the OS theme had its dark theme judged by eye only (the demo sites took `?theme=dark` instead).
51
+ */
52
+ const COLOR_SCHEME_INPUT = {
53
+ name: "color-scheme",
54
+ kind: "string",
55
+ description: "Emulate prefers-color-scheme while judging (a page that follows the OS theme)",
56
+ choices: COLOR_SCHEMES,
57
+ defaultDescription: "light"
58
+ };
59
+ /** Read `--color-scheme`; absent gives an absent key. */
60
+ function parseColorScheme(argv) {
61
+ const colorScheme = readChoice(argv, "color-scheme", COLOR_SCHEMES);
62
+ return colorScheme ? { colorScheme } : {};
63
+ }
64
+ /** Emulate the scheme on a page before it navigates, so its first style already matches. */
65
+ async function applyColorScheme(page, colorScheme) {
66
+ if (colorScheme) await page.emulateMedia({ colorScheme });
67
+ }
41
68
  /** The flag spellings, for `readPositionals` value-flag lists. */
42
69
  const PAGE_LOAD_VALUE_FLAGS = [
43
70
  "--timeout",
44
71
  "--wait-until",
45
72
  "--har"
46
73
  ];
74
+ /** `--color-scheme`'s spelling, for the value-flag lists of the gates that declare it. */
75
+ const COLOR_SCHEME_VALUE_FLAGS = ["--color-scheme"];
47
76
  /**
48
77
  * Read the three flags off argv. Absent flags produce absent keys, so spreading
49
78
  * the result never overwrites a gate's own default with `undefined`.
@@ -59,7 +88,7 @@ function parsePageLoad(argv) {
59
88
  };
60
89
  }
61
90
  /**
62
- * Narrow a wider options object down to just these three keys.
91
+ * Narrow a wider options object down to these three keys, plus `colorScheme` when set.
63
92
  *
64
93
  * For measurement modules that load through `openSource`: spreading the whole
65
94
  * gate options object into it would also hand over `outputDir`, `reportPath` and
@@ -70,7 +99,8 @@ function pickPageLoad(options) {
70
99
  return {
71
100
  ...options.waitUntil ? { waitUntil: options.waitUntil } : {},
72
101
  ...options.timeout !== void 0 ? { timeout: options.timeout } : {},
73
- ...options.har ? { har: options.har } : {}
102
+ ...options.har ? { har: options.har } : {},
103
+ ...options.colorScheme ? { colorScheme: options.colorScheme } : {}
74
104
  };
75
105
  }
76
106
  /**
@@ -112,5 +142,4 @@ async function navigatePage(page, url, options = {}) {
112
142
  await page.goto(url, navigationOptions(options));
113
143
  if (options.waitUntil && options.waitUntil !== "networkidle") await settlePage(page, 0);
114
144
  }
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 };
145
+ export { COLOR_SCHEMES, COLOR_SCHEME_INPUT, COLOR_SCHEME_VALUE_FLAGS, DEFAULT_PAGE_LOAD_TIMEOUT_MS, DEFAULT_PAGE_LOAD_WAIT_UNTIL, PAGE_LOAD_INPUTS, PAGE_LOAD_VALUE_FLAGS, PAGE_LOAD_WAIT_UNTIL, applyColorScheme, applyHar, navigatePage, navigationOptions, parseColorScheme, parsePageLoad, pickPageLoad };
@@ -1,6 +1,4 @@
1
1
  import { Browser, Page, ViewportSize } from "playwright";
2
-
3
- //#region src/page-open.d.ts
4
2
  /**
5
3
  * Is this source already a URL, or is it a path that has to become one?
6
4
  *
@@ -28,7 +26,7 @@ import { Browser, Page, ViewportSize } from "playwright";
28
26
  * and `about:` are not sources any caller resolves, and a bare Windows drive letter
29
27
  * (`C:\page.html`) must stay a path.
30
28
  */
31
- declare const isUrlSource: (source: string) => boolean;
29
+ export declare const isUrlSource: (source: string) => boolean;
32
30
  /**
33
31
  * Normalize a source for storage and display: an absolute path for a file, the
34
32
  * URL untouched for a URL.
@@ -37,7 +35,7 @@ declare const isUrlSource: (source: string) => boolean;
37
35
  * yields `<cwd>/http:/x/p.html`, which then fails as "file not found" and tells
38
36
  * the caller nothing about what actually went wrong.
39
37
  */
40
- declare function resolveSource(source: string): string;
38
+ export declare function resolveSource(source: string): string;
41
39
  /**
42
40
  * File path or URL → a URL Playwright can navigate to.
43
41
  *
@@ -50,7 +48,7 @@ declare function resolveSource(source: string): string;
50
48
  * file and the part before the `?` / `#` is, so a file that really has `?` in its name still
51
49
  * opens as that file.
52
50
  */
53
- declare function sourceToUrl(source: string): string;
51
+ export declare function sourceToUrl(source: string): string;
54
52
  /**
55
53
  * Wait for the page to stop moving: bounded network idle, then webfonts, then
56
54
  * one frame. Every part is best-effort — a page with a long-poll connection
@@ -99,7 +97,7 @@ declare function sourceToUrl(source: string): string;
99
97
  * wait regardless, because a long finite animation is not worth stalling a run for — a page
100
98
  * with a 30-second intro gets measured at the cap and that is the correct trade.
101
99
  */
102
- declare function settlePage(page: Page, settleMs?: number, animationCapMs?: number): Promise<void>;
100
+ export declare function settlePage(page: Page, settleMs?: number, animationCapMs?: number): Promise<void>;
103
101
  /**
104
102
  * Install HAR replay on a page, when the caller asked for it.
105
103
  *
@@ -125,7 +123,7 @@ declare function settlePage(page: Page, settleMs?: number, animationCapMs?: numb
125
123
  * documented once and the gates that have since adopted `--har` cannot disagree
126
124
  * about it.
127
125
  */
128
- declare function applyHar(page: Page, har?: string): Promise<HarReplay | null>;
126
+ export declare function applyHar(page: Page, har?: string): Promise<HarReplay | null>;
129
127
  /**
130
128
  * What the recording contains, and what the run asked for that it did not.
131
129
  *
@@ -142,7 +140,7 @@ declare function applyHar(page: Page, har?: string): Promise<HarReplay | null>;
142
140
  * doc comment. A gate that judges resources can ask which failures were fixture
143
141
  * misses and blame the recording instead of the page.
144
142
  */
145
- interface HarReplay {
143
+ export interface HarReplay {
146
144
  /** Absolute path of the recording in use. */
147
145
  path: string;
148
146
  /** Origins the recording actually contains, deduped, in first-seen order. */
@@ -158,9 +156,13 @@ interface HarReplay {
158
156
  */
159
157
  originMismatch(pageUrl: string): string | null;
160
158
  }
161
- interface OpenPageOptions {
159
+ export interface OpenPageOptions {
162
160
  viewport?: ViewportSize;
163
161
  deviceScaleFactor?: number;
162
+ /** A phone: the viewport meta is honoured and `pointer: coarse` matches (`check mobile`). */
163
+ isMobile?: boolean;
164
+ /** Touch events are on (`check mobile` swipes with them). */
165
+ hasTouch?: boolean;
164
166
  /** `prefers-color-scheme` for the page's context (theme-parity opens both). */
165
167
  colorScheme?: "light" | "dark" | "no-preference";
166
168
  /** Playwright storage state for pages behind a login. */
@@ -188,7 +190,7 @@ interface OpenPageOptions {
188
190
  /** Skip settling entirely (a gate that measures load timing does its own). */
189
191
  skipSettle?: boolean;
190
192
  }
191
- interface OpenedPage {
193
+ export interface OpenedPage {
192
194
  page: Page;
193
195
  /**
194
196
  * Human-readable note when a URL redirected somewhere meaningful (a login
@@ -200,8 +202,8 @@ interface OpenedPage {
200
202
  /**
201
203
  * Open a file or URL by navigation, so relative assets resolve.
202
204
  */
203
- declare function openSource(browser: Browser, source: string, options?: OpenPageOptions): Promise<OpenedPage>;
204
- interface OpenHtmlOptions extends OpenPageOptions {
205
+ export declare function openSource(browser: Browser, source: string, options?: OpenPageOptions): Promise<OpenedPage>;
206
+ export interface OpenHtmlOptions extends OpenPageOptions {
205
207
  /**
206
208
  * The file or URL this HTML came from. The page navigates there first, so the
207
209
  * document keeps that base URL and the mutated copy still resolves the
@@ -229,6 +231,4 @@ interface OpenHtmlOptions extends OpenPageOptions {
229
231
  * the document a real base URL, and `setContent` replaces the markup without
230
232
  * discarding it.
231
233
  */
232
- declare function openHtml(browser: Browser, html: string, options?: OpenHtmlOptions): Promise<Page>;
233
- //#endregion
234
- export { HarReplay, OpenHtmlOptions, OpenPageOptions, OpenedPage, applyHar, isUrlSource, openHtml, openSource, resolveSource, settlePage, sourceToUrl };
234
+ export declare function openHtml(browser: Browser, html: string, options?: OpenHtmlOptions): Promise<Page>;
@@ -3,7 +3,7 @@ import { describeRedirect } from "./navigation-redirect.mjs";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { resolve } from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
- //#region src/page-open.ts
6
+ // src/page-open.ts
7
7
  /**
8
8
  * One way to open the page under test.
9
9
  *
@@ -266,7 +266,9 @@ function pageOptions(options) {
266
266
  return withAuthState({
267
267
  ...options.viewport ? { viewport: options.viewport } : {},
268
268
  ...options.deviceScaleFactor !== void 0 ? { deviceScaleFactor: options.deviceScaleFactor } : {},
269
- ...options.colorScheme ? { colorScheme: options.colorScheme } : {}
269
+ ...options.colorScheme ? { colorScheme: options.colorScheme } : {},
270
+ ...options.isMobile ? { isMobile: true } : {},
271
+ ...options.hasTouch ? { hasTouch: true } : {}
270
272
  }, options.storageState);
271
273
  }
272
274
  /**
@@ -317,5 +319,4 @@ async function openHtml(browser, html, options = {}) {
317
319
  if (!options.skipSettle) await settlePage(page, options.settleMs ?? 250, options.animationCapMs);
318
320
  return page;
319
321
  }
320
- //#endregion
321
322
  export { applyHar, isUrlSource, openHtml, openSource, resolveSource, settlePage, sourceToUrl };
@@ -1,4 +1,3 @@
1
- //#region src/plugin/args.d.ts
2
1
  /**
3
2
  * Argument helpers for writing a gate — the shapes `arg-reader` does not cover.
4
3
  *
@@ -16,7 +15,7 @@
16
15
  * rather than a boundary. Re-exported from `./index.ts`, which is the entry a
17
16
  * plugin should import.
18
17
  */
19
- declare function firstPositional(argv: readonly string[], usage: string, valueFlags?: readonly string[]): string;
18
+ export declare function firstPositional(argv: readonly string[], usage: string, valueFlags?: readonly string[]): string;
20
19
  /**
21
20
  * The first positional, or `undefined` when there is none.
22
21
  *
@@ -24,7 +23,7 @@ declare function firstPositional(argv: readonly string[], usage: string, valueFl
24
23
  * distinction `check integrity` needs in order to *reject* being given both a page and
25
24
  * `--elements` rather than silently preferring one.
26
25
  */
27
- declare function firstPositionalOrUndefined(argv: readonly string[], valueFlags?: readonly string[]): string | undefined;
26
+ export declare function firstPositionalOrUndefined(argv: readonly string[], valueFlags?: readonly string[]): string | undefined;
28
27
  /**
29
28
  * Drop an optionally-valued flag and whatever value it consumed.
30
29
  *
@@ -41,20 +40,27 @@ declare function firstPositionalOrUndefined(argv: readonly string[], valueFlags?
41
40
  * positional left and fails with the usage line, which is the honest outcome
42
41
  * for a genuinely ambiguous command line.
43
42
  */
44
- declare function withoutOptionalValue(argv: readonly string[], name: string): string[];
43
+ export declare function withoutOptionalValue(argv: readonly string[], name: string): string[];
45
44
  /** `--breakpoints 768,1024` → `[768, 1024]`. Absent flag → `undefined`. */
46
- declare function numberList(argv: readonly string[], name: string): number[] | undefined;
45
+ export declare function numberList(argv: readonly string[], name: string): number[] | undefined;
46
+ /**
47
+ * `--at 0,150,1.5s,0..1s/100ms` → instants in ms, sorted and deduplicated. Absent flag →
48
+ * `undefined`. The grammar is `parseInstants` (`@mizchi/vlmkit-judge/frames.ts`): bare numbers
49
+ * are ms, and `s`, `ms`, `f` (60fps frames), `mm:ss.sss` and ranges are accepted. Not
50
+ * `numberList`, whose `parseInt` read `1.5s` as 1 ms.
51
+ */
52
+ export declare function instantList(argv: readonly string[], name: string): number[] | undefined;
47
53
  /**
48
54
  * Like `numberList`, but for scales that are legitimately fractional
49
55
  * (`--tolerance`-adjacent flags such as `--radius-scale 0,2,4.5`).
50
56
  */
51
- declare function numberListFloat(argv: readonly string[], name: string): number[] | undefined;
57
+ export declare function numberListFloat(argv: readonly string[], name: string): number[] | undefined;
52
58
  /** `--viewport 1280x720` → `{width, height}`. */
53
- declare function viewportFlag(argv: readonly string[], name?: string): {
59
+ export declare function viewportFlag(argv: readonly string[], name?: string): {
54
60
  width: number;
55
61
  height: number;
56
62
  } | undefined;
57
- declare function optionalInt(argv: readonly string[], name: string, options?: {
63
+ export declare function optionalInt(argv: readonly string[], name: string, options?: {
58
64
  min?: number;
59
65
  }): number | undefined;
60
66
  /**
@@ -65,7 +71,7 @@ declare function optionalInt(argv: readonly string[], name: string, options?: {
65
71
  * `readFlag` cannot express this: the value is optional, so a bare `--vlm`
66
72
  * followed by another flag must not consume it.
67
73
  */
68
- declare function vlmFlag(argv: readonly string[], name?: string): string | true | undefined;
74
+ export declare function vlmFlag(argv: readonly string[], name?: string): string | true | undefined;
69
75
  /**
70
76
  * Default output directory for a gate run, keyed on what the run measured.
71
77
  *
@@ -81,6 +87,4 @@ declare function vlmFlag(argv: readonly string[], name?: string): string | true
81
87
  * `discriminator` is for a gate where the source is not the whole question - drift
82
88
  * passes its `--selector`, since two selectors on one page are two different runs.
83
89
  */
84
- declare function runOutputDir(gateDir: string, source: string, discriminator?: string): string;
85
- //#endregion
86
- export { firstPositional, firstPositionalOrUndefined, numberList, numberListFloat, optionalInt, runOutputDir, viewportFlag, vlmFlag, withoutOptionalValue };
90
+ export declare function runOutputDir(gateDir: string, source: string, discriminator?: string): string;