Repository navigation
Expand file tree
/
Copy pathverify.html
More file actions
591 lines (528 loc) · 26.7 KB
/
Copy pathverify.html
File metadata and controls
591 lines (528 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>css-anchor-kit — browser verification harness</title>
<style>
body { margin: 0; font-family: system-ui, sans-serif; }
.pair { position: relative; }
button.anchor {
position: absolute;
width: 80px; height: 30px;
background: #ddd; border: 1px solid #999;
}
.float {
background: #cde; border: 1px solid #36c;
padding: 6px 10px; width: 60px; box-sizing: border-box;
}
/* Containing-block traps: in-flow panels wide enough that a 160px
floating box centered on the anchor must stick out of them. */
.trap {
width: 200px; height: 40px; margin: 40px 0 0 240px;
background: #eee; box-sizing: border-box; padding: 4px;
}
.trap button { position: static; width: 60px; height: 24px; }
.trap .float { width: 160px; }
/* Deliberately unrotated: the rotation consumers apply is purely visual,
and a square box makes the hit test at the tip deterministic. */
.arrow { background: #36c; }
</style>
</head>
<body>
<div id="root"></div>
<script type="module">
import { buildAnchorStyles, isAnchorPositioningSupported } from '../dist/core.js'
import { findContainingBlockTrap } from '../dist/containingBlock.js'
const PLACEMENTS = [
'top', 'top-start', 'top-end',
'bottom', 'bottom-start', 'bottom-end',
'left', 'left-start', 'left-end',
'right', 'right-start', 'right-end',
]
const root = document.getElementById('root')
const pairs = []
// Lay anchors out on a wide, tall grid with plenty of room so the
// primary side never needs to flip. flip is disabled for determinism.
PLACEMENTS.forEach((placement, i) => {
const col = i % 3
const rowN = Math.floor(i / 3)
const x = 200 + col * 320
const y = 200 + rowN * 260
const wrap = document.createElement('div')
wrap.className = 'pair'
const anchorName = `--cak-v${i}`
const btn = document.createElement('button')
btn.className = 'anchor'
btn.textContent = placement
btn.style.left = x + 'px'
btn.style.top = y + 'px'
const float = document.createElement('div')
float.className = 'float'
float.textContent = placement
const { anchor, floating } = buildAnchorStyles(anchorName, {
placement,
offset: 8,
flip: false,
})
Object.assign(btn.style, anchor)
Object.assign(float.style, floating)
wrap.append(btn, float)
root.append(wrap)
pairs.push({ placement, btn, float, wrap })
})
// --- safe area: one pair per side, the corridor rendered as a child of
// the floating element (the only place both anchors stay in scope).
const SAFE_SIDES = ['top', 'bottom', 'left', 'right']
const safePairs = []
SAFE_SIDES.forEach((placement, i) => {
const x = 200 + i * 320
const y = 1300
const wrap = document.createElement('div')
wrap.className = 'pair'
const anchorName = `--cak-s${i}`
const btn = document.createElement('button')
btn.className = 'anchor'
btn.textContent = placement
btn.style.left = x + 'px'
btn.style.top = y + 'px'
const float = document.createElement('div')
float.className = 'float'
float.textContent = placement
const safe = document.createElement('div')
const styles = buildAnchorStyles(anchorName, {
placement,
offset: 24,
flip: false,
safeArea: true,
})
Object.assign(btn.style, styles.anchor)
Object.assign(float.style, styles.floating)
Object.assign(safe.style, styles.safeArea)
float.append(safe)
wrap.append(btn, float)
root.append(wrap)
safePairs.push({ placement, btn, float, safe })
})
// --- arrow: centred on the floating element's facing edge, at any size,
// rendered as a child of the floating element (where it escapes the
// surface's own box-shadow and rides into the top layer with it).
const arrowPairs = []
function buildArrowPair({ placement, size, flip, x, y, key }) {
const wrap = document.createElement('div')
wrap.className = 'pair'
const anchorName = `--cak-${key}`
const btn = document.createElement('button')
btn.className = 'anchor'
btn.textContent = placement
btn.style.left = x + 'px'
btn.style.top = y + 'px'
const float = document.createElement('div')
float.className = 'float'
float.textContent = placement
const arrow = document.createElement('div')
arrow.className = 'arrow'
arrow.style.width = size + 'px'
arrow.style.height = size + 'px'
const styles = buildAnchorStyles(anchorName, { placement, offset: 16, flip })
Object.assign(btn.style, styles.anchor)
Object.assign(float.style, styles.floating)
Object.assign(arrow.style, styles.arrow)
float.append(arrow)
wrap.append(btn, float)
root.append(wrap)
return { placement, size, flip, btn, float, arrow, wrap }
}
PLACEMENTS.forEach((placement, i) => {
arrowPairs.push(buildArrowPair({
placement, size: 12, flip: false, key: `a${i}`,
x: 200 + (i % 3) * 320, y: 1560 + Math.floor(i / 3) * 250,
}))
})
// Size independence: nothing in the formula knows how big the arrow is.
SAFE_SIDES.forEach((placement, i) => {
arrowPairs.push(buildArrowPair({
placement, size: 28, flip: false, key: `ab${i}`,
x: 200 + i * 240, y: 2560,
}))
})
// --- arrow mounted while the page is already scrolled. This is the
// ordinary case (a tooltip opens halfway down a page) and the one that
// catches an `anchor()` resolved against stale, document-space
// coordinates: the anchor's registered position and the viewport agree
// only at scroll 0. Deliberately measured *without* the forced relayout
// in `settle`, which would paper over exactly that.
const lateSpecs = SAFE_SIDES.map((placement, i) => {
const anchorName = `--cak-al${i}`
const btn = document.createElement('button')
btn.className = 'anchor'
btn.textContent = placement
btn.style.left = 200 + i * 240 + 'px'
btn.style.top = '2810px'
Object.assign(btn.style, buildAnchorStyles(anchorName, { placement }).anchor)
const wrap = document.createElement('div')
wrap.className = 'pair'
wrap.append(btn)
root.append(wrap)
return { placement, anchorName, btn, wrap }
})
// Every pair is absolutely/fixed positioned and contributes no flow
// height, so the page would scroll no further than the last anchor —
// leaving the bottom row pinned to the viewport edge where
// `scrollIntoView({ block: 'center' })` can't actually center it (and a
// corridor just below it falls outside the viewport, where
// `elementFromPoint` sees nothing). This spacer is in flow, so it has to
// clear the lowest anchor on its own.
const spacer = document.createElement('div')
spacer.style.height = '3800px'
root.append(spacer)
const raf = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))
// Anchor positioning is scroll-adjusted off the main thread, so after a
// programmatic scroll the new position can be a couple of frames behind
// the rects we're about to read. Two frames alone flake; give it a beat.
// A floating box whose anchor was off-screen when it was first laid out
// gets clamped into the viewport (expected: `position: fixed` is
// viewport-relative). Chrome's scroll adjustment then moves that clamped
// box, so scrolling the anchor into view isn't enough to un-clamp it —
// only a fresh layout is. Every pair here starts off-screen, so re-lay it
// out after scrolling, then let the adjustment settle.
const settle = async (el) => {
if (el) {
el.style.display = 'none'
void el.offsetHeight
el.style.display = ''
}
await raf()
await new Promise((r) => setTimeout(r, 60))
await raf()
}
// Assert geometry once layout settles. Each anchor is scrolled into view
// first: `position: fixed` + `anchor-center` is viewport-relative, so an
// off-screen anchor would clamp the floating element (expected CSS
// behavior — tooltips are only shown when their anchor is visible).
async function check() {
const T = 2 // px tolerance
const results = []
for (const { placement, btn, float } of pairs) {
btn.scrollIntoView({ block: 'center', inline: 'center' })
await settle(float)
const a = btn.getBoundingClientRect()
const f = float.getBoundingClientRect()
const [side, align] = placement.split('-')
const fails = []
// primary side (8px gap)
if (side === 'top' && !(f.bottom <= a.top + T)) fails.push(`not above (f.bottom=${f.bottom} a.top=${a.top})`)
if (side === 'bottom' && !(f.top >= a.bottom - T)) fails.push(`not below (f.top=${f.top} a.bottom=${a.bottom})`)
if (side === 'left' && !(f.right <= a.left + T)) fails.push(`not left (f.right=${f.right} a.left=${a.left})`)
if (side === 'right' && !(f.left >= a.right - T)) fails.push(`not right (f.left=${f.left} a.right=${a.right})`)
// gap ~8px on the primary axis
const gap =
side === 'top' ? a.top - f.bottom :
side === 'bottom' ? f.top - a.bottom :
side === 'left' ? a.left - f.right :
f.left - a.right
if (Math.abs(gap - 8) > T) fails.push(`gap=${gap.toFixed(1)} expected ~8`)
// cross-axis alignment
const blockAxis = side === 'top' || side === 'bottom'
if (!align) {
// centered
const ac = blockAxis ? (a.left + a.right) / 2 : (a.top + a.bottom) / 2
const fc = blockAxis ? (f.left + f.right) / 2 : (f.top + f.bottom) / 2
if (Math.abs(ac - fc) > T) fails.push(`not centered (Δ=${(ac - fc).toFixed(1)})`)
} else if (blockAxis) {
if (align === 'start' && Math.abs(f.left - a.left) > T) fails.push(`start edge Δ=${(f.left - a.left).toFixed(1)}`)
if (align === 'end' && Math.abs(f.right - a.right) > T) fails.push(`end edge Δ=${(f.right - a.right).toFixed(1)}`)
} else {
if (align === 'start' && Math.abs(f.top - a.top) > T) fails.push(`start edge Δ=${(f.top - a.top).toFixed(1)}`)
if (align === 'end' && Math.abs(f.bottom - a.bottom) > T) fails.push(`end edge Δ=${(f.bottom - a.bottom).toFixed(1)}`)
}
if (fails.length) {
fails.push(`ctx scrollY=${window.scrollY} a=[${a.top.toFixed(0)},${a.bottom.toFixed(0)}] f=[${f.top.toFixed(0)},${f.bottom.toFixed(0)}]`)
}
results.push({ placement, ok: fails.length === 0, fails })
}
// The 12 placement pairs are `position: fixed`, so once we scroll past
// them the browser clamps their floating boxes into view, where they'd
// sit on top of the corridor and spoil the hit test. They're measured
// by now — take them out.
for (const { wrap } of pairs) wrap.style.display = 'none'
await raf()
// The safe area must fill the gap exactly on the placement's own axis
// and cover both boxes on the cross axis.
const safeResults = []
for (const { placement, btn, float, safe } of safePairs) {
btn.scrollIntoView({ block: 'center', inline: 'center' })
await settle(float)
const a = btn.getBoundingClientRect()
const f = float.getBoundingClientRect()
const s = safe.getBoundingClientRect()
const blockAxis = placement === 'top' || placement === 'bottom'
const near = (x, y, label) => (Math.abs(x - y) > T ? [`${label} Δ=${(x - y).toFixed(1)}`] : [])
const fails = blockAxis
? [
...near(s.top, Math.min(a.bottom, f.bottom), 'gap top'),
...near(s.bottom, Math.max(a.top, f.top), 'gap bottom'),
...near(s.left, Math.min(a.left, f.left), 'union left'),
...near(s.right, Math.max(a.right, f.right), 'union right'),
]
: [
...near(s.left, Math.min(a.right, f.right), 'gap left'),
...near(s.right, Math.max(a.left, f.left), 'gap right'),
...near(s.top, Math.min(a.top, f.top), 'union top'),
...near(s.bottom, Math.max(a.bottom, f.bottom), 'union bottom'),
]
// …and it has to be hit-testable, or it isn't a hover corridor.
const mid = { x: (s.left + s.right) / 2, y: (s.top + s.bottom) / 2 }
if (document.elementFromPoint(mid.x, mid.y) !== safe) {
const hit = document.elementFromPoint(mid.x, mid.y)
fails.push(`not hit-testable at its center (got ${hit ? hit.className || hit.tagName : 'null'} @ ${mid.x.toFixed(0)},${mid.y.toFixed(0)}; safe=${JSON.stringify({l:s.left,t:s.top,w:s.width,h:s.height})})`)
}
safeResults.push({ placement, ok: fails.length === 0, fails })
}
// --- arrow: the box is centred on the floating element's facing edge
// (main axis) and on the anchor's centre (cross axis), whatever its
// size, and it is painted *above* the surface rather than under it.
for (const { float } of safePairs) float.style.display = 'none'
await raf()
const effectiveSide = (a, f) =>
f.top >= a.bottom - T ? 'bottom'
: f.bottom <= a.top + T ? 'top'
: f.left >= a.right - T ? 'right'
: 'left'
async function checkArrow({ placement, size, btn, float, arrow }, scroll) {
if (scroll !== false) {
btn.scrollIntoView({ block: 'center', inline: 'center' })
await settle(float)
}
const a = btn.getBoundingClientRect()
const f = float.getBoundingClientRect()
const r = arrow.getBoundingClientRect()
const side = effectiveSide(a, f)
const blockAxis = side === 'top' || side === 'bottom'
const fails = []
// 1. Centred on the edge that faces the anchor — so exactly half of it
// sticks out, at any size.
const facing =
side === 'bottom' ? f.top : side === 'top' ? f.bottom :
side === 'right' ? f.left : f.right
const main = blockAxis ? (r.top + r.bottom) / 2 : (r.left + r.right) / 2
if (Math.abs(main - facing) > T) fails.push(`not on the facing edge (Δ=${(main - facing).toFixed(1)})`)
// 2. Still pointing at the anchor on the cross axis, even when the
// floating box is edge-aligned.
const ac = blockAxis ? (a.left + a.right) / 2 : (a.top + a.bottom) / 2
const rc = blockAxis ? (r.left + r.right) / 2 : (r.top + r.bottom) / 2
if (Math.abs(rc - ac) > T) fails.push(`not centred on the anchor (Δ=${(rc - ac).toFixed(1)})`)
// 3. The half outside the surface is really painted there. A sibling
// arrow would be under the surface's box-shadow; a child is not.
const out = size / 4
const tip = blockAxis
? { x: rc, y: side === 'bottom' ? main - out : main + out }
: { x: side === 'right' ? main - out : main + out, y: rc }
const hit = document.elementFromPoint(tip.x, tip.y)
if (hit !== arrow) fails.push(`tip not on top (got ${hit ? hit.className || hit.tagName : 'null'})`)
return { placement, size, side, fails }
}
const arrowResults = []
for (const pair of arrowPairs) {
const { placement, side, fails } = await checkArrow(pair)
if (side !== placement.split('-')[0]) fails.push(`flipped unexpectedly to ${side}`)
arrowResults.push({ name: `${placement} @${pair.size}px`, ok: fails.length === 0, fails })
}
for (const { wrap } of arrowPairs) wrap.style.display = 'none'
await raf()
const arrowLateResults = []
for (const { placement, anchorName, btn, wrap } of lateSpecs) {
btn.scrollIntoView({ block: 'center', inline: 'center' })
await raf()
// Only now does the floating element (and its arrow) come into
// existence — the page is already scrolled underneath it.
const styles = buildAnchorStyles(anchorName, { placement, offset: 16, flip: false })
const float = document.createElement('div')
float.className = 'float'
float.textContent = placement
const arrow = document.createElement('div')
arrow.className = 'arrow'
arrow.style.width = '12px'
arrow.style.height = '12px'
Object.assign(float.style, styles.floating)
Object.assign(arrow.style, styles.arrow)
float.append(arrow)
wrap.append(float)
await settle(null)
const { fails } = await checkArrow({ placement, size: 12, btn, float, arrow }, false)
arrowLateResults.push({ name: `${placement}, mounted at scrollY=${Math.round(window.scrollY)}`, ok: fails.length === 0, fails })
wrap.style.display = 'none'
}
await raf()
// --- containing-block traps: ancestor declarations that capture a
// `position: fixed` floating element. The gap must survive all of them
// (`anchor()` resolves correctly no matter which box it measures from),
// but a capturing ancestor that also clips makes the floating element
// vanish — which is what `findContainingBlockTrap` is there to predict.
const TRAPS = [
{ name: 'transform', css: 'transform: translateZ(0)', property: 'transform', clips: false },
{ name: 'filter', css: 'filter: blur(0px)', property: 'filter', clips: false },
{ name: 'will-change', css: 'will-change: transform', property: 'will-change', clips: false },
{ name: 'backdrop-filter', css: 'backdrop-filter: blur(1px)', property: 'backdrop-filter', clips: false },
{ name: 'contain:layout', css: 'contain: layout', property: 'contain', clips: false },
{ name: 'contain:paint', css: 'contain: paint', property: 'contain', clips: true },
{ name: 'contain:strict', css: 'contain: strict', property: 'contain', clips: true },
{ name: 'contain:content', css: 'contain: content', property: 'contain', clips: true },
{ name: 'content-visibility', css: 'content-visibility: auto; contain-intrinsic-size: 200px 40px', property: 'content-visibility', clips: true },
{ name: 'transform+overflow', css: 'transform: translateZ(0); overflow: hidden', property: 'transform', clips: true },
// Not a trap, despite reading like one: no `container-type` value and
// no size/style-only containment moves the containing block.
{ name: 'container-type', css: 'container-type: inline-size', property: null, clips: false },
{ name: 'contain:size style', css: 'contain: size style; height: 40px', property: null, clips: false },
{ name: 'overflow:hidden', css: 'overflow: hidden', property: null, clips: false },
]
function buildTrapPair(trap, i, topLayer) {
const wrap = document.createElement('div')
wrap.className = 'trap'
wrap.style.cssText += ';' + trap.css
const anchorName = `--cak-t${topLayer ? 'p' : ''}${i}`
const btn = document.createElement('button')
btn.className = 'anchor'
btn.textContent = trap.name
const float = document.createElement('div')
float.className = 'float'
float.textContent = trap.name
if (topLayer) {
float.setAttribute('popover', 'manual')
// Same neutralization PopoverContent applies: the UA stylesheet's
// `inset: 0` would otherwise outrank the kit's anchor() insets.
float.style.inset = 'auto'
}
const styles = buildAnchorStyles(anchorName, {
placement: 'bottom',
offset: 8,
flip: false,
})
Object.assign(btn.style, styles.anchor)
Object.assign(float.style, styles.floating)
// Only on the top-layer pairs: inside a trap Safari resolves an
// `anchor()` naming anything but the element's own `position-anchor`
// against the wrong origin, and the arrow measures off the floating
// box. The top layer is the documented fix for traps — this asserts
// it fixes the arrow too, not just the floating element.
let arrow = null
if (topLayer) {
arrow = document.createElement('div')
arrow.className = 'arrow'
arrow.style.width = '12px'
arrow.style.height = '12px'
Object.assign(arrow.style, styles.arrow)
float.append(arrow)
}
wrap.append(btn, float)
root.append(wrap)
return { wrap, btn, float, arrow }
}
const trapPairs = TRAPS.map((trap, i) => ({ trap, ...buildTrapPair(trap, i, false) }))
const topLayerPairs = TRAPS.map((trap, i) => ({ trap, ...buildTrapPair(trap, i, true) }))
for (const { wrap } of topLayerPairs) wrap.style.display = 'none'
// Room below the last panel, or `scrollIntoView({ block: 'center' })`
// can't centre it and its floating box falls past the viewport edge,
// where `elementFromPoint` reports nothing and the hit test is a lie.
const trapSpacer = document.createElement('div')
trapSpacer.style.height = '1200px'
root.append(trapSpacer)
await raf()
/** Is the floating box actually painted where it was placed? */
const hitTest = (float) => {
const f = float.getBoundingClientRect()
const hit = document.elementFromPoint(f.left + f.width / 2, f.top + f.height / 2)
return hit === float ? null : hit ? hit.className || hit.tagName : 'nothing'
}
const trapResults = []
for (const { trap, btn, float } of trapPairs) {
btn.scrollIntoView({ block: 'center', inline: 'center' })
await settle(float)
const a = btn.getBoundingClientRect()
const f = float.getBoundingClientRect()
const fails = []
// 1. `anchor()` itself is never the casualty: the gap holds in every
// containing block.
const gap = f.top - a.bottom
if (Math.abs(gap - 8) > T) fails.push(`gap=${gap.toFixed(1)} expected ~8`)
// 2. The documented visual outcome.
const clippedBy = hitTest(float)
if (trap.clips && !clippedBy) fails.push('expected to be clipped away, but it is visible')
if (!trap.clips && clippedBy) fails.push(`unexpectedly clipped (hit ${clippedBy})`)
// 3. …and the runtime detector agrees with the browser.
const detected = findContainingBlockTrap(btn)
if ((detected?.property ?? null) !== trap.property) {
fails.push(`detector said ${detected?.property ?? 'no trap'}, expected ${trap.property ?? 'no trap'}`)
}
if ((detected?.clips ?? false) !== trap.clips) {
fails.push(`detector clips=${detected?.clips ?? false}, expected ${trap.clips}`)
}
trapResults.push({ name: trap.name, ok: fails.length === 0, fails })
}
for (const { wrap } of trapPairs) wrap.style.display = 'none'
for (const { wrap } of topLayerPairs) wrap.style.display = ''
await raf()
// The fix: the same traps, with the floating element in the top layer.
// Nothing should be clipped and everything should still be centered.
const topLayerResults = []
for (const { trap, btn, float, arrow } of topLayerPairs) {
btn.scrollIntoView({ block: 'center', inline: 'center' })
float.showPopover()
await settle(null)
const a = btn.getBoundingClientRect()
const f = float.getBoundingClientRect()
const fails = []
const gap = f.top - a.bottom
if (Math.abs(gap - 8) > T) fails.push(`gap=${gap.toFixed(1)} expected ~8`)
const dx = (f.left + f.right) / 2 - (a.left + a.right) / 2
if (Math.abs(dx) > T) fails.push(`not centered (Δ=${dx.toFixed(1)})`)
const clippedBy = hitTest(float)
if (clippedBy) fails.push(`clipped even in the top layer (hit ${clippedBy})`)
// The arrow rides along: centred on the surface's facing edge, still
// pointing at the anchor, still painted on top.
const r = arrow.getBoundingClientRect()
const arrowMain = (r.top + r.bottom) / 2
if (Math.abs(arrowMain - f.top) > T) fails.push(`arrow off the facing edge (Δ=${(arrowMain - f.top).toFixed(1)})`)
const arrowDx = (r.left + r.right) / 2 - (a.left + a.right) / 2
if (Math.abs(arrowDx) > T) fails.push(`arrow not centred on the anchor (Δ=${arrowDx.toFixed(1)})`)
const tipHit = document.elementFromPoint((r.left + r.right) / 2, arrowMain - 3)
if (tipHit !== arrow) fails.push(`arrow tip not on top (got ${tipHit ? tipHit.className || tipHit.tagName : 'null'})`)
float.hidePopover()
topLayerResults.push({ name: trap.name, ok: fails.length === 0, fails })
}
window.__verify = {
supported: isAnchorPositioningSupported(),
results,
passed: results.filter((r) => r.ok).length,
total: results.length,
safeArea: {
results: safeResults,
passed: safeResults.filter((r) => r.ok).length,
total: safeResults.length,
},
arrow: {
results: arrowResults,
passed: arrowResults.filter((r) => r.ok).length,
total: arrowResults.length,
},
arrowMountedScrolled: {
results: arrowLateResults,
passed: arrowLateResults.filter((r) => r.ok).length,
total: arrowLateResults.length,
},
containingBlockTraps: {
results: trapResults,
passed: trapResults.filter((r) => r.ok).length,
total: trapResults.length,
},
topLayerEscapes: {
results: topLayerResults,
passed: topLayerResults.filter((r) => r.ok).length,
total: topLayerResults.length,
},
}
window.__verifyDone = true
}
check()
</script>
</body>
</html>