Skip to content

Commit 19bceae

Browse files
committed
fix(style): make pptx aspect-ratio regex attribute-order independent
1 parent 105c65f commit 19bceae

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

apps/sim/lib/copilot/vfs/document-style.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ function parsePptxPresentation(xml: string): {
346346
const sldIdLst = between(xml, '<p:sldIdLst>', '</p:sldIdLst>')
347347
const slideCount = (sldIdLst.match(/<p:sldId\b/g) ?? []).length
348348

349-
// Slide size in EMU — 1 inch = 914400 EMU
350-
const sldSzMatch = /<p:sldSz\b[^>]*\bcx="(\d+)"[^>]*\bcy="(\d+)"/.exec(xml)
349+
// Slide size in EMU — 1 inch = 914400 EMU. Capture cx/cy independently so
350+
// attribute order (LibreOffice/Google Slides may write cy before cx) doesn't matter.
351+
const cxMatch = /<p:sldSz\b[^>]*\bcx="(\d+)"/.exec(xml)
352+
const cyMatch = /<p:sldSz\b[^>]*\bcy="(\d+)"/.exec(xml)
351353
let aspectRatio: '16:9' | '4:3' | 'custom' = 'custom'
352-
if (sldSzMatch) {
353-
const cx = Number.parseInt(sldSzMatch[1])
354-
const cy = Number.parseInt(sldSzMatch[2])
354+
if (cxMatch && cyMatch) {
355+
const cx = Number.parseInt(cxMatch[1])
356+
const cy = Number.parseInt(cyMatch[1])
355357
const ratio = cx / cy
356-
// 16:9 ≈ 1.7778 (covers both 9144000×5143500 and 12192000×6858000)
357-
// 4:3 ≈ 1.3333 (9144000×6858000 or 10×7.5 inches)
358358
if (Math.abs(ratio - 16 / 9) < 0.01) aspectRatio = '16:9'
359359
else if (Math.abs(ratio - 4 / 3) < 0.01) aspectRatio = '4:3'
360360
}

0 commit comments

Comments
 (0)