"use client"; import { useEffect, useState } from "react"; export default function ReadingProgress() { const [progress, setProgress] = useState(0); useEffect(() => { let raf = 0; const update = () => { raf = 0; const doc = document.documentElement; const max = doc.scrollHeight - doc.clientHeight; setProgress(max > 0 ? Math.min(1, doc.scrollTop / max) : 0); }; const onScroll = () => { if (!raf) raf = requestAnimationFrame(update); }; update(); window.addEventListener("scroll", onScroll, { passive: true }); window.addEventListener("resize", onScroll); return () => { window.removeEventListener("scroll", onScroll); window.removeEventListener("resize", onScroll); if (raf) cancelAnimationFrame(raf); }; }, []); if (progress <= 0) return null; return (