"use client"; import { useEffect, useState } from "react"; export function ReadingProgress() { const [progress, setProgress] = useState(0); useEffect(() => { function onScroll() { const doc = document.documentElement; const scrollTop = doc.scrollTop; const scrollHeight = doc.scrollHeight - doc.clientHeight; const pct = scrollHeight > 0 ? (scrollTop / scrollHeight) * 100 : 0; setProgress(Math.min(100, Math.max(0, pct))); } onScroll(); window.addEventListener("scroll", onScroll, { passive: true }); return () => window.removeEventListener("scroll", onScroll); }, []); return (
); }