
Renders Mermaid diagrams to SVG via native Rust and WebAssembly bindings; supports spacing and classic theme options, includes an editor sample app and build/publishing tooling.
mermaid-rust-kmp provides Kotlin Multiplatform bindings for mermaid-rs-renderer. It renders Mermaid text to SVG strings through native Rust libraries on Android and JVM, or WebAssembly on Kotlin/Wasm.
| Platform | Status |
|---|---|
| Android | Supported |
| JVM / Desktop | Linux x86_64, Windows x86_64, macOS 15+ (Intel and Apple Silicon) |
| Kotlin/Wasm browser | Supported |
| Kotlin/JS | Native rendering is not yet supported |
| iOS | Native rendering is not yet supported |
The published Kotlin Multiplatform library coordinates are:
implementation("io.github.storytellerf:mermaidffi-kmp:<version>")Add the dependency to each source set that renders diagrams. For example, Android and JVM can share a source set:
kotlin {
sourceSets {
val jvmAndAndroidMain by creating {
dependencies {
implementation("io.github.storytellerf:mermaidffi-kmp:<version>")
}
}
}
}Kotlin/Wasm targets also need the npm package published alongside the library:
wasmJsMain.dependencies {
implementation("io.github.storytellerf:mermaidffi-kmp:<version>")
implementation(npm("mermaid-ffi-wasm", "<version>"))
}Import a function from com.storyteller_f.mermaid_kmp, pass Mermaid syntax, and receive SVG text.
import com.storyteller_f.mermaid_kmp.renderMermaid
val svg = renderMermaid(
"""flowchart LR
A[Start] --> B{Decision}
B -->|Yes| C[OK]
B -->|No| D[Cancel]
""".trimIndent(),
)Available APIs:
renderMermaid(input): renders with the default options.renderMermaidWithSpacing(input, nodeSpacing, rankSpacing): adjusts node and rank spacing.renderMermaidClassicTheme(input): renders with the Mermaid default (classic) theme.Calls throw an exception when the underlying renderer cannot process the input. Catch it at your UI or service boundary and present a useful error to the user.
sample/ is a Compose Multiplatform application with Android, Desktop, Web (JS/Wasm), and iOS entry points. It provides a Mermaid editor and displays the resulting SVG text.
cd sample
# Android APK
./gradlew :androidApp:assembleDebug
# Desktop application
./gradlew :desktopApp:run
# Kotlin/Wasm browser application
./gradlew :webApp:wasmJsBrowserDevelopmentRunThe sample's iOS and Kotlin/JS targets display a "Native rendering not yet supported" message. Its Wasm, Android, and JVM targets invoke this library.
Desktop native packaging and validation are documented in DEVELOPMENT.md.
Version 0.0.1-alpha2 includes only the Linux x86_64 native library. The Windows and macOS packaging fix requires a new release.
For source builds, validation and publishing, see DEVELOPMENT.md.
mermaid-rust-kmp provides Kotlin Multiplatform bindings for mermaid-rs-renderer. It renders Mermaid text to SVG strings through native Rust libraries on Android and JVM, or WebAssembly on Kotlin/Wasm.
| Platform | Status |
|---|---|
| Android | Supported |
| JVM / Desktop | Linux x86_64, Windows x86_64, macOS 15+ (Intel and Apple Silicon) |
| Kotlin/Wasm browser | Supported |
| Kotlin/JS | Native rendering is not yet supported |
| iOS | Native rendering is not yet supported |
The published Kotlin Multiplatform library coordinates are:
implementation("io.github.storytellerf:mermaidffi-kmp:<version>")Add the dependency to each source set that renders diagrams. For example, Android and JVM can share a source set:
kotlin {
sourceSets {
val jvmAndAndroidMain by creating {
dependencies {
implementation("io.github.storytellerf:mermaidffi-kmp:<version>")
}
}
}
}Kotlin/Wasm targets also need the npm package published alongside the library:
wasmJsMain.dependencies {
implementation("io.github.storytellerf:mermaidffi-kmp:<version>")
implementation(npm("mermaid-ffi-wasm", "<version>"))
}Import a function from com.storyteller_f.mermaid_kmp, pass Mermaid syntax, and receive SVG text.
import com.storyteller_f.mermaid_kmp.renderMermaid
val svg = renderMermaid(
"""flowchart LR
A[Start] --> B{Decision}
B -->|Yes| C[OK]
B -->|No| D[Cancel]
""".trimIndent(),
)Available APIs:
renderMermaid(input): renders with the default options.renderMermaidWithSpacing(input, nodeSpacing, rankSpacing): adjusts node and rank spacing.renderMermaidClassicTheme(input): renders with the Mermaid default (classic) theme.Calls throw an exception when the underlying renderer cannot process the input. Catch it at your UI or service boundary and present a useful error to the user.
sample/ is a Compose Multiplatform application with Android, Desktop, Web (JS/Wasm), and iOS entry points. It provides a Mermaid editor and displays the resulting SVG text.
cd sample
# Android APK
./gradlew :androidApp:assembleDebug
# Desktop application
./gradlew :desktopApp:run
# Kotlin/Wasm browser application
./gradlew :webApp:wasmJsBrowserDevelopmentRunThe sample's iOS and Kotlin/JS targets display a "Native rendering not yet supported" message. Its Wasm, Android, and JVM targets invoke this library.
Desktop native packaging and validation are documented in DEVELOPMENT.md.
Version 0.0.1-alpha2 includes only the Linux x86_64 native library. The Windows and macOS packaging fix requires a new release.
For source builds, validation and publishing, see DEVELOPMENT.md.