tdesign-mobile-vue
Version:
tdesign-mobile-vue
79 lines (73 loc) • 2.11 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
function getTouch(el, x, y) {
return {
identifier: Date.now(),
target: el,
pageX: x,
pageY: y,
clientX: x,
clientY: y,
radiusX: 2.5,
radiusY: 2.5,
rotationAngle: 10,
force: 0.5
};
}
function trigger(wrapper, eventName) {
var x = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var y = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var el = "element" in wrapper ? wrapper.element : wrapper;
var touchList = options.touchList || [getTouch(el, x, y)];
if (options.x || options.y) {
touchList.push(getTouch(el, options.x, options.y));
}
var event = document.createEvent("CustomEvent");
event.initCustomEvent(eventName, true, true, {});
Object.assign(event, {
clientX: x,
clientY: y,
touches: touchList,
targetTouches: touchList,
changedTouches: touchList
});
el.dispatchEvent(event);
return vue.nextTick();
}
function triggerTwoFingerTouchmove(el, x, y) {
trigger(el, "touchmove", -x, -y, {
x: x,
y: y
});
}
function triggerZoom(el, x, y) {
var direction = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "in";
trigger(el, "touchstart", 0, 0, {
x: x,
y: y
});
if (direction === "in") {
triggerTwoFingerTouchmove(el, x / 4, y / 4);
triggerTwoFingerTouchmove(el, x / 3, y / 3);
triggerTwoFingerTouchmove(el, x / 2, y / 2);
triggerTwoFingerTouchmove(el, x, y);
} else if (direction === "out") {
triggerTwoFingerTouchmove(el, x, y);
triggerTwoFingerTouchmove(el, x / 2, y / 2);
triggerTwoFingerTouchmove(el, x / 3, y / 3);
triggerTwoFingerTouchmove(el, x / 4, y / 4);
}
trigger(el, "touchend", 0, 0, {
touchList: []
});
}
exports.trigger = trigger;
exports.triggerZoom = triggerZoom;
//# sourceMappingURL=touch.js.map