@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
125 lines (124 loc) • 4.39 kB
TypeScript
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
import { ColorType, LayerType, ScaleType } from "../../types";
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
import { LayersManager } from "../managers";
export interface IPolygonLayer extends IBaseLayer {
/**
* The type of the layer, which is `Polygon`.
*/
type: LayerType.Polygon;
/**
* The properties specific to the Polygon Layer.
*/
props: IPolygonLayerProps;
}
export interface IPolygonLayerProps extends IBaseLayerProps {
/**
* The size of the Polygon Layer, including width, height, and radius.
*/
size: {
/**
* The width of the Polygon Layer.
*/
width: ScaleType;
/**
* The height of the Polygon Layer.
*/
height: ScaleType;
/**
* The radius of corners in the Polygon Layer.
*/
radius: number;
/**
* The number of sides of the polygon.
*/
count: number;
};
/**
* Whether the layer is filled.
*/
filled: boolean;
/**
* The fill style (color or pattern) of the layer.
*/
fillStyle: ColorType;
/**
* The stroke properties of the polygon.
*/
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;
};
}
export declare class PolygonLayer extends BaseLayer<IPolygonLayerProps> {
props: IPolygonLayerProps;
constructor(props?: IPolygonLayerProps, misc?: IBaseLayerMisc);
/**
* Sets the size of the Polygon layer.
* @param {ScaleType} [width] - The width of the Polygon layer.
* @param {ScaleType} [height] - The height of the Polygon layer.
* @param {number} [count] - The number of sides of the polygon.
* @param {number} [radius] - The radius of the Polygon Layer (optional).
* @returns {this} The current instance for chaining.
*/
setSize(width: ScaleType, height: ScaleType, count: number, radius?: number): this;
/**
* Sets the color of the Polygon 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 Polygon 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;
/**
* Draws the Polygon layer on the given canvas context.
* @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 Polygon layer to a JSON representation.
* @returns {IPolygonLayer} The JSON representation of the Polygon layer.
*/
toJSON(): IPolygonLayer;
/**
* Validates the properties of the Morph Layer.
* @param {IPolygonLayerProps} [data] - The properties to validate.
* @returns {IPolygonLayerProps} The validated properties.
*/
protected validateProps(data: IPolygonLayerProps): IPolygonLayerProps;
}