{"version":3,"file":"use-intersection.cjs","names":[],"sources":["../../src/use-intersection/use-intersection.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nexport interface UseIntersectionReturnValue<T> {\n  ref: React.RefCallback<T | null>;\n  entry: IntersectionObserverEntry | null;\n}\n\nexport function useIntersection<T extends HTMLElement = any>(\n  options?: IntersectionObserverInit\n): UseIntersectionReturnValue<T> {\n  const [entry, setEntry] = useState<IntersectionObserverEntry | null>(null);\n\n  const observer = useRef<IntersectionObserver | null>(null);\n\n  const ref: React.RefCallback<T | null> = useCallback(\n    (element) => {\n      if (observer.current) {\n        observer.current.disconnect();\n        observer.current = null;\n      }\n\n      if (element === null) {\n        setEntry(null);\n        return;\n      }\n\n      observer.current = new IntersectionObserver(([_entry]) => {\n        setEntry(_entry);\n      }, options);\n\n      observer.current.observe(element);\n    },\n    [options?.rootMargin, options?.root, options?.threshold]\n  );\n\n  return { ref, entry };\n}\n\nexport namespace useIntersection {\n  export type ReturnValue<T> = UseIntersectionReturnValue<T>;\n}\n"],"mappings":";;;AAOA,SAAgB,gBACd,SAC+B;CAC/B,MAAM,CAAC,OAAO,aAAA,GAAA,MAAA,UAAuD,IAAI;CAEzE,MAAM,YAAA,GAAA,MAAA,QAA+C,IAAI;CAuBzD,OAAO;EAAE,MAAA,GAAA,MAAA,cApBN,YAAY;GACX,IAAI,SAAS,SAAS;IACpB,SAAS,QAAQ,WAAW;IAC5B,SAAS,UAAU;GACrB;GAEA,IAAI,YAAY,MAAM;IACpB,SAAS,IAAI;IACb;GACF;GAEA,SAAS,UAAU,IAAI,sBAAsB,CAAC,YAAY;IACxD,SAAS,MAAM;GACjB,GAAG,OAAO;GAEV,SAAS,QAAQ,QAAQ,OAAO;EAClC,GACA;GAAC,SAAS;GAAY,SAAS;GAAM,SAAS;EAAS,CAG9C;EAAG;CAAM;AACtB"}