@creative-web-solution/front-library 7.0.7 → 7.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 (141) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/DOM/Class.ts +10 -12
  3. package/DOM/DocumentSize.ts +3 -1
  4. package/DOM/Filter.ts +0 -2
  5. package/DOM/Index.ts +1 -3
  6. package/DOM/Manipulation.ts +0 -3
  7. package/DOM/Matrix.ts +12 -12
  8. package/DOM/Offset.ts +4 -5
  9. package/DOM/OuterSize.ts +12 -12
  10. package/DOM/PageToDOM.ts +2 -2
  11. package/DOM/Position.ts +3 -3
  12. package/DOM/Size.ts +3 -7
  13. package/DOM/StrToDOM.ts +0 -1
  14. package/DOM/Styles.ts +3 -12
  15. package/DOM/Traversing.ts +0 -6
  16. package/DOM/WindowScroll.ts +3 -1
  17. package/DOM/WindowSize.ts +3 -1
  18. package/DOM/Wrap.ts +0 -1
  19. package/Events/DeviceOrientation.ts +27 -31
  20. package/Events/EventsManager.ts +10 -25
  21. package/Events/Gesture.ts +36 -37
  22. package/Events/HistoryController.ts +11 -17
  23. package/Events/ImageLoad.ts +35 -19
  24. package/Events/IntersectObserver.ts +15 -19
  25. package/Events/KeyboardHandler.ts +10 -8
  26. package/Events/MediaQueriesEvents.ts +53 -51
  27. package/Events/OnAnimationEnd.ts +2 -3
  28. package/Events/OnTransitionEnd.ts +3 -3
  29. package/Events/PubSub.ts +5 -8
  30. package/Events/TouchHover.ts +18 -21
  31. package/Events/WindowEvents.ts +26 -30
  32. package/Helpers/Colors.ts +7 -23
  33. package/Helpers/Cookie.ts +5 -12
  34. package/Helpers/Coordinates.ts +0 -7
  35. package/Helpers/Debounce.ts +3 -7
  36. package/Helpers/Defer.ts +1 -1
  37. package/Helpers/GetValue.ts +0 -2
  38. package/Helpers/Insert.ts +0 -1
  39. package/Helpers/Sequential.ts +0 -2
  40. package/Helpers/Slice.ts +0 -3
  41. package/Helpers/Throttle.ts +0 -1
  42. package/Helpers/TransitionHelpers.ts +8 -6
  43. package/Helpers/Type.ts +1 -14
  44. package/Helpers/Unique.ts +3 -3
  45. package/Helpers/UrlParser.ts +13 -22
  46. package/Helpers/Wait.ts +1 -1
  47. package/Modules/Accordion/Tab.ts +18 -16
  48. package/Modules/Accordion/index.ts +24 -16
  49. package/Modules/Autocomplete.ts +95 -101
  50. package/Modules/DragSlider.ts +72 -63
  51. package/Modules/GlobalState.ts +60 -53
  52. package/Modules/LoadGMap.ts +4 -7
  53. package/Modules/Notifications/Notification.ts +28 -32
  54. package/Modules/Notifications/index.ts +43 -36
  55. package/Modules/Popin/Popin.ts +100 -110
  56. package/Modules/Popin/PopinAccessibility.ts +8 -8
  57. package/Modules/Popin/PopinBackground.ts +11 -11
  58. package/Modules/Popin/PopinController.ts +23 -29
  59. package/Modules/Popin/Tools.ts +18 -19
  60. package/Modules/QuickTemplate.ts +4 -6
  61. package/Modules/ScrollSnap.ts +110 -104
  62. package/Modules/SkinCheckbox.ts +51 -37
  63. package/Modules/SkinFile.ts +62 -52
  64. package/Modules/SkinRadio.ts +62 -42
  65. package/Modules/SkinSelect.ts +116 -100
  66. package/Modules/Slider/Slide.ts +49 -52
  67. package/Modules/Slider/Slider.ts +100 -136
  68. package/Modules/Slider/SliderControls.ts +60 -59
  69. package/Modules/Tabs/Tab.ts +27 -23
  70. package/Modules/Tabs/index.ts +35 -25
  71. package/Modules/Validator/Date.ts +2 -1
  72. package/Modules/Validator/Equals.ts +1 -1
  73. package/Modules/Validator/Internal/Input.ts +370 -0
  74. package/Modules/Validator/Internal/InputValidator.ts +99 -0
  75. package/Modules/Validator/Internal/ValidatorFunctionsController.ts +58 -0
  76. package/Modules/Validator/Max.ts +1 -1
  77. package/Modules/Validator/Min.ts +1 -1
  78. package/Modules/Validator/MultiRequired.ts +5 -5
  79. package/Modules/Validator/Number.ts +1 -0
  80. package/Modules/Validator/Pattern.ts +1 -1
  81. package/Modules/Validator/Recaptcha.ts +1 -0
  82. package/Modules/Validator/Required.ts +3 -2
  83. package/Modules/Validator/ServerCheck.ts +23 -15
  84. package/Modules/Validator/Tools/GetQueryFromForm.ts +1 -6
  85. package/Modules/Validator/Tools/IsDate.ts +2 -3
  86. package/Modules/Validator/Tools/IsEmail.ts +2 -5
  87. package/Modules/Validator/Tools/IsEmpty.ts +0 -2
  88. package/Modules/Validator/Tools/IsNumber.ts +0 -2
  89. package/Modules/Validator/Tools/IsUrl.ts +1 -3
  90. package/Modules/Validator/Tools/Label.ts +5 -15
  91. package/Modules/Validator/Tools/RadioButton.ts +4 -10
  92. package/Modules/Validator/Url.ts +1 -0
  93. package/Modules/Validator/index.ts +36 -36
  94. package/Modules/YouTubePlayer.ts +18 -16
  95. package/README.md +1 -1
  96. package/Types/Accordion.d.ts +36 -0
  97. package/Types/Autocomplete.d.ts +95 -0
  98. package/Types/DOM.d.ts +69 -0
  99. package/Types/DragSlider.d.ts +56 -0
  100. package/Types/EventsHelpers.d.ts +390 -0
  101. package/Types/GLImageTransition.d.ts +47 -43
  102. package/Types/GlobalState.d.ts +9 -0
  103. package/Types/Helpers.d.ts +30 -0
  104. package/Types/Notifications.d.ts +48 -44
  105. package/Types/Popin.d.ts +95 -0
  106. package/Types/ScrollSnap.d.ts +66 -0
  107. package/Types/SkinCheckbox.d.ts +26 -0
  108. package/Types/SkinFile.d.ts +38 -0
  109. package/Types/SkinRadio.d.ts +28 -0
  110. package/Types/SkinSelect.d.ts +59 -0
  111. package/Types/Slider.d.ts +106 -0
  112. package/Types/Tabs.d.ts +26 -0
  113. package/Types/Validator.d.ts +72 -0
  114. package/Types/YouTubePlayer.d.ts +27 -0
  115. package/Types/index.d.ts +22 -21
  116. package/WebGL/GLImageTransition/GLImageTransition.ts +83 -80
  117. package/WebGL/GLImageTransition/Presets/Cellular.ts +11 -11
  118. package/WebGL/GLImageTransition/Presets/Fade.ts +2 -3
  119. package/WebGL/GLImageTransition/Presets/HorizontalMovingGrid.ts +9 -9
  120. package/WebGL/GLImageTransition/Presets/PresetSample.ts +11 -9
  121. package/WebGL/GLImageTransition/Presets/Solarisation.ts +7 -12
  122. package/package.json +1 -1
  123. package/Modules/Template.ts +0 -209
  124. package/Types/AccordionTypes.d.ts +0 -29
  125. package/Types/AutocompleteTypes.d.ts +0 -85
  126. package/Types/DOMTypes.d.ts +0 -62
  127. package/Types/DragSliderTypes.d.ts +0 -52
  128. package/Types/EventsHelpersTypes.d.ts +0 -370
  129. package/Types/GlobalStateTypes.d.ts +0 -5
  130. package/Types/HelpersTypes.d.ts +0 -23
  131. package/Types/MediaPreloaderTypes.d.ts +0 -12
  132. package/Types/PopinTypes.d.ts +0 -83
  133. package/Types/ScrollSnapTypes.d.ts +0 -62
  134. package/Types/SkinCheckboxTypes.d.ts +0 -23
  135. package/Types/SkinFileTypes.d.ts +0 -34
  136. package/Types/SkinRadioTypes.d.ts +0 -24
  137. package/Types/SkinSelectTypes.d.ts +0 -48
  138. package/Types/SliderTypes.d.ts +0 -97
  139. package/Types/TabsTypes.d.ts +0 -22
  140. package/Types/ValidatorTypes.d.ts +0 -61
  141. package/Types/YouTubePlayerTypes.d.ts +0 -23
