npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@domphy/mermaid

v0.17.0

Published

Domphy Mermaid - build-time (SSG) and client-side Mermaid diagram rendering, with markdown tree integration for @domphy/markdown

Readme

@domphy/mermaid

domphy.com · Docs · npm

Render Mermaid diagrams for Domphy.

Two complementary paths:

  • Build-time / SSG — render diagrams to inline SVG with a headless browser (via @mermaid-js/mermaid-cli), with an on-disk render cache and a tree integration for @domphy/markdown. Diagrams become plain SVG in your HTML, so the browser ships no Mermaid runtime.
  • Client-side — the mermaidClient() patch renders a diagram in the browser at mount time, using the mermaid library (an optional peer dependency).

Install

pnpm add @domphy/mermaid

@domphy/core is a peer dependency. @mermaid-js/mermaid-cli is a direct dependency and powers the build-time path; it manages its own headless browser (Puppeteer / Chrome) internally, so you do not install or configure Puppeteer yourself. mermaid is an optional peer dependency, needed only for the client-side patch.

Build-time rendering

import { renderMermaidToSvg } from "@domphy/mermaid";

const svg = await renderMermaidToSvg("graph TD; A-->B;", {
  theme: "dark",
  background: "transparent",
});
// svg === "<svg ...>...</svg>"

MermaidOptions:

| Option | Type | Default | | --------------- | --------------------------------------------- | --------------- | | theme | "default" \| "dark" \| "neutral" \| "forest" | "default" | | background | string ("transparent" for none) | "transparent" | | mermaidConfig | Record<string, unknown> | — | | css | string (injected into the render page) | — | | puppeteer | Record<string, unknown> (launch options) | — |

Mermaid syntax errors are thrown as an Error that includes the diagram source, never silently swallowed.

Render cache

import { renderMermaidCached } from "@domphy/mermaid";

// First call renders; later calls with the same source + options read the SVG
// back from disk.
const svg = await renderMermaidCached("graph TD; A-->B;", {
  cacheDir: "node_modules/.cache/domphy-mermaid", // default
});

The cache key is a stable SHA-256 hash of the normalized source plus the output-affecting options (no time or randomness), so repeated builds are fast. Pass cache: false to bypass it.

Markdown tree integration

@domphy/markdown emits a fenced ```mermaid block as:

{ pre: [{ code: "<escaped source>", dataLanguage: "mermaid", class: "language-mermaid" }] }

renderMermaidInTree finds those blocks anywhere in the tree, renders each to SVG (through the cache), and replaces the node with an SVG-wrapping element:

{ div: "<svg ...>...</svg>", class: "mermaid", ariaLabel: "diagram" }
import { parse } from "@domphy/markdown";
import { renderMermaidInTree } from "@domphy/mermaid";

const { body } = parse(markdownSource);
const rendered = await renderMermaidInTree(body, { theme: "neutral" });

All other nodes — siblings, nesting, attributes — are left untouched. Identical diagram sources are rendered only once, and distinct diagrams render concurrently. Inject a custom renderer to test without a browser:

await renderMermaidInTree(body, {
  renderer: async (code) => `<svg data-src="${code}"></svg>`,
});

Client-side patch

Render in the browser instead of at build time:

import { mermaidClient } from "@domphy/mermaid";

const App = {
  pre: [{ code: "graph TD; A-->B;" }],
  $: [mermaidClient({ theme: "dark" })],
};

On mount the patch reads the source from the element (preferring an inner <code>), renders it with the mermaid library, and swaps in the SVG. Install mermaid to use this path:

pnpm add mermaid

License

MIT