touch.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. exports.touch = void 0;
  4. // @ts-nocheck
  5. var MIN_DISTANCE = 10;
  6. function getDirection(x, y) {
  7. if (x > y && x > MIN_DISTANCE) {
  8. return 'horizontal';
  9. }
  10. if (y > x && y > MIN_DISTANCE) {
  11. return 'vertical';
  12. }
  13. return '';
  14. }
  15. exports.touch = Behavior({
  16. methods: {
  17. resetTouchStatus: function () {
  18. this.direction = '';
  19. this.deltaX = 0;
  20. this.deltaY = 0;
  21. this.offsetX = 0;
  22. this.offsetY = 0;
  23. },
  24. touchStart: function (event) {
  25. this.resetTouchStatus();
  26. var touch = event.touches[0];
  27. this.startX = touch.clientX;
  28. this.startY = touch.clientY;
  29. },
  30. touchMove: function (event) {
  31. var touch = event.touches[0];
  32. this.deltaX = touch.clientX - this.startX;
  33. this.deltaY = touch.clientY - this.startY;
  34. this.offsetX = Math.abs(this.deltaX);
  35. this.offsetY = Math.abs(this.deltaY);
  36. this.direction =
  37. this.direction || getDirection(this.offsetX, this.offsetY);
  38. },
  39. },
  40. });