vevet 5.0.10 → 5.1.0

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.
Files changed (156) hide show
  1. package/README.md +18 -16
  2. package/lib/cdn/vevet.iife.min.js +9 -9
  3. package/lib/cjs/base/Module/index.js +2 -1
  4. package/lib/cjs/base/Module/index.js.map +1 -1
  5. package/lib/cjs/components/Canvas/index.js +1 -1
  6. package/lib/cjs/components/CanvasMedia/index.js +1 -1
  7. package/lib/cjs/components/Cursor/index.js +28 -13
  8. package/lib/cjs/components/Cursor/index.js.map +1 -1
  9. package/lib/cjs/components/InView/index.js +1 -1
  10. package/lib/cjs/components/Marquee/index.js +1 -1
  11. package/lib/cjs/components/Pointers/index.js +4 -1
  12. package/lib/cjs/components/Pointers/index.js.map +1 -1
  13. package/lib/cjs/components/Preloader/index.js +1 -1
  14. package/lib/cjs/components/ProgressPreloader/index.js +1 -1
  15. package/lib/cjs/components/Raf/index.js +1 -1
  16. package/lib/cjs/components/ScrollProgress/index.js +1 -1
  17. package/lib/cjs/components/Scrollbar/index.js +2 -1
  18. package/lib/cjs/components/Scrollbar/index.js.map +1 -1
  19. package/lib/cjs/components/Snap/Slide/index.js +1 -0
  20. package/lib/cjs/components/Snap/Slide/index.js.map +1 -1
  21. package/lib/cjs/components/Snap/Swipe/index.js +120 -23
  22. package/lib/cjs/components/Snap/Swipe/index.js.map +1 -1
  23. package/lib/cjs/components/Snap/Track/index.js +12 -1
  24. package/lib/cjs/components/Snap/Track/index.js.map +1 -1
  25. package/lib/cjs/components/Snap/Wheel/index.js +247 -54
  26. package/lib/cjs/components/Snap/Wheel/index.js.map +1 -1
  27. package/lib/cjs/components/Snap/index.js +98 -40
  28. package/lib/cjs/components/Snap/index.js.map +1 -1
  29. package/lib/cjs/components/SplitText/index.js +1 -1
  30. package/lib/cjs/components/Swipe/index.js +97 -47
  31. package/lib/cjs/components/Swipe/index.js.map +1 -1
  32. package/lib/cjs/components/Timeline/index.js +1 -1
  33. package/lib/cjs/internal/mergeWithNoUndefined.js +24 -0
  34. package/lib/cjs/internal/mergeWithNoUndefined.js.map +1 -0
  35. package/lib/cjs/manifest.json +1 -1
  36. package/lib/cjs/utils/common/toPixels.js +3 -0
  37. package/lib/cjs/utils/common/toPixels.js.map +1 -1
  38. package/lib/cjs/utils/listeners/onResize.js +1 -1
  39. package/lib/cjs/utils/listeners/onResize.js.map +1 -1
  40. package/lib/cjs/utils/math/clamp.js +3 -1
  41. package/lib/cjs/utils/math/clamp.js.map +1 -1
  42. package/lib/cjs/utils/math/inRange.js +4 -4
  43. package/lib/esm/base/Module/index.js +2 -1
  44. package/lib/esm/base/Module/index.js.map +1 -1
  45. package/lib/esm/components/Canvas/index.js +1 -1
  46. package/lib/esm/components/CanvasMedia/index.js +1 -1
  47. package/lib/esm/components/Cursor/index.js +28 -13
  48. package/lib/esm/components/Cursor/index.js.map +1 -1
  49. package/lib/esm/components/InView/index.js +1 -1
  50. package/lib/esm/components/Marquee/index.js +1 -1
  51. package/lib/esm/components/Pointers/index.js +4 -1
  52. package/lib/esm/components/Pointers/index.js.map +1 -1
  53. package/lib/esm/components/Preloader/index.js +1 -1
  54. package/lib/esm/components/ProgressPreloader/index.js +1 -1
  55. package/lib/esm/components/Raf/index.js +1 -1
  56. package/lib/esm/components/ScrollProgress/index.js +1 -1
  57. package/lib/esm/components/Scrollbar/index.js +2 -1
  58. package/lib/esm/components/Scrollbar/index.js.map +1 -1
  59. package/lib/esm/components/Snap/Slide/index.js +1 -0
  60. package/lib/esm/components/Snap/Slide/index.js.map +1 -1
  61. package/lib/esm/components/Snap/Swipe/index.js +104 -23
  62. package/lib/esm/components/Snap/Swipe/index.js.map +1 -1
  63. package/lib/esm/components/Snap/Track/index.js +12 -1
  64. package/lib/esm/components/Snap/Track/index.js.map +1 -1
  65. package/lib/esm/components/Snap/Wheel/index.js +224 -55
  66. package/lib/esm/components/Snap/Wheel/index.js.map +1 -1
  67. package/lib/esm/components/Snap/index.js +84 -29
  68. package/lib/esm/components/Snap/index.js.map +1 -1
  69. package/lib/esm/components/SplitText/index.js +1 -1
  70. package/lib/esm/components/Swipe/index.js +93 -43
  71. package/lib/esm/components/Swipe/index.js.map +1 -1
  72. package/lib/esm/components/Timeline/index.js +1 -1
  73. package/lib/esm/internal/mergeWithNoUndefined.js +10 -0
  74. package/lib/esm/internal/mergeWithNoUndefined.js.map +1 -0
  75. package/lib/esm/manifest.json +1 -1
  76. package/lib/esm/utils/common/toPixels.js +3 -0
  77. package/lib/esm/utils/common/toPixels.js.map +1 -1
  78. package/lib/esm/utils/listeners/onResize.js +1 -1
  79. package/lib/esm/utils/listeners/onResize.js.map +1 -1
  80. package/lib/esm/utils/math/clamp.js +3 -1
  81. package/lib/esm/utils/math/clamp.js.map +1 -1
  82. package/lib/esm/utils/math/inRange.js +4 -4
  83. package/lib/types/base/Module/index.d.ts.map +1 -1
  84. package/lib/types/components/Canvas/index.d.ts +1 -1
  85. package/lib/types/components/CanvasMedia/index.d.ts +1 -1
  86. package/lib/types/components/Cursor/index.d.ts +5 -1
  87. package/lib/types/components/Cursor/index.d.ts.map +1 -1
  88. package/lib/types/components/InView/index.d.ts +1 -1
  89. package/lib/types/components/Marquee/index.d.ts +1 -1
  90. package/lib/types/components/Pointers/index.d.ts +1 -1
  91. package/lib/types/components/Pointers/index.d.ts.map +1 -1
  92. package/lib/types/components/Preloader/index.d.ts +1 -1
  93. package/lib/types/components/ProgressPreloader/index.d.ts +1 -1
  94. package/lib/types/components/Raf/index.d.ts +1 -1
  95. package/lib/types/components/ScrollProgress/index.d.ts +1 -1
  96. package/lib/types/components/Scrollbar/index.d.ts +1 -1
  97. package/lib/types/components/Scrollbar/index.d.ts.map +1 -1
  98. package/lib/types/components/Snap/Slide/index.d.ts.map +1 -1
  99. package/lib/types/components/Snap/Swipe/index.d.ts +12 -1
  100. package/lib/types/components/Snap/Swipe/index.d.ts.map +1 -1
  101. package/lib/types/components/Snap/Swipe/types.d.ts +10 -0
  102. package/lib/types/components/Snap/Swipe/types.d.ts.map +1 -1
  103. package/lib/types/components/Snap/Track/index.d.ts +2 -0
  104. package/lib/types/components/Snap/Track/index.d.ts.map +1 -1
  105. package/lib/types/components/Snap/Wheel/index.d.ts +28 -6
  106. package/lib/types/components/Snap/Wheel/index.d.ts.map +1 -1
  107. package/lib/types/components/Snap/Wheel/types.d.ts +9 -3
  108. package/lib/types/components/Snap/Wheel/types.d.ts.map +1 -1
  109. package/lib/types/components/Snap/index.d.ts +12 -8
  110. package/lib/types/components/Snap/index.d.ts.map +1 -1
  111. package/lib/types/components/Snap/types.d.ts +19 -5
  112. package/lib/types/components/Snap/types.d.ts.map +1 -1
  113. package/lib/types/components/SplitText/index.d.ts +1 -1
  114. package/lib/types/components/Swipe/index.d.ts +3 -7
  115. package/lib/types/components/Swipe/index.d.ts.map +1 -1
  116. package/lib/types/components/Swipe/types.d.ts +16 -2
  117. package/lib/types/components/Swipe/types.d.ts.map +1 -1
  118. package/lib/types/components/Timeline/index.d.ts +1 -1
  119. package/lib/types/internal/mergeWithNoUndefined.d.ts +2 -0
  120. package/lib/types/internal/mergeWithNoUndefined.d.ts.map +1 -0
  121. package/lib/types/utils/common/toPixels.d.ts.map +1 -1
  122. package/lib/types/utils/listeners/onResize.d.ts +1 -0
  123. package/lib/types/utils/listeners/onResize.d.ts.map +1 -1
  124. package/lib/types/utils/math/clamp.d.ts.map +1 -1
  125. package/lib/types/utils/math/inRange.d.ts +4 -4
  126. package/package.json +1 -1
  127. package/src/base/Module/index.ts +8 -5
  128. package/src/components/Canvas/index.ts +1 -1
  129. package/src/components/CanvasMedia/index.ts +1 -1
  130. package/src/components/Cursor/index.ts +35 -15
  131. package/src/components/InView/index.ts +1 -1
  132. package/src/components/Marquee/index.ts +1 -1
  133. package/src/components/Pointers/index.ts +5 -1
  134. package/src/components/Preloader/index.ts +1 -1
  135. package/src/components/ProgressPreloader/index.ts +1 -1
  136. package/src/components/Raf/index.ts +1 -1
  137. package/src/components/ScrollProgress/index.ts +1 -1
  138. package/src/components/Scrollbar/index.ts +2 -1
  139. package/src/components/Snap/Slide/index.ts +1 -0
  140. package/src/components/Snap/Swipe/index.ts +138 -25
  141. package/src/components/Snap/Swipe/types.ts +12 -0
  142. package/src/components/Snap/Track/index.ts +15 -1
  143. package/src/components/Snap/Wheel/index.ts +291 -60
  144. package/src/components/Snap/Wheel/types.ts +10 -3
  145. package/src/components/Snap/index.ts +81 -39
  146. package/src/components/Snap/types.ts +24 -5
  147. package/src/components/SplitText/index.ts +1 -1
  148. package/src/components/Swipe/index.ts +123 -55
  149. package/src/components/Swipe/types.ts +20 -2
  150. package/src/components/Timeline/index.ts +1 -1
  151. package/src/internal/mergeWithNoUndefined.ts +20 -0
  152. package/src/manifest.json +1 -1
  153. package/src/utils/common/toPixels.ts +2 -0
  154. package/src/utils/listeners/onResize.ts +2 -1
  155. package/src/utils/math/clamp.ts +4 -1
  156. package/src/utils/math/inRange.ts +4 -4
