import { ScrollContainer, StickyState, ContextTrackingConfig } from './types'; /** * Callback for scroll events. */ export type ScrollCallback = (container: ScrollContainer) => void; /** * Callback for scroll edge events. */ export type ScrollEdgeCallback = (edge: 'top' | 'right' | 'bottom' | 'left') => void; /** * Callback for sticky state changes. */ export type StickyCallback = (state: StickyState) => void; /** * Options for scroll tracking. */ export interface ScrollTrackingOptions { /** Throttle interval for scroll events (ms) */ throttleMs?: number; /** Whether to track velocity */ trackVelocity?: boolean; /** Whether to track direction */ trackDirection?: boolean; /** Edge detection threshold (px) */ edgeThreshold?: number; } /** * Tracks scroll containers and their state. * * @remarks * Manages scroll tracking for individual containers, providing * scroll position, velocity, direction, and edge detection. * * @example * ```typescript * const tracker = new ScrollTracker(scrollElement); * * tracker.onScroll((container) => { * console.log('Scroll position:', container.scrollPosition); * }); * * tracker.onEdge((edge) => { * console.log('Reached edge:', edge); * }); * ``` */ export declare class ScrollTracker { /** ID counter for trackers */ private static idCounter; /** The scroll container element */ private readonly element; /** Unique identifier for this tracker */ private readonly id; /** Configuration */ private readonly config; /** Options */ private readonly options; /** Current scroll container state */ private state; /** Velocity tracking state */ private velocityState; /** Last known scroll direction */ private lastDirection; /** Scroll event callbacks */ private readonly scrollCallbacks; /** Edge event callbacks */ private readonly edgeCallbacks; /** Sticky element callbacks */ private readonly stickyCallbacks; /** Sticky element states */ private readonly stickyStates; /** Throttle timer */ private throttleTimer; /** Last throttle time */ private lastThrottleTime; /** Animation frame handle */ private rafHandle; /** Whether scrolling is in progress */ private isScrolling; /** Scroll end detection timer */ private scrollEndTimer; /** Whether we're in SSR mode */ private readonly isSSR; /** * Creates a new ScrollTracker. * * @param element - Scroll container element * @param config - Tracking configuration * @param options - Scroll tracking options */ constructor(element: Element, config?: Partial, options?: ScrollTrackingOptions); /** * Gets the current scroll container state. * * @returns Current ScrollContainer state */ getState(): ScrollContainer; /** * Gets the tracker ID. * * @returns Unique identifier */ getId(): string; /** * Gets the scroll container element. * * @returns The scroll container element */ getElement(): Element; /** * Subscribes to scroll events. * * @param callback - Callback function * @returns Unsubscribe function */ onScroll(callback: ScrollCallback): () => void; /** * Subscribes to edge events. * * @param callback - Callback function * @returns Unsubscribe function */ onEdge(callback: ScrollEdgeCallback): () => void; /** * Registers a sticky element for tracking. * * @param element - Sticky element * @param callback - Callback for state changes * @returns Unregister function */ trackSticky(element: Element, callback: StickyCallback): () => void; /** * Scrolls to a specific position. * * @param options - Scroll options */ scrollTo(options: { x?: number; y?: number; behavior?: 'auto' | 'smooth'; }): void; /** * Scrolls by a relative offset. * * @param options - Scroll options */ scrollBy(options: { x?: number; y?: number; behavior?: 'auto' | 'smooth'; }): void; /** * Scrolls to top. * * @param behavior - Scroll behavior */ scrollToTop(behavior?: 'auto' | 'smooth'): void; /** * Scrolls to bottom. * * @param behavior - Scroll behavior */ scrollToBottom(behavior?: 'auto' | 'smooth'): void; /** * Scrolls an element into view within this container. * * @param element - Element to scroll to * @param options - Scroll into view options */ scrollIntoView(element: Element, options?: ScrollIntoViewOptions): void; /** * Forces a state refresh. */ refresh(): void; /** * Destroys the tracker and cleans up resources. */ destroy(): void; /** * Attaches scroll event listener. */ private attachListeners; /** * Handles scroll events with throttling. */ private handleScroll; /** * Computes the current scroll container state. */ private computeState; /** * Creates default state for SSR. */ private createDefaultState; /** * Updates state and notifies listeners. */ private updateState; /** * Updates velocity tracking. */ private updateVelocity; /** * Updates scroll direction. */ private updateDirection; /** * Notifies all scroll callbacks. */ private notifyScrollCallbacks; /** * Checks and emits edge events. */ private checkEdgeEvents; /** * Updates all sticky element states. */ private updateAllStickyStates; /** * Updates sticky state for an element. */ private updateStickyState; /** * Computes sticky state for an element. */ private computeStickyState; } /** * Registry for managing multiple scroll trackers. */ export declare class ScrollContainerRegistry { private static instance; /** Map of elements to their trackers */ private readonly trackers; /** Set of all active trackers */ private readonly activeTrackers; private constructor(); /** * Gets the singleton instance. */ static getInstance(): ScrollContainerRegistry; /** * Gets or creates a tracker for an element. * * @param element - Scroll container element * @param options - Tracking options * @returns ScrollTracker instance */ getTracker(element: Element, options?: ScrollTrackingOptions): ScrollTracker; /** * Removes a tracker. * * @param element - Scroll container element */ removeTracker(element: Element): void; /** * Finds the nearest scroll container for an element. * * @param element - Element to check * @returns Scroll container tracker or null */ findScrollContainer(element: Element): ScrollTracker | null; /** * Gets all active trackers. */ getAllTrackers(): ScrollTracker[]; /** * Destroys all trackers. */ destroyAll(): void; } /** * Gets the scroll container registry instance. */ export declare function getScrollContainerRegistry(): ScrollContainerRegistry; /** * Finds the nearest scroll container for an element. * * @param element - Element to check * @returns ScrollTracker or null */ export declare function findScrollContainer(element: Element): ScrollTracker | null; /** * Creates a scroll tracker for an element. * * @param element - Scroll container element * @param options - Tracking options * @returns ScrollTracker instance */ export declare function createScrollTracker(element: Element, options?: ScrollTrackingOptions): ScrollTracker;