@alauda/doom 1.10.12 → 1.12.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/assets/alert.svg +1 -0
- package/assets/angle-down.svg +1 -0
- package/assets/assistant.svg +1 -0
- package/assets/close.svg +1 -0
- package/assets/logout.svg +1 -0
- package/assets/new-chat.svg +1 -0
- package/assets/question-circle.svg +1 -0
- package/assets/send.svg +1 -0
- package/lib/cli/export.js +1 -1
- package/lib/cli/load-config.js +11 -6
- package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.d.ts +5 -0
- package/lib/global/Intelligence/AIAssistant/Chat/ChatRefDocs/index.js +16 -0
- package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.d.ts +4 -0
- package/lib/global/Intelligence/AIAssistant/Chat/ThinkingProcess/index.js +6 -0
- package/lib/global/Intelligence/AIAssistant/Chat/index.d.ts +7 -0
- package/lib/global/Intelligence/AIAssistant/Chat/index.js +8 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.d.ts +5 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/ApiErrorAlert/index.js +22 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Button/index.d.ts +8 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Button/index.js +5 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.d.ts +10 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/CaptchaInput/index.js +14 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/FocusInput/index.d.ts +6 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/FocusInput/index.js +19 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/FormItem/index.d.ts +16 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/FormItem/index.js +27 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Input/index.d.ts +7 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Input/index.js +5 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.d.ts +3 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/index.js +88 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/types.d.ts +18 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/utils.d.ts +3 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/LoginForm/utils.js +7 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/Radio.d.ts +7 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/Radio.js +11 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/RadioGroup.d.ts +11 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/RadioGroup.js +21 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/context.d.ts +7 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/context.js +2 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/index.d.ts +2 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/Radio/index.js +2 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/index.d.ts +4 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/index.js +10 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/types.d.ts +9 -0
- package/lib/global/Intelligence/AIAssistant/Preamble/types.js +1 -0
- package/lib/global/Intelligence/AIAssistant/ResizableUserInput/index.d.ts +8 -0
- package/lib/global/Intelligence/AIAssistant/ResizableUserInput/index.js +54 -0
- package/lib/global/Intelligence/AIAssistant/Thinking.d.ts +1 -0
- package/lib/global/Intelligence/AIAssistant/Thinking.js +15 -0
- package/lib/global/Intelligence/AIAssistant/index.d.ts +6 -0
- package/lib/global/Intelligence/AIAssistant/index.js +122 -0
- package/lib/global/Intelligence/AIAssistant/types.d.ts +14 -0
- package/lib/global/Intelligence/AIAssistant/types.js +1 -0
- package/lib/global/Intelligence/AIAssistant/utils.d.ts +8 -0
- package/lib/global/Intelligence/AIAssistant/utils.js +29 -0
- package/lib/global/Intelligence/constants.d.ts +6 -0
- package/lib/global/Intelligence/constants.js +21 -0
- package/lib/global/Intelligence/context.d.ts +18 -0
- package/lib/global/Intelligence/context.js +31 -0
- package/lib/global/Intelligence/index.d.ts +2 -0
- package/lib/global/Intelligence/index.js +33 -0
- package/lib/global/Intelligence/types.d.ts +32 -0
- package/lib/global/Intelligence/types.js +6 -0
- package/lib/global/Intelligence/utils.d.ts +3 -0
- package/lib/global/Intelligence/utils.js +32 -0
- package/lib/global/VersionsNav/NavMenuSingleItem.js +2 -2
- package/lib/plugins/index.d.ts +0 -1
- package/lib/plugins/index.js +0 -1
- package/lib/runtime/components/OpenAPIPath.js +2 -3
- package/lib/runtime/components/Overview.js +3 -6
- package/lib/runtime/components/_utils.d.ts +1 -1
- package/lib/runtime/components/_utils.js +2 -4
- package/lib/runtime/hooks/index.d.ts +5 -3
- package/lib/runtime/hooks/index.js +5 -3
- package/lib/runtime/hooks/useInterval.d.ts +1 -0
- package/lib/runtime/hooks/useInterval.js +19 -0
- package/lib/runtime/hooks/useMemoizedFn.d.ts +1 -0
- package/lib/runtime/hooks/useMemoizedFn.js +12 -0
- package/lib/runtime/hooks/useTranslation.d.ts +1 -1
- package/lib/runtime/translation.d.ts +148 -0
- package/lib/runtime/translation.js +111 -0
- package/package.json +32 -30
- package/styles/ai-assistant.module.scss +61 -0
- package/styles/chat-ref-docs.module.scss +50 -0
- package/styles/chat.module.scss +72 -0
- package/styles/global.scss +2 -0
- package/styles/intelligence.module.scss +26 -0
- package/styles/intelligence.scss +168 -0
- package/styles/preamble.module.scss +27 -0
- package/styles/resizable-user-input.module.scss +60 -0
- package/LICENSE +0 -21
- package/README.md +0 -29
- package/lib/cli/export-pdf-core/generatePdf.d.ts +0 -25
- package/lib/cli/export-pdf-core/generatePdf.js +0 -91
- package/lib/cli/export-pdf-core/index.d.ts +0 -3
- package/lib/cli/export-pdf-core/index.js +0 -3
- package/lib/cli/export-pdf-core/types.d.ts +0 -15
- package/lib/cli/export-pdf-core/utils/convertPathToPosix.d.ts +0 -8
- package/lib/cli/export-pdf-core/utils/convertPathToPosix.js +0 -26
- package/lib/cli/export-pdf-core/utils/getUrlLink.d.ts +0 -4
- package/lib/cli/export-pdf-core/utils/getUrlLink.js +0 -7
- package/lib/cli/export-pdf-core/utils/index.d.ts +0 -3
- package/lib/cli/export-pdf-core/utils/index.js +0 -3
- package/lib/cli/export-pdf-core/utils/mergePDF.d.ts +0 -26
- package/lib/cli/export-pdf-core/utils/mergePDF.js +0 -137
- package/lib/cli/html-export-pdf/core/index.d.ts +0 -3
- package/lib/cli/html-export-pdf/core/index.js +0 -3
- package/lib/cli/html-export-pdf/core/outline.d.ts +0 -47
- package/lib/cli/html-export-pdf/core/outline.js +0 -217
- package/lib/cli/html-export-pdf/core/postprocesser.d.ts +0 -14
- package/lib/cli/html-export-pdf/core/postprocesser.js +0 -36
- package/lib/cli/html-export-pdf/core/printer.d.ts +0 -59
- package/lib/cli/html-export-pdf/core/printer.js +0 -235
- package/lib/cli/html-export-pdf/index.d.ts +0 -2
- package/lib/cli/html-export-pdf/index.js +0 -2
- package/lib/cli/html-export-pdf/utils/cliProgress.d.ts +0 -13
- package/lib/cli/html-export-pdf/utils/cliProgress.js +0 -80
- package/lib/cli/html-export-pdf/utils/fs.d.ts +0 -5
- package/lib/cli/html-export-pdf/utils/fs.js +0 -18
- package/lib/cli/html-export-pdf/utils/getAbsFileName.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/getAbsFileName.js +0 -4
- package/lib/cli/html-export-pdf/utils/getDirname.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/getDirname.js +0 -5
- package/lib/cli/html-export-pdf/utils/index.d.ts +0 -7
- package/lib/cli/html-export-pdf/utils/index.js +0 -7
- package/lib/cli/html-export-pdf/utils/isValidUrl.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/isValidUrl.js +0 -3
- package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.d.ts +0 -2
- package/lib/cli/html-export-pdf/utils/optionsCustomProcessing.js +0 -6
- package/lib/cli/html-export-pdf/utils/replaceExt.d.ts +0 -1
- package/lib/cli/html-export-pdf/utils/replaceExt.js +0 -19
- package/lib/cli/merge-pdfs/formatDate.d.ts +0 -1
- package/lib/cli/merge-pdfs/formatDate.js +0 -23
- package/lib/cli/merge-pdfs/index.d.ts +0 -8
- package/lib/cli/merge-pdfs/index.js +0 -62
- package/lib/plugins/sitemap/index.d.ts +0 -16
- package/lib/plugins/sitemap/index.js +0 -51
- package/pyodide/README.md +0 -90
- package/pyodide/console.html +0 -259
- package/pyodide/ffi.d.ts +0 -1118
- package/pyodide/micropip-0.8.0-py3-none-any.whl +0 -0
- package/pyodide/package.json +0 -59
- package/pyodide/packaging-24.2-py3-none-any.whl +0 -0
- package/pyodide/pyodide-lock.json +0 -1
- package/pyodide/pyodide.asm.js +0 -17
- package/pyodide/pyodide.asm.wasm +0 -0
- package/pyodide/pyodide.d.ts +0 -1627
- package/pyodide/pyodide.js +0 -6
- package/pyodide/pyodide.js.map +0 -1
- package/pyodide/pyodide.mjs +0 -4
- package/pyodide/pyodide.mjs.map +0 -1
- package/pyodide/pypdf-3.8.1-py3-none-any.whl +0 -0
- package/pyodide/python_stdlib.zip +0 -0
- package/pyodide/repodata.json +0 -1
- /package/lib/{cli/export-pdf-core → global/Intelligence/AIAssistant/Preamble/LoginForm}/types.js +0 -0
|
@@ -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
|
-
}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import process from 'node:process';
|
|
4
|
-
import { PDFDocument } from 'pdf-lib';
|
|
5
|
-
import { chromium } from 'playwright';
|
|
6
|
-
import { red } from 'yoctocolors';
|
|
7
|
-
import { getOutlineNodes, setOutlineNodes, } from './outline.js';
|
|
8
|
-
import { setMetadata } from './postprocesser.js';
|
|
9
|
-
export class Printer extends EventEmitter {
|
|
10
|
-
debug;
|
|
11
|
-
headless;
|
|
12
|
-
allowLocal;
|
|
13
|
-
outlineTags;
|
|
14
|
-
allowRemote;
|
|
15
|
-
initScripts;
|
|
16
|
-
additionalScripts;
|
|
17
|
-
additionalStyles;
|
|
18
|
-
allowedPaths;
|
|
19
|
-
allowedDomains;
|
|
20
|
-
ignoreHTTPSErrors;
|
|
21
|
-
browserWSEndpoint;
|
|
22
|
-
browserArgs;
|
|
23
|
-
timeout;
|
|
24
|
-
emulateMedia;
|
|
25
|
-
enableWarnings;
|
|
26
|
-
outlineContainerSelector;
|
|
27
|
-
browser;
|
|
28
|
-
browserContext;
|
|
29
|
-
page;
|
|
30
|
-
url;
|
|
31
|
-
constructor(options = {}) {
|
|
32
|
-
super();
|
|
33
|
-
this.debug = options.debug ?? false;
|
|
34
|
-
this.headless = options.headless ?? true;
|
|
35
|
-
this.allowLocal = options.allowLocal ?? false;
|
|
36
|
-
this.allowRemote = options.allowRemote ?? true;
|
|
37
|
-
this.outlineTags = options.outlineTags ?? [
|
|
38
|
-
'h1',
|
|
39
|
-
'h2',
|
|
40
|
-
'h3',
|
|
41
|
-
'h4',
|
|
42
|
-
'h5',
|
|
43
|
-
'h6',
|
|
44
|
-
];
|
|
45
|
-
this.initScripts = options.initScripts ?? [];
|
|
46
|
-
this.additionalScripts = options.additionalScripts ?? [];
|
|
47
|
-
this.additionalStyles = options.additionalStyles ?? [];
|
|
48
|
-
this.allowedPaths = options.allowedPaths ?? [];
|
|
49
|
-
this.allowedDomains = options.allowedDomains ?? [];
|
|
50
|
-
this.ignoreHTTPSErrors = options.ignoreHTTPSErrors ?? false;
|
|
51
|
-
this.browserWSEndpoint = options.browserEndpoint;
|
|
52
|
-
this.browserArgs = options.browserArgs ?? [];
|
|
53
|
-
this.timeout = options.timeout ?? 0;
|
|
54
|
-
this.emulateMedia = options.emulateMedia ?? 'print';
|
|
55
|
-
this.enableWarnings = options.enableWarnings ?? false;
|
|
56
|
-
this.outlineContainerSelector = options.outlineContainerSelector ?? '';
|
|
57
|
-
if (this.debug) {
|
|
58
|
-
this.headless = false;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
async setup(launchOptions) {
|
|
62
|
-
if (this.page) {
|
|
63
|
-
return this.page;
|
|
64
|
-
}
|
|
65
|
-
const browserOptions = {
|
|
66
|
-
pipe: true,
|
|
67
|
-
headless: this.headless,
|
|
68
|
-
args: ['--disable-dev-shm-usage', '--export-tagged-pdf'],
|
|
69
|
-
...launchOptions,
|
|
70
|
-
};
|
|
71
|
-
if (this.allowLocal) {
|
|
72
|
-
browserOptions.args.push('--allow-file-access-from-files');
|
|
73
|
-
}
|
|
74
|
-
if (this.browserArgs.length) {
|
|
75
|
-
browserOptions.args.push(...this.browserArgs);
|
|
76
|
-
}
|
|
77
|
-
if (this.browserWSEndpoint) {
|
|
78
|
-
this.browser = await chromium.connect(this.browserWSEndpoint, browserOptions);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this.browser = await chromium.launch(browserOptions);
|
|
82
|
-
}
|
|
83
|
-
this.browserContext = await this.browser.newContext({
|
|
84
|
-
ignoreHTTPSErrors: this.ignoreHTTPSErrors,
|
|
85
|
-
});
|
|
86
|
-
for (const script of this.initScripts) {
|
|
87
|
-
await this.browserContext.addInitScript(script);
|
|
88
|
-
}
|
|
89
|
-
const page = await this.browserContext.newPage();
|
|
90
|
-
this.page = page;
|
|
91
|
-
await page.emulateMedia({
|
|
92
|
-
colorScheme: 'light',
|
|
93
|
-
media: this.emulateMedia,
|
|
94
|
-
});
|
|
95
|
-
if (this.needsAllowedRules()) {
|
|
96
|
-
await page.route('**/*', (route) => {
|
|
97
|
-
const uri = new URL(route.request().url());
|
|
98
|
-
const { host, protocol, pathname } = uri;
|
|
99
|
-
const local = protocol === 'file:';
|
|
100
|
-
if (local && !this.withinAllowedPath(pathname)) {
|
|
101
|
-
return route.abort();
|
|
102
|
-
}
|
|
103
|
-
if (local && !this.allowLocal) {
|
|
104
|
-
return route.abort();
|
|
105
|
-
}
|
|
106
|
-
if (host && !this.isAllowedDomain(host)) {
|
|
107
|
-
return route.abort();
|
|
108
|
-
}
|
|
109
|
-
if (host && !this.allowRemote) {
|
|
110
|
-
return route.abort();
|
|
111
|
-
}
|
|
112
|
-
return route.continue();
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return page;
|
|
116
|
-
}
|
|
117
|
-
async render(url) {
|
|
118
|
-
const page = this.page || (await this.setup());
|
|
119
|
-
if (url === this.url) {
|
|
120
|
-
return page;
|
|
121
|
-
}
|
|
122
|
-
this.url = url;
|
|
123
|
-
try {
|
|
124
|
-
await page.goto(url);
|
|
125
|
-
for (const style of this.additionalStyles) {
|
|
126
|
-
await page.addStyleTag({ path: style });
|
|
127
|
-
}
|
|
128
|
-
for (const script of this.additionalScripts) {
|
|
129
|
-
await page.addScriptTag({ path: script });
|
|
130
|
-
}
|
|
131
|
-
await page.waitForLoadState('networkidle', { timeout: this.timeout });
|
|
132
|
-
return page;
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
await this.closeBrowser();
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
async pdf(url, options = {}, pdfOutlines) {
|
|
140
|
-
const page = await this.render(url);
|
|
141
|
-
try {
|
|
142
|
-
// Get metatags
|
|
143
|
-
const meta = await page.evaluate(() => {
|
|
144
|
-
const meta = {};
|
|
145
|
-
const title = document.querySelector('title');
|
|
146
|
-
if (title) {
|
|
147
|
-
meta.title = title.textContent.trim();
|
|
148
|
-
}
|
|
149
|
-
const lang = document.querySelector('html')?.getAttribute('lang');
|
|
150
|
-
if (lang) {
|
|
151
|
-
meta.lang = lang;
|
|
152
|
-
}
|
|
153
|
-
const metaTags = document.querySelectorAll('meta');
|
|
154
|
-
metaTags.forEach((tag) => {
|
|
155
|
-
if (tag.name) {
|
|
156
|
-
meta[tag.name] = tag.content;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return meta;
|
|
160
|
-
});
|
|
161
|
-
const pdfExportOptions = {
|
|
162
|
-
scale: !options.scale ? 1 : options.scale,
|
|
163
|
-
displayHeaderFooter: false,
|
|
164
|
-
headerTemplate: options.headerTemplate,
|
|
165
|
-
footerTemplate: options.footerTemplate,
|
|
166
|
-
preferCSSPageSize: options.preferCSSPageSize,
|
|
167
|
-
printBackground: options.printBackground,
|
|
168
|
-
width: options.width,
|
|
169
|
-
height: options.height,
|
|
170
|
-
landscape: options.landscape,
|
|
171
|
-
format: options.format,
|
|
172
|
-
};
|
|
173
|
-
if (options.margin) {
|
|
174
|
-
pdfExportOptions.margin = options.margin;
|
|
175
|
-
}
|
|
176
|
-
if (options.pageRanges) {
|
|
177
|
-
pdfExportOptions.pageRanges = options.pageRanges;
|
|
178
|
-
}
|
|
179
|
-
if (options.headerTemplate || options.footerTemplate) {
|
|
180
|
-
pdfExportOptions.displayHeaderFooter = true;
|
|
181
|
-
}
|
|
182
|
-
const pdf = await page.pdf(pdfExportOptions);
|
|
183
|
-
this.emit('postprocessing');
|
|
184
|
-
const pdfDoc = await PDFDocument.load(pdf);
|
|
185
|
-
setMetadata(pdfDoc, meta);
|
|
186
|
-
let outlineNodes = [];
|
|
187
|
-
if (pdfOutlines) {
|
|
188
|
-
outlineNodes = await getOutlineNodes(page, this.outlineTags, this.outlineContainerSelector);
|
|
189
|
-
setOutlineNodes(pdfDoc, outlineNodes, this.enableWarnings);
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
data: await pdfDoc.save(),
|
|
193
|
-
outlineNodes,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
await this.closeBrowser();
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async closeBrowser() {
|
|
202
|
-
if (this.browser) {
|
|
203
|
-
await this.browser.close();
|
|
204
|
-
this.browser = undefined;
|
|
205
|
-
this.browserContext = undefined;
|
|
206
|
-
this.page = undefined;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
process.stdout.write(red('Browser instance not found'));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
needsAllowedRules() {
|
|
213
|
-
return this.allowedPaths.length || this.allowedDomains.length;
|
|
214
|
-
}
|
|
215
|
-
withinAllowedPath(pathname) {
|
|
216
|
-
if (!this.allowedPaths.length) {
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
for (const parent of this.allowedPaths) {
|
|
220
|
-
const relative = path.relative(parent, pathname);
|
|
221
|
-
if (relative &&
|
|
222
|
-
!relative.startsWith('..') &&
|
|
223
|
-
!path.isAbsolute(relative)) {
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
isAllowedDomain(domain) {
|
|
230
|
-
if (!this.allowedDomains.length) {
|
|
231
|
-
return true;
|
|
232
|
-
}
|
|
233
|
-
return this.allowedDomains.includes(domain);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SingleBar } from 'cli-progress';
|
|
2
|
-
export declare function createProgress(indeterminate?: boolean): {
|
|
3
|
-
bar: SingleBar;
|
|
4
|
-
start(total: number): void;
|
|
5
|
-
updateNumber(v: number): void;
|
|
6
|
-
increment(step: number, { txt, headTitle }?: {
|
|
7
|
-
txt?: string;
|
|
8
|
-
headTitle?: string;
|
|
9
|
-
}): void;
|
|
10
|
-
updateText(t: string): void;
|
|
11
|
-
updateTitle(t: string): void;
|
|
12
|
-
stop(): void;
|
|
13
|
-
};
|