@creative-web-solution/front-library 7.1.3 → 7.1.4
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 +7 -0
- package/Events/HistoryController.ts +11 -12
- package/Helpers/Debounce.ts +1 -1
- package/Modules/DragSlider.ts +40 -35
- package/Modules/ScrollSnap.ts +12 -8
- package/Modules/SkinSelect.ts +15 -11
- package/README.md +1 -1
- package/Types/EventsHelpers.d.ts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { on } from './EventsManager';
|
|
2
|
-
import { UrlParser } from '../Helpers/UrlParser';
|
|
3
2
|
import { slice } from '../Helpers/Slice';
|
|
4
3
|
|
|
5
4
|
|
|
@@ -33,7 +32,7 @@ export default class HistoryController {
|
|
|
33
32
|
#hasPushstate: boolean;
|
|
34
33
|
#hasPopStateEvent: boolean;
|
|
35
34
|
#currentState: FLib.Events.History.StateObject;
|
|
36
|
-
#registeredFunctionList: (( url:
|
|
35
|
+
#registeredFunctionList: (( url: URL, state: any ) => void)[];
|
|
37
36
|
|
|
38
37
|
|
|
39
38
|
get state(): FLib.Events.History.StateObject {
|
|
@@ -53,7 +52,7 @@ export default class HistoryController {
|
|
|
53
52
|
this.#defaultTitle = encodeURIComponent( defaultTitle );
|
|
54
53
|
|
|
55
54
|
this.#currentState = {
|
|
56
|
-
"url": new
|
|
55
|
+
"url": new window.URL( window.location.href ),
|
|
57
56
|
"state": {},
|
|
58
57
|
"title": this.#defaultTitle
|
|
59
58
|
};
|
|
@@ -69,7 +68,7 @@ export default class HistoryController {
|
|
|
69
68
|
|
|
70
69
|
|
|
71
70
|
// Call each registered function for popstate event
|
|
72
|
-
#callRegisteredFunction = ( url:
|
|
71
|
+
#callRegisteredFunction = ( url: URL, state: any ): void => {
|
|
73
72
|
if ( !this.#registeredFunctionList.length ) {
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
@@ -87,7 +86,7 @@ export default class HistoryController {
|
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
this.#currentState = {
|
|
90
|
-
"url": new
|
|
89
|
+
"url": new URL( document.location.href ),
|
|
91
90
|
state,
|
|
92
91
|
"title": ""
|
|
93
92
|
};
|
|
@@ -101,15 +100,15 @@ export default class HistoryController {
|
|
|
101
100
|
*
|
|
102
101
|
* @param state - Native browser state object
|
|
103
102
|
*/
|
|
104
|
-
pushState( state: any, title: string, url: string |
|
|
103
|
+
pushState( state: any, title: string, url: string | URL ): this {
|
|
105
104
|
if ( !this.#hasPushstate ) {
|
|
106
105
|
return this;
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
url = url instanceof
|
|
108
|
+
url = url instanceof URL ? url : new URL( url as string );
|
|
110
109
|
|
|
111
110
|
this.#currentState = {
|
|
112
|
-
"url": url as
|
|
111
|
+
"url": url as URL,
|
|
113
112
|
state,
|
|
114
113
|
"title": title ? encodeURIComponent( title ) : this.#defaultTitle
|
|
115
114
|
};
|
|
@@ -118,7 +117,7 @@ export default class HistoryController {
|
|
|
118
117
|
window.history.pushState(
|
|
119
118
|
state,
|
|
120
119
|
this.#currentState.title,
|
|
121
|
-
this.#currentState.url.
|
|
120
|
+
this.#currentState.url.href
|
|
122
121
|
);
|
|
123
122
|
}
|
|
124
123
|
catch ( e ) {
|
|
@@ -137,14 +136,14 @@ export default class HistoryController {
|
|
|
137
136
|
return this;
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
anchor = anchor.indexOf( '#' ) === -1 ? anchor : anchor
|
|
139
|
+
anchor = anchor.indexOf( '#' ) === -1 ? `#${ anchor }` : anchor;
|
|
141
140
|
|
|
142
141
|
try {
|
|
143
|
-
this.#currentState.url.
|
|
142
|
+
this.#currentState.url.hash = anchor.indexOf( '#' ) === -1 ? `#${ anchor }` : anchor;
|
|
144
143
|
window.history.pushState(
|
|
145
144
|
this.#currentState.state,
|
|
146
145
|
this.#currentState.title,
|
|
147
|
-
this.#currentState.url.
|
|
146
|
+
this.#currentState.url.href
|
|
148
147
|
);
|
|
149
148
|
}
|
|
150
149
|
catch ( e ) {
|
package/Helpers/Debounce.ts
CHANGED
package/Modules/DragSlider.ts
CHANGED
|
@@ -20,17 +20,17 @@ export default class DragSlider {
|
|
|
20
20
|
#$slider: HTMLElement;
|
|
21
21
|
#viewportInfo;
|
|
22
22
|
#siteOffset;
|
|
23
|
-
#listDelta
|
|
24
|
-
#$viewport
|
|
25
|
-
#$items
|
|
26
|
-
#$list
|
|
27
|
-
#isDragging
|
|
28
|
-
#itemMap
|
|
29
|
-
#firstItem
|
|
30
|
-
#currentSnapItem
|
|
31
|
-
#hasAlreadyBeenDragged
|
|
32
|
-
#startDragCoords
|
|
33
|
-
#isInitialized
|
|
23
|
+
#listDelta = 0;
|
|
24
|
+
#$viewport: HTMLElement | undefined;
|
|
25
|
+
#$items: NodeList | undefined;
|
|
26
|
+
#$list: HTMLElement | undefined;
|
|
27
|
+
#isDragging = false;
|
|
28
|
+
#itemMap = new Map<HTMLElement, FLib.DragSlider.Item>();
|
|
29
|
+
#firstItem: FLib.DragSlider.Item | undefined;
|
|
30
|
+
#currentSnapItem: FLib.DragSlider.Item | undefined;
|
|
31
|
+
#hasAlreadyBeenDragged = false;
|
|
32
|
+
#startDragCoords: FLib.Events.Gesture.Coords | undefined;
|
|
33
|
+
#isInitialized = false;
|
|
34
34
|
#debouncedOnResize;
|
|
35
35
|
|
|
36
36
|
|
|
@@ -40,6 +40,7 @@ export default class DragSlider {
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
constructor( $slider: HTMLElement, options: Partial<FLib.DragSlider.Options> ) {
|
|
43
|
+
|
|
43
44
|
if ( !options.viewportSelector || !options.listSelector || !options.itemSelector || !options.dragClass ) {
|
|
44
45
|
throw '[Drag Slider]: Missing at least one of viewportSelector, listSelector, itemSelector, dragClass';
|
|
45
46
|
}
|
|
@@ -80,7 +81,10 @@ export default class DragSlider {
|
|
|
80
81
|
|
|
81
82
|
|
|
82
83
|
#onResize = (): void => {
|
|
83
|
-
|
|
84
|
+
if ( !this.#$items || !this.#$list ) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.#viewportInfo = offset( this.#$viewport as HTMLElement );
|
|
84
88
|
this.#siteOffset = parseInt( prop( (this.#$items[ 0 ] as HTMLElement), 'marginLeft' ), 10 );
|
|
85
89
|
this.#listDelta = this.#viewportInfo.width - this.#$list.scrollWidth;
|
|
86
90
|
|
|
@@ -105,6 +109,8 @@ export default class DragSlider {
|
|
|
105
109
|
|
|
106
110
|
this.#itemArray.length = 0;
|
|
107
111
|
|
|
112
|
+
const LAST_INDEX = this.#$items.length;
|
|
113
|
+
|
|
108
114
|
this.#$items.forEach( ( $item: Node, index: number ) => {
|
|
109
115
|
const $ITEM = $item as HTMLElement;
|
|
110
116
|
const ITEM_OFFSET = offset( $ITEM, false, this.#$list );
|
|
@@ -112,7 +118,7 @@ export default class DragSlider {
|
|
|
112
118
|
this.#itemArray.push({
|
|
113
119
|
index,
|
|
114
120
|
"isFirst": index === 0,
|
|
115
|
-
"isLast": index ===
|
|
121
|
+
"isLast": index === LAST_INDEX - 1 || ITEM_OFFSET.left > Math.abs( this.#listDelta ),
|
|
116
122
|
"$item": $ITEM,
|
|
117
123
|
"info": ITEM_OFFSET
|
|
118
124
|
});
|
|
@@ -161,7 +167,7 @@ export default class DragSlider {
|
|
|
161
167
|
|
|
162
168
|
this.#currentSnapItem = snapItem;
|
|
163
169
|
|
|
164
|
-
const TWEEN = gsap.to( this.#$list, {
|
|
170
|
+
const TWEEN = gsap.to( this.#$list as HTMLElement, {
|
|
165
171
|
"duration": 0.3,
|
|
166
172
|
"x": finalX,
|
|
167
173
|
"y": 0,
|
|
@@ -276,7 +282,7 @@ export default class DragSlider {
|
|
|
276
282
|
|
|
277
283
|
const ABS_DELTA_X = Math.abs( this.#deltaMove.deltaX );
|
|
278
284
|
|
|
279
|
-
if ( ABS_DELTA_X >= this.#options.swipeTresholdMin && ABS_DELTA_X < Math.min( this.#firstItem.info.width * this.#options.swipeTresholdSize, this.#options.swipeTresholdMin * 3 ) ) {
|
|
285
|
+
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 ) ) {
|
|
280
286
|
if ( this.#deltaMove.deltaX < 0 ) {
|
|
281
287
|
snapItem = this.#getFirstNextItem( this.#deltaMove.x );
|
|
282
288
|
}
|
|
@@ -302,7 +308,7 @@ export default class DragSlider {
|
|
|
302
308
|
this.#hasAlreadyBeenDragged = true;
|
|
303
309
|
}
|
|
304
310
|
|
|
305
|
-
if ( !this.#isDraggingActive ) {
|
|
311
|
+
if ( !this.#isDraggingActive || !this.#$list ) {
|
|
306
312
|
return;
|
|
307
313
|
}
|
|
308
314
|
|
|
@@ -339,8 +345,8 @@ export default class DragSlider {
|
|
|
339
345
|
#onMove = ( e: Event, $target: HTMLElement, coords: FLib.Events.Gesture.Coords ): void => {
|
|
340
346
|
this.#cancelLinkClick();
|
|
341
347
|
|
|
342
|
-
this.#deltaMove.deltaX = coords.pageX - this.#startDragCoords.pageX;
|
|
343
|
-
this.#deltaMove.deltaY = coords.pageY - this.#startDragCoords.pageY;
|
|
348
|
+
this.#deltaMove.deltaX = coords.pageX - ( this.#startDragCoords as FLib.Events.Gesture.Coords ).pageX;
|
|
349
|
+
this.#deltaMove.deltaY = coords.pageY - ( this.#startDragCoords as FLib.Events.Gesture.Coords ).pageY;
|
|
344
350
|
|
|
345
351
|
this.#deltaMove.newX = this.#deltaMove.deltaX + this.#deltaMove.x;
|
|
346
352
|
|
|
@@ -351,7 +357,7 @@ export default class DragSlider {
|
|
|
351
357
|
this.#deltaMove.newX = this.#listDelta;
|
|
352
358
|
}
|
|
353
359
|
|
|
354
|
-
gsap.set( this.#$list, {
|
|
360
|
+
gsap.set( this.#$list as HTMLElement, {
|
|
355
361
|
"x": this.#deltaMove.newX,
|
|
356
362
|
"y": 0,
|
|
357
363
|
"z": 0
|
|
@@ -424,20 +430,20 @@ export default class DragSlider {
|
|
|
424
430
|
|
|
425
431
|
|
|
426
432
|
next(): gsap.core.Tween | void {
|
|
427
|
-
if ( !this.#isDraggingActive || this.#currentSnapItem.isLast ) {
|
|
433
|
+
if ( !this.#isDraggingActive || ( this.#currentSnapItem as FLib.DragSlider.Item ).isLast ) {
|
|
428
434
|
return;
|
|
429
435
|
}
|
|
430
436
|
|
|
431
|
-
return this.#snapToItemAnimation( this.#itemArray[ this.#currentSnapItem.index + 1 ] );
|
|
437
|
+
return this.#snapToItemAnimation( this.#itemArray[ ( this.#currentSnapItem as FLib.DragSlider.Item ).index + 1 ] );
|
|
432
438
|
}
|
|
433
439
|
|
|
434
440
|
|
|
435
441
|
previous(): gsap.core.Tween | void {
|
|
436
|
-
if ( !this.#isDraggingActive || this.#currentSnapItem.isFirst ) {
|
|
442
|
+
if ( !this.#isDraggingActive || ( this.#currentSnapItem as FLib.DragSlider.Item ).isFirst ) {
|
|
437
443
|
return;
|
|
438
444
|
}
|
|
439
445
|
|
|
440
|
-
return this.#snapToItemAnimation( this.#itemArray[ this.#currentSnapItem.index - 1 ] );
|
|
446
|
+
return this.#snapToItemAnimation( this.#itemArray[ ( this.#currentSnapItem as FLib.DragSlider.Item ).index - 1 ] );
|
|
441
447
|
}
|
|
442
448
|
|
|
443
449
|
|
|
@@ -461,7 +467,7 @@ export default class DragSlider {
|
|
|
461
467
|
"isAtEnd": this.#deltaMove.x === this.#listDelta
|
|
462
468
|
} );
|
|
463
469
|
|
|
464
|
-
return gsap.to( this.#$list, {
|
|
470
|
+
return gsap.to( this.#$list as HTMLElement, {
|
|
465
471
|
"duration": 0.3,
|
|
466
472
|
"x": -1 * ITEM.info.left + this.#siteOffset,
|
|
467
473
|
"y": 0,
|
|
@@ -491,8 +497,6 @@ export default class DragSlider {
|
|
|
491
497
|
this.#isInitialized = true;
|
|
492
498
|
|
|
493
499
|
if ( !this.#$viewport ) {
|
|
494
|
-
this.#itemMap = new Map();
|
|
495
|
-
|
|
496
500
|
const $VP = this.#$slider.querySelector( this.#options.viewportSelector );
|
|
497
501
|
if ( !$VP ) {
|
|
498
502
|
throw `"${ this.#options.viewportSelector }" not found`;
|
|
@@ -514,7 +518,7 @@ export default class DragSlider {
|
|
|
514
518
|
this.#debouncedOnResize = debounce( this.#onResize );
|
|
515
519
|
}
|
|
516
520
|
|
|
517
|
-
if ( !this.#$items
|
|
521
|
+
if ( !this.#$items?.length ) {
|
|
518
522
|
return this;
|
|
519
523
|
}
|
|
520
524
|
|
|
@@ -563,7 +567,7 @@ export default class DragSlider {
|
|
|
563
567
|
this.#isInitialized = false;
|
|
564
568
|
this.#hasAlreadyBeenDragged = false;
|
|
565
569
|
|
|
566
|
-
if ( !this.#$items
|
|
570
|
+
if ( !this.#$items?.length ) {
|
|
567
571
|
return this;
|
|
568
572
|
}
|
|
569
573
|
|
|
@@ -572,7 +576,7 @@ export default class DragSlider {
|
|
|
572
576
|
"callback": this.#debouncedOnResize
|
|
573
577
|
} );
|
|
574
578
|
|
|
575
|
-
gestureOff( this.#$viewport, 'dragSlider' );
|
|
579
|
+
this.#$viewport && gestureOff( this.#$viewport, 'dragSlider' );
|
|
576
580
|
|
|
577
581
|
gestureOff( document.body, 'dragSlider' );
|
|
578
582
|
|
|
@@ -591,14 +595,15 @@ export default class DragSlider {
|
|
|
591
595
|
"callback": this.#onMouseleave
|
|
592
596
|
} );
|
|
593
597
|
|
|
598
|
+
if ( this.#$list ) {
|
|
599
|
+
gsap.killTweensOf( this.#$list );
|
|
594
600
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
} );
|
|
601
|
+
gsap.set( this.#$list, {
|
|
602
|
+
"clearProps": "all"
|
|
603
|
+
} );
|
|
604
|
+
}
|
|
600
605
|
|
|
601
|
-
rClass( this.#$viewport, this.#options.dragClass );
|
|
606
|
+
this.#$viewport && rClass( this.#$viewport, this.#options.dragClass );
|
|
602
607
|
|
|
603
608
|
rClass( this.#$slider, 'is-active' );
|
|
604
609
|
|
package/Modules/ScrollSnap.ts
CHANGED
|
@@ -35,12 +35,12 @@ function getPosition( start, end, elapsed, duration ) {
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
class ScrollTo {
|
|
38
|
-
#startTime
|
|
38
|
+
#startTime: number | undefined;
|
|
39
39
|
#animationFrame;
|
|
40
|
-
#duration
|
|
41
|
-
#startPosition
|
|
42
|
-
#snapItem
|
|
43
|
-
#snapItemType
|
|
40
|
+
#duration: number | undefined;
|
|
41
|
+
#startPosition: number | undefined;
|
|
42
|
+
#snapItem: FLib.ScrollSnap.Item | undefined;
|
|
43
|
+
#snapItemType: FLib.ScrollSnap.SnapType | undefined;
|
|
44
44
|
#scrollPropName: FLib.ScrollSnap.ScrollPropertyType;
|
|
45
45
|
#$element: HTMLElement;
|
|
46
46
|
#callback: FLib.ScrollSnap.ScrollToCallback;
|
|
@@ -54,6 +54,10 @@ class ScrollTo {
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
#step = ( timestamp: number ) => {
|
|
57
|
+
if ( !this.#snapItem ) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
57
61
|
if ( !this.#startTime ) {
|
|
58
62
|
this.#startTime = timestamp;
|
|
59
63
|
}
|
|
@@ -69,13 +73,13 @@ class ScrollTo {
|
|
|
69
73
|
);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
if ( elapsed < this.#duration ) {
|
|
76
|
+
if ( elapsed < (this.#duration as number) ) {
|
|
73
77
|
this.#animationFrame = window.requestAnimationFrame( this.#step.bind( this ) );
|
|
74
78
|
}
|
|
75
79
|
else {
|
|
76
80
|
if ( typeof this.#callback === 'function' ) {
|
|
77
81
|
window.requestAnimationFrame( () => {
|
|
78
|
-
this.#callback( this.#snapItem, this.#snapItemType );
|
|
82
|
+
this.#callback( this.#snapItem as FLib.ScrollSnap.Item, this.#snapItemType as FLib.ScrollSnap.SnapType );
|
|
79
83
|
} );
|
|
80
84
|
}
|
|
81
85
|
}
|
|
@@ -98,7 +102,7 @@ class ScrollTo {
|
|
|
98
102
|
if ( !delta ) {
|
|
99
103
|
if ( typeof this.#callback === 'function' ) {
|
|
100
104
|
window.requestAnimationFrame( () => {
|
|
101
|
-
this.#callback( this.#snapItem, this.#snapItemType );
|
|
105
|
+
this.#callback( this.#snapItem as FLib.ScrollSnap.Item, this.#snapItemType as FLib.ScrollSnap.SnapType );
|
|
102
106
|
} );
|
|
103
107
|
}
|
|
104
108
|
return;
|
package/Modules/SkinSelect.ts
CHANGED
|
@@ -38,26 +38,26 @@ const defaultOptions: FLib.SkinSelect.Options = {
|
|
|
38
38
|
* You can access the skin API in the __skinAPI property of the $select HTMLElement or its wrapper.
|
|
39
39
|
*/
|
|
40
40
|
export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
|
|
41
|
-
#$select
|
|
42
|
-
#loading
|
|
41
|
+
#$select!: FLib.SkinSelect.CustomSelect;
|
|
42
|
+
#loading = false;
|
|
43
43
|
#options!: FLib.SkinSelect.Options;
|
|
44
44
|
#extraClass!: string;
|
|
45
45
|
#$parent!: FLib.SkinSelect.CustomSelectParent;
|
|
46
46
|
#$title!: HTMLElement;
|
|
47
|
-
#isListOpened
|
|
48
|
-
#$options
|
|
49
|
-
#$lastOption
|
|
50
|
-
#focusedItemIndex
|
|
51
|
-
#$layer
|
|
47
|
+
#isListOpened = false;
|
|
48
|
+
#$options: NodeList | undefined;
|
|
49
|
+
#$lastOption: HTMLElement | null = null;
|
|
50
|
+
#focusedItemIndex = -1;
|
|
51
|
+
#$layer: HTMLElement | undefined;
|
|
52
52
|
|
|
53
|
-
constructor( $select:
|
|
53
|
+
constructor( $select: FLib.SkinSelect.CustomSelect, userOptions?: Partial<FLib.SkinSelect.Options> ) {
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if ( this.#$select.hasAttribute( 'multiple' ) || this.#$select.__skinAPI ) {
|
|
55
|
+
if ( $select.hasAttribute( 'multiple' ) || $select.__skinAPI ) {
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
58
|
|
|
59
|
+
this.#$select = $select;
|
|
60
|
+
|
|
61
61
|
this.#loading = false;
|
|
62
62
|
|
|
63
63
|
this.#options = extend( defaultOptions, userOptions );
|
|
@@ -420,6 +420,10 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
|
|
|
420
420
|
|
|
421
421
|
|
|
422
422
|
#focusItem = ( index: number ): void => {
|
|
423
|
+
if ( !this.#$options ) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
423
427
|
if ( index < 0 ) {
|
|
424
428
|
index = this.#$options.length - 1;
|
|
425
429
|
}
|
package/README.md
CHANGED
package/Types/EventsHelpers.d.ts
CHANGED
|
@@ -179,12 +179,12 @@ declare namespace FLib {
|
|
|
179
179
|
*/
|
|
180
180
|
namespace History {
|
|
181
181
|
type StateObject = {
|
|
182
|
-
url:
|
|
182
|
+
url: URL;
|
|
183
183
|
state: any;
|
|
184
184
|
title: string;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
type Callback = ( url:
|
|
187
|
+
type Callback = ( url: URL, state: any ) => void;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
|
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.
|
|
5
|
+
"version": "7.1.4",
|
|
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": [],
|