Files
openmotion/shared/preview-timing.ts
open-design-crew[bot] 177fe119bb [OPEND-5496] Update ordinary timeline copies and splits in mounted previews (#972)
* Keep ordinary timeline copies and splits mounted in both previews

* Verify the inserted clip manifest reports the accepted revision

---------

Co-authored-by: lefarcen <935902669@qq.com>
2026-11-24 17:32:00 +08:00

62 lines
3.3 KiB
TypeScript

export const MAX_PEER_PREVIEW_SOURCE_LENGTH = 128 * 1024;
export type PreviewLiveEdits = { position?: true; mediaTiming?: true };
export const PREVIEW_ATTRIBUTES = [
"data-start", "data-end", "data-duration", "data-track-index", "data-playback-start", "data-media-start",
"data-timeline-locked", "data-hidden", "muted", "data-volume",
] as const;
/** Only values the player can reproduce from the mounted declarative document. */
export function canPatchPreviewAttribute(name: string, value: unknown, tag: string): boolean {
if ((name === "muted" || name === "data-volume") && tag !== "audio" && tag !== "video") return false;
if (value === null) return true;
if (typeof value !== "string") return false;
if (name === "data-timeline-locked" || name === "data-hidden" || name === "muted") {
return value === "" || value === "true" || value === name;
}
return /^\d+(?:\.\d+)?$/.test(value) && Number.isFinite(Number(value)) && (name !== "data-volume" || Number(value) <= 1);
}
// Properties set directly by the inspector or by the positioning gesture.
export const PRESENTATION_STYLES = ["position", "left", "top", "width", "height", "font-size", "font-weight", "font-family", "text-align", "color", "background-color", "background-image", "opacity", "translate"] as const;
/** Solid fills clear the image layer; canvas moves produce a one- or two-axis pixel offset. */
export function canPatchPresentationValue(name: string, value: string): boolean {
if (name === "background-image") return value === "none" || value === "";
if (name === "translate") return value === "" || value === "none" || /^-?(?:\d+\.?\d*|\.\d+)px(?: -?(?:\d+\.?\d*|\.\d+)px)?$/.test(value);
return true;
}
export const PRESENTATION_TAGS = ["div", "span", "p", "h1", "h2", "h3", "h4", "h5", "h6"] as const;
export const MAX_PREVIEW_TEXT_LENGTH = 4096;
/** The bundler preserves identified, numeric, direct visual leaves. No executable markup crosses the bridge. */
export type VisualClipInsert = {
owner: string;
next: string | null;
whitespace: [before: string, left: string, right: string];
attrs: [name: string, value: string][];
text: string;
};
export interface PreviewChange {
hfId: string | null;
id: string;
compositionId: string | null;
tag: string;
styles?: [typeof PRESENTATION_STYLES[number], string, string][];
/** A first canvas move captures the author's translate for Reset; undo removes the marker. */
captureOriginalTranslate?: boolean;
text?: [string, string];
/** Remove the verified visual leaf directly owned by this composition. */
removeFromComposition?: string;
insert?: VisualClipInsert;
attributes: [typeof PREVIEW_ATTRIBUTES[number], string | null, string | null][];
}
/** Used by Studio and the isolated bridge to validate the complete set of changes. */
export function isLivePositionEdit(changes: PreviewChange[]): boolean {
return Array.isArray(changes) && changes.length > 0 && changes.every(change =>
!change?.text && Array.isArray(change?.attributes) && change.attributes.length === 0 &&
Array.isArray(change.styles) && change.styles.length > 0 && change.styles.every(style =>
Array.isArray(style) && style.length === 3 && (style[0] === "left" || style[0] === "top") &&
style.slice(1).every(value => typeof value === "string" && (value === "" || /^-?(?:\d+\.?\d*|\.\d+)px$/.test(value)))));
}