@creative-web-solution/front-library 7.1.28 → 7.1.30

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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 7.1.30
4
+
5
+ * [DragSlider]: Fix link cancellation
6
+
7
+
8
+ ## 7.1.29
9
+
10
+ * [DragSlider]: Fix callback issue
11
+
12
+
3
13
  ## 7.1.28
4
14
 
5
15
  * [YouTubePlayer]: Update types + use ready event to handle end of loading
@@ -1,33 +1,33 @@
1
- import { wait } from '../Helpers/Wait';
2
- import { debounce } from '../Helpers/Debounce';
3
- import { offset } from '../DOM/Offset';
4
- import { gesture, gestureOff } from '../Events/Gesture';
5
- import { prop } from '../DOM/Styles';
6
- import { aClass, rClass, tClass } from '../DOM/Class';
7
- import { on, off } from '../Events/EventsManager';
8
- import { isTouchDevice } from '../Tools/TouchDeviceSupport';
9
- import { extend } from '../Helpers/Extend';
1
+ import { wait } from "../Helpers/Wait";
2
+ import { debounce } from "../Helpers/Debounce";
3
+ import { offset } from "../DOM/Offset";
4
+ import { gesture, gestureOff } from "../Events/Gesture";
5
+ import { prop } from "../DOM/Styles";
6
+ import { aClass, rClass, tClass } from "../DOM/Class";
7
+ import { on, off } from "../Events/EventsManager";
8
+ import { isTouchDevice } from "../Tools/TouchDeviceSupport";
9
+ import { extend } from "../Helpers/Extend";
10
10
 
