{
  "title": "Token Counter",
  "description": "Compact selector for toggling abilities with icons and custom styles",
  "name": "motion-ai-token-counter",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [],
  "type": "registry:ui",
  "files": [
    {
      "path": "components/paceui/motion/ai-token-counter.tsx",
      "type": "registry:ui",
      "content": "import { useEffect, useRef, useState } from \"react\";\n\nimport { animate, motion } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface AiTokenCounterProps extends React.HTMLAttributes<HTMLParagraphElement> {\n    sourceRef: React.RefObject<HTMLElement | null>;\n    token: number;\n    flyingClassName?: string;\n}\n\nexport const AiTokenCounter = ({ sourceRef, token, className, flyingClassName, ...props }: AiTokenCounterProps) => {\n    const [displayCount, setDisplayCount] = useState<number>(token);\n    const lastToken = useRef<number>(token);\n    const counterRef = useRef<HTMLParagraphElement>(null);\n    const flyingRef = useRef<HTMLParagraphElement>(null);\n\n    const ANIMATION_DURATION = 1;\n\n    useEffect(() => {\n        const diff = token - lastToken.current;\n        if (diff === 0 || !sourceRef.current || !counterRef.current || !flyingRef.current) return;\n\n        const startValue = lastToken.current;\n        lastToken.current = token;\n\n        const flyEl = flyingRef.current;\n        flyEl.innerText = `${diff > 0 ? \"+\" : \"\"}${diff}`;\n        flyEl.style.transform = \"none\";\n\n        const src = sourceRef.current.getBoundingClientRect();\n        const dest = counterRef.current.getBoundingClientRect();\n        const fly = flyEl.getBoundingClientRect();\n\n        const start = {\n            x: src.left + src.width / 2 - (fly.left + fly.width / 2),\n            y: src.top + src.height / 2 - (fly.top + fly.height / 2),\n        };\n\n        const end = {\n            x: dest.left + dest.width / 2 - (fly.left + fly.width / 2),\n            y: dest.top + dest.height / 2 - (fly.top + fly.height / 2),\n        };\n\n        const midX = (start.x + end.x) / 2;\n        const midY = Math.min(start.y, end.y) - 24;\n\n        flyEl.style.visibility = \"visible\";\n\n        const flyControls = animate(\n            flyEl,\n            {\n                x: [start.x, midX, end.x],\n                y: [start.y, midY, end.y],\n                scale: [0.5, 1.2, 0.5],\n                opacity: [0, 1, 0],\n            },\n            {\n                duration: ANIMATION_DURATION,\n                x: { duration: ANIMATION_DURATION, ease: \"linear\", times: [0, 0.5, 1] },\n                y: { duration: ANIMATION_DURATION, ease: [\"easeOut\", \"easeIn\"], times: [0, 0.5, 1] },\n                scale: { duration: ANIMATION_DURATION, ease: \"easeInOut\", times: [0, 0.5, 1] },\n                opacity: { duration: ANIMATION_DURATION, ease: \"easeInOut\", times: [0, 0.5, 1] },\n            },\n        );\n\n        const countControls = animate(startValue, token, {\n            duration: ANIMATION_DURATION * 0.2,\n            delay: ANIMATION_DURATION * 0.8,\n            onUpdate: (value) => {\n                setDisplayCount(Math.floor(value));\n            },\n            onComplete: () => {\n                setDisplayCount(token);\n                flyEl.style.visibility = \"hidden\";\n            },\n        });\n\n        return () => {\n            flyControls.stop();\n            countControls.stop();\n        };\n    }, [token, sourceRef]);\n\n    return (\n        <div className=\"flex items-center\">\n            <p ref={counterRef} className={className} {...props}>\n                {displayCount}\n            </p>\n            <div className=\"relative h-0 w-0\">\n                <motion.p ref={flyingRef} className={cn(\"invisible absolute font-bold\", flyingClassName)}>\n                    +0\n                </motion.p>\n            </div>\n        </div>\n    );\n};\n"
    }
  ],
  "mcp": {
    "description": "Provides refined UI interactions and accessible controls. Compact selector for toggling abilities with icons and custom styles Relies on motion. Optimal for building reusable interface elements and user input flows.",
    "tags": [
      "component",
      "motion",
      "animation"
    ]
  }
}