{"version":3,"sources":["useCallbackOnMouseMove.ts"],"sourcesContent":["// From: @framerjs/fresco/src/components/utils/useCallbackOnMouseMove.ts\nimport { MutableRefObject, useRef, useCallback } from \"react\"\nimport { Browser } from \"./browser.ts\"\n\nexport interface Point {\n    x: number\n    y: number\n}\n\n/**\n * Webkit fires mousemove events if the pointer's coordination changes relative\n * to its container (e.g. if the container scrolls), or when a modifier key is\n * pressed, mousemove would fire even if the cursor did not actually move.\n * This helper compares the cursor position between mouse events, and fire the\n * callback only when its position changes.\n */\nexport const useCallbackOnMouseMove = (\n    callback: (event: React.MouseEvent) => void,\n    mousePositionRef: MutableRefObject<Point | null>\n) => {\n    const prevPositionRef = useRef<Point | null>(null)\n\n    return useCallback(\n        (event: React.MouseEvent) => {\n            if (!Browser.isSafari()) return callback(event)\n\n            const ref = mousePositionRef ? mousePositionRef : prevPositionRef\n            const { clientX, clientY } = event\n            const prevCursorPosition = ref.current\n\n            ref.current = { x: clientX, y: clientY }\n\n            // Ignore mouse moves unless we have a position. Else it might be an\n            // element that appears behind the mouse without the mouse moving.\n            if (!prevCursorPosition) {\n                return\n            }\n\n            if (\n                prevCursorPosition.x !== clientX ||\n                prevCursorPosition.y !== clientY\n            ) {\n                return callback(event)\n            }\n        },\n        [mousePositionRef, callback]\n    )\n}\n"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAA2B,MAAM,CAAE,WAAW,KAAQ,OAAO,CAAA,AAC7D,OAAS,OAAO,KAAQ,cAAc,CAAA,AAOtC;;;;;;CAMC,GACD,OAAO,MAAM,sBAAsB,CAAG,CAClC,QAA2C,CAC3C,gBAAgD,GAC/C,CACD,MAAM,eAAe,CAAG,MAAM,CAAe,IAAI,CAAC,CAElD,OAAO,WAAW,CACd,AAAC,KAAuB,EAAK,CACzB,GAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA,AAE/C,MAAM,GAAG,CAAG,gBAAgB,CAAG,gBAAgB,CAAG,eAAe,CACjE,KAAM,CAAE,OAAO,CAAE,OAAO,CAAE,CAAG,KAAK,CAClC,MAAM,kBAAkB,CAAG,GAAG,CAAC,OAAO,CAEtC,GAAG,CAAC,OAAO,CAAG,CAAE,CAAC,CAAE,OAAO,CAAE,CAAC,CAAE,OAAO,CAAE,CAExC,oEAAoE;AACpE,kEAAkE;AAClE,GAAI,CAAC,kBAAkB,CAAE,CACrB,OAAM,AACV,CAAC,AAED,GACI,kBAAkB,CAAC,CAAC,GAAK,OAAO,EAChC,kBAAkB,CAAC,CAAC,GAAK,OAAO,CAClC,CACE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA,AAC1B,CAAC,AACL,CAAC,CACD,CAAC,gBAAgB,CAAE,QAAQ,CAAC,CAC/B,CAAA,AACL,CAAC,CAAA"}