"use client"; import { useEffect } from "react"; import { usePathname } from "next/navigation"; const REVEAL_SELECTOR = ".reveal, .reveal-left, .reveal-right, .reveal-scale, .reveal-fade"; /** * On every route change, applies `.in-view` to any reveal element whose * top edge is already within the viewport. This handles standalone pages * (like /bestall, /katalog/[id]) that are fully visible on load, where * IntersectionObserver alone may not fire before the user sees blank content. */ export function RouteReveal() { const pathname = usePathname(); useEffect(() => { const vh = window.innerHeight; const apply = () => { document.querySelectorAll(REVEAL_SELECTOR).forEach((el) => { if (!el.classList.contains("in-view")) { const { top } = el.getBoundingClientRect(); if (top < vh * 0.95) el.classList.add("in-view"); } }); }; // Two passes: immediate + after paint (for async-loaded content). apply(); const raf = requestAnimationFrame(apply); const t = setTimeout(apply, 600); return () => { cancelAnimationFrame(raf); clearTimeout(t); }; }, [pathname]); return null; }