UNPKG

@nmmty/lazycanvas

Version:

A simple way to interact with @napi-rs/canvas in an advanced way!

133 lines (132 loc) 3.96 kB
import { AnyGlobalCompositeOperation, AnyLayer, LayerType } from "../../types"; import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas"; import { LayersManager } from "../managers"; /** * Interface representing a group of layer's. */ 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 layer's 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 layer's. */ 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 layer's contained within the group. */ layers: Array<any>; props?: IGroupProps; /** * Constructs a new Group instance. * @param {string} [opts.id] - The unique identifier of the group. * @param {boolean} [opts.visible] - The visibility of the group. * @param {number} [opts.zIndex] - The z-index of the group. */ constructor(opts?: { id?: string; visible?: boolean; zIndex?: number; }); /** * Sets the ID of the group. * @param {string} [id] - The unique identifier of the group. * @returns {this} The current instance for chaining. */ setID(id: string): this; /** * Sets the visibility of the group. * @param {boolean} [visible] - 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 {number} [zIndex] - The z-index value of the group. * @returns {this} The current instance for chaining. */ setZIndex(zIndex: number): this; /** * Adds components to the group. * @param {AnyLayer[]} [components] - 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 {string} [id] - 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 {string} [id] - 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; }