@mizchi/vlmkit-core 0.23.2 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a11y-semantic.d.mts +7 -9
- package/dist/a11y-semantic.mjs +2 -2
- package/dist/animated-image.d.mts +29 -0
- package/dist/animated-image.mjs +113 -0
- package/dist/apng.d.mts +6 -8
- package/dist/apng.mjs +5 -5
- package/dist/arg-reader.d.mts +10 -11
- package/dist/auth-state.d.mts +7 -8
- package/dist/authored-style-capture.d.mts +8 -9
- package/dist/authored-style-diff.d.mts +7 -9
- package/dist/bitmap-font.d.mts +8 -9
- package/dist/browser-launch.d.mts +8 -10
- package/dist/cli-args.d.mts +9 -10
- package/dist/cli-error.d.mts +10 -11
- package/dist/cli-error.mjs +1 -1
- package/dist/computed-style-capture.d.mts +21 -22
- package/dist/computed-style-capture.mjs +3 -3
- package/dist/computed-style-diff.d.mts +8 -9
- package/dist/computed-style-diff.mjs +1 -1
- package/dist/diff-regions.d.mts +4 -6
- package/dist/dom-equivalence.d.mts +6 -7
- package/dist/dom-position-styles.d.mts +15 -14
- package/dist/dom-position-styles.mjs +3 -3
- package/dist/element-compare.d.mts +9 -8
- package/dist/element-compare.mjs +3 -2
- package/dist/filmstrip.d.mts +61 -8
- package/dist/filmstrip.mjs +82 -10
- package/dist/gate-config.d.mts +19 -21
- package/dist/gate-exit.d.mts +6 -7
- package/dist/gif.d.mts +43 -0
- package/dist/gif.mjs +74 -0
- package/dist/heatmap-regions.d.mts +5 -6
- package/dist/heatmap.d.mts +21 -15
- package/dist/heatmap.mjs +11 -3
- package/dist/image-resize.d.mts +9 -10
- package/dist/image-timing.d.mts +59 -0
- package/dist/image-timing.mjs +167 -0
- package/dist/index.d.mts +2 -2
- package/dist/mask.d.mts +6 -8
- package/dist/navigation-redirect.d.mts +2 -3
- package/dist/page-load.d.mts +12 -13
- package/dist/page-open.d.mts +12 -14
- package/dist/plugin/args.d.mts +17 -11
- package/dist/plugin/args.mjs +12 -1
- package/dist/plugin/cli-entry.d.mts +2 -3
- package/dist/plugin/contract.d.mts +18 -20
- package/dist/plugin/index.d.mts +3 -4
- package/dist/plugin/index.mjs +2 -2
- package/dist/plugin/load.d.mts +7 -9
- package/dist/plugin/registry.d.mts +9 -11
- package/dist/plugin/rule-prose.d.mts +5 -7
- package/dist/plugin/rule-tier.d.mts +8 -10
- package/dist/plugin/rules.d.mts +19 -21
- package/dist/plugin/runner.d.mts +19 -20
- package/dist/plugin/runner.mjs +43 -2
- package/dist/png-decode.d.mts +19 -0
- package/dist/png-decode.mjs +161 -0
- package/dist/png-utils.d.mts +8 -9
- package/dist/png-utils.mjs +2 -1
- package/dist/project-config.d.mts +8 -9
- package/dist/rect-overlap.d.mts +4 -5
- package/dist/region-shift.d.mts +3 -5
- package/dist/run-ledger.d.mts +11 -12
- package/dist/run-ledger.mjs +3 -2
- package/dist/stable-selector.d.mts +2 -3
- package/dist/terminal-colors.d.mts +9 -10
- package/dist/text-rows.d.mts +11 -12
- package/dist/types.d.mts +87 -62
- package/dist/version.d.mts +2 -3
- package/dist/version.mjs +1 -1
- package/dist/video-decode.d.mts +146 -0
- package/dist/video-decode.mjs +936 -0
- package/dist/video-frames.d.mts +306 -0
- package/dist/video-frames.mjs +565 -0
- package/dist/webp.d.mts +8 -10
- package/dist/webp.mjs +2 -1
- package/package.json +4 -4
package/dist/gate-config.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RuleSettingEntry, RuleSettings } from "./plugin/rules.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/gate-config.d.ts
|
|
4
|
-
interface GateSuppression {
|
|
3
|
+
export interface GateSuppression {
|
|
5
4
|
/**
|
|
6
5
|
* Gate this applies to, as a prefix of the gate command: `check copy`
|
|
7
6
|
* matches `check copy --manifest x.txt`.
|
|
@@ -16,7 +15,7 @@ interface GateSuppression {
|
|
|
16
15
|
/** `YYYY-MM-DD`. Omitted means permanent, which the inventory counts separately. */
|
|
17
16
|
expires?: string;
|
|
18
17
|
}
|
|
19
|
-
interface GatePage {
|
|
18
|
+
export interface GatePage {
|
|
20
19
|
/** Short stable name for `--only` and reports. Defaults to the source. */
|
|
21
20
|
id?: string;
|
|
22
21
|
/** File path, glob, or URL handed to each gate. */
|
|
@@ -55,7 +54,7 @@ interface GatePage {
|
|
|
55
54
|
* Named and shaped after Playwright's on purpose. A team that has written one
|
|
56
55
|
* should not have to learn a second vocabulary to write this one.
|
|
57
56
|
*/
|
|
58
|
-
interface GateWebServer {
|
|
57
|
+
export interface GateWebServer {
|
|
59
58
|
/** Shell command that starts the server. */
|
|
60
59
|
command: string;
|
|
61
60
|
/**
|
|
@@ -79,7 +78,7 @@ interface GateWebServer {
|
|
|
79
78
|
/** Extra environment for the server process, on top of the current one. */
|
|
80
79
|
env?: Readonly<Record<string, string>>;
|
|
81
80
|
}
|
|
82
|
-
interface GateConfig {
|
|
81
|
+
export interface GateConfig {
|
|
83
82
|
webServer?: GateWebServer;
|
|
84
83
|
defaults?: {
|
|
85
84
|
gates?: string[];
|
|
@@ -89,7 +88,7 @@ interface GateConfig {
|
|
|
89
88
|
};
|
|
90
89
|
pages: GatePage[];
|
|
91
90
|
}
|
|
92
|
-
interface ResolvedSuppression extends GateSuppression {
|
|
91
|
+
export interface ResolvedSuppression extends GateSuppression {
|
|
93
92
|
/** Page id this came from, or `defaults`. */
|
|
94
93
|
scope: string;
|
|
95
94
|
status: "active" | "expired" | "permanent";
|
|
@@ -109,7 +108,7 @@ interface ResolvedSuppression extends GateSuppression {
|
|
|
109
108
|
/** Rule reference, for `kind: "rule"` only. */
|
|
110
109
|
ref?: string;
|
|
111
110
|
}
|
|
112
|
-
interface GateJob {
|
|
111
|
+
export interface GateJob {
|
|
113
112
|
pageId: string;
|
|
114
113
|
source: string;
|
|
115
114
|
/** Gate command with active suppression flags and rule settings appended. */
|
|
@@ -120,7 +119,7 @@ interface GateJob {
|
|
|
120
119
|
/** Rule settings in effect, defaults merged with the page's. */
|
|
121
120
|
rules: RuleSettings;
|
|
122
121
|
}
|
|
123
|
-
interface GatePlan {
|
|
122
|
+
export interface GatePlan {
|
|
124
123
|
jobs: GateJob[];
|
|
125
124
|
/** Every suppression the config declares, resolved against `now`. */
|
|
126
125
|
suppressions: ResolvedSuppression[];
|
|
@@ -130,17 +129,17 @@ interface GatePlan {
|
|
|
130
129
|
*/
|
|
131
130
|
expired: ResolvedSuppression[];
|
|
132
131
|
}
|
|
133
|
-
declare const GATE_CONFIG_FILENAMES: string[];
|
|
132
|
+
export declare const GATE_CONFIG_FILENAMES: string[];
|
|
134
133
|
/** Parse and validate. Every error names the JSON path so the fix is obvious. */
|
|
135
|
-
declare function parseGateConfig(raw: string): GateConfig;
|
|
134
|
+
export declare function parseGateConfig(raw: string): GateConfig;
|
|
136
135
|
/**
|
|
137
136
|
* Whether to reuse a server already listening. Playwright's default, and for
|
|
138
137
|
* Playwright's reason: locally the listening port is your own `npm run dev`; in
|
|
139
138
|
* CI it is usually a leaked process from an earlier job, and reusing it gates a
|
|
140
139
|
* build nobody asked about.
|
|
141
140
|
*/
|
|
142
|
-
declare function shouldReuseExistingServer(server: GateWebServer, env?: NodeJS.ProcessEnv): boolean;
|
|
143
|
-
declare function resolveSuppression(s: GateSuppression, scope: string, now: Date): ResolvedSuppression;
|
|
141
|
+
export declare function shouldReuseExistingServer(server: GateWebServer, env?: NodeJS.ProcessEnv): boolean;
|
|
142
|
+
export declare function resolveSuppression(s: GateSuppression, scope: string, now: Date): ResolvedSuppression;
|
|
144
143
|
/**
|
|
145
144
|
* Resolve one long-form `rules` entry onto the same shape as a suppression, so
|
|
146
145
|
* the inventory, the expiry notice and `--require-expiry` cover both.
|
|
@@ -149,8 +148,8 @@ declare function resolveSuppression(s: GateSuppression, scope: string, now: Date
|
|
|
149
148
|
* -> `check.integrity`), which is what a reader scanning the inventory wants to
|
|
150
149
|
* see; a bare rule id has no gate to name and reports as `*`.
|
|
151
150
|
*/
|
|
152
|
-
declare function resolveRuleSetting(ref: string, entry: RuleSettingEntry, scope: string, now: Date): ResolvedSuppression;
|
|
153
|
-
interface ResolveOptions {
|
|
151
|
+
export declare function resolveRuleSetting(ref: string, entry: RuleSettingEntry, scope: string, now: Date): ResolvedSuppression;
|
|
152
|
+
export interface ResolveOptions {
|
|
154
153
|
now?: Date;
|
|
155
154
|
/**
|
|
156
155
|
* Which of the resolved rule settings belong on THIS gate's command line.
|
|
@@ -178,15 +177,15 @@ interface ResolveOptions {
|
|
|
178
177
|
* command line: the gate returns to failing, which is what an expiry date is
|
|
179
178
|
* supposed to mean.
|
|
180
179
|
*/
|
|
181
|
-
declare function resolveGatePlan(config: GateConfig, options?: ResolveOptions): GatePlan;
|
|
180
|
+
export declare function resolveGatePlan(config: GateConfig, options?: ResolveOptions): GatePlan;
|
|
182
181
|
/** `{ "check.integrity/text-collision": "off" }` → `["--rule", "check.integrity/text-collision=off"]`. */
|
|
183
|
-
declare function ruleFlags(rules: RuleSettings): string[];
|
|
182
|
+
export declare function ruleFlags(rules: RuleSettings): string[];
|
|
184
183
|
/**
|
|
185
184
|
* Token-wise prefix match: `check copy` matches `check copy --manifest x.txt`
|
|
186
185
|
* but not `check copyright`, and `check` matches every check gate.
|
|
187
186
|
*/
|
|
188
|
-
declare function gateMatches(gate: string, pattern: string): boolean;
|
|
189
|
-
interface SuppressionSummary {
|
|
187
|
+
export declare function gateMatches(gate: string, pattern: string): boolean;
|
|
188
|
+
export interface SuppressionSummary {
|
|
190
189
|
rows: ResolvedSuppression[];
|
|
191
190
|
active: number;
|
|
192
191
|
expired: number;
|
|
@@ -196,6 +195,5 @@ interface SuppressionSummary {
|
|
|
196
195
|
/** Active entries expiring within `soonDays`. */
|
|
197
196
|
expiringSoon: number;
|
|
198
197
|
}
|
|
199
|
-
declare function summarizeSuppressions(suppressions: ResolvedSuppression[], soonDays?: number): SuppressionSummary;
|
|
200
|
-
//#endregion
|
|
201
|
-
export { GATE_CONFIG_FILENAMES, GateConfig, GateJob, GatePage, GatePlan, GateSuppression, GateWebServer, ResolveOptions, ResolvedSuppression, SuppressionSummary, gateMatches, parseGateConfig, resolveGatePlan, resolveRuleSetting, resolveSuppression, ruleFlags, shouldReuseExistingServer, summarizeSuppressions };
|
|
198
|
+
export declare function summarizeSuppressions(suppressions: ResolvedSuppression[], soonDays?: number): SuppressionSummary;
|
|
199
|
+
//#endregion
|
package/dist/gate-exit.d.mts
CHANGED
|
@@ -23,23 +23,22 @@
|
|
|
23
23
|
*
|
|
24
24
|
* Warns never affect the exit code, under any flag.
|
|
25
25
|
*/
|
|
26
|
-
interface GateExitFlags {
|
|
26
|
+
export interface GateExitFlags {
|
|
27
27
|
/** Print findings and exit 0 even when suspects exist. */
|
|
28
28
|
advisory: boolean;
|
|
29
29
|
}
|
|
30
30
|
/** Parse the shared exit-code flags out of an argv array. */
|
|
31
|
-
declare function parseGateExitFlags(argv: readonly string[]): GateExitFlags;
|
|
31
|
+
export declare function parseGateExitFlags(argv: readonly string[]): GateExitFlags;
|
|
32
32
|
/**
|
|
33
33
|
* Decide the process exit code. `hasSuspect` should count only
|
|
34
34
|
* defect-severity findings; warn-level findings must not reach it.
|
|
35
35
|
*/
|
|
36
|
-
declare function gateExitCode(hasSuspect: boolean, flags: GateExitFlags): 0 | 1;
|
|
36
|
+
export declare function gateExitCode(hasSuspect: boolean, flags: GateExitFlags): 0 | 1;
|
|
37
37
|
/** Shared help text so every gate documents the contract identically. */
|
|
38
|
-
declare const GATE_EXIT_HELP = " --advisory Print findings but exit 0 (default: a suspect exits 1)";
|
|
38
|
+
export declare const GATE_EXIT_HELP = " --advisory Print findings but exit 0 (default: a suspect exits 1)";
|
|
39
39
|
/**
|
|
40
40
|
* Apply the contract. Sets `process.exitCode` rather than calling
|
|
41
41
|
* `process.exit` so buffered stdout is not truncated.
|
|
42
42
|
*/
|
|
43
|
-
declare function applyGateExit(hasSuspect: boolean, flags: GateExitFlags): void;
|
|
44
|
-
//#endregion
|
|
45
|
-
export { GATE_EXIT_HELP, GateExitFlags, applyGateExit, gateExitCode, parseGateExitFlags };
|
|
43
|
+
export declare function applyGateExit(hasSuspect: boolean, flags: GateExitFlags): void;
|
|
44
|
+
//#endregion
|
package/dist/gif.d.mts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/gif.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A minimal GIF writer: a global palette, an optional loop block, and frames each with its own
|
|
4
|
+
* place on the logical screen and its graphic control extension (delay, disposal, transparent
|
|
5
|
+
* index) or none. Written so the cases ffmpeg composites otherwise than a browser can be built
|
|
6
|
+
* byte for byte (`gifCompositingProblem`); the LZW stream sends a clear code before the table
|
|
7
|
+
* would grow, so every code has the minimum width and no dictionary is kept.
|
|
8
|
+
*
|
|
9
|
+
* Pure: frames in, bytes out.
|
|
10
|
+
*/
|
|
11
|
+
export interface GifFrame {
|
|
12
|
+
x?: number;
|
|
13
|
+
y?: number;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
/** Palette index per pixel, row by row, or one index for every pixel. */
|
|
17
|
+
pixels: number | ((x: number, y: number) => number);
|
|
18
|
+
/** Centiseconds; default 10. */
|
|
19
|
+
delayCs?: number;
|
|
20
|
+
/** 0-1 leave it, 2 restore to background, 3 restore to previous. */
|
|
21
|
+
disposal?: number;
|
|
22
|
+
/** A transparent palette index. */
|
|
23
|
+
transparent?: number;
|
|
24
|
+
/** false: no graphic control extension at all. */
|
|
25
|
+
gce?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface GifOptions {
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
/** RGB triples; at most 256. */
|
|
31
|
+
palette: readonly (readonly [number, number, number])[];
|
|
32
|
+
/** The logical screen's background colour index. */
|
|
33
|
+
background?: number;
|
|
34
|
+
/** NETSCAPE2.0 loop count (0 forever); none when absent (plays once). */
|
|
35
|
+
loop?: number;
|
|
36
|
+
/** The logical screen's pixel aspect byte (0: none). */
|
|
37
|
+
aspectByte?: number;
|
|
38
|
+
/** Give each image the palette as a local colour table and write no global one. */
|
|
39
|
+
localTables?: boolean;
|
|
40
|
+
frames: readonly GifFrame[];
|
|
41
|
+
}
|
|
42
|
+
export declare function encodeGif(options: GifOptions): Uint8Array;
|
|
43
|
+
//#endregion
|
package/dist/gif.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
//#region src/gif.ts
|
|
2
|
+
function lzw(indices, minCodeSize) {
|
|
3
|
+
const clear = 1 << minCodeSize;
|
|
4
|
+
const end = clear + 1;
|
|
5
|
+
const width = minCodeSize + 1;
|
|
6
|
+
const every = (1 << minCodeSize) - 2;
|
|
7
|
+
const codes = [clear];
|
|
8
|
+
indices.forEach((v, i) => {
|
|
9
|
+
if (i > 0 && i % every === 0) codes.push(clear);
|
|
10
|
+
codes.push(v);
|
|
11
|
+
});
|
|
12
|
+
codes.push(end);
|
|
13
|
+
const bytes = [];
|
|
14
|
+
let acc = 0;
|
|
15
|
+
let bits = 0;
|
|
16
|
+
for (const c of codes) {
|
|
17
|
+
acc |= c << bits;
|
|
18
|
+
bits += width;
|
|
19
|
+
while (bits >= 8) {
|
|
20
|
+
bytes.push(acc & 255);
|
|
21
|
+
acc >>>= 8;
|
|
22
|
+
bits -= 8;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (bits > 0) bytes.push(acc & 255);
|
|
26
|
+
const out = [minCodeSize];
|
|
27
|
+
for (let i = 0; i < bytes.length; i += 255) {
|
|
28
|
+
const block = bytes.slice(i, i + 255);
|
|
29
|
+
out.push(block.length, ...block);
|
|
30
|
+
}
|
|
31
|
+
out.push(0);
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
const u16 = (v) => [v & 255, v >> 8 & 255];
|
|
35
|
+
function encodeGif(options) {
|
|
36
|
+
const { width, height, palette } = options;
|
|
37
|
+
let bits = 1;
|
|
38
|
+
while (1 << bits < palette.length) bits++;
|
|
39
|
+
const table = [];
|
|
40
|
+
for (let i = 0; i < 1 << bits; i++) table.push(...palette[i] ?? [
|
|
41
|
+
0,
|
|
42
|
+
0,
|
|
43
|
+
0
|
|
44
|
+
]);
|
|
45
|
+
const local = options.localTables === true;
|
|
46
|
+
const out = [
|
|
47
|
+
...Array.from("GIF89a", (c) => c.charCodeAt(0)),
|
|
48
|
+
...u16(width),
|
|
49
|
+
...u16(height),
|
|
50
|
+
local ? 0 : 128 | bits - 1 << 4 | bits - 1,
|
|
51
|
+
options.background ?? 0,
|
|
52
|
+
options.aspectByte ?? 0,
|
|
53
|
+
...local ? [] : table
|
|
54
|
+
];
|
|
55
|
+
if (options.loop !== void 0) out.push(33, 255, 11, ...Array.from("NETSCAPE2.0", (c) => c.charCodeAt(0)), 3, 1, ...u16(options.loop), 0);
|
|
56
|
+
for (const f of options.frames) {
|
|
57
|
+
if (f.gce !== false) {
|
|
58
|
+
const packed = (f.disposal ?? 0) << 2 | (f.transparent !== void 0 ? 1 : 0);
|
|
59
|
+
out.push(33, 249, 4, packed, ...u16(f.delayCs ?? 10), f.transparent ?? 0, 0);
|
|
60
|
+
}
|
|
61
|
+
const x = f.x ?? 0;
|
|
62
|
+
const y = f.y ?? 0;
|
|
63
|
+
const w = f.width ?? width;
|
|
64
|
+
const h = f.height ?? height;
|
|
65
|
+
out.push(44, ...u16(x), ...u16(y), ...u16(w), ...u16(h), local ? 128 | bits - 1 : 0, ...local ? table : []);
|
|
66
|
+
const paint = f.pixels;
|
|
67
|
+
const px = Array.from({ length: w * h }, (_, i) => typeof paint === "number" ? paint : paint(i % w, Math.floor(i / w)));
|
|
68
|
+
out.push(...lzw(px, Math.max(2, bits)));
|
|
69
|
+
}
|
|
70
|
+
out.push(59);
|
|
71
|
+
return Uint8Array.from(out);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { encodeGif };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/heatmap-regions.d.ts
|
|
2
|
-
interface HeatmapRegion {
|
|
2
|
+
export interface HeatmapRegion {
|
|
3
3
|
top: number;
|
|
4
4
|
left: number;
|
|
5
5
|
width: number;
|
|
@@ -33,7 +33,7 @@ interface HeatmapRegion {
|
|
|
33
33
|
/** Classifier confidence ∈ [0, 1]. */
|
|
34
34
|
kindConfidence?: number;
|
|
35
35
|
}
|
|
36
|
-
interface FindHeatmapRegionsOptions {
|
|
36
|
+
export interface FindHeatmapRegionsOptions {
|
|
37
37
|
/** Minimum hot-pixel count for a region to be kept. Default 80. */
|
|
38
38
|
minArea?: number;
|
|
39
39
|
/** Cap on returned regions, sorted by area desc. Default 8. */
|
|
@@ -51,7 +51,6 @@ interface FindHeatmapRegionsOptions {
|
|
|
51
51
|
*/
|
|
52
52
|
maxRegionFraction?: number;
|
|
53
53
|
}
|
|
54
|
-
declare function findHeatmapRegionsFromRgba(data: Uint8Array, width: number, height: number, options?: FindHeatmapRegionsOptions): HeatmapRegion[];
|
|
55
|
-
declare function findHeatmapRegionsFromFile(path: string, options?: FindHeatmapRegionsOptions, sourceImagePath?: string): Promise<HeatmapRegion[]>;
|
|
56
|
-
//#endregion
|
|
57
|
-
export { FindHeatmapRegionsOptions, HeatmapRegion, findHeatmapRegionsFromFile, findHeatmapRegionsFromRgba };
|
|
54
|
+
export declare function findHeatmapRegionsFromRgba(data: Uint8Array, width: number, height: number, options?: FindHeatmapRegionsOptions): HeatmapRegion[];
|
|
55
|
+
export declare function findHeatmapRegionsFromFile(path: string, options?: FindHeatmapRegionsOptions, sourceImagePath?: string): Promise<HeatmapRegion[]>;
|
|
56
|
+
//#endregion
|
package/dist/heatmap.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DiffIgnoreRegion, DiffRegionColorSample, DiffReport, ShiftRegion, VrtDiff, VrtSnapshot } from "./types.mjs";
|
|
1
|
+
import { DiffIgnoreRegion, DiffRegion, DiffRegionColorSample, DiffReport, ShiftRegion, VrtDiff, VrtSnapshot } from "./types.mjs";
|
|
2
2
|
import { PngData } from "./png-utils.mjs";
|
|
3
|
-
|
|
4
3
|
//#region src/heatmap.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Parse `"<x>,<y>,<w>x<h>"` (e.g. `"0,300,640x60"`) into an ignore rect.
|
|
@@ -13,14 +12,15 @@ import { PngData } from "./png-utils.mjs";
|
|
|
13
12
|
* Zero-area rects are rejected: `"0,0,0x0"` masks nothing, so accepting it
|
|
14
13
|
* would only ever mean the caller mistyped and got silence.
|
|
15
14
|
*/
|
|
16
|
-
declare function parseIgnoreRegionSpec(value: string): DiffIgnoreRegion;
|
|
15
|
+
export declare function parseIgnoreRegionSpec(value: string): DiffIgnoreRegion;
|
|
17
16
|
/**
|
|
18
17
|
* Compare two screenshots pixel-by-pixel and generate a diff heatmap.
|
|
19
18
|
*/
|
|
20
|
-
declare function compareScreenshots(snapshot: VrtSnapshot, opts?: {
|
|
19
|
+
export declare function compareScreenshots(snapshot: VrtSnapshot, opts?: {
|
|
21
20
|
threshold?: number;
|
|
22
21
|
outputDir?: string;
|
|
23
|
-
skipHeatmap?: boolean;
|
|
22
|
+
skipHeatmap?: boolean;
|
|
23
|
+
/** Override the adaptive grid. See `adaptiveRegionCellSize`. */
|
|
24
24
|
regionCellSize?: number;
|
|
25
25
|
/**
|
|
26
26
|
* Rectangles that are non-deterministic by construction (particles, a
|
|
@@ -51,7 +51,12 @@ declare function compareScreenshots(snapshot: VrtSnapshot, opts?: {
|
|
|
51
51
|
* continuous function would shift region geometry on nearly every existing image, and
|
|
52
52
|
* region bboxes appear in baselines, approvals and reports.
|
|
53
53
|
*/
|
|
54
|
-
declare function adaptiveRegionCellSize(width: number, height: number): number;
|
|
54
|
+
export declare function adaptiveRegionCellSize(width: number, height: number): number;
|
|
55
|
+
/** Edge-only test over a region: `@mizchi/vlmkit-judge/edge-noise.ts`. */
|
|
56
|
+
export declare function regionDelta(baseline: PngData, current: PngData, region: DiffRegion): {
|
|
57
|
+
max: number;
|
|
58
|
+
edgeOnly: boolean;
|
|
59
|
+
};
|
|
55
60
|
/**
|
|
56
61
|
* Sample a region's color pair from the pixels that actually differ.
|
|
57
62
|
*
|
|
@@ -66,7 +71,7 @@ declare function adaptiveRegionCellSize(width: number, height: number): number;
|
|
|
66
71
|
* antialiasing blends, so we additionally surface the single highest-delta
|
|
67
72
|
* pixel pair as `peak` (draft 11).
|
|
68
73
|
*/
|
|
69
|
-
declare function sampleRegionColorSample(baseline: PngData, current: PngData, region: {
|
|
74
|
+
export declare function sampleRegionColorSample(baseline: PngData, current: PngData, region: {
|
|
70
75
|
x: number;
|
|
71
76
|
y: number;
|
|
72
77
|
width: number;
|
|
@@ -83,7 +88,7 @@ declare function sampleRegionColorSample(baseline: PngData, current: PngData, re
|
|
|
83
88
|
*
|
|
84
89
|
* Exported for unit testing.
|
|
85
90
|
*/
|
|
86
|
-
declare function detectBandShifts(baseline: {
|
|
91
|
+
export declare function detectBandShifts(baseline: {
|
|
87
92
|
data: Uint8Array;
|
|
88
93
|
width: number;
|
|
89
94
|
height: number;
|
|
@@ -100,18 +105,20 @@ declare function detectBandShifts(baseline: {
|
|
|
100
105
|
* Generate a comprehensive diff report including clustering, shift detection,
|
|
101
106
|
* and region classification. Compatible with mizchi/pixelmatch 0.5.0 DiffReport format.
|
|
102
107
|
*/
|
|
103
|
-
declare function generateDiffReport(snapshot: VrtSnapshot, opts?: {
|
|
108
|
+
export declare function generateDiffReport(snapshot: VrtSnapshot, opts?: {
|
|
104
109
|
threshold?: number;
|
|
105
110
|
outputDir?: string;
|
|
106
111
|
skipHeatmap?: boolean;
|
|
107
|
-
detectShift?: boolean;
|
|
108
|
-
|
|
112
|
+
detectShift?: boolean;
|
|
113
|
+
/** Override the adaptive grid. See `adaptiveRegionCellSize`. */
|
|
114
|
+
regionCellSize?: number;
|
|
115
|
+
/** See `compareScreenshots`. Shift detection is NOT masked — see below. */
|
|
109
116
|
ignoreRegions?: DiffIgnoreRegion[];
|
|
110
117
|
}): Promise<DiffReport | null>;
|
|
111
118
|
/**
|
|
112
119
|
* Whiteout detection: checks if most of the image is white (or a single color).
|
|
113
120
|
*/
|
|
114
|
-
declare function detectWhiteout(data: PngData, opts?: {
|
|
121
|
+
export declare function detectWhiteout(data: PngData, opts?: {
|
|
115
122
|
threshold?: number;
|
|
116
123
|
}): {
|
|
117
124
|
isWhiteout: boolean;
|
|
@@ -120,11 +127,10 @@ declare function detectWhiteout(data: PngData, opts?: {
|
|
|
120
127
|
/**
|
|
121
128
|
* Empty content detection: checks if the image has low entropy.
|
|
122
129
|
*/
|
|
123
|
-
declare function detectEmptyContent(data: PngData, opts?: {
|
|
130
|
+
export declare function detectEmptyContent(data: PngData, opts?: {
|
|
124
131
|
threshold?: number;
|
|
125
132
|
}): {
|
|
126
133
|
isEmpty: boolean;
|
|
127
134
|
uniqueColors: number;
|
|
128
135
|
};
|
|
129
|
-
//#endregion
|
|
130
|
-
export { adaptiveRegionCellSize, compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport, parseIgnoreRegionSpec, sampleRegionColorSample };
|
|
136
|
+
//#endregion
|
package/dist/heatmap.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cropImage, decodePng, encodePng } from "./png-utils.mjs";
|
|
2
2
|
import { estimateRegionShift } from "./region-shift.mjs";
|
|
3
|
+
import { edgeOnlyDelta } from "@mizchi/vlmkit-judge/edge-noise.ts";
|
|
3
4
|
//#region src/heatmap.ts
|
|
4
5
|
/**
|
|
5
6
|
* Colour written into the heatmap over ignored pixels.
|
|
@@ -270,8 +271,15 @@ function attachRegionColorSamples(regions, baseline, current) {
|
|
|
270
271
|
for (const region of regions) {
|
|
271
272
|
const sample = sampleRegionColorSample(baseline, current, region);
|
|
272
273
|
if (sample) region.colorSample = sample;
|
|
274
|
+
const delta = regionDelta(baseline, current, region);
|
|
275
|
+
region.maxChannelDelta = delta.max;
|
|
276
|
+
if (delta.edgeOnly) region.edgeOnly = true;
|
|
273
277
|
}
|
|
274
278
|
}
|
|
279
|
+
/** Edge-only test over a region: `@mizchi/vlmkit-judge/edge-noise.ts`. */
|
|
280
|
+
function regionDelta(baseline, current, region) {
|
|
281
|
+
return edgeOnlyDelta(baseline, current, region);
|
|
282
|
+
}
|
|
275
283
|
function attachRegionShiftEstimates(regions, baseline, current) {
|
|
276
284
|
for (const region of regions) {
|
|
277
285
|
if (region.regionType === "edge") continue;
|
|
@@ -558,8 +566,8 @@ function generateCompact(diffData, width, height, diffPixels, totalPixels, regio
|
|
|
558
566
|
const cellH = Math.ceil(height / gridSize);
|
|
559
567
|
const grid = Array.from({ length: gridSize }, () => new Array(gridSize).fill(0));
|
|
560
568
|
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) if (diffData[(y * width + x) * 4 + 1] < 128) {
|
|
561
|
-
const gx = Math.min(Math.floor(x / cellW),
|
|
562
|
-
const gy = Math.min(Math.floor(y / cellH),
|
|
569
|
+
const gx = Math.min(Math.floor(x / cellW), 9);
|
|
570
|
+
const gy = Math.min(Math.floor(y / cellH), 9);
|
|
563
571
|
grid[gy][gx]++;
|
|
564
572
|
}
|
|
565
573
|
const lines = [`diff:${diffPixels}/${totalPixels}(${((1 - safeDiffRatio(diffPixels, totalPixels)) * 100).toFixed(0)}%match)`];
|
|
@@ -652,4 +660,4 @@ function detectEmptyContent(data, opts = {}) {
|
|
|
652
660
|
};
|
|
653
661
|
}
|
|
654
662
|
//#endregion
|
|
655
|
-
export { adaptiveRegionCellSize, compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport, parseIgnoreRegionSpec, sampleRegionColorSample };
|
|
663
|
+
export { adaptiveRegionCellSize, compareScreenshots, detectBandShifts, detectEmptyContent, detectWhiteout, generateDiffReport, parseIgnoreRegionSpec, regionDelta, sampleRegionColorSample };
|
package/dist/image-resize.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/image-resize.d.ts
|
|
2
|
-
type ResolutionPreset = "low" | "medium" | "high" | "full";
|
|
3
|
-
declare const RESOLUTION_PRESETS: Record<ResolutionPreset, {
|
|
2
|
+
export type ResolutionPreset = "low" | "medium" | "high" | "full";
|
|
3
|
+
export declare const RESOLUTION_PRESETS: Record<ResolutionPreset, {
|
|
4
4
|
maxWidth: number;
|
|
5
5
|
maxHeight: number;
|
|
6
6
|
}>;
|
|
@@ -8,8 +8,8 @@ declare const RESOLUTION_PRESETS: Record<ResolutionPreset, {
|
|
|
8
8
|
* Select the optimal resolution preset for a given viewport width.
|
|
9
9
|
* Returns the smallest preset with at least half the viewport width.
|
|
10
10
|
*/
|
|
11
|
-
declare function resolveResolutionForViewport(viewportWidth: number, maxPreset?: ResolutionPreset): ResolutionPreset;
|
|
12
|
-
interface ResizeOptions {
|
|
11
|
+
export declare function resolveResolutionForViewport(viewportWidth: number, maxPreset?: ResolutionPreset): ResolutionPreset;
|
|
12
|
+
export interface ResizeOptions {
|
|
13
13
|
/** Preset or custom size */
|
|
14
14
|
resolution?: ResolutionPreset | {
|
|
15
15
|
maxWidth: number;
|
|
@@ -17,18 +17,17 @@ interface ResizeOptions {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
/** Resize PNG buffer to fit within the given size. Preserves aspect ratio. */
|
|
20
|
-
declare function resizePngBuffer(pngBuffer: Buffer, options?: ResizeOptions): Buffer;
|
|
20
|
+
export declare function resizePngBuffer(pngBuffer: Buffer, options?: ResizeOptions): Buffer;
|
|
21
21
|
/** Read dimensions from PNG IHDR chunk (no full decode needed) */
|
|
22
|
-
declare function readPngDimensions(buf: Buffer): {
|
|
22
|
+
export declare function readPngDimensions(buf: Buffer): {
|
|
23
23
|
width: number;
|
|
24
24
|
height: number;
|
|
25
25
|
};
|
|
26
26
|
/** Resize a base64 PNG to the specified resolution. Returns base64. */
|
|
27
|
-
declare function resizeBase64Png(base64: string, options?: ResizeOptions): string;
|
|
27
|
+
export declare function resizeBase64Png(base64: string, options?: ResizeOptions): string;
|
|
28
28
|
/** Get image dimensions */
|
|
29
|
-
declare function getImageDimensions(base64: string): {
|
|
29
|
+
export declare function getImageDimensions(base64: string): {
|
|
30
30
|
width: number;
|
|
31
31
|
height: number;
|
|
32
32
|
};
|
|
33
|
-
//#endregion
|
|
34
|
-
export { RESOLUTION_PRESETS, ResizeOptions, ResolutionPreset, getImageDimensions, readPngDimensions, resizeBase64Png, resizePngBuffer, resolveResolutionForViewport };
|
|
33
|
+
//#endregion
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/image-timing.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* How an animated GIF or APNG plays in a browser: each frame's delay as stored, how many times
|
|
4
|
+
* the animation plays, and the delays a browser actually holds.
|
|
5
|
+
*
|
|
6
|
+
* Measured on Chromium 141 and 149 (`docs/reports/2026-10-13-scan-video-v1.md`): a frame of 10ms
|
|
7
|
+
* or less is held 100ms, in a GIF and an APNG alike; longer delays play as stored. ffmpeg times
|
|
8
|
+
* them otherwise — a GIF's 1cs frame plays for 10ms, an APNG's 0 delay for 1/15s — and decodes one
|
|
9
|
+
* pass, where a browser loops. A two-frame black/white GIF looping at 100ms a frame is five
|
|
10
|
+
* flashes a second on screen and one transition in a single decoded pass.
|
|
11
|
+
*
|
|
12
|
+
* Pure: bytes in, no I/O.
|
|
13
|
+
*/
|
|
14
|
+
export interface ImageTiming {
|
|
15
|
+
format: "gif" | "apng";
|
|
16
|
+
/** Each frame's delay as stored, in ms (a GIF's centiseconds x 10; an APNG's delay_num / delay_den). */
|
|
17
|
+
storedMs: number[];
|
|
18
|
+
/** How many times the animation plays; `null` is forever. */
|
|
19
|
+
plays: number | null;
|
|
20
|
+
/** An APNG's `acTL` num_frames: the frames a browser plays, whatever number of `fcTL` follow. */
|
|
21
|
+
declaredFrames?: number;
|
|
22
|
+
/** A GIF's logical screen and each image's place and compositing, which ffmpeg composites otherwise than a browser. */
|
|
23
|
+
gif?: {
|
|
24
|
+
screen: {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
};
|
|
28
|
+
globalTable: boolean;
|
|
29
|
+
images: GifImage[];
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface GifImage {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
/** The graphic control extension's disposal method: 0-1 leave it, 2 restore to background, 3 restore to previous. */
|
|
38
|
+
disposal: number;
|
|
39
|
+
/** It has a transparent colour index. */
|
|
40
|
+
transparent: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** What Chromium holds a frame for: 10ms or less is 100ms. */
|
|
43
|
+
export declare const browserDelayMs: (storedMs: number) => number;
|
|
44
|
+
/**
|
|
45
|
+
* Where ffmpeg 6.1's GIF decoder composites otherwise than Chromium (measured,
|
|
46
|
+
* `docs/reports/2026-10-13-scan-video-v1.md`), or null. ffmpeg's background is the global colour
|
|
47
|
+
* table's background entry, opaque, wherever a browser leaves the canvas transparent — but only
|
|
48
|
+
* when the GIF has a global table and the image it fills under has no transparent index; otherwise
|
|
49
|
+
* it fills with its transparent colour, as a browser does (measured: those decode pixel for pixel
|
|
50
|
+
* as Chromium shows them). So refused: a first image larger than the logical screen (a browser grows
|
|
51
|
+
* the canvas, ffmpeg crops); one that does not cover it, opaque, under a global table; a frame
|
|
52
|
+
* disposed to background, opaque, under a global table, that the next image does not paint over
|
|
53
|
+
* opaquely; and one restored to previous where what is restored holds that fill (ffmpeg saved it,
|
|
54
|
+
* a browser restores the cleared canvas). Frame 0 of every pass is drawn on a cleared canvas in both.
|
|
55
|
+
*/
|
|
56
|
+
export declare function gifCompositingProblem(timing: ImageTiming): string | null;
|
|
57
|
+
/** The timing of an animated GIF or APNG, or null for anything else (a still PNG, a video). */
|
|
58
|
+
export declare function imageTiming(bytes: Uint8Array): ImageTiming | null;
|
|
59
|
+
//#endregion
|