"use client"; import { useEffect, useRef } from 'react'; import { gsap } from 'gsap'; import './GridMotion.css'; const GridMotion = ({ items = [], gradientColor = 'black' }) => { const gridRef = useRef(null); const rowRefs = useRef([]); const mouseXRef = useRef(window.innerWidth / 2); const totalItems = 28; const defaultItems = Array.from({ length: totalItems }, (_, index) => `Item ${index + 1}`); const combinedItems = items.length > 0 ? items.slice(0, totalItems) : defaultItems; useEffect(() => { gsap.ticker.lagSmoothing(0); const handleMouseMove = e => { mouseXRef.current = e.clientX; }; const updateMotion = () => { const maxMoveAmount = 300; const baseDuration = 0.8; const inertiaFactors = [0.6, 0.4, 0.3, 0.2]; rowRefs.current.forEach((row, index) => { if (row) { const direction = index % 2 === 0 ? 1 : -1; const moveAmount = ((mouseXRef.current / window.innerWidth) * maxMoveAmount - maxMoveAmount / 2) * direction; gsap.to(row, { x: moveAmount, duration: baseDuration + inertiaFactors[index % inertiaFactors.length], ease: 'power3.out', overwrite: 'auto' }); } }); }; const removeAnimationLoop = gsap.ticker.add(updateMotion); window.addEventListener('mousemove', handleMouseMove); return () => { window.removeEventListener('mousemove', handleMouseMove); removeAnimationLoop(); }; }, []); return (