11
11
  const defaultOptions = {
12
12
  swipeTresholdMin: 40,
13
13
  swipeTresholdSize: 0.5,
14
- lockedClass: 'is-locked',
15
- _animReset: function($list) {
14
+ lockedClass: "is-locked",
15
+ _animReset: function ($list) {
16
16
  // gsap.set( $list, {
17
17
  // "x": 0,
18
18
  // "y": 0,
19
19
  // "z": 0
20
20
  // } );
21
21
  },
22
- _animClear: function($list) {
22
+ _animClear: function ($list) {
23
23
  // gsap.set( $list, {
24
24
  // "clearProps": "all"
25
25
  // } );
26
26
  },
27
- _animKill: function($list) {
27
+ _animKill: function ($list) {
28
28
  // gsap.killTweensOf( $list );
29
29
  },
30
- _animMoveItem: function($list, x, onUpdate) {
30
+ _animMoveItem: function ($list, x, onUpdate) {
31
31
  // return gsap.to( $list, {
32
32
  // "duration": 0.3,
33
33
  // "x": x,
@@ -38,14 +38,14 @@ const defaultOptions = {
38
38
  // }
39
39
  // } );
40
40
  },
41
- _setCoordinates: function($list, x) {
41
+ _setCoordinates: function ($list, x) {
42
42
  // gsap.set( $list, {
43
43
  // "x": x,
44
44
  // "y": 0,
45
45
  // "z": 0
46
46
  // } );
47
- }
48
- }
47
+ },
48
+ };
49
49
 
50
50
  const MINIMUM_MOVEMENT_TO_START_DRAG = 3; // px
51
51
 
@@ -53,34 +53,35 @@ const MINIMUM_MOVEMENT_TO_START_DRAG = 3; // px
53
53
  * DragSlider
54
54
  */
55
55
  export default class DragSlider {
56
- #isDraggingActive: boolean;
57
- #options: FLib.DragSlider.Options;
58
- #deltaMove: FLib.DragSlider.DeltaMove = {
59
- "x": 0,
60
- "deltaX": 0,
61
- "deltaY": 0,
62
- "newX": 0
56
+ #isDraggingActive: boolean;
57
+ #options: FLib.DragSlider.Options;
58
+ #deltaMove: FLib.DragSlider.DeltaMove = {
59
+ x: 0,
60
+ deltaX: 0,
61
+ deltaY: 0,
62
+ newX: 0,
63
63
  };
64
- #itemArray: FLib.DragSlider.Item[];
65
- #$slider: HTMLElement;
64
+ #itemArray: FLib.DragSlider.Item[];
65
+ #$slider: HTMLElement;
66
66
  #viewportInfo;
67
- #siteOffsetLeft = 0;
68
- #siteOffsetRight = 0;
69
- #listDelta = 0;
70
- #$viewport: HTMLElement | undefined;
71
- #$items: NodeList | undefined;
72
- #$list: HTMLElement | undefined;
73
- #isDragging = false;
74
- #itemMap = new Map<HTMLElement, FLib.DragSlider.Item>();
75
- #firstItem: FLib.DragSlider.Item | undefined;
76
- #currentSnapItem: FLib.DragSlider.Item | undefined;
77
- #hasAlreadyBeenDragged = false;
78
- #startDragCoords: FLib.Events.Gesture.Coords | undefined;
79
- #isInitialized = false;
80
- #visibleItems: FLib.DragSlider.Item[] = [];
81
- #hiddenItems: FLib.DragSlider.Item[] = [];
67
+ #siteOffsetLeft = 0;
68
+ #siteOffsetRight = 0;
69
+ #listDelta = 0;
70
+ #$viewport: HTMLElement | undefined;
71
+ #$items: NodeList | undefined;
72
+ #$list: HTMLElement | undefined;
73
+ #isDragging = false;
74
+ #itemMap = new Map<HTMLElement, FLib.DragSlider.Item>();
75
+ #firstItem: FLib.DragSlider.Item | undefined;
76
+ #currentSnapItem: FLib.DragSlider.Item | undefined;
77
+ #hasAlreadyBeenDragged = false;
78
+ #startDragCoords: FLib.Events.Gesture.Coords | undefined;
79
+ #isInitialized = false;
80
+ #visibleItems: FLib.DragSlider.Item[] = [];
81
+ #hiddenItems: FLib.DragSlider.Item[] = [];
82
82
  #debouncedOnResize;
83
-
83
+ #minXPos: number = 0;
84
+ #maxXPos: number = 0;
84
85
 
85
86
  get count(): number {
86
87
  return this.#$items?.length ?? 0;
@@ -106,83 +107,108 @@ export default class DragSlider {
106
107
  return this.#hiddenItems;
107
108
  }
108
109
 
110
+ get firstItem(): FLib.DragSlider.Item | undefined {
111
+ return this.#itemArray[0];
112
+ }
109
113
 
110
- constructor( $slider: HTMLElement, userOptions: Partial<FLib.DragSlider.Options> ) {
114
+ get lastItem(): FLib.DragSlider.Item | undefined {
115
+ return this.#itemArray[this.#itemArray.length - 1];
116
+ }
111
117
 
112
- if ( !userOptions.viewportSelector || !userOptions.listSelector || !userOptions.itemSelector || !userOptions.dragClass ) {
113
- throw '[Drag Slider]: Missing at least one of viewportSelector, listSelector, itemSelector, dragClass';
118
+ constructor(
119
+ $slider: HTMLElement,
120
+ userOptions: Partial<FLib.DragSlider.Options>
121
+ ) {
122
+ if (
123
+ !userOptions.viewportSelector ||
124
+ !userOptions.listSelector ||
125
+ !userOptions.itemSelector ||
126
+ !userOptions.dragClass
127
+ ) {
128
+ throw "[Drag Slider]: Missing at least one of viewportSelector, listSelector, itemSelector, dragClass";
114
129
  }
115
130
 
116
131
  this.#$slider = $slider;
117
132
 
118
133
  this.#isDraggingActive = false;
119
134
 
120
- this.#options = extend( defaultOptions, userOptions );
135
+ this.#options = extend(defaultOptions, userOptions);
121
136
 
122
137
  this.#itemArray = [];
123
138
 
124
- wait( 'idle' ).then( this.init );
139
+ wait("idle").then(this.init);
125
140
  }
126
141
 
127
-
128
142
  #cancelLinkClick = (): void => {
129
- aClass( this.#$slider, this.#options.dragClass );
130
- }
131
-
143
+ wait().then(() => aClass(this.#$slider, this.#options.dragClass));
144
+ };
132
145
 
133
146
  #activeLinkClick = (): void => {
134
- wait().then( () => {
135
- rClass( this.#$slider, this.#options.dragClass );
136
- } );
137
- }
138
-
147
+ wait().then(() => rClass(this.#$slider, this.#options.dragClass));
148
+ };
139
149
 
140
150
  #onResize = (): void => {
141
- if ( !this.#$items || !this.#$list ) {
151
+ if (!this.#$items || !this.#$list) {
142
152
  return;
143
153
  }
144
154
 
145
- this.#viewportInfo = offset( this.#$viewport as HTMLElement );
146
- this.#siteOffsetLeft = parseInt( prop( (this.#$items[ 0 ] as HTMLElement), 'marginLeft' ), 10 );
147
- this.#siteOffsetRight = parseInt( prop( (this.#$items[ this.#$items.length - 1 ] as HTMLElement), 'marginRight' ), 10 );
155
+ this.#viewportInfo = offset(this.#$viewport as HTMLElement);
156
+ this.#siteOffsetLeft = parseInt(
157
+ prop(this.#$items[0] as HTMLElement, "marginLeft"),
158
+ 10
159
+ );
160
+ this.#siteOffsetRight = parseInt(
161
+ prop(
162
+ this.#$items[this.#$items.length - 1] as HTMLElement,
163
+ "marginRight"
164
+ ),
165
+ 10
166
+ );
148
167
 
149
- this.#listDelta = this.#viewportInfo.width - this.#$list.scrollWidth - this.#siteOffsetLeft - this.#siteOffsetRight;
168
+ this.#listDelta = this.#getMaxMoveSize();
169
+
170
+ this.#minXPos = 0;
171
+ this.#maxXPos = this.#listDelta;
150
172
 
151
173
  const prevIsDraggingActive = this.#isDraggingActive;
152
- this.#isDraggingActive = this.#listDelta < 0;
174
+ this.#isDraggingActive = this.#listDelta < 0;
153
175
 
154
- if ( !this.#isDraggingActive ) {
176
+ if (!this.#isDraggingActive) {
155
177
  this.#isDragging = false;
156
- this.#options._animKill( this.#$list );
157
- this.#options._animReset( this.#$list );
178
+ this.#options._animKill(this.#$list);
179
+ this.#options._animReset(this.#$list);
158
180
  }
159
181
 
160
- tClass( this.#$slider, this.#options.lockedClass, !this.#isDraggingActive );
182
+ tClass(
183
+ this.#$slider,
184
+ this.#options.lockedClass,
185
+ !this.#isDraggingActive
186
+ );
161
187
 
162
- if ( prevIsDraggingActive !== this.#isDraggingActive ) {
163
- this.#options.onChangeState?.( this.#isDraggingActive );
188
+ if (prevIsDraggingActive !== this.#isDraggingActive) {
189
+ this.#options.onChangeState?.(this.#isDraggingActive);
164
190
  }
165
191
 
166
192
  this.#itemArray.length = 0;
167
- const ABS_LIST_DELTA = Math.abs( this.#listDelta );
193
+ const ABS_LIST_DELTA = Math.abs(this.#listDelta);
168
194
 
169
195
  let flag = false;
170
196
 
171
197
  for (let index = 0; index < this.#$items.length; ++index) {
172
- const $ITEM = this.#$items[ index ] as HTMLElement;
173
- const ITEM_OFFSET = offset( $ITEM, false, this.#$list );
198
+ const $ITEM = this.#$items[index] as HTMLElement;
199
+ const ITEM_OFFSET = offset($ITEM, false, this.#$list);
174
200
  const DATA = {
175
201
  index,
176
- "isFirst": index === 0,
177
- "isLast": false,
178
- "$item": $ITEM,
179
- "info": ITEM_OFFSET
202
+ isFirst: index === 0,
203
+ isLast: false,
204
+ $item: $ITEM,
205
+ info: ITEM_OFFSET,
180
206
  };
181
207
 
182
208
  if (ITEM_OFFSET.left - this.#siteOffsetLeft <= ABS_LIST_DELTA) {
183
209
  this.#itemArray.push(DATA);
184
210
 
185
- this.#itemMap.set( $ITEM, DATA );
211
+ this.#itemMap.set($ITEM, DATA);
186
212
  continue;
187
213
  }
188
214
 
@@ -201,84 +227,84 @@ export default class DragSlider {
201
227
  }
202
228
  flag = true;
203
229
 
204
- this.#itemMap.set( $ITEM, DATA );
230
+ this.#itemMap.set($ITEM, DATA);
205
231
  }
206
232
 
207
- this.#firstItem = this.#itemMap.get( (this.#$items[ 0 ] as HTMLElement) ) as FLib.DragSlider.Item;
233
+ this.#firstItem = this.#itemMap.get(
234
+ this.#$items[0] as HTMLElement
235
+ ) as FLib.DragSlider.Item;
208
236
 
209
- if ( !this.#currentSnapItem ) {
237
+ if (!this.#currentSnapItem) {
210
238
  this.#currentSnapItem = this.#firstItem;
211
- }
212
- else {
213
- this.#currentSnapItem = this.#itemArray[ this.#currentSnapItem.index ];
239
+ } else {
240
+ this.#currentSnapItem =
241
+ this.#itemArray[this.#currentSnapItem.index];
214
242
  }
215
243
 
216
244
  this.#updateAccessibilityFeature();
217
- }
218
-
245
+ };
219
246
 
220
- #snapToItemAnimation = ( snapItem: FLib.DragSlider.Item ): Promise<any> => {
247
+ #snapToItemAnimation = (snapItem: FLib.DragSlider.Item): Promise<any> => {
221
248
  if (!snapItem) {
222
249
  return Promise.resolve();
223
250
  }
224
251
 
225
- let finalX;
226
-
227
- finalX = -1 * snapItem.info.left;
252
+ const finalX = Math.max(
253
+ Math.min(
254
+ this.#minXPos,
255
+ -1 * snapItem.info.left + this.#siteOffsetLeft
256
+ ),
257
+ this.#maxXPos
258
+ );
228
259
 
229
- finalX = Math.max( Math.min( 0, finalX ), this.#listDelta );
260
+ this.#options.onSnap?.(this.#getCallbackOptions(finalX, snapItem));
230
261
 
231
- // If close to the end, then snap to it
232
- if ( Math.abs( finalX - this.#listDelta ) <= 3 ) {
233
- finalX = this.#listDelta;
234
- }
235
-
236
- // If close to the start, then snap to it
237
- if ( Math.abs( finalX ) <= 3 ) {
238
- finalX = 0;
239
- }
262
+ this.#currentSnapItem = snapItem;
240
263
 
241
- const IS_SNAP_TO_END = finalX === this.#listDelta;
242
- const IS_SNAP_TO_START = finalX === 0;
264
+ return this.#options
265
+ ._animMoveItem(this.#$list, finalX, (newX) => {
266
+ this.#deltaMove.x = newX;
243
267
 
244
- this.#options.onSnap?.( {
245
- "item": snapItem,
246
- "xPos": this.#deltaMove.x,
247
- "moveMaxSize": this.#listDelta,
248
- "isAtStart": IS_SNAP_TO_START,
249
- "isAtEnd": IS_SNAP_TO_END,
250
- "visibleItems": this.#visibleItems,
251
- "hiddenItems": this.#hiddenItems
252
- } );
268
+ this.#options.onSnapUpdate?.(
269
+ this.#getCallbackOptions(newX, snapItem)
270
+ );
271
+ })
272
+ .then(() => {
273
+ return this.#updateAccessibilityFeature();
274
+ })
275
+ .then(() => {
276
+ this.#deltaMove.x = finalX;
277
+ this.#options.onSnapEnd?.(
278
+ this.#getCallbackOptions(this.#deltaMove.x)
279
+ );
280
+ });
281
+ };
253
282
 
254
- this.#currentSnapItem = snapItem;
283
+ #getCallbackOptions(xPos: number, snapItem?: FLib.DragSlider.Item) {
284
+ const IS_SNAP_TO_END = xPos === this.#listDelta;
285
+ const IS_SNAP_TO_START = xPos === 0;
255
286
 
256
- finalX += this.#siteOffsetLeft;
257
-
258
- return this.#options._animMoveItem( this.#$list, finalX, (newX) => {
259
- this.#deltaMove.x = newX;
260
-
261
- this.#options.onSnapUpdate?.( {
262
- "item": snapItem,
263
- "xPos": this.#deltaMove.x,
264
- "moveMaxSize": this.#listDelta,
265
- "isAtStart": IS_SNAP_TO_START,
266
- "isAtEnd": IS_SNAP_TO_END,
267
- "visibleItems": this.#visibleItems,
268
- "hiddenItems": this.#hiddenItems
269
- } );
270
- } ).then(() => this.#updateAccessibilityFeature());
287
+ return {
288
+ item: snapItem ?? this.#currentSnapItem,
289
+ xPos: this.#deltaMove.x,
290
+ moveMaxSize: this.#listDelta,
291
+ isAtStart: IS_SNAP_TO_START,
292
+ isAtEnd: IS_SNAP_TO_END,
293
+ visibleItems: this.#visibleItems,
294
+ hiddenItems: this.#hiddenItems,
295
+ };
271
296
  }
272
297
 
273
-
274
- #getFirstPreviousItem = ( xPos: number ): { snapItem: FLib.DragSlider.Item, snapToEnd: boolean } => {
298
+ #getFirstPreviousItem = (
299
+ xPos: number
300
+ ): { snapItem: FLib.DragSlider.Item; snapToEnd: boolean } => {
275
301
  let snapItem;
276
302
 
277
- const absXPos = Math.abs( xPos );
303
+ const absXPos = Math.abs(xPos);
278
304
 
279
- for ( const item of this.#itemArray ) {
280
- if ( item.info.left <= absXPos ) {
281
- snapItem = item;
305
+ for (const item of this.#itemArray) {
306
+ if (item.info.left <= absXPos) {
307
+ snapItem = item;
282
308
  continue;
283
309
  }
284
310
  break;
@@ -286,168 +312,173 @@ export default class DragSlider {
286
312
 
287
313
  return {
288
314
  snapItem,
289
- "snapToEnd": false
315
+ snapToEnd: false,
290
316
  };
291
- }
292
-
317
+ };
293
318
 
294
- #getFirstNextItem = ( xPos: number ): { snapItem: FLib.DragSlider.Item, snapToEnd: boolean } => {
319
+ #getFirstNextItem = (
320
+ xPos: number
321
+ ): { snapItem: FLib.DragSlider.Item; snapToEnd: boolean } => {
295
322
  let snapItem;
296
323
 
297
- const absXPos = Math.abs( xPos );
324
+ const absXPos = Math.abs(xPos);
298
325
 
299
- for ( const item of this.#itemArray ) {
300
- if ( item.info.left < absXPos ) {
326
+ for (const item of this.#itemArray) {
327
+ if (item.info.left < absXPos) {
301
328
  continue;
302
329
  }
303
330
 
304
- snapItem = item;
331
+ snapItem = item;
305
332
  break;
306
333
  }
307
334
 
308
335
  return {
309
- "snapItem": snapItem ? snapItem : this.#itemArray[ this.#itemArray.length - 1 ],
310
- "snapToEnd": !snapItem
336
+ snapItem: snapItem
337
+ ? snapItem
338
+ : this.#itemArray[this.#itemArray.length - 1],
339
+ snapToEnd: !snapItem,
311
340
  };
312
- }
313
-
341
+ };
314
342
 
315
- #getClosestItem = ( xPos: number ): { snapItem: FLib.DragSlider.Item, snapToEnd: boolean } => {
343
+ #getClosestItem = (
344
+ xPos: number
345
+ ): { snapItem: FLib.DragSlider.Item; snapToEnd: boolean } => {
316
346
  let lastDelta, snapItem;
317
347
 
318
- const absXPos = Math.abs( xPos );
348
+ const absXPos = Math.abs(xPos);
319
349
 
320
- for ( const item of this.#itemArray ) {
321
- const IS_LAST_DELTA = typeof lastDelta !== 'undefined';
322
- const newDelta = Math.abs( absXPos - item.info.left + this.#siteOffsetLeft );
350
+ for (const item of this.#itemArray) {
351
+ const IS_LAST_DELTA = typeof lastDelta !== "undefined";
352
+ const newDelta = Math.abs(
353
+ absXPos - item.info.left + this.#siteOffsetLeft
354
+ );
323
355
 
324
- if ( !IS_LAST_DELTA || newDelta <= lastDelta ) {
356
+ if (!IS_LAST_DELTA || newDelta <= lastDelta) {
325
357
  lastDelta = newDelta;
326
- snapItem = item;
358
+ snapItem = item;
327
359
  }
328
360
  }
329
361
 
330
362
  return {
331
363
  snapItem,
332
- snapToEnd: false
364
+ snapToEnd: false,
333
365
  };
334
- }
335
-
366
+ };
336
367
 
337
368
  #snapToItem = (): void => {
338
369
  let snapItem;
339
370
 
340
- const ABS_DELTA_X = Math.abs( this.#deltaMove.deltaX );
371
+ const ABS_DELTA_X = Math.abs(this.#deltaMove.deltaX);
341
372
 
342
373
  // If move a bit on right or left, juste move by one item only
343
- if ( ABS_DELTA_X >= this.#options.swipeTresholdMin && ABS_DELTA_X < Math.min( (this.#firstItem as FLib.DragSlider.Item ).info.width * this.#options.swipeTresholdSize, this.#options.swipeTresholdMin * 3 ) ) {
344
- if ( this.#deltaMove.deltaX < 0 ) {
345
- snapItem = this.#getFirstNextItem( this.#deltaMove.x );
346
- }
347
- else {
348
- snapItem = this.#getFirstPreviousItem( this.#deltaMove.x );
374
+ if (
375
+ ABS_DELTA_X >= this.#options.swipeTresholdMin &&
376
+ ABS_DELTA_X <
377
+ Math.min(
378
+ (this.#firstItem as FLib.DragSlider.Item).info.width *
379
+ this.#options.swipeTresholdSize,
380
+ this.#options.swipeTresholdMin * 3
381
+ )
382
+ ) {
383
+ if (this.#deltaMove.deltaX < 0) {
384
+ snapItem = this.#getFirstNextItem(this.#deltaMove.x);
385
+ } else {
386
+ snapItem = this.#getFirstPreviousItem(this.#deltaMove.x);
349
387
  }
350
- }
351
- else {
352
- snapItem = this.#getClosestItem( this.#deltaMove.x );
388
+ } else {
389
+ snapItem = this.#getClosestItem(this.#deltaMove.x);
353
390
  }
354
391
 
355
- if ( !snapItem ) {
392
+ if (!snapItem) {
356
393
  return;
357
394
  }
358
395
 
359
- this.#snapToItemAnimation( snapItem.snapItem ).then(() => {
360
- this.#options.onSnapEnd?.({
361
- "item": this.#currentSnapItem,
362
- "xPos": this.#deltaMove.x,
363
- "moveMaxSize": this.#listDelta,
364
- "isAtStart": this.#deltaMove.x === 0,
365
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
366
- "visibleItems": this.#visibleItems,
367
- "hiddenItems": this.#hiddenItems
368
- })
369
- });
370
- }
396
+ this.#snapToItemAnimation(snapItem.snapItem);
397
+ };
371
398
 
399
+ #getMaxMoveSize(): number {
400
+ return (
401
+ this.#viewportInfo.width -
402
+ this.#$list!.scrollWidth -
403
+ this.#siteOffsetLeft
404
+ );
405
+ }
372
406
 
373
- #onStartDrag = ( e: Event, $target: HTMLElement, coords: FLib.Events.Gesture.Coords ): void => {
374
- if ( !this.#hasAlreadyBeenDragged ) {
407
+ #onStartDrag = (
408
+ e: Event,
409
+ $target: HTMLElement,
410
+ coords: FLib.Events.Gesture.Coords
411
+ ): void => {
412
+ if (!this.#hasAlreadyBeenDragged) {
375
413
  this.#onResize();
376
414
  this.#hasAlreadyBeenDragged = true;
377
415
  }
378
416
 
379
- if ( !this.#isDraggingActive || !this.#$list ) {
417
+ if (!this.#isDraggingActive || !this.#$list) {
380
418
  return;
381
419
  }
382
420
 
383
421
  this.#isDragging = true;
384
422
 
385
- this.#options._animKill( this.#$list );
423
+ this.#options._animKill(this.#$list);
386
424
 
387
425
  this.#startDragCoords = coords;
388
- this.#listDelta = this.#viewportInfo.width - this.#$list.scrollWidth - this.#siteOffsetLeft - this.#siteOffsetRight;
389
- this.#deltaMove.newX = this.#deltaMove.x;
390
-
391
- gesture( document.body, 'dragSlider', {
392
- "move": this.#onMove,
393
- "end": this.#onStopDrag,
394
- "preventMove": e => {
395
- if ( !e.cancelable ) {
426
+ this.#listDelta = this.#getMaxMoveSize();
427
+ this.#deltaMove.newX = this.#deltaMove.x;
428
+
429
+ gesture(document.body, "dragSlider", {
430
+ move: this.#onMove,
431
+ end: this.#onStopDrag,
432
+ preventMove: (e) => {
433
+ if (!e.cancelable) {
396
434
  return false;
397
435
  }
398
436
 
399
- return !isTouchDevice ||
400
- isTouchDevice && Math.abs( this.#deltaMove.deltaY ) < Math.abs( this.#deltaMove.deltaX );
401
- }
402
- } );
403
-
404
- this.#options.onStartDrag?.( {
405
- "item": this.#currentSnapItem,
406
- "xPos": this.#deltaMove.x,
407
- "moveMaxSize": this.#listDelta,
408
- "isAtStart": this.#deltaMove.x === 0,
409
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
410
- "visibleItems": this.#visibleItems,
411
- "hiddenItems": this.#hiddenItems
412
- } );
413
- }
414
-
437
+ return (
438
+ !isTouchDevice ||
439
+ (isTouchDevice &&
440
+ Math.abs(this.#deltaMove.deltaY) <
441
+ Math.abs(this.#deltaMove.deltaX))
442
+ );
443
+ },
444
+ });
415
445
 
416
- #onMove = ( e: Event, $target: HTMLElement, coords: FLib.Events.Gesture.Coords ): void => {
417
- this.#cancelLinkClick();
446
+ this.#options.onStartDrag?.(
447
+ this.#getCallbackOptions(this.#deltaMove.x)
448
+ );
449
+ };
418
450
 
419
- this.#deltaMove.deltaX = coords.pageX - ( this.#startDragCoords as FLib.Events.Gesture.Coords ).pageX;
420
- this.#deltaMove.deltaY = coords.pageY - ( this.#startDragCoords as FLib.Events.Gesture.Coords ).pageY;
451
+ #onMove = (
452
+ e: Event,
453
+ $target: HTMLElement,
454
+ coords: FLib.Events.Gesture.Coords
455
+ ): void => {
456
+ this.#deltaMove.deltaX =
457
+ coords.pageX -
458
+ (this.#startDragCoords as FLib.Events.Gesture.Coords).pageX;
459
+ this.#deltaMove.deltaY =
460
+ coords.pageY -
461
+ (this.#startDragCoords as FLib.Events.Gesture.Coords).pageY;
421
462
 
422
463
  if (Math.abs(this.#deltaMove.deltaX) < MINIMUM_MOVEMENT_TO_START_DRAG) {
423
464
  return;
424
465
  }
425
466
 
426
- this.#deltaMove.newX = this.#deltaMove.deltaX + this.#deltaMove.x;
467
+ this.#cancelLinkClick();
427
468
 
428
- if ( this.#deltaMove.newX > 0 ) {
429
- this.#deltaMove.newX = 0;
430
- }
431
- else if ( this.#deltaMove.newX < this.#listDelta + this.#siteOffsetRight ) {
432
- this.#deltaMove.newX = this.#listDelta + this.#siteOffsetRight;
433
- }
469
+ this.#deltaMove.newX = this.#deltaMove.deltaX + this.#deltaMove.x;
470
+ this.#deltaMove.newX = Math.max(
471
+ Math.min(this.#minXPos, this.#deltaMove.newX),
472
+ this.#maxXPos
473
+ );
434
474
 
435
475
  this.#options._setCoordinates(this.#$list, this.#deltaMove.newX);
436
476
 
437
- this.#options.onDrag?.( {
438
- "item": this.#currentSnapItem,
439
- "xPos": this.#deltaMove.newX,
440
- "moveMaxSize": this.#listDelta,
441
- "isAtStart": this.#deltaMove.newX === 0,
442
- "isAtEnd": this.#deltaMove.newX === this.#listDelta,
443
- "visibleItems": this.#visibleItems,
444
- "hiddenItems": this.#hiddenItems
445
- } );
446
- }
447
-
477
+ this.#options.onDrag?.(this.#getCallbackOptions(this.#deltaMove.newX));
478
+ };
448
479
 
449
480
  #onStopDrag = (): void => {
450
- gestureOff( document.body, 'dragSlider' );
481
+ gestureOff(document.body, "dragSlider");
451
482
  this.#isDragging = false;
452
483
 
453
484
  this.#activeLinkClick();
@@ -460,138 +491,109 @@ export default class DragSlider {
460
491
 
461
492
  this.#snapToItem();
462
493
 
463
- this.#options.onStopDrag?.({
464
- "item": this.#currentSnapItem,
465
- "xPos": this.#deltaMove.x,
466
- "moveMaxSize": this.#listDelta,
467
- "isAtStart": this.#deltaMove.x === 0,
468
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
469
- "visibleItems": this.#visibleItems,
470
- "hiddenItems": this.#hiddenItems
471
- } );
472
- }
473
-
494
+ this.#options.onStopDrag?.(this.#getCallbackOptions(this.#deltaMove.x));
495
+ };
474
496
 
475
497
  #onMouseenter = (): void => {
476
- if ( this.#isDragging || !this.#isDraggingActive ) {
498
+ if (this.#isDragging || !this.#isDraggingActive) {
477
499
  return;
478
500
  }
479
501
 
480
- this.#options.onMouseEnter?.( {
481
- "item": this.#currentSnapItem,
482
- "xPos": this.#deltaMove.x,
483
- "moveMaxSize": this.#listDelta,
484
- "isAtStart": this.#deltaMove.x === 0,
485
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
486
- "visibleItems": this.#visibleItems,
487
- "hiddenItems": this.#hiddenItems
488
- } );
489
- }
490
-
502
+ this.#options.onMouseEnter?.(
503
+ this.#getCallbackOptions(this.#deltaMove.x)
504
+ );
505
+ };
491
506
 
492
507
  #onMouseleave = (): void => {
493
- if ( this.#isDragging || !this.#isDraggingActive ) {
508
+ if (this.#isDragging || !this.#isDraggingActive) {
494
509
  return;
495
510
  }
496
511
 
497
- this.#options.onMouseLeave?.( {
498
- "item": this.#currentSnapItem,
499
- "xPos": this.#deltaMove.x,
500
- "moveMaxSize": this.#listDelta,
501
- "isAtStart": this.#deltaMove.x === 0,
502
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
503
- "visibleItems": this.#visibleItems,
504
- "hiddenItems": this.#hiddenItems
505
- } );
506
- }
507
-
512
+ this.#options.onMouseLeave?.(
513
+ this.#getCallbackOptions(this.#deltaMove.x)
514
+ );
515
+ };
508
516
 
