mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 23:00:03 +00:00
fix(studio): fit preview reset to composition dimensions (#1085)
* fix(studio): fit preview reset to composition dimensions * fix(core): keep runtime root resolution explicit * fix(studio): resume playback after keep-playing seek
This commit is contained in:
@@ -36,6 +36,24 @@ export interface ProbeCallbacks {
|
||||
onRuntimeInjected?: () => void;
|
||||
}
|
||||
|
||||
function readPositiveDimension(value: string | null): number | null {
|
||||
if (value === null) return null;
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
||||
}
|
||||
|
||||
export function readCompositionSizeFromDocument(
|
||||
doc: Document | null | undefined,
|
||||
): { width: number; height: number } | null {
|
||||
const root =
|
||||
doc?.querySelector("[data-composition-id][data-width][data-height]") ??
|
||||
doc?.querySelector("[data-width][data-height]");
|
||||
if (!root) return null;
|
||||
const width = readPositiveDimension(root.getAttribute("data-width"));
|
||||
const height = readPositiveDimension(root.getAttribute("data-height"));
|
||||
return width !== null && height !== null ? { width, height } : null;
|
||||
}
|
||||
|
||||
export class CompositionProbe {
|
||||
private _interval: ReturnType<typeof setInterval> | null = null;
|
||||
private _runtimeInjected = false;
|
||||
@@ -45,6 +63,7 @@ export class CompositionProbe {
|
||||
private readonly _callbacks: ProbeCallbacks,
|
||||
) {}
|
||||
|
||||
// fallow-ignore-next-line unused-class-member
|
||||
get runtimeInjected(): boolean {
|
||||
return this._runtimeInjected;
|
||||
}
|
||||
@@ -55,6 +74,7 @@ export class CompositionProbe {
|
||||
this._runtimeInjected = false;
|
||||
let attempts = 0;
|
||||
|
||||
// fallow-ignore-next-line complexity
|
||||
this._interval = setInterval(() => {
|
||||
attempts++;
|
||||
try {
|
||||
@@ -89,14 +109,7 @@ export class CompositionProbe {
|
||||
if (adapter && adapter.getDuration() > 0) {
|
||||
this.stop();
|
||||
|
||||
const doc = this._iframe.contentDocument;
|
||||
let compositionSize: { width: number; height: number } | null = null;
|
||||
const root = doc?.querySelector("[data-composition-id]");
|
||||
if (root) {
|
||||
const w = parseInt(root.getAttribute("data-width") || "0", 10);
|
||||
const h = parseInt(root.getAttribute("data-height") || "0", 10);
|
||||
if (w > 0 && h > 0) compositionSize = { width: w, height: h };
|
||||
}
|
||||
const compositionSize = readCompositionSizeFromDocument(this._iframe.contentDocument);
|
||||
|
||||
this._callbacks.onReady({
|
||||
duration: adapter.getDuration(),
|
||||
@@ -135,6 +148,7 @@ export class CompositionProbe {
|
||||
}
|
||||
}
|
||||
|
||||
// fallow-ignore-next-line unused-class-member
|
||||
resolveDirectTimelineAdapterFromWindow(win: Window): DirectTimelineAdapter | null {
|
||||
return this._resolveDirectTimelineAdapterFromWindow(win);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user