vitepress-plugin-sfc 2.0.0-beta.1 → 2.0.0-beta.2
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/README.md +23 -128
- package/dist/index.d.mts +13 -9
- package/dist/index.mjs +9 -5
- package/package.json +36 -32
- package/src/client/ComponentView.vue +109 -125
- package/src/client/useLocaleMappings.ts +2 -7
package/README.md
CHANGED
|
@@ -1,156 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# VitePress Plugin SFC
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
[Documentation](https://vitepress-plugin-sfc-playgrou.vercel.app/)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Allows you to write Vue SFC within Markdown files and render them in VitePress.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Install
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- [x] **Code Copying** - One-click copy for the component's source code.
|
|
12
|
-
- [x] **Dark Mode Support** - Automatically adapts to VitePress's light and dark themes.
|
|
13
|
-
- [x] **Lightweight** - No complex dependencies, only `2kb` / gzip:`1kb`.
|
|
14
|
-
- [x] **Internationalization Support** - Default support for Chinese and English, configurable for other languages.
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install vitepress-plugin-sfc --save-dev
|
|
9
|
+
```shell
|
|
10
|
+
npm install -D vitepress-plugin-sfc
|
|
20
11
|
```
|
|
21
12
|
|
|
22
13
|
## Configuration
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Add the plugin to your VitePress configuration file (`.vitepress/config.js` or `.vitepress/config.ts`):
|
|
15
|
+
Configure it in `.vitepress/config.ts`:
|
|
27
16
|
|
|
28
17
|
```ts
|
|
29
|
-
import { defineConfig } from
|
|
30
|
-
import {
|
|
18
|
+
import { defineConfig } from "vitepress";
|
|
19
|
+
import { sfcPlugin, sfcRegistryVitePlugin } from "vitepress-plugin-sfc";
|
|
31
20
|
|
|
32
21
|
export default defineConfig({
|
|
33
|
-
// ...
|
|
34
|
-
|
|
22
|
+
// ...other configurations
|
|
35
23
|
markdown: {
|
|
36
24
|
config: (md) => {
|
|
37
|
-
md.use(
|
|
38
|
-
}
|
|
25
|
+
md.use(sfcPlugin);
|
|
26
|
+
},
|
|
39
27
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### Configure Client
|
|
44
|
-
|
|
45
|
-
VitePress resolves themes from `.vitepress/theme/index.js` or `.vitepress/theme/index.ts`, and we configure the client here as well.
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
// theme/index.ts
|
|
49
|
-
import DefaultTheme from "vitepress/theme";
|
|
50
|
-
import { enhanceAppWithComponentView } from 'vitepress-plugin-sfc/client'
|
|
51
|
-
|
|
52
|
-
export default {
|
|
53
|
-
extends: DefaultTheme, // Use VitePress's default theme
|
|
54
|
-
enhanceApp({ app }) {
|
|
55
|
-
enhanceAppWithComponentView(app)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
The `enhanceAppWithComponentView` function automatically registers the preview component on the passed root component.
|
|
61
|
-
|
|
62
|
-
### Configure Internationalization
|
|
63
|
-
|
|
64
|
-
The plugin gets language configuration from the `locales.lang` option in VitePress and supports `zh` and `en` languages by default. You can also manually configure other languages or even override the default languages.
|
|
65
|
-
|
|
66
|
-
Configure internationalization in the client configuration:
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
export default {
|
|
70
|
-
// Other configurations
|
|
71
|
-
enhanceApp({ app }) {
|
|
72
|
-
enhanceAppWithComponentView(app, {
|
|
73
|
-
// Configure corresponding languages through localeMappings option
|
|
74
|
-
localeMappings: {
|
|
75
|
-
fr: {
|
|
76
|
-
previewLabel: "foo",
|
|
77
|
-
codeLabel: "bar",
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
});
|
|
28
|
+
vite: {
|
|
29
|
+
plugins: [sfcRegistryVitePlugin()],
|
|
81
30
|
},
|
|
82
|
-
};
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Example
|
|
86
|
-
|
|
87
|
-
This is an example of button SFC:
|
|
88
|
-
|
|
89
|
-
```vue
|
|
90
|
-
<script setup lang="ts">
|
|
91
|
-
import { ref } from 'vue';
|
|
92
|
-
|
|
93
|
-
const count = ref(0)
|
|
94
|
-
</script>
|
|
95
|
-
|
|
96
|
-
<template>
|
|
97
|
-
<button class="my-button" @click="count++">
|
|
98
|
-
Clicked {{ count }} times
|
|
99
|
-
</button>
|
|
100
|
-
</template>
|
|
101
|
-
|
|
102
|
-
<style>
|
|
103
|
-
.my-button {
|
|
104
|
-
background-color: #3eaf7c;
|
|
105
|
-
color: white;
|
|
106
|
-
border: none;
|
|
107
|
-
padding: 8px 16px;
|
|
108
|
-
border-radius: 4px;
|
|
109
|
-
cursor: pointer;
|
|
110
|
-
}
|
|
111
|
-
</style>
|
|
31
|
+
});
|
|
112
32
|
```
|
|
113
33
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
```bash
|
|
117
|
-
<script setup>
|
|
118
|
-
import Button from './Button.vue'
|
|
119
|
-
</script>
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Then use the specified syntax:
|
|
123
|
-
|
|
124
|
-
```markdown
|
|
125
|
-
::: component-view
|
|
126
|
-
<Button />
|
|
127
|
-
:::
|
|
128
|
-
```
|
|
34
|
+
## Usage
|
|
129
35
|
|
|
130
|
-
|
|
36
|
+
Wrap **valid** Vue SFC content with `:::sfc`:
|
|
131
37
|
|
|
132
38
|
```markdown
|
|
39
|
+
:::sfc
|
|
133
40
|
<script setup>
|
|
134
|
-
import
|
|
41
|
+
import { ref } from "vue"
|
|
42
|
+
const msg = ref("");
|
|
135
43
|
</script>
|
|
136
44
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
<Button />
|
|
45
|
+
<template>
|
|
46
|
+
<input v-model="msg" placeholder="Please enter text" />
|
|
47
|
+
</template>
|
|
141
48
|
:::
|
|
142
|
-
|
|
143
|
-
##
|
|
144
49
|
```
|
|
145
50
|
|
|
146
|
-
You can view the component's preview and source code in the tabs above.
|
|
147
|
-
|
|
148
|
-
You can check out the [live demo here](https://vitepress-plugin-sfc-playgrou.vercel.app/).
|
|
149
|
-
|
|
150
|
-
## Notes
|
|
151
|
-
|
|
152
|
-
- Component paths should be relative to the project root.
|
|
153
|
-
- Current version supports simple Vue components; complex components might require additional configuration. - Components must be valid Single File Components (SFCs).
|
|
154
|
-
## License
|
|
155
|
-
|
|
156
51
|
[MIT](LICENSE)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { MarkdownEnv, Plugin } from "vitepress";
|
|
1
2
|
import LinkifyIt from "linkify-it";
|
|
2
|
-
import { Plugin } from "vitepress";
|
|
3
3
|
|
|
4
4
|
//#region \0rolldown/runtime.js
|
|
5
5
|
declare namespace index_d_exports$1 {
|
|
@@ -1065,16 +1065,20 @@ interface SFC {
|
|
|
1065
1065
|
content: string;
|
|
1066
1066
|
hash: string;
|
|
1067
1067
|
importer: string;
|
|
1068
|
+
markupParams: MarkupParams;
|
|
1068
1069
|
}
|
|
1069
|
-
interface
|
|
1070
|
-
|
|
1070
|
+
interface MarkdownEnvExt extends MarkdownEnv {
|
|
1071
|
+
sfcs: SFC[];
|
|
1072
|
+
__matched_sfc_set__: Set<string>;
|
|
1071
1073
|
}
|
|
1072
|
-
|
|
1074
|
+
interface MarkupParams {
|
|
1075
|
+
showSource: boolean;
|
|
1076
|
+
filepath?: string;
|
|
1077
|
+
component?: string;
|
|
1078
|
+
}
|
|
1079
|
+
declare const sfcPlugin: PluginSimple;
|
|
1073
1080
|
//#endregion
|
|
1074
1081
|
//#region src/node/vite.d.ts
|
|
1075
|
-
|
|
1076
|
-
md: MarkdownIt;
|
|
1077
|
-
}
|
|
1078
|
-
declare function sfcRegistryVitePlugin(options: PluginOptions): Plugin;
|
|
1082
|
+
declare function sfcRegistryVitePlugin(): Promise<Plugin>;
|
|
1079
1083
|
//#endregion
|
|
1080
|
-
export { SCRIPT_RE, SFC, SFC_IMPORTER_RE, sfcPlugin, sfcRegistryVitePlugin };
|
|
1084
|
+
export { MarkdownEnvExt, MarkupParams, SCRIPT_RE, SFC, SFC_IMPORTER_RE, sfcPlugin, sfcRegistryVitePlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import e from"node:crypto";import{createMarkdownRenderer as t}from"vitepress";function n(e,t,n){function r(e){return e.trim().split(` `,2)[0]===t}function i(e,n,r,i,a){return e[n].nesting===1&&e[n].attrJoin(`class`,t),a.renderToken(e,n,r,i,a)}n||={};let a=n.marker||`:`,o=a.charCodeAt(0),s=a.length,c=n.validate||r,l=n.render||i;function u(e,n,r,i){let l,u=!1,d=e.bMarks[n]+e.tShift[n],f=e.eMarks[n];if(o!==e.src.charCodeAt(d))return!1;for(l=d+1;l<=f&&a[(l-d)%s]===e.src[l];l++);let p=Math.floor((l-d)/s);if(p<3)return!1;l-=(l-d)%s;let m=e.src.slice(d,l),h=e.src.slice(l,f);if(!c(h,m))return!1;if(i)return!0;let g=n;for(;g++,!(g>=r||(d=e.bMarks[g]+e.tShift[g],f=e.eMarks[g],d<f&&e.sCount[g]<e.blkIndent));)if(o===e.src.charCodeAt(d)&&!(e.sCount[g]-e.blkIndent>=4)){for(l=d+1;l<=f&&a[(l-d)%s]===e.src[l];l++);if(!(Math.floor((l-d)/s)<p)&&(l-=(l-d)%s,l=e.skipSpaces(l),!(l<f))){u=!0;break}}let _=e.parentType,v=e.lineMax;e.parentType=`container`,e.lineMax=g;let y=e.push(`container_`+t+`_open`,`div`,1);y.markup=m,y.block=!0,y.info=h,y.map=[n,g],e.md.block.tokenize(e,n+1,g);let b=e.push(`container_`+t+`_close`,`div`,-1);return b.markup=e.src.slice(d,l),b.block=!0,e.parentType=_,e.lineMax=v,e.line=g+ +!!u,!0}e.block.ruler.before(`fence`,`container_`+t,u,{alt:[`paragraph`,`reference`,`blockquote`,`list`]}),e.renderer.rules[`container_`+t+`_open`]=l,e.renderer.rules[`container_`+t+`_close`]=l}const r=/<script\b[^>]*>([\s\S]*?)<\/script>/,i=/^virtual:VP_SFC_/;function a(){return{content:`<script setup>
|
|
2
|
+
<\/script>`,tagOpen:`<script setup>`,type:`script`,contentStripped:`
|
|
3
|
+
`,tagClose:`<\/script>`}}function o(t){return e.createHash(`sha256`).update(t).digest(`hex`)}function s(e){if(!e)return{};let t=e.split(`,`);return Object.fromEntries(t.map(e=>{let[,t,n]=e.match(/([^=]+)=(.*)/)||[];return e===`showSource`||t===`showSource`&&n===`true`?[`showSource`,!0]:[t,n]}))}function c(e){e.use(n,`sfc`,{validate:e=>RegExp(`^sfc`).test(e.trim()),render:(e,t,n,r)=>{let{__matched_sfc_set__:i,sfcBlocks:o}=r;o.scripts.length||o.scripts.push(a());let[s]=o.scripts??[],c=e[t];if(c.nesting===1){let{hash:e,name:t,content:r,markupParams:a,importer:o}=c.meta.sfc;if(!i.has(e)){let{tagOpen:n,tagClose:r,contentStripped:a}=s,c=a+`// [vitepress-plugin-sfc] injected vue virtual imports
|
|
4
|
+
// REGION START
|
|
5
|
+
import ${t} from '${o}'
|
|
6
|
+
// REGION END
|
|
7
|
+
`;s.contentStripped=c,s.content=n+c+r,i.add(e)}return a.showSource?`<ComponentView>\n<template #v3><${t} /></template>\n<template #highlight>${n.highlight(r,`vue`,``)}</template>\n</ComponentView>\n`:`<${t} />`}else return``}}),e.core.ruler.after(`block`,`extract_sfc`,e=>{let t=e.src.split(`
|
|
8
|
+
`),n=e.env.sfcs||[],r;function a(e){let{type:n,nesting:r,map:a,info:c}=e;if(n!==`container_sfc_open`||r!==1||!a)return;let[l,u]=a,d=t.slice(l+1,u).join(`
|
|
9
|
+
`),f=o(d),p=`VP_SFC_${f}`,m=`virtual:${p}.vue`;if(!i.test(m))throw Error(`[vitepress-plugin-sfc] Plugin-self Error: Unmatched importer syntax`);let[,h]=(c??``).split(` `);return{content:d,name:p,hash:f,importer:m,markupParams:s(h)}}for(let t of e.tokens){let{map:e}=t,i=a(t);if(i){r=t,t.meta={...t.meta,sfc:i};let e=n.some(({name:e})=>i?.name===e);i&&!e&&n.push(i)}if(r&&r!==t){let[n]=e||[-1],[i,a]=r.map;n>i&&n<a?t.content=``:r=void 0}}let c=e.env;c.sfcs=[...n],c.__matched_sfc_set__=new Set})}const l=c;async function u(){let e=await t(``,{html:!0});e.use(l);let n=new Map;return{name:`vite-plugin-sfc-registry`,enforce:`pre`,resolveId:{filter:{id:new RegExp(i,`gi`)},handler(e){if(n.has(e))return e}},load:{filter:{id:new RegExp(i,`gi`)},handler(e){if(n.has(e))return n.get(e)}},transform(t,r){if(/.md$/gi.test(r)){let r={};e.render(t,r);let i=r.sfcs||[];for(let{importer:e,content:t}of i)n.set(e,t)}}}}export{r as SCRIPT_RE,i as SFC_IMPORTER_RE,l as sfcPlugin,u as sfcRegistryVitePlugin};
|
package/package.json
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-plugin-sfc",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "VitePress plugin that renders inline Vue SFC with tabs showing preview and source code",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"component",
|
|
7
|
+
"plugin",
|
|
8
|
+
"tabs",
|
|
9
|
+
"vitepress",
|
|
10
|
+
"vitepress plugin",
|
|
11
|
+
"vitepress-plugin",
|
|
12
|
+
"vue"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "hotdogc1017@gmail.com",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/heroui-vue/vitepress-plugin-sfc"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"src/client"
|
|
23
|
+
],
|
|
5
24
|
"type": "module",
|
|
6
25
|
"main": "dist/index.js",
|
|
7
26
|
"module": "dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
8
28
|
"exports": {
|
|
9
29
|
".": {
|
|
10
30
|
"types": "./dist/index.d.mts",
|
|
@@ -12,50 +32,34 @@
|
|
|
12
32
|
},
|
|
13
33
|
"./client": "./src/client/index.ts"
|
|
14
34
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist",
|
|
17
|
-
"src/client"
|
|
18
|
-
],
|
|
19
|
-
"types": "./dist/index.d.mts",
|
|
20
|
-
"scripts": {
|
|
21
|
-
"dev": "tsdown -w",
|
|
22
|
-
"build": "tsdown --minify",
|
|
23
|
-
"bump": "bumpp --sign",
|
|
24
|
-
"pub": "npm run build && npm publish --registry=https://registry.npmjs.org/",
|
|
25
|
-
"dev:docs": "pnpm -C playground dev"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"vitepress",
|
|
29
|
-
"vitepress-plugin",
|
|
30
|
-
"vitepress plugin",
|
|
31
|
-
"plugin",
|
|
32
|
-
"vue",
|
|
33
|
-
"component",
|
|
34
|
-
"tabs"
|
|
35
|
-
],
|
|
36
35
|
"publishConfig": {
|
|
37
36
|
"access": "public",
|
|
38
37
|
"registry": "https://registry.npmjs.org/"
|
|
39
38
|
},
|
|
40
|
-
"author": "hotdogc1017@gmail.com",
|
|
41
|
-
"license": "MIT",
|
|
42
|
-
"repository": {
|
|
43
|
-
"type": "git",
|
|
44
|
-
"url": "https://github.com/heroui-vue/vitepress-plugin-sfc"
|
|
45
|
-
},
|
|
46
39
|
"devDependencies": {
|
|
47
|
-
"@babel/parser": "8.0.0-rc.5",
|
|
48
|
-
"@babel/traverse": "8.0.0-rc.5",
|
|
49
|
-
"@rolldown/pluginutils": "^1.0.1",
|
|
50
40
|
"@types/markdown-it": "^14.2.0",
|
|
51
41
|
"@types/markdown-it-container": "^2.0.10",
|
|
52
42
|
"@types/node": "^22.17.0",
|
|
53
43
|
"bumpp": "^10.1.0",
|
|
54
44
|
"markdown-it-container": "^4.0.0",
|
|
45
|
+
"oxfmt": "^0.73.0",
|
|
46
|
+
"oxlint": "^1.88.0",
|
|
55
47
|
"tsdown": "0.21.10",
|
|
56
48
|
"typescript": "^5.8.3",
|
|
57
49
|
"unplugin-vue": "^6.2.0",
|
|
58
50
|
"vitepress": "next",
|
|
51
|
+
"vitest": "^5.0.4",
|
|
59
52
|
"vue": "^3.5.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"dev": "tsdown -w",
|
|
56
|
+
"build": "tsdown --minify",
|
|
57
|
+
"bump": "bumpp --sign",
|
|
58
|
+
"pub": "npm run build && npm publish --registry=https://registry.npmjs.org/",
|
|
59
|
+
"dev:docs": "pnpm -C playground dev",
|
|
60
|
+
"fmt": "oxfmt",
|
|
61
|
+
"fmt:check": "oxfmt --check",
|
|
62
|
+
"lint": "oxlint",
|
|
63
|
+
"t": "vitest run tests/output.test.ts"
|
|
60
64
|
}
|
|
61
|
-
}
|
|
65
|
+
}
|
|
@@ -6,176 +6,160 @@ import { useLocaleMappings } from "./useLocaleMappings";
|
|
|
6
6
|
import type { LocaleMappings } from "./useLocaleMappings";
|
|
7
7
|
|
|
8
8
|
const localMappings: LocaleMappings = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
en: {
|
|
10
|
+
previewLabel: "Preview",
|
|
11
|
+
codeLabel: "Source Code",
|
|
12
|
+
},
|
|
13
|
+
zh: {
|
|
14
|
+
previewLabel: "预览",
|
|
15
|
+
codeLabel: "源代码",
|
|
16
|
+
},
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const props = defineProps<{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
src: string;
|
|
21
|
+
highlightedSrc?: string;
|
|
22
|
+
previewLabel?: string;
|
|
23
|
+
codeLabel?: string;
|
|
24
24
|
}>();
|
|
25
25
|
|
|
26
26
|
const { lang } = useData();
|
|
27
27
|
const { get } = useLocaleMappings();
|
|
28
28
|
|
|
29
29
|
const labels = computed(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
] as const;
|
|
30
|
+
const mappings = { ...localMappings, ...get() };
|
|
31
|
+
// Default to English mappings if no locale-specific mappings are found
|
|
32
|
+
const { previewLabel: preview, codeLabel: code } = mappings[lang.value] ?? localMappings.en;
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
label: preview,
|
|
36
|
+
value: "preview",
|
|
37
|
+
},
|
|
38
|
+
{ label: code, value: "code" },
|
|
39
|
+
] as const;
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
const decodedSrc = ref("");
|
|
44
43
|
const highlightedSrc = ref("");
|
|
45
44
|
const activedTab = ref<"preview" | "code">("preview");
|
|
46
|
-
const copied = ref(false);
|
|
47
45
|
const tabGroupId = useId();
|
|
48
46
|
|
|
49
47
|
watch(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
48
|
+
[() => props.src, () => props.highlightedSrc],
|
|
49
|
+
async ([src, highlight = ""]) => {
|
|
50
|
+
try {
|
|
51
|
+
decodedSrc.value = atob(src);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
decodedSrc.value = src;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
highlightedSrc.value = atob(highlight);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
highlightedSrc.value = highlight;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
atob(src);
|
|
64
|
+
} catch (e) {}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
immediate: true,
|
|
68
|
+
},
|
|
71
69
|
);
|
|
72
|
-
|
|
73
|
-
async function copyCode() {
|
|
74
|
-
await navigator.clipboard.writeText(decodedSrc.value);
|
|
75
|
-
copied.value = true;
|
|
76
|
-
setTimeout(() => {
|
|
77
|
-
copied.value = false;
|
|
78
|
-
}, 2000);
|
|
79
|
-
}
|
|
80
70
|
</script>
|
|
81
71
|
|
|
82
72
|
<template>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
:class="`language-vue${activedTab === 'code' ? ' active' : ''}`"
|
|
109
|
-
style="margin: 0px"
|
|
110
|
-
>
|
|
111
|
-
<button title="" class="copy"></button>
|
|
112
|
-
<span class="lang">Vue</span>
|
|
113
|
-
<span v-html="highlightedSrc" />
|
|
114
|
-
</div>
|
|
73
|
+
<div class="vp-component-tabs">
|
|
74
|
+
<header>
|
|
75
|
+
<template v-for="{ label, value } in labels" :key="value">
|
|
76
|
+
<input
|
|
77
|
+
:id="`tab-${tabGroupId}-${value}`"
|
|
78
|
+
type="radio"
|
|
79
|
+
:name="`vp-component-tabs-${tabGroupId}`"
|
|
80
|
+
style="position: fixed; opacity: 0; pointer-events: none"
|
|
81
|
+
:data-checked="activedTab === value" />
|
|
82
|
+
<label :for="`tab-${tabGroupId}-${value}`" @click="activedTab = value">{{ label }}</label>
|
|
83
|
+
</template>
|
|
84
|
+
</header>
|
|
85
|
+
|
|
86
|
+
<main v-show="activedTab === 'preview'">
|
|
87
|
+
<!-- <slot /> -->
|
|
88
|
+
<slot name="v3" />
|
|
89
|
+
</main>
|
|
90
|
+
|
|
91
|
+
<div
|
|
92
|
+
v-show="activedTab === 'code'"
|
|
93
|
+
:class="`language-vue${activedTab === 'code' ? ' active' : ''}`"
|
|
94
|
+
style="margin: 0px">
|
|
95
|
+
<button title="copy source code" class="copy"></button>
|
|
96
|
+
<span class="lang">Vue</span>
|
|
97
|
+
<slot name="highlight" />
|
|
115
98
|
</div>
|
|
99
|
+
</div>
|
|
116
100
|
</template>
|
|
117
101
|
|
|
118
102
|
<style>
|
|
119
103
|
.vp-component-tabs {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
margin: 16px 0;
|
|
105
|
+
display: grid;
|
|
106
|
+
grid-template-columns: 1fr;
|
|
107
|
+
grid-template-rows: min-content 1fr;
|
|
108
|
+
row-gap: 16px;
|
|
125
109
|
}
|
|
126
110
|
|
|
127
111
|
.vp-component-tabs > header {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
display: flex;
|
|
113
|
+
position: relative;
|
|
114
|
+
border-radius: 8px;
|
|
115
|
+
overflow-x: auto;
|
|
116
|
+
overflow-y: hidden;
|
|
133
117
|
}
|
|
134
118
|
|
|
135
119
|
.vp-component-tabs > header input + label {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
120
|
+
box-sizing: border-box;
|
|
121
|
+
display: inline-block;
|
|
122
|
+
position: relative;
|
|
123
|
+
padding: 8px 12px;
|
|
124
|
+
font-size: 14px;
|
|
125
|
+
font-weight: 500;
|
|
126
|
+
color: var(--vp-code-tab-text-color);
|
|
127
|
+
white-space: nowrap;
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
transition:
|
|
130
|
+
color 0.25s,
|
|
131
|
+
background-color 0.25s;
|
|
148
132
|
}
|
|
149
133
|
|
|
150
134
|
.vp-component-tabs > header input + label::after {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
content: "";
|
|
136
|
+
position: absolute;
|
|
137
|
+
height: 4px;
|
|
138
|
+
border-radius: 2px;
|
|
139
|
+
left: 8px;
|
|
140
|
+
right: 8px;
|
|
141
|
+
bottom: -1px;
|
|
142
|
+
transition: background-color 0.25s;
|
|
159
143
|
}
|
|
160
144
|
.vp-component-tabs > header input[data-checked="true"] + label::after {
|
|
161
|
-
|
|
145
|
+
background-color: var(--vp-code-tab-active-bar-color);
|
|
162
146
|
}
|
|
163
147
|
.vp-component-tabs > header input[data-checked="true"] + label,
|
|
164
148
|
.vp-component-tabs > header label:hover {
|
|
165
|
-
|
|
149
|
+
color: var(--vp-code-tab-active-text-color);
|
|
166
150
|
}
|
|
167
151
|
|
|
168
152
|
.vp-component-tabs > main {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
153
|
+
padding: 20px;
|
|
154
|
+
background-color: var(--vp-nav-bg-color);
|
|
155
|
+
border-radius: 8px;
|
|
156
|
+
outline: 1px solid var(--vp-c-divider);
|
|
173
157
|
}
|
|
174
158
|
|
|
175
159
|
.vp-component-tabs > section {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
160
|
+
background-color: var(--vp-code-block-bg);
|
|
161
|
+
border-radius: 8px;
|
|
162
|
+
padding: 24px;
|
|
163
|
+
overflow: auto;
|
|
180
164
|
}
|
|
181
165
|
</style>
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { provide, inject, getCurrentInstance } from "vue";
|
|
2
2
|
import type { App } from "vue";
|
|
3
3
|
|
|
4
|
-
export type LocaleMappings = Record<
|
|
5
|
-
string,
|
|
6
|
-
{ previewLabel: string; codeLabel: string }
|
|
7
|
-
>;
|
|
4
|
+
export type LocaleMappings = Record<string, { previewLabel: string; codeLabel: string }>;
|
|
8
5
|
|
|
9
|
-
const localeMappingSymbol = Symbol(
|
|
10
|
-
"__vitepress_plugin_component_localeMapping",
|
|
11
|
-
);
|
|
6
|
+
const localeMappingSymbol = Symbol("__vitepress_plugin_component_localeMapping");
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
9
|
* Initialize locale mappings for the application.
|