@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.
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
+ import { captureTimelineFrames } from "./frames-capture.mjs";
2
3
  import { VIRTUAL_CLOCK_SCRIPT } from "./virtual-clock.mjs";
3
4
  import { mkdir, writeFile } from "node:fs/promises";
4
5
  import { STABLE_SELECTOR_JS } from "@mizchi/vlmkit-core/stable-selector.ts";
5
- import { dirname, join, resolve } from "node:path";
6
+ import { dirname, resolve } from "node:path";
6
7
  import { PNG } from "pngjs";
7
8
  import { BOLD, CYAN, DIM, GREEN, RED, RESET, YELLOW } from "@mizchi/vlmkit-core/terminal-colors.ts";
8
9
  import { retuneNote, tierIssues } from "@mizchi/vlmkit-core/plugin/rule-prose.ts";
@@ -14,7 +15,8 @@ import { encodeApng } from "@mizchi/vlmkit-core/apng.ts";
14
15
  import { cropRegion, encodePng } from "@mizchi/vlmkit-core/png-utils.ts";
15
16
  import { encodeWebp, imageFormatForPath } from "@mizchi/vlmkit-core/webp.ts";
16
17
  import { applyHar, settlePage, sourceToUrl } from "@mizchi/vlmkit-core/page-open.ts";
17
- //#region src/animation-eval.ts
18
+ import { formatInstant, playbackDelays } from "@mizchi/vlmkit-judge/frames.ts";
19
+ // src/animation-eval.ts
18
20
  /**
19
21
  * Frame-sampled animation evaluator.
20
22
  *
@@ -40,11 +42,10 @@ import { applyHar, settlePage, sourceToUrl } from "@mizchi/vlmkit-core/page-open
40
42
  *
41
43
  * Usage:
42
44
  * vlmkit check animation <html-or-url>
43
- * vlmkit check animation <html-or-url> --json --frames out/frames
44
- * vlmkit-anim eval <page.html> (the same report from the animation tool)
45
+ * vlmkit check animation <html-or-url> --json --frames out/frames --at 0..600/100
45
46
  *
46
- * Lives in its own package (`@mizchi/vlmkit-animation-eval`) so the animation
47
- * authoring tool can depend on the measurement without the rest of vlmkit.
47
+ * Lives in its own package (`@mizchi/vlmkit-animation-eval`) so a caller can
48
+ * depend on the measurement without the rest of vlmkit.
48
49
  */
49
50
  /**
50
51
  * Effective oscillation of one animation. WAAPI folds both `alternate`
@@ -70,6 +71,25 @@ function computeOscillation(t) {
70
71
  legMs: t.durationMs
71
72
  };
72
73
  }
74
+ /** Pure: the sweep's pixels changed only as a slow timer updated the page (no animation frames). */
75
+ function clockUpdatesOnly(clock) {
76
+ const r = clock.runs;
77
+ if (!r || r.frames > 0) return false;
78
+ if ((clock.started ?? []).length > 0 || (clock.replays ?? []).length > 0) return false;
79
+ return r.timers > 0 && r.timers <= 5 * Math.max(1, clock.windowMs / 1e3);
80
+ }
81
+ /**
82
+ * When a timer-started animation began, as far as the sweep's instants can say: "at 250ms" read
83
+ * as the start of a transition a timer began at 200ms (round 13), when 250 was only the first
84
+ * instant after it.
85
+ */
86
+ const beganText = (s) => s.afterMs !== void 0 && s.atMs - s.afterMs > 1e3 / 60 + 1e-6 ? `between ${s.afterMs}ms and ${s.atMs}ms` : `at ${s.atMs}ms`;
87
+ /** Pure: what a clock sweep's motion is, named as far as the page let it be. */
88
+ function clockMotionSource(clock) {
89
+ const started = clock.started ?? [];
90
+ if (started.length === 0) return "requestAnimationFrame / timers";
91
+ return `a timer started ${started.slice(0, 3).map((s) => `${s.kind} \`${s.name}\` on ${s.selector} (begun ${beganText(s)})`).join(", ")}${started.length > 3 ? ` and ${started.length - 3} more` : ""}`;
92
+ }
73
93
  /** Pure: the settle instant of a clock sweep — null when its last interval still moved. */
74
94
  function clockSettledAt(times, frames, minChangedPixels) {
75
95
  let settled = 0;
@@ -140,10 +160,191 @@ function computeSettleMs(animations) {
140
160
  }
141
161
  return settle;
142
162
  }
163
+ /** A delay this long (ms) at least, with the element held unseen through it, is a `delayed-entrance`. */
164
+ const DELAYED_ENTRANCE_MS = 1e3;
143
165
  function deriveAnimationIssues(input, options = {}) {
144
166
  const settleThreshold = options.settleThresholdMs ?? 3e3;
145
167
  const durationFloor = options.reducedMotionDurationFloorMs ?? 100;
146
168
  const issues = [];
169
+ for (const h of input.reducedHidden ?? []) {
170
+ const gone = h.reducedOpacity < .05;
171
+ issues.push({
172
+ kind: "reduced-motion-hides",
173
+ severity: "suspect",
174
+ selector: h.selector,
175
+ message: gone ? `${h.selector} rests at opacity ${h.reducedOpacity.toFixed(2)} under prefers-reduced-motion: reduce, and at ${h.opacity.toFixed(2)} without it: the reduce rule took its animation away, and with it the fill that showed it. Give it its end state in that rule (opacity: 1, transform: none), or make the hidden state the first keyframe's (fill: both) instead of the element's own.` : `${h.selector} rests ${Math.round(h.offPx)}px from its place under prefers-reduced-motion: reduce: the reduce rule took its animation away and left the element where the animation started. Give it its end state in that rule (transform: none).`
176
+ });
177
+ }
178
+ for (const push of input.shapes?.pushes ?? []) {
179
+ const moved = push.moved.map((m) => `${m.selector} ${Math.round(Math.hypot(m.dx, m.dy))}px`).join(", ");
180
+ issues.push({
181
+ kind: "layout-animation",
182
+ severity: "warn",
183
+ selector: push.selector,
184
+ message: `${push.selector} \`${push.name}\` animates ${push.props.map((p) => p.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)).join(", ")}, a layout property, in the flow, so it moves ${push.count} element(s) that have no animation of their own: ${moved}${push.count > push.moved.length ? ", …" : ""}. If they are meant to stay put, animate transform instead (or take ${push.selector} out of the flow); if pushing them is the design (an accordion opening), this is it.`
185
+ });
186
+ }
187
+ for (const seam of input.shapes?.seams ?? []) {
188
+ const keyed = seam.from !== null && seam.to !== null ? ` (its keyframes run from ${seam.from} to ${seam.to})` : "";
189
+ const what = seam.channel === "turn" ? "turns" : seam.channel === "opacity" ? "fades" : "jumps";
190
+ issues.push({
191
+ kind: "loop-seam",
192
+ severity: "suspect",
193
+ selector: seam.selector,
194
+ message: `${seam.selector} \`${seam.name}\` ${what} ${seam.step.toFixed(1)}${seam.unit} in one step at the end of every run, against ${seam.usual.toFixed(2)}${seam.unit} a ms either side${keyed}: the run ends off the pose the next begins on. End it on the same pose it starts on (360deg for a turn, a whole copy for a ticker).`
195
+ });
196
+ }
197
+ for (const stroke of input.shapes?.strokes ?? []) issues.push({
198
+ kind: "stroke-incomplete",
199
+ severity: "suspect",
200
+ selector: stroke.selector,
201
+ message: `${stroke.selector} \`${stroke.name}\` draws its stroke and rests ${Math.round(stroke.drawn * 100)}% drawn: ${stroke.note}. A dash shorter than the line leaves the rest of it off; make the dash (and the offset it starts from) at least the line's length, or set pathLength and use that.`
202
+ });
203
+ for (const z of input.zeroDuration ?? []) issues.push({
204
+ kind: "zero-duration-animation",
205
+ severity: "suspect",
206
+ selector: z.selector,
207
+ message: `${z.selector} \`${z.name}\` has no duration (0s): it ends the moment it begins, and its fill holds its last keyframe from the start. If it is meant to follow the scroll, \`animation-timeline\` has to come after the \`animation\` shorthand, which resets it to auto (and the duration to 0s); otherwise give it a duration.`
208
+ });
209
+ for (const u of input.discreteTransitions ?? []) issues.push({
210
+ kind: "discrete-transition",
211
+ severity: "warn",
212
+ selector: u.selector,
213
+ message: `${u.selector} transitions \`${u.name}\` over a gradient (${u.image}): a gradient is an image and does not interpolate, so a change to another gradient steps at once with no frame between. To fade it, build the gradient from registered colour properties (@property --c { syntax: "<color>"; inherits: false; initial-value: … }) and transition those, or cross-fade a second gradient layer's opacity. If the gradient never changes, this transition does nothing.`
214
+ });
215
+ for (const u of input.unknownTransitions ?? []) {
216
+ if (u.duplicate) {
217
+ issues.push({
218
+ kind: "duplicate-keyframes",
219
+ severity: "suspect",
220
+ selector: u.selector,
221
+ message: `${u.selector} plays \`${u.name}\`, which ${u.duplicate.length} @keyframes rules define (${u.duplicate.map((d, i) => `#${i + 1}: ${d || "nothing"}`).join("; ")}): the last one in the cascade wins, so the others never run. Give each its own name.`
222
+ });
223
+ continue;
224
+ }
225
+ if (u.negativeDelayMs !== void 0) {
226
+ issues.push({
227
+ kind: "negative-delay-entrance",
228
+ severity: "warn",
229
+ selector: u.selector,
230
+ message: `${u.selector} \`${u.name}\` has animation-delay ${u.negativeDelayMs}ms: it starts ${-u.negativeDelayMs}ms into its ${u.durationMs}ms run, so that much of its entrance is skipped and it is already part way in at load. A stagger is a positive delay per item (calc(var(--i) * 80ms)); a negative one only suits a loop meant to start mid-run.`
231
+ });
232
+ continue;
233
+ }
234
+ if (u.overridden) {
235
+ const o = u.overridden;
236
+ issues.push({
237
+ kind: "overridden-animation",
238
+ severity: "suspect",
239
+ selector: u.selector,
240
+ message: `${u.selector} \`${u.name}\` and \`${o.by}\` both animate ${o.props.join(", ")}, and \`${o.by}\` comes later in animation-name, so its value wins${o.coveredMs === null ? " for the whole of" : ` for ${o.coveredMs}ms of`} \`${u.name}\`'s run${o.delayMs > 0 && (o.fill === "backwards" || o.fill === "both") ? ` (its ${o.fill} fill holds its first keyframe through its ${Math.round(o.delayMs)}ms delay)` : ""}: that part of \`${u.name}\` never shows. Animate one with an individual property (translate / scale / rotate compose with transform), or drop the backwards fill.`
241
+ });
242
+ continue;
243
+ }
244
+ if (u.counterDrift) {
245
+ const c = u.counterDrift;
246
+ issues.push({
247
+ kind: "counter-rotation-drift",
248
+ severity: "warn",
249
+ selector: u.selector,
250
+ message: `${u.selector} \`${u.name}\` turns ${Math.round(c.mine.deg)}° per ${Math.round(c.mine.ms)}ms against ${c.ancestor}'s \`${c.theirs}\` (${Math.round(c.other.deg)}° per ${Math.round(c.other.ms)}ms), so on screen it turns ${Math.abs(c.net).toFixed(1)}°/s ${c.net > 0 ? "clockwise" : "counterclockwise"}: a counter-rotation meant to keep it level needs the same duration, easing and delay as the turn it cancels. If the drift is meant, ignore this.`
251
+ });
252
+ continue;
253
+ }
254
+ if (u.unitlessVar) {
255
+ const v = u.unitlessVar;
256
+ issues.push({
257
+ kind: "unitless-duration-var",
258
+ severity: "suspect",
259
+ selector: u.selector,
260
+ message: `${u.selector} { ${v.prop}: ${v.text} } reads ${v.variable}, which is ${v.value}: a number with no unit, so the declaration is invalid at computed-value time and ${v.prop.startsWith("animation") ? "the animation" : "the transition"} is dropped (the element snaps). Give the token a unit (${v.value}ms), or write calc(var(${v.variable}) * 1ms).`
261
+ });
262
+ continue;
263
+ }
264
+ if (u.steppedKeyframe) {
265
+ const k = u.steppedKeyframe;
266
+ issues.push({
267
+ kind: "stepped-keyframe",
268
+ severity: "warn",
269
+ selector: u.selector,
270
+ message: `${u.selector} \`${u.name}\`'s ${k.at} keyframe sets animation-timing-function: ${k.easing}, which overrides the element's own ${k.own} from that keyframe to the next: it moves in jumps, not a glide. A timing function inside @keyframes applies per keyframe and wins over the element's; take it out of the keyframe (or give that animation its own keyframes) unless the steps are meant.`
271
+ });
272
+ continue;
273
+ }
274
+ if (u.inertSize) {
275
+ issues.push({
276
+ kind: "inert-size-animation",
277
+ severity: "suspect",
278
+ selector: u.selector,
279
+ message: `${u.selector} \`${u.name}\` animates ${u.inertSize.join(", ")}, but the element is a <${u.tag}> laid out inline (display: inline), where width and height do not apply: it has no box of its own to grow, so nothing is drawn. Give it display: block (or inline-block).`
280
+ });
281
+ continue;
282
+ }
283
+ if (u.unknownMedia) {
284
+ const m = u.unknownMedia;
285
+ issues.push({
286
+ kind: "unknown-media-feature",
287
+ severity: "suspect",
288
+ selector: u.selector,
289
+ message: `@media ${m.header} never matches: the browser does not know the media feature${m.feature ? ` \`${m.feature}\`` : ""} (or its value), so the query is false for everyone and the animations and transitions inside it never apply for anyone${m.suggest && m.suggest !== m.feature ? ` — did you mean \`${m.suggest}\`?` : ""}`
290
+ });
291
+ continue;
292
+ }
293
+ if (u.heldPaused !== void 0) {
294
+ issues.push({
295
+ kind: "held-paused-animation",
296
+ severity: "suspect",
297
+ selector: u.selector,
298
+ message: `${u.selector} \`${u.name}\` is held paused at rest by ${u.heldPaused}, and the element is invisible while it is (opacity 0): the animation never plays, so the element never appears. Whatever should release it has not: a class a script removes (check the name it removes matches), a state the page never reaches. The frames of this evaluation seek it, so they show it as if it ran.`
299
+ });
300
+ continue;
301
+ }
302
+ if (u.restFilter !== void 0) {
303
+ issues.push({
304
+ kind: "held-filter",
305
+ severity: "warn",
306
+ selector: u.selector,
307
+ message: `${u.selector} \`${u.name}\` ends on filter: ${u.restFilter} and its fill holds it at rest: a blur left there softens the element for good (at 1x a blur under 1px can draw as no blur, so a screenshot may not show it), End the animation without the filter, or fill it backwards so the element's own style shows once it ends.`
308
+ });
309
+ continue;
310
+ }
311
+ if (u.inertOffsets) {
312
+ issues.push({
313
+ kind: "inert-offset-animation",
314
+ severity: "suspect",
315
+ selector: u.selector,
316
+ message: `${u.selector} \`${u.name}\` animates ${u.inertOffsets.join(", ")}, but the element is position: static, where ${u.inertOffsets.length === 1 ? "that offset does" : "offsets do"} nothing: whatever else the animation does still shows, and the move it meant never happens. Give it position: relative, or animate transform: translate() (or translate) instead.`
317
+ });
318
+ continue;
319
+ }
320
+ if (u.unregistered) {
321
+ issues.push({
322
+ kind: "unregistered-property-transition",
323
+ severity: "suspect",
324
+ selector: u.selector,
325
+ message: `${u.selector} transitions \`${u.name}\`, a custom property no @property registers: an unregistered custom property has no type, so it does not interpolate and whatever it drives (a gradient stop, a width through calc()) changes in one frame. Register it — @property ${u.name} { syntax: "<percentage>"; inherits: false; initial-value: 0%; }, with the syntax of its values — and the transition runs.`
326
+ });
327
+ continue;
328
+ }
329
+ issues.push({
330
+ kind: "unknown-transition-property",
331
+ severity: "suspect",
332
+ selector: u.selector,
333
+ message: `${u.selector} transitions \`${u.name}\`, which is no CSS property, so that transition never runs and the property it meant changes in one frame. Check the spelling in transition / transition-property.`
334
+ });
335
+ }
336
+ for (const u of input.undefinedKeyframes ?? []) issues.push({
337
+ kind: "undefined-keyframes",
338
+ severity: "suspect",
339
+ selector: u.selector,
340
+ message: `${u.selector} names \`${u.name}\` in animation-name${u.reducedMotion ? " under prefers-reduced-motion: reduce" : ""}, but no @keyframes ${u.name} exists, so nothing runs` + (u.reducedMotion ? " — whatever that rule was meant to do for reduced-motion users (hide, settle) does not happen." : ".")
341
+ });
342
+ for (const anim of input.evaluated) if (anim.startsHidden && anim.delayMs >= 1e3 && (anim.fill === "backwards" || anim.fill === "both")) issues.push({
343
+ kind: "delayed-entrance",
344
+ severity: "warn",
345
+ selector: anim.selector,
346
+ message: `${anim.selector} is held unseen for the first ${Math.round(anim.delayMs)}ms: \`${anim.name}\` waits ${Math.round(anim.delayMs)}ms (animation-delay) and its fill (${anim.fill}) keeps its first, hidden keyframe until then. If it should appear with the page, drop the delay; if the wait is meant, this is its design.`
347
+ });
147
348
  for (const anim of input.evaluated) {
148
349
  if (anim.seekIneffective) {
149
350
  const why = anim.seekIneffective.reason === "readback" ? `after a seek the animation ${anim.seekIneffective.detail} — the page cancelled or replaced it, so the gate was moving an object nothing renders` : `seeking back to its first sample did not reproduce that frame (${anim.seekIneffective.detail}) — something other than this animation's time drives those pixels`;
@@ -155,6 +356,17 @@ function deriveAnimationIssues(input, options = {}) {
155
356
  });
156
357
  continue;
157
358
  }
