Latest Threat Research:Malicious dYdX Packages Published to npm and PyPI After Maintainer Compromise.Details
Socket
Book a DemoInstallSign in
Socket

@vercel/beautiful-mermaid

Package Overview
Dependencies
Maintainers
375
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vercel/beautiful-mermaid

Render Mermaid diagrams as beautiful SVGs or ASCII art. Ultra-fast, fully themeable, zero DOM dependencies.

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
375
Created
Source

beautiful-mermaid

Render Mermaid diagrams as beautiful SVGs or ASCII art

Ultra-fast, fully themeable, animated, zero DOM dependencies. Built for the AI era.

beautiful-mermaid sequence diagram example

npm version License

Live Demo & Samples

→ Use it live in Craft Agents

Features

  • 5 diagram types — Flowcharts, State, Sequence, Class, and ER diagrams
  • Dual output — SVG for rich UIs, ASCII/Unicode for terminals
  • 17 built-in themes — Including Vercel dark/light, and dead simple to add your own
  • Rank-by-rank animation — Nodes fade in, edges draw in with traveling arrows, CSS + SMIL
  • 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

npm install beautiful-mermaid

Quick Start

SVG Output

import { renderMermaid } from 'beautiful-mermaid'

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

With Animation

const svg = await renderMermaid(diagram, {
  animate: true,  // rank-by-rank animation with sane defaults
})

// Or customize:
const svg = await renderMermaid(diagram, {
  animate: {
    duration: 650,
    stagger: 0,
    nodeOverlap: 0.35,
    nodeAnimation: 'fade-up',
  },
})

ASCII Output

import { renderMermaidAscii } from 'beautiful-mermaid'

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

Browser (Script Tag)

<script src="https://unpkg.com/beautiful-mermaid/dist/beautiful-mermaid.browser.global.js"></script>
<script>
  const { renderMermaid, THEMES } = beautifulMermaid;
  renderMermaid('graph TD; A-->B', { ...THEMES['vercel-dark'], animate: true })
    .then(svg => { ... });
</script>

Theming

The Two-Color Foundation

Every diagram needs just two colors: background (bg) and foreground (fg):

const svg = await renderMermaid(diagram, {
  bg: '#1a1b26',
  fg: '#a9b1d6',
})

Everything else is derived via color-mix().

Enriched Mode

Override specific derived colors:

const svg = await renderMermaid(diagram, {
  bg: '#1a1b26',
  fg: '#a9b1d6',
  line: '#3d59a1',    // Edge/connector color
  accent: '#7aa2f7',  // Arrow heads, highlights
  muted: '#565f89',   // Secondary text, labels
  surface: '#292e42', // Node fill tint
  border: '#3d59a1',  // Node stroke
})

Built-in Themes

17 themes ship out of the box:

import { renderMermaid, THEMES } from 'beautiful-mermaid'

const svg = await renderMermaid(diagram, THEMES['vercel-dark'])
ThemeTypeBackground
vercel-darkDark#0A0A0A
vercel-lightLight#FFFFFF
tokyo-nightDark#1a1b26
tokyo-night-stormDark#24283b
tokyo-night-lightLight#d5d6db
catppuccin-mochaDark#1e1e2e
catppuccin-latteLight#eff1f5
nordDark#2e3440
nord-lightLight#eceff4
draculaDark#282a36
github-lightLight#ffffff
github-darkDark#0d1117
solarized-lightLight#fdf6e3
solarized-darkDark#002b36
one-darkDark#282c34
zinc-darkDark#18181B

