ThorVG WebCanvas API - v1.1.4
    Preparing search index...

    Function init

    • 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).

      Parameters

      • options: InitOptions = {}

        Initialization options

        • OptionallocateFile?: (path: string) => string

          Optional function to locate WASM files. If not provided, assumes WASM files are in the same directory as the JavaScript bundle.

        • Optionalrenderer?: constants.RendererType

          Renderer type: 'sw' (Software), 'gl' (WebGL), or 'wg' (WebGPU). Default: 'gl'. WebGPU provides best performance but requires Chrome 113+ or Edge 113+.

        • OptionalonError?: ErrorHandler

          Global error handler for all ThorVG operations. If provided, errors will be passed to this handler instead of being thrown.

        • Optionalthreads?: number

          Number of worker threads count. Ignored in default preset. Default: 0.

      Returns Promise<ThorVGNamespace>

      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 with thread-enabled preset
      import ThorVG from '@thorvg/webcanvas/thread';

      const TVG = await ThorVG.init({
      locateFile: (path) => `/wasm/thread/${path}`,
      threads: 4
      });

      If WASM module fails to load or engine initialization fails