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