"use client"; import type { Variants } from "motion/react"; import { motion, useAnimation } from "motion/react"; import type { HTMLAttributes } from "react"; import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, } from "react"; import { cn } from "@/utils/cn"; export interface FingerprintIconHandle { startAnimation: () => void; stopAnimation: () => void; } interface FingerprintIconProps extends HTMLAttributes { size?: number; autoAnimate?: boolean; animationDelay?: number; } const pathVariants: Variants = { normal: { pathLength: 1, opacity: 1 }, animate: { opacity: [0, 0, 1, 1, 1], pathLength: [0.1, 0.3, 0.5, 0.7, 0.9, 1], transition: { opacity: { duration: 0.5 }, pathLength: { duration: 2, }, }, }, }; const FingerprintIcon = forwardRef( ( { onMouseEnter, onMouseLeave, className, size = 28, autoAnimate = true, animationDelay = 0, ...props }, ref, ) => { const controls = useAnimation(); const isControlledRef = useRef(false); useImperativeHandle(ref, () => { isControlledRef.current = true; return { startAnimation: () => controls.start("animate"), stopAnimation: () => controls.start("normal"), }; }); useEffect(() => { if (autoAnimate && !isControlledRef.current) { const timer = setTimeout(() => { controls.start("animate"); }, animationDelay); return () => clearTimeout(timer); } }, [autoAnimate, animationDelay, controls]); const handleMouseEnter = useCallback( (e: React.MouseEvent) => { if (!isControlledRef.current) { controls.start("animate"); } onMouseEnter?.(e); }, [controls, onMouseEnter], ); const handleMouseLeave = useCallback( (e: React.MouseEvent) => { if (!isControlledRef.current) { controls.start("normal"); } onMouseLeave?.(e); }, [controls, onMouseLeave], ); return (
); }, ); FingerprintIcon.displayName = "FingerprintIcon"; export { FingerprintIcon };