(doc: Document, cssText: string | null)
| 97 | } |
| 98 | |
| 99 | function 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 | |
| 134 | function parseResolutionFromHtml(doc: Document): CanvasResolution | null { |
| 135 | const htmlEl = doc.documentElement; |
no test coverage detected