{"version":3,"file":"use-intersection-observer.cjs","names":[],"sources":["../../src/hooks/use-intersection-observer.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport type { RefObject } from \"react\";\n\nexport interface UseIntersectionObserverOptions extends IntersectionObserverInit {\n    /** Stop observing after the first intersection (one-shot). Default: false. */\n    once?: boolean;\n}\n\n/**\n * Track whether the referenced element intersects the viewport. Useful for\n * lazy-loading images, \"load more\" sentinels, and animation triggers.\n *\n * @returns `IntersectionObserverEntry | null`. `null` until the first observation.\n */\nexport function useIntersectionObserver(\n    ref: RefObject<Element | null>,\n    options: UseIntersectionObserverOptions = {},\n): IntersectionObserverEntry | null {\n    const [entry, setEntry] = useState<IntersectionObserverEntry | null>(null);\n    const { once = false, root, rootMargin, threshold } = options;\n\n    useEffect(() => {\n        const target = ref.current;\n        if (!target || typeof IntersectionObserver === \"undefined\") return;\n\n        const observer = new IntersectionObserver(\n            ([nextEntry]) => {\n                if (!nextEntry) return;\n                setEntry(nextEntry);\n                if (once && nextEntry.isIntersecting) observer.unobserve(target);\n            },\n            { root, rootMargin, threshold },\n        );\n\n        observer.observe(target);\n        return () => observer.disconnect();\n    }, [ref, once, root, rootMargin, threshold]);\n\n    return entry;\n}\n"],"mappings":"uBAcA,SAAgB,EACZ,EACA,EAA0C,CAAC,EACX,CAChC,GAAM,CAAC,EAAO,IAAA,EAAY,EAAA,SAAA,CAA2C,IAAI,EACnE,CAAE,OAAO,GAAO,OAAM,aAAY,aAAc,EAmBtD,OAjBA,EAAA,EAAA,UAAA,KAAgB,CACZ,IAAM,EAAS,EAAI,QACnB,GAAI,CAAC,GAAU,OAAO,qBAAyB,IAAa,OAE5D,IAAM,EAAW,IAAI,sBAChB,CAAC,KAAe,CACR,IACL,EAAS,CAAS,EACd,GAAQ,EAAU,gBAAgB,EAAS,UAAU,CAAM,EACnE,EACA,CAAE,OAAM,aAAY,WAAU,CAClC,EAGA,OADA,EAAS,QAAQ,CAAM,MACV,EAAS,WAAW,CACrC,EAAG,CAAC,EAAK,EAAM,EAAM,EAAY,CAAS,CAAC,EAEpC,CACX"}