@slidev/cli 0.42.3 → 0.42.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.
@@ -183,13 +183,13 @@ var _isinstalledglobally = require('is-installed-globally'); var _isinstalledglo
183
183
 
184
184
  // ../client/package.json
185
185
  var dependencies = {
186
- "@antfu/utils": "^0.7.2",
186
+ "@antfu/utils": "^0.7.4",
187
187
  "@slidev/parser": "workspace:*",
188
188
  "@slidev/types": "workspace:*",
189
- "@unocss/reset": "^0.52.4",
190
- "@vueuse/core": "^10.1.2",
189
+ "@unocss/reset": "^0.53.1",
190
+ "@vueuse/core": "^10.2.0",
191
191
  "@vueuse/head": "^1.1.26",
192
- "@vueuse/math": "^10.1.2",
192
+ "@vueuse/math": "^10.2.0",
193
193
  "@vueuse/motion": "^2.0.0",
194
194
  codemirror: "^5.65.5",
195
195
  defu: "^6.1.2",
@@ -199,13 +199,13 @@ var dependencies = {
199
199
  "js-base64": "^3.7.5",
200
200
  "js-yaml": "^4.1.0",
201
201
  katex: "^0.16.7",
202
- mermaid: "^10.2.0",
202
+ mermaid: "^10.2.3",
203
203
  "monaco-editor": "^0.37.1",
204
204
  nanoid: "^4.0.2",
205
205
  prettier: "^2.8.8",
206
206
  recordrtc: "^5.6.2",
207
207
  resolve: "^1.22.2",
208
- unocss: "^0.52.4",
208
+ unocss: "^0.53.1",
209
209
  "vite-plugin-windicss": "^1.9.0",
210
210
  vue: "^3.3.4",
211
211
  "vue-router": "^4.2.2",
@@ -418,7 +418,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, u
418
418
  if (!match)
419
419
  return next();
420
420
  const [, no, type] = match;
421
- const idx = parseInt(no);
421
+ const idx = Number.parseInt(no);
422
422
  if (type === "json" && req.method === "GET") {
423
423
  res.write(JSON.stringify(prepareSlideInfo(data.slides[idx])));
424
424
  return res.end();
@@ -538,7 +538,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, u
538
538
  return generateCustomNavControls();
539
539
  if (id === "/@slidev/titles.md") {
540
540
  return {
541
- code: data.slides.map(({ title }, i) => {
541
+ code: data.slides.filter(({ frontmatter }) => !(frontmatter == null ? void 0 : frontmatter.disabled)).map(({ title }, i) => {
542
542
  return `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">
543
543
 
544
544
  ${title}
@@ -553,7 +553,7 @@ ${title}
553
553
  const match = remaning.match(regexIdQuery);
554
554
  if (match) {
555
555
  const [, no, type] = match;
556
- const pageNo = parseInt(no) - 1;
556
+ const pageNo = Number.parseInt(no) - 1;
557
557
  if (type === "md") {
558
558
  return {
559
559
  code: (_a = data.slides[pageNo]) == null ? void 0 : _a.content,
@@ -581,7 +581,7 @@ ${title}
581
581
  const [, no, type] = match;
582
582
  if (type !== "md")
583
583
  return;
584
- const pageNo = parseInt(no) - 1;
584
+ const pageNo = Number.parseInt(no) - 1;
585
585
  return transformMarkdown(code, pageNo, data);
586
586
  }
587
587
  },
@@ -804,36 +804,39 @@ ${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}
804
804
  }
805
805
  async function generateRoutes() {
806
806
  const imports = [];
807
+ const redirects = [];
807
808
  const layouts = await getLayouts();
808
809
  imports.push(`import __layout__end from '${layouts.end}'`);
809
810
  let no = 1;
810
- const routes = [
811
- ...data.slides.map((i, idx) => {
812
- var _a, _b, _c, _d;
813
- if ((_a = i.frontmatter) == null ? void 0 : _a.disabled)
814
- return void 0;
815
- imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
816
- const additions = {
817
- slide: {
818
- ...prepareSlideInfo(i),
819
- filepath: ((_b = i.source) == null ? void 0 : _b.filepath) || entry,
820
- id: idx,
821
- no
822
- },
823
- __clicksElements: [],
824
- __preloaded: false
825
- };
826
- const meta = Object.assign({}, i.frontmatter, additions);
827
- const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: ${JSON.stringify(meta)} }`;
828
- const redirect = ((_c = i.frontmatter) == null ? void 0 : _c.routeAlias) ? `{ path: '${(_d = i.frontmatter) == null ? void 0 : _d.routeAlias}', redirect: { path: '${no}' } }` : null;
829
- no += 1;
830
- return [route, redirect];
831
- }).flat().filter(_utils.notNullish)
832
- ];
811
+ const routes = data.slides.map((i, idx) => {
812
+ var _a, _b, _c, _d;
813
+ if ((_a = i.frontmatter) == null ? void 0 : _a.disabled)
814
+ return void 0;
815
+ imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
816
+ const additions = {
817
+ slide: {
818
+ ...prepareSlideInfo(i),
819
+ filepath: ((_b = i.source) == null ? void 0 : _b.filepath) || entry,
820
+ id: idx,
821
+ no
822
+ },
823
+ __clicksElements: [],
824
+ __preloaded: false
825
+ };
826
+ const meta = Object.assign({}, i.frontmatter, additions);
827
+ const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: ${JSON.stringify(meta)} }`;
828
+ if ((_c = i.frontmatter) == null ? void 0 : _c.routeAlias)
829
+ redirects.push(`{ path: '${(_d = i.frontmatter) == null ? void 0 : _d.routeAlias}', redirect: { path: '${no}' } }`);
830
+ no += 1;
831
+ return route;
832
+ });
833
833
  const routesStr = `export default [
834
834
  ${routes.join(",\n")}
835
835
  ]`;
836
- return [...imports, routesStr].join("\n");
836
+ const redirectsStr = `export const redirects = [
837
+ ${redirects.join(",\n")}
838
+ ]`;
839
+ return [...imports, routesStr, redirectsStr].join("\n");
837
840
  }
838
841
  function generateConfigs() {
839
842
  const config = { ...data.config, remote };
@@ -1149,6 +1152,19 @@ function math_plugin(md2, options) {
1149
1152
  // node/plugins/markdown-it-prism.ts
1150
1153
  var _prismjs = require('prismjs'); var _prismjs2 = _interopRequireDefault(_prismjs);
1151
1154
  var _ = require('prismjs/components/'); var _2 = _interopRequireDefault(_);
1155
+ var _htmlparser2 = require('htmlparser2'); var htmlparser2 = _interopRequireWildcard(_htmlparser2);
1156
+ var Tag = class {
1157
+ constructor(tagname, attributes) {
1158
+ this.tagname = tagname;
1159
+ this.attributes = attributes;
1160
+ }
1161
+ asOpen() {
1162
+ return `<${this.tagname} ${Object.entries(this.attributes).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
1163
+ }
1164
+ asClosed() {
1165
+ return `</${this.tagname}>`;
1166
+ }
1167
+ };
1152
1168
  var DEFAULTS = {
1153
1169
  plugins: [],
1154
1170
  init: () => {
@@ -1187,10 +1203,32 @@ function selectLanguage(options, lang) {
1187
1203
  }
1188
1204
  function highlight(markdownit, options, text, lang) {
1189
1205
  const [langToUse, prismLang] = selectLanguage(options, lang);
1190
- const code = text.trimEnd().split(/\r?\n/g).map((line) => prismLang ? _prismjs2.default.highlight(line, prismLang, langToUse) : markdownit.utils.escapeHtml(line)).map((line) => `<span class="line">${line}</span>`).join("\n");
1206
+ let code = text.trimEnd();
1207
+ code = prismLang ? highlightPrism(code, prismLang, langToUse) : markdownit.utils.escapeHtml(code);
1208
+ code = code.split(/\r?\n/g).map((line) => `<span class="line">${line}</span>`).join("\n");
1191
1209
  const classAttribute = langToUse ? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"` : "";
1192
1210
  return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`);
1193
1211
  }
1212
+ function highlightPrism(code, prismLang, langToUse) {
1213
+ const openTags = [];
1214
+ const parser2 = new htmlparser2.Parser({
1215
+ onopentag(tagname, attributes) {
1216
+ openTags.push(new Tag(tagname, attributes));
1217
+ },
1218
+ onclosetag() {
1219
+ openTags.pop();
1220
+ }
1221
+ });
1222
+ code = _prismjs2.default.highlight(code, prismLang, langToUse);
1223
+ code = code.split(/\r?\n/g).map((line) => {
1224
+ const prefix = openTags.map((tag) => tag.asOpen()).join("");
1225
+ parser2.write(line);
1226
+ const postfix = openTags.reverse().map((tag) => tag.asClosed()).join("");
1227
+ return prefix + line + postfix;
1228
+ }).join("\n");
1229
+ parser2.end();
1230
+ return code;
1231
+ }
1194
1232
  function checkLanguageOption(options, optionName) {
1195
1233
  const language = options[optionName];
1196
1234
  if (language !== void 0 && loadPrismLang(language) === void 0)
@@ -183,13 +183,13 @@ import { uniq as uniq2 } from "@antfu/utils";
183
183
 
184
184
  // ../client/package.json
185
185
  var dependencies = {
186
- "@antfu/utils": "^0.7.2",
186
+ "@antfu/utils": "^0.7.4",
187
187
  "@slidev/parser": "workspace:*",
188
188
  "@slidev/types": "workspace:*",
189
- "@unocss/reset": "^0.52.4",
190
- "@vueuse/core": "^10.1.2",
189
+ "@unocss/reset": "^0.53.1",
190
+ "@vueuse/core": "^10.2.0",
191
191
  "@vueuse/head": "^1.1.26",
192
- "@vueuse/math": "^10.1.2",
192
+ "@vueuse/math": "^10.2.0",
193
193
  "@vueuse/motion": "^2.0.0",
194
194
  codemirror: "^5.65.5",
195
195
  defu: "^6.1.2",
@@ -199,13 +199,13 @@ var dependencies = {
199
199
  "js-base64": "^3.7.5",
200
200
  "js-yaml": "^4.1.0",
201
201
  katex: "^0.16.7",
202
- mermaid: "^10.2.0",
202
+ mermaid: "^10.2.3",
203
203
  "monaco-editor": "^0.37.1",
204
204
  nanoid: "^4.0.2",
205
205
  prettier: "^2.8.8",
206
206
  recordrtc: "^5.6.2",
207
207
  resolve: "^1.22.2",
208
- unocss: "^0.52.4",
208
+ unocss: "^0.53.1",
209
209
  "vite-plugin-windicss": "^1.9.0",
210
210
  vue: "^3.3.4",
211
211
  "vue-router": "^4.2.2",
@@ -418,7 +418,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, u
418
418
  if (!match)
419
419
  return next();
420
420
  const [, no, type] = match;
421
- const idx = parseInt(no);
421
+ const idx = Number.parseInt(no);
422
422
  if (type === "json" && req.method === "GET") {
423
423
  res.write(JSON.stringify(prepareSlideInfo(data.slides[idx])));
424
424
  return res.end();
@@ -538,7 +538,7 @@ function createSlidesLoader({ data, entry, clientRoot, themeRoots, addonRoots, u
538
538
  return generateCustomNavControls();
539
539
  if (id === "/@slidev/titles.md") {
540
540
  return {
541
- code: data.slides.map(({ title }, i) => {
541
+ code: data.slides.filter(({ frontmatter }) => !(frontmatter == null ? void 0 : frontmatter.disabled)).map(({ title }, i) => {
542
542
  return `<template ${i === 0 ? "v-if" : "v-else-if"}="+no === ${i + 1}">
543
543
 
544
544
  ${title}
@@ -553,7 +553,7 @@ ${title}
553
553
  const match = remaning.match(regexIdQuery);
554
554
  if (match) {
555
555
  const [, no, type] = match;
556
- const pageNo = parseInt(no) - 1;
556
+ const pageNo = Number.parseInt(no) - 1;
557
557
  if (type === "md") {
558
558
  return {
559
559
  code: (_a = data.slides[pageNo]) == null ? void 0 : _a.content,
@@ -581,7 +581,7 @@ ${title}
581
581
  const [, no, type] = match;
582
582
  if (type !== "md")
583
583
  return;
584
- const pageNo = parseInt(no) - 1;
584
+ const pageNo = Number.parseInt(no) - 1;
585
585
  return transformMarkdown(code, pageNo, data);
586
586
  }
587
587
  },
@@ -804,36 +804,39 @@ ${Object.entries(layouts).map(([k, v]) => `"${k}": ${v}`).join(",\n")}
804
804
  }
805
805
  async function generateRoutes() {
806
806
  const imports = [];
807
+ const redirects = [];
807
808
  const layouts = await getLayouts();
808
809
  imports.push(`import __layout__end from '${layouts.end}'`);
809
810
  let no = 1;
810
- const routes = [
811
- ...data.slides.map((i, idx) => {
812
- var _a, _b, _c, _d;
813
- if ((_a = i.frontmatter) == null ? void 0 : _a.disabled)
814
- return void 0;
815
- imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
816
- const additions = {
817
- slide: {
818
- ...prepareSlideInfo(i),
819
- filepath: ((_b = i.source) == null ? void 0 : _b.filepath) || entry,
820
- id: idx,
821
- no
822
- },
823
- __clicksElements: [],
824
- __preloaded: false
825
- };
826
- const meta = Object.assign({}, i.frontmatter, additions);
827
- const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: ${JSON.stringify(meta)} }`;
828
- const redirect = ((_c = i.frontmatter) == null ? void 0 : _c.routeAlias) ? `{ path: '${(_d = i.frontmatter) == null ? void 0 : _d.routeAlias}', redirect: { path: '${no}' } }` : null;
829
- no += 1;
830
- return [route, redirect];
831
- }).flat().filter(notNullish)
832
- ];
811
+ const routes = data.slides.map((i, idx) => {
812
+ var _a, _b, _c, _d;
813
+ if ((_a = i.frontmatter) == null ? void 0 : _a.disabled)
814
+ return void 0;
815
+ imports.push(`import n${no} from '${slidePrefix}${idx + 1}.md'`);
816
+ const additions = {
817
+ slide: {
818
+ ...prepareSlideInfo(i),
819
+ filepath: ((_b = i.source) == null ? void 0 : _b.filepath) || entry,
820
+ id: idx,
821
+ no
822
+ },
823
+ __clicksElements: [],
824
+ __preloaded: false
825
+ };
826
+ const meta = Object.assign({}, i.frontmatter, additions);
827
+ const route = `{ path: '${no}', name: 'page-${no}', component: n${no}, meta: ${JSON.stringify(meta)} }`;
828
+ if ((_c = i.frontmatter) == null ? void 0 : _c.routeAlias)
829
+ redirects.push(`{ path: '${(_d = i.frontmatter) == null ? void 0 : _d.routeAlias}', redirect: { path: '${no}' } }`);
830
+ no += 1;
831
+ return route;
832
+ });
833
833
  const routesStr = `export default [
834
834
  ${routes.join(",\n")}
835
835
  ]`;
836
- return [...imports, routesStr].join("\n");
836
+ const redirectsStr = `export const redirects = [
837
+ ${redirects.join(",\n")}
838
+ ]`;
839
+ return [...imports, routesStr, redirectsStr].join("\n");
837
840
  }
838
841
  function generateConfigs() {
839
842
  const config = { ...data.config, remote };
@@ -1149,6 +1152,19 @@ function math_plugin(md2, options) {
1149
1152
  // node/plugins/markdown-it-prism.ts
1150
1153
  import Prism from "prismjs";
1151
1154
  import loadLanguages from "prismjs/components/";
1155
+ import * as htmlparser2 from "htmlparser2";
1156
+ var Tag = class {
1157
+ constructor(tagname, attributes) {
1158
+ this.tagname = tagname;
1159
+ this.attributes = attributes;
1160
+ }
1161
+ asOpen() {
1162
+ return `<${this.tagname} ${Object.entries(this.attributes).map(([key, value]) => `${key}="${value}"`).join(" ")}>`;
1163
+ }
1164
+ asClosed() {
1165
+ return `</${this.tagname}>`;
1166
+ }
1167
+ };
1152
1168
  var DEFAULTS = {
1153
1169
  plugins: [],
1154
1170
  init: () => {
@@ -1187,10 +1203,32 @@ function selectLanguage(options, lang) {
1187
1203
  }
1188
1204
  function highlight(markdownit, options, text, lang) {
1189
1205
  const [langToUse, prismLang] = selectLanguage(options, lang);
1190
- const code = text.trimEnd().split(/\r?\n/g).map((line) => prismLang ? Prism.highlight(line, prismLang, langToUse) : markdownit.utils.escapeHtml(line)).map((line) => `<span class="line">${line}</span>`).join("\n");
1206
+ let code = text.trimEnd();
1207
+ code = prismLang ? highlightPrism(code, prismLang, langToUse) : markdownit.utils.escapeHtml(code);
1208
+ code = code.split(/\r?\n/g).map((line) => `<span class="line">${line}</span>`).join("\n");
1191
1209
  const classAttribute = langToUse ? ` class="slidev-code ${markdownit.options.langPrefix}${markdownit.utils.escapeHtml(langToUse)}"` : "";
1192
1210
  return escapeVueInCode(`<pre${classAttribute}><code>${code}</code></pre>`);
1193
1211
  }
1212
+ function highlightPrism(code, prismLang, langToUse) {
1213
+ const openTags = [];
1214
+ const parser2 = new htmlparser2.Parser({
1215
+ onopentag(tagname, attributes) {
1216
+ openTags.push(new Tag(tagname, attributes));
1217
+ },
1218
+ onclosetag() {
1219
+ openTags.pop();
1220
+ }
1221
+ });
1222
+ code = Prism.highlight(code, prismLang, langToUse);
1223
+ code = code.split(/\r?\n/g).map((line) => {
1224
+ const prefix = openTags.map((tag) => tag.asOpen()).join("");
1225
+ parser2.write(line);
1226
+ const postfix = openTags.reverse().map((tag) => tag.asClosed()).join("");
1227
+ return prefix + line + postfix;
1228
+ }).join("\n");
1229
+ parser2.end();
1230
+ return code;
1231
+ }
1194
1232
  function checkLanguageOption(options, optionName) {
1195
1233
  const language = options[optionName];
1196
1234
  if (language !== void 0 && loadPrismLang(language) === void 0)