@poe-platform/safe-bash 0.1.710 → 0.1.712
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -1
- package/dist/safe-bash/commands/fmt/index.d.ts +2 -0
- package/dist/safe-bash/commands/fmt/index.d.ts.map +1 -0
- package/dist/safe-bash/commands/fmt/index.js +2 -0
- package/dist/safe-bash/commands/fmt/index.js.map +1 -0
- package/dist/safe-bash/commands/fmt.d.ts +1 -2
- package/dist/safe-bash/commands/fmt.d.ts.map +1 -1
- package/dist/safe-bash/commands/fmt.js +1 -838
- package/dist/safe-bash/commands/fmt.js.map +1 -1
- package/dist/safe-bash/commands/time-env/printenv.d.ts +1 -1
- package/dist/safe-bash/commands/time-env/printenv.d.ts.map +1 -1
- package/dist/safe-bash/commands/time-env/sleep.d.ts +1 -1
- package/dist/safe-bash/commands/time-env/sleep.d.ts.map +1 -1
- package/dist/safe-bash/core.browser.js +155 -2099
- package/dist/safe-bash/core.browser.js.map +3 -3
- package/dist/safe-bash/playwright/private-target-transport.d.ts.map +1 -1
- package/dist/safe-bash/playwright/private-target-transport.js +18 -2
- package/dist/safe-bash/playwright/private-target-transport.js.map +1 -1
- package/dist/safe-bash/playwright/profile.d.ts +3 -1
- package/dist/safe-bash/playwright/profile.d.ts.map +1 -1
- package/dist/safe-bash/playwright/profile.js +3 -3
- package/dist/safe-bash/playwright/profile.js.map +1 -1
- package/dist/safe-bash-command-exiftool/index.js +1401 -6
- package/dist/safe-bash-command-exiftool/index.js.map +7 -0
- package/dist/safe-bash-command-fmt/arguments.d.ts +8 -0
- package/dist/safe-bash-command-fmt/command.d.ts +20 -0
- package/dist/safe-bash-command-fmt/contracts.d.ts +42 -0
- package/dist/safe-bash-command-fmt/engine.d.ts +20 -0
- package/dist/safe-bash-command-fmt/index.d.ts +5 -0
- package/dist/safe-bash-command-fmt/index.js +2419 -0
- package/dist/safe-bash-command-fmt/index.js.map +7 -0
- package/dist/safe-bash-command-fmt/sdk.d.ts +15 -0
- package/dist/safe-bash-command-wkhtmltopdf/index.js +1458 -7
- package/dist/safe-bash-command-wkhtmltopdf/index.js.map +7 -0
- package/dist/safe-bash-contracts/index.d.ts +8 -0
- package/dist/safe-bash-contracts/index.js +8 -0
- package/dist/safe-playwright-cloudflare/browser-run-code.js +15 -1
- package/package.json +6 -2
- package/dist/safe-bash-command-exiftool/argfiles.js +0 -163
- package/dist/safe-bash-command-exiftool/arguments.js +0 -128
- package/dist/safe-bash-command-exiftool/command.js +0 -324
- package/dist/safe-bash-command-exiftool/csv.js +0 -78
- package/dist/safe-bash-command-exiftool/paths.js +0 -18
- package/dist/safe-bash-command-exiftool/png.js +0 -308
- package/dist/safe-bash-command-exiftool/publication.js +0 -80
- package/dist/safe-bash-command-exiftool/registry.js +0 -14
- package/dist/safe-bash-command-exiftool/resources.js +0 -29
- package/dist/safe-bash-command-exiftool/scalar.js +0 -103
- package/dist/safe-bash-command-exiftool/sdk.js +0 -113
- package/dist/safe-bash-command-exiftool/shifts.js +0 -29
- package/dist/safe-bash-command-wkhtmltopdf/command.js +0 -373
- package/dist/safe-bash-command-wkhtmltopdf/engine.js +0 -99
- package/dist/safe-bash-command-wkhtmltopdf/errors.js +0 -11
- package/dist/safe-bash-command-wkhtmltopdf/limits.js +0 -69
- package/dist/safe-bash-command-wkhtmltopdf/outcome.js +0 -38
- package/dist/safe-bash-command-wkhtmltopdf/parser.js +0 -146
- package/dist/safe-bash-command-wkhtmltopdf/resources.js +0 -284
- package/dist/safe-bash-command-wkhtmltopdf/settings.js +0 -35
- package/dist/safe-bash-command-wkhtmltopdf/switches.js +0 -127
- package/dist/safe-bash-command-wkhtmltopdf/values.js +0 -66
|
@@ -1,7 +1,1458 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/errors.js
|
|
2
|
+
var WkhtmltopdfError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
option;
|
|
5
|
+
exitCode = 1;
|
|
6
|
+
constructor(code, message, option) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.option = option;
|
|
10
|
+
this.name = "WkhtmltopdfError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/limits.js
|
|
15
|
+
var ParseBudget = class {
|
|
16
|
+
options;
|
|
17
|
+
work = 0;
|
|
18
|
+
bytes = 0;
|
|
19
|
+
objects = 0;
|
|
20
|
+
limits;
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.checkCancellation();
|
|
24
|
+
this.limits = {
|
|
25
|
+
maxArguments: options.limits?.maxArguments,
|
|
26
|
+
maxTextBytes: options.limits?.maxTextBytes,
|
|
27
|
+
maxObjects: options.limits?.maxObjects,
|
|
28
|
+
maxWork: options.limits?.maxWork
|
|
29
|
+
};
|
|
30
|
+
for (const value of Object.values(this.limits)) {
|
|
31
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
32
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Parser limits must be positive safe integers");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
checkCancellation() {
|
|
37
|
+
if (this.options.signal?.aborted)
|
|
38
|
+
throw this.options.signal.reason;
|
|
39
|
+
}
|
|
40
|
+
step(amount = 1) {
|
|
41
|
+
this.checkCancellation();
|
|
42
|
+
if (amount > this.limits.maxWork - this.work) {
|
|
43
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser work limit exceeded");
|
|
44
|
+
}
|
|
45
|
+
this.work += amount;
|
|
46
|
+
}
|
|
47
|
+
admitArguments(count) {
|
|
48
|
+
this.step();
|
|
49
|
+
if (count > this.limits.maxArguments) {
|
|
50
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser argument limit exceeded");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
admitText(text) {
|
|
54
|
+
for (let i = 0; i < text.length; i++) {
|
|
55
|
+
this.step();
|
|
56
|
+
const code = text.charCodeAt(i);
|
|
57
|
+
let size = code < 128 ? 1 : code < 2048 ? 2 : 3;
|
|
58
|
+
if (code >= 55296 && code <= 56319) {
|
|
59
|
+
const next = text.charCodeAt(i + 1);
|
|
60
|
+
if (next >= 56320 && next <= 57343) {
|
|
61
|
+
size = 4;
|
|
62
|
+
i++;
|
|
63
|
+
this.step();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (size > this.limits.maxTextBytes - this.bytes) {
|
|
67
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser text byte limit exceeded");
|
|
68
|
+
}
|
|
69
|
+
this.bytes += size;
|
|
70
|
+
if (code === 0)
|
|
71
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "NUL is not admitted in CLI text");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
admitObject(replacementCount) {
|
|
75
|
+
this.step(64 + replacementCount * 2);
|
|
76
|
+
if (++this.objects > this.limits.maxObjects) {
|
|
77
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Parser object limit exceeded");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/settings.js
|
|
83
|
+
function createGlobalSettings() {
|
|
84
|
+
return {
|
|
85
|
+
logLevel: "info",
|
|
86
|
+
orientation: "Portrait",
|
|
87
|
+
pageSize: "A4",
|
|
88
|
+
dpi: 96,
|
|
89
|
+
copies: 1,
|
|
90
|
+
collate: true,
|
|
91
|
+
outline: true,
|
|
92
|
+
outlineDepth: 4,
|
|
93
|
+
imageDPI: 600,
|
|
94
|
+
imageQuality: 94,
|
|
95
|
+
useCompression: true,
|
|
96
|
+
colorMode: "color",
|
|
97
|
+
resolution: "high",
|
|
98
|
+
documentTitle: "",
|
|
99
|
+
marginTop: { value: -1, unit: "mm" },
|
|
100
|
+
marginBottom: { value: -1, unit: "mm" },
|
|
101
|
+
marginLeft: { value: 10, unit: "mm" },
|
|
102
|
+
marginRight: { value: 10, unit: "mm" },
|
|
103
|
+
pageHeight: { value: -1, unit: "mm" },
|
|
104
|
+
pageWidth: { value: -1, unit: "mm" },
|
|
105
|
+
pageOffset: 0,
|
|
106
|
+
resolveRelativeLinks: true,
|
|
107
|
+
viewportSize: "",
|
|
108
|
+
readArgsFromStdin: false,
|
|
109
|
+
action: ""
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function createPageSettings() {
|
|
113
|
+
return {
|
|
114
|
+
header: { fontSize: 12, fontName: "Arial", left: "", right: "", center: "", line: false, htmlUrl: "", spacing: 0 },
|
|
115
|
+
footer: { fontSize: 12, fontName: "Arial", left: "", right: "", center: "", line: false, htmlUrl: "", spacing: 0 },
|
|
116
|
+
toc: { useDottedLines: true, captionText: "Table of Contents", forwardLinks: true, backLinks: false, indentation: "1em", fontScale: Math.fround(0.8) },
|
|
117
|
+
web: { background: true, loadImages: true, enableJavascript: true, enableIntelligentShrinking: true, minimumFontSize: -1, defaultEncoding: "", enablePlugins: false },
|
|
118
|
+
load: { jsdelay: 200, zoomFactor: 1, blockLocalFileAccess: true, stopSlowScripts: true, loadErrorHandling: "abort", mediaLoadErrorHandling: "ignore", printMediaType: false },
|
|
119
|
+
includeInOutline: true,
|
|
120
|
+
pagesCount: true,
|
|
121
|
+
produceForms: false,
|
|
122
|
+
useLocalLinks: true,
|
|
123
|
+
useExternalLinks: true,
|
|
124
|
+
replacements: []
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function clonePageSettings(settings) {
|
|
128
|
+
return {
|
|
129
|
+
...settings,
|
|
130
|
+
header: { ...settings.header },
|
|
131
|
+
footer: { ...settings.footer },
|
|
132
|
+
toc: { ...settings.toc },
|
|
133
|
+
web: { ...settings.web },
|
|
134
|
+
load: { ...settings.load },
|
|
135
|
+
replacements: settings.replacements.map(([key, value]) => [key, value])
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/values.js
|
|
140
|
+
function integer(text, min, max) {
|
|
141
|
+
const value = text.trim();
|
|
142
|
+
let index = value[0] === "+" || value[0] === "-" ? 1 : 0;
|
|
143
|
+
if (index === value.length)
|
|
144
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected an integer");
|
|
145
|
+
for (; index < value.length; index++) {
|
|
146
|
+
if (value[index] < "0" || value[index] > "9") {
|
|
147
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected a decimal integer");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const result = Number(value);
|
|
151
|
+
if (!Number.isSafeInteger(result) || result < min || result > max) {
|
|
152
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Integer is outside the admitted range");
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
function float32(text, positive) {
|
|
157
|
+
const value = text.trim();
|
|
158
|
+
let digits = 0;
|
|
159
|
+
for (const character of value) {
|
|
160
|
+
if (character >= "0" && character <= "9")
|
|
161
|
+
digits++;
|
|
162
|
+
else if (!"+-.eE".includes(character)) {
|
|
163
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected a decimal float");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const result = Math.fround(Number(value));
|
|
167
|
+
if (!digits || !Number.isFinite(result) || (positive ? result <= 0 : result < 0)) {
|
|
168
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Float is outside the admitted finite binary32 range");
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
function choice(text, values) {
|
|
173
|
+
const result = values.find((value) => value.toLowerCase() === text.toLowerCase());
|
|
174
|
+
if (result === void 0)
|
|
175
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Unknown enumerated value");
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
function length(text) {
|
|
179
|
+
let index = 0;
|
|
180
|
+
while (text[index] !== void 0 && text[index] >= "0" && text[index] <= "9")
|
|
181
|
+
index++;
|
|
182
|
+
if (text[index] === ".")
|
|
183
|
+
index++;
|
|
184
|
+
while (text[index] !== void 0 && text[index] >= "0" && text[index] <= "9")
|
|
185
|
+
index++;
|
|
186
|
+
const number = text.slice(0, index);
|
|
187
|
+
const value = Number(number);
|
|
188
|
+
if (!number || number === "." || !Number.isFinite(value)) {
|
|
189
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected an unsigned finite length");
|
|
190
|
+
}
|
|
191
|
+
const units = {
|
|
192
|
+
"": ["mm", 1],
|
|
193
|
+
mm: ["mm", 1],
|
|
194
|
+
millimeter: ["mm", 1],
|
|
195
|
+
cm: ["mm", 10],
|
|
196
|
+
centimeter: ["mm", 10],
|
|
197
|
+
m: ["mm", 1e3],
|
|
198
|
+
meter: ["mm", 1e3],
|
|
199
|
+
in: ["in", 1],
|
|
200
|
+
inch: ["in", 1],
|
|
201
|
+
pt: ["pt", 1],
|
|
202
|
+
point: ["pt", 1],
|
|
203
|
+
px: ["px", 1],
|
|
204
|
+
pixel: ["px", 1],
|
|
205
|
+
pc: ["pc", 1],
|
|
206
|
+
pica: ["pc", 1],
|
|
207
|
+
didot: ["didot", 1],
|
|
208
|
+
cicero: ["cicero", 1]
|
|
209
|
+
};
|
|
210
|
+
const suffix = text.slice(index).toLowerCase();
|
|
211
|
+
const entry = Object.hasOwn(units, suffix) ? units[suffix] : void 0;
|
|
212
|
+
if (!entry || !Number.isFinite(value * entry[1])) {
|
|
213
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Unknown or overflowing length unit");
|
|
214
|
+
}
|
|
215
|
+
return { value: value * entry[1], unit: entry[0] };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/switches.js
|
|
219
|
+
var declarations = [
|
|
220
|
+
{ name: "--help", short: "h", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
221
|
+
_g.action = "help";
|
|
222
|
+
} },
|
|
223
|
+
{ name: "--version", short: "V", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
224
|
+
_g.action = "version";
|
|
225
|
+
} },
|
|
226
|
+
{ name: "--license", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
227
|
+
_g.action = "license";
|
|
228
|
+
} },
|
|
229
|
+
{ name: "--extended-help", short: "H", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
230
|
+
_g.action = "extended-help";
|
|
231
|
+
} },
|
|
232
|
+
{ name: "--manpage", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
233
|
+
_g.action = "manpage";
|
|
234
|
+
} },
|
|
235
|
+
{ name: "--htmldoc", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
236
|
+
_g.action = "htmldoc";
|
|
237
|
+
} },
|
|
238
|
+
{ name: "--readme", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
239
|
+
_g.action = "readme";
|
|
240
|
+
} },
|
|
241
|
+
{ name: "--quiet", short: "q", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
242
|
+
_g.logLevel = "none";
|
|
243
|
+
} },
|
|
244
|
+
{ name: "--log-level", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
245
|
+
_g.logLevel = choice(_a[0], ["none", "error", "warn", "info", "debug"]);
|
|
246
|
+
} },
|
|
247
|
+
{ name: "--no-collate", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
248
|
+
_g.collate = false;
|
|
249
|
+
} },
|
|
250
|
+
{ name: "--collate", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
251
|
+
_g.collate = true;
|
|
252
|
+
} },
|
|
253
|
+
{ name: "--copies", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
254
|
+
_g.copies = integer(_a[0], 1, 2147483647);
|
|
255
|
+
} },
|
|
256
|
+
{ name: "--orientation", short: "O", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
257
|
+
_g.orientation = choice(_a[0], ["Portrait", "Landscape"]);
|
|
258
|
+
} },
|
|
259
|
+
{ name: "--page-size", short: "s", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
260
|
+
_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"]);
|
|
261
|
+
} },
|
|
262
|
+
{ name: "--grayscale", short: "g", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
263
|
+
_g.colorMode = "grayscale";
|
|
264
|
+
} },
|
|
265
|
+
{ name: "--lowquality", short: "l", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
266
|
+
_g.resolution = "screen";
|
|
267
|
+
} },
|
|
268
|
+
{ name: "--title", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
269
|
+
_g.documentTitle = _a[0];
|
|
270
|
+
} },
|
|
271
|
+
{ name: "--read-args-from-stdin", short: "", scope: "global", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
272
|
+
_g.readArgsFromStdin = true;
|
|
273
|
+
} },
|
|
274
|
+
{ name: "--margin-bottom", short: "B", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
275
|
+
_g.marginBottom = length(_a[0]);
|
|
276
|
+
} },
|
|
277
|
+
{ name: "--margin-left", short: "L", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
278
|
+
_g.marginLeft = length(_a[0]);
|
|
279
|
+
} },
|
|
280
|
+
{ name: "--margin-right", short: "R", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
281
|
+
_g.marginRight = length(_a[0]);
|
|
282
|
+
} },
|
|
283
|
+
{ name: "--margin-top", short: "T", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
284
|
+
_g.marginTop = length(_a[0]);
|
|
285
|
+
} },
|
|
286
|
+
{ name: "--dpi", short: "d", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
287
|
+
_g.dpi = integer(_a[0], 1, 2147483647);
|
|
288
|
+
} },
|
|
289
|
+
{ name: "--page-height", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
290
|
+
_g.pageHeight = length(_a[0]);
|
|
291
|
+
} },
|
|
292
|
+
{ name: "--page-width", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
293
|
+
_g.pageWidth = length(_a[0]);
|
|
294
|
+
} },
|
|
295
|
+
{ name: "--cookie-jar", short: "", scope: "global", arity: 1, qtPatched: false, disposition: "resource" },
|
|
296
|
+
{ name: "--image-quality", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
297
|
+
_g.imageQuality = integer(_a[0], 0, 100);
|
|
298
|
+
} },
|
|
299
|
+
{ name: "--image-dpi", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
300
|
+
_g.imageDPI = integer(_a[0], 1, 2147483647);
|
|
301
|
+
} },
|
|
302
|
+
{ name: "--no-pdf-compression", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
303
|
+
_g.useCompression = false;
|
|
304
|
+
} },
|
|
305
|
+
{ name: "--use-xserver", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "excluded" },
|
|
306
|
+
{ name: "--outline", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
307
|
+
_g.outline = true;
|
|
308
|
+
} },
|
|
309
|
+
{ name: "--no-outline", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
310
|
+
_g.outline = false;
|
|
311
|
+
} },
|
|
312
|
+
{ name: "--outline-depth", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
313
|
+
_g.outlineDepth = integer(_a[0], 0, 2147483647);
|
|
314
|
+
} },
|
|
315
|
+
{ name: "--dump-outline", short: "", scope: "global", arity: 1, qtPatched: true, disposition: "resource" },
|
|
316
|
+
{ name: "--dump-default-toc-xsl", short: "", scope: "global", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
317
|
+
_g.action = "dump-default-toc-xsl";
|
|
318
|
+
} },
|
|
319
|
+
{ name: "--default-header", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p) => {
|
|
320
|
+
_p.header.left = "[webpage]";
|
|
321
|
+
_p.header.right = "[page]/[topage]";
|
|
322
|
+
_p.header.line = true;
|
|
323
|
+
_g.marginTop = { value: 20, unit: "mm" };
|
|
324
|
+
} },
|
|
325
|
+
{ name: "--viewport-size", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
326
|
+
_g.viewportSize = _a[0];
|
|
327
|
+
} },
|
|
328
|
+
{ name: "--enable-plugins", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "excluded" },
|
|
329
|
+
{ name: "--disable-plugins", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
330
|
+
_p.web.enablePlugins = false;
|
|
331
|
+
} },
|
|
332
|
+
{ name: "--minimum-font-size", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
333
|
+
_p.web.minimumFontSize = integer(_a[0], 1, 2147483647);
|
|
334
|
+
} },
|
|
335
|
+
{ name: "--user-style-sheet", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
336
|
+
{ name: "--no-images", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
337
|
+
_p.web.loadImages = false;
|
|
338
|
+
} },
|
|
339
|
+
{ name: "--images", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
340
|
+
_p.web.loadImages = true;
|
|
341
|
+
} },
|
|
342
|
+
{ name: "--disable-javascript", short: "n", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
343
|
+
_p.web.enableJavascript = false;
|
|
344
|
+
} },
|
|
345
|
+
{ name: "--enable-javascript", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
|
|
346
|
+
{ name: "--encoding", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
347
|
+
_p.web.defaultEncoding = _a[0];
|
|
348
|
+
} },
|
|
349
|
+
{ name: "--no-background", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
350
|
+
_p.web.background = false;
|
|
351
|
+
} },
|
|
352
|
+
{ name: "--background", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
353
|
+
_p.web.background = true;
|
|
354
|
+
} },
|
|
355
|
+
{ name: "--include-in-outline", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
356
|
+
_p.includeInOutline = true;
|
|
357
|
+
} },
|
|
358
|
+
{ name: "--exclude-from-outline", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
359
|
+
_p.includeInOutline = false;
|
|
360
|
+
} },
|
|
361
|
+
{ name: "--disable-smart-shrinking", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
362
|
+
_p.web.enableIntelligentShrinking = false;
|
|
363
|
+
} },
|
|
364
|
+
{ name: "--enable-smart-shrinking", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
365
|
+
_p.web.enableIntelligentShrinking = true;
|
|
366
|
+
} },
|
|
367
|
+
{ name: "--print-media-type", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
368
|
+
_p.load.printMediaType = true;
|
|
369
|
+
} },
|
|
370
|
+
{ name: "--no-print-media-type", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
371
|
+
_p.load.printMediaType = false;
|
|
372
|
+
} },
|
|
373
|
+
{ name: "--enable-forms", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
374
|
+
_p.produceForms = true;
|
|
375
|
+
} },
|
|
376
|
+
{ name: "--disable-forms", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
377
|
+
_p.produceForms = false;
|
|
378
|
+
} },
|
|
379
|
+
{ name: "--disable-internal-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
380
|
+
_p.useLocalLinks = false;
|
|
381
|
+
} },
|
|
382
|
+
{ name: "--enable-internal-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
383
|
+
_p.useLocalLinks = true;
|
|
384
|
+
} },
|
|
385
|
+
{ name: "--disable-external-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
386
|
+
_p.useExternalLinks = false;
|
|
387
|
+
} },
|
|
388
|
+
{ name: "--enable-external-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
389
|
+
_p.useExternalLinks = true;
|
|
390
|
+
} },
|
|
391
|
+
{ name: "--resolve-relative-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
392
|
+
_g.resolveRelativeLinks = true;
|
|
393
|
+
} },
|
|
394
|
+
{ name: "--keep-relative-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
395
|
+
_g.resolveRelativeLinks = false;
|
|
396
|
+
} },
|
|
397
|
+
{ name: "--enable-toc-back-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
398
|
+
_p.toc.backLinks = true;
|
|
399
|
+
} },
|
|
400
|
+
{ name: "--disable-toc-back-links", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
401
|
+
_p.toc.backLinks = false;
|
|
402
|
+
} },
|
|
403
|
+
{ name: "--proxy", short: "p", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
404
|
+
{ name: "--proxy-hostname-lookup", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
|
|
405
|
+
{ name: "--bypass-proxy-for", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
406
|
+
{ name: "--username", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
407
|
+
{ name: "--password", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
408
|
+
{ name: "--ssl-key-path", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
409
|
+
{ name: "--ssl-key-password", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
410
|
+
{ name: "--ssl-crt-path", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
411
|
+
{ name: "--load-error-handling", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
412
|
+
_p.load.loadErrorHandling = choice(_a[0], ["abort", "skip", "ignore"]);
|
|
413
|
+
} },
|
|
414
|
+
{ name: "--load-media-error-handling", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
415
|
+
_p.load.mediaLoadErrorHandling = choice(_a[0], ["abort", "skip", "ignore"]);
|
|
416
|
+
} },
|
|
417
|
+
{ name: "--custom-header", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
|
|
418
|
+
{ name: "--custom-header-propagation", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
|
|
419
|
+
{ name: "--no-custom-header-propagation", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
|
|
420
|
+
{ name: "--javascript-delay", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "harness" },
|
|
421
|
+
{ name: "--window-status", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "harness" },
|
|
422
|
+
{ name: "--zoom", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
423
|
+
_p.load.zoomFactor = float32(_a[0], true);
|
|
424
|
+
} },
|
|
425
|
+
{ name: "--cookie", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
|
|
426
|
+
{ name: "--post", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
|
|
427
|
+
{ name: "--post-file", short: "", scope: "page", arity: 2, qtPatched: false, disposition: "resource" },
|
|
428
|
+
{ name: "--disable-local-file-access", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
429
|
+
_p.load.blockLocalFileAccess = true;
|
|
430
|
+
} },
|
|
431
|
+
{ name: "--enable-local-file-access", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "resource" },
|
|
432
|
+
{ name: "--allow", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
433
|
+
{ name: "--cache-dir", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
434
|
+
{ name: "--debug-javascript", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
|
|
435
|
+
{ name: "--no-debug-javascript", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
|
|
436
|
+
{ name: "--stop-slow-scripts", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
|
|
437
|
+
{ name: "--no-stop-slow-scripts", short: "", scope: "page", arity: 0, qtPatched: false, disposition: "harness" },
|
|
438
|
+
{ name: "--run-script", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "harness" },
|
|
439
|
+
{ name: "--checkbox-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
440
|
+
{ name: "--checkbox-checked-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
441
|
+
{ name: "--radiobutton-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
442
|
+
{ name: "--radiobutton-checked-svg", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "resource" },
|
|
443
|
+
{ name: "--page-offset", short: "", scope: "page", arity: 1, qtPatched: false, disposition: "static", apply: (_g, _p, _a) => {
|
|
444
|
+
_g.pageOffset = integer(_a[0], -2147483648, 2147483647);
|
|
445
|
+
} },
|
|
446
|
+
{ name: "--footer-center", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
447
|
+
_p.footer.center = _a[0];
|
|
448
|
+
} },
|
|
449
|
+
{ name: "--footer-font-name", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
450
|
+
_p.footer.fontName = _a[0];
|
|
451
|
+
} },
|
|
452
|
+
{ name: "--footer-font-size", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
453
|
+
_p.footer.fontSize = integer(_a[0], 1, 2147483647);
|
|
454
|
+
} },
|
|
455
|
+
{ name: "--footer-left", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
456
|
+
_p.footer.left = _a[0];
|
|
457
|
+
} },
|
|
458
|
+
{ name: "--footer-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
459
|
+
_p.footer.line = true;
|
|
460
|
+
} },
|
|
461
|
+
{ name: "--no-footer-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
462
|
+
_p.footer.line = false;
|
|
463
|
+
} },
|
|
464
|
+
{ name: "--footer-right", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
465
|
+
_p.footer.right = _a[0];
|
|
466
|
+
} },
|
|
467
|
+
{ name: "--footer-spacing", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
468
|
+
_p.footer.spacing = float32(_a[0], false);
|
|
469
|
+
} },
|
|
470
|
+
{ name: "--footer-html", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "resource" },
|
|
471
|
+
{ name: "--header-center", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
472
|
+
_p.header.center = _a[0];
|
|
473
|
+
} },
|
|
474
|
+
{ name: "--header-font-name", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
475
|
+
_p.header.fontName = _a[0];
|
|
476
|
+
} },
|
|
477
|
+
{ name: "--header-font-size", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
478
|
+
_p.header.fontSize = integer(_a[0], 1, 2147483647);
|
|
479
|
+
} },
|
|
480
|
+
{ name: "--header-left", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
481
|
+
_p.header.left = _a[0];
|
|
482
|
+
} },
|
|
483
|
+
{ name: "--header-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
484
|
+
_p.header.line = true;
|
|
485
|
+
} },
|
|
486
|
+
{ name: "--no-header-line", short: "", scope: "page", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
487
|
+
_p.header.line = false;
|
|
488
|
+
} },
|
|
489
|
+
{ name: "--header-right", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
490
|
+
_p.header.right = _a[0];
|
|
491
|
+
} },
|
|
492
|
+
{ name: "--header-spacing", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
493
|
+
_p.header.spacing = float32(_a[0], false);
|
|
494
|
+
} },
|
|
495
|
+
{ name: "--header-html", short: "", scope: "page", arity: 1, qtPatched: true, disposition: "resource" },
|
|
496
|
+
{ name: "--replace", short: "", scope: "page", arity: 2, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
497
|
+
_p.replacements.push([_a[0], _a[1]]);
|
|
498
|
+
} },
|
|
499
|
+
{ name: "--xsl-style-sheet", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "resource" },
|
|
500
|
+
{ name: "--toc-header-text", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
501
|
+
_p.toc.captionText = _a[0];
|
|
502
|
+
} },
|
|
503
|
+
{ name: "--disable-toc-links", short: "", scope: "toc", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
504
|
+
_p.toc.forwardLinks = false;
|
|
505
|
+
} },
|
|
506
|
+
{ name: "--disable-dotted-lines", short: "", scope: "toc", arity: 0, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
507
|
+
_p.toc.useDottedLines = false;
|
|
508
|
+
} },
|
|
509
|
+
{ name: "--toc-text-size-shrink", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
510
|
+
_p.toc.fontScale = float32(_a[0], true);
|
|
511
|
+
} },
|
|
512
|
+
{ name: "--toc-level-indentation", short: "", scope: "toc", arity: 1, qtPatched: true, disposition: "static", apply: (_g, _p, _a) => {
|
|
513
|
+
_p.toc.indentation = _a[0];
|
|
514
|
+
} }
|
|
515
|
+
];
|
|
516
|
+
var switches = Object.freeze(declarations.map((entry) => Object.freeze(entry)));
|
|
517
|
+
|
|
518
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/parser.js
|
|
519
|
+
var longOptions = new Map(switches.map((entry) => [entry.name, entry]));
|
|
520
|
+
var shortOptions = new Map(switches.filter((entry) => entry.short).map((entry) => [entry.short, entry]));
|
|
521
|
+
function parseInvocation(argv, options) {
|
|
522
|
+
const budget = new ParseBudget(options);
|
|
523
|
+
budget.admitArguments(argv.length);
|
|
524
|
+
for (const arg of argv)
|
|
525
|
+
budget.admitText(arg);
|
|
526
|
+
budget.step(64);
|
|
527
|
+
const global = createGlobalSettings();
|
|
528
|
+
const defaults = createPageSettings();
|
|
529
|
+
const objects = [];
|
|
530
|
+
let index = 0;
|
|
531
|
+
let literal = false;
|
|
532
|
+
const parseOptions = (settings, scope) => {
|
|
533
|
+
if (literal)
|
|
534
|
+
return;
|
|
535
|
+
while (index < (scope === "leading" ? argv.length : argv.length - 1)) {
|
|
536
|
+
const token = argv[index];
|
|
537
|
+
if (!token.startsWith("-") || token === "-")
|
|
538
|
+
break;
|
|
539
|
+
budget.step();
|
|
540
|
+
if (token === "--" && options.endOfOptions) {
|
|
541
|
+
index++;
|
|
542
|
+
literal = true;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
if (token === "--" || token.startsWith("--0")) {
|
|
546
|
+
throw new WkhtmltopdfError("UNQUALIFIED_QUIRK", "Pinned default-mode sentinel is unqualified and not admitted", token);
|
|
547
|
+
}
|
|
548
|
+
index++;
|
|
549
|
+
const names = token.startsWith("--") ? [token] : token.slice(1);
|
|
550
|
+
for (const name of names) {
|
|
551
|
+
budget.step();
|
|
552
|
+
const entry = token.startsWith("--") ? longOptions.get(name) : shortOptions.get(name);
|
|
553
|
+
if (!entry)
|
|
554
|
+
throw new WkhtmltopdfError("UNKNOWN_OPTION", "Unknown switch", token);
|
|
555
|
+
const allowed = entry.scope === "page" || (entry.scope === "global" ? scope === "leading" : scope === "toc");
|
|
556
|
+
if (!allowed)
|
|
557
|
+
throw new WkhtmltopdfError("OPTION_LOCATION", "Switch is in an incorrect object scope", entry.name);
|
|
558
|
+
if (entry.arity > argv.length - index) {
|
|
559
|
+
throw new WkhtmltopdfError("MISSING_OPERAND", "Switch is missing an operand", entry.name);
|
|
560
|
+
}
|
|
561
|
+
if (entry.disposition !== "static") {
|
|
562
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", `Switch requires unavailable ${entry.disposition} capability`, entry.name);
|
|
563
|
+
}
|
|
564
|
+
budget.step(entry.arity + 1);
|
|
565
|
+
const operands = argv.slice(index, index + entry.arity);
|
|
566
|
+
index += entry.arity;
|
|
567
|
+
try {
|
|
568
|
+
entry.apply(global, settings, operands);
|
|
569
|
+
} catch (error) {
|
|
570
|
+
if (error instanceof WkhtmltopdfError)
|
|
571
|
+
throw new WkhtmltopdfError(error.code, error.message, entry.name);
|
|
572
|
+
throw error;
|
|
573
|
+
}
|
|
574
|
+
if (global.action)
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
};
|
|
579
|
+
parseOptions(defaults, "leading");
|
|
580
|
+
if (global.action)
|
|
581
|
+
return { mode: "information", global, pageDefaults: defaults, objects, output: null };
|
|
582
|
+
if (global.readArgsFromStdin && !options.batchJob)
|
|
583
|
+
return { mode: "batch", global, pageDefaults: defaults, objects, output: null };
|
|
584
|
+
while (index < argv.length - 1) {
|
|
585
|
+
budget.admitObject(defaults.replacements.length);
|
|
586
|
+
const settings = clonePageSettings(defaults);
|
|
587
|
+
let kind = "page";
|
|
588
|
+
const token = argv[index++];
|
|
589
|
+
let input = token;
|
|
590
|
+
if (token === "toc") {
|
|
591
|
+
kind = "toc";
|
|
592
|
+
input = null;
|
|
593
|
+
} else if (token === "cover" || token === "page") {
|
|
594
|
+
kind = token;
|
|
595
|
+
if (index >= argv.length - 1) {
|
|
596
|
+
throw new WkhtmltopdfError("MISSING_OBJECT", "Object requires an input and a final output");
|
|
597
|
+
}
|
|
598
|
+
input = argv[index++];
|
|
599
|
+
}
|
|
600
|
+
parseOptions(settings, kind === "toc" ? "toc" : "page");
|
|
601
|
+
if (kind === "cover") {
|
|
602
|
+
for (const furniture of [settings.header, settings.footer]) {
|
|
603
|
+
furniture.left = furniture.right = furniture.center = furniture.htmlUrl = "";
|
|
604
|
+
furniture.line = false;
|
|
605
|
+
}
|
|
606
|
+
settings.includeInOutline = false;
|
|
607
|
+
}
|
|
608
|
+
objects.push({ kind, input, settings });
|
|
609
|
+
}
|
|
610
|
+
if (!objects.length || index !== argv.length - 1) {
|
|
611
|
+
throw new WkhtmltopdfError("MISSING_OBJECT", "Expected at least one input object and exactly one output");
|
|
612
|
+
}
|
|
613
|
+
const margins = [global.marginTop, global.marginBottom, global.marginLeft, global.marginRight];
|
|
614
|
+
if (margins.some((margin) => margin.unit !== global.marginLeft.unit)) {
|
|
615
|
+
throw new WkhtmltopdfError("MARGIN_UNITS", "All margins must use the same normalized unit");
|
|
616
|
+
}
|
|
617
|
+
return { mode: "conversion", global, pageDefaults: defaults, objects, output: argv[index] };
|
|
618
|
+
}
|
|
619
|
+
function tokenizeBatchLine(line, options) {
|
|
620
|
+
const budget = new ParseBudget(options);
|
|
621
|
+
budget.admitText(line);
|
|
622
|
+
const tokens = [];
|
|
623
|
+
let token = "";
|
|
624
|
+
let quote = "";
|
|
625
|
+
let escaped = false;
|
|
626
|
+
const emit = () => {
|
|
627
|
+
if (!token)
|
|
628
|
+
return;
|
|
629
|
+
budget.admitArguments(tokens.length + 1);
|
|
630
|
+
tokens.push(token);
|
|
631
|
+
token = "";
|
|
632
|
+
};
|
|
633
|
+
for (const character of line) {
|
|
634
|
+
budget.step();
|
|
635
|
+
if (escaped) {
|
|
636
|
+
token += character;
|
|
637
|
+
escaped = false;
|
|
638
|
+
} else if (character === "\\")
|
|
639
|
+
escaped = true;
|
|
640
|
+
else if (quote) {
|
|
641
|
+
if (character === quote)
|
|
642
|
+
quote = "";
|
|
643
|
+
else
|
|
644
|
+
token += character;
|
|
645
|
+
} else if (character === "'" || character === '"')
|
|
646
|
+
quote = character;
|
|
647
|
+
else if (" \r\n".includes(character))
|
|
648
|
+
emit();
|
|
649
|
+
else
|
|
650
|
+
token += character;
|
|
651
|
+
}
|
|
652
|
+
emit();
|
|
653
|
+
return tokens;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/command.js
|
|
657
|
+
import { commandRuntimeIdentity, getCommandArguments } from "../safe-bash-contracts/command.js";
|
|
658
|
+
import { readBytes, writeBytes } from "../safe-bash-contracts/io.js";
|
|
659
|
+
import { shellValueByteLength } from "../safe-bash-contracts/value.js";
|
|
660
|
+
import { FsError } from "../safe-bash-contracts/errors.js";
|
|
661
|
+
import { createOutputOperation } from "../safe-bash-contracts/output.js";
|
|
662
|
+
import { basename, compareEntries, dirname, resolvePath } from "@poe-platform/safe-fs/core";
|
|
663
|
+
|
|
664
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/engine.js
|
|
665
|
+
var rendererFeatures = [
|
|
666
|
+
"html5",
|
|
667
|
+
"computed-css",
|
|
668
|
+
"selectors",
|
|
669
|
+
"css-units",
|
|
670
|
+
"block-inline",
|
|
671
|
+
"font-shaping",
|
|
672
|
+
"lists",
|
|
673
|
+
"images",
|
|
674
|
+
"table-spans",
|
|
675
|
+
"pagination",
|
|
676
|
+
"break-rules",
|
|
677
|
+
"widows-orphans",
|
|
678
|
+
"positioning",
|
|
679
|
+
"page-furniture",
|
|
680
|
+
"flex",
|
|
681
|
+
"grid"
|
|
682
|
+
];
|
|
683
|
+
function requireRendererFeatures(profile, required) {
|
|
684
|
+
if (typeof profile.id !== "string" || !profile.id || profile.id.length > 128 || profile.features.length > rendererFeatures.length || required.length > rendererFeatures.length) {
|
|
685
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected a bounded renderer profile and feature requirements");
|
|
686
|
+
}
|
|
687
|
+
for (const feature of [...profile.features, ...required]) {
|
|
688
|
+
if (!rendererFeatures.includes(feature)) {
|
|
689
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Unknown renderer feature");
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
for (const feature of required) {
|
|
693
|
+
if (!profile.features.includes(feature)) {
|
|
694
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", `Renderer profile ${profile.id} does not support ${feature}`);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
function planPageSequence(objects, options) {
|
|
699
|
+
const checkCancellation = () => {
|
|
700
|
+
if (options.signal?.aborted)
|
|
701
|
+
throw options.signal.reason;
|
|
702
|
+
};
|
|
703
|
+
checkCancellation();
|
|
704
|
+
const { maxObjects, maxPhysicalPages, maxWork } = options.limits;
|
|
705
|
+
for (const value of [maxObjects, maxPhysicalPages, maxWork, options.copies]) {
|
|
706
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
707
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Page sequence limits and copies must be positive safe integers");
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
if (typeof options.collate !== "boolean" || !Number.isInteger(options.pageOffset) || options.pageOffset < -2147483648 || options.pageOffset > 2147483647) {
|
|
711
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected boolean collate and int32 page offset");
|
|
712
|
+
}
|
|
713
|
+
if (objects.length > maxObjects || objects.length > maxWork) {
|
|
714
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Page sequence object/work limit exceeded");
|
|
715
|
+
}
|
|
716
|
+
let outlineTotal = 0;
|
|
717
|
+
let logicalTotal = 0;
|
|
718
|
+
const sourcePageLimit = Math.floor(Math.min(maxPhysicalPages, maxWork - objects.length) / options.copies);
|
|
719
|
+
for (const object of objects) {
|
|
720
|
+
checkCancellation();
|
|
721
|
+
if (!Number.isSafeInteger(object.physicalPages) || object.physicalPages < 0 || typeof object.pagesCount !== "boolean") {
|
|
722
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected a nonnegative safe page count and boolean pagesCount");
|
|
723
|
+
}
|
|
724
|
+
if (object.physicalPages > sourcePageLimit - outlineTotal) {
|
|
725
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Page sequence physical-page/work limit exceeded");
|
|
726
|
+
}
|
|
727
|
+
outlineTotal += object.physicalPages;
|
|
728
|
+
if (object.pagesCount)
|
|
729
|
+
logicalTotal += object.physicalPages;
|
|
730
|
+
}
|
|
731
|
+
if (!Number.isSafeInteger(logicalTotal + Math.abs(options.pageOffset) + 1)) {
|
|
732
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Logical page number exceeds checked precision");
|
|
733
|
+
}
|
|
734
|
+
const passes = options.collate ? options.copies : 1;
|
|
735
|
+
if (outlineTotal > 0) {
|
|
736
|
+
const remainingWork = maxWork - objects.length - outlineTotal * options.copies;
|
|
737
|
+
if (objects.length > Math.floor(remainingWork / passes)) {
|
|
738
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Page sequence repeated traversal work limit exceeded");
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const pages = [];
|
|
742
|
+
const emit = (objectIndex, pageIndex, copyIndex, logicalPage, outlinePage) => {
|
|
743
|
+
checkCancellation();
|
|
744
|
+
pages.push({ objectIndex, pageIndex, copyIndex, outputPage: pages.length + 1, logicalPage, outlinePage });
|
|
745
|
+
};
|
|
746
|
+
if (outlineTotal === 0)
|
|
747
|
+
return { pages, logicalTotal, outlineTotal };
|
|
748
|
+
for (let pass = 0; pass < passes; pass++) {
|
|
749
|
+
let logicalPage = 1 + options.pageOffset;
|
|
750
|
+
let outlinePage = 1;
|
|
751
|
+
for (let objectIndex = 0; objectIndex < objects.length; objectIndex++) {
|
|
752
|
+
checkCancellation();
|
|
753
|
+
const object = objects[objectIndex];
|
|
754
|
+
for (let pageIndex = 0; pageIndex < object.physicalPages; pageIndex++) {
|
|
755
|
+
if (options.collate)
|
|
756
|
+
emit(objectIndex, pageIndex, pass, logicalPage, outlinePage);
|
|
757
|
+
else
|
|
758
|
+
for (let copyIndex = 0; copyIndex < options.copies; copyIndex++) {
|
|
759
|
+
emit(objectIndex, pageIndex, copyIndex, logicalPage, outlinePage);
|
|
760
|
+
}
|
|
761
|
+
if (object.pagesCount)
|
|
762
|
+
logicalPage++;
|
|
763
|
+
outlinePage++;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return { pages, logicalTotal, outlineTotal };
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/outcome.js
|
|
771
|
+
var httpDescriptions = {
|
|
772
|
+
400: "Bad Request",
|
|
773
|
+
401: "Unauthorized",
|
|
774
|
+
402: "Payment Required",
|
|
775
|
+
403: "Forbidden",
|
|
776
|
+
404: "Page not found",
|
|
777
|
+
405: "Method Not Allowed",
|
|
778
|
+
500: "Internal Server Error",
|
|
779
|
+
501: "Not Implemented",
|
|
780
|
+
503: "Service Unavailable",
|
|
781
|
+
505: "HTTP Version Not Supported"
|
|
782
|
+
};
|
|
783
|
+
function conversionOutcome(completion) {
|
|
784
|
+
const { mode, success, errorCode, networkErrorName } = completion;
|
|
785
|
+
if (mode !== "single" && mode !== "batch" || typeof success !== "boolean" || !Number.isInteger(errorCode) || errorCode < 0 || errorCode > 2147483647) {
|
|
786
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected a conversion mode, boolean success and nonnegative int32 loader code");
|
|
787
|
+
}
|
|
788
|
+
if (networkErrorName !== void 0) {
|
|
789
|
+
if (typeof networkErrorName !== "string" || !networkErrorName.length || networkErrorName.length > 128) {
|
|
790
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Network enum name must contain 1\u2013128 ASCII identifier characters");
|
|
791
|
+
}
|
|
792
|
+
for (const character of networkErrorName) {
|
|
793
|
+
if (!(character >= "a" && character <= "z") && !(character >= "A" && character <= "Z") && !(character >= "0" && character <= "9") && character !== "_") {
|
|
794
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Network enum name must contain ASCII identifier characters");
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
if (mode === "batch")
|
|
799
|
+
return { exitCode: success ? 0 : 1, diagnostic: null };
|
|
800
|
+
if (errorCode >= 1e3) {
|
|
801
|
+
return { exitCode: 1, diagnostic: { kind: "network", code: errorCode - 1e3, name: networkErrorName ?? null } };
|
|
802
|
+
}
|
|
803
|
+
if (errorCode !== 0) {
|
|
804
|
+
return {
|
|
805
|
+
exitCode: errorCode === 404 ? 2 : errorCode === 401 ? 3 : 1,
|
|
806
|
+
diagnostic: { kind: "http", code: errorCode, description: httpDescriptions[errorCode] ?? "" }
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
return { exitCode: success ? 0 : 1, diagnostic: success ? null : { kind: "unknown" } };
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/resources.js
|
|
813
|
+
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
814
|
+
var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
815
|
+
var byteLengthGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
|
|
816
|
+
var byteTypeGetter = Object.getOwnPropertyDescriptor(typedArrayPrototype, Symbol.toStringTag).get;
|
|
817
|
+
var copyBytes = Uint8Array.prototype.set;
|
|
818
|
+
async function withResources(options, run) {
|
|
819
|
+
const limits = { ...options.limits };
|
|
820
|
+
for (const key of ["maxInputBytes", "maxDecodedBytes", "maxRetainedBytes", "maxWork", "maxResources"]) {
|
|
821
|
+
if (!Number.isSafeInteger(limits[key]) || limits[key] < 1) {
|
|
822
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Resource limits must be positive safe integers");
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
const { vfs, fonts, network } = options;
|
|
826
|
+
const controller = new AbortController();
|
|
827
|
+
const signal = controller.signal;
|
|
828
|
+
const sourceSignal = options.signal;
|
|
829
|
+
const abort = () => controller.abort(sourceSignal.reason);
|
|
830
|
+
sourceSignal.addEventListener("abort", abort, { once: true });
|
|
831
|
+
if (sourceSignal.aborted)
|
|
832
|
+
abort();
|
|
833
|
+
const usage = { inputBytes: 0, decodedBytes: 0, retainedBytes: 0, work: 0, resources: 0 };
|
|
834
|
+
let active = true;
|
|
835
|
+
let busy = false;
|
|
836
|
+
const pending = /* @__PURE__ */ new Set();
|
|
837
|
+
const check = () => {
|
|
838
|
+
if (signal.aborted)
|
|
839
|
+
throw signal.reason;
|
|
840
|
+
if (!active)
|
|
841
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Resource invocation has ended");
|
|
842
|
+
};
|
|
843
|
+
const charge = (key, amount, limit) => {
|
|
844
|
+
check();
|
|
845
|
+
if (amount > limit - usage[key])
|
|
846
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", `Resource ${key} limit exceeded`);
|
|
847
|
+
usage[key] += amount;
|
|
848
|
+
};
|
|
849
|
+
const work = (amount = 1) => charge("work", amount, limits.maxWork);
|
|
850
|
+
const admitText = (reference) => {
|
|
851
|
+
for (let i = 0; i < reference.length; i++) {
|
|
852
|
+
work();
|
|
853
|
+
const c = reference.charCodeAt(i);
|
|
854
|
+
let size = c < 128 ? 1 : c < 2048 ? 2 : 3;
|
|
855
|
+
if (c >= 55296 && c <= 56319 && reference.charCodeAt(i + 1) >= 56320 && reference.charCodeAt(i + 1) <= 57343) {
|
|
856
|
+
size = 4;
|
|
857
|
+
i++;
|
|
858
|
+
work();
|
|
859
|
+
}
|
|
860
|
+
charge("inputBytes", size, limits.maxInputBytes);
|
|
861
|
+
if (c === 0)
|
|
862
|
+
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)
|
|
872
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Data URL requires a comma");
|
|
873
|
+
const base64 = reference.slice(5, comma).toLowerCase().endsWith(";base64");
|
|
874
|
+
const start = comma + 1;
|
|
875
|
+
let size = 0;
|
|
876
|
+
const invalid = () => {
|
|
877
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Malformed data URL byte encoding");
|
|
878
|
+
};
|
|
879
|
+
const hex = (c) => {
|
|
880
|
+
const code = c.charCodeAt(0);
|
|
881
|
+
if (code >= 48 && code <= 57)
|
|
882
|
+
return code - 48;
|
|
883
|
+
if (code >= 65 && code <= 70)
|
|
884
|
+
return code - 55;
|
|
885
|
+
if (code >= 97 && code <= 102)
|
|
886
|
+
return code - 87;
|
|
887
|
+
return invalid();
|
|
888
|
+
};
|
|
889
|
+
if (base64) {
|
|
890
|
+
const length2 = reference.length - start;
|
|
891
|
+
if (length2 % 4 !== 0)
|
|
892
|
+
invalid();
|
|
893
|
+
for (let i = start; i < reference.length; i += 4) {
|
|
894
|
+
work(4);
|
|
895
|
+
const a = alphabet.indexOf(reference[i]);
|
|
896
|
+
const b = alphabet.indexOf(reference[i + 1]);
|
|
897
|
+
const c = alphabet.indexOf(reference[i + 2]);
|
|
898
|
+
const d = alphabet.indexOf(reference[i + 3]);
|
|
899
|
+
if (a < 0 || b < 0)
|
|
900
|
+
invalid();
|
|
901
|
+
if (reference[i + 2] === "=") {
|
|
902
|
+
if (reference[i + 3] !== "=" || i + 4 !== reference.length || (b & 15) !== 0)
|
|
903
|
+
invalid();
|
|
904
|
+
size++;
|
|
905
|
+
} else if (reference[i + 3] === "=") {
|
|
906
|
+
if (c < 0 || i + 4 !== reference.length || (c & 3) !== 0)
|
|
907
|
+
invalid();
|
|
908
|
+
size += 2;
|
|
909
|
+
} else {
|
|
910
|
+
if (c < 0 || d < 0)
|
|
911
|
+
invalid();
|
|
912
|
+
size += 3;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
} else {
|
|
916
|
+
for (let i = start; i < reference.length; i++) {
|
|
917
|
+
work();
|
|
918
|
+
const code = reference.charCodeAt(i);
|
|
919
|
+
if (code > 127 || code <= 32)
|
|
920
|
+
invalid();
|
|
921
|
+
if (reference[i] === "%") {
|
|
922
|
+
if (i + 2 >= reference.length)
|
|
923
|
+
invalid();
|
|
924
|
+
hex(reference[i + 1]);
|
|
925
|
+
hex(reference[i + 2]);
|
|
926
|
+
i += 2;
|
|
927
|
+
work(2);
|
|
928
|
+
}
|
|
929
|
+
size++;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
work(size);
|
|
933
|
+
retain(size);
|
|
934
|
+
const result = new Uint8Array(size);
|
|
935
|
+
let offset = 0;
|
|
936
|
+
if (base64) {
|
|
937
|
+
for (let i = start; i < reference.length; i += 4) {
|
|
938
|
+
const a = alphabet.indexOf(reference[i]);
|
|
939
|
+
const b = alphabet.indexOf(reference[i + 1]);
|
|
940
|
+
const c = alphabet.indexOf(reference[i + 2]);
|
|
941
|
+
const d = alphabet.indexOf(reference[i + 3]);
|
|
942
|
+
result[offset++] = a << 2 | b >> 4;
|
|
943
|
+
if (c >= 0)
|
|
944
|
+
result[offset++] = b << 4 | c >> 2;
|
|
945
|
+
if (d >= 0)
|
|
946
|
+
result[offset++] = c << 6 | d;
|
|
947
|
+
}
|
|
948
|
+
} else {
|
|
949
|
+
for (let i = start; i < reference.length; i++) {
|
|
950
|
+
result[offset++] = reference[i] === "%" ? hex(reference[++i]) << 4 | hex(reference[++i]) : reference.charCodeAt(i);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return result;
|
|
954
|
+
};
|
|
955
|
+
const read = async (reference, open) => {
|
|
956
|
+
const lease = await open(reference, signal);
|
|
957
|
+
let temporary = 0;
|
|
958
|
+
const chunks = [];
|
|
959
|
+
let primary = false;
|
|
960
|
+
let failure;
|
|
961
|
+
let result;
|
|
962
|
+
try {
|
|
963
|
+
check();
|
|
964
|
+
const iterator = lease.chunks[Symbol.asyncIterator]();
|
|
965
|
+
for (; ; ) {
|
|
966
|
+
work();
|
|
967
|
+
let abortRead;
|
|
968
|
+
let next;
|
|
969
|
+
try {
|
|
970
|
+
next = await new Promise((resolve, reject) => {
|
|
971
|
+
abortRead = () => reject(signal.reason);
|
|
972
|
+
signal.addEventListener("abort", abortRead, { once: true });
|
|
973
|
+
if (signal.aborted)
|
|
974
|
+
abortRead();
|
|
975
|
+
Promise.resolve().then(() => {
|
|
976
|
+
check();
|
|
977
|
+
return iterator.next();
|
|
978
|
+
}).then(resolve, reject);
|
|
979
|
+
});
|
|
980
|
+
} finally {
|
|
981
|
+
if (abortRead)
|
|
982
|
+
signal.removeEventListener("abort", abortRead);
|
|
983
|
+
}
|
|
984
|
+
check();
|
|
985
|
+
if (next.done)
|
|
986
|
+
break;
|
|
987
|
+
if (byteTypeGetter.call(next.value) !== "Uint8Array") {
|
|
988
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Expected resource byte chunks");
|
|
989
|
+
}
|
|
990
|
+
const size = byteLengthGetter.call(next.value);
|
|
991
|
+
charge("inputBytes", size, limits.maxInputBytes);
|
|
992
|
+
work(size);
|
|
993
|
+
retain(size);
|
|
994
|
+
temporary += size;
|
|
995
|
+
if (size) {
|
|
996
|
+
const chunk = new Uint8Array(size);
|
|
997
|
+
copyBytes.call(chunk, next.value);
|
|
998
|
+
chunks.push(chunk);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
work(temporary);
|
|
1002
|
+
charge("retainedBytes", temporary, limits.maxRetainedBytes);
|
|
1003
|
+
result = new Uint8Array(temporary);
|
|
1004
|
+
let offset = 0;
|
|
1005
|
+
for (const chunk of chunks) {
|
|
1006
|
+
result.set(chunk, offset);
|
|
1007
|
+
offset += chunk.length;
|
|
1008
|
+
}
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
primary = true;
|
|
1011
|
+
failure = error;
|
|
1012
|
+
} finally {
|
|
1013
|
+
usage.retainedBytes -= temporary;
|
|
1014
|
+
try {
|
|
1015
|
+
await lease.close();
|
|
1016
|
+
check();
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
if (!primary) {
|
|
1019
|
+
primary = true;
|
|
1020
|
+
failure = error;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
if (primary) {
|
|
1025
|
+
if (result)
|
|
1026
|
+
usage.retainedBytes -= result.byteLength;
|
|
1027
|
+
throw failure;
|
|
1028
|
+
}
|
|
1029
|
+
return result;
|
|
1030
|
+
};
|
|
1031
|
+
const load = (reference, font, base) => {
|
|
1032
|
+
const operation = (async () => {
|
|
1033
|
+
check();
|
|
1034
|
+
if (busy)
|
|
1035
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Resource reads must be sequential");
|
|
1036
|
+
busy = true;
|
|
1037
|
+
try {
|
|
1038
|
+
charge("resources", 1, limits.maxResources);
|
|
1039
|
+
admitText(reference);
|
|
1040
|
+
if (base !== void 0) {
|
|
1041
|
+
admitText(base);
|
|
1042
|
+
try {
|
|
1043
|
+
reference = new URL(reference, base).href;
|
|
1044
|
+
} catch {
|
|
1045
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Invalid resource URL or base");
|
|
1046
|
+
}
|
|
1047
|
+
admitText(reference);
|
|
1048
|
+
}
|
|
1049
|
+
if (!font) {
|
|
1050
|
+
work(reference.length);
|
|
1051
|
+
const fragment = reference.indexOf("#");
|
|
1052
|
+
if (fragment >= 0)
|
|
1053
|
+
reference = reference.slice(0, fragment);
|
|
1054
|
+
}
|
|
1055
|
+
if (!font && reference.startsWith("data:"))
|
|
1056
|
+
return data(reference);
|
|
1057
|
+
const open = font ? fonts : reference.startsWith("vfs:") ? vfs : reference.startsWith("https:") || reference.startsWith("http:") ? network : void 0;
|
|
1058
|
+
if (!open)
|
|
1059
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Resource requires an explicitly supplied capability");
|
|
1060
|
+
return await read(reference, open);
|
|
1061
|
+
} finally {
|
|
1062
|
+
busy = false;
|
|
1063
|
+
}
|
|
1064
|
+
})();
|
|
1065
|
+
pending.add(operation);
|
|
1066
|
+
void operation.then(() => pending.delete(operation), () => pending.delete(operation));
|
|
1067
|
+
return operation;
|
|
1068
|
+
};
|
|
1069
|
+
try {
|
|
1070
|
+
check();
|
|
1071
|
+
const result = await run({ load: (reference, base) => load(reference, false, base), font: (name) => load(name, true), get usage() {
|
|
1072
|
+
return { ...usage };
|
|
1073
|
+
} });
|
|
1074
|
+
check();
|
|
1075
|
+
if (pending.size)
|
|
1076
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Resource reads must finish before the invocation ends");
|
|
1077
|
+
return result;
|
|
1078
|
+
} finally {
|
|
1079
|
+
active = false;
|
|
1080
|
+
controller.abort(new WkhtmltopdfError("INVALID_VALUE", "Resource invocation has ended"));
|
|
1081
|
+
await Promise.allSettled(pending);
|
|
1082
|
+
sourceSignal.removeEventListener("abort", abort);
|
|
1083
|
+
usage.retainedBytes = 0;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// packages/safe-bash-command-wkhtmltopdf/dist/command.js
|
|
1088
|
+
var wkhtmltopdfLimits = Object.freeze({
|
|
1089
|
+
parse: Object.freeze({ maxArguments: 1024, maxTextBytes: 65536, maxObjects: 64, maxWork: 1048576 }),
|
|
1090
|
+
resources: Object.freeze({ maxInputBytes: 16777216, maxDecodedBytes: 16777216, maxRetainedBytes: 33554432, maxWork: 67108864, maxResources: 128 }),
|
|
1091
|
+
maxOutputBytes: 16777216,
|
|
1092
|
+
maxOutputChunks: 65536,
|
|
1093
|
+
maxBatchJobs: 128
|
|
1094
|
+
});
|
|
1095
|
+
var encoder = new TextEncoder();
|
|
1096
|
+
var decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
1097
|
+
var typedArrayPrototype2 = Object.getPrototypeOf(Uint8Array.prototype);
|
|
1098
|
+
var byteType = Object.getOwnPropertyDescriptor(typedArrayPrototype2, Symbol.toStringTag).get;
|
|
1099
|
+
var byteLength = Object.getOwnPropertyDescriptor(typedArrayPrototype2, "byteLength").get;
|
|
1100
|
+
async function runWkhtmltopdf(context, options) {
|
|
1101
|
+
context.signal.throwIfAborted();
|
|
1102
|
+
const controller = new AbortController();
|
|
1103
|
+
const signal = controller.signal;
|
|
1104
|
+
let opening;
|
|
1105
|
+
let closing;
|
|
1106
|
+
let cleanupPromise;
|
|
1107
|
+
let resourceRun;
|
|
1108
|
+
let stdout;
|
|
1109
|
+
let stderr;
|
|
1110
|
+
const retire = () => {
|
|
1111
|
+
if (!opening)
|
|
1112
|
+
return Promise.resolve();
|
|
1113
|
+
closing ??= opening.then((document) => document.close(), () => {
|
|
1114
|
+
});
|
|
1115
|
+
return closing;
|
|
1116
|
+
};
|
|
1117
|
+
const onAbort = () => controller.abort(context.signal.reason);
|
|
1118
|
+
const cleanup = () => {
|
|
1119
|
+
cleanupPromise ??= (async () => {
|
|
1120
|
+
controller.abort(new WkhtmltopdfError("INVALID_VALUE", "Invocation has ended"));
|
|
1121
|
+
context.signal.removeEventListener("abort", onAbort);
|
|
1122
|
+
const drained = await Promise.allSettled([
|
|
1123
|
+
retire(),
|
|
1124
|
+
resourceRun?.then(() => {
|
|
1125
|
+
}, () => {
|
|
1126
|
+
}),
|
|
1127
|
+
stdout?.close(),
|
|
1128
|
+
stderr?.close()
|
|
1129
|
+
]);
|
|
1130
|
+
const failures = drained.filter((value) => value.status === "rejected").map((value) => value.reason);
|
|
1131
|
+
if (failures.length)
|
|
1132
|
+
throw new AggregateError(failures, "Invocation cleanup failed");
|
|
1133
|
+
})();
|
|
1134
|
+
return cleanupPromise;
|
|
1135
|
+
};
|
|
1136
|
+
context.registerCleanup?.(cleanup);
|
|
1137
|
+
let primary = false;
|
|
1138
|
+
let failure;
|
|
1139
|
+
let result;
|
|
1140
|
+
try {
|
|
1141
|
+
context.signal.addEventListener("abort", onAbort, { once: true });
|
|
1142
|
+
if (context.signal.aborted)
|
|
1143
|
+
onAbort();
|
|
1144
|
+
signal.throwIfAborted();
|
|
1145
|
+
stdout = createOutputOperation({ signal, registerCleanup: (callback) => context.registerCleanup?.(callback) }, context.stdout);
|
|
1146
|
+
stderr = createOutputOperation({ signal, registerCleanup: (callback) => context.registerCleanup?.(callback) }, context.stderr);
|
|
1147
|
+
const limits = Object.freeze({
|
|
1148
|
+
...options.limits,
|
|
1149
|
+
parse: Object.freeze({ ...options.limits.parse }),
|
|
1150
|
+
resources: Object.freeze({ ...options.limits.resources })
|
|
1151
|
+
});
|
|
1152
|
+
for (const value of [limits.maxOutputBytes, limits.maxOutputChunks, limits.maxBatchJobs]) {
|
|
1153
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
1154
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Command limits must be positive safe integers");
|
|
1155
|
+
}
|
|
1156
|
+
for (const key of ["maxInputBytes", "maxDecodedBytes", "maxRetainedBytes", "maxWork", "maxResources"]) {
|
|
1157
|
+
if (!Number.isSafeInteger(limits.resources[key]) || limits.resources[key] < 1) {
|
|
1158
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Resource limits must be positive safe integers");
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
const admission = new ParseBudget({ limits: limits.parse, signal });
|
|
1162
|
+
admission.admitArguments(context.args.length);
|
|
1163
|
+
for (const arg of context.args)
|
|
1164
|
+
admission.admitText(arg);
|
|
1165
|
+
const carrier = context.argumentValues === void 0 ? void 0 : getCommandArguments(context);
|
|
1166
|
+
const argv = [];
|
|
1167
|
+
let argumentBytes = 0;
|
|
1168
|
+
for (let index = 0; index < context.args.length; index++) {
|
|
1169
|
+
signal.throwIfAborted();
|
|
1170
|
+
if (carrier === void 0 || typeof carrier.values[index] === "string") {
|
|
1171
|
+
argv.push(context.args[index]);
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
const bytes = carrier.bytes(index);
|
|
1175
|
+
if (bytes.byteLength > limits.parse.maxTextBytes - argumentBytes)
|
|
1176
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "CLI argument byte limit exceeded");
|
|
1177
|
+
argumentBytes += bytes.byteLength;
|
|
1178
|
+
try {
|
|
1179
|
+
argv.push(decoder.decode(bytes));
|
|
1180
|
+
} catch {
|
|
1181
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "CLI arguments must be valid UTF-8");
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
const parse = (args, batchJob = false) => parseInvocation(args, { limits: limits.parse, signal, endOfOptions: true, batchJob });
|
|
1185
|
+
const initial = parse(argv);
|
|
1186
|
+
if (initial.mode === "information") {
|
|
1187
|
+
let text;
|
|
1188
|
+
if (initial.global.action === "help" || initial.global.action === "extended-help") {
|
|
1189
|
+
text = "Usage: wkhtmltopdf [options] [page|cover input|toc]... output\nStatic first-party renderer requires an explicit binding. Input/output '-' use stdin/stdout.\n";
|
|
1190
|
+
} else if (initial.global.action === "version") {
|
|
1191
|
+
text = "wkhtmltopdf safe static adapter (source 024b2b2bb459dd904d15b911d04c6df4ff2c9031; Qt compatibility unqualified)\n";
|
|
1192
|
+
} else
|
|
1193
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Information action is unavailable in the static profile", initial.global.action);
|
|
1194
|
+
if (shellValueByteLength(text) > limits.maxOutputBytes) {
|
|
1195
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Information output byte limit exceeded");
|
|
1196
|
+
}
|
|
1197
|
+
await writeBytes(stdout.output, encoder.encode(text), signal);
|
|
1198
|
+
result = { kind: "information", exitCode: 0 };
|
|
1199
|
+
} else {
|
|
1200
|
+
const renderer = options.renderer;
|
|
1201
|
+
if (!renderer)
|
|
1202
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "A qualified first-party static renderer binding is required");
|
|
1203
|
+
requireRendererFeatures(renderer.profile, []);
|
|
1204
|
+
let outputBytes = 0;
|
|
1205
|
+
let outputChunks = 0;
|
|
1206
|
+
let jobs = 0;
|
|
1207
|
+
let inputBytes = 0;
|
|
1208
|
+
let currentInputs = [];
|
|
1209
|
+
let produced;
|
|
1210
|
+
resourceRun = Promise.resolve().then(() => withResources({
|
|
1211
|
+
limits: limits.resources,
|
|
1212
|
+
signal,
|
|
1213
|
+
vfs: async (reference, readSignal) => {
|
|
1214
|
+
if (reference === "vfs:output") {
|
|
1215
|
+
if (!produced)
|
|
1216
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "No renderer output is active");
|
|
1217
|
+
const document = produced;
|
|
1218
|
+
return {
|
|
1219
|
+
chunks: (async function* () {
|
|
1220
|
+
for await (const chunk of document.chunks) {
|
|
1221
|
+
readSignal.throwIfAborted();
|
|
1222
|
+
if (byteType.call(chunk) !== "Uint8Array")
|
|
1223
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Renderer must produce byte chunks");
|
|
1224
|
+
const length2 = byteLength.call(chunk);
|
|
1225
|
+
if (++outputChunks > limits.maxOutputChunks || length2 > limits.maxOutputBytes - outputBytes) {
|
|
1226
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "PDF output stage limit exceeded");
|
|
1227
|
+
}
|
|
1228
|
+
outputBytes += length2;
|
|
1229
|
+
yield chunk;
|
|
1230
|
+
}
|
|
1231
|
+
})(),
|
|
1232
|
+
close: retire
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
const index = Number(reference.slice("vfs:input/".length));
|
|
1236
|
+
const input = currentInputs[index];
|
|
1237
|
+
if (input === void 0)
|
|
1238
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Unknown invocation input identity");
|
|
1239
|
+
if (input === "-")
|
|
1240
|
+
return {
|
|
1241
|
+
chunks: (async function* () {
|
|
1242
|
+
for await (const chunk of readBytes(context.stdin, readSignal)) {
|
|
1243
|
+
inputBytes += byteLength.call(chunk);
|
|
1244
|
+
context.inputBudget?.check(inputBytes);
|
|
1245
|
+
yield chunk;
|
|
1246
|
+
}
|
|
1247
|
+
})(),
|
|
1248
|
+
async close() {
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
if (!context.fs.openReadFile)
|
|
1252
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "VFS requires bounded read handles");
|
|
1253
|
+
const handle = await context.fs.openReadFile(resolvePath(context.cwd, input), { signal: readSignal });
|
|
1254
|
+
let position = 0;
|
|
1255
|
+
return {
|
|
1256
|
+
chunks: (async function* () {
|
|
1257
|
+
for (; ; ) {
|
|
1258
|
+
readSignal.throwIfAborted();
|
|
1259
|
+
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 });
|
|
1260
|
+
if (byteType.call(chunk) !== "Uint8Array")
|
|
1261
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "VFS must produce byte chunks");
|
|
1262
|
+
const length2 = byteLength.call(chunk);
|
|
1263
|
+
if (!length2)
|
|
1264
|
+
return;
|
|
1265
|
+
inputBytes += length2;
|
|
1266
|
+
context.inputBudget?.check(inputBytes);
|
|
1267
|
+
position += length2;
|
|
1268
|
+
yield chunk;
|
|
1269
|
+
}
|
|
1270
|
+
})(),
|
|
1271
|
+
close: () => handle.close()
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
}, async (resources) => {
|
|
1275
|
+
const convert = async (job, batch) => {
|
|
1276
|
+
if (++jobs > limits.maxBatchJobs)
|
|
1277
|
+
throw new WkhtmltopdfError("LIMIT_EXCEEDED", "Batch job limit exceeded");
|
|
1278
|
+
currentInputs = job.objects.map((object) => {
|
|
1279
|
+
if (object.input === null)
|
|
1280
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "TOC requires a qualified outline/XSLT engine");
|
|
1281
|
+
if (batch && object.input === "-")
|
|
1282
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Batch conversion cannot share stdin with HTML input");
|
|
1283
|
+
return object.input;
|
|
1284
|
+
});
|
|
1285
|
+
let destination;
|
|
1286
|
+
if (job.output !== "-") {
|
|
1287
|
+
if (!context.fs.writeFileConditional) {
|
|
1288
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "VFS requires conditional file publication");
|
|
1289
|
+
}
|
|
1290
|
+
const requested = resolvePath(context.cwd, job.output);
|
|
1291
|
+
const parentPath = await context.fs.realpath(dirname(requested), { signal });
|
|
1292
|
+
const path = resolvePath(parentPath, basename(requested));
|
|
1293
|
+
const parent = await context.fs.stat(parentPath, { signal });
|
|
1294
|
+
let expected = null;
|
|
1295
|
+
try {
|
|
1296
|
+
expected = await context.fs.lstat(path, { signal });
|
|
1297
|
+
} catch (error) {
|
|
1298
|
+
if (!(error instanceof FsError && error.code === "ENOENT"))
|
|
1299
|
+
throw error;
|
|
1300
|
+
}
|
|
1301
|
+
if (expected !== null && expected.type !== "file") {
|
|
1302
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Output must be a regular VFS file or absent");
|
|
1303
|
+
}
|
|
1304
|
+
for (let index = 0; index < currentInputs.length; index++) {
|
|
1305
|
+
const input = currentInputs[index];
|
|
1306
|
+
if (input === "-")
|
|
1307
|
+
continue;
|
|
1308
|
+
const source = await context.fs.realpath(resolvePath(context.cwd, input), { signal });
|
|
1309
|
+
currentInputs[index] = source;
|
|
1310
|
+
if (source === path || expected !== null && await compareEntries(context.fs, source, context.fs, path, { signal }) !== "distinct") {
|
|
1311
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Input and output VFS identities must be distinct");
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
destination = { path, condition: { parent, expected, signal } };
|
|
1315
|
+
}
|
|
1316
|
+
const inputs = [];
|
|
1317
|
+
for (let index = 0; index < currentInputs.length; index++)
|
|
1318
|
+
inputs.push(await resources.load("vfs:input/" + index));
|
|
1319
|
+
signal.throwIfAborted();
|
|
1320
|
+
opening = Promise.resolve().then(() => {
|
|
1321
|
+
signal.throwIfAborted();
|
|
1322
|
+
return renderer.open({ job, inputs, signal, limits });
|
|
1323
|
+
});
|
|
1324
|
+
closing = void 0;
|
|
1325
|
+
const document = await opening;
|
|
1326
|
+
produced = document;
|
|
1327
|
+
signal.throwIfAborted();
|
|
1328
|
+
const outcome2 = conversionOutcome({
|
|
1329
|
+
mode: batch ? "batch" : "single",
|
|
1330
|
+
success: document.success,
|
|
1331
|
+
errorCode: document.errorCode,
|
|
1332
|
+
...document.networkErrorName === void 0 ? {} : { networkErrorName: document.networkErrorName }
|
|
1333
|
+
});
|
|
1334
|
+
let pdf;
|
|
1335
|
+
if (outcome2.exitCode === 0) {
|
|
1336
|
+
pdf = await resources.load("vfs:output");
|
|
1337
|
+
}
|
|
1338
|
+
await retire();
|
|
1339
|
+
opening = void 0;
|
|
1340
|
+
closing = void 0;
|
|
1341
|
+
produced = void 0;
|
|
1342
|
+
signal.throwIfAborted();
|
|
1343
|
+
if (outcome2.exitCode === 0) {
|
|
1344
|
+
if (job.output === "-")
|
|
1345
|
+
await writeBytes(stdout.output, pdf, signal);
|
|
1346
|
+
else
|
|
1347
|
+
await context.fs.writeFileConditional(destination.path, pdf, destination.condition);
|
|
1348
|
+
} else
|
|
1349
|
+
await diagnostic({ ...context, stderr: stderr.output }, outcome2, signal);
|
|
1350
|
+
return outcome2;
|
|
1351
|
+
};
|
|
1352
|
+
let outcome = { exitCode: 0, diagnostic: null };
|
|
1353
|
+
if (initial.mode === "batch") {
|
|
1354
|
+
currentInputs = ["-"];
|
|
1355
|
+
const bytes = await resources.load("vfs:input/0");
|
|
1356
|
+
let text;
|
|
1357
|
+
try {
|
|
1358
|
+
text = decoder.decode(bytes);
|
|
1359
|
+
} catch {
|
|
1360
|
+
throw new WkhtmltopdfError("INVALID_VALUE", "Batch input must be valid UTF-8");
|
|
1361
|
+
}
|
|
1362
|
+
let start = 0;
|
|
1363
|
+
for (let end = 0; end <= text.length; end++) {
|
|
1364
|
+
signal.throwIfAborted();
|
|
1365
|
+
if (end !== text.length && text[end] !== "\n")
|
|
1366
|
+
continue;
|
|
1367
|
+
if (end === text.length && start === end)
|
|
1368
|
+
break;
|
|
1369
|
+
const args = tokenizeBatchLine(text.slice(start, end), { limits: limits.parse, signal });
|
|
1370
|
+
const job = parse([...argv, ...args], true);
|
|
1371
|
+
if (job.mode !== "conversion")
|
|
1372
|
+
throw new WkhtmltopdfError("UNSUPPORTED_CAPABILITY", "Batch lines must describe conversion jobs");
|
|
1373
|
+
outcome = await convert(job, true);
|
|
1374
|
+
if (outcome.exitCode !== 0)
|
|
1375
|
+
break;
|
|
1376
|
+
start = end + 1;
|
|
1377
|
+
}
|
|
1378
|
+
} else
|
|
1379
|
+
outcome = await convert(initial, false);
|
|
1380
|
+
return { kind: "conversion", exitCode: outcome.exitCode, jobs, outcome, usage: resources.usage };
|
|
1381
|
+
}));
|
|
1382
|
+
result = await resourceRun;
|
|
1383
|
+
}
|
|
1384
|
+
} catch (error) {
|
|
1385
|
+
if (context.signal.aborted) {
|
|
1386
|
+
primary = true;
|
|
1387
|
+
failure = context.signal.reason;
|
|
1388
|
+
} else if (signal.aborted) {
|
|
1389
|
+
primary = true;
|
|
1390
|
+
failure = signal.reason;
|
|
1391
|
+
} else if (error instanceof WkhtmltopdfError || error instanceof FsError) {
|
|
1392
|
+
try {
|
|
1393
|
+
const option = error instanceof WkhtmltopdfError ? error.option : void 0;
|
|
1394
|
+
await writeBytes(stderr.output, encoder.encode(`wkhtmltopdf: ${error.code}${option ? ` (${option})` : ""}: ${error.message}
|
|
1395
|
+
`), signal);
|
|
1396
|
+
result = { kind: "rejected", exitCode: 1, code: error.code };
|
|
1397
|
+
} catch (writeError) {
|
|
1398
|
+
primary = true;
|
|
1399
|
+
failure = writeError;
|
|
1400
|
+
}
|
|
1401
|
+
} else {
|
|
1402
|
+
primary = true;
|
|
1403
|
+
failure = error;
|
|
1404
|
+
}
|
|
1405
|
+
} finally {
|
|
1406
|
+
try {
|
|
1407
|
+
await cleanup();
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
if (primary)
|
|
1410
|
+
failure = new AggregateError([failure, error], "Invocation and cleanup failed");
|
|
1411
|
+
else {
|
|
1412
|
+
primary = true;
|
|
1413
|
+
failure = error;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
if (primary)
|
|
1418
|
+
throw failure;
|
|
1419
|
+
return result;
|
|
1420
|
+
}
|
|
1421
|
+
async function diagnostic(context, outcome, signal) {
|
|
1422
|
+
const value = outcome.diagnostic;
|
|
1423
|
+
if (!value)
|
|
1424
|
+
return;
|
|
1425
|
+
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.";
|
|
1426
|
+
await writeBytes(context.stderr, encoder.encode(message + "\n"), signal);
|
|
1427
|
+
}
|
|
1428
|
+
function createWkhtmltopdfCommand(options = { limits: wkhtmltopdfLimits }) {
|
|
1429
|
+
return Object.freeze({
|
|
1430
|
+
name: "wkhtmltopdf",
|
|
1431
|
+
runtimeIdentity: commandRuntimeIdentity,
|
|
1432
|
+
description: "Bounded static HTML-to-PDF adapter with an explicit first-party renderer",
|
|
1433
|
+
execute: (context) => runWkhtmltopdf(context, options)
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
var wkhtmltopdfCommand = createWkhtmltopdfCommand();
|
|
1437
|
+
function wkhtmltopdfCommands(options = { limits: wkhtmltopdfLimits }) {
|
|
1438
|
+
const command = createWkhtmltopdfCommand(options);
|
|
1439
|
+
return { name: "wkhtmltopdf-commands", setup(host) {
|
|
1440
|
+
host.commands.register(command);
|
|
1441
|
+
} };
|
|
1442
|
+
}
|
|
1443
|
+
export {
|
|
1444
|
+
WkhtmltopdfError,
|
|
1445
|
+
conversionOutcome,
|
|
1446
|
+
createWkhtmltopdfCommand,
|
|
1447
|
+
parseInvocation,
|
|
1448
|
+
planPageSequence,
|
|
1449
|
+
requireRendererFeatures,
|
|
1450
|
+
runWkhtmltopdf,
|
|
1451
|
+
switches,
|
|
1452
|
+
tokenizeBatchLine,
|
|
1453
|
+
withResources,
|
|
1454
|
+
wkhtmltopdfCommand,
|
|
1455
|
+
wkhtmltopdfCommands,
|
|
1456
|
+
wkhtmltopdfLimits
|
|
1457
|
+
};
|
|
1458
|
+
//# sourceMappingURL=index.js.map
|