@mizchi/vlmkit-core 0.23.1 → 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
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
import { browserDelayMs } from "./image-timing.mjs";
|
|
2
|
+
import { UsageError } from "@mizchi/vlmkit-judge/errors.ts";
|
|
3
|
+
//#region src/video-frames.ts
|
|
4
|
+
/**
|
|
5
|
+
* The pure half of loading a recording through a decoder the user supplies (`vlmkit scan video`):
|
|
6
|
+
* which frames to keep, how big the frames are shown, and which codecs reproduce their input.
|
|
7
|
+
* No process and no file: `video-decode.ts` runs the user's own ffmpeg and ffprobe and brings
|
|
8
|
+
* their output here.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Codecs whose decoded frames are what was encoded, bit for bit (modulo a chroma subsampling the
|
|
12
|
+
* encoder chose). Anything else is treated as lossy: x264 at `-qp 0` is lossless too, but nothing
|
|
13
|
+
* in the stream says so, so it is not claimed. (Apple's rpza is a 4x4 vector quantizer: lossy.)
|
|
14
|
+
*/
|
|
15
|
+
const LOSSLESS_CODECS = /* @__PURE__ */ new Set([
|
|
16
|
+
"png",
|
|
17
|
+
"apng",
|
|
18
|
+
"gif",
|
|
19
|
+
"ffv1",
|
|
20
|
+
"ffvhuff",
|
|
21
|
+
"huffyuv",
|
|
22
|
+
"utvideo",
|
|
23
|
+
"magicyuv",
|
|
24
|
+
"lagarith",
|
|
25
|
+
"qtrle",
|
|
26
|
+
"rawvideo",
|
|
27
|
+
"zmbv",
|
|
28
|
+
"msrle",
|
|
29
|
+
"bmp",
|
|
30
|
+
"tiff",
|
|
31
|
+
"r210",
|
|
32
|
+
"v210",
|
|
33
|
+
"v410",
|
|
34
|
+
"flashsv",
|
|
35
|
+
"flashsv2"
|
|
36
|
+
]);
|
|
37
|
+
/** A time within this of a frame's start is that frame's: decimal input against a rational timestamp. */
|
|
38
|
+
const ON_FRAME_MS = 1e-6;
|
|
39
|
+
/** The frame on screen at `t`: the last one that began at or before it, or the first frame before any began. */
|
|
40
|
+
function frameAt(rows, t) {
|
|
41
|
+
let lo = 0;
|
|
42
|
+
let hi = rows.length - 1;
|
|
43
|
+
if (hi < 0) throw new Error("frameAt: no frames");
|
|
44
|
+
if (t < rows[0].atMs - ON_FRAME_MS) return 0;
|
|
45
|
+
while (lo < hi) {
|
|
46
|
+
const mid = lo + hi + 1 >> 1;
|
|
47
|
+
if (rows[mid].atMs <= t + ON_FRAME_MS) lo = mid;
|
|
48
|
+
else hi = mid - 1;
|
|
49
|
+
}
|
|
50
|
+
return lo;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The frames a selection keeps, in order. `span` keeps every frame on screen at some moment of
|
|
54
|
+
* [from, to]; `at` keeps the frame on screen at each instant, once, with the instants it answers.
|
|
55
|
+
*/
|
|
56
|
+
function chooseFrames(rows, selection, endMs) {
|
|
57
|
+
if (rows.length === 0) return [];
|
|
58
|
+
if (selection.kind === "all") return rows.map((r) => ({ ...r }));
|
|
59
|
+
if (selection.kind === "span") {
|
|
60
|
+
const end = recordingEndMs(rows, endMs);
|
|
61
|
+
if (selection.fromMs > end + ON_FRAME_MS) throw new UsageError(`--from ${selection.fromMs}ms is after the recording ends (its last frame is on screen until ${Number(end.toFixed(3))}ms)`);
|
|
62
|
+
const from = frameAt(rows, Math.max(0, selection.fromMs - (selection.leadInMs ?? 0)));
|
|
63
|
+
const to = selection.toMs === void 0 ? rows.length - 1 : frameAt(rows, selection.toMs);
|
|
64
|
+
return rows.slice(from, to + 1).map((r) => ({ ...r }));
|
|
65
|
+
}
|
|
66
|
+
const byFrame = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const t of selection.atMs) {
|
|
68
|
+
const k = frameAt(rows, t);
|
|
69
|
+
byFrame.set(k, [...byFrame.get(k) ?? [], t]);
|
|
70
|
+
}
|
|
71
|
+
return [...byFrame.entries()].sort((a, b) => a[0] - b[0]).map(([k, instants]) => ({
|
|
72
|
+
...rows[k],
|
|
73
|
+
instants
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* When the last frame leaves the screen: `endMs` when the stream says how long it is shown, else
|
|
78
|
+
* as long after it began as the gap before it (the rate it was shown at), or at once for one frame.
|
|
79
|
+
*/
|
|
80
|
+
function recordingEndMs(rows, endMs) {
|
|
81
|
+
const last = rows[rows.length - 1];
|
|
82
|
+
if (endMs !== void 0 && endMs > last.atMs) return endMs;
|
|
83
|
+
return rows.length > 1 ? last.atMs + (last.atMs - rows[rows.length - 2].atMs) : last.atMs;
|
|
84
|
+
}
|
|
85
|
+
/** The largest side a recording is judged at, in CSS px: the judge keeps several arrays per CSS px. */
|
|
86
|
+
const MAX_DISPLAY_PX = 4096;
|
|
87
|
+
/**
|
|
88
|
+
* How big the frames are shown, as the frames contract states it: the viewport in CSS px and the
|
|
89
|
+
* frame pixels per CSS px. A video has no page, so by default one frame pixel is one CSS pixel;
|
|
90
|
+
* `displayWidth` is the width it plays at (a 1920px recording in a 1280px player is 1.5 pixels per
|
|
91
|
+
* CSS px). `check flash` measures its 341x256 field and its area limit in those CSS px.
|
|
92
|
+
*/
|
|
93
|
+
function displayGeometry(frame, displayWidth) {
|
|
94
|
+
if (displayWidth === void 0) {
|
|
95
|
+
if (frame.width > 4096 || frame.height > 4096) throw new UsageError(`the frames are ${frame.width}x${frame.height}, and one frame pixel per CSS px is over the ${MAX_DISPLAY_PX} a side the judge takes: say how wide it plays, e.g. --display-width 1920`);
|
|
96
|
+
return {
|
|
97
|
+
viewport: {
|
|
98
|
+
width: frame.width,
|
|
99
|
+
height: frame.height
|
|
100
|
+
},
|
|
101
|
+
deviceScaleFactor: 1
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (!(Number.isFinite(displayWidth) && displayWidth >= 1)) throw new UsageError(`--display-width is the width the video plays at, in CSS px (got ${displayWidth})`);
|
|
105
|
+
const deviceScaleFactor = frame.width / displayWidth;
|
|
106
|
+
const viewport = {
|
|
107
|
+
width: displayWidth,
|
|
108
|
+
height: Math.max(1, Math.round(frame.height / deviceScaleFactor))
|
|
109
|
+
};
|
|
110
|
+
if (viewport.width > 4096 || viewport.height > 4096) throw new UsageError(`--display-width ${displayWidth} shows the video at ${viewport.width}x${viewport.height} CSS px; the judge works per CSS px and takes at most ${MAX_DISPLAY_PX} a side`);
|
|
111
|
+
return {
|
|
112
|
+
viewport,
|
|
113
|
+
deviceScaleFactor
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The filters ffmpeg 6.1's own autorotate inserts for a stream's display matrix
|
|
118
|
+
* (`fftools/ffmpeg_filter.c`), for a chain that has to turn the frames itself — after splitting an
|
|
119
|
+
* interlaced frame into its fields, which autorotate would otherwise turn first (a quarter turn
|
|
120
|
+
* makes rows of columns, and a half turn reverses the field order). `[]` for none; null for a turn
|
|
121
|
+
* that is not a quarter one, which ffmpeg does with `rotate` and black corners.
|
|
122
|
+
*/
|
|
123
|
+
function rotationFilters(stream) {
|
|
124
|
+
const m = stream.displayMatrix;
|
|
125
|
+
if (stream.rotation === void 0 && !m) return [];
|
|
126
|
+
let theta = -Math.round(stream.rotation ?? 0);
|
|
127
|
+
theta -= 360 * Math.floor(theta / 360 + .9 / 360);
|
|
128
|
+
if (Math.abs(theta - 90) < 1) return [`transpose=${m && m[3] > 0 ? "cclock_flip" : "clock"}`];
|
|
129
|
+
if (Math.abs(theta - 180) < 1) return [...!m || m[0] < 0 ? ["hflip"] : [], ...!m || m[4] < 0 ? ["vflip"] : []];
|
|
130
|
+
if (Math.abs(theta - 270) < 1) return [`transpose=${m && m[3] < 0 ? "clock_flip" : "cclock"}`];
|
|
131
|
+
if (Math.abs(theta) > 1) return null;
|
|
132
|
+
return m && m[4] < 0 ? ["vflip"] : [];
|
|
133
|
+
}
|
|
134
|
+
const stated = (value) => value === void 0 || value === "" || value === "unknown" || value === "unspecified" ? void 0 : value;
|
|
135
|
+
function ratio(raw, sep) {
|
|
136
|
+
const m = raw?.match(new RegExp(`^(\\d+)${sep}(\\d+)$`));
|
|
137
|
+
if (!m) return null;
|
|
138
|
+
const num = Number(m[1]);
|
|
139
|
+
const den = Number(m[2]);
|
|
140
|
+
return num > 0 && den > 0 ? {
|
|
141
|
+
num,
|
|
142
|
+
den
|
|
143
|
+
} : null;
|
|
144
|
+
}
|
|
145
|
+
const ALPHA_FORMAT = /^(yuva|rgba|bgra|argb|abgr|gbrap|ya8|ya16|pal8$)/;
|
|
146
|
+
/**
|
|
147
|
+
* The video stream to decode from `ffprobe -show_streams -show_format -of json`: the one asked for
|
|
148
|
+
* by index, else not cover art (`attached_pic`), with a size, the default-disposition one first,
|
|
149
|
+
* then the largest. That is not ffmpeg's own choice — ffmpeg 6.1 takes a larger non-default stream
|
|
150
|
+
* over a smaller default one (measured) — but the stream a file marks as the one to play. It is mapped by its absolute index:
|
|
151
|
+
* `-map 0:v:0` is the first by index, which in an mkv can be a one-frame cover track. Refuses a
|
|
152
|
+
* file with none, listing what it holds.
|
|
153
|
+
*/
|
|
154
|
+
function pickVideoStream(probeJson, file, wanted) {
|
|
155
|
+
let probe;
|
|
156
|
+
try {
|
|
157
|
+
probe = JSON.parse(probeJson);
|
|
158
|
+
} catch {
|
|
159
|
+
throw new Error(`ffprobe printed something that is not JSON for ${file}`);
|
|
160
|
+
}
|
|
161
|
+
const streams = probe.streams ?? [];
|
|
162
|
+
const listing = streams.map((s) => `#${s.index} ${s.codec_type ?? "?"} ${s.codec_name ?? "(no decoder)"}${s.disposition?.attached_pic ? " cover art" : ""}`).join(", ") || "none";
|
|
163
|
+
const candidates = streams.filter((s) => s.codec_type === "video" && !s.disposition?.attached_pic && (s.width ?? 0) > 0 && (s.height ?? 0) > 0).sort((a, b) => (b.disposition?.default ?? 0) - (a.disposition?.default ?? 0) || (b.width ?? 0) * (b.height ?? 0) - (a.width ?? 0) * (a.height ?? 0) || (a.index ?? 0) - (b.index ?? 0));
|
|
164
|
+
const stream = wanted === void 0 ? candidates[0] : streams.find((s) => s.index === wanted && s.codec_type === "video");
|
|
165
|
+
if (!stream) throw new UsageError(wanted === void 0 ? `${file} holds no video stream to decode (streams: ${listing})` : `${file} has no video stream #${wanted} (streams: ${listing}); --stream takes a video stream's index`);
|
|
166
|
+
if (!stream.codec_name) throw new UsageError(`${file}: this ffmpeg has no decoder for video stream #${stream.index} (streams: ${listing})`);
|
|
167
|
+
const timeBase = ratio(stream.time_base, "/");
|
|
168
|
+
if (!timeBase || !stream.width || !stream.height) throw new UsageError(`${file}: ffprobe gives video stream #${stream.index} no size or time base`);
|
|
169
|
+
const sar = ratio(stream.sample_aspect_ratio, ":");
|
|
170
|
+
const matrix = stream.side_data_list?.find((d) => d.side_data_type === "Display Matrix" && typeof d.rotation === "number");
|
|
171
|
+
const rotateTag = stream.tags?.rotate !== void 0 ? Number(stream.tags.rotate) : void 0;
|
|
172
|
+
const rotation = matrix?.rotation ?? (Number.isFinite(rotateTag) ? rotateTag : void 0);
|
|
173
|
+
const entries = (matrix?.displaymatrix ?? "").split("\n").flatMap((row) => row.replace(/^\s*[0-9a-f]+:/i, "").trim().split(/\s+/).filter(Boolean)).map(Number);
|
|
174
|
+
const displayMatrix = entries.length === 9 && entries.every(Number.isFinite) ? entries : void 0;
|
|
175
|
+
const tagged = stream.tags?.DURATION?.match(/^(\d+):(\d+):(\d+(?:\.\d+)?)$/);
|
|
176
|
+
const seconds = tagged ? Number(tagged[1]) * 3600 + Number(tagged[2]) * 60 + Number(tagged[3]) : stream.duration !== void 0 ? Number(stream.duration) : NaN;
|
|
177
|
+
const pixelFormat = stream.pix_fmt ?? "unknown";
|
|
178
|
+
const alpha = stream.tags?.alpha_mode === "1" && (stream.codec_name === "vp9" || stream.codec_name === "vp8") ? stream.codec_name === "vp9" ? "libvpx-vp9" : "libvpx" : ALPHA_FORMAT.test(pixelFormat) ? "pixels" : void 0;
|
|
179
|
+
return {
|
|
180
|
+
index: stream.index ?? 0,
|
|
181
|
+
codec: stream.codec_name,
|
|
182
|
+
...stated(stream.profile) ? { profile: stream.profile } : {},
|
|
183
|
+
pixelFormat,
|
|
184
|
+
width: stream.width,
|
|
185
|
+
height: stream.height,
|
|
186
|
+
...sar && sar.num !== sar.den ? { sampleAspect: `${sar.num}:${sar.den}` } : {},
|
|
187
|
+
timeBase,
|
|
188
|
+
...stated(stream.color_space) ? { colorSpace: stream.color_space } : {},
|
|
189
|
+
...stated(stream.color_range) ? { colorRange: stream.color_range } : {},
|
|
190
|
+
...stated(stream.color_transfer) ? { colorTransfer: stream.color_transfer } : {},
|
|
191
|
+
...stated(stream.color_primaries) ? { colorPrimaries: stream.color_primaries } : {},
|
|
192
|
+
...stated(stream.field_order) && stream.field_order !== "progressive" ? { fieldOrder: stream.field_order } : {},
|
|
193
|
+
...rotation ? { rotation } : {},
|
|
194
|
+
...displayMatrix ? { displayMatrix } : {},
|
|
195
|
+
...Number.isFinite(seconds) && seconds > 0 ? { durationMs: seconds * 1e3 } : {},
|
|
196
|
+
...stream.start_time !== void 0 && Number.isFinite(Number(stream.start_time)) ? { startMs: Number(stream.start_time) * 1e3 } : {},
|
|
197
|
+
...probe.format?.format_name ? { container: probe.format.format_name } : {},
|
|
198
|
+
...alpha ? { alpha } : {}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* `ffprobe -show_entries frame=best_effort_timestamp,key_frame,interlaced_frame -of json`: every
|
|
203
|
+
* decoded frame, in the order the decoder outputs them, which is the order they are shown. A frame
|
|
204
|
+
* without a timestamp cannot be placed and is refused; the order is checked by `videoTimeline`
|
|
205
|
+
* (a timestamp that goes back is refused, an equal one hides the frame before it).
|
|
206
|
+
*/
|
|
207
|
+
function parseFrameTable(framesJson, file) {
|
|
208
|
+
let parsed;
|
|
209
|
+
try {
|
|
210
|
+
parsed = JSON.parse(framesJson);
|
|
211
|
+
} catch {
|
|
212
|
+
throw new Error(`ffprobe printed something that is not JSON for ${file}'s frames`);
|
|
213
|
+
}
|
|
214
|
+
const frames = parsed.frames ?? [];
|
|
215
|
+
if (frames.length === 0) throw new UsageError(`${file}: the video stream decodes to no frames`);
|
|
216
|
+
return frames.map((f, index) => {
|
|
217
|
+
const ticks = f.best_effort_timestamp ?? f.pts;
|
|
218
|
+
if (typeof ticks !== "number" || !Number.isFinite(ticks)) throw new UsageError(`${file}: decoded frame ${index} has no timestamp, so when it is shown is not known (a raw elementary stream carries none). Re-encode it losslessly at its rate first (a copy cannot give reordered frames a time), e.g. ffmpeg -r 30 -i ${file} -c:v ffv1 timed.mkv`);
|
|
219
|
+
return {
|
|
220
|
+
index,
|
|
221
|
+
ticks,
|
|
222
|
+
key: f.key_frame === 1,
|
|
223
|
+
...f.interlaced_frame === 1 ? { interlaced: true } : {},
|
|
224
|
+
...f.top_field_first === 1 ? { topFieldFirst: true } : {},
|
|
225
|
+
...f.width && f.height ? {
|
|
226
|
+
width: f.width,
|
|
227
|
+
height: f.height
|
|
228
|
+
} : {},
|
|
229
|
+
...(f.duration ?? f.pkt_duration ?? 0) > 0 ? { durationTicks: f.duration ?? f.pkt_duration } : {},
|
|
230
|
+
...f.pkt_pos !== void 0 && f.pkt_pos !== "" && Number(f.pkt_pos) >= 0 ? { pos: Number(f.pkt_pos) } : {}
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Each decoded frame's GOP, in the order the frames are shown: counted in decode order, where a
|
|
236
|
+
* keyframe that follows a predicted frame begins one. Decode order is the packets' order in the
|
|
237
|
+
* file (`pkt_pos`), when every frame has one; otherwise the order they are shown, which differs
|
|
238
|
+
* only for an open GOP. There the B-frames shown just before a keyframe are decoded after it and
|
|
239
|
+
* predicted from it, so they carry its re-quantization (measured on x264 --open-gop: the frame
|
|
240
|
+
* shown 17ms before the keyframe stepped 42 levels on a still page, the keyframe 18 after it).
|
|
241
|
+
* A run of keyframes is one GOP: an intra-only codec codes a still picture the same every frame.
|
|
242
|
+
* Only keyframes shown one after another are a run: x264 --open-gop with a GOP no longer than its
|
|
243
|
+
* B-frames decodes the IDR and the next keyframe back to back, the B-frames shown between them
|
|
244
|
+
* after both, and counted as a run that keyframe was in GOP 0 — neither an opening nor a run as
|
|
245
|
+
* shown, so its re-quantization was a 55-frame transient that swallowed every caret blink in it.
|
|
246
|
+
*/
|
|
247
|
+
function gopNumbers(frames) {
|
|
248
|
+
const order = frames.every((f) => f.pos !== void 0) ? frames.map((_, i) => i).sort((a, b) => frames[a].pos - frames[b].pos || a - b) : frames.map((_, i) => i);
|
|
249
|
+
const gop = new Array(frames.length).fill(0);
|
|
250
|
+
let g = 0;
|
|
251
|
+
order.forEach((i, k) => {
|
|
252
|
+
const prev = k > 0 ? order[k - 1] : -1;
|
|
253
|
+
if (k > 0 && frames[i].key && (!frames[prev].key || i !== prev + 1)) g++;
|
|
254
|
+
gop[i] = g;
|
|
255
|
+
});
|
|
256
|
+
return gop;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* The frames a video shows, at their presentation times on the stream's own timeline — the one a
|
|
260
|
+
* browser's `video.currentTime` counts (measured: a video that starts 0.7s in shows frame 9 at
|
|
261
|
+
* 1.0s, not frame 30), so `--at 1s` is the frame a player shows at 1s. A frame is dropped when the
|
|
262
|
+
* next one begins at the same instant (the one on screen then is the later; measured:
|
|
263
|
+
* `-fps_mode passthrough` keeps both, and a recording with 0, 0, 0, 33, 33ms exists). Timestamps
|
|
264
|
+
* that go back are refused. A frame `split` says is interlaced is its two fields: the second
|
|
265
|
+
* halfway to the next frame, so a flicker at field rate is in the sequence (woven, it was a still
|
|
266
|
+
* comb, measured); a progressive one, in the same stream, is one row.
|
|
267
|
+
*/
|
|
268
|
+
function videoTimeline(frames, timeBase, file, options = {}) {
|
|
269
|
+
const ms = (ticks) => ticks * 1e3 * timeBase.num / timeBase.den;
|
|
270
|
+
const origin = Math.min(0, ms(frames[0].ticks));
|
|
271
|
+
const shown = [];
|
|
272
|
+
let hidden = 0;
|
|
273
|
+
for (const [i, f] of frames.entries()) {
|
|
274
|
+
const next = frames[i + 1];
|
|
275
|
+
if (next && next.ticks < f.ticks) throw new UsageError(`${file}: decoded frame ${i + 1} is shown before frame ${i} (timestamps ${f.ticks}, ${next.ticks}): its frames cannot be put in time order`);
|
|
276
|
+
if (next && next.ticks === f.ticks) {
|
|
277
|
+
hidden++;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
shown.push({
|
|
281
|
+
f,
|
|
282
|
+
at: ms(f.ticks) - origin
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const split = shown.length > 1 ? options.split : void 0;
|
|
286
|
+
let splitFrames = 0;
|
|
287
|
+
const rows = [];
|
|
288
|
+
const gops = gopNumbers(frames);
|
|
289
|
+
for (const [k, { f, at }] of shown.entries()) {
|
|
290
|
+
const fields = split?.(f) === true;
|
|
291
|
+
const gop = gops[f.index];
|
|
292
|
+
rows.push({
|
|
293
|
+
index: rows.length,
|
|
294
|
+
atMs: at,
|
|
295
|
+
key: f.key,
|
|
296
|
+
gop,
|
|
297
|
+
decoded: f.index,
|
|
298
|
+
...fields ? { field: 0 } : {}
|
|
299
|
+
});
|
|
300
|
+
if (fields) {
|
|
301
|
+
splitFrames++;
|
|
302
|
+
const gap = k + 1 < shown.length ? shown[k + 1].at - at : at - shown[k - 1].at;
|
|
303
|
+
rows.push({
|
|
304
|
+
index: rows.length,
|
|
305
|
+
atMs: at + gap / 2,
|
|
306
|
+
key: false,
|
|
307
|
+
gop,
|
|
308
|
+
decoded: f.index,
|
|
309
|
+
field: 1
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const last = shown[shown.length - 1];
|
|
314
|
+
const endMs = last.f.durationTicks !== void 0 ? last.at + ms(last.f.durationTicks) : void 0;
|
|
315
|
+
return {
|
|
316
|
+
rows,
|
|
317
|
+
hidden,
|
|
318
|
+
...splitFrames > 0 ? {
|
|
319
|
+
fields: true,
|
|
320
|
+
splitFrames
|
|
321
|
+
} : {},
|
|
322
|
+
...endMs !== void 0 ? { endMs } : {}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/** Rows a looping image is unrolled to at most: past that, an instant is too far into the loop to write out. */
|
|
326
|
+
const MAX_LOOP_ROWS = 1e5;
|
|
327
|
+
/**
|
|
328
|
+
* The frames an animated GIF / APNG shows in a browser: each held for its stored delay, or 100ms
|
|
329
|
+
* when that is 10ms or less (Chromium 141 and 149, measured), and the animation repeated as the
|
|
330
|
+
* browser repeats it, as long as it plays. Unrolled up to `untilMs` — by default one pass and a
|
|
331
|
+
* second more, which holds every one-second window of a loop — so an instant or a span further on
|
|
332
|
+
* is the frame the loop has reached there, never the last one written. An APNG plays the frames
|
|
333
|
+
* its `acTL` declares, when it holds more (measured: Chromium never showed a third `fcTL` frame of
|
|
334
|
+
* an `acTL` saying two). Null when the file's own frame count is not the decoder's, or an APNG
|
|
335
|
+
* declares more than it holds.
|
|
336
|
+
*/
|
|
337
|
+
function imageTimeline(decoded, timing, untilMs) {
|
|
338
|
+
if (timing.storedMs.length !== decoded.length || decoded.length === 0) return null;
|
|
339
|
+
const declared = timing.declaredFrames;
|
|
340
|
+
if (declared !== void 0 && (declared < 1 || declared > decoded.length)) return null;
|
|
341
|
+
const n = declared ?? decoded.length;
|
|
342
|
+
const delays = timing.storedMs.slice(0, n).map(browserDelayMs);
|
|
343
|
+
const passMs = delays.reduce((a, b) => a + b, 0);
|
|
344
|
+
const until = n > 1 ? Math.max(untilMs ?? 0, passMs + 1e3) : 0;
|
|
345
|
+
const plays = timing.plays ?? Number.POSITIVE_INFINITY;
|
|
346
|
+
const rows = [];
|
|
347
|
+
let at = 0;
|
|
348
|
+
for (let p = 0; p < plays; p++) {
|
|
349
|
+
for (let k = 0; k < n; k++) {
|
|
350
|
+
if (rows.length >= n && at > until) break;
|
|
351
|
+
if (rows.length >= 1e5) throw new UsageError(`an instant ${Math.round(until)}ms into a looping image is more than ${MAX_LOOP_ROWS} of its frames away; the loop repeats every ${Math.round(passMs)}ms, so ask for one within its first passes`);
|
|
352
|
+
rows.push({
|
|
353
|
+
index: rows.length,
|
|
354
|
+
atMs: at,
|
|
355
|
+
key: decoded[k].key,
|
|
356
|
+
decoded: decoded[k].index
|
|
357
|
+
});
|
|
358
|
+
at += delays[k];
|
|
359
|
+
}
|
|
360
|
+
if (rows.length >= n && at > until) break;
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
rows,
|
|
364
|
+
hidden: 0,
|
|
365
|
+
timing: "browser",
|
|
366
|
+
loop: {
|
|
367
|
+
plays: timing.plays,
|
|
368
|
+
passFrames: n,
|
|
369
|
+
passMs,
|
|
370
|
+
passes: Math.ceil(rows.length / n)
|
|
371
|
+
},
|
|
372
|
+
...timing.plays !== null ? { endMs: Number.POSITIVE_INFINITY } : {}
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/** showinfo's own prefix: a recording's metadata printed at info level must not read as a frame. */
|
|
376
|
+
const SHOWINFO_LINE = /^\[(?:Parsed_showinfo_\d+|showinfo@(\w+)) @ (?:0x)?[0-9a-fA-F]+\] (?:\[info\] )?(.*)$/;
|
|
377
|
+
const SHOWINFO_FRAME = /^n:\s*(\d+)\s+pts:\s*(-?\d+)\b.*?\bs:(\d+)x(\d+)(?:.*?\biskey:([01]))?/;
|
|
378
|
+
const SHOWINFO_CONFIG = /^config in time_base:\s*(\d+)\/(\d+)/;
|
|
379
|
+
/** A line of ffmpeg's stderr: a showinfo frame, the time base showinfo counts in, or neither. */
|
|
380
|
+
function parseShowinfoLine(line) {
|
|
381
|
+
const prefix = line.match(SHOWINFO_LINE);
|
|
382
|
+
if (!prefix) return null;
|
|
383
|
+
const instance = prefix[1];
|
|
384
|
+
const body = prefix[2];
|
|
385
|
+
const named = instance !== void 0 ? { instance } : {};
|
|
386
|
+
const config = body.match(SHOWINFO_CONFIG);
|
|
387
|
+
if (config) return {
|
|
388
|
+
timeBase: {
|
|
389
|
+
num: Number(config[1]),
|
|
390
|
+
den: Number(config[2])
|
|
391
|
+
},
|
|
392
|
+
...named
|
|
393
|
+
};
|
|
394
|
+
const m = body.match(SHOWINFO_FRAME);
|
|
395
|
+
if (!m) return null;
|
|
396
|
+
return { frame: {
|
|
397
|
+
...named,
|
|
398
|
+
n: Number(m[1]),
|
|
399
|
+
pts: Number(m[2]),
|
|
400
|
+
width: Number(m[3]),
|
|
401
|
+
height: Number(m[4]),
|
|
402
|
+
...m[5] !== void 0 ? { key: m[5] === "1" } : {}
|
|
403
|
+
} };
|
|
404
|
+
}
|
|
405
|
+
/** HDR transfers: relative luminance, which WCAG 2.3.1's thresholds are written in, is an SDR quantity. */
|
|
406
|
+
const HDR_TRANSFERS = /* @__PURE__ */ new Set(["smpte2084", "arib-std-b67"]);
|
|
407
|
+
/** swscale's names for the YUV matrices ffprobe reports. */
|
|
408
|
+
const MATRIX_FOR = {
|
|
409
|
+
bt709: "bt709",
|
|
410
|
+
smpte170m: "smpte170m",
|
|
411
|
+
bt470bg: "bt470",
|
|
412
|
+
bt2020nc: "bt2020",
|
|
413
|
+
bt2020c: "bt2020",
|
|
414
|
+
fcc: "fcc",
|
|
415
|
+
smpte240m: "smpte240m"
|
|
416
|
+
};
|
|
417
|
+
/** The matrices `--color-matrix` takes: swscale's own names. */
|
|
418
|
+
const COLOR_MATRICES = [
|
|
419
|
+
"bt601",
|
|
420
|
+
"bt709",
|
|
421
|
+
"bt2020",
|
|
422
|
+
"smpte170m",
|
|
423
|
+
"bt470",
|
|
424
|
+
"fcc",
|
|
425
|
+
"smpte240m"
|
|
426
|
+
];
|
|
427
|
+
/** Primaries an sRGB display shows without a gamut conversion (BT.601's are close enough to be read as one). */
|
|
428
|
+
const SRGB_PRIMARIES = /* @__PURE__ */ new Set(["bt709", "smpte170m"]);
|
|
429
|
+
const isRgbFormat = (pixelFormat) => /^(rgb|bgr|argb|abgr|rgba|bgra|gbr|pal8|gray|ya|monob|monow|x?rgb)/.test(pixelFormat);
|
|
430
|
+
/**
|
|
431
|
+
* Codecs whose grey frames are a YUV stream's luma alone (AV1 Main 4:0:0, HEVC RExt, H.264 High
|
|
432
|
+
* 4:0:0): limited range unless tagged otherwise, as their colour is. A grey PNG, GIF or FFV1 frame
|
|
433
|
+
* is a picture's own grey levels.
|
|
434
|
+
*/
|
|
435
|
+
const LUMA_GRAY_CODECS = /* @__PURE__ */ new Set([
|
|
436
|
+
"h264",
|
|
437
|
+
"hevc",
|
|
438
|
+
"av1",
|
|
439
|
+
"vvc",
|
|
440
|
+
"vp9",
|
|
441
|
+
"mpeg4",
|
|
442
|
+
"jpeg2000"
|
|
443
|
+
]);
|
|
444
|
+
/**
|
|
445
|
+
* The conversion to 8-bit sRGB, stated rather than left to the decoder's default (measured with
|
|
446
|
+
* ffmpeg 6.1, `docs/reports/2026-10-13-scan-video-v1.md`):
|
|
447
|
+
*
|
|
448
|
+
* - A tagged matrix and range are the stream's own word and are used.
|
|
449
|
+
* - An untagged matrix is BT.601, and an untagged range limited: ffmpeg's own default at every
|
|
450
|
+
* size, Chromium's for VP9 at every size, and what ffmpeg's encoder and Playwright's recordVideo
|
|
451
|
+
* write. Chrome guesses BT.709 for untagged H.264 from 720 lines up, and that guess misreads
|
|
452
|
+
* ffmpeg's default 720p output by 39 levels, so it is not copied. What was assumed is recorded,
|
|
453
|
+
* and `--color-matrix` / `--color-range` override it: a wrong matrix flipped a green strobe's
|
|
454
|
+
* verdict (ΔL 0.229 read as 0.019).
|
|
455
|
+
* - `accurate_rnd+full_chroma_int` holds tagged colours to ±1 level (0 on 10-bit); the default
|
|
456
|
+
* rounding errs by 2 to 3, and `accurate_rnd` alone by more.
|
|
457
|
+
* - An HDR transfer is refused: ffmpeg passes PQ and HLG code values through as if SDR.
|
|
458
|
+
*/
|
|
459
|
+
function colorPlan(stream, file, override = {}) {
|
|
460
|
+
if (stream.colorTransfer && HDR_TRANSFERS.has(stream.colorTransfer)) throw new UsageError(`${file} is HDR (transfer ${stream.colorTransfer}): WCAG 2.3.1's luminance thresholds are for SDR, and ffmpeg passes HDR code values through as if they were SDR (100-nit white lands near 130/255). Tone-map it to the SDR version you publish and scan that, e.g. ffmpeg -i ${file} -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=hable,zscale=t=bt709:m=bt709:r=tv,format=yuv420p sdr.mp4 (zscale needs an ffmpeg built with libzimg)`);
|
|
461
|
+
if (override.matrix !== void 0 && !COLOR_MATRICES.includes(override.matrix)) throw new UsageError(`--color-matrix is one of ${COLOR_MATRICES.join(", ")} (got ${override.matrix})`);
|
|
462
|
+
const notes = [];
|
|
463
|
+
if (stream.colorPrimaries && !SRGB_PRIMARIES.has(stream.colorPrimaries)) notes.push(`primaries ${stream.colorPrimaries} shown as sRGB: the gamut is not converted`);
|
|
464
|
+
const extra = {
|
|
465
|
+
...stream.colorTransfer ? { transfer: stream.colorTransfer } : {},
|
|
466
|
+
...stream.colorPrimaries ? { primaries: stream.colorPrimaries } : {}
|
|
467
|
+
};
|
|
468
|
+
if (/^gray/.test(stream.pixelFormat) && (LUMA_GRAY_CODECS.has(stream.codec) || stream.colorRange === "tv" || override.range !== void 0)) {
|
|
469
|
+
const assumedRange = [];
|
|
470
|
+
let range;
|
|
471
|
+
if (override.range) range = override.range;
|
|
472
|
+
else if (stream.colorRange === "pc" || stream.colorRange === "tv") range = stream.colorRange;
|
|
473
|
+
else {
|
|
474
|
+
range = "tv";
|
|
475
|
+
assumedRange.push("range");
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
before: `scale=in_range=${range}:out_range=${range},${/^gray$/.test(stream.pixelFormat) ? "format=yuv444p" : "format=yuv444p16le"}`,
|
|
479
|
+
scale: `in_color_matrix=bt601:in_range=${range}:flags=accurate_rnd+full_chroma_int`,
|
|
480
|
+
color: {
|
|
481
|
+
matrix: "gray",
|
|
482
|
+
range,
|
|
483
|
+
...extra,
|
|
484
|
+
assumed: assumedRange
|
|
485
|
+
},
|
|
486
|
+
notes
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
if (isRgbFormat(stream.pixelFormat)) return {
|
|
490
|
+
scale: "",
|
|
491
|
+
color: {
|
|
492
|
+
matrix: "rgb",
|
|
493
|
+
range: "pc",
|
|
494
|
+
...extra,
|
|
495
|
+
assumed: []
|
|
496
|
+
},
|
|
497
|
+
notes
|
|
498
|
+
};
|
|
499
|
+
const assumed = [];
|
|
500
|
+
if (!override.matrix && stream.colorSpace && !MATRIX_FOR[stream.colorSpace] && stream.colorSpace !== "gbr") throw new UsageError(`${file} is tagged with the ${stream.colorSpace} matrix, which this conversion cannot apply: say which to read it with, --color-matrix ${COLOR_MATRICES.join(" | ")}`);
|
|
501
|
+
let matrix = override.matrix ?? (stream.colorSpace ? MATRIX_FOR[stream.colorSpace] : void 0);
|
|
502
|
+
if (!matrix) {
|
|
503
|
+
matrix = "bt601";
|
|
504
|
+
assumed.push("matrix");
|
|
505
|
+
if (stream.colorPrimaries === "bt709" || stream.colorTransfer === "bt709") notes.push("the stream tags BT.709 primaries or transfer but no matrix (a WebM container can say BT.709 where ffprobe cannot see it): if it was encoded as BT.709, pass --color-matrix bt709");
|
|
506
|
+
}
|
|
507
|
+
let range;
|
|
508
|
+
if (override.range) range = override.range;
|
|
509
|
+
else if (stream.colorRange === "pc" || stream.colorRange === "tv") range = stream.colorRange;
|
|
510
|
+
else if (/^yuvj/.test(stream.pixelFormat)) range = "pc";
|
|
511
|
+
else {
|
|
512
|
+
range = "tv";
|
|
513
|
+
assumed.push("range");
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
scale: `in_color_matrix=${matrix}:in_range=${range}:flags=accurate_rnd+full_chroma_int`,
|
|
517
|
+
color: {
|
|
518
|
+
matrix,
|
|
519
|
+
range,
|
|
520
|
+
...extra,
|
|
521
|
+
assumed
|
|
522
|
+
},
|
|
523
|
+
notes
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* The filter chain. Measured, each step's place: `select` first (it counts decoded frames);
|
|
528
|
+
* fields split before the colour conversion, and the line-doubling's doubled sample aspect undone
|
|
529
|
+
* (`scale` keeps the display aspect, so an 8:9 field came out 16:9 and the frame twice as wide);
|
|
530
|
+
* then the turn, if the chain does it; alpha composited after the conversion, by premultiplying (over
|
|
531
|
+
* black) or by premultiplying the negative and negating back (over white), so every frame keeps its
|
|
532
|
+
* timestamp — an `overlay` on a colour source would take that source's constant rate; the SAR
|
|
533
|
+
* resample after RGB, nearest, since bicubic in YUV blended a red/blue edge into (197,0,52); the
|
|
534
|
+
* colour tags and an ICC profile stripped only after `format=rgb24` (before it, the matrix falls
|
|
535
|
+
* back to BT.601); and showinfo without its checksums, which doubled the cost of a 1080p decode.
|
|
536
|
+
*/
|
|
537
|
+
function filterChain(plan) {
|
|
538
|
+
const rgb = plan.alpha ? "format=rgba" : "format=rgb24";
|
|
539
|
+
const composite = plan.alpha ? plan.alpha.background === "black" ? ["premultiply=inplace=1", "format=rgb24"] : [
|
|
540
|
+
"negate",
|
|
541
|
+
"premultiply=inplace=1",
|
|
542
|
+
"negate",
|
|
543
|
+
"format=rgb24"
|
|
544
|
+
] : [];
|
|
545
|
+
return [
|
|
546
|
+
plan.select,
|
|
547
|
+
...plan.fields ? [
|
|
548
|
+
...plan.fieldOrder ? [`setfield=${plan.fieldOrder}`] : [],
|
|
549
|
+
"separatefields",
|
|
550
|
+
"scale=w=iw:h=ih*2:flags=neighbor",
|
|
551
|
+
"setsar=r=sar/2:max=10000"
|
|
552
|
+
] : plan.lineDouble ? ["scale=w=iw:h=ih*2:flags=neighbor", "setsar=r=sar/2:max=10000"] : [],
|
|
553
|
+
...plan.rotate ?? [],
|
|
554
|
+
plan.color.before ?? null,
|
|
555
|
+
plan.color.scale ? `scale=${plan.color.scale}` : null,
|
|
556
|
+
rgb,
|
|
557
|
+
...composite,
|
|
558
|
+
...plan.sampleAspect ? ["scale=w='if(gte(sar,1),iw*sar,iw)':h='if(gte(sar,1),ih,ih/sar)':flags=neighbor", "setsar=1"] : [],
|
|
559
|
+
"setparams=color_primaries=unknown:color_trc=unknown:colorspace=unknown",
|
|
560
|
+
"sidedata=mode=delete:type=ICC_PROFILE",
|
|
561
|
+
plan.name ? `showinfo@${plan.name}=checksum=0` : "showinfo=checksum=0"
|
|
562
|
+
].filter(Boolean).join(",");
|
|
563
|
+
}
|
|
564
|
+
//#endregion
|
|
565
|
+
export { COLOR_MATRICES, LOSSLESS_CODECS, MAX_DISPLAY_PX, MAX_LOOP_ROWS, chooseFrames, colorPlan, displayGeometry, filterChain, frameAt, gopNumbers, imageTimeline, parseFrameTable, parseShowinfoLine, pickVideoStream, recordingEndMs, rotationFilters, videoTimeline };
|
package/dist/webp.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { PngData } from "./png-utils.mjs";
|
|
2
|
-
|
|
3
2
|
//#region src/webp.d.ts
|
|
4
|
-
declare const WEBP_ENCODER_PACKAGE = "@jsquash/webp";
|
|
5
|
-
interface WebpEncodeOptions {
|
|
3
|
+
export declare const WEBP_ENCODER_PACKAGE = "@jsquash/webp";
|
|
4
|
+
export interface WebpEncodeOptions {
|
|
6
5
|
/**
|
|
7
6
|
* Lossy quality 0-100. Omit for lossless, which is both smaller and
|
|
8
7
|
* artifact-free on UI screenshots — see the header.
|
|
@@ -14,18 +13,17 @@ interface WebpEncodeOptions {
|
|
|
14
13
|
* `cli-error.ts` uses for the Playwright diagnoses: the caller asked for webp
|
|
15
14
|
* explicitly, so "not installed" is the whole answer and a stack adds nothing.
|
|
16
15
|
*/
|
|
17
|
-
declare function formatMissingWebpEncoderError(error?: unknown): string;
|
|
18
|
-
declare class WebpEncoderMissingError extends Error {
|
|
16
|
+
export declare function formatMissingWebpEncoderError(error?: unknown): string;
|
|
17
|
+
export declare class WebpEncoderMissingError extends Error {
|
|
19
18
|
readonly name = "WebpEncoderMissingError";
|
|
20
19
|
}
|
|
21
20
|
/** 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>;
|
|
21
|
+
export declare function webpEncoderAvailable(): Promise<boolean>;
|
|
22
|
+
export declare function encodeWebp(image: PngData, options?: WebpEncodeOptions): Promise<Uint8Array>;
|
|
24
23
|
/**
|
|
25
24
|
* Which format a path asks for. Extension-driven so `--out strip.webp` needs no
|
|
26
25
|
* second flag, and an unknown extension is PNG rather than an error — the caller
|
|
27
26
|
* asked for a file, not for a format quiz.
|
|
28
27
|
*/
|
|
29
|
-
declare function imageFormatForPath(path: string): "png" | "webp";
|
|
30
|
-
//#endregion
|
|
31
|
-
export { WEBP_ENCODER_PACKAGE, WebpEncodeOptions, WebpEncoderMissingError, encodeWebp, formatMissingWebpEncoderError, imageFormatForPath, webpEncoderAvailable };
|
|
28
|
+
export declare function imageFormatForPath(path: string): "png" | "webp";
|
|
29
|
+
//#endregion
|
package/dist/webp.mjs
CHANGED
|
@@ -38,7 +38,8 @@ const WEBP_ENCODER_PACKAGE = "@jsquash/webp";
|
|
|
38
38
|
* explicitly, so "not installed" is the whole answer and a stack adds nothing.
|
|
39
39
|
*/
|
|
40
40
|
function formatMissingWebpEncoderError(error) {
|
|
41
|
-
|
|
41
|
+
const detail = error === void 0 ? "" : `\n (${String(error?.message ?? error).split("\n")[0]})`;
|
|
42
|
+
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.${detail}`;
|
|
42
43
|
}
|
|
43
44
|
var WebpEncoderMissingError = class extends Error {
|
|
44
45
|
name = "WebpEncoderMissingError";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mizchi/vlmkit-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "VRT diff engine + shared types — pure image / DOM / a11y / visual comparison primitives.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "mizchi",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"pixelmatch": "^7.1.0",
|
|
48
48
|
"pngjs": "^7.0.0",
|
|
49
|
-
"@mizchi/vlmkit-judge": "0.
|
|
49
|
+
"@mizchi/vlmkit-judge": "0.24.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"playwright": ">=1.61 <2",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
|
-
"build": "pnpm --dir ../.. exec
|
|
62
|
-
"test": "pnpm --dir ../.. exec
|
|
61
|
+
"build": "pnpm --dir ../.. exec vp pack --filter @mizchi/vlmkit-core",
|
|
62
|
+
"test": "pnpm --dir ../.. exec vp test run packages/vlmkit-core/src"
|
|
63
63
|
}
|
|
64
64
|
}
|