359
+ if (anim.visible && anim.motionBbox && anim.elementBox) {
360
+ const box = anim.elementBox;
361
+ const seen = anim.motionBbox.width * anim.motionBbox.height;
362
+ const area = box.width * box.height;
363
+ if (area >= 400 && seen < area * .25 && (box.topmost ?? 0) < .5) issues.push({
364
+ kind: "motion-mostly-hidden",
365
+ severity: "warn",
366
+ selector: anim.selector,
367
+ message: `${anim.selector} \`${anim.name}\` moved pixels in only ${anim.motionBbox.width}x${anim.motionBbox.height} of its ${box.width}x${box.height} box (${Math.round(seen / area * 100)}%), and it is the topmost thing painted on ${Math.round((box.topmost ?? 0) * 100)}% of that box at rest: most of it is clipped or covered — \`vlmkit inspect motion <page> --selector ${anim.selector}\` names the clip or the cover.`
368
+ });
369
+ }
158
370
  if (!anim.visible) issues.push({
159
371
  kind: "no-visible-effect",
160
372
  severity: "suspect",
@@ -166,15 +378,32 @@ function deriveAnimationIssues(input, options = {}) {
166
378
  kind: "infinite-animation",
167
379
  severity: "warn",
168
380
  selector: anim.selector,
169
- message: `${anim.selector} animation \`${anim.name}\` runs forever — the page never settles. To fix the page, give it a bounded \`animation-iteration-count\` (or stop it once its work is done). If it is meant to run forever, the capture side has to absorb it instead: mask it with \`vlmkit snapshot <url> --mask "${anim.selector}"\` (that flag belongs to \`snapshot\` / \`diff html\`, not to this gate) or pause animations before screenshots.`
381
+ message: anim.indicator ? `${anim.selector} animation \`${anim.name}\` runs forever, on what reads as a loading indicator (${anim.indicator}), which is meant to: that is not a defect of the page. The capture side absorbs it: mask it with \`vlmkit snapshot <url> --mask "${anim.selector}"\` (that flag belongs to \`snapshot\` / \`diff html\`, not to this gate) or pause animations before screenshots. If it should stop once its work is done, give it a bounded \`animation-iteration-count\` or remove it then.` : `${anim.selector} animation \`${anim.name}\` runs forever — the page never settles. To fix the page, give it a bounded \`animation-iteration-count\` (or stop it once its work is done). If it is meant to run forever, the capture side has to absorb it instead: mask it with \`vlmkit snapshot <url> --mask "${anim.selector}"\` (that flag belongs to \`snapshot\` / \`diff html\`, not to this gate) or pause animations before screenshots.`
170
382
  });
171
383
  const clock = input.clockMotion;
172
- if (clock?.visible && clock.settledAtMs === null) {
384
+ for (const r of clock?.replays ?? []) {
385
+ const when = r.atMs.slice(0, 3).map((t) => `${t}ms`).join(", ");
386
+ issues.push({
387
+ kind: "animation-replayed",
388
+ severity: r.newElement ? "suspect" : "warn",
389
+ selector: r.selector,
390
+ message: r.newElement ? `${r.selector} \`${r.name}\` plays again by ${when}${r.atMs.length > 3 ? ", …" : ""} of virtual time on a new element: the page replaced it (a re-render — innerHTML, a framework re-keying the node), and each new one plays its entrance again. Update what it shows (textContent, an attribute) instead of re-creating it.` : `${r.selector} \`${r.name}\` begins again by ${when}${r.atMs.length > 3 ? ", …" : ""} of virtual time on the same element (a class or animation-name toggled on a timer). If it should play once, nothing should start it again.`
391
+ });
392
+ }
393
+ const updatesOnly = clock ? clockUpdatesOnly(clock) : false;
394
+ if (clock?.visible && clock.settledAtMs === null && updatesOnly) {
395
+ const b = clock.motionBbox;
396
+ issues.push({
397
+ kind: "clock-motion-unsettled",
398
+ severity: "warn",
399
+ message: `The page at (${b.x},${b.y}) ${b.width}x${b.height} changes only when a timer updates it (${clock.runs.timers} timer run(s) in ${clock.windowMs}ms of virtual time, no animation frame): a value updated in place (a clock, a live price) is not motion, and needs nothing under reduced motion. It does keep captures from being still: mask the region in them.`
400
+ });
401
+ } else if (clock?.visible && clock.settledAtMs === null) {
173
402
  const b = clock.motionBbox;
174
403
  issues.push({
175
404
  kind: "clock-motion-unsettled",
176
405
  severity: "warn",
177
- message: `Script-driven motion at (${b.x},${b.y}) ${b.width}x${b.height} is still changing at ${clock.windowMs}ms of virtual time — a requestAnimationFrame / timer loop that never stops, so the page never settles. Stop the loop once its work is done, and check \`matchMedia("(prefers-reduced-motion: reduce)")\` in the script; if it is meant to run forever, mask the region in captures.`
406
+ message: `Script-driven motion at (${b.x},${b.y}) ${b.width}x${b.height} is still changing at ${clock.windowMs}ms of virtual time — ${(clock.started ?? []).length > 0 ? `${clockMotionSource(clock)}, and it` : "a requestAnimationFrame / timer loop that"} never stops, so the page never settles. Stop the loop once its work is done, and check \`matchMedia("(prefers-reduced-motion: reduce)")\` in the script; if it is meant to run forever, mask the region in captures.`
178
407
  });
179
408
  } else if (clock?.visible && clock.settledAtMs !== null && clock.settledAtMs > settleThreshold) issues.push({
180
409
  kind: "long-settle",
@@ -201,7 +430,7 @@ function deriveAnimationIssues(input, options = {}) {
201
430
  kind: "reduced-motion-ignored",
202
431
  severity: "suspect",
203
432
  ...sample ? { selector: sample.selector } : {},
204
- message: `${input.reducedMotion.remainingCount} animation(s) still run under \`prefers-reduced-motion: reduce\` emulation: ${input.reducedMotion.remaining.slice(0, 4).map((r) => `${r.selector} \`${r.name}\` ${Math.round(r.durationMs)}ms`).join(", ")}${input.reducedMotion.remaining.length > 4 ? `, and ${input.reducedMotion.remaining.length - 4} more` : ""} — motion is not reduced for users who requested it. Add \`@media (prefers-reduced-motion: reduce)\` and either set \`animation: none\` on them or shorten each duration below ${durationFloor}ms.` + (input.reducedMotion.remaining.some((r) => r.selector.startsWith("(script-driven")) ? ` For the script-driven motion, read \`matchMedia("(prefers-reduced-motion: reduce)")\` and skip or shorten the loop.` : "")
433
+ message: `${input.reducedMotion.remainingCount} animation(s) still run under \`prefers-reduced-motion: reduce\` emulation: ${input.reducedMotion.remaining.slice(0, 4).map((r) => `${r.selector} \`${r.name}\` ${Math.round(r.durationMs)}ms`).join(", ")}${input.reducedMotion.remaining.length > 4 ? `, and ${input.reducedMotion.remaining.length - 4} more` : ""} — motion is not reduced for users who requested it. Add \`@media (prefers-reduced-motion: reduce)\` and either set \`animation: none\` on them or shorten each duration below ${durationFloor}ms. If an element only reaches its place through an animation (an entrance from off-screen or from opacity 0), give it that end state in the same rule — \`animation: none\` alone leaves it where the animation started.` + (input.reducedMotion.remaining.some((r) => r.selector.startsWith("(script-driven")) ? ` For the script-driven motion, read \`matchMedia("(prefers-reduced-motion: reduce)")\` and skip or shorten the loop.` : "") + (input.reducedMotion.remaining.some((r) => r.selector.includes(" a transition a timer started")) ? ` For a transition a timer started, \`transition: none\` on it in that rule reduces it too.` : "") + ` When the task's brief sets no reduced-motion policy, this is WCAG 2.3.3 (AAA) advice rather than a defect of the repair: say so and judge the rest with \`--rule reduced-motion-ignored=off\`.`
205
434
  });
206
435
  }
207
436
  return issues;
