{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"click-spark","type":"registry:ui","title":"Click Spark","description":"A wrapper that throws short spark lines out of every click inside it.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/click-spark.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { useRef, useState, type MouseEvent, type ReactNode } from \"react\";\n\ntype ClickSparkProps = {\n  children: ReactNode;\n  /** Color of the sparks. */\n  color?: string;\n  /** Number of spark lines in each burst. */\n  count?: number;\n  /** How far the sparks travel from the click, in pixels. */\n  radius?: number;\n  /** Length of one burst, in seconds. */\n  duration?: number;\n  className?: string;\n};\n\ntype Burst = { id: number; x: number; y: number };\n\n/** A wrapper that throws short spark lines out of every click inside it. */\nexport function ClickSpark({\n  children,\n  color = \"#ffc24a\",\n  count = 8,\n  radius = 28,\n  duration = 0.45,\n  className = \"\",\n}: ClickSparkProps) {\n  const reduce = useReducedMotion();\n  const [bursts, setBursts] = useState<Burst[]>([]);\n  const nextId = useRef(0);\n\n  function spark(e: MouseEvent<HTMLDivElement>) {\n    const box = e.currentTarget.getBoundingClientRect();\n    let x = e.clientX;\n    let y = e.clientY;\n    // A keyboard press has no pointer position: start from the center of the element it activated.\n    if (e.detail === 0 && e.target instanceof Element) {\n      const target = e.target.getBoundingClientRect();\n      x = target.left + target.width / 2;\n      y = target.top + target.height / 2;\n    }\n    const id = nextId.current++;\n    setBursts((list) => [...list.slice(-5), { id, x: x - box.left, y: y - box.top }]);\n  }\n\n  function remove(id: number) {\n    setBursts((list) => list.filter((b) => b.id !== id));\n  }\n\n  return (\n    <div className={`relative ${className}`} onClick={spark}>\n      {children}\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\">\n        {bursts.map((b) => (\n          <SparkBurst\n            key={b.id}\n            x={b.x}\n            y={b.y}\n            color={color}\n            count={count}\n            radius={radius}\n            duration={duration}\n            reduce={Boolean(reduce)}\n            onDone={() => remove(b.id)}\n          />\n        ))}\n      </div>\n    </div>\n  );\n}\n\ntype SparkBurstProps = {\n  x: number;\n  y: number;\n  color: string;\n  count: number;\n  radius: number;\n  duration: number;\n  reduce: boolean;\n  onDone: () => void;\n};\n\nfunction SparkBurst({ x, y, color, count, radius, duration, reduce, onDone }: SparkBurstProps) {\n  if (reduce) {\n    // No flying lines: a small dot that fades in place.\n    return (\n      <motion.span\n        className=\"absolute size-2 rounded-full\"\n        style={{ left: x - 4, top: y - 4, backgroundColor: color }}\n        initial={{ opacity: 0.9 }}\n        animate={{ opacity: 0 }}\n        transition={{ duration: 0.35 }}\n        onAnimationComplete={onDone}\n      />\n    );\n  }\n\n  const lines = Math.max(1, Math.round(count));\n  const length = radius * 0.5;\n\n  return (\n    <>\n      {Array.from({ length: lines }, (_, i) => (\n        // The outer span sets the direction; the line then travels along its own x axis.\n        <span\n          key={i}\n          className=\"absolute size-0\"\n          style={{ left: x, top: y, transform: `rotate(${(i / lines) * 360}deg)` }}\n        >\n          <motion.span\n            className=\"absolute left-0 top-[-1px] block h-0.5 origin-left rounded-full\"\n            style={{ width: length, backgroundColor: color }}\n            initial={{ x: radius * 0.1, scaleX: 1, opacity: 1 }}\n            animate={{ x: radius, scaleX: 0, opacity: 0.4 }}\n            transition={{ duration, ease: [0.16, 0.8, 0.3, 1] }}\n            onAnimationComplete={i === 0 ? onDone : undefined}\n          />\n        </span>\n      ))}\n    </>\n  );\n}\n"}]}