Simple Decision Flow
Basic flowchart for decision-making processes
%% a mermaid renderer for svelte 5
Mermaid Svelte gives you one component: pass it Mermaid source, get an SVG in the DOM. Typed props, a snippet for parse errors, and a dynamic import that keeps mermaid.js out of your server bundle.
$npm i @friendofsvelte/mermaid v0.0.4 · MIT · Svelte 5 runes · mermaid 10
%% this is the published component, not a mockup. Break the syntax and watch the error snippet take over.
%% usage
The component validates the source with mermaid.parse, renders it, and swaps the SVG in. mermaid.js is imported dynamically on the client,
so server builds and prerendering never touch it.
When the source doesn't parse, your error snippet renders instead. No broken half-diagram, no unhandled exception.
npm i @friendofsvelte/mermaid <script>
import { Mermaid } from '@friendofsvelte/mermaid';
const diagram = `graph TD
A[Start] --> B[Process]
B --> C[End]`;
</script>
<Mermaid string={diagram} /> <Mermaid string={diagram}>
{#snippet error(err)}
<p class="diagram-error">
Could not render this diagram: {err.message}
</p>
{/snippet}
</Mermaid> %% what you get
%% api
| prop | type | required | description |
|---|---|---|---|
| string | string | yes | Mermaid source to render |
| config | MermaidConfig | no | Passed to mermaid.initialize before rendering |
| class | string | no | Class applied to the container element |
| error | Snippet<[MermaidError]> | no | Rendered in place of the diagram when parsing fails |
The config prop is a full MermaidConfig. Every diagram on this page uses theme: 'base' with themeVariables so the SVGs match
the site palette instead of Mermaid's defaults.
<script lang="ts">
import { Mermaid, type MermaidConfig } from '@friendofsvelte/mermaid';
const config: MermaidConfig = {
theme: 'base',
themeVariables: {
primaryColor: '#fff1eb',
primaryBorderColor: '#ff3e00'
},
flowchart: { curve: 'basis' }
};
</script>
<Mermaid string={diagram} {config} /> %% examples
Flowcharts, sequence diagrams, Gantt charts, ER schemas: each Svelte 5 Mermaid diagram below is rendered live by the component.
Basic flowchart for decision-making processes
Sequence diagram showing API authentication process
Entity relationship diagram for database design
Pie chart showing market distribution across segments
%% recipes
Mermaid's 'base' theme plus themeVariables lets diagrams pick up your palette instead of the default purple. This page does exactly that.
const config: MermaidConfig = {
theme: 'base',
themeVariables: {
primaryColor: '#fff1eb',
primaryBorderColor: '#ff3e00',
lineColor: '#16181d',
fontFamily: 'IBM Plex Sans, sans-serif'
}
}; The error snippet receives the parse error. Show it inline so a typo in diagram source never leaves an empty hole in your docs.
<Mermaid string={diagram}>
{#snippet error(err)}
<details class="diagram-error">
<summary>Diagram failed to render</summary>
<pre>{err.message}</pre>
</details>
{/snippet}
</Mermaid> useMaxWidth is on by default for flowcharts. Set it per diagram type and wide charts scale down instead of overflowing on mobile.
const config: MermaidConfig = {
flowchart: { useMaxWidth: true },
sequence: { useMaxWidth: true },
gantt: { useMaxWidth: true }
};
<Mermaid string={diagram} {config} />