# Marking menu

> Spacious gesture stage with a live active-view header, press-and-hold or flick radial wheel, wedge highlight and keyboard menu trigger.

- Kind: ui · Category: Navigation · Interactivity: script
- Install: `npx shadcn@latest add @haze/marking-menu`
- File: `src/components/haze/ui/marking-menu.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/ui/marking-menu

## Use when
- Canvas, workspace or reader stages benefit from fast press-and-hold or flick directional navigation
- Four to eight frequent destinations or actions need equal radial distance from the pointer anchor

## Avoid when
- Actions exceed eight items or require nested submenus; use context-menu or dropdown-menu
- Commands belong to a standard toolbar button rather than an interactive gesture stage

## Alternatives
- [context-menu](https://hazeui.com/ui/context-menu.md)
- [dropdown-menu](https://hazeui.com/ui/dropdown-menu.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique prefix connecting the stage, header menu button, live status and radial popover. |
| items | `{ label: string; value?: string; href?: string; shortcut?: string; icon?: string; destructive?: boolean }[]` | 6 navigation views | no | Four to eight directional actions arranged clockwise from north. |
| label | `string` | "Gesture navigation stage" | no | Accessible name of the press-and-hold gesture region. |
| triggerLabel | `string` | "Menu" | no | Visible label for the top-right keyboard-focusable menu trigger. |
| hint | `string` | "Press and hold anywhere, or flick" | no | Primary instructional copy centered inside the default gesture stage. |
| subhint | `string` | "Right-click opens it too" | no | Muted helper subtitle shown beneath the primary instruction copy. |
| holdMs | `number` | 180 | no | Press-and-hold duration in milliseconds before opening the radial wheel. |
| class | `string` |  | no | Additional classes on the outer stage card. |

## Accessibility
- Provides a keyboard-focusable Menu button in the stage header using native popovertarget so every item stays reachable without pointer gestures or scripts.
- Without scripts, clicking Menu opens the native popover as a structured vertical list with icons and shortcut hints.
- Updates the visible active view chip and announces selection changes via an aria-live polite status region, restoring focus on Escape.
- Key Enter / Space / Shift+F10: Open the radial menu centered in the stage from the gesture surface or Menu button
- Key Arrow keys: Step clockwise or counter-clockwise around the directional nodes
- Key Home / End: Jump to the first or last radial item
- Key Escape: Close the radial menu and restore focus to the opener

## Agent prompts

### Install and use

Install the Haze UI component "Marking menu" with `npx shadcn@latest add @haze/marking-menu`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import MarkingMenu from "@/components/haze/ui/marking-menu.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/marking-menu.md

### Customize with real content

Adapt the Haze marking-menu ui for our product. Replace the demo values of these props with our real content: id, items, label, triggerLabel, hint, subhint, holdMs, class. Keep the layout, the heading level rules and these accessibility details: Provides a keyboard-focusable Menu button in the stage header using native popovertarget so every item stays reachable without pointer gestures or scripts. Without scripts, clicking Menu opens the native popover as a structured vertical list with icons and shortcut hints. Updates the visible active view chip and announces selection changes via an aria-live polite status region, restoring focus on Escape. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using marking-menu, check it fits: use it when canvas, workspace or reader stages benefit from fast press-and-hold or flick directional navigation; four to eight frequent destinations or actions need equal radial distance from the pointer anchor. Avoid it when actions exceed eight items or require nested submenus; use context-menu or dropdown-menu; commands belong to a standard toolbar button rather than an interactive gesture stage. Alternatives: @haze/context-menu, @haze/dropdown-menu.

## Example requests that should lead here
- Add an interactive marking menu stage with an active-view top bar and press-and-hold radial navigation
- Provide a flick-and-release radial pie menu with wedge highlighting and a keyboard Menu button

## Source

```astro
---
import {
  Bell,
  Bookmark,
  Compass,
  Folder,
  House,
  Inbox,
  Layers,
  Menu,
  Search,
  Settings,
  Sparkles,
  X,
} from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

type MarkingIcon =
  | "home"
  | "search"
  | "inbox"
  | "folder"
  | "bookmark"
  | "settings"
  | "compass"
  | "sparkles"
  | "layers"
  | "bell";

interface MarkingAction {
  label: string;
  value?: string;
  href?: string;
  shortcut?: string;
  icon?: MarkingIcon;
  destructive?: boolean;
}

