From 97b90d8fa2b9e7c475e30e0e9a91f49418d1aedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 22 Nov 2026 12:40:37 +0000 Subject: [PATCH] fix(studio): a sealed preview's clips keep their GSAP transition label (#8499) * test: a sealed preview's clips name their GSAP transition * fix(studio): a sealed preview's clips keep their GSAP transition label * fix(studio): GSAP scene and overlay clips carry their transition label too --- packages/core/src/runtime/timeline.test.ts | 24 +++++++++++++ packages/core/src/runtime/timeline.ts | 5 +++ .../src/runtime/transitionLabels.ts} | 12 +++---- packages/core/src/runtime/types.ts | 1 + packages/core/src/studioPreviewMark.ts | 5 +++ .../src/player/lib/manifestClips.test.ts | 36 +++++++++++++++++++ .../studio/src/player/lib/manifestClips.ts | 15 +++++++- .../studio/src/player/lib/playbackTypes.ts | 1 + .../studio/src/player/lib/timelineDOM.test.ts | 24 +++++++++++++ packages/studio/src/player/lib/timelineDOM.ts | 9 ++--- .../src/player/lib/timelineIframeHelpers.ts | 2 +- 11 files changed, 118 insertions(+), 16 deletions(-) rename packages/{studio/src/player/lib/timelineTransitionMetadata.ts => core/src/runtime/transitionLabels.ts} (79%) create mode 100644 packages/studio/src/player/lib/manifestClips.test.ts diff --git a/packages/core/src/runtime/timeline.test.ts b/packages/core/src/runtime/timeline.test.ts index d1f3227e46..e6d003eaf2 100644 --- a/packages/core/src/runtime/timeline.test.ts +++ b/packages/core/src/runtime/timeline.test.ts @@ -115,6 +115,30 @@ describe("collectRuntimeTimelinePayload", () => { expect(trackOf("clip-other")).toBe(2); }); + it("names both clips of a GSAP transition on the clip message, for a preview that cannot read the page", () => { + const root = document.createElement("div"); + root.setAttribute("data-composition-id", "main"); + root.setAttribute("data-duration", "10"); + root.innerHTML = ` +
+
+
`; + document.body.appendChild(root); + (window as TimelineTestWindow).__timelines = { + main: { duration: () => 10, labels: { "hf:transition:a:b:fade": 2 } } as never, + }; + + const labels = collectRuntimeTimelinePayload(defaultParams).clips.map((clip) => [ + clip.id, + clip.transitionLabel, + ]); + expect(labels).toEqual([ + ["a", "hf:transition:a:b:fade"], + ["b", "hf:transition:a:b:fade"], + ["c", null], + ]); + }); + it("collects clips from elements with data-start and data-duration", () => { const root = document.createElement("div"); root.setAttribute("data-composition-id", "main"); diff --git a/packages/core/src/runtime/timeline.ts b/packages/core/src/runtime/timeline.ts index bc901f671e..c248d2ed47 100644 --- a/packages/core/src/runtime/timeline.ts +++ b/packages/core/src/runtime/timeline.ts @@ -5,6 +5,7 @@ import type { RuntimeTimelineScene, RuntimeTimelineLike, } from "./types"; +import { transitionLabelsForDocument } from "./transitionLabels"; import { unproxiedSrc } from "./proxySrc"; import { stableClipId } from "./clipTree"; import { findRootCompositionElement, parseCompositionDimension } from "./compositionDimension"; @@ -270,6 +271,7 @@ export function collectRuntimeTimelinePayload(params: { __timelines?: Record; }; const timelineRegistry = runtimeWindow.__timelines ?? {}; + const transitionLabels = transitionLabelsForDocument(document, timelineRegistry); const startResolver = createRuntimeStartTimeResolver({ timelineRegistry, includeAuthoredTimingAttrs: true, @@ -505,6 +507,7 @@ export function collectRuntimeTimelinePayload(params: { timelineGroup: node.getAttribute("data-timeline-group"), timelinePriority: parseNum(node.getAttribute("data-timeline-priority")), text: readSentTextLayer(node), + transitionLabel: transitionLabels.get(node) ?? null, }; }; const addClip = (clip: RuntimeTimelineClip) => { @@ -636,6 +639,7 @@ export function collectRuntimeTimelinePayload(params: { timelineGroup: el.getAttribute("data-timeline-group"), timelinePriority: parseNum(el.getAttribute("data-timeline-priority")), text: readSentTextLayer(el), + transitionLabel: transitionLabels.get(el) ?? null, }); gsapClipIds.add(el.id); } @@ -694,6 +698,7 @@ export function collectRuntimeTimelinePayload(params: { timelineGroup: el.getAttribute("data-timeline-group"), timelinePriority: parseNum(el.getAttribute("data-timeline-priority")), text: readSentTextLayer(el), + transitionLabel: transitionLabels.get(el) ?? null, }); gsapClipIds.add(el.id); } diff --git a/packages/studio/src/player/lib/timelineTransitionMetadata.ts b/packages/core/src/runtime/transitionLabels.ts similarity index 79% rename from packages/studio/src/player/lib/timelineTransitionMetadata.ts rename to packages/core/src/runtime/transitionLabels.ts index 713637e440..13c9e21bb0 100644 --- a/packages/studio/src/player/lib/timelineTransitionMetadata.ts +++ b/packages/core/src/runtime/transitionLabels.ts @@ -1,8 +1,6 @@ -import type { TimelineLike } from "./playbackTypes"; +export const TRANSITION_LABEL_PREFIX = "hf:transition:"; -const TRANSITION_LABEL_PREFIX = "hf:transition:"; - -type TimelineWithLabels = TimelineLike & { +type TimelineWithLabels = { labels?: Record; getLabels?: () => Record; }; @@ -30,13 +28,13 @@ function findTimedElement(doc: Document, markerId: string): Element | null { export function transitionLabelsForDocument( doc: Document, - timelines: Readonly> | undefined, + timelines: Readonly> | undefined, ): ReadonlyMap { const labels = new Map(); if (!timelines) return labels; - for (const timeline of Object.values(timelines) as TimelineWithLabels[]) { - const timelineLabels = timeline.getLabels?.() ?? timeline.labels ?? {}; + for (const timeline of Object.values(timelines) as Array) { + const timelineLabels = timeline?.getLabels?.() ?? timeline?.labels ?? {}; for (const label of Object.keys(timelineLabels)) { const pair = transitionParts(label); if (!pair) continue; diff --git a/packages/core/src/runtime/types.ts b/packages/core/src/runtime/types.ts index f962baf61e..d08ec4cbab 100644 --- a/packages/core/src/runtime/types.ts +++ b/packages/core/src/runtime/types.ts @@ -99,6 +99,7 @@ export type RuntimeTimelineClip = RuntimeTimelineClipIdentity & { timelineGroup: string | null; timelinePriority: number | null; text: TextLayerRead | null; + transitionLabel: string | null; }; export type RuntimeTimelineScene = { diff --git a/packages/core/src/studioPreviewMark.ts b/packages/core/src/studioPreviewMark.ts index c826576f5e..5e53e837ad 100644 --- a/packages/core/src/studioPreviewMark.ts +++ b/packages/core/src/studioPreviewMark.ts @@ -1,5 +1,10 @@ import { isWebKit } from "./runtime/mediaClock.js"; +export { + TRANSITION_LABEL_PREFIX, + transitionLabelsForDocument, +} from "./runtime/transitionLabels.js"; + export const STUDIO_PREVIEW_MARK_META = "hyperframes-studio-preview"; export const PREVIEW_SEEK_HOLD_ATTR = "data-hf-preview-seek-hold"; export const PREVIEW_VIDEO_FRAME_ATTR = "data-hf-preview-video-frame"; diff --git a/packages/studio/src/player/lib/manifestClips.test.ts b/packages/studio/src/player/lib/manifestClips.test.ts new file mode 100644 index 0000000000..e7b2a5b41d --- /dev/null +++ b/packages/studio/src/player/lib/manifestClips.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, it } from "vitest"; +import { wellFormedClips } from "./manifestClips"; + +const clip = (transitionLabel: unknown) => ({ + id: "a", + label: "A", + kind: "element", + tagName: "div", + start: 0, + duration: 3, + track: 0, + compositionId: null, + parentCompositionId: null, + compositionSrc: null, + assetUrl: null, + transitionLabel, +}); + +describe("wellFormedClips", () => { + it("keeps a transition label only as the runtime writes one, and the clip either way", () => { + const clips = wellFormedClips([ + clip("hf:transition:a:b:fade"), + clip(`hf:transition:a:b:${"x".repeat(200)}`), + clip("javascript:alert(1)"), + clip(5), + clip(null), + ]); + expect(clips.map((kept) => kept.transitionLabel)).toEqual([ + "hf:transition:a:b:fade", + undefined, + undefined, + undefined, + undefined, + ]); + }); +}); diff --git a/packages/studio/src/player/lib/manifestClips.ts b/packages/studio/src/player/lib/manifestClips.ts index 55816f0958..97518db6e9 100644 --- a/packages/studio/src/player/lib/manifestClips.ts +++ b/packages/studio/src/player/lib/manifestClips.ts @@ -1,5 +1,8 @@ +import { TRANSITION_LABEL_PREFIX } from "@hyperframes/core/studio-preview-mark"; import type { ClipManifestClip } from "./playbackTypes"; +const MAX_TRANSITION_LABEL = 200; + const OPTIONAL_NUMBERS = ["zIndex", "playbackStart", "playbackRate"] as const; export const clipNumber = (value: unknown): number | null => @@ -18,7 +21,17 @@ function wellFormedClip(clip: unknown): clip is ClipManifestClip { ); } +const transitionLabelOf = (value: unknown): string | undefined => + typeof value === "string" && + value.length <= MAX_TRANSITION_LABEL && + value.startsWith(TRANSITION_LABEL_PREFIX) + ? value + : undefined; + /** A preview frame's clip list, keeping only clips whose timing and track are numbers. */ export function wellFormedClips(clips: readonly unknown[]): ClipManifestClip[] { - return clips.filter(wellFormedClip); + return clips.filter(wellFormedClip).map(({ transitionLabel, ...clip }) => { + const label = transitionLabelOf(transitionLabel); + return label ? { ...clip, transitionLabel: label } : clip; + }); } diff --git a/packages/studio/src/player/lib/playbackTypes.ts b/packages/studio/src/player/lib/playbackTypes.ts index d42916cbb5..b7bd51ad2f 100644 --- a/packages/studio/src/player/lib/playbackTypes.ts +++ b/packages/studio/src/player/lib/playbackTypes.ts @@ -47,6 +47,7 @@ export interface ClipManifestClip extends RuntimeTimelineClipIdentity { compositionAncestors?: string[]; playbackStart?: number; playbackRate?: number; + transitionLabel?: string; } export interface ClipManifest { diff --git a/packages/studio/src/player/lib/timelineDOM.test.ts b/packages/studio/src/player/lib/timelineDOM.test.ts index 011efe4530..7f74011801 100644 --- a/packages/studio/src/player/lib/timelineDOM.test.ts +++ b/packages/studio/src/player/lib/timelineDOM.test.ts @@ -428,6 +428,30 @@ describe("a sealed preview's text rows", () => { }); }); +describe("a sealed preview's transition labels", () => { + it("names a clip's transition from the runtime's clip message, with no page timelines to read", () => { + const row = createTimelineElementFromManifestClip({ + clip: { + id: "a", + label: "A", + kind: "element", + tagName: "div", + start: 0, + duration: 3, + track: 0, + compositionId: null, + parentCompositionId: null, + compositionSrc: null, + assetUrl: null, + transitionLabel: "hf:transition:a:b:fade", + }, + fallbackIndex: 0, + doc: makeDoc(`
`), + }); + expect(row.transitionLabel).toBe("hf:transition:a:b:fade"); + }); +}); + describe("group info cache", () => { const parseMember = (doc: Document) => createTimelineElementFromManifestClip({ diff --git a/packages/studio/src/player/lib/timelineDOM.ts b/packages/studio/src/player/lib/timelineDOM.ts index 6f985de87a..e3657ca674 100644 --- a/packages/studio/src/player/lib/timelineDOM.ts +++ b/packages/studio/src/player/lib/timelineDOM.ts @@ -20,7 +20,7 @@ import { previewWithoutFrameToken } from "./frameToken"; import { clipNumber, clipTrack } from "./manifestClips"; import { groupInfoFor } from "./timelineGroupInfo"; import { receivedTimelineText } from "./timelineText"; -import { transitionLabelsForDocument } from "./timelineTransitionMetadata"; +import { transitionLabelsForDocument } from "@hyperframes/core/studio-preview-mark"; import { resolveMediaElement, applyMediaMetadataFromElement, @@ -84,9 +84,6 @@ export function createTimelineElementFromManifestClip(params: { const { clip, fallbackIndex, doc } = params; const numericTrack = clipTrack(clip.track) ?? 0; let hostEl = params.hostEl ?? null; - const transitionLabels = doc - ? transitionLabelsForDocument(doc, (doc.defaultView as IframeWindow | null)?.__timelines) - : new Map(); const label = getTimelineElementDisplayLabel({ id: clip.id, label: clip.label, @@ -121,9 +118,7 @@ export function createTimelineElementFromManifestClip(params: { id: identity.id, label, transitionLabel: - (hostEl && transitionLabels.get(hostEl)) || - hostEl?.getAttribute("data-transition-label") || - undefined, + clip.transitionLabel || hostEl?.getAttribute("data-transition-label") || undefined, key: identity.key, kind: clip.kind, tag: resolveClipTag(clip), diff --git a/packages/studio/src/player/lib/timelineIframeHelpers.ts b/packages/studio/src/player/lib/timelineIframeHelpers.ts index 59d9292c56..befddaaab4 100644 --- a/packages/studio/src/player/lib/timelineIframeHelpers.ts +++ b/packages/studio/src/player/lib/timelineIframeHelpers.ts @@ -25,7 +25,7 @@ import { type PreviewTarget, } from "./timelineElementHelpers"; import { postRuntimeControlMessage } from "./runtimeProtocol"; -import { transitionLabelsForDocument } from "./timelineTransitionMetadata"; +import { transitionLabelsForDocument } from "@hyperframes/core/studio-preview-mark"; // --------------------------------------------------------------------------- // Viewport / DOM normalisation