@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
134 lines (133 loc) • 4.01 kB
TypeScript
import { AnyGlobalCompositeOperation, AnyLayer, LayerType } from "../../types";
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
import { LayersManager } from "../managers/LayersManager";
/**
* Interface representing a group of layers.
*/
export interface IGroup {
/**
* The unique identifier of the group.
*/
id: string;
/**
* The type of the group, which is `Group`.
*/
type: LayerType.Group;
/**
* The visibility of the group.
*/
visible: boolean;
/**
* The z-index of the group, determining its stacking order.
*/
zIndex: number;
/**
* The layers contained within the group.
*/
layers: Array<AnyLayer>;
/**
*
*/
props?: IGroupProps;
}
export interface IGroupProps {
/**
* Don't use, this is just for compatibility.
*/
globalComposite: AnyGlobalCompositeOperation;
}
/**
* Class representing a group of layers.
*/
export declare class Group implements IGroup {
/**
* The unique identifier of the group.
*/
id: string;
/**
* The type of the group, which is `Group`.
*/
type: LayerType.Group;
/**
* The visibility of the group.
*/
visible: boolean;
/**
* The z-index of the group, determining its stacking order.
*/
zIndex: number;
/**
* The layers contained within the group.
*/
layers: Array<any>;
props?: IGroupProps;
/**
* Constructs a new Group instance.
* @param opts {Object} - Optional parameters for the group.
* @param opts.id {string} - The unique identifier of the group.
* @param opts.visible {boolean} - The visibility of the group.
* @param opts.zIndex {number} - The z-index of the group.
*/
constructor(opts?: {
id?: string;
visible?: boolean;
zIndex?: number;
});
/**
* Sets the ID of the group.
* @param id {string} - The unique identifier of the group.
* @returns {this} The current instance for chaining.
*/
setID(id: string): this;
/**
* Sets the visibility of the group.
* @param visible {boolean} - The visibility state of the group.
* @returns {this} The current instance for chaining.
*/
setVisible(visible: boolean): this;
/**
* Sets the z-index of the group.
* @param zIndex {number} - The z-index value of the group.
* @returns {this} The current instance for chaining.
*/
setZIndex(zIndex: number): this;
/**
* Adds components to the group.
* @param components {AnyLayer[]} - The components to add to the group.
* @returns {this} The current instance for chaining.
*/
add(...components: AnyLayer[]): this;
/**
* Removes a component from the group by its ID.
* @param id {string} - The unique identifier of the component to remove.
* @returns {this} The current instance for chaining.
*/
remove(id: string): this;
/**
* Clears all components from the group.
* @returns {this} The current instance for chaining.
*/
clear(): this;
/**
* Retrieves a component from the group by its ID.
* @param id {string} - The unique identifier of the component to retrieve.
* @returns {AnyLayer | undefined} The component with the specified ID, or undefined if not found.
*/
get(id: string): AnyLayer | undefined;
/**
* Retrieves all components from the group.
* @returns {AnyLayer[]} An array of all components in the group.
*/
getAll(): AnyLayer[];
/**
* Gets the number of components in the group.
* @returns {number} The number of components in the group.
*/
get length(): number;
draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
/**
* Converts the group to a JSON representation.
* @returns {IGroup} The JSON representation of the group.
*/
toJSON(): IGroup;
}