@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.
@@ -0,0 +1,557 @@
1
+ // Runs inside the page. Kept self-contained for init-script injection and
2
+ // deterministic fixture tests; heuristics report candidates for visual review.
3
+ export function watchMotion(selector) {
4
+ const watched = new WeakSet()
5
+ const watch = (root) => {
6
+ const key = window.__ssStageKey(root)
7
+ const seen = new Map()
8
+ const flagged = []
9
+ const ink = []
10
+ const t0 = performance.now()
11
+ const opacityOf = (el, root) => {
12
+ let o = 1
13
+ for (let n = el; n && n !== root.parentElement; n = n.parentElement) o *= Number(getComputedStyle(n).opacity)
14
+ return o
15
+ }
16
+ const center = (el) => {
17
+ const r = el.getBoundingClientRect()
18
+ return { x: r.left + r.width / 2, y: r.top + r.height / 2 }
19
+ }
20
+ const label = (el) => `${el.tagName.toLowerCase()}${el.classList.length ? '.' + [...el.classList].join('.') : ''}`
21
+ let lastInk = 0
22
+ // Hard edges: the visible fraction of each cut leaf, last frame
23
+ const cut = new WeakMap()
24
+ const masked = (cs) => (cs.maskImage && cs.maskImage !== 'none') || (cs.webkitMaskImage && cs.webkitMaskImage !== 'none')
25
+ const hardEdges = (root) => {
26
+ const S = root.getBoundingClientRect()
27
+ for (const el of root.querySelectorAll('*')) {
28
+ if (el.children.length && el.tagName.toLowerCase() !== 'svg') continue
29
+ if (el.closest('.ss-cursor, .ss-keys, .ss-roll, .ss-count') || (el.closest('svg') && el.tagName.toLowerCase() !== 'svg')) continue
30
+ const r = el.getBoundingClientRect()
31
+ if (r.width < 4 || r.height < 4) continue
32
+ let found = null
33
+ for (let a = el; a && a !== root; a = a.parentElement) {
34
+ const cs = getComputedStyle(a)
35
+ if (masked(cs)) break
36
+ if (a === el || (cs.overflowX === 'visible' && cs.overflowY === 'visible')) continue
37
+ const c = a.getBoundingClientRect()
38
+ const visH = Math.min(r.bottom, c.bottom) - Math.max(r.top, c.top)
39
+ const visW = Math.min(r.right, c.right) - Math.max(r.left, c.left)
40
+ if (visH <= 0 || visW <= 0) break
41
+ const fy = visH / r.height
42
+ const fx = visW / r.width
43
+ // The cutting edge must be inside the stage; the stage's own edge is a deliberate crop
44
+ const edgeIn = (fy < 0.999 && ((r.top < c.top && c.top > S.top + 2) || (r.bottom > c.bottom && c.bottom < S.bottom - 2))) || (fx < 0.999 && ((r.left < c.left && c.left > S.left + 2) || (r.right > c.right && c.right < S.right - 2)))
45
+ // An edge that lines up with an outer clipping surface's edge (a panel
46
+ // sliding out from under a window's side) is a surface boundary, not a slice
47
+ const flush = (b) => {
48
+ const d = b.getBoundingClientRect()
49
+ const near = (x, y) => Math.abs(x - y) < 1.5
50
+ return (r.top < c.top && near(c.top, d.top)) || (r.bottom > c.bottom && near(c.bottom, d.bottom)) || (r.left < c.left && near(c.left, d.left)) || (r.right > c.right && near(c.right, d.right))
51
+ }
52
+ let surfaceEdge = false
53
+ for (let b = a.parentElement; b && b !== root.parentElement; b = b.parentElement) {
54
+ const bs = getComputedStyle(b)
55
+ if ((bs.overflowX !== 'visible' || bs.overflowY !== 'visible' || b === root) && flush(b)) {
56
+ surfaceEdge = true
57
+ break
58
+ }
59
+ }
60
+ if (edgeIn && !surfaceEdge) found = { a, f: Math.min(fy, fx) }
61
+ break
62
+ }
63
+ const prev = cut.get(el)
64
+ if (!found) {
65
+ cut.delete(el)
66
+ continue
67
+ }
68
+ cut.set(el, found.f)
69
+ // Sliced between 10% and 90%, the cut moved since last frame, and still readable
70
+ if (prev === undefined || Math.abs(prev - found.f) < 0.02 || found.f < 0.1 || found.f > 0.9) continue
71
+ if (opacityOf(el, root) < 0.35) continue
72
+ // A single row unfolding from its middle (Collapse reveal="clip") is cut on purpose
73
+ if (found.a.matches?.(".ss-collapse[data-reveal='clip']:not([data-tall]) > .ss-collapse__inner")) continue
74
+ flagged.push(`hard edge: ${label(el)}${(el.textContent || '').trim() ? ` "${el.textContent.trim().slice(0, 20)}"` : ''} is cut by ${label(found.a)}'s edge while it moves; keep it faint until the edge has passed (Collapse does), or keep it whole`)
75
+ }
76
+ }
77
+ // Boxes with text in them, and where each was last frame
78
+ const painted = (c) => c && c !== 'transparent' && !/rgba\([^)]*,\s*0\)$/.test(c)
79
+ const isBox = (cs) => painted(cs.backgroundColor) || cs.backgroundImage !== 'none' || (parseFloat(cs.borderTopWidth) > 0 && painted(cs.borderTopColor))
80
+ const ownText = (el) => [...el.childNodes].some((n) => n.nodeType === 3 && n.textContent.trim())
81
+ let boxes = []
82
+ let boxesAt = 0
83
+ const was = new WeakMap()
84
+ const stepped = new Set()
85
+ const layered = (el, root) => {
86
+ for (let a = el; a && a !== root.parentElement; a = a.parentElement) if (/transform/.test(getComputedStyle(a).willChange)) return true
87
+ return false
88
+ }
89
+ const stepsInBox = (root, transforming) => {
90
+ const now = performance.now()
91
+ if (now - boxesAt > 400) {
92
+ boxesAt = now
93
+ boxes = []
94
+ for (const el of root.querySelectorAll('*')) {
95
+ if (el.closest('.ss-cursor, .ss-keys, .ss-roll, .ss-count, svg')) continue
96
+ const r = el.getBoundingClientRect()
97
+ if (r.height < 8 || r.height > 64 || r.width > 320) continue
98
+ if (!isBox(getComputedStyle(el))) continue
99
+ // Text in the box itself or in anything inside it
100
+ if (ownText(el) || [...el.querySelectorAll('*')].some(ownText)) boxes.push(el)
101
+ }
102
+ }
103
+ for (const el of boxes) {
104
+ if (!el.isConnected) continue
105
+ const r = el.getBoundingClientRect()
106
+ const p = was.get(el)
107
+ was.set(el, { x: r.left, y: r.top })
108
+ if (!p) continue
109
+ const d = Math.max(Math.abs(r.left - p.x), Math.abs(r.top - p.y))
110
+ if (d < 0.05 || d > 40) continue
111
+ // Moved by a transform, box and text are one layer while it runs
112
+ let t = false
113
+ for (const a of transforming) if (a.contains(el)) t = true
114
+ if (t || layered(el, root) || opacityOf(el, root) < 0.5) continue
115
+ const name = label(el)
116
+ if (stepped.has(name)) continue
117
+ stepped.add(name)
118
+ flagged.push(`steps in its box: ${name} "${(el.textContent || '').trim().slice(0, 20)}" moves by layout, so its text snaps to whole pixels while the box glides, and hops inside it as it lands; give it or a parent a lasting layer (will-change: transform), and glide it by a transform`)
119
+ }
120
+ }
121
+ // Fly sizes: a handoff is one object. The flyer takes off at the size of
122
+ // what it leaves and lands at the size of what replaces it; a mismatch
123
+ // grows or shrinks in flight and snaps when the real element appears.
124
+ const flights = new Map()
125
+ const flyNoted = new Set()
126
+ const twin = (r, fly) => {
127
+ const cx = r.left + r.width / 2
128
+ const cy = r.top + r.height / 2
129
+ for (const el of document.elementsFromPoint(cx, cy)) {
130
+ if (fly.contains(el) || el.closest('.ss-cursor')) continue
131
+ const b = el.getBoundingClientRect()
132
+ // The same object: centered together and within about a third in each size
133
+ const kw = b.width / Math.max(1, r.width)
134
+ const kh = b.height / Math.max(1, r.height)
135
+ if (Math.abs(b.left + b.width / 2 - cx) <= 3 && Math.abs(b.top + b.height / 2 - cy) <= 3 && kw > 0.7 && kw < 1.45 && kh > 0.7 && kh < 1.45) return el
136
+ }
137
+ return null
138
+ }
139
+ const flyNote = (key, msg) => {
140
+ if (flyNoted.has(key)) return
141
+ flyNoted.add(key)
142
+ flagged.push(msg)
143
+ }
144
+ const landing = (fly, rec) => {
145
+ const r = rec.last
146
+ const real = twin(r, fly)
147
+ if (real) {
148
+ const b = real.getBoundingClientRect()
149
+ if (Math.abs(b.width - r.width) > 1 || Math.abs(b.height - r.height) > 1) flyNote(`down:${label(real)}`, `fly size: the flyer lands at ${Math.round(r.width)}x${Math.round(r.height)} but ${label(real)}, which replaces it, is ${Math.round(b.width)}x${Math.round(b.height)}, so it snaps on the handoff; pass the landing element's own rect as \`to\`, not its slot's`)
150
+ rec.last = null
151
+ } else if (--rec.wait <= 0) rec.last = null
152
+ }
153
+ const flySizes = (root) => {
154
+ // A flyer unmounted on the landing frame
155
+ for (const [fly, rec] of flights) {
156
+ if (fly.isConnected) continue
157
+ if (rec.last) landing(fly, rec)
158
+ if (!rec.last) flights.delete(fly)
159
+ }
160
+ for (const fly of root.querySelectorAll('.ss-fly')) {
161
+ const rec = flights.get(fly) ?? { up: false, last: null, wait: 0 }
162
+ flights.set(fly, rec)
163
+ const body = fly.querySelector('.ss-fly__lift')?.firstElementChild ?? fly
164
+ const go = fly.hasAttribute('data-go') && opacityOf(fly, root) > 0.5
165
+ if (go) {
166
+ const r = body.getBoundingClientRect()
167
+ if (!rec.up) {
168
+ rec.up = true
169
+ const src = twin(r, fly)
170
+ if (src) {
171
+ const b = src.getBoundingClientRect()
172
+ if (Math.abs(b.width - r.width) > 1 || Math.abs(b.height - r.height) > 1) flyNote(`up:${label(src)}`, `fly size: the flyer takes off at ${Math.round(r.width)}x${Math.round(r.height)} from ${label(src)} drawn at ${Math.round(b.width)}x${Math.round(b.height)}, so it changes size the moment it lifts; draw the flyer at the size of what it leaves`)
173
+ }
174
+ }
175
+ rec.last = r
176
+ rec.wait = 6
177
+ } else if (rec.last) {
178
+ // Just landed: look for what replaces it, for a few frames
179
+ landing(fly, rec)
180
+ rec.up = false
181
+ } else rec.up = false
182
+ }
183
+ }
184
+ // After motion, nothing moves. Two checks on every element, every frame:
185
+ // a handoff (one element hides as a near-identical one shows in its place:
186
+ // a flyer and the real one, a ghost, a crossover) must swap on a frame
187
+ // where both are identical; and an element at rest after motion must not
188
+ // then shift with nothing animating.
189
+ const restAt = new Map()
190
+ let flowBoxes = new Map()
191
+ const gone = []
192
+ const shiftNoted = new Set()
193
+ // What it is: its kind, its own words, and for a wordless mark (an icon)
194
+ // its drawing, so two different icons crossfading are never paired
195
+ const sig = (el) => {
196
+ const words = [...el.childNodes].filter((c) => c.nodeType === 3).map((c) => c.textContent.trim()).join('').slice(0, 30)
197
+ return `${label(el)}|${words}|${words ? '' : el.innerHTML.replace(/\s+/g, '').slice(0, 200)}`
198
+ }
199
+ const handoffs = (root) => {
200
+ const now = performance.now()
201
+ const animations = document.getAnimations().filter((a) => a.playState === 'running' && a.effect?.target && root.contains(a.effect.target))
202
+ const runningTargets = animations.map((a) => a.effect.target)
203
+ const layoutProperty = /^(?:width|height|min-width|max-width|min-height|max-height|block-size|inline-size|min-block-size|max-block-size|min-inline-size|max-inline-size|grid-template-rows|grid-template-columns|flex-basis|gap|row-gap|column-gap|padding(?:-.+)?|margin(?:-.+)?)$/
204
+ const layoutTargets = [...new Set(animations.filter((animation) => {
205
+ if (animation.transitionProperty) return layoutProperty.test(animation.transitionProperty)
206
+ return (animation.effect.getKeyframes?.() || []).some((frame) => Object.keys(frame).some((name) => layoutProperty.test(name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`))))
207
+ }).map((animation) => animation.effect.target))]
208
+ const seen = new Map()
209
+ const boxes = new Map([[root, root.getBoundingClientRect()]])
210
+ const op = new Map()
211
+ for (const el of root.querySelectorAll('*')) {
212
+ if (el.closest('.ss-cursor, .ss-keys') || (el.parentElement && el.parentElement.closest('svg'))) continue
213
+ const cs = getComputedStyle(el)
214
+ // Include zero-height/transparent flow items before their entrance: a
215
+ // receipt can move its siblings on the first frame it starts opening.
216
+ const r = el.getBoundingClientRect()
217
+ boxes.set(el, r)
218
+ const o = (op.get(el.parentElement) ?? 1) * Number(cs.opacity)
219
+ // Meant to step (a terminal adding a line, a caret): not a settle snap
220
+ if (el.closest('[data-snap]')) { op.set(el, o); continue }
221
+ op.set(el, cs.visibility === 'hidden' || cs.display === 'none' ? 0 : o)
222
+ if (op.get(el) < 0.5) continue
223
+ if (r.width < 4 || r.height < 4 || r.width > 500 || r.height > 500) continue
224
+ seen.set(el, r)
225
+ }
226
+ const inFlow = (element) => {
227
+ const style = getComputedStyle(element)
228
+ return !/^(absolute|fixed)$/.test(style.position) && style.display !== 'none' && (!style.cssFloat || style.cssFloat === 'none')
229
+ }
230
+ const carriedByFlow = (el, rect, previous) => {
231
+ if (!previous) return false
232
+ // A sibling must explain the displacement, not a simultaneous resize
233
+ // of this element. Transforms/opacity (including spinners) do not qualify.
234
+ if (Math.abs(rect.width - previous.width) > 0.1 || Math.abs(rect.height - previous.height) > 0.1) return false
235
+ for (const target of layoutTargets) {
236
+ for (let branch = target; branch && branch !== root; branch = branch.parentElement) {
237
+ if (!inFlow(branch)) break
238
+ const parent = branch.parentElement
239
+ if (!parent || !parent.contains(el) || branch.contains(el)) continue
240
+ let subject = el
241
+ while (subject.parentElement && subject.parentElement !== parent) subject = subject.parentElement
242
+ if (!inFlow(subject)) break
243
+ const style = getComputedStyle(parent)
244
+ const flex = /^(inline-)?flex$/.test(style.display)
245
+ // Keep this exemption to simple one-axis flow. Grid placements,
246
+ // wrapping flex rows and distributed gaps need separate evidence.
247
+ if (flex ? style.flexWrap && style.flexWrap !== 'nowrap' : !/^(block|flow-root)$/.test(style.display)) break
248
+ if (style.writingMode && style.writingMode !== 'horizontal-tb') break
249
+ const horizontal = flex && !style.flexDirection.startsWith('column')
250
+ const axis = horizontal ? 'left' : 'top', cross = horizontal ? 'top' : 'left', size = horizontal ? 'width' : 'height'
251
+ const before = flowBoxes.get(branch), after = boxes.get(branch), subjectBefore = flowBoxes.get(subject)
252
+ if (!before || !after || !subjectBefore) break
253
+ const growth = after[size] - before[size]
254
+ if (Math.abs(growth) < 0.05 || Math.abs(rect[cross] - previous[cross]) > 0.1) break
255
+ const reverse = flex && style.flexDirection.endsWith('reverse')
256
+ const ahead = reverse ? before[axis] > subjectBefore[axis] : before[axis] < subjectBefore[axis]
257
+ const justify = flex ? style.justifyContent : 'start'
258
+ let alignment = 0
259
+ if (justify === 'center') alignment = -0.5
260
+ else if (justify === 'flex-end' || justify === 'end') alignment = -1
261
+ else if (justify && !['normal', 'start', 'flex-start', 'stretch'].includes(justify)) break
262
+ const expected = (reverse ? -1 : 1) * ((ahead ? 1 : 0) + alignment) * growth
263
+ const moved = rect[axis] - previous[axis]
264
+ // Compare actual pixels: an active height transition in a fixed-size
265
+ // or unrelated sibling does not waive an independent settle snap.
266
+ if (Math.abs(expected) >= 0.05 && Math.abs(moved - expected) <= Math.max(0.1, Math.abs(expected) * 0.05)) return true
267
+ break
268
+ }
269
+ }
270
+ return false
271
+ }
272
+ // What left this frame first, so a swap within one frame is paired
273
+ for (const [el, rec] of restAt) {
274
+ if (seen.has(el)) continue
275
+ gone.push({ sig: sig(el), r: rec.r, at: now })
276
+ restAt.delete(el)
277
+ }
278
+ for (const [el, r] of seen) {
279
+ const prev = restAt.get(el)
280
+ const running = runningTargets.some((target) => target === el || target.contains(el)) || carriedByFlow(el, r, prev?.r)
281
+ if (!prev) {
282
+ // It just appeared: is it taking over from something that just left?
283
+ const k = sig(el)
284
+ for (const g of gone) {
285
+ if (g.sig !== k || now - g.at > 60) continue
286
+ const d = Math.max(Math.abs(g.r.left - r.left), Math.abs(g.r.top - r.top), Math.abs(g.r.width - r.width), Math.abs(g.r.height - r.height))
287
+ if (d > 6) continue
288
+ if (d >= 0.5 && !shiftNoted.has('h' + k)) {
289
+ shiftNoted.add('h' + k)
290
+ flagged.push(`handoff shift: ${label(el)} replaces an identical element that was last drawn ${(r.left - g.r.left).toFixed(1)}px across, ${(r.top - g.r.top).toFixed(1)}px down and ${(r.width - g.r.width).toFixed(1)}x${(r.height - g.r.height).toFixed(1)}px larger, so it visibly snaps on the swap; measure the element that lands (rect() on it, not its container) and swap on a frame where both are identical`)
291
+ }
292
+ g.used = true
293
+ break
294
+ }
295
+ restAt.set(el, { r, still: 0, moved: running ? now : -1e9, lastAnim: running ? now : -1e9 })
296
+ continue
297
+ }
298
+ const dx = Math.abs(r.left - prev.r.left)
299
+ const dy = Math.abs(r.top - prev.r.top)
300
+ const dw = Math.abs(r.width - prev.r.width)
301
+ const dh = Math.abs(r.height - prev.r.height)
302
+ const moved = Math.max(dx, dy, dw, dh)
303
+ if (running) prev.lastAnim = now
304
+ if (moved < 0.01) prev.still++
305
+ else {
306
+ // Moved with nothing animating, soon after motion, from rest
307
+ if (moved >= 0.5 && !running && now - prev.lastAnim > 20 && prev.still >= 2 && now - prev.moved < 1000) {
308
+ const k = sig(el)
309
+ if (!shiftNoted.has('s' + k)) {
310
+ shiftNoted.add('s' + k)
311
+ flagged.push(`settle snap: ${label(el)} came to rest after moving, then shifted ${moved.toFixed(1)}px with no transition running, so it hops after the motion has ended; land it exactly where it stays (measure the element, mind borders and rounding) or carry the last part in the transition`)
312
+ }
313
+ }
314
+ prev.still = 0
315
+ if (running) prev.moved = now
316
+ }
317
+ prev.r = r
318
+ }
319
+ flowBoxes = boxes
320
+ while (gone.length && (now - gone[0].at > 60 || gone.length > 400)) gone.shift()
321
+ }
322
+ // Pops: an element that shows between two frames already at full opacity
323
+ // and size, with nothing animating it or its ancestors (a chip appearing
324
+ // whole over the value it buds from), or vanishes the same way. Exempt:
325
+ // the cursor and keycaps, what steps on purpose (data-snap, carets),
326
+ // something that shows under a covering surface, and a swap where an
327
+ // identical element leaves as it shows (a flyer taking over from its
328
+ // source), typing (placeholders, typed letters, selections, highlights),
329
+ // anything crossing a clip's edge (a move, not a pop) and a Roll's parts.
330
+ // Also: a dashed or dotted edge whose box changes size, which
331
+ // Chrome re-lays every frame, so the dashes crawl and flicker.
332
+ let vis = new Map()
333
+ let tiny = new Set()
334
+ let popFrom = -1
335
+ let popLast = -1
336
+ const popNoted = new Set()
337
+ const pops = (root) => {
338
+ const now = performance.now()
339
+ if (popFrom < 0) popFrom = now
340
+ // Only an entrance or exit counts: a fade, a clip, a size opening. A
341
+ // move alone (a flyer setting off at full size) still pops in
342
+ const entering = (a) => {
343
+ if (a.transitionProperty) return /opacity|clip|height|width|grid-template|filter/.test(a.transitionProperty) && !(a.transitionProperty === 'filter')
344
+ const kf = a.effect?.getKeyframes?.() ?? []
345
+ return kf.some((f) => 'opacity' in f || 'clipPath' in f || 'height' in f || 'width' in f)
346
+ }
347
+ const busy = new Set(document.getAnimations().filter((a) => a.playState === 'running' && entering(a)).map((a) => a.effect && a.effect.target).filter(Boolean))
348
+ const busyUp = (el) => { for (let a = el; a && a !== root.parentElement; a = a.parentElement) if (busy.has(a)) return true; return false }
349
+ const k = root.getBoundingClientRect().width / (root.offsetWidth || 1) || 1
350
+ const cur = new Map()
351
+ const op = new Map()
352
+ // Shown but too small to judge: a fill that eases to nothing (or grows
353
+ // out of it) crosses the size floor without popping
354
+ const tinyNow = new Set()
355
+ // The box each element is clipped to by its ancestors: a roll's old
356
+ // line slid out of its window has left view before it is removed
357
+ const clipOf = new Map()
358
+ const R = root.getBoundingClientRect()
359
+ clipOf.set(root, { l: R.left, t: R.top, r: R.right, b: R.bottom })
360
+ for (const el of root.querySelectorAll('*')) {
361
+ if (el.closest('.ss-cursor, .ss-keys, [data-snap], .ss-caret, .ss-field__caret, .ss-term__caret, .ss-count__strip') || el.parentElement?.closest('svg')) continue
362
+ const cs = getComputedStyle(el)
363
+ const o = (op.get(el.parentElement) ?? 1) * Number(cs.opacity) * (cs.visibility === 'hidden' || cs.display === 'none' ? 0 : 1)
364
+ op.set(el, o)
365
+ const pc = clipOf.get(el.parentElement) ?? clipOf.get(root)
366
+ if (cs.overflow !== 'visible' || cs.clipPath !== 'none') {
367
+ const b = el.getBoundingClientRect()
368
+ clipOf.set(el, { l: Math.max(pc.l, b.left), t: Math.max(pc.t, b.top), r: Math.min(pc.r, b.right), b: Math.min(pc.b, b.bottom) })
369
+ } else clipOf.set(el, pc)
370
+ if (o < 0.5) continue
371
+ // A flyer is drawn by its scaled inner box, not its take-off box
372
+ const r = (el.matches('.ss-fly') && el.querySelector('.ss-fly__lift')?.getBoundingClientRect()) || el.getBoundingClientRect()
373
+ if (r.width * r.height < 36 * k * k) {
374
+ tinyNow.add(el)
375
+ continue
376
+ }
377
+ // Mostly outside its clip: present but out of view, so crossing the
378
+ // clip's edge is a move, not an entrance or an exit
379
+ const out = Math.max(0, Math.min(r.right, pc.r) - Math.max(r.left, pc.l)) * Math.max(0, Math.min(r.bottom, pc.b) - Math.max(r.top, pc.t)) < r.width * r.height * 0.5
380
+ const sc = el.matches('.ss-fly') ? 1 : el instanceof HTMLElement && el.offsetWidth ? r.width / el.offsetWidth / k : 1
381
+ const dashed = (/dashed|dotted/.test(cs.borderTopStyle) && parseFloat(cs.borderTopWidth) > 0) || (/dashed|dotted/.test(cs.outlineStyle) && parseFloat(cs.outlineWidth) > 0)
382
+ // A flyer shows through its inner box (where it buds and lifts)
383
+ const lift = el.matches('.ss-fly') ? el.querySelector('.ss-fly__lift') : null
384
+ const ov = lift ? o * Number(getComputedStyle(lift).opacity) : o
385
+ cur.set(el, { o: ov, r, sc, busy: busyUp(lift ?? el), parent: el.parentElement, dashed, out, roll: !!el.closest('.ss-roll, .ss-count'), signature: sig(el), typed: !!el.closest('[data-typing], .ss-field__chars, .ss-field__placeholder, .ss-draft__ph, .ss-draft__typed, .ss-kb__callout, .ss-kb__suggest') })
386
+ }
387
+ const near = (a, b) => Math.abs(a.left + a.width / 2 - b.left - b.width / 2) < 40 * k && Math.abs(a.top + a.height / 2 - b.top - b.height / 2) < 40 * k && Math.abs(a.width - b.width) < Math.max(a.width, b.width) * 0.35
388
+ const left = [...vis].filter(([el]) => !cur.has(el))
389
+ const came = [...cur].filter(([el]) => !vis.has(el))
390
+ // A late frame (the page busy, as while a screenshot is taken) can hide a
391
+ // whole short fade between two samples: not judged
392
+ const late = popLast > 0 && now - popLast > 40
393
+ popLast = now
394
+ if (now > popFrom && !late) {
395
+ const name = (el) => `${label(el)}${(el.textContent || '').trim() ? ` "${el.textContent.trim().slice(0, 20)}"` : ''}`
396
+ // What it paints: its contents at their own opacity (a held flyer
397
+ // whose chip fades in by a keyframe paints nothing yet)
398
+ const paints = (el) => {
399
+ if (!el.children.length) return 1
400
+ let most = 0
401
+ const walk = (n, o) => {
402
+ for (const c of n.children) {
403
+ const co = o * Number(getComputedStyle(c).opacity)
404
+ if (!c.children.length || [...c.childNodes].some((t) => t.nodeType === 3 && t.textContent.trim())) most = Math.max(most, co)
405
+ if (c.children.length && most < 0.9) walk(c, co)
406
+ }
407
+ }
408
+ walk(el, 1)
409
+ return most
410
+ }
411
+ // Typing is instant in the real thing: a field's placeholder goes on
412
+ // the first key, letters and the clear button land whole, a key's
413
+ // callout flashes, a text selection or match highlight paints at once.
414
+ // A Roll splits its line into parts on the first change (the part that
415
+ // stays is still painted), so its own pieces aren't judged
416
+ const typed = (el) => el.closest('[data-typing], .ss-field__chars, .ss-field__placeholder, .ss-draft__ph, .ss-draft__typed, .ss-kb__callout, .ss-kb__suggest')
417
+ for (const [el, c] of came) {
418
+ if (cur.has(c.parent) && !vis.has(c.parent)) continue
419
+ if (typed(el) || c.out || el.closest('.ss-roll') || tiny.has(el)) continue
420
+ if (c.o < 0.9 || c.sc < 0.95 || c.busy) continue
421
+ if (el.getAnimations({ subtree: true }).some((a) => a.playState === 'running' && entering(a)) || paints(el) < 0.9) continue
422
+ if (left.some(([, g]) => g.signature === c.signature && near(g.r, c.r))) continue
423
+ // Shown under a surface that covers it (a card sliding over it)
424
+ // (hit-testing skips pointer-events: none, a flyer's, so that one can't be judged covered)
425
+ const top = getComputedStyle(el).pointerEvents === 'none' ? null : document.elementFromPoint(c.r.left + c.r.width / 2, c.r.top + c.r.height / 2)
426
+ if (top && !el.contains(top) && !top.contains(el) && !top.closest('.ss-cursor')) continue
427
+ const key = 'in' + name(el)
428
+ if (popNoted.has(key)) continue
429
+ popNoted.add(key)
430
+ flagged.push(`appears with no entrance: ${name(el)} shows at full size and opacity in one frame; fade it in, or grow it out of what it comes from (a chip budding off a value scales from it as it fades in: Fly with held), never pop it in whole`)
431
+ }
432
+ for (const [el, g] of left) {
433
+ if (vis.has(g.parent) && !cur.has(g.parent)) continue
434
+ if (g.typed || g.out || g.roll || g.sc < 0.95 || tinyNow.has(el)) continue
435
+ if (g.o < 0.9 || g.busy) continue
436
+ if (came.some(([, c]) => g.signature === c.signature && near(g.r, c.r))) continue
437
+ const key = 'out' + name(el)
438
+ if (popNoted.has(key)) continue
439
+ popNoted.add(key)
440
+ flagged.push(`vanishes with no exit: ${name(el)} goes from full opacity to gone in one frame; fade it out (or move it out of view) before it is removed`)
441
+ }
442
+ for (const [el, c] of cur) {
443
+ const p = vis.get(el)
444
+ if (!p || !c.dashed || !p.dashed) continue
445
+ if (Math.abs(c.r.width - p.r.width) < 0.5 && Math.abs(c.r.height - p.r.height) < 0.5) continue
446
+ const key = 'dash' + label(el)
447
+ if (popNoted.has(key)) continue
448
+ popNoted.add(key)
449
+ flagged.push(`dashed edge resizes: ${label(el)} has a dashed or dotted edge whose box changes size, so the dashes are re-laid every frame and crawl; draw the mark at its full size on its own layer and only fade it`)
450
+ }
451
+ }
452
+ vis = cur
453
+ tiny = tinyNow
454
+ }
455
+ const moving = new Set()
456
+ const landed = new Set()
457
+ const tick = () => {
458
+ if (window.__ssVerification?.stopped || !root.isConnected) return
459
+ try {
460
+ if (root) {
461
+ // Text riding a transform to rest: watch transform transitions finish
462
+ const now0 = new Set()
463
+ for (const a of document.getAnimations()) {
464
+ const el = a.effect && a.effect.target
465
+ if (!el || !root.contains(el) || !/^(transform|translate|scale)$/.test(a.transitionProperty || '')) continue
466
+ // A surface scaling on ::before carries no text: that is the fix, not the fault
467
+ if (a.effect.pseudoElement) continue
468
+ // A camera push-in has to be a transform: it scales the whole scene
469
+ if (el.closest('.ss-cursor, .ss-fly, .ss-keys, .ss-key') || el.matches('.ss-camera, .ss-camera-view')) continue
470
+ now0.add(el)
471
+ }
472
+ for (const el of moving) {
473
+ if (now0.has(el)) continue
474
+ moving.delete(el)
475
+ if (!el.isConnected) continue
476
+ const cs = getComputedStyle(el)
477
+ const t = cs.transform
478
+ // Kept on its own layer for good (will-change: transform), it rests
479
+ // exactly as it would untransformed: nothing re-snaps (Expand's launch)
480
+ if (/transform/.test(cs.willChange)) continue
481
+ const rest = t === 'none' || /^matrix\(1, 0, 0, 1, 0, 0\)$/.test(t)
482
+ if (!rest || opacityOf(el, root) < 0.5 || !(el.textContent || '').trim()) continue
483
+ const name = label(el)
484
+ if (landed.has(name)) continue
485
+ landed.add(name)
486
+ flagged.push(`lands on a transform: ${name} "${el.textContent.trim().slice(0, 20)}" comes to rest at the end of a transform, so its text hops a fraction of a pixel as it lands; keep it on a layer for good (will-change: transform), or scale only its surface`)
487
+ }
488
+ for (const el of now0) moving.add(el)
489
+ const live = new Set()
490
+ for (const a of document.getAnimations()) {
491
+ const el = a.effect && a.effect.target
492
+ const prop = a.transitionProperty || ''
493
+ // A pen tip (data-lead) shows first on purpose: the draw follows it
494
+ if (!el || !root.contains(el) || !/^(transform|translate|top|left)$/.test(prop) || el.closest('.ss-cursor, [data-lead]')) continue
495
+ live.add(el)
496
+ if (!seen.has(el)) seen.set(el, { from: center(el), o0: opacityOf(el, root), opaqueAt: null })
497
+ const s = seen.get(el)
498
+ if (!s.opaqueAt && s.o0 < 0.5 && opacityOf(el, root) >= 0.95) s.opaqueAt = center(el)
499
+ }
500
+ for (const [el, s] of seen) {
501
+ if (live.has(el)) continue
502
+ seen.delete(el)
503
+ if (!s.opaqueAt || !el.isConnected) continue
504
+ const to = center(el)
505
+ const total = Math.hypot(to.x - s.from.x, to.y - s.from.y)
506
+ const left = Math.hypot(to.x - s.opaqueAt.x, to.y - s.opaqueAt.y)
507
+ if (left > 8 && left > total * 0.4) flagged.push(`appears, then moves: ${label(el)} is fully visible with ${Math.round((left / total) * 100)}% of its travel still to go (fade at least half the move, starting with it)`)
508
+ }
509
+ const now = performance.now()
510
+ if (now - lastInk > 40) {
511
+ lastInk = now
512
+ const S = root.getBoundingClientRect()
513
+ // A camera push-in shows less on purpose: not an empty frame
514
+ const zoomed = !!root.querySelector('.ss-camera-view[data-zoomed]')
515
+ let n = 0
516
+ for (const el of root.querySelectorAll('*')) {
517
+ if (el.children.length && el.tagName.toLowerCase() !== 'svg') continue
518
+ if (el.closest('.ss-cursor') || (el.closest('svg') && el.tagName.toLowerCase() !== 'svg')) continue
519
+ const r = el.getBoundingClientRect()
520
+ if (r.width < 2 || r.height < 2 || r.right < S.left || r.left > S.right || r.bottom < S.top || r.top > S.bottom) continue
521
+ if (opacityOf(el, root) > 0.3) n++
522
+ }
523
+ if (!zoomed) ink.push({ at: now, n })
524
+ }
525
+ hardEdges(root)
526
+ const transforming = new Set()
527
+ for (const a of document.getAnimations()) {
528
+ const el = a.effect && a.effect.target
529
+ if (el && root.contains(el) && /^(transform|translate|scale)$/.test(a.transitionProperty || a.animationName || '')) transforming.add(el)
530
+ else if (el && root.contains(el) && a.animationName) transforming.add(el)
531
+ }
532
+ stepsInBox(root, transforming)
533
+ flySizes(root)
534
+ handoffs(root)
535
+ pops(root)
536
+ }
537
+ window.__ssVerification.stages[key].motion = { flagged, ink, start: t0 }
538
+ requestAnimationFrame(tick)
539
+ } catch (error) { window.__ssVerification.errors.push(`motion ${key}: ${error.message}`) }
540
+ }
541
+ requestAnimationFrame(tick)
542
+ }
543
+ const discover = () => {
544
+ if (window.__ssVerification?.stopped) return
545
+ if (window.__ssVisibleStages && window.__ssStageKey) {
546
+ try {
547
+ for (const root of window.__ssVisibleStages(selector)) {
548
+ if (watched.has(root)) continue
549
+ watched.add(root)
550
+ watch(root)
551
+ }
552
+ } catch (error) { window.__ssVerification.errors.push(`motion discovery: ${error.message}`); return }
553
+ }
554
+ requestAnimationFrame(discover)
555
+ }
556
+ requestAnimationFrame(discover)
557
+ }