@slidev/cli 0.48.0-beta.11 → 0.48.0-beta.13

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.
@@ -2,7 +2,7 @@ import {
2
2
  ViteSlidevPlugin,
3
3
  getIndexHtml,
4
4
  mergeViteConfigs
5
- } from "./chunk-7HWAUX7C.mjs";
5
+ } from "./chunk-MJETSRBI.mjs";
6
6
  import "./chunk-O6TYYGU6.mjs";
7
7
  import {
8
8
  findPkgRoot
@@ -4,7 +4,7 @@ import {
4
4
  mergeViteConfigs,
5
5
  require_semver,
6
6
  version
7
- } from "./chunk-7HWAUX7C.mjs";
7
+ } from "./chunk-MJETSRBI.mjs";
8
8
  import {
9
9
  createResolver,
10
10
  getRoots,
@@ -2496,7 +2496,7 @@ var require_semver2 = __commonJS({
2496
2496
  });
2497
2497
 
2498
2498
  // package.json
2499
- var version = "0.48.0-beta.11";
2499
+ var version = "0.48.0-beta.13";
2500
2500
 
2501
2501
  // node/common.ts
2502
2502
  import { existsSync, promises as fs } from "node:fs";
@@ -2757,10 +2757,20 @@ md.use(mila, {
2757
2757
  rel: "noopener"
2758
2758
  }
2759
2759
  });
2760
- function renderNoteHTML(data) {
2760
+ function renderNote(text = "") {
2761
+ let clickCount = 0;
2762
+ const html = md.render(
2763
+ text.replace(/\[click(?::(\d+))?\]/gi, (_, count = 1) => {
2764
+ clickCount += Number(count);
2765
+ return `<span class="slidev-note-click-mark" data-clicks="${clickCount}"></span>`;
2766
+ })
2767
+ );
2768
+ return html;
2769
+ }
2770
+ function withRenderedNote(data) {
2761
2771
  return {
2762
2772
  ...data,
2763
- noteHTML: md.render(data?.note || "")
2773
+ noteHTML: renderNote(data?.note)
2764
2774
  };
2765
2775
  }
2766
2776
  function createSlidesLoader({ data, clientRoot, roots, remote, mode }, pluginOptions, serverOptions) {
@@ -2782,7 +2792,7 @@ function createSlidesLoader({ data, clientRoot, roots, remote, mode }, pluginOpt
2782
2792
  const [, no, type] = match;
2783
2793
  const idx = Number.parseInt(no);
2784
2794
  if (type === "json" && req.method === "GET") {
2785
- res.write(JSON.stringify(renderNoteHTML(data.slides[idx])));
2795
+ res.write(JSON.stringify(withRenderedNote(data.slides[idx])));
2786
2796
  return res.end();
2787
2797
  }
2788
2798
  if (type === "json" && req.method === "POST") {
@@ -2794,7 +2804,7 @@ function createSlidesLoader({ data, clientRoot, roots, remote, mode }, pluginOpt
2794
2804
  parser.prettifySlide(slide.source);
2795
2805
  await parser.save(data.markdownFiles[slide.source.filepath]);
2796
2806
  res.statusCode = 200;
2797
- res.write(JSON.stringify(renderNoteHTML(slide)));
2807
+ res.write(JSON.stringify(withRenderedNote(slide)));
2798
2808
  return res.end();
2799
2809
  }
2800
2810
  next();
@@ -2842,7 +2852,7 @@ function createSlidesLoader({ data, clientRoot, roots, remote, mode }, pluginOpt
2842
2852
  data: {
2843
2853
  id: i,
2844
2854
  note: b.note || "",
2845
- noteHTML: md.render(b.note || "")
2855
+ noteHTML: renderNote(b.note || "")
2846
2856
  }
2847
2857
  });
2848
2858
  }
@@ -2853,7 +2863,7 @@ function createSlidesLoader({ data, clientRoot, roots, remote, mode }, pluginOpt
2853
2863
  event: "slidev-update",
2854
2864
  data: {
2855
2865
  id: i,
2856
- data: renderNoteHTML(newData.slides[i])
2866
+ data: withRenderedNote(newData.slides[i])
2857
2867
  }
2858
2868
  });
2859
2869
  hmrPages.add(i);
@@ -2921,7 +2931,7 @@ ${title}
2921
2931
  };
