'use client'; /** * Scroll-reveal wrapper — adds `.is-visible` when the block enters the * viewport. The animation itself lives in globals.css strictly inside a * `prefers-reduced-motion: no-preference` guard, so with reduced motion the * content is simply visible (the base .reveal-scroll styles are also inside * the guard — no hidden content ever). */ import * as React from 'react'; import { cn } from '@/core/lib/utils'; export function Reveal({ children, className, /** transition-delay in ms for stagger */ delay = 0, as: Tag = 'div', }: { children: React.ReactNode; className?: string; delay?: number; as?: 'div' | 'section' | 'li' | 'span'; }) { const ref = React.useRef(null); const [visible, setVisible] = React.useState(false); React.useEffect(() => { const el = ref.current; if (!el) return; if ( typeof window === 'undefined' || !('IntersectionObserver' in window) || window.matchMedia('(prefers-reduced-motion: reduce)').matches ) { setVisible(true); return; } const io = new IntersectionObserver( (entries) => { for (const entry of entries) { if (entry.isIntersecting) { setVisible(true); io.disconnect(); break; } } }, { rootMargin: '0px 0px -10% 0px', threshold: 0.08 } ); io.observe(el); // Safety net: never leave content hidden if the observer misfires // (embedded webviews, print, prerender snapshots). const failSafe = window.setTimeout(() => setVisible(true), 2000); return () => { io.disconnect(); window.clearTimeout(failSafe); }; }, []); const Comp = Tag as React.ElementType; return ( {children} ); }