mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 14:27:26 +00:00
* perf(player): scope preview readiness to first frame * refactor(core): share runtime visibility timing * refactor(core): share readiness timing owner * test(core): pin readiness caller wiring * test(core): cover fonts in first-frame gate * fix(core): restore readiness test contract
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
export type AuthoredTimingValue = string | number | null | undefined;
|
|
|
|
export const AUTHORED_DURATION_ATTR = "data-hf-authored-duration";
|
|
export const AUTHORED_END_ATTR = "data-hf-authored-end";
|
|
|
|
export interface RawAuthoredTiming {
|
|
start?: AuthoredTimingValue;
|
|
duration?: AuthoredTimingValue;
|
|
authoredDuration?: AuthoredTimingValue;
|
|
end?: AuthoredTimingValue;
|
|
authoredEnd?: AuthoredTimingValue;
|
|
}
|
|
|
|
export interface AuthoredTimingWindow {
|
|
start: number;
|
|
duration: number | null;
|
|
end: number | null;
|
|
}
|
|
|
|
function finiteNumber(value: AuthoredTimingValue): number | null {
|
|
if (value == null) return null;
|
|
if (typeof value === "string" && value.trim() === "") return null;
|
|
const parsed = typeof value === "number" ? value : Number(value);
|
|
return Number.isFinite(parsed) ? parsed : null;
|
|
}
|
|
|
|
export function resolveAuthoredTimingWindow(
|
|
values: RawAuthoredTiming,
|
|
): AuthoredTimingWindow | null {
|
|
const parsedStart = finiteNumber(values.start);
|
|
if (parsedStart == null) return null;
|
|
const start = Math.max(0, parsedStart);
|
|
|
|
const publicDuration = finiteNumber(values.duration);
|
|
const preservedDuration = finiteNumber(values.authoredDuration);
|
|
const duration =
|
|
publicDuration != null && publicDuration > 0
|
|
? publicDuration
|
|
: preservedDuration != null && preservedDuration > 0
|
|
? preservedDuration
|
|
: null;
|
|
if (duration != null) return { start, duration, end: start + duration };
|
|
|
|
const publicEnd = finiteNumber(values.end);
|
|
const preservedEnd = finiteNumber(values.authoredEnd);
|
|
const end =
|
|
publicEnd != null && publicEnd > start
|
|
? publicEnd
|
|
: preservedEnd != null && preservedEnd > start
|
|
? preservedEnd
|
|
: null;
|
|
return { start, duration: end == null ? null : end - start, end };
|
|
}
|