{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover-radial-menu",
  "type": "registry:component",
  "title": "Radial Context Menu",
  "description": "A context menu that opens as a ring of wedges around the pointer on right-click, long-press or Shift F10. Aim toward a wedge to select it, read the label in the hub, and confirm with a click or Enter.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "modals",
    "context-menu",
    "radial",
    "pie-menu",
    "right-click",
    "long-press",
    "gesture"
  ],
  "docs": "https://hyperblur.dev/effects/popover-radial-menu",
  "files": [
    {
      "path": "registry/hyperblur/popover-radial-menu.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/popover-radial-menu.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PopoverRadialItem {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  shortcut?: string;\n  danger?: boolean;\n}\n\nexport interface PopoverRadialMenuProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n  items?: PopoverRadialItem[];\n  children?: React.ReactNode;\n  radius?: number;\n  longPress?: number;\n  onSelect?: (id: string) => void;\n  onOpenChange?: (open: boolean) => void;\n  label?: string;\n  embedded?: boolean;\n  accent?: string;\n}\n\nconst glyphs: Record<string, string> = {\n  copy: \"M9 9h10v10H9zM5 15V5h10\",\n  duplicate: \"M8 8h12v12H8zM14 11v6M11 14h6M4 16V4h12\",\n  share: \"M12 3v12M7 8l5-5 5 5M5 13v6h14v-6\",\n  favorite: \"M12 4l2.5 5.2 5.5.7-4 3.9 1 5.6L12 16.8 7 19.4l1-5.6-4-3.9 5.5-.7z\",\n  rename: \"M4 20h4L19 9l-4-4L4 16zM13 7l4 4\",\n  delete: \"M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13\",\n};\n\nconst defaultItems: PopoverRadialItem[] = [\n  { id: \"copy\", label: \"Copy\", shortcut: \"⌘C\" },\n  { id: \"duplicate\", label: \"Duplicate\", shortcut: \"⌘D\" },\n  { id: \"share\", label: \"Share\", shortcut: \"⇧S\" },\n  { id: \"favorite\", label: \"Favorite\", shortcut: \"F\" },\n  { id: \"rename\", label: \"Rename\", shortcut: \"↵\" },\n  { id: \"delete\", label: \"Delete\", shortcut: \"⌫\", danger: true },\n];\n\nconst css = `\n.hb-xf10 { --hb-xf10-accent: #2f7bff; position: relative; box-sizing: border-box; width: 100%; font-family: inherit; color: #ededed; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; outline: none; border-radius: 16px; }\n.hb-xf10 *, .hb-xf10 *::before, .hb-xf10 *::after { box-sizing: border-box; }\n.hb-xf10:focus-visible { box-shadow: 0 0 0 2px var(--hb-xf10-accent); }\n.hb-xf10-canvas { position: relative; height: 280px; border-radius: 16px; overflow: hidden; border: 1px solid #222; background: linear-gradient(180deg, #1d2a3f 0%, #3b3552 45%, #c0745a 78%, #2a1d1b 100%); }\n.hb-xf10-canvas svg { position: absolute; inset: auto 0 0; width: 100%; height: 62%; }\n.hb-xf10-sun { position: absolute; left: 62%; top: 34%; width: 56px; height: 56px; border-radius: 50%; background: radial-gradient(circle, #ffd9a0, #ff9a6a 60%, transparent 70%); filter: blur(.5px); }\n.hb-xf10-cap { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11.5px; }\n.hb-xf10-file { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; background: rgba(10,10,10,.55); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.1); font-family: var(--font-mono), ui-monospace, monospace; }\n.hb-xf10-hint { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; background: rgba(10,10,10,.55); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.1); color: #d4d4d4; white-space: nowrap; }\n.hb-xf10-hint kbd { font-family: var(--font-mono), ui-monospace, monospace; font-size: 10px; padding: 0 4px; border-radius: 4px; border: 1px solid rgba(255,255,255,.2); }\n.hb-xf10-menu { position: absolute; z-index: 40; outline: none; transform: translate(-50%, -50%); }\n.hb-xf10-menu svg { display: block; overflow: visible; filter: drop-shadow(0 18px 30px rgba(0,0,0,.6)); }\n.hb-xf10-ring { transform-origin: center; transform-box: view-box; animation: hb-xf10-open .42s cubic-bezier(.2,1.3,.4,1) both; }\n.hb-xf10-menu[data-state=\"closing\"] .hb-xf10-ring { animation: hb-xf10-close .2s cubic-bezier(.4,0,1,1) both; }\n.hb-xf10-wedge { fill: rgba(22,22,22,.92); stroke: #2e2e2e; stroke-width: 1; transition: fill .18s ease, transform .25s cubic-bezier(.3,1.4,.5,1); transform-box: view-box; transform-origin: center; cursor: pointer; }\n.hb-xf10-item[data-active=\"true\"] .hb-xf10-wedge { fill: color-mix(in srgb, var(--hb-xf10-accent) 30%, #161616); stroke: color-mix(in srgb, var(--hb-xf10-accent) 70%, #2e2e2e); }\n.hb-xf10-item[data-danger=\"true\"][data-active=\"true\"] .hb-xf10-wedge { fill: color-mix(in srgb, #ff4d4d 28%, #161616); stroke: #ff5d5d; }\n.hb-xf10-item[data-fired=\"true\"] .hb-xf10-wedge { animation: hb-xf10-fire .35s ease both; }\n.hb-xf10-icon { fill: none; stroke: #bdbdbd; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; transition: stroke .18s; pointer-events: none; }\n.hb-xf10-item[data-active=\"true\"] .hb-xf10-icon { stroke: #fff; }\n.hb-xf10-item[data-danger=\"true\"] .hb-xf10-icon { stroke: #ff8a8a; }\n.hb-xf10-hub { fill: #0f0f0f; stroke: #2e2e2e; }\n.hb-xf10-pointer { fill: var(--hb-xf10-accent); transition: transform .25s cubic-bezier(.3,1.3,.5,1); transform-box: view-box; transform-origin: center; }\n.hb-xf10-hublabel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 2px; pointer-events: none; text-align: center; }\n.hb-xf10-hublabel b { font-size: 11.5px; font-weight: 600; white-space: nowrap; }\n.hb-xf10-hublabel span { font-family: var(--font-mono), ui-monospace, monospace; font-size: 10px; color: #8f8f8f; }\n.hb-xf10-toast { position: absolute; left: 50%; top: 14px; z-index: 41; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 12px; background: rgba(15,15,15,.88); backdrop-filter: blur(10px); border: 1px solid #2a2a2a; white-space: nowrap; animation: hb-xf10-toast 1.8s cubic-bezier(.2,.8,.2,1) both; }\n.hb-xf10-toast i { font-style: normal; width: 7px; height: 7px; border-radius: 50%; background: #3ddc84; }\n@keyframes hb-xf10-open { from { opacity: 0; transform: scale(.4) rotate(-40deg); } to { opacity: 1; transform: none; } }\n@keyframes hb-xf10-close { to { opacity: 0; transform: scale(.7) rotate(12deg); } }\n@keyframes hb-xf10-fire { 50% { transform: scale(1.07); } }\n@keyframes hb-xf10-toast { 0% { opacity: 0; transform: translate(-50%, -8px); } 15%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -4px); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xf10 *, .hb-xf10 *::before { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction polar(cx: number, cy: number, r: number, deg: number) {\n  const a = (deg * Math.PI) / 180;\n  return [cx + r * Math.cos(a), cy + r * Math.sin(a)];\n}\n\nfunction sector(cx: number, cy: number, r0: number, r1: number, a0: number, a1: number) {\n  const [x0, y0] = polar(cx, cy, r1, a0);\n  const [x1, y1] = polar(cx, cy, r1, a1);\n  const [x2, y2] = polar(cx, cy, r0, a1);\n  const [x3, y3] = polar(cx, cy, r0, a0);\n  const large = a1 - a0 > 180 ? 1 : 0;\n  const f = (n: number) => n.toFixed(2);\n  return `M${f(x0)} ${f(y0)} A${r1} ${r1} 0 ${large} 1 ${f(x1)} ${f(y1)} L${f(x2)} ${f(y2)} A${r0} ${r0} 0 ${large} 0 ${f(x3)} ${f(y3)} Z`;\n}\n\nfunction DefaultCanvas() {\n  return (\n    <div className=\"hb-xf10-canvas\">\n      <span className=\"hb-xf10-sun\" aria-hidden=\"true\" />\n      <svg viewBox=\"0 0 400 160\" preserveAspectRatio=\"none\" aria-hidden=\"true\">\n        <path d=\"M0 90 L60 50 L110 80 L170 30 L230 76 L290 44 L350 70 L400 52 V160 H0Z\" fill=\"#2b2338\" />\n        <path d=\"M0 120 L80 84 L150 110 L220 78 L300 108 L360 90 L400 104 V160 H0Z\" fill=\"#1b1622\" />\n        <path d=\"M0 140 Q100 124 200 138 T400 132 V160 H0Z\" fill=\"#0f0c12\" />\n      </svg>\n      <div className=\"hb-xf10-cap\">\n        <span className=\"hb-xf10-file\">IMG_2041.heic</span>\n        <span className=\"hb-xf10-hint\">Right-click or hold <kbd>⇧F10</kbd></span>\n      </div>\n    </div>\n  );\n}\n\nexport function PopoverRadialMenu({\n  items = defaultItems,\n  children,\n  radius = 92,\n  longPress = 450,\n  onSelect,\n  onOpenChange,\n  label = \"Photo actions\",\n  embedded = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: PopoverRadialMenuProps) {\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const menuRef = React.useRef<HTMLDivElement>(null);\n  const [menu, setMenu] = React.useState<{ x: number; y: number } | null>(embedded ? { x: -1, y: -1 } : null);\n  const [closing, setClosing] = React.useState(false);\n  const [active, setActive] = React.useState(0);\n  const [fired, setFired] = React.useState<string | null>(null);\n  const [toast, setToast] = React.useState<{ text: string; n: number } | null>(null);\n  const press = React.useRef(0);\n  const timers = React.useRef<number[]>([]);\n  const n = Math.max(1, items.length);\n  const r0 = Math.round(radius * 0.4);\n  const size = (radius + 8) * 2;\n  const c = size / 2;\n  const step = 360 / n;\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => {\n      list.forEach((t) => window.clearTimeout(t));\n      window.clearTimeout(press.current);\n    };\n  }, []);\n\n  const openAt = React.useCallback(\n    (clientX: number | null, clientY: number | null) => {\n      const root = rootRef.current;\n      if (!root) return;\n      const rr = root.getBoundingClientRect();\n      const k = rr.width / (root.offsetWidth || 1) || 1;\n      const w = root.offsetWidth;\n      const h = root.offsetHeight;\n      const pad = radius + 10;\n      let x = clientX === null ? w / 2 : (clientX - rr.left) / k;\n      let y = clientY === null ? h / 2 : (clientY - rr.top) / k;\n      x = w > pad * 2 ? Math.min(Math.max(x, pad), w - pad) : w / 2;\n      y = h > pad * 2 ? Math.min(Math.max(y, pad), h - pad) : h / 2;\n      setClosing(false);\n      setActive(0);\n      setMenu({ x, y });\n      onOpenChange?.(true);\n      requestAnimationFrame(() => menuRef.current?.focus({ preventScroll: true }));\n    },\n    [radius, onOpenChange],\n  );\n\n  const close = React.useCallback(\n    (refocus: boolean) => {\n      setClosing(true);\n      timers.current.push(\n        window.setTimeout(() => {\n          setMenu(null);\n          setClosing(false);\n          setFired(null);\n          onOpenChange?.(false);\n          if (refocus) rootRef.current?.focus({ preventScroll: true });\n        }, 200),\n      );\n    },\n    [onOpenChange],\n  );\n\n  React.useEffect(() => {\n    if (!menu || embedded) return;\n    const onDown = (e: PointerEvent) => {\n      if (menuRef.current && !menuRef.current.contains(e.target as Node)) close(false);\n    };\n    const onScroll = () => close(false);\n    document.addEventListener(\"pointerdown\", onDown, true);\n    window.addEventListener(\"scroll\", onScroll, true);\n    return () => {\n      document.removeEventListener(\"pointerdown\", onDown, true);\n      window.removeEventListener(\"scroll\", onScroll, true);\n    };\n  }, [menu, embedded, close]);\n\n  const fire = (i: number) => {\n    const item = items[i];\n    if (!item || closing) return;\n    setFired(item.id);\n    onSelect?.(item.id);\n    setToast((t) => ({ text: item.label, n: (t?.n ?? 0) + 1 }));\n    timers.current.push(window.setTimeout(() => close(true), 160));\n  };\n\n  const pick = (e: React.PointerEvent) => {\n    const el = menuRef.current;\n    if (!el) return -1;\n    const b = el.getBoundingClientRect();\n    const k = b.width / (el.offsetWidth || 1) || 1;\n    const dx = (e.clientX - (b.left + b.width / 2)) / k;\n    const dy = (e.clientY - (b.top + b.height / 2)) / k;\n    if (Math.hypot(dx, dy) < r0) return -1;\n    const deg = ((Math.atan2(dy, dx) * 180) / Math.PI + 90 + step / 2 + 720) % 360;\n    return Math.floor(deg / step) % n;\n  };\n\n  const onMenuKey = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") {\n      e.preventDefault();\n      setActive((a) => (a + 1) % n);\n    } else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setActive((a) => (a - 1 + n) % n);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      setActive(0);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      setActive(n - 1);\n    } else if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      fire(active);\n    } else if (e.key === \"Escape\" || e.key === \"Tab\") {\n      if (e.key === \"Escape\") e.preventDefault();\n      e.stopPropagation();\n      close(e.key === \"Escape\");\n    }\n  };\n\n  const cur = items[active];\n  const pos = menu && menu.x < 0 ? { left: \"50%\", top: \"50%\" } : menu ? { left: menu.x, top: menu.y } : undefined;\n  const mid = -90 + active * step;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-xf10 ${className}`}\n      tabIndex={0}\n      aria-label={`${label}. Press Shift F10 for actions`}\n      aria-haspopup=\"menu\"\n      aria-expanded={Boolean(menu)}\n      style={{ \"--hb-xf10-accent\": accent, ...style } as React.CSSProperties}\n      onContextMenu={(e) => {\n        e.preventDefault();\n        openAt(e.clientX, e.clientY);\n      }}\n      onKeyDown={(e) => {\n        if (e.target !== e.currentTarget) return;\n        if ((e.shiftKey && e.key === \"F10\") || e.key === \"ContextMenu\" || e.key === \"Enter\") {\n          e.preventDefault();\n          openAt(null, null);\n        }\n      }}\n      onPointerDown={(e) => {\n        if (e.pointerType !== \"touch\" || menu) return;\n        const { clientX, clientY } = e;\n        window.clearTimeout(press.current);\n        press.current = window.setTimeout(() => openAt(clientX, clientY), longPress);\n      }}\n      onPointerUp={() => window.clearTimeout(press.current)}\n      onPointerCancel={() => window.clearTimeout(press.current)}\n      onPointerMove={(e) => {\n        if (e.pointerType === \"touch\" && !menu) window.clearTimeout(press.current);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-popover-radial-menu\" precedence=\"default\">{css}</style>\n      {children ?? <DefaultCanvas />}\n      {toast && (\n        <span className=\"hb-xf10-toast\" key={toast.n} role=\"status\">\n          <i aria-hidden=\"true\" />\n          {toast.text} · done\n        </span>\n      )}\n      {menu && pos && (\n        <div\n          ref={menuRef}\n          className=\"hb-xf10-menu\"\n          role=\"menu\"\n          aria-label={label}\n          aria-activedescendant={`${uid}-i${active}`}\n          tabIndex={-1}\n          data-state={closing ? \"closing\" : \"open\"}\n          style={{ ...pos, width: size, height: size }}\n          onKeyDown={onMenuKey}\n          onContextMenu={(e) => {\n            e.preventDefault();\n            e.stopPropagation();\n          }}\n          onPointerMove={(e) => {\n            const i = pick(e);\n            if (i >= 0 && i !== active) setActive(i);\n          }}\n          onClick={(e) => {\n            e.stopPropagation();\n            const i = pick(e as unknown as React.PointerEvent);\n            if (i >= 0) fire(i);\n            else close(true);\n          }}\n        >\n          <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>\n            <g className=\"hb-xf10-ring\">\n              {items.map((it, i) => {\n                const a0 = -90 - step / 2 + i * step + 1.6;\n                const a1 = a0 + step - 3.2;\n                const [ix, iy] = polar(c, c, (r0 + radius) / 2, -90 + i * step);\n                const glyph = glyphs[it.id];\n                return (\n                  <g\n                    key={it.id}\n                    id={`${uid}-i${i}`}\n                    className=\"hb-xf10-item\"\n                    role=\"menuitem\"\n                    aria-label={it.shortcut ? `${it.label}, ${it.shortcut}` : it.label}\n                    data-active={i === active}\n                    data-danger={it.danger ? \"true\" : \"false\"}\n                    data-fired={fired === it.id}\n                  >\n                    <path className=\"hb-xf10-wedge\" d={sector(c, c, r0, radius, a0, a1)} />\n                    {it.icon ? (\n                      <foreignObject x={(ix - 10).toFixed(2)} y={(iy - 10).toFixed(2)} width=\"20\" height=\"20\" style={{ pointerEvents: \"none\", color: it.danger ? \"#ff8a8a\" : \"#ededed\" }}>\n                        {it.icon}\n                      </foreignObject>\n                    ) : (\n                      <path className=\"hb-xf10-icon\" d={glyph ?? \"M8 12h8M12 8v8\"} transform={`translate(${(ix - 9).toFixed(2)} ${(iy - 9).toFixed(2)}) scale(.75)`} />\n                    )}\n                  </g>\n                );\n              })}\n              <circle className=\"hb-xf10-hub\" cx={c} cy={c} r={r0 - 4} />\n              <path\n                className=\"hb-xf10-pointer\"\n                d={`M${c - 5} ${(c - r0 + 9).toFixed(2)} L${c} ${(c - r0 + 3).toFixed(2)} L${c + 5} ${(c - r0 + 9).toFixed(2)} Z`}\n                style={{ transform: `rotate(${(mid + 90).toFixed(2)}deg)` }}\n              />\n            </g>\n          </svg>\n          {cur && (\n            <span className=\"hb-xf10-hublabel\" aria-hidden=\"true\">\n              <b style={cur.danger ? { color: \"#ff8a8a\" } : undefined}>{cur.label}</b>\n              {cur.shortcut && <span>{cur.shortcut}</span>}\n            </span>\n          )}\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}