@poe-platform/safe-bash 0.1.756 → 0.1.757

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 (113) hide show
  1. package/dist/image-ast/index.browser.js +4 -4
  2. package/dist/image-ast/index.js +4 -4
  3. package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
  4. package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
  5. package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
  7. package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
  8. package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
  9. package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
  11. package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
  12. package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
  13. package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
  14. package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
  15. package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
  16. package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
  17. package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
  19. package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
  20. package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
  21. package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
  22. package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
  23. package/dist/safe-bash/commands/pandoc/index.js +5 -3
  24. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  25. package/dist/safe-bash/commands/python/index.js +6 -0
  26. package/dist/safe-bash/commands/python/jspi.js +11 -2
  27. package/dist/safe-bash/core.browser.js +6 -4
  28. package/dist/safe-bash-command-csvkit/index.js +8 -8
  29. package/dist/safe-bash-command-soffice/index.js +16 -16
  30. package/dist/safe-bash-command-ssconvert/core.js +8 -8
  31. package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
  32. package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
  33. package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
  34. package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
  35. package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
  36. package/dist/safe-bash-command-ssconvert/index.js +107 -27
  37. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  38. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  39. package/dist/safe-bash-mcp/index.js +4 -4
  40. package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
  41. package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
  42. package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
  43. package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
  44. package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
  45. package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
  46. package/dist/spreadsheet-engine/formulas/parser.js +34 -0
  47. package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
  48. package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
  49. package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
  50. package/dist/xlsx-ast/formula-semantics.js +2 -0
  51. package/package.json +2 -2
  52. package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
  53. package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
  54. package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
  55. package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
  56. package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
  57. package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
  58. package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
  59. package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
  60. package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
  61. package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
  62. package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
  63. package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
  64. package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
  65. package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
  66. package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
  67. package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
  68. package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
  69. package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
  70. package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
  71. package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
  72. package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
  73. package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
  74. package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
  75. package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
  76. package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
  77. package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
  78. package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
  79. package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
  80. package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
  81. package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
  82. package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
  83. package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
  84. package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
  85. package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
  86. package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
  87. package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
  88. package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
  89. package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
  90. package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
  91. package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
  92. package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
  93. package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
  94. package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
  95. package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
  96. package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
  97. package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
  98. package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
  99. package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
  100. package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
  101. package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
  102. package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
  103. package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
  104. package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
  105. package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
  106. package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
  107. package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
  108. package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
  109. package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
  110. package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
  111. package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
  112. package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
  113. package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
