@vivliostyle/cli 9.0.1 → 9.1.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.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-QZWMJ4L2.js → chunk-2O2YEPBK.js} +11 -8
  3. package/dist/chunk-2O2YEPBK.js.map +1 -0
  4. package/dist/{chunk-EX7EA34F.js → chunk-4IIM6RSG.js} +7 -0
  5. package/dist/chunk-4IIM6RSG.js.map +1 -0
  6. package/dist/chunk-7BGVK3JL.js +1138 -0
  7. package/dist/chunk-7BGVK3JL.js.map +1 -0
  8. package/dist/{chunk-DMARNPN5.js → chunk-ASL7KKVE.js} +17 -1
  9. package/dist/chunk-ASL7KKVE.js.map +1 -0
  10. package/dist/{chunk-4Y2QIRBA.js → chunk-ES2EB7JI.js} +7 -4
  11. package/dist/chunk-ES2EB7JI.js.map +1 -0
  12. package/dist/{chunk-WX6JHPSL.js → chunk-FXUEYQRY.js} +1 -0
  13. package/dist/chunk-FXUEYQRY.js.map +1 -0
  14. package/dist/{chunk-XRR6RKA6.js → chunk-GWTECQAW.js} +7 -3
  15. package/dist/chunk-GWTECQAW.js.map +1 -0
  16. package/dist/{chunk-BIEQXUOY.js → chunk-I7BWSAN6.js} +1 -0
  17. package/dist/chunk-I7BWSAN6.js.map +1 -0
  18. package/dist/{chunk-5AUWIYEK.js → chunk-ICXF2SCI.js} +172 -35
  19. package/dist/chunk-ICXF2SCI.js.map +1 -0
  20. package/dist/{chunk-PY4J4NG6.js → chunk-KSJHCVYG.js} +438 -1635
  21. package/dist/chunk-KSJHCVYG.js.map +1 -0
  22. package/dist/{chunk-FQMQ7BWY.js → chunk-WBVBMEED.js} +7 -4
  23. package/dist/chunk-WBVBMEED.js.map +1 -0
  24. package/dist/cli.js +3 -2
  25. package/dist/cli.js.map +1 -0
  26. package/dist/commands/build.js +11 -9
  27. package/dist/commands/build.js.map +1 -0
  28. package/dist/commands/init.js +6 -6
  29. package/dist/commands/init.js.map +1 -0
  30. package/dist/commands/preview.js +9 -7
  31. package/dist/commands/preview.js.map +1 -0
  32. package/dist/config/schema.d.ts +20 -20
  33. package/dist/config/schema.js +4 -2
  34. package/dist/config/schema.js.map +1 -0
  35. package/dist/index.js +12 -10
  36. package/dist/index.js.map +1 -0
  37. package/dist/node-modules.js +3 -2
  38. package/dist/node-modules.js.map +1 -0
  39. package/dist/vite-adapter.js +8 -6
  40. package/dist/vite-adapter.js.map +1 -0
  41. package/package.json +5 -3