interface Props {
  /** Unique on the page. Links the stage, menu button, live status and radial menu. */
  id: string;
  /** Four to eight directional actions arranged radially around the anchor. */
  items?: MarkingAction[];
  /** Accessible name for the interactive gesture stage. */
  label?: string;
  /** Label for the top-right keyboard-focusable menu button. */
  triggerLabel?: string;
  /** Primary instruction copy centered inside the default stage. */
  hint?: string;
  /** Secondary helper subtitle shown beneath the primary instruction copy. */
  subhint?: string;
  /** Press-and-hold duration in milliseconds before the radial menu opens. */
  holdMs?: number;
  class?: string;
}

const defaultItems: MarkingAction[] = [
  { label: "Home", value: "home", icon: "home", shortcut: "1" },
  { label: "Search", value: "search", icon: "search", shortcut: "2" },
  { label: "Inbox", value: "inbox", icon: "inbox", shortcut: "3" },
  { label: "Projects", value: "projects", icon: "folder", shortcut: "4" },
  { label: "Saved", value: "saved", icon: "bookmark", shortcut: "5" },
  { label: "Settings", value: "settings", icon: "settings", shortcut: "6" },
];

const iconMap = {
  home: House,
  search: Search,
  inbox: Inbox,
  folder: Folder,
  bookmark: Bookmark,
  settings: Settings,
  compass: Compass,
  sparkles: Sparkles,
  layers: Layers,
  bell: Bell,
} as const;

const {
  id,
  items = defaultItems,
  label = "Gesture navigation stage",
  triggerLabel = "Menu",
  hint = "Press and hold anywhere, or flick",
  subhint = "Right-click opens it too",
  holdMs = 180,
  class: className,
} = Astro.props;

const clamped = items.slice(0, 8);
const count = Math.max(1, clamped.length);
const compass = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
const wheelSize = 230;
const center = wheelSize / 2;
const radius = 78;
const rIn = 38;
const rOut = 115;
const stepRad = (Math.PI * 2) / count;

const pt = (r: number, a: number) => `${(center + Math.cos(a) * r).toFixed(1)} ${(center + Math.sin(a) * r).toFixed(1)}`;
const a1 = -Math.PI / 2 - stepRad / 2;
const a2 = -Math.PI / 2 + stepRad / 2;
const largeArc = stepRad > Math.PI ? 1 : 0;
const wedgePath = `M ${pt(rIn, a1)} L ${pt(rOut, a1)} A ${rOut} ${rOut} 0 ${largeArc} 1 ${pt(rOut, a2)} L ${pt(rIn, a2)} A ${rIn} ${rIn} 0 ${largeArc} 0 ${pt(rIn, a1)} Z`;

const positioned = clamped.map((item, index) => {
  const angleRad = (index / count) * Math.PI * 2 - Math.PI / 2;
  const angleDeg = ((index / count) * 360) % 360;
  const dir = compass[Math.round(angleDeg / 45) % 8];
  const x = Math.round(center + Math.cos(angleRad) * radius);
  const y = Math.round(center + Math.sin(angleRad) * radius);
  const Icon = iconMap[item.icon ?? "compass"] ?? Compass;
  return { ...item, index, dir, angleDeg, x, y, Icon };
});

const initialItem = positioned[0];
const menuId = `${id}-menu`;
const hintId = `${id}-hint`;
const statusId = `${id}-status`;
---

<div
  id={id}
  data-haze-marking-menu
  data-hold-ms={holdMs}
  class={cn(
    "relative flex min-h-[340px] w-full max-w-md min-w-0 flex-col overflow-hidden rounded-xl border border-border bg-card text-card-foreground select-none",
    className,
  )}
