{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "confetti-button",
  "type": "registry:component",
  "title": "Confetti Button",
  "description": "Click and a burst of small rectangles and circles pops out and falls with gravity while the label swaps to a success message.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "confetti",
    "celebrate",
    "success",
    "click"
  ],
  "docs": "https://hyperblur.dev/effects/confetti-button",
  "files": [
    {
      "path": "registry/hyperblur/confetti-button.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/confetti-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ConfettiButtonProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\"> {\n  children: React.ReactNode;\n  colors?: string[];\n  count?: number;\n  successLabel?: string;\n  rounded?: number;\n  size?: \"sm\" | \"md\" | \"lg\";\n}\n\ninterface Piece {\n  x: number;\n  up: number;\n  fall: number;\n  rot: number;\n  w: number;\n  h: number;\n  dur: number;\n  delay: number;\n  color: string;\n  round: boolean;\n}\n\ninterface Burst {\n  id: number;\n  pieces: Piece[];\n}\n\nconst css = `\n.hb-cf {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  margin: 0;\n  padding: 0.8em 1.8em;\n  font-family: inherit;\n  font-size: 15px;\n  font-weight: 700;\n  line-height: 1.2;\n  color: #0a0c11;\n  background: #fff;\n  border: 0;\n  border-radius: var(--hb-r);\n  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25), 0 10px 28px -12px rgba(255, 255, 255, 0.4);\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;\n}\n.hb-cf[data-size=\"sm\"] { font-size: 13px; padding: 0.65em 1.45em; }\n.hb-cf[data-size=\"lg\"] { font-size: 17px; padding: 0.9em 2.1em; }\n.hb-cf:hover { transform: translateY(-1px); }\n.hb-cf:active { transform: scale(0.95); }\n.hb-cf:focus-visible { outline: 2px solid var(--hb-c); outline-offset: 3px; }\n.hb-cf:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }\n.hb-cf-l {\n  display: grid;\n  place-items: center;\n  overflow: clip;\n  padding-block: 0.1em;\n}\n.hb-cf-a, .hb-cf-b {\n  grid-area: 1 / 1;\n  white-space: nowrap;\n  transition: opacity 0.25s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-cf-b { opacity: 0; transform: translateY(70%); }\n.hb-cf[data-done=\"true\"] .hb-cf-a { opacity: 0; transform: translateY(-70%); }\n.hb-cf[data-done=\"true\"] .hb-cf-b { opacity: 1; transform: none; }\n.hb-cf-burst {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: 0;\n  height: 0;\n  z-index: 2;\n  pointer-events: none;\n}\n.hb-cf-p {\n  position: absolute;\n  left: 0;\n  top: 0;\n  animation: hb-cf-x var(--hb-t) cubic-bezier(0.08, 0.6, 0.3, 1) var(--hb-dl) both;\n}\n.hb-cf-p > i {\n  display: block;\n  width: var(--hb-w);\n  height: var(--hb-h);\n  margin: calc(var(--hb-h) / -2) 0 0 calc(var(--hb-w) / -2);\n  background: var(--hb-pc);\n  border-radius: var(--hb-br);\n  animation: hb-cf-y var(--hb-t) linear var(--hb-dl) both;\n}\n.hb-cf-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n@keyframes hb-cf-x {\n  to { transform: translateX(var(--hb-x)); }\n}\n@keyframes hb-cf-y {\n  0% { transform: translateY(0) rotate(0deg); opacity: 1; animation-timing-function: cubic-bezier(0.2, 0.7, 0.4, 1); }\n  38% { transform: translateY(var(--hb-up)) rotate(calc(var(--hb-r) * 0.4)); animation-timing-function: cubic-bezier(0.5, 0, 0.9, 0.6); }\n  82% { opacity: 1; }\n  100% { transform: translateY(var(--hb-fall)) rotate(var(--hb-r)); opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-cf, .hb-cf-a, .hb-cf-b { transition-duration: 0.01s; }\n  .hb-cf:hover, .hb-cf:active { transform: none; }\n}\n`;\n\nconst fallbackColors = [\"#ff4d6d\", \"#ffb703\", \"#2f7bff\", \"#19c3f5\", \"#7cf29a\"];\n\nfunction seeded(seed: number) {\n  let a = (seed * 2654435761) >>> 0;\n  return () => {\n    a = (a + 0x6d2b79f5) >>> 0;\n    let t = a;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n}\n\nfunction makePieces(seed: number, count: number, colors: string[]): Piece[] {\n  const rand = seeded(seed + 1);\n  const palette = colors.length ? colors : fallbackColors;\n  const pieces: Piece[] = [];\n  for (let i = 0; i < count; i++) {\n    const angle = -Math.PI / 2 + (rand() - 0.5) * Math.PI * 1.15;\n    const power = 70 + rand() * 90;\n    const round = rand() < 0.4;\n    const w = round ? 5 + rand() * 3 : 6 + rand() * 5;\n    pieces.push({\n      x: Math.cos(angle) * power,\n      up: Math.sin(angle) * power * 0.9,\n      fall: 70 + rand() * 90,\n      rot: (rand() - 0.5) * 1080,\n      w,\n      h: round ? w : 3 + rand() * 3,\n      dur: 0.9 + rand() * 0.5,\n      delay: rand() * 0.06,\n      color: palette[Math.floor(rand() * palette.length)],\n      round,\n    });\n  }\n  return pieces;\n}\n\nexport function ConfettiButton({\n  children,\n  colors = [\"#ff4d6d\", \"#ffb703\", \"#2f7bff\", \"#19c3f5\", \"#7cf29a\"],\n  count = 28,\n  successLabel = \"Done\",\n  rounded = 9999,\n  size = \"md\",\n  type = \"button\",\n  className = \"\",\n  style,\n  onClick,\n  ...rest\n}: ConfettiButtonProps) {\n  const counter = React.useRef(0);\n  const timers = React.useRef<number[]>([]);\n  const labelTimer = React.useRef(0);\n  const [bursts, setBursts] = React.useState<Burst[]>([]);\n  const [done, setDone] = React.useState(false);\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => {\n      list.forEach((t) => window.clearTimeout(t));\n      window.clearTimeout(labelTimer.current);\n    };\n  }, []);\n\n  function handleClick(e: React.MouseEvent<HTMLButtonElement>) {\n    onClick?.(e);\n    if (e.defaultPrevented) return;\n    const id = counter.current++;\n    const calm = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (!calm) {\n      const pieces = makePieces(id, Math.max(0, Math.min(160, Math.round(count))), colors);\n      setBursts((list) => [...list, { id, pieces }]);\n      timers.current.push(\n        window.setTimeout(() => {\n          setBursts((list) => list.filter((b) => b.id !== id));\n        }, 1700),\n      );\n    }\n    setDone(true);\n    window.clearTimeout(labelTimer.current);\n    labelTimer.current = window.setTimeout(() => setDone(false), 1800);\n  }\n\n  const vars = {\n    \"--hb-c\": colors[0] ?? \"#2f7bff\",\n    \"--hb-r\": `${rounded}px`,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-confetti-button\" precedence=\"default\">{css}</style>\n      <button\n        type={type}\n        className={`hb-cf ${className}`}\n        style={vars}\n        data-size={size}\n        data-done={done}\n        onClick={handleClick}\n        {...rest}\n      >\n        <span className=\"hb-cf-l\">\n          <span className=\"hb-cf-a\">{children}</span>\n          <span className=\"hb-cf-b\" aria-hidden=\"true\">{successLabel}</span>\n        </span>\n        {bursts.map((burst) => (\n          <span key={burst.id} className=\"hb-cf-burst\" aria-hidden=\"true\">\n            {burst.pieces.map((p, i) => (\n              <span\n                key={i}\n                className=\"hb-cf-p\"\n                style={\n                  {\n                    \"--hb-x\": `${p.x.toFixed(1)}px`,\n                    \"--hb-t\": `${p.dur.toFixed(2)}s`,\n                    \"--hb-dl\": `${p.delay.toFixed(3)}s`,\n                  } as React.CSSProperties\n                }\n              >\n                <i\n                  style={\n                    {\n                      \"--hb-up\": `${p.up.toFixed(1)}px`,\n                      \"--hb-fall\": `${p.fall.toFixed(1)}px`,\n                      \"--hb-r\": `${p.rot.toFixed(0)}deg`,\n                      \"--hb-w\": `${p.w.toFixed(1)}px`,\n                      \"--hb-h\": `${p.h.toFixed(1)}px`,\n                      \"--hb-pc\": p.color,\n                      \"--hb-br\": p.round ? \"50%\" : \"1px\",\n                    } as React.CSSProperties\n                  }\n                />\n              </span>\n            ))}\n          </span>\n        ))}\n      </button>\n      <span className=\"hb-cf-sr\" role=\"status\" aria-live=\"polite\">\n        {done ? successLabel : \"\"}\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}