-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<codapi-snippet | ||
engine="mermaid" | ||
sandbox="mermaid" | ||
editor="basic" | ||
output-mode="svg" | ||
output="@next" | ||
></codapi-snippet> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* editor styles */ | ||
.vp-doc .language-mermaid pre { | ||
padding: 0; | ||
} | ||
|
||
.vp-doc .language-mermaid code { | ||
border-radius: 8px; | ||
padding: 20px 24px; | ||
} | ||
|
||
.vp-doc .language-mermaid code:focus::after { | ||
position: absolute; | ||
bottom: 2px; | ||
right: 8px; | ||
content: 'Ctrl+Enter to run'; | ||
color: var(--vp-code-lang-color); | ||
font-family: var(--vp-font-family-base); | ||
font-size: 12px; | ||
font-weight: 500; | ||
} | ||
|
||
/* widget styles */ | ||
codapi-snippet { | ||
display: block; | ||
} | ||
|
||
codapi-toolbar { | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
gap: 1em; | ||
margin-bottom: 1em; | ||
} | ||
codapi-toolbar button { | ||
font-size: 1em; | ||
font-weight: 500; | ||
color: var(--vp-c-brand-1); | ||
text-decoration: none; | ||
text-underline-offset: 2px; | ||
transition: color 0.25s, opacity 0.25s; | ||
} | ||
codapi-toolbar button::after { | ||
content: ' ▶'; | ||
} | ||
.vp-doc codapi-toolbar a { | ||
text-decoration: none; | ||
} | ||
|
||
codapi-status { | ||
display: block; | ||
white-space: nowrap; | ||
} | ||
|
||
.vp-doc codapi-ref a { | ||
color: var(--vp-c-text-1); | ||
font-weight: 400; | ||
text-decoration: underline; | ||
} | ||
|
||
codapi-output { | ||
position: relative; | ||
display: block; | ||
} | ||
codapi-output[hidden] { | ||
display: none; | ||
} | ||
codapi-output a[href='#close'] { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Codapi execution engine for Mermaid. | ||
|
||
import mermaid from 'mermaid'; | ||
|
||
// exec executes a mermaid code snippet. | ||
const exec = async (req) => { | ||
try { | ||
const start = new Date().valueOf(); | ||
const res = await render(req.files['']); | ||
const elapsed = new Date().valueOf() - start; | ||
return { | ||
ok: true, | ||
duration: elapsed, | ||
stdout: res, | ||
stderr: '', | ||
}; | ||
} catch (exc) { | ||
return { | ||
ok: false, | ||
duration: 0, | ||
stdout: '', | ||
stderr: exc.toString(), | ||
}; | ||
} | ||
}; | ||
|
||
// render renders a mermaid diagram according to the spec. | ||
const render = async (spec) => { | ||
const id = 'mermaid-' + hashCode(spec); | ||
const { svg } = await mermaid.render(id, spec); | ||
return svg; | ||
}; | ||
|
||
// hashCode calculates a hashcode for a string. | ||
const hashCode = (s) => { | ||
return s.split('').reduce(function (a, b) { | ||
a = (a << 5) - a + b.charCodeAt(0); | ||
return a & a; | ||
}, 0); | ||
}; | ||
|
||
if (!import.meta.env.SSR) { | ||
// register mermaid execution engine in codapi (client-only). | ||
import('@antonz/codapi/dist/snippet.mjs'); | ||
window.codapi = window.codapi ?? {}; | ||
window.codapi.engines = { | ||
...window.codapi.engines, | ||
...{ mermaid: { init: () => {}, exec } }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.