{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glide",
  "title": "Glide",
  "description": "How a popup that a group of triggers shares opens, slides and closes: one box that grows out of its trigger, slides to the next trigger and folds back in. Tooltip, Hover card and Navigation menu share it.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/popup.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/glide.tsx",
      "content": "'use client'\n\nimport {\n  anchorStrip,\n  physicalSide,\n  popupGrowContentClassName,\n  type PopupSide,\n  type ReadingDirection,\n  type ScreenBox,\n} from '@/registry/lib/popup'\nimport { commitStyles } from '@/registry/lib/refs'\nimport {\n  FOLLOWS_TRANSITION,\n  transitionTiming,\n  withoutTransition,\n} from '@/registry/lib/resize'\nimport {\n  createContext,\n  type CSSProperties,\n  type ReactNode,\n  use,\n  useCallback,\n  useLayoutEffect,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * How a popup that a group of triggers shares opens, slides and closes: one\n * box that grows out of a strip on the edge facing its trigger, slides to\n * the next trigger of its group, and folds back into the strip. Tooltip,\n * Hover card and Navigation menu share it.\n *\n * The popup paints nothing itself. Its surface reaches far past it, and the\n * surface and the content are clipped to one box, written as CSS variables\n * relative to the popup: the box when open, the strip while opening and\n * closing, and the last box's size while it slides to a new one. One clip, so\n * an open, a slide and a close each turn back from wherever the last one left\n * it. When the popup is placed somewhere else, the whole popup shifts\n * back to where it showed and glides to its new place on a `translate` of\n * its own, so the clip keeps its own clock on the way: a tooltip that follows\n * the pointer finishes opening while it moves.\n */\n\n/**\n * How long a trigger in a group waits before its popup closes, in ms: long\n * enough to cross the gap to the next trigger, so the popup slides there\n * instead of closing and opening again.\n */\nexport const GLIDE_GROUP_CLOSE_DELAY = 150\n\n/**\n * How long a group remembers where its popup was after it closed, in ms, so\n * one that opens again soon carries on from there: the tooltips' warm window.\n */\nexport const GLIDE_MEMORY_MS = 400\n\n/**\n * Where the clip is in its life, as the popup's `data-glide`: not yet placed\n * (`waiting`, hidden), still (`rest`), growing out of its strip (`open`),\n * moving to a new box (`slide`) or folding back (`close`).\n */\nexport type GlidePhase = 'waiting' | 'rest' | 'open' | 'slide' | 'close'\n\n/** What the tracker saw. */\nexport type GlideCue =\n  | {\n      kind: 'measured'\n      /** The library asks for no animation. */\n      instant: boolean\n      /** The popup moved only because the page scrolled, so the clip already follows. */\n      scrolled: boolean\n      /** The popup's box changed size, not only its place. */\n      resized: boolean\n      /** How a popup that opens soon after its group's last one closed starts, if one did. */\n      remembered: 'slide' | 'grow' | null\n    }\n  | { kind: 'ending' }\n  | { kind: 'settled' }\n\n/**\n * What the clip does: snap to the box, grow from the strip, grow from the\n * strip the last popup folded into, slide from where it shows now, slide\n * from where the last popup was, fold, or come to rest. On a `move`, the\n * popup glides to its new place and the clip carries on as it was.\n */\nexport type GlideStep =\n  | 'snap'\n  | 'grow'\n  | 'grow-again'\n  | 'slide'\n  | 'slide-again'\n  | 'move'\n  | 'fold'\n  | 'rest'\n  | 'stay'\n\n/** The next phase, and the step that gets there. */\nexport function glideNext(\n  phase: GlidePhase,\n  cue: GlideCue,\n): readonly [GlidePhase, GlideStep] {\n  // A fold already running carries on from where it has got to.\n  if (cue.kind === 'ending')\n    return phase === 'close' ? ['close', 'stay'] : ['close', 'fold']\n  if (cue.kind === 'settled') {\n    return phase === 'open' || phase === 'slide' ? ['rest', 'rest'] : [phase, 'stay']\n  }\n  if (phase === 'waiting') {\n    // Carrying on from the group's last popup wins over an instant open,\n    // which is how the warm window opens the next one.\n    if (cue.remembered === 'slide') return ['slide', 'slide-again']\n    if (cue.remembered === 'grow') return ['open', 'grow-again']\n    return cue.instant ? ['rest', 'snap'] : ['open', 'grow']\n  }\n  if (cue.instant) return ['rest', 'snap']\n  // Opened again before it had gone, it slides on from where the fold got to.\n  if (cue.scrolled && phase !== 'close') return [phase, 'stay']\n  // The same box somewhere else: an open keeps growing on its own clock as it\n  // goes, rather than starting over from wherever the pointer left it.\n  if (!cue.resized && phase !== 'close') return [phase, 'move']\n  return ['slide', 'slide']\n}\n\n/**\n * The box an `inset()` clip shows, in screen pixels, on an element whose box\n * is `frame`; null for any other clip. Reads a computed value, which gives\n * one to four lengths in pixels.\n */\nexport function insetBox(clip: string, frame: ScreenBox): ScreenBox | null {\n  if (!clip.startsWith('inset(')) return null\n  const end = clip.includes(' round') ? clip.indexOf(' round') : clip.lastIndexOf(')')\n  const values = clip\n    .slice('inset('.length, end)\n    .trim()\n    .split(/\\s+/)\n    .map((value) => Number.parseFloat(value))\n  if (values.length === 0 || values.length > 4 || values.some(Number.isNaN)) return null\n  const [top, right = top, bottom = top, left = right] = values\n  return {\n    left: frame.left + left,\n    top: frame.top + top,\n    width: frame.width - left - right,\n    height: frame.height - top - bottom,\n  }\n}\n\n/**\n * The shift that keeps a popup where it is on screen once it has been placed\n * from `from` to `to`: `current` plus the move of its inline-start corner,\n * which its content is laid out from.\n */\nexport function rideOffset(\n  current: readonly [number, number],\n  from: ScreenBox,\n  to: ScreenBox,\n  direction: ReadingDirection,\n): [number, number] {\n  const dx =\n    direction === 'rtl'\n      ? from.left + from.width - (to.left + to.width)\n      : from.left - to.left\n  return [current[0] + dx, current[1] + from.top - to.top]\n}\n\n/* Where a group's popup last was, the strip it folded into, and when it went. */\ninterface GlideMemory {\n  box: ScreenBox | null\n  strip: ScreenBox | null\n  /** From `performance.now()`; infinite while it is still folding. */\n  closedAt: number\n}\n\nconst GlideMemoryContext = createContext<GlideMemory | null>(null)\n\n/** Lets the popups of one group carry on from where the last one was. */\nexport function GlideGroupMemory({ children }: { children: ReactNode }) {\n  const [memory] = useState<GlideMemory>(() => ({ box: null, strip: null, closedAt: 0 }))\n  return <GlideMemoryContext value={memory}>{children}</GlideMemoryContext>\n}\n\n/** The handle a group's triggers share, and how each item hands its content to the one popup. */\nexport interface GlideGroup<Handle, Content> {\n  handle: Handle\n  setContent: (id: string, content: Content | null) => void\n}\n\n/**\n * One popup for a group of triggers, such as a toolbar's tooltips: a handle\n * or controller the triggers share, and the content of each item, by the id\n * its trigger sends as the payload.\n */\nexport function useGlideGroup<Handle, Content>(createHandle: () => Handle) {\n  const [contents, setContents] = useState<Record<string, Content>>({})\n  const [group] = useState<GlideGroup<Handle, Content>>(() => ({\n    handle: createHandle(),\n    setContent: (id, content) =>\n      setContents((previous) => {\n        if (content) return { ...previous, [id]: content }\n        const rest = { ...previous }\n        delete rest[id]\n        return rest\n      }),\n  }))\n  return { group, contentOf: (payload: unknown) => contents[String(payload)] }\n}\n\n/** Hands an item's content to its group's popup while it is mounted. */\nexport function useGlideGroupItem<Handle, Content>(\n  group: GlideGroup<Handle, Content> | null,\n  id: string | null,\n  content: Content,\n) {\n  useLayoutEffect(() => {\n    if (group && id) group.setContent(id, content)\n  })\n  useLayoutEffect(() => {\n    if (group && id) return () => group.setContent(id, null)\n  }, [group, id])\n}\n\nfunction cssPixels(element: HTMLElement, name: string) {\n  return Number.parseFloat(element.style.getPropertyValue(name))\n}\n\n/** Writes `box` as `--<name>-t/r/b/l` insets against `popupBox`. */\nfunction writeBox(\n  popup: HTMLElement,\n  name: 'glide' | 'strip',\n  popupBox: ScreenBox,\n  box: ScreenBox,\n) {\n  popup.style.setProperty(`--${name}-t`, `${box.top - popupBox.top}px`)\n  popup.style.setProperty(`--${name}-l`, `${box.left - popupBox.left}px`)\n  popup.style.setProperty(\n    `--${name}-r`,\n    `${popupBox.left + popupBox.width - (box.left + box.width)}px`,\n  )\n  popup.style.setProperty(\n    `--${name}-b`,\n    `${popupBox.top + popupBox.height - (box.top + box.height)}px`,\n  )\n}\n\n/** The box written as `--<name>-*` against `popupBox`, back on screen. */\nfunction readBox(\n  popup: HTMLElement,\n  name: 'glide' | 'strip',\n  popupBox: ScreenBox,\n): ScreenBox {\n  const t = cssPixels(popup, `--${name}-t`) || 0\n  const r = cssPixels(popup, `--${name}-r`) || 0\n  const b = cssPixels(popup, `--${name}-b`) || 0\n  const l = cssPixels(popup, `--${name}-l`) || 0\n  return {\n    left: popupBox.left + l,\n    top: popupBox.top + t,\n    width: popupBox.width - l - r,\n    height: popupBox.height - t - b,\n  }\n}\n\n/**\n * Notes when anything on the page scrolls. A popup that moved just after a\n * scroll, at the same size, moved with its anchor: its clip is written\n * against the popup, so it already follows, and sliding it would leave the\n * box behind.\n */\nfunction watchScroll() {\n  let at = Number.NEGATIVE_INFINITY\n  const note = () => {\n    at = performance.now()\n  }\n  window.addEventListener('scroll', note, { capture: true, passive: true })\n  return {\n    followed: (from: ScreenBox | null, to: ScreenBox) =>\n      from !== null &&\n      from.width === to.width &&\n      from.height === to.height &&\n      performance.now() - at < 100,\n    stop: () => window.removeEventListener('scroll', note, { capture: true }),\n  }\n}\n\nconst boxOf = (element: Element): ScreenBox => {\n  const rect = element.getBoundingClientRect()\n  return { left: rect.left, top: rect.top, width: rect.width, height: rect.height }\n}\n\n/** How far the popup shows from its place, in pixels across and down. */\ntype Shift = readonly [number, number]\n\n/** The popup's shift now, mid-glide or not. */\nconst shiftOf = (popup: HTMLElement): Shift => {\n  const now = getComputedStyle(popup).translate\n  if (now === 'none') return [0, 0]\n  const [x = '0', y = '0'] = now.split(' ')\n  return [Number.parseFloat(x), Number.parseFloat(y)]\n}\n\n/** `box` moved by `shift`, or back by it with a `sign` of -1. */\nconst moved = (box: ScreenBox, [x, y]: Shift, sign: 1 | -1 = 1): ScreenBox => ({\n  ...box,\n  left: box.left + x * sign,\n  top: box.top + y * sign,\n})\n\n/** Where the popup was placed, without the shift it shows at. */\nconst placeOf = (popup: HTMLElement, shift: Shift) => moved(boxOf(popup), shift, -1)\n\n/** Whether the library asks for no animation; `first` is the popup's first placing. */\nexport type GlideInstant = (parts: { popup: HTMLElement; first: boolean }) => boolean\n\ninterface GlideOptions {\n  /**\n   * How a popup that opens soon after its group's last one closed starts:\n   * sliding from the box the last one had (a tooltip, which looks as if it\n   * never closed), or growing from the strip it folded into (a panel).\n   */\n  reopen: 'slide' | 'grow'\n  instant: GlideInstant\n}\n\nconst popupInstant: GlideInstant = ({ popup, first }) =>\n  first && popup.hasAttribute('data-instant')\n\n/*\n * Follows the popup's place and size and writes the clip, through the phases\n * `glideNext` sets out. Kept outside any component: the React Compiler can\n * drop a forced style read written inside one, and the transitions need it.\n */\nfunction trackGlide(\n  content: HTMLElement,\n  memory: GlideMemory | null,\n  { reopen, instant }: GlideOptions,\n) {\n  const popup = content.parentElement\n  if (!popup) return\n  let phase: GlidePhase = 'waiting'\n  let last = ''\n  let popupBox: ScreenBox | null = null\n  const scroll = watchScroll()\n  const direction = () => getComputedStyle(popup).direction as ReadingDirection\n\n  const enter = (next: GlidePhase) => {\n    phase = next\n    popup.dataset.glide = next\n  }\n\n  // The shift the popup keeps while it folds, set at once.\n  const setHeld = ([x, y]: Shift) =>\n    withoutTransition(\n      popup,\n      () => {\n        popup.style.translate = x === 0 && y === 0 ? '' : `${x}px ${y}px`\n      },\n      { properties: ['translate'] },\n    )\n  const heldOf = (): Shift => {\n    const [x = '0', y = '0'] = popup.style.translate.split(' ')\n    return [Number.parseFloat(x) || 0, Number.parseFloat(y) || 0]\n  }\n\n  // Each move glides home on an animation of its own, added to the ones still\n  // running: a move that comes mid-way keeps the earlier ones' speed, where\n  // a transition turned round would start again from rest.\n  const glideHome = ([x, y]: Shift) => {\n    const [heldX, heldY] = heldOf()\n    if (heldX !== 0 || heldY !== 0) setHeld([0, 0])\n    const from = [x + heldX, y + heldY]\n    if (from[0] === 0 && from[1] === 0) return\n    const timing = transitionTiming(getComputedStyle(popup), 'translate')\n    if (!timing) return\n    const glide = popup.animate(\n      [{ translate: `${from[0]}px ${from[1]}px` }, { translate: '0px 0px' }],\n      {\n        ...timing,\n        composite: 'add',\n        id: FOLLOWS_TRANSITION,\n      },\n    )\n    // Started on this frame's clock: a new animation waits a frame for its start, and\n    // without one it would show the popup at its new place for that frame.\n    glide.startTime = document.timeline.currentTime\n  }\n\n  // A popup placed afresh shows at its place.\n  const settle = () => {\n    for (const animation of popup.getAnimations()) {\n      if (animation.id === FOLLOWS_TRANSITION) animation.cancel()\n    }\n    setHeld([0, 0])\n  }\n\n  // The strip under the trigger, read from where the trigger was placed.\n  const stripOf = (box: ScreenBox) => {\n    const side = physicalSide(popup.dataset.side as PopupSide | undefined, direction())\n    const across = side === 'top' || side === 'bottom'\n    const anchor = cssPixels(popup, '--arrow-offset')\n    const anchorLength = cssPixels(popup, across ? '--anchor-width' : '--anchor-height')\n    const length = across ? box.width : box.height\n    return anchorStrip(\n      side,\n      box,\n      Number.isNaN(anchor) ? length / 2 : anchor,\n      Number.isNaN(anchorLength) ? length : anchorLength,\n    )\n  }\n\n  // Moves the clip from `from` to the box, both against the popup's place.\n  const play = (next: 'open' | 'slide', from: ScreenBox | null, box: ScreenBox) => {\n    enter('rest')\n    if (from) writeBox(popup, 'glide', box, from)\n    commitStyles(content)\n    enter(next)\n    writeBox(popup, 'glide', box, box)\n  }\n\n  // A closing popup can be moved before it has gone, such as to its next\n  // trigger a frame before it opens it again: the shift keeps the fold where\n  // it is on screen.\n  const hold = () => {\n    if (!popupBox) return\n    const shift = shiftOf(popup)\n    const box = placeOf(popup, shift)\n    if (box.width === 0 || (box.left === popupBox.left && box.top === popupBox.top)) {\n      return\n    }\n    const [x, y] = rideOffset(heldOf(), popupBox, box, direction())\n    setHeld([x, y])\n    popupBox = box\n  }\n\n  const fold = () => {\n    const [next, step] = glideNext(phase, { kind: 'ending' })\n    if (popupBox) {\n      // The closing content can be taken out of flow: the box keeps its size.\n      popup.style.width = `${popupBox.width}px`\n      popup.style.height = `${popupBox.height}px`\n      // The fold starts: aim it at the trigger open now.\n      if (step === 'fold') writeBox(popup, 'strip', popupBox, stripOf(popupBox))\n    }\n    hold()\n    enter(next)\n    if (memory && popupBox) {\n      memory.strip = readBox(popup, 'strip', popupBox)\n      memory.closedAt = Number.POSITIVE_INFINITY\n    }\n    last = ''\n  }\n\n  const remembered = (): 'slide' | 'grow' | null => {\n    if (!memory || performance.now() - memory.closedAt >= GLIDE_MEMORY_MS) return null\n    return (reopen === 'slide' ? memory.box : memory.strip) ? reopen : null\n  }\n\n  // A ui-sdk popup stays in the page once it has closed, hidden: the next\n  // open starts afresh.\n  const reset = () => {\n    if (phase === 'waiting') return\n    if (memory && popupBox) memory.closedAt = performance.now()\n    phase = 'waiting'\n    delete popup.dataset.glide\n    popup.style.width = ''\n    popup.style.height = ''\n    settle()\n    popupBox = null\n    last = ''\n  }\n\n  // Not placed yet: ui-sdk sets the side once it has.\n  const waiting = () => popup.hidden || !popup.dataset.side\n\n  const write = () => {\n    if (popup.hidden) {\n      reset()\n      return\n    }\n    if (waiting()) return\n    if (popup.hasAttribute('data-ending-style')) {\n      // The fold is driven by our attribute, not the library's: should the popup\n      // open again before it has gone, the clip stays where the fold has got\n      // to until the next write slides on from there.\n      fold()\n      return\n    }\n    popup.style.width = ''\n    popup.style.height = ''\n    const shift = shiftOf(popup)\n    const box = placeOf(popup, shift)\n    if (box.width === 0) return\n    const key = `${box.left},${box.top},${box.width},${box.height}`\n    if (key === last) return\n    last = key\n    const strip = stripOf(box)\n    writeBox(popup, 'strip', box, strip)\n    const [next, step] = glideNext(phase, {\n      kind: 'measured',\n      instant: instant({ popup, first: phase === 'waiting' }),\n      scrolled: scroll.followed(popupBox, box),\n      // Under a pixel, the clip's edges simply follow the popup's.\n      resized:\n        popupBox !== null &&\n        (Math.abs(popupBox.width - box.width) >= 1 ||\n          Math.abs(popupBox.height - box.height) >= 1),\n      remembered: phase === 'waiting' ? remembered() : null,\n    })\n    if (step === 'snap') {\n      enter(next)\n      writeBox(popup, 'glide', box, box)\n      settle()\n    } else if (step === 'grow') {\n      settle()\n      play('open', strip, box)\n    } else if (step === 'grow-again' && memory?.strip) {\n      settle()\n      play('open', memory.strip, box)\n    } else if (step === 'slide-again' && memory?.box) {\n      const from = rideOffset([0, 0], memory.box, box, direction())\n      play('slide', moved(memory.box, from, -1), box)\n      glideHome(from)\n    } else if (step === 'slide' || step === 'move') {\n      const move = popupBox ? rideOffset([0, 0], popupBox, box, direction()) : null\n      if (step === 'slide') {\n        // Where the box shows now, mid-move or not, read against where the\n        // popup shows, then written against its new place, from which the\n        // shift and the move start out.\n        const shown = popupBox\n          ? insetBox(getComputedStyle(content).clipPath, moved(popupBox, shift))\n          : null\n        const start: Shift = move ? [shift[0] + move[0], shift[1] + move[1]] : shift\n        play('slide', shown && moved(shown, start, -1), box)\n      }\n      if (move) glideHome(move)\n    }\n    popupBox = box\n    if (memory) memory.box = box\n  }\n\n  const settled = (event: TransitionEvent) => {\n    if (event.propertyName !== 'clip-path' || event.target !== content) return\n    const [next] = glideNext(phase, { kind: 'settled' })\n    enter(next)\n  }\n\n  // What a write reads from the placed element's style. The tracker writes\n  // that style too, so a change of anything else is its own and skipped.\n  // ui-sdk's Navigation menu sizes its viewport to the next panel a frame\n  // before it places it there.\n  const placing = () =>\n    [\n      'left',\n      'top',\n      'transform',\n      'opacity',\n      '--anchor-width',\n      '--anchor-height',\n      '--viewport-width',\n      '--viewport-height',\n    ]\n      .map((name) => popup.style.getPropertyValue(name))\n      .join()\n  let seen = placing()\n  const placedMoved = () => {\n    const now = placing()\n    if (now === seen) return\n    seen = now\n    write()\n  }\n\n  write()\n  const resize = new ResizeObserver(write)\n  resize.observe(popup)\n  const style = new MutationObserver(placedMoved)\n  style.observe(popup, { attributes: true, attributeFilter: ['style'] })\n  const change = new MutationObserver(write)\n  change.observe(popup, {\n    attributes: true,\n    attributeFilter: ['data-ending-style', 'data-side', 'hidden'],\n  })\n  content.addEventListener('transitionend', settled)\n  return () => {\n    resize.disconnect()\n    style.disconnect()\n    change.disconnect()\n    content.removeEventListener('transitionend', settled)\n    scroll.stop()\n    if (memory && popupBox) memory.closedAt = performance.now()\n  }\n}\n\n/*\n * The clip's timing: none at rest, so a scroll just follows; `morph` to open,\n * `layout` to slide, `exit` to close. Hidden until it is placed. Under reduced\n * motion the box is always the box, and the popup only fades.\n */\nconst glideTiming =\n  'transition-none group-data-[glide=open]/popup:transition-[clip-path] group-data-[glide=open]/popup:duration-(--motion-morph-duration) group-data-[glide=open]/popup:ease-(--motion-morph-easing) group-data-[glide=slide]/popup:transition-[clip-path] group-data-[glide=slide]/popup:duration-(--motion-layout-duration) group-data-[glide=slide]/popup:ease-(--motion-layout-easing) group-data-[glide=close]/popup:transition-[clip-path] group-data-[glide=close]/popup:duration-(--motion-exit-duration) group-data-[glide=close]/popup:ease-(--motion-exit-easing) motion-reduce:transition-none! not-group-data-glide/popup:invisible'\n\nconst glideClipClassName =\n  '[clip-path:var(--clip-box)] group-data-[glide=close]/popup:[clip-path:var(--clip-strip)] motion-reduce:group-data-[glide=close]/popup:[clip-path:var(--clip-box)]'\n\nfunction glideInset(name: 'glide' | 'strip', offset: string, shrink: string) {\n  const edge = (key: string) => `calc(var(--${name}-${key}) + ${offset} + ${shrink})`\n  return `inset(${edge('t')} ${edge('r')} ${edge('b')} ${edge('l')} round max(0px, calc(var(--glide-radius) - ${shrink})))`\n}\n\n/** The clips of an element whose box reaches `offset` past the popup's, drawn `shrink` inside it. */\nfunction glideClip(offset: string, shrink = '0px') {\n  return {\n    '--clip-box': glideInset('glide', offset, shrink),\n    '--clip-strip': glideInset('strip', offset, shrink),\n  } as CSSProperties\n}\n\n/**\n * The popup's own classes. It fades as it folds, so the strip never lingers\n * as a line, and the library keeps it open until then. It glides to a new\n * place on `layout`, also on an instant open, which only skips the fade, and\n * not under reduced motion. Set `--glide-radius` beside them.\n */\nexport const glidePopupClassName =\n  'group/popup relative isolate [transition:opacity_calc(var(--motion-exit-duration)*0.6)_var(--motion-exit-easing),translate_var(--motion-layout-duration)_var(--motion-layout-easing)] motion-reduce:[transition-property:opacity,--held] data-ending-style:opacity-0 motion-reduce:data-starting-style:opacity-0 data-instant:[transition-property:--held,translate] motion-reduce:data-instant:transition-none'\n\n/**\n * What the popup's box is painted with, behind its content: `fill`, and with\n * `ring`, a hairline around it, and with `shadow`, a drop shadow. Goes first\n * inside the popup.\n */\nexport function GlideSurface({\n  fill,\n  ring,\n  shadow = false,\n}: {\n  fill: string\n  ring?: string\n  shadow?: boolean\n}) {\n  const layer = cn('absolute inset-0', glideClipClassName, glideTiming)\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        // Far past the popup on every side, so the box can be drawn wherever\n        // it slides from; the popup is fixed, so this never scrolls the page.\n        'pointer-events-none absolute -inset-[100vmax] -z-10',\n        // Chromium runs the clip's transition on the compositor. A shadow\n        // painted on the main thread stays where the box started until it\n        // ends, so the last box's shadow trails a slide: the compositor\n        // applies the shadow too.\n        shadow && 'drop-shadow-lg will-change-[filter]',\n      )}\n    >\n      {ring ? (\n        <>\n          <span className={cn(layer, ring)} style={glideClip('100vmax')} />\n          <span className={cn(layer, fill)} style={glideClip('100vmax', '1px')} />\n        </>\n      ) : (\n        <span className={cn(layer, fill)} style={glideClip('100vmax')} />\n      )}\n    </span>\n  )\n}\n\n/**\n * The popup's content, clipped to the same box as its surface. Goes after\n * `GlideSurface`. `reopen` and `instant` say how it starts (see\n * `GlideOptions`); by default, a popup that opens soon after its group's last\n * one slides from it, and `data-instant` on the popup skips the grow.\n */\nexport function GlideContent({\n  children,\n  reopen = 'slide',\n  instant = popupInstant,\n}: { children?: ReactNode } & Partial<GlideOptions>) {\n  const memory = use(GlideMemoryContext)\n  // Stable, so a render doesn't start the tracking over.\n  const track = useCallback(\n    (element: HTMLDivElement | null) =>\n      element ? trackGlide(element, memory, { reopen, instant }) : undefined,\n    [memory, reopen, instant],\n  )\n  return (\n    <div\n      ref={track}\n      className={cn(glideClipClassName, glideTiming)}\n      style={glideClip('0px')}\n    >\n      {children}\n    </div>\n  )\n}\n\n/**\n * For content the library renders straight into the popup, after an empty\n * `GlideContent` that tracks the box, as the Navigation menu's viewport\n * renders each panel: a layer as large as the popup, clipped to the same\n * box on the same timing, that lets the pointer through to what it holds.\n */\nexport function GlideClip({ children }: { children: ReactNode }) {\n  return (\n    <div\n      className={cn(\n        'pointer-events-none absolute inset-0 *:pointer-events-auto',\n        glideClipClassName,\n        glideTiming,\n      )}\n      style={glideClip('0px')}\n    >\n      {children}\n    </div>\n  )\n}\n\n/** A tooltip's box: the glide popup, with a control's corner. */\nexport const tooltipBoxClassName = cn(\n  glidePopupClassName,\n  '[--glide-radius:var(--control-radius-capped)]',\n)\n\n/** A tooltip's fill and hairline, inverted from the page. */\nexport function TooltipSurface() {\n  return (\n    <GlideSurface\n      fill='bg-foreground forced-colors:bg-[Canvas]'\n      ring='bg-foreground forced-colors:bg-[CanvasText]'\n    />\n  )\n}\n\n/** A tooltip's label, inside `GlideContent`. */\nexport const tooltipLabelClassName = cn(\n  'text-background max-w-64 px-2 py-1 text-xs leading-snug text-pretty forced-colors:text-[CanvasText]',\n  popupGrowContentClassName,\n  'group-data-instant/popup:transition-none',\n)\n",
      "type": "registry:lib",
      "target": "@lib/glide.tsx"
    }
  ],
  "type": "registry:lib"
}