UNPKG

@nmmty/lazycanvas

Version:

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

147 lines (146 loc) 4.98 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"; /** * 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; }; /** * Whether the layer is filled. */ filled: boolean; /** * The fill style (color or pattern) of the layer. */ fillStyle: ColorType; /** * 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 {ILineLayerProps} [props] - The properties of the Line Layer. * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer. */ constructor(props?: ILineLayerProps, misc?: IBaseLayerMisc); /** * Sets the end position of the line layer. * @param {ScaleType} [x] - The x-coordinate of the end point. * @param {ScaleType} [y] - 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 {ColorType} [color] - The color of the layer. * @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 {number} [width] - The width of the stroke. * @param {string} [cap] - The cap style of the stroke. * @param {string} [join] - The join style of the stroke. * @param {number[]} [dash] - The dash pattern of the stroke. * @param {number} [dashOffset] - The dash offset of the stroke. * @param {number} [miterLimit] - 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 {SKRSContext2D} [ctx] - The canvas rendering context. * @param {Canvas | SvgCanvas} [canvas] - The canvas instance. * @param {LayersManager} [manager] - The layer's 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 {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. */ 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; /** * Validates the properties of the Line Layer. * @param {ILineLayerProps} [data] - The properties to validate. * @returns {ILineLayerProps} The validated properties. */ protected validateProps(data: ILineLayerProps): ILineLayerProps; }