| 30 | |
| 31 | /** The SVG's own root width/height, which the raster canvas has to match. */ |
| 32 | export function svgPixelSize(svg: string): { width: number; height: number } { |
| 33 | const width = Number(/\bwidth="(\d+(?:\.\d+)?)"/.exec(svg)?.[1] ?? 0); |
| 34 | const height = Number(/\bheight="(\d+(?:\.\d+)?)"/.exec(svg)?.[1] ?? 0); |
| 35 | return { width: Math.max(1, Math.round(width)), height: Math.max(1, Math.round(height)) }; |
| 36 | } |
| 37 | |
| 38 | function loadImage(url: string): Promise<HTMLImageElement> { |
| 39 | return new Promise((resolve, reject) => { |