Initialization options
OptionallocateFile?: (path: string) => stringOptional function to locate WASM files. If not provided, assumes WASM files are in the same directory as the JavaScript bundle.
Optionalrenderer?: constants.RendererTypeRenderer type: 'sw' (Software), 'gl' (WebGL), or 'wg' (WebGPU). Default: 'gl'. WebGPU provides best performance but requires Chrome 113+ or Edge 113+.
OptionalonError?: ErrorHandlerGlobal error handler for all ThorVG operations. If provided, errors will be passed to this handler instead of being thrown.
Optionalthreads?: numberNumber of worker threads count. Ignored in default preset. Default: 0.
Promise that resolves to ThorVG namespace containing all classes and utilities
// Initialize with default WebGL renderer
const TVG = await ThorVG.init();
const canvas = new TVG.Canvas('#canvas');
// Initialize with custom WASM file location
const TVG = await ThorVG.init({
locateFile: (path) => `/public/wasm/${path}`,
renderer: 'gl'
});
// Initialize with WebGPU for maximum performance
const TVG = await ThorVG.init({
locateFile: (path) => '../dist/' + path.split('/').pop(),
renderer: 'wg'
});
// Initialize with Software renderer for maximum compatibility
const TVG = await ThorVG.init({
renderer: 'sw'
});
Initialize ThorVG WASM module and rendering engine.
This is the entry point for using ThorVG WebCanvas. It loads the WebAssembly module and initializes the rendering engine with the specified backend (Software, WebGL, or WebGPU).