Files
hyperframes/packages/core/src/runtime/compositionDimension.ts
T
Miguel Ángel 34ff5ca1de refactor(core): one pure owner for composition length and root size (#4990)
* 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
2026-10-04 08:16:20 +00:00

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]");
}