UNPKG

@nmmty/lazycanvas

Version:

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

137 lines (136 loc) 5.06 kB
import { AnyLayer } from "../../types"; import { Group } from "../components"; import { LazyCanvas } from "../LazyCanvas"; /** * Interface representing the LayersManager. */ export interface ILayersManager { /** * The LazyCanvas instance associated with this manager. */ lazyCanvas: LazyCanvas; /** * A map storing layers or groups with their IDs as keys. */ map: Map<string, AnyLayer | Group>; /** * Whether debugging is enabled. */ debug: boolean; } /** * Class representing a manager for handling layers and groups. */ export declare class LayersManager implements ILayersManager { /** * The LazyCanvas instance associated with this manager. */ lazyCanvas: LazyCanvas; /** * A map storing layers or groups with their IDs as keys. */ map: Map<string, AnyLayer | Group>; /** * Whether debugging is enabled. */ debug: boolean; /** * Constructs a new LayersManager instance. * @param {LazyCanvas} [lazyCanvas] - The LazyCanvas instance to associate with this manager. * @param {Object} [opts] - Optional settings for the LayersManager. * @param {boolean} [opts.debug] - Whether debugging is enabled. */ constructor(lazyCanvas: LazyCanvas, opts?: { debug?: boolean; }); /** * Adds layers or groups to the map. * @param {Array<AnyLayer | Group>} [layers] - The layers or groups to add to the map. * @returns {this} The current instance for chaining. * @throws {LazyError} If a layer with the same ID already exists. */ add(...layers: Array<AnyLayer | Group>): this; /** * Removes layers or groups from the map by their IDs. * @param {string[]} [ids] - The IDs of the layers or groups to remove. * @returns {this} The current instance for chaining. */ remove(...ids: string[]): this; /** * Clears all layers and groups from the map. * @returns {this} The current instance for chaining. */ clear(): this; /** * Retrieves a layer or group from the map by its ID. * @param {string} [id] - The ID of the layer or group to retrieve. * @param {boolean} [cross] - Whether to search within groups for the ID. * @returns {AnyLayer | Group | undefined} The retrieved layer or group, or undefined if not found. */ get(id: string, cross?: boolean): AnyLayer | Group | undefined; /** * Checks if a layer or group exists in the map by its ID. * @param {string} [id] - The ID of the layer or group to check. * @returns {boolean} True if the layer or group exists, false otherwise. */ has(id: string): boolean; /** * Retrieves the number of layers and groups in the map. * @returns {number} The size of the map. */ size(): number; /** * Retrieves the values (layers and groups) from the map. * @returns {IterableIterator<AnyLayer | Group>} An iterator for the map values. */ values(): IterableIterator<AnyLayer | Group>; /** * Retrieves the keys (IDs) from the map. * @returns {IterableIterator<string>} An iterator for the map keys. */ keys(): IterableIterator<string>; /** * Retrieves the entries (key-value pairs) from the map. * @returns {IterableIterator<[string, AnyLayer | Group]>} An iterator for the map entries. */ entries(): IterableIterator<[string, AnyLayer | Group]>; /** * Executes a callback function for each layer or group in the map. * @param {Function} [callbackfn] - The callback function to execute. * @returns {this} The current instance for chaining. */ forEach(callbackfn: (value: AnyLayer | Group, key: string, map: Map<string, AnyLayer | Group>) => void): this; /** * Converts the map to a JSON object. * @returns {object} The JSON representation of the map. */ toJSON(): object; /** * Populates the map from a JSON object. * @param {object} [json] - The JSON object to populate the map from. * @returns {this} The current instance for chaining. */ fromJSON(json: object): this; /** * Converts the map to an array of layers and groups. * @returns {Array<AnyLayer | Group>} An array of layers and groups. */ toArray(): Array<AnyLayer | Group>; /** * Populates the map from an array of layers and groups. * @param {Array<AnyLayer | Group>} [array] - The array of layers and groups to populate the map from. * @returns {this} The current instance for chaining. */ fromArray(array: Array<AnyLayer | Group>): this; /** * Sorts the layers and groups in the map by their zIndex property. * @returns {void} */ sort(): void; /** * Searches for a layer or group by its ID, including within groups. * @param {string} [id] - The ID of the layer or group to search for. * @returns {AnyLayer | Group | undefined} The found layer or group, or undefined if not found. */ private crossSearch; }