{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "liquid-glass-menu",
  "title": "Liquid Glass Menu",
  "description": "A dropdown menu with a liquid-glass surface that stays fully keyboard and screen-reader accessible. The round trigger flows into the panel as one blob of glass, the items sharpen from a blur, and a small glass lens slides to the highlighted item.",
  "dependencies": [
    "@base-ui/react",
    "@rexa-developer/tiks",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/liquid-glass-menu/liquid-glass-menu.tsx",
      "content": "\"use client\";\n\nimport { Menu as MenuPrimitive } from \"@base-ui/react/menu\";\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport {\n\ttype AnimationPlaybackControls,\n\tanimate,\n\tuseMotionValue,\n\tuseReducedMotion,\n} from \"motion/react\";\nimport {\n\tcreateContext,\n\ttype ReactNode,\n\ttype Ref,\n\ttype RefObject,\n\tuse,\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\n// Layout, in px, on a 4 px grid. Item corners are concentric with the\n// panel's: item radius = panel radius - panel padding.\nconst PANEL_RADIUS = 24;\nconst PANEL_PADDING = 8;\nconst ITEM_RADIUS = PANEL_RADIUS - PANEL_PADDING;\n/** How far the panel reaches past a trigger it swallows, all round. */\nconst ABSORB_INSET = 4;\n/** Gap to a trigger the panel doesn't swallow. */\nconst SIDE_OFFSET = 8;\n\n// Motion. Progress runs from 0 (glass the shape of the trigger) to 1 (the\n// panel). Only the glass changes shape; the popup itself never moves, so it\n// lands exactly where Base UI placed it.\n/** Critically damped: settles in about 300 ms with no overshoot. */\nconst openSpring = {\n\ttype: \"spring\",\n\tstiffness: 520,\n\tdamping: 46,\n\trestDelta: 0.002,\n\trestSpeed: 0.02,\n} as const;\n/** The drain: a smooth shrink that eases into the trigger without lingering. */\nconst CLOSE_MS = 240;\nconst CLOSE_EASE = [0.4, 0, 0.2, 1] as const;\n/** Progress from which the lens may show on the growing panel. */\nconst SETTLED_AT = 0.96;\n/** Critically damped, about 150 ms between neighbouring items. */\nconst lensSpring = { type: \"spring\", stiffness: 600, damping: 49 } as const;\n\n/** The frost behind the glass: a calm blur and a little saturation. */\nconst GLASS_BLUR = \"blur(24px) saturate(150%)\";\n\n// Refraction: a displacement map that bends the backdrop at the panel's rim.\n/** Width of the bent band at the panel's rim, in px. */\nconst PANEL_BEZEL = 16;\n/** Furthest the backdrop is pulled in at the very rim, in px. */\nconst PANEL_BEND = 6;\n/** The bend swells in once the panel is at rest, in s. */\nconst REFRACT_SWELL = 0.24;\n\n// The glass. The trigger and the panel share it, so one can become the other\n// without a seam. Light and dark are tuned separately, not inverted.\n/** Clear enough to show the backdrop, opaque enough for AA text over it. */\nconst GLASS_FILL = \"bg-[rgb(255_255_255/0.6)] dark:bg-[rgb(36_36_42/0.76)]\";\n/** No `backdrop-filter`, or reduced transparency: frosted, but solid. */\nconst SOLID_FILL =\n\t\"bg-[linear-gradient(to_bottom,#fdfdfd,#f4f4f6)] dark:bg-[linear-gradient(to_bottom,#2c2c31,#232327)]\";\n/**\n * A 0.5 px specular hairline that is brightest along the top and fades down\n * the sides, a faint contour to hold the edge on light pages, and a small,\n * soft lift.\n */\nconst GLASS_EDGE =\n\t\"shadow-[inset_0_0.5px_0_rgb(255_255_255/0.9),inset_0_0_0_0.5px_rgb(255_255_255/0.3),0_0_0_0.5px_rgb(0_0_0/0.08),0_1px_2px_rgb(0_0_0/0.04),0_4px_12px_-4px_rgb(0_0_0/0.1)] dark:shadow-[inset_0_0.5px_0_rgb(255_255_255/0.24),inset_0_0_0_0.5px_rgb(255_255_255/0.07),0_0_0_0.5px_rgb(0_0_0/0.5),0_1px_2px_rgb(0_0_0/0.3),0_4px_12px_-4px_rgb(0_0_0/0.4)]\";\n/** The panel's wider ambient shadow, which grows in with it. */\nconst PANEL_SHADOW =\n\t\"shadow-[0_12px_32px_-12px_rgb(0_0_0/0.14)] dark:shadow-[0_16px_40px_-12px_rgb(0_0_0/0.55)]\";\n/** The lens: a faint, clear tint with the same top-weighted hairline. */\nconst LENS_GLASS =\n\t\"bg-[rgb(118_118_128/0.08)] shadow-[inset_0_0.5px_0_rgb(255_255_255/0.9),inset_0_0_0_0.5px_rgb(0_0_0/0.03)] dark:bg-[rgb(255_255_255/0.07)] dark:shadow-[inset_0_0.5px_0_rgb(255_255_255/0.16),inset_0_0_0_0.5px_rgb(255_255_255/0.025)]\";\nconst LENS_SOLID =\n\t\"bg-[rgb(0_0_0/0.045)] shadow-[inset_0_0.5px_0_rgb(255_255_255/0.9),inset_0_0_0_0.5px_rgb(0_0_0/0.04)] dark:bg-[rgb(255_255_255/0.07)] dark:shadow-[inset_0_0.5px_0_rgb(255_255_255/0.16),inset_0_0_0_0.5px_rgb(255_255_255/0.025)]\";\n/** Pressed: the lens dips a touch, like a soft key. */\nconst LENS_PRESSED = \"group-has-[[data-highlighted]:active]/lgm:scale-[0.985]\";\nconst LENS_PRESSED_GLASS =\n\t\"group-has-[[data-highlighted]:active]/lgm:bg-[rgb(118_118_128/0.13)] dark:group-has-[[data-highlighted]:active]/lgm:bg-[rgb(255_255_255/0.1)]\";\nconst LENS_PRESSED_SOLID =\n\t\"group-has-[[data-highlighted]:active]/lgm:bg-[rgb(0_0_0/0.07)] dark:group-has-[[data-highlighted]:active]/lgm:bg-[rgb(255_255_255/0.1)]\";\n\n// A clear glass pop on open, a lower and shorter one on close, and a tiny\n// tick on select.\nconst OPEN_SOUND = {\n\tname: \"liquid-glass-menu-open\",\n\tbaseFreq: 620,\n\tnoiseColor: \"pink\",\n\toscType: \"sine\",\n\tfilterFreq: 5200,\n\tfilterQ: 4,\n\tattack: 0.003,\n\tdecay: 1.1,\n\tbrightness: 5000,\n} as const;\nconst CLOSE_SOUND = {\n\t...OPEN_SOUND,\n\tname: \"liquid-glass-menu-close\",\n\tbaseFreq: 470,\n\tdecay: 0.75,\n} as const;\nconst TICK_SOUND = {\n\t...OPEN_SOUND,\n\tname: \"liquid-glass-menu-tick\",\n\tfilterFreq: 4200,\n\tfilterQ: 2,\n\tdecay: 0.8,\n} as const;\n\ntype Feedback = \"open\" | \"close\" | \"select\";\n\n/**\n * - `pending`: mounted, waiting a frame for Base UI to place it.\n * - `morph`: the glass grows out of the trigger and the items sharpen.\n * - `open`: at rest. No clip, no blur on the items, nothing animating.\n * - `drain`: shrinking back into the trigger.\n * - `static`: `morph={false}` or reduced motion; CSS transitions only.\n */\ntype Phase = \"idle\" | \"pending\" | \"morph\" | \"open\" | \"drain\" | \"static\";\n\ninterface GlassSupport {\n\t/** Translucent glass; false under reduced transparency or without `backdrop-filter`. */\n\tglass: boolean;\n\t/** SVG displacement through `backdrop-filter: url()`, Chromium only. */\n\trefract: boolean;\n}\n\ninterface LiquidGlassMenuContextValue {\n\topen: boolean;\n\tmorph: boolean;\n\tsupport: GlassSupport;\n\ttriggerRef: RefObject<HTMLButtonElement | null>;\n\t/** The default round trigger is in use, so the panel swallows it. */\n\troundTriggerRef: RefObject<boolean>;\n\t/** Opened at mount by `defaultOpen` or `open`: shown at rest, no morph. */\n\topenAtMountRef: RefObject<boolean>;\n\t/** A mouse press that started on the trigger and hasn't come up yet. */\n\ttriggerPressRef: RefObject<boolean>;\n\tfeedback: (kind: Feedback) => void;\n}\n\nconst LiquidGlassMenuContext =\n\tcreateContext<LiquidGlassMenuContextValue | null>(null);\n\nfunction useLiquidGlassMenu() {\n\tconst context = use(LiquidGlassMenuContext);\n\tif (!context) {\n\t\tthrow new Error(\n\t\t\t\"LiquidGlassMenu parts must be used inside <LiquidGlassMenu>.\",\n\t\t);\n\t}\n\treturn context;\n}\n\nfunction clamp(value: number, min: number, max: number) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nfunction round(value: number) {\n\treturn Math.round(value * 1000) / 1000;\n}\n\nfunction setRefs<T>(value: T, ...refs: Array<Ref<T> | undefined>) {\n\tfor (const ref of refs) {\n\t\tif (typeof ref === \"function\") ref(value);\n\t\telse if (ref) ref.current = value;\n\t}\n}\n\ntype ClassName<State> = string | ((state: State) => string | undefined);\n\n/** Prepends classes to Base UI's `className`, which may be a function of state. */\nfunction withClasses<State>(base: string, className?: ClassName<State>) {\n\tif (typeof className === \"function\") {\n\t\treturn (state: State) => cn(base, className(state));\n\t}\n\treturn cn(base, className);\n}\n\nfunction supportsBackdrop() {\n\treturn (\n\t\tCSS.supports(\"backdrop-filter\", \"blur(1px)\") ||\n\t\tCSS.supports(\"-webkit-backdrop-filter\", \"blur(1px)\")\n\t);\n}\n\n/**\n * Glass needs `backdrop-filter`; refraction also needs SVG filters inside it,\n * which only Chromium draws. Safari and Firefox parse `url()` there but drop\n * the whole filter, so a parse check alone isn't enough: `userAgentData` is\n * the Chromium-only signal.\n */\nfunction useGlassSupport(refraction: \"auto\" | \"off\"): GlassSupport {\n\tconst [support, setSupport] = useState<GlassSupport>({\n\t\tglass: true,\n\t\trefract: false,\n\t});\n\tuseEffect(() => {\n\t\tconst transparency = window.matchMedia(\n\t\t\t\"(prefers-reduced-transparency: reduce)\",\n\t\t);\n\t\tconst update = () => {\n\t\t\tconst glass = supportsBackdrop() && !transparency.matches;\n\t\t\tconst refract =\n\t\t\t\tglass &&\n\t\t\t\trefraction === \"auto\" &&\n\t\t\t\tCSS.supports(\"backdrop-filter\", \"url(#a)\") &&\n\t\t\t\t\"userAgentData\" in navigator;\n\t\t\tsetSupport((current) =>\n\t\t\t\tcurrent.glass === glass && current.refract === refract\n\t\t\t\t\t? current\n\t\t\t\t\t: { glass, refract },\n\t\t\t);\n\t\t};\n\t\tupdate();\n\t\ttransparency.addEventListener(\"change\", update);\n\t\treturn () => transparency.removeEventListener(\"change\", update);\n\t}, [refraction]);\n\treturn support;\n}\n\n/**\n * A displacement map for a rounded rect, and the filter `scale` that goes with\n * it. Within `bezel` of the rim it points inward by up to `bend` px, easing in\n * toward the edge, so the glass samples from further in and the backdrop bends\n * like it does at the edge of a lens. Flat everywhere else.\n */\nfunction displacementMap(\n\twidth: number,\n\theight: number,\n\tradius: number,\n\tbezel: number,\n\tbend: number,\n) {\n\tconst halfWidth = width / 2;\n\tconst halfHeight = height / 2;\n\tconst scale = Math.ceil(bend * 2);\n\tconst canvas = document.createElement(\"canvas\");\n\tcanvas.width = width;\n\tcanvas.height = height;\n\tconst context = canvas.getContext(\"2d\");\n\tif (!context) return { href: \"\", scale };\n\tconst image = context.createImageData(width, height);\n\tconst r = Math.min(radius, halfWidth, halfHeight);\n\tfor (let y = 0; y < height; y++) {\n\t\tfor (let x = 0; x < width; x++) {\n\t\t\tconst px = x + 0.5 - halfWidth;\n\t\t\tconst py = y + 0.5 - halfHeight;\n\t\t\tconst qx = Math.abs(px) - (halfWidth - r);\n\t\t\tconst qy = Math.abs(py) - (halfHeight - r);\n\t\t\tconst ox = Math.max(qx, 0);\n\t\t\tconst oy = Math.max(qy, 0);\n\t\t\tconst corner = Math.hypot(ox, oy);\n\t\t\tconst depth = r - corner - Math.min(Math.max(qx, qy), 0);\n\t\t\tlet nx = 0;\n\t\t\tlet ny = 0;\n\t\t\tif (corner > 0) {\n\t\t\t\tnx = ox / corner;\n\t\t\t\tny = oy / corner;\n\t\t\t} else if (qx > qy) nx = 1;\n\t\t\telse ny = 1;\n\t\t\t// Smoothstep, so the bend has no crease where the bezel starts.\n\t\t\tconst t = clamp(1 - depth / bezel, 0, 1);\n\t\t\tconst rim = bend * t * t * (3 - 2 * t);\n\t\t\tconst dx = -rim * nx * Math.sign(px);\n\t\t\tconst dy = -rim * ny * Math.sign(py);\n\t\t\tconst i = (y * width + x) * 4;\n\t\t\timage.data[i] = 128 + (127 * dx) / bend;\n\t\t\timage.data[i + 1] = 128 + (127 * dy) / bend;\n\t\t\timage.data[i + 2] = 128;\n\t\t\timage.data[i + 3] = 255;\n\t\t}\n\t}\n\tcontext.putImageData(image, 0, 0);\n\treturn { href: canvas.toDataURL(), scale };\n}\n\nexport interface LiquidGlassMenuProps extends MenuPrimitive.Root.Props {\n\t/**\n\t * Flow the trigger into the panel as one blob of glass, and back on close.\n\t * `false` gives a plain scale-and-fade popover.\n\t */\n\tmorph?: boolean;\n\t/**\n\t * Bend the backdrop at the rim of the glass and the lens where the browser\n\t * can (Chromium). Elsewhere, and with `\"off\"`, the glass is a clean blur.\n\t */\n\trefraction?: \"auto\" | \"off\";\n\t/** Play a glass pop on open and close, and a tick on select. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n}\n\nexport function LiquidGlassMenu({\n\tmorph = true,\n\trefraction = \"auto\",\n\tsound = true,\n\thaptics = true,\n\topen: openProp,\n\tdefaultOpen = false,\n\tonOpenChange,\n\t...props\n}: LiquidGlassMenuProps) {\n\tconst [internalOpen, setInternalOpen] = useState(defaultOpen);\n\tconst controlled = openProp !== undefined;\n\tconst open = controlled ? openProp : internalOpen;\n\tconst support = useGlassSupport(refraction);\n\n\tconst triggerRef = useRef<HTMLButtonElement | null>(null);\n\tconst roundTriggerRef = useRef(false);\n\tconst openAtMountRef = useRef(open);\n\tconst triggerPressRef = useRef(false);\n\n\tconst { trigger: haptic } = useWebHaptics();\n\t// Sound stays on under reduced motion; only movement is reduced.\n\tconst { pop: playOpen } = useTiks({\n\t\ttheme: OPEN_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\tconst { pop: playClose } = useTiks({\n\t\ttheme: CLOSE_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\tconst { click: playTick } = useTiks({\n\t\ttheme: TICK_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst latest = useRef({\n\t\tsound,\n\t\thaptics,\n\t\tplayOpen,\n\t\tplayClose,\n\t\tplayTick,\n\t\thaptic,\n\t});\n\tuseLayoutEffect(() => {\n\t\tlatest.current = { sound, haptics, playOpen, playClose, playTick, haptic };\n\t});\n\n\t// Called only for user input, so mounting and the `open` prop stay quiet.\n\tconst feedback = useCallback((kind: Feedback) => {\n\t\tif (document.visibilityState === \"hidden\") return;\n\t\tconst current = latest.current;\n\t\tif (current.sound) {\n\t\t\tif (kind === \"open\") current.playOpen();\n\t\t\telse if (kind === \"close\") current.playClose();\n\t\t\telse current.playTick();\n\t\t}\n\t\tif (current.haptics) {\n\t\t\tvoid current.haptic(\n\t\t\t\tkind === \"open\" ? \"light\" : kind === \"close\" ? \"soft\" : \"selection\",\n\t\t\t);\n\t\t}\n\t}, []);\n\n\tconst handleOpenChange: NonNullable<\n\t\tMenuPrimitive.Root.Props[\"onOpenChange\"]\n\t> = (next, details) => {\n\t\tonOpenChange?.(next, details);\n\t\tif (details.isCanceled) return;\n\t\tif (!controlled) setInternalOpen(next);\n\t\t// An item press already ticked; imperative calls aren't user input.\n\t\tif (\n\t\t\tdetails.reason === \"item-press\" ||\n\t\t\tdetails.reason === \"imperative-action\" ||\n\t\t\tdetails.reason === \"none\"\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\tfeedback(next ? \"open\" : \"close\");\n\t};\n\n\t// Only the first opening can skip the morph.\n\tuseLayoutEffect(() => {\n\t\tif (!open) openAtMountRef.current = false;\n\t}, [open]);\n\n\tconst context = useMemo<LiquidGlassMenuContextValue>(\n\t\t() => ({\n\t\t\topen,\n\t\t\tmorph,\n\t\t\tsupport,\n\t\t\ttriggerRef,\n\t\t\troundTriggerRef,\n\t\t\topenAtMountRef,\n\t\t\ttriggerPressRef,\n\t\t\tfeedback,\n\t\t}),\n\t\t[open, morph, support, feedback],\n\t);\n\n\treturn (\n\t\t<LiquidGlassMenuContext value={context}>\n\t\t\t<MenuPrimitive.Root\n\t\t\t\tdata-slot=\"liquid-glass-menu\"\n\t\t\t\topen={open}\n\t\t\t\tonOpenChange={handleOpenChange}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t</LiquidGlassMenuContext>\n\t);\n}\n\nfunction PlusIcon() {\n\treturn (\n\t\t<svg\n\t\t\taria-hidden\n\t\t\tviewBox=\"0 0 20 20\"\n\t\t\tfill=\"none\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeWidth={1.75}\n\t\t\tstrokeLinecap=\"round\"\n\t\t\tclassName=\"size-5\"\n\t\t>\n\t\t\t<path d=\"M10 4.5v11M4.5 10h11\" />\n\t\t</svg>\n\t);\n}\n\ntype TriggerBaseProps = Omit<\n\tMenuPrimitive.Trigger.Props,\n\t\"children\" | \"aria-label\" | \"aria-labelledby\"\n>;\n\n/** The default trigger has no text, so it needs `aria-label` or `aria-labelledby`. */\nexport type LiquidGlassMenuTriggerProps = TriggerBaseProps &\n\t(\n\t\t| {\n\t\t\t\tchildren: ReactNode;\n\t\t\t\t\"aria-label\"?: string;\n\t\t\t\t\"aria-labelledby\"?: string;\n\t\t  }\n\t\t| {\n\t\t\t\tchildren?: undefined;\n\t\t\t\t\"aria-label\": string;\n\t\t\t\t\"aria-labelledby\"?: string;\n\t\t  }\n\t\t| {\n\t\t\t\tchildren?: undefined;\n\t\t\t\t\"aria-label\"?: string;\n\t\t\t\t\"aria-labelledby\": string;\n\t\t  }\n\t);\n\n/**\n * A round glass button with a plus by default. Pass `render` to use your own\n * element; it keeps the menu behaviour and drops the glass styling.\n */\nexport function LiquidGlassMenuTrigger({\n\tclassName,\n\tchildren,\n\trender,\n\tref,\n\tonPointerDown,\n\tonKeyDown,\n\tonBlur,\n\t...props\n}: LiquidGlassMenuTriggerProps) {\n\tconst context = useLiquidGlassMenu();\n\tconst reducedMotion = useReducedMotion() ?? false;\n\tconst round = render === undefined;\n\tuseLayoutEffect(() => {\n\t\tcontext.roundTriggerRef.current = round;\n\t});\n\n\treturn (\n\t\t<MenuPrimitive.Trigger\n\t\t\tdata-slot=\"liquid-glass-menu-trigger\"\n\t\t\tdata-solid={!context.support.glass || undefined}\n\t\t\tdata-lgm-morph={(context.morph && !reducedMotion) || undefined}\n\t\t\tref={(element: HTMLButtonElement | null) => {\n\t\t\t\tcontext.triggerRef.current = element;\n\t\t\t\tsetRefs(element, ref as Ref<HTMLButtonElement> | undefined);\n\t\t\t}}\n\t\t\trender={render}\n\t\t\tonPointerDown={(event) => {\n\t\t\t\t// Pointer use: no focus ring, even when focus comes back from the menu.\n\t\t\t\tevent.currentTarget.dataset.lgmPointer = \"\";\n\t\t\t\tif (event.pointerType === \"mouse\" && event.button === 0) {\n\t\t\t\t\t// Cleared after the mouseup has reached the items.\n\t\t\t\t\tcontext.triggerPressRef.current = true;\n\t\t\t\t\tconst release = () =>\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tcontext.triggerPressRef.current = false;\n\t\t\t\t\t\t}, 0);\n\t\t\t\t\tdocument.addEventListener(\"pointerup\", release, {\n\t\t\t\t\t\tonce: true,\n\t\t\t\t\t\tcapture: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tonPointerDown?.(event);\n\t\t\t}}\n\t\t\tonKeyDown={(event) => {\n\t\t\t\tdelete event.currentTarget.dataset.lgmPointer;\n\t\t\t\tonKeyDown?.(event);\n\t\t\t}}\n\t\t\tonBlur={(event) => {\n\t\t\t\t// Focus leaving for good, not into the open menu.\n\t\t\t\tif (!event.currentTarget.hasAttribute(\"data-popup-open\")) {\n\t\t\t\t\tdelete event.currentTarget.dataset.lgmPointer;\n\t\t\t\t}\n\t\t\t\tonBlur?.(event);\n\t\t\t}}\n\t\t\tclassName={\n\t\t\t\tround\n\t\t\t\t\t? withClasses(\n\t\t\t\t\t\t\tcn(\n\t\t\t\t\t\t\t\t\"group/lgm-trigger relative inline-grid size-11 shrink-0 cursor-pointer select-none place-items-center rounded-full text-foreground outline-none [-webkit-tap-highlight-color:transparent]\",\n\t\t\t\t\t\t\t\t\"transition-[scale] duration-150 ease-out active:scale-[0.97] motion-reduce:transition-none\",\n\t\t\t\t\t\t\t\t\"focus-visible:not-data-lgm-pointer:ring-2 focus-visible:not-data-lgm-pointer:ring-ring focus-visible:not-data-lgm-pointer:ring-offset-2 focus-visible:not-data-lgm-pointer:ring-offset-background\",\n\t\t\t\t\t\t\t\t\"disabled:pointer-events-none disabled:opacity-50\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tclassName,\n\t\t\t\t\t\t)\n\t\t\t\t\t: className\n\t\t\t}\n\t\t\t{...props}\n\t\t>\n\t\t\t{round ? (\n\t\t\t\t<>\n\t\t\t\t\t{/* The same glass as the panel. While the panel has swallowed the\n\t\t\t\t\t    button it hides, at once when the panel is its exact double;\n\t\t\t\t\t    the icon dissolves under the growing glass. */}\n\t\t\t\t\t<span\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\tdata-slot=\"liquid-glass-menu-trigger-glass\"\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"pointer-events-none absolute inset-0 rounded-[inherit] transition-[opacity,background-color] duration-150 ease-out motion-reduce:transition-none\",\n\t\t\t\t\t\t\tcontext.support.glass\n\t\t\t\t\t\t\t\t? cn(\n\t\t\t\t\t\t\t\t\t\tGLASS_FILL,\n\t\t\t\t\t\t\t\t\t\t\"group-hover/lgm-trigger:bg-[rgb(255_255_255/0.7)] dark:group-hover/lgm-trigger:bg-[rgb(46_46_52/0.78)]\",\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: cn(\n\t\t\t\t\t\t\t\t\t\tSOLID_FILL,\n\t\t\t\t\t\t\t\t\t\t\"group-hover/lgm-trigger:bg-[linear-gradient(to_bottom,#fff,#f8f8fa)] dark:group-hover/lgm-trigger:bg-[linear-gradient(to_bottom,#323237,#29292d)]\",\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tGLASS_EDGE,\n\t\t\t\t\t\t\t\"group-data-lgm-hidden/lgm-trigger:opacity-0 group-data-lgm-morph/lgm-trigger:transition-[background-color]\",\n\t\t\t\t\t\t)}\n\t\t\t\t\t\tstyle={\n\t\t\t\t\t\t\tcontext.support.glass\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tbackdropFilter: GLASS_BLUR,\n\t\t\t\t\t\t\t\t\t\tWebkitBackdropFilter: GLASS_BLUR,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-slot=\"liquid-glass-menu-trigger-icon\"\n\t\t\t\t\t\tclassName=\"relative grid place-items-center transition-opacity duration-150 ease-out group-data-lgm-hidden/lgm-trigger:opacity-0 group-data-lgm-hidden/lgm-trigger:duration-[60ms] motion-reduce:transition-none\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{children ?? <PlusIcon />}\n\t\t\t\t\t</span>\n\t\t\t\t</>\n\t\t\t) : (\n\t\t\t\tchildren\n\t\t\t)}\n\t\t</MenuPrimitive.Trigger>\n\t);\n}\n\ntype PositionerProps = MenuPrimitive.Positioner.Props;\n\nexport interface LiquidGlassMenuContentProps extends MenuPrimitive.Popup.Props {\n\t/** Which side of the trigger the panel opens on. Defaults to `\"bottom\"`. */\n\tside?: PositionerProps[\"side\"];\n\t/** How the panel lines up with the trigger along that side. Defaults to `\"start\"`. */\n\talign?: PositionerProps[\"align\"];\n\t/**\n\t * Gap to the trigger, in px. Defaults to covering the round trigger, so the\n\t * panel grows out of it, or 8 px from any other trigger.\n\t */\n\tsideOffset?: PositionerProps[\"sideOffset\"];\n\t/** Shift along the aligned edge, in px. */\n\talignOffset?: PositionerProps[\"alignOffset\"];\n\t/** Space kept from the edge of the viewport, in px. Defaults to 8. */\n\tcollisionPadding?: PositionerProps[\"collisionPadding\"];\n}\n\n/** Where the glass starts, relative to the popup, in px. */\ninterface Shape {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n\tradius: number;\n}\n\n/** Half-px steps: crisp at 2x, and no shimmer from tiny fractions. */\nfunction snap(value: number) {\n\treturn Math.round(value * 2) / 2;\n}\n\n/**\n * The glass panel. With the default round trigger and `morph` on, it is placed\n * over the trigger and grows out of it; otherwise it sits `sideOffset` away.\n */\nexport function LiquidGlassMenuContent({\n\tside = \"bottom\",\n\talign = \"start\",\n\tsideOffset,\n\talignOffset,\n\tcollisionPadding = 8,\n\tclassName,\n\tchildren,\n\tref,\n\t...props\n}: LiquidGlassMenuContentProps) {\n\tconst context = useLiquidGlassMenu();\n\tconst { open, morph, support, triggerRef, roundTriggerRef, openAtMountRef } =\n\t\tcontext;\n\tconst reducedMotion = useReducedMotion() ?? false;\n\tconst morphing = morph && !reducedMotion;\n\tconst mode = !morph ? \"pop\" : reducedMotion ? \"fade\" : \"morph\";\n\n\tconst ids = useId().replace(/[^\\w-]/g, \"\");\n\tconst panelFilterId = `liquid-glass-menu-${ids}-panel`;\n\n\tconst popupRef = useRef<HTMLDivElement | null>(null);\n\tconst viewportRef = useRef<HTMLDivElement | null>(null);\n\tconst shellRef = useRef<HTMLSpanElement | null>(null);\n\tconst ambientRef = useRef<HTMLSpanElement | null>(null);\n\tconst lensRef = useRef<HTMLSpanElement | null>(null);\n\tconst panelMapRef = useRef<SVGFEImageElement | null>(null);\n\tconst panelFilterRef = useRef<SVGFilterElement | null>(null);\n\tconst panelDisplaceRef = useRef<SVGFEDisplacementMapElement | null>(null);\n\tconst [popup, setPopup] = useState<HTMLDivElement | null>(null);\n\n\tconst progress = useMotionValue(0);\n\tconst lensX = useMotionValue(0);\n\tconst lensY = useMotionValue(0);\n\tconst lensWidth = useMotionValue(0);\n\tconst lensHeight = useMotionValue(0);\n\n\tconst phaseRef = useRef<Phase>(\"idle\");\n\tconst animationRef = useRef<AnimationPlaybackControls | null>(null);\n\tconst lensAnimationRef = useRef<AnimationPlaybackControls[]>([]);\n\tconst swellRef = useRef<AnimationPlaybackControls | null>(null);\n\tconst holdRef = useRef<Animation | null>(null);\n\tconst frameRef = useRef(0);\n\tconst lensShownRef = useRef(false);\n\tconst lensHideRef = useRef<ReturnType<typeof setTimeout> | undefined>(\n\t\tundefined,\n\t);\n\tconst lensItemRef = useRef<HTMLElement | null>(null);\n\t/** Whether the panel covers the trigger; measured when it opens. */\n\tconst absorbedRef = useRef(false);\n\t/** The trigger's shape inside the panel, where the glass grows from. */\n\tconst fromRef = useRef<Shape | null>(null);\n\tconst panelScaleRef = useRef(0);\n\n\tconst latest = useRef({ morphing, refract: support.refract, reducedMotion });\n\tuseLayoutEffect(() => {\n\t\tlatest.current = { morphing, refract: support.refract, reducedMotion };\n\t});\n\n\tconst clearTimers = () => {\n\t\tcancelAnimationFrame(frameRef.current);\n\t\tclearTimeout(lensHideRef.current);\n\t};\n\n\t/** The rim only bends at rest: Chromium feeds `url()` filters a stale\n\t * backdrop while their element changes. It swells in from no bend. */\n\tconst refract = (on: boolean) => {\n\t\tconst shell = shellRef.current;\n\t\tconst displace = panelDisplaceRef.current;\n\t\tif (!shell || !displace || !latest.current.refract) return;\n\t\tswellRef.current?.stop();\n\t\tif (!on) {\n\t\t\tshell.style.backdropFilter = GLASS_BLUR;\n\t\t\treturn;\n\t\t}\n\t\tconst target = panelScaleRef.current;\n\t\tdisplace.setAttribute(\"scale\", \"0\");\n\t\tshell.style.backdropFilter = `${GLASS_BLUR} url(#${panelFilterId})`;\n\t\tif (latest.current.reducedMotion) {\n\t\t\tdisplace.setAttribute(\"scale\", String(target));\n\t\t\treturn;\n\t\t}\n\t\tswellRef.current = animate(0, target, {\n\t\t\tduration: REFRACT_SWELL,\n\t\t\tease: \"easeOut\",\n\t\t\tonUpdate: (value) => displace.setAttribute(\"scale\", String(round(value))),\n\t\t});\n\t};\n\n\tconst setPhase = (phase: Phase) => {\n\t\tphaseRef.current = phase;\n\t\tconst element = popupRef.current;\n\t\tif (!element) return;\n\t\telement.dataset.lgmPhase = phase;\n\t\tconst resting = phase === \"open\" || phase === \"static\";\n\t\tif (resting) element.dataset.lgmRest = \"\";\n\t\telse if (phase !== \"morph\") delete element.dataset.lgmRest;\n\t\trefract(resting);\n\t};\n\n\tconst hideTrigger = (hidden: boolean) => {\n\t\tconst trigger = triggerRef.current;\n\t\tif (!trigger) return;\n\t\tif (hidden && absorbedRef.current) trigger.dataset.lgmHidden = \"\";\n\t\telse delete trigger.dataset.lgmHidden;\n\t};\n\n\t/** Writes the glass's shape for the current progress. */\n\tconst paint = () => {\n\t\tconst element = popupRef.current;\n\t\tconst shell = shellRef.current;\n\t\tconst viewport = viewportRef.current;\n\t\tconst from = fromRef.current;\n\t\tif (!element || !shell || !viewport || !from) return;\n\t\tconst width = element.offsetWidth;\n\t\tconst height = element.offsetHeight;\n\t\tif (!width || !height) return;\n\t\tconst value = clamp(progress.get(), 0, 1);\n\t\tconst rest = 1 - value;\n\t\tconst w = from.width + (width - from.width) * value;\n\t\tconst h = from.height + (height - from.height) * value;\n\t\tconst left = snap(from.x * rest);\n\t\tconst top = snap(from.y * rest);\n\t\tconst right = snap(width - from.x * rest - w);\n\t\tconst bottom = snap(height - from.y * rest - h);\n\t\tconst radius = round(\n\t\t\tMath.min(\n\t\t\t\tfrom.radius + (PANEL_RADIUS - from.radius) * value,\n\t\t\t\tw / 2,\n\t\t\t\th / 2,\n\t\t\t),\n\t\t);\n\t\tconst inset = `${top}px ${right}px ${bottom}px ${left}px`;\n\t\tshell.style.inset = inset;\n\t\tshell.style.borderRadius = `${radius}px`;\n\t\t// The rows only show inside the glass, never as ghosts around it.\n\t\tviewport.style.clipPath = `inset(${inset} round ${radius}px)`;\n\t\tif (ambientRef.current) {\n\t\t\tambientRef.current.style.opacity = String(round(value));\n\t\t}\n\t\t// A swallowed trigger is replaced by its double; beside one, the glass\n\t\t// fades in as it leaves it.\n\t\tshell.style.opacity = absorbedRef.current\n\t\t\t? \"\"\n\t\t\t: String(round(clamp(value / 0.25, 0, 1)));\n\t};\n\n\tconst clearPaint = () => {\n\t\tconst shell = shellRef.current;\n\t\tif (shell) {\n\t\t\tshell.style.inset = \"\";\n\t\t\tshell.style.borderRadius = \"\";\n\t\t\tshell.style.opacity = \"\";\n\t\t}\n\t\tif (viewportRef.current) viewportRef.current.style.clipPath = \"\";\n\t\tif (ambientRef.current) ambientRef.current.style.opacity = \"\";\n\t};\n\n\tconst paintRef = useRef(paint);\n\tuseLayoutEffect(() => {\n\t\tpaintRef.current = paint;\n\t});\n\n\tuseEffect(() => progress.on(\"change\", () => paintRef.current()), [progress]);\n\n\t// The lens is written by hand rather than through `motion.*`, which would\n\t// add window listeners for layout projection.\n\tuseLayoutEffect(() => {\n\t\tconst paintLens = () => {\n\t\t\tconst lens = lensRef.current;\n\t\t\tif (!lens) return;\n\t\t\tlens.style.transform = `translate(${round(lensX.get())}px, ${round(lensY.get())}px)`;\n\t\t\tlens.style.width = `${round(lensWidth.get())}px`;\n\t\t\tlens.style.height = `${round(lensHeight.get())}px`;\n\t\t};\n\t\tconst stops = [lensX, lensY, lensWidth, lensHeight].map((value) =>\n\t\t\tvalue.on(\"change\", paintLens),\n\t\t);\n\t\tpaintLens();\n\t\treturn () => {\n\t\t\tfor (const stop of stops) stop();\n\t\t};\n\t}, [lensX, lensY, lensWidth, lensHeight]);\n\n\tconst updatePanelMap = () => {\n\t\tconst element = popupRef.current;\n\t\tconst map = panelMapRef.current;\n\t\tconst filter = panelFilterRef.current;\n\t\tif (!element || !map || !filter) return;\n\t\tconst width = element.offsetWidth;\n\t\tconst height = element.offsetHeight;\n\t\tif (!width || !height) return;\n\t\tconst { href, scale } = displacementMap(\n\t\t\twidth,\n\t\t\theight,\n\t\t\tPANEL_RADIUS,\n\t\t\tPANEL_BEZEL,\n\t\t\tPANEL_BEND,\n\t\t);\n\t\tfor (const node of [filter, map]) {\n\t\t\tnode.setAttribute(\"width\", String(width));\n\t\t\tnode.setAttribute(\"height\", String(height));\n\t\t}\n\t\tmap.setAttribute(\"href\", href);\n\t\tpanelScaleRef.current = scale;\n\t};\n\n\t/** Moves the lens onto the highlighted item, or hides it. */\n\tconst updateLens = () => {\n\t\tconst viewport = viewportRef.current;\n\t\tconst element = popupRef.current;\n\t\tconst lens = lensRef.current;\n\t\tif (!viewport || !element || !lens) return;\n\t\tconst item = viewport.querySelector<HTMLElement>(\"[data-highlighted]\");\n\t\tconst visible = Boolean(item) && \"lgmRest\" in element.dataset;\n\t\tclearTimeout(lensHideRef.current);\n\t\tif (!item || !visible) {\n\t\t\t// The highlight clears for a moment between rows; only hide for real\n\t\t\t// if nothing takes it, so the lens glides rather than blinks.\n\t\t\tconst hide = () => {\n\t\t\t\tlens.dataset.visible = \"false\";\n\t\t\t\tlensShownRef.current = false;\n\t\t\t\tlensItemRef.current = null;\n\t\t\t};\n\t\t\tif (item || !lensShownRef.current) hide();\n\t\t\telse lensHideRef.current = setTimeout(hide, 80);\n\t\t\treturn;\n\t\t}\n\t\tlens.dataset.visible = \"true\";\n\t\tif (item === lensItemRef.current && lensShownRef.current) return;\n\t\tlensItemRef.current = item;\n\t\tconst box = viewport.getBoundingClientRect();\n\t\tconst rect = item.getBoundingClientRect();\n\t\tconst scale = box.width / (viewport.offsetWidth || box.width) || 1;\n\t\tconst x = Math.round((rect.left - box.left) / scale + viewport.scrollLeft);\n\t\tconst y = Math.round((rect.top - box.top) / scale + viewport.scrollTop);\n\t\tconst width = Math.round(rect.width / scale);\n\t\tconst height = Math.round(rect.height / scale);\n\n\t\tfor (const animation of lensAnimationRef.current) animation.stop();\n\t\t// A lens that is just appearing fades in where it is needed.\n\t\tconst jump = !lensShownRef.current || latest.current.reducedMotion;\n\t\tlensShownRef.current = true;\n\t\tif (jump) {\n\t\t\tlensX.jump(x);\n\t\t\tlensY.jump(y);\n\t\t\tlensWidth.jump(width);\n\t\t\tlensHeight.jump(height);\n\t\t\treturn;\n\t\t}\n\t\tlensAnimationRef.current = [\n\t\t\tanimate(lensX, x, lensSpring),\n\t\t\tanimate(lensY, y, lensSpring),\n\t\t\tanimate(lensWidth, width, lensSpring),\n\t\t\tanimate(lensHeight, height, lensSpring),\n\t\t];\n\t};\n\n\tconst updateLensRef = useRef(updateLens);\n\tuseLayoutEffect(() => {\n\t\tupdateLensRef.current = updateLens;\n\t});\n\n\t/** Whether the placed panel covers the trigger, and where the glass starts. */\n\tconst measure = (element: HTMLElement, trigger: HTMLElement) => {\n\t\tconst anchor = trigger.getBoundingClientRect();\n\t\tconst place = element.getBoundingClientRect();\n\t\tconst width = element.offsetWidth;\n\t\tconst height = element.offsetHeight;\n\t\tabsorbedRef.current =\n\t\t\tanchor.left >= place.left - 1 &&\n\t\t\tanchor.right <= place.right + 1 &&\n\t\t\tanchor.top >= place.top - 1 &&\n\t\t\tanchor.bottom <= place.bottom + 1;\n\t\tconst x = anchor.left - place.left;\n\t\tconst y = anchor.top - place.top;\n\t\tif (absorbedRef.current) {\n\t\t\tconst radius = Math.min(\n\t\t\t\tNumber.parseFloat(getComputedStyle(trigger).borderTopLeftRadius) || 0,\n\t\t\t\tMath.min(anchor.width, anchor.height) / 2,\n\t\t\t);\n\t\t\tfromRef.current = {\n\t\t\t\tx,\n\t\t\t\ty,\n\t\t\t\twidth: anchor.width,\n\t\t\t\theight: anchor.height,\n\t\t\t\tradius,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\t// Beside the trigger: a pill as wide as it, on the panel's near edge.\n\t\tconst placed = element.dataset.side ?? side;\n\t\tconst vertical = placed === \"top\" || placed === \"bottom\";\n\t\tconst w = Math.min(anchor.width, width);\n\t\tconst h = Math.min(anchor.height, height);\n\t\tconst before = placed === \"top\" || placed === \"left\";\n\t\tfromRef.current = vertical\n\t\t\t? {\n\t\t\t\t\tx: clamp(x, 0, width - w),\n\t\t\t\t\ty: before ? height - h : 0,\n\t\t\t\t\twidth: w,\n\t\t\t\t\theight: h,\n\t\t\t\t\tradius: Math.min(h / 2, PANEL_RADIUS),\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tx: placed === \"right\" || placed === \"inline-end\" ? 0 : width - w,\n\t\t\t\t\ty: clamp(y, 0, height - h),\n\t\t\t\t\twidth: w,\n\t\t\t\t\theight: h,\n\t\t\t\t\tradius: Math.min(w / 2, PANEL_RADIUS),\n\t\t\t\t};\n\t};\n\n\t/** Rows sharpen in order of distance from the trigger. */\n\tconst orderItems = (element: HTMLElement) => {\n\t\tconst items = element.querySelectorAll<HTMLElement>(\"[data-lgm-item]\");\n\t\tconst from = fromRef.current;\n\t\tconst fromBottom = from\n\t\t\t? from.y + from.height / 2 > element.offsetHeight / 2\n\t\t\t: false;\n\t\titems.forEach((item, index) => {\n\t\t\tconst order = fromBottom ? items.length - 1 - index : index;\n\t\t\titem.style.setProperty(\"--lgm-i\", String(order));\n\t\t});\n\t};\n\n\tconst settle = () => {\n\t\tclearPaint();\n\t\tsetPhase(\"open\");\n\t};\n\n\tconst startOpen = () => {\n\t\tconst element = popupRef.current;\n\t\tconst trigger = triggerRef.current;\n\t\tif (!element) return;\n\t\tconst phase = phaseRef.current;\n\t\tif (phase === \"pending\" || phase === \"morph\" || phase === \"open\") return;\n\t\tif (phase === \"static\" && !holdRef.current) return;\n\t\tholdRef.current?.cancel();\n\t\tholdRef.current = null;\n\t\tclearTimers();\n\t\t// A drain this interrupts holds still until the open picks it up.\n\t\tanimationRef.current?.stop();\n\t\telement.style.opacity = \"\";\n\t\tif (phase !== \"drain\") {\n\t\t\t// Whole px, so the glass's edges and its refraction map land on pixels.\n\t\t\telement.style.width = \"\";\n\t\t\tconst width = Number.parseFloat(getComputedStyle(element).width);\n\t\t\tif (width) element.style.width = `${Math.ceil(width - 0.01)}px`;\n\t\t}\n\t\tif (latest.current.refract) updatePanelMap();\n\n\t\tconst atRest = !latest.current.morphing || openAtMountRef.current;\n\t\tif (atRest || !trigger) {\n\t\t\tprogress.jump(1);\n\t\t\tclearPaint();\n\t\t\tsetPhase(latest.current.morphing ? \"open\" : \"static\");\n\t\t\t// Base UI places the popup during the first frame; measure after it.\n\t\t\tframeRef.current = requestAnimationFrame(() => {\n\t\t\t\tif (!trigger) return;\n\t\t\t\tmeasure(element, trigger);\n\t\t\t\thideTrigger(true);\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst resuming = phase === \"drain\";\n\t\tif (!resuming) {\n\t\t\tprogress.jump(0);\n\t\t\tsetPhase(\"pending\");\n\t\t}\n\t\tframeRef.current = requestAnimationFrame(() => {\n\t\t\tif (!resuming) measure(element, trigger);\n\t\t\torderItems(element);\n\t\t\thideTrigger(true);\n\t\t\tsetPhase(\"morph\");\n\t\t\tpaintRef.current();\n\t\t\tanimationRef.current?.stop();\n\t\t\tanimationRef.current = animate(progress, 1, {\n\t\t\t\t...openSpring,\n\t\t\t\tonUpdate: (value) => {\n\t\t\t\t\tif (value >= SETTLED_AT && !(\"lgmRest\" in element.dataset)) {\n\t\t\t\t\t\telement.dataset.lgmRest = \"\";\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tonComplete: settle,\n\t\t\t});\n\t\t});\n\t};\n\n\tconst startClose = () => {\n\t\tconst element = popupRef.current;\n\t\tif (!element) return;\n\t\tconst phase = phaseRef.current;\n\t\tclearTimers();\n\t\tfor (const animation of lensAnimationRef.current) animation.stop();\n\t\tif (phase === \"idle\") return;\n\t\tanimationRef.current?.stop();\n\t\tif (phase === \"static\" || !latest.current.morphing || phase === \"pending\") {\n\t\t\t// The panel fades out over the trigger as it fades back in. Base UI\n\t\t\t// unmounts once the popup's own animations finish; this one keeps it\n\t\t\t// mounted for as long as the children's fade runs.\n\t\t\thideTrigger(false);\n\t\t\tif (phase === \"static\") {\n\t\t\t\tholdRef.current = element.animate(\n\t\t\t\t\t[{ outlineColor: \"transparent\" }, { outlineColor: \"transparent\" }],\n\t\t\t\t\t{ duration: 150 },\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst trigger = triggerRef.current;\n\t\tconst from = clamp(progress.get(), 0, 1);\n\t\t// Opened at rest: measure where to drain to now.\n\t\tif (phase === \"open\" && trigger) measure(element, trigger);\n\t\tconst duration = CLOSE_MS * Math.max(from, 0.4);\n\t\tholdRef.current = element.animate(\n\t\t\t[{ outlineColor: \"transparent\" }, { outlineColor: \"transparent\" }],\n\t\t\t{ duration },\n\t\t);\n\t\tsetPhase(\"drain\");\n\t\tupdateLensRef.current();\n\t\tpaintRef.current();\n\t\tanimationRef.current = animate(progress, 0, {\n\t\t\tduration: duration / 1000,\n\t\t\tease: CLOSE_EASE,\n\t\t\tonComplete: () => {\n\t\t\t\t// Back in the trigger's shape: swap to the trigger in one frame.\n\t\t\t\telement.style.opacity = \"0\";\n\t\t\t\thideTrigger(false);\n\t\t\t},\n\t\t});\n\t};\n\n\t/** Lets go of everything when the popup unmounts. */\n\tconst release = () => {\n\t\tclearTimers();\n\t\tanimationRef.current?.stop();\n\t\tswellRef.current?.stop();\n\t\tfor (const animation of lensAnimationRef.current) animation.stop();\n\t\tholdRef.current = null;\n\t\tphaseRef.current = \"idle\";\n\t\tlensShownRef.current = false;\n\t\tlensItemRef.current = null;\n\t\tfromRef.current = null;\n\t\thideTrigger(false);\n\t};\n\n\tconst startOpenRef = useRef(startOpen);\n\tconst startCloseRef = useRef(startClose);\n\tconst releaseRef = useRef(release);\n\tuseLayoutEffect(() => {\n\t\tstartOpenRef.current = startOpen;\n\t\tstartCloseRef.current = startClose;\n\t\treleaseRef.current = release;\n\t});\n\n\t// The popup only exists while the menu is open or draining.\n\tconst popupCallback = useCallback(\n\t\t(element: HTMLDivElement | null) => {\n\t\t\tpopupRef.current = element;\n\t\t\tsetPopup(element);\n\t\t\tsetRefs(element, ref as Ref<HTMLDivElement> | undefined);\n\t\t\tif (element) startOpenRef.current();\n\t\t\telse releaseRef.current();\n\t\t},\n\t\t[ref],\n\t);\n\n\t// Open and close while the popup is mounted: a reopen mid-drain flows back\n\t// out, and a close drains. Controlled changes animate the same way.\n\tuseLayoutEffect(() => {\n\t\tif (!popup) return;\n\t\tif (open) startOpenRef.current();\n\t\telse startCloseRef.current();\n\t}, [open, popup]);\n\n\t// The lens follows Base UI's highlight, from the pointer and the keyboard.\n\tuseEffect(() => {\n\t\tif (!popup) return;\n\t\tconst observer = new MutationObserver(() => updateLensRef.current());\n\t\tobserver.observe(popup, {\n\t\t\tattributes: true,\n\t\t\tattributeFilter: [\"data-highlighted\", \"data-lgm-rest\"],\n\t\t\tsubtree: true,\n\t\t});\n\t\treturn () => observer.disconnect();\n\t}, [popup]);\n\n\t// Focus returns to the trigger on close. After pointer use it shouldn't\n\t// show a ring there; after keys it should.\n\tuseEffect(() => {\n\t\tif (!popup) return;\n\t\tconst pointer = () => {\n\t\t\tif (triggerRef.current) triggerRef.current.dataset.lgmPointer = \"\";\n\t\t};\n\t\tconst key = () => {\n\t\t\tif (triggerRef.current) delete triggerRef.current.dataset.lgmPointer;\n\t\t};\n\t\tdocument.addEventListener(\"pointerdown\", pointer, true);\n\t\tdocument.addEventListener(\"keydown\", key, true);\n\t\treturn () => {\n\t\t\tdocument.removeEventListener(\"pointerdown\", pointer, true);\n\t\t\tdocument.removeEventListener(\"keydown\", key, true);\n\t\t};\n\t}, [popup, triggerRef]);\n\n\tuseEffect(() => () => releaseRef.current(), []);\n\n\tconst absorbs = () => morph && roundTriggerRef.current;\n\n\tconst glassStyle = support.glass\n\t\t? { backdropFilter: GLASS_BLUR, WebkitBackdropFilter: GLASS_BLUR }\n\t\t: undefined;\n\t// Without the morph, the children fade rather than the popup: opacity on\n\t// the popup would cut the glass off from the page behind it.\n\tconst fade =\n\t\tmode !== \"morph\" &&\n\t\t\"transition-opacity duration-150 ease-out group-data-ending-style/lgm:opacity-0 group-data-starting-style/lgm:opacity-0\";\n\n\treturn (\n\t\t<MenuPrimitive.Portal>\n\t\t\t{support.refract ? (\n\t\t\t\t<svg aria-hidden width={0} height={0} className=\"absolute\">\n\t\t\t\t\t<defs>\n\t\t\t\t\t\t<filter\n\t\t\t\t\t\t\tref={panelFilterRef}\n\t\t\t\t\t\t\tid={panelFilterId}\n\t\t\t\t\t\t\tx={0}\n\t\t\t\t\t\t\ty={0}\n\t\t\t\t\t\t\tfilterUnits=\"userSpaceOnUse\"\n\t\t\t\t\t\t\tprimitiveUnits=\"userSpaceOnUse\"\n\t\t\t\t\t\t\tcolorInterpolationFilters=\"sRGB\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<feImage\n\t\t\t\t\t\t\t\tref={panelMapRef}\n\t\t\t\t\t\t\t\tx={0}\n\t\t\t\t\t\t\t\ty={0}\n\t\t\t\t\t\t\t\tpreserveAspectRatio=\"none\"\n\t\t\t\t\t\t\t\tresult=\"map\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<feDisplacementMap\n\t\t\t\t\t\t\t\tref={panelDisplaceRef}\n\t\t\t\t\t\t\t\tin=\"SourceGraphic\"\n\t\t\t\t\t\t\t\tin2=\"map\"\n\t\t\t\t\t\t\t\tscale={0}\n\t\t\t\t\t\t\t\txChannelSelector=\"R\"\n\t\t\t\t\t\t\t\tyChannelSelector=\"G\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</filter>\n\t\t\t\t\t</defs>\n\t\t\t\t</svg>\n\t\t\t) : null}\n\t\t\t<MenuPrimitive.Positioner\n\t\t\t\tclassName=\"isolate z-50 outline-none\"\n\t\t\t\tside={side}\n\t\t\t\talign={align}\n\t\t\t\tcollisionPadding={collisionPadding}\n\t\t\t\tsideOffset={\n\t\t\t\t\tsideOffset ??\n\t\t\t\t\t(({ anchor, side: placed }) =>\n\t\t\t\t\t\tabsorbs()\n\t\t\t\t\t\t\t? -(\n\t\t\t\t\t\t\t\t\t(placed === \"top\" || placed === \"bottom\"\n\t\t\t\t\t\t\t\t\t\t? anchor.height\n\t\t\t\t\t\t\t\t\t\t: anchor.width) + ABSORB_INSET\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: SIDE_OFFSET)\n\t\t\t\t}\n\t\t\t\talignOffset={alignOffset ?? (() => (absorbs() ? -ABSORB_INSET : 0))}\n\t\t\t>\n\t\t\t\t<MenuPrimitive.Popup\n\t\t\t\t\tref={popupCallback}\n\t\t\t\t\tdata-slot=\"liquid-glass-menu-content\"\n\t\t\t\t\tdata-mode={mode}\n\t\t\t\t\tdata-solid={!support.glass || undefined}\n\t\t\t\t\tclassName={withClasses(\n\t\t\t\t\t\tcn(\n\t\t\t\t\t\t\t\"group/lgm relative flex max-h-(--available-height) min-w-48 flex-col rounded-[24px] text-foreground outline-none\",\n\t\t\t\t\t\t\tmode === \"pop\" &&\n\t\t\t\t\t\t\t\t\"origin-(--transform-origin) transition-[scale] duration-150 ease-out data-ending-style:scale-[0.96] data-starting-style:scale-[0.96]\",\n\t\t\t\t\t\t\t\"data-[lgm-phase=pending]:opacity-0\",\n\t\t\t\t\t\t\t// The items' blur and fade per phase; see `ITEM_MORPH`.\n\t\t\t\t\t\t\t\"data-[lgm-phase=pending]:[--lgm-fade:0] data-[lgm-phase=pending]:[--lgm-filter:blur(4px)]\",\n\t\t\t\t\t\t\t\"data-[lgm-phase=morph]:[--lgm-delay:80ms] data-[lgm-phase=morph]:[--lgm-duration:160ms] data-[lgm-phase=morph]:[--lgm-filter:blur(0px)] data-[lgm-phase=morph]:[--lgm-stagger:16ms]\",\n\t\t\t\t\t\t\t\"data-[lgm-phase=drain]:[--lgm-duration:70ms] data-[lgm-phase=drain]:[--lgm-fade:0]\",\n\t\t\t\t\t\t),\n\t\t\t\t\t\tclassName,\n\t\t\t\t\t)}\n\t\t\t\t\t{...props}\n\t\t\t\t>\n\t\t\t\t\t{/* The glass: blur, fill, hairline, and shadow. During the morph it\n\t\t\t\t\t    changes shape, from the trigger's to the panel's. */}\n\t\t\t\t\t<span\n\t\t\t\t\t\tref={shellRef}\n\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\tdata-slot=\"liquid-glass-menu-surface\"\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"pointer-events-none absolute inset-0 rounded-[inherit]\",\n\t\t\t\t\t\t\tsupport.glass ? GLASS_FILL : SOLID_FILL,\n\t\t\t\t\t\t\tGLASS_EDGE,\n\t\t\t\t\t\t\tfade,\n\t\t\t\t\t\t)}\n\t\t\t\t\t\tstyle={glassStyle}\n\t\t\t\t\t>\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tref={ambientRef}\n\t\t\t\t\t\t\tclassName={cn(\"absolute inset-0 rounded-[inherit]\", PANEL_SHADOW)}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</span>\n\t\t\t\t\t<div\n\t\t\t\t\t\tref={viewportRef}\n\t\t\t\t\t\tdata-slot=\"liquid-glass-menu-viewport\"\n\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\"relative min-h-0 flex-1 overflow-y-auto overscroll-contain rounded-[inherit] [scrollbar-width:thin]\",\n\t\t\t\t\t\t\tfade,\n\t\t\t\t\t\t)}\n\t\t\t\t\t\tstyle={{ padding: PANEL_PADDING }}\n\t\t\t\t\t>\n\t\t\t\t\t\t{/* The lens: a clear pill of glass under the highlighted item. */}\n\t\t\t\t\t\t<span\n\t\t\t\t\t\t\tref={lensRef}\n\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\tdata-slot=\"liquid-glass-menu-lens\"\n\t\t\t\t\t\t\tdata-visible=\"false\"\n\t\t\t\t\t\t\tclassName={cn(\n\t\t\t\t\t\t\t\t\"pointer-events-none absolute top-0 left-0 opacity-0 transition-[opacity,scale,background-color] duration-150 ease-out data-[visible=true]:opacity-100 motion-reduce:transition-none\",\n\t\t\t\t\t\t\t\tsupport.glass ? LENS_GLASS : LENS_SOLID,\n\t\t\t\t\t\t\t\tLENS_PRESSED,\n\t\t\t\t\t\t\t\tsupport.glass ? LENS_PRESSED_GLASS : LENS_PRESSED_SOLID,\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\tstyle={{ borderRadius: ITEM_RADIUS }}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<div className=\"relative flex flex-col\">{children}</div>\n\t\t\t\t\t</div>\n\t\t\t\t</MenuPrimitive.Popup>\n\t\t\t</MenuPrimitive.Positioner>\n\t\t</MenuPrimitive.Portal>\n\t);\n}\n\n/**\n * Every row starts blurred and clear, then sharpens 16 ms after the row\n * nearer the trigger. The values come from the popup's phase; at rest they\n * resolve to no filter at all.\n */\nconst ITEM_MORPH =\n\t\"[filter:var(--lgm-filter,none)] [opacity:calc(var(--lgm-fade,1)*var(--lgm-dim,1))] [transition-delay:calc(var(--lgm-delay,0ms)+var(--lgm-i,0)*var(--lgm-stagger,0ms))] [transition-duration:var(--lgm-duration,0ms)] [transition-property:filter,opacity] [transition-timing-function:cubic-bezier(0.2,0.8,0.2,1)]\";\n\n/**\n * 40 px rows (44 px on touch), 12 px in from the lens, with a 16 px icon\n * column and a 12 px gap, so labels line up whatever the row type. The lens\n * and a stronger label mark the highlight; nothing moves.\n */\nconst ITEM_CLASS = cn(\n\t\"group/lgm-item relative flex min-h-10 pointer-coarse:min-h-11 cursor-default select-none items-center gap-3 px-3 py-2 text-foreground/85 text-sm leading-5 outline-none [-webkit-tap-highlight-color:transparent] dark:text-foreground/90\",\n\t\"data-disabled:pointer-events-none data-highlighted:text-foreground data-disabled:[--lgm-dim:0.45]\",\n\tITEM_MORPH,\n);\n\nconst ICON_CLASS =\n\t\"grid min-w-4 shrink-0 place-items-center [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0\";\n\n/** The label and the shortcut share a baseline. */\nfunction ItemText({\n\tchildren,\n\tshortcut,\n}: {\n\tchildren?: ReactNode;\n\tshortcut?: ReactNode;\n}) {\n\treturn (\n\t\t<span className=\"flex min-w-0 flex-1 items-baseline gap-4\">\n\t\t\t<span className=\"min-w-0 flex-1 truncate\">{children}</span>\n\t\t\t{shortcut === undefined || shortcut === null ? null : (\n\t\t\t\t<span\n\t\t\t\t\tdata-slot=\"liquid-glass-menu-shortcut\"\n\t\t\t\t\tclassName=\"shrink-0 text-foreground/75 text-xs tabular-nums dark:text-foreground/80\"\n\t\t\t\t>\n\t\t\t\t\t{shortcut}\n\t\t\t\t</span>\n\t\t\t)}\n\t\t</span>\n\t);\n}\n\nfunction CheckIcon() {\n\treturn (\n\t\t<svg\n\t\t\taria-hidden\n\t\t\tviewBox=\"0 0 16 16\"\n\t\t\tfill=\"none\"\n\t\t\tstroke=\"currentColor\"\n\t\t\tstrokeWidth={1.75}\n\t\t\tstrokeLinecap=\"round\"\n\t\t\tstrokeLinejoin=\"round\"\n\t\t\tclassName=\"size-4\"\n\t\t>\n\t\t\t<path d=\"m3.5 8.5 3 3 6-7\" />\n\t\t</svg>\n\t);\n}\n\n/**\n * Stops a long press on the swallowed trigger from choosing whichever row has\n * grown over it by the time the button comes up. A press dragged onto a row\n * away from the trigger still chooses it.\n */\nfunction useReleaseGuard() {\n\tconst { triggerPressRef, triggerRef } = useLiquidGlassMenu();\n\treturn (event: {\n\t\tclientX: number;\n\t\tclientY: number;\n\t\tpreventBaseUIHandler?: () => void;\n\t}) => {\n\t\tconst trigger = triggerRef.current;\n\t\tif (!triggerPressRef.current || !trigger) return;\n\t\tconst rect = trigger.getBoundingClientRect();\n\t\tif (\n\t\t\tevent.clientX >= rect.left &&\n\t\t\tevent.clientX <= rect.right &&\n\t\t\tevent.clientY >= rect.top &&\n\t\t\tevent.clientY <= rect.bottom\n\t\t) {\n\t\t\tevent.preventBaseUIHandler?.();\n\t\t}\n\t};\n}\n\nexport interface LiquidGlassMenuItemProps\n\textends Omit<MenuPrimitive.Item.Props, \"children\"> {\n\t/** Leading icon, such as a lucide icon or a colored badge. Plain icons are drawn at 16 px. */\n\ticon?: ReactNode;\n\t/** Trailing hint, such as a keyboard shortcut. Shown, not bound. */\n\tshortcut?: ReactNode;\n\t/** The label. */\n\tchildren?: ReactNode;\n}\n\nexport function LiquidGlassMenuItem({\n\ticon,\n\tshortcut,\n\tchildren,\n\tclassName,\n\tonClick,\n\tonMouseUp,\n\t...props\n}: LiquidGlassMenuItemProps) {\n\tconst { feedback } = useLiquidGlassMenu();\n\tconst guard = useReleaseGuard();\n\treturn (\n\t\t<MenuPrimitive.Item\n\t\t\tdata-slot=\"liquid-glass-menu-item\"\n\t\t\tdata-lgm-item=\"\"\n\t\t\tclassName={withClasses(ITEM_CLASS, className)}\n\t\t\tonClick={(event) => {\n\t\t\t\tfeedback(\"select\");\n\t\t\t\tonClick?.(event);\n\t\t\t}}\n\t\t\tonMouseUp={(event) => {\n\t\t\t\tguard(event);\n\t\t\t\tonMouseUp?.(event);\n\t\t\t}}\n\t\t\t{...props}\n\t\t>\n\t\t\t{icon ? (\n\t\t\t\t<span data-slot=\"liquid-glass-menu-item-icon\" className={ICON_CLASS}>\n\t\t\t\t\t{icon}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t\t<ItemText shortcut={shortcut}>{children}</ItemText>\n\t\t</MenuPrimitive.Item>\n\t);\n}\n\nexport interface LiquidGlassMenuCheckboxItemProps\n\textends Omit<MenuPrimitive.CheckboxItem.Props, \"children\"> {\n\t/** Trailing hint, such as a keyboard shortcut. Shown, not bound. */\n\tshortcut?: ReactNode;\n\t/** The label. */\n\tchildren?: ReactNode;\n}\n\n/** A row that toggles. It stays open on click unless `closeOnClick` is set. */\nexport function LiquidGlassMenuCheckboxItem({\n\tshortcut,\n\tchildren,\n\tclassName,\n\tonClick,\n\tonMouseUp,\n\t...props\n}: LiquidGlassMenuCheckboxItemProps) {\n\tconst { feedback } = useLiquidGlassMenu();\n\tconst guard = useReleaseGuard();\n\treturn (\n\t\t<MenuPrimitive.CheckboxItem\n\t\t\tdata-slot=\"liquid-glass-menu-checkbox-item\"\n\t\t\tdata-lgm-item=\"\"\n\t\t\tclassName={withClasses(ITEM_CLASS, className)}\n\t\t\tonClick={(event) => {\n\t\t\t\tfeedback(\"select\");\n\t\t\t\tonClick?.(event);\n\t\t\t}}\n\t\t\tonMouseUp={(event) => {\n\t\t\t\tguard(event);\n\t\t\t\tonMouseUp?.(event);\n\t\t\t}}\n\t\t\t{...props}\n\t\t>\n\t\t\t<span className=\"grid size-4 shrink-0 place-items-center\">\n\t\t\t\t<MenuPrimitive.CheckboxItemIndicator>\n\t\t\t\t\t<CheckIcon />\n\t\t\t\t</MenuPrimitive.CheckboxItemIndicator>\n\t\t\t</span>\n\t\t\t<ItemText shortcut={shortcut}>{children}</ItemText>\n\t\t</MenuPrimitive.CheckboxItem>\n\t);\n}\n\nexport function LiquidGlassMenuRadioGroup(\n\tprops: MenuPrimitive.RadioGroup.Props,\n) {\n\treturn (\n\t\t<MenuPrimitive.RadioGroup\n\t\t\tdata-slot=\"liquid-glass-menu-radio-group\"\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nexport interface LiquidGlassMenuRadioItemProps\n\textends Omit<MenuPrimitive.RadioItem.Props, \"children\"> {\n\t/** Trailing hint, such as a keyboard shortcut. Shown, not bound. */\n\tshortcut?: ReactNode;\n\t/** The label. */\n\tchildren?: ReactNode;\n}\n\n/** One choice in a `LiquidGlassMenuRadioGroup`. It stays open on click unless `closeOnClick` is set. */\nexport function LiquidGlassMenuRadioItem({\n\tshortcut,\n\tchildren,\n\tclassName,\n\tonClick,\n\tonMouseUp,\n\t...props\n}: LiquidGlassMenuRadioItemProps) {\n\tconst { feedback } = useLiquidGlassMenu();\n\tconst guard = useReleaseGuard();\n\treturn (\n\t\t<MenuPrimitive.RadioItem\n\t\t\tdata-slot=\"liquid-glass-menu-radio-item\"\n\t\t\tdata-lgm-item=\"\"\n\t\t\tclassName={withClasses(ITEM_CLASS, className)}\n\t\t\tonClick={(event) => {\n\t\t\t\tfeedback(\"select\");\n\t\t\t\tonClick?.(event);\n\t\t\t}}\n\t\t\tonMouseUp={(event) => {\n\t\t\t\tguard(event);\n\t\t\t\tonMouseUp?.(event);\n\t\t\t}}\n\t\t\t{...props}\n\t\t>\n\t\t\t<span className=\"grid size-4 shrink-0 place-items-center\">\n\t\t\t\t<MenuPrimitive.RadioItemIndicator>\n\t\t\t\t\t<span className=\"block size-1.5 rounded-full bg-current\" />\n\t\t\t\t</MenuPrimitive.RadioItemIndicator>\n\t\t\t</span>\n\t\t\t<ItemText shortcut={shortcut}>{children}</ItemText>\n\t\t</MenuPrimitive.RadioItem>\n\t);\n}\n\nexport function LiquidGlassMenuGroup(props: MenuPrimitive.Group.Props) {\n\treturn <MenuPrimitive.Group data-slot=\"liquid-glass-menu-group\" {...props} />;\n}\n\n/** A heading for a `LiquidGlassMenuGroup` or `LiquidGlassMenuRadioGroup`. */\nexport function LiquidGlassMenuLabel({\n\tclassName,\n\t...props\n}: MenuPrimitive.GroupLabel.Props) {\n\treturn (\n\t\t<MenuPrimitive.GroupLabel\n\t\t\tdata-slot=\"liquid-glass-menu-label\"\n\t\t\tdata-lgm-item=\"\"\n\t\t\tclassName={withClasses(\n\t\t\t\t// Lines up with the item labels, past the 16 px icon column.\n\t\t\t\tcn(\n\t\t\t\t\t\"flex h-7 items-end pr-3 pb-1 pl-10 font-medium text-foreground/75 text-xs leading-4 dark:text-foreground/80\",\n\t\t\t\t\tITEM_MORPH,\n\t\t\t\t),\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nexport function LiquidGlassMenuSeparator({\n\tclassName,\n\t...props\n}: MenuPrimitive.Separator.Props) {\n\treturn (\n\t\t<MenuPrimitive.Separator\n\t\t\tdata-slot=\"liquid-glass-menu-separator\"\n\t\t\tdata-lgm-item=\"\"\n\t\t\tclassName={withClasses(\n\t\t\t\t// An 8 px band with a hairline in it, inset like the item padding:\n\t\t\t\t// one device pixel at 2x, centred.\n\t\t\t\tcn(\n\t\t\t\t\t\"relative mx-3 h-2 shrink-0 before:absolute before:inset-x-0 before:top-[3.25px] before:h-px before:scale-y-50 before:bg-foreground/15\",\n\t\t\t\t\tITEM_MORPH,\n\t\t\t\t),\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nexport default LiquidGlassMenu;\n",
      "type": "registry:component",
      "target": "@components/liquid-glass-menu.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-12",
    "image": "https://cdn.tentui.com/images/components/liquid-glass-menu?v=2",
    "video": "https://cdn.tentui.com/videos/components/liquid-glass-menu?v=2"
  },
  "docs": "https://tentui.com/components/liquid-glass-menu",
  "categories": [
    "menus"
  ],
  "type": "registry:component"
}