File tree Expand file tree Collapse file tree 3 files changed +303
-269
lines changed
packages/vue-mermaid-render/src/components Expand file tree Collapse file tree 3 files changed +303
-269
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " vue-mermaid-render" ,
33 "type" : " module" ,
4- "version" : " 0.1.2 " ,
5- "packageManager" : " pnpm@8.13 .1" ,
4+ "version" : " 0.1.3 " ,
5+ "packageManager" : " pnpm@8.14 .1" ,
66 "license" : " MIT" ,
77 "repository" : " hojas/vue-mermaid-render" ,
88 "bugs" : " https://github.com/hojas/vue-mermaid-render/issues" ,
3333 "push" : " pnpm build && npm publish"
3434 },
3535 "dependencies" : {
36- "mermaid" : " ^10.6.1 "
36+ "mermaid" : " ^10.7.0 "
3737 },
3838 "devDependencies" : {
39- "@antfu/eslint-config" : " ^2.6.1 " ,
40- "@types/node" : " ^20.10.6 " ,
41- "@vitejs/plugin-vue" : " ^5.0.2 " ,
39+ "@antfu/eslint-config" : " ^2.6.3 " ,
40+ "@types/node" : " ^20.11.5 " ,
41+ "@vitejs/plugin-vue" : " ^5.0.3 " ,
4242 "eslint" : " ^8.56.0" ,
4343 "shelljs" : " ^0.8.5" ,
4444 "typescript" : " ^5.3.3" ,
45- "vite" : " ^5.0.10 " ,
46- "vue" : " ^3.4.3 " ,
45+ "vite" : " ^5.0.12 " ,
46+ "vue" : " ^3.4.15 " ,
4747 "vue-tsc" : " ^1.8.27"
4848 }
4949}
Original file line number Diff line number Diff line change @@ -3,23 +3,40 @@ import { ref, watchEffect } from 'vue'
33import mermaid from ' mermaid'
44import type { MermaidConfig } from ' mermaid'
55
6+ /**
7+ * props
8+ *
9+ * @param {string} content - mermaid graph definition
10+ * @param {MermaidConfig} config - mermaid config
11+ */
612const props = defineProps <{ content: string , config? : MermaidConfig }>()
713
814const el = ref ()
915const mermaidString = ref (' ' )
1016
17+ /**
18+ * generate svg id
19+ */
1120function genSvgId() {
12- const min = Math .ceil (1 )
13- const max = Math .floor (100000 )
14- return ` mermaid-svg-${Math .floor (Math .random () * (max - min + 1 ))}${min } `
21+ const max = 1000000
22+ return ` mermaid-svg-${genId (max )}${genId (max )} `
23+
24+ function genId(max : number ) {
25+ return ~~ (Math .random () * max )
26+ }
1527}
1628
29+ /**
30+ * update graph
31+ * @param graphDefinition - mermaid graph definition
32+ */
1733async function updateGraph(graphDefinition : string ) {
1834 const id = genSvgId ()
1935 const res = await mermaid .render (id , graphDefinition , el .value )
2036 mermaidString .value = res .svg
2137}
2238
39+ // init mermaid
2340watchEffect (() => {
2441 if (! el .value )
2542 return
@@ -30,6 +47,7 @@ watchEffect(() => {
3047 mermaid .initialize ({ startOnLoad: false })
3148})
3249
50+ // update graph
3351watchEffect (() => {
3452 if (! el .value )
3553 return
You can’t perform that action at this time.
0 commit comments