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,EAAU,GAAc,CAC1B,OAAQ,CAAE,IAAK,QAAS,MAAO,OAAQ,OAAQ,QAAS,KAAM,QAC9D,OAAQ,MAEZ,IAAK,EACD,IACI,MAAM,QAAY,EAAK,KAAK,IAAI,GAEhC,aADM,KAAK,UAAU,QAAQ,GACtB,CACX,CACA,MAAO,GAEH,YADM,KAAK,UAAU,QAAQ,GACvB,CACV,CAEJ,IACI,IAAI,GAAW,EACf,aAAc,EAAK,KAAK,gBAAgB,IACnC,KAAK,SAAS,KACV,IACD,GAAW,EACX,KAAK,UAAU,QAAQ,GAAM,OAAM,KAAe,IACtD,IAEC,KAAK,SAAS,KACV,IACD,GAAW,EACX,KAAK,UAAU,QAAQ,GAAM,OAAM,KAAe,IACtD,IAEC,KAAK,OAAO,KACR,IACD,GAAW,EACX,KAAK,UAAU,QAAQ,GAAM,OAAM,KAAe,IACtD,GAER,CACA,MAAO,GAEH,YADM,KAAK,UAAU,QAAQ,GAAM,OAAM,KAAe,IAClD,CACV,CACJ,EAEJ,QAAQ,aAAe","file":"/npm/hpdf@1.0.3/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/hpdf@1.0.3/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.PdfGenerator = void 0;\nconst generic_pool_1 = require(\"generic-pool\");\nconst puppeteer_1 = __importDefault(require(\"puppeteer\"));\nclass PageFactory {\n    constructor(puppeteerArgs) {\n        this.puppeteerArgs = puppeteerArgs;\n    }\n    async create() {\n        const browser = await puppeteer_1.default.launch({\n            headless: 'new',\n            args: this.puppeteerArgs || ['--no-sandbox', '--disable-setuid-sandbox'],\n        });\n        return {\n            browser,\n            page: await browser.newPage(),\n        };\n    }\n    async destroy(client) {\n        try {\n            if (client.browser.isConnected()) {\n                await client.browser.close();\n            }\n        }\n        catch {\n            return;\n        }\n    }\n    async validate(client) {\n        try {\n            return !!(await client.page.metrics());\n        }\n        catch {\n            return false;\n        }\n    }\n}\nclass PdfGenerator {\n    /**\n     * @param poolConfig https://github.com/coopernurse/node-pool/blob/1c5cb79dcbea27c4b1839bd75bfc41274adb8b94/lib/PoolOptions.js#L5\n     * @param puppeteerArgs https://peter.sh/experiments/chromium-command-line-switches/\n     */\n    constructor(poolConfig = { min: 1, max: 10 }, puppeteerArgs) {\n        this.pagesPool = (0, generic_pool_1.createPool)(new PageFactory(puppeteerArgs), {\n            testOnBorrow: true,\n            evictionRunIntervalMillis: 5000,\n            ...poolConfig,\n            autostart: true,\n        });\n    }\n    async stop() {\n        await this.pagesPool.drain();\n        await this.pagesPool.clear();\n    }\n    async awaitPool() {\n        return this.pagesPool.ready();\n    }\n    async generatePDF(htmlOrUrl, stream = false, pdfOptions) {\n        const page = await this.pagesPool.acquire();\n        try {\n            if (htmlOrUrl instanceof URL) {\n                await page.page.goto(htmlOrUrl.toString(), {\n                    waitUntil: 'networkidle0',\n                });\n            }\n            else {\n                await page.page.setContent(htmlOrUrl, { waitUntil: 'networkidle0' });\n            }\n            //To reflect CSS used for screens instead of print\n            await page.page.emulateMediaType('print');\n        }\n        catch (e) {\n            await this.pagesPool.release(page);\n            throw e;\n        }\n        const options = pdfOptions || {\n            margin: { top: '100px', right: '50px', bottom: '100px', left: '50px' },\n            format: 'A4',\n        };\n        if (!stream) {\n            try {\n                const res = await page.page.pdf(options);\n                await this.pagesPool.release(page);\n                return res;\n            }\n            catch (e) {\n                await this.pagesPool.destroy(page);\n                throw e;\n            }\n        }\n        try {\n            let released = false;\n            return (await page.page.createPDFStream(options))\n                .once('error', () => {\n                if (!released) {\n                    released = true;\n                    this.pagesPool.destroy(page).catch(() => undefined);\n                }\n            })\n                .once('close', () => {\n                if (!released) {\n                    released = true;\n                    this.pagesPool.release(page).catch(() => undefined);\n                }\n            })\n                .once('end', () => {\n                if (!released) {\n                    released = true;\n                    this.pagesPool.release(page).catch(() => undefined);\n                }\n            });\n        }\n        catch (e) {\n            await this.pagesPool.destroy(page).catch(() => undefined);\n            throw e;\n        }\n    }\n}\nexports.PdfGenerator = PdfGenerator;\n"]}