UNPKG

tdesign-mobile-vue

Version:
77 lines (71 loc) 1.87 kB
/** * tdesign v1.7.0 * (c) 2024 TDesign Group * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); function getDirection(x, y) { if (x > y) { return "horizontal"; } if (y > x) { return "vertical"; } return ""; } function useTouch() { var startX = vue.ref(0); var startY = vue.ref(0); var deltaX = vue.ref(0); var deltaY = vue.ref(0); var offsetX = vue.ref(0); var offsetY = vue.ref(0); var direction = vue.ref(""); var isVertical = function isVertical() { return direction.value === "vertical"; }; var isHorizontal = function isHorizontal() { return direction.value === "horizontal"; }; var reset = function reset() { deltaX.value = 0; deltaY.value = 0; offsetX.value = 0; offsetY.value = 0; direction.value = ""; }; var start = function start(event) { reset(); startX.value = event.touches[0].clientX; startY.value = event.touches[0].clientY; }; var move = function move(event) { var touch = event.touches[0]; deltaX.value = (touch.clientX < 0 ? 0 : touch.clientX) - startX.value; deltaY.value = touch.clientY - startY.value; offsetX.value = Math.abs(deltaX.value); offsetY.value = Math.abs(deltaY.value); var LOCK_DIRECTION_DISTANCE = 10; if (!direction.value || offsetX.value < LOCK_DIRECTION_DISTANCE && offsetY.value < LOCK_DIRECTION_DISTANCE) { direction.value = getDirection(offsetX.value, offsetY.value); } }; return { move: move, start: start, reset: reset, startX: startX, startY: startY, deltaX: deltaX, deltaY: deltaY, offsetX: offsetX, offsetY: offsetY, direction: direction, isVertical: isVertical, isHorizontal: isHorizontal }; } exports.useTouch = useTouch; //# sourceMappingURL=index.js.map