PromoCursed/node_modules/.cache/babel-loader/3ec9c75457a40e20e059892154d9c659466515bfec56a00cb74dad3e4ac010f0.json
2024-08-20 23:25:37 +04:00

1 line
9.9 KiB
JSON

{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport useEvent from \"rc-util/es/hooks/useEvent\";\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport { useMemo, useState } from 'react';\nimport { isInViewPort } from \"../util\";\nexport default function useTarget(target, open, gap, scrollIntoViewOptions) {\n // ========================= Target =========================\n // We trade `undefined` as not get target by function yet.\n // `null` as empty target.\n var _useState = useState(undefined),\n _useState2 = _slicedToArray(_useState, 2),\n targetElement = _useState2[0],\n setTargetElement = _useState2[1];\n useLayoutEffect(function () {\n var nextElement = typeof target === 'function' ? target() : target;\n setTargetElement(nextElement || null);\n });\n\n // ========================= Align ==========================\n var _useState3 = useState(null),\n _useState4 = _slicedToArray(_useState3, 2),\n posInfo = _useState4[0],\n setPosInfo = _useState4[1];\n var updatePos = useEvent(function () {\n if (targetElement) {\n // Exist target element. We should scroll and get target position\n if (!isInViewPort(targetElement) && open) {\n targetElement.scrollIntoView(scrollIntoViewOptions);\n }\n var _targetElement$getBou = targetElement.getBoundingClientRect(),\n left = _targetElement$getBou.left,\n top = _targetElement$getBou.top,\n width = _targetElement$getBou.width,\n height = _targetElement$getBou.height;\n var nextPosInfo = {\n left: left,\n top: top,\n width: width,\n height: height,\n radius: 0\n };\n setPosInfo(function (origin) {\n if (JSON.stringify(origin) !== JSON.stringify(nextPosInfo)) {\n return nextPosInfo;\n }\n return origin;\n });\n } else {\n // Not exist target which means we just show in center\n setPosInfo(null);\n }\n });\n var getGapOffset = function getGapOffset(index) {\n var _ref;\n return (_ref = Array.isArray(gap === null || gap === void 0 ? void 0 : gap.offset) ? gap === null || gap === void 0 ? void 0 : gap.offset[index] : gap === null || gap === void 0 ? void 0 : gap.offset) !== null && _ref !== void 0 ? _ref : 6;\n };\n useLayoutEffect(function () {\n updatePos();\n // update when window resize\n window.addEventListener('resize', updatePos);\n return function () {\n window.removeEventListener('resize', updatePos);\n };\n }, [targetElement, open, updatePos]);\n\n // ======================== PosInfo =========================\n var mergedPosInfo = useMemo(function () {\n if (!posInfo) {\n return posInfo;\n }\n var gapOffsetX = getGapOffset(0);\n var gapOffsetY = getGapOffset(1);\n var gapRadius = (gap === null || gap === void 0 ? void 0 : gap.radius) || 2;\n return {\n left: posInfo.left - gapOffsetX,\n top: posInfo.top - gapOffsetY,\n width: posInfo.width + gapOffsetX * 2,\n height: posInfo.height + gapOffsetY * 2,\n radius: gapRadius\n };\n }, [posInfo, gap]);\n return [mergedPosInfo, targetElement];\n}","map":{"version":3,"names":["_slicedToArray","useEvent","useLayoutEffect","useMemo","useState","isInViewPort","useTarget","target","open","gap","scrollIntoViewOptions","_useState","undefined","_useState2","targetElement","setTargetElement","nextElement","_useState3","_useState4","posInfo","setPosInfo","updatePos","scrollIntoView","_targetElement$getBou","getBoundingClientRect","left","top","width","height","nextPosInfo","radius","origin","JSON","stringify","getGapOffset","index","_ref","Array","isArray","offset","window","addEventListener","removeEventListener","mergedPosInfo","gapOffsetX","gapOffsetY","gapRadius"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/@rc-component/tour/es/hooks/useTarget.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport useEvent from \"rc-util/es/hooks/useEvent\";\nimport useLayoutEffect from \"rc-util/es/hooks/useLayoutEffect\";\nimport { useMemo, useState } from 'react';\nimport { isInViewPort } from \"../util\";\nexport default function useTarget(target, open, gap, scrollIntoViewOptions) {\n // ========================= Target =========================\n // We trade `undefined` as not get target by function yet.\n // `null` as empty target.\n var _useState = useState(undefined),\n _useState2 = _slicedToArray(_useState, 2),\n targetElement = _useState2[0],\n setTargetElement = _useState2[1];\n useLayoutEffect(function () {\n var nextElement = typeof target === 'function' ? target() : target;\n setTargetElement(nextElement || null);\n });\n\n // ========================= Align ==========================\n var _useState3 = useState(null),\n _useState4 = _slicedToArray(_useState3, 2),\n posInfo = _useState4[0],\n setPosInfo = _useState4[1];\n var updatePos = useEvent(function () {\n if (targetElement) {\n // Exist target element. We should scroll and get target position\n if (!isInViewPort(targetElement) && open) {\n targetElement.scrollIntoView(scrollIntoViewOptions);\n }\n var _targetElement$getBou = targetElement.getBoundingClientRect(),\n left = _targetElement$getBou.left,\n top = _targetElement$getBou.top,\n width = _targetElement$getBou.width,\n height = _targetElement$getBou.height;\n var nextPosInfo = {\n left: left,\n top: top,\n width: width,\n height: height,\n radius: 0\n };\n setPosInfo(function (origin) {\n if (JSON.stringify(origin) !== JSON.stringify(nextPosInfo)) {\n return nextPosInfo;\n }\n return origin;\n });\n } else {\n // Not exist target which means we just show in center\n setPosInfo(null);\n }\n });\n var getGapOffset = function getGapOffset(index) {\n var _ref;\n return (_ref = Array.isArray(gap === null || gap === void 0 ? void 0 : gap.offset) ? gap === null || gap === void 0 ? void 0 : gap.offset[index] : gap === null || gap === void 0 ? void 0 : gap.offset) !== null && _ref !== void 0 ? _ref : 6;\n };\n useLayoutEffect(function () {\n updatePos();\n // update when window resize\n window.addEventListener('resize', updatePos);\n return function () {\n window.removeEventListener('resize', updatePos);\n };\n }, [targetElement, open, updatePos]);\n\n // ======================== PosInfo =========================\n var mergedPosInfo = useMemo(function () {\n if (!posInfo) {\n return posInfo;\n }\n var gapOffsetX = getGapOffset(0);\n var gapOffsetY = getGapOffset(1);\n var gapRadius = (gap === null || gap === void 0 ? void 0 : gap.radius) || 2;\n return {\n left: posInfo.left - gapOffsetX,\n top: posInfo.top - gapOffsetY,\n width: posInfo.width + gapOffsetX * 2,\n height: posInfo.height + gapOffsetY * 2,\n radius: gapRadius\n };\n }, [posInfo, gap]);\n return [mergedPosInfo, targetElement];\n}"],"mappings":"AAAA,OAAOA,cAAc,MAAM,0CAA0C;AACrE,OAAOC,QAAQ,MAAM,2BAA2B;AAChD,OAAOC,eAAe,MAAM,kCAAkC;AA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