mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* test(core): pin how the runtime resolves a composition's length and size * refactor(core): move composition length and root size rules into a pure module * test(core): pin the one-frame timeline floor against a derived length * fix(core): build and declare the composition-length subpath, reject a non-finite declared length
23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
import { isHtmlElement } from "./domRealm";
|
|
|
|
/** A `data-width`/`data-height` length in CSS px as the stage lays it out, fractions kept. */
|
|
export function parseLayoutDimension(value: string | null | undefined): number | null {
|
|
if (value == null || value.trim() === "") return null;
|
|
const parsed = Number.parseFloat(value);
|
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
}
|
|
|
|
/** The size the runtime reports to its host: whole px, read with `parseInt` as the renderer does. */
|
|
export function parseCompositionDimension(value: string | null | undefined): number | null {
|
|
if (value == null || value.trim() === "") return null;
|
|
const parsed = Number.parseInt(value, 10);
|
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
}
|
|
|
|
export function findRootCompositionElement(doc: ParentNode = document): HTMLElement | null {
|
|
const explicitRoot = doc.querySelector('[data-composition-id][data-root="true"]');
|
|
if (isHtmlElement(explicitRoot)) return explicitRoot;
|
|
// The first composition in document order never sits inside another one.
|
|
return doc.querySelector<HTMLElement>("[data-composition-id]");
|
|
}
|