@paprize/puppeteer 0.0.12 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,44 @@
1
- # Changelog
1
+ # @paprize/puppeteer
2
2
 
3
- All notable changes to this project will be documented in this file.
3
+ ## 0.2.0
4
4
 
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+ ### Minor Changes
7
6
 
8
- ## [Unreleased]
7
+ - Updated dependencies [8e2ef6e]
8
+ - @paprize/core@0.2.0
9
+
10
+ ## 0.1.0
11
+
12
+ ### Minor Changes
13
+
14
+ ### Added
15
+
16
+ - 909306c: Expand Zero report configs for sections (#24 (https://github.com/your-repo/pull/24))
17
+
18
+ ### Changed
19
+
20
+ Improve log message for Zero report fallback (#20 (https://github.com/your-repo/pull/20))
21
+
22
+ ## 0.0.12
23
+
24
+ ### Patch Changes
25
+
26
+ - 33f727c: update dependencies
27
+
28
+ ## 0.0.11
29
+
30
+ ### Patch Changes
31
+
32
+ - 89f4841: updated to use latest vanilla
33
+
34
+ ## 0.0.10
35
+
36
+ ### Patch Changes
37
+
38
+ - 307425f: fix empty package issue
39
+
40
+ ## 0.0.9
41
+
42
+ ### Patch Changes
43
+
44
+ - 673b94e: switch to pnpm
package/README.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # Paprize
2
2
 
3
- Design your report using the full power of JavaScript and CSS, mark the report section by paprize components and then paprize pagination engine will transforming it into a beautiful, professional, print-ready pages.
3
+ **Build clean, print-ready reports with familiar web tools.**
4
4
 
5
- ![Components](https://raw.githubusercontent.com/PejmanNik/paprize/refs/heads/main/website/static/img/components.svg)
5
+ Paprize is a report-generation toolkit that lets you design pages with JavaScript/TypeScript, React, and CSS. Mark your layout with Paprize components, then let its pagination engine split content into polished, printable pages.
6
+
7
+ ## Documentation
8
+
9
+ For guides, API references, and full examples, visit [paprize.page](https://paprize.page).
10
+
11
+ ## Why Paprize
12
+
13
+ - **Web-native authoring**: Build reports with standard HTML and CSS.
14
+ - **Automatic pagination**: Split long content into pages without manual slicing.
15
+ - **Composable layout primitives**: Structure reports with sections, headers, footers, and content wrappers.
16
+ - **Print-ready output**: Configure A4, Letter, or custom sizes and margins.
17
+
18
+ ![Paprize components](https://raw.githubusercontent.com/PejmanNik/paprize/refs/heads/main/website/static/img/components.svg)
19
+
20
+ ## Packages
21
+
22
+ - `@paprize/react`: React components for report layout and pagination.
23
+ - `@paprize/vanilla`: Framework-agnostic DOM API.
24
+ - `@paprize/puppeteer`: PDF rendering adapter for server-side generation.
25
+
26
+ ## Installation
27
+
28
+ Choose one UI package (`react` or `vanilla`), and if you need server-side PDF generation, pair it with the Puppeteer adapter.
29
+
30
+ ```bash
31
+ # React
32
+ npm install @paprize/react @paprize/puppeteer
33
+
34
+ # Vanilla JavaScript/TypeScript
35
+ npm install @paprize/vanilla @paprize/puppeteer
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### Vanilla HTML
41
+
42
+ ```html
43
+ <div data-pz-preview>
44
+ <div data-pz-section>
45
+ <div data-pz-page-header>
46
+ <h2>Page <span data-pz-v-page-number></span></h2>
47
+ </div>
48
+
49
+ <div data-pz-page-content>...</div>
50
+ </div>
51
+ </div>
52
+ ```
53
+
54
+ ### React
55
+
56
+ ```tsx
57
+ function App() {
58
+ return (
59
+ <ReportRoot>
60
+ <ReportPreview>
61
+ <Section size={pageSize.A4}>
62
+ <PageHeader>
63
+ <Header />
64
+ </PageHeader>
65
+
66
+ <PageContent>
67
+ <Finance />
68
+ <Business />
69
+ </PageContent>
70
+
71
+ <PageFooter>
72
+ <Footer />
73
+ </PageFooter>
74
+ </Section>
75
+ </ReportPreview>
76
+ </ReportRoot>
77
+ );
78
+ }
79
+ ```
@@ -1,78 +1 @@
1
- import { default as default_2 } from 'http';
2
- import { Page } from 'puppeteer-core';
3
- import { PDFOptions } from 'puppeteer-core';
4
-
5
- /**
6
- * Opens a report in the given Puppeteer page, injects a JSON data file if provided,
7
- * and waits for the report to be ready.
8
- *
9
- * @param page - The Puppeteer `Page` instance where the report will be opened.
10
- * @param reportUrl - The URL of the report to be opened.
11
- * @param jsonData - Optional JSON data to be injected into the page.
12
- * @param timeout - The maximum time to wait for the report to be ready, in milliseconds. Defaults to 30,000 ms.
13
- * @returns A promise that resolves when the report is ready.
14
- * @throws Will throw an error if the report does not become ready within the specified timeout.
15
- */
16
- export declare function openReport(page: Page, reportUrl: URL, jsonData: unknown | undefined, timeout?: number): Promise<void>;
17
-
18
- /**
19
- * Generates a PDF from the given Puppeteer `Page` instance using the specified options.
20
- *
21
- * @param page - The Puppeteer `Page` instance to generate the PDF from.
22
- * @param options - Optional additional options to customize the PDF generation. These options
23
- * will be merged with the default settings.
24
- * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.
25
- */
26
- export declare function pageToPdf(page: Page, options?: ReportOptions): Promise<Uint8Array>;
27
-
28
- /**
29
- * Predefined static Paprize PDF options.
30
- *
31
- * including:
32
- * - waitForFonts: true
33
- * - printBackground: true
34
- * - displayHeaderFooter: false
35
- * - preferCSSPageSize: true
36
- * - margin: all sides 0px
37
- */
38
- export declare const paprizeOptions: PDFOptions;
39
-
40
- /**
41
- * Options for generating a PDF report with Paprize.
42
- * extends Puppeteer's [PDFOptions](https://pptr.dev/api/puppeteer.pdfoptions)
43
- * , excluding options that are already set by Paprize {@link paprizeOptions}
44
- */
45
- export declare type ReportOptions = Omit<PDFOptions, keyof typeof paprizeOptions>;
46
-
47
- export declare interface ReportServer {
48
- server: default_2.Server;
49
- close: () => void;
50
- getHost: () => string;
51
- }
52
-
53
- /**
54
- * Generates a PDF from a report by navigating to the specified report URL
55
- * and optionally sending JSON data to the page.
56
- *
57
- * @param page - The Puppeteer `Page` instance used to interact with the report.
58
- * @param reportUrl - The URL of the report to be converted to a PDF.
59
- * @param jsonData - Optional JSON data to be sent to the report page.
60
- * @param pdfOptions - Optional configuration for generating the PDF, including timeout and other settings.
61
- * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.
62
- */
63
- export declare function reportToPdf(page: Page, reportUrl: URL, jsonData?: unknown, pdfOptions?: PDFOptions): Promise<Uint8Array>;
64
-
65
- /**
66
- * Serves a static report from the specified directory over HTTP.
67
- *
68
- * @param dir - The directory containing the static files to serve.
69
- * @param port - Optional. The port on which the server will listen. If not provided, a random available port will be used.
70
- * @returns A promise that resolves to a `ReportServer` object, which provides methods to close the server and retrieve its host URL.
71
- *
72
- * The server serves files from the specified directory and automatically rewrites requests
73
- * to `/index.html` for any unmatched routes. Subdirectories in the specified directory are
74
- * mapped to corresponding routes.
75
- */
76
- export declare function serveReport(dir: string, port?: number): Promise<ReportServer>;
77
-
78
1
  export { }
@@ -38,19 +38,19 @@ function setupLogger(page) {
38
38
  const text = msg.text();
39
39
  switch (type) {
40
40
  case "error":
41
- logger.error(`[browser] ${text}`);
41
+ logger.error(`error: ${text}`);
42
42
  break;
43
43
  case "warn":
44
- logger.warn(`[browser] ${text}`);
44
+ logger.warn(`warn: ${text}`);
45
45
  break;
46
46
  case "debug":
47
- logger.debug(`[browser] ${text}`);
47
+ logger.debug(`debug: ${text}`);
48
48
  break;
49
49
  case "info":
50
- logger.info(`[browser] ${text}`);
50
+ logger.info(`info: ${text}`);
51
51
  break;
52
52
  default:
53
- logger.log(`[browser] ${text}`);
53
+ logger.log(`log: ${text}`);
54
54
  }
55
55
  });
56
56
  }
@@ -69,8 +69,8 @@ async function openReport(page, reportUrl, jsonData, timeout = 3e4) {
69
69
  await page.waitForFunction(`window.${paprize_isInitialized} === true`, {
70
70
  timeout: 100
71
71
  }).catch(() => {
72
- logger2.warn(
73
- "The page is not a valid paprize report. Using paprize fallback zero report."
72
+ logger2.info(
73
+ "Using Zero report mode (standard Paprize report format not detected)"
74
74
  );
75
75
  return page.addScriptTag({
76
76
  type: "module",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/options.ts", "../src/pageToPdf.ts", "../src/openReport.ts", "../src/setupLogger.ts", "../src/serveReport.ts", "../src/reportToPdf.ts"],
4
- "sourcesContent": ["import type { PDFOptions } from 'puppeteer-core';\n\n/**\n * Predefined static Paprize PDF options.\n *\n * including:\n * - waitForFonts: true\n * - printBackground: true\n * - displayHeaderFooter: false\n * - preferCSSPageSize: true\n * - margin: all sides 0px\n */\nexport const paprizeOptions: PDFOptions = {\n waitForFonts: true,\n printBackground: true,\n displayHeaderFooter: false,\n headerTemplate: undefined,\n footerTemplate: undefined,\n preferCSSPageSize: true,\n margin: {\n bottom: '0px',\n left: '0px',\n right: '0px',\n top: '0px',\n },\n} as const;\n\n/**\n * Options for generating a PDF report with Paprize.\n * extends Puppeteer's [PDFOptions](https://pptr.dev/api/puppeteer.pdfoptions)\n * , excluding options that are already set by Paprize {@link paprizeOptions}\n */\nexport type ReportOptions = Omit<PDFOptions, keyof typeof paprizeOptions>;\n", "import type { Page } from 'puppeteer-core';\nimport { paprizeOptions, type ReportOptions } from './options';\n\n/**\n * Generates a PDF from the given Puppeteer `Page` instance using the specified options.\n *\n * @param page - The Puppeteer `Page` instance to generate the PDF from.\n * @param options - Optional additional options to customize the PDF generation. These options\n * will be merged with the default settings.\n * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.\n */\nexport function pageToPdf(\n page: Page,\n options?: ReportOptions\n): Promise<Uint8Array> {\n return page.pdf({\n ...paprizeOptions,\n ...options,\n });\n}\n", "import type { Page } from 'puppeteer-core';\nimport {\n logger,\n paprize_isInitialized,\n paprize_isReady,\n paprize_readJsonDataFile,\n} from '@paprize/core';\nimport { setupLogger } from './setupLogger';\n\n/**\n * Opens a report in the given Puppeteer page, injects a JSON data file if provided,\n * and waits for the report to be ready.\n *\n * @param page - The Puppeteer `Page` instance where the report will be opened.\n * @param reportUrl - The URL of the report to be opened.\n * @param jsonData - Optional JSON data to be injected into the page.\n * @param timeout - The maximum time to wait for the report to be ready, in milliseconds. Defaults to 30,000 ms.\n * @returns A promise that resolves when the report is ready.\n * @throws Will throw an error if the report does not become ready within the specified timeout.\n */\nexport async function openReport(\n page: Page,\n reportUrl: URL,\n jsonData: unknown | undefined,\n timeout: number = 30000\n): Promise<void> {\n setupLogger(page);\n\n const jsonDataStr = jsonData ? JSON.stringify(jsonData) : null;\n await page.exposeFunction(paprize_readJsonDataFile, () => {\n return jsonDataStr;\n });\n\n await page.goto(reportUrl.toString(), {\n waitUntil: 'networkidle0',\n timeout,\n });\n\n await page\n .waitForFunction(`window.${paprize_isInitialized} === true`, {\n timeout: 100,\n })\n .catch(() => {\n logger.warn(\n 'The page is not a valid paprize report. Using paprize fallback zero report.'\n );\n\n return page.addScriptTag({\n type: 'module',\n path: `${import.meta.dirname}/paprize-zero.js`,\n });\n });\n\n await page\n .waitForFunction(`window.${paprize_isReady} === true`, {\n timeout,\n })\n .catch(() => {\n throw new Error(\n 'The report did not become ready within the specified timeout.'\n );\n });\n}\n", "import { logger } from '@paprize/core';\nimport type { Page } from 'puppeteer-core';\n\nexport function setupLogger(page: Page) {\n page.on('console', (msg) => {\n const type = msg.type();\n const text = msg.text();\n\n switch (type) {\n case 'error':\n logger.error(`[browser] ${text}`);\n break;\n case 'warn':\n logger.warn(`[browser] ${text}`);\n break;\n case 'debug':\n logger.debug(`[browser] ${text}`);\n break;\n case 'info':\n logger.info(`[browser] ${text}`);\n break;\n default:\n logger.log(`[browser] ${text}`);\n }\n });\n}\n", "import http from 'http';\nimport type { AddressInfo } from 'node:net';\nimport handler from 'serve-handler';\nimport { promises as fs } from 'fs';\n\nexport interface ReportServer {\n server: http.Server;\n close: () => void;\n getHost: () => string;\n}\n\n/**\n * Serves a static report from the specified directory over HTTP.\n *\n * @param dir - The directory containing the static files to serve.\n * @param port - Optional. The port on which the server will listen. If not provided, a random available port will be used.\n * @returns A promise that resolves to a `ReportServer` object, which provides methods to close the server and retrieve its host URL.\n *\n * The server serves files from the specified directory and automatically rewrites requests\n * to `/index.html` for any unmatched routes. Subdirectories in the specified directory are\n * mapped to corresponding routes.\n */\nexport async function serveReport(\n dir: string,\n port?: number\n): Promise<ReportServer> {\n const staticDirectories = (await fs.readdir(dir, { withFileTypes: true }))\n .filter((x) => x.isDirectory())\n .map((x) => ({ source: x.name, destination: `/${x.name}` }));\n\n const server = http.createServer(\n async (req: http.IncomingMessage, res: http.ServerResponse) => {\n await handler(req, res, {\n public: dir,\n rewrites: [\n ...staticDirectories,\n { source: '**', destination: '/index.html' },\n ],\n });\n }\n );\n\n server.listen(port);\n const address = server.address() as AddressInfo;\n\n return {\n server,\n close: () => server.close(),\n getHost: () => `http://localhost:${address.port}`,\n };\n}\n", "import type { Page, PDFOptions } from 'puppeteer-core';\nimport { openReport } from './openReport';\nimport { pageToPdf } from './pageToPdf';\n\n/**\n * Generates a PDF from a report by navigating to the specified report URL\n * and optionally sending JSON data to the page.\n *\n * @param page - The Puppeteer `Page` instance used to interact with the report.\n * @param reportUrl - The URL of the report to be converted to a PDF.\n * @param jsonData - Optional JSON data to be sent to the report page.\n * @param pdfOptions - Optional configuration for generating the PDF, including timeout and other settings.\n * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.\n */\nexport async function reportToPdf(\n page: Page,\n reportUrl: URL,\n jsonData?: unknown,\n pdfOptions?: PDFOptions\n): Promise<Uint8Array> {\n await openReport(page, reportUrl, jsonData, pdfOptions?.timeout);\n return await pageToPdf(page, pdfOptions);\n}\n"],
5
- "mappings": ";AAYO,IAAM,iBAA6B;AAAA,EACtC,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,QAAQ;AAAA,IACJ,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,EACT;AACJ;;;ACdO,SAAS,UACZ,MACA,SACmB;AACnB,SAAO,KAAK,IAAI;AAAA,IACZ,GAAG;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AA,IACJ;AAAA,EACJ,CAAC;AACT;;;AE9DA,OAAO,UAAU;AAEjB,OAAO,aAAa;AACpB,SAAS,YAAY,UAAU;AAmB/B,eAAsB,YAClB,KACA,MACqB;AACrB,QAAM,qBAAqB,MAAM,GAAG,QAAQ,KAAK,EAAE,eAAe,KAAK,CAAC,GACnE,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,EAC7B,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,IAAI,EAAE,IAAI,GAAG,EAAE;AAE/D,QAAM,SAAS,KAAK;AAAA,IAChB,OAAO,KAA2B,QAA6B;AAC3D,YAAM,QAAQ,KAAK,KAAK;AAAA,QACpB,QAAQ;AAAA,QACR,UAAU;AAAA,UACN,GAAG;AAAA,UACH,EAAE,QAAQ,MAAM,aAAa,cAAc;AAAA,QAC/C;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,EACJ;AAEA,SAAO,OAAO,IAAI;AAClB,QAAM,UAAU,OAAO,QAAQ;AAE/B,SAAO;AAAA,IACH;AAAA,IACA,OAAO,MAAM,OAAO,MAAM;AAAA,IAC1B,SAAS,MAAM,oBAAoB,QAAQ,IAAI;AAAA,EACnD;AACJ;;;ACpCA,eAAsB,YAClB,MACA,WACA,UACA,YACmB;AACnB,QAAM,WAAW,MAAM,WAAW,UAAU,YAAY,OAAO;AAC/D,SAAO,MAAM,UAAU,MAAM,UAAU;AAC3C;",
4
+ "sourcesContent": ["import type { PDFOptions } from 'puppeteer-core';\n\n/**\n * Predefined static Paprize PDF options.\n *\n * including:\n * - waitForFonts: true\n * - printBackground: true\n * - displayHeaderFooter: false\n * - preferCSSPageSize: true\n * - margin: all sides 0px\n */\nexport const paprizeOptions: PDFOptions = {\n waitForFonts: true,\n printBackground: true,\n displayHeaderFooter: false,\n headerTemplate: undefined,\n footerTemplate: undefined,\n preferCSSPageSize: true,\n margin: {\n bottom: '0px',\n left: '0px',\n right: '0px',\n top: '0px',\n },\n} as const;\n\n/**\n * Options for generating a PDF report with Paprize.\n * extends Puppeteer's [PDFOptions](https://pptr.dev/api/puppeteer.pdfoptions)\n * , excluding options that are already set by Paprize {@link paprizeOptions}\n */\nexport type ReportOptions = Omit<PDFOptions, keyof typeof paprizeOptions>;\n", "import type { Page } from 'puppeteer-core';\nimport { paprizeOptions, type ReportOptions } from './options';\n\n/**\n * Generates a PDF from the given Puppeteer `Page` instance using the specified options.\n *\n * @param page - The Puppeteer `Page` instance to generate the PDF from.\n * @param options - Optional additional options to customize the PDF generation. These options\n * will be merged with the default settings.\n * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.\n */\nexport function pageToPdf(\n page: Page,\n options?: ReportOptions\n): Promise<Uint8Array> {\n return page.pdf({\n ...paprizeOptions,\n ...options,\n });\n}\n", "import type { Page } from 'puppeteer-core';\nimport {\n logger,\n paprize_isInitialized,\n paprize_isReady,\n paprize_readJsonDataFile,\n} from '@paprize/core';\nimport { setupLogger } from './setupLogger';\n\n/**\n * Opens a report in the given Puppeteer page, injects a JSON data file if provided,\n * and waits for the report to be ready.\n *\n * @param page - The Puppeteer `Page` instance where the report will be opened.\n * @param reportUrl - The URL of the report to be opened.\n * @param jsonData - Optional JSON data to be injected into the page.\n * @param timeout - The maximum time to wait for the report to be ready, in milliseconds. Defaults to 30,000 ms.\n * @returns A promise that resolves when the report is ready.\n * @throws Will throw an error if the report does not become ready within the specified timeout.\n */\nexport async function openReport(\n page: Page,\n reportUrl: URL,\n jsonData: unknown | undefined,\n timeout: number = 30000\n): Promise<void> {\n setupLogger(page);\n\n const jsonDataStr = jsonData ? JSON.stringify(jsonData) : null;\n await page.exposeFunction(paprize_readJsonDataFile, () => {\n return jsonDataStr;\n });\n\n await page.goto(reportUrl.toString(), {\n waitUntil: 'networkidle0',\n timeout,\n });\n\n await page\n .waitForFunction(`window.${paprize_isInitialized} === true`, {\n timeout: 100,\n })\n .catch(() => {\n logger.info(\n 'Using Zero report mode (standard Paprize report format not detected)'\n );\n\n return page.addScriptTag({\n type: 'module',\n path: `${import.meta.dirname}/paprize-zero.js`,\n });\n });\n\n await page\n .waitForFunction(`window.${paprize_isReady} === true`, {\n timeout,\n })\n .catch(() => {\n throw new Error(\n 'The report did not become ready within the specified timeout.'\n );\n });\n}\n", "import { logger } from '@paprize/core';\nimport type { Page } from 'puppeteer-core';\n\nexport function setupLogger(page: Page) {\n page.on('console', (msg) => {\n const type = msg.type();\n const text = msg.text();\n\n switch (type) {\n case 'error':\n logger.error(`error: ${text}`);\n break;\n case 'warn':\n logger.warn(`warn: ${text}`);\n break;\n case 'debug':\n logger.debug(`debug: ${text}`);\n break;\n case 'info':\n logger.info(`info: ${text}`);\n break;\n default:\n logger.log(`log: ${text}`);\n }\n });\n}\n", "import http from 'http';\nimport type { AddressInfo } from 'node:net';\nimport handler from 'serve-handler';\nimport { promises as fs } from 'fs';\n\nexport interface ReportServer {\n server: http.Server;\n close: () => void;\n getHost: () => string;\n}\n\n/**\n * Serves a static report from the specified directory over HTTP.\n *\n * @param dir - The directory containing the static files to serve.\n * @param port - Optional. The port on which the server will listen. If not provided, a random available port will be used.\n * @returns A promise that resolves to a `ReportServer` object, which provides methods to close the server and retrieve its host URL.\n *\n * The server serves files from the specified directory and automatically rewrites requests\n * to `/index.html` for any unmatched routes. Subdirectories in the specified directory are\n * mapped to corresponding routes.\n */\nexport async function serveReport(\n dir: string,\n port?: number\n): Promise<ReportServer> {\n const staticDirectories = (await fs.readdir(dir, { withFileTypes: true }))\n .filter((x) => x.isDirectory())\n .map((x) => ({ source: x.name, destination: `/${x.name}` }));\n\n const server = http.createServer(\n async (req: http.IncomingMessage, res: http.ServerResponse) => {\n await handler(req, res, {\n public: dir,\n rewrites: [\n ...staticDirectories,\n { source: '**', destination: '/index.html' },\n ],\n });\n }\n );\n\n server.listen(port);\n const address = server.address() as AddressInfo;\n\n return {\n server,\n close: () => server.close(),\n getHost: () => `http://localhost:${address.port}`,\n };\n}\n", "import type { Page, PDFOptions } from 'puppeteer-core';\nimport { openReport } from './openReport';\nimport { pageToPdf } from './pageToPdf';\n\n/**\n * Generates a PDF from a report by navigating to the specified report URL\n * and optionally sending JSON data to the page.\n *\n * @param page - The Puppeteer `Page` instance used to interact with the report.\n * @param reportUrl - The URL of the report to be converted to a PDF.\n * @param jsonData - Optional JSON data to be sent to the report page.\n * @param pdfOptions - Optional configuration for generating the PDF, including timeout and other settings.\n * @returns A promise that resolves to a `Uint8Array` containing the generated PDF data.\n */\nexport async function reportToPdf(\n page: Page,\n reportUrl: URL,\n jsonData?: unknown,\n pdfOptions?: PDFOptions\n): Promise<Uint8Array> {\n await openReport(page, reportUrl, jsonData, pdfOptions?.timeout);\n return await pageToPdf(page, pdfOptions);\n}\n"],
5
+ "mappings": ";AAYO,IAAM,iBAA6B;AAAA,EACtC,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,QAAQ;AAAA,IACJ,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,OAAO;AAAA,IACP,KAAK;AAAA,EACT;AACJ;;;ACdO,SAAS,UACZ,MACA,SACmB;AACnB,SAAO,KAAK,IAAI;AAAA,IACZ,GAAG;AAAA,IACH,GAAG;AAAA,EACP,CAAC;AACL;;;AClBA;AAAA,EACI,UAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;;;ACNP,SAAS,cAAc;AAGhB,SAAS,YAAY,MAAY;AACpC,OAAK,GAAG,WAAW,CAAC,QAAQ;AACxB,UAAM,OAAO,IAAI,KAAK;AACtB,UAAM,OAAO,IAAI,KAAK;AAEtB,YAAQ,MAAM;AAAA,MACV,KAAK;AACD,eAAO,MAAM,UAAU,IAAI,EAAE;AAC7B;AAAA,MACJ,KAAK;AACD,eAAO,KAAK,SAAS,IAAI,EAAE;AAC3B;AAAA,MACJ,KAAK;AACD,eAAO,MAAM,UAAU,IAAI,EAAE;AAC7B;AAAA,MACJ,KA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