vitepress-plugin-toolkit 0.3.0 → 0.5.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.
@@ -1,37 +1,127 @@
1
+ import { Matcher } from "picomatch";
1
2
  import MarkdownIt from "markdown-it";
2
3
  import { RenderRule } from "markdown-it/lib/renderer.mjs";
3
- import { RuleOptions } from "markdown-it/lib/ruler.mjs";
4
4
  import { MarkdownEnv, Plugin, SiteConfig } from "vitepress";
5
5
 
6
6
  //#region src/shared/link.d.ts
7
+ /**
8
+ * Regular expression that matches external URLs.
9
+ *
10
+ * Matches URLs that start with a protocol (such as `http:` or `mailto:`) or
11
+ * with `//` (protocol-relative URLs).
12
+ *
13
+ * 匹配外部链接的正则表达式。
14
+ *
15
+ * 匹配以协议(如 `http:` 或 `mailto:`)或 `//`(协议相对链接)开头的 URL。
16
+ *
17
+ * @example
18
+ * EXTERNAL_URL_RE.test('https://example.com') // true
19
+ * EXTERNAL_URL_RE.test('//cdn.example.com/lib.js') // true
20
+ * EXTERNAL_URL_RE.test('/about') // false
21
+ */
7
22
  declare const EXTERNAL_URL_RE: RegExp;
23
+ /**
24
+ * Checks whether the given path is an external URL.
25
+ *
26
+ * 判断给定路径是否为外部链接。
27
+ *
28
+ * @param path - The path to check / 要检查的路径
29
+ * @returns `true` if the path is an external URL, otherwise `false` / 若为外部链接返回 `true`,否则返回 `false`
30
+ * @example
31
+ * isExternal('https://example.com') // true
32
+ * isExternal('//cdn.example.com/lib.js') // true
33
+ * isExternal('/about') // false
34
+ * isExternal('mailto:foo@example.com') // true
35
+ */
8
36
  declare function isExternal(path: string): boolean;
37
+ /**
38
+ * Regular expression that matches the protocol scheme of a URL.
39
+ *
40
+ * Matches the leading protocol portion such as `http:`, `https:`, or
41
+ * `mailto:`. Does not match protocol-relative URLs (`//`).
42
+ *
43
+ * 匹配 URL 协议部分的正则表达式。
44
+ *
45
+ * 匹配前导协议部分,如 `http:`、`https:` 或 `mailto:`。
46
+ * 不匹配协议相对链接(`//`)。
47
+ *
48
+ * @example
49
+ * URL_PROTOCOL_RE.test('https://example.com') // true
50
+ * URL_PROTOCOL_RE.test('mailto:foo@example.com') // true
51
+ * URL_PROTOCOL_RE.test('//cdn.example.com/lib.js') // false
52
+ */
9
53
  declare const URL_PROTOCOL_RE: RegExp;
54
+ /**
55
+ * Checks whether the given link contains a URL protocol scheme or is a
56
+ * protocol-relative URL.
57
+ *
58
+ * Unlike {@link isExternal}, this function also matches links that start with
59
+ * `//` via an additional check, in addition to those matched by
60
+ * {@link URL_PROTOCOL_RE}.
61
+ *
62
+ * 判断给定链接是否包含 URL 协议部分或为协议相对链接。
63
+ *
64
+ * 与 {@link isExternal} 不同,此函数除了匹配 {@link URL_PROTOCOL_RE} 之外,
65
+ * 还会通过额外检查匹配以 `//` 开头的链接。
66
+ *
67
+ * @param link - The link to check / 要检查的链接
68
+ * @returns `true` if the link has a protocol or starts with `//` / 若链接包含协议或以 `//` 开头则返回 `true`
69
+ * @example
70
+ * isLinkWithProtocol('https://example.com') // true
71
+ * isLinkWithProtocol('mailto:foo@example.com') // true
72
+ * isLinkWithProtocol('//cdn.example.com/lib.js') // true
73
+ * isLinkWithProtocol('/about') // false
74
+ */
10
75
  declare function isLinkWithProtocol(link: string): boolean;
