@shikijs/vitepress-twoslash 4.0.2 → 4.1.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/cache-fs.mjs CHANGED
@@ -2,7 +2,6 @@ import { createHash } from "node:crypto";
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { join, resolve } from "node:path";
4
4
  import process from "node:process";
5
-
6
5
  //#region src/cache-fs.ts
7
6
  function createFileSystemTypesCache(options = {}) {
8
7
  const dir = resolve(process.cwd(), options.dir ?? ".vitepress/cache/twoslash");
@@ -20,6 +19,5 @@ function createFileSystemTypesCache(options = {}) {
20
19
  }
21
20
  };
22
21
  }
23
-
24
22
  //#endregion
25
- export { createFileSystemTypesCache };
23
+ export { createFileSystemTypesCache };
@@ -1,4 +1,4 @@
1
- import { t as VitePressPluginTwoslashOptions } from "../types-CKSDIC5E.mjs";
1
+ import { t as VitePressPluginTwoslashOptions } from "../types-BvNUFoZh.mjs";
2
2
  import { UserConfig } from "vitepress";
3
3
 
4
4
  //#region src/cache-inline/markdown-fence.d.ts
@@ -6,7 +6,6 @@ import LZString from "lz-string";
6
6
  import { hash } from "ohash";
7
7
  import MagicString from "magic-string";
8
8
  import MarkdownIt from "markdown-it";
9
-
10
9
  //#region src/cache-inline/file-patcher.ts
11
10
  var FilePatcher = class {
12
11
  files = /* @__PURE__ */ new Map();
@@ -42,7 +41,6 @@ var FilePatcher = class {
42
41
  }
43
42
  }
44
43
  };
45
-
46
44
  //#endregion
47
45
  //#region src/cache-inline/cache-inline.ts
48
46
  const CODE_INLINE_CACHE_KEY = "@twoslash-cache";
@@ -156,7 +154,6 @@ function simplifyTwoslashReturn(ret) {
156
154
  meta: ret.meta ? { extension: ret.meta.extension } : void 0
157
155
  };
158
156
  }
159
-
160
157
  //#endregion
161
158
  //#region src/cache-inline/env.ts
162
159
  function isEnabledEnv(key) {
@@ -173,7 +170,6 @@ function isEnabledEnv(key) {
173
170
  }[val] || null;
174
171
  return null;
175
172
  }
176
-
177
173
  //#endregion
178
174
  //#region src/cache-inline/markdown-fence.ts
