@slidev/cli 0.29.1 → 0.30.1

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,9 +1,9 @@
1
1
  import {
2
2
  ViteSlidevPlugin
3
- } from "./chunk-UEIFQWPY.mjs";
3
+ } from "./chunk-4AVLCCHB.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();
@@ -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";
@@ -593,6 +595,15 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
593
595
  const pageNo = parseInt(no) - 1;
594
596
  return transformMarkdown(code, pageNo, data);
595
597
  }
598
+ },
599
+ {
600
+ name: "slidev:context-transform:pre",
601
+ enforce: "pre",
602
+ async transform(code, id) {
603
+ if (!id.endsWith(".vue"))
604
+ return;
605
+ return transformVue(code);
606
+ }
596
607
  }
597
608
  ];
598
609
  function updateServerWatcher() {
@@ -610,8 +621,11 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRoot, roo
610
621
  throw new Error(`Unknown layout "${layoutName}"`);
611
622
  delete frontmatter.title;
612
623
  const imports = [
624
+ 'import { inject as vueInject } from "vue"',
613
625
  `import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
614
- `const frontmatter = ${JSON.stringify(frontmatter)}`
626
+ 'import { injectionSlidevContext } from "@slidev/client/constants"',
627
+ `const frontmatter = ${JSON.stringify(frontmatter)}`,
628
+ "const $slidev = vueInject(injectionSlidevContext)"
615
629
  ];
616
630
  code = code.replace(/(<script setup.*>)/g, `$1
617
631
  ${imports.join("\n")}
@@ -628,6 +642,59 @@ ${body}
628
642
  ${code.slice(injectB)}`;
629
643
  return code;
630
644
  }
645
+ function transformVue(code) {
646
+ if (code.includes("injectionSlidevContext"))
647
+ return code;
648
+ const imports = [
649
+ 'import { inject as vueInject } from "vue"',
650
+ 'import { injectionSlidevContext } from "@slidev/client/constants"',
651
+ "const $slidev = vueInject(injectionSlidevContext)"
652
+ ];
653
+ const matchScript = code.match(/<script((?!setup).)*(setup)?.*>/);
654
+ if (matchScript && matchScript[2]) {
655
+ return code.replace(/(<script.*>)/g, `$1
656
+ ${imports.join("\n")}
657
+ `);
658
+ } else if (matchScript && !matchScript[2]) {
659
+ const matchExport = code.match(/export\s+default\s+[^{]*{/);
660
+ if (matchExport) {
661
+ const exportIndex = (matchExport.index || 0) + matchExport[0].length;
662
+ let component = code.slice(exportIndex);
663
+ component = component.slice(0, component.indexOf("<\/script>"));
664
+ if (component.match(/setup\s*\(/)) {
665
+ const scriptIndex = (matchScript.index || 0) + matchScript[0].length;
666
+ const provideImport = '\nimport { injectionSlidevContext } from "@slidev/client/constants"\n';
667
+ code = `${code.slice(0, scriptIndex)}${provideImport}${code.slice(scriptIndex)}`;
668
+ let injectIndex = exportIndex + provideImport.length;
669
+ let injectObject = "$slidev: { from: injectionSlidevContext },";
670
+ const matchInject = component.match(/.*inject\s*:\s*([\[{])/);
671
+ if (matchInject) {
672
+ injectIndex += (matchInject.index || 0) + matchInject[0].length;
673
+ if (matchInject[1] === "[") {
674
+ let injects = component.slice((matchInject.index || 0) + matchInject[0].length);
675
+ const injectEndIndex = injects.indexOf("]");
676
+ injects = injects.slice(0, injectEndIndex);
677
+ injectObject += injects.split(",").map((inject) => `${inject}: {from: ${inject}}`).join(",");
678
+ return `${code.slice(0, injectIndex - 1)}{
679
+ ${injectObject}
680
+ }${code.slice(injectIndex + injectEndIndex + 1)}`;
681
+ } else {
682
+ return `${code.slice(0, injectIndex)}
683
+ ${injectObject}
684
+ ${code.slice(injectIndex)}`;
685
+ }
686
+ }
687
+ return `${code.slice(0, injectIndex)}
688
+ inject: { ${injectObject} },
689
+ ${code.slice(injectIndex)}`;
690
+ }
691
+ }
692
+ }
693
+ return `<script setup>
694
+ ${imports.join("\n")}
695
+ <\/script>
696
+ ${code}`;
697
+ }
631
698
  async function getLayouts() {
632
699
  const now = Date.now();
633
700
  if (now - _layouts_cache_time < 2e3)
@@ -1159,7 +1226,7 @@ async function createMarkdownPlugin({ data: { config }, roots, mode, entry }, {
1159
1226
  const setups = [];
1160
1227
  const entryPath = slash5(entry);
1161
1228
  if (config.highlighter === "shiki") {
1162
- const { getHighlighter } = await Promise.resolve().then(() => __toModule(__require("shiki")));
1229
+ const { getHighlighter } = await Promise.resolve().then(() => __toESM(__require("shiki")));
1163
1230
  const shikiOptions = await loadSetups(roots, "shiki.ts", Shiki, DEFAULT_SHIKI_OPTIONS, false);
1164
1231
  const { langs, themes } = resolveShikiOptions(shikiOptions);
1165
1232
  shikiOptions.highlighter = await getHighlighter({ themes, langs });
@@ -1278,8 +1345,7 @@ function transformPageCSS(md2, id) {
1278
1345
  if (!page)
1279
1346
  return md2;
1280
1347
  const { isInsideCodeblocks } = getCodeBlocks(md2);
1281
- const result = md2.replace(/(\n<style[^>]*?>)([\s\S]+?)(<\/style>)/g, (full, start, css, end) => {
1282
- const index = md2.indexOf(full);
1348
+ const result = md2.replace(/(\n<style[^>]*?>)([\s\S]+?)(<\/style>)/g, (full, start, css, end, index) => {
1283
1349
  if (index < 0 || isInsideCodeblocks(index))
1284
1350
  return full;
1285
1351
  if (!start.includes("scoped"))