@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
143 lines (142 loc) • 5.08 kB
TypeScript
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
import { ColorType, ScaleType, Point, LayerType } from "../../types";
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
import { LayersManager } from "../managers/LayersManager";
/**
* Interface representing a Quadratic Layer.
*/
export interface IQuadraticLayer extends IBaseLayer {
/**
* The type of the layer, which is `QuadraticCurve`.
*/
type: LayerType.QuadraticCurve;
/**
* The properties specific to the Quadratic Layer.
*/
props: IQuadraticLayerProps;
}
/**
* Interface representing the properties of a Quadratic Layer.
*/
export interface IQuadraticLayerProps extends IBaseLayerProps {
/**
* The control point of the quadratic curve, including x and y coordinates.
*/
controlPoints: Array<Point>;
/**
* The end point of the quadratic curve, including x and y coordinates.
*/
endPoint: Point;
/**
* The stroke properties of the quadratic 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 Quadratic Layer, extending the BaseLayer class.
*/
export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
/**
* The properties of the Quadratic Layer.
*/
props: IQuadraticLayerProps;
/**
* Constructs a new QuadraticLayer instance.
* @param props {IQuadraticLayerProps} - The properties of the Quadratic Layer.
* @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
*/
constructor(props?: IQuadraticLayerProps, misc?: IBaseLayerMisc);
/**
* Sets the control point of the quadratic layer.
* @param x {ScaleType} - The x-coordinate of the control point.
* @param y {ScaleType} - The y-coordinate of the control point.
* @returns {this} The current instance for chaining.
*/
setControlPoint(x: ScaleType, y: ScaleType): this;
/**
* Sets the end point of the quadratic 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 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 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 quadratic curve.
* @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: {
x: number;
y: number;
};
min: {
x: number;
y: number;
};
center: {
x: number;
y: number;
};
width: number;
height: number;
};
/**
* Draws the quadratic curve 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 Quadratic Layer to a JSON representation.
* @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
*/
toJSON(): IQuadraticLayer;
}