@@ -124,7 +124,9 @@ function parseResolutionFromHtml(doc: Document): CanvasResolution | null {
124124 resolutionAttr === "landscape" ||
125125 resolutionAttr === "portrait" ||
126126 resolutionAttr === "landscape-4k" ||
127- resolutionAttr === "portrait-4k"
127+ resolutionAttr === "portrait-4k" ||
128+ resolutionAttr === "square" ||
129+ resolutionAttr === "square-4k"
128130 ) {
129131 return resolutionAttr ;
130132 }
@@ -143,17 +145,17 @@ function parseResolutionFromHtml(doc: Document): CanvasResolution | null {
143145}
144146
145147function resolveResolutionFromDimensions ( width : number , height : number ) : CanvasResolution {
146- // `width === height` (square) falls into the portrait branch by convention —
147- // the same bias the previous `w > h ? landscape : portrait` ternary used.
148- // Square compositions are rare; pick portrait-as-default so we don't surprise
149- // the existing call sites that depend on this behavior.
150- const isLandscape = width > height ;
151148 const longSide = Math . max ( width , height ) ;
152- // UHD cutoff is the long side of `landscape-4k` / `portrait-4k` (3840). A
153- // looser threshold (e.g. ≥ 2560) would silently misclassify QHD/1440p
154- // (2560×1440) as 4K, which is the wrong default for a common authoring
155- // resolution closer to 1080p than to UHD. Authors who genuinely want the
156- // 4K preset can still set `data-resolution="landscape-4k"` explicitly.
149+ // UHD cutoff is the long side of the 4K presets (3840 for `landscape-4k` /
150+ // `portrait-4k`, 2160 for `square-4k`). A looser threshold (e.g. >= 2560)
151+ // would silently misclassify QHD/1440p (2560x1440) as 4K, which is the
152+ // wrong default for a common authoring resolution closer to 1080p than to
153+ // UHD. Authors who genuinely want the 4K preset can still set
154+ // `data-resolution="..."` explicitly.
155+ if ( width === height ) {
156+ return longSide >= 2160 ? "square-4k" : "square" ;
157+ }
158+ const isLandscape = width > height ;
157159 const isUhd = longSide >= 3840 ;
158160 if ( isLandscape ) return isUhd ? "landscape-4k" : "landscape" ;
159161 return isUhd ? "portrait-4k" : "portrait" ;
0 commit comments