509
- #cancelDrag = ( e: Event ): void => {
517
+ #cancelDrag = (e: Event): void => {
510
518
  e.preventDefault();
511
- }
512
-
519
+ };
513
520
 
514
521
  next(): Promise<any> {
515
522
  const CURRENT_ITEM = this.#currentSnapItem as FLib.DragSlider.Item;
516
523
 
517
- if ( !this.#isDraggingActive || !this.#itemArray[ CURRENT_ITEM.index + 1 ] ) {
524
+ if (
525
+ !this.#isDraggingActive ||
526
+ !this.#itemArray[CURRENT_ITEM.index + 1]
527
+ ) {
518
528
  return Promise.resolve();
519
529
  }
520
530
 
521
- return this.#snapToItemAnimation( this.#itemArray[ CURRENT_ITEM.index + 1 ] );
531
+ return this.#snapToItemAnimation(
532
+ this.#itemArray[CURRENT_ITEM.index + 1]
533
+ );
522
534
  }
523
535
 
524
-
525
536
  previous(): Promise<any> {
526
537
  const CURRENT_ITEM = this.#currentSnapItem as FLib.DragSlider.Item;
527
538
 
528
- if ( !this.#isDraggingActive || CURRENT_ITEM.isFirst ) {
539
+ if (!this.#isDraggingActive || CURRENT_ITEM.isFirst) {
529
540
  return Promise.resolve();
530
541
  }
531
542
 
532
- return this.#snapToItemAnimation( this.#itemArray[ CURRENT_ITEM.index - 1 ] );
543
+ return this.#snapToItemAnimation(
544
+ this.#itemArray[CURRENT_ITEM.index - 1]
545
+ );
533
546
  }