@@ -0,0 +1,1138 @@
1
+ import {
2
+ VivliostyleInlineConfig
3
+ } from "./chunk-ASL7KKVE.js";
4
+ import {
5
+ EMPTY_DATA_URI
6
+ } from "./chunk-4IIM6RSG.js";
7
+
8
+ // src/util.ts
9
+ import { codeFrameColumns } from "@babel/code-frame";
10
+ import {
11
+ evaluate,
12
+ parse
13
+ } from "@humanwhocodes/momoa";
14
+ import { Ajv } from "ajv";
15
+ import formatsPlugin from "ajv-formats";
16
+ import { XMLParser } from "fast-xml-parser";
17
+ import StreamZip from "node-stream-zip";
18
+ import fs from "node:fs";
19
+ import readline from "node:readline";
20
+ import util from "node:util";
21
+ import tmp from "tmp";
22
+ import upath from "upath";
23
+ import { gray as gray2, red, redBright as redBright2 } from "yoctocolors";
24
+
25
+ // src/logger.ts
26
+ import debug from "debug";
27
+ import yoctoSpinner from "yocto-spinner";
28
+ import {
29
+ blueBright,
30
+ gray,
31
+ greenBright,
32
+ redBright,
33
+ yellowBright
34
+ } from "yoctocolors";
35
+ var isUnicodeSupported = process.platform !== "win32" || Boolean(process.env.WT_SESSION);
36
+ var randomBookSymbol = ["\u{1F4D5}", "\u{1F4D7}", "\u{1F4D8}", "\u{1F4D9}"][Math.floor(Math.random() * 4)];
37
+ var infoSymbol = blueBright("INFO");
38
+ var successSymbol = greenBright("SUCCESS");
39
+ var warnSymbol = yellowBright("WARN");
40
+ var errorSymbol = redBright("ERROR");
41
+ var Logger = class _Logger {
42
+ /**
43
+ * 0: silent 1: info 2: verbose 3: debug
44
+ */
45
+ static #logLevel = 0;
46
+ static #loggerInstance;
47
+ static #nonBlockingLogPrinted = false;
48
+ static #customLogger;
49
+ static debug = debug("vs-cli");
50
+ static get #spinner() {
51
+ return this.#loggerInstance && this.#loggerInstance.#_spinner;
52
+ }
53
+ static get isInteractive() {
54
+ return Boolean(
55
+ !this.#customLogger && process.stderr.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env) && !import.meta.env?.VITEST && !debug.enabled("vs-cli") && // Prevent stream output in docker container so that not to spawn process
56
+ !isInContainer()
57
+ );
58
+ }
59
+ static startLogging(text) {
60
+ if (this.#logLevel === 0) {
61
+ return;
62
+ }
63
+ if (!this.isInteractive) {
64
+ this.logInfo(text);
65
+ return;
66
+ }
67
+ if (this.#loggerInstance) {
68
+ this.#loggerInstance.#_spinner.text = text;
69
+ return this.#loggerInstance;
70
+ }
71
+ this.#loggerInstance = new _Logger();
72
+ this.#loggerInstance.#start(text);
73
+ return this.#loggerInstance;
74
+ }
75
+ static suspendLogging(text) {
76
+ if (this.#logLevel === 0) {
77
+ return;
78
+ }
79
+ if (!this.#spinner || !this.isInteractive) {
80
+ this.logInfo(text);
81
+ return;
82
+ }
83
+ const currentMsg = this.#spinner?.text;
84
+ this.logUpdate(currentMsg);
85
+ this.#spinner.stop(`${infoSymbol} ${text}
86
+ `);
87
+ return {
88
+ [Symbol.dispose]() {
89
+ if (_Logger.isInteractive) {
90
+ console.log("");
91
+ _Logger.#spinner?.start(currentMsg);
92
+ _Logger.#nonBlockingLogPrinted = true;
93
+ }
94
+ }
95
+ };
96
+ }
97
+ static log(...messages) {
98
+ if (this.#logLevel < 1) {
99
+ return;
100
+ }
101
+ console.log(...messages);
102
+ }
103
+ static logUpdate(...messages) {
104
+ if (!this.#spinner || !this.isInteractive) {
105
+ this.logInfo(...messages);
106
+ return;
107
+ }
108
+ this.#spinner.stop(
109
+ this.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#spinner.text}`
110
+ );
111
+ this.#spinner.start(messages.join(" "));
112
+ this.#nonBlockingLogPrinted = false;
113
+ }
114
+ static getMessage(message, symbol) {
115
+ return !this.#customLogger && symbol ? `${symbol} ${message}` : message;
116
+ }
117
+ static #nonBlockingLog(logMethod, message) {
118
+ if (!this.#spinner || !this.isInteractive) {
119
+ if (isInContainer()) {
120
+ message = `${gray("[Docker]")} ${message}`;
121
+ }
122
+ this.#logLevel >= 3 ? this.debug(message) : (this.#customLogger || console)[logMethod](message);
123
+ return;
124
+ }
125
+ this.logUpdate(this.#spinner.text);
126
+ this.#nonBlockingLogPrinted = true;
127
+ this.#spinner.stop(message);
128
+ this.#spinner.start();
129
+ }
130
+ static logSuccess(...messages) {
131
+ if (this.#logLevel < 1) {
132
+ return;
133
+ }
134
+ this.#nonBlockingLog(
135
+ "info",
136
+ this.getMessage(messages.join(" "), successSymbol)
137
+ );
138
+ }
139
+ static logError(...messages) {
140
+ if (this.#logLevel < 1) {
141
+ return;
142
+ }
143
+ this.#nonBlockingLog(
144
+ "error",
145
+ this.getMessage(messages.join(" "), errorSymbol)
146
+ );
147
+ }
148
+ static logWarn(...messages) {
149
+ if (this.#logLevel < 1) {
150
+ return;
151
+ }
152
+ this.#nonBlockingLog(
153
+ "warn",
154
+ this.getMessage(messages.join(" "), warnSymbol)
155
+ );
156
+ }
157
+ static logInfo(...messages) {
158
+ if (this.#logLevel < 1) {
159
+ return;
160
+ }
161
+ this.#nonBlockingLog(
162
+ "info",
163
+ this.getMessage(messages.join(" "), infoSymbol)
164
+ );
165
+ }
166
+ static logVerbose(...messages) {
167
+ if (this.#logLevel < 2) {
168
+ return;
169
+ }
170
+ this.#nonBlockingLog("info", this.getMessage(messages.join(" ")));
171
+ }
172
+ static setLogLevel(level) {
173
+ if (!level) {
174
+ return;
175
+ }
176
+ this.#logLevel = {
177
+ silent: 0,
178
+ info: 1,
179
+ verbose: 2,
180
+ debug: 3
181
+ }[level];
182
+ if (this.#logLevel >= 3) {
183
+ debug.enable("vs-cli");
184
+ }
185
+ }
186
+ static setCustomLogger(logger) {
187
+ this.#customLogger = logger;
188
+ }
189
+ #_spinner;
190
+ #_disposeSpinnerExitHandler;
191
+ constructor() {
192
+ this.#_spinner = yoctoSpinner({
193
+ spinner: {
194
+ frames: isUnicodeSupported ? ["\u2581\u2581\u2571 ", "\u2581\u2551\u2581 ", "\u2572\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 ", "\u2581\u2581\u2581 "] : ["- ", "\\ ", "| ", "/ "],
195
+ interval: 80
196
+ },
197
+ color: "gray"
198
+ });
199
+ return this;
200
+ }
201
+ #start(text) {
202
+ this.#_spinner.start(text);
203
+ this.#_disposeSpinnerExitHandler = registerExitHandler(
204
+ "Stopping spinner",
205
+ () => {
206
+ this.#_spinner.stop();
207
+ }
208
+ );
209
+ }
210
+ [Symbol.dispose]() {
211
+ this.#_disposeSpinnerExitHandler?.();
212
+ this.#_spinner.stop(
213
+ _Logger.#nonBlockingLogPrinted ? void 0 : `${infoSymbol} ${this.#_spinner.text}`
214
+ );
215
+ _Logger.#loggerInstance = void 0;
216
+ }
217
+ };
218
+
219
+ // schemas/pub-manifest/module/bcp.schema.json
220
+ var bcp_schema_default = {
221
+ $schema: "http://json-schema.org/draft-07/schema#",
222
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/bcp.schema.json",
223
+ title: "BCP47 Language tag",
224
+ type: "string",
225
+ pattern: "^((?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?:([A-Za-z]{2,3}(-(?:[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?:[A-Za-z]{4}))?(-(?:[A-Za-z]{2}|[0-9]{3}))?(-(?:[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?:[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?:x(-[A-Za-z0-9]{1,8})+))?)|(?:x(-[A-Za-z0-9]{1,8})+))$"
226
+ };
227
+
228
+ // schemas/pub-manifest/module/context.schema.json
229
+ var context_schema_default = {
230
+ $schema: "http://json-schema.org/draft-07/schema#",
231
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/context.schema.json",
232
+ title: "Publication Contexts",
233
+ type: "array",
234
+ items: [
235
+ {
236
+ const: "https://schema.org"
237
+ },
238
+ {
239
+ const: "https://www.w3.org/ns/pub-context"
240
+ }
241
+ ],
242
+ additionalItems: {
243
+ anyOf: [
244
+ {
245
+ type: "string"
246
+ },
247
+ {
248
+ type: "object",
249
+ properties: {
250
+ language: {
251
+ $ref: "bcp.schema.json"
252
+ },
253
+ direction: false
254
+ },
255
+ required: ["language"]
256
+ },
257
+ {
258
+ type: "object",
259
+ properties: {
260
+ direction: {
261
+ type: "string",
262
+ enum: ["ltr", "rtl"]
263
+ },
264
+ language: false
265
+ },
266
+ required: ["direction"]
267
+ },
268
+ {
269
+ type: "object",
270
+ properties: {
271
+ language: {
272
+ $ref: "bcp.schema.json"
273
+ },
274
+ direction: {
275
+ type: "string",
276
+ enum: ["ltr", "rtl"]
277
+ }
278
+ },
279
+ required: ["language", "direction"]
280
+ },
281
+ {
282
+ type: "object",
283
+ properties: {
284
+ language: false,
285
+ direction: false
286
+ }
287
+ }
288
+ ]
289
+ }
290
+ };
291
+
292
+ // schemas/pub-manifest/module/contributor-object.schema.json
293
+ var contributor_object_schema_default = {
294
+ $schema: "http://json-schema.org/draft-07/schema#",
295
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/contributor-object.schema.json",
296
+ title: "Contributor Object",
297
+ type: "object",
298
+ properties: {
299
+ name: {
300
+ $ref: "localizable.schema.json"
301
+ },
302
+ id: {
303
+ $ref: "url.schema.json"
304
+ },
305
+ type: {
306
+ oneOf: [
307
+ {
308
+ type: "string",
309
+ enum: ["Person", "Organization"],
310
+ default: "Person"
311
+ },
312
+ {
313
+ type: "array",
314
+ items: {
315
+ type: "string"
316
+ },
317
+ contains: {
318
+ enum: ["Person", "Organization"]
319
+ }
320
+ }
321
+ ]
322
+ },
323
+ url: {
324
+ $ref: "url.schema.json"
325
+ },
326
+ identifier: {
327
+ type: "array",
328
+ items: {
329
+ type: "string"
330
+ }
331
+ }
332
+ },
333
+ required: ["name"]
334
+ };
335
+
336
+ // schemas/pub-manifest/module/contributor.schema.json
337
+ var contributor_schema_default = {
338
+ $schema: "http://json-schema.org/draft-07/schema#",
339
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/contributor.schema.json",
340
+ title: "Contributor",
341
+ anyOf: [
342
+ {
343
+ type: "string"
344
+ },
345
+ {
346
+ type: "array",
347
+ items: {
348
+ anyOf: [
349
+ {
350
+ type: "string"
351
+ },
352
+ {
353
+ $ref: "contributor-object.schema.json"
354
+ }
355
+ ]
356
+ }
357
+ },
358
+ {
359
+ $ref: "contributor-object.schema.json"
360
+ }
361
+ ]
362
+ };
363
+
364
+ // schemas/pub-manifest/module/date.schema.json
365
+ var date_schema_default = {
366
+ $schema: "http://json-schema.org/draft-07/schema#",
367
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/date.schema.json",
368
+ title: "Dates",
369
+ type: "string",
370
+ format: "date-time"
371
+ };
372
+
373
+ // schemas/pub-manifest/module/duration.schema.json
374
+ var duration_schema_default = {
375
+ $schema: "http://json-schema.org/draft-07/schema#",
376
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/duration.schema.json",
377
+ title: "Duration",
378
+ type: "string",
379
+ pattern: "^P(?!$)((\\d+Y)|(\\d+\\.\\d+Y$))?((\\d+M)|(\\d+\\.\\d+M$))?((\\d+W)|(\\d+\\.\\d+W$))?((\\d+D)|(\\d+\\.\\d+D$))?(T(?=\\d)((\\d+H)|(\\d+\\.\\d+H$))?((\\d+M)|(\\d+\\.\\d+M$))?(\\d+(\\.\\d+)?S)?)??$"
380
+ };
381
+
382
+ // schemas/pub-manifest/module/item-lists.schema.json
383
+ var item_lists_schema_default = {
384
+ $schema: "http://json-schema.org/draft-07/schema#",
385
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/item-lists.schema.json",
386
+ title: "Lists of ItemList",
387
+ oneOf: [
388
+ {
389
+ $ref: "ItemList.schema.json"
390
+ },
391
+ {
392
+ type: "array",
393
+ items: {
394
+ $ref: "ItemList.schema.json"
395
+ }
396
+ }
397
+ ]
398
+ };
399
+
400
+ // schemas/pub-manifest/module/ItemList.schema.json
401
+ var ItemList_schema_default = {
402
+ $schema: "http://json-schema.org/draft-07/schema#",
403
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/ItemList.schema.json",
404
+ title: "schema.org ItemList object",
405
+ type: "object",
406
+ properties: {
407
+ type: {
408
+ oneOf: [
409
+ {
410
+ type: "string",
411
+ const: "ItemList"
412
+ },
413
+ {
414
+ type: "array",
415
+ items: {
416
+ type: "string"
417
+ },
418
+ contains: {
419
+ const: "ItemList"
420
+ }
421
+ }
422
+ ]
423
+ },
424
+ itemListElement: {
425
+ type: ["array"],
426
+ items: {
427
+ type: "string"
428
+ }
429
+ }
430
+ },
431
+ required: ["type", "itemListElement"]
432
+ };
433
+
434
+ // schemas/pub-manifest/module/language.schema.json
435
+ var language_schema_default = {
436
+ $schema: "http://json-schema.org/draft-07/schema#",
437
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/language.schema.json",
438
+ title: "Languages",
439
+ oneOf: [
440
+ {
441
+ $ref: "bcp.schema.json"
442
+ },
443
+ {
444
+ type: "array",
445
+ items: {
446
+ $ref: "bcp.schema.json"
447
+ }
448
+ }
449
+ ]
450
+ };
451
+
452
+ // schemas/pub-manifest/module/link.schema.json
453
+ var link_schema_default = {
454
+ $schema: "http://json-schema.org/draft-07/schema#",
455
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/link.schema.json",
456
+ title: "Publication Links",
457
+ type: "object",
458
+ properties: {
459
+ type: {
460
+ oneOf: [
461
+ {
462
+ type: "string",
463
+ const: "LinkedResource"
464
+ },
465
+ {
466
+ type: "array",
467
+ items: {
468
+ type: "string"
469
+ },
470
+ contains: {
471
+ const: "LinkedResource"
472
+ }
473
+ }
474
+ ]
475
+ },
476
+ url: {
477
+ $ref: "url.schema.json"
478
+ },
479
+ encodingFormat: {
480
+ type: "string"
481
+ },
482
+ name: {
483
+ $ref: "localizable.schema.json"
484
+ },
485
+ description: {
486
+ anyOf: [
487
+ {
488
+ type: "string"
489
+ },
490
+ {
491
+ $ref: "localizable-object.schema.json"
492
+ }
493
+ ]
494
+ },
495
+ rel: {
496
+ type: ["string", "array"],
497
+ items: {
498
+ type: "string"
499
+ }
500
+ },
501
+ integrity: {
502
+ type: "string"
503
+ },
504
+ duration: {
505
+ $ref: "duration.schema.json"
506
+ },
507
+ alternate: {
508
+ $ref: "resource.categorization.schema.json"
509
+ }
510
+ },
511
+ required: ["url"]
512
+ };
513
+
514
+ // schemas/pub-manifest/module/localizable-object.schema.json
515
+ var localizable_object_schema_default = {
516
+ $schema: "http://json-schema.org/draft-07/schema#",
517
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/localizable-object.schema.json",
518
+ title: "Localizable String Object",
519
+ type: "object",
520
+ properties: {
521
+ value: {
522
+ type: "string"
523
+ },
524
+ language: {
525
+ $ref: "bcp.schema.json"
526
+ }
527
+ },
528
+ required: ["value"]
529
+ };
530
+
531
+ // schemas/pub-manifest/module/localizable.schema.json
532
+ var localizable_schema_default = {
533
+ $schema: "http://json-schema.org/draft-07/schema#",
534
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/localizable.schema.json",
535
+ title: "Localizable String or Object",
536
+ anyOf: [
537
+ {
538
+ type: "string"
539
+ },
540
+ {
541
+ type: "array",
542
+ items: {
543
+ anyOf: [
544
+ {
545
+ type: "string"
546
+ },
547
+ {
548
+ $ref: "localizable-object.schema.json"
549
+ }
550
+ ]
551
+ }
552
+ },
553
+ {
554
+ $ref: "localizable-object.schema.json"
555
+ }
556
+ ]
557
+ };
558
+
559
+ // schemas/pub-manifest/module/resource.categorization.schema.json
560
+ var resource_categorization_schema_default = {
561
+ $schema: "http://json-schema.org/draft-07/schema#",
562
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/resource.categorization.schema.json",
563
+ title: "Resource Categorization",
564
+ oneOf: [
565
+ {
566
+ oneOf: [
567
+ {
568
+ $ref: "url.schema.json"
569
+ },
570
+ {
571
+ $ref: "link.schema.json"
572
+ }
573
+ ]
574
+ },
575
+ {
576
+ type: "array",
577
+ items: {
578
+ anyOf: [
579
+ {
580
+ $ref: "url.schema.json"
581
+ },
582
+ {
583
+ $ref: "link.schema.json"
584
+ }
585
+ ]
586
+ },
587
+ uniqueItems: true
588
+ }
589
+ ]
590
+ };
591
+
592
+ // schemas/pub-manifest/module/strings.schema.json
593
+ var strings_schema_default = {
594
+ $schema: "http://json-schema.org/draft-07/schema#",
595
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/strings.schema.json",
596
+ title: "Unique strings",
597
+ type: ["string", "array"],
598
+ items: {
599
+ type: "string"
600
+ }
601
+ };
602
+
603
+ // schemas/pub-manifest/module/url.schema.json
604
+ var url_schema_default = {
605
+ $schema: "http://json-schema.org/draft-07/schema#",
606
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/url.schema.json",
607
+ title: "URL",
608
+ type: "string",
609
+ format: "uri-reference"
610
+ };
611
+
612
+ // schemas/pub-manifest/module/urls.schema.json
613
+ var urls_schema_default = {
614
+ $schema: "http://json-schema.org/draft-07/schema#",
615
+ $id: "https://www.w3.org/ns/pub-schema/manifest/module/urls.schema.json",
616
+ title: "URLs",
617
+ oneOf: [
618
+ {
619
+ type: "string",
620
+ format: "uri-reference"
621
+ },
622
+ {
623
+ type: "array",
624
+ items: {
625
+ type: "string",
626
+ format: "uri-reference"
627
+ }
628
+ }
629
+ ]
630
+ };
631
+
632
+ // schemas/pub-manifest/publication.schema.json
633
+ var publication_schema_default = {
634
+ $schema: "http://json-schema.org/draft-07/schema#",
635
+ $id: "https://www.w3.org/ns/pub-schema/manifest/publication.schema.json",
636
+ title: "Publication Manifest",
637
+ type: "object",
638
+ properties: {
639
+ "@context": {
640
+ $ref: "module/context.schema.json"
641
+ },
642
+ type: {
643
+ type: ["string", "array"],
644
+ items: {
645
+ type: "string"
646
+ }
647
+ },
648
+ conformsTo: {
649
+ oneOf: [
650
+ {
651
+ $ref: "module/url.schema.json"
652
+ },
653
+ {
654
+ type: "array",
655
+ items: {
656
+ $ref: "module/url.schema.json"
657
+ }
658
+ }
659
+ ]
660
+ },
661
+ id: {
662
+ type: "string"
663
+ },
664
+ abridged: {
665
+ type: "boolean"
666
+ },
667
+ accessMode: {
668
+ $ref: "module/strings.schema.json"
669
+ },
670
+ accessModeSufficient: {
671
+ $ref: "module/item-lists.schema.json"
672
+ },
673
+ accessibilityFeature: {
674
+ $ref: "module/strings.schema.json"
675
+ },
676
+ accessibilityHazard: {
677
+ $ref: "module/strings.schema.json"
678
+ },
679
+ accessibilitySummary: {
680
+ $ref: "module/localizable.schema.json"
681
+ },
682
+ artist: {
683
+ $ref: "module/contributor.schema.json"
684
+ },
685
+ author: {
686
+ $ref: "module/contributor.schema.json"
687
+ },
688
+ colorist: {
689
+ $ref: "module/contributor.schema.json"
690
+ },
691
+ contributor: {
692
+ $ref: "module/contributor.schema.json"
693
+ },
694
+ creator: {
695
+ $ref: "module/contributor.schema.json"
696
+ },
697
+ editor: {
698
+ $ref: "module/contributor.schema.json"
699
+ },
700
+ illustrator: {
701
+ $ref: "module/contributor.schema.json"
702
+ },
703
+ inker: {
704
+ $ref: "module/contributor.schema.json"
705
+ },
706
+ letterer: {
707
+ $ref: "module/contributor.schema.json"
708
+ },
709
+ penciler: {
710
+ $ref: "module/contributor.schema.json"
711
+ },
712
+ publisher: {
713
+ $ref: "module/contributor.schema.json"
714
+ },
715
+ readBy: {
716
+ $ref: "module/contributor.schema.json"
717
+ },
718
+ translator: {
719
+ $ref: "module/contributor.schema.json"
720
+ },
721
+ url: {
722
+ $ref: "module/urls.schema.json"
723
+ },
724
+ duration: {
725
+ $ref: "module/duration.schema.json"
726
+ },
727
+ inLanguage: {
728
+ $ref: "module/language.schema.json"
729
+ },
730
+ dateModified: {
731
+ $ref: "module/date.schema.json"
732
+ },
733
+ datePublished: {
734
+ $ref: "module/date.schema.json"
735
+ },
736
+ name: {
737
+ $ref: "module/localizable.schema.json"
738
+ },
739
+ readingOrder: {
740
+ $ref: "module/resource.categorization.schema.json"
741
+ },
742
+ resources: {
743
+ $ref: "module/resource.categorization.schema.json"
744
+ },
745
+ links: {
746
+ $ref: "module/resource.categorization.schema.json"
747
+ },
748
+ readingProgression: {
749
+ type: "string",
750
+ enum: ["ltr", "rtl"],
751
+ default: "ltr"
752
+ }
753
+ },
754
+ required: ["@context", "conformsTo"]
755
+ };
756
+
757
+ // src/schema/pub-manifest.ts
758
+ var publicationSchemas = [
759
+ bcp_schema_default,
760
+ context_schema_default,
761
+ contributor_object_schema_default,
762
+ contributor_schema_default,
763
+ date_schema_default,
764
+ duration_schema_default,
765
+ item_lists_schema_default,
766
+ ItemList_schema_default,
767
+ language_schema_default,
768
+ link_schema_default,
769
+ localizable_object_schema_default,
770
+ localizable_schema_default,
771
+ resource_categorization_schema_default,
772
+ strings_schema_default,
773
+ url_schema_default,
774
+ urls_schema_default,
775
+ publication_schema_default
776
+ ];
777
+
778
+ // src/util.ts
779
+ var cwd = upath.normalize(process.cwd());
780
+ var beforeExitHandlers = [];
781
+ var registerExitHandler = (debugMessage, handler) => {
782
+ const callback = () => {
783
+ Logger.debug(debugMessage);
784
+ handler();
785
+ };
786
+ beforeExitHandlers.push(callback);
787
+ return () => {
788
+ const index = beforeExitHandlers.indexOf(callback);
789
+ if (index !== -1) {
790
+ beforeExitHandlers.splice(index, 1);
791
+ }
792
+ };
793
+ };
794
+ function runExitHandlers() {
795
+ while (beforeExitHandlers.length) {
796
+ try {
797
+ beforeExitHandlers.shift()?.();
798
+ } catch (e) {
799
+ }
800
+ }
801
+ }
802
+ var exitSignals = ["exit", "SIGINT", "SIGTERM"];
803
+ exitSignals.forEach((sig) => {
804
+ process.once(sig, (signal, exitCode) => {
805
+ runExitHandlers();
806
+ if (process.exitCode === void 0) {
807
+ process.exitCode = exitCode !== void 0 ? 128 + exitCode : Number(signal);
808
+ }
809
+ process.exit();
810
+ });
811
+ });
812
+ if (process.platform === "win32") {
813
+ const rl = readline.createInterface({
814
+ input: process.stdin,
815
+ output: process.stdout
816
+ });
817
+ rl.on("SIGINT", () => {
818
+ runExitHandlers();
819
+ process.exit(1);
820
+ });
821
+ registerExitHandler("Closing readline interface", () => {
822
+ rl.close();
823
+ });
824
+ }
825
+ var DetailError = class extends Error {
826
+ constructor(message, detail) {
827
+ super(message);
828
+ this.detail = detail;
829
+ }
830
+ };
831
+ function getFormattedError(err) {
832
+ return err instanceof DetailError ? `${err.message}
833
+ ${err.detail}` : err.stack || `${err.message}`;
834
+ }
835
+ function gracefulError(err) {
836
+ console.log(`${redBright2("ERROR")} ${getFormattedError(err)}
837
+
838
+ ${gray2("If you think this is a bug, please report at https://github.com/vivliostyle/vivliostyle-cli/issues")}`);
839
+ process.exit(1);
840
+ }
841
+ function readJSON(path) {
842
+ try {
843
+ return JSON.parse(fs.readFileSync(path, "utf8"));
844
+ } catch (err) {
845
+ return void 0;
846
+ }
847
+ }
848
+ function statFileSync(filePath, {
849
+ errorMessage = "Specified input does not exist"
850
+ } = {}) {
851
+ try {
852
+ return fs.statSync(filePath);
853
+ } catch (err) {
854
+ if (err.code === "ENOENT") {
855
+ throw new Error(`${errorMessage}: ${filePath}`);
856
+ }
857
+ throw err;
858
+ }
859
+ }
860
+ async function inflateZip(filePath, dest) {
861
+ return await new Promise((res, rej) => {
862
+ try {
863
+ const zip = new StreamZip({
864
+ file: filePath,
865
+ storeEntries: true
866
+ });
867
+ zip.on("error", (err) => {
868
+ rej(err);
869
+ });
870
+ zip.on("ready", async () => {
871
+ await util.promisify(zip.extract)(null, dest);
872
+ await util.promisify(zip.close)();
873
+ Logger.debug(`Unzipped ${filePath} to ${dest}`);
874
+ res();
875
+ });
876
+ } catch (err) {
877
+ rej(err);
878
+ }
879
+ });
880
+ }
881
+ function useTmpDirectory() {
882
+ return new Promise((res, rej) => {
883
+ tmp.dir({ unsafeCleanup: true }, (err, path, clear) => {
884
+ if (err) {
885
+ return rej(err);
886
+ }
887
+ Logger.debug(`Created the temporary directory: ${path}`);
888
+ if (import.meta.env?.VITEST) {
889
+ return res([path, () => {
890
+ }]);
891
+ }
892
+ const callback = () => {
893
+ fs.rmSync(path, { force: true, recursive: true });
894
+ };
895
+ registerExitHandler(
896
+ `Removing the temporary directory: ${path}`,
897
+ callback
898
+ );
899
+ res([path, callback]);
900
+ });
901
+ });
902
+ }
903
+ function touchTmpFile(path) {
904
+ fs.mkdirSync(upath.dirname(path), { recursive: true });
905
+ fs.closeSync(fs.openSync(path, "a"));
906
+ Logger.debug(`Created the temporary file: ${path}`);
907
+ const callback = () => {
908
+ fs.rmSync(path, { force: true, recursive: true });
909
+ };
910
+ registerExitHandler(`Removing the temporary file: ${path}`, callback);
911
+ return callback;
912
+ }
913
+ function pathEquals(path1, path2) {
914
+ return upath.relative(path1, path2) === "";
915
+ }
916
+ function pathContains(parentPath, childPath) {
917
+ const rel = upath.relative(parentPath, childPath);
918
+ return rel !== "" && !rel.startsWith("..");
919
+ }
920
+ function isValidUri(str) {
921
+ return /^(https?|file|data):/i.test(str);
922
+ }
923
+ function isInContainer() {
924
+ return fs.existsSync("/opt/vivliostyle-cli/.vs-cli-version");
925
+ }
926
+ function isRunningOnWSL() {
927
+ return fs.existsSync("/proc/version") && fs.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
928
+ }
929
+ async function openEpub(epubPath, tmpDir) {
930
+ await inflateZip(epubPath, tmpDir);
931
+ Logger.debug(`Created the temporary EPUB directory: ${tmpDir}`);
932
+ const deleteEpub = () => {
933
+ fs.rmSync(tmpDir, { force: true, recursive: true });
934
+ };
935
+ registerExitHandler(
936
+ `Removing the temporary EPUB directory: ${tmpDir}`,
937
+ deleteEpub
938
+ );
939
+ return deleteEpub;
940
+ }
941
+ function getDefaultEpubOpfPath(epubDir) {
942
+ const containerXmlPath = upath.join(epubDir, "META-INF/container.xml");
943
+ const xmlParser = new XMLParser({
944
+ ignoreAttributes: false
945
+ });
946
+ const { container } = xmlParser.parse(
947
+ fs.readFileSync(containerXmlPath, "utf8")
948
+ );
949
+ const rootfile = [container.rootfiles.rootfile].flat()[0];
950
+ const epubOpfPath = upath.join(epubDir, rootfile["@_full-path"]);
951
+ return epubOpfPath;
952
+ }
953
+ function getEpubRootDir(epubOpfPath) {
954
+ function traverse(dir) {
955
+ const files = fs.readdirSync(dir);
956
+ if (files.includes("META-INF") && pathEquals(epubOpfPath, getDefaultEpubOpfPath(dir))) {
957
+ return dir;
958
+ }
959
+ const next = upath.dirname(dir);
960
+ if (pathEquals(dir, next)) {
961
+ return;
962
+ }
963
+ return traverse(next);
964
+ }
965
+ return traverse(upath.dirname(epubOpfPath));
966
+ }
967
+ var getAjvValidatorFunction = (schema, refSchemas) => (obj) => {
968
+ const ajv = new Ajv({ strict: false });
969
+ const addFormats = formatsPlugin;
970
+ addFormats(ajv);
971
+ if (refSchemas) {
972
+ ajv.addSchema(refSchemas);
973
+ }
974
+ const validate = ajv.compile(schema);
975
+ const valid = validate(obj);
976
+ if (!valid) {
977
+ throw validate.errors?.[0] || new Error();
978
+ }
979
+ return true;
980
+ };
981
+ var assertPubManifestSchema = getAjvValidatorFunction(
982
+ publication_schema_default,
983
+ publicationSchemas
984
+ );
985
+ function parseJsonc(rawJsonc) {
986
+ const ast = parse(rawJsonc, {
987
+ mode: "jsonc",
988
+ ranges: false,
989
+ tokens: false
990
+ });
991
+ return evaluate(ast);
992
+ }
993
+ function prettifySchemaError(rawJsonc, issues) {
994
+ const parsed = parse(rawJsonc, {
995
+ mode: "jsonc",
996
+ ranges: false,
997
+ tokens: false
998
+ });
999
+ function traverse(issues2, depth) {
1000
+ return issues2.flatMap((issue) => {
1001
+ const p = issue.path?.length || 0;
1002
+ if (!issue.issues) {
1003
+ return [[[issue], depth + p]];
1004
+ }
1005
+ return traverse(issue.issues, depth + p).map(([i, d]) => [
1006
+ [issue, ...i],
1007
+ d
1008
+ ]);
1009
+ });
1010
+ }
1011
+ const all = traverse(issues, 0);
1012
+ const maxDepth = Math.max(...all.map(([, d]) => d));
1013
+ const issuesTraversed = all.find(([, d]) => d === maxDepth)[0];
1014
+ let jsonValue = parsed.body;
1015
+ for (const p of issuesTraversed.flatMap((v2) => v2.path ?? [])) {
1016
+ let childValue;
1017
+ if (p.type === "object" && jsonValue.type === "Object") {
1018
+ childValue = jsonValue.members.find(
1019
+ (m) => m.name.type === "Identifier" && m.name.name === p.key || m.name.type === "String" && m.name.value === p.key
1020
+ )?.value;
1021
+ }
1022
+ if (p.type === "array" && jsonValue.type === "Array") {
1023
+ childValue = jsonValue.elements[p.key]?.value;
1024
+ }
1025
+ if (childValue) {
1026
+ jsonValue = childValue;
1027
+ } else {
1028
+ break;
1029
+ }
1030
+ }
1031
+ let message = `${red(issuesTraversed.at(-1).message)}`;
1032
+ if (jsonValue) {
1033
+ message += `
1034
+ ${codeFrameColumns(rawJsonc, jsonValue.loc, {
1035
+ highlightCode: true
1036
+ })}`;
1037
+ }
1038
+ return message;
1039
+ }
1040
+ function writeFileIfChanged(filePath, content) {
1041
+ if (!fs.existsSync(filePath) || !fs.readFileSync(filePath).equals(content)) {
1042
+ fs.mkdirSync(upath.dirname(filePath), { recursive: true });
1043
+ fs.writeFileSync(filePath, content);
1044
+ }
1045
+ }
1046
+
1047
+ // src/commands/cli-flags.ts
1048
+ import upath2 from "upath";
1049
+ import * as v from "valibot";
1050
+ function parseFlagsToInlineConfig(argv, setupProgram) {
1051
+ const program = setupProgram();
1052
+ program.parse(argv);
1053
+ let options = program.opts();
1054
+ const input = program.args?.[0];
1055
+ options = warnDeprecatedFlags(options);
1056
+ let inlineConfig = { input, ...options };
1057
+ if (input && !options.config && upath2.basename(input).startsWith("vivliostyle.config")) {
1058
+ inlineConfig = { config: input, ...options };
1059
+ }
1060
+ return v.parse(VivliostyleInlineConfig, inlineConfig);
1061
+ }
1062
+ function setupConfigFromFlags(flags) {
1063
+ if (!flags.input) {
1064
+ if (flags.enableViewerStartPage) {
1065
+ return {
1066
+ tasks: [{ entry: [] }],
1067
+ inlineOptions: {
1068
+ input: { format: "webbook", entry: EMPTY_DATA_URI }
1069
+ }
1070
+ };
1071
+ } else {
1072
+ throw new Error(
1073
+ "No input is set. Please set an appropriate entry or a Vivliostyle config file."
1074
+ );
1075
+ }
1076
+ }
1077
+ return {
1078
+ tasks: [{ entry: [] }],
1079
+ inlineOptions: {}
1080
+ };
1081
+ }
1082
+ function warnDeprecatedFlags(options) {
1083
+ const modifiedOptions = { ...options };
1084
+ if (options.executableChromium) {
1085
+ Logger.logWarn(
1086
+ "'--executable-chromium' option was deprecated and will be removed in a future release. Please replace with '--executable-browser' option."
1087
+ );
1088
+ modifiedOptions.executableBrowser = options.executableChromium;
1089
+ }
1090
+ if (options.verbose) {
1091
+ Logger.logWarn(
1092
+ "'--verbose' option was deprecated and will be removed in a future release. Please replace with '--log-level verbose' option."
1093
+ );
1094
+ modifiedOptions.logLevel = "verbose";
1095
+ }
1096
+ if (options.sandbox === false) {
1097
+ Logger.logWarn(
1098
+ "'--no-sandbox' option was deprecated and will be removed in a future release. It is no longer necessary because the sandbox is disabled by default."
1099
+ );
1100
+ }
1101
+ if (options.http) {
1102
+ Logger.logWarn(
1103
+ "'--http' option was deprecated and will be removed in a future release. It is unnecessary because the HTTP server starts automatically."
1104
+ );
1105
+ }
1106
+ return modifiedOptions;
1107
+ }
1108
+
1109
+ export {
1110
+ cwd,
1111
+ registerExitHandler,
1112
+ runExitHandlers,
1113
+ DetailError,
1114
+ getFormattedError,
1115
+ gracefulError,
1116
+ readJSON,
1117
+ statFileSync,
1118
+ useTmpDirectory,
1119
+ touchTmpFile,
1120
+ pathEquals,
1121
+ pathContains,
1122
+ isValidUri,
1123
+ isInContainer,
1124
+ isRunningOnWSL,
1125
+ openEpub,
1126
+ getDefaultEpubOpfPath,
1127
+ getEpubRootDir,
1128
+ assertPubManifestSchema,
1129
+ parseJsonc,
1130
+ prettifySchemaError,
1131
+ writeFileIfChanged,
1132
+ isUnicodeSupported,
1133
+ randomBookSymbol,
1134
+ Logger,
1135
+ parseFlagsToInlineConfig,
1136
+ setupConfigFromFlags
1137
+ };
1138
+ //# sourceMappingURL=chunk-7BGVK3JL.js.map