>
  <header
    data-mm-topbar
    class="relative z-10 flex items-center justify-between gap-3 border-b border-border/70 px-4 py-3"
  >
    <div class="inline-flex min-w-0 items-center gap-2 h-8 rounded-lg bg-field px-2.5 text-xs/4 font-medium text-foreground">
      {
        positioned.map((item, index) => (
          <span
            data-mm-chip-icon={index}
            aria-hidden="true"
            data-hidden={index !== 0 ? "" : undefined}
            class="inline-flex shrink-0 text-muted-foreground data-hidden:hidden"
          >
            <item.Icon class="size-3.5" />
          </span>
        ))
      }
      <span data-mm-view-label class="truncate">{initialItem?.label ?? "Home"}</span>
    </div>

    <button
      type="button"
      popovertarget={menuId}
      aria-haspopup="menu"
      aria-controls={menuId}
      aria-expanded="false"
      data-mm-trigger
      style={`anchor-name: --${menuId}`}
      class="inline-flex h-8 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg bg-field px-3 text-[0.8125rem]/5 font-medium text-foreground transition-[background-color] duration-150 ease-snappy hover:bg-accent motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
    >
      <Menu class="size-3.5 text-muted-foreground" aria-hidden="true" />
      <span>{triggerLabel}</span>
    </button>
  </header>

  <div
    data-mm-surface
    tabindex="0"
    role="region"
    aria-label={label}
    aria-describedby={Astro.slots.has("default") ? undefined : hintId}
    aria-keyshortcuts="Shift+F10"
    class="relative flex flex-1 cursor-crosshair flex-col items-center justify-center px-6 py-10 text-center touch-none focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
  >
    <slot>
      <div class="grid max-w-64 justify-items-center gap-1.5">
        <p class="text-sm/5 font-medium text-foreground">{hint}</p>
        <p id={hintId} class="text-xs/4 text-muted-foreground">{subhint}</p>
      </div>
    </slot>
  </div>

  <p id={statusId} data-mm-status aria-live="polite" class="sr-only"></p>

  <div
    popover
    id={menuId}
    data-mm-menu
    role="menu"
    aria-label={triggerLabel}
    style={`position-anchor: --${menuId}`}
    class={cn(
      "m-auto max-h-[min(24rem,calc(100dvh-2rem))] w-56 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-xl border border-border bg-popover p-1.5 text-[0.8125rem]/5 text-popover-foreground backdrop:bg-background/60",
      "scale-[0.97] opacity-0 transition-[opacity,scale,overlay,display] transition-discrete duration-200 ease-snappy motion-reduce:transition-none open:scale-100 open:opacity-100 starting:open:scale-[0.97] starting:open:opacity-0",
      "supports-[position-area:block-end]:mx-0 supports-[position-area:block-end]:my-1.5 supports-[position-area:block-end]:backdrop:bg-transparent supports-[position-area:block-end]:[position-area:block-end_span-inline-start] supports-[position-area:block-end]:[position-try-fallbacks:flip-block,flip-inline]",
      "data-[radial]:m-0! data-[radial]:size-[232px] data-[radial]:max-h-none data-[radial]:overflow-visible data-[radial]:rounded-full data-[radial]:border-border data-[radial]:bg-card data-[radial]:p-0 data-[radial]:backdrop:bg-transparent data-[radial]:[position-area:none]! data-[radial]:inset-[var(--mm-top)_auto_auto_var(--mm-left)]!",
    )}
  >
    <svg
      viewBox={`0 0 ${wheelSize} ${wheelSize}`}
      aria-hidden="true"
      class="pointer-events-none absolute inset-0 hidden size-full [[data-radial]_&]:block"
    >
      <g
        data-mm-wedge
        class="opacity-0 transition-opacity duration-150 ease-snappy motion-reduce:transition-none [[data-has-active]_&]:opacity-100"
        style="transform-box: view-box; transform-origin: 50% 50%;"
      >
        <path d={wedgePath} class="fill-accent" />
      </g>
    </svg>

    <div
      data-mm-hub
      class="pointer-events-auto absolute top-1/2 left-1/2 z-10 hidden size-16 -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center gap-0.5 rounded-full bg-muted p-1 text-center [[data-radial]_&]:flex"
    >
      <span data-mm-hub-label class="max-w-14 truncate text-[0.6875rem]/3.5 font-medium text-foreground">
        {triggerLabel}
      </span>
      <button
        type="button"
        popovertarget={menuId}
        popovertargetaction="hide"
        aria-label="Close radial menu"
        class="inline-flex size-5 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors duration-150 ease-snappy hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
      >
        <X class="size-3" aria-hidden="true" />
      </button>
    </div>

    <ul role="list" class="grid gap-0.5 [[data-radial]_&]:relative [[data-radial]_&]:block [[data-radial]_&]:size-full">
      {
        positioned.map((item) => {
          const itemClasses = cn(
            "flex min-h-9 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-left font-medium transition-[background-color,color,border-color,scale] duration-150 ease-snappy focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring motion-reduce:transition-none",
            "[[data-radial]_&]:h-auto [[data-radial]_&]:min-h-0 [[data-radial]_&]:w-14 [[data-radial]_&]:flex-col [[data-radial]_&]:justify-center [[data-radial]_&]:gap-1 [[data-radial]_&]:rounded-lg [[data-radial]_&]:outline-none [[data-radial]_&]:px-0.5 [[data-radial]_&]:py-1 [[data-radial]_&]:text-[0.6875rem]/4 [[data-radial]_&]:text-muted-foreground [[data-radial]_&]:hover:bg-transparent [[data-radial]_&]:focus-visible:bg-transparent [[data-radial]_&]:data-[active]:bg-transparent [[data-radial]_&]:data-[active]:text-foreground",
            item.destructive
              ? "text-destructive hover:bg-accent focus-visible:bg-accent data-[active]:bg-accent data-[active]:text-destructive"
              : "text-popover-foreground hover:bg-accent focus-visible:bg-accent data-[active]:bg-accent data-[active]:text-foreground",
          );

          return (
            <li
              style={`--mm-x: ${item.x}px; --mm-y: ${item.y}px;`}
              class="[[data-radial]_&]:absolute [[data-radial]_&]:[top:var(--mm-y)] [[data-radial]_&]:[left:var(--mm-x)] [[data-radial]_&]:-translate-x-1/2 [[data-radial]_&]:-translate-y-1/2"
            >
              {item.href ? (
                <a
                  href={item.href}
                  role="menuitem"
                  data-mm-item
                  data-index={item.index}
                  data-value={item.value ?? item.label.toLowerCase()}
                  data-label={item.label}
                  data-angle={item.angleDeg}
                  class={itemClasses}
                >
                  <item.Icon class="size-3.5 shrink-0 opacity-80 [[data-radial]_&]:size-4" aria-hidden="true" />
                  <span class="truncate [[data-radial]_&]:max-w-full">{item.label}</span>
                  {item.shortcut && (
                    <span class="ms-auto font-mono text-[0.6875rem]/4 text-muted-foreground [[data-radial]_&]:hidden">
                      {item.shortcut}
                    </span>
                  )}
                </a>
              ) : (
                <button
                  type="button"
                  role="menuitem"
                  data-mm-item
                  data-index={item.index}
                  data-value={item.value ?? item.label.toLowerCase()}
                  data-label={item.label}
                  data-angle={item.angleDeg}
                  class={itemClasses}
                >
                  <item.Icon class="size-3.5 shrink-0 opacity-80 [[data-radial]_&]:size-4" aria-hidden="true" />
                  <span class="truncate [[data-radial]_&]:max-w-full">{item.label}</span>
                  {item.shortcut && (
                    <span class="ms-auto font-mono text-[0.6875rem]/4 text-muted-foreground [[data-radial]_&]:hidden">
                      {item.shortcut}
                    </span>
                  )}
                </button>
              )}
            </li>
          );
        })
      }
    </ul>
  </div>
