import { ZIndexLayer, ZIndexContext, ContextTrackingConfig } from './types'; /** * Registration for a z-index allocation. */ export interface ZIndexRegistration { /** Unique registration ID */ id: string; /** The element being registered */ element: Element; /** Assigned layer */ layer: ZIndexLayer; /** Assigned z-index value */ zIndex: number; /** Priority within layer (higher = on top) */ priority: number; /** Registration timestamp */ registeredAt: number; } /** * Options for z-index registration. */ export interface ZIndexRegistrationOptions { /** Layer to register in */ layer?: ZIndexLayer; /** Priority within layer (default: 0) */ priority?: number; /** Whether to auto-increment within layer */ autoIncrement?: boolean; } /** * Callback for z-index changes. */ export type ZIndexChangeCallback = (registration: ZIndexRegistration) => void; /** * Manages z-index values across the application. * * @remarks * Provides a centralized system for z-index management that prevents * conflicts and ensures consistent layering behavior. * * @example * ```typescript * const manager = ZIndexManager.getInstance(); * * // Register an element in the modal layer * const reg = manager.register(element, { layer: 'modal' }); * * // Apply the z-index * element.style.zIndex = String(reg.zIndex); * * // When done: * manager.unregister(reg.id); * ``` */ export declare class ZIndexManager { private static instance; /** Map of registration IDs to registrations */ private readonly registrations; /** Map of elements to their registration IDs */ private readonly elementToId; /** Map of layers to their registration IDs (ordered by z-index) */ private readonly layerRegistrations; /** Current offset within each layer */ private readonly layerOffsets; /** Change callbacks */ private readonly changeCallbacks; /** Configuration */ private readonly config; /** Registration ID counter */ private registrationIdCounter; /** * Creates a new ZIndexManager instance. */ private constructor(); /** * Gets the singleton instance. */ static getInstance(config?: Partial): ZIndexManager; /** * Resets the singleton instance. */ static resetInstance(): void; /** * Registers an element for z-index management. * * @param element - Element to register * @param options - Registration options * @returns Registration object */ register(element: Element, options?: ZIndexRegistrationOptions): ZIndexRegistration; /** * Unregisters an element. * * @param idOrElement - Registration ID or element to unregister */ unregister(idOrElement: string | Element): void; /** * Updates an existing registration. * * @param id - Registration ID * @param options - New options * @returns Updated registration or null */ update(id: string, options: Partial): ZIndexRegistration | null; /** * Gets the registration for an element. * * @param element - Element to look up * @returns Registration or null */ getRegistration(element: Element): ZIndexRegistration | null; /** * Gets all registrations in a layer. * * @param layer - Layer to query * @returns Array of registrations (sorted by z-index) */ getLayerRegistrations(layer: ZIndexLayer): ZIndexRegistration[]; /** * Gets the z-index for a layer. * * @param layer - Layer to query * @returns Base z-index for the layer */ getLayerZIndex(layer: ZIndexLayer): number; /** * Gets the z-index context for an element. * * @param element - Element to query * @returns Z-index context */ getZIndexContext(element: Element): ZIndexContext; /** * Gets the next available z-index in a layer. * * @param layer - Layer to query * @returns Next z-index value */ getNextZIndex(layer: ZIndexLayer): number; /** * Gets the highest z-index currently in use in a layer. * * @param layer - Layer to query * @returns Highest z-index or base layer z-index */ getHighestZIndex(layer: ZIndexLayer): number; /** * Subscribes to z-index changes. * * @param callback - Change callback * @returns Unsubscribe function */ onChange(callback: ZIndexChangeCallback): () => void; /** * Brings an element to the front of its layer. * * @param element - Element to bring to front */ bringToFront(element: Element): void; /** * Sends an element to the back of its layer. * * @param element - Element to send to back */ sendToBack(element: Element): void; /** * Clears all registrations. */ clear(): void; /** * Generates a unique registration ID. */ private generateId; /** * Sorts registrations within a layer by z-index. */ private sortLayer; /** * Rebalances z-index values within a layer. */ private rebalanceLayer; /** * Notifies change callbacks. */ private notifyChange; /** * Finds the stacking context root for an element. */ private findStackingContextRoot; /** * Checks if an element creates a stacking context. */ private createsStackingContext; } /** * Gets the z-index manager instance. */ export declare function getZIndexManager(): ZIndexManager; /** * Registers an element for z-index management. * * @param element - Element to register * @param options - Registration options * @returns Registration object */ export declare function registerZIndex(element: Element, options?: ZIndexRegistrationOptions): ZIndexRegistration; /** * Unregisters an element from z-index management. * * @param idOrElement - Registration ID or element */ export declare function unregisterZIndex(idOrElement: string | Element): void; /** * Gets the z-index for a specific layer. * * @param layer - Layer to query * @returns Z-index value */ export declare function getLayerZIndex(layer: ZIndexLayer): number; /** * Brings an element to the front of its layer. * * @param element - Element to bring to front */ export declare function bringToFront(element: Element): void; /** * Sends an element to the back of its layer. * * @param element - Element to send to back */ export declare function sendToBack(element: Element): void;