'use client'; import React, { useEffect, useRef, useState } from 'react'; import { cn } from '@/lib/utils'; interface BorderBeamProps { className?: string; size?: number; duration?: number; borderWidth?: number; anchor?: number; colorFrom?: string; colorTo?: string; delay?: number; } /** * Magic UI - Border Beam * Animated traveling light border beam. * Optimized with IntersectionObserver to sleep when out of view, * and falls back to a clean static gradient on mobile/touch to eliminate GPU heating. * Reference: https://magicui.design/docs/components/border-beam */ export function BorderBeam({ className, size = 250, duration = 12, borderWidth = 1.5, anchor = 90, colorFrom = 'var(--color-accent)', colorTo = 'var(--color-accent-hi)', delay = 0, }: BorderBeamProps) { const containerRef = useRef(null); const [isVisible, setIsVisible] = useState(false); const [isTouchDevice, setIsTouchDevice] = useState(false); useEffect(() => { // Detect mobile touch devices to eliminate GPU-churning conic masks if (typeof window !== 'undefined') { const isTouch = window.innerWidth < 1024 || navigator.maxTouchPoints > 0 || 'ontouchstart' in window; setIsTouchDevice(isTouch); } const container = containerRef.current; if (!container) return; const observer = new IntersectionObserver( ([entry]) => { setIsVisible(entry.isIntersecting); }, { threshold: 0.05 } ); observer.observe(container); return () => observer.disconnect(); }, []); return (
); } export default BorderBeam;