touch.js 1.2 KB

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