@vivliostyle/cli 9.3.1 → 9.3.2

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.
@@ -25,10 +25,10 @@ import {
25
25
  touchTmpFile,
26
26
  useTmpDirectory,
27
27
  writeFileIfChanged
28
- } from "./chunk-U63QI2TT.js";
28
+ } from "./chunk-A7YURMH3.js";
29
29
  import {
30
30
  VivliostyleConfigSchema
31
- } from "./chunk-SEVGSYUZ.js";
31
+ } from "./chunk-GKPT4TWW.js";
32
32
  import {
33
33
  CONTAINER_LOCAL_HOSTNAME,
34
34
  CONTAINER_URL,
@@ -270,6 +270,8 @@ var manuscriptMediaTypes = [
270
270
  ];
271
271
  var UseTemporaryServerRoot = Symbol("UseTemporaryServerRoot");
272
272
  var DEFAULT_ASSET_EXTENSIONS = [
273
+ "css",
274
+ "css.map",
273
275
  "png",
274
276
  "jpg",
275
277
  "jpeg",
@@ -1183,9 +1185,9 @@ async function launchPreview({
1183
1185
  }
1184
1186
 
1185
1187
  // src/server.ts
1186
- import fs10 from "node:fs";
1188
+ import fs11 from "node:fs";
1187
1189
  import { URL as URL2 } from "node:url";
1188
- import upath10 from "upath";
1190
+ import upath11 from "upath";
1189
1191
  import {
1190
1192
  createServer,
1191
1193
  preview
@@ -1194,26 +1196,171 @@ import {
1194
1196
  // src/vite/vite-plugin-dev-server.ts
1195
1197
  import escapeRe from "escape-string-regexp";
1196
1198
  import { pathToFileURL as pathToFileURL6 } from "node:url";
1197
- import picomatch2 from "picomatch";
1198
1199
  import sirv from "sirv";
1199
- import upath7 from "upath";
1200
+ import upath8 from "upath";
1200
1201
 
1201
- // src/processor/compile.ts
1202
- import { copy as copy3, move } from "fs-extra/esm";
1203
- import fs8 from "node:fs";
1202
+ // src/processor/asset.ts
1203
+ import { copy } from "fs-extra/esm";
1204
+ import fs5 from "node:fs";
1204
1205
  import picomatch from "picomatch";
1205
- import { glob as glob2 } from "tinyglobby";
1206
- import upath6 from "upath";
1206
+ import { glob } from "tinyglobby";
1207
+ import upath3 from "upath";
1208
+ var GlobMatcher = class {
1209
+ constructor(matcherConfig) {
1210
+ this.matcherConfig = matcherConfig;
1211
+ this.#_matchers = matcherConfig.map(
1212
+ ({ patterns, ...options }) => picomatch(patterns, options)
1213
+ );
1214
+ }
1215
+ #_matchers;
1216
+ match(test) {
1217
+ return this.#_matchers.some((matcher) => matcher(test));
1218
+ }
1219
+ async glob(globOptions = {}) {
1220
+ return new Set(
1221
+ (await Promise.all(
1222
+ this.matcherConfig.map(
1223
+ (config) => glob({ ...config, ...globOptions })
1224
+ )
1225
+ )).flat()
1226
+ );
1227
+ }
1228
+ };
1229
+ function getIgnoreThemeDirectoryPatterns({
1230
+ themesDir,
1231
+ cwd: cwd2
1232
+ }) {
1233
+ return pathContains(cwd2, themesDir) ? [
1234
+ `${upath3.relative(cwd2, themesDir)}/node_modules/*/example`,
1235
+ `${upath3.relative(cwd2, themesDir)}/node_modules/*/*/example`
1236
+ ] : [];
1237
+ }
1238
+ function getIgnoreAssetPatterns({
1239
+ outputs,
1240
+ entries,
1241
+ cwd: cwd2
1242
+ }) {
1243
+ return [
1244
+ ...outputs.flatMap(
1245
+ ({ format, path: p }) => !pathContains(cwd2, p) ? [] : format === "webpub" ? upath3.join(upath3.relative(cwd2, p), "**") : upath3.relative(cwd2, p)
1246
+ ),
1247
+ ...entries.flatMap(({ template }) => {
1248
+ return template?.type === "file" && pathContains(cwd2, template.pathname) ? upath3.relative(cwd2, template.pathname) : [];
1249
+ })
1250
+ ];
1251
+ }
1252
+ function getWebPubResourceMatcher({
1253
+ outputs,
1254
+ themesDir,
1255
+ entries,
1256
+ cwd: cwd2,
1257
+ manifestPath
1258
+ }) {
1259
+ return new GlobMatcher([
1260
+ {
1261
+ patterns: [
1262
+ `**/${upath3.relative(cwd2, manifestPath)}`,
1263
+ "**/*.{html,htm,xhtml,xht,css}"
1264
+ ],
1265
+ ignore: [
1266
+ ...getIgnoreAssetPatterns({
1267
+ cwd: cwd2,
1268
+ outputs,
1269
+ entries
1270
+ }),
1271
+ ...getIgnoreThemeDirectoryPatterns({
1272
+ cwd: cwd2,
1273
+ themesDir
1274
+ }),
1275
+ // Ignore node_modules in the root directory
1276
+ "node_modules/**",
1277
+ // only include dotfiles starting with `.vs-`
1278
+ "**/.!(vs-*)/**"
1279
+ ],
1280
+ dot: true,
1281
+ cwd: cwd2
1282
+ }
1283
+ ]);
1284
+ }
1285
+ function getAssetMatcher({
1286
+ copyAsset: { fileExtensions, includes, excludes },
1287
+ outputs,
1288
+ themesDir,
1289
+ entries,
1290
+ cwd: cwd2,
1291
+ ignore = []
1292
+ }) {
1293
+ const ignorePatterns = [
1294
+ ...ignore,
1295
+ ...excludes,
1296
+ ...getIgnoreAssetPatterns({ outputs, entries, cwd: cwd2 })
1297
+ ];
1298
+ return new GlobMatcher([
1299
+ // Step 1: Glob files with an extension in `fileExtension`
1300
+ // Ignore files in node_modules directory, theme example files and files matched `excludes`
1301
+ {
1302
+ patterns: fileExtensions.map((ext) => `**/*.${ext}`),
1303
+ ignore: [
1304
+ "**/node_modules/**",
1305
+ ...ignorePatterns,
1306
+ ...getIgnoreThemeDirectoryPatterns({ themesDir, cwd: cwd2 })
1307
+ ],
1308
+ cwd: cwd2
1309
+ },
1310
+ // Step 2: Glob files matched with `includes`
1311
+ // Ignore only files matched `excludes`
1312
+ {
1313
+ patterns: includes,
1314
+ ignore: ignorePatterns,
1315
+ cwd: cwd2
1316
+ }
1317
+ ]);
1318
+ }
1319
+ async function copyAssets({
1320
+ entryContextDir,
1321
+ workspaceDir,
1322
+ copyAsset,
1323
+ outputs,
1324
+ themesDir,
1325
+ entries
1326
+ }) {
1327
+ if (pathEquals(entryContextDir, workspaceDir)) {
1328
+ return;
1329
+ }
1330
+ const relWorkspaceDir = upath3.relative(entryContextDir, workspaceDir);
1331
+ const assets = await getAssetMatcher({
1332
+ copyAsset,
1333
+ cwd: entryContextDir,
1334
+ outputs,
1335
+ themesDir,
1336
+ entries,
1337
+ ignore: [
1338
+ // don't copy workspace itself
1339
+ ...relWorkspaceDir ? [upath3.join(relWorkspaceDir, "**")] : []
1340
+ ]
1341
+ }).glob({ followSymbolicLinks: true });
1342
+ Logger.debug("assets", assets);
1343
+ for (const asset of assets) {
1344
+ const target = upath3.join(workspaceDir, asset);
1345
+ fs5.mkdirSync(upath3.dirname(target), { recursive: true });
1346
+ await copy(upath3.resolve(entryContextDir, asset), target);
1347
+ }
1348
+ }
1349
+
1350
+ // src/processor/compile.ts
1351
+ import { copy as copy4, move } from "fs-extra/esm";
1352
+ import fs9 from "node:fs";
1353
+ import upath7 from "upath";
1207
1354
  import serializeToXml2 from "w3c-xmlserializer";
1208
1355
  import MIMEType2 from "whatwg-mimetype";
1209
1356
 
1210
1357
  // src/output/webbook.ts
1211
- import { copy as copy2 } from "fs-extra/esm";
1358
+ import { copy as copy3 } from "fs-extra/esm";
1212
1359
  import { lookup as mime3 } from "mime-types";
1213
- import fs6 from "node:fs";
1360
+ import fs7 from "node:fs";
1214
1361
  import { pathToFileURL as pathToFileURL5 } from "node:url";
1215
- import { glob } from "tinyglobby";
1216
- import upath5 from "upath";
1362
+ import { glob as glob2 } from "tinyglobby";
1363
+ import upath6 from "upath";
1217
1364
 
1218
1365
  // src/processor/html.tsx
1219
1366
  import jsdom, {
@@ -1223,7 +1370,7 @@ import jsdom, {
1223
1370
  import DOMPurify from "dompurify";
1224
1371
  import { toHtml } from "hast-util-to-html";
1225
1372
  import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL3 } from "node:url";
1226
- import upath3 from "upath";
1373
+ import upath4 from "upath";
1227
1374
  import MIMEType from "whatwg-mimetype";
1228
1375
  import { jsx, jsxs } from "hastscript/jsx-runtime";
1229
1376
  var createVirtualConsole = (onError) => {
@@ -1284,7 +1431,7 @@ var ResourceLoader = class _ResourceLoader extends BaseResourceLoader {
1284
1431
  if (mimeType === "text/html" && !/\.html?$/.test(url.pathname)) {
1285
1432
  url.pathname = `${url.pathname.replace(/\/$/, "")}/index.html`;
1286
1433
  }
1287
- let relTarget = upath3.relative(rootHref, url.href);
1434
+ let relTarget = upath4.relative(rootHref, url.href);
1288
1435
  return decodeURI(relTarget);
1289
1436
  };
1290
1437
  const fetchedResources = [];
@@ -1303,7 +1450,7 @@ var ResourceLoader = class _ResourceLoader extends BaseResourceLoader {
1303
1450
  } catch (e) {
1304
1451
  }
1305
1452
  const relTarget = normalizeToLocalPath(url, encodingFormat);
1306
- const target = upath3.join(outputDir, relTarget);
1453
+ const target = upath4.join(outputDir, relTarget);
1307
1454
  fetchedResources.push({ url: relTarget, encodingFormat });
1308
1455
  writeFileIfChanged(target, buffer);
1309
1456
  }).catch(onError);
@@ -1492,11 +1639,11 @@ async function generateTocListSection({
1492
1639
  } = transform;
1493
1640
  const structure = await Promise.all(
1494
1641
  entries.map(async (entry) => {
1495
- const href = encodeURI(upath3.relative(distDir, entry.target));
1642
+ const href = encodeURI(upath4.relative(distDir, entry.target));
1496
1643
  const sections = sectionDepth >= 1 ? await getStructuredSectionFromHtml(entry.target, href) : [];
1497
1644
  return {
1498
- title: entry.title || upath3.basename(entry.target, ".html"),
1499
- href: encodeURI(upath3.relative(distDir, entry.target)),
1645
+ title: entry.title || upath4.basename(entry.target, ".html"),
1646
+ href: encodeURI(upath4.relative(distDir, entry.target)),
1500
1647
  sections,
1501
1648
  children: []
1502
1649
  // TODO
@@ -1544,7 +1691,7 @@ async function processTocHtml(dom, {
1544
1691
  const l = document.createElement("link");
1545
1692
  l.setAttribute("rel", "publication");
1546
1693
  l.setAttribute("type", "application/ld+json");
1547
- l.setAttribute("href", encodeURI(upath3.relative(distDir, manifestPath)));
1694
+ l.setAttribute("href", encodeURI(upath4.relative(distDir, manifestPath)));
1548
1695
  document.head.appendChild(l);
1549
1696
  }
1550
1697
  const style = document.querySelector("style[data-vv-style]");
@@ -1803,12 +1950,12 @@ function parsePageListDocument(dom) {
1803
1950
  import archiver from "archiver";
1804
1951
  import { lookup as lookupLanguage } from "bcp-47-match";
1805
1952
  import { XMLBuilder } from "fast-xml-parser";
1806
- import { copy } from "fs-extra/esm";
1953
+ import { copy as copy2 } from "fs-extra/esm";
1807
1954
  import GithubSlugger from "github-slugger";
1808
1955
  import { lookup as mime2 } from "mime-types";
1809
- import fs5 from "node:fs";
1956
+ import fs6 from "node:fs";
1810
1957
  import { pathToFileURL as pathToFileURL4 } from "node:url";
1811
- import upath4 from "upath";
1958
+ import upath5 from "upath";
1812
1959
  import { v4 as uuid } from "uuid";
1813
1960
  import serializeToXml from "w3c-xmlserializer";
1814
1961
  var TOC_ID = "toc";
@@ -1822,12 +1969,12 @@ var COVER_IMAGE_MIMETYPES = [
1822
1969
  "image/webp"
1823
1970
  ];
1824
1971
  var changeExtname = (filepath, newExt) => {
1825
- let ext = upath4.extname(filepath);
1972
+ let ext = upath5.extname(filepath);
1826
1973
  return `${filepath.slice(0, -ext.length)}${newExt}`;
1827
1974
  };
1828
1975
  var getRelativeHref = (target, baseUrl, rootUrl) => {
1829
- const absBasePath = upath4.join("/", baseUrl);
1830
- const absRootPath = upath4.join("/", rootUrl);
1976
+ const absBasePath = upath5.join("/", baseUrl);
1977
+ const absRootPath = upath5.join("/", rootUrl);
1831
1978
  const hrefUrl = new URL(encodeURI(target), pathToFileURL4(absBasePath));
1832
1979
  if (hrefUrl.protocol !== "file:") {
1833
1980
  return target;
@@ -1835,8 +1982,8 @@ var getRelativeHref = (target, baseUrl, rootUrl) => {
1835
1982
  if (/\.html?$/.test(hrefUrl.pathname)) {
1836
1983
  hrefUrl.pathname = changeExtname(hrefUrl.pathname, ".xhtml");
1837
1984
  }
1838
- const pathname = upath4.posix.relative(
1839
- pathToFileURL4(upath4.dirname(absRootPath)).pathname,
1985
+ const pathname = upath5.posix.relative(
1986
+ pathToFileURL4(upath5.dirname(absRootPath)).pathname,
1840
1987
  hrefUrl.pathname
1841
1988
  );
1842
1989
  return `${pathname}${hrefUrl.search}${hrefUrl.hash}`;
@@ -1879,10 +2026,10 @@ async function exportEpub({
1879
2026
  epubVersion
1880
2027
  });
1881
2028
  const [tmpDir] = await useTmpDirectory();
1882
- fs5.mkdirSync(upath4.join(tmpDir, "META-INF"), { recursive: true });
1883
- await copy(webpubDir, upath4.join(tmpDir, "EPUB"));
2029
+ fs6.mkdirSync(upath5.join(tmpDir, "META-INF"), { recursive: true });
2030
+ await copy2(webpubDir, upath5.join(tmpDir, "EPUB"));
1884
2031
  const uid = `urn:uuid:${uuid()}`;
1885
- const entryHtmlRelPath = entryHtmlFile && upath4.relative(webpubDir, upath4.resolve(webpubDir, entryHtmlFile));
2032
+ const entryHtmlRelPath = entryHtmlFile && upath5.relative(webpubDir, upath5.resolve(webpubDir, entryHtmlFile));
1886
2033
  const findPublicationLink = (relType, list, filter) => [list].flat().find(
1887
2034
  (e) => typeof e === "object" && e.rel === relType && (!filter || filter(e))
1888
2035
  );
@@ -1919,7 +2066,7 @@ async function exportEpub({
1919
2066
  return acc;
1920
2067
  } catch (e) {
1921
2068
  }
1922
- if (!fs5.existsSync(upath4.join(tmpDir, "EPUB", url))) {
2069
+ if (!fs6.existsSync(upath5.join(tmpDir, "EPUB", url))) {
1923
2070
  return acc;
1924
2071
  }
1925
2072
  const mediaType = encodingFormat || mime2(url) || "text/plain";
@@ -1973,7 +2120,7 @@ async function exportEpub({
1973
2120
  text: EPUB_LANDMARKS_COVER_ENTRY
1974
2121
  });
1975
2122
  }
1976
- const contextDir = upath4.join(tmpDir, "EPUB");
2123
+ const contextDir = upath5.join(tmpDir, "EPUB");
1977
2124
  const processHtml = async (target2) => {
1978
2125
  let parseResult;
1979
2126
  try {
@@ -2035,20 +2182,20 @@ async function exportEpub({
2035
2182
  });
2036
2183
  }
2037
2184
  if (relManifestPath) {
2038
- await fs5.promises.rm(upath4.join(tmpDir, "EPUB", relManifestPath), {
2185
+ await fs6.promises.rm(upath5.join(tmpDir, "EPUB", relManifestPath), {
2039
2186
  force: true,
2040
2187
  recursive: true
2041
2188
  });
2042
2189
  delete manifestItem[relManifestPath];
2043
2190
  }
2044
- fs5.writeFileSync(
2045
- upath4.join(tmpDir, "META-INF/container.xml"),
2191
+ fs6.writeFileSync(
2192
+ upath5.join(tmpDir, "META-INF/container.xml"),
2046
2193
  EPUB_CONTAINER_XML,
2047
2194
  "utf8"
2048
2195
  );
2049
2196
  Logger.debug(`Generating content.opf`);
2050
- fs5.writeFileSync(
2051
- upath4.join(tmpDir, "EPUB/content.opf"),
2197
+ fs6.writeFileSync(
2198
+ upath5.join(tmpDir, "EPUB/content.opf"),
2052
2199
  buildEpubPackageDocument({
2053
2200
  epubVersion,
2054
2201
  uid,
@@ -2065,13 +2212,13 @@ async function exportEpub({
2065
2212
  async function writeAsXhtml(dom, absPath) {
2066
2213
  const xhtml = `${XML_DECLARATION}
2067
2214
  ${serializeToXml(dom.window.document)}`;
2068
- await fs5.promises.writeFile(changeExtname(absPath, ".xhtml"), xhtml, "utf8");
2215
+ await fs6.promises.writeFile(changeExtname(absPath, ".xhtml"), xhtml, "utf8");
2069
2216
  }
2070
2217
  async function transpileHtmlToXhtml({
2071
2218
  target,
2072
2219
  contextDir
2073
2220
  }) {
2074
- const absPath = upath4.join(contextDir, target);
2221
+ const absPath = upath5.join(contextDir, target);
2075
2222
  const dom = await getJsdomFromUrlOrFile({ src: absPath });
2076
2223
  const { document } = dom.window;
2077
2224
  document.documentElement.removeAttribute("xmlns");
@@ -2081,7 +2228,7 @@ async function transpileHtmlToXhtml({
2081
2228
  el.setAttribute("href", getRelativeHref(href, target, target));
2082
2229
  });
2083
2230
  await writeAsXhtml(dom, absPath);
2084
- await fs5.promises.unlink(absPath);
2231
+ await fs6.promises.unlink(absPath);
2085
2232
  return {
2086
2233
  dom,
2087
2234
  // FIXME: Yes, I recognize this implementation is inadequate.
@@ -2139,7 +2286,7 @@ async function processTocDocument({
2139
2286
  let name = normalizeLocalizableString(content.name, docLanguages);
2140
2287
  if (!name) {
2141
2288
  const dom2 = await getJsdomFromUrlOrFile({
2142
- src: upath4.join(contextDir, changeExtname(content.url, ".xhtml"))
2289
+ src: upath5.join(contextDir, changeExtname(content.url, ".xhtml"))
2143
2290
  });
2144
2291
  name = dom2.window.document.title;
2145
2292
  }
@@ -2192,7 +2339,7 @@ async function processTocDocument({
2192
2339
  }
2193
2340
  publicationLinkEl.parentNode?.removeChild(publicationLinkEl);
2194
2341
  }
2195
- const absPath = upath4.join(contextDir, target);
2342
+ const absPath = upath5.join(contextDir, target);
2196
2343
  await writeAsXhtml(dom, absPath);
2197
2344
  return { tocResourceTree };
2198
2345
  }
@@ -2207,7 +2354,7 @@ async function processPagelistDocument({
2207
2354
  nav.setAttribute("id", PAGELIST_ID);
2208
2355
  nav.setAttribute("epub:type", "page-list");
2209
2356
  }
2210
- const absPath = upath4.join(contextDir, target);
2357
+ const absPath = upath5.join(contextDir, target);
2211
2358
  await writeAsXhtml(dom, absPath);
2212
2359
  return { pageListResourceTree };
2213
2360
  }
@@ -2326,7 +2473,7 @@ async function compressEpub({
2326
2473
  sourceDir
2327
2474
  }) {
2328
2475
  Logger.debug(`Compressing EPUB: ${target}`);
2329
- const output = fs5.createWriteStream(target);
2476
+ const output = fs6.createWriteStream(target);
2330
2477
  const archive = archiver("zip", {
2331
2478
  zlib: { level: 9 }
2332
2479
  // Compression level
@@ -2346,8 +2493,8 @@ async function compressEpub({
2346
2493
  // https://www.w3.org/TR/epub-33/#sec-zip-container-mime
2347
2494
  store: true
2348
2495
  });
2349
- archive.directory(upath4.join(sourceDir, "META-INF"), "META-INF");
2350
- archive.directory(upath4.join(sourceDir, "EPUB"), "EPUB");
2496
+ archive.directory(upath5.join(sourceDir, "META-INF"), "META-INF");
2497
+ archive.directory(upath5.join(sourceDir, "EPUB"), "EPUB");
2351
2498
  archive.finalize();
2352
2499
  });
2353
2500
  }
@@ -2364,11 +2511,11 @@ function sortManifestResources(manifest) {
2364
2511
  async function prepareWebPublicationDirectory({
2365
2512
  outputDir
2366
2513
  }) {
2367
- if (fs6.existsSync(outputDir)) {
2514
+ if (fs7.existsSync(outputDir)) {
2368
2515
  Logger.debug("going to remove existing webpub", outputDir);
2369
- await fs6.promises.rm(outputDir, { force: true, recursive: true });
2516
+ await fs7.promises.rm(outputDir, { force: true, recursive: true });
2370
2517
  }
2371
- fs6.mkdirSync(outputDir, { recursive: true });
2518
+ fs7.mkdirSync(outputDir, { recursive: true });
2372
2519
  }
2373
2520
  function transformPublicationManifest(entity, transformer) {
2374
2521
  const { url: transformUrl } = transformer;
@@ -2465,8 +2612,8 @@ function writePublicationManifest(output, options) {
2465
2612
  typeof thrownError === "string" ? thrownError : thrownError.stack ?? thrownError.message
2466
2613
  );
2467
2614
  }
2468
- fs6.mkdirSync(upath5.dirname(output), { recursive: true });
2469
- fs6.writeFileSync(output, JSON.stringify(encodedManifest, null, 2));
2615
+ fs7.mkdirSync(upath6.dirname(output), { recursive: true });
2616
+ fs7.writeFileSync(output, JSON.stringify(encodedManifest, null, 2));
2470
2617
  return publication;
2471
2618
  }
2472
2619
  async function retrieveWebbookEntry({
@@ -2482,7 +2629,7 @@ async function retrieveWebbookEntry({
2482
2629
  src: webbookEntryUrl,
2483
2630
  resourceLoader
2484
2631
  });
2485
- const entryHtml = viewerInput.webbookPath ? upath5.basename(viewerInput.webbookPath) : decodeURI(dom.window.location.pathname);
2632
+ const entryHtml = viewerInput.webbookPath ? upath6.basename(viewerInput.webbookPath) : decodeURI(dom.window.location.pathname);
2486
2633
  const { manifest, manifestUrl } = await fetchLinkedPublicationManifest({
2487
2634
  dom,
2488
2635
  resourceLoader,
@@ -2493,7 +2640,7 @@ async function retrieveWebbookEntry({
2493
2640
  pathContains2 = (url) => false;
2494
2641
  } else {
2495
2642
  const rootUrl = /^https?:/i.test(webbookEntryUrl) ? new URL("/", webbookEntryUrl).href : new URL(".", webbookEntryUrl).href;
2496
- pathContains2 = (url) => !upath5.relative(rootUrl, url).startsWith("..");
2643
+ pathContains2 = (url) => !upath6.relative(rootUrl, url).startsWith("..");
2497
2644
  }
2498
2645
  const retriever = new Map(resourceLoader.fetcherMap);
2499
2646
  if (manifest && manifestUrl) {
@@ -2562,10 +2709,10 @@ async function retrieveWebbookEntry({
2562
2709
  manifest && JSON.stringify(manifest, null, 2)
2563
2710
  );
2564
2711
  return {
2565
- entryHtmlFile: upath5.join(
2712
+ entryHtmlFile: upath6.join(
2566
2713
  outputDir,
2567
2714
  entryHtml,
2568
- ...upath5.extname(entryHtml) ? [] : ["index.html"]
2715
+ ...upath6.extname(entryHtml) ? [] : ["index.html"]
2569
2716
  ),
2570
2717
  manifest
2571
2718
  };
@@ -2581,12 +2728,12 @@ async function supplyWebPublicationManifestForWebbook({
2581
2728
  const language = config.language || document.documentElement.lang || void 0;
2582
2729
  const title = config.title || document.title || "";
2583
2730
  const author = config.author || document.querySelector('meta[name="author"]')?.getAttribute("content") || "";
2584
- const entry = upath5.relative(outputDir, entryHtmlFile);
2585
- const allFiles = await glob("**", {
2731
+ const entry = upath6.relative(outputDir, entryHtmlFile);
2732
+ const allFiles = await glob2("**", {
2586
2733
  cwd: outputDir
2587
2734
  });
2588
2735
  const manifest = writePublicationManifest(
2589
- upath5.join(outputDir, MANIFEST_FILENAME),
2736
+ upath6.join(outputDir, MANIFEST_FILENAME),
2590
2737
  {
2591
2738
  title,
2592
2739
  author,
@@ -2603,13 +2750,13 @@ async function supplyWebPublicationManifestForWebbook({
2603
2750
  link.setAttribute("type", "application/ld+json");
2604
2751
  link.setAttribute(
2605
2752
  "href",
2606
- upath5.relative(
2607
- upath5.dirname(entryHtmlFile),
2608
- upath5.join(outputDir, MANIFEST_FILENAME)
2753
+ upath6.relative(
2754
+ upath6.dirname(entryHtmlFile),
2755
+ upath6.join(outputDir, MANIFEST_FILENAME)
2609
2756
  )
2610
2757
  );
2611
2758
  document.head.appendChild(link);
2612
- await fs6.promises.writeFile(entryHtmlFile, dom.serialize(), "utf8");
2759
+ await fs7.promises.writeFile(entryHtmlFile, dom.serialize(), "utf8");
2613
2760
  Logger.debug(
2614
2761
  "Generated publication manifest from HTML",
2615
2762
  JSON.stringify(manifest, null, 2)
@@ -2624,51 +2771,33 @@ async function copyWebPublicationAssets({
2624
2771
  manifestPath,
2625
2772
  input,
2626
2773
  outputDir,
2627
- entries,
2628
- customStyle,
2629
- customUserStyle
2774
+ entries
2630
2775
  }) {
2776
+ debugger;
2631
2777
  const relExportAliases = exportAliases.map(({ source, target }) => ({
2632
- source: upath5.relative(input, source),
2633
- target: upath5.relative(input, target)
2778
+ source: upath6.relative(input, source),
2779
+ target: upath6.relative(input, target)
2634
2780
  })).filter(({ source }) => !source.startsWith(".."));
2781
+ const assetMatcher = getAssetMatcher({
2782
+ copyAsset,
2783
+ cwd: input,
2784
+ outputs,
2785
+ themesDir,
2786
+ entries
2787
+ });
2788
+ const webResourceMatcher = getWebPubResourceMatcher({
2789
+ cwd: input,
2790
+ outputs,
2791
+ themesDir,
2792
+ entries,
2793
+ manifestPath
2794
+ });
2635
2795
  const allFiles = /* @__PURE__ */ new Set([
2636
- ...await globAssetFiles({
2637
- copyAsset,
2638
- cwd: input,
2639
- outputs,
2640
- themesDir,
2641
- entries,
2642
- customStyle,
2643
- customUserStyle
2644
- }),
2645
- ...await glob(
2646
- [
2647
- `**/${upath5.relative(input, manifestPath)}`,
2648
- "**/*.{html,htm,xhtml,xht,css}"
2649
- ],
2650
- {
2651
- cwd: input,
2652
- ignore: [
2653
- ...getIgnoreAssetPatterns({
2654
- cwd: input,
2655
- outputs,
2656
- entries
2657
- }),
2658
- ...getIgnoreThemeExamplePatterns({
2659
- cwd: input,
2660
- themesDir
2661
- }),
2662
- // Ignore node_modules in the root directory
2663
- "node_modules/**",
2664
- // only include dotfiles starting with `.vs-`
2665
- "**/.!(vs-*)/**"
2666
- ],
2667
- // follow symbolic links to copy local theme packages
2668
- followSymbolicLinks: true,
2669
- dot: true
2670
- }
2671
- )
2796
+ ...await assetMatcher.glob(),
2797
+ ...await webResourceMatcher.glob({
2798
+ // follow symbolic links to copy local theme packages
2799
+ followSymbolicLinks: true
2800
+ })
2672
2801
  ]);
2673
2802
  for (const alias of relExportAliases) {
2674
2803
  allFiles.delete(alias.target);
@@ -2685,24 +2814,24 @@ async function copyWebPublicationAssets({
2685
2814
  )
2686
2815
  );
2687
2816
  const resources = [];
2688
- let actualManifestPath = upath5.join(
2817
+ let actualManifestPath = upath6.join(
2689
2818
  outputDir,
2690
- upath5.relative(input, manifestPath)
2819
+ upath6.relative(input, manifestPath)
2691
2820
  );
2692
2821
  for (const file of allFiles) {
2693
2822
  const alias = relExportAliases.find(({ source }) => source === file);
2694
2823
  const relTarget = alias?.target || file;
2695
2824
  resources.push(relTarget);
2696
- const target = upath5.join(outputDir, relTarget);
2697
- fs6.mkdirSync(upath5.dirname(target), { recursive: true });
2698
- await copy2(upath5.join(input, file), target);
2699
- if (alias && pathEquals(upath5.join(input, alias.source), manifestPath)) {
2825
+ const target = upath6.join(outputDir, relTarget);
2826
+ fs7.mkdirSync(upath6.dirname(target), { recursive: true });
2827
+ await copy3(upath6.join(input, file), target);
2828
+ if (alias && pathEquals(upath6.join(input, alias.source), manifestPath)) {
2700
2829
  actualManifestPath = target;
2701
2830
  }
2702
2831
  }
2703
2832
  Logger.debug("webbook publication.json", actualManifestPath);
2704
2833
  const manifest = decodePublicationManifest(
2705
- JSON.parse(fs6.readFileSync(actualManifestPath, "utf8"))
2834
+ JSON.parse(fs7.readFileSync(actualManifestPath, "utf8"))
2706
2835
  );
2707
2836
  for (const entry of relExportAliases) {
2708
2837
  const rewriteAliasPath = (e) => {
@@ -2734,14 +2863,14 @@ async function copyWebPublicationAssets({
2734
2863
  ...[manifest.resources || []].flat(),
2735
2864
  ...resources.flatMap((file) => {
2736
2865
  if (preDefinedResources.includes(file) || // Omit publication.json itself
2737
- pathEquals(file, upath5.relative(outputDir, actualManifestPath))) {
2866
+ pathEquals(file, upath6.relative(outputDir, actualManifestPath))) {
2738
2867
  return [];
2739
2868
  }
2740
2869
  return file;
2741
2870
  })
2742
2871
  ];
2743
2872
  sortManifestResources(manifest);
2744
- fs6.writeFileSync(
2873
+ fs7.writeFileSync(
2745
2874
  actualManifestPath,
2746
2875
  JSON.stringify(encodePublicationManifest(manifest), null, 2)
2747
2876
  );
@@ -2773,7 +2902,7 @@ async function buildWebPublication({
2773
2902
  if (config.input.format === "markdown") {
2774
2903
  const entry = [manifest.readingOrder].flat()[0];
2775
2904
  if (entry) {
2776
- entryHtmlFile = upath5.join(
2905
+ entryHtmlFile = upath6.join(
2777
2906
  outputDir,
2778
2907
  typeof entry === "string" ? entry : entry.url
2779
2908
  );
@@ -2798,7 +2927,7 @@ async function buildWebPublication({
2798
2927
  webpubDir: outputDir,
2799
2928
  entryHtmlFile,
2800
2929
  manifest,
2801
- relManifestPath: actualManifestPath && upath5.relative(outputDir, actualManifestPath),
2930
+ relManifestPath: actualManifestPath && upath6.relative(outputDir, actualManifestPath),
2802
2931
  target: target.path,
2803
2932
  epubVersion: target.version
2804
2933
  });
@@ -2808,12 +2937,12 @@ async function buildWebPublication({
2808
2937
 
2809
2938
  // src/processor/theme.ts
2810
2939
  import Arborist from "@npmcli/arborist";
2811
- import fs7 from "node:fs";
2940
+ import fs8 from "node:fs";
2812
2941
  async function checkThemeInstallationNecessity({
2813
2942
  themesDir,
2814
2943
  themeIndexes
2815
2944
  }) {
2816
- if (!fs7.existsSync(themesDir)) {
2945
+ if (!fs8.existsSync(themesDir)) {
2817
2946
  return [...themeIndexes].some((theme) => theme.type === "package");
2818
2947
  }
2819
2948
  const commonOpt = {
@@ -2831,7 +2960,7 @@ async function installThemeDependencies({
2831
2960
  themesDir,
2832
2961
  themeIndexes
2833
2962
  }) {
2834
- fs7.mkdirSync(themesDir, { recursive: true });
2963
+ fs8.mkdirSync(themesDir, { recursive: true });
2835
2964
  try {
2836
2965
  const commonOpt = {
2837
2966
  path: themesDir,
@@ -2866,21 +2995,21 @@ function locateThemePath(theme, from) {
2866
2995
  return theme.location;
2867
2996
  }
2868
2997
  if (theme.type === "file") {
2869
- return upath6.relative(from, theme.location);
2998
+ return upath7.relative(from, theme.location);
2870
2999
  }
2871
3000
  if (theme.importPath) {
2872
3001
  return [theme.importPath].flat().map((locator) => {
2873
- const resolvedPath = upath6.resolve(theme.location, locator);
2874
- if (!pathContains(theme.location, resolvedPath) || !fs8.existsSync(resolvedPath)) {
3002
+ const resolvedPath = upath7.resolve(theme.location, locator);
3003
+ if (!pathContains(theme.location, resolvedPath) || !fs9.existsSync(resolvedPath)) {
2875
3004
  throw new Error(
2876
3005
  `Could not find a style path ${theme.importPath} for the theme: ${theme.name}.`
2877
3006
  );
2878
3007
  }
2879
- return upath6.relative(from, resolvedPath);
3008
+ return upath7.relative(from, resolvedPath);
2880
3009
  });
2881
3010
  } else {
2882
- const pkgJsonPath = upath6.join(theme.location, "package.json");
2883
- const packageJson = JSON.parse(fs8.readFileSync(pkgJsonPath, "utf8"));
3011
+ const pkgJsonPath = upath7.join(theme.location, "package.json");
3012
+ const packageJson = JSON.parse(fs9.readFileSync(pkgJsonPath, "utf8"));
2884
3013
  const maybeStyle = packageJson?.vivliostyle?.theme?.style ?? packageJson.style ?? packageJson.main;
2885
3014
  if (!maybeStyle) {
2886
3015
  throw new DetailError(
@@ -2888,7 +3017,7 @@ function locateThemePath(theme, from) {
2888
3017
  "Please ensure this package satisfies a `vivliostyle.theme.style` property."
2889
3018
  );
2890
3019
  }
2891
- return upath6.relative(from, upath6.join(theme.location, maybeStyle));
3020
+ return upath7.relative(from, upath7.join(theme.location, maybeStyle));
2892
3021
  }
2893
3022
  }
2894
3023
  async function cleanupWorkspace({
@@ -2904,27 +3033,27 @@ async function cleanupWorkspace({
2904
3033
  }
2905
3034
  Logger.debug("cleanup workspace files", workspaceDir);
2906
3035
  let movedWorkspacePath;
2907
- if (pathContains(workspaceDir, themesDir) && fs8.existsSync(themesDir)) {
2908
- movedWorkspacePath = upath6.join(
2909
- upath6.dirname(workspaceDir),
3036
+ if (pathContains(workspaceDir, themesDir) && fs9.existsSync(themesDir)) {
3037
+ movedWorkspacePath = upath7.join(
3038
+ upath7.dirname(workspaceDir),
2910
3039
  `.vs-${Date.now()}`
2911
3040
  );
2912
- const movedThemePath = upath6.join(
3041
+ const movedThemePath = upath7.join(
2913
3042
  movedWorkspacePath,
2914
- upath6.relative(workspaceDir, themesDir)
3043
+ upath7.relative(workspaceDir, themesDir)
2915
3044
  );
2916
- fs8.mkdirSync(upath6.dirname(movedThemePath), { recursive: true });
3045
+ fs9.mkdirSync(upath7.dirname(movedThemePath), { recursive: true });
2917
3046
  registerExitHandler(
2918
3047
  `Removing the moved workspace directory: ${movedWorkspacePath}`,
2919
3048
  () => {
2920
- if (movedWorkspacePath && fs8.existsSync(movedWorkspacePath)) {
2921
- fs8.rmSync(movedWorkspacePath, { recursive: true, force: true });
3049
+ if (movedWorkspacePath && fs9.existsSync(movedWorkspacePath)) {
3050
+ fs9.rmSync(movedWorkspacePath, { recursive: true, force: true });
2922
3051
  }
2923
3052
  }
2924
3053
  );
2925
3054
  await move(themesDir, movedThemePath);
2926
3055
  }
2927
- await fs8.promises.rm(workspaceDir, { recursive: true, force: true });
3056
+ await fs9.promises.rm(workspaceDir, { recursive: true, force: true });
2928
3057
  if (movedWorkspacePath) {
2929
3058
  await move(movedWorkspacePath, workspaceDir);
2930
3059
  }
@@ -2933,10 +3062,10 @@ async function prepareThemeDirectory({
2933
3062
  themesDir,
2934
3063
  themeIndexes
2935
3064
  }) {
2936
- if (fs8.existsSync(upath6.join(themesDir, "packages")) && !fs8.existsSync(upath6.join(themesDir, "node_modules"))) {
2937
- fs8.renameSync(
2938
- upath6.join(themesDir, "packages"),
2939
- upath6.join(themesDir, "node_modules")
3065
+ if (fs9.existsSync(upath7.join(themesDir, "packages")) && !fs9.existsSync(upath7.join(themesDir, "node_modules"))) {
3066
+ fs9.renameSync(
3067
+ upath7.join(themesDir, "packages"),
3068
+ upath7.join(themesDir, "node_modules")
2940
3069
  );
2941
3070
  }
2942
3071
  if (await checkThemeInstallationNecessity({ themesDir, themeIndexes })) {
@@ -2945,8 +3074,8 @@ async function prepareThemeDirectory({
2945
3074
  }
2946
3075
  for (const theme of themeIndexes) {
2947
3076
  if (theme.type === "file" && !pathEquals(theme.source, theme.location)) {
2948
- fs8.mkdirSync(upath6.dirname(theme.location), { recursive: true });
2949
- await copy3(theme.source, theme.location);
3077
+ fs9.mkdirSync(upath7.dirname(theme.location), { recursive: true });
3078
+ await copy4(theme.source, theme.location);
2950
3079
  }
2951
3080
  }
2952
3081
  }
@@ -2966,7 +3095,7 @@ async function transformManuscript(entry, {
2966
3095
  let resourceLoader;
2967
3096
  let resourceUrl;
2968
3097
  const style = entry.themes.flatMap(
2969
- (theme) => locateThemePath(theme, upath6.dirname(entry.target))
3098
+ (theme) => locateThemePath(theme, upath7.dirname(entry.target))
2970
3099
  );
2971
3100
  if (source?.type === "file") {
2972
3101
  if (source.contentType === "text/markdown") {
@@ -2991,7 +3120,7 @@ async function transformManuscript(entry, {
2991
3120
  });
2992
3121
  } else {
2993
3122
  if (!pathEquals(source.pathname, entry.target)) {
2994
- await copy3(source.pathname, entry.target);
3123
+ await copy4(source.pathname, entry.target);
2995
3124
  }
2996
3125
  }
2997
3126
  } else if (source?.type === "uri") {
@@ -3061,7 +3190,7 @@ async function transformManuscript(entry, {
3061
3190
  content = await processTocHtml(content, {
3062
3191
  entries: manuscriptEntries,
3063
3192
  manifestPath,
3064
- distDir: upath6.dirname(contentsEntry.target),
3193
+ distDir: upath7.dirname(contentsEntry.target),
3065
3194
  tocTitle: contentsEntry.tocTitle,
3066
3195
  sectionDepth: contentsEntry.sectionDepth,
3067
3196
  styleOptions: contentsEntry,
@@ -3071,10 +3200,10 @@ async function transformManuscript(entry, {
3071
3200
  if (entry.rel === "cover") {
3072
3201
  const coverEntry = entry;
3073
3202
  content = await processCoverHtml(content, {
3074
- imageSrc: upath6.relative(
3075
- upath6.join(
3203
+ imageSrc: upath7.relative(
3204
+ upath7.join(
3076
3205
  entryContextDir,
3077
- upath6.relative(workspaceDir, coverEntry.target),
3206
+ upath7.relative(workspaceDir, coverEntry.target),
3078
3207
  ".."
3079
3208
  ),
3080
3209
  coverEntry.coverImageSrc
@@ -3124,7 +3253,7 @@ async function generateManifest({
3124
3253
  }) {
3125
3254
  const manifestEntries = entries.map((entry) => ({
3126
3255
  title: entry.rel === "contents" && entry.tocTitle || entry.title,
3127
- path: upath6.relative(workspaceDir, entry.target),
3256
+ path: upath7.relative(workspaceDir, entry.target),
3128
3257
  encodingFormat: !("contentType" in entry) || entry.contentType === "text/markdown" || entry.contentType === "text/html" ? void 0 : entry.contentType,
3129
3258
  rel: entry.rel
3130
3259
  }));
@@ -3134,7 +3263,7 @@ async function generateManifest({
3134
3263
  language,
3135
3264
  readingProgression,
3136
3265
  cover: cover && {
3137
- url: upath6.relative(entryContextDir, cover.src),
3266
+ url: upath7.relative(entryContextDir, cover.src),
3138
3267
  name: cover.name
3139
3268
  },
3140
3269
  entries: manifestEntries,
@@ -3157,123 +3286,6 @@ async function compile(config) {
3157
3286
  await generateManifest(config);
3158
3287
  }
3159
3288
  }
3160
- function getIgnoreThemeExamplePatterns({
3161
- themesDir,
3162
- cwd: cwd2
3163
- }) {
3164
- return pathContains(cwd2, themesDir) ? [
3165
- `${upath6.relative(cwd2, themesDir)}/node_modules/*/example`,
3166
- `${upath6.relative(cwd2, themesDir)}/node_modules/*/*/example`
3167
- ] : [];
3168
- }
3169
- function getIgnoreAssetPatterns({
3170
- outputs,
3171
- entries,
3172
- cwd: cwd2
3173
- }) {
3174
- return [
3175
- ...outputs.flatMap(
3176
- ({ format, path: p }) => !pathContains(cwd2, p) ? [] : format === "webpub" ? upath6.join(upath6.relative(cwd2, p), "**") : upath6.relative(cwd2, p)
3177
- ),
3178
- ...entries.flatMap(({ template }) => {
3179
- return template?.type === "file" && pathContains(cwd2, template.pathname) ? upath6.relative(cwd2, template.pathname) : [];
3180
- })
3181
- ];
3182
- }
3183
- function getAssetMatcherSettings({
3184
- copyAsset: { fileExtensions, includes, excludes },
3185
- outputs,
3186
- themesDir,
3187
- entries,
3188
- customStyle,
3189
- customUserStyle,
3190
- cwd: cwd2,
3191
- ignore = []
3192
- }) {
3193
- const ignorePatterns = [
3194
- ...ignore,
3195
- ...excludes,
3196
- ...getIgnoreAssetPatterns({ outputs, entries, cwd: cwd2 })
3197
- ];
3198
- Logger.debug("globAssetFiles > ignorePatterns", ignorePatterns);
3199
- return [
3200
- // Step 1: Glob files with an extension in `fileExtension`
3201
- // Ignore files in node_modules directory, theme example files and files matched `excludes`
3202
- {
3203
- patterns: fileExtensions.map((ext) => `**/*.${ext}`),
3204
- ignore: [
3205
- "**/node_modules/**",
3206
- ...ignorePatterns,
3207
- ...getIgnoreThemeExamplePatterns({ themesDir, cwd: cwd2 })
3208
- ]
3209
- },
3210
- // Step 2: Glob files matched with `includes`
3211
- // Ignore only files matched `excludes`
3212
- {
3213
- patterns: [
3214
- ...includes,
3215
- // Copy custom (user) style if specified
3216
- customStyle,
3217
- customUserStyle
3218
- ].filter((s) => Boolean(s)),
3219
- ignore: ignorePatterns
3220
- }
3221
- ];
3222
- }
3223
- function getAssetMatcher(arg) {
3224
- const matchers = getAssetMatcherSettings(arg).map(
3225
- ({ patterns, ignore }) => picomatch(patterns, { ignore })
3226
- );
3227
- return (test) => matchers.some((matcher) => matcher(test));
3228
- }
3229
- async function globAssetFiles(arg) {
3230
- const settings = getAssetMatcherSettings(arg);
3231
- return new Set(
3232
- (await Promise.all(
3233
- settings.map(
3234
- ({ patterns, ignore }) => glob2(patterns, {
3235
- cwd: arg.cwd,
3236
- ignore,
3237
- followSymbolicLinks: true
3238
- })
3239
- )
3240
- )).flat()
3241
- );
3242
- }
3243
- async function copyAssets({
3244
- entryContextDir,
3245
- workspaceDir,
3246
- copyAsset,
3247
- outputs,
3248
- themesDir,
3249
- entries,
3250
- customStyle,
3251
- customUserStyle
3252
- }) {
3253
- if (pathEquals(entryContextDir, workspaceDir)) {
3254
- return;
3255
- }
3256
- const relWorkspaceDir = upath6.relative(entryContextDir, workspaceDir);
3257
- const assets = await globAssetFiles({
3258
- copyAsset,
3259
- cwd: entryContextDir,
3260
- outputs,
3261
- themesDir,
3262
- entries,
3263
- customStyle,
3264
- customUserStyle,
3265
- ignore: [
3266
- // don't copy workspace itself
3267
- ...relWorkspaceDir ? [upath6.join(relWorkspaceDir, "**")] : []
3268
- ]
3269
- });
3270
- Logger.debug("assets", assets);
3271
- for (const asset of assets) {
3272
- const target = upath6.join(workspaceDir, asset);
3273
- fs8.mkdirSync(upath6.dirname(target), { recursive: true });
3274
- await copy3(upath6.resolve(entryContextDir, asset), target);
3275
- }
3276
- }
3277
3289
 
3278
3290
  // src/vite/plugin-util.ts
3279
3291
  var headStartTagRe = /<head[^>]*>/i;
@@ -3307,7 +3319,7 @@ function createEntriesRouteLookup(entries, cwd2) {
3307
3319
  return arr;
3308
3320
  };
3309
3321
  const cache = entries.reduce((acc, e) => {
3310
- acc[`/${upath7.relative(cwd2, e.target).normalize().replace(/\\+/g, "/")}`] = e;
3322
+ acc[`/${upath8.relative(cwd2, e.target).normalize().replace(/\\+/g, "/")}`] = e;
3311
3323
  return acc;
3312
3324
  }, {});
3313
3325
  return (uri) => {
@@ -3321,17 +3333,25 @@ function getWorkspaceMatcher({
3321
3333
  workspaceDir,
3322
3334
  themesDir,
3323
3335
  viewerInput,
3324
- themeIndexes
3336
+ themeIndexes,
3337
+ entries,
3338
+ outputs
3325
3339
  }) {
3340
+ if (viewerInput.type === "webpub") {
3341
+ return getWebPubResourceMatcher({
3342
+ outputs,
3343
+ themesDir,
3344
+ entries,
3345
+ cwd: workspaceDir,
3346
+ manifestPath: viewerInput.manifestPath
3347
+ });
3348
+ }
3326
3349
  let entryFiles = [];
3327
3350
  switch (viewerInput.type) {
3328
- case "webpub":
3329
- entryFiles = [upath7.relative(workspaceDir, viewerInput.manifestPath)];
3330
- break;
3331
3351
  case "epub":
3332
3352
  entryFiles = [
3333
- upath7.join(
3334
- upath7.relative(workspaceDir, viewerInput.epubTmpOutputDir),
3353
+ upath8.join(
3354
+ upath8.relative(workspaceDir, viewerInput.epubTmpOutputDir),
3335
3355
  "**"
3336
3356
  )
3337
3357
  ];
@@ -3343,16 +3363,14 @@ function getWorkspaceMatcher({
3343
3363
  default:
3344
3364
  entryFiles = viewerInput;
3345
3365
  }
3346
- return picomatch2(
3347
- [
3348
- ...entryFiles,
3349
- ...pathContains(workspaceDir, themesDir) ? [upath7.join(upath7.relative(workspaceDir, themesDir), "**")] : [],
3350
- ...[...themeIndexes].flatMap(
3351
- (theme) => theme.type === "file" && pathContains(workspaceDir, theme.location) ? [upath7.relative(workspaceDir, theme.location)] : []
3352
- )
3353
- ],
3354
- { dot: true, ignore: ["node_modules/**"] }
3355
- );
3366
+ return new GlobMatcher([
3367
+ {
3368
+ patterns: entryFiles,
3369
+ ignore: ["node_modules/**"],
3370
+ dot: true,
3371
+ cwd: workspaceDir
3372
+ }
3373
+ ]);
3356
3374
  }
3357
3375
  function vsDevServerPlugin({
3358
3376
  config: _config,
@@ -3404,6 +3422,16 @@ function vsDevServerPlugin({
3404
3422
  serveAssets,
3405
3423
  serveAssetsMatcher
3406
3424
  };
3425
+ if (needToUpdateManifest) {
3426
+ Logger.debug(
3427
+ "dev-server > serveWorkspaceMatcher %O",
3428
+ serveWorkspaceMatcher.matcherConfig
3429
+ );
3430
+ Logger.debug(
3431
+ "dev-server > serveAssetsMatcher %O",
3432
+ serveAssetsMatcher.matcherConfig
3433
+ );
3434
+ }
3407
3435
  const configPath = locateVivliostyleConfig(inlineConfig);
3408
3436
  const projectDeps = [];
3409
3437
  if (configPath) {
@@ -3488,6 +3516,7 @@ function vsDevServerPlugin({
3488
3516
  res.setHeader("Location", `${expected}${qs || ""}`);
3489
3517
  return res.end();
3490
3518
  }
3519
+ Logger.debug("dev-server > request %s", pathname);
3491
3520
  const cachePromise = transformCache.get(entry.target);
3492
3521
  if (cachePromise) {
3493
3522
  const cached = await cachePromise;
@@ -3536,15 +3565,34 @@ function vsDevServerPlugin({
3536
3565
  serveAssetsMatcher
3537
3566
  } = program;
3538
3567
  const [_, pathname] = decodeURI(req.url).match(urlMatchRe) ?? [];
3539
- if (pathname && serveWorkspaceMatcher(pathname.slice(1))) {
3540
- req.url = req.url.slice(config.base.length);
3541
- return serveWorkspace(req, res, next);
3568
+ if (!pathname) {
3569
+ return next();
3542
3570
  }
3543
- if (pathname && serveAssetsMatcher(pathname.slice(1))) {
3571
+ const handleWorkspace = (next2) => {
3572
+ if (!serveWorkspaceMatcher.match(pathname.slice(1))) {
3573
+ return next2();
3574
+ }
3575
+ Logger.debug("dev-server > serveWorkspace %s", pathname);
3576
+ const url = req.url;
3544
3577
  req.url = req.url.slice(config.base.length);
3545
- return serveAssets(req, res, next);
3546
- }
3547
- next();
3578
+ return serveWorkspace(req, res, () => {
3579
+ req.url = url;
3580
+ next2();
3581
+ });
3582
+ };
3583
+ const handleAssets = (next2) => {
3584
+ if (!serveAssetsMatcher.match(pathname.slice(1))) {
3585
+ return next2();
3586
+ }
3587
+ Logger.debug("dev-server > serveAssets %s", pathname);
3588
+ const url = req.url;
3589
+ req.url = url.slice(config.base.length);
3590
+ return serveAssets(req, res, () => {
3591
+ req.url = url;
3592
+ next2();
3593
+ });
3594
+ };
3595
+ handleWorkspace(() => handleAssets(next));
3548
3596
  };
3549
3597
  return {
3550
3598
  name: "vivliostyle:dev-server",
@@ -3593,7 +3641,7 @@ function vsDevServerPlugin({
3593
3641
 
3594
3642
  // src/vite/vite-plugin-static-serve.ts
3595
3643
  import sirv2 from "sirv";
3596
- import upath8 from "upath";
3644
+ import upath9 from "upath";
3597
3645
  function vsStaticServePlugin({
3598
3646
  config: _config,
3599
3647
  inlineConfig
@@ -3607,7 +3655,7 @@ function vsStaticServePlugin({
3607
3655
  ([base, dirs]) => dirs.map(
3608
3656
  (dir) => [
3609
3657
  base,
3610
- sirv2(upath8.resolve(config.serverRootDir, dir), {
3658
+ sirv2(upath9.resolve(config.serverRootDir, dir), {
3611
3659
  dev: true,
3612
3660
  etag: false
3613
3661
  })
@@ -3636,9 +3684,9 @@ function vsStaticServePlugin({
3636
3684
  }
3637
3685
 
3638
3686
  // src/vite/vite-plugin-viewer.ts
3639
- import fs9 from "node:fs";
3687
+ import fs10 from "node:fs";
3640
3688
  import sirv3 from "sirv";
3641
- import upath9 from "upath";
3689
+ import upath10 from "upath";
3642
3690
  var viewerClientId = "@vivliostyle:viewer:client";
3643
3691
  var viewerClientRequestPath = `/${viewerClientId}`;
3644
3692
  var viewerClientContent = (
@@ -3651,13 +3699,13 @@ if (import.meta.hot) {
3651
3699
  }`
3652
3700
  );
3653
3701
  function vsViewerPlugin(_) {
3654
- const serveRootDir = upath9.join(viewerRoot, "lib");
3702
+ const serveRootDir = upath10.join(viewerRoot, "lib");
3655
3703
  const serve = sirv3(serveRootDir, { dev: false, etag: true });
3656
3704
  let cachedIndexHtml;
3657
3705
  const middleware = async function vivliostyleViewerMiddleware(req, res, next) {
3658
3706
  if (req.url === "/" || req.url === "/index.html") {
3659
3707
  cachedIndexHtml ??= prependToHead(
3660
- fs9.readFileSync(upath9.join(serveRootDir, "index.html"), "utf-8"),
3708
+ fs10.readFileSync(upath10.join(serveRootDir, "index.html"), "utf-8"),
3661
3709
  `<script type="module" src="${viewerClientRequestPath}"></script>`
3662
3710
  );
3663
3711
  res.statusCode = 200;
@@ -3712,11 +3760,11 @@ function getViewerParams(src, {
3712
3760
  let viewerParams = src ? `src=${escapeParam(src)}` : "";
3713
3761
  viewerParams += `&bookMode=${!singleDoc}&renderAllPages=${!quick}`;
3714
3762
  if (customStyle) {
3715
- const param = isValidUri(customStyle) ? customStyle : upath10.posix.join(base, customStyle);
3763
+ const param = isValidUri(customStyle) ? customStyle : upath11.posix.join(base, customStyle);
3716
3764
  viewerParams += `&style=${escapeParam(param)}`;
3717
3765
  }
3718
3766
  if (customUserStyle) {
3719
- const param = isValidUri(customUserStyle) ? customUserStyle : upath10.posix.join(base, customUserStyle);
3767
+ const param = isValidUri(customUserStyle) ? customUserStyle : upath11.posix.join(base, customUserStyle);
3720
3768
  viewerParams += `&userStyle=${escapeParam(param)}`;
3721
3769
  }
3722
3770
  if (pageSizeValue || cropMarks || bleed || cropOffset || css) {
@@ -3761,7 +3809,7 @@ async function getSourceUrl({
3761
3809
  input = viewerInput.epubOpfPath;
3762
3810
  break;
3763
3811
  case "epub": {
3764
- if (!fs10.existsSync(viewerInput.epubTmpOutputDir)) {
3812
+ if (!fs11.existsSync(viewerInput.epubTmpOutputDir)) {
3765
3813
  await openEpub(viewerInput.epubPath, viewerInput.epubTmpOutputDir);
3766
3814
  }
3767
3815
  input = getDefaultEpubOpfPath(viewerInput.epubTmpOutputDir);
@@ -3771,7 +3819,7 @@ async function getSourceUrl({
3771
3819
  input = viewerInput;
3772
3820
  }
3773
3821
  return (isValidUri(input) ? new URL2(input) : new URL2(
3774
- upath10.posix.join(base, upath10.relative(workspaceDir, input)),
3822
+ upath11.posix.join(base, upath11.relative(workspaceDir, input)),
3775
3823
  rootUrl
3776
3824
  )).href;
3777
3825
  }
@@ -3823,8 +3871,8 @@ async function createViteServer({
3823
3871
  if (config.serverRootDir === config.workspaceDir) {
3824
3872
  const { cacheDir } = viteInlineConfig;
3825
3873
  registerExitHandler("Removing the Vite cacheDir", () => {
3826
- if (fs10.existsSync(cacheDir)) {
3827
- fs10.rmSync(cacheDir, { recursive: true });
3874
+ if (fs11.existsSync(cacheDir)) {
3875
+ fs11.rmSync(cacheDir, { recursive: true });
3828
3876
  }
3829
3877
  });
3830
3878
  }
@@ -3897,11 +3945,11 @@ export {
3897
3945
  getFullBrowserName,
3898
3946
  launchPreview,
3899
3947
  vsBrowserPlugin,
3948
+ copyAssets,
3900
3949
  buildWebPublication,
3901
3950
  cleanupWorkspace,
3902
3951
  prepareThemeDirectory,
3903
3952
  compile,
3904
- copyAssets,
3905
3953
  vsDevServerPlugin,
3906
3954
  vsStaticServePlugin,
3907
3955
  vsViewerPlugin,
@@ -3909,4 +3957,4 @@ export {
3909
3957
  getViewerFullUrl,
3910
3958
  createViteServer
3911
3959
  };
3912
- //# sourceMappingURL=chunk-XYOW6HSN.js.map
3960
+ //# sourceMappingURL=chunk-2E4GDR4I.js.map