Default theme (when no colors provided) is Vercel dark (#0A0A0A / #EDEDED).

Shiki Compatibility

Use any VS Code theme via Shiki:

import { getSingletonHighlighter } from 'shiki'
import { renderMermaid, fromShikiTheme } from 'beautiful-mermaid'

const hl = await getSingletonHighlighter({ themes: ['vitesse-dark'] })
const colors = fromShikiTheme(hl.getTheme('vitesse-dark'))
const svg = await renderMermaid(diagram, colors)

Animation

Pass animate: true for rank-by-rank animation with sane defaults, or customize with AnimationOptions.

How It Works

  • Nodes fade in rank-by-rank (top → bottom)
  • Edges draw in via stroke-dashoffset with pathLength="1"
  • Arrow tips travel along the path via SMIL <animateMotion>, synced with edge easing
  • Subgroups fade in after their contents are mostly visible
  • Cascade: source node → edge draws → target node appears (with configurable overlap)

All CSS-based (works in standalone SVG files, no JS runtime needed). SMIL used only for arrow travel.

AnimationOptions

interface AnimationOptions {
  duration?: number        // Each element's animation duration (ms). Default: 650
  stagger?: number         // Delay between consecutive elements (ms). Default: 0
  nodeOverlap?: number     // How early node appears before incoming edge finishes
                           // (0 = wait, 0.5 = halfway, 1 = with edge). Default: 0.35
  groupDelay?: number      // Extra offset for group container (ms). Default: 110
  nodeEasing?: string      // CSS easing for nodes/groups. Default: 'ease'
  edgeEasing?: string      // CSS easing for edge draw-in + arrow travel. Default: 'ease-in-out'
  nodeAnimation?: string   // 'fade' | 'fade-up' | 'scale' | 'none'. Default: 'fade'
  edgeAnimation?: string   // 'draw' | 'fade' | 'none'. Default: 'draw'
  reducedMotion?: boolean  // Respect prefers-reduced-motion. Default: true
}

Easing Design

ElementEasingRationale
Nodes/groupsnodeEasingElements "appear" — deceleration curve
Edge linesedgeEasingLines "flow" — acceleration/deceleration
Arrow tipsauto-derived from edgeEasingSMIL keySplines converted from CSS cubic-bezier, guaranteed sync
Edge labelsnodeEasingLabels are content, not motion

Accessibility

When reducedMotion: true (default), a @media (prefers-reduced-motion: reduce) block disables all animations, showing the diagram instantly.

Layout & Styling Options

RenderOptions

OptionTypeDefaultDescription
bgstring#0A0A0ABackground color
fgstring#EDEDEDForeground color
linestring?Edge/connector color
accentstring?Arrow heads, highlights
mutedstring?Secondary text, labels
surfacestring?Node fill tint
borderstring?Node stroke color
fontstringGeistFont family
fontSizenumber19.2Node label font size (px)
fontWeightnumber400Node label font weight
letterSpacingnumber-0.384Node label letter spacing (px)
edgeFontSizenumber10Edge label font size (px)
nodePaddingXnumber24Horizontal padding inside nodes (px)
nodePaddingYnumber24Vertical padding inside nodes (px)
cornerRadiusnumber6Node corner radius (px)
lineWidthnumber1.5Edge stroke width (px)
edgeBendRadiusnumber8Rounded corners on edge bends (px)
paddingnumber80Canvas padding (px)
nodeSpacingnumber40Horizontal spacing between nodes (px)
layerSpacingnumber50Vertical spacing between layers (px)
transparentbooleanfalseTransparent background
animateboolean | AnimationOptionsfalseEnable animation

Subgraph Options

OptionTypeDefaultDescription
groupFontstringGeist MonoSubgraph header font family
groupFontSizenumber16Subgraph header font size (px)
groupFontWeightnumber600Subgraph header font weight
groupTextTransformstringuppercaseSubgraph header text transform
groupCornerRadiusnumber3Subgraph corner radius (px)
groupBorderColorstring#454545Subgraph border color
groupPaddingXnumber32Subgraph horizontal padding (px)
groupPaddingYnumber32Subgraph vertical padding (px)

Subgraph backgrounds use a diagonal hatching pattern.

Supported Diagrams

Flowcharts

graph TD
  A[Start] --> B{Decision}
  B -->|Yes| C[Process]
  B -->|No| D[End]

All directions: TD, LR, BT, RL. Subgraphs supported.

State Diagrams

stateDiagram-v2
  [*] --> Idle
  Idle --> Processing: start
  Processing --> Complete: done
  Complete --> [*]

Sequence Diagrams

sequenceDiagram
  Alice->>Bob: Hello Bob!
  Bob-->>Alice: Hi Alice!

Class Diagrams

classDiagram
  Animal <|-- Duck
  Animal: +int age
  Duck: +swim()

ER Diagrams

erDiagram
  CUSTOMER ||--o{ ORDER : places
  ORDER ||--|{ LINE_ITEM : contains

ASCII Output

import { renderMermaidAscii } from 'beautiful-mermaid'

const unicode = renderMermaidAscii(`graph LR; A --> B`)
const ascii = renderMermaidAscii(`graph LR; A --> B`, { useAscii: true })
OptionTypeDefaultDescription
useAsciibooleanfalseASCII instead of Unicode
paddingXnumber5Horizontal node spacing
paddingYnumber5Vertical node spacing
boxBorderPaddingnumber1Inner box padding

Attribution

ASCII rendering based on mermaid-ascii by Alexander Grooff (ported from Go, extended with sequence/class/ER support).

License

MIT — see LICENSE for details.

Built with care by the team at Craft

Keywords

mermaid

FAQs

Package last updated on 13 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts