UNPKG

@nmmty/lazycanvas

Version:

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

133 lines (132 loc) 4.53 kB
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer"; import { ColorType, ScaleType, LayerType } from "../../types"; import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas"; import { LayersManager } from "../managers/LayersManager"; /** * Interface representing a Line Layer. */ export interface ILineLayer extends IBaseLayer { /** * The type of the layer, which is `Line`. */ type: LayerType.Line; /** * The properties specific to the Line Layer. */ props: ILineLayerProps; } /** * Interface representing the properties of a Line Layer. */ export interface ILineLayerProps extends IBaseLayerProps { /** * The end point of the line, including x and y coordinates. */ endPoint: { /** * The x-coordinate of the end point. */ x: ScaleType; /** * The y-coordinate of the end point. */ y: ScaleType; }; /** * The stroke properties of the line. */ stroke: { /** * The width of the stroke. */ width: number; /** * The cap style of the stroke. */ cap: CanvasLineCap; /** * The join style of the stroke. */ join: CanvasLineJoin; /** * The dash offset of the stroke. */ dashOffset: number; /** * The dash pattern of the stroke. */ dash: number[]; /** * The miter limit of the stroke. */ miterLimit: number; }; } /** * Class representing a Line Layer, extending the BaseLayer class. */ export declare class LineLayer extends BaseLayer<ILineLayerProps> { /** * The properties of the Line Layer. */ props: ILineLayerProps; /** * Constructs a new LineLayer instance. * @param props {ILineLayerProps} - The properties of the Line Layer. * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer. */ constructor(props?: ILineLayerProps, misc?: IBaseLayerMisc); /** * Sets the end position of the line layer. * @param x {ScaleType} - The x-coordinate of the end point. * @param y {ScaleType} - The y-coordinate of the end point. * @returns {this} The current instance for chaining. */ setEndPosition(x: ScaleType, y: ScaleType): this; /** * Sets the color of the line layer. * @param color {ColorType} - The color of the line. * @returns {this} The current instance for chaining. * @throws {LazyError} If the color is not provided or invalid. */ setColor(color: ColorType): this; /** * Sets the stroke properties of the line layer. * @param width {number} - The width of the stroke. * @param cap {CanvasLineCap} - The cap style of the stroke. * @param join {CanvasLineJoin} - The join style of the stroke. * @param dash {number[]} - The dash pattern of the stroke. * @param dashOffset {number} - The dash offset of the stroke. * @param miterLimit {number} - The miter limit of the stroke. * @returns {this} The current instance for chaining. */ setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this; /** * Calculates the bounding box of the line layer. * @param ctx {SKRSContext2D} - The canvas rendering context. * @param canvas {Canvas | SvgCanvas} - The canvas instance. * @param manager {LayersManager} - The layers manager. * @returns {Object} The bounding box details including start and end points, width, and height. */ getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): { xs: number; ys: number; xe: number; ye: number; width: number; height: number; }; /** * Draws the line 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. */ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>; /** * Converts the Line Layer to a JSON representation. * @returns {ILineLayer} The JSON representation of the Line Layer. */ toJSON(): ILineLayer; }