@slidev/cli 0.29.2 → 0.30.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.
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkNPCPO6ETjs = require('./chunk-NPCPO6ET.js');
3
+ var _chunkRSHUQSN4js = require('./chunk-RSHUQSN4.js');
4
4
 
5
5
 
6
- var _chunk7QXPSYEZjs = require('./chunk-7QXPSYEZ.js');
6
+ var _chunkIXNT7VMKjs = require('./chunk-IXNT7VMK.js');
7
7
 
8
8
  // node/server.ts
9
- _chunk7QXPSYEZjs.init_cjs_shims.call(void 0, );
9
+ _chunkIXNT7VMKjs.init_cjs_shims.call(void 0, );
10
10
  var _path = require('path');
11
11
  var _vite = require('vite');
12
12
  async function createServer(options, viteConfig = {}, serverOptions = {}) {
@@ -20,7 +20,7 @@ async function createServer(options, viteConfig = {}, serverOptions = {}) {
20
20
  ]
21
21
  },
22
22
  plugins: [
23
- await _chunkNPCPO6ETjs.ViteSlidevPlugin.call(void 0, options, pluginOptions, serverOptions)
23
+ await _chunkRSHUQSN4js.ViteSlidevPlugin.call(void 0, options, pluginOptions, serverOptions)
24
24
  ]
25
25
  }));
26
26
  return server;
@@ -21,7 +21,6 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
24
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
26
25
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
27
26
  }) : x)(function(x) {
@@ -30,31 +29,31 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
30
29
  throw new Error('Dynamic require of "' + x + '" is not supported');
31
30
  });
32
31
  var __esm = (fn, res) => function __init() {
33
- return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
32
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
34
33
  };
35
34
  var __commonJS = (cb, mod) => function __require2() {
36
- return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
35
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
37
36
  };
38
37
  var __export = (target, all) => {
39
- __markAsModule(target);
40
38
  for (var name in all)
41
39
  __defProp(target, name, { get: all[name], enumerable: true });
42
40
  };
43
- var __reExport = (target, module, desc) => {
44
- if (module && typeof module === "object" || typeof module === "function") {
45
- for (let key of __getOwnPropNames(module))
46
- if (!__hasOwnProp.call(target, key) && key !== "default")
47
- __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
48
46
  }
49
- return target;
50
- };
51
- var __toModule = (module) => {
52
- return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
47
+ return to;
53
48
  };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
54
50
 
