{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/useMouse/index.ts"],"sourcesContent":["import { useRef, useState } from 'react';\nimport { useEventListener } from '../../hooks/useEventListener';\n\ninterface CursorPosition {\n  screenX: number | null;\n  screenY: number | null;\n  clientX: number | null;\n  clientY: number | null;\n  pageX: number | null;\n  pageY: number | null;\n  elementRelativeX: number | null;\n  elementRelativeY: number | null;\n  elementPositionX: number | null;\n  elementPositionY: number | null;\n}\n\nconst initialCursorPosition: CursorPosition = {\n  screenX: null,\n  screenY: null,\n  clientX: null,\n  clientY: null,\n  pageX: null,\n  pageY: null,\n  elementRelativeX: null,\n  elementRelativeY: null,\n  elementPositionX: null,\n  elementPositionY: null,\n};\n\nexport function useMouse<T extends HTMLElement>(): {\n  ref: React.RefObject<T | null>;\n  position: CursorPosition;\n} {\n  const targetRef = useRef<T>(null);\n  const [cursorPosition, setCursorPosition] = useState<CursorPosition>(\n    initialCursorPosition\n  );\n\n  const handleMouseMove = (event: MouseEvent) => {\n    const { screenX, screenY, clientX, clientY, pageX, pageY } = event;\n\n    let elementRelativeX = null;\n    let elementRelativeY = null;\n    let elementPositionX = null;\n    let elementPositionY = null;\n\n    if (targetRef.current) {\n      const clientRect = targetRef.current.getBoundingClientRect();\n\n      elementRelativeX = clientX - clientRect.left;\n      elementRelativeY = clientY - clientRect.top;\n      elementPositionX = clientRect.left + window.scrollX;\n      elementPositionY = clientRect.top + window.scrollY;\n    }\n\n    setCursorPosition({\n      screenX,\n      screenY,\n      clientX,\n      clientY,\n      pageX,\n      pageY,\n      elementRelativeX,\n      elementRelativeY,\n      elementPositionX,\n      elementPositionY,\n    });\n  };\n\n  useEventListener(\n    typeof document !== 'undefined' ? document : null,\n    'mousemove',\n    handleMouseMove\n  );\n\n  return { ref: targetRef, position: cursorPosition };\n}\n"],"mappings":";;;AAgBA,MAAM,wBAAwC;CAC5C,SAAS;CACT,SAAS;CACT,SAAS;CACT,SAAS;CACT,OAAO;CACP,OAAO;CACP,kBAAkB;CAClB,kBAAkB;CAClB,kBAAkB;CAClB,kBAAkB;CACnB;AAED,SAAgB,WAGd;CACA,MAAM,YAAY,OAAU,KAAK;CACjC,MAAM,CAAC,gBAAgB,qBAAqB,SAC1C,sBACD;CAED,MAAM,mBAAmB,UAAsB;EAC7C,MAAM,EAAE,SAAS,SAAS,SAAS,SAAS,OAAO,UAAU;EAE7D,IAAI,mBAAmB;EACvB,IAAI,mBAAmB;EACvB,IAAI,mBAAmB;EACvB,IAAI,mBAAmB;EAEvB,IAAI,UAAU,SAAS;GACrB,MAAM,aAAa,UAAU,QAAQ,uBAAuB;GAE5D,mBAAmB,UAAU,WAAW;GACxC,mBAAmB,UAAU,WAAW;GACxC,mBAAmB,WAAW,OAAO,OAAO;GAC5C,mBAAmB,WAAW,MAAM,OAAO;;EAG7C,kBAAkB;GAChB;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC;;CAGJ,iBACE,OAAO,aAAa,cAAc,WAAW,MAC7C,aACA,gBACD;CAED,OAAO;EAAE,KAAK;EAAW,UAAU;EAAgB"}