import { type RefObject } from 'react'; export interface UseExposureDetectionOptions { /** * 唯一标识,用于判断是否已曝光 * 如果不提供,将使用元素的唯一标识(如果可能) */ exposureKey?: string; /** * 可见性阈值,0-1 之间,默认 0.5(50%) */ threshold?: number; /** * 停留时间(毫秒),默认 2000ms */ duration?: number; /** * 是否只触发一次,默认 true */ once?: boolean; /** * 曝光回调函数 */ onExposure?: () => void; /** * IntersectionObserver 的 rootMargin */ rootMargin?: string; } /** * 曝光检测 Hook * 使用 IntersectionObserver 检测元素是否至少 50% 可见且停留时间超过指定时间 * 确保在整个页面生命周期中只曝光一次 * * @param elementRef - 要检测的元素的 ref * @param options - 配置选项 * @returns 返回清除计时器的方法(用于切换时清理) * * @example * ```tsx * const MyComponent = () => { * const ref = useRef(null) * const { clearTimer } = useExposureDetection(ref, { * exposureKey: 'my-component-1', * threshold: 0.5, * duration: 2000, * onExposure: () => { * console.log('元素已曝光') * } * }) * * return
内容
* } * ``` */ export declare const useExposureDetection: (elementRef: RefObject, options?: UseExposureDetectionOptions) => { clearTimer: () => void; }; /** * 清除指定 key 的曝光记录(用于测试或特殊场景) */ export declare const clearExposureRecord: (key: string) => void; /** * 清除所有曝光记录(用于测试或特殊场景) */ export declare const clearAllExposureRecords: () => void; /** * 检查指定 key 是否已曝光 */ export declare const hasExposed: (key: string) => boolean;