meo-canvas - v8.1.5
    Preparing search index...

    Interface WorkerCanvas

    A Canvas that lives in a worker thread.

    Every method behaves as its counterpart on a real Canvas does. Sync methods block the calling thread while the worker runs the real call (over the pool's synchronous channel); async methods go through Comlink. The two members that cannot be honoured — getContext() and newPage() — say so instead of returning something that only resembles the real thing.

    interface WorkerCanvas {
        colorSpace: ColorSpace;
        colorType: ColorType;
        engine: EngineDetails;
        gpu: boolean;
        height: number;
        width: number;
        get apng(): Promise<Buffer<ArrayBufferLike>>;
        get avif(): Promise<Buffer<ArrayBufferLike>>;
        get bmp(): Promise<Buffer<ArrayBufferLike>>;
        get gif(): Promise<Buffer<ArrayBufferLike>>;
        get ico(): Promise<Buffer<ArrayBufferLike>>;
        get jpg(): Promise<Buffer<ArrayBufferLike>>;
        get pages(): never;
        get pdf(): Promise<Buffer<ArrayBufferLike>>;
        get png(): Promise<Buffer<ArrayBufferLike>>;
        get raw(): Promise<Buffer<ArrayBufferLike>>;
        get svg(): Promise<Buffer<ArrayBufferLike>>;
        get tiff(): Promise<Buffer<ArrayBufferLike>>;
        get webp(): Promise<Buffer<ArrayBufferLike>>;
        getContext(): never;
        newPage(): never;
        release(): void;
        saveAs(filename: string, options?: SaveOptions): Promise<void>;
        saveAsSync(filename: string, options?: SaveOptions): void;
        toBuffer(
            format: AnimatedFormat,
            options?: ExportOptions & AnimationExportOptions,
        ): Promise<Buffer<ArrayBufferLike>>;
        toBuffer(
            format: StillFormat,
            options?: StillExportOptions,
        ): Promise<Buffer<ArrayBufferLike>>;
        toBufferSync(
            format: AnimatedFormat,
            options?: ExportOptions & AnimationExportOptions,
        ): Buffer;
        toBufferSync(format?: StillFormat, options?: StillExportOptions): Buffer;
        toDataURL(format?: ExportFormat, quality?: number): string;
        toDataURLSync(
            format: AnimatedFormat,
            options?: ExportOptions & AnimationExportOptions,
        ): string;
        toDataURLSync(format?: StillFormat, options?: StillExportOptions): string;
        toFile(filename: string, options?: SaveOptions): Promise<void>;
        toFileSync(filename: string, options?: SaveOptions): void;
        toSharp(options?: RenderOptions): Sharp;
        toSharpSync(options?: RenderOptions): Sharp;
        toURL(
            format: AnimatedFormat,
            options?: ExportOptions & AnimationExportOptions,
        ): Promise<string>;
        toURL(format: StillFormat, options?: StillExportOptions): Promise<string>;
        toURLSync(
            format: AnimatedFormat,
            options?: ExportOptions & AnimationExportOptions,
        ): string;
        toURLSync(format?: StillFormat, options?: StillExportOptions): string;
    }
    Index
    colorSpace: ColorSpace

    The space the canvas composited in. Exports convert out of it when asked.

    colorType: ColorType

    What the engine settled on, which is not always what Root asked for.

    Which backend took the render, and what it reports about itself.

    gpu: boolean

    Snapshots, not proxies: none of these can change once the canvas has been rendered.

    height: number

    Height of the rendered canvas in device pixels.

    width: number

    Width of the rendered canvas in device pixels — the root's width times its scale.

    • get avif(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('avif'). Smaller again than WebP, at a much higher encode cost.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get bmp(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('bmp'). Uncompressed pixels in a container almost nothing needs.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get ico(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('ico'). An icon, one size per page.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get jpg(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('jpg'). Lossy and opaque — no alpha channel.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get pdf(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('pdf'). A document, one page per rendered page.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get png(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('png'). Lossless, and the format to reach for unless there is a reason not to.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get raw(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('raw'). Pixel data in the canvas's own colorType, with no container around it.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get svg(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('svg'). Vector output: the drawing as paths rather than pixels.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get tiff(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('tiff'). A sheet per page, for print pipelines.

      Returns Promise<Buffer<ArrayBufferLike>>

    • get webp(): Promise<Buffer<ArrayBufferLike>>

      Shorthand for toBuffer('webp'). Smaller than PNG at the same quality, and takes every page as an animation.

      Returns Promise<Buffer<ArrayBufferLike>>

    • getContext, newPage and pages all hand back a live CanvasRenderingContext2D bound to native memory in the worker. Proxying one would mean a thread round trip per fillRect, so these throw rather than return something that only looks like a context. Drawing is expressed as a component tree here, which is what the worker replays on the other side.

      Returns never

    • Not available in worker mode: a page is added while drawing, and drawing happens in the worker.

      Returns never

    • The HTMLCanvasElement spelling of toURLSync, taking a quality rather than an options object. Synchronous despite the name, as it is on a real canvas.

      Parameters

      Returns string

    • Writes the canvas to disk, taking the format from the file's extension.

      Parameters

      Returns Promise<void>

    • Writes the canvas to disk, blocking on the worker.

      Not split by format the way toBuffer is: the format comes from the filename extension here, so there is no format argument for the animation options to be checked against.

      Parameters

      Returns void

    • Returns a real Sharp, as skia-canvas does — not a Buffer, which is what this used to hand back.

      A Sharp instance cannot cross a thread boundary, so the pixels are fetched and the wrapper is built here. That mirrors what skia-canvas itself does internally with toBuffer('raw').

      Parameters

      Returns Sharp