@alauda/doom 1.10.12 → 1.11.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.
Files changed (74) hide show
  1. package/lib/cli/export.js +1 -1
  2. package/lib/cli/load-config.js +7 -6
  3. package/lib/plugins/index.d.ts +0 -1
  4. package/lib/plugins/index.js +0 -1
  5. package/lib/runtime/components/OpenAPIPath.js +2 -3
  6. package/lib/runtime/components/Overview.js +3 -6
  7. package/lib/runtime/components/_utils.d.ts +1 -1
  8. package/lib/runtime/components/_utils.js +2 -4
  9. package/package.json +26 -29
  10. package/LICENSE +0 -21
  11. package/README.md +0 -29
  12. package/lib/cli/export-pdf-core/generatePdf.d.ts +0 -25
  13. package/lib/cli/export-pdf-core/generatePdf.js +0 -91
  14. package/lib/cli/export-pdf-core/index.d.ts +0 -3
  15. package/lib/cli/export-pdf-core/index.js +0 -3
  16. package/lib/cli/export-pdf-core/types.d.ts +0 -15
  17. package/lib/cli/export-pdf-core/types.js +0 -1
  18. package/lib/cli/export-pdf-core/utils/convertPathToPosix.d.ts +0 -8
  19. package/lib/cli/export-pdf-core/utils/convertPathToPosix.js +0 -26
  20. package/lib/cli/export-pdf-core/utils/getUrlLink.d.ts +0 -4
  21. package/lib/cli/export-pdf-core/utils/getUrlLink.js +0 -7
  22. package/lib/cli/export-pdf-core/utils/index.d.ts +0 -3
  23. package/lib/cli/export-pdf-core/utils/index.js +0 -3
  24. package/lib/cli/export-pdf-core/utils/mergePDF.d.ts +0 -26
  25. package/lib/cli/export-pdf-core/utils/mergePDF.js +0 -137
  26. package/lib/cli/html-export-pdf/core/index.d.ts +0 -3
  27. package/lib/cli/html-export-pdf/core/index.js +0 -3
  28. package/lib/cli/html-export-pdf/core/outline.d.ts +0 -47
  29. package/lib/cli/html-export-pdf/core/outline.js +0 -217
  30. package/lib/cli/html-export-pdf/core/postprocesser.d.ts +0 -14
  31. package/lib/cli/html-export-pdf/core/postprocesser.js +0 -36
  32. package/lib/cli/html-export-pdf/core/printer.d.ts +0 -59
  33. package/lib/cli/html-export-pdf/core/printer.js +0 -235
  34. package/lib/cli/html-export-pdf/index.d.ts +0 -2
  35. package/lib/cli/html-export-pdf/index.js +0 -2
  36. package/lib/cli/html-export-pdf/utils/cliProgress.d.ts +0 -13
  37. package/lib/cli/html-export-pdf/utils/cliProgress.js +0 -80
  38. package/lib/cli/html-export-pdf/utils/fs.d.ts +0 -5
  39. package/lib/cli/html-export-pdf/utils/fs.js +0 -18
  40. package/lib/cli/html-export-pdf/utils/getAbsFileName.d.ts +0 -1
  41. package/lib/cli/html-export-pdf/utils/getAbsFileName.js +0 -4
  42. package/lib/cli/html-export-pdf/utils/getDirname.d.ts +0 -1
  43. package/lib/cli/html-export-pdf/utils/getDirname.js +0 -5
  44. package/lib/cli/html-export-pdf/utils/index.d.ts +0 -7
  45. package/lib/cli/html-export-pdf/utils/index.js +0 -7
  46. package/lib/cli/html-export-pdf/utils/isValidUrl.d.ts +0 -1
  47. package/lib/cli/html-export-pdf/utils/isValidUrl.js +0 -3
  48. package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.d.ts +0 -2
  49. package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.js +0 -6
  50. package/lib/cli/html-export-pdf/utils/replaceExt.d.ts +0 -1
  51. package/lib/cli/html-export-pdf/utils/replaceExt.js +0 -19
  52. package/lib/cli/merge-pdfs/formatDate.d.ts +0 -1
  53. package/lib/cli/merge-pdfs/formatDate.js +0 -23
  54. package/lib/cli/merge-pdfs/index.d.ts +0 -8
  55. package/lib/cli/merge-pdfs/index.js +0 -62
  56. package/lib/plugins/sitemap/index.d.ts +0 -16
  57. package/lib/plugins/sitemap/index.js +0 -51
  58. package/pyodide/README.md +0 -90
  59. package/pyodide/console.html +0 -259
  60. package/pyodide/ffi.d.ts +0 -1118
  61. package/pyodide/micropip-0.8.0-py3-none-any.whl +0 -0
  62. package/pyodide/package.json +0 -59
  63. package/pyodide/packaging-24.2-py3-none-any.whl +0 -0
  64. package/pyodide/pyodide-lock.json +0 -1
  65. package/pyodide/pyodide.asm.js +0 -17
  66. package/pyodide/pyodide.asm.wasm +0 -0
  67. package/pyodide/pyodide.d.ts +0 -1627
  68. package/pyodide/pyodide.js +0 -6
  69. package/pyodide/pyodide.js.map +0 -1
  70. package/pyodide/pyodide.mjs +0 -4
  71. package/pyodide/pyodide.mjs.map +0 -1
  72. package/pyodide/pypdf-3.8.1-py3-none-any.whl +0 -0
  73. package/pyodide/python_stdlib.zip +0 -0
  74. package/pyodide/repodata.json +0 -1
