1 line
15 KiB
JSON
1 line
15 KiB
JSON
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport addEventListener from \"rc-util/es/Dom/addEventListener\";\nimport { warning } from \"rc-util/es/warning\";\nimport { useEffect, useRef, useState } from 'react';\nimport getFixScaleEleTransPosition from \"../getFixScaleEleTransPosition\";\nimport { BASE_SCALE_RATIO, WHEEL_MAX_SCALE_RATIO } from \"../previewConfig\";\nexport default function useMouseEvent(imgRef, movable, visible, scaleStep, transform, updateTransform, dispatchZoomChange) {\n var rotate = transform.rotate,\n scale = transform.scale,\n x = transform.x,\n y = transform.y;\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n isMoving = _useState2[0],\n setMoving = _useState2[1];\n var startPositionInfo = useRef({\n diffX: 0,\n diffY: 0,\n transformX: 0,\n transformY: 0\n });\n var onMouseDown = function onMouseDown(event) {\n // Only allow main button\n if (!movable || event.button !== 0) return;\n event.preventDefault();\n event.stopPropagation();\n startPositionInfo.current = {\n diffX: event.pageX - x,\n diffY: event.pageY - y,\n transformX: x,\n transformY: y\n };\n setMoving(true);\n };\n var onMouseMove = function onMouseMove(event) {\n if (visible && isMoving) {\n updateTransform({\n x: event.pageX - startPositionInfo.current.diffX,\n y: event.pageY - startPositionInfo.current.diffY\n }, 'move');\n }\n };\n var onMouseUp = function onMouseUp() {\n if (visible && isMoving) {\n setMoving(false);\n\n /** No need to restore the position when the picture is not moved, So as not to interfere with the click */\n var _startPositionInfo$cu = startPositionInfo.current,\n transformX = _startPositionInfo$cu.transformX,\n transformY = _startPositionInfo$cu.transformY;\n var hasChangedPosition = x !== transformX && y !== transformY;\n if (!hasChangedPosition) return;\n var width = imgRef.current.offsetWidth * scale;\n var height = imgRef.current.offsetHeight * scale;\n // eslint-disable-next-line @typescript-eslint/no-shadow\n var _imgRef$current$getBo = imgRef.current.getBoundingClientRect(),\n left = _imgRef$current$getBo.left,\n top = _imgRef$current$getBo.top;\n var isRotate = rotate % 180 !== 0;\n var fixState = getFixScaleEleTransPosition(isRotate ? height : width, isRotate ? width : height, left, top);\n if (fixState) {\n updateTransform(_objectSpread({}, fixState), 'dragRebound');\n }\n }\n };\n var onWheel = function onWheel(event) {\n if (!visible || event.deltaY == 0) return;\n // Scale ratio depends on the deltaY size\n var scaleRatio = Math.abs(event.deltaY / 100);\n // Limit the maximum scale ratio\n var mergedScaleRatio = Math.min(scaleRatio, WHEEL_MAX_SCALE_RATIO);\n // Scale the ratio each time\n var ratio = BASE_SCALE_RATIO + mergedScaleRatio * scaleStep;\n if (event.deltaY > 0) {\n ratio = BASE_SCALE_RATIO / ratio;\n }\n dispatchZoomChange(ratio, 'wheel', event.clientX, event.clientY);\n };\n useEffect(function () {\n var onTopMouseUpListener;\n var onTopMouseMoveListener;\n var onMouseUpListener;\n var onMouseMoveListener;\n if (movable) {\n onMouseUpListener = addEventListener(window, 'mouseup', onMouseUp, false);\n onMouseMoveListener = addEventListener(window, 'mousemove', onMouseMove, false);\n try {\n // Resolve if in iframe lost event\n /* istanbul ignore next */\n if (window.top !== window.self) {\n onTopMouseUpListener = addEventListener(window.top, 'mouseup', onMouseUp, false);\n onTopMouseMoveListener = addEventListener(window.top, 'mousemove', onMouseMove, false);\n }\n } catch (error) {\n /* istanbul ignore next */\n warning(false, \"[rc-image] \".concat(error));\n }\n }\n return function () {\n var _onMouseUpListener, _onMouseMoveListener, _onTopMouseUpListener, _onTopMouseMoveListen;\n (_onMouseUpListener = onMouseUpListener) === null || _onMouseUpListener === void 0 || _onMouseUpListener.remove();\n (_onMouseMoveListener = onMouseMoveListener) === null || _onMouseMoveListener === void 0 || _onMouseMoveListener.remove();\n /* istanbul ignore next */\n (_onTopMouseUpListener = onTopMouseUpListener) === null || _onTopMouseUpListener === void 0 || _onTopMouseUpListener.remove();\n /* istanbul ignore next */\n (_onTopMouseMoveListen = onTopMouseMoveListener) === null || _onTopMouseMoveListen === void 0 || _onTopMouseMoveListen.remove();\n };\n }, [visible, isMoving, x, y, rotate, movable]);\n return {\n isMoving: isMoving,\n onMouseDown: onMouseDown,\n onMouseMove: onMouseMove,\n onMouseUp: onMouseUp,\n onWheel: onWheel\n };\n}","map":{"version":3,"names":["_objectSpread","_slicedToArray","addEventListener","warning","useEffect","useRef","useState","getFixScaleEleTransPosition","BASE_SCALE_RATIO","WHEEL_MAX_SCALE_RATIO","useMouseEvent","imgRef","movable","visible","scaleStep","transform","updateTransform","dispatchZoomChange","rotate","scale","x","y","_useState","_useState2","isMoving","setMoving","startPositionInfo","diffX","diffY","transformX","transformY","onMouseDown","event","button","preventDefault","stopPropagation","current","pageX","pageY","onMouseMove","onMouseUp","_startPositionInfo$cu","hasChangedPosition","width","offsetWidth","height","offsetHeight","_imgRef$current$getBo","getBoundingClientRect","left","top","isRotate","fixState","onWheel","deltaY","scaleRatio","Math","abs","mergedScaleRatio","min","ratio","clientX","clientY","onTopMouseUpListener","onTopMouseMoveListener","onMouseUpListener","onMouseMoveListener","window","self","error","concat","_onMouseUpListener","_onMouseMoveListener","_onTopMouseUpListener","_onTopMouseMoveListen","remove"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-image/es/hooks/useMouseEvent.js"],"sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport addEventListener from \"rc-util/es/Dom/addEventListener\";\nimport { warning } from \"rc-util/es/warning\";\nimport { useEffect, useRef, useState } from 'react';\nimport getFixScaleEleTransPosition from \"../getFixScaleEleTransPosition\";\nimport { BASE_SCALE_RATIO, WHEEL_MAX_SCALE_RATIO } from \"../previewConfig\";\nexport default function useMouseEvent(imgRef, movable, visible, scaleStep, transform, updateTransform, dispatchZoomChange) {\n var rotate = transform.rotate,\n scale = transform.scale,\n x = transform.x,\n y = transform.y;\n var _useState = useState(false),\n _useState2 = _slicedToArray(_useState, 2),\n isMoving = _useState2[0],\n setMoving = _useState2[1];\n var startPositionInfo = useRef({\n diffX: 0,\n diffY: 0,\n transformX: 0,\n transformY: 0\n });\n var onMouseDown = function onMouseDown(event) {\n // Only allow main button\n if (!movable || event.button !== 0) return;\n event.preventDefault();\n event.stopPropagation();\n startPositionInfo.current = {\n diffX: event.pageX - x,\n diffY: event.pageY - y,\n transformX: x,\n transformY: y\n };\n setMoving(true);\n };\n var onMouseMove = function onMouseMove(event) {\n if (visible && isMoving) {\n updateTransform({\n x: event.pageX - startPositionInfo.current.diffX,\n y: event.pageY - startPositionInfo.current.diffY\n }, 'move');\n }\n };\n var onMouseUp = function onMouseUp() {\n if (visible && isMoving) {\n setMoving(false);\n\n /** No need to restore the position when the picture is not moved, So as not to interfere with the click */\n var _startPositionInfo$cu = startPositionInfo.current,\n transformX = _startPositionInfo$cu.transformX,\n transformY = _startPositionInfo$cu.transformY;\n var hasChangedPosition = x !== transformX && y !== transformY;\n if (!hasChangedPosition) return;\n var width = imgRef.current.offsetWidth * scale;\n var height = imgRef.current.offsetHeight * scale;\n // eslint-disable-next-line @typescript-eslint/no-shadow\n var _imgRef$current$getBo = imgRef.current.getBoundingClientRect(),\n left = _imgRef$current$getBo.left,\n top = _imgRef$current$getBo.top;\n var isRotate = rotate % 180 !== 0;\n var fixState = getFixScaleEleTransPosition(isRotate ? height : width, isRotate ? width : height, left, top);\n if (fixState) {\n updateTransform(_objectSpread({}, fixState), 'dragRebound');\n }\n }\n };\n var onWheel = function onWheel(event) {\n if (!visible || event.deltaY == 0) return;\n // Scale ratio depends on the deltaY size\n var scaleRatio = Math.abs(event.deltaY / 100);\n // Limit the maximum scale ratio\n var mergedScaleRatio = Math.min(scaleRatio, WHEEL_MAX_SCALE_RATIO);\n // Scale the ratio each time\n var ratio = BASE_SCALE_RATIO + mergedScaleRatio * scaleStep;\n if (event.deltaY > 0) {\n ratio = BASE_SCALE_RATIO / ratio;\n }\n dispatchZoomChange(ratio, 'wheel', event.clientX, event.clientY);\n };\n useEffect(function () {\n var onTopMouseUpListener;\n var onTopMouseMoveListener;\n var onMouseUpListener;\n var onMouseMoveListener;\n if (movable) {\n onMouseUpListener = addEventListener(window, 'mouseup', onMouseUp, false);\n onMouseMoveListener = addEventListener(window, 'mousemove', onMouseMove, false);\n try {\n // Resolve if in iframe lost event\n /* istanbul ignore next */\n if (window.top !== window.self) {\n onTopMouseUpListener = addEventListener(window.top, 'mouseup', onMouseUp, false);\n onTopMouseMoveListener = addEventListener(window.top, 'mousemove', onMouseMove, false);\n }\n } catch (error) {\n /* istanbul ignore next */\n warning(false, \"[rc-image] \".concat(error));\n }\n }\n return function () {\n var _onMouseUpListener, _onMouseMoveListener, _onTopMouseUpListener, _onTopMouseMoveListen;\n (_onMouseUpListener = onMouseUpListener) === null || _onMouseUpListener === void 0 || _onMouseUpListener.remove();\n (_onMouseMoveListener = onMouseMoveListener) === null || _onMouseMoveListener === void 0 || _onMouseMoveListener.remove();\n /* istanbul ignore next */\n (_onTopMouseUpListener = onTopMouseUpListener) === null || _onTopMouseUpListener === void 0 || _onTopMouseUpListener.remove();\n /* istanbul ignore next */\n (_onTopMouseMoveListen = onTopMouseMoveListener) === null || _onTopMouseMoveListen === void 0 || _onTopMouseMoveListen.remove();\n };\n }, [visible, isMoving, x, y, rotate, movable]);\n return {\n isMoving: isMoving,\n onMouseDown: onMouseDown,\n onMouseMove: onMouseMove,\n onMouseUp: onMouseUp,\n onWheel: onWheel\n };\n}"],"mappings":"AAAA,OAAOA,aAAa,MAAM,0CAA0C;AACpE,OAAOC,cAAc,MAAM,0CAA0C;AACrE,OAAOC,gBAAgB,MAAM,iCAAiC;AAC9D,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnD,OAAOC,2BAA2B,MAAM,gCAAgC;AACxE,SAASC,gBAAgB,EAAEC,qBAAqB,QAAQ,kBAAkB;AAC1E,eAAe,SAASC,aAAaA,CAACC,MAAM,EAAEC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