@sloppy-ai/verify 0.0.0-stage → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/accessibility.mjs +534 -0
- package/browser.mjs +30 -0
- package/class-clash-core.mjs +130 -0
- package/class-clash.mjs +52 -0
- package/film-checks.mjs +2120 -0
- package/film.mjs +664 -0
- package/jumps-core.mjs +191 -0
- package/jumps.mjs +68 -0
- package/layout-core.mjs +164 -0
- package/layout.mjs +65 -0
- package/motion-interactions.mjs +463 -0
- package/motion-watch.mjs +557 -0
- package/multi-width.mjs +259 -0
- package/package.json +45 -4
- package/tells.mjs +390 -0
- package/verification.mjs +401 -0
- package/README.md +0 -3
package/film.mjs
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
// Film a stage: shots at a fixed interval, laid out as one contact sheet.
|
|
2
|
+
// Prints any console warnings (loop seams, missing targets) and errors.
|
|
3
|
+
//
|
|
4
|
+
// node scripts/film.mjs <url> [--out shots/film.png] [--every 500] [--count 36]
|
|
5
|
+
// [--delay 0] [--at <mark>] [--select "#example .ss-fit"] [--width 1280]
|
|
6
|
+
// [--cols auto] [--zoom x,y,w,h] [--scale auto] [--pad 16]
|
|
7
|
+
// [--reduced] [--dark] [--still] [--slow 1]
|
|
8
|
+
// [--hover] [--hover-for 4000] [--leave-for 1600]
|
|
9
|
+
// [--gate] [--states] [--states-for 20000]
|
|
10
|
+
// [--report findings.json] [--strict] [--help]
|
|
11
|
+
//
|
|
12
|
+
// --out output PNG, relative to the current directory; the absolute
|
|
13
|
+
// path written is printed
|
|
14
|
+
// --every ms between frames
|
|
15
|
+
// --count frames in a contact sheet (ignored by --hover, which uses the
|
|
16
|
+
// --hover-for / --leave-for windows instead)
|
|
17
|
+
// --delay wait this many ms after the stage appears before the first shot
|
|
18
|
+
// --at <mark> wait until the stage's data-mark equals <mark> (set by
|
|
19
|
+
// act.mark('<mark>') in a script), then start shooting. Times out
|
|
20
|
+
// after 30s. Stacks with --delay (delay runs after the mark).
|
|
21
|
+
// --select CSS selector for stages or their containers. Defaults to all
|
|
22
|
+
// visible .ss-fit / .ss-stage elements on any host page.
|
|
23
|
+
// --report write a JSON report with per-stage findings and coverage.
|
|
24
|
+
// Layout fit checks cover selected stages. For ordinary host
|
|
25
|
+
// controls outside them, also run scripts/layout.mjs <url>.
|
|
26
|
+
// --strict exit 1 for findings. Incomplete scans always exit 2.
|
|
27
|
+
// --gate the rehearsal gate: ends `rehearsal passed` only when every
|
|
28
|
+
// never-intentional line (the table in references/rehearse.md,
|
|
29
|
+
// from framing and cut by the crop to spills its slot) is at 0, otherwise prints the
|
|
30
|
+
// count and exits 1. A missing favicon or a sampling gap does
|
|
31
|
+
// not fail the gate; those lines do. Nor does a kit warning, except
|
|
32
|
+
// selection drift (a text selection that isn't under the I-beam).
|
|
33
|
+
// --states one sheet of every state: the opening, each act.mark() as the
|
|
34
|
+
// stage reaches it and 0.7s after, and the end of the window
|
|
35
|
+
// (--states-for ms, default 20000). Nothing is predicted.
|
|
36
|
+
// --width viewport width in CSS px. Frames are always captured at 2x and
|
|
37
|
+
// shown 1:1 in the sheet, never scaled up, so a --width 390 sheet
|
|
38
|
+
// reads exactly as a phone would show it.
|
|
39
|
+
// --cols sheet columns. Default: as many as fit in ~1800 CSS px (wide
|
|
40
|
+
// stages: enough for a sheet about twice as wide as tall).
|
|
41
|
+
// --zoom x,y,w,h close-up of a region in STAGE coordinates: the stage's own
|
|
42
|
+
// design pixels (the width/height passed to <Stage>), origin at
|
|
43
|
+
// the stage's top-left corner. --pad does not count and is not
|
|
44
|
+
// added. The region is captured at a high device scale so it is
|
|
45
|
+
// genuinely enlarged (works with --still and sheets).
|
|
46
|
+
// --zoom target:<name>[,pad] close-up that follows [data-target=name]
|
|
47
|
+
// wherever it is drawn, through a Camera's zoom too, refound
|
|
48
|
+
// every frame; pad in stage px (default 16).
|
|
49
|
+
// --scale device scale for --zoom (default: enough to make the crop
|
|
50
|
+
// ~1200 px wide, between 3 and 8)
|
|
51
|
+
// --pad CSS px of page around the stage (not used with --zoom)
|
|
52
|
+
// --still one clean PNG of the stage at 2x (or the --zoom crop), no sheet
|
|
53
|
+
// --hover for play="hover" stages: a 'rest' frame with the pointer off
|
|
54
|
+
// the stage, then the real pointer moves onto it and frames are
|
|
55
|
+
// taken every --every ms for --hover-for ms ('hover 0.40s'),
|
|
56
|
+
// then it moves off and frames continue for --leave-for ms
|
|
57
|
+
// ('left 0.80s') while the stage settles.
|
|
58
|
+
// --reduced emulate prefers-reduced-motion: reduce (shows the poster)
|
|
59
|
+
// --dark emulate prefers-color-scheme: dark
|
|
60
|
+
// --slow N run the stage's clock and every CSS animation and transition
|
|
61
|
+
// N times slower, so a landing or a press gets every frame.
|
|
62
|
+
// Timestamps stay in scene time. Pair with a short --every
|
|
63
|
+
// (--slow 6 --every 40).
|
|
64
|
+
//
|
|
65
|
+
// Scale check: the stage's scale at --width is reported when it isn't 1:1.
|
|
66
|
+
// Below about 0.85 its type reads small next to other figures; give it a
|
|
67
|
+
// compact design for that width instead of letting it shrink. Under 600 wide
|
|
68
|
+
// (a phone) the bar is 0.85, and any visible text drawn under about 10px is
|
|
69
|
+
// flagged on the shot it shows in.
|
|
70
|
+
//
|
|
71
|
+
// Clip check: every shot is also checked for marks sliced by a container
|
|
72
|
+
// that hides overflow (an avatar half outside its window, a status halo cut
|
|
73
|
+
// by a column, text cut mid-word). Crops at the stage's own edge are
|
|
74
|
+
// deliberate and ignored, as is any container marked data-crop (an inner
|
|
75
|
+
// crop you chose on purpose). Anything reported as "clipped" needs fixing.
|
|
76
|
+
// It also flags uneven padding: content in a visible container sitting much
|
|
77
|
+
// closer to its top or bottom than its side (a button 14px off a preview's
|
|
78
|
+
// bottom with 24px at the left). Padding is even unless you mark the
|
|
79
|
+
// container data-crop.
|
|
80
|
+
//
|
|
81
|
+
// Framing check, every shot, judged in the crop the viewer sees (the stage
|
|
82
|
+
// cut again by any wrapper that hides overflow). "framing:" lines: the hero
|
|
83
|
+
// window or phone cut on the top or left; a corner bleed whose top and left
|
|
84
|
+
// gutters differ by more than 2px (waived when a satellite straddles the
|
|
85
|
+
// window's side at any shot); a whole window with uneven margins; an edge a
|
|
86
|
+
// few px to most of a gutter short of the stage edge, or past it by a
|
|
87
|
+
// sliver under 24px (any box, bottom included); a desktop window that is
|
|
88
|
+
// near-square or narrow; a satellite off the gutter; a wrapper shadow with
|
|
89
|
+
// tighter corners than the shape inside it (a halo round a phone); and a
|
|
90
|
+
// data-target or real words cut by the crop; and anything the story opens
|
|
91
|
+
// (popover, menu, toast, tooltip, notification) closer than a gutter to any
|
|
92
|
+
// edge, on any frame it shows; a bottom-only bleed off center (waived when
|
|
93
|
+
// a satellite, a phone included, straddles the wider side); a column bled
|
|
94
|
+
// off the right showing under 56px. Boxes in flight are judged once settled.
|
|
95
|
+
// Under a Camera: frames while it moves are skipped, and a settled zoom is
|
|
96
|
+
// judged on its focus (whole, clear of the feather), the rest free to crop.
|
|
97
|
+
// "touching:" is text within 5px of a neighboring box on its line, or over
|
|
98
|
+
// it (a label beside its field in a space-between row with no gap); a parent
|
|
99
|
+
// with its own CSS gap only flags overlaps. A satellite edge within 6px of
|
|
100
|
+
// a window's traffic lights prints as near-tangent.
|
|
101
|
+
//
|
|
102
|
+
// Jump scan, every frame of every film including hover/leave (not --still): "jump:" is
|
|
103
|
+
// an element that moves or resizes over 2px in one frame instead of gliding,
|
|
104
|
+
// "drift:" neighbors gliding out of step (see jumps-core.mjs).
|
|
105
|
+
//
|
|
106
|
+
// Handoff check, every frame of every film (the motion line): "handoff
|
|
107
|
+
// shift:" is an element that hides as an identical one shows in its place
|
|
108
|
+
// (same kind, words or drawing) but drawn 0.5px or more away; "settle snap:"
|
|
109
|
+
// is an element at rest after motion that shifts 0.5px or more with nothing
|
|
110
|
+
// animating; "fly size:" is a Fly that takes off or lands at a different size
|
|
111
|
+
// from the element it leaves or becomes.
|
|
112
|
+
// "cut by the crop:" is a button or chip half off the edge (remove it or
|
|
113
|
+
// bring it in). "half-pixel glyph:" is an odd icon in an even box that
|
|
114
|
+
// scales or transitions, so it hops as the motion ends. "squeezed:" is a
|
|
115
|
+
// fixed-size flex item its row shrinks; give it flex: none.
|
|
116
|
+
|
|
117
|
+
import { launch } from './browser.mjs'
|
|
118
|
+
import { record, analyse, contentChanges } from './jumps-core.mjs'
|
|
119
|
+
import { watchMotion } from './motion-watch.mjs'
|
|
120
|
+
import { auditLayout } from './layout-core.mjs'
|
|
121
|
+
import { instrumentationSource, coverage, reportResult, printCoverage, motionFindings } from './verification.mjs'
|
|
122
|
+
import { filmChecksSource } from './film-checks.mjs'
|
|
123
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
124
|
+
import { dirname, resolve } from 'node:path'
|
|
125
|
+
import { spawnSync } from 'node:child_process'
|
|
126
|
+
|
|
127
|
+
// The dev server reloads whenever a file changes, and other work may be saving
|
|
128
|
+
// files while this films. A reload mid-film (or Vite's error overlay showing
|
|
129
|
+
// up) restarts the whole film, a few times with a pause between, instead of
|
|
130
|
+
// failing. If it never gets a quiet run it says so: nothing was written.
|
|
131
|
+
if (!process.env.FILM_CHILD) {
|
|
132
|
+
const TRIES = 6
|
|
133
|
+
let last
|
|
134
|
+
let reloaded = false
|
|
135
|
+
for (let attempt = 1; attempt <= TRIES; attempt++) {
|
|
136
|
+
last = spawnSync(process.execPath, process.argv.slice(1), { env: { ...process.env, FILM_CHILD: '1' }, encoding: 'utf8' })
|
|
137
|
+
const output = `${last.stdout}${last.stderr}`
|
|
138
|
+
reloaded = last.status !== 0 && (last.status === 3 || /FILM_RELOADED|Execution context was destroyed|Target page, context or browser has been closed|frame was detached/.test(output))
|
|
139
|
+
if (!reloaded) break
|
|
140
|
+
if (attempt < TRIES) {
|
|
141
|
+
console.error(`film: the page reloaded mid-film, filming again (${attempt + 1} of ${TRIES})`)
|
|
142
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1500 * attempt)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (reloaded) {
|
|
146
|
+
console.error(`film: the page kept reloading (other work is saving files); nothing was written. Try again once it is quiet.`)
|
|
147
|
+
process.exit(3)
|
|
148
|
+
}
|
|
149
|
+
process.stdout.write((last.stdout || '').replace(/^FILM_RELOADED.*\n?/m, ''))
|
|
150
|
+
process.stderr.write(last.stderr || last.error?.message || '')
|
|
151
|
+
process.exit(last.status ?? 1)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const args = process.argv.slice(2)
|
|
155
|
+
const FLAGS = new Set(['reduced', 'dark', 'still', 'hover', 'strict', 'help', 'gate', 'states'])
|
|
156
|
+
const url = args.find((a, i) => !a.startsWith('--') && (i === 0 || !args[i - 1].startsWith('--') || FLAGS.has(args[i - 1].slice(2))))
|
|
157
|
+
const opt = (name, fallback) => {
|
|
158
|
+
const i = args.indexOf(`--${name}`)
|
|
159
|
+
return i === -1 ? fallback : args[i + 1]
|
|
160
|
+
}
|
|
161
|
+
const has = (name) => args.includes(`--${name}`)
|
|
162
|
+
const VALUE_OPTIONS = new Set(['out', 'every', 'count', 'delay', 'at', 'select', 'width', 'cols', 'zoom', 'scale', 'pad', 'slow', 'hover-for', 'leave-for', 'report', 'states-for'])
|
|
163
|
+
for (let i = 0; i < args.length; i++) {
|
|
164
|
+
if (!args[i].startsWith('--')) continue
|
|
165
|
+
const name = args[i].slice(2)
|
|
166
|
+
if (FLAGS.has(name)) continue
|
|
167
|
+
if (!VALUE_OPTIONS.has(name) || !args[i + 1] || args[i + 1].startsWith('--')) {
|
|
168
|
+
console.error(`film: unknown option or missing value: ${args[i]}`)
|
|
169
|
+
process.exit(2)
|
|
170
|
+
}
|
|
171
|
+
i++
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!url || has('help')) {
|
|
175
|
+
// Print the flag reference from this file's header comment
|
|
176
|
+
const head = (await import('node:fs')).readFileSync(new URL(import.meta.url), 'utf8').split('\n')
|
|
177
|
+
const doc = []
|
|
178
|
+
for (const line of head) {
|
|
179
|
+
if (!line.startsWith('//')) break
|
|
180
|
+
doc.push(line.replace(/^\/\/ ?/, ''))
|
|
181
|
+
}
|
|
182
|
+
console.log(doc.join('\n'))
|
|
183
|
+
process.exit(has('help') ? 0 : 2)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const out = resolve(process.cwd(), opt('out', 'shots/film.png'))
|
|
187
|
+
const every = Number(opt('every', 500))
|
|
188
|
+
const count = Number(opt('count', 36))
|
|
189
|
+
let select = opt('select', null)
|
|
190
|
+
// On the playground, `#example` is scoped to the example the URL names, so a
|
|
191
|
+
// reload that lands on another build's page is never mistaken for this one
|
|
192
|
+
{
|
|
193
|
+
const url = args.find((a) => /^https?:/.test(a)) || ''
|
|
194
|
+
const slug = (url.match(/[?&]example=([^&#]+)/) || [])[1]
|
|
195
|
+
if (select === '#example' && slug) select = `#example[data-example="${decodeURIComponent(slug)}"]`
|
|
196
|
+
}
|
|
197
|
+
const width = Number(opt('width', 1280))
|
|
198
|
+
const colsOpt = opt('cols', null)
|
|
199
|
+
const zoomOpt = opt('zoom', null)
|
|
200
|
+
// --zoom target:<name>[,pad]: follows a data-target wherever it is drawn
|
|
201
|
+
const zoomTarget = zoomOpt?.startsWith('target:') ? { name: zoomOpt.slice(7).split(',')[0], pad: Number(zoomOpt.split(',')[1] ?? 16) } : null
|
|
202
|
+
const zoom = zoomOpt && !zoomTarget ? zoomOpt.split(',').map(Number) : null
|
|
203
|
+
const delay = Number(opt('delay', 0))
|
|
204
|
+
const pad = Number(opt('pad', 16))
|
|
205
|
+
const at = opt('at', null)
|
|
206
|
+
const still = has('still')
|
|
207
|
+
const hover = has('hover')
|
|
208
|
+
const hoverFor = Number(opt('hover-for', 4000))
|
|
209
|
+
const leaveFor = Number(opt('leave-for', 1600))
|
|
210
|
+
const reportPath = opt('report', null)
|
|
211
|
+
const statesFor = Number(opt('states-for', 20000))
|
|
212
|
+
for (const [name, value, minimum] of [['every', every, 1], ['count', count, 1], ['width', width, 1], ['delay', delay, 0], ['pad', pad, 0], ['hover-for', hoverFor, 0], ['leave-for', leaveFor, 0], ['states-for', statesFor, 0], ['slow', Number(opt('slow', 1)), 1]]) {
|
|
213
|
+
if (!Number.isFinite(value) || value < minimum || (['count', 'width'].includes(name) && !Number.isInteger(value))) {
|
|
214
|
+
console.error(`film: invalid --${name}: ${value}`)
|
|
215
|
+
process.exit(2)
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (still && hover) { console.error('film: --still and --hover are separate capture modes'); process.exit(2) }
|
|
219
|
+
if (colsOpt && (!Number.isInteger(Number(colsOpt)) || Number(colsOpt) < 1)) { console.error('film: --cols must be a positive integer'); process.exit(2) }
|
|
220
|
+
if (zoomTarget && (!zoomTarget.name || !Number.isFinite(zoomTarget.pad) || zoomTarget.pad < 0)) { console.error('film: target zoom needs a name and a nonnegative padding'); process.exit(2) }
|
|
221
|
+
if (has('scale') && (!Number.isFinite(Number(opt('scale'))) || Number(opt('scale')) <= 0)) { console.error('film: --scale must be positive'); process.exit(2) }
|
|
222
|
+
|
|
223
|
+
if (zoom && (zoom.length !== 4 || zoom.some((n) => !Number.isFinite(n)) || zoom[2] <= 0 || zoom[3] <= 0)) {
|
|
224
|
+
console.error('--zoom wants x,y,w,h in stage coordinates, e.g. --zoom 40,60,200,120, or target:<data-target name>[,pad]')
|
|
225
|
+
process.exit(2)
|
|
226
|
+
}
|
|
227
|
+
// Device scale is fixed per page, so pick it before opening one.
|
|
228
|
+
const dsf = zoom ? Number(opt('scale', 0)) || Math.min(8, Math.max(3, Math.ceil(1200 / zoom[2]))) : zoomTarget ? Number(opt('scale', 0)) || 4 : 2
|
|
229
|
+
|
|
230
|
+
const browser = await launch()
|
|
231
|
+
const fail = async (msg) => {
|
|
232
|
+
console.error(msg)
|
|
233
|
+
await browser.close()
|
|
234
|
+
process.exit(2)
|
|
235
|
+
}
|
|
236
|
+
const page = await browser.newPage({
|
|
237
|
+
viewport: { width, height: 900 },
|
|
238
|
+
deviceScaleFactor: dsf,
|
|
239
|
+
reducedMotion: has('reduced') ? 'reduce' : 'no-preference',
|
|
240
|
+
colorScheme: has('dark') ? 'dark' : 'light',
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
// Motion watch, running in the page every frame while a sheet is filmed:
|
|
244
|
+
// - appears, then moves: an entrance (a moving element that starts mostly
|
|
245
|
+
// transparent) that is fully visible while most of its travel is still
|
|
246
|
+
// ahead. Arrivals should already be moving on their first visible frame.
|
|
247
|
+
// - near-empty frames: the stage's visible content dropping far below its
|
|
248
|
+
// usual amount (a loop resting on an empty frame, a hole between beats).
|
|
249
|
+
// - hard edge: content being cut by a straight container edge while the
|
|
250
|
+
// cut moves (a row sliced as a panel opens, a line scrolled under a
|
|
251
|
+
// header). Checked on every frame, since it only lasts a few. Keep the
|
|
252
|
+
// content faint while the edge passes (Collapse does), or keep it whole.
|
|
253
|
+
// - lands on a transform: text that comes to rest at the end of a transform
|
|
254
|
+
// transition (translate, scale). Chrome draws text unsnapped while a
|
|
255
|
+
// transform runs and redraws it on the pixel grid when it ends, so it hops
|
|
256
|
+
// a fraction of a pixel as it lands. Keep it on a layer for good
|
|
257
|
+
// (will-change: transform), or scale only its surface.
|
|
258
|
+
// - steps in its box: a box with text in it (a pill, a badge, a bubble, an
|
|
259
|
+
// avatar's initials) moving by layout: pushed by a height opening, or
|
|
260
|
+
// glided by top or margin. Its fill and border glide smoothly but its text
|
|
261
|
+
// snaps to whole pixels, so the text hops about inside the box, last of
|
|
262
|
+
// all just after it seems to have landed. A lasting layer (will-change:
|
|
263
|
+
// transform on the box or a parent) moves box and text as one picture.
|
|
264
|
+
// --slow N: the stage's clock and every CSS animation and transition run N
|
|
265
|
+
// times slower, so fast beats (a landing, a press) get every frame. Sheet
|
|
266
|
+
// timestamps stay in scene time. --dark films the stage in its dark theme.
|
|
267
|
+
const slow = Math.max(1, Number(opt('slow', 1)))
|
|
268
|
+
await page.addInitScript(([slow, dark, stillRun]) => {
|
|
269
|
+
window.__stageshow = { slow, ...(dark ? { theme: 'dark' } : {}) }
|
|
270
|
+
window.__ssStill = stillRun
|
|
271
|
+
}, [slow, has('dark'), still])
|
|
272
|
+
await page.addInitScript({ content: instrumentationSource(record, select) })
|
|
273
|
+
// The per-shot checks (film-checks.mjs), installed the same way
|
|
274
|
+
await page.addInitScript({ content: filmChecksSource() })
|
|
275
|
+
if (slow > 1) {
|
|
276
|
+
const cdp = await page.context().newCDPSession(page)
|
|
277
|
+
await cdp.send('Animation.enable')
|
|
278
|
+
await cdp.send('Animation.setPlaybackRate', { playbackRate: 1 / slow })
|
|
279
|
+
}
|
|
280
|
+
await page.addInitScript(watchMotion, select)
|
|
281
|
+
|
|
282
|
+
let notes = []
|
|
283
|
+
let serverErrors = []
|
|
284
|
+
const noise = /favicon/
|
|
285
|
+
page.on('console', (m) => {
|
|
286
|
+
if (!['warning', 'error'].includes(m.type()) || noise.test(m.text())) return
|
|
287
|
+
// A 500 while Vite is still compiling is usually transient; judged after the load.
|
|
288
|
+
if (/Failed to load resource.*(5\d\d|Internal Server Error)/.test(m.text())) serverErrors.push(m.text())
|
|
289
|
+
else notes.push(`${m.type()}: ${m.text()}`)
|
|
290
|
+
})
|
|
291
|
+
page.on('response', (r) => r.status() >= 500 && serverErrors.push(`${r.status()} ${r.url()}`))
|
|
292
|
+
page.on('pageerror', (e) => notes.push(`exception: ${e.message}`))
|
|
293
|
+
|
|
294
|
+
// Find the stage: the first match that is actually laid out and visible.
|
|
295
|
+
const findStage = () =>
|
|
296
|
+
page.waitForFunction(
|
|
297
|
+
(sel) => {
|
|
298
|
+
const stages = window.__ssVisibleStages(sel)
|
|
299
|
+
if (!stages.length) {
|
|
300
|
+
if (!document.querySelector('.ss-stage') && document.querySelector('iframe')) throw new Error('This page embeds its scene in an iframe. Film the scene URL directly (the playground uses ?capture=<example>), not the surrounding viewer.')
|
|
301
|
+
if (sel && [...document.querySelectorAll(sel)].some(el => !el.matches('.ss-stage') && !el.querySelector('.ss-stage') && el.closest('.ss-stage'))) throw new Error('--select matches content inside a Stage. Select the .ss-stage itself or its .ss-fit container.')
|
|
302
|
+
return false
|
|
303
|
+
}
|
|
304
|
+
document.querySelectorAll('[data-film-target]').forEach((el) => el.removeAttribute('data-film-target'))
|
|
305
|
+
for (const stage of stages) {
|
|
306
|
+
const target = sel ? [...document.querySelectorAll(sel)].find((el) => el === stage || el.contains(stage)) : stage.closest('.ss-fit') || stage
|
|
307
|
+
target.setAttribute('data-film-target', '')
|
|
308
|
+
}
|
|
309
|
+
return true
|
|
310
|
+
},
|
|
311
|
+
select,
|
|
312
|
+
{ timeout: 30000, polling: 100 },
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
// The first load after a new example appears can stall or 500 while Vite
|
|
316
|
+
// compiles it. Retry a timeout once, and reload through transient 500s; only
|
|
317
|
+
// report them if they survive the retries.
|
|
318
|
+
const MAX_LOADS = 3
|
|
319
|
+
let loaded = false
|
|
320
|
+
let timeouts = 0
|
|
321
|
+
for (let attempt = 1; attempt <= MAX_LOADS && !loaded; attempt++) {
|
|
322
|
+
notes = []
|
|
323
|
+
serverErrors = []
|
|
324
|
+
try {
|
|
325
|
+
await page.goto(url, { waitUntil: 'networkidle', timeout: 45000 })
|
|
326
|
+
await findStage()
|
|
327
|
+
if (serverErrors.length && attempt < MAX_LOADS) {
|
|
328
|
+
await page.waitForTimeout(800)
|
|
329
|
+
continue
|
|
330
|
+
}
|
|
331
|
+
loaded = true
|
|
332
|
+
} catch (e) {
|
|
333
|
+
const timedOut = e.name === 'TimeoutError' || /Timeout/.test(e.message)
|
|
334
|
+
if (timedOut && ++timeouts < 2) continue
|
|
335
|
+
if (!timedOut && serverErrors.length && attempt < MAX_LOADS) {
|
|
336
|
+
await page.waitForTimeout(800)
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
339
|
+
const why = timedOut ? `no visible stages in "${select ?? '.ss-fit, .ss-stage'}" after retrying` : e.message
|
|
340
|
+
await fail([`film: ${why}`, ...serverErrors.map((s) => `server: ${s}`), ...notes].join('\n'))
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (!loaded) await fail(`film: page never loaded cleanly\n${[...serverErrors, ...notes].join('\n')}`)
|
|
344
|
+
// Never shoot a stage before it has measured and fitted (a first frame of a
|
|
345
|
+
// half-placed, tiled stage)
|
|
346
|
+
await page.waitForFunction(() => !document.querySelector('[data-film-target] .ss-stage[data-placing], [data-film-target].ss-stage[data-placing]'), null, { timeout: 10000 }).catch(() => notes.push('incomplete: stage placement did not settle within 10s'))
|
|
347
|
+
// The page must show the example asked for, not whatever the tab had before
|
|
348
|
+
{
|
|
349
|
+
const want = new URL(url).searchParams.get('example')
|
|
350
|
+
const got = await page.evaluate(() => document.querySelector('#example')?.getAttribute('data-example'))
|
|
351
|
+
if (want && got && got !== want) await fail(`film: asked for ${want} but the page shows ${got}`)
|
|
352
|
+
}
|
|
353
|
+
notes.push(...[...new Set(serverErrors)].map((s) => `server error: ${s}`))
|
|
354
|
+
// How big the design shows at this width
|
|
355
|
+
const scaleNotes = await page.evaluate((phone) => window.__ssVisibleStages(window.__ssVerification.selector).flatMap((st) => {
|
|
356
|
+
if (!st.offsetWidth) return []
|
|
357
|
+
const k = st.getBoundingClientRect().width / st.offsetWidth
|
|
358
|
+
const lay = st.getAttribute('data-layout')
|
|
359
|
+
let message
|
|
360
|
+
if (phone && k < 0.85) message = `shrunk, not laid out for the phone: drawn at ${k.toFixed(2)} (${lay} design, ${st.offsetWidth}px wide); design compact at the column's width and draw it 1:1`
|
|
361
|
+
else if (k < 0.85) message = `scale: ${k.toFixed(2)} (${lay} design, ${st.offsetWidth}px wide); type reads small below about 0.85`
|
|
362
|
+
else if (k > 1.01) message = `scale: ${k.toFixed(2)}, grown past the design size`
|
|
363
|
+
return message ? [{ key: st.getAttribute('data-ss-verification-stage'), message }] : []
|
|
364
|
+
}), width < 600)
|
|
365
|
+
|
|
366
|
+
// From here on a navigation means the dev server reloaded under the film
|
|
367
|
+
page.on('framenavigated', (f) => {
|
|
368
|
+
if (f === page.mainFrame()) {
|
|
369
|
+
console.log('FILM_RELOADED')
|
|
370
|
+
process.exit(3)
|
|
371
|
+
}
|
|
372
|
+
})
|
|
373
|
+
const overlaid = async () => {
|
|
374
|
+
if (await page.$('vite-error-overlay')) {
|
|
375
|
+
console.log('FILM_RELOADED (vite error overlay)')
|
|
376
|
+
process.exit(3)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const el = await page.$('[data-film-target]')
|
|
381
|
+
const stageCount = await page.evaluate((selector) => window.__ssVisibleStages(selector).length, select)
|
|
382
|
+
if (stageCount > 1 && (zoom || zoomTarget || at)) await fail('film: --zoom and --at require one visible stage; narrow --select')
|
|
383
|
+
// Let fonts settle and the stage measure itself before the first shot.
|
|
384
|
+
await page.evaluate(() => document.fonts.ready)
|
|
385
|
+
await page.waitForTimeout(150)
|
|
386
|
+
|
|
387
|
+
// Make the viewport tall enough to hold the stage, then put it in view, so the
|
|
388
|
+
// clip is in viewport coordinates and the pointer can reach it.
|
|
389
|
+
const docBottom = await page.evaluate(() => Math.max(...[...document.querySelectorAll('[data-film-target]')].map((el) => el.getBoundingClientRect().bottom + window.scrollY)))
|
|
390
|
+
if (docBottom + pad + 32 > 900) await page.setViewportSize({ width, height: Math.ceil(docBottom + pad + 32) })
|
|
391
|
+
await page.evaluate(() => window.scrollTo(0, 0))
|
|
392
|
+
await page.waitForTimeout(50)
|
|
393
|
+
|
|
394
|
+
const stageRoot = async () =>
|
|
395
|
+
(await el.evaluateHandle((n) => (n.classList.contains('ss-stage') ? n : n.querySelector('.ss-stage') ?? n))).asElement()
|
|
396
|
+
const stageRoots = async () => {
|
|
397
|
+
const handles = await page.locator('[data-ss-verification-stage]').elementHandles()
|
|
398
|
+
const roots = []
|
|
399
|
+
for (const handle of handles) if (await handle.evaluate((node) => window.__ssVisibleStages(window.__ssVerification.selector).includes(node))) roots.push(handle)
|
|
400
|
+
return roots
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const waitForMark = async () => {
|
|
404
|
+
if (!at) return
|
|
405
|
+
const root = await stageRoot()
|
|
406
|
+
try {
|
|
407
|
+
await page.waitForFunction(([r, name]) => r.getAttribute('data-mark') === name, [root, at], { timeout: 30000 * slow, polling: 16 })
|
|
408
|
+
} catch {
|
|
409
|
+
const seen = await root.getAttribute('data-mark')
|
|
410
|
+
await fail(`film: stage never reached data-mark="${at}" in 30s (last seen: ${seen ?? 'none'}). Does the script call act.mark('${at}')?`)
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const clipFor = async () => {
|
|
415
|
+
// The example may still be compiling or animating in; wait for a real box
|
|
416
|
+
let bounds = await el.boundingBox()
|
|
417
|
+
for (let i = 0; !bounds && i < 50; i++) {
|
|
418
|
+
await page.waitForTimeout(200)
|
|
419
|
+
bounds = await el.boundingBox()
|
|
420
|
+
}
|
|
421
|
+
if (!bounds) await fail('film: the stage has no box after 10s. Is it rendered and visible?')
|
|
422
|
+
if (!zoom && !zoomTarget) {
|
|
423
|
+
const boxes = await page.locator('[data-film-target]').evaluateAll((nodes) => nodes.map((node) => { const r = node.getBoundingClientRect(); return { x: r.x, y: r.y, right: r.right, bottom: r.bottom } }))
|
|
424
|
+
const x = Math.max(0, Math.min(...boxes.map((r) => r.x)) - pad)
|
|
425
|
+
const y = Math.max(0, Math.min(...boxes.map((r) => r.y)) - pad)
|
|
426
|
+
return { x, y, width: Math.max(...boxes.map((r) => r.right)) + pad - x, height: Math.max(...boxes.map((r) => r.bottom)) + pad - y }
|
|
427
|
+
}
|
|
428
|
+
if (zoomTarget) {
|
|
429
|
+
// Where the target is drawn now (inside a Camera, as zoomed), padded in
|
|
430
|
+
// stage pixels at the same scale
|
|
431
|
+
const root = await stageRoot()
|
|
432
|
+
const t = await root.$(`[data-target="${zoomTarget.name}"]`)
|
|
433
|
+
const tb = t && (await t.boundingBox())
|
|
434
|
+
if (!tb) await fail(`film: --zoom target:${zoomTarget.name} found no visible [data-target="${zoomTarget.name}"] in the stage`)
|
|
435
|
+
const k = await t.evaluate((n) => { const r = n.getBoundingClientRect(); return n.offsetWidth ? r.width / n.offsetWidth : 1 })
|
|
436
|
+
const p = zoomTarget.pad * k
|
|
437
|
+
return { x: tb.x - p, y: tb.y - p, width: tb.width + p * 2, height: tb.height + p * 2 }
|
|
438
|
+
}
|
|
439
|
+
if (!zoom) return { x: bounds.x - pad, y: bounds.y - pad, width: bounds.width + pad * 2, height: bounds.height + pad * 2 }
|
|
440
|
+
// Stage coordinates: undo the fit scale the stage renders at.
|
|
441
|
+
const root = await stageRoot()
|
|
442
|
+
const box = (await root.boundingBox()) ?? bounds
|
|
443
|
+
const designW = await root.evaluate((n) => n.offsetWidth || n.getBoundingClientRect().width)
|
|
444
|
+
const s = box.width / designW
|
|
445
|
+
return { x: box.x + zoom[0] * s, y: box.y + zoom[1] * s, width: zoom[2] * s, height: zoom[3] * s }
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// What the per-shot checks (film-checks.mjs) found, keyed by stage and
|
|
449
|
+
// message, with the shots each was seen at
|
|
450
|
+
const clipped = new Map()
|
|
451
|
+
const cameraSkipped = []
|
|
452
|
+
const clipSamples = new Map()
|
|
453
|
+
const layoutDeferred = new Map()
|
|
454
|
+
const layoutSamples = new Map()
|
|
455
|
+
// A satellite seen beside the hero window at any shot (see Framing)
|
|
456
|
+
const sideSatellites = new Set()
|
|
457
|
+
const checkClipsForStage = async (label, root) => {
|
|
458
|
+
const stageKey = await root.getAttribute('data-ss-verification-stage')
|
|
459
|
+
// Every per-shot check, in page context (film-checks.mjs): clips, padding,
|
|
460
|
+
// near-tangents, icons, lists, framing, touching and the crop
|
|
461
|
+
const found = await root.evaluate((root) => window.__ssFilmChecks.checkStage(root))
|
|
462
|
+
// Phone widths: the smallest visible text as drawn, through every scale
|
|
463
|
+
if (width < 600) {
|
|
464
|
+
const small = await root.evaluate((root) => window.__ssFilmChecks.smallestText(root))
|
|
465
|
+
if (small) found.push(`small text: ${small.el} renders at ${small.px.toFixed(1)}px on a phone; the floor is about 10px, so lay compact out at the column's width and set its type for it, not shrunk from the wide design`)
|
|
466
|
+
}
|
|
467
|
+
// Controls that spill the slot they were laid out in
|
|
468
|
+
found.push(...await root.evaluate((root) => window.__ssFilmChecks.detectSpills(root)))
|
|
469
|
+
const layout = await root.evaluate(auditLayout)
|
|
470
|
+
layoutSamples.set(stageKey, layout.checked)
|
|
471
|
+
found.push(...layout.findings.map((finding) => finding.message))
|
|
472
|
+
if (layout.deferred.length) layoutDeferred.set(stageKey, layout.deferred)
|
|
473
|
+
else layoutDeferred.delete(stageKey)
|
|
474
|
+
if (found.includes('SAT_SIDE')) sideSatellites.add(stageKey)
|
|
475
|
+
if (found.includes('CAMERA_MOVING')) cameraSkipped.push({ stageKey, label })
|
|
476
|
+
else clipSamples.set(stageKey, (clipSamples.get(stageKey) || 0) + 1)
|
|
477
|
+
for (const message of found) if (message !== 'SAT_SIDE' && message !== 'CAMERA_MOVING') {
|
|
478
|
+
const key = `${stageKey}: ${message}`
|
|
479
|
+
const entry = clipped.get(key) || { stageKey, message, at: [] }
|
|
480
|
+
entry.at.push(label)
|
|
481
|
+
clipped.set(key, entry)
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const checkClips = async (label) => {
|
|
485
|
+
for (const root of await stageRoots()) await checkClipsForStage(label, root)
|
|
486
|
+
}
|
|
487
|
+
const clipFindings = (stageKey, minFrames) => [...clipped.values()]
|
|
488
|
+
.filter((entry) => entry.stageKey === stageKey)
|
|
489
|
+
.filter(({ message: f }) => !(sideSatellites.has(stageKey) && (f.startsWith('framing: corner bleed') || f.includes('runs off the bottom but sits off center'))))
|
|
490
|
+
.filter(({ message: f, at }) => at.length >= minFrames || /^(translucent|covers|framing|small text)/.test(f))
|
|
491
|
+
.map(({ message: f, at }) => `${/^(layout|uneven|translucent|lopsided|near-tangent|covers|unclipped|double corner|tight lines|tight stack|loose stack|tight mark|tight inset|skeleton ladder|onion skin|kit override|unit wrapped|unsized text|clipped glyph|loose list|empty pane|fat row|emoji icon|anchor drift|uneven padding|mixed icons|tight control|invented mark|uneven inset|uneven gutters|avatar alignment|spills its slot|half-pixel|squeezed|cut by the crop|framing|touching|dark slab|small text)/.test(f) ? '' : 'clipped: '}${f} (${at.length > 3 ? `${at.length} frames from ${at[0]}` : at.join(', ')})`)
|
|
492
|
+
|
|
493
|
+
const finishReport = (snapshot, requestedMs = 0) => {
|
|
494
|
+
const errors = [...notes, ...(snapshot?.errors || [])]
|
|
495
|
+
if (!snapshot) errors.push('recording was unavailable')
|
|
496
|
+
const stages = Object.entries(snapshot?.stages || {}).map(([key, stage]) => {
|
|
497
|
+
const sample = still ? { status: 'complete', frames: 1, durationMs: 0, maxGapMs: 0, reasons: [] } : coverage(stage.frames, { requestedMs, slow })
|
|
498
|
+
if (!still && !stage.motion) { sample.status = 'inconclusive'; sample.reasons.push('motion watcher produced no samples') }
|
|
499
|
+
sample.framingSamples = clipSamples.get(key) || 0
|
|
500
|
+
sample.layout = layoutSamples.get(key) || { controls: 0, paddedContainers: 0 }
|
|
501
|
+
if (!sample.framingSamples) { sample.status = 'inconclusive'; sample.reasons.push('no framing sample was judged for this stage') }
|
|
502
|
+
const manual = still ? [] : contentChanges(stage.frames, slow)
|
|
503
|
+
if (layoutDeferred.has(key)) {
|
|
504
|
+
sample.status = 'inconclusive'
|
|
505
|
+
sample.reasons.push('some layout geometry was still moving at the final shot')
|
|
506
|
+
manual.push(`Layout checks remain deferred: ${layoutDeferred.get(key).join('; ')}. Capture a settled state.`)
|
|
507
|
+
}
|
|
508
|
+
if (stage.frames.some((frame) => frame.cameraMoving)) manual.push('Camera contents were omitted from geometry checks while moving; inspect the full push-in and return.')
|
|
509
|
+
const cameraShots = cameraSkipped.filter((frame) => frame.stageKey === key).length
|
|
510
|
+
if (cameraShots) manual.push(`Framing checks omitted ${cameraShots} shot(s) while the camera moved.`)
|
|
511
|
+
return { key, label: stage.label, coverage: sample, findings: [...scaleNotes.filter((note) => note.key === key).map((note) => note.message), ...clipFindings(key, still ? 1 : 2), ...(!still ? [...analyse(stage.frames, slow), ...motionFindings(stage.motion, slow)] : [])], manual }
|
|
512
|
+
})
|
|
513
|
+
const result = reportResult({ stages, errors, strict: has('strict'), still })
|
|
514
|
+
for (const stage of stages) {
|
|
515
|
+
printCoverage(stage.key, stage.coverage)
|
|
516
|
+
for (const line of stage.findings) console.log(`[${stage.key}] ${line}`)
|
|
517
|
+
for (const line of stage.manual) console.log(`[${stage.key}] manual: ${line}`)
|
|
518
|
+
}
|
|
519
|
+
for (const error of errors) console.error(`incomplete: ${error}`)
|
|
520
|
+
console.log(`film: ${result.status}; ${still ? 'still capture only, motion was not judged' : 'watch the motion and inspect every image before approval'}`)
|
|
521
|
+
if (has('gate')) {
|
|
522
|
+
const NEVER = /^(clipped: )?(framing|cut by the crop|tight stack|loose stack|tight mark|tight inset|skeleton ladder|onion skin|kit override|unit wrapped|unsized text|clipped glyph|loose list|empty pane|fat row|emoji icon|anchor drift|uneven padding|mixed icons|tight control|invented mark|uneven inset|uneven gutters|avatar alignment|spills its slot):/
|
|
523
|
+
const bad = [...stages.flatMap((stage) => stage.findings.filter((line) => NEVER.test(line))), ...notes.filter((line) => /\[stageshow\] selection drift:/.test(line))]
|
|
524
|
+
if (bad.length) { console.log(`rehearsal failed: ${bad.length} never-intentional line(s) above`); process.exitCode = 1 }
|
|
525
|
+
else console.log('rehearsal passed (necessary, not sufficient: references/verify.md and the fresh eye in review.md still stand)')
|
|
526
|
+
}
|
|
527
|
+
if (reportPath) {
|
|
528
|
+
const path = resolve(reportPath)
|
|
529
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
530
|
+
writeFileSync(path, JSON.stringify(result, null, 2) + '\n')
|
|
531
|
+
}
|
|
532
|
+
// Keep the higher code: a failed gate (1) or an incomplete film (2) is never reported as a pass
|
|
533
|
+
process.exitCode = Math.max(process.exitCode ?? 0, result.exitCode)
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const shots = []
|
|
537
|
+
const shoot = async (label) => {
|
|
538
|
+
await overlaid()
|
|
539
|
+
// A target followed through a Camera: re-found every frame (the sheet
|
|
540
|
+
// shows each at one width; a uniform zoom keeps its shape)
|
|
541
|
+
if (zoomTarget) clip = await clipFor()
|
|
542
|
+
await checkClips(label)
|
|
543
|
+
const buf = await page.screenshot({ clip })
|
|
544
|
+
shots.push({ label, src: `data:image/png;base64,${buf.toString('base64')}`, w: clip.width, h: clip.height })
|
|
545
|
+
}
|
|
546
|
+
const secs = (ms) => `${(ms / 1000).toFixed(2)}s`
|
|
547
|
+
|
|
548
|
+
// A series of frames on a fixed clock, labeled from the series start.
|
|
549
|
+
const series = async (ms, prefix) => {
|
|
550
|
+
const n = Math.max(1, Math.floor(ms / every) + 1)
|
|
551
|
+
const start = Date.now()
|
|
552
|
+
for (let i = 0; i < n; i++) {
|
|
553
|
+
await page.waitForTimeout(Math.max(0, start + i * every * slow - Date.now()))
|
|
554
|
+
await shoot(`${prefix}${secs((Date.now() - start) / slow)}`)
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
let clip
|
|
559
|
+
// Measure the requested interval on the same browser clock as the samples.
|
|
560
|
+
// Serializing a large trace back to Node happens after recording has stopped
|
|
561
|
+
// and must not turn complete browser coverage into an artificial shortfall.
|
|
562
|
+
const captureStarted = await page.evaluate(() => performance.now())
|
|
563
|
+
if (hover) {
|
|
564
|
+
// Park the pointer outside the stage first.
|
|
565
|
+
await page.mouse.move(1, 1)
|
|
566
|
+
await page.waitForTimeout(150 + delay)
|
|
567
|
+
clip = await clipFor()
|
|
568
|
+
await shoot('rest')
|
|
569
|
+
for (const root of await stageRoots()) {
|
|
570
|
+
const key = await root.getAttribute('data-ss-verification-stage')
|
|
571
|
+
const box = await root.boundingBox()
|
|
572
|
+
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2, { steps: 8 })
|
|
573
|
+
await waitForMark()
|
|
574
|
+
await series(hoverFor, `${key} hover `)
|
|
575
|
+
await page.mouse.move(1, 1, { steps: 8 })
|
|
576
|
+
await series(leaveFor, `${key} left `)
|
|
577
|
+
}
|
|
578
|
+
} else {
|
|
579
|
+
await waitForMark()
|
|
580
|
+
await page.waitForTimeout(delay)
|
|
581
|
+
clip = await clipFor()
|
|
582
|
+
if (still) {
|
|
583
|
+
await overlaid()
|
|
584
|
+
// A number part way through its roll isn't the poster: wait for it to land
|
|
585
|
+
await page.waitForFunction(() => !document.querySelector('[data-film-target] .ss-count[data-rolling], [data-film-target].ss-stage .ss-count[data-rolling]'), null, { timeout: 4000 * slow, polling: 16 }).catch(() => notes.push('incomplete: number roll did not settle before the still'))
|
|
586
|
+
mkdirSync(dirname(out), { recursive: true })
|
|
587
|
+
await page.screenshot({ path: out, clip })
|
|
588
|
+
await checkClips('still')
|
|
589
|
+
const snapshot = await page.evaluate(() => { window.__ssVerification.stopped = true; return window.__ssVerification }).catch(() => null)
|
|
590
|
+
await browser.close()
|
|
591
|
+
console.log(`still${zoom || zoomTarget ? ` (zoom ${dsf}x)` : ''} -> ${out}`)
|
|
592
|
+
finishReport(snapshot)
|
|
593
|
+
process.exit(process.exitCode)
|
|
594
|
+
}
|
|
595
|
+
await page.evaluate(() => (window.__filmStart = performance.now()))
|
|
596
|
+
if (has('states')) {
|
|
597
|
+
// Every state the script passes through: the opening, each mark as the
|
|
598
|
+
// stage reaches it and again 0.7s on when it has settled, then the end
|
|
599
|
+
const roots = await stageRoots()
|
|
600
|
+
// data-mark lives on the stage itself, which may sit inside the selected fit box
|
|
601
|
+
const root = (await roots[0].$('.ss-stage')) ?? roots[0]
|
|
602
|
+
const start = Date.now()
|
|
603
|
+
let last = await root.getAttribute('data-mark')
|
|
604
|
+
await shoot('open')
|
|
605
|
+
const pending = []
|
|
606
|
+
while (Date.now() - start < statesFor * slow) {
|
|
607
|
+
await page.waitForTimeout(40)
|
|
608
|
+
const mark = await root.getAttribute('data-mark')
|
|
609
|
+
if (mark && mark !== last) { last = mark; await shoot(`${mark}`); pending.push({ mark, at: Date.now() + 700 * slow }) }
|
|
610
|
+
while (pending.length && pending[0].at <= Date.now()) { const p = pending.shift(); await shoot(`${p.mark} +0.7s`) }
|
|
611
|
+
}
|
|
612
|
+
await shoot(`end ${secs((Date.now() - start) / slow)}`)
|
|
613
|
+
} else {
|
|
614
|
+
// The jump scan has been running since the first stage render, including
|
|
615
|
+
// once-only beats that happened before fonts and the first shot settled.
|
|
616
|
+
const start = Date.now()
|
|
617
|
+
for (let i = 0; i < count; i++) {
|
|
618
|
+
await page.waitForTimeout(Math.max(0, start + i * every * slow - Date.now()))
|
|
619
|
+
await shoot(`${(Math.max(0, Date.now() - start) / slow / 1000).toFixed(slow > 1 ? 2 : 1)}s`)
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const stopped = await page.evaluate(() => {
|
|
625
|
+
window.__ssVerification.stopped = true
|
|
626
|
+
return { at: performance.now(), snapshot: window.__ssVerification }
|
|
627
|
+
}).catch(() => null)
|
|
628
|
+
const snapshot = stopped?.snapshot
|
|
629
|
+
const captureMs = stopped ? stopped.at - captureStarted : 0
|
|
630
|
+
|
|
631
|
+
// Lay the frames out in the browser itself, so there is nothing else to install.
|
|
632
|
+
// The sheet renders at 2x and each frame is drawn at its natural pixel size
|
|
633
|
+
// (CSS width = pixels / 2), so nothing is ever scaled up or down.
|
|
634
|
+
// A followed target varies in size: frame them all at the widest
|
|
635
|
+
if (zoomTarget) clip = shots.reduce((a, s) => (s.w > a.width ? { width: s.w, height: s.h } : a), { width: 0, height: 0 })
|
|
636
|
+
const frameW = Math.round((clip.width * dsf) / 2)
|
|
637
|
+
const gap = 12
|
|
638
|
+
// Columns: as many as fit in ~1800px, but a wide stage that fits only one or
|
|
639
|
+
// two still gets a sheet about twice as wide as it is tall, not a long strip
|
|
640
|
+
const frameH = Math.round((clip.height * dsf) / 2)
|
|
641
|
+
const fit = Math.floor(1800 / (frameW + gap))
|
|
642
|
+
const even = Math.round(Math.sqrt((shots.length * 2 * (frameH + gap)) / (frameW + gap)))
|
|
643
|
+
const cols = colsOpt ? Number(colsOpt) : Math.max(1, Math.min(shots.length, fit >= 3 ? fit : Math.max(fit, even)))
|
|
644
|
+
const sheetHeight = Math.ceil(shots.length / cols) * (frameH + gap) + gap
|
|
645
|
+
const sheet = await browser.newPage({ viewport: { width: cols * (frameW + gap) + gap, height: Math.min(400, sheetHeight) }, deviceScaleFactor: 2 })
|
|
646
|
+
await sheet.setContent(`<body style="margin:0;background:#e9e9e9;font:11px system-ui">
|
|
647
|
+
<div style="display:grid;grid-template-columns:repeat(${cols},${frameW}px);gap:${gap}px;padding:${gap}px">
|
|
648
|
+
${shots
|
|
649
|
+
.map(
|
|
650
|
+
(s) => `<figure style="margin:0;position:relative">
|
|
651
|
+
<img src="${s.src}" style="width:${frameW}px;display:block;background:#fff">
|
|
652
|
+
<figcaption style="position:absolute;left:4px;top:4px;padding:1px 4px;background:#000c;color:#fff;border-radius:3px">${s.label}</figcaption>
|
|
653
|
+
</figure>`,
|
|
654
|
+
)
|
|
655
|
+
.join('')}
|
|
656
|
+
</div></body>`)
|
|
657
|
+
await sheet.waitForLoadState('load')
|
|
658
|
+
mkdirSync(dirname(out), { recursive: true })
|
|
659
|
+
await sheet.screenshot({ path: out, fullPage: true })
|
|
660
|
+
await browser.close()
|
|
661
|
+
|
|
662
|
+
const what = hover ? `${shots.length} frames (rest, hover ${hoverFor}ms, leave ${leaveFor}ms) every ${every}ms` : `${shots.length} frames every ${every}ms`
|
|
663
|
+
console.log(`${what}${zoom || zoomTarget ? `, zoom ${dsf}x` : ''} -> ${out}`)
|
|
664
|
+
finishReport(snapshot, captureMs)
|