{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-ink-ripple",
  "type": "registry:component",
  "title": "Button Ink Ripple",
  "description": "A button whose click ripple spreads from the exact pointer position and takes its ink color from the variant. Keyboard activation ripples from the center.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "ripple",
    "ink",
    "click",
    "material",
    "feedback"
  ],
  "docs": "https://hyperblur.dev/effects/button-ink-ripple",
  "files": [
    {
      "path": "registry/hyperblur/button-ink-ripple.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-ink-ripple.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonInkRippleProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\"> {\n  variant?: \"solid\" | \"outline\" | \"ghost\";\n  accent?: string;\n  size?: \"sm\" | \"md\" | \"lg\";\n  loading?: boolean;\n  idle?: boolean;\n}\n\ninterface Ink {\n  id: number;\n  x: number;\n  y: number;\n  d: number;\n}\n\nconst idlePoints = [\n  [0.18, 0.55],\n  [0.72, 0.35],\n  [0.46, 0.75],\n  [0.88, 0.62],\n  [0.3, 0.3],\n];\n\nconst css = `\n.hb-ya1 {\n  --hb-ya1-h: 2.5rem;\n  --hb-ya1-fs: 0.9375rem;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  box-sizing: border-box;\n  height: var(--hb-ya1-h);\n  margin: 0;\n  padding: 0 1.35em;\n  overflow: hidden;\n  isolation: isolate;\n  font: inherit;\n  font-size: var(--hb-ya1-fs);\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  border: 1px solid transparent;\n  border-radius: 12px;\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  transition: transform 0.18s 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-ya1 *, .hb-ya1 *::before, .hb-ya1 *::after { box-sizing: border-box; }\n.hb-ya1[data-size=\"sm\"] { --hb-ya1-h: 2.1rem; --hb-ya1-fs: 0.8125rem; }\n.hb-ya1[data-size=\"lg\"] { --hb-ya1-h: 3rem; --hb-ya1-fs: 1.0625rem; }\n.hb-ya1[data-variant=\"solid\"] {\n  --hb-ya1-ink: rgba(255, 255, 255, 0.42);\n  color: #fff;\n  background: var(--hb-ya1-c);\n}\n.hb-ya1[data-variant=\"outline\"] {\n  --hb-ya1-ink: color-mix(in srgb, var(--hb-ya1-c) 38%, transparent);\n  color: #ededed;\n  background: transparent;\n  border-color: color-mix(in srgb, var(--hb-ya1-c) 55%, #262626);\n}\n.hb-ya1[data-variant=\"ghost\"] {\n  --hb-ya1-ink: color-mix(in srgb, var(--hb-ya1-c) 30%, transparent);\n  color: color-mix(in srgb, var(--hb-ya1-c) 70%, #fff);\n  background: transparent;\n}\n.hb-ya1[data-variant=\"solid\"]:not(:disabled):hover { filter: brightness(1.1); }\n.hb-ya1[data-variant=\"outline\"]:not(:disabled):hover { background: color-mix(in srgb, var(--hb-ya1-c) 9%, transparent); }\n.hb-ya1[data-variant=\"ghost\"]:not(:disabled):hover { background: color-mix(in srgb, var(--hb-ya1-c) 10%, transparent); }\n.hb-ya1:not(:disabled):active { transform: scale(0.97); }\n.hb-ya1:focus-visible { outline: 2px solid var(--hb-ya1-c); outline-offset: 3px; }\n.hb-ya1:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-ya1[aria-busy=\"true\"] { cursor: progress; }\n.hb-ya1-inks {\n  position: absolute;\n  inset: 0;\n  z-index: 0;\n  overflow: hidden;\n  border-radius: inherit;\n  pointer-events: none;\n}\n.hb-ya1-ink {\n  position: absolute;\n  border-radius: 50%;\n  background: var(--hb-ya1-ink);\n  transform: scale(0);\n  opacity: 0.9;\n  animation: hb-ya1-spread 0.75s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;\n}\n.hb-ya1-label {\n  position: relative;\n  z-index: 1;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.6em;\n}\n.hb-ya1-spin {\n  width: 1em;\n  height: 1em;\n  border: 2px solid currentColor;\n  border-right-color: transparent;\n  border-radius: 50%;\n  animation: hb-ya1-turn 0.7s linear infinite;\n}\n@keyframes hb-ya1-spread {\n  0% { transform: scale(0); opacity: 0.9; }\n  100% { transform: scale(1); opacity: 0; }\n}\n@keyframes hb-ya1-turn {\n  to { transform: rotate(360deg); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ya1 { transition: none; }\n  .hb-ya1:not(:disabled):active { transform: none; }\n  .hb-ya1-ink { animation-duration: 0.01s; }\n  .hb-ya1-spin { animation-duration: 2s; }\n}\n`;\n\nexport function ButtonInkRipple({\n  variant = \"solid\",\n  accent = \"#2f7bff\",\n  size = \"md\",\n  loading = false,\n  idle = false,\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  children,\n  onPointerDown,\n  onPointerEnter,\n  onPointerLeave,\n  onClick,\n  ...rest\n}: ButtonInkRippleProps) {\n  const ref = React.useRef<HTMLButtonElement>(null);\n  const counter = React.useRef(0);\n  const hovering = React.useRef(false);\n  const [inks, setInks] = React.useState<Ink[]>([]);\n  const blocked = disabled || loading;\n\n  const spawn = React.useCallback((x: number, y: number) => {\n    const el = ref.current;\n    if (!el) return;\n    const rect = el.getBoundingClientRect();\n    const dx = Math.max(x, rect.width - x);\n    const dy = Math.max(y, rect.height - y);\n    const d = Math.hypot(dx, dy) * 2;\n    counter.current += 1;\n    const id = counter.current;\n    setInks((list) => [...list.slice(-5), { id, x, y, d }]);\n  }, []);\n\n  React.useEffect(() => {\n    if (!idle || blocked) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let step = 0;\n    const timer = window.setInterval(() => {\n      const el = ref.current;\n      if (!el || hovering.current) return;\n      const [fx, fy] = idlePoints[step % idlePoints.length];\n      step += 1;\n      spawn(fx * el.offsetWidth, fy * el.offsetHeight);\n    }, 2400);\n    return () => window.clearInterval(timer);\n  }, [idle, blocked, spawn]);\n\n  const vars = { \"--hb-ya1-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-button-ink-ripple\" precedence=\"default\">{css}</style>\n      <button\n        ref={ref}\n        type={type}\n        className={`hb-ya1 ${className}`}\n        style={vars}\n        data-variant={variant}\n        data-size={size}\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        onPointerDown={(e) => {\n          onPointerDown?.(e);\n          if (blocked || e.button !== 0) return;\n          const rect = e.currentTarget.getBoundingClientRect();\n          spawn(e.clientX - rect.left, e.clientY - rect.top);\n        }}\n        onClick={(e) => {\n          if (loading) {\n            e.preventDefault();\n            return;\n          }\n          if (e.detail === 0 && !disabled) {\n            const el = e.currentTarget;\n            spawn(el.offsetWidth / 2, el.offsetHeight / 2);\n          }\n          onClick?.(e);\n        }}\n        {...rest}\n      >\n        <span className=\"hb-ya1-inks\" aria-hidden=\"true\">\n          {inks.map((ink) => (\n            <span\n              key={ink.id}\n              className=\"hb-ya1-ink\"\n              style={{\n                left: `${(ink.x - ink.d / 2).toFixed(1)}px`,\n                top: `${(ink.y - ink.d / 2).toFixed(1)}px`,\n                width: `${ink.d.toFixed(1)}px`,\n                height: `${ink.d.toFixed(1)}px`,\n              }}\n              onAnimationEnd={() => setInks((list) => list.filter((item) => item.id !== ink.id))}\n            />\n          ))}\n        </span>\n        <span className=\"hb-ya1-label\">\n          {loading ? <span className=\"hb-ya1-spin\" aria-hidden=\"true\" /> : null}\n          {children}\n        </span>\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}