@slidev/cli 52.15.2 → 52.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,17 @@
1
- import { a as resolveImportPath, c as toAtFS, i as resolveEntry, n as getRoots, o as resolveImportUrl, r as isInstalledGlobally, s as resolveSourceFiles, t as createResolver } from "./resolver-BhqywfGz.mjs";
1
+ import { a as resolveImportPath, c as toAtFS, i as resolveEntry, n as getRoots, o as resolveImportUrl, r as isInstalledGlobally, s as resolveSourceFiles, t as createResolver } from "./resolver-CZx9LFrt.mjs";
2
2
  import { builtinModules } from "node:module";
3
3
  import path, { basename, dirname, join, relative, resolve, win32 } from "node:path";
4
- import { loadConfigFromFile, mergeConfig, parseSync } from "vite";
4
+ import process from "node:process";
5
+ import { createServer, loadConfigFromFile, mergeConfig, parseSync } from "vite";
5
6
  import MarkdownExit from "markdown-exit";
6
- import fs, { existsSync, realpathSync } from "node:fs";
7
+ import fs, { existsSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
7
8
  import fs$1, { readFile } from "node:fs/promises";
8
9
  import { fileURLToPath, pathToFileURL } from "node:url";
9
10
  import { ensureSuffix, isString, isTruthy, notNullish, objectEntries, objectMap, range, slash, uniq } from "@antfu/utils";
10
11
  import { bold, gray, red, white, yellow } from "ansis";
11
12
  import { createResolve } from "mlly";
12
13
  import { findDepPkgJsonPath } from "vitefu";
14
+ import { createHash } from "node:crypto";
13
15
  import { createJiti } from "jiti";
14
16
  import YAML from "yaml";
15
17
  import IconsResolver from "unplugin-icons/resolver";
@@ -32,9 +34,9 @@ import Markdown from "unplugin-vue-markdown/vite";
32
34
  import MarkdownItComark from "@comark/markdown-it";
33
35
  import MarkdownItFootnote from "markdown-it-footnote";
34
36
  import MarkdownItGitHubAlerts from "markdown-it-github-alerts";
37
+ import { toKeyedTokens } from "@shikijs/magic-move/core";
35
38
  import { defineCodeblockTransformer } from "@slidev/types";
36
39
  import lz from "lz-string";
37
- import { toKeyedTokens } from "shiki-magic-move/core";
38
40
  import { encode } from "plantuml-encoder";
39
41
  import { SourceMapConsumer } from "source-map-js";
40
42
  import { fromAsyncCodeToHtml } from "@shikijs/markdown-it/async";
@@ -43,7 +45,6 @@ import UnoCSS from "unocss/vite";
43
45
  import { mergeConfigs, presetIcons } from "unocss";
44
46
  import Vue from "@vitejs/plugin-vue";
45
47
  import VueJsx from "@vitejs/plugin-vue-jsx";
46
-
47
48
  //#region node/syntax/link.ts
48
49
  const RE_DIGITS_ONLY = /^\d+$/;
49
50
  function MarkdownItLink(md) {
@@ -64,7 +65,6 @@ function MarkdownItLink(md) {
64
65
  return defaultRender(tokens, idx, options, env, self);
65
66
  };
66
67
  }
67
-
68
68
  //#endregion
69
69
  //#region node/utils.ts
70
70
  const RE_WHITESPACE_ONLY = /^\s*$/;
@@ -104,8 +104,8 @@ function updateFrontmatterPatch(source, frontmatter) {
104
104
  else {
105
105
  const valueNode = doc.createNode(value);
106
106
  let found = false;
107
- YAML.visit(doc.contents, { Pair(_key, node, path$1) {
108
- if (path$1.length === 1 && YAML.isScalar(node.key) && node.key.value === key) {
107
+ YAML.visit(doc.contents, { Pair(_key, node, path) {
108
+ if (path.length === 1 && YAML.isScalar(node.key) && node.key.value === key) {
109
109
  node.value = valueNode;
110
110
  found = true;
111
111
  return YAML.visit.BREAK;
@@ -119,13 +119,13 @@ function updateFrontmatterPatch(source, frontmatter) {
119
119
  }
120
120
  }
121
121
  function getBodyJson(req) {
122
- return new Promise((resolve$2, reject) => {
122
+ return new Promise((resolve, reject) => {
123
123
  let body = "";
124
124
  req.on("data", (chunk) => body += chunk);
125
125
  req.on("error", reject);
126
126
  req.on("end", () => {
127
127
  try {
128
- resolve$2(JSON.parse(body) || {});
128
+ resolve(JSON.parse(body) || {});
129
129
  } catch (e) {
130
130
  reject(e);
131
131
  }
@@ -137,39 +137,51 @@ function getImportGlobRelativePath(from, to) {
137
137
  const normalizedTo = slash(to);
138
138
  return slash(RE_WINDOWS_DRIVE.test(normalizedFrom) || RE_WINDOWS_DRIVE.test(normalizedTo) ? win32.relative(normalizedFrom, normalizedTo) : relative(normalizedFrom, normalizedTo));
139
139
  }
140
- function makeAbsoluteImportGlob(self, globs, options = {}, baseRoot) {
141
- const root = baseRoot && globs.some((glob) => RE_WINDOWS_DRIVE.test(slash(glob))) ? baseRoot : void 0;
140
+ function resolveImportGlobProxyModule(proxyBase, content) {
141
+ return `${proxyBase}.${createHash("sha256").update(content).digest("hex").slice(0, 10)}.ts`;
142
+ }
143
+ function createMakeAbsoluteImportGlob(baseRoot) {
144
+ const proxyModules = /* @__PURE__ */ new Map();
145
+ const proxyBase = slash(join(baseRoot, "node_modules/.slidev/virtual/import-glob"));
146
+ return function makeAbsoluteImportGlob(globs, options = {}) {
147
+ const content = `export default ${makeAbsoluteImportGlobExpression(dirname(proxyBase), globs, options)}\n`;
148
+ const proxyModule = resolveImportGlobProxyModule(proxyBase, content);
149
+ if (proxyModules.get(proxyModule) !== content) {
150
+ mkdirSync(dirname(proxyModule), { recursive: true });
151
+ writeFileSync(proxyModule, content, "utf-8");
152
+ proxyModules.set(proxyModule, content);
153
+ }
154
+ return toAtFS(proxyModule);
155
+ };
156
+ }
157
+ function makeAbsoluteImportGlobExpression(self, globs, options = {}) {
142
158
  const relativeGlobs = globs.map((glob) => {
143
- const relativeGlob = getImportGlobRelativePath(root ?? self, glob);
144
- return root && !relativeGlob.startsWith(".") && !RE_WINDOWS_DRIVE.test(relativeGlob) ? `./${relativeGlob}` : relativeGlob;
159
+ const relativeGlob = getImportGlobRelativePath(self, glob);
160
+ return !relativeGlob.startsWith(".") && !RE_WINDOWS_DRIVE.test(relativeGlob) ? `./${relativeGlob}` : relativeGlob;
145
161
  });
146
162
  const opts = {
147
163
  eager: true,
148
164
  exhaustive: true,
149
- ...root ? { base: "/" } : {},
150
165
  ...options
151
166
  };
152
167
  return `import.meta.glob(${JSON.stringify(relativeGlobs)}, ${JSON.stringify(opts)})`;
153
168
  }
154
-
155
169
  //#endregion
156
170
  //#region node/setups/load.ts
157
171
  async function loadSetups(roots, filename, args, extraLoader) {
158
172
  return await Promise.all(roots.flatMap((root) => {
159
173
  const tasks = [];
160
- const path$1 = resolve(root, "setup", filename);
161
- if (existsSync(path$1)) tasks.push(loadModule(path$1).then((mod) => mod.default(...args)));
174
+ const path = resolve(root, "setup", filename);
175
+ if (existsSync(path)) tasks.push(loadModule(path).then((mod) => mod.default(...args)));
162
176
  if (extraLoader) tasks.push(...extraLoader(root));
163
177
  return tasks;
164
178
  }));
165
179
  }
166
-
167
180
  //#endregion
168
181
  //#region node/setups/vite-plugins.ts
169
182
  async function setupVitePlugins(options) {
170
183
  return await loadSetups(options.roots, "vite-plugins.ts", [options]);
171
184
  }
172
-
173
185
  //#endregion
174
186
  //#region node/vite/compilerFlagsVue.ts
175
187
  const RE_VUE_FILE = /\.vue(?:$|\?)/;
@@ -181,8 +193,8 @@ function createVueCompilerFlagsPlugin(options) {
181
193
  return {
182
194
  name: "slidev:flags",
183
195
  enforce: "pre",
184
- transform: { handler(code, id$2) {
185
- if (!RE_VUE_FILE.test(id$2) && !id$2.includes("?vue&")) return;
196
+ transform: { handler(code, id) {
197
+ if (!RE_VUE_FILE.test(id) && !id.includes("?vue&")) return;
186
198
  const original = code;
187
199
  define.forEach(([from, to]) => {
188
200
  code = code.replaceAll(from, to);
@@ -191,7 +203,6 @@ function createVueCompilerFlagsPlugin(options) {
191
203
  } }
192
204
  };
193
205
  }
194
-
195
206
  //#endregion
196
207
  //#region node/vite/components.ts
197
208
  const RE_VUE_EXT$1 = /\.vue$/;
@@ -227,7 +238,6 @@ function createComponentsPlugin({ clientRoot, roots }, pluginOptions) {
227
238
  ...pluginOptions.components
228
239
  });
229
240
  }
230
-
231
241
  //#endregion
232
242
  //#region node/vite/common.ts
233
243
  const regexSlideReqPath = /^\/__slidev\/slides\/(\d+)\.json$/;
@@ -236,7 +246,6 @@ const regexSlideSourceId = /__slidev_(\d+)\.(md|frontmatter)$/;
236
246
  const templateInjectionMarker = "/* @slidev-injection */";
237
247
  const templateImportContextUtils = `import { useSlideContext as _useSlideContext, frontmatterToProps as _frontmatterToProps } from "@slidev/client/context.ts"`;
238
248
  const templateInitContext = `const { $slidev, $nav, $clicksContext, $clicks, $page, $renderContext, $frontmatter } = _useSlideContext()`;
239
-
240
249
  //#endregion
241
250
  //#region node/vite/contextInjection.ts
242
251
  const RE_EXPORT_DEFAULT_OBJECT = /export\s+default\s+\{/;
@@ -247,9 +256,9 @@ const RE_INJECT_OPTION = /.*inject\s*:\s*([[{])/;
247
256
  function createContextInjectionPlugin() {
248
257
  return {
249
258
  name: "slidev:context-injection",
250
- transform: { async handler(code, id$2) {
251
- if (!id$2.endsWith(".vue") || id$2.includes("/@slidev/client/") || id$2.includes("/packages/client/")) return;
252
- if (code.includes(templateInjectionMarker) || code.includes("useSlideContext()")) return code;
259
+ transform: { async handler(code, id) {
260
+ if (!id.endsWith(".vue") || id.includes("/@slidev/client/") || id.includes("/packages/client/")) return;
261
+ if (code.includes("/* @slidev-injection */") || code.includes("useSlideContext()")) return code;
253
262
  const imports = [
254
263
  templateImportContextUtils,
255
264
  templateInitContext,
@@ -291,7 +300,6 @@ ${code.slice(scriptIndex)}`;
291
300
  } }
292
301
  };
293
302
  }
294
-
295
303
  //#endregion
296
304
  //#region node/vite/extendConfig.ts
297
305
  const RE_SLIDEV_CLIENT = /^@slidev\/client$/;
@@ -311,6 +319,7 @@ const INCLUDE_GLOBAL = [
311
319
  const INCLUDE_LOCAL = INCLUDE_GLOBAL.map((i) => `@slidev/cli > @slidev/client > ${i}`);
312
320
  const EXCLUDE_GLOBAL = [
313
321
  "@antfu/utils",
322
+ "@shikijs/magic-move/vue",
314
323
  "@shikijs/monaco",
315
324
  "@shikijs/vitepress-twoslash/client",
316
325
  "@slidev/client",
@@ -332,7 +341,6 @@ const EXCLUDE_GLOBAL = [
332
341
  "fuse.js",
333
342
  "mermaid",
334
343
  "monaco-editor",
335
- "shiki-magic-move/vue",
336
344
  "shiki",
337
345
  "shiki/core",
338
346
  "vue-demi",
@@ -412,18 +420,18 @@ function createConfigPlugin(options) {
412
420
  if (chunkInfo.moduleIds.filter((i) => i.match(RE_MONACO_EDITOR)).length > chunkInfo.moduleIds.length * .6) return "assets/monaco/[name]-[hash].js";
413
421
  return DEFAULT;
414
422
  },
415
- manualChunks(id$2) {
416
- if (id$2.startsWith("/@slidev-monaco-types/") || id$2.includes("/@slidev/monaco-types") || id$2.endsWith("?monaco-types&raw")) return "monaco/bundled-types";
417
- if (id$2.includes("/shiki/") || id$2.includes("/@shikijs/")) return `modules/shiki`;
418
- if (id$2.startsWith("~icons/")) return "modules/unplugin-icons";
419
- const matchedAsyncModule = ASYNC_MODULES.find((i) => id$2.includes(`/node_modules/${i}`));
423
+ manualChunks(id) {
424
+ if (id.startsWith("/@slidev-monaco-types/") || id.includes("/@slidev/monaco-types") || id.endsWith("?monaco-types&raw")) return "monaco/bundled-types";
425
+ if (id.includes("/shiki/") || id.includes("/@shikijs/")) return `modules/shiki`;
426
+ if (id.startsWith("~icons/")) return "modules/unplugin-icons";
427
+ const matchedAsyncModule = ASYNC_MODULES.find((i) => id.includes(`/node_modules/${i}`));
420
428
  if (matchedAsyncModule) return `modules/${matchedAsyncModule.replace("@", "").replace("/", "-")}`;
421
429
  }
422
430
  } } },
423
431
  cacheDir: isInstalledGlobally.value ? join(options.cliRoot, "node_modules/.vite") : void 0
424
432
  };
425
- function isSlidevClient(id$2) {
426
- return id$2.includes("/@slidev/") || id$2.includes("/slidev/packages/client/") || id$2.includes("/@vueuse/");
433
+ function isSlidevClient(id) {
434
+ return id.includes("/@slidev/") || id.includes("/slidev/packages/client/") || id.includes("/@vueuse/");
427
435
  }
428
436
  return mergeConfig(injection, config);
429
437
  },
@@ -444,7 +452,6 @@ function createConfigPlugin(options) {
444
452
  }
445
453
  };
446
454
  }
447
-
448
455
  //#endregion
449
456
  //#region node/vite/hmrPatch.ts
450
457
  /**
@@ -455,14 +462,13 @@ function createHmrPatchPlugin() {
455
462
  name: "slidev:hmr-patch",
456
463
  transform: {
457
464
  filter: { id: { include: regexSlideSourceId } },
458
- handler(code, id$2) {
459
- if (!id$2.match(regexSlideSourceId)) return;
465
+ handler(code, id) {
466
+ if (!id.match(regexSlideSourceId)) return;
460
467
  return code.replace("if (_rerender_only)", "if (false)");
461
468
  }
462
469
  }
463
470
  };
464
471
  }
465
-
466
472
  //#endregion
467
473
  //#region node/vite/icons.ts
468
474
  function createIconsPlugin(options, pluginOptions) {
@@ -472,7 +478,6 @@ function createIconsPlugin(options, pluginOptions) {
472
478
  ...pluginOptions.icons
473
479
  });
474
480
  }
475
-
476
481
  //#endregion
477
482
  //#region node/virtual/deprecated.ts
478
483
  /**
@@ -505,7 +510,6 @@ console.warn('/@slidev/titles.md is deprecated, import from #slidev/title-render
505
510
  `;
506
511
  }
507
512
  };
508
-
509
513
  //#endregion
510
514
  //#region node/virtual/titles.ts
511
515
  const templateTitleRendererMd = {
@@ -522,7 +526,6 @@ const templateTitleRenderer = {
522
526
  return "export { default } from \"/@slidev/title-renderer.md\"";
523
527
  }
524
528
  };
525
-
526
529
  //#endregion
527
530
  //#region node/vite/importGuard.ts
528
531
  const virtualSlideMarkdownIds = new Set([templateTitleRendererMd.id, templateLegacyTitles.id]);
@@ -535,10 +538,10 @@ function createSlideImportGuardPlugin() {
535
538
  config = resolved;
536
539
  allowRoots = config.server.fs.allow.map(normalizeFsPath);
537
540
  },
538
- async transform(code, id$2) {
539
- if (!isSlideMarkdownId(id$2) || !config?.server.fs.strict) return null;
540
- const importer = filePathFromId(id$2) ?? id$2;
541
- await Promise.all(extractImportSources(code, id$2).map(async ({ value, start }) => {
541
+ async transform(code, id) {
542
+ if (!isSlideMarkdownId(id) || !config?.server.fs.strict) return null;
543
+ const importer = filePathFromId(id) ?? id;
544
+ await Promise.all(extractImportSources(code, id).map(async ({ value, start }) => {
542
545
  const resolved = await this.resolve(value, importer, { skipSelf: true });
543
546
  if (!resolved || resolved.external) return;
544
547
  const filePath = filePathFromId(resolved.id);
@@ -552,12 +555,12 @@ function createSlideImportGuardPlugin() {
552
555
  }
553
556
  };
554
557
  }
555
- function isSlideMarkdownId(id$2) {
556
- const clean = cleanUrl$1(id$2);
558
+ function isSlideMarkdownId(id) {
559
+ const clean = cleanUrl$1(id);
557
560
  return regexSlideSourceId.test(clean) || virtualSlideMarkdownIds.has(clean);
558
561
  }
559
- function filePathFromId(id$2) {
560
- const clean = cleanUrl$1(id$2);
562
+ function filePathFromId(id) {
563
+ const clean = cleanUrl$1(id);
561
564
  if (clean.startsWith("file://")) return fileURLToPath(clean);
562
565
  if (clean.startsWith("/@fs/")) return clean.slice(4);
563
566
  if (clean.startsWith("/@")) return null;
@@ -567,8 +570,8 @@ function filePathFromId(id$2) {
567
570
  function isAllowedFile(filePath, allowRoots) {
568
571
  return allowRoots.some((root) => isFileInRoot(root, filePath));
569
572
  }
570
- function extractImportSources(code, id$2) {
571
- const result = parseSync(id$2, code);
573
+ function extractImportSources(code, id) {
574
+ const result = parseSync(id, code);
572
575
  const sources = [];
573
576
  for (const item of result.module.staticImports) sources.push({
574
577
  value: item.moduleRequest.value,
@@ -587,8 +590,8 @@ function extractImportSources(code, id$2) {
587
590
  }
588
591
  return sources;
589
592
  }
590
- function cleanUrl$1(id$2) {
591
- return id$2.replace(/[?#].*$/, "");
593
+ function cleanUrl$1(id) {
594
+ return id.replace(/[?#].*$/, "");
592
595
  }
593
596
  function normalizeFsPath(filePath) {
594
597
  const absolute = path.resolve(filePath);
@@ -602,8 +605,8 @@ function normalizeMissingFsPath(filePath) {
602
605
  return path.join(normalizeMissingFsPath(dir), path.basename(filePath));
603
606
  }
604
607
  function isFileInRoot(root, filePath) {
605
- const relative$1 = path.relative(root, filePath);
606
- return relative$1 === "" || !!relative$1 && !relative$1.startsWith("..") && !path.isAbsolute(relative$1);
608
+ const relative = path.relative(root, filePath);
609
+ return relative === "" || !!relative && !relative.startsWith("..") && !path.isAbsolute(relative);
607
610
  }
608
611
  function isDependencyFile(filePath) {
609
612
  return filePath.split(/[\\/]/).includes("node_modules");
@@ -624,7 +627,6 @@ function parseStringLiteral(raw) {
624
627
  return trimmed.slice(1, -1);
625
628
  }
626
629
  }
627
-
628
630
  //#endregion
629
631
  //#region node/vite/inspect.ts
630
632
  async function createInspectPlugin(options, pluginOptions) {
@@ -636,7 +638,6 @@ async function createInspectPlugin(options, pluginOptions) {
636
638
  ...pluginOptions.inspect
637
639
  });
638
640
  }
639
-
640
641
  //#endregion
641
642
  //#region node/vite/layoutWrapper.ts
642
643
  const RE_SCRIPT_SETUP_TAG = /^<script setup.*>/m;
@@ -645,8 +646,8 @@ function createLayoutWrapperPlugin({ data, utils }) {
645
646
  name: "slidev:layout-wrapper",
646
647
  transform: {
647
648
  filter: { id: { include: regexSlideSourceId } },
648
- async handler(code, id$2) {
649
- const match = id$2.match(regexSlideSourceId);
649
+ async handler(code, id) {
650
+ const match = id.match(regexSlideSourceId);
650
651
  if (!match) return;
651
652
  const [, no, type] = match;
652
653
  if (type !== "md") return;
@@ -682,11 +683,9 @@ function createLayoutWrapperPlugin({ data, utils }) {
682
683
  }
683
684
  };
684
685
  }
685
-
686
686
  //#endregion
687
687
  //#region package.json
688
- var version = "52.15.2";
689
-
688
+ var version = "52.16.0";
690
689
  //#endregion
691
690
  //#region node/integrations/addons.ts
692
691
  async function resolveAddons(addonsInConfig) {
@@ -705,26 +704,21 @@ async function resolveAddons(addonsInConfig) {
705
704
  if (Array.isArray(userPkgJson.slidev?.addons)) await Promise.all(userPkgJson.slidev.addons.map((addon) => resolveAddon(addon, userRoot)));
706
705
  return resolved;
707
706
  }
708
-
709
- //#endregion
710
- //#region node/integrations/themes.ts
711
- const officialThemes = {
707
+ const resolveTheme = createResolver("theme", {
712
708
  "none": "",
713
709
  "default": "@slidev/theme-default",
714
710
  "seriph": "@slidev/theme-seriph",
715
711
  "apple-basic": "@slidev/theme-apple-basic",
716
712
  "shibainu": "@slidev/theme-shibainu",
717
713
  "bricks": "@slidev/theme-bricks"
718
- };
719
- const resolveTheme = createResolver("theme", officialThemes);
714
+ });
720
715
  async function getThemeMeta(name, root) {
721
- const path$1 = join(root, "package.json");
722
- if (!existsSync(path$1)) return {};
723
- const { slidev = {}, engines = {} } = JSON.parse(await fs$1.readFile(path$1, "utf-8"));
716
+ const path = join(root, "package.json");
717
+ if (!existsSync(path)) return {};
718
+ const { slidev = {}, engines = {} } = JSON.parse(await fs$1.readFile(path, "utf-8"));
724
719
  if (engines.slidev && !satisfies(version, engines.slidev, { includePrerelease: true })) throw new Error(`[slidev] theme "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
725
720
  return slidev;
726
721
  }
727
-
728
722
  //#endregion
729
723
  //#region node/setups/indexHtml.ts
730
724
  const RE_TRAILING_SLASH = /\/$/;
@@ -761,11 +755,11 @@ async function setupIndexHtml({ mode, entry, clientRoot, userRoot, roots, data,
761
755
  let body = "";
762
756
  const inputs = [];
763
757
  for (const root of roots) {
764
- const path$1 = join(root, "index.html");
765
- if (!existsSync(path$1)) continue;
766
- const html = await readFile(path$1, "utf-8");
758
+ const path = join(root, "index.html");
759
+ if (!existsSync(path)) continue;
760
+ const html = await readFile(path, "utf-8");
767
761
  if (root === userRoot && html.includes("<!DOCTYPE")) {
768
- console.error(yellow(`[Slidev] Ignored provided index.html with doctype declaration. (${white(path$1)})`));
762
+ console.error(yellow(`[Slidev] Ignored provided index.html with doctype declaration. (${white(path)})`));
769
763
  console.error(yellow("This file may be generated by Slidev, please remove it from your project."));
770
764
  continue;
771
765
  }
@@ -815,7 +809,7 @@ async function setupIndexHtml({ mode, entry, clientRoot, userRoot, roots, data,
815
809
  },
816
810
  {
817
811
  property: "slidev:entry",
818
- content: mode === "dev" && slash(entry)
812
+ content: mode === "dev" ? slash(entry) : null
819
813
  },
820
814
  {
821
815
  name: "description",
@@ -878,16 +872,14 @@ async function setupIndexHtml({ mode, entry, clientRoot, userRoot, roots, data,
878
872
  main = main.replace("__ENTRY__", encodeURI(basePrefix + mainUrl));
879
873
  }
880
874
  main = main.replace("<!-- body -->", body);
881
- return await transformHtmlTemplate(unhead, main);
875
+ return transformHtmlTemplate(unhead, main);
882
876
  }
883
-
884
877
  //#endregion
885
878
  //#region node/setups/katex.ts
886
879
  async function setupKatex(roots) {
887
880
  const options = await loadSetups(roots, "katex.ts", []);
888
881
  return Object.assign({ strict: false }, ...options);
889
882
  }
890
-
891
883
  //#endregion
892
884
  //#region ../client/setup/shiki-options.ts
893
885
  function resolveShikiOptions(options) {
@@ -959,16 +951,17 @@ function extractThemeNames(themes) {
959
951
  return [key, name];
960
952
  });
961
953
  }
962
-
963
954
  //#endregion
964
955
  //#region node/setups/shiki.ts
965
956
  let cachedRoots;
966
957
  let cachedShiki;
967
958
  async function setupShiki(roots) {
968
959
  if (cachedRoots === roots) return cachedShiki;
969
- const { options, languageInput, themeInput } = resolveShikiOptions(await loadSetups(roots, "shiki.ts", [{ async loadTheme(path$1) {
960
+ const { options, languageInput, themeInput } = resolveShikiOptions(await loadSetups(roots, "shiki.ts", [{
961
+ /** @deprecated */
962
+ async loadTheme(path) {
970
963
  console.warn("[slidev] `loadTheme` in `setup/shiki.ts` is deprecated. Pass directly the theme name it's supported by Shiki. For custom themes, load it manually via `JSON.parse(fs.readFileSync(path, 'utf-8'))` and pass the raw JSON object instead.");
971
- return JSON.parse(await fs$1.readFile(path$1, "utf-8"));
964
+ return JSON.parse(await fs$1.readFile(path, "utf-8"));
972
965
  } }]));
973
966
  const createHighlighter = createBundledHighlighter({
974
967
  engine: createJavaScriptRegexEngine,
@@ -981,7 +974,6 @@ async function setupShiki(roots) {
981
974
  shikiOptions: options
982
975
  };
983
976
  }
984
-
985
977
  //#endregion
986
978
  //#region node/options.ts
987
979
  const RE_FILE_EXTENSION = /\.\w+$/;
@@ -989,7 +981,10 @@ const debug = createDebug("slidev:options");
989
981
  async function resolveOptions(entryOptions, mode) {
990
982
  const entry = await resolveEntry(entryOptions.entry);
991
983
  const rootsInfo = await getRoots(entry);
992
- const loaded = await parser.load(rootsInfo.userRoot, entry, void 0, mode);
984
+ const loaded = await parser.load({
985
+ userRoot: rootsInfo.userRoot,
986
+ roots: [rootsInfo.userRoot]
987
+ }, entry, void 0, mode);
993
988
  let themeRaw = entryOptions.theme || loaded.headmatter.theme;
994
989
  themeRaw = themeRaw === null ? "none" : themeRaw || "default";
995
990
  const [theme, themeRoot] = await resolveTheme(themeRaw, entry);
@@ -1091,7 +1086,6 @@ function getDefine(options) {
1091
1086
  __SLIDEV_HAS_SERVER__: options.mode !== "build"
1092
1087
  }, (v, k) => [v, JSON.stringify(k)]);
1093
1088
  }
1094
-
1095
1089
  //#endregion
1096
1090
  //#region node/syntax/utils.ts
1097
1091
  function normalizeRangeStr(rangeStr = "") {
@@ -1103,7 +1097,6 @@ function normalizeRangeStr(rangeStr = "") {
1103
1097
  function escapeVueInCode(md) {
1104
1098
  return md.replace(/\{\{/g, "&lbrace;&lbrace;");
1105
1099
  }
1106
-
1107
1100
  //#endregion
1108
1101
  //#region node/syntax/katex.ts
1109
1102
  const RE_KATEX_BLOCK_INFO = /^\{([\w*,|-]+)\}\s*(\{[^}]*\})?/;
@@ -1228,9 +1221,9 @@ function MarkdownItKatex(md, options) {
1228
1221
  };
1229
1222
  const blockRenderer = function(tokens, idx) {
1230
1223
  const token = tokens[idx];
1231
- const [, rangeStr, options$1] = RE_KATEX_BLOCK_INFO.exec(token.info) || [];
1224
+ const [, rangeStr, options] = RE_KATEX_BLOCK_INFO.exec(token.info) || [];
1232
1225
  const ranges = normalizeRangeStr(rangeStr);
1233
- return `<KaTexBlockWrapper ${options$1 ? `v-bind="${options$1}"` : ""} :ranges='${JSON.stringify(ranges)}'>${katexBlock(tokens[idx].content)}</KaTexBlockWrapper>\n`;
1226
+ return `<KaTexBlockWrapper ${options ? `v-bind="${options}"` : ""} :ranges='${JSON.stringify(ranges)}'>${katexBlock(tokens[idx].content)}</KaTexBlockWrapper>\n`;
1234
1227
  };
1235
1228
  md.inline.ruler.after("escape", "math_inline", math_inline);
1236
1229
  md.block.ruler.after("blockquote", "math_block", math_block, { alt: [
@@ -1242,24 +1235,22 @@ function MarkdownItKatex(md, options) {
1242
1235
  md.renderer.rules.math_inline = inlineRenderer;
1243
1236
  md.renderer.rules.math_block = blockRenderer;
1244
1237
  }
1245
-
1246
- //#endregion
1247
- //#region node/virtual/conditional-styles.ts
1248
- const id$1 = "/@slidev/conditional-styles";
1249
1238
  const templateConditionalStyles = {
1250
- id: id$1,
1251
- async getContent({ data, roots, userRoot }) {
1239
+ id: "/@slidev/conditional-styles",
1240
+ async getContent({ data, roots }) {
1252
1241
  const imports = [];
1253
- for (const root of roots) imports.push(makeAbsoluteImportGlob(id$1, [
1254
- join(root, "styles/index.{ts,js,css}"),
1255
- join(root, "styles.{ts,js,css}"),
1256
- join(root, "style.{ts,js,css}")
1257
- ], {}, userRoot));
1242
+ for (const root of roots) {
1243
+ const importPath = this.makeAbsoluteImportGlob([
1244
+ join(root, "styles/index.{ts,js,css}"),
1245
+ join(root, "styles.{ts,js,css}"),
1246
+ join(root, "style.{ts,js,css}")
1247
+ ]);
1248
+ imports.push(`import ${JSON.stringify(importPath)}`);
1249
+ }
1258
1250
  if (data.features.katex) imports.push(`import "${await resolveImportUrl("katex/dist/katex.min.css")}"`);
1259
1251
  return imports.join("\n");
1260
1252
  }
1261
1253
  };
1262
-
1263
1254
  //#endregion
1264
1255
  //#region node/virtual/configs.ts
1265
1256
  const templateConfigs = {
@@ -1274,26 +1265,24 @@ const templateConfigs = {
1274
1265
  return `export default ${JSON.stringify(config)}`;
1275
1266
  }
1276
1267
  };
1277
-
1278
- //#endregion
1279
- //#region node/virtual/global-layers.ts
1280
- const id = `/@slidev/global-layers`;
1281
1268
  const templateGlobalLayers = {
1282
- id,
1283
- getContent({ roots, userRoot }) {
1269
+ id: `/@slidev/global-layers`,
1270
+ getContent({ roots }) {
1271
+ const { makeAbsoluteImportGlob } = this;
1272
+ const imports = [`import { h } from 'vue'`];
1273
+ let importIndex = 0;
1284
1274
  function* getComponent(name, names) {
1285
1275
  yield `const ${name}Components = [\n`;
1286
1276
  for (const root of roots) {
1287
- const globs = names.map((name$1) => join(root, `${name$1}.{ts,js,vue}`));
1288
- yield " Object.values(";
1289
- yield makeAbsoluteImportGlob(id, globs, { import: "default" }, userRoot);
1290
- yield ")[0],\n";
1277
+ const globs = names.map((name) => join(root, `${name}.{ts,js,vue}`));
1278
+ const importName = `__slidev_global_layer_${importIndex++}`;
1279
+ imports.push(`import ${importName} from ${JSON.stringify(makeAbsoluteImportGlob(globs, { import: "default" }))}`);
1280
+ yield ` Object.values(${importName})[0],\n`;
1291
1281
  }
1292
1282
  yield `].filter(Boolean)\n`;
1293
1283
  yield `export const ${name} = { render: () => ${name}Components.map(comp => h(comp)) }\n\n`;
1294
1284
  }
1295
- return [
1296
- `import { h } from 'vue'\n\n`,
1285
+ const body = [
1297
1286
  ...getComponent("GlobalTop", [
1298
1287
  "global",
1299
1288
  "global-top",
@@ -1303,9 +1292,9 @@ const templateGlobalLayers = {
1303
1292
  ...getComponent("SlideTop", ["slide-top", "SlideTop"]),
1304
1293
  ...getComponent("SlideBottom", ["slide-bottom", "SlideBottom"])
1305
1294
  ].join("");
1295
+ return `${imports.join("\n")}\n\n${body}`;
1306
1296
  }
1307
1297
  };
1308
-
1309
1298
  //#endregion
1310
1299
  //#region node/virtual/layouts.ts
1311
1300
  const templateLayouts = {
@@ -1319,7 +1308,6 @@ const templateLayouts = {
1319
1308
  return [imports.join("\n"), `export default {\n${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}\n}`].join("\n\n");
1320
1309
  }
1321
1310
  };
1322
-
1323
1311
  //#endregion
1324
1312
  //#region node/virtual/monaco-deps.ts
1325
1313
  const templateMonacoRunDeps = {
@@ -1345,7 +1333,6 @@ const templateMonacoRunDeps = {
1345
1333
  return result;
1346
1334
  }
1347
1335
  };
1348
-
1349
1336
  //#endregion
1350
1337
  //#region node/virtual/monaco-types.ts
1351
1338
  const templateMonacoTypes = {
@@ -1382,7 +1369,6 @@ const templateMonacoTypes = {
1382
1369
  return result;
1383
1370
  }
1384
1371
  };
1385
-
1386
1372
  //#endregion
1387
1373
  //#region node/virtual/nav-controls.ts
1388
1374
  const templateNavControls = {
@@ -1398,21 +1384,24 @@ export default {
1398
1384
  }`;
1399
1385
  }
1400
1386
  };
1401
-
1402
1387
  //#endregion
1403
1388
  //#region node/virtual/setups.ts
1404
1389
  function createSetupTemplate(name) {
1405
- const id$2 = `/@slidev/setups/${name}`;
1406
1390
  return {
1407
- id: id$2,
1408
- getContent({ roots, userRoot }) {
1409
- return `export default [${roots.map((root) => {
1410
- return `Object.values(${makeAbsoluteImportGlob(id$2, [join(root, `setup/${name}.{ts,js,mts,mjs}`)], { import: "default" }, userRoot)})[0]`;
1411
- }).join(", ")}].filter(Boolean)`;
1391
+ id: `/@slidev/setups/${name}`,
1392
+ getContent({ roots }) {
1393
+ const imports = [];
1394
+ const globs = roots.map((root) => {
1395
+ const glob = join(root, `setup/${name}.{ts,js,mts,mjs}`);
1396
+ const importName = `__slidev_setup_${imports.length}`;
1397
+ imports.push(`import ${importName} from ${JSON.stringify(this.makeAbsoluteImportGlob([glob], { import: "default" }))}`);
1398
+ return `Object.values(${importName})[0]`;
1399
+ });
1400
+ return `${imports.join("\n")}\n\nexport default [${globs.join(", ")}].filter(Boolean)`;
1412
1401
  }
1413
1402
  };
1414
1403
  }
1415
- const setupModules = [
1404
+ const templateSetups = [
1416
1405
  "shiki",
1417
1406
  "code-runners",
1418
1407
  "monaco",
@@ -1423,9 +1412,7 @@ const setupModules = [
1423
1412
  "routes",
1424
1413
  "shortcuts",
1425
1414
  "context-menu"
1426
- ];
1427
- const templateSetups = setupModules.map(createSetupTemplate);
1428
-
1415
+ ].map(createSetupTemplate);
1429
1416
  //#endregion
1430
1417
  //#region node/virtual/slides.ts
1431
1418
  const VIRTUAL_SLIDE_PREFIX = "/@slidev/slides/";
@@ -1463,7 +1450,6 @@ const templateSlides = {
1463
1450
  ].join("\n");
1464
1451
  }
1465
1452
  };
1466
-
1467
1453
  //#endregion
1468
1454
  //#region node/virtual/index.ts
1469
1455
  const templates = [
@@ -1481,7 +1467,6 @@ const templates = [
1481
1467
  templateLegacyRoutes,
1482
1468
  templateLegacyTitles
1483
1469
  ];
1484
-
1485
1470
  //#endregion
1486
1471
  //#region node/vite/loaders.ts
1487
1472
  const RE_WORD_CHARS_ONLY = /^[\w-]+$/;
@@ -1493,13 +1478,14 @@ function createSlidesLoader(options, serverOptions) {
1493
1478
  const hmrSlidesIndexes = /* @__PURE__ */ new Set();
1494
1479
  let server;
1495
1480
  let skipHmr = null;
1481
+ const makeAbsoluteImportGlob = createMakeAbsoluteImportGlob(options.userRoot);
1496
1482
  let sourceIds = resolveSourceIds(data);
1497
- function resolveSourceIds(data$1) {
1483
+ function resolveSourceIds(data) {
1498
1484
  const ids = {
1499
1485
  md: [],
1500
1486
  frontmatter: []
1501
1487
  };
1502
- for (const type of ["md", "frontmatter"]) for (let i = 0; i < data$1.slides.length; i++) ids[type].push(`${data$1.slides[i].source.filepath}__slidev_${i + 1}.${type}`);
1488
+ for (const type of ["md", "frontmatter"]) for (let i = 0; i < data.slides.length; i++) ids[type].push(`${data.slides[i].source.filepath}__slidev_${i + 1}.${type}`);
1503
1489
  return ids;
1504
1490
  }
1505
1491
  function updateServerWatcher() {
@@ -1537,7 +1523,7 @@ function createSlidesLoader(options, serverOptions) {
1537
1523
  if (parsed.errors.length) console.error("ERROR when saving frontmatter", parsed.errors);
1538
1524
  else slide.source.frontmatterDoc = parsed;
1539
1525
  }
1540
- if (body.note) slide.note = slide.source.note = body.note;
1526
+ if (body.note != null) slide.note = slide.source.note = body.note;
1541
1527
  if (body.frontmatter) {
1542
1528
  updateFrontmatterPatch(slide.source, body.frontmatter);
1543
1529
  Object.assign(slide.frontmatter, body.frontmatter);
@@ -1625,32 +1611,38 @@ function createSlidesLoader(options, serverOptions) {
1625
1611
  const moduleEntries = [
1626
1612
  ...ctx.modules.filter((i) => i.id === templateMonacoRunDeps.id || i.id === templateMonacoTypes.id),
1627
1613
  ...vueModules,
1628
- ...Array.from(moduleIds).map((id$2) => ctx.server.moduleGraph.getModuleById(id$2))
1614
+ ...Array.from(moduleIds).map((id) => ctx.server.moduleGraph.getModuleById(id))
1629
1615
  ].filter(notNullish).filter((i) => !i.id?.startsWith("/@id/@vite-icons"));
1630
1616
  updateServerWatcher();
1631
1617
  return moduleEntries;
1632
1618
  },
1633
1619
  resolveId: {
1634
1620
  order: "pre",
1635
- handler(id$2) {
1636
- if (id$2.startsWith("/@slidev/") || id$2.includes("__slidev_")) return id$2;
1621
+ handler(id) {
1622
+ if (id.startsWith("/@slidev/") || id.includes("__slidev_")) return id;
1637
1623
  return null;
1638
1624
  }
1639
1625
  },
1640
- async load(id$2) {
1641
- const template = templates.find((i) => i.id === id$2);
1642
- if (template) return {
1643
- code: await template.getContent.call(this, options),
1644
- map: { mappings: "" }
1645
- };
1646
- const matchFacade = id$2.match(regexSlideFacadeId);
1626
+ async load(id) {
1627
+ const template = templates.find((i) => i.id === id);
1628
+ if (template) {
1629
+ const templateContext = {
1630
+ resolve: this.resolve.bind(this),
1631
+ makeAbsoluteImportGlob
1632
+ };
1633
+ return {
1634
+ code: await template.getContent.call(templateContext, options),
1635
+ map: { mappings: "" }
1636
+ };
1637
+ }
1638
+ const matchFacade = id.match(regexSlideFacadeId);
1647
1639
  if (matchFacade) {
1648
1640
  const [, no, type] = matchFacade;
1649
1641
  const idx = +no - 1;
1650
1642
  const sourceId = JSON.stringify(sourceIds[type][idx]);
1651
1643
  return [`export * from ${sourceId}`, `export { default } from ${sourceId}`].join("\n");
1652
1644
  }
1653
- const matchSource = id$2.match(regexSlideSourceId);
1645
+ const matchSource = id.match(regexSlideSourceId);
1654
1646
  if (matchSource) {
1655
1647
  const [, no, type] = matchSource;
1656
1648
  const idx = +no - 1;
@@ -1702,6 +1694,7 @@ function createSlidesLoader(options, serverOptions) {
1702
1694
  ` frontmatter,`,
1703
1695
  ` filepath: ${JSON.stringify(mode === "dev" ? slide.source.filepath : "")},`,
1704
1696
  ` start: ${JSON.stringify(slide.source.start)},`,
1697
+ ` sourceIndex: ${JSON.stringify(slide.source.index)},`,
1705
1698
  ` id: ${idx},`,
1706
1699
  ` no: ${no},`,
1707
1700
  " },",
@@ -1713,7 +1706,7 @@ function createSlidesLoader(options, serverOptions) {
1713
1706
  };
1714
1707
  }
1715
1708
  }
1716
- if (data.markdownFiles[id$2]) return "";
1709
+ if (data.markdownFiles[id]) return "";
1717
1710
  }
1718
1711
  };
1719
1712
  function renderNote(text = "") {
@@ -1734,15 +1727,14 @@ function createSlidesLoader(options, serverOptions) {
1734
1727
  }
1735
1728
  return notesMd.render(md);
1736
1729
  }
1737
- function withRenderedNote(data$1) {
1730
+ function withRenderedNote(data) {
1738
1731
  return {
1739
- ...data$1,
1732
+ ...data,
1740
1733
  ...withoutNotes && { note: "" },
1741
- noteHTML: renderNote(data$1?.note)
1734
+ noteHTML: renderNote(data?.note)
1742
1735
  };
1743
1736
  }
1744
1737
  }
1745
-
1746
1738
  //#endregion
1747
1739
  //#region node/setups/transformers.ts
1748
1740
  async function setupTransformers(roots) {
@@ -1765,26 +1757,24 @@ async function setupTransformers(roots) {
1765
1757
  }
1766
1758
  return result;
1767
1759
  }
1768
-
1769
1760
  //#endregion
1770
- //#region ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=49e14003b6caa0b7d164cbe71da573809d375bab_0dce998d26f79c06311f476731d22630/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/image-size/specialCharacters.js
1761
+ //#region ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=49e14003b6caa0b7d164cbe71da573809d375bab_20f9b6719589445333fe4d166d07e531/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/image-size/specialCharacters.js
1771
1762
  var SpecialCharacters;
1772
- (function(SpecialCharacters$1) {
1773
- SpecialCharacters$1[SpecialCharacters$1["EXCLAMATION_MARK"] = 33] = "EXCLAMATION_MARK";
1774
- SpecialCharacters$1[SpecialCharacters$1["OPENING_BRACKET"] = 91] = "OPENING_BRACKET";
1775
- SpecialCharacters$1[SpecialCharacters$1["OPENING_PARENTHESIS"] = 40] = "OPENING_PARENTHESIS";
1776
- SpecialCharacters$1[SpecialCharacters$1["WHITESPACE"] = 32] = "WHITESPACE";
1777
- SpecialCharacters$1[SpecialCharacters$1["NEW_LINE"] = 10] = "NEW_LINE";
1778
- SpecialCharacters$1[SpecialCharacters$1["EQUALS"] = 61] = "EQUALS";
1779
- SpecialCharacters$1[SpecialCharacters$1["LOWER_CASE_X"] = 120] = "LOWER_CASE_X";
1780
- SpecialCharacters$1[SpecialCharacters$1["NUMBER_ZERO"] = 48] = "NUMBER_ZERO";
1781
- SpecialCharacters$1[SpecialCharacters$1["NUMBER_NINE"] = 57] = "NUMBER_NINE";
1782
- SpecialCharacters$1[SpecialCharacters$1["PERCENTAGE"] = 37] = "PERCENTAGE";
1783
- SpecialCharacters$1[SpecialCharacters$1["CLOSING_PARENTHESIS"] = 41] = "CLOSING_PARENTHESIS";
1763
+ (function(SpecialCharacters) {
1764
+ SpecialCharacters[SpecialCharacters["EXCLAMATION_MARK"] = 33] = "EXCLAMATION_MARK";
1765
+ SpecialCharacters[SpecialCharacters["OPENING_BRACKET"] = 91] = "OPENING_BRACKET";
1766
+ SpecialCharacters[SpecialCharacters["OPENING_PARENTHESIS"] = 40] = "OPENING_PARENTHESIS";
1767
+ SpecialCharacters[SpecialCharacters["WHITESPACE"] = 32] = "WHITESPACE";
1768
+ SpecialCharacters[SpecialCharacters["NEW_LINE"] = 10] = "NEW_LINE";
1769
+ SpecialCharacters[SpecialCharacters["EQUALS"] = 61] = "EQUALS";
1770
+ SpecialCharacters[SpecialCharacters["LOWER_CASE_X"] = 120] = "LOWER_CASE_X";
1771
+ SpecialCharacters[SpecialCharacters["NUMBER_ZERO"] = 48] = "NUMBER_ZERO";
1772
+ SpecialCharacters[SpecialCharacters["NUMBER_NINE"] = 57] = "NUMBER_NINE";
1773
+ SpecialCharacters[SpecialCharacters["PERCENTAGE"] = 37] = "PERCENTAGE";
1774
+ SpecialCharacters[SpecialCharacters["CLOSING_PARENTHESIS"] = 41] = "CLOSING_PARENTHESIS";
1784
1775
  })(SpecialCharacters || (SpecialCharacters = {}));
1785
-
1786
1776
  //#endregion
1787
- //#region ../../node_modules/.pnpm/markdown-it@14.1.1/node_modules/markdown-it/lib/token.mjs
1777
+ //#region ../../node_modules/.pnpm/markdown-it@14.2.0/node_modules/markdown-it/lib/token.mjs
1788
1778
  /**
1789
1779
  * class Token
1790
1780
  **/
@@ -1937,10 +1927,8 @@ Token.prototype.attrJoin = function attrJoin(name, value) {
1937
1927
  if (idx < 0) this.attrPush([name, value]);
1938
1928
  else this.attrs[idx][1] = this.attrs[idx][1] + " " + value;
1939
1929
  };
1940
- var token_default = Token;
1941
-
1942
1930
  //#endregion
1943
- //#region ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=49e14003b6caa0b7d164cbe71da573809d375bab_0dce998d26f79c06311f476731d22630/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/task-lists/index.js
1931
+ //#region ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=49e14003b6caa0b7d164cbe71da573809d375bab_20f9b6719589445333fe4d166d07e531/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/task-lists/index.js
1944
1932
  const checkboxRegex = /^ *\[([\sx])] /i;
1945
1933
  function taskLists(md, options = {
1946
1934
  enabled: false,
@@ -1985,11 +1973,11 @@ function isTodoItem(tokens, index) {
1985
1973
  }
1986
1974
  function todoify(token, options) {
1987
1975
  if (token.children == null) return;
1988
- const id$2 = generateIdForToken(token);
1989
- token.children.splice(0, 0, createCheckboxToken(token, options.enabled, id$2));
1976
+ const id = generateIdForToken(token);
1977
+ token.children.splice(0, 0, createCheckboxToken(token, options.enabled, id));
1990
1978
  token.children[1].content = token.children[1].content.replace(checkboxRegex, "");
1991
1979
  if (options.label) {
1992
- token.children.splice(1, 0, createLabelBeginToken(id$2));
1980
+ token.children.splice(1, 0, createLabelBeginToken(id));
1993
1981
  token.children.push(createLabelEndToken());
1994
1982
  }
1995
1983
  }
@@ -1997,21 +1985,21 @@ function generateIdForToken(token) {
1997
1985
  if (token.map) return `task-item-${token.map[0]}`;
1998
1986
  else return `task-item-${Math.ceil(Math.random() * (1e4 * 1e3) - 1e3)}`;
1999
1987
  }
2000
- function createCheckboxToken(token, enabled, id$2) {
2001
- const checkbox = new token_default("taskListItemCheckbox", "", 0);
1988
+ function createCheckboxToken(token, enabled, id) {
1989
+ const checkbox = new Token("taskListItemCheckbox", "", 0);
2002
1990
  if (!enabled) checkbox.attrSet("disabled", "true");
2003
1991
  if (token.map) checkbox.attrSet("line", token.map[0].toString());
2004
- checkbox.attrSet("id", id$2);
1992
+ checkbox.attrSet("id", id);
2005
1993
  if (checkboxRegex.exec(token.content)?.[1].toLowerCase() === "x") checkbox.attrSet("checked", "true");
2006
1994
  return checkbox;
2007
1995
  }
2008
- function createLabelBeginToken(id$2) {
2009
- const labelBeginToken = new token_default("taskListItemLabel_open", "", 1);
2010
- labelBeginToken.attrSet("id", id$2);
1996
+ function createLabelBeginToken(id) {
1997
+ const labelBeginToken = new Token("taskListItemLabel_open", "", 1);
1998
+ labelBeginToken.attrSet("id", id);
2011
1999
  return labelBeginToken;
2012
2000
  }
2013
2001
  function createLabelEndToken() {
2014
- return new token_default("taskListItemLabel_close", "", -1);
2002
+ return new Token("taskListItemLabel_close", "", -1);
2015
2003
  }
2016
2004
  function isInline(token) {
2017
2005
  return token.type === "inline";
@@ -2025,38 +2013,227 @@ function isListItem(token) {
2025
2013
  function startsWithTodoMarkdown(token) {
2026
2014
  return checkboxRegex.test(token.content);
2027
2015
  }
2028
-
2016
+ //#endregion
2017
+ //#region node/vite/monacoWrite.ts
2018
+ const monacoWriterWhitelist = /* @__PURE__ */ new Set();
2019
+ function createMonacoWriterPlugin({ userRoot }) {
2020
+ return {
2021
+ name: "slidev:monaco-write",
2022
+ apply: "serve",
2023
+ configureServer(server) {
2024
+ server.ws.on("connection", (socket) => {
2025
+ socket.on("message", async (data) => {
2026
+ let json;
2027
+ try {
2028
+ json = JSON.parse(data.toString());
2029
+ } catch {
2030
+ return;
2031
+ }
2032
+ if (json.type === "custom" && json.event === "slidev:monaco-write") {
2033
+ const { file, content } = json.data;
2034
+ if (!monacoWriterWhitelist.has(file)) {
2035
+ console.error(`[Slidev] Unauthorized file write: ${file}`);
2036
+ return;
2037
+ }
2038
+ const filepath = path.join(userRoot, file);
2039
+ console.log("[Slidev] Writing file:", filepath);
2040
+ await fs$1.writeFile(filepath, content, "utf-8");
2041
+ }
2042
+ });
2043
+ });
2044
+ }
2045
+ };
2046
+ }
2047
+ //#endregion
2048
+ //#region node/syntax/snippet.ts
2049
+ const RE_NEWLINE = /\r?\n/;
2050
+ function dedent(text) {
2051
+ const lines = text.split("\n");
2052
+ const minIndentLength = lines.reduce((acc, line) => {
2053
+ for (let i = 0; i < line.length; i++) if (line[i] !== " " && line[i] !== " ") return Math.min(i, acc);
2054
+ return acc;
2055
+ }, Number.POSITIVE_INFINITY);
2056
+ if (minIndentLength < Number.POSITIVE_INFINITY) return lines.map((x) => x.slice(minIndentLength)).join("\n");
2057
+ return text;
2058
+ }
2059
+ const markers = [
2060
+ {
2061
+ start: /^\s*\/\/\s*#?region\b\s*(.*?)\s*$/,
2062
+ end: /^\s*\/\/\s*#?endregion\b\s*(.*?)\s*$/
2063
+ },
2064
+ {
2065
+ start: /^\s*<!--\s*#?region\b\s*(.*?)\s*-->/,
2066
+ end: /^\s*<!--\s*#?endregion\b\s*(.*?)\s*-->/
2067
+ },
2068
+ {
2069
+ start: /^\s*\/\*\s*#region\b\s*(.*?)\s*\*\//,
2070
+ end: /^\s*\/\*\s*#endregion\b\s*(.*?)\s*\*\//
2071
+ },
2072
+ {
2073
+ start: /^\s*#[rR]egion\b\s*(.*?)\s*$/,
2074
+ end: /^\s*#[eE]nd ?[rR]egion\b\s*(.*?)\s*$/
2075
+ },
2076
+ {
2077
+ start: /^\s*#\s*#?region\b\s*(.*?)\s*$/,
2078
+ end: /^\s*#\s*#?endregion\b\s*(.*?)\s*$/
2079
+ },
2080
+ {
2081
+ start: /^\s*(?:--|::|@?REM)\s*#region\b\s*(.*?)\s*$/,
2082
+ end: /^\s*(?:--|::|@?REM)\s*#endregion\b\s*(.*?)\s*$/
2083
+ },
2084
+ {
2085
+ start: /^\s*#pragma\s+region\b\s*(.*?)\s*$/,
2086
+ end: /^\s*#pragma\s+endregion\b\s*(.*?)\s*$/
2087
+ },
2088
+ {
2089
+ start: /^\s*\(\*\s*#region\b\s*(.*?)\s*\*\)/,
2090
+ end: /^\s*\(\*\s*#endregion\b\s*(.*?)\s*\*\)/
2091
+ }
2092
+ ];
2093
+ function findRegion(lines, regionName) {
2094
+ let chosen = null;
2095
+ for (let i = 0; i < lines.length; i++) {
2096
+ for (const re of markers) if (re.start.exec(lines[i])?.[1] === regionName) {
2097
+ chosen = {
2098
+ re,
2099
+ start: i + 1
2100
+ };
2101
+ break;
2102
+ }
2103
+ if (chosen) break;
2104
+ }
2105
+ if (!chosen) return null;
2106
+ let counter = 1;
2107
+ for (let i = chosen.start; i < lines.length; i++) {
2108
+ if (chosen.re.start.exec(lines[i])?.[1] === regionName) {
2109
+ counter++;
2110
+ continue;
2111
+ }
2112
+ const endRegion = chosen.re.end.exec(lines[i])?.[1];
2113
+ if (endRegion === regionName || endRegion === "") {
2114
+ if (--counter === 0) return {
2115
+ ...chosen,
2116
+ end: i
2117
+ };
2118
+ }
2119
+ }
2120
+ return null;
2121
+ }
2122
+ const RE_SNIPPET_IMPORT = /^<<<[ \t]*(\S.*?)(#[\w-]+)?[ \t]*(?:[ \t](\S+?))?[ \t]*(\{.*)?$/;
2123
+ function resolveSnippetImport(lineText, userRoot, slide) {
2124
+ const match = lineText.trimStart().match(RE_SNIPPET_IMPORT);
2125
+ if (!match) return null;
2126
+ let [, filepath = "", regionName = "", lang = "", meta = ""] = match;
2127
+ const dir = path.dirname(slide.source.filepath);
2128
+ const src = slash(filepath.startsWith("@/") ? path.resolve(userRoot, filepath.slice(2)) : path.resolve(dir, filepath));
2129
+ lang = lang.trim() || path.extname(filepath).slice(1);
2130
+ meta = meta.trim();
2131
+ if (!(fs.existsSync(src) && fs.statSync(src).isFile())) throw new Error(`Code snippet path not found: ${src}`);
2132
+ let content = fs.readFileSync(src, "utf8");
2133
+ if (regionName) {
2134
+ const lines = content.split(RE_NEWLINE);
2135
+ const region = findRegion(lines, regionName.slice(1));
2136
+ if (region) content = dedent(lines.slice(region.start, region.end).filter((l) => !(region.re.start.test(l) || region.re.end.test(l))).join("\n"));
2137
+ }
2138
+ return {
2139
+ content,
2140
+ filepath,
2141
+ lang,
2142
+ meta,
2143
+ src
2144
+ };
2145
+ }
2146
+ function MarkdownItSnippet(md, { userRoot, data: { watchFiles, slides } }) {
2147
+ md.block.ruler.before("fence", "snippet_import", (state, startLine, _endLine, silent) => {
2148
+ const pos = state.bMarks[startLine] + state.tShift[startLine];
2149
+ const max = state.eMarks[startLine];
2150
+ const lineText = state.src.slice(pos, max);
2151
+ if (!lineText.match(RE_SNIPPET_IMPORT)) return false;
2152
+ if (silent) return true;
2153
+ const slideNo = state.env.id?.match(regexSlideSourceId);
2154
+ const slide = slideNo ? slides[slideNo[1] - 1] : null;
2155
+ if (!slide) {
2156
+ console.warn(yellow(`[markdown-it-snippet] Snippet syntax is not supported in ${state.env.id || "unknown source"}. Skipped.`));
2157
+ return false;
2158
+ }
2159
+ const snippet = resolveSnippetImport(lineText, userRoot, slide);
2160
+ if (!snippet) return false;
2161
+ const { content, filepath, src } = snippet;
2162
+ let { lang, meta } = snippet;
2163
+ if (meta.includes("{monaco-write}")) {
2164
+ monacoWriterWhitelist.add(filepath);
2165
+ lang = lang.trim();
2166
+ meta = meta.replace("{monaco-write}", "").trim() || "{}";
2167
+ const safeFilepath = JSON.stringify(filepath).slice(1, -1);
2168
+ const encoded = lz.compressToBase64(content);
2169
+ const token = state.push("html_block", "", 0);
2170
+ token.content = `<Monaco writable="${safeFilepath}" code-lz="${encoded}" lang="${lang}" v-bind="${meta}" />\n`;
2171
+ token.map = [startLine, startLine + 1];
2172
+ } else {
2173
+ watchFiles[src] ??= /* @__PURE__ */ new Set();
2174
+ watchFiles[src].add(slide.index);
2175
+ const token = state.push("fence", "code", 0);
2176
+ token.info = `${lang} ${meta}`.trim();
2177
+ token.content = content.endsWith("\n") ? content : `${content}\n`;
2178
+ token.map = [startLine, startLine + 1];
2179
+ }
2180
+ state.line = startLine + 1;
2181
+ return true;
2182
+ }, { alt: [
2183
+ "paragraph",
2184
+ "reference",
2185
+ "blockquote",
2186
+ "list"
2187
+ ] });
2188
+ }
2029
2189
  //#endregion
2030
2190
  //#region node/syntax/codeblock/magic-move.ts
2031
2191
  const RE_MAGIC_MOVE_INFO = /^(?:md|markdown) magic-move\s*(?:\[([^\]]*)\])?\s*(\{[^}]*\})?/;
2032
2192
  const RE_CODE_BLOCK = /^```([\w'-]+)?(?:[ \t]*|[ \t][ \w\t'-]*)(?:\[([^\]]*)\])?[ \t]*(?:\{([\w*,|-]+)\}[ \t]*(\{[^}]*\})?([^\r\n]*))?\r?\n((?:(?!^```)[\s\S])*?)^```$/gm;
2193
+ const RE_INNER_CODE_FENCE = /^```/;
2033
2194
  const RE_LINES_TRUE = /\blines: *true\b/;
2034
2195
  const RE_LINES_FALSE = /\blines: *false\b/;
2035
2196
  function parseLineNumbersOption(options) {
2036
2197
  return RE_LINES_TRUE.test(options) ? true : RE_LINES_FALSE.test(options) ? false : void 0;
2037
2198
  }
2038
- var magic_move_default = defineCodeblockTransformer(async ({ info, fence, code, options: { data: { config }, utils: { shikiOptions, shiki } } }) => {
2199
+ function resolveMagicMoveSnippetImports(code, userRoot, slide, watchFiles) {
2200
+ let inCodeBlock = false;
2201
+ return code.split(/\r?\n/).map((line) => {
2202
+ if (RE_INNER_CODE_FENCE.test(line)) {
2203
+ inCodeBlock = !inCodeBlock;
2204
+ return line;
2205
+ }
2206
+ if (inCodeBlock) return line;
2207
+ const snippet = resolveSnippetImport(line, userRoot, slide);
2208
+ if (!snippet) return line;
2209
+ watchFiles[snippet.src] ??= /* @__PURE__ */ new Set();
2210
+ watchFiles[snippet.src].add(slide.index);
2211
+ return `\`\`\`${`${snippet.lang} ${snippet.meta}`.trim()}\n${snippet.content.endsWith("\n") ? snippet.content : `${snippet.content}\n`}\`\`\``;
2212
+ }).join("\n");
2213
+ }
2214
+ var magic_move_default = defineCodeblockTransformer(async ({ info, fence, code, slide, options: { userRoot, data: { config, watchFiles }, utils: { shikiOptions, shiki } } }) => {
2039
2215
  if (fence !== 4) return;
2040
2216
  const match = info.match(RE_MAGIC_MOVE_INFO);
2041
2217
  if (!match) return;
2042
2218
  const [, title = "", options = "{}"] = match;
2043
2219
  const defaultLineNumbers = parseLineNumbersOption(options) ?? config.lineNumbers;
2044
- const matches = Array.from(code.matchAll(RE_CODE_BLOCK));
2220
+ const resolvedCode = slide ? resolveMagicMoveSnippetImports(code, userRoot, slide, watchFiles) : code;
2221
+ const matches = Array.from(resolvedCode.matchAll(RE_CODE_BLOCK));
2045
2222
  if (!matches.length) throw new Error("Magic Move block must contain at least one code block");
2046
2223
  const ranges = matches.map((i) => normalizeRangeStr(i[3]));
2047
2224
  const steps = await Promise.all(matches.map(async (i) => {
2048
2225
  const lang = i[1];
2049
2226
  const lineNumbers = parseLineNumbersOption(i[4]) ?? defaultLineNumbers;
2050
- const code$1 = i[6].trimEnd();
2051
- const options$1 = {
2227
+ const code = i[6].trimEnd();
2228
+ const options = {
2052
2229
  ...shikiOptions,
2053
2230
  lang
2054
2231
  };
2055
- const { tokens, bg, fg: fg$1, rootStyle, themeName } = await shiki.codeToTokens(code$1, options$1);
2232
+ const { tokens, bg, fg, rootStyle, themeName } = await shiki.codeToTokens(code, options);
2056
2233
  return {
2057
- ...toKeyedTokens(code$1, tokens, JSON.stringify([lang, "themes" in options$1 ? options$1.themes : options$1.theme]), lineNumbers),
2234
+ ...toKeyedTokens(code, tokens, JSON.stringify([lang, "themes" in options ? options.themes : options.theme]), lineNumbers),
2058
2235
  bg,
2059
- fg: fg$1,
2236
+ fg,
2060
2237
  rootStyle,
2061
2238
  themeName,
2062
2239
  lang
@@ -2064,7 +2241,6 @@ var magic_move_default = defineCodeblockTransformer(async ({ info, fence, code,
2064
2241
  }));
2065
2242
  return `<ShikiMagicMove v-bind="${options}" steps-lz="${lz.compressToBase64(JSON.stringify(steps))}" :title='${JSON.stringify(title)}' :step-ranges='${JSON.stringify(ranges)}' />`;
2066
2243
  });
2067
-
2068
2244
  //#endregion
2069
2245
  //#region node/syntax/codeblock/mermaid.ts
2070
2246
  const RE_MERMAID = /^mermaid\s*(\{[^\n]*\})?/;
@@ -2074,7 +2250,6 @@ var mermaid_default = defineCodeblockTransformer(async ({ info, code }) => {
2074
2250
  const [, options] = match;
2075
2251
  return `<Mermaid ${options ? `v-bind="${options}"` : ""} code-lz="${lz.compressToBase64(code.trim())}" />`;
2076
2252
  });
2077
-
2078
2253
  //#endregion
2079
2254
  //#region node/syntax/codeblock/monaco.ts
2080
2255
  const RE_MONACO = /^([\w'-]+)?\s*\{(monaco[\w-]*)\}\s*(\{[^}]*\})?(.*)$/;
@@ -2093,7 +2268,6 @@ var monaco_default = defineCodeblockTransformer(async ({ info, code, options: {
2093
2268
  } else encoded = lz.compressToBase64(code);
2094
2269
  return `<Monaco ${options ? `v-bind="${options}"` : ""} ${monaco === "monaco-run" ? "runnable" : ""} lang="${lang}" code-lz="${encoded}" ${diff} />`;
2095
2270
  });
2096
-
2097
2271
  //#endregion
2098
2272
  //#region node/syntax/codeblock/plant-uml.ts
2099
2273
  const RE_PLANT_UML = /^plantuml\s*(\{[^\n]*\})?/;
@@ -2103,7 +2277,6 @@ var plant_uml_default = defineCodeblockTransformer(async ({ info, code, options:
2103
2277
  const [, options] = match;
2104
2278
  return `<PlantUml ${options ? `v-bind="${options}"` : ""} code="${encode(code.trim())}"${plantUmlServer === void 0 ? "" : ` server=${JSON.stringify(plantUmlServer)}`} />`;
2105
2279
  });
2106
-
2107
2280
  //#endregion
2108
2281
  //#region node/syntax/codeblock/wrapper.ts
2109
2282
  const RE_BLOCK_INFO = /^([\w'-]+)?(?:[ \t]*|[ \t][ \w\t'-]*)(?:\[([^\]]*)\])?[ \t]*(?:\{([\w,|\-*]+)\})?[ \t]*(\{[^}]*\})?(.*)$/;
@@ -2114,7 +2287,6 @@ var wrapper_default = defineCodeblockTransformer(async ({ info, renderHighlighte
2114
2287
  const code = await renderHighlighted({ info: `${lang} ${rest}` });
2115
2288
  return `<CodeBlockWrapper ${optionsProp} title=${JSON.stringify(title)} :ranges='${JSON.stringify(ranges)}'>${escapeVueInCode(code)}</CodeBlockWrapper>`;
2116
2289
  });
2117
-
2118
2290
  //#endregion
2119
2291
  //#region node/syntax/codeblock/index.ts
2120
2292
  function MarkdownItCodeblocks(md, options, extraTransformers) {
@@ -2150,7 +2322,6 @@ function MarkdownItCodeblocks(md, options, extraTransformers) {
2150
2322
  throw new Error("Should not reach here");
2151
2323
  };
2152
2324
  }
2153
-
2154
2325
  //#endregion
2155
2326
  //#region node/syntax/drag.ts
2156
2327
  const dragComponentRegex = /<(v-?drag-?\w*)([\s>])/i;
@@ -2158,8 +2329,8 @@ const dragDirectiveRegex = /(?<![</\w])v-drag(=".*?")?/i;
2158
2329
  function MarkdownItVDrag(md, markdownTransformMap) {
2159
2330
  const visited = /* @__PURE__ */ new WeakSet();
2160
2331
  const sourceMapConsumers = /* @__PURE__ */ new WeakMap();
2161
- function getSourceMapConsumer(id$2) {
2162
- const s = id$2 && markdownTransformMap.get(id$2);
2332
+ function getSourceMapConsumer(id) {
2333
+ const s = id && markdownTransformMap.get(id);
2163
2334
  if (!s) return void 0;
2164
2335
  let smc = sourceMapConsumers.get(s);
2165
2336
  if (smc) return smc;
@@ -2209,7 +2380,6 @@ function MarkdownItVDrag(md, markdownTransformMap) {
2209
2380
  });
2210
2381
  };
2211
2382
  }
2212
-
2213
2383
  //#endregion
2214
2384
  //#region node/syntax/escape-code.ts
2215
2385
  const RE_CODE_TAG_OPEN = /^<code/;
@@ -2219,7 +2389,6 @@ function MarkdownItEscapeInlineCode(md) {
2219
2389
  return (await codeInline(tokens, idx, options, env, self)).replace(RE_CODE_TAG_OPEN, "<code v-pre");
2220
2390
  };
2221
2391
  }
2222
-
2223
2392
  //#endregion
2224
2393
  //#region node/syntax/scoped.ts
2225
2394
  const RE_STYLE_TAG_OPEN = /<style\b([^>]*)>/gi;
@@ -2236,7 +2405,6 @@ function MarkdownItStyleScoped(md) {
2236
2405
  const htmlInline = md.renderer.rules.html_inline;
2237
2406
  md.renderer.rules.html_inline = async (...args) => addScoped(await htmlInline(...args));
2238
2407
  }
2239
-
2240
2408
  //#endregion
2241
2409
  //#region node/syntax/shiki.ts
2242
2410
  async function MarkdownItShiki({ data: { config }, mode, utils: { shiki, shikiOptions } }) {
@@ -2254,7 +2422,10 @@ async function MarkdownItShiki({ data: { config }, mode, utils: { shiki, shikiOp
2254
2422
  ]);
2255
2423
  return transformerTwoslash({
2256
2424
  explicitTrigger: true,
2257
- twoslashOptions: { handbookOptions: { noErrorValidation: true } }
2425
+ twoslashOptions: {
2426
+ compilerOptions: { ignoreDeprecations: "6.0" },
2427
+ handbookOptions: { noErrorValidation: true }
2428
+ }
2258
2429
  });
2259
2430
  }
2260
2431
  const transformers = [
@@ -2281,7 +2452,6 @@ function transformerTwoslashConditional() {
2281
2452
  }
2282
2453
  };
2283
2454
  }
2284
-
2285
2455
  //#endregion
2286
2456
  //#region node/syntax/slot-sugar.ts
2287
2457
  const RE_SLOT_MARKER = /^::\s*([\w.\-:]+)\s*::\s*$/;
@@ -2332,167 +2502,6 @@ function MarkdownItSlotSugar(md) {
2332
2502
  state.tokens = newTokens;
2333
2503
  });
2334
2504
  }
2335
-
2336
- //#endregion
2337
- //#region node/vite/monacoWrite.ts
2338
- const monacoWriterWhitelist = /* @__PURE__ */ new Set();
2339
- function createMonacoWriterPlugin({ userRoot }) {
2340
- return {
2341
- name: "slidev:monaco-write",
2342
- apply: "serve",
2343
- configureServer(server) {
2344
- server.ws.on("connection", (socket) => {
2345
- socket.on("message", async (data) => {
2346
- let json;
2347
- try {
2348
- json = JSON.parse(data.toString());
2349
- } catch {
2350
- return;
2351
- }
2352
- if (json.type === "custom" && json.event === "slidev:monaco-write") {
2353
- const { file, content } = json.data;
2354
- if (!monacoWriterWhitelist.has(file)) {
2355
- console.error(`[Slidev] Unauthorized file write: ${file}`);
2356
- return;
2357
- }
2358
- const filepath = path.join(userRoot, file);
2359
- console.log("[Slidev] Writing file:", filepath);
2360
- await fs$1.writeFile(filepath, content, "utf-8");
2361
- }
2362
- });
2363
- });
2364
- }
2365
- };
2366
- }
2367
-
2368
- //#endregion
2369
- //#region node/syntax/snippet.ts
2370
- const RE_NEWLINE = /\r?\n/;
2371
- function dedent(text) {
2372
- const lines = text.split("\n");
2373
- const minIndentLength = lines.reduce((acc, line) => {
2374
- for (let i = 0; i < line.length; i++) if (line[i] !== " " && line[i] !== " ") return Math.min(i, acc);
2375
- return acc;
2376
- }, Number.POSITIVE_INFINITY);
2377
- if (minIndentLength < Number.POSITIVE_INFINITY) return lines.map((x) => x.slice(minIndentLength)).join("\n");
2378
- return text;
2379
- }
2380
- const markers = [
2381
- {
2382
- start: /^\s*\/\/\s*#?region\b\s*(.*?)\s*$/,
2383
- end: /^\s*\/\/\s*#?endregion\b\s*(.*?)\s*$/
2384
- },
2385
- {
2386
- start: /^\s*<!--\s*#?region\b\s*(.*?)\s*-->/,
2387
- end: /^\s*<!--\s*#?endregion\b\s*(.*?)\s*-->/
2388
- },
2389
- {
2390
- start: /^\s*\/\*\s*#region\b\s*(.*?)\s*\*\//,
2391
- end: /^\s*\/\*\s*#endregion\b\s*(.*?)\s*\*\//
2392
- },
2393
- {
2394
- start: /^\s*#[rR]egion\b\s*(.*?)\s*$/,
2395
- end: /^\s*#[eE]nd ?[rR]egion\b\s*(.*?)\s*$/
2396
- },
2397
- {
2398
- start: /^\s*#\s*#?region\b\s*(.*?)\s*$/,
2399
- end: /^\s*#\s*#?endregion\b\s*(.*?)\s*$/
2400
- },
2401
- {
2402
- start: /^\s*(?:--|::|@?REM)\s*#region\b\s*(.*?)\s*$/,
2403
- end: /^\s*(?:--|::|@?REM)\s*#endregion\b\s*(.*?)\s*$/
2404
- },
2405
- {
2406
- start: /^\s*#pragma\s+region\b\s*(.*?)\s*$/,
2407
- end: /^\s*#pragma\s+endregion\b\s*(.*?)\s*$/
2408
- },
2409
- {
2410
- start: /^\s*\(\*\s*#region\b\s*(.*?)\s*\*\)/,
2411
- end: /^\s*\(\*\s*#endregion\b\s*(.*?)\s*\*\)/
2412
- }
2413
- ];
2414
- function findRegion(lines, regionName) {
2415
- let chosen = null;
2416
- for (let i = 0; i < lines.length; i++) {
2417
- for (const re of markers) if (re.start.exec(lines[i])?.[1] === regionName) {
2418
- chosen = {
2419
- re,
2420
- start: i + 1
2421
- };
2422
- break;
2423
- }
2424
- if (chosen) break;
2425
- }
2426
- if (!chosen) return null;
2427
- let counter = 1;
2428
- for (let i = chosen.start; i < lines.length; i++) {
2429
- if (chosen.re.start.exec(lines[i])?.[1] === regionName) {
2430
- counter++;
2431
- continue;
2432
- }
2433
- const endRegion = chosen.re.end.exec(lines[i])?.[1];
2434
- if (endRegion === regionName || endRegion === "") {
2435
- if (--counter === 0) return {
2436
- ...chosen,
2437
- end: i
2438
- };
2439
- }
2440
- }
2441
- return null;
2442
- }
2443
- const RE_SNIPPET_IMPORT = /^<<<[ \t]*(\S.*?)(#[\w-]+)?[ \t]*(?:[ \t](\S+?))?[ \t]*(\{.*)?$/;
2444
- function MarkdownItSnippet(md, { userRoot, data: { watchFiles, slides } }) {
2445
- md.block.ruler.before("fence", "snippet_import", (state, startLine, _endLine, silent) => {
2446
- const pos = state.bMarks[startLine] + state.tShift[startLine];
2447
- const max = state.eMarks[startLine];
2448
- const match = state.src.slice(pos, max).match(RE_SNIPPET_IMPORT);
2449
- if (!match) return false;
2450
- if (silent) return true;
2451
- let [, filepath = "", regionName = "", lang = "", meta = ""] = match;
2452
- const slideNo = state.env.id?.match(regexSlideSourceId);
2453
- const slide = slideNo ? slides[slideNo[1] - 1] : null;
2454
- if (!slide) {
2455
- console.warn(yellow(`[markdown-it-snippet] Snippet syntax is not supported in ${state.env.id || "unknown source"}. Skipped.`));
2456
- return false;
2457
- }
2458
- const dir = path.dirname(slide.source.filepath);
2459
- const src = slash(filepath.startsWith("@/") ? path.resolve(userRoot, filepath.slice(2)) : path.resolve(dir, filepath));
2460
- lang = lang.trim() || path.extname(filepath).slice(1);
2461
- meta = meta.trim();
2462
- if (!(fs.existsSync(src) && fs.statSync(src).isFile())) throw new Error(`Code snippet path not found: ${src}`);
2463
- let content = fs.readFileSync(src, "utf8");
2464
- if (regionName) {
2465
- const lines = content.split(RE_NEWLINE);
2466
- const region = findRegion(lines, regionName.slice(1));
2467
- if (region) content = dedent(lines.slice(region.start, region.end).filter((l) => !(region.re.start.test(l) || region.re.end.test(l))).join("\n"));
2468
- }
2469
- if (meta.includes("{monaco-write}")) {
2470
- monacoWriterWhitelist.add(filepath);
2471
- lang = lang.trim();
2472
- meta = meta.replace("{monaco-write}", "").trim() || "{}";
2473
- const safeFilepath = JSON.stringify(filepath).slice(1, -1);
2474
- const encoded = lz.compressToBase64(content);
2475
- const token = state.push("html_block", "", 0);
2476
- token.content = `<Monaco writable="${safeFilepath}" code-lz="${encoded}" lang="${lang}" v-bind="${meta}" />\n`;
2477
- token.map = [startLine, startLine + 1];
2478
- } else {
2479
- watchFiles[src] ??= /* @__PURE__ */ new Set();
2480
- watchFiles[src].add(slide.index);
2481
- const token = state.push("fence", "code", 0);
2482
- token.info = `${lang} ${meta}`.trim();
2483
- token.content = content.endsWith("\n") ? content : `${content}\n`;
2484
- token.map = [startLine, startLine + 1];
2485
- }
2486
- state.line = startLine + 1;
2487
- return true;
2488
- }, { alt: [
2489
- "paragraph",
2490
- "reference",
2491
- "blockquote",
2492
- "list"
2493
- ] });
2494
- }
2495
-
2496
2505
  //#endregion
2497
2506
  //#region node/syntax/index.ts
2498
2507
  async function useMarkdownItPlugins(md, options, markdownTransformMap, codeblockTransformers) {
@@ -2515,7 +2524,6 @@ async function useMarkdownItPlugins(md, options, markdownTransformMap, codeblock
2515
2524
  md.use(MarkdownItStyleScoped);
2516
2525
  md.use(MarkdownItGitHubAlerts);
2517
2526
  }
2518
-
2519
2527
  //#endregion
2520
2528
  //#region node/vite/markdown.ts
2521
2529
  const RE_MD_EXT$1 = /\.md$/;
@@ -2548,13 +2556,13 @@ async function createMarkdownPlugin(options, { markdown: mdOptions }) {
2548
2556
  },
2549
2557
  transforms: {
2550
2558
  ...mdOptions?.transforms,
2551
- async before(code, id$2) {
2552
- if (options.data.markdownFiles[id$2]) return "";
2553
- code = await mdOptions?.transforms?.before?.(code, id$2) ?? code;
2554
- const match = id$2.match(regexSlideSourceId);
2559
+ async before(code, id) {
2560
+ if (options.data.markdownFiles[id]) return "";
2561
+ code = await mdOptions?.transforms?.before?.(code, id) ?? code;
2562
+ const match = id.match(regexSlideSourceId);
2555
2563
  if (!match) return code;
2556
2564
  const s = new MagicString(code);
2557
- markdownTransformMap.set(id$2, s);
2565
+ markdownTransformMap.set(id, s);
2558
2566
  const ctx = {
2559
2567
  s,
2560
2568
  slide: options.data.slides[+match[1] - 1],
@@ -2570,19 +2578,18 @@ async function createMarkdownPlugin(options, { markdown: mdOptions }) {
2570
2578
  }
2571
2579
  });
2572
2580
  }
2573
-
2574
2581
  //#endregion
2575
2582
  //#region node/vite/monacoTypes.ts
2576
2583
  function createMonacoTypesLoader({ userRoot, utils }) {
2577
2584
  return {
2578
2585
  name: "slidev:monaco-types-loader",
2579
- resolveId(id$2) {
2580
- if (id$2.startsWith("/@slidev-monaco-types/")) return id$2;
2586
+ resolveId(id) {
2587
+ if (id.startsWith("/@slidev-monaco-types/")) return id;
2581
2588
  return null;
2582
2589
  },
2583
- async load(id$2) {
2584
- if (!id$2.startsWith("/@slidev-monaco-types/")) return null;
2585
- const url = new URL(id$2, "http://localhost");
2590
+ async load(id) {
2591
+ if (!id.startsWith("/@slidev-monaco-types/")) return null;
2592
+ const url = new URL(id, "http://localhost");
2586
2593
  if (url.pathname === "/@slidev-monaco-types/resolve") {
2587
2594
  const query = new URLSearchParams(url.search);
2588
2595
  const pkg = query.get("pkg");
@@ -2592,7 +2599,7 @@ function createMonacoTypesLoader({ userRoot, utils }) {
2592
2599
  const root = slash(dirname(pkgJsonPath));
2593
2600
  const pkgJson = JSON.parse(await fs$1.readFile(pkgJsonPath, "utf-8"));
2594
2601
  let deps = Object.keys(pkgJson.dependencies ?? {});
2595
- deps = deps.filter((pkg$1) => !utils.isMonacoTypesIgnored(pkg$1));
2602
+ deps = deps.filter((pkg) => !utils.isMonacoTypesIgnored(pkg));
2596
2603
  return [`import "/@slidev-monaco-types/load?${new URLSearchParams({
2597
2604
  root,
2598
2605
  name: pkgJson.name
@@ -2621,7 +2628,6 @@ function createMonacoTypesLoader({ userRoot, utils }) {
2621
2628
  }
2622
2629
  };
2623
2630
  }
2624
-
2625
2631
  //#endregion
2626
2632
  //#region node/vite/patchMonacoSourceMap.ts
2627
2633
  const postfixRE = /[?#].*$/;
@@ -2635,20 +2641,19 @@ function createPatchMonacoSourceMapPlugin() {
2635
2641
  return {
2636
2642
  name: "slidev:patch-monaco-sourcemap",
2637
2643
  enforce: "pre",
2638
- load(id$2) {
2639
- if (!id$2.includes("node_modules/monaco-editor/esm/vs/base")) return;
2640
- return readFile(cleanUrl(id$2), "utf-8");
2644
+ load(id) {
2645
+ if (!id.includes("node_modules/monaco-editor/esm/vs/base")) return;
2646
+ return readFile(cleanUrl(id), "utf-8");
2641
2647
  }
2642
2648
  };
2643
2649
  }
2644
-
2645
2650
  //#endregion
2646
2651
  //#region node/vite/remoteAssets.ts
2647
2652
  async function createRemoteAssetsPlugin({ data: { config }, mode }, pluginOptions) {
2648
2653
  if (!(config.remoteAssets === true || config.remoteAssets === mode)) return;
2649
2654
  const { VitePluginRemoteAssets, DefaultRules } = await import("vite-plugin-remote-assets");
2650
2655
  return VitePluginRemoteAssets({
2651
- resolveMode: (id$2) => id$2.endsWith("index.html") ? "relative" : "@fs",
2656
+ resolveMode: (id) => id.endsWith("index.html") ? "relative" : "@fs",
2652
2657
  awaitDownload: mode === "build",
2653
2658
  ...pluginOptions.remoteAssets,
2654
2659
  rules: [
@@ -2661,7 +2666,6 @@ async function createRemoteAssetsPlugin({ data: { config }, mode }, pluginOption
2661
2666
  ]
2662
2667
  });
2663
2668
  }
2664
-
2665
2669
  //#endregion
2666
2670
  //#region node/integrations/drawings.ts
2667
2671
  function resolveDrawingsDir(options) {
@@ -2677,10 +2681,10 @@ async function loadDrawings(options) {
2677
2681
  suppressErrors: true
2678
2682
  });
2679
2683
  const obj = {};
2680
- await Promise.all(files.map(async (path$1) => {
2681
- const num = +basename(path$1, ".svg");
2684
+ await Promise.all(files.map(async (path) => {
2685
+ const num = +basename(path, ".svg");
2682
2686
  if (Number.isNaN(num)) return;
2683
- const lines = (await fs$1.readFile(path$1, "utf8")).split(/\n/g);
2687
+ const lines = (await fs$1.readFile(path, "utf8")).split(/\n/g);
2684
2688
  obj[num.toString()] = lines.slice(1, -1).join("\n");
2685
2689
  }));
2686
2690
  return obj;
@@ -2697,7 +2701,6 @@ async function writeDrawings(options, drawing) {
2697
2701
  await fs$1.writeFile(join(dir, `${key}.svg`), svg, "utf-8");
2698
2702
  }));
2699
2703
  }
2700
-
2701
2704
  //#endregion
2702
2705
  //#region node/integrations/snapshots.ts
2703
2706
  function resolveSnapshotsDir(options) {
@@ -2715,7 +2718,6 @@ async function writeSnapshots(options, data) {
2715
2718
  await fs$1.mkdir(dir, { recursive: true });
2716
2719
  await fs$1.writeFile(join(dir, "snapshots.json"), JSON.stringify(data, null, 2), "utf-8");
2717
2720
  }
2718
-
2719
2721
  //#endregion
2720
2722
  //#region node/vite/serverRef.ts
2721
2723
  async function createServerRefPlugin(options, pluginOptions) {
@@ -2744,7 +2746,6 @@ async function createServerRefPlugin(options, pluginOptions) {
2744
2746
  }
2745
2747
  });
2746
2748
  }
2747
-
2748
2749
  //#endregion
2749
2750
  //#region node/vite/staticCopy.ts
2750
2751
  async function createStaticCopyPlugin({ themeRoots, addonRoots }, pluginOptions) {
@@ -2760,7 +2761,6 @@ async function createStaticCopyPlugin({ themeRoots, addonRoots }, pluginOptions)
2760
2761
  ...pluginOptions.staticCopy
2761
2762
  });
2762
2763
  }
2763
-
2764
2764
  //#endregion
2765
2765
  //#region node/setups/unocss.ts
2766
2766
  async function setupUnocss({ clientRoot, roots, data, utils }) {
@@ -2789,7 +2789,6 @@ async function setupUnocss({ clientRoot, roots, data, utils }) {
2789
2789
  config.theme.fontFamily.serif ||= data.config.fonts.serif.join(",");
2790
2790
  return config;
2791
2791
  }
2792
-
2793
2792
  //#endregion
2794
2793
  //#region node/vite/unocss.ts
2795
2794
  async function createUnocssPlugin(options, pluginOptions) {
@@ -2799,7 +2798,6 @@ async function createUnocssPlugin(options, pluginOptions) {
2799
2798
  ...pluginOptions.unocss
2800
2799
  });
2801
2800
  }
2802
-
2803
2801
  //#endregion
2804
2802
  //#region node/vite/vue.ts
2805
2803
  const RE_VUE_EXT = /\.vue$/;
@@ -2860,7 +2858,6 @@ async function createVuePlugin(_options, pluginOptions) {
2860
2858
  });
2861
2859
  return [VueJsx(vuejsxOptions), VuePlugin];
2862
2860
  }
2863
-
2864
2861
  //#endregion
2865
2862
  //#region node/vite/index.ts
2866
2863
  function ViteSlidevPlugin(options, pluginOptions = {}, serverOptions = {}) {
@@ -2887,7 +2884,6 @@ function ViteSlidevPlugin(options, pluginOptions = {}, serverOptions = {}) {
2887
2884
  setupVitePlugins(options)
2888
2885
  ]);
2889
2886
  }
2890
-
2891
2887
  //#endregion
2892
2888
  //#region node/commands/shared.ts
2893
2889
  const sharedMd = MarkdownExit({ html: true });
@@ -2917,6 +2913,11 @@ async function resolveViteConfigs(options, baseConfig, overrideConfigs, command,
2917
2913
  });
2918
2914
  return baseConfig;
2919
2915
  }
2920
-
2921
2916
  //#endregion
2922
- export { parser as a, resolveAddons as c, updateFrontmatterPatch as d, resolveOptions as i, version as l, ViteSlidevPlugin as n, getThemeMeta as o, createDataUtils as r, resolveTheme as s, resolveViteConfigs as t, loadSetups as u };
2917
+ //#region node/commands/serve.ts
2918
+ async function createServer$1(options, viteConfig = {}, serverOptions) {
2919
+ process.env.EDITOR = process.env.EDITOR || "code";
2920
+ return await createServer(await resolveViteConfigs(options, { optimizeDeps: { entries: [join(options.clientRoot, "main.ts")] } }, viteConfig, "serve", serverOptions));
2921
+ }
2922
+ //#endregion
2923
+ export { resolveOptions as a, resolveTheme as c, updateFrontmatterPatch as d, createDataUtils as i, version as l, resolveViteConfigs as n, parser as o, ViteSlidevPlugin as r, getThemeMeta as s, createServer$1 as t, loadSetups as u };