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KAAK;oBAAA;oBAC5D,MAAM,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS;oBAC9B,IAAI,cAAc,CAAA,GAAA,wCAAa,EAAE,CAAA,GAAA,wCAAa,EAAE;oBAChD,kBAAkB,aAAa,eAAe,eAAe;oBAC7D,kBAAkB,aAAa,aAAa,aAAa;oBACzD,kBAAkB,aAAa,iBAAiB,aAAa;gBAC/D;YACF;QACF;QAEA,IAAI,sBAAsB,CAAC,GAAc,QAAgB;YACvD;YACA,sDAAsD;YACtD,UAAU,GAAG,YAAY,QAAQ;YACjC,sDAAsD;YACtD,SAAS,GAAG;QACd;QAEA,UAAU,SAAS,GAAG,CAAA;YACpB,OAAQ,EAAE,GAAG;gBACX,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,IAAI;oBAC3B;gBACF,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,GAAG;oBAC1B;gBACF,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,GAAG;oBAC1B;gBACF,KAAK;gBACL,KAAK;oBACH,EAAE,cAAc;oBAChB,EAAE,eAAe;oBACjB,oBAAoB,GAAG,GAAG;oBAC1B;YACJ;QACF;QAEA,OAAO;IACT,GAAG;QAAC;QAAmB;QAAsB;KAAM;IAEnD,OAAO;mBAAC;IAAS;AACnB","sources":["packages/react-aria/src/interactions/useMove.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {disableTextSelection, restoreTextSelection} from './textSelection';\nimport {DOMAttributes, MoveEvents, PointerType} from '@react-types/shared';\nimport {getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {getOwnerWindow} from '../utils/domHelpers';\nimport React, {useCallback, useMemo, useRef} from 'react';\nimport {useEffectEvent} from '../utils/useEffectEvent';\nimport {useGlobalListeners} from '../utils/useGlobalListeners';\n\nexport interface MoveResult {\n  /** Props to spread on the target element. */\n  moveProps: DOMAttributes;\n}\n\ninterface EventBase {\n  shiftKey: boolean;\n  ctrlKey: boolean;\n  metaKey: boolean;\n  altKey: boolean;\n}\n\n/**\n * Handles move interactions across mouse, touch, and keyboard, including dragging with\n * the mouse or touch, and using the arrow keys. Normalizes behavior across browsers and\n * platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useMove(props: MoveEvents): MoveResult {\n  let {onMoveStart, onMove, onMoveEnd} = props;\n\n  let state = useRef<{\n    didMove: boolean;\n    lastPosition: {pageX: number; pageY: number} | null;\n    id: number | null;\n  }>({didMove: false, lastPosition: null, id: null});\n\n  let {addGlobalListener, removeGlobalListener} = useGlobalListeners();\n\n  let move = useCallback(\n    (originalEvent: EventBase, pointerType: PointerType, deltaX: number, deltaY: number) => {\n      if (deltaX === 0 && deltaY === 0) {\n        return;\n      }\n\n      if (!state.current.didMove) {\n        state.current.didMove = true;\n        onMoveStart?.({\n          type: 'movestart',\n          pointerType,\n          shiftKey: originalEvent.shiftKey,\n          metaKey: originalEvent.metaKey,\n          ctrlKey: originalEvent.ctrlKey,\n          altKey: originalEvent.altKey\n        });\n      }\n      onMove?.({\n        type: 'move',\n        pointerType,\n        deltaX: deltaX,\n        deltaY: deltaY,\n        shiftKey: originalEvent.shiftKey,\n        metaKey: originalEvent.metaKey,\n        ctrlKey: originalEvent.ctrlKey,\n        altKey: originalEvent.altKey\n      });\n    },\n    [onMoveStart, onMove, state]\n  );\n  let moveEvent = useEffectEvent(move);\n\n  let end = useCallback(\n    (originalEvent: EventBase, pointerType: PointerType) => {\n      restoreTextSelection();\n      if (state.current.didMove) {\n        onMoveEnd?.({\n          type: 'moveend',\n          pointerType,\n          shiftKey: originalEvent.shiftKey,\n          metaKey: originalEvent.metaKey,\n          ctrlKey: originalEvent.ctrlKey,\n          altKey: originalEvent.altKey\n        });\n      }\n    },\n    [onMoveEnd, state]\n  );\n  let endEvent = useEffectEvent(end);\n\n  let moveProps = useMemo(() => {\n    let moveProps: DOMAttributes = {};\n\n    let start = () => {\n      disableTextSelection();\n      state.current.didMove = false;\n    };\n\n    if (typeof PointerEvent === 'undefined' && process.env.NODE_ENV === 'test') {\n      let onMouseMove = (e: MouseEvent) => {\n        if (e.button === 0) {\n          // Should be safe to use the useEffectEvent because these are equivalent https://github.com/reactjs/react.dev/issues/8075#issuecomment-3400179389\n          // However, the compiler is not smart enough to know that. As such, this whole file must be manually optimised as the compiler will bail.\n          //\n          // eslint-disable-next-line react-hooks/rules-of-hooks\n          moveEvent(\n            e,\n            'mouse',\n            e.pageX - (state.current.lastPosition?.pageX ?? 0),\n            e.pageY - (state.current.lastPosition?.pageY ?? 0)\n          );\n          state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n        }\n      };\n      let onMouseUp = (e: MouseEvent) => {\n        if (e.button === 0) {\n          // eslint-disable-next-line react-hooks/rules-of-hooks\n          endEvent(e, 'mouse');\n          let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n          removeGlobalListener(ownerWindow, 'mousemove', onMouseMove, false);\n          removeGlobalListener(ownerWindow, 'mouseup', onMouseUp, false);\n        }\n      };\n      moveProps.onMouseDown = (e: React.MouseEvent) => {\n        if (e.button === 0) {\n          start();\n          e.stopPropagation();\n          e.preventDefault();\n          state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n          let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n          addGlobalListener(ownerWindow, 'mousemove', onMouseMove, false);\n          addGlobalListener(ownerWindow, 'mouseup', onMouseUp, false);\n        }\n      };\n\n      let onTouchMove = (e: TouchEvent) => {\n        let touch = [...e.changedTouches].findIndex(\n          ({identifier}) => identifier === state.current.id\n        );\n        if (touch >= 0) {\n          let {pageX, pageY} = e.changedTouches[touch];\n          // eslint-disable-next-line react-hooks/rules-of-hooks\n          moveEvent(\n            e,\n            'touch',\n            pageX - (state.current.lastPosition?.pageX ?? 0),\n            pageY - (state.current.lastPosition?.pageY ?? 0)\n          );\n          state.current.lastPosition = {pageX, pageY};\n        }\n      };\n      let onTouchEnd = (e: TouchEvent) => {\n        let touch = [...e.changedTouches].findIndex(\n          ({identifier}) => identifier === state.current.id\n        );\n        if (touch >= 0) {\n          // eslint-disable-next-line react-hooks/rules-of-hooks\n          endEvent(e, 'touch');\n          state.current.id = null;\n          let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n          removeGlobalListener(ownerWindow, 'touchmove', onTouchMove);\n          removeGlobalListener(ownerWindow, 'touchend', onTouchEnd);\n          removeGlobalListener(ownerWindow, 'touchcancel', onTouchEnd);\n        }\n      };\n      moveProps.onTouchStart = (e: React.TouchEvent) => {\n        if (e.changedTouches.length === 0 || state.current.id != null) {\n          return;\n        }\n\n        let {pageX, pageY, identifier} = e.changedTouches[0];\n        start();\n        e.stopPropagation();\n        e.preventDefault();\n        state.current.lastPosition = {pageX, pageY};\n        state.current.id = identifier;\n        let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n        addGlobalListener(ownerWindow, 'touchmove', onTouchMove, false);\n        addGlobalListener(ownerWindow, 'touchend', onTouchEnd, false);\n        addGlobalListener(ownerWindow, 'touchcancel', onTouchEnd, false);\n      };\n    } else {\n      let onPointerMove = (e: PointerEvent) => {\n        if (e.pointerId === state.current.id) {\n          let pointerType = (e.pointerType || 'mouse') as PointerType;\n\n          // Problems with PointerEvent#movementX/movementY:\n          // 1. it is always 0 on macOS Safari.\n          // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS\n          // eslint-disable-next-line react-hooks/rules-of-hooks\n          moveEvent(\n            e,\n            pointerType,\n            e.pageX - (state.current.lastPosition?.pageX ?? 0),\n            e.pageY - (state.current.lastPosition?.pageY ?? 0)\n          );\n          state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n        }\n      };\n\n      let onPointerUp = (e: PointerEvent) => {\n        if (e.pointerId === state.current.id) {\n          let pointerType = (e.pointerType || 'mouse') as PointerType;\n          // eslint-disable-next-line react-hooks/rules-of-hooks\n          endEvent(e, pointerType);\n          state.current.id = null;\n          let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n          removeGlobalListener(ownerWindow, 'pointermove', onPointerMove, false);\n          removeGlobalListener(ownerWindow, 'pointerup', onPointerUp, false);\n          removeGlobalListener(ownerWindow, 'pointercancel', onPointerUp, false);\n        }\n      };\n\n      moveProps.onPointerDown = (e: React.PointerEvent) => {\n        if (e.button === 0 && state.current.id == null) {\n          start();\n          e.stopPropagation();\n          e.preventDefault();\n          state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};\n          state.current.id = e.pointerId;\n          let ownerWindow = getOwnerWindow(getEventTarget(e) as Element);\n          addGlobalListener(ownerWindow, 'pointermove', onPointerMove, false);\n          addGlobalListener(ownerWindow, 'pointerup', onPointerUp, false);\n          addGlobalListener(ownerWindow, 'pointercancel', onPointerUp, false);\n        }\n      };\n    }\n\n    let triggerKeyboardMove = (e: EventBase, deltaX: number, deltaY: number) => {\n      start();\n      // eslint-disable-next-line react-hooks/rules-of-hooks\n      moveEvent(e, 'keyboard', deltaX, deltaY);\n      // eslint-disable-next-line react-hooks/rules-of-hooks\n      endEvent(e, 'keyboard');\n    };\n\n    moveProps.onKeyDown = e => {\n      switch (e.key) {\n        case 'Left':\n        case 'ArrowLeft':\n          e.preventDefault();\n          e.stopPropagation();\n          triggerKeyboardMove(e, -1, 0);\n          break;\n        case 'Right':\n        case 'ArrowRight':\n          e.preventDefault();\n          e.stopPropagation();\n          triggerKeyboardMove(e, 1, 0);\n          break;\n        case 'Up':\n        case 'ArrowUp':\n          e.preventDefault();\n          e.stopPropagation();\n          triggerKeyboardMove(e, 0, -1);\n          break;\n        case 'Down':\n        case 'ArrowDown':\n          e.preventDefault();\n          e.stopPropagation();\n          triggerKeyboardMove(e, 0, 1);\n          break;\n      }\n    };\n\n    return moveProps;\n  }, [addGlobalListener, removeGlobalListener, state]);\n\n  return {moveProps};\n}\n"],"names":[],"version":3,"file":"useMove.cjs.map"}