{"version":3,"file":"use-throttle.cjs","names":[],"sources":["../../src/hooks/use-throttle.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\n/**\n * Return a value that updates at most once every `delay` ms. Complements\n * `useDebounce` — throttle emits on the leading edge and again after the\n * interval; debounce only emits after a period of stillness.\n *\n * @example\n * const throttledScroll = useThrottle(scrollY, 100);\n */\nexport function useThrottle<T>(value: T, delay: number): T {\n    const [throttled, setThrottled] = useState<T>(value);\n    const lastEmitRef = useRef<number>(0);\n    const pendingRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n    useEffect(() => {\n        const now = Date.now();\n        const elapsed = now - lastEmitRef.current;\n        if (elapsed >= delay) {\n            lastEmitRef.current = now;\n            setThrottled(value);\n        } else {\n            if (pendingRef.current) clearTimeout(pendingRef.current);\n            pendingRef.current = setTimeout(() => {\n                lastEmitRef.current = Date.now();\n                setThrottled(value);\n            }, delay - elapsed);\n        }\n        return () => {\n            if (pendingRef.current) clearTimeout(pendingRef.current);\n        };\n    }, [value, delay]);\n\n    return throttled;\n}\n"],"mappings":"uBAUA,SAAgB,EAAe,EAAU,EAAkB,CACvD,GAAM,CAAC,EAAW,IAAA,EAAgB,EAAA,SAAA,CAAY,CAAK,EAC7C,GAAA,EAAc,EAAA,OAAA,CAAe,CAAC,EAC9B,GAAA,EAAa,EAAA,OAAA,CAA6C,IAAI,EAoBpE,OAlBA,EAAA,EAAA,UAAA,KAAgB,CACZ,IAAM,EAAM,KAAK,IAAI,EACf,EAAU,EAAM,EAAY,QAWlC,OAVI,GAAW,GACX,EAAY,QAAU,EACtB,EAAa,CAAK,IAEd,EAAW,SAAS,aAAa,EAAW,OAAO,EACvD,EAAW,QAAU,eAAiB,CAClC,EAAY,QAAU,KAAK,IAAI,EAC/B,EAAa,CAAK,CACtB,EAAG,EAAQ,CAAO,OAET,CACL,EAAW,SAAS,aAAa,EAAW,OAAO,CAC3D,CACJ,EAAG,CAAC,EAAO,CAAK,CAAC,EAEV,CACX"}