All 30 Mermaid diagram types, parsed, laid out, and rendered in pure Swift — natively on macOS/iOS, Linux, Android, Windows, WebAssembly, and Flutter, plus any bare framebuffer or SDL surface, with byte-identical output.
A MermaidView follows light/dark automatically, sizes to the diagram, caches renders, and describes itself to VoiceOver. That's the whole integration.
.package( url: "https://github.com/2389-research/MermaidKit.git", from: "2.2.0" )
import MermaidRender MermaidView(""" flowchart TD A[Start] --> B{Choice} B -->|yes| C[Do it] B -->|no| D[Skip] """)
The platform-free layout core cross-compiles to every target; a fully-resolved scene crosses the C ABI as a language-neutral JSON contract (SceneWire), and each platform paints it with a thin native renderer. The scene's output is proven byte-identical across the five it compiles to on every push — and a raw raster drives any bare surface beyond them.
macOS, iOS, visionOS. MermaidView and the MermaidRenderer image/PDF/SVG API, drawn with CoreGraphics/CoreText.
Headless Cairo/FontConfig rendering behind the LinuxRaster trait; the platform-free layout runs anywhere Swift does.
MermaidDiagram("…", Modifier.fillMaxWidth()) — one line, themed from MaterialTheme, device-font measured, contentDescription from the narration. JNI over a per-ABI .so, shipped as an AAR.
MermaidNative.Scene("…") → SceneRenderer.Draw(canvas). Real Skia — the same engine as Android — over a P/Invoked Swift DLL. No SVG fallback.
MermaidNative.scene("…") → MermaidPainter on Flutter's Skia canvas, over dart:ffi. One plugin reaches iOS, Android, web, and desktop.
The core compiles to wasm32-unknown-wasi and emits SVG (or a Canvas2D scene) in the browser — the layout engine, running client-side.
A raw RGBA raster with no display server drives a Raspberry Pi framebuffer (/dev/fb0), an SDL2 window, or a GPU texture — see tools/pi-canvas, an infinite pannable canvas.
A conformance harness runs the same fixtures on every platform and asserts one signature. It caught two real cross-platform determinism bugs — and now gates them forever.
The class diagram is the real public API. The sankey hero is the render pipeline. The gitgraph is the actual release history. The same 30 files are the gallery, the lint corpus, and the benchmark suite at once — so the examples can't drift from what the engine does. Follows your system theme.






























Every diagram lowers to a machine-readable geometry scene — boxes, edge routes, label frames. A geometry linter checks the invariants of good layout on every CI run and reports each failure as a named geometric fact, with coordinates.
A regression fails CI as "edge #3 is 165pt inside node DiagramScene" — a coordinate you can act on, not a pixel-diff image or a human squinting at a screenshot.
The same 30 fixtures are the gallery, the lint corpus, and the benchmark suite. The examples on this page cannot drift from what the engine actually does.
Geometry invariants run in CI, so a layout regression can't merge. Most tools rely on eyeballing or pixel snapshots that flake across fonts and OSes — checking geometry is stable, precise, and catches the real defect.
Layout is engineered underneath: network-simplex layer assignment (the strategy Graphviz dot defaults to), label-space reservation during layout, chain straightening after coordinate assignment, and edit-stability proven by scene-diff tests — rename a label to same-width text and nothing else moves.
MermaidView(source, theme:spacing:) — light/dark aware, self-sizing, cached, VoiceOver-described.
MermaidRenderer.image / pdfData / attachmentString — same layout and draw code; vector PDF for crisp export and print.
MermaidRenderer.svg(source:theme:) exports a standalone SVG document for all 30 types. It lowers through RenderScene — a Codable, platform-free render IR — so the SVG backend runs headless on Linux and in CI, and, projected to the SceneWire JSON contract, is the foundation for the shipped native Android and Windows renderers.
altText(source:) generates a deterministic content description for every one of the 30 types; MermaidAltText.narrate(_:) adds a step-by-step walkthrough — decisions, states, ER cardinalities, sequence messages.
DiagramTheme — six colors plus a categorical palette re-skin all 30 types at once; DiagramSpacing sets density.
MermaidParser.diagnose(_:) explains failures with line numbers and did-you-mean suggestions for typo'd headers.
The parse → layout → scene pipeline is platform-free — no AppKit/UIKit. Tools get frames, polylines, and label boxes without rendering a pixel.
DOTParser, DippinParser, SQLDDLParser, and GitLogParser parse Graphviz DOT, Dippin, SQL CREATE TABLE, and raw git log output into the same engine; DOTExporter emits DOT back — a Mermaid ⇄ DOT converter. SQL DDL renders as an ER diagram with PK/FK/UK badges; git log renders as a gitgraph.
The mermaidkit-term CLI draws any Mermaid/DOT/Dippin source in the terminal — Kitty graphics, half-block truecolor, colored box-drawing, or plain ASCII. Platform-free; runs headless on Linux/CI.
Repeat renders hit an in-memory cache keyed by (source, theme, spacing). Input caps mirror mermaid.js — 50,000-character sources, 500 flowchart edges; oversized input returns nil fast. Requires Swift 6.2 / Xcode 26. Platforms: macOS 14+, iOS 17+, visionOS 1+, Linux (via the LinuxRaster package trait), and — via the platform-free scene core — Android, Windows/.NET, Flutter, and WebAssembly, plus any bare framebuffer or SDL/GPU surface.
Where the time goes: drawing (rasterization) is ~75% of a cold render; the parse-and-layout plumbing is lean, with a ~0.2 ms fixed floor. It's profiled, not guessed — the one "obvious" win, an 8-bit sRGB backing store, measured ~2× slower on Apple silicon, so it stayed f16. Full performance analysis →
Unknown dialects degrade to readable monospaced source. Styling directives are ignored, not fatal. Garbage, 100k-character labels, and NaN/Infinity are contained by an adversarial test suite with numeric sanitation at the parser boundary.
A dedicated "parser honesty" effort eliminated silent content loss and phantom content across the parsers — each fix pinned by a regression test using the exact previously-broken syntax.
The same platform-free layout core renders through native backends: CoreGraphics on Apple, Silica/Cairo on Linux, Kotlin Canvas on Android, SkiaSharp on Windows/.NET, a Dart CustomPainter on Flutter, and SVG/Canvas2D on WebAssembly — with the scene's output proven byte-identical across the five it compiles to in CI, and a raw raster for any bare framebuffer/SDL surface.
The README states plainly what parses, what's ignored, and what's a known gap worth filing. SVG export now ships for all 30 types; lower OS floors sit at the top of the roadmap.
Guides, deep-dive engineering notes, and the full history — all on GitHub.