Shumoku Docs

ドキュメントを検索

共通文書と現行公開版

検索を読み込み中…

English

libs/@shumoku/renderer-svg/README.md

@shumoku/renderer-svg

Generate SVG topology diagrams.

日本語版はまだありません。英語の原文を表示しています。

SVG compatibility and pipeline package for Shumoku. Its public pipeline functions render ResolvedLayout through the canonical @shumoku/renderer static SVG implementation shared by CLI, HTML, PNG, server output, Editor export, and Playground. The older LayoutResult renderer remains available as an explicitly deprecated compatibility layer.

Install

npm install @shumoku/renderer-svg @shumoku/core

Quick start

import { YamlParser } from '@shumoku/core'
import { prepareRender, renderSvg, renderGraphToSvg } from '@shumoku/renderer-svg'

const { graph } = new YamlParser().parse(yaml)

// One-liner
const svg = await renderGraphToSvg(graph)

// Or split the pipeline — `prepared` can feed SVG, HTML, and PNG renderers
const prepared = await prepareRender(graph) // resolves icon dimensions + computes layout
const svg2 = await renderSvg(prepared)

Pipeline

FunctionDescription
prepareRender(graph, options?)PreparedRender. Resolves icon dimensions (CDN fetch + cache) and computes layout
renderSvg(prepared, options?)→ canonical SVG when prepared.resolved is available; legacy fallback otherwise
renderGraphToSvg(graph, options?)Canonical graph-to-SVG convenience API
renderEmbeddable(prepared, options?){ svg, css, … } for embedding in a web app with scoped styles

All four are async (icon resolution may fetch over the network).

Icon utilities

resolveAllIconDimensions, fetchIconAsDataUrl, fetchImageDimensions, clearIconCache, DEFAULT_ICON_FETCH_TIMEOUT, and collectIconUrls are exported for callers that manage icon fetching themselves (e.g. a server resolving dimensions ahead of time).

SVGRenderer / LegacySVGRenderer and the synchronous svg.render(graph, layout) namespace API are deprecated compatibility surfaces for callers that only have the old LayoutResult. They now live behind the explicit @shumoku/renderer-svg/legacy boundary. Root re-exports remain temporarily for source compatibility. New code should use the pipeline functions above or @shumoku/renderer/static directly.

Legacy removal boundary

The old LayoutResult renderer is isolated in src/svg.ts and exported only through src/legacy.ts. Canonical icon discovery lives separately, so server and pipeline callers do not depend on the old renderer for utility functions. HTML and PNG compatibility fallbacks import the explicit /legacy subpath; their normal ResolvedLayout paths use @shumoku/renderer/static.

Once root compatibility can be broken, removal is limited to deleting the /legacy export and fallback branches, followed by deleting src/legacy.ts and src/svg.ts. The boundary test prevents new direct imports of the implementation.

License

AGPL-3.0-only. For commercial licensing, contact contact@shumoku.dev.