### Browser WebAssembly Setup Source: https://github.com/thx/resvg-js/blob/main/README.md Include the resvg-wasm script and initialize the WebAssembly module. This example demonstrates loading custom fonts. ```html ``` -------------------------------- ### Run resvg.js with Deno Source: https://github.com/thx/resvg-js/blob/main/README.md Execute the resvg.js example using Deno. Ensure you have Deno 1.26.1 or later installed and use the --unstable flag. ```shell deno run --unstable --allow-read --allow-write --allow-ffi example/index-deno.js ``` -------------------------------- ### Run Deno example Source: https://github.com/thx/resvg-js/blob/main/README.md Execute the provided Deno example script with required permissions. ```shell deno run --unstable --allow-read --allow-write --allow-ffi example/index-deno.js [2022-11-16T15:03:29Z DEBUG resvg_js::fonts] Loaded 1 font faces in 0.067ms. [2022-11-16T15:03:29Z DEBUG resvg_js::fonts] Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.001ms. Original SVG Size: 1324 x 687 Output PNG Size : 1200 x 623 ✨ Done in 66 ms ``` -------------------------------- ### Run Node.js example Source: https://github.com/thx/resvg-js/blob/main/README.md Execute the provided Node.js example script. ```shell node example/index.js Loaded 1 font faces in 0ms. Font './example/SourceHanSerifCN-Light-subset.ttf':0 found in 0.006ms. ✨ Done in 55.65491008758545 ms ``` -------------------------------- ### Run example in Bun Source: https://github.com/thx/resvg-js/blob/main/README.md Execute the Node.js example script directly using the Bun runtime. ```shell bun example/index.js ``` -------------------------------- ### Install wasm-bindgen-cli Source: https://github.com/thx/resvg-js/blob/main/README.md Manually installs wasm-bindgen-cli if the automatic installation via wasm-pack fails due to network issues. ```bash cargo install wasm-bindgen-cli ``` -------------------------------- ### Build WebAssembly bindings Source: https://github.com/thx/resvg-js/blob/main/README.md Installs dependencies, builds the WebAssembly bindings, and runs their respective tests. Ensure Node.js and npm are installed. ```bash npm i npm run build:wasm npm run test:wasm ``` -------------------------------- ### Build Node.js bindings Source: https://github.com/thx/resvg-js/blob/main/README.md Installs dependencies, builds the Node.js bindings, and runs tests. Ensure Node.js and npm are installed. ```bash npm i npm run build npm test ``` -------------------------------- ### Install wasm-pack Source: https://github.com/thx/resvg-js/blob/main/README.md Installs wasm-pack using the provided script. Ensure Rust and Node.js are installed prior to running. ```bash curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh ``` -------------------------------- ### Install Benchmark Dependencies Source: https://github.com/thx/resvg-js/blob/main/README.md Install necessary packages for benchmarking resvg-js against other libraries like sharp and svg2img. ```shell npm i benny@3.x sharp@0.x @types/sharp svg2img@0.x npm run bench ``` -------------------------------- ### Deno Usage Example Source: https://context7.com/thx/resvg-js/llms.txt Run resvg-js natively in Deno using FFI support. Requires unstable, read, write, and FFI permissions. ```javascript // example/index-deno.js import * as path from 'https://deno.land/std@0.159.0/path/mod.ts' import { Resvg } from 'npm:@resvg/resvg-js' const __dirname = path.dirname(path.fromFileUrl(import.meta.url)) const svg = await Deno.readFile(path.join(__dirname, './text.svg')) const opts = { fitTo: { mode: 'width', value: 1200 }, font: { fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], loadSystemFonts: false, }, } const t = performance.now() const resvg = new Resvg(svg, opts) const pngData = resvg.render() const pngBuffer = pngData.asPng() console.info('Original SVG Size:', `${resvg.width} x ${resvg.height}`) console.info('Output PNG Size:', `${pngData.width} x ${pngData.height}`) console.info('Done in', performance.now() - t, 'ms') await Deno.writeFile(path.join(__dirname, './text-out-deno.png'), pngBuffer) // Run with: deno run --unstable --allow-read --allow-write --allow-ffi index-deno.js ``` -------------------------------- ### Install Node.js package Source: https://github.com/thx/resvg-js/blob/main/README.md Use npm to add the package to your project. ```shell npm i @resvg/resvg-js ``` -------------------------------- ### Install binaryen on Apple M chips Source: https://github.com/thx/resvg-js/blob/main/README.md Installs binaryen using Homebrew for Apple M chip users experiencing download errors for binaryen. ```bash brew install binaryen ``` -------------------------------- ### resvg.js Deno Example Source: https://github.com/thx/resvg-js/blob/main/README.md This script uses Deno to read an SVG file, convert it to PNG using resvg.js, and write the output. It utilizes Deno's file system and path modules. ```javascript import * as path from 'https://deno.land/std@0.159.0/path/mod.ts' import { Resvg } from 'npm:@resvg/resvg-js' const __dirname = path.dirname(path.fromFileUrl(import.meta.url)) const svg = await Deno.readFile(path.join(__dirname, './text.svg')) const opts = { fitTo: { mode: 'width', value: 1200, }, } const t = performance.now() const resvg = new Resvg(svg, opts) const pngData = resvg.render() const pngBuffer = pngData.asPng() console.info('Original SVG Size:', `${resvg.width} x ${resvg.height}`) console.info('Output PNG Size :', `${pngData.width} x ${pngData.height}`) console.info('✨ Done in', performance.now() - t, 'ms') await Deno.writeFile(path.join(__dirname, './text-out-deno.png'), pngBuffer) ``` -------------------------------- ### imagesToResolve() and resolveImage() Methods Source: https://context7.com/thx/resvg-js/llms.txt Methods to handle external images referenced in SVG via `` elements with HTTP/HTTPS URLs. This involves getting the URLs, fetching them, and providing the image buffers back to resvg. ```APIDOC ## imagesToResolve() and resolveImage() Methods ### Description Load external images referenced in the SVG via `` elements with HTTP/HTTPS URLs. First get URLs to resolve, fetch them, then provide the image buffers back to resvg. ### Method Not applicable (methods of a class instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript const { Resvg } = require('@resvg/resvg-js') const fetch = require('node-fetch') const fs = require('fs').promises async function renderSvgWithExternalImages() { const svg = ` ` const resvg = new Resvg(svg, { font: { loadSystemFonts: false }, logLevel: 'off', }) // Get list of external image URLs to resolve const imageUrls = resvg.imagesToResolve() console.log('Images to resolve:', imageUrls) // ['https://example.com/logo.png', 'https://example.com/icon.gif'] // Fetch and resolve each image const resolved = await Promise.all( imageUrls.map(async (url) => { console.log('Fetching:', url) const response = await fetch(url) const buffer = await response.arrayBuffer() return { url, buffer: Buffer.from(buffer) } }) ) // Provide image data back to resvg for (const { url, buffer } of resolved) { resvg.resolveImage(url, buffer) } // Now render with resolved images const pngData = resvg.render() const pngBuffer = pngData.asPng() console.log('Output Size:', `${pngData.width} x ${pngData.height}`) await fs.writeFile('./output-with-images.png', pngBuffer) } renderSvgWithExternalImages() ``` ### Response #### Success Response (200) None (modifies the resvg instance in place) #### Response Example None ``` -------------------------------- ### Render SVG String with resvg-js Source: https://github.com/thx/resvg-js/blob/main/wasm/index.html Render an SVG string using resvg-js. This example includes a complex SVG with paths and transformations. ```javascript const svgList = [{ name: 'Hello resvg-js', svgString: ` ` }, { name: 'GitHub Octocat', svgString: ` ``` ### Response #### Success Response (200) None (renders PNG data to be displayed or saved) #### Response Example None ``` -------------------------------- ### Benchmark Results Source: https://github.com/thx/resvg-js/blob/main/README.md Sample output from the benchmark script, showing operations per second for different SVG rendering libraries. ```shell Running "resize width" suite... resvg-js(Rust): 12 ops/s sharp: 9 ops/s skr-canvas(Rust): 7 ops/s svg2img(canvg and node-canvas): 6 ops/s ``` -------------------------------- ### Initialize Resvg Instance Source: https://context7.com/thx/resvg-js/llms.txt Create a new Resvg instance from an SVG string or Buffer with optional rendering configuration. ```javascript const { Resvg } = require('@resvg/resvg-js') const fs = require('fs') // Basic usage with SVG string const svg = ` ` const resvg = new Resvg(svg) // Full options example const svgBuffer = fs.readFileSync('./image.svg') const resvg = new Resvg(svgBuffer, { background: 'rgba(238, 235, 230, .9)', // CSS3 color format fitTo: { mode: 'width', // 'original' | 'width' | 'height' | 'zoom' value: 1200, }, font: { fontFiles: ['./fonts/CustomFont.ttf'], // Local font file paths fontDirs: ['./fonts/'], // Font directories loadSystemFonts: false, // Faster when disabled defaultFontFamily: 'Custom Font', defaultFontSize: 12, serifFamily: 'Times New Roman', sansSerifFamily: 'Arial', cursiveFamily: 'Comic Sans MS', fantasyFamily: 'Impact', monospaceFamily: 'Courier New', }, dpi: 96, languages: ['en'], shapeRendering: 2, // 0: optimizeSpeed, 1: crispEdges, 2: geometricPrecision textRendering: 1, // 0: optimizeSpeed, 1: optimizeLegibility, 2: geometricPrecision imageRendering: 0, // 0: optimizeQuality, 1: optimizeSpeed crop: { left: 20, top: 20, right: 100, bottom: 100, }, logLevel: 'debug', // 'off' | 'error' | 'warn' | 'info' | 'debug' | 'trace' }) console.log('Original SVG Size:', `${resvg.width} x ${resvg.height}`) // Original SVG Size: 200 x 200 ``` -------------------------------- ### Initialize Select Options Source: https://github.com/thx/resvg-js/blob/main/wasm/index.html Populates a select dropdown element with options from a data list. ```javascript function initSelectOptions(sltId, dataList, defaultVal) { const selectElement = document.querySelector('#' + sltId) let optionText = '' for (const [i, item] of dataList.entries()) { const optionElement = document.createElement('option') optionElement.value = item.name optionElement.innerText = item.name if (i === defaultVal) { optionElement.setAttribute('selected', true) } selectElement.appendChild(optionElement) } } ``` -------------------------------- ### WebAssembly Initialization and Usage Source: https://context7.com/thx/resvg-js/llms.txt Initialize the Wasm module before rendering. Note that Wasm-based instances require manual memory management via .free() and use fontBuffers for custom fonts. ```javascript // Browser usage ``` ```javascript // Node.js Wasm usage const fs = require('fs').promises const { join } = require('path') const { Resvg, initWasm } = require('@resvg/resvg-wasm') async function main() { // Initialize Wasm from file await initWasm(fs.readFile(join(__dirname, 'node_modules/@resvg/resvg-wasm/index_bg.wasm'))) const svg = await fs.readFile('./image.svg') const resvg = new Resvg(svg, { fitTo: { mode: 'width', value: 500 }, }) const pngData = resvg.render() const pngBuffer = pngData.asPng() console.log('Original SVG Size:', `${resvg.width} x ${resvg.height}`) console.log('Output PNG Size:', `${pngData.width} x ${pngData.height}`) await fs.writeFile('./output.png', pngBuffer) } main() ``` -------------------------------- ### Resvg Constructor Source: https://context7.com/thx/resvg-js/llms.txt Initializes a new Resvg instance by parsing an SVG string or buffer and applying optional rendering configurations. ```APIDOC ## Constructor: new Resvg(svg, options) ### Description Creates a new Resvg instance to prepare an SVG for rendering. The constructor parses the input and applies settings for background, scaling, fonts, and rendering quality. ### Parameters #### Request Body - **svg** (string|Buffer) - Required - The SVG content to render. - **options** (object) - Optional - Configuration object: - **background** (string) - CSS3 color format for the background. - **fitTo** (object) - Scaling configuration (mode: 'original' | 'width' | 'height' | 'zoom', value: number). - **font** (object) - Font configuration (fontFiles, fontDirs, loadSystemFonts, defaultFontFamily, etc.). - **dpi** (number) - Dots per inch for rendering. - **languages** (array) - List of languages for font selection. - **shapeRendering** (number) - 0: optimizeSpeed, 1: crispEdges, 2: geometricPrecision. - **textRendering** (number) - 0: optimizeSpeed, 1: optimizeLegibility, 2: geometricPrecision. - **imageRendering** (number) - 0: optimizeQuality, 1: optimizeSpeed. - **crop** (object) - Cropping dimensions (left, top, right, bottom). - **logLevel** (string) - Logging verbosity ('off', 'error', 'warn', 'info', 'debug', 'trace'). ``` -------------------------------- ### Include Browser Wasm script Source: https://github.com/thx/resvg-js/blob/main/README.md Load the WebAssembly version of the library via script tag. ```html ``` -------------------------------- ### render() Method Source: https://context7.com/thx/resvg-js/llms.txt Renders the configured SVG instance into a RenderedImage object containing PNG data and pixel information. ```APIDOC ## Method: render() ### Description Executes the rendering process based on the instance configuration and returns a RenderedImage object. ### Response #### Success Response (RenderedImage object) - **asPng()** (function) - Returns the rendered image as a PNG Buffer. - **width** (number) - The width of the rendered output. - **height** (number) - The height of the rendered output. - **pixels** (Buffer) - Raw RGBA pixel data of the rendered image. ``` -------------------------------- ### Upgrade Yarn Source: https://github.com/thx/resvg-js/blob/main/README.md Run this command to upgrade to the latest stable version of Yarn. It automatically downloads the new version and updates the yarnPath in .yarnrc.yml. ```bash yarn set version stable ``` -------------------------------- ### resvg-js Background and Crop Options Source: https://context7.com/thx/resvg-js/llms.txt Set PNG background color using CSS3 color formats and crop the output to specific regions. Supports various color formats and optional crop coordinates. ```javascript const { Resvg } = require('@resvg/resvg-js') const fs = require('fs') const svg = ` ` // Background with alpha channel const withBackground = new Resvg(svg, { background: 'rgba(255, 0, 0, 0.5)', // Semi-transparent red // Also supports: '#ff0000', 'rgb(255,0,0)', 'hsl(0,100%,50%)', 'hsla(0,100%,50%,0.5)' }) const pngWithBg = withBackground.render().asPng() fs.writeFileSync('./with-background.png', pngWithBg) // Crop to specific region const cropped = new Resvg(svg, { background: '#ffffff', crop: { left: 20, // Required: pixels from left top: 20, // Required: pixels from top right: 180, // Optional: pixels from left (not from right edge) bottom: 180, // Optional: pixels from top (not from bottom edge) }, }) const croppedPng = cropped.render() console.log('Cropped Size:', `${croppedPng.width} x ${croppedPng.height}`) // Cropped Size: 160 x 160 fs.writeFileSync('./cropped.png', croppedPng.asPng()) ``` -------------------------------- ### Initialize resvg-js and SVG conversion Source: https://github.com/thx/resvg-js/blob/main/wasm/index.html Initializes the WASM module and sets up the conversion pipeline for SVG strings. Includes logic for handling font buffers and rendering options. ```javascript async function getFontBuffer() { if (fetchFontLock) return fetchFontLock = true const controller = new AbortController() const signal = controller.signal setTimeout(() => controller.abort(), 3000) // Cancel the fetch request try { const t = performance.now() const font = await fetch(fontFile) if (!font.ok) return const data = await font.arrayBuffer() const buffer = new Uint8Array(data) fetchFontLock = false console.info('✨ 字体请求用时:', performance.now() - t + 'ms') return { buffer, family_name: 'Source Han Serif CN Light', } } catch (error) { return console.error('fetch font error', error) } } (async function () { await resvg.initWasm(fetch('./index_bg.wasm')) initSelectOptions('slt-svg', svgList, defaultSvgNumber) initSelectOptions('slt-font', fontList, defaultFontNumber) const output = document.getElementById('output') const svgInputElement = document.querySelector('#input-svg') // 在 textarea 中输入 SVG 字符串 svgInputElement.value = INIT_INPUT_SVG_STRING // INIT_INPUT_SVG_STRING to DOM const inputSvgElement = new DOMParser().parseFromString(INIT_INPUT_SVG_STRING, 'image/svg+xml').documentElement let resvgOpts = { font: {}, fitTo: { mode: 'zoom', value: 2, }, } if (checkHasText()) { const { buffer, family_name } = await getFontBuffer() resvgOpts.font.fontBuffers = [buffer] fontList[0].buffer = buffer } await svg2png(INIT_INPUT_SVG_STRING, resvgOpts, false, 20, false) async function svg2png(svgString, opts, hasCrop = false, bleedSize = 0, square = false) { const svg = svgString ? svgString : svgInputElement.value.trim() if (!svg) { alert('SVG is empty') return } const resvgJS = new resvg.Resvg(svg, opts) document.querySelector('#svg-info').textContent = 'Original SVG size: ' + resvgJS.width + ' x ' + resvgJS.height + ' px' const resolved = await Promise.all( resvgJS.imagesToResolve().map(async (url) => { const img = await fetch(url) const buffer = await img.arrayBuffer() return { url, buffer: new Uint8Array(buffer), } }), ) if (resolved.l ``` -------------------------------- ### Asynchronously Render SVG to PNG Source: https://context7.com/thx/resvg-js/llms.txt Use renderAsync for non-blocking SVG to PNG conversion in server environments. Supports AbortSignal for cancelling queued tasks. Requires SVG data and options for customization. ```javascript const { renderAsync } = require('@resvg/resvg-js') const fs = require('fs').promises async function renderSvgAsync() { const svg = await fs.readFile('./image.svg') const options = { background: 'rgba(238, 235, 230, .9)', fitTo: { mode: 'width', value: 1200 }, font: { fontFiles: ['./fonts/SourceHanSerif.ttf'], loadSystemFonts: false, defaultFontFamily: 'Source Han Serif CN Light', }, logLevel: 'off', } // Basic async rendering const pngData = await renderAsync(svg, options) const pngBuffer = pngData.asPng() await fs.writeFile('./output.png', pngBuffer) console.log('Output PNG Size:', `${pngData.width} x ${pngData.height}`) } // With AbortSignal for cancellation async function renderWithAbort() { const svg = '' const controller = new AbortController() try { const renderPromise = renderAsync(svg, {}, controller.signal) // Cancel if needed (only works for queued, not yet started tasks) // controller.abort() const result = await renderPromise return result.asPng() } catch (err) { if (err.message === 'AbortError') { console.log('Rendering was cancelled') } throw err } } renderSvgAsync() ``` -------------------------------- ### Render SVG to PNG in Node.js Source: https://github.com/thx/resvg-js/blob/main/README.md Load an SVG file, configure rendering options including custom fonts, and save the output as a PNG. ```javascript const { promises } = require('fs') const { join } = require('path') const { Resvg } = require('@resvg/resvg-js') async function main() { const svg = await promises.readFile(join(__dirname, './text.svg')) const opts = { background: 'rgba(238, 235, 230, .9)', fitTo: { mode: 'width', value: 1200, }, font: { fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts. loadSystemFonts: false, // It will be faster to disable loading system fonts. // defaultFontFamily: 'Source Han Serif CN Light', // You can omit this. }, } const resvg = new Resvg(svg, opts) const pngData = resvg.render() const pngBuffer = pngData.asPng() console.info('Original SVG Size:', `${resvg.width} x ${resvg.height}`) console.info('Output PNG Size :', `${pngData.width} x ${pngData.height}`) await promises.writeFile(join(__dirname, './text-out.png'), pngBuffer) } main() ``` -------------------------------- ### renderAsync() Function Source: https://context7.com/thx/resvg-js/llms.txt Asynchronously renders an SVG to a PNG buffer. Supports non-blocking operations and cancellation via AbortSignal. ```APIDOC ## renderAsync(svg, options, signal) ### Description Asynchronously render an SVG to PNG, useful for non-blocking operations in server environments. Supports AbortSignal for cancellation of queued rendering tasks. ### Parameters #### Request Body - **svg** (string/buffer) - Required - The SVG content to render. - **options** (object) - Optional - Configuration for rendering (background, fitTo, font, logLevel). - **signal** (AbortSignal) - Optional - Signal to cancel the rendering task. ### Response - **pngData** (object) - Returns an object containing the rendered PNG data, width, height, and an asPng() method to retrieve the buffer. ``` -------------------------------- ### SVG Size Input Event Listener Source: https://github.com/thx/resvg-js/blob/main/wasm/index.html Handles changes in the SVG size input. It updates the `fitTo` option in `resvgOpts` based on the provided value (width or original) and re-renders the PNG. Includes a confirmation dialog for large widths. ```javascript svgSizeElement.addEventListener('change', function (event) { const value = event.target.value const hasCrop = cropElement.checked const square = squareElement.checked const bleedSize = bleedSizeElement.value if (!value) { Object.assign(resvgOpts, { fitTo: { mode: 'original' } }) } else { const limitWidth = 3000 const title = `The width(${limitWidth}) is larger and generating images will be slower.\nAre you sure to continue?` if (value >= limitWidth && !confirm(title)) { return } Object.assign(resvgOpts, { fitTo: { mode: 'width', value: parseInt(value, 10), }, }) } svg2png(null, resvgOpts, hasCrop, bleedSize, square) }) ``` -------------------------------- ### Version Package (Minor) Source: https://github.com/thx/resvg-js/blob/main/README.md Use this command to increment the minor version of your npm package (e.g., 1.0.0 to 1.1.0). ```bash npm version minor ``` -------------------------------- ### Color Change Handler Source: https://github.com/thx/resvg-js/blob/main/wasm/index.html Updates the background color option for resvg and re-renders the PNG. It retrieves the computed color and converts it to RGBA format. ```javascript function onChangeColor() { const hasCrop = cropElement.checked const square = squareElement.checked const bleedSize = bleedSizeElement.value const style = window.getComputedStyle(document.querySelector('html'), ':before') const color = style.getPropertyValue('color') const rgb_color = convertColorToRGBA(color) console.info('getComputedStyle color\n', color) console.info('convert to rgba()\n', rgb_color) resvgOpts.background = rgb_color svg2png(null, resvgOpts, hasCrop, bleedSize, square) } ``` -------------------------------- ### Convert SVG to Simplified Path String Source: https://context7.com/thx/resvg-js/llms.txt The toString() method converts various SVG shapes (rect, circle, ellipse) into elements for optimization. Initialize Resvg with SVG content and options. ```javascript const { Resvg } = require('@resvg/resvg-js') // SVG with various shapes const svg = ` ` const resvg = new Resvg(svg, { font: { loadSystemFonts: false }, }) // Get simplified SVG with all shapes converted to paths const simplifiedSvg = resvg.toString() console.log('Simplified SVG:\n', simplifiedSvg) // Output: SVG with elements instead of rect, circle, ellipse ``` -------------------------------- ### resvg-js fitTo Options Source: https://context7.com/thx/resvg-js/llms.txt Control output image dimensions using different scaling modes: original size, fit to width, fit to height, or zoom factor. Maintains aspect ratio when fitting. ```javascript const { Resvg } = require('@resvg/resvg-js') const svg = ` ` // Original size (no scaling) const original = new Resvg(svg, { fitTo: { mode: 'original' } }) console.log('Original:', `${original.render().width} x ${original.render().height}`) // Original: 200 x 100 // Fit to specific width (maintains aspect ratio) const fitWidth = new Resvg(svg, { fitTo: { mode: 'width', value: 800 } }) console.log('Fit Width:', `${fitWidth.render().width} x ${fitWidth.render().height}`) // Fit Width: 800 x 400 // Fit to specific height (maintains aspect ratio) const fitHeight = new Resvg(svg, { fitTo: { mode: 'height', value: 300 } }) console.log('Fit Height:', `${fitHeight.render().width} x ${fitHeight.render().height}`) // Fit Height: 600 x 300 // Zoom by factor const zoom = new Resvg(svg, { fitTo: { mode: 'zoom', value: 2.5 } }) console.log('Zoom 2.5x:', `${zoom.render().width} x ${zoom.render().height}`) // Zoom 2.5x: 500 x 250 ``` -------------------------------- ### Version Package (Patch) Source: https://github.com/thx/resvg-js/blob/main/README.md Use this command to increment the patch version of your npm package (e.g., 1.0.0 to 1.0.1). ```bash npm version patch ``` -------------------------------- ### getBBox() Method Source: https://context7.com/thx/resvg-js/llms.txt Calculates the bounding box of all visible elements in the SVG, including applied transforms. ```APIDOC ## getBBox() ### Description Calculate the bounding box of all visible elements in the SVG with transforms applied. Returns precise bounds including curves. ### Response - **object** - Returns an object containing x, y, width, and height properties, or null if no visible content exists. ``` -------------------------------- ### Helper Function for Multiple Event Listeners Source: https://github.com/thx/resvg-js/blob/main/wasm/index.html A utility function to add multiple event listeners to an element with the same handler. ```javascript function addMultipleEventListener(element, events, handler) { events.forEach(e => element.addEventListener(e, handler)) } ``` -------------------------------- ### toString() Method Source: https://context7.com/thx/resvg-js/llms.txt Converts an SVG to a simplified path-based string representation, transforming all shapes into elements. ```APIDOC ## toString() ### Description Convert the SVG to a simplified path-based string representation. This transforms all shapes (rect, circle, ellipse, etc.) to elements, useful for optimizing SVG output. ### Response - **string** - The simplified SVG string. ```