11
76
  //#endregion
12
77
  //#region src/shared/size.d.ts
13
78
  /**
14
- * Size Options
79
+ * Options for describing the size of an element.
80
+ *
81
+ * Used by plugins to normalize width, height, and aspect ratio inputs into a
82
+ * consistent CSS-friendly form.
83
+ *
84
+ * 描述元素尺寸的选项。
85
+ *
86
+ * 供插件使用,将宽度、高度和宽高比输入归一化为一致的 CSS 友好形式。
15
87
  *
16
- * 尺寸选项
88
+ * @example
89
+ * const options: SizeOptions = {
90
+ * width: '100%',
91
+ * ratio: 16 / 9,
92
+ * }
17
93
  */
18
94
  interface SizeOptions {
19
95
  /**
20
- * Width
96
+ * Width of the element, expressed as a CSS value.
97
+ *
98
+ * 元素的宽度,以 CSS 值表示。
21
99
  *
22
- * 宽度
100
+ * @example
101
+ * '100%' | '640px' | 'auto'
23
102
  */
24
103
  width?: string;
25
104
  /**
26
- * Height
105
+ * Height of the element, expressed as a CSS value.
106
+ *
107
+ * 元素的高度,以 CSS 值表示。
27
108
  *
28
- * 高度
109
+ * @example
110
+ * '100%' | '360px' | 'auto'
29
111
  */
30
112
  height?: string;
31
113
  /**
32
- * Aspect ratio
114
+ * Aspect ratio of the element. Can be:
115
+ * - `number`: Numeric ratio (for example `16 / 9` represents 16:9)
116
+ * - `string`: CSS aspect-ratio value (for example `'16 / 9'` or `'1.77'`)
33
117
  *
34
- * 宽高比
118
+ * 元素的宽高比。可以是:
119
+ * - `number`:数字比例(例如 `16 / 9` 表示 16:9)
120
+ * - `string`:CSS aspect-ratio 值(例如 `'16 / 9'` 或 `'1.77'`)
121
+ *
122
+ * @example
123
+ * 16 / 9
124
+ * '16 / 9'
35
125
  */
36
126
  ratio?: number | string;
37
127
  }
