easy-gestures 2.0.5

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