Skip to content

embedIcons

function embedIcons(params): Promise<string>;

Defined in: src/utils/iconEmbedder.ts:164

Embed external icon URLs in SVG as base64 data URIs

This function scans the SVG for external image references (href attributes) and replaces them with inline base64-encoded data URIs. This ensures icons display correctly in standalone SVG files, PNG exports, and contexts where external resources are blocked by security policies.

Each distinct URL is fetched once, with at most six fetches in flight at a time, and every occurrence is rewritten in a single pass over the SVG.

EmbedIconsParams

Parameters for icon embedding

Promise<string>

Promise resolving to SVG string with embedded icons

const svgWithExternalIcons = generateSvg({ aslDefinition, showIcons: true });
const svgWithEmbeddedIcons = await embedIcons({ svg: svgWithExternalIcons.svg });
writeFileSync('diagram.svg', svgWithEmbeddedIcons);
// Chain with PNG export
const { svg } = generateSvg({ aslDefinition, showIcons: true });
const embeddedSvg = await embedIcons({ svg });
const png = await exportPng({ svg: embeddedSvg });