@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
|
importNodeModule
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ECEGM36O.js";
|
|
4
4
|
import {
|
|
5
5
|
DetailError,
|
|
6
6
|
GlobMatcher,
|
|
@@ -33,10 +33,10 @@ import {
|
|
|
33
33
|
touchTmpFile,
|
|
34
34
|
useTmpDirectory,
|
|
35
35
|
writeFileIfChanged
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-DBK27BAR.js";
|
|
37
37
|
import {
|
|
38
38
|
VivliostyleConfigSchema
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-7GIJVX4M.js";
|
|
40
40
|
import {
|
|
41
41
|
CONTAINER_LOCAL_HOSTNAME,
|
|
42
42
|
CONTAINER_URL,
|
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
XML_DECLARATION,
|
|
58
58
|
cliVersion,
|
|
59
59
|
viewerRoot
|
|
60
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-OAFXM4ES.js";
|
|
61
61
|
import {
|
|
62
62
|
__callDispose,
|
|
63
63
|
__using
|
|
@@ -77,7 +77,7 @@ function locateVivliostyleConfig({
|
|
|
77
77
|
if (config) {
|
|
78
78
|
return upath.resolve(cwd2, config);
|
|
79
79
|
}
|
|
80
|
-
return [".js", ".mjs", ".cjs", ".json"].map((ext) => upath.join(cwd2, `vivliostyle.config${ext}`)).find((p) => fs.existsSync(p));
|
|
80
|
+
return [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts", ".json"].map((ext) => upath.join(cwd2, `vivliostyle.config${ext}`)).find((p) => fs.existsSync(p));
|
|
81
81
|
}
|
|
82
82
|
async function loadVivliostyleConfig({
|
|
83
83
|
config,
|
|
@@ -149,6 +149,25 @@ function warnDeprecatedConfig(config) {
|
|
|
149
149
|
"'http' property of Vivliostyle config was deprecated and will be removed in a future release. This option is enabled by default, and the file protocol is no longer supported."
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
|
+
if (config.tasks.some((task) => task.pressReady !== void 0)) {
|
|
153
|
+
Logger.logWarn(
|
|
154
|
+
`'pressReady' property of Vivliostyle config was deprecated and will be removed in a future release. Please use 'pdfPostprocess.preflight: "press-ready"' property instead.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (config.tasks.some(
|
|
158
|
+
(task) => task.output && [task.output].flat().some((o) => o.preflight)
|
|
159
|
+
)) {
|
|
160
|
+
Logger.logWarn(
|
|
161
|
+
"'preflight' property of output config was deprecated and will be removed in a future release. Please use 'pdfPostprocess.preflight' property instead."
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if (config.tasks.some(
|
|
165
|
+
(task) => task.output && [task.output].flat().some((o) => o.preflightOption)
|
|
166
|
+
)) {
|
|
167
|
+
Logger.logWarn(
|
|
168
|
+
"'preflightOption' property of output config was deprecated and will be removed in a future release. Please use 'pdfPostprocess.preflightOption' property instead."
|
|
169
|
+
);
|
|
170
|
+
}
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
// src/config/merge.ts
|
|
@@ -198,7 +217,7 @@ function mergeInlineConfig({ tasks, inlineOptions }, inlineConfig) {
|
|
|
198
217
|
tasks: tasks.map((task) => ({
|
|
199
218
|
...pruneObject(task),
|
|
200
219
|
...pruneObject({
|
|
201
|
-
theme,
|
|
220
|
+
theme: theme === false ? void 0 : theme,
|
|
202
221
|
size,
|
|
203
222
|
pressReady,
|
|
204
223
|
title,
|
|
@@ -249,6 +268,7 @@ import { lookup as mime } from "mime-types";
|
|
|
249
268
|
import fs3 from "node:fs";
|
|
250
269
|
import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "node:url";
|
|
251
270
|
import npa from "npm-package-arg";
|
|
271
|
+
import { globSync } from "tinyglobby";
|
|
252
272
|
import upath2 from "upath";
|
|
253
273
|
|
|
254
274
|
// src/processor/markdown.ts
|
|
@@ -493,24 +513,105 @@ function resolveTaskConfig(config, options) {
|
|
|
493
513
|
const customStyle = options.style && parseCustomStyle({ customStyle: options.style, entryContextDir }) || void 0;
|
|
494
514
|
const customUserStyle = options.userStyle && parseCustomStyle({ customStyle: options.userStyle, entryContextDir }) || void 0;
|
|
495
515
|
const outputs = (() => {
|
|
516
|
+
const resolveCmykConfig = (cmykOption) => {
|
|
517
|
+
if (cmykOption && typeof cmykOption === "object") {
|
|
518
|
+
return {
|
|
519
|
+
warnUnmapped: cmykOption.warnUnmapped ?? true,
|
|
520
|
+
overrideMap: cmykOption.overrideMap ?? [],
|
|
521
|
+
mapOutput: cmykOption.mapOutput ? upath2.resolve(context, cmykOption.mapOutput) : void 0
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
if (options.cmyk || cmykOption === true) {
|
|
525
|
+
return { warnUnmapped: true, overrideMap: [], mapOutput: void 0 };
|
|
526
|
+
}
|
|
527
|
+
return false;
|
|
528
|
+
};
|
|
529
|
+
const resolveReplaceImageConfig = (replaceImageOption) => {
|
|
530
|
+
if (!replaceImageOption) {
|
|
531
|
+
return [];
|
|
532
|
+
}
|
|
533
|
+
const allFiles = globSync("**/*", {
|
|
534
|
+
cwd: entryContextDir,
|
|
535
|
+
onlyFiles: true
|
|
536
|
+
});
|
|
537
|
+
return replaceImageOption.flatMap(({ source, replacement }) => {
|
|
538
|
+
if (source instanceof RegExp) {
|
|
539
|
+
return allFiles.filter((file) => source.test(file)).map((file) => ({
|
|
540
|
+
source: upath2.resolve(entryContextDir, file),
|
|
541
|
+
replacement: upath2.resolve(
|
|
542
|
+
entryContextDir,
|
|
543
|
+
file.replace(source, replacement)
|
|
544
|
+
)
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
source: upath2.resolve(entryContextDir, source),
|
|
549
|
+
replacement: upath2.resolve(entryContextDir, replacement)
|
|
550
|
+
};
|
|
551
|
+
});
|
|
552
|
+
};
|
|
553
|
+
const resolveDefaultPreflight = () => {
|
|
554
|
+
if (options.preflight) {
|
|
555
|
+
return options.preflight;
|
|
556
|
+
}
|
|
557
|
+
const pp = config.pdfPostprocess;
|
|
558
|
+
if (pp && "preflight" in pp) {
|
|
559
|
+
return pp.preflight;
|
|
560
|
+
}
|
|
561
|
+
if (config.pressReady) {
|
|
562
|
+
return "press-ready";
|
|
563
|
+
}
|
|
564
|
+
return void 0;
|
|
565
|
+
};
|
|
566
|
+
const resolveDefaultPreflightOption = () => {
|
|
567
|
+
if (options.preflightOption) {
|
|
568
|
+
return options.preflightOption;
|
|
569
|
+
}
|
|
570
|
+
return config.pdfPostprocess?.preflightOption ?? [];
|
|
571
|
+
};
|
|
496
572
|
const defaultPdfOptions = {
|
|
497
573
|
format: "pdf",
|
|
498
574
|
renderMode: options.renderMode ?? "local",
|
|
499
|
-
preflight:
|
|
500
|
-
preflightOption:
|
|
575
|
+
preflight: resolveDefaultPreflight(),
|
|
576
|
+
preflightOption: resolveDefaultPreflightOption(),
|
|
577
|
+
cmyk: resolveCmykConfig(config.pdfPostprocess?.cmyk),
|
|
578
|
+
replaceImage: resolveReplaceImageConfig(
|
|
579
|
+
config.pdfPostprocess?.replaceImage
|
|
580
|
+
)
|
|
501
581
|
};
|
|
502
582
|
if (config.output) {
|
|
503
583
|
return config.output.map((target) => {
|
|
504
584
|
const outputPath = upath2.resolve(context, target.path);
|
|
505
585
|
const format = target.format;
|
|
506
586
|
switch (format) {
|
|
507
|
-
case "pdf":
|
|
587
|
+
case "pdf": {
|
|
588
|
+
const targetPp = target.pdfPostprocess;
|
|
589
|
+
const { pdfPostprocess: _, ...targetRest } = target;
|
|
590
|
+
const resolvedPreflight = (() => {
|
|
591
|
+
if (options.preflight) return options.preflight;
|
|
592
|
+
if (targetPp?.preflight) return targetPp.preflight;
|
|
593
|
+
if (target.preflight) return target.preflight;
|
|
594
|
+
return defaultPdfOptions.preflight;
|
|
595
|
+
})();
|
|
596
|
+
const resolvedPreflightOption = (() => {
|
|
597
|
+
if (options.preflightOption) return options.preflightOption;
|
|
598
|
+
if (targetPp?.preflightOption) return targetPp.preflightOption;
|
|
599
|
+
if (target.preflightOption) return target.preflightOption;
|
|
600
|
+
return defaultPdfOptions.preflightOption;
|
|
601
|
+
})();
|
|
602
|
+
const resolvedCmyk = targetPp?.cmyk !== void 0 ? resolveCmykConfig(targetPp.cmyk) : defaultPdfOptions.cmyk;
|
|
603
|
+
const resolvedReplaceImage = targetPp?.replaceImage !== void 0 ? resolveReplaceImageConfig(targetPp.replaceImage) : defaultPdfOptions.replaceImage;
|
|
508
604
|
return {
|
|
509
605
|
...defaultPdfOptions,
|
|
510
|
-
...
|
|
606
|
+
...targetRest,
|
|
511
607
|
format,
|
|
512
|
-
path: outputPath
|
|
608
|
+
path: outputPath,
|
|
609
|
+
preflight: resolvedPreflight,
|
|
610
|
+
preflightOption: resolvedPreflightOption,
|
|
611
|
+
cmyk: resolvedCmyk,
|
|
612
|
+
replaceImage: resolvedReplaceImage
|
|
513
613
|
};
|
|
614
|
+
}
|
|
514
615
|
case "epub":
|
|
515
616
|
return {
|
|
516
617
|
...target,
|
|
@@ -1128,7 +1229,8 @@ async function launchBrowser({
|
|
|
1128
1229
|
headless,
|
|
1129
1230
|
noSandbox,
|
|
1130
1231
|
disableDevShmUsage,
|
|
1131
|
-
ignoreHttpsErrors
|
|
1232
|
+
ignoreHttpsErrors,
|
|
1233
|
+
protocolTimeout
|
|
1132
1234
|
}) {
|
|
1133
1235
|
const puppeteer = await importNodeModule("puppeteer-core");
|
|
1134
1236
|
const args = [];
|
|
@@ -1197,15 +1299,16 @@ async function launchBrowser({
|
|
|
1197
1299
|
browser: browserType === "chromium" ? "chrome" : browserType,
|
|
1198
1300
|
headless,
|
|
1199
1301
|
acceptInsecureCerts: ignoreHttpsErrors,
|
|
1200
|
-
waitForInitialPage: false
|
|
1302
|
+
waitForInitialPage: false,
|
|
1303
|
+
protocolTimeout
|
|
1201
1304
|
};
|
|
1202
1305
|
Logger.debug("launchOptions %O", launchOptions);
|
|
1203
1306
|
const browser = await puppeteer.launch({
|
|
1204
1307
|
...launchOptions,
|
|
1205
1308
|
env: { ...process.env, LANG: "en.UTF-8" }
|
|
1206
1309
|
});
|
|
1207
|
-
registerExitHandler("Closing browser", () => {
|
|
1208
|
-
browser.close();
|
|
1310
|
+
registerExitHandler("Closing browser", async () => {
|
|
1311
|
+
await browser.close();
|
|
1209
1312
|
});
|
|
1210
1313
|
const [browserContext] = browser.browserContexts();
|
|
1211
1314
|
return { browser, browserContext };
|
|
@@ -1321,7 +1424,13 @@ async function launchPreview({
|
|
|
1321
1424
|
url,
|
|
1322
1425
|
onBrowserOpen,
|
|
1323
1426
|
onPageOpen,
|
|
1324
|
-
config: {
|
|
1427
|
+
config: {
|
|
1428
|
+
browser: browserConfig,
|
|
1429
|
+
proxy,
|
|
1430
|
+
sandbox,
|
|
1431
|
+
ignoreHttpsErrors,
|
|
1432
|
+
timeout
|
|
1433
|
+
}
|
|
1325
1434
|
}) {
|
|
1326
1435
|
let executableBrowser = browserConfig.executablePath;
|
|
1327
1436
|
Logger.debug(`Specified browser path: ${executableBrowser}`);
|
|
@@ -1351,7 +1460,8 @@ async function launchPreview({
|
|
|
1351
1460
|
headless: mode === "build",
|
|
1352
1461
|
noSandbox: !sandbox,
|
|
1353
1462
|
disableDevShmUsage: isInContainer(),
|
|
1354
|
-
ignoreHttpsErrors
|
|
1463
|
+
ignoreHttpsErrors,
|
|
1464
|
+
protocolTimeout: timeout
|
|
1355
1465
|
});
|
|
1356
1466
|
await onBrowserOpen?.(browser);
|
|
1357
1467
|
const page = (await browserContext.pages())[0] ?? await browserContext.newPage();
|
|
@@ -1378,7 +1488,7 @@ async function launchPreview({
|
|
|
1378
1488
|
// src/server.ts
|
|
1379
1489
|
import fs10 from "node:fs";
|
|
1380
1490
|
import { URL as URL2 } from "node:url";
|
|
1381
|
-
import
|
|
1491
|
+
import upath12 from "upath";
|
|
1382
1492
|
import {
|
|
1383
1493
|
createServer,
|
|
1384
1494
|
preview
|
|
@@ -1388,14 +1498,14 @@ import {
|
|
|
1388
1498
|
import escapeRe from "escape-string-regexp";
|
|
1389
1499
|
import { pathToFileURL as pathToFileURL6 } from "node:url";
|
|
1390
1500
|
import sirv from "sirv";
|
|
1391
|
-
import
|
|
1501
|
+
import upath9 from "upath";
|
|
1392
1502
|
import "vite";
|
|
1393
1503
|
|
|
1394
1504
|
// src/processor/compile.ts
|
|
1395
1505
|
import "@vivliostyle/jsdom";
|
|
1396
1506
|
import { copy as copy3, move } from "fs-extra/esm";
|
|
1397
1507
|
import fs8 from "node:fs";
|
|
1398
|
-
import
|
|
1508
|
+
import upath8 from "upath";
|
|
1399
1509
|
import serializeToXml2 from "w3c-xmlserializer";
|
|
1400
1510
|
import MIMEType2 from "whatwg-mimetype";
|
|
1401
1511
|
|
|
@@ -2991,10 +3101,37 @@ async function buildWebPublication({
|
|
|
2991
3101
|
// src/processor/theme.ts
|
|
2992
3102
|
import Arborist from "@npmcli/arborist";
|
|
2993
3103
|
import fs7 from "node:fs";
|
|
3104
|
+
import upath7 from "upath";
|
|
3105
|
+
function* iterateSymlinksInThemesNodeModules(themesDir) {
|
|
3106
|
+
if (!fs7.existsSync(themesDir)) {
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
const nodeModulesDir = upath7.join(themesDir, "node_modules");
|
|
3110
|
+
if (!fs7.existsSync(nodeModulesDir)) {
|
|
3111
|
+
return;
|
|
3112
|
+
}
|
|
3113
|
+
for (const entry of fs7.readdirSync(nodeModulesDir, { withFileTypes: true })) {
|
|
3114
|
+
if (!entry.isSymbolicLink()) {
|
|
3115
|
+
continue;
|
|
3116
|
+
}
|
|
3117
|
+
const linkPath = upath7.join(nodeModulesDir, entry.name);
|
|
3118
|
+
const target = fs7.readlinkSync(linkPath);
|
|
3119
|
+
yield upath7.resolve(nodeModulesDir, target);
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
function removeThemesDirIfBrokenSymlinks(themesDir) {
|
|
3123
|
+
for (const target of iterateSymlinksInThemesNodeModules(themesDir)) {
|
|
3124
|
+
if (!fs7.existsSync(target)) {
|
|
3125
|
+
fs7.rmSync(themesDir, { recursive: true });
|
|
3126
|
+
return;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
2994
3130
|
async function checkThemeInstallationNecessity({
|
|
2995
3131
|
themesDir,
|
|
2996
3132
|
themeIndexes
|
|
2997
3133
|
}) {
|
|
3134
|
+
removeThemesDirIfBrokenSymlinks(themesDir);
|
|
2998
3135
|
if (!fs7.existsSync(themesDir)) {
|
|
2999
3136
|
return [...themeIndexes].some((theme) => theme.type === "package");
|
|
3000
3137
|
}
|
|
@@ -3010,11 +3147,17 @@ async function checkThemeInstallationNecessity({
|
|
|
3010
3147
|
(theme) => theme.type === "package" && !pkgs.includes(theme.name)
|
|
3011
3148
|
);
|
|
3012
3149
|
}
|
|
3150
|
+
function getLocalThemePaths({
|
|
3151
|
+
themesDir
|
|
3152
|
+
}) {
|
|
3153
|
+
return [...iterateSymlinksInThemesNodeModules(themesDir)];
|
|
3154
|
+
}
|
|
3013
3155
|
async function installThemeDependencies({
|
|
3014
3156
|
themesDir,
|
|
3015
3157
|
themeIndexes
|
|
3016
3158
|
}) {
|
|
3017
3159
|
fs7.mkdirSync(themesDir, { recursive: true });
|
|
3160
|
+
removeThemesDirIfBrokenSymlinks(themesDir);
|
|
3018
3161
|
try {
|
|
3019
3162
|
const commonOpt = {
|
|
3020
3163
|
path: themesDir,
|
|
@@ -3033,8 +3176,17 @@ async function installThemeDependencies({
|
|
|
3033
3176
|
const rm = existing.filter((v2) => !add.includes(v2));
|
|
3034
3177
|
const opt = { ...commonOpt, rm, add };
|
|
3035
3178
|
const arb = new Arborist(opt);
|
|
3036
|
-
await arb.reify(opt);
|
|
3037
|
-
|
|
3179
|
+
const actualTree = await arb.reify(opt);
|
|
3180
|
+
for (const child of actualTree.children.values()) {
|
|
3181
|
+
if (child.resolved?.startsWith("file:")) {
|
|
3182
|
+
const sourcePath = upath7.resolve(themesDir, child.resolved.slice(5));
|
|
3183
|
+
if (fs7.existsSync(child.path)) {
|
|
3184
|
+
fs7.rmSync(child.path, { recursive: true });
|
|
3185
|
+
}
|
|
3186
|
+
const relPath = upath7.relative(upath7.dirname(child.path), sourcePath);
|
|
3187
|
+
fs7.symlinkSync(relPath, child.path, "junction");
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3038
3190
|
} catch (error) {
|
|
3039
3191
|
const thrownError = error;
|
|
3040
3192
|
throw new DetailError(
|
|
@@ -3050,20 +3202,20 @@ function locateThemePath(theme, from) {
|
|
|
3050
3202
|
return theme.location;
|
|
3051
3203
|
}
|
|
3052
3204
|
if (theme.type === "file") {
|
|
3053
|
-
return
|
|
3205
|
+
return upath8.relative(from, theme.location);
|
|
3054
3206
|
}
|
|
3055
3207
|
if (theme.importPath) {
|
|
3056
3208
|
return [theme.importPath].flat().map((locator) => {
|
|
3057
|
-
const resolvedPath =
|
|
3209
|
+
const resolvedPath = upath8.resolve(theme.location, locator);
|
|
3058
3210
|
if (!pathContains(theme.location, resolvedPath) || !fs8.existsSync(resolvedPath)) {
|
|
3059
3211
|
throw new Error(
|
|
3060
3212
|
`Could not find a style path ${theme.importPath} for the theme: ${theme.name}.`
|
|
3061
3213
|
);
|
|
3062
3214
|
}
|
|
3063
|
-
return
|
|
3215
|
+
return upath8.relative(from, resolvedPath);
|
|
3064
3216
|
});
|
|
3065
3217
|
} else {
|
|
3066
|
-
const pkgJsonPath =
|
|
3218
|
+
const pkgJsonPath = upath8.join(theme.location, "package.json");
|
|
3067
3219
|
const packageJson = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf8"));
|
|
3068
3220
|
const maybeStyle = packageJson?.vivliostyle?.theme?.style ?? packageJson.style ?? packageJson.main;
|
|
3069
3221
|
if (!maybeStyle) {
|
|
@@ -3072,7 +3224,7 @@ function locateThemePath(theme, from) {
|
|
|
3072
3224
|
"Please ensure this package satisfies a `vivliostyle.theme.style` property."
|
|
3073
3225
|
);
|
|
3074
3226
|
}
|
|
3075
|
-
return
|
|
3227
|
+
return upath8.relative(from, upath8.join(theme.location, maybeStyle));
|
|
3076
3228
|
}
|
|
3077
3229
|
}
|
|
3078
3230
|
async function cleanupWorkspace({
|
|
@@ -3089,15 +3241,15 @@ async function cleanupWorkspace({
|
|
|
3089
3241
|
Logger.debug("cleanup workspace files", workspaceDir);
|
|
3090
3242
|
let movedWorkspacePath;
|
|
3091
3243
|
if (pathContains(workspaceDir, themesDir) && fs8.existsSync(themesDir)) {
|
|
3092
|
-
movedWorkspacePath =
|
|
3093
|
-
|
|
3244
|
+
movedWorkspacePath = upath8.join(
|
|
3245
|
+
upath8.dirname(workspaceDir),
|
|
3094
3246
|
`.vs-${Date.now()}`
|
|
3095
3247
|
);
|
|
3096
|
-
const movedThemePath =
|
|
3248
|
+
const movedThemePath = upath8.join(
|
|
3097
3249
|
movedWorkspacePath,
|
|
3098
|
-
|
|
3250
|
+
upath8.relative(workspaceDir, themesDir)
|
|
3099
3251
|
);
|
|
3100
|
-
fs8.mkdirSync(
|
|
3252
|
+
fs8.mkdirSync(upath8.dirname(movedThemePath), { recursive: true });
|
|
3101
3253
|
registerExitHandler(
|
|
3102
3254
|
`Removing the moved workspace directory: ${movedWorkspacePath}`,
|
|
3103
3255
|
() => {
|
|
@@ -3117,10 +3269,10 @@ async function prepareThemeDirectory({
|
|
|
3117
3269
|
themesDir,
|
|
3118
3270
|
themeIndexes
|
|
3119
3271
|
}) {
|
|
3120
|
-
if (fs8.existsSync(
|
|
3272
|
+
if (fs8.existsSync(upath8.join(themesDir, "packages")) && !fs8.existsSync(upath8.join(themesDir, "node_modules"))) {
|
|
3121
3273
|
fs8.renameSync(
|
|
3122
|
-
|
|
3123
|
-
|
|
3274
|
+
upath8.join(themesDir, "packages"),
|
|
3275
|
+
upath8.join(themesDir, "node_modules")
|
|
3124
3276
|
);
|
|
3125
3277
|
}
|
|
3126
3278
|
if (await checkThemeInstallationNecessity({ themesDir, themeIndexes })) {
|
|
@@ -3129,10 +3281,11 @@ async function prepareThemeDirectory({
|
|
|
3129
3281
|
}
|
|
3130
3282
|
for (const theme of themeIndexes) {
|
|
3131
3283
|
if (theme.type === "file" && !pathEquals(theme.source, theme.location)) {
|
|
3132
|
-
fs8.mkdirSync(
|
|
3284
|
+
fs8.mkdirSync(upath8.dirname(theme.location), { recursive: true });
|
|
3133
3285
|
await copy3(theme.source, theme.location);
|
|
3134
3286
|
}
|
|
3135
3287
|
}
|
|
3288
|
+
return getLocalThemePaths({ themesDir });
|
|
3136
3289
|
}
|
|
3137
3290
|
async function transformManuscript(entry, {
|
|
3138
3291
|
entryContextDir,
|
|
@@ -3149,7 +3302,7 @@ async function transformManuscript(entry, {
|
|
|
3149
3302
|
let resourceLoader;
|
|
3150
3303
|
let resourceUrl;
|
|
3151
3304
|
const style = entry.themes.flatMap(
|
|
3152
|
-
(theme) => locateThemePath(theme,
|
|
3305
|
+
(theme) => locateThemePath(theme, upath8.dirname(entry.target))
|
|
3153
3306
|
);
|
|
3154
3307
|
if (source?.type === "file") {
|
|
3155
3308
|
if (source.documentProcessor) {
|
|
@@ -3245,7 +3398,7 @@ async function transformManuscript(entry, {
|
|
|
3245
3398
|
content = await processTocHtml(content, {
|
|
3246
3399
|
entries: manuscriptEntries,
|
|
3247
3400
|
manifestPath,
|
|
3248
|
-
distDir:
|
|
3401
|
+
distDir: upath8.dirname(contentsEntry.target),
|
|
3249
3402
|
tocTitle: contentsEntry.tocTitle,
|
|
3250
3403
|
sectionDepth: contentsEntry.sectionDepth,
|
|
3251
3404
|
styleOptions: contentsEntry,
|
|
@@ -3255,10 +3408,10 @@ async function transformManuscript(entry, {
|
|
|
3255
3408
|
if (entry.rel === "cover") {
|
|
3256
3409
|
const coverEntry = entry;
|
|
3257
3410
|
content = await processCoverHtml(content, {
|
|
3258
|
-
imageSrc:
|
|
3259
|
-
|
|
3411
|
+
imageSrc: upath8.relative(
|
|
3412
|
+
upath8.join(
|
|
3260
3413
|
entryContextDir,
|
|
3261
|
-
|
|
3414
|
+
upath8.relative(workspaceDir, coverEntry.target),
|
|
3262
3415
|
".."
|
|
3263
3416
|
),
|
|
3264
3417
|
coverEntry.coverImageSrc
|
|
@@ -3308,7 +3461,7 @@ async function generateManifest({
|
|
|
3308
3461
|
}) {
|
|
3309
3462
|
const manifestEntries = entries.map((entry) => ({
|
|
3310
3463
|
title: entry.rel === "contents" && entry.tocTitle || entry.title,
|
|
3311
|
-
path:
|
|
3464
|
+
path: upath8.relative(workspaceDir, entry.target),
|
|
3312
3465
|
encodingFormat: !("contentType" in entry) || entry.contentType === "text/markdown" || entry.contentType === "text/x-vivliostyle-custom" || entry.contentType === "text/html" ? void 0 : entry.contentType,
|
|
3313
3466
|
rel: entry.rel
|
|
3314
3467
|
}));
|
|
@@ -3318,7 +3471,7 @@ async function generateManifest({
|
|
|
3318
3471
|
language,
|
|
3319
3472
|
readingProgression,
|
|
3320
3473
|
cover: cover && {
|
|
3321
|
-
url:
|
|
3474
|
+
url: upath8.relative(entryContextDir, cover.src),
|
|
3322
3475
|
name: cover.name
|
|
3323
3476
|
},
|
|
3324
3477
|
entries: manifestEntries,
|
|
@@ -3374,7 +3527,7 @@ function createEntriesRouteLookup(entries, cwd2) {
|
|
|
3374
3527
|
return arr;
|
|
3375
3528
|
};
|
|
3376
3529
|
const cache = entries.reduce((acc, e) => {
|
|
3377
|
-
acc[`/${
|
|
3530
|
+
acc[`/${upath9.relative(cwd2, e.target).normalize().replace(/\\+/g, "/")}`] = e;
|
|
3378
3531
|
return acc;
|
|
3379
3532
|
}, {});
|
|
3380
3533
|
return (uri) => {
|
|
@@ -3407,8 +3560,8 @@ function getWorkspaceMatcher({
|
|
|
3407
3560
|
switch (viewerInput.type) {
|
|
3408
3561
|
case "epub":
|
|
3409
3562
|
entryFiles = [
|
|
3410
|
-
|
|
3411
|
-
|
|
3563
|
+
upath9.join(
|
|
3564
|
+
upath9.relative(workspaceDir, viewerInput.epubTmpOutputDir),
|
|
3412
3565
|
"**"
|
|
3413
3566
|
)
|
|
3414
3567
|
];
|
|
@@ -3447,7 +3600,7 @@ function vsDevServerPlugin({
|
|
|
3447
3600
|
if (isWebPubConfig(config) && config.viewerInput.needToGenerateManifest && needToUpdateManifest) {
|
|
3448
3601
|
await generateManifest(config);
|
|
3449
3602
|
}
|
|
3450
|
-
await prepareThemeDirectory(config);
|
|
3603
|
+
const localThemePaths = await prepareThemeDirectory(config);
|
|
3451
3604
|
const entriesLookup = createEntriesRouteLookup(
|
|
3452
3605
|
config.entries,
|
|
3453
3606
|
config.workspaceDir
|
|
@@ -3465,6 +3618,7 @@ function vsDevServerPlugin({
|
|
|
3465
3618
|
const serveAssets = sirv(config.entryContextDir, {
|
|
3466
3619
|
dev: true,
|
|
3467
3620
|
etag: false,
|
|
3621
|
+
dotfiles: false,
|
|
3468
3622
|
extensions: []
|
|
3469
3623
|
});
|
|
3470
3624
|
const serveAssetsMatcher = getAssetMatcher({
|
|
@@ -3514,7 +3668,8 @@ function vsDevServerPlugin({
|
|
|
3514
3668
|
prevThemeFiles.filter((target) => !themeFiles.includes(target))
|
|
3515
3669
|
);
|
|
3516
3670
|
server?.watcher.add(themeFiles);
|
|
3517
|
-
|
|
3671
|
+
server?.watcher.add(localThemePaths);
|
|
3672
|
+
projectDeps.push(...themeFiles, ...localThemePaths);
|
|
3518
3673
|
matchProjectDep = (pathname) => projectDeps.some(
|
|
3519
3674
|
(dep) => pathEquals(dep, pathname) || pathContains(dep, pathname)
|
|
3520
3675
|
);
|
|
@@ -3692,7 +3847,21 @@ function vsDevServerPlugin({
|
|
|
3692
3847
|
return () => {
|
|
3693
3848
|
viteServer.middlewares.use(
|
|
3694
3849
|
config.base,
|
|
3695
|
-
sirv(config.workspaceDir, {
|
|
3850
|
+
sirv(config.workspaceDir, {
|
|
3851
|
+
dev: true,
|
|
3852
|
+
etag: false,
|
|
3853
|
+
dotfiles: true,
|
|
3854
|
+
extensions: []
|
|
3855
|
+
})
|
|
3856
|
+
);
|
|
3857
|
+
viteServer.middlewares.use(
|
|
3858
|
+
config.base,
|
|
3859
|
+
sirv(config.entryContextDir, {
|
|
3860
|
+
dev: true,
|
|
3861
|
+
etag: false,
|
|
3862
|
+
dotfiles: false,
|
|
3863
|
+
extensions: []
|
|
3864
|
+
})
|
|
3696
3865
|
);
|
|
3697
3866
|
};
|
|
3698
3867
|
},
|
|
@@ -3713,7 +3882,7 @@ function vsDevServerPlugin({
|
|
|
3713
3882
|
|
|
3714
3883
|
// src/vite/vite-plugin-static-serve.ts
|
|
3715
3884
|
import sirv2 from "sirv";
|
|
3716
|
-
import
|
|
3885
|
+
import upath10 from "upath";
|
|
3717
3886
|
import "vite";
|
|
3718
3887
|
function vsStaticServePlugin({
|
|
3719
3888
|
config: _config,
|
|
@@ -3728,7 +3897,7 @@ function vsStaticServePlugin({
|
|
|
3728
3897
|
([base, dirs]) => dirs.map(
|
|
3729
3898
|
(dir) => [
|
|
3730
3899
|
base,
|
|
3731
|
-
sirv2(
|
|
3900
|
+
sirv2(upath10.resolve(config.serverRootDir, dir), {
|
|
3732
3901
|
dev: true,
|
|
3733
3902
|
etag: false
|
|
3734
3903
|
})
|
|
@@ -3759,7 +3928,7 @@ function vsStaticServePlugin({
|
|
|
3759
3928
|
// src/vite/vite-plugin-viewer.ts
|
|
3760
3929
|
import fs9 from "node:fs";
|
|
3761
3930
|
import sirv3 from "sirv";
|
|
3762
|
-
import
|
|
3931
|
+
import upath11 from "upath";
|
|
3763
3932
|
import "vite";
|
|
3764
3933
|
var viewerClientId = "@vivliostyle:viewer:client";
|
|
3765
3934
|
var viewerClientRequestPath = `/${viewerClientId}`;
|
|
@@ -3773,13 +3942,13 @@ if (import.meta.hot) {
|
|
|
3773
3942
|
}`
|
|
3774
3943
|
);
|
|
3775
3944
|
function vsViewerPlugin(_) {
|
|
3776
|
-
const serveRootDir =
|
|
3945
|
+
const serveRootDir = upath11.join(viewerRoot, "lib");
|
|
3777
3946
|
const serve = sirv3(serveRootDir, { dev: false, etag: true });
|
|
3778
3947
|
let cachedIndexHtml;
|
|
3779
3948
|
const middleware = async function vivliostyleViewerMiddleware(req, res, next) {
|
|
3780
3949
|
if (req.url === "/" || req.url === "/index.html") {
|
|
3781
3950
|
cachedIndexHtml ??= prependToHead(
|
|
3782
|
-
fs9.readFileSync(
|
|
3951
|
+
fs9.readFileSync(upath11.join(serveRootDir, "index.html"), "utf-8"),
|
|
3783
3952
|
`<script type="module" src="${viewerClientRequestPath}"></script>`
|
|
3784
3953
|
);
|
|
3785
3954
|
res.statusCode = 200;
|
|
@@ -3834,11 +4003,11 @@ function getViewerParams(src, {
|
|
|
3834
4003
|
let viewerParams = src ? `src=${escapeParam(src)}` : "";
|
|
3835
4004
|
viewerParams += `&bookMode=${!singleDoc}&renderAllPages=${!quick}`;
|
|
3836
4005
|
if (customStyle) {
|
|
3837
|
-
const param = isValidUri(customStyle) ? customStyle :
|
|
4006
|
+
const param = isValidUri(customStyle) ? customStyle : upath12.posix.join(base, customStyle);
|
|
3838
4007
|
viewerParams += `&style=${escapeParam(param)}`;
|
|
3839
4008
|
}
|
|
3840
4009
|
if (customUserStyle) {
|
|
3841
|
-
const param = isValidUri(customUserStyle) ? customUserStyle :
|
|
4010
|
+
const param = isValidUri(customUserStyle) ? customUserStyle : upath12.posix.join(base, customUserStyle);
|
|
3842
4011
|
viewerParams += `&userStyle=${escapeParam(param)}`;
|
|
3843
4012
|
}
|
|
3844
4013
|
if (pageSizeValue || cropMarks || bleed || cropOffset || css) {
|
|
@@ -3893,7 +4062,7 @@ async function getSourceUrl({
|
|
|
3893
4062
|
input = viewerInput;
|
|
3894
4063
|
}
|
|
3895
4064
|
return (isValidUri(input) ? new URL2(input) : new URL2(
|
|
3896
|
-
|
|
4065
|
+
upath12.posix.join(base, upath12.relative(workspaceDir, input)),
|
|
3897
4066
|
rootUrl
|
|
3898
4067
|
)).href;
|
|
3899
4068
|
}
|
|
@@ -4036,4 +4205,4 @@ export {
|
|
|
4036
4205
|
getViewerFullUrl,
|
|
4037
4206
|
createViteServer
|
|
4038
4207
|
};
|
|
4039
|
-
//# sourceMappingURL=chunk-
|
|
4208
|
+
//# sourceMappingURL=chunk-C4HQHRXQ.js.map
|