UNPKG

@nmmty/lazycanvas

Version:

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

151 lines (150 loc) 5.35 kB
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer"; import { ColorType, Point, ScaleType, LayerType } from "../../types"; import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas"; import { LayersManager } from "../managers"; /** * Interface representing a Bezier layer. */ export interface IBezierLayer extends IBaseLayer { /** * The type of the layer, which is a Bézier curve. */ type: LayerType.BezierCurve; /** * The properties specific to the Bezier layer. */ props: IBezierLayerProps; } /** * Interface representing the properties of a Bezier layer. */ export interface IBezierLayerProps extends IBaseLayerProps { /** * The control points of the Bézier curve. */ controlPoints: Array<Point>; /** * The end point of the Bézier curve. */ endPoint: Point; /** * Whether the layer is filled. */ filled: boolean; /** * The fill style (color or pattern) of the layer. */ fillStyle: ColorType; /** * The stroke properties of the Bézier curve. */ 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 Bezier layer, extending the BaseLayer class. */ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> { /** * The properties of the Bezier layer. */ props: IBezierLayerProps; /** * Constructs a new BezierLayer instance. * @param {IBezierLayerProps} [props] - The properties of the Bezier layer. * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer. */ constructor(props?: IBezierLayerProps, misc?: IBaseLayerMisc); /** * Sets the control points of the Bezier layer. * @param {Array<{ x: ScaleType, y: ScaleType }>} [controlPoints] - The control points of the Bezier layer. * @returns {this} The current instance for chaining. * @throws {LazyError} If the number of control points is not exactly 2. */ setControlPoints(...controlPoints: { x: ScaleType; y: ScaleType; }[]): this; /** * Sets the end position of the Bezier 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 Bezier 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 Bezier 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 Bezier 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 max, min, center, width, and height. */ getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): { max: Point; min: Point; center: Point; width: number; height: number; }; /** * Draws the Bezier 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 Bezier layer to a JSON representation. * @returns {IBezierLayer} The JSON representation of the Bezier layer. */ toJSON(): IBezierLayer; /** * Validates the properties of the Bezier layer. * @param {IBezierLayerProps} [data] - The properties to validate. * @returns {IBezierLayerProps} The validated properties. */ protected validateProps(data: IBezierLayerProps): IBezierLayerProps; }