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

    Class Accessor

    Utility class for traversing and inspecting paint trees

    Hierarchy (View Summary)

    Index
    • get ptr(): number

      Gets the WASM pointer for this object Returns 0 if object has been disposed (error handled by global handler)

      Returns number

    • get isDisposed(): boolean

      Check if this object has been disposed

      Returns boolean

    • Cleanup function to be implemented by subclasses

      Parameters

      • ptr: number

        The WASM pointer to clean up

      Returns void

    • Generate a unique hash ID from a string name (DJB2 hash).

      Parameters

      • name: string

        The string name to hash

      Returns number

      The generated hash ID

    • Traverse the scene tree of a paint and invoke a callback on the paint and each of its descendants. The callback receives the correctly typed Paint subclass (Shape, Scene, Picture, or Text). Return false from the callback to stop traversal early.

      Parameters

      • paint: Paint

        The root paint node to traverse, typically a Picture or Scene

      • callback: (paint: Paint) => boolean

        Called for the root and each descendant paint. Return false to stop.

      Returns void

      A bitmap-based Picture might not have a scene tree.

      const accessor = new TVG.Accessor();

      accessor.set(picture, (paint) => {
      if (paint instanceof TVG.Shape) {
      paint.fill(0, 0, 255);
      }
      return true; // continue traversal
      });
    • Retrieve the original name string for a given ID.

      Parameters

      • id: number

        The unique identifier, e.g. from Paint.id

      Returns string | null

      The corresponding name, or null if not found or unavailable

      Only resolves while set is traversing, and only when the picture was marked accessible before loading (see Picture.accessible). Returns null otherwise.

      const picture = new TVG.Picture();
      picture.accessible = true;
      picture.load(svgData, { type: 'svg' });

      const accessor = new TVG.Accessor();
      accessor.set(picture, (paint) => {
      if (accessor.name(paint.id) === 'background') paint.fill(255, 0, 0);
      return true;
      });