UNPKG

@agentman/chat-widget

Version:

Agentman Chat Widget for easy integration with web applications

71 lines (70 loc) 2.17 kB
/** * StickyElementObserver - Detects sticky/fixed elements at viewport bottom * * Automatically detects when elements become "stuck" at the bottom of the viewport * and calculates the total offset needed to position the widget above them. * * Use Case: Shopify sticky "Add to Cart" bars, floating bottom navigation, etc. */ export interface StickyElementConfig { /** Enable automatic detection of sticky elements (default: true) */ enabled?: boolean; /** Additional selectors to specifically watch for sticky behavior */ customSelectors?: string[]; /** Callback when sticky offset changes */ onOffsetChange?: (offset: number) => void; } export declare class StickyElementObserver { private intersectionObserver; private resizeObserver; private mutationObserver; private observedElements; private stickyElements; private stickyElementRefs; private config; private updateCallback; private isSupported; constructor(config?: StickyElementConfig); private init; /** * Quick heuristic check to identify potentially sticky elements * before expensive getComputedStyle calls */ private quickCheckPotentialSticky; /** * Optimized scan using targeted selectors instead of querying all elements */ private scanForStickyElements; /** * Check if elements should be observed */ private checkElements; private isBottomAligned; private observeElement; /** * Track a sticky element with a WeakRef for cleanup */ private trackStickyElement; /** * Remove a sticky element from tracking */ private untrackStickyElement; private handleIntersection; /** * Check if element is actually stuck AT the bottom of viewport * (not just somewhere in the bottom region) */ private isActuallyAtBottom; private getElementHeight; private updateOffset; destroy(): void; /** * Manually trigger a scan for sticky elements * Useful after dynamic content changes */ refresh(): void; /** * Get current total offset */ getCurrentOffset(): number; }