a97b7a292992c5c860b487363151e280.json
15.5 KB
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useState, useRef } 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); // ================================= Hook =================================\n\nexport default function useTouchMove(ref, onOffset) {\n var _useState = useState(),\n _useState2 = _slicedToArray(_useState, 2),\n touchPosition = _useState2[0],\n setTouchPosition = _useState2[1];\n\n var _useState3 = useState(0),\n _useState4 = _slicedToArray(_useState3, 2),\n lastTimestamp = _useState4[0],\n setLastTimestamp = _useState4[1];\n\n var _useState5 = useState(0),\n _useState6 = _slicedToArray(_useState5, 2),\n lastTimeDiff = _useState6[0],\n setLastTimeDiff = _useState6[1];\n\n var _useState7 = useState(),\n _useState8 = _slicedToArray(_useState7, 2),\n lastOffset = _useState8[0],\n setLastOffset = _useState8[1];\n\n var motionRef = useRef(); // ========================= Events =========================\n // >>> Touch events\n\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\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\n function onTouchEnd() {\n if (!touchPosition) return;\n setTouchPosition(null);\n setLastOffset(null); // Swipe if needed\n\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); // Skip swipe if low distance\n\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\n currentX *= SPEED_OFF_MULTIPLE;\n currentY *= SPEED_OFF_MULTIPLE;\n onOffset(currentX * REFRESH_INTERVAL, currentY * REFRESH_INTERVAL);\n }, REFRESH_INTERVAL);\n }\n } // >>> Wheel event\n\n\n var lastWheelDirectionRef = useRef();\n\n function onWheel(e) {\n var deltaX = e.deltaX,\n deltaY = e.deltaY; // Convert both to x & y since wheel only happened on PC\n\n var mixed = 0;\n var absX = Math.abs(deltaX);\n var absY = Math.abs(deltaY);\n\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\n if (onOffset(-mixed, -mixed)) {\n e.preventDefault();\n }\n } // ========================= Effect =========================\n\n\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\n function onProxyTouchMove(e) {\n touchEventsRef.current.onTouchMove(e);\n }\n\n function onProxyTouchEnd(e) {\n touchEventsRef.current.onTouchEnd(e);\n }\n\n function onProxyWheel(e) {\n touchEventsRef.current.onWheel(e);\n }\n\n document.addEventListener('touchmove', onProxyTouchMove, {\n passive: false\n });\n document.addEventListener('touchend', onProxyTouchEnd, {\n passive: false\n }); // No need to clean up since element removed\n\n ref.current.addEventListener('touchstart', onProxyTouchStart, {\n passive: false\n });\n ref.current.addEventListener('wheel', onProxyWheel);\n return function () {\n document.removeEventListener('touchmove', onProxyTouchMove);\n document.removeEventListener('touchend', onProxyTouchEnd);\n };\n }, []);\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-tabs/es/hooks/useTouchMove.js"],"names":["_slicedToArray","React","useState","useRef","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"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,EAAmBC,MAAnB,QAAiC,OAAjC;AACA,IAAIC,kBAAkB,GAAG,GAAzB;AACA,IAAIC,mBAAmB,GAAG,IAA1B;AACA,IAAIC,gBAAgB,GAAG,EAAvB;AACA,IAAIC,kBAAkB,GAAGC,IAAI,CAACC,GAAL,CAAS,KAAT,EAAgBH,gBAAhB,CAAzB,C,CAA4D;;AAE5D,eAAe,SAASI,YAAT,CAAsBC,GAAtB,EAA2BC,QAA3B,EAAqC;AAClD,MAAIC,SAAS,GAAGX,QAAQ,EAAxB;AAAA,MACI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AAAA,QAAQ,CAACC,gBAAT,CAA0B,UAA1B,EAAsCH,eAAtC,EAAuD;AACrDI,MAAAA,OAAO,EAAE;AAD4C,KAAvD,EApB0B,CAsBtB;;AAEJ5D,IAAAA,GAAG,CAAC6B,OAAJ,CAAY8B,gBAAZ,CAA6B,YAA7B,EAA2CL,iBAA3C,EAA8D;AAC5DM,MAAAA,OAAO,EAAE;AADmD,KAA9D;AAGA5D,IAAAA,GAAG,CAAC6B,OAAJ,CAAY8B,gBAAZ,CAA6B,OAA7B,EAAsCF,YAAtC;AACA,WAAO,YAAY;AACjBC,MAAAA,QAAQ,CAACG,mBAAT,CAA6B,WAA7B,EAA0CN,gBAA1C;AACAG,MAAAA,QAAQ,CAACG,mBAAT,CAA6B,UAA7B,EAAyCL,eAAzC;AACD,KAHD;AAID,GAhCD,EAgCG,EAhCH;AAiCD","sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { useState, useRef } 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); // ================================= Hook =================================\n\nexport default function useTouchMove(ref, onOffset) {\n var _useState = useState(),\n _useState2 = _slicedToArray(_useState, 2),\n touchPosition = _useState2[0],\n setTouchPosition = _useState2[1];\n\n var _useState3 = useState(0),\n _useState4 = _slicedToArray(_useState3, 2),\n lastTimestamp = _useState4[0],\n setLastTimestamp = _useState4[1];\n\n var _useState5 = useState(0),\n _useState6 = _slicedToArray(_useState5, 2),\n lastTimeDiff = _useState6[0],\n setLastTimeDiff = _useState6[1];\n\n var _useState7 = useState(),\n _useState8 = _slicedToArray(_useState7, 2),\n lastOffset = _useState8[0],\n setLastOffset = _useState8[1];\n\n var motionRef = useRef(); // ========================= Events =========================\n // >>> Touch events\n\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\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\n function onTouchEnd() {\n if (!touchPosition) return;\n setTouchPosition(null);\n setLastOffset(null); // Swipe if needed\n\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); // Skip swipe if low distance\n\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\n currentX *= SPEED_OFF_MULTIPLE;\n currentY *= SPEED_OFF_MULTIPLE;\n onOffset(currentX * REFRESH_INTERVAL, currentY * REFRESH_INTERVAL);\n }, REFRESH_INTERVAL);\n }\n } // >>> Wheel event\n\n\n var lastWheelDirectionRef = useRef();\n\n function onWheel(e) {\n var deltaX = e.deltaX,\n deltaY = e.deltaY; // Convert both to x & y since wheel only happened on PC\n\n var mixed = 0;\n var absX = Math.abs(deltaX);\n var absY = Math.abs(deltaY);\n\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\n if (onOffset(-mixed, -mixed)) {\n e.preventDefault();\n }\n } // ========================= Effect =========================\n\n\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\n function onProxyTouchMove(e) {\n touchEventsRef.current.onTouchMove(e);\n }\n\n function onProxyTouchEnd(e) {\n touchEventsRef.current.onTouchEnd(e);\n }\n\n function onProxyWheel(e) {\n touchEventsRef.current.onWheel(e);\n }\n\n document.addEventListener('touchmove', onProxyTouchMove, {\n passive: false\n });\n document.addEventListener('touchend', onProxyTouchEnd, {\n passive: false\n }); // No need to clean up since element removed\n\n ref.current.addEventListener('touchstart', onProxyTouchStart, {\n passive: false\n });\n ref.current.addEventListener('wheel', onProxyWheel);\n return function () {\n document.removeEventListener('touchmove', onProxyTouchMove);\n document.removeEventListener('touchend', onProxyTouchEnd);\n };\n }, []);\n}"]},"metadata":{},"sourceType":"module"}