'use client';


import { useCallback, useSyncExternalStore } from "react";

//#region src/hooks/useScrollY.ts
const useScrollY = () => {
	const subscribe = useCallback((onChange) => {
		if (typeof window === "undefined") return () => {};
		let raf = 0;
		const handler = () => {
			if (raf) return;
			raf = window.requestAnimationFrame(() => {
				raf = 0;
				onChange();
			});
		};
		window.addEventListener("scroll", handler, { passive: true });
		return () => {
			window.removeEventListener("scroll", handler);
			if (raf) window.cancelAnimationFrame(raf);
		};
	}, []);
	const getSnapshot = () => {
		if (typeof window === "undefined") return 0;
		const doc = document.documentElement;
		const body = document.body;
		return window.scrollY ?? window.pageYOffset ?? doc?.scrollTop ?? body?.scrollTop ?? 0;
	};
	const getServerSnapshot = () => 0;
	return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
};

//#endregion
export { useScrollY };
//# sourceMappingURL=useScrollY.mjs.map