百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

beautiful-mermaid

> 编程语言
开源

--- 我们为什么要构建这些图表 图表对于人工智能辅助编程至关重要。当您与人工智能编码助手一起工作时,能够查看代码的结构和流程是非常重要的。

10.8K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

--- 我们为什么要构建这些图表 图表对于人工智能辅助编程至关重要。当您与人工智能编码助手一起工作时,能够查看代码的结构和流程是非常重要的。

--- ## 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](https://mermaid.js.org/) 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](https://craft.do) to power diagrams in [Craft Agents](https://agents.craft.do). It's fast, beautiful, and works everywhere—from rich UIs to plain terminals. The ASCII rendering engine is based on [mermaid-ascii](https://github.com/AlexanderGrooff/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`. ### 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: ```tsx 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
{error.message}
return

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

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