{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "click-burst",
  "title": "Click Burst",
  "description": "A wrapper that makes anything celebrate a click: sparks, confetti, hearts, expanding rings or stars burst from the exact point you clicked, drawn on a canvas that spills past the element's edges and stops when the last particle fades.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/click-burst/click-burst.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type BurstShape = \"sparks\" | \"confetti\" | \"hearts\" | \"rings\" | \"stars\";\n\nexport interface ClickBurstProps extends Omit<React.ComponentPropsWithoutRef<\"span\">, \"children\"> {\n  children: React.ReactNode;\n  shape?: BurstShape;\n  colors?: string[];\n  /** Particles per click. */\n  count?: number;\n  /** How far particles fly, in px. */\n  spread?: number;\n  /** Burst from the centre instead of the click point (keyboard clicks always use the centre). */\n  fromCenter?: boolean;\n  disabled?: boolean;\n}\n\ntype Particle = { x: number; y: number; vx: number; vy: number; rot: number; vr: number; size: number; life: number; max: number; color: string; kind: BurstShape };\n\nconst PAD = 140;\nconst DEFAULT_COLORS = [\"#ff5a5f\", \"#ffb400\", \"#00c2a8\", \"#7b61ff\", \"#ffffff\"];\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction heart(ctx: CanvasRenderingContext2D, s: number) {\n  ctx.beginPath();\n  ctx.moveTo(0, s * 0.35);\n  ctx.bezierCurveTo(-s, -s * 0.25, -s * 0.45, -s, 0, -s * 0.45);\n  ctx.bezierCurveTo(s * 0.45, -s, s, -s * 0.25, 0, s * 0.35);\n  ctx.fill();\n}\n\nfunction star(ctx: CanvasRenderingContext2D, s: number) {\n  ctx.beginPath();\n  for (let i = 0; i < 10; i++) {\n    const r = i % 2 ? s * 0.42 : s;\n    const a = (i / 10) * Math.PI * 2 - Math.PI / 2;\n    ctx.lineTo(Math.cos(a) * r, Math.sin(a) * r);\n  }\n  ctx.closePath();\n  ctx.fill();\n}\n\nexport function ClickBurst({ children, shape = \"sparks\", colors = DEFAULT_COLORS, count = 18, spread = 90, fromCenter = false, disabled = false, className, onClick, ...props }: ClickBurstProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLSpanElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const particles = React.useRef<Particle[]>([]);\n  const raf = React.useRef(0);\n\n  React.useEffect(() => () => cancelAnimationFrame(raf.current), []);\n\n  const loop = () => {\n    cancelAnimationFrame(raf.current);\n    let last = performance.now();\n    const tick = (now: number) => {\n      const canvas = canvasRef.current;\n      const ctx = canvas?.getContext(\"2d\");\n      if (!canvas || !ctx) return;\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      const dpr = canvas.width / canvas.clientWidth || 1;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);\n      const alive: Particle[] = [];\n      for (const p of particles.current) {\n        p.life += dt;\n        if (p.life >= p.max) continue;\n        alive.push(p);\n        // Rings start one after another: a ring still waiting to start isn't drawn yet.\n        if (p.life < 0) continue;\n        const k = p.life / p.max;\n        const drag = p.kind === \"rings\" ? 0 : p.kind === \"confetti\" ? 2.2 : 3.4;\n        p.vx *= Math.exp(-drag * dt);\n        p.vy *= Math.exp(-drag * dt);\n        if (p.kind === \"confetti\" || p.kind === \"hearts\") p.vy += (p.kind === \"hearts\" ? -120 : 420) * dt;\n        p.x += p.vx * dt;\n        p.y += p.vy * dt;\n        p.rot += p.vr * dt;\n        ctx.save();\n        ctx.translate(p.x, p.y);\n        ctx.rotate(p.rot);\n        ctx.globalAlpha = p.kind === \"rings\" ? (1 - k) * 0.9 : Math.min(1, (1 - k) * 2.2);\n        ctx.fillStyle = p.color;\n        ctx.strokeStyle = p.color;\n        if (p.kind === \"sparks\") {\n          // A streak pointing along its velocity, shrinking as it slows.\n          const len = Math.hypot(p.vx, p.vy) * 0.045 + 2;\n          ctx.rotate(Math.atan2(p.vy, p.vx) - p.rot);\n          ctx.lineCap = \"round\";\n          ctx.lineWidth = p.size * (1 - k * 0.6);\n          ctx.beginPath();\n          ctx.moveTo(-len, 0);\n          ctx.lineTo(0, 0);\n          ctx.stroke();\n        } else if (p.kind === \"confetti\") {\n          const flip = Math.abs(Math.cos(p.rot * 1.7));\n          ctx.fillRect(-p.size / 2, (-p.size / 2) * 0.6 * flip, p.size, p.size * 0.6 * flip + 0.5);\n        } else if (p.kind === \"hearts\") {\n          heart(ctx, p.size * (0.6 + 0.4 * Math.sin(Math.min(1, k * 3) * Math.PI * 0.5)));\n        } else if (p.kind === \"stars\") {\n          star(ctx, p.size * (1 - k * 0.5));\n        } else {\n          ctx.lineWidth = 2 * (1 - k) + 0.5;\n          ctx.beginPath();\n          ctx.arc(0, 0, p.size + k * spread * 0.9, 0, Math.PI * 2);\n          ctx.stroke();\n        }\n        ctx.restore();\n      }\n      particles.current = alive;\n      if (alive.length) raf.current = requestAnimationFrame(tick);\n      else ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);\n    };\n    raf.current = requestAnimationFrame(tick);\n  };\n\n  const burst = (x: number, y: number) => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    const dpr = Math.min(window.devicePixelRatio || 1, 2);\n    const w = Math.round(canvas.clientWidth * dpr);\n    const h = Math.round(canvas.clientHeight * dpr);\n    if (canvas.width !== w || canvas.height !== h) {\n      canvas.width = w;\n      canvas.height = h;\n    }\n    const n = shape === \"rings\" ? 3 : count;\n    for (let i = 0; i < n; i++) {\n      const a = (i / n) * Math.PI * 2 + Math.random() * 0.5;\n      const speed = shape === \"rings\" ? 0 : spread * (2.6 + Math.random() * 2.2);\n      particles.current.push({\n        x: x + PAD,\n        y: y + PAD,\n        vx: Math.cos(a) * speed,\n        vy: Math.sin(a) * speed - (shape === \"confetti\" ? spread * 2.2 : 0),\n        rot: Math.random() * Math.PI * 2,\n        vr: (Math.random() - 0.5) * 14,\n        size: shape === \"sparks\" ? 2.4 : shape === \"rings\" ? 4 + i * 6 : shape === \"confetti\" ? 9 : shape === \"hearts\" ? 8 + Math.random() * 6 : 6 + Math.random() * 4,\n        life: shape === \"rings\" ? -i * 0.08 : 0,\n        max: shape === \"rings\" ? 0.75 : shape === \"confetti\" ? 1.4 + Math.random() * 0.4 : 0.7 + Math.random() * 0.35,\n        color: colors[i % colors.length],\n        kind: shape,\n      });\n    }\n    loop();\n  };\n\n  return (\n    <span\n      ref={rootRef}\n      className={cn(\"relative inline-flex\", className)}\n      onClick={(event) => {\n        onClick?.(event);\n        if (disabled || reduce || event.defaultPrevented) return;\n        const r = event.currentTarget.getBoundingClientRect();\n        // detail === 0 means a keyboard click: burst from the middle.\n        const centre = fromCenter || event.detail === 0;\n        burst(centre ? r.width / 2 : event.clientX - r.left, centre ? r.height / 2 : event.clientY - r.top);\n      }}\n      {...props}\n    >\n      {children}\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute z-50\" style={{ inset: -PAD, width: `calc(100% + ${PAD * 2}px)`, height: `calc(100% + ${PAD * 2}px)` }} />\n    </span>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}