Use setupSvgRenderer to attach a dynamic SVG drawing system to an existing <svg> element. This function handles automatic re-rendering when the element's size changes (via ResizeObserver) or when its parent undergoes CSS transitions or animations.
Parameters:
el: The target SVGSVGElement.paths: An array of Paths configuration objects.enableBackdropBlur?: (Optional) If true, creates a div with a backdrop-filter: blur(10px) that uses the SVG as a mask. This is useful for complex masking effects.enableViewBox?: (Optional) If true, sets the SVG viewBox attribute based on the element's current dimensions.
Returns:
An object containing a destroy() method to disconnect the ResizeObserver and clean up resources.
import { setupSvgRenderer } from './src/utils/frame';
const svgElement = document.querySelector('svg') as SVGSVGElement;
const myPaths: Paths = [
{
style: { strokeWidth: '2', stroke: 'black', fill: 'red' },
path: [['M', '0', '0'], ['L', '100%', '100%']]
}
];
const renderer = setupSvgRenderer({
el: svgElement,
paths: myPaths,
enableBackdropBlur: true,
enableViewBox: true
});
// Call renderer.destroy() when the component unmounts