vitepress-plugin-codepen 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,20 +2,25 @@ import { EnhanceAppContext } from "vitepress/client";
2
2
 
3
3
  //#region src/client/VPCodepen.vue.d.ts
4
4
  type __VLS_Props = {
5
- user: string;
6
- slash: string;
7
- title?: string;
8
- preview?: boolean;
9
- editable?: boolean;
10
- tab?: string;
11
- theme?: 'light' | 'dark';
12
- width?: string;
5
+ /** CodePen user name owning the Pen / 拥有该 Pen 的 CodePen 用户名 */user: string; /** Pen slug identifier used in the CodePen URL / Pen 标识,用于 CodePen URL 中 */
6
+ slash: string; /** Pen title displayed as the iframe `title` attribute / Pen 标题,作为 iframe 的 `title` 属性显示 */
7
+ title?: string; /** Whether to render the preview embed view / 是否渲染预览嵌入视图 */
8
+ preview?: boolean; /** Whether the embedded Pen is editable by the viewer / 嵌入的 Pen 是否可被查看者编辑 */
9
+ editable?: boolean; /** Comma-separated list of tabs to display / 要显示的选项卡列表,以逗号分隔 */
10
+ tab?: string; /** Embed theme, follows site theme when omitted / 嵌入主题,省略时跟随站点主题 */
11
+ theme?: 'light' | 'dark'; /** Iframe width, defaults to `100%` / iframe 宽度,默认为 `100%` */
12
+ width?: string; /** Iframe height, defaults to `400px` / iframe 高度,默认为 `400px` */
13
13
  height?: string;
14
14
  };
15
15
  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>;
16
16
  declare const _default: typeof __VLS_export;
17
17
  //#endregion
18
18
  //#region src/client/index.d.ts
19
+ /**
20
+ * Enhances the VitePress application by registering the `VPCodepen` component.
21
+ *
22
+ * 通过注册 `VPCodepen` 组件来增强 VitePress 应用。
23
+ */
19
24
  declare function enhanceAppWithCodepen({
20
25
  app
21
26
  }: EnhanceAppContext): void;
@@ -18,6 +18,20 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
18
18
  },
19
19
  setup(__props) {
20
20
  const { isDark } = useData();
21
+ /**
22
+ * Builds the CodePen embed URL from the component props.
23
+ *
24
+ * 根据组件 props 构建 CodePen 嵌入 URL。
25
+ *
26
+ * The URL switches between preview and standard embed endpoints, and forwards
27
+ * the `editable`, `tab`, and `theme` options as query parameters. When `theme`
28
+ * is omitted, it falls back to the current site theme.
29
+ *
30
+ * URL 会在预览和标准嵌入端点之间切换,并将 `editable`、`tab` 和 `theme`
31
+ * 选项作为查询参数传递。当省略 `theme` 时,回退到当前站点主题。
32
+ *
33
+ * @returns The fully qualified CodePen embed URL / 完整的 CodePen 嵌入 URL
34
+ */
21
35
  const link = computed(() => {
22
36
  const middle = __props.preview ? "/embed/preview/" : "/embed/";
23
37
  const params = new URLSearchParams();
@@ -50,6 +64,11 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
50
64
  });
51
65
  //#endregion
52
66
  //#region src/client/index.ts
67
+ /**
68
+ * Enhances the VitePress application by registering the `VPCodepen` component.
69
+ *
70
+ * 通过注册 `VPCodepen` 组件来增强 VitePress 应用。
71
+ */
53
72
  function enhanceAppWithCodepen({ app }) {
54
73
  app.component("VPCodepen", _sfc_main);
55
74
  }
@@ -2,20 +2,25 @@ import { EnhanceAppContext } from "vitepress/client";
2
2
 
3
3
  //#region src/client/VPCodepen.vue.d.ts
4
4
  type __VLS_Props = {
5
- user: string;
6
- slash: string;
7
- title?: string;
8
- preview?: boolean;
9
- editable?: boolean;
10
- tab?: string;
11
- theme?: 'light' | 'dark';
12
- width?: string;
5
+ /** CodePen user name owning the Pen / 拥有该 Pen 的 CodePen 用户名 */user: string; /** Pen slug identifier used in the CodePen URL / Pen 标识,用于 CodePen URL 中 */
6
+ slash: string; /** Pen title displayed as the iframe `title` attribute / Pen 标题,作为 iframe 的 `title` 属性显示 */
7
+ title?: string; /** Whether to render the preview embed view / 是否渲染预览嵌入视图 */
8
+ preview?: boolean; /** Whether the embedded Pen is editable by the viewer / 嵌入的 Pen 是否可被查看者编辑 */
9
+ editable?: boolean; /** Comma-separated list of tabs to display / 要显示的选项卡列表,以逗号分隔 */
10
+ tab?: string; /** Embed theme, follows site theme when omitted / 嵌入主题,省略时跟随站点主题 */
11
+ theme?: 'light' | 'dark'; /** Iframe width, defaults to `100%` / iframe 宽度,默认为 `100%` */
12
+ width?: string; /** Iframe height, defaults to `400px` / iframe 高度,默认为 `400px` */
13
13
  height?: string;
14
14
  };
15
15
  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>;
16
16
  declare const _default: typeof __VLS_export;
17
17
  //#endregion
18
18
  //#region src/client/index.d.ts
19
+ /**
20
+ * Enhances the VitePress application by registering the `VPCodepen` component.
21
+ *
22
+ * 通过注册 `VPCodepen` 组件来增强 VitePress 应用。
23
+ */
19
24
  declare function enhanceAppWithCodepen({
20
25
  app
21
26
  }: EnhanceAppContext): void;
@@ -19,6 +19,20 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
19
19
  },
