@vivliostyle/cli 9.0.0-next.3 → 9.0.0-next.5

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 (186) hide show
  1. package/dist/chunk-4ZNBH6IA.js +74 -0
  2. package/dist/{core/init.js → chunk-6ETFX7W2.js} +39 -27
  3. package/dist/chunk-BIEQXUOY.js +50 -0
  4. package/dist/chunk-BPSQMFSC.js +54 -0
  5. package/dist/chunk-BT47BDZK.js +85 -0
  6. package/dist/chunk-DMARNPN5.js +1073 -0
  7. package/dist/chunk-EX7EA34F.js +64 -0
  8. package/dist/chunk-SPYTZBBG.js +4988 -0
  9. package/dist/chunk-UQHNZL7X.js +590 -0
  10. package/dist/chunk-WX6JHPSL.js +16 -0
  11. package/dist/cli.d.ts +0 -2
  12. package/dist/cli.js +17 -18
  13. package/dist/commands/build.d.ts +2 -2
  14. package/dist/commands/build.js +165 -17
  15. package/dist/commands/init.d.ts +2 -2
  16. package/dist/commands/init.js +35 -12
  17. package/dist/commands/preview.d.ts +2 -2
  18. package/dist/commands/preview.js +98 -12
  19. package/dist/config/schema.d.ts +225 -218
  20. package/dist/config/schema.js +50 -588
  21. package/dist/index.d.ts +326 -8
  22. package/dist/index.js +47 -42
  23. package/dist/node-modules.d.ts +21 -0
  24. package/dist/node-modules.js +9 -0
  25. package/dist/vite-adapter.d.ts +8 -2
  26. package/dist/vite-adapter.js +11 -43
  27. package/package.json +32 -13
  28. package/dist/browser.d.ts +0 -19
  29. package/dist/browser.d.ts.map +0 -1
  30. package/dist/browser.js +0 -154
  31. package/dist/browser.js.map +0 -1
  32. package/dist/cli.d.ts.map +0 -1
  33. package/dist/cli.js.map +0 -1
  34. package/dist/commands/build.d.ts.map +0 -1
  35. package/dist/commands/build.js.map +0 -1
  36. package/dist/commands/build.parser.d.ts +0 -3
  37. package/dist/commands/build.parser.d.ts.map +0 -1
  38. package/dist/commands/build.parser.js +0 -104
  39. package/dist/commands/build.parser.js.map +0 -1
  40. package/dist/commands/cli-flags.d.ts +0 -42
  41. package/dist/commands/cli-flags.d.ts.map +0 -1
  42. package/dist/commands/cli-flags.js +0 -58
  43. package/dist/commands/cli-flags.js.map +0 -1
  44. package/dist/commands/init.d.ts.map +0 -1
  45. package/dist/commands/init.js.map +0 -1
  46. package/dist/commands/init.parser.d.ts +0 -3
  47. package/dist/commands/init.parser.d.ts.map +0 -1
  48. package/dist/commands/init.parser.js +0 -17
  49. package/dist/commands/init.parser.js.map +0 -1
  50. package/dist/commands/preview.d.ts.map +0 -1
  51. package/dist/commands/preview.js.map +0 -1
  52. package/dist/commands/preview.parser.d.ts +0 -3
  53. package/dist/commands/preview.parser.d.ts.map +0 -1
  54. package/dist/commands/preview.parser.js +0 -52
  55. package/dist/commands/preview.parser.js.map +0 -1
  56. package/dist/config/load.d.ts +0 -4
  57. package/dist/config/load.d.ts.map +0 -1
  58. package/dist/config/load.js +0 -75
  59. package/dist/config/load.js.map +0 -1
  60. package/dist/config/merge.d.ts +0 -4
  61. package/dist/config/merge.d.ts.map +0 -1
  62. package/dist/config/merge.js +0 -59
  63. package/dist/config/merge.js.map +0 -1
  64. package/dist/config/resolve.d.ts +0 -205
  65. package/dist/config/resolve.d.ts.map +0 -1
  66. package/dist/config/resolve.js +0 -770
  67. package/dist/config/resolve.js.map +0 -1
  68. package/dist/config/schema.d.ts.map +0 -1
  69. package/dist/config/schema.js.map +0 -1
  70. package/dist/config/vite.d.ts +0 -6
  71. package/dist/config/vite.d.ts.map +0 -1
  72. package/dist/config/vite.js +0 -49
  73. package/dist/config/vite.js.map +0 -1
  74. package/dist/const.d.ts +0 -20
  75. package/dist/const.d.ts.map +0 -1
  76. package/dist/const.js +0 -41
  77. package/dist/const.js.map +0 -1
  78. package/dist/container.d.ts +0 -21
  79. package/dist/container.d.ts.map +0 -1
  80. package/dist/container.js +0 -175
  81. package/dist/container.js.map +0 -1
  82. package/dist/core/build.d.ts +0 -3
  83. package/dist/core/build.d.ts.map +0 -1
  84. package/dist/core/build.js +0 -168
  85. package/dist/core/build.js.map +0 -1
  86. package/dist/core/init.d.ts +0 -3
  87. package/dist/core/init.d.ts.map +0 -1
  88. package/dist/core/init.js.map +0 -1
  89. package/dist/core/preview.d.ts +0 -4
  90. package/dist/core/preview.d.ts.map +0 -1
  91. package/dist/core/preview.js +0 -114
  92. package/dist/core/preview.js.map +0 -1
  93. package/dist/index.d.ts.map +0 -1
  94. package/dist/index.js.map +0 -1
  95. package/dist/logger.d.ts +0 -30
  96. package/dist/logger.d.ts.map +0 -1
  97. package/dist/logger.js +0 -172
  98. package/dist/logger.js.map +0 -1
  99. package/dist/output/epub.d.ts +0 -10
  100. package/dist/output/epub.d.ts.map +0 -1
  101. package/dist/output/epub.js +0 -505
  102. package/dist/output/epub.js.map +0 -1
  103. package/dist/output/pdf-postprocess.d.ts +0 -30
  104. package/dist/output/pdf-postprocess.d.ts.map +0 -1
  105. package/dist/output/pdf-postprocess.js +0 -270
  106. package/dist/output/pdf-postprocess.js.map +0 -1
  107. package/dist/output/pdf.d.ts +0 -6
  108. package/dist/output/pdf.d.ts.map +0 -1
  109. package/dist/output/pdf.js +0 -200
  110. package/dist/output/pdf.js.map +0 -1
  111. package/dist/output/webbook.d.ts +0 -45
  112. package/dist/output/webbook.d.ts.map +0 -1
  113. package/dist/output/webbook.js +0 -413
  114. package/dist/output/webbook.js.map +0 -1
  115. package/dist/processor/compile.d.ts +0 -30
  116. package/dist/processor/compile.d.ts.map +0 -1
  117. package/dist/processor/compile.js +0 -348
  118. package/dist/processor/compile.js.map +0 -1
  119. package/dist/processor/html.d.ts +0 -107
  120. package/dist/processor/html.d.ts.map +0 -1
  121. package/dist/processor/html.js +0 -494
  122. package/dist/processor/html.js.map +0 -1
  123. package/dist/processor/markdown.d.ts +0 -12
  124. package/dist/processor/markdown.d.ts.map +0 -1
  125. package/dist/processor/markdown.js +0 -23
  126. package/dist/processor/markdown.js.map +0 -1
  127. package/dist/processor/theme.d.ts +0 -4
  128. package/dist/processor/theme.d.ts.map +0 -1
  129. package/dist/processor/theme.js +0 -41
  130. package/dist/processor/theme.js.map +0 -1
  131. package/dist/schema/pub-manifest.d.ts +0 -4
  132. package/dist/schema/pub-manifest.d.ts.map +0 -1
  133. package/dist/schema/pub-manifest.js +0 -41
  134. package/dist/schema/pub-manifest.js.map +0 -1
  135. package/dist/schema/publication.schema.d.ts +0 -104
  136. package/dist/schema/publication.schema.d.ts.map +0 -1
  137. package/dist/schema/publication.schema.js +0 -8
  138. package/dist/schema/publication.schema.js.map +0 -1
  139. package/dist/server.d.ts +0 -20
  140. package/dist/server.d.ts.map +0 -1
  141. package/dist/server.js +0 -126
  142. package/dist/server.js.map +0 -1
  143. package/dist/util.d.ts +0 -55
  144. package/dist/util.d.ts.map +0 -1
  145. package/dist/util.js +0 -274
  146. package/dist/util.js.map +0 -1
  147. package/dist/vite/plugin-util.d.ts +0 -6
  148. package/dist/vite/plugin-util.d.ts.map +0 -1
  149. package/dist/vite/plugin-util.js +0 -18
  150. package/dist/vite/plugin-util.js.map +0 -1
  151. package/dist/vite/vite-plugin-browser.d.ts +0 -8
  152. package/dist/vite/vite-plugin-browser.d.ts.map +0 -1
  153. package/dist/vite/vite-plugin-browser.js +0 -54
  154. package/dist/vite/vite-plugin-browser.js.map +0 -1
  155. package/dist/vite/vite-plugin-dev-server.d.ts +0 -8
  156. package/dist/vite/vite-plugin-dev-server.d.ts.map +0 -1
  157. package/dist/vite/vite-plugin-dev-server.js +0 -270
  158. package/dist/vite/vite-plugin-dev-server.js.map +0 -1
  159. package/dist/vite/vite-plugin-static-serve.d.ts +0 -8
  160. package/dist/vite/vite-plugin-static-serve.d.ts.map +0 -1
  161. package/dist/vite/vite-plugin-static-serve.js +0 -31
  162. package/dist/vite/vite-plugin-static-serve.js.map +0 -1
  163. package/dist/vite/vite-plugin-viewer.d.ts +0 -8
  164. package/dist/vite/vite-plugin-viewer.d.ts.map +0 -1
  165. package/dist/vite/vite-plugin-viewer.js +0 -52
  166. package/dist/vite/vite-plugin-viewer.js.map +0 -1
  167. package/dist/vite-adapter.d.ts.map +0 -1
  168. package/dist/vite-adapter.js.map +0 -1
  169. package/schemas/pub-manifest/README.md +0 -5
  170. package/schemas/pub-manifest/module/ItemList.schema.json +0 -32
  171. package/schemas/pub-manifest/module/bcp.schema.json +0 -7
  172. package/schemas/pub-manifest/module/context.schema.json +0 -62
  173. package/schemas/pub-manifest/module/contributor-object.schema.json +0 -42
  174. package/schemas/pub-manifest/module/contributor.schema.json +0 -26
  175. package/schemas/pub-manifest/module/date.schema.json +0 -7
  176. package/schemas/pub-manifest/module/duration.schema.json +0 -7
  177. package/schemas/pub-manifest/module/item-lists.schema.json +0 -16
  178. package/schemas/pub-manifest/module/language.schema.json +0 -16
  179. package/schemas/pub-manifest/module/link.schema.json +0 -60
  180. package/schemas/pub-manifest/module/localizable-object.schema.json +0 -15
  181. package/schemas/pub-manifest/module/localizable.schema.json +0 -26
  182. package/schemas/pub-manifest/module/resource.categorization.schema.json +0 -31
  183. package/schemas/pub-manifest/module/strings.schema.json +0 -9
  184. package/schemas/pub-manifest/module/url.schema.json +0 -7
  185. package/schemas/pub-manifest/module/urls.schema.json +0 -18
  186. package/schemas/pub-manifest/publication.schema.json +0 -123
