{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"glass-morph-popover","type":"registry:component","title":"Glass Morph Popover","description":"A popover that grows out of its button as a drop of liquid glass, stretches toward its place and settles flat, then drains back the same way.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/glass-morph-popover.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport type { KeyboardEvent as ReactKeyboardEvent, ReactNode } from \"react\";\n\n/**\n * GlassMorphPopover — a popover that grows out of its trigger as a drop of\n * liquid glass and settles into a flat panel.\n *\n * Open it and a capsule the width of the button leaves the trigger, pulled\n * through a short glass neck, stretches toward where the panel will sit, then\n * spreads into the panel's rounded rectangle and settles with a little\n * spring. The content arrives as the shape lands. Close it and the panel\n * drains back into the button along the same path.\n *\n * Following the glass rule that glass never fades in, the material appears by\n * SHAPE (a clip-path morph) and, in Chromium, by ramping its refraction from\n * zero: a displacement map sized to the panel bends the backdrop at its rim,\n * and its strength climbs as the panel opens. Safari and Firefox get the\n * same morph with blur, saturation and the graduated rim.\n *\n * A non-modal dialog: the trigger carries aria-expanded and aria-controls,\n * the panel takes focus when it opens, Escape closes it and returns focus to\n * the trigger, and a press outside closes it. Under prefers-reduced-motion it\n * simply appears and disappears. Controlled (open + onOpenChange) or not\n * (defaultOpen). The panel is positioned inside the trigger's wrapper, so\n * keep the wrapper out of overflow-hidden ancestors. Once settled, a light\n * follows the pointer across the panel's rim. Animating a clip-path on an\n * element with backdrop-filter is smooth in Chromium; check it in Safari if\n * your audience is Safari-heavy.\n *\n * Needs Tailwind v4 (or v3.4+). No dependencies beyond React.\n */\n\ntype Tone = \"dark\" | \"light\";\ntype Placement = \"bottom\" | \"top\";\ntype Align = \"start\" | \"center\" | \"end\";\n\nconst GAP = 12;\nconst RADIUS = 28;\n\n/** \"#rrggbb\" to \"r,g,b\", or null. Anything else is ignored, never interpolated. */\nfunction rgbOf(hex?: string): string | null {\n  const m = /^#([0-9a-f]{6})$/i.exec(hex || \"\");\n  if (!m) return null;\n  const n = parseInt(m[1], 16);\n  return ((n >> 16) & 255) + \",\" + ((n >> 8) & 255) + \",\" + (n & 255);\n}\n\nfunction isChromium(): boolean {\n  const ua = (navigator as Navigator & { userAgentData?: { brands?: { brand: string }[] } }).userAgentData;\n  return !!ua && !!ua.brands && ua.brands.some((b) => /Chromium/.test(b.brand));\n}\n\n/** Displacement map for a rounded rectangle: red = x, green = y, 128 = none. */\nfunction lensMap(w: number, h: number, r: number, bezel: number): string {\n  const c = document.createElement(\"canvas\");\n  c.width = w;\n  c.height = h;\n  const ctx = c.getContext(\"2d\");\n  if (!ctx) return \"\";\n  const img = ctx.createImageData(w, h);\n  const hw = w / 2;\n  const hh = h / 2;\n  const rr = Math.min(r, hw, hh);\n  const sd = (x: number, y: number) => {\n    const qx = Math.abs(x) - (hw - rr);\n    const qy = Math.abs(y) - (hh - rr);\n    return Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) + Math.min(Math.max(qx, qy), 0) - rr;\n  };\n  for (let j = 0; j < h; j++) {\n    for (let i = 0; i < w; i++) {\n      const x = i + 0.5 - hw;\n      const y = j + 0.5 - hh;\n      const t = -sd(x, y);\n      let dx = 0;\n      let dy = 0;\n      if (t > 0 && t < bezel) {\n        const nx = sd(x + 0.5, y) - sd(x - 0.5, y);\n        const ny = sd(x, y + 0.5) - sd(x, y - 0.5);\n        const len = Math.hypot(nx, ny) || 1;\n        const m = Math.pow(1 - t / bezel, 2);\n        dx = (-nx / len) * m;\n        dy = (-ny / len) * m;\n      }\n      const k = (j * w + i) * 4;\n      img.data[k] = Math.round(128 + 127 * dx);\n      img.data[k + 1] = Math.round(128 + 127 * dy);\n      img.data[k + 2] = 128;\n      img.data[k + 3] = 255;\n    }\n  }\n  ctx.putImageData(img, 0, 0);\n  return c.toDataURL();\n}\n\n/**\n * A light that eases after the pointer (about 180ms) and fades when it\n * leaves. Writes <prefix>x and <prefix>y (layout pixels) and <prefix>o on the\n * element; the loop sleeps once the light arrives. Returns a cleanup.\n */\nfunction followPointer(el: HTMLElement, prefix: string): () => void {\n  const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  const L = { x: 0, y: 0, tx: 0, ty: 0, o: 0, to: 0, raf: 0, last: 0, placed: false };\n  function step(now: number) {\n    L.raf = 0;\n    const dt = L.last ? Math.min(1 / 30, (now - L.last) / 1000) : 1 / 60;\n    L.last = now;\n    const kp = reduce.matches ? 1 : 1 - Math.exp(-dt / 0.18);\n    const ko = reduce.matches ? 1 : 1 - Math.exp(-dt / 0.22);\n    L.x += (L.tx - L.x) * kp;\n    L.y += (L.ty - L.y) * kp;\n    L.o += (L.to - L.o) * ko;\n    el.style.setProperty(prefix + \"x\", L.x.toFixed(1) + \"px\");\n    el.style.setProperty(prefix + \"y\", L.y.toFixed(1) + \"px\");\n    el.style.setProperty(prefix + \"o\", L.o.toFixed(3));\n    if (Math.abs(L.tx - L.x) > 0.3 || Math.abs(L.ty - L.y) > 0.3 || Math.abs(L.to - L.o) > 0.004) {\n      L.raf = requestAnimationFrame(step);\n    } else L.last = 0;\n  }\n  const kick = () => {\n    if (!L.raf) L.raf = requestAnimationFrame(step);\n  };\n  function onMove(e: PointerEvent) {\n    // Layout pixels, even inside a transform-scaled container.\n    const r = el.getBoundingClientRect();\n    const k = el.offsetWidth / (r.width || 1);\n    L.tx = (e.clientX - r.left) * k;\n    L.ty = (e.clientY - r.top) * k;\n    L.to = 1;\n    if (!L.placed) {\n      L.x = L.tx;\n      L.y = L.ty;\n      L.placed = true;\n    }\n    kick();\n  }\n  function onLeave() {\n    L.to = 0;\n    kick();\n  }\n  el.addEventListener(\"pointermove\", onMove);\n  el.addEventListener(\"pointerdown\", onMove);\n  el.addEventListener(\"pointerleave\", onLeave);\n  return () => {\n    el.removeEventListener(\"pointermove\", onMove);\n    el.removeEventListener(\"pointerdown\", onMove);\n    el.removeEventListener(\"pointerleave\", onLeave);\n    if (L.raf) cancelAnimationFrame(L.raf);\n  };\n}\n\n/** A clip-path capsule of width w and height h, centred on x, hanging from the top (or rising from the bottom). */\nfunction capsule(pw: number, ph: number, x: number, w: number, h: number, fromTop: boolean, r: number): string {\n  const left = Math.max(0, x - w / 2);\n  const right = Math.max(0, pw - (x + w / 2));\n  const top = fromTop ? 0 : Math.max(0, ph - h);\n  const bottom = fromTop ? Math.max(0, ph - h) : 0;\n  return \"inset(\" + top.toFixed(1) + \"px \" + right.toFixed(1) + \"px \" + bottom.toFixed(1) + \"px \" + left.toFixed(1) + \"px round \" + r.toFixed(1) + \"px)\";\n}\n\nexport function GlassMorphPopover({\n  label,\n  icon,\n  children,\n  title,\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  placement = \"bottom\",\n  align = \"center\",\n  width = 320,\n  tone = \"dark\",\n  tint,\n  refraction = 1,\n  className = \"\",\n}: {\n  /** The trigger's text. */\n  label: string;\n  /** Optional icon before the label. */\n  icon?: ReactNode;\n  /** The panel's content. */\n  children: ReactNode;\n  /** The dialog's accessible name; defaults to the label. */\n  title?: string;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Where the panel opens relative to the trigger. */\n  placement?: Placement;\n  align?: Align;\n  /** Panel width in px. */\n  width?: number;\n  /** Glass over dark content (white text) or light content (ink text). */\n  tone?: Tone;\n  /** Optional tint, \"#rrggbb\", at 12%. */\n  tint?: string;\n  /** Rim refraction of the panel, 0–2 (Chromium only). */\n  refraction?: number;\n  className?: string;\n}) {\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const panelId = \"gmp\" + uid;\n  const filterId = \"gmpl\" + uid;\n  const rootRef = useRef<HTMLDivElement>(null);\n  const triggerRef = useRef<HTMLButtonElement>(null);\n  const panelRef = useRef<HTMLDivElement>(null);\n  const neckRef = useRef<HTMLSpanElement>(null);\n  const contentRef = useRef<HTMLDivElement>(null);\n  const mapRef = useRef<SVGFEImageElement>(null);\n  const dispRef = useRef<SVGFEDisplacementMapElement>(null);\n  const userOpened = useRef(false);\n\n  const [inner, setInner] = useState(defaultOpen);\n  const isOpen = open ?? inner;\n  // Whether the panel is currently settled open. It survives effect re-runs\n  // (React development mounts twice; a prop can change while open), so only a\n  // real closed-to-open change plays the morph.\n  const settled = useRef(isOpen);\n  // Keep the panel in the DOM while it drains back into the trigger.\n  const [prevOpen, setPrevOpen] = useState(isOpen);\n  const [closing, setClosing] = useState(false);\n  if (prevOpen !== isOpen) {\n    setPrevOpen(isOpen);\n    setClosing(!isOpen);\n  }\n  const visible = isOpen || closing;\n\n  const dark = tone === \"dark\";\n  const base = \"blur(18px) saturate(180%) brightness(\" + (dark ? 1.08 : 1.04) + \")\";\n  const rgb = rgbOf(tint);\n  const fill = rgb\n    ? \"linear-gradient(rgba(\" + rgb + \",0.12), rgba(\" + rgb + \",0.12)), \" + (dark ? \"rgba(18,18,24,0.34)\" : \"rgba(255,255,255,0.5)\")\n    : dark\n      ? \"rgba(18,18,24,0.36)\"\n      : \"rgba(255,255,255,0.55)\";\n  const ink = dark ? \"#ffffff\" : \"#111111\";\n\n  function setOpen(next: boolean) {\n    userOpened.current = next;\n    if (open === undefined) setInner(next);\n    onOpenChange?.(next);\n  }\n\n  // The morph: open grows the droplet out of the trigger; close drains it back.\n  // A layout effect, so the panel never paints one full-size frame first.\n  useLayoutEffect(() => {\n    const panel = panelRef.current;\n    const trigger = triggerRef.current;\n    const neck = neckRef.current;\n    const content = contentRef.current;\n    if (!panel || !trigger || !neck || !content) return;\n    if (!isOpen && !closing) return;\n\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const lens = isChromium() && refraction > 0;\n    const pw = panel.offsetWidth;\n    const ph = panel.offsetHeight;\n    const fromTop = placement === \"bottom\";\n    // The trigger's centre in the panel's own layout pixels.\n    const cx = Math.max(0, Math.min(pw, trigger.offsetLeft + trigger.offsetWidth / 2 - panel.offsetLeft));\n    const tw = Math.min(pw, trigger.offsetWidth);\n    const th = trigger.offsetHeight;\n    // Refraction up to 1 strengthens the bend; above 1 it widens the bent\n    // band instead, so the peak offset never passes 0.4 of the bezel.\n    const bezel = Math.min(Math.min(24, Math.max(14, Math.min(pw, ph) * 0.08)) * Math.max(1, refraction), Math.min(pw, ph) * 0.3);\n    const peak = Math.round(0.8 * bezel * Math.min(1, refraction));\n    if (lens && mapRef.current && dispRef.current && pw && ph) {\n      mapRef.current.setAttribute(\"href\", lensMap(pw, ph, RADIUS, bezel));\n      mapRef.current.setAttribute(\"width\", String(pw));\n      mapRef.current.setAttribute(\"height\", String(ph));\n      panel.style.backdropFilter = \"url(#\" + filterId + \") \" + base;\n    }\n\n    const shapes = [\n      capsule(pw, ph, cx, tw, th * 0.9, fromTop, th * 0.45),\n      capsule(pw, ph, cx, Math.max(56, tw * 0.72), ph * 0.58, fromTop, Math.max(28, tw * 0.36)),\n      \"inset(0px 0px 0px 0px round \" + RADIUS + \"px)\",\n    ];\n    const anims: Animation[] = [];\n    let raf = 0;\n    let timer = 0;\n    const ramp = (from: number, to: number, ms: number) => {\n      if (!lens || !dispRef.current) return;\n      const t0 = performance.now();\n      const tick = (now: number) => {\n        const k = Math.min(1, (now - t0) / ms);\n        dispRef.current?.setAttribute(\"scale\", String(Math.round(from + (to - from) * k)));\n        if (k < 1) raf = requestAnimationFrame(tick);\n      };\n      raf = requestAnimationFrame(tick);\n    };\n\n    if (isOpen) {\n      const wasSettled = settled.current;\n      settled.current = true;\n      if (wasSettled || reduce) {\n        // Already open (on mount, or a prop changed), or no motion wanted.\n        content.style.opacity = \"1\";\n        dispRef.current?.setAttribute(\"scale\", String(peak));\n      } else {\n        anims.push(\n          panel.animate(\n            [\n              { clipPath: shapes[0], easing: \"cubic-bezier(0.3, 0, 0.2, 1)\" },\n              { clipPath: shapes[1], offset: 0.42, easing: \"cubic-bezier(0.34, 1.4, 0.64, 1)\" },\n              { clipPath: shapes[2] },\n            ],\n            // \"backwards\" only: once settled the clip lets go, so the\n            // panel's shadow is not clipped away.\n            { duration: 320, fill: \"backwards\" }\n          ),\n          neck.animate(\n            [\n              { transform: \"scale(0.2, 0)\", opacity: 1 },\n              { transform: \"scale(1, 1)\", opacity: 1, offset: 0.35 },\n              { transform: \"scale(0.3, 0)\", opacity: 1 },\n            ],\n            { duration: 300, easing: \"cubic-bezier(0.3, 0, 0.2, 1)\", fill: \"both\" }\n          ),\n          content.animate(\n            [\n              { opacity: 0, transform: \"translateY(\" + (fromTop ? -6 : 6) + \"px)\" },\n              { opacity: 1, transform: \"none\" },\n            ],\n            { duration: 200, delay: 140, easing: \"cubic-bezier(0.22, 1, 0.36, 1)\", fill: \"both\" }\n          )\n        );\n        ramp(0, peak, 320);\n      }\n      // Take focus only when a person just opened it, never on a re-run.\n      if (!wasSettled && userOpened.current) panel.focus({ preventScroll: true });\n      userOpened.current = false;\n    } else if (closing) {\n      settled.current = false;\n      const done = () => setClosing(false);\n      if (reduce) {\n        done();\n      } else {\n        // End on a timer, not on the animation's finish event, which only\n        // fires on a rendered frame and can stall in a throttled tab.\n        timer = window.setTimeout(done, 250);\n        anims.push(\n          content.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 90, easing: \"linear\", fill: \"both\" }),\n          panel.animate(\n            [\n              { clipPath: shapes[2] },\n              { clipPath: shapes[1], offset: 0.5 },\n              { clipPath: shapes[0] },\n            ],\n            { duration: 240, easing: \"cubic-bezier(0.4, 0, 1, 1)\", fill: \"forwards\" }\n          )\n        );\n        ramp(peak, 0, 200);\n      }\n    }\n    return () => {\n      cancelAnimationFrame(raf);\n      window.clearTimeout(timer);\n      anims.forEach((a) => a.cancel());\n    };\n  }, [isOpen, closing, placement, refraction, base, filterId]);\n\n  // A light that follows the pointer across the settled panel.\n  useEffect(() => {\n    const panel = panelRef.current;\n    return panel ? followPointer(panel, \"--gmp-l\") : undefined;\n  }, []);\n\n  // Outside press and Escape.\n  useEffect(() => {\n    if (!isOpen) return;\n    function onDown(e: PointerEvent) {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);\n    }\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  });\n\n  function onPanelKey(e: ReactKeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"Escape\") {\n      e.stopPropagation();\n      setOpen(false);\n      triggerRef.current?.focus();\n    }\n  }\n\n  const glass = {\n    background: fill,\n    backdropFilter: base,\n    WebkitBackdropFilter: base,\n    boxShadow:\n      \"inset 0 1px 0 rgba(255,255,255,\" + (dark ? 0.55 : 0.9) + \"), inset 0 -1px 0 rgba(255,255,255,0.18), 0 12px 40px rgba(0,0,0,\" + (dark ? 0.28 : 0.14) + \")\",\n  };\n  const left = align === \"start\" ? 0 : align === \"end\" ? undefined : \"calc(50% - \" + width / 2 + \"px)\";\n\n  return (\n    <div ref={rootRef} className={\"relative inline-block \" + className}>\n      <button\n        ref={triggerRef}\n        type=\"button\"\n        aria-haspopup=\"dialog\"\n        aria-expanded={isOpen}\n        aria-controls={panelId}\n        onClick={() => setOpen(!isOpen)}\n        className=\"relative inline-flex h-11 select-none items-center gap-2 rounded-full px-5 text-[15px] font-semibold tracking-[-0.01em] outline-none transition-transform duration-300 ease-[cubic-bezier(0.34,1.4,0.64,1)] focus-visible:ring-2 focus-visible:ring-white/80 active:scale-x-[0.98] active:scale-y-[0.97] active:duration-100\"\n        style={{ ...glass, color: ink }}\n      >\n        {icon && (\n          <span aria-hidden className=\"flex h-5 w-5 items-center justify-center [&>svg]:h-5 [&>svg]:w-5\">\n            {icon}\n          </span>\n        )}\n        {label}\n      </button>\n      {/* The neck: a bead of glass that bridges the gap while the drop leaves. */}\n      <span\n        ref={neckRef}\n        aria-hidden\n        className=\"pointer-events-none absolute z-40 rounded-full\"\n        style={{\n          ...glass,\n          width: 18,\n          height: GAP + 8,\n          left: \"calc(50% - 9px)\",\n          top: placement === \"bottom\" ? \"calc(100% - 4px)\" : undefined,\n          bottom: placement === \"top\" ? \"calc(100% - 4px)\" : undefined,\n          transformOrigin: placement === \"bottom\" ? \"50% 0%\" : \"50% 100%\",\n          transform: \"scale(0.2, 0)\",\n          boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.5)\",\n        }}\n      />\n      <div\n        ref={panelRef}\n        id={panelId}\n        role=\"dialog\"\n        aria-label={title || label}\n        tabIndex={-1}\n        hidden={!visible}\n        onKeyDown={onPanelKey}\n        className=\"absolute z-50 overflow-hidden outline-none\"\n        style={{\n          ...glass,\n          width,\n          borderRadius: RADIUS,\n          color: ink,\n          left,\n          right: align === \"end\" ? 0 : undefined,\n          top: placement === \"bottom\" ? \"calc(100% + \" + GAP + \"px)\" : undefined,\n          bottom: placement === \"top\" ? \"calc(100% + \" + GAP + \"px)\" : undefined,\n        }}\n      >\n        {/* A graduated rim: bright top-left, faint through the sides. */}\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: RADIUS,\n            padding: 1,\n            background:\n              \"linear-gradient(160deg, rgba(255,255,255,\" + (dark ? 0.6 : 0.95) + \") 0%, rgba(255,255,255,0.12) 38%, rgba(255,255,255,0.06) 70%, rgba(255,255,255,0.22) 100%)\",\n            WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n            WebkitMaskComposite: \"xor\",\n            mask: \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\",\n          }}\n        />\n        {/* The pointer's light: the nearby rim brightens, a soft specular below. */}\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            borderRadius: RADIUS,\n            padding: 1,\n            opacity: \"var(--gmp-lo, 0)\",\n            background:\n              \"radial-gradient(220px circle at var(--gmp-lx, -999px) var(--gmp-ly, -999px), rgba(255,255,255,0.95), rgba(255,255,255,0) 70%)\",\n            WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n            WebkitMaskComposite: \"xor\",\n            mask: \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\",\n          }}\n        />\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-0\"\n          style={{\n            opacity: \"var(--gmp-lo, 0)\",\n            background:\n              \"radial-gradient(320px circle at var(--gmp-lx, -999px) var(--gmp-ly, -999px), rgba(255,255,255,\" + (dark ? 0.16 : 0.3) + \"), rgba(255,255,255,0) 65%)\",\n            mixBlendMode: dark ? \"screen\" : \"normal\",\n          }}\n        />\n        <div ref={contentRef} className=\"relative z-10 p-4\">\n          {children}\n        </div>\n        <svg aria-hidden width=\"0\" height=\"0\" style={{ position: \"absolute\" }}>\n          <filter id={filterId} x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" colorInterpolationFilters=\"sRGB\">\n            <feImage ref={mapRef} x=\"0\" y=\"0\" preserveAspectRatio=\"none\" result=\"map\" />\n            <feDisplacementMap ref={dispRef} in=\"SourceGraphic\" in2=\"map\" scale=\"0\" xChannelSelector=\"R\" yChannelSelector=\"G\" />\n          </filter>\n        </svg>\n      </div>\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/glass-morph-popover.tsx"}],"meta":{"tier":"free","tags":["popover","animation","morph","glass","liquid glass","dialog","clip-path"],"href":"https://viberdy.dev/library/glass-morph-popover","aiPrompt":"Create a React + Tailwind client component, GlassMorphPopover: a liquid-glass popover that grows out of its trigger as a droplet and settles into a flat panel.\n\nProps: label, icon?, children (panel content), title? (the dialog's accessible name, defaults to label), open / defaultOpen / onOpenChange, placement (\"bottom\" | \"top\"), align (\"start\" | \"center\" | \"end\"), width (px, default 320), tone (\"dark\" | \"light\"), tint (\"#rrggbb\", regex-validated, at 12%), refraction (0–2), className.\n\nStructure: a relative inline-block wrapper holding (1) the trigger, a 44px glass pill button (backdrop-filter blur(18px) saturate(180%) brightness(1.08), fill rgba(18,18,24,0.36) on dark or rgba(255,255,255,0.55) on light, inset 0 1px 0 white 0.55 (0.9 light), inset 0 −1px 0 white 0.18, 0 12px 40px black 0.28 (0.14 light)) with aria-haspopup=\"dialog\", aria-expanded and aria-controls, the kit press squash (scale 0.98 × 0.97) and spring release cubic-bezier(0.34,1.4,0.64,1); (2) a \"neck\", an aria-hidden 18 × 20px glass bead centred under (or above) the trigger that bridges the 12px gap; (3) the panel, role=\"dialog\" with tabIndex −1, positioned absolutely 12px below (or above) the trigger, aligned by left/right in px (never a transform, which the animation owns), 28px radius (the kit's panel token), the same glass, a 1px graduated rim (a padding + mask-composite ring with a 160° gradient white 0.6 → 0.12 → 0.06 → 0.22), content padding 16px.\n\nKeep the panel mounted while it closes: track the previous open value during render and set a `closing` flag when it flips to false; the panel is hidden only when neither open nor closing.\n\nThe morph runs in a useLayoutEffect (so the panel never paints one full-size frame first). Measure the panel (offsetWidth/Height) and the trigger's centre in the panel's layout pixels. Define three clip-path shapes: (a) a capsule the trigger's width and 0.9× its height, hanging from the panel's near edge at the trigger's centre; (b) a narrower pill (max(56, 0.72 × trigger width)) reaching 58% of the panel's height; (c) inset(0 round 28px). Open: Web Animations on clip-path a → b (offset 0.42, easing cubic-bezier(0.3,0,0.2,1)) → c (spring easing cubic-bezier(0.34,1.4,0.64,1)), 320ms, fill \"backwards\" only, so the clip lets go when settled and the shadow is not clipped; the neck scales (0.2, 0) → (1, 1) at 35% → (0.3, 0) over 300ms; the content fades and rises 6px after a 140ms delay over 200ms. Close: content fades in 90ms; clip c → b → a over 240ms ease-in with fill \"forwards\", then clear `closing` from a 250ms timer (not the animation's finish event, which only fires on a rendered frame and can stall in a throttled tab). Only a real closed-to-open change plays the morph: track \"settled open\" in a ref that survives effect re-runs (React development mounts twice, and props can change while open). If it mounts open, or under prefers-reduced-motion, just show it. Focus the panel (preventScroll) only on a real closed-to-open change that a person caused, then clear that flag, so a prop change while open never steals focus. Once settled, a light follows the pointer across the panel: ease a position toward the pointer (layout pixels via the rect-to-offsetWidth ratio) with a 180ms time constant and an opacity to 1 (0 on leave) with 220ms in a sleeping requestAnimationFrame loop, written to --gmp-lx/--gmp-ly/--gmp-lo, lighting a rim ring (radial 220px, white 0.95) and a soft specular (radial 320px, white 0.16, screen on dark).\n\nRefraction (Chromium only, detected with navigator.userAgentData brands containing \"Chromium\", never with @supports): an SVG filter (feImage + feDisplacementMap, R = x, G = y, sRGB) with a canvas-generated rounded-rect displacement map sized to the panel (bezel clamp(0.08 × shorter side, 14, 24) × max(1, refraction), at most 0.3 × the shorter side: refraction above 1 widens the bent band instead of deepening it, so the peak offset never passes 0.4 of the bezel; inward offset (1 − t/bezel)², encoded 128 + 127·d), prepended to the panel's backdrop-filter. Glass never fades in, so ramp the feDisplacementMap scale from 0 to round(0.8 × bezel × min(1, refraction)) over the 320ms open with requestAnimationFrame, and back to 0 over 200ms on close.\n\nClose on a pointerdown outside the wrapper and on Escape inside the panel (then return focus to the trigger). Document that the panel is positioned inside the trigger's wrapper, so the wrapper must not sit inside an overflow-hidden ancestor, and that animating clip-path on a backdrop-filter element should be checked in Safari.\n\nOutput one self-contained \"use client\" TSX file with no dependencies beyond React. Build strings with + rather than template literals.","license":"https://viberdy.dev/license"}}