{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-spring-press",
  "type": "registry:component",
  "title": "Button Spring Press",
  "description": "A keycap button driven by a real spring: it squashes into its base while pressed, sinks deeper the longer you hold, and rebounds past rest with a wobble on release. Works with pointer, Space and Enter.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "spring",
    "physics",
    "keycap",
    "press",
    "shortcut"
  ],
  "docs": "https://hyperblur.dev/effects/button-spring-press",
  "files": [
    {
      "path": "registry/hyperblur/button-spring-press.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-spring-press.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonSpringPressProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onClick\" | \"children\"> {\n  children?: React.ReactNode;\n  shortcut?: string;\n  variant?: \"accent\" | \"dark\" | \"light\";\n  accent?: string;\n  depth?: number;\n  stiffness?: number;\n  damping?: number;\n  chargeTime?: number;\n  onPress?: (strength: number) => void;\n}\n\nconst css = `\n.hb-xb3 {\n  --hb-xb3-c: #2f7bff;\n  --hb-xb3-face: linear-gradient(180deg, color-mix(in srgb, var(--hb-xb3-c) 82%, #fff) 0%, var(--hb-xb3-c) 45%, color-mix(in srgb, var(--hb-xb3-c) 86%, #000) 100%);\n  --hb-xb3-base: color-mix(in srgb, var(--hb-xb3-c) 45%, #000);\n  --hb-xb3-fg: #ffffff;\n  --hb-xb3-d: 6px;\n  position: relative;\n  display: inline-flex;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 0 0 var(--hb-xb3-d);\n  border: 0;\n  background: none;\n  font: inherit;\n  color: var(--hb-xb3-fg);\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: manipulation;\n  border-radius: 14px;\n}\n.hb-xb3 *, .hb-xb3 *::before, .hb-xb3 *::after { box-sizing: border-box; }\n.hb-xb3[data-variant=\"dark\"] {\n  --hb-xb3-face: linear-gradient(180deg, #2c2c2c 0%, #1e1e1e 50%, #171717 100%);\n  --hb-xb3-base: #050505;\n  --hb-xb3-fg: #ededed;\n}\n.hb-xb3[data-variant=\"light\"] {\n  --hb-xb3-face: linear-gradient(180deg, #ffffff 0%, #f1f1f1 55%, #e2e2e2 100%);\n  --hb-xb3-base: #9a9a9a;\n  --hb-xb3-fg: #111111;\n}\n.hb-xb3-base {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  top: var(--hb-xb3-d);\n  border-radius: 14px;\n  background: var(--hb-xb3-base);\n  box-shadow: 0 10px 24px -10px rgba(0, 0, 0, 0.9), 0 2px 0 rgba(0, 0, 0, 0.35), inset 0 -1px 0 rgba(255, 255, 255, 0.06);\n}\n.hb-xb3-glow {\n  position: absolute;\n  inset: auto 10% -10px;\n  height: 18px;\n  border-radius: 50%;\n  background: var(--hb-xb3-c);\n  filter: blur(14px);\n  opacity: calc(var(--hb-xb3-q, 0) * 0.85);\n  pointer-events: none;\n}\n.hb-xb3-face {\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: 12px;\n  padding: 13px 16px 13px 20px;\n  border-radius: 14px;\n  background: var(--hb-xb3-face);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -1px 0 rgba(0, 0, 0, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.05);\n  transform-origin: 50% 100%;\n  transform: translateY(var(--hb-xb3-y, 0px)) scale(var(--hb-xb3-sx, 1), var(--hb-xb3-sy, 1));\n  will-change: transform;\n}\n.hb-xb3[data-variant=\"dark\"] .hb-xb3-face { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 0 0 1px #2e2e2e; }\n.hb-xb3-face::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: radial-gradient(80% 120% at 50% 120%, rgba(255, 255, 255, 0.35), transparent 60%);\n  opacity: var(--hb-xb3-q, 0);\n  pointer-events: none;\n}\n.hb-xb3-label { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }\n.hb-xb3-keys { display: inline-flex; gap: 3px; }\n.hb-xb3-key {\n  min-width: 22px;\n  height: 22px;\n  padding: 0 5px;\n  display: inline-grid;\n  place-items: center;\n  border-radius: 6px;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 11px;\n  font-weight: 500;\n  background: rgba(0, 0, 0, 0.18);\n  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25), inset 0 0 0 1px rgba(255, 255, 255, 0.14);\n}\n.hb-xb3[data-variant=\"light\"] .hb-xb3-key { background: rgba(0, 0, 0, 0.06); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.12), inset 0 0 0 1px rgba(0, 0, 0, 0.08); }\n.hb-xb3-meter { position: absolute; left: 14px; right: 14px; bottom: 5px; height: 2px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); overflow: hidden; opacity: calc(var(--hb-xb3-q, 0) * 4); }\n.hb-xb3-meter::before { content: \"\"; position: absolute; inset: 0; transform-origin: 0 50%; transform: scaleX(var(--hb-xb3-q, 0)); background: currentColor; }\n.hb-xb3:focus-visible { outline: none; }\n.hb-xb3:focus-visible .hb-xb3-face { outline: 2px solid var(--hb-xb3-c); outline-offset: 4px; }\n.hb-xb3[data-variant=\"accent\"]:focus-visible .hb-xb3-face { outline-color: #ffffff; }\n.hb-xb3:disabled { cursor: not-allowed; opacity: 0.45; }\n`;\n\nfunction reduced() {\n  return typeof window !== \"undefined\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\nexport function ButtonSpringPress({\n  children = \"Deploy\",\n  shortcut = \"⌘ ↵\",\n  variant = \"accent\",\n  accent = \"#2f7bff\",\n  depth = 6,\n  stiffness = 520,\n  damping = 16,\n  chargeTime = 700,\n  onPress,\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  ...rest\n}: ButtonSpringPressProps) {\n  const ref = React.useRef<HTMLButtonElement>(null);\n  const sim = React.useRef({ x: 0, v: 0, target: 0, raf: 0, last: 0, down: 0, charge: 0 });\n  const onPressRef = React.useRef(onPress);\n\n  React.useEffect(() => {\n    onPressRef.current = onPress;\n  });\n\n  const paint = React.useCallback(\n    (x: number, q: number) => {\n      const el = ref.current;\n      if (!el) return;\n      const y = Math.max(-0.35, x) * depth;\n      const sx = 1 + x * 0.035;\n      const sy = 1 - x * 0.05;\n      el.style.setProperty(\"--hb-xb3-y\", `${y.toFixed(2)}px`);\n      el.style.setProperty(\"--hb-xb3-sx\", sx.toFixed(4));\n      el.style.setProperty(\"--hb-xb3-sy\", sy.toFixed(4));\n      el.style.setProperty(\"--hb-xb3-q\", q.toFixed(3));\n    },\n    [depth],\n  );\n\n  const kick = () => {\n    const sm = sim.current;\n    if (sm.raf) return;\n    sm.last = 0;\n    function loop(now: number) {\n      const s = sim.current;\n      const dt = Math.min(0.032, s.last ? (now - s.last) / 1000 : 0.016);\n      s.last = now;\n      if (s.down) s.charge = Math.min(1, (now - s.down) / chargeTime);\n      const target = s.target * (1 + s.charge * 0.25);\n      const a = -stiffness * (s.x - target) - damping * s.v;\n      s.v += a * dt;\n      s.x += s.v * dt;\n      paint(s.x, s.down ? s.charge : Math.max(0, s.charge * Math.min(1, s.x * 1.5)));\n      if (!s.down && Math.abs(s.x) < 0.001 && Math.abs(s.v) < 0.01) {\n        s.x = 0;\n        s.v = 0;\n        s.charge = 0;\n        paint(0, 0);\n        s.raf = 0;\n        return;\n      }\n      s.raf = requestAnimationFrame(loop);\n    }\n    sm.raf = requestAnimationFrame(loop);\n  };\n\n  React.useEffect(() => {\n    const s = sim.current;\n    return () => cancelAnimationFrame(s.raf);\n  }, []);\n\n  const press = () => {\n    if (disabled) return;\n    const s = sim.current;\n    if (s.down) return;\n    s.down = performance.now();\n    s.charge = 0;\n    s.target = 1;\n    if (reduced()) {\n      paint(1, 0);\n      return;\n    }\n    kick();\n  };\n\n  const release = (fire: boolean) => {\n    const s = sim.current;\n    if (!s.down) return;\n    const strength = Math.min(1, (performance.now() - s.down) / chargeTime);\n    s.down = 0;\n    s.target = 0;\n    if (reduced()) {\n      s.charge = 0;\n      paint(0, 0);\n    } else {\n      s.v -= 6 + strength * 10;\n      kick();\n    }\n    if (fire) onPressRef.current?.(strength);\n  };\n\n  const keys = shortcut ? shortcut.split(\" \").filter(Boolean) : [];\n\n  return (\n    <button\n      ref={ref}\n      type={type}\n      disabled={disabled}\n      className={`hb-xb3 ${className}`.trim()}\n      data-variant={variant}\n      style={{ \"--hb-xb3-c\": accent, \"--hb-xb3-d\": `${depth}px`, ...style } as React.CSSProperties}\n      onPointerDown={(e) => {\n        if (e.button !== 0) return;\n        e.currentTarget.setPointerCapture(e.pointerId);\n        press();\n      }}\n      onPointerUp={(e) => {\n        const r = e.currentTarget.getBoundingClientRect();\n        const inside = e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;\n        release(inside);\n      }}\n      onPointerCancel={() => release(false)}\n      onKeyDown={(e) => {\n        if (e.key === \" \" || e.key === \"Enter\") {\n          e.preventDefault();\n          if (!e.repeat) press();\n        }\n      }}\n      onKeyUp={(e) => {\n        if (e.key === \" \" || e.key === \"Enter\") {\n          e.preventDefault();\n          release(true);\n        }\n      }}\n      onBlur={() => release(false)}\n      onClick={(e) => {\n        if (e.detail === 0 && !sim.current.down) {\n          press();\n          window.setTimeout(() => release(true), 90);\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-button-spring-press\" precedence=\"default\">{css}</style>\n      <span className=\"hb-xb3-glow\" aria-hidden=\"true\" />\n      <span className=\"hb-xb3-base\" aria-hidden=\"true\" />\n      <span className=\"hb-xb3-face\">\n        <span className=\"hb-xb3-label\">{children}</span>\n        {keys.length > 0 && (\n          <span className=\"hb-xb3-keys\" aria-hidden=\"true\">\n            {keys.map((k, i) => (\n              <kbd key={i} className=\"hb-xb3-key\">{k}</kbd>\n            ))}\n          </span>\n        )}\n        <span className=\"hb-xb3-meter\" aria-hidden=\"true\" />\n      </span>\n    </button>\n  );\n}\n"
    }
  ]
}