{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "click-burst",
  "type": "registry:component",
  "title": "Click Burst",
  "description": "Fine rays that burst out where you click: they travel outward, detach from their origin and leave a ring and tiny sparks.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cursors"
  ],
  "docs": "Installed in components/furin/click-burst/. Docs, live controls and props table: https://furin.dev/components/click-burst/",
  "files": [
    {
      "path": "registry/click-burst/ClickBurst.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport \"./ClickBurst.css\";\n\nexport interface ClickBurstProps {\n  /** Color de los rayos. */\n  color?: string;\n  /** Cuántos rayos salen en cada ráfaga. */\n  rays?: number;\n  /** Alcance de los rayos, en px. */\n  radius?: number;\n  /** Duración de cada ráfaga, en milisegundos. */\n  duration?: number;\n  /** Grosor de los rayos, en px. */\n  thickness?: number;\n  /** Dibuja el anillo y el destello central. */\n  ring?: boolean;\n  /** Estalla en toda la ventana en vez de solo en el contenedor. */\n  global?: boolean;\n  /** Estalla solo, en puntos al azar, cuando nadie hace clic. */\n  autoplay?: boolean;\n  /** Texto de pista que se muestra cuando no hay children. */\n  hint?: string;\n  /** Contenido que queda debajo de las ráfagas. */\n  children?: ReactNode;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nlet colorCtx: CanvasRenderingContext2D | null = null;\nfunction toRgb(color: string): [number, number, number] {\n  if (typeof document === \"undefined\") return [142, 162, 255];\n  colorCtx ??= document.createElement(\"canvas\").getContext(\"2d\", { willReadFrequently: true })!;\n  colorCtx.clearRect(0, 0, 1, 1);\n  colorCtx.fillStyle = \"#000\";\n  colorCtx.fillStyle = color;\n  colorCtx.fillRect(0, 0, 1, 1);\n  const d = colorCtx.getImageData(0, 0, 1, 1).data;\n  return [d[0], d[1], d[2]];\n}\n\ninterface Ray { a: number; len: number; w: number; delay: number; tint: number }\ninterface Burst { x: number; y: number; t0: number; rays: Ray[]; dots: { a: number; d: number; r: number; delay: number }[]; spin: number }\n\nconst easeOut = (t: number) => 1 - Math.pow(1 - t, 3);\nconst easeOutExpo = (t: number) => (t >= 1 ? 1 : 1 - Math.pow(2, -10 * t));\nconst easeInOut = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);\n\n/** Ráfaga al clic: rayos finos que viajan hacia afuera y se despegan de su origen, con anillo y destello. */\nexport function ClickBurst({\n  color = \"#8EA2FF\",\n  rays = 12,\n  radius = 64,\n  duration = 720,\n  thickness = 2.4,\n  ring = true,\n  global = false,\n  autoplay = false,\n  hint = \"Click anywhere\",\n  children,\n  className = \"\",\n  style,\n}: ClickBurstProps) {\n  const host = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [activo, setActivo] = useState(true);\n  const live = useRef({ color, rays, radius, duration, thickness, ring, autoplay });\n  live.current = { color, rays, radius, duration, thickness, ring, autoplay };\n\n  useEffect(() => {\n    const el = host.current;\n    const cv = canvas.current;\n    if (!el || !cv) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) { setActivo(false); return; }\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    let W = 1, H = 1, dpr = 1, raf = 0, visible = true, lastReal = -1e9, nextAuto = 0, inside = false;\n    const bursts: Burst[] = [];\n    let colKey = live.current.color;\n    let col = toRgb(colKey);\n\n    const resize = () => {\n      dpr = Math.min(window.devicePixelRatio || 1, 2);\n      const r = global ? { width: window.innerWidth, height: window.innerHeight } : el.getBoundingClientRect();\n      W = Math.max(1, r.width);\n      H = Math.max(1, r.height);\n      cv.width = Math.round(W * dpr);\n      cv.height = Math.round(H * dpr);\n    };\n\n    const spawn = (x: number, y: number, now: number) => {\n      const n = Math.max(3, Math.round(live.current.rays));\n      const off = Math.random() * Math.PI;\n      const list: Ray[] = [];\n      for (let i = 0; i < n; i++) {\n        const long = i % 2 === 0;\n        list.push({\n          a: off + (i / n) * Math.PI * 2 + (Math.random() - 0.5) * 0.12,\n          len: live.current.radius * (long ? 0.92 + Math.random() * 0.2 : 0.55 + Math.random() * 0.15),\n          w: live.current.thickness * (long ? 1 : 0.75),\n          delay: Math.random() * 0.06,\n          tint: long ? 0 : 1,\n        });\n      }\n      const dots = Array.from({ length: Math.max(4, Math.round(n / 2)) }, () => ({ a: Math.random() * 6.283, d: 0.85 + Math.random() * 0.5, r: 1 + Math.random() * 1.2, delay: Math.random() * 0.1 }));\n      bursts.push({ x, y, t0: now, rays: list, dots, spin: (Math.random() - 0.5) * 0.35 });\n      if (bursts.length > 24) bursts.shift();\n    };\n\n    const draw = (now: number) => {\n      if (colKey !== live.current.color) { colKey = live.current.color; col = toRgb(colKey); }\n      const D = Math.max(200, live.current.duration);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, W, H);\n      ctx.globalCompositeOperation = \"lighter\";\n      ctx.lineCap = \"round\";\n      const R = live.current.radius;\n      const light = `${Math.round(col[0] + (255 - col[0]) * 0.65)},${Math.round(col[1] + (255 - col[1]) * 0.65)},${Math.round(col[2] + (255 - col[2]) * 0.65)}`;\n      const base = `${col[0]},${col[1]},${col[2]}`;\n      for (let i = bursts.length - 1; i >= 0; i--) {\n        const b = bursts[i];\n        const t = Math.max(0, (now - b.t0) / D);\n        if (t >= 1) { bursts.splice(i, 1); continue; }\n        if (live.current.ring) {\n          // Destello central: una luz breve que se encoge.\n          if (t < 0.3) {\n            const f = 1 - t / 0.3;\n            const g = ctx.createRadialGradient(b.x, b.y, 0, b.x, b.y, R * 0.55);\n            g.addColorStop(0, `rgba(${light},${0.8 * f})`);\n            g.addColorStop(0.4, `rgba(${base},${0.3 * f})`);\n            g.addColorStop(1, `rgba(${base},0)`);\n            ctx.fillStyle = g;\n            ctx.beginPath();\n            ctx.arc(b.x, b.y, R * 0.55, 0, 6.2832);\n            ctx.fill();\n          }\n          // Anillo que se expande y se afina.\n          const rr = R * 0.78 * easeOutExpo(Math.min(1, t * 1.4));\n          ctx.beginPath();\n          ctx.arc(b.x, b.y, rr, 0, 6.2832);\n          ctx.strokeStyle = `rgba(${light},${0.8 * Math.pow(1 - t, 1.6)})`;\n          ctx.lineWidth = Math.max(0.5, 2 * (1 - t));\n          ctx.stroke();\n        }\n        // Rayos: la punta sale rápido y la cola la alcanza, así el rayo viaja y se despega del origen.\n        for (const ry of b.rays) {\n          const tt = Math.min(1, Math.max(0, (t - ry.delay) / (1 - ry.delay)));\n          const head = ry.len * easeOut(Math.min(1, tt / 0.62));\n          const tail = ry.len * 0.96 * easeInOut(Math.min(1, Math.max(0, (tt - 0.18) / 0.82)));\n          if (head - tail < 0.5) continue;\n          const a = ry.a + b.spin * tt;\n          const ca = Math.cos(a), sa = Math.sin(a);\n          const x0 = b.x + ca * (R * 0.16 + tail), y0 = b.y + sa * (R * 0.16 + tail);\n          const x1 = b.x + ca * (R * 0.16 + head), y1 = b.y + sa * (R * 0.16 + head);\n          const alpha = Math.pow(1 - tt, 0.55);\n          const grad = ctx.createLinearGradient(x0, y0, x1, y1);\n          const c = ry.tint ? base : light;\n          grad.addColorStop(0, `rgba(${base},0)`);\n          grad.addColorStop(0.55, `rgba(${base},${alpha * 0.7})`);\n          grad.addColorStop(1, `rgba(${c},${alpha})`);\n          ctx.strokeStyle = grad;\n          ctx.lineWidth = ry.w * (1 - tt * 0.4);\n          ctx.beginPath();\n          ctx.moveTo(x0, y0);\n          ctx.lineTo(x1, y1);\n          ctx.stroke();\n        }\n        // Chispitas que siguen de largo, más lejos que los rayos.\n        for (const d of b.dots) {\n          const tt = Math.min(1, Math.max(0, (t - d.delay) / (1 - d.delay)));\n          const dist = R * (0.3 + d.d * easeOut(tt));\n          ctx.beginPath();\n          ctx.arc(b.x + Math.cos(d.a) * dist, b.y + Math.sin(d.a) * dist, d.r * (1 - tt * 0.7), 0, 6.2832);\n          ctx.fillStyle = `rgba(${light},${0.8 * Math.pow(1 - tt, 1.4)})`;\n          ctx.fill();\n        }\n      }\n      ctx.globalCompositeOperation = \"source-over\";\n    };\n\n    const frame = (now: number) => {\n      raf = 0;\n      const auto = live.current.autoplay && (!inside || now - lastReal > 3000);\n      if (auto && now > nextAuto) {\n        spawn(W * (0.18 + Math.random() * 0.64), H * (0.2 + Math.random() * 0.6), now);\n        nextAuto = now + 1100 + Math.random() * 500;\n      }\n      draw(now);\n      if ((bursts.length || auto) && visible) raf = requestAnimationFrame(frame);\n      else if (!bursts.length) { ctx.setTransform(dpr, 0, 0, dpr, 0, 0); ctx.clearRect(0, 0, W, H); }\n    };\n    const wake = () => { if (raf || !visible) return; raf = requestAnimationFrame(frame); };\n\n    const target: EventTarget = global ? window : el;\n    const onDown = (e: Event) => {\n      const pe = e as PointerEvent;\n      if (pe.pointerType === \"touch\" || pe.button !== 0) return;\n      const r = global ? { left: 0, top: 0 } : el.getBoundingClientRect();\n      lastReal = performance.now();\n      spawn(pe.clientX - r.left, pe.clientY - r.top, performance.now());\n      wake();\n    };\n    const onEnter = () => { inside = true; };\n    const onMove = () => { inside = true; lastReal = Math.max(lastReal, performance.now() - 2400); };\n    const onLeave = () => { inside = false; wake(); };\n    target.addEventListener(\"pointerdown\", onDown);\n    el.addEventListener(\"pointerenter\", onEnter);\n    el.addEventListener(\"pointermove\", onMove);\n    el.addEventListener(\"pointerleave\", onLeave);\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) wake(); else if (raf) { cancelAnimationFrame(raf); raf = 0; } });\n    io.observe(el);\n    const ro = new ResizeObserver(resize);\n    ro.observe(el);\n    if (global) window.addEventListener(\"resize\", resize);\n    resize();\n    const poll = window.setInterval(wake, 700);\n    wake();\n    return () => {\n      cancelAnimationFrame(raf);\n      window.clearInterval(poll);\n      target.removeEventListener(\"pointerdown\", onDown);\n      el.removeEventListener(\"pointerenter\", onEnter);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n      if (global) window.removeEventListener(\"resize\", resize);\n      io.disconnect();\n      ro.disconnect();\n    };\n  }, [global]);\n\n  return (\n    <div ref={host} className={`furin-click-burst ${className}`} style={style}>\n      <div className=\"furin-click-burst__contenido\">\n        {children ?? <span className=\"furin-click-burst__pista\">{hint}</span>}\n      </div>\n      {activo ? <canvas ref={canvas} aria-hidden=\"true\" className={`furin-click-burst__canvas${global ? \" furin-click-burst__canvas--global\" : \"\"}`} /> : null}\n    </div>\n  );\n}\n\nexport default ClickBurst;\n",
      "type": "registry:component",
      "target": "components/furin/click-burst/ClickBurst.tsx"
    },
    {
      "path": "registry/click-burst/ClickBurst.css",
      "content": ".furin-click-burst {\n  position: relative;\n  width: 100%;\n  height: 100%;\n  min-height: 200px;\n  overflow: hidden;\n  touch-action: pan-y;\n  font-family: Geist, system-ui, -apple-system, sans-serif;\n  color: rgba(255, 255, 255, 0.5);\n  user-select: none;\n}\n.furin-click-burst__contenido { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }\n.furin-click-burst__pista {\n  font: 500 12px/1 \"JetBrains Mono\", ui-monospace, \"SF Mono\", Menlo, monospace;\n  letter-spacing: 0.14em;\n  text-transform: uppercase;\n  color: rgba(255, 255, 255, 0.34);\n}\n.furin-click-burst__canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; z-index: 2; }\n.furin-click-burst__canvas--global { position: fixed; z-index: 2147483000; }\n",
      "type": "registry:file",
      "target": "components/furin/click-burst/ClickBurst.css"
    }
  ]
}
