diff --git a/packages/core/src/runtime/captureMotionBlur/frames.ts b/packages/core/src/runtime/captureMotionBlur/frames.ts index f4936816f0..052566e2ac 100644 --- a/packages/core/src/runtime/captureMotionBlur/frames.ts +++ b/packages/core/src/runtime/captureMotionBlur/frames.ts @@ -53,8 +53,32 @@ function growToRect(box: Box, back: Affine, r: DOMRect): void { } } +const POSITIONED = new Set(["absolute", "fixed"]); +const NO_CONTENT = new Set(["none", "normal"]); + +function pseudoBox(el: HTMLElement, which: "::before" | "::after"): Box | null { + const cs = getComputedStyle(el, which); + if (NO_CONTENT.has(cs.content) || !POSITIONED.has(cs.position)) return null; + const left = parseFloat(cs.left) + el.clientLeft; + const top = parseFloat(cs.top) + el.clientTop; + const width = parseFloat(cs.width); + const height = parseFloat(cs.height); + if (![left, top, width, height].every(Number.isFinite)) return null; + return [left, top, left + width, top + height]; +} + +function growToBox(box: Box, other: Box | null): void { + if (!other) return; + box[0] = Math.min(box[0], other[0]); + box[1] = Math.min(box[1], other[1]); + box[2] = Math.max(box[2], other[2]); + box[3] = Math.max(box[3], other[3]); +} + function grownBox(el: HTMLElement, pose: Affine, scene: HTMLElement, frameW: number): Box { const box: Box = [0, 0, el.offsetWidth, el.offsetHeight]; + growToBox(box, pseudoBox(el, "::before")); + growToBox(box, pseudoBox(el, "::after")); const back = clientToMover(pose, scene, frameW); if (!back) return box; const own = el.getBoundingClientRect(); diff --git a/packages/engine/src/services/__fixtures__/motionBlur/sweepFixtures.ts b/packages/engine/src/services/__fixtures__/motionBlur/sweepFixtures.ts index 297ae7dddd..25c6c5f067 100644 --- a/packages/engine/src/services/__fixtures__/motionBlur/sweepFixtures.ts +++ b/packages/engine/src/services/__fixtures__/motionBlur/sweepFixtures.ts @@ -105,6 +105,10 @@ const SWEEP_FIXTURES = [ name: "pseudo-after", css: ".m::after { content: ''; position: absolute; left: 130px; top: 10px; width: 60px; height: 60px; background: #ffd166; border-radius: 50% }", }), + sweepFixture({ + name: "pseudo-before", + css: ".m::before { content: ''; position: absolute; left: -90px; top: 10px; width: 60px; height: 60px; background: #ffd166; border-radius: 50% }", + }), // E: the mover's own clip-path. sweepFixture({ name: "own-clip-polygon", diff --git a/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts b/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts index 906d4ae4ad..d71b402cd4 100644 --- a/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts +++ b/packages/engine/src/services/__fixtures__/motionBlur/thresholds.ts @@ -52,8 +52,6 @@ export const SWEEP_SYMPTOMS = { A: 47.67, B: 148.63, C: 73.02, - D_CAPTURE: 107.66, - D_FILTER: 107.66, E: 27.6, F_CAPTURE: 40.62, H: 135.67, diff --git a/packages/engine/src/services/captureMotionBlur.sweep.browser.test.ts b/packages/engine/src/services/captureMotionBlur.sweep.browser.test.ts index 54fdd6a14e..fbcb152443 100644 --- a/packages/engine/src/services/captureMotionBlur.sweep.browser.test.ts +++ b/packages/engine/src/services/captureMotionBlur.sweep.browser.test.ts @@ -115,19 +115,10 @@ const CASES: readonly SweepCase[] = [ measuredMae: S.C, }, }, - ...(["capture", "filter"] as const).map( - (tier): SweepCase => ({ - fixture: "pseudo-after", - tier, - frame: 14, - check: "inside", - bug: { - finding: "D", - reason: "an ::after drawn outside the mover's box is cut off", - regions: [rect(376, 150, 72, 68)], - measuredMae: tier === "capture" ? S.D_CAPTURE : S.D_FILTER, - }, - }), + ...(["pseudo-after", "pseudo-before"] as const).flatMap((fixture) => + (["capture", "filter"] as const).map( + (tier): SweepCase => ({ fixture, tier, frame: 14, check: "inside" }), + ), ), { fixture: "own-clip-polygon",