mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
refactor(studio): a preview clip's number and track rules live in one place (#8471)
This commit is contained in:
@@ -2,15 +2,20 @@ import type { ClipManifestClip } from "./playbackTypes";
|
||||
|
||||
const OPTIONAL_NUMBERS = ["zIndex", "playbackStart", "playbackRate"] as const;
|
||||
|
||||
const finiteNumber = (value: unknown): boolean =>
|
||||
typeof value === "number" && Number.isFinite(value);
|
||||
export const clipNumber = (value: unknown): number | null =>
|
||||
typeof value === "number" && Number.isFinite(value) ? value : null;
|
||||
|
||||
export const clipTrack = (value: unknown): number | null =>
|
||||
typeof value === "number" && Number.isSafeInteger(value) ? value : null;
|
||||
|
||||
function wellFormedClip(clip: unknown): clip is ClipManifestClip {
|
||||
if (typeof clip !== "object" || clip === null) return false;
|
||||
const fields = clip as Record<string, unknown>;
|
||||
if (!finiteNumber(fields.start) || !finiteNumber(fields.duration)) return false;
|
||||
if (!Number.isInteger(fields.track)) return false;
|
||||
return OPTIONAL_NUMBERS.every((name) => fields[name] == null || finiteNumber(fields[name]));
|
||||
if (clipNumber(fields.start) === null || clipNumber(fields.duration) === null) return false;
|
||||
if (clipTrack(fields.track) === null) return false;
|
||||
return OPTIONAL_NUMBERS.every(
|
||||
(name) => fields[name] == null || clipNumber(fields[name]) !== null,
|
||||
);
|
||||
}
|
||||
|
||||
/** A preview frame's clip list, keeping only clips whose timing and track are numbers. */
|
||||
|
||||
@@ -17,7 +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 { previewWithoutFrameToken } from "./frameToken";
|
||||
import { finiteNumber } from "../../components/editor/manualEditsParsing";
|
||||
import { clipNumber, clipTrack } from "./manifestClips";
|
||||
import { groupInfoFor } from "./timelineGroupInfo";
|
||||
import { receivedTimelineText } from "./timelineText";
|
||||
import { transitionLabelsForDocument } from "./timelineTransitionMetadata";
|
||||
@@ -82,7 +82,7 @@ export function createTimelineElementFromManifestClip(params: {
|
||||
hostEl?: Element | null;
|
||||
}): TimelineElement {
|
||||
const { clip, fallbackIndex, doc } = params;
|
||||
const numericTrack = Number.isSafeInteger(clip.track) ? clip.track : 0;
|
||||
const numericTrack = clipTrack(clip.track) ?? 0;
|
||||
let hostEl = params.hostEl ?? null;
|
||||
const transitionLabels = doc
|
||||
? transitionLabelsForDocument(doc, (doc.defaultView as IframeWindow | null)?.__timelines)
|
||||
@@ -127,8 +127,8 @@ export function createTimelineElementFromManifestClip(params: {
|
||||
key: identity.key,
|
||||
kind: clip.kind,
|
||||
tag: resolveClipTag(clip),
|
||||
start: finiteNumber(clip.start) ?? 0,
|
||||
duration: finiteNumber(clip.duration) ?? 0,
|
||||
start: clipNumber(clip.start) ?? 0,
|
||||
duration: clipNumber(clip.duration) ?? 0,
|
||||
track: numericTrack,
|
||||
// clip.track IS the authored data-track-index verbatim (the runtime honors
|
||||
// it; see parseAuthoredTrack in core/runtime/timeline.ts). Record it at this
|
||||
|
||||
Reference in New Issue
Block a user