179
175
  function createMarkdownFenceSourceCodec(mapper) {
@@ -185,7 +181,7 @@ function createMarkdownFenceSourceCodec(mapper) {
185
181
  function injectToMarkdown(code, path) {
186
182
  const injects = mapper(code, path);
187
183
  let newCode = code;
188
- const injectAts = Array.from(injects.keys()).sort((a, b) => b - a);
184
+ const injectAts = [...injects.keys()].sort((a, b) => b - a);
189
185
  for (const at of injectAts) {
190
186
  const data = stringifyFenceSourceMap(injects.get(at));
191
187
  newCode = newCode.slice(0, at) + data + newCode.slice(at);
@@ -210,7 +206,6 @@ function createMarkdownFenceSourceCodec(mapper) {
210
206
  extractFromFence
211
207
  };
212
208
  }
213
-
214
209
  //#endregion
215
210
  //#region src/cache-inline/markdown-it-mapper.ts
216
211
  const markdownItMapper = function(code, path) {
@@ -266,7 +261,6 @@ function findNextNewLine(str, position) {
266
261
  if (str.charCodeAt(idx) === 13 && str.charCodeAt(idx + 1) === 10) return [idx, 2];
267
262
  return [idx, 1];
268
263
  }
269
-
270
264
  //#endregion
271
265
  //#region src/cache-inline/index.ts
272
266
  /**
@@ -320,6 +314,5 @@ function withFenceSourceMap(config, codec) {
320
314
  ((config.vite ??= {}).plugins ??= []).push(InjectPlugin);
321
315
  return config;
322
316
  }
323
-
324
317
  //#endregion
325
- export { createTwoslashWithInlineCache };
318
+ export { createTwoslashWithInlineCache };
package/dist/client.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import FloatingVue, { recomputeAllPoppers } from "floating-vue";
2
-
3
2
  //#region src/client.ts
4
3
  const isMobile = typeof navigator !== "undefined" && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
5
4
  /**
@@ -82,6 +81,5 @@ const TwoslashFloatingVue = { install: (app, options = {}) => {
82
81
  }
83
82
  });
84
83
  } };
85
-
86
84
  //#endregion
87
- export { TwoslashFloatingVue as default };
85
+ export { TwoslashFloatingVue as default };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as rendererFloatingVue, i as defaultHoverInfoProcessor, n as TwoslashFloatingVueOptions, r as TwoslashFloatingVueRendererOptions, t as VitePressPluginTwoslashOptions } from "./types-CKSDIC5E.mjs";
1
+ import { a as rendererFloatingVue, i as defaultHoverInfoProcessor, n as TwoslashFloatingVueOptions, r as TwoslashFloatingVueRendererOptions, t as VitePressPluginTwoslashOptions } from "./types-BvNUFoZh.mjs";
2
2
  import { ShikiTransformer } from "shiki";
3
3
 
4
4
  //#region src/index.d.ts
package/dist/index.mjs CHANGED
@@ -5,8 +5,9 @@ import { defaultHoverInfoProcessor, rendererRich } from "@shikijs/twoslash";
5
5
  import { fromMarkdown } from "mdast-util-from-markdown";
6
6
  import { gfmFromMarkdown } from "mdast-util-gfm";
7
7
  import { defaultHandlers, toHast } from "mdast-util-to-hast";
8
-
9
8
  //#region src/renderer-floating-vue.ts
9
+ const RE_JSDOC_LINK = /\{@link ([^}]*)\}/g;
10
+ const RE_PARAM_NAME = /^([\w$-]+)/;
10
11
  function rendererFloatingVue(options = {}) {
11
12
  const { classCopyIgnore = "vp-copy-ignore", classFloatingPanel = "twoslash-floating", classMarkdown = "vp-doc", floatingVueTheme = "twoslash", floatingVueThemeQuery = "twoslash-query", floatingVueThemeCompletion = "twoslash-completion" } = options.floatingVue || {};
12
13
  const { errorRendering = "line" } = options;
@@ -85,7 +86,7 @@ function vPre(el) {
85
86
  return el;
86
87
  }
87
88
  function renderMarkdown(md) {
88
- return toHast(fromMarkdown(md.replace(/\{@link ([^}]*)\}/g, "$1"), { mdastExtensions: [gfmFromMarkdown()] }), { handlers: { code: (state, node) => {
89
+ return toHast(fromMarkdown(md.replace(RE_JSDOC_LINK, "$1"), { mdastExtensions: [gfmFromMarkdown()] }), { handlers: { code: (state, node) => {
89
90
  const lang = node.lang || "";
90
91
  if (lang) return {
91
92
  type: "element",
@@ -102,7 +103,7 @@ function renderMarkdown(md) {
102
103
  } } }).children;
103
104
  }
104
105
  function renderMarkdownInline(md, context) {
105
- if (context === "tag:param") md = md.replace(/^([\w$-]+)/, "`$1` ");
106
+ if (context === "tag:param") md = md.replace(RE_PARAM_NAME, "`$1` ");
106
107
  const children = renderMarkdown.call(this, md);
107
108
  if (children.length === 1 && children[0].type === "element" && children[0].tagName === "p") return children[0].children;
108
109
  return children;
@@ -128,9 +129,11 @@ function compose(parts) {
128
129
  children: []
129
130
  }];
130
131
  }
131
-
132
132
  //#endregion
133
133
  //#region src/index.ts
134
+ const RE_NEWLINE = /\n/g;
135
+ const RE_TWOSLASH = /\btwoslash\b/;
136
+ const RE_LEFT_BRACE = /\{/g;
134
137
  /**
135
138
  * Create a Shiki transformer for VitePress to enable twoslash integration
136
139
  *
@@ -142,7 +145,7 @@ function transformerTwoslash(options = {}) {
142
145
  const isCI = typeof process !== "undefined" && process?.env?.CI;
143
146
  const isDev = typeof process !== "undefined" && process?.env?.NODE_ENV === "development";
144
147
  const shouldThrow = (options.throws || isCI || !isDev) && options.throws !== false;
145
- console.error(`\n\n--------\nTwoslash error in code:\n--------\n${code.split(/\n/g).slice(0, 15).join("\n").trim()}\n--------\n`);
148
+ console.error(`\n\n--------\nTwoslash error in code:\n--------\n${code.split(RE_NEWLINE).slice(0, 15).join("\n").trim()}\n--------\n`);
146
149
  if (shouldThrow) throw error;
147
150
  else console.error(error);
148
151
  return removeTwoslashNotations(code);
@@ -162,7 +165,7 @@ function transformerTwoslash(options = {}) {
162
165
  ...options,
163
166
  explicitTrigger
164
167
  });
165
- const trigger = explicitTrigger instanceof RegExp ? explicitTrigger : /\btwoslash\b/;
168
+ const trigger = explicitTrigger instanceof RegExp ? explicitTrigger : RE_TWOSLASH;
166
169
  return {
167
170
  ...twoslash,
168
171
  name: "@shikijs/vitepress-twoslash",
@@ -176,10 +179,9 @@ function transformerTwoslash(options = {}) {
176
179
  return twoslash.preprocess.call(this, code, options);
177
180
  },
178
181
  postprocess(html) {
179
- if (this.meta.twoslash) return html.replace(/\{/g, "{");
182
+ if (this.meta.twoslash) return html.replace(RE_LEFT_BRACE, "{");
180
183
  }
181
184
  };
182
185
  }
183
-
184
186
  //#endregion
185
- export { defaultHoverInfoProcessor, rendererFloatingVue, transformerTwoslash };
187
+ export { defaultHoverInfoProcessor, rendererFloatingVue, transformerTwoslash };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/vitepress-twoslash",
3
3
  "type": "module",
4
- "version": "4.0.2",
4
+ "version": "4.1.0",
5
5
  "description": "Enable Twoslash support in VitePress",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -45,11 +45,11 @@
45
45
  "mdast-util-gfm": "^3.1.0",
46
46
  "mdast-util-to-hast": "^13.2.1",
47
47
  "ohash": "^2.0.11",
48
- "twoslash": "^0.3.6",
49
- "twoslash-vue": "^0.3.6",
50
- "vue": "^3.5.29",
51
- "@shikijs/twoslash": "4.0.2",
52
- "shiki": "4.0.2"
48
+ "twoslash": "^0.3.8",
49
+ "twoslash-vue": "^0.3.8",
50
+ "vue": "^3.5.34",
51
+ "@shikijs/twoslash": "4.1.0",
52
+ "shiki": "4.1.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsdown",