@slidev/cli 0.43.0-beta.3 → 0.43.0-beta.5
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-BMJKCMWK.js → build-2HVDTXMU.js} +5 -5
- package/dist/{build-4JRH4QXK.mjs → build-UUIAUK3H.mjs} +1 -1
- package/dist/{chunk-O2663AU4.js → chunk-2BMKFV7C.js} +33 -15
- package/dist/{chunk-SWZ5SM6V.mjs → chunk-BAK2YZDZ.mjs} +28 -10
- package/dist/chunk-DXJWPFLI.js +1640 -0
- package/dist/chunk-IMVZEGBY.mjs +1640 -0
- package/dist/cli.js +29 -28
- package/dist/cli.mjs +5 -4
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -2
- package/package.json +9 -9
- package/dist/chunk-WAD6PHVC.mjs +0 -4842
- package/dist/chunk-XPOF53GO.js +0 -4842
|
@@ -0,0 +1,1640 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadSetups
|
|
3
|
+
} from "./chunk-JDHANZ37.mjs";
|
|
4
|
+
import {
|
|
5
|
+
generateGoogleFontsUrl,
|
|
6
|
+
resolveGlobalImportPath,
|
|
7
|
+
resolveImportPath,
|
|
8
|
+
stringifyMarkdownTokens,
|
|
9
|
+
toAtFS
|
|
10
|
+
} from "./chunk-ZEKM4EGL.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__commonJS,
|
|
13
|
+
__require,
|
|
14
|
+
__toESM
|
|
15
|
+
} from "./chunk-QHOBBTS4.mjs";
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
|
|
18
|
+
var require_fast_deep_equal = __commonJS({
|
|
19
|
+
"../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
|
|
20
|
+
"use strict";
|
|
21
|
+
module.exports = function equal2(a, b) {
|
|
22
|
+
if (a === b)
|
|
23
|
+
return true;
|
|
24
|
+
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
25
|
+
if (a.constructor !== b.constructor)
|
|
26
|
+
return false;
|
|
27
|
+
var length, i, keys;
|
|
28
|
+
if (Array.isArray(a)) {
|
|
29
|
+
length = a.length;
|
|
30
|
+
if (length != b.length)
|
|
31
|
+
return false;
|
|
32
|
+
for (i = length; i-- !== 0; )
|
|
33
|
+
if (!equal2(a[i], b[i]))
|
|
34
|
+
return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (a.constructor === RegExp)
|
|
38
|
+
return a.source === b.source && a.flags === b.flags;
|
|
39
|
+
if (a.valueOf !== Object.prototype.valueOf)
|
|
40
|
+
return a.valueOf() === b.valueOf();
|
|
41
|
+
if (a.toString !== Object.prototype.toString)
|
|
42
|
+
return a.toString() === b.toString();
|
|
43
|
+
keys = Object.keys(a);
|
|
44
|
+
length = keys.length;
|
|
45
|
+
if (length !== Object.keys(b).length)
|
|
46
|
+
return false;
|
|
47
|
+
for (i = length; i-- !== 0; )
|
|
48
|
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
|
|
49
|
+
return false;
|
|
50
|
+
for (i = length; i-- !== 0; ) {
|
|
51
|
+
var key = keys[i];
|
|
52
|
+
if (!equal2(a[key], b[key]))
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return a !== a && b !== b;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// node/common.ts
|
|
63
|
+
import { existsSync, promises as fs } from "node:fs";
|
|
64
|
+
import { join } from "node:path";
|
|
65
|
+
import { uniq } from "@antfu/utils";
|
|
66
|
+
import { loadConfigFromFile, mergeConfig } from "vite";
|
|
67
|
+
async function getIndexHtml({ clientRoot, themeRoots, addonRoots, data, userRoot }) {
|
|
68
|
+
let main = await fs.readFile(join(clientRoot, "index.html"), "utf-8");
|
|
69
|
+
let head = "";
|
|
70
|
+
let body = "";
|
|
71
|
+
head += `<link rel="icon" href="${data.config.favicon}">`;
|
|
72
|
+
const roots = uniq([
|
|
73
|
+
...themeRoots,
|
|
74
|
+
...addonRoots,
|
|
75
|
+
userRoot
|
|
76
|
+
]);
|
|
77
|
+
for (const root of roots) {
|
|
78
|
+
const path = join(root, "index.html");
|
|
79
|
+
if (!existsSync(path))
|
|
80
|
+
continue;
|
|
81
|
+
const index = await fs.readFile(path, "utf-8");
|
|
82
|
+
head += `
|
|
83
|
+
${(index.match(/<head>([\s\S]*?)<\/head>/im)?.[1] || "").trim()}`;
|
|
84
|
+
body += `
|
|
85
|
+
${(index.match(/<body>([\s\S]*?)<\/body>/im)?.[1] || "").trim()}`;
|
|
86
|
+
}
|
|
87
|
+
if (data.features.tweet)
|
|
88
|
+
body += '\n<script async src="https://platform.twitter.com/widgets.js"></script>';
|
|
89
|
+
if (data.config.fonts.webfonts.length && data.config.fonts.provider !== "none")
|
|
90
|
+
head += `
|
|
91
|
+
<link rel="stylesheet" href="${generateGoogleFontsUrl(data.config.fonts)}" type="text/css">`;
|
|
92
|
+
main = main.replace("__ENTRY__", toAtFS(join(clientRoot, "main.ts"))).replace("<!-- head -->", head).replace("<!-- body -->", body);
|
|
93
|
+
return main;
|
|
94
|
+
}
|
|
95
|
+
async function mergeViteConfigs({ addonRoots, themeRoots }, viteConfig, config, command) {
|
|
96
|
+
const configEnv = {
|
|
97
|
+
mode: "development",
|
|
98
|
+
command
|
|
99
|
+
};
|
|
100
|
+
const files = uniq([
|
|
101
|
+
...themeRoots,
|
|
102
|
+
...addonRoots
|
|
103
|
+
]).map((i) => join(i, "vite.config.ts"));
|
|
104
|
+
for await (const file of files) {
|
|
105
|
+
if (!existsSync(file))
|
|
106
|
+
continue;
|
|
107
|
+
const viteConfig2 = await loadConfigFromFile(configEnv, file);
|
|
108
|
+
if (!viteConfig2?.config)
|
|
109
|
+
continue;
|
|
110
|
+
config = mergeConfig(config, viteConfig2.config);
|
|
111
|
+
}
|
|
112
|
+
return mergeConfig(viteConfig, config);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// node/plugins/preset.ts
|
|
116
|
+
import { join as join8 } from "node:path";
|
|
117
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
118
|
+
import process3 from "node:process";
|
|
119
|
+
import Vue from "@vitejs/plugin-vue";
|
|
120
|
+
import VueJsx from "@vitejs/plugin-vue-jsx";
|
|
121
|
+
import Icons from "unplugin-icons/vite";
|
|
122
|
+
import IconsResolver from "unplugin-icons/resolver";
|
|
123
|
+
import Components from "unplugin-vue-components/vite";
|
|
124
|
+
import ServerRef from "vite-plugin-vue-server-ref";
|
|
125
|
+
import { notNullish as notNullish2 } from "@antfu/utils";
|
|
126
|
+
|
|
127
|
+
// node/drawings.ts
|
|
128
|
+
import { basename, dirname, join as join2, resolve } from "node:path";
|
|
129
|
+
import fs2 from "fs-extra";
|
|
130
|
+
import fg from "fast-glob";
|
|
131
|
+
function resolveDrawingsDir(options) {
|
|
132
|
+
return options.data.config.drawings.persist ? resolve(
|
|
133
|
+
dirname(options.entry),
|
|
134
|
+
options.data.config.drawings.persist
|
|
135
|
+
) : void 0;
|
|
136
|
+
}
|
|
137
|
+
async function loadDrawings(options) {
|
|
138
|
+
const dir = resolveDrawingsDir(options);
|
|
139
|
+
if (!dir || !fs2.existsSync(dir))
|
|
140
|
+
return {};
|
|
141
|
+
const files = await fg("*.svg", {
|
|
142
|
+
onlyFiles: true,
|
|
143
|
+
cwd: dir,
|
|
144
|
+
absolute: true,
|
|
145
|
+
suppressErrors: true
|
|
146
|
+
});
|
|
147
|
+
const obj = {};
|
|
148
|
+
await Promise.all(files.map(async (path) => {
|
|
149
|
+
const num = +basename(path, ".svg");
|
|
150
|
+
if (Number.isNaN(num))
|
|
151
|
+
return;
|
|
152
|
+
const content = await fs2.readFile(path, "utf8");
|
|
153
|
+
const lines = content.split(/\n/g);
|
|
154
|
+
obj[num.toString()] = lines.slice(1, -1).join("\n");
|
|
155
|
+
}));
|
|
156
|
+
return obj;
|
|
157
|
+
}
|
|
158
|
+
async function writeDrawings(options, drawing) {
|
|
159
|
+
const dir = resolveDrawingsDir(options);
|
|
160
|
+
if (!dir)
|
|
161
|
+
return;
|
|
162
|
+
const width = options.data.config.canvasWidth;
|
|
163
|
+
const height = Math.round(width / options.data.config.aspectRatio);
|
|
164
|
+
const SVG_HEAD = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">`;
|
|
165
|
+
await fs2.ensureDir(dir);
|
|
166
|
+
return Promise.all(
|
|
167
|
+
Object.entries(drawing).map(async ([key, value]) => {
|
|
168
|
+
if (!value)
|
|
169
|
+
return;
|
|
170
|
+
const svg = `${SVG_HEAD}
|
|
171
|
+
${value}
|
|
172
|
+
</svg>`;
|
|
173
|
+
await fs2.writeFile(join2(dir, `${key}.svg`), svg, "utf-8");
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// node/plugins/extendConfig.ts
|
|
179
|
+
import { dirname as dirname3, join as join4 } from "node:path";
|
|
180
|
+
import { mergeConfig as mergeConfig2 } from "vite";
|
|
181
|
+
import isInstalledGlobally from "is-installed-globally";
|
|
182
|
+
import { uniq as uniq2 } from "@antfu/utils";
|
|
183
|
+
|
|
184
|
+
// ../client/package.json
|
|
185
|
+
var dependencies = {
|
|
186
|
+
"@antfu/utils": "^0.7.6",
|
|
187
|
+
"@slidev/parser": "workspace:*",
|
|
188
|
+
"@slidev/types": "workspace:*",
|
|
189
|
+
"@unocss/reset": "^0.55.6",
|
|
190
|
+
"@vueuse/core": "^10.4.1",
|
|
191
|
+
"@vueuse/head": "^1.3.1",
|
|
192
|
+
"@vueuse/math": "^10.4.1",
|
|
193
|
+
"@vueuse/motion": "^2.0.0",
|
|
194
|
+
codemirror: "^5.65.5",
|
|
195
|
+
defu: "^6.1.2",
|
|
196
|
+
drauu: "^0.3.5",
|
|
197
|
+
"file-saver": "^2.0.5",
|
|
198
|
+
"fuse.js": "^6.6.2",
|
|
199
|
+
"js-base64": "^3.7.5",
|
|
200
|
+
"js-yaml": "^4.1.0",
|
|
201
|
+
katex: "^0.16.8",
|
|
202
|
+
mermaid: "^10.4.0",
|
|
203
|
+
"monaco-editor": "^0.37.1",
|
|
204
|
+
nanoid: "^4.0.2",
|
|
205
|
+
prettier: "^3.0.3",
|
|
206
|
+
recordrtc: "^5.6.2",
|
|
207
|
+
resolve: "^1.22.4",
|
|
208
|
+
unocss: "^0.55.6",
|
|
209
|
+
"vite-plugin-windicss": "^1.9.1",
|
|
210
|
+
vue: "^3.3.4",
|
|
211
|
+
"vue-router": "^4.2.4",
|
|
212
|
+
"vue-starport": "^0.3.0",
|
|
213
|
+
windicss: "^3.5.6"
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// node/vite/searchRoot.ts
|
|
217
|
+
import fs3 from "node:fs";
|
|
218
|
+
import { dirname as dirname2, join as join3 } from "node:path";
|
|
219
|
+
var ROOT_FILES = [
|
|
220
|
+
// '.git',
|
|
221
|
+
// https://pnpm.js.org/workspaces/
|
|
222
|
+
"pnpm-workspace.yaml"
|
|
223
|
+
// https://rushjs.io/pages/advanced/config_files/
|
|
224
|
+
// 'rush.json',
|
|
225
|
+
// https://nx.dev/latest/react/getting-started/nx-setup
|
|
226
|
+
// 'workspace.json',
|
|
227
|
+
// 'nx.json'
|
|
228
|
+
];
|
|
229
|
+
function hasWorkspacePackageJSON(root) {
|
|
230
|
+
const path = join3(root, "package.json");
|
|
231
|
+
try {
|
|
232
|
+
fs3.accessSync(path, fs3.constants.R_OK);
|
|
233
|
+
} catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
const content = JSON.parse(fs3.readFileSync(path, "utf-8")) || {};
|
|
237
|
+
return !!content.workspaces;
|
|
238
|
+
}
|
|
239
|
+
function hasRootFile(root) {
|
|
240
|
+
return ROOT_FILES.some((file) => fs3.existsSync(join3(root, file)));
|
|
241
|
+
}
|
|
242
|
+
function hasPackageJSON(root) {
|
|
243
|
+
const path = join3(root, "package.json");
|
|
244
|
+
return fs3.existsSync(path);
|
|
245
|
+
}
|
|
246
|
+
function searchForPackageRoot(current, root = current) {
|
|
247
|
+
if (hasPackageJSON(current))
|
|
248
|
+
return current;
|
|
249
|
+
const dir = dirname2(current);
|
|
250
|
+
if (!dir || dir === current)
|
|
251
|
+
return root;
|
|
252
|
+
return searchForPackageRoot(dir, root);
|
|
253
|
+
}
|
|
254
|
+
function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
|
|
255
|
+
if (hasRootFile(current))
|
|
256
|
+
return current;
|
|
257
|
+
if (hasWorkspacePackageJSON(current))
|
|
258
|
+
return current;
|
|
259
|
+
const dir = dirname2(current);
|
|
260
|
+
if (!dir || dir === current)
|
|
261
|
+
return root;
|
|
262
|
+
return searchForWorkspaceRoot(dir, root);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// node/plugins/extendConfig.ts
|
|
266
|
+
var EXCLUDE = [
|
|
267
|
+
"@slidev/shared",
|
|
268
|
+
"@slidev/types",
|
|
269
|
+
"@slidev/client",
|
|
270
|
+
"@slidev/client/constants",
|
|
271
|
+
"@slidev/client/logic/dark",
|
|
272
|
+
"@vueuse/core",
|
|
273
|
+
"@vueuse/shared",
|
|
274
|
+
"@unocss/reset",
|
|
275
|
+
"unocss",
|
|
276
|
+
"mermaid",
|
|
277
|
+
"vite-plugin-windicss",
|
|
278
|
+
"vue-demi",
|
|
279
|
+
"vue"
|
|
280
|
+
];
|
|
281
|
+
function createConfigPlugin(options) {
|
|
282
|
+
return {
|
|
283
|
+
name: "slidev:config",
|
|
284
|
+
async config(config) {
|
|
285
|
+
const injection = {
|
|
286
|
+
define: getDefine(options),
|
|
287
|
+
resolve: {
|
|
288
|
+
alias: {
|
|
289
|
+
"@slidev/client/": `${toAtFS(options.clientRoot)}/`
|
|
290
|
+
},
|
|
291
|
+
dedupe: ["vue"]
|
|
292
|
+
},
|
|
293
|
+
optimizeDeps: {
|
|
294
|
+
include: [
|
|
295
|
+
...Object.keys(dependencies).filter((i) => !EXCLUDE.includes(i)),
|
|
296
|
+
"codemirror/mode/javascript/javascript",
|
|
297
|
+
"codemirror/mode/css/css",
|
|
298
|
+
"codemirror/mode/markdown/markdown",
|
|
299
|
+
"codemirror/mode/xml/xml",
|
|
300
|
+
"codemirror/mode/htmlmixed/htmlmixed",
|
|
301
|
+
"codemirror/addon/display/placeholder",
|
|
302
|
+
"prettier/plugins/babel",
|
|
303
|
+
"prettier/plugins/html",
|
|
304
|
+
"prettier/plugins/typescript",
|
|
305
|
+
"mermaid/dist/mermaid.esm.min.mjs",
|
|
306
|
+
"mermaid/dist/mermaid.esm.mjs",
|
|
307
|
+
"vite-plugin-vue-server-ref/client"
|
|
308
|
+
],
|
|
309
|
+
exclude: EXCLUDE
|
|
310
|
+
},
|
|
311
|
+
css: options.data.config.css === "unocss" ? {
|
|
312
|
+
postcss: {
|
|
313
|
+
plugins: [
|
|
314
|
+
await import("postcss-nested").then((r) => (r.default || r)())
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
} : {},
|
|
318
|
+
server: {
|
|
319
|
+
fs: {
|
|
320
|
+
strict: true,
|
|
321
|
+
allow: uniq2([
|
|
322
|
+
searchForWorkspaceRoot(options.userRoot),
|
|
323
|
+
searchForWorkspaceRoot(options.cliRoot),
|
|
324
|
+
...isInstalledGlobally ? [dirname3(resolveGlobalImportPath("@slidev/client/package.json")), dirname3(resolveGlobalImportPath("katex/package.json"))] : []
|
|
325
|
+
])
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
publicDir: join4(options.userRoot, "public")
|
|
329
|
+
};
|
|
330
|
+
if (isInstalledGlobally) {
|
|
331
|
+
injection.cacheDir = join4(options.cliRoot, "node_modules/.vite");
|
|
332
|
+
injection.root = options.cliRoot;
|
|
333
|
+
injection.resolve.alias.vue = `${resolveImportPath("vue/dist/vue.esm-browser.js", true)}`;
|
|
334
|
+
}
|
|
335
|
+
return mergeConfig2(injection, config);
|
|
336
|
+
},
|
|
337
|
+
configureServer(server) {
|
|
338
|
+
return () => {
|
|
339
|
+
server.middlewares.use(async (req, res, next) => {
|
|
340
|
+
if (req.url.endsWith(".html")) {
|
|
341
|
+
res.setHeader("Content-Type", "text/html");
|
|
342
|
+
res.statusCode = 200;
|
|
343
|
+
res.end(await getIndexHtml(options));
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
next();
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function getDefine(options) {
|
|
353
|
+
return {
|
|
354
|
+
__DEV__: options.mode === "dev" ? "true" : "false",
|
|
355
|
+
__SLIDEV_CLIENT_ROOT__: JSON.stringify(toAtFS(options.clientRoot)),
|
|
356
|
+
__SLIDEV_HASH_ROUTE__: JSON.stringify(options.data.config.routerMode === "hash"),
|
|
357
|
+
__SLIDEV_FEATURE_DRAWINGS__: JSON.stringify(options.data.config.drawings.enabled === true || options.data.config.drawings.enabled === options.mode),
|
|
358
|
+
__SLIDEV_FEATURE_EDITOR__: JSON.stringify(options.mode === "dev" && options.data.config.editor !== false),
|
|
359
|
+
__SLIDEV_FEATURE_DRAWINGS_PERSIST__: JSON.stringify(!!options.data.config.drawings.persist === true),
|
|
360
|
+
__SLIDEV_FEATURE_RECORD__: JSON.stringify(options.data.config.record === true || options.data.config.record === options.mode),
|
|
361
|
+
__SLIDEV_FEATURE_PRESENTER__: JSON.stringify(options.data.config.presenter === true || options.data.config.presenter === options.mode),
|
|
362
|
+
__SLIDEV_HAS_SERVER__: options.mode !== "build" ? "true" : "false"
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// node/plugins/loaders.ts
|
|
367
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
|
368
|
+
import { basename as basename2, join as join5 } from "node:path";
|
|
369
|
+
import process from "node:process";
|
|
370
|
+
import { isString, notNullish, objectMap, range, slash, uniq as uniq3 } from "@antfu/utils";
|
|
371
|
+
import fg2 from "fast-glob";
|
|
372
|
+
import fs4, { existsSync as existsSync2 } from "fs-extra";
|
|
373
|
+
import Markdown from "markdown-it";
|
|
374
|
+
import { bold, gray, red, yellow } from "kolorist";
|
|
375
|
+
import mila from "markdown-it-link-attributes";
|
|
376
|
+
import * as parser from "@slidev/parser/fs";
|
|
377
|
+
var regexId = /^\/\@slidev\/slide\/(\d+)\.(md|json)(?:\?import)?$/;
|
|
378
|
+
var regexIdQuery = /(\d+?)\.(md|json)$/;
|
|
379
|
+
var vueContextImports = [
|
|
380
|
+
'import { inject as _vueInject, toRef as _vueToRef } from "vue"',
|
|
381
|
+
`import {
|
|
382
|
+
injectionSlidevContext as _injectionSlidevContext,
|
|
383
|
+
injectionClicks as _injectionClicks,
|
|
384
|
+
injectionCurrentPage as _injectionCurrentPage,
|
|
385
|
+
injectionSlideContext as _injectionSlideContext,
|
|
386
|
+
} from "@slidev/client/constants.ts"`.replace(/\n\s+/g, "\n"),
|
|
387
|
+
"const $slidev = _vueInject(_injectionSlidevContext)",
|
|
388
|
+
'const $nav = _vueToRef($slidev, "nav")',
|
|
389
|
+
"const $clicks = _vueInject(_injectionClicks)",
|
|
390
|
+
"const $page = _vueInject(_injectionCurrentPage)",
|
|
391
|
+
"const $renderContext = _vueInject(_injectionSlideContext)"
|
|
392
|
+
];
|
|
393
|
+
function getBodyJson(req) {
|
|
394
|
+
return new Promise((resolve3, reject) => {
|
|
395
|
+
let body = "";
|
|
396
|
+
req.on("data", (chunk) => body += chunk);
|
|
397
|
+
req.on("error", reject);
|
|
398
|
+
req.on("end", () => {
|
|
399
|
+
try {
|
|
400
|
+
resolve3(JSON.parse(body) || {});
|
|
401
|
+
} catch (e) {
|
|
402
|
+
reject(e);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
var md = Markdown({ html: true });
|
|
408
|
+
md.use(mila, {
|
|
409
|
+
attrs: {
|
|
410
|
+
target: "_blank",
|
|
411
|
+
rel: "noopener"
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
function prepareSlideInfo(data) {
|
|
415
|
+
return {
|
|
416
|
+
...data,
|
|
417
|
+
noteHTML: md.render(data?.note || "")
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, userRoot, roots, remote }, pluginOptions, serverOptions) {
|
|
421
|
+
const slidePrefix = "/@slidev/slides/";
|
|
422
|
+
const hmrPages = /* @__PURE__ */ new Set();
|
|
423
|
+
let server;
|
|
424
|
+
let _layouts_cache_time = 0;
|
|
425
|
+
let _layouts_cache = {};
|
|
426
|
+
return [
|
|
427
|
+
{
|
|
428
|
+
name: "slidev:loader",
|
|
429
|
+
configureServer(_server) {
|
|
430
|
+
server = _server;
|
|
431
|
+
updateServerWatcher();
|
|
432
|
+
server.middlewares.use(async (req, res, next) => {
|
|
433
|
+
const match = req.url?.match(regexId);
|
|
434
|
+
if (!match)
|
|
435
|
+
return next();
|
|
436
|
+
const [, no, type] = match;
|
|
437
|
+
const idx = Number.parseInt(no);
|
|
438
|
+
if (type === "json" && req.method === "GET") {
|
|
439
|
+
res.write(JSON.stringify(prepareSlideInfo(data.slides[idx])));
|
|
440
|
+
return res.end();
|
|
441
|
+
}
|
|
442
|
+
if (type === "json" && req.method === "POST") {
|
|
443
|
+
const body = await getBodyJson(req);
|
|
444
|
+
const slide = data.slides[idx];
|
|
445
|
+
hmrPages.add(idx);
|
|
446
|
+
if (slide.source) {
|
|
447
|
+
Object.assign(slide.source, body);
|
|
448
|
+
await parser.saveExternalSlide(slide.source);
|
|
449
|
+
} else {
|
|
450
|
+
Object.assign(slide, body);
|
|
451
|
+
await parser.save(data, entry);
|
|
452
|
+
}
|
|
453
|
+
res.statusCode = 200;
|
|
454
|
+
res.write(JSON.stringify(prepareSlideInfo(slide)));
|
|
455
|
+
return res.end();
|
|
456
|
+
}
|
|
457
|
+
next();
|
|
458
|
+
});
|
|
459
|
+
},
|
|
460
|
+
async handleHotUpdate(ctx) {
|
|
461
|
+
if (!data.entries.some((i) => slash(i) === ctx.file))
|
|
462
|
+
return;
|
|
463
|
+
await ctx.read();
|
|
464
|
+
const newData = await parser.load(entry, data.themeMeta);
|
|
465
|
+
const moduleIds = /* @__PURE__ */ new Set();
|
|
466
|
+
if (data.slides.length !== newData.slides.length) {
|
|
467
|
+
moduleIds.add("/@slidev/routes");
|
|
468
|
+
range(newData.slides.length).map((i) => hmrPages.add(i));
|
|
469
|
+
}
|
|
470
|
+
if (!(0, import_fast_deep_equal.default)(data.headmatter.defaults, newData.headmatter.defaults)) {
|
|
471
|
+
moduleIds.add("/@slidev/routes");
|
|
472
|
+
range(data.slides.length).map((i) => hmrPages.add(i));
|
|
473
|
+
}
|
|
474
|
+
if (!(0, import_fast_deep_equal.default)(data.config, newData.config))
|
|
475
|
+
moduleIds.add("/@slidev/configs");
|
|
476
|
+
if (!(0, import_fast_deep_equal.default)(data.features, newData.features)) {
|
|
477
|
+
setTimeout(() => {
|
|
478
|
+
ctx.server.ws.send({ type: "full-reload" });
|
|
479
|
+
}, 1);
|
|
480
|
+
}
|
|
481
|
+
const length = Math.max(data.slides.length, newData.slides.length);
|
|
482
|
+
for (let i = 0; i < length; i++) {
|
|
483
|
+
const a = data.slides[i];
|
|
484
|
+
const b = newData.slides[i];
|
|
485
|
+
if (a?.content.trim() === b?.content.trim() && a?.title?.trim() === b?.title?.trim() && a?.note === b?.note && (0, import_fast_deep_equal.default)(a.frontmatter, b.frontmatter))
|
|
486
|
+
continue;
|
|
487
|
+
ctx.server.ws.send({
|
|
488
|
+
type: "custom",
|
|
489
|
+
event: "slidev-update",
|
|
490
|
+
data: {
|
|
491
|
+
id: i,
|
|
492
|
+
data: prepareSlideInfo(newData.slides[i])
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
hmrPages.add(i);
|
|
496
|
+
}
|
|
497
|
+
serverOptions.onDataReload?.(newData, data);
|
|
498
|
+
Object.assign(data, newData);
|
|
499
|
+
if (hmrPages.size > 0)
|
|
500
|
+
moduleIds.add("/@slidev/titles.md");
|
|
501
|
+
const vueModules = Array.from(hmrPages).map(
|
|
502
|
+
(i) => ctx.server.moduleGraph.getModuleById(`${slidePrefix}${i + 1}.md`)
|
|
503
|
+
);
|
|
504
|
+
hmrPages.clear();
|
|
505
|
+
const moduleEntries = [
|
|
506
|
+
...vueModules,
|
|
507
|
+
...Array.from(moduleIds).map((id) => ctx.server.moduleGraph.getModuleById(id))
|
|
508
|
+
].filter(notNullish).filter((i) => !i.id?.startsWith("/@id/@vite-icons"));
|
|
509
|
+
updateServerWatcher();
|
|
510
|
+
return moduleEntries;
|
|
511
|
+
},
|
|
512
|
+
resolveId(id) {
|
|
513
|
+
if (id.startsWith(slidePrefix) || id.startsWith("/@slidev/"))
|
|
514
|
+
return id;
|
|
515
|
+
return null;
|
|
516
|
+
},
|
|
517
|
+
load(id) {
|
|
518
|
+
if (id === "/@slidev/routes")
|
|
519
|
+
return generateRoutes();
|
|
520
|
+
if (id === "/@slidev/layouts")
|
|
521
|
+
return generateLayouts();
|
|
522
|
+
if (id === "/@slidev/styles")
|
|
523
|
+
return generateUserStyles();
|
|
524
|
+
if (id === "/@slidev/monaco-types")
|
|
525
|
+
return generateMonacoTypes();
|
|
526
|
+
if (id === "/@slidev/configs")
|
|
527
|
+
return generateConfigs();
|
|
528
|
+
if (id === "/@slidev/global-components/top")
|
|
529
|
+
return generateGlobalComponents("top");
|
|
530
|
+
if (id === "/@slidev/global-components/bottom")
|
|
531
|
+
return generateGlobalComponents("bottom");
|
|
532
|
+
if (id === "/@slidev/custom-nav-controls")
|
|
533
|
+
return generateCustomNavControls();
|
|
534
|
+
if (id === "/@slidev/titles.md") {
|
|
535
|
+
return {
|
|
536
|
+
code: data.slides.filter(({ frontmatter }) => !frontmatter?.disabled).map(({ title }, i) => {
|
|
537
|
+
return `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">
|
|
538
|
+
|
|
539
|
+
${title}
|
|
540
|
+
|
|
541
|
+
</template>`;
|
|
542
|
+
}).join(""),
|
|
543
|
+
map: { mappings: "" }
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
if (id.startsWith(slidePrefix)) {
|
|
547
|
+
const remaning = id.slice(slidePrefix.length);
|
|
548
|
+
const match = remaning.match(regexIdQuery);
|
|
549
|
+
if (match) {
|
|
550
|
+
const [, no, type] = match;
|
|
551
|
+
const pageNo = Number.parseInt(no) - 1;
|
|
552
|
+
if (type === "md") {
|
|
553
|
+
return {
|
|
554
|
+
code: data.slides[pageNo]?.content,
|
|
555
|
+
map: { mappings: "" }
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
code: "",
|
|
561
|
+
map: { mappings: "" }
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
name: "slidev:layout-transform:pre",
|
|
568
|
+
enforce: "pre",
|
|
569
|
+
async transform(code, id) {
|
|
570
|
+
if (!id.startsWith(slidePrefix))
|
|
571
|
+
return;
|
|
572
|
+
const remaning = id.slice(slidePrefix.length);
|
|
573
|
+
const match = remaning.match(regexIdQuery);
|
|
574
|
+
if (!match)
|
|
575
|
+
return;
|
|
576
|
+
const [, no, type] = match;
|
|
577
|
+
if (type !== "md")
|
|
578
|
+
return;
|
|
579
|
+
const pageNo = Number.parseInt(no) - 1;
|
|
580
|
+
return transformMarkdown(code, pageNo, data);
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: "slidev:context-transform:pre",
|
|
585
|
+
enforce: "pre",
|
|
586
|
+
async transform(code, id) {
|
|
587
|
+
if (!id.endsWith(".vue") || id.includes("/@slidev/client/") || id.includes("/packages/client/"))
|
|
588
|
+
return;
|
|
589
|
+
return transformVue(code);
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
name: "slidev:title-transform:pre",
|
|
594
|
+
enforce: "pre",
|
|
595
|
+
transform(code, id) {
|
|
596
|
+
if (id !== "/@slidev/titles.md")
|
|
597
|
+
return;
|
|
598
|
+
return transformTitles(code);
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
name: "slidev:slide-transform:post",
|
|
603
|
+
enforce: "post",
|
|
604
|
+
transform(code, id) {
|
|
605
|
+
if (!id.match(/\/@slidev\/slides\/\d+\.md($|\?)/))
|
|
606
|
+
return;
|
|
607
|
+
return code.replace("if (_rerender_only)", "if (false)");
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
];
|
|
611
|
+
function updateServerWatcher() {
|
|
612
|
+
if (!server)
|
|
613
|
+
return;
|
|
614
|
+
server.watcher.add(data.entries?.map(slash) || []);
|
|
615
|
+
}
|
|
616
|
+
async function transformMarkdown(code, pageNo, data2) {
|
|
617
|
+
const layouts = await getLayouts();
|
|
618
|
+
const frontmatter = {
|
|
619
|
+
...data2.headmatter?.defaults || {},
|
|
620
|
+
...data2.slides[pageNo]?.frontmatter || {}
|
|
621
|
+
};
|
|
622
|
+
let layoutName = frontmatter?.layout || (pageNo === 0 ? "cover" : "default");
|
|
623
|
+
if (!layouts[layoutName]) {
|
|
624
|
+
console.error(red(`
|
|
625
|
+
Unknown layout "${bold(layoutName)}".${yellow(" Available layouts are:")}`) + Object.keys(layouts).map((i, idx) => (idx % 3 === 0 ? "\n " : "") + gray(i.padEnd(15, " "))).join(" "));
|
|
626
|
+
console.error();
|
|
627
|
+
layoutName = "default";
|
|
628
|
+
}
|
|
629
|
+
delete frontmatter.title;
|
|
630
|
+
const imports = [
|
|
631
|
+
...vueContextImports,
|
|
632
|
+
`import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
|
|
633
|
+
`const frontmatter = ${JSON.stringify(frontmatter)}`,
|
|
634
|
+
"const $frontmatter = frontmatter"
|
|
635
|
+
];
|
|
636
|
+
code = code.replace(/(<script setup.*>)/g, `$1
|
|
637
|
+
${imports.join("\n")}
|
|
638
|
+
`);
|
|
639
|
+
const injectA = code.indexOf("<template>") + "<template>".length;
|
|
640
|
+
const injectB = code.lastIndexOf("</template>");
|
|
641
|
+
let body = code.slice(injectA, injectB).trim();
|
|
642
|
+
if (body.startsWith("<div>") && body.endsWith("</div>"))
|
|
643
|
+
body = body.slice(5, -6);
|
|
644
|
+
code = `${code.slice(0, injectA)}
|
|
645
|
+
<InjectedLayout v-bind="frontmatter">
|
|
646
|
+
${body}
|
|
647
|
+
</InjectedLayout>
|
|
648
|
+
${code.slice(injectB)}`;
|
|
649
|
+
return code;
|
|
650
|
+
}
|
|
651
|
+
function transformVue(code) {
|
|
652
|
+
if (code.includes("injectionSlidevContext") || code.includes("injectionClicks") || code.includes("const $slidev"))
|
|
653
|
+
return code;
|
|
654
|
+
const imports = [
|
|
655
|
+
...vueContextImports
|
|
656
|
+
];
|
|
657
|
+
const matchScript = code.match(/<script((?!setup).)*(setup)?.*>/);
|
|
658
|
+
if (matchScript && matchScript[2]) {
|
|
659
|
+
return code.replace(/(<script.*>)/g, `$1
|
|
660
|
+
${imports.join("\n")}
|
|
661
|
+
`);
|
|
662
|
+
} else if (matchScript && !matchScript[2]) {
|
|
663
|
+
const matchExport = code.match(/export\s+default\s+{/);
|
|
664
|
+
if (matchExport) {
|
|
665
|
+
const exportIndex = (matchExport.index || 0) + matchExport[0].length;
|
|
666
|
+
let component = code.slice(exportIndex);
|
|
667
|
+
component = component.slice(0, component.indexOf("</script>"));
|
|
668
|
+
const scriptIndex = (matchScript.index || 0) + matchScript[0].length;
|
|
669
|
+
const provideImport = '\nimport { injectionSlidevContext } from "@slidev/client/constants.ts"\n';
|
|
670
|
+
code = `${code.slice(0, scriptIndex)}${provideImport}${code.slice(scriptIndex)}`;
|
|
671
|
+
let injectIndex = exportIndex + provideImport.length;
|
|
672
|
+
let injectObject = "$slidev: { from: injectionSlidevContext },";
|
|
673
|
+
const matchInject = component.match(/.*inject\s*:\s*([\[{])/);
|
|
674
|
+
if (matchInject) {
|
|
675
|
+
injectIndex += (matchInject.index || 0) + matchInject[0].length;
|
|
676
|
+
if (matchInject[1] === "[") {
|
|
677
|
+
let injects = component.slice((matchInject.index || 0) + matchInject[0].length);
|
|
678
|
+
const injectEndIndex = injects.indexOf("]");
|
|
679
|
+
injects = injects.slice(0, injectEndIndex);
|
|
680
|
+
injectObject += injects.split(",").map((inject) => `${inject}: {from: ${inject}}`).join(",");
|
|
681
|
+
return `${code.slice(0, injectIndex - 1)}{
|
|
682
|
+
${injectObject}
|
|
683
|
+
}${code.slice(injectIndex + injectEndIndex + 1)}`;
|
|
684
|
+
} else {
|
|
685
|
+
return `${code.slice(0, injectIndex)}
|
|
686
|
+
${injectObject}
|
|
687
|
+
${code.slice(injectIndex)}`;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return `${code.slice(0, injectIndex)}
|
|
691
|
+
inject: { ${injectObject} },
|
|
692
|
+
${code.slice(injectIndex)}`;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return `<script setup>
|
|
696
|
+
${imports.join("\n")}
|
|
697
|
+
</script>
|
|
698
|
+
${code}`;
|
|
699
|
+
}
|
|
700
|
+
function transformTitles(code) {
|
|
701
|
+
return code.replace(/<template>\s*<div>\s*<p>/, "<template>").replace(/<\/p>\s*<\/div>\s*<\/template>/, "</template>").replace(/<script\ssetup>/, `<script setup lang="ts">
|
|
702
|
+
defineProps<{ no: number | string }>()`);
|
|
703
|
+
}
|
|
704
|
+
async function getLayouts() {
|
|
705
|
+
const now = Date.now();
|
|
706
|
+
if (now - _layouts_cache_time < 2e3)
|
|
707
|
+
return _layouts_cache;
|
|
708
|
+
const layouts = {};
|
|
709
|
+
const roots2 = uniq3([
|
|
710
|
+
userRoot,
|
|
711
|
+
...themeRoots,
|
|
712
|
+
...addonRoots,
|
|
713
|
+
clientRoot
|
|
714
|
+
]);
|
|
715
|
+
for (const root of roots2) {
|
|
716
|
+
const layoutPaths = await fg2("layouts/**/*.{vue,ts}", {
|
|
717
|
+
cwd: root,
|
|
718
|
+
absolute: true,
|
|
719
|
+
suppressErrors: true
|
|
720
|
+
});
|
|
721
|
+
for (const layoutPath of layoutPaths) {
|
|
722
|
+
const layout = basename2(layoutPath).replace(/\.\w+$/, "");
|
|
723
|
+
if (layouts[layout])
|
|
724
|
+
continue;
|
|
725
|
+
layouts[layout] = layoutPath;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
_layouts_cache_time = now;
|
|
729
|
+
_layouts_cache = layouts;
|
|
730
|
+
return layouts;
|
|
731
|
+
}
|
|
732
|
+
async function generateUserStyles() {
|
|
733
|
+
const imports = [
|
|
734
|
+
`import "${toAtFS(join5(clientRoot, "styles/vars.css"))}"`,
|
|
735
|
+
`import "${toAtFS(join5(clientRoot, "styles/index.css"))}"`,
|
|
736
|
+
`import "${toAtFS(join5(clientRoot, "styles/code.css"))}"`,
|
|
737
|
+
`import "${toAtFS(join5(clientRoot, "styles/transitions.css"))}"`
|
|
738
|
+
];
|
|
739
|
+
const roots2 = uniq3([
|
|
740
|
+
...themeRoots,
|
|
741
|
+
...addonRoots,
|
|
742
|
+
userRoot
|
|
743
|
+
]);
|
|
744
|
+
for (const root of roots2) {
|
|
745
|
+
const styles = [
|
|
746
|
+
join5(root, "styles", "index.ts"),
|
|
747
|
+
join5(root, "styles", "index.js"),
|
|
748
|
+
join5(root, "styles", "index.css"),
|
|
749
|
+
join5(root, "styles.css"),
|
|
750
|
+
join5(root, "style.css")
|
|
751
|
+
];
|
|
752
|
+
for (const style of styles) {
|
|
753
|
+
if (existsSync2(style)) {
|
|
754
|
+
imports.push(`import "${toAtFS(style)}"`);
|
|
755
|
+
continue;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (data.features.katex)
|
|
760
|
+
imports.push(`import "${toAtFS(resolveImportPath("katex/dist/katex.min.css", true))}"`);
|
|
761
|
+
if (data.config.css === "unocss") {
|
|
762
|
+
imports.unshift(
|
|
763
|
+
'import "@unocss/reset/tailwind.css"',
|
|
764
|
+
'import "uno:preflights.css"',
|
|
765
|
+
'import "uno:typography.css"',
|
|
766
|
+
'import "uno:shortcuts.css"'
|
|
767
|
+
);
|
|
768
|
+
imports.push('import "uno.css"');
|
|
769
|
+
} else {
|
|
770
|
+
imports.unshift(
|
|
771
|
+
'import "virtual:windi-components.css"',
|
|
772
|
+
'import "virtual:windi-base.css"'
|
|
773
|
+
);
|
|
774
|
+
imports.push('import "virtual:windi-utilities.css"');
|
|
775
|
+
if (process.env.NODE_ENV !== "production")
|
|
776
|
+
imports.push('import "virtual:windi-devtools"');
|
|
777
|
+
}
|
|
778
|
+
return imports.join("\n");
|
|
779
|
+
}
|
|
780
|
+
async function generateMonacoTypes() {
|
|
781
|
+
return `void 0; ${parser.scanMonacoModules(data.raw).map((i) => `import('/@slidev-monaco-types/${i}')`).join("\n")}`;
|
|
782
|
+
}
|
|
783
|
+
async function generateLayouts() {
|
|
784
|
+
const imports = [];
|
|
785
|
+
const layouts = objectMap(
|
|
786
|
+
await getLayouts(),
|
|
787
|
+
(k, v) => {
|
|
788
|
+
imports.push(`import __layout_${k} from "${toAtFS(v)}"`);
|
|
789
|
+
return [k, `__layout_${k}`];
|
|
790
|
+
}
|
|
791
|
+
);
|
|
792
|
+
return [
|
|
793
|
+
imports.join("\n"),
|
|
794
|
+
`export default {
|
|
795
|
+
${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}
|
|
796
|
+
}`
|
|
797
|
+
].join("\n\n");
|
|
798
|
+
}
|
|
799
|
+
async function generateRoutes() {
|
|
800
|
+
const imports = [];
|
|
801
|
+
const redirects = [];
|
|
802
|
+
const layouts = await getLayouts();
|
|
803
|
+
imports.push(`import __layout__end from '${layouts.end}'`);
|
|
804
|
+
let no = 1;
|
|
805
|
+
const routes = data.slides.filter(({ frontmatter }) => !frontmatter?.disabled).map((i, idx) => {
|
|
806
|
+
imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
|
|
807
|
+
const additions = {
|
|
808
|
+
slide: {
|
|
809
|
+
...prepareSlideInfo(i),
|
|
810
|
+
filepath: i.source?.filepath || entry,
|
|
811
|
+
id: idx,
|
|
812
|
+
no
|
|
813
|
+
},
|
|
814
|
+
__clicksElements: [],
|
|
815
|
+
__preloaded: false
|
|
816
|
+
};
|
|
817
|
+
const meta = Object.assign({}, i.frontmatter, additions);
|
|
818
|
+
const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: ${JSON.stringify(meta)} }`;
|
|
819
|
+
if (i.frontmatter?.routeAlias)
|
|
820
|
+
redirects.push(`{ path: '${i.frontmatter?.routeAlias}', redirect: { path: '${no}' } }`);
|
|
821
|
+
no += 1;
|
|
822
|
+
return route;
|
|
823
|
+
});
|
|
824
|
+
const routesStr = `export default [
|
|
825
|
+
${routes.join(",\n")}
|
|
826
|
+
]`;
|
|
827
|
+
const redirectsStr = `export const redirects = [
|
|
828
|
+
${redirects.join(",\n")}
|
|
829
|
+
]`;
|
|
830
|
+
return [...imports, routesStr, redirectsStr].join("\n");
|
|
831
|
+
}
|
|
832
|
+
function generateConfigs() {
|
|
833
|
+
const config = { ...data.config, remote };
|
|
834
|
+
if (isString(config.title)) {
|
|
835
|
+
const tokens = md.parseInline(config.title, {});
|
|
836
|
+
config.title = stringifyMarkdownTokens(tokens);
|
|
837
|
+
}
|
|
838
|
+
if (isString(config.info))
|
|
839
|
+
config.info = md.render(config.info);
|
|
840
|
+
return `export default ${JSON.stringify(config)}`;
|
|
841
|
+
}
|
|
842
|
+
async function generateGlobalComponents(layer) {
|
|
843
|
+
const components = roots.flatMap((root) => {
|
|
844
|
+
if (layer === "top") {
|
|
845
|
+
return [
|
|
846
|
+
join5(root, "global.vue"),
|
|
847
|
+
join5(root, "global-top.vue"),
|
|
848
|
+
join5(root, "GlobalTop.vue")
|
|
849
|
+
];
|
|
850
|
+
} else {
|
|
851
|
+
return [
|
|
852
|
+
join5(root, "global-bottom.vue"),
|
|
853
|
+
join5(root, "GlobalBottom.vue")
|
|
854
|
+
];
|
|
855
|
+
}
|
|
856
|
+
}).filter((i) => fs4.existsSync(i));
|
|
857
|
+
const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
|
|
858
|
+
const render = components.map((i, idx) => `h(__n${idx})`).join(",");
|
|
859
|
+
return `
|
|
860
|
+
${imports}
|
|
861
|
+
import { h } from 'vue'
|
|
862
|
+
export default {
|
|
863
|
+
render() {
|
|
864
|
+
return [${render}]
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
`;
|
|
868
|
+
}
|
|
869
|
+
async function generateCustomNavControls() {
|
|
870
|
+
const components = roots.flatMap((root) => {
|
|
871
|
+
return [
|
|
872
|
+
join5(root, "custom-nav-controls.vue"),
|
|
873
|
+
join5(root, "CustomNavControls.vue")
|
|
874
|
+
];
|
|
875
|
+
}).filter((i) => fs4.existsSync(i));
|
|
876
|
+
const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
|
|
877
|
+
const render = components.map((i, idx) => `h(__n${idx})`).join(",");
|
|
878
|
+
return `
|
|
879
|
+
${imports}
|
|
880
|
+
import { h } from 'vue'
|
|
881
|
+
export default {
|
|
882
|
+
render() {
|
|
883
|
+
return [${render}]
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
`;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// node/plugins/monacoTransform.ts
|
|
891
|
+
import { join as join6 } from "node:path";
|
|
892
|
+
import process2 from "node:process";
|
|
893
|
+
import { slash as slash2 } from "@antfu/utils";
|
|
894
|
+
async function getPackageData(pkg) {
|
|
895
|
+
const { resolvePackageData } = await eval('import("vite")');
|
|
896
|
+
const info = resolvePackageData(pkg, process2.cwd());
|
|
897
|
+
if (!info)
|
|
898
|
+
return;
|
|
899
|
+
const typePath = info.data.types || info.data.typings;
|
|
900
|
+
if (!typePath)
|
|
901
|
+
return;
|
|
902
|
+
return [info, typePath];
|
|
903
|
+
}
|
|
904
|
+
function createMonacoTypesLoader() {
|
|
905
|
+
return {
|
|
906
|
+
name: "slidev:monaco-types-loader",
|
|
907
|
+
resolveId(id) {
|
|
908
|
+
if (id.startsWith("/@slidev-monaco-types/"))
|
|
909
|
+
return id;
|
|
910
|
+
return null;
|
|
911
|
+
},
|
|
912
|
+
async load(id) {
|
|
913
|
+
const match = id.match(/^\/\@slidev-monaco-types\/(.*)$/);
|
|
914
|
+
if (match) {
|
|
915
|
+
const pkg2 = match[1];
|
|
916
|
+
const packageData = await getPackageData(pkg2) || await getPackageData(`@types/${pkg2}`);
|
|
917
|
+
if (!packageData)
|
|
918
|
+
return;
|
|
919
|
+
const [info2, typePath2] = packageData;
|
|
920
|
+
return [
|
|
921
|
+
"import * as monaco from 'monaco-editor'",
|
|
922
|
+
`import Type from "${slash2(join6(info2.dir, typePath2))}?raw"`,
|
|
923
|
+
...Object.keys(info2.data.dependencies || {}).map((i) => `import "/@slidev-monaco-types/${i}"`),
|
|
924
|
+
`monaco.languages.typescript.typescriptDefaults.addExtraLib(\`declare module "${pkg2}" { \${Type} }\`)`
|
|
925
|
+
].join("\n");
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// node/plugins/setupClient.ts
|
|
932
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
933
|
+
import { join as join7, resolve as resolve2 } from "node:path";
|
|
934
|
+
import { slash as slash3, uniq as uniq4 } from "@antfu/utils";
|
|
935
|
+
function createClientSetupPlugin({ clientRoot, themeRoots, addonRoots, userRoot }) {
|
|
936
|
+
const setupEntry = slash3(resolve2(clientRoot, "setup"));
|
|
937
|
+
return {
|
|
938
|
+
name: "slidev:setup",
|
|
939
|
+
enforce: "pre",
|
|
940
|
+
async transform(code, id) {
|
|
941
|
+
if (id.startsWith(setupEntry)) {
|
|
942
|
+
let getInjections2 = function(isAwait = false, isChained = false) {
|
|
943
|
+
return injections.join("\n").replace(/:AWAIT:/g, isAwait ? "await " : "").replace(/(,\s*)?:LAST:/g, isChained ? "$1injection_return" : "");
|
|
944
|
+
};
|
|
945
|
+
var getInjections = getInjections2;
|
|
946
|
+
const name = id.slice(setupEntry.length + 1).replace(/\?.*$/, "");
|
|
947
|
+
const imports = [];
|
|
948
|
+
const injections = [];
|
|
949
|
+
const setups = uniq4([
|
|
950
|
+
...themeRoots,
|
|
951
|
+
...addonRoots,
|
|
952
|
+
userRoot
|
|
953
|
+
]).map((i) => join7(i, "setup", name));
|
|
954
|
+
setups.forEach((path, idx) => {
|
|
955
|
+
if (!existsSync3(path))
|
|
956
|
+
return;
|
|
957
|
+
imports.push(`import __n${idx} from '${toAtFS(path)}'`);
|
|
958
|
+
let fn = `:AWAIT:__n${idx}`;
|
|
959
|
+
if (/\binjection_return\b/g.test(code))
|
|
960
|
+
fn = `injection_return = ${fn}`;
|
|
961
|
+
if (/\binjection_arg\b/g.test(code)) {
|
|
962
|
+
fn += "(";
|
|
963
|
+
const matches = Array.from(code.matchAll(/\binjection_arg(_\d+)?\b/g));
|
|
964
|
+
const dedupedMatches = Array.from(new Set(matches.map((m) => m[0])));
|
|
965
|
+
fn += dedupedMatches.join(", ");
|
|
966
|
+
fn += ", :LAST:)";
|
|
967
|
+
} else {
|
|
968
|
+
fn += "(:LAST:)";
|
|
969
|
+
}
|
|
970
|
+
injections.push(
|
|
971
|
+
`// ${path}`,
|
|
972
|
+
fn
|
|
973
|
+
);
|
|
974
|
+
});
|
|
975
|
+
code = code.replace("/* __imports__ */", imports.join("\n"));
|
|
976
|
+
code = code.replace("/* __injections__ */", getInjections2());
|
|
977
|
+
code = code.replace("/* __async_injections__ */", getInjections2(true));
|
|
978
|
+
code = code.replace("/* __chained_injections__ */", getInjections2(false, true));
|
|
979
|
+
code = code.replace("/* __chained_async_injections__ */", getInjections2(true, true));
|
|
980
|
+
return code;
|
|
981
|
+
}
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// node/plugins/markdown.ts
|
|
988
|
+
import Markdown2 from "unplugin-vue-markdown/vite";
|
|
989
|
+
import * as base64 from "js-base64";
|
|
990
|
+
import { slash as slash4 } from "@antfu/utils";
|
|
991
|
+
import mila2 from "markdown-it-link-attributes";
|
|
992
|
+
import mif from "markdown-it-footnote";
|
|
993
|
+
import { taskLists } from "@hedgedoc/markdown-it-plugins";
|
|
994
|
+
import { encode as encode2 } from "plantuml-encoder";
|
|
995
|
+
import Mdc from "markdown-it-mdc";
|
|
996
|
+
|
|
997
|
+
// node/plugins/markdown-it-katex.ts
|
|
998
|
+
import katex from "katex";
|
|
999
|
+
function isValidDelim(state, pos) {
|
|
1000
|
+
const max = state.posMax;
|
|
1001
|
+
let can_open = true;
|
|
1002
|
+
let can_close = true;
|
|
1003
|
+
const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
|
|
1004
|
+
const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
|
|
1005
|
+
if (prevChar === 32 || prevChar === 9 || /* \t */
|
|
1006
|
+
nextChar >= 48 && nextChar <= 57)
|
|
1007
|
+
can_close = false;
|
|
1008
|
+
if (nextChar === 32 || nextChar === 9)
|
|
1009
|
+
can_open = false;
|
|
1010
|
+
return {
|
|
1011
|
+
can_open,
|
|
1012
|
+
can_close
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
function math_inline(state, silent) {
|
|
1016
|
+
let match, token, res, pos;
|
|
1017
|
+
if (state.src[state.pos] !== "$")
|
|
1018
|
+
return false;
|
|
1019
|
+
res = isValidDelim(state, state.pos);
|
|
1020
|
+
if (!res.can_open) {
|
|
1021
|
+
if (!silent)
|
|
1022
|
+
state.pending += "$";
|
|
1023
|
+
state.pos += 1;
|
|
1024
|
+
return true;
|
|
1025
|
+
}
|
|
1026
|
+
const start = state.pos + 1;
|
|
1027
|
+
match = start;
|
|
1028
|
+
while ((match = state.src.indexOf("$", match)) !== -1) {
|
|
1029
|
+
pos = match - 1;
|
|
1030
|
+
while (state.src[pos] === "\\")
|
|
1031
|
+
pos -= 1;
|
|
1032
|
+
if ((match - pos) % 2 === 1)
|
|
1033
|
+
break;
|
|
1034
|
+
match += 1;
|
|
1035
|
+
}
|
|
1036
|
+
if (match === -1) {
|
|
1037
|
+
if (!silent)
|
|
1038
|
+
state.pending += "$";
|
|
1039
|
+
state.pos = start;
|
|
1040
|
+
return true;
|
|
1041
|
+
}
|
|
1042
|
+
if (match - start === 0) {
|
|
1043
|
+
if (!silent)
|
|
1044
|
+
state.pending += "$$";
|
|
1045
|
+
state.pos = start + 1;
|
|
1046
|
+
return true;
|
|
1047
|
+
}
|
|
1048
|
+
res = isValidDelim(state, match);
|
|
1049
|
+
if (!res.can_close) {
|
|
1050
|
+
if (!silent)
|
|
1051
|
+
state.pending += "$";
|
|
1052
|
+
state.pos = start;
|
|
1053
|
+
return true;
|
|
1054
|
+
}
|
|
1055
|
+
if (!silent) {
|
|
1056
|
+
token = state.push("math_inline", "math", 0);
|
|
1057
|
+
token.markup = "$";
|
|
1058
|
+
token.content = state.src.slice(start, match);
|
|
1059
|
+
}
|
|
1060
|
+
state.pos = match + 1;
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
function math_block(state, start, end, silent) {
|
|
1064
|
+
let firstLine;
|
|
1065
|
+
let lastLine;
|
|
1066
|
+
let next;
|
|
1067
|
+
let lastPos;
|
|
1068
|
+
let found = false;
|
|
1069
|
+
let pos = state.bMarks[start] + state.tShift[start];
|
|
1070
|
+
let max = state.eMarks[start];
|
|
1071
|
+
if (pos + 2 > max)
|
|
1072
|
+
return false;
|
|
1073
|
+
if (state.src.slice(pos, pos + 2) !== "$$")
|
|
1074
|
+
return false;
|
|
1075
|
+
pos += 2;
|
|
1076
|
+
firstLine = state.src.slice(pos, max);
|
|
1077
|
+
if (silent)
|
|
1078
|
+
return true;
|
|
1079
|
+
if (firstLine.trim().slice(-2) === "$$") {
|
|
1080
|
+
firstLine = firstLine.trim().slice(0, -2);
|
|
1081
|
+
found = true;
|
|
1082
|
+
}
|
|
1083
|
+
for (next = start; !found; ) {
|
|
1084
|
+
next++;
|
|
1085
|
+
if (next >= end)
|
|
1086
|
+
break;
|
|
1087
|
+
pos = state.bMarks[next] + state.tShift[next];
|
|
1088
|
+
max = state.eMarks[next];
|
|
1089
|
+
if (pos < max && state.tShift[next] < state.blkIndent) {
|
|
1090
|
+
break;
|
|
1091
|
+
}
|
|
1092
|
+
if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
|
|
1093
|
+
lastPos = state.src.slice(0, max).lastIndexOf("$$");
|
|
1094
|
+
lastLine = state.src.slice(pos, lastPos);
|
|
1095
|
+
found = true;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
state.line = next + 1;
|
|
1099
|
+
const token = state.push("math_block", "math", 0);
|
|
1100
|
+
token.block = true;
|
|
1101
|
+
token.content = (firstLine && firstLine.trim() ? `${firstLine}
|
|
1102
|
+
` : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
|
|
1103
|
+
token.map = [start, state.line];
|
|
1104
|
+
token.markup = "$$";
|
|
1105
|
+
return true;
|
|
1106
|
+
}
|
|
1107
|
+
function math_plugin(md2, options) {
|
|
1108
|
+
options = options || {};
|
|
1109
|
+
const katexInline = function(latex) {
|
|
1110
|
+
options.displayMode = false;
|
|
1111
|
+
try {
|
|
1112
|
+
return katex.renderToString(latex, options);
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
if (options.throwOnError)
|
|
1115
|
+
console.warn(error);
|
|
1116
|
+
return latex;
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
const inlineRenderer = function(tokens, idx) {
|
|
1120
|
+
return katexInline(tokens[idx].content);
|
|
1121
|
+
};
|
|
1122
|
+
const katexBlock = function(latex) {
|
|
1123
|
+
options.displayMode = true;
|
|
1124
|
+
try {
|
|
1125
|
+
return `<p>${katex.renderToString(latex, options)}</p>`;
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
if (options.throwOnError)
|
|
1128
|
+
console.warn(error);
|
|
1129
|
+
return latex;
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
const blockRenderer = function(tokens, idx) {
|
|
1133
|
+
return `${katexBlock(tokens[idx].content)}
|
|
1134
|
+
`;
|
|
1135
|
+
};
|
|
1136
|
+
md2.inline.ruler.after("escape", "math_inline", math_inline);
|
|
1137
|
+
md2.block.ruler.after("blockquote", "math_block", math_block, {
|
|
1138
|
+
alt: ["paragraph", "reference", "blockquote", "list"]
|
|
1139
|
+
});
|
|
1140
|
+
md2.renderer.rules.math_inline = inlineRenderer;
|
|
1141
|
+
md2.renderer.rules.math_block = blockRenderer;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// node/plugins/markdown-it-prism.ts
|
|
1145
|
+
import Prism from "prismjs";
|
|
1146
|
+
import loadLanguages from "prismjs/components/";
|
|
1147
|
+
import * as htmlparser2 from "htmlparser2";
|
|
1148
|
+
var Tag = class {
|
|
1149
|
+
constructor(tagname, attributes) {
|
|
1150
|
+
this.tagname = tagname;
|
|
1151
|
+
this.attributes = attributes;
|
|
1152
|
+
}
|
|
1153
|
+
asOpen() {
|
|
1154
|
+
return `<${this.tagname} ${Object.entries(this.attributes).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
|
|
1155
|
+
}
|
|
1156
|
+
asClosed() {
|
|
1157
|
+
return `</${this.tagname}>`;
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
var DEFAULTS = {
|
|
1161
|
+
plugins: [],
|
|
1162
|
+
init: () => {
|
|
1163
|
+
},
|
|
1164
|
+
defaultLanguageForUnknown: void 0,
|
|
1165
|
+
defaultLanguageForUnspecified: void 0,
|
|
1166
|
+
defaultLanguage: void 0
|
|
1167
|
+
};
|
|
1168
|
+
function loadPrismLang(lang) {
|
|
1169
|
+
if (!lang)
|
|
1170
|
+
return void 0;
|
|
1171
|
+
let langObject = Prism.languages[lang];
|
|
1172
|
+
if (langObject === void 0) {
|
|
1173
|
+
loadLanguages([lang]);
|
|
1174
|
+
langObject = Prism.languages[lang];
|
|
1175
|
+
}
|
|
1176
|
+
return langObject;
|
|
1177
|
+
}
|
|
1178
|
+
function loadPrismPlugin(name) {
|
|
1179
|
+
try {
|
|
1180
|
+
__require(`prismjs/plugins/${name}/prism-${name}`);
|
|
1181
|
+
} catch (e) {
|
|
1182
|
+
throw new Error(`Cannot load Prism plugin "${name}". Please check the spelling.`);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function selectLanguage(options, lang) {
|
|
1186
|
+
let langToUse = lang;
|
|
1187
|
+
if (langToUse === "" && options.defaultLanguageForUnspecified !== void 0)
|
|
1188
|
+
langToUse = options.defaultLanguageForUnspecified;
|
|
1189
|
+
let prismLang = loadPrismLang(langToUse);
|
|
1190
|
+
if (prismLang === void 0 && options.defaultLanguageForUnknown !== void 0) {
|
|
1191
|
+
langToUse = options.defaultLanguageForUnknown;
|
|
1192
|
+
prismLang = loadPrismLang(langToUse);
|
|
1193
|
+
}
|
|
1194
|
+
return [langToUse, prismLang];
|
|
1195
|
+
}
|
|
1196
|
+
function highlight(markdownit, options, text, lang) {
|
|
1197
|
+
const [langToUse, prismLang] = selectLanguage(options, lang);
|
|
1198
|
+
let code = text.trimEnd();
|
|
1199
|
+
code = prismLang ? highlightPrism(code, prismLang, langToUse) : markdownit.utils.escapeHtml(code);
|
|
1200
|
+
code = code.split(/\r?\n/g).map((line) => `<span class="line">${line}</span>`).join("\n");
|
|
1201
|
+
const classAttribute = langToUse ? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"` : "";
|
|
1202
|
+
return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`);
|
|
1203
|
+
}
|
|
1204
|
+
function highlightPrism(code, prismLang, langToUse) {
|
|
1205
|
+
const openTags = [];
|
|
1206
|
+
const parser2 = new htmlparser2.Parser({
|
|
1207
|
+
onopentag(tagname, attributes) {
|
|
1208
|
+
openTags.push(new Tag(tagname, attributes));
|
|
1209
|
+
},
|
|
1210
|
+
onclosetag() {
|
|
1211
|
+
openTags.pop();
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
code = Prism.highlight(code, prismLang, langToUse);
|
|
1215
|
+
code = code.split(/\r?\n/g).map((line) => {
|
|
1216
|
+
const prefix = openTags.map((tag) => tag.asOpen()).join("");
|
|
1217
|
+
parser2.write(line);
|
|
1218
|
+
const postfix = openTags.reverse().map((tag) => tag.asClosed()).join("");
|
|
1219
|
+
return prefix + line + postfix;
|
|
1220
|
+
}).join("\n");
|
|
1221
|
+
parser2.end();
|
|
1222
|
+
return code;
|
|
1223
|
+
}
|
|
1224
|
+
function checkLanguageOption(options, optionName) {
|
|
1225
|
+
const language = options[optionName];
|
|
1226
|
+
if (language !== void 0 && loadPrismLang(language) === void 0)
|
|
1227
|
+
throw new Error(`Bad option ${optionName}: There is no Prism language '${language}'.`);
|
|
1228
|
+
}
|
|
1229
|
+
function markdownItPrism(markdownit, useroptions) {
|
|
1230
|
+
const options = Object.assign({}, DEFAULTS, useroptions);
|
|
1231
|
+
checkLanguageOption(options, "defaultLanguage");
|
|
1232
|
+
checkLanguageOption(options, "defaultLanguageForUnknown");
|
|
1233
|
+
checkLanguageOption(options, "defaultLanguageForUnspecified");
|
|
1234
|
+
options.defaultLanguageForUnknown = options.defaultLanguageForUnknown || options.defaultLanguage;
|
|
1235
|
+
options.defaultLanguageForUnspecified = options.defaultLanguageForUnspecified || options.defaultLanguage;
|
|
1236
|
+
options.plugins.forEach(loadPrismPlugin);
|
|
1237
|
+
options.init(Prism);
|
|
1238
|
+
markdownit.options.highlight = (text, lang) => highlight(markdownit, options, text, lang);
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// node/plugins/markdown-it-shiki.ts
|
|
1242
|
+
function getThemeName(theme) {
|
|
1243
|
+
if (typeof theme === "string")
|
|
1244
|
+
return theme;
|
|
1245
|
+
return theme.name;
|
|
1246
|
+
}
|
|
1247
|
+
function isShikiDarkModeThemes(theme) {
|
|
1248
|
+
return typeof theme === "object" && ("dark" in theme || "light" in theme);
|
|
1249
|
+
}
|
|
1250
|
+
function resolveShikiOptions(options) {
|
|
1251
|
+
const themes = [];
|
|
1252
|
+
let darkModeThemes;
|
|
1253
|
+
if (!options.theme) {
|
|
1254
|
+
themes.push("nord");
|
|
1255
|
+
} else if (typeof options.theme === "string") {
|
|
1256
|
+
themes.push(options.theme);
|
|
1257
|
+
} else {
|
|
1258
|
+
if (isShikiDarkModeThemes(options.theme)) {
|
|
1259
|
+
darkModeThemes = options.theme;
|
|
1260
|
+
themes.push(options.theme.dark);
|
|
1261
|
+
themes.push(options.theme.light);
|
|
1262
|
+
} else {
|
|
1263
|
+
themes.push(options.theme);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return {
|
|
1267
|
+
...options,
|
|
1268
|
+
themes,
|
|
1269
|
+
darkModeThemes: darkModeThemes ? {
|
|
1270
|
+
dark: getThemeName(darkModeThemes.dark),
|
|
1271
|
+
light: getThemeName(darkModeThemes.light)
|
|
1272
|
+
} : void 0
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
function trimEndNewLine(code) {
|
|
1276
|
+
return code.replace(/\n$/, "");
|
|
1277
|
+
}
|
|
1278
|
+
var MarkdownItShiki = (markdownit, options = {}) => {
|
|
1279
|
+
const _highlighter = options.highlighter;
|
|
1280
|
+
const { darkModeThemes } = resolveShikiOptions(options);
|
|
1281
|
+
markdownit.options.highlight = (code, lang) => {
|
|
1282
|
+
if (darkModeThemes) {
|
|
1283
|
+
const trimmed = trimEndNewLine(code);
|
|
1284
|
+
const dark = _highlighter.codeToHtml(trimmed, { lang: lang || "text", theme: darkModeThemes.dark }).replace('<pre class="shiki', '<pre class="slidev-code shiki shiki-dark');
|
|
1285
|
+
const light = _highlighter.codeToHtml(trimmed, { lang: lang || "text", theme: darkModeThemes.light }).replace('<pre class="shiki', '<pre class="slidev-code shiki shiki-light');
|
|
1286
|
+
return escapeVueInCode(`<pre class="shiki-container">${dark}${light}</pre>`);
|
|
1287
|
+
} else {
|
|
1288
|
+
return escapeVueInCode(
|
|
1289
|
+
_highlighter.codeToHtml(code, { lang: lang || "text" }).replace('<pre class="shiki"', '<pre class="slidev-code shiki"')
|
|
1290
|
+
);
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
var markdown_it_shiki_default = MarkdownItShiki;
|
|
1295
|
+
|
|
1296
|
+
// node/plugins/markdown.ts
|
|
1297
|
+
var DEFAULT_SHIKI_OPTIONS = {
|
|
1298
|
+
theme: {
|
|
1299
|
+
dark: "min-dark",
|
|
1300
|
+
light: "min-light"
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
async function createMarkdownPlugin({ data: { config }, roots, mode, entry }, { markdown: mdOptions }) {
|
|
1304
|
+
const setups = [];
|
|
1305
|
+
const entryPath = slash4(entry);
|
|
1306
|
+
if (config.highlighter === "shiki") {
|
|
1307
|
+
const Shiki = await import("shiki");
|
|
1308
|
+
const shikiOptions = await loadSetups(roots, "shiki.ts", Shiki, DEFAULT_SHIKI_OPTIONS, false);
|
|
1309
|
+
const { langs, themes } = resolveShikiOptions(shikiOptions);
|
|
1310
|
+
shikiOptions.highlighter = await Shiki.getHighlighter({ themes, langs });
|
|
1311
|
+
setups.push((md2) => md2.use(markdown_it_shiki_default, shikiOptions));
|
|
1312
|
+
} else {
|
|
1313
|
+
setups.push((md2) => md2.use(markdownItPrism));
|
|
1314
|
+
}
|
|
1315
|
+
if (config.mdc)
|
|
1316
|
+
setups.push((md2) => md2.use(Mdc));
|
|
1317
|
+
const KatexOptions = await loadSetups(roots, "katex.ts", {}, { strict: false }, false);
|
|
1318
|
+
return Markdown2({
|
|
1319
|
+
include: [/\.md$/],
|
|
1320
|
+
wrapperClasses: "",
|
|
1321
|
+
headEnabled: false,
|
|
1322
|
+
frontmatter: false,
|
|
1323
|
+
markdownItOptions: {
|
|
1324
|
+
quotes: `""''`,
|
|
1325
|
+
html: true,
|
|
1326
|
+
xhtmlOut: true,
|
|
1327
|
+
linkify: true,
|
|
1328
|
+
...mdOptions?.markdownItOptions
|
|
1329
|
+
},
|
|
1330
|
+
...mdOptions,
|
|
1331
|
+
markdownItSetup(md2) {
|
|
1332
|
+
md2.use(mila2, {
|
|
1333
|
+
attrs: {
|
|
1334
|
+
target: "_blank",
|
|
1335
|
+
rel: "noopener"
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
md2.use(mif);
|
|
1339
|
+
md2.use(taskLists, { enabled: true, lineNumber: true, label: true });
|
|
1340
|
+
md2.use(math_plugin, KatexOptions);
|
|
1341
|
+
setups.forEach((i) => i(md2));
|
|
1342
|
+
mdOptions?.markdownItSetup?.(md2);
|
|
1343
|
+
},
|
|
1344
|
+
transforms: {
|
|
1345
|
+
before(code, id) {
|
|
1346
|
+
if (id === entryPath)
|
|
1347
|
+
return "";
|
|
1348
|
+
const monaco = config.monaco === true || config.monaco === mode ? transformMarkdownMonaco : truncateMancoMark;
|
|
1349
|
+
code = transformSlotSugar(code);
|
|
1350
|
+
code = transformMermaid(code);
|
|
1351
|
+
code = transformPlantUml(code, config.plantUmlServer);
|
|
1352
|
+
code = monaco(code);
|
|
1353
|
+
code = transformHighlighter(code);
|
|
1354
|
+
code = transformPageCSS(code, id);
|
|
1355
|
+
return code;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
function transformMarkdownMonaco(md2) {
|
|
1361
|
+
md2 = md2.replace(/^```(\w+?)\s*{monaco-diff}\s*?({.*?})?\s*?\n([\s\S]+?)^~~~\s*?\n([\s\S]+?)^```/mg, (full, lang = "ts", options = "{}", code, diff) => {
|
|
1362
|
+
lang = lang.trim();
|
|
1363
|
+
options = options.trim() || "{}";
|
|
1364
|
+
const encoded = base64.encode(code, true);
|
|
1365
|
+
const encodedDiff = base64.encode(diff, true);
|
|
1366
|
+
return `<Monaco :code="'${encoded}'" :diff="'${encodedDiff}'" lang="${lang}" v-bind="${options}" />`;
|
|
1367
|
+
});
|
|
1368
|
+
md2 = md2.replace(/^```(\w+?)\s*{monaco}\s*?({.*?})?\s*?\n([\s\S]+?)^```/mg, (full, lang = "ts", options = "{}", code) => {
|
|
1369
|
+
lang = lang.trim();
|
|
1370
|
+
options = options.trim() || "{}";
|
|
1371
|
+
const encoded = base64.encode(code, true);
|
|
1372
|
+
return `<Monaco :code="'${encoded}'" lang="${lang}" v-bind="${options}" />`;
|
|
1373
|
+
});
|
|
1374
|
+
return md2;
|
|
1375
|
+
}
|
|
1376
|
+
function truncateMancoMark(md2) {
|
|
1377
|
+
return md2.replace(/{monaco.*?}/g, "");
|
|
1378
|
+
}
|
|
1379
|
+
function transformSlotSugar(md2) {
|
|
1380
|
+
const lines = md2.split(/\r?\n/g);
|
|
1381
|
+
let prevSlot = false;
|
|
1382
|
+
const { isLineInsideCodeblocks } = getCodeBlocks(md2);
|
|
1383
|
+
lines.forEach((line, idx) => {
|
|
1384
|
+
if (isLineInsideCodeblocks(idx))
|
|
1385
|
+
return;
|
|
1386
|
+
const match = line.trimEnd().match(/^::\s*(\w+)\s*::$/);
|
|
1387
|
+
if (match) {
|
|
1388
|
+
lines[idx] = `${prevSlot ? "\n\n</template>\n" : "\n"}<template v-slot:${match[1]}="slotProps">
|
|
1389
|
+
`;
|
|
1390
|
+
prevSlot = true;
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
if (prevSlot)
|
|
1394
|
+
lines[lines.length - 1] += "\n\n</template>";
|
|
1395
|
+
return lines.join("\n");
|
|
1396
|
+
}
|
|
1397
|
+
function transformHighlighter(md2) {
|
|
1398
|
+
return md2.replace(/^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?\s*?)?\n([\s\S]+?)^```/mg, (full, lang = "", rangeStr = "", options = "", code) => {
|
|
1399
|
+
const ranges = rangeStr.split(/\|/g).map((i) => i.trim());
|
|
1400
|
+
code = code.trimEnd();
|
|
1401
|
+
options = options.trim() || "{}";
|
|
1402
|
+
return `
|
|
1403
|
+
<CodeBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
|
|
1404
|
+
|
|
1405
|
+
\`\`\`${lang}
|
|
1406
|
+
${code}
|
|
1407
|
+
\`\`\`
|
|
1408
|
+
|
|
1409
|
+
</CodeBlockWrapper>`;
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
function getCodeBlocks(md2) {
|
|
1413
|
+
const codeblocks = Array.from(md2.matchAll(/^```[\s\S]*?^```/mg)).map((m) => {
|
|
1414
|
+
const start = m.index;
|
|
1415
|
+
const end = m.index + m[0].length;
|
|
1416
|
+
const startLine = md2.slice(0, start).match(/\n/g)?.length || 0;
|
|
1417
|
+
const endLine = md2.slice(0, end).match(/\n/g)?.length || 0;
|
|
1418
|
+
return [start, end, startLine, endLine];
|
|
1419
|
+
});
|
|
1420
|
+
return {
|
|
1421
|
+
codeblocks,
|
|
1422
|
+
isInsideCodeblocks(idx) {
|
|
1423
|
+
return codeblocks.some(([s, e]) => s <= idx && idx <= e);
|
|
1424
|
+
},
|
|
1425
|
+
isLineInsideCodeblocks(line) {
|
|
1426
|
+
return codeblocks.some(([, , s, e]) => s <= line && line <= e);
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
function transformPageCSS(md2, id) {
|
|
1431
|
+
const page = id.match(/(\d+)\.md$/)?.[1];
|
|
1432
|
+
if (!page)
|
|
1433
|
+
return md2;
|
|
1434
|
+
const { isInsideCodeblocks } = getCodeBlocks(md2);
|
|
1435
|
+
const result = md2.replace(
|
|
1436
|
+
/(\n<style[^>]*?>)([\s\S]+?)(<\/style>)/g,
|
|
1437
|
+
(full, start, css, end, index) => {
|
|
1438
|
+
if (index < 0 || isInsideCodeblocks(index))
|
|
1439
|
+
return full;
|
|
1440
|
+
if (!start.includes("scoped"))
|
|
1441
|
+
start = start.replace("<style", "<style scoped");
|
|
1442
|
+
return `${start}
|
|
1443
|
+
${css}${end}`;
|
|
1444
|
+
}
|
|
1445
|
+
);
|
|
1446
|
+
return result;
|
|
1447
|
+
}
|
|
1448
|
+
function transformMermaid(md2) {
|
|
1449
|
+
return md2.replace(/^```mermaid\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", code = "") => {
|
|
1450
|
+
code = code.trim();
|
|
1451
|
+
options = options.trim() || "{}";
|
|
1452
|
+
const encoded = base64.encode(code, true);
|
|
1453
|
+
return `<Mermaid :code="'${encoded}'" v-bind="${options}" />`;
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
function transformPlantUml(md2, server) {
|
|
1457
|
+
return md2.replace(/^```plantuml\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = "", content = "") => {
|
|
1458
|
+
const code = encode2(content.trim());
|
|
1459
|
+
options = options.trim() || "{}";
|
|
1460
|
+
return `<PlantUml :code="'${code}'" :server="'${server}'" v-bind="${options}" />`;
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
function escapeVueInCode(md2) {
|
|
1464
|
+
return md2.replace(/{{(.*?)}}/g, "{{$1}}");
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// node/plugins/patchTransform.ts
|
|
1468
|
+
import { objectEntries } from "@antfu/utils";
|
|
1469
|
+
function createFixPlugins(options) {
|
|
1470
|
+
const define = objectEntries(getDefine(options));
|
|
1471
|
+
return [
|
|
1472
|
+
{
|
|
1473
|
+
name: "slidev:flags",
|
|
1474
|
+
enforce: "pre",
|
|
1475
|
+
transform(code, id) {
|
|
1476
|
+
if (id.match(/\.vue($|\?)/)) {
|
|
1477
|
+
const original = code;
|
|
1478
|
+
define.forEach(([from, to]) => {
|
|
1479
|
+
code = code.replace(new RegExp(from, "g"), to);
|
|
1480
|
+
});
|
|
1481
|
+
if (original !== code)
|
|
1482
|
+
return code;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
];
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// node/plugins/preset.ts
|
|
1490
|
+
var customElements = /* @__PURE__ */ new Set([
|
|
1491
|
+
// katex
|
|
1492
|
+
"annotation",
|
|
1493
|
+
"math",
|
|
1494
|
+
"menclose",
|
|
1495
|
+
"mfrac",
|
|
1496
|
+
"mglyph",
|
|
1497
|
+
"mi",
|
|
1498
|
+
"mlabeledtr",
|
|
1499
|
+
"mn",
|
|
1500
|
+
"mo",
|
|
1501
|
+
"mover",
|
|
1502
|
+
"mpadded",
|
|
1503
|
+
"mphantom",
|
|
1504
|
+
"mroot",
|
|
1505
|
+
"mrow",
|
|
1506
|
+
"mspace",
|
|
1507
|
+
"msqrt",
|
|
1508
|
+
"mstyle",
|
|
1509
|
+
"msub",
|
|
1510
|
+
"msubsup",
|
|
1511
|
+
"msup",
|
|
1512
|
+
"mtable",
|
|
1513
|
+
"mtd",
|
|
1514
|
+
"mtext",
|
|
1515
|
+
"mtr",
|
|
1516
|
+
"munder",
|
|
1517
|
+
"munderover",
|
|
1518
|
+
"semantics"
|
|
1519
|
+
]);
|
|
1520
|
+
async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
|
|
1521
|
+
const {
|
|
1522
|
+
vue: vueOptions = {},
|
|
1523
|
+
vuejsx: vuejsxOptions = {},
|
|
1524
|
+
components: componentsOptions = {},
|
|
1525
|
+
icons: iconsOptions = {},
|
|
1526
|
+
remoteAssets: remoteAssetsOptions = {},
|
|
1527
|
+
serverRef: serverRefOptions = {}
|
|
1528
|
+
} = pluginOptions;
|
|
1529
|
+
const {
|
|
1530
|
+
mode,
|
|
1531
|
+
themeRoots,
|
|
1532
|
+
addonRoots,
|
|
1533
|
+
clientRoot,
|
|
1534
|
+
data: { config }
|
|
1535
|
+
} = options;
|
|
1536
|
+
const VuePlugin = Vue({
|
|
1537
|
+
include: [/\.vue$/, /\.md$/],
|
|
1538
|
+
exclude: [],
|
|
1539
|
+
template: {
|
|
1540
|
+
compilerOptions: {
|
|
1541
|
+
isCustomElement(tag) {
|
|
1542
|
+
return customElements.has(tag);
|
|
1543
|
+
}
|
|
1544
|
+
},
|
|
1545
|
+
...vueOptions?.template
|
|
1546
|
+
},
|
|
1547
|
+
...vueOptions
|
|
1548
|
+
});
|
|
1549
|
+
const VueJsxPlugin = VueJsx(vuejsxOptions);
|
|
1550
|
+
const MarkdownPlugin = await createMarkdownPlugin(options, pluginOptions);
|
|
1551
|
+
const drawingData = await loadDrawings(options);
|
|
1552
|
+
const publicRoots = themeRoots.map((i) => join8(i, "public")).filter(existsSync4);
|
|
1553
|
+
const plugins = [
|
|
1554
|
+
MarkdownPlugin,
|
|
1555
|
+
VueJsxPlugin,
|
|
1556
|
+
VuePlugin,
|
|
1557
|
+
createSlidesLoader(options, pluginOptions, serverOptions),
|
|
1558
|
+
Components({
|
|
1559
|
+
extensions: ["vue", "md", "js", "ts", "jsx", "tsx"],
|
|
1560
|
+
dirs: [
|
|
1561
|
+
join8(clientRoot, "builtin"),
|
|
1562
|
+
join8(clientRoot, "components"),
|
|
1563
|
+
...themeRoots.map((i) => join8(i, "components")),
|
|
1564
|
+
...addonRoots.map((i) => join8(i, "components")),
|
|
1565
|
+
"src/components",
|
|
1566
|
+
"components"
|
|
1567
|
+
],
|
|
1568
|
+
include: [/\.vue$/, /\.vue\?vue/, /\.vue\?v=/, /\.md$/],
|
|
1569
|
+
exclude: [],
|
|
1570
|
+
resolvers: [
|
|
1571
|
+
IconsResolver({
|
|
1572
|
+
prefix: "",
|
|
1573
|
+
customCollections: Object.keys(iconsOptions.customCollections || [])
|
|
1574
|
+
})
|
|
1575
|
+
],
|
|
1576
|
+
dts: false,
|
|
1577
|
+
...componentsOptions
|
|
1578
|
+
}),
|
|
1579
|
+
Icons({
|
|
1580
|
+
defaultClass: "slidev-icon",
|
|
1581
|
+
autoInstall: true,
|
|
1582
|
+
...iconsOptions
|
|
1583
|
+
}),
|
|
1584
|
+
config.remoteAssets === true || config.remoteAssets === mode ? import("vite-plugin-remote-assets").then((r) => r.default({
|
|
1585
|
+
rules: [
|
|
1586
|
+
...r.DefaultRules,
|
|
1587
|
+
{
|
|
1588
|
+
match: /\b(https?:\/\/image.unsplash\.com.*?)(?=[`'")\]])/ig,
|
|
1589
|
+
ext: ".png"
|
|
1590
|
+
}
|
|
1591
|
+
],
|
|
1592
|
+
resolveMode: (id) => id.endsWith("index.html") ? "relative" : "@fs",
|
|
1593
|
+
awaitDownload: mode === "build",
|
|
1594
|
+
...remoteAssetsOptions
|
|
1595
|
+
})) : null,
|
|
1596
|
+
ServerRef({
|
|
1597
|
+
debug: process3.env.NODE_ENV === "development",
|
|
1598
|
+
state: {
|
|
1599
|
+
sync: false,
|
|
1600
|
+
nav: {
|
|
1601
|
+
page: 0,
|
|
1602
|
+
clicks: 0
|
|
1603
|
+
},
|
|
1604
|
+
drawings: drawingData,
|
|
1605
|
+
...serverRefOptions.state
|
|
1606
|
+
},
|
|
1607
|
+
onChanged(key, data, patch, timestamp) {
|
|
1608
|
+
serverRefOptions.onChanged && serverRefOptions.onChanged(key, data, patch, timestamp);
|
|
1609
|
+
if (!options.data.config.drawings.persist)
|
|
1610
|
+
return;
|
|
1611
|
+
if (key === "drawings")
|
|
1612
|
+
writeDrawings(options, patch ?? data);
|
|
1613
|
+
}
|
|
1614
|
+
}),
|
|
1615
|
+
createConfigPlugin(options),
|
|
1616
|
+
createClientSetupPlugin(options),
|
|
1617
|
+
createMonacoTypesLoader(),
|
|
1618
|
+
createFixPlugins(options),
|
|
1619
|
+
publicRoots.length ? import("vite-plugin-static-copy").then((r) => r.viteStaticCopy({
|
|
1620
|
+
silent: true,
|
|
1621
|
+
targets: publicRoots.map((r2) => ({
|
|
1622
|
+
src: `${r2}/*`,
|
|
1623
|
+
dest: "theme"
|
|
1624
|
+
}))
|
|
1625
|
+
})) : null,
|
|
1626
|
+
options.inspect ? import("vite-plugin-inspect").then((r) => (r.default || r)({
|
|
1627
|
+
dev: true,
|
|
1628
|
+
build: true
|
|
1629
|
+
})) : null,
|
|
1630
|
+
config.css === "none" ? null : config.css === "windicss" ? import("./windicss-UVXCUIV4.mjs").then((r) => r.createWindiCSSPlugin(options, pluginOptions)) : import("./unocss-2UOAV4VT.mjs").then((r) => r.createUnocssPlugin(options, pluginOptions))
|
|
1631
|
+
];
|
|
1632
|
+
return (await Promise.all(plugins)).flat().filter(notNullish2);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
export {
|
|
1636
|
+
getIndexHtml,
|
|
1637
|
+
mergeViteConfigs,
|
|
1638
|
+
require_fast_deep_equal,
|
|
1639
|
+
ViteSlidevPlugin
|
|
1640
|
+
};
|