* 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, )
| 1049 | * hook over its timeout — see the note on `renderLocal browser GPU config`). |
| 1050 | */ |
| 1051 | async 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 |
no test coverage detected