This repository includes helper scripts to compare our experimental renderer (Maid) with Mermaid CLI for visual parity. Use this guide when you need to debug or improve rendering fidelity across diagram types.
- Node.js ≥ 18
- Project built:
npm run build - Mermaid CLI is installed via devDependencies and used by the scripts.
- PNG rasterizer (any of the following):
@resvg/resvg-js(preferred, bundled as devDependency) — used when availablersvg-convert(librsvg) or ImageMagickconvertas fallbacks
Optional:
- Puppeteer no-sandbox config exists at
scripts/puppeteer-ci.json(used by Mermaid CLI to run headless safely).
For each valid diagram fixture, the scripts:
- Render the diagram with Mermaid CLI to SVG (and then to PNG)
- Render the same diagram with Maid to SVG (and then to PNG)
- Save both outputs side-by-side
- Produce a structural summary (counts of
<path>,<rect>, colors, viewBox, etc.) and a diff JSON
Outputs live under .tmp-compare-all/<type>/<name>/:
<name>.mermaid.svg/<name>.mermaid.png<name>.maid.svg/<name>.maid.pngsummary.mermaid.json/summary.maid.jsondiff.json— tag deltas, palette differences, viewBoxA/B
A top-level .tmp-compare-all/REPORT.json indexes all items.
Always build first:
npm run build
Compare a single type (recommended for iteration):
# sequence | flowchart | pie
npm run compare:renderers:sequence
Compare all supported types:
npm run compare:renderers
Compare one diagram quickly and print a summary (SVG only):
node scripts/compare-render-svg.js test-fixtures/sequence/valid/basic.mmd
This writes Mermaid/Maid SVGs to .tmp-compare/ and prints shape/color counts to stdout.
- Pick a target set (e.g., sequence). Run:
npm run build
npm run compare:renderers:sequence
-
Open the PNGs for a diagram that looks off (e.g.,
.tmp-compare-all/sequence/alt-minimal/).- Check
diff.jsonto see what’s different (viewBox, tag counts, color set). - Check
summary.*.jsonto confirm differences are consistent.
- Check
-
Tweak renderer code:
- Layout:
src/renderer/*-layout.ts - SVG drawing:
src/renderer/svg-generator.ts(flowchart) orsrc/renderer/sequence-renderer.ts/pie-renderer.ts - Theming/CSS:
src/renderer/index.tstheme mappers and default styles
- Layout:
-
Re-run comparison for the single type. Iterate until PNGs/metrics converge.
-
When satisfied, regenerate previews and ensure CI matches snapshots:
npm run build
npm run generate:previews
git add -A && git commit -m "chore(previews): regenerate after renderer tweaks"
tagDelta— Differences in element counts. Large gaps often indicate extra wrappers or missing shapes.fills/strokes— Palette differences. Color mismatches may come from default CSS or theme variables.viewBoxA/B— SVG coordinate systems. If they differ greatly, normalize margins/padding in the renderer.
- Mermaid CLI sometimes returns an error page with exit code 0. The scripts handle this internally, but if you see odd SVGs, open them to confirm.
- If PNGs are not produced, ensure one of these is available:
@resvg/resvg-js,rsvg-convert, orconvert(ImageMagick). - Long runs: Puppeteer rendering can be slow. Prefer per-type comparisons while iterating.
- Previews:
npm run ci:previewsregenerates previews and fails on drift. - Tests:
npm run ci:testruns error-code tests and renderer smoke tests.
npm run build && \
npm run compare:renderers:sequence && \
code .tmp-compare-all/sequence/basic && \
code src/renderer/sequence-renderer.ts && \
npm run build && \
npm run compare:renderers:sequence