import { IconCopy, IconGlobe } from '../icons'; import { createPositionTracker, type PositionTracker } from './popover/anchored-position'; import { promoteToTopLayer, removeFromTopLayer } from './top-layer'; import { twJoin } from './tw'; /** * Grace period (ms) between the pointer leaving the anchor/card and the card * hiding. Gives the pointer time to travel from the link onto the (hoverable) * card without it vanishing — the same "hoverable" affordance the tooltip uses * (WCAG 1.4.13). */ const GRACE_HIDE_DURATION = 250; /** * Delay (ms) before the card appears after the pointer rests on a link. A short * hover-intent gap so brushing past a link mid-sentence doesn't flash the card. */ const SHOW_DELAY = 350; /** * Vertical gap (px) between the anchor and the card placed below it. Used by the * anchor-relative fallback when no cursor position is supplied. */ const OFFSET_TOP = 6; /** * Vertical gap (px) between the link and the card. Anchored to the link's * bottom edge (not the pointer) so the gap stays consistent no matter where on * the link the pointer rests. */ const LINK_GAP_Y = 10; /** * Minimum gap (px) kept between the card and the viewport edges when clamping. */ const VIEWPORT_MARGIN = 4; /** * A pointer position in viewport coordinates. */ interface CursorPosition { x: number; y: number; } /** * Duration (ms) of the enter/leave fade+rise animation. MUST match the * `duration-150` transition on the wrapper: the leave animation sets the closed * state and removes the element only after this elapses, so the fade-out is * seen rather than clipped. */ const ANIMATION_DURATION = 150; /** * Shared chrome for the two trailing action buttons (copy / edit). Kept in one * const so both stay visually identical. `appearance-none border-0 bg-transparent` * + `font-[inherit]` neutralize any host-page global `button {}` styling (e.g. * the docs demo page paints a border on every button) so the card renders the * same everywhere. */ const ACTION_BUTTON_BASE = twJoin( // `p-0` is load-bearing: the UA stylesheet gives every