@@ -0,0 +1,590 @@
1
+ import {
2
+ resolveViteConfig
3
+ } from "./chunk-4ZNBH6IA.js";
4
+ import {
5
+ Logger,
6
+ buildPDFWithContainer,
7
+ buildWebPublication,
8
+ cleanupWorkspace,
9
+ collectVolumeArgs,
10
+ compile,
11
+ copyAssets,
12
+ createViteServer,
13
+ cwd,
14
+ getFullBrowserName,
15
+ getViewerFullUrl,
16
+ isInContainer,
17
+ isUnicodeSupported,
18
+ isWebPubConfig,
19
+ launchPreview,
20
+ loadVivliostyleConfig,
21
+ mergeInlineConfig,
22
+ pathEquals,
23
+ prepareThemeDirectory,
24
+ randomBookSymbol,
25
+ resolveTaskConfig,
26
+ runContainer,
27
+ runExitHandlers,
28
+ setupConfigFromFlags,
29
+ toContainerPath,
30
+ warnDeprecatedConfig
31
+ } from "./chunk-SPYTZBBG.js";
32
+ import {
33
+ coreVersion
34
+ } from "./chunk-EX7EA34F.js";
35
+ import {
36
+ importNodeModule
37
+ } from "./chunk-WX6JHPSL.js";
38
+ import {
39
+ __callDispose,
40
+ __using
41
+ } from "./chunk-BIEQXUOY.js";
42
+
43
+ // src/core/build.ts
44
+ import { pathToFileURL } from "node:url";
45
+ import terminalLink2 from "terminal-link";
46
+ import upath3 from "upath";
47
+ import { build as viteBuild } from "vite";
48
+ import { cyan as cyan2 } from "yoctocolors";
49
+
50
+ // src/output/pdf.ts
51
+ import fs2 from "node:fs";
52
+ import { URL } from "node:url";
53
+ import terminalLink from "terminal-link";
54
+ import upath2 from "upath";
55
+ import { cyan, gray, green, red } from "yoctocolors";
56
+
57
+ // src/output/pdf-postprocess.ts
58
+ import decamelize from "decamelize";
59
+ import fs from "node:fs";
60
+ import os from "node:os";
61
+ import upath from "upath";
62
+ import { v1 as uuid } from "uuid";
63
+ var prefixes = {
64
+ dcterms: "http://purl.org/dc/terms/",
65
+ meta: "http://idpf.org/epub/vocab/package/meta/#"
66
+ };
67
+ var metaTerms = {
68
+ title: `${prefixes.dcterms}title`,
69
+ creator: `${prefixes.dcterms}creator`,
70
+ description: `${prefixes.dcterms}description`,
71
+ subject: `${prefixes.dcterms}subject`,
72
+ contributor: `${prefixes.dcterms}contributor`,
73
+ language: `${prefixes.dcterms}language`,
74
+ role: `${prefixes.meta}role`,
75
+ created: `${prefixes.meta}created`,
76
+ date: `${prefixes.meta}date`
77
+ };
78
+ async function pressReadyWithContainer({
79
+ input,
80
+ output,
81
+ preflightOption,
82
+ image
83
+ }) {
84
+ await runContainer({
85
+ image,
86
+ entrypoint: "press-ready",
87
+ userVolumeArgs: collectVolumeArgs([
88
+ upath.dirname(input),
89
+ upath.dirname(output)
90
+ ]),
91
+ commandArgs: [
92
+ "build",
93
+ "-i",
94
+ toContainerPath(input),
95
+ "-o",
96
+ toContainerPath(output),
97
+ ...preflightOption.map((opt) => `--${decamelize(opt, { separator: "-" })}`).filter((str) => /^[\w-]+/.test(str))
98
+ ]
99
+ });
100
+ }
101
+ var PostProcess = class _PostProcess {
102
+ constructor(document2) {
103
+ this.document = document2;
104
+ }
105
+ static async load(pdf) {
106
+ const { PDFDocument } = await importNodeModule("pdf-lib");
107
+ const document2 = await PDFDocument.load(pdf, { updateMetadata: false });
108
+ return new _PostProcess(document2);
109
+ }
110
+ async save(output, { preflight, preflightOption, image }) {
111
+ const input = preflight ? upath.join(os.tmpdir(), `vivliostyle-cli-${uuid()}.pdf`) : output;
112
+ const pdf = await this.document.save();
113
+ await fs.promises.writeFile(input, pdf);
114
+ if (preflight === "press-ready-local" || preflight === "press-ready" && isInContainer()) {
115
+ var _stack = [];
116
+ try {
117
+ const _3 = __using(_stack, Logger.suspendLogging("Running press-ready"));
118
+ const { build: build2 } = await importNodeModule("press-ready");
119
+ await build2({
120
+ ...preflightOption.reduce((acc, opt) => {
121
+ const optName = decamelize(opt, { separator: "-" });
122
+ return optName.startsWith("no-") ? {
123
+ ...acc,
124
+ [optName.slice(3)]: false
125
+ } : {
126
+ ...acc,
127
+ [optName]: true
128
+ };
129
+ }, {}),
130
+ input,
131
+ output
132
+ });
133
+ } catch (_) {
134
+ var _error = _, _hasError = true;
135
+ } finally {
136
+ __callDispose(_stack, _error, _hasError);
137
+ }
138
+ } else if (preflight === "press-ready") {
139
+ var _stack2 = [];
140
+ try {
141
+ const _3 = __using(_stack2, Logger.suspendLogging("Running press-ready"));
142
+ await pressReadyWithContainer({
143
+ input,
144
+ output,
145
+ preflightOption,
146
+ image
147
+ });
148
+ } catch (_2) {
149
+ var _error2 = _2, _hasError2 = true;
150
+ } finally {
151
+ __callDispose(_stack2, _error2, _hasError2);
152
+ }
153
+ }
154
+ }
155
+ async metadata(tree, {
156
+ pageProgression,
157
+ browserVersion,
158
+ viewerCoreVersion,
159
+ disableCreatorOption
160
+ } = {}) {
161
+ const { ReadingDirection } = await importNodeModule("pdf-lib");
162
+ const title = tree[metaTerms.title]?.[0].v;
163
+ if (title) {
164
+ this.document.setTitle(title);
165
+ }
166
+ const author = tree[metaTerms.creator]?.map((item) => item.v)?.join("; ");
167
+ if (author) {
168
+ this.document.setAuthor(author);
169
+ }
170
+ const subject = tree[metaTerms.description]?.[0].v;
171
+ if (subject) {
172
+ this.document.setSubject(subject);
173
+ }
174
+ const keywords = tree[metaTerms.subject]?.map((item) => item.v);
175
+ if (keywords) {
176
+ this.document.setKeywords(keywords);
177
+ }
178
+ let creatorOpt = `Vivliostyle.js ${viewerCoreVersion ?? coreVersion}`;
179
+ if (browserVersion) {
180
+ creatorOpt += `; ${browserVersion}`;
181
+ }
182
+ this.document.setCreator(
183
+ disableCreatorOption ? "Vivliostyle" : `Vivliostyle (${creatorOpt})`
184
+ );
185
+ const language = tree[metaTerms.language]?.[0].v;
186
+ if (language) {
187
+ this.document.setLanguage(language);
188
+ }
189
+ const creation = (tree[metaTerms.created] || tree[metaTerms.date])?.[0].v;
190
+ const creationDate = creation && new Date(creation);
191
+ if (creationDate) {
192
+ this.document.setCreationDate(creationDate);
193
+ }
194
+ if (pageProgression === "rtl") {
195
+ const viewerPrefs = this.document.catalog.getOrCreateViewerPreferences();
196
+ viewerPrefs.setReadingDirection(ReadingDirection.R2L);
197
+ }
198
+ }
199
+ async toc(items) {
200
+ const { PDFDict, PDFHexString, PDFName, PDFNumber } = await importNodeModule("pdf-lib");
201
+ if (!items || !items.length) {
202
+ return;
203
+ }
204
+ const addRefs = (items2, parentRef) => items2.map((item) => {
205
+ const ref = this.document.context.nextRef();
206
+ return {
207
+ ...item,
208
+ parentRef,
209
+ ref,
210
+ children: addRefs(item.children, ref)
211
+ };
212
+ });
213
+ const countAll = (items2) => items2.reduce((sum, item) => sum + countAll(item.children), items2.length);
214
+ const addObjectsToPDF = (items2) => {
215
+ for (const [i, item] of items2.entries()) {
216
+ const child = PDFDict.withContext(this.document.context);
217
+ child.set(PDFName.of("Title"), PDFHexString.fromText(item.title));
218
+ child.set(PDFName.of("Dest"), PDFName.of(item.id));
219
+ child.set(PDFName.of("Parent"), item.parentRef);
220
+ const prev = items2[i - 1];
221
+ if (prev) {
222
+ child.set(PDFName.of("Prev"), prev.ref);
223
+ }
224
+ const next = items2[i + 1];
225
+ if (next) {
226
+ child.set(PDFName.of("Next"), next.ref);
227
+ }
228
+ if (item.children.length) {
229
+ child.set(PDFName.of("First"), item.children[0].ref);
230
+ child.set(
231
+ PDFName.of("Last"),
232
+ item.children[item.children.length - 1].ref
233
+ );
234
+ child.set(PDFName.of("Count"), PDFNumber.of(countAll(item.children)));
235
+ }
236
+ this.document.context.assign(item.ref, child);
237
+ addObjectsToPDF(item.children);
238
+ }
239
+ };
240
+ const outlineRef = this.document.context.nextRef();
241
+ const itemsWithRefs = addRefs(items, outlineRef);
242
+ addObjectsToPDF(itemsWithRefs);
243
+ const outline = PDFDict.withContext(this.document.context);
244
+ outline.set(PDFName.of("First"), itemsWithRefs[0].ref);
245
+ outline.set(
246
+ PDFName.of("Last"),
247
+ itemsWithRefs[itemsWithRefs.length - 1].ref
248
+ );
249
+ outline.set(PDFName.of("Count"), PDFNumber.of(countAll(itemsWithRefs)));
250
+ this.document.context.assign(outlineRef, outline);
251
+ this.document.catalog.set(PDFName.of("Outlines"), outlineRef);
252
+ }
253
+ async setPageBoxes(pageSizeData) {
254
+ if (pageSizeData.length + 1 === this.document.getPageCount()) {
255
+ this.document.removePage(pageSizeData.length);
256
+ }
257
+ if (pageSizeData.length !== this.document.getPageCount()) {
258
+ return;
259
+ }
260
+ for (let i = 0; i < pageSizeData.length; i++) {
261
+ const page = this.document.getPage(i);
262
+ const sizeData = pageSizeData[i];
263
+ if (!sizeData.mediaWidth || !sizeData.mediaHeight || isNaN(sizeData.bleedOffset) || isNaN(sizeData.bleedSize)) {
264
+ continue;
265
+ }
266
+ const yOffset = page.getHeight() - sizeData.mediaHeight;
267
+ page.setMediaBox(0, yOffset, sizeData.mediaWidth, sizeData.mediaHeight);
268
+ if (!sizeData.bleedOffset && !sizeData.bleedSize) {
269
+ continue;
270
+ }
271
+ page.setBleedBox(
272
+ sizeData.bleedOffset,
273
+ yOffset + sizeData.bleedOffset,
274
+ sizeData.mediaWidth - sizeData.bleedOffset * 2,
275
+ sizeData.mediaHeight - sizeData.bleedOffset * 2
276
+ );
277
+ const trimOffset = sizeData.bleedOffset + sizeData.bleedSize;
278
+ page.setTrimBox(
279
+ trimOffset,
280
+ yOffset + trimOffset,
281
+ sizeData.mediaWidth - trimOffset * 2,
282
+ sizeData.mediaHeight - trimOffset * 2
283
+ );
284
+ }
285
+ }
286
+ };
287
+
288
+ // src/output/pdf.ts
289
+ async function buildPDF({
290
+ target,
291
+ config
292
+ }) {
293
+ Logger.logUpdate(`Launching PDF build environment`);
294
+ const viewerFullUrl = await getViewerFullUrl(config);
295
+ Logger.debug("viewerFullUrl", viewerFullUrl);
296
+ let lastEntry;
297
+ function stringifyEntry(entry) {
298
+ const formattedSourcePath = cyan(
299
+ entry.source.type === "file" ? upath2.relative(config.entryContextDir, entry.source.pathname) : entry.source.href
300
+ );
301
+ return `${terminalLink(
302
+ formattedSourcePath,
303
+ entry.source.type === "file" ? `file://${entry.source.pathname}` : entry.source.href,
304
+ {
305
+ fallback: () => formattedSourcePath
306
+ }
307
+ )} ${entry.title ? gray(entry.title) : ""}`;
308
+ }
309
+ function handleEntry(response) {
310
+ const entry = config.entries.find((entry2) => {
311
+ if (!("source" in entry2)) {
312
+ return false;
313
+ }
314
+ const url = new URL(response.url());
315
+ return url.protocol === "file:" ? pathEquals(entry2.target, url.pathname) : pathEquals(
316
+ upath2.relative(config.workspaceDir, entry2.target),
317
+ url.pathname.substring(1)
318
+ );
319
+ });
320
+ if (entry) {
321
+ if (!lastEntry) {
322
+ lastEntry = entry;
323
+ Logger.logUpdate(stringifyEntry(entry));
324
+ return;
325
+ }
326
+ Logger.logSuccess(stringifyEntry(lastEntry));
327
+ Logger.startLogging(stringifyEntry(entry));
328
+ lastEntry = entry;
329
+ }
330
+ }
331
+ const { browser, page } = await launchPreview({
332
+ mode: "build",
333
+ url: viewerFullUrl,
334
+ config,
335
+ onBrowserOpen: () => {
336
+ Logger.logUpdate("Building pages");
337
+ },
338
+ onPageOpen: async (page2) => {
339
+ page2.on("pageerror", (error) => {
340
+ Logger.logError(red(error.message));
341
+ });
342
+ page2.on("console", (msg) => {
343
+ switch (msg.type()) {
344
+ case "error":
345
+ if (/\/vivliostyle-viewer\.js$/.test(msg.location().url ?? "")) {
346
+ Logger.logError(msg.text());
347
+ throw msg.text();
348
+ }
349
+ return;
350
+ case "debug":
351
+ if (/time slice/.test(msg.text())) {
352
+ return;
353
+ }
354
+ break;
355
+ }
356
+ if (msg.type() === "error") {
357
+ Logger.logVerbose(red("console.error()"), msg.text());
358
+ } else {
359
+ Logger.logVerbose(gray(`console.${msg.type()}()`), msg.text());
360
+ }
361
+ });
362
+ page2.on("response", (response) => {
363
+ Logger.debug(
364
+ gray("viewer:response"),
365
+ green(response.status().toString()),
366
+ response.url()
367
+ );
368
+ handleEntry(response);
369
+ if (300 > response.status() && 200 <= response.status()) return;
370
+ if (response.url().startsWith("file://") && response.ok()) return;
371
+ Logger.logError(red(`${response.status()}`), response.url());
372
+ });
373
+ await page2.setDefaultTimeout(config.timeout);
374
+ }
375
+ });
376
+ const browserName = getFullBrowserName(config.browser.type);
377
+ const browserVersion = `${browserName}/${await browser.version()}`;
378
+ Logger.debug(green("success"), `browserVersion=${browserVersion}`);
379
+ let remainTime = config.timeout;
380
+ const startTime = Date.now();
381
+ await page.waitForLoadState("networkidle");
382
+ await page.waitForFunction(() => !!window.coreViewer);
383
+ await page.emulateMedia({ media: "print" });
384
+ await page.waitForFunction(
385
+ /* v8 ignore next */
386
+ () => window.coreViewer.readyState === "complete",
387
+ void 0,
388
+ { polling: 1e3 }
389
+ );
390
+ if (lastEntry) {
391
+ Logger.logSuccess(stringifyEntry(lastEntry));
392
+ }
393
+ const pageProgression = await page.evaluate(
394
+ () => (
395
+ /* v8 ignore next 5 */
396
+ document.querySelector("#vivliostyle-viewer-viewport")?.getAttribute("data-vivliostyle-page-progression") === "rtl" ? "rtl" : "ltr"
397
+ )
398
+ );
399
+ const viewerCoreVersion = await page.evaluate(
400
+ () => (
401
+ /* v8 ignore next 3 */
402
+ document.querySelector("#vivliostyle-menu_settings .version")?.textContent?.replace(/^.*?: (\d[-+.\w]+).*$/, "$1")
403
+ )
404
+ );
405
+ const metadata = await loadMetadata(page);
406
+ const toc = await loadTOC(page);
407
+ const pageSizeData = await loadPageSizeData(page);
408
+ remainTime -= Date.now() - startTime;
409
+ if (remainTime <= 0) {
410
+ throw new Error("Typesetting process timed out");
411
+ }
412
+ Logger.debug("Remaining timeout:", remainTime);
413
+ Logger.logUpdate("Building PDF");
414
+ const pdf = await page.pdf({
415
+ margin: {
416
+ top: 0,
417
+ bottom: 0,
418
+ right: 0,
419
+ left: 0
420
+ },
421
+ printBackground: true,
422
+ preferCSSPageSize: true,
423
+ tagged: true
424
+ // timeout: remainTime,
425
+ });
426
+ await browser.close();
427
+ Logger.logUpdate("Processing PDF");
428
+ fs2.mkdirSync(upath2.dirname(target.path), { recursive: true });
429
+ const post = await PostProcess.load(pdf);
430
+ await post.metadata(metadata, {
431
+ pageProgression,
432
+ browserVersion,
433
+ viewerCoreVersion,
434
+ // If custom viewer is set and its version info is not available,
435
+ // there is no guarantee that the default creator option is correct.
436
+ disableCreatorOption: !!config.viewer && !viewerCoreVersion
437
+ });
438
+ await post.toc(toc);
439
+ await post.setPageBoxes(pageSizeData);
440
+ await post.save(target.path, {
441
+ preflight: target.preflight,
442
+ preflightOption: target.preflightOption,
443
+ image: config.image
444
+ });
445
+ return target.path;
446
+ }
447
+ async function loadMetadata(page) {
448
+ return page.evaluate(() => window.coreViewer.getMetadata());
449
+ }
450
+ async function loadTOC(page) {
451
+ return page.evaluate(
452
+ () => new Promise((resolve) => {
453
+ function listener(payload) {
454
+ if (payload.a !== "toc") {
455
+ return;
456
+ }
457
+ window.coreViewer.removeListener("done", listener);
458
+ window.coreViewer.showTOC(false);
459
+ resolve(window.coreViewer.getTOC());
460
+ }
461
+ window.coreViewer.addListener("done", listener);
462
+ window.coreViewer.showTOC(true);
463
+ })
464
+ );
465
+ }
466
+ async function loadPageSizeData(page) {
467
+ return page.evaluate(() => {
468
+ const sizeData = [];
469
+ const pageContainers = document.querySelectorAll(
470
+ "#vivliostyle-viewer-viewport > div > div > div[data-vivliostyle-page-container]"
471
+ );
472
+ for (const pageContainer of pageContainers) {
473
+ const bleedBox = pageContainer.querySelector(
474
+ "div[data-vivliostyle-bleed-box]"
475
+ );
476
+ sizeData.push({
477
+ mediaWidth: parseFloat(pageContainer.style.width) * 0.75,
478
+ mediaHeight: parseFloat(pageContainer.style.height) * 0.75,
479
+ bleedOffset: parseFloat(bleedBox?.style.left) * 0.75,
480
+ bleedSize: parseFloat(bleedBox?.style.paddingLeft) * 0.75
481
+ });
482
+ }
483
+ return sizeData;
484
+ });
485
+ }
486
+
487
+ // src/core/build.ts
488
+ async function build(inlineConfig) {
489
+ Logger.setLogLevel(inlineConfig.logLevel);
490
+ Logger.setCustomLogger(inlineConfig.logger);
491
+ Logger.debug("build > inlineConfig %O", inlineConfig);
492
+ let vivliostyleConfig = await loadVivliostyleConfig(inlineConfig) ?? setupConfigFromFlags(inlineConfig);
493
+ warnDeprecatedConfig(vivliostyleConfig);
494
+ vivliostyleConfig = mergeInlineConfig(vivliostyleConfig, {
495
+ ...inlineConfig,
496
+ quick: false
497
+ });
498
+ const { inlineOptions } = vivliostyleConfig;
499
+ Logger.debug("build > vivliostyleConfig %O", vivliostyleConfig);
500
+ for (let [i, task] of vivliostyleConfig.tasks.entries()) {
501
+ var _stack2 = [];
502
+ try {
503
+ const _3 = __using(_stack2, Logger.startLogging("Start building"));
504
+ const config = resolveTaskConfig(task, inlineOptions);
505
+ Logger.debug("build > config %O", config);
506
+ const viteConfig = await resolveViteConfig({
507
+ ...config,
508
+ mode: "build"
509
+ });
510
+ let server;
511
+ if (!isInContainer()) {
512
+ Logger.debug("build > viteConfig.configFile %s", viteConfig.configFile);
513
+ if (viteConfig.configFile) {
514
+ var _stack = [];
515
+ try {
516
+ const _4 = __using(_stack, Logger.suspendLogging("Building Vite project"));
517
+ await viteBuild({
518
+ configFile: viteConfig.configFile,
519
+ root: config.context
520
+ });
521
+ } catch (_) {
522
+ var _error = _, _hasError = true;
523
+ } finally {
524
+ __callDispose(_stack, _error, _hasError);
525
+ }
526
+ }
527
+ if (isWebPubConfig(config)) {
528
+ await cleanupWorkspace(config);
529
+ await prepareThemeDirectory(config);
530
+ await compile(config);
531
+ await copyAssets(config);
532
+ }
533
+ if (config.outputs.some((o) => o.format === "pdf")) {
534
+ server = await createViteServer({
535
+ config,
536
+ viteConfig,
537
+ inlineConfig,
538
+ mode: "build"
539
+ });
540
+ }
541
+ }
542
+ for (const target of config.outputs) {
543
+ let output = null;
544
+ const { format } = target;
545
+ if (format === "pdf") {
546
+ if (!isInContainer() && target.renderMode === "docker") {
547
+ output = await buildPDFWithContainer({
548
+ target,
549
+ config,
550
+ inlineConfig
551
+ });
552
+ } else {
553
+ output = await buildPDF({ target, config });
554
+ }
555
+ } else if (format === "webpub" || format === "epub") {
556
+ output = await buildWebPublication({ target, config });
557
+ }
558
+ if (output && !isInContainer()) {
559
+ const formattedOutput = cyan2(
560
+ upath3.relative(inlineConfig.cwd ?? cwd, output)
561
+ );
562
+ Logger.logSuccess(
563
+ `Finished building ${terminalLink2(
564
+ formattedOutput,
565
+ pathToFileURL(output).href,
566
+ {
567
+ fallback: () => formattedOutput
568
+ }
569
+ )}`
570
+ );
571
+ }
572
+ }
573
+ await server?.close();
574
+ } catch (_2) {
575
+ var _error2 = _2, _hasError2 = true;
576
+ } finally {
577
+ __callDispose(_stack2, _error2, _hasError2);
578
+ }
579
+ }
580
+ runExitHandlers();
581
+ if (!isInContainer()) {
582
+ const num = vivliostyleConfig.tasks.flatMap((t) => t.output ?? []).length;
583
+ const symbol = isUnicodeSupported ? `${num > 1 ? "\u{1F4DA}" : randomBookSymbol} ` : "";
584
+ Logger.log(`${symbol}Built successfully!`);
585
+ }
586
+ }
587
+
588
+ export {
589
+ build
590
+ };
@@ -0,0 +1,16 @@
1
+ // src/node-modules.ts
2
+ var nodeExternalModules = [
3
+ "@napi-rs/canvas",
4
+ "command-exists",
5
+ "execa",
6
+ "press-ready",
7
+ "pdf-lib",
8
+ "playwright-core",
9
+ "playwright-core/lib/server"
10
+ ];
11
+ var importNodeModule = (name) => import(name);
12
+
13
+ export {
14
+ nodeExternalModules,
15
+ importNodeModule
16
+ };
package/dist/cli.d.ts CHANGED
@@ -1,3 +1 @@
1
1
  #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -1,20 +1,19 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from 'commander';
3
- import { cliVersion, coreVersion } from './const.js';
4
- const version = `cli: ${cliVersion}
2
+ import {
3
+ cliVersion,
4
+ coreVersion
5
+ } from "./chunk-EX7EA34F.js";
6
+ import "./chunk-BIEQXUOY.js";
7
+
8
+ // src/cli.ts
9
+ import { Command } from "commander";
10
+ var version = `cli: ${cliVersion}
5
11
  core: ${coreVersion}`;
6
- const program = new Command();
7
- program
8
- .name('vivliostyle')
9
- .version(version, '-v, --version')
10
- .command('init', 'create vivliostyle config', {
11
- executableFile: 'commands/init',
12
- })
13
- .command('build', 'build and create PDF file', {
14
- executableFile: 'commands/build',
15
- })
16
- .command('preview', 'launch preview server', {
17
- executableFile: 'commands/preview',
18
- })
19
- .parse(process.argv);
20
- //# sourceMappingURL=cli.js.map
12
+ var program = new Command();
13
+ program.name("vivliostyle").version(version, "-v, --version").command("init", "create vivliostyle config", {
14
+ executableFile: "commands/init"
15
+ }).command("build", "build and create PDF file", {
16
+ executableFile: "commands/build"
17
+ }).command("preview", "launch preview server", {
18
+ executableFile: "commands/preview"
19
+ }).parse(process.argv);
@@ -1,2 +1,2 @@
1
- export {};
2
- //# sourceMappingURL=build.d.ts.map
1
+
2
+ export { }