import { useMemo } from 'react' import type { HTMLAttributes, ReactNode } from 'react' import { cn } from '@/lib/utils' import { motion } from 'framer-motion' export interface ThinkingIndicatorProps extends HTMLAttributes { text?: string textClassName?: string shimmer?: boolean shimmerDuration?: number shimmerSpread?: number /** 主库可注入 Lottie 等自定义动画;不传则用 CSS 三点脉动 */ loader?: ReactNode } /** 默认:CSS 三点脉动,无 Lottie 依赖 */ function DefaultLoader() { return ( ) } export function ThinkingIndicator({ text = 'Spark is Thinking...', textClassName, shimmer = true, shimmerDuration = 2, shimmerSpread = 2, className, loader, ...props }: ThinkingIndicatorProps) { const dynamicSpread = useMemo(() => { const textToUse = text || '' return textToUse.length * shimmerSpread }, [text, shimmerSpread]) const loaderContent = loader ?? return ( {loaderContent} {shimmer ? ( {text} ) : ( {text} )} ) } ThinkingIndicator.displayName = 'ThinkingIndicator'