File tree 6 files changed +320
-1
lines changed
6 files changed +320
-1
lines changed Original file line number Diff line number Diff line change 29
29
"dependencies" : {
30
30
"@vue-motion/core" : " workspace:*" ,
31
31
"@vue-motion/lib" : " workspace:*" ,
32
+ "shiki" : " ^1.17.6" ,
32
33
"vue" : " ^3.4.26"
33
34
},
34
35
"devDependencies" : {
Original file line number Diff line number Diff line change
1
+ export type { CodeOptions } from './index.vue'
2
+ export { default as Code } from './index.vue'
Original file line number Diff line number Diff line change
1
+ <script setup lang="ts">
2
+ import { defineWidget } from ' @vue-motion/core'
3
+ import { WidgetOptions , widget } from ' @vue-motion/lib'
4
+ import { CodeToHastOptions , codeToHtml } from ' shiki'
5
+ import { ref , useSlots } from ' vue' ;
6
+
7
+ export interface CodeOptions extends WidgetOptions {
8
+ shikiOptions? : CodeToHastOptions
9
+ lang: string
10
+ theme: string
11
+ width: number
12
+ height: number
13
+ }
14
+
15
+ const props = defineProps <CodeOptions >()
16
+ const options = defineWidget <CodeOptions >(props )
17
+
18
+ const slots = useSlots ()
19
+ const codes = slots .default ? slots .default ().map (vnode => vnode .children ).join (' ' ) : ' '
20
+ const content = ref (await codeToHtml (codes , {
21
+ ... options .shikiOptions ,
22
+ lang: options .lang ,
23
+ theme: options .theme ,
24
+ }))
25
+ </script >
26
+
27
+ <template >
28
+ <g v-bind =" widget(options)" >
29
+ <foreignObject x =" 20" y =" 20" :width =" options.width" :height =" options.height" >
30
+ <!--
31
+ In the context of SVG embeded into HTML, the XHTML namespace could
32
+ be avoided, but it is mandatory in the context of an SVG document
33
+ -->
34
+ <div xmlns =" http://www.w3.org/1999/xhtml" style =" color : white " v-html =" content" ></div >
35
+ </foreignObject >
36
+ </g >
37
+ </template >
Original file line number Diff line number Diff line change 19
19
"test" : " pnpm run --filter=* test" ,
20
20
"lint" : " eslint ." ,
21
21
"lint:fix" : " eslint --fix ." ,
22
- "pub:core" : " pnpm run build:core && pnpm run --filter=./packages/* --sort pub"
22
+ "pub:core" : " pnpm run build:core && pnpm run --filter=./packages/* --sort pub" ,
23
+ "preversion" : " pnpm build:core && pnpm build:ext" ,
24
+ "change" : " changeset add" ,
25
+ "release" : " pnpm preversion && changeset version" ,
26
+ "pub" : " changeset publish"
23
27
},
24
28
"devDependencies" : {
25
29
"@antfu/eslint-config" : " ^2.26.0" ,
You can’t perform that action at this time.
0 commit comments