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

@render-policy/mermaid

v0.1.8

Published

Strict Mermaid diagrams for @render-policy/core: rendered in securityLevel strict without HTML labels, sanitized as SVG, isolated in a shadow root.

Readme

@render-policy/mermaid

Strict Mermaid diagrams for @render-policy/core. Models emit ```mermaid blocks all the time; rendering them is the one place where "sanitize the Markdown" is not enough, because the diagram library itself produces markup from untrusted text.

import { createRenderer } from '@render-policy/core';
import { createMermaidTransform } from '@render-policy/mermaid';
import mermaid from 'mermaid';

const renderer = createRenderer({
  transforms: [createMermaidTransform({ mermaid, config: { theme: 'neutral' } })],
});
renderer.renderMarkdownInto(element, message.content);

What the transform guarantees, whatever the diagram source says:

  • mermaid runs with securityLevel: 'strict', no HTML labels (so no foreignObject), no error diagram injected into the page, nothing rendered on load; config cannot override these;
  • the SVG mermaid produced goes through an SVG-only sanitizer: no <a>, <script>, <foreignObject>, <image>, <use> or animations, no href, no data-*, no stylesheet or inline style that imports, fetches an external url() or targets :host; the root <svg> gets a fixed style;
  • the result lives in a shadow root inside a contain: paint wrapper: the diagram's stylesheet cannot reach the host page, the host page's CSS does not break the diagram, and nothing inside can overlay the page;
  • the original code block stays as the wrapper's light DOM, so streaming keeps a finished diagram in place, and a block whose fence is still open is left as code until it closes;
  • a diagram that fails to parse stays a code block, and the failure is journaled through onDecision, with codes diagram-render-failed, diagram-element-not-allowed, diagram-attribute-not-allowed, diagram-style-escapes and diagram-root-not-svg.

Renders are cached by source (cacheSize, default 50; the least recently used diagram is evicted first, so a diagram a stream keeps re-rendering stays cached; 0 turns the cache off). Diagram languages other than mermaid can be mapped with languages.

Bring your own mermaid (peer dependency, 11 or later) and load it lazily if bundle size matters; the transform only needs initialize and render. The browser proof in e2e/run.mjs runs the real mermaid in Chromium against click handlers, label injection, themeCSS directives, positioning through classDef, invalid input and streaming.

Works with mermaid 11 and 12. Mermaid 12 lays diagrams out with ELK by default and recolours them; pass config: { layout: 'dagre', theme: 'default', look: 'classic' } to keep the mermaid 11 look. The strict settings win over config either way.