Skip to content

Commit b713f35

Browse files
committed
fix(mermaid): theme config hmr
1 parent dc15531 commit b713f35

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/client/builtin/Mermaid.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ const props = defineProps({
2323
scale: {
2424
default: 1,
2525
},
26+
theme: {
27+
defualt: 'base',
28+
},
2629
})
2730
2831
const vm = getCurrentInstance()
29-
const html = computed(() => renderMermaid(props.code, vm?.attrs || {}))
32+
const html = computed(() => renderMermaid(props.code, Object.assign({ theme: props.theme }, vm.attrs)))
3033
</script>
3134

3235
<template>

packages/client/modules/mermaid.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const nanoid = customAlphabet('abcedfghicklmn', 10)
1010
const cache = new Map<string, string>()
1111

1212
export function renderMermaid(encoded: string, options: any) {
13-
const _cache = cache.get(encoded)
13+
const key = encoded + JSON.stringify(options)
14+
const _cache = cache.get(key)
1415
if (_cache)
1516
return _cache
1617

@@ -22,6 +23,6 @@ export function renderMermaid(encoded: string, options: any) {
2223
const code = decode(encoded)
2324
const id = nanoid()
2425
const svg = mermaid.render(id, code)
25-
cache.set(encoded, svg)
26+
cache.set(key, svg)
2627
return svg
2728
}

0 commit comments

Comments
 (0)