20
20
  setup(__props) {
21
21
  const { isDark } = useData();
22
+ /**
23
+ * Builds the CodePen embed URL from the component props.
24
+ *
25
+ * 根据组件 props 构建 CodePen 嵌入 URL。
26
+ *
27
+ * The URL switches between preview and standard embed endpoints, and forwards
28
+ * the `editable`, `tab`, and `theme` options as query parameters. When `theme`
29
+ * is omitted, it falls back to the current site theme.
30
+ *
31
+ * URL 会在预览和标准嵌入端点之间切换,并将 `editable`、`tab` 和 `theme`
32
+ * 选项作为查询参数传递。当省略 `theme` 时,回退到当前站点主题。
33
+ *
34
+ * @returns The fully qualified CodePen embed URL / 完整的 CodePen 嵌入 URL
35
+ */
22
36
  const link = computed(() => {
23
37
  const middle = __props.preview ? "/embed/preview/" : "/embed/";
24
38
  const params = new URLSearchParams();
@@ -57,6 +71,11 @@ _sfc_main.setup = (props, ctx) => {
57
71
  };
58
72
  //#endregion
59
73
  //#region src/client/index.ts
74
+ /**
75
+ * Enhances the VitePress application by registering the `VPCodepen` component.
76
+ *
77
+ * 通过注册 `VPCodepen` 组件来增强 VitePress 应用。
78
+ */
60
79
  function enhanceAppWithCodepen({ app }) {
61
80
  app.component("VPCodepen", _sfc_main);
62
81
  }
@@ -2,7 +2,18 @@ import { PluginSimple } from "markdown-it";
2
2
 
3
3
  //#region src/node/plugin.d.ts
4
4
  /**
5
+ * VitePress plugin for embedding CodePen demos.
6
+ *
7
+ * VitePress 插件,用于嵌入 CodePen 演示。
8
+ *
9
+ * The plugin registers a markdown embed rule (`@codepen`) and the `VPCodepen`
10
+ * Vue component, which renders an iframe pointing to the CodePen embed service.
11
+ *
12
+ * 该插件注册 markdown 嵌入规则(`@codepen`)和 `VPCodepen` Vue 组件,
13
+ * 组件会渲染指向 CodePen 嵌入服务的 iframe。
14
+ *
5
15
  * @example
16
+ * `.vitepress/config.ts`
6
17
  * ```ts
7
18
  * import codepen from 'vitepress-plugin-codepen'
8
19
  * import { defineConfig } from 'vitepress-tuck'
@@ -15,7 +26,24 @@ declare const codepen: (options?: unknown) => import("vitepress-tuck").Vitepress
15
26
  //#endregion
16
27
  //#region src/node/markdown.d.ts
17
28
  /**
29
+ * markdown-it plugin that registers the `@codepen` embed block rule.
30
+ *
31
+ * markdown-it 插件,注册 `@codepen` 嵌入块规则。
32
+ *
33
+ * Supported syntaxes:
34
+ * - `@[codepen](user/slash)` — default embed view / 默认嵌入视图
35
+ * - `@[codepen preview](user/slash)` — preview embed view / 预览嵌入视图
36
+ * - `@[codepen preview editable title="" height="400px" tab="css,result" theme="dark"](user/slash)`
37
+ * — fully customized embed / 完全自定义的嵌入
38
+ *
39
+ * 支持的语法:
40
+ * - `@[codepen](user/slash)` — 默认嵌入视图
41
+ * - `@[codepen preview](user/slash)` — 预览嵌入视图
42
+ * - `@[codepen preview editable title="" height="400px" tab="css,result" theme="dark"](user/slash)`
43
+ * — 完全自定义的嵌入
44
+ *
18
45
  * @example
46
+ * `.vitepress/config.ts`
19
47
  * ```ts
20
48
  * import { codepenMarkdownPlugin } from 'vitepress-plugin-codepen'
21
49
  * import { defineConfig } from 'vitepress'
@@ -2,7 +2,24 @@ import { definePlugin } from "vitepress-tuck";
2
2
  import { createEmbedRuleBlock, parseRect, resolveAttrs, stringifyAttrs } from "vitepress-plugin-toolkit";
3
3
  //#region src/node/markdown.ts
4
4
  /**
5
+ * markdown-it plugin that registers the `@codepen` embed block rule.
6
+ *
7
+ * markdown-it 插件,注册 `@codepen` 嵌入块规则。
8
+ *
9
+ * Supported syntaxes:
10
+ * - `@[codepen](user/slash)` — default embed view / 默认嵌入视图
11
+ * - `@[codepen preview](user/slash)` — preview embed view / 预览嵌入视图
12
+ * - `@[codepen preview editable title="" height="400px" tab="css,result" theme="dark"](user/slash)`
13
+ * — fully customized embed / 完全自定义的嵌入
14
+ *
15
+ * 支持的语法:
16
+ * - `@[codepen](user/slash)` — 默认嵌入视图
17
+ * - `@[codepen preview](user/slash)` — 预览嵌入视图
18
+ * - `@[codepen preview editable title="" height="400px" tab="css,result" theme="dark"](user/slash)`
19
+ * — 完全自定义的嵌入
20
+ *
5
21
  * @example
22
+ * `.vitepress/config.ts`
6
23
  * ```ts
7
24
  * import { codepenMarkdownPlugin } from 'vitepress-plugin-codepen'
8
25
  * import { defineConfig } from 'vitepress'
@@ -18,8 +35,7 @@ import { createEmbedRuleBlock, parseRect, resolveAttrs, stringifyAttrs } from "v
18
35
  const codepenMarkdownPlugin = (md) => {
19
36
  createEmbedRuleBlock(md, {
20
37
  type: "codepen",
21
- syntaxPattern: /^@\[codepen([^\]]*)\]\(([^)]*)\)/,
22
- meta: ([, info, source]) => {
38
+ meta: (info, source) => {
23
39
  const { width, height, title, tab, ...rest } = resolveAttrs(info);
24
40
  const [user, slash] = source.split("/");
25
41
  return {
@@ -38,7 +54,18 @@ const codepenMarkdownPlugin = (md) => {
38
54
  //#endregion
39
55
  //#region src/node/plugin.ts
40
56
  /**
57
+ * VitePress plugin for embedding CodePen demos.
58
+ *
59
+ * VitePress 插件,用于嵌入 CodePen 演示。
60
+ *
61
+ * The plugin registers a markdown embed rule (`@codepen`) and the `VPCodepen`
62
+ * Vue component, which renders an iframe pointing to the CodePen embed service.
63
+ *
64
+ * 该插件注册 markdown 嵌入规则(`@codepen`)和 `VPCodepen` Vue 组件,
65
+ * 组件会渲染指向 CodePen 嵌入服务的 iframe。
66
+ *
41
67
  * @example
68
+ * `.vitepress/config.ts`
42
69
  * ```ts
43
70
  * import codepen from 'vitepress-plugin-codepen'
44
71
  * import { defineConfig } from 'vitepress-tuck'
@@ -49,7 +76,7 @@ const codepenMarkdownPlugin = (md) => {
49
76
  */
50
77
  const codepen = definePlugin(() => ({
51
78
  name: "vitepress-plugin-codepen",
52
- client: { enhance: "enhanceAppWithCodepen" },
79
+ componentResolver: ["VPCodepen"],
53
80
  markdown: { config(md) {
54
81
  md.use(codepenMarkdownPlugin);
55
82
  } },
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "vitepress-plugin-codepen",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.5.0",
5
5
  "description": "embed codepen in vitepress document.",
6
6
  "author": "pengzhanbo <q942450674@outlook.com> (https://github.com/pengzhanbo/)",
7
7
  "license": "MIT",
8
+ "homepage": "https://tuck.pengzhanbo.cn/plugins/codepen",
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "git+https://github.com/pengzhanbo/vitepress-tuck.git",
11
12
  "directory": "packages/plugin-codepen"
12
13
  },
14
+ "bugs": {
15
+ "url": "https://github.com/pengzhanbo/vitepress-tuck/issues"
16
+ },
13
17
  "keywords": [
14
18
  "vitepress",
15
19
  "vitepress-plugin",
@@ -33,8 +37,8 @@
33
37
  "vue": "^3.5.0"
34
38
  },
35
39
  "dependencies": {
36
- "vitepress-plugin-toolkit": "0.3.0",
37
- "vitepress-tuck": "0.3.0"
40
+ "vitepress-plugin-toolkit": "0.5.0",
41
+ "vitepress-tuck": "0.5.0"
38
42
  },
39
43
  "publishConfig": {
40
44
  "access": "public",