6
6
DragConfig ,
7
7
Tuple ,
8
8
GestureOptions ,
9
- DragOptions ,
10
9
InternalDragOptions ,
11
10
InternalGestureOptions ,
12
11
CoordinatesConfig ,
@@ -18,9 +17,15 @@ import {
18
17
19
18
const DEFAULT_DRAG_DELAY = 180
20
19
const DEFAULT_RUBBERBAND = 0.15
20
+ const DEFAULT_SWIPE_VELOCITY = 0.5
21
+ const DEFAULT_SWIPE_DISTANCE = 60
21
22
22
- function getWindow ( ) {
23
- return typeof window !== 'undefined' ? window : undefined
23
+ const defaultWindow = typeof window !== 'undefined' ? window : undefined
24
+
25
+ const defaultCoordinatesOptions : CoordinatesOptions = {
26
+ lockDirection : false ,
27
+ axis : undefined ,
28
+ bounds : undefined ,
24
29
}
25
30
26
31
/**
@@ -32,38 +37,28 @@ function getWindow() {
32
37
* @returns {InternalGenericOptions }
33
38
*/
34
39
export function getInternalGenericOptions ( config : Partial < GenericOptions > = { } ) : InternalGenericOptions {
35
- const defaultOptions : GenericOptions = {
36
- domTarget : undefined ,
37
- eventOptions : { passive : true , capture : false , pointer : false } ,
38
- window : getWindow ( ) ,
39
- enabled : true ,
40
- }
41
-
42
- const { eventOptions : defaultEventOptions , window : defaultWindow , ...restDefault } = defaultOptions
43
- const { eventOptions, window, ...restConfig } = config
44
- const { passive, capture, pointer } = { ...defaultEventOptions , ...eventOptions }
40
+ let {
41
+ eventOptions : { passive = true , capture = false , pointer = false } = { } ,
42
+ window = defaultWindow ,
43
+ domTarget = undefined ,
44
+ enabled = true ,
45
+ ...restConfig
46
+ } = config
45
47
46
48
return {
47
- ...restDefault ,
48
49
...restConfig ,
49
- window : window || defaultWindow ,
50
+ enabled,
51
+ domTarget,
52
+ window,
50
53
// passive is always true if there's no domTarget
51
- eventOptions : { passive : ! config . domTarget || ! ! passive , capture : ! ! capture } ,
54
+ eventOptions : { passive : ! domTarget || ! ! passive , capture : ! ! capture } ,
52
55
captureString : capture ? 'Capture' : '' ,
53
56
pointer : ! ! pointer ,
54
57
}
55
58
}
56
59
57
60
export function getInternalGestureOptions ( gestureConfig : Partial < GestureOptions > ) : InternalGestureOptions {
58
- const defaultGestureOptions : GestureOptions = {
59
- enabled : true ,
60
- initial : [ 0 , 0 ] ,
61
- threshold : undefined ,
62
- rubberband : 0 ,
63
- }
64
-
65
- const config = { ...defaultGestureOptions , ...gestureConfig }
66
- let { threshold, rubberband, enabled, initial } = config
61
+ let { threshold = undefined , rubberband = 0 , enabled = true , initial = [ 0 , 0 ] } = gestureConfig
67
62
68
63
if ( typeof rubberband === 'boolean' ) rubberband = rubberband ? DEFAULT_RUBBERBAND : 0
69
64
if ( threshold === void 0 ) threshold = 0
@@ -77,12 +72,6 @@ export function getInternalGestureOptions(gestureConfig: Partial<GestureOptions>
77
72
}
78
73
79
74
export function getInternalCoordinatesOptions ( coordinatesConfig : CoordinatesConfig = { } ) : InternalCoordinatesOptions {
80
- const defaultCoordinatesOptions : CoordinatesOptions = {
81
- lockDirection : false ,
82
- axis : undefined ,
83
- bounds : undefined ,
84
- }
85
-
86
75
const { axis, lockDirection, bounds = { } , ...internalOptions } = coordinatesConfig
87
76
88
77
const boundsArray = [
@@ -115,18 +104,15 @@ export function getInternalDistanceAngleOptions(
115
104
}
116
105
117
106
export function getInternalDragOptions ( dragConfig : DragConfig = { } ) : InternalDragOptions {
118
- const defaultDragOptions : DragOptions = {
119
- filterTaps : false ,
120
- swipeVelocity : 0.5 ,
121
- swipeDistance : 60 ,
122
- delay : false ,
123
- }
124
-
125
107
let { enabled, threshold, bounds, rubberband, initial, ...dragOptions } = dragConfig
126
- let { swipeVelocity, swipeDistance, delay, filterTaps, axis, lockDirection } = {
127
- ...defaultDragOptions ,
128
- ...dragOptions ,
129
- }
108
+ let {
109
+ swipeVelocity = DEFAULT_SWIPE_VELOCITY ,
110
+ swipeDistance = DEFAULT_SWIPE_DISTANCE ,
111
+ delay = false ,
112
+ filterTaps = false ,
113
+ axis,
114
+ lockDirection,
115
+ } = dragOptions
130
116
131
117
if ( threshold === void 0 ) {
132
118
threshold = Math . max ( 0 , filterTaps ? 3 : 0 , lockDirection || axis ? 1 : 0 )
0 commit comments