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