import React, { useState, useEffect } from 'react'; interface RotatingTextProps { texts: string[]; transitionDuration?: number; rotationInterval?: number; staggerDuration?: number; staggerFrom?: 'first' | 'last' | 'center' | 'random'; splitBy?: 'characters' | 'words' | 'lines'; mainClassName?: string; splitLevelClassName?: string; elementLevelClassName?: string; animatePresence?: boolean; } export const RotatingText: React.FC = ({ texts, rotationInterval = 2800, staggerDuration = 0.025, splitBy = 'characters', mainClassName = '', splitLevelClassName = '', elementLevelClassName = '', }) => { const [currentIndex, setCurrentIndex] = useState(0); const [animationKey, setAnimationKey] = useState(0); useEffect(() => { if (!texts || texts.length <= 1) return; const interval = setInterval(() => { setCurrentIndex((prev) => (prev + 1) % texts.length); setAnimationKey((prev) => prev + 1); }, rotationInterval); return () => clearInterval(interval); }, [texts, rotationInterval]); const currentText = texts[currentIndex] || ''; const renderElements = () => { if (splitBy === 'characters') { const words = currentText.split(' '); let charCounter = 0; return words.map((word, wordIndex) => ( {word.split('').map((char) => { const index = charCounter++; const delay = index * staggerDuration; return ( {char} ); })} )); } if (splitBy === 'words') { const words = currentText.split(' '); return words.map((word, wordIndex) => { const delay = wordIndex * (staggerDuration * 2.5); return ( {word} ); }); } return ( {currentText} ); }; return ( {renderElements()} ); };