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.

A renderer of SVG

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.

limu

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.

One scene, laid out once and drawn four ways

The scene Boxes, paths and labels, with no style.

approvereviseDraftReviewShip

Kohu Drawn in limu’s light theme.

Drawn in limu’s light theme.

KohuDark Only the colors change.

Only the colors change.

Liquid Glass Each part drawn its own way, with MyGo’s 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.

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

cargo add limu limu-gpui

limu-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.

// Measure text with the window's text system.let measurer = TextMeasurer::new(window, Fonts::default());let layout = limu::layout::Options {    measurer: &measurer,    ..Default::default()};let scene = limu::layout(src, &layout)?;// In a canvas's paint closure, paint the scene, and find the part at a point.let o = Options {    look: Look::new(Theme::KOHU_DARK),    ..Options::default()};paint(&scene, &o, bounds.origin, 1.0, window, cx);if let Some(i) = scene.item_at(at, 4.0) {    let it = &scene.items[i];    println!("clicked {} {:?}", it.role.as_str(), it.id);}
go get github.com/firede/limu/limumygo

limumygo 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.

fonts := limumygo.DefaultFontssc, err := limu.Layout(src, &layout.Options{Measurer: fonts})if err != nil {	return err}// Draw the diagram in a view, and see which part was clicked.w := limumygo.View(c, sc, &limumygo.Options{	Look:  style.Look{Theme: style.KohuDark()},	Fonts: fonts,})if it := w.Clicked(); it != nil {	fmt.Println("clicked", it.Role, it.ID)}

Explore

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.