{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-elastic-stretch",
  "type": "registry:component",
  "title": "Button Elastic Stretch",
  "description": "A glossy gummy button you can grab and pull: the body stretches toward the pointer with rubber-band resistance and wobbles back on a spring when released. It also leans slightly toward the cursor on hover.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "elastic",
    "spring",
    "physics",
    "drag",
    "gummy"
  ],
  "docs": "https://hyperblur.dev/effects/button-elastic-stretch",
  "files": [
    {
      "path": "registry/hyperblur/button-elastic-stretch.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-elastic-stretch.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonElasticStretchProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\"> {\n  accent?: string;\n  stretch?: number;\n  icon?: React.ReactNode;\n  size?: \"sm\" | \"md\" | \"lg\";\n}\n\nconst css = `\n.hb-xa2 {\n  --hb-xa2-c: #ff5c8a;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 0.95em 1.8em;\n  font: inherit;\n  font-size: 15px;\n  font-weight: 700;\n  line-height: 1;\n  letter-spacing: -0.01em;\n  color: #fff;\n  background: transparent;\n  border: 0;\n  border-radius: 999px;\n  cursor: grab;\n  isolation: isolate;\n  touch-action: none;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-xa2 *, .hb-xa2 *::before, .hb-xa2 *::after { box-sizing: border-box; }\n.hb-xa2[data-size=\"sm\"] { font-size: 13px; }\n.hb-xa2[data-size=\"lg\"] { font-size: 17px; }\n.hb-xa2[data-held=\"true\"] { cursor: grabbing; }\n.hb-xa2:focus-visible { outline: none; }\n.hb-xa2:focus-visible .hb-xa2-body { box-shadow: 0 0 0 2px #0a0a0a, 0 0 0 4px var(--hb-xa2-c), inset 0 2px 1px rgba(255, 255, 255, 0.45), inset 0 -6px 12px rgba(0, 0, 0, 0.22); }\n.hb-xa2:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-xa2-body {\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  border-radius: inherit;\n  background:\n    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--hb-xa2-c) 70%, #fff) 0%, transparent 60%),\n    linear-gradient(180deg, var(--hb-xa2-c), color-mix(in srgb, var(--hb-xa2-c) 72%, #3a0016));\n  box-shadow:\n    inset 0 2px 1px rgba(255, 255, 255, 0.45),\n    inset 0 -6px 12px rgba(0, 0, 0, 0.22),\n    0 14px 26px -12px color-mix(in srgb, var(--hb-xa2-c) 75%, transparent),\n    0 3px 6px -2px rgba(0, 0, 0, 0.5);\n  will-change: transform;\n}\n.hb-xa2-body::before {\n  content: \"\";\n  position: absolute;\n  left: 14%;\n  right: 14%;\n  top: 9%;\n  height: 34%;\n  border-radius: 999px;\n  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));\n  filter: blur(0.5px);\n}\n.hb-xa2-body::after {\n  content: \"\";\n  position: absolute;\n  right: 12%;\n  top: 22%;\n  width: 0.38em;\n  height: 0.38em;\n  border-radius: 50%;\n  background: rgba(255, 255, 255, 0.8);\n  filter: blur(0.4px);\n}\n.hb-xa2-label {\n  display: inline-flex;\n  align-items: center;\n  gap: 0.55em;\n  white-space: nowrap;\n  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);\n  will-change: transform;\n}\n.hb-xa2-label svg { width: 1.1em; height: 1.1em; flex: none; }\n`;\n\nfunction Bag() {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" aria-hidden=\"true\">\n      <path d=\"M4.5 7h11l-.8 9.2a1.5 1.5 0 0 1-1.5 1.3H6.8a1.5 1.5 0 0 1-1.5-1.3L4.5 7Z\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinejoin=\"round\" />\n      <path d=\"M7.5 9V6a2.5 2.5 0 0 1 5 0v3\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\nexport function ButtonElasticStretch({\n  children = \"Add to cart\",\n  accent = \"#ff5c8a\",\n  stretch = 1,\n  icon,\n  size = \"md\",\n  type = \"button\",\n  disabled = false,\n  className = \"\",\n  style,\n  onPointerDown,\n  onPointerMove,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  onKeyDown,\n  ...rest\n}: ButtonElasticStretchProps) {\n  const bodyRef = React.useRef<HTMLSpanElement>(null);\n  const labelRef = React.useRef<HTMLSpanElement>(null);\n  const [held, setHeld] = React.useState(false);\n  const sim = React.useRef({ x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0, held: false, sx: 0, sy: 0, raf: 0, reduce: false, k: 1, kick: () => {} });\n\n  React.useEffect(() => {\n    const s = sim.current;\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    s.reduce = mq.matches;\n    const onMq = () => {\n      s.reduce = mq.matches;\n    };\n    mq.addEventListener(\"change\", onMq);\n\n    function paint() {\n      const k = Math.max(0, s.k);\n      const ax = Math.abs(s.x);\n      const ay = Math.abs(s.y);\n      const scx = 1 + (ax * 0.0045 - ay * 0.0018) * k;\n      const scy = 1 + (ay * 0.006 - ax * 0.0022) * k;\n      if (bodyRef.current) {\n        bodyRef.current.style.transform = `translate(${(s.x * 0.5).toFixed(2)}px, ${(s.y * 0.5).toFixed(2)}px) scale(${scx.toFixed(4)}, ${scy.toFixed(4)})`;\n      }\n      if (labelRef.current) {\n        labelRef.current.style.transform = `translate(${(s.x * 0.62).toFixed(2)}px, ${(s.y * 0.62).toFixed(2)}px)`;\n      }\n    }\n\n    function tick() {\n      s.raf = 0;\n      const stiff = s.held ? 0.28 : 0.14;\n      const damp = s.held ? 0.62 : 0.8;\n      s.vx = (s.vx + (s.tx - s.x) * stiff) * damp;\n      s.vy = (s.vy + (s.ty - s.y) * stiff) * damp;\n      s.x += s.vx;\n      s.y += s.vy;\n      paint();\n      const moving = Math.abs(s.vx) + Math.abs(s.vy) + Math.abs(s.tx - s.x) + Math.abs(s.ty - s.y) > 0.02;\n      if (moving) s.raf = requestAnimationFrame(tick);\n      else {\n        s.x = s.tx;\n        s.y = s.ty;\n        paint();\n      }\n    }\n\n    s.kick = () => {\n      if (s.reduce) return;\n      if (!s.raf) s.raf = requestAnimationFrame(tick);\n    };\n\n    return () => {\n      cancelAnimationFrame(s.raf);\n      s.raf = 0;\n      s.kick = () => {};\n      mq.removeEventListener(\"change\", onMq);\n    };\n  }, []);\n\n  React.useEffect(() => {\n    sim.current.k = stretch;\n  }, [stretch]);\n\n  function kick() {\n    sim.current.kick();\n  }\n\n  function rubber(d: number, limit: number) {\n    return (d * limit) / (limit + Math.abs(d));\n  }\n\n  function aim(e: React.PointerEvent<HTMLButtonElement>) {\n    const s = sim.current;\n    const r = e.currentTarget.getBoundingClientRect();\n    if (s.held) {\n      s.tx = rubber(e.clientX - s.sx, 70);\n      s.ty = rubber(e.clientY - s.sy, 40);\n    } else {\n      s.tx = (e.clientX - (r.left + r.width / 2)) * 0.12;\n      s.ty = (e.clientY - (r.top + r.height / 2)) * 0.16;\n    }\n    kick();\n  }\n\n  function rest0() {\n    const s = sim.current;\n    s.tx = 0;\n    s.ty = 0;\n    kick();\n  }\n\n  function release() {\n    const s = sim.current;\n    if (!s.held) return;\n    s.held = false;\n    setHeld(false);\n    s.vx += -s.x * 0.18;\n    s.vy += -s.y * 0.18;\n    rest0();\n  }\n\n  const vars = { \"--hb-xa2-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-button-elastic-stretch\" precedence=\"default\">{css}</style>\n      <button\n        type={type}\n        className={`hb-xa2 ${className}`}\n        style={vars}\n        data-size={size}\n        data-held={held || undefined}\n        disabled={disabled}\n        onPointerDown={(e) => {\n          const s = sim.current;\n          s.held = true;\n          s.sx = e.clientX;\n          s.sy = e.clientY;\n          s.tx = 0;\n          s.ty = 4;\n          setHeld(true);\n          e.currentTarget.setPointerCapture?.(e.pointerId);\n          kick();\n          onPointerDown?.(e);\n        }}\n        onPointerMove={(e) => {\n          aim(e);\n          onPointerMove?.(e);\n        }}\n        onPointerUp={(e) => {\n          release();\n          onPointerUp?.(e);\n        }}\n        onPointerCancel={(e) => {\n          release();\n          onPointerCancel?.(e);\n        }}\n        onPointerLeave={(e) => {\n          if (!sim.current.held) rest0();\n          onPointerLeave?.(e);\n        }}\n        onKeyDown={(e) => {\n          if (e.key === \" \" || e.key === \"Enter\") {\n            const s = sim.current;\n            s.vx = 0;\n            s.vy = 9;\n            kick();\n          }\n          onKeyDown?.(e);\n        }}\n        {...rest}\n      >\n        <span ref={bodyRef} className=\"hb-xa2-body\" aria-hidden=\"true\" />\n        <span ref={labelRef} className=\"hb-xa2-label\">\n          {icon === undefined ? <Bag /> : icon}\n          {children}\n        </span>\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}