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

Function parseResolutionFromCss

packages/parsers/src/htmlParser.ts:99–132  ·  view source on GitHub ↗
(doc: Document, cssText: string | null)

Source from the content-addressed store, hash-verified

97}
98
99function parseResolutionFromCss(doc: Document, cssText: string | null): CanvasResolution {
100 const stage = doc.getElementById("stage") || doc.querySelector("#stage");
101 if (stage) {
102 const inlineStyle = (stage as HTMLElement).style;
103 if (inlineStyle?.width && inlineStyle?.height) {
104 const w = parseInt(inlineStyle.width, 10);
105 const h = parseInt(inlineStyle.height, 10);
106 if (w && h) {
107 return resolveResolutionFromDimensions(w, h);
108 }
109 }
110 }
111
112 if (cssText) {
113 const stageMatch = cssText.match(
114 /#stage\s*\{[^}]*width:\s*(\d+)px[^}]*height:\s*(\d+)px[^}]*\}/,
115 );
116 if (stageMatch) {
117 const w = parseInt(stageMatch[1] ?? "", 10);
118 const h = parseInt(stageMatch[2] ?? "", 10);
119 return resolveResolutionFromDimensions(w, h);
120 }
121 const stageMatchReverse = cssText.match(
122 /#stage\s*\{[^}]*height:\s*(\d+)px[^}]*width:\s*(\d+)px[^}]*\}/,
123 );
124 if (stageMatchReverse) {
125 const h = parseInt(stageMatchReverse[1] ?? "", 10);
126 const w = parseInt(stageMatchReverse[2] ?? "", 10);
127 return resolveResolutionFromDimensions(w, h);
128 }
129 }
130
131 return "portrait";
132}
133
134function parseResolutionFromHtml(doc: Document): CanvasResolution | null {
135 const htmlEl = doc.documentElement;

Callers 1

parseHtmlFunction · 0.85

Calls 2

querySelectorMethod · 0.65

Tested by

no test coverage detected