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

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,1906 +0,0 @@
1
- import {
2
- loadSetups
3
- } from "./chunk-CTBVOVLQ.mjs";
4
- import {
5
- generateGoogleFontsUrl,
6
- resolveGlobalImportPath,
7
- resolveImportPath,
8
- stringifyMarkdownTokens,
9
- toAtFS
10
- } from "./chunk-DWXI5WEO.mjs";
11
-
12
- // node/common.ts
13
- import { existsSync, promises as fs } from "node:fs";
14
- import { join } from "node:path";
15
- import { uniq } from "@antfu/utils";
16
- import { loadConfigFromFile, mergeConfig, resolveConfig } from "vite";
17
- async function getIndexHtml({ clientRoot, themeRoots, addonRoots, data, userRoot }) {
18
- let main = await fs.readFile(join(clientRoot, "index.html"), "utf-8");
19
- let head = "";
20
- let body = "";
21
- head += `<link rel="icon" href="${data.config.favicon}">`;
22
- const roots = uniq([
23
- ...themeRoots,
24
- ...addonRoots,
25
- userRoot
26
- ]);
27
- for (const root of roots) {
28
- const path2 = join(root, "index.html");
29
- if (!existsSync(path2))
30
- continue;
31
- const index = await fs.readFile(path2, "utf-8");
32
- head += `
33
- ${(index.match(/<head>([\s\S]*?)<\/head>/im)?.[1] || "").trim()}`;
34
- body += `
35
- ${(index.match(/<body>([\s\S]*?)<\/body>/im)?.[1] || "").trim()}`;
36
- }
37
- if (data.features.tweet)
38
- body += '\n<script async src="https://platform.twitter.com/widgets.js"></script>';
39
- if (data.config.fonts.webfonts.length && data.config.fonts.provider !== "none")
40
- head += `
41
- <link rel="stylesheet" href="${generateGoogleFontsUrl(data.config.fonts)}" type="text/css">`;
42
- main = main.replace("__ENTRY__", toAtFS(join(clientRoot, "main.ts"))).replace("<!-- head -->", head).replace("<!-- body -->", body);
43
- return main;
44
- }
45
- async function mergeViteConfigs({ addonRoots, themeRoots, entry }, viteConfig, config, command) {
46
- const configEnv = {
47
- mode: "development",
48
- command
49
- };
50
- const files = uniq([
51
- ...themeRoots,
52
- ...addonRoots
53
- ]).map((i) => join(i, "vite.config.ts"));
54
- for await (const file of files) {
55
- if (!existsSync(file))
56
- continue;
57
- const viteConfig2 = await loadConfigFromFile(configEnv, file);
58
- if (!viteConfig2?.config)
59
- continue;
60
- config = mergeConfig(config, viteConfig2.config);
61
- }
62
- config = mergeConfig(config, viteConfig);
63
- const localConfig = await resolveConfig({}, command, entry);
64
- config = mergeConfig(config, { slidev: localConfig.slidev || {} });
65
- return config;
66
- }
67
-
68
- // node/plugins/preset.ts
69
- import { join as join8 } from "node:path";
70
- import { existsSync as existsSync3 } from "node:fs";
71
- import process2 from "node:process";
72
- import { fileURLToPath } from "node:url";
73
- import Vue from "@vitejs/plugin-vue";
74
- import VueJsx from "@vitejs/plugin-vue-jsx";
75
- import Icons from "unplugin-icons/vite";
76
- import IconsResolver from "unplugin-icons/resolver";
77
- import Components from "unplugin-vue-components/vite";
78
- import ServerRef from "vite-plugin-vue-server-ref";
79
- import { notNullish as notNullish2 } from "@antfu/utils";
80
-
81
- // node/drawings.ts
82
- import { basename, dirname, join as join2, resolve } from "node:path";
83
- import fs2 from "fs-extra";
84
- import fg from "fast-glob";
85
- function resolveDrawingsDir(options) {
86
- return options.data.config.drawings.persist ? resolve(
87
- dirname(options.entry),
88
- options.data.config.drawings.persist
89
- ) : void 0;
90
- }
91
- async function loadDrawings(options) {
92
- const dir = resolveDrawingsDir(options);
93
- if (!dir || !fs2.existsSync(dir))
94
- return {};
95
- const files = await fg("*.svg", {
96
- onlyFiles: true,
97
- cwd: dir,
98
- absolute: true,
99
- suppressErrors: true
100
- });
101
- const obj = {};
102
- await Promise.all(files.map(async (path2) => {
103
- const num = +basename(path2, ".svg");
104
- if (Number.isNaN(num))
105
- return;
106
- const content = await fs2.readFile(path2, "utf8");
107
- const lines = content.split(/\n/g);
108
- obj[num.toString()] = lines.slice(1, -1).join("\n");
109
- }));
110
- return obj;
111
- }
112
- async function writeDrawings(options, drawing) {
113
- const dir = resolveDrawingsDir(options);
114
- if (!dir)
115
- return;
116
- const width = options.data.config.canvasWidth;
117
- const height = Math.round(width / options.data.config.aspectRatio);
118
- const SVG_HEAD = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">`;
119
- await fs2.ensureDir(dir);
120
- return Promise.all(
121
- Object.entries(drawing).map(async ([key, value]) => {
122
- if (!value)
123
- return;
124
- const svg = `${SVG_HEAD}
125
- ${value}
126
- </svg>`;
127
- await fs2.writeFile(join2(dir, `${key}.svg`), svg, "utf-8");
128
- })
129
- );
130
- }
131
-
132
- // node/plugins/extendConfig.ts
133
- import { dirname as dirname3, join as join4 } from "node:path";
134
- import { mergeConfig as mergeConfig2 } from "vite";
135
- import isInstalledGlobally from "is-installed-globally";
136
- import { uniq as uniq2 } from "@antfu/utils";
137
-
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
- }
186
-
187
- // node/plugins/extendConfig.ts
188
- var EXCLUDE = [
189
- "@slidev/shared",
190
- "@slidev/types",
191
- "@slidev/client",
192
- "@slidev/client/constants",
193
- "@slidev/client/logic/dark",
194
- "@vueuse/core",
195
- "@vueuse/shared",
196
- "@unocss/reset",
197
- "unocss",
198
- "mermaid",
199
- "vue-demi",
200
- "vue"
201
- ];
202
- function createConfigPlugin(options) {
203
- return {
204
- name: "slidev:config",
205
- async config(config) {
206
- const injection = {
207
- define: getDefine(options),
208
- resolve: {
209
- alias: {
210
- "@slidev/client/": `${toAtFS(options.clientRoot)}/`
211
- },
212
- dedupe: ["vue"]
213
- },
214
- optimizeDeps: {
215
- exclude: EXCLUDE
216
- },
217
- css: options.data.config.css === "unocss" ? {
218
- postcss: {
219
- plugins: [
220
- await import("postcss-nested").then((r) => (r.default || r)())
221
- ]
222
- }
223
- } : {},
224
- server: {
225
- fs: {
226
- 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
- ] : []
234
- ])
235
- }
236
- },
237
- publicDir: join4(options.userRoot, "public")
238
- };
239
- injection.resolve ||= {};
240
- injection.resolve.alias ||= {};
241
- if (isInstalledGlobally) {
242
- injection.cacheDir = join4(options.cliRoot, "node_modules/.vite");
243
- injection.root = options.cliRoot;
244
- }
245
- injection.resolve.alias.vue = await resolveImportPath("vue/dist/vue.esm-browser.js", true);
246
- return mergeConfig2(injection, config);
247
- },
248
- configureServer(server) {
249
- return () => {
250
- server.middlewares.use(async (req, res, next) => {
251
- if (req.url.endsWith(".html")) {
252
- res.setHeader("Content-Type", "text/html");
253
- res.statusCode = 200;
254
- res.end(await getIndexHtml(options));
255
- return;
256
- }
257
- next();
258
- });
259
- };
260
- }
261
- };
262
- }
263
- function getDefine(options) {
264
- return {
265
- __DEV__: options.mode === "dev" ? "true" : "false",
266
- __SLIDEV_CLIENT_ROOT__: JSON.stringify(toAtFS(options.clientRoot)),
267
- __SLIDEV_HASH_ROUTE__: JSON.stringify(options.data.config.routerMode === "hash"),
268
- __SLIDEV_FEATURE_DRAWINGS__: JSON.stringify(options.data.config.drawings.enabled === true || options.data.config.drawings.enabled === options.mode),
269
- __SLIDEV_FEATURE_EDITOR__: JSON.stringify(options.mode === "dev" && options.data.config.editor !== false),
270
- __SLIDEV_FEATURE_DRAWINGS_PERSIST__: JSON.stringify(!!options.data.config.drawings.persist === true),
271
- __SLIDEV_FEATURE_RECORD__: JSON.stringify(options.data.config.record === true || options.data.config.record === options.mode),
272
- __SLIDEV_FEATURE_PRESENTER__: JSON.stringify(options.data.config.presenter === true || options.data.config.presenter === options.mode),
273
- __SLIDEV_HAS_SERVER__: options.mode !== "build" ? "true" : "false"
274
- };
275
- }
276
-
277
- // 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";
280
- import fg2 from "fast-glob";
281
- import fs4 from "fs-extra";
282
- import Markdown from "markdown-it";
283
- import { bold, gray, red, yellow } from "kolorist";
284
- import mila from "markdown-it-link-attributes";
285
- import * as parser from "@slidev/parser/fs";
286
- 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);
315
- }
316
- });
317
- });
318
- }
319
- var md = Markdown({ html: true });
320
- md.use(mila, {
321
- attrs: {
322
- target: "_blank",
323
- rel: "noopener"
324
- }
325
- });
326
- function prepareSlideInfo(data) {
327
- return {
328
- ...data,
329
- noteHTML: md.render(data?.note || "")
330
- };
331
- }
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) || []);
629
- }
630
- function getFrontmatter(pageNo) {
631
- return {
632
- ...data.headmatter?.defaults || {},
633
- ...data.slides[pageNo]?.frontmatter || {}
634
- };
635
- }
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;
678
- }
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 }>()`);
732
- }
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;
760
- }
761
- async function resolveUrl(id) {
762
- return toAtFS(await resolveImportPath(id, true));
763
- }
764
- function resolveUrlOfClient(name) {
765
- return toAtFS(join5(clientRoot, name));
766
- }
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
- );
802
- }
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"');
811
- }
812
- return imports.join("\n");
813
- }
814
- async function generateMonacoTypes() {
815
- return `void 0; ${parser.scanMonacoModules(data.raw).map((i) => `import('/@slidev-monaco-types/${i}')`).join("\n")}`;
816
- }
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");
832
- }
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");
855
- }
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}]
896
- }
897
- }
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}]
915
- }
916
- }
917
- `;
918
- }
919
- }
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];
936
- }
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;
944
- },
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
- }
960
- }
961
- };
962
- }
963
-
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
1006
- );
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;
1014
- }
1015
- return null;
1016
- }
1017
- };
1018
- }
1019
-
1020
- // 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");
1080
- }
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]}`;
1112
- } 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");
1129
- }
1130
- return checkbox;
1131
- }
1132
- function createLabelBeginToken(id) {
1133
- const labelBeginToken = new Token("taskListItemLabel_open", "", 1);
1134
- labelBeginToken.attrSet("id", id);
1135
- return labelBeginToken;
1136
- }
1137
- function createLabelEndToken() {
1138
- return new Token("taskListItemLabel_close", "", -1);
1139
- }
1140
- function isInline(token) {
1141
- return token.type === "inline";
1142
- }
1143
- function isParagraph(token) {
1144
- return token.type === "paragraph_open";
1145
- }
1146
- function isListItem(token) {
1147
- return token.type === "list_item_open";
1148
- }
1149
- function startsWithTodoMarkdown(token) {
1150
- return checkboxRegex.test(token.content);
1151
- }
1152
-
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";
1159
-
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;
1173
- return {
1174
- can_open,
1175
- can_close
1176
- };
1177
- }
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;
1259
- }
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;
1269
- }
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"]
1302
- });
1303
- md2.renderer.rules.math_inline = inlineRenderer;
1304
- md2.renderer.rules.math_block = blockRenderer;
1305
- }
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}>`;
1325
- }
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];
1342
- }
1343
- return langObject;
1344
- }
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
- }
1351
- }
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);
1360
- }
1361
- return [langToUse, prismLang];
1362
- }
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);
1406
- }
1407
-
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;
1454
- }
1455
- }
1456
- } else if (testLine(line, regexp, regionName, true)) {
1457
- return { start, end: lineId, regexp };
1458
- }
1459
- }
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`);
1478
- }
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
- );
1489
- }
1490
- }
1491
- return `${firstLine}
1492
- ${content}
1493
- \`\`\``;
1494
- }
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));
1533
- }
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;
1578
- }
1579
- }
1580
- });
1581
- }
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
- `;
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, "");
1614
- }
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
- `;
1626
- prevSlot = true;
1627
- }
1628
- });
1629
- if (prevSlot)
1630
- lines[lines.length - 1] += "\n\n</template>";
1631
- return lines.join("\n");
1632
- }
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
-
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
- });
1656
- 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);
1663
- }
1664
- };
1665
- }
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
-
1733
- // node/plugins/patchTransform.ts
1734
- import { objectEntries } from "@antfu/utils";
1735
- function createFixPlugins(options) {
1736
- const define = objectEntries(getDefine(options));
1737
- return [
1738
- {
1739
- name: "slidev:flags",
1740
- enforce: "pre",
1741
- transform(code, id) {
1742
- if (id.match(/\.vue($|\?)/)) {
1743
- const original = code;
1744
- define.forEach(([from, to]) => {
1745
- code = code.replace(new RegExp(from, "g"), to);
1746
- });
1747
- if (original !== code)
1748
- return code;
1749
- }
1750
- }
1751
- }
1752
- ];
1753
- }
1754
-
1755
- // node/plugins/preset.ts
1756
- var customElements = /* @__PURE__ */ new Set([
1757
- // katex
1758
- "annotation",
1759
- "math",
1760
- "menclose",
1761
- "mfrac",
1762
- "mglyph",
1763
- "mi",
1764
- "mlabeledtr",
1765
- "mn",
1766
- "mo",
1767
- "mover",
1768
- "mpadded",
1769
- "mphantom",
1770
- "mroot",
1771
- "mrow",
1772
- "mspace",
1773
- "msqrt",
1774
- "mstyle",
1775
- "msub",
1776
- "msubsup",
1777
- "msup",
1778
- "mtable",
1779
- "mtd",
1780
- "mtext",
1781
- "mtr",
1782
- "munder",
1783
- "munderover",
1784
- "semantics"
1785
- ]);
1786
- async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
1787
- const {
1788
- vue: vueOptions = {},
1789
- vuejsx: vuejsxOptions = {},
1790
- components: componentsOptions = {},
1791
- icons: iconsOptions = {},
1792
- remoteAssets: remoteAssetsOptions = {},
1793
- serverRef: serverRefOptions = {}
1794
- } = pluginOptions;
1795
- const {
1796
- mode,
1797
- themeRoots,
1798
- addonRoots,
1799
- clientRoot,
1800
- data: { config }
1801
- } = options;
1802
- const VuePlugin = Vue({
1803
- include: [/\.vue$/, /\.md$/],
1804
- exclude: [],
1805
- template: {
1806
- compilerOptions: {
1807
- isCustomElement(tag) {
1808
- return customElements.has(tag);
1809
- }
1810
- },
1811
- ...vueOptions?.template
1812
- },
1813
- ...vueOptions
1814
- });
1815
- const VueJsxPlugin = VueJsx(vuejsxOptions);
1816
- const MarkdownPlugin = await createMarkdownPlugin(options, pluginOptions);
1817
- const drawingData = await loadDrawings(options);
1818
- const publicRoots = themeRoots.map((i) => join8(i, "public")).filter(existsSync3);
1819
- const plugins = [
1820
- MarkdownPlugin,
1821
- VueJsxPlugin,
1822
- VuePlugin,
1823
- createSlidesLoader(options, pluginOptions, serverOptions),
1824
- Components({
1825
- extensions: ["vue", "md", "js", "ts", "jsx", "tsx"],
1826
- dirs: [
1827
- join8(clientRoot, "builtin"),
1828
- join8(clientRoot, "components"),
1829
- ...themeRoots.map((i) => join8(i, "components")),
1830
- ...addonRoots.map((i) => join8(i, "components")),
1831
- "src/components",
1832
- "components",
1833
- join8(process2.cwd(), "components")
1834
- ],
1835
- include: [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/, /\.md$/],
1836
- exclude: [],
1837
- resolvers: [
1838
- IconsResolver({
1839
- prefix: "",
1840
- customCollections: Object.keys(iconsOptions.customCollections || [])
1841
- })
1842
- ],
1843
- dts: false,
1844
- ...componentsOptions
1845
- }),
1846
- Icons({
1847
- defaultClass: "slidev-icon",
1848
- collectionsNodeResolvePath: fileURLToPath(import.meta.url),
1849
- ...iconsOptions
1850
- }),
1851
- config.remoteAssets === true || config.remoteAssets === mode ? import("vite-plugin-remote-assets").then((r) => r.VitePluginRemoteAssets({
1852
- rules: [
1853
- ...r.DefaultRules,
1854
- {
1855
- match: /\b(https?:\/\/image.unsplash\.com.*?)(?=[`'")\]])/ig,
1856
- ext: ".png"
1857
- }
1858
- ],
1859
- resolveMode: (id) => id.endsWith("index.html") ? "relative" : "@fs",
1860
- awaitDownload: mode === "build",
1861
- ...remoteAssetsOptions
1862
- })) : null,
1863
- ServerRef({
1864
- debug: process2.env.NODE_ENV === "development",
1865
- state: {
1866
- sync: false,
1867
- nav: {
1868
- page: 0,
1869
- clicks: 0
1870
- },
1871
- drawings: drawingData,
1872
- ...serverRefOptions.state
1873
- },
1874
- onChanged(key, data, patch, timestamp) {
1875
- serverRefOptions.onChanged && serverRefOptions.onChanged(key, data, patch, timestamp);
1876
- if (!options.data.config.drawings.persist)
1877
- return;
1878
- if (key === "drawings")
1879
- writeDrawings(options, patch ?? data);
1880
- }
1881
- }),
1882
- createConfigPlugin(options),
1883
- createClientSetupPlugin(options),
1884
- createMonacoTypesLoader(),
1885
- createFixPlugins(options),
1886
- publicRoots.length ? import("vite-plugin-static-copy").then((r) => r.viteStaticCopy({
1887
- silent: true,
1888
- targets: publicRoots.map((r2) => ({
1889
- src: `${r2}/*`,
1890
- dest: "theme"
1891
- }))
1892
- })) : null,
1893
- options.inspect ? import("vite-plugin-inspect").then((r) => (r.default || r)({
1894
- dev: true,
1895
- build: true
1896
- })) : null,
1897
- config.css === "none" ? null : import("./unocss-6IVIFJMZ.mjs").then((r) => r.createUnocssPlugin(options, pluginOptions))
1898
- ];
1899
- return (await Promise.all(plugins)).flat().filter(notNullish2);
1900
- }
1901
-
1902
- export {
1903
- getIndexHtml,
1904
- mergeViteConfigs,
1905
- ViteSlidevPlugin
1906
- };