@slidev/client 0.40.6 → 0.40.7

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.
@@ -13,7 +13,7 @@ pie
13
13
  -->
14
14
 
15
15
  <script setup lang="ts">
16
- import { computed, getCurrentInstance, ref, watch, watchEffect } from 'vue'
16
+ import { getCurrentInstance, ref, watch, watchEffect } from 'vue'
17
17
  import { renderMermaid } from '../modules/mermaid'
18
18
  import ShadowRoot from '../internals/ShadowRoot.vue'
19
19
  import { isDark } from '../logic/dark'
@@ -26,14 +26,24 @@ const props = defineProps<{
26
26
 
27
27
  const vm = getCurrentInstance()
28
28
  const el = ref<HTMLDivElement>()
29
- const svgObj = computed(() => renderMermaid(
30
- props.code || '',
31
- {
32
- theme: props.theme || (isDark.value ? 'dark' : undefined),
33
- ...vm!.attrs,
34
- },
35
- ))
36
- const html = computed(() => svgObj.value)
29
+ const html = ref('')
30
+
31
+ watchEffect(async (onCleanup) => {
32
+ let disposed = false
33
+ onCleanup(() => {
34
+ disposed = true
35
+ })
36
+ const svg = await renderMermaid(
37
+ props.code || '',
38
+ {
39
+ theme: props.theme || (isDark.value ? 'dark' : undefined),
40
+ ...vm!.attrs,
41
+ },
42
+ )
43
+ if (!disposed)
44
+ html.value = svg
45
+ })
46
+
37
47
  const actualHeight = ref<number>()
38
48
 
39
49
  watch(html, () => {
@@ -1,4 +1,4 @@
1
- import mermaid from 'mermaid/dist/mermaid'
1
+ import mermaid from 'mermaid/dist/mermaid.esm.mjs'
2
2
  import { customAlphabet } from 'nanoid'
3
3
  import { decode } from 'js-base64'
4
4
  import { clearUndefined } from '@antfu/utils'
@@ -10,7 +10,7 @@ mermaid.initialize({ startOnLoad: false })
10
10
  const nanoid = customAlphabet('abcedfghicklmn', 10)
11
11
  const cache = new Map<string, string>()
12
12
 
13
- export function renderMermaid(encoded: string, options: any) {
13
+ export async function renderMermaid(encoded: string, options: any) {
14
14
  const key = encoded + JSON.stringify(options)
15
15
  const _cache = cache.get(key)
16
16
  if (_cache)
@@ -23,7 +23,7 @@ export function renderMermaid(encoded: string, options: any) {
23
23
  })
24
24
  const code = decode(encoded)
25
25
  const id = nanoid()
26
- const svg = mermaid.render(id, code) as string
26
+ const { svg } = await mermaid.render(id, code)
27
27
  cache.set(key, svg)
28
28
  return svg
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/client",
3
- "version": "0.40.6",
3
+ "version": "0.40.7",
4
4
  "description": "Presentation slides for developers",
5
5
  "author": "antfu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@antfu/utils": "^0.7.2",
19
- "@unocss/reset": "^0.50.6",
19
+ "@unocss/reset": "^0.51.0",
20
20
  "@vueuse/core": "^9.13.0",
21
21
  "@vueuse/head": "^1.1.23",
22
22
  "@vueuse/math": "^9.13.0",
@@ -29,20 +29,20 @@
29
29
  "js-base64": "^3.7.5",
30
30
  "js-yaml": "^4.1.0",
31
31
  "katex": "^0.16.4",
32
- "mermaid": "^9.4.3",
32
+ "mermaid": "^10.1.0",
33
33
  "monaco-editor": "^0.33.0",
34
34
  "nanoid": "^4.0.2",
35
35
  "prettier": "^2.8.7",
36
36
  "recordrtc": "^5.6.2",
37
- "resolve": "^1.22.1",
38
- "unocss": "^0.50.6",
37
+ "resolve": "^1.22.2",
38
+ "unocss": "^0.51.0",
39
39
  "vite-plugin-windicss": "^1.8.10",
40
40
  "vue": "^3.2.47",
41
41
  "vue-router": "^4.1.6",
42
42
  "vue-starport": "^0.3.0",
43
43
  "windicss": "^3.5.6",
44
- "@slidev/parser": "0.40.6",
45
- "@slidev/types": "0.40.6"
44
+ "@slidev/parser": "0.40.7",
45
+ "@slidev/types": "0.40.7"
46
46
  },
47
47
  "devDependencies": {
48
48
  "vite": "^4.2.1"
package/shim.d.ts CHANGED
@@ -15,3 +15,8 @@ declare module '/@slidev/configs' {
15
15
  import { SlidevConfig } from '@slidev/types'
16
16
  export default SlidevConfig
17
17
  }
18
+
19
+ declare module 'mermaid/dist/mermaid.esm.mjs' {
20
+ import Mermaid from 'mermaid/dist/mermaid.d.ts'
21
+ export default Mermaid
22
+ }