1 | 'use strict';
|
2 |
|
3 | const helpers = require('./helpers-d381ec4d.js');
|
4 | const index = require('./index-a1dd5c93.js');
|
5 | require('./gesture-controller-29adda71.js');
|
6 |
|
7 | const createSwipeBackGesture = (el, canStartHandler, onStartHandler, onMoveHandler, onEndHandler) => {
|
8 | const win = el.ownerDocument.defaultView;
|
9 | const canStart = (detail) => {
|
10 | return detail.startX <= 50 && canStartHandler();
|
11 | };
|
12 | const onMove = (detail) => {
|
13 |
|
14 | const delta = detail.deltaX;
|
15 | const stepValue = delta / win.innerWidth;
|
16 | onMoveHandler(stepValue);
|
17 | };
|
18 | const onEnd = (detail) => {
|
19 |
|
20 | const delta = detail.deltaX;
|
21 | const width = win.innerWidth;
|
22 | const stepValue = delta / width;
|
23 | const velocity = detail.velocityX;
|
24 | const z = width / 2.0;
|
25 | const shouldComplete = velocity >= 0 && (velocity > 0.2 || detail.deltaX > z);
|
26 | const missing = shouldComplete ? 1 - stepValue : stepValue;
|
27 | const missingDistance = missing * width;
|
28 | let realDur = 0;
|
29 | if (missingDistance > 5) {
|
30 | const dur = missingDistance / Math.abs(velocity);
|
31 | realDur = Math.min(dur, 540);
|
32 | }
|
33 | |
34 |
|
35 |
|
36 |
|
37 |
|
38 | onEndHandler(shouldComplete, (stepValue <= 0) ? 0.01 : helpers.clamp(0, stepValue, 0.9999), realDur);
|
39 | };
|
40 | return index.createGesture({
|
41 | el,
|
42 | gestureName: 'goback-swipe',
|
43 | gesturePriority: 40,
|
44 | threshold: 10,
|
45 | canStart,
|
46 | onStart: onStartHandler,
|
47 | onMove,
|
48 | onEnd
|
49 | });
|
50 | };
|
51 |
|
52 | exports.createSwipeBackGesture = createSwipeBackGesture;
|