</div>

<script>
  function enhanceMarkingMenu(root: HTMLElement) {
    if (root.hasAttribute("data-enhanced")) return;
    const surface = root.querySelector<HTMLElement>("[data-mm-surface]");
    const trigger = root.querySelector<HTMLButtonElement>("[data-mm-trigger]");
    const menu = root.querySelector<HTMLElement>("[data-mm-menu]");
    const hubLabel = root.querySelector<HTMLElement>("[data-mm-hub-label]");
    const viewLabel = root.querySelector<HTMLElement>("[data-mm-view-label]");
    const chipIcons = Array.from(root.querySelectorAll<HTMLElement>("[data-mm-chip-icon]"));
    const wedge = root.querySelector<SVGGElement>("[data-mm-wedge]");
    const status = root.querySelector<HTMLElement>("[data-mm-status]");
    const items = Array.from(root.querySelectorAll<HTMLElement>("[data-mm-item]"));
    if (!surface || !trigger || !menu || !items.length || typeof menu.showPopover !== "function") return;

    const holdMs = Math.max(100, Number(root.dataset.holdMs) || 180);
    const defaultHubText = hubLabel?.textContent?.trim() || "Menu";
    const wheelSize = 232;
    let centerX = 0;
    let centerY = 0;
    let activeIndex = -1;
    let holdTimer = 0;
    let pointerDown = false;
    let holding = false;
    let pointerStartX = 0;
    let pointerStartY = 0;
    let opener: HTMLElement = trigger;

    const setActive = (index: number) => {
      activeIndex = index;
      items.forEach((item, i) => item.toggleAttribute("data-active", i === index));
      menu.toggleAttribute("data-has-active", index >= 0);
      if (wedge && index >= 0) {
        const deg = Number(items[index].dataset.angle) || 0;
        wedge.style.transform = `rotate(${deg}deg)`;
      }
      if (hubLabel) {
        hubLabel.textContent = index >= 0 ? (items[index].dataset.label ?? defaultHubText) : defaultHubText;
      }
    };

    const closeMenu = (restoreFocus: boolean) => {
      if (menu.matches(":popover-open")) menu.hidePopover();
      setActive(-1);
      if (restoreFocus) opener.focus({ preventScroll: true });
    };

    const activateItem = (item: HTMLElement) => {
      const index = Number(item.dataset.index);
      const label = item.dataset.label ?? item.textContent?.trim() ?? "";
      const value = item.dataset.value ?? label.toLowerCase();
      if (viewLabel) viewLabel.textContent = label;
      if (Number.isFinite(index)) {
        chipIcons.forEach((el, i) => el.toggleAttribute("data-hidden", i !== index));
      }
      if (status) status.textContent = `Switched view to ${label}`;
      root.dispatchEvent(new CustomEvent("haze:marking-menu-select", { detail: { label, value, index }, bubbles: true }));
      if (item.tagName !== "A") closeMenu(true);
      else closeMenu(false);
    };

    const openRadialAt = (clientX: number, clientY: number, focusFirst: boolean, source: HTMLElement) => {
      opener = source;
      const stageRect = root.getBoundingClientRect();
      const pad = 10;
      const minLeft = Math.max(8, stageRect.left + pad);
      const maxLeft = Math.min(document.documentElement.clientWidth - wheelSize - 8, stageRect.right - wheelSize - pad);
      const minTop = Math.max(8, stageRect.top + 46);
      const maxTop = Math.min(window.innerHeight - wheelSize - 8, stageRect.bottom - wheelSize - pad);

      const rawLeft = clientX - wheelSize / 2;
      const rawTop = clientY - wheelSize / 2;
      const left =
        maxLeft >= minLeft
          ? Math.round(Math.max(minLeft, Math.min(rawLeft, maxLeft)))
          : Math.round(Math.max(8, stageRect.left + (stageRect.width - wheelSize) / 2));
      const top =
        maxTop >= minTop
          ? Math.round(Math.max(minTop, Math.min(rawTop, maxTop)))
          : Math.round(Math.max(8, stageRect.top + (stageRect.height - wheelSize) / 2));

      centerX = left + wheelSize / 2;
      centerY = top + wheelSize / 2;
      menu.setAttribute("data-radial", "");
      menu.style.setProperty("--mm-left", `${left}px`);
      menu.style.setProperty("--mm-top", `${top}px`);
      if (!menu.matches(":popover-open")) menu.showPopover();
      setActive(focusFirst ? 0 : -1);
      if (focusFirst) items[0].focus({ preventScroll: true });
    };

    const angleToIndex = (dx: number, dy: number) => {
      const dist = Math.hypot(dx, dy);
      if (dist < 26) return -1;
      const deg = ((Math.atan2(dy, dx) * 180) / Math.PI + 90 + 360) % 360;
      const step = 360 / items.length;
      return Math.round(deg / step) % items.length;
    };

    surface.addEventListener("contextmenu", (event) => {
      event.preventDefault();
      openRadialAt(event.clientX, event.clientY, true, surface);
    });

    surface.addEventListener("pointerdown", (event) => {
      if (event.button !== 0) return;
      pointerDown = true;
      holding = false;
      pointerStartX = event.clientX;
      pointerStartY = event.clientY;
      surface.setPointerCapture(event.pointerId);
      clearTimeout(holdTimer);
      holdTimer = window.setTimeout(() => {
        if (!pointerDown) return;
        holding = true;
        openRadialAt(pointerStartX, pointerStartY, false, surface);
      }, holdMs);
    });

    surface.addEventListener("pointermove", (event) => {
      if (!pointerDown) return;
      if (!holding) {
        const dx = event.clientX - pointerStartX;
        const dy = event.clientY - pointerStartY;
        if (Math.hypot(dx, dy) > 20) {
          clearTimeout(holdTimer);
          holdTimer = 0;
          holding = true;
          openRadialAt(pointerStartX, pointerStartY, false, surface);
          setActive(angleToIndex(event.clientX - centerX, event.clientY - centerY));
        }
        return;
      }
      setActive(angleToIndex(event.clientX - centerX, event.clientY - centerY));
    });

    const endGesture = (event: PointerEvent, cancelled: boolean) => {
      clearTimeout(holdTimer);
      holdTimer = 0;
      if (surface.hasPointerCapture(event.pointerId)) {
        surface.releasePointerCapture(event.pointerId);
      }
      const wasHolding = holding;
      pointerDown = false;
      holding = false;
      if (cancelled || !wasHolding) return;
      if (activeIndex >= 0 && items[activeIndex]) {
        activateItem(items[activeIndex]);
      } else if (menu.matches(":popover-open")) {
        items[0].focus({ preventScroll: true });
        setActive(0);
      }
    };

    surface.addEventListener("pointerup", (event) => endGesture(event, false));
    surface.addEventListener("pointercancel", (event) => endGesture(event, true));

    surface.addEventListener("keydown", (event) => {
      if (event.target !== surface) return;
      if (event.key === "Enter" || event.key === " " || event.key === "ContextMenu" || (event.shiftKey && event.key === "F10")) {
        event.preventDefault();
        const rect = surface.getBoundingClientRect();
        openRadialAt(rect.left + rect.width / 2, rect.top + rect.height / 2, true, surface);
      }
    });

    trigger.addEventListener("click", (event) => {
      event.preventDefault();
      if (menu.matches(":popover-open")) {
        closeMenu(true);
        return;
      }
      const rect = surface.getBoundingClientRect();
      openRadialAt(rect.left + rect.width / 2, rect.top + rect.height / 2, true, trigger);
    });

    items.forEach((item, index) => {
      item.addEventListener("pointerenter", () => setActive(index));
      item.addEventListener("focus", () => setActive(index));
      item.addEventListener("click", (event) => {
        if (item.tagName !== "A") event.preventDefault();
        activateItem(item);
      });
    });

    menu.addEventListener("pointermove", (event) => {
      if (!menu.hasAttribute("data-radial") || event.buttons) return;
      if ((event.target as HTMLElement).closest("[data-mm-hub]")) return setActive(-1);
      setActive(angleToIndex(event.clientX - centerX, event.clientY - centerY));
    });
    menu.addEventListener("pointerleave", () => {
      if (menu.hasAttribute("data-radial") && !menu.contains(document.activeElement)) setActive(-1);
    });
    menu.addEventListener("click", (event) => {
      const target = event.target as HTMLElement;
      if (!menu.hasAttribute("data-radial") || target.closest("[data-mm-item],[data-mm-hub]")) return;
      if (activeIndex >= 0 && items[activeIndex]) items[activeIndex].click();
    });

    menu.addEventListener("keydown", (event) => {
      const current = items.indexOf(document.activeElement as HTMLElement);
      if (event.key === "Escape") {
        event.preventDefault();
        closeMenu(true);
        return;
      }
      let next: number | undefined;
      if (event.key === "ArrowRight" || event.key === "ArrowDown") {
        next = (current + 1) % items.length;
      } else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
        next = current <= 0 ? items.length - 1 : current - 1;
      } else if (event.key === "Home") {
        next = 0;
      } else if (event.key === "End") {
        next = items.length - 1;
      }
      if (next !== undefined) {
        event.preventDefault();
        items[next].focus();
        setActive(next);
      }
    });

    menu.addEventListener("toggle", () => {
      const open = menu.matches(":popover-open");
      trigger.setAttribute("aria-expanded", String(open));
      if (!open) setActive(-1);
    });

    root.setAttribute("data-enhanced", "");
  }

  const initMarkingMenus = () => {
    document.querySelectorAll<HTMLElement>("[data-haze-marking-menu]").forEach(enhanceMarkingMenu);
  };
  initMarkingMenus();
  if (!document.documentElement.hasAttribute("data-haze-marking-menu-listener")) {
    document.documentElement.setAttribute("data-haze-marking-menu-listener", "");
    document.addEventListener("astro:page-load", initMarkingMenus);
  }
</script>
```
