Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
node-version: 22
registry-url: 'https://registry.npmjs.org'

- name: Ensure npm with OIDC support
run: npm install -g npm@latest

- name: Install dependencies
run: npm install

Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.1] - 2026-04-28

### Fixed
### Added

- Sequence diagram rendering (polyfill CSSStyleDeclaration for svgdom)
- Sequence diagram support (mermaid 11.14, svgdom 0.1.23)

### Changed

Expand Down
6 changes: 3 additions & 3 deletions src/mermaid/render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createHash } from 'node:crypto'
import { Resvg } from '@resvg/resvg-js'
import { patchSvgdomStyle } from './style-polyfill.js'

// Patch JSON.stringify to handle circular references (elkjs debug logs)
const originalStringify = JSON.stringify
Expand Down Expand Up @@ -50,8 +49,6 @@ async function loadMermaid() {
win.setInterval = setInterval
win.clearInterval = clearInterval
win.console = console

patchSvgdomStyle(win)
}

// Load and register ELK layout engine
Expand Down Expand Up @@ -117,6 +114,9 @@ export async function renderMermaid(code: string): Promise<Buffer> {
svg = svg.replace(/style="[^"]*max-width:[^;]*;?\s*"/, '')
}

// resvg doesn't support orient="auto-start-reverse" on markers
svg = svg.replace(/orient="auto-start-reverse"/g, 'orient="auto"')

// Convert SVG to PNG with 4x scale for crisp images
const resvg = new Resvg(svg, {
fitTo: {
Expand Down
64 changes: 0 additions & 64 deletions src/mermaid/style-polyfill.ts

This file was deleted.

8 changes: 1 addition & 7 deletions test/mermaid-elk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ flowchart TB
expect(filename).toMatch(/^mermaid-[a-f0-9]{12}\.png$/)
})

it('renders sequence diagrams - regression test for CSSStyleDeclaration polyfill', async () => {
// D3 (bundled in mermaid) calls element.style.removeProperty() during sequence rendering
// svgdom doesn't implement CSSStyleDeclaration, so we polyfill it
// Without the polyfill: TypeError: this.style.removeProperty is not a function
it('renders sequence diagrams', async () => {
const sequenceDiagram = `
sequenceDiagram
participant A as Service A
Expand All @@ -100,13 +97,10 @@ sequenceDiagram
`
const png = await renderMermaid(sequenceDiagram)

// Check PNG magic bytes
expect(png[0]).toBe(0x89)
expect(png[1]).toBe(0x50)
expect(png[2]).toBe(0x4e)
expect(png[3]).toBe(0x47)

// Sequence diagram should render to reasonable size
expect(png.length).toBeGreaterThan(5000)
})

Expand Down