Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

beautiful-mermaid

> 编程语言
Open source

--- Why We Built This Diagrams are essential for AI-assisted programming. When you're working with an AI coding assistant, being able to vi…

10.8K stars0 likes1 views
WebsiteGitHub

About

--- Why We Built This Diagrams are essential for AI-assisted programming. When you're working with an AI coding assistant, being able to vi…


Why We Built This

Diagrams are essential for AI-assisted programming. When you're working with an AI coding assistant, being able to visualize data flows, state machines, and system architecture—directly in your terminal or chat interface—makes complex concepts instantly graspable.

Mermaid is the de facto standard for text-based diagrams. It's brilliant. But the default renderer has problems:

  • Aesthetics — Might be personal preference, but wished they looked more professional
  • Complex theming — Customizing colors requires wrestling with CSS classes
  • No terminal output — Can't render to ASCII for CLI tools
  • Heavy dependencies — Pulls in a lot of code for simple diagrams

We built beautiful-mermaid at Craft to power diagrams in Craft Agents. It's fast, beautiful, and works everywhere—from rich UIs to plain terminals.

The ASCII rendering engine is based on mermaid-ascii by Alexander Grooff. We ported it from Go to TypeScript and extended it. Thank you Alexander for the excellent foundation! (And inspiration that this was possible.)

Features

  • 6 diagram types — Flowcharts, State, Sequence, Class, ER, and XY Charts (bar, line, combined)
  • Dual output — SVG for rich UIs, ASCII/Unicode for terminals
  • Synchronous rendering — No async, no flash. Works with React useMemo()
  • 15 built-in themes — And dead simple to add your own
  • Full Shiki compatibility — Use any VS Code theme directly
  • Live theme switching — CSS custom properties, no re-render needed
  • Mono mode — Beautiful diagrams from just 2 colors
  • Zero DOM dependencies — Pure TypeScript, works everywhere
  • Ultra-fast — Renders 100+ diagrams in under 500ms

Installation

bash
npm install beautiful-mermaid
# or
bun add beautiful-mermaid
# or
pnpm add beautiful-mermaid

Quick Start

SVG Output

typescript
import { renderMermaidSVG } from 'beautiful-mermaid'

const svg = renderMermaidSVG(`
  graph TD
    A[Start] --> B{Decision}
    B -->|Yes| C[Action]
    B -->|No| D[End]
`)

Rendering is fully synchronous — no await, no promises. The ELK.js layout engine runs synchronously via a FakeWorker bypass, so you get your SVG string instantly.

Need async? Use renderMermaidSVGAsync() — same output, returns a Promise<string>.

ASCII Output

typescript
import { renderMermaidASCII } from 'beautiful-mermaid'

const ascii = renderMermaidASCII(`graph LR; A --> B --> C`)
┌───┐     ┌───┐     ┌───┐
│   │     │   │     │   │
│ A │────►│ B │────►│ C │
│   │     │   │     │   │
└───┘     └───┘     └───┘

React Integration

Because rendering is synchronous, you can use useMemo() for zero-flash diagram rendering:

typescript
import { renderMermaidSVG } from 'beautiful-mermaid'

function MermaidDiagram({ code }: { code: string }) {
  const { svg, error } = React.useMemo(() => {
    try {
      return {
        svg: renderMermaidSVG(code, {
          bg: 'var(--background)',
          fg: 'var(--foreground)',
          transparent: true,
        }),
        error: null,
      }
    } catch (err) {
      return { svg: null, error: err instanceof Error ? err : new Error(String(err)) }
    }
  }, [code])

  if (error) return <pre>{error.message}</pre>
  return

Issues· 87 open

View all issuesOpen on GitHub
  • #149

    Support rendering in Web Workers and Cloudflare Workers

    Updated Sep 18, 2026
  • #73

    `require("beautiful-mermaid")` in Node.js throws `ERR_PACKAGE_PATH_NOT_EXPORTED`

    Updated Aug 30, 2026
  • #140

    Bug: `A-->B` (no space before the arrow) parses as a single node `A--` and drops the edge

    Updated Aug 30, 2026
  • #89

    Bug: CJK Characters in Subgraph Title Cause Incorrect Layout (Labels Float to Top)

    Updated Aug 29, 2026
  • #80

    Emit classAssignments as CSS classes on SVG node elements

    Updated Aug 29, 2026
  • #68

    Root nodes in fan-in groups are placed without target-aware grouping, causing edge overlap

    Updated Aug 29, 2026
  • #65

    Root detection in grid layout is order-dependent, misclassifying child nodes as roots

    Updated Aug 29, 2026
  • #64

    A* pathfinding in edge-bundling exhausts memory (Map maximum size exceeded) on dense TD graphs

    Updated Aug 29, 2026
  • #143

    ASCII backend: an edge-less node in a target subgraph merges two subgraph frames and overwrites their titles

    Updated Aug 29, 2026
  • #137

    ASCII output: inline `<i>`/`<b>` tags rendered literally; edges to subgraph IDs create phantom nodes

    Updated Aug 29, 2026

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言