From 889143eac9b545c796cb74d44e3ba36807018a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Mon, 16 Nov 2026 07:06:33 +0000 Subject: [PATCH] fix(core): a color-graded video's dissolve and wipe play in preview and export (#7756) * fix(core): a graded video's opacity animation reaches its export * fix(core): a graded clip keeps its own clip-path, so it never renders black * test(producer): golden render of graded video dissolve and wipe * fix(core): a graded clip stays clickable in the preview, hidden by a filter not a clip * chore(studio): drop an import the reader no longer uses, and format the graded fixture --- .github/workflows/ci.yml | 5 + .../core/src/runtime/colorGrading.test.ts | 99 ++++++-------- packages/core/src/runtime/colorGrading.ts | 123 ++++++------------ .../src/services/screenshotService.test.ts | 12 +- .../engine/src/services/screenshotService.ts | 17 +-- .../tests/graded-video-transitions/meta.json | 13 ++ .../output/compiled.html | 3 + .../output/output.mp4 | 3 + .../src/assets/blue.mp4 | 3 + .../src/assets/green.mp4 | 3 + .../src/assets/red.mp4 | 3 + .../graded-video-transitions/src/index.html | 56 ++++++++ packages/producer/tests/shard-schedule.json | 1 + packages/studio/src/hooks/gsapRuntimePatch.ts | 5 +- .../src/hooks/gsapRuntimeReaders.test.ts | 45 +------ .../studio/src/hooks/gsapRuntimeReaders.ts | 30 +---- packages/studio/src/utils/gsapSoftReload.ts | 16 +-- .../graded-video-transitions/assets/blue.mp4 | Bin 0 -> 5779 bytes .../graded-video-transitions/assets/green.mp4 | Bin 0 -> 3665 bytes .../graded-video-transitions/assets/red.mp4 | Bin 0 -> 5779 bytes .../graded-video-transitions/hyperframes.json | 8 ++ .../graded-video-transitions/index.html | 93 +++++++++++++ .../tests/e2e/graded-video-transitions.mjs | 117 +++++++++++++++++ 23 files changed, 409 insertions(+), 246 deletions(-) create mode 100644 packages/producer/tests/graded-video-transitions/meta.json create mode 100644 packages/producer/tests/graded-video-transitions/output/compiled.html create mode 100644 packages/producer/tests/graded-video-transitions/output/output.mp4 create mode 100644 packages/producer/tests/graded-video-transitions/src/assets/blue.mp4 create mode 100644 packages/producer/tests/graded-video-transitions/src/assets/green.mp4 create mode 100644 packages/producer/tests/graded-video-transitions/src/assets/red.mp4 create mode 100644 packages/producer/tests/graded-video-transitions/src/index.html create mode 100644 packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/blue.mp4 create mode 100644 packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/green.mp4 create mode 100644 packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/red.mp4 create mode 100644 packages/studio/tests/e2e/fixtures/graded-video-transitions/hyperframes.json create mode 100644 packages/studio/tests/e2e/fixtures/graded-video-transitions/index.html create mode 100644 packages/studio/tests/e2e/graded-video-transitions.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0255de1a06..042006a818 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1181,6 +1181,11 @@ jobs: node packages/studio/tests/e2e/timeline-snap-release.mjs || rc=1 STUDIO_URL="http://localhost:5316/#project/aroll-backdrop" \ node packages/studio/tests/e2e/aroll-backdrop.mjs || rc=1 + rm -rf packages/studio/data/projects/graded-video-transitions + cp -R packages/studio/tests/e2e/fixtures/graded-video-transitions \ + packages/studio/data/projects/graded-video-transitions + STUDIO_URL="http://localhost:5316/#project/graded-video-transitions" \ + node packages/studio/tests/e2e/graded-video-transitions.mjs || rc=1 exit "$rc" - name: Measure the caret of a text edited in place if: success() || failure() diff --git a/packages/core/src/runtime/colorGrading.test.ts b/packages/core/src/runtime/colorGrading.test.ts index 6a59ba09b5..6e0e05d296 100644 --- a/packages/core/src/runtime/colorGrading.test.ts +++ b/packages/core/src/runtime/colorGrading.test.ts @@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { mediaElementTime } from "./mediaClock"; import { PREVIEW_SEEK_HOLD_ATTR } from "../studioPreviewMark"; import { + COLOR_GRADING_SOURCE_HIDDEN_ATTR, HF_COLOR_GRADING_ATTR, HF_COLOR_GRADING_EFFECT_KEYS, serializeHfColorGrading, @@ -312,34 +313,30 @@ describe("createColorGradingRuntime", () => { runtime?.redraw(); } - it("restores the authored inline opacity captured before animation transients", () => { + it("hides its source without touching the source's own opacity, which the canvas copies", () => { const video = makeDrawableVideo(); - // Parse-time capture stamped the authored value; by hide time GSAP has - // already left a from()-tween transient (0) in the inline style. - video.setAttribute("data-hf-authored-opacity", "0.75"); - video.style.opacity = "0"; - startRuntimeWithVideo(video); + video.style.opacity = "0.75"; + const { canvas } = startRuntimeWithVideo(video); - expect(video.style.getPropertyPriority("opacity")).toBe("important"); - - runtime?.destroy(); - runtime = null; - - // Restore must use the authored 0.75, not the GSAP transient 0. + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); expect(video.style.getPropertyValue("opacity")).toBe("0.75"); expect(video.style.getPropertyPriority("opacity")).toBe(""); - }); - - it("restores no inline opacity when the authored capture recorded none", () => { - const video = makeDrawableVideo(); - video.setAttribute("data-hf-authored-opacity", ""); - video.style.opacity = "0"; - startRuntimeWithVideo(video); + expect(canvas.style.opacity).toBe("0.75"); runtime?.destroy(); runtime = null; - expect(video.style.getPropertyValue("opacity")).toBe(""); + expect(video.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe(false); + expect(video.style.getPropertyValue("opacity")).toBe("0.75"); + }); + + it("hides its source with a filter, keeping its hit area, with one rule for the whole document", () => { + startRuntimeWithVideo(); + const rules = [...document.querySelectorAll("style")].filter((style) => + style.textContent?.includes(`[${COLOR_GRADING_SOURCE_HIDDEN_ATTR}]`), + ); + expect(rules).toHaveLength(1); + expect(rules[0]?.textContent).toContain("filter: opacity(0) !important"); }); it("re-syncs the graded canvas when the source's inline transform changes", async () => { @@ -391,8 +388,7 @@ describe("createColorGradingRuntime", () => { expect(canvas.id).toBe("__hf_color_grading_hero-video"); expect(video.style.getPropertyValue("visibility")).toBe(""); - expect(video.style.getPropertyValue("opacity")).toBe("0"); - expect(video.style.getPropertyPriority("opacity")).toBe("important"); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); expect(video.hasAttribute("data-hf-color-grading-source-hidden")).toBe(true); expect(canvas?.style.visibility).toBe("visible"); expect(canvas?.style.opacity).toBe("1"); @@ -412,8 +408,7 @@ describe("createColorGradingRuntime", () => { expect(recreated).not.toBeNull(); expect(recreated).toBe(canvas); expect(webglContexts()).toBe(1); - expect(video.style.getPropertyValue("opacity")).toBe("0"); - expect(video.style.getPropertyPriority("opacity")).toBe("important"); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); }); it("draws every graded clip through one WebGL context, however often a seek run shows and hides them", () => { @@ -949,7 +944,7 @@ describe("createColorGradingRuntime", () => { expect(runtime.isGraded(canvas)).toBe(true); expect(runtime.getStatus("drawn")).toMatchObject({ state: "active" }); - expect(canvas.style.getPropertyValue("opacity")).toBe("0"); + expect(canvas.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); expect(canvasUploads(canvas)).toBe(1); expect(runtime.redrawAnimated()).toBe(1); @@ -1002,8 +997,7 @@ describe("createColorGradingRuntime", () => { runtime.redraw(); expect(canvas.style.display).toBe("block"); - expect(video.style.getPropertyValue("opacity")).toBe("0"); - expect(video.style.getPropertyPriority("opacity")).toBe("important"); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); }); it("caps a clip shown far larger than the screen to what a GPU can draw, keeping its shape", () => { @@ -1029,7 +1023,7 @@ describe("createColorGradingRuntime", () => { const { video } = startRuntimeWithVideo(); - expect(video.style.getPropertyValue("opacity")).not.toBe("0"); + expect(video.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe(false); }); it("gives a drawn clip back to its source when a later draw outgrows the drawing buffer", () => { @@ -1038,14 +1032,14 @@ describe("createColorGradingRuntime", () => { type === "webgl" ? createMockWebGl({ drawingBuffer }) : type === "2d" ? mock2d() : null, ); const { video, canvas } = startRuntimeWithVideo(); - expect(video.style.getPropertyValue("opacity")).toBe("0"); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); drawingBuffer.width = 100; drawingBuffer.height = 100; Object.defineProperty(video, "offsetWidth", { value: 3000, configurable: true }); video.dispatchEvent(new Event("seeked")); - expect(video.style.getPropertyValue("opacity")).not.toBe("0"); + expect(video.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe(false); expect(canvas.style.display).toBe("none"); }); @@ -1099,7 +1093,7 @@ describe("createColorGradingRuntime", () => { expect(canvas.style.opacity).toBe("0.75"); }); - it("drops the injected render frame's border while grading draws over it", () => { + it("hides the injected render frame while grading draws over it, and shows it after", () => { const video = makeDrawableVideo(); Object.defineProperty(video, "readyState", { value: HTMLMediaElement.HAVE_METADATA, @@ -1125,12 +1119,12 @@ describe("createColorGradingRuntime", () => { runtime.redraw(); expect(canvas.style.display).toBe("block"); - expect(frame.style.borderStyle).toBe("none"); + expect(frame.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); - video.style.border = "16px dashed rgb(255, 0, 0)"; video.removeAttribute(HF_COLOR_GRADING_ATTR); runtime.refresh(); - expect(frame.style.borderStyle).toBe("dashed"); + expect(frame.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe(false); + expect(frame.style.borderStyle).toBe("solid"); }); it("keeps a staged scene copy's canvas on its own render frame (#3994)", async () => { @@ -1199,7 +1193,6 @@ describe("createColorGradingRuntime", () => { runtime.redraw(); expect(canvas.style.visibility).toBe("visible"); - // Grading still owns the source's opacity hide, so the canvas keeps full opacity. expect(canvas.style.opacity).toBe("1"); }); @@ -1224,7 +1217,7 @@ describe("createColorGradingRuntime", () => { expect(runtime.isGraded(image)).toBe(true); expect(image.nextElementSibling?.hasAttribute("data-hf-color-grading-canvas")).toBe(true); - expect(image.style.getPropertyValue("opacity")).toBe("0"); + expect(image.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); }); it.each([ @@ -1251,34 +1244,16 @@ describe("createColorGradingRuntime", () => { expect(runtime.isGraded(image)).toBe(false); }); - it("updates canvas opacity through grading's own hide when CSS animation progresses (#3329)", () => { - const video = makeDrawableVideo(); - // Simulate a CSS entrance animation: the authored opacity is empty (no - // inline opacity), but at parse time the element has opacity 0 from the - // animation's initial keyframe. - video.setAttribute("data-hf-authored-opacity", ""); - document.body.appendChild(video); - - runtime = createColorGradingRuntime(); - const canvas = document.querySelector("[data-hf-color-grading-canvas]"); - if (!canvas) throw new Error("Expected color grading canvas"); - - // Source is hidden by color grading. - expect(video.style.getPropertyValue("opacity")).toBe("0"); - expect(video.style.getPropertyPriority("opacity")).toBe("important"); - - // The canvas opacity should NOT be frozen at "0" — after the hide is - // temporarily lifted, jsdom's getComputedStyle returns "" (no inline - // opacity set), which the code normalizes to "1". + it("copies the source's animated opacity to the canvas on every redraw (#3329)", () => { + const { video, canvas } = startRuntimeWithVideo(); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); expect(canvas.style.opacity).toBe("1"); - // Simulate the CSS animation progressing by re-reading after a redraw. - runtime.redraw(); - expect(canvas.style.opacity).toBe("1"); + video.style.opacity = "0.4"; + runtime?.redraw(); - // Source remains hidden throughout. - expect(video.style.getPropertyValue("opacity")).toBe("0"); - expect(video.style.getPropertyPriority("opacity")).toBe("important"); + expect(canvas.style.opacity).toBe("0.4"); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); }); it("allows a drawable producer render frame to initialize hidden source grading", () => { @@ -2324,7 +2299,7 @@ describe("createColorGradingRuntime", () => { expect(runtime?.getStatus("#hero-video").state).toBe("active"); expect(video.hasAttribute("data-hf-color-grading-source-hidden")).toBe(true); - expect(video.style.getPropertyValue("opacity")).toBe("0"); + expect(video.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)).toBe("true"); }); it("does not rescan the document when only text changes", async () => { diff --git a/packages/core/src/runtime/colorGrading.ts b/packages/core/src/runtime/colorGrading.ts index 4b43aa5f1f..8f0f470cb4 100644 --- a/packages/core/src/runtime/colorGrading.ts +++ b/packages/core/src/runtime/colorGrading.ts @@ -232,9 +232,7 @@ interface ColorGradingEntry extends ColorGradingRenderer { touchedParent: HTMLElement | null; parentInlinePosition: string | null; sourceHidden: boolean; - borderlessFrame: HTMLElement | null; - sourceInlineOpacity: string | null; - sourceInlineOpacityPriority: string; + hiddenFrame: HTMLElement | null; sourceOpacityForCanvas: string; sourceVisibleForCanvas: boolean; hasDrawn: boolean; @@ -2213,36 +2211,51 @@ function adoptContext( else drawEntry(entry); } -function hideFrameBorder(entry: ColorGradingEntry, frame: HTMLElement): void { - if (entry.borderlessFrame !== frame) restoreFrameBorder(entry); - entry.borderlessFrame = frame; - frame.style.borderStyle = "none"; +const HIDE_STYLE_ATTR = "data-hf-color-grading-hide"; + +// A hidden source keeps its own opacity, which the canvas copies, and its hit area, so a click still picks it. +function hideFromView(element: HTMLElement): void { + const doc = element.ownerDocument; + if (!doc.querySelector(`style[${HIDE_STYLE_ATTR}]`)) { + const style = doc.createElement("style"); + style.setAttribute(HIDE_STYLE_ATTR, ""); + style.textContent = `[${COLOR_GRADING_SOURCE_HIDDEN_ATTR}] { filter: opacity(0) !important; }`; + (doc.head ?? doc.documentElement).appendChild(style); + } + element.setAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR, "true"); } -function restoreFrameBorder(entry: ColorGradingEntry): void { - const frame = entry.borderlessFrame; - if (!frame) return; - entry.borderlessFrame = null; - frame.style.borderStyle = window.getComputedStyle(entry.element).borderStyle; +/** The filter the page gives `element`, read with grading's hide lifted for that one synchronous read. */ +function ownFilter(element: HTMLElement): string { + const sheet = element.ownerDocument.querySelector( + `style[${HIDE_STYLE_ATTR}]`, + )?.sheet; + if (!sheet || !element.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR)) { + return window.getComputedStyle(element).filter; + } + sheet.disabled = true; + try { + return window.getComputedStyle(element).filter; + } finally { + sheet.disabled = false; + } +} + +function hideFrame(entry: ColorGradingEntry, frame: HTMLElement): void { + if (entry.hiddenFrame !== frame) restoreFrame(entry); + entry.hiddenFrame = frame; + hideFromView(frame); +} + +function restoreFrame(entry: ColorGradingEntry): void { + entry.hiddenFrame?.removeAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR); + entry.hiddenFrame = null; } function restoreSourceElement(entry: ColorGradingEntry): void { - restoreFrameBorder(entry); + restoreFrame(entry); if (!entry.sourceHidden) return; entry.element.removeAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR); - const opacity = entry.element.style.getPropertyValue("opacity"); - const priority = entry.element.style.getPropertyPriority("opacity"); - if (opacity === "0" && priority === "important") { - if (entry.sourceInlineOpacity === null) { - entry.element.style.removeProperty("opacity"); - } else { - entry.element.style.setProperty( - "opacity", - entry.sourceInlineOpacity, - entry.sourceInlineOpacityPriority, - ); - } - } entry.sourceHidden = false; } @@ -2934,6 +2947,7 @@ function updateCanvasLayout( const computed = window.getComputedStyle(styleSource); copyMediaVisualStyles(canvas.style, computed); + canvas.style.filter = ownFilter(element); canvas.style.borderStyle = "none"; canvas.style.pointerEvents = "none"; canvas.style.position = "absolute"; @@ -3244,24 +3258,7 @@ function applyUniforms( } function hideSourceElement(entry: ColorGradingEntry): void { - if (!entry.sourceHidden) { - // Prefer the parse-time authored capture: by the time the first hide runs, - // the inline opacity is usually an animation-engine transient (a from() - // tween's 0 at playhead 0), and restoring THAT when grading is removed - // would leave the element invisible. Fall back to the live inline value - // for documents loaded without the capture installed. - // `null` = never captured; "" = captured, authored none (store as null). - const authored = entry.element.getAttribute(COLOR_GRADING_AUTHORED_OPACITY_ATTR); - if (authored !== null) { - entry.sourceInlineOpacity = authored === "" ? null : authored; - entry.sourceInlineOpacityPriority = ""; - } else { - entry.sourceInlineOpacity = entry.element.style.getPropertyValue("opacity") || null; - entry.sourceInlineOpacityPriority = entry.element.style.getPropertyPriority("opacity"); - } - } - entry.element.setAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR, "true"); - entry.element.style.setProperty("opacity", "0", "important"); + hideFromView(entry.element); entry.sourceHidden = true; } @@ -3434,50 +3431,18 @@ function drawableFrame(entry: ColorGradingEntry): DrawableFrame | null { return size ? { source, pixels, size } : null; } -function restoreAuthoredOpacity(entry: ColorGradingEntry): void { - if (entry.sourceInlineOpacity === null) { - entry.element.style.removeProperty("opacity"); - return; - } - entry.element.style.setProperty( - "opacity", - entry.sourceInlineOpacity, - entry.sourceInlineOpacityPriority || "", - ); -} - -function isHiddenByColorGrading(entry: ColorGradingEntry): boolean { - const { style } = entry.element; - return ( - entry.sourceHidden && - style.getPropertyValue("opacity") === "0" && - style.getPropertyPriority("opacity") === "important" - ); -} - function syncSourceAppearance( entry: ColorGradingEntry, source: TexImageSource, injectedFrameSource: boolean, ): void { - const hiddenByColorGrading = isHiddenByColorGrading(entry); const sourceVisibility = entry.element.style.getPropertyValue("visibility"); - // When color grading hid the source (opacity:0 !important), temporarily - // restore the authored inline opacity so getComputedStyle reflects the CSS - // animation's current value instead of our own hide. Without this, a CSS - // entrance animation (opacity: 0→1) freezes at its first-frame value for - // the entire render because the !important blocks all animation effects on - // the property (#3329). The restore–read–rehide is synchronous, so no - // repaint occurs between the style writes. - const restoresOpacity = hiddenByColorGrading && !injectedFrameSource; - if (restoresOpacity) restoreAuthoredOpacity(entry); const computed = window.getComputedStyle( injectedFrameSource ? (source as HTMLImageElement) : entry.element, ); // Grading never writes `visibility`, so the source's computed visibility // always tracks the clip window and has to be re-read every frame. entry.sourceOpacityForCanvas = computed.opacity || "1"; - if (restoresOpacity) entry.element.style.setProperty("opacity", "0", "important"); entry.sourceVisibleForCanvas = (injectedFrameSource || sourceVisibility !== "hidden") && computed.visibility !== "hidden"; } @@ -3574,7 +3539,7 @@ function drawEntry(entry: ColorGradingEntry): boolean { try { renderGradedFrame(entry, pixels, layout, uv); hideSourceElement(entry); - if (injectedFrameSource) hideFrameBorder(entry, source); + if (injectedFrameSource) hideFrame(entry, source); entry.hasDrawn = true; entry.drawError = null; return true; @@ -4034,9 +3999,7 @@ export function createColorGradingRuntime(pausedMediaLease?: { touchedParent: null, parentInlinePosition: null, sourceHidden: false, - borderlessFrame: null, - sourceInlineOpacity: null, - sourceInlineOpacityPriority: "", + hiddenFrame: null, sourceOpacityForCanvas: window.getComputedStyle(element).opacity || "1", sourceVisibleForCanvas: window.getComputedStyle(element).visibility !== "hidden", hasDrawn: false, diff --git a/packages/engine/src/services/screenshotService.test.ts b/packages/engine/src/services/screenshotService.test.ts index 892fc7f78a..63bdfc65f8 100644 --- a/packages/engine/src/services/screenshotService.test.ts +++ b/packages/engine/src/services/screenshotService.test.ts @@ -727,9 +727,9 @@ describe("video-frame injection respects ancestor visibility", () => { expect(sibling?.style.visibility).toBe("visible"); }); - it("does not copy color-grading source suppression opacity to the injected frame", async () => { + it("copies a color-graded video's animated opacity to the injected frame", async () => { const { teardown, setup } = withGlobals( - setupHostHiddenScenario({}, { videoStyle: { opacity: "0" } }), + setupHostHiddenScenario({}, { videoStyle: { opacity: "0.4" } }), ); setup.video.setAttribute("data-hf-color-grading-source-hidden", "true"); @@ -747,15 +747,15 @@ describe("video-frame injection respects ancestor visibility", () => { const sibling = setup.video.nextElementSibling as HTMLElement | null; expect(sibling?.classList.contains("__render_frame__")).toBe(true); - expect(sibling?.style.opacity).toBe("1"); + expect(sibling?.style.opacity).toBe("0.4"); }); - it("repairs stale injected-frame opacity while syncing color-graded active videos", async () => { + it("leaves the injected frame's opacity alone while syncing color-graded active videos", async () => { const { teardown, setup } = withGlobals(setupHostHiddenScenario({})); setup.video.setAttribute("data-hf-color-grading-source-hidden", "true"); const seededImg = setup.document.createElement("img"); seededImg.classList.add("__render_frame__"); - seededImg.style.opacity = "0"; + seededImg.style.opacity = "0.4"; setup.video.parentNode?.insertBefore(seededImg, setup.video.nextSibling); const setSourceVisibility = vi.fn(); (setup.window as unknown as { __hf: unknown }).__hf = { @@ -768,7 +768,7 @@ describe("video-frame injection respects ancestor visibility", () => { teardown(); } - expect(seededImg.style.opacity).toBe("1"); + expect(seededImg.style.opacity).toBe("0.4"); expect(seededImg.style.visibility).toBe("visible"); expect(setSourceVisibility).toHaveBeenCalledWith(setup.video, true); }); diff --git a/packages/engine/src/services/screenshotService.ts b/packages/engine/src/services/screenshotService.ts index 99065b9280..96616edcb3 100644 --- a/packages/engine/src/services/screenshotService.ts +++ b/packages/engine/src/services/screenshotService.ts @@ -9,7 +9,6 @@ import { type Page } from "puppeteer-core"; import { withVideoFrameSources, type VideoFrameUpdate } from "./videoFrameTransport.js"; import { type CaptureOptions } from "../types.js"; -import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading"; import { HF_COLOR_GRADING_CANVAS_ID_PREFIX, MEDIA_RENDER_ID_ATTR, @@ -699,7 +698,6 @@ async function injectResolvedVideoFramesBatch( async ( items: Array & { videoId: string; frameId: string }>, visualProperties: string[], - colorGradingSourceHiddenAttr: string, ) => { const injectedIds: string[] = []; const pendingDecodes: Array> = []; @@ -783,11 +781,7 @@ async function injectResolvedVideoFramesBatch( // `opacity: 0`), so its computed opacity is preserved across seeks // and accurately reflects the user's intent on every frame. const opacityParsed = parseFloat(computedStyle.opacity); - const computedOpacity = video.hasAttribute(colorGradingSourceHiddenAttr) - ? 1 - : Number.isNaN(opacityParsed) - ? 1 - : opacityParsed; + const computedOpacity = Number.isNaN(opacityParsed) ? 1 : opacityParsed; // Measure first: an in-flow bordered sibling would shrink the video's flex box. const videoRect = video.getBoundingClientRect(); @@ -888,7 +882,6 @@ async function injectResolvedVideoFramesBatch( }, items, [...MEDIA_VISUAL_STYLE_PROPERTIES], - COLOR_GRADING_SOURCE_HIDDEN_ATTR, ); } @@ -898,7 +891,7 @@ export async function syncVideoFrameVisibility( ): Promise { await page.evaluate( // fallow-ignore-next-line complexity - (ids: string[], colorGradingSourceHiddenAttr: string) => { + (ids: string[]) => { // Mirror the ancestor-visibility guard from `injectVideoFramesBatch`. // See that copy for the full rationale on why `visibility: hidden` is // narrowed to sub-composition hosts only — keep these two functions in @@ -943,10 +936,7 @@ export async function syncVideoFrameVisibility( // its computed opacity. video.style.setProperty("visibility", "hidden", "important"); video.style.setProperty("pointer-events", "none", "important"); - if (hasImg) { - if (video.hasAttribute(colorGradingSourceHiddenAttr)) img.style.opacity = "1"; - img.style.visibility = "visible"; - } + if (hasImg) img.style.visibility = "visible"; } else { // Inactive (or ancestor-hidden) video: hide both. Use visibility only // (never opacity) so we never clobber GSAP-controlled inline opacity. @@ -965,6 +955,5 @@ export async function syncVideoFrameVisibility( } }, activeVideoIds, - COLOR_GRADING_SOURCE_HIDDEN_ATTR, ); } diff --git a/packages/producer/tests/graded-video-transitions/meta.json b/packages/producer/tests/graded-video-transitions/meta.json new file mode 100644 index 0000000000..d7f0a720b8 --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/meta.json @@ -0,0 +1,13 @@ +{ + "name": "graded-video-transitions", + "description": "Color-graded videos keep their animation: a red-to-blue opacity dissolve (2-4 s) and a green clip-path wipe from the left (4-6 s). Before the fix the dissolve exported as a hard cut.", + "tags": ["regression", "color-grading", "video"], + "minPsnr": 30, + "maxFrameFailures": 0, + "minAudioCorrelation": 0, + "maxAudioLagWindows": 1, + "renderConfig": { + "fps": 30, + "workers": 1 + } +} diff --git a/packages/producer/tests/graded-video-transitions/output/compiled.html b/packages/producer/tests/graded-video-transitions/output/compiled.html new file mode 100644 index 0000000000..367573e221 --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/output/compiled.html @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c4ccb303b2513887b06da4bcb3e4dc87ff8fbd975b04f2cb2ae76d6030aeb21 +size 76383 diff --git a/packages/producer/tests/graded-video-transitions/output/output.mp4 b/packages/producer/tests/graded-video-transitions/output/output.mp4 new file mode 100644 index 0000000000..76344aa0a2 --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/output/output.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a7f3457aeefc74732eb16dfb4dbb8984986d2cc5864475d849b5a149e797479 +size 14560 diff --git a/packages/producer/tests/graded-video-transitions/src/assets/blue.mp4 b/packages/producer/tests/graded-video-transitions/src/assets/blue.mp4 new file mode 100644 index 0000000000..31b7ec8874 --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/src/assets/blue.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d4f7010380fb66130b6b868ef6a436145f9794efc2b5eb2aee8e451dc70b7ea +size 5779 diff --git a/packages/producer/tests/graded-video-transitions/src/assets/green.mp4 b/packages/producer/tests/graded-video-transitions/src/assets/green.mp4 new file mode 100644 index 0000000000..c65016c229 --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/src/assets/green.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2ed7bf0fb6055e7611173cec80e8b574be56c3465b115a130eca18639f9ad8c +size 3665 diff --git a/packages/producer/tests/graded-video-transitions/src/assets/red.mp4 b/packages/producer/tests/graded-video-transitions/src/assets/red.mp4 new file mode 100644 index 0000000000..3a3dd3253b --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/src/assets/red.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99056628b491e3f3d2d80c214c0c0c635df3258ec902dd9e331ba9018aa1cef3 +size 5779 diff --git a/packages/producer/tests/graded-video-transitions/src/index.html b/packages/producer/tests/graded-video-transitions/src/index.html new file mode 100644 index 0000000000..2e8a7e9e68 --- /dev/null +++ b/packages/producer/tests/graded-video-transitions/src/index.html @@ -0,0 +1,56 @@ + + + + + Graded video dissolve and clip-path wipe + + + + +
+ + + +
+ + + diff --git a/packages/producer/tests/shard-schedule.json b/packages/producer/tests/shard-schedule.json index 36e133d83a..f30f1983ca 100644 --- a/packages/producer/tests/shard-schedule.json +++ b/packages/producer/tests/shard-schedule.json @@ -23,6 +23,7 @@ "font-variant-numeric": 7, "gsap-letters-render-compat": 9, "gsap-redraw-start-and-overlap": 6, + "graded-video-transitions": 10, "hdr-hlg-audio-windows": 150, "hdr-hlg-regression": 125, "hdr-regression": 207, diff --git a/packages/studio/src/hooks/gsapRuntimePatch.ts b/packages/studio/src/hooks/gsapRuntimePatch.ts index 7768fb011e..454b29fcaf 100644 --- a/packages/studio/src/hooks/gsapRuntimePatch.ts +++ b/packages/studio/src/hooks/gsapRuntimePatch.ts @@ -250,9 +250,8 @@ function changeTouchesOpacity(change: RuntimeTweenChange): boolean { /** * A tween re-initialization (invalidate, or kill+recreate for keyframe-rebuild) - * captures opacity from the element's CURRENT inline style — for a color-graded - * source (hidden with `opacity: 0 !important`) or a mid-flight tween that's a - * runtime transient, not the authored value, and the capture makes it permanent. + * captures opacity from the element's CURRENT inline style — for a mid-flight + * tween that's a runtime transient, not the authored value, and the capture makes it permanent. * Restore the runtime's parse-time authored capture (data-hf-authored-opacity) * first; the re-seek after the patch re-renders the animated value anyway. * Duck-typed (no instanceof): the targets live in the preview iframe's realm. diff --git a/packages/studio/src/hooks/gsapRuntimeReaders.test.ts b/packages/studio/src/hooks/gsapRuntimeReaders.test.ts index 4e2f5485ea..2162a2ab8a 100644 --- a/packages/studio/src/hooks/gsapRuntimeReaders.test.ts +++ b/packages/studio/src/hooks/gsapRuntimeReaders.test.ts @@ -2,10 +2,7 @@ import { afterEach, describe, expect, it } from "vitest"; import { gsap } from "gsap"; import type { GsapAnimation } from "@hyperframes/core/gsap-parser"; -import { - COLOR_GRADING_SOURCE_HIDDEN_ATTR, - HF_COLOR_GRADING_CANVAS_ID_PREFIX, -} from "@hyperframes/core/color-grading"; +import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading"; import { readAllAnimatedProperties, readGsapProperty } from "./gsapRuntimeReaders"; /** @@ -68,47 +65,15 @@ describe("readAllAnimatedProperties group filter", () => { }); describe("color-grading opacity truth", () => { - function gradedElement(): HTMLElement { + it("reads a graded source's opacity from GSAP, as for any element", () => { const el = document.createElement("img"); el.id = "clip"; - el.setAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR, ""); - const canvas = document.createElement("canvas"); - canvas.id = `${HF_COLOR_GRADING_CANVAS_ID_PREFIX}clip`; - canvas.style.opacity = "0.98"; - document.body.append(el, canvas); - return el; - } - - it("resolves opacity from the grading canvas, not the runtime hide", () => { - const el = gradedElement(); - const iframe = fakeIframe(el, { gsapValues: { opacity: 0 } }); - const anim = { - id: "#clip-from-200-visual", - targetSelector: "#clip", - method: "from", - properties: { opacity: 0.5 }, - } as unknown as GsapAnimation; - - const result = readAllAnimatedProperties(iframe, "#clip", anim); - - expect(result.opacity).toBe(0.98); - }); - - it("readGsapProperty takes the same detour", () => { - const el = gradedElement(); - const iframe = fakeIframe(el, { gsapValues: { opacity: 0 } }); + el.setAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR, "true"); + document.body.appendChild(el); + const iframe = fakeIframe(el, { gsapValues: { opacity: 0.98 } }); expect(readGsapProperty(iframe, "#clip", "opacity")).toBe(0.98); }); - - it("reads GSAP directly when the source is not grading-hidden", () => { - const el = document.createElement("div"); - el.id = "clip"; - document.body.appendChild(el); - const iframe = fakeIframe(el, { gsapValues: { opacity: 0.3 } }); - - expect(readGsapProperty(iframe, "#clip", "opacity")).toBe(0.3); - }); }); describe("readAllAnimatedProperties with a sibling tween", () => { diff --git a/packages/studio/src/hooks/gsapRuntimeReaders.ts b/packages/studio/src/hooks/gsapRuntimeReaders.ts index 0bc7203ac4..ac1feeb437 100644 --- a/packages/studio/src/hooks/gsapRuntimeReaders.ts +++ b/packages/studio/src/hooks/gsapRuntimeReaders.ts @@ -3,34 +3,10 @@ */ import type { GsapAnimation } from "@hyperframes/core/gsap-parser"; import { classifyPropertyGroup, type PropertyGroupName } from "@hyperframes/core/gsap-parser"; -import { - COLOR_GRADING_SOURCE_HIDDEN_ATTR, - HF_COLOR_GRADING_CANVAS_ID_PREFIX, -} from "@hyperframes/core/color-grading"; -import { getIframeGsap, queryIframeElement, type IframeGsap } from "./gsapShared"; +import { getIframeGsap, queryIframeElement } from "./gsapShared"; import { gsapWritesChannels } from "./gsapRuntimeKeyframes"; import { roundTo3 } from "../utils/rounding"; -/** - * The element's live value for `prop` as GSAP drives it. Opacity on a - * color-grading-hidden source needs a detour: the runtime hides the source - * with inline `opacity: 0 !important`, so computed opacity is the hide, not - * the animated value. The grading canvas mirrors the source's effective - * opacity every frame, so it is the truth for that one property — reading the - * raw 0 here is what bakes `opacity: 0` into committed keyframes. - */ -function readLiveGsapValue(gsap: IframeGsap, el: Element, prop: string): number { - if (prop === "opacity" && el.getAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR) != null && el.id) { - const canvas = el.ownerDocument.getElementById(HF_COLOR_GRADING_CANVAS_ID_PREFIX + el.id); - const win = el.ownerDocument.defaultView; - if (canvas && win) { - const val = Number(win.getComputedStyle(canvas).opacity); - if (Number.isFinite(val)) return val; - } - } - return Number(gsap.getProperty(el, prop)); -} - export function readGsapProperty( iframe: HTMLIFrameElement | null, selector: string | null, @@ -42,7 +18,7 @@ export function readGsapProperty( const el = queryIframeElement(iframe, selector); if (!el) return null; try { - const val = readLiveGsapValue(gsap, el, prop); + const val = Number(gsap.getProperty(el, prop)); if (!Number.isFinite(val)) return null; return POSITION_PROPS.has(prop) ? Math.round(val) : roundTo3(val); } catch { @@ -89,7 +65,7 @@ export function readAllAnimatedProperties( const groupedPropKeys = new Set([...propKeys].filter(inGroup)); for (const prop of groupedPropKeys) { - const val = readLiveGsapValue(gsap, el, prop); + const val = Number(gsap.getProperty(el, prop)); if (Number.isFinite(val)) { result[prop] = POSITION_PROPS.has(prop) ? Math.round(val) : roundTo3(val); } diff --git a/packages/studio/src/utils/gsapSoftReload.ts b/packages/studio/src/utils/gsapSoftReload.ts index e43482abb4..5049b47170 100644 --- a/packages/studio/src/utils/gsapSoftReload.ts +++ b/packages/studio/src/utils/gsapSoftReload.ts @@ -1,4 +1,3 @@ -import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading"; import { parseGsapScript } from "@hyperframes/parsers/gsap-parser"; import { GSAP_BASE_URL_META, motionPathPluginUrl } from "@hyperframes/core/gsap-cdn"; import { findAuthoredElement } from "./authoredSource"; @@ -464,24 +463,13 @@ export function applySoftReload( s.cssText = css; restoreAuthoredStyle(s, findAuthoredStyle(el), targets.get(el)!); // The restored cssText carries RUNTIME opacity, not authored opacity: - // a mid-flight tween's interpolated value, or the color-grading hide - // (`opacity: 0 !important`). The re-run script's tweens re-initialize + // a mid-flight tween's interpolated value. The re-run script's tweens re-initialize // against it — a from() captures it as its END, a to() as its START — // turning the transient into the tween's permanent bound (dimmed or // invisible elements). Put the AUTHORED inline opacity back; the seek // below re-renders the correct animated value either way. const authored = readAuthoredOpacity(el); - if (authored !== null) { - applyAuthoredInlineOpacity(s, authored); - } else if ( - el.hasAttribute(COLOR_GRADING_SOURCE_HIDDEN_ATTR) && - s.getPropertyValue("opacity") === "0" && - s.getPropertyPriority("opacity") === "important" - ) { - // Authored value unknown, but this is definitely the grading hide — - // never let a from() capture 0; fall back to the CSS cascade. - s.removeProperty("opacity"); - } + if (authored !== null) applyAuthoredInlineOpacity(s, authored); } } forgetLiveSets(targets); diff --git a/packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/blue.mp4 b/packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/blue.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..56dadef38e1d30698f99c2fc45b5c6c7501d7f18 GIT binary patch literal 5779 zcmeHJYitx%6u#Rnr4ofg$|JnI2tE?o?aa28TA9eQX{_(P+qF`7UEF_Az1lNw1RBq)+7MomCN*K=leVY}P@0ZAnG zW@gU0=keXgId{$_gwTvAxTf#egwzqF@Fv)RCfjbCOi1H5w&M&CLM(g0(1BL8=ud& z(=CoRb644BE(1*SfE|EVPJ5jm>Q?F=M;mOYzq8-7XvjC5@kQDK{RxASD09L7pPF5GslI6WX zk4|hl*mA{PNJtciiIR;Amc)i5q`|m&?$kZUu3o;3-c2s^U7$D-e4Eq4EA8@%`=F0) znJP`fpO;s~sk$G;(HEKncGw^X?m(LE*98N*!{z}+*_z7g3KiL7u8RfmT8o)s z3BUJ-K;>HbOTVUh3!gO+eC)HS*X^Kpt<}0mK=V{B)vWna( zbxM@wm{st(BIR2uj=WF9GAceKGZhzTvriM1`pL^ zxn8cw?Nl>7$7U+H%2asVvP>Vij(mr%31GB7TajQ2OyB9`xRQ|9%QDR{U#PC1HC?m_ z0s36k$z*&klvsia!vhZhf_sGHWSIdy^_r0SmZ`yH$^wbzykHQ`w3)z(m^r~ci-8fy z(^kL73aaMVE)&q#V2|KFXyyO{3_XT68IRfAhuuo6ZUJ~xR}#Q8ow>M-w3;@VkAs*V z4;D7a&0a&KLFc$Ur}jE7XhWe3u326HY^7ByaVlKW0NvMkj%)owX_Ii09>X2=xNm^7 zr>WN#i;kYAXkLceaMR(qDCj7O*0@Cba4CuuZwJ;z+<>yY(*7_Ae8F9%jhZgR2=W0! z2xGB62tNjs3_;4OeBU0jp*VRqdb#=AEtA^*)I`MCcIwUXMQ`^^{QkzW{m;+otA7FS zV))EElKk=W4`1K)?rG>o-y?_X$y)aD(lsBfuG`yrvSX-;mMug3CBMNC3zG-dS*cx< zhxUZZ$X6hopB&wse|c9)GKiAMC=;8@k~5)1dvS_nY4U*a_~E4SPEVs#oC?^K9NpWs zaQ%aDvBa?>CCK+{AP?0*9tB8iddRQ47S}*tsDZp#19@pi$g%mgkYllG$g!4c$dR_0 zA)lHCvabfxuYt_Z3^_av}(nApfp`yjp^MvUnBJDM+m3aYzrw z_q{~wADujZ?8@+tHRp!5zLMSh#3!%4_4cbhiSgYRPDJCW)TyzO2l(YPKM(Ehw(pNn zCmw)Y`{ywN(lBYu-`EdiHhC-0Y*TVJc`N=cV>g<-#~`mDdH0Z} z;;l>Gv$M%NrQpmaZ}@*J6~>!Q-dp?UolV~A%gul0&$}c!Qoc6y7AHrWf~;!z6aF@E c!fxo+0Ep#V!_&pdj!gmL3MoYVS1%3!0ApJMEC2ui literal 0 HcmV?d00001 diff --git a/packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/green.mp4 b/packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/green.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4bf99d2c7f560837fd48cf1fde2e4f40df1f885e GIT binary patch literal 3665 zcmeHIe~1)S9Dj4Wo|lxJacAPGJVR$q1_GY@7ow=EJ zcf0zBM_L@!pK_7HUHuW3_)m~XP@rH4N#vgz1xg^A&=08a3UB*>449 zFA#~~b7#z%fVghncgJ!*u8ELEDG{(CQ0^5&(VDRu!wMR#TR-a7nQz^uaR|qX9M^GE zgut!hPADo+fPlF1O3d-&u4yySQP-@`eG7;SWY^iqGhvxdP{AOhw#lnJ(%mrk23X#7 zINHQ_xpqDWOxvg%f!2n-&MfOznE^)|9H_s4Byeb%kGF?HcYr?=im+M`wD}l|1{6mv zW+Z4DhqMQP#TSRvz8&n-sbs1rsmKa-Y`u_5cbApXcSWfLbR$@0C6lZvT_Gz6fu6Y3 z_g?3Wzl@L=E)yeL9$cQ7lt{C6d!6j230 z9ofK^Lh%U!d5D$4fdce@1jsexj{WAc94Zy*msDtVj#KoD@POXadPt(0*FBxb->5^B z=PIbb5mm5Ud#peHZa}3t==N1~NI)KI2HFnqLp5&)@NNI{9RKpWz3$4oxa;RpUZF5N zu)_g+(%b`7A29_3`m)O-in_J6T?sl_z@QL z3Oq8lm6lw)>{E?B{zHQl_ZR66=?|MkzWUK%(xx#1$c^w^I-VGp4RYIp&sO8RMF z2a+J_+_AHNTcVq0c4t9nasw1u&o4SWCumBRyAmlmh1Ql3es5>z*w|PS`>5xze9{XB zI}tZ&3D*G|&lk3r4|}P>bY`dugfg>Xi$M(nVda zTD(BR5goXV)DMf`3STWSRV68d6MU#^7r3b*q5>XT!19A!RnpY30?%a{xGGcx+;Qv> zxSm3fX$WA9VONzQ1ZM8@@?1?R8x)1+SSU0<9I}11C<6@pnwQIkT&Rf@6;=Qq00jNl z^M;rOGwrsJhK_AOFjav}^Fg$TVY^IVAa-8xz+qqna@`pTSWz=P*JlFe2J8{sqjnx3 zz%XEFlM9&3L)a}{^NYaSrkVntnasyDbWOKeh>O?(j}jZ>_Mjzn(0M-3YlEH-+Op6G z*CAd6Y_&_Sa2i~0fF2q=&y5kGcFP!Kz;H(c9$MfW7~1V*(J?SoBgjz~ZU~M^!9-1U zC1pB{si<-?4Xls25oHB6y$J-N;J(^TZ69g`=K)FxYq4P{KNgdW!;#ha#38b=G zv+e8sGjG4LZHIJn@24HZPl~UmH%Sw}UD(t5EM8&d=lJ0@`;T8d_s44R?d@AK-q)1w zSR1T-|MGg{#ETOWwBf2{#7OwdEXy2O=VTAe9y?UlO6NehG&8le@cMy@WDF(J6cbyk zlJCkA?{07LN^=2QGgEK$FWc}GT*w%LRDt}U0rFS_U zzr6wSdIRK*2FRZmgq&X52sxdohn()LhdkQ7FyssKKn^!Rh7FK~g&`;Bfjrp&d8z^O zvxOnQnFn&F0rJlV$XgZ2=S#PKDHoSy&cN|teBw0{e`faT>6yu059~ScyS`=d_$O~2 ze&@~YsZ$59pN%E6+4IvC4>%Ns+z;ai2izwlO2~cdC9UP9Y&M>Z?cDrDd}IkDAf0n| zN#Zj3|M1rSv#pu`%;8<0Ia)ougQeN2)~I&Pze2$v$bWQp0kL{^_mpOP`Xa;*yww5m JZXVs!e*s|6t6Bg6 literal 0 HcmV?d00001 diff --git a/packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/red.mp4 b/packages/studio/tests/e2e/fixtures/graded-video-transitions/assets/red.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..459c0f2fdf32f11c30b35790a08c5bc40c347ba5 GIT binary patch literal 5779 zcmeHKYitx%6u#RnrSdGKEl2?`FaN-9XSTJ}hKXI8#$qr&5+L!B_3q5w?$DW?>CA1r zi$B^JB>W%|V^WnSZB10bzzSMeVlXW+$Dt2gvi*sYng7j z+{iWI0=JqQuE;?F0^*kD<~-jqHJyQunp)x7w}JQ?+4Y&{8A@t~<8kon)-|5zk?w}R z)y7hq!O>>^8dFatfT`>@J-ZbvXw0`LYYHh#SD4afO=?2->`l zK?90yDyAnW>4Rmr0gDf|K-EsLZ-|5=jbT}msiDWyk%oF->AhEGvp~0kRZBo4YqJ;0 zs&=3!Mw^Fg$L(c=1aX)k*|xMg)E^*a$*Vt|T|Y80Hiq66Hgj#DI1zj*1!1GztsD$Y6s|c)ACGD)2lDBYvdb^6T>TXohwRax~w^F3LUJdtDEU z$ggW|oqk;J>3#UW#1qb)m$$3oT&v!R^v^WN@yz4-4EzbYeK{QxkO#|vR>8A;%2NY; z3#{{bX-^nxJF~1GbR{;GM9idC&N#|@>rg5I7E2yfC*Mm8HUQ{WwQg{w_f?=(rDYM z{w?R}=!Rc^!&*o~RJ9yV<%WlVZ3}~__VFiM9}U&h=R?Ie#cm3zYv?LWCNGd^%JBwKb(0C4h@KMM zF&G$uJZ^M3EE7{L(`EwtD(n&52lW&{fT6?CCgCuXyRcjFn4JM$*OUnGOk*}KBOZ(E z%*8=;hkFa_;d*;g#6f4-JQZuVY|#2b8(ceh2C$VnDaXa&k_PCm%2QnJ5=y;#&Q5DrmP!n!C92W&0B~llbXeTa3k-`nY+KB5>mR1@b27xQMt<+Q9 zh8RIUKnP(h)(PRqV3Iya*%&{#pKQ%eUJQ;^e*NP3p}iNL;_p_Sef8Ax*LRNoad_n` z&(G^DeF5)c_*-y1dinIpL%naEhi>p~a;%hWU>~el_ukr)15KYd_EpflrEgz-9fnvI zJ+jeg>76{f-&Y2{0O6A8;P&*(y*Wt_N&rkJ(d3&u%dPBm zz>4VLf!1YPHp9gd#}4Em-zkDTS_F9lAdQ(Jzih24g1k}$d9?`g+N_X6ONt?fLWPh+ zwS|xa^|M1hJp*KC5u{rLnVuc8e+I}8iy%)GL4G_t-ppL`PAfQb$?JdLa)t3ullSg^dFPV1@N)B?`SMmr2lCg3 m_Uz + + + + Graded video dissolve and clip-path wipe + + + + +
+ + + +
+ + + diff --git a/packages/studio/tests/e2e/graded-video-transitions.mjs b/packages/studio/tests/e2e/graded-video-transitions.mjs new file mode 100644 index 0000000000..a2e9cb850b --- /dev/null +++ b/packages/studio/tests/e2e/graded-video-transitions.mjs @@ -0,0 +1,117 @@ +#!/usr/bin/env node +// Color-graded videos keep their animation in the preview: a red-to-blue opacity dissolve (2-4 s) and a +// green clip-path wipe from the left (4-6 s). Grading once froze the dissolve, and its hide once blacked it out. +// A click on a graded clip still picks it. +import { mkdirSync, writeFileSync } from "node:fs"; +import { launchStudioChrome } from "./chrome-executable.mjs"; + +const STUDIO_URL = process.env.STUDIO_URL; +const OUT_DIR = process.env.OUT_DIR; + +if (!STUDIO_URL) { + console.error("STUDIO_URL is required and must point at the graded-video-transitions fixture"); + process.exit(2); +} +if (OUT_DIR) mkdirSync(OUT_DIR, { recursive: true }); + +// Share of red in red + blue at the dissolve's quarter points, and which colour leads either side of the wipe. +const DISSOLVE = [ + { time: 2.5, red: 0.75 }, + { time: 3, red: 0.5 }, + { time: 3.5, red: 0.25 }, +]; +const WIPE = { time: 5, left: "green", right: "blue" }; +const TOLERANCE = 0.12; + +const { browser } = await launchStudioChrome(); +const failures = []; +const evidence = {}; +try { + const page = await browser.newPage(); + await page.setViewport({ width: 1440, height: 900 }); + await page.goto(STUDIO_URL, { waitUntil: "domcontentloaded" }); + await page.waitForSelector('button[aria-label="Play"]:not([disabled])', { timeout: 60_000 }); + const handle = await page.waitForFunction( + () => document.querySelector("hyperframes-player")?.shadowRoot?.querySelector("iframe"), + { timeout: 60_000 }, + ); + const iframe = handle.asElement(); + const frame = await iframe.contentFrame(); + await frame.waitForFunction(() => window.__playerReady, { timeout: 60_000 }); + + /** RGB at fractions of the film's width and height, read from a screenshot of the preview at `time`. */ + const sample = async (name, time, points) => { + await frame.evaluate((t) => window.__player.seek(t, { settled: true }), time); + await frame.evaluate( + () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))), + ); + const film = await frame.evaluate(() => { + const r = document.getElementById("film").getBoundingClientRect(); + return { x: r.x, y: r.y, width: r.width, height: r.height }; + }); + const png = await iframe.screenshot({ encoding: "base64" }); + if (OUT_DIR) writeFileSync(`${OUT_DIR}/${name}.png`, Buffer.from(png, "base64")); + const box = await iframe.boundingBox(); + const scale = box.width / (await frame.evaluate(() => window.innerWidth)); + return page.evaluate( + async (data, film, scale, points) => { + const img = new Image(); + img.src = `data:image/png;base64,${data}`; + await img.decode(); + const canvas = new OffscreenCanvas(img.width, img.height); + const ctx = canvas.getContext("2d"); + ctx.drawImage(img, 0, 0); + return points.map(([fx, fy]) => { + const x = Math.round((film.x + film.width * fx) * scale); + const y = Math.round((film.y + film.height * fy) * scale); + const [r, g, b] = ctx.getImageData(x, y, 1, 1).data; + return { r, g, b }; + }); + }, + png, + film, + scale, + points, + ); + }; + const dark = ({ r, g, b }) => Math.max(r, g, b) < 40; + const leads = ({ r, g, b }) => (g > r && g > b ? "green" : b > r ? "blue" : "red"); + + for (const { time, red } of DISSOLVE) { + const [centre] = await sample(`dissolve-${time}`, time, [[0.5, 0.5]]); + const share = centre.r / Math.max(1, centre.r + centre.b); + evidence[`dissolve-${time}`] = { ...centre, share: Number(share.toFixed(3)) }; + if (dark(centre)) failures.push(`dissolve at ${time} s: black (${JSON.stringify(centre)})`); + else if (Math.abs(share - red) > TOLERANCE) + failures.push(`dissolve at ${time} s: red share ${share.toFixed(2)}, expected ${red}`); + } + + // A graded clip stays under the pointer, so a click in the preview still picks it. + await frame.evaluate(() => window.__player.seek(1, { settled: true })); + const picked = await frame.evaluate(() => { + const r = document.getElementById("film").getBoundingClientRect(); + return document.elementsFromPoint(r.x + r.width / 2, r.y + r.height / 2).map((el) => el.id); + }); + evidence.pickAt1 = picked; + if (!picked.includes("a")) + failures.push(`at 1 s the graded clip is not under the pointer: ${picked}`); + + const [left, right] = await sample("wipe-5", WIPE.time, [ + [0.25, 0.5], + [0.75, 0.5], + ]); + evidence.wipe = { left, right }; + for (const [side, pixel, colour] of [ + ["left", left, WIPE.left], + ["right", right, WIPE.right], + ]) { + if (dark(pixel)) failures.push(`wipe at ${WIPE.time} s, ${side}: black`); + else if (leads(pixel) !== colour) + failures.push(`wipe at ${WIPE.time} s, ${side}: ${leads(pixel)} leads, expected ${colour}`); + } +} finally { + await browser.close(); +} + +console.log(JSON.stringify({ evidence, failures }, null, 2)); +if (failures.length > 0) process.exit(1);