2922
2932
  } else if (type === "frontmatter") {
2923
2933
  const slideBase = {
2924
- ...renderNoteHTML(slide),
2934
+ ...withRenderedNote(slide),
2925
2935
  frontmatter: void 0,
2926
2936
  source: void 0,
2927
2937
  // remove raw content in build, optimize the bundle size
@@ -3438,6 +3448,7 @@ import fs6 from "node:fs/promises";
3438
3448
  import Markdown2 from "unplugin-vue-markdown/vite";
3439
3449
  import * as base64 from "js-base64";
3440
3450
  import { slash as slash3 } from "@antfu/utils";
3451
+ import { hash as getHash } from "ohash";
3441
3452
  import mila2 from "markdown-it-link-attributes";
3442
3453
  import mif from "markdown-it-footnote";
3443
3454
 
@@ -3572,6 +3583,7 @@ import { Optional } from "@mrdrogdrog/optional";
3572
3583
  // node/plugins/markdown.ts
3573
3584
  import { encode as encode2 } from "plantuml-encoder";
3574
3585
  import Mdc from "markdown-it-mdc";
3586
+ import { codeToKeyedTokens, createMagicMoveMachine } from "shiki-magic-move/core";
3575
3587
 
3576
3588
  // node/plugins/markdown-it-katex.ts
3577
3589
  import katex from "katex";
@@ -3912,36 +3924,53 @@ ${content}
3912
3924
  }
3913
3925
 
3914
3926
  // node/plugins/markdown.ts
3927
+ var shiki;
3928
+ var shikiOptions;
3915
3929
  async function createMarkdownPlugin(options, { markdown: mdOptions }) {
3916
3930
  const { data: { config }, roots, mode, entry, clientRoot } = options;
3917
3931
  const setups = [];
3918
3932
  const entryPath = slash3(entry);
3919
3933
  if (config.highlighter === "shiki") {
3920
- const MarkdownItShiki = await import("@shikijs/markdown-it").then((r) => r.default);
3921
- const { transformerTwoslash } = await import("@shikijs/vitepress-twoslash");
3922
- const options2 = await loadShikiSetups(clientRoot, roots);
3923
- const plugin = await MarkdownItShiki({
3934
+ const [
3935
+ options2,
3936
+ { getHighlighter, bundledLanguages },
3937
+ markdownItShiki,
3938
+ transformerTwoslash
3939
+ ] = await Promise.all([
3940
+ loadShikiSetups(clientRoot, roots),
3941
+ import("shiki").then(({ getHighlighter: getHighlighter2, bundledLanguages: bundledLanguages2 }) => ({ bundledLanguages: bundledLanguages2, getHighlighter: getHighlighter2 })),
3942
+ import("@shikijs/markdown-it/core").then(({ fromHighlighter }) => fromHighlighter),
3943
+ import("@shikijs/vitepress-twoslash").then(({ transformerTwoslash: transformerTwoslash2 }) => transformerTwoslash2)
3944
+ ]);
3945
+ shikiOptions = options2;
3946
+ shiki = await getHighlighter({
3924
3947
  ...options2,
3925
- transformers: [
3926
- ...options2.transformers || [],
3927
- transformerTwoslash({
3928
- explicitTrigger: true,
3929
- twoslashOptions: {
3930
- handbookOptions: {
3931
- noErrorValidation: true
3932
- }
3933
- }
3934
- }),
3935
- {
3936
- pre(pre) {
3937
- this.addClassToHast(pre, "slidev-code");
3938
- delete pre.properties.tabindex;
3939
- },
3940
- postprocess(code) {
3941
- return escapeVueInCode(code);
3948
+ langs: options2.langs ?? Object.keys(bundledLanguages),
3949
+ themes: "themes" in options2 ? Object.values(options2.themes) : [options2.theme]
3950
+ });
3951
+ const transformers = [
3952
+ ...options2.transformers || [],
3953
+ transformerTwoslash({
3954
+ explicitTrigger: true,
3955
+ twoslashOptions: {
3956
+ handbookOptions: {
3957
+ noErrorValidation: true
3942
3958
  }
3943
3959
  }
3944
- ]
3960
+ }),
3961
+ {
3962
+ pre(pre) {
3963
+ this.addClassToHast(pre, "slidev-code");
3964
+ delete pre.properties.tabindex;
3965
+ },
3966
+ postprocess(code) {
3967
+ return escapeVueInCode(code);
3968
+ }
3969
+ }
3970
+ ];
3971
+ const plugin = markdownItShiki(shiki, {
3972
+ ...options2,
3973
+ transformers
3945
3974
  });
3946
3975
  setups.push((md2) => md2.use(plugin));
3947
3976
  } else {
@@ -3982,6 +4011,8 @@ async function createMarkdownPlugin(options, { markdown: mdOptions }) {
3982
4011
  if (id === entryPath)
3983
4012
  return "";
3984
4013
  const monaco = config.monaco === true || config.monaco === mode ? transformMarkdownMonaco : truncateMancoMark;
4014
+ if (config.highlighter === "shiki")
4015
+ code = transformMagicMove(code, shiki, shikiOptions);
3985
4016
  code = transformSlotSugar(code);
3986
4017
  code = transformSnippet(code, options, id);
3987
4018
  code = transformMermaid(code);
@@ -4046,12 +4077,50 @@ function transformSlotSugar(md2) {
4046
4077
  lines[lines.length - 1] += "\n\n</template>";
4047
4078
  return lines.join("\n");
4048
4079
  }
4080
+ var reMagicMoveBlock = /^````(?:md|markdown) magic-move(?:[ ]*?({.*?})?([^\n]*?))?\n([\s\S]+?)^````$/mg;
4081
+ var reCodeBlock = /^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```$/mg;
4082
+ function transformMagicMove(md2, shiki2, shikiOptions2) {
4083
+ const scripts = [];
4084
+ let count = 0;
4085
+ md2 = md2.replace(
4086
+ reMagicMoveBlock,
4087
+ (full, _options = "", _attrs = "", body) => {
4088
+ if (!shiki2 || !shikiOptions2)
4089
+ throw new Error("Shiki is required for Magic Move. You may need to set `highlighter: shiki` in your Slidev config.");
4090
+ const matches = Array.from(body.matchAll(reCodeBlock));
4091
+ if (!matches.length)
4092
+ throw new Error("Magic Move block must contain at least one code block");
4093
+ const langs = new Set(matches.map((i) => i[1]));
4094
+ if (langs.size > 1)
4095
+ throw new Error(`Magic Move block must contain code blocks with the same language, got ${Array.from(langs).join(", ")}`);
4096
+ const lang = Array.from(langs)[0];
4097
+ const magicMove = createMagicMoveMachine(
4098
+ (code) => codeToKeyedTokens(shiki2, code, {
4099
+ ...shikiOptions2,
4100
+ lang
4101
+ })
4102
+ );
4103
+ const steps = matches.map((i) => magicMove.commit((i[5] || "").trimEnd()));
4104
+ const id = `__magicMoveSteps_${getHash(body)}_${count++}`;
4105
+ scripts.push(`const ${id} = Object.freeze(${JSON.stringify(steps)})`);
4106
+ return `<ShikiMagicMove :steps='${id}' />`;
4107
+ }
4108
+ );
4109
+ if (scripts.length)
4110
+ md2 = `<script setup>
4111
+ ${scripts.join("\n")}</script>
4112
+
4113
+ ${md2}`;
4114
+ return md2;
4115
+ }
4049
4116
  function transformHighlighter(md2) {
4050
- return md2.replace(/^```(\w+?)(?:\s*{([\d\w*,\|-]+)}\s*?({.*?})?(.*?))?\n([\s\S]+?)^```/mg, (full, lang = "", rangeStr = "", options = "", attrs = "", code) => {
4051
- const ranges = rangeStr.split(/\|/g).map((i) => i.trim());
4052
- code = code.trimEnd();
4053
- options = options.trim() || "{}";
4054
- return `
4117
+ return md2.replace(
4118
+ reCodeBlock,
4119
+ (full, lang = "", rangeStr = "", options = "", attrs = "", code) => {
4120
+ const ranges = rangeStr.split(/\|/g).map((i) => i.trim());
4121
+ code = code.trimEnd();
4122
+ options = options.trim() || "{}";
4123
+ return `
4055
4124
  <CodeBlockWrapper v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>
4056
4125
 
4057
4126
  \`\`\`${lang}${attrs}
@@ -4059,7 +4128,8 @@ ${code}
4059
4128
  \`\`\`
4060
4129
 
4061
4130
  </CodeBlockWrapper>`;
4062
- });
4131
+ }
4132
+ );
4063
4133
  }
4064
4134
  function getCodeBlocks(md2) {
4065
4135
  const codeblocks = Array.from(md2.matchAll(/^```[\s\S]*?^```/mg)).map((m) => {
package/dist/cli.mjs CHANGED
@@ -5,10 +5,10 @@ import {
5
5
  resolveAddons,
6
6
  resolveOptions,
7
7
  resolveTheme
8
- } from "./chunk-DFSBG7Q2.mjs";
8
+ } from "./chunk-DGBTBO7O.mjs";
9
9
  import {
10
10
  version
11
- } from "./chunk-7HWAUX7C.mjs";
11
+ } from "./chunk-MJETSRBI.mjs";
12
12
  import {
13
13
  loadSetups
14
14
  } from "./chunk-O6TYYGU6.mjs";
@@ -277,7 +277,7 @@ cli.command(
277
277
  }).strict().help(),
278
278
  async (args) => {
279
279
  const { entry, theme, watch, base, download, out, inspect } = args;
280
- const { build } = await import("./build-DTVJA6KF.mjs");
280
+ const { build } = await import("./build-WAYUJVTS.mjs");
281
281
  for (const entryFile of entry) {
282
282
  const options = await resolveOptions({ entry: entryFile, theme, inspect }, "build");
283
283
  if (download && !options.data.config.download)
@@ -482,13 +482,15 @@ function printInfo(options, port, remote, tunnelUrl, publicIp) {
482
482
  const query = remote ? `?password=${remote}` : "";
483
483
  const presenterPath = `${options.data.config.routerMode === "hash" ? "/#/" : "/"}presenter/${query}`;
484
484
  const entryPath = `${options.data.config.routerMode === "hash" ? "/#/" : "/"}entry${query}/`;
485
+ const overviewPath = `${options.data.config.routerMode === "hash" ? "/#/" : "/"}overview${query}/`;
485
486
  console.log();
486
487
  console.log(`${dim(" public slide show ")} > ${cyan(`http://localhost:${bold(port)}/`)}`);
487
488
  if (query)
488
489
  console.log(`${dim(" private slide show ")} > ${cyan(`http://localhost:${bold(port)}/${query}`)}`);
489
490
  console.log(`${dim(" presenter mode ")} > ${blue(`http://localhost:${bold(port)}${presenterPath}`)}`);
491
+ console.log(`${dim(" slides overview ")} > ${blue(`http://localhost:${bold(port)}${overviewPath}`)}`);
490
492
  if (options.inspect)
491
- console.log(`${dim(" inspector")} > ${yellow(`http://localhost:${bold(port)}/__inspect/`)}`);
493
+ console.log(`${dim(" vite inspector")} > ${yellow(`http://localhost:${bold(port)}/__inspect/`)}`);
492
494
  let lastRemoteUrl = "";
493
495
  if (remote !== void 0) {
494
496
  Object.values(os.networkInterfaces()).forEach((v) => (v || []).filter((details) => String(details.family).slice(-1) === "4" && !details.address.includes("127.0.0.1")).forEach(({ address }) => {
package/dist/index.mjs CHANGED
@@ -2,10 +2,10 @@ import {
2
2
  createServer,
3
3
  parser,
4
4
  resolveOptions
5
- } from "./chunk-DFSBG7Q2.mjs";
5
+ } from "./chunk-DGBTBO7O.mjs";
6
6
  import {
7
7
  ViteSlidevPlugin
8
- } from "./chunk-7HWAUX7C.mjs";
8
+ } from "./chunk-MJETSRBI.mjs";
9
9
  import "./chunk-O6TYYGU6.mjs";
10
10
  import "./chunk-7HOZGSL4.mjs";
11
11
  import "./chunk-BXO7ZPPU.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/cli",
3
- "version": "0.48.0-beta.11",
3
+ "version": "0.48.0-beta.13",
4
4
  "description": "Presentation slides for developers",
5
5
  "author": "antfu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -77,7 +77,8 @@
77
77
  "mlly": "^1.6.1",
78
78
  "monaco-editor": "^0.37.1",
79
79
  "nanoid": "^5.0.6",
80
- "open": "^10.0.3",
80
+ "ohash": "^1.1.3",
81
+ "open": "^10.0.4",
81
82
  "pdf-lib": "^1.17.1",
82
83
  "plantuml-encoder": "^1.4.0",
83
84
  "postcss-nested": "^6.0.1",
@@ -88,6 +89,7 @@
88
89
  "resolve-from": "^5.0.0",
89
90
  "resolve-global": "^2.0.0",
90
91
  "shiki": "^1.1.7",
92
+ "shiki-magic-move": "^0.1.0",
91
93
  "sirv": "^2.0.4",
92
94
  "typescript": "^5.3.3",
93
95
  "unocss": "^0.58.5",
@@ -102,11 +104,11 @@
102
104
  "vite-plugin-static-copy": "^1.0.1",
103
105
  "vite-plugin-vue-server-ref": "^0.4.2",
104
106
  "vitefu": "^0.2.5",
105
- "vue": "^3.4.19",
107
+ "vue": "^3.4.20",
106
108
  "yargs": "^17.7.2",
107
- "@slidev/parser": "0.48.0-beta.11",
108
- "@slidev/client": "0.48.0-beta.11",
109
- "@slidev/types": "0.48.0-beta.11"
109
+ "@slidev/parser": "0.48.0-beta.13",
110
+ "@slidev/types": "0.48.0-beta.13",
111
+ "@slidev/client": "0.48.0-beta.13"
110
112
  },
111
113
  "devDependencies": {
112
114
  "@hedgedoc/markdown-it-plugins": "^2.1.4",