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xC,MAAM,EAAS,cAAc,GAC7B,MAAsB,mBAAX,EACH,EAAO,GAER,CACR,CAEA,IAAI,EACJ,OAAQ,GACP,IAAK,MACJ,EAAW,UACV,IAEC,aAAa,IAAI,OAAO,EAAU,EAAc,CAC/C,OAAO,GAET,CAAE,MAAO,GACR,MAAM,aAAe,MAAQ,EAAM,IAAI,MAAM,OAAO,GACrD,GAED,MACD,IAAK,OAEJ,EAAW,EAAS,QAAQ,oBAAoB,CAAC,EAAG,IAC5C,EAAK,EAAI,SAAW,KAE5B,MAED,QACC,MAAM,EAAqB,WAAW,QAAQ,GAC9C,EAAW,GACV,QAAQ,QAAQ,EAAmB,IAOtC,OAHI,GAAY,IACf,cAAc,GAAY,GAEA,mBAAb,EAA0B,EAAS,GAAQ,CAC1D,QAIO,SAAS,qBACf,OAAO,KAAK,eAAe,SAAQ,WAC3B,cAAc,EAAI,GAE3B,CACA,MAAM,QAAU,CACf,wBACA,sBACA,sCAEA,QAAS,CACR,WAAY,WACZ,yBAGa","file":"/npm/pdf-node@1.5.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/pdf-node@1.5.0/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","import * as pdf from 'html-pdf';\nimport Handlebars from 'handlebars';\nimport * as ejs from 'ejs';\nimport handleError from 'cli-error-handler';\nconst templateCache = {};\nexport {Handlebars, ejs};\n/**\n * Generates a PDF from an HTML template and data\n * @param options PDF generation options\n * @returns Promise that resolves with the generated PDF (as buffer or file info)\n * @throws {Error} If required options are missing or PDF generation fails\n */\nexport function generatePDF(options) {\n\treturn new Promise(async (resolve, reject) => {\n\t\tif (!options || !options.html || !options.data) {\n\t\t\treject(new Error('Some, or all, options are missing.'));\n\t\t\treturn;\n\t\t}\n\t\tif (options.type !== undefined && options.type !== 'pdf') {\n\t\t\treject(new Error('Only PDF file type is supported'));\n\t\t\treturn;\n\t\t}\n\t\tconst pdfOptions = options.pdfOptions || {};\n\t\tconst useCache = options.cacheTemplate !== false; // Default to true\n\t\tconst engine = options.engine || 'handlebars';\n\t\t// Get compiled template\n\t\tlet html;\n\t\ttry {\n\t\t\thtml = await compileTemplate(\n\t\t\t\toptions.html,\n\t\t\t\toptions.data,\n\t\t\t\tengine,\n\t\t\t\tuseCache\n\t\t\t);\n\t\t} catch (error) {\n\t\t\thandleError('Error compiling template', error);\n\t\t\treject(error);\n\t\t\treturn;\n\t\t}\n\t\t// Check if buffer output is requested\n\t\tif (options.buffer === true) {\n\t\t\t// Output will be PDF buffer (useful for APIs/web services)\n\t\t\tpdf.create(html, pdfOptions).toBuffer(function (err, buffer) {\n\t\t\t\tif (err) {\n\t\t\t\t\thandleError('error in creating buffer', err);\n\t\t\t\t\treject(err);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconsole.log(\n\t\t\t\t\t'PDF buffer generated, size:',\n\t\t\t\t\tbuffer.length,\n\t\t\t\t\t'bytes'\n\t\t\t\t);\n\t\t\t\tresolve({\n\t\t\t\t\tbuffer: buffer,\n\t\t\t\t\tsize: buffer.length,\n\t\t\t\t\ttype: 'application/pdf'\n\t\t\t\t});\n\t\t\t});\n\t\t} else {\n\t\t\t// Output will be PDF file (default behavior)\n\t\t\tif (!options.path) {\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t'Path is required when buffer option is not set to true.'\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst filepath = options.path;\n\t\t\tpdf.create(html, pdfOptions).toFile(filepath, function (err, res) {\n\t\t\t\tif (err) {\n\t\t\t\t\thandleError('error in creating file', err);\n\t\t\t\t\treject(err);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconsole.log('file generated:', res.filename);\n\t\t\t\tresolve(res);\n\t\t\t});\n\t\t}\n\t});\n}\n/**\n * Adds a page break to the PDF\n * @returns HTML string with a page break\n */\nexport function addNewPage() {\n\treturn '<div style=\"page-break-after: always;\"></div>';\n}\n/**\n * Compiles a template with the specified engine\n * @param template The template string\n * @param data Data to inject into the template\n * @param engine Template engine to use ('handlebars', 'ejs', or 'html')\n * @param useCache Whether to cache the compiled template\n * @returns Compiled HTML string\n */\nasync function compileTemplate(\n\ttemplate,\n\tdata,\n\tengine = 'handlebars',\n\tuseCache = true\n) {\n\tconst cacheKey = useCache ? `${engine}:${template}` : null;\n\t// Return cached template if available\n\tif (cacheKey && templateCache[cacheKey]) {\n\t\tconst cached = templateCache[cacheKey];\n\t\tif (typeof cached === 'function') {\n\t\t\treturn cached(data);\n\t\t}\n\t\treturn cached;\n\t}\n\t// Compile and cache the template\n\tlet compiled;\n\tswitch (engine) {\n\t\tcase 'ejs':\n\t\t\tcompiled = async templateData => {\n\t\t\t\ttry {\n\t\t\t\t\t// Use the promise-based renderFile with a fake filename\n\t\t\t\t\treturn await ejs.render(template, templateData, {\n\t\t\t\t\t\tasync: true\n\t\t\t\t\t});\n\t\t\t\t} catch (err) {\n\t\t\t\t\tthrow err instanceof Error ? err : new Error(String(err));\n\t\t\t\t}\n\t\t\t};\n\t\t\tbreak;\n\t\tcase 'html':\n\t\t\t// Simple variable replacement for HTML mode\n\t\t\tcompiled = template.replace(/\\{\\{([^}]+)\\}\\}/g, (_, key) => {\n\t\t\t\treturn data[key.trim()] || '';\n\t\t\t});\n\t\t\tbreak;\n\t\tcase 'handlebars':\n\t\tdefault:\n\t\t\tconst handlebarsTemplate = Handlebars.compile(template);\n\t\t\tcompiled = templateData =>\n\t\t\t\tPromise.resolve(handlebarsTemplate(templateData));\n\t\t\tbreak;\n\t}\n\t// Cache the compiled template if needed\n\tif (useCache && cacheKey) {\n\t\ttemplateCache[cacheKey] = compiled;\n\t}\n\treturn typeof compiled === 'function' ? compiled(data) : compiled;\n}\n/**\n * Clears the template cache\n */\nexport function clearTemplateCache() {\n\tObject.keys(templateCache).forEach(key => {\n\t\tdelete templateCache[key];\n\t});\n}\nconst pdfNode = {\n\tgeneratePDF,\n\taddNewPage,\n\tclearTemplateCache,\n\t// Export template engines for advanced usage\n\tengines: {\n\t\thandlebars: Handlebars,\n\t\tejs\n\t}\n};\nexport default pdfNode;\n"]}