mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-26 00:57:05 +00:00
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
This commit is contained in:
@@ -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 = `
|
||||
<div id="a" data-start="0" data-duration="3" data-track-index="0"></div>
|
||||
<div id="b" data-start="2" data-duration="3" data-track-index="0"></div>
|
||||
<div id="c" data-start="5" data-duration="3" data-track-index="0"></div>`;
|
||||
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");
|
||||
|
||||
@@ -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<string, RuntimeTimelineLike | undefined>;
|
||||
};
|
||||
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);
|
||||
}
|
||||
|
||||
+5
-7
@@ -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<string, number>;
|
||||
getLabels?: () => Record<string, number>;
|
||||
};
|
||||
@@ -30,13 +28,13 @@ function findTimedElement(doc: Document, markerId: string): Element | null {
|
||||
|
||||
export function transitionLabelsForDocument(
|
||||
doc: Document,
|
||||
timelines: Readonly<Record<string, TimelineLike>> | undefined,
|
||||
timelines: Readonly<Record<string, object | undefined>> | undefined,
|
||||
): ReadonlyMap<Element, string> {
|
||||
const labels = new Map<Element, string>();
|
||||
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<TimelineWithLabels | undefined>) {
|
||||
const timelineLabels = timeline?.getLabels?.() ?? timeline?.labels ?? {};
|
||||
for (const label of Object.keys(timelineLabels)) {
|
||||
const pair = transitionParts(label);
|
||||
if (!pair) continue;
|
||||
@@ -99,6 +99,7 @@ export type RuntimeTimelineClip = RuntimeTimelineClipIdentity & {
|
||||
timelineGroup: string | null;
|
||||
timelinePriority: number | null;
|
||||
text: TextLayerRead | null;
|
||||
transitionLabel: string | null;
|
||||
};
|
||||
|
||||
export type RuntimeTimelineScene = {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ export interface ClipManifestClip extends RuntimeTimelineClipIdentity {
|
||||
compositionAncestors?: string[];
|
||||
playbackStart?: number;
|
||||
playbackRate?: number;
|
||||
transitionLabel?: string;
|
||||
}
|
||||
|
||||
export interface ClipManifest {
|
||||
|
||||
@@ -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(`<div id="a" data-start="0" data-duration="3"></div>`),
|
||||
});
|
||||
expect(row.transitionLabel).toBe("hf:transition:a:b:fade");
|
||||
});
|
||||
});
|
||||
|
||||
describe("group info cache", () => {
|
||||
const parseMember = (doc: Document) =>
|
||||
createTimelineElementFromManifestClip({
|
||||
|
||||
@@ -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<Element, string>();
|
||||
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),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user