();
useEffect(() => {
if (!hasStarted) {
const startTimeout = setTimeout(() => {
setHasStarted(true);
setRevealedChars(0);
const speedMap = {
slow: 150,
medium: 80,
fast: 40,
instant: 10,
};
const interval = setInterval(() => {
setRevealedChars((prev) => {
const next = prev + 1;
if (next >= children.length) {
clearInterval(interval);
onComplete?.();
if (loop) {
setTimeout(() => {
setRevealedChars(0);
}, 2000);
}
return next;
}
return next;
});
}, speedMap[revealSpeed]);
intervalRef.current = interval;
}, startDelay);
timeoutRef.current = startTimeout;
}
return () => {
clearTimeout(timeoutRef.current);
clearInterval(intervalRef.current);
};
}, [hasStarted, children.length, revealSpeed, startDelay, loop, onComplete]);
const chars = children.split('');
return (
{
if (typeof ref === 'function') ref(node);
containerRef.current = node;
}}
className={`${styles.prophecy} ${ancientFont ? styles.ancientFont : ''} ${className || ''}`}
style={style}
{...props}
>
{children}
{chars.map((char, index) => (
{char === ' ' ? '\u00A0' : char}
))}
);
});
Prophecy.displayName = 'Prophecy';
export default Prophecy;