534
547
 
535
-
536
- goToItem( blockOrIndex: HTMLElement | number ): Promise<any> {
537
-
538
- if ( !this.#isDraggingActive ) {
548
+ goToItem(blockOrIndex: HTMLElement | number): Promise<any> {
549
+ if (!this.#isDraggingActive) {
539
550
  return Promise.resolve();
540
551
  }
541
552
 
542
553
  let $block;
543
554
 
544
- if (typeof blockOrIndex === 'number') {
555
+ if (typeof blockOrIndex === "number") {
545
556
  $block = this.#$items?.[blockOrIndex] as HTMLElement;
546
- }
547
- else {
557
+ } else {
548
558
  $block = blockOrIndex;
549
559
  }
550
560
 
551
- if ( !$block ) {
561
+ if (!$block) {
552
562
  return Promise.resolve();
553
563
  }
554
564
 
555
- const ITEM = this.#itemMap.get( $block );
565
+ const ITEM = this.#itemMap.get($block);
556
566
 
557
- if ( !ITEM ) {
567
+ if (!ITEM) {
558
568
  return Promise.resolve();
559
569
  }
560
570
 
561
571
  this.#currentSnapItem = ITEM;
562
572
 
563
- this.#options.onSnap?.( {
564
- "item": ITEM,
565
- "xPos": this.#deltaMove.x,
566
- "moveMaxSize": this.#listDelta,
567
- "isAtStart": this.#deltaMove.x === 0,
568
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
569
- "visibleItems": this.#visibleItems,
570
- "hiddenItems": this.#hiddenItems
571
- } );
572
-
573
- return this.#options._animMoveItem(this.#$list, -1 * ITEM.info.left + this.#siteOffsetLeft, (x) => {
574
- this.#deltaMove.x = x;
575
-
576
- this.#options.onSnapUpdate?.( {
577
- "item": ITEM,
578
- "xPos": this.#deltaMove.x,
579
- "moveMaxSize": this.#listDelta,
580
- "isAtStart": this.#deltaMove.x === 0,
581
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
582
- "visibleItems": this.#visibleItems,
583
- "hiddenItems": this.#hiddenItems
584
- } );
585
- }).then(() => this.#updateAccessibilityFeature());
573
+ const xPos = -1 * ITEM.info.left + this.#siteOffsetLeft;
574
+
575
+ this.#options.onSnap?.(this.#getCallbackOptions(xPos, ITEM));
576
+
577
+ return this.#options
578
+ ._animMoveItem(this.#$list, xPos, (x) => {
579
+ this.#deltaMove.x = x;
580
+
581
+ this.#options.onSnapUpdate?.(
582
+ this.#getCallbackOptions(this.#deltaMove.x, ITEM)
583
+ );
584
+ })
585
+ .then(() => this.#updateAccessibilityFeature());
586
586
  }
