limu is a diagram layout engine in Rust and Go. It reads Mermaid and leaves the drawing to your program.
How it works
Mermaid and Pele, the Mermaid renderer limu is ported from, lay out a diagram and write it as SVG for a browser to draw.
limu stops one step earlier, at the scene. A scene is the laid-out diagram as data. It says what each part is and where it goes, but not how it looks. A backend then draws it. limu has backends for GPUI and MyGo on the GPU, for tiny-skia and Core Graphics into a bitmap, for a terminal’s cells and for SVG, and you can write your own.
Because the scene holds no colors, it's laid out once and can be drawn any number of ways. Switching themes only redraws it, and a backend can also draw each part its own way.
The scene Boxes, paths and labels, with no style.
Kohu Drawn in limu’s light theme.

KohuDark Only the colors change.

Liquid Glass Each part drawn its own way, with MyGo’s glass.

A backend can go further and lay a diagram out again for a look of its own, as mygo-platinum does for the Platinum desktop.
Platinum Laid out again in bitmap faces, and drawn a pixel at a time.

An app can also ask the scene which part is under the pointer.
limu in your app
1cargo add limu limu-gpuilimu-gpui paints a scene in a GPUI window, on the GPU with the rest of the window, and measures its text with GPUI’s text system. The scene tells you which part is under the pointer.
1// Measure text with the window's text system.2let measurer = TextMeasurer::new(window, Fonts::default());3let layout = limu::layout::Options {4 measurer: &measurer,5 ..Default::default()6};7let scene = limu::layout(src, &layout)?;89// In a canvas's paint closure, paint the scene, and find the part at a point.10let o = Options {11 look: Look::new(Theme::KOHU_DARK),12 ..Options::default()13};14paint(&scene, &o, bounds.origin, 1.0, window, cx);15if let Some(i) = scene.item_at(at, 4.0) {16 let it = &scene.items[i];17 println!("clicked {} {:?}", it.role.as_str(), it.id);18}1cargo add limu limu-tiny-skialimu-tiny-skia draws a scene into a bitmap, in font files your program carries, with no GPU and no system libraries. Lay out the diagram with the same fonts you draw it in.
1let fonts = Fonts::new(std::fs::read("Inter-Regular.ttf")?)?;2let layout = limu::layout::Options {3 measurer: &fonts,4 ..Default::default()5};6let scene = limu::layout(src, &layout)?;7let o = Options {8 look: Look::new(Theme::KOHU),9 fonts: Some(&fonts),10 scale: 2.0,11 ..Options::default()12};13let pixmap = limu_tiny_skia::render(&scene, &o).ok_or("too large to draw")?;14pixmap.save_png("diagram.png")?;1cargo add limu limu-asciilimu-ascii lays a diagram out in a terminal’s cells and draws it in box-drawing characters, or in ASCII alone.
1let cells = Cells::default();2let layout = limu::layout::Options {3 measurer: &cells,4 font_size: cells.font_size(),5 snap: Some(cells.grid()),6 max_width: 80.0 * cells.width,7 direction_breakpoint: f64::INFINITY,8 ..Default::default()9};10let scene = limu::layout(src, &layout)?;11print!("{}", limu_ascii::render(&scene, &Options::default())?);1cargo add limulimu::scene::svg writes a scene as SVG and leaves its colors as CSS variables, so a page can restyle it. limu uses only Rust’s standard library.
1let scene = limu::layout(src, &Default::default())?;2let out = svg::render(&scene, &svg::Options {3 look: Look::new(Theme::KOHU),4 ..Default::default()5});1go get github.com/firede/limu/limumygolimumygo draws a scene on the GPU with MyGo’s native UI and tells you which part is under the pointer. Lay out the diagram with the same fonts you draw it in.
1fonts := limumygo.DefaultFonts2sc, err := limu.Layout(src, &layout.Options{Measurer: fonts})3if err != nil {4 return err5}67// Draw the diagram in a view, and see which part was clicked.8w := limumygo.View(c, sc, &limumygo.Options{9 Look: style.Look{Theme: style.KohuDark()},10 Fonts: fonts,11})12if it := w.Clicked(); it != nil {13 fmt.Println("clicked", it.Role, it.ID)14}1go get github.com/firede/limuThe svg package writes a scene as SVG and leaves its colors as CSS variables, so a page can restyle it. limu and the svg package use only Go’s standard library.
1sc, err := limu.Layout(src, nil)2if err != nil {3 return err4}5out := svg.Render(sc, &svg.Options{Look: style.Look{Theme: style.Kohu()}})Explore
Examples
Every type of diagram limu supports, in each of its themes.
Playground
Write a diagram and see it laid out as you type.
Getting started
Lay out your first diagram and render it as SVG.
Theming
Change colors with themes and overrides, or draw parts yourself.
limu and Pele
limu is ported function by function from Pele, the small, fast Mermaid renderer made by the Obsidian team. There are two ports, limu-rs in Rust and limu in Go, and the tests of each check that its layouts match Pele’s number for number. Both are open source under the MIT license, in Rust and in Go.
Pele is named after the goddess of Hawaiʻi’s volcanoes. Limu is the Hawaiian word for the algae in its seas, and this site takes its colors from limu kohu, a red alga that grows in tide pools.