1 line
9.2 KiB
JSON
1 line
9.2 KiB
JSON
{"ast":null,"code":"import useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport { useRef } from 'react';\nvar SMOOTH_PTG = 14 / 15;\nexport default function useMobileTouchMove(inVirtual, listRef, callback) {\n var touchedRef = useRef(false);\n var touchXRef = useRef(0);\n var touchYRef = useRef(0);\n var elementRef = useRef(null);\n\n // Smooth scroll\n var intervalRef = useRef(null);\n\n /* eslint-disable prefer-const */\n var cleanUpEvents;\n var onTouchMove = function onTouchMove(e) {\n if (touchedRef.current) {\n var currentX = Math.ceil(e.touches[0].pageX);\n var currentY = Math.ceil(e.touches[0].pageY);\n var offsetX = touchXRef.current - currentX;\n var offsetY = touchYRef.current - currentY;\n var _isHorizontal = Math.abs(offsetX) > Math.abs(offsetY);\n if (_isHorizontal) {\n touchXRef.current = currentX;\n } else {\n touchYRef.current = currentY;\n }\n if (callback(_isHorizontal, _isHorizontal ? offsetX : offsetY)) {\n e.preventDefault();\n }\n // Smooth interval\n clearInterval(intervalRef.current);\n intervalRef.current = setInterval(function () {\n if (_isHorizontal) {\n offsetX *= SMOOTH_PTG;\n } else {\n offsetY *= SMOOTH_PTG;\n }\n var offset = Math.floor(_isHorizontal ? offsetX : offsetY);\n if (!callback(_isHorizontal, offset, true) || Math.abs(offset) <= 0.1) {\n clearInterval(intervalRef.current);\n }\n }, 16);\n }\n };\n var onTouchEnd = function onTouchEnd() {\n touchedRef.current = false;\n cleanUpEvents();\n };\n var onTouchStart = function onTouchStart(e) {\n cleanUpEvents();\n if (e.touches.length === 1 && !touchedRef.current) {\n touchedRef.current = true;\n touchXRef.current = Math.ceil(e.touches[0].pageX);\n touchYRef.current = Math.ceil(e.touches[0].pageY);\n elementRef.current = e.target;\n elementRef.current.addEventListener('touchmove', onTouchMove, {\n passive: false\n });\n elementRef.current.addEventListener('touchend', onTouchEnd, {\n passive: true\n });\n }\n };\n cleanUpEvents = function cleanUpEvents() {\n if (elementRef.current) {\n elementRef.current.removeEventListener('touchmove', onTouchMove);\n elementRef.current.removeEventListener('touchend', onTouchEnd);\n }\n };\n useLayoutEffect(function () {\n if (inVirtual) {\n listRef.current.addEventListener('touchstart', onTouchStart, {\n passive: true\n });\n }\n return function () {\n var _listRef$current;\n (_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.removeEventListener('touchstart', onTouchStart);\n cleanUpEvents();\n clearInterval(intervalRef.current);\n };\n }, [inVirtual]);\n}","map":{"version":3,"names":["useLayoutEffect","useRef","SMOOTH_PTG","useMobileTouchMove","inVirtual","listRef","callback","touchedRef","touchXRef","touchYRef","elementRef","intervalRef","cleanUpEvents","onTouchMove","e","current","currentX","Math","ceil","touches","pageX","currentY","pageY","offsetX","offsetY","_isHorizontal","abs","preventDefault","clearInterval","setInterval","offset","floor","onTouchEnd","onTouchStart","length","target","addEventListener","passive","removeEventListener","_listRef$current"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js"],"sourcesContent":["import useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport { useRef } from 'react';\nvar SMOOTH_PTG = 14 / 15;\nexport default function useMobileTouchMove(inVirtual, listRef, callback) {\n var touchedRef = useRef(false);\n var touchXRef = useRef(0);\n var touchYRef = useRef(0);\n var elementRef = useRef(null);\n\n // Smooth scroll\n var intervalRef = useRef(null);\n\n /* eslint-disable prefer-const */\n var cleanUpEvents;\n var onTouchMove = function onTouchMove(e) {\n if (touchedRef.current) {\n var currentX = Math.ceil(e.touches[0].pageX);\n var currentY = Math.ceil(e.touches[0].pageY);\n var offsetX = touchXRef.current - currentX;\n var offsetY = touchYRef.current - currentY;\n var _isHorizontal = Math.abs(offsetX) > Math.abs(offsetY);\n if (_isHorizontal) {\n touchXRef.current = currentX;\n } else {\n touchYRef.current = currentY;\n }\n if (callback(_isHorizontal, _isHorizontal ? offsetX : offsetY)) {\n e.preventDefault();\n }\n // Smooth interval\n clearInterval(intervalRef.current);\n intervalRef.current = setInterval(function () {\n if (_isHorizontal) {\n offsetX *= SMOOTH_PTG;\n } else {\n offsetY *= SMOOTH_PTG;\n }\n var offset = Math.floor(_isHorizontal ? offsetX : offsetY);\n if (!callback(_isHorizontal, offset, true) || Math.abs(offset) <= 0.1) {\n clearInterval(intervalRef.current);\n }\n }, 16);\n }\n };\n var onTouchEnd = function onTouchEnd() {\n touchedRef.current = false;\n cleanUpEvents();\n };\n var onTouchStart = function onTouchStart(e) {\n cleanUpEvents();\n if (e.touches.length === 1 && !touchedRef.current) {\n touchedRef.current = true;\n touchXRef.current = Math.ceil(e.touches[0].pageX);\n touchYRef.current = Math.ceil(e.touches[0].pageY);\n elementRef.current = e.target;\n elementRef.current.addEventListener('touchmove', onTouchMove, {\n passive: false\n });\n elementRef.current.addEventListener('touchend', onTouchEnd, {\n passive: true\n });\n }\n };\n cleanUpEvents = function cleanUpEvents() {\n if (elementRef.current) {\n elementRef.current.removeEventListener('touchmove', onTouchMove);\n elementRef.current.removeEventListener('touchend', onTouchEnd);\n }\n };\n useLayoutEffect(function () {\n if (inVirtual) {\n listRef.current.addEventListener('touchstart', onTouchStart, {\n passive: true\n });\n }\n return function () {\n var _listRef$current;\n (_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.removeEventListener('touchstart', onTouchStart);\n cleanUpEvents();\n clearInterval(intervalRef.current);\n };\n }, [inVirtual]);\n}"],"mappings":"AAAA,OAAOA,eAAe,MAAM,kCAAkC;AAC9D,SAASC,MAAM,QAAQ,OAAO;AAC9B,IAAIC,UAAU,GAAG,EAAE,GAAG,EAAE;AACxB,eAAe,SAASC,kBAAkBA,CAACC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,EAAE;EACvE,IAAIC,UAAU,GAAGN,MAAM,CAAC,KAAK,CAAC;EAC9B,IAAIO,SAAS,GAAGP,MAAM,CAAC,CAAC,CAAC;EACzB,IAAIQ,SAAS,GAAGR,MAAM,CAAC,CAAC,CAAC;EACzB,IAAIS,UAAU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