587
587
 
588
588
  #updateAccessibilityFeature = (): void => {
589
589
  this.#visibleItems.length = 0;
590
590
  this.#hiddenItems.length = 0;
591
591
 
592
- this.#itemMap.forEach(item => {
592
+ this.#itemMap.forEach((item) => {
593
593
  const hideElement1 = item.info.left + this.#deltaMove.x < 0;
594
- const hideElement2 = item.info.left + item.info.width + this.#deltaMove.x > this.#viewportInfo.width;
594
+ const hideElement2 =
595
+ item.info.left + item.info.width + this.#deltaMove.x >
596
+ this.#viewportInfo.width;
595
597
 
596
598
  if (hideElement1 || hideElement2) {
597
599
  item.$item.setAttribute("tabindex", "-1");
@@ -606,132 +608,128 @@ export default class DragSlider {
606
608
  item.$item.setAttribute("aria-hidden", "false");
607
609
  this.#visibleItems.push(item);
608
610
  });
609
- }
611
+ };
610
612
 
611
613
  refresh = (): this => {
612
614
  this.#onResize();
613
615
 
614
616
  return this;
615
- }
617
+ };
616
618
 
617
619
  init = (): this => {
618
- if ( this.#isInitialized ) {
620
+ if (this.#isInitialized) {
619
621
  return this;
620
622
  }
621
623
 
622
624
  this.#isInitialized = true;
623
625
 
624
- if ( !this.#$viewport ) {
625
- const $VP = this.#$slider.querySelector( this.#options.viewportSelector );
626
- if ( !$VP ) {
627
- throw `"${ this.#options.viewportSelector }" not found`;
626
+ if (!this.#$viewport) {
627
+ const $VP = this.#$slider.querySelector(
628
+ this.#options.viewportSelector
629
+ );
630
+ if (!$VP) {
631
+ throw `"${this.#options.viewportSelector}" not found`;
628
632
  }
629
- this.#$viewport = $VP as HTMLElement;
633
+ this.#$viewport = $VP as HTMLElement;
630
634
 
631
- const $LST = this.#$viewport.querySelector( this.#options.listSelector );
632
- if ( !$LST ) {
633
- throw `"${ this.#options.listSelector }" not found`;
635
+ const $LST = this.#$viewport.querySelector(
636
+ this.#options.listSelector
637
+ );
638
+ if (!$LST) {
639
+ throw `"${this.#options.listSelector}" not found`;
634
640
  }
635
- this.#$list = $LST as HTMLElement;
641
+ this.#$list = $LST as HTMLElement;
636
642
 
637
- const $ITEMS = this.#$list.querySelectorAll( this.#options.itemSelector );
638
- if ( !$ITEMS ) {
639
- throw `"${ this.#options.itemSelector }" not found`;
643
+ const $ITEMS = this.#$list.querySelectorAll(
644
+ this.#options.itemSelector
645
+ );
646
+ if (!$ITEMS) {
647
+ throw `"${this.#options.itemSelector}" not found`;
640
648
  }
641
- this.#$items = $ITEMS as NodeList;
649
+ this.#$items = $ITEMS as NodeList;
642
650
 
643
- this.#debouncedOnResize = debounce( this.#onResize );
651
+ this.#debouncedOnResize = debounce(this.#onResize);
644
652
  }
645
653
 
646
- if ( !this.#$items?.length ) {
654
+ if (!this.#$items?.length) {
647
655
  return this;
648
656
  }
649
657
 
650
- aClass( this.#$slider, 'is-active' );
658
+ aClass(this.#$slider, "is-active");
651
659
 
652
660
  this.#onResize();
653
661
 
654
- on( window, {
655
- "eventsName": "resize",
656
- "callback": this.#debouncedOnResize
657
- } );
662
+ on(window, {
663
+ eventsName: "resize",
664
+ callback: this.#debouncedOnResize,
665
+ });
658
666
 
659
- gesture( this.#$viewport, 'dragSlider', {
660
- "start": this.#onStartDrag
661
- } );
667
+ gesture(this.#$viewport, "dragSlider", {
668
+ start: this.#onStartDrag,
669
+ });
662
670
 
663
671
  // Avoid image or content drag on Firefox
664
- on( this.#$items, {
665
- "eventsName": "dragstart",
666
- "callback": this.#cancelDrag
667
- } );
668
-
669
- on( this.#$viewport, {
670
- "eventsName": "mouseenter",
671
- "callback": this.#onMouseenter
672
- } );
673
-
674
- on( this.#$viewport, {
675
- "eventsName": "mouseleave",
676
- "callback": this.#onMouseleave
677
- } );
678
-
679
- this.#options.onInit?.( {
680
- "item": this.#currentSnapItem,
681
- "xPos": this.#deltaMove.x,
682
- "moveMaxSize": this.#listDelta,
683
- "isAtStart": this.#deltaMove.x === 0,
684
- "isAtEnd": this.#deltaMove.x === this.#listDelta,
685
- "visibleItems": this.#visibleItems,
686
- "hiddenItems": this.#hiddenItems
687
- } );
672
+ on(this.#$items, {
673
+ eventsName: "dragstart",
674
+ callback: this.#cancelDrag,
675
+ });
688
676
 
