PromoCursed/node_modules/.cache/babel-loader/71bdb9cc4e6b2ee69bc3647708ccaa95302af42b6ce0c13b8bb0802b095e3d17.json

1 line
13 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useEffect, useRef, useState } from 'react';\nfunction getPosition(e) {\n var obj = 'touches' in e ? e.touches[0] : e;\n var scrollXOffset = document.documentElement.scrollLeft || document.body.scrollLeft || window.pageXOffset;\n var scrollYOffset = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;\n return {\n pageX: obj.pageX - scrollXOffset,\n pageY: obj.pageY - scrollYOffset\n };\n}\nfunction useColorDrag(props) {\n var targetRef = props.targetRef,\n containerRef = props.containerRef,\n direction = props.direction,\n onDragChange = props.onDragChange,\n onDragChangeComplete = props.onDragChangeComplete,\n calculate = props.calculate,\n color = props.color,\n disabledDrag = props.disabledDrag;\n var _useState = useState({\n x: 0,\n y: 0\n }),\n _useState2 = _slicedToArray(_useState, 2),\n offsetValue = _useState2[0],\n setOffsetValue = _useState2[1];\n var mouseMoveRef = useRef(null);\n var mouseUpRef = useRef(null);\n\n // Always get position from `color`\n useEffect(function () {\n setOffsetValue(calculate());\n }, [color]);\n useEffect(function () {\n return function () {\n document.removeEventListener('mousemove', mouseMoveRef.current);\n document.removeEventListener('mouseup', mouseUpRef.current);\n document.removeEventListener('touchmove', mouseMoveRef.current);\n document.removeEventListener('touchend', mouseUpRef.current);\n mouseMoveRef.current = null;\n mouseUpRef.current = null;\n };\n }, []);\n var updateOffset = function updateOffset(e) {\n var _getPosition = getPosition(e),\n pageX = _getPosition.pageX,\n pageY = _getPosition.pageY;\n var _containerRef$current = containerRef.current.getBoundingClientRect(),\n rectX = _containerRef$current.x,\n rectY = _containerRef$current.y,\n width = _containerRef$current.width,\n height = _containerRef$current.height;\n var _targetRef$current$ge = targetRef.current.getBoundingClientRect(),\n targetWidth = _targetRef$current$ge.width,\n targetHeight = _targetRef$current$ge.height;\n var centerOffsetX = targetWidth / 2;\n var centerOffsetY = targetHeight / 2;\n var offsetX = Math.max(0, Math.min(pageX - rectX, width)) - centerOffsetX;\n var offsetY = Math.max(0, Math.min(pageY - rectY, height)) - centerOffsetY;\n var calcOffset = {\n x: offsetX,\n y: direction === 'x' ? offsetValue.y : offsetY\n };\n\n // Exclusion of boundary cases\n if (targetWidth === 0 && targetHeight === 0 || targetWidth !== targetHeight) {\n return false;\n }\n onDragChange === null || onDragChange === void 0 || onDragChange(calcOffset);\n };\n var onDragMove = function onDragMove(e) {\n e.preventDefault();\n updateOffset(e);\n };\n var onDragStop = function onDragStop(e) {\n e.preventDefault();\n document.removeEventListener('mousemove', mouseMoveRef.current);\n document.removeEventListener('mouseup', mouseUpRef.current);\n document.removeEventListener('touchmove', mouseMoveRef.current);\n document.removeEventListener('touchend', mouseUpRef.current);\n mouseMoveRef.current = null;\n mouseUpRef.current = null;\n onDragChangeComplete === null || onDragChangeComplete === void 0 || onDragChangeComplete();\n };\n var onDragStart = function onDragStart(e) {\n // https://github.com/ant-design/ant-design/issues/43529\n document.removeEventListener('mousemove', mouseMoveRef.current);\n document.removeEventListener('mouseup', mouseUpRef.current);\n if (disabledDrag) {\n return;\n }\n updateOffset(e);\n document.addEventListener('mousemove', onDragMove);\n document.addEventListener('mouseup', onDragStop);\n document.addEventListener('touchmove', onDragMove);\n document.addEventListener('touchend', onDragStop);\n mouseMoveRef.current = onDragMove;\n mouseUpRef.current = onDragStop;\n };\n return [offse