88 lines
2.7 KiB
JavaScript
88 lines
2.7 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var stdin_exports = {};
|
|
__export(stdin_exports, {
|
|
useTouch: () => useTouch
|
|
});
|
|
module.exports = __toCommonJS(stdin_exports);
|
|
var import_vue = require("vue");
|
|
var import_utils = require("../utils");
|
|
function getDirection(x, y) {
|
|
if (x > y) {
|
|
return "horizontal";
|
|
}
|
|
if (y > x) {
|
|
return "vertical";
|
|
}
|
|
return "";
|
|
}
|
|
function useTouch() {
|
|
const startX = (0, import_vue.ref)(0);
|
|
const startY = (0, import_vue.ref)(0);
|
|
const deltaX = (0, import_vue.ref)(0);
|
|
const deltaY = (0, import_vue.ref)(0);
|
|
const offsetX = (0, import_vue.ref)(0);
|
|
const offsetY = (0, import_vue.ref)(0);
|
|
const direction = (0, import_vue.ref)("");
|
|
const isTap = (0, import_vue.ref)(true);
|
|
const isVertical = () => direction.value === "vertical";
|
|
const isHorizontal = () => direction.value === "horizontal";
|
|
const reset = () => {
|
|
deltaX.value = 0;
|
|
deltaY.value = 0;
|
|
offsetX.value = 0;
|
|
offsetY.value = 0;
|
|
direction.value = "";
|
|
isTap.value = true;
|
|
};
|
|
const start = (event) => {
|
|
reset();
|
|
startX.value = event.touches[0].clientX;
|
|
startY.value = event.touches[0].clientY;
|
|
};
|
|
const move = (event) => {
|
|
const 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);
|
|
const LOCK_DIRECTION_DISTANCE = 10;
|
|
if (!direction.value || offsetX.value < LOCK_DIRECTION_DISTANCE && offsetY.value < LOCK_DIRECTION_DISTANCE) {
|
|
direction.value = getDirection(offsetX.value, offsetY.value);
|
|
}
|
|
if (isTap.value && (offsetX.value > import_utils.TAP_OFFSET || offsetY.value > import_utils.TAP_OFFSET)) {
|
|
isTap.value = false;
|
|
}
|
|
};
|
|
return {
|
|
move,
|
|
start,
|
|
reset,
|
|
startX,
|
|
startY,
|
|
deltaX,
|
|
deltaY,
|
|
offsetX,
|
|
offsetY,
|
|
direction,
|
|
isVertical,
|
|
isHorizontal,
|
|
isTap
|
|
};
|
|
}
|