@@ -72,6 +162,13 @@ interface ContainerOptions {
72
162
  * @param options - Optional before/after render hooks / 可选的 before/after 渲染钩子
73
163
  * @param options.before - Callback for rendering container opening tag / 渲染容器起始标签时的回调函数
74
164
  * @param options.after - Callback for rendering container closing tag / 渲染容器结束标签时的回调函数
165
+ * @example
166
+ * ```ts
167
+ * md.use(createContainerPlugin, 'tip', {
168
+ * before: info => `<div class="tip">${info}`,
169
+ * after: () => '</div>',
170
+ * })
171
+ * ```
75
172
  */
76
173
  declare function createContainerPlugin(md: MarkdownIt, type: string, {
77
174
  before,
@@ -122,43 +219,25 @@ interface EmbedRuleBlockOptions<Meta extends Record<string, any>> {
122
219
  */
123
220
  name?: string;
124
221
  /**
125
- * Name of the rule to insert before
126
- *
127
- * 要插入在其前面的规则名称
128
- */
129
- beforeName?: string;
130
- /**
131
- * Syntax pattern regular expression
222
+ * Parse the `info` and `source` in `@[type info](source)` and convert them into a metadata object.
132
223
  *
133
- * 语法模式正则表达式
134
- */
135
- syntaxPattern: RegExp;
136
- /**
137
- * Rule options
138
- *
139
- * 规则选项
140
- */
141
- ruleOptions?: RuleOptions;
142
- /**
143
- * Extract metadata from match
224
+ * 解析 `@[type info](source)` 中的 `info` 和 `source`,转换为元数据对象
144
225
  *
145
- * 从匹配中提取元数据
146
- *
147
- * @param match - RegExp match array / 正则表达式匹配数组
226
+ * @param info - Information / 信息
227
+ * @param source - Source / 来源
148
228
  * @returns Metadata object / 元数据对象
149
229
  */
150
- meta: (match: RegExpMatchArray) => Meta;
230
+ meta: (info: string, source: string) => Meta;
151
231
  /**
152
232
  * Generate content from metadata
153
233
  *
154
234
  * 从元数据生成内容
155
235
  *
156
236
  * @param meta - Metadata / 元数据
157
- * @param content - Original content / 原始内容
158
237
  * @param env - Markdown environment / Markdown 环境
159
238
  * @returns Generated content / 生成的内容
160
239
  */
161
- content: (meta: Meta, content: string, env: MarkdownEnv) => string;
240
+ content?: (meta: Meta, env: MarkdownEnv) => string;
162
241
  }
163
242
  /**
164
243
  * Create embed rule block
@@ -172,38 +251,118 @@ interface EmbedRuleBlockOptions<Meta extends Record<string, any>> {
172
251
  * @param md - Markdown instance / Markdown 实例
173
252
  * @param {EmbedRuleBlockOptions} options - Embed rule block options / 嵌入规则块选项
174
253
  * @typeParam Meta - Metadata type / 元数据类型
254
+ * @example
255
+ * ```ts
256
+ * createEmbedRuleBlock(md, {
257
+ * type: 'video',
258
+ * meta: (info, source) => ({ src: source, title: info }),
259
+ * content: meta => `<video src="${meta.src}" title="${meta.title}"></video>`,
260
+ * })
261
+ * ```
175
262
  */
176
263
  declare function createEmbedRuleBlock<Meta extends Record<string, any> = Record<string, any>>(md: MarkdownIt, {
177
264
  type,
178
265
  name,
179
- syntaxPattern,
180
- beforeName,
181
- ruleOptions,
182
266
  meta,
183
267
  content
184
268
  }: EmbedRuleBlockOptions<Meta>): void;
185
269
  //#endregion
186
270
  //#region src/node/utils/constants.d.ts
271
+ /**
272
+ * Whether the current process is running in production build mode.
273
+ *
274
+ * 当前进程是否运行在生产构建模式下。
275
+ */
187
276
  declare const isBuild: boolean;
277
+ /**
278
+ * Whether the current process is running in development mode.
279
+ *
280
+ * 当前进程是否运行在开发模式下。
281
+ */
188
282
  declare const isDev: boolean;
189
283
  /**
190
- * 浏览器支持的视频文件名扩展名
284
+ * Browser-supported video file name extensions.
285
+ *
286
+ * 浏览器支持的视频文件名扩展名。
191
287
  */
192
288
  declare const EXTENSION_VIDEOS: string[];
193
289
  /**
194
- * 浏览器支持的图片文件名扩展名
290
+ * Browser-supported image file name extensions.
291
+ *
292
+ * 浏览器支持的图片文件名扩展名。
195
293
  */
196
294
  declare const EXTENSION_IMAGES: string[];
197
295
  /**
198
- * 浏览器支持的音频文件名扩展名
296
+ * Browser-supported audio file name extensions.
297
+ *
298
+ * 浏览器支持的音频文件名扩展名。
199
299
  */
200
300
  declare const EXTENSION_AUDIOS: string[];
201
301
  //#endregion
302
+ //#region src/node/utils/createMatcher.d.ts
303
+ /**
304
+ * Create a matcher for the given include and exclude patterns.
305
+ *
306
+ * 创建一个用于给定 include 和 exclude 模式的匹配器。
307
+ *
308
+ * @param include - Patterns to include, can be string or array / 要包含的模式,可以是字符串或数组
309
+ * @param exclude - Patterns to exclude, can be string or array / 要排除的模式,可以是字符串或数组
310
+ * @returns Matcher instance / 匹配器实例
311
+ */
312
+ declare function createMatcher(include?: string | string[], exclude?: string | string[]): Matcher | undefined;
313
+ /**
314
+ * Resolve include and exclude patterns into pattern and ignore arrays.
315
+ * Converts various pattern formats into a standardized format for matching.
316
+ *
317
+ * 将 include 和 exclude 模式解析为 pattern 和 ignore 数组。
318
+ * 将各种模式格式转换为用于匹配的标准化格式。
319
+ *
320
+ * @param include - Patterns to include, can be string or array / 要包含的模式,可以是字符串或数组
321
+ * @param exclude - Patterns to exclude, can be string or array / 要排除的模式,可以是字符串或数组
322
+ * @returns Object containing pattern and ignore arrays / 包含 pattern 和 ignore 数组的对象
323
+ */
324
+ declare function resolveMatcherPattern(include?: string | string[], exclude?: string | string[]): {
325
+ pattern: string[];
326
+ ignore: string[];
327
+ };
328
+ //#endregion
202
329
  //#region src/node/utils/hash.d.ts
330
+ /**
331
+ * Generate a SHA-256 hash from the given data.
332
+ *
333
+ * 根据给定数据生成 SHA-256 哈希值。
334
+ *
335
+ * Primitive values are converted to strings directly, while objects are serialized
336
+ * to JSON before hashing. When `length` is provided, the hash is truncated to the
337
+ * specified length.
338
+ *
339
+ * 基本类型直接转为字符串,对象则序列化为 JSON 后再哈希。提供 `length` 时,
340
+ * 哈希值会被截断到指定长度。
341
+ *
342
+ * @param data - The data to hash, can be any value / 要哈希的数据,可以是任意值
343
+ * @param length - Optional length to truncate the hash / 可选的哈希值截断长度
344
+ * @returns The SHA-256 hash string (truncated if length is given)
345
+ * / SHA-256 哈希字符串(指定长度时会被截断)
346
+ * @example
347
+ * ```ts
348
+ * genHash('hello') // full sha256 hash
349
+ * genHash({ a: 1 }, 8) // 8-character hash
350
+ * ```
351
+ */
203
352
  declare function genHash(data: unknown, length?: number): string;
204
353
  //#endregion
205
354
  //#region src/node/utils/logger.d.ts
355
+ /**
356
+ * Log type for categorizing log messages.
357
+ *
358
+ * 用于分类日志消息的日志类型。
359
+ */
206
360
  type LogType = 'info' | 'warn' | 'error' | 'debug';
361
+ /**
362
+ * Log level controlling the verbosity of the logger.
363
+ *
364
+ * 控制日志输出详细程度的日志级别。
365
+ */
207
366
  type LogLevel = LogType | 'silent';
208
367
  /**
209
368
  * Logger interface
@@ -250,6 +409,13 @@ declare const logLevels: Record<LogLevel, number>;
250
409
  * @param prefix - Log prefix / 日志前缀
251
410
  * @param defaultLevel - Default log level / 默认日志级别
252
411
  * @returns Logger instance / 日志实例
412
+ * @example
413
+ * ```ts
414
+ * const logger = createLogger('my-plugin', 'info')
415
+ * logger.info('Starting build')
416
+ * logger.warn('Deprecated feature used')
417
+ * logger.debug('Verbose details', 'debug')
418
+ * ```
253
419
  */
254
420
  declare function createLogger(prefix: string, defaultLevel?: LogLevel): Logger;
255
421
  //#endregion
@@ -262,6 +428,12 @@ declare function createLogger(prefix: string, defaultLevel?: LogLevel): Logger;
262
428
  * @param str - Size string / 尺寸字符串
263
429
  * @param unit - Unit to append (default: 'px') / 要添加的单位(默认:'px')
264
430
  * @returns Size string with unit / 带单位的尺寸字符串
431
+ * @example
432
+ * ```ts
433
+ * parseRect('100') // '100px'
434
+ * parseRect('50%') // '50%'
435
+ * parseRect('200', 'rpx') // '200rpx'
436
+ * ```
265
437
  */
266
438
  declare function parseRect(str: string, unit?: string): string;
267
439
  //#endregion
@@ -274,6 +446,13 @@ declare function parseRect(str: string, unit?: string): string;
274
446
  * @param info - Attribute string / 属性字符串
275
447
  * @returns Object with attrs and rawAttrs / 包含 attrs 和 rawAttrs 的对象
276
448
  * @typeParam T - Attribute type / 属性类型
449
+ * @example
450
+ * ```ts
451
+ * resolveAttrs('width="100" height="50"')
452
+ * // { width: '100', height: '50' }
453
+ * resolveAttrs('disabled title="Hello"')
454
+ * // { disabled: true, title: 'Hello' }
455
+ * ```
277
456
  */
278
457
  declare function resolveAttrs<T extends Record<string, any> = Record<string, any>>(info: string): T;
279
458
  /**
@@ -284,12 +463,35 @@ declare function resolveAttrs<T extends Record<string, any> = Record<string, any
284
463
  * @param info - Info string / 信息字符串
285
464
  * @param key - Attribute key / 属性键
286
465
  * @returns Attribute value or undefined / 属性值或 undefined
466
+ * @example
467
+ * ```ts
468
+ * resolveAttr('width="100" height="50"', 'width') // '100'
469
+ * resolveAttr('width="100" height="50"', 'color') // undefined
470
+ * ```
287
471
  */
288
472
  declare function resolveAttr(info: string, key: string): string | undefined;
289
473
  //#endregion
290
474
  //#region src/node/utils/slugify.d.ts
291
475
  /**
292
- * Default slugification function
476
+ * Default slugification function that normalizes a string into a URL-safe slug.
477
+ *
478
+ * 默认的 slug 化函数,将字符串规范化为 URL 安全的 slug。
479
+ *
480
+ * The function removes accents, control characters, and special characters,
481
+ * replaces separators with hyphens, and ensures the result does not start
482
+ * with a number.
483
+ *
484
+ * 该函数会移除重音符号、控制字符和特殊字符,用连字符替换分隔符,
485
+ * 并确保结果不以数字开头。
486
+ *
487
+ * @param str - The string to slugify / 要 slug 化的字符串
488
+ * @returns The slugified string / slug 化后的字符串
489
+ * @example
490
+ * ```ts
491
+ * slugify('Hello World!') // 'hello-world'
492
+ * slugify('你好 World') // '你好-world'
493
+ * slugify('1st Section') // '_1st-section'
494
+ * ```
293
495
  */
294
496
  declare function slugify(str: string): string;
295
497
  //#endregion
@@ -304,41 +506,214 @@ declare function slugify(str: string): string;
304
506
  * @param forceStringify - Keys to force stringify / 强制字符串化的键
305
507
  * @returns HTML attribute string / HTML 属性字符串
306
508
  * @typeParam T - Attribute type / 属性类型
509
+ * @example
510
+ * ```ts
511
+ * stringifyAttrs({ width: 100, disabled: true })
512
+ * // ' :width="100" disabled'
513
+ * stringifyAttrs({ title: 'hello', visible: false })
514
+ * // ' title="hello"'
515
+ * ```
307
516
  */
308
517
  declare function stringifyAttrs<T extends object = object>(attrs: T, withUndefinedOrNull?: boolean, forceStringify?: (keyof T)[]): string;
309
518
  //#endregion
310
519
  //#region src/node/utils/treat-as-html.d.ts
520
+ /**
521
+ * Determine whether a file should be treated as an HTML route based on its extension.
522
+ *
523
+ * 根据文件扩展名判断该文件是否应作为 HTML 路由处理。
524
+ *
525
+ * Returns `true` when the file has no extension or its extension is not in the
526
+ * known extensions list (meaning it should be served as an HTML page). Returns
527
+ * `false` for known static asset extensions.
528
+ *
529
+ * 当文件没有扩展名或其扩展名不在已知扩展名列表中时返回 `true`(表示应作为
530
+ * HTML 页面提供)。对于已知的静态资源扩展名返回 `false`。
531
+ *
532
+ * @param filename - The filename to check / 要检查的文件名
533
+ * @returns `true` if the file should be treated as HTML, `false` otherwise
534
+ * / 如果文件应作为 HTML 处理则返回 `true`,否则返回 `false`
535
+ * @example
536
+ * ```ts
537
+ * treatAsHtml('about') // true (no extension)
538
+ * treatAsHtml('logo.png') // false (known image extension)
539
+ * treatAsHtml('custom.xyz') // true (unknown extension)
540
+ * ```
541
+ */
311
542
  declare function treatAsHtml(filename: string): boolean;
312
543
  //#endregion
313
544
  //#region src/node/vite-plugins/iconPlugin.d.ts
545
+ /**
546
+ * Represents an SVG icon definition with optional classname.
547
+ *
548
+ * 表示一个 SVG 图标定义,包含可选的类名。
549
+ */
314
550
  interface Icon {
551
+ /**
552
+ * Icon name used as the CSS class identifier.
553
+ *
554
+ * 用作 CSS 类标识的图标名称。
555
+ */
315
556
  name: string;
557
+ /**
558
+ * SVG content for the icon.
559
+ *
560
+ * 图标的 SVG 内容。
561
+ */
316
562
  svg: string;
563
+ /**
564
+ * Optional classname override for the icon.
565
+ *
566
+ * 图标的可选类名覆盖。
567
+ */
317
568
  classname?: string;
318
569
  }
570
+ /**
571
+ * Create a Vite plugin that registers SVG icons as CSS custom properties.
572
+ *
573
+ * 创建一个 Vite 插件,将 SVG 图标注册为 CSS 自定义属性。
574
+ *
575
+ * The plugin collects icons into a global list and exposes them through a
576
+ * virtual module `virtual:tuck-icons.css`. Each icon is rendered as a CSS
577
+ * rule that sets the `--icon` custom property on `.vpi-<name>` selectors.
578
+ *
579
+ * 该插件将图标收集到全局列表中,并通过虚拟模块 `virtual:tuck-icons.css`
580
+ * 暴露它们。每个图标被渲染为一条 CSS 规则,在 `.vpi-<name>` 选择器上
581
+ * 设置 `--icon` 自定义属性。
582
+ *
583
+ * @param icons - Array of icon definitions to register / 要注册的图标定义数组
584
+ * @returns A Vite plugin instance / Vite 插件实例
585
+ * @example
586
+ * ```ts
587
+ * import { iconPlugin } from 'vitepress-plugin-toolkit/node'
588
+ * icons: iconPlugin([
589
+ * { name: 'github', svg: '<svg>...</svg>' },
590
+ * { name: 'twitter', svg: '<svg>...</svg>' },
591
+ * ])
592
+ * ```
593
+ */
319
594
  declare function iconPlugin(icons: Icon[]): Plugin;
320
595
  //#endregion
321
596
  //#region src/node/vitepress/createLocales.d.ts
597
+ /**
598
+ * A builtin locale entry pairing language codes with their locale data.
599
+ *
600
+ * 内置语言环境条目,将语言代码与对应的语言环境数据配对。
601
+ *
602
+ * @typeParam LocaleData - Locale data type / 语言环境数据类型
603
+ */
322
604
  type BuiltinLocale<LocaleData extends Record<string, unknown>> = [langCodes: string[], localeData: LocaleData];
605
+ /**
606
+ * A list of builtin locale entries.
607
+ *
608
+ * 内置语言环境条目列表。
609
+ *
610
+ * @typeParam LocaleData - Locale data type / 语言环境数据类型
611
+ */
323
612
  type BuiltinLocales<LocaleData extends Record<string, unknown>> = BuiltinLocale<LocaleData>[];
324
613
  /**
325
- * 创建 locales
326
- * @param builtinLocales 内置的 locales
327
- * @param userLocales 用户的 locales
328
- * @returns locales
614
+ * Create a locales configuration by merging builtin locales with user locales.
615
+ *
616
+ * 通过合并内置语言环境与用户语言环境来创建语言环境配置。
617
+ *
618
+ * The function reads the VitePress locales config, matches each locale key
619
+ * (or its `lang` field) against the builtin locales, and falls back to the
620
+ * first builtin locale for the `root` entry when no match is found. User
621
+ * locales are deep-merged on top of the result.
622
+ *
623
+ * 该函数读取 VitePress 的语言环境配置,将每个语言环境键(或其 `lang` 字段)
624
+ * 与内置语言环境匹配,未匹配到时 `root` 条目回退到第一个内置语言环境。
625
+ * 用户语言环境会深度合并到结果之上。
626
+ *
627
+ * @param builtinLocales - Builtin locale entries / 内置语言环境条目
628
+ * @param userLocales - User-provided locale overrides / 用户提供的语言环境覆盖
629
+ * @returns Merged locales configuration / 合并后的语言环境配置
630
+ * @typeParam LocaleData - Locale data type / 语言环境数据类型
631
+ * @example
632
+ * ```ts
633
+ * const locales = createLocales(
634
+ * [[['en', 'en-US'], { title: 'English' }], [['zh', 'zh-CN'], { title: '中文' }]],
635
+ * { zh: { title: '我的站点' } },
636
+ * )
637
+ * ```
329
638
  */
330
639
  declare function createLocales<LocaleData extends Record<string, unknown>>(builtinLocales: BuiltinLocales<LocaleData>, userLocales?: Record<string, LocaleData>): Record<string, LocaleData>;
331
640
  //#endregion
332
641
  //#region src/node/vitepress/get-locale-with-path.d.ts
642
+ /**
643
+ * Resolve the locale and language code for a given path.
644
+ *
645
+ * 解析给定路径对应的语言环境和语言代码。
646
+ *
647
+ * The function inspects the VitePress locales config and finds the locale key
648
+ * that the provided path starts with. When the matched key is `root`, the
649
+ * returned locale is an empty string. Returns empty strings for both fields
650
+ * when no locale matches.
651
+ *
652
+ * 该函数检查 VitePress 的语言环境配置,找到所提供路径以其开头的语言环境键。
653
+ * 当匹配的键为 `root` 时,返回的语言环境为空字符串。无匹配时两个字段均返回空字符串。
654
+ *
655
+ * @param path - The path to resolve / 要解析的路径
656
+ * @returns An object with `lang` and `locale` fields / 包含 `lang` 和 `locale` 字段的对象
657
+ * @example
658
+ * ```ts
659
+ * getLocaleWithPath('/zh/guide/') // { lang: 'zh-CN', locale: '/zh/' }
660
+ * getLocaleWithPath('/guide/') // { lang: 'en', locale: '' } (root locale)
661
+ * ```
662
+ */
333
663
  declare function getLocaleWithPath(path: string): {
334
664
  lang: string;
335
665
  locale: string;
336
666
  };
337
667
  //#endregion
338
668
  //#region src/node/vitepress/get-vitepress-config.d.ts
669
+ /**
670
+ * Get the current VitePress site configuration from the global context.
671
+ *
672
+ * 从全局上下文获取当前的 VitePress 站点配置。
673
+ *
674
+ * VitePress stores its resolved `SiteConfig` on `globalThis.VITEPRESS_CONFIG`
675
+ * during the build and dev lifecycle. This helper reads that value and throws
676
+ * when it has not been initialized yet.
677
+ *
678
+ * VitePress 在构建和开发生命周期中将解析后的 `SiteConfig` 存储在
679
+ * `globalThis.VITEPRESS_CONFIG` 上。该辅助函数读取该值,未初始化时抛出错误。
680
+ *
681
+ * @returns The current VitePress site config / 当前的 VitePress 站点配置
682
+ * @throws {Error} When VITEPRESS_CONFIG is not initialized / VITEPRESS_CONFIG 未初始化时
683
+ * @example
684
+ * ```ts
685
+ * const config = getVitepressConfig()
686
+ * console.log(config.userConfig.title)
687
+ * ```
688
+ */
339
689
  declare function getVitepressConfig(): SiteConfig;
340
690
  //#endregion
341
691
  //#region src/node/vitepress/resolve-route-link.d.ts
692
+ /**
693
+ * Resolve a markdown link to its final URL form based on VitePress routing rules.
694
+ *
695
+ * 根据 VitePress 路由规则将 markdown 链接解析为最终 URL 形式。
696
+ *
697
+ * External links are returned as-is. Absolute paths are prefixed with the
698
+ * site base. Hash links are slugified. Relative links to markdown files are
699
+ * transformed according to the `cleanUrls` setting (`.md` becomes `''` or
700
+ * `.html`), and `index.md` is collapsed to its directory.
701
+ *
702
+ * 外部链接原样返回。绝对路径添加站点 base 前缀。哈希链接进行 slug 化。
703
+ * 指向 markdown 文件的相对链接根据 `cleanUrls` 设置转换(`.md` 变为 `''`
704
+ * 或 `.html`),`index.md` 折叠为其所在目录。
705
+ *
706
+ * @param url - The raw URL from markdown content / markdown 内容中的原始 URL
707
+ * @param env - The markdown environment with routing context / 带路由上下文的 markdown 环境
708
+ * @returns The resolved URL / 解析后的 URL
709
+ * @example
710
+ * ```ts
711
+ * resolveRouteLink('./guide.md', { cleanUrls: false } as MarkdownEnv)
712
+ * // './guide.html'
713
+ * resolveRouteLink('/about/', {} as MarkdownEnv)
714
+ * // '/base/about/'
715
+ * ```
716
+ */
342
717
  declare function resolveRouteLink(url: string, env: MarkdownEnv): string;
343
718
  //#endregion
344
- export { BuiltinLocale, BuiltinLocales, ContainerOptions, EXTENSION_AUDIOS, EXTENSION_IMAGES, EXTENSION_VIDEOS, EXTERNAL_URL_RE, EmbedRuleBlockOptions, LogLevel, LogType, Logger, SizeOptions, URL_PROTOCOL_RE, createContainerPlugin, createContainerSyntaxPlugin, createEmbedRuleBlock, createLocales, createLogger, genHash, getLocaleWithPath, getVitepressConfig, iconPlugin, isBuild, isDev, isExternal, isLinkWithProtocol, logLevels, parseRect, resolveAttr, resolveAttrs, resolveRouteLink, slugify, stringifyAttrs, treatAsHtml };
719
+ export { BuiltinLocale, BuiltinLocales, ContainerOptions, EXTENSION_AUDIOS, EXTENSION_IMAGES, EXTENSION_VIDEOS, EXTERNAL_URL_RE, EmbedRuleBlockOptions, LogLevel, LogType, Logger, SizeOptions, URL_PROTOCOL_RE, createContainerPlugin, createContainerSyntaxPlugin, createEmbedRuleBlock, createLocales, createLogger, createMatcher, genHash, getLocaleWithPath, getVitepressConfig, iconPlugin, isBuild, isDev, isExternal, isLinkWithProtocol, logLevels, parseRect, resolveAttr, resolveAttrs, resolveMatcherPattern, resolveRouteLink, slugify, stringifyAttrs, treatAsHtml };