@@ -212,18 +441,42 @@ function deriveAnimationIssues(input, options = {}) {
212
441
  * the dedupe between them silently fails.
213
442
  */
214
443
  const ANIMATION_HELPERS_JS = `
444
+ function keyframeProps(anim) {
445
+ try {
446
+ const skip = new Set(["offset", "computedOffset", "easing", "composite"]);
447
+ const frames = anim.effect && anim.effect.getKeyframes ? anim.effect.getKeyframes() : [];
448
+ const props = new Set();
449
+ for (const k of frames) for (const key of Object.keys(k)) if (!skip.has(key)) props.add(key);
450
+ if (anim.transitionProperty) props.add(anim.transitionProperty);
451
+ return [...props];
452
+ } catch {}
453
+ return [];
454
+ }
215
455
  ${STABLE_SELECTOR_JS}
216
456
 
217
457
  function describeTiming(anim) {
218
- let timing = { duration: 0, delay: 0, iterations: 1, direction: "normal" };
458
+ let timing = { duration: 0, delay: 0, iterations: 1, direction: "normal", easing: "linear", fill: "none", startsHidden: false };
219
459
  try {
220
460
  const computed = anim.effect && anim.effect.getComputedTiming ? anim.effect.getComputedTiming() : null;
221
461
  if (computed) {
462
+ // A CSS animation's timing function lives on its keyframes (the effect's own easing is
463
+ // linear); a transition or el.animate() carries it on the effect.
464
+ const frames = anim.effect.getKeyframes ? anim.effect.getKeyframes().slice(0, -1) : [];
465
+ const keyed = [...new Set(frames.map((k) => k.easing).filter(Boolean))];
222
466
  timing = {
223
467
  duration: typeof computed.duration === "number" ? computed.duration : 0,
224
468
  delay: computed.delay || 0,
225
469
  iterations: computed.iterations,
226
470
  direction: computed.direction || "normal",
471
+ easing: computed.easing && computed.easing !== "linear" ? computed.easing : keyed.join(" / ") || "linear",
472
+ fill: computed.fill || "none",
473
+ // Its first keyframe leaves it unseen (opacity 0 or visibility hidden): held there
474
+ // through a delay by a backwards fill, the element is not on screen until it starts.
475
+ startsHidden: (() => {
476
+ const first = anim.effect.getKeyframes ? anim.effect.getKeyframes()[0] : null;
477
+ if (!first) return false;
478
+ return (first.opacity !== undefined && Number(first.opacity) <= 0.05) || first.visibility === "hidden";
479
+ })(),
227
480
  };
228
481
  }
229
482
  } catch {}
@@ -242,11 +495,18 @@ const ANIMATION_HELPERS_JS = `
242
495
  const first = keyframes[0];
243
496
  const last = keyframes[keyframes.length - 1];
244
497
  const props = Object.keys(first).filter((k) => !skip.has(k));
498
+ const same = (a, b) => props.every((k) => String(a[k]) === String(b[k]));
499
+ // Out and back means mirrored: each keyframe at offset o has its twin at 1 - o. An
500
+ // enter / hold / exit (0%, 15%, 90%, 100%, first == last) is not, and read "leg 1650ms".
501
+ const mirrored = keyframes.every((k) =>
502
+ keyframes.some((m) => Math.abs(m.computedOffset - (1 - k.computedOffset)) < 0.011 && same(k, m))
503
+ );
245
504
  return props.length > 0
246
505
  && props.every((k) => k in last && String(first[k]) === String(last[k]))
247
506
  && keyframes.slice(1, -1).some((mid) =>
248
507
  props.some((k) => k in mid && String(mid[k]) !== String(first[k]))
249
- );
508
+ )
509
+ && mirrored;
250
510
  } catch {}
251
511
  return false;
252
512
  }
@@ -296,6 +556,7 @@ ${ANIMATION_HELPERS_JS}
296
556
  const target = event.target;
297
557
  if (!target || !target.getAnimations) return;
298
558
  for (const anim of target.getAnimations()) {
559
+ if (anim.timeline && !(anim.timeline instanceof DocumentTimeline)) continue;
299
560
  const name = animationName(anim);
300
561
  if (event.animationName !== undefined && name !== event.animationName) continue;
301
562
  const timing = describeTiming(anim);
@@ -309,6 +570,7 @@ ${ANIMATION_HELPERS_JS}
309
570
  iterations: Number.isFinite(timing.iterations) ? timing.iterations : null,
310
571
  direction: timing.direction || "normal",
311
572
  palindromic: isPalindromic(anim),
573
+ properties: keyframeProps(anim),
312
574
  authorPlayState,
313
575
  });
314
576
  window.__vlmkitHeld.push(anim);
@@ -321,7 +583,16 @@ ${ANIMATION_HELPERS_JS}
321
583
  })()`;
322
584
  const COLLECT_ANIMATIONS_SCRIPT = `(() => {
323
585
  ${ANIMATION_HELPERS_JS}
324
- const anims = document.getAnimations ? document.getAnimations({ subtree: true }) : [];
586
+ // On a scroll timeline an animation's time is a share of the scroll, not ms: seeking it threw
587
+ // "not supported for progress based animations" (round 12). It is listed, not evaluated.
588
+ const all = document.getAnimations ? document.getAnimations({ subtree: true }) : [];
589
+ const anims = all.filter((a) => !a.timeline || a.timeline instanceof DocumentTimeline);
590
+ window.__vlmkitScrollDriven = all
591
+ .filter((a) => a.timeline && !(a.timeline instanceof DocumentTimeline))
592
+ .map((a) => {
593
+ const el = a.effect && a.effect.target;
594
+ return { selector: el ? stableSelector(el) : "(no target)", name: animationName(a), timeline: el ? getComputedStyle(el).animationTimeline : "" };
595
+ });
325
596
  window.__vlmkitAnims = anims;
326
597
  return anims.map((anim, index) => {
327
598
  const timing = describeTiming(anim);
@@ -349,14 +620,586 @@ ${ANIMATION_HELPERS_JS}
349
620
  name,
350
621
  durationMs: timing.duration,
351
622
  delayMs: timing.delay,
623
+ easing: timing.easing,
624
+ fill: timing.fill,
625
+ startsHidden: timing.startsHidden,
352
626
  iterations: Number.isFinite(timing.iterations) ? timing.iterations : null,
353
627
  playState,
354
628
  currentTimeMs,
355
629
  direction: timing.direction || "normal",
356
630
  palindromic,
631
+ properties: keyframeProps(anim),
357
632
  };
358
633
  });
359
634
  })()`;
635
+ /**
636
+ * Names in an element's computed `animation-name` that no animation ran under: the name has no
637
+ * @keyframes. A reduced-motion rule set to such a name ran nothing, so "honored" was reported
638
+ * for a toast that then never left (from a dynamic-markup run).
639
+ */
640
+ /** Properties whose animation changes how something looks, not where it is or how big. */
641
+ const NOT_MOTION = /* @__PURE__ */ new Set([
642
+ "opacity",
643
+ "visibility",
644
+ "display",
645
+ "contentVisibility",
646
+ "color",
647
+ "backgroundColor",
648
+ "borderColor",
649
+ "borderTopColor",
650
+ "borderRightColor",
651
+ "borderBottomColor",
652
+ "borderLeftColor",
653
+ "outlineColor",
654
+ "textDecorationColor",
655
+ "caretColor",
656
+ "fill",
657
+ "stroke",
658
+ "boxShadow",
659
+ "textShadow"
660
+ ]);
661
+ /**
662
+ * Every animated element at rest — each finite animation finished — with the opacity it renders
663
+ * at and the centre of its box: the targets the page's animations had (null), or those given.
664
+ */
665
+ const restStateScript = (selectors) => `(() => {
666
+ ${STABLE_SELECTOR_JS}
667
+ const given = ${JSON.stringify(selectors)};
668
+ const els = new Set();
669
+ if (given) for (const sel of given) { const el = document.querySelector(sel); if (el) els.add(el); }
670
+ else {
671
+ for (const a of document.getAnimations()) if (a.effect && a.effect.target) els.add(a.effect.target);
672
+ for (const r of window.__vlmkitStarted || []) { try { const el = document.querySelector(r.selector); if (el) els.add(el); } catch {} }
673
+ }
674
+ for (const a of document.getAnimations()) {
675
+ try { if (Number.isFinite(a.effect.getComputedTiming().endTime)) a.finish(); } catch {}
676
+ }
677
+ return [...els].map((el) => {
678
+ let op = getComputedStyle(el).visibility === "hidden" ? 0 : 1;
679
+ for (let n = el; n; n = n.parentElement) op *= Number(getComputedStyle(n).opacity);
680
+ const r = el.getBoundingClientRect();
681
+ return { selector: given ? given[[...els].indexOf(el)] ?? stableSelector(el) : stableSelector(el), opacity: op, x: r.x + r.width / 2, y: r.y + r.height / 2 };
682
+ });
683
+ })()`;
684
+ const UNKNOWN_TRANSITION_PROPERTY_SCRIPT = `(() => {
685
+ ${ANIMATION_HELPERS_JS}
686
+ const out = [];
687
+ const seen = new Set();
688
+ // Custom properties an @property rule registers (in the sheets the page can read): only those
689
+ // have a type, and a transition on any other one steps at once (round 13's ring).
690
+ const registered = new Set();
691
+ const walk = (rules) => {
692
+ for (const r of rules) {
693
+ if (typeof CSSPropertyRule !== "undefined" && r instanceof CSSPropertyRule) registered.add(r.name);
694
+ else if (r.cssRules) walk(r.cssRules);
695
+ }
696
+ };
697
+ for (const sheet of document.styleSheets) {
698
+ try { walk(sheet.cssRules); } catch {}
699
+ }
700
+ // Registered with a type anywhere (CSS.registerProperty in a script, a sheet the page cannot
701
+ // read): such a property computes \`initial\` to its initial value, an unregistered one to
702
+ // nothing. A switch registered from JS read as unregistered (held-out set).
703
+ const typedProperty = (name) => {
704
+ const probe = document.createElement("div");
705
+ probe.style.setProperty(name, "initial");
706
+ document.documentElement.append(probe);
707
+ const v = getComputedStyle(probe).getPropertyValue(name).trim();
708
+ probe.remove();
709
+ return v !== "";
710
+ };
711
+ // Every @keyframes rule by name, in sheet order, with the properties it animates: the last one
712
+ // of a name wins, and a component's fade-up lost its rise to a utility's later fade-up (round 15).
713
+ const keyframes = new Map();
714
+ const walkKf = (rules) => {
715
+ for (const r of rules) {
716
+ if (typeof CSSKeyframesRule !== "undefined" && r instanceof CSSKeyframesRule) {
717
+ const props = new Set();
718
+ for (const k of r.cssRules) for (let i = 0; i < k.style.length; i++) props.add(k.style[i]);
719
+ if (!keyframes.has(r.name)) keyframes.set(r.name, []);
720
+ keyframes.get(r.name).push([...props]);
721
+ } else if (r.cssRules) walkKf(r.cssRules);
722
+ }
723
+ };
724
+ for (const sheet of document.styleSheets) {
725
+ try { walkKf(sheet.cssRules); } catch {}
726
+ }
727
+ for (const el of document.querySelectorAll("*")) {
728
+ const cs = getComputedStyle(el);
729
+ if (out.length < 8) {
730
+ for (const a of el.getAnimations()) {
731
+ const name = a.animationName;
732
+ const t = a.effect && a.effect.getComputedTiming ? a.effect.getComputedTiming() : null;
733
+ const kf = a.effect && a.effect.getKeyframes ? a.effect.getKeyframes() : [];
734
+ const selector = stableSelector(el);
735
+ const defs = name ? keyframes.get(name) : undefined;
736
+ if (defs && defs.length > 1 && !seen.has("dup\u0000" + name)) {
737
+ seen.add("dup\u0000" + name);
738
+ out.push({ selector, name, duplicate: defs.map((d) => d.join(", ")) });
739
+ }
740
+ // An entrance with a negative delay starts part way through: a row 240ms into its 300ms
741
+ // rise was there at load, and the stagger read as running backwards (round 15).
742
+ const first = kf[0] || {};
743
+ const hiddenStart = Number(first.opacity) < 0.05 || (first.transform && first.transform !== "none") || (first.translate && first.translate !== "none");
744
+ if (t && Number(t.delay) < 0 && Number.isFinite(Number(t.iterations)) && hiddenStart && !seen.has("neg\u0000" + selector)) {
745
+ seen.add("neg\u0000" + selector);
746
+ out.push({ selector, name: name || "an animation", negativeDelayMs: Number(t.delay), durationMs: Number(t.duration) });
747
+ }
748
+ // Held paused by the page's CSS (animation-play-state: paused) while it hides the element:
749
+ // results held by a boot class that a script never removed stayed at opacity 0 for good,
750
+ // and the evaluation, seeking every animation, read them "visible" (round 16).
751
+ if (a.playState === "paused" && /paused/.test(cs.animationPlayState) && Number(cs.opacity) < 0.05 && !seen.has("hold\u0000" + selector)) {
752
+ seen.add("hold\u0000" + selector);
753
+ let rule = "";
754
+ const findRule = (rules) => {
755
+ for (const r of rules) {
756
+ if (rule) return;
757
+ if (r.selectorText && r.style && /paused/.test(r.style.animationPlayState || "")) {
758
+ try { if (el.matches(r.selectorText)) rule = r.selectorText + " { animation-play-state: " + r.style.animationPlayState + (r.style.getPropertyPriority("animation-play-state") ? " !important" : "") + " }"; } catch {}
759
+ } else if (r.cssRules) findRule(r.cssRules);
760
+ }
761
+ };
762
+ for (const sheet of document.styleSheets) { try { findRule(sheet.cssRules); } catch {} }
763
+ if (!rule && /paused/.test(el.style.animationPlayState || "")) rule = "its style attribute";
764
+ out.push({ selector, name: name || "an animation", heldPaused: rule || "animation-play-state: paused" });
765
+ }
766
+ // steps() written inside a keyframe overrides the element's smooth easing: a shared
767
+ // entrance's from { animation-timing-function: steps(5, end) } made a panel hop (round 17).
768
+ {
769
+ const stepFn = (e) => /^steps\\(|^step-/.test(String(e || ""));
770
+ const names = cs.animationName.split(/,\\s*/);
771
+ const fns = cs.animationTimingFunction.split(/,\\s*(?![^()]*\\))/);
772
+ const mine = (fns[Math.max(0, names.indexOf(name)) % Math.max(1, fns.length)] || "ease").trim();
773
+ const odd = !stepFn(mine) ? kf.slice(0, -1).find((k) => stepFn(k.easing)) : undefined;
774
+ if (name && odd && !seen.has("stp\\u0000" + selector)) {
775
+ seen.add("stp\\u0000" + selector);
776
+ out.push({ selector, name, steppedKeyframe: { at: odd.offset === 0 ? "from" : odd.offset === 1 ? "to" : Math.round(Number(odd.computedOffset ?? odd.offset) * 100) + "%", easing: String(odd.easing), own: mine } });
777
+ }
778
+ }
779
+ // width / height animated on a non-replaced inline box do nothing: a usage bar written as
780
+ // an empty <span> stayed 0x0 for its whole fill (round 17).
781
+ if (cs.display === "inline" && !/^(img|video|canvas|svg|iframe|input|select|textarea|object|embed)$/i.test(el.tagName) && !seen.has("inl\\u0000" + selector)) {
782
+ const sizes = [...new Set(kf.flatMap((k) => Object.keys(k).filter((p) => /^(width|height|min-width|min-height|max-width|max-height|inline-size|block-size)$/.test(p))))];
783
+ if (sizes.length > 0) {
784
+ seen.add("inl\\u0000" + selector);
785
+ out.push({ selector, name: name || "an animation", inertSize: sizes, tag: el.tagName.toLowerCase() });
786
+ }
787
+ }
788
+ // A fill that holds a filter at rest: blur(0.6px) left a card soft for good, and even
789
+ // blur(0) keeps a filter layer the card is rasterised through (round 15).
790
+ const last = kf[kf.length - 1] || {};
791
+ const changes = (f) => [...f.matchAll(/([a-z-]+)\\(([^)]*)\\)/g)].some(([, fn, arg]) => {
792
+ const v = parseFloat(arg);
793
+ if (!Number.isFinite(v)) return true;
794
+ if (/^(blur|grayscale|sepia|invert|hue-rotate)$/.test(fn)) return Math.abs(v) > 1e-3;
795
+ if (/^(brightness|contrast|saturate|opacity)$/.test(fn)) return Math.abs((arg.includes("%") ? v / 100 : v) - 1) > 1e-3;
796
+ return true;
797
+ });
798
+ if (t && (t.fill === "forwards" || t.fill === "both") && last.filter && last.filter !== "none" && changes(String(last.filter)) && !seen.has("flt\u0000" + selector)) {
799
+ seen.add("flt\u0000" + selector);
800
+ out.push({ selector, name: name || "an animation", restFilter: String(last.filter) });
801
+ }
802
+ }
803
+ }
804
+ // Two animations on one element on one property: the later in animation-name wins wherever its
805
+ // fill reaches. A toast's rise was replaced for its whole run by the pulse after it, whose both
806
+ // fill held scale(1) through its delay, and the rise read "visible" from its fade (round 18).
807
+ if (out.length < 8) {
808
+ const order = cs.animationName.split(/,\\s*/);
809
+ const css = el.getAnimations().filter((a) => typeof CSSAnimation !== "undefined" && a instanceof CSSAnimation)
810
+ .sort((a, b) => order.indexOf(a.animationName) - order.indexOf(b.animationName));
811
+ const propsOf = (a) => new Set(((a.effect && a.effect.getKeyframes) ? a.effect.getKeyframes() : []).flatMap((k) => Object.keys(k).filter((p) => !["offset", "computedOffset", "easing", "composite", "opacity"].includes(p))));
812
+ const span = (a, applying) => {
813
+ const t = a.effect.getComputedTiming();
814
+ const delay = Number(t.delay) || 0;
815
+ const end = Number(t.endTime);
816
+ const fill = t.fill;
817
+ const from = applying && (fill === "backwards" || fill === "both") ? 0 : delay;
818
+ const to = applying && (fill === "forwards" || fill === "both") ? Infinity : end;
819
+ return [from, to, delay, fill];
820
+ };
821
+ for (let i = 0; i < css.length; i++) {
822
+ for (let j = i + 1; j < css.length; j++) {
823
+ const shared = [...propsOf(css[j])].filter((p) => propsOf(css[i]).has(p));
824
+ if (shared.length === 0 || (css[j].effect.composite || "replace") !== "replace") continue;
825
+ const [ai, bi] = span(css[i], false);
826
+ const [aj, bj, dj, fj] = span(css[j], true);
827
+ const overlap = Math.min(bi, bj) - Math.max(ai, aj);
828
+ const selector = stableSelector(el);
829
+ if (overlap > 0 && !seen.has("ovr\u0000" + selector)) {
830
+ seen.add("ovr\u0000" + selector);
831
+ out.push({ selector, name: css[i].animationName, overridden: { by: css[j].animationName, props: shared, delayMs: dj, fill: fj, coveredMs: Number.isFinite(overlap) ? Math.round(overlap) : null } });
832
+ }
833
+ }
834
+ }
835
+ }
836
+ // A counter-rotation that does not cancel its ancestor's turn: a label at -360deg per 5s inside
837
+ // a dial at 360deg per 4s drifted 18deg/s on screen (round 18).
838
+ if (out.length < 8) {
839
+ const turnRate = (node) => {
840
+ for (const a of node.getAnimations()) {
841
+ if (typeof CSSAnimation === "undefined" || !(a instanceof CSSAnimation)) continue;
842
+ const t = a.effect.getComputedTiming();
843
+ if (t.iterations !== Infinity || !(Number(t.duration) > 0)) continue;
844
+ const kf = a.effect.getKeyframes();
845
+ const angle = (k) => {
846
+ const m = /rotate(?:Z)?\\((-?[\\d.]+)(deg|turn|rad|grad)\\)/.exec(String((k && (k.transform || k.rotate)) || ""));
847
+ if (!m) return 0;
848
+ const v = Number(m[1]);
849
+ return m[2] === "turn" ? v * 360 : m[2] === "rad" ? (v * 180) / Math.PI : m[2] === "grad" ? v * 0.9 : v;
850
+ };
851
+ const d = angle(kf[kf.length - 1]) - angle(kf[0]);
852
+ if (Math.abs(d) < 1) continue;
853
+ return { rate: (d / Number(t.duration)) * 1000, name: a.animationName, ms: Number(t.duration), deg: d };
854
+ }
855
+ return null;
856
+ };
857
+ const mine = turnRate(el);
858
+ if (mine) {
859
+ for (let p = el.parentElement; p; p = p.parentElement) {
860
+ const theirs = turnRate(p);
861
+ if (!theirs) continue;
862
+ const net = mine.rate + theirs.rate;
863
+ const selector = stableSelector(el);
864
+ if (Math.sign(mine.rate) !== Math.sign(theirs.rate) && Math.abs(net) > 0.5 && !seen.has("ctr\u0000" + selector)) {
865
+ seen.add("ctr\u0000" + selector);
866
+ out.push({ selector, name: mine.name, counterDrift: { ancestor: stableSelector(p), theirs: theirs.name, mine: { deg: mine.deg, ms: mine.ms }, other: { deg: theirs.deg, ms: theirs.ms }, net } });
867
+ }
868
+ break;
869
+ }
870
+ }
871
+ }
872
+ // An offset animated on a static box does nothing: a notice meant to slide in animated
873
+ // \`left\` and only faded, and \`check animation\` read it "visible" (round 14).
874
+ if (cs.position === "static" && out.length < 8) {
875
+ for (const a of el.getAnimations()) {
876
+ const kf = (a.effect && a.effect.getKeyframes) ? a.effect.getKeyframes() : [];
877
+ const offs = [...new Set(kf.flatMap((k) => Object.keys(k).filter((p) => /^(top|left|right|bottom|inset)/.test(p))))];
878
+ if (offs.length === 0) continue;
879
+ // It moves by a transform as well: the slide happens, the offset is only dead weight (a
880
+ // held-out box animating left and translateX together slid 200px and read "never moves").
881
+ if (kf.some((k) => ["transform", "translate"].some((p) => k[p] !== undefined && k[p] !== "none"))) continue;
882
+ const selector = stableSelector(el);
883
+ const key = selector + "\u0000" + (a.animationName || "");
884
+ if (seen.has(key)) continue;
885
+ seen.add(key);
886
+ out.push({ selector, name: a.animationName || "an animation", inertOffsets: offs });
887
+ }
888
+ }
889
+ const props = cs.transitionProperty.split(",").map((p) => p.trim());
890
+ const durations = cs.transitionDuration.split(",").map((d) => parseFloat(d) || 0);
891
+ props.forEach((name, i) => {
892
+ if (!name || name === "all" || name === "none") return;
893
+ if (!(durations[i % durations.length] > 0)) return;
894
+ if (name.startsWith("--")) {
895
+ if (registered.has(name) || typedProperty(name)) return;
896
+ const selector = stableSelector(el);
897
+ if (seen.has(selector + "\u0000" + name) || out.length >= 8) return;
898
+ seen.add(selector + "\u0000" + name);
899
+ out.push({ selector, name, unregistered: true });
900
+ return;
901
+ }
902
+ if (CSS.supports(name, "initial")) return;
903
+ const selector = stableSelector(el);
904
+ if (seen.has(selector + "\\u0000" + name) || out.length >= 8) return;
905
+ seen.add(selector + "\\u0000" + name);
906
+ out.push({ selector, name });
907
+ });
908
+ }
909
+ // A duration token with no unit: transition: transform var(--motion-fast) with --motion-fast: 180
910
+ // is invalid at computed-value time, so the drawer had no transition and snapped (round 18).
911
+ {
912
+ const PROPS = ["transition", "transition-duration", "transition-delay", "animation", "animation-duration", "animation-delay"];
913
+ const walkVar = (rules) => {
914
+ for (const r of rules) {
915
+ if (out.length >= 8) return;
916
+ if (typeof CSSStyleRule !== "undefined" && r instanceof CSSStyleRule) {
917
+ for (const prop of PROPS) {
918
+ const text = r.style.getPropertyValue(prop);
919
+ if (!text || !text.includes("var(")) continue;
920
+ let el = null;
921
+ try { el = document.querySelector(r.selectorText); } catch {}
922
+ if (!el) continue;
923
+ const cs = getComputedStyle(el);
924
+ for (const m of text.matchAll(/var\\(\\s*(--[\\w-]+)/g)) {
925
+ // Inside calc() a unitless number is a multiplier (calc(var(--i) * 80ms)), not a duration.
926
+ const before = text.slice(0, m.index);
927
+ const at = before.lastIndexOf("calc(");
928
+ if (at >= 0) {
929
+ let depth = 0;
930
+ for (const ch of before.slice(at + 4)) depth += ch === "(" ? 1 : ch === ")" ? -1 : 0;
931
+ if (depth > 0) continue;
932
+ }
933
+ const v = cs.getPropertyValue(m[1]).trim();
934
+ const key = "var\u0000" + r.selectorText + "\u0000" + prop;
935
+ if (/^-?\\d*\\.?\\d+$/.test(v) && !seen.has(key)) {
936
+ seen.add(key);
937
+ out.push({ selector: r.selectorText, name: prop, unitlessVar: { prop, text, variable: m[1], value: v } });
938
+ }
939
+ }
940
+ }
941
+ } else if (r.cssRules) walkVar(r.cssRules);
942
+ }
943
+ };
944
+ for (const sheet of document.styleSheets) { try { walkVar(sheet.cssRules); } catch {} }
945
+ }
946
+ // An @media whose feature the browser does not know never matches (it reads as "not all"): an
947
+ // entrance behind @media (prefers-reduce-motion: no-preference) never played for anyone, and
948
+ // the page read "animations: 0 … No animation issues detected" (round 17).
949
+ {
950
+ const KNOWN = ["prefers-reduced-motion", "prefers-color-scheme", "prefers-contrast", "prefers-reduced-transparency", "forced-colors", "hover", "any-hover", "pointer", "any-pointer", "orientation", "min-width", "max-width", "width", "min-height", "max-height", "height", "aspect-ratio", "resolution", "min-resolution", "max-resolution", "color-gamut", "display-mode", "scripting", "inverted-colors"];
951
+ const near = (f) => {
952
+ let best = null, bd = Infinity;
953
+ for (const k of KNOWN) {
954
+ const d = (() => { const m = []; for (let i = 0; i <= f.length; i++) { m[i] = [i]; for (let j = 1; j <= k.length; j++) m[i][j] = i === 0 ? j : Math.min(m[i - 1][j] + 1, m[i][j - 1] + 1, m[i - 1][j - 1] + (f[i - 1] === k[j - 1] ? 0 : 1)); } return m[f.length][k.length]; })();
955
+ if (d < bd) { bd = d; best = k; }
956
+ }
957
+ return bd <= 3 ? best : null;
958
+ };
959
+ const moves = (rules) => [...rules].some((r) => (r.style && (/\\S/.test(r.style.animationName || "") && r.style.animationName !== "none" || /\\S/.test(r.style.transitionProperty || "") && (r.style.transitionDuration || "0s") !== "0s")) || (r.cssRules && moves(r.cssRules)));
960
+ // Chromium keeps an unknown feature's text and evaluates it as false; so does its negation. A
961
+ // known feature (and value) matches exactly one of (f) and not (f).
962
+ const unknownAtom = (cond) => {
963
+ for (const m of String(cond).matchAll(/\\(([^()]+)\\)/g)) {
964
+ const atom = "(" + m[1] + ")";
965
+ if (!window.matchMedia(atom).matches && !window.matchMedia("not " + atom).matches) return m[1].trim();
966
+ }
967
+ return null;
968
+ };
969
+ const walkMedia = (rules) => {
970
+ for (const r of rules) {
971
+ if (typeof CSSMediaRule !== "undefined" && r instanceof CSSMediaRule && moves(r.cssRules)) {
972
+ const header = r.conditionText || r.media.mediaText;
973
+ const atom = unknownAtom(header);
974
+ if (atom && !seen.has("med\\u0000" + header) && out.length < 8) {
975
+ seen.add("med\\u0000" + header);
976
+ const feature = (/^\\s*([a-z-]+)/i.exec(atom) || [])[1] || "";
977
+ out.push({ selector: "@media " + header, name: "@media", unknownMedia: { header, feature, suggest: feature ? near(feature) : null } });
978
+ }
979
+ } else if (r.cssRules) walkMedia(r.cssRules);
980
+ }
981
+ };
982
+ for (const sheet of document.styleSheets) { try { walkMedia(sheet.cssRules); } catch {} }
983
+ }
984
+ return out;
985
+ })()`;
986
+ /**
987
+ * What an animation does beyond its own box, read from the held animations themselves
988
+ * (motion-repair round 10, where each of these passed every gate):
989
+ * - `pushes`: an in-flow element animating a layout property (`margin-top`) moves the elements
990
+ * after it — their boxes at the start and the end of its first run differ.
991
+ * - `seams`: a repeating animation whose run does not end on the pose the next one begins on
992
+ * (a spinner keyed to 350deg jumps 10deg a second). The step across the end of a run against
993
+ * the steps either side of it; `steps()` timing is left out (every step jumps by design).
994
+ * - `strokes`: a dashed SVG stroke drawing itself that rests part drawn (a dash shorter than
995
+ * its line), from the dash pattern along the path's length.
996
+ * - `indicators`: a looping animation on a loading indicator (role progressbar / status,
997
+ * aria-busy, or named spin / load / busy), which is meant to run forever.
998
+ * Each animation's time is put back as it was found.
999
+ */
1000
+ const MOTION_SHAPE_SCRIPT = `(() => {
1001
+ ${ANIMATION_HELPERS_JS}
1002
+ const anims = window.__vlmkitAnims || [];
1003
+ const LAYOUT = /^(margin|padding|width|height|minWidth|minHeight|maxWidth|maxHeight|borderWidth|border(Top|Right|Bottom|Left)Width|fontSize|lineHeight|flexBasis|gap|rowGap|columnGap|gridTemplate)/;
1004
+ const nums = (v) => (String(v).match(/-?\\d*\\.?\\d+(e-?\\d+)?/g) || []).map(Number);
1005
+ const pose = (el, props) => {
1006
+ const cs = getComputedStyle(el);
1007
+ const out = {};
1008
+ for (const p of props) {
1009
+ if (p === "transform") {
1010
+ const m = new DOMMatrix(cs.transform === "none" ? undefined : cs.transform);
1011
+ out.turn = (Math.atan2(m.b, m.a) * 180) / Math.PI;
1012
+ out.x = m.e;
1013
+ out.y = m.f;
1014
+ out.scale = Math.hypot(m.a, m.b) * 100;
1015
+ } else if (p === "opacity") out.opacity = Number(cs.opacity) * 100;
1016
+ else nums(cs[p]).forEach((n, i) => { out[p + i] = n; });
1017
+ }
1018
+ return out;
1019
+ };
1020
+ const diff = (a, b) => {
1021
+ const d = {};
1022
+ for (const k of Object.keys(a)) {
1023
+ let v = Math.abs((b[k] ?? 0) - a[k]);
1024
+ if (k === "turn") v = Math.min(v, 360 - v);
1025
+ d[k] = v;
1026
+ }
1027
+ return d;
1028
+ };
1029
+ const unit = (k) => (k === "turn" ? "°" : k === "opacity" || k === "scale" ? "%" : "px");
1030
+ // What is in view of it: its children (or itself), clipped by every clipping ancestor and the
1031
+ // viewport, with their content. A ticker one copy long and a shimmer clipped away at both ends
1032
+ // jump in their transform and in nothing seen (authoring v1).
1033
+ const inView = (el) => {
1034
+ let clip = { l: 0, t: 0, r: innerWidth, b: innerHeight };
1035
+ for (let n = el.parentElement; n; n = n.parentElement) {
1036
+ const cs = getComputedStyle(n);
1037
+ if (cs.overflowX !== "visible" || cs.overflowY !== "visible" || cs.clipPath !== "none") {
1038
+ const q = n.getBoundingClientRect();
1039
+ clip = { l: Math.max(clip.l, q.left), t: Math.max(clip.t, q.top), r: Math.min(clip.r, q.right), b: Math.min(clip.b, q.bottom) };
1040
+ }
1041
+ }
1042
+ const parts = el.children.length > 0 ? [...el.children] : [el];
1043
+ return parts
1044
+ .map((c) => ({ q: c.getBoundingClientRect(), key: c.tagName + "." + c.className + "|" + (c.textContent || "").trim().slice(0, 80) }))
1045
+ .filter(({ q }) => q.right > clip.l + 0.5 && q.left < clip.r - 0.5 && q.bottom > clip.t + 0.5 && q.top < clip.b - 0.5)
1046
+ .map(({ q, key }) => ({ x: q.left, y: q.top, w: q.width, h: q.height, key }));
1047
+ };
1048
+ const sameView = (a, b) =>
1049
+ a.length === b.length &&
1050
+ a.every((p) => b.some((q) => q.key === p.key && Math.abs(q.x - p.x) < 1.5 && Math.abs(q.y - p.y) < 1.5 && Math.abs(q.w - p.w) < 1.5 && Math.abs(q.h - p.h) < 1.5));
1051
+ const describe = (el) => {
1052
+ let n = el, why = null;
1053
+ for (let depth = 0; n && depth < 4 && !why; n = n.parentElement, depth++) {
1054
+ const role = n.getAttribute && n.getAttribute("role");
1055
+ if (role === "progressbar" || role === "status") why = 'role="' + role + '"';
1056
+ else if (n.getAttribute && n.getAttribute("aria-busy") === "true") why = 'aria-busy="true"';
1057
+ }
1058
+ return why;
1059
+ };
1060
+ const out = { pushes: [], seams: [], strokes: [], indicators: [] };
1061
+ anims.forEach((anim, index) => {
1062
+ const el = anim.effect && anim.effect.target;
1063
+ if (!el || !anim.effect.getComputedTiming) return;
1064
+ const t = anim.effect.getComputedTiming();
1065
+ const d = typeof t.duration === "number" ? t.duration : 0;
1066
+ if (!(d > 0)) return;
1067
+ const delay = t.delay || 0;
1068
+ const props = keyframeProps(anim);
1069
+ const saved = anim.currentTime;
1070
+ const selector = stableSelector(el);
1071
+ const name = animationName(anim);
1072
+ try {
1073
+ const repeats = !Number.isFinite(t.iterations) || t.iterations > 1;
1074
+ if (repeats) {
1075
+ const why = describe(el) || (/spin|load|busy|progress|shimmer|skeleton|marquee|ticker/i.test(name + " " + (el.className && el.className.baseVal !== undefined ? el.className.baseVal : el.className)) ? "named " + name : null);
1076
+ if (why) out.indicators.push({ index, selector, name, why });
1077
+ }
1078
+ const frames = anim.effect.getKeyframes ? anim.effect.getKeyframes() : [];
1079
+ const stepped = [t.easing || "", ...frames.map((k) => k.easing || "")].some((e) => /steps|step-/.test(e));
1080
+ if (repeats && !stepped && !String(t.direction).startsWith("alternate") && props.length > 0) {
1081
+ const at = (ms) => { anim.currentTime = ms; return pose(el, props); };
1082
+ const end = delay + d;
1083
+ const a = at(end - 2), b = at(end - 1);
1084
+ const v1 = inView(el);
1085
+ const c = at(end + 0.001);
1086
+ const v2 = inView(el);
1087
+ const e = at(end + 1);
1088
+ const before = diff(a, b), across = diff(b, c), after = diff(c, e);
1089
+ const unseen = sameView(v1, v2);
1090
+ for (const k of Object.keys(across)) {
1091
+ const usual = Math.max(before[k], after[k]);
1092
+ if (across[k] >= 2 && across[k] > 4 * usual + 0.5 && !((k === "x" || k === "y") && unseen)) {
1093
+ const first = frames[0], last = frames[frames.length - 1];
1094
+ const prop = k === "turn" || k === "x" || k === "y" || k === "scale" ? "transform" : k.replace(/\\d+$/, "");
1095
+ out.seams.push({
1096
+ selector, name, channel: k, step: across[k], usual, unit: unit(k),
1097
+ from: first && first[prop] !== undefined ? String(first[prop]) : null,
1098
+ to: last && last[prop] !== undefined ? String(last[prop]) : null,
1099
+ prop,
1100
+ });
1101
+ break;
1102
+ }
1103
+ }
1104
+ }
1105
+ const cs = getComputedStyle(el);
1106
+ const inFlow = cs.position !== "absolute" && cs.position !== "fixed";
1107
+ const layoutProps = props.filter((p) => LAYOUT.test(p));
1108
+ if (inFlow && layoutProps.length > 0) {
1109
+ const skip = new Set();
1110
+ for (let n = el; n; n = n.parentElement) skip.add(n);
1111
+ const others = [...document.body.querySelectorAll("*")].filter((n) => !skip.has(n) && !el.contains(n)).slice(0, 2000);
1112
+ const rects = () => others.map((n) => n.getBoundingClientRect());
1113
+ anim.currentTime = delay;
1114
+ const start = rects();
1115
+ anim.currentTime = delay + d - 0.001;
1116
+ const finish = rects();
1117
+ const moved = [];
1118
+ others.forEach((n, i) => {
1119
+ const s0 = start[i], s1 = finish[i];
1120
+ if (s0.width === 0 && s0.height === 0 && s1.width === 0 && s1.height === 0) return;
1121
+ const dx = s1.x - s0.x, dy = s1.y - s0.y;
1122
+ if (Math.hypot(dx, dy) < 2) return;
1123
+ // Only the outermost of what moved together: a moved paragraph's text moves with it.
1124
+ const parent = n.parentElement;
1125
+ const pi = parent ? others.indexOf(parent) : -1;
1126
+ if (pi >= 0) {
1127
+ const pdx = finish[pi].x - start[pi].x, pdy = finish[pi].y - start[pi].y;
1128
+ if (Math.abs(pdx - dx) < 1 && Math.abs(pdy - dy) < 1) return;
1129
+ }
1130
+ moved.push({ selector: stableSelector(n), dx, dy });
1131
+ });
1132
+ if (moved.length > 0) out.pushes.push({ selector, name, props: layoutProps, moved: moved.slice(0, 3), count: moved.length });
1133
+ }
1134
+ if (el instanceof SVGGeometryElement && Number.isFinite(t.iterations) && props.some((p) => p === "strokeDashoffset" || p === "strokeDasharray")) {
1135
+ const drawnShare = () => {
1136
+ const st = getComputedStyle(el);
1137
+ if (!st.strokeDasharray || st.strokeDasharray === "none") return 1;
1138
+ const dash = st.strokeDasharray.split(/[ ,]+/).map(parseFloat).filter((v) => Number.isFinite(v));
1139
+ const pattern = dash.length % 2 === 1 ? [...dash, ...dash] : dash;
1140
+ const period = pattern.reduce((x, y) => x + y, 0);
1141
+ const len = el.getTotalLength();
1142
+ const attr = Number(el.getAttribute("pathLength"));
1143
+ const scaleLen = Number.isFinite(attr) && attr > 0 ? attr / len : 1;
1144
+ const off = parseFloat(st.strokeDashoffset) || 0;
1145
+ if (!(period > 0 && len > 0)) return 1;
1146
+ let on = 0;
1147
+ const step = len / 400;
1148
+ for (let x = step / 2; x < len; x += step) {
1149
+ let ph = (((x * scaleLen + off) % period) + period) % period;
1150
+ for (let k = 0; k < pattern.length; k++) {
1151
+ if (ph < pattern[k]) { if (k % 2 === 0) on++; break; }
1152
+ ph -= pattern[k];
1153
+ }
1154
+ }
1155
+ return { drawn: on / 400, note: "stroke-dasharray " + st.strokeDasharray + " with stroke-dashoffset " + st.strokeDashoffset + " on a line " + (len * scaleLen).toFixed(1) + " long" };
1156
+ };
1157
+ anim.currentTime = delay;
1158
+ const first = drawnShare();
1159
+ anim.currentTime = delay + d * t.iterations;
1160
+ const rest = drawnShare();
1161
+ const fd = typeof first === "number" ? first : first.drawn;
1162
+ if (typeof rest !== "number" && Math.abs(rest.drawn - fd) > 0.05 && rest.drawn > 0.02 && rest.drawn < 0.98) {
1163
+ out.strokes.push({ selector, name, drawn: rest.drawn, note: rest.note });
1164
+ }
1165
+ }
1166
+ } catch {}
1167
+ anim.currentTime = saved;
1168
+ });
1169
+ return out;
1170
+ })()`;
1171
+ const DISCRETE_TRANSITION_SCRIPT = `(() => {
1172
+ ${ANIMATION_HELPERS_JS}
1173
+ const out = [];
1174
+ for (const el of document.querySelectorAll("*")) {
1175
+ const cs = getComputedStyle(el);
1176
+ if (!/gradient\\(/.test(cs.backgroundImage)) continue;
1177
+ const props = cs.transitionProperty.split(",").map((p) => p.trim());
1178
+ const durations = cs.transitionDuration.split(",").map((d) => parseFloat(d) || 0);
1179
+ // Named, not \`all\`: a gradient button with \`transition: all\` for its hover lift was 4 of 5
1180
+ // findings on the repo's pages, and its gradient never changes.
1181
+ const i = props.findIndex((p, k) => /^(background|background-image)$/.test(p) && durations[k % durations.length] > 0);
1182
+ if (i < 0 || out.length >= 8) continue;
1183
+ const image = cs.backgroundImage.length > 60 ? cs.backgroundImage.slice(0, 57) + "..." : cs.backgroundImage;
1184
+ out.push({ selector: stableSelector(el), name: props[i], image });
1185
+ }
1186
+ return out;
1187
+ })()`;
1188
+ const UNDEFINED_KEYFRAMES_SCRIPT = `(() => {
1189
+ ${ANIMATION_HELPERS_JS}
1190
+ const ran = new Set((window.__vlmkitStarted || []).map((r) => r.selector + "\\u0000" + r.name));
1191
+ const out = [];
1192
+ for (const el of document.querySelectorAll("*")) {
1193
+ const names = getComputedStyle(el).animationName.split(",").map((n) => n.trim()).filter((n) => n && n !== "none");
1194
+ if (names.length === 0) continue;
1195
+ const selector = stableSelector(el);
1196
+ const live = new Set(el.getAnimations().map((a) => a.animationName).filter(Boolean));
1197
+ for (const name of names) {
1198
+ if (!live.has(name) && !ran.has(selector + "\\u0000" + name)) out.push({ selector, name });
1199
+ }
1200
+ }
1201
+ return out;
1202
+ })()`;
360
1203
  function pngFromBuffer(buffer) {
361
1204
  const png = PNG.sync.read(buffer);
362
1205
  return {
@@ -409,8 +1252,59 @@ async function sampleClock(page, baseline, shot, windowMs, count, tolerance, min
409
1252
  const frames = [];
410
1253
  let previous = baseline;
411
1254
  let motionBbox = null;
1255
+ const listStarted = () => page.evaluate(`(() => {
1256
+ ${STABLE_SELECTOR_JS}
1257
+ const seen = (window.__vlmkitSeenAnims = window.__vlmkitSeenAnims || new WeakSet());
1258
+ const targets = (window.__vlmkitSeenTargets = window.__vlmkitSeenTargets || new WeakSet());
1259
+ return document.getAnimations().map((a) => {
1260
+ const el = a.effect && a.effect.target;
1261
+ const fresh = !seen.has(a);
1262
+ seen.add(a);
1263
+ const newElement = !!el && !targets.has(el);
1264
+ if (el) targets.add(el);
1265
+ const kind = typeof a.transitionProperty === "string" ? "transition" : "animation";
1266
+ const name = kind === "transition" ? a.transitionProperty : (a.animationName || a.id || "(el.animate)");
1267
+ let durationMs = null;
1268
+ try { durationMs = Number(a.effect.getComputedTiming().duration) || null; } catch {}
1269
+ return { key: (el ? stableSelector(el) : "(no target)") + "\\u0000" + kind + "\\u0000" + name, selector: el ? stableSelector(el) : "(no target)", name, kind, durationMs, fresh, newElement };
1270
+ });
1271
+ })()`);
1272
+ const readRuns = () => page.evaluate(() => {
1273
+ const c = window.__vlmkitClock;
1274
+ return c?.runs ? c.runs() : null;
1275
+ }).catch(() => null);
1276
+ const runsBefore = await readRuns();
1277
+ const known = new Set((await listStarted().catch(() => [])).map((a) => a.key));
1278
+ const started = [];
1279
+ const replays = /* @__PURE__ */ new Map();
1280
+ let prevT = 0;
412
1281
  for (const t of times) {
413
1282
  await advanceClock(page, t);
1283
+ for (const a of await listStarted().catch(() => [])) {
1284
+ if (known.has(a.key) && a.fresh && a.kind === "animation") {
1285
+ const r = replays.get(a.key) ?? {
1286
+ selector: a.selector,
1287
+ name: a.name,
1288
+ atMs: [],
1289
+ newElement: false
1290
+ };
1291
+ r.atMs.push(t);
1292
+ r.newElement ||= a.newElement;
1293
+ replays.set(a.key, r);
1294
+ continue;
1295
+ }
1296
+ if (known.has(a.key)) continue;
1297
+ known.add(a.key);
1298
+ started.push({
1299
+ selector: a.selector,
1300
+ name: a.name,
1301
+ kind: a.kind,
1302
+ atMs: t,
1303
+ afterMs: prevT,
1304
+ ...a.durationMs !== null ? { durationMs: a.durationMs } : {}
1305
+ });
1306
+ }
1307
+ prevT = t;
414
1308
  const frame = await shot(`${label}-${t}ms`);
415
1309
  const delta = frameDelta(previous, frame, tolerance);
416
1310
  frames.push(delta);
@@ -418,6 +1312,7 @@ async function sampleClock(page, baseline, shot, windowMs, count, tolerance, min
418
1312
  previous = frame;
419
1313
  }
420
1314
  const errors = await page.evaluate(() => [...window.__vlmkitClock.errors]);
1315
+ const runsAfter = await readRuns();
421
1316
  return {
422
1317
  windowMs,
423
1318
  times,
@@ -425,13 +1320,19 @@ async function sampleClock(page, baseline, shot, windowMs, count, tolerance, min
425
1320
  motionBbox,
426
1321
  visible: frames.some((f) => f.changedPixels >= minChangedPixels),
427
1322
  settledAtMs: clockSettledAt(times, frames, minChangedPixels),
428
- errors: errors.slice(0, 5)
1323
+ errors: errors.slice(0, 5),
1324
+ ...started.length > 0 ? { started } : {},
1325
+ ...replays.size > 0 ? { replays: [...replays.values()] } : {},
1326
+ ...runsBefore && runsAfter ? { runs: {
1327
+ frames: runsAfter.frames - runsBefore.frames,
1328
+ timers: runsAfter.timers - runsBefore.timers
1329
+ } } : {}
429
1330
  };
430
1331
  }
431
1332
  async function runAnimationEval(options) {
432
1333
  const viewport = options.viewport ?? {
433
1334
  width: 1280,
434
- height: 720
1335
+ height: 800
435
1336
  };
436
1337
  const samples = Math.max(1, options.samples ?? 4);
437
1338
  const maxAnimations = options.maxAnimations ?? 8;
@@ -449,16 +1350,31 @@ async function runAnimationEval(options) {
449
1350
  } else await navigatePage(p, pageUrl, options);
450
1351
  if (options.virtualTime) await advanceClock(p, 0);
451
1352
  };
1353
+ if (options.framesDir && pageUrl === void 0) throw new UsageError("--frames needs the page as a file or URL to load, not inline HTML.");
1354
+ const framePaths = [];
452
1355
  return await withBrowser(async (browser) => {
453
1356
  const page = await browser.newPage({ viewport });
454
1357
  await loadPage(page);
455
1358
  const timings = await collectAnimations(page);
456
- const selfDriven = timings.filter((t) => t.playState !== "paused" && t.playState !== "idle");
457
- const settleMs = computeSettleMs(selfDriven);
458
- const infinite = selfDriven.filter((t) => t.iterations === null).map((t) => ({
1359
+ const scrollDriven = await page.evaluate(() => window.__vlmkitScrollDriven ?? []);
1360
+ const zeroDuration = timings.filter((t) => t.type === "css-animation" && t.durationMs === 0).map((t) => ({
459
1361
  selector: t.selector,
460
1362
  name: t.name
461
1363
  }));
1364
+ const shapes = await page.evaluate(MOTION_SHAPE_SCRIPT);
1365
+ const discreteTransitions = await page.evaluate(DISCRETE_TRANSITION_SCRIPT);
1366
+ const undefinedOnPage = await page.evaluate(UNDEFINED_KEYFRAMES_SCRIPT);
1367
+ const unknownTransitions = await page.evaluate(UNKNOWN_TRANSITION_PROPERTY_SCRIPT);
1368
+ const selfDriven = timings.filter((t) => t.playState !== "paused" && t.playState !== "idle");
1369
+ const settleMs = computeSettleMs(selfDriven);
1370
+ const infinite = selfDriven.filter((t) => t.iterations === null).map((t) => {
1371
+ const indicator = shapes.indicators.find((i) => i.index === t.index)?.why;
1372
+ return {
1373
+ selector: t.selector,
1374
+ name: t.name,
1375
+ ...indicator ? { indicator } : {}
1376
+ };
1377
+ });
462
1378
  const seek = async (index, timeMs) => {
463
1379
  return await page.evaluate(([i, t]) => {
464
1380
  const anim = window.__vlmkitAnims?.[i];
@@ -471,19 +1387,23 @@ async function runAnimationEval(options) {
471
1387
  return null;
472
1388
  }, [index, timeMs]);
473
1389
  };
474
- const framePaths = [];
475
- if (options.framesDir) await mkdir(options.framesDir, { recursive: true });
476
- const shot = async (label) => {
477
- const buffer = await page.screenshot({ animations: "allow" });
478
- if (options.framesDir) {
479
- const path = join(options.framesDir, `${label}.png`);
480
- await writeFile(path, buffer);
481
- framePaths.push(path);
482
- }
483
- return pngFromBuffer(buffer);
484
- };
1390
+ const shot = async (_label) => pngFromBuffer(await page.screenshot({ animations: "allow" }));
485
1391
  for (const t of timings) if (t.index >= 0) await seek(t.index, restTimeForAnimation(t));
486
1392
  const evaluable = timings.filter((t) => t.index >= 0 && t.durationMs > 0).slice(0, maxAnimations);
1393
+ const ancestorsOf = await page.evaluate(() => {
1394
+ const list = window.__vlmkitAnims ?? [];
1395
+ const target = (a) => a.effect?.target ?? null;
1396
+ const out = {};
1397
+ list.forEach((a, i) => {
1398
+ const el = target(a);
1399
+ if (!el) return;
1400
+ out[i] = list.map((b, j) => ({
1401
+ b,
1402
+ j
1403
+ })).filter(({ b, j }) => j !== i && target(b) !== el && target(b)?.contains(el)).map(({ j }) => j);
1404
+ });
1405
+ return out;
1406
+ }).catch(() => ({}));
487
1407
  const restProbe = await shot("rest");
488
1408
  const baseline = await shot("rest-recheck");
489
1409
  const restDelta = frameDelta(restProbe, baseline, tolerance);
@@ -491,6 +1411,7 @@ async function runAnimationEval(options) {
491
1411
  const evaluated = [];
492
1412
  const stripRows = [];
493
1413
  for (const timing of evaluable) {
1414
+ const siblings = timings.filter((t) => t.index >= 0 && t.index !== timing.index && (t.selector === timing.selector || (ancestorsOf[timing.index] ?? []).includes(t.index)));
494
1415
  const frames = [];
495
1416
  const rowFrames = [];
496
1417
  let previous = baseline;
@@ -499,11 +1420,18 @@ async function runAnimationEval(options) {
499
1420
  let maxFrameRatio = 0;
500
1421
  let readback = null;
501
1422
  let firstSample = null;
1423
+ {
1424
+ await seek(timing.index, timing.delayMs);
1425
+ for (const sib of siblings) await seek(sib.index, timing.delayMs);
1426
+ const d0 = frameDelta(baseline, await shot(`anim-${timing.index}-0`), tolerance);
1427
+ if (d0.changedPixels >= minChangedPixels) motionBbox = unionBbox(motionBbox, d0.bbox);
1428
+ }
502
1429
  for (let s = 1; s <= samples; s++) {
503
1430
  const fraction = s / samples;
504
1431
  const timeMs = timing.delayMs + Math.min(timing.durationMs * fraction, timing.durationMs - 1);
505
1432
  const seekedTo = Math.max(timing.delayMs, timeMs);
506
1433
  readback ??= await seek(timing.index, seekedTo);
1434
+ for (const sib of siblings) await seek(sib.index, seekedTo);
507
1435
  const frame = await shot(`anim-${timing.index}-${Math.round(fraction * 100)}`);
508
1436
  firstSample ??= {
509
1437
  timeMs: seekedTo,
@@ -526,6 +1454,7 @@ async function runAnimationEval(options) {
526
1454
  } : void 0;
527
1455
  if (!seekIneffective && firstSample && motionBbox && samples > 1) {
528
1456
  const replayReadback = await seek(timing.index, firstSample.timeMs);
1457
+ for (const sib of siblings) await seek(sib.index, firstSample.timeMs);
529
1458
  const again = await shot(`anim-${timing.index}-replay`);
530
1459
  const region = (f) => cropRegion(f, motionBbox.x, motionBbox.y, motionBbox.width, motionBbox.height);
531
1460
  const replay = frameDelta(region(firstSample.frame), region(again), tolerance);
@@ -535,6 +1464,7 @@ async function runAnimationEval(options) {
535
1464
  };
536
1465
  else if (replay.changedPixels >= minChangedPixels) {
537
1466
  await seek(timing.index, firstSample.timeMs);
1467
+ for (const sib of siblings) await seek(sib.index, firstSample.timeMs);
538
1468
  const third = await shot(`anim-${timing.index}-replay-2`);
539
1469
  const differs = (a, b) => frameDelta(region(a), region(b), tolerance).changedPixels >= minChangedPixels;
540
1470
  if (differs(firstSample.frame, third) && differs(again, third)) seekIneffective = {
@@ -544,12 +1474,42 @@ async function runAnimationEval(options) {
544
1474
  }
545
1475
  }
546
1476
  await seek(timing.index, restTimeForAnimation(timing));
1477
+ for (const sib of siblings) await seek(sib.index, restTimeForAnimation(sib));
1478
+ const elementBox = await page.evaluate((sel) => {
1479
+ const el = document.querySelector(sel);
1480
+ if (!el) return null;
1481
+ const r = el.getBoundingClientRect();
1482
+ const probe = document.createElement("style");
1483
+ probe.textContent = "[data-vlmkit-probe],[data-vlmkit-probe] *{pointer-events:auto!important}";
1484
+ (document.head ?? document.documentElement).append(probe);
1485
+ el.setAttribute("data-vlmkit-probe", "");
1486
+ let inView = 0;
1487
+ let hits = 0;
1488
+ for (let gy = 0; gy < 5; gy++) for (let gx = 0; gx < 5; gx++) {
1489
+ const x = r.x + (gx + .5) / 5 * r.width;
1490
+ const y = r.y + (gy + .5) / 5 * r.height;
1491
+ if (x < 0 || y < 0 || x >= innerWidth || y >= innerHeight) continue;
1492
+ inView++;
1493
+ const top = document.elementFromPoint(x, y);
1494
+ if (top && el.contains(top)) hits++;
1495
+ }
1496
+ el.removeAttribute("data-vlmkit-probe");
1497
+ probe.remove();
1498
+ return {
1499
+ x: Math.round(r.x),
1500
+ y: Math.round(r.y),
1501
+ width: Math.round(r.width),
1502
+ height: Math.round(r.height),
1503
+ topmost: inView === 0 ? 0 : hits / inView
1504
+ };
1505
+ }, timing.selector).catch(() => null);
547
1506
  if (options.stripPath && rowFrames.length > 0) stripRows.push(rowFrames);
548
1507
  evaluated.push({
549
1508
  ...timing,
550
1509
  frames,
551
1510
  visible: frames.some((f) => f.changedPixels >= minChangedPixels),
552
1511
  motionBbox,
1512
+ ...elementBox ? { elementBox } : {},
553
1513
  totalChangedPixels,
554
1514
  maxFrameRatio: Number(maxFrameRatio.toFixed(4)),
555
1515
  ...seekIneffective ? { seekIneffective } : {}
@@ -573,8 +1533,8 @@ async function runAnimationEval(options) {
573
1533
  const rows = evaluated.filter((a) => a.motionBbox && (matched === null || matched.has(a.index)));
574
1534
  if (matched !== null && rows.length === 0) throw new UsageError(`--strip-selector \`${wanted}\` matched no animated element. Animated elements on this page: ${evaluated.map((a) => a.selector).join(", ")}`);
575
1535
  const finiteEnds = rows.filter((a) => a.iterations !== null).map((a) => a.delayMs + a.durationMs * (a.iterations ?? 1));
576
- const windowMs = options.stripWindowMs ?? (finiteEnds.length > 0 ? Math.max(1, ...finiteEnds) : Math.max(1, ...rows.map((a) => a.delayMs + a.durationMs)));
577
- const times = Array.from({ length: samples }, (_, i) => Math.round(windowMs * (i + 1) / samples));
1536
+ const windowMs = (options.at && options.at.length > 0 ? Math.max(...options.at) : void 0) ?? options.stripWindowMs ?? (finiteEnds.length > 0 ? Math.max(1, ...finiteEnds) : Math.max(1, ...rows.map((a) => a.delayMs + a.durationMs)));
1537
+ const times = options.at && options.at.length > 0 ? [...options.at] : Array.from({ length: samples }, (_, i) => Math.round(windowMs * (i + 1) / samples));
578
1538
  const PAD = 8;
579
1539
  const columns = [];
580
1540
  for (const timeMs of times) {
@@ -590,11 +1550,10 @@ async function runAnimationEval(options) {
590
1550
  const cap = options.stripMaxWidth ?? 1600;
591
1551
  const factor = cap > 0 && columns[0].width > cap ? Math.ceil(columns[0].width / cap) : 1;
592
1552
  const played = factor === 1 ? columns : columns.map((frame) => scalePngData(frame, factor));
593
- const gaps = times.slice(1).map((t, i) => t - times[i]);
594
- const holdMs = gaps.length > 0 ? Math.round(gaps.reduce((a, b) => a + b, 0) / gaps.length) : 200;
1553
+ const delaysMs = playbackDelays(times);
595
1554
  const bytes = encodeApng(played, {
596
- delaysMs: [...gaps, holdMs],
597
- delayMs: holdMs
1555
+ delaysMs,
1556
+ delayMs: delaysMs.at(-1)
598
1557
  });
599
1558
  await mkdir(dirname(resolve(options.stripPath)), { recursive: true });
600
1559
  await writeFile(resolve(options.stripPath), bytes);
@@ -612,13 +1571,14 @@ async function runAnimationEval(options) {
612
1571
  animated: true
613
1572
  };
614
1573
  } else {
615
- const sheet = composeFilmstrip(rows.flatMap((anim) => {
1574
+ const cells = rows.flatMap((anim) => {
616
1575
  const bbox = anim.motionBbox;
617
- return columns.map((frame) => cropRegion(frame, Math.max(0, bbox.x - PAD), Math.max(0, bbox.y - PAD), bbox.width + PAD * 2, bbox.height + PAD * 2));
618
- }), {
619
- columns: samples,
1576
+ return columns.map((frame) => cropRegion(frame, Math.max(0, bbox.x - PAD), Math.max(0, bbox.y - PAD), bbox.width + 16, bbox.height + 16));
1577
+ });
1578
+ const sheet = composeFilmstrip(cells, {
1579
+ columns: times.length,
620
1580
  maxWidth: options.stripMaxWidth ?? 1600,
621
- columnLabels: times.map((t) => `${t}ms`),
1581
+ columnLabels: times.map((t) => `${formatInstant(t)}ms`),
622
1582
  rowLabels: rows.map((anim) => `${anim.selector} ${anim.name}`)
623
1583
  });
624
1584
  await mkdir(dirname(resolve(options.stripPath)), { recursive: true });
@@ -639,20 +1599,75 @@ async function runAnimationEval(options) {
639
1599
  }
640
1600
  }
641
1601
  await page.close();
1602
+ let frames;
1603
+ if (options.framesDir) {
1604
+ const framesPage = await browser.newPage({ viewport });
1605
+ try {
1606
+ const written = await captureTimelineFrames(framesPage, pageUrl, {
1607
+ ...options.waitUntil ? { waitUntil: options.waitUntil } : {},
1608
+ ...options.timeout !== void 0 ? { timeout: options.timeout } : {},
1609
+ ...options.har ? { har: options.har } : {},
1610
+ dir: resolve(options.framesDir),
1611
+ tool: "check animation",
1612
+ ...options.at ? { instants: options.at } : {},
1613
+ ...options.framesReducedMotion ? { reducedMotion: true } : {}
1614
+ });
1615
+ const { dir, manifest, count, unstable, instants } = written;
1616
+ frames = {
1617
+ dir,
1618
+ manifest,
1619
+ count,
1620
+ unstable,
1621
+ instants,
1622
+ ...options.framesReducedMotion ? { reducedMotion: true } : {}
1623
+ };
1624
+ framePaths.push(...written.files);
1625
+ } finally {
1626
+ await framesPage.close();
1627
+ }
1628
+ }
642
1629
  let reducedMotion;
1630
+ let undefinedUnderReduce = [];
1631
+ let reducedHidden = [];
643
1632
  if (!options.skipReducedMotion && (timings.length > 0 || clockMotion?.visible)) {
644
1633
  const durationFloor = options.reducedMotionDurationFloorMs ?? 100;
645
1634
  const rmPage = await browser.newPage({ viewport });
646
1635
  await rmPage.emulateMedia({ reducedMotion: "reduce" });
647
1636
  await loadPage(rmPage);
648
1637
  const rmTimings = await collectAnimations(rmPage);
1638
+ {
1639
+ const restPage = await browser.newPage({ viewport });
1640
+ try {
1641
+ await loadPage(restPage);
1642
+ const seenPlain = (await restPage.evaluate(restStateScript(null))).filter((r) => r.opacity >= .5);
1643
+ if (seenPlain.length > 0) {
1644
+ const reduced = await rmPage.evaluate(restStateScript(seenPlain.map((r) => r.selector)));
1645
+ reducedHidden = seenPlain.flatMap((a) => {
1646
+ const b = reduced.find((r) => r.selector === a.selector);
1647
+ if (!b) return [];
1648
+ const offPx = Math.hypot(b.x - a.x, b.y - a.y);
1649
+ return b.opacity < .05 || offPx >= 8 ? [{
1650
+ selector: a.selector,
1651
+ opacity: a.opacity,
1652
+ reducedOpacity: b.opacity,
1653
+ offPx
1654
+ }] : [];
1655
+ });
1656
+ }
1657
+ } catch {
1658
+ reducedHidden = [];
1659
+ } finally {
1660
+ await restPage.close();
1661
+ }
1662
+ }
1663
+ undefinedUnderReduce = await rmPage.evaluate(UNDEFINED_KEYFRAMES_SCRIPT);
649
1664
  let rmClock;
650
1665
  if (options.virtualTime) {
651
1666
  const rmShot = async () => pngFromBuffer(await rmPage.screenshot({ animations: "allow" }));
652
1667
  rmClock = await sampleClock(rmPage, await rmShot(), rmShot, clockWindowMs, clockSamples, tolerance, minChangedPixels, "rm-clock");
653
1668
  }
654
1669
  await rmPage.close();
655
- const remaining = rmTimings.filter((t) => t.playState !== "paused" && t.playState !== "idle" && t.durationMs >= durationFloor).map((t) => ({
1670
+ const remaining = rmTimings.filter((t) => t.playState !== "paused" && t.playState !== "idle" && t.durationMs >= durationFloor).filter((t) => !t.properties || t.properties.length === 0 || t.properties.some((p) => !NOT_MOTION.has(p))).map((t) => ({
656
1671
  selector: t.selector,
657
1672
  name: t.name,
658
1673
  durationMs: t.durationMs
@@ -660,17 +1675,38 @@ async function runAnimationEval(options) {
660
1675
  if (rmClock?.visible && rmClock.motionBbox) {
661
1676
  const b = rmClock.motionBbox;
662
1677
  const lasted = rmClock.settledAtMs ?? rmClock.windowMs;
663
- if (lasted >= durationFloor) remaining.push({
1678
+ if (lasted >= durationFloor && (rmClock.started ?? []).length > 0) for (const st of rmClock.started) remaining.push({
1679
+ selector: `${st.selector} (a ${st.kind} a timer started ${beganText(st)})`,
1680
+ name: st.name,
1681
+ durationMs: st.durationMs ?? lasted
1682
+ });
1683
+ else if (lasted >= durationFloor && !clockUpdatesOnly(rmClock)) remaining.push({
664
1684
  selector: `(script-driven motion at ${b.x},${b.y} ${b.width}x${b.height})`,
665
1685
  name: "requestAnimationFrame / timers",
666
1686
  durationMs: lasted
667
1687
  });
668
1688
  }
1689
+ const moves = (t) => !t.properties || t.properties.length === 0 || t.properties.some((p) => !NOT_MOTION.has(p));
1690
+ const nothingToReduce = remaining.length === 0 && !timings.some(moves) && !clockMotion?.visible;
1691
+ const fadesUnderReduce = rmTimings.filter((t) => t.playState !== "idle" && t.durationMs >= durationFloor && !moves(t)).length;
669
1692
  reducedMotion = {
670
1693
  remainingCount: remaining.length,
671
- remaining
1694
+ remaining,
1695
+ ...nothingToReduce ? {
1696
+ nothingToReduce: true,
1697
+ fadesUnderReduce
1698
+ } : {}
672
1699
  };
673
1700
  }
1701
+ const key = (u) => `${u.selector}\u0000${u.name}`;
1702
+ const onPage = new Set(undefinedOnPage.map(key));
1703
+ const undefinedKeyframes = [...undefinedOnPage.map((u) => ({
1704
+ ...u,
1705
+ reducedMotion: false
1706
+ })), ...undefinedUnderReduce.filter((u) => !onPage.has(key(u))).map((u) => ({
1707
+ ...u,
1708
+ reducedMotion: true
1709
+ }))];
674
1710
  const issues = deriveAnimationIssues({
675
1711
  evaluated,
676
1712
  settleMs,
@@ -678,7 +1714,13 @@ async function runAnimationEval(options) {
678
1714
  ...reducedMotion ? { reducedMotion } : {},
679
1715
  ...uncontrolledMotion ? { uncontrolledMotion } : {},
680
1716
  ...options.virtualTime ? { virtualTime: true } : {},
681
- ...clockMotion ? { clockMotion } : {}
1717
+ ...clockMotion ? { clockMotion } : {},
1718
+ ...undefinedKeyframes.length > 0 ? { undefinedKeyframes } : {},
1719
+ ...unknownTransitions.length > 0 ? { unknownTransitions } : {},
1720
+ ...discreteTransitions.length > 0 ? { discreteTransitions } : {},
1721
+ ...zeroDuration.length > 0 ? { zeroDuration } : {},
1722
+ ...reducedHidden.length > 0 ? { reducedHidden } : {},
1723
+ shapes
682
1724
  }, {
683
1725
  settleThresholdMs: options.settleThresholdMs,
684
1726
  reducedMotionDurationFloorMs: options.reducedMotionDurationFloorMs
@@ -687,6 +1729,7 @@ async function runAnimationEval(options) {
687
1729
  source: options.source,
688
1730
  viewport,
689
1731
  animationCount: timings.length,
1732
+ ...scrollDriven.length > 0 ? { scrollDriven } : {},
690
1733
  evaluated,
691
1734
  settleMs,
692
1735
  infinite,
@@ -694,8 +1737,10 @@ async function runAnimationEval(options) {
694
1737
  ...uncontrolledMotion ? { uncontrolledMotion } : {},
695
1738
  ...options.virtualTime ? { virtualTime: true } : {},
696
1739
  ...clockMotion ? { clockMotion } : {},
1740
+ ...undefinedKeyframes.length > 0 ? { undefinedKeyframes } : {},
697
1741
  issues,
698
1742
  ...framePaths.length > 0 ? { framePaths } : {},
1743
+ ...frames ? { frames } : {},
699
1744
  ...strip ? { strip } : {}
700
1745
  };
701
1746
  });
@@ -706,13 +1751,14 @@ function formatAnimationEvalReport(report, rules) {
706
1751
  lines.push(`${BOLD}${CYAN}vlmkit check animation${RESET}`);
707
1752
  lines.push(`${DIM}source: ${report.source} (${report.viewport.width}x${report.viewport.height})${report.virtualTime ? ", page clock held (--virtual-time)" : ""}${RESET}`);
708
1753
  lines.push("");
709
- lines.push(`status: ${status}`);
710
- lines.push(`animations: ${report.animationCount} (evaluated ${report.evaluated.length}, infinite ${report.infinite.length})`);
1754
+ const onlyReduced = status === "suspect" && shown.some((i) => i.row.kind === "reduced-motion-ignored") && shown.every((i) => i.row.kind === "reduced-motion-ignored" || i.tier !== "suspect");
1755
+ lines.push(`status: ${status}${onlyReduced ? ` — only reduced-motion-ignored (WCAG 2.3.3, AAA): no other rule fails. If the brief sets no reduced-motion policy, the motion passed; --rule reduced-motion-ignored=off exits 0` : ""}`);
1756
+ lines.push(`animations: ${report.animationCount} (evaluated ${report.evaluated.length}, infinite ${report.infinite.length})`, ...report.scrollDriven ? [`scroll-driven: ${report.scrollDriven.map((s) => `${s.selector} \`${s.name}\` on ${s.timeline}`).join(", ")} — its time is the scroll's, so it is not evaluated here: \`vlmkit inspect motion <page> --selector <el>\` sweeps the scroll`] : []);
711
1757
  const firedKinds = new Set(shown.map((entry) => entry.row.kind));
712
1758
  const ruleTag = (kind) => firedKinds.has(kind) ? ` ${DIM}[${kind}]${RESET}` : "";
713
1759
  if (report.settleMs === null) lines.push(`settle: never (infinite animation)` + (firedKinds.has("infinite-animation") ? ` ${DIM}[infinite-animation]${RESET}` : ` ${DIM}(no rule covers this — \`long-settle\` needs a settle time to compare)${RESET}`));
714
1760
  else lines.push(`settle: ${Math.round(report.settleMs)}ms${ruleTag("long-settle")}`);
715
- if (report.reducedMotion) lines.push(report.reducedMotion.remainingCount === 0 ? `reduced-motion: honored` : `reduced-motion: ${report.reducedMotion.remainingCount} animation(s) still running${ruleTag("reduced-motion-ignored")}`);
1761
+ if (report.reducedMotion) lines.push(report.reducedMotion.nothingToReduce && !report.issues.some((i) => i.kind === "held-paused-animation") ? `reduced-motion: nothing to reduce — no animation here moves anything (only opacity, colour or visibility)${report.reducedMotion.fadesUnderReduce ? `, and the ${report.reducedMotion.fadesUnderReduce} that run still run under reduce, which the preference allows` : ""}; not a sign the page has a prefers-reduced-motion rule` : report.reducedMotion.remainingCount === 0 && report.issues.some((i) => i.kind === "held-paused-animation") ? `reduced-motion: not judged — ${report.issues.filter((i) => i.kind === "held-paused-animation").length} animation(s) are held paused by the page and never run, with or without the preference${ruleTag("held-paused-animation")}` : report.reducedMotion.remainingCount === 0 ? `reduced-motion: honored${report.issues.some((i) => i.kind === "reduced-motion-hides") ? ` — but ${report.issues.filter((i) => i.kind === "reduced-motion-hides").length} element(s) rest hidden or out of place under it${ruleTag("reduced-motion-hides")}` : ""}` : `reduced-motion: ${report.reducedMotion.remainingCount} animation(s) still running${ruleTag("reduced-motion-ignored")}`);
716
1762
  if (report.uncontrolledMotion) {
717
1763
  const m = report.uncontrolledMotion;
718
1764
  const where = m.bbox ? ` at (${m.bbox.x},${m.bbox.y}) ${m.bbox.width}x${m.bbox.height}` : "";
@@ -721,7 +1767,8 @@ function formatAnimationEvalReport(report, rules) {
721
1767
  if (report.clockMotion) {
722
1768
  const c = report.clockMotion;
723
1769
  const where = c.motionBbox ? ` at (${c.motionBbox.x},${c.motionBbox.y}) ${c.motionBbox.width}x${c.motionBbox.height}` : "";
724
- lines.push(!c.visible ? `script-driven motion: none in ${c.windowMs}ms of virtual time` : c.settledAtMs === null ? `script-driven motion${where}: still moving at ${c.windowMs}ms of virtual time${ruleTag("clock-motion-unsettled")}` : `script-driven motion${where}: settles by ${c.settledAtMs}ms of virtual time${ruleTag("long-settle")}`);
1770
+ lines.push(!c.visible ? `script-driven motion: none in ${c.windowMs}ms of virtual time` : c.settledAtMs === null && clockUpdatesOnly(c) ? `script-driven change${where}: a timer updates it in place (${c.runs.timers} run(s), no animation frame) — not motion${ruleTag("clock-motion-unsettled")}` : c.settledAtMs === null ? `script-driven motion${where}: still moving at ${c.windowMs}ms of virtual time${ruleTag("clock-motion-unsettled")}` : `script-driven motion${where}: settles by ${c.settledAtMs}ms of virtual time${ruleTag("long-settle")}${(c.started ?? []).some((st) => (st.durationMs ?? 0) > 0) ? ` — the sweep's own frames only: what the timer started runs ${Math.max(...c.started.map((st) => st.durationMs ?? 0))}ms on its own clock, so measure it with \`vlmkit inspect motion <page> --selector <el>\`` : ""}`);
1771
+ if (c.visible && (c.started ?? []).length > 0) lines.push(`${DIM} not a requestAnimationFrame loop: ${clockMotionSource(c)}${RESET}`);
725
1772
  if (c.errors.length > 0) lines.push(`${DIM} page callbacks threw while the clock advanced: ${c.errors.join(" | ")}${RESET}`);
726
1773
  }
727
1774
  if (report.evaluated.length > 0) {
@@ -731,8 +1778,8 @@ function formatAnimationEvalReport(report, rules) {
731
1778
  const bbox = anim.motionBbox ? `(${anim.motionBbox.x},${anim.motionBbox.y}) ${anim.motionBbox.width}x${anim.motionBbox.height}` : "none";
732
1779
  const visibility = anim.seekIneffective ? `${RED}not measured (seek ineffective)${RESET}` : anim.visible ? `${GREEN}visible${RESET}` : `${RED}no visible effect${RESET}`;
733
1780
  const osc = computeOscillation(anim);
734
- const oscLabel = osc.oscillating ? ` (${anim.direction.startsWith("alternate") ? anim.direction : "palindromic keyframes"}, leg ${Math.round(osc.legMs)}ms)` : "";
735
- lines.push(` - ${anim.selector} \`${anim.name}\` ${Math.round(anim.durationMs)}ms x${anim.iterations ?? "∞"}${oscLabel}: ${visibility}, motion region ${bbox}, peak frame delta ${(anim.maxFrameRatio * 100).toFixed(2)}%`);
1781
+ const oscLabel = osc.oscillating ? anim.direction.startsWith("alternate") ? ` (${anim.direction}, leg ${Math.round(osc.legMs)}ms)` : ` (palindromic keyframes: each ${Math.round(anim.durationMs)}ms run goes out and back, ${Math.round(osc.legMs)}ms each way)` : "";
1782
+ lines.push(` - ${anim.selector} \`${anim.name}\` ${Math.round(anim.durationMs)}ms${anim.delayMs ? ` after ${Math.round(anim.delayMs)}ms` : ""}${anim.easing ? ` ${anim.easing}` : ""} x${anim.iterations ?? "∞"}${oscLabel}: ${visibility}, motion region ${bbox}, peak frame delta ${(anim.maxFrameRatio * 100).toFixed(2)}%`);
736
1783
  }
737
1784
  }
738
1785
  if (shown.length > 0) {
@@ -747,20 +1794,25 @@ function formatAnimationEvalReport(report, rules) {
747
1794
  } else if (note === void 0) {
748
1795
  lines.push("");
749
1796
  lines.push(`${GREEN}No animation issues detected.${RESET}`);
1797
+ lines.push(`${DIM}Only motion that runs from load is evaluated: a transition or animation started by a click, a :hover or a scroll is not — \`vlmkit inspect motion <page> --selector <el> --click/--hover/--leave/--scroll <css>\` samples it.${RESET}`);
750
1798
  }
751
1799
  if (note) {
752
1800
  lines.push("");
753
1801
  lines.push(`${DIM}${note}${RESET}`);
754
1802
  }
755
- if (report.framePaths && report.framePaths.length > 0) {
1803
+ if (report.frames) {
1804
+ const f = report.frames;
756
1805
  lines.push("");
757
- lines.push(`Frames: ${report.framePaths.length} written`);
1806
+ const at = f.instants.length <= 12 ? f.instants.map(formatInstant).join("/") : `${formatInstant(f.instants[0])}–${formatInstant(f.instants.at(-1))}`;
1807
+ lines.push(`Frames: ${f.count} written to ${f.dir} at ${at}ms of page time (clock and animations held${f.reducedMotion ? ", prefers-reduced-motion: reduce" : ""}), ${report.viewport.width}x${report.viewport.height} (--viewport WxH to match a target), manifest ${f.manifest}`);
1808
+ lines.push(`${DIM} What they show happening: vlmkit snapshot storyboard ${f.manifest}${RESET}`);
1809
+ if (f.unstable > 0) lines.push(`${YELLOW} ${f.unstable} frame(s) never captured the same twice: something moves that the clock does not hold (video, animated image, worker)${RESET}`);
758
1810
  }
759
1811
  if (report.strip) {
760
1812
  const s = report.strip;
761
1813
  lines.push("");
762
1814
  lines.push(`Strip: ${s.path} (${s.width}x${s.height}, ${s.rows} animation(s) x ${s.columns} sample(s)${s.omitted > 0 ? `; ${s.omitted} omitted as no-visible-effect` : ""}${s.outOfScope > 0 ? `; ${s.outOfScope} outside --strip-selector` : ""})`);
763
- lines.push(`${DIM} caption: columns are ${s.times.map((ms) => `${ms}ms`).join(" / ")} on the page timeline (window ${s.windowMs}ms, one shared clock); rows top to bottom are ${s.rowSelectors.join(", ")}${RESET}`);
1815
+ lines.push(`${DIM} caption: columns are ${s.times.map((ms) => `${formatInstant(ms)}ms`).join(" / ")} on the page timeline (window ${formatInstant(s.windowMs)}ms, one shared clock); rows top to bottom are ${s.rowSelectors.join(", ")}${RESET}`);
764
1816
  }
765
1817
  return lines.join("\n");
766
1818
  }
@@ -770,5 +1822,4 @@ function formatAnimationEvalReport(report, rules) {
770
1822
  * (`@mizchi/vlmkit-core/plugin/runner.ts`), which owns argument parsing,
771
1823
  * `--json`, `--advisory`, the run ledger and the exit code.
772
1824
  */
773
- //#endregion
774
- export { clockSettledAt, computeOscillation, computeSettleMs, deriveAnimationIssues, formatAnimationEvalReport, frameDelta, restTimeForAnimation, runAnimationEval, unionBbox };
1825
+ export { DELAYED_ENTRANCE_MS, clockMotionSource, clockSettledAt, clockUpdatesOnly, computeOscillation, computeSettleMs, deriveAnimationIssues, formatAnimationEvalReport, frameDelta, restTimeForAnimation, runAnimationEval, unionBbox };