@vivliostyle/cli 10.2.1 → 10.3.1
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 +7 -4
- package/dist/{chunk-CKXFRCPH.js → chunk-7GIJVX4M.js} +143 -11
- package/dist/chunk-7GIJVX4M.js.map +1 -0
- package/dist/{chunk-BR2V7MHE.js → chunk-C4HQHRXQ.js} +227 -58
- package/dist/chunk-C4HQHRXQ.js.map +1 -0
- package/dist/{chunk-T2VWLU2I.js → chunk-DBK27BAR.js} +22 -13
- package/dist/chunk-DBK27BAR.js.map +1 -0
- package/dist/{chunk-E6QVHS6D.js → chunk-ECEGM36O.js} +2 -1
- package/dist/chunk-ECEGM36O.js.map +1 -0
- package/dist/{chunk-5MEUINC4.js → chunk-ERDN47XG.js} +524 -52
- package/dist/chunk-ERDN47XG.js.map +1 -0
- package/dist/{chunk-37OLZSNI.js → chunk-LGOHUEEQ.js} +5 -5
- package/dist/{chunk-62AC6XGJ.js → chunk-LWMSAGHL.js} +4 -4
- package/dist/{chunk-XMCTTVR7.js → chunk-MU7JCDMK.js} +2 -2
- package/dist/{chunk-ZEBXHUJX.js → chunk-OAFXM4ES.js} +4 -4
- package/dist/chunk-OAFXM4ES.js.map +1 -0
- package/dist/{chunk-O3CBPX4R.js → chunk-PYPAYBFL.js} +170 -112
- package/dist/chunk-PYPAYBFL.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/commands/build.js +15 -9
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.js +11 -5
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/init.js +4 -4
- package/dist/commands/preview.js +14 -8
- package/dist/commands/preview.js.map +1 -1
- package/dist/config/schema.d.ts +21152 -21165
- package/dist/config/schema.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -11
- package/dist/index.js.map +1 -1
- package/dist/node-modules.d.ts +3 -1
- package/dist/node-modules.js +1 -1
- package/dist/vite-adapter.js +6 -6
- package/package.json +5 -4
- package/dist/chunk-5MEUINC4.js.map +0 -1
- package/dist/chunk-BR2V7MHE.js.map +0 -1
- package/dist/chunk-CKXFRCPH.js.map +0 -1
- package/dist/chunk-E6QVHS6D.js.map +0 -1
- package/dist/chunk-O3CBPX4R.js.map +0 -1
- package/dist/chunk-T2VWLU2I.js.map +0 -1
- package/dist/chunk-ZEBXHUJX.js.map +0 -1
- /package/dist/{chunk-37OLZSNI.js.map → chunk-LGOHUEEQ.js.map} +0 -0
- /package/dist/{chunk-62AC6XGJ.js.map → chunk-LWMSAGHL.js.map} +0 -0
- /package/dist/{chunk-XMCTTVR7.js.map → chunk-MU7JCDMK.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveViteConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MU7JCDMK.js";
|
|
4
4
|
import {
|
|
5
5
|
buildWebPublication,
|
|
6
6
|
cleanupWorkspace,
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
prepareThemeDirectory,
|
|
17
17
|
resolveTaskConfig,
|
|
18
18
|
warnDeprecatedConfig
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-C4HQHRXQ.js";
|
|
20
20
|
import {
|
|
21
21
|
importNodeModule
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ECEGM36O.js";
|
|
23
23
|
import {
|
|
24
24
|
Logger,
|
|
25
25
|
copyAssets,
|
|
@@ -32,12 +32,12 @@ import {
|
|
|
32
32
|
randomBookSymbol,
|
|
33
33
|
runExitHandlers,
|
|
34
34
|
setupConfigFromFlags
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-DBK27BAR.js";
|
|
36
36
|
import {
|
|
37
37
|
CONTAINER_LOCAL_HOSTNAME,
|
|
38
38
|
CONTAINER_ROOT_DIR,
|
|
39
39
|
coreVersion
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-OAFXM4ES.js";
|
|
41
41
|
import {
|
|
42
42
|
__callDispose,
|
|
43
43
|
__using
|
|
@@ -187,7 +187,7 @@ async function buildPDFWithContainer({
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
// src/output/pdf.ts
|
|
190
|
-
import
|
|
190
|
+
import fs3 from "node:fs";
|
|
191
191
|
import { URL as URL2 } from "node:url";
|
|
192
192
|
import terminalLink from "terminal-link";
|
|
193
193
|
import upath3 from "upath";
|
|
@@ -195,10 +195,435 @@ import { cyan, gray, green, red } from "yoctocolors";
|
|
|
195
195
|
|
|
196
196
|
// src/output/pdf-postprocess.ts
|
|
197
197
|
import decamelize from "decamelize";
|
|
198
|
-
import
|
|
198
|
+
import fs2 from "node:fs";
|
|
199
199
|
import os from "node:os";
|
|
200
200
|
import upath2 from "upath";
|
|
201
201
|
import { v1 as uuid } from "uuid";
|
|
202
|
+
|
|
203
|
+
// src/output/pdf-stream.ts
|
|
204
|
+
var SRGB_MAX = 1e4;
|
|
205
|
+
var CMYK_MAX = 1e4;
|
|
206
|
+
function* tokenize(content) {
|
|
207
|
+
let i = 0;
|
|
208
|
+
const len = content.length;
|
|
209
|
+
while (i < len) {
|
|
210
|
+
while (i < len && /\s/.test(content[i])) i++;
|
|
211
|
+
if (i >= len) break;
|
|
212
|
+
const c = content[i];
|
|
213
|
+
if (c === "%") {
|
|
214
|
+
const start = i;
|
|
215
|
+
while (i < len && content[i] !== "\n" && content[i] !== "\r") i++;
|
|
216
|
+
yield { type: "other", raw: content.slice(start, i) };
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (c === "(") {
|
|
220
|
+
let depth = 1;
|
|
221
|
+
let str = "(";
|
|
222
|
+
i++;
|
|
223
|
+
while (i < len && depth > 0) {
|
|
224
|
+
if (content[i] === "\\" && i + 1 < len) {
|
|
225
|
+
str += content[i] + content[i + 1];
|
|
226
|
+
i += 2;
|
|
227
|
+
} else {
|
|
228
|
+
if (content[i] === "(") depth++;
|
|
229
|
+
else if (content[i] === ")") depth--;
|
|
230
|
+
str += content[i];
|
|
231
|
+
i++;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
yield { type: "other", raw: str };
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (c === "<" && content[i + 1] !== "<") {
|
|
238
|
+
let str = "<";
|
|
239
|
+
i++;
|
|
240
|
+
while (i < len && content[i] !== ">") {
|
|
241
|
+
str += content[i];
|
|
242
|
+
i++;
|
|
243
|
+
}
|
|
244
|
+
if (i < len) {
|
|
245
|
+
str += ">";
|
|
246
|
+
i++;
|
|
247
|
+
}
|
|
248
|
+
yield { type: "other", raw: str };
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (c === "[" || c === "]" || c === "{" || c === "}") {
|
|
252
|
+
yield { type: "other", raw: c };
|
|
253
|
+
i++;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (c === "<" && content[i + 1] === "<") {
|
|
257
|
+
yield { type: "other", raw: "<<" };
|
|
258
|
+
i += 2;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (c === ">" && content[i + 1] === ">") {
|
|
262
|
+
yield { type: "other", raw: ">>" };
|
|
263
|
+
i += 2;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (c === "/") {
|
|
267
|
+
let name = "/";
|
|
268
|
+
i++;
|
|
269
|
+
while (i < len && /[^\s\[\]()<>{}/%]/.test(content[i])) {
|
|
270
|
+
name += content[i];
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
yield { type: "other", raw: name };
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
let token = "";
|
|
277
|
+
while (i < len && /[^\s\[\]()<>{}/%]/.test(content[i])) {
|
|
278
|
+
token += content[i];
|
|
279
|
+
i++;
|
|
280
|
+
}
|
|
281
|
+
if (/^[+-]?(\d+\.?\d*|\.\d+)$/.test(token)) {
|
|
282
|
+
yield { type: "number", value: parseFloat(token), raw: token };
|
|
283
|
+
} else if (token === "ID") {
|
|
284
|
+
yield { type: "operator", value: "ID", raw: "ID" };
|
|
285
|
+
const dataStart = i;
|
|
286
|
+
while (i < len) {
|
|
287
|
+
if (/\s/.test(content[i]) && content[i + 1] === "E" && content[i + 2] === "I" && (i + 3 >= len || /\s/.test(content[i + 3]))) {
|
|
288
|
+
yield { type: "other", raw: content.slice(dataStart, i + 1) };
|
|
289
|
+
yield { type: "operator", value: "EI", raw: "EI" };
|
|
290
|
+
i += 3;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
i++;
|
|
294
|
+
}
|
|
295
|
+
} else if (token.length > 0) {
|
|
296
|
+
yield { type: "operator", value: token, raw: token };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function formatRgbKey(r, g, b) {
|
|
301
|
+
const ri = Math.round(r * SRGB_MAX);
|
|
302
|
+
const gi = Math.round(g * SRGB_MAX);
|
|
303
|
+
const bi = Math.round(b * SRGB_MAX);
|
|
304
|
+
return JSON.stringify([ri, gi, bi]);
|
|
305
|
+
}
|
|
306
|
+
function formatRgbKeyForWarning(r, g, b) {
|
|
307
|
+
const ri = Math.round(r * SRGB_MAX);
|
|
308
|
+
const gi = Math.round(g * SRGB_MAX);
|
|
309
|
+
const bi = Math.round(b * SRGB_MAX);
|
|
310
|
+
return JSON.stringify({ r: ri, g: gi, b: bi });
|
|
311
|
+
}
|
|
312
|
+
function convertStreamColors(content, colorMap, warnUnmapped, warnedColors) {
|
|
313
|
+
const result = [];
|
|
314
|
+
const pendingNumbers = [];
|
|
315
|
+
const flushPendingNumbers = () => {
|
|
316
|
+
for (const num of pendingNumbers) {
|
|
317
|
+
result.push(num.raw);
|
|
318
|
+
}
|
|
319
|
+
pendingNumbers.length = 0;
|
|
320
|
+
};
|
|
321
|
+
for (const token of tokenize(content)) {
|
|
322
|
+
if (token.type === "number") {
|
|
323
|
+
pendingNumbers.push({ value: token.value, raw: token.raw });
|
|
324
|
+
} else if (token.type === "operator") {
|
|
325
|
+
const op = token.value;
|
|
326
|
+
const cmykOp = op === "rg" ? "k" : op === "RG" ? "K" : null;
|
|
327
|
+
if (cmykOp && pendingNumbers.length >= 3) {
|
|
328
|
+
const b = pendingNumbers.pop();
|
|
329
|
+
const g = pendingNumbers.pop();
|
|
330
|
+
const r = pendingNumbers.pop();
|
|
331
|
+
flushPendingNumbers();
|
|
332
|
+
const key = formatRgbKey(r.value, g.value, b.value);
|
|
333
|
+
const cmyk = colorMap[key];
|
|
334
|
+
if (cmyk) {
|
|
335
|
+
const c = (cmyk.c / CMYK_MAX).toString();
|
|
336
|
+
const m = (cmyk.m / CMYK_MAX).toString();
|
|
337
|
+
const y = (cmyk.y / CMYK_MAX).toString();
|
|
338
|
+
const k = (cmyk.k / CMYK_MAX).toString();
|
|
339
|
+
result.push(`${c} ${m} ${y} ${k} ${cmykOp}`);
|
|
340
|
+
} else {
|
|
341
|
+
result.push(r.raw, g.raw, b.raw, token.raw);
|
|
342
|
+
if (warnUnmapped) {
|
|
343
|
+
const warnKey = formatRgbKeyForWarning(r.value, g.value, b.value);
|
|
344
|
+
if (!warnedColors.has(warnKey)) {
|
|
345
|
+
warnedColors.add(warnKey);
|
|
346
|
+
Logger.logWarn(`RGB color not mapped to CMYK: ${warnKey}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
flushPendingNumbers();
|
|
352
|
+
result.push(token.raw);
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
flushPendingNumbers();
|
|
356
|
+
result.push(token.raw);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
flushPendingNumbers();
|
|
360
|
+
return result.join(" ");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/output/cmyk.ts
|
|
364
|
+
function disposable(obj) {
|
|
365
|
+
return Object.assign(obj, {
|
|
366
|
+
[Symbol.dispose]() {
|
|
367
|
+
obj.destroy();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function processStream(stream, colorMap, warnUnmapped, warnedColors, mupdf) {
|
|
372
|
+
const buffer = stream.readStream();
|
|
373
|
+
const content = buffer.asString();
|
|
374
|
+
const converted = convertStreamColors(
|
|
375
|
+
content,
|
|
376
|
+
colorMap,
|
|
377
|
+
warnUnmapped,
|
|
378
|
+
warnedColors
|
|
379
|
+
);
|
|
380
|
+
stream.writeStream(new mupdf.Buffer(converted));
|
|
381
|
+
}
|
|
382
|
+
function processFormXObjects(resources, colorMap, warnUnmapped, warnedColors, mupdf, processed) {
|
|
383
|
+
const xobjects = resources.get("XObject");
|
|
384
|
+
if (!xobjects || !xobjects.isDictionary()) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
xobjects.forEach((xobj) => {
|
|
388
|
+
if (!xobj || !xobj.isStream()) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const objNum = xobj.asIndirect();
|
|
392
|
+
if (objNum && processed.has(objNum)) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (objNum) {
|
|
396
|
+
processed.add(objNum);
|
|
397
|
+
}
|
|
398
|
+
const subtype = xobj.get("Subtype");
|
|
399
|
+
if (!subtype || subtype.toString() !== "/Form") {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
processStream(xobj, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
403
|
+
const nestedResources = xobj.get("Resources");
|
|
404
|
+
if (nestedResources && nestedResources.isDictionary()) {
|
|
405
|
+
processFormXObjects(
|
|
406
|
+
nestedResources,
|
|
407
|
+
colorMap,
|
|
408
|
+
warnUnmapped,
|
|
409
|
+
warnedColors,
|
|
410
|
+
mupdf,
|
|
411
|
+
processed
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
function processContents(contents, colorMap, warnUnmapped, warnedColors, mupdf) {
|
|
417
|
+
if (contents.isArray()) {
|
|
418
|
+
for (let i = 0; i < contents.length; i++) {
|
|
419
|
+
const streamObj = contents.get(i);
|
|
420
|
+
if (streamObj && streamObj.isStream()) {
|
|
421
|
+
processStream(streamObj, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
} else if (contents.isStream()) {
|
|
425
|
+
processStream(contents, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
async function convertCmykColors({
|
|
429
|
+
pdf,
|
|
430
|
+
colorMap,
|
|
431
|
+
warnUnmapped
|
|
432
|
+
}) {
|
|
433
|
+
var _stack = [];
|
|
434
|
+
try {
|
|
435
|
+
const mupdf = await importNodeModule("mupdf");
|
|
436
|
+
const warnedColors = /* @__PURE__ */ new Set();
|
|
437
|
+
const processedXObjects = /* @__PURE__ */ new Set();
|
|
438
|
+
const doc = __using(_stack, disposable(
|
|
439
|
+
mupdf.PDFDocument.openDocument(
|
|
440
|
+
pdf,
|
|
441
|
+
"application/pdf"
|
|
442
|
+
)
|
|
443
|
+
));
|
|
444
|
+
const pageCount = doc.countPages();
|
|
445
|
+
for (let i = 0; i < pageCount; i++) {
|
|
446
|
+
const page = doc.loadPage(i);
|
|
447
|
+
const pageObj = page.getObject().resolve();
|
|
448
|
+
const contents = pageObj.get("Contents");
|
|
449
|
+
if (contents) {
|
|
450
|
+
processContents(contents, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
451
|
+
}
|
|
452
|
+
const resources = pageObj.get("Resources");
|
|
453
|
+
if (resources && resources.isDictionary()) {
|
|
454
|
+
processFormXObjects(
|
|
455
|
+
resources,
|
|
456
|
+
colorMap,
|
|
457
|
+
warnUnmapped,
|
|
458
|
+
warnedColors,
|
|
459
|
+
mupdf,
|
|
460
|
+
processedXObjects
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
const annots = pageObj.get("Annots");
|
|
464
|
+
if (!annots?.isArray()) {
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
for (let j = 0; j < annots.length; j++) {
|
|
468
|
+
const annot = annots.get(j);
|
|
469
|
+
if (!annot) {
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const ap = annot.resolve().get("AP");
|
|
473
|
+
if (!ap?.isDictionary()) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
const n = ap.get("N");
|
|
477
|
+
if (!n) {
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (n.isStream()) {
|
|
481
|
+
processStream(n, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
482
|
+
} else if (n.isDictionary()) {
|
|
483
|
+
n.forEach((val) => {
|
|
484
|
+
if (val?.isStream()) {
|
|
485
|
+
processStream(val, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const outputBuffer = __using(_stack, disposable(doc.saveToBuffer("compress")));
|
|
492
|
+
return new Uint8Array(outputBuffer.asUint8Array());
|
|
493
|
+
} catch (_) {
|
|
494
|
+
var _error = _, _hasError = true;
|
|
495
|
+
} finally {
|
|
496
|
+
__callDispose(_stack, _error, _hasError);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// src/output/image.ts
|
|
501
|
+
import fs from "node:fs";
|
|
502
|
+
function disposable2(obj) {
|
|
503
|
+
return Object.assign(obj, {
|
|
504
|
+
[Symbol.dispose]() {
|
|
505
|
+
obj.destroy();
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
function imagesEqual(a, b) {
|
|
510
|
+
if (a.getWidth() !== b.getWidth() || a.getHeight() !== b.getHeight()) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
const pixmapA = a.toPixmap();
|
|
514
|
+
const pixmapB = b.toPixmap();
|
|
515
|
+
const typeA = pixmapA.getColorSpace();
|
|
516
|
+
const typeB = pixmapB.getColorSpace();
|
|
517
|
+
if (typeA === null || typeB === null || !(typeA.isRGB() && typeB.isRGB() || typeA.isCMYK() && typeB.isCMYK() || typeA.isGray() && typeB.isGray())) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
const pixelsA = pixmapA.getPixels();
|
|
521
|
+
const pixelsB = pixmapB.getPixels();
|
|
522
|
+
return pixelsA.length === pixelsB.length && Buffer.compare(Buffer.from(pixelsA), Buffer.from(pixelsB)) === 0;
|
|
523
|
+
}
|
|
524
|
+
function replaceImagesInDocument(doc, imagePairs) {
|
|
525
|
+
let replaced = 0;
|
|
526
|
+
let total = 0;
|
|
527
|
+
const pageCount = doc.countPages();
|
|
528
|
+
for (let i = 0; i < pageCount; i++) {
|
|
529
|
+
const page = doc.loadPage(i);
|
|
530
|
+
const pageObj = page.getObject().resolve();
|
|
531
|
+
const res = pageObj.get("Resources");
|
|
532
|
+
if (!res || !res.isDictionary()) continue;
|
|
533
|
+
const xobjects = res.get("XObject");
|
|
534
|
+
if (!xobjects || !xobjects.isDictionary()) continue;
|
|
535
|
+
const entries = [];
|
|
536
|
+
xobjects.forEach((value, key) => {
|
|
537
|
+
entries.push({ key, value });
|
|
538
|
+
});
|
|
539
|
+
for (const { key, value } of entries) {
|
|
540
|
+
const resolved = value.resolve();
|
|
541
|
+
const subtype = resolved.get("Subtype");
|
|
542
|
+
if (subtype && subtype.toString() === "/Image") {
|
|
543
|
+
total++;
|
|
544
|
+
const pdfImage = doc.loadImage(value);
|
|
545
|
+
for (const pair of imagePairs) {
|
|
546
|
+
if (imagesEqual(pdfImage, pair.srcImage)) {
|
|
547
|
+
const newImageRef = doc.addImage(pair.destImage);
|
|
548
|
+
xobjects.put(key, newImageRef);
|
|
549
|
+
replaced++;
|
|
550
|
+
Logger.debug(
|
|
551
|
+
` Page ${i + 1}, ref "${key}": ${pair.sourcePath} -> ${pair.replacementPath}`
|
|
552
|
+
);
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
res.put("XObject", xobjects);
|
|
559
|
+
pageObj.put("Resources", res);
|
|
560
|
+
}
|
|
561
|
+
return { replaced, total };
|
|
562
|
+
}
|
|
563
|
+
async function replaceImages({
|
|
564
|
+
pdf,
|
|
565
|
+
replaceImageConfig
|
|
566
|
+
}) {
|
|
567
|
+
var _stack = [];
|
|
568
|
+
try {
|
|
569
|
+
if (replaceImageConfig.length === 0) {
|
|
570
|
+
return pdf;
|
|
571
|
+
}
|
|
572
|
+
const mupdf = await importNodeModule("mupdf");
|
|
573
|
+
const imagePairs = [];
|
|
574
|
+
for (const { source, replacement } of replaceImageConfig) {
|
|
575
|
+
let srcImage;
|
|
576
|
+
let destImage;
|
|
577
|
+
try {
|
|
578
|
+
const srcBuffer = fs.readFileSync(source);
|
|
579
|
+
srcImage = new mupdf.Image(srcBuffer);
|
|
580
|
+
Logger.debug(
|
|
581
|
+
`Loaded source image: ${source} (${srcImage.getWidth()}x${srcImage.getHeight()})`
|
|
582
|
+
);
|
|
583
|
+
} catch (error) {
|
|
584
|
+
Logger.logWarn(`Failed to load source image: ${source}: ${error}`);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
try {
|
|
588
|
+
const destBuffer = fs.readFileSync(replacement);
|
|
589
|
+
destImage = new mupdf.Image(destBuffer);
|
|
590
|
+
Logger.debug(
|
|
591
|
+
`Loaded replacement image: ${replacement} (${destImage.getWidth()}x${destImage.getHeight()})`
|
|
592
|
+
);
|
|
593
|
+
} catch (error) {
|
|
594
|
+
Logger.logWarn(
|
|
595
|
+
`Failed to load replacement image: ${replacement}: ${error}`
|
|
596
|
+
);
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
imagePairs.push({
|
|
600
|
+
srcImage,
|
|
601
|
+
destImage,
|
|
602
|
+
sourcePath: source,
|
|
603
|
+
replacementPath: replacement
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
if (imagePairs.length === 0) {
|
|
607
|
+
return pdf;
|
|
608
|
+
}
|
|
609
|
+
const doc = __using(_stack, disposable2(
|
|
610
|
+
mupdf.PDFDocument.openDocument(
|
|
611
|
+
pdf,
|
|
612
|
+
"application/pdf"
|
|
613
|
+
)
|
|
614
|
+
));
|
|
615
|
+
const stats = replaceImagesInDocument(doc, imagePairs);
|
|
616
|
+
Logger.debug(`Replaced ${stats.replaced} of ${stats.total} images`);
|
|
617
|
+
const outputBuffer = __using(_stack, disposable2(doc.saveToBuffer("compress")));
|
|
618
|
+
return new Uint8Array(outputBuffer.asUint8Array());
|
|
619
|
+
} catch (_) {
|
|
620
|
+
var _error = _, _hasError = true;
|
|
621
|
+
} finally {
|
|
622
|
+
__callDispose(_stack, _error, _hasError);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/output/pdf-postprocess.ts
|
|
202
627
|
var prefixes = {
|
|
203
628
|
dcterms: "http://purl.org/dc/terms/",
|
|
204
629
|
meta: "http://idpf.org/epub/vocab/package/meta/#"
|
|
@@ -247,49 +672,89 @@ var PostProcess = class _PostProcess {
|
|
|
247
672
|
constructor(document2) {
|
|
248
673
|
this.document = document2;
|
|
249
674
|
}
|
|
250
|
-
async save(output, {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
[optName.slice(3)]: false
|
|
265
|
-
} : {
|
|
266
|
-
...acc,
|
|
267
|
-
[optName]: true
|
|
268
|
-
};
|
|
269
|
-
}, {}),
|
|
270
|
-
input,
|
|
271
|
-
output
|
|
272
|
-
});
|
|
273
|
-
} catch (_) {
|
|
274
|
-
var _error = _, _hasError = true;
|
|
275
|
-
} finally {
|
|
276
|
-
__callDispose(_stack, _error, _hasError);
|
|
675
|
+
async save(output, {
|
|
676
|
+
preflight,
|
|
677
|
+
preflightOption,
|
|
678
|
+
image,
|
|
679
|
+
cmyk,
|
|
680
|
+
cmykMap,
|
|
681
|
+
replaceImage
|
|
682
|
+
}) {
|
|
683
|
+
let pdf = await this.document.save();
|
|
684
|
+
if (cmyk) {
|
|
685
|
+
const mergedMap = { ...cmykMap };
|
|
686
|
+
for (const [rgb, cmykValue] of cmyk.overrideMap) {
|
|
687
|
+
const key = JSON.stringify([rgb.r, rgb.g, rgb.b]);
|
|
688
|
+
mergedMap[key] = cmykValue;
|
|
277
689
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
690
|
+
Logger.logInfo("Converting CMYK colors");
|
|
691
|
+
pdf = await convertCmykColors({
|
|
692
|
+
pdf,
|
|
693
|
+
colorMap: mergedMap,
|
|
694
|
+
warnUnmapped: cmyk.warnUnmapped
|
|
695
|
+
});
|
|
696
|
+
if (cmyk.mapOutput) {
|
|
697
|
+
const mapOutputDir = upath2.dirname(cmyk.mapOutput);
|
|
698
|
+
fs2.mkdirSync(mapOutputDir, { recursive: true });
|
|
699
|
+
await fs2.promises.writeFile(
|
|
700
|
+
cmyk.mapOutput,
|
|
701
|
+
JSON.stringify(mergedMap, null, 2)
|
|
702
|
+
);
|
|
703
|
+
Logger.logInfo(`CMYK color map saved to ${cmyk.mapOutput}`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (replaceImage.length > 0) {
|
|
707
|
+
Logger.logInfo("Replacing images");
|
|
708
|
+
pdf = await replaceImages({
|
|
709
|
+
pdf,
|
|
710
|
+
replaceImageConfig: replaceImage
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
if (preflight) {
|
|
714
|
+
const input = upath2.join(os.tmpdir(), `vivliostyle-cli-${uuid()}.pdf`);
|
|
715
|
+
await fs2.promises.writeFile(input, pdf);
|
|
716
|
+
if (preflight === "press-ready-local" || preflight === "press-ready" && isInContainer()) {
|
|
717
|
+
var _stack = [];
|
|
718
|
+
try {
|
|
719
|
+
const _3 = __using(_stack, Logger.suspendLogging("Running press-ready"));
|
|
720
|
+
const { build: build2 } = await importNodeModule("press-ready");
|
|
721
|
+
await build2({
|
|
722
|
+
...preflightOption.reduce((acc, opt) => {
|
|
723
|
+
const optName = decamelize(opt, { separator: "-" });
|
|
724
|
+
return optName.startsWith("no-") ? {
|
|
725
|
+
...acc,
|
|
726
|
+
[optName.slice(3)]: false
|
|
727
|
+
} : {
|
|
728
|
+
...acc,
|
|
729
|
+
[optName]: true
|
|
730
|
+
};
|
|
731
|
+
}, {}),
|
|
732
|
+
input,
|
|
733
|
+
output
|
|
734
|
+
});
|
|
735
|
+
} catch (_) {
|
|
736
|
+
var _error = _, _hasError = true;
|
|
737
|
+
} finally {
|
|
738
|
+
__callDispose(_stack, _error, _hasError);
|
|
739
|
+
}
|
|
740
|
+
} else if (preflight === "press-ready") {
|
|
741
|
+
var _stack2 = [];
|
|
742
|
+
try {
|
|
743
|
+
const _3 = __using(_stack2, Logger.suspendLogging("Running press-ready"));
|
|
744
|
+
await pressReadyWithContainer({
|
|
745
|
+
input,
|
|
746
|
+
output,
|
|
747
|
+
preflightOption,
|
|
748
|
+
image
|
|
749
|
+
});
|
|
750
|
+
} catch (_2) {
|
|
751
|
+
var _error2 = _2, _hasError2 = true;
|
|
752
|
+
} finally {
|
|
753
|
+
__callDispose(_stack2, _error2, _hasError2);
|
|
754
|
+
}
|
|
292
755
|
}
|
|
756
|
+
} else {
|
|
757
|
+
await fs2.promises.writeFile(output, pdf);
|
|
293
758
|
}
|
|
294
759
|
}
|
|
295
760
|
async metadata(tree, {
|
|
@@ -506,7 +971,7 @@ async function buildPDF({
|
|
|
506
971
|
response.url()
|
|
507
972
|
);
|
|
508
973
|
handleEntry(response);
|
|
509
|
-
if (
|
|
974
|
+
if (400 > response.status() && 200 <= response.status()) return;
|
|
510
975
|
if (response.url().startsWith("file://") && response.ok()) return;
|
|
511
976
|
Logger.logError(red(`${response.status()}`), response.url());
|
|
512
977
|
});
|
|
@@ -546,6 +1011,7 @@ async function buildPDF({
|
|
|
546
1011
|
const metadata = await loadMetadata(page);
|
|
547
1012
|
const toc = await loadTOC(page);
|
|
548
1013
|
const pageSizeData = await loadPageSizeData(page);
|
|
1014
|
+
const cmykMap = target.cmyk ? await loadCmykMap(page) : {};
|
|
549
1015
|
remainTime -= Date.now() - startTime;
|
|
550
1016
|
if (remainTime <= 0) {
|
|
551
1017
|
throw new Error("Typesetting process timed out");
|
|
@@ -572,7 +1038,7 @@ async function buildPDF({
|
|
|
572
1038
|
});
|
|
573
1039
|
await browser.close();
|
|
574
1040
|
Logger.logUpdate("Processing PDF");
|
|
575
|
-
|
|
1041
|
+
fs3.mkdirSync(upath3.dirname(target.path), { recursive: true });
|
|
576
1042
|
const post = await PostProcess.load(pdf);
|
|
577
1043
|
await post.metadata(metadata, {
|
|
578
1044
|
pageProgression,
|
|
@@ -587,7 +1053,10 @@ async function buildPDF({
|
|
|
587
1053
|
await post.save(target.path, {
|
|
588
1054
|
preflight: target.preflight,
|
|
589
1055
|
preflightOption: target.preflightOption,
|
|
590
|
-
image: config.image
|
|
1056
|
+
image: config.image,
|
|
1057
|
+
cmyk: target.cmyk,
|
|
1058
|
+
cmykMap,
|
|
1059
|
+
replaceImage: target.replaceImage
|
|
591
1060
|
});
|
|
592
1061
|
return target.path;
|
|
593
1062
|
}
|
|
@@ -630,6 +1099,9 @@ async function loadPageSizeData(page) {
|
|
|
630
1099
|
return sizeData;
|
|
631
1100
|
});
|
|
632
1101
|
}
|
|
1102
|
+
async function loadCmykMap(page) {
|
|
1103
|
+
return page.evaluate(() => window.coreViewer.getCmykMap?.() ?? {});
|
|
1104
|
+
}
|
|
633
1105
|
|
|
634
1106
|
// src/core/build.ts
|
|
635
1107
|
async function build(inlineConfig, { containerForkMode = false } = {}) {
|
|
@@ -754,4 +1226,4 @@ async function build(inlineConfig, { containerForkMode = false } = {}) {
|
|
|
754
1226
|
export {
|
|
755
1227
|
build
|
|
756
1228
|
};
|
|
757
|
-
//# sourceMappingURL=chunk-
|
|
1229
|
+
//# sourceMappingURL=chunk-ERDN47XG.js.map
|