fix(studio): fx badges in a sealed preview show the clip's look, crop and duck (#8411)

* test(studio): a sealed preview's fx badge lights from what discovery read

* fix(studio): fx badges in a sealed preview show the clip's look, crop and duck
This commit is contained in:
Miguel Ángel
2026-11-21 23:14:47 +00:00
committed by GitHub
parent 71907274a7
commit 8a69ea0395
6 changed files with 71 additions and 5 deletions
@@ -5,6 +5,7 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { TimelineElement } from "../store/playerStore";
import { usePreviewIframeStore } from "../store/previewIframeStore";
import { applyMediaMetadataFromElement } from "../lib/timelineElementHelpers";
import { ClipBadges } from "./ClipBadges";
Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", {
@@ -86,6 +87,19 @@ describe("ClipBadges", () => {
expect(fx()?.getAttribute("title")).toBe("Look: Warm daylight · Crop");
});
it("lights the fx badge from what discovery read when the preview's node is out of reach", () => {
const node = document.createElement("video");
node.setAttribute("data-color-grading", '{"preset":"warm-daylight","intensity":1}');
node.setAttribute("data-fx-carve", '{"enabled":true}');
node.setAttribute("style", "clip-path: inset(10px)");
const read: TimelineElement = { ...talk };
applyMediaMetadataFromElement(read, node);
render(read);
const fx = document.querySelector("[data-badge='fx']");
expect(fx?.getAttribute("data-fx-active")).toBe("true");
expect(fx?.getAttribute("title")).toBe("Look: Warm daylight · Crop · Ducked");
});
it("opens the clip menu from the fx badge without reaching the clip", () => {
const host = document.createElement("div");
document.body.append(host);
@@ -51,9 +51,9 @@ function toolStateFromElement(el: TimelineElement): ClipToolState {
muted: el.muted === true,
fxChain: el.fxChain ?? null,
automation: el.automation ?? null,
colorGrading: null,
clipPath: null,
carve: null,
colorGrading: el.colorGrading ?? null,
clipPath: el.clipPath ?? null,
carve: el.carve ?? null,
};
}
@@ -73,6 +73,33 @@ describe("syncStoredElementAttribute", () => {
});
});
describe("the fx badge's fields", () => {
const LOOK = '{"preset":"warm-daylight","intensity":1}';
it("records a saved look and duck on the stored clip, and drops them when they go", () => {
usePlayerStore.setState({ elements: [el()] });
syncStoredElementAttribute(el(), "data-color-grading", LOOK);
syncStoredElementAttribute(el(), "data-fx-carve", '{"enabled":true}');
expect(usePlayerStore.getState().elements[0]).toMatchObject({
colorGrading: LOOK,
carve: '{"enabled":true}',
});
syncStoredElementAttribute(el(), "data-color-grading", null);
expect(usePlayerStore.getState().elements[0]?.colorGrading).toBeUndefined();
});
it("reads back a look and crop an undo restored on the preview", () => {
usePlayerStore.setState({ elements: [el()] });
syncStoredAutomationFromPreview(
previewWith({ "data-color-grading": LOOK, style: "clip-path: inset(10px)" }),
);
expect(usePlayerStore.getState().elements[0]).toMatchObject({
colorGrading: LOOK,
clipPath: "inset(10px)",
});
});
});
describe("syncStoredAutomationFromPreview", () => {
it("reads back a volume an undo restored on the preview", () => {
usePlayerStore.setState({ elements: [el({ volume: 1.5 })] });
@@ -16,6 +16,8 @@
import { HF_AUDIO_AUTOMATION_ATTR } from "@hyperframes/core/audio-automation";
import { HF_AUDIO_FX_ATTR } from "@hyperframes/core/audio-fx";
import { HF_AUDIO_CARVE_ATTR } from "@hyperframes/core/audio-carve";
import { HF_COLOR_GRADING_ATTR } from "@hyperframes/core/color-grading";
import {
HF_AUDIO_FADE_IN_ATTR,
HF_AUDIO_FADE_OUT_ATTR,
@@ -27,6 +29,7 @@ import { groupInfoFor } from "./timelineGroupInfo";
import {
getTimelineElementIdentity,
previewElementFinder,
readBadgeFields,
resolveMediaElement,
} from "./timelineElementHelpers";
import { elementVolume, parseStoredVolume } from "./storedVolume";
@@ -49,9 +52,9 @@ let syncs = 0;
* reverted is only known by looking.
*/
/**
* What an element's seven synced fields SHOULD read, given the preview.
* What an element's ten synced fields SHOULD read, given the preview.
*
* Its own five come off its node; the other two are its copy of what its group
* Its own eight come off its node; the other two are its copy of what its group
* carries. The timeline derives a group's lanes and chain from these mirrors,
* never from the group element, and automating a group writes `data-automation`
* on the group node through the ordinary element path, so both halves are re-read.
@@ -67,6 +70,7 @@ function syncedFields(doc: Document, element: TimelineElement, node: Element) {
volume: elementVolume(node, resolveMediaElement(node) ?? node),
audioGroupAutomation: group?.automation,
audioGroupFxChain: group?.fxChain,
...readBadgeFields(node),
};
}
@@ -112,6 +116,8 @@ const storedFade = (seconds: number) => (seconds > 0 ? seconds : undefined);
const STORED_FIELD: Record<string, (value: string | null) => Partial<TimelineElement>> = {
[HF_AUDIO_AUTOMATION_ATTR]: (value) => ({ automation: value ?? undefined }),
[HF_AUDIO_FX_ATTR]: (value) => ({ fxChain: value ?? undefined }),
[HF_COLOR_GRADING_ATTR]: (value) => ({ colorGrading: value ?? undefined }),
[HF_AUDIO_CARVE_ATTR]: (value) => ({ carve: value ?? undefined }),
[HF_AUDIO_FADE_IN_ATTR]: (value) => ({ fadeIn: storedFade(readFadeSeconds(value)) }),
[HF_AUDIO_FADE_OUT_ATTR]: (value) => ({ fadeOut: storedFade(readFadeSeconds(value)) }),
// A quick volume save writes no other field the store keeps: without this, a clip read its last load's volume.
@@ -23,6 +23,9 @@ import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
import { readElementFades } from "@hyperframes/core/audio-fade";
import { isHtmlElement, isImageElement, isMediaElement } from "@hyperframes/core/runtime/dom-realm";
import { elementVolume } from "./storedVolume";
import { HF_COLOR_GRADING_ATTR } from "@hyperframes/core/color-grading";
import { HF_AUDIO_CARVE_ATTR } from "@hyperframes/core/audio-carve";
import { committedClipPath } from "../../components/editor/cropPresetStore";
import {
type AttrReader,
clampPlaybackRate,
@@ -242,8 +245,20 @@ function applyFadeMetadataFromElement(entry: TimelineElement, el: Element): void
setOptional(entry, "fadeOut", fades.fadeOut > 0 ? fades.fadeOut : undefined);
}
export function readBadgeFields(el: Element) {
return {
colorGrading: el.getAttribute(HF_COLOR_GRADING_ATTR) ?? undefined,
clipPath: committedClipPath(el) ?? undefined,
carve: el.getAttribute(HF_AUDIO_CARVE_ATTR) ?? undefined,
};
}
export function applyMediaMetadataFromElement(entry: TimelineElement, el: Element): void {
setOptional(entry, "text", readTimelineText(el));
const badge = readBadgeFields(el);
setOptional(entry, "colorGrading", badge.colorGrading);
setOptional(entry, "clipPath", badge.clipPath);
setOptional(entry, "carve", badge.carve);
applyPlaybackMetadataFromElement(entry, el);
applyAudioMetadataFromElement(entry, el);
applyFadeMetadataFromElement(entry, el);
@@ -66,6 +66,10 @@ export interface TimelineElement {
fxChain?: string;
automation?: string;
masterChain?: string;
/** The fx badge's `data-color-grading`, inline clip-path and `data-fx-carve`, for a frame Studio cannot reach. */
colorGrading?: string;
clipPath?: string;
carve?: string;
/** Path from data-composition-src — identifies sub-composition elements */
compositionSrc?: string;
/** Set by data-timeline-locked on the host element — disables move and trim in Studio. */