@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
141 lines (140 loc) • 4.74 kB
TypeScript
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
import { ColorType, ScaleType, LayerType, RadiusCorner } from "../../types";
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
import { LayersManager } from "../managers";
/**
* Interface representing a Morph Layer.
*/
export interface IMorphLayer extends IBaseLayer {
/**
* The type of the layer, which is `Morph`.
*/
type: LayerType.Morph;
/**
* The properties specific to the Morph Layer.
*/
props: IMorphLayerProps;
}
/**
* Interface representing the properties of a Morph Layer.
*/
export interface IMorphLayerProps extends IBaseLayerProps {
/**
* The size of the Morph Layer, including width, height, and radius.
*/
size: {
/**
* The width of the Morph Layer.
*/
width: ScaleType;
/**
* The height of the Morph Layer.
*/
height: ScaleType;
/**
* The radius of the Morph Layer.
*/
radius: {
[corner in RadiusCorner]?: ScaleType;
};
};
/**
* Whether the layer is filled.
*/
filled: boolean;
/**
* The fill style (color or pattern) of the layer.
*/
fillStyle: ColorType;
/**
* The stroke properties of the morph.
*/
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 Morph Layer, extending the BaseLayer class.
*/
export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
/**
* The properties of the Morph Layer.
*/
props: IMorphLayerProps;
/**
* Constructs a new MorphLayer instance.
* @param {IMorphLayerProps} [props] - The properties of the Morph Layer.
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
*/
constructor(props?: IMorphLayerProps, misc?: IBaseLayerMisc);
/**
* Sets the size of the Morph Layer.
* @param {ScaleType} [width] - The width of the Morph Layer.
* @param {ScaleType} [height] - The height of the Morph Layer.
* @param {{ [corner in radiusCorner]?: ScaleType }} [radius] - The radius of the Morph Layer (optional).
* @returns {this} The current instance for chaining.
*/
setSize(width: ScaleType, height: ScaleType, radius?: {
[corner in RadiusCorner]?: ScaleType;
}): this;
/**
* Sets the color of the Morph 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 Morph 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 Morph 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 Morph Layer to a JSON representation.
* @returns {IMorphLayer} The JSON representation of the Morph Layer.
*/
toJSON(): IMorphLayer;
/**
* Validates the properties of the Morph Layer.
* @param {IMorphLayerProps} [data] - The properties to validate.
* @returns {IMorphLayerProps} The validated properties.
*/
protected validateProps(data: IMorphLayerProps): IMorphLayerProps;
}