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.
@@ -2,21 +2,97 @@ import { computed, defineComponent, isRef, mergeModels, mergeProps, nextTick, on
2
2
  import { ssrInterpolate, ssrRenderAttrs, ssrRenderClass, ssrRenderList } from "vue/server-renderer";
3
3
  import { useClipboard, useEventListener, useMediaQuery, useMutationObserver } from "@vueuse/core";
4
4
  //#region src/shared/link.ts
5
+ /**
6
+ * Regular expression that matches external URLs.
7
+ *
8
+ * Matches URLs that start with a protocol (such as `http:` or `mailto:`) or
9
+ * with `//` (protocol-relative URLs).
10
+ *
11
+ * 匹配外部链接的正则表达式。
12
+ *
13
+ * 匹配以协议(如 `http:` 或 `mailto:`)或 `//`(协议相对链接)开头的 URL。
14
+ *
15
+ * @example
16
+ * EXTERNAL_URL_RE.test('https://example.com') // true
17
+ * EXTERNAL_URL_RE.test('//cdn.example.com/lib.js') // true
18
+ * EXTERNAL_URL_RE.test('/about') // false
19
+ */
5
20
  const EXTERNAL_URL_RE = /^(?:[a-z]+:|\/\/)/i;
21
+ /**
22
+ * Checks whether the given path is an external URL.
23
+ *
24
+ * 判断给定路径是否为外部链接。
25
+ *
26
+ * @param path - The path to check / 要检查的路径
27
+ * @returns `true` if the path is an external URL, otherwise `false` / 若为外部链接返回 `true`,否则返回 `false`
28
+ * @example
29
+ * isExternal('https://example.com') // true
30
+ * isExternal('//cdn.example.com/lib.js') // true
31
+ * isExternal('/about') // false
32
+ * isExternal('mailto:foo@example.com') // true
33
+ */
6
34
  function isExternal(path) {
7
35
  return EXTERNAL_URL_RE.test(path);
8
36
  }
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
  const URL_PROTOCOL_RE = /^[a-z][a-z0-9+.-]*:/;
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
  function isLinkWithProtocol(link) {
11
76
  return URL_PROTOCOL_RE.test(link) || link.startsWith("//");
12
77
  }
13
78
  //#endregion
14
79
  //#region src/client/components/VPCopyButton.vue
80
+ /** Text to copy to the clipboard / 要复制到剪贴板的文本 */
15
81
  const _sfc_main = /*@__PURE__*/ defineComponent({
16
82
  __name: "VPCopyButton",
17
83
  __ssrInlineRender: true,
18
84
  props: { text: {} },
19
85
  setup(__props) {
86
+ /**
87
+ * A button component that copies the given text to the clipboard.
88
+ *
89
+ * 复制指定文本到剪贴板的按钮组件。
90
+ *
91
+ * @example
92
+ * ```vue
93
+ * <VPCopyButton text="Hello, world!" />
94
+ * ```
95
+ */
20
96
  const { copied, copy } = useClipboard();
21
97
  return (_ctx, _push, _parent, _attrs) => {
22
98
  _push(`<button${ssrRenderAttrs(mergeProps({
@@ -43,6 +119,18 @@ const _sfc_main$1 = /*@__PURE__*/ defineComponent({
43
119
  height: {}
44
120
  },
45
121
  setup(__props) {
122
+ /**
123
+ * A loading indicator component with an animated SVG spinner.
124
+ *
125
+ * 带有 SVG 动画旋转图标的加载指示器组件。
126
+ *
127
+ * @example
128
+ * ```vue
129
+ * <VPLoading />
130
+ *
131
+ * <VPLoading absolute height="200px" />
132
+ * ```
133
+ */
46
134
  return (_ctx, _push, _parent, _attrs) => {
47
135
  _push(`<div${ssrRenderAttrs(mergeProps({
48
136
  class: ["vp-loading", { absolute: __props.absolute }],
@@ -59,6 +147,7 @@ _sfc_main$1.setup = (props, ctx) => {
59
147
  };
60
148
  //#endregion
61
149
  //#region src/client/components/VPTabSwitch.vue
150
+ /** List of tab items to render / 要渲染的标签项列表 */
62
151
  const _sfc_main$2 = /*@__PURE__*/ defineComponent({
63
152
  __name: "VPTabSwitch",
64
153
  __ssrInlineRender: true,
@@ -68,6 +157,7 @@ const _sfc_main$2 = /*@__PURE__*/ defineComponent({
68
157
  }),
69
158
  emits: /*@__PURE__*/ mergeModels(["update"], ["update:modelValue"]),
70
159
  setup(__props, { emit: __emit }) {
160
+ /** Current active tab value (v-model) / 当前活动标签的值(v-model) */
71
161
  const tab = useModel(__props, "modelValue");
72
162
  watch(() => __props.items, () => {
73
163
  tab.value = __props.items[0].value;
@@ -89,6 +179,23 @@ _sfc_main$2.setup = (props, ctx) => {
89
179
  };
90
180
  //#endregion
91
181
  //#region src/client/composables/use-size.ts
182
+ /**
183
+ * Composable that provides reactive size tracking for an element based on width,
184
+ * height, and aspect ratio options.
185
+ *
186
+ * 基于宽度、高度和宽高比选项为元素提供响应式尺寸追踪的组合式函数。
187
+ *
188
+ * @template T - HTMLElement type of the target element / 目标元素的 HTMLElement 类型
189
+ * @param el - Template ref to the target element / 目标元素的模板 ref
190
+ * @param options - Reactive size options (width, height, ratio) / 响应式尺寸选项(width、height、ratio)
191
+ * @param extraHeight - Extra height in pixels to add to the computed height / 要加到计算高度上的额外像素高度
192
+ * @returns Reactive size info with width, height, and a resize function / 包含 width、height 和 resize 函数的响应式尺寸信息
193
+ * @example
194
+ * ```ts
195
+ * const el = ref<HTMLElement>()
196
+ * const { width, height, resize } = useSize(el, toRefs({ width: '100%', ratio: '16:9' }))
197
+ * ```
198
+ */
92
199
  function useSize(el, options, extraHeight = 0) {
93
200
  const width = computed(() => toValue(options.width) || "100%");
94
201
  const height = ref("auto");
@@ -112,6 +219,27 @@ function useSize(el, options, extraHeight = 0) {
112
219
  resize
113
220
  };
114
221
  }
222
+ /**
223
+ * Parse a ratio value into a numeric width-to-height ratio.
224
+ *
225
+ * 将宽高比值解析为数值形式的宽高比。
226
+ *
227
+ * Accepts a number, a string like `"16:9"`, or `undefined` (defaults to 16:9).
228
+ *
229
+ * 接受数字、形如 `"16:9"` 的字符串或 `undefined`(默认为 16:9)。
230
+ *
231
+ * @param ratio - Ratio value, can be:
232
+ * - `number`: Used directly as the ratio / 直接作为宽高比
233
+ * - `string`: Parsed from "width:height" format / 从 "width:height" 格式解析
234
+ * - `undefined`: Defaults to 16/9 / 默认为 16/9
235
+ * @returns Numeric width-to-height ratio / 数值形式的宽高比
236
+ * @example
237
+ * ```ts
238
+ * getRadio(2) // 2
239
+ * getRadio('16:9') // 1.777...
240
+ * getRadio(undefined) // 1.777...
241
+ * ```
242
+ */
115
243
  function getRadio(ratio) {
116
244
  if (typeof ratio === "string") {
117
245
  const [width, height] = ratio.split(":");
@@ -122,6 +250,26 @@ function getRadio(ratio) {
122
250
  }
123
251
  //#endregion
124
252
  //#region src/client/composables/use-zoom-and-drag.ts
253
+ /**
254
+ * Composable that provides zoom and drag interaction for a content stage,
255
+ * supporting mouse drag, touch drag, pinch-to-zoom, and programmatic zoom.
256
+ *
257
+ * 为内容舞台提供缩放和拖拽交互的组合式函数,支持鼠标拖拽、触摸拖拽、双指缩放和编程式缩放。
258
+ *
259
+ * @param parentEl - Template ref to the stage container element / 舞台容器元素的模板 ref
260
+ * @returns Interaction controls and reactive state, including:
261
+ * - `actorStyle`: Reactive style object for the actor element / actor 元素的响应式样式对象
262
+ * - `zoom`: Reactive zoom percentage string / 响应式缩放百分比字符串
263
+ * - `reset`: Reset layout to fit the stage / 重置布局以适配舞台
264
+ * - `zoomIn`: Zoom in by one step / 放大一个步长
265
+ * - `zoomOut`: Zoom out by one step / 缩小一个步长
266
+ * - `resetZoom`: Reset zoom to the initial state / 重置缩放至初始状态
267
+ * @example
268
+ * ```ts
269
+ * const stageEl = ref<HTMLDivElement>()
270
+ * const { actorStyle, zoom, zoomIn, zoomOut, resetZoom, reset } = useZoomAndDrag(stageEl)
271
+ * ```
272
+ */
125
273
  function useZoomAndDrag(parentEl) {
126
274
  const actorEl = shallowRef();
127
275
  let ratio = 0;
@@ -143,6 +291,14 @@ function useZoomAndDrag(parentEl) {
143
291
  attributes: false
144
292
  });
145
293
  onMounted(() => nextTick(initialize));
294
+ /**
295
+ * Initialize the actor layout by measuring content size and computing the
296
+ * initial zoom, position, and stage height to fit the available space.
297
+ *
298
+ * 通过测量内容尺寸并计算初始缩放、位置和舞台高度来初始化 actor 布局,以适配可用空间。
299
+ *
300
+ * @param isFullscreen - Whether the stage is in fullscreen mode / 舞台是否处于全屏模式
301
+ */
146
302
  function initialize(isFullscreen = false) {
147
303
  if (!parentEl.value) return;
148
304
  const actor = parentEl.value.querySelector(".content");
@@ -236,6 +392,16 @@ function useZoomAndDrag(parentEl) {
236
392
  useEventListener(parentEl, "touchend", () => {
237
393
  isDragging = false;
238
394
  }, { passive: false });
395
+ /**
396
+ * Adjust the zoom level by a fixed step, or reset to the initial state.
397
+ *
398
+ * 按固定步长调整缩放级别,或重置到初始状态。
399
+ *
400
+ * @param type - Zoom direction, can be:
401
+ * - `1`: Zoom in by one step / 放大一个步长
402
+ * - `-1`: Zoom out by one step / 缩小一个步长
403
+ * - `0`: Reset to the initial zoom and position / 重置到初始缩放和位置
404
+ */
239
405
  function zoom(type) {
240
406
  if (typeof width.value === "undefined" || !actorEl.value) return;
241
407
  if (type === 0) {
@@ -253,6 +419,12 @@ function useZoomAndDrag(parentEl) {
253
419
  }
254
420
  }
255
421
  let zoomTimer;
422
+ /**
423
+ * Temporarily add a `zooming` class to the actor element to enable CSS
424
+ * transitions during zoom, and remove it after the transition completes.
425
+ *
426
+ * 临时为 actor 元素添加 `zooming` 类以在缩放时启用 CSS 过渡,并在过渡结束后移除该类。
427
+ */
256
428
  function zooming() {
257
429
  actorEl.value?.classList.add("zooming");
258
430
  if (zoomTimer) clearTimeout(zoomTimer);
@@ -276,9 +448,24 @@ function useZoomAndDrag(parentEl) {
276
448
  }
277
449
  //#endregion
278
450
  //#region src/client/utils/env.ts
451
+ /**
452
+ * Get the platform string of the user device, preferring UA-CH data over the
453
+ * legacy `navigator.platform`.
454
+ *
455
+ * 获取用户设备的平台字符串,优先使用 UA-CH 数据,其次使用传统的 `navigator.platform`。
456
+ *
457
+ * @returns Platform string / 平台字符串
458
+ */
279
459
  function getPlatform() {
280
460
  return navigator.userAgentData?.platform ?? navigator.platform;
281
461
  }
462
+ /**
463
+ * Get the user agent string of the browser.
464
+ *
465
+ * 获取浏览器的 user agent 字符串。
466
+ *
467
+ * @returns User agent string / user agent 字符串
468
+ */
282
469
  const getUA = () => navigator.userAgent;
283
470
  /**
284
471
  * Check if the user device is iPhone or iPod.