@paprize/puppeteer 0.0.12 → 0.1.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 +34 -5
- package/README.md +76 -2
- package/dist/paprize-puppeteer.d.ts +0 -77
- package/dist/paprize-puppeteer.js +7 -7
- package/dist/paprize-puppeteer.js.map +2 -2
- package/dist/paprize-zero.js +79 -45
- package/dist/paprize-zero.js.map +4 -4
- package/package.json +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @paprize/puppeteer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 0.1.0
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
5
|
+
### Minor Changes
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- 909306c: Expand Zero report configs for sections (#24 (https://github.com/your-repo/pull/24))
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
Improve log message for Zero report fallback (#20 (https://github.com/your-repo/pull/20))
|
|
14
|
+
|
|
15
|
+
## 0.0.12
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 33f727c: update dependencies
|
|
20
|
+
|
|
21
|
+
## 0.0.11
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 89f4841: updated to use latest vanilla
|
|
26
|
+
|
|
27
|
+
## 0.0.10
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- 307425f: fix empty package issue
|
|
32
|
+
|
|
33
|
+
## 0.0.9
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 673b94e: switch to pnpm
|
package/README.md
CHANGED
|
@@ -1,5 +1,79 @@
|
|
|
1
1
|
# Paprize
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Build clean, print-ready reports with familiar web tools.**
|
|
4
4
|
|
|
5
|
-
|
|
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
|
+

|
|
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(`
|
|
41
|
+
logger.error(`error: ${text}`);
|
|
42
42
|
break;
|
|
43
43
|
case "warn":
|
|
44
|
-
logger.warn(`
|
|
44
|
+
logger.warn(`warn: ${text}`);
|
|
45
45
|
break;
|
|
46
46
|
case "debug":
|
|
47
|
-
logger.debug(`
|
|
47
|
+
logger.debug(`debug: ${text}`);
|
|
48
48
|
break;
|
|
49
49
|
case "info":
|
|
50
|
-
logger.info(`
|
|
50
|
+
logger.info(`info: ${text}`);
|
|
51
51
|
break;
|
|
52
52
|
default:
|
|
53
|
-
logger.log(`
|
|
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.
|
|
73
|
-
"
|
|
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.
|
|
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,
|
|
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": "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",
|
|
6
6
|
"names": ["logger", "logger"]
|
|
7
7
|
}
|
package/dist/paprize-zero.js
CHANGED
|
@@ -290,6 +290,12 @@ var sectionClassName = "pz-section";
|
|
|
290
290
|
var previewClassName = "pz-preview";
|
|
291
291
|
var attributePrefix = "data-pz-";
|
|
292
292
|
|
|
293
|
+
// ../core/src/logger.ts
|
|
294
|
+
var import_loglevel = __toESM(require_loglevel(), 1);
|
|
295
|
+
var logger = import_loglevel.default.getLogger(loggerName);
|
|
296
|
+
logger.setDefaultLevel("info");
|
|
297
|
+
var logger_default = logger;
|
|
298
|
+
|
|
293
299
|
// ../core/src/debugUtilities/debugMode.ts
|
|
294
300
|
var debugMode = false;
|
|
295
301
|
var isDebugMode = () => debugMode;
|
|
@@ -346,9 +352,7 @@ function assignAttribute(key, reader, value, attributes) {
|
|
|
346
352
|
return;
|
|
347
353
|
}
|
|
348
354
|
const parsedValue = reader(value);
|
|
349
|
-
|
|
350
|
-
attributes[key] = parsedValue;
|
|
351
|
-
}
|
|
355
|
+
attributes[key] = parsedValue;
|
|
352
356
|
}
|
|
353
357
|
function getNodeLayoutOptionsFromAttribute(node) {
|
|
354
358
|
if (!node) {
|
|
@@ -381,12 +385,6 @@ function resolvePaginationOptions(node, globalConfig) {
|
|
|
381
385
|
return { ...defaultPaginationOptions, ...globalConfig, ...attributes };
|
|
382
386
|
}
|
|
383
387
|
|
|
384
|
-
// ../core/src/logger.ts
|
|
385
|
-
var import_loglevel = __toESM(require_loglevel(), 1);
|
|
386
|
-
var logger = import_loglevel.default.getLogger(loggerName);
|
|
387
|
-
logger.setDefaultLevel("info");
|
|
388
|
-
var logger_default = logger;
|
|
389
|
-
|
|
390
388
|
// ../core/src/paginate/PaginationPlugin.ts
|
|
391
389
|
var logPrefix = "\x1B[46mPLUGIN\x1B[0m";
|
|
392
390
|
function callPluginHook(plugins, hookName, ...args) {
|
|
@@ -819,9 +817,14 @@ var PageManager = class _PageManager {
|
|
|
819
817
|
return !this._pageState.pageIsFull && this._pageState.currentPage.getHeight() + (elementHeight || 1e-4) <= this._pageState.pageHeight;
|
|
820
818
|
}
|
|
821
819
|
isOverFlow() {
|
|
822
|
-
return this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
|
|
820
|
+
return this._pageState.pageIsFull || this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
|
|
823
821
|
}
|
|
824
822
|
markPageAsFull() {
|
|
823
|
+
logger_default.debug(
|
|
824
|
+
logPrefix3,
|
|
825
|
+
"marking page as full",
|
|
826
|
+
this._pageState.activeElement
|
|
827
|
+
);
|
|
825
828
|
this._pageState.pageIsFull = true;
|
|
826
829
|
}
|
|
827
830
|
appendChild(node, withChildren) {
|
|
@@ -874,7 +877,7 @@ function paginateElementAcrossPages(currentNode, pageManager) {
|
|
|
874
877
|
return nextPageResult;
|
|
875
878
|
}
|
|
876
879
|
rollback();
|
|
877
|
-
logger_default.
|
|
880
|
+
logger_default.error("Element is too big to fit on a page", currentNode);
|
|
878
881
|
return SplitResult.None;
|
|
879
882
|
}
|
|
880
883
|
function tryPlaceElement(currentNode, pageManager) {
|
|
@@ -1027,6 +1030,13 @@ var Paginator = class _Paginator {
|
|
|
1027
1030
|
return result;
|
|
1028
1031
|
}
|
|
1029
1032
|
processAllNodes() {
|
|
1033
|
+
callPluginHook(
|
|
1034
|
+
this._config.plugins,
|
|
1035
|
+
"beforePagination",
|
|
1036
|
+
this._config.id,
|
|
1037
|
+
this._domState,
|
|
1038
|
+
this._pageManager
|
|
1039
|
+
);
|
|
1030
1040
|
this._domState.goToNextNode();
|
|
1031
1041
|
do {
|
|
1032
1042
|
import_loglevel2.default.debug(
|
|
@@ -1067,7 +1077,7 @@ var Paginator = class _Paginator {
|
|
|
1067
1077
|
handleNodeSkipped() {
|
|
1068
1078
|
import_loglevel2.default.debug(logPrefix4, "node skipped - couldn't paginate");
|
|
1069
1079
|
DEV: markIgnoredNode(this._domState.currentNode);
|
|
1070
|
-
this._domState.
|
|
1080
|
+
this._domState.goToNextSiblingOrParentSibling();
|
|
1071
1081
|
}
|
|
1072
1082
|
handleFullNodePlaced() {
|
|
1073
1083
|
import_loglevel2.default.debug(logPrefix4, "node fully paginated");
|
|
@@ -1357,11 +1367,11 @@ var overlay = {
|
|
|
1357
1367
|
left: 0,
|
|
1358
1368
|
top: 0
|
|
1359
1369
|
};
|
|
1360
|
-
var section = (
|
|
1361
|
-
page: `section-${
|
|
1370
|
+
var section = (sectionId) => ({
|
|
1371
|
+
page: `section-${sectionId}`
|
|
1362
1372
|
});
|
|
1363
|
-
function sectionPageMedia(
|
|
1364
|
-
return `@page section-${
|
|
1373
|
+
function sectionPageMedia(sectionId, size) {
|
|
1374
|
+
return `@page section-${sectionId} {
|
|
1365
1375
|
margin: none;
|
|
1366
1376
|
size:${size.width} ${size.height};
|
|
1367
1377
|
width:${size.width};
|
|
@@ -1394,12 +1404,13 @@ function cloneComponents(components) {
|
|
|
1394
1404
|
}
|
|
1395
1405
|
|
|
1396
1406
|
// ../core/src/plugins/PageBreakPlugin.ts
|
|
1397
|
-
var pageBreakAttributeName =
|
|
1407
|
+
var pageBreakAttributeName = `${attributePrefix}page-break`;
|
|
1398
1408
|
var PageBreakPlugin = class {
|
|
1399
1409
|
name = "pageBreak";
|
|
1400
1410
|
order = 1;
|
|
1401
1411
|
onVisitElement = (_id, domState, pageManager, context) => {
|
|
1402
|
-
|
|
1412
|
+
const attr = domState.currentNode.getNode().getAttribute(pageBreakAttributeName);
|
|
1413
|
+
if (attr === "true" || attr === "") {
|
|
1403
1414
|
pageManager.markPageAsFull();
|
|
1404
1415
|
context.result = SplitResult.FullNodePlaced;
|
|
1405
1416
|
}
|
|
@@ -1585,8 +1596,8 @@ var PromiseTracker = class _PromiseTracker {
|
|
|
1585
1596
|
};
|
|
1586
1597
|
|
|
1587
1598
|
// ../core/src/utils.ts
|
|
1588
|
-
function buildPageId(
|
|
1589
|
-
return `${
|
|
1599
|
+
function buildPageId(sectionId, pageIndex) {
|
|
1600
|
+
return `${sectionId}-${pageIndex + 1}`;
|
|
1590
1601
|
}
|
|
1591
1602
|
function adjustPageSize(size, orientation) {
|
|
1592
1603
|
if (orientation === "landscape") {
|
|
@@ -1622,8 +1633,8 @@ var ReportBuilder = class {
|
|
|
1622
1633
|
/**
|
|
1623
1634
|
* Removes a section from the registered sections, if it has already been registered in the report.
|
|
1624
1635
|
*/
|
|
1625
|
-
removeSection(
|
|
1626
|
-
this._sections.delete(
|
|
1636
|
+
removeSection(sectionId) {
|
|
1637
|
+
this._sections.delete(sectionId);
|
|
1627
1638
|
}
|
|
1628
1639
|
/**
|
|
1629
1640
|
* Registers a section by its ID, specifying the page size, margins, and other options.
|
|
@@ -2064,12 +2075,12 @@ var PaprizeReport = class {
|
|
|
2064
2075
|
}
|
|
2065
2076
|
return state;
|
|
2066
2077
|
}
|
|
2067
|
-
_createSectionInDom(
|
|
2078
|
+
_createSectionInDom(sectionId) {
|
|
2068
2079
|
const section2 = document.createElement("div");
|
|
2069
|
-
section2.setAttribute(sectionIdMetadataAttribute,
|
|
2080
|
+
section2.setAttribute(sectionIdMetadataAttribute, sectionId);
|
|
2070
2081
|
section2.classList.add(sectionClassName);
|
|
2071
|
-
section2.id =
|
|
2072
|
-
Object.assign(section2.style, reportStyles.section(
|
|
2082
|
+
section2.id = sectionId;
|
|
2083
|
+
Object.assign(section2.style, reportStyles.section(sectionId));
|
|
2073
2084
|
this._root.appendChild(section2);
|
|
2074
2085
|
return section2;
|
|
2075
2086
|
}
|
|
@@ -2196,16 +2207,36 @@ var PaprizeReport = class {
|
|
|
2196
2207
|
}
|
|
2197
2208
|
};
|
|
2198
2209
|
|
|
2199
|
-
// src/
|
|
2210
|
+
// src/zeroReportUtils.ts
|
|
2200
2211
|
var sectionPageSizeAttribute = `${attributePrefix}section-page-size`;
|
|
2212
|
+
var sectionPageWidthAttribute = `${attributePrefix}section-page-width`;
|
|
2213
|
+
var sectionPageHeightAttribute = `${attributePrefix}section-page-height`;
|
|
2214
|
+
var sectionPageOrientationAttribute = `${attributePrefix}section-page-orientation`;
|
|
2201
2215
|
var sectionPageMarginAttribute = `${attributePrefix}section-page-margin`;
|
|
2202
2216
|
function parsePageSizeAttribute(section2) {
|
|
2203
2217
|
const sizeAttributeValue = section2.getAttribute(sectionPageSizeAttribute);
|
|
2218
|
+
const widthAttributeValue = section2.getAttribute(sectionPageWidthAttribute);
|
|
2219
|
+
const heightAttributeValue = section2.getAttribute(
|
|
2220
|
+
sectionPageHeightAttribute
|
|
2221
|
+
);
|
|
2222
|
+
if (widthAttributeValue && heightAttributeValue) {
|
|
2223
|
+
return {
|
|
2224
|
+
width: widthAttributeValue,
|
|
2225
|
+
height: heightAttributeValue
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2204
2228
|
const size = Object.entries(pageSize).find(
|
|
2205
2229
|
([key]) => key.toLowerCase() === sizeAttributeValue?.toLowerCase()
|
|
2206
2230
|
)?.[1];
|
|
2207
2231
|
return size ?? pageSize.A4;
|
|
2208
2232
|
}
|
|
2233
|
+
function parsePageOrientation(section2) {
|
|
2234
|
+
const orientationAttributeValue = section2.getAttribute(sectionPageOrientationAttribute)?.toLocaleLowerCase();
|
|
2235
|
+
if (orientationAttributeValue === "landscape" || orientationAttributeValue === "portrait") {
|
|
2236
|
+
return orientationAttributeValue;
|
|
2237
|
+
}
|
|
2238
|
+
return void 0;
|
|
2239
|
+
}
|
|
2209
2240
|
function parsePageMarginAttribute(section2) {
|
|
2210
2241
|
const size = section2.getAttribute(sectionPageMarginAttribute);
|
|
2211
2242
|
const margin = Object.entries(pageMargin).find(
|
|
@@ -2213,23 +2244,26 @@ function parsePageMarginAttribute(section2) {
|
|
|
2213
2244
|
)?.[1];
|
|
2214
2245
|
return margin ?? pageMargin.Narrow;
|
|
2215
2246
|
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
const
|
|
2221
|
-
|
|
2222
|
-
el.id
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2247
|
+
async function runZeroReport() {
|
|
2248
|
+
let sectionId = 1;
|
|
2249
|
+
const report = new PaprizeReport();
|
|
2250
|
+
const elements = document.querySelectorAll(`[${sectionAttribute}]`);
|
|
2251
|
+
for (const el of elements) {
|
|
2252
|
+
const id = el.id || `section-${sectionId++}`;
|
|
2253
|
+
if (!el.id) {
|
|
2254
|
+
el.id = id;
|
|
2255
|
+
}
|
|
2256
|
+
await report.addSection({
|
|
2257
|
+
size: parsePageSizeAttribute(el),
|
|
2258
|
+
orientation: parsePageOrientation(el),
|
|
2259
|
+
margin: parsePageMarginAttribute(el),
|
|
2260
|
+
id
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
await report.schedulePagination();
|
|
2229
2264
|
}
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
};
|
|
2265
|
+
|
|
2266
|
+
// src/zeroReport.ts
|
|
2267
|
+
await runZeroReport();
|
|
2268
|
+
/* v8 ignore if -- @preserve */
|
|
2235
2269
|
//# sourceMappingURL=paprize-zero.js.map
|