@slidev/parser 52.14.2 → 52.15.0

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/dist/core.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-BwHfBd2q.mjs";
1
+ import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-Bas9O4Gd.mjs";
2
2
  import { FontOptions, ResolvedFontOptions, SlidevConfig, SlidevDetectedFeatures, SlidevMarkdown, SlidevPreparserExtension, SlidevThemeMeta, SourceSlideInfo } from "@slidev/types";
3
3
 
4
4
  //#region src/config.d.ts
package/dist/core.mjs CHANGED
@@ -1,8 +1,10 @@
1
- import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-BiNCPCdQ.mjs";
1
+ import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-CmVawvVO.mjs";
2
2
  import { ensurePrefix, toArray, uniq } from "@antfu/utils";
3
3
  import YAML from "yaml";
4
4
 
5
5
  //#region src/config.ts
6
+ const RE_QUOTED_STRING = /^(['"]).*\1$/;
7
+ const RE_FILENAME_STEM = /([^\\/]+?)(?:\.\w+)?$/;
6
8
  function getDefaultConfig() {
7
9
  return {
8
10
  theme: "default",
@@ -53,7 +55,8 @@ function getDefaultConfig() {
53
55
  duration: "30min",
54
56
  timer: "stopwatch",
55
57
  magicMoveDuration: 800,
56
- preloadImages: true
58
+ preloadImages: true,
59
+ clickAnimation: ""
57
60
  };
58
61
  }
59
62
  function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
@@ -72,15 +75,23 @@ function resolveConfig(headmatter, themeMeta = {}, filepath, verify = false) {
72
75
  ...headmatter.config,
73
76
  ...headmatter,
74
77
  fonts: resolveFonts({
78
+ ...defaultConfig.fonts,
75
79
  ...themeMeta.defaults?.fonts,
76
80
  ...headmatter.config?.fonts,
77
81
  ...headmatter?.fonts
78
82
  }),
79
83
  drawings: resolveDrawings(headmatter.drawings, filepath),
80
84
  htmlAttrs: {
85
+ ...defaultConfig.htmlAttrs,
81
86
  ...themeMeta.defaults?.htmlAttrs,
82
87
  ...headmatter.config?.htmlAttrs,
83
88
  ...headmatter?.htmlAttrs
89
+ },
90
+ themeConfig: {
91
+ ...defaultConfig.themeConfig,
92
+ ...themeMeta.defaults?.themeConfig,
93
+ ...headmatter.config?.themeConfig,
94
+ ...headmatter?.themeConfig
84
95
  }
85
96
  };
86
97
  if (config.highlighter === "shikiji") {
@@ -106,12 +117,12 @@ function verifyConfig(config, themeMeta = {}, warn = (v) => console.warn(`[slide
106
117
  }
107
118
  function resolveFonts(fonts = {}) {
108
119
  const { fallbacks = true, italic = false, provider = "google" } = fonts;
109
- let sans = toArray(fonts.sans).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
110
- let serif = toArray(fonts.serif).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
111
- let mono = toArray(fonts.mono).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
112
- const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(/,\s*/g)).map((i) => i.trim());
113
- const custom = toArray(fonts.custom).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
114
- const local = toArray(fonts.local).flatMap((i) => i.split(/,\s*/g)).map((i) => i.trim());
120
+ let sans = toArray(fonts.sans).flatMap((i) => i.split(",")).map((i) => i.trim());
121
+ let serif = toArray(fonts.serif).flatMap((i) => i.split(",")).map((i) => i.trim());
122
+ let mono = toArray(fonts.mono).flatMap((i) => i.split(",")).map((i) => i.trim());
123
+ const weights = toArray(fonts.weights || "200,400,600").flatMap((i) => i.toString().split(",")).map((i) => i.trim());
124
+ const custom = toArray(fonts.custom).flatMap((i) => i.split(",")).map((i) => i.trim());
125
+ const local = toArray(fonts.local).flatMap((i) => i.split(",")).map((i) => i.trim());
115
126
  const webfonts = fonts.webfonts ? fonts.webfonts : fallbacks ? uniq([
116
127
  ...sans,
117
128
  ...serif,
@@ -119,7 +130,7 @@ function resolveFonts(fonts = {}) {
119
130
  ...custom
120
131
  ]).filter((i) => !local.includes(i)) : [];
121
132
  function toQuoted(font) {
122
- if (/^(['"]).*\1$/.test(font)) return font;
133
+ if (RE_QUOTED_STRING.test(font)) return font;
123
134
  return `"${font}"`;
124
135
  }
125
136
  if (fallbacks) {
@@ -176,7 +187,7 @@ function resolveDrawings(options = {}, filepath) {
176
187
  const { enabled = true, persist = false, presenterOnly = false, syncAll = true } = options;
177
188
  return {
178
189
  enabled,
179
- persist: typeof persist === "string" ? persist : persist ? `.slidev/drawings${filepath ? `/${filepath.match(/([^\\/]+?)(\.\w+)?$/)?.[1]}` : ""}` : false,
190
+ persist: typeof persist === "string" ? persist : persist ? `.slidev/drawings${filepath ? `/${filepath.match(RE_FILENAME_STEM)?.[1]}` : ""}` : false,
180
191
  presenterOnly,
181
192
  syncAll
182
193
  };
@@ -184,6 +195,17 @@ function resolveDrawings(options = {}, filepath) {
184
195
 
185
196
  //#endregion
186
197
  //#region src/core.ts
198
+ const RE_FRONTMATTER = /^---.*\r?\n([\s\S]*?)---/;
199
+ const RE_YAML_CODEBLOCK = /^\s*```ya?ml([\s\S]*?)```/;
200
+ const RE_DOLLAR_INLINE = /\$.*?\$/;
201
+ const RE_DOLLAR_BLOCK = /\$\$/;
202
+ const RE_MONACO_BLOCK = /\{monaco.*\}/;
203
+ const RE_TWEET_TAG = /<Tweet\b/;
204
+ const RE_BLUESKY_TAG = /<BlueSky\b/;
205
+ const RE_MERMAID_CODEBLOCK = /^```mermaid/m;
206
+ const RE_HEADING = /^(#+) (.*)$/m;
207
+ const RE_LEADING_BACKTICKS = /^\s*`+/;
208
+ const RE_CRLF = /\r?\n/g;
187
209
  function stringify(data) {
188
210
  return `${data.slides.map(stringifySlide).join("\n").trim()}\n`;
189
211
  }
@@ -203,12 +225,12 @@ function prettify(data) {
203
225
  function matter(code, options) {
204
226
  let type;
205
227
  let raw;
206
- let content = code.replace(/^---.*\r?\n([\s\S]*?)---/, (_, f) => {
228
+ let content = code.replace(RE_FRONTMATTER, (_, f) => {
207
229
  type = "frontmatter";
208
230
  raw = f;
209
231
  return "";
210
232
  });
211
- if (type !== "frontmatter") content = content.replace(/^\s*```ya?ml([\s\S]*?)```/, (_, f) => {
233
+ if (type !== "frontmatter") content = content.replace(RE_YAML_CODEBLOCK, (_, f) => {
212
234
  type = "yaml";
213
235
  raw = f;
214
236
  return "";
@@ -248,10 +270,11 @@ function extractImagesUsage(content, frontmatter) {
248
270
  }
249
271
  function detectFeatures(code) {
250
272
  return {
251
- katex: !!code.match(/\$.*?\$/) || !!code.match(/\$\$/),
252
- monaco: code.match(/\{monaco.*\}/) ? scanMonacoReferencedMods(code) : false,
253
- tweet: !!code.match(/<Tweet\b/),
254
- mermaid: !!code.match(/^```mermaid/m)
273
+ katex: !!code.match(RE_DOLLAR_INLINE) || !!code.match(RE_DOLLAR_BLOCK),
274
+ monaco: RE_MONACO_BLOCK.test(code) ? scanMonacoReferencedMods(code) : false,
275
+ tweet: !!code.match(RE_TWEET_TAG),
276
+ bluesky: !!code.match(RE_BLUESKY_TAG),
277
+ mermaid: !!code.match(RE_MERMAID_CODEBLOCK)
255
278
  };
256
279
  }
257
280
  function parseSlide(raw, options = {}) {
@@ -272,7 +295,7 @@ function parseSlide(raw, options = {}) {
272
295
  let level;
273
296
  if (frontmatter.title || frontmatter.name) title = frontmatter.title || frontmatter.name;
274
297
  else {
275
- const match = content.match(/^(#+) (.*)$/m);
298
+ const match = content.match(RE_HEADING);
276
299
  title = match?.[2]?.trim();
277
300
  level = match?.[1]?.length;
278
301
  }
@@ -294,7 +317,7 @@ function parseSlide(raw, options = {}) {
294
317
  };
295
318
  }
296
319
  async function parse(markdown, filepath, extensions, options = {}) {
297
- const lines = markdown.split(options.preserveCR ? "\n" : /\r?\n/g);
320
+ const lines = markdown.split(options.preserveCR ? "\n" : RE_CRLF);
298
321
  const slides = [];
299
322
  let start = 0;
300
323
  let contentStart = 0;
@@ -338,7 +361,7 @@ async function parse(markdown, filepath, extensions, options = {}) {
338
361
  contentStart = i + 1;
339
362
  }
340
363
  } else if (line.trimStart().startsWith("```")) {
341
- const codeBlockLevel = line.match(/^\s*`+/)[0];
364
+ const codeBlockLevel = line.match(RE_LEADING_BACKTICKS)[0];
342
365
  let j = i + 1;
343
366
  for (; j < lines.length; j++) if (lines[j].startsWith(codeBlockLevel)) break;
344
367
  if (j !== lines.length) i = j;
@@ -352,7 +375,7 @@ async function parse(markdown, filepath, extensions, options = {}) {
352
375
  };
353
376
  }
354
377
  function parseSync(markdown, filepath, options = {}) {
355
- const lines = markdown.split(options.preserveCR ? "\n" : /\r?\n/g);
378
+ const lines = markdown.split(options.preserveCR ? "\n" : RE_CRLF);
356
379
  const slides = [];
357
380
  let start = 0;
358
381
  let contentStart = 0;
@@ -381,7 +404,7 @@ function parseSync(markdown, filepath, options = {}) {
381
404
  contentStart = i + 1;
382
405
  }
383
406
  } else if (line.trimStart().startsWith("```")) {
384
- const codeBlockLevel = line.match(/^\s*`+/)[0];
407
+ const codeBlockLevel = line.match(RE_LEADING_BACKTICKS)[0];
385
408
  let j = i + 1;
386
409
  for (; j < lines.length; j++) if (lines[j].startsWith(codeBlockLevel)) break;
387
410
  if (j !== lines.length) i = j;
package/dist/fs.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-BwHfBd2q.mjs";
1
+ import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-Bas9O4Gd.mjs";
2
2
  import { SlidevParserOptions, detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig } from "./core.mjs";
3
3
  import { PreparserExtensionLoader, SlidevData, SlidevMarkdown } from "@slidev/types";
4
4
 
package/dist/fs.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-BiNCPCdQ.mjs";
1
+ import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-CmVawvVO.mjs";
2
2
  import { detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig } from "./core.mjs";
3
3
  import { slash } from "@antfu/utils";
4
4
  import YAML from "yaml";
@@ -7,6 +7,10 @@ import { readFile, writeFile } from "node:fs/promises";
7
7
  import { dirname, resolve } from "node:path";
8
8
 
9
9
  //#region src/fs.ts
10
+ const RE_FRONTMATTER_START = /^---(?:[^-].*)?$/;
11
+ const RE_BLANK_LINE = /^\s*$/;
12
+ const RE_FRONTMATTER_END = /^---$/;
13
+ const RE_CRLF = /\r?\n/g;
10
14
  let preparserExtensionLoader = null;
11
15
  function injectPreparserExtensionLoader(fn) {
12
16
  preparserExtensionLoader = fn;
@@ -16,11 +20,11 @@ async function load(userRoot, filepath, sources = {}, mode) {
16
20
  const markdown = await loadSource(filepath);
17
21
  let extensions;
18
22
  if (preparserExtensionLoader) {
19
- const lines = markdown.split(/\r?\n/g);
23
+ const lines = markdown.split(RE_CRLF);
20
24
  let hm = "";
21
- if (lines[0].match(/^---([^-].*)?$/) && !lines[1]?.match(/^\s*$/)) {
25
+ if (RE_FRONTMATTER_START.test(lines[0]) && !lines[1]?.match(RE_BLANK_LINE)) {
22
26
  let hEnd = 1;
23
- while (hEnd < lines.length && !lines[hEnd].trimEnd().match(/^---$/)) hEnd++;
27
+ while (hEnd < lines.length && !RE_FRONTMATTER_END.test(lines[hEnd].trimEnd())) hEnd++;
24
28
  hm = lines.slice(1, hEnd).join("\n");
25
29
  }
26
30
  const o = YAML.parse(hm) ?? {};
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-BwHfBd2q.mjs";
1
+ import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-Bas9O4Gd.mjs";
2
2
  import { SlidevParserOptions, detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig } from "./core.mjs";
3
3
  export { SlidevParserOptions, TimesplitInput, TimesplitOutput, detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseAspectRatio, parseRangeString, parseSlide, parseSync, parseTimeString, parseTimesplits, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-BiNCPCdQ.mjs";
1
+ import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-CmVawvVO.mjs";
2
2
  import { detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseSlide, parseSync, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig } from "./core.mjs";
3
3
 
4
4
  export { detectFeatures, extractImagesUsage, getDefaultConfig, parse, parseAspectRatio, parseRangeString, parseSlide, parseSync, parseTimeString, parseTimesplits, prettify, prettifySlide, resolveConfig, resolveFonts, stringify, stringifySlide, verifyConfig };
@@ -14,21 +14,6 @@ interface TimesplitOutput {
14
14
  declare function parseTimesplits(inputs: TimesplitInput[]): TimesplitOutput[];
15
15
  //#endregion
16
16
  //#region src/timesplit/timestring.d.ts
17
- /**
18
- * Parse timestamp into seconds
19
- *
20
- * Accepts:
21
- * - 10:50.1
22
- * - 10s
23
- * - 5m
24
- * - 3min
25
- * - 3mins 5secs
26
- * - 10.5m3s
27
- * - +10s
28
- * - 1h10m30s
29
- * - 1h4s
30
- * - 1:1:1
31
- */
32
17
  declare function parseTimeString(timestamp: string | number): {
33
18
  seconds: number;
34
19
  relative: boolean;
@@ -16,6 +16,7 @@ import { isNumber, range, uniq } from "@antfu/utils";
16
16
  * - 1h4s
17
17
  * - 1:1:1
18
18
  */
19
+ const RE_ALPHA = /[a-z]/i;
19
20
  function parseTimeString(timestamp) {
20
21
  if (typeof timestamp === "number") return {
21
22
  seconds: timestamp,
@@ -40,7 +41,7 @@ function parseTimeString(timestamp) {
40
41
  else throw new TypeError("Invalid timestamp format");
41
42
  if (Number.isNaN(h) || Number.isNaN(m) || Number.isNaN(s)) throw new TypeError("Invalid timestamp format");
42
43
  seconds = (h || 0) * 3600 + (m || 0) * 60 + (s || 0);
43
- } else if (!timestamp.match(/[a-z]/i)) seconds = Number(timestamp);
44
+ } else if (!RE_ALPHA.test(timestamp)) seconds = Number(timestamp);
44
45
  else {
45
46
  const unitMap = {
46
47
  s: 1,
@@ -115,6 +116,7 @@ function parseTimesplits(inputs) {
115
116
 
116
117
  //#endregion
117
118
  //#region src/utils.ts
119
+ const RE_ASPECT_RATIO_SEPARATOR = /[:/x|]/;
118
120
  /**
119
121
  * 1,3-5,8 => [1, 3, 4, 5, 8]
120
122
  */
@@ -135,7 +137,7 @@ function parseRangeString(total, rangeStr) {
135
137
  function parseAspectRatio(str) {
136
138
  if (isNumber(str)) return str;
137
139
  if (!Number.isNaN(+str)) return +str;
138
- const [wStr = "", hStr = ""] = str.split(/[:/x|]/);
140
+ const [wStr = "", hStr = ""] = str.split(RE_ASPECT_RATIO_SEPARATOR);
139
141
  const w = Number.parseFloat(wStr.trim());
140
142
  const h = Number.parseFloat(hStr.trim());
141
143
  if (Number.isNaN(w) || Number.isNaN(h) || h === 0) throw new Error(`Invalid aspect ratio "${str}"`);
package/dist/utils.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-BwHfBd2q.mjs";
1
+ import { a as TimesplitOutput, i as TimesplitInput, n as parseRangeString, o as parseTimesplits, r as parseTimeString, t as parseAspectRatio } from "./utils-Bas9O4Gd.mjs";
2
2
  export { TimesplitInput, TimesplitOutput, parseAspectRatio, parseRangeString, parseTimeString, parseTimesplits };
package/dist/utils.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-BiNCPCdQ.mjs";
1
+ import { i as parseTimeString, n as parseRangeString, r as parseTimesplits, t as parseAspectRatio } from "./utils-CmVawvVO.mjs";
2
2
 
3
3
  export { parseAspectRatio, parseRangeString, parseTimeString, parseTimesplits };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/parser",
3
- "version": "52.14.2",
3
+ "version": "52.15.0",
4
4
  "description": "Markdown parser for Slidev",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@antfu/utils": "^9.3.0",
33
- "yaml": "^2.8.2",
34
- "@slidev/types": "52.14.2"
33
+ "yaml": "^2.8.3",
34
+ "@slidev/types": "52.15.0"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsdown",