import { useEffect, useRef } from "react" import { cn } from "@/lib/utils" interface TextShimmerProps extends React.HTMLAttributes { duration?: number children: React.ReactNode } export const TextShimmer: React.FC = ({ className, duration = 3, children, ...props }) => { const shimmerRef = useRef(null) useEffect(() => { const shimmerElement = shimmerRef.current if (!shimmerElement) return const animateShimmer = () => { const startTime = performance.now() let animationFrameId: number const animate = (currentTime: number) => { const elapsed = (currentTime - startTime) / 1000 const progress = (elapsed % duration) / duration const position = progress * 200 - 100 // -100% to 100% if (shimmerElement) { shimmerElement.style.backgroundPosition = `${position}% 0` } animationFrameId = requestAnimationFrame(animate) } animationFrameId = requestAnimationFrame(animate) return () => { cancelAnimationFrame(animationFrameId) } } const cleanup = animateShimmer() return cleanup }, [duration]) return (
{children}
) }