Files
hyperframes/packages/core/src/runtime/compositionDimension.ts
T
Miguel Ángel 77b2260f2b fix(core): report one composition size in stage-size and timeline messages (#4496)
* fix(core): report one composition size in stage-size and timeline messages

The runtime posted the composition size twice per timeline post, read two
ways: stage-size used the lenient reader the stage layout uses, the timeline
payload a strict one. A root with data-width="1080px" reached the player as
1080x1920, then 1920x1080, so a portrait film was framed as a cropped
landscape picture. Both messages and the stage layout now share
parseCompositionDimension, and stage-size sends the value unrounded.

* fix(core): the layout diagnostic and nested roots read the same composition size

* fix(core): read composition sizes as whole px, as the renderer and Studio do

* chore(core): one comment line on the composition size reader

* fix(core): keep fractional layout sizes and report the same root in both size messages

Layout (the stage, timed clips, flattened nested roots, the layout
diagnostic) reads data-width/data-height as before, fractions kept. Only the
size the runtime reports in stage-size and timeline reads whole px. Both
messages and the stage layout now take the root from one finder, so an
earlier composition no longer replaces the explicit data-root's size.

* fix(core): use the size messages root for the clip tree and analytics
2026-09-25 21:59:01 +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(): HTMLElement | null {
const explicitRoot = document.querySelector('[data-composition-id][data-root="true"]');
if (isHtmlElement(explicitRoot)) return explicitRoot;
// The first composition in document order never sits inside another one.
return document.querySelector<HTMLElement>("[data-composition-id]");
}