@slidev/cli 0.22.6 → 0.23.2
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/README.md +14 -13
- package/dist/{build-M5EATJMB.mjs → build-IEU5WUDM.mjs} +26 -20
- package/dist/{build-NE7OFJDC.js → build-QDRV2UJ5.js} +28 -22
- package/dist/chunk-6LUF2SCB.mjs +10259 -0
- package/dist/{chunk-3QL4BHWJ.js → chunk-M25N7CYC.js} +173 -147
- package/dist/{chunk-WW3PRZGC.mjs → chunk-NHK2R4LN.mjs} +198 -172
- package/dist/chunk-S6F4YP7Z.js +10259 -0
- package/dist/{chunk-ZRBGXFM7.js → chunk-UJKYYHMF.js} +3 -2
- package/dist/{chunk-WM7KTGRL.mjs → chunk-VWK3TRVU.mjs} +2 -1
- package/dist/cli.js +29 -21
- package/dist/cli.mjs +17 -9
- package/dist/{export-JCHMAWVR.mjs → export-SNR56WLB.mjs} +1 -1
- package/dist/{export-74CUV4GO.js → export-ZTTMEOKV.js} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/index.mjs +3 -3
- package/package.json +30 -29
- package/dist/chunk-DJLELPCD.mjs +0 -9983
- package/dist/chunk-ZCNASYZV.js +0 -9983
|
@@ -92,15 +92,13 @@ import { resolve as resolve2, dirname } from "path";
|
|
|
92
92
|
import { existsSync as existsSync3 } from "fs";
|
|
93
93
|
import { slash, uniq as uniq2 } from "@antfu/utils";
|
|
94
94
|
import WindiCSS, { defaultConfigureFiles } from "vite-plugin-windicss";
|
|
95
|
-
|
|
96
|
-
// node/plugins/jiti.ts
|
|
97
|
-
import _jiti from "jiti";
|
|
98
|
-
var jiti = _jiti(__filename);
|
|
95
|
+
import jiti2 from "jiti";
|
|
99
96
|
|
|
100
97
|
// node/plugins/setupNode.ts
|
|
101
98
|
import { resolve } from "path";
|
|
102
99
|
import { existsSync as existsSync2 } from "fs-extra";
|
|
103
100
|
import { isObject } from "@antfu/utils";
|
|
101
|
+
import jiti from "jiti";
|
|
104
102
|
function deepMerge(a, b, rootPath = "") {
|
|
105
103
|
a = __spreadValues({}, a);
|
|
106
104
|
Object.keys(b).forEach((key) => {
|
|
@@ -118,7 +116,7 @@ async function loadSetups(roots, name, arg, initial, merge = true) {
|
|
|
118
116
|
for (const root of roots) {
|
|
119
117
|
const path = resolve(root, "setup", name);
|
|
120
118
|
if (existsSync2(path)) {
|
|
121
|
-
const { default: setup } = jiti(path);
|
|
119
|
+
const { default: setup } = jiti(__filename)(path);
|
|
122
120
|
const result = await setup(arg);
|
|
123
121
|
if (result !== null) {
|
|
124
122
|
returns = merge ? deepMerge(returns, result) : result;
|
|
@@ -136,7 +134,7 @@ async function createWindiCSSPlugin({ themeRoots, clientRoot, userRoot, roots, d
|
|
|
136
134
|
resolve2(clientRoot, "windi.config.ts")
|
|
137
135
|
]);
|
|
138
136
|
const configFile = configFiles.find((i) => existsSync3(i));
|
|
139
|
-
let config =
|
|
137
|
+
let config = jiti2(__filename)(configFile);
|
|
140
138
|
if (config.default)
|
|
141
139
|
config = config.default;
|
|
142
140
|
config = await loadSetups(roots, "windicss.ts", {}, config, true);
|
|
@@ -171,42 +169,134 @@ async function createWindiCSSPlugin({ themeRoots, clientRoot, userRoot, roots, d
|
|
|
171
169
|
|
|
172
170
|
// node/plugins/preset.ts
|
|
173
171
|
import Vue from "@vitejs/plugin-vue";
|
|
174
|
-
import
|
|
175
|
-
import
|
|
172
|
+
import Icons from "unplugin-icons/vite";
|
|
173
|
+
import IconsResolver from "unplugin-icons/resolver";
|
|
174
|
+
import Components from "unplugin-vue-components/vite";
|
|
176
175
|
import RemoteAssets, { DefaultRules } from "vite-plugin-remote-assets";
|
|
176
|
+
import ServerRef from "vite-plugin-vue-server-ref";
|
|
177
177
|
import { notNullish as notNullish2 } from "@antfu/utils";
|
|
178
178
|
|
|
179
|
-
// node/
|
|
180
|
-
import { join as join2 } from "path";
|
|
179
|
+
// node/drawings.ts
|
|
180
|
+
import { dirname as dirname2, resolve as resolve3, join as join2, basename } from "path";
|
|
181
|
+
import fs2 from "fs-extra";
|
|
182
|
+
import fg from "fast-glob";
|
|
183
|
+
function resolveDrawingsDir(options) {
|
|
184
|
+
return options.data.config.drawings.persist ? resolve3(dirname2(options.entry), options.data.config.drawings.persist) : void 0;
|
|
185
|
+
}
|
|
186
|
+
async function loadDrawings(options) {
|
|
187
|
+
const dir = resolveDrawingsDir(options);
|
|
188
|
+
if (!dir || !fs2.existsSync(dir))
|
|
189
|
+
return {};
|
|
190
|
+
const files = await fg("*.svg", {
|
|
191
|
+
onlyFiles: true,
|
|
192
|
+
cwd: dir,
|
|
193
|
+
absolute: true
|
|
194
|
+
});
|
|
195
|
+
const obj = {};
|
|
196
|
+
Promise.all(files.map(async (path) => {
|
|
197
|
+
const num = +basename(path, ".svg");
|
|
198
|
+
if (Number.isNaN(num))
|
|
199
|
+
return;
|
|
200
|
+
const content = await fs2.readFile(path, "utf8");
|
|
201
|
+
const lines = content.split(/\n/g);
|
|
202
|
+
obj[num.toString()] = lines.slice(1, -1).join("\n");
|
|
203
|
+
}));
|
|
204
|
+
return obj;
|
|
205
|
+
}
|
|
206
|
+
async function writeDarwings(options, drawing) {
|
|
207
|
+
const dir = resolveDrawingsDir(options);
|
|
208
|
+
if (!dir)
|
|
209
|
+
return;
|
|
210
|
+
const width = options.data.config.canvasWidth;
|
|
211
|
+
const height = Math.round(width / options.data.config.aspectRatio);
|
|
212
|
+
const SVG_HEAD = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">`;
|
|
213
|
+
await fs2.ensureDir(dir);
|
|
214
|
+
return Promise.all(Object.entries(drawing).map(async ([key, value]) => {
|
|
215
|
+
if (!value)
|
|
216
|
+
return;
|
|
217
|
+
const svg = `${SVG_HEAD}
|
|
218
|
+
${value}
|
|
219
|
+
</svg>`;
|
|
220
|
+
await fs2.writeFile(join2(dir, `${key}.svg`), svg, "utf-8");
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// node/plugins/extendConfig.ts
|
|
225
|
+
import { dirname as dirname4, join as join4 } from "path";
|
|
181
226
|
import { mergeConfig } from "vite";
|
|
182
227
|
import isInstalledGlobally from "is-installed-globally";
|
|
228
|
+
import resolveGlobal from "resolve-global";
|
|
229
|
+
import { uniq as uniq3 } from "@antfu/utils";
|
|
183
230
|
|
|
184
231
|
// ../client/package.json
|
|
185
232
|
var dependencies = {
|
|
186
|
-
"@antfu/utils": "^0.
|
|
233
|
+
"@antfu/utils": "^0.3.0",
|
|
187
234
|
"@slidev/parser": "workspace:*",
|
|
188
235
|
"@slidev/types": "workspace:*",
|
|
189
|
-
"@vueuse/core": "^
|
|
236
|
+
"@vueuse/core": "^6.3.3",
|
|
190
237
|
"@vueuse/head": "^0.6.0",
|
|
191
|
-
"@vueuse/motion": "^1.
|
|
192
|
-
codemirror: "^5.62.
|
|
238
|
+
"@vueuse/motion": "^1.6.0",
|
|
239
|
+
codemirror: "^5.62.3",
|
|
240
|
+
drauu: "^0.1.0",
|
|
193
241
|
"file-saver": "^2.0.5",
|
|
194
|
-
"js-base64": "^3.
|
|
242
|
+
"js-base64": "^3.7.0",
|
|
195
243
|
"js-yaml": "^4.1.0",
|
|
196
|
-
katex: "^0.13.
|
|
197
|
-
mermaid: "8.
|
|
198
|
-
"monaco-editor": "^0.
|
|
199
|
-
nanoid: "^3.1.
|
|
200
|
-
prettier: "^2.
|
|
244
|
+
katex: "^0.13.18",
|
|
245
|
+
mermaid: "^8.12.1",
|
|
246
|
+
"monaco-editor": "^0.27.0",
|
|
247
|
+
nanoid: "^3.1.25",
|
|
248
|
+
prettier: "^2.4.0",
|
|
201
249
|
recordrtc: "^5.6.2",
|
|
202
250
|
resolve: "^1.20.0",
|
|
203
|
-
"vite-plugin-windicss": "^1.2
|
|
204
|
-
vue: "^3.
|
|
205
|
-
"vue-router": "^4.0.
|
|
206
|
-
windicss: "^3.1.
|
|
251
|
+
"vite-plugin-windicss": "^1.4.2",
|
|
252
|
+
vue: "^3.2.11",
|
|
253
|
+
"vue-router": "^4.0.11",
|
|
254
|
+
windicss: "^3.1.7"
|
|
207
255
|
};
|
|
208
256
|
|
|
209
|
-
// node/
|
|
257
|
+
// node/vite/searchRoot.ts
|
|
258
|
+
import fs3 from "fs";
|
|
259
|
+
import { dirname as dirname3, join as join3 } from "path";
|
|
260
|
+
var ROOT_FILES = [
|
|
261
|
+
"pnpm-workspace.yaml"
|
|
262
|
+
];
|
|
263
|
+
function hasWorkspacePackageJSON(root) {
|
|
264
|
+
const path = join3(root, "package.json");
|
|
265
|
+
try {
|
|
266
|
+
fs3.accessSync(path, fs3.constants.R_OK);
|
|
267
|
+
} catch {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
const content = JSON.parse(fs3.readFileSync(path, "utf-8")) || {};
|
|
271
|
+
return !!content.workspaces;
|
|
272
|
+
}
|
|
273
|
+
function hasRootFile(root) {
|
|
274
|
+
return ROOT_FILES.some((file) => fs3.existsSync(join3(root, file)));
|
|
275
|
+
}
|
|
276
|
+
function hasPackageJSON(root) {
|
|
277
|
+
const path = join3(root, "package.json");
|
|
278
|
+
return fs3.existsSync(path);
|
|
279
|
+
}
|
|
280
|
+
function searchForPackageRoot(current, root = current) {
|
|
281
|
+
if (hasPackageJSON(current))
|
|
282
|
+
return current;
|
|
283
|
+
const dir = dirname3(current);
|
|
284
|
+
if (!dir || dir === current)
|
|
285
|
+
return root;
|
|
286
|
+
return searchForPackageRoot(dir, root);
|
|
287
|
+
}
|
|
288
|
+
function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
|
|
289
|
+
if (hasRootFile(current))
|
|
290
|
+
return current;
|
|
291
|
+
if (hasWorkspacePackageJSON(current))
|
|
292
|
+
return current;
|
|
293
|
+
const dir = dirname3(current);
|
|
294
|
+
if (!dir || dir === current)
|
|
295
|
+
return root;
|
|
296
|
+
return searchForWorkspaceRoot(dir, root);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// node/plugins/extendConfig.ts
|
|
210
300
|
var EXCLUDE = [
|
|
211
301
|
"@slidev/shared",
|
|
212
302
|
"@slidev/types",
|
|
@@ -221,11 +311,7 @@ function createConfigPlugin(options) {
|
|
|
221
311
|
name: "slidev:config",
|
|
222
312
|
config(config) {
|
|
223
313
|
const injection = {
|
|
224
|
-
define:
|
|
225
|
-
__SLIDEV_CLIENT_ROOT__: JSON.stringify(toAtFS(options.clientRoot)),
|
|
226
|
-
__SLIDEV_HASH_ROUTE__: options.data.config.routerMode === "hash",
|
|
227
|
-
__DEV__: options.mode === "dev" ? "true" : "false"
|
|
228
|
-
},
|
|
314
|
+
define: getDefine(options),
|
|
229
315
|
resolve: {
|
|
230
316
|
alias: {
|
|
231
317
|
"@slidev/client/": `${toAtFS(options.clientRoot)}/`
|
|
@@ -243,18 +329,24 @@ function createConfigPlugin(options) {
|
|
|
243
329
|
"prettier/esm/parser-babel",
|
|
244
330
|
"prettier/esm/parser-html",
|
|
245
331
|
"prettier/esm/parser-typescript",
|
|
246
|
-
"mermaid/dist/mermaid.min"
|
|
332
|
+
"mermaid/dist/mermaid.min",
|
|
333
|
+
"vite-plugin-vue-server-ref/client"
|
|
247
334
|
],
|
|
248
335
|
exclude: EXCLUDE
|
|
249
336
|
},
|
|
250
337
|
server: {
|
|
251
338
|
fs: {
|
|
252
|
-
strict: true
|
|
339
|
+
strict: true,
|
|
340
|
+
allow: uniq3([
|
|
341
|
+
searchForWorkspaceRoot(options.userRoot),
|
|
342
|
+
searchForWorkspaceRoot(options.cliRoot),
|
|
343
|
+
...isInstalledGlobally ? [dirname4(resolveGlobal("@slidev/client/package.json"))] : []
|
|
344
|
+
])
|
|
253
345
|
}
|
|
254
346
|
}
|
|
255
347
|
};
|
|
256
348
|
if (isInstalledGlobally) {
|
|
257
|
-
injection.cacheDir =
|
|
349
|
+
injection.cacheDir = join4(options.cliRoot, "node_modules/.vite");
|
|
258
350
|
injection.root = options.cliRoot;
|
|
259
351
|
injection.resolve.alias.vue = `${resolveImportPath("vue/dist/vue.esm-browser.js", true)}`;
|
|
260
352
|
}
|
|
@@ -264,6 +356,7 @@ function createConfigPlugin(options) {
|
|
|
264
356
|
return () => {
|
|
265
357
|
server.middlewares.use(async (req, res, next) => {
|
|
266
358
|
if (req.url.endsWith(".html")) {
|
|
359
|
+
res.setHeader("Content-Type", "text/html");
|
|
267
360
|
res.statusCode = 200;
|
|
268
361
|
res.end(await getIndexHtml(options));
|
|
269
362
|
return;
|
|
@@ -274,13 +367,22 @@ function createConfigPlugin(options) {
|
|
|
274
367
|
}
|
|
275
368
|
};
|
|
276
369
|
}
|
|
370
|
+
function getDefine(options) {
|
|
371
|
+
return {
|
|
372
|
+
__SLIDEV_CLIENT_ROOT__: JSON.stringify(toAtFS(options.clientRoot)),
|
|
373
|
+
__SLIDEV_HASH_ROUTE__: JSON.stringify(options.data.config.routerMode === "hash"),
|
|
374
|
+
__SLIDEV_FEATURE_DRAWINGS__: JSON.stringify(options.data.config.drawings.enabled === true || options.data.config.drawings.enabled === options.mode),
|
|
375
|
+
__SLIDEV_FEATURE_DRAWINGS_PERSIST__: JSON.stringify(!!options.data.config.drawings.persist === true),
|
|
376
|
+
__DEV__: options.mode === "dev" ? "true" : "false"
|
|
377
|
+
};
|
|
378
|
+
}
|
|
277
379
|
|
|
278
380
|
// node/plugins/loaders.ts
|
|
279
381
|
var import_fast_deep_equal = __toModule(require_fast_deep_equal());
|
|
280
|
-
import { basename, join as
|
|
281
|
-
import { isString, notNullish, objectMap, range, slash as slash2, uniq as
|
|
282
|
-
import
|
|
283
|
-
import
|
|
382
|
+
import { basename as basename2, join as join5 } from "path";
|
|
383
|
+
import { isString, notNullish, objectMap, range, slash as slash2, uniq as uniq4 } from "@antfu/utils";
|
|
384
|
+
import fg2 from "fast-glob";
|
|
385
|
+
import fs4, { existsSync as existsSync4 } from "fs-extra";
|
|
284
386
|
import Markdown from "markdown-it";
|
|
285
387
|
import mila from "markdown-it-link-attributes";
|
|
286
388
|
import {
|
|
@@ -292,13 +394,13 @@ import {
|
|
|
292
394
|
var regexId = /^\/\@slidev\/slide\/(\d+)\.(md|json)(?:\?import)?$/;
|
|
293
395
|
var regexIdQuery = /(\d+?)\.(md|json)$/;
|
|
294
396
|
function getBodyJson(req) {
|
|
295
|
-
return new Promise((
|
|
397
|
+
return new Promise((resolve5, reject) => {
|
|
296
398
|
let body = "";
|
|
297
399
|
req.on("data", (chunk) => body += chunk);
|
|
298
400
|
req.on("error", reject);
|
|
299
401
|
req.on("end", () => {
|
|
300
402
|
try {
|
|
301
|
-
|
|
403
|
+
resolve5(JSON.parse(body) || {});
|
|
302
404
|
} catch (e) {
|
|
303
405
|
reject(e);
|
|
304
406
|
}
|
|
@@ -489,6 +591,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
|
|
|
489
591
|
const layoutName = (frontmatter == null ? void 0 : frontmatter.layout) || (pageNo === 0 ? "cover" : "default");
|
|
490
592
|
if (!layouts[layoutName])
|
|
491
593
|
throw new Error(`Unknown layout "${layoutName}"`);
|
|
594
|
+
delete frontmatter.title;
|
|
492
595
|
const imports = [
|
|
493
596
|
`import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
|
|
494
597
|
`const frontmatter = ${JSON.stringify(frontmatter)}`
|
|
@@ -513,18 +616,18 @@ ${code.slice(injectB)}`;
|
|
|
513
616
|
if (now - _layouts_cache_time < 2e3)
|
|
514
617
|
return _layouts_cache;
|
|
515
618
|
const layouts = {};
|
|
516
|
-
const roots2 =
|
|
619
|
+
const roots2 = uniq4([
|
|
517
620
|
userRoot,
|
|
518
621
|
...themeRoots,
|
|
519
622
|
clientRoot
|
|
520
623
|
]);
|
|
521
624
|
for (const root of roots2) {
|
|
522
|
-
const layoutPaths = await
|
|
625
|
+
const layoutPaths = await fg2("layouts/*.{vue,ts}", {
|
|
523
626
|
cwd: root,
|
|
524
627
|
absolute: true
|
|
525
628
|
});
|
|
526
629
|
for (const layoutPath of layoutPaths) {
|
|
527
|
-
const layout =
|
|
630
|
+
const layout = basename2(layoutPath).replace(/\.\w+$/, "");
|
|
528
631
|
if (layouts[layout])
|
|
529
632
|
continue;
|
|
530
633
|
layouts[layout] = layoutPath;
|
|
@@ -536,21 +639,21 @@ ${code.slice(injectB)}`;
|
|
|
536
639
|
}
|
|
537
640
|
async function generateUserStyles() {
|
|
538
641
|
const imports = [
|
|
539
|
-
`import "${toAtFS(
|
|
540
|
-
`import "${toAtFS(
|
|
541
|
-
`import "${toAtFS(
|
|
642
|
+
`import "${toAtFS(join5(clientRoot, "styles/vars.css"))}"`,
|
|
643
|
+
`import "${toAtFS(join5(clientRoot, "styles/index.css"))}"`,
|
|
644
|
+
`import "${toAtFS(join5(clientRoot, "styles/code.css"))}"`
|
|
542
645
|
];
|
|
543
|
-
const roots2 =
|
|
646
|
+
const roots2 = uniq4([
|
|
544
647
|
...themeRoots,
|
|
545
648
|
userRoot
|
|
546
649
|
]);
|
|
547
650
|
for (const root of roots2) {
|
|
548
651
|
const styles = [
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
652
|
+
join5(root, "styles", "index.ts"),
|
|
653
|
+
join5(root, "styles", "index.js"),
|
|
654
|
+
join5(root, "styles", "index.css"),
|
|
655
|
+
join5(root, "styles.css"),
|
|
656
|
+
join5(root, "style.css")
|
|
554
657
|
];
|
|
555
658
|
for (const style of styles) {
|
|
556
659
|
if (existsSync4(style)) {
|
|
@@ -628,17 +731,17 @@ ${routes.join(",\n")}
|
|
|
628
731
|
const components = roots.flatMap((root) => {
|
|
629
732
|
if (layer === "top") {
|
|
630
733
|
return [
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
734
|
+
join5(root, "global.vue"),
|
|
735
|
+
join5(root, "global-top.vue"),
|
|
736
|
+
join5(root, "GlobalTop.vue")
|
|
634
737
|
];
|
|
635
738
|
} else {
|
|
636
739
|
return [
|
|
637
|
-
|
|
638
|
-
|
|
740
|
+
join5(root, "global-bottom.vue"),
|
|
741
|
+
join5(root, "GlobalBottom.vue")
|
|
639
742
|
];
|
|
640
743
|
}
|
|
641
|
-
}).filter((i) =>
|
|
744
|
+
}).filter((i) => fs4.existsSync(i));
|
|
642
745
|
const imports = components.map((i, idx) => `import __n${idx} from '${toAtFS(i)}'`).join("\n");
|
|
643
746
|
const render = components.map((i, idx) => `h(__n${idx})`).join(",");
|
|
644
747
|
return `
|
|
@@ -653,8 +756,8 @@ export default {
|
|
|
653
756
|
}
|
|
654
757
|
}
|
|
655
758
|
|
|
656
|
-
// node/plugins/
|
|
657
|
-
import { join as
|
|
759
|
+
// node/plugins/monacoTransform.ts
|
|
760
|
+
import { join as join6 } from "path";
|
|
658
761
|
import { slash as slash3 } from "@antfu/utils";
|
|
659
762
|
import { resolvePackageData } from "vite";
|
|
660
763
|
function createMonacoTypesLoader() {
|
|
@@ -677,7 +780,7 @@ function createMonacoTypesLoader() {
|
|
|
677
780
|
return "";
|
|
678
781
|
return [
|
|
679
782
|
"import * as monaco from 'monaco-editor'",
|
|
680
|
-
`import Type from "${slash3(
|
|
783
|
+
`import Type from "${slash3(join6(info.dir, typePath))}?raw"`,
|
|
681
784
|
...Object.keys(info.data.dependencies || {}).map((i) => `import "/@slidev-monaco-types/${i}"`),
|
|
682
785
|
`monaco.languages.typescript.typescriptDefaults.addExtraLib(\`declare module "${pkg}" { \${Type} }\`)`
|
|
683
786
|
].join("\n");
|
|
@@ -688,10 +791,10 @@ function createMonacoTypesLoader() {
|
|
|
688
791
|
|
|
689
792
|
// node/plugins/setupClient.ts
|
|
690
793
|
import { existsSync as existsSync5 } from "fs";
|
|
691
|
-
import { join as
|
|
692
|
-
import { slash as slash4, uniq as
|
|
794
|
+
import { join as join7, resolve as resolve4 } from "path";
|
|
795
|
+
import { slash as slash4, uniq as uniq5 } from "@antfu/utils";
|
|
693
796
|
function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }) {
|
|
694
|
-
const setupEntry = slash4(
|
|
797
|
+
const setupEntry = slash4(resolve4(clientRoot, "setup"));
|
|
695
798
|
return {
|
|
696
799
|
name: "slidev:setup",
|
|
697
800
|
enforce: "pre",
|
|
@@ -701,10 +804,10 @@ function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }) {
|
|
|
701
804
|
const imports = [];
|
|
702
805
|
const injections = [];
|
|
703
806
|
const asyncInjections = [];
|
|
704
|
-
const setups =
|
|
807
|
+
const setups = uniq5([
|
|
705
808
|
...themeRoots,
|
|
706
809
|
userRoot
|
|
707
|
-
]).map((i) =>
|
|
810
|
+
]).map((i) => join7(i, "setup", name));
|
|
708
811
|
setups.forEach((path, idx) => {
|
|
709
812
|
if (!existsSync5(path))
|
|
710
813
|
return;
|
|
@@ -735,98 +838,6 @@ function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }) {
|
|
|
735
838
|
};
|
|
736
839
|
}
|
|
737
840
|
|
|
738
|
-
// node/plugins/server-ref.ts
|
|
739
|
-
var PREFIX = "/@server-ref/";
|
|
740
|
-
function VitePluginServerRef(options = {}) {
|
|
741
|
-
const {
|
|
742
|
-
dataMap = {},
|
|
743
|
-
debounceMs = 10,
|
|
744
|
-
debug = true
|
|
745
|
-
} = options;
|
|
746
|
-
return {
|
|
747
|
-
name: "vite-plugin-server-ref",
|
|
748
|
-
resolveId(id) {
|
|
749
|
-
return id.startsWith(PREFIX) ? id : null;
|
|
750
|
-
},
|
|
751
|
-
configureServer(server) {
|
|
752
|
-
server.middlewares.use(async (req, res, next) => {
|
|
753
|
-
var _a, _b;
|
|
754
|
-
if (!((_a = req.url) == null ? void 0 : _a.startsWith(PREFIX)) || req.method !== "POST")
|
|
755
|
-
return next();
|
|
756
|
-
const name = req.url.slice(PREFIX.length);
|
|
757
|
-
const { data, timestamp } = await getBodyJson(req);
|
|
758
|
-
const module = server.moduleGraph.getModuleById(PREFIX + name);
|
|
759
|
-
if (module)
|
|
760
|
-
server.moduleGraph.invalidateModule(module);
|
|
761
|
-
dataMap[name] = data;
|
|
762
|
-
server.ws.send({
|
|
763
|
-
type: "custom",
|
|
764
|
-
event: "server-ref",
|
|
765
|
-
data: {
|
|
766
|
-
name,
|
|
767
|
-
data,
|
|
768
|
-
timestamp
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
(_b = options.onChanged) == null ? void 0 : _b.call(options, name, data, timestamp);
|
|
772
|
-
res.write("");
|
|
773
|
-
res.end();
|
|
774
|
-
});
|
|
775
|
-
},
|
|
776
|
-
load(id) {
|
|
777
|
-
var _a;
|
|
778
|
-
if (!id.startsWith(PREFIX))
|
|
779
|
-
return;
|
|
780
|
-
const name = id.slice(PREFIX.length);
|
|
781
|
-
return `
|
|
782
|
-
import { ref, watch } from "vue"
|
|
783
|
-
|
|
784
|
-
const data = ref(${JSON.stringify((_a = dataMap[name]) != null ? _a : null)})
|
|
785
|
-
|
|
786
|
-
if (import.meta.hot) {
|
|
787
|
-
${debug ? `console.log("[server-ref] [${name}] ref", data)` : ""}
|
|
788
|
-
${debug ? `console.log("[server-ref] [${name}] initial", data.value)` : ""}
|
|
789
|
-
|
|
790
|
-
let skipNext = false
|
|
791
|
-
let timer = null
|
|
792
|
-
import.meta.hot.on("server-ref", (payload) =>{
|
|
793
|
-
if (payload.name !== "${name}")
|
|
794
|
-
return
|
|
795
|
-
skipNext = true
|
|
796
|
-
data.value = payload.data
|
|
797
|
-
${debug ? `console.log("[server-ref] [${name}] incoming", payload.data)` : ""}
|
|
798
|
-
})
|
|
799
|
-
watch(data, (v) => {
|
|
800
|
-
if (skipNext) {
|
|
801
|
-
skipNext = false
|
|
802
|
-
return
|
|
803
|
-
}
|
|
804
|
-
if (timer)
|
|
805
|
-
clearTimeout(timer)
|
|
806
|
-
|
|
807
|
-
timer = setTimeout(()=>{
|
|
808
|
-
${debug ? `console.log("[server-ref] [${name}] outgoing", data.value)` : ""}
|
|
809
|
-
fetch('${PREFIX + name}', {
|
|
810
|
-
method: 'POST',
|
|
811
|
-
headers: {
|
|
812
|
-
'Content-Type': 'application/json',
|
|
813
|
-
},
|
|
814
|
-
body: JSON.stringify({
|
|
815
|
-
data: data.value,
|
|
816
|
-
timestamp: Date.now(),
|
|
817
|
-
})
|
|
818
|
-
})
|
|
819
|
-
}, ${debounceMs})
|
|
820
|
-
}, { flush: 'sync', deep: true })
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
export default data
|
|
824
|
-
`;
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
var server_ref_default = VitePluginServerRef;
|
|
829
|
-
|
|
830
841
|
// node/plugins/markdown.ts
|
|
831
842
|
import Markdown2 from "vite-plugin-md";
|
|
832
843
|
import base64 from "js-base64";
|
|
@@ -1244,16 +1255,21 @@ function escapeVueInCode(md2) {
|
|
|
1244
1255
|
return md2.replace(/{{(.*?)}}/g, "{{$1}}");
|
|
1245
1256
|
}
|
|
1246
1257
|
|
|
1247
|
-
// node/plugins/
|
|
1248
|
-
|
|
1249
|
-
|
|
1258
|
+
// node/plugins/patchTransform.ts
|
|
1259
|
+
import { objectEntries } from "@antfu/utils";
|
|
1260
|
+
function createFixPlugins(options) {
|
|
1261
|
+
const define = objectEntries(getDefine(options));
|
|
1250
1262
|
return [
|
|
1251
1263
|
{
|
|
1252
1264
|
name: "slidev:flags",
|
|
1253
1265
|
enforce: "pre",
|
|
1254
1266
|
transform(code, id) {
|
|
1255
|
-
if (id.endsWith(".vue"))
|
|
1256
|
-
|
|
1267
|
+
if (id.endsWith(".vue")) {
|
|
1268
|
+
define.forEach(([from, to]) => {
|
|
1269
|
+
code = code.replace(new RegExp(from, "g"), to);
|
|
1270
|
+
});
|
|
1271
|
+
return code;
|
|
1272
|
+
}
|
|
1257
1273
|
}
|
|
1258
1274
|
}
|
|
1259
1275
|
];
|
|
@@ -1305,12 +1321,13 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
|
|
|
1305
1321
|
}, vueOptions == null ? void 0 : vueOptions.template)
|
|
1306
1322
|
}, vueOptions));
|
|
1307
1323
|
const MarkdownPlugin = await createMarkdownPlugin(options, pluginOptions);
|
|
1324
|
+
const drawingData = await loadDrawings(options);
|
|
1308
1325
|
return [
|
|
1309
1326
|
await createWindiCSSPlugin(options, pluginOptions),
|
|
1310
1327
|
MarkdownPlugin,
|
|
1311
1328
|
VuePlugin,
|
|
1312
1329
|
createSlidesLoader(options, pluginOptions, serverOptions, VuePlugin, MarkdownPlugin),
|
|
1313
|
-
|
|
1330
|
+
Components(__spreadValues({
|
|
1314
1331
|
extensions: ["vue", "md", "ts"],
|
|
1315
1332
|
dirs: [
|
|
1316
1333
|
`${clientRoot}/builtin`,
|
|
@@ -1319,14 +1336,15 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
|
|
|
1319
1336
|
"src/components",
|
|
1320
1337
|
"components"
|
|
1321
1338
|
],
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1339
|
+
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
|
|
1340
|
+
exclude: [],
|
|
1341
|
+
resolvers: [
|
|
1342
|
+
IconsResolver({
|
|
1343
|
+
prefix: ""
|
|
1326
1344
|
})
|
|
1327
1345
|
]
|
|
1328
1346
|
}, componentsOptions)),
|
|
1329
|
-
|
|
1347
|
+
Icons(__spreadValues({}, iconsOptions)),
|
|
1330
1348
|
config.remoteAssets === true || config.remoteAssets === mode ? RemoteAssets(__spreadValues({
|
|
1331
1349
|
rules: [
|
|
1332
1350
|
...DefaultRules,
|
|
@@ -1338,13 +1356,21 @@ async function ViteSlidevPlugin(options, pluginOptions, serverOptions = {}) {
|
|
|
1338
1356
|
resolveMode: (id) => id.endsWith("index.html") ? "relative" : "@fs",
|
|
1339
1357
|
awaitDownload: mode === "build"
|
|
1340
1358
|
}, remoteAssetsOptions)) : null,
|
|
1341
|
-
|
|
1342
|
-
|
|
1359
|
+
ServerRef({
|
|
1360
|
+
debug: process.env.NODE_ENV === "development",
|
|
1361
|
+
state: {
|
|
1343
1362
|
sync: false,
|
|
1344
|
-
|
|
1363
|
+
nav: {
|
|
1345
1364
|
page: 0,
|
|
1346
1365
|
clicks: 0
|
|
1347
|
-
}
|
|
1366
|
+
},
|
|
1367
|
+
drawings: drawingData
|
|
1368
|
+
},
|
|
1369
|
+
onChanged(key, data, patch) {
|
|
1370
|
+
if (!options.data.config.drawings.persist)
|
|
1371
|
+
return;
|
|
1372
|
+
if (key === "drawings")
|
|
1373
|
+
writeDarwings(options, patch != null ? patch : data);
|
|
1348
1374
|
}
|
|
1349
1375
|
}),
|
|
1350
1376
|
createConfigPlugin(options),
|