vitepress-plugin-caniuse 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,16 +2,21 @@ import { EnhanceAppContext } from "vitepress/client";
|
|
|
2
2
|
|
|
3
3
|
//#region src/client/VPCaniuse.vue.d.ts
|
|
4
4
|
type __VLS_Props = {
|
|
5
|
-
feature: string;
|
|
6
|
-
past?: number;
|
|
7
|
-
future?: number;
|
|
8
|
-
meta?: string;
|
|
5
|
+
/** Feature identifier to look up on Can I Use / 要在 Can I Use 上查询的特性标识符 */feature: string; /** Number of past browser versions to display / 要显示的过去浏览器版本数量 */
|
|
6
|
+
past?: number; /** Number of future browser versions to display / 要显示的未来浏览器版本数量 */
|
|
7
|
+
future?: number; /** Unique metadata key matching iframe messages / 匹配 iframe 消息的唯一元数据键 */
|
|
8
|
+
meta?: string; /** Whether to render the Baseline view / 是否渲染 Baseline 视图 */
|
|
9
9
|
baseline?: boolean;
|
|
10
10
|
};
|
|
11
11
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
12
|
declare const _default: typeof __VLS_export;
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/client/index.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Enhances the VitePress application by registering the `VPCaniuse` component.
|
|
17
|
+
*
|
|
18
|
+
* 通过注册 `VPCaniuse` 组件来增强 VitePress 应用。
|
|
19
|
+
*/
|
|
15
20
|
declare function enhanceAppWithCaniuse({
|
|
16
21
|
app
|
|
17
22
|
}: EnhanceAppContext): void;
|
|
@@ -27,6 +27,14 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
27
27
|
const { type, payload } = parseData(event.data);
|
|
28
28
|
if (type === "ciu-embed" && payload && payload.feature === __props.feature && payload.meta === __props.meta) height.value = `${Math.ceil(payload.height)}px`;
|
|
29
29
|
});
|
|
30
|
+
/**
|
|
31
|
+
* Parses incoming message data, handling both string and object payloads.
|
|
32
|
+
*
|
|
33
|
+
* 解析传入的消息数据,支持字符串和对象两种载荷格式。
|
|
34
|
+
*
|
|
35
|
+
* @param data - Raw message data from the iframe / 来自 iframe 的原始消息数据
|
|
36
|
+
* @returns Parsed message data object / 解析后的消息数据对象
|
|
37
|
+
*/
|
|
30
38
|
function parseData(data) {
|
|
31
39
|
if (typeof data === "string") try {
|
|
32
40
|
return JSON.parse(data);
|
|
@@ -46,6 +54,11 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
46
54
|
});
|
|
47
55
|
//#endregion
|
|
48
56
|
//#region src/client/index.ts
|
|
57
|
+
/**
|
|
58
|
+
* Enhances the VitePress application by registering the `VPCaniuse` component.
|
|
59
|
+
*
|
|
60
|
+
* 通过注册 `VPCaniuse` 组件来增强 VitePress 应用。
|
|
61
|
+
*/
|
|
49
62
|
function enhanceAppWithCaniuse({ app }) {
|
|
50
63
|
app.component("VPCaniuse", _sfc_main);
|
|
51
64
|
}
|
|
@@ -2,16 +2,21 @@ import { EnhanceAppContext } from "vitepress/client";
|
|
|
2
2
|
|
|
3
3
|
//#region src/client/VPCaniuse.vue.d.ts
|
|
4
4
|
type __VLS_Props = {
|
|
5
|
-
feature: string;
|
|
6
|
-
past?: number;
|
|
7
|
-
future?: number;
|
|
8
|
-
meta?: string;
|
|
5
|
+
/** Feature identifier to look up on Can I Use / 要在 Can I Use 上查询的特性标识符 */feature: string; /** Number of past browser versions to display / 要显示的过去浏览器版本数量 */
|
|
6
|
+
past?: number; /** Number of future browser versions to display / 要显示的未来浏览器版本数量 */
|
|
7
|
+
future?: number; /** Unique metadata key matching iframe messages / 匹配 iframe 消息的唯一元数据键 */
|
|
8
|
+
meta?: string; /** Whether to render the Baseline view / 是否渲染 Baseline 视图 */
|
|
9
9
|
baseline?: boolean;
|
|
10
10
|
};
|
|
11
11
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
12
12
|
declare const _default: typeof __VLS_export;
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/client/index.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Enhances the VitePress application by registering the `VPCaniuse` component.
|
|
17
|
+
*
|
|
18
|
+
* 通过注册 `VPCaniuse` 组件来增强 VitePress 应用。
|
|
19
|
+
*/
|
|
15
20
|
declare function enhanceAppWithCaniuse({
|
|
16
21
|
app
|
|
17
22
|
}: EnhanceAppContext): void;
|
package/dist/client/ssr/index.js
CHANGED
|
@@ -27,6 +27,14 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
27
27
|
const { type, payload } = parseData(event.data);
|
|
28
28
|
if (type === "ciu-embed" && payload && payload.feature === __props.feature && payload.meta === __props.meta) height.value = `${Math.ceil(payload.height)}px`;
|
|
29
29
|
});
|
|
30
|
+
/**
|
|
31
|
+
* Parses incoming message data, handling both string and object payloads.
|
|
32
|
+
*
|
|
33
|
+
* 解析传入的消息数据,支持字符串和对象两种载荷格式。
|
|
34
|
+
*
|
|
35
|
+
* @param data - Raw message data from the iframe / 来自 iframe 的原始消息数据
|
|
36
|
+
* @returns Parsed message data object / 解析后的消息数据对象
|
|
37
|
+
*/
|
|
30
38
|
function parseData(data) {
|
|
31
39
|
if (typeof data === "string") try {
|
|
32
40
|
return JSON.parse(data);
|
|
@@ -48,6 +56,11 @@ _sfc_main.setup = (props, ctx) => {
|
|
|
48
56
|
};
|
|
49
57
|
//#endregion
|
|
50
58
|
//#region src/client/index.ts
|
|
59
|
+
/**
|
|
60
|
+
* Enhances the VitePress application by registering the `VPCaniuse` component.
|
|
61
|
+
*
|
|
62
|
+
* 通过注册 `VPCaniuse` 组件来增强 VitePress 应用。
|
|
63
|
+
*/
|
|
51
64
|
function enhanceAppWithCaniuse({ app }) {
|
|
52
65
|
app.component("VPCaniuse", _sfc_main);
|
|
53
66
|
}
|
package/dist/node/index.d.ts
CHANGED
|
@@ -2,6 +2,17 @@ import { PluginSimple } from "markdown-it";
|
|
|
2
2
|
|
|
3
3
|
//#region src/node/plugin.d.ts
|
|
4
4
|
/**
|
|
5
|
+
* VitePress plugin for embedding Can I Use browser support information.
|
|
6
|
+
*
|
|
7
|
+
* VitePress 插件,用于嵌入 Can I Use 浏览器支持信息。
|
|
8
|
+
*
|
|
9
|
+
* The plugin registers a markdown embed rule (`@[caniuse](feature_name)`)PCaniuse`
|
|
10
|
+
PCaniuse`
|
|
11
|
+
* Vue component, which renders an iframe pointing to the Can I Use embed service.
|
|
12
|
+
*
|
|
13
|
+
* 该插件注册 markdown 嵌入规则(`@[caniuse](feature_name)`)和 `VPCaniuse` Vue 组件,
|
|
14
|
+
* 组件会渲染指向 Can I Use 嵌入服务的 iframe。
|
|
15
|
+
*
|
|
5
16
|
* @example
|
|
6
17
|
* `.vitepress/config.ts`
|
|
7
18
|
* ```ts
|
|
@@ -16,6 +27,20 @@ declare const caniuse: (options?: unknown) => import("vitepress-tuck").Vitepress
|
|
|
16
27
|
//#endregion
|
|
17
28
|
//#region src/node/markdown.d.ts
|
|
18
29
|
/**
|
|
30
|
+
* markdown-it plugin that registers the `@caniuse` embed block rule.
|
|
31
|
+
*
|
|
32
|
+
* markdown-it 插件,注册 `@caniuse` 嵌入块规则。
|
|
33
|
+
*
|
|
34
|
+
* Supported syntaxes:
|
|
35
|
+
* - `@[caniuse](feature_name)` — default embed view
|
|
36
|
+
* - `@[caniuse embed{-2,4}](feature_name)` — embed with version range
|
|
37
|
+
* - `@[caniuse baseline](feature_name)` — baseline view
|
|
38
|
+
*
|
|
39
|
+
* 支持的语法:
|
|
40
|
+
* - `@[caniuse](feature_name)` — 默认嵌入视图
|
|
41
|
+
* - `@[caniuse embed{-2,4}](feature_name)` — 带版本范围的嵌入
|
|
42
|
+
* - `@[caniuse baseline](feature_name)` — Baseline 视图
|
|
43
|
+
*
|
|
19
44
|
* @example
|
|
20
45
|
* `.vitepress/config.ts`
|
|
21
46
|
* ```ts
|
package/dist/node/index.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { definePlugin } from "vitepress-tuck";
|
|
2
2
|
import { createEmbedRuleBlock, stringifyAttrs } from "vitepress-plugin-toolkit";
|
|
3
3
|
//#region src/node/markdown.ts
|
|
4
|
+
const UNDERLINE_RE = /_+/g;
|
|
5
|
+
let uuid = 0;
|
|
4
6
|
/**
|
|
7
|
+
* markdown-it plugin that registers the `@caniuse` embed block rule.
|
|
8
|
+
*
|
|
9
|
+
* markdown-it 插件,注册 `@caniuse` 嵌入块规则。
|
|
10
|
+
*
|
|
11
|
+
* Supported syntaxes:
|
|
12
|
+
* - `@[caniuse](feature_name)` — default embed view
|
|
13
|
+
* - `@[caniuse embed{-2,4}](feature_name)` — embed with version range
|
|
14
|
+
* - `@[caniuse baseline](feature_name)` — baseline view
|
|
15
|
+
*
|
|
16
|
+
* 支持的语法:
|
|
17
|
+
* - `@[caniuse](feature_name)` — 默认嵌入视图
|
|
18
|
+
* - `@[caniuse embed{-2,4}](feature_name)` — 带版本范围的嵌入
|
|
19
|
+
* - `@[caniuse baseline](feature_name)` — Baseline 视图
|
|
20
|
+
*
|
|
5
21
|
* @example
|
|
6
22
|
* `.vitepress/config.ts`
|
|
7
23
|
* ```ts
|
|
@@ -19,30 +35,51 @@ import { createEmbedRuleBlock, stringifyAttrs } from "vitepress-plugin-toolkit";
|
|
|
19
35
|
const caniuseMarkdownPlugin = (md) => {
|
|
20
36
|
createEmbedRuleBlock(md, {
|
|
21
37
|
type: "caniuse",
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
meta: (info, source) => {
|
|
39
|
+
const [mode, versions = ""] = info.split("{");
|
|
40
|
+
return {
|
|
41
|
+
feature: source,
|
|
42
|
+
mode: mode.trim() || "embed",
|
|
43
|
+
versions: versions.replace("}", "")
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
content: ({ feature, mode, versions }) => {
|
|
47
|
+
if (!feature) return "";
|
|
48
|
+
feature = feature.replace(UNDERLINE_RE, "_");
|
|
49
|
+
const { past, future } = resolveVersions(versions);
|
|
50
|
+
const meta = `${feature}-${uuid++}`;
|
|
51
|
+
return `<VPCaniuse${stringifyAttrs({
|
|
52
|
+
feature,
|
|
53
|
+
meta,
|
|
54
|
+
past,
|
|
55
|
+
future,
|
|
56
|
+
baseline: mode === "baseline"
|
|
57
|
+
})} />`;
|
|
58
|
+
}
|
|
29
59
|
});
|
|
30
60
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Parses a version range string into past and future browser version offsets.
|
|
63
|
+
*
|
|
64
|
+
* 将版本范围字符串解析为过去和未来的浏览器版本偏移量。
|
|
65
|
+
*
|
|
66
|
+
* The input uses comma-separated numbers where negative values represent past
|
|
67
|
+
* versions and positive values represent future versions. The value `0` is
|
|
68
|
+
* always included as the anchor. Values outside the range `[-5, 3]` are ignored.
|
|
69
|
+
*
|
|
70
|
+
* 输入使用逗号分隔的数字,负值表示过去版本,正值表示未来版本。
|
|
71
|
+
* 值 `0` 始终作为锚点包含在内。超出 `[-5, 3]` 范围的值会被忽略。
|
|
72
|
+
*
|
|
73
|
+
* @param versions - Comma-separated version offsets (e.g. `-2,4`) / 逗号分隔的版本偏移量(例如 `-2,4`)
|
|
74
|
+
* @returns An object containing the past and future version offsets / 包含过去和未来版本偏移量的对象
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Default values when no range is provided
|
|
78
|
+
* resolveVersions('') // { past: 5, future: 3 }
|
|
79
|
+
*
|
|
80
|
+
* // Custom range
|
|
81
|
+
* resolveVersions('-2,4') // { past: 2, future: 4 }
|
|
82
|
+
*/
|
|
46
83
|
function resolveVersions(versions) {
|
|
47
84
|
if (!versions) return {
|
|
48
85
|
past: 5,
|
|
@@ -59,6 +96,17 @@ function resolveVersions(versions) {
|
|
|
59
96
|
//#endregion
|
|
60
97
|
//#region src/node/plugin.ts
|
|
61
98
|
/**
|
|
99
|
+
* VitePress plugin for embedding Can I Use browser support information.
|
|
100
|
+
*
|
|
101
|
+
* VitePress 插件,用于嵌入 Can I Use 浏览器支持信息。
|
|
102
|
+
*
|
|
103
|
+
* The plugin registers a markdown embed rule (`@[caniuse](feature_name)`)PCaniuse`
|
|
104
|
+
PCaniuse`
|
|
105
|
+
* Vue component, which renders an iframe pointing to the Can I Use embed service.
|
|
106
|
+
*
|
|
107
|
+
* 该插件注册 markdown 嵌入规则(`@[caniuse](feature_name)`)和 `VPCaniuse` Vue 组件,
|
|
108
|
+
* 组件会渲染指向 Can I Use 嵌入服务的 iframe。
|
|
109
|
+
*
|
|
62
110
|
* @example
|
|
63
111
|
* `.vitepress/config.ts`
|
|
64
112
|
* ```ts
|
|
@@ -71,7 +119,7 @@ function resolveVersions(versions) {
|
|
|
71
119
|
*/
|
|
72
120
|
const caniuse = definePlugin(() => ({
|
|
73
121
|
name: "vitepress-plugin-caniuse",
|
|
74
|
-
|
|
122
|
+
componentResolver: ["VPCaniuse"],
|
|
75
123
|
markdown: { config: (md) => {
|
|
76
124
|
md.use(caniuseMarkdownPlugin);
|
|
77
125
|
} },
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-plugin-caniuse",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "Embed caniuse.com data in your VitePress site",
|
|
6
6
|
"author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"homepage": "https://tuck.pengzhanbo.cn/plugins/caniuse",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "git+https://github.com/pengzhanbo/vitepress-tuck.git",
|
|
11
12
|
"directory": "packages/plugin-caniuse"
|
|
12
13
|
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pengzhanbo/vitepress-tuck/issues"
|
|
16
|
+
},
|
|
13
17
|
"keywords": [
|
|
14
18
|
"vitepress",
|
|
15
19
|
"vitepress-plugin",
|
|
@@ -35,8 +39,8 @@
|
|
|
35
39
|
},
|
|
36
40
|
"dependencies": {
|
|
37
41
|
"@vueuse/core": "^14.3.0",
|
|
38
|
-
"vitepress-
|
|
39
|
-
"vitepress-
|
|
42
|
+
"vitepress-plugin-toolkit": "0.5.0",
|
|
43
|
+
"vitepress-tuck": "0.5.0"
|
|
40
44
|
},
|
|
41
45
|
"publishConfig": {
|
|
42
46
|
"access": "public",
|