Skip to content

Masks: re-read boxes at every shot, clip to overflow, cover overflowing children - #86

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-72-mask-geometry
Oct 29, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-72-mask-geometry

Conversation

@tmashara

Copy link
Copy Markdown
Owner

Three fixes to where a mask is painted, all in src/capture.ts.

What and why

1. Boxes are re-read at every shot. Mask boxes were read once, after settle, and that rect was painted in every stability attempt. Anything that re-lays out after the read (a ScrollTrigger pin refreshing after scrollTo(0,0)) was painted at its old position, so the masked content leaked. shoot() now reads the boxes right before and right after each screenshot and paints both sets, so a box that moves while the shot is taken stays covered. A box that moves between attempts makes the painted shots differ, so the existing stability loop marks old and new rects unstable instead of painting a stale rect. The tiled path, recheck and the #83 retry all go through capture() and get this too.

2. Masks are clipped to their overflow ancestors. A masked element taller than its overflow:hidden wrapper was painted at its full box, covering content outside the wrapper that both sides render. The in-page read now cuts each rect to the border box of every ancestor that clips it (per axis; skipping inline/display:contents ancestors, honouring the containing block of absolute and fixed boxes, stopping at body so the viewport edge does the rest).

3. A mask covers what its children paint outside its box. Masking a video.js player left its poster (positioned above the player) unmasked, which needed a second mask on every page. Every visible descendant that paints outside the element now gets its own rect, each clipped by its own ancestors (a carousel track's off-screen slides aren't painted) and dropped if it ends up inside the element's box. checkVisibility({ opacityProperty, visibilityProperty }) excludes opacity:0 / visibility:hidden descendants (a closed dropdown under a masked header). Always on; no option.

To keep (3) cheap, paintBoxes fills raw pixels instead of compositing one sharp input per rect.

What stays as today

  • Frame masks: a mask whose locate returns a locator inside a frame gets frame-viewport coordinates from an in-page read, so maskRects returns null there and that locator falls back to today's boundingBox() (no clip, no descendants). --mask-media masks the iframe element in the main frame, so it takes the new path.
  • The text read (hide masks, read innerText, restore), masksFor, and locate/snapshot (which already skip the whole masked subtree) are untouched.
  • Text nodes that overflow without an element box, and shadow-root descendants, are not covered (same as today).

Performance

paintBoxes on a 1440×20000 PNG (this machine):

rects composite (before) raw fill (now)
50 82 ms 56 ms
500 726 ms 57 ms
5000 47.7 s (measured during planning) 65 ms

The in-page read: 5 ms for a 5k-node masked subtree, 30–38 ms for 50k nodes; ×2 reads ×≤3 attempts, so at most ~0.25 s per shot on a very large mask. The full visual suite took ≈143 s here with this change (not compared against main).

Behaviour change

Mask pixels change: masks now grow by what their children paint outside them and shrink where an overflow ancestor clips them. Accepted-diff entries that cover a masked area may stop matching and need re-accepting — in CI, since hashes recorded on macOS don't match Linux.

How tested

New guard-rail fixture tests/fixtures/pages/mask-geometry and config tests/fixtures/configs/mask-geometry.mjs, with two tests in tests/visual/guardrails.test.ts (masks): unmasked it differs; masked it reaches diffPixels === 0, plus six pixel probes per side. Each part was checked to bite by reverting just that part:

variant exit / diff probe that catches it
main 1 / 194 px moved box not magenta, below-wrapper magenta, poster not magenta
no re-read (one read before the loop) 1 / 97 px moved box not magenta
no clipping 0 / 0 below-wrapper pixel and clipped slide magenta
no descendants 1 / 97 px poster strip not magenta
no checkVisibility 0 / 0 opacity:0 menu magenta
this PR 0 / 0 all six pass

npm run typecheck, lint, format:check, npm test (314) and npm run test:visual (339) pass.

Fixes #72

🤖 Generated with Claude Code

tmashara and others added 2 commits October 29, 2026 19:36
…ng children

Fixes #72

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A box-less display:contents ancestor with a position set made an absolute
mask look clipped by overflow ancestors it escapes, so the mask came out empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara force-pushed the claude/issue-72-mask-geometry branch from c6252ec to fd9de67 Compare October 29, 2026 18:39
@tmashara
tmashara merged commit 7516d8d into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-72-mask-geometry branch October 29, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Masks: re-read boxes before each shot, clip to overflow, cover overflowing descendants

1 participant