@nmmty/lazycanvas
Version:
A simple way to interact with @napi-rs/canvas in an advanced way!
127 lines (126 loc) • 4.66 kB
TypeScript
import { AnyLayer } from "../../types";
import { Group } from "../components";
/**
* Interface representing the LayersManager.
*/
export interface ILayersManager {
/**
* 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 {
/**
* 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 opts {Object} - Optional settings for the LayersManager.
* @param opts.debug {boolean} - Whether debugging is enabled.
*/
constructor(opts?: {
debug?: boolean;
});
/**
* Adds layers or groups to the map.
* @param layers {Array<AnyLayer | Group>} - 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 ids {string[]} - 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 id {string} - The ID of the layer or group to retrieve.
* @param cross {boolean} - 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 id {string} - 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 callbackfn {Function} - 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 json {object} - 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 {Array<AnyLayer | Group>} - 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 id {string} - 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;
}