@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
137 lines (136 loc) • 4.88 kB
TypeScript
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/LayersManager";
/**
* 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;
/**
* 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 props {IBezierLayerProps} - The properties of the Bezier layer.
* @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
*/
constructor(props?: IBezierLayerProps, misc?: IBaseLayerMisc);
/**
* Sets the control points of the Bezier layer.
* @param controlPoints {Array<{ x: ScaleType, y: ScaleType }>} - 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 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 Bezier layer.
* @param color {ColorType} - 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 width {number} - The width of the stroke.
* @param cap {string} - The cap style of the stroke.
* @param join {string} - 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 Bezier 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 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 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 Bezier layer to a JSON representation.
* @returns {IBezierLayer} The JSON representation of the Bezier layer.
*/
toJSON(): IBezierLayer;
}