@@ -1,137 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- import process from 'node:process';
4
- import { asPDFName, PDFArray, PDFDict, PDFDocument, PDFObject, PDFString, } from 'pdf-lib';
5
- import PDFMerger from 'pdf-merger-js';
6
- import { mergePDFs } from '../../merge-pdfs/index.js';
7
- import { convertPathToPosix } from './convertPathToPosix.js';
8
- import { getUrlLink } from './getUrlLink.js';
9
- const extractOutline = (doc, dict) => {
10
- return {
11
- title: dict.get(asPDFName('Title')).decodeText(),
12
- dest: dict.get(asPDFName('Dest')),
13
- children: extractOutlines(doc, dict),
14
- };
15
- };
16
- const extractOutlines = (doc, dictObj) => {
17
- const outlineDict = doc.context.lookup(dictObj, PDFDict);
18
- const first = outlineDict.get(asPDFName('First'));
19
- let dict = doc.context.lookupMaybe(first, PDFDict);
20
- if (!dict) {
21
- return [];
22
- }
23
- const outlines = [extractOutline(doc, dict)];
24
- let obj;
25
- while ((obj = dict.get(asPDFName('Next')))) {
26
- dict = doc.context.lookup(obj, PDFDict);
27
- outlines.push(extractOutline(doc, dict));
28
- }
29
- return outlines;
30
- };
31
- /**
32
- * Based on @see https://github.com/Hopding/pdf-lib/issues/867#issuecomment-827570106
33
- */
34
- export const replaceLinksWithOutline = async (pdfData, pdfOutlines) => {
35
- const pdfDoc = await PDFDocument.load(pdfData);
36
- const outlinesObj = pdfDoc.catalog.get(asPDFName('Outlines'));
37
- if (!outlinesObj) {
38
- return pdfData;
39
- }
40
- const outlineMap = new WeakMap();
41
- const outlineNodes = pdfOutlines.flatMap(([, outlineNodes]) => outlineNodes);
42
- const outlineNodeMap = new Map(pdfOutlines);
43
- const outlines = extractOutlines(pdfDoc, outlinesObj);
44
- for (const [index, outlineNode] of outlineNodes.entries()) {
45
- const outline = outlines[index];
46
- outlineMap.set(outlineNode, outline);
47
- for (const [index, outlineChild] of outlineNode.children.entries()) {
48
- outlineMap.set(outlineChild, outline.children[index]);
49
- }
50
- }
51
- const pages = pdfDoc.getPages();
52
- for (const page of pages) {
53
- for (const annot of page.node.Annots()?.asArray() || []) {
54
- const dict = pdfDoc.context.lookupMaybe(annot, PDFDict);
55
- const aRecord = dict?.get(asPDFName(`A`));
56
- const link = pdfDoc.context.lookupMaybe(aRecord, PDFDict);
57
- const uri = link?.get(asPDFName('URI'))?.toString().slice(1, -1); // get the original link, remove parenthesis
58
- if (!dict || !aRecord || !link || !uri) {
59
- continue;
60
- }
61
- const url = uri.replace(/\\(\d{2,3})/g, (_, code) => String.fromCharCode(Number.parseInt(code, 8)));
62
- if (/^https?:\/\//.test(url)) {
63
- const { link, hash } = getUrlLink(url);
64
- let matched = outlineNodeMap.get(link);
65
- if (!matched && link.endsWith('/')) {
66
- matched = outlineNodeMap.get(link + 'index.html');
67
- }
68
- if (!matched?.length) {
69
- continue;
70
- }
71
- let matchedOutlineNode = matched[0];
72
- if (hash) {
73
- for (const node of matched) {
74
- if (node.destination === hash) {
75
- matchedOutlineNode = node;
76
- break;
77
- }
78
- for (const child of node.children) {
79
- if (child.destination === hash) {
80
- matchedOutlineNode = child;
81
- break;
82
- }
83
- }
84
- }
85
- }
86
- const matchedOutline = outlineMap.get(matchedOutlineNode);
87
- if (!matchedOutline) {
88
- continue;
89
- }
90
- dict.set(asPDFName('A'), pdfDoc.context.obj({
91
- S: 'GoTo',
92
- D: matchedOutline.dest,
93
- }));
94
- }
95
- }
96
- }
97
- return pdfDoc.save();
98
- };
99
- /**
100
- * Merge PDFs.
101
- * @param pages - NormalizePage
102
- * @param outFile - Output file
103
- * @param outDir - Output directory
104
- * @returns relativePath - Output relative path
105
- */
106
- export async function mergePDF(pages, outFile, outDir, pdfOutlines) {
107
- const saveDirPath = path.resolve(outDir);
108
- if (outDir) {
109
- await fs.mkdir(saveDirPath, { recursive: true });
110
- }
111
- const saveFilePath = path.join(saveDirPath, outFile);
112
- if (pages.length === 0) {
113
- throw new Error('The website has no pages, please check whether the export path is set correctly');
114
- }
115
- else if (pages.length === 1) {
116
- await fs.rename(pages[0].pagePath, saveFilePath);
117
- }
118
- else {
119
- let pdfData;
120
- if (pdfOutlines.length > 0) {
121
- pdfData = await mergePDFs(pages.map(({ pagePath }) => {
122
- const relativePagePath = path.relative(process.cwd(), pagePath);
123
- return convertPathToPosix(relativePagePath);
124
- }));
125
- pdfData = await replaceLinksWithOutline(pdfData, pdfOutlines);
126
- }
127
- else {
128
- const merger = new PDFMerger();
129
- for (const { pagePath } of pages) {
130
- await merger.add(pagePath);
131
- }
132
- pdfData = await merger.saveAsBuffer();
133
- }
134
- await fs.writeFile(saveFilePath, pdfData);
135
- }
136
- return path.relative(process.cwd(), saveFilePath);
137
- }
@@ -1,3 +0,0 @@
1
- export * from './outline.js';
2
- export * from './printer.js';
3
- export * from './postprocesser.js';
@@ -1,3 +0,0 @@
1
- export * from './outline.js';
2
- export * from './printer.js';
3
- export * from './postprocesser.js';
@@ -1,47 +0,0 @@
1
- import type { PDFDocument, PDFObject, PDFRef } from 'pdf-lib';
2
- import { PDFName } from 'pdf-lib';
3
- import type { Page } from 'playwright';
4
- export type DictMap = Map<PDFName, PDFObject>;
5
- export interface RootOutlineNode {
6
- children: OutlineNode[];
7
- depth: number;
8
- parent?: OutlineNode | RootOutlineNode;
9
- }
10
- export interface OutlineNode {
11
- title: string;
12
- destination: string;
13
- children: OutlineNode[];
14
- depth: number;
15
- parent?: OutlineNode | RootOutlineNode;
16
- italic?: boolean;
17
- bold?: boolean;
18
- color?: number[];
19
- }
20
- export interface OutlineRef extends OutlineNode {
21
- children: OutlineRef[];
22
- ref: PDFRef;
23
- parentRef: PDFRef;
24
- }
25
- /**
26
- * Format the outline container selector by removing extra spaces and ensuring trailing space.
27
- *
28
- * @param {string} outlineContainerSelector - The selector for the outline container.
29
- * @returns The formatted selector.
30
- */
31
- export declare function formatOutlineContainerSelector(outlineContainerSelector: string): string;
32
- /**
33
- * Gets the outline of a webpage using a headless browser.
34
- * @param {Page} page - The page to evaluate.
35
- * @param {string[]} tags - An array of tag names to use for the outline.
36
- * @param outlineContainerSelector - Outline Container Selector
37
- * @returns A Promise that resolves to an array of top-level OutlineNode objects representing the parsed outline.
38
- */
39
- export declare function getOutlineNodes(page: Page, tags: string[], outlineContainerSelector?: string): Promise<OutlineNode[]>;
40
- /**
41
- * Sets the outlines of a PDF document from a nested outline tree.
42
- * @param {PDFDocument} pdfDoc - The PDF document to set outlines on.
43
- * @param {OutlineNode[]} outlineNodes - The nested outline tree to use as outlines.
44
- * @param {boolean} [enableWarnings=false] - Whether to generate warnings for missing destinations.
45
- * @returns The PDF document with outlines set.
46
- */
47
- export declare function setOutlineNodes(pdfDoc: PDFDocument, outlineNodes: OutlineNode[], enableWarnings?: boolean): OutlineRef[];
@@ -1,217 +0,0 @@
1
- /*
2
- * The following code is adapted from asciidoctor-web-pdf for HTML documents, available at:
3
- * https://github.com/ggrossetie/asciidoctor-web-pdf/blob/main/lib/outline.js
4
- *
5
- * Copyright (c) 2018 Guillaume Grossetie
6
- * Licensed under the MIT License.
7
- */
8
- import { decode } from 'html-entities';
9
- import { PDFArray, PDFDict, PDFHexString, PDFName, PDFNumber } from 'pdf-lib';
10
- /**
11
- * Format the outline container selector by removing extra spaces and ensuring trailing space.
12
- *
13
- * @param {string} outlineContainerSelector - The selector for the outline container.
14
- * @returns The formatted selector.
15
- */
16
- export function formatOutlineContainerSelector(outlineContainerSelector) {
17
- // If the selector is empty, return an empty string.
18
- if (!outlineContainerSelector) {
19
- return '';
20
- }
21
- // Split the selector string by whitespace.
22
- const selectors = outlineContainerSelector.split(/\s+/);
23
- // Filter out empty selectors.
24
- const validSelectors = selectors.filter((selector) => selector);
25
- // Join the valid selectors with spaces and add a trailing space.
26
- const formattedSelector = `${validSelectors.join(' ')} `;
27
- return formattedSelector;
28
- }
29
- /**
30
- * Gets the outline of a webpage using a headless browser.
31
- * @param {Page} page - The page to evaluate.
32
- * @param {string[]} tags - An array of tag names to use for the outline.
33
- * @param outlineContainerSelector - Outline Container Selector
34
- * @returns A Promise that resolves to an array of top-level OutlineNode objects representing the parsed outline.
35
- */
36
- export async function getOutlineNodes(page, tags, outlineContainerSelector = '') {
37
- const preSelector = formatOutlineContainerSelector(outlineContainerSelector);
38
- return await page.evaluate(([tags, outlineSelector]) => {
39
- const tagsToProcess = Array.from(document.querySelectorAll(outlineSelector)).reverse();
40
- const root = {
41
- children: [],
42
- depth: -1,
43
- parent: undefined,
44
- };
45
- let currentOutlineNode = root;
46
- const linkHolder = document.createElement('div');
47
- const body = document.querySelector('body');
48
- linkHolder.style.display = 'none';
49
- body?.insertBefore(linkHolder, body.firstChild);
50
- while (tagsToProcess.length > 0) {
51
- const tag = tagsToProcess.pop();
52
- const orderDepth = tags.indexOf(tag.tagName.toLowerCase());
53
- const dest = encodeURIComponent(tag.id);
54
- // Add to link holder to register a destination
55
- const hiddenLink = document.createElement('a');
56
- hiddenLink.href = `#${dest}`;
57
- linkHolder.appendChild(hiddenLink);
58
- if (orderDepth < currentOutlineNode.depth) {
59
- currentOutlineNode = currentOutlineNode.parent;
60
- tagsToProcess.push(tag);
61
- }
62
- else {
63
- const newNode = {
64
- // http://perfectionkills.com/the-poor-misunderstood-innerText/
65
- title: tag.textContent.trim().replace(/^#|#$/, ''),
66
- destination: dest,
67
- children: [],
68
- depth: orderDepth,
69
- parent: undefined,
70
- };
71
- if (orderDepth === currentOutlineNode.depth) {
72
- if (currentOutlineNode.parent) {
73
- newNode.parent = currentOutlineNode.parent;
74
- currentOutlineNode.parent.children.push(newNode);
75
- }
76
- else {
77
- newNode.parent = currentOutlineNode;
78
- currentOutlineNode.children.push(newNode);
79
- }
80
- currentOutlineNode = newNode;
81
- }
82
- else if (orderDepth > currentOutlineNode.depth) {
83
- newNode.parent = currentOutlineNode;
84
- currentOutlineNode.children.push(newNode);
85
- currentOutlineNode = newNode;
86
- }
87
- }
88
- }
89
- const stripParentProperty = (node) => {
90
- node.parent = undefined;
91
- for (const child of node.children) {
92
- stripParentProperty(child);
93
- }
94
- };
95
- stripParentProperty(root);
96
- return root.children;
97
- }, [
98
- tags,
99
- tags.map((titleItem) => `${preSelector}${titleItem}`).join(','),
100
- ]);
101
- }
102
- /**
103
- * Adds PDF references to each outline item in a nested outline tree.
104
- * @param {OutlineNode[]} outlines - The nested outline tree to add references to.
105
- * @param {PDFContext} context - The PDF context to use.
106
- * @param {PDFRef} parentRef - The reference of the parent outline item.
107
- * @returns {OutlineRef[]} An array of outline items with references.
108
- */
109
- function addRefsForOutlineItems(outlines, context, parentRef) {
110
- return outlines.map((item) => {
111
- const itemRef = context.nextRef();
112
- return {
113
- ...item,
114
- ref: itemRef,
115
- parentRef,
116
- children: addRefsForOutlineItems(item.children, context, itemRef),
117
- };
118
- });
119
- }
120
- /**
121
- * Counts the total number of outline items in a nested outline tree.
122
- * @param {OutlineNode[]} outlines - The nested outline tree to count the items of.
123
- * @returns The total number of outline items in the tree.
124
- */
125
- function countChildrenOfOutline(outlines) {
126
- let count = 0;
127
- for (const item of outlines) {
128
- ++count;
129
- count += countChildrenOfOutline(item.children);
130
- }
131
- return count;
132
- }
133
- /**
134
- * Builds the PDF objects for a nested outline tree with references.
135
- * @param {OutlineRef[]} outlinesWithRef - The nested outline tree with references.
136
- * @param {PDFContext} context - The PDF context to use.
137
- */
138
- function buildPdfObjectsForOutline(outlinesWithRef, context) {
139
- for (const [i, item] of outlinesWithRef.entries()) {
140
- const prev = outlinesWithRef.at(i - 1);
141
- const next = outlinesWithRef.at(i + 1);
142
- const pdfObject = new Map();
143
- pdfObject.set(PDFName.of('Title'), PDFHexString.fromText(decode(item.title)));
144
- pdfObject.set(PDFName.of('Dest'), PDFName.of(item.destination));
145
- pdfObject.set(PDFName.of('Parent'), item.parentRef);
146
- pdfObject.set(PDFName.of('F'), PDFNumber.of((item.italic ? 1 : 0) | (item.bold ? 2 : 0)));
147
- if (Array.isArray(item.color)) {
148
- // outline text color, three numbers in the range 0.0 to 1.0
149
- const pdfArr = PDFArray.withContext(context);
150
- pdfArr.push(PDFNumber.of(item.color[0] ?? 0));
151
- pdfArr.push(PDFNumber.of(item.color[1] ?? 0));
152
- pdfArr.push(PDFNumber.of(item.color[2] ?? 0));
153
- pdfObject.set(PDFName.of('C'), pdfArr);
154
- }
155
- if (prev) {
156
- pdfObject.set(PDFName.of('Prev'), prev.ref);
157
- }
158
- if (next) {
159
- pdfObject.set(PDFName.of('Next'), next.ref);
160
- }
161
- if (item.children.length > 0) {
162
- pdfObject.set(PDFName.of('First'), item.children[0].ref);
163
- pdfObject.set(PDFName.of('Last'), item.children[item.children.length - 1].ref);
164
- pdfObject.set(PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(item.children)));
165
- }
166
- context.assign(item.ref, PDFDict.fromMapWithContext(pdfObject, context));
167
- buildPdfObjectsForOutline(item.children, context);
168
- }
169
- }
170
- /**
171
- * Generates warnings for each missing destination in a nested outline tree.
172
- * @param {OutlineNode[]} layer - The nested outline tree to generate warnings for.
173
- * @param {PDFDocument} pdfDoc - The PDF document to generate warnings for.
174
- */
175
- function generateWarningsAboutMissingDestinations(layer, pdfDoc) {
176
- const dests = pdfDoc.context.lookup(pdfDoc.catalog.get(PDFName.of('Dests')), PDFDict);
177
- // Dests can be undefined if the PDF wasn't successfully generated (for instance if Paged.js threw an exception)
178
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
179
- if (!dests) {
180
- return;
181
- }
182
- const validDestinationTargets = dests.entries().map(([key]) => key.asString());
183
- for (const item of layer) {
184
- if (item.destination &&
185
- !validDestinationTargets.includes(`/${item.destination}`)) {
186
- console.warn(`Unable to find destination "${item.destination}" while generating PDF outline.`);
187
- }
188
- generateWarningsAboutMissingDestinations(item.children, pdfDoc);
189
- }
190
- }
191
- /**
192
- * Sets the outlines of a PDF document from a nested outline tree.
193
- * @param {PDFDocument} pdfDoc - The PDF document to set outlines on.
194
- * @param {OutlineNode[]} outlineNodes - The nested outline tree to use as outlines.
195
- * @param {boolean} [enableWarnings=false] - Whether to generate warnings for missing destinations.
196
- * @returns The PDF document with outlines set.
197
- */
198
- export function setOutlineNodes(pdfDoc, outlineNodes, enableWarnings = false) {
199
- if (!outlineNodes.length) {
200
- return [];
201
- }
202
- const context = pdfDoc.context;
203
- const rootOutlineRef = context.nextRef();
204
- if (enableWarnings) {
205
- generateWarningsAboutMissingDestinations(outlineNodes, pdfDoc);
206
- }
207
- const outlinesWithRef = addRefsForOutlineItems(outlineNodes, context, rootOutlineRef);
208
- buildPdfObjectsForOutline(outlinesWithRef, context);
209
- const outlineObject = new Map();
210
- outlineObject.set(PDFName.of('Type'), PDFName.of('Outlines'));
211
- outlineObject.set(PDFName.of('First'), outlinesWithRef[0].ref);
212
- outlineObject.set(PDFName.of('Last'), outlinesWithRef[outlinesWithRef.length - 1].ref);
213
- outlineObject.set(PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(outlinesWithRef)));
214
- context.assign(rootOutlineRef, PDFDict.fromMapWithContext(outlineObject, context));
215
- pdfDoc.catalog.set(PDFName.of('Outlines'), rootOutlineRef);
216
- return outlinesWithRef;
217
- }
@@ -1,14 +0,0 @@
1
- import type { PDFDocument } from 'pdf-lib';
2
- export interface Meta {
3
- title?: string;
4
- lang?: string;
5
- subject?: string;
6
- author?: string;
7
- keywords?: string[] | string;
8
- creator?: string;
9
- producer?: string;
10
- creationDate?: Date | string;
11
- modDate?: Date | string;
12
- [tag: string]: unknown;
13
- }
14
- export declare function setMetadata(pdfDoc: PDFDocument, meta: Meta): void;
@@ -1,36 +0,0 @@
1
- export function setMetadata(pdfDoc, meta) {
2
- // Get the existing Info
3
- if (!meta.creator) {
4
- const creator = pdfDoc.getCreator();
5
- meta.creator = creator ? `${creator} - doom` : 'doom';
6
- }
7
- pdfDoc.setCreator(meta.creator);
8
- if (meta.author) {
9
- pdfDoc.setAuthor(meta.author);
10
- }
11
- if (!meta.producer) {
12
- const producer = pdfDoc.getProducer();
13
- meta.producer = producer || 'doom';
14
- }
15
- pdfDoc.setProducer(meta.producer);
16
- if (meta.title) {
17
- pdfDoc.setTitle(meta.title);
18
- }
19
- if (meta.subject) {
20
- pdfDoc.setSubject(meta.subject);
21
- }
22
- if (!meta.keywords) {
23
- meta.keywords = [];
24
- }
25
- else if (typeof meta.keywords === 'string') {
26
- meta.keywords = meta.keywords.split(',');
27
- }
28
- pdfDoc.setKeywords(meta.keywords);
29
- // Overwrite Dates
30
- if (!(meta.creationDate instanceof Date)) {
31
- meta.creationDate = new Date();
32
- }
33
- pdfDoc.setCreationDate(meta.creationDate);
34
- meta.modDate = new Date();
35
- pdfDoc.setModificationDate(meta.modDate);
36
- }
@@ -1,59 +0,0 @@
1
- import EventEmitter from 'node:events';
2
- import type { Browser, LaunchOptions, Page } from 'playwright';
3
- import { type OutlineNode } from './outline.js';
4
- export type PDFOptions = Exclude<Parameters<Page['pdf']>[0], undefined>;
5
- export type { Browser, LaunchOptions, Page };
6
- export type PageInitScriptFn = Page['addInitScript'];
7
- export interface PrinterOptions {
8
- debug?: boolean;
9
- headless?: LaunchOptions['headless'];
10
- allowLocal?: boolean;
11
- allowRemote?: boolean;
12
- outlineTags?: string[];
13
- initScripts?: PageInitScriptFn[];
14
- additionalScripts?: string[];
15
- additionalStyles?: string[];
16
- allowedPaths?: string[];
17
- allowedDomains?: string[];
18
- ignoreHTTPSErrors?: boolean;
19
- browserEndpoint?: string;
20
- browserArgs?: string[];
21
- timeout?: number;
22
- emulateMedia?: null | 'screen' | 'print';
23
- enableWarnings?: boolean;
24
- outlineContainerSelector?: string;
25
- }
26
- export declare class Printer extends EventEmitter {
27
- private debug;
28
- private headless;
29
- private allowLocal;
30
- private outlineTags;
31
- private allowRemote;
32
- private initScripts;
33
- private additionalScripts;
34
- private additionalStyles;
35
- private allowedPaths;
36
- private allowedDomains;
37
- private ignoreHTTPSErrors;
38
- private browserWSEndpoint?;
39
- private browserArgs;
40
- private timeout;
41
- private emulateMedia;
42
- private enableWarnings;
43
- private outlineContainerSelector;
44
- private browser?;
45
- private browserContext?;
46
- private page?;
47
- private url?;
48
- constructor(options?: PrinterOptions);
49
- setup(launchOptions?: LaunchOptions): Promise<Page>;
50
- render(url: string): Promise<Page>;
51
- pdf(url: string, options?: PDFOptions, pdfOutlines?: boolean): Promise<{
52
- data: Uint8Array<ArrayBufferLike>;
53
- outlineNodes: OutlineNode[];
54
- }>;
55
- closeBrowser(): Promise<void>;
56
- needsAllowedRules(): number;
57
- withinAllowedPath(pathname: string): boolean;
58
- isAllowedDomain(domain: string): boolean;
59
- }