@@ -1,5 +1,6 @@
1
1
  import { Snap } from '..';
2
- import { ISwipeCoords, Swipe } from '@/components/Swipe';
2
+ import { ISwipeCoords, ISwipeMatrix, Swipe } from '@/components/Swipe';
3
+ import { clamp } from '@/utils';
3
4
 
4
5
  export class SnapSwipe {
5
6
  /** Swipe events */
@@ -14,22 +15,32 @@ export class SnapSwipe {
14
15
  constructor(protected snap: Snap) {
15
16
  snap.on('destroy', () => this._destroy(), { protected: true });
16
17
 
17
- this._startIndex = snap.activeIndex;
18
+ const { props, activeIndex } = snap;
19
+
20
+ this._startIndex = activeIndex;
18
21
  this._startTime = 0;
19
22
 
20
23
  this._swipe = new Swipe({
21
24
  container: snap.eventsEmitter,
22
- enabled: snap.props.swipe,
23
- grabCursor: snap.props.grabCursor,
24
- minTime: snap.props.swipeMinTime,
25
- threshold: snap.props.swipeThreshold,
25
+ enabled: props.swipe,
26
+ grabCursor: props.grabCursor,
27
+ minTime: props.swipeMinTime,
28
+ threshold: props.swipeThreshold,
26
29
  axis: this.axis,
27
- inertia: snap.props.freemode,
30
+ inertia: false,
31
+ inertiaDuration: props.swipeInertiaDuration,
32
+ inertiaRatio: props.swipeInertiaRatio,
33
+ velocityModifier: this._handleVelocityModifier.bind(this),
34
+ inertiaDistanceThreshold: 5,
28
35
  });
29
36
 
30
37
  this._swipe.on('start', (data) => this._handleSwipeStart(data));
31
38
  this._swipe.on('move', (data) => this._handleSwipeMove(data));
32
39
  this._swipe.on('end', (data) => this._handleSwipeEnd(data));
40
+ this._swipe.on('inertiaStart', () => this._handleSwipeInertiaStart());
41
+ this._swipe.on('inertiaEnd', () => this._handleSwipeInertiaEnd());
42
+ this._swipe.on('inertiaFail', () => this._handleSwipeInertiaFail());
43
+ this._swipe.on('inertiaCancel', () => this._handleSwipeInertiaCancel());
33
44
 
34
45
  // on props change
35
46
  snap.on(
@@ -41,7 +52,8 @@ export class SnapSwipe {
41
52
  minTime: snap.props.swipeMinTime,
42
53
  threshold: snap.props.swipeThreshold,
43
54
  axis: this.axis,
44
- inertia: snap.props.freemode,
55
+ inertiaDuration: snap.props.swipeInertiaDuration,
56
+ inertiaRatio: snap.props.swipeInertiaRatio,
45
57
  });
46
58
  },
47
59
  { protected: true },
@@ -60,6 +72,11 @@ export class SnapSwipe {
60
72
  return this._swipe.isSwiping;
61
73
  }
62
74
 
75
+ /** Check if inertia is active */
76
+ get hasInertia() {
77
+ return this._swipe.hasInertia;
78
+ }
79
+
63
80
  /** Detect if swipe is short */
64
81
  get isShort() {
65
82
  const { props } = this.snap;
@@ -83,6 +100,47 @@ export class SnapSwipe {
83
100
  return this.axis === 'x' ? this._swipe.diff.x : this._swipe.diff.y;
84
101
  }
85
102
 
103
+ protected _handleVelocityModifier(source: ISwipeMatrix) {
104
+ const { props, track, activeSlide, domSize } = this.snap;
105
+ const { coord, size: slideSize } = activeSlide;
106
+
107
+ // Simple freemode
108
+
109
+ if (props.freemode === true) {
110
+ return source;
111
+ }
112
+
113
+ // Update target coordinate
114
+
115
+ track.target = track.current;
116
+
117
+ // Sticky freemode
118
+
119
+ if (props.freemode === 'sticky' && !track.isSlideScrolling) {
120
+ const virtualCoord = track.loopedCurrent - source[this.axis];
121
+
122
+ const magnet = this.snap.getNearestMagnet(virtualCoord);
123
+
124
+ if (!magnet) {
125
+ return source;
126
+ }
127
+
128
+ const newVelocity = track.loopedCurrent - virtualCoord - magnet.diff;
129
+
130
+ return {
131
+ ...source,
132
+ [this.axis]: newVelocity,
133
+ };
134
+ }
135
+
136
+ // Freemode: false, when slides are scrolled
137
+
138
+ const value = clamp(source[this.axis], -coord, domSize - slideSize - coord);
139
+ const output = { ...source, [this.axis]: value };
140
+
141
+ return output;
142
+ }
143
+
86
144
  /**
87
145
  * Handles swipe `start` event.
88
146
  */
@@ -109,26 +167,28 @@ export class SnapSwipe {
109
167
  */
110
168
  protected _handleSwipeMove(coords: ISwipeCoords) {
111
169
  const { snap } = this;
112
- const { swipeSpeed, followSwipe: shouldFollow } = snap.props;
170
+ const { props, track, callbacks } = snap;
171
+ const { followSwipe: shouldFollow } = props;
113
172
 
114
- if (!shouldFollow) {
173
+ if (!shouldFollow && !track.isSlideScrolling) {
115
174
  return;
116
175
  }
117
176
 
118
- // Normalize wheel data
177
+ // Normalize swipe delta
119
178
  const swipeDelta = this.axis === 'x' ? coords.step.x : coords.step.y;
120
- const delta = swipeDelta * -swipeSpeed;
179
+ const speed = this.hasInertia ? 1 : props.swipeSpeed;
180
+ const delta = swipeDelta * -speed;
121
181
 
122
182
  // Update track target
123
- snap.track.iterateTarget(delta);
183
+ track.iterateTarget(delta);
124
184
 
125
- // Clamp target if inertia active
185
+ // Clamp target if inertia is animating
126
186
  if (this._swipe.hasInertia) {
127
- snap.track.clampTarget();
187
+ track.clampTarget();
128
188
  }
129
189
 
130
190
  // Emit move callbacks
131
- snap.callbacks.emit('swipe', coords);
191
+ callbacks.emit('swipe', coords);
132
192
  }
133
193
 
134
194
  /** Handles swipe `end` event */
@@ -142,18 +202,46 @@ export class SnapSwipe {
142
202
  this.snap.callbacks.emit('swipeEnd', coords);
143
203
  }
144
204
 
205
+ /** Handles swipe inertia start */
206
+ protected _handleSwipeInertiaStart() {
207
+ this.snap.callbacks.emit('swipeInertiaStart', undefined);
208
+ }
209
+
210
+ /** Handles swipe inertia end */
211
+ protected _handleSwipeInertiaEnd() {
212
+ this.snap.callbacks.emit('swipeInertiaEnd', undefined);
213
+ }
214
+
215
+ /** Handles swipe inertia fail */
216
+ protected _handleSwipeInertiaFail() {
217
+ const { snap } = this;
218
+
219
+ if (snap.props.freemode === 'sticky' && !snap.track.isSlideScrolling) {
220
+ if (this.isShort) {
221
+ this._endShort();
222
+ } else {
223
+ snap.stick();
224
+ }
225
+ }
226
+
227
+ this.snap.callbacks.emit('swipeInertiaFail', undefined);
228
+ }
229
+
230
+ /** Handles swipe inertia cancel */
231
+ protected _handleSwipeInertiaCancel() {
232
+ this.snap.callbacks.emit('swipeInertiaCancel', undefined);
233
+ }
234
+
145
235
  /** End swipe action */
146
236
  protected _end() {
147
237
  const { snap, _swipe: swipe } = this;
148
238
  const { props, track } = snap;
149
239
 
150
- if (!props.followSwipe) {
151
- this._endNoFollow();
152
-
153
- return;
154
- }
155
-
240
+ // Handle freemode
156
241
  if (props.freemode) {
242
+ this._swipe.updateProps({ inertia: true });
243
+
244
+ // Clamp & stick if out of bounds
157
245
  if (
158
246
  !track.canLoop &&
159
247
  (track.target < track.min || track.target > track.max)
@@ -162,18 +250,43 @@ export class SnapSwipe {
162
250
  snap.stick();
163
251
  }
164
252
 
253
+ // End short swipe
254
+ if (this.isShort && props.freemode === 'sticky') {
255
+ this._swipe.updateProps({ inertia: false });
256
+ swipe.cancelInertia();
257
+
258
+ this._endShort();
259
+ }
260
+
165
261
  return;
166
262
  }
167
263
 
168
- if (snap.track.isSlideScrolling) {
264
+ // Enable inertia if active slide is being scrolled
265
+ if (track.isSlideScrolling) {
266
+ this._swipe.updateProps({ inertia: true });
267
+
169
268
  return;
170
269
  }
171
270
 
271
+ // Disable inertia
272
+ this._swipe.updateProps({ inertia: false });
273
+
274
+ // Return if followSwipe is disabled
275
+ if (!props.followSwipe) {
276
+ this._endNoFollow();
277
+
278
+ return;
279
+ }
280
+
281
+ // Short swipe
172
282
  if (this.isShort) {
173
283
  this._endShort();
174
- } else {
175
- snap.stick();
284
+
285
+ return;
176
286
  }
287
+
288
+ // Or just stick to the nearest slide
289
+ snap.stick();
177
290
  }
178
291
 
179
292
  /** End short swipe */
@@ -71,4 +71,16 @@ export interface ISnapSwipeProps {
71
71
  * @default 0
72
72
  */
73
73
  swipeMinTime?: number;
74
+
75
+ /**
76
+ * Inertia duration.
77
+ * @default `(distance) => clamp(distance, 500, 2000)`
78
+ */
79
+ swipeInertiaDuration?: (distance: number) => number;
80
+
81
+ /**
82
+ * Inertia strength.
83
+ * @default 0.3
84
+ */
85
+ swipeInertiaRatio?: number;
74
86
  }
@@ -44,7 +44,7 @@ export class SnapTrack {
44
44
 
45
45
  /** Get looped current value */
46
46
  get loopedCurrent() {
47
- return this.canLoop ? loop(this.current, this.min, this.max) : this.current;
47
+ return this.loopCoord(this.current);
48
48
  }
49
49
 
50
50
  /** Get track offset */
@@ -59,6 +59,11 @@ export class SnapTrack {
59
59
  return Math.floor(this.current / this.max);
60
60
  }
61
61
 
62
+ /** Loop a coordinate if can loop */
63
+ public loopCoord(coord: number) {
64
+ return this.canLoop ? loop(coord, this.min, this.max) : coord;
65
+ }
66
+
62
67
  /** Interpolate the current track value */
63
68
  public lerp(factor: number) {
64
69
  let { target } = this;
@@ -83,6 +88,15 @@ export class SnapTrack {
83
88
 
84
89
  // Interpolate current value
85
90
 
91
+ const rest = Math.abs(this.current - target);
92
+ const fastThreshold = 5;
93
+
94
+ if (rest < fastThreshold) {
95
+ const fastProgress = 1 - rest / fastThreshold;
96
+ const additionalFactor = (1 - factor) / 3;
97
+ factor += additionalFactor * fastProgress;
98
+ }
99
+
86
100
  this.current = lerp(this.current, target, factor, 0.000001);
87
101
  }
88
102