689
- return this;
690
- }
677
+ on(this.#$viewport, {
678
+ eventsName: "mouseenter",
679
+ callback: this.#onMouseenter,
680
+ });
681
+
682
+ on(this.#$viewport, {
683
+ eventsName: "mouseleave",
684
+ callback: this.#onMouseleave,
685
+ });
686
+
687
+ this.#options.onInit?.(this.#getCallbackOptions(this.#deltaMove.x));
691
688
 
689
+ return this;
690
+ };
692
691
 
693
692
  destroy(): this {
694
- this.#isInitialized = false;
693
+ this.#isInitialized = false;
695
694
  this.#hasAlreadyBeenDragged = false;
696
695
 
697
- if ( !this.#$items?.length ) {
696
+ if (!this.#$items?.length) {
698
697
  return this;
699
698
  }
700
699
 
701
- off( window, {
702
- "eventsName": "resize",
703
- "callback": this.#debouncedOnResize
704
- } );
700
+ off(window, {
701
+ eventsName: "resize",
702
+ callback: this.#debouncedOnResize,
703
+ });
705
704
 
706
- this.#$viewport && gestureOff( this.#$viewport, 'dragSlider' );
705
+ this.#$viewport && gestureOff(this.#$viewport, "dragSlider");
707
706
 
708
- gestureOff( document.body, 'dragSlider' );
707
+ gestureOff(document.body, "dragSlider");
709
708
 
710
- off( this.#$items, {
711
- "eventsName": "dragstart",
712
- "callback": this.#cancelDrag
713
- } );
709
+ off(this.#$items, {
710
+ eventsName: "dragstart",
711
+ callback: this.#cancelDrag,
712
+ });
714
713
 
