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;YACrF,iDAAiD;YACjD,IAAI,CAAC,CAAA,GAAA,yCAAO,OAAO,CAAA,GAAA,yCAAI,OAAO,CAAC,cAAc,OAAO,EAClD;YAGF,IAAI,MAAM,cAAc,OAAO,CAAC,qBAAqB;YACrD,IAAI,OAAO;YACX,IAAI,MAAM;YACV,IAAI,SAAS,IAAI,MAAM,GAAG;YAC1B,IAAI,QAAQ,IAAI,KAAK,GAAG;YACxB,IAAI,IAAI,QAAQ,IAAI,SAAS,IAAI,OAAO,IAAI,QAAQ;gBAClD,IAAI,IAAI,MACN,MAAM,EAAE,GAAG,IAAI;qBACV,IAAI,IAAI,OACb,MAAM,EAAE,GAAG,IAAI;gBAEjB,IAAI,IAAI,KACN,MAAM,EAAE,GAAG,IAAI;qBACV,IAAI,IAAI,QACb,MAAM,EAAE,GAAG,IAAI;gBAGjB,IAAI,CAAC,MAAM,KAAK,EACd,MAAM,KAAK,GAAG,sBAAsB;YAExC,OACE,IAAI,CAAC,IAAI;QAEb;QACA;YACE,IAAI,MAAM,KAAK,EAAE;gBACf,qBAAqB,MAAM,KAAK;gBAChC,MAAM,KAAK,GAAG;YAChB;QACF;IACF;AACF","sources":["packages/react-aria/src/dnd/useAutoScroll.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 {getScrollParent} from '../utils/getScrollParent';\n\nimport {isIOS, isWebKit} from '../utils/platform';\nimport {isScrollable} from '../utils/isScrollable';\nimport {RefObject} from '@react-types/shared';\nimport {useCallback, useEffect, useRef} from 'react';\n\nconst AUTOSCROLL_AREA_SIZE = 20;\n\ninterface AutoScrollAria {\n    move(x: number, y: number): void,\n    stop(): void\n}\n\nexport function useAutoScroll(ref: RefObject<Element | null>): AutoScrollAria {\n  let scrollableRef = useRef<Element>(null);\n  let scrollableX = useRef(true);\n  let scrollableY = useRef(true);\n  useEffect(() => {\n    if (ref.current) {\n      scrollableRef.current = isScrollable(ref.current) ? ref.current : getScrollParent(ref.current);\n      let style = window.getComputedStyle(scrollableRef.current);\n      scrollableX.current = /(auto|scroll)/.test(style.overflowX);\n      scrollableY.current = /(auto|scroll)/.test(style.overflowY);\n    }\n  }, [ref]);\n\n  let state = useRef<{timer: ReturnType<typeof requestAnimationFrame> | undefined, dx: number, dy: number}>({\n    timer: undefined,\n    dx: 0,\n    dy: 0\n  }).current;\n\n  useEffect(() => {\n    return () => {\n      if (state.timer) {\n        cancelAnimationFrame(state.timer);\n        state.timer = undefined;\n      }\n    };\n  // state will become a new object, so it's ok to use in the dependency array for unmount\n  }, [state]);\n\n  let scroll = useCallback(() => {\n    if (scrollableX.current && scrollableRef.current) {\n      scrollableRef.current.scrollLeft += state.dx;\n    }\n    if (scrollableY.current && scrollableRef.current) {\n      scrollableRef.current.scrollTop += state.dy;\n    }\n\n    if (state.timer) {\n      state.timer = requestAnimationFrame(scroll);\n    }\n  }, [scrollableRef, state]);\n\n  return {\n    move(x, y) {\n      // Most browsers auto scroll natively, but WebKit on macOS does not (iOS does 🤷‍♂️).\n      // https://bugs.webkit.org/show_bug.cgi?id=222636\n      if (!isWebKit() || isIOS() || !scrollableRef.current) {\n        return;\n      }\n\n      let box = scrollableRef.current.getBoundingClientRect();\n      let left = AUTOSCROLL_AREA_SIZE;\n      let top = AUTOSCROLL_AREA_SIZE;\n      let bottom = box.height - AUTOSCROLL_AREA_SIZE;\n      let right = box.width - AUTOSCROLL_AREA_SIZE;\n      if (x < left || x > right || y < top || y > bottom) {\n        if (x < left) {\n          state.dx = x - left;\n        } else if (x > right) {\n          state.dx = x - right;\n        }\n        if (y < top) {\n          state.dy = y - top;\n        } else if (y > bottom) {\n          state.dy = y - bottom;\n        }\n\n        if (!state.timer) {\n          state.timer = requestAnimationFrame(scroll);\n        }\n      } else {\n        this.stop();\n      }\n    },\n    stop() {\n      if (state.timer) {\n        cancelAnimationFrame(state.timer);\n        state.timer = undefined;\n      }\n    }\n  };\n}\n"],"names":[],"version":3,"file":"useAutoScroll.mjs.map"}