@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.
- package/dist/apng.d.mts +42 -0
- package/dist/apng.mjs +199 -0
- package/dist/auth-state.d.mts +14 -3
- package/dist/auth-state.mjs +30 -6
- package/dist/bitmap-font.d.mts +48 -0
- package/dist/bitmap-font.mjs +945 -0
- package/dist/browser-launch.d.mts +65 -0
- package/dist/browser-launch.mjs +194 -0
- package/dist/cli-error.d.mts +73 -1
- package/dist/cli-error.mjs +164 -32
- package/dist/element-compare.mjs +8 -11
- package/dist/filmstrip.d.mts +121 -0
- package/dist/filmstrip.mjs +181 -0
- package/dist/gate-config.d.mts +107 -22
- package/dist/gate-config.mjs +138 -9
- package/dist/heatmap.d.mts +48 -4
- package/dist/heatmap.mjs +157 -12
- package/dist/index.d.mts +6 -4
- package/dist/index.mjs +4 -2
- package/dist/mask.d.mts +66 -2
- package/dist/mask.mjs +91 -4
- package/dist/page-load.d.mts +83 -0
- package/dist/page-load.mjs +116 -0
- package/dist/page-open.d.mts +123 -2
- package/dist/page-open.mjs +176 -6
- package/dist/plugin/args.d.mts +86 -0
- package/dist/plugin/args.mjs +162 -0
- package/dist/plugin/browser.d.mts +6 -0
- package/dist/plugin/browser.mjs +6 -0
- package/dist/plugin/cli-entry.d.mts +11 -0
- package/dist/plugin/cli-entry.mjs +69 -0
- package/dist/plugin/contract.d.mts +270 -0
- package/dist/plugin/contract.mjs +51 -0
- package/dist/plugin/index.d.mts +82 -0
- package/dist/plugin/index.mjs +81 -0
- package/dist/plugin/load.d.mts +36 -0
- package/dist/plugin/load.mjs +98 -0
- package/dist/plugin/registry.d.mts +60 -0
- package/dist/plugin/registry.mjs +160 -0
- package/dist/plugin/rule-tier.d.mts +65 -0
- package/dist/plugin/rule-tier.mjs +77 -0
- package/dist/plugin/rules.d.mts +112 -0
- package/dist/plugin/rules.mjs +188 -0
- package/dist/plugin/runner.d.mts +198 -0
- package/dist/plugin/runner.mjs +440 -0
- package/dist/png-utils.d.mts +31 -1
- package/dist/png-utils.mjs +24 -1
- package/dist/rect-overlap.d.mts +41 -0
- package/dist/rect-overlap.mjs +28 -0
- package/dist/run-ledger.d.mts +56 -2
- package/dist/run-ledger.mjs +102 -11
- package/dist/types.d.mts +60 -1
- package/dist/version.d.mts +20 -0
- package/dist/version.mjs +20 -0
- package/dist/webp.d.mts +31 -0
- package/dist/webp.mjs +105 -0
- package/package.json +17 -3
package/dist/png-utils.mjs
CHANGED
|
@@ -6,6 +6,29 @@ import { readFile, writeFile } from "node:fs/promises";
|
|
|
6
6
|
* Low-level PNG decode/encode using pngjs.
|
|
7
7
|
* Used by heatmap.ts and other modules that need raw pixel data.
|
|
8
8
|
*/
|
|
9
|
+
function measureChangeMagnitude(a, b) {
|
|
10
|
+
const width = Math.min(a.width, b.width);
|
|
11
|
+
const height = Math.min(a.height, b.height);
|
|
12
|
+
let changedPixels = 0;
|
|
13
|
+
let sum = 0;
|
|
14
|
+
let maxChannelDelta = 0;
|
|
15
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
16
|
+
const ia = (y * a.width + x) * 4;
|
|
17
|
+
const ib = (y * b.width + x) * 4;
|
|
18
|
+
const delta = Math.max(Math.abs(a.data[ia] - b.data[ib]), Math.abs(a.data[ia + 1] - b.data[ib + 1]), Math.abs(a.data[ia + 2] - b.data[ib + 2]));
|
|
19
|
+
if (delta > 0) changedPixels += 1;
|
|
20
|
+
if (delta > maxChannelDelta) maxChannelDelta = delta;
|
|
21
|
+
sum += delta;
|
|
22
|
+
}
|
|
23
|
+
const totalPixels = width * height;
|
|
24
|
+
return {
|
|
25
|
+
changedPixels,
|
|
26
|
+
totalPixels,
|
|
27
|
+
changedFraction: totalPixels === 0 ? 0 : changedPixels / totalPixels,
|
|
28
|
+
maxChannelDelta,
|
|
29
|
+
meanChannelDelta: totalPixels === 0 ? 0 : sum / totalPixels
|
|
30
|
+
};
|
|
31
|
+
}
|
|
9
32
|
/**
|
|
10
33
|
* Crop or pad an image to the target dimensions.
|
|
11
34
|
* Only handles the common region; overflow is zero-filled.
|
|
@@ -77,4 +100,4 @@ async function encodePng(path, data) {
|
|
|
77
100
|
await writeFile(path, PNG.sync.write(png));
|
|
78
101
|
}
|
|
79
102
|
//#endregion
|
|
80
|
-
export { cropImage, cropRegion, decodePng, encodePng };
|
|
103
|
+
export { cropImage, cropRegion, decodePng, encodePng, measureChangeMagnitude };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/rect-overlap.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* How much two boxes overlap, in one place.
|
|
4
|
+
*
|
|
5
|
+
* This arithmetic was written out six times across the repo, under five names: `overlapArea`
|
|
6
|
+
* (`semantic-drilldown`), `intersectionArea` (`region-selector-match`), `rectIntersectionArea`
|
|
7
|
+
* (`diff-for-agent`), and `iouOf` twice — once in `component-bbox` and once in `page-compose-diff`,
|
|
8
|
+
* byte-identical apart from the local variable names. It is the shape of defect this repo keeps
|
|
9
|
+
* finding: the same thing in several places, where fixing one leaves the others.
|
|
10
|
+
*
|
|
11
|
+
* Two sites deliberately keep their own copy and are worth naming, so a future sweep does not
|
|
12
|
+
* "collapse" them by mistake:
|
|
13
|
+
*
|
|
14
|
+
* - `copy-check.ts` computes it inside a browser script, which cannot import anything.
|
|
15
|
+
* - `integrity-check.ts` and `font-determinism-probe.ts` need the per-axis overlap (`ox`, `oy`)
|
|
16
|
+
* rather than the area, because they report which axis collided.
|
|
17
|
+
*/
|
|
18
|
+
/** Any box with a top-left origin. `x`/`y`-shaped callers pass `{ left: x, top: y, … }`. */
|
|
19
|
+
interface OverlapBox {
|
|
20
|
+
left: number;
|
|
21
|
+
top: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Area shared by two boxes, and 0 when they do not overlap at all.
|
|
27
|
+
*
|
|
28
|
+
* `Math.max(0, …)` on each axis rather than an early return: boxes that touch along one edge have a
|
|
29
|
+
* zero-width intersection, and multiplying gives 0 without a special case.
|
|
30
|
+
*/
|
|
31
|
+
declare function overlapArea(a: OverlapBox, b: OverlapBox): number;
|
|
32
|
+
/**
|
|
33
|
+
* Intersection over union, the standard box-similarity ratio: 1 for identical boxes, 0 for disjoint.
|
|
34
|
+
*
|
|
35
|
+
* Returns 0 rather than `NaN` when both boxes are empty — the union is then 0, and a division would
|
|
36
|
+
* hand every caller a value that fails every comparison it is put into. `NaN > threshold` is false,
|
|
37
|
+
* so the case would read as "not similar" in some callers and be silently skipped in others.
|
|
38
|
+
*/
|
|
39
|
+
declare function iou(a: OverlapBox, b: OverlapBox): number;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { OverlapBox, iou, overlapArea };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/rect-overlap.ts
|
|
2
|
+
/**
|
|
3
|
+
* Area shared by two boxes, and 0 when they do not overlap at all.
|
|
4
|
+
*
|
|
5
|
+
* `Math.max(0, …)` on each axis rather than an early return: boxes that touch along one edge have a
|
|
6
|
+
* zero-width intersection, and multiplying gives 0 without a special case.
|
|
7
|
+
*/
|
|
8
|
+
function overlapArea(a, b) {
|
|
9
|
+
const left = Math.max(a.left, b.left);
|
|
10
|
+
const top = Math.max(a.top, b.top);
|
|
11
|
+
const right = Math.min(a.left + a.width, b.left + b.width);
|
|
12
|
+
const bottom = Math.min(a.top + a.height, b.top + b.height);
|
|
13
|
+
return Math.max(0, right - left) * Math.max(0, bottom - top);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Intersection over union, the standard box-similarity ratio: 1 for identical boxes, 0 for disjoint.
|
|
17
|
+
*
|
|
18
|
+
* Returns 0 rather than `NaN` when both boxes are empty — the union is then 0, and a division would
|
|
19
|
+
* hand every caller a value that fails every comparison it is put into. `NaN > threshold` is false,
|
|
20
|
+
* so the case would read as "not similar" in some callers and be silently skipped in others.
|
|
21
|
+
*/
|
|
22
|
+
function iou(a, b) {
|
|
23
|
+
const inter = overlapArea(a, b);
|
|
24
|
+
const union = a.width * a.height + b.width * b.height - inter;
|
|
25
|
+
return union > 0 ? inter / union : 0;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { iou, overlapArea };
|
package/dist/run-ledger.d.mts
CHANGED
|
@@ -9,6 +9,60 @@ interface RunLedgerEntry {
|
|
|
9
9
|
/** Headline numbers, tool-specific but flat (matched/missing/extra/status/diffRatio...). */
|
|
10
10
|
headline: Record<string, string | number | boolean | null>;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
/** Default location, relative to the working directory. */
|
|
13
|
+
declare const LEDGER_RELATIVE_PATH: string;
|
|
14
|
+
/**
|
|
15
|
+
* The directories a vlmkit run creates under the working directory. Exported so
|
|
16
|
+
* `gates init` can write them into `.gitignore` and the runner can name them in
|
|
17
|
+
* the first-write notice — one list, so the two cannot disagree.
|
|
18
|
+
*
|
|
19
|
+
* v6's adopting agent had to discover both with `ls` and write the `.gitignore`
|
|
20
|
+
* itself: "adopting the tool dirtied the repo silently."
|
|
21
|
+
*/
|
|
22
|
+
declare const VLMKIT_IGNORE_ENTRIES: readonly [".vlmkit/", "test-results/"];
|
|
23
|
+
interface LedgerWrite {
|
|
24
|
+
/** Absolute path appended to. */
|
|
25
|
+
path: string;
|
|
26
|
+
/** True when this call brought the file into existence. */
|
|
27
|
+
created: boolean;
|
|
28
|
+
}
|
|
29
|
+
interface AppendRunLedgerOptions {
|
|
30
|
+
cwd?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Explicit target from `--ledger <path>`. A directory-less path is still
|
|
33
|
+
* resolved against `cwd`, so `--ledger runs.jsonl` lands where the user is.
|
|
34
|
+
*/
|
|
35
|
+
path?: string;
|
|
36
|
+
/** `--no-ledger`. Checked here as well as at the call site so both paths agree. */
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Replace the run-level settings. Called once per run; resets the first-write record. */
|
|
40
|
+
declare function configureRunLedger(options?: AppendRunLedgerOptions): void;
|
|
41
|
+
/**
|
|
42
|
+
* The append that brought the ledger into existence this run, if any.
|
|
43
|
+
*
|
|
44
|
+
* Reported by whoever prints, so a gate that writes from inside its measurement
|
|
45
|
+
* gets the same announcement as one using the `gate.ledger` hook.
|
|
46
|
+
*/
|
|
47
|
+
declare function firstLedgerWrite(): LedgerWrite | null;
|
|
48
|
+
/**
|
|
49
|
+
* Append one entry. Returns what was written, or `null` when the ledger is off
|
|
50
|
+
* or the write failed — the caller uses that to announce a first write rather
|
|
51
|
+
* than to decide anything.
|
|
52
|
+
*/
|
|
53
|
+
declare function appendRunLedger(entry: RunLedgerEntry, options?: AppendRunLedgerOptions | string): LedgerWrite | null;
|
|
54
|
+
/**
|
|
55
|
+
* Is `target` already covered by the working directory's `.gitignore`?
|
|
56
|
+
*
|
|
57
|
+
* A deliberately shallow read: the top-level `.gitignore` only, matching on the
|
|
58
|
+
* literal entry. Shelling out to `git check-ignore` would be exact and would
|
|
59
|
+
* also mean spawning a process on a path taken once per fresh checkout. The one
|
|
60
|
+
* failure mode of guessing wrong is one extra advisory line, so the cheap check
|
|
61
|
+
* is the right trade — but it must not guess wrong in the *other* direction,
|
|
62
|
+
* which is why anything unreadable counts as "not ignored" rather than ignored.
|
|
63
|
+
*/
|
|
64
|
+
declare function isGitIgnored(cwd: string, target: string): boolean;
|
|
65
|
+
/** Is this working directory a git repo at all? Nothing to advise if it is not. */
|
|
66
|
+
declare function isGitRepo(cwd: string): boolean;
|
|
13
67
|
//#endregion
|
|
14
|
-
export { RunLedgerEntry, appendRunLedger };
|
|
68
|
+
export { AppendRunLedgerOptions, LEDGER_RELATIVE_PATH, LedgerWrite, RunLedgerEntry, VLMKIT_IGNORE_ENTRIES, appendRunLedger, configureRunLedger, firstLedgerWrite, isGitIgnored, isGitRepo };
|
package/dist/run-ledger.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
3
3
|
//#region src/run-ledger.ts
|
|
4
4
|
/**
|
|
5
5
|
* Append-only run ledger for agent-loop tools.
|
|
@@ -13,19 +13,110 @@ import { join } from "node:path";
|
|
|
13
13
|
* counts were self-reported and unreliable in 5/5 S5 runs).
|
|
14
14
|
*
|
|
15
15
|
* Writes are best-effort: a ledger failure must never break the tool run.
|
|
16
|
-
*
|
|
16
|
+
* Relocate with `--ledger <path>`, turn it off with `--no-ledger` or
|
|
17
|
+
* VLMKIT_NO_LEDGER=1 (e.g. CI bulk runs).
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/** Default location, relative to the working directory. */
|
|
20
|
+
const LEDGER_RELATIVE_PATH = join(".vlmkit", "run-ledger.jsonl");
|
|
21
|
+
/**
|
|
22
|
+
* The directories a vlmkit run creates under the working directory. Exported so
|
|
23
|
+
* `gates init` can write them into `.gitignore` and the runner can name them in
|
|
24
|
+
* the first-write notice — one list, so the two cannot disagree.
|
|
25
|
+
*
|
|
26
|
+
* v6's adopting agent had to discover both with `ls` and write the `.gitignore`
|
|
27
|
+
* itself: "adopting the tool dirtied the repo silently."
|
|
28
|
+
*/
|
|
29
|
+
const VLMKIT_IGNORE_ENTRIES = [".vlmkit/", "test-results/"];
|
|
30
|
+
/**
|
|
31
|
+
* Run-level ledger settings, set once per process.
|
|
32
|
+
*
|
|
33
|
+
* This is here rather than threaded through the callers because the runner's
|
|
34
|
+
* `gate.ledger` hook is NOT the only writer: sixteen call sites append directly
|
|
35
|
+
* from inside measurement functions (`runDesignPolicyCheck`, `snapshot`,
|
|
36
|
+
* `markup-verify`, ...). `--ledger` and `--no-ledger` implemented at the runner
|
|
37
|
+
* alone would have silently missed fourteen of them — the same shape as the
|
|
38
|
+
* `--wait-until` bug earlier this cycle, where three of 42 `.goto(` sites
|
|
39
|
+
* hand-rolled their options and fixing `navigatePage` changed nothing.
|
|
40
|
+
*
|
|
41
|
+
* A module-level setting is the choke point that covers all of them, and the
|
|
42
|
+
* ledger is already a process-wide side effect configured by a process-wide
|
|
43
|
+
* signal (`VLMKIT_NO_LEDGER`).
|
|
44
|
+
*/
|
|
45
|
+
let runConfig = {};
|
|
46
|
+
let firstWrite = null;
|
|
47
|
+
/** Replace the run-level settings. Called once per run; resets the first-write record. */
|
|
48
|
+
function configureRunLedger(options = {}) {
|
|
49
|
+
runConfig = { ...options };
|
|
50
|
+
firstWrite = null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The append that brought the ledger into existence this run, if any.
|
|
54
|
+
*
|
|
55
|
+
* Reported by whoever prints, so a gate that writes from inside its measurement
|
|
56
|
+
* gets the same announcement as one using the `gate.ledger` hook.
|
|
57
|
+
*/
|
|
58
|
+
function firstLedgerWrite() {
|
|
59
|
+
return firstWrite;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Append one entry. Returns what was written, or `null` when the ledger is off
|
|
63
|
+
* or the write failed — the caller uses that to announce a first write rather
|
|
64
|
+
* than to decide anything.
|
|
65
|
+
*/
|
|
66
|
+
function appendRunLedger(entry, options = {}) {
|
|
67
|
+
const explicit = typeof options === "string" ? { cwd: options } : options;
|
|
68
|
+
const opts = {
|
|
69
|
+
...runConfig,
|
|
70
|
+
...explicit
|
|
71
|
+
};
|
|
72
|
+
if (opts.disabled || runConfig.disabled || process.env.VLMKIT_NO_LEDGER === "1") return null;
|
|
73
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
74
|
+
const target = opts.path ? resolve(cwd, opts.path) : resolve(cwd, LEDGER_RELATIVE_PATH);
|
|
20
75
|
try {
|
|
21
|
-
const
|
|
22
|
-
mkdirSync(
|
|
23
|
-
|
|
76
|
+
const created = !existsSync(target);
|
|
77
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
78
|
+
appendFileSync(target, JSON.stringify({
|
|
24
79
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
25
80
|
...entry
|
|
81
|
+
}) + "\n");
|
|
82
|
+
const write = {
|
|
83
|
+
path: target,
|
|
84
|
+
created
|
|
85
|
+
};
|
|
86
|
+
if (created && !firstWrite) firstWrite = write;
|
|
87
|
+
return write;
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Is `target` already covered by the working directory's `.gitignore`?
|
|
94
|
+
*
|
|
95
|
+
* A deliberately shallow read: the top-level `.gitignore` only, matching on the
|
|
96
|
+
* literal entry. Shelling out to `git check-ignore` would be exact and would
|
|
97
|
+
* also mean spawning a process on a path taken once per fresh checkout. The one
|
|
98
|
+
* failure mode of guessing wrong is one extra advisory line, so the cheap check
|
|
99
|
+
* is the right trade — but it must not guess wrong in the *other* direction,
|
|
100
|
+
* which is why anything unreadable counts as "not ignored" rather than ignored.
|
|
101
|
+
*/
|
|
102
|
+
function isGitIgnored(cwd, target) {
|
|
103
|
+
const rel = relative(cwd, target).split("\\").join("/");
|
|
104
|
+
if (!rel || rel.startsWith("..")) return true;
|
|
105
|
+
try {
|
|
106
|
+
const lines = readFileSync(join(cwd, ".gitignore"), "utf8").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
|
|
107
|
+
const segments = rel.split("/");
|
|
108
|
+
return lines.some((line) => {
|
|
109
|
+
const bare = line.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
110
|
+
if (!bare) return false;
|
|
111
|
+
return bare === rel || segments.includes(bare) || rel.startsWith(bare + "/");
|
|
26
112
|
});
|
|
27
|
-
|
|
28
|
-
|
|
113
|
+
} catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Is this working directory a git repo at all? Nothing to advise if it is not. */
|
|
118
|
+
function isGitRepo(cwd) {
|
|
119
|
+
return existsSync(join(cwd, ".git"));
|
|
29
120
|
}
|
|
30
121
|
//#endregion
|
|
31
|
-
export { appendRunLedger };
|
|
122
|
+
export { LEDGER_RELATIVE_PATH, VLMKIT_IGNORE_ENTRIES, appendRunLedger, configureRunLedger, firstLedgerWrite, isGitIgnored, isGitRepo };
|
package/dist/types.d.mts
CHANGED
|
@@ -54,10 +54,57 @@ interface VrtSnapshot {
|
|
|
54
54
|
interface VrtDiff {
|
|
55
55
|
snapshot: VrtSnapshot;
|
|
56
56
|
diffPixels: number;
|
|
57
|
+
/**
|
|
58
|
+
* The `diffRatio` denominator: pixels that were actually measured. Equals the
|
|
59
|
+
* compared image area unless `mask` is present, in which case the ignored
|
|
60
|
+
* pixels are subtracted. See `DiffMaskSummary` for why.
|
|
61
|
+
*/
|
|
57
62
|
totalPixels: number;
|
|
58
63
|
diffRatio: number;
|
|
59
64
|
heatmapPath?: string;
|
|
60
65
|
regions: DiffRegion[];
|
|
66
|
+
/** Present only when the caller passed ignore regions. */
|
|
67
|
+
mask?: DiffMaskSummary;
|
|
68
|
+
}
|
|
69
|
+
/** A rectangle the caller declared permanently non-deterministic. */
|
|
70
|
+
interface DiffIgnoreRegion {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
}
|
|
76
|
+
interface DiffIgnoredRegionReport extends DiffIgnoreRegion {
|
|
77
|
+
/**
|
|
78
|
+
* Pixels this rect actually covered inside the compared area — less than
|
|
79
|
+
* `width * height` when the rect hangs off the edge, and 0 when it misses the
|
|
80
|
+
* frame entirely (a typo'd mask that silences nothing should be visible, not
|
|
81
|
+
* inferred).
|
|
82
|
+
*/
|
|
83
|
+
pixels: number;
|
|
84
|
+
/**
|
|
85
|
+
* Diff pixels that fell inside this rect and were discarded. This is the
|
|
86
|
+
* number that says how much the mask is doing: 0 means it changed nothing.
|
|
87
|
+
* Per-rect counts double-count where rects overlap; `ignoredDiffPixels` is
|
|
88
|
+
* the de-duplicated total.
|
|
89
|
+
*/
|
|
90
|
+
diffPixels: number;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What a set of ignore regions removed from the measurement.
|
|
94
|
+
*
|
|
95
|
+
* Always reported alongside the verdict, never only in `--json`: the failure
|
|
96
|
+
* mode of this feature is a mask over half the frame and a gate that then says
|
|
97
|
+
* 0.1%. `imagePixels - ignoredPixels === totalPixels` is the arithmetic a
|
|
98
|
+
* reader can check.
|
|
99
|
+
*/
|
|
100
|
+
interface DiffMaskSummary {
|
|
101
|
+
regions: DiffIgnoredRegionReport[];
|
|
102
|
+
/** De-duplicated count of pixels inside at least one ignore region. */
|
|
103
|
+
ignoredPixels: number;
|
|
104
|
+
/** De-duplicated count of *differing* pixels that were discarded. */
|
|
105
|
+
ignoredDiffPixels: number;
|
|
106
|
+
/** The compared area before masking (excludes size-mismatch overflow). */
|
|
107
|
+
imagePixels: number;
|
|
61
108
|
}
|
|
62
109
|
type DiffRegionType = "shift" | "content" | "edge";
|
|
63
110
|
interface DiffRegion {
|
|
@@ -87,6 +134,15 @@ interface DiffRegionSelectorCandidate {
|
|
|
87
134
|
tag: string;
|
|
88
135
|
regionCoverage: number;
|
|
89
136
|
elementCoverage: number;
|
|
137
|
+
/**
|
|
138
|
+
* Runners-up, best first — present only when more than one candidate was requested
|
|
139
|
+
* (`diff png --elements-top N`), so the default JSON shape is unchanged.
|
|
140
|
+
*
|
|
141
|
+
* Attribution picks one element out of several overlapping ones, and when it picks
|
|
142
|
+
* wrong the alternatives are what a reader needs; without them the report asserts a
|
|
143
|
+
* cause with no way to see what it beat.
|
|
144
|
+
*/
|
|
145
|
+
alternates?: Omit<DiffRegionSelectorCandidate, "alternates">[];
|
|
90
146
|
}
|
|
91
147
|
interface DiffRegionColor {
|
|
92
148
|
r: number;
|
|
@@ -119,9 +175,12 @@ interface ShiftRegion {
|
|
|
119
175
|
}
|
|
120
176
|
interface DiffReport {
|
|
121
177
|
diffPixels: number;
|
|
178
|
+
/** Measured pixels — see `VrtDiff.totalPixels`. */
|
|
122
179
|
totalPixels: number;
|
|
123
180
|
diffRatio: number;
|
|
124
181
|
regions: DiffRegion[];
|
|
182
|
+
/** Present only when the caller passed ignore regions. */
|
|
183
|
+
mask?: DiffMaskSummary;
|
|
125
184
|
shiftOnly: boolean;
|
|
126
185
|
contentChangeCount: number;
|
|
127
186
|
globalShift: number;
|
|
@@ -412,4 +471,4 @@ interface HtmlSource {
|
|
|
412
471
|
label?: string;
|
|
413
472
|
}
|
|
414
473
|
//#endregion
|
|
415
|
-
export { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionSelectorCandidate, DiffRegionShift, DiffRegionType, DiffReport, DiffSemantics, ExpectedA11yChange, FileChange, HtmlSource, IntrospectResult, Language, LoopScore, NlAssertion, PageExpectation, PageIntrospection, PageSpec, PlaywrightReport, ProjectConfig, QualityCheckResult, QualityCheckType, ScoreDetail, ShiftRegion, SpecCheckType, SpecInvariant, TestAttempt, TestError, TestResult, TestSpec, TestSuite, UiSpec, UnifiedAgentContext, VisualChangeType, VisualExpectation, VisualSemanticChange, VisualSemanticDiff, VrtDiff, VrtExpectation, VrtSnapshot, VrtVerdict };
|
|
474
|
+
export { A11yChange, A11yChangeType, A11yDiff, A11yExpectation, A11yNode, A11ySnapshot, AffectedComponent, AgentContext, Attachment, ChangeIntent, CrossValidationResult, DepEdge, DepGraph, DepNode, DiffHunk, DiffIgnoreRegion, DiffIgnoredRegionReport, DiffMaskSummary, DiffRegion, DiffRegionColor, DiffRegionColorPair, DiffRegionColorSample, DiffRegionSelectorCandidate, DiffRegionShift, DiffRegionType, DiffReport, DiffSemantics, ExpectedA11yChange, FileChange, HtmlSource, IntrospectResult, Language, LoopScore, NlAssertion, PageExpectation, PageIntrospection, PageSpec, PlaywrightReport, ProjectConfig, QualityCheckResult, QualityCheckType, ScoreDetail, ShiftRegion, SpecCheckType, SpecInvariant, TestAttempt, TestError, TestResult, TestSpec, TestSuite, UiSpec, UnifiedAgentContext, VisualChangeType, VisualExpectation, VisualSemanticChange, VisualSemanticDiff, VrtDiff, VrtExpectation, VrtSnapshot, VrtVerdict };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/version.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one place the shipped version number is written.
|
|
4
|
+
*
|
|
5
|
+
* It was written in three: this number, `cli.version(...)` in `src/cli/cli.ts`, and the MCP
|
|
6
|
+
* server's `{ name: "vlmkit", version }` handshake. `src/cli/version.test.ts` already caught the
|
|
7
|
+
* drift — it compares every copy against the root manifest — but catching it is not the same as not
|
|
8
|
+
* having it: the 0.11.0 bump failed that test twice and needed three files edited to go green, and
|
|
9
|
+
* the number two independent parties use to identify a build (`--version` in a bug report, the
|
|
10
|
+
* handshake in an MCP client's log) should not depend on remembering the third file.
|
|
11
|
+
*
|
|
12
|
+
* This is a literal rather than a `package.json` read on purpose. The CLI is bundled to
|
|
13
|
+
* `dist/*.mjs` and a manifest read resolves relative to the *bundle*, not the source — the reason
|
|
14
|
+
* it was hardcoded to begin with. `src/cli/version.test.ts` still asserts this constant matches
|
|
15
|
+
* every `package.json` and that the CHANGELOG has a section for it, so the literal cannot drift
|
|
16
|
+
* from the release either.
|
|
17
|
+
*/
|
|
18
|
+
declare const VLMKIT_VERSION = "0.11.1";
|
|
19
|
+
//#endregion
|
|
20
|
+
export { VLMKIT_VERSION };
|
package/dist/version.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/version.ts
|
|
2
|
+
/**
|
|
3
|
+
* The one place the shipped version number is written.
|
|
4
|
+
*
|
|
5
|
+
* It was written in three: this number, `cli.version(...)` in `src/cli/cli.ts`, and the MCP
|
|
6
|
+
* server's `{ name: "vlmkit", version }` handshake. `src/cli/version.test.ts` already caught the
|
|
7
|
+
* drift — it compares every copy against the root manifest — but catching it is not the same as not
|
|
8
|
+
* having it: the 0.11.0 bump failed that test twice and needed three files edited to go green, and
|
|
9
|
+
* the number two independent parties use to identify a build (`--version` in a bug report, the
|
|
10
|
+
* handshake in an MCP client's log) should not depend on remembering the third file.
|
|
11
|
+
*
|
|
12
|
+
* This is a literal rather than a `package.json` read on purpose. The CLI is bundled to
|
|
13
|
+
* `dist/*.mjs` and a manifest read resolves relative to the *bundle*, not the source — the reason
|
|
14
|
+
* it was hardcoded to begin with. `src/cli/version.test.ts` still asserts this constant matches
|
|
15
|
+
* every `package.json` and that the CHANGELOG has a section for it, so the literal cannot drift
|
|
16
|
+
* from the release either.
|
|
17
|
+
*/
|
|
18
|
+
const VLMKIT_VERSION = "0.11.1";
|
|
19
|
+
//#endregion
|
|
20
|
+
export { VLMKIT_VERSION };
|
package/dist/webp.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PngData } from "./png-utils.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/webp.d.ts
|
|
4
|
+
declare const WEBP_ENCODER_PACKAGE = "@jsquash/webp";
|
|
5
|
+
interface WebpEncodeOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Lossy quality 0-100. Omit for lossless, which is both smaller and
|
|
8
|
+
* artifact-free on UI screenshots — see the header.
|
|
9
|
+
*/
|
|
10
|
+
quality?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* One sentence naming what is missing and how to get it, in the shape
|
|
14
|
+
* `cli-error.ts` uses for the Playwright diagnoses: the caller asked for webp
|
|
15
|
+
* explicitly, so "not installed" is the whole answer and a stack adds nothing.
|
|
16
|
+
*/
|
|
17
|
+
declare function formatMissingWebpEncoderError(error?: unknown): string;
|
|
18
|
+
declare class WebpEncoderMissingError extends Error {
|
|
19
|
+
readonly name = "WebpEncoderMissingError";
|
|
20
|
+
}
|
|
21
|
+
/** Is the optional encoder installed? For a caller that wants to offer the flag. */
|
|
22
|
+
declare function webpEncoderAvailable(): Promise<boolean>;
|
|
23
|
+
declare function encodeWebp(image: PngData, options?: WebpEncodeOptions): Promise<Uint8Array>;
|
|
24
|
+
/**
|
|
25
|
+
* Which format a path asks for. Extension-driven so `--out strip.webp` needs no
|
|
26
|
+
* second flag, and an unknown extension is PNG rather than an error — the caller
|
|
27
|
+
* asked for a file, not for a format quiz.
|
|
28
|
+
*/
|
|
29
|
+
declare function imageFormatForPath(path: string): "png" | "webp";
|
|
30
|
+
//#endregion
|
|
31
|
+
export { WEBP_ENCODER_PACKAGE, WebpEncodeOptions, WebpEncoderMissingError, encodeWebp, formatMissingWebpEncoderError, imageFormatForPath, webpEncoderAvailable };
|
package/dist/webp.mjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
//#region src/webp.ts
|
|
4
|
+
/**
|
|
5
|
+
* Lossless WebP encoding for the strip/sheet outputs, via libwebp compiled to
|
|
6
|
+
* WASM (`@jsquash/webp`).
|
|
7
|
+
*
|
|
8
|
+
* Chosen against two alternatives, measured on the real strips this repo writes
|
|
9
|
+
* (`check animation --strip` on `fixtures/css-challenge/dashboard.html`, a
|
|
10
|
+
* 1526x492 sheet, and an uncapped 2-up full-viewport sheet at 2584x736):
|
|
11
|
+
*
|
|
12
|
+
* encoder 106.8 KB PNG 165.3 KB PNG install
|
|
13
|
+
* @jsquash/webp lossless 24.0 KB 39.3 KB 1.1 MB (pure WASM)
|
|
14
|
+
* sharp lossless 24.0 KB 38.9 KB 29 MB (libvips 18 MB
|
|
15
|
+
* + a wasm32 fallback)
|
|
16
|
+
* mizchi/image (MoonBit) 701.6 KB 1748.1 KB none (no npm dep)
|
|
17
|
+
*
|
|
18
|
+
* Identical bytes from the two libwebp bindings, 26x apart on install weight, so
|
|
19
|
+
* the WASM one wins. `mizchi/image` 0.4.3 was the appealing option — it would have
|
|
20
|
+
* added no npm dependency at all and fits this repo's MoonBit boundary — but its
|
|
21
|
+
* `encode_webp` emits a valid VP8L stream (verified: decodes to 1526x492 in
|
|
22
|
+
* Chromium) that is **6.6x larger than the PNG it replaces**, i.e. 29x libwebp.
|
|
23
|
+
* It is a correct minimal encoder, not a competitive one.
|
|
24
|
+
*
|
|
25
|
+
* Lossless rather than lossy, and not out of caution: on flat UI screenshots
|
|
26
|
+
* lossless measured *smaller* than quality 90 (24.0 KB against 55.9 KB), because
|
|
27
|
+
* lossy first adds noise it then has to encode. So there is no size-for-fidelity
|
|
28
|
+
* trade to make here — the artifact-free choice is also the small one. `quality`
|
|
29
|
+
* is still exposed for callers with photographic content.
|
|
30
|
+
*
|
|
31
|
+
* An **optional peer**, so `npx vlmkit` stays a PNG-only install and nobody pays
|
|
32
|
+
* 1.1 MB for a format they did not ask for.
|
|
33
|
+
*/
|
|
34
|
+
const WEBP_ENCODER_PACKAGE = "@jsquash/webp";
|
|
35
|
+
/**
|
|
36
|
+
* One sentence naming what is missing and how to get it, in the shape
|
|
37
|
+
* `cli-error.ts` uses for the Playwright diagnoses: the caller asked for webp
|
|
38
|
+
* explicitly, so "not installed" is the whole answer and a stack adds nothing.
|
|
39
|
+
*/
|
|
40
|
+
function formatMissingWebpEncoderError(error) {
|
|
41
|
+
return `error: WebP output needs the optional \`${WEBP_ENCODER_PACKAGE}\` package.\n run: npm install --save-dev ${WEBP_ENCODER_PACKAGE}\n or write a .png instead — PNG needs no extra dependency.${error === void 0 ? "" : `\n (${String(error?.message ?? error).split("\n")[0]})`}`;
|
|
42
|
+
}
|
|
43
|
+
var WebpEncoderMissingError = class extends Error {
|
|
44
|
+
name = "WebpEncoderMissingError";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* `@jsquash/webp` locates its `.wasm` with `fetch()`, which Node's undici refuses
|
|
48
|
+
* for a `file://` URL — "not implemented... yet...". So the module is compiled
|
|
49
|
+
* here and handed in through the package's own `init`.
|
|
50
|
+
*
|
|
51
|
+
* Resolved with `createRequire(import.meta.url)` rather than a relative path,
|
|
52
|
+
* for the same reason `cli-error.ts` resolves Playwright that way: this module
|
|
53
|
+
* gets bundled into a hashed chunk in the shipped CLI, and only a package
|
|
54
|
+
* resolution survives that.
|
|
55
|
+
*/
|
|
56
|
+
let encoderPromise = null;
|
|
57
|
+
async function loadEncoder() {
|
|
58
|
+
if (encoderPromise) return encoderPromise;
|
|
59
|
+
encoderPromise = (async () => {
|
|
60
|
+
const require = createRequire(import.meta.url);
|
|
61
|
+
let mod;
|
|
62
|
+
try {
|
|
63
|
+
mod = await import(`${WEBP_ENCODER_PACKAGE}/encode.js`);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new WebpEncoderMissingError(formatMissingWebpEncoderError(error));
|
|
66
|
+
}
|
|
67
|
+
let wasmPath;
|
|
68
|
+
try {
|
|
69
|
+
wasmPath = require.resolve(`${WEBP_ENCODER_PACKAGE}/codec/enc/webp_enc_simd.wasm`);
|
|
70
|
+
} catch {
|
|
71
|
+
wasmPath = require.resolve(`${WEBP_ENCODER_PACKAGE}/codec/enc/webp_enc.wasm`);
|
|
72
|
+
}
|
|
73
|
+
await mod.init(await WebAssembly.compile(await readFile(wasmPath)));
|
|
74
|
+
return mod.default;
|
|
75
|
+
})();
|
|
76
|
+
return encoderPromise;
|
|
77
|
+
}
|
|
78
|
+
/** Is the optional encoder installed? For a caller that wants to offer the flag. */
|
|
79
|
+
async function webpEncoderAvailable() {
|
|
80
|
+
try {
|
|
81
|
+
await loadEncoder();
|
|
82
|
+
return true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function encodeWebp(image, options = {}) {
|
|
88
|
+
const buffer = await (await loadEncoder())({
|
|
89
|
+
data: new Uint8ClampedArray(image.data.buffer, image.data.byteOffset, image.data.byteLength),
|
|
90
|
+
width: image.width,
|
|
91
|
+
height: image.height,
|
|
92
|
+
colorSpace: "srgb"
|
|
93
|
+
}, options.quality === void 0 ? { lossless: 1 } : { quality: options.quality });
|
|
94
|
+
return new Uint8Array(buffer);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Which format a path asks for. Extension-driven so `--out strip.webp` needs no
|
|
98
|
+
* second flag, and an unknown extension is PNG rather than an error — the caller
|
|
99
|
+
* asked for a file, not for a format quiz.
|
|
100
|
+
*/
|
|
101
|
+
function imageFormatForPath(path) {
|
|
102
|
+
return /\.webp$/i.test(path) ? "webp" : "png";
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { WEBP_ENCODER_PACKAGE, WebpEncoderMissingError, encodeWebp, formatMissingWebpEncoderError, imageFormatForPath, webpEncoderAvailable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mizchi/vlmkit-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "VRT diff engine + shared types — pure image / DOM / a11y / visual comparison primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "mizchi",
|
|
@@ -30,6 +30,14 @@
|
|
|
30
30
|
"types": "./dist/index.d.mts",
|
|
31
31
|
"import": "./dist/index.mjs"
|
|
32
32
|
},
|
|
33
|
+
"./plugin": {
|
|
34
|
+
"types": "./dist/plugin/index.d.mts",
|
|
35
|
+
"import": "./dist/plugin/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./plugin/browser": {
|
|
38
|
+
"types": "./dist/plugin/browser.d.mts",
|
|
39
|
+
"import": "./dist/plugin/browser.mjs"
|
|
40
|
+
},
|
|
33
41
|
"./*.ts": {
|
|
34
42
|
"types": "./dist/*.d.mts",
|
|
35
43
|
"import": "./dist/*.mjs"
|
|
@@ -40,10 +48,16 @@
|
|
|
40
48
|
"pngjs": "^7.0.0"
|
|
41
49
|
},
|
|
42
50
|
"peerDependencies": {
|
|
43
|
-
"playwright": ">=1.61 <2"
|
|
51
|
+
"playwright": ">=1.61 <2",
|
|
52
|
+
"@jsquash/webp": "^1"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"@jsquash/webp": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
44
58
|
},
|
|
45
59
|
"scripts": {
|
|
46
60
|
"build": "pnpm --dir ../.. exec tsdown --config tsdown.packages.config.ts --filter @mizchi/vlmkit-core",
|
|
47
|
-
"test": "
|
|
61
|
+
"test": "pnpm --dir ../.. exec vitest run packages/vlmkit-core/src"
|
|
48
62
|
}
|
|
49
63
|
}
|