{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-equalizer",
  "type": "registry:component",
  "title": "Button Equalizer",
  "description": "A play preview button whose waveform bars come alive while playing, with an elapsed timer and a progress hairline along the bottom. The play icon spins into pause and the bars already played stay lit.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "audio",
    "equalizer",
    "play",
    "waveform",
    "toggle"
  ],
  "docs": "https://hyperblur.dev/effects/button-equalizer",
  "files": [
    {
      "path": "registry/hyperblur/button-equalizer.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-equalizer.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonEqualizerProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\" | \"onChange\"> {\n  playing?: boolean;\n  defaultPlaying?: boolean;\n  onPlayingChange?: (playing: boolean) => void;\n  duration?: number;\n  bars?: number;\n  accent?: string;\n  caption?: string;\n}\n\nconst css = `\n.hb-xa4 {\n  --hb-xa4-c: #ff7a45;\n  --hb-xa4-p: 0;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.8em;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 0.45em 1em 0.45em 0.45em;\n  font: inherit;\n  font-size: 14px;\n  line-height: 1.15;\n  color: #ededed;\n  text-align: left;\n  background: linear-gradient(180deg, #181818, #111);\n  border: 0;\n  border-radius: 999px;\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 0 0 1px #262626, 0 10px 28px -16px rgba(0, 0, 0, 0.9);\n  cursor: pointer;\n  overflow: hidden;\n  isolation: isolate;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  transition: box-shadow 0.3s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-xa4 *, .hb-xa4 *::before, .hb-xa4 *::after { box-sizing: border-box; }\n.hb-xa4:hover:not(:disabled) { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px #333, 0 10px 28px -16px rgba(0, 0, 0, 0.9); }\n.hb-xa4[aria-pressed=\"true\"] { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px color-mix(in srgb, var(--hb-xa4-c) 38%, #262626), 0 12px 30px -16px color-mix(in srgb, var(--hb-xa4-c) 55%, transparent); }\n.hb-xa4:active:not(:disabled) { transform: scale(0.98); }\n.hb-xa4:focus-visible { outline: 2px solid var(--hb-xa4-c); outline-offset: 3px; }\n.hb-xa4:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-xa4-prog {\n  position: absolute;\n  left: 0;\n  bottom: 0;\n  height: 2px;\n  width: 100%;\n  z-index: -1;\n  background: var(--hb-xa4-c);\n  transform-origin: left;\n  transform: scaleX(var(--hb-xa4-p));\n  transition: transform 0.25s linear;\n  opacity: 0.9;\n}\n.hb-xa4-disc {\n  position: relative;\n  display: grid;\n  place-items: center;\n  width: 2.5em;\n  height: 2.5em;\n  flex: none;\n  color: #120700;\n  border-radius: 50%;\n  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--hb-xa4-c) 60%, #fff), var(--hb-xa4-c) 60%);\n  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.2), 0 4px 12px -4px color-mix(in srgb, var(--hb-xa4-c) 70%, transparent);\n}\n.hb-xa4-disc::after {\n  content: \"\";\n  position: absolute;\n  inset: -4px;\n  border-radius: 50%;\n  border: 1.5px solid var(--hb-xa4-c);\n  opacity: 0;\n  transform: scale(0.85);\n}\n.hb-xa4[aria-pressed=\"true\"] .hb-xa4-disc::after { animation: hb-xa4-ping 1.6s cubic-bezier(0.2, 0.6, 0.3, 1) infinite; }\n.hb-xa4-ico {\n  position: absolute;\n  width: 1em;\n  height: 1em;\n  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;\n}\n.hb-xa4-ico[data-k=\"pause\"] { opacity: 0; transform: scale(0.4) rotate(-90deg); }\n.hb-xa4[aria-pressed=\"true\"] .hb-xa4-ico[data-k=\"play\"] { opacity: 0; transform: scale(0.4) rotate(90deg); }\n.hb-xa4[aria-pressed=\"true\"] .hb-xa4-ico[data-k=\"pause\"] { opacity: 1; transform: none; }\n.hb-xa4-meta { display: flex; flex-direction: column; gap: 0.2em; min-width: 0; }\n.hb-xa4-title { font-weight: 600; white-space: nowrap; }\n.hb-xa4-time { font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.78em; color: #8f8f8f; font-variant-numeric: tabular-nums; white-space: nowrap; }\n.hb-xa4-eq {\n  display: flex;\n  align-items: center;\n  gap: 2px;\n  height: 1.9em;\n  margin-left: 0.2em;\n  flex: none;\n}\n.hb-xa4-bar {\n  width: 3px;\n  height: 100%;\n  border-radius: 2px;\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xa4-c) 55%, #fff), var(--hb-xa4-c));\n  transform: scaleY(var(--hb-xa4-h));\n  opacity: 0.4;\n  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;\n}\n.hb-xa4-bar[data-done=\"true\"] { opacity: 0.95; }\n.hb-xa4[aria-pressed=\"true\"] .hb-xa4-bar {\n  opacity: 1;\n  animation: hb-xa4-eq var(--hb-xa4-d) cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;\n  animation-delay: var(--hb-xa4-dl);\n}\n@keyframes hb-xa4-eq {\n  0% { transform: scaleY(0.14); }\n  40% { transform: scaleY(var(--hb-xa4-h)); }\n  100% { transform: scaleY(calc(var(--hb-xa4-h) * 0.45 + 0.1)); }\n}\n@keyframes hb-xa4-ping {\n  0% { opacity: 0.7; transform: scale(0.9); }\n  100% { opacity: 0; transform: scale(1.35); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-xa4, .hb-xa4-ico, .hb-xa4-bar, .hb-xa4-prog { transition: none; }\n  .hb-xa4[aria-pressed=\"true\"] .hb-xa4-bar, .hb-xa4[aria-pressed=\"true\"] .hb-xa4-disc::after { animation: none; }\n}\n`;\n\nfunction hash(n: number) {\n  let h = Math.imul(n + 17, 2654435761);\n  h = Math.imul(h ^ (h >>> 15), 2246822519);\n  h = Math.imul(h ^ (h >>> 13), 3266489917);\n  return ((h ^ (h >>> 16)) >>> 0) / 4294967295;\n}\n\nfunction clock(s: number) {\n  const t = Math.max(0, Math.floor(s));\n  return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, \"0\")}`;\n}\n\nexport function ButtonEqualizer({\n  playing,\n  defaultPlaying = false,\n  onPlayingChange,\n  duration = 30,\n  bars = 14,\n  accent = \"#ff7a45\",\n  caption,\n  children = \"Play preview\",\n  type = \"button\",\n  className = \"\",\n  style,\n  onClick,\n  ...rest\n}: ButtonEqualizerProps) {\n  const [inner, setInner] = React.useState(defaultPlaying);\n  const on = playing ?? inner;\n  const [elapsed, setElapsed] = React.useState(0);\n  const total = Math.max(1, duration);\n\n  const setOn = React.useCallback(\n    (next: boolean) => {\n      if (playing === undefined) setInner(next);\n      onPlayingChange?.(next);\n    },\n    [playing, onPlayingChange],\n  );\n\n  const live = React.useRef({ elapsed: 0, setOn });\n  React.useEffect(() => {\n    live.current.setOn = setOn;\n  }, [setOn]);\n\n  React.useEffect(() => {\n    if (!on) return;\n    const id = setInterval(() => {\n      const next = live.current.elapsed + 0.25;\n      if (next >= total) {\n        live.current.elapsed = 0;\n        setElapsed(0);\n        live.current.setOn(false);\n      } else {\n        live.current.elapsed = next;\n        setElapsed(next);\n      }\n    }, 250);\n    return () => clearInterval(id);\n  }, [on, total]);\n\n  const n = Math.max(4, Math.min(32, Math.round(bars)));\n  const frac = elapsed / total;\n  const vars = { \"--hb-xa4-c\": accent, \"--hb-xa4-p\": frac.toFixed(4), ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-button-equalizer\" precedence=\"default\">{css}</style>\n      <button\n        type={type}\n        className={`hb-xa4 ${className}`}\n        style={vars}\n        aria-pressed={on}\n        onClick={(e) => {\n          setOn(!on);\n          onClick?.(e);\n        }}\n        {...rest}\n      >\n        <span className=\"hb-xa4-prog\" aria-hidden=\"true\" />\n        <span className=\"hb-xa4-disc\" aria-hidden=\"true\">\n          <svg className=\"hb-xa4-ico\" data-k=\"play\" viewBox=\"0 0 16 16\">\n            <path d=\"M5 3.3v9.4a.6.6 0 0 0 .9.5l7.4-4.7a.6.6 0 0 0 0-1L5.9 2.8a.6.6 0 0 0-.9.5Z\" fill=\"currentColor\" />\n          </svg>\n          <svg className=\"hb-xa4-ico\" data-k=\"pause\" viewBox=\"0 0 16 16\">\n            <rect x=\"3.5\" y=\"3\" width=\"3.2\" height=\"10\" rx=\"1\" fill=\"currentColor\" />\n            <rect x=\"9.3\" y=\"3\" width=\"3.2\" height=\"10\" rx=\"1\" fill=\"currentColor\" />\n          </svg>\n        </span>\n        <span className=\"hb-xa4-meta\">\n          <span className=\"hb-xa4-title\">{on ? \"Pause preview\" : children}</span>\n          <span className=\"hb-xa4-time\">\n            {caption ? `${caption} · ` : \"\"}\n            {clock(elapsed)} / {clock(total)}\n          </span>\n        </span>\n        <span className=\"hb-xa4-eq\" aria-hidden=\"true\">\n          {Array.from({ length: n }, (_, i) => {\n            const shape = 0.35 + 0.65 * Math.sin(((i + 0.5) / n) * Math.PI);\n            const h = Math.min(1, 0.2 + shape * (0.45 + hash(i) * 0.55));\n            const v = {\n              \"--hb-xa4-h\": h.toFixed(3),\n              \"--hb-xa4-d\": `${(0.38 + hash(i + 50) * 0.5).toFixed(3)}s`,\n              \"--hb-xa4-dl\": `${(-hash(i + 99) * 0.8).toFixed(3)}s`,\n            } as React.CSSProperties;\n            return <span className=\"hb-xa4-bar\" style={v} data-done={i / n < frac || undefined} key={i} />;\n          })}\n        </span>\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}