@ssgoi/core
Version:
Core animation engine for SSGOI - Native app-like page transitions with spring physics
43 lines • 1.5 kB
TypeScript
/**
* Global MutationObserver for detecting element unmount
*
* This module provides a shared observer that watches for DOM removals
* and triggers cleanup callbacks when watched elements are removed.
*
* Key features:
* - Single shared observer for all transitions (performance)
* - subtree: true to detect removals at any depth
* - Optimized: only checks removedNodes, not all watched elements
* - Framework agnostic: works with React 18/19, Svelte, Vue, etc.
*/
type UnmountCallback = () => void;
/**
* Register an element to watch for unmount
*
* When the element is removed from DOM, the callback is executed
* and the element is automatically unregistered.
*
* @param element - The element to watch
* @param callback - Callback to execute when element is removed from DOM
*/
export declare function watchUnmount(element: HTMLElement, callback: UnmountCallback): void;
/**
* Check if an element is being watched
*/
export declare function isWatched(element: HTMLElement): boolean;
/**
* Get the number of watched elements (for debugging)
*/
export declare function getWatchedCount(): number;
/**
* Manually trigger unmount for an element
* Useful when cleanup is called explicitly (React 19, Svelte destroy)
*/
export declare function triggerUnmount(element: HTMLElement): boolean;
/**
* Cleanup all watchers and disconnect observer
* Mainly for testing purposes
*/
export declare function resetObserver(): void;
export {};
//# sourceMappingURL=unmount-observer.d.ts.map