@friendofsvelte/mermaid

中文文档
0.0.4发布于 2025/09/04TypeScriptES Module近 30 天下载 9565

A powerful, type-safe Mermaid.js component for Svelte 5 with SSR support, custom themes, and responsive design.

原始使用文档
文档目录15 节
  1. Features
  2. Installation
  3. Quick Start
  4. Advanced Usage
  5. API Reference
  6. Props
  7. Types
  8. Supported Diagram Types
  9. Examples
  10. Custom Theme
  11. Error Handling
  12. Development
  13. Contributing
  14. License
  15. Links

@friendofsvelte/mermaid

A powerful, type-safe Mermaid.js component for Svelte 5 with SSR support, custom themes, and responsive design.

npm version License: MIT

Features

  • ⚡ Lightning Fast - Dynamic imports and optimized rendering
  • 🎨 Fully Customizable - Complete theme control and configuration
  • 📱 Responsive Ready - Built-in responsive behavior
  • 🔒 Type Safe - Full TypeScript support with strict typing
  • 🧪 Test Friendly - E2E tested with Playwright
  • 🚀 SSR Compatible - Works with SvelteKit SSR and static generation

Installation

npm install @friendofsvelte/mermaid

Quick Start

<script>
  import { Mermaid } from '@friendofsvelte/mermaid';
  
  const diagram = `graph TD
    A[Start] --> B[Process]
    B --> C[End]`;
</script>

<Mermaid string={diagram} />

Advanced Usage

<script>
  import { Mermaid } from '@friendofsvelte/mermaid';
  import type { MermaidConfig } from '@friendofsvelte/mermaid';
  
  const config: MermaidConfig = {
    theme: 'dark',
    flowchart: {
      useMaxWidth: true,
      htmlLabels: true
    }
  };
  
  const diagram = `sequenceDiagram
    participant A as Alice
    participant B as Bob
    A->>B: Hello Bob!
    B-->>A: Hello Alice!`;
</script>

<Mermaid string={diagram} {config} />

API Reference

Props

PropTypeRequiredDescription
stringstringYesThe Mermaid diagram definition string
configMermaidConfigNoMermaid configuration options
errorSnippet<[MermaidError]>NoError display snippet

Types

interface MermaidConfig {
  theme?: 'default' | 'dark' | 'forest' | 'neutral' | 'base';
  flowchart?: {
    useMaxWidth?: boolean;
    htmlLabels?: boolean;
    curve?: string;
  };
  sequence?: {
    useMaxWidth?: boolean;
    actorMargin?: number;
  };
  // ... and more
}

interface MermaidError {
  message: string;
  stack?: string;
}

Supported Diagram Types

  • Flowcharts - Process flows and decision trees
  • Sequence Diagrams - API interactions and workflows
  • Gantt Charts - Project timelines and scheduling
  • User Journey Maps - UX flows and customer experience
  • Entity Relationship Diagrams - Database schemas
  • Git Graphs - Version control workflows
  • Pie Charts - Data visualization
  • Class Diagrams - Object-oriented design

Examples

Custom Theme

<script>
  import { Mermaid } from '@friendofsvelte/mermaid';
  
  const customConfig = {
    theme: 'dark',
    flowchart: {
      useMaxWidth: true,
      htmlLabels: true,
      curve: 'basis'
    }
  };
</script>

<Mermaid string={diagram} config={customConfig} />

Error Handling

<script>
  import { Mermaid } from '@friendofsvelte/mermaid';
  
  const invalidDiagram = `invalid syntax here`;
</script>

<Mermaid string={invalidDiagram}>
  {#snippet error(errorObj)}
    <div class="error-message">
      <p>Failed to render diagram: {errorObj.message}</p>
    </div>
  {/snippet}
</Mermaid>

Development

# Clone the repository
git clone https://github.com/friendofsvelte/mermaid.git
cd mermaid

# Install dependencies
npm install

# Start development server
npm run dev

# Run tests
npm run test

# Build library
npm run build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT © Friend of Svelte


Built with ❤️ for the Svelte community.

版本与发布记录

@friendofsvelte/mermaid 共发布 4 个版本,首次发布于 2025/08/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.4latest2025/09/041.2 年前
0.0.32025/08/291.2 年前
0.0.22025/08/291.2 年前
0.0.12025/08/291.2 年前

关于 @friendofsvelte/mermaid 的常见问题

@friendofsvelte/mermaid 是什么?

A powerful, type-safe Mermaid.js component for Svelte 5 with SSR support, custom themes, and responsive design.

如何安装 @friendofsvelte/mermaid?

在项目目录运行 npm install @friendofsvelte/mermaid,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:svelte(^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@friendofsvelte/mermaid 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@friendofsvelte/mermaid 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@friendofsvelte/mermaid 可以商用吗?

@friendofsvelte/mermaid 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@friendofsvelte/mermaid 的下载量有多少?

根据 npm 官方下载统计,@friendofsvelte/mermaid 在 2026/10/16 – 2026/11/14 这 30 天内被下载 9,565 次,日均约 319 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@friendofsvelte/mermaid 还在维护吗?

最新版本 0.0.4 发布于 2025/09/04(1.2 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。