Skip to content
D
Documentation

SvgExportOptions

reference
2 min readUpdated

Import it from @grafloria/renderer.

ts
interface SvgExportOptions

Properties

NameTypeDefaultDescription
theme?ThemeThe theme whose values get baked into the output. MUST be the theme the tree was rendered with — it is the source of every --grafloria-* value the live stylesheet would have supplied. Defaults to LIGHT_THEME.
scale?numberMultiplies the SVG's width/height (its intrinsic size) while the viewBox stays put — so the picture is unchanged, just rendered larger. This is what makes a 2x PNG a 2x PNG.
backgroundColor?stringPainted as a full-viewBox rect behind everything. Default: transparent.
foreignObject?ForeignObjectModeWhat to do with <foreignObject> subtrees. Default 'serialize'.
captureForeignObject?(vnode: VNode) => string | undefinedSupply the live HTML inside a foreignObject (browser-side callers).
customNodes?readonly CustomNodeCapture[]CUSTOM-NODE CONTENT — the widgets an HTML-layer node paints, which the VNode tree does not contain and cannot contain (the renderer emits an empty <g> for those nodes; the page paints a raw HTML host that is a SIBLING of the SVG).
htmlFallback?HtmlFallbackModeWhat to do with a custom node that could only be captured as HTML. Default 'foreignObject'. Whatever you choose, it is REPORTED in warnings — a widget that cannot make it into the file faithfully never does so quietly.
embedFontCss?stringCSS emitted verbatim into a <style> inside <defs>. THE font seam: pass an @font-face whose src is a data: URI and the exported file carries its own glyphs. We do not fetch, subset or embed fonts for you — that is a deliberate boundary, not an oversight.
embedFonts?FontSource[]Fonts to EMBED as base64 @font-face rules — the built form of the embedFontCss seam. Both are honoured; embedFontCss is appended after these.
fitToContent?booleanFit the viewBox to the CONTENT — the union box of everything the tree actually draws (labels, ports and arrowheads included), not the root's own viewBox.
padding?numberMargin around the fitted content box, in world units. Default 20.
includeIds?Iterable<string>Export ONLY these node/link ids. The tree is pruned to them (not merely cropped — an un-selected node outside the viewBox is invisible but its markup, and its labels, would still be in the bytes) and the box is fitted around them.
viewBox?RectangleUse this exact viewBox and fit nothing. Wins over fitToContent.
maxSize?numberCap on the output's intrinsic size, per side, in px. Default 4000. The scale is REDUCED to fit rather than the picture being cropped — see clampOutputSize.
minSize?numberFloor on the output's intrinsic size, per side, in px. Default 1.
xmlDeclaration?booleanPrepend the <?xml …?> prolog. Default false (an inline <svg> must not have one).
embedModel?DiagramDocumentEnvelopeEmbed this document envelope in the SVG's <metadata>, making the exported file an EDITABLE artifact: re-import it and get the diagram back, losslessly.

Was this page helpful?

SvgExportOptions — Grafloria