UNPKG

@nmmty/lazycanvas

Version:

A simple way to interact with @napi-rs/canvas in an advanced way!

94 lines (93 loc) 3.2 kB
/// <reference types="node" /> /// <reference types="node" /> import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer"; import { ScaleType, LayerType, radiusCorner } from "../../types"; import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas"; import { LayersManager } from "../managers/LayersManager"; /** * Interface representing an Image Layer. */ export interface IImageLayer extends IBaseLayer { /** * The type of the layer, which is `Image`. */ type: LayerType.Image; /** * The properties specific to the Image Layer. */ props: IImageLayerProps; } /** * Interface representing the properties of an Image Layer. */ export interface IImageLayerProps extends IBaseLayerProps { /** * The source of the image, which can be a URL or a Buffer. */ src: string | Buffer; /** * The size of the image, including width, height, and radius. */ size: { /** * The width of the image. */ width: ScaleType; /** * The height of the image. */ height: ScaleType; /** * The radius of the image. */ radius: { [corner in radiusCorner]?: ScaleType; }; }; } /** * Class representing an Image Layer, extending the BaseLayer class. */ export declare class ImageLayer extends BaseLayer<IImageLayerProps> { /** * The properties of the Image Layer. */ props: IImageLayerProps; /** * Constructs a new ImageLayer instance. * @param props {IImageLayerProps} - The properties of the Image Layer. * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer. */ constructor(props?: IImageLayerProps, misc?: IBaseLayerMisc); /** * Sets the source of the image. * @param src {string} - The source of the image, which can be a URL or file path. * @returns {this} The current instance for chaining. * @throws {LazyError} If the source is not a valid URL. */ setSrc(src: string): this; /** * Sets the size of the image. * @param width {ScaleType} - The width of the image. * @param height {ScaleType} - The height of the image. * @param radius {{ [corner in radiusCorner]?: ScaleType }} - The radius of the image (optional). * @returns {this} The current instance for chaining. */ setSize(width: ScaleType, height: ScaleType, radius?: { [corner in radiusCorner]?: ScaleType; }): this; /** * Draws the Image Layer on the canvas. * @param ctx {SKRSContext2D} - The canvas rendering context. * @param canvas {Canvas | SvgCanvas} - The canvas instance. * @param manager {LayersManager} - The layers manager. * @param debug {boolean} - Whether to enable debug logging. * @throws {LazyError} If the image could not be loaded. */ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>; /** * Converts the Image Layer to a JSON representation. * @returns {IImageLayer} The JSON representation of the Image Layer. */ toJSON(): IImageLayer; }