UNPKG

@nmmty/lazycanvas

Version:

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

98 lines (97 loc) 3.41 kB
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"; /** * 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 {IImageLayerProps} [props] - The properties of the Image Layer. * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer. */ constructor(props?: IImageLayerProps, misc?: IBaseLayerMisc); /** * Sets the source of the image. * @param {string} [src] - 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 {ScaleType} [width] - The width of the image. * @param {ScaleType} [height] - The height of the image. * @param {{ [corner in radiusCorner]?: ScaleType }} [radius] - 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 {SKRSContext2D} [ctx] - The canvas rendering context. * @param {Canvas | SvgCanvas} [canvas] - The canvas instance. * @param {LayersManager} [manager] - The layer's manager. * @param {boolean} [debug] - 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; /** * Validates the properties of the Image Layer. * @param {IImageLayerProps} [data] - The properties to validate. * @returns {IImageLayerProps} The validated properties. */ protected validateProps(data: IImageLayerProps): IImageLayerProps; }