@paprize/puppeteer 0.1.0 → 0.3.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 +19 -0
- package/dist/paprize-puppeteer.d.ts +83 -0
- package/dist/paprize-puppeteer.js +10 -5
- package/dist/paprize-puppeteer.js.map +2 -2
- package/dist/paprize-zero.js +151 -60
- package/dist/paprize-zero.js.map +4 -4
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @paprize/puppeteer
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Fix missing type deceleration
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @paprize/core@0.3.0
|
|
13
|
+
- Improve zero report by preloading it to page
|
|
14
|
+
|
|
15
|
+
## 0.2.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [8e2ef6e]
|
|
20
|
+
- @paprize/core@0.2.0
|
|
21
|
+
|
|
3
22
|
## 0.1.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -1 +1,84 @@
|
|
|
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
|
+
|
|
1
78
|
export { }
|
|
79
|
+
|
|
80
|
+
declare global {
|
|
81
|
+
interface Window {
|
|
82
|
+
runZeroReport: () => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -62,19 +62,24 @@ async function openReport(page, reportUrl, jsonData, timeout = 3e4) {
|
|
|
62
62
|
await page.exposeFunction(paprize_readJsonDataFile, () => {
|
|
63
63
|
return jsonDataStr;
|
|
64
64
|
});
|
|
65
|
-
await page.goto(reportUrl.toString()
|
|
66
|
-
|
|
65
|
+
await page.goto(reportUrl.toString());
|
|
66
|
+
const task1 = page.addScriptTag({
|
|
67
|
+
type: "module",
|
|
68
|
+
path: `${import.meta.dirname}/paprize-zero.js`
|
|
69
|
+
});
|
|
70
|
+
const task2 = page.waitForNetworkIdle({
|
|
71
|
+
idleTime: 500,
|
|
67
72
|
timeout
|
|
68
73
|
});
|
|
74
|
+
await Promise.all([task1, task2]);
|
|
69
75
|
await page.waitForFunction(`window.${paprize_isInitialized} === true`, {
|
|
70
76
|
timeout: 100
|
|
71
77
|
}).catch(() => {
|
|
72
78
|
logger2.info(
|
|
73
79
|
"Using Zero report mode (standard Paprize report format not detected)"
|
|
74
80
|
);
|
|
75
|
-
return page.
|
|
76
|
-
|
|
77
|
-
path: `${import.meta.dirname}/paprize-zero.js`
|
|
81
|
+
return page.evaluate(() => {
|
|
82
|
+
return window.runZeroReport();
|
|
78
83
|
});
|
|
79
84
|
});
|
|
80
85
|
await page.waitForFunction(`window.${paprize_isReady} === true`, {
|
|
@@ -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()
|
|
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,KAAK;AACD,eAAO,KAAK,SAAS,IAAI,EAAE;AAC3B;AAAA,MACJ;AACI,eAAO,IAAI,QAAQ,IAAI,EAAE;AAAA,IACjC;AAAA,EACJ,CAAC;AACL;;;ADLA,eAAsB,WAClB,MACA,WACA,UACA,UAAkB,KACL;AACb,cAAY,IAAI;AAEhB,QAAM,cAAc,WAAW,KAAK,UAAU,QAAQ,IAAI;AAC1D,QAAM,KAAK,eAAe,0BAA0B,MAAM;AACtD,WAAO;AAAA,EACX,CAAC;AAED,QAAM,KAAK,KAAK,UAAU,SAAS,GAAG;AAAA,IAClC,
|
|
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\n // preload the paprize-zero.js\n const task1 = page.addScriptTag({\n type: 'module',\n path: `${import.meta.dirname}/paprize-zero.js`,\n });\n\n const task2 = page.waitForNetworkIdle({\n idleTime: 500,\n timeout: timeout,\n });\n\n await Promise.all([task1, task2]);\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.evaluate(() => {\n return window.runZeroReport();\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
|
@@ -252,14 +252,14 @@ var require_loglevel = __commonJS({
|
|
|
252
252
|
if (typeof name !== "symbol" && typeof name !== "string" || name === "") {
|
|
253
253
|
throw new TypeError("You must supply a name when creating a logger.");
|
|
254
254
|
}
|
|
255
|
-
var
|
|
256
|
-
if (!
|
|
257
|
-
|
|
255
|
+
var logger2 = _loggersByName[name];
|
|
256
|
+
if (!logger2) {
|
|
257
|
+
logger2 = _loggersByName[name] = new Logger(
|
|
258
258
|
name,
|
|
259
259
|
defaultLogger.methodFactory
|
|
260
260
|
);
|
|
261
261
|
}
|
|
262
|
-
return
|
|
262
|
+
return logger2;
|
|
263
263
|
};
|
|
264
264
|
var _log = typeof window !== undefinedType ? window.log : void 0;
|
|
265
265
|
defaultLogger.noConflict = function() {
|
|
@@ -339,7 +339,18 @@ var layoutOptionsAttributes = {
|
|
|
339
339
|
},
|
|
340
340
|
keepOnSamePage: {
|
|
341
341
|
key: layoutOptionKeepOnSamePageAttribute,
|
|
342
|
-
reader: (value) =>
|
|
342
|
+
reader: (value) => {
|
|
343
|
+
switch (value) {
|
|
344
|
+
case "true":
|
|
345
|
+
return true;
|
|
346
|
+
case "false":
|
|
347
|
+
return false;
|
|
348
|
+
case "prefer":
|
|
349
|
+
return "prefer";
|
|
350
|
+
default:
|
|
351
|
+
return defaultLayoutOptions.keepOnSamePage;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
343
354
|
},
|
|
344
355
|
hyphenationDisabled: {
|
|
345
356
|
key: layoutOptionHyphenationDisabledAttribute,
|
|
@@ -425,21 +436,25 @@ var PageElement = class _PageElement {
|
|
|
425
436
|
config;
|
|
426
437
|
type = PageNodeType.Element;
|
|
427
438
|
transaction;
|
|
428
|
-
|
|
429
|
-
cloneCount;
|
|
439
|
+
clonedData;
|
|
430
440
|
constructor(element, transaction, config, clonedFrom) {
|
|
431
441
|
this._node = element;
|
|
432
442
|
this.transaction = transaction;
|
|
433
443
|
this.config = config;
|
|
434
|
-
this.
|
|
435
|
-
|
|
444
|
+
this.clonedData = clonedFrom ? {
|
|
445
|
+
clonedFrom,
|
|
446
|
+
cloneCount: clonedFrom.clonedData.cloneCount + 1
|
|
447
|
+
} : {
|
|
448
|
+
clonedFrom: void 0,
|
|
449
|
+
cloneCount: 0
|
|
450
|
+
};
|
|
436
451
|
}
|
|
437
452
|
getOriginalNode() {
|
|
438
|
-
let current = this.clonedFrom;
|
|
439
|
-
while (current?.clonedFrom) {
|
|
440
|
-
current = current.clonedFrom;
|
|
453
|
+
let current = this.clonedData.clonedFrom;
|
|
454
|
+
while (current?.clonedData.clonedFrom) {
|
|
455
|
+
current = current.clonedData.clonedFrom;
|
|
441
456
|
}
|
|
442
|
-
return current?._node;
|
|
457
|
+
return current?._node ?? this._node;
|
|
443
458
|
}
|
|
444
459
|
appendChild(node) {
|
|
445
460
|
if (this.transaction.isActive) {
|
|
@@ -676,17 +691,17 @@ var logPrefix3 = "\x1B[102mPAGE\x1B[0m";
|
|
|
676
691
|
var PageState = class _PageState {
|
|
677
692
|
currentPage;
|
|
678
693
|
activeElement;
|
|
694
|
+
// most recently added/handled node
|
|
679
695
|
currentElement;
|
|
696
|
+
// the current parent container/context
|
|
680
697
|
parentStack;
|
|
681
|
-
pageIsFull;
|
|
682
698
|
pageIndex;
|
|
683
699
|
pageHeight;
|
|
684
|
-
constructor(currentPage, activeElement, currentElement, parentStack,
|
|
700
|
+
constructor(currentPage, activeElement, currentElement, parentStack, pageIndex, pageHeight) {
|
|
685
701
|
this.currentPage = currentPage;
|
|
686
702
|
this.activeElement = activeElement;
|
|
687
703
|
this.currentElement = currentElement;
|
|
688
704
|
this.parentStack = parentStack;
|
|
689
|
-
this.pageIsFull = pageIsFull;
|
|
690
705
|
this.pageIndex = pageIndex;
|
|
691
706
|
this.pageHeight = pageHeight;
|
|
692
707
|
}
|
|
@@ -696,7 +711,6 @@ var PageState = class _PageState {
|
|
|
696
711
|
null,
|
|
697
712
|
currentPage,
|
|
698
713
|
parentStack,
|
|
699
|
-
false,
|
|
700
714
|
pageIndex,
|
|
701
715
|
pageHeight
|
|
702
716
|
);
|
|
@@ -707,7 +721,6 @@ var PageState = class _PageState {
|
|
|
707
721
|
this.activeElement,
|
|
708
722
|
this.currentElement,
|
|
709
723
|
[...this.parentStack],
|
|
710
|
-
this.pageIsFull,
|
|
711
724
|
this.pageIndex,
|
|
712
725
|
this.pageHeight
|
|
713
726
|
);
|
|
@@ -814,18 +827,10 @@ var PageManager = class _PageManager {
|
|
|
814
827
|
return this._transaction;
|
|
815
828
|
}
|
|
816
829
|
hasEmptySpace(elementHeight) {
|
|
817
|
-
return
|
|
830
|
+
return this._pageState.currentPage.getHeight() + (elementHeight || 1e-4) <= this._pageState.pageHeight;
|
|
818
831
|
}
|
|
819
832
|
isOverFlow() {
|
|
820
|
-
return this._pageState.
|
|
821
|
-
}
|
|
822
|
-
markPageAsFull() {
|
|
823
|
-
logger_default.debug(
|
|
824
|
-
logPrefix3,
|
|
825
|
-
"marking page as full",
|
|
826
|
-
this._pageState.activeElement
|
|
827
|
-
);
|
|
828
|
-
this._pageState.pageIsFull = true;
|
|
833
|
+
return this._pageState.currentPage.getHeight() > this._pageState.pageHeight;
|
|
829
834
|
}
|
|
830
835
|
appendChild(node, withChildren) {
|
|
831
836
|
const clonedNode = node.clone(withChildren);
|
|
@@ -877,19 +882,27 @@ function paginateElementAcrossPages(currentNode, pageManager) {
|
|
|
877
882
|
return nextPageResult;
|
|
878
883
|
}
|
|
879
884
|
rollback();
|
|
880
|
-
|
|
885
|
+
if (currentNode.config.keepOnSamePage === "prefer") {
|
|
886
|
+
return tryPlaceElementWithoutChildren(currentNode, pageManager);
|
|
887
|
+
}
|
|
881
888
|
return SplitResult.None;
|
|
882
889
|
}
|
|
883
890
|
function tryPlaceElement(currentNode, pageManager) {
|
|
884
891
|
if (pageManager.hasEmptySpace(currentNode.getHeight())) {
|
|
885
|
-
const
|
|
892
|
+
const clonedNode = pageManager.appendChild(currentNode, true);
|
|
886
893
|
if (pageManager.isOverFlow()) {
|
|
887
|
-
|
|
894
|
+
clonedNode.remove();
|
|
888
895
|
} else {
|
|
889
896
|
return SplitResult.FullNodePlaced;
|
|
890
897
|
}
|
|
891
898
|
}
|
|
892
|
-
if (currentNode.config.keepOnSamePage
|
|
899
|
+
if (currentNode.config.keepOnSamePage === false) {
|
|
900
|
+
return tryPlaceElementWithoutChildren(currentNode, pageManager);
|
|
901
|
+
}
|
|
902
|
+
return SplitResult.None;
|
|
903
|
+
}
|
|
904
|
+
function tryPlaceElementWithoutChildren(currentNode, pageManager) {
|
|
905
|
+
if (currentNode.getChildrenCount() === 0) {
|
|
893
906
|
return SplitResult.None;
|
|
894
907
|
}
|
|
895
908
|
const clonedNode = pageManager.appendChild(currentNode, false);
|
|
@@ -972,7 +985,7 @@ function hyphenation(word, hyphen, pageManager) {
|
|
|
972
985
|
textNode.textContent = tentative + hyphen;
|
|
973
986
|
if (!pageManager.hasEmptySpace()) {
|
|
974
987
|
textNode.textContent = appended ? appended + hyphen : "";
|
|
975
|
-
pageManager.
|
|
988
|
+
pageManager.nextPage();
|
|
976
989
|
return word.slice(i);
|
|
977
990
|
}
|
|
978
991
|
appended = tentative;
|
|
@@ -980,8 +993,26 @@ function hyphenation(word, hyphen, pageManager) {
|
|
|
980
993
|
return null;
|
|
981
994
|
}
|
|
982
995
|
|
|
996
|
+
// ../core/src/utils.ts
|
|
997
|
+
function buildPageId(sectionId, pageIndex) {
|
|
998
|
+
return `${sectionId}-${pageIndex + 1}`;
|
|
999
|
+
}
|
|
1000
|
+
function adjustPageSize(size, orientation) {
|
|
1001
|
+
if (orientation === "landscape") {
|
|
1002
|
+
return { height: size.width, width: size.height };
|
|
1003
|
+
}
|
|
1004
|
+
return size;
|
|
1005
|
+
}
|
|
1006
|
+
function pageNodeToString(node) {
|
|
1007
|
+
if (!node) return "undefined";
|
|
1008
|
+
const el = node.getNode();
|
|
1009
|
+
if (!(el instanceof Element)) return String(el).slice(0, 100);
|
|
1010
|
+
const id = el.id ? `#${el.id}` : "";
|
|
1011
|
+
const classes = el.classList.length ? `.${Array.from(el.classList).join(".")}` : "";
|
|
1012
|
+
return `<${el.tagName.toLowerCase()}${id}${classes}>`;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
983
1015
|
// ../core/src/paginate/Paginator.ts
|
|
984
|
-
var import_loglevel2 = __toESM(require_loglevel(), 1);
|
|
985
1016
|
var logPrefix4 = "\x1B[103mPAGINATOR\x1B[0m";
|
|
986
1017
|
var Paginator = class _Paginator {
|
|
987
1018
|
_domState;
|
|
@@ -1039,7 +1070,7 @@ var Paginator = class _Paginator {
|
|
|
1039
1070
|
);
|
|
1040
1071
|
this._domState.goToNextNode();
|
|
1041
1072
|
do {
|
|
1042
|
-
|
|
1073
|
+
logger_default.debug(
|
|
1043
1074
|
logPrefix4,
|
|
1044
1075
|
"paginating node",
|
|
1045
1076
|
this._domState.currentNode
|
|
@@ -1072,22 +1103,26 @@ var Paginator = class _Paginator {
|
|
|
1072
1103
|
this._domState,
|
|
1073
1104
|
this._pageManager
|
|
1074
1105
|
);
|
|
1075
|
-
|
|
1106
|
+
logger_default.debug(logPrefix4, "pagination completed");
|
|
1076
1107
|
}
|
|
1077
1108
|
handleNodeSkipped() {
|
|
1078
|
-
|
|
1109
|
+
logger_default.error(
|
|
1110
|
+
"Node is too big to fit on a page. Skipping node:",
|
|
1111
|
+
pageNodeToString(this._domState.currentNode),
|
|
1112
|
+
this._domState.currentNode
|
|
1113
|
+
);
|
|
1079
1114
|
DEV: markIgnoredNode(this._domState.currentNode);
|
|
1080
1115
|
this._domState.goToNextSiblingOrParentSibling();
|
|
1081
1116
|
}
|
|
1082
1117
|
handleFullNodePlaced() {
|
|
1083
|
-
|
|
1118
|
+
logger_default.debug(logPrefix4, "node fully paginated");
|
|
1084
1119
|
const { parentsTraversed } = this._domState.goToNextSiblingOrParentSibling();
|
|
1085
1120
|
for (let i = 0; i < parentsTraversed; i++) {
|
|
1086
1121
|
this._pageManager.leaveElement();
|
|
1087
1122
|
}
|
|
1088
1123
|
}
|
|
1089
1124
|
handleChildrenSplit() {
|
|
1090
|
-
|
|
1125
|
+
logger_default.debug(
|
|
1091
1126
|
logPrefix4,
|
|
1092
1127
|
"node partially paginated - splitting children"
|
|
1093
1128
|
);
|
|
@@ -1403,6 +1438,66 @@ function cloneComponents(components) {
|
|
|
1403
1438
|
};
|
|
1404
1439
|
}
|
|
1405
1440
|
|
|
1441
|
+
// ../core/src/plugins/OrderedListPlugin.ts
|
|
1442
|
+
var OrderedListPlugin = class {
|
|
1443
|
+
// original list -> (clone list -> count of items rendered in the clone)
|
|
1444
|
+
_originalItemCount = /* @__PURE__ */ new Map();
|
|
1445
|
+
name = "orderedList";
|
|
1446
|
+
order = 1;
|
|
1447
|
+
onClone = (_id, source, cloned) => {
|
|
1448
|
+
if (!this._isListItem(source)) return;
|
|
1449
|
+
const isSpreadAcrossPages = cloned.clonedData.cloneCount > 1;
|
|
1450
|
+
if (!isSpreadAcrossPages) return;
|
|
1451
|
+
const node = cloned.getNode();
|
|
1452
|
+
node.style.listStyleType = "none";
|
|
1453
|
+
const sourceParent = cloned.clonedData.clonedFrom?.getNode().parentElement;
|
|
1454
|
+
const originalParent = cloned.getOriginalNode().parentElement;
|
|
1455
|
+
if (!sourceParent || !originalParent || !this._isOrderedList(sourceParent) || !this._isOrderedList(originalParent)) {
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
const currentCount = this._readRenderedItemCount(
|
|
1459
|
+
originalParent,
|
|
1460
|
+
(list) => list === sourceParent
|
|
1461
|
+
);
|
|
1462
|
+
this._setListItemCount(originalParent, sourceParent, currentCount - 1);
|
|
1463
|
+
};
|
|
1464
|
+
afterVisitNode = (_id, _result, _domState, pageManager) => {
|
|
1465
|
+
const currentElement = pageManager.getPageState().currentElement;
|
|
1466
|
+
const node = currentElement.getNode();
|
|
1467
|
+
if (!this._isOrderedList(node)) return;
|
|
1468
|
+
const originalList = currentElement.getOriginalNode();
|
|
1469
|
+
const renderedItemCount = this._readRenderedItemCount(
|
|
1470
|
+
originalList,
|
|
1471
|
+
(list) => list !== node
|
|
1472
|
+
);
|
|
1473
|
+
node.start = originalList.start + renderedItemCount;
|
|
1474
|
+
const itemCount = this._getListItemCount(node);
|
|
1475
|
+
this._setListItemCount(originalList, node, itemCount);
|
|
1476
|
+
};
|
|
1477
|
+
beforePagination = () => {
|
|
1478
|
+
this._originalItemCount.clear();
|
|
1479
|
+
};
|
|
1480
|
+
_isListItem(element) {
|
|
1481
|
+
return element.tagName === "LI";
|
|
1482
|
+
}
|
|
1483
|
+
_isOrderedList(element) {
|
|
1484
|
+
return element.tagName === "OL";
|
|
1485
|
+
}
|
|
1486
|
+
_setListItemCount(originalList, list, count) {
|
|
1487
|
+
const cloneCatalog = this._originalItemCount.get(originalList) ?? /* @__PURE__ */ new Map();
|
|
1488
|
+
cloneCatalog.set(list, count);
|
|
1489
|
+
this._originalItemCount.set(originalList, cloneCatalog);
|
|
1490
|
+
}
|
|
1491
|
+
_readRenderedItemCount(originalList, filter) {
|
|
1492
|
+
const cloneCatalog = this._originalItemCount.get(originalList);
|
|
1493
|
+
if (!cloneCatalog) return 0;
|
|
1494
|
+
return [...cloneCatalog.entries()].filter((i) => filter(i[0])).reduce((a, b) => a + b[1], 0);
|
|
1495
|
+
}
|
|
1496
|
+
_getListItemCount(list) {
|
|
1497
|
+
return [...list.children].filter((child) => this._isListItem(child)).length;
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1406
1501
|
// ../core/src/plugins/PageBreakPlugin.ts
|
|
1407
1502
|
var pageBreakAttributeName = `${attributePrefix}page-break`;
|
|
1408
1503
|
var PageBreakPlugin = class {
|
|
@@ -1411,7 +1506,7 @@ var PageBreakPlugin = class {
|
|
|
1411
1506
|
onVisitElement = (_id, domState, pageManager, context) => {
|
|
1412
1507
|
const attr = domState.currentNode.getNode().getAttribute(pageBreakAttributeName);
|
|
1413
1508
|
if (attr === "true" || attr === "") {
|
|
1414
|
-
pageManager.
|
|
1509
|
+
pageManager.nextPage();
|
|
1415
1510
|
context.result = SplitResult.FullNodePlaced;
|
|
1416
1511
|
}
|
|
1417
1512
|
};
|
|
@@ -1433,10 +1528,10 @@ var TablePlugin = class {
|
|
|
1433
1528
|
const tableElement = pageState.parentStack.find(
|
|
1434
1529
|
(node) => this._isTable(node.getNode())
|
|
1435
1530
|
);
|
|
1436
|
-
if (!tableElement || !tableElement.clonedFrom) {
|
|
1531
|
+
if (!tableElement || !tableElement.clonedData.clonedFrom) {
|
|
1437
1532
|
return;
|
|
1438
1533
|
}
|
|
1439
|
-
const openTable = tableElement.clonedFrom;
|
|
1534
|
+
const openTable = tableElement.clonedData.clonedFrom;
|
|
1440
1535
|
const openTableNode = openTable.getNode();
|
|
1441
1536
|
const header = openTableNode.tHead;
|
|
1442
1537
|
const hasHeader = header !== null;
|
|
@@ -1461,7 +1556,7 @@ var TablePlugin = class {
|
|
|
1461
1556
|
onVisitElement = (_id, domState, _pageManager, context) => {
|
|
1462
1557
|
const node = domState.currentNode.getNode();
|
|
1463
1558
|
if (node.tagName === "TR") {
|
|
1464
|
-
domState.currentNode.config.keepOnSamePage =
|
|
1559
|
+
domState.currentNode.config.keepOnSamePage = "prefer";
|
|
1465
1560
|
} else if (node.tagName === "TFOOT" && this._options.cloneFooter) {
|
|
1466
1561
|
context.result = SplitResult.FullNodePlaced;
|
|
1467
1562
|
} else if (node.tagName === "THEAD" && this._options.cloneHeader) {
|
|
@@ -1469,7 +1564,7 @@ var TablePlugin = class {
|
|
|
1469
1564
|
}
|
|
1470
1565
|
};
|
|
1471
1566
|
onClone = (_id, source, cloned) => {
|
|
1472
|
-
if (!this._isTable(source) || !cloned.clonedFrom) {
|
|
1567
|
+
if (!this._isTable(source) || !cloned.clonedData.clonedFrom) {
|
|
1473
1568
|
return;
|
|
1474
1569
|
}
|
|
1475
1570
|
const node = cloned.getNode();
|
|
@@ -1515,7 +1610,8 @@ var TablePlugin = class {
|
|
|
1515
1610
|
// ../core/src/plugins/defaultPlugins.ts
|
|
1516
1611
|
var defaultPlugins = [
|
|
1517
1612
|
new PageBreakPlugin(),
|
|
1518
|
-
new TablePlugin()
|
|
1613
|
+
new TablePlugin(),
|
|
1614
|
+
new OrderedListPlugin()
|
|
1519
1615
|
];
|
|
1520
1616
|
|
|
1521
1617
|
// ../core/src/plugins/debugPlugin.ts
|
|
@@ -1595,17 +1691,6 @@ var PromiseTracker = class _PromiseTracker {
|
|
|
1595
1691
|
}
|
|
1596
1692
|
};
|
|
1597
1693
|
|
|
1598
|
-
// ../core/src/utils.ts
|
|
1599
|
-
function buildPageId(sectionId, pageIndex) {
|
|
1600
|
-
return `${sectionId}-${pageIndex + 1}`;
|
|
1601
|
-
}
|
|
1602
|
-
function adjustPageSize(size, orientation) {
|
|
1603
|
-
if (orientation === "landscape") {
|
|
1604
|
-
return { height: size.width, width: size.height };
|
|
1605
|
-
}
|
|
1606
|
-
return size;
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
1694
|
// ../core/src/report/ReportBuilder.ts
|
|
1610
1695
|
var logPrefix5 = "\x1B[43mREPORT\x1B[0m";
|
|
1611
1696
|
var ReportBuilder = class {
|
|
@@ -2207,7 +2292,7 @@ var PaprizeReport = class {
|
|
|
2207
2292
|
}
|
|
2208
2293
|
};
|
|
2209
2294
|
|
|
2210
|
-
// src/
|
|
2295
|
+
// src/zeroReport.ts
|
|
2211
2296
|
var sectionPageSizeAttribute = `${attributePrefix}section-page-size`;
|
|
2212
2297
|
var sectionPageWidthAttribute = `${attributePrefix}section-page-width`;
|
|
2213
2298
|
var sectionPageHeightAttribute = `${attributePrefix}section-page-height`;
|
|
@@ -2262,8 +2347,14 @@ async function runZeroReport() {
|
|
|
2262
2347
|
}
|
|
2263
2348
|
await report.schedulePagination();
|
|
2264
2349
|
}
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2350
|
+
window.runZeroReport = runZeroReport;
|
|
2351
|
+
export {
|
|
2352
|
+
runZeroReport,
|
|
2353
|
+
sectionPageHeightAttribute,
|
|
2354
|
+
sectionPageMarginAttribute,
|
|
2355
|
+
sectionPageOrientationAttribute,
|
|
2356
|
+
sectionPageSizeAttribute,
|
|
2357
|
+
sectionPageWidthAttribute
|
|
2358
|
+
};
|
|
2268
2359
|
/* v8 ignore if -- @preserve */
|
|
2269
2360
|
//# sourceMappingURL=paprize-zero.js.map
|