@@ -1,2317 +0,0 @@
1
- import {
2
- PdfDocument,
3
- decodePng
4
- } from "./chunk-JCN3FXLP.js";
5
- import {
6
- init_platform
7
- } from "./chunk-ZG7GWQ5P.js";
8
-
9
- // packages/safe-bash-command-wkhtmltopdf/src/pdf-renderer.ts
10
- init_platform();
11
- import { yieldTurn } from "../../safe-bash-contracts/yield.js";
12
-
13
- // packages/safe-bash-command-wkhtmltopdf/src/command.ts
14
- init_platform();
15
- import { commandRuntimeIdentity, getCommandArguments } from "../../safe-bash-contracts/command.js";
16
- import { readBytes, writeBytes } from "../../safe-bash-contracts/io.js";
17
- import { shellValueByteLength } from "../../safe-bash-contracts/value.js";
18
- import { FsError } from "../../safe-bash-contracts/errors.js";
19
- import { createOutputOperation } from "../../safe-bash-contracts/output.js";
20
- import { basename, compareEntries, dirname, resolvePath } from "@poe-platform/safe-fs/core";
21
-
22
- // packages/safe-bash-command-wkhtmltopdf/src/errors.ts
23
- init_platform();
24
- var WkhtmltopdfError = class extends Error {
25
- constructor(code, message, option) {
26
- super(message);
27
- this.code = code;
28
- this.option = option;
29
- this.name = "WkhtmltopdfError";
30
- }
31
- code;
32
- option;
33
- exitCode = 1;
34
- };
35
-
36
- // packages/safe-bash-command-wkhtmltopdf/src/engine.ts
37
- init_platform();
38
- var rendererFeatures = [
39
- "html5",
40
- "computed-css",
41
- "selectors",
42
- "css-units",
43
- "block-inline",
44
- "font-shaping",
45
- "lists",
46
- "images",
47
- "table-spans",
48
- "pagination",
49
- "break-rules",
50
- "widows-orphans",
51
- "positioning",
52
- "page-furniture",
53
- "flex",
54
- "grid"
55
- ];
56
- function requireRendererFeatures(profile, required) {
57
- if (typeof profile.id !== "string" || !profile.id || profile.id.length > 128 || profile.features.length > rendererFeatures.length || required.length > rendererFeatures.length) {
58
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected a bounded renderer profile and feature requirements");
59
- }
60
- for (const feature of [...profile.features, ...required]) {
61
- if (!rendererFeatures.includes(feature)) {
62
- throw new WkhtmltopdfError("INVALID_VALUE", "Unknown renderer feature");
63
- }
64
- }
65
- for (const feature of required) {
66
- if (!profile.features.includes(feature)) {
67
- throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", `Renderer profile ${profile.id} does not support ${feature}`);
68
- }
69
- }
70
- }
71
- function planPageSequence(objects, options) {
72
- const checkCancellation = () => {
73
- if (options.signal?.aborted) throw options.signal.reason;
74
- };
75
- checkCancellation();
76
- const { maxObjects, maxPhysicalPages, maxWork } = options.limits;
77
- for (const value of [maxObjects, maxPhysicalPages, maxWork]) {
78
- if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) {
79
- throw new WkhtmltopdfError("INVALID_VALUE", "Page sequence limits must be positive safe integers or Infinity");
80
- }
81
- }
82
- if (!Number.isSafeInteger(options.copies) || options.copies < 1) {
83
- throw new WkhtmltopdfError("INVALID_VALUE", "Page copies must be positive safe integers");
84
- }
85
- if (typeof options.collate !== "boolean" || !Number.isInteger(options.pageOffset) || options.pageOffset < -2147483648 || options.pageOffset > 2147483647) {
86
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected boolean collate and int32 page offset");
87
- }
88
- if (objects.length > maxObjects || objects.length > maxWork) {
89
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Page sequence object/work limit exceeded");
90
- }
91
- let outlineTotal = 0;
92
- let logicalTotal = 0;
93
- const workLimit = Math.min(maxWork, Number.MAX_SAFE_INTEGER);
94
- const sourcePageLimit = Math.floor(Math.min(maxPhysicalPages, workLimit - objects.length) / options.copies);
95
- for (const object of objects) {
96
- checkCancellation();
97
- if (!Number.isSafeInteger(object.physicalPages) || object.physicalPages < 0 || typeof object.pagesCount !== "boolean") {
98
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected a nonnegative safe page count and boolean pagesCount");
99
- }
100
- if (object.physicalPages > sourcePageLimit - outlineTotal) {
101
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Page sequence physical-page/work limit exceeded");
102
- }
103
- outlineTotal += object.physicalPages;
104
- if (object.pagesCount) logicalTotal += object.physicalPages;
105
- }
106
- if (!Number.isSafeInteger(logicalTotal + Math.abs(options.pageOffset) + 1)) {
107
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Logical page number exceeds checked precision");
108
- }
109
- const passes = options.collate ? options.copies : 1;
110
- if (outlineTotal > 0) {
111
- const remainingWork = workLimit - objects.length - outlineTotal * options.copies;
112
- if (objects.length > Math.floor(remainingWork / passes)) {
113
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Page sequence repeated traversal work limit exceeded");
114
- }
115
- }
116
- const pages = [];
117
- const emit = (objectIndex, pageIndex, copyIndex, logicalPage, outlinePage) => {
118
- checkCancellation();
119
- pages.push({ objectIndex, pageIndex, copyIndex, outputPage: pages.length + 1, logicalPage, outlinePage });
120
- };
121
- if (outlineTotal === 0) return { pages, logicalTotal, outlineTotal };
122
- for (let pass = 0; pass < passes; pass++) {
123
- let logicalPage = 1 + options.pageOffset;
124
- let outlinePage = 1;
125
- for (let objectIndex = 0; objectIndex < objects.length; objectIndex++) {
126
- checkCancellation();
127
- const object = objects[objectIndex];
128
- for (let pageIndex = 0; pageIndex < object.physicalPages; pageIndex++) {
129
- if (options.collate) emit(objectIndex, pageIndex, pass, logicalPage, outlinePage);
130
- else for (let copyIndex = 0; copyIndex < options.copies; copyIndex++) {
131
- emit(objectIndex, pageIndex, copyIndex, logicalPage, outlinePage);
132
- }
133
- if (object.pagesCount) logicalPage++;
134
- outlinePage++;
135
- }
136
- }
137
- }
138
- return { pages, logicalTotal, outlineTotal };
139
- }
140
-
141
- // packages/safe-bash-command-wkhtmltopdf/src/limits.ts
142
- init_platform();
143
- var ParseBudget = class {
144
- constructor(options) {
145
- this.options = options;
146
- this.checkCancellation();
147
- this.limits = {
148
- maxArguments: options.limits?.maxArguments ?? Infinity,
149
- maxTextBytes: options.limits?.maxTextBytes ?? Infinity,
150
- maxObjects: options.limits?.maxObjects ?? Infinity,
151
- maxWork: options.limits?.maxWork ?? Infinity
152
- };
153
- for (const value of Object.values(this.limits)) {
154
- if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) {
155
- throw new WkhtmltopdfError("INVALID_VALUE", "Parser limits must be positive safe integers");
156
- }
157
- }
158
- }
159
- options;
160
- work = 0;
161
- bytes = 0;
162
- objects = 0;
163
- limits;
164
- checkCancellation() {
165
- if (this.options.signal?.aborted) throw this.options.signal.reason;
166
- }
167
- step(amount = 1) {
168
- this.checkCancellation();
169
- if (amount > this.limits.maxWork - this.work) {
170
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser work limit exceeded");
171
- }
172
- this.work += amount;
173
- }
174
- admitArguments(count) {
175
- this.step();
176
- if (count > this.limits.maxArguments) {
177
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser argument limit exceeded");
178
- }
179
- }
180
- admitText(text) {
181
- for (let i = 0; i < text.length; i++) {
182
- this.step();
183
- const code = text.charCodeAt(i);
184
- let size = code < 128 ? 1 : code < 2048 ? 2 : 3;
185
- if (code >= 55296 && code <= 56319) {
186
- const next = text.charCodeAt(i + 1);
187
- if (next >= 56320 && next <= 57343) {
188
- size = 4;
189
- i++;
190
- this.step();
191
- }
192
- }
193
- if (size > this.limits.maxTextBytes - this.bytes) {
194
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser text byte limit exceeded");
195
- }
196
- this.bytes += size;
197
- if (code === 0) throw new WkhtmltopdfError("INVALID_VALUE", "NUL is not admitted in CLI text");
198
- }
199
- }
200
- admitObject(replacementCount) {
201
- this.step(64 + replacementCount * 2);
202
- if (++this.objects > this.limits.maxObjects) {
203
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser object limit exceeded");
204
- }
205
- }
206
- };
207
-
208
- // packages/safe-bash-command-wkhtmltopdf/src/outcome.ts
209
- init_platform();
210
- var httpDescriptions = {
211
- 400: "Bad Request",
212
- 401: "Unauthorized",
213
- 402: "Payment Required",
214
- 403: "Forbidden",
215
- 404: "Page not found",
216
- 405: "Method Not Allowed",
217
- 500: "Internal Server Error",
218
- 501: "Not Implemented",
219
- 503: "Service Unavailable",
220
- 505: "HTTP Version Not Supported"
221
- };
222
- function conversionOutcome(completion) {
223
- const { mode, success, errorCode, networkErrorName } = completion;
224
- if (mode !== "single" && mode !== "batch" || typeof success !== "boolean" || !Number.isInteger(errorCode) || errorCode < 0 || errorCode > 2147483647) {
225
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected a conversion mode, boolean success and nonnegative int32 loader code");
226
- }
227
- if (networkErrorName !== void 0) {
228
- if (typeof networkErrorName !== "string" || !networkErrorName.length || networkErrorName.length > 128) {
229
- throw new WkhtmltopdfError("INVALID_VALUE", "Network enum name must contain 1\u2013128 ASCII identifier characters");
230
- }
231
- for (const character of networkErrorName) {
232
- if (!(character >= "a" && character <= "z") && !(character >= "A" && character <= "Z") && !(character >= "0" && character <= "9") && character !== "_") {
233
- throw new WkhtmltopdfError("INVALID_VALUE", "Network enum name must contain ASCII identifier characters");
234
- }
235
- }
236
- }
237
- if (mode === "batch") return { exitCode: success ? 0 : 1, diagnostic: null };
238
- if (errorCode >= 1e3) {
239
- return { exitCode: 1, diagnostic: { kind: "network", code: errorCode - 1e3, name: networkErrorName ?? null } };
240
- }
241
- if (errorCode !== 0) {
242
- return {
243
- exitCode: errorCode === 404 ? 2 : errorCode === 401 ? 3 : 1,
244
- diagnostic: { kind: "http", code: errorCode, description: httpDescriptions[errorCode] ?? "" }
245
- };
246
- }
247
- return { exitCode: success ? 0 : 1, diagnostic: success ? null : { kind: "unknown" } };
248
- }
249
-
250
- // packages/safe-bash-command-wkhtmltopdf/src/parser.ts
251
- init_platform();
252
-
253
- // packages/safe-bash-command-wkhtmltopdf/src/settings.ts
254
- init_platform();
255
- function createGlobalSettings() {
256
- return {
257
- logLevel: "info",
258
- orientation: "Portrait",
259
- pageSize: "A4",
260
- dpi: 96,
261
- copies: 1,
262
- collate: true,
263
- outline: true,
264
- outlineDepth: 4,
265
- imageDPI: 600,
266
- imageQuality: 94,
267
- useCompression: true,
268
- colorMode: "color",
269
- resolution: "high",
270
- documentTitle: "",
271
- marginTop: { value: -1, unit: "mm" },
272
- marginBottom: { value: -1, unit: "mm" },
273
- marginLeft: { value: 10, unit: "mm" },
274
- marginRight: { value: 10, unit: "mm" },
275
- pageHeight: { value: -1, unit: "mm" },
276
- pageWidth: { value: -1, unit: "mm" },
277
- pageOffset: 0,
278
- resolveRelativeLinks: true,
279
- viewportSize: "",
280
- readArgsFromStdin: false,
281
- action: ""
282
- };
283
- }
284
- function createPageSettings() {
285
- return {
286
- header: { fontSize: 12, fontName: "Arial", left: "", right: "", center: "", line: false, htmlUrl: "", spacing: 0 },
287
- footer: { fontSize: 12, fontName: "Arial", left: "", right: "", center: "", line: false, htmlUrl: "", spacing: 0 },
288
- toc: { useDottedLines: true, captionText: "Table of Contents", forwardLinks: true, backLinks: false, indentation: "1em", fontScale: Math.fround(0.8) },
289
- web: { background: true, loadImages: true, enableJavascript: true, enableIntelligentShrinking: true, minimumFontSize: -1, defaultEncoding: "", enablePlugins: false },
290
- load: { jsdelay: 200, zoomFactor: 1, blockLocalFileAccess: true, stopSlowScripts: true, loadErrorHandling: "abort", mediaLoadErrorHandling: "ignore", printMediaType: false },
291
- includeInOutline: true,
292
- pagesCount: true,
293
- produceForms: false,
294
- useLocalLinks: true,
295
- useExternalLinks: true,
296
- replacements: []
297
- };
298
- }
299
- function clonePageSettings(settings) {
300
- return {
301
- ...settings,
302
- header: { ...settings.header },
303
- footer: { ...settings.footer },
304
- toc: { ...settings.toc },
305
- web: { ...settings.web },
306
- load: { ...settings.load },
307
- replacements: settings.replacements.map(([key, value]) => [key, value])
308
- };
309
- }
310
-
311
- // packages/safe-bash-command-wkhtmltopdf/src/switches.ts
312
- init_platform();
313
-
314
- // packages/safe-bash-command-wkhtmltopdf/src/values.ts
315
- init_platform();
316
- function integer(text, min, max) {
317
- const value = text.trim();
318
- let index = value[0] === "+" || value[0] === "-" ? 1 : 0;
319
- if (index === value.length) throw new WkhtmltopdfError("INVALID_VALUE", "Expected an integer");
320
- for (; index < value.length; index++) {
321
- if (value[index] < "0" || value[index] > "9") {
322
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected a decimal integer");
323
- }
324
- }
325
- const result = Number(value);
326
- if (!Number.isSafeInteger(result) || result < min || result > max) {
327
- throw new WkhtmltopdfError("INVALID_VALUE", "Integer is outside the admitted range");
328
- }
329
- return result;
330
- }
331
- function float32(text, positive) {
332
- const value = text.trim();
333
- let digits = 0;
334
- for (const character of value) {
335
- if (character >= "0" && character <= "9") digits++;
336
- else if (!"+-.eE".includes(character)) {
337
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected a decimal float");
338
- }
339
- }
340
- const result = Math.fround(Number(value));
341
- if (!digits || !Number.isFinite(result) || (positive ? result <= 0 : result < 0)) {
342
- throw new WkhtmltopdfError("INVALID_VALUE", "Float is outside the admitted finite binary32 range");
343
- }
344
- return result;
345
- }
346
- function choice(text, values) {
347
- const result = values.find((value) => value.toLowerCase() === text.toLowerCase());
348
- if (result === void 0) throw new WkhtmltopdfError("INVALID_VALUE", "Unknown enumerated value");
349
- return result;
350
- }
351
- function length(text) {
352
- let index = 0;
353
- while (text[index] !== void 0 && text[index] >= "0" && text[index] <= "9") index++;
354
- if (text[index] === ".") index++;
355
- while (text[index] !== void 0 && text[index] >= "0" && text[index] <= "9") index++;
356
- const number = text.slice(0, index);
357
- const value = Number(number);
358
- if (!number || number === "." || !Number.isFinite(value)) {
359
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected an unsigned finite length");
360
- }
361
- const units = {
362
- "": ["mm", 1],
363
- mm: ["mm", 1],
364
- millimeter: ["mm", 1],
365
- cm: ["mm", 10],
366
- centimeter: ["mm", 10],
367
- m: ["mm", 1e3],
368
- meter: ["mm", 1e3],
369
- in: ["in", 1],
370
- inch: ["in", 1],
371
- pt: ["pt", 1],
372
- point: ["pt", 1],
373
- px: ["px", 1],
374
- pixel: ["px", 1],
375
- pc: ["pc", 1],
376
- pica: ["pc", 1],
377
- didot: ["didot", 1],
378
- cicero: ["cicero", 1]
379
- };
380
- const suffix = text.slice(index).toLowerCase();
381
- const entry = Object.hasOwn(units, suffix) ? units[suffix] : void 0;
382
- if (!entry || !Number.isFinite(value * entry[1])) {
383
- throw new WkhtmltopdfError("INVALID_VALUE", "Unknown or overflowing length unit");
384
- }
385
- return { value: value * entry[1], unit: entry[0] };
386
- }
387
-
388
- // packages/safe-bash-command-wkhtmltopdf/src/switches.ts
389
- var declarations = [
390
- { name: "--help", short: "h", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
391
- _g.action = "help";
392
- } },
393
- { name: "--version", short: "V", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
394
- _g.action = "version";
395
- } },
396
- { name: "--license", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
397
- _g.action = "license";
398
- } },
399
- { name: "--extended-help", short: "H", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
400
- _g.action = "extended-help";
401
- } },
402
- { name: "--manpage", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
403
- _g.action = "manpage";
404
- } },
405
- { name: "--htmldoc", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
406
- _g.action = "htmldoc";
407
- } },
408
- { name: "--readme", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
409
- _g.action = "readme";
410
- } },
411
- { name: "--quiet", short: "q", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
412
- _g.logLevel = "none";
413
- } },
414
- { name: "--log-level", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
415
- _g.logLevel = choice(_a[0], ["none", "error", "warn", "info", "debug"]);
416
- } },
417
- { name: "--no-collate", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
418
- _g.collate = false;
419
- } },
420
- { name: "--collate", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
421
- _g.collate = true;
422
- } },
423
- { name: "--copies", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
424
- _g.copies = integer(_a[0], 1, 2147483647);
425
- } },
426
- { name: "--orientation", short: "O", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
427
- _g.orientation = choice(_a[0], ["Portrait", "Landscape"]);
428
- } },
429
- { name: "--page-size", short: "s", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
430
- _g.pageSize = choice(_a[0], ["A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "C5E", "Comm10E", "DLE", "Executive", "Folio", "Ledger", "Legal", "Letter", "Tabloid"]);
431
- } },
432
- { name: "--grayscale", short: "g", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
433
- _g.colorMode = "grayscale";
434
- } },
435
- { name: "--lowquality", short: "l", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
436
- _g.resolution = "screen";
437
- } },
438
- { name: "--title", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
439
- _g.documentTitle = _a[0];
440
- } },
441
- { name: "--read-args-from-stdin", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
442
- _g.readArgsFromStdin = true;
443
- } },
444
- { name: "--margin-bottom", short: "B", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
445
- _g.marginBottom = length(_a[0]);
446
- } },
447
- { name: "--margin-left", short: "L", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
448
- _g.marginLeft = length(_a[0]);
449
- } },
450
- { name: "--margin-right", short: "R", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
451
- _g.marginRight = length(_a[0]);
452
- } },
453
- { name: "--margin-top", short: "T", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
454
- _g.marginTop = length(_a[0]);
455
- } },
456
- { name: "--dpi", short: "d", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
457
- _g.dpi = integer(_a[0], 1, 2147483647);
458
- } },
459
- { name: "--page-height", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
460
- _g.pageHeight = length(_a[0]);
461
- } },
462
- { name: "--page-width", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
463
- _g.pageWidth = length(_a[0]);
464
- } },
465
- { name: "--cookie-jar", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "resource" },
466
- { name: "--image-quality", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
467
- _g.imageQuality = integer(_a[0], 0, 100);
468
- } },
469
- { name: "--image-dpi", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
470
- _g.imageDPI = integer(_a[0], 1, 2147483647);
471
- } },
472
- { name: "--no-pdf-compression", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
473
- _g.useCompression = false;
474
- } },
475
- { name: "--use-xserver", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "excluded" },
476
- { name: "--outline", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
477
- _g.outline = true;
478
- } },
479
- { name: "--no-outline", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
480
- _g.outline = false;
481
- } },
482
- { name: "--outline-depth", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
483
- _g.outlineDepth = integer(_a[0], 0, 2147483647);
484
- } },
485
- { name: "--dump-outline", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "resource" },
486
- { name: "--dump-default-toc-xsl", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
487
- _g.action = "dump-default-toc-xsl";
488
- } },
489
- { name: "--default-header", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p) => {
490
- _p.header.left = "[webpage]";
491
- _p.header.right = "[page]/[topage]";
492
- _p.header.line = true;
493
- _g.marginTop = { value: 20, unit: "mm" };
494
- } },
495
- { name: "--viewport-size", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
496
- _g.viewportSize = _a[0];
497
- } },
498
- { name: "--enable-plugins", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "excluded" },
499
- { name: "--disable-plugins", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
500
- _p.web.enablePlugins = false;
501
- } },
502
- { name: "--minimum-font-size", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
503
- _p.web.minimumFontSize = integer(_a[0], 1, 2147483647);
504
- } },
505
- { name: "--user-style-sheet", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
506
- { name: "--no-images", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
507
- _p.web.loadImages = false;
508
- } },
509
- { name: "--images", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
510
- _p.web.loadImages = true;
511
- } },
512
- { name: "--disable-javascript", short: "n", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
513
- _p.web.enableJavascript = false;
514
- } },
515
- { name: "--enable-javascript", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
516
- { name: "--encoding", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
517
- _p.web.defaultEncoding = _a[0];
518
- } },
519
- { name: "--no-background", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
520
- _p.web.background = false;
521
- } },
522
- { name: "--background", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
523
- _p.web.background = true;
524
- } },
525
- { name: "--include-in-outline", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
526
- _p.includeInOutline = true;
527
- } },
528
- { name: "--exclude-from-outline", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
529
- _p.includeInOutline = false;
530
- } },
531
- { name: "--disable-smart-shrinking", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
532
- _p.web.enableIntelligentShrinking = false;
533
- } },
534
- { name: "--enable-smart-shrinking", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
535
- _p.web.enableIntelligentShrinking = true;
536
- } },
537
- { name: "--print-media-type", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
538
- _p.load.printMediaType = true;
539
- } },
540
- { name: "--no-print-media-type", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
541
- _p.load.printMediaType = false;
542
- } },
543
- { name: "--enable-forms", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
544
- _p.produceForms = true;
545
- } },
546
- { name: "--disable-forms", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
547
- _p.produceForms = false;
548
- } },
549
- { name: "--disable-internal-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
550
- _p.useLocalLinks = false;
551
- } },
552
- { name: "--enable-internal-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
553
- _p.useLocalLinks = true;
554
- } },
555
- { name: "--disable-external-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
556
- _p.useExternalLinks = false;
557
- } },
558
- { name: "--enable-external-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
559
- _p.useExternalLinks = true;
560
- } },
561
- { name: "--resolve-relative-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
562
- _g.resolveRelativeLinks = true;
563
- } },
564
- { name: "--keep-relative-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
565
- _g.resolveRelativeLinks = false;
566
- } },
567
- { name: "--enable-toc-back-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
568
- _p.toc.backLinks = true;
569
- } },
570
- { name: "--disable-toc-back-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
571
- _p.toc.backLinks = false;
572
- } },
573
- { name: "--proxy", short: "p", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
574
- { name: "--proxy-hostname-lookup", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
575
- { name: "--bypass-proxy-for", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
576
- { name: "--username", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
577
- { name: "--password", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
578
- { name: "--ssl-key-path", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
579
- { name: "--ssl-key-password", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
580
- { name: "--ssl-crt-path", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
581
- { name: "--load-error-handling", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
582
- _p.load.loadErrorHandling = choice(_a[0], ["abort", "skip", "ignore"]);
583
- } },
584
- { name: "--load-media-error-handling", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
585
- _p.load.mediaLoadErrorHandling = choice(_a[0], ["abort", "skip", "ignore"]);
586
- } },
587
- { name: "--custom-header", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
588
- { name: "--custom-header-propagation", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
589
- { name: "--no-custom-header-propagation", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
590
- { name: "--javascript-delay", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "harness" },
591
- { name: "--window-status", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "harness" },
592
- { name: "--zoom", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
593
- _p.load.zoomFactor = float32(_a[0], true);
594
- } },
595
- { name: "--cookie", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
596
- { name: "--post", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
597
- { name: "--post-file", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
598
- { name: "--disable-local-file-access", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
599
- _p.load.blockLocalFileAccess = true;
600
- } },
601
- { name: "--enable-local-file-access", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
602
- { name: "--allow", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
603
- { name: "--cache-dir", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
604
- { name: "--debug-javascript", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
605
- { name: "--no-debug-javascript", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
606
- { name: "--stop-slow-scripts", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
607
- { name: "--no-stop-slow-scripts", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
608
- { name: "--run-script", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "harness" },
609
- { name: "--checkbox-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
610
- { name: "--checkbox-checked-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
611
- { name: "--radiobutton-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
612
- { name: "--radiobutton-checked-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
613
- { name: "--page-offset", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
614
- _g.pageOffset = integer(_a[0], -2147483648, 2147483647);
615
- } },
616
- { name: "--footer-center", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
617
- _p.footer.center = _a[0];
618
- } },
619
- { name: "--footer-font-name", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
620
- _p.footer.fontName = _a[0];
621
- } },
622
- { name: "--footer-font-size", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
623
- _p.footer.fontSize = integer(_a[0], 1, 2147483647);
624
- } },
625
- { name: "--footer-left", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
626
- _p.footer.left = _a[0];
627
- } },
628
- { name: "--footer-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
629
- _p.footer.line = true;
630
- } },
631
- { name: "--no-footer-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
632
- _p.footer.line = false;
633
- } },
634
- { name: "--footer-right", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
635
- _p.footer.right = _a[0];
636
- } },
637
- { name: "--footer-spacing", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
638
- _p.footer.spacing = float32(_a[0], false);
639
- } },
640
- { name: "--footer-html", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "resource" },
641
- { name: "--header-center", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
642
- _p.header.center = _a[0];
643
- } },
644
- { name: "--header-font-name", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
645
- _p.header.fontName = _a[0];
646
- } },
647
- { name: "--header-font-size", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
648
- _p.header.fontSize = integer(_a[0], 1, 2147483647);
649
- } },
650
- { name: "--header-left", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
651
- _p.header.left = _a[0];
652
- } },
653
- { name: "--header-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
654
- _p.header.line = true;
655
- } },
656
- { name: "--no-header-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
657
- _p.header.line = false;
658
- } },
659
- { name: "--header-right", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
660
- _p.header.right = _a[0];
661
- } },
662
- { name: "--header-spacing", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
663
- _p.header.spacing = float32(_a[0], false);
664
- } },
665
- { name: "--header-html", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "resource" },
666
- { name: "--replace", short: "", scope: "page", arity: 2, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
667
- _p.replacements.push([_a[0], _a[1]]);
668
- } },
669
- { name: "--xsl-style-sheet", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "resource" },
670
- { name: "--toc-header-text", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
671
- _p.toc.captionText = _a[0];
672
- } },
673
- { name: "--disable-toc-links", short: "", scope: "toc", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
674
- _p.toc.forwardLinks = false;
675
- } },
676
- { name: "--disable-dotted-lines", short: "", scope: "toc", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
677
- _p.toc.useDottedLines = false;
678
- } },
679
- { name: "--toc-text-size-shrink", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
680
- _p.toc.fontScale = float32(_a[0], true);
681
- } },
682
- { name: "--toc-level-indentation", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
683
- _p.toc.indentation = _a[0];
684
- } }
685
- ];
686
- var switches = Object.freeze(declarations.map((entry) => Object.freeze(entry)));
687
-
688
- // packages/safe-bash-command-wkhtmltopdf/src/parser.ts
689
- var longOptions = new Map(switches.map((entry) => [entry.name, entry]));
690
- var shortOptions = new Map(switches.filter((entry) => entry.short).map((entry) => [entry.short, entry]));
691
- function parseInvocation(argv, options) {
692
- const budget = new ParseBudget(options);
693
- budget.admitArguments(argv.length);
694
- for (const arg of argv) budget.admitText(arg);
695
- budget.step(64);
696
- const global = createGlobalSettings();
697
- const defaults = createPageSettings();
698
- const objects = [];
699
- let index = 0;
700
- let literal = false;
701
- const parseOptions = (settings, scope) => {
702
- if (literal) return;
703
- while (index < (scope === "leading" ? argv.length : argv.length - 1)) {
704
- const token = argv[index];
705
- if (!token.startsWith("-") || token === "-") break;
706
- budget.step();
707
- if (token === "--" && options.endOfOptions) {
708
- index++;
709
- literal = true;
710
- break;
711
- }
712
- if (token === "--" || token.startsWith("--0")) {
713
- throw new WkhtmltopdfError("UNQUALIFIED_QUIRK", "Pinned default-mode sentinel is unqualified and not admitted", token);
714
- }
715
- index++;
716
- const names = token.startsWith("--") ? [token] : token.slice(1);
717
- for (const name of names) {
718
- budget.step();
719
- const entry = token.startsWith("--") ? longOptions.get(name) : shortOptions.get(name);
720
- if (!entry) throw new WkhtmltopdfError("UNKNOWN_OPTION", "Unknown switch", token);
721
- const allowed = entry.scope === "page" || (entry.scope === "global" ? scope === "leading" : scope === "toc");
722
- if (!allowed) throw new WkhtmltopdfError("OPTION_LOCATION", "Switch is in an incorrect object scope", entry.name);
723
- if (entry.arity > argv.length - index) {
724
- throw new WkhtmltopdfError("MISSING_OPERAND", "Switch is missing an operand", entry.name);
725
- }
726
- if (entry.disposition !== "static") {
727
- throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", `Switch requires unavailable ${entry.disposition} capability`, entry.name);
728
- }
729
- budget.step(entry.arity + 1);
730
- const operands = argv.slice(index, index + entry.arity);
731
- index += entry.arity;
732
- try {
733
- entry.apply(global, settings, operands);
734
- } catch (error) {
735
- if (error instanceof WkhtmltopdfError) throw new WkhtmltopdfError(error.code, error.message, entry.name);
736
- throw error;
737
- }
738
- if (global.action) return;
739
- }
740
- }
741
- };
742
- parseOptions(defaults, "leading");
743
- if (global.action) return { mode: "information", global, pageDefaults: defaults, objects, output: null };
744
- if (global.readArgsFromStdin && !options.batchJob) return { mode: "batch", global, pageDefaults: defaults, objects, output: null };
745
- while (index < argv.length - 1) {
746
- budget.admitObject(defaults.replacements.length);
747
- const settings = clonePageSettings(defaults);
748
- let kind = "page";
749
- const token = argv[index++];
750
- let input = token;
751
- if (token === "toc") {
752
- kind = "toc";
753
- input = null;
754
- } else if (token === "cover" || token === "page") {
755
- kind = token;
756
- if (index >= argv.length - 1) {
757
- throw new WkhtmltopdfError("MISSING_OBJECT", "Object requires an input and a final output");
758
- }
759
- input = argv[index++];
760
- }
761
- parseOptions(settings, kind === "toc" ? "toc" : "page");
762
- if (kind === "cover") {
763
- for (const furniture of [settings.header, settings.footer]) {
764
- furniture.left = furniture.right = furniture.center = furniture.htmlUrl = "";
765
- furniture.line = false;
766
- }
767
- settings.includeInOutline = false;
768
- }
769
- objects.push({ kind, input, settings });
770
- }
771
- if (!objects.length || index !== argv.length - 1) {
772
- throw new WkhtmltopdfError("MISSING_OBJECT", "Expected at least one input object and exactly one output");
773
- }
774
- const margins = [global.marginTop, global.marginBottom, global.marginLeft, global.marginRight];
775
- if (margins.some((margin) => margin.unit !== global.marginLeft.unit)) {
776
- throw new WkhtmltopdfError("MARGIN_UNITS", "All margins must use the same normalized unit");
777
- }
778
- return { mode: "conversion", global, pageDefaults: defaults, objects, output: argv[index] };
779
- }
780
- function tokenizeBatchLine(line, options) {
781
- const budget = new ParseBudget(options);
782
- budget.admitText(line);
783
- const tokens = [];
784
- let token = "";
785
- let quote = "";
786
- let escaped = false;
787
- const emit = () => {
788
- if (!token) return;
789
- budget.admitArguments(tokens.length + 1);
790
- tokens.push(token);
791
- token = "";
792
- };
793
- for (const character of line) {
794
- budget.step();
795
- if (escaped) {
796
- token += character;
797
- escaped = false;
798
- } else if (character === "\\") escaped = true;
799
- else if (quote) {
800
- if (character === quote) quote = "";
801
- else token += character;
802
- } else if (character === "'" || character === '"') quote = character;
803
- else if (" \r\n".includes(character)) emit();
804
- else token += character;
805
- }
806
- emit();
807
- return tokens;
808
- }
809
-
810
- // packages/safe-bash-command-wkhtmltopdf/src/resources.ts
811
- init_platform();
812
- var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
813
- var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
814
- var byteLengthGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
815
- var byteTypeGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
816
- var copyBytes = Uint8Array.prototype.set;
817
- async function withResources(options, run) {
818
- const limits = {
819
- maxInputBytes: options.limits?.maxInputBytes ?? Infinity,
820
- maxDecodedBytes: options.limits?.maxDecodedBytes ?? Infinity,
821
- maxRetainedBytes: options.limits?.maxRetainedBytes ?? Infinity,
822
- maxWork: options.limits?.maxWork ?? Infinity,
823
- maxResources: options.limits?.maxResources ?? Infinity
824
- };
825
- for (const key of ["maxInputBytes", "maxDecodedBytes", "maxRetainedBytes", "maxWork", "maxResources"]) {
826
- if (limits[key] !== Infinity && (!Number.isSafeInteger(limits[key]) || limits[key] < 1)) {
827
- throw new WkhtmltopdfError("INVALID_VALUE", "Resource limits must be positive safe integers");
828
- }
829
- }
830
- const { vfs, fonts, network } = options;
831
- const controller = new AbortController();
832
- const signal = controller.signal;
833
- const sourceSignal = options.signal;
834
- const abort = () => controller.abort(sourceSignal.reason);
835
- sourceSignal.addEventListener("abort", abort, { once: true });
836
- if (sourceSignal.aborted) abort();
837
- const usage = { inputBytes: 0, decodedBytes: 0, retainedBytes: 0, work: 0, resources: 0 };
838
- let active = true;
839
- let busy = false;
840
- const pending = /* @__PURE__ */ new Set();
841
- const check = () => {
842
- if (signal.aborted) throw signal.reason;
843
- if (!active) throw new WkhtmltopdfError("INVALID_VALUE", "Resource invocation has ended");
844
- };
845
- const charge = (key, amount, limit) => {
846
- check();
847
- if (amount > limit - usage[key]) throw new WkhtmltopdfError("LIMIT_EXCEEDED", `Resource ${key} limit exceeded`);
848
- usage[key] += amount;
849
- };
850
- const work = (amount = 1) => charge("work", amount, limits.maxWork);
851
- const admitText = (reference) => {
852
- for (let i = 0; i < reference.length; i++) {
853
- work();
854
- const c = reference.charCodeAt(i);
855
- let size = c < 128 ? 1 : c < 2048 ? 2 : 3;
856
- if (c >= 55296 && c <= 56319 && reference.charCodeAt(i + 1) >= 56320 && reference.charCodeAt(i + 1) <= 57343) {
857
- size = 4;
858
- i++;
859
- work();
860
- }
861
- charge("inputBytes", size, limits.maxInputBytes);
862
- if (c === 0) throw new WkhtmltopdfError("INVALID_VALUE", "NUL resource reference");
863
- }
864
- };
865
- const retain = (size) => {
866
- charge("decodedBytes", size, limits.maxDecodedBytes);
867
- charge("retainedBytes", size, limits.maxRetainedBytes);
868
- };
869
- const data = (reference) => {
870
- const comma = reference.indexOf(",");
871
- if (comma < 0) throw new WkhtmltopdfError("INVALID_VALUE", "Data URL requires a comma");
872
- const base64 = reference.slice(5, comma).toLowerCase().endsWith(";base64");
873
- const start = comma + 1;
874
- let size = 0;
875
- const invalid = () => {
876
- throw new WkhtmltopdfError("INVALID_VALUE", "Malformed data URL byte encoding");
877
- };
878
- const hex = (c) => {
879
- const code = c.charCodeAt(0);
880
- if (code >= 48 && code <= 57) return code - 48;
881
- if (code >= 65 && code <= 70) return code - 55;
882
- if (code >= 97 && code <= 102) return code - 87;
883
- return invalid();
884
- };
885
- if (base64) {
886
- const length2 = reference.length - start;
887
- if (length2 % 4 !== 0) invalid();
888
- for (let i = start; i < reference.length; i += 4) {
889
- work(4);
890
- const a = alphabet.indexOf(reference[i]);
891
- const b = alphabet.indexOf(reference[i + 1]);
892
- const c = alphabet.indexOf(reference[i + 2]);
893
- const d = alphabet.indexOf(reference[i + 3]);
894
- if (a < 0 || b < 0) invalid();
895
- if (reference[i + 2] === "=") {
896
- if (reference[i + 3] !== "=" || i + 4 !== reference.length || (b & 15) !== 0) invalid();
897
- size++;
898
- } else if (reference[i + 3] === "=") {
899
- if (c < 0 || i + 4 !== reference.length || (c & 3) !== 0) invalid();
900
- size += 2;
901
- } else {
902
- if (c < 0 || d < 0) invalid();
903
- size += 3;
904
- }
905
- }
906
- } else {
907
- for (let i = start; i < reference.length; i++) {
908
- work();
909
- const code = reference.charCodeAt(i);
910
- if (code > 127 || code <= 32) invalid();
911
- if (reference[i] === "%") {
912
- if (i + 2 >= reference.length) invalid();
913
- hex(reference[i + 1]);
914
- hex(reference[i + 2]);
915
- i += 2;
916
- work(2);
917
- }
918
- size++;
919
- }
920
- }
921
- work(size);
922
- retain(size);
923
- const result = new Uint8Array(size);
924
- let offset = 0;
925
- if (base64) {
926
- for (let i = start; i < reference.length; i += 4) {
927
- const a = alphabet.indexOf(reference[i]);
928
- const b = alphabet.indexOf(reference[i + 1]);
929
- const c = alphabet.indexOf(reference[i + 2]);
930
- const d = alphabet.indexOf(reference[i + 3]);
931
- result[offset++] = a << 2 | b >> 4;
932
- if (c >= 0) result[offset++] = b << 4 | c >> 2;
933
- if (d >= 0) result[offset++] = c << 6 | d;
934
- }
935
- } else {
936
- for (let i = start; i < reference.length; i++) {
937
- result[offset++] = reference[i] === "%" ? hex(reference[++i]) << 4 | hex(reference[++i]) : reference.charCodeAt(i);
938
- }
939
- }
940
- return result;
941
- };
942
- const read = async (reference, open) => {
943
- const lease = await open(reference, signal);
944
- let temporary = 0;
945
- const chunks = [];
946
- let primary = false;
947
- let failure;
948
- let result;
949
- try {
950
- check();
951
- const iterator = lease.chunks[Symbol.asyncIterator]();
952
- for (; ; ) {
953
- work();
954
- let abortRead;
955
- let next;
956
- try {
957
- next = await new Promise((resolve, reject) => {
958
- abortRead = () => reject(signal.reason);
959
- signal.addEventListener("abort", abortRead, { once: true });
960
- if (signal.aborted) abortRead();
961
- Promise.resolve().then(() => {
962
- check();
963
- return iterator.next();
964
- }).then(resolve, reject);
965
- });
966
- } finally {
967
- if (abortRead) signal.removeEventListener("abort", abortRead);
968
- }
969
- check();
970
- if (next.done) break;
971
- if (byteTypeGetter.call(next.value) !== "Uint8Array") {
972
- throw new WkhtmltopdfError("INVALID_VALUE", "Expected resource byte chunks");
973
- }
974
- const size = byteLengthGetter.call(next.value);
975
- charge("inputBytes", size, limits.maxInputBytes);
976
- work(size);
977
- retain(size);
978
- temporary += size;
979
- if (size) {
980
- const chunk = new Uint8Array(size);
981
- copyBytes.call(chunk, next.value);
982
- chunks.push(chunk);
983
- }
984
- }
985
- work(temporary);
986
- charge("retainedBytes", temporary, limits.maxRetainedBytes);
987
- result = new Uint8Array(temporary);
988
- let offset = 0;
989
- for (const chunk of chunks) {
990
- result.set(chunk, offset);
991
- offset += chunk.length;
992
- }
993
- } catch (error) {
994
- primary = true;
995
- failure = error;
996
- } finally {
997
- usage.retainedBytes -= temporary;
998
- try {
999
- await lease.close();
1000
- check();
1001
- } catch (error) {
1002
- if (!primary) {
1003
- primary = true;
1004
- failure = error;
1005
- }
1006
- }
1007
- }
1008
- if (primary) {
1009
- if (result) usage.retainedBytes -= result.byteLength;
1010
- throw failure;
1011
- }
1012
- return result;
1013
- };
1014
- const load = (reference, font, base) => {
1015
- const operation = (async () => {
1016
- check();
1017
- if (busy) throw new WkhtmltopdfError("INVALID_VALUE", "Resource reads must be sequential");
1018
- busy = true;
1019
- try {
1020
- charge("resources", 1, limits.maxResources);
1021
- admitText(reference);
1022
- if (base !== void 0) {
1023
- admitText(base);
1024
- try {
1025
- reference = new URL(reference, base).href;
1026
- } catch {
1027
- throw new WkhtmltopdfError("INVALID_VALUE", "Invalid resource URL or base");
1028
- }
1029
- admitText(reference);
1030
- }
1031
- if (!font) {
1032
- work(reference.length);
1033
- const fragment = reference.indexOf("#");
1034
- if (fragment >= 0) reference = reference.slice(0, fragment);
1035
- }
1036
- if (!font && reference.startsWith("data:")) return data(reference);
1037
- const open = font ? fonts : reference.startsWith("vfs:") ? vfs : reference.startsWith("https:") || reference.startsWith("http:") ? network : void 0;
1038
- if (!open) throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Resource requires an explicitly supplied capability");
1039
- return await read(reference, open);
1040
- } finally {
1041
- busy = false;
1042
- }
1043
- })();
1044
- pending.add(operation);
1045
- void operation.then(() => pending.delete(operation), () => pending.delete(operation));
1046
- return operation;
1047
- };
1048
- try {
1049
- check();
1050
- const result = await run({ load: (reference, base) => load(reference, false, base), font: (name) => load(name, true), get usage() {
1051
- return { ...usage };
1052
- } });
1053
- check();
1054
- if (pending.size) throw new WkhtmltopdfError("INVALID_VALUE", "Resource reads must finish before the invocation ends");
1055
- return result;
1056
- } finally {
1057
- active = false;
1058
- controller.abort(new WkhtmltopdfError("INVALID_VALUE", "Resource invocation has ended"));
1059
- await Promise.allSettled(pending);
1060
- sourceSignal.removeEventListener("abort", abort);
1061
- usage.retainedBytes = 0;
1062
- }
1063
- }
1064
-
1065
- // packages/safe-bash-command-wkhtmltopdf/src/information.ts
1066
- init_platform();
1067
- var defaultToc = `<?xml version="1.0" encoding="UTF-8"?>
1068
- <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1069
- xmlns:outline="http://wkhtmltopdf.org/outline" xmlns="http://www.w3.org/1999/xhtml">
1070
- <xsl:output indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
1071
- doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
1072
- <xsl:template match="outline:outline">
1073
- <html><head><title>Table of Contents</title>
1074
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
1075
- <style>
1076
- h1 { text-align: center; font: 20px arial; }
1077
- div { border-bottom: 1px dashed rgb(200,200,200); }
1078
- span { float: right; }
1079
- li { list-style: none; }
1080
- ul { font: 20px arial; padding-left: 0em; }
1081
- ul ul { font-size: 80%; padding-left: 1em; }
1082
- a { text-decoration: none; color: black; }
1083
- </style>
1084
- </head><body><h1>Table of Contents</h1>
1085
- <ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
1086
- </body></html>
1087
- </xsl:template>
1088
- <xsl:template match="outline:item">
1089
- <li>
1090
- <xsl:if test="@title!=''">
1091
- <div><a>
1092
- <xsl:if test="@link"><xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute></xsl:if>
1093
- <xsl:if test="@backLink"><xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute></xsl:if>
1094
- <xsl:value-of select="@title"/>
1095
- </a><span> <xsl:value-of select="@page"/> </span></div>
1096
- </xsl:if>
1097
- <ul><xsl:comment>Keep an explicit closing tag for QtXmlPatterns</xsl:comment>
1098
- <xsl:apply-templates select="outline:item"/>
1099
- </ul>
1100
- </li>
1101
- </xsl:template>
1102
- </xsl:stylesheet>
1103
- `;
1104
- var license = `MIT License
1105
-
1106
- Copyright (c) 2026 Poe Platform
1107
-
1108
- Permission is hereby granted, free of charge, to any person obtaining a copy
1109
- of this software and associated documentation files (the "Software"), to deal
1110
- in the Software without restriction, including without limitation the rights
1111
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1112
- copies of the Software, and to permit persons to whom the Software is
1113
- furnished to do so, subject to the following conditions:
1114
-
1115
- The above copyright notice and this permission notice shall be included in all
1116
- copies or substantial portions of the Software.
1117
-
1118
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1119
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1120
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1121
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1122
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1123
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1124
- SOFTWARE.
1125
- `;
1126
- function informationText(action) {
1127
- if (action === "dump-default-toc-xsl") return defaultToc;
1128
- if (action === "license") return license;
1129
- if (action === "version") return "wkhtmltopdf safe static adapter (source 024b2b2bb459dd904d15b911d04c6df4ff2c9031; Qt compatibility unqualified)\n";
1130
- const usage = "Usage: wkhtmltopdf [options] [page|cover input|toc]... output\nBuilt-in PDF AST static renderer; trusted overrides are optional. Input/output '-' use stdin/stdout.\n";
1131
- if (action === "help" || action === "extended-help") return usage;
1132
- const description = "wkhtmltopdf safe static adapter\n\n" + usage + "\nThe built-in PDF AST renderer converts static HTML by default; a trusted first-party renderer may override it.\nTOC stylesheet export does not enable TOC conversion. Qt/WebKit compatibility is unqualified.\nPaths use only the configured virtual filesystem. No native executable, ambient files or implicit network are used.\nInformation exports require no renderer and write UTF-8 to stdout. --license describes this adapter's MIT license.\n\nOptions (static means parser admission; rendering still requires a qualified binding):\n" + switches.map((option) => option.name + (option.short ? ", -" + option.short : "") + " <arg>".repeat(option.arity) + " [" + option.scope + "; " + option.disposition + "]").join("\n") + "\n";
1133
- if (action === "readme") return description;
1134
- if (action === "manpage") return ".TH WKHTMLTOPDF 1\n.SH NAME\nwkhtmltopdf \\- safe static adapter\n.SH DESCRIPTION\n.nf\n" + description + ".fi\n";
1135
- if (action === "htmldoc") {
1136
- const escaped = description.split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;");
1137
- return '<!DOCTYPE html>\n<html lang="en"><head><meta charset="utf-8"><title>wkhtmltopdf safe static adapter</title></head><body><pre>' + escaped + "</pre></body></html>\n";
1138
- }
1139
- throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Unknown information action", action);
1140
- }
1141
-
1142
- // packages/safe-bash-command-wkhtmltopdf/src/command.ts
1143
- var wkhtmltopdfLimits = Object.freeze({
1144
- parse: Object.freeze({ maxArguments: Infinity, maxTextBytes: Infinity, maxObjects: Infinity, maxWork: Infinity }),
1145
- resources: Object.freeze({ maxInputBytes: Infinity, maxDecodedBytes: Infinity, maxRetainedBytes: Infinity, maxWork: Infinity, maxResources: Infinity }),
1146
- maxOutputBytes: Infinity,
1147
- maxOutputChunks: Infinity,
1148
- maxBatchJobs: Infinity
1149
- });
1150
- var encoder = new TextEncoder();
1151
- var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
1152
- var typedArrayPrototype2 = Object.getPrototypeOf(Uint8Array.prototype);
1153
- var byteType = Object.getOwnPropertyDescriptor(typedArrayPrototype2, Symbol.toStringTag).get;
1154
- var byteLength = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "byteLength").get;
1155
- async function runWkhtmltopdf(context, options = {}) {
1156
- context.signal.throwIfAborted();
1157
- const controller = new AbortController();
1158
- const signal = controller.signal;
1159
- let opening;
1160
- let closing;
1161
- let cleanupPromise;
1162
- let resourceRun;
1163
- let stdout;
1164
- let stderr;
1165
- const retire = () => {
1166
- if (!opening) return Promise.resolve();
1167
- closing ??= opening.then((document) => document.close(), () => {
1168
- });
1169
- return closing;
1170
- };
1171
- const onAbort = () => controller.abort(context.signal.reason);
1172
- const cleanup = () => {
1173
- cleanupPromise ??= (async () => {
1174
- controller.abort(new WkhtmltopdfError("INVALID_VALUE", "Invocation has ended"));
1175
- context.signal.removeEventListener("abort", onAbort);
1176
- const drained = await Promise.allSettled([
1177
- retire(),
1178
- resourceRun?.then(() => {
1179
- }, () => {
1180
- }),
1181
- stdout?.close(),
1182
- stderr?.close()
1183
- ]);
1184
- const failures = drained.filter((value) => value.status === "rejected").map((value) => value.reason);
1185
- if (failures.length) throw new AggregateError(failures, "Invocation cleanup failed");
1186
- })();
1187
- return cleanupPromise;
1188
- };
1189
- context.registerCleanup?.(cleanup);
1190
- let primary = false;
1191
- let failure;
1192
- let result;
1193
- try {
1194
- context.signal.addEventListener("abort", onAbort, { once: true });
1195
- if (context.signal.aborted) onAbort();
1196
- signal.throwIfAborted();
1197
- stdout = createOutputOperation({ signal, registerCleanup: (callback) => context.registerCleanup?.(callback) }, context.stdout);
1198
- stderr = createOutputOperation({ signal, registerCleanup: (callback) => context.registerCleanup?.(callback) }, context.stderr);
1199
- if (options.limits !== void 0 && (typeof options.limits !== "object" || options.limits === null)) {
1200
- throw new WkhtmltopdfError("INVALID_VALUE", "Command limits must be positive safe integers");
1201
- }
1202
- if (options.limits?.parse !== void 0 && (typeof options.limits.parse !== "object" || options.limits.parse === null)) {
1203
- throw new WkhtmltopdfError("INVALID_VALUE", "Parser limits must be positive safe integers");
1204
- }
1205
- if (options.limits?.resources !== void 0 && (typeof options.limits.resources !== "object" || options.limits.resources === null)) {
1206
- throw new WkhtmltopdfError("INVALID_VALUE", "Resource limits must be positive safe integers");
1207
- }
1208
- const limits = Object.freeze({
1209
- ...wkhtmltopdfLimits,
1210
- ...options.limits,
1211
- parse: Object.freeze({ ...wkhtmltopdfLimits.parse, ...options.limits?.parse }),
1212
- resources: Object.freeze({ ...wkhtmltopdfLimits.resources, ...options.limits?.resources })
1213
- });
1214
- for (const value of [limits.maxOutputBytes, limits.maxOutputChunks, limits.maxBatchJobs]) {
1215
- if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) throw new WkhtmltopdfError("INVALID_VALUE", "Command limits must be positive safe integers");
1216
- }
1217
- for (const key of ["maxInputBytes", "maxDecodedBytes", "maxRetainedBytes", "maxWork", "maxResources"]) {
1218
- if (limits.resources[key] !== Infinity && (!Number.isSafeInteger(limits.resources[key]) || limits.resources[key] < 1)) {
1219
- throw new WkhtmltopdfError("INVALID_VALUE", "Resource limits must be positive safe integers");
1220
- }
1221
- }
1222
- const admission = new ParseBudget({ limits: limits.parse, signal });
1223
- admission.admitArguments(context.args.length);
1224
- for (const arg of context.args) admission.admitText(arg);
1225
- const carrier = context.argumentValues === void 0 ? void 0 : getCommandArguments(context);
1226
- const argv = [];
1227
- let argumentBytes = 0;
1228
- for (let index = 0; index < context.args.length; index++) {
1229
- signal.throwIfAborted();
1230
- if (carrier === void 0 || typeof carrier.values[index] === "string") {
1231
- argv.push(context.args[index]);
1232
- continue;
1233
- }
1234
- const bytes = carrier.bytes(index);
1235
- if (bytes.byteLength > limits.parse.maxTextBytes - argumentBytes) throw new WkhtmltopdfError("LIMIT_EXCEEDED", "CLI argument byte limit exceeded");
1236
- argumentBytes += bytes.byteLength;
1237
- try {
1238
- argv.push(decoder.decode(bytes));
1239
- } catch {
1240
- throw new WkhtmltopdfError("INVALID_VALUE", "CLI arguments must be valid UTF-8");
1241
- }
1242
- }
1243
- const parse = (args, batchJob = false) => parseInvocation(args, { limits: limits.parse, signal, endOfOptions: true, batchJob });
1244
- const initial = parse(argv);
1245
- if (initial.mode === "information") {
1246
- const text = informationText(initial.global.action);
1247
- if (shellValueByteLength(text) > limits.maxOutputBytes) {
1248
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Information output byte limit exceeded");
1249
- }
1250
- await writeBytes(stdout.output, encoder.encode(text), signal);
1251
- result = { kind: "information", exitCode: 0 };
1252
- } else {
1253
- const renderer = options.renderer ?? (await import("./pdf-renderer-CMF3CSVU.js")).pdfAstRenderer;
1254
- requireRendererFeatures(renderer.profile, []);
1255
- let outputBytes = 0;
1256
- let outputChunks = 0;
1257
- let jobs = 0;
1258
- let inputBytes = 0;
1259
- let currentInputs = [];
1260
- let produced;
1261
- resourceRun = Promise.resolve().then(() => withResources({
1262
- limits: limits.resources,
1263
- signal,
1264
- vfs: async (reference, readSignal) => {
1265
- if (reference === "vfs:output") {
1266
- if (!produced) throw new WkhtmltopdfError("INVALID_VALUE", "No renderer output is active");
1267
- const document = produced;
1268
- return {
1269
- chunks: (async function* () {
1270
- for await (const chunk of document.chunks) {
1271
- readSignal.throwIfAborted();
1272
- if (byteType.call(chunk) !== "Uint8Array") throw new WkhtmltopdfError("INVALID_VALUE", "Renderer must produce byte chunks");
1273
- const length2 = byteLength.call(chunk);
1274
- if (++outputChunks > limits.maxOutputChunks || length2 > limits.maxOutputBytes - outputBytes) {
1275
- throw new WkhtmltopdfError("LIMIT_EXCEEDED", "PDF output stage limit exceeded");
1276
- }
1277
- outputBytes += length2;
1278
- yield chunk;
1279
- }
1280
- })(),
1281
- close: retire
1282
- };
1283
- }
1284
- const index = Number(reference.slice("vfs:input/".length));
1285
- const input = currentInputs[index];
1286
- if (input === void 0) throw new WkhtmltopdfError("INVALID_VALUE", "Unknown invocation input identity");
1287
- if (input === "-") return {
1288
- chunks: (async function* () {
1289
- for await (const chunk of readBytes(context.stdin, readSignal)) {
1290
- inputBytes += byteLength.call(chunk);
1291
- context.inputBudget?.check(inputBytes);
1292
- yield chunk;
1293
- }
1294
- })(),
1295
- async close() {
1296
- }
1297
- };
1298
- if (!context.fs.openReadFile) throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "VFS requires bounded read handles");
1299
- const handle = await context.fs.openReadFile(resolvePath(context.cwd, input), { signal: readSignal });
1300
- let position = 0;
1301
- return {
1302
- chunks: (async function* () {
1303
- for (; ; ) {
1304
- readSignal.throwIfAborted();
1305
- const chunk = await handle.read(position, Math.min(65536, limits.resources.maxInputBytes, limits.resources.maxDecodedBytes, limits.resources.maxRetainedBytes, Math.max(1, context.inputBudget?.maxBytes ?? limits.resources.maxInputBytes)), { signal: readSignal });
1306
- if (byteType.call(chunk) !== "Uint8Array") throw new WkhtmltopdfError("INVALID_VALUE", "VFS must produce byte chunks");
1307
- const length2 = byteLength.call(chunk);
1308
- if (!length2) return;
1309
- inputBytes += length2;
1310
- context.inputBudget?.check(inputBytes);
1311
- position += length2;
1312
- yield chunk;
1313
- }
1314
- })(),
1315
- close: () => handle.close()
1316
- };
1317
- }
1318
- }, async (resources) => {
1319
- const convert = async (job, batch) => {
1320
- if (++jobs > limits.maxBatchJobs) throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Batch job limit exceeded");
1321
- currentInputs = job.objects.map((object) => {
1322
- if (object.input === null) throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "TOC requires a qualified outline/XSLT engine");
1323
- if (batch && object.input === "-") throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Batch conversion cannot share stdin with HTML input");
1324
- return object.input;
1325
- });
1326
- let destination;
1327
- if (job.output !== "-") {
1328
- if (!context.fs.writeFileConditional) {
1329
- throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "VFS requires conditional file publication");
1330
- }
1331
- const requested = resolvePath(context.cwd, job.output);
1332
- const parentPath = await context.fs.realpath(dirname(requested), { signal });
1333
- const path = resolvePath(parentPath, basename(requested));
1334
- const parent = await context.fs.stat(parentPath, { signal });
1335
- let expected = null;
1336
- try {
1337
- expected = await context.fs.lstat(path, { signal });
1338
- } catch (error) {
1339
- if (!(error instanceof FsError && error.code === "ENOENT")) throw error;
1340
- }
1341
- if (expected !== null && expected.type !== "file") {
1342
- throw new WkhtmltopdfError("INVALID_VALUE", "Output must be a regular VFS file or absent");
1343
- }
1344
- for (let index = 0; index < currentInputs.length; index++) {
1345
- const input = currentInputs[index];
1346
- if (input === "-") continue;
1347
- const source = await context.fs.realpath(resolvePath(context.cwd, input), { signal });
1348
- currentInputs[index] = source;
1349
- if (source === path || expected !== null && await compareEntries(context.fs, source, context.fs, path, { signal }) !== "distinct") {
1350
- throw new WkhtmltopdfError("INVALID_VALUE", "Input and output VFS identities must be distinct");
1351
- }
1352
- }
1353
- destination = { path, condition: { parent, expected, signal } };
1354
- }
1355
- const inputs = [];
1356
- for (let index = 0; index < currentInputs.length; index++) inputs.push(await resources.load("vfs:input/" + index));
1357
- signal.throwIfAborted();
1358
- opening = Promise.resolve().then(() => {
1359
- signal.throwIfAborted();
1360
- return renderer.open({ job, inputs, signal, limits });
1361
- });
1362
- closing = void 0;
1363
- const document = await opening;
1364
- produced = document;
1365
- signal.throwIfAborted();
1366
- const outcome2 = conversionOutcome({
1367
- mode: batch ? "batch" : "single",
1368
- success: document.success,
1369
- errorCode: document.errorCode,
1370
- ...document.networkErrorName === void 0 ? {} : { networkErrorName: document.networkErrorName }
1371
- });
1372
- let pdf;
1373
- if (outcome2.exitCode === 0) {
1374
- pdf = await resources.load("vfs:output");
1375
- }
1376
- await retire();
1377
- opening = void 0;
1378
- closing = void 0;
1379
- produced = void 0;
1380
- signal.throwIfAborted();
1381
- if (outcome2.exitCode === 0) {
1382
- if (job.output === "-") await writeBytes(stdout.output, pdf, signal);
1383
- else await context.fs.writeFileConditional(destination.path, pdf, destination.condition);
1384
- } else await diagnostic({ ...context, stderr: stderr.output }, outcome2, signal);
1385
- return outcome2;
1386
- };
1387
- let outcome = { exitCode: 0, diagnostic: null };
1388
- if (initial.mode === "batch") {
1389
- currentInputs = ["-"];
1390
- const bytes = await resources.load("vfs:input/0");
1391
- let text;
1392
- try {
1393
- text = decoder.decode(bytes);
1394
- } catch {
1395
- throw new WkhtmltopdfError("INVALID_VALUE", "Batch input must be valid UTF-8");
1396
- }
1397
- let start = 0;
1398
- for (let end = 0; end <= text.length; end++) {
1399
- signal.throwIfAborted();
1400
- if (end !== text.length && text[end] !== "\n") continue;
1401
- if (end === text.length && start === end) break;
1402
- const args = tokenizeBatchLine(text.slice(start, end), { limits: limits.parse, signal });
1403
- const job = parse([...argv, ...args], true);
1404
- if (job.mode !== "conversion") throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Batch lines must describe conversion jobs");
1405
- outcome = await convert(job, true);
1406
- if (outcome.exitCode !== 0) break;
1407
- start = end + 1;
1408
- }
1409
- } else outcome = await convert(initial, false);
1410
- return { kind: "conversion", exitCode: outcome.exitCode, jobs, outcome, usage: resources.usage };
1411
- }));
1412
- result = await resourceRun;
1413
- }
1414
- } catch (error) {
1415
- if (context.signal.aborted) {
1416
- primary = true;
1417
- failure = context.signal.reason;
1418
- } else if (signal.aborted) {
1419
- primary = true;
1420
- failure = signal.reason;
1421
- } else if (error instanceof WkhtmltopdfError || error instanceof FsError) {
1422
- try {
1423
- const option = error instanceof WkhtmltopdfError ? error.option : void 0;
1424
- await writeBytes(stderr.output, encoder.encode(`wkhtmltopdf: ${error.code}${option ? ` (${option})` : ""}: ${error.message}
1425
- `), signal);
1426
- result = { kind: "rejected", exitCode: 1, code: error.code };
1427
- } catch (writeError) {
1428
- primary = true;
1429
- failure = writeError;
1430
- }
1431
- } else {
1432
- primary = true;
1433
- failure = error;
1434
- }
1435
- } finally {
1436
- try {
1437
- await cleanup();
1438
- } catch (error) {
1439
- if (primary) failure = new AggregateError([failure, error], "Invocation and cleanup failed");
1440
- else {
1441
- primary = true;
1442
- failure = error;
1443
- }
1444
- }
1445
- }
1446
- if (primary) throw failure;
1447
- return result;
1448
- }
1449
- async function diagnostic(context, outcome, signal) {
1450
- const value = outcome.diagnostic;
1451
- if (!value) return;
1452
- const message = value.kind === "http" ? `Exit with code ${outcome.exitCode} due to http error: ${value.code} ${value.description}` : value.kind === "network" ? `Exit with code 1 due to network error: ${value.name ?? "UnqualifiedNetworkError"}` : "Exit with code 1, due to unknown error.";
1453
- await writeBytes(context.stderr, encoder.encode(message + "\n"), signal);
1454
- }
1455
- function createWkhtmltopdfCommand(options = { limits: wkhtmltopdfLimits }) {
1456
- return Object.freeze({
1457
- name: "wkhtmltopdf",
1458
- runtimeIdentity: commandRuntimeIdentity,
1459
- description: "Bounded static HTML-to-PDF adapter with a built-in PDF AST renderer",
1460
- execute: (context) => runWkhtmltopdf(context, options)
1461
- });
1462
- }
1463
- var wkhtmltopdfCommand = createWkhtmltopdfCommand();
1464
- function wkhtmltopdfCommands(options = {}) {
1465
- const commands = createWkhtmltopdfCommands(options);
1466
- const replace = options.replace ?? false;
1467
- return {
1468
- name: "wkhtmltopdf-commands",
1469
- setup(host) {
1470
- for (const command of commands) host.commands.register(command, { replace });
1471
- }
1472
- };
1473
- }
1474
- function createWkhtmltopdfCommands(options = {}) {
1475
- return Object.freeze([createWkhtmltopdfCommand(options)]);
1476
- }
1477
-
1478
- // packages/safe-bash-command-wkhtmltopdf/src/pdf-renderer.ts
1479
- var pdfAstRendererProfile = Object.freeze({
1480
- id: "pdf-ast-static",
1481
- features: Object.freeze([
1482
- "html5",
1483
- "computed-css",
1484
- "selectors",
1485
- "css-units",
1486
- "block-inline",
1487
- "font-shaping",
1488
- "lists",
1489
- "images",
1490
- "table-spans",
1491
- "pagination",
1492
- "break-rules",
1493
- "widows-orphans",
1494
- "positioning",
1495
- "page-furniture",
1496
- "flex",
1497
- "grid"
1498
- ])
1499
- });
1500
- var PAGE_SIZES_PT = {
1501
- A3: [841.89, 1190.55],
1502
- A4: [595.28, 841.89],
1503
- A5: [419.53, 595.28],
1504
- B4: [708.66, 1000.63],
1505
- B5: [498.9, 708.66],
1506
- Letter: [612, 792],
1507
- Legal: [612, 1008],
1508
- Executive: [522, 756],
1509
- Tabloid: [792, 1224],
1510
- Ledger: [792, 1224]
1511
- };
1512
- function decodeBase64(b64) {
1513
- const clean = b64.replace(/[^A-Za-z0-9+/=]/g, "");
1514
- const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1515
- const out = [];
1516
- for (let i = 0; i < clean.length; i += 4) {
1517
- const c0 = alphabet2.indexOf(clean[i] ?? "A");
1518
- const c1 = alphabet2.indexOf(clean[i + 1] ?? "A");
1519
- const c2 = clean[i + 2] === "=" ? -1 : alphabet2.indexOf(clean[i + 2] ?? "A");
1520
- const c3 = clean[i + 3] === "=" ? -1 : alphabet2.indexOf(clean[i + 3] ?? "A");
1521
- const triple = Math.max(0, c0) << 18 | Math.max(0, c1) << 12 | Math.max(0, c2) << 6 | Math.max(0, c3);
1522
- out.push(triple >> 16 & 255);
1523
- if (c2 !== -1) out.push(triple >> 8 & 255);
1524
- if (c3 !== -1) out.push(triple & 255);
1525
- }
1526
- return new Uint8Array(out);
1527
- }
1528
- function lengthToPoints(length2, dpi, fallbackPt) {
1529
- if (!Number.isFinite(length2.value) || length2.value < 0) return fallbackPt;
1530
- switch (length2.unit) {
1531
- case "pt":
1532
- return length2.value;
1533
- case "in":
1534
- return length2.value * 72;
1535
- case "mm":
1536
- return length2.value * (72 / 25.4);
1537
- case "px":
1538
- return length2.value * (72 / Math.max(1, dpi || 96));
1539
- case "pc":
1540
- return length2.value * 12;
1541
- case "didot":
1542
- return length2.value * 1.07;
1543
- case "cicero":
1544
- return length2.value * 12.84;
1545
- default:
1546
- return fallbackPt;
1547
- }
1548
- }
1549
- function resolvePageBox(global) {
1550
- const base = PAGE_SIZES_PT[global.pageSize] ?? PAGE_SIZES_PT.A4;
1551
- let width = global.pageWidth.value > 0 ? lengthToPoints(global.pageWidth, global.dpi, base[0]) : base[0];
1552
- let height = global.pageHeight.value > 0 ? lengthToPoints(global.pageHeight, global.dpi, base[1]) : base[1];
1553
- if (global.orientation === "Landscape") {
1554
- const tmp = width;
1555
- width = height;
1556
- height = tmp;
1557
- }
1558
- const marginTop = lengthToPoints(global.marginTop, global.dpi, 36);
1559
- const marginBottom = lengthToPoints(global.marginBottom, global.dpi, 36);
1560
- const marginLeft = lengthToPoints(global.marginLeft, global.dpi, 28.35);
1561
- const marginRight = lengthToPoints(global.marginRight, global.dpi, 28.35);
1562
- return { width, height, marginTop, marginBottom, marginLeft, marginRight };
1563
- }
1564
- function decodeHtmlEntities(input) {
1565
- return input.replace(/&(nbsp|amp|lt|gt|quot|apos|#39|#x([0-9a-f]+)|#([0-9]+));/gi, (full, entity, hex, dec) => {
1566
- if (hex !== void 0) {
1567
- const cp = parseInt(hex, 16);
1568
- return Number.isFinite(cp) && cp >= 0 && cp <= 1114111 ? String.fromCodePoint(cp) : "\uFFFD";
1569
- }
1570
- if (dec !== void 0) {
1571
- const cp = parseInt(dec, 10);
1572
- return Number.isFinite(cp) && cp >= 0 && cp <= 1114111 ? String.fromCodePoint(cp) : "\uFFFD";
1573
- }
1574
- switch (entity.toLowerCase()) {
1575
- case "nbsp":
1576
- return " ";
1577
- case "amp":
1578
- return "&";
1579
- case "lt":
1580
- return "<";
1581
- case "gt":
1582
- return ">";
1583
- case "quot":
1584
- return '"';
1585
- case "apos":
1586
- case "#39":
1587
- return "'";
1588
- default:
1589
- return full;
1590
- }
1591
- });
1592
- }
1593
- function stripTags(html) {
1594
- return decodeHtmlEntities(
1595
- html.replace(/<br\s*\/?>/gi, "\n").replace(/<[^>]+>/g, " ").replace(/[ \t]+/g, " ")
1596
- ).trim();
1597
- }
1598
- function extractLinks(html) {
1599
- const links = [];
1600
- const linkRegex = /<a\b[^>]*href=(?:"([^"]*)"|'([^']*)'|([^\s>]+))[^>]*>([\s\S]*?)<\/a>/gi;
1601
- let match;
1602
- while ((match = linkRegex.exec(html)) !== null) {
1603
- const href = decodeHtmlEntities(match[1] ?? match[2] ?? match[3] ?? "").trim();
1604
- const text = stripTags(match[4] ?? "");
1605
- if (href && text) {
1606
- links.push({ text, href });
1607
- }
1608
- }
1609
- return links;
1610
- }
1611
- function parseHtmlDocumentSync(rawHtml, replacements, signal) {
1612
- let html = rawHtml;
1613
- for (const [key, value] of replacements) {
1614
- if (key) html = html.split(key).join(value);
1615
- }
1616
- const titleMatch = /<title[^>]*>([\s\S]*?)<\/title>/i.exec(html);
1617
- const title = titleMatch ? stripTags(titleMatch[1] ?? "") : "";
1618
- const bodyHtml = html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<head\b[^>]*>[\s\S]*?<\/head>/gi, "");
1619
- const blocks = [];
1620
- const tokenRegex = /<(h[1-6]|p|pre|ul|ol|dl|table|svg|hr|img|blockquote|div|section|article)\b([^>]*)>([\s\S]*?)<\/\1>|<(hr|img)\b([^>]*?)\/?>/gi;
1621
- let lastIndex = 0;
1622
- let match;
1623
- let work = 0;
1624
- while ((match = tokenRegex.exec(bodyHtml)) !== null) {
1625
- signal.throwIfAborted();
1626
- if (++work % 64 === 0) signal.throwIfAborted();
1627
- const leadingText = stripTags(bodyHtml.slice(lastIndex, match.index));
1628
- if (leadingText) {
1629
- blocks.push({ kind: "paragraph", text: leadingText, links: extractLinks(bodyHtml.slice(lastIndex, match.index)) });
1630
- }
1631
- lastIndex = tokenRegex.lastIndex;
1632
- const tag = (match[1] ?? match[4] ?? "").toLowerCase();
1633
- const attrs = match[2] ?? match[5] ?? "";
1634
- const inner = match[3] ?? "";
1635
- if (/page-break-before\s*:\s*always/i.test(attrs) || /class=["'][^"']*page-break/i.test(attrs)) {
1636
- blocks.push({ kind: "pagebreak" });
1637
- }
1638
- if (tag === "hr") {
1639
- blocks.push({ kind: "hr" });
1640
- } else if (tag === "img") {
1641
- const srcMatch = /src=(?:"([^"]*)"|'([^']*)')/i.exec(attrs);
1642
- const src = srcMatch ? srcMatch[1] ?? srcMatch[2] ?? "" : "";
1643
- if (src.startsWith("data:image/png;base64,")) {
1644
- try {
1645
- const b64 = src.slice("data:image/png;base64,".length).trim();
1646
- const pngBytes = decodeBase64(b64);
1647
- const bitmap = decodePng(pngBytes);
1648
- const widthAttr = /width=["']?(\d+)/i.exec(attrs);
1649
- const heightAttr = /height=["']?(\d+)/i.exec(attrs);
1650
- blocks.push({
1651
- kind: "image",
1652
- pngBytes,
1653
- displayWidth: widthAttr ? Number(widthAttr[1]) : Math.min(240, bitmap.width),
1654
- displayHeight: heightAttr ? Number(heightAttr[1]) : Math.min(180, bitmap.height)
1655
- });
1656
- } catch {
1657
- }
1658
- }
1659
- } else if (/^h[1-6]$/.test(tag)) {
1660
- const level = Number(tag[1]);
1661
- const text = stripTags(inner);
1662
- if (text) {
1663
- blocks.push({ kind: "heading", level, text, links: extractLinks(inner) });
1664
- }
1665
- } else if (tag === "pre") {
1666
- const codeText = decodeHtmlEntities(inner.replace(/<[^>]+>/g, "")).replace(/\r\n/g, "\n").trim();
1667
- if (codeText) {
1668
- blocks.push({ kind: "code", text: codeText });
1669
- }
1670
- } else if (tag === "ul" || tag === "ol") {
1671
- const items = [];
1672
- const liRegex = /<li\b[^>]*>([\s\S]*?)<\/li>/gi;
1673
- let liMatch;
1674
- while ((liMatch = liRegex.exec(inner)) !== null) {
1675
- const itemText = stripTags(liMatch[1] ?? "");
1676
- if (itemText) items.push(itemText);
1677
- }
1678
- if (items.length > 0) {
1679
- blocks.push({ kind: "list", ordered: tag === "ol", items });
1680
- }
1681
- } else if (tag === "dl") {
1682
- const items = [];
1683
- const dtDdRegex = /<(dt|dd)\b[^>]*>([\s\S]*?)<\/\1>/gi;
1684
- let m;
1685
- let currentTerm = "";
1686
- while ((m = dtDdRegex.exec(inner)) !== null) {
1687
- const t = m[1].toLowerCase();
1688
- const txt = stripTags(m[2] ?? "");
1689
- if (t === "dt") {
1690
- currentTerm = txt;
1691
- } else if (t === "dd") {
1692
- items.push(currentTerm ? `${currentTerm}: ${txt}` : txt);
1693
- currentTerm = "";
1694
- }
1695
- }
1696
- if (items.length > 0) {
1697
- blocks.push({ kind: "list", ordered: false, items });
1698
- }
1699
- } else if (tag === "svg") {
1700
- const wMatch = /width=["']?(\d+)/i.exec(attrs);
1701
- const hMatch = /height=["']?(\d+)/i.exec(attrs);
1702
- const displayWidth = wMatch ? Number(wMatch[1]) : 200;
1703
- const displayHeight = hMatch ? Number(hMatch[1]) : 100;
1704
- const svgPrimitives = [];
1705
- const rectRe = /<rect\b([^>]*)\/?>/gi;
1706
- let rm;
1707
- while ((rm = rectRe.exec(inner)) !== null) {
1708
- const ra = rm[1] ?? "";
1709
- const rx = Number(/\bx=["']?([\d.]+)/i.exec(ra)?.[1] ?? 0);
1710
- const ry = Number(/\by=["']?([\d.]+)/i.exec(ra)?.[1] ?? 0);
1711
- const rw = Number(/\bwidth=["']?([\d.]+)/i.exec(ra)?.[1] ?? 40);
1712
- const rh = Number(/\bheight=["']?([\d.]+)/i.exec(ra)?.[1] ?? 20);
1713
- svgPrimitives.push({ kind: "rect", x: rx, y: ry, w: rw, h: rh });
1714
- }
1715
- const textRe = /<text\b([^>]*)>([\s\S]*?)<\/text>/gi;
1716
- let tm;
1717
- while ((tm = textRe.exec(inner)) !== null) {
1718
- const ta = tm[1] ?? "";
1719
- const tx = Number(/\bx=["']?([\d.]+)/i.exec(ta)?.[1] ?? 8);
1720
- const ty = Number(/\by=["']?([\d.]+)/i.exec(ta)?.[1] ?? 16);
1721
- const txt = stripTags(tm[2] ?? "");
1722
- if (txt) svgPrimitives.push({ kind: "text", x: tx, y: ty, text: txt });
1723
- }
1724
- blocks.push({ kind: "svg", displayWidth, displayHeight, svgPrimitives });
1725
- } else if (tag === "blockquote") {
1726
- const text = stripTags(inner);
1727
- if (text) {
1728
- blocks.push({ kind: "blockquote", text, links: extractLinks(inner) });
1729
- }
1730
- } else if (tag === "table") {
1731
- const rows = [];
1732
- const trRegex = /<tr\b[^>]*>([\s\S]*?)<\/tr>/gi;
1733
- let trMatch;
1734
- while ((trMatch = trRegex.exec(inner)) !== null) {
1735
- const rowHtml = trMatch[1] ?? "";
1736
- const cells = [];
1737
- let header = false;
1738
- const cellRegex = /<(th|td)\b([^>]*)>([\s\S]*?)<\/\1>/gi;
1739
- let cellMatch;
1740
- while ((cellMatch = cellRegex.exec(rowHtml)) !== null) {
1741
- if (cellMatch[1]?.toLowerCase() === "th") header = true;
1742
- const cellAttrs = cellMatch[2] ?? "";
1743
- const colspanMatch = /colspan=["']?(\d+)/i.exec(cellAttrs);
1744
- const colspan = Math.max(1, colspanMatch ? Number(colspanMatch[1]) : 1);
1745
- cells.push({ text: stripTags(cellMatch[3] ?? ""), colspan });
1746
- }
1747
- if (cells.length > 0) {
1748
- rows.push({ cells, header });
1749
- }
1750
- }
1751
- if (rows.length > 0) {
1752
- blocks.push({ kind: "table", rows });
1753
- }
1754
- } else {
1755
- if (/<(h[1-6]|p|pre|ul|ol|dl|table|svg|hr|img|blockquote|div|section|article)\b/i.test(inner)) {
1756
- const nested = parseHtmlDocumentSync(inner, [], signal);
1757
- blocks.push(...nested.blocks);
1758
- } else {
1759
- const text = stripTags(inner);
1760
- if (text) {
1761
- blocks.push({ kind: "paragraph", text, links: extractLinks(inner) });
1762
- }
1763
- }
1764
- }
1765
- if (/page-break-after\s*:\s*always/i.test(attrs)) {
1766
- blocks.push({ kind: "pagebreak" });
1767
- }
1768
- }
1769
- const trailingText = stripTags(bodyHtml.slice(lastIndex));
1770
- if (trailingText) {
1771
- blocks.push({ kind: "paragraph", text: trailingText, links: extractLinks(bodyHtml.slice(lastIndex)) });
1772
- }
1773
- if (blocks.length === 0) {
1774
- const fallback = stripTags(bodyHtml);
1775
- if (fallback) {
1776
- blocks.push({ kind: "paragraph", text: fallback });
1777
- }
1778
- }
1779
- return { title, blocks };
1780
- }
1781
- function wrapTextLines(text, maxCharsPerLine) {
1782
- const words = text.split(/\s+/).filter(Boolean);
1783
- if (words.length === 0) return [];
1784
- const lines = [];
1785
- let current = words[0];
1786
- for (let i = 1; i < words.length; i++) {
1787
- const word = words[i];
1788
- if (current.length + 1 + word.length <= maxCharsPerLine) {
1789
- current += " " + word;
1790
- } else {
1791
- lines.push(current);
1792
- current = word;
1793
- }
1794
- }
1795
- lines.push(current);
1796
- return lines;
1797
- }
1798
- function rgbColor(r, g, b, grayscale) {
1799
- if (!grayscale) return { r, g, b };
1800
- const lum = Math.round((0.299 * r + 0.587 * g + 0.114 * b) * 1e3) / 1e3;
1801
- return { r: lum, g: lum, b: lum };
1802
- }
1803
- function layoutObjectPagesSync(blocks, box, settings, signal) {
1804
- const pages = [];
1805
- let currentActions = [];
1806
- const headerReserve = settings.header.left || settings.header.center || settings.header.right ? 24 : 0;
1807
- const footerReserve = settings.footer.left || settings.footer.center || settings.footer.right ? 24 : 0;
1808
- const topY = box.height - box.marginTop - headerReserve;
1809
- const bottomY = box.marginBottom + footerReserve;
1810
- const contentWidth = Math.max(72, box.width - box.marginLeft - box.marginRight);
1811
- let cursorY = topY;
1812
- const flushPage = () => {
1813
- pages.push({ actions: currentActions });
1814
- currentActions = [];
1815
- cursorY = topY;
1816
- };
1817
- const ensureHeight = (needed) => {
1818
- if (cursorY - needed < bottomY && currentActions.length > 0) {
1819
- flushPage();
1820
- }
1821
- };
1822
- let work = 0;
1823
- for (const block of blocks) {
1824
- signal.throwIfAborted();
1825
- if (++work % 64 === 0) signal.throwIfAborted();
1826
- if (block.kind === "pagebreak") {
1827
- flushPage();
1828
- continue;
1829
- }
1830
- if (block.kind === "heading") {
1831
- const level = block.level ?? 1;
1832
- const fontSize = level === 1 ? 20 : level === 2 ? 16 : level === 3 ? 14 : 12;
1833
- const lineHeight = fontSize * 1.35;
1834
- const maxChars = Math.max(15, Math.floor(contentWidth / (fontSize * 0.55)));
1835
- const lines = wrapTextLines(block.text ?? "", maxChars);
1836
- ensureHeight(lines.length * lineHeight + 10);
1837
- cursorY -= 4;
1838
- const blockTopY = cursorY;
1839
- for (const line of lines) {
1840
- const drawY = cursorY - fontSize;
1841
- const x = box.marginLeft;
1842
- currentActions.push((page, _doc, grayscale) => {
1843
- page.drawText(line, {
1844
- x,
1845
- y: drawY,
1846
- size: fontSize,
1847
- font: "Helvetica-Bold",
1848
- color: rgbColor(0.1, 0.12, 0.18, grayscale)
1849
- });
1850
- });
1851
- cursorY -= lineHeight;
1852
- }
1853
- if (block.links && block.links.length > 0 && settings.useExternalLinks) {
1854
- const rectBottom = cursorY;
1855
- const rectTop = blockTopY;
1856
- for (const link of block.links) {
1857
- currentActions.push((page) => {
1858
- page.addLinkAnnotation({
1859
- rect: [box.marginLeft, rectBottom, box.marginLeft + Math.min(contentWidth, 220), rectTop],
1860
- uri: link.href
1861
- });
1862
- });
1863
- }
1864
- }
1865
- cursorY -= 6;
1866
- continue;
1867
- }
1868
- if (block.kind === "paragraph") {
1869
- const fontSize = 11;
1870
- const lineHeight = 15;
1871
- const maxChars = Math.max(20, Math.floor(contentWidth / (fontSize * 0.52)));
1872
- const lines = wrapTextLines(block.text ?? "", maxChars);
1873
- ensureHeight(lines.length * lineHeight + 6);
1874
- const blockTopY = cursorY;
1875
- for (const line of lines) {
1876
- const drawY = cursorY - fontSize;
1877
- const x = box.marginLeft;
1878
- const hasLink = (block.links?.length ?? 0) > 0;
1879
- currentActions.push((page, _doc, grayscale) => {
1880
- page.drawText(line, {
1881
- x,
1882
- y: drawY,
1883
- size: fontSize,
1884
- font: "Helvetica",
1885
- color: hasLink ? rgbColor(0.05, 0.28, 0.72, grayscale) : rgbColor(0.12, 0.12, 0.12, grayscale)
1886
- });
1887
- });
1888
- cursorY -= lineHeight;
1889
- }
1890
- if (block.links && block.links.length > 0 && settings.useExternalLinks) {
1891
- const rectBottom = cursorY;
1892
- const rectTop = blockTopY;
1893
- for (const link of block.links) {
1894
- currentActions.push((page) => {
1895
- page.addLinkAnnotation({
1896
- rect: [box.marginLeft, rectBottom, box.marginLeft + Math.min(contentWidth, 220), rectTop],
1897
- uri: link.href
1898
- });
1899
- });
1900
- }
1901
- }
1902
- cursorY -= 6;
1903
- continue;
1904
- }
1905
- if (block.kind === "code") {
1906
- const fontSize = 9.5;
1907
- const lineHeight = 13;
1908
- const rawLines = (block.text ?? "").split("\n");
1909
- const totalHeight = rawLines.length * lineHeight + 12;
1910
- ensureHeight(totalHeight);
1911
- const boxTop = cursorY;
1912
- const boxHeight = totalHeight - 4;
1913
- currentActions.push((page, _doc, grayscale) => {
1914
- page.drawRect({
1915
- x: box.marginLeft,
1916
- y: boxTop - boxHeight,
1917
- width: contentWidth,
1918
- height: boxHeight,
1919
- fill: rgbColor(0.95, 0.96, 0.97, grayscale),
1920
- stroke: rgbColor(0.82, 0.84, 0.87, grayscale),
1921
- strokeWidth: 0.5
1922
- });
1923
- });
1924
- cursorY -= 6;
1925
- for (const rawLine of rawLines) {
1926
- const drawY = cursorY - fontSize;
1927
- const x = box.marginLeft + 6;
1928
- currentActions.push((page, _doc, grayscale) => {
1929
- page.drawText(rawLine, {
1930
- x,
1931
- y: drawY,
1932
- size: fontSize,
1933
- font: "Courier",
1934
- color: rgbColor(0.15, 0.15, 0.2, grayscale)
1935
- });
1936
- });
1937
- cursorY -= lineHeight;
1938
- }
1939
- cursorY -= 8;
1940
- continue;
1941
- }
1942
- if (block.kind === "list") {
1943
- const fontSize = 11;
1944
- const lineHeight = 15;
1945
- const items = block.items ?? [];
1946
- for (let idx = 0; idx < items.length; idx++) {
1947
- const prefix = block.ordered ? `${idx + 1}. ` : "\u2022 ";
1948
- const lines = wrapTextLines(prefix + items[idx], Math.max(20, Math.floor((contentWidth - 14) / 5.8)));
1949
- ensureHeight(lines.length * lineHeight + 2);
1950
- for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
1951
- const drawY = cursorY - fontSize;
1952
- const x = box.marginLeft + (lineIdx === 0 ? 10 : 22);
1953
- const lineText = lines[lineIdx];
1954
- currentActions.push((page, _doc, grayscale) => {
1955
- page.drawText(lineText, {
1956
- x,
1957
- y: drawY,
1958
- size: fontSize,
1959
- font: "Helvetica",
1960
- color: rgbColor(0.12, 0.12, 0.12, grayscale)
1961
- });
1962
- });
1963
- cursorY -= lineHeight;
1964
- }
1965
- }
1966
- cursorY -= 4;
1967
- continue;
1968
- }
1969
- if (block.kind === "blockquote") {
1970
- const fontSize = 10.5;
1971
- const lineHeight = 14.5;
1972
- const maxChars = Math.max(20, Math.floor((contentWidth - 18) / (fontSize * 0.52)));
1973
- const lines = wrapTextLines(block.text ?? "", maxChars);
1974
- const totalH = lines.length * lineHeight + 6;
1975
- ensureHeight(totalH);
1976
- const barTop = cursorY - 2;
1977
- const barBottom = cursorY - totalH + 4;
1978
- currentActions.push((page, _doc, grayscale) => {
1979
- page.drawLine({
1980
- x1: box.marginLeft + 4,
1981
- y1: barTop,
1982
- x2: box.marginLeft + 4,
1983
- y2: barBottom,
1984
- stroke: rgbColor(0.45, 0.5, 0.6, grayscale),
1985
- strokeWidth: 2.2
1986
- });
1987
- });
1988
- for (const line of lines) {
1989
- const drawY = cursorY - fontSize;
1990
- const x = box.marginLeft + 14;
1991
- currentActions.push((page, _doc, grayscale) => {
1992
- page.drawText(line, {
1993
- x,
1994
- y: drawY,
1995
- size: fontSize,
1996
- font: "Helvetica-Oblique",
1997
- color: rgbColor(0.25, 0.27, 0.32, grayscale)
1998
- });
1999
- });
2000
- cursorY -= lineHeight;
2001
- }
2002
- cursorY -= 6;
2003
- continue;
2004
- }
2005
- if (block.kind === "svg") {
2006
- const h = block.displayHeight ?? 100;
2007
- ensureHeight(h + 8);
2008
- const topBoxY = cursorY;
2009
- const prims = block.svgPrimitives ?? [];
2010
- currentActions.push((page, _doc, grayscale) => {
2011
- for (const p of prims) {
2012
- if (p.kind === "rect") {
2013
- const rw = p.w ?? 40;
2014
- const rh = p.h ?? 20;
2015
- page.drawRect({
2016
- x: box.marginLeft + p.x,
2017
- y: topBoxY - p.y - rh,
2018
- width: rw,
2019
- height: rh,
2020
- fill: rgbColor(0.92, 0.94, 0.98, grayscale),
2021
- stroke: rgbColor(0.3, 0.4, 0.6, grayscale),
2022
- strokeWidth: 0.8
2023
- });
2024
- } else if (p.kind === "text" && p.text) {
2025
- page.drawText(p.text, {
2026
- x: box.marginLeft + p.x,
2027
- y: topBoxY - p.y,
2028
- size: 10,
2029
- font: "Helvetica",
2030
- color: rgbColor(0.1, 0.12, 0.18, grayscale)
2031
- });
2032
- }
2033
- }
2034
- });
2035
- cursorY -= h + 8;
2036
- continue;
2037
- }
2038
- if (block.kind === "table") {
2039
- const rows = block.rows ?? [];
2040
- const colCount = Math.max(
2041
- 1,
2042
- ...rows.map((r) => r.cells.reduce((sum, c) => sum + c.colspan, 0))
2043
- );
2044
- const colWidth = contentWidth / colCount;
2045
- const rowHeight = 20;
2046
- ensureHeight(rows.length * rowHeight + 8);
2047
- for (const row of rows) {
2048
- ensureHeight(rowHeight);
2049
- const rowBottom = cursorY - rowHeight;
2050
- let colCursor = 0;
2051
- for (const cell of row.cells) {
2052
- if (colCursor >= colCount) break;
2053
- const span = Math.min(cell.colspan, colCount - colCursor);
2054
- const cellX = box.marginLeft + colCursor * colWidth;
2055
- const cellW = span * colWidth;
2056
- const cellText = cell.text;
2057
- const isHeader = row.header;
2058
- currentActions.push((page, _doc, grayscale) => {
2059
- page.drawRect({
2060
- x: cellX,
2061
- y: rowBottom,
2062
- width: cellW,
2063
- height: rowHeight,
2064
- ...isHeader ? { fill: rgbColor(0.91, 0.93, 0.96, grayscale) } : {},
2065
- stroke: rgbColor(0.7, 0.73, 0.78, grayscale),
2066
- strokeWidth: 0.6
2067
- });
2068
- page.drawText(cellText, {
2069
- x: cellX + 5,
2070
- y: rowBottom + 6,
2071
- size: 9.5,
2072
- font: isHeader ? "Helvetica-Bold" : "Helvetica",
2073
- color: rgbColor(0.1, 0.1, 0.12, grayscale)
2074
- });
2075
- });
2076
- colCursor += span;
2077
- }
2078
- cursorY -= rowHeight;
2079
- }
2080
- cursorY -= 8;
2081
- continue;
2082
- }
2083
- if (block.kind === "hr") {
2084
- ensureHeight(12);
2085
- const lineY = cursorY - 6;
2086
- currentActions.push((page, _doc, grayscale) => {
2087
- page.drawLine({
2088
- x1: box.marginLeft,
2089
- y1: lineY,
2090
- x2: box.marginLeft + contentWidth,
2091
- y2: lineY,
2092
- stroke: rgbColor(0.75, 0.75, 0.78, grayscale),
2093
- strokeWidth: 0.75
2094
- });
2095
- });
2096
- cursorY -= 12;
2097
- continue;
2098
- }
2099
- if (block.kind === "image" && block.pngBytes) {
2100
- const w = block.displayWidth ?? 120;
2101
- const h = block.displayHeight ?? 90;
2102
- ensureHeight(h + 8);
2103
- const drawY = cursorY - h;
2104
- const pngBytes = block.pngBytes;
2105
- currentActions.push((page, doc) => {
2106
- const imgRef = doc.embedPng(pngBytes);
2107
- page.drawImage(imgRef, {
2108
- x: box.marginLeft,
2109
- y: drawY,
2110
- width: w,
2111
- height: h
2112
- });
2113
- });
2114
- cursorY -= h + 8;
2115
- }
2116
- }
2117
- if (currentActions.length > 0 || pages.length === 0) {
2118
- flushPage();
2119
- }
2120
- return pages;
2121
- }
2122
- function substituteFurnitureTokens(template, tokens) {
2123
- const isoDate = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
2124
- return template.replace(/\[page\]/g, String(tokens.page)).replace(/\[topage\]/g, String(tokens.topage)).replace(/\[webpage\]/g, tokens.webpage).replace(/\[title\]/g, tokens.title).replace(/\[section\]/g, tokens.section ?? tokens.title).replace(/\[subsection\]/g, tokens.subsection ?? "").replace(/\[isodate\]/g, isoDate).replace(/\[date\]/g, isoDate);
2125
- }
2126
- function renderPdfAstSync(request) {
2127
- request.signal.throwIfAborted();
2128
- const { job, inputs, signal, limits } = request;
2129
- const decoder2 = new TextDecoder("utf-8", { fatal: false, ignoreBOM: true });
2130
- const box = resolvePageBox(job.global);
2131
- const grayscale = job.global.colorMode === "grayscale";
2132
- const laidOutPerObject = [];
2133
- const objectMeta = [];
2134
- let inferredDocumentTitle = job.global.documentTitle;
2135
- for (let i = 0; i < job.objects.length; i++) {
2136
- signal.throwIfAborted();
2137
- const obj = job.objects[i];
2138
- const htmlBytes = inputs[i] ?? new Uint8Array(0);
2139
- const htmlText = decoder2.decode(htmlBytes);
2140
- const parsed = parseHtmlDocumentSync(htmlText, obj.settings.replacements, signal);
2141
- if (!inferredDocumentTitle && parsed.title) {
2142
- inferredDocumentTitle = parsed.title;
2143
- }
2144
- const pages = layoutObjectPagesSync(parsed.blocks, box, obj.settings, signal);
2145
- laidOutPerObject.push(pages);
2146
- objectMeta.push({
2147
- title: parsed.title || inferredDocumentTitle || "Document",
2148
- webpage: obj.input ?? "-",
2149
- settings: obj.settings
2150
- });
2151
- }
2152
- const sequence = planPageSequence(
2153
- laidOutPerObject.map((pages, idx) => ({
2154
- physicalPages: pages.length,
2155
- pagesCount: job.objects[idx].settings.pagesCount
2156
- })),
2157
- {
2158
- copies: job.global.copies,
2159
- collate: job.global.collate,
2160
- pageOffset: job.global.pageOffset,
2161
- limits: {
2162
- maxObjects: limits.parse.maxObjects,
2163
- maxPhysicalPages: Infinity,
2164
- maxWork: limits.resources.maxWork
2165
- },
2166
- signal
2167
- }
2168
- );
2169
- const doc = PdfDocument.create();
2170
- doc.setMetadata({
2171
- title: inferredDocumentTitle || "Document",
2172
- creator: "wkhtmltopdf (pdf-ast-static)",
2173
- producer: "@poe-code/pdf-ast"
2174
- });
2175
- for (const outPage of sequence.pages) {
2176
- signal.throwIfAborted();
2177
- const spec = laidOutPerObject[outPage.objectIndex][outPage.pageIndex];
2178
- const meta = objectMeta[outPage.objectIndex];
2179
- const page = doc.addPage({ width: box.width, height: box.height });
2180
- for (const action of spec.actions) action(page, doc, grayscale);
2181
- const tokens = {
2182
- page: outPage.logicalPage,
2183
- topage: sequence.logicalTotal + job.global.pageOffset,
2184
- webpage: meta.webpage,
2185
- title: meta.title
2186
- };
2187
- const header = meta.settings.header;
2188
- const footer = meta.settings.footer;
2189
- const headerY = box.height - Math.max(18, box.marginTop * 0.6);
2190
- if (header.left) {
2191
- page.drawText(substituteFurnitureTokens(header.left, tokens), {
2192
- x: box.marginLeft,
2193
- y: headerY,
2194
- size: Math.min(10, header.fontSize || 9),
2195
- font: "Helvetica",
2196
- color: rgbColor(0.35, 0.35, 0.38, grayscale)
2197
- });
2198
- }
2199
- if (header.center) {
2200
- const text = substituteFurnitureTokens(header.center, tokens);
2201
- page.drawText(text, {
2202
- x: Math.max(box.marginLeft, (box.width - text.length * 4.5) / 2),
2203
- y: headerY,
2204
- size: Math.min(10, header.fontSize || 9),
2205
- font: "Helvetica",
2206
- color: rgbColor(0.35, 0.35, 0.38, grayscale)
2207
- });
2208
- }
2209
- if (header.right) {
2210
- const text = substituteFurnitureTokens(header.right, tokens);
2211
- page.drawText(text, {
2212
- x: Math.max(box.marginLeft, box.width - box.marginRight - text.length * 4.8),
2213
- y: headerY,
2214
- size: Math.min(10, header.fontSize || 9),
2215
- font: "Helvetica",
2216
- color: rgbColor(0.35, 0.35, 0.38, grayscale)
2217
- });
2218
- }
2219
- if (header.line) {
2220
- page.drawLine({
2221
- x1: box.marginLeft,
2222
- y1: headerY - 4,
2223
- x2: box.width - box.marginRight,
2224
- y2: headerY - 4,
2225
- stroke: rgbColor(0.7, 0.7, 0.74, grayscale),
2226
- strokeWidth: 0.5
2227
- });
2228
- }
2229
- const footerY = Math.max(12, box.marginBottom * 0.5);
2230
- if (footer.left) {
2231
- page.drawText(substituteFurnitureTokens(footer.left, tokens), {
2232
- x: box.marginLeft,
2233
- y: footerY,
2234
- size: Math.min(10, footer.fontSize || 9),
2235
- font: "Helvetica",
2236
- color: rgbColor(0.35, 0.35, 0.38, grayscale)
2237
- });
2238
- }
2239
- if (footer.center) {
2240
- const text = substituteFurnitureTokens(footer.center, tokens);
2241
- page.drawText(text, {
2242
- x: Math.max(box.marginLeft, (box.width - text.length * 4.5) / 2),
2243
- y: footerY,
2244
- size: Math.min(10, footer.fontSize || 9),
2245
- font: "Helvetica",
2246
- color: rgbColor(0.35, 0.35, 0.38, grayscale)
2247
- });
2248
- }
2249
- if (footer.right) {
2250
- const text = substituteFurnitureTokens(footer.right, tokens);
2251
- page.drawText(text, {
2252
- x: Math.max(box.marginLeft, box.width - box.marginRight - text.length * 4.8),
2253
- y: footerY,
2254
- size: Math.min(10, footer.fontSize || 9),
2255
- font: "Helvetica",
2256
- color: rgbColor(0.35, 0.35, 0.38, grayscale)
2257
- });
2258
- }
2259
- if (footer.line) {
2260
- page.drawLine({
2261
- x1: box.marginLeft,
2262
- y1: footerY + 11,
2263
- x2: box.width - box.marginRight,
2264
- y2: footerY + 11,
2265
- stroke: rgbColor(0.7, 0.7, 0.74, grayscale),
2266
- strokeWidth: 0.5
2267
- });
2268
- }
2269
- }
2270
- return doc.save();
2271
- }
2272
- function createPdfAstRenderer() {
2273
- return Object.freeze({
2274
- profile: pdfAstRendererProfile,
2275
- async open(request) {
2276
- await yieldTurn(request.signal);
2277
- const pdfBytes = renderPdfAstSync(request);
2278
- return {
2279
- success: true,
2280
- errorCode: 0,
2281
- chunks: [pdfBytes],
2282
- async close() {
2283
- }
2284
- };
2285
- }
2286
- });
2287
- }
2288
- var pdfAstRenderer = createPdfAstRenderer();
2289
- function createPdfAstWkhtmltopdfCommand(options = {}) {
2290
- return createWkhtmltopdfCommand({
2291
- limits: options.limits ?? wkhtmltopdfLimits,
2292
- renderer: options.renderer ?? pdfAstRenderer,
2293
- ...options.replace === void 0 ? {} : { replace: options.replace }
2294
- });
2295
- }
2296
- var pdfAstWkhtmltopdfCommand = createPdfAstWkhtmltopdfCommand();
2297
- function pdfAstWkhtmltopdfCommands(options = {}) {
2298
- return wkhtmltopdfCommands({
2299
- limits: options.limits ?? wkhtmltopdfLimits,
2300
- renderer: options.renderer ?? pdfAstRenderer,
2301
- ...options.replace === void 0 ? {} : { replace: options.replace }
2302
- });
2303
- }
2304
-
2305
- export {
2306
- parseInvocation,
2307
- informationText,
2308
- pdfAstRendererProfile,
2309
- renderPdfAstSync,
2310
- createPdfAstRenderer,
2311
- pdfAstRenderer,
2312
- createPdfAstWkhtmltopdfCommand,
2313
- pdfAstWkhtmltopdfCommand,
2314
- pdfAstWkhtmltopdfCommands,
2315
- wkhtmltopdfLimits
2316
- };
2317
- //# sourceMappingURL=chunk-OSUXMC43.js.map