{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "context-menu",
  "title": "Context Menu",
  "description": "Astro menus that open from a right click or a long press.",
  "dependencies": [
    "@data-slot/core",
    "@data-slot/dropdown-menu",
    "cn"
  ],
  "registryDependencies": [
    "@gnostic/dropdown-menu"
  ],
  "files": [
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-checkbox-item.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuCheckboxItem from \"../dropdown-menu/dropdown-menu-checkbox-item.astro\"\nimport type { ContextMenuCheckboxItemProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"button\"> & ContextMenuCheckboxItemProps\n\nconst {\n  class: className,\n  value,\n  defaultChecked,\n  variant,\n  inset,\n  disabled,\n  ...props\n} = Astro.props\n---\n\n<DropdownMenuCheckboxItem\n  class={className}\n  value={value}\n  defaultChecked={defaultChecked}\n  disabled={disabled ? true : undefined}\n  variant={variant}\n  inset={inset}\n  {...props}\n>\n  <slot />\n</DropdownMenuCheckboxItem>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-checkbox-item.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-content.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuContent from \"../dropdown-menu/dropdown-menu-content.astro\"\nimport type { ContextMenuContentProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"div\"> & ContextMenuContentProps\n\nconst {\n  class: className,\n  side,\n  align,\n  sideOffset,\n  alignOffset,\n  avoidCollisions,\n  collisionPadding,\n  ...props\n} = Astro.props\n---\n\n<DropdownMenuContent\n  class={className}\n  side={side}\n  align={align}\n  sideOffset={sideOffset}\n  alignOffset={alignOffset}\n  avoidCollisions={avoidCollisions}\n  collisionPadding={collisionPadding}\n  {...props}\n>\n  <slot />\n</DropdownMenuContent>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-content.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-group.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuGroup from \"../dropdown-menu/dropdown-menu-group.astro\"\n\ntype Props = HTMLAttributes<\"div\">\n\nconst { class: className, ...props } = Astro.props\n---\n\n<DropdownMenuGroup class={className} {...props}>\n  <slot />\n</DropdownMenuGroup>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-group.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-item.astro",
      "content": "---\nimport type { HTMLAttributes, HTMLTag, Polymorphic } from \"astro/types\"\n\nimport DropdownMenuItem from \"../dropdown-menu/dropdown-menu-item.astro\"\nimport type { ContextMenuItemProps } from \"./types.ts\"\n\ntype Props<T extends HTMLTag = \"button\"> = Polymorphic<{ as: T }> &\n  HTMLAttributes<T> &\n  ContextMenuItemProps\n\nconst { class: className, variant, inset, ...props } = Astro.props\n---\n\n<DropdownMenuItem class={className} variant={variant} inset={inset} {...props}>\n  <slot />\n</DropdownMenuItem>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-item.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-label.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuLabel from \"../dropdown-menu/dropdown-menu-label.astro\"\nimport type { ContextMenuLabelProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"div\"> & ContextMenuLabelProps\n\nconst { class: className, inset, ...props } = Astro.props\n---\n\n<DropdownMenuLabel class={className} inset={inset} {...props}>\n  <slot />\n</DropdownMenuLabel>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-label.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-portal.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuPortal from \"../dropdown-menu/dropdown-menu-portal.astro\"\n\ntype Props = HTMLAttributes<\"div\">\n\nconst { class: className, ...props } = Astro.props\n---\n\n<DropdownMenuPortal class={className} {...props}>\n  <slot />\n</DropdownMenuPortal>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-portal.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-radio-group.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\ntype Props = HTMLAttributes<\"div\">\n\nconst { class: className, ...props } = Astro.props\n---\n\n<div\n  data-slot=\"context-menu-radio-group\"\n  role=\"group\"\n  class={className}\n  {...props}\n>\n  <slot />\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-radio-group.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-radio-item.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuRadioItem from \"../dropdown-menu/dropdown-menu-radio-item.astro\"\nimport type { ContextMenuRadioItemProps } from \"./types.ts\"\n\ntype Props = HTMLAttributes<\"button\"> & ContextMenuRadioItemProps\n\nconst {\n  class: className,\n  value,\n  defaultChecked,\n  variant,\n  inset,\n  disabled,\n  ...props\n} = Astro.props\n---\n\n<DropdownMenuRadioItem\n  class={className}\n  value={value}\n  defaultChecked={defaultChecked}\n  disabled={disabled ? true : undefined}\n  variant={variant}\n  inset={inset}\n  {...props}\n>\n  <slot />\n</DropdownMenuRadioItem>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-radio-item.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-separator.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuSeparator from \"../dropdown-menu/dropdown-menu-separator.astro\"\n\ntype Props = HTMLAttributes<\"div\">\n\nconst { class: className, ...props } = Astro.props\n---\n\n<DropdownMenuSeparator class={className} {...props} />\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-separator.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-shortcut.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenuShortcut from \"../dropdown-menu/dropdown-menu-shortcut.astro\"\n\ntype Props = HTMLAttributes<\"span\">\n\nconst { class: className, ...props } = Astro.props\n---\n\n<DropdownMenuShortcut class={className} {...props}>\n  <slot />\n</DropdownMenuShortcut>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-shortcut.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu-trigger.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\n\ntype Props = HTMLAttributes<\"div\">\n\nconst { class: className, tabindex = 0, ...props } = Astro.props\n---\n\n<div\n  data-slot=\"context-menu-trigger\"\n  tabindex={tabindex}\n  aria-haspopup=\"menu\"\n  aria-expanded=\"false\"\n  class={cn(\"select-none\", className)}\n  {...props}\n>\n  <slot />\n</div>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu-trigger.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport DropdownMenu from \"../dropdown-menu/dropdown-menu.astro\"\nimport type { ContextMenuProps } from \"./types.ts\"\n\n// Coss context menu visuals come from the shared dropdown menu recipes.\n// data-slot has no context menu package, so this root owns the right-click\n// binding and the dropdown menu owns the popup.\ntype Props = HTMLAttributes<\"div\"> & ContextMenuProps\n\nconst {\n  class: className,\n  defaultOpen,\n  defaultValue,\n  defaultValues,\n  closeOnClickOutside,\n  closeOnEscape,\n  closeOnSelect,\n  highlightItemOnHover,\n  side = \"bottom\",\n  align = \"center\",\n  sideOffset = 4,\n  alignOffset = 0,\n  avoidCollisions,\n  collisionPadding,\n  lockScroll,\n  ...props\n} = Astro.props\n---\n\n<div data-slot=\"context-menu\" class={className} {...props}>\n  <DropdownMenu\n    defaultOpen={defaultOpen}\n    defaultValue={defaultValue}\n    defaultValues={defaultValues}\n    closeOnClickOutside={closeOnClickOutside}\n    closeOnEscape={closeOnEscape}\n    closeOnSelect={closeOnSelect}\n    highlightItemOnHover={highlightItemOnHover}\n    side={side}\n    align={align}\n    sideOffset={sideOffset}\n    alignOffset={alignOffset}\n    avoidCollisions={avoidCollisions}\n    collisionPadding={collisionPadding}\n    lockScroll={lockScroll}\n  >\n    <!-- Point anchor. context-menu.ts moves this box to the pointer. -->\n    <button\n      data-slot=\"dropdown-menu-trigger\"\n      type=\"button\"\n      tabindex=\"-1\"\n      aria-label=\"Context menu\"\n      class=\"pointer-events-none fixed top-0 left-0 size-0 border-0 p-0 opacity-0\"\n    ></button>\n    <slot />\n  </DropdownMenu>\n</div>\n\n<script>\n  import { create, type ContextMenuController } from \"./context-menu.ts\"\n\n  // Destroy bindings before a view transition so the next page load binds once.\n  const controllers: ContextMenuController[] = []\n  const initialize = () => controllers.push(...create())\n  initialize()\n  document.addEventListener(\"astro:page-load\", initialize)\n  document.addEventListener(\"astro:before-swap\", () => {\n    for (const controller of controllers) controller.destroy()\n    controllers.length = 0\n  })\n</script>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu.astro"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/context-menu.ts",
      "content": "import {\n    clearRootBinding,\n    emit,\n    getPart,\n    getRootBinding,\n    getRoots,\n    hasRootBinding,\n    lockScroll,\n    on,\n    onRoot,\n    reuseRootBinding,\n    setRootBinding,\n    unlockScroll,\n} from '@data-slot/core'\nimport { createDropdownMenu } from '@data-slot/dropdown-menu'\nimport type {\n    DropdownMenuController,\n    DropdownMenuHighlightChangeDetail,\n    DropdownMenuOpenChangeDetail,\n    DropdownMenuSelectDetail,\n    DropdownMenuSetDetail,\n    DropdownMenuValueChangeDetail,\n    DropdownMenuValuesChangeDetail,\n} from '@data-slot/dropdown-menu'\n\n/**\n * Binding key for one context menu root.\n * A second `createContextMenu()` call returns the controller already stored here.\n */\nconst BINDING_KEY = '@gnostic/context-menu'\n\n/** Touch and pen presses that stay inside this distance count as a long press. */\nconst LONG_PRESS_MOVE_PX = 10\n\n/** Hold time before a touch or pen press opens the menu. */\nconst LONG_PRESS_MS = 500\n\n/**\n * Clicks that follow a context-menu gesture within this window must not close\n * the menu that gesture just opened.\n */\nconst OPEN_CLICK_GUARD_MS = 100\n\n/** Viewport rectangle used as the dropdown menu anchor. */\ninterface AnchorRect {\n    left: number\n    top: number\n    width: number\n    height: number\n}\n\n/**\n * Controller for one context menu.\n * Item behavior, focus, and placement stay on the inner dropdown menu.\n */\nexport interface ContextMenuController {\n    /** Open the menu against the trigger bounds. */\n    open(): void\n    /** Open the menu at a viewport point. Width and height are zero. */\n    openAt(x: number, y: number): void\n    /** Close the menu. */\n    close(): void\n    /** Whether the menu popup is open. */\n    readonly isOpen: boolean\n    /** Dropdown menu controller that owns the popup and its items. */\n    readonly menu: DropdownMenuController\n    /** Remove listeners and destroy the dropdown menu controller. */\n    destroy(): void\n}\n\n/**\n * Place the invisible dropdown trigger where the popup should anchor.\n * The dropdown menu reads this element's box on open.\n */\nfunction placeAnchor(anchor: HTMLElement, rect: AnchorRect) {\n    const style = anchor.style\n    style.position = 'fixed'\n    style.margin = '0'\n    style.padding = '0'\n    style.borderWidth = '0'\n    style.pointerEvents = 'none'\n    style.width = `${rect.width}px`\n    style.height = `${rect.height}px`\n    // A transformed ancestor makes fixed `top` and `left` relative to that\n    // ancestor. Measure that origin, then place the box on the pointer.\n    style.left = '0px'\n    style.top = '0px'\n    const origin = anchor.getBoundingClientRect()\n    style.left = `${rect.left - origin.left}px`\n    style.top = `${rect.top - origin.top}px`\n}\n\n/**\n * True when the event target belongs to this trigger and not a nested trigger.\n */\nfunction ownsTrigger(target: EventTarget | null, trigger: Element) {\n    const element =\n        target instanceof Element\n            ? target\n            : target instanceof Node\n              ? target.parentElement\n              : null\n    if (!element || !trigger.contains(element)) return false\n    return element.closest('[data-slot=\"context-menu-trigger\"]') === trigger\n}\n\n/**\n * True when the trigger is marked disabled.\n */\nfunction isTriggerDisabled(trigger: Element) {\n    return (\n        trigger.hasAttribute('data-disabled') ||\n        trigger.getAttribute('aria-disabled') === 'true'\n    )\n}\n\n/**\n * Create a context menu controller for one root.\n *\n * The root must contain `context-menu-trigger` and a dropdown menu with a\n * trigger and content. A right click, a long press, or the context-menu key\n * moves the dropdown trigger to the requested box and emits `dropdown-menu:set`.\n *\n * @param root - Element with `data-slot=\"context-menu\"`.\n */\nexport function createContextMenu(root: Element): ContextMenuController {\n    const existing = reuseRootBinding<ContextMenuController>(\n        root,\n        BINDING_KEY,\n        '[@gnostic/context-menu] createContextMenu() called more than once for the same root. Returning the existing controller. Destroy it before rebinding.',\n    )\n    if (existing) return existing\n\n    const trigger = getPart<HTMLElement>(root, 'context-menu-trigger')\n    const menu = getPart<HTMLElement>(root, 'dropdown-menu')\n    const anchor = menu\n        ? getPart<HTMLElement>(menu, 'dropdown-menu-trigger')\n        : null\n    const content = menu\n        ? getPart<HTMLElement>(menu, 'dropdown-menu-content')\n        : null\n    if (!trigger || !menu || !anchor || !content) {\n        throw new Error(\n            'ContextMenu requires ContextMenuTrigger and ContextMenuContent.',\n        )\n    }\n\n    // Copy the narrowed elements so nested functions keep a definite type.\n    const triggerEl: HTMLElement = trigger\n    const menuEl: HTMLElement = menu\n    const anchorEl: HTMLElement = anchor\n    const contentEl: HTMLElement = content\n\n    const menuController =\n        getRootBinding<DropdownMenuController>(\n            menuEl,\n            '@data-slot/dropdown-menu',\n        ) ?? createDropdownMenu(menuEl)\n    // The anchor is only a positioning box. Name the popup, then hide the anchor\n    // so assistive technology does not stop on an empty control.\n    contentEl.setAttribute('aria-label', 'Context menu')\n    contentEl.removeAttribute('aria-labelledby')\n    anchorEl.setAttribute('aria-hidden', 'true')\n    const cleanups: Array<() => void> = []\n    let destroyed = false\n    let openedAt = 0\n    let ignoreClick = false\n    let pressTimer: ReturnType<typeof setTimeout> | null = null\n    let pressX = 0\n    let pressY = 0\n    // The dropdown menu locks scroll on open, which moves the fixed containing\n    // block. Hold that lock before measuring the anchor so the box stays put.\n    let heldScrollLock = false\n    let repositioning = false\n\n    function menuLocksScroll() {\n        return menuEl.getAttribute('data-lock-scroll') !== 'false'\n    }\n\n    function holdScrollLock() {\n        if (heldScrollLock || !menuLocksScroll()) return\n        lockScroll()\n        heldScrollLock = true\n    }\n\n    function releaseScrollLock() {\n        if (!heldScrollLock) return\n        heldScrollLock = false\n        unlockScroll()\n    }\n\n    const controls = anchorEl.getAttribute('aria-controls')\n    if (controls) triggerEl.setAttribute('aria-controls', controls)\n    triggerEl.setAttribute('aria-haspopup', 'menu')\n    if (!triggerEl.hasAttribute('aria-expanded')) {\n        triggerEl.setAttribute('aria-expanded', 'false')\n    }\n\n    /**\n     * Move the anchor, then open. An open menu closes and opens again so the\n     * dropdown menu reads the new anchor box.\n     */\n    function showAt(rect: AnchorRect) {\n        if (destroyed || isTriggerDisabled(triggerEl)) return\n        holdScrollLock()\n        placeAnchor(anchorEl, rect)\n        openedAt = performance.now()\n        // Closing to reposition also emits open-change. Keep the scroll lock\n        // until the menu stays closed.\n        repositioning = true\n        if (menuController.isOpen) {\n            emit<DropdownMenuSetDetail>(menuEl, 'dropdown-menu:set', {\n                open: false,\n            })\n        }\n        repositioning = false\n        emit<DropdownMenuSetDetail>(menuEl, 'dropdown-menu:set', {\n            open: true,\n        })\n    }\n\n    function openAtPoint(x: number, y: number) {\n        showAt({ left: x, top: y, width: 0, height: 0 })\n    }\n\n    function openAtTrigger() {\n        const rect = triggerEl.getBoundingClientRect()\n        showAt({\n            left: rect.left,\n            top: rect.top,\n            width: rect.width,\n            height: rect.height,\n        })\n    }\n\n    function clearPress() {\n        if (pressTimer === null) return\n        clearTimeout(pressTimer)\n        pressTimer = null\n    }\n\n    cleanups.push(\n        on(triggerEl, 'contextmenu', (event) => {\n            if (!ownsTrigger(event.target, triggerEl)) return\n            event.preventDefault()\n            event.stopPropagation()\n            // A completed long press already opened the menu.\n            if (ignoreClick) return\n            openAtPoint(event.clientX, event.clientY)\n        }),\n    )\n\n    cleanups.push(\n        on(triggerEl, 'keydown', (event) => {\n            if (!ownsTrigger(event.target, triggerEl)) return\n            const isContextKey =\n                event.key === 'ContextMenu' ||\n                (event.key === 'F10' && event.shiftKey)\n            if (!isContextKey) return\n            event.preventDefault()\n            openAtTrigger()\n        }),\n    )\n\n    // Touch and pen have no right click. A held press opens the menu.\n    cleanups.push(\n        on(triggerEl, 'pointerdown', (event) => {\n            if (event.pointerType === 'mouse' || event.button !== 0) return\n            if (\n                !ownsTrigger(event.target, triggerEl) ||\n                isTriggerDisabled(triggerEl)\n            )\n                return\n            clearPress()\n            pressX = event.clientX\n            pressY = event.clientY\n            pressTimer = setTimeout(() => {\n                pressTimer = null\n                ignoreClick = true\n                openAtPoint(pressX, pressY)\n            }, LONG_PRESS_MS)\n        }),\n    )\n    cleanups.push(\n        on(triggerEl, 'pointermove', (event) => {\n            if (pressTimer === null) return\n            const distance = Math.hypot(\n                event.clientX - pressX,\n                event.clientY - pressY,\n            )\n            if (distance > LONG_PRESS_MOVE_PX) clearPress()\n        }),\n    )\n    cleanups.push(on(triggerEl, 'pointerup', clearPress))\n    cleanups.push(on(triggerEl, 'pointercancel', clearPress))\n    cleanups.push(on(triggerEl, 'pointerleave', clearPress))\n\n    // The trigger sits inside the dropdown root, so an outside press does not\n    // see a primary click here. Close it unless this click opened the menu.\n    cleanups.push(\n        on(triggerEl, 'click', (event) => {\n            if (ignoreClick) {\n                ignoreClick = false\n                event.preventDefault()\n                event.stopPropagation()\n                return\n            }\n            if (!ownsTrigger(event.target, triggerEl)) return\n            if (event.ctrlKey || event.metaKey) return\n            if (performance.now() - openedAt < OPEN_CLICK_GUARD_MS) return\n            if (!menuController.isOpen) return\n            emit<DropdownMenuSetDetail>(menuEl, 'dropdown-menu:set', {\n                open: false,\n            })\n        }),\n    )\n\n    cleanups.push(\n        on(contentEl, 'contextmenu', (event) => {\n            event.preventDefault()\n        }),\n    )\n\n    cleanups.push(\n        on(menuEl, 'dropdown-menu:open-change', (event) => {\n            const detail = (event as CustomEvent<DropdownMenuOpenChangeDetail>)\n                .detail\n            triggerEl.setAttribute(\n                'aria-expanded',\n                detail?.open ? 'true' : 'false',\n            )\n            if (!detail?.open && !repositioning) releaseScrollLock()\n            emit(root, 'context-menu:open-change', detail)\n        }),\n    )\n    cleanups.push(\n        on(menuEl, 'dropdown-menu:highlight-change', (event) => {\n            const detail = (\n                event as CustomEvent<DropdownMenuHighlightChangeDetail>\n            ).detail\n            emit(root, 'context-menu:highlight-change', detail)\n        }),\n    )\n    cleanups.push(\n        on(menuEl, 'dropdown-menu:select', (event) => {\n            const detail = (event as CustomEvent<DropdownMenuSelectDetail>)\n                .detail\n            // `emit` does not create a cancelable event. Selection must stay\n            // cancelable, matching the dropdown menu event.\n            const allowed = root.dispatchEvent(\n                new CustomEvent<DropdownMenuSelectDetail>(\n                    'context-menu:select',\n                    { bubbles: true, cancelable: true, detail },\n                ),\n            )\n            if (!allowed) event.preventDefault()\n        }),\n    )\n    cleanups.push(\n        on(menuEl, 'dropdown-menu:value-change', (event) => {\n            const detail = (event as CustomEvent<DropdownMenuValueChangeDetail>)\n                .detail\n            emit(root, 'context-menu:value-change', detail)\n        }),\n    )\n    cleanups.push(\n        on(menuEl, 'dropdown-menu:values-change', (event) => {\n            const detail = (\n                event as CustomEvent<DropdownMenuValuesChangeDetail>\n            ).detail\n            emit(root, 'context-menu:values-change', detail)\n        }),\n    )\n    cleanups.push(\n        onRoot(root, 'context-menu:set', (event) => {\n            const detail = (event as CustomEvent<DropdownMenuSetDetail>).detail\n            if (!detail || typeof detail !== 'object') return\n            if (detail.open === true && isTriggerDisabled(triggerEl)) return\n            // Programmatic open uses the trigger box. A pointer open calls\n            // `dropdown-menu:set` directly and does not pass through here.\n            if (detail.open === true) {\n                const rect = triggerEl.getBoundingClientRect()\n                holdScrollLock()\n                placeAnchor(anchorEl, {\n                    left: rect.left,\n                    top: rect.top,\n                    width: rect.width,\n                    height: rect.height,\n                })\n                openedAt = performance.now()\n                repositioning = true\n                if (menuController.isOpen) {\n                    emit<DropdownMenuSetDetail>(menuEl, 'dropdown-menu:set', {\n                        open: false,\n                    })\n                }\n                repositioning = false\n            }\n            emit(menuEl, 'dropdown-menu:set', detail)\n        }),\n    )\n\n    // A menu marked open before this script runs still uses the trigger box.\n    if (menuController.isOpen) openAtTrigger()\n\n    const controller: ContextMenuController = {\n        open: openAtTrigger,\n        openAt: openAtPoint,\n        close: () => {\n            if (destroyed) return\n            emit<DropdownMenuSetDetail>(menuEl, 'dropdown-menu:set', {\n                open: false,\n            })\n        },\n        get isOpen() {\n            return menuController.isOpen\n        },\n        menu: menuController,\n        destroy() {\n            if (destroyed) return\n            if (!clearRootBinding(root, BINDING_KEY, controller)) return\n            destroyed = true\n            clearPress()\n            releaseScrollLock()\n            for (const cleanup of cleanups) cleanup()\n            cleanups.length = 0\n            menuController.destroy()\n        },\n    }\n\n    return setRootBinding(root, BINDING_KEY, controller)\n}\n\n/**\n * Find and bind every context menu in a scope.\n * Roots that already have a controller are skipped.\n *\n * @param scope - Parent to search. Defaults to the document.\n */\nexport function create(scope: ParentNode = document): ContextMenuController[] {\n    const controllers: ContextMenuController[] = []\n    for (const root of getRoots(scope, 'context-menu')) {\n        if (hasRootBinding(root, BINDING_KEY)) continue\n        controllers.push(createContextMenu(root))\n    }\n    return controllers\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/context-menu.ts"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/index.ts",
      "content": "export { default as ContextMenu } from './context-menu.astro'\nexport { default as ContextMenuCheckboxItem } from './context-menu-checkbox-item.astro'\nexport { default as ContextMenuContent } from './context-menu-content.astro'\nexport { default as ContextMenuGroup } from './context-menu-group.astro'\nexport { default as ContextMenuItem } from './context-menu-item.astro'\nexport { default as ContextMenuLabel } from './context-menu-label.astro'\nexport { default as ContextMenuPortal } from './context-menu-portal.astro'\nexport { default as ContextMenuRadioGroup } from './context-menu-radio-group.astro'\nexport { default as ContextMenuRadioItem } from './context-menu-radio-item.astro'\nexport { default as ContextMenuSeparator } from './context-menu-separator.astro'\nexport { default as ContextMenuShortcut } from './context-menu-shortcut.astro'\nexport { default as ContextMenuTrigger } from './context-menu-trigger.astro'\nexport type {\n    ContextMenuCheckboxItemProps,\n    ContextMenuContentProps,\n    ContextMenuItemProps,\n    ContextMenuLabelProps,\n    ContextMenuProps,\n    ContextMenuRadioItemProps,\n} from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/index.ts"
    },
    {
      "path": "packages/ui/src/components/ui/context-menu/types.ts",
      "content": "import type {\n    DropdownMenuContentProps,\n    DropdownMenuProps,\n} from '../dropdown-menu/types.ts'\n\n/**\n * Options for a menu that opens from a right click or a long press.\n *\n * These fields match the supported dropdown menu props.\n * Listen for `context-menu:*` events on this root instead.\n *\n * The menu locks page scroll while it is open, same as the dropdown menu.\n * That keeps the popup on the pointer. Pass `lockScroll={false}` to leave\n * the page free. The popup then uses absolute positioning.\n */\nexport interface ContextMenuProps extends DropdownMenuProps {\n    /**\n     * Preferred side of the pointer or trigger.\n     *\n     * @default \"bottom\"\n     */\n    side?: DropdownMenuProps['side']\n    /**\n     * Preferred alignment against the pointer or trigger.\n     *\n     * @default \"center\"\n     */\n    align?: DropdownMenuProps['align']\n    /**\n     * Distance in pixels from the pointer or trigger.\n     *\n     * @default 4\n     */\n    sideOffset?: number\n    /**\n     * Offset in pixels from the start or end alignment.\n     *\n     * @default 0\n     */\n    alignOffset?: number\n}\n\n/**\n * Placement fields for the context menu popup.\n * Set fields override the same fields on `ContextMenu`.\n */\nexport type ContextMenuContentProps = DropdownMenuContentProps\n\n/**\n * Props for one action in a context menu.\n * Button attributes such as `class`, `disabled`, and `aria-*` pass through.\n * Set `as` to render another element, such as `as=\"a\"` for a link.\n */\nexport interface ContextMenuItemProps {\n    /**\n     * Visual style of the action.\n     * `destructive` uses the destructive foreground color.\n     *\n     * @default \"default\"\n     */\n    variant?: 'default' | 'destructive'\n    /**\n     * Indent the label so it lines up with checkbox and radio labels.\n     *\n     * @default false\n     */\n    inset?: boolean\n}\n\n/**\n * Props for a context menu item that toggles one value.\n * Button attributes such as `class` and `disabled` pass through.\n */\nexport interface ContextMenuCheckboxItemProps {\n    /**\n     * Value committed when the item is checked.\n     */\n    value: string\n    /**\n     * Check this item when the menu root has no `defaultValues`.\n     *\n     * @default false\n     */\n    defaultChecked?: boolean\n    /**\n     * Visual style of the action.\n     *\n     * @default \"default\"\n     */\n    variant?: 'default' | 'destructive'\n    /**\n     * Indent the label.\n     *\n     * @default false\n     */\n    inset?: boolean\n}\n\n/**\n * Props for one choice in the menu radio selection.\n * A context menu has one radio value. Button attributes pass through.\n */\nexport interface ContextMenuRadioItemProps {\n    /**\n     * Value committed when this choice is selected.\n     */\n    value: string\n    /**\n     * Select this choice when the menu root has no `defaultValue`.\n     *\n     * @default false\n     */\n    defaultChecked?: boolean\n    /**\n     * Visual style of the choice.\n     *\n     * @default \"default\"\n     */\n    variant?: 'default' | 'destructive'\n    /**\n     * Indent the label.\n     *\n     * @default false\n     */\n    inset?: boolean\n}\n\n/**\n * Props for a non-interactive context menu label.\n */\nexport interface ContextMenuLabelProps {\n    /**\n     * Indent the label so it lines up with checkbox and radio labels.\n     *\n     * @default false\n     */\n    inset?: boolean\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/context-menu/types.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "@data-slot/core": "^1.0.2",
      "@data-slot/dropdown-menu": "^1.1.2",
      "cn": "0.5.2"
    }
  },
  "docs": "https://ui.gnosticai.com/components/context-menu",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
