@vivliostyle/cli 10.2.0 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-CKXFRCPH.js → chunk-3QOSSWIX.js} +129 -7
- package/dist/chunk-3QOSSWIX.js.map +1 -0
- package/dist/{chunk-5MEUINC4.js → chunk-ALY3QX7K.js} +530 -51
- package/dist/chunk-ALY3QX7K.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-37OLZSNI.js → chunk-NVNEYZ3J.js} +4 -4
- package/dist/{chunk-O3CBPX4R.js → chunk-QLK3XMQI.js} +3 -3
- package/dist/{chunk-XMCTTVR7.js → chunk-RBKPG6VU.js} +2 -2
- package/dist/{chunk-T2VWLU2I.js → chunk-RILZCPJE.js} +5 -3
- package/dist/chunk-RILZCPJE.js.map +1 -0
- package/dist/{chunk-62AC6XGJ.js → chunk-WIGLU3EK.js} +4 -4
- package/dist/{chunk-BR2V7MHE.js → chunk-YNX6D2I6.js} +207 -53
- package/dist/chunk-YNX6D2I6.js.map +1 -0
- package/dist/commands/build.js +7 -7
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/create.js +3 -3
- package/dist/commands/init.js +3 -3
- package/dist/commands/preview.js +6 -6
- package/dist/config/schema.d.ts +21143 -21173
- package/dist/config/schema.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -10
- 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 +5 -5
- package/package.json +4 -3
- 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-T2VWLU2I.js.map +0 -1
- /package/dist/{chunk-37OLZSNI.js.map → chunk-NVNEYZ3J.js.map} +0 -0
- /package/dist/{chunk-O3CBPX4R.js.map → chunk-QLK3XMQI.js.map} +0 -0
- /package/dist/{chunk-XMCTTVR7.js.map → chunk-RBKPG6VU.js.map} +0 -0
- /package/dist/{chunk-62AC6XGJ.js.map → chunk-WIGLU3EK.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveViteConfig
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RBKPG6VU.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-YNX6D2I6.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,7 +32,7 @@ import {
|
|
|
32
32
|
randomBookSymbol,
|
|
33
33
|
runExitHandlers,
|
|
34
34
|
setupConfigFromFlags
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-RILZCPJE.js";
|
|
36
36
|
import {
|
|
37
37
|
CONTAINER_LOCAL_HOSTNAME,
|
|
38
38
|
CONTAINER_ROOT_DIR,
|
|
@@ -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,442 @@ 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 resolved = xobj.resolve();
|
|
392
|
+
const objNum = resolved.asIndirect();
|
|
393
|
+
if (objNum && processed.has(objNum)) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (objNum) {
|
|
397
|
+
processed.add(objNum);
|
|
398
|
+
}
|
|
399
|
+
const subtype = resolved.get("Subtype");
|
|
400
|
+
if (!subtype || subtype.toString() !== "/Form") {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
processStream(resolved, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
404
|
+
const nestedResources = resolved.get("Resources");
|
|
405
|
+
if (nestedResources && nestedResources.isDictionary()) {
|
|
406
|
+
processFormXObjects(
|
|
407
|
+
nestedResources,
|
|
408
|
+
colorMap,
|
|
409
|
+
warnUnmapped,
|
|
410
|
+
warnedColors,
|
|
411
|
+
mupdf,
|
|
412
|
+
processed
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
function processContents(contents, colorMap, warnUnmapped, warnedColors, mupdf) {
|
|
418
|
+
if (contents.isArray()) {
|
|
419
|
+
for (let i = 0; i < contents.length; i++) {
|
|
420
|
+
const streamObj = contents.get(i);
|
|
421
|
+
if (streamObj && streamObj.isStream()) {
|
|
422
|
+
processStream(
|
|
423
|
+
streamObj.resolve(),
|
|
424
|
+
colorMap,
|
|
425
|
+
warnUnmapped,
|
|
426
|
+
warnedColors,
|
|
427
|
+
mupdf
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
} else if (contents.isStream()) {
|
|
432
|
+
processStream(contents, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
async function convertCmykColors({
|
|
436
|
+
pdf,
|
|
437
|
+
colorMap,
|
|
438
|
+
warnUnmapped
|
|
439
|
+
}) {
|
|
440
|
+
var _stack = [];
|
|
441
|
+
try {
|
|
442
|
+
const mupdf = await importNodeModule("mupdf");
|
|
443
|
+
const warnedColors = /* @__PURE__ */ new Set();
|
|
444
|
+
const processedXObjects = /* @__PURE__ */ new Set();
|
|
445
|
+
const doc = __using(_stack, disposable(
|
|
446
|
+
mupdf.PDFDocument.openDocument(
|
|
447
|
+
pdf,
|
|
448
|
+
"application/pdf"
|
|
449
|
+
)
|
|
450
|
+
));
|
|
451
|
+
const pageCount = doc.countPages();
|
|
452
|
+
for (let i = 0; i < pageCount; i++) {
|
|
453
|
+
const page = doc.loadPage(i);
|
|
454
|
+
const pageObj = page.getObject().resolve();
|
|
455
|
+
const contents = pageObj.get("Contents");
|
|
456
|
+
if (contents) {
|
|
457
|
+
processContents(contents, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
458
|
+
}
|
|
459
|
+
const resources = pageObj.get("Resources");
|
|
460
|
+
if (resources && resources.isDictionary()) {
|
|
461
|
+
processFormXObjects(
|
|
462
|
+
resources,
|
|
463
|
+
colorMap,
|
|
464
|
+
warnUnmapped,
|
|
465
|
+
warnedColors,
|
|
466
|
+
mupdf,
|
|
467
|
+
processedXObjects
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
const annots = pageObj.get("Annots");
|
|
471
|
+
if (!annots?.isArray()) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
for (let j = 0; j < annots.length; j++) {
|
|
475
|
+
const annot = annots.get(j);
|
|
476
|
+
if (!annot) {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const ap = annot.resolve().get("AP");
|
|
480
|
+
if (!ap?.isDictionary()) {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
const n = ap.get("N");
|
|
484
|
+
if (!n) {
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
if (n.isStream()) {
|
|
488
|
+
processStream(n, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
489
|
+
} else if (n.isDictionary()) {
|
|
490
|
+
n.forEach((val) => {
|
|
491
|
+
if (val?.isStream()) {
|
|
492
|
+
processStream(val, colorMap, warnUnmapped, warnedColors, mupdf);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const outputBuffer = __using(_stack, disposable(doc.saveToBuffer("compress")));
|
|
499
|
+
return new Uint8Array(outputBuffer.asUint8Array());
|
|
500
|
+
} catch (_) {
|
|
501
|
+
var _error = _, _hasError = true;
|
|
502
|
+
} finally {
|
|
503
|
+
__callDispose(_stack, _error, _hasError);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// src/output/image.ts
|
|
508
|
+
import fs from "node:fs";
|
|
509
|
+
function disposable2(obj) {
|
|
510
|
+
return Object.assign(obj, {
|
|
511
|
+
[Symbol.dispose]() {
|
|
512
|
+
obj.destroy();
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
function imagesEqual(a, b) {
|
|
517
|
+
if (a.getWidth() !== b.getWidth() || a.getHeight() !== b.getHeight()) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
const pixmapA = a.toPixmap();
|
|
521
|
+
const pixmapB = b.toPixmap();
|
|
522
|
+
const typeA = pixmapA.getColorSpace();
|
|
523
|
+
const typeB = pixmapB.getColorSpace();
|
|
524
|
+
if (typeA === null || typeB === null || !(typeA.isRGB() && typeB.isRGB() || typeA.isCMYK() && typeB.isCMYK() || typeA.isGray() && typeB.isGray())) {
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
const pixelsA = pixmapA.getPixels();
|
|
528
|
+
const pixelsB = pixmapB.getPixels();
|
|
529
|
+
return pixelsA.length === pixelsB.length && Buffer.compare(Buffer.from(pixelsA), Buffer.from(pixelsB)) === 0;
|
|
530
|
+
}
|
|
531
|
+
function replaceImagesInDocument(doc, imagePairs) {
|
|
532
|
+
let replaced = 0;
|
|
533
|
+
let total = 0;
|
|
534
|
+
const pageCount = doc.countPages();
|
|
535
|
+
for (let i = 0; i < pageCount; i++) {
|
|
536
|
+
const page = doc.loadPage(i);
|
|
537
|
+
const pageObj = page.getObject().resolve();
|
|
538
|
+
const res = pageObj.get("Resources");
|
|
539
|
+
if (!res || !res.isDictionary()) continue;
|
|
540
|
+
const xobjects = res.get("XObject");
|
|
541
|
+
if (!xobjects || !xobjects.isDictionary()) continue;
|
|
542
|
+
const entries = [];
|
|
543
|
+
xobjects.forEach((value, key) => {
|
|
544
|
+
entries.push({ key, value });
|
|
545
|
+
});
|
|
546
|
+
for (const { key, value } of entries) {
|
|
547
|
+
const resolved = value.resolve();
|
|
548
|
+
const subtype = resolved.get("Subtype");
|
|
549
|
+
if (subtype && subtype.toString() === "/Image") {
|
|
550
|
+
total++;
|
|
551
|
+
const pdfImage = doc.loadImage(value);
|
|
552
|
+
for (const pair of imagePairs) {
|
|
553
|
+
if (imagesEqual(pdfImage, pair.srcImage)) {
|
|
554
|
+
const newImageRef = doc.addImage(pair.destImage);
|
|
555
|
+
xobjects.put(key, newImageRef);
|
|
556
|
+
replaced++;
|
|
557
|
+
Logger.debug(
|
|
558
|
+
` Page ${i + 1}, ref "${key}": ${pair.sourcePath} -> ${pair.replacementPath}`
|
|
559
|
+
);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
res.put("XObject", xobjects);
|
|
566
|
+
pageObj.put("Resources", res);
|
|
567
|
+
}
|
|
568
|
+
return { replaced, total };
|
|
569
|
+
}
|
|
570
|
+
async function replaceImages({
|
|
571
|
+
pdf,
|
|
572
|
+
replaceImageConfig
|
|
573
|
+
}) {
|
|
574
|
+
var _stack = [];
|
|
575
|
+
try {
|
|
576
|
+
if (replaceImageConfig.length === 0) {
|
|
577
|
+
return pdf;
|
|
578
|
+
}
|
|
579
|
+
const mupdf = await importNodeModule("mupdf");
|
|
580
|
+
const imagePairs = [];
|
|
581
|
+
for (const { source, replacement } of replaceImageConfig) {
|
|
582
|
+
let srcImage;
|
|
583
|
+
let destImage;
|
|
584
|
+
try {
|
|
585
|
+
const srcBuffer = fs.readFileSync(source);
|
|
586
|
+
srcImage = new mupdf.Image(srcBuffer);
|
|
587
|
+
Logger.debug(
|
|
588
|
+
`Loaded source image: ${source} (${srcImage.getWidth()}x${srcImage.getHeight()})`
|
|
589
|
+
);
|
|
590
|
+
} catch (error) {
|
|
591
|
+
Logger.logWarn(`Failed to load source image: ${source}: ${error}`);
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
try {
|
|
595
|
+
const destBuffer = fs.readFileSync(replacement);
|
|
596
|
+
destImage = new mupdf.Image(destBuffer);
|
|
597
|
+
Logger.debug(
|
|
598
|
+
`Loaded replacement image: ${replacement} (${destImage.getWidth()}x${destImage.getHeight()})`
|
|
599
|
+
);
|
|
600
|
+
} catch (error) {
|
|
601
|
+
Logger.logWarn(
|
|
602
|
+
`Failed to load replacement image: ${replacement}: ${error}`
|
|
603
|
+
);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
imagePairs.push({
|
|
607
|
+
srcImage,
|
|
608
|
+
destImage,
|
|
609
|
+
sourcePath: source,
|
|
610
|
+
replacementPath: replacement
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
if (imagePairs.length === 0) {
|
|
614
|
+
return pdf;
|
|
615
|
+
}
|
|
616
|
+
const doc = __using(_stack, disposable2(
|
|
617
|
+
mupdf.PDFDocument.openDocument(
|
|
618
|
+
pdf,
|
|
619
|
+
"application/pdf"
|
|
620
|
+
)
|
|
621
|
+
));
|
|
622
|
+
const stats = replaceImagesInDocument(doc, imagePairs);
|
|
623
|
+
Logger.debug(`Replaced ${stats.replaced} of ${stats.total} images`);
|
|
624
|
+
const outputBuffer = __using(_stack, disposable2(doc.saveToBuffer("compress")));
|
|
625
|
+
return new Uint8Array(outputBuffer.asUint8Array());
|
|
626
|
+
} catch (_) {
|
|
627
|
+
var _error = _, _hasError = true;
|
|
628
|
+
} finally {
|
|
629
|
+
__callDispose(_stack, _error, _hasError);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/output/pdf-postprocess.ts
|
|
202
634
|
var prefixes = {
|
|
203
635
|
dcterms: "http://purl.org/dc/terms/",
|
|
204
636
|
meta: "http://idpf.org/epub/vocab/package/meta/#"
|
|
@@ -247,49 +679,89 @@ var PostProcess = class _PostProcess {
|
|
|
247
679
|
constructor(document2) {
|
|
248
680
|
this.document = document2;
|
|
249
681
|
}
|
|
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);
|
|
682
|
+
async save(output, {
|
|
683
|
+
preflight,
|
|
684
|
+
preflightOption,
|
|
685
|
+
image,
|
|
686
|
+
cmyk,
|
|
687
|
+
cmykMap,
|
|
688
|
+
replaceImage
|
|
689
|
+
}) {
|
|
690
|
+
let pdf = await this.document.save();
|
|
691
|
+
if (cmyk) {
|
|
692
|
+
const mergedMap = { ...cmykMap };
|
|
693
|
+
for (const [rgb, cmykValue] of cmyk.overrideMap) {
|
|
694
|
+
const key = JSON.stringify([rgb.r, rgb.g, rgb.b]);
|
|
695
|
+
mergedMap[key] = cmykValue;
|
|
277
696
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
697
|
+
Logger.logInfo("Converting CMYK colors");
|
|
698
|
+
pdf = await convertCmykColors({
|
|
699
|
+
pdf,
|
|
700
|
+
colorMap: mergedMap,
|
|
701
|
+
warnUnmapped: cmyk.warnUnmapped
|
|
702
|
+
});
|
|
703
|
+
if (cmyk.mapOutput) {
|
|
704
|
+
const mapOutputDir = upath2.dirname(cmyk.mapOutput);
|
|
705
|
+
fs2.mkdirSync(mapOutputDir, { recursive: true });
|
|
706
|
+
await fs2.promises.writeFile(
|
|
707
|
+
cmyk.mapOutput,
|
|
708
|
+
JSON.stringify(mergedMap, null, 2)
|
|
709
|
+
);
|
|
710
|
+
Logger.logInfo(`CMYK color map saved to ${cmyk.mapOutput}`);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
if (replaceImage.length > 0) {
|
|
714
|
+
Logger.logInfo("Replacing images");
|
|
715
|
+
pdf = await replaceImages({
|
|
716
|
+
pdf,
|
|
717
|
+
replaceImageConfig: replaceImage
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
if (preflight) {
|
|
721
|
+
const input = upath2.join(os.tmpdir(), `vivliostyle-cli-${uuid()}.pdf`);
|
|
722
|
+
await fs2.promises.writeFile(input, pdf);
|
|
723
|
+
if (preflight === "press-ready-local" || preflight === "press-ready" && isInContainer()) {
|
|
724
|
+
var _stack = [];
|
|
725
|
+
try {
|
|
726
|
+
const _3 = __using(_stack, Logger.suspendLogging("Running press-ready"));
|
|
727
|
+
const { build: build2 } = await importNodeModule("press-ready");
|
|
728
|
+
await build2({
|
|
729
|
+
...preflightOption.reduce((acc, opt) => {
|
|
730
|
+
const optName = decamelize(opt, { separator: "-" });
|
|
731
|
+
return optName.startsWith("no-") ? {
|
|
732
|
+
...acc,
|
|
733
|
+
[optName.slice(3)]: false
|
|
734
|
+
} : {
|
|
735
|
+
...acc,
|
|
736
|
+
[optName]: true
|
|
737
|
+
};
|
|
738
|
+
}, {}),
|
|
739
|
+
input,
|
|
740
|
+
output
|
|
741
|
+
});
|
|
742
|
+
} catch (_) {
|
|
743
|
+
var _error = _, _hasError = true;
|
|
744
|
+
} finally {
|
|
745
|
+
__callDispose(_stack, _error, _hasError);
|
|
746
|
+
}
|
|
747
|
+
} else if (preflight === "press-ready") {
|
|
748
|
+
var _stack2 = [];
|
|
749
|
+
try {
|
|
750
|
+
const _3 = __using(_stack2, Logger.suspendLogging("Running press-ready"));
|
|
751
|
+
await pressReadyWithContainer({
|
|
752
|
+
input,
|
|
753
|
+
output,
|
|
754
|
+
preflightOption,
|
|
755
|
+
image
|
|
756
|
+
});
|
|
757
|
+
} catch (_2) {
|
|
758
|
+
var _error2 = _2, _hasError2 = true;
|
|
759
|
+
} finally {
|
|
760
|
+
__callDispose(_stack2, _error2, _hasError2);
|
|
761
|
+
}
|
|
292
762
|
}
|
|
763
|
+
} else {
|
|
764
|
+
await fs2.promises.writeFile(output, pdf);
|
|
293
765
|
}
|
|
294
766
|
}
|
|
295
767
|
async metadata(tree, {
|
|
@@ -506,7 +978,7 @@ async function buildPDF({
|
|
|
506
978
|
response.url()
|
|
507
979
|
);
|
|
508
980
|
handleEntry(response);
|
|
509
|
-
if (
|
|
981
|
+
if (400 > response.status() && 200 <= response.status()) return;
|
|
510
982
|
if (response.url().startsWith("file://") && response.ok()) return;
|
|
511
983
|
Logger.logError(red(`${response.status()}`), response.url());
|
|
512
984
|
});
|
|
@@ -546,6 +1018,7 @@ async function buildPDF({
|
|
|
546
1018
|
const metadata = await loadMetadata(page);
|
|
547
1019
|
const toc = await loadTOC(page);
|
|
548
1020
|
const pageSizeData = await loadPageSizeData(page);
|
|
1021
|
+
const cmykMap = target.cmyk ? await loadCmykMap(page) : {};
|
|
549
1022
|
remainTime -= Date.now() - startTime;
|
|
550
1023
|
if (remainTime <= 0) {
|
|
551
1024
|
throw new Error("Typesetting process timed out");
|
|
@@ -572,7 +1045,7 @@ async function buildPDF({
|
|
|
572
1045
|
});
|
|
573
1046
|
await browser.close();
|
|
574
1047
|
Logger.logUpdate("Processing PDF");
|
|
575
|
-
|
|
1048
|
+
fs3.mkdirSync(upath3.dirname(target.path), { recursive: true });
|
|
576
1049
|
const post = await PostProcess.load(pdf);
|
|
577
1050
|
await post.metadata(metadata, {
|
|
578
1051
|
pageProgression,
|
|
@@ -587,7 +1060,10 @@ async function buildPDF({
|
|
|
587
1060
|
await post.save(target.path, {
|
|
588
1061
|
preflight: target.preflight,
|
|
589
1062
|
preflightOption: target.preflightOption,
|
|
590
|
-
image: config.image
|
|
1063
|
+
image: config.image,
|
|
1064
|
+
cmyk: target.cmyk,
|
|
1065
|
+
cmykMap,
|
|
1066
|
+
replaceImage: target.replaceImage
|
|
591
1067
|
});
|
|
592
1068
|
return target.path;
|
|
593
1069
|
}
|
|
@@ -630,6 +1106,9 @@ async function loadPageSizeData(page) {
|
|
|
630
1106
|
return sizeData;
|
|
631
1107
|
});
|
|
632
1108
|
}
|
|
1109
|
+
async function loadCmykMap(page) {
|
|
1110
|
+
return page.evaluate(() => window.coreViewer.getCmykMap?.() ?? {});
|
|
1111
|
+
}
|
|
633
1112
|
|
|
634
1113
|
// src/core/build.ts
|
|
635
1114
|
async function build(inlineConfig, { containerForkMode = false } = {}) {
|
|
@@ -754,4 +1233,4 @@ async function build(inlineConfig, { containerForkMode = false } = {}) {
|
|
|
754
1233
|
export {
|
|
755
1234
|
build
|
|
756
1235
|
};
|
|
757
|
-
//# sourceMappingURL=chunk-
|
|
1236
|
+
//# sourceMappingURL=chunk-ALY3QX7K.js.map
|