PromoCursed/node_modules/.cache/babel-loader/7bbd5d11e46733683982d893b73da4c9968db0fc1a7ea9c1f8466131d7a92136.json

1 line
7.6 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import { useEvent } from 'rc-util';\nimport raf from \"rc-util/es/raf\";\nimport isVisible from \"rc-util/es/Dom/isVisible\";\nimport * as React from 'react';\nvar SPEED_PTG = 1 / 3;\nexport default function useScrollTo(ulRef, value) {\n // ========================= Scroll =========================\n var scrollingRef = React.useRef(false);\n var scrollRafRef = React.useRef(null);\n var scrollDistRef = React.useRef(null);\n var isScrolling = function isScrolling() {\n return scrollingRef.current;\n };\n var stopScroll = function stopScroll() {\n raf.cancel(scrollRafRef.current);\n scrollingRef.current = false;\n };\n var scrollRafTimesRef = React.useRef();\n var startScroll = function startScroll() {\n var ul = ulRef.current;\n scrollDistRef.current = null;\n scrollRafTimesRef.current = 0;\n if (ul) {\n var targetLi = ul.querySelector(\"[data-value=\\\"\".concat(value, \"\\\"]\"));\n var firstLi = ul.querySelector(\"li\");\n var doScroll = function doScroll() {\n stopScroll();\n scrollingRef.current = true;\n scrollRafTimesRef.current += 1;\n var currentTop = ul.scrollTop;\n var firstLiTop = firstLi.offsetTop;\n var targetLiTop = targetLi.offsetTop;\n var targetTop = targetLiTop - firstLiTop;\n\n // Wait for element exist. 5 frames is enough\n if (targetLiTop === 0 && targetLi !== firstLi || !isVisible(ul)) {\n if (scrollRafTimesRef.current <= 5) {\n scrollRafRef.current = raf(doScroll);\n }\n return;\n }\n var nextTop = currentTop + (targetTop - currentTop) * SPEED_PTG;\n var dist = Math.abs(targetTop - nextTop);\n\n // Break if dist get larger, which means user is scrolling\n if (scrollDistRef.current !== null && scrollDistRef.current < dist) {\n stopScroll();\n return;\n }\n scrollDistRef.current = dist;\n\n // Stop when dist is less than 1\n if (dist <= 1) {\n ul.scrollTop = targetTop;\n stopScroll();\n return;\n }\n\n // IE not support `scrollTo`\n ul.scrollTop = nextTop;\n scrollRafRef.current = raf(doScroll);\n };\n if (targetLi && firstLi) {\n doScroll();\n }\n }\n };\n\n // ======================== Trigger =========================\n var syncScroll = useEvent(startScroll);\n return [syncScroll, stopScroll, isScrolling];\n}","map":{"version":3,"names":["useEvent","raf","isVisible","React","SPEED_PTG","useScrollTo","ulRef","value","scrollingRef","useRef","scrollRafRef","scrollDistRef","isScrolling","current","stopScroll","cancel","scrollRafTimesRef","startScroll","ul","targetLi","querySelector","concat","firstLi","doScroll","currentTop","scrollTop","firstLiTop","offsetTop","targetLiTop","targetTop","nextTop","dist","Math","abs","syncScroll"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-picker/es/PickerPanel/TimePanel/TimePanelBody/useScrollTo.js"],"sourcesContent":["import { useEvent } from 'rc-util';\nimport raf from \"rc-util/es/raf\";\nimport isVisible from \"rc-util/es/Dom/isVisible\";\nimport * as React from 'react';\nvar SPEED_PTG = 1 / 3;\nexport default function useScrollTo(ulRef, value) {\n // ========================= Scroll =========================\n var scrollingRef = React.useRef(false);\n var scrollRafRef = React.useRef(null);\n var scrollDistRef = React.useRef(null);\n var isScrolling = function isScrolling() {\n return scrollingRef.current;\n };\n var stopScroll = function stopScroll() {\n raf.cancel(scrollRafRef.current);\n scrollingRef.current = false;\n };\n var scrollRafTimesRef = React.useRef();\n var startScroll = function startScroll() {\n var ul = ulRef.current;\n scrollDistRef.current = null;\n scrollRafTimesRef.current = 0;\n if (ul) {\n var targetLi = ul.querySelector(\"[data-value=\\\"\".concat(value, \"\\\"]\"));\n var firstLi = ul.querySelector(\"li\");\n var doScroll = function d