1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.now = now;
|
7 | exports.calcMutliFingerStatus = calcMutliFingerStatus;
|
8 | exports.calcMoveStatus = calcMoveStatus;
|
9 | exports.calcRotation = calcRotation;
|
10 | exports.getEventName = getEventName;
|
11 | exports.shouldTriggerSwipe = shouldTriggerSwipe;
|
12 | exports.shouldTriggerDirection = shouldTriggerDirection;
|
13 | exports.getDirection = getDirection;
|
14 | exports.getDirectionEventName = getDirectionEventName;
|
15 |
|
16 | var _config = require('./config');
|
17 |
|
18 | function _calcTriangleDistance(x, y) {
|
19 | return Math.sqrt(x * x + y * y);
|
20 | }
|
21 |
|
22 | function _calcAngle(x, y) {
|
23 | var radian = Math.atan2(y, x);
|
24 | return 180 / (Math.PI / radian);
|
25 | }
|
26 | function now() {
|
27 | return Date.now();
|
28 | }
|
29 | function calcMutliFingerStatus(touches) {
|
30 | if (touches.length < 2) {
|
31 | return;
|
32 | }
|
33 | var _touches$ = touches[0],
|
34 | x1 = _touches$.x,
|
35 | y1 = _touches$.y;
|
36 | var _touches$2 = touches[1],
|
37 | x2 = _touches$2.x,
|
38 | y2 = _touches$2.y;
|
39 |
|
40 | var deltaX = x2 - x1;
|
41 | var deltaY = y2 - y1;
|
42 | return {
|
43 | x: deltaX,
|
44 | y: deltaY,
|
45 | z: _calcTriangleDistance(deltaX, deltaY),
|
46 | angle: _calcAngle(deltaX, deltaY)
|
47 | };
|
48 | }
|
49 | function calcMoveStatus(startTouches, touches, time) {
|
50 | var _startTouches$ = startTouches[0],
|
51 | x1 = _startTouches$.x,
|
52 | y1 = _startTouches$.y;
|
53 | var _touches$3 = touches[0],
|
54 | x2 = _touches$3.x,
|
55 | y2 = _touches$3.y;
|
56 |
|
57 | var deltaX = x2 - x1;
|
58 | var deltaY = y2 - y1;
|
59 | var deltaZ = _calcTriangleDistance(deltaX, deltaY);
|
60 | return {
|
61 | x: deltaX,
|
62 | y: deltaY,
|
63 | z: deltaZ,
|
64 | time: time,
|
65 | velocity: deltaZ / time,
|
66 | angle: _calcAngle(deltaX, deltaY)
|
67 | };
|
68 | }
|
69 | function calcRotation(startMutliFingerStatus, mutliFingerStatus) {
|
70 | var startAngle = startMutliFingerStatus.angle;
|
71 | var angle = mutliFingerStatus.angle;
|
72 |
|
73 | return angle - startAngle;
|
74 | }
|
75 | function getEventName(prefix, status) {
|
76 | return prefix + status[0].toUpperCase() + status.slice(1);
|
77 | }
|
78 | function shouldTriggerSwipe(delta, velocity) {
|
79 | return Math.abs(delta) >= _config.SWIPE.threshold && Math.abs(velocity) > _config.SWIPE.velocity;
|
80 | }
|
81 | function shouldTriggerDirection(direction, directionSetting) {
|
82 | if (directionSetting & direction) {
|
83 | return true;
|
84 | }
|
85 | return false;
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | function getDirection(x, y) {
|
95 | if (x === y) {
|
96 | return _config.DIRECTION_NONE;
|
97 | }
|
98 | if (Math.abs(x) >= Math.abs(y)) {
|
99 | return x < 0 ? _config.DIRECTION_LEFT : _config.DIRECTION_RIGHT;
|
100 | }
|
101 | return y < 0 ? _config.DIRECTION_UP : _config.DIRECTION_DOWN;
|
102 | }
|
103 | function getDirectionEventName(direction) {
|
104 | var name = void 0;
|
105 | switch (direction) {
|
106 | case _config.DIRECTION_NONE:
|
107 | break;
|
108 | case _config.DIRECTION_LEFT:
|
109 | name = 'left';
|
110 | break;
|
111 | case _config.DIRECTION_RIGHT:
|
112 | name = 'right';
|
113 | break;
|
114 | case _config.DIRECTION_UP:
|
115 | name = 'up';
|
116 | break;
|
117 | case _config.DIRECTION_DOWN:
|
118 | name = 'down';
|
119 | break;
|
120 | default:
|
121 | }
|
122 | return name;
|
123 | } |
\ | No newline at end of file |