55
- // ../../node_modules/.pnpm/tsup@5.11.13_typescript@4.6.2/node_modules/tsup/assets/cjs_shims.js
51
+ // ../../node_modules/.pnpm/tsup@5.12.5_typescript@4.6.3/node_modules/tsup/assets/cjs_shims.js
52
+ var getImportMetaUrl, importMetaUrl;
56
53
  var init_cjs_shims = __esm({
57
- "../../node_modules/.pnpm/tsup@5.11.13_typescript@4.6.2/node_modules/tsup/assets/cjs_shims.js"() {
54
+ "../../node_modules/.pnpm/tsup@5.12.5_typescript@4.6.3/node_modules/tsup/assets/cjs_shims.js"() {
55
+ getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
56
+ importMetaUrl = exports.importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
58
57
  }
59
58
  });
60
59
 
@@ -129,4 +128,5 @@ function generateGoogleFontsUrl(options) {
129
128
 
130
129
 
131
130
 
132
- exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__require = __require; exports.__commonJS = __commonJS; exports.__export = __export; exports.__toModule = __toModule; exports.init_cjs_shims = init_cjs_shims; exports.toAtFS = toAtFS; exports.resolveImportPath = resolveImportPath; exports.resolveGlobalImportPath = resolveGlobalImportPath; exports.stringifyMarkdownTokens = stringifyMarkdownTokens; exports.generateGoogleFontsUrl = generateGoogleFontsUrl;
131
+
132
+ exports.__spreadValues = __spreadValues; exports.__spreadProps = __spreadProps; exports.__require = __require; exports.__commonJS = __commonJS; exports.__export = __export; exports.__toESM = __toESM; exports.importMetaUrl = importMetaUrl; exports.init_cjs_shims = init_cjs_shims; exports.toAtFS = toAtFS; exports.resolveImportPath = resolveImportPath; exports.resolveGlobalImportPath = resolveGlobalImportPath; exports.stringifyMarkdownTokens = stringifyMarkdownTokens; exports.generateGoogleFontsUrl = generateGoogleFontsUrl;
@@ -4,14 +4,14 @@ import {
4
4
  __require,
5
5
  __spreadProps,
6
6
  __spreadValues,
7
- __toModule,
7
+ __toESM,
8
8
  generateGoogleFontsUrl,
9
9
  init_esm_shims,
10
10
  resolveGlobalImportPath,
11
11
  resolveImportPath,
12
12
  stringifyMarkdownTokens,
13
13
  toAtFS
14
- } from "./chunk-VYBQLH2X.mjs";
14
+ } from "./chunk-XMETW2MS.mjs";
15
15
 
16
16
  // ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
17
17
  var require_fast_deep_equal = __commonJS({
@@ -240,27 +240,29 @@ import { uniq as uniq3 } from "@antfu/utils";
240
240
 
241
241
  // ../client/package.json
242
242
  var dependencies = {
243
- "@antfu/utils": "^0.5.0",
243
+ "@antfu/utils": "^0.5.1",
244
244
  "@slidev/parser": "workspace:*",
245
245
  "@slidev/types": "workspace:*",
246
- "@vueuse/core": "^8.1.2",
246
+ "@vueuse/core": "^8.2.5",
247
247
  "@vueuse/head": "^0.7.5",
248
- "@vueuse/motion": "^2.0.0-beta.12",
248
+ "@vueuse/motion": "^2.0.0-beta.18",
249
249
  codemirror: "^5.65.2",
250
+ defu: "^6.0.0",
250
251
  drauu: "^0.3.0",
251
252
  "file-saver": "^2.0.5",
252
253
  "js-base64": "^3.7.2",
253
254
  "js-yaml": "^4.1.0",
254
255
  katex: "^0.15.3",
255
- mermaid: "^8.14.0",
256
+ mermaid: "^9.0.0",
256
257
  "monaco-editor": "^0.33.0",
257
- nanoid: "^3.3.1",
258
- prettier: "^2.6.0",
258
+ nanoid: "^3.3.2",
259
+ prettier: "^2.6.2",
259
260
  recordrtc: "^5.6.2",
260
261
  resolve: "^1.22.0",
261
- "vite-plugin-windicss": "^1.8.3",
262
- vue: "^3.2.31",
262
+ "vite-plugin-windicss": "^1.8.4",
263
+ vue: "^3.2.32",
263
264
  "vue-router": "^4.0.14",
265
+ "vue-starport": "^0.2.4",
264
266
  windicss: "^3.5.1"
265
267
  };
266
268
 
@@ -392,7 +394,7 @@ function getDefine(options) {
392
394
 
393
395
  // node/plugins/loaders.ts
394
396
  init_esm_shims();
395
- var import_fast_deep_equal = __toModule(require_fast_deep_equal());
397
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
396
398
  import { basename as basename2, join as join5 } from "path";
397
399
  import { isString, notNullish, objectMap, range, slash as slash2, uniq as uniq4 } from "@antfu/utils";
398
400
  import fg2 from "fast-glob";
@@ -470,7 +472,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
470
472
  });
471
473
  },
472
474
  async handleHotUpdate(ctx) {
473
- var _a;
475
+ var _a, _b, _c;
474
476
  if (!data.entries.some((i) => slash2(i) === ctx.file))
475
477
  return;
476
478
  const newData = await parser.load(entry, data.themeMeta);
@@ -494,7 +496,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
494
496
  for (let i = 0; i < length; i++) {
495
497
  const a = data.slides[i];
496
498
  const b = newData.slides[i];
497
- if ((a == null ? void 0 : a.content.trim()) === (b == null ? void 0 : b.content.trim()) && (a == null ? void 0 : a.note) === (b == null ? void 0 : b.note) && (0, import_fast_deep_equal.default)(a.frontmatter, b.frontmatter))
499
+ if ((a == null ? void 0 : a.content.trim()) === (b == null ? void 0 : b.content.trim()) && ((_a = a == null ? void 0 : a.title) == null ? void 0 : _a.trim()) === ((_b = b == null ? void 0 : b.title) == null ? void 0 : _b.trim()) && (a == null ? void 0 : a.note) === (b == null ? void 0 : b.note) && (0, import_fast_deep_equal.default)(a.frontmatter, b.frontmatter))
498
500
  continue;
499
501
  ctx.server.ws.send({
500
502
  type: "custom",
@@ -506,13 +508,15 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
506
508
  });
507
509
  hmrPages.add(i);
508
510
  }
509
- (_a = serverOptions.onDataReload) == null ? void 0 : _a.call(serverOptions, newData, data);
511
+ (_c = serverOptions.onDataReload) == null ? void 0 : _c.call(serverOptions, newData, data);
510
512
  Object.assign(data, newData);
513
+ if (hmrPages.size > 0)
514
+ moduleIds.add("/@slidev/titles.md");
511
515
  const vueModules = (await Promise.all(Array.from(hmrPages).map(async (i) => {
512
516
  var _a2;
513
517
  const file = `${slidePrefix}${i + 1}.md`;
514
518
  try {
515
- const md2 = await transformMarkdown(MarkdownPlugin.transform((_a2 = newData.slides[i]) == null ? void 0 : _a2.content, file), i, newData);
519
+ const md2 = await transformMarkdown(await MarkdownPlugin.transform((_a2 = newData.slides[i]) == null ? void 0 : _a2.content, file), i, newData);
516
520
  return await VuePlugin.handleHotUpdate(__spreadProps(__spreadValues({}, ctx), {
517
521
  modules: Array.from(ctx.server.moduleGraph.getModulesByFile(file) || []),
518
522
  file,
@@ -557,6 +561,14 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
557
561
  return generateGlobalComponents("bottom");
558
562
  if (id === "/@slidev/custom-nav-controls")
559
563
  return generateCustomNavControls();
564
+ if (id === "/@slidev/titles.md") {
565
+ return {
566
+ code: data.slides.map(({ title }, i) => {
567
+ return `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">${title}</template>`;
568
+ }).join(""),
569
+ map: {}
570
+ };
571
+ }
560
572
  if (id.startsWith(slidePrefix)) {
561
573
  const remaning = id.slice(slidePrefix.length);
562
574
  const match = remaning.match(regexIdQuery);
@@ -593,6 +605,24 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
593
605
  const pageNo = parseInt(no) - 1;
594
606
  return transformMarkdown(code, pageNo, data);
595
607
  }
608
+ },
609
+ {
610
+ name: "slidev:context-transform:pre",
611
+ enforce: "pre",
612
+ async transform(code, id) {
613
+ if (!id.endsWith(".vue"))
614
+ return;
615
+ return transformVue(code);
616
+ }
617
+ },
618
+ {
619
+ name: "slidev:title-transform:pre",
620
+ enforce: "pre",
621
+ transform(code, id) {
622
+ if (id !== "/@slidev/titles.md")
623
+ return;
624
+ return transformTitles(code);
625
+ }
596
626
  }
597
627
  ];
598
628
  function updateServerWatcher() {
@@ -610,8 +640,11 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
610
640
  throw new Error(`Unknown layout "${layoutName}"`);
611
641
  delete frontmatter.title;
612
642
  const imports = [
643
+ 'import { inject as vueInject } from "vue"',
613
644
  `import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
614
- `const frontmatter = ${JSON.stringify(frontmatter)}`
645
+ 'import { injectionSlidevContext } from "@slidev/client/constants"',
646
+ `const frontmatter = ${JSON.stringify(frontmatter)}`,
647
+ "const $slidev = vueInject(injectionSlidevContext)"
615
648
  ];
616
649
  code = code.replace(/(<script setup.*>)/g, `$1
617
650
  ${imports.join("\n")}
@@ -628,6 +661,63 @@ ${body}
628
661
  ${code.slice(injectB)}`;
629
662
  return code;
630
663
  }
664
+ function transformVue(code) {
665
+ if (code.includes("injectionSlidevContext"))
666
+ return code;
667
+ const imports = [
668
+ 'import { inject as vueInject } from "vue"',
669
+ 'import { injectionSlidevContext } from "@slidev/client/constants"',
670
+ "const $slidev = vueInject(injectionSlidevContext)"
671
+ ];
672
+ const matchScript = code.match(/<script((?!setup).)*(setup)?.*>/);
673
+ if (matchScript && matchScript[2]) {
674
+ return code.replace(/(<script.*>)/g, `$1
675
+ ${imports.join("\n")}
676
+ `);
677
+ } else if (matchScript && !matchScript[2]) {
678
+ const matchExport = code.match(/export\s+default\s+[^{]*{/);
679
+ if (matchExport) {
680
+ const exportIndex = (matchExport.index || 0) + matchExport[0].length;
681
+ let component = code.slice(exportIndex);
682
+ component = component.slice(0, component.indexOf("<\/script>"));
683
+ if (component.match(/setup\s*\(/)) {
684
+ const scriptIndex = (matchScript.index || 0) + matchScript[0].length;
685
+ const provideImport = '\nimport { injectionSlidevContext } from "@slidev/client/constants"\n';
686
+ code = `${code.slice(0, scriptIndex)}${provideImport}${code.slice(scriptIndex)}`;
687
+ let injectIndex = exportIndex + provideImport.length;
688
+ let injectObject = "$slidev: { from: injectionSlidevContext },";
689
+ const matchInject = component.match(/.*inject\s*:\s*([\[{])/);
690
+ if (matchInject) {
691
+ injectIndex += (matchInject.index || 0) + matchInject[0].length;
692
+ if (matchInject[1] === "[") {
693
+ let injects = component.slice((matchInject.index || 0) + matchInject[0].length);
694
+ const injectEndIndex = injects.indexOf("]");
695
+ injects = injects.slice(0, injectEndIndex);
696
+ injectObject += injects.split(",").map((inject) => `${inject}: {from: ${inject}}`).join(",");
697
+ return `${code.slice(0, injectIndex - 1)}{
698
+ ${injectObject}
699
+ }${code.slice(injectIndex + injectEndIndex + 1)}`;
700
+ } else {
701
+ return `${code.slice(0, injectIndex)}
702
+ ${injectObject}
703
+ ${code.slice(injectIndex)}`;
704
+ }
705
+ }
706
+ return `${code.slice(0, injectIndex)}
707
+ inject: { ${injectObject} },
708
+ ${code.slice(injectIndex)}`;
709
+ }
710
+ }
711
+ }
712
+ return `<script setup>
713
+ ${imports.join("\n")}
714
+ <\/script>
715
+ ${code}`;
716
+ }
717
+ function transformTitles(code) {
718
+ return code.replace(/<template>\s*<div>\s*<p>/, "<template>").replace(/<\/p>\s*<\/div>\s*<\/template>/, "</template>").replace(/<script\ssetup>/, `<script setup lang="ts">
719
+ defineProps<{ no: number | string }>()`);
720
+ }
631
721
  async function getLayouts() {
632
722
  const now = Date.now();
633
723
  if (now - _layouts_cache_time < 2e3)
@@ -1159,7 +1249,7 @@ async function createMarkdownPlugin({ data: { config }, roots, mode, entry }, {
1159
1249
  const setups = [];
1160
1250
  const entryPath = slash5(entry);
1161
1251
  if (config.highlighter === "shiki") {
1162
- const { getHighlighter } = await Promise.resolve().then(() => __toModule(__require("shiki")));
1252
+ const { getHighlighter } = await Promise.resolve().then(() => __toESM(__require("shiki")));
1163
1253
  const shikiOptions = await loadSetups(roots, "shiki.ts", Shiki, DEFAULT_SHIKI_OPTIONS, false);
1164
1254
  const { langs, themes } = resolveShikiOptions(shikiOptions);
1165
1255
  shikiOptions.highlighter = await getHighlighter({ themes, langs });
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  ViteSlidevPlugin
3
- } from "./chunk-NQIXBLV4.mjs";
3
+ } from "./chunk-MBZTOLHN.mjs";
4
4
  import {
5
5
  init_esm_shims
6
- } from "./chunk-VYBQLH2X.mjs";
6
+ } from "./chunk-XMETW2MS.mjs";
7
7
 
8
8
  // node/server.ts
9
9
  init_esm_shims();