@@ -8,7 +8,7 @@ import { position } from '../DOM/Position';
8
8
  import { width, height } from '../DOM/Size';
9
9
 
10
10
 
11
- const defaultOptions: ScrollSnapOptionsType = {
11
+ const defaultOptions: FLib.ScrollSnap.Options = {
12
12
  "lockedClass": "locked",
13
13
  "minItemsToActivate": 2,
14
14
  "direction": "h",
@@ -39,21 +39,21 @@ class ScrollTo {
39
39
  #animationFrame;
40
40
  #duration!: number;
41
41
  #startPosition!: number;
42
- #snapItem!: ScrollSnapItemType;
43
- #snapItemType!: ScrollSnapSnapType;
44
- #scrollPropName: ScrollSnapScrollPropertyType;
42
+ #snapItem!: FLib.ScrollSnap.Item;
43
+ #snapItemType!: FLib.ScrollSnap.SnapType;
44
+ #scrollPropName: FLib.ScrollSnap.ScrollPropertyType;
45
45
  #$element: HTMLElement;
46
- #callback: ScrollToCallbackType;
46
+ #callback: FLib.ScrollSnap.ScrollToCallback;
47
47
 
48
48
 
49
- constructor( $element: HTMLElement, direction: ScrollSnapDirectionType, callback: ScrollToCallbackType ) {
49
+ constructor( $element: HTMLElement, direction: FLib.ScrollSnap.DirectionType, callback: FLib.ScrollSnap.ScrollToCallback ) {
50
50
  this.#$element = $element;
51
51
  this.#callback = callback;
52
52
  this.#scrollPropName = direction === 'v' ? 'scrollTop' : 'scrollLeft';
53
53
  }
54
54
 
55
55
 
56
- private step( timestamp: number ) {
56
+ #step = ( timestamp: number ) => {
57
57
  if ( !this.#startTime ) {
58
58
  this.#startTime = timestamp;
59
59
  }
@@ -70,7 +70,7 @@ class ScrollTo {
70
70
  }
71
71
 
72
72
  if ( elapsed < this.#duration ) {
73
- this.#animationFrame = window.requestAnimationFrame( this.step.bind( this ) );
73
+ this.#animationFrame = window.requestAnimationFrame( this.#step.bind( this ) );
74
74
  }
75
75
  else {
76
76
  if ( typeof this.#callback === 'function' ) {
@@ -82,7 +82,7 @@ class ScrollTo {
82
82
  }
83
83
 
84
84
 
85
- scrollTo( item: ScrollSnapItemType, type: ScrollSnapSnapType, _duration?: number ) {
85
+ scrollTo( item: FLib.ScrollSnap.Item, type: FLib.ScrollSnap.SnapType, _duration?: number ) {
86
86
  if ( !item ) {
87
87
  return;
88
88
  }
@@ -106,7 +106,7 @@ class ScrollTo {
106
106
 
107
107
  this.#duration = typeof _duration !== 'undefined' ? _duration : delta; // ms
108
108
 
109
- this.#animationFrame = window.requestAnimationFrame( this.step.bind( this ) );
109
+ this.#animationFrame = window.requestAnimationFrame( this.#step.bind( this ) );
110
110
  }
111
111
 
112
112
 
@@ -137,7 +137,7 @@ class ScrollTo {
137
137
  export default class ScrollSnap {
138
138
 
139
139
  #$snapItems!: NodeList;
140
- #snapPoints: ScrollSnapItemType[];
140
+ #snapPoints: FLib.ScrollSnap.Item[];
141
141
  #halfSize: {
142
142
  coord: number;
143
143
  index: number;
@@ -150,15 +150,15 @@ export default class ScrollSnap {
150
150
  #minItemsToActivate: number;
151
151
  #scrollerSize!: number;
152
152
  #offsetSize!: number;
153
- #options: ScrollSnapOptionsType;
153
+ #options: FLib.ScrollSnap.Options;
154
154
  #hasSwipe: boolean;
155
155
  #touchended: boolean;
156
- #currentSnapItem!: ScrollSnapItemType;
156
+ #currentSnapItem!: FLib.ScrollSnap.Item;
157
157
  #areEventsBinded!: boolean;
158
- #lastTouchPosition!: GestureCoordsType;
158
+ #lastTouchPosition!: FLib.Events.Gesture.Coords;
159
159
  #IS_VERTICAL_MODE: boolean;
160
- #SCROLL_PROPERTY_NAME: ScrollSnapScrollPropertyType;
161
- #SCROLL_SIZE_PROPERTY_NAME: ScrollSnapSizePropertyType;
160
+ #SCROLL_PROPERTY_NAME: FLib.ScrollSnap.ScrollPropertyType;
161
+ #SCROLL_SIZE_PROPERTY_NAME: FLib.ScrollSnap.SizePropertyType;
162
162
  #$scroller: HTMLElement
163
163
 
164
164
  #TIMEOUT_DELAY = 100;
@@ -168,7 +168,7 @@ export default class ScrollSnap {
168
168
  #SCROLL_END_TRESHOLD = 5;
169
169
 
170
170
 
171
- constructor( $scroller: HTMLElement, userOptions: ScrollSnapOptionsType = {} ) {
171
+ constructor( $scroller: HTMLElement, userOptions: FLib.ScrollSnap.Options = {} ) {
172
172
 
173
173
  this.#$scroller = $scroller;
174
174
  this.#options = extend( defaultOptions, userOptions );
@@ -194,7 +194,7 @@ export default class ScrollSnap {
194
194
  // Store the coordinate of the middle and the DOM object of each item
195
195
  this.#halfSize = [];
196
196
 
197
- this.#scrollToHandler = new ScrollTo( $scroller, this.#options.direction as ScrollSnapDirectionType, this.resetState.bind( this ) );
197
+ this.#scrollToHandler = new ScrollTo( $scroller, this.#options.direction as FLib.ScrollSnap.DirectionType, this.#resetState.bind( this ) );
198
198
 
199
199
  this.refresh( {
200
200
  "snapTo": this.#options.snapTo
@@ -202,8 +202,8 @@ export default class ScrollSnap {
202
202
  }
203
203
 
204
204
 
205
- private getScrollPositionInformation() {
206
- let scrollPos = this.#$scroller[ this.#SCROLL_PROPERTY_NAME ];
205
+ #getScrollPositionInformation = (): { scrollAtStart: boolean, scrollAtEnd: boolean } => {
206
+ const scrollPos = this.#$scroller[ this.#SCROLL_PROPERTY_NAME ];
207
207
 
208
208
  return {
209
209
  "scrollAtStart": scrollPos === 0,
@@ -212,13 +212,13 @@ export default class ScrollSnap {
212
212
  }
213
213
 
214
214
 
215
- private resetState( snapItem: ScrollSnapItemType, type: ScrollSnapSnapType ) {
215
+ #resetState = ( snapItem: FLib.ScrollSnap.Item, type: FLib.ScrollSnap.SnapType ): void => {
216
216
  this.#state = this.#STATE_IDLE;
217
217
  this.#touchended = true;
218
218
 
219
219
  this.#currentSnapItem = snapItem;
220
220
 
221
- this.bindEvents();
221
+ this.#bindEvents();
222
222
 
223
223
  if ( this.#options.onSnapEnd ) {
224
224
  this.#options.onSnapEnd( {
@@ -227,16 +227,16 @@ export default class ScrollSnap {
227
227
  type,
228
228
  "scrollerSize": this.#scrollerSize,
229
229
  "offsetSize": this.#offsetSize,
230
- ...this.getScrollPositionInformation()
230
+ ...this.#getScrollPositionInformation()
231
231
  } );
232
232
  }
233
233
 
234
- this.processLimit( snapItem, type, true );
234
+ this.#processLimit( snapItem, type, true );
235
235
  }
236
236
 
237
237
 
238
- private getCurrentSection( scrollPos: number ) {
239
- let len = this.#halfSize.length;
238
+ #getCurrentSection = ( scrollPos: number ): number => {
239
+ const len = this.#halfSize.length;
240
240
 
241
241
  if ( scrollPos <= 0 ) {
242
242
  return 0;
@@ -252,25 +252,25 @@ export default class ScrollSnap {
252
252
  }
253
253
 
254
254
 
255
- private cancelAutoScroll() {
255
+ #cancelAutoScroll = (): void => {
256
256
  clearTimeout( this.#scrollTimeoutId );
257
257
  this.#scrollToHandler.cancelAnimation();
258
258
  window.cancelAnimationFrame( this.#scrollTickTimeout );
259
259
  }
260
260
 
261
261
 
262
- #interuptAnimation = () => {
262
+ #interuptAnimation = (): void => {
263
263
  off( this.#$scroller, {
264
264
  "eventsName": "wheel",
265
265
  "callback": this.#interuptAnimation
266
266
  } );
267
- this.cancelAutoScroll();
267
+ this.#cancelAutoScroll();
268
268
  this.#state = this.#STATE_IDLE;
269
269
  this.#touchended = true;
270
270
  }
271
271
 
272
272
 
273
- private handleInterruption() {
273
+ #handleInterruption = (): void => {
274
274
  on( this.#$scroller, {
275
275
  "eventsName": "wheel",
276
276
  "callback": this.#interuptAnimation
@@ -279,11 +279,11 @@ export default class ScrollSnap {
279
279
 
280
280
 
281
281
  /* Return true if the start or the end is reached */
282
- private processLimit( snapItem: ScrollSnapItemType, type: ScrollSnapSnapType, fromResetState?: boolean ) {
282
+ #processLimit = ( snapItem: FLib.ScrollSnap.Item, type: FLib.ScrollSnap.SnapType, fromResetState?: boolean ): boolean => {
283
283
 
284
284
  if ( this.#$scroller[ this.#SCROLL_PROPERTY_NAME ] + this.#scrollerSize >= this.#$scroller[ this.#SCROLL_SIZE_PROPERTY_NAME ] - this.#SCROLL_END_TRESHOLD ) {
285
285
  if ( !fromResetState ) {
286
- this.resetState( snapItem, type );
286
+ this.#resetState( snapItem, type );
287
287
  }
288
288
 
289
289
  if ( this.#options.onReachEnd ) {
@@ -293,14 +293,14 @@ export default class ScrollSnap {
293
293
  type,
294
294
  "scrollerSize": this.#scrollerSize,
295
295
  "offsetSize": this.#offsetSize,
296
- ...this.getScrollPositionInformation()
296
+ ...this.#getScrollPositionInformation()
297
297
  } );
298
298
  }
299
299
  return true;
300
300
  }
301
301
  else if ( this.#$scroller[ this.#SCROLL_PROPERTY_NAME ] === 0 ) {
302
302
  if ( !fromResetState ) {
303
- this.resetState(snapItem, type);
303
+ this.#resetState(snapItem, type);
304
304
  }
305
305
 
306
306
  if ( this.#options.onReachStart ) {
@@ -319,10 +319,10 @@ export default class ScrollSnap {
319
319
  }
320
320
 
321
321
 
322
- private processScroll() {
323
- let snapItem = this.#snapPoints[ this.getCurrentSection( this.#$scroller[ this.#SCROLL_PROPERTY_NAME ] ) ];
322
+ #processScroll = (): void => {
323
+ const snapItem = this.#snapPoints[ this.#getCurrentSection( this.#$scroller[ this.#SCROLL_PROPERTY_NAME ] ) ];
324
324
 
325
- if ( this.processLimit( snapItem, 'scroll' ) ) {
325
+ if ( this.#processLimit( snapItem, 'scroll' ) ) {
326
326
  return;
327
327
  }
328
328
 
@@ -333,7 +333,7 @@ export default class ScrollSnap {
333
333
  "type": "scroll",
334
334
  "scrollerSize": this.#scrollerSize,
335
335
  "offsetSize": this.#offsetSize,
336
- ...this.getScrollPositionInformation()
336
+ ...this.#getScrollPositionInformation()
337
337
  } );
338
338
  }
339
339
 
@@ -343,31 +343,31 @@ export default class ScrollSnap {
343
343
  );
344
344
  this.#state = this.#STATE_MOVING;
345
345
 
346
- this.handleInterruption();
346
+ this.#handleInterruption();
347
347
  }
348
348
 
349
349
 
350
- private debounceScroll() {
350
+ #debounceScroll = (): void => {
351
351
  clearTimeout( this.#scrollTimeoutId );
352
352
  window.cancelAnimationFrame( this.#scrollTickTimeout );
353
- this.#scrollTickTimeout = window.requestAnimationFrame( this.processScroll.bind( this ) );
353
+ this.#scrollTickTimeout = window.requestAnimationFrame( this.#processScroll.bind( this ) );
354
354
  }
355
355
 
356
356
 
357
- #onScroll = () => {
357
+ #onScroll = (): void => {
358
358
  if ( this.#state !== this.#STATE_IDLE || !this.#touchended ) {
359
359
  return;
360
360
  }
361
361
 
362
362
  this.#state = this.#STATE_IDLE;
363
363
 
364
- this.cancelAutoScroll();
364
+ this.#cancelAutoScroll();
365
365
 
366
- this.#scrollTimeoutId = setTimeout( this.debounceScroll.bind( this ), this.#TIMEOUT_DELAY );
366
+ this.#scrollTimeoutId = setTimeout( this.#debounceScroll.bind( this ), this.#TIMEOUT_DELAY );
367
367
  }
368
368
 
369
369
 
370
- private removeEvents() {
370
+ #removeEvents = (): void => {
371
371
  if ( !this.#areEventsBinded ) {
372
372
  return;
373
373
  }
@@ -382,7 +382,7 @@ export default class ScrollSnap {
382
382
  }
383
383
 
384
384
 
385
- private bindEvents() {
385
+ #bindEvents = (): void => {
386
386
  if ( this.#areEventsBinded ) {
387
387
  return;
388
388
  }
@@ -402,9 +402,9 @@ export default class ScrollSnap {
402
402
  }
403
403
 
404
404
 
405
- private updateOptions( newOptions: ScrollSnapOptionsType ) {
405
+ #updateOptions = ( newOptions: FLib.ScrollSnap.Options ): void => {
406
406
 
407
- let { offset, $offsetElement, direction } = newOptions;
407
+ const { offset, $offsetElement, direction } = newOptions;
408
408
 
409
409
  if ( direction ) {
410
410
  this.#options.direction = direction;
@@ -423,12 +423,11 @@ export default class ScrollSnap {
423
423
  /**
424
424
  * Refresh the scroller and snap to the asked item
425
425
  */
426
- refresh( _options: ScrollSnapRefreshOptionType = {} ) {
427
- let propPos;
426
+ refresh( _options: FLib.ScrollSnap.RefreshOption = {} ): this {
427
+ let { snapTo } = _options;
428
+ const { $itemToSnapOn } = _options;
428
429
 
429
- let { snapTo, $itemToSnapOn } = _options;
430
-
431
- this.updateOptions( _options );
430
+ this.#updateOptions( _options );
432
431
 
433
432
  if ( !snapTo ) {
434
433
  snapTo = this.#options.snapTo;
@@ -437,7 +436,7 @@ export default class ScrollSnap {
437
436
  this.#options.snapTo = snapTo;
438
437
  }
439
438
 
440
- propPos = this.#IS_VERTICAL_MODE ? 'top' : 'left';
439
+ const propPos = this.#IS_VERTICAL_MODE ? 'top' : 'left';
441
440
  this.#offsetSize = 0;
442
441
  this.#snapPoints.length = 0;
443
442
  this.#halfSize.length = 0;
@@ -455,13 +454,13 @@ export default class ScrollSnap {
455
454
  this.#state = this.#STATE_LOCKED;
456
455
  this.#touchended = true;
457
456
 
458
- this.removeEvents();
457
+ this.#removeEvents();
459
458
  aClass( this.#$scroller, this.#options.lockedClass as string );
460
459
 
461
- return;
460
+ return this;
462
461
  }
463
462
 
464
- this.bindEvents();
463
+ this.#bindEvents();
465
464
 
466
465
  this.#state = this.#STATE_IDLE;
467
466
  this.#touchended = true;
@@ -480,8 +479,8 @@ export default class ScrollSnap {
480
479
 
481
480
  this.#$snapItems.forEach( ( $item, index ) => {
482
481
  const $ITM = $item as HTMLElement;
483
- let _position = position( $ITM );
484
- let snapItem: ScrollSnapItemType = {
482
+ const _position = position( $ITM );
483
+ const snapItem: FLib.ScrollSnap.Item = {
485
484
  "coord": _position[ propPos ] - this.#offsetSize,
486
485
  "index": index,
487
486
  "isFirst": index === 0,
@@ -519,25 +518,25 @@ export default class ScrollSnap {
519
518
  });
520
519
  }
521
520
  });
521
+
522
+ return this;
522
523
  }
523
524
 
524
525
 
525
526
  // Scroll event fired only on touchmove and at the end of the scrolling
526
527
  // on some old iOS or on all iOS (up to 11) in PWA or hybrid app...
527
- #onSwipe = () => {
528
- let scrollPos;
529
-
528
+ #onSwipe = (): void => {
530
529
  this.#hasSwipe = true;
531
530
 
532
531
  // Cancel scroll watching fired on touchmove,
533
532
  // Allow us to wait for the last scroll event fired one time at the end of the scrolling for bad iOS scroll behaviour
534
- this.cancelAutoScroll();
533
+ this.#cancelAutoScroll();
535
534
 
536
535
  if ( hasIosBadScroll !== undefined ) {
537
536
  return;
538
537
  }
539
538
 
540
- scrollPos = this.#$scroller[ this.#SCROLL_PROPERTY_NAME ];
539
+ const scrollPos = this.#$scroller[ this.#SCROLL_PROPERTY_NAME ];
541
540
 
542
541
  setTimeout( () => {
543
542
  hasIosBadScroll = scrollPos === this.#$scroller[ this.#SCROLL_PROPERTY_NAME ]
@@ -545,25 +544,24 @@ export default class ScrollSnap {
545
544
  }
546
545
 
547
546
 
548
- private onInitMove() {
547
+ #onInitMove = (): void => {
549
548
  if ( this.#state === this.#STATE_MOVING ) {
550
549
  this.#interuptAnimation();
551
550
  }
552
551
  this.#hasSwipe = false;
553
552
  this.#touchended = false;
554
- this.cancelAutoScroll();
555
-
553
+ this.#cancelAutoScroll();
556
554
  }
557
555
 
558
556
 
559
- #onTouchstart = ( e: Event, $targetElement: HTMLElement, position: GestureCoordsType ) => {
560
- this.onInitMove()
557
+ #onTouchstart = ( e: Event, $targetElement: HTMLElement, position: FLib.Events.Gesture.Coords ): void => {
558
+ this.#onInitMove()
561
559
  this.#lastTouchPosition = position;
562
560
  }
563
561
 
564
562
 
565
- #onTouchend = ( e: Event, $targetElement: HTMLElement, position: GestureCoordsType) => {
566
- let deltaX = Math.abs( this.#lastTouchPosition.pageX - position.pageX );
563
+ #onTouchend = ( e: Event, $targetElement: HTMLElement, position: FLib.Events.Gesture.Coords): void => {
564
+ const deltaX = Math.abs( this.#lastTouchPosition.pageX - position.pageX );
567
565
 
568
566
  if ( this.#state === this.#STATE_MOVING || deltaX < 2 ) {
569
567
  return;
@@ -573,9 +571,9 @@ export default class ScrollSnap {
573
571
 
574
572
  // Cancel scroll watching fired on touchmove,
575
573
  // Allow us to wait for the last scroll event fired one time at the end of the scrolling for bad iOS scroll behaviour
576
- this.cancelAutoScroll();
574
+ this.#cancelAutoScroll();
577
575
  if ( !this.#hasSwipe ) {
578
- this.#scrollTimeoutId = setTimeout( this.debounceScroll.bind( this ), this.#TIMEOUT_DELAY );
576
+ this.#scrollTimeoutId = setTimeout( this.#debounceScroll.bind( this ), this.#TIMEOUT_DELAY );
579
577
  }
580
578
  }
581
579
 
@@ -583,19 +581,18 @@ export default class ScrollSnap {
583
581
  /**
584
582
  * Scroll to a specific index
585
583
  *
586
- * @param index
587
- * @param [duration] - In ms
584
+ * @param duration - In ms
588
585
  */
589
- scrollToIndex( index: number, duration?: number ) {
586
+ scrollToIndex( index: number, duration?: number ): this {
590
587
 
591
588
  if ( index < 0 || !this.#snapPoints[ index ] ) {
592
- return;
589
+ return this;
593
590
  }
594
591
 
595
592
  this.#state = this.#STATE_MOVING;
596
593
 
597
- this.removeEvents();
598
- this.onInitMove();
594
+ this.#removeEvents();
595
+ this.#onInitMove();
599
596
  this.#touchended = true;
600
597
 
601
598
 
@@ -606,31 +603,32 @@ export default class ScrollSnap {
606
603
  "type": "api",
607
604
  "scrollerSize": this.#scrollerSize,
608
605
  "offsetSize": this.#offsetSize,
609
- ...this.getScrollPositionInformation()
606
+ ...this.#getScrollPositionInformation()
610
607
  } );
611
608
  }
612
609
 
613
610
  this.#scrollToHandler.scrollTo( this.#snapPoints[ index ], "api", duration );
611
+
612
+ return this;
614
613
  }
615
614
 
616
615
 
617
616
  /**
618
617
  * Scroll to a specific item
619
618
  *
620
- * @param $item
621
- * @param [duration] - In ms
619
+ * @param duration - In ms
622
620
  */
623
- scrollToItem( $item: HTMLElement, duration?: number ) {
621
+ scrollToItem( $item: HTMLElement, duration?: number ): this {
624
622
  const snapItem = this.#snapPoints.find( snapPoint => snapPoint.$item === $item );
625
623
 
626
624
  if ( !snapItem ) {
627
- return;
625
+ return this;
628
626
  }
629
627
 
630
628
  this.#state = this.#STATE_MOVING;
631
629
 
632
- this.removeEvents();
633
- this.onInitMove();
630
+ this.#removeEvents();
631
+ this.#onInitMove();
634
632
  this.#touchended = true;
635
633
 
636
634
  this.#currentSnapItem = snapItem;
@@ -642,7 +640,7 @@ export default class ScrollSnap {
642
640
  "type": "api",
643
641
  "scrollerSize": this.#scrollerSize,
644
642
  "offsetSize": this.#offsetSize,
645
- ...this.getScrollPositionInformation()
643
+ ...this.#getScrollPositionInformation()
646
644
  } );
647
645
  }
648
646
 
@@ -653,29 +651,30 @@ export default class ScrollSnap {
653
651
  else {
654
652
  this.#options._setScroll?.( this.#$scroller, snapItem.coord, 0 );
655
653
  }
656
- wait().then( () => this.resetState( snapItem, "api" ) );
654
+ wait().then( () => this.#resetState( snapItem, "api" ) );
657
655
  }
658
656
  else {
659
657
  this.#scrollToHandler.scrollTo( snapItem, "api", duration );
660
658
  }
661
659
 
660
+ return this;
662
661
  }
663
662
 
664
663
 
665
664
  /**
666
665
  * Scroll to the next item
667
666
  *
668
- * @param [duration] - In ms
667
+ * @param duration - In ms
669
668
  */
670
- next( duration?: number ) {
671
- let nextIndex = this.#currentSnapItem.index + 1;
669
+ next( duration?: number ): this {
670
+ const nextIndex = this.#currentSnapItem.index + 1;
672
671
 
673
672
  if ( !this.#snapPoints[ nextIndex ] ) {
674
- return;
673
+ return this;
675
674
  }
676
675
 
677
- this.removeEvents();
678
- this.onInitMove();
676
+ this.#removeEvents();
677
+ this.#onInitMove();
679
678
  this.#touchended = true;
680
679
 
681
680
  this.#state = this.#STATE_MOVING;
@@ -687,27 +686,30 @@ export default class ScrollSnap {
687
686
  "type": "api",
688
687
  "scrollerSize": this.#scrollerSize,
689
688
  "offsetSize": this.#offsetSize,
690
- ...this.getScrollPositionInformation()
689
+ ...this.#getScrollPositionInformation()
691
690
  } );
692
691
  }
693
692
 
694
693
  this.#scrollToHandler.scrollTo( this.#snapPoints[ nextIndex ], "api", duration );
694
+
695
+ return this;
695
696
  }
696
697
 
697
698
 
698
699
  /**
699
700
  * Scroll to the previous item
700
- * @param [duration] - In ms
701
+ *
702
+ * @param duration - In ms
701
703
  */
702
- previous( duration?: number ) {
703
- let previousIndex = this.#currentSnapItem.index - 1;
704
+ previous( duration?: number ): this {
705
+ const previousIndex = this.#currentSnapItem.index - 1;
704
706
 
705
707
  if ( previousIndex < 0 || !this.#snapPoints[ previousIndex ] ) {
706
- return;
708
+ return this;
707
709
  }
708
710
 
709
- this.removeEvents();
710
- this.onInitMove();
711
+ this.#removeEvents();
712
+ this.#onInitMove();
711
713
  this.#touchended = true;
712
714
 
713
715
  this.#state = this.#STATE_MOVING;
@@ -719,19 +721,21 @@ export default class ScrollSnap {
719
721
  "type": "api",
720
722
  "scrollerSize": this.#scrollerSize,
721
723
  "offsetSize": this.#offsetSize,
722
- ...this.getScrollPositionInformation()
724
+ ...this.#getScrollPositionInformation()
723
725
  } );
724
726
  }
725
727
 
726
728
  this.#scrollToHandler.scrollTo( this.#snapPoints[ previousIndex ], "api", duration );
729
+
730
+ return this;
727
731
  }
728
732
 
729
733
 
730
734
  /**
731
735
  * Remove all events, css class or inline styles
732
736
  */
733
- clean() {
734
- this.cancelAutoScroll();
737
+ clean(): this {
738
+ this.#cancelAutoScroll();
735
739
  off( this.#$scroller, {
736
740
  "eventsName": "scroll",
737
741
  "callback": this.#onScroll
@@ -741,6 +745,8 @@ export default class ScrollSnap {
741
745
  "callback": this.#interuptAnimation
742
746
  } );
743
747
  gestureOff( this.#$scroller, 'scrollSnapTouchSwipe' );
748
+
749
+ return this;
744
750
  }
745
751
  }
746
752