{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useState } from 'react';\nvar MIN_SWIPE_DISTANCE = 0.1;\nvar STOP_SWIPE_DISTANCE = 0.01;\nvar REFRESH_INTERVAL = 20;\nvar SPEED_OFF_MULTIPLE = Math.pow(0.995, REFRESH_INTERVAL);\n\n// ================================= Hook =================================\nexport default function useTouchMove(ref, onOffset) {\n var _useState = useState(),\n _useState2 = _slicedToArray(_useState, 2),\n touchPosition = _useState2[0],\n setTouchPosition = _useState2[1];\n var _useState3 = useState(0),\n _useState4 = _slicedToArray(_useState3, 2),\n lastTimestamp = _useState4[0],\n setLastTimestamp = _useState4[1];\n var _useState5 = useState(0),\n _useState6 = _slicedToArray(_useState5, 2),\n lastTimeDiff = _useState6[0],\n setLastTimeDiff = _useState6[1];\n var _useState7 = useState(),\n _useState8 = _slicedToArray(_useState7, 2),\n lastOffset = _useState8[0],\n setLastOffset = _useState8[1];\n var motionRef = useRef();\n\n // ========================= Events =========================\n // >>> Touch events\n function onTouchStart(e) {\n var _e$touches$ = e.touches[0],\n screenX = _e$touches$.screenX,\n screenY = _e$touches$.screenY;\n setTouchPosition({\n x: screenX,\n y: screenY\n });\n window.clearInterval(motionRef.current);\n }\n function onTouchMove(e) {\n if (!touchPosition) return;\n e.preventDefault();\n var _e$touches$2 = e.touches[0],\n screenX = _e$touches$2.screenX,\n screenY = _e$touches$2.screenY;\n setTouchPosition({\n x: screenX,\n y: screenY\n });\n var offsetX = screenX - touchPosition.x;\n var offsetY = screenY - touchPosition.y;\n onOffset(offsetX, offsetY);\n var now = Date.now();\n setLastTimestamp(now);\n setLastTimeDiff(now - lastTimestamp);\n setLastOffset({\n x: offsetX,\n y: offsetY\n });\n }\n function onTouchEnd() {\n if (!touchPosition) return;\n setTouchPosition(null);\n setLastOffset(null);\n\n // Swipe if needed\n if (lastOffset) {\n var distanceX = lastOffset.x / lastTimeDiff;\n var distanceY = lastOffset.y / lastTimeDiff;\n var absX = Math.abs(distanceX);\n var absY = Math.abs(distanceY);\n\n // Skip swipe if low distance\n if (Math.max(absX, absY) < MIN_SWIPE_DISTANCE) return;\n var currentX = distanceX;\n var currentY = distanceY;\n motionRef.current = window.setInterval(function () {\n if (Math.abs(currentX) < STOP_SWIPE_DISTANCE && Math.abs(currentY) < STOP_SWIPE_DISTANCE) {\n window.clearInterval(motionRef.current);\n return;\n }\n currentX *= SPEED_OFF_MULTIPLE;\n currentY *= SPEED_OFF_MULTIPLE;\n onOffset(currentX * REFRESH_INTERVAL, currentY * REFRESH_INTERVAL);\n }, REFRESH_INTERVAL);\n }\n }\n\n // >>> Wheel event\n var lastWheelDirectionRef = useRef();\n function onWheel(e) {\n var deltaX = e.deltaX,\n deltaY = e.deltaY;\n\n // Convert both to x & y since wheel only happened on PC\n var mixed = 0;\n var absX = Math.abs(deltaX);\n var absY = Math.abs(deltaY);\n if (absX === absY) {\n mixed = lastWheelDirectionRef.current === 'x' ? deltaX : deltaY;\n } else if (absX > absY) {\n mixed = deltaX;\n lastWheelDirectionRef.current = 'x';\n } else {\n mixed = deltaY;\n lastWheelDirectionRef.current = 'y';\n }\n if (onOffset(-mixed, -mixed)) {\n e.preventDefault();\n }\n }\n\n // ========================= Effect =========================\n var touchEventsRef = useRef(null);\n touchEventsRef.current = {\n onTouchStart: onTouchStart,\n onTouchMove: onTouchMove,\n onTouchEnd: onTouchEnd,\n onWheel: onWheel\n };\n React.useEffect(function () {\n function onProxyTouchStart(e) {\n touchEventsRef.current.onTouchStart(e);\n }\n function onProxyTouchMove(e) {\n touchEventsRef.current.onTouchMove(e);\n }\n function onProxyTouchEnd(e) {\n touchEventsRef.current.onTouchEnd(e);\n }\n function onProxyWheel(e) {\n touchEventsRef.current.onWheel(e);\n }\n document.addEventListener('touchmove', onProxyTouchMove, {\n passive: false\n });\n document.addEventListener('touchend', onProxyTouchEnd, {\n passive: true\n });\n\n // No need to clean up since element removed\n ref.current.addEventListener('touchstart', onProxyTouchStart, {\n passive: true\n });\n ref.current.addEventListener('wheel', onProxyWheel, {\n passive: false\n });\n return function () {\n document.removeEventListener('touchmove', onProxyTouchMove);\n document.removeEventListener('touchend', onProxyTouchEnd);\n };\n }, []);\n}","map":{"version":3,"names":["_slicedToArray","React","useRef","useState","MIN_SWIPE_DISTANCE","STOP_SWIPE_DISTANCE","REFRESH_INTERVAL","SPEED_OFF_MULTIPLE","Math","pow","useTouchMove","ref","onOffset","_useState","_useState2","touchPosition","setTouchPosition","_useState3","_useState4","lastTimestamp","setLastTimestamp","_useState5","_useState6","lastTimeDiff","setLastTimeDiff","_useState7","_useState8","lastOffset","setLastOffset","motionRef","onTouchStart","e","_e$touches$","touches","screenX","screenY","x","y","window","clearInterval","current","onTouchMove","preventDefault","_e$touches$2","offsetX","offsetY","now","Date","onTouchEnd","distanceX","distanceY","absX","abs","absY","max","currentX","currentY","setInterval","lastWheelDirectionRef","onWheel","deltaX","deltaY","mixed","touchEventsRef","useEffect","onProxyTouchStart","onProxyTouchMove","onProxyTouchEnd","onProxyWheel","document","addEventListener","passive","removeEventListener"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-tabs/es/hooks/useTouchMove.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useRef, useState } from 'react';\nvar MIN_SWIPE_DISTANCE = 0.1;\nvar STOP_SWIPE_DISTANCE = 0.01;\nvar REFRESH_INTERVAL = 20;\nvar SPEED_OFF_MULTIPLE = Math.pow(0.995, REFRESH_INTERVAL);\n\n// ================================= Hook =================================\nexport default function useTouchMove(ref, onOffset) {\n var _useState = useState(),\n _useState2 = _slicedToArray(_useState, 2),\n touchPosition = _useState2[0],\n setTouchPosition = _useState2[1];\n var _useState3 = useState(0),\n _useState4 = _slicedToArray(_useState3, 2),\n lastTimestamp = _useState4[0],\n setLastTimestamp = _useState4[1];\n var _useState5 = useState(0),\n _useState6 = _slicedToArray(_useState5, 2),\n lastTimeDiff = _useState6[0],\n setLastTimeDiff = _useState6[1];\n var _useState7 = useState(),\n _useState8 = _slicedToArray(_useState7, 2),\n lastOffset = _useState8[0],\n setLastOffset = _useState8[1];\n var motionRef = useRef();\n\n // ========================= Events =========================\n // >>> Touch events\n function onTouchStart(e) {\n var _e$touches$ = e.touches[0],\n screenX = _e$touches$.screenX,\n screenY = _e$touches$.screenY;\n setTouchPosition({\n x: screenX,\n y: screenY\n });\n window.clearInterval(motionRef.current);\n }\n function onTouchMove(e) {\n if (!touchPosition) return;\n e.preventDefault();\n var _e$touches$2 = e.touches[0],\n screenX = _e$touches$2.screenX,\n screenY = _e$touches$2.screenY;\n setTouchPosition({\n x: screenX,\n y: screenY\n });\n var offsetX = screenX - touchPosition.x;\n var offsetY = screenY - touchPosition.y;\n onOffset(offsetX, offsetY);\n var now = Date.now();\n setLastTimestamp(now);\n setLastTimeDiff(now - lastTimestamp);\n setLastOffset({\n x: offsetX,\n y: offsetY\n });\n }\n function onTouchEnd() {\n if (!touchPosition) return;\n setTouchPosition(null);\n setLastOffset(null);\n\n // Swipe if needed\n if (lastOffset) {\n var distanceX = lastOffset.x / lastTimeDiff;\n var distanceY = lastOffset.y / lastTimeDiff;\n var absX = Math.abs(distanceX);\n var absY = Math.abs(distanceY);\n\n // Skip swipe if low distance\n if (Math.max(absX, absY) < MIN_SWIPE_DISTANCE) return;\n var currentX = distanceX;\n var currentY = distanceY;\n motionRef.current = window.setInterval(function () {\n if (Math.abs(currentX) < STOP_SWIPE_DISTANCE && Math.abs(currentY) < STOP_SWIPE_DISTANCE) {\n window.clearInterval(motionRef.current);\n return;\n }\n currentX *= SPEED_OFF_MULTIPLE;\n currentY *= SPEED_OFF_MULTIPLE;\n onOffset(currentX * REFRESH_INTERVAL, currentY * REFRESH_INTERVAL);\n }, REFRESH_INTERVAL);\n }\n }\n\n // >>> Wheel event\n var lastWheelDirectionRef = useRef();\n function onWheel(e) {\n var deltaX = e.deltaX,\n deltaY = e.deltaY;\n\n // Convert both to x & y since wheel only happened on PC\n var mixed = 0;\n var absX = Math.abs(deltaX);\n var absY = Math.abs(deltaY);\n if (absX === absY) {\n mixed = lastWheelDirectionRef.current === 'x' ? deltaX : deltaY;\n } else if (absX > absY) {\n mixed = deltaX;\n lastWheelDirectionRef.current = 'x';\n } else {\n mixed = deltaY;\n lastWheelDirectionRef.current = 'y';\n }\n if (onOffset(-mixed, -mixed)) {\n e.preventDefault();\n }\n }\n\n // ========================= Effect =========================\n var touchEventsRef = useRef(null);\n touchEventsRef.current = {\n onTouchStart: onTouchStart,\n onTouchMove: onTouchMove,\n onTouchEnd: onTouchEnd,\n onWheel: onWheel\n };\n React.useEffect(function () {\n function onProxyTouchStart(e) {\n touchEventsRef.current.onTouchStart(e);\n }\n function onProxyTouchMove(e) {\n touchEventsRef.current.onTouchMove(e);\n }\n function onProxyTouchEnd(e) {\n touchEventsRef.current.onTouchEnd(e);\n }\n function onProxyWheel(e) {\n touchEventsRef.current.onWheel(e);\n }\n document.addEventListener('touchmove', onProxyTouchMove, {\n passive: false\n });\n document.addEventListener('touchend', onProxyTouchEnd, {\n passive: true\n });\n\n // No need to clean up since element removed\n ref.current.addEventListener('touchstart', onProxyTouchStart, {\n passive: true\n });\n ref.current.addEventListener('wheel', onProxyWheel, {\n passive: false\n });\n return function () {\n document.removeEventListener('touchmove', onProxyTouchMove);\n document.removeEventListener('touchend', onProxyTouchEnd);\n };\n }, []);\n}"],"mappings":"AAAA,OAAOA,cAAc,MAAM,0CAA0C;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACxC,IAAIC,kBAAkB,GAAG,GAAG;AAC5B,IAAIC,mBAAmB,GAAG,IAAI;AAC9B,IAAIC,gBAAgB,GAAG,EAAE;AACzB,IAAIC,kBAAkB,GAAGC,IAAI,CAACC,GAAG,CAAC,KAAK,EAAEH,gBAAgB,CAAC;;AAE1D;AACA,eAAe,SAASI,YAAYA,CA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