diff --git a/packages/studio/src/player/components/ClipBadges.test.tsx b/packages/studio/src/player/components/ClipBadges.test.tsx index 57a53fc813..26c7d4ba25 100644 --- a/packages/studio/src/player/components/ClipBadges.test.tsx +++ b/packages/studio/src/player/components/ClipBadges.test.tsx @@ -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); diff --git a/packages/studio/src/player/components/useClipToolState.ts b/packages/studio/src/player/components/useClipToolState.ts index b99c91fcc7..ece4997a27 100644 --- a/packages/studio/src/player/components/useClipToolState.ts +++ b/packages/studio/src/player/components/useClipToolState.ts @@ -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, }; } diff --git a/packages/studio/src/player/lib/automationStoreSync.test.ts b/packages/studio/src/player/lib/automationStoreSync.test.ts index a1873bbe7a..5389898f85 100644 --- a/packages/studio/src/player/lib/automationStoreSync.test.ts +++ b/packages/studio/src/player/lib/automationStoreSync.test.ts @@ -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 })] }); diff --git a/packages/studio/src/player/lib/automationStoreSync.ts b/packages/studio/src/player/lib/automationStoreSync.ts index e115be2953..0e053bce0e 100644 --- a/packages/studio/src/player/lib/automationStoreSync.ts +++ b/packages/studio/src/player/lib/automationStoreSync.ts @@ -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 Partial> = { [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. diff --git a/packages/studio/src/player/lib/timelineElementHelpers.ts b/packages/studio/src/player/lib/timelineElementHelpers.ts index 178fa9247b..e1bd5cc1dc 100644 --- a/packages/studio/src/player/lib/timelineElementHelpers.ts +++ b/packages/studio/src/player/lib/timelineElementHelpers.ts @@ -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); diff --git a/packages/studio/src/player/store/timelineElement.ts b/packages/studio/src/player/store/timelineElement.ts index 68f7d1940f..65ad690b9c 100644 --- a/packages/studio/src/player/store/timelineElement.ts +++ b/packages/studio/src/player/store/timelineElement.ts @@ -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. */