Skip to content

Commit 188ebcc

Browse files
committed
fix(engine): preserve GSAP-applied opacity across DOM-layer captures
SDR clips inside an HDR composition were rendering at full opacity even when the user had animated their wrapper opacity (e.g. fade-in or yoyo). Two bugs in the per-layer screenshot path conspired to drop the GSAP-applied opacity on the floor: 1. removeDomLayerMask was unconditionally calling `el.style.removeProperty("opacity")` on every wrapper after each layer capture. applyDomLayerMask only ever sets `visibility`, so the only inline opacity present is the value GSAP wrote. Stripping it between layer captures means that on the next capture (at the same timestamp), GSAP's `totalTime(t, false)` no-ops because the timeline is already at that time — the opacity is never restored, and the wrapper renders fully opaque. 2. injectVideoFramesBatch was reading the source <video>'s computed opacity via `parseFloat(computedStyle.opacity) || 1` and copying it onto the injected <img>. Because syncVideoFrameVisibility forces the <video> to `opacity: 0 !important` to hide it during capture, the computed value is always 0, which `|| 1` then silently flips to full opacity. The <img> is a sibling of the <video> inside the same wrapper, so it should inherit opacity from the wrapper directly instead of having a value hard-set on it. Fix both: drop the opacity removal in removeDomLayerMask, skip opacity when copying visual properties from <video> to <img>, and explicitly clear any stale inline opacity on the <img> so it inherits from the wrapper that GSAP is animating. Made-with: Cursor
1 parent cbd6cb1 commit 188ebcc

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎packages/engine/src/services/screenshotService.ts‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,16 @@ export async function applyDomLayerMask(
331331
/**
332332
* Tear down the mask installed by applyDomLayerMask.
333333
*
334-
* Removes the mask stylesheet and clears the inline `visibility`/`opacity`
335-
* properties set on `extraHideIds` (and their `__render_frame_*` siblings).
336-
* Inline values are removed rather than restored — `injectVideoFramesBatch`
337-
* and `syncVideoFrameVisibility` re-apply the correct inline values for
338-
* native videos and injected imgs at the start of every frame, so subsequent
339-
* captures get a clean slate.
334+
* Removes the mask stylesheet and clears the inline `visibility` properties
335+
* set on `extraHideIds` (and their `__render_frame_*` siblings).
336+
*
337+
* IMPORTANT: We do NOT strip inline `opacity` here. applyDomLayerMask only
338+
* ever sets `visibility` (never `opacity`), so any inline opacity present on
339+
* a wrapper was put there by user animation code (typically GSAP) and must
340+
* survive across per-layer captures. GSAP's seek with suppress-events does
341+
* not re-apply tweens when the timeline is already at the target time, so if
342+
* we strip opacity here and then seek to the same time for the next layer,
343+
* GSAP won't put it back and the wrapper will render fully opaque.
340344
*/
341345
export async function removeDomLayerMask(page: Page, extraHideIds: string[]): Promise<void> {
342346
await page.evaluate(
@@ -347,7 +351,6 @@ export async function removeDomLayerMask(page: Page, extraHideIds: string[]): Pr
347351
const el = document.getElementById(id);
348352
if (el) {
349353
el.style.removeProperty("visibility");
350-
el.style.removeProperty("opacity");
351354
}
352355
const img = document.getElementById(`__render_frame_${id}__`);
353356
if (img) img.style.removeProperty("visibility");
@@ -372,7 +375,6 @@ export async function injectVideoFramesBatch(
372375
let img = video.nextElementSibling as HTMLImageElement | null;
373376
const isNewImage = !img || !img.classList.contains("__render_frame__");
374377
const computedStyle = window.getComputedStyle(video);
375-
const computedOpacity = parseFloat(computedStyle.opacity) || 1;
376378
const sourceIsStatic = !computedStyle.position || computedStyle.position === "static";
377379

378380
if (isNewImage) {
@@ -408,6 +410,13 @@ export async function injectVideoFramesBatch(
408410
img.style.zIndex = computedStyle.zIndex;
409411

410412
for (const property of visualProperties) {
413+
// Skip opacity — the <video> is forced to opacity:0 !important below
414+
// (and by syncVideoFrameVisibility) to hide it during capture, so its
415+
// computed opacity is not the user's intent. The injected <img> is a
416+
// sibling of the <video> inside the same wrapper, so it inherits the
417+
// wrapper's opacity (where GSAP applies animated values) just like
418+
// the <video> would have.
419+
if (property === "opacity") continue;
411420
if (
412421
sourceIsStatic &&
413422
(property === "top" ||
@@ -431,8 +440,8 @@ export async function injectVideoFramesBatch(
431440
.catch(() => undefined)
432441
.then(() => undefined),
433442
);
434-
img.style.opacity = String(computedOpacity);
435443
img.style.visibility = "visible";
444+
img.style.removeProperty("opacity");
436445
video.style.setProperty("visibility", "hidden", "important");
437446
video.style.setProperty("opacity", "0", "important");
438447
video.style.setProperty("pointer-events", "none", "important");

0 commit comments

Comments
 (0)