fix(studio): a sealed preview's timeline shows its text clips' words and look (#8228)

* fix(studio): a sealed preview's timeline shows its text clips' words and look

A sealed preview's timeline rows come from the clip list the film sends, which
carried no text, so its text clips drew as blank rows. The film now sends each
plain text layer's words (up to 200 characters) and look, read by the same rule
Studio uses for its own rows, and the row shows the words as plain text.

* fix(studio): check a sealed clip's text on arrival, cap only what the film sends

Studio now takes a clip's text from the film's message only when every field is
text within the film's limits; otherwise the clip keeps its row without words.
The 200-character limit applies to the film's message alone, so an open
preview's own rows keep their full words as before.
This commit is contained in:
Miguel Ángel
2026-11-19 03:51:53 +00:00
committed by GitHub
parent 4abbdc3e0d
commit 1cf98cf892
11 changed files with 199 additions and 31 deletions
@@ -1,4 +1,5 @@
// How an element is addressed in source: one rule for Studio and the runtime's editing agent.
import { isHtmlElement } from "./domRealm";
/** Names an element's source file. The parent resolves it: `file`, else its composition map. */
export interface EditingElementSource {
@@ -65,6 +66,52 @@ export const MAX_SOURCE_GROUPS = 64;
export const MAX_DESCRIBE_HANDLES = 256;
export const MAX_POINT_STACK = 64;
export const MAX_QUERY_MATCHES = 2_048;
export const MAX_TIMELINE_TEXT = 200;
const TEXT_TAGS = new Set(["div", "span", "p", "strong", "h1", "h2", "h3", "h4", "h5", "h6"]);
function isTextBearingTag(tagName: string): boolean {
return TEXT_TAGS.has(tagName);
}
export function isEditableTextLeaf(el: HTMLElement): boolean {
return isTextBearingTag(el.tagName.toLowerCase()) && el.children.length === 0;
}
/** A text layer's words and computed look, as its timeline row draws them. */
export interface TextLayerRead {
value: string;
fontFamily: string;
fontWeight: string;
color: string;
backgroundColor: string;
}
/** A layer that paints only text on a flat colour, read; null for anything painted beyond that. */
export function readTextLayer(el: Element): TextLayerRead | null {
if (!isHtmlElement(el) || !isTextBearingTag(el.localName)) return null;
if (!Array.from(el.children).every((child) => isHtmlElement(child) && isEditableTextLeaf(child)))
return null;
const words = (el.textContent ?? "").replace(/\s+/g, " ").trim();
if (!words) return null;
const style = el.ownerDocument.defaultView?.getComputedStyle(el);
if (!style || (style.backgroundImage || "none") !== "none") return null;
const { fontFamily, fontWeight, color, backgroundColor } = style;
return { value: words, fontFamily, fontWeight, color, backgroundColor };
}
/** A text layer as the runtime's clip list sends it: the words and each style value capped. */
export function readSentTextLayer(el: Element): TextLayerRead | null {
const read = readTextLayer(el);
if (!read) return null;
return {
value: read.value.slice(0, MAX_TIMELINE_TEXT),
fontFamily: read.fontFamily.slice(0, MAX_ELEMENT_VALUE),
fontWeight: read.fontWeight.slice(0, MAX_ELEMENT_VALUE),
color: read.color.slice(0, MAX_ELEMENT_VALUE),
backgroundColor: read.backgroundColor.slice(0, MAX_ELEMENT_VALUE),
};
}
// fallow-ignore-next-line complexity
function escapeCssIdentifier(value: string): string {
+4
View File
@@ -77,12 +77,15 @@ export {
buildStableSelector,
escapeCssString,
getPreferredClassSelector,
isEditableTextLeaf,
readElementSource,
readTextLayer,
EDITING_ELEMENT_HANDLE,
MAX_DESCRIBE_HANDLES,
MAX_ELEMENT_ENTRIES,
MAX_ELEMENT_TEXT,
MAX_ELEMENT_VALUE,
MAX_TIMELINE_TEXT,
MAX_POINT_STACK,
MAX_QUERY_MATCHES,
MAX_SOURCE_GROUPS,
@@ -92,6 +95,7 @@ export {
type EditingElementMatch,
type EditingElementSource,
type EditingRect,
type TextLayerRead,
} from "./editingElement";
export {
elementCornerPoints,
@@ -136,6 +136,31 @@ describe("collectRuntimeTimelinePayload", () => {
expect(result.clips[0].kind).toBe("element");
});
it("sends a plain text layer's words and look, capped, and no text for any other layer", () => {
const root = document.createElement("div");
root.setAttribute("data-composition-id", "main");
root.setAttribute("data-duration", "10");
document.body.appendChild(root);
const title = document.createElement("h1");
title.id = "title";
title.setAttribute("data-start", "0");
title.setAttribute("data-duration", "5");
title.style.color = "rgb(255, 255, 255)";
title.textContent = ` Hello\n ${"x".repeat(500)} `;
const card = document.createElement("div");
card.id = "card";
card.setAttribute("data-start", "0");
card.setAttribute("data-duration", "5");
card.innerHTML = "<img src='a.png'> Caption";
root.append(title, card);
const [titleClip, cardClip] = collectRuntimeTimelinePayload(defaultParams).clips;
expect(titleClip.text?.value).toBe(`Hello ${"x".repeat(194)}`);
expect(titleClip.text?.color).toBe("rgb(255, 255, 255)");
expect(cardClip.text).toBeNull();
});
it("parses inline z-index for timeline clips", () => {
const root = document.createElement("div");
root.setAttribute("data-composition-id", "main");
+4
View File
@@ -28,6 +28,7 @@ import { isSceneLikeCompositionId } from "../slideshow/index.js";
import { COMPOSITION_CONTRACT_VERSION } from "../compositionContract.js";
import { runtimeProtocolMetadata } from "./protocol.js";
import { isElementNode, isMediaElement } from "./domRealm";
import { readSentTextLayer } from "./editingElement";
import { LOOP_INFLATED_TIMELINE_SECONDS } from "./compositionLength";
import { cutToHostSlots } from "../mediaTiming";
@@ -502,6 +503,7 @@ export function collectRuntimeTimelinePayload(params: {
timelineLabel: node.getAttribute("data-timeline-label"),
timelineGroup: node.getAttribute("data-timeline-group"),
timelinePriority: parseNum(node.getAttribute("data-timeline-priority")),
text: readSentTextLayer(node),
};
};
const addClip = (clip: RuntimeTimelineClip) => {
@@ -632,6 +634,7 @@ export function collectRuntimeTimelinePayload(params: {
timelineLabel: el.getAttribute("data-timeline-label"),
timelineGroup: el.getAttribute("data-timeline-group"),
timelinePriority: parseNum(el.getAttribute("data-timeline-priority")),
text: readSentTextLayer(el),
});
gsapClipIds.add(el.id);
}
@@ -689,6 +692,7 @@ export function collectRuntimeTimelinePayload(params: {
timelineLabel: el.getAttribute("data-timeline-label"),
timelineGroup: el.getAttribute("data-timeline-group"),
timelinePriority: parseNum(el.getAttribute("data-timeline-priority")),
text: readSentTextLayer(el),
});
gsapClipIds.add(el.id);
}
+2
View File
@@ -1,6 +1,7 @@
import type { HfColorGradingTarget } from "../colorGrading";
import type { PreviewTarget } from "../studioPreviewMark";
import type { RuntimeAnalyticsEvent } from "./analytics";
import type { TextLayerRead } from "./editingElement";
import type { AudioFades } from "../audioFade";
import type { RateSpec } from "../speedRamp";
import type { VolumeKeyframe } from "./mediaVolumeEnvelope";
@@ -97,6 +98,7 @@ export type RuntimeTimelineClip = RuntimeTimelineClipIdentity & {
timelineLabel: string | null;
timelineGroup: string | null;
timelinePriority: number | null;
text: TextLayerRead | null;
};
export type RuntimeTimelineScene = {
@@ -8,6 +8,7 @@ import {
buildStableSelector,
escapeCssString,
getPreferredClassSelector,
isEditableTextLeaf,
isElementVisibleThroughAncestors,
readElementSource,
type EditingElementSource,
@@ -34,13 +35,7 @@ export function isHtmlElement(value: unknown): value is HTMLElement {
// module's public surface (6 studio callers import parsePx from it).
export { parsePx } from "@hyperframes/core/editing";
export function isTextBearingTag(tagName: string): boolean {
return ["div", "span", "p", "strong", "h1", "h2", "h3", "h4", "h5", "h6"].includes(tagName);
}
export function isEditableTextLeaf(el: HTMLElement): boolean {
return isTextBearingTag(el.tagName.toLowerCase()) && el.children.length === 0;
}
export { isEditableTextLeaf };
export { getLogicalOpacity };
// One addressing rule for Studio and the runtime that describes elements to it.
@@ -1,5 +1,7 @@
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { textClipBackground } from "./TextClipContent";
import { TextClipContent, textClipBackground } from "./TextClipContent";
describe("textClipBackground", () => {
it("puts dark text on a light strip and light text on a dark one", () => {
@@ -17,3 +19,16 @@ describe("textClipBackground", () => {
).toBe("rgb(230, 57, 70)");
});
});
describe("TextClipContent", () => {
it("shows a film's words as plain text, never as markup", () => {
const value = '<img src="x" onerror="alert(1)"><b>Title</b>';
const html = renderToStaticMarkup(createElement(TextClipContent, { text: { value } }));
expect(html).not.toContain("<img");
expect(html).not.toContain("<b>");
expect(html).toContain(
"&lt;img src=&quot;x&quot; onerror=&quot;alert(1)&quot;&gt;&lt;b&gt;Title&lt;/b&gt;",
);
});
});
@@ -41,6 +41,7 @@ export interface TimelineLike {
}
export interface ClipManifestClip extends RuntimeTimelineClipIdentity {
text?: unknown;
zIndex?: number;
stackingContextId?: string | null;
compositionAncestors?: string[];
@@ -11,6 +11,7 @@ import { clipTimingStart, resolveClipTimingBasis } from "../../hooks/gsapShared"
import { toAuthoredStart } from "../store/timelineElement";
import { computeResizePreview } from "../components/timelineClipDragPreview";
import type { TimelineElement } from "../store/playerStore";
import { readTimelineText } from "./timelineText";
import {
MAX_PLAYBACK_RATE,
MIN_PLAYBACK_RATE,
@@ -314,6 +315,66 @@ describe("parseTimelineFromDOM — hfId from data-hf-id", () => {
});
});
describe("a sealed preview's text rows", () => {
const LOOK = {
fontFamily: "Inter",
fontWeight: "700",
color: "rgb(255, 255, 255)",
backgroundColor: "rgba(0, 0, 0, 0)",
};
const rowFor = (text: unknown) =>
createTimelineElementFromManifestClip({
clip: {
id: "title",
label: "Title",
kind: "element",
tagName: "h1",
start: 0,
duration: 5,
track: 0,
compositionId: null,
parentCompositionId: null,
compositionSrc: null,
assetUrl: null,
text,
},
fallbackIndex: 0,
});
it("draws a text layer from the words and look in the runtime's clip message", () => {
expect(rowFor({ value: "Title", ...LOOK }).text).toEqual({
value: "Title",
fontFamily: "Inter",
fontWeight: "700",
color: "rgb(255, 255, 255)",
background: undefined,
});
});
it("keeps the clip and drops a text field that is missing, not text, or over the runtime's cap", () => {
for (const text of [
{ value: "Title" },
{ ...LOOK, value: 5 },
{ ...LOOK, value: "x".repeat(201) },
{ ...LOOK, value: "Title", color: "x".repeat(2_001) },
"Title",
]) {
const row = rowFor(text);
expect(row.id).toBe("title");
expect(row.text).toBeUndefined();
}
});
it("leaves an open preview's own text rows uncapped", () => {
const title = document.createElement("h1");
title.textContent = "x".repeat(500);
document.body.appendChild(title);
expect(readTimelineText(title)?.value).toHaveLength(500);
title.remove();
});
});
describe("group info cache", () => {
const parseMember = (doc: Document) =>
createTimelineElementFromManifestClip({
@@ -17,6 +17,7 @@ import { readMasterFxChain } from "@hyperframes/core/audio-groups";
import { linkScopeOf } from "@hyperframes/core/media-link";
import { createRuntimeStartTimeResolver } from "@hyperframes/core/runtime/start-resolver";
import { groupInfoFor } from "./timelineGroupInfo";
import { receivedTimelineText } from "./timelineText";
import { transitionLabelsForDocument } from "./timelineTransitionMetadata";
import {
resolveMediaElement,
@@ -178,6 +179,7 @@ export function createTimelineElementFromManifestClip(params: {
entry.zIndex = readTimelineElementZIndex(hostEl);
}
if (clip.assetUrl) entry.src = clip.assetUrl;
entry.text ??= receivedTimelineText(clip.text);
if (clip.kind === "composition" && clip.compositionId) {
entry.playbackStart ??= 0;
entry.playbackRate ??= 1;
+35 -23
View File
@@ -1,33 +1,45 @@
import { isHtmlElement } from "@hyperframes/core/runtime/dom-realm";
import {
MAX_ELEMENT_VALUE,
MAX_TIMELINE_TEXT,
readTextLayer,
type TextLayerRead,
} from "@hyperframes/core/runtime/editing-port";
import { parseCssColor } from "../../components/editor/colorValue";
import type { TimelineText } from "../store/timelineElement";
import {
getCuratedComputedStyles,
isEditableTextLeaf,
isTextBearingTag,
} from "../../components/editor/domEditingDom";
/** A layer that paints only text and a flat colour (a text tag whose children are all text leaves,
* no background image): its words and look. Anything painted beyond that keeps its picture. */
export function readTimelineText(el: Element): TimelineText | undefined {
if (!isHtmlElement(el) || !isTextBearingTag(el.localName)) return undefined;
const children = Array.from(el.children);
if (!children.every((child) => isHtmlElement(child) && isEditableTextLeaf(child)))
return undefined;
const value = el.textContent?.replace(/\s+/g, " ").trim();
if (!value) return undefined;
const style = getCuratedComputedStyles(el);
if ((style["background-image"] ?? "none") !== "none") return undefined;
const background = style["background-color"];
function timelineTextOf(read: TextLayerRead | null): TimelineText | undefined {
if (!read) return undefined;
const { backgroundColor, ...look } = read;
return {
value,
fontFamily: style["font-family"],
fontWeight: style["font-weight"],
color: style.color,
background: background && parseCssColor(background)?.alpha === 1 ? background : undefined,
...look,
background: parseCssColor(backgroundColor)?.alpha === 1 ? backgroundColor : undefined,
};
}
const isSentText = (value: unknown, max: number): value is string =>
typeof value === "string" && value.length <= max;
/** The runtime's text read from a clip message: null unless every field is text within the runtime's caps. */
function receivedTextLayer(raw: unknown): TextLayerRead | null {
if (typeof raw !== "object" || raw === null) return null;
const { value, fontFamily, fontWeight, color, backgroundColor } = raw as Record<string, unknown>;
return isSentText(value, MAX_TIMELINE_TEXT) &&
isSentText(fontFamily, MAX_ELEMENT_VALUE) &&
isSentText(fontWeight, MAX_ELEMENT_VALUE) &&
isSentText(color, MAX_ELEMENT_VALUE) &&
isSentText(backgroundColor, MAX_ELEMENT_VALUE)
? { value, fontFamily, fontWeight, color, backgroundColor }
: null;
}
export function readTimelineText(el: Element): TimelineText | undefined {
return timelineTextOf(readTextLayer(el));
}
export function receivedTimelineText(raw: unknown): TimelineText | undefined {
return timelineTextOf(receivedTextLayer(raw));
}
export function sameTimelineText(a?: TimelineText, b?: TimelineText): boolean {
if (!a || !b) return a === b;
return (