* Export as high-resolution PNG * pixelRatio controls pixel density - higher values produce clearer images * Output image pixels = width * pixelRatio × height * pixelRatio
(
element: HTMLElement,
width: number,
height: number,
viewport: { x: number; y: number; zoom: number },
options: Required<ExportOptions>
)
| 78 | * Output image pixels = width * pixelRatio × height * pixelRatio |
| 79 | */ |
| 80 | async function exportToPng( |
| 81 | element: HTMLElement, |
| 82 | width: number, |
| 83 | height: number, |
| 84 | viewport: { x: number; y: number; zoom: number }, |
| 85 | options: Required<ExportOptions> |
| 86 | ): Promise<string> { |
| 87 | return toPng(element, { |
| 88 | backgroundColor: options.backgroundColor, |
| 89 | width: width, |
| 90 | height: height, |
| 91 | pixelRatio: options.scale, // Use pixelRatio for higher pixel density |
| 92 | style: { |
| 93 | width: `${width}px`, |
| 94 | height: `${height}px`, |
| 95 | transform: `translate(${viewport.x}px, ${viewport.y}px) scale(${viewport.zoom})`, |
| 96 | border: 'none', |
| 97 | outline: 'none', |
| 98 | }, |
| 99 | filter: createNodeFilter(), |
| 100 | }); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Export as SVG (vector graphics, infinitely scalable) |
no test coverage detected