@slidev/cli 0.48.0-beta.2 → 0.48.0-beta.21

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,29 +1,40 @@
1
1
  import {
2
2
  loadSetups
3
- } from "./chunk-CTBVOVLQ.mjs";
3
+ } from "./chunk-O6TYYGU6.mjs";
4
4
  import {
5
- generateGoogleFontsUrl,
6
- resolveGlobalImportPath,
7
5
  resolveImportPath,
8
- stringifyMarkdownTokens,
9
6
  toAtFS
10
- } from "./chunk-DWXI5WEO.mjs";
7
+ } from "./chunk-CV7OWJOF.mjs";
8
+
9
+ // package.json
10
+ var version = "0.48.0-beta.21";
11
11
 
12
12
  // node/common.ts
13
13
  import { existsSync, promises as fs } from "node:fs";
14
14
  import { join } from "node:path";
15
- import { uniq } from "@antfu/utils";
16
15
  import { loadConfigFromFile, mergeConfig, resolveConfig } from "vite";
17
- async function getIndexHtml({ clientRoot, themeRoots, addonRoots, data, userRoot }) {
16
+
17
+ // node/utils.ts
18
+ import { satisfies } from "semver";
19
+ function stringifyMarkdownTokens(tokens) {
20
+ return tokens.map((token) => token.children?.filter((t) => ["text", "code_inline"].includes(t.type) && !t.content.match(/^\s*$/)).map((t) => t.content.trim()).join(" ")).filter(Boolean).join(" ");
21
+ }
22
+ function generateGoogleFontsUrl(options) {
23
+ const weights = options.weights.flatMap((i) => options.italic ? [`0,${i}`, `1,${i}`] : [`${i}`]).sort().join(";");
24
+ const fonts = options.webfonts.map((i) => `family=${i.replace(/^(['"])(.*)\1$/, "$1").replace(/\s+/g, "+")}:${options.italic ? "ital," : ""}wght@${weights}`).join("&");
25
+ return `https://fonts.googleapis.com/css2?${fonts}&display=swap`;
26
+ }
27
+ function checkEngine(name, engines = {}) {
28
+ if (engines.slidev && !satisfies(version, engines.slidev, { includePrerelease: true }))
29
+ throw new Error(`[slidev] addon "${name}" requires Slidev version range "${engines.slidev}" but found "${version}"`);
30
+ }
31
+
32
+ // node/common.ts
33
+ async function getIndexHtml({ clientRoot, roots, data }) {
18
34
  let main = await fs.readFile(join(clientRoot, "index.html"), "utf-8");
19
35
  let head = "";
20
36
  let body = "";
21
37
  head += `<link rel="icon" href="${data.config.favicon}">`;
22
- const roots = uniq([
23
- ...themeRoots,
24
- ...addonRoots,
25
- userRoot
26
- ]);
27
38
  for (const root of roots) {
28
39
  const path2 = join(root, "index.html");
29
40
  if (!existsSync(path2))
@@ -42,15 +53,12 @@ ${(index.match(/<body>([\s\S]*?)<\/body>/im)?.[1] || "").trim()}`;
42
53
  main = main.replace("__ENTRY__", toAtFS(join(clientRoot, "main.ts"))).replace("<!-- head -->", head).replace("<!-- body -->", body);
43
54
  return main;
44
55
  }
45
- async function mergeViteConfigs({ addonRoots, themeRoots, entry }, viteConfig, config, command) {
56
+ async function mergeViteConfigs({ roots, entry }, viteConfig, config, command) {
46
57
  const configEnv = {
47
58
  mode: "development",
48
59
  command
49
60
  };
50
- const files = uniq([
51
- ...themeRoots,
52
- ...addonRoots
53
- ]).map((i) => join(i, "vite.config.ts"));
61
+ const files = roots.map((i) => join(i, "vite.config.ts"));
54
62
  for await (const file of files) {
55
63
  if (!existsSync(file))
56
64
  continue;
@@ -66,9 +74,9 @@ async function mergeViteConfigs({ addonRoots, themeRoots, entry }, viteConfig, c
66
74
  }
67
75
 
68
76
  // node/plugins/preset.ts
69
- import { join as join8 } from "node:path";
77
+ import { join as join6 } from "node:path";
70
78
  import { existsSync as existsSync3 } from "node:fs";
71
- import process2 from "node:process";
79
+ import process from "node:process";
72
80
  import { fileURLToPath } from "node:url";
73
81
  import Vue from "@vitejs/plugin-vue";
74
82
  import VueJsx from "@vitejs/plugin-vue-jsx";
@@ -130,61 +138,58 @@ ${value}
130
138
  }
131
139
 
132
140
  // node/plugins/extendConfig.ts
133
- import { dirname as dirname3, join as join4 } from "node:path";
141
+ import { join as join3 } from "node:path";
134
142
  import { mergeConfig as mergeConfig2 } from "vite";
135
143
  import isInstalledGlobally from "is-installed-globally";
136
- import { uniq as uniq2 } from "@antfu/utils";
144
+ import { uniq } from "@antfu/utils";
137
145
 
138
- // node/vite/searchRoot.ts
139
- import fs3 from "node:fs";
140
- import { dirname as dirname2, join as join3 } from "node:path";
141
- var ROOT_FILES = [
142
- // '.git',
143
- // https://pnpm.js.org/workspaces/
144
- "pnpm-workspace.yaml"
145
- // https://rushjs.io/pages/advanced/config_files/
146
- // 'rush.json',
147
- // https://nx.dev/latest/react/getting-started/nx-setup
148
- // 'workspace.json',
149
- // 'nx.json'
150
- ];
151
- function hasWorkspacePackageJSON(root) {
152
- const path2 = join3(root, "package.json");
153
- try {
154
- fs3.accessSync(path2, fs3.constants.R_OK);
155
- } catch {
156
- return false;
157
- }
158
- const content = JSON.parse(fs3.readFileSync(path2, "utf-8")) || {};
159
- return !!content.workspaces;
160
- }
161
- function hasRootFile(root) {
162
- return ROOT_FILES.some((file) => fs3.existsSync(join3(root, file)));
163
- }
164
- function hasPackageJSON(root) {
165
- const path2 = join3(root, "package.json");
166
- return fs3.existsSync(path2);
167
- }
168
- function searchForPackageRoot(current, root = current) {
169
- if (hasPackageJSON(current))
170
- return current;
171
- const dir = dirname2(current);
172
- if (!dir || dir === current)
173
- return root;
174
- return searchForPackageRoot(dir, root);
175
- }
176
- function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
177
- if (hasRootFile(current))
178
- return current;
179
- if (hasWorkspacePackageJSON(current))
180
- return current;
181
- const dir = dirname2(current);
182
- if (!dir || dir === current)
183
- return root;
184
- return searchForWorkspaceRoot(dir, root);
185
- }
146
+ // ../client/package.json
147
+ var dependencies = {
148
+ "@antfu/utils": "^0.7.7",
149
+ "@iconify-json/carbon": "^1.1.30",
150
+ "@iconify-json/ph": "^1.1.11",
151
+ "@iconify-json/svg-spinners": "^1.1.2",
152
+ "@shikijs/monaco": "^1.1.7",
153
+ "@shikijs/vitepress-twoslash": "^1.1.7",
154
+ "@slidev/parser": "workspace:*",
155
+ "@slidev/rough-notation": "^0.1.0",
156
+ "@slidev/types": "workspace:*",
157
+ "@typescript/ata": "^0.9.4",
158
+ "@unhead/vue": "^1.8.10",
159
+ "@unocss/reset": "^0.58.5",
160
+ "@vueuse/core": "^10.9.0",
161
+ "@vueuse/math": "^10.9.0",
162
+ "@vueuse/motion": "^2.1.0",
163
+ codemirror: "^5.65.16",
164
+ drauu: "^0.4.0",
165
+ "file-saver": "^2.0.5",
166
+ "floating-vue": "^5.2.2",
167
+ "fuse.js": "^7.0.0",
168
+ "js-yaml": "^4.1.0",
169
+ katex: "^0.16.9",
170
+ "lz-string": "^1.5.0",
171
+ mermaid: "^10.8.0",
172
+ "monaco-editor": "^0.46.0",
173
+ prettier: "^3.2.5",
174
+ recordrtc: "^5.6.2",
175
+ shiki: "^1.1.7",
176
+ "shiki-magic-move": "^0.1.0",
177
+ typescript: "^5.3.3",
178
+ unocss: "^0.58.5",
179
+ vue: "^3.4.21",
180
+ "vue-router": "^4.3.0"
181
+ };
186
182
 
187
183
  // node/plugins/extendConfig.ts
184
+ var INCLUDE = [
185
+ ...Object.keys(dependencies),
186
+ "codemirror/mode/javascript/javascript",
187
+ "codemirror/mode/css/css",
188
+ "codemirror/mode/markdown/markdown",
189
+ "codemirror/mode/xml/xml",
190
+ "codemirror/mode/htmlmixed/htmlmixed",
191
+ "codemirror/addon/display/placeholder"
192
+ ];
188
193
  var EXCLUDE = [
189
194
  "@slidev/shared",
190
195
  "@slidev/types",
@@ -197,7 +202,13 @@ var EXCLUDE = [
197
202
  "unocss",
198
203
  "mermaid",
199
204
  "vue-demi",
200
- "vue"
205
+ "vue",
206
+ "shiki"
207
+ ];
208
+ var ASYNC_MODULES = [
209
+ "file-saver",
210
+ "vue",
211
+ "@vue"
201
212
  ];
202
213
  function createConfigPlugin(options) {
203
214
  return {
@@ -207,12 +218,15 @@ function createConfigPlugin(options) {
207
218
  define: getDefine(options),
208
219
  resolve: {
209
220
  alias: {
210
- "@slidev/client/": `${toAtFS(options.clientRoot)}/`
221
+ "@slidev/client/": `${toAtFS(options.clientRoot)}/`,
222
+ "#slidev/": "/@slidev/",
223
+ "vue": await resolveImportPath("vue/dist/vue.esm-browser.js", true)
211
224
  },
212
225
  dedupe: ["vue"]
213
226
  },
214
227
  optimizeDeps: {
215
- exclude: EXCLUDE
228
+ exclude: EXCLUDE,
229
+ include: INCLUDE.filter((i) => !EXCLUDE.includes(i)).map((i) => `@slidev/cli > @slidev/client > ${i}`)
216
230
  },
217
231
  css: options.data.config.css === "unocss" ? {
218
232
  postcss: {
@@ -224,25 +238,50 @@ function createConfigPlugin(options) {
224
238
  server: {
225
239
  fs: {
226
240
  strict: true,
227
- allow: uniq2([
228
- searchForWorkspaceRoot(options.userRoot),
229
- searchForWorkspaceRoot(options.cliRoot),
230
- ...isInstalledGlobally ? [
231
- dirname3(await resolveGlobalImportPath("@slidev/client/package.json")),
232
- dirname3(await resolveGlobalImportPath("katex/package.json"))
233
- ] : []
241
+ allow: uniq([
242
+ options.userWorkspaceRoot,
243
+ options.cliRoot,
244
+ options.clientRoot,
245
+ ...options.roots
234
246
  ])
235
247
  }
236
248
  },
237
- publicDir: join4(options.userRoot, "public")
249
+ publicDir: join3(options.userRoot, "public"),
250
+ build: {
251
+ rollupOptions: {
252
+ output: {
253
+ chunkFileNames(chunkInfo) {
254
+ const DEFAULT = "assets/[name]-[hash].js";
255
+ if (chunkInfo.name.includes("/"))
256
+ return DEFAULT;
257
+ if (chunkInfo.moduleIds.filter((i) => isSlidevClient(i)).length > chunkInfo.moduleIds.length * 0.6)
258
+ return "assets/slidev/[name]-[hash].js";
259
+ if (chunkInfo.moduleIds.filter((i) => i.match(/\/monaco-editor(-core)?\//)).length > chunkInfo.moduleIds.length * 0.6)
260
+ return "assets/monaco/[name]-[hash].js";
261
+ return DEFAULT;
262
+ },
263
+ manualChunks(id) {
264
+ if (id.startsWith("/@slidev-monaco-types/") || id.includes("/@slidev/monaco-types") || id.endsWith("?monaco-types&raw"))
265
+ return "monaco/bundled-types";
266
+ if (id.includes("/shiki/") || id.includes("/@shikijs/"))
267
+ return `modules/shiki`;
268
+ if (id.startsWith("~icons/"))
269
+ return "modules/unplugin-icons";
270
+ const matchedAsyncModule = ASYNC_MODULES.find((i) => id.includes(`/node_modules/${i}`));
271
+ if (matchedAsyncModule)
272
+ return `modules/${matchedAsyncModule.replace("@", "").replace("/", "-")}`;
273
+ }
274
+ }
275
+ }
276
+ }
238
277
  };
239
- injection.resolve ||= {};
240
- injection.resolve.alias ||= {};
278
+ function isSlidevClient(id) {
279
+ return id.includes("/@slidev/") || id.includes("/slidev/packages/client/") || id.includes("/@vueuse/");
280
+ }
241
281
  if (isInstalledGlobally) {
242
- injection.cacheDir = join4(options.cliRoot, "node_modules/.vite");
282
+ injection.cacheDir = join3(options.cliRoot, "node_modules/.vite");
243
283
  injection.root = options.cliRoot;
244
284
  }
245
- injection.resolve.alias.vue = await resolveImportPath("vue/dist/vue.esm-browser.js", true);
246
285
  return mergeConfig2(injection, config);
247
286
  },
248
287
  configureServer(server) {
@@ -275,1460 +314,1570 @@ function getDefine(options) {
275
314
  }
276
315
 
277
316
  // node/plugins/loaders.ts
278
- import { basename as basename2, join as join5 } from "node:path";
279
- import { isString, isTruthy, notNullish, objectMap, range, slash, uniq as uniq3 } from "@antfu/utils";
317
+ import { basename as basename2, join as join4, resolve as resolve2 } from "node:path";
318
+ import { builtinModules } from "node:module";
319
+ import { isString, isTruthy as isTruthy2, notNullish, objectMap, range, uniq as uniq2 } from "@antfu/utils";
280
320
  import fg2 from "fast-glob";
281
- import fs4 from "fs-extra";
282
- import Markdown from "markdown-it";
321
+ import fs5 from "fs-extra";
322
+ import Markdown2 from "markdown-it";
283
323
  import { bold, gray, red, yellow } from "kolorist";
284
- import mila from "markdown-it-link-attributes";
324
+ import mila2 from "markdown-it-link-attributes";
285
325
  import * as parser from "@slidev/parser/fs";
286
326
  import equal from "fast-deep-equal";
287
- var regexId = /^\/\@slidev\/slide\/(\d+)\.(md|json)(?:\?import)?$/;
288
- var regexIdQuery = /(\d+?)\.(md|json|frontmatter)$/;
289
- var vueContextImports = [
290
- `import { inject as _vueInject, provide as _vueProvide, toRef as _vueToRef } from "vue"`,
291
- `import {
292
- injectionSlidevContext as _injectionSlidevContext,
293
- injectionClicksContext as _injectionClicksContext,
294
- injectionCurrentPage as _injectionCurrentPage,
295
- injectionRenderContext as _injectionRenderContext,
296
- injectionFrontmatter as _injectionFrontmatter,
297
- } from "@slidev/client/constants.ts"`.replace(/\n\s+/g, "\n"),
298
- "const $slidev = _vueInject(_injectionSlidevContext)",
299
- 'const $nav = _vueToRef($slidev, "nav")',
300
- "const $clicksContext = _vueInject(_injectionClicksContext)?.value",
301
- 'const $clicks = _vueToRef($clicksContext, "current")',
302
- "const $page = _vueInject(_injectionCurrentPage)",
303
- "const $renderContext = _vueInject(_injectionRenderContext)"
304
- ];
305
- function getBodyJson(req) {
306
- return new Promise((resolve3, reject) => {
307
- let body = "";
308
- req.on("data", (chunk) => body += chunk);
309
- req.on("error", reject);
310
- req.on("end", () => {
311
- try {
312
- resolve3(JSON.parse(body) || {});
313
- } catch (e) {
314
- reject(e);
327
+
328
+ // node/plugins/markdown.ts
329
+ import fs4 from "node:fs/promises";
330
+ import Markdown from "unplugin-vue-markdown/vite";
331
+ import { isTruthy, slash } from "@antfu/utils";
332
+
333
+ // ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=tuyuxytl56b2vxulpkzt2wf4o4_markdown-it@14.0.0/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/image-size/specialCharacters.js
334
+ var SpecialCharacters;
335
+ (function(SpecialCharacters2) {
336
+ SpecialCharacters2[SpecialCharacters2["EXCLAMATION_MARK"] = 33] = "EXCLAMATION_MARK";
337
+ SpecialCharacters2[SpecialCharacters2["OPENING_BRACKET"] = 91] = "OPENING_BRACKET";
338
+ SpecialCharacters2[SpecialCharacters2["OPENING_PARENTHESIS"] = 40] = "OPENING_PARENTHESIS";
339
+ SpecialCharacters2[SpecialCharacters2["WHITESPACE"] = 32] = "WHITESPACE";
340
+ SpecialCharacters2[SpecialCharacters2["NEW_LINE"] = 10] = "NEW_LINE";
341
+ SpecialCharacters2[SpecialCharacters2["EQUALS"] = 61] = "EQUALS";
342
+ SpecialCharacters2[SpecialCharacters2["LOWER_CASE_X"] = 120] = "LOWER_CASE_X";
343
+ SpecialCharacters2[SpecialCharacters2["NUMBER_ZERO"] = 48] = "NUMBER_ZERO";
344
+ SpecialCharacters2[SpecialCharacters2["NUMBER_NINE"] = 57] = "NUMBER_NINE";
345
+ SpecialCharacters2[SpecialCharacters2["PERCENTAGE"] = 37] = "PERCENTAGE";
346
+ SpecialCharacters2[SpecialCharacters2["CLOSING_PARENTHESIS"] = 41] = "CLOSING_PARENTHESIS";
347
+ })(SpecialCharacters || (SpecialCharacters = {}));
348
+
349
+ // ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=tuyuxytl56b2vxulpkzt2wf4o4_markdown-it@14.0.0/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/task-lists/index.js
350
+ import Token from "markdown-it/lib/token.mjs";
351
+ var checkboxRegex = /^ *\[([\sx])] /i;
352
+ function taskLists(md2, options = { enabled: false, label: false, lineNumber: false }) {
353
+ md2.core.ruler.after("inline", "task-lists", (state) => processToken(state, options));
354
+ md2.renderer.rules.taskListItemCheckbox = (tokens) => {
355
+ const token = tokens[0];
356
+ const checkedAttribute = token.attrGet("checked") ? 'checked="" ' : "";
357
+ const disabledAttribute = token.attrGet("disabled") ? 'disabled="" ' : "";
358
+ const line = token.attrGet("line");
359
+ const idAttribute = `id="${token.attrGet("id")}" `;
360
+ const dataLineAttribute = line && options.lineNumber ? `data-line="${line}" ` : "";
361
+ return `<input class="task-list-item-checkbox" type="checkbox" ${checkedAttribute}${disabledAttribute}${dataLineAttribute}${idAttribute}/>`;
362
+ };
363
+ md2.renderer.rules.taskListItemLabel_close = () => {
364
+ return "</label>";
365
+ };
366
+ md2.renderer.rules.taskListItemLabel_open = (tokens) => {
367
+ const token = tokens[0];
368
+ const id = token.attrGet("id");
369
+ return `<label for="${id}">`;
370
+ };
371
+ }
372
+ function processToken(state, options) {
373
+ const allTokens = state.tokens;
374
+ for (let i = 2; i < allTokens.length; i++) {
375
+ if (!isTodoItem(allTokens, i)) {
376
+ continue;
377
+ }
378
+ todoify(allTokens[i], options);
379
+ allTokens[i - 2].attrJoin("class", `task-list-item ${options.enabled ? " enabled" : ""}`);
380
+ const parentToken = findParentToken(allTokens, i - 2);
381
+ if (parentToken) {
382
+ const classes = parentToken.attrGet("class") ?? "";
383
+ if (!classes.match(/(^| )contains-task-list/)) {
384
+ parentToken.attrJoin("class", "contains-task-list");
315
385
  }
316
- });
317
- });
386
+ }
387
+ }
388
+ return false;
318
389
  }
319
- var md = Markdown({ html: true });
320
- md.use(mila, {
321
- attrs: {
322
- target: "_blank",
323
- rel: "noopener"
390
+ function findParentToken(tokens, index) {
391
+ const targetLevel = tokens[index].level - 1;
392
+ for (let currentTokenIndex = index - 1; currentTokenIndex >= 0; currentTokenIndex--) {
393
+ if (tokens[currentTokenIndex].level === targetLevel) {
394
+ return tokens[currentTokenIndex];
395
+ }
324
396
  }
325
- });
326
- function prepareSlideInfo(data) {
397
+ return void 0;
398
+ }
399
+ function isTodoItem(tokens, index) {
400
+ return isInline(tokens[index]) && isParagraph(tokens[index - 1]) && isListItem(tokens[index - 2]) && startsWithTodoMarkdown(tokens[index]);
401
+ }
402
+ function todoify(token, options) {
403
+ if (token.children == null) {
404
+ return;
405
+ }
406
+ const id = generateIdForToken(token);
407
+ token.children.splice(0, 0, createCheckboxToken(token, options.enabled, id));
408
+ token.children[1].content = token.children[1].content.replace(checkboxRegex, "");
409
+ if (options.label) {
410
+ token.children.splice(1, 0, createLabelBeginToken(id));
411
+ token.children.push(createLabelEndToken());
412
+ }
413
+ }
414
+ function generateIdForToken(token) {
415
+ if (token.map) {
416
+ return `task-item-${token.map[0]}`;
417
+ } else {
418
+ return `task-item-${Math.ceil(Math.random() * (1e4 * 1e3) - 1e3)}`;
419
+ }
420
+ }
421
+ function createCheckboxToken(token, enabled, id) {
422
+ const checkbox = new Token("taskListItemCheckbox", "", 0);
423
+ if (!enabled) {
424
+ checkbox.attrSet("disabled", "true");
425
+ }
426
+ if (token.map) {
427
+ checkbox.attrSet("line", token.map[0].toString());
428
+ }
429
+ checkbox.attrSet("id", id);
430
+ const checkboxRegexResult = checkboxRegex.exec(token.content);
431
+ const isChecked = checkboxRegexResult?.[1].toLowerCase() === "x";
432
+ if (isChecked) {
433
+ checkbox.attrSet("checked", "true");
434
+ }
435
+ return checkbox;
436
+ }
437
+ function createLabelBeginToken(id) {
438
+ const labelBeginToken = new Token("taskListItemLabel_open", "", 1);
439
+ labelBeginToken.attrSet("id", id);
440
+ return labelBeginToken;
441
+ }
442
+ function createLabelEndToken() {
443
+ return new Token("taskListItemLabel_close", "", -1);
444
+ }
445
+ function isInline(token) {
446
+ return token.type === "inline";
447
+ }
448
+ function isParagraph(token) {
449
+ return token.type === "paragraph_open";
450
+ }
451
+ function isListItem(token) {
452
+ return token.type === "list_item_open";
453
+ }
454
+ function startsWithTodoMarkdown(token) {
455
+ return checkboxRegex.test(token.content);
456
+ }
457
+
458
+ // node/plugins/markdown.ts
459
+ import { encode as encodePlantUml } from "plantuml-encoder";
460
+ import Mdc from "markdown-it-mdc";
461
+ import { codeToKeyedTokens, createMagicMoveMachine } from "shiki-magic-move/core";
462
+ import mila from "markdown-it-link-attributes";
463
+ import mif from "markdown-it-footnote";
464
+ import lz from "lz-string";
465
+
466
+ // node/plugins/markdown-it-katex.ts
467
+ import katex from "katex";
468
+ function isValidDelim(state, pos) {
469
+ const max = state.posMax;
470
+ let can_open = true;
471
+ let can_close = true;
472
+ const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
473
+ const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
474
+ if (prevChar === 32 || prevChar === 9 || /* \t */
475
+ nextChar >= 48 && nextChar <= 57)
476
+ can_close = false;
477
+ if (nextChar === 32 || nextChar === 9)
478
+ can_open = false;
327
479
  return {
328
- ...data,
329
- noteHTML: md.render(data?.note || "")
480
+ can_open,
481
+ can_close
330
482
  };
331
483
  }
332
- function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, userRoot, roots, remote, mode }, pluginOptions, serverOptions) {
333
- const slidePrefix = "/@slidev/slides/";
334
- const hmrPages = /* @__PURE__ */ new Set();
335
- let server;
336
- let _layouts_cache_time = 0;
337
- let _layouts_cache = {};
338
- return [
339
- {
340
- name: "slidev:loader",
341
- configureServer(_server) {
342
- server = _server;
343
- updateServerWatcher();
344
- server.middlewares.use(async (req, res, next) => {
345
- const match = req.url?.match(regexId);
346
- if (!match)
347
- return next();
348
- const [, no, type] = match;
349
- const idx = Number.parseInt(no);
350
- if (type === "json" && req.method === "GET") {
351
- res.write(JSON.stringify(prepareSlideInfo(data.slides[idx])));
352
- return res.end();
353
- }
354
- if (type === "json" && req.method === "POST") {
355
- const body = await getBodyJson(req);
356
- const slide = data.slides[idx];
357
- const onlyNoteChanged = Object.keys(body).length === 2 && "note" in body && body.raw === null;
358
- if (!onlyNoteChanged)
359
- hmrPages.add(idx);
360
- if (slide.source) {
361
- Object.assign(slide.source, body);
362
- await parser.saveExternalSlide(data, slide.source.filepath);
363
- } else {
364
- Object.assign(slide, body);
365
- await parser.save(data, entry);
366
- }
367
- res.statusCode = 200;
368
- res.write(JSON.stringify(prepareSlideInfo(slide)));
369
- return res.end();
370
- }
371
- next();
372
- });
373
- },
374
- async handleHotUpdate(ctx) {
375
- if (!data.entries.some((i) => slash(i) === ctx.file))
376
- return;
377
- await ctx.read();
378
- const newData = await parser.load(entry, data.themeMeta);
379
- const moduleIds = /* @__PURE__ */ new Set();
380
- if (data.slides.length !== newData.slides.length) {
381
- moduleIds.add("/@slidev/routes");
382
- range(newData.slides.length).map((i) => hmrPages.add(i));
383
- }
384
- if (!equal(data.headmatter.defaults, newData.headmatter.defaults)) {
385
- moduleIds.add("/@slidev/routes");
386
- range(data.slides.length).map((i) => hmrPages.add(i));
387
- }
388
- if (!equal(data.config, newData.config))
389
- moduleIds.add("/@slidev/configs");
390
- if (!equal(data.features, newData.features)) {
391
- setTimeout(() => {
392
- ctx.server.ws.send({ type: "full-reload" });
393
- }, 1);
394
- }
395
- const length = Math.max(data.slides.length, newData.slides.length);
396
- for (let i = 0; i < length; i++) {
397
- const a = data.slides[i];
398
- const b = newData.slides[i];
399
- if (a?.content.trim() === b?.content.trim() && a?.title?.trim() === b?.title?.trim() && equal(a.frontmatter, b.frontmatter) && Object.entries(a.snippetsUsed ?? {}).every(([file, oldContent]) => {
400
- try {
401
- const newContent = fs4.readFileSync(file, "utf-8");
402
- return oldContent === newContent;
403
- } catch {
404
- return false;
405
- }
406
- })) {
407
- if (a?.note !== b?.note) {
408
- ctx.server.ws.send({
409
- type: "custom",
410
- event: "slidev-update-note",
411
- data: {
412
- id: i,
413
- note: b.note || "",
414
- noteHTML: md.render(b.note || "")
415
- }
416
- });
417
- }
418
- continue;
419
- }
420
- ctx.server.ws.send({
421
- type: "custom",
422
- event: "slidev-update",
423
- data: {
424
- id: i,
425
- data: prepareSlideInfo(newData.slides[i])
426
- }
427
- });
428
- hmrPages.add(i);
429
- }
430
- serverOptions.onDataReload?.(newData, data);
431
- Object.assign(data, newData);
432
- if (hmrPages.size > 0)
433
- moduleIds.add("/@slidev/titles.md");
434
- const vueModules = Array.from(hmrPages).flatMap((i) => [
435
- ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.frontmatter`),
436
- ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.md`)
437
- ]);
438
- hmrPages.clear();
439
- const moduleEntries = [
440
- ...vueModules,
441
- ...Array.from(moduleIds).map((id) => ctx.server.moduleGraph.getModuleById(id))
442
- ].filter(notNullish).filter((i) => !i.id?.startsWith("/@id/@vite-icons"));
443
- updateServerWatcher();
444
- return moduleEntries;
445
- },
446
- resolveId(id) {
447
- if (id.startsWith(slidePrefix) || id.startsWith("/@slidev/"))
448
- return id;
449
- return null;
450
- },
451
- load(id) {
452
- if (id === "/@slidev/routes")
453
- return generateRoutes();
454
- if (id === "/@slidev/layouts")
455
- return generateLayouts();
456
- if (id === "/@slidev/styles")
457
- return generateUserStyles();
458
- if (id === "/@slidev/monaco-types")
459
- return generateMonacoTypes();
460
- if (id === "/@slidev/configs")
461
- return generateConfigs();
462
- if (id === "/@slidev/global-components/top")
463
- return generateGlobalComponents("top");
464
- if (id === "/@slidev/global-components/bottom")
465
- return generateGlobalComponents("bottom");
466
- if (id === "/@slidev/custom-nav-controls")
467
- return generateCustomNavControls();
468
- if (id === "/@slidev/titles.md") {
469
- return {
470
- code: data.slides.filter(({ frontmatter }) => !frontmatter?.disabled).map(({ title }, i) => `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">
471
-
472
- ${title}
473
-
474
- </template>`).join(""),
475
- map: { mappings: "" }
476
- };
477
- }
478
- if (id.startsWith(slidePrefix)) {
479
- const remaning = id.slice(slidePrefix.length);
480
- const match = remaning.match(regexIdQuery);
481
- if (match) {
482
- const [, no, type] = match;
483
- const pageNo = Number.parseInt(no) - 1;
484
- const slide = data.slides[pageNo];
485
- if (!slide)
486
- return;
487
- if (type === "md") {
488
- return {
489
- code: slide?.content,
490
- map: { mappings: "" }
491
- };
492
- } else if (type === "frontmatter") {
493
- const slideBase = {
494
- ...prepareSlideInfo(slide),
495
- frontmatter: void 0,
496
- // remove raw content in build, optimize the bundle size
497
- ...mode === "build" ? { raw: "", content: "", note: "" } : {}
498
- };
499
- const fontmatter = getFrontmatter(pageNo);
500
- return {
501
- code: [
502
- "// @unocss-include",
503
- 'import { reactive, computed } from "vue"',
504
- `export const frontmatter = reactive(${JSON.stringify(fontmatter)})`,
505
- `export const meta = reactive({
506
- layout: computed(() => frontmatter.layout),
507
- transition: computed(() => frontmatter.transition),
508
- class: computed(() => frontmatter.class),
509
- clicks: computed(() => frontmatter.clicks),
510
- name: computed(() => frontmatter.name),
511
- preload: computed(() => frontmatter.preload),
512
- slide: {
513
- ...(${JSON.stringify(slideBase)}),
514
- frontmatter,
515
- filepath: ${JSON.stringify(slide.source?.filepath || entry)},
516
- id: ${pageNo},
517
- no: ${no},
518
- },
519
- __clicksContext: null,
520
- __preloaded: false,
521
- })`,
522
- "export default frontmatter",
523
- // handle HMR, update frontmatter with update
524
- "if (import.meta.hot) {",
525
- " import.meta.hot.accept(({ frontmatter: update }) => {",
526
- " if(!update) return",
527
- " Object.keys(frontmatter).forEach(key => {",
528
- " if (!(key in update)) delete frontmatter[key]",
529
- " })",
530
- " Object.assign(frontmatter, update)",
531
- " })",
532
- "}"
533
- ].join("\n"),
534
- map: { mappings: "" }
535
- };
536
- }
537
- }
538
- return {
539
- code: "",
540
- map: { mappings: "" }
541
- };
542
- }
543
- }
544
- },
545
- {
546
- name: "slidev:layout-transform:pre",
547
- enforce: "pre",
548
- async transform(code, id) {
549
- if (!id.startsWith(slidePrefix))
550
- return;
551
- const remaning = id.slice(slidePrefix.length);
552
- const match = remaning.match(regexIdQuery);
553
- if (!match)
554
- return;
555
- const [, no, type] = match;
556
- if (type !== "md")
557
- return;
558
- const pageNo = Number.parseInt(no) - 1;
559
- return transformMarkdown(code, pageNo);
560
- }
561
- },
562
- {
563
- name: "slidev:context-transform:pre",
564
- enforce: "pre",
565
- async transform(code, id) {
566
- if (!id.endsWith(".vue") || id.includes("/@slidev/client/") || id.includes("/packages/client/"))
567
- return;
568
- return transformVue(code);
569
- }
570
- },
571
- {
572
- name: "slidev:title-transform:pre",
573
- enforce: "pre",
574
- transform(code, id) {
575
- if (id !== "/@slidev/titles.md")
576
- return;
577
- return transformTitles(code);
578
- }
579
- },
580
- {
581
- name: "slidev:slide-transform:post",
582
- enforce: "post",
583
- transform(code, id) {
584
- if (!id.match(/\/@slidev\/slides\/\d+\.md($|\?)/))
585
- return;
586
- const replaced = code.replace("if (_rerender_only)", "if (false)");
587
- if (replaced !== code)
588
- return replaced;
589
- }
590
- },
591
- {
592
- name: "slidev:index-html-transform",
593
- transformIndexHtml() {
594
- const { info, author, keywords } = data.headmatter;
595
- return [
596
- {
597
- tag: "title",
598
- children: getTitle()
599
- },
600
- info && {
601
- tag: "meta",
602
- attrs: {
603
- name: "description",
604
- content: info
605
- }
606
- },
607
- author && {
608
- tag: "meta",
609
- attrs: {
610
- name: "author",
611
- content: author
612
- }
613
- },
614
- keywords && {
615
- tag: "meta",
616
- attrs: {
617
- name: "keywords",
618
- content: Array.isArray(keywords) ? keywords.join(", ") : keywords
619
- }
620
- }
621
- ].filter(isTruthy);
622
- }
623
- }
624
- ];
625
- function updateServerWatcher() {
626
- if (!server)
627
- return;
628
- server.watcher.add(data.entries?.map(slash) || []);
484
+ function math_inline(state, silent) {
485
+ let match, token, res, pos;
486
+ if (state.src[state.pos] !== "$")
487
+ return false;
488
+ res = isValidDelim(state, state.pos);
489
+ if (!res.can_open) {
490
+ if (!silent)
491
+ state.pending += "$";
492
+ state.pos += 1;
493
+ return true;
629
494
  }
630
- function getFrontmatter(pageNo) {
631
- return {
632
- ...data.headmatter?.defaults || {},
633
- ...data.slides[pageNo]?.frontmatter || {}
634
- };
495
+ const start = state.pos + 1;
496
+ match = start;
497
+ while ((match = state.src.indexOf("$", match)) !== -1) {
498
+ pos = match - 1;
499
+ while (state.src[pos] === "\\")
500
+ pos -= 1;
501
+ if ((match - pos) % 2 === 1)
502
+ break;
503
+ match += 1;
635
504
  }
636
- async function transformMarkdown(code, pageNo) {
637
- const layouts = await getLayouts();
638
- const frontmatter = getFrontmatter(pageNo);
639
- let layoutName = frontmatter?.layout || (pageNo === 0 ? "cover" : "default");
640
- if (!layouts[layoutName]) {
641
- console.error(red(`
642
- Unknown layout "${bold(layoutName)}".${yellow(" Available layouts are:")}`) + Object.keys(layouts).map((i, idx) => (idx % 3 === 0 ? "\n " : "") + gray(i.padEnd(15, " "))).join(" "));
643
- console.error();
644
- layoutName = "default";
645
- }
646
- delete frontmatter.title;
647
- const imports = [
648
- ...vueContextImports,
649
- `import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
650
- `import frontmatter from "${toAtFS(`${slidePrefix + (pageNo + 1)}.frontmatter`)}"`,
651
- "const $frontmatter = frontmatter",
652
- "_vueProvide(_injectionFrontmatter, frontmatter)",
653
- // update frontmatter in router
654
- ";(() => {",
655
- " const route = $slidev.nav.rawRoutes.find(i => i.path === String($page.value))",
656
- " if (route?.meta?.slide?.frontmatter) {",
657
- " Object.keys(route.meta.slide.frontmatter).forEach(key => {",
658
- " if (!(key in $frontmatter)) delete route.meta.slide.frontmatter[key]",
659
- " })",
660
- " Object.assign(route.meta.slide.frontmatter, frontmatter)",
661
- " }",
662
- "})();"
663
- ];
664
- code = code.replace(/(<script setup.*>)/g, `$1
665
- ${imports.join("\n")}
666
- `);
667
- const injectA = code.indexOf("<template>") + "<template>".length;
668
- const injectB = code.lastIndexOf("</template>");
669
- let body = code.slice(injectA, injectB).trim();
670
- if (body.startsWith("<div>") && body.endsWith("</div>"))
671
- body = body.slice(5, -6);
672
- code = `${code.slice(0, injectA)}
673
- <InjectedLayout v-bind="frontmatter">
674
- ${body}
675
- </InjectedLayout>
676
- ${code.slice(injectB)}`;
677
- return code;
505
+ if (match === -1) {
506
+ if (!silent)
507
+ state.pending += "$";
508
+ state.pos = start;
509
+ return true;
678
510
  }
679
- function transformVue(code) {
680
- if (code.includes("injectionSlidevContext") || code.includes("injectionClicksContext") || code.includes("const $slidev"))
681
- return code;
682
- const imports = [
683
- ...vueContextImports,
684
- "const $frontmatter = _vueInject(_injectionFrontmatter)"
685
- ];
686
- const matchScript = code.match(/<script((?!setup).)*(setup)?.*>/);
687
- if (matchScript && matchScript[2]) {
688
- return code.replace(/(<script.*>)/g, `$1
689
- ${imports.join("\n")}
690
- `);
691
- } else if (matchScript && !matchScript[2]) {
692
- const matchExport = code.match(/export\s+default\s+{/);
693
- if (matchExport) {
694
- const exportIndex = (matchExport.index || 0) + matchExport[0].length;
695
- let component = code.slice(exportIndex);
696
- component = component.slice(0, component.indexOf("</script>"));
697
- const scriptIndex = (matchScript.index || 0) + matchScript[0].length;
698
- const provideImport = '\nimport { injectionSlidevContext } from "@slidev/client/constants.ts"\n';
699
- code = `${code.slice(0, scriptIndex)}${provideImport}${code.slice(scriptIndex)}`;
700
- let injectIndex = exportIndex + provideImport.length;
701
- let injectObject = "$slidev: { from: injectionSlidevContext },";
702
- const matchInject = component.match(/.*inject\s*:\s*([\[{])/);
703
- if (matchInject) {
704
- injectIndex += (matchInject.index || 0) + matchInject[0].length;
705
- if (matchInject[1] === "[") {
706
- let injects = component.slice((matchInject.index || 0) + matchInject[0].length);
707
- const injectEndIndex = injects.indexOf("]");
708
- injects = injects.slice(0, injectEndIndex);
709
- injectObject += injects.split(",").map((inject) => `${inject}: {from: ${inject}}`).join(",");
710
- return `${code.slice(0, injectIndex - 1)}{
711
- ${injectObject}
712
- }${code.slice(injectIndex + injectEndIndex + 1)}`;
713
- } else {
714
- return `${code.slice(0, injectIndex)}
715
- ${injectObject}
716
- ${code.slice(injectIndex)}`;
717
- }
718
- }
719
- return `${code.slice(0, injectIndex)}
720
- inject: { ${injectObject} },
721
- ${code.slice(injectIndex)}`;
722
- }
723
- }
724
- return `<script setup>
725
- ${imports.join("\n")}
726
- </script>
727
- ${code}`;
728
- }
729
- function transformTitles(code) {
730
- return code.replace(/<template>\s*<div>\s*<p>/, "<template>").replace(/<\/p>\s*<\/div>\s*<\/template>/, "</template>").replace(/<script\ssetup>/, `<script setup lang="ts">
731
- defineProps<{ no: number | string }>()`);
511
+ if (match - start === 0) {
512
+ if (!silent)
513
+ state.pending += "$$";
514
+ state.pos = start + 1;
515
+ return true;
732
516
  }
733
- async function getLayouts() {
734
- const now = Date.now();
735
- if (now - _layouts_cache_time < 2e3)
736
- return _layouts_cache;
737
- const layouts = {};
738
- const roots2 = uniq3([
739
- userRoot,
740
- ...themeRoots,
741
- ...addonRoots,
742
- clientRoot
743
- ]);
744
- for (const root of roots2) {
745
- const layoutPaths = await fg2("layouts/**/*.{vue,ts}", {
746
- cwd: root,
747
- absolute: true,
748
- suppressErrors: true
749
- });
750
- for (const layoutPath of layoutPaths) {
751
- const layout = basename2(layoutPath).replace(/\.\w+$/, "");
752
- if (layouts[layout])
753
- continue;
754
- layouts[layout] = layoutPath;
755
- }
756
- }
757
- _layouts_cache_time = now;
758
- _layouts_cache = layouts;
759
- return layouts;
517
+ res = isValidDelim(state, match);
518
+ if (!res.can_close) {
519
+ if (!silent)
520
+ state.pending += "$";
521
+ state.pos = start;
522
+ return true;
760
523
  }
761
- async function resolveUrl(id) {
762
- return toAtFS(await resolveImportPath(id, true));
524
+ if (!silent) {
525
+ token = state.push("math_inline", "math", 0);
526
+ token.markup = "$";
527
+ token.content = state.src.slice(start, match);
763
528
  }
764
- function resolveUrlOfClient(name) {
765
- return toAtFS(join5(clientRoot, name));
529
+ state.pos = match + 1;
530
+ return true;
531
+ }
532
+ function math_block(state, start, end, silent) {
533
+ let firstLine;
534
+ let lastLine;
535
+ let next;
536
+ let lastPos;
537
+ let found = false;
538
+ let pos = state.bMarks[start] + state.tShift[start];
539
+ let max = state.eMarks[start];
540
+ if (pos + 2 > max)
541
+ return false;
542
+ if (state.src.slice(pos, pos + 2) !== "$$")
543
+ return false;
544
+ pos += 2;
545
+ firstLine = state.src.slice(pos, max);
546
+ if (silent)
547
+ return true;
548
+ if (firstLine.trim().slice(-2) === "$$") {
549
+ firstLine = firstLine.trim().slice(0, -2);
550
+ found = true;
766
551
  }
767
- async function generateUserStyles() {
768
- const imports = [
769
- `import "${resolveUrlOfClient("styles/vars.css")}"`,
770
- `import "${resolveUrlOfClient("styles/index.css")}"`,
771
- `import "${resolveUrlOfClient("styles/code.css")}"`,
772
- `import "${resolveUrlOfClient("styles/katex.css")}"`,
773
- `import "${resolveUrlOfClient("styles/transitions.css")}"`
774
- ];
775
- const roots2 = uniq3([
776
- ...themeRoots,
777
- ...addonRoots,
778
- userRoot
779
- ]);
780
- for (const root of roots2) {
781
- const styles = [
782
- join5(root, "styles", "index.ts"),
783
- join5(root, "styles", "index.js"),
784
- join5(root, "styles", "index.css"),
785
- join5(root, "styles.css"),
786
- join5(root, "style.css")
787
- ];
788
- for (const style of styles) {
789
- if (fs4.existsSync(style)) {
790
- imports.push(`import "${toAtFS(style)}"`);
791
- continue;
792
- }
793
- }
794
- }
795
- if (data.features.katex)
796
- imports.push(`import "${await resolveUrl("katex/dist/katex.min.css")}"`);
797
- if (data.config.highlighter === "shiki") {
798
- imports.push(
799
- `import "${await resolveUrl("@shikijs/vitepress-twoslash/style.css")}"`,
800
- `import "${resolveUrlOfClient("styles/shiki-twoslash.css")}"`
801
- );
552
+ for (next = start; !found; ) {
553
+ next++;
554
+ if (next >= end)
555
+ break;
556
+ pos = state.bMarks[next] + state.tShift[next];
557
+ max = state.eMarks[next];
558
+ if (pos < max && state.tShift[next] < state.blkIndent) {
559
+ break;
802
560
  }
803
- if (data.config.css === "unocss") {
804
- imports.unshift(
805
- `import "${await resolveUrl("@unocss/reset/tailwind.css")}"`,
806
- 'import "uno:preflights.css"',
807
- 'import "uno:typography.css"',
808
- 'import "uno:shortcuts.css"'
809
- );
810
- imports.push('import "uno.css"');
561
+ if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
562
+ lastPos = state.src.slice(0, max).lastIndexOf("$$");
563
+ lastLine = state.src.slice(pos, lastPos);
564
+ found = true;
811
565
  }
812
- return imports.join("\n");
813
566
  }
814
- async function generateMonacoTypes() {
815
- return `void 0; ${parser.scanMonacoModules(data.raw).map((i) => `import('/@slidev-monaco-types/${i}')`).join("\n")}`;
567
+ state.line = next + 1;
568
+ const token = state.push("math_block", "math", 0);
569
+ token.block = true;
570
+ token.content = (firstLine && firstLine.trim() ? `${firstLine}
571
+ ` : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
572
+ token.map = [start, state.line];
573
+ token.markup = "$$";
574
+ return true;
575
+ }
576
+ function math_plugin(md2, options) {
577
+ options = options || {};
578
+ const katexInline = function(latex) {
579
+ options.displayMode = false;
580
+ try {
581
+ return katex.renderToString(latex, options);
582
+ } catch (error) {
583
+ if (options.throwOnError)
584
+ console.warn(error);
585
+ return latex;
586
+ }
587
+ };
588
+ const inlineRenderer = function(tokens, idx) {
589
+ return katexInline(tokens[idx].content);
590
+ };
591
+ const katexBlock = function(latex) {
592
+ options.displayMode = true;
593
+ try {
594
+ return `<p>${katex.renderToString(latex, options)}</p>`;
595
+ } catch (error) {
596
+ if (options.throwOnError)
597
+ console.warn(error);
598
+ return latex;
599
+ }
600
+ };
601
+ const blockRenderer = function(tokens, idx) {
602
+ return `${katexBlock(tokens[idx].content)}
603
+ `;
604
+ };
605
+ md2.inline.ruler.after("escape", "math_inline", math_inline);
606
+ md2.block.ruler.after("blockquote", "math_block", math_block, {
607
+ alt: ["paragraph", "reference", "blockquote", "list"]
608
+ });
609
+ md2.renderer.rules.math_inline = inlineRenderer;
610
+ md2.renderer.rules.math_block = blockRenderer;
611
+ }
612
+
613
+ // node/plugins/markdown-it-prism.ts
614
+ import { createRequire } from "node:module";
615
+ import Prism from "prismjs";
616
+ import loadLanguages from "prismjs/components/index.js";
617
+ import * as htmlparser2 from "htmlparser2";
618
+ var require2 = createRequire(import.meta.url);
619
+ var Tag = class {
620
+ tagname;
621
+ attributes;
622
+ constructor(tagname, attributes) {
623
+ this.tagname = tagname;
624
+ this.attributes = attributes;
816
625
  }
817
- async function generateLayouts() {
818
- const imports = [];
819
- const layouts = objectMap(
820
- await getLayouts(),
821
- (k, v) => {
822
- imports.push(`import __layout_${k} from "${toAtFS(v)}"`);
823
- return [k, `__layout_${k}`];
824
- }
825
- );
826
- return [
827
- imports.join("\n"),
828
- `export default {
829
- ${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}
830
- }`
831
- ].join("\n\n");
626
+ asOpen() {
627
+ return `<${this.tagname} ${Object.entries(this.attributes).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
832
628
  }
833
- async function generateRoutes() {
834
- const imports = [];
835
- const redirects = [];
836
- const layouts = await getLayouts();
837
- imports.push(`import __layout__end from '${layouts.end}'`);
838
- let no = 1;
839
- const routes = data.slides.filter(({ frontmatter }) => !frontmatter?.disabled).map((i, idx) => {
840
- imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
841
- imports.push(`import { meta as f${no} } from '${slidePrefix}${idx + 1}.frontmatter'`);
842
- const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: f${no} }`;
843
- if (i.frontmatter?.routeAlias)
844
- redirects.push(`{ path: '${i.frontmatter?.routeAlias}', redirect: { path: '${no}' } }`);
845
- no += 1;
846
- return route;
847
- });
848
- const routesStr = `export default [
849
- ${routes.join(",\n")}
850
- ]`;
851
- const redirectsStr = `export const redirects = [
852
- ${redirects.join(",\n")}
853
- ]`;
854
- return [...imports, routesStr, redirectsStr].join("\n");
629
+ asClosed() {
630
+ return `</${this.tagname}>`;
855
631
  }
856
- function getTitle() {
857
- if (isString(data.config.title)) {
858
- const tokens = md.parseInline(data.config.title, {});
859
- return stringifyMarkdownTokens(tokens);
860
- }
861
- return data.config.title;
862
- }
863
- function generateConfigs() {
864
- const config = {
865
- ...data.config,
866
- remote,
867
- title: getTitle()
868
- };
869
- if (isString(config.info))
870
- config.info = md.render(config.info);
871
- return `export default ${JSON.stringify(config)}`;
872
- }
873
- async function generateGlobalComponents(layer) {
874
- const components = roots.flatMap((root) => {
875
- if (layer === "top") {
876
- return [
877
- join5(root, "global.vue"),
878
- join5(root, "global-top.vue"),
879
- join5(root, "GlobalTop.vue")
880
- ];
881
- } else {
882
- return [
883
- join5(root, "global-bottom.vue"),
884
- join5(root, "GlobalBottom.vue")
885
- ];
886
- }
887
- }).filter((i) => fs4.existsSync(i));
888
- const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
889
- const render = components.map((i, idx) => `h(__n${idx})`).join(",");
890
- return `
891
- ${imports}
892
- import { h } from 'vue'
893
- export default {
894
- render() {
895
- return [${render}]
632
+ };
633
+ var DEFAULTS = {
634
+ plugins: [],
635
+ init: () => {
636
+ },
637
+ defaultLanguageForUnknown: void 0,
638
+ defaultLanguageForUnspecified: void 0,
639
+ defaultLanguage: void 0
640
+ };
641
+ function loadPrismLang(lang) {
642
+ if (!lang)
643
+ return void 0;
644
+ let langObject = Prism.languages[lang];
645
+ if (langObject === void 0) {
646
+ loadLanguages([lang]);
647
+ langObject = Prism.languages[lang];
896
648
  }
649
+ return langObject;
897
650
  }
898
- `;
899
- }
900
- async function generateCustomNavControls() {
901
- const components = roots.flatMap((root) => {
902
- return [
903
- join5(root, "custom-nav-controls.vue"),
904
- join5(root, "CustomNavControls.vue")
905
- ];
906
- }).filter((i) => fs4.existsSync(i));
907
- const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
908
- const render = components.map((i, idx) => `h(__n${idx})`).join(",");
909
- return `
910
- ${imports}
911
- import { h } from 'vue'
912
- export default {
913
- render() {
914
- return [${render}]
651
+ function loadPrismPlugin(name) {
652
+ try {
653
+ require2(`prismjs/plugins/${name}/prism-${name}`);
654
+ } catch (e) {
655
+ throw new Error(`Cannot load Prism plugin "${name}". Please check the spelling.`);
915
656
  }
916
657
  }
917
- `;
658
+ function selectLanguage(options, lang) {
659
+ let langToUse = lang;
660
+ if (langToUse === "" && options.defaultLanguageForUnspecified !== void 0)
661
+ langToUse = options.defaultLanguageForUnspecified;
662
+ let prismLang = loadPrismLang(langToUse);
663
+ if (prismLang === void 0 && options.defaultLanguageForUnknown !== void 0) {
664
+ langToUse = options.defaultLanguageForUnknown;
665
+ prismLang = loadPrismLang(langToUse);
918
666
  }
667
+ return [langToUse, prismLang];
919
668
  }
920
-
921
- // node/plugins/monacoTransform.ts
922
- import { dirname as dirname4, join as join6 } from "node:path";
923
- import fs5 from "node:fs/promises";
924
- import process from "node:process";
925
- import { slash as slash2 } from "@antfu/utils";
926
- import { findDepPkgJsonPath } from "vitefu";
927
- async function getPackageData(pkg) {
928
- const pkgJsonPath = await findDepPkgJsonPath(pkg, process.cwd());
929
- if (!pkgJsonPath)
930
- return;
931
- const pkgJson = JSON.parse(await fs5.readFile(pkgJsonPath, "utf-8"));
932
- const typePath = pkgJson.types || pkgJson.typings;
933
- if (!typePath)
934
- return;
935
- return [dirname4(pkgJsonPath), pkgJson, typePath];
669
+ function highlight(markdownit, options, text, lang) {
670
+ const [langToUse, prismLang] = selectLanguage(options, lang);
671
+ let code = text.trimEnd();
672
+ code = prismLang ? highlightPrism(code, prismLang, langToUse) : markdownit.utils.escapeHtml(code);
673
+ code = code.split(/\r?\n/g).map((line) => `<span class="line">${line}</span>`).join("\n");
674
+ const classAttribute = langToUse ? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"` : "";
675
+ return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`);
936
676
  }
937
- function createMonacoTypesLoader() {
938
- return {
939
- name: "slidev:monaco-types-loader",
940
- resolveId(id) {
941
- if (id.startsWith("/@slidev-monaco-types/"))
942
- return id;
943
- return null;
677
+ function highlightPrism(code, prismLang, langToUse) {
678
+ const openTags = [];
679
+ const parser2 = new htmlparser2.Parser({
680
+ onopentag(tagname, attributes) {
681
+ openTags.push(new Tag(tagname, attributes));
944
682
  },
945
- async load(id) {
946
- const match = id.match(/^\/\@slidev-monaco-types\/(.*)$/);
947
- if (match) {
948
- const pkg = match[1];
949
- const packageData = await getPackageData(pkg) || await getPackageData(`@types/${pkg}`);
950
- if (!packageData)
951
- return;
952
- const [pkgDir, pkgJson, typePath] = packageData;
953
- return [
954
- "import * as monaco from 'monaco-editor'",
955
- `import Type from "${slash2(join6(pkgDir, typePath))}?raw"`,
956
- ...Object.keys(pkgJson.dependencies || {}).map((i) => `import "/@slidev-monaco-types/${i}"`),
957
- `monaco.languages.typescript.typescriptDefaults.addExtraLib(\`declare module "${pkg}" { \${Type} }\`)`
958
- ].join("\n");
959
- }
683
+ onclosetag() {
684
+ openTags.pop();
960
685
  }
961
- };
686
+ });
687
+ code = Prism.highlight(code, prismLang, langToUse);
688
+ code = code.split(/\r?\n/g).map((line) => {
689
+ const prefix = openTags.map((tag) => tag.asOpen()).join("");
690
+ parser2.write(line);
691
+ const postfix = openTags.reverse().map((tag) => tag.asClosed()).join("");
692
+ return prefix + line + postfix;
693
+ }).join("\n");
694
+ parser2.end();
695
+ return code;
696
+ }
697
+ function checkLanguageOption(options, optionName) {
698
+ const language = options[optionName];
699
+ if (language !== void 0 && loadPrismLang(language) === void 0)
700
+ throw new Error(`Bad option ${optionName}: There is no Prism language '${language}'.`);
701
+ }
702
+ function markdownItPrism(markdownit, useroptions) {
703
+ const options = Object.assign({}, DEFAULTS, useroptions);
704
+ checkLanguageOption(options, "defaultLanguage");
705
+ checkLanguageOption(options, "defaultLanguageForUnknown");
706
+ checkLanguageOption(options, "defaultLanguageForUnspecified");
707
+ options.defaultLanguageForUnknown = options.defaultLanguageForUnknown || options.defaultLanguage;
708
+ options.defaultLanguageForUnspecified = options.defaultLanguageForUnspecified || options.defaultLanguage;
709
+ options.plugins.forEach(loadPrismPlugin);
710
+ options.init(Prism);
711
+ markdownit.options.highlight = (text, lang) => highlight(markdownit, options, text, lang);
962
712
  }
963
713
 
964
- // node/plugins/setupClient.ts
965
- import { existsSync as existsSync2 } from "node:fs";
966
- import { join as join7, resolve as resolve2 } from "node:path";
967
- import { slash as slash3, uniq as uniq4 } from "@antfu/utils";
968
- function createClientSetupPlugin({ clientRoot, themeRoots, addonRoots, userRoot }) {
969
- const setupEntry = slash3(resolve2(clientRoot, "setup"));
970
- return {
971
- name: "slidev:setup",
972
- enforce: "pre",
973
- async transform(code, id) {
974
- if (id.startsWith(setupEntry)) {
975
- let getInjections2 = function(isAwait = false, isChained = false) {
976
- return injections.join("\n").replace(/:AWAIT:/g, isAwait ? "await " : "").replace(/(,\s*)?:LAST:/g, isChained ? "$1injection_return" : "");
977
- };
978
- var getInjections = getInjections2;
979
- const name = id.slice(setupEntry.length + 1).replace(/\?.*$/, "");
980
- const imports = [];
981
- const injections = [];
982
- const setups = uniq4([
983
- ...themeRoots,
984
- ...addonRoots,
985
- userRoot
986
- ]).map((i) => join7(i, "setup", name));
987
- setups.forEach((path2, idx) => {
988
- if (!existsSync2(path2))
989
- return;
990
- imports.push(`import __n${idx} from '${toAtFS(path2)}'`);
991
- let fn = `:AWAIT:__n${idx}`;
992
- if (/\binjection_return\b/g.test(code))
993
- fn = `injection_return = ${fn}`;
994
- if (/\binjection_arg\b/g.test(code)) {
995
- fn += "(";
996
- const matches = Array.from(code.matchAll(/\binjection_arg(_\d+)?\b/g));
997
- const dedupedMatches = Array.from(new Set(matches.map((m) => m[0])));
998
- fn += dedupedMatches.join(", ");
999
- fn += ", :LAST:)";
1000
- } else {
1001
- fn += "(:LAST:)";
1002
- }
1003
- injections.push(
1004
- `// ${path2}`,
1005
- fn
714
+ // node/plugins/transformSnippet.ts
715
+ import path from "node:path";
716
+ import fs3 from "fs-extra";
717
+ function dedent(text) {
718
+ const lines = text.split("\n");
719
+ const minIndentLength = lines.reduce((acc, line) => {
720
+ for (let i = 0; i < line.length; i++) {
721
+ if (line[i] !== " " && line[i] !== " ")
722
+ return Math.min(i, acc);
723
+ }
724
+ return acc;
725
+ }, Number.POSITIVE_INFINITY);
726
+ if (minIndentLength < Number.POSITIVE_INFINITY)
727
+ return lines.map((x) => x.slice(minIndentLength)).join("\n");
728
+ return text;
729
+ }
730
+ function testLine(line, regexp, regionName, end = false) {
731
+ const [full, tag, name] = regexp.exec(line.trim()) || [];
732
+ return full && tag && name === regionName && tag.match(end ? /^[Ee]nd ?[rR]egion$/ : /^[rR]egion$/);
733
+ }
734
+ function findRegion(lines, regionName) {
735
+ const regionRegexps = [
736
+ /^\/\/ ?#?((?:end)?region) ([\w*-]+)$/,
737
+ // javascript, typescript, java
738
+ /^\/\* ?#((?:end)?region) ([\w*-]+) ?\*\/$/,
739
+ // css, less, scss
740
+ /^#pragma ((?:end)?region) ([\w*-]+)$/,
741
+ // C, C++
742
+ /^<!-- #?((?:end)?region) ([\w*-]+) -->$/,
743
+ // HTML, markdown
744
+ /^#((?:End )Region) ([\w*-]+)$/,
745
+ // Visual Basic
746
+ /^::#((?:end)region) ([\w*-]+)$/,
747
+ // Bat
748
+ /^# ?((?:end)?region) ([\w*-]+)$/
749
+ // C#, PHP, Powershell, Python, perl & misc
750
+ ];
751
+ let regexp = null;
752
+ let start = -1;
753
+ for (const [lineId, line] of lines.entries()) {
754
+ if (regexp === null) {
755
+ for (const reg of regionRegexps) {
756
+ if (testLine(line, reg, regionName)) {
757
+ start = lineId + 1;
758
+ regexp = reg;
759
+ break;
760
+ }
761
+ }
762
+ } else if (testLine(line, regexp, regionName, true)) {
763
+ return { start, end: lineId, regexp };
764
+ }
765
+ }
766
+ return null;
767
+ }
768
+ function transformSnippet(md2, options, id) {
769
+ const slideId = id.match(/(\d+)\.md$/)?.[1];
770
+ if (!slideId)
771
+ return md2;
772
+ const data = options.data;
773
+ const slideInfo = data.slides[+slideId - 1];
774
+ const dir = path.dirname(slideInfo.source?.filepath ?? options.entry ?? options.userRoot);
775
+ return md2.replace(
776
+ /^<<< *(.+?)(#[\w-]+)? *(?: (\S+?))? *(\{.*)?$/mg,
777
+ (full, filepath = "", regionName = "", lang = "", meta = "") => {
778
+ const firstLine = `\`\`\`${lang || path.extname(filepath).slice(1)} ${meta}`;
779
+ const src = /^\@[\/]/.test(filepath) ? path.resolve(options.userRoot, filepath.slice(2)) : path.resolve(dir, filepath);
780
+ data.watchFiles.push(src);
781
+ const isAFile = fs3.statSync(src).isFile();
782
+ if (!fs3.existsSync(src) || !isAFile) {
783
+ throw new Error(isAFile ? `Code snippet path not found: ${src}` : `Invalid code snippet option`);
784
+ }
785
+ let content = fs3.readFileSync(src, "utf8");
786
+ slideInfo.snippetsUsed ??= {};
787
+ slideInfo.snippetsUsed[src] = content;
788
+ if (regionName) {
789
+ const lines = content.split(/\r?\n/);
790
+ const region = findRegion(lines, regionName.slice(1));
791
+ if (region) {
792
+ content = dedent(
793
+ lines.slice(region.start, region.end).filter((line) => !region.regexp.test(line.trim())).join("\n")
1006
794
  );
1007
- });
1008
- code = code.replace("/* __imports__ */", imports.join("\n"));
1009
- code = code.replace("/* __injections__ */", getInjections2());
1010
- code = code.replace("/* __async_injections__ */", getInjections2(true));
1011
- code = code.replace("/* __chained_injections__ */", getInjections2(false, true));
1012
- code = code.replace("/* __chained_async_injections__ */", getInjections2(true, true));
1013
- return code;
795
+ }
1014
796
  }
1015
- return null;
797
+ return `${firstLine}
798
+ ${content}
799
+ \`\`\``;
1016
800
  }
1017
- };
801
+ );
1018
802
  }
1019
803
 
1020
804
  // node/plugins/markdown.ts
1021
- import fs7 from "node:fs/promises";
1022
- import Markdown2 from "unplugin-vue-markdown/vite";
1023
- import * as base64 from "js-base64";
1024
- import { slash as slash4 } from "@antfu/utils";
1025
- import mila2 from "markdown-it-link-attributes";
1026
- import mif from "markdown-it-footnote";
1027
-
1028
- // ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=tuyuxytl56b2vxulpkzt2wf4o4_markdown-it@14.0.0/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/image-size/specialCharacters.js
1029
- var SpecialCharacters;
1030
- (function(SpecialCharacters2) {
1031
- SpecialCharacters2[SpecialCharacters2["EXCLAMATION_MARK"] = 33] = "EXCLAMATION_MARK";
1032
- SpecialCharacters2[SpecialCharacters2["OPENING_BRACKET"] = 91] = "OPENING_BRACKET";
1033
- SpecialCharacters2[SpecialCharacters2["OPENING_PARENTHESIS"] = 40] = "OPENING_PARENTHESIS";
1034
- SpecialCharacters2[SpecialCharacters2["WHITESPACE"] = 32] = "WHITESPACE";
1035
- SpecialCharacters2[SpecialCharacters2["NEW_LINE"] = 10] = "NEW_LINE";
1036
- SpecialCharacters2[SpecialCharacters2["EQUALS"] = 61] = "EQUALS";
1037
- SpecialCharacters2[SpecialCharacters2["LOWER_CASE_X"] = 120] = "LOWER_CASE_X";
1038
- SpecialCharacters2[SpecialCharacters2["NUMBER_ZERO"] = 48] = "NUMBER_ZERO";
1039
- SpecialCharacters2[SpecialCharacters2["NUMBER_NINE"] = 57] = "NUMBER_NINE";
1040
- SpecialCharacters2[SpecialCharacters2["PERCENTAGE"] = 37] = "PERCENTAGE";
1041
- SpecialCharacters2[SpecialCharacters2["CLOSING_PARENTHESIS"] = 41] = "CLOSING_PARENTHESIS";
1042
- })(SpecialCharacters || (SpecialCharacters = {}));
1043
-
1044
- // ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=tuyuxytl56b2vxulpkzt2wf4o4_markdown-it@14.0.0/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/task-lists/index.js
1045
- import Token from "markdown-it/lib/token.mjs";
1046
- var checkboxRegex = /^ *\[([\sx])] /i;
1047
- function taskLists(md2, options = { enabled: false, label: false, lineNumber: false }) {
1048
- md2.core.ruler.after("inline", "task-lists", (state) => processToken(state, options));
1049
- md2.renderer.rules.taskListItemCheckbox = (tokens) => {
1050
- const token = tokens[0];
1051
- const checkedAttribute = token.attrGet("checked") ? 'checked="" ' : "";
1052
- const disabledAttribute = token.attrGet("disabled") ? 'disabled="" ' : "";
1053
- const line = token.attrGet("line");
1054
- const idAttribute = `id="${token.attrGet("id")}" `;
1055
- const dataLineAttribute = line && options.lineNumber ? `data-line="${line}" ` : "";
1056
- return `<input class="task-list-item-checkbox" type="checkbox" ${checkedAttribute}${disabledAttribute}${dataLineAttribute}${idAttribute}/>`;
1057
- };
1058
- md2.renderer.rules.taskListItemLabel_close = () => {
1059
- return "</label>";
1060
- };
1061
- md2.renderer.rules.taskListItemLabel_open = (tokens) => {
1062
- const token = tokens[0];
1063
- const id = token.attrGet("id");
1064
- return `<label for="${id}">`;
1065
- };
1066
- }
1067
- function processToken(state, options) {
1068
- const allTokens = state.tokens;
1069
- for (let i = 2; i < allTokens.length; i++) {
1070
- if (!isTodoItem(allTokens, i)) {
1071
- continue;
1072
- }
1073
- todoify(allTokens[i], options);
1074
- allTokens[i - 2].attrJoin("class", `task-list-item ${options.enabled ? " enabled" : ""}`);
1075
- const parentToken = findParentToken(allTokens, i - 2);
1076
- if (parentToken) {
1077
- const classes = parentToken.attrGet("class") ?? "";
1078
- if (!classes.match(/(^| )contains-task-list/)) {
1079
- parentToken.attrJoin("class", "contains-task-list");
805
+ var shiki;
806
+ var shikiOptions;
807
+ async function createMarkdownPlugin(options, { markdown: mdOptions }) {
808
+ const { data: { config }, roots, mode, entry, clientRoot } = options;
809
+ const setups = [];
810
+ const entryPath = slash(entry);
811
+ if (config.highlighter === "shiki") {
812
+ const [
813
+ options2,
814
+ { getHighlighter, bundledLanguages },
815
+ markdownItShiki,
816
+ transformerTwoslash
817
+ ] = await Promise.all([
818
+ loadShikiSetups(clientRoot, roots),
819
+ import("shiki").then(({ getHighlighter: getHighlighter2, bundledLanguages: bundledLanguages2 }) => ({ bundledLanguages: bundledLanguages2, getHighlighter: getHighlighter2 })),
820
+ import("@shikijs/markdown-it/core").then(({ fromHighlighter }) => fromHighlighter),
821
+ import("@shikijs/vitepress-twoslash").then(({ transformerTwoslash: transformerTwoslash2 }) => transformerTwoslash2)
822
+ ]);
823
+ shikiOptions = options2;
824
+ shiki = await getHighlighter({
825
+ ...options2,
826
+ langs: options2.langs ?? Object.keys(bundledLanguages),
827
+ themes: "themes" in options2 ? Object.values(options2.themes) : [options2.theme]
828
+ });
829
+ const transformers = [
830
+ ...options2.transformers || [],
831
+ transformerTwoslash({
832
+ explicitTrigger: true,
833
+ twoslashOptions: {
834
+ handbookOptions: {
835
+ noErrorValidation: true
836
+ }
837
+ }
838
+ }),
839
+ {
840
+ pre(pre) {
841
+ this.addClassToHast(pre, "slidev-code");
842
+ delete pre.properties.tabindex;
843
+ },
844
+ postprocess(code) {
845
+ return escapeVueInCode(code);
846
+ }
1080
847
  }
1081
- }
1082
- }
1083
- return false;
1084
- }
1085
- function findParentToken(tokens, index) {
1086
- const targetLevel = tokens[index].level - 1;
1087
- for (let currentTokenIndex = index - 1; currentTokenIndex >= 0; currentTokenIndex--) {
1088
- if (tokens[currentTokenIndex].level === targetLevel) {
1089
- return tokens[currentTokenIndex];
1090
- }
1091
- }
1092
- return void 0;
1093
- }
1094
- function isTodoItem(tokens, index) {
1095
- return isInline(tokens[index]) && isParagraph(tokens[index - 1]) && isListItem(tokens[index - 2]) && startsWithTodoMarkdown(tokens[index]);
1096
- }
1097
- function todoify(token, options) {
1098
- if (token.children == null) {
1099
- return;
1100
- }
1101
- const id = generateIdForToken(token);
1102
- token.children.splice(0, 0, createCheckboxToken(token, options.enabled, id));
1103
- token.children[1].content = token.children[1].content.replace(checkboxRegex, "");
1104
- if (options.label) {
1105
- token.children.splice(1, 0, createLabelBeginToken(id));
1106
- token.children.push(createLabelEndToken());
1107
- }
1108
- }
1109
- function generateIdForToken(token) {
1110
- if (token.map) {
1111
- return `task-item-${token.map[0]}`;
848
+ ];
849
+ const plugin = markdownItShiki(shiki, {
850
+ ...options2,
851
+ transformers
852
+ });
853
+ setups.push((md2) => md2.use(plugin));
1112
854
  } else {
1113
- return `task-item-${Math.ceil(Math.random() * (1e4 * 1e3) - 1e3)}`;
1114
- }
1115
- }
1116
- function createCheckboxToken(token, enabled, id) {
1117
- const checkbox = new Token("taskListItemCheckbox", "", 0);
1118
- if (!enabled) {
1119
- checkbox.attrSet("disabled", "true");
1120
- }
1121
- if (token.map) {
1122
- checkbox.attrSet("line", token.map[0].toString());
1123
- }
1124
- checkbox.attrSet("id", id);
1125
- const checkboxRegexResult = checkboxRegex.exec(token.content);
1126
- const isChecked = checkboxRegexResult?.[1].toLowerCase() === "x";
1127
- if (isChecked) {
1128
- checkbox.attrSet("checked", "true");
855
+ setups.push((md2) => md2.use(markdownItPrism));
1129
856
  }
1130
- return checkbox;
857
+ if (config.mdc)
858
+ setups.push((md2) => md2.use(Mdc));
859
+ const KatexOptions = await loadSetups(options.clientRoot, roots, "katex.ts", {}, { strict: false }, false);
860
+ return Markdown({
861
+ include: [/\.md$/],
862
+ wrapperClasses: "",
863
+ headEnabled: false,
864
+ frontmatter: false,
865
+ escapeCodeTagInterpolation: false,
866
+ markdownItOptions: {
867
+ quotes: `""''`,
868
+ html: true,
869
+ xhtmlOut: true,
870
+ linkify: true,
871
+ ...mdOptions?.markdownItOptions
872
+ },
873
+ ...mdOptions,
874
+ markdownItSetup(md2) {
875
+ md2.use(mila, {
876
+ attrs: {
877
+ target: "_blank",
878
+ rel: "noopener"
879
+ }
880
+ });
881
+ md2.use(mif);
882
+ md2.use(taskLists, { enabled: true, lineNumber: true, label: true });
883
+ md2.use(math_plugin, KatexOptions);
884
+ setups.forEach((i) => i(md2));
885
+ mdOptions?.markdownItSetup?.(md2);
886
+ },
887
+ transforms: {
888
+ before(code, id) {
889
+ if (id === entryPath)
890
+ return "";
891
+ const monaco = config.monaco === true || config.monaco === mode ? transformMarkdownMonaco : truncateMancoMark;
892
+ if (config.highlighter === "shiki")
893
+ code = transformMagicMove(code, shiki, shikiOptions);
894
+ code = transformSlotSugar(code);
895
+ code = transformSnippet(code, options, id);
896
+ code = transformMermaid(code);
897
+ code = transformPlantUml(code, config.plantUmlServer);
898
+ code = monaco(code);
899
+ code = transformHighlighter(code);
900
+ code = transformPageCSS(code, id);
901
+ code = transformKaTex(code);
902
+ return code;
903
+ }
904
+ }
905
+ });
1131
906
  }
1132
- function createLabelBeginToken(id) {
1133
- const labelBeginToken = new Token("taskListItemLabel_open", "", 1);
1134
- labelBeginToken.attrSet("id", id);
1135
- return labelBeginToken;
907
+ function transformKaTex(md2) {
908
+ return md2.replace(
909
+ /^\$\$(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?\s*?)?\n([\s\S]+?)^\$\$/mg,
910
+ (full, rangeStr = "", options = "", code) => {
911
+ const ranges = !rangeStr.trim() ? [] : rangeStr.trim().split(/\|/g).map((i) => i.trim());
912
+ code = code.trimEnd();
913
+ options = options.trim() || "{}";
914
+ return `<KaTexBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
915
+
916
+ $$
917
+ ${code}
918
+ $$
919
+ </KaTexBlockWrapper>
920
+ `;
921
+ }
922
+ );
1136
923
  }
1137
- function createLabelEndToken() {
1138
- return new Token("taskListItemLabel_close", "", -1);
924
+ function transformMarkdownMonaco(md2) {
925
+ md2 = md2.replace(
926
+ /^```(\w+?)\s*{monaco-diff}\s*?({.*?})?\s*?\n([\s\S]+?)^~~~\s*?\n([\s\S]+?)^```/mg,
927
+ (full, lang = "ts", options = "{}", code, diff) => {
928
+ lang = lang.trim();
929
+ options = options.trim() || "{}";
930
+ const encoded = lz.compressToBase64(code);
931
+ const encodedDiff = lz.compressToBase64(diff);
932
+ return `<Monaco code-lz="${encoded}" diff-lz="${encodedDiff}" lang="${lang}" v-bind="${options}" />`;
933
+ }
934
+ );
935
+ md2 = md2.replace(
936
+ /^```(\w+?)\s*{monaco}\s*?({.*?})?\s*?\n([\s\S]+?)^```/mg,
937
+ (full, lang = "ts", options = "{}", code) => {
938
+ lang = lang.trim();
939
+ options = options.trim() || "{}";
940
+ const encoded = lz.compressToBase64(code);
941
+ return `<Monaco code-lz="${encoded}" lang="${lang}" v-bind="${options}" />`;
942
+ }
943
+ );
944
+ return md2;
1139
945
  }
1140
- function isInline(token) {
1141
- return token.type === "inline";
946
+ function scanMonacoModules(md2) {
947
+ const typeModules = /* @__PURE__ */ new Set();
948
+ md2.replace(
949
+ /^```(\w+?)\s*{monaco([\w:,-]*)}[\s\n]*([\s\S]+?)^```/mg,
950
+ (full, lang = "ts", options, code) => {
951
+ options = options || "";
952
+ lang = lang.trim();
953
+ if (lang === "ts" || lang === "typescript") {
954
+ Array.from(code.matchAll(/\s+from\s+(["'])([\/\w@-]+)\1/g)).map((i) => i[2]).filter(isTruthy).map((i) => typeModules.add(i));
955
+ }
956
+ return "";
957
+ }
958
+ );
959
+ return Array.from(typeModules);
1142
960
  }
1143
- function isParagraph(token) {
1144
- return token.type === "paragraph_open";
961
+ function truncateMancoMark(md2) {
962
+ return md2.replace(/{monaco.*?}/g, "");
1145
963
  }
1146
- function isListItem(token) {
1147
- return token.type === "list_item_open";
964
+ function transformSlotSugar(md2) {
965
+ const lines = md2.split(/\r?\n/g);
966
+ let prevSlot = false;
967
+ const { isLineInsideCodeblocks } = getCodeBlocks(md2);
968
+ lines.forEach((line, idx) => {
969
+ if (isLineInsideCodeblocks(idx))
970
+ return;
971
+ const match = line.trimEnd().match(/^::\s*([\w\.\-\:]+)\s*::$/);
972
+ if (match) {
973
+ lines[idx] = `${prevSlot ? "\n\n</template>\n" : "\n"}<template v-slot:${match[1]}="slotProps">
974
+ `;
975
+ prevSlot = true;
976
+ }
977
+ });
978
+ if (prevSlot)
979
+ lines[lines.length - 1] += "\n\n</template>";
980
+ return lines.join("\n");
1148
981
  }
1149
- function startsWithTodoMarkdown(token) {
1150
- return checkboxRegex.test(token.content);
982
+ var reMagicMoveBlock = /^````(?:md|markdown) magic-move(?:[ ]*?({.*?})?([^\n]*?))?\n([\s\S]+?)^````$/mg;
983
+ var reCodeBlock = /^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```$/mg;
984
+ function transformMagicMove(md2, shiki2, shikiOptions2) {
985
+ return md2.replace(
986
+ reMagicMoveBlock,
987
+ (full, _options = "", _attrs = "", body) => {
988
+ if (!shiki2 || !shikiOptions2)
989
+ throw new Error("Shiki is required for Magic Move. You may need to set `highlighter: shiki` in your Slidev config.");
990
+ const matches = Array.from(body.matchAll(reCodeBlock));
991
+ if (!matches.length)
992
+ throw new Error("Magic Move block must contain at least one code block");
993
+ const langs = new Set(matches.map((i) => i[1]));
994
+ if (langs.size > 1)
995
+ throw new Error(`Magic Move block must contain code blocks with the same language, got ${Array.from(langs).join(", ")}`);
996
+ const lang = Array.from(langs)[0];
997
+ const magicMove = createMagicMoveMachine(
998
+ (code) => codeToKeyedTokens(shiki2, code, {
999
+ ...shikiOptions2,
1000
+ lang
1001
+ })
1002
+ );
1003
+ const steps = matches.map((i) => magicMove.commit((i[5] || "").trimEnd()));
1004
+ const compressed = lz.compressToBase64(JSON.stringify(steps));
1005
+ return `<ShikiMagicMove steps-lz="${compressed}" />`;
1006
+ }
1007
+ );
1151
1008
  }
1009
+ function transformHighlighter(md2) {
1010
+ return md2.replace(
1011
+ reCodeBlock,
1012
+ (full, lang = "", rangeStr = "", options = "", attrs = "", code) => {
1013
+ const ranges = !rangeStr.trim() ? [] : rangeStr.trim().split(/\|/g).map((i) => i.trim());
1014
+ code = code.trimEnd();
1015
+ options = options.trim() || "{}";
1016
+ return `
1017
+ <CodeBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
1152
1018
 
1153
- // ../../node_modules/.pnpm/@hedgedoc+markdown-it-plugins@2.1.4_patch_hash=tuyuxytl56b2vxulpkzt2wf4o4_markdown-it@14.0.0/node_modules/@hedgedoc/markdown-it-plugins/dist/esm/toc/plugin.js
1154
- import { Optional } from "@mrdrogdrog/optional";
1155
-
1156
- // node/plugins/markdown.ts
1157
- import { encode as encode2 } from "plantuml-encoder";
1158
- import Mdc from "markdown-it-mdc";
1019
+ \`\`\`${lang}${attrs}
1020
+ ${code}
1021
+ \`\`\`
1159
1022
 
1160
- // node/plugins/markdown-it-katex.ts
1161
- import katex from "katex";
1162
- function isValidDelim(state, pos) {
1163
- const max = state.posMax;
1164
- let can_open = true;
1165
- let can_close = true;
1166
- const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
1167
- const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
1168
- if (prevChar === 32 || prevChar === 9 || /* \t */
1169
- nextChar >= 48 && nextChar <= 57)
1170
- can_close = false;
1171
- if (nextChar === 32 || nextChar === 9)
1172
- can_open = false;
1023
+ </CodeBlockWrapper>`;
1024
+ }
1025
+ );
1026
+ }
1027
+ function getCodeBlocks(md2) {
1028
+ const codeblocks = Array.from(md2.matchAll(/^```[\s\S]*?^```/mg)).map((m) => {
1029
+ const start = m.index;
1030
+ const end = m.index + m[0].length;
1031
+ const startLine = md2.slice(0, start).match(/\n/g)?.length || 0;
1032
+ const endLine = md2.slice(0, end).match(/\n/g)?.length || 0;
1033
+ return [start, end, startLine, endLine];
1034
+ });
1173
1035
  return {
1174
- can_open,
1175
- can_close
1036
+ codeblocks,
1037
+ isInsideCodeblocks(idx) {
1038
+ return codeblocks.some(([s, e]) => s <= idx && idx <= e);
1039
+ },
1040
+ isLineInsideCodeblocks(line) {
1041
+ return codeblocks.some(([, , s, e]) => s <= line && line <= e);
1042
+ }
1176
1043
  };
1177
1044
  }
1178
- function math_inline(state, silent) {
1179
- let match, token, res, pos;
1180
- if (state.src[state.pos] !== "$")
1181
- return false;
1182
- res = isValidDelim(state, state.pos);
1183
- if (!res.can_open) {
1184
- if (!silent)
1185
- state.pending += "$";
1186
- state.pos += 1;
1187
- return true;
1188
- }
1189
- const start = state.pos + 1;
1190
- match = start;
1191
- while ((match = state.src.indexOf("$", match)) !== -1) {
1192
- pos = match - 1;
1193
- while (state.src[pos] === "\\")
1194
- pos -= 1;
1195
- if ((match - pos) % 2 === 1)
1196
- break;
1197
- match += 1;
1198
- }
1199
- if (match === -1) {
1200
- if (!silent)
1201
- state.pending += "$";
1202
- state.pos = start;
1203
- return true;
1204
- }
1205
- if (match - start === 0) {
1206
- if (!silent)
1207
- state.pending += "$$";
1208
- state.pos = start + 1;
1209
- return true;
1210
- }
1211
- res = isValidDelim(state, match);
1212
- if (!res.can_close) {
1213
- if (!silent)
1214
- state.pending += "$";
1215
- state.pos = start;
1216
- return true;
1217
- }
1218
- if (!silent) {
1219
- token = state.push("math_inline", "math", 0);
1220
- token.markup = "$";
1221
- token.content = state.src.slice(start, match);
1222
- }
1223
- state.pos = match + 1;
1224
- return true;
1225
- }
1226
- function math_block(state, start, end, silent) {
1227
- let firstLine;
1228
- let lastLine;
1229
- let next;
1230
- let lastPos;
1231
- let found = false;
1232
- let pos = state.bMarks[start] + state.tShift[start];
1233
- let max = state.eMarks[start];
1234
- if (pos + 2 > max)
1235
- return false;
1236
- if (state.src.slice(pos, pos + 2) !== "$$")
1237
- return false;
1238
- pos += 2;
1239
- firstLine = state.src.slice(pos, max);
1240
- if (silent)
1241
- return true;
1242
- if (firstLine.trim().slice(-2) === "$$") {
1243
- firstLine = firstLine.trim().slice(0, -2);
1244
- found = true;
1245
- }
1246
- for (next = start; !found; ) {
1247
- next++;
1248
- if (next >= end)
1249
- break;
1250
- pos = state.bMarks[next] + state.tShift[next];
1251
- max = state.eMarks[next];
1252
- if (pos < max && state.tShift[next] < state.blkIndent) {
1253
- break;
1254
- }
1255
- if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
1256
- lastPos = state.src.slice(0, max).lastIndexOf("$$");
1257
- lastLine = state.src.slice(pos, lastPos);
1258
- found = true;
1045
+ function transformPageCSS(md2, id) {
1046
+ const page = id.match(/(\d+)\.md$/)?.[1];
1047
+ if (!page)
1048
+ return md2;
1049
+ const { isInsideCodeblocks } = getCodeBlocks(md2);
1050
+ const result = md2.replace(
1051
+ /(\n<style[^>]*?>)([\s\S]+?)(<\/style>)/g,
1052
+ (full, start, css, end, index) => {
1053
+ if (index < 0 || isInsideCodeblocks(index))
1054
+ return full;
1055
+ if (!start.includes("scoped"))
1056
+ start = start.replace("<style", "<style scoped");
1057
+ return `${start}
1058
+ ${css}${end}`;
1259
1059
  }
1260
- }
1261
- state.line = next + 1;
1262
- const token = state.push("math_block", "math", 0);
1263
- token.block = true;
1264
- token.content = (firstLine && firstLine.trim() ? `${firstLine}
1265
- ` : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
1266
- token.map = [start, state.line];
1267
- token.markup = "$$";
1268
- return true;
1060
+ );
1061
+ return result;
1269
1062
  }
1270
- function math_plugin(md2, options) {
1271
- options = options || {};
1272
- const katexInline = function(latex) {
1273
- options.displayMode = false;
1274
- try {
1275
- return katex.renderToString(latex, options);
1276
- } catch (error) {
1277
- if (options.throwOnError)
1278
- console.warn(error);
1279
- return latex;
1280
- }
1281
- };
1282
- const inlineRenderer = function(tokens, idx) {
1283
- return katexInline(tokens[idx].content);
1284
- };
1285
- const katexBlock = function(latex) {
1286
- options.displayMode = true;
1287
- try {
1288
- return `<p>${katex.renderToString(latex, options)}</p>`;
1289
- } catch (error) {
1290
- if (options.throwOnError)
1291
- console.warn(error);
1292
- return latex;
1293
- }
1294
- };
1295
- const blockRenderer = function(tokens, idx) {
1296
- return `${katexBlock(tokens[idx].content)}
1297
- `;
1298
- };
1299
- md2.inline.ruler.after("escape", "math_inline", math_inline);
1300
- md2.block.ruler.after("blockquote", "math_block", math_block, {
1301
- alt: ["paragraph", "reference", "blockquote", "list"]
1063
+ function transformMermaid(md2) {
1064
+ return md2.replace(/^```mermaid\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", code = "") => {
1065
+ code = code.trim();
1066
+ options = options.trim() || "{}";
1067
+ const encoded = lz.compressToBase64(code);
1068
+ return `<Mermaid code-lz="${encoded}" v-bind="${options}" />`;
1302
1069
  });
1303
- md2.renderer.rules.math_inline = inlineRenderer;
1304
- md2.renderer.rules.math_block = blockRenderer;
1305
1070
  }
1306
-
1307
- // node/plugins/markdown-it-prism.ts
1308
- import { createRequire } from "node:module";
1309
- import Prism from "prismjs";
1310
- import loadLanguages from "prismjs/components/index.js";
1311
- import * as htmlparser2 from "htmlparser2";
1312
- var require2 = createRequire(import.meta.url);
1313
- var Tag = class {
1314
- tagname;
1315
- attributes;
1316
- constructor(tagname, attributes) {
1317
- this.tagname = tagname;
1318
- this.attributes = attributes;
1319
- }
1320
- asOpen() {
1321
- return `<${this.tagname} ${Object.entries(this.attributes).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
1322
- }
1323
- asClosed() {
1324
- return `</${this.tagname}>`;
1071
+ function transformPlantUml(md2, server) {
1072
+ return md2.replace(/^```plantuml\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", content = "") => {
1073
+ const code = encodePlantUml(content.trim());
1074
+ options = options.trim() || "{}";
1075
+ return `<PlantUml :code="'${code}'" :server="'${server}'" v-bind="${options}" />`;
1076
+ });
1077
+ }
1078
+ function escapeVueInCode(md2) {
1079
+ return md2.replace(/{{/g, "&lbrace;&lbrace;");
1080
+ }
1081
+ async function loadShikiSetups(clientRoot, roots) {
1082
+ const result = await loadSetups(
1083
+ clientRoot,
1084
+ roots,
1085
+ "shiki.ts",
1086
+ {
1087
+ /** @deprecated */
1088
+ async loadTheme(path2) {
1089
+ 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.");
1090
+ return JSON.parse(await fs4.readFile(path2, "utf-8"));
1091
+ }
1092
+ },
1093
+ {},
1094
+ false
1095
+ );
1096
+ if ("theme" in result && "themes" in result)
1097
+ delete result.theme;
1098
+ if (result.theme && typeof result.theme !== "string" && !result.theme.name && !result.theme.tokenColors) {
1099
+ result.themes = result.theme;
1100
+ delete result.theme;
1325
1101
  }
1326
- };
1327
- var DEFAULTS = {
1328
- plugins: [],
1329
- init: () => {
1330
- },
1331
- defaultLanguageForUnknown: void 0,
1332
- defaultLanguageForUnspecified: void 0,
1333
- defaultLanguage: void 0
1334
- };
1335
- function loadPrismLang(lang) {
1336
- if (!lang)
1337
- return void 0;
1338
- let langObject = Prism.languages[lang];
1339
- if (langObject === void 0) {
1340
- loadLanguages([lang]);
1341
- langObject = Prism.languages[lang];
1102
+ if (!result.theme && !result.themes) {
1103
+ result.themes = {
1104
+ dark: "vitesse-dark",
1105
+ light: "vitesse-light"
1106
+ };
1342
1107
  }
1343
- return langObject;
1108
+ if (result.themes)
1109
+ result.defaultColor = false;
1110
+ return result;
1344
1111
  }
1345
- function loadPrismPlugin(name) {
1346
- try {
1347
- require2(`prismjs/plugins/${name}/prism-${name}`);
1348
- } catch (e) {
1349
- throw new Error(`Cannot load Prism plugin "${name}". Please check the spelling.`);
1350
- }
1112
+
1113
+ // node/plugins/loaders.ts
1114
+ var regexId = /^\/\@slidev\/slide\/(\d+)\.(md|json)(?:\?import)?$/;
1115
+ var regexIdQuery = /(\d+?)\.(md|json|frontmatter)$/;
1116
+ var templateInjectionMarker = "/* @slidev-injection */";
1117
+ var templateImportContextUtils = `import {
1118
+ useSlideContext,
1119
+ provideFrontmatter as _provideFrontmatter,
1120
+ frontmatterToProps as _frontmatterToProps,
1121
+ } from "@slidev/client/context.ts"`.replace(/\n\s*/g, " ");
1122
+ var templateInitContext = `const { $slidev, $nav, $clicksContext, $clicks, $page, $renderContext, $frontmatter } = useSlideContext()`;
1123
+ function getBodyJson(req) {
1124
+ return new Promise((resolve5, reject) => {
1125
+ let body = "";
1126
+ req.on("data", (chunk) => body += chunk);
1127
+ req.on("error", reject);
1128
+ req.on("end", () => {
1129
+ try {
1130
+ resolve5(JSON.parse(body) || {});
1131
+ } catch (e) {
1132
+ reject(e);
1133
+ }
1134
+ });
1135
+ });
1351
1136
  }
1352
- function selectLanguage(options, lang) {
1353
- let langToUse = lang;
1354
- if (langToUse === "" && options.defaultLanguageForUnspecified !== void 0)
1355
- langToUse = options.defaultLanguageForUnspecified;
1356
- let prismLang = loadPrismLang(langToUse);
1357
- if (prismLang === void 0 && options.defaultLanguageForUnknown !== void 0) {
1358
- langToUse = options.defaultLanguageForUnknown;
1359
- prismLang = loadPrismLang(langToUse);
1137
+ var md = Markdown2({ html: true });
1138
+ md.use(mila2, {
1139
+ attrs: {
1140
+ target: "_blank",
1141
+ rel: "noopener"
1360
1142
  }
1361
- return [langToUse, prismLang];
1143
+ });
1144
+ function renderNote(text = "") {
1145
+ let clickCount = 0;
1146
+ const html = md.render(
1147
+ text.replace(/\[click(?::(\d+))?\]/gi, (_, count = 1) => {
1148
+ clickCount += Number(count);
1149
+ return `<span class="slidev-note-click-mark" data-clicks="${clickCount}"></span>`;
1150
+ })
1151
+ );
1152
+ return html;
1362
1153
  }
1363
- function highlight(markdownit, options, text, lang) {
1364
- const [langToUse, prismLang] = selectLanguage(options, lang);
1365
- let code = text.trimEnd();
1366
- code = prismLang ? highlightPrism(code, prismLang, langToUse) : markdownit.utils.escapeHtml(code);
1367
- code = code.split(/\r?\n/g).map((line) => `<span class="line">${line}</span>`).join("\n");
1368
- const classAttribute = langToUse ? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"` : "";
1369
- return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`);
1370
- }
1371
- function highlightPrism(code, prismLang, langToUse) {
1372
- const openTags = [];
1373
- const parser2 = new htmlparser2.Parser({
1374
- onopentag(tagname, attributes) {
1375
- openTags.push(new Tag(tagname, attributes));
1376
- },
1377
- onclosetag() {
1378
- openTags.pop();
1379
- }
1380
- });
1381
- code = Prism.highlight(code, prismLang, langToUse);
1382
- code = code.split(/\r?\n/g).map((line) => {
1383
- const prefix = openTags.map((tag) => tag.asOpen()).join("");
1384
- parser2.write(line);
1385
- const postfix = openTags.reverse().map((tag) => tag.asClosed()).join("");
1386
- return prefix + line + postfix;
1387
- }).join("\n");
1388
- parser2.end();
1389
- return code;
1390
- }
1391
- function checkLanguageOption(options, optionName) {
1392
- const language = options[optionName];
1393
- if (language !== void 0 && loadPrismLang(language) === void 0)
1394
- throw new Error(`Bad option ${optionName}: There is no Prism language '${language}'.`);
1395
- }
1396
- function markdownItPrism(markdownit, useroptions) {
1397
- const options = Object.assign({}, DEFAULTS, useroptions);
1398
- checkLanguageOption(options, "defaultLanguage");
1399
- checkLanguageOption(options, "defaultLanguageForUnknown");
1400
- checkLanguageOption(options, "defaultLanguageForUnspecified");
1401
- options.defaultLanguageForUnknown = options.defaultLanguageForUnknown || options.defaultLanguage;
1402
- options.defaultLanguageForUnspecified = options.defaultLanguageForUnspecified || options.defaultLanguage;
1403
- options.plugins.forEach(loadPrismPlugin);
1404
- options.init(Prism);
1405
- markdownit.options.highlight = (text, lang) => highlight(markdownit, options, text, lang);
1154
+ function withRenderedNote(data) {
1155
+ return {
1156
+ ...data,
1157
+ noteHTML: renderNote(data?.note)
1158
+ };
1406
1159
  }
1160
+ function createSlidesLoader({ data, clientRoot, roots, remote, mode, userRoot }, pluginOptions, serverOptions) {
1161
+ const slidePrefix = "/@slidev/slides/";
1162
+ const hmrPages = /* @__PURE__ */ new Set();
1163
+ let server;
1164
+ let _layouts_cache_time = 0;
1165
+ let _layouts_cache = {};
1166
+ return [
1167
+ {
1168
+ name: "slidev:loader",
1169
+ configureServer(_server) {
1170
+ server = _server;
1171
+ updateServerWatcher();
1172
+ server.middlewares.use(async (req, res, next) => {
1173
+ const match = req.url?.match(regexId);
1174
+ if (!match)
1175
+ return next();
1176
+ const [, no, type] = match;
1177
+ const idx = Number.parseInt(no);
1178
+ if (type === "json" && req.method === "GET") {
1179
+ res.write(JSON.stringify(withRenderedNote(data.slides[idx])));
1180
+ return res.end();
1181
+ }
1182
+ if (type === "json" && req.method === "POST") {
1183
+ const body = await getBodyJson(req);
1184
+ const slide = data.slides[idx];
1185
+ if (body.content && body.content !== slide.source.content)
1186
+ hmrPages.add(idx);
1187
+ Object.assign(slide.source, body);
1188
+ parser.prettifySlide(slide.source);
1189
+ await parser.save(data.markdownFiles[slide.source.filepath]);
1190
+ res.statusCode = 200;
1191
+ res.write(JSON.stringify(withRenderedNote(slide)));
1192
+ return res.end();
1193
+ }
1194
+ next();
1195
+ });
1196
+ },
1197
+ async handleHotUpdate(ctx) {
1198
+ if (!data.watchFiles.includes(ctx.file))
1199
+ return;
1200
+ await ctx.read();
1201
+ const newData = await serverOptions.loadData?.();
1202
+ if (!newData)
1203
+ return [];
1204
+ const moduleIds = /* @__PURE__ */ new Set();
1205
+ if (data.slides.length !== newData.slides.length) {
1206
+ moduleIds.add("/@slidev/slides");
1207
+ range(newData.slides.length).map((i) => hmrPages.add(i));
1208
+ }
1209
+ if (!equal(data.headmatter.defaults, newData.headmatter.defaults)) {
1210
+ moduleIds.add("/@slidev/slides");
1211
+ range(data.slides.length).map((i) => hmrPages.add(i));
1212
+ }
1213
+ if (!equal(data.config, newData.config))
1214
+ moduleIds.add("/@slidev/configs");
1215
+ if (!equal(data.features, newData.features)) {
1216
+ setTimeout(() => {
1217
+ ctx.server.hot.send({ type: "full-reload" });
1218
+ }, 1);
1219
+ }
1220
+ const length = Math.min(data.slides.length, newData.slides.length);
1221
+ for (let i = 0; i < length; i++) {
1222
+ const a = data.slides[i];
1223
+ const b = newData.slides[i];
1224
+ if (a.content.trim() === b.content.trim() && a.title?.trim() === b.title?.trim() && equal(a.frontmatter, b.frontmatter) && Object.entries(a.snippetsUsed ?? {}).every(([file, oldContent]) => {
1225
+ try {
1226
+ const newContent = fs5.readFileSync(file, "utf-8");
1227
+ return oldContent === newContent;
1228
+ } catch {
1229
+ return false;
1230
+ }
1231
+ })) {
1232
+ if (a.note !== b.note) {
1233
+ ctx.server.hot.send(
1234
+ "slidev:update-note",
1235
+ {
1236
+ id: i,
1237
+ note: b.note || "",
1238
+ noteHTML: renderNote(b.note || "")
1239
+ }
1240
+ );
1241
+ }
1242
+ continue;
1243
+ }
1244
+ ctx.server.hot.send(
1245
+ "slidev:update-slide",
1246
+ {
1247
+ id: i,
1248
+ data: withRenderedNote(newData.slides[i])
1249
+ }
1250
+ );
1251
+ hmrPages.add(i);
1252
+ }
1253
+ Object.assign(data, newData);
1254
+ if (hmrPages.size > 0)
1255
+ moduleIds.add("/@slidev/titles.md");
1256
+ const vueModules = Array.from(hmrPages).flatMap((i) => [
1257
+ ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.frontmatter`),
1258
+ ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.md`)
1259
+ ]);
1260
+ hmrPages.clear();
1261
+ const moduleEntries = [
1262
+ ...vueModules,
1263
+ ...Array.from(moduleIds).map((id) => ctx.server.moduleGraph.getModuleById(id))
1264
+ ].filter(notNullish).filter((i) => !i.id?.startsWith("/@id/@vite-icons"));
1265
+ updateServerWatcher();
1266
+ return moduleEntries;
1267
+ },
1268
+ resolveId(id) {
1269
+ if (id.startsWith(slidePrefix) || id.startsWith("/@slidev/"))
1270
+ return id;
1271
+ return null;
1272
+ },
1273
+ load(id) {
1274
+ if (id === "/@slidev/slides")
1275
+ return generateSlideRoutes();
1276
+ if (id === "/@slidev/routes")
1277
+ return generateDummyRoutes();
1278
+ if (id === "/@slidev/layouts")
1279
+ return generateLayouts();
1280
+ if (id === "/@slidev/styles")
1281
+ return generateUserStyles();
1282
+ if (id === "/@slidev/monaco-types")
1283
+ return generateMonacoTypes();
1284
+ if (id === "/@slidev/configs")
1285
+ return generateConfigs();
1286
+ if (id === "/@slidev/global-components/top")
1287
+ return generateGlobalComponents("top");
1288
+ if (id === "/@slidev/global-components/bottom")
1289
+ return generateGlobalComponents("bottom");
1290
+ if (id === "/@slidev/custom-nav-controls")
1291
+ return generateCustomNavControls();
1292
+ if (id === "/@slidev/shiki")
1293
+ return generteShikiBundle();
1294
+ if (id === "/@slidev/titles.md") {
1295
+ return {
1296
+ code: data.slides.map(({ title }, i) => `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">
1407
1297
 
1408
- // node/plugins/transformSnippet.ts
1409
- import path from "node:path";
1410
- import fs6 from "fs-extra";
1411
- function dedent(text) {
1412
- const lines = text.split("\n");
1413
- const minIndentLength = lines.reduce((acc, line) => {
1414
- for (let i = 0; i < line.length; i++) {
1415
- if (line[i] !== " " && line[i] !== " ")
1416
- return Math.min(i, acc);
1417
- }
1418
- return acc;
1419
- }, Number.POSITIVE_INFINITY);
1420
- if (minIndentLength < Number.POSITIVE_INFINITY)
1421
- return lines.map((x) => x.slice(minIndentLength)).join("\n");
1422
- return text;
1423
- }
1424
- function testLine(line, regexp, regionName, end = false) {
1425
- const [full, tag, name] = regexp.exec(line.trim()) || [];
1426
- return full && tag && name === regionName && tag.match(end ? /^[Ee]nd ?[rR]egion$/ : /^[rR]egion$/);
1427
- }
1428
- function findRegion(lines, regionName) {
1429
- const regionRegexps = [
1430
- /^\/\/ ?#?((?:end)?region) ([\w*-]+)$/,
1431
- // javascript, typescript, java
1432
- /^\/\* ?#((?:end)?region) ([\w*-]+) ?\*\/$/,
1433
- // css, less, scss
1434
- /^#pragma ((?:end)?region) ([\w*-]+)$/,
1435
- // C, C++
1436
- /^<!-- #?((?:end)?region) ([\w*-]+) -->$/,
1437
- // HTML, markdown
1438
- /^#((?:End )Region) ([\w*-]+)$/,
1439
- // Visual Basic
1440
- /^::#((?:end)region) ([\w*-]+)$/,
1441
- // Bat
1442
- /^# ?((?:end)?region) ([\w*-]+)$/
1443
- // C#, PHP, Powershell, Python, perl & misc
1444
- ];
1445
- let regexp = null;
1446
- let start = -1;
1447
- for (const [lineId, line] of lines.entries()) {
1448
- if (regexp === null) {
1449
- for (const reg of regionRegexps) {
1450
- if (testLine(line, reg, regionName)) {
1451
- start = lineId + 1;
1452
- regexp = reg;
1453
- break;
1298
+ ${title}
1299
+
1300
+ </template>`).join(""),
1301
+ map: { mappings: "" }
1302
+ };
1303
+ }
1304
+ if (id.startsWith(slidePrefix)) {
1305
+ const remaning = id.slice(slidePrefix.length);
1306
+ const match = remaning.match(regexIdQuery);
1307
+ if (match) {
1308
+ const [, no, type] = match;
1309
+ const pageNo = Number.parseInt(no) - 1;
1310
+ const slide = data.slides[pageNo];
1311
+ if (!slide)
1312
+ return;
1313
+ if (type === "md") {
1314
+ return {
1315
+ code: slide?.content,
1316
+ map: { mappings: "" }
1317
+ };
1318
+ } else if (type === "frontmatter") {
1319
+ const slideBase = {
1320
+ ...withRenderedNote(slide),
1321
+ frontmatter: void 0,
1322
+ source: void 0,
1323
+ // remove raw content in build, optimize the bundle size
1324
+ ...mode === "build" ? { raw: "", content: "", note: "" } : {}
1325
+ };
1326
+ const fontmatter = getFrontmatter(pageNo);
1327
+ return {
1328
+ code: [
1329
+ "// @unocss-include",
1330
+ 'import { reactive, computed } from "vue"',
1331
+ `export const frontmatter = reactive(${JSON.stringify(fontmatter)})`,
1332
+ `export const meta = reactive({
1333
+ layout: computed(() => frontmatter.layout),
1334
+ transition: computed(() => frontmatter.transition),
1335
+ class: computed(() => frontmatter.class),
1336
+ clicks: computed(() => frontmatter.clicks),
1337
+ name: computed(() => frontmatter.name),
1338
+ preload: computed(() => frontmatter.preload),
1339
+ slide: {
1340
+ ...(${JSON.stringify(slideBase)}),
1341
+ frontmatter,
1342
+ filepath: ${JSON.stringify(slide.source.filepath)},
1343
+ start: ${JSON.stringify(slide.source.start)},
1344
+ id: ${pageNo},
1345
+ no: ${no},
1346
+ },
1347
+ __clicksContext: null,
1348
+ __preloaded: false,
1349
+ })`,
1350
+ "export default frontmatter",
1351
+ // handle HMR, update frontmatter with update
1352
+ "if (import.meta.hot) {",
1353
+ " import.meta.hot.accept(({ frontmatter: update }) => {",
1354
+ " if(!update) return",
1355
+ " Object.keys(frontmatter).forEach(key => {",
1356
+ " if (!(key in update)) delete frontmatter[key]",
1357
+ " })",
1358
+ " Object.assign(frontmatter, update)",
1359
+ " })",
1360
+ "}"
1361
+ ].join("\n"),
1362
+ map: { mappings: "" }
1363
+ };
1364
+ }
1365
+ }
1366
+ return {
1367
+ code: "",
1368
+ map: { mappings: "" }
1369
+ };
1370
+ }
1371
+ }
1372
+ },
1373
+ {
1374
+ name: "slidev:layout-transform:pre",
1375
+ enforce: "pre",
1376
+ async transform(code, id) {
1377
+ if (!id.startsWith(slidePrefix))
1378
+ return;
1379
+ const remaning = id.slice(slidePrefix.length);
1380
+ const match = remaning.match(regexIdQuery);
1381
+ if (!match)
1382
+ return;
1383
+ const [, no, type] = match;
1384
+ if (type !== "md")
1385
+ return;
1386
+ const pageNo = Number.parseInt(no) - 1;
1387
+ return transformMarkdown(code, pageNo);
1388
+ }
1389
+ },
1390
+ {
1391
+ name: "slidev:context-transform:pre",
1392
+ enforce: "pre",
1393
+ async transform(code, id) {
1394
+ if (!id.endsWith(".vue") || id.includes("/@slidev/client/") || id.includes("/packages/client/"))
1395
+ return;
1396
+ return transformVue(code);
1397
+ }
1398
+ },
1399
+ {
1400
+ name: "slidev:title-transform:pre",
1401
+ enforce: "pre",
1402
+ transform(code, id) {
1403
+ if (id !== "/@slidev/titles.md")
1404
+ return;
1405
+ return transformTitles(code);
1406
+ }
1407
+ },
1408
+ {
1409
+ name: "slidev:slide-transform:post",
1410
+ enforce: "post",
1411
+ transform(code, id) {
1412
+ if (!id.match(/\/@slidev\/slides\/\d+\.md($|\?)/))
1413
+ return;
1414
+ const replaced = code.replace("if (_rerender_only)", "if (false)");
1415
+ if (replaced !== code)
1416
+ return replaced;
1417
+ }
1418
+ },
1419
+ {
1420
+ name: "slidev:index-html-transform",
1421
+ transformIndexHtml() {
1422
+ const { info, author, keywords } = data.headmatter;
1423
+ return [
1424
+ {
1425
+ tag: "title",
1426
+ children: getTitle()
1427
+ },
1428
+ info && {
1429
+ tag: "meta",
1430
+ attrs: {
1431
+ name: "description",
1432
+ content: info
1433
+ }
1434
+ },
1435
+ author && {
1436
+ tag: "meta",
1437
+ attrs: {
1438
+ name: "author",
1439
+ content: author
1440
+ }
1441
+ },
1442
+ keywords && {
1443
+ tag: "meta",
1444
+ attrs: {
1445
+ name: "keywords",
1446
+ content: Array.isArray(keywords) ? keywords.join(", ") : keywords
1447
+ }
1448
+ }
1449
+ ].filter(isTruthy2);
1450
+ }
1451
+ }
1452
+ ];
1453
+ function updateServerWatcher() {
1454
+ if (!server)
1455
+ return;
1456
+ server.watcher.add(data.watchFiles);
1457
+ }
1458
+ function getFrontmatter(pageNo) {
1459
+ return {
1460
+ ...data.headmatter?.defaults || {},
1461
+ ...data.slides[pageNo]?.frontmatter || {}
1462
+ };
1463
+ }
1464
+ async function transformMarkdown(code, pageNo) {
1465
+ const layouts = await getLayouts();
1466
+ const frontmatter = getFrontmatter(pageNo);
1467
+ let layoutName = frontmatter?.layout || (pageNo === 0 ? "cover" : "default");
1468
+ if (!layouts[layoutName]) {
1469
+ console.error(red(`
1470
+ Unknown layout "${bold(layoutName)}".${yellow(" Available layouts are:")}`) + Object.keys(layouts).map((i, idx) => (idx % 3 === 0 ? "\n " : "") + gray(i.padEnd(15, " "))).join(" "));
1471
+ console.error();
1472
+ layoutName = "default";
1473
+ }
1474
+ delete frontmatter.title;
1475
+ const imports = [
1476
+ `import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
1477
+ `import frontmatter from "${toAtFS(`${slidePrefix + (pageNo + 1)}.frontmatter`)}"`,
1478
+ templateImportContextUtils,
1479
+ "_provideFrontmatter(frontmatter)",
1480
+ templateInitContext,
1481
+ templateInjectionMarker
1482
+ ];
1483
+ code = code.replace(/(<script setup.*>)/g, `$1
1484
+ ${imports.join("\n")}
1485
+ `);
1486
+ const injectA = code.indexOf("<template>") + "<template>".length;
1487
+ const injectB = code.lastIndexOf("</template>");
1488
+ let body = code.slice(injectA, injectB).trim();
1489
+ if (body.startsWith("<div>") && body.endsWith("</div>"))
1490
+ body = body.slice(5, -6);
1491
+ code = `${code.slice(0, injectA)}
1492
+ <InjectedLayout v-bind="_frontmatterToProps(frontmatter,${pageNo})">
1493
+ ${body}
1494
+ </InjectedLayout>
1495
+ ${code.slice(injectB)}`;
1496
+ return code;
1497
+ }
1498
+ function transformVue(code) {
1499
+ if (code.includes(templateInjectionMarker) || code.includes("useSlideContext()"))
1500
+ return code;
1501
+ const imports = [
1502
+ templateImportContextUtils,
1503
+ templateInitContext,
1504
+ templateInjectionMarker
1505
+ ];
1506
+ const matchScript = code.match(/<script((?!setup).)*(setup)?.*>/);
1507
+ if (matchScript && matchScript[2]) {
1508
+ return code.replace(/(<script.*>)/g, `$1
1509
+ ${imports.join("\n")}
1510
+ `);
1511
+ } else if (matchScript && !matchScript[2]) {
1512
+ const matchExport = code.match(/export\s+default\s+{/);
1513
+ if (matchExport) {
1514
+ const exportIndex = (matchExport.index || 0) + matchExport[0].length;
1515
+ let component = code.slice(exportIndex);
1516
+ component = component.slice(0, component.indexOf("</script>"));
1517
+ const scriptIndex = (matchScript.index || 0) + matchScript[0].length;
1518
+ const provideImport = '\nimport { injectionSlidevContext } from "@slidev/client/constants.ts"\n';
1519
+ code = `${code.slice(0, scriptIndex)}${provideImport}${code.slice(scriptIndex)}`;
1520
+ let injectIndex = exportIndex + provideImport.length;
1521
+ let injectObject = "$slidev: { from: injectionSlidevContext },";
1522
+ const matchInject = component.match(/.*inject\s*:\s*([\[{])/);
1523
+ if (matchInject) {
1524
+ injectIndex += (matchInject.index || 0) + matchInject[0].length;
1525
+ if (matchInject[1] === "[") {
1526
+ let injects = component.slice((matchInject.index || 0) + matchInject[0].length);
1527
+ const injectEndIndex = injects.indexOf("]");
1528
+ injects = injects.slice(0, injectEndIndex);
1529
+ injectObject += injects.split(",").map((inject) => `${inject}: {from: ${inject}}`).join(",");
1530
+ return `${code.slice(0, injectIndex - 1)}{
1531
+ ${injectObject}
1532
+ }${code.slice(injectIndex + injectEndIndex + 1)}`;
1533
+ } else {
1534
+ return `${code.slice(0, injectIndex)}
1535
+ ${injectObject}
1536
+ ${code.slice(injectIndex)}`;
1537
+ }
1454
1538
  }
1539
+ return `${code.slice(0, injectIndex)}
1540
+ inject: { ${injectObject} },
1541
+ ${code.slice(injectIndex)}`;
1455
1542
  }
1456
- } else if (testLine(line, regexp, regionName, true)) {
1457
- return { start, end: lineId, regexp };
1458
1543
  }
1544
+ return `<script setup>
1545
+ ${imports.join("\n")}
1546
+ </script>
1547
+ ${code}`;
1459
1548
  }
1460
- return null;
1461
- }
1462
- function transformSnippet(md2, options, id) {
1463
- const slideId = id.match(/(\d+)\.md$/)?.[1];
1464
- if (!slideId)
1465
- return md2;
1466
- const data = options.data;
1467
- const slideInfo = data.slides[+slideId - 1];
1468
- const dir = path.dirname(slideInfo.source?.filepath ?? options?.entry ?? options.userRoot);
1469
- return md2.replace(
1470
- /^<<< *(.+?)(#[\w-]+)? *(?: (\S+?))? *(\{.*)?$/mg,
1471
- (full, filepath = "", regionName = "", lang = "", meta = "") => {
1472
- const firstLine = `\`\`\`${lang || path.extname(filepath).slice(1)} ${meta}`;
1473
- const src = /^\@[\/]/.test(filepath) ? path.resolve(options.userRoot, filepath.slice(2)) : path.resolve(dir, filepath);
1474
- data.entries.push(src);
1475
- const isAFile = fs6.statSync(src).isFile();
1476
- if (!fs6.existsSync(src) || !isAFile) {
1477
- throw new Error(isAFile ? `Code snippet path not found: ${src}` : `Invalid code snippet option`);
1549
+ function transformTitles(code) {
1550
+ return code.replace(/<template>\s*<div>\s*<p>/, "<template>").replace(/<\/p>\s*<\/div>\s*<\/template>/, "</template>").replace(/<script\ssetup>/, `<script setup lang="ts">
1551
+ defineProps<{ no: number | string }>()`);
1552
+ }
1553
+ async function getLayouts() {
1554
+ const now = Date.now();
1555
+ if (now - _layouts_cache_time < 2e3)
1556
+ return _layouts_cache;
1557
+ const layouts = {};
1558
+ for (const root of [...roots, clientRoot]) {
1559
+ const layoutPaths = await fg2("layouts/**/*.{vue,ts}", {
1560
+ cwd: root,
1561
+ absolute: true,
1562
+ suppressErrors: true
1563
+ });
1564
+ for (const layoutPath of layoutPaths) {
1565
+ const layout = basename2(layoutPath).replace(/\.\w+$/, "");
1566
+ if (layouts[layout])
1567
+ continue;
1568
+ layouts[layout] = layoutPath;
1478
1569
  }
1479
- let content = fs6.readFileSync(src, "utf8");
1480
- slideInfo.snippetsUsed ??= {};
1481
- slideInfo.snippetsUsed[src] = content;
1482
- if (regionName) {
1483
- const lines = content.split(/\r?\n/);
1484
- const region = findRegion(lines, regionName.slice(1));
1485
- if (region) {
1486
- content = dedent(
1487
- lines.slice(region.start, region.end).filter((line) => !region.regexp.test(line.trim())).join("\n")
1488
- );
1570
+ }
1571
+ _layouts_cache_time = now;
1572
+ _layouts_cache = layouts;
1573
+ return layouts;
1574
+ }
1575
+ async function resolveUrl(id) {
1576
+ return toAtFS(await resolveImportPath(id, true));
1577
+ }
1578
+ function resolveUrlOfClient(name) {
1579
+ return toAtFS(join4(clientRoot, name));
1580
+ }
1581
+ async function generateUserStyles() {
1582
+ const imports = [
1583
+ `import "${resolveUrlOfClient("styles/vars.css")}"`,
1584
+ `import "${resolveUrlOfClient("styles/index.css")}"`,
1585
+ `import "${resolveUrlOfClient("styles/code.css")}"`,
1586
+ `import "${resolveUrlOfClient("styles/katex.css")}"`,
1587
+ `import "${resolveUrlOfClient("styles/transitions.css")}"`,
1588
+ `import "${resolveUrlOfClient("styles/monaco.css")}"`
1589
+ ];
1590
+ for (const root of roots) {
1591
+ const styles = [
1592
+ join4(root, "styles", "index.ts"),
1593
+ join4(root, "styles", "index.js"),
1594
+ join4(root, "styles", "index.css"),
1595
+ join4(root, "styles.css"),
1596
+ join4(root, "style.css")
1597
+ ];
1598
+ for (const style of styles) {
1599
+ if (fs5.existsSync(style)) {
1600
+ imports.push(`import "${toAtFS(style)}"`);
1601
+ continue;
1489
1602
  }
1490
1603
  }
1491
- return `${firstLine}
1492
- ${content}
1493
- \`\`\``;
1494
1604
  }
1495
- );
1496
- }
1497
-
1498
- // node/plugins/markdown.ts
1499
- async function createMarkdownPlugin(options, { markdown: mdOptions }) {
1500
- const { data: { config }, roots, mode, entry } = options;
1501
- const setups = [];
1502
- const entryPath = slash4(entry);
1503
- if (config.highlighter === "shiki") {
1504
- const MarkdownItShiki = await import("@shikijs/markdown-it").then((r) => r.default);
1505
- const { transformerTwoslash } = await import("@shikijs/vitepress-twoslash");
1506
- const options2 = await loadShikiSetups(roots);
1507
- const plugin = await MarkdownItShiki({
1508
- ...options2,
1509
- transformers: [
1510
- ...options2.transformers || [],
1511
- transformerTwoslash({
1512
- explicitTrigger: true,
1513
- twoslashOptions: {
1514
- handbookOptions: {
1515
- noErrorValidation: true
1516
- }
1517
- }
1518
- }),
1519
- {
1520
- pre(pre) {
1521
- this.addClassToHast(pre, "slidev-code");
1522
- delete pre.properties.tabindex;
1523
- },
1524
- postprocess(code) {
1525
- return escapeVueInCode(code);
1526
- }
1527
- }
1528
- ]
1529
- });
1530
- setups.push((md2) => md2.use(plugin));
1531
- } else {
1532
- setups.push((md2) => md2.use(markdownItPrism));
1605
+ if (data.features.katex)
1606
+ imports.push(`import "${await resolveUrl("katex/dist/katex.min.css")}"`);
1607
+ if (data.config.highlighter === "shiki") {
1608
+ imports.push(
1609
+ `import "${await resolveUrl("@shikijs/vitepress-twoslash/style.css")}"`,
1610
+ `import "${resolveUrlOfClient("styles/shiki-twoslash.css")}"`
1611
+ );
1612
+ }
1613
+ if (data.config.css === "unocss") {
1614
+ imports.unshift(
1615
+ `import "${await resolveUrl("@unocss/reset/tailwind.css")}"`,
1616
+ 'import "uno:preflights.css"',
1617
+ 'import "uno:typography.css"',
1618
+ 'import "uno:shortcuts.css"'
1619
+ );
1620
+ imports.push('import "uno.css"');
1621
+ }
1622
+ return imports.join("\n");
1533
1623
  }
1534
- if (config.mdc)
1535
- setups.push((md2) => md2.use(Mdc));
1536
- const KatexOptions = await loadSetups(roots, "katex.ts", {}, { strict: false }, false);
1537
- return Markdown2({
1538
- include: [/\.md$/],
1539
- wrapperClasses: "",
1540
- headEnabled: false,
1541
- frontmatter: false,
1542
- escapeCodeTagInterpolation: false,
1543
- markdownItOptions: {
1544
- quotes: `""''`,
1545
- html: true,
1546
- xhtmlOut: true,
1547
- linkify: true,
1548
- ...mdOptions?.markdownItOptions
1549
- },
1550
- ...mdOptions,
1551
- markdownItSetup(md2) {
1552
- md2.use(mila2, {
1553
- attrs: {
1554
- target: "_blank",
1555
- rel: "noopener"
1556
- }
1557
- });
1558
- md2.use(mif);
1559
- md2.use(taskLists, { enabled: true, lineNumber: true, label: true });
1560
- md2.use(math_plugin, KatexOptions);
1561
- setups.forEach((i) => i(md2));
1562
- mdOptions?.markdownItSetup?.(md2);
1563
- },
1564
- transforms: {
1565
- before(code, id) {
1566
- if (id === entryPath)
1567
- return "";
1568
- const monaco = config.monaco === true || config.monaco === mode ? transformMarkdownMonaco : truncateMancoMark;
1569
- code = transformSlotSugar(code);
1570
- code = transformSnippet(code, options, id);
1571
- code = transformMermaid(code);
1572
- code = transformPlantUml(code, config.plantUmlServer);
1573
- code = monaco(code);
1574
- code = transformHighlighter(code);
1575
- code = transformPageCSS(code, id);
1576
- code = transformKaTex(code);
1577
- return code;
1624
+ async function generateMonacoTypes() {
1625
+ const typesRoot = join4(userRoot, "snippets");
1626
+ const files = await fg2(["**/*.ts", "**/*.mts", "**/*.cts"], { cwd: typesRoot });
1627
+ let result = 'import { addFile } from "@slidev/client/setup/monaco.ts"\n';
1628
+ for (const file of files) {
1629
+ const url = `${toAtFS(resolve2(typesRoot, file))}?monaco-types&raw`;
1630
+ result += `addFile(import(${JSON.stringify(url)}), ${JSON.stringify(file)})
1631
+ `;
1632
+ }
1633
+ const deps = data.config.monacoTypesAdditionalPackages;
1634
+ if (data.config.monacoTypesSource === "local")
1635
+ deps.push(...scanMonacoModules(data.slides.map((s) => s.source.raw).join()));
1636
+ function mapModuleNameToModule(moduleSpecifier) {
1637
+ if (moduleSpecifier.startsWith("node:"))
1638
+ return "node";
1639
+ if (builtinModules.includes(moduleSpecifier))
1640
+ return "node";
1641
+ const mainPackageName = moduleSpecifier.split("/")[0];
1642
+ if (builtinModules.includes(mainPackageName) && !mainPackageName.startsWith("@"))
1643
+ return "node";
1644
+ const [a = "", b = ""] = moduleSpecifier.split("/");
1645
+ const moduleName = a.startsWith("@") ? `${a}/${b}` : a;
1646
+ return moduleName;
1647
+ }
1648
+ for (const specifier of uniq2(deps)) {
1649
+ if (specifier[0] === ".")
1650
+ continue;
1651
+ const moduleName = mapModuleNameToModule(specifier);
1652
+ result += `import(${JSON.stringify(`/@slidev-monaco-types/resolve?pkg=${moduleName}`)})
1653
+ `;
1654
+ }
1655
+ return result;
1656
+ }
1657
+ async function generateLayouts() {
1658
+ const imports = [];
1659
+ const layouts = objectMap(
1660
+ await getLayouts(),
1661
+ (k, v) => {
1662
+ imports.push(`import __layout_${k} from "${toAtFS(v)}"`);
1663
+ return [k, `__layout_${k}`];
1578
1664
  }
1665
+ );
1666
+ return [
1667
+ imports.join("\n"),
1668
+ `export default {
1669
+ ${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}
1670
+ }`
1671
+ ].join("\n\n");
1672
+ }
1673
+ async function generateSlideRoutes() {
1674
+ const layouts = await getLayouts();
1675
+ const imports = [
1676
+ `import { shallowRef } from 'vue'`,
1677
+ `import * as __layout__error from '${layouts.error}'`
1678
+ ];
1679
+ const slides = data.slides.map((_, idx) => {
1680
+ const no = idx + 1;
1681
+ imports.push(`import { meta as f${no} } from '${slidePrefix}${no}.frontmatter'`);
1682
+ return `{
1683
+ no: ${no},
1684
+ meta: f${no},
1685
+ component: async () => {
1686
+ try {
1687
+ return await import('${slidePrefix}${no}.md')
1688
+ }
1689
+ catch {
1690
+ return __layout__error
1691
+ }
1692
+ },
1693
+ }`;
1694
+ });
1695
+ return [
1696
+ ...imports,
1697
+ `const data = [
1698
+ ${slides.join(",\n")}
1699
+ ]`,
1700
+ `export const slides = shallowRef([...data])`,
1701
+ `let oldRef = slides`,
1702
+ `export function update(old) {`,
1703
+ ` oldRef = old`,
1704
+ ` old.value = data`,
1705
+ `}`,
1706
+ `if (import.meta.hot) {`,
1707
+ ` import.meta.hot.accept(({ update }) => {`,
1708
+ ` update(oldRef)`,
1709
+ ` })`,
1710
+ `}`
1711
+ ].join("\n");
1712
+ }
1713
+ function generateDummyRoutes() {
1714
+ return [
1715
+ `export { slides } from '#slidev/slides'`,
1716
+ `console.warn('[slidev] #slidev/routes is deprecated, use #slidev/slides instead')`
1717
+ ].join("\n");
1718
+ }
1719
+ function getTitle() {
1720
+ if (isString(data.config.title)) {
1721
+ const tokens = md.parseInline(data.config.title, {});
1722
+ return stringifyMarkdownTokens(tokens);
1579
1723
  }
1580
- });
1724
+ return data.config.title;
1725
+ }
1726
+ function generateConfigs() {
1727
+ const config = {
1728
+ ...data.config,
1729
+ remote,
1730
+ title: getTitle()
1731
+ };
1732
+ if (isString(config.info))
1733
+ config.info = md.render(config.info);
1734
+ return `export default ${JSON.stringify(config)}`;
1735
+ }
1736
+ async function generateGlobalComponents(layer) {
1737
+ const components = roots.flatMap((root) => {
1738
+ if (layer === "top") {
1739
+ return [
1740
+ join4(root, "global.vue"),
1741
+ join4(root, "global-top.vue"),
1742
+ join4(root, "GlobalTop.vue")
1743
+ ];
1744
+ } else {
1745
+ return [
1746
+ join4(root, "global-bottom.vue"),
1747
+ join4(root, "GlobalBottom.vue")
1748
+ ];
1749
+ }
1750
+ }).filter((i) => fs5.existsSync(i));
1751
+ const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
1752
+ const render = components.map((i, idx) => `h(__n${idx})`).join(",");
1753
+ return `
1754
+ ${imports}
1755
+ import { h } from 'vue'
1756
+ export default {
1757
+ render() {
1758
+ return [${render}]
1759
+ }
1581
1760
  }
1582
- function transformKaTex(md2) {
1583
- return md2.replace(/^\$\$(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?\s*?)?\n([\s\S]+?)^\$\$/mg, (full, rangeStr = "", options = "", code) => {
1584
- const ranges = rangeStr.split(/\|/g).map((i) => i.trim());
1585
- code = code.trimEnd();
1586
- options = options.trim() || "{}";
1587
- return `<KaTexBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
1588
-
1589
- $$
1590
- ${code}
1591
- $$
1592
- </KaTexBlockWrapper>
1593
1761
  `;
1594
- });
1595
- }
1596
- function transformMarkdownMonaco(md2) {
1597
- md2 = md2.replace(/^```(\w+?)\s*{monaco-diff}\s*?({.*?})?\s*?\n([\s\S]+?)^~~~\s*?\n([\s\S]+?)^```/mg, (full, lang = "ts", options = "{}", code, diff) => {
1598
- lang = lang.trim();
1599
- options = options.trim() || "{}";
1600
- const encoded = base64.encode(code, true);
1601
- const encodedDiff = base64.encode(diff, true);
1602
- return `<Monaco :code="'${encoded}'" :diff="'${encodedDiff}'" lang="${lang}" v-bind="${options}" />`;
1603
- });
1604
- md2 = md2.replace(/^```(\w+?)\s*{monaco}\s*?({.*?})?\s*?\n([\s\S]+?)^```/mg, (full, lang = "ts", options = "{}", code) => {
1605
- lang = lang.trim();
1606
- options = options.trim() || "{}";
1607
- const encoded = base64.encode(code, true);
1608
- return `<Monaco :code="'${encoded}'" lang="${lang}" v-bind="${options}" />`;
1609
- });
1610
- return md2;
1611
- }
1612
- function truncateMancoMark(md2) {
1613
- return md2.replace(/{monaco.*?}/g, "");
1762
+ }
1763
+ async function generateCustomNavControls() {
1764
+ const components = roots.flatMap((root) => {
1765
+ return [
1766
+ join4(root, "custom-nav-controls.vue"),
1767
+ join4(root, "CustomNavControls.vue")
1768
+ ];
1769
+ }).filter((i) => fs5.existsSync(i));
1770
+ const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
1771
+ const render = components.map((i, idx) => `h(__n${idx})`).join(",");
1772
+ return `
1773
+ ${imports}
1774
+ import { h } from 'vue'
1775
+ export default {
1776
+ render() {
1777
+ return [${render}]
1778
+ }
1614
1779
  }
1615
- function transformSlotSugar(md2) {
1616
- const lines = md2.split(/\r?\n/g);
1617
- let prevSlot = false;
1618
- const { isLineInsideCodeblocks } = getCodeBlocks(md2);
1619
- lines.forEach((line, idx) => {
1620
- if (isLineInsideCodeblocks(idx))
1621
- return;
1622
- const match = line.trimEnd().match(/^::\s*([\w\.\-\:]+)\s*::$/);
1623
- if (match) {
1624
- lines[idx] = `${prevSlot ? "\n\n</template>\n" : "\n"}<template v-slot:${match[1]}="slotProps">
1625
1780
  `;
1626
- prevSlot = true;
1781
+ }
1782
+ async function generteShikiBundle() {
1783
+ const options = await loadShikiSetups(clientRoot, roots);
1784
+ const langs = await resolveLangs(options.langs || ["javascript", "typescript", "html", "css"]);
1785
+ const resolvedThemeOptions = "themes" in options ? {
1786
+ themes: Object.fromEntries(await Promise.all(
1787
+ Object.entries(options.themes).map(async ([name, value]) => [name, await resolveTheme(value)])
1788
+ ))
1789
+ } : {
1790
+ theme: await resolveTheme(options.theme || "vitesse-dark")
1791
+ };
1792
+ const themes = resolvedThemeOptions.themes ? Object.values(resolvedThemeOptions.themes) : [resolvedThemeOptions.theme];
1793
+ const themeOptionsNames = resolvedThemeOptions.themes ? { themes: Object.fromEntries(Object.entries(resolvedThemeOptions.themes).map(([name, value]) => [name, typeof value === "string" ? value : value.name])) } : { theme: typeof resolvedThemeOptions.theme === "string" ? resolvedThemeOptions.theme : resolvedThemeOptions.theme.name };
1794
+ async function normalizeGetter(p) {
1795
+ return Promise.resolve(typeof p === "function" ? p() : p).then((r) => r.default || r);
1627
1796
  }
1628
- });
1629
- if (prevSlot)
1630
- lines[lines.length - 1] += "\n\n</template>";
1631
- return lines.join("\n");
1797
+ async function resolveLangs(langs2) {
1798
+ return Array.from(new Set((await Promise.all(
1799
+ langs2.map(async (lang) => await normalizeGetter(lang).then((r) => Array.isArray(r) ? r : [r]))
1800
+ )).flat()));
1801
+ }
1802
+ async function resolveTheme(theme) {
1803
+ return typeof theme === "string" ? theme : await normalizeGetter(theme);
1804
+ }
1805
+ const langsInit = await Promise.all(
1806
+ langs.map(async (lang) => typeof lang === "string" ? `import('${await resolveUrl(`shiki/langs/${lang}.mjs`)}')` : JSON.stringify(lang))
1807
+ );
1808
+ const themesInit = await Promise.all(themes.map(async (theme) => typeof theme === "string" ? `import('${await resolveUrl(`shiki/themes/${theme}.mjs`)}')` : JSON.stringify(theme)));
1809
+ const langNames = langs.flatMap((lang) => typeof lang === "string" ? lang : lang.name);
1810
+ const lines = [];
1811
+ lines.push(
1812
+ `import { getHighlighterCore } from "${await resolveUrl("shiki/core")}"`,
1813
+ `export { shikiToMonaco } from "${await resolveUrl("@shikijs/monaco")}"`,
1814
+ `export const languages = ${JSON.stringify(langNames)}`,
1815
+ `export const themes = ${JSON.stringify(themeOptionsNames.themes || themeOptionsNames.theme)}`,
1816
+ "export const shiki = getHighlighterCore({",
1817
+ ` themes: [${themesInit.join(",")}],`,
1818
+ ` langs: [${langsInit.join(",")}],`,
1819
+ ` loadWasm: import('${await resolveUrl("shiki/wasm")}'),`,
1820
+ "})"
1821
+ );
1822
+ return lines.join("\n");
1823
+ }
1632
1824
  }
1633
- function transformHighlighter(md2) {
1634
- return md2.replace(/^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```/mg, (full, lang = "", rangeStr = "", options = "", attrs = "", code) => {
1635
- const ranges = rangeStr.split(/\|/g).map((i) => i.trim());
1636
- code = code.trimEnd();
1637
- options = options.trim() || "{}";
1638
- return `
1639
- <CodeBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
1640
-
1641
- \`\`\`${lang}${attrs}
1642
- ${code}
1643
- \`\`\`
1644
1825
 
1645
- </CodeBlockWrapper>`;
1646
- });
1647
- }
1648
- function getCodeBlocks(md2) {
1649
- const codeblocks = Array.from(md2.matchAll(/^```[\s\S]*?^```/mg)).map((m) => {
1650
- const start = m.index;
1651
- const end = m.index + m[0].length;
1652
- const startLine = md2.slice(0, start).match(/\n/g)?.length || 0;
1653
- const endLine = md2.slice(0, end).match(/\n/g)?.length || 0;
1654
- return [start, end, startLine, endLine];
1655
- });
1826
+ // node/plugins/setupClient.ts
1827
+ import { existsSync as existsSync2 } from "node:fs";
1828
+ import { join as join5, resolve as resolve3 } from "node:path";
1829
+ import { slash as slash2, uniq as uniq3 } from "@antfu/utils";
1830
+ function createClientSetupPlugin({ themeRoots, addonRoots, userRoot, clientRoot }) {
1831
+ const setupEntry = slash2(resolve3(clientRoot, "setup"));
1656
1832
  return {
1657
- codeblocks,
1658
- isInsideCodeblocks(idx) {
1659
- return codeblocks.some(([s, e]) => s <= idx && idx <= e);
1660
- },
1661
- isLineInsideCodeblocks(line) {
1662
- return codeblocks.some(([, , s, e]) => s <= line && line <= e);
1833
+ name: "slidev:setup",
1834
+ enforce: "pre",
1835
+ async transform(code, id) {
1836
+ if (id.startsWith(setupEntry)) {
1837
+ let getInjections2 = function(isAwait = false, isChained = false) {
1838
+ return injections.join("\n").replace(/:AWAIT:/g, isAwait ? "await " : "").replace(/(,\s*)?:LAST:/g, isChained ? "$1injection_return" : "");
1839
+ };
1840
+ var getInjections = getInjections2;
1841
+ const name = id.slice(setupEntry.length + 1).replace(/\?.*$/, "");
1842
+ const imports = [];
1843
+ const injections = [];
1844
+ const setups = uniq3([
1845
+ ...themeRoots,
1846
+ ...addonRoots,
1847
+ userRoot
1848
+ ]).map((i) => join5(i, "setup", name));
1849
+ setups.forEach((path2, idx) => {
1850
+ if (!existsSync2(path2))
1851
+ return;
1852
+ imports.push(`import __n${idx} from '${toAtFS(path2)}'`);
1853
+ let fn = `:AWAIT:__n${idx}`;
1854
+ if (/\binjection_return\b/g.test(code))
1855
+ fn = `injection_return = ${fn}`;
1856
+ if (/\binjection_arg\b/g.test(code)) {
1857
+ fn += "(";
1858
+ const matches = Array.from(code.matchAll(/\binjection_arg(_\d+)?\b/g));
1859
+ const dedupedMatches = Array.from(new Set(matches.map((m) => m[0])));
1860
+ fn += dedupedMatches.join(", ");
1861
+ fn += ", :LAST:)";
1862
+ } else {
1863
+ fn += "(:LAST:)";
1864
+ }
1865
+ injections.push(
1866
+ `// ${path2}`,
1867
+ fn
1868
+ );
1869
+ });
1870
+ code = code.replace("/* __imports__ */", imports.join("\n"));
1871
+ code = code.replace("/* __injections__ */", getInjections2());
1872
+ code = code.replace("/* __async_injections__ */", getInjections2(true));
1873
+ code = code.replace("/* __chained_injections__ */", getInjections2(false, true));
1874
+ code = code.replace("/* __chained_async_injections__ */", getInjections2(true, true));
1875
+ return code;
1876
+ }
1877
+ return null;
1663
1878
  }
1664
1879
  };
1665
1880
  }
1666
- function transformPageCSS(md2, id) {
1667
- const page = id.match(/(\d+)\.md$/)?.[1];
1668
- if (!page)
1669
- return md2;
1670
- const { isInsideCodeblocks } = getCodeBlocks(md2);
1671
- const result = md2.replace(
1672
- /(\n<style[^>]*?>)([\s\S]+?)(<\/style>)/g,
1673
- (full, start, css, end, index) => {
1674
- if (index < 0 || isInsideCodeblocks(index))
1675
- return full;
1676
- if (!start.includes("scoped"))
1677
- start = start.replace("<style", "<style scoped");
1678
- return `${start}
1679
- ${css}${end}`;
1680
- }
1681
- );
1682
- return result;
1683
- }
1684
- function transformMermaid(md2) {
1685
- return md2.replace(/^```mermaid\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", code = "") => {
1686
- code = code.trim();
1687
- options = options.trim() || "{}";
1688
- const encoded = base64.encode(code, true);
1689
- return `<Mermaid :code="'${encoded}'" v-bind="${options}" />`;
1690
- });
1691
- }
1692
- function transformPlantUml(md2, server) {
1693
- return md2.replace(/^```plantuml\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", content = "") => {
1694
- const code = encode2(content.trim());
1695
- options = options.trim() || "{}";
1696
- return `<PlantUml :code="'${code}'" :server="'${server}'" v-bind="${options}" />`;
1697
- });
1698
- }
1699
- function escapeVueInCode(md2) {
1700
- return md2.replace(/{{(.*?)}}/g, "&lbrace;&lbrace;$1&rbrace;&rbrace;");
1701
- }
1702
- async function loadShikiSetups(roots) {
1703
- const result = await loadSetups(
1704
- roots,
1705
- "shiki.ts",
1706
- {
1707
- /** @deprecated */
1708
- async loadTheme(path2) {
1709
- 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.");
1710
- return JSON.parse(await fs7.readFile(path2, "utf-8"));
1711
- }
1712
- },
1713
- {},
1714
- false
1715
- );
1716
- if ("theme" in result && "themes" in result)
1717
- delete result.theme;
1718
- if (result.theme && typeof result.theme !== "string" && !result.theme.name && !result.theme.tokenColors) {
1719
- result.themes = result.theme;
1720
- delete result.theme;
1721
- }
1722
- if (!result.theme && !result.themes) {
1723
- result.themes = {
1724
- dark: "vitesse-dark",
1725
- light: "vitesse-light"
1726
- };
1727
- }
1728
- if (result.themes)
1729
- result.defaultColor = false;
1730
- return result;
1731
- }
1732
1881
 
1733
1882
  // node/plugins/patchTransform.ts
1734
1883
  import { objectEntries } from "@antfu/utils";
@@ -1752,6 +1901,67 @@ function createFixPlugins(options) {
1752
1901
  ];
1753
1902
  }
1754
1903
 
1904
+ // node/plugins/monacoTypes.ts
1905
+ import fs6 from "node:fs/promises";
1906
+ import { dirname as dirname2, resolve as resolve4 } from "node:path";
1907
+ import { slash as slash3 } from "@antfu/utils";
1908
+ import fg3 from "fast-glob";
1909
+ import { findDepPkgJsonPath } from "vitefu";
1910
+ function createMonacoTypesLoader({ userRoot }) {
1911
+ const resolvedDepsMap = {};
1912
+ return {
1913
+ name: "slidev:monaco-types-loader",
1914
+ resolveId(id) {
1915
+ if (id.startsWith("/@slidev-monaco-types/"))
1916
+ return id;
1917
+ return null;
1918
+ },
1919
+ async load(id) {
1920
+ const matchResolve = id.match(/^\/\@slidev-monaco-types\/resolve\?pkg=(.*?)(?:&importer=(.*))?$/);
1921
+ if (matchResolve) {
1922
+ const [_, pkg, importer = userRoot] = matchResolve;
1923
+ const resolvedDeps = resolvedDepsMap[importer] ??= /* @__PURE__ */ new Set();
1924
+ if (resolvedDeps.has(pkg))
1925
+ return "";
1926
+ resolvedDeps.add(pkg);
1927
+ const pkgJsonPath = await findDepPkgJsonPath(pkg, importer);
1928
+ if (!pkgJsonPath)
1929
+ throw new Error(`Package "${pkg}" not found in "${importer}"`);
1930
+ const root = dirname2(pkgJsonPath);
1931
+ const pkgJson = JSON.parse(await fs6.readFile(pkgJsonPath, "utf-8"));
1932
+ const deps = pkgJson.dependencies ?? {};
1933
+ return [
1934
+ `import "/@slidev-monaco-types/load?root=${slash3(root)}&name=${pkgJson.name}"`,
1935
+ ...Object.keys(deps).map((dep) => `import "/@slidev-monaco-types/resolve?pkg=${dep}&importer=${slash3(root)}"`)
1936
+ ].join("\n");
1937
+ }
1938
+ const matchLoad = id.match(/^\/\@slidev-monaco-types\/load\?root=(.*?)&name=(.*)$/);
1939
+ if (matchLoad) {
1940
+ const [_, root, name] = matchLoad;
1941
+ const files = await fg3(
1942
+ [
1943
+ "**/*.ts",
1944
+ "**/*.mts",
1945
+ "**/*.cts",
1946
+ "package.json"
1947
+ ],
1948
+ {
1949
+ cwd: root,
1950
+ followSymbolicLinks: true,
1951
+ ignore: ["**/node_modules/**"]
1952
+ }
1953
+ );
1954
+ if (!files.length)
1955
+ return "";
1956
+ return [
1957
+ 'import { addFile } from "@slidev/client/setup/monaco.ts"',
1958
+ ...files.map((file) => `addFile(import(${JSON.stringify(`${toAtFS(resolve4(root, file))}?monaco-types&raw`)}), ${JSON.stringify(`node_modules/${name}/${file}`)})`)
1959
+ ].join("\n");
1960
+ }
1961
+ }
1962
+ };
1963
+ }
1964
+
1755
1965
  // node/plugins/preset.ts
1756
1966
  var customElements = /* @__PURE__ */ new Set([
1757
1967
  // katex
@@ -1796,7 +2006,7 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1796
2006
  mode,
1797
2007
  themeRoots,
1798
2008
  addonRoots,
1799
- clientRoot,
2009
+ roots,
1800
2010
  data: { config }
1801
2011
  } = options;
1802
2012
  const VuePlugin = Vue({
@@ -1815,7 +2025,7 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1815
2025
  const VueJsxPlugin = VueJsx(vuejsxOptions);
1816
2026
  const MarkdownPlugin = await createMarkdownPlugin(options, pluginOptions);
1817
2027
  const drawingData = await loadDrawings(options);
1818
- const publicRoots = themeRoots.map((i) => join8(i, "public")).filter(existsSync3);
2028
+ const publicRoots = [...themeRoots, ...addonRoots].map((i) => join6(i, "public")).filter(existsSync3);
1819
2029
  const plugins = [
1820
2030
  MarkdownPlugin,
1821
2031
  VueJsxPlugin,
@@ -1824,15 +2034,13 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1824
2034
  Components({
1825
2035
  extensions: ["vue", "md", "js", "ts", "jsx", "tsx"],
1826
2036
  dirs: [
1827
- join8(clientRoot, "builtin"),
1828
- join8(clientRoot, "components"),
1829
- ...themeRoots.map((i) => join8(i, "components")),
1830
- ...addonRoots.map((i) => join8(i, "components")),
2037
+ join6(options.clientRoot, "builtin"),
2038
+ ...roots.map((i) => join6(i, "components")),
1831
2039
  "src/components",
1832
2040
  "components",
1833
- join8(process2.cwd(), "components")
2041
+ join6(process.cwd(), "components")
1834
2042
  ],
1835
- include: [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/, /\.md$/],
2043
+ include: [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/, /\.md$/, /\.md\?vue/],
1836
2044
  exclude: [],
1837
2045
  resolvers: [
1838
2046
  IconsResolver({
@@ -1861,7 +2069,7 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1861
2069
  ...remoteAssetsOptions
1862
2070
  })) : null,
1863
2071
  ServerRef({
1864
- debug: process2.env.NODE_ENV === "development",
2072
+ debug: process.env.NODE_ENV === "development",
1865
2073
  state: {
1866
2074
  sync: false,
1867
2075
  nav: {
@@ -1881,7 +2089,7 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1881
2089
  }),
1882
2090
  createConfigPlugin(options),
1883
2091
  createClientSetupPlugin(options),
1884
- createMonacoTypesLoader(),
2092
+ createMonacoTypesLoader(options),
1885
2093
  createFixPlugins(options),
1886
2094
  publicRoots.length ? import("vite-plugin-static-copy").then((r) => r.viteStaticCopy({
1887
2095
  silent: true,
@@ -1894,12 +2102,14 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1894
2102
  dev: true,
1895
2103
  build: true
1896
2104
  })) : null,
1897
- config.css === "none" ? null : import("./unocss-6IVIFJMZ.mjs").then((r) => r.createUnocssPlugin(options, pluginOptions))
2105
+ config.css === "none" ? null : import("./unocss-M5KPNI4Z.mjs").then((r) => r.createUnocssPlugin(options, pluginOptions))
1898
2106
  ];
1899
2107
  return (await Promise.all(plugins)).flat().filter(notNullish2);
1900
2108
  }
1901
2109
 
1902
2110
  export {
2111
+ version,
2112
+ checkEngine,
1903
2113
  getIndexHtml,
1904
2114
  mergeViteConfigs,
1905
2115
  ViteSlidevPlugin