MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / exportToSvg

Function exportToSvg

yaml-flow-editor/src/utils/image.ts:107–141  ·  view source on GitHub ↗

* Export as SVG (vector graphics, infinitely scalable) * Manually adds background rectangle to ensure white background

(
  element: HTMLElement,
  width: number,
  height: number,
  viewport: { x: number; y: number; zoom: number },
  options: Required<ExportOptions>
)

Source from the content-addressed store, hash-verified

105 * Manually adds background rectangle to ensure white background
106 */
107async function exportToSvg(
108 element: HTMLElement,
109 width: number,
110 height: number,
111 viewport: { x: number; y: number; zoom: number },
112 options: Required<ExportOptions>
113): Promise<string> {
114 const svgDataUrl = await toSvg(element, {
115 backgroundColor: options.backgroundColor,
116 width: width,
117 height: height,
118 style: {
119 width: `${width}px`,
120 height: `${height}px`,
121 transform: `translate(${viewport.x}px, ${viewport.y}px) scale(${viewport.zoom})`,
122 border: 'none',
123 outline: 'none',
124 fill: 'none',
125 },
126 filter: createNodeFilter(),
127 });
128
129 // Decode data URL to get SVG content
130 const svgContent = decodeURIComponent(svgDataUrl.split(',')[1]);
131
132 // Insert background rectangle after <svg> tag
133 const bgRect = `<rect width="100%" height="100%" fill="${options.backgroundColor}"/>`;
134 const modifiedSvg = svgContent.replace(
135 /(<svg[^>]*>)/,
136 `$1${bgRect}`
137 );
138
139 // Re-encode as data URL
140 return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(modifiedSvg)}`;
141}
142
143/**
144 * Export as PDF

Callers 1

downloadImageFunction · 0.85

Calls 1

createNodeFilterFunction · 0.85

Tested by

no test coverage detected