"use client" import * as React from "react" import { css } from '@hanzo/ui' import { motion } from "motion/react" import { cn } from "./utils" interface AnimatedBeamProps extends React.SVGAttributes { duration?: number delay?: number pathColor?: string pathWidth?: number gradientStartColor?: string gradientStopColor?: string containerRef?: React.RefObject fromRef?: React.RefObject toRef?: React.RefObject } const AnimatedBeam = React.forwardRef( ( { className, duration = 3, delay = 0, pathColor = "gray", pathWidth = 2, gradientStartColor = "#18CCFC", gradientStopColor = "#6344F5", containerRef, fromRef, toRef, ...props }, ref ) => { const [pathD, setPathD] = React.useState("") React.useEffect(() => { if (!containerRef?.current || !fromRef?.current || !toRef?.current) return const updatePath = () => { const containerRect = containerRef.current!.getBoundingClientRect() const fromRect = fromRef.current!.getBoundingClientRect() const toRect = toRef.current!.getBoundingClientRect() const fromX = fromRect.left - containerRect.left + fromRect.width / 2 const fromY = fromRect.top - containerRect.top + fromRect.height / 2 const toX = toRect.left - containerRect.left + toRect.width / 2 const toY = toRect.top - containerRect.top + toRect.height / 2 const controlX = (fromX + toX) / 2 const controlY = Math.min(fromY, toY) - 50 setPathD(`M ${fromX} ${fromY} Q ${controlX} ${controlY} ${toX} ${toY}`) } updatePath() window.addEventListener("resize", updatePath) return () => window.removeEventListener("resize", updatePath) }, [containerRef, fromRef, toRef]) return ( ) } ) AnimatedBeam.displayName = "AnimatedBeam" export { AnimatedBeam }