(htmlFile, pres, options = {})
| 894 | } |
| 895 | |
| 896 | async function html2pptx(htmlFile, pres, options = {}) { |
| 897 | const { |
| 898 | tmpDir = process.env.TMPDIR || '/tmp', |
| 899 | slide = null |
| 900 | } = options; |
| 901 | |
| 902 | try { |
| 903 | // Use Chrome on macOS, default Chromium on Unix |
| 904 | const launchOptions = { env: { TMPDIR: tmpDir } }; |
| 905 | if (process.platform === 'darwin') { |
| 906 | launchOptions.channel = 'chrome'; |
| 907 | } |
| 908 | |
| 909 | const browser = await chromium.launch(launchOptions); |
| 910 | |
| 911 | let bodyDimensions; |
| 912 | let slideData; |
| 913 | |
| 914 | const filePath = path.isAbsolute(htmlFile) ? htmlFile : path.join(process.cwd(), htmlFile); |
| 915 | const validationErrors = []; |
| 916 | |
| 917 | try { |
| 918 | const page = await browser.newPage(); |
| 919 | page.on('console', (msg) => { |
| 920 | // Log the message text to your test runner's console |
| 921 | console.log(`Browser console: ${msg.text()}`); |
| 922 | }); |
| 923 | |
| 924 | await page.goto(`file://${filePath}`); |
| 925 | |
| 926 | bodyDimensions = await getBodyDimensions(page); |
| 927 | |
| 928 | await page.setViewportSize({ |
| 929 | width: Math.round(bodyDimensions.width), |
| 930 | height: Math.round(bodyDimensions.height) |
| 931 | }); |
| 932 | |
| 933 | slideData = await extractSlideData(page); |
| 934 | } finally { |
| 935 | await browser.close(); |
| 936 | } |
| 937 | |
| 938 | // Collect all validation errors |
| 939 | if (bodyDimensions.errors && bodyDimensions.errors.length > 0) { |
| 940 | validationErrors.push(...bodyDimensions.errors); |
| 941 | } |
| 942 | |
| 943 | const dimensionErrors = validateDimensions(bodyDimensions, pres); |
| 944 | if (dimensionErrors.length > 0) { |
| 945 | validationErrors.push(...dimensionErrors); |
| 946 | } |
| 947 | |
| 948 | const textBoxPositionErrors = validateTextBoxPosition(slideData, bodyDimensions); |
| 949 | if (textBoxPositionErrors.length > 0) { |
| 950 | validationErrors.push(...textBoxPositionErrors); |
| 951 | } |
| 952 | |
| 953 | if (slideData.errors && slideData.errors.length > 0) { |
nothing calls this directly
no test coverage detected