feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+30
View File
@@ -0,0 +1,30 @@
import { clearUndefined } from '@antfu/utils'
import lz from 'lz-string'
import mermaid from 'mermaid/dist/mermaid.esm.mjs'
import { makeId } from '../logic/utils'
import setupMermaid from '../setup/mermaid'
mermaid.startOnLoad = false
mermaid.initialize({ startOnLoad: false })
const cache = new Map<string, string>()
let containerElement: Element | undefined
export async function renderMermaid(lzEncoded: string, options: any) {
containerElement ??= document.getElementById('mermaid-rendering-container')!
const key = lzEncoded + JSON.stringify(options)
const _cache = cache.get(key)
if (_cache)
return _cache
mermaid.initialize({
startOnLoad: false,
...clearUndefined(await setupMermaid() || {}),
...clearUndefined(options),
})
const code = lz.decompressFromBase64(lzEncoded)
const id = makeId()
const { svg } = await mermaid.render(id, code, containerElement)
cache.set(key, svg)
return svg
}