{"version":3,"file":"use-map-hover.cjs","names":[],"sources":["../../src/br/use-map-hover.ts"],"sourcesContent":["import { useCallback, useState, type MouseEvent, type RefObject } from \"react\";\n\n/** The currently hovered item plus cursor position within the map container. */\nexport interface MapHover<T> {\n    item: T;\n    x: number;\n    y: number;\n}\n\n/**\n * Track which shape the cursor is over and where, for a floating map tooltip.\n * Positions are computed relative to `containerRef` so the tooltip can be\n * placed with plain `left`/`top` inside the (relatively positioned) container.\n */\nexport function useMapHover<T>(containerRef: RefObject<HTMLDivElement | null>): {\n    hover: MapHover<T> | null;\n    onMove: (item: T, event: MouseEvent) => void;\n    onLeave: () => void;\n} {\n    const [hover, setHover] = useState<MapHover<T> | null>(null);\n\n    const onMove = useCallback(\n        (item: T, event: MouseEvent): void => {\n            const rect = containerRef.current?.getBoundingClientRect();\n            if (!rect) return;\n            setHover({ item, x: event.clientX - rect.left, y: event.clientY - rect.top });\n        },\n        [containerRef],\n    );\n\n    const onLeave = useCallback((): void => setHover(null), []);\n\n    return { hover, onMove, onLeave };\n}\n"],"mappings":"uBAcA,SAAgB,EAAe,EAI7B,CACE,GAAM,CAAC,EAAO,IAAA,EAAY,EAAA,SAAA,CAA6B,IAAI,EAa3D,MAAO,CAAE,QAAO,QAAA,EAXD,EAAA,YAAA,EACV,EAAS,IAA4B,CAClC,IAAM,EAAO,EAAa,SAAS,sBAAsB,EACpD,GACL,EAAS,CAAE,OAAM,EAAG,EAAM,QAAU,EAAK,KAAM,EAAG,EAAM,QAAU,EAAK,GAAI,CAAC,CAChF,EACA,CAAC,CAAY,CAKD,EAAQ,SAAA,EAFR,EAAA,YAAA,KAAwB,EAAS,IAAI,EAAG,CAAC,CAEjC,CAAQ,CACpC"}