@mizchi/vlmkit-animation-eval 0.23.2 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,117 @@
1
+ import { PageLoadOptions } from "@mizchi/vlmkit-core/page-load.ts";
2
+ import { FrameEntry, FramesSource } from "@mizchi/vlmkit-judge/frames.ts";
3
+ import { Page } from "playwright";
4
+ export interface HeldAnimationTiming {
5
+ /** When it starts on the page timeline, delay included. */
6
+ startMs: number;
7
+ durationMs: number;
8
+ /** null = infinite. */
9
+ iterations: number | null;
10
+ }
11
+ /** What the held clocks still have to run (`VIRTUAL_CLOCK_SCRIPT`'s `pending()`), over every frame. */
12
+ export interface HeldPending {
13
+ /** Timers still to fire. */
14
+ timers: number;
15
+ /** Queued `requestAnimationFrame` callbacks. */
16
+ frames: number;
17
+ /** How many of the timers repeat. */
18
+ intervals: number;
19
+ /** The pages' `vlmkit:seek` listeners on their windows. */
20
+ seekListeners: number;
21
+ /** The latest one-shot timer's due time on the sweep's clock, or null when there is none. */
22
+ latestTimerMs: number | null;
23
+ }
24
+ export interface HeldTimeline {
25
+ /** Every animation held so far in every frame, timed on the sweep's clock. */
26
+ animations(): Promise<HeldAnimationTiming[]>;
27
+ /** What every frame's held clock still has to run, summed; the latest one-shot on the sweep's clock. */
28
+ pending(): Promise<HeldPending>;
29
+ /** Advance the clock to `t` ms of page time and seek every held animation there, in every frame. */
30
+ at(t: number): Promise<void>;
31
+ /** How many times the page has moved to a new document since it was opened. */
32
+ navigations(): number;
33
+ }
34
+ /** More navigations than this during one sweep and `at` throws. */
35
+ export declare const MAX_SWEEP_NAVIGATIONS = 5;
36
+ /** Instants added to the animation-derived ones, so script-driven motion is sampled too. */
37
+ export declare const COARSE_GRID_MS: number[];
38
+ /**
39
+ * The instants to look at a page's motion at when the caller names none: each finite
40
+ * animation's start, middle and end (`timelineInstants`), plus a coarse grid for what moves
41
+ * by script.
42
+ */
43
+ export declare function defaultTimelineInstants(held: readonly HeldAnimationTiming[]): number[];
44
+ /**
45
+ * Load `url` into `page` with the page clock held from document start (`VIRTUAL_CLOCK_SCRIPT`)
46
+ * and every animation held from the instant it begins (`HOLD_TIMELINE_SCRIPT`), and run the
47
+ * zero-delay work queued during load at virtual 0, with everything held by then put at 0. Init
48
+ * scripts do not run for `setContent`, so the page has to be navigated to.
49
+ *
50
+ * Every frame of the page is advanced and seeked at each instant: init scripts run in every
51
+ * frame, so each iframe has a clock of its own, and before this one held only the main frame's
52
+ * (an iframe's rAF loop and CSS animations sat at 0 for the whole sweep). Each frame's document
53
+ * keeps its own offset: the sweep instant it was first seen at, so an iframe inserted at 1000ms
54
+ * starts at its own 0 there instead of being advanced 1000ms in one step (which ran a strobe's
55
+ * every toggle at once), and one that navigates starts again at the instant its new document is
56
+ * first seen. A frame that detaches, has no clock, or does not answer within 10s is skipped.
57
+ * `animations()` and `pending()` read every frame, each on the sweep's clock; a document they find
58
+ * that no instant has reached yet is put at its own 0 first, at the sweep's present instant.
59
+ *
60
+ * A page may navigate during the sweep (a splash that forwards itself, a timer that follows a
61
+ * link): the new document's clock starts at 0, and the page time it began at becomes its offset
62
+ * — at `t` it is advanced to `t - offset`. That time is read from the old document's
63
+ * `beforeunload` (`takeLeftAt`) when the step that navigated returned; when the old document was
64
+ * destroyed under the step instead, it is the instant being reached, late by at most that step.
65
+ * More than `MAX_SWEEP_NAVIGATIONS` navigations throw.
66
+ */
67
+ export declare function openHeldTimeline(page: Page, url: string, options?: PageLoadOptions): Promise<HeldTimeline>;
68
+ /**
69
+ * Screenshot until two consecutive shots are byte-identical, at most `maxShots` (default 3).
70
+ * `stable: false` = they never agreed; the last shot is returned.
71
+ *
72
+ * `clock`, when given, is read just before each shot, and `at` is its reading for the picture
73
+ * returned — the first of an agreeing pair (the page showed it from then), or the last shot when
74
+ * none agreed. A reading taken before the call would be early by every shot it took.
75
+ */
76
+ export declare function captureStable(page: Page, options?: {
77
+ maxShots?: number;
78
+ clock?: () => Promise<number>;
79
+ }): Promise<{
80
+ png: Buffer;
81
+ stable: boolean;
82
+ at?: number;
83
+ }>;
84
+ /** What a sequence's writer reports once it is done. */
85
+ export interface FramesWritten {
86
+ dir: string;
87
+ /** `frames.json`, absolute. */
88
+ manifest: string;
89
+ count: number;
90
+ /** Frames whose captures never agreed. */
91
+ unstable: number;
92
+ /** Every frame file, absolute, in sequence order. */
93
+ files: string[];
94
+ }
95
+ /** `chromium 141.0.7390.37`, device pixel ratio: the facts a frame's pixels depend on. */
96
+ export declare function frameSourceFacts(page: Page): Promise<Pick<FramesSource, "browser" | "deviceScaleFactor">>;
97
+ /**
98
+ * Write a sequence into `dir`: each frame as it is added, `frames.json` at `finish`. Frames a
99
+ * previous run left there (files named like a frame, and `frames.json`) are removed first, so
100
+ * a glob of the directory is always one sequence; nothing else in it is touched.
101
+ */
102
+ export declare function frameWriter(dir: string, source: FramesSource): Promise<{
103
+ add(png: Buffer, entry: Omit<FrameEntry, "n" | "file">): Promise<string>;
104
+ finish(): Promise<FramesWritten>;
105
+ }>;
106
+ /**
107
+ * The viewport, uncropped, at each instant of its own time, as a sequence: `openHeldTimeline`, then for
108
+ * each instant `at` + `captureStable`. `instants` defaults to `defaultTimelineInstants`.
109
+ */
110
+ export declare function captureTimelineFrames(page: Page, url: string, options: PageLoadOptions & {
111
+ dir: string;
112
+ tool: string;
113
+ instants?: readonly number[];
114
+ reducedMotion?: boolean;
115
+ }): Promise<FramesWritten & {
116
+ instants: number[];
117
+ }>;
@@ -0,0 +1,421 @@
1
+ import { HOLD_TIMELINE_SCRIPT, VIRTUAL_CLOCK_SCRIPT } from "./virtual-clock.mjs";
2
+ import { mkdir, readdir, unlink, writeFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { navigationOptions } from "@mizchi/vlmkit-core/page-load.ts";
5
+ import { applyHar, settlePage } from "@mizchi/vlmkit-core/page-open.ts";
6
+ import { FRAMES_FORMAT, frameFileName } from "@mizchi/vlmkit-judge/frames.ts";
7
+ import { timelineInstants } from "@mizchi/vlmkit-judge/persistence.ts";
8
+ // src/frames-capture.ts
9
+ /**
10
+ * Frames at chosen instants: the page loaded with its clock and animations held, moved to an
11
+ * instant of its own time, captured, and written as a `vlmkit-frames/1` sequence.
12
+ *
13
+ * One copy of the hold / advance / seek loop for every caller: `check integrity --timeline`
14
+ * judges at each instant, `check animation --frames` captures at each one, and `inspect interact`
15
+ * writes its `frames` steps through the same writer. Before this the loop lived inside
16
+ * integrity's timeline, and a second caller would have been a second copy of it.
17
+ *
18
+ * A capture is taken until two consecutive shots agree, at most three. On the held clock the
19
+ * seek is synchronous but the compositor is not: `check animation` measured a capture landing
20
+ * before a seek was applied in 2 runs of 30. Two equal shots rule that out. Three that never
21
+ * agree mean something moves that nothing here holds — a `<video>`, an animated image, a worker
22
+ * — and the frame is written with `stable: false` instead of being passed off as the instant.
23
+ */
24
+ /** More navigations than this during one sweep and `at` throws. */
25
+ const MAX_SWEEP_NAVIGATIONS = 5;
26
+ /** How long a document the page navigates to may take to commit and to load; and a frame to answer. */
27
+ const NAVIGATION_WAIT_MS = 1e4;
28
+ const NAVIGATED = /Execution context was destroyed|navigat|Cannot find context/i;
29
+ /**
30
+ * One instant in one frame, run in the page: the clock advanced to `target - offset`, every held
31
+ * animation seeked there, and the page time the document began to leave at, if it did. `known` is
32
+ * the frame's document as the sweep last put it. In the main frame another document answers
33
+ * `fresh` before anything is advanced (a navigation that committed between two instants), since
34
+ * advancing it to the old document's time would start it late; the caller then decides its offset.
35
+ * In any other frame a document not seen before (an iframe inserted or navigated since) begins at
36
+ * this instant: its offset is `target`, so it is put at its own 0, and its first seconds are not
37
+ * run in one step.
38
+ *
39
+ * A seek that ended an animation is followed by the browser's next rendering, where its finish
40
+ * event is dispatched (its finished promise resolved within the seek), then seeked again: what the
41
+ * page starts there can end before the instant too. At most 16 such stages in one instant.
42
+ */
43
+ const stepFrame = async ({ target, known, main }) => {
44
+ const origin = performance.timeOrigin;
45
+ if (main && known !== null && known.origin !== origin) return { fresh: true };
46
+ const w = window;
47
+ const clock = w.__vlmkitClock;
48
+ if (!clock) return { noClock: true };
49
+ const offset = known !== null && known.origin === origin ? known.offset : target;
50
+ const ms = target - offset;
51
+ await clock.advanceTo(ms);
52
+ const seek = () => Number(w.__vlmkitSeekTimeline ? w.__vlmkitSeekTimeline(ms) : 0) || 0;
53
+ for (let ended = seek(), round = 0; ended > 0 && round < 16; round++) {
54
+ if (clock.rendered) await clock.rendered();
55
+ ended = seek();
56
+ }
57
+ return {
58
+ clock: {
59
+ origin,
60
+ offset
61
+ },
62
+ leftAt: clock.takeLeftAt ? clock.takeLeftAt() : null
63
+ };
64
+ };
65
+ /** A frame's held list and pending work, when its document is the one `known` describes. */
66
+ const readFrame = ({ known, main }) => {
67
+ if (known === null || known.origin !== performance.timeOrigin) return main ? { fresh: true } : { unknown: true };
68
+ const w = window;
69
+ if (!w.__vlmkitClock) return null;
70
+ return {
71
+ animations: w.__vlmkitTimelineAnimations ? w.__vlmkitTimelineAnimations() : [],
72
+ pending: w.__vlmkitClock.pending ? w.__vlmkitClock.pending() : null
73
+ };
74
+ };
75
+ /** `promise`, or undefined once `ms` have passed. */
76
+ function within(promise, ms) {
77
+ return new Promise((resolve, reject) => {
78
+ const timer = setTimeout(() => resolve(void 0), ms);
79
+ promise.then((value) => {
80
+ clearTimeout(timer);
81
+ resolve(value);
82
+ }, (error) => {
83
+ clearTimeout(timer);
84
+ reject(error);
85
+ });
86
+ });
87
+ }
88
+ /** Instants added to the animation-derived ones, so script-driven motion is sampled too. */
89
+ const COARSE_GRID_MS = [
90
+ 0,
91
+ 250,
92
+ 500,
93
+ 1e3,
94
+ 2e3
95
+ ];
96
+ /**
97
+ * The instants to look at a page's motion at when the caller names none: each finite
98
+ * animation's start, middle and end (`timelineInstants`), plus a coarse grid for what moves
99
+ * by script.
100
+ */
101
+ function defaultTimelineInstants(held) {
102
+ return [.../* @__PURE__ */ new Set([...timelineInstants(held), ...COARSE_GRID_MS])].sort((a, b) => a - b);
103
+ }
104
+ /**
105
+ * Load `url` into `page` with the page clock held from document start (`VIRTUAL_CLOCK_SCRIPT`)
106
+ * and every animation held from the instant it begins (`HOLD_TIMELINE_SCRIPT`), and run the
107
+ * zero-delay work queued during load at virtual 0, with everything held by then put at 0. Init
108
+ * scripts do not run for `setContent`, so the page has to be navigated to.
109
+ *
110
+ * Every frame of the page is advanced and seeked at each instant: init scripts run in every
111
+ * frame, so each iframe has a clock of its own, and before this one held only the main frame's
112
+ * (an iframe's rAF loop and CSS animations sat at 0 for the whole sweep). Each frame's document
113
+ * keeps its own offset: the sweep instant it was first seen at, so an iframe inserted at 1000ms
114
+ * starts at its own 0 there instead of being advanced 1000ms in one step (which ran a strobe's
115
+ * every toggle at once), and one that navigates starts again at the instant its new document is
116
+ * first seen. A frame that detaches, has no clock, or does not answer within 10s is skipped.
117
+ * `animations()` and `pending()` read every frame, each on the sweep's clock; a document they find
118
+ * that no instant has reached yet is put at its own 0 first, at the sweep's present instant.
119
+ *
120
+ * A page may navigate during the sweep (a splash that forwards itself, a timer that follows a
121
+ * link): the new document's clock starts at 0, and the page time it began at becomes its offset
122
+ * — at `t` it is advanced to `t - offset`. That time is read from the old document's
123
+ * `beforeunload` (`takeLeftAt`) when the step that navigated returned; when the old document was
124
+ * destroyed under the step instead, it is the instant being reached, late by at most that step.
125
+ * More than `MAX_SWEEP_NAVIGATIONS` navigations throw.
126
+ */
127
+ async function openHeldTimeline(page, url, options = {}) {
128
+ await page.addInitScript(VIRTUAL_CLOCK_SCRIPT);
129
+ await page.addInitScript(HOLD_TIMELINE_SCRIPT);
130
+ await applyHar(page, options.har);
131
+ await page.goto(url, navigationOptions(options));
132
+ await settlePage(page, 0, 0);
133
+ let offset = 0;
134
+ let navigations = 0;
135
+ let origin = null;
136
+ let opened = false;
137
+ let lastAt = 0;
138
+ const stalled = /* @__PURE__ */ new WeakSet();
139
+ const clocks = /* @__PURE__ */ new WeakMap();
140
+ const others = () => page.frames().filter((frame) => frame !== page.mainFrame() && !stalled.has(frame));
141
+ /** Put one frame that is not the main one at sweep instant `target`; its clock, if it answered. */
142
+ const stepOther = async (frame, target) => {
143
+ try {
144
+ const answered = await within(frame.evaluate(stepFrame, {
145
+ target,
146
+ known: clocks.get(frame) ?? null,
147
+ main: false
148
+ }), NAVIGATION_WAIT_MS);
149
+ if (answered === void 0) stalled.add(frame);
150
+ else if ("clock" in answered) {
151
+ clocks.set(frame, answered.clock);
152
+ return answered.clock;
153
+ }
154
+ } catch {}
155
+ };
156
+ const put = async (target) => {
157
+ try {
158
+ if (origin === null) origin = await page.evaluate(() => performance.timeOrigin);
159
+ const step = await page.mainFrame().evaluate(stepFrame, {
160
+ target,
161
+ known: {
162
+ origin,
163
+ offset
164
+ },
165
+ main: true
166
+ });
167
+ if ("fresh" in step) return { kind: "fresh" };
168
+ if ("noClock" in step) throw new Error(`openHeldTimeline: the page has no held clock (${page.url()})`);
169
+ lastAt = target;
170
+ await Promise.all(others().map((frame) => stepOther(frame, target)));
171
+ return step.leftAt === null ? { kind: "ok" } : {
172
+ kind: "left",
173
+ at: offset + step.leftAt
174
+ };
175
+ } catch (error) {
176
+ if (!NAVIGATED.test(String(error))) throw error;
177
+ return { kind: "destroyed" };
178
+ }
179
+ };
180
+ const committed = async () => {
181
+ const deadline = Date.now() + NAVIGATION_WAIT_MS;
182
+ while (Date.now() < deadline) {
183
+ try {
184
+ const now = await within(page.evaluate(() => performance.timeOrigin), deadline - Date.now());
185
+ if (now !== void 0 && now !== origin) return true;
186
+ } catch (error) {
187
+ if (!NAVIGATED.test(String(error))) throw error;
188
+ return true;
189
+ }
190
+ await new Promise((resolve) => setTimeout(resolve, 25));
191
+ }
192
+ return false;
193
+ };
194
+ const navigated = async (at) => {
195
+ navigations += 1;
196
+ if (navigations > 5) throw new Error(`page navigated more than 5 times during the sweep`);
197
+ offset = at;
198
+ lastAt = at;
199
+ origin = null;
200
+ opened = false;
201
+ await page.waitForLoadState("load", { timeout: NAVIGATION_WAIT_MS }).catch(() => {});
202
+ await settlePage(page, 0, 0);
203
+ };
204
+ const at = async (t) => {
205
+ for (;;) {
206
+ const opening = !opened;
207
+ const target = opening ? offset : t;
208
+ const outcome = await put(target);
209
+ if (outcome.kind === "fresh") {
210
+ await navigated(lastAt);
211
+ continue;
212
+ }
213
+ if (outcome.kind === "destroyed") {
214
+ await navigated(target);
215
+ continue;
216
+ }
217
+ if (outcome.kind === "left" && await committed()) {
218
+ await navigated(outcome.at);
219
+ continue;
220
+ }
221
+ opened = true;
222
+ if (!opening || target === t) return;
223
+ }
224
+ };
225
+ /** One frame that is not the main one, read; a document no instant has reached yet is put at its 0 first. */
226
+ const readOther = async (frame) => {
227
+ for (let attempt = 0; attempt < 2; attempt++) {
228
+ let read;
229
+ try {
230
+ read = await within(frame.evaluate(readFrame, {
231
+ known: clocks.get(frame) ?? null,
232
+ main: false
233
+ }), NAVIGATION_WAIT_MS);
234
+ } catch {
235
+ return null;
236
+ }
237
+ if (read === void 0) stalled.add(frame);
238
+ if (!read || "fresh" in read) return null;
239
+ if ("unknown" in read) {
240
+ if (!await stepOther(frame, lastAt)) return null;
241
+ continue;
242
+ }
243
+ return {
244
+ offset: clocks.get(frame).offset,
245
+ ...read
246
+ };
247
+ }
248
+ return null;
249
+ };
250
+ /** Every frame's held list and pending work, the main frame first, each with its offset. */
251
+ const readAll = async () => {
252
+ for (;;) {
253
+ let main = { fresh: true };
254
+ try {
255
+ main = await page.mainFrame().evaluate(readFrame, {
256
+ known: origin === null ? null : {
257
+ origin,
258
+ offset
259
+ },
260
+ main: true
261
+ });
262
+ } catch (error) {
263
+ if (!NAVIGATED.test(String(error))) throw error;
264
+ }
265
+ if (main && ("fresh" in main || "unknown" in main)) {
266
+ await at(lastAt);
267
+ continue;
268
+ }
269
+ const rest = await Promise.all(others().map(readOther));
270
+ return [{
271
+ offset,
272
+ animations: main?.animations ?? [],
273
+ pending: main?.pending ?? null
274
+ }, ...rest.filter((r) => r !== null)];
275
+ }
276
+ };
277
+ await at(0);
278
+ return {
279
+ animations: async () => (await readAll()).flatMap((r) => r.animations.map((a) => ({
280
+ ...a,
281
+ startMs: a.startMs + r.offset
282
+ }))),
283
+ pending: async () => {
284
+ const total = {
285
+ timers: 0,
286
+ frames: 0,
287
+ intervals: 0,
288
+ seekListeners: 0,
289
+ latestTimerMs: null
290
+ };
291
+ for (const { offset: frameOffset, pending } of await readAll()) {
292
+ if (!pending) continue;
293
+ total.timers += pending.timers;
294
+ total.frames += pending.frames;
295
+ total.intervals += pending.intervals ?? 0;
296
+ total.seekListeners += pending.seekListeners ?? 0;
297
+ if (pending.latestTimerMs !== null && pending.latestTimerMs !== void 0) {
298
+ const due = pending.latestTimerMs + frameOffset;
299
+ total.latestTimerMs = total.latestTimerMs === null ? due : Math.max(total.latestTimerMs, due);
300
+ }
301
+ }
302
+ return total;
303
+ },
304
+ at,
305
+ navigations: () => navigations
306
+ };
307
+ }
308
+ /**
309
+ * Screenshot until two consecutive shots are byte-identical, at most `maxShots` (default 3).
310
+ * `stable: false` = they never agreed; the last shot is returned.
311
+ *
312
+ * `clock`, when given, is read just before each shot, and `at` is its reading for the picture
313
+ * returned — the first of an agreeing pair (the page showed it from then), or the last shot when
314
+ * none agreed. A reading taken before the call would be early by every shot it took.
315
+ */
316
+ async function captureStable(page, options = {}) {
317
+ const shoot = async () => {
318
+ return {
319
+ at: options.clock ? await options.clock() : void 0,
320
+ png: await page.screenshot({ animations: "allow" })
321
+ };
322
+ };
323
+ const stamp = (at) => at === void 0 ? {} : { at };
324
+ let previous = await shoot();
325
+ for (let shot = 1; shot < Math.max(2, options.maxShots ?? 3); shot++) {
326
+ const next = await shoot();
327
+ if (next.png.equals(previous.png)) return {
328
+ png: next.png,
329
+ stable: true,
330
+ ...stamp(previous.at)
331
+ };
332
+ previous = next;
333
+ }
334
+ return {
335
+ png: previous.png,
336
+ stable: false,
337
+ ...stamp(previous.at)
338
+ };
339
+ }
340
+ /** `chromium 141.0.7390.37`, device pixel ratio: the facts a frame's pixels depend on. */
341
+ async function frameSourceFacts(page) {
342
+ const browser = page.context().browser();
343
+ return {
344
+ deviceScaleFactor: await page.evaluate(() => window.devicePixelRatio),
345
+ ...browser ? { browser: `${browser.browserType().name()} ${browser.version()}` } : {}
346
+ };
347
+ }
348
+ /** A frame file this writer would have written: `0006-t000100.png`. */
349
+ const FRAME_FILE = /^\d{4,}-t\d{6,}\.png$/;
350
+ /**
351
+ * Write a sequence into `dir`: each frame as it is added, `frames.json` at `finish`. Frames a
352
+ * previous run left there (files named like a frame, and `frames.json`) are removed first, so
353
+ * a glob of the directory is always one sequence; nothing else in it is touched.
354
+ */
355
+ async function frameWriter(dir, source) {
356
+ await mkdir(dir, { recursive: true });
357
+ for (const name of await readdir(dir)) if (FRAME_FILE.test(name) || name === "frames.json") await unlink(join(dir, name));
358
+ const frames = [];
359
+ return {
360
+ async add(png, entry) {
361
+ const n = frames.length;
362
+ const file = frameFileName(n, entry.atMs);
363
+ await writeFile(join(dir, file), png);
364
+ frames.push({
365
+ n,
366
+ file,
367
+ ...entry
368
+ });
369
+ return join(dir, file);
370
+ },
371
+ async finish() {
372
+ const manifest = {
373
+ format: FRAMES_FORMAT,
374
+ source,
375
+ frames
376
+ };
377
+ const path = join(dir, "frames.json");
378
+ await writeFile(path, `${JSON.stringify(manifest, null, 2)}\n`);
379
+ return {
380
+ dir,
381
+ manifest: path,
382
+ count: frames.length,
383
+ unstable: frames.filter((f) => !f.stable).length,
384
+ files: frames.map((f) => join(dir, f.file))
385
+ };
386
+ }
387
+ };
388
+ }
389
+ /**
390
+ * The viewport, uncropped, at each instant of its own time, as a sequence: `openHeldTimeline`, then for
391
+ * each instant `at` + `captureStable`. `instants` defaults to `defaultTimelineInstants`.
392
+ */
393
+ async function captureTimelineFrames(page, url, options) {
394
+ if (options.reducedMotion) await page.emulateMedia({ reducedMotion: "reduce" });
395
+ const timeline = await openHeldTimeline(page, url, options);
396
+ const instants = options.instants && options.instants.length > 0 ? [...new Set(options.instants)].sort((a, b) => a - b) : defaultTimelineInstants(await timeline.animations());
397
+ const writer = await frameWriter(options.dir, {
398
+ tool: options.tool,
399
+ url,
400
+ viewport: page.viewportSize() ?? {
401
+ width: 0,
402
+ height: 0
403
+ },
404
+ ...await frameSourceFacts(page),
405
+ clock: "held",
406
+ ...options.reducedMotion ? { reducedMotion: true } : {}
407
+ });
408
+ for (const atMs of instants) {
409
+ await timeline.at(atMs);
410
+ const { png, stable } = await captureStable(page);
411
+ await writer.add(png, {
412
+ atMs,
413
+ stable
414
+ });
415
+ }
416
+ return {
417
+ ...await writer.finish(),
418
+ instants
419
+ };
420
+ }
421
+ export { COARSE_GRID_MS, MAX_SWEEP_NAVIGATIONS, captureStable, captureTimelineFrames, defaultTimelineInstants, frameSourceFacts, frameWriter, openHeldTimeline };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { HOLD_TIMELINE_SCRIPT, VIRTUAL_CLOCK_SCRIPT } from "./virtual-clock.mjs";
2
1
  import { clockSettledAt, computeOscillation, computeSettleMs, deriveAnimationIssues, formatAnimationEvalReport, frameDelta, restTimeForAnimation, runAnimationEval, unionBbox } from "./animation-eval.mjs";
2
+ import { HOLD_TIMELINE_SCRIPT, VIRTUAL_CLOCK_SCRIPT } from "./virtual-clock.mjs";
3
3
  export { HOLD_TIMELINE_SCRIPT, VIRTUAL_CLOCK_SCRIPT, clockSettledAt, computeOscillation, computeSettleMs, deriveAnimationIssues, formatAnimationEvalReport, frameDelta, restTimeForAnimation, runAnimationEval, unionBbox };