MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / readCompositionDimensions

Function readCompositionDimensions

packages/cli/src/commands/render.ts:1051–1066  ·  view source on GitHub ↗

* Read a composition's dimensions from the SAME source the producer's compiler * uses — `data-width` / `data-height` on the `[data-composition-id]` root (see * htmlCompiler.ts). Returns `undefined` when they can't be determined (no root, * missing/invalid attrs, unparseable HTML). Note the produc

(
  compositionHtml: string,
)

Source from the content-addressed store, hash-verified

1049 * hook over its timeout — see the note on `renderLocal browser GPU config`).
1050 */
1051async function readCompositionDimensions(
1052 compositionHtml: string,
1053): Promise<{ width: number; height: number } | undefined> {
1054 try {
1055 const { ensureDOMParser } = await import("../utils/dom.js");
1056 ensureDOMParser();
1057 const doc = new DOMParser().parseFromString(compositionHtml, "text/html");
1058 const rootEl = doc.querySelector("[data-composition-id]");
1059 const width = parseInt(rootEl?.getAttribute("data-width") ?? "", 10);
1060 const height = parseInt(rootEl?.getAttribute("data-height") ?? "", 10);
1061 if (width > 0 && height > 0) return { width, height };
1062 } catch {
1063 // Unreadable / unparseable composition — fall through to `undefined`.
1064 }
1065 return undefined;
1066}
1067
1068/**
1069 * Render pre-flight: return an actionable message when the chosen

Callers 1

Calls 3

ensureDOMParserFunction · 0.85
querySelectorMethod · 0.65
getAttributeMethod · 0.65

Tested by

no test coverage detected