{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fluid-tooltip",
  "title": "Fluid Tooltip",
  "description": "One shared tooltip for a toolbar, rail, or dock. Slide between buttons and a single quiet bubble glides with you on soft springs, settles without overshoot, and crossfades to the new label.",
  "dependencies": [
    "@rexa-developer/tiks",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/fluid-tooltip/fluid-tooltip.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport {\n\tAnimatePresence,\n\tanimate,\n\tdomAnimation,\n\tLazyMotion,\n\ttype MotionValue,\n\tm,\n\tuseMotionValue,\n\tuseReducedMotion,\n\ttype Variants,\n} from \"motion/react\";\nimport {\n\tChildren,\n\tcloneElement,\n\tcreateContext,\n\ttype FocusEvent,\n\tisValidElement,\n\ttype MouseEvent,\n\ttype PointerEvent,\n\ttype ReactElement,\n\ttype ReactNode,\n\ttype Ref,\n\ttype RefObject,\n\tuseContext,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\n// Layout, in px. The bubble is one small rounded box, sized to its label.\nconst HEIGHT = 24;\nconst PAD_X = 8;\n/** Room kept between the bubble and the viewport edges. */\nconst VIEWPORT_PADDING = 8;\n\n// The bubble is drawn between four edges, each on its own critically damped\n// spring, so it glides onto a new target without overshoot. The edge facing\n// the target is a touch quicker than the far one, which stretches the box very\n// slightly along the way; the far edge then settles in behind it.\nconst leadSpring = { stiffness: 400, damping: 40 } as const;\nconst trailSpring = { stiffness: 340, damping: 37 } as const;\n/** Edges across the direction of travel, such as a width change. */\nconst crossSpring = { stiffness: 380, damping: 39 } as const;\nconst leanSpring = { stiffness: 300, damping: 35 } as const;\n/** The box is at most this many times its resting length mid-move. */\nconst MAX_STRETCH = 1.1;\n/** How far, in px, the resting bubble leans toward the pointer with `follow`. */\nconst LEAN = 2;\n\n// Timing, in ms.\n/** A pointer that leaves a trigger has this long to reach another or the bubble. */\nconst CLOSE_GRACE = 120;\nconst LONG_PRESS = 450;\n/** A long-press tooltip stays this long after the finger lifts. */\nconst TOUCH_HIDE = 1200;\n/** Px a finger can drift before a long press is cancelled. */\nconst TOUCH_SLOP = 10;\nconst TICK_THROTTLE = 90;\n\n// Motion, in seconds.\nconst OPEN_DURATION = 0.14;\nconst OPEN_SCALE = 0.97;\nconst CLOSE_DURATION = 0.1;\n/** Reduced motion opens and closes with a plain fade. */\nconst FADE_DURATION = 0.1;\n// The label swap is a short crossfade. The old label is nearly gone before the\n// new one starts, so the two never read as one smeared label.\nconst SWAP_OUT = 0.08;\nconst SWAP_IN = 0.12;\nconst SWAP_IN_DELAY = 0.05;\n/** Px the labels drift in the direction of travel as they swap. */\nconst SWAP_NUDGE = 2;\nconst EASE_OUT = [0.23, 1, 0.32, 1] as const;\n\n// A very soft, short tick of bright noise as the bubble lands on a new target.\nconst TICK_SOUND = {\n\tname: \"fluid-tooltip-tick\",\n\tbaseFreq: 440,\n\tnoiseColor: \"white\",\n\toscType: \"sine\",\n\tfilterFreq: 3000,\n\tfilterQ: 1,\n\tattack: 0.001,\n\tdecay: 0.5,\n\tbrightness: 4200,\n} as const;\n\ntype Side = \"top\" | \"right\" | \"bottom\" | \"left\";\ntype Align = \"center\" | \"start\" | \"end\";\ntype Axis = \"x\" | \"y\";\ntype Shortcut = string | string[];\n\nconst OPPOSITE: Record<Side, Side> = {\n\ttop: \"bottom\",\n\tbottom: \"top\",\n\tleft: \"right\",\n\tright: \"left\",\n};\n\nexport interface FluidTooltipGroupProps {\n\t/** Where the bubble sits relative to the trigger. Flips if there is no room. */\n\tside?: Side;\n\t/** Alignment along the trigger's edge. `start` and `end` follow text direction. */\n\talign?: Align;\n\t/** Gap between the trigger and the bubble, in px. */\n\tsideOffset?: number;\n\t/** Ms a pointer rests on a trigger before the bubble opens. */\n\tdelay?: number;\n\t/** Ms after the bubble closes during which it reopens without the delay. */\n\tskipDelay?: number;\n\t/** Lean the resting bubble a couple of px toward the pointer. Off by default, so it stays still. */\n\tfollow?: boolean;\n\t/** Play a soft tick each time the bubble lands on a new trigger. */\n\tsound?: boolean;\n\t/** Classes for the bubble. */\n\tclassName?: string;\n\tchildren?: ReactNode;\n}\n\nexport interface FluidTooltipProps {\n\t/** The label. Keep it short and plain; interactive content needs a popover. */\n\tcontent: ReactNode;\n\t/** Keyboard shortcut shown dimmer after the label, such as `\"⌘K\"` or `[\"⌘\", \"K\"]`. */\n\tshortcut?: Shortcut;\n\t/** Overrides the group's `side` for this trigger. */\n\tside?: Side;\n\t/** Never show the tooltip. A disabled child is treated the same way. */\n\tdisabled?: boolean;\n\t/** Exactly one focusable element, usually a button. */\n\tchildren: ReactElement;\n}\n\ninterface TriggerEntry {\n\telement: HTMLElement | null;\n\tcontent: ReactNode;\n\tshortcut?: Shortcut;\n\tside?: Side;\n\tdisabled: boolean;\n}\n\ninterface View {\n\tkey: string;\n\tcontent: ReactNode;\n\tshortcut?: Shortcut;\n\t/** Bumps on every new target, so the label swaps. */\n\tseq: number;\n\t/** The direction of travel from the last target, for the swap. */\n\taxis: Axis;\n\tdir: number;\n\tappear: boolean;\n}\n\ninterface Target {\n\tx: number;\n\ty: number;\n\tw: number;\n\th: number;\n\tside: Side;\n\t/** Where the trigger's center falls on the bubble, for the open scale. */\n\torigin: string;\n}\n\ninterface GroupApi {\n\tregister: (key: string, entry: TriggerEntry) => void;\n\tunregister: (key: string) => void;\n\tpointerEnter: (key: string, event: PointerEvent<HTMLElement>) => void;\n\tpointerLeave: (key: string, event: PointerEvent<HTMLElement>) => void;\n\tpointerMove: (key: string, event: PointerEvent<HTMLElement>) => void;\n\tpointerDown: (key: string, event: PointerEvent<HTMLElement>) => void;\n\tpointerUp: (key: string, event: PointerEvent<HTMLElement>) => void;\n\tfocus: (key: string, element: HTMLElement) => void;\n\tblur: (key: string) => void;\n\tclickCapture: (key: string, event: MouseEvent<HTMLElement>) => void;\n\tcontextMenu: (key: string, event: MouseEvent<HTMLElement>) => void;\n}\n\ninterface GroupContextValue {\n\tapi: GroupApi;\n\ttooltipId: string;\n\t/** The trigger the bubble describes right now, if it's open. */\n\tshownKey: string | null;\n}\n\nconst GroupContext = createContext<GroupContextValue | null>(null);\n\ntype ZoomedElement = HTMLElement & { currentCSSZoom?: number };\n\nfunction clamp(value: number, min = 0, max = 1) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nfunction keysOf(shortcut: Shortcut | undefined) {\n\tif (shortcut === undefined) return [];\n\treturn Array.isArray(shortcut) ? shortcut : [shortcut];\n}\n\nfunction sameShortcut(a: Shortcut | undefined, b: Shortcut | undefined) {\n\treturn keysOf(a).join(\"\\u0000\") === keysOf(b).join(\"\\u0000\");\n}\n\nfunction center(element: HTMLElement) {\n\tconst rect = element.getBoundingClientRect();\n\treturn { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };\n}\n\n/**\n * Places a `width` x `height` bubble beside `rect`, flipping to the opposite\n * side when it would overflow the viewport, then shifting along the edge to\n * stay inside it.\n */\nfunction placeBubble(\n\trect: { left: number; right: number; top: number; bottom: number },\n\twidth: number,\n\theight: number,\n\tpreferred: Side,\n\talign: Align,\n\toffset: number,\n\tviewport: { width: number; height: number },\n\trtl: boolean,\n): Omit<Target, \"origin\"> {\n\tconst room: Record<Side, number> = {\n\t\ttop: rect.top - offset - VIEWPORT_PADDING,\n\t\tbottom: viewport.height - rect.bottom - offset - VIEWPORT_PADDING,\n\t\tleft: rect.left - offset - VIEWPORT_PADDING,\n\t\tright: viewport.width - rect.right - offset - VIEWPORT_PADDING,\n\t};\n\tconst need = (side: Side) =>\n\t\tside === \"top\" || side === \"bottom\" ? height : width;\n\tlet side = preferred;\n\tconst opposite = OPPOSITE[preferred];\n\tif (room[side] < need(side) && room[opposite] >= need(opposite)) {\n\t\tside = opposite;\n\t}\n\n\tlet x: number;\n\tlet y: number;\n\tif (side === \"top\" || side === \"bottom\") {\n\t\tconst logical =\n\t\t\trtl && align !== \"center\" ? (align === \"start\" ? \"end\" : \"start\") : align;\n\t\tx =\n\t\t\tlogical === \"start\"\n\t\t\t\t? rect.left\n\t\t\t\t: logical === \"end\"\n\t\t\t\t\t? rect.right - width\n\t\t\t\t\t: (rect.left + rect.right) / 2 - width / 2;\n\t\tx = clamp(\n\t\t\tx,\n\t\t\tVIEWPORT_PADDING,\n\t\t\tMath.max(VIEWPORT_PADDING, viewport.width - VIEWPORT_PADDING - width),\n\t\t);\n\t\ty = side === \"top\" ? rect.top - offset - height : rect.bottom + offset;\n\t} else {\n\t\ty =\n\t\t\talign === \"start\"\n\t\t\t\t? rect.top\n\t\t\t\t: align === \"end\"\n\t\t\t\t\t? rect.bottom - height\n\t\t\t\t\t: (rect.top + rect.bottom) / 2 - height / 2;\n\t\ty = clamp(\n\t\t\ty,\n\t\t\tVIEWPORT_PADDING,\n\t\t\tMath.max(VIEWPORT_PADDING, viewport.height - VIEWPORT_PADDING - height),\n\t\t);\n\t\tx = side === \"left\" ? rect.left - offset - width : rect.right + offset;\n\t}\n\treturn { x, y, w: width, h: height, side };\n}\n\n/** Keeps a stretched span within `MAX_STRETCH`, pulling its trailing end along. */\nfunction limitSpan(start: number, end: number, rest: number, dir: number) {\n\tconst max = rest * MAX_STRETCH;\n\tif (end - start <= max) return [start, Math.max(end, start + 1)] as const;\n\tif (dir > 0) return [end - max, end] as const;\n\tif (dir < 0) return [start, start + max] as const;\n\tconst middle = (start + end) / 2;\n\treturn [middle - max / 2, middle + max / 2] as const;\n}\n\nfunction mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n\treturn (node: T | null) => {\n\t\tconst cleanups: Array<() => void> = [];\n\t\tfor (const ref of refs) {\n\t\t\tif (typeof ref === \"function\") {\n\t\t\t\tconst cleanup = ref(node);\n\t\t\t\tif (typeof cleanup === \"function\") cleanups.push(cleanup);\n\t\t\t} else if (ref) {\n\t\t\t\t(ref as RefObject<T | null>).current = node;\n\t\t\t}\n\t\t}\n\t\tif (cleanups.length === 0) return;\n\t\treturn () => {\n\t\t\tfor (const cleanup of cleanups) cleanup();\n\t\t};\n\t};\n}\n\n/** Shared by the visible label and its unseen measure, so both lay out alike. */\nconst LABEL = \"flex items-center gap-2 whitespace-nowrap\";\n\nfunction Label({\n\tcontent,\n\tshortcut,\n}: {\n\tcontent: ReactNode;\n\tshortcut?: Shortcut;\n}) {\n\tconst keys = keysOf(shortcut);\n\treturn (\n\t\t<>\n\t\t\t<span>{content}</span>\n\t\t\t{keys.length > 0 ? (\n\t\t\t\t<span\n\t\t\t\t\tdata-slot=\"fluid-tooltip-shortcut\"\n\t\t\t\t\tclassName=\"flex gap-px text-neutral-400 tabular-nums\"\n\t\t\t\t>\n\t\t\t\t\t{keys.map((key, index) => (\n\t\t\t\t\t\t<span key={index}>{key}</span>\n\t\t\t\t\t))}\n\t\t\t\t</span>\n\t\t\t) : null}\n\t\t</>\n\t);\n}\n\ninterface Swap {\n\taxis: Axis;\n\tdir: number;\n\tappear: boolean;\n\treduced: boolean;\n}\n\nfunction nudge(axis: Axis, distance: number) {\n\treturn axis === \"x\" ? { x: distance, y: 0 } : { x: 0, y: distance };\n}\n\n// A quick crossfade: the old label fades out fast while drifting a couple of\n// px in the direction of travel, and the new one follows it in. Reduced motion\n// keeps the fade and drops the drift.\nconst labelVariants: Variants = {\n\tenter: ({ axis, dir, reduced }: Swap) =>\n\t\treduced\n\t\t\t? { opacity: 0 }\n\t\t\t: { opacity: 0, ...nudge(axis, -dir * SWAP_NUDGE) },\n\tcenter: {\n\t\topacity: 1,\n\t\tx: 0,\n\t\ty: 0,\n\t\ttransition: { duration: SWAP_IN, delay: SWAP_IN_DELAY, ease: EASE_OUT },\n\t},\n\texit: ({ axis, dir, appear, reduced }: Swap) =>\n\t\tappear\n\t\t\t? { opacity: 0, transition: { duration: 0 } }\n\t\t\t: {\n\t\t\t\t\topacity: 0,\n\t\t\t\t\t...(reduced ? {} : nudge(axis, dir * SWAP_NUDGE)),\n\t\t\t\t\ttransition: { duration: SWAP_OUT, ease: EASE_OUT },\n\t\t\t\t},\n};\n\nfunction keepOnFrameLoop() {}\n\ninterface Edges {\n\tleft: MotionValue<number>;\n\tright: MotionValue<number>;\n\ttop: MotionValue<number>;\n\tbottom: MotionValue<number>;\n\t/** Resting length on each axis, for the stretch limit. */\n\trestW: MotionValue<number>;\n\trestH: MotionValue<number>;\n\taxis: MotionValue<Axis>;\n\tdir: MotionValue<number>;\n\tleanX: MotionValue<number>;\n\tleanY: MotionValue<number>;\n\t/** Device px per bubble px, so the resting bubble lands on whole pixels. */\n\tpixel: MotionValue<number>;\n\topacity: MotionValue<number>;\n\tscale: MotionValue<number>;\n\torigin: MotionValue<string>;\n}\n\nfunction FluidTooltipBubble({\n\tview,\n\topen,\n\treduced,\n\tedges,\n\ttooltipId,\n\tclassName,\n\tbubbleRef,\n\tmeasureRef,\n\tonPointerEnter,\n\tonPointerLeave,\n}: {\n\tview: View;\n\topen: boolean;\n\treduced: boolean;\n\tedges: Edges;\n\ttooltipId: string;\n\tclassName?: string;\n\tbubbleRef: (node: HTMLDivElement | null) => void;\n\tmeasureRef: (node: HTMLSpanElement | null) => void;\n\tonPointerEnter: () => void;\n\tonPointerLeave: () => void;\n}) {\n\tconst x = useMotionValue(0);\n\tconst y = useMotionValue(0);\n\tconst width = useMotionValue(0);\n\tconst height = useMotionValue(0);\n\n\t// Draws the box between the four edges. Subscribed in a layout effect, so\n\t// it sees the edges the group sets in its own layout effect on open.\n\tuseLayoutEffect(() => {\n\t\tconst draw = () => {\n\t\t\tlet left = edges.left.get() + edges.leanX.get();\n\t\t\tlet right = edges.right.get() + edges.leanX.get();\n\t\t\tlet top = edges.top.get() + edges.leanY.get();\n\t\t\tlet bottom = edges.bottom.get() + edges.leanY.get();\n\t\t\tconst axis = edges.axis.get();\n\t\t\tconst dir = edges.dir.get();\n\t\t\tconst restW = edges.restW.get() || 1;\n\t\t\tconst restH = edges.restH.get() || 1;\n\t\t\tif (axis === \"x\") [left, right] = limitSpan(left, right, restW, dir);\n\t\t\telse [top, bottom] = limitSpan(top, bottom, restH, dir);\n\t\t\tconst pixel = edges.pixel.get() || 1;\n\t\t\tconst snap = (value: number) => Math.round(value * pixel) / pixel;\n\t\t\tx.set(snap(left));\n\t\t\ty.set(snap(top));\n\t\t\twidth.set(snap(right) - snap(left));\n\t\t\theight.set(snap(bottom) - snap(top));\n\t\t};\n\t\tdraw();\n\t\tconst inputs = [\n\t\t\tedges.left,\n\t\t\tedges.right,\n\t\t\tedges.top,\n\t\t\tedges.bottom,\n\t\t\tedges.leanX,\n\t\t\tedges.leanY,\n\t\t\tedges.axis,\n\t\t\tedges.dir,\n\t\t\tedges.restW,\n\t\t\tedges.restH,\n\t\t\tedges.pixel,\n\t\t] as MotionValue<unknown>[];\n\t\tconst stops = inputs.map((value) => value.on(\"change\", draw));\n\t\treturn () => {\n\t\t\tfor (const stop of stops) stop();\n\t\t};\n\t}, [edges, x, y, width, height]);\n\n\tconst swap: Swap = {\n\t\taxis: view.axis,\n\t\tdir: view.dir,\n\t\tappear: view.appear,\n\t\treduced,\n\t};\n\tconst keys = keysOf(view.shortcut);\n\n\treturn (\n\t\t<m.div\n\t\t\tref={bubbleRef}\n\t\t\tid={tooltipId}\n\t\t\trole=\"tooltip\"\n\t\t\tdata-slot=\"fluid-tooltip\"\n\t\t\tdata-state={open ? \"open\" : \"closed\"}\n\t\t\tonPointerEnter={onPointerEnter}\n\t\t\tonPointerLeave={onPointerLeave}\n\t\t\tstyle={{\n\t\t\t\tx,\n\t\t\t\ty,\n\t\t\t\twidth,\n\t\t\t\theight,\n\t\t\t\topacity: edges.opacity,\n\t\t\t\tscale: edges.scale,\n\t\t\t\ttransformOrigin: edges.origin,\n\t\t\t}}\n\t\t\tclassName={cn(\n\t\t\t\t// Only transform and opacity animate on the compositor; width is written\n\t\t\t\t// on a fixed, layout-contained box, so nothing else on the page reflows.\n\t\t\t\t\"group/fluid-tooltip pointer-events-none fixed top-0 left-0 z-50 select-none rounded-md bg-neutral-900 font-medium text-neutral-50 text-xs leading-4 shadow-[0_1px_2px_rgb(0_0_0/0.08),0_4px_12px_rgb(0_0_0/0.08)] [contain:layout] data-[state=open]:pointer-events-auto dark:bg-neutral-800 dark:text-neutral-100 dark:shadow-[inset_0_0_0_1px_rgb(255_255_255/0.08),0_1px_2px_rgb(0_0_0/0.3),0_4px_12px_rgb(0_0_0/0.25)]\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{/* Keeps the bubble open while the pointer crosses the gap from its trigger. */}\n\t\t\t<span\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tdata-slot=\"fluid-tooltip-bridge\"\n\t\t\t\tclassName=\"absolute group-data-[side=bottom]/fluid-tooltip:inset-x-0 group-data-[side=top]/fluid-tooltip:inset-x-0 group-data-[side=left]/fluid-tooltip:inset-y-0 group-data-[side=right]/fluid-tooltip:inset-y-0 group-data-[side=top]/fluid-tooltip:top-full group-data-[side=right]/fluid-tooltip:right-full group-data-[side=bottom]/fluid-tooltip:bottom-full group-data-[side=left]/fluid-tooltip:left-full group-data-[side=bottom]/fluid-tooltip:h-(--fluid-tooltip-offset) group-data-[side=top]/fluid-tooltip:h-(--fluid-tooltip-offset) group-data-[side=left]/fluid-tooltip:w-(--fluid-tooltip-offset) group-data-[side=right]/fluid-tooltip:w-(--fluid-tooltip-offset)\"\n\t\t\t/>\n\t\t\t<span className=\"sr-only\">\n\t\t\t\t{view.content}\n\t\t\t\t{keys.length > 0 ? ` ${keys.join(\" \")}` : null}\n\t\t\t</span>\n\t\t\t<span\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName=\"absolute inset-0 overflow-hidden rounded-[inherit]\"\n\t\t\t>\n\t\t\t\t<AnimatePresence initial={false} custom={swap}>\n\t\t\t\t\t<m.span\n\t\t\t\t\t\tkey={view.seq}\n\t\t\t\t\t\tcustom={swap}\n\t\t\t\t\t\tvariants={labelVariants}\n\t\t\t\t\t\tinitial={view.appear ? false : \"enter\"}\n\t\t\t\t\t\tanimate=\"center\"\n\t\t\t\t\t\texit=\"exit\"\n\t\t\t\t\t\t// Keeps the swap on motion's frame loop, in step with the edge\n\t\t\t\t\t\t// springs, instead of handing it to WAAPI.\n\t\t\t\t\t\tonUpdate={keepOnFrameLoop}\n\t\t\t\t\t\tclassName={cn(\"absolute inset-0 justify-center\", LABEL)}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Label content={view.content} shortcut={view.shortcut} />\n\t\t\t\t\t</m.span>\n\t\t\t\t</AnimatePresence>\n\t\t\t</span>\n\t\t\t{/* The new label, laid out unseen so the bubble can size itself before it fades in. */}\n\t\t\t<span\n\t\t\t\tref={measureRef}\n\t\t\t\taria-hidden=\"true\"\n\t\t\t\tclassName={cn(\"invisible absolute top-0 left-0\", LABEL)}\n\t\t\t>\n\t\t\t\t<Label content={view.content} shortcut={view.shortcut} />\n\t\t\t</span>\n\t\t</m.div>\n\t);\n}\n\n/**\n * Shares one tooltip between every `FluidTooltip` inside it, such as the\n * buttons of a toolbar, rail, or dock. Renders no element of its own.\n */\nexport function FluidTooltipGroup({\n\tside = \"top\",\n\talign = \"center\",\n\tsideOffset = 8,\n\tdelay = 500,\n\tskipDelay = 400,\n\tfollow = false,\n\tsound = false,\n\tclassName,\n\tchildren,\n}: FluidTooltipGroupProps) {\n\tconst tooltipId = `fluid-tooltip-${useId().replace(/[^\\w-]/g, \"\")}`;\n\tconst reducedMotion = useReducedMotion() ?? false;\n\tconst [view, setView] = useState<View | null>(null);\n\tconst [open, setOpen] = useState(false);\n\tconst [present, setPresent] = useState(false);\n\n\tconst { trigger: haptic } = useWebHaptics();\n\t// Sound stays on under reduced motion; only movement is reduced.\n\tconst { hover: playTick } = useTiks({\n\t\ttheme: TICK_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst edges: Edges = {\n\t\tleft: useMotionValue(0),\n\t\tright: useMotionValue(0),\n\t\ttop: useMotionValue(0),\n\t\tbottom: useMotionValue(0),\n\t\trestW: useMotionValue(1),\n\t\trestH: useMotionValue(1),\n\t\taxis: useMotionValue<Axis>(\"x\"),\n\t\tdir: useMotionValue(0),\n\t\tleanX: useMotionValue(0),\n\t\tleanY: useMotionValue(0),\n\t\tpixel: useMotionValue(1),\n\t\topacity: useMotionValue(0),\n\t\tscale: useMotionValue(1),\n\t\torigin: useMotionValue(\"50% 100%\"),\n\t};\n\n\t// Handlers read the latest props through a ref, so the API stays stable.\n\tconst latest = useRef({\n\t\tside,\n\t\talign,\n\t\tsideOffset,\n\t\tdelay,\n\t\tskipDelay,\n\t\tfollow,\n\t\tsound,\n\t\treducedMotion,\n\t\thaptic,\n\t\tplayTick,\n\t});\n\tuseLayoutEffect(() => {\n\t\tlatest.current = {\n\t\t\tside,\n\t\t\talign,\n\t\t\tsideOffset,\n\t\t\tdelay,\n\t\t\tskipDelay,\n\t\t\tfollow,\n\t\t\tsound,\n\t\t\treducedMotion,\n\t\t\thaptic,\n\t\t\tplayTick,\n\t\t};\n\t});\n\n\t// The imperative core: timers, the active trigger, and the edge springs.\n\tconst [core] = useState(() => {\n\t\tconst triggers = new Map<string, TriggerEntry>();\n\t\tlet bubble: HTMLDivElement | null = null;\n\t\tlet measure: HTMLSpanElement | null = null;\n\t\tlet target: Target | null = null;\n\t\tlet activeKey: string | null = null;\n\t\tlet isOpen = false;\n\t\tlet closedAt = Number.NEGATIVE_INFINITY;\n\t\tlet hovered: string | null = null;\n\t\tlet focused: string | null = null;\n\t\tlet bubbleHovered = false;\n\t\t/** Esc hides the bubble until the pointer or focus leaves that trigger. */\n\t\tlet dismissed: string | null = null;\n\t\tlet touchKey: string | null = null;\n\t\tlet touchStart: { key: string; x: number; y: number } | null = null;\n\t\tlet suppressClick: string | null = null;\n\t\tlet pending: \"appear\" | \"move\" | \"stay\" | null = null;\n\t\tlet travel: { axis: Axis; dir: number } = { axis: \"x\", dir: 0 };\n\t\tlet seq = 0;\n\t\tlet lastTick = Number.NEGATIVE_INFINITY;\n\t\tlet delayTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet closeTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet longPressTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tlet touchHideTimer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst silent = () => document.visibilityState === \"hidden\";\n\n\t\tconst clearTimers = () => {\n\t\t\tclearTimeout(delayTimer);\n\t\t\tclearTimeout(closeTimer);\n\t\t\tclearTimeout(touchHideTimer);\n\t\t};\n\n\t\tconst measureTarget = (): Target | null => {\n\t\t\tconst entry = activeKey ? triggers.get(activeKey) : undefined;\n\t\t\tconst element = entry?.element;\n\t\t\tif (!entry || !element?.isConnected || !bubble) return null;\n\t\t\tconst props = latest.current;\n\t\t\t// Inside CSS `zoom`, the bubble takes the trigger's zoom and works in\n\t\t\t// its px, so it matches the trigger's scale.\n\t\t\tconst zoom = (element as ZoomedElement).currentCSSZoom ?? 1;\n\t\t\tbubble.style.zoom = zoom === 1 ? \"\" : String(zoom);\n\t\t\tbubble.style.setProperty(\n\t\t\t\t\"--fluid-tooltip-offset\",\n\t\t\t\t`${props.sideOffset}px`,\n\t\t\t);\n\t\t\tconst pixel = window.devicePixelRatio * zoom;\n\t\t\tedges.pixel.set(pixel);\n\t\t\tconst snap = (value: number) => Math.round(value * pixel) / pixel;\n\t\t\tconst rect = element.getBoundingClientRect();\n\t\t\tconst root = document.documentElement;\n\t\t\tconst width = Math.max(\n\t\t\t\tHEIGHT,\n\t\t\t\tMath.ceil(measure?.offsetWidth ?? 0) + PAD_X * 2,\n\t\t\t);\n\t\t\tconst placed = placeBubble(\n\t\t\t\t{\n\t\t\t\t\tleft: rect.left / zoom,\n\t\t\t\t\tright: rect.right / zoom,\n\t\t\t\t\ttop: rect.top / zoom,\n\t\t\t\t\tbottom: rect.bottom / zoom,\n\t\t\t\t},\n\t\t\t\twidth,\n\t\t\t\tHEIGHT,\n\t\t\t\tentry.side ?? props.side,\n\t\t\t\tprops.align,\n\t\t\t\tprops.sideOffset,\n\t\t\t\t{ width: root.clientWidth / zoom, height: root.clientHeight / zoom },\n\t\t\t\tgetComputedStyle(element).direction === \"rtl\",\n\t\t\t);\n\t\t\tconst triggerX = (rect.left + rect.width / 2) / zoom;\n\t\t\tconst triggerY = (rect.top + rect.height / 2) / zoom;\n\t\t\tconst originX = clamp((triggerX - placed.x) / placed.w) * 100;\n\t\t\tconst originY = clamp((triggerY - placed.y) / placed.h) * 100;\n\t\t\tconst origin =\n\t\t\t\tplaced.side === \"top\"\n\t\t\t\t\t? `${originX}% 100%`\n\t\t\t\t\t: placed.side === \"bottom\"\n\t\t\t\t\t\t? `${originX}% 0%`\n\t\t\t\t\t\t: placed.side === \"left\"\n\t\t\t\t\t\t\t? `100% ${originY}%`\n\t\t\t\t\t\t\t: `0% ${originY}%`;\n\t\t\treturn {\n\t\t\t\t...placed,\n\t\t\t\tx: snap(placed.x),\n\t\t\t\ty: snap(placed.y),\n\t\t\t\torigin,\n\t\t\t};\n\t\t};\n\n\t\tconst spring = (\n\t\t\tvalue: MotionValue<number>,\n\t\t\tto: number,\n\t\t\tconfig: { stiffness: number; damping: number },\n\t\t) => {\n\t\t\tif (value.get() === to && !value.isAnimating()) return;\n\t\t\t// Starts from the edge's current position and velocity.\n\t\t\tanimate(value, to, {\n\t\t\t\ttype: \"spring\",\n\t\t\t\t...config,\n\t\t\t\trestDelta: 0.05,\n\t\t\t\trestSpeed: 2,\n\t\t\t});\n\t\t};\n\n\t\t/** Moves the edges to `next`: at once, across the travel, or along it. */\n\t\tconst retarget = (next: Target, how: \"jump\" | \"move\" | \"cross\") => {\n\t\t\tconst previous = target;\n\t\t\ttarget = next;\n\t\t\tif (bubble) bubble.dataset.side = next.side;\n\t\t\tedges.origin.set(next.origin);\n\t\t\tconst { left, right, top, bottom } = edges;\n\t\t\tif (how === \"jump\" || !previous || latest.current.reducedMotion) {\n\t\t\t\tedges.dir.set(0);\n\t\t\t\tedges.restW.set(next.w);\n\t\t\t\tedges.restH.set(next.h);\n\t\t\t\tleft.jump(next.x);\n\t\t\t\tright.jump(next.x + next.w);\n\t\t\t\ttop.jump(next.y);\n\t\t\t\tbottom.jump(next.y + next.h);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { axis, dir } =\n\t\t\t\thow === \"move\" ? travel : { axis: travel.axis, dir: 0 };\n\t\t\tedges.axis.set(axis);\n\t\t\tedges.dir.set(dir);\n\t\t\tedges.restW.set(axis === \"x\" ? Math.max(previous.w, next.w) : next.w);\n\t\t\tedges.restH.set(axis === \"y\" ? Math.max(previous.h, next.h) : next.h);\n\t\t\tconst role = (edgeAxis: Axis, facing: number) =>\n\t\t\t\tedgeAxis !== axis || dir === 0\n\t\t\t\t\t? crossSpring\n\t\t\t\t\t: facing === dir\n\t\t\t\t\t\t? leadSpring\n\t\t\t\t\t\t: trailSpring;\n\t\t\tspring(left, next.x, role(\"x\", -1));\n\t\t\tspring(right, next.x + next.w, role(\"x\", 1));\n\t\t\tspring(top, next.y, role(\"y\", -1));\n\t\t\tspring(bottom, next.y + next.h, role(\"y\", 1));\n\t\t};\n\n\t\tconst moving = () =>\n\t\t\tedges.left.isAnimating() ||\n\t\t\tedges.right.isAnimating() ||\n\t\t\tedges.top.isAnimating() ||\n\t\t\tedges.bottom.isAnimating();\n\n\t\t/** Follows the trigger after a scroll, resize, or label change. */\n\t\tconst sync = (how: \"jump\" | \"cross\") => {\n\t\t\tif (!isOpen) return;\n\t\t\tconst next = measureTarget();\n\t\t\tif (!next) {\n\t\t\t\thide();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\ttarget &&\n\t\t\t\tMath.abs(next.x - target.x) < 0.5 &&\n\t\t\t\tMath.abs(next.y - target.y) < 0.5 &&\n\t\t\t\tMath.abs(next.w - target.w) < 0.5 &&\n\t\t\t\tnext.side === target.side\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tretarget(next, how === \"cross\" && moving() ? \"cross\" : \"jump\");\n\t\t};\n\n\t\tconst fadeIn = (appear: boolean) => {\n\t\t\tconst reduced = latest.current.reducedMotion;\n\t\t\tif (appear) {\n\t\t\t\tedges.opacity.jump(0);\n\t\t\t\tedges.scale.jump(reduced ? 1 : OPEN_SCALE);\n\t\t\t}\n\t\t\tconst duration = reduced ? FADE_DURATION : OPEN_DURATION;\n\t\t\tanimate(edges.opacity, 1, { duration, ease: EASE_OUT });\n\t\t\tif (!reduced) animate(edges.scale, 1, { duration, ease: EASE_OUT });\n\t\t};\n\n\t\tconst show = (key: string, source: \"pointer\" | \"focus\" | \"touch\") => {\n\t\t\tclearTimers();\n\t\t\tconst entry = triggers.get(key);\n\t\t\tif (!entry?.element?.isConnected || entry.disabled) return;\n\t\t\tif (dismissed === key) return;\n\t\t\tif (isOpen && activeKey === key) return;\n\t\t\tconst previousKey = activeKey;\n\t\t\tconst visible = isOpen || edges.opacity.get() > 0.02;\n\t\t\tconst switching = visible && previousKey !== null && previousKey !== key;\n\n\t\t\ttravel = { axis: travel.axis, dir: 0 };\n\t\t\tconst previous = previousKey ? triggers.get(previousKey)?.element : null;\n\t\t\tif (switching && previous?.isConnected) {\n\t\t\t\tconst from = center(previous);\n\t\t\t\tconst to = center(entry.element);\n\t\t\t\tconst dx = to.x - from.x;\n\t\t\t\tconst dy = to.y - from.y;\n\t\t\t\tconst axis: Axis = Math.abs(dx) >= Math.abs(dy) ? \"x\" : \"y\";\n\t\t\t\tconst delta = axis === \"x\" ? dx : dy;\n\t\t\t\ttravel = { axis, dir: Math.abs(delta) < 0.5 ? 0 : Math.sign(delta) };\n\t\t\t}\n\n\t\t\tconst props = latest.current;\n\t\t\tif (props.sound && source === \"pointer\" && switching && !silent()) {\n\t\t\t\tconst now = performance.now();\n\t\t\t\tif (now - lastTick >= TICK_THROTTLE) {\n\t\t\t\t\tlastTick = now;\n\t\t\t\t\tprops.playTick();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tactiveKey = key;\n\t\t\tisOpen = true;\n\t\t\tpending = switching ? \"move\" : visible ? \"stay\" : \"appear\";\n\t\t\tif (pending !== \"stay\") seq += 1;\n\t\t\tconst nextSeq = seq;\n\t\t\tconst { axis, dir } = travel;\n\t\t\tsetView({\n\t\t\t\tkey,\n\t\t\t\tcontent: entry.content,\n\t\t\t\tshortcut: entry.shortcut,\n\t\t\t\tseq: nextSeq,\n\t\t\t\taxis,\n\t\t\t\tdir,\n\t\t\t\tappear: pending === \"appear\",\n\t\t\t});\n\t\t\tsetOpen(true);\n\t\t\tsetPresent(true);\n\t\t};\n\n\t\tconst hide = () => {\n\t\t\tclearTimers();\n\t\t\tclearTimeout(longPressTimer);\n\t\t\ttouchKey = null;\n\t\t\tif (!isOpen) return;\n\t\t\tisOpen = false;\n\t\t\tclosedAt = performance.now();\n\t\t\tsetOpen(false);\n\t\t\tconst fade = animate(edges.opacity, 0, {\n\t\t\t\tduration: latest.current.reducedMotion ? FADE_DURATION : CLOSE_DURATION,\n\t\t\t\tease: \"easeOut\",\n\t\t\t});\n\t\t\tvoid fade.then(() => {\n\t\t\t\tif (isOpen) return;\n\t\t\t\tedges.leanX.jump(0);\n\t\t\t\tedges.leanY.jump(0);\n\t\t\t\ttarget = null;\n\t\t\t\tsetPresent(false);\n\t\t\t});\n\t\t};\n\n\t\t/** After a short grace, follows whatever still holds the tooltip, or closes. */\n\t\tconst scheduleClose = () => {\n\t\t\tclearTimeout(closeTimer);\n\t\t\tcloseTimer = setTimeout(() => {\n\t\t\t\tif (bubbleHovered || touchKey) return;\n\t\t\t\tconst next = hovered ?? focused;\n\t\t\t\tif (next && next !== dismissed) {\n\t\t\t\t\tshow(next, hovered ? \"pointer\" : \"focus\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\thide();\n\t\t\t}, CLOSE_GRACE);\n\t\t};\n\n\t\tconst api: GroupApi = {\n\t\t\tregister(key, entry) {\n\t\t\t\tconst previous = triggers.get(key);\n\t\t\t\ttriggers.set(key, entry);\n\t\t\t\tif (key !== activeKey || !isOpen) return;\n\t\t\t\tif (entry.disabled) {\n\t\t\t\t\thide();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tprevious &&\n\t\t\t\t\t(previous.content !== entry.content ||\n\t\t\t\t\t\t!sameShortcut(previous.shortcut, entry.shortcut))\n\t\t\t\t) {\n\t\t\t\t\t// The label changed in place: replace it without a swap.\n\t\t\t\t\tsetView((current) =>\n\t\t\t\t\t\tcurrent && current.key === key\n\t\t\t\t\t\t\t? { ...current, content: entry.content, shortcut: entry.shortcut }\n\t\t\t\t\t\t\t: current,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t},\n\t\t\tunregister(key) {\n\t\t\t\ttriggers.delete(key);\n\t\t\t\tif (hovered === key) hovered = null;\n\t\t\t\tif (focused === key) focused = null;\n\t\t\t\tif (key === activeKey && isOpen) hide();\n\t\t\t},\n\t\t\tpointerEnter(key, event) {\n\t\t\t\tif (event.pointerType === \"touch\") return;\n\t\t\t\thovered = key;\n\t\t\t\tclearTimeout(closeTimer);\n\t\t\t\tif (dismissed === key) return;\n\t\t\t\tconst props = latest.current;\n\t\t\t\tif (\n\t\t\t\t\tisOpen ||\n\t\t\t\t\tprops.delay <= 0 ||\n\t\t\t\t\tperformance.now() - closedAt < props.skipDelay\n\t\t\t\t) {\n\t\t\t\t\tshow(key, \"pointer\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tclearTimeout(delayTimer);\n\t\t\t\tdelayTimer = setTimeout(() => {\n\t\t\t\t\tif (hovered === key) show(key, \"pointer\");\n\t\t\t\t}, props.delay);\n\t\t\t},\n\t\t\tpointerLeave(key, event) {\n\t\t\t\tif (event.pointerType === \"touch\") return;\n\t\t\t\tif (hovered === key) hovered = null;\n\t\t\t\tif (dismissed === key) dismissed = null;\n\t\t\t\tclearTimeout(delayTimer);\n\t\t\t\tif (isOpen) scheduleClose();\n\t\t\t},\n\t\t\tpointerMove(key, event) {\n\t\t\t\tif (event.pointerType === \"touch\") {\n\t\t\t\t\tif (\n\t\t\t\t\t\ttouchStart?.key === key &&\n\t\t\t\t\t\tMath.hypot(\n\t\t\t\t\t\t\tevent.clientX - touchStart.x,\n\t\t\t\t\t\t\tevent.clientY - touchStart.y,\n\t\t\t\t\t\t) > TOUCH_SLOP\n\t\t\t\t\t) {\n\t\t\t\t\t\tclearTimeout(longPressTimer);\n\t\t\t\t\t\ttouchStart = null;\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst props = latest.current;\n\t\t\t\tif (!props.follow || props.reducedMotion) return;\n\t\t\t\tif (!isOpen || key !== activeKey || !target) return;\n\t\t\t\tconst element = triggers.get(key)?.element;\n\t\t\t\tif (!element) return;\n\t\t\t\tconst rect = element.getBoundingClientRect();\n\t\t\t\tconst zoom = (element as ZoomedElement).currentCSSZoom ?? 1;\n\t\t\t\tconst across = target.side === \"top\" || target.side === \"bottom\";\n\t\t\t\tconst amount = across\n\t\t\t\t\t? (event.clientX - (rect.left + rect.width / 2)) / (rect.width / 2)\n\t\t\t\t\t: (event.clientY - (rect.top + rect.height / 2)) / (rect.height / 2);\n\t\t\t\tconst lean = (clamp(amount, -1, 1) * LEAN) / zoom;\n\t\t\t\tanimate(across ? edges.leanX : edges.leanY, lean, {\n\t\t\t\t\ttype: \"spring\",\n\t\t\t\t\t...leanSpring,\n\t\t\t\t});\n\t\t\t\tanimate(across ? edges.leanY : edges.leanX, 0, {\n\t\t\t\t\ttype: \"spring\",\n\t\t\t\t\t...leanSpring,\n\t\t\t\t});\n\t\t\t},\n\t\t\tpointerDown(key, event) {\n\t\t\t\tif (event.pointerType !== \"touch\") return;\n\t\t\t\tclearTimeout(longPressTimer);\n\t\t\t\ttouchStart = { key, x: event.clientX, y: event.clientY };\n\t\t\t\tlongPressTimer = setTimeout(() => {\n\t\t\t\t\ttouchStart = null;\n\t\t\t\t\tdismissed = null;\n\t\t\t\t\ttouchKey = key;\n\t\t\t\t\tshow(key, \"touch\");\n\t\t\t\t\tif (!silent()) void latest.current.haptic(\"light\");\n\t\t\t\t}, LONG_PRESS);\n\t\t\t},\n\t\t\tpointerUp(key, event) {\n\t\t\t\tif (event.pointerType !== \"touch\") return;\n\t\t\t\tclearTimeout(longPressTimer);\n\t\t\t\ttouchStart = null;\n\t\t\t\tif (touchKey !== key) return;\n\t\t\t\t// The release after a long press reads the label; it isn't a tap.\n\t\t\t\tsuppressClick = key;\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tif (suppressClick === key) suppressClick = null;\n\t\t\t\t}, 400);\n\t\t\t\tclearTimeout(touchHideTimer);\n\t\t\t\ttouchHideTimer = setTimeout(() => {\n\t\t\t\t\ttouchKey = null;\n\t\t\t\t\thide();\n\t\t\t\t}, TOUCH_HIDE);\n\t\t\t},\n\t\t\tfocus(key, element) {\n\t\t\t\t// Keyboard focus only; a click or tap that focuses a button doesn't open it.\n\t\t\t\tif (!element.matches(\":focus-visible\")) return;\n\t\t\t\tfocused = key;\n\t\t\t\tif (dismissed !== key) dismissed = null;\n\t\t\t\tshow(key, \"focus\");\n\t\t\t},\n\t\t\tblur(key) {\n\t\t\t\tif (focused === key) focused = null;\n\t\t\t\tif (dismissed === key) dismissed = null;\n\t\t\t\tif (isOpen) scheduleClose();\n\t\t\t},\n\t\t\tclickCapture(key, event) {\n\t\t\t\tif (suppressClick !== key) return;\n\t\t\t\tsuppressClick = null;\n\t\t\t\tevent.preventDefault();\n\t\t\t\tevent.stopPropagation();\n\t\t\t},\n\t\t\tcontextMenu(key, event) {\n\t\t\t\tif (touchKey === key || touchStart?.key === key) event.preventDefault();\n\t\t\t},\n\t\t};\n\n\t\treturn {\n\t\t\tapi,\n\t\t\tbubbleRef(node: HTMLDivElement | null) {\n\t\t\t\tbubble = node;\n\t\t\t},\n\t\t\tmeasureRef(node: HTMLSpanElement | null) {\n\t\t\t\tmeasure = node;\n\t\t\t},\n\t\t\tbubbleEnter() {\n\t\t\t\tbubbleHovered = true;\n\t\t\t\tclearTimeout(closeTimer);\n\t\t\t},\n\t\t\tbubbleLeave() {\n\t\t\t\tbubbleHovered = false;\n\t\t\t\tif (isOpen) scheduleClose();\n\t\t\t},\n\t\t\t/** Runs after the new label is in the DOM, so it can be measured. */\n\t\t\tcommit() {\n\t\t\t\tconst mode = pending;\n\t\t\t\tpending = null;\n\t\t\t\tif (!isOpen) return;\n\t\t\t\tif (mode === \"stay\") {\n\t\t\t\t\tfadeIn(false);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst next = measureTarget();\n\t\t\t\tif (!next) {\n\t\t\t\t\thide();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (mode === \"appear\") {\n\t\t\t\t\tretarget(next, \"jump\");\n\t\t\t\t\tfadeIn(true);\n\t\t\t\t} else if (mode === \"move\") {\n\t\t\t\t\tretarget(next, \"move\");\n\t\t\t\t\tfadeIn(false);\n\t\t\t\t} else {\n\t\t\t\t\tretarget(next, moving() ? \"cross\" : \"jump\");\n\t\t\t\t}\n\t\t\t},\n\t\t\t/** Listeners that only exist while the bubble is open. */\n\t\t\tlisten() {\n\t\t\t\tconst onKeyDown = (event: KeyboardEvent) => {\n\t\t\t\t\tif (event.key !== \"Escape\" || !isOpen) return;\n\t\t\t\t\tdismissed = activeKey;\n\t\t\t\t\thide();\n\t\t\t\t};\n\t\t\t\tconst onScroll = () => sync(\"jump\");\n\t\t\t\tdocument.addEventListener(\"keydown\", onKeyDown);\n\t\t\t\twindow.addEventListener(\"scroll\", onScroll, {\n\t\t\t\t\tcapture: true,\n\t\t\t\t\tpassive: true,\n\t\t\t\t});\n\t\t\t\twindow.addEventListener(\"resize\", onScroll, { passive: true });\n\t\t\t\treturn () => {\n\t\t\t\t\tdocument.removeEventListener(\"keydown\", onKeyDown);\n\t\t\t\t\twindow.removeEventListener(\"scroll\", onScroll, { capture: true });\n\t\t\t\t\twindow.removeEventListener(\"resize\", onScroll);\n\t\t\t\t};\n\t\t\t},\n\t\t\t/** Re-measures when the active trigger or the label changes size. */\n\t\t\tobserve() {\n\t\t\t\tconst element = activeKey ? triggers.get(activeKey)?.element : null;\n\t\t\t\tif (!element || !measure) return () => undefined;\n\t\t\t\tconst observer = new ResizeObserver(() => sync(\"cross\"));\n\t\t\t\tobserver.observe(element);\n\t\t\t\tobserver.observe(measure);\n\t\t\t\treturn () => observer.disconnect();\n\t\t\t},\n\t\t\tdispose() {\n\t\t\t\tclearTimers();\n\t\t\t\tclearTimeout(longPressTimer);\n\t\t\t},\n\t\t};\n\t});\n\n\tuseLayoutEffect(() => {\n\t\tif (view) core.commit();\n\t}, [core, view]);\n\n\tuseEffect(() => (open ? core.listen() : undefined), [core, open]);\n\n\tconst activeKey = view?.key;\n\tuseEffect(\n\t\t() => (open && activeKey ? core.observe() : undefined),\n\t\t[core, open, activeKey],\n\t);\n\n\tuseEffect(() => () => core.dispose(), [core]);\n\n\tconst shownKey = open && view ? view.key : null;\n\tconst context = useMemo<GroupContextValue>(\n\t\t() => ({ api: core.api, tooltipId, shownKey }),\n\t\t[core, tooltipId, shownKey],\n\t);\n\n\treturn (\n\t\t<GroupContext.Provider value={context}>\n\t\t\t{children}\n\t\t\t{present && view\n\t\t\t\t? createPortal(\n\t\t\t\t\t\t// No layout projection: it would leave a window resize listener.\n\t\t\t\t\t\t<LazyMotion features={domAnimation}>\n\t\t\t\t\t\t\t<FluidTooltipBubble\n\t\t\t\t\t\t\t\tview={view}\n\t\t\t\t\t\t\t\topen={open}\n\t\t\t\t\t\t\t\treduced={reducedMotion}\n\t\t\t\t\t\t\t\tedges={edges}\n\t\t\t\t\t\t\t\ttooltipId={tooltipId}\n\t\t\t\t\t\t\t\tclassName={className}\n\t\t\t\t\t\t\t\tbubbleRef={core.bubbleRef}\n\t\t\t\t\t\t\t\tmeasureRef={core.measureRef}\n\t\t\t\t\t\t\t\tonPointerEnter={core.bubbleEnter}\n\t\t\t\t\t\t\t\tonPointerLeave={core.bubbleLeave}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</LazyMotion>,\n\t\t\t\t\t\tdocument.body,\n\t\t\t\t\t)\n\t\t\t\t: null}\n\t\t</GroupContext.Provider>\n\t);\n}\n\ntype TriggerChildProps = {\n\tref?: Ref<HTMLElement>;\n\tdisabled?: boolean;\n\t\"aria-describedby\"?: string;\n\tonPointerEnter?: (event: PointerEvent<HTMLElement>) => void;\n\tonPointerLeave?: (event: PointerEvent<HTMLElement>) => void;\n\tonPointerMove?: (event: PointerEvent<HTMLElement>) => void;\n\tonPointerDown?: (event: PointerEvent<HTMLElement>) => void;\n\tonPointerUp?: (event: PointerEvent<HTMLElement>) => void;\n\tonPointerCancel?: (event: PointerEvent<HTMLElement>) => void;\n\tonFocus?: (event: FocusEvent<HTMLElement>) => void;\n\tonBlur?: (event: FocusEvent<HTMLElement>) => void;\n\tonClickCapture?: (event: MouseEvent<HTMLElement>) => void;\n\tonContextMenu?: (event: MouseEvent<HTMLElement>) => void;\n};\n\n/** Runs the child's own handler first; ours is skipped if it prevented default. */\nfunction compose<E extends { defaultPrevented: boolean }>(\n\ttheirs: ((event: E) => void) | undefined,\n\tours: (event: E) => void,\n) {\n\treturn (event: E) => {\n\t\ttheirs?.(event);\n\t\tif (!event.defaultPrevented) ours(event);\n\t};\n}\n\nfunction FluidTooltipTrigger({\n\tcontent,\n\tshortcut,\n\tside,\n\tdisabled = false,\n\tchildren,\n\tgroup,\n}: FluidTooltipProps & { group: GroupContextValue }) {\n\tconst key = useId();\n\tconst elementRef = useRef<HTMLElement | null>(null);\n\tconst child = Children.only(children);\n\tconst childProps = (\n\t\tisValidElement(child) ? child.props : {}\n\t) as TriggerChildProps;\n\tconst off = disabled || childProps.disabled === true;\n\tconst { api, tooltipId, shownKey } = group;\n\tconst ref = mergeRefs(childProps.ref, elementRef);\n\n\tuseLayoutEffect(() => {\n\t\tapi.register(key, {\n\t\t\telement: elementRef.current,\n\t\t\tcontent,\n\t\t\tshortcut,\n\t\t\tside,\n\t\t\tdisabled: off,\n\t\t});\n\t});\n\tuseEffect(() => () => api.unregister(key), [api, key]);\n\n\tconst shown = shownKey === key;\n\tconst describedBy = shown\n\t\t? [childProps[\"aria-describedby\"], tooltipId].filter(Boolean).join(\" \")\n\t\t: childProps[\"aria-describedby\"];\n\tconst guard =\n\t\t<E,>(handler: (key: string, event: E) => void) =>\n\t\t(event: E) => {\n\t\t\tif (!off) handler(key, event);\n\t\t};\n\n\treturn cloneElement(child as ReactElement<Record<string, unknown>>, {\n\t\tref,\n\t\t\"data-slot\": \"fluid-tooltip-trigger\",\n\t\t\"aria-describedby\": describedBy,\n\t\tonPointerEnter: compose(childProps.onPointerEnter, guard(api.pointerEnter)),\n\t\tonPointerLeave: compose(childProps.onPointerLeave, (event) =>\n\t\t\tapi.pointerLeave(key, event),\n\t\t),\n\t\tonPointerMove: compose(childProps.onPointerMove, guard(api.pointerMove)),\n\t\tonPointerDown: compose(childProps.onPointerDown, guard(api.pointerDown)),\n\t\tonPointerUp: compose(childProps.onPointerUp, (event) =>\n\t\t\tapi.pointerUp(key, event),\n\t\t),\n\t\tonPointerCancel: compose(childProps.onPointerCancel, (event) =>\n\t\t\tapi.pointerUp(key, event),\n\t\t),\n\t\tonFocus: compose(childProps.onFocus, (event) => {\n\t\t\tif (!off) api.focus(key, event.currentTarget);\n\t\t}),\n\t\tonBlur: compose(childProps.onBlur, () => api.blur(key)),\n\t\tonClickCapture: compose(childProps.onClickCapture, (event) =>\n\t\t\tapi.clickCapture(key, event),\n\t\t),\n\t\tonContextMenu: compose(childProps.onContextMenu, (event) =>\n\t\t\tapi.contextMenu(key, event),\n\t\t),\n\t});\n}\n\n/**\n * Adds a tooltip to its one child. Inside a `FluidTooltipGroup` every trigger\n * shares one bubble that travels between them; on its own it works as a\n * normal tooltip with the same look.\n */\nexport function FluidTooltip(props: FluidTooltipProps) {\n\tconst group = useContext(GroupContext);\n\tif (!group) {\n\t\treturn (\n\t\t\t<FluidTooltipGroup side={props.side}>\n\t\t\t\t<FluidTooltip {...props} />\n\t\t\t</FluidTooltipGroup>\n\t\t);\n\t}\n\treturn <FluidTooltipTrigger {...props} group={group} />;\n}\n\nexport default FluidTooltip;\n",
      "type": "registry:component",
      "target": "@components/fluid-tooltip.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-13",
    "image": "https://cdn.tentui.com/images/components/fluid-tooltip?v=2",
    "video": "https://cdn.tentui.com/videos/components/fluid-tooltip?v=2"
  },
  "docs": "https://tentui.com/components/fluid-tooltip",
  "categories": [
    "overlays"
  ],
  "type": "registry:component"
}