highmark-cli 0.0.135 → 0.0.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +1376 -449
- package/lib/client.js +4 -6
- package/lib/constants.js +37 -25
- package/lib/customEventTypes.js +40 -4
- package/lib/mixins/touch.js +346 -71
- package/lib/position/relative.js +97 -0
- package/lib/position.js +8 -36
- package/lib/selectors.js +26 -0
- package/lib/style.js +13 -0
- package/lib/utilities/element.js +6 -3
- package/lib/utilities/positions.js +143 -0
- package/lib/view/div/leaf.js +20 -16
- package/lib/view/div/menu.js +238 -0
- package/lib/view.js +268 -68
- package/package.json +5 -5
- package/src/client.js +2 -6
- package/src/constants.js +11 -8
- package/src/customEventTypes.js +10 -1
- package/src/mixins/touch.js +556 -78
- package/src/position/relative.js +63 -0
- package/src/position.js +10 -48
- package/src/selectors.js +5 -0
- package/src/style.js +3 -0
- package/src/utilities/element.js +7 -2
- package/src/utilities/positions.js +127 -0
- package/src/view/div/leaf.js +23 -26
- package/src/view/div/menu.js +62 -0
- package/src/view.js +315 -76
- package/template/default.html +10 -4
- package/lib/mixins/event.js +0 -46
- package/lib/velocity.js +0 -82
- package/src/mixins/event.js +0 -56
- package/src/velocity.js +0 -45
package/src/mixins/touch.js
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { window } from "easy";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import { MAXIMUM_TAP_TIME, MINIMUM_SWIPE_SPEED,
|
|
4
|
+
import { arrayUtilities } from "necessary";
|
|
5
|
+
|
|
6
|
+
import RelativePosition from "../position/relative";
|
|
7
|
+
|
|
8
|
+
import { TOUCHSTART_EVENT_TYPE, TOUCHMOVE_EVENT_TYPE, TOUCHEND_EVENT_TYPE } from "../eventTypes";
|
|
9
|
+
import { PI, TAP_DELAY, PI_OVER_TWO, MAXIMUM_TAP_TIME, MINIMUM_SWIPE_SPEED, MAXIMUM_SPREAD } from "../constants";
|
|
10
|
+
import { sortPositions, matchPositions, filterPositions, positionsFromMouseEvent, positionsFromTouchEvent } from "../utilities/positions";
|
|
11
|
+
import { TAP_CUSTOM_EVENT_TYPE,
|
|
12
|
+
DRAG_UP_CUSTOM_EVENT_TYPE,
|
|
13
|
+
DRAG_DOWN_CUSTOM_EVENT_TYPE,
|
|
14
|
+
DRAG_LEFT_CUSTOM_EVENT_TYPE,
|
|
15
|
+
DRAG_RIGHT_CUSTOM_EVENT_TYPE,
|
|
16
|
+
DRAG_START_CUSTOM_EVENT_TYPE,
|
|
17
|
+
SWIPE_UP_CUSTOM_EVENT_TYPE,
|
|
18
|
+
SWIPE_DOWN_CUSTOM_EVENT_TYPE,
|
|
19
|
+
SWIPE_LEFT_CUSTOM_EVENT_TYPE,
|
|
20
|
+
SWIPE_RIGHT_CUSTOM_EVENT_TYPE,
|
|
21
|
+
PINCH_MOVE_CUSTOM_EVENT_TYPE,
|
|
22
|
+
PINCH_START_CUSTOM_EVENT_TYPE,
|
|
23
|
+
DOUBLE_TAP_CUSTOM_EVENT_TYPE } from "../customEventTypes";
|
|
24
|
+
|
|
25
|
+
const { push, first, second } = arrayUtilities;
|
|
10
26
|
|
|
11
27
|
function enableTouch() {
|
|
12
|
-
const
|
|
28
|
+
const tapInterval = null,
|
|
29
|
+
startMagnitude = null,
|
|
30
|
+
startPositions = [],
|
|
31
|
+
movingPositions = [];
|
|
13
32
|
|
|
14
33
|
this.updateState({
|
|
15
|
-
|
|
34
|
+
tapInterval,
|
|
35
|
+
startMagnitude,
|
|
36
|
+
startPositions,
|
|
37
|
+
movingPositions
|
|
16
38
|
});
|
|
17
39
|
|
|
18
40
|
this.onMouseDown(this.mouseDownHandler);
|
|
@@ -36,6 +58,48 @@ function disableTouch() {
|
|
|
36
58
|
this.offTouchEnd(this.touchEndHandler);
|
|
37
59
|
}
|
|
38
60
|
|
|
61
|
+
function onTouchStart(touchStartHandler) {
|
|
62
|
+
const eventType = TOUCHSTART_EVENT_TYPE,
|
|
63
|
+
handler = touchStartHandler; ///
|
|
64
|
+
|
|
65
|
+
this.onEvent(eventType, handler);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function offTouchStart(touchStartHandler) {
|
|
69
|
+
const eventType = TOUCHSTART_EVENT_TYPE,
|
|
70
|
+
handler = touchStartHandler; ///
|
|
71
|
+
|
|
72
|
+
this.offEvent(eventType, handler);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function onTouchMove(touchStartHandler) {
|
|
76
|
+
const eventType = TOUCHMOVE_EVENT_TYPE,
|
|
77
|
+
handler = touchStartHandler; ///
|
|
78
|
+
|
|
79
|
+
this.onEvent(eventType, handler);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function offTouchMove(touchStartHandler) {
|
|
83
|
+
const eventType = TOUCHMOVE_EVENT_TYPE,
|
|
84
|
+
handler = touchStartHandler; ///
|
|
85
|
+
|
|
86
|
+
this.offEvent(eventType, handler);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function onTouchEnd(touchStartHandler) {
|
|
90
|
+
const eventType = TOUCHEND_EVENT_TYPE,
|
|
91
|
+
handler = touchStartHandler; ///
|
|
92
|
+
|
|
93
|
+
this.onEvent(eventType, handler);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function offTouchEnd(touchStartHandler) {
|
|
97
|
+
const eventType = TOUCHEND_EVENT_TYPE,
|
|
98
|
+
handler = touchStartHandler; ///
|
|
99
|
+
|
|
100
|
+
this.offEvent(eventType, handler);
|
|
101
|
+
}
|
|
102
|
+
|
|
39
103
|
function onCustomTap(tapCustomHandler, element) {
|
|
40
104
|
const customEventType = TAP_CUSTOM_EVENT_TYPE,
|
|
41
105
|
customHandler = tapCustomHandler; ///
|
|
@@ -50,6 +114,104 @@ function offCustomTap(tapCustomHandler, element) {
|
|
|
50
114
|
this.offCustomEvent(customEventType, customHandler, element);
|
|
51
115
|
}
|
|
52
116
|
|
|
117
|
+
function onCustomDragUp(dragUpCustomHandler, element) {
|
|
118
|
+
const customEventType = DRAG_UP_CUSTOM_EVENT_TYPE,
|
|
119
|
+
customHandler = dragUpCustomHandler; ///
|
|
120
|
+
|
|
121
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function offCustomDragUp(dragUpCustomHandler, element) {
|
|
125
|
+
const customEventType = DRAG_UP_CUSTOM_EVENT_TYPE,
|
|
126
|
+
customHandler = dragUpCustomHandler; ///
|
|
127
|
+
|
|
128
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function onCustomDragDown(dragDownCustomHandler, element) {
|
|
132
|
+
const customEventType = DRAG_DOWN_CUSTOM_EVENT_TYPE,
|
|
133
|
+
customHandler = dragDownCustomHandler; ///
|
|
134
|
+
|
|
135
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function offCustomDragDown(dragDownCustomHandler, element) {
|
|
139
|
+
const customEventType = DRAG_DOWN_CUSTOM_EVENT_TYPE,
|
|
140
|
+
customHandler = dragDownCustomHandler; ///
|
|
141
|
+
|
|
142
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function onCustomDragLeft(dragLeftCustomHandler, element) {
|
|
146
|
+
const customEventType = DRAG_LEFT_CUSTOM_EVENT_TYPE,
|
|
147
|
+
customHandler = dragLeftCustomHandler; ///
|
|
148
|
+
|
|
149
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function offCustomDragLeft(dragLeftCustomHandler, element) {
|
|
153
|
+
const customEventType = DRAG_LEFT_CUSTOM_EVENT_TYPE,
|
|
154
|
+
customHandler = dragLeftCustomHandler; ///
|
|
155
|
+
|
|
156
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function onCustomDragRight(dragRightCustomHandler, element) {
|
|
160
|
+
const customEventType = DRAG_RIGHT_CUSTOM_EVENT_TYPE,
|
|
161
|
+
customHandler = dragRightCustomHandler; ///
|
|
162
|
+
|
|
163
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function offCustomDragRight(dragRightCustomHandler, element) {
|
|
167
|
+
const customEventType = DRAG_RIGHT_CUSTOM_EVENT_TYPE,
|
|
168
|
+
customHandler = dragRightCustomHandler; ///
|
|
169
|
+
|
|
170
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function onCustomDragStart(dragStartCustomHandler, element) {
|
|
174
|
+
const customEventType = DRAG_START_CUSTOM_EVENT_TYPE,
|
|
175
|
+
customHandler = dragStartCustomHandler; ///
|
|
176
|
+
|
|
177
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function offCustomDragStart(dragStartCustomHandler, element) {
|
|
181
|
+
const customEventType = DRAG_START_CUSTOM_EVENT_TYPE,
|
|
182
|
+
customHandler = dragStartCustomHandler; ///
|
|
183
|
+
|
|
184
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function onCustomSwipeUp(swipeUpCustomHandler, element) {
|
|
188
|
+
const customEventType = SWIPE_UP_CUSTOM_EVENT_TYPE,
|
|
189
|
+
customHandler = swipeUpCustomHandler; ///
|
|
190
|
+
|
|
191
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function offCustomSwipeUp(swipeUpCustomHandler, element) {
|
|
195
|
+
const customEventType = SWIPE_UP_CUSTOM_EVENT_TYPE,
|
|
196
|
+
customHandler = swipeUpCustomHandler; ///
|
|
197
|
+
|
|
198
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function onCustomSwipeDown(swipeDownCustomHandler, element) {
|
|
202
|
+
const customEventType = SWIPE_DOWN_CUSTOM_EVENT_TYPE,
|
|
203
|
+
customHandler = swipeDownCustomHandler; ///
|
|
204
|
+
|
|
205
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function offCustomSwipeDown(swipeDownCustomHandler, element) {
|
|
209
|
+
const customEventType = SWIPE_DOWN_CUSTOM_EVENT_TYPE,
|
|
210
|
+
customHandler = swipeDownCustomHandler; ///
|
|
211
|
+
|
|
212
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
213
|
+
}
|
|
214
|
+
|
|
53
215
|
function onCustomSwipeLeft(swipeLeftCustomHandler, element) {
|
|
54
216
|
const customEventType = SWIPE_LEFT_CUSTOM_EVENT_TYPE,
|
|
55
217
|
customHandler = swipeLeftCustomHandler; ///
|
|
@@ -78,154 +240,447 @@ function offCustomSwipeRight(swipeRightCustomHandler, element) {
|
|
|
78
240
|
this.offCustomEvent(customEventType, customHandler, element);
|
|
79
241
|
}
|
|
80
242
|
|
|
81
|
-
function
|
|
82
|
-
const
|
|
243
|
+
function onCustomPinchMove(pinchMoveCustomHandler, element) {
|
|
244
|
+
const customEventType = PINCH_MOVE_CUSTOM_EVENT_TYPE,
|
|
245
|
+
customHandler = pinchMoveCustomHandler; ///
|
|
246
|
+
|
|
247
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function offCustomPinchMove(pinchMoveCustomHandler, element) {
|
|
251
|
+
const customEventType = PINCH_MOVE_CUSTOM_EVENT_TYPE,
|
|
252
|
+
customHandler = pinchMoveCustomHandler; ///
|
|
253
|
+
|
|
254
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function onCustomPinchStart(pinchStartCustomHandler, element) {
|
|
258
|
+
const customEventType = PINCH_START_CUSTOM_EVENT_TYPE,
|
|
259
|
+
customHandler = pinchStartCustomHandler; ///
|
|
260
|
+
|
|
261
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function offCustomPinchStart(pinchStartCustomHandler, element) {
|
|
265
|
+
const customEventType = PINCH_START_CUSTOM_EVENT_TYPE,
|
|
266
|
+
customHandler = pinchStartCustomHandler; ///
|
|
267
|
+
|
|
268
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function onCustomDoubleTap(doubleTapCustomHandler, element) {
|
|
272
|
+
const customEventType = DOUBLE_TAP_CUSTOM_EVENT_TYPE,
|
|
273
|
+
customHandler = doubleTapCustomHandler; ///
|
|
274
|
+
|
|
275
|
+
this.onCustomEvent(customEventType, customHandler, element);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function offCustomDoubleTap(doubleTapCustomHandler, element) {
|
|
279
|
+
const customEventType = DOUBLE_TAP_CUSTOM_EVENT_TYPE,
|
|
280
|
+
customHandler = doubleTapCustomHandler; ///
|
|
281
|
+
|
|
282
|
+
this.offCustomEvent(customEventType, customHandler, element);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function getTapInterval() {
|
|
286
|
+
const { tapInterval } = this.getState();
|
|
83
287
|
|
|
84
|
-
return
|
|
288
|
+
return tapInterval;
|
|
85
289
|
}
|
|
86
290
|
|
|
87
|
-
function
|
|
291
|
+
function setTapInterval(tapInterval) {
|
|
88
292
|
this.updateState({
|
|
89
|
-
|
|
293
|
+
tapInterval
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function getStartMagnitude() {
|
|
298
|
+
const { startMagnitude } = this.getState();
|
|
299
|
+
|
|
300
|
+
return startMagnitude;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function setStartMagnitude(startMagnitude) {
|
|
304
|
+
this.updateState({
|
|
305
|
+
startMagnitude
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function getStartPositions() {
|
|
310
|
+
const { startPositions } = this.getState();
|
|
311
|
+
|
|
312
|
+
return startPositions;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function setStartPositions(startPositions) {
|
|
316
|
+
this.updateState({
|
|
317
|
+
startPositions
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function getMovingPositions() {
|
|
322
|
+
const { movingPositions } = this.getState();
|
|
323
|
+
|
|
324
|
+
return movingPositions;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function setMovingPositions(movingPositions) {
|
|
328
|
+
this.updateState({
|
|
329
|
+
movingPositions
|
|
90
330
|
});
|
|
91
331
|
}
|
|
92
332
|
|
|
93
333
|
function touchStartHandler(event, element) {
|
|
94
334
|
this.startHandler(event, element, (event) => {
|
|
95
335
|
const touchEvent = event, ///
|
|
96
|
-
|
|
336
|
+
changed = false,
|
|
337
|
+
positions = positionsFromTouchEvent(touchEvent, changed);
|
|
97
338
|
|
|
98
|
-
return
|
|
339
|
+
return positions;
|
|
99
340
|
});
|
|
100
341
|
}
|
|
101
342
|
|
|
102
343
|
function mouseDownHandler(event, element) {
|
|
103
|
-
this.startHandler(event, element, (event) => {
|
|
344
|
+
this.startHandler(event, element, (event) => {
|
|
104
345
|
const mouseEvent = event, ///
|
|
105
|
-
|
|
346
|
+
positions = positionsFromMouseEvent(mouseEvent);
|
|
106
347
|
|
|
107
|
-
return
|
|
348
|
+
return positions;
|
|
108
349
|
});
|
|
109
350
|
}
|
|
110
351
|
|
|
111
352
|
function touchMoveHandler(event, element) {
|
|
112
353
|
this.moveHandler(event, element, (event) => {
|
|
113
354
|
const touchEvent = event, ///
|
|
114
|
-
|
|
355
|
+
changed = false,
|
|
356
|
+
positions = positionsFromTouchEvent(touchEvent, changed);
|
|
115
357
|
|
|
116
|
-
return
|
|
358
|
+
return positions;
|
|
117
359
|
});
|
|
118
360
|
}
|
|
119
361
|
|
|
120
362
|
function mouseMoveHandler(event, element) {
|
|
121
363
|
this.moveHandler(event, element, (event) => {
|
|
122
364
|
const mouseEvent = event, ///
|
|
123
|
-
|
|
365
|
+
positions = positionsFromMouseEvent(mouseEvent);
|
|
124
366
|
|
|
125
|
-
return
|
|
367
|
+
return positions;
|
|
126
368
|
});
|
|
127
369
|
}
|
|
128
370
|
|
|
129
371
|
function touchEndHandler(event, element) {
|
|
130
372
|
this.endHandler(event, element, (event) => {
|
|
131
373
|
const touchEvent = event, ///
|
|
132
|
-
|
|
374
|
+
changed = true,
|
|
375
|
+
positions = positionsFromTouchEvent(touchEvent, changed);
|
|
133
376
|
|
|
134
|
-
return
|
|
377
|
+
return positions;
|
|
135
378
|
});
|
|
136
379
|
}
|
|
137
380
|
|
|
138
381
|
function mouseUpHandler(event, element) {
|
|
139
|
-
this.endHandler(event, element, (event) => {
|
|
382
|
+
this.endHandler(event, element, (event) => {
|
|
140
383
|
const mouseEvent = event, ///
|
|
141
|
-
|
|
384
|
+
positions = positionsFromMouseEvent(mouseEvent);
|
|
142
385
|
|
|
143
|
-
return
|
|
386
|
+
return positions;
|
|
144
387
|
});
|
|
145
388
|
}
|
|
146
389
|
|
|
147
|
-
function startHandler(event, element,
|
|
148
|
-
const
|
|
149
|
-
|
|
390
|
+
function startHandler(event, element, positionsFromEvent) {
|
|
391
|
+
const positions = positionsFromEvent(event),
|
|
392
|
+
startPositions = this.getStartPositions();
|
|
393
|
+
|
|
394
|
+
filterPositions(startPositions, positions);
|
|
150
395
|
|
|
151
|
-
|
|
396
|
+
push(startPositions, positions);
|
|
397
|
+
|
|
398
|
+
const startingPositionsLength = startPositions.length;
|
|
399
|
+
|
|
400
|
+
if (startingPositionsLength === 1) {
|
|
401
|
+
this.dragStart(event, element);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (startingPositionsLength === 2) {
|
|
405
|
+
this.pinchStart(event, element);
|
|
406
|
+
}
|
|
152
407
|
}
|
|
153
408
|
|
|
154
|
-
function moveHandler(event, element,
|
|
155
|
-
|
|
409
|
+
function moveHandler(event, element, positionsFromEvent) {
|
|
410
|
+
const positions = positionsFromEvent(event),
|
|
411
|
+
startPositions = this.getStartPositions(),
|
|
412
|
+
movingPositions = this.getMovingPositions();
|
|
156
413
|
|
|
157
|
-
|
|
158
|
-
const position = positionFromEvent(event);
|
|
414
|
+
filterPositions(movingPositions, positions);
|
|
159
415
|
|
|
160
|
-
|
|
161
|
-
const positionMatchesStartPosition = position.match(startPosition);
|
|
416
|
+
push(movingPositions, positions);
|
|
162
417
|
|
|
163
|
-
|
|
164
|
-
const velocity = Velocity.fromPositionAndStartPosition(position, startPosition),
|
|
165
|
-
speed = velocity.getSpeed();
|
|
418
|
+
const positionsMatch = matchPositions(startPositions, movingPositions);
|
|
166
419
|
|
|
167
|
-
|
|
168
|
-
|
|
420
|
+
if (positionsMatch) {
|
|
421
|
+
sortPositions(movingPositions, startPositions);
|
|
169
422
|
|
|
170
|
-
|
|
423
|
+
const movingPositionsLength = movingPositions.length;
|
|
171
424
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
425
|
+
if (movingPositionsLength === 1) {
|
|
426
|
+
this.drag(event, element);
|
|
427
|
+
}
|
|
175
428
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
429
|
+
if (movingPositionsLength === 2) {
|
|
430
|
+
this.pinch(event, element);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function endHandler(event, element, positionsFromEvent) {
|
|
436
|
+
const positions = positionsFromEvent(event),
|
|
437
|
+
startPositions = this.getStartPositions(),
|
|
438
|
+
movingPositions = this.getMovingPositions(),
|
|
439
|
+
positionsMatch = matchPositions(startPositions, movingPositions);
|
|
179
440
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
441
|
+
if (positionsMatch) {
|
|
442
|
+
const startPositionsLength = startPositions.length,
|
|
443
|
+
movingPositionsLength = movingPositions.length;
|
|
444
|
+
|
|
445
|
+
if (movingPositionsLength === 0) {
|
|
446
|
+
this.tapOrDoubleTap(event, element);
|
|
447
|
+
} else if (startPositionsLength === 1) {
|
|
448
|
+
this.possibleTap(event, element);
|
|
449
|
+
|
|
450
|
+
this.possibleSwipe(event, element);
|
|
185
451
|
}
|
|
186
452
|
}
|
|
453
|
+
|
|
454
|
+
filterPositions(startPositions, positions);
|
|
455
|
+
|
|
456
|
+
filterPositions(movingPositions, positions);
|
|
187
457
|
}
|
|
188
458
|
|
|
189
|
-
function
|
|
190
|
-
|
|
459
|
+
function tap(event, element) {
|
|
460
|
+
const elementTarget = isElementTarget(event, element);
|
|
461
|
+
|
|
462
|
+
if (!elementTarget) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
191
465
|
|
|
192
|
-
|
|
466
|
+
const customEventType = TAP_CUSTOM_EVENT_TYPE;
|
|
193
467
|
|
|
194
|
-
|
|
195
|
-
|
|
468
|
+
this.callCustomHandlers(customEventType, event, element);
|
|
469
|
+
}
|
|
196
470
|
|
|
197
|
-
|
|
198
|
-
|
|
471
|
+
function drag(event, element) {
|
|
472
|
+
const startPositions = this.getStartPositions(),
|
|
473
|
+
movingPositions = this.getMovingPositions(),
|
|
474
|
+
firstStartPosition = first(startPositions),
|
|
475
|
+
firstMovingPosition = first(movingPositions),
|
|
476
|
+
firstPosition = firstStartPosition, ///
|
|
477
|
+
secondPosition = firstMovingPosition, ///
|
|
478
|
+
relativePosition = RelativePosition.fromFirstPositionAndSecondPosition(firstPosition, secondPosition),
|
|
479
|
+
top = relativePosition.getTop(),
|
|
480
|
+
left = relativePosition.getLeft(),
|
|
481
|
+
direction = relativePosition.getDirection();
|
|
482
|
+
|
|
483
|
+
let customEventType = null;
|
|
484
|
+
|
|
485
|
+
if ((Math.abs(direction)) < MAXIMUM_SPREAD) {
|
|
486
|
+
customEventType = DRAG_RIGHT_CUSTOM_EVENT_TYPE;
|
|
487
|
+
}
|
|
199
488
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
489
|
+
if (Math.abs(PI_OVER_TWO - direction) < MAXIMUM_SPREAD) {
|
|
490
|
+
customEventType = DRAG_UP_CUSTOM_EVENT_TYPE;
|
|
491
|
+
}
|
|
203
492
|
|
|
204
|
-
|
|
205
|
-
|
|
493
|
+
if (Math.abs(-PI_OVER_TWO - direction) < MAXIMUM_SPREAD) {
|
|
494
|
+
customEventType = DRAG_DOWN_CUSTOM_EVENT_TYPE;
|
|
495
|
+
}
|
|
206
496
|
|
|
207
|
-
|
|
208
|
-
|
|
497
|
+
if ((PI - Math.abs(direction)) < MAXIMUM_SPREAD) {
|
|
498
|
+
customEventType = DRAG_LEFT_CUSTOM_EVENT_TYPE;
|
|
499
|
+
}
|
|
209
500
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
501
|
+
if (customEventType !== null) {
|
|
502
|
+
this.callCustomHandlers(customEventType, event, element, top, left);
|
|
215
503
|
}
|
|
216
504
|
}
|
|
217
505
|
|
|
218
|
-
|
|
506
|
+
function pinch(event, element) {
|
|
507
|
+
const movingPositions = this.getMovingPositions(),
|
|
508
|
+
firstMovingPosition = first(movingPositions),
|
|
509
|
+
secondMovingPosition = second(movingPositions),
|
|
510
|
+
relativeMovingPosition = RelativePosition.fromFirstPositionAndSecondPosition(firstMovingPosition, secondMovingPosition),
|
|
511
|
+
customEventType = PINCH_MOVE_CUSTOM_EVENT_TYPE,
|
|
512
|
+
startMagnitude = this.getStartMagnitude(),
|
|
513
|
+
magnitude = relativeMovingPosition.getMagnitude(),
|
|
514
|
+
ratio = magnitude / startMagnitude;
|
|
515
|
+
|
|
516
|
+
this.callCustomHandlers(customEventType, event, element, ratio);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function swipe(event, element, speed, direction) {
|
|
520
|
+
let customEventType = null;
|
|
521
|
+
|
|
522
|
+
if ((Math.abs(direction)) < MAXIMUM_SPREAD) {
|
|
523
|
+
customEventType = SWIPE_RIGHT_CUSTOM_EVENT_TYPE;
|
|
524
|
+
|
|
525
|
+
speed = speed * Math.cos(direction);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (Math.abs(PI_OVER_TWO - direction) < MAXIMUM_SPREAD) {
|
|
529
|
+
customEventType = SWIPE_UP_CUSTOM_EVENT_TYPE;
|
|
530
|
+
|
|
531
|
+
speed = speed * Math.sin(direction);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (Math.abs(-PI_OVER_TWO - direction) < MAXIMUM_SPREAD) {
|
|
535
|
+
customEventType = SWIPE_DOWN_CUSTOM_EVENT_TYPE;
|
|
536
|
+
|
|
537
|
+
speed = speed * Math.sin(direction);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if ((PI - Math.abs(direction)) < MAXIMUM_SPREAD) {
|
|
541
|
+
customEventType = SWIPE_LEFT_CUSTOM_EVENT_TYPE;
|
|
542
|
+
|
|
543
|
+
speed = speed * Math.cos(direction);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (customEventType !== null) {
|
|
547
|
+
const startPositions = this.getStartPositions(),
|
|
548
|
+
firstStartPosition = first(startPositions),
|
|
549
|
+
startPosition = firstStartPosition, ///
|
|
550
|
+
top = startPosition.getTop(),
|
|
551
|
+
left = startPosition.getLeft();
|
|
552
|
+
|
|
553
|
+
this.callCustomHandlers(customEventType, event, element, top, left, speed);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function doubleTap(event, element) {
|
|
558
|
+
const customEventType = DOUBLE_TAP_CUSTOM_EVENT_TYPE;
|
|
559
|
+
|
|
560
|
+
this.callCustomHandlers(customEventType, event, element);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function dragStart(event, element) {
|
|
564
|
+
const customEventType = DRAG_START_CUSTOM_EVENT_TYPE;
|
|
565
|
+
|
|
566
|
+
this.callCustomHandlers(customEventType, event, element);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function pinchStart(event, element) {
|
|
570
|
+
const startPositions = this.getStartPositions(),
|
|
571
|
+
firstStartPosition = first(startPositions),
|
|
572
|
+
secondStartPosition = second(startPositions),
|
|
573
|
+
relativeStartPosition = RelativePosition.fromFirstPositionAndSecondPosition(firstStartPosition, secondStartPosition),
|
|
574
|
+
magnitude = relativeStartPosition.getMagnitude(),
|
|
575
|
+
startMagnitude = magnitude, ///
|
|
576
|
+
customEventType = PINCH_START_CUSTOM_EVENT_TYPE;
|
|
577
|
+
|
|
578
|
+
this.setStartMagnitude(startMagnitude);
|
|
579
|
+
|
|
580
|
+
this.callCustomHandlers(customEventType, event, element);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function possibleTap(event, element) {
|
|
584
|
+
const startPositions = this.getStartPositions(),
|
|
585
|
+
movingPositions = this.getMovingPositions(),
|
|
586
|
+
firstStartPosition = first(startPositions),
|
|
587
|
+
firstMovingPosition = first(movingPositions),
|
|
588
|
+
firstPosition = firstStartPosition, ///
|
|
589
|
+
secondPosition = firstMovingPosition, ///
|
|
590
|
+
relativePosition = RelativePosition.fromFirstPositionAndSecondPosition(firstPosition, secondPosition),
|
|
591
|
+
time = relativePosition.getTime(),
|
|
592
|
+
speed = relativePosition.getSpeed();
|
|
593
|
+
|
|
594
|
+
if ((speed === 0) && (time < MAXIMUM_TAP_TIME)){
|
|
595
|
+
this.tapOrDoubleTap(event, element);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function possibleSwipe(event, element) {
|
|
600
|
+
const startPositions = this.getStartPositions(),
|
|
601
|
+
movingPositions = this.getMovingPositions(),
|
|
602
|
+
firstStartPosition = first(startPositions),
|
|
603
|
+
firstMovingPosition = first(movingPositions),
|
|
604
|
+
firstPosition = firstStartPosition, ///
|
|
605
|
+
secondPosition = firstMovingPosition, ///
|
|
606
|
+
relativePosition = RelativePosition.fromFirstPositionAndSecondPosition(firstPosition, secondPosition),
|
|
607
|
+
direction = relativePosition.getDirection(),
|
|
608
|
+
speed = relativePosition.getSpeed();
|
|
609
|
+
|
|
610
|
+
if (speed > MINIMUM_SWIPE_SPEED) {
|
|
611
|
+
this.swipe(event, element, speed, direction);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function tapOrDoubleTap(event, element) {
|
|
616
|
+
let tapInterval = this.getTapInterval();
|
|
617
|
+
|
|
618
|
+
if (tapInterval !== null) {
|
|
619
|
+
clearTimeout(tapInterval);
|
|
620
|
+
|
|
621
|
+
tapInterval = null;
|
|
622
|
+
|
|
623
|
+
this.setTapInterval(tapInterval);
|
|
624
|
+
|
|
625
|
+
this.doubleTap(event, element);
|
|
626
|
+
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
tapInterval = setTimeout(() => {
|
|
631
|
+
tapInterval = null;
|
|
632
|
+
|
|
633
|
+
this.setTapInterval(tapInterval);
|
|
634
|
+
|
|
635
|
+
this.tap(event, element);
|
|
636
|
+
}, TAP_DELAY);
|
|
637
|
+
|
|
638
|
+
this.setTapInterval(tapInterval);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const touchMixins = {
|
|
219
642
|
enableTouch,
|
|
220
643
|
disableTouch,
|
|
644
|
+
onTouchStart,
|
|
645
|
+
offTouchStart,
|
|
646
|
+
onTouchMove,
|
|
647
|
+
offTouchMove,
|
|
648
|
+
onTouchEnd,
|
|
649
|
+
offTouchEnd,
|
|
221
650
|
onCustomTap,
|
|
222
651
|
offCustomTap,
|
|
652
|
+
onCustomDragUp,
|
|
653
|
+
offCustomDragUp,
|
|
654
|
+
onCustomDragDown,
|
|
655
|
+
offCustomDragDown,
|
|
656
|
+
onCustomDragLeft,
|
|
657
|
+
offCustomDragLeft,
|
|
658
|
+
onCustomDragRight,
|
|
659
|
+
offCustomDragRight,
|
|
660
|
+
onCustomDragStart,
|
|
661
|
+
offCustomDragStart,
|
|
662
|
+
onCustomSwipeUp,
|
|
663
|
+
offCustomSwipeUp,
|
|
664
|
+
onCustomSwipeDown,
|
|
665
|
+
offCustomSwipeDown,
|
|
223
666
|
onCustomSwipeLeft,
|
|
224
667
|
offCustomSwipeLeft,
|
|
225
668
|
onCustomSwipeRight,
|
|
226
669
|
offCustomSwipeRight,
|
|
227
|
-
|
|
228
|
-
|
|
670
|
+
onCustomPinchMove,
|
|
671
|
+
offCustomPinchMove,
|
|
672
|
+
onCustomPinchStart,
|
|
673
|
+
offCustomPinchStart,
|
|
674
|
+
onCustomDoubleTap,
|
|
675
|
+
offCustomDoubleTap,
|
|
676
|
+
getTapInterval,
|
|
677
|
+
setTapInterval,
|
|
678
|
+
getStartMagnitude,
|
|
679
|
+
setStartMagnitude,
|
|
680
|
+
getStartPositions,
|
|
681
|
+
setStartPositions,
|
|
682
|
+
getMovingPositions,
|
|
683
|
+
setMovingPositions,
|
|
229
684
|
touchStartHandler,
|
|
230
685
|
mouseDownHandler,
|
|
231
686
|
touchMoveHandler,
|
|
@@ -234,7 +689,30 @@ const customEventMixins = {
|
|
|
234
689
|
mouseUpHandler,
|
|
235
690
|
startHandler,
|
|
236
691
|
moveHandler,
|
|
237
|
-
endHandler
|
|
692
|
+
endHandler,
|
|
693
|
+
tap,
|
|
694
|
+
drag,
|
|
695
|
+
pinch,
|
|
696
|
+
swipe,
|
|
697
|
+
doubleTap,
|
|
698
|
+
dragStart,
|
|
699
|
+
pinchStart,
|
|
700
|
+
possibleTap,
|
|
701
|
+
possibleSwipe,
|
|
702
|
+
tapOrDoubleTap
|
|
238
703
|
};
|
|
239
704
|
|
|
240
|
-
export default
|
|
705
|
+
export default touchMixins;
|
|
706
|
+
|
|
707
|
+
function isElementTarget(event, element) {
|
|
708
|
+
if (element === window) {
|
|
709
|
+
debugger
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const { target } = event,
|
|
713
|
+
domElement = element.getDOMElement(),
|
|
714
|
+
domElementTarget = (domElement === target),
|
|
715
|
+
elementTarget = domElementTarget; ///
|
|
716
|
+
|
|
717
|
+
return elementTarget;
|
|
718
|
+
}
|