@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.
- package/CHANGELOG.md +15 -0
- package/DOM/Class.ts +10 -12
- package/DOM/DocumentSize.ts +3 -1
- package/DOM/Filter.ts +0 -2
- package/DOM/Index.ts +1 -3
- package/DOM/Manipulation.ts +0 -3
- package/DOM/Matrix.ts +12 -12
- package/DOM/Offset.ts +4 -5
- package/DOM/OuterSize.ts +12 -12
- package/DOM/PageToDOM.ts +2 -2
- package/DOM/Position.ts +3 -3
- package/DOM/Size.ts +3 -7
- package/DOM/StrToDOM.ts +0 -1
- package/DOM/Styles.ts +3 -12
- package/DOM/Traversing.ts +0 -6
- package/DOM/WindowScroll.ts +3 -1
- package/DOM/WindowSize.ts +3 -1
- package/DOM/Wrap.ts +0 -1
- package/Events/DeviceOrientation.ts +27 -31
- package/Events/EventsManager.ts +10 -25
- package/Events/Gesture.ts +36 -37
- package/Events/HistoryController.ts +11 -17
- package/Events/ImageLoad.ts +35 -19
- package/Events/IntersectObserver.ts +15 -19
- package/Events/KeyboardHandler.ts +10 -8
- package/Events/MediaQueriesEvents.ts +53 -51
- package/Events/OnAnimationEnd.ts +2 -3
- package/Events/OnTransitionEnd.ts +3 -3
- package/Events/PubSub.ts +5 -8
- package/Events/TouchHover.ts +18 -21
- package/Events/WindowEvents.ts +26 -30
- package/Helpers/Colors.ts +7 -23
- package/Helpers/Cookie.ts +5 -12
- package/Helpers/Coordinates.ts +0 -7
- package/Helpers/Debounce.ts +3 -7
- package/Helpers/Defer.ts +1 -1
- package/Helpers/GetValue.ts +0 -2
- package/Helpers/Insert.ts +0 -1
- package/Helpers/Sequential.ts +0 -2
- package/Helpers/Slice.ts +0 -3
- package/Helpers/Throttle.ts +0 -1
- package/Helpers/TransitionHelpers.ts +8 -6
- package/Helpers/Type.ts +1 -14
- package/Helpers/Unique.ts +3 -3
- package/Helpers/UrlParser.ts +13 -22
- package/Helpers/Wait.ts +1 -1
- package/Modules/Accordion/Tab.ts +18 -16
- package/Modules/Accordion/index.ts +24 -16
- package/Modules/Autocomplete.ts +95 -101
- package/Modules/DragSlider.ts +72 -63
- package/Modules/GlobalState.ts +60 -53
- package/Modules/LoadGMap.ts +4 -7
- package/Modules/Notifications/Notification.ts +28 -32
- package/Modules/Notifications/index.ts +43 -36
- package/Modules/Popin/Popin.ts +100 -110
- package/Modules/Popin/PopinAccessibility.ts +8 -8
- package/Modules/Popin/PopinBackground.ts +11 -11
- package/Modules/Popin/PopinController.ts +23 -29
- package/Modules/Popin/Tools.ts +18 -19
- package/Modules/QuickTemplate.ts +4 -6
- package/Modules/ScrollSnap.ts +110 -104
- package/Modules/SkinCheckbox.ts +51 -37
- package/Modules/SkinFile.ts +62 -52
- package/Modules/SkinRadio.ts +62 -42
- package/Modules/SkinSelect.ts +116 -100
- package/Modules/Slider/Slide.ts +49 -52
- package/Modules/Slider/Slider.ts +100 -136
- package/Modules/Slider/SliderControls.ts +60 -59
- package/Modules/Tabs/Tab.ts +27 -23
- package/Modules/Tabs/index.ts +35 -25
- package/Modules/Validator/Date.ts +2 -1
- package/Modules/Validator/Equals.ts +1 -1
- package/Modules/Validator/Internal/Input.ts +370 -0
- package/Modules/Validator/Internal/InputValidator.ts +99 -0
- package/Modules/Validator/Internal/ValidatorFunctionsController.ts +58 -0
- package/Modules/Validator/Max.ts +1 -1
- package/Modules/Validator/Min.ts +1 -1
- package/Modules/Validator/MultiRequired.ts +5 -5
- package/Modules/Validator/Number.ts +1 -0
- package/Modules/Validator/Pattern.ts +1 -1
- package/Modules/Validator/Recaptcha.ts +1 -0
- package/Modules/Validator/Required.ts +3 -2
- package/Modules/Validator/ServerCheck.ts +23 -15
- package/Modules/Validator/Tools/GetQueryFromForm.ts +1 -6
- package/Modules/Validator/Tools/IsDate.ts +2 -3
- package/Modules/Validator/Tools/IsEmail.ts +2 -5
- package/Modules/Validator/Tools/IsEmpty.ts +0 -2
- package/Modules/Validator/Tools/IsNumber.ts +0 -2
- package/Modules/Validator/Tools/IsUrl.ts +1 -3
- package/Modules/Validator/Tools/Label.ts +5 -15
- package/Modules/Validator/Tools/RadioButton.ts +4 -10
- package/Modules/Validator/Url.ts +1 -0
- package/Modules/Validator/index.ts +36 -36
- package/Modules/YouTubePlayer.ts +18 -16
- package/README.md +1 -1
- package/Types/Accordion.d.ts +36 -0
- package/Types/Autocomplete.d.ts +95 -0
- package/Types/DOM.d.ts +69 -0
- package/Types/DragSlider.d.ts +56 -0
- package/Types/EventsHelpers.d.ts +390 -0
- package/Types/GLImageTransition.d.ts +47 -43
- package/Types/GlobalState.d.ts +9 -0
- package/Types/Helpers.d.ts +30 -0
- package/Types/Notifications.d.ts +48 -44
- package/Types/Popin.d.ts +95 -0
- package/Types/ScrollSnap.d.ts +66 -0
- package/Types/SkinCheckbox.d.ts +26 -0
- package/Types/SkinFile.d.ts +38 -0
- package/Types/SkinRadio.d.ts +28 -0
- package/Types/SkinSelect.d.ts +59 -0
- package/Types/Slider.d.ts +106 -0
- package/Types/Tabs.d.ts +26 -0
- package/Types/Validator.d.ts +72 -0
- package/Types/YouTubePlayer.d.ts +27 -0
- package/Types/index.d.ts +22 -21
- package/WebGL/GLImageTransition/GLImageTransition.ts +83 -80
- package/WebGL/GLImageTransition/Presets/Cellular.ts +11 -11
- package/WebGL/GLImageTransition/Presets/Fade.ts +2 -3
- package/WebGL/GLImageTransition/Presets/HorizontalMovingGrid.ts +9 -9
- package/WebGL/GLImageTransition/Presets/PresetSample.ts +11 -9
- package/WebGL/GLImageTransition/Presets/Solarisation.ts +7 -12
- package/package.json +1 -1
- package/Modules/Template.ts +0 -209
- package/Types/AccordionTypes.d.ts +0 -29
- package/Types/AutocompleteTypes.d.ts +0 -85
- package/Types/DOMTypes.d.ts +0 -62
- package/Types/DragSliderTypes.d.ts +0 -52
- package/Types/EventsHelpersTypes.d.ts +0 -370
- package/Types/GlobalStateTypes.d.ts +0 -5
- package/Types/HelpersTypes.d.ts +0 -23
- package/Types/MediaPreloaderTypes.d.ts +0 -12
- package/Types/PopinTypes.d.ts +0 -83
- package/Types/ScrollSnapTypes.d.ts +0 -62
- package/Types/SkinCheckboxTypes.d.ts +0 -23
- package/Types/SkinFileTypes.d.ts +0 -34
- package/Types/SkinRadioTypes.d.ts +0 -24
- package/Types/SkinSelectTypes.d.ts +0 -48
- package/Types/SliderTypes.d.ts +0 -97
- package/Types/TabsTypes.d.ts +0 -22
- package/Types/ValidatorTypes.d.ts +0 -61
- package/Types/YouTubePlayerTypes.d.ts +0 -23
package/Modules/ScrollSnap.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { position } from '../DOM/Position';
|
|
|
8
8
|
import { width, height } from '../DOM/Size';
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
const defaultOptions:
|
|
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!:
|
|
43
|
-
#snapItemType!:
|
|
44
|
-
#scrollPropName:
|
|
42
|
+
#snapItem!: FLib.ScrollSnap.Item;
|
|
43
|
+
#snapItemType!: FLib.ScrollSnap.SnapType;
|
|
44
|
+
#scrollPropName: FLib.ScrollSnap.ScrollPropertyType;
|
|
45
45
|
#$element: HTMLElement;
|
|
46
|
-
#callback:
|
|
46
|
+
#callback: FLib.ScrollSnap.ScrollToCallback;
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
constructor( $element: HTMLElement, direction:
|
|
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
|
-
|
|
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
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
153
|
+
#options: FLib.ScrollSnap.Options;
|
|
154
154
|
#hasSwipe: boolean;
|
|
155
155
|
#touchended: boolean;
|
|
156
|
-
#currentSnapItem!:
|
|
156
|
+
#currentSnapItem!: FLib.ScrollSnap.Item;
|
|
157
157
|
#areEventsBinded!: boolean;
|
|
158
|
-
#lastTouchPosition!:
|
|
158
|
+
#lastTouchPosition!: FLib.Events.Gesture.Coords;
|
|
159
159
|
#IS_VERTICAL_MODE: boolean;
|
|
160
|
-
#SCROLL_PROPERTY_NAME:
|
|
161
|
-
#SCROLL_SIZE_PROPERTY_NAME:
|
|
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:
|
|
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
|
|
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
|
-
|
|
206
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
230
|
+
...this.#getScrollPositionInformation()
|
|
231
231
|
} );
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
this
|
|
234
|
+
this.#processLimit( snapItem, type, true );
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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
|
|
267
|
+
this.#cancelAutoScroll();
|
|
268
268
|
this.#state = this.#STATE_IDLE;
|
|
269
269
|
this.#touchended = true;
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
|
|
273
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
323
|
-
|
|
322
|
+
#processScroll = (): void => {
|
|
323
|
+
const snapItem = this.#snapPoints[ this.#getCurrentSection( this.#$scroller[ this.#SCROLL_PROPERTY_NAME ] ) ];
|
|
324
324
|
|
|
325
|
-
if ( this
|
|
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
|
|
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
|
|
346
|
+
this.#handleInterruption();
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
|
|
350
|
-
|
|
350
|
+
#debounceScroll = (): void => {
|
|
351
351
|
clearTimeout( this.#scrollTimeoutId );
|
|
352
352
|
window.cancelAnimationFrame( this.#scrollTickTimeout );
|
|
353
|
-
this.#scrollTickTimeout = window.requestAnimationFrame( 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
|
|
364
|
+
this.#cancelAutoScroll();
|
|
365
365
|
|
|
366
|
-
this.#scrollTimeoutId = setTimeout( this
|
|
366
|
+
this.#scrollTimeoutId = setTimeout( this.#debounceScroll.bind( this ), this.#TIMEOUT_DELAY );
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
|
|
370
|
-
|
|
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
|
-
|
|
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
|
-
|
|
405
|
+
#updateOptions = ( newOptions: FLib.ScrollSnap.Options ): void => {
|
|
406
406
|
|
|
407
|
-
|
|
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:
|
|
427
|
-
let
|
|
426
|
+
refresh( _options: FLib.ScrollSnap.RefreshOption = {} ): this {
|
|
427
|
+
let { snapTo } = _options;
|
|
428
|
+
const { $itemToSnapOn } = _options;
|
|
428
429
|
|
|
429
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
484
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
555
|
-
|
|
553
|
+
this.#cancelAutoScroll();
|
|
556
554
|
}
|
|
557
555
|
|
|
558
556
|
|
|
559
|
-
#onTouchstart = ( e: Event, $targetElement: HTMLElement, position:
|
|
560
|
-
this
|
|
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:
|
|
566
|
-
|
|
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
|
|
574
|
+
this.#cancelAutoScroll();
|
|
577
575
|
if ( !this.#hasSwipe ) {
|
|
578
|
-
this.#scrollTimeoutId = setTimeout( this
|
|
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
|
|
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
|
|
598
|
-
this
|
|
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
|
|
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
|
|
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
|
|
633
|
-
this
|
|
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
|
|
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
|
|
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
|
|
667
|
+
* @param duration - In ms
|
|
669
668
|
*/
|
|
670
|
-
next( duration?: number ) {
|
|
671
|
-
|
|
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
|
|
678
|
-
this
|
|
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
|
|
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
|
-
*
|
|
701
|
+
*
|
|
702
|
+
* @param duration - In ms
|
|
701
703
|
*/
|
|
702
|
-
previous( duration?: number ) {
|
|
703
|
-
|
|
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
|
|
710
|
-
this
|
|
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
|
|
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
|
|
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
|
|