{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dropdown-menu",
  "title": "Dropdown Menu",
  "description": "Menu button and right-click context menu with default, glass, neo, inverted and flat surfaces, soft, solid, bar or outline highlights, tones, sizes, shapes and shadows; icons, descriptions, badges and live keyboard shortcuts, checkbox items, radio groups, labelled groups, destructive items and nested sub-menus with hover intent and a safe triangle; scale, fade, slide or stagger entrances, type-ahead and full APG keyboard, portaled and flipped to stay on screen.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/core/dropdown-menu.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { AnimatePresence, motion, useIsPresent, useReducedMotion, type Transition } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, ease as easing } from \"@/lib/goodui-motion\"\n\n/*\n * Menu button and context menu, independent layers: every axis combines with every other.\n *   variant    default, glass, neo, inverted, flat (menu surface)   tone       accent for highlight, checks and bars\n *   highlight  soft, solid, bar, outline (active item)              size       sm, md, lg\n *   shadow     none, sm, md, lg                                    shape      square, rounded, pill\n *   animation  none, fade, scale, slide, stagger (open)            mode       menu (trigger) or context (right-click)\n * Items: actions with icons, descriptions, badges and shortcuts, checkbox items, radio groups, labelled groups,\n * separators, destructive items and nested sub-menus (hover intent with a safe triangle, or arrow keys).\n * Keyboard follows the WAI-ARIA menu button pattern: ↑ ↓ Home End, → opens a sub-menu, ← closes it, Enter/Space\n * activate, Esc closes one level, Tab closes everything, letters jump (type-ahead).\n * Menus render in a portal on document.body and flip/shift to stay inside the viewport.\n */\n\nexport type DropdownMenuVariant = \"default\" | \"glass\" | \"neo\" | \"inverted\" | \"flat\"\nexport type DropdownMenuTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type DropdownMenuSize = \"sm\" | \"md\" | \"lg\"\nexport type DropdownMenuShadow = \"none\" | \"sm\" | \"md\" | \"lg\"\nexport type DropdownMenuAnimation = \"none\" | \"fade\" | \"scale\" | \"slide\" | \"stagger\"\nexport type DropdownMenuShape = \"square\" | \"rounded\" | \"pill\"\nexport type DropdownMenuHighlight = \"soft\" | \"solid\" | \"bar\" | \"outline\"\nexport type DropdownMenuSide = \"top\" | \"bottom\" | \"left\" | \"right\"\nexport type DropdownMenuAlign = \"start\" | \"center\" | \"end\"\n\ntype ItemBase = {\n  label: string\n  icon?: React.ReactNode\n  /** Second, muted line. */\n  description?: string\n  /** Shown on the right as keycaps, e.g. \"Mod+D\" (⌘D on Mac, Ctrl+D elsewhere), \"Shift+Mod+E\", \"Delete\". */\n  shortcut?: string\n  disabled?: boolean\n}\nexport type DropdownMenuAction = ItemBase & {\n  type?: \"item\"\n  id?: string\n  /** Paints the item in the danger color (delete, cancel booking). */\n  destructive?: boolean\n  /** Renders the item as a link. */\n  href?: string\n  target?: string\n  /** Small trailing badge, e.g. a count or \"New\". */\n  badge?: React.ReactNode\n  onSelect?: () => void\n  /** Keep the menu open after selecting. */\n  keepOpen?: boolean\n}\nexport type DropdownMenuCheckbox = ItemBase & {\n  type: \"checkbox\"\n  id: string\n  /** Controlled state. */\n  checked?: boolean\n  defaultChecked?: boolean\n  onCheckedChange?: (checked: boolean) => void\n  /** Checkbox items keep the menu open by default; false closes it. */\n  keepOpen?: boolean\n}\nexport type DropdownMenuRadioOption = ItemBase & { value: string }\nexport type DropdownMenuRadioGroup = {\n  type: \"radio\"\n  id: string\n  /** Visible heading and accessible name of the group. */\n  label?: string\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  options: DropdownMenuRadioOption[]\n  /** Radio items close the menu by default; true keeps it open. */\n  keepOpen?: boolean\n}\nexport type DropdownMenuSub = ItemBase & { type: \"sub\"; id?: string; items: DropdownMenuItem[] }\nexport type DropdownMenuGroup = { type: \"group\"; label?: string; items: DropdownMenuItem[] }\nexport type DropdownMenuLabel = { type: \"label\"; label: string }\nexport type DropdownMenuSeparator = { type: \"separator\" }\nexport type DropdownMenuItem =\n  | DropdownMenuAction\n  | DropdownMenuCheckbox\n  | DropdownMenuRadioGroup\n  | DropdownMenuSub\n  | DropdownMenuGroup\n  | DropdownMenuLabel\n  | DropdownMenuSeparator\n\nexport type DropdownMenuLabels = {\n  /** Text of the built-in trigger. */\n  trigger: string\n  /** Accessible name of a context menu. */\n  contextMenu: string\n  /** Name of a modifier or special key on non-Mac keyboards (\"Ctrl\", \"Shift\", \"Alt\", \"Del\", \"Esc\", \"Enter\", \"Tab\", \"Space\"). */\n  keyName: (key: string) => string\n}\nconst DEFAULT_LABELS: DropdownMenuLabels = { trigger: \"Options\", contextMenu: \"Context menu\", keyName: (key) => key }\n\nexport type DropdownMenuProps = Omit<React.ComponentProps<\"div\">, \"children\" | \"onSelect\"> & {\n  items: DropdownMenuItem[]\n  /** menu opens from the trigger; context opens at the pointer on right-click (or long-press) inside children. */\n  mode?: \"menu\" | \"context\"\n  /** Your trigger element (usually a button). It gets the ARIA and handlers. Without it a built-in button is shown. */\n  trigger?: React.ReactElement\n  /** Text of the built-in trigger. */\n  label?: React.ReactNode\n  /** Context mode: the area that opens the menu on right-click. */\n  children?: React.ReactNode\n  /** Menu surface: default (popover), glass, neo, inverted or flat. */\n  variant?: DropdownMenuVariant\n  /** Accent for the highlight, check marks and bars. */\n  tone?: DropdownMenuTone\n  /** How the active item is painted: soft tint, solid tone fill, a bar at the start edge, or an outline. */\n  highlight?: DropdownMenuHighlight\n  size?: DropdownMenuSize\n  shadow?: DropdownMenuShadow\n  shape?: DropdownMenuShape\n  /** How menus open. stagger cascades the items in. Reduced motion turns it into a short fade. */\n  animation?: DropdownMenuAnimation\n  /** Preferred side; flips when there is no room. */\n  side?: DropdownMenuSide\n  /** Alignment along the side; start follows the reading direction. */\n  align?: DropdownMenuAlign\n  /** Gap between trigger and menu in px. */\n  sideOffset?: number\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Also run items' shortcuts as global hotkeys while the page is focused. */\n  bindShortcuts?: boolean\n  /** Arrow keys wrap from the last item to the first. */\n  loop?: boolean\n  disabled?: boolean\n  /** Class for every menu panel (root and sub-menus). */\n  menuClassName?: string\n  /** Names the menu. Defaults to the trigger's text (menu) or labels.contextMenu (context). */\n  \"aria-label\"?: string\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<DropdownMenuLabels>\n}\n\nconst CSS = `\n.pc-ddm{--pc-c:var(--primary);--pc-fg:var(--primary-foreground)}\n.pc-ddm[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.pc-ddm[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.pc-ddm[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.pc-ddm[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.pc-ddm[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .pc-ddm[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .pc-ddm[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .pc-ddm[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.pc-ddm{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.pc-ddm[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n\n.pc-ddm-trigger{background:var(--background);color:var(--foreground);border:1px solid var(--input);transition:border-color .15s,background-color .15s,box-shadow .15s}\n.pc-ddm-trigger:hover{background:color-mix(in oklab,var(--pc-c) 5%,var(--background));border-color:color-mix(in oklab,var(--pc-c) 30%,var(--input))}\n.pc-ddm-trigger:focus-visible{outline:none;border-color:color-mix(in oklab,var(--pc-c) 55%,var(--border));box-shadow:0 0 0 3px color-mix(in oklab,var(--pc-c) 32%,transparent)}\n.pc-ddm-trigger svg{transition:transform .2s var(--pc-ease-out);color:var(--muted-foreground)}\n.pc-ddm-trigger[aria-expanded=true] svg{transform:rotate(180deg)}\n\n.pc-ddm-surface{--pc-bg:var(--popover);--pc-text:var(--popover-foreground);--pc-sub:color-mix(in oklab,var(--muted-foreground) 85%,var(--popover-foreground));--pc-line:var(--border);position:relative;isolation:isolate;background:var(--pc-bg);color:var(--pc-text);border:1px solid var(--pc-line);outline:none}\n.pc-ddm[data-variant=glass] .pc-ddm-surface{--pc-bg:color-mix(in oklab,var(--popover) 70%,transparent);--pc-line:color-mix(in oklab,var(--foreground) 12%,transparent);-webkit-backdrop-filter:blur(18px) saturate(1.7);backdrop-filter:blur(18px) saturate(1.7)}\n.pc-ddm[data-variant=neo] .pc-ddm-surface{--pc-line:var(--foreground);border-width:2px;box-shadow:4px 4px 0 var(--foreground)!important}\n.pc-ddm[data-variant=inverted] .pc-ddm-surface{--pc-bg:var(--foreground);--pc-text:var(--background);--pc-sub:color-mix(in oklab,var(--background) 62%,var(--foreground));--pc-line:color-mix(in oklab,var(--background) 16%,var(--foreground))}\n.pc-ddm[data-variant=inverted][data-tone=neutral]{--pc-c:var(--background);--pc-fg:var(--foreground)}\n.pc-ddm[data-variant=flat] .pc-ddm-surface{--pc-bg:var(--card);--pc-text:var(--card-foreground);box-shadow:none!important}\n.pc-ddm[data-shadow=sm] .pc-ddm-surface{box-shadow:var(--pc-e1)}\n.pc-ddm[data-shadow=md] .pc-ddm-surface{box-shadow:var(--pc-e2)}\n.pc-ddm[data-shadow=lg] .pc-ddm-surface{box-shadow:var(--pc-e3)}\n.pc-ddm:is([data-variant=default],[data-variant=inverted]):not([data-shadow=none]) .pc-ddm-surface{border-color:transparent}\n/* One highlight glides between rows instead of each row lighting up on its own. */\n.pc-ddm-glide{position:absolute;top:0;left:var(--pc-gl-x,4px);right:var(--pc-gl-x,4px);height:var(--pc-gl-h,0);transform:translateY(var(--pc-gl-y,0));opacity:0;z-index:0;pointer-events:none;transition:transform 150ms var(--pc-ease-out),height 150ms var(--pc-ease-out),opacity 100ms ease}\n.pc-ddm-glide[data-on]{opacity:1}\n.pc-ddm-glide[data-destructive]{--pc-c:oklch(0.56 0.21 27)}\n.pc-ddm[data-hl=soft] .pc-ddm-glide{background:color-mix(in oklab,var(--pc-c) 12%,color-mix(in oklab,var(--pc-text) 5%,transparent))}\n.pc-ddm[data-hl=solid] .pc-ddm-glide{background:var(--pc-c)}\n.pc-ddm[data-hl=bar] .pc-ddm-glide{background:color-mix(in oklab,var(--pc-text) 6%,transparent)}\n.pc-ddm[data-hl=outline] .pc-ddm-glide{background:color-mix(in oklab,var(--pc-c) 6%,transparent);box-shadow:inset 0 0 0 1.5px color-mix(in oklab,var(--pc-c) 65%,transparent)}\n\n.pc-ddm-item{z-index:1;color:var(--pc-text);outline:none;cursor:default;text-decoration:none;-webkit-tap-highlight-color:transparent}\n.pc-ddm-item[data-disabled]{opacity:.45;cursor:not-allowed}\n.pc-ddm-sub,.pc-ddm-kbd{color:var(--pc-sub)}\n.pc-ddm-icon{color:var(--pc-sub)}\n.pc-ddm-ind{color:var(--pc-c)}\n.pc-ddm[data-tone=neutral] .pc-ddm-ind{color:var(--pc-text)}\n.pc-ddm[data-hl=solid] .pc-ddm-item:is(:focus,[data-open]){color:var(--pc-fg)}\n.pc-ddm[data-hl=solid] .pc-ddm-item:is(:focus,[data-open]) :is(.pc-ddm-sub,.pc-ddm-kbd,.pc-ddm-icon,.pc-ddm-ind){color:inherit}\n.pc-ddm[data-hl=solid] .pc-ddm-item:is(:focus,[data-open]) kbd{border-color:color-mix(in oklab,var(--pc-fg) 35%,transparent);background:transparent}\n.pc-ddm[data-hl=bar] .pc-ddm-item::before{content:\"\";position:absolute;inset-block:5px;inset-inline-start:0;width:3px;border-radius:3px;background:var(--pc-c);transform:scaleY(0);transition:transform .16s var(--pc-ease-out)}\n.pc-ddm[data-hl=bar] .pc-ddm-item:is(:focus,[data-open])::before{transform:scaleY(1)}\n.pc-ddm[data-hl=outline] .pc-ddm-item:is(:focus,[data-open]){background:color-mix(in oklab,var(--pc-c) 6%,transparent);box-shadow:inset 0 0 0 1.5px color-mix(in oklab,var(--pc-c) 65%,transparent)}\n.pc-ddm-item[data-destructive]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff;color:oklch(0.52 0.2 27)}\n.dark .pc-ddm-item[data-destructive]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25);color:oklch(0.72 0.17 25)}\n.pc-ddm[data-variant=inverted] .pc-ddm-item[data-destructive]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25);color:oklch(0.74 0.16 25)}\n.dark .pc-ddm[data-variant=inverted] .pc-ddm-item[data-destructive]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff;color:oklch(0.5 0.2 27)}\n.pc-ddm-item[data-destructive] .pc-ddm-icon{color:inherit}\n.pc-ddm-sep{background:var(--pc-line)}\n.pc-ddm-label{color:var(--pc-sub)}\n.pc-ddm-kbd kbd{font:inherit;font-size:.72rem;line-height:1.45;min-width:1.35em;padding:0 .3em;text-align:center;border-radius:4px;border:1px solid var(--pc-line);background:color-mix(in oklab,var(--pc-text) 4%,transparent)}\n.pc-ddm-badge{background:var(--pc-tint);color:var(--pc-ink)}\n.pc-ddm[data-variant=inverted] .pc-ddm-badge{background:color-mix(in oklab,var(--pc-text) 14%,transparent);color:var(--pc-text)}\n.pc-ddm-box{border:1.5px solid color-mix(in oklab,var(--pc-text) 28%,transparent);transition:background-color .12s,border-color .12s}\n.pc-ddm-item[aria-checked=true] .pc-ddm-box{background:var(--pc-c);border-color:var(--pc-c);color:var(--pc-fg)}\n.pc-ddm[data-hl=solid] .pc-ddm-item:is(:focus,[data-open])[aria-checked=true] .pc-ddm-box{background:var(--pc-fg);border-color:var(--pc-fg);color:var(--pc-c)}\n.pc-ddm-mark{transform:scale(.4);opacity:0;transition:transform .18s var(--pc-ease-spring),opacity .12s}\n.pc-ddm-item[aria-checked=true] .pc-ddm-mark{transform:scale(1);opacity:1}\n@media (prefers-reduced-motion:reduce){.pc-ddm-glide,.pc-ddm-trigger,.pc-ddm-trigger svg,.pc-ddm-item::before,.pc-ddm-mark,.pc-ddm-box{transition:none!important}}\n`\n\nconst SIZES = {\n  sm: { panel: \"min-w-44 p-1\", item: \"min-h-7 gap-2 px-2 py-1 text-xs [&_svg]:size-3.5\", label: \"px-2 pt-1.5 pb-1 text-[10px]\", trigger: \"h-8 px-2.5 text-xs gap-1.5\", ind: \"size-3.5\" },\n  md: { panel: \"min-w-52 p-1\", item: \"min-h-8 gap-2.5 px-2 py-1.5 text-sm [&_svg]:size-4\", label: \"px-2 pt-2 pb-1 text-[11px]\", trigger: \"h-10 px-3 text-sm gap-2\", ind: \"size-4\" },\n  lg: { panel: \"min-w-60 p-1.5\", item: \"min-h-10 gap-3 px-3 py-2 text-[15px] [&_svg]:size-[18px]\", label: \"px-3 pt-2 pb-1 text-xs\", trigger: \"h-11 px-4 text-base gap-2\", ind: \"size-[18px]\" },\n} satisfies Record<DropdownMenuSize, Record<string, string>>\nconst SHAPES: Record<DropdownMenuShape, { panel: string; item: string; trigger: string }> = {\n  square: { panel: \"rounded-none\", item: \"rounded-none\", trigger: \"rounded-none\" },\n  rounded: { panel: \"rounded-xl\", item: \"rounded-md\", trigger: \"rounded-lg\" },\n  pill: { panel: \"rounded-[1.25rem]\", item: \"rounded-xl\", trigger: \"rounded-full\" },\n}\n\n/* ---------- floating placement (flip + shift, no library) ---------- */\n\ntype Side = DropdownMenuSide\ntype Rect = { top: number; left: number; right: number; bottom: number; width: number; height: number }\ntype Placement = { x: number; y: number; side: Side; maxH: number }\ntype PlaceOpts = { side: Side; align: DropdownMenuAlign; offset: number; alignOffset: number; rtl: boolean }\n\nconst clamp = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(v, hi))\nconst FLIP: Record<Side, Side> = { top: \"bottom\", bottom: \"top\", left: \"right\", right: \"left\" }\n\nfunction place(a: Rect, w: number, h: number, o: PlaceOpts): Placement {\n  const pad = 8\n  const vw = document.documentElement.clientWidth\n  const vh = window.innerHeight\n  const room: Record<Side, number> = { top: a.top - o.offset - pad, bottom: vh - a.bottom - o.offset - pad, left: a.left - o.offset - pad, right: vw - a.right - o.offset - pad }\n  const vertical = (s: Side) => s === \"top\" || s === \"bottom\"\n  let side = o.side\n  if (room[side] < (vertical(side) ? h : w) && room[FLIP[side]] > room[side]) side = FLIP[side]\n  if (vertical(side)) {\n    const align = o.rtl && o.align !== \"center\" ? (o.align === \"start\" ? \"end\" : \"start\") : o.align\n    const maxH = Math.max(96, room[side])\n    const hh = Math.min(h, maxH)\n    const x = align === \"start\" ? a.left + o.alignOffset : align === \"end\" ? a.right - w - o.alignOffset : a.left + a.width / 2 - w / 2\n    return { x: clamp(x, pad, vw - pad - w), y: side === \"bottom\" ? a.bottom + o.offset : a.top - o.offset - hh, side, maxH }\n  }\n  const maxH = vh - pad * 2\n  const hh = Math.min(h, maxH)\n  const y = o.align === \"start\" ? a.top + o.alignOffset : o.align === \"end\" ? a.bottom - hh - o.alignOffset : a.top + a.height / 2 - hh / 2\n  const x = side === \"right\" ? a.right + o.offset : a.left - o.offset - w\n  return { x: clamp(x, pad, vw - pad - w), y: clamp(y, pad, vh - pad - hh), side, maxH }\n}\n\nfunction usePlacement(open: boolean, anchor: () => Rect | null, surface: React.RefObject<HTMLElement | null>, opts: PlaceOpts) {\n  const [p, setP] = React.useState<Placement | null>(null)\n  const live = React.useRef({ anchor, opts })\n  React.useLayoutEffect(() => {\n    live.current = { anchor, opts }\n  })\n  React.useLayoutEffect(() => {\n    if (!open) {\n      setP(null)\n      return\n    }\n    const update = () => {\n      const el = surface.current\n      const a = live.current.anchor()\n      if (!el || !a) return\n      const next = place(a, el.offsetWidth, el.scrollHeight + (el.offsetHeight - el.clientHeight), live.current.opts)\n      setP((prev) => (prev && Math.abs(prev.x - next.x) < 0.5 && Math.abs(prev.y - next.y) < 0.5 && prev.side === next.side && prev.maxH === next.maxH ? prev : next))\n    }\n    update()\n    let raf = 0\n    const schedule = () => {\n      cancelAnimationFrame(raf)\n      raf = requestAnimationFrame(update)\n    }\n    window.addEventListener(\"scroll\", schedule, true)\n    window.addEventListener(\"resize\", schedule)\n    const ro = typeof ResizeObserver === \"undefined\" ? null : new ResizeObserver(schedule)\n    if (surface.current) ro?.observe(surface.current)\n    return () => {\n      cancelAnimationFrame(raf)\n      window.removeEventListener(\"scroll\", schedule, true)\n      window.removeEventListener(\"resize\", schedule)\n      ro?.disconnect()\n    }\n    // Re-run once placed: the measured surface is swapped for the animated one, which needs observing too.\n  }, [open, surface, !!p])\n  return p\n}\n\n/* ---------- helpers ---------- */\n\nconst isEditable = (t: EventTarget | null) => t instanceof HTMLElement && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))\n\nconst MAC_SYMBOL: Record<string, string> = { mod: \"⌘\", cmd: \"⌘\", meta: \"⌘\", ctrl: \"⌃\", control: \"⌃\", shift: \"⇧\", alt: \"⌥\", option: \"⌥\", enter: \"↵\", backspace: \"⌫\", delete: \"⌦\", escape: \"Esc\", esc: \"Esc\", tab: \"⇥\", space: \"Space\" }\nconst PC_NAME: Record<string, string> = { mod: \"Ctrl\", ctrl: \"Ctrl\", control: \"Ctrl\", cmd: \"Win\", meta: \"Win\", shift: \"Shift\", alt: \"Alt\", option: \"Alt\", enter: \"Enter\", backspace: \"Backspace\", delete: \"Del\", escape: \"Esc\", esc: \"Esc\", tab: \"Tab\", space: \"Space\" }\nconst ARROWS: Record<string, string> = { arrowup: \"↑\", arrowdown: \"↓\", arrowleft: \"←\", arrowright: \"→\", up: \"↑\", down: \"↓\", left: \"←\", right: \"→\" }\nconst ARIA_KEY: Record<string, string> = { ctrl: \"Control\", control: \"Control\", cmd: \"Meta\", meta: \"Meta\", shift: \"Shift\", alt: \"Alt\", option: \"Alt\", esc: \"Escape\", escape: \"Escape\", del: \"Delete\", delete: \"Delete\", enter: \"Enter\", backspace: \"Backspace\", tab: \"Tab\", space: \"Space\" }\nconst EVENT_KEY: Record<string, string> = { esc: \"escape\", del: \"delete\", space: \" \", up: \"arrowup\", down: \"arrowdown\", left: \"arrowleft\", right: \"arrowright\" }\n\nconst splitKeys = (sc: string) =>\n  sc\n    .split(/\\+(?!$)/)\n    .map((k) => k.trim())\n    .filter(Boolean)\n\nfunction keyCaps(sc: string, mac: boolean, keyName: (k: string) => string) {\n  return splitKeys(sc).map((k) => {\n    const low = k.toLowerCase()\n    if (ARROWS[low]) return ARROWS[low]\n    if (mac && MAC_SYMBOL[low]) return MAC_SYMBOL[low]\n    if (!mac && PC_NAME[low]) return keyName(PC_NAME[low])\n    return k.length === 1 ? k.toUpperCase() : k\n  })\n}\n\nfunction ariaShortcut(sc: string, mac: boolean) {\n  return splitKeys(sc)\n    .map((k) => {\n      const low = k.toLowerCase()\n      if (low === \"mod\") return mac ? \"Meta\" : \"Control\"\n      return ARIA_KEY[low] ?? (k.length === 1 ? k.toUpperCase() : k)\n    })\n    .join(\"+\")\n}\n\nfunction matchesShortcut(e: KeyboardEvent, sc: string, mac: boolean) {\n  const want = { meta: false, ctrl: false, shift: false, alt: false }\n  let main = \"\"\n  for (const raw of splitKeys(sc)) {\n    const k = raw.toLowerCase()\n    if (k === \"mod\") want[mac ? \"meta\" : \"ctrl\"] = true\n    else if (k === \"cmd\" || k === \"meta\") want.meta = true\n    else if (k === \"ctrl\" || k === \"control\") want.ctrl = true\n    else if (k === \"shift\") want.shift = true\n    else if (k === \"alt\" || k === \"option\") want.alt = true\n    else main = EVENT_KEY[k] ?? k\n  }\n  if (!main || e.metaKey !== want.meta || e.ctrlKey !== want.ctrl || e.shiftKey !== want.shift || e.altKey !== want.alt) return false\n  const code = e.code.toLowerCase()\n  return e.key.toLowerCase() === main || (main.length === 1 && (code === \"key\" + main || code === \"digit\" + main))\n}\n\ntype Flat = { checks: Record<string, boolean>; radios: Record<string, string> }\nfunction collectState(items: DropdownMenuItem[], out: Flat = { checks: {}, radios: {} }): Flat {\n  for (const it of items) {\n    if (it.type === \"checkbox\") out.checks[it.id] = it.defaultChecked ?? false\n    else if (it.type === \"radio\") out.radios[it.id] = it.defaultValue ?? \"\"\n    else if (it.type === \"sub\" || it.type === \"group\") collectState(it.items, out)\n  }\n  return out\n}\n\nfunction hasIndicator(items: DropdownMenuItem[]): boolean {\n  return items.some((it) => it.type === \"checkbox\" || it.type === \"radio\" || (it.type === \"group\" && hasIndicator(it.items)))\n}\n\nfunction inTriangle(px: number, py: number, poly: [number, number][]) {\n  let inside = false\n  for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {\n    const [xi, yi] = poly[i]!\n    const [xj, yj] = poly[j]!\n    if (yi > py !== yj > py && px < ((xj - xi) * (py - yi)) / (yj - yi) + xi) inside = !inside\n  }\n  return inside\n}\n\nconst Chevron = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"m4 6 4 4 4-4\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n)\nconst ChevronEnd = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"m6 4 4 4-4 4\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n)\nconst Check = (p: React.SVGProps<SVGSVGElement>) => (\n  <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" {...p}>\n    <path d=\"M3.5 8.5 6.5 11.5 12.5 4.5\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n  </svg>\n)\n\n/* ---------- context shared by every panel ---------- */\n\ntype Ctx = {\n  owner: string\n  variant: DropdownMenuVariant\n  tone: DropdownMenuTone\n  highlight: DropdownMenuHighlight\n  size: DropdownMenuSize\n  shadow: DropdownMenuShadow\n  shape: DropdownMenuShape\n  animation: DropdownMenuAnimation\n  reduce: boolean\n  rtl: boolean\n  mac: boolean\n  loop: boolean\n  menuClassName?: string\n  l: DropdownMenuLabels\n  isChecked: (it: DropdownMenuCheckbox) => boolean\n  radioValue: (g: DropdownMenuRadioGroup) => string\n  toggle: (it: DropdownMenuCheckbox) => void\n  setRadio: (g: DropdownMenuRadioGroup, value: string) => void\n  closeAll: (returnFocus: boolean) => void\n  tabOut: (back: boolean) => void\n}\nconst MenuCtx = React.createContext<Ctx | null>(null)\n\ntype FocusMode = \"first\" | \"last\" | \"panel\"\n\ntype PanelProps = {\n  items: DropdownMenuItem[]\n  id: string\n  level: number\n  anchor: () => Rect | null\n  side: Side\n  align: DropdownMenuAlign\n  offset: number\n  alignOffset: number\n  focus: FocusMode\n  focusNonce: number\n  /** Called to close this panel (sub-menus) or the whole menu (root). */\n  onClose: (returnFocus: boolean) => void\n  onPointerEnterPanel?: () => void\n  labelledBy?: string\n  ariaLabel?: string\n  /** Point-anchored context menus grow from the corner instead of the side. */\n  fromPoint?: boolean\n}\n\nfunction Panel({ items, id, level, anchor, side, align, offset, alignOffset, focus, focusNonce, onClose, onPointerEnterPanel, labelledBy, ariaLabel, fromPoint }: PanelProps) {\n  const maybe = React.useContext(MenuCtx)\n  if (!maybe) throw new Error(\"DropdownMenu panel rendered outside DropdownMenu\")\n  const ctx = maybe\n  const present = useIsPresent()\n  const surface = React.useRef<HTMLDivElement>(null)\n  const p = usePlacement(true, anchor, surface, { side, align, offset, alignOffset, rtl: ctx.rtl })\n  const [sub, setSub] = React.useState<{ key: string; el: HTMLElement; focus: FocusMode; nonce: number } | null>(null)\n  const timers = React.useRef<{ open?: number; close?: number }>({})\n  const grace = React.useRef<{ poly: [number, number][]; until: number } | null>(null)\n  const typed = React.useRef({ text: \"\", at: 0 })\n  const s = SIZES[ctx.size]\n  const sh = SHAPES[ctx.shape]\n  const inset = hasIndicator(items)\n\n  const list = () => (surface.current ? Array.from(surface.current.querySelectorAll<HTMLElement>(\"[data-pc-ddm-item]:not([data-disabled])\")) : [])\n\n  // Focus once the panel is placed (hidden elements can't take focus) and whenever the parent asks again.\n  React.useEffect(() => {\n    if (!p) return\n    const items = list()\n    // A sub-menu opened by hover leaves focus on its parent item, so → and the pointer keep working there.\n    const target = focus === \"first\" ? items[0] : focus === \"last\" ? items[items.length - 1] : level === 0 ? surface.current : null\n    target?.focus({ preventScroll: true })\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [!!p, focus, focusNonce])\n\n  React.useEffect(\n    () => () => {\n      window.clearTimeout(timers.current.open)\n      window.clearTimeout(timers.current.close)\n    },\n    [],\n  )\n\n  const openSub = (key: string, el: HTMLElement, f: FocusMode) => {\n    window.clearTimeout(timers.current.open)\n    window.clearTimeout(timers.current.close)\n    setSub((cur) => ({ key, el, focus: f, nonce: (cur?.nonce ?? 0) + 1 }))\n  }\n  const closeSub = (returnFocus: boolean) => {\n    window.clearTimeout(timers.current.close)\n    setSub((cur) => {\n      if (cur && returnFocus) cur.el.focus({ preventScroll: true })\n      return null\n    })\n  }\n\n  const move = (to: \"next\" | \"prev\" | \"first\" | \"last\") => {\n    const items = list()\n    if (!items.length) return\n    const cur = items.indexOf(document.activeElement as HTMLElement)\n    let i = to === \"first\" ? 0 : to === \"last\" ? items.length - 1 : cur < 0 ? (to === \"next\" ? 0 : items.length - 1) : cur + (to === \"next\" ? 1 : -1)\n    if (i >= items.length) i = ctx.loop ? 0 : items.length - 1\n    if (i < 0) i = ctx.loop ? items.length - 1 : 0\n    items[i]!.focus({ preventScroll: false })\n  }\n\n  const typeAhead = (key: string) => {\n    const now = Date.now()\n    const t = typed.current\n    t.text = now - t.at > 500 ? key : t.text + key\n    t.at = now\n    const q = t.text.toLowerCase()\n    const items = list()\n    const cur = items.indexOf(document.activeElement as HTMLElement)\n    const start = t.text.length === 1 ? cur + 1 : Math.max(cur, 0)\n    for (let k = 0; k < items.length; k++) {\n      const el = items[(start + k) % items.length]!\n      if ((el.dataset.label ?? \"\").toLowerCase().startsWith(q)) {\n        el.focus()\n        return\n      }\n    }\n  }\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    // Key events from a sub-menu bubble here through the React tree; only handle our own DOM.\n    if (!surface.current?.contains(e.target as Node)) return\n    const target = e.target as HTMLElement\n    const forward = ctx.rtl ? \"ArrowLeft\" : \"ArrowRight\"\n    const back = ctx.rtl ? \"ArrowRight\" : \"ArrowLeft\"\n    switch (e.key) {\n      case \"ArrowDown\":\n        e.preventDefault()\n        move(\"next\")\n        break\n      case \"ArrowUp\":\n        e.preventDefault()\n        move(\"prev\")\n        break\n      case \"Home\":\n      case \"PageUp\":\n        e.preventDefault()\n        move(\"first\")\n        break\n      case \"End\":\n      case \"PageDown\":\n        e.preventDefault()\n        move(\"last\")\n        break\n      case forward:\n        if (target.dataset.subKey) {\n          e.preventDefault()\n          openSub(target.dataset.subKey, target, \"first\")\n        }\n        break\n      case back:\n        if (level > 0) {\n          e.preventDefault()\n          onClose(true)\n        }\n        break\n      case \"Enter\":\n      case \" \":\n        if (!target.hasAttribute(\"data-pc-ddm-item\")) {\n          e.preventDefault()\n          break\n        }\n        // Links follow on Enter natively; everything else is clicked here.\n        if (e.key === \"Enter\" && target.tagName === \"A\") break\n        e.preventDefault()\n        target.click()\n        break\n      case \"Escape\":\n        e.preventDefault()\n        e.stopPropagation()\n        if (level > 0) onClose(true)\n        else ctx.closeAll(true)\n        break\n      case \"Tab\":\n        // APG: Tab closes the menu and moves on from the trigger, as if the menu had not been there.\n        e.preventDefault()\n        ctx.tabOut(e.shiftKey)\n        break\n      default:\n        if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {\n          e.preventDefault()\n          typeAhead(e.key)\n        }\n    }\n  }\n\n  const hover = (e: React.PointerEvent<HTMLElement>, el: HTMLElement, subKey?: string, disabled?: boolean) => {\n    if (e.pointerType !== \"mouse\" || !surface.current?.contains(el)) return\n    const g = grace.current\n    if (g && Date.now() < g.until && inTriangle(e.clientX, e.clientY, g.poly)) return\n    grace.current = null\n    if (disabled) {\n      if (document.activeElement !== surface.current) surface.current?.focus({ preventScroll: true })\n    } else if (document.activeElement !== el) el.focus({ preventScroll: true })\n    window.clearTimeout(timers.current.open)\n    if (subKey) {\n      if (sub?.key === subKey) {\n        window.clearTimeout(timers.current.close)\n        return\n      }\n      timers.current.open = window.setTimeout(() => openSub(subKey, el, \"panel\"), 110)\n    } else if (sub) {\n      window.clearTimeout(timers.current.close)\n      timers.current.close = window.setTimeout(() => setSub(null), 120)\n    }\n  }\n\n  const leaveSubTrigger = (e: React.PointerEvent<HTMLElement>, key: string) => {\n    window.clearTimeout(timers.current.open)\n    if (e.pointerType !== \"mouse\" || sub?.key !== key) return\n    const panel = document.getElementById(`${id}-${key}`)\n    if (!panel) return\n    const r = panel.getBoundingClientRect()\n    const toRight = r.left >= e.clientX\n    const edge = toRight ? r.left : r.right\n    const x = e.clientX + (toRight ? -4 : 4)\n    grace.current = { poly: [[x, e.clientY], [edge, r.top - 4], [edge, r.bottom + 4]], until: Date.now() + 320 }\n  }\n\n  let order = 0\n  const stagger = ctx.animation === \"stagger\" && !ctx.reduce\n  const itemMotion = () => {\n    const i = order++\n    return stagger\n      ? { initial: { opacity: 0, x: ctx.rtl ? 6 : -6 }, animate: { opacity: 1, x: 0 }, transition: { delay: 0.04 + Math.min(i, 12) * 0.024, duration: 0.2, ease: easing.out } }\n      : { initial: false as const }\n  }\n\n  const row = (it: ItemBase, extra: React.ReactNode, indicator: React.ReactNode, trailing: React.ReactNode) => (\n    <>\n      {inset && <span className={cn(\"pc-ddm-ind inline-flex shrink-0 items-center justify-center\", s.ind)}>{indicator}</span>}\n      {it.icon && <span className=\"pc-ddm-icon inline-flex shrink-0\">{it.icon}</span>}\n      <span className=\"flex min-w-0 flex-1 flex-col\">\n        <span className=\"truncate\">{it.label}</span>\n        {it.description && <span className=\"pc-ddm-sub truncate text-[0.85em] leading-snug\">{it.description}</span>}\n      </span>\n      {extra}\n      {it.shortcut && (\n        <span className=\"pc-ddm-kbd ms-auto inline-flex shrink-0 items-center gap-0.5 ps-3\" dir=\"ltr\" aria-hidden=\"true\">\n          {keyCaps(it.shortcut, ctx.mac, ctx.l.keyName).map((k, i) => (\n            <kbd key={i}>{k}</kbd>\n          ))}\n        </span>\n      )}\n      {trailing}\n    </>\n  )\n\n  const itemClass = cn(\"pc-press pc-press-soft pc-ddm-item relative flex w-full items-center text-start select-none\", s.item, sh.item)\n\n  const render = (list: DropdownMenuItem[], path: string): React.ReactNode =>\n    list.map((it, idx) => {\n      const key = `${path}${idx}`\n      if (it.type === \"separator\") return <div key={key} role=\"separator\" className=\"pc-ddm-sep -mx-1 my-1 h-px\" />\n      if (it.type === \"label\")\n        return (\n          <div key={key} role=\"presentation\" className={cn(\"pc-ddm-label font-medium tracking-wide uppercase\", s.label)}>\n            {it.label}\n          </div>\n        )\n      if (it.type === \"group\" || it.type === \"radio\") {\n        const labelId = `${id}-g${key}`\n        const inner =\n          it.type === \"group\"\n            ? render(it.items, key + \".\")\n            : it.options.map((o) => {\n                const on = ctx.radioValue(it) === o.value\n                return (\n                  <motion.div\n                    key={o.value}\n                    {...itemMotion()}\n                    role=\"menuitemradio\"\n                    aria-checked={on}\n                    aria-disabled={o.disabled || undefined}\n                    aria-keyshortcuts={o.shortcut ? ariaShortcut(o.shortcut, ctx.mac) : undefined}\n                    tabIndex={-1}\n                    data-pc-ddm-item=\"\"\n                    data-label={o.label}\n                    data-disabled={o.disabled ? \"\" : undefined}\n                    className={itemClass}\n                    onPointerMove={(e) => hover(e, e.currentTarget, undefined, o.disabled)}\n                    onClick={() => {\n                      if (o.disabled) return\n                      ctx.setRadio(it, o.value)\n                      if (!it.keepOpen) ctx.closeAll(true)\n                    }}\n                  >\n                    {row(o, null, <span className=\"pc-ddm-mark size-[0.45em] min-h-1.5 min-w-1.5 rounded-full bg-current\" />, null)}\n                  </motion.div>\n                )\n              })\n        return (\n          <div key={key} role=\"group\" aria-labelledby={it.label ? labelId : undefined}>\n            {it.label && (\n              <div id={labelId} role=\"presentation\" className={cn(\"pc-ddm-label font-medium tracking-wide uppercase\", s.label)}>\n                {it.label}\n              </div>\n            )}\n            {inner}\n          </div>\n        )\n      }\n      if (it.type === \"checkbox\") {\n        const on = ctx.isChecked(it)\n        return (\n          <motion.div\n            key={key}\n            {...itemMotion()}\n            role=\"menuitemcheckbox\"\n            aria-checked={on}\n            aria-disabled={it.disabled || undefined}\n            aria-keyshortcuts={it.shortcut ? ariaShortcut(it.shortcut, ctx.mac) : undefined}\n            tabIndex={-1}\n            data-pc-ddm-item=\"\"\n            data-label={it.label}\n            data-disabled={it.disabled ? \"\" : undefined}\n            className={itemClass}\n            onPointerMove={(e) => hover(e, e.currentTarget, undefined, it.disabled)}\n            onClick={() => {\n              if (it.disabled) return\n              ctx.toggle(it)\n              if (it.keepOpen === false) ctx.closeAll(true)\n            }}\n          >\n            {row(\n              it,\n              null,\n              <span className=\"pc-ddm-box grid size-[1em] place-items-center rounded-[4px]\">\n                <Check className=\"pc-ddm-mark !size-[0.75em]\" />\n              </span>,\n              null,\n            )}\n          </motion.div>\n        )\n      }\n      if (it.type === \"sub\") {\n        const subKey = it.id ?? key\n        const open = sub?.key === subKey\n        return (\n          <motion.div\n            key={key}\n            {...itemMotion()}\n            role=\"menuitem\"\n            aria-haspopup=\"menu\"\n            aria-expanded={open}\n            aria-controls={open ? `${id}-${subKey}` : undefined}\n            aria-disabled={it.disabled || undefined}\n            tabIndex={-1}\n            data-pc-ddm-item=\"\"\n            data-sub-key={it.disabled ? undefined : subKey}\n            data-label={it.label}\n            data-open={open ? \"\" : undefined}\n            data-disabled={it.disabled ? \"\" : undefined}\n            className={itemClass}\n            onPointerMove={(e) => hover(e, e.currentTarget, it.disabled ? undefined : subKey, it.disabled)}\n            onPointerLeave={(e) => leaveSubTrigger(e, subKey)}\n            onClick={(e) => !it.disabled && openSub(subKey, e.currentTarget, e.detail === 0 ? \"first\" : \"panel\")}\n          >\n            {row(it, null, null, <ChevronEnd className=\"pc-ddm-icon ms-auto shrink-0 rtl:rotate-180\" />)}\n          </motion.div>\n        )\n      }\n      const a = it\n      const common = {\n        role: \"menuitem\",\n        tabIndex: -1,\n        \"aria-disabled\": a.disabled || undefined,\n        \"aria-keyshortcuts\": a.shortcut ? ariaShortcut(a.shortcut, ctx.mac) : undefined,\n        \"data-pc-ddm-item\": \"\",\n        \"data-label\": a.label,\n        \"data-disabled\": a.disabled ? \"\" : undefined,\n        \"data-destructive\": a.destructive ? \"\" : undefined,\n        className: itemClass,\n        onPointerMove: (e: React.PointerEvent<HTMLElement>) => hover(e, e.currentTarget, undefined, a.disabled),\n        onClick: (e: React.MouseEvent<HTMLElement>) => {\n          if (a.disabled) {\n            e.preventDefault()\n            return\n          }\n          a.onSelect?.()\n          if (!a.keepOpen) ctx.closeAll(true)\n        },\n      }\n      const badge = a.badge != null && <span className=\"pc-ddm-badge shrink-0 rounded-full px-1.5 text-[0.75em] leading-[1.6] font-medium\">{a.badge}</span>\n      return a.href ? (\n        <motion.a key={key} {...itemMotion()} {...common} href={a.disabled ? undefined : a.href} target={a.target} rel={a.target === \"_blank\" ? \"noreferrer\" : undefined}>\n          {row(a, badge, null, null)}\n        </motion.a>\n      ) : (\n        <motion.div key={key} {...itemMotion()} {...common}>\n          {row(a, badge, null, null)}\n        </motion.div>\n      )\n    })\n\n  const subItem = sub ? findSub(items, sub.key) : null\n  const placed = p ?? { x: 0, y: 0, side, maxH: 9999 }\n  const origin = fromPoint\n    ? `${placed.side === \"top\" ? \"bottom\" : \"top\"} ${ctx.rtl ? \"right\" : \"left\"}`\n    : placed.side === \"bottom\"\n      ? \"top\"\n      : placed.side === \"top\"\n        ? \"bottom\"\n        : placed.side === \"right\"\n          ? \"left\"\n          : \"right\"\n  const dx = placed.side === \"right\" ? -8 : placed.side === \"left\" ? 8 : 0\n  const dy = placed.side === \"bottom\" ? -8 : placed.side === \"top\" ? 8 : 0\n  const anim = ctx.animation\n  // Opened from the keyboard: no entrance at all. Frequent actions stay quiet.\n  const [byKey] = React.useState(() => typeof document !== \"undefined\" && !!document.activeElement?.matches(\":focus-visible\"))\n  const glide = React.useRef<HTMLDivElement>(null)\n  const moveGlide = (e: React.FocusEvent<HTMLDivElement>) => {\n    const g = glide.current\n    const t = e.target as HTMLElement\n    if (!g) return\n    if (!t.matches(\"[data-pc-ddm-item]\")) {\n      if (t === surface.current) delete g.dataset.on\n      return\n    }\n    // From hidden it appears in place; only a move between rows slides.\n    if (!g.dataset.on) g.style.transition = \"none\"\n    g.style.setProperty(\"--pc-gl-y\", `${t.offsetTop}px`)\n    g.style.setProperty(\"--pc-gl-h\", `${t.offsetHeight}px`)\n    g.style.setProperty(\"--pc-gl-x\", `${t.offsetLeft}px`)\n    if (t.hasAttribute(\"data-destructive\")) g.dataset.destructive = \"\"\n    else delete g.dataset.destructive\n    g.dataset.on = \"\"\n    void g.offsetHeight\n    g.style.transition = \"\"\n  }\n  const motionProps = ctx.reduce\n    ? { initial: { opacity: 0 }, animate: { opacity: 1 } }\n    : anim === \"none\"\n      ? { initial: false as const, animate: { opacity: 1 } }\n      : anim === \"fade\"\n        ? { initial: { opacity: 0 }, animate: { opacity: 1 } }\n        : anim === \"slide\"\n          ? { initial: { opacity: 0, x: dx, y: dy }, animate: { opacity: 1, x: 0, y: 0 } }\n          : anim === \"stagger\"\n            ? { initial: { opacity: 0, scale: 0.98 }, animate: { opacity: 1, scale: 1 } }\n            : { initial: { opacity: 0, scale: 0.96 }, animate: { opacity: 1, scale: 1 } }\n  const t: Transition = ctx.reduce ? { duration: 0.1 } : anim === \"none\" || byKey ? { duration: 0 } : { duration: 0.15, ease: easing.out }\n  const exitT: Transition = anim === \"none\" ? { duration: 0 } : { duration: 0.1, ease: easing.out }\n\n  const body = render(items, \"\")\n  const surfaceClass = cn(\"pc-ddm-surface overflow-x-hidden overflow-y-auto overscroll-contain\", s.panel, sh.panel, ctx.menuClassName)\n  const surfaceProps = {\n    id,\n    role: \"menu\",\n    tabIndex: -1,\n    \"aria-orientation\": \"vertical\" as const,\n    \"aria-labelledby\": labelledBy,\n    \"aria-label\": labelledBy ? undefined : ariaLabel,\n    onKeyDown,\n    onFocus: moveGlide,\n    onPointerEnter: onPointerEnterPanel,\n    onPointerLeave: (e: React.PointerEvent<HTMLDivElement>) => {\n      if (e.pointerType === \"mouse\" && !sub && surface.current?.contains(document.activeElement)) surface.current.focus({ preventScroll: true })\n    },\n    onContextMenu: (e: React.MouseEvent) => e.preventDefault(),\n    style: { maxHeight: placed.maxH, transformOrigin: origin },\n  }\n\n  return (\n    <div\n      data-pc-ddm-owner={ctx.owner}\n      data-variant={ctx.variant}\n      data-tone={ctx.tone}\n      data-hl={ctx.highlight}\n      data-shadow={ctx.variant === \"neo\" || ctx.variant === \"flat\" ? \"none\" : ctx.shadow}\n      data-side={placed.side}\n      className=\"pc-ddm fixed z-50\"\n      style={{ left: placed.x, top: placed.y, visibility: p ? undefined : \"hidden\" }}\n    >\n      {p ? (\n        <motion.div ref={surface} {...surfaceProps} {...motionProps} exit={{ opacity: 0, transition: exitT }} transition={t} className={surfaceClass}>\n          <div ref={glide} aria-hidden=\"true\" className={cn(\"pc-ddm-glide\", sh.item)} />\n          {body}\n        </motion.div>\n      ) : (\n        <div ref={surface} {...surfaceProps} className={surfaceClass}>\n          {body}\n        </div>\n      )}\n      {createPortal(\n        <AnimatePresence>\n          {present && sub && subItem && (\n            <Panel\n              key={sub.key}\n              items={subItem.items}\n              id={`${id}-${sub.key}`}\n              level={level + 1}\n              anchor={() => (sub.el.isConnected ? sub.el.getBoundingClientRect() : null)}\n              side={ctx.rtl ? \"left\" : \"right\"}\n              align=\"start\"\n              offset={4}\n              alignOffset={ctx.size === \"lg\" ? -7 : -5}\n              focus={sub.focus}\n              focusNonce={sub.nonce}\n              labelledBy={undefined}\n              ariaLabel={subItem.label}\n              onClose={closeSub}\n              onPointerEnterPanel={() => {\n                window.clearTimeout(timers.current.close)\n                grace.current = null\n              }}\n            />\n          )}\n        </AnimatePresence>,\n        document.body,\n      )}\n    </div>\n  )\n}\n\nfunction findSub(items: DropdownMenuItem[], key: string, path = \"\"): DropdownMenuSub | null {\n  for (let i = 0; i < items.length; i++) {\n    const it = items[i]!\n    const k = `${path}${i}`\n    if (it.type === \"sub\" && (it.id ?? k) === key) return it\n    if (it.type === \"group\") {\n      const found = findSub(it.items, key, k + \".\")\n      if (found) return found\n    }\n  }\n  return null\n}\n\nfunction walk(items: DropdownMenuItem[], fn: (it: DropdownMenuItem, group?: DropdownMenuRadioGroup) => void) {\n  for (const it of items) {\n    fn(it)\n    if (it.type === \"sub\" || it.type === \"group\") walk(it.items, fn)\n    if (it.type === \"radio\") for (const o of it.options) fn({ ...o, type: \"item\" }, it)\n  }\n}\n\n/* ---------- root ---------- */\n\nexport function DropdownMenu({\n  items,\n  mode = \"menu\",\n  trigger,\n  label,\n  children,\n  variant = \"default\",\n  tone = \"primary\",\n  highlight = \"soft\",\n  size = \"md\",\n  shadow = \"md\",\n  shape = \"rounded\",\n  animation = \"scale\",\n  side = \"bottom\",\n  align = \"start\",\n  sideOffset = 6,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  bindShortcuts,\n  loop = true,\n  disabled,\n  menuClassName,\n  \"aria-label\": ariaLabel,\n  labels,\n  className,\n  ...rest\n}: DropdownMenuProps) {\n  const l = useLabels(\"dropdown-menu\", DEFAULT_LABELS, labels)\n  const prefersReduced = useReducedMotion()\n  const [mounted, setMounted] = React.useState(false)\n  const [mac, setMac] = React.useState(false)\n  React.useEffect(() => {\n    setMounted(true)\n    setMac(/Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent))\n  }, [])\n  const reduce = mounted && !!prefersReduced\n  const uid = React.useId()\n  const menuId = uid + \"-menu\"\n  const triggerId = uid + \"-trigger\"\n\n  const [openInner, setOpenInner] = React.useState(defaultOpen)\n  const open = (openProp ?? openInner) && !disabled\n  const [focus, setFocus] = React.useState<{ mode: FocusMode; nonce: number }>({ mode: \"panel\", nonce: 0 })\n  const [point, setPoint] = React.useState<{ x: number; y: number } | null>(null)\n  const [rtl, setRtl] = React.useState(false)\n  const root = React.useRef<HTMLDivElement>(null)\n  const triggerEl = React.useRef<HTMLElement | null>(null)\n  const prevFocus = React.useRef<HTMLElement | null>(null)\n  const press = React.useRef<{ timer: number; x: number; y: number } | null>(null)\n  const lastDown = React.useRef(0)\n\n  const [state, setState] = React.useState<Flat>(() => collectState(items))\n  const isChecked = (it: DropdownMenuCheckbox) => it.checked ?? state.checks[it.id] ?? false\n  const radioValue = (g: DropdownMenuRadioGroup) => g.value ?? state.radios[g.id] ?? \"\"\n  const toggle = (it: DropdownMenuCheckbox) => {\n    const next = !isChecked(it)\n    if (it.checked === undefined) setState((s) => ({ ...s, checks: { ...s.checks, [it.id]: next } }))\n    it.onCheckedChange?.(next)\n  }\n  const setRadio = (g: DropdownMenuRadioGroup, value: string) => {\n    if (g.value === undefined) setState((s) => ({ ...s, radios: { ...s.radios, [g.id]: value } }))\n    if (radioValue(g) !== value) g.onValueChange?.(value)\n  }\n\n  const setOpen = (o: boolean) => {\n    if (openProp === undefined) setOpenInner(o)\n    onOpenChange?.(o)\n  }\n  const readDir = (el: Element | null) => setRtl(!!el && getComputedStyle(el).direction === \"rtl\")\n  const show = (f: FocusMode) => {\n    if (disabled) return\n    prevFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null\n    readDir(mode === \"menu\" ? triggerEl.current : root.current)\n    setFocus((cur) => ({ mode: f, nonce: cur.nonce + 1 }))\n    if (!open) setOpen(true)\n  }\n  const closeAll = React.useCallback(\n    (returnFocus: boolean) => {\n      setOpen(false)\n      if (!returnFocus) return\n      const el = mode === \"menu\" ? triggerEl.current : prevFocus.current\n      el?.focus({ preventScroll: true })\n    },\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [mode, openProp, onOpenChange],\n  )\n\n  const tabOut = (back: boolean) => {\n    const from = mode === \"menu\" ? triggerEl.current : prevFocus.current\n    closeAll(true)\n    if (!from) return\n    const all = Array.from(document.querySelectorAll<HTMLElement>(\"a[href],button,input,select,textarea,[tabindex]\")).filter(\n      (el) => el.tabIndex >= 0 && !(el as HTMLButtonElement).disabled && el.getClientRects().length > 0 && !el.closest(`[data-pc-ddm-owner=\"${uid}\"]`),\n    )\n    const i = all.indexOf(from)\n    if (i >= 0) all[i + (back ? -1 : 1)]?.focus()\n  }\n\n  // A controlled or defaultOpen menu still needs the reading direction.\n  React.useEffect(() => {\n    if (open) readDir(mode === \"menu\" ? triggerEl.current : root.current)\n  }, [open, mode])\n\n  // Click outside closes (every panel of this menu carries the owner id).\n  React.useEffect(() => {\n    if (!open) return\n    const onDown = (e: PointerEvent) => {\n      const t = e.target as Element | null\n      if (t?.closest?.(`[data-pc-ddm-owner=\"${uid}\"]`)) return\n      if (mode === \"menu\" && triggerEl.current?.contains(t)) return\n      if (mode === \"context\" && e.button === 2 && root.current?.contains(t)) return\n      closeAll(false)\n    }\n    document.addEventListener(\"pointerdown\", onDown, true)\n    return () => document.removeEventListener(\"pointerdown\", onDown, true)\n  }, [open, mode, uid, closeAll])\n\n  // Optional global hotkeys from the items' shortcuts.\n  const live = React.useRef({ items, mac, isChecked, toggle, setRadio, open, closeAll })\n  React.useLayoutEffect(() => {\n    live.current = { items, mac, isChecked, toggle, setRadio, open, closeAll }\n  })\n  React.useEffect(() => {\n    if (!bindShortcuts || disabled) return\n    const onKey = (e: KeyboardEvent) => {\n      if (e.defaultPrevented || e.repeat) return\n      if (isEditable(e.target) && !e.metaKey && !e.ctrlKey && !e.altKey) return\n      const c = live.current\n      let hit = false\n      walk(c.items, (it, group) => {\n        if (hit || !(\"shortcut\" in it) || !it.shortcut || it.disabled || !matchesShortcut(e, it.shortcut, c.mac)) return\n        if (it.type === \"sub\") return\n        hit = true\n        e.preventDefault()\n        if (group && \"value\" in it) c.setRadio(group, it.value as string)\n        else if (it.type === \"checkbox\") c.toggle(it)\n        else if (it.type === \"item\" || it.type === undefined) (it as DropdownMenuAction).onSelect?.()\n        if (c.open) c.closeAll(false)\n      })\n    }\n    window.addEventListener(\"keydown\", onKey)\n    return () => window.removeEventListener(\"keydown\", onKey)\n  }, [bindShortcuts, disabled])\n\n  const ctx: Ctx = { owner: uid, variant, tone, highlight, size, shadow, shape, animation, reduce, rtl, mac, loop, menuClassName, l, isChecked, radioValue, toggle, setRadio, closeAll, tabOut }\n\n  const anchor = (): Rect | null => {\n    if (mode === \"context\") {\n      if (point) return { left: point.x, right: point.x, top: point.y, bottom: point.y, width: 0, height: 0 }\n      return root.current?.getBoundingClientRect() ?? null\n    }\n    return triggerEl.current?.getBoundingClientRect() ?? null\n  }\n\n  const panel =\n    mounted &&\n    createPortal(\n      <MenuCtx.Provider value={ctx}>\n        <AnimatePresence>\n          {open && (\n            <Panel\n              key={point ? `${point.x},${point.y}` : \"root\"}\n              items={items}\n              id={menuId}\n              level={0}\n              anchor={anchor}\n              side={mode === \"context\" ? \"bottom\" : side}\n              align={mode === \"context\" ? \"start\" : align}\n              offset={mode === \"context\" ? 2 : sideOffset}\n              alignOffset={0}\n              focus={focus.mode}\n              focusNonce={focus.nonce}\n              onClose={closeAll}\n              labelledBy={mode === \"menu\" && !ariaLabel ? triggerId : undefined}\n              ariaLabel={ariaLabel ?? (mode === \"context\" ? l.contextMenu : undefined)}\n              fromPoint={mode === \"context\" && !!point}\n            />\n          )}\n        </AnimatePresence>\n      </MenuCtx.Provider>,\n      document.body,\n    )\n\n  const style = (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-dropdown-menu\" precedence=\"default\">\n        {CSS}\n      </style>\n    </>\n  )\n\n  if (mode === \"context\") {\n    return (\n      <>\n        {style}\n        <div\n          {...rest}\n          ref={root}\n          data-slot=\"dropdown-menu\"\n          data-tone={tone}\n          data-state={open ? \"open\" : \"closed\"}\n          className={cn(\"pc-ddm\", className)}\n          onContextMenu={(e) => {\n            rest.onContextMenu?.(e)\n            // Right-clicks inside the portaled menu bubble here through React; ignore them.\n            if (e.defaultPrevented || disabled || !root.current?.contains(e.target as Node)) return\n            e.preventDefault()\n            if (press.current) window.clearTimeout(press.current.timer)\n            press.current = null\n            // Shift+F10 / the Menu key fire contextmenu without a pointer press just before it.\n            const keyboard = Date.now() - lastDown.current > 1500 || (e.clientX === 0 && e.clientY === 0)\n            if (keyboard) {\n              const r = (e.target as HTMLElement).getBoundingClientRect()\n              setPoint({ x: ctx.rtl ? r.right : r.left, y: r.bottom })\n            } else setPoint({ x: e.clientX, y: e.clientY })\n            show(keyboard ? \"first\" : \"panel\")\n          }}\n          onPointerDown={(e) => {\n            rest.onPointerDown?.(e)\n            if (!root.current?.contains(e.target as Node)) return\n            lastDown.current = Date.now()\n            if (e.pointerType !== \"touch\" || disabled) return\n            const { clientX: x, clientY: y } = e\n            press.current = {\n              x,\n              y,\n              timer: window.setTimeout(() => {\n                setPoint({ x, y })\n                show(\"panel\")\n                press.current = null\n              }, 550),\n            }\n          }}\n          onPointerMove={(e) => {\n            rest.onPointerMove?.(e)\n            const pr = press.current\n            if (pr && Math.hypot(e.clientX - pr.x, e.clientY - pr.y) > 8) {\n              window.clearTimeout(pr.timer)\n              press.current = null\n            }\n          }}\n          onPointerUp={(e) => {\n            rest.onPointerUp?.(e)\n            if (press.current) window.clearTimeout(press.current.timer)\n            press.current = null\n          }}\n        >\n          {children}\n        </div>\n        {panel}\n      </>\n    )\n  }\n\n  const triggerProps = {\n    id: triggerId,\n    \"aria-haspopup\": \"menu\" as const,\n    \"aria-expanded\": open,\n    \"aria-controls\": open ? menuId : undefined,\n    \"data-state\": open ? \"open\" : \"closed\",\n  }\n  const onTriggerClick = (e: React.MouseEvent<HTMLElement>) => {\n    if (open) closeAll(false)\n    else show(e.detail === 0 ? \"first\" : \"panel\")\n  }\n  const onTriggerKey = (e: React.KeyboardEvent<HTMLElement>) => {\n    if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n      e.preventDefault()\n      show(e.key === \"ArrowDown\" ? \"first\" : \"last\")\n    }\n  }\n\n  let triggerNode: React.ReactNode\n  if (trigger && React.isValidElement(trigger)) {\n    const tp = trigger.props as {\n      ref?: React.Ref<HTMLElement>\n      onClick?: (e: React.MouseEvent<HTMLElement>) => void\n      onKeyDown?: (e: React.KeyboardEvent<HTMLElement>) => void\n      id?: string\n    }\n    const theirRef = tp.ref\n    triggerNode = React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n      ...triggerProps,\n      id: tp.id ?? triggerId,\n      disabled: disabled || undefined,\n      ref: (el: HTMLElement | null) => {\n        triggerEl.current = el\n        if (typeof theirRef === \"function\") theirRef(el)\n        else if (theirRef && typeof theirRef === \"object\") (theirRef as React.RefObject<HTMLElement | null>).current = el\n      },\n      onClick: (e: React.MouseEvent<HTMLElement>) => {\n        tp.onClick?.(e)\n        if (!e.defaultPrevented) onTriggerClick(e)\n      },\n      onKeyDown: (e: React.KeyboardEvent<HTMLElement>) => {\n        tp.onKeyDown?.(e)\n        if (!e.defaultPrevented) onTriggerKey(e)\n      },\n    })\n  } else {\n    triggerNode = (\n      <button\n        type=\"button\"\n        {...triggerProps}\n        ref={(el) => {\n          triggerEl.current = el\n        }}\n        disabled={disabled}\n        onClick={onTriggerClick}\n        onKeyDown={onTriggerKey}\n        className={cn(\"pc-press pc-ddm-trigger inline-flex items-center font-medium whitespace-nowrap select-none disabled:pointer-events-none disabled:opacity-55\", SIZES[size].trigger, SHAPES[shape].trigger, \"[&_svg]:size-4\")}\n      >\n        {label ?? l.trigger}\n        <Chevron className=\"-me-1\" />\n      </button>\n    )\n  }\n\n  return (\n    <>\n      {style}\n      <div {...rest} ref={root} data-slot=\"dropdown-menu\" data-tone={tone} data-state={open ? \"open\" : \"closed\"} className={cn(\"pc-ddm inline-flex\", className)}>\n        {triggerNode}\n      </div>\n      {panel}\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/dropdown-menu.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}