@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.
package/README.md CHANGED
@@ -7,12 +7,10 @@ any pixels at all, when the page settles, whether `prefers-reduced-motion`
7
7
  is honoured behaviourally, and whether something outside the Web Animations
8
8
  API (rAF, video, GIF) is moving the page on its own.
9
9
 
10
- It is the measurement behind two commands that live in different tools:
11
-
12
- - `vlmkit check animation page.html` — the gate, with rule settings, `--json`,
13
- `--strip` filmstrips and the run ledger (package `@mizchi/vlmkit-markup`).
14
- - `vlmkit-anim eval page.html` — the same report from the animation authoring
15
- tool, on the pages it emits (package `@mizchi/vlmkit-anim`).
10
+ It is the measurement behind `vlmkit check animation page.html` — the gate,
11
+ with rule settings, `--json`, `--strip` filmstrips and the run ledger (package
12
+ `@mizchi/vlmkit-markup`) — and its clock holds `check integrity --timeline`.
13
+ Use it directly to get the same report without the rest of vlmkit.
16
14
 
17
15
  ```ts
18
16
  import { runAnimationEval, formatAnimationEvalReport } from "@mizchi/vlmkit-animation-eval";
@@ -32,4 +30,10 @@ exported on its own as `VIRTUAL_CLOCK_SCRIPT` (`virtual-clock.ts`).
32
30
 
33
31
  `playwright` is a required peer: the whole job is driving a browser. Depends
34
32
  on `@mizchi/vlmkit-core` for page loading, browser launch and PNG utilities,
35
- and on nothing else in the workspace.
33
+ and on `@mizchi/vlmkit-judge` (pure, no dependencies of its own) for the frame
34
+ format and the instants a timeline is sampled at.
35
+
36
+ `frames-capture.ts` is the frames half: the page at chosen instants of its own
37
+ time (`captureTimelineFrames`), written as `vlmkit-frames/1` — numbered PNGs
38
+ plus a `frames.json` — which `check animation --frames` and
39
+ `check integrity --timeline --frames` both write.
@@ -1,8 +1,6 @@
1
1
  import { PageLoadOptions } from "@mizchi/vlmkit-core/page-load.ts";
2
2
  import { RuleView } from "@mizchi/vlmkit-core/plugin/contract.ts";
3
-
4
- //#region src/animation-eval.d.ts
5
- interface AnimationTimingSample {
3
+ export interface AnimationTimingSample {
6
4
  /** Index into the page's animation list at capture time. */
7
5
  index: number;
8
6
  /** Best-effort stable selector of the animation's effect target. */
@@ -12,6 +10,8 @@ interface AnimationTimingSample {
12
10
  name: string;
13
11
  durationMs: number;
14
12
  delayMs: number;
13
+ /** The timing function: the effect's, or a CSS animation's keyframes' ("a / b" when they differ). */
14
+ easing?: string;
15
15
  /** null = infinite. */
16
16
  iterations: number | null;
17
17
  /** Play state as found on the page, captured BEFORE the evaluator pauses it. */
@@ -26,8 +26,14 @@ interface AnimationTimingSample {
26
26
  * sweep even without `alternate`.
27
27
  */
28
28
  palindromic: boolean;
29
+ /** The properties its keyframes animate (camelCase, as getKeyframes names them). */
30
+ properties?: string[];
31
+ /** animation-fill-mode as computed: none / forwards / backwards / both / auto. */
32
+ fill?: string;
33
+ /** Its first keyframe leaves the element unseen (opacity 0 or visibility hidden). */
34
+ startsHidden?: boolean;
29
35
  }
30
- interface OscillationInfo {
36
+ export interface OscillationInfo {
31
37
  /** The animation sweeps out and back rather than jumping to restart. */
32
38
  oscillating: boolean;
33
39
  /** Duration of one visual leg (one extreme to the other), in ms. */
@@ -43,8 +49,8 @@ interface OscillationInfo {
43
49
  * iteration per leg; palindromic keyframes complete out-and-back within a
44
50
  * single iteration, so each leg is half the duration.
45
51
  */
46
- declare function computeOscillation(t: Pick<AnimationTimingSample, "durationMs" | "direction" | "palindromic">): OscillationInfo;
47
- interface FrameDeltaStat {
52
+ export declare function computeOscillation(t: Pick<AnimationTimingSample, "durationMs" | "direction" | "palindromic">): OscillationInfo;
53
+ export interface FrameDeltaStat {
48
54
  changedPixels: number;
49
55
  /** changedPixels / total pixels. */
50
56
  ratio: number;
@@ -56,11 +62,11 @@ interface FrameDeltaStat {
56
62
  height: number;
57
63
  } | null;
58
64
  }
59
- interface AnimationFrameStat extends FrameDeltaStat {
65
+ export interface AnimationFrameStat extends FrameDeltaStat {
60
66
  /** Sampled progress through one iteration (0..1]. */
61
67
  fraction: number;
62
68
  }
63
- interface EvaluatedAnimation extends AnimationTimingSample {
69
+ export interface EvaluatedAnimation extends AnimationTimingSample {
64
70
  frames: AnimationFrameStat[];
65
71
  /** Any sampled interval moved at least minChangedPixels pixels. */
66
72
  visible: boolean;
@@ -71,6 +77,14 @@ interface EvaluatedAnimation extends AnimationTimingSample {
71
77
  width: number;
72
78
  height: number;
73
79
  } | null;
80
+ /** The animated element's own border box at rest, when its selector still matches. */
81
+ elementBox?: {
82
+ x: number;
83
+ y: number;
84
+ width: number;
85
+ height: number;
86
+ topmost?: number;
87
+ };
74
88
  totalChangedPixels: number;
75
89
  maxFrameRatio: number;
76
90
  /**
@@ -96,7 +110,7 @@ interface EvaluatedAnimation extends AnimationTimingSample {
96
110
  * was the page's own restart. HyperFrames' `sweep_static` guards the same thing from the other
97
111
  * side: a sweep whose seeks did nothing makes every other green meaningless.
98
112
  */
99
- interface SeekIneffective {
113
+ export interface SeekIneffective {
100
114
  reason: "readback" | "replay";
101
115
  /** Readback: what the Animation reported instead. Replay: pixels that differed inside the motion region. */
102
116
  detail: string;
@@ -105,7 +119,7 @@ interface SeekIneffective {
105
119
  * Motion driven by the page's own script — rAF loops, timers, a canvas — sampled by advancing
106
120
  * the virtual clock (`virtual-clock.ts`) with every WAAPI animation held at rest.
107
121
  */
108
- interface ClockMotion {
122
+ export interface ClockMotion {
109
123
  /** Virtual-time span sampled, from document start. */
110
124
  windowMs: number;
111
125
  /** The instant of each sample, in ms of virtual time. */
@@ -126,40 +140,97 @@ interface ClockMotion {
126
140
  settledAtMs: number | null;
127
141
  /** Exceptions thrown by page callbacks while the clock advanced (they do not stop it). */
128
142
  errors: string[];
143
+ /**
144
+ * CSS transitions and animations that came into being while the clock advanced — begun by a
145
+ * timer or a script, so the sweep's motion may be theirs and not a requestAnimationFrame loop.
146
+ */
147
+ started?: Array<{
148
+ selector: string;
149
+ name: string;
150
+ kind: "transition" | "animation";
151
+ /** The sweep instant it was first seen at; `afterMs` is the instant before it, when it was not. */
152
+ atMs: number;
153
+ afterMs?: number;
154
+ durationMs?: number;
155
+ }>;
156
+ /**
157
+ * An animation already seen begun again while the clock ran — on a new element (a re-render
158
+ * replaced it) or on the same one. A quote whose innerHTML was rebuilt every second replayed
159
+ * its price's entrance, and under --virtual-time it read "visible" and nothing else (round 11).
160
+ */
161
+ replays?: Array<{
162
+ selector: string;
163
+ name: string;
164
+ atMs: number[];
165
+ newElement: boolean;
166
+ }>;
167
+ /**
168
+ * What the clock ran in the window: animation-frame callbacks and timer runs. With no frame
169
+ * callback and timers at most 5 a second, the pixels change only when a timer updates the page
170
+ * (a clock, a live value): updates, not motion.
171
+ */
172
+ runs?: {
173
+ frames: number;
174
+ timers: number;
175
+ };
129
176
  }
177
+ /** Pure: the sweep's pixels changed only as a slow timer updated the page (no animation frames). */
178
+ export declare function clockUpdatesOnly(clock: Pick<ClockMotion, "runs" | "started" | "replays" | "windowMs">): boolean;
179
+ /** Pure: what a clock sweep's motion is, named as far as the page let it be. */
180
+ export declare function clockMotionSource(clock: Pick<ClockMotion, "started">): string;
130
181
  /** Pure: the settle instant of a clock sweep — null when its last interval still moved. */
131
- declare function clockSettledAt(times: number[], frames: FrameDeltaStat[], minChangedPixels: number): number | null;
132
- interface ReducedMotionRemaining {
182
+ export declare function clockSettledAt(times: number[], frames: FrameDeltaStat[], minChangedPixels: number): number | null;
183
+ export interface ReducedMotionRemaining {
133
184
  selector: string;
134
185
  name: string;
135
186
  durationMs: number;
136
187
  }
137
- type AnimationEvalIssueKind = "no-visible-effect" | "infinite-animation" | "reduced-motion-ignored" | "long-settle" | "uncontrolled-motion" | "seek-ineffective" | "clock-motion-unsettled";
138
- interface AnimationEvalIssue {
188
+ export type AnimationEvalIssueKind = "no-visible-effect" | "infinite-animation" | "reduced-motion-ignored" | "long-settle" | "uncontrolled-motion" | "seek-ineffective" | "clock-motion-unsettled" | "undefined-keyframes" | "motion-mostly-hidden" | "delayed-entrance" | "unknown-transition-property" | "unregistered-property-transition" | "inert-offset-animation" | "duplicate-keyframes" | "negative-delay-entrance" | "held-filter" | "held-paused-animation" | "stepped-keyframe" | "inert-size-animation" | "unknown-media-feature" | "overridden-animation" | "unitless-duration-var" | "counter-rotation-drift" | "reduced-motion-hides" | "layout-animation" | "loop-seam" | "stroke-incomplete" | "discrete-transition" | "animation-replayed" | "zero-duration-animation";
189
+ export interface AnimationEvalIssue {
139
190
  kind: AnimationEvalIssueKind;
140
191
  severity: "warn" | "suspect";
141
192
  message: string;
142
193
  selector?: string;
143
194
  }
144
- interface AnimationEvalReport {
195
+ export interface AnimationEvalReport {
145
196
  source: string;
146
197
  viewport: {
147
198
  width: number;
148
199
  height: number;
149
200
  };
150
201
  animationCount: number;
202
+ /** Animations on a scroll timeline: listed, not evaluated (inspect motion sweeps the scroll). */
203
+ scrollDriven?: {
204
+ selector: string;
205
+ name: string;
206
+ timeline: string;
207
+ }[];
151
208
  evaluated: EvaluatedAnimation[];
152
209
  /** Max over finite animations of delay + duration × iterations; null when an infinite animation is present. */
153
210
  settleMs: number | null;
154
211
  infinite: {
155
212
  selector: string;
156
213
  name: string;
214
+ indicator?: string;
157
215
  }[];
158
216
  /** Present unless the reduced-motion pass was skipped or there were no animations. */
159
217
  reducedMotion?: {
160
218
  remainingCount: number;
161
219
  remaining: ReducedMotionRemaining[];
220
+ /**
221
+ * Nothing that moves runs without the preference either (only opacity, colour, visibility):
222
+ * there was no motion to reduce, so the pass is not "honored" by any choice of the page's.
223
+ */
224
+ nothingToReduce?: boolean;
225
+ /** With `nothingToReduce`: the fades / colour animations that still run under reduce, as allowed. */
226
+ fadesUnderReduce?: number;
162
227
  };
228
+ /** `animation-name`s with no @keyframes: nothing ran under them (`reducedMotion`: only under reduce). */
229
+ undefinedKeyframes?: {
230
+ selector: string;
231
+ name: string;
232
+ reducedMotion: boolean;
233
+ }[];
163
234
  /**
164
235
  * Pixel delta between two back-to-back rest captures with every WAAPI
165
236
  * animation held still. Present (nonzero) means a motion source the Web
@@ -172,24 +243,43 @@ interface AnimationEvalReport {
172
243
  /** Script-driven motion sampled on the virtual clock. Present only with `--virtual-time`. */
173
244
  clockMotion?: ClockMotion;
174
245
  issues: AnimationEvalIssue[];
175
- /** Written sample frames (when --frames was passed). */
246
+ /** The frame files `--frames` wrote, in sequence order. */
176
247
  framePaths?: string[];
248
+ /**
249
+ * `--frames`: the viewport, uncropped, at each instant of its own time, clock and animations held, as a
250
+ * `vlmkit-frames/1` sequence (numbered PNGs + `frames.json`).
251
+ */
252
+ frames?: {
253
+ dir: string;
254
+ manifest: string;
255
+ count: number;
256
+ unstable: number;
257
+ instants: number[];
258
+ /** Captured with `prefers-reduced-motion: reduce` emulated. */
259
+ reducedMotion?: boolean;
260
+ };
177
261
  /** Written when `stripPath` was given: one image holding every sampled frame. */
178
262
  strip?: {
179
263
  path: string;
180
264
  columns: number;
181
- rows: number; /** Evaluated animations left out because they moved no pixels. */
182
- omitted: number; /** Evaluated animations left out because `--strip-selector` did not match them. */
183
- outOfScope: number; /** Page-timeline span the columns cover, in ms. */
184
- windowMs: number; /** The instant each column was taken at, in ms from the animations' start. */
185
- times: number[]; /** Row order, top to bottom. Empty for an animated strip, which has no rows. */
265
+ rows: number;
266
+ /** Evaluated animations left out because they moved no pixels. */
267
+ omitted: number;
268
+ /** Evaluated animations left out because `--strip-selector` did not match them. */
269
+ outOfScope: number;
270
+ /** Page-timeline span the columns cover, in ms. */
271
+ windowMs: number;
272
+ /** The instant each column was taken at, in ms from the animations' start. */
273
+ times: number[];
274
+ /** Row order, top to bottom. Empty for an animated strip, which has no rows. */
186
275
  rowSelectors: string[];
187
276
  width: number;
188
- height: number; /** True when this is an animated PNG of the whole page rather than a cropped still sheet. */
277
+ height: number;
278
+ /** True when this is an animated PNG of the whole page rather than a cropped still sheet. */
189
279
  animated?: boolean;
190
280
  };
191
281
  }
192
- interface AnimationEvalOptions extends PageLoadOptions {
282
+ export interface AnimationEvalOptions extends PageLoadOptions {
193
283
  source: string;
194
284
  html?: string;
195
285
  viewport?: {
@@ -218,8 +308,19 @@ interface AnimationEvalOptions extends PageLoadOptions {
218
308
  virtualTime?: boolean;
219
309
  /** Virtual-time span to sample script-driven motion over (default 2000ms). */
220
310
  clockWindowMs?: number;
221
- /** Write each sampled frame PNG into this directory. */
311
+ /**
312
+ * Write the viewport, uncropped, at each instant (`at`, else each animation's start / middle / end plus a
313
+ * coarse grid) into this directory as a `vlmkit-frames/1` sequence. Captured on a page of its
314
+ * own with the clock held, so script-driven motion is at the instant too, `virtualTime` or not.
315
+ */
222
316
  framesDir?: string;
317
+ /** Capture `framesDir` with `prefers-reduced-motion: reduce` emulated: what that visitor sees. */
318
+ framesReducedMotion?: boolean;
319
+ /**
320
+ * Instants of page time, in ms: the frames `framesDir` writes and the strip's columns. Without
321
+ * it the strip's columns divide its window evenly.
322
+ */
323
+ at?: readonly number[];
223
324
  /**
224
325
  * Composite every sampled frame into ONE image at this path, one row per
225
326
  * animation. `--frames` writes N files a reader has to open in order; this
@@ -260,15 +361,15 @@ interface RgbaFrame {
260
361
  * Pixel delta between two same-size RGBA frames: count, ratio, and the
261
362
  * bounding box of every pixel whose any channel moved more than tolerance.
262
363
  */
263
- declare function frameDelta(a: RgbaFrame, b: RgbaFrame, tolerance?: number): FrameDeltaStat;
364
+ export declare function frameDelta(a: RgbaFrame, b: RgbaFrame, tolerance?: number): FrameDeltaStat;
264
365
  /**
265
366
  * Rest-pose time for an animation: page-paused/finished animations stay at
266
367
  * their author-chosen currentTime (their true resting appearance); running
267
368
  * finite animations seek past their end (settled appearance); running
268
369
  * infinite ones hold at 0.
269
370
  */
270
- declare function restTimeForAnimation(t: AnimationTimingSample): number;
271
- declare function unionBbox(a: {
371
+ export declare function restTimeForAnimation(t: AnimationTimingSample): number;
372
+ export declare function unionBbox(a: {
272
373
  x: number;
273
374
  y: number;
274
375
  width: number;
@@ -285,27 +386,151 @@ declare function unionBbox(a: {
285
386
  height: number;
286
387
  } | null;
287
388
  /** Max over finite animations of delay + duration × iterations; null when any animation is infinite. */
288
- declare function computeSettleMs(animations: AnimationTimingSample[]): number | null;
289
- interface DeriveIssuesInput {
389
+ export declare function computeSettleMs(animations: AnimationTimingSample[]): number | null;
390
+ /** An element that rests seen without reduced motion and hidden (or moved) with it. */
391
+ export interface ReducedHidden {
392
+ selector: string;
393
+ opacity: number;
394
+ reducedOpacity: number;
395
+ /** How far its centre rests from where it rests without the preference (px). */
396
+ offPx: number;
397
+ }
398
+ export interface DeriveIssuesInput {
290
399
  evaluated: EvaluatedAnimation[];
291
400
  settleMs: number | null;
292
401
  infinite: {
293
402
  selector: string;
294
403
  name: string;
404
+ indicator?: string;
295
405
  }[];
296
- reducedMotion?: {
297
- remainingCount: number;
298
- remaining: ReducedMotionRemaining[];
299
- };
406
+ reducedMotion?: AnimationEvalReport["reducedMotion"];
300
407
  uncontrolledMotion?: FrameDeltaStat;
301
408
  virtualTime?: boolean;
302
409
  clockMotion?: ClockMotion;
410
+ undefinedKeyframes?: {
411
+ selector: string;
412
+ name: string;
413
+ reducedMotion: boolean;
414
+ }[];
415
+ /** transition-property names no CSS property, with a duration over 0. */
416
+ unknownTransitions?: {
417
+ selector: string;
418
+ name: string;
419
+ unregistered?: boolean;
420
+ inertOffsets?: string[];
421
+ duplicate?: string[];
422
+ negativeDelayMs?: number;
423
+ durationMs?: number;
424
+ restFilter?: string;
425
+ /** The rule that holds it paused while it hides the element (animation-play-state: paused). */
426
+ heldPaused?: string;
427
+ /** A later animation in animation-name on the same property, whose fill covers this one's run. */
428
+ overridden?: {
429
+ by: string;
430
+ props: string[];
431
+ delayMs: number;
432
+ fill: string;
433
+ coveredMs: number | null;
434
+ };
435
+ /** A counter-rotation against an ancestor's turn at a rate that does not cancel it. */
436
+ counterDrift?: {
437
+ ancestor: string;
438
+ theirs: string;
439
+ mine: {
440
+ deg: number;
441
+ ms: number;
442
+ };
443
+ other: {
444
+ deg: number;
445
+ ms: number;
446
+ };
447
+ net: number;
448
+ };
449
+ /** A transition / animation duration var() that resolves to a number with no unit. */
450
+ unitlessVar?: {
451
+ prop: string;
452
+ text: string;
453
+ variable: string;
454
+ value: string;
455
+ };
456
+ /** A keyframe's steps() timing function that overrides the element's smooth one. */
457
+ steppedKeyframe?: {
458
+ at: string;
459
+ easing: string;
460
+ own: string;
461
+ };
462
+ /** Size properties its keyframes animate on a non-replaced inline box, where they do nothing. */
463
+ inertSize?: string[];
464
+ tag?: string;
465
+ /** An @media header the browser reads as "not all" (an unknown feature) around motion. */
466
+ unknownMedia?: {
467
+ header: string;
468
+ feature: string;
469
+ suggest: string | null;
470
+ };
471
+ }[];
472
+ /** CSS animations with no duration: they end as they begin. */
473
+ zeroDuration?: {
474
+ selector: string;
475
+ name: string;
476
+ }[];
477
+ /** A transition on background over a gradient, which does not interpolate. */
478
+ discreteTransitions?: {
479
+ selector: string;
480
+ name: string;
481
+ image: string;
482
+ }[];
483
+ /** Seen at rest without the preference, hidden or out of place at rest under reduce. */
484
+ reducedHidden?: ReducedHidden[];
485
+ /** What an animation does beyond its own box (`MOTION_SHAPE_SCRIPT`). */
486
+ shapes?: MotionShapes;
487
+ }
488
+ export interface MotionShapes {
489
+ /** An in-flow element animating a layout property, and what that moved. */
490
+ pushes: {
491
+ selector: string;
492
+ name: string;
493
+ props: string[];
494
+ moved: {
495
+ selector: string;
496
+ dx: number;
497
+ dy: number;
498
+ }[];
499
+ count: number;
500
+ }[];
501
+ /** A repeating animation whose run ends off the pose the next begins on. */
502
+ seams: {
503
+ selector: string;
504
+ name: string;
505
+ channel: string;
506
+ step: number;
507
+ usual: number;
508
+ unit: string;
509
+ prop: string;
510
+ from: string | null;
511
+ to: string | null;
512
+ }[];
513
+ /** A dashed stroke drawing itself that rests part drawn. */
514
+ strokes: {
515
+ selector: string;
516
+ name: string;
517
+ drawn: number;
518
+ note: string;
519
+ }[];
520
+ /** A looping animation on a loading indicator, and why it reads as one. */
521
+ indicators: {
522
+ index: number;
523
+ selector: string;
524
+ name: string;
525
+ why: string;
526
+ }[];
303
527
  }
304
- declare function deriveAnimationIssues(input: DeriveIssuesInput, options?: {
528
+ /** A delay this long (ms) at least, with the element held unseen through it, is a `delayed-entrance`. */
529
+ export declare const DELAYED_ENTRANCE_MS = 1000;
530
+ export declare function deriveAnimationIssues(input: DeriveIssuesInput, options?: {
305
531
  settleThresholdMs?: number;
306
532
  reducedMotionDurationFloorMs?: number;
307
533
  }): AnimationEvalIssue[];
308
- declare function runAnimationEval(options: AnimationEvalOptions): Promise<AnimationEvalReport>;
309
- declare function formatAnimationEvalReport(report: AnimationEvalReport, rules?: RuleView): string;
310
- //#endregion
311
- export { AnimationEvalIssue, AnimationEvalIssueKind, AnimationEvalOptions, AnimationEvalReport, AnimationFrameStat, AnimationTimingSample, ClockMotion, DeriveIssuesInput, EvaluatedAnimation, FrameDeltaStat, OscillationInfo, ReducedMotionRemaining, SeekIneffective, clockSettledAt, computeOscillation, computeSettleMs, deriveAnimationIssues, formatAnimationEvalReport, frameDelta, restTimeForAnimation, runAnimationEval, unionBbox };
534
+ export declare function runAnimationEval(options: AnimationEvalOptions): Promise<AnimationEvalReport>;
535
+ export declare function formatAnimationEvalReport(report: AnimationEvalReport, rules?: RuleView): string;
536
+ export {};