{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-bubbles-pop",
  "type": "registry:component",
  "title": "Button Bubbles Pop",
  "description": "A button that squashes on press, rebounds and releases a handful of bubbles that float up and pop. The scatter is deterministic.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "bubbles",
    "particles",
    "squash",
    "press",
    "playful"
  ],
  "docs": "https://hyperblur.dev/effects/button-bubbles-pop",
  "files": [
    {
      "path": "registry/hyperblur/button-bubbles-pop.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-bubbles-pop.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonBubblesPopProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\"> {\n  variant?: \"solid\" | \"outline\" | \"ghost\";\n  accent?: string;\n  size?: \"sm\" | \"md\" | \"lg\";\n  count?: number;\n  idle?: boolean;\n  loading?: boolean;\n}\n\nfunction mix(n: number) {\n  let x = Math.imul(n + 0x6d2b79f5, 0x85ebca6b) >>> 0;\n  x ^= x >>> 15;\n  x = Math.imul(x, 0xc2b2ae35) >>> 0;\n  x ^= x >>> 13;\n  return (x >>> 0) / 4294967296;\n}\n\nconst css = `\n.hb-ya8 {\n  --hb-ya8-fs: 0.9375rem;\n  --hb-ya8-h: 2.75rem;\n  position: relative;\n  display: inline-block;\n  box-sizing: border-box;\n}\n.hb-ya8 *, .hb-ya8 *::before, .hb-ya8 *::after { box-sizing: border-box; }\n.hb-ya8[data-size=\"sm\"] { --hb-ya8-fs: 0.8125rem; --hb-ya8-h: 2.25rem; }\n.hb-ya8[data-size=\"lg\"] { --hb-ya8-fs: 1.0625rem; --hb-ya8-h: 3.25rem; }\n.hb-ya8-btn {\n  position: relative;\n  z-index: 1;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  gap: 0.6em;\n  height: var(--hb-ya8-h);\n  margin: 0;\n  padding: 0 1.5em;\n  font: inherit;\n  font-size: var(--hb-ya8-fs);\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  border: 1px solid transparent;\n  border-radius: 999px;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  transform-origin: 50% 100%;\n  transition: transform 0.16s cubic-bezier(0.3, 1.4, 0.5, 1), background-color 0.2s ease, border-color 0.2s ease, filter 0.2s ease;\n}\n.hb-ya8[data-variant=\"solid\"] .hb-ya8-btn { color: #fff; background: var(--hb-ya8-c); }\n.hb-ya8[data-variant=\"outline\"] .hb-ya8-btn {\n  color: #ededed;\n  background: transparent;\n  border-color: color-mix(in srgb, var(--hb-ya8-c) 55%, #262626);\n}\n.hb-ya8[data-variant=\"ghost\"] .hb-ya8-btn {\n  color: color-mix(in srgb, var(--hb-ya8-c) 70%, #fff);\n  background: color-mix(in srgb, var(--hb-ya8-c) 12%, transparent);\n}\n.hb-ya8[data-variant=\"solid\"] .hb-ya8-btn:not(:disabled):hover { filter: brightness(1.1); }\n.hb-ya8[data-variant=\"outline\"] .hb-ya8-btn:not(:disabled):hover { background: color-mix(in srgb, var(--hb-ya8-c) 9%, transparent); }\n.hb-ya8[data-variant=\"ghost\"] .hb-ya8-btn:not(:disabled):hover { background: color-mix(in srgb, var(--hb-ya8-c) 20%, transparent); }\n.hb-ya8-btn:not(:disabled):active { transform: scale(1.07, 0.88); }\n.hb-ya8-btn[data-sq=\"a\"] { animation: hb-ya8-rebound-a 0.6s cubic-bezier(0.3, 0.9, 0.3, 1); }\n.hb-ya8-btn[data-sq=\"b\"] { animation: hb-ya8-rebound-b 0.6s cubic-bezier(0.3, 0.9, 0.3, 1); }\n.hb-ya8-btn:focus-visible { outline: 2px solid var(--hb-ya8-c); outline-offset: 3px; }\n.hb-ya8-btn:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-ya8-btn[aria-busy=\"true\"] { cursor: progress; }\n.hb-ya8-field {\n  position: absolute;\n  left: 0;\n  right: 0;\n  top: 0;\n  height: 0;\n  z-index: 2;\n  pointer-events: none;\n}\n.hb-ya8-bubble {\n  position: absolute;\n  top: 0;\n  width: var(--hb-ya8-s);\n  height: var(--hb-ya8-s);\n  margin: calc(var(--hb-ya8-s) / -2) 0 0 calc(var(--hb-ya8-s) / -2);\n  border: 1px solid color-mix(in srgb, var(--hb-ya8-c) 65%, #fff);\n  border-radius: 50%;\n  background:\n    radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.85) 0, rgba(255, 255, 255, 0) 24%),\n    radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--hb-ya8-c) 10%, transparent) 40%, color-mix(in srgb, var(--hb-ya8-c) 38%, transparent) 100%);\n  opacity: 0;\n  animation: hb-ya8-rise var(--hb-ya8-d) cubic-bezier(0.2, 0.6, 0.3, 1) var(--hb-ya8-w) both;\n}\n.hb-ya8-spin {\n  width: 1em;\n  height: 1em;\n  border: 2px solid currentColor;\n  border-right-color: transparent;\n  border-radius: 50%;\n  animation: hb-ya8-turn 0.7s linear infinite;\n}\n@keyframes hb-ya8-rise {\n  0% { opacity: 0; transform: translate(0, 4px) scale(0.35); }\n  14% { opacity: 1; transform: translate(0, -6px) scale(1); }\n  78% { opacity: 0.9; }\n  100% { opacity: 0; transform: translate(var(--hb-ya8-x), calc(var(--hb-ya8-r) * -1)) scale(1.3); }\n}\n@keyframes hb-ya8-rebound-a {\n  0% { transform: scale(1.1, 0.86); }\n  34% { transform: scale(0.94, 1.1); }\n  64% { transform: scale(1.03, 0.97); }\n  100% { transform: scale(1); }\n}\n@keyframes hb-ya8-rebound-b {\n  0% { transform: scale(1.1, 0.86); }\n  34% { transform: scale(0.94, 1.1); }\n  64% { transform: scale(1.03, 0.97); }\n  100% { transform: scale(1); }\n}\n@keyframes hb-ya8-turn {\n  to { transform: rotate(360deg); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ya8-btn { transition: none; }\n  .hb-ya8-btn:not(:disabled):active { transform: none; }\n  .hb-ya8-btn[data-sq] { animation: none; }\n  .hb-ya8-field { display: none; }\n  .hb-ya8-spin { animation-duration: 2s; }\n}\n`;\n\nexport function ButtonBubblesPop({\n  variant = \"solid\",\n  accent = \"#2f7bff\",\n  size = \"md\",\n  count = 9,\n  idle = false,\n  loading = false,\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  children,\n  onClick,\n  onPointerEnter,\n  onPointerLeave,\n  ...rest\n}: ButtonBubblesPopProps) {\n  const hovering = React.useRef(false);\n  const timer = React.useRef(0);\n  const [burst, setBurst] = React.useState(0);\n  const [live, setLive] = React.useState(false);\n  const blocked = disabled || loading;\n\n  const pop = React.useCallback(() => {\n    setBurst((n) => n + 1);\n    setLive(true);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => setLive(false), 1800);\n  }, []);\n\n  React.useEffect(() => {\n    return () => window.clearTimeout(timer.current);\n  }, []);\n\n  React.useEffect(() => {\n    if (!idle || blocked) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const id = window.setInterval(() => {\n      if (!hovering.current) pop();\n    }, 3200);\n    return () => window.clearInterval(id);\n  }, [idle, blocked, pop]);\n\n  const total = Math.max(0, Math.min(24, Math.round(count)));\n  const bubbles = live\n    ? Array.from({ length: total }, (_, i) => {\n        const seed = burst * 131 + i * 17;\n        return {\n          key: `${burst}-${i}`,\n          left: 8 + mix(seed) * 84,\n          s: 6 + mix(seed + 1) * 12,\n          r: 54 + mix(seed + 2) * 62,\n          x: (mix(seed + 3) - 0.5) * 36,\n          w: mix(seed + 4) * 0.2,\n          d: 0.95 + mix(seed + 5) * 0.7,\n        };\n      })\n    : [];\n\n  const vars = { \"--hb-ya8-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-button-bubbles-pop\" precedence=\"default\">{css}</style>\n      <span className={`hb-ya8 ${className}`} style={vars} data-variant={variant} data-size={size}>\n        <button\n          type={type}\n          className=\"hb-ya8-btn\"\n          data-sq={burst === 0 ? undefined : burst % 2 === 0 ? \"a\" : \"b\"}\n          disabled={disabled}\n          aria-busy={loading || undefined}\n          onPointerEnter={(e) => {\n            hovering.current = true;\n            onPointerEnter?.(e);\n          }}\n          onPointerLeave={(e) => {\n            hovering.current = false;\n            onPointerLeave?.(e);\n          }}\n          onClick={(e) => {\n            if (loading) {\n              e.preventDefault();\n              return;\n            }\n            pop();\n            onClick?.(e);\n          }}\n          {...rest}\n        >\n          {loading ? <span className=\"hb-ya8-spin\" aria-hidden=\"true\" /> : null}\n          {children}\n        </button>\n        <span className=\"hb-ya8-field\" aria-hidden=\"true\">\n          {bubbles.map((b) => (\n            <span\n              key={b.key}\n              className=\"hb-ya8-bubble\"\n              style={\n                {\n                  left: `${b.left.toFixed(1)}%`,\n                  \"--hb-ya8-s\": `${b.s.toFixed(1)}px`,\n                  \"--hb-ya8-r\": `${b.r.toFixed(0)}px`,\n                  \"--hb-ya8-x\": `${b.x.toFixed(1)}px`,\n                  \"--hb-ya8-w\": `${b.w.toFixed(2)}s`,\n                  \"--hb-ya8-d\": `${b.d.toFixed(2)}s`,\n                } as React.CSSProperties\n              }\n            />\n          ))}\n        </span>\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}