@creative-web-solution/front-library 7.1.17 → 7.1.18

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,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 7.1.18
4
+
5
+ * [DragSlider] Expose some properties + allow item index in goToItem function
3
6
 
4
7
  ## 7.1.17
5
8
 
@@ -39,10 +39,22 @@ export default class DragSlider {
39
39
  #debouncedOnResize;
40
40
 
41
41
 
42
+ get count(): number {
43
+ return this.#$items?.length ?? 0;
44
+ }
45
+
46
+ get currentSnapItem(): FLib.DragSlider.Item | undefined {
47
+ return this.#currentSnapItem;
48
+ }
49
+
42
50
  get isActive(): boolean {
43
51
  return this.#isDraggingActive;
44
52
  }
45
53
 
54
+ get items(): NodeList | undefined {
55
+ return this.#$items;
56
+ }
57
+
46
58
 
47
59
  constructor( $slider: HTMLElement, options: Partial<FLib.DragSlider.Options> ) {
48
60
 
@@ -257,13 +269,13 @@ export default class DragSlider {
257
269
 
258
270
 
259
271
  #getClosestItem = ( xPos: number ): { snapItem: FLib.DragSlider.Item, snapToEnd: boolean } => {
260
- let lastDelta, snapItem, snapToEnd = false;
272
+ let lastDelta, snapItem;
261
273
 
262
274
  const absXPos = Math.abs( xPos );
263
275
 
264
276
  for ( const item of this.#itemArray ) {
265
277
  const IS_LAST_DELTA = typeof lastDelta !== 'undefined';
266
- let newDelta = Math.abs( absXPos - item.info.left + this.#siteOffsetLeft );
278
+ const newDelta = Math.abs( absXPos - item.info.left + this.#siteOffsetLeft );
267
279
 
268
280
  if ( !IS_LAST_DELTA || newDelta <= lastDelta ) {
269
281
  lastDelta = newDelta;
@@ -273,7 +285,7 @@ export default class DragSlider {
273
285
 
274
286
  return {
275
287
  snapItem,
276
- snapToEnd
288
+ snapToEnd: false
277
289
  };
278
290
  }
279
291
 
@@ -453,12 +465,25 @@ export default class DragSlider {
453
465
  }
454
466
 
455
467
 
456
- goToItem( $block: HTMLElement ): gsap.core.Tween | void {
468
+ goToItem( blockOrIndex: HTMLElement | number ): gsap.core.Tween | void {
457
469
 
458
470
  if ( !this.#isDraggingActive ) {
459
471
  return;
460
472
  }
461
473
 
474
+ let $block;
475
+
476
+ if (typeof blockOrIndex === 'number') {
477
+ $block = this.#$items?.[blockOrIndex] as HTMLElement;
478
+ }
479
+ else {
480
+ $block = blockOrIndex;
481
+ }
482
+
483
+ if ( !$block ) {
484
+ return;
485
+ }
486
+
462
487
  const ITEM = this.#itemMap.get( $block );
463
488
 
464
489
  if ( !ITEM ) {
@@ -494,8 +519,10 @@ export default class DragSlider {
494
519
  } );
495
520
  }
496
521
 
497
- refresh = () => {
522
+ refresh = (): this => {
498
523
  this.#onResize();
524
+
525
+ return this;
499
526
  }
500
527
 
501
528
  init = (): this => {
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.17
3
+ @version: 7.1.18
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.17",
5
+ "version": "7.1.18",
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": [],