715
- off( this.#$viewport, {
716
- "eventsName": "mouseenter",
717
- "callback": this.#onMouseenter
718
- } );
714
+ off(this.#$viewport, {
715
+ eventsName: "mouseenter",
716
+ callback: this.#onMouseenter,
717
+ });
719
718
 
720
- off( this.#$viewport, {
721
- "eventsName": "mouseleave",
722
- "callback": this.#onMouseleave
723
- } );
719
+ off(this.#$viewport, {
720
+ eventsName: "mouseleave",
721
+ callback: this.#onMouseleave,
722
+ });
724
723
 
725
- if ( this.#$list ) {
726
- this.#options._animKill( this.#$list );
727
- this.#options._animClear( this.#$list );
724
+ if (this.#$list) {
725
+ this.#options._animKill(this.#$list);
726
+ this.#options._animClear(this.#$list);
728
727
  }
729
728
 
730
- this.#$viewport && rClass( this.#$viewport, this.#options.dragClass );
729
+ this.#$viewport && rClass(this.#$viewport, this.#options.dragClass);
731
730
 
732
- rClass( this.#$slider, 'is-active' );
731
+ rClass(this.#$slider, "is-active");
733
732
 
734
733
  return this;
735
734
  }
736
-
737
735
  }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.28
3
+ @version: 7.1.30
4
4
 
5
5
 
6
6
  ## Use
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@creative-web-solution/front-library",
3
3
  "title": "Frontend library",
4
4
  "description": "Frontend functions and modules",
5
- "version": "7.1.28",
5
+ "version": "7.1.30",
6
6
  "homepage": "https://github.com/creative-web-solution/front-library",
7
7
  "author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
8
8
  "keywords": [],