{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-press-radial",
  "type": "registry:component",
  "title": "Button Press Radial",
  "description": "Tap to run the main action, or long-press to open a radial menu around the button and drag toward an option to pick it on release. A ring fills during the hold and a beam follows your finger.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "long press",
    "radial menu",
    "context menu",
    "send",
    "gesture"
  ],
  "docs": "https://hyperblur.dev/effects/button-press-radial",
  "files": [
    {
      "path": "registry/hyperblur/button-press-radial.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-press-radial.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonPressRadialOption {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n}\n\nexport interface ButtonPressRadialProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n  options?: ButtonPressRadialOption[];\n  label?: string;\n  icon?: React.ReactNode;\n  holdTime?: number;\n  radius?: number;\n  startAngle?: number;\n  endAngle?: number;\n  accent?: string;\n  disabled?: boolean;\n  onPress?: () => void;\n  onSelect?: (id: string) => void;\n  onOpenChange?: (open: boolean) => void;\n}\n\nconst css = `\n.hb-xb12 {\n  --hb-xb12-c: #2f7bff;\n  --hb-xb12-hold: 480ms;\n  position: relative;\n  display: inline-grid;\n  place-items: center;\n  width: 52px;\n  height: 52px;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n}\n.hb-xb12 *, .hb-xb12 *::before, .hb-xb12 *::after { box-sizing: border-box; }\n.hb-xb12-main {\n  position: relative;\n  z-index: 3;\n  width: 52px;\n  height: 52px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  display: grid;\n  place-items: center;\n  color: #fff;\n  font: inherit;\n  cursor: pointer;\n  background: radial-gradient(120% 120% at 30% 15%, color-mix(in srgb, var(--hb-xb12-c) 70%, #fff) 0%, var(--hb-xb12-c) 50%, color-mix(in srgb, var(--hb-xb12-c) 75%, #000) 100%);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 10px 24px -10px var(--hb-xb12-c), 0 3px 8px -2px rgba(0, 0, 0, 0.6);\n  touch-action: none;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-touch-callout: none;\n  -webkit-tap-highlight-color: transparent;\n  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s ease, box-shadow 0.3s ease;\n}\n.hb-xb12[data-press=\"true\"] .hb-xb12-main { transform: scale(0.9); }\n.hb-xb12[data-open=\"true\"] .hb-xb12-main { transform: scale(0.82); background: radial-gradient(120% 120% at 30% 15%, #3a3a3a 0%, #1f1f1f 60%, #141414 100%); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 0 0 1px #333; }\n.hb-xb12-main:focus-visible { outline: 2px solid var(--hb-xb12-c); outline-offset: 4px; }\n.hb-xb12-main:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-xb12-main svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xb12[data-open=\"true\"] .hb-xb12-main svg { transform: scale(0.85); }\n.hb-xb12-ring { position: absolute; inset: -7px; width: calc(100% + 14px); height: calc(100% + 14px); transform: rotate(-90deg); pointer-events: none; z-index: 2; }\n.hb-xb12-ring circle { fill: none; stroke: var(--hb-xb12-c); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 201; stroke-dashoffset: 201; opacity: 0; }\n.hb-xb12[data-press=\"true\"] .hb-xb12-ring circle { opacity: 1; animation: hb-xb12-fill var(--hb-xb12-hold) cubic-bezier(0.4, 0, 0.6, 1) forwards; }\n.hb-xb12-halo {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: calc(var(--hb-xb12-r) * 2 + 96px);\n  height: calc(var(--hb-xb12-r) * 2 + 96px);\n  margin: calc((var(--hb-xb12-r) * 2 + 96px) / -2);\n  border-radius: 50%;\n  background: radial-gradient(circle, rgba(8, 8, 8, 0.9) 0%, rgba(8, 8, 8, 0.65) 42%, transparent 70%);\n  opacity: 0;\n  transform: scale(0.5);\n  pointer-events: none;\n  transition: opacity 0.25s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);\n  z-index: 0;\n}\n.hb-xb12[data-open=\"true\"] .hb-xb12-halo { opacity: 1; transform: none; }\n.hb-xb12-beam {\n  position: absolute;\n  left: 50%;\n  top: 50%;\n  width: var(--hb-xb12-bl, 0px);\n  height: 2px;\n  margin-top: -1px;\n  transform-origin: 0 50%;\n  transform: rotate(var(--hb-xb12-ba, 0deg));\n  border-radius: 2px;\n  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--hb-xb12-c) 80%, #fff));\n  opacity: 0;\n  pointer-events: none;\n  z-index: 1;\n  transition: opacity 0.2s ease;\n}\n.hb-xb12[data-drag=\"true\"] .hb-xb12-beam { opacity: 0.8; }\n.hb-xb12-opts { position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin: 0; padding: 0; list-style: none; z-index: 2; }\n.hb-xb12-opt {\n  position: absolute;\n  left: -22px;\n  top: -22px;\n  width: 44px;\n  height: 44px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  display: grid;\n  place-items: center;\n  color: #d4d4d4;\n  font: inherit;\n  cursor: pointer;\n  background: linear-gradient(180deg, #242424, #181818);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 0 1px #2f2f2f, 0 10px 20px -10px rgba(0, 0, 0, 0.95);\n  opacity: 0;\n  visibility: hidden;\n  transform: translate(0, 0) scale(0.2);\n  transition: transform 0.3s cubic-bezier(0.55, 0, 0.3, 1), opacity 0.2s ease, visibility 0s linear 0.3s, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;\n}\n.hb-xb12[data-open=\"true\"] .hb-xb12-opt {\n  opacity: 1;\n  visibility: visible;\n  transform: translate(var(--hb-xb12-x), var(--hb-xb12-y)) scale(1);\n  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) var(--hb-xb12-d, 0s), opacity 0.2s ease var(--hb-xb12-d, 0s), visibility 0s, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;\n}\n.hb-xb12[data-open=\"true\"] .hb-xb12-opt[data-hot=\"true\"] {\n  color: #fff;\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xb12-c) 75%, #fff) 0%, var(--hb-xb12-c) 100%);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 0 0 1px var(--hb-xb12-c), 0 10px 24px -8px var(--hb-xb12-c);\n  transform: translate(var(--hb-xb12-x), var(--hb-xb12-y)) scale(1.14);\n  transition-delay: 0s;\n}\n.hb-xb12-opt:focus-visible { outline: 2px solid color-mix(in srgb, var(--hb-xb12-c) 80%, #fff); outline-offset: 3px; }\n.hb-xb12-opt svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }\n.hb-xb12-cap {\n  position: absolute;\n  left: 50%;\n  bottom: calc(100% + 8px);\n  white-space: nowrap;\n  padding: 4px 8px;\n  border-radius: 7px;\n  font-size: 11.5px;\n  font-weight: 600;\n  color: #ededed;\n  background: #1c1c1c;\n  box-shadow: 0 0 0 1px #2e2e2e, 0 8px 18px -8px rgba(0, 0, 0, 0.9);\n  opacity: 0;\n  transform: translate(-50%, 4px);\n  pointer-events: none;\n  transition: opacity 0.15s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-xb12-opt[data-hot=\"true\"] .hb-xb12-cap { opacity: 1; transform: translate(-50%, 0); }\n@keyframes hb-xb12-fill { to { stroke-dashoffset: 0; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xb12 *, .hb-xb12-opt, .hb-xb12[data-open=\"true\"] .hb-xb12-opt { transition-duration: 0.01s !important; transition-delay: 0s !important; }\n  .hb-xb12[data-press=\"true\"] .hb-xb12-ring circle { animation-timing-function: steps(4, end); }\n}\n`;\n\nconst ico = (d: string) => (\n  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n    <path d={d} />\n  </svg>\n);\n\nconst defaultOptions: ButtonPressRadialOption[] = [\n  { id: \"schedule\", label: \"Schedule send\", icon: ico(\"M12 20.5a8.5 8.5 0 1 0 0-17 8.5 8.5 0 0 0 0 17zM12 7.5V12l3 2\") },\n  { id: \"silent\", label: \"Send without sound\", icon: ico(\"M9.5 19.5a2.6 2.6 0 0 0 5 0M6.3 6.8A6 6 0 0 0 6 8.7V14l-1.6 2.6h11.3M9 4.3A6 6 0 0 1 18 9.2V14M3.5 3.5l17 17\") },\n  { id: \"draft\", label: \"Save as draft\", icon: ico(\"M14 3.5H7.5c-1 0-2 .9-2 2v13c0 1.1 1 2 2 2h9c1.1 0 2-.9 2-2V8zM14 3.5V8h4.5M9 14.5l2 2 4-4\") },\n  { id: \"vanish\", label: \"Disappearing message\", icon: ico(\"M12 20.5a8.5 8.5 0 1 1 8.5-8.5M12 7.5V12h4M17.5 16.5l3 3M20.5 16.5l-3 3\") },\n];\n\nexport function ButtonPressRadial({\n  options = defaultOptions,\n  label = \"Send\",\n  icon,\n  holdTime = 480,\n  radius = 84,\n  startAngle = 165,\n  endAngle = 15,\n  accent = \"#2f7bff\",\n  disabled = false,\n  onPress,\n  onSelect,\n  onOpenChange,\n  className = \"\",\n  style,\n  ...rest\n}: ButtonPressRadialProps) {\n  const id = React.useId();\n  const [open, setOpenState] = React.useState(false);\n  const [pressing, setPressing] = React.useState(false);\n  const [drag, setDrag] = React.useState(false);\n  const [hot, setHot] = React.useState(-1);\n  const [beam, setBeam] = React.useState({ a: 0, l: 0 });\n  const root = React.useRef<HTMLDivElement>(null);\n  const main = React.useRef<HTMLButtonElement>(null);\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const timer = React.useRef(0);\n  const phase = React.useRef<\"idle\" | \"pressing\" | \"drag\">(\"idle\");\n  const hotRef = React.useRef(-1);\n  const suppress = React.useRef(false);\n\n  const n = options.length;\n  const pos = options.map((_, i) => {\n    const t = n === 1 ? 0.5 : i / (n - 1);\n    const deg = startAngle + (endAngle - startAngle) * t;\n    const a = (deg * Math.PI) / 180;\n    return { deg, x: Math.cos(a) * radius, y: -Math.sin(a) * radius };\n  });\n\n  const setOpen = (next: boolean) => {\n    setOpenState(next);\n    onOpenChange?.(next);\n  };\n\n  const setHotBoth = (i: number) => {\n    hotRef.current = i;\n    setHot(i);\n  };\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onDown = (e: PointerEvent) => {\n      if (root.current && !root.current.contains(e.target as Node)) {\n        setOpenState(false);\n        setHot(-1);\n        hotRef.current = -1;\n        onOpenChange?.(false);\n      }\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open, onOpenChange]);\n\n  const close = (refocus: boolean) => {\n    setOpen(false);\n    setDrag(false);\n    setHotBoth(-1);\n    phase.current = \"idle\";\n    if (refocus) main.current?.focus();\n  };\n\n  const choose = (i: number) => {\n    const o = options[i];\n    if (!o) return;\n    onSelect?.(o.id);\n    close(true);\n  };\n\n  const openWith = (focusFirst: boolean) => {\n    setOpen(true);\n    if (focusFirst) {\n      setHotBoth(0);\n      window.requestAnimationFrame(() => refs.current[0]?.focus());\n    }\n  };\n\n  const track = (clientX: number, clientY: number) => {\n    const el = main.current;\n    if (!el) return;\n    const r = el.getBoundingClientRect();\n    const dx = clientX - (r.left + r.width / 2);\n    const dy = clientY - (r.top + r.height / 2);\n    const dist = Math.hypot(dx, dy);\n    const deg = (Math.atan2(-dy, dx) * 180) / Math.PI;\n    setBeam({ a: (Math.atan2(dy, dx) * 180) / Math.PI, l: Math.min(dist, radius) });\n    if (dist < 30) {\n      setHotBoth(-1);\n      return;\n    }\n    let best = -1;\n    let bestDiff = 999;\n    pos.forEach((p, i) => {\n      let diff = Math.abs(((deg - p.deg + 540) % 360) - 180);\n      if (dist > radius + 60) diff += 999;\n      if (diff < bestDiff) {\n        bestDiff = diff;\n        best = i;\n      }\n    });\n    const span = n > 1 ? Math.abs(endAngle - startAngle) / (n - 1) : 60;\n    setHotBoth(bestDiff <= Math.max(24, span * 0.75) ? best : -1);\n  };\n\n  const onPointerDown = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (disabled || e.button !== 0) return;\n    if (open) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    phase.current = \"pressing\";\n    setPressing(true);\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => {\n      if (phase.current !== \"pressing\") return;\n      phase.current = \"drag\";\n      setPressing(false);\n      setDrag(true);\n      openWith(false);\n      if (\"vibrate\" in navigator) navigator.vibrate?.(8);\n    }, holdTime);\n  };\n\n  const onPointerMove = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (phase.current === \"drag\") track(e.clientX, e.clientY);\n  };\n\n  const onPointerUp = () => {\n    window.clearTimeout(timer.current);\n    const p = phase.current;\n    setPressing(false);\n    if (p === \"pressing\") {\n      phase.current = \"idle\";\n      onPress?.();\n    } else if (p === \"drag\") {\n      setDrag(false);\n      phase.current = \"idle\";\n      suppress.current = true;\n      if (hotRef.current >= 0) choose(hotRef.current);\n    }\n  };\n\n  const onPointerCancel = () => {\n    window.clearTimeout(timer.current);\n    setPressing(false);\n    setDrag(false);\n    phase.current = \"idle\";\n  };\n\n  const onRootKey = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (!open) return;\n    const i = refs.current.findIndex((el) => el === document.activeElement);\n    const step = (d: number) => {\n      const next = ((i < 0 ? (d > 0 ? -1 : 0) : i) + d + n) % n;\n      setHotBoth(next);\n      refs.current[next]?.focus();\n    };\n    if (e.key === \"Escape\") {\n      e.preventDefault();\n      close(true);\n    } else if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      step(1);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      step(-1);\n    } else if (e.key === \"Tab\") {\n      close(false);\n    }\n  };\n\n  return (\n    <div\n      ref={root}\n      className={`hb-xb12 ${className}`.trim()}\n      data-open={open ? \"true\" : \"false\"}\n      data-press={pressing ? \"true\" : \"false\"}\n      data-drag={drag ? \"true\" : \"false\"}\n      style={\n        {\n          \"--hb-xb12-c\": accent,\n          \"--hb-xb12-hold\": `${holdTime}ms`,\n          \"--hb-xb12-r\": `${radius}px`,\n          \"--hb-xb12-ba\": `${beam.a.toFixed(1)}deg`,\n          \"--hb-xb12-bl\": `${beam.l.toFixed(1)}px`,\n          ...style,\n        } as React.CSSProperties\n      }\n      onKeyDown={onRootKey}\n      {...rest}\n    >\n      <style href=\"hb-button-press-radial\" precedence=\"default\">{css}</style>\n      <span className=\"hb-xb12-halo\" aria-hidden=\"true\" />\n      <span className=\"hb-xb12-beam\" aria-hidden=\"true\" />\n      <ul id={`${id}-menu`} className=\"hb-xb12-opts\" role=\"menu\" aria-label={`${label} options`} aria-hidden={!open}>\n        {options.map((o, i) => (\n          <li key={o.id} role=\"none\">\n            <button\n              ref={(el) => {\n                refs.current[i] = el;\n              }}\n              type=\"button\"\n              role=\"menuitem\"\n              className=\"hb-xb12-opt\"\n              tabIndex={open ? 0 : -1}\n              aria-label={o.label}\n              data-hot={hot === i ? \"true\" : \"false\"}\n              style={\n                {\n                  \"--hb-xb12-x\": `${pos[i].x.toFixed(2)}px`,\n                  \"--hb-xb12-y\": `${pos[i].y.toFixed(2)}px`,\n                  \"--hb-xb12-d\": `${(i * 0.04).toFixed(2)}s`,\n                } as React.CSSProperties\n              }\n              onPointerEnter={() => setHotBoth(i)}\n              onPointerLeave={() => phase.current !== \"drag\" && setHotBoth(-1)}\n              onFocus={() => setHotBoth(i)}\n              onClick={() => choose(i)}\n            >\n              {o.icon ?? ico(\"M12 5v14M5 12h14\")}\n              <span className=\"hb-xb12-cap\" aria-hidden=\"true\">\n                {o.label}\n              </span>\n            </button>\n          </li>\n        ))}\n      </ul>\n      <svg className=\"hb-xb12-ring\" viewBox=\"0 0 66 66\" aria-hidden=\"true\">\n        <circle cx=\"33\" cy=\"33\" r=\"32\" />\n      </svg>\n      <button\n        ref={main}\n        type=\"button\"\n        className=\"hb-xb12-main\"\n        disabled={disabled}\n        aria-label={`${label}. Long press or press Arrow Up for more options.`}\n        aria-haspopup=\"menu\"\n        aria-expanded={open}\n        aria-controls={`${id}-menu`}\n        onPointerDown={onPointerDown}\n        onPointerMove={onPointerMove}\n        onPointerUp={onPointerUp}\n        onPointerCancel={onPointerCancel}\n        onContextMenu={(e) => {\n          e.preventDefault();\n          if (!disabled && !open && phase.current === \"idle\") openWith(false);\n        }}\n        onClick={(e) => {\n          if (suppress.current) {\n            suppress.current = false;\n            return;\n          }\n          if (e.detail === 0 && !open) onPress?.();\n          else if (open && phase.current === \"idle\" && e.detail > 0) close(false);\n        }}\n        onKeyDown={(e) => {\n          if (disabled) return;\n          if (!open && (e.key === \"ArrowUp\" || e.key === \"ContextMenu\" || (e.shiftKey && e.key === \"F10\"))) {\n            e.preventDefault();\n            e.stopPropagation();\n            openWith(true);\n          }\n        }}\n      >\n        {icon ?? (\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M4.5 12L20 4.5 15 20l-3.2-6.3zM11.8 13.7L20 4.5\" />\n          </svg>\n        )}\n      </button>\n    </div>\n  );\n}\n"
    }
  ]
}