@creative-web-solution/front-library 7.0.6 → 7.1.2
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 +30 -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 +5 -6
- 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 +95 -0
- package/Helpers/Type.ts +1 -14
- package/Helpers/Unique.ts +3 -3
- package/Helpers/UrlParser.ts +14 -23
- package/Helpers/Wait.ts +1 -1
- package/Modules/Accordion/Tab.ts +19 -17
- package/Modules/Accordion/index.ts +27 -19
- 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 +12 -12
- package/Modules/Popin/PopinController.ts +24 -30
- package/Modules/Popin/Tools.ts +18 -19
- package/Modules/QuickTemplate.ts +4 -6
- package/Modules/ScrollSnap.ts +110 -104
- package/Modules/SkinCheckbox.ts +52 -38
- package/Modules/SkinFile.ts +63 -53
- package/Modules/SkinRadio.ts +63 -43
- package/Modules/SkinSelect.ts +117 -101
- 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 +28 -24
- package/Modules/Tabs/index.ts +36 -26
- package/Modules/Validator/Date.ts +2 -1
- package/Modules/Validator/Equals.ts +1 -1
- package/Modules/Validator/Internal/Input.ts +366 -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 +41 -0
- package/Types/Autocomplete.d.ts +94 -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 +63 -0
- package/Types/Notifications.d.ts +48 -44
- package/Types/Popin.d.ts +113 -0
- package/Types/ScrollSnap.d.ts +66 -0
- package/Types/SkinCheckbox.d.ts +35 -0
- package/Types/SkinFile.d.ts +45 -0
- package/Types/SkinRadio.d.ts +37 -0
- package/Types/SkinSelect.d.ts +72 -0
- package/Types/Slider.d.ts +106 -0
- package/Types/Tabs.d.ts +33 -0
- package/Types/Validator.d.ts +99 -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/Events/ImageLoad.ts
CHANGED
|
@@ -44,25 +44,27 @@ function isDataURI( src ) {
|
|
|
44
44
|
* Preload an image
|
|
45
45
|
*
|
|
46
46
|
* @param $element - DOM image to preload
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
47
|
+
* @param callback - Function called on image load (`{` $element, type: string `}`) => `{}`
|
|
48
|
+
* @param handleError - If true reject the promise on error
|
|
49
49
|
*
|
|
50
50
|
* @example
|
|
51
|
-
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* onImageLoad( $image, callback, handleError ).then( () => {} )
|
|
52
53
|
*
|
|
53
54
|
* // To allow event cancelation, don't chain .then() directly after onImageLoad
|
|
54
|
-
* let preload = onImageLoad( $image, callback,
|
|
55
|
+
* let preload = onImageLoad( $image, callback, handleError );
|
|
55
56
|
* preload.then( () => {} );
|
|
56
57
|
* ...
|
|
57
58
|
*
|
|
58
59
|
* preload.off();
|
|
60
|
+
* ```
|
|
59
61
|
*
|
|
60
62
|
* @returns Return a standard Promise + an .off() function to cancel event
|
|
61
63
|
*/
|
|
62
|
-
export function onImageLoad( $element: Element,
|
|
64
|
+
export function onImageLoad( $element: Element, callback?: ( data: FLib.Events.ImagesLoad.CallbackParam ) => void, handleError = false ): FLib.Events.ImagesLoad.PromiseLoad {
|
|
63
65
|
let _remove;
|
|
64
66
|
|
|
65
|
-
const PROM:
|
|
67
|
+
const PROM: FLib.Events.ImagesLoad.PromiseLoad = new Promise( function( resolve, reject ) {
|
|
66
68
|
let $img;
|
|
67
69
|
|
|
68
70
|
function onImageLoaded( e ) {
|
|
@@ -71,14 +73,20 @@ export function onImageLoad( $element: Element, manageError?: boolean, callback?
|
|
|
71
73
|
$img = null;
|
|
72
74
|
|
|
73
75
|
if ( callback ) {
|
|
74
|
-
callback(
|
|
76
|
+
callback( {
|
|
77
|
+
$element,
|
|
78
|
+
"type": e.type
|
|
79
|
+
} );
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
if (
|
|
82
|
+
if ( handleError && e.type === 'error' ) {
|
|
78
83
|
reject();
|
|
79
84
|
}
|
|
80
85
|
else {
|
|
81
|
-
resolve(
|
|
86
|
+
resolve( {
|
|
87
|
+
$element,
|
|
88
|
+
"type": e.type
|
|
89
|
+
} );
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
|
|
@@ -103,10 +111,16 @@ export function onImageLoad( $element: Element, manageError?: boolean, callback?
|
|
|
103
111
|
( !hasNativePicture && ($element as HTMLImageElement).complete && !isDataURI( src ) )
|
|
104
112
|
) {
|
|
105
113
|
if ( callback ) {
|
|
106
|
-
callback(
|
|
114
|
+
callback({
|
|
115
|
+
$element,
|
|
116
|
+
"type": 'complete'
|
|
117
|
+
});
|
|
107
118
|
}
|
|
108
119
|
|
|
109
|
-
resolve(
|
|
120
|
+
resolve({
|
|
121
|
+
$element,
|
|
122
|
+
"type": 'complete'
|
|
123
|
+
});
|
|
110
124
|
return;
|
|
111
125
|
}
|
|
112
126
|
|
|
@@ -121,7 +135,7 @@ export function onImageLoad( $element: Element, manageError?: boolean, callback?
|
|
|
121
135
|
$img.addEventListener( 'error', onImageLoaded );
|
|
122
136
|
$img.addEventListener( 'load', onImageLoaded );
|
|
123
137
|
} );
|
|
124
|
-
} ) as
|
|
138
|
+
} ) as FLib.Events.ImagesLoad.PromiseLoad;
|
|
125
139
|
|
|
126
140
|
PROM.off = _remove;
|
|
127
141
|
|
|
@@ -133,29 +147,31 @@ export function onImageLoad( $element: Element, manageError?: boolean, callback?
|
|
|
133
147
|
* Preload a list of images
|
|
134
148
|
*
|
|
135
149
|
* @param $elements - Array of images to preload
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
150
|
+
* @param callback - Function called on each image load (`{` $element, type:string `}`) => `{}`
|
|
151
|
+
* @param handleError - If true reject the promise on error
|
|
138
152
|
*
|
|
139
153
|
* @example
|
|
140
|
-
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* onAllImagesLoad( $images, partialCallback, handleError ).then( () => {} )
|
|
141
156
|
*
|
|
142
157
|
* // To allow event cancelation, don't chain .then() directly after onAllImagesLoad
|
|
143
|
-
* let preload = onAllImagesLoad( $images,
|
|
158
|
+
* let preload = onAllImagesLoad( $images, callback, handleError );
|
|
144
159
|
* preload.then( () => {} );
|
|
145
160
|
* ...
|
|
146
161
|
*
|
|
147
162
|
* preload.off();
|
|
163
|
+
* ```
|
|
148
164
|
*
|
|
149
165
|
* @returns Return a standard Promise + an .off() function to cancel event
|
|
150
166
|
*/
|
|
151
|
-
export function onAllImagesLoad( $images: NodeList | Element[], ...args ):
|
|
152
|
-
const promArray:
|
|
167
|
+
export function onAllImagesLoad( $images: NodeList | Element[], ...args: any[] ): FLib.Events.ImagesLoad.PromisesLoad {
|
|
168
|
+
const promArray: FLib.Events.ImagesLoad.PromiseLoad[] = [];
|
|
153
169
|
|
|
154
170
|
$images.forEach( $img => {
|
|
155
171
|
promArray.push( onImageLoad( $img, ...args ) );
|
|
156
172
|
} );
|
|
157
173
|
|
|
158
|
-
const promResult:
|
|
174
|
+
const promResult: FLib.Events.ImagesLoad.PromisesLoad = Promise.all( promArray ) as FLib.Events.ImagesLoad.PromisesLoad;
|
|
159
175
|
|
|
160
176
|
promResult.off = function() {
|
|
161
177
|
promArray.forEach( imageLoad => {
|
|
@@ -6,6 +6,7 @@ import { slice } from '../Helpers/Slice';
|
|
|
6
6
|
* Wrapper for the IntersectionObserver API
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
+
* ```ts
|
|
9
10
|
* let io = new IntersectObserver( {
|
|
10
11
|
* "onIntersecting": callback
|
|
11
12
|
* } );
|
|
@@ -26,17 +27,16 @@ import { slice } from '../Helpers/Slice';
|
|
|
26
27
|
*
|
|
27
28
|
* // To remove all elements from the observer
|
|
28
29
|
* io.clear();
|
|
29
|
-
*
|
|
30
|
-
* @param options
|
|
30
|
+
* ```
|
|
31
31
|
*/
|
|
32
32
|
export default class IntersectObserver {
|
|
33
33
|
|
|
34
34
|
#elementObserver: IntersectionObserver;
|
|
35
|
-
#options:
|
|
35
|
+
#options: FLib.Events.IntersectObserver.Options;
|
|
36
36
|
#observedElements;
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
constructor( options:
|
|
39
|
+
constructor( options: FLib.Events.IntersectObserver.Options ) {
|
|
40
40
|
this.#options = extend( {
|
|
41
41
|
"onIntersecting": null,
|
|
42
42
|
"onlyOnce": false,
|
|
@@ -52,15 +52,15 @@ export default class IntersectObserver {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
this.#observedElements = [];
|
|
55
|
-
this.#elementObserver = new IntersectionObserver( this
|
|
55
|
+
this.#elementObserver = new IntersectionObserver( this.#intersect.bind( this ), this.#options.ioOptions );
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
#intersect = ( entries: IntersectionObserverEntry[] ): void => {
|
|
60
60
|
entries.forEach( ( entry: IntersectionObserverEntry ) => {
|
|
61
61
|
if ( this.#options.onlyOnce && entry.isIntersecting ) {
|
|
62
62
|
this.#options.onIntersecting.call( entry.target, entry.target, entry );
|
|
63
|
-
this
|
|
63
|
+
this.#unobserve( entry.target );
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
else if ( !this.#options.onlyOnce ) {
|
|
@@ -70,13 +70,13 @@ export default class IntersectObserver {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
#unobserve = ( $element: Element ): void => {
|
|
74
74
|
this.#elementObserver.unobserve( $element );
|
|
75
75
|
slice( this.#observedElements, $element )
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
#observe = ( $element: Element ): void => {
|
|
80
80
|
if ( this.#observedElements.includes( $element ) ) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
@@ -87,26 +87,24 @@ export default class IntersectObserver {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
#toggle = ( $elements: Element | NodeList | Element[], isAddAction?: boolean ): void => {
|
|
91
91
|
if ( ( $elements instanceof NodeList || $elements instanceof Array ) && typeof $elements.forEach !== 'undefined' ) {
|
|
92
92
|
$elements.forEach( $element => {
|
|
93
|
-
isAddAction ? this
|
|
93
|
+
isAddAction ? this.#observe( $element ) : this.#unobserve( $element );
|
|
94
94
|
} );
|
|
95
95
|
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
isAddAction ? this
|
|
99
|
+
isAddAction ? this.#observe( $elements as Element ) : this.#unobserve( $elements as Element );
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Add elements to be observed
|
|
105
|
-
*
|
|
106
|
-
* @param $elements
|
|
107
105
|
*/
|
|
108
106
|
add( $elements: Element | NodeList | Element[] ): this {
|
|
109
|
-
this
|
|
107
|
+
this.#toggle( $elements, true );
|
|
110
108
|
|
|
111
109
|
return this;
|
|
112
110
|
}
|
|
@@ -114,11 +112,9 @@ export default class IntersectObserver {
|
|
|
114
112
|
|
|
115
113
|
/**
|
|
116
114
|
* Stop some elements to be observed
|
|
117
|
-
*
|
|
118
|
-
* @param $elements
|
|
119
115
|
*/
|
|
120
116
|
remove( $elements: Element | NodeList | Element[] ): this {
|
|
121
|
-
this
|
|
117
|
+
this.#toggle( $elements, false );
|
|
122
118
|
|
|
123
119
|
return this;
|
|
124
120
|
}
|
|
@@ -132,7 +128,7 @@ export default class IntersectObserver {
|
|
|
132
128
|
return this;
|
|
133
129
|
}
|
|
134
130
|
|
|
135
|
-
this
|
|
131
|
+
this.#toggle( this.#observedElements, false );
|
|
136
132
|
|
|
137
133
|
this.#observedElements.length = 0;
|
|
138
134
|
|
|
@@ -17,10 +17,10 @@ export default class KeyboardHandler {
|
|
|
17
17
|
|
|
18
18
|
#$element;
|
|
19
19
|
#options;
|
|
20
|
-
#eventsName = new Map();
|
|
20
|
+
#eventsName = new Map<string, ( e: KeyboardEvent ) => string[]>();
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
constructor( $element: Element, userOptions:
|
|
23
|
+
constructor( $element: Element, userOptions: FLib.Events.KeyboardHandler.Options = {} ) {
|
|
24
24
|
|
|
25
25
|
this.#$element = $element;
|
|
26
26
|
|
|
@@ -44,7 +44,7 @@ export default class KeyboardHandler {
|
|
|
44
44
|
this.#eventsName.set( 'ArrowDown', () => [ 'onDown', 'onPrevious' ] );
|
|
45
45
|
this.#eventsName.set( 'PageUp', () => [ 'onPageUp' ] );
|
|
46
46
|
this.#eventsName.set( 'PageDown', () => [ 'onPageDown' ] );
|
|
47
|
-
this.#eventsName.set( 'Tab', e => {
|
|
47
|
+
this.#eventsName.set( 'Tab', ( e: KeyboardEvent ) => {
|
|
48
48
|
if ( e.shiftKey && this.#options[ 'onTabReverse' ] ) {
|
|
49
49
|
return [ 'onTabReverse' ];
|
|
50
50
|
}
|
|
@@ -55,7 +55,7 @@ export default class KeyboardHandler {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
#handleCallbacks = ( event: KeyboardEvent, $context: EventTarget | null, callbacks: string[] ): void => {
|
|
59
59
|
callbacks.forEach( cb => {
|
|
60
60
|
if ( this.#options[ cb ] ) {
|
|
61
61
|
this.#options[ cb ].call( $context, event, $context );
|
|
@@ -64,7 +64,7 @@ export default class KeyboardHandler {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
#onKeypress = ( e: KeyboardEvent ) => {
|
|
67
|
+
#onKeypress = ( e: KeyboardEvent ): void => {
|
|
68
68
|
const key = e.key;
|
|
69
69
|
|
|
70
70
|
// Block all key except tab, CTRL R, CMD R or F5
|
|
@@ -78,10 +78,12 @@ export default class KeyboardHandler {
|
|
|
78
78
|
e.preventDefault();
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
this
|
|
81
|
+
this.#handleCallbacks( e, e.target, [ 'onKey' ] );
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
const FNC = this.#eventsName.get( key );
|
|
84
|
+
|
|
85
|
+
if ( FNC ) {
|
|
86
|
+
this.#handleCallbacks( e, e.target, FNC( e ) );
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -6,37 +6,41 @@ import { slice } from '../Helpers/Slice';
|
|
|
6
6
|
* Manage media queries events
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
|
+
* ```ts
|
|
9
10
|
* let mquery = new MediaQueriesEvents( [
|
|
11
|
+
* {
|
|
10
12
|
* "name" : "mob",
|
|
11
13
|
* "query": window.matchMedia( '(max-width:767px)' )
|
|
12
|
-
* },
|
|
14
|
+
* \},
|
|
13
15
|
* {
|
|
14
16
|
* "name" : "tab",
|
|
15
17
|
* "query": window.matchMedia( '(min-width:768px) and (max-width:959px)' )
|
|
16
|
-
* },
|
|
18
|
+
* \},
|
|
17
19
|
* {
|
|
18
20
|
* "name" : "desk",
|
|
19
21
|
* "query": window.matchMedia( '(min-width:960px)' )
|
|
20
|
-
* }
|
|
22
|
+
* \}
|
|
23
|
+
* ] );
|
|
21
24
|
*
|
|
22
25
|
* or
|
|
23
26
|
*
|
|
24
27
|
* let mquery = new MediaQueriesEvents( [
|
|
28
|
+
* {
|
|
25
29
|
* "name" : "mob",
|
|
26
30
|
* "max": 767
|
|
27
|
-
* },
|
|
31
|
+
* \},
|
|
28
32
|
* {
|
|
29
33
|
* "name" : "tab",
|
|
30
34
|
* "min": 768,
|
|
31
35
|
* "max": 956
|
|
32
|
-
* },
|
|
36
|
+
* \},
|
|
33
37
|
* {
|
|
34
38
|
* "name" : "desk",
|
|
35
39
|
* "max": 960
|
|
36
|
-
* } ],
|
|
40
|
+
* \} ],
|
|
37
41
|
* {
|
|
38
42
|
* "unit": "px" // Default value
|
|
39
|
-
* }
|
|
43
|
+
* \}
|
|
40
44
|
* );
|
|
41
45
|
*
|
|
42
46
|
* // Register a function to be call when leaving any breakpoint
|
|
@@ -63,9 +67,9 @@ import { slice } from '../Helpers/Slice';
|
|
|
63
67
|
* boolean = mquery.is( 'desk' );
|
|
64
68
|
*
|
|
65
69
|
* // Current active breakpoint
|
|
66
|
-
* myBreakpoint = mquery.currentBreakpoint; //
|
|
67
|
-
* myBreakpoint.is( 'mob' ); //
|
|
68
|
-
* myBreakpoint.in( ['mob', 'tab'] ); //
|
|
70
|
+
* myBreakpoint = mquery.currentBreakpoint; // => { name, query, ... } or false
|
|
71
|
+
* myBreakpoint.is( 'mob' ); // => true|false
|
|
72
|
+
* myBreakpoint.in( ['mob', 'tab'] ); // => true|false
|
|
69
73
|
*
|
|
70
74
|
* // List of all breakpoints
|
|
71
75
|
* array = mquery.list;
|
|
@@ -78,30 +82,30 @@ import { slice } from '../Helpers/Slice';
|
|
|
78
82
|
*
|
|
79
83
|
* // Resume media queries watch
|
|
80
84
|
* mquery.resume();
|
|
81
|
-
*
|
|
85
|
+
* ```
|
|
82
86
|
*/
|
|
83
87
|
export default class MediaQueriesEvents {
|
|
84
88
|
|
|
85
|
-
#breakpointsList: Breakpoint[];
|
|
86
|
-
#currentBreakpoint: Breakpoint |
|
|
87
|
-
#functionHash:
|
|
88
|
-
#isSuspended
|
|
89
|
-
#options:
|
|
89
|
+
#breakpointsList: FLib.Events.MediaqueriesEvents.Breakpoint[];
|
|
90
|
+
#currentBreakpoint: FLib.Events.MediaqueriesEvents.Breakpoint | undefined;
|
|
91
|
+
#functionHash: Record<string, FLib.Events.MediaqueriesEvents.InternalCallbackType[]>;
|
|
92
|
+
#isSuspended = false;
|
|
93
|
+
#options: FLib.Events.MediaqueriesEvents.Options;
|
|
90
94
|
|
|
91
95
|
#globalHashName = '__globalHashName';
|
|
92
96
|
|
|
93
97
|
/** Current active breakpoint */
|
|
94
|
-
get currentBreakpoint() {
|
|
98
|
+
get currentBreakpoint(): FLib.Events.MediaqueriesEvents.Breakpoint | undefined {
|
|
95
99
|
return this.#currentBreakpoint;
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
/** List of all breakpoints */
|
|
99
|
-
get list() {
|
|
103
|
+
get list(): FLib.Events.MediaqueriesEvents.Breakpoint[] {
|
|
100
104
|
return this.#breakpointsList;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
|
|
104
|
-
constructor( breakpointsList:
|
|
108
|
+
constructor( breakpointsList: FLib.Events.MediaqueriesEvents.ListOptions[], userOptions: FLib.Events.MediaqueriesEvents.Options ) {
|
|
105
109
|
const DEFAULT_OPTIONS = {
|
|
106
110
|
"unit": "px"
|
|
107
111
|
};
|
|
@@ -118,16 +122,16 @@ export default class MediaQueriesEvents {
|
|
|
118
122
|
|
|
119
123
|
// Handlers
|
|
120
124
|
this.#breakpointsList = breakpointsList.map( breakpointItem => {
|
|
121
|
-
const breakpoint: Breakpoint = {
|
|
125
|
+
const breakpoint: FLib.Events.MediaqueriesEvents.Breakpoint = {
|
|
122
126
|
...breakpointItem,
|
|
123
|
-
"query": breakpointItem.query || this
|
|
127
|
+
"query": breakpointItem.query || this.#createQuery( breakpointItem ),
|
|
124
128
|
"handler": mql => {
|
|
125
129
|
if ( mql.matches ) {
|
|
126
130
|
this.#currentBreakpoint = breakpoint;
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
if ( !this.#isSuspended ) {
|
|
130
|
-
this
|
|
134
|
+
this.#update( breakpoint, mql.matches );
|
|
131
135
|
}
|
|
132
136
|
},
|
|
133
137
|
"in": breakpointNameList => {
|
|
@@ -150,14 +154,14 @@ export default class MediaQueriesEvents {
|
|
|
150
154
|
return breakpoint;
|
|
151
155
|
});
|
|
152
156
|
|
|
153
|
-
this.#currentBreakpoint = this
|
|
157
|
+
this.#currentBreakpoint = this.#getCurrentBreakpoint();
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
|
|
157
161
|
// TOOLS
|
|
158
162
|
|
|
159
163
|
|
|
160
|
-
|
|
164
|
+
#processList = ( list: FLib.Events.MediaqueriesEvents.InternalCallbackType[], breakpoint: FLib.Events.MediaqueriesEvents.Breakpoint, isMatching: boolean ): void => {
|
|
161
165
|
list.forEach( obj => {
|
|
162
166
|
if (
|
|
163
167
|
obj.type === 'both' ||
|
|
@@ -171,28 +175,28 @@ export default class MediaQueriesEvents {
|
|
|
171
175
|
|
|
172
176
|
|
|
173
177
|
// Call each registered function
|
|
174
|
-
|
|
178
|
+
#update = ( breakpoint: FLib.Events.MediaqueriesEvents.Breakpoint, isMatching: boolean ): void => {
|
|
175
179
|
if ( this.#functionHash[ breakpoint.name ] && this.#functionHash[ breakpoint.name ].length ) {
|
|
176
|
-
this
|
|
180
|
+
this.#processList( this.#functionHash[ breakpoint.name ], breakpoint, isMatching );
|
|
177
181
|
}
|
|
178
182
|
|
|
179
183
|
if ( this.#functionHash[ this.#globalHashName ].length ) {
|
|
180
|
-
this
|
|
184
|
+
this.#processList( this.#functionHash[ this.#globalHashName ], breakpoint, isMatching );
|
|
181
185
|
}
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
|
|
185
|
-
|
|
189
|
+
#getBreakpoint = ( breakpointName: string ): FLib.Events.MediaqueriesEvents.Breakpoint | undefined => {
|
|
186
190
|
return this.#breakpointsList.find( bp => bp.name === breakpointName );
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
|
|
190
|
-
|
|
194
|
+
#getCurrentBreakpoint = (): FLib.Events.MediaqueriesEvents.Breakpoint | undefined => {
|
|
191
195
|
return this.#breakpointsList.find( bp => bp.query.matches );
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
|
|
195
|
-
|
|
199
|
+
#createQuery = ( breakpoint: FLib.Events.MediaqueriesEvents.ListOptions ): MediaQueryList => {
|
|
196
200
|
let minQuery, maxQuery, query;
|
|
197
201
|
|
|
198
202
|
if ( typeof breakpoint.min === 'number' ) {
|
|
@@ -226,18 +230,18 @@ export default class MediaQueriesEvents {
|
|
|
226
230
|
/**
|
|
227
231
|
* Return the value of the property with the name of the current breakpoint of an object
|
|
228
232
|
*
|
|
229
|
-
* @param obj
|
|
230
|
-
*
|
|
231
233
|
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* // If the current breakpoint name is "small", it will return "val1"
|
|
232
236
|
* mediaQueryEvent.getValue( { "small": "val1", "medium": "val2", ... } );
|
|
233
|
-
*
|
|
237
|
+
* ```
|
|
234
238
|
*/
|
|
235
|
-
getValue<Value>( obj:
|
|
239
|
+
getValue<Value>( obj: Record<string, Value> ): Value | undefined {
|
|
236
240
|
if ( !this.#currentBreakpoint ) {
|
|
237
241
|
return;
|
|
238
242
|
}
|
|
239
243
|
return obj[ this.#currentBreakpoint.name ];
|
|
240
|
-
}
|
|
244
|
+
}
|
|
241
245
|
|
|
242
246
|
|
|
243
247
|
/**
|
|
@@ -245,9 +249,9 @@ export default class MediaQueriesEvents {
|
|
|
245
249
|
*
|
|
246
250
|
* @param callback - Callback
|
|
247
251
|
* @param breakpointName - Name of the breakpoint
|
|
248
|
-
* @param
|
|
252
|
+
* @param type - Select when the function will be called: when entering the query, when leaving it, or on both
|
|
249
253
|
*/
|
|
250
|
-
on( callback:
|
|
254
|
+
on( callback: FLib.Events.MediaqueriesEvents.Callback, breakpointName: string, type: FLib.Events.MediaqueriesEvents.CallbackType = 'enter' ): this {
|
|
251
255
|
if ( !this.#functionHash[ breakpointName ] ) {
|
|
252
256
|
return this;
|
|
253
257
|
}
|
|
@@ -264,15 +268,15 @@ export default class MediaQueriesEvents {
|
|
|
264
268
|
/**
|
|
265
269
|
* Unbind a function to be called on a specific breakpoint
|
|
266
270
|
*
|
|
267
|
-
* @param
|
|
268
|
-
* @param
|
|
271
|
+
* @param callback - Function to remove from the registered function list
|
|
272
|
+
* @param breakpointName - Name of the breakpoint
|
|
269
273
|
*/
|
|
270
|
-
off( callback:
|
|
274
|
+
off( callback: FLib.Events.MediaqueriesEvents.Callback, breakpointName: string ): this {
|
|
271
275
|
if ( !this.#functionHash[ breakpointName ] ) {
|
|
272
276
|
return this;
|
|
273
277
|
}
|
|
274
278
|
|
|
275
|
-
|
|
279
|
+
const obj = this.#functionHash[ breakpointName ].find( o => o.callback === callback );
|
|
276
280
|
|
|
277
281
|
slice( this.#functionHash[ breakpointName ], obj );
|
|
278
282
|
|
|
@@ -283,10 +287,10 @@ export default class MediaQueriesEvents {
|
|
|
283
287
|
/**
|
|
284
288
|
* Register a function to be called on all media queries change
|
|
285
289
|
*
|
|
286
|
-
* @param
|
|
287
|
-
* @param
|
|
290
|
+
* @param callback - Function to call on mediaquery change
|
|
291
|
+
* @param type - Select when the function will be called: when entering the query, when leaving it, or on both
|
|
288
292
|
*/
|
|
289
|
-
register( callback:
|
|
293
|
+
register( callback: FLib.Events.MediaqueriesEvents.Callback, type: FLib.Events.MediaqueriesEvents.CallbackType = 'enter' ): this {
|
|
290
294
|
this.#functionHash[ this.#globalHashName ].push({
|
|
291
295
|
callback,
|
|
292
296
|
type
|
|
@@ -301,8 +305,8 @@ export default class MediaQueriesEvents {
|
|
|
301
305
|
*
|
|
302
306
|
* @param callback - Function to remove from the registered function list
|
|
303
307
|
*/
|
|
304
|
-
remove( callback:
|
|
305
|
-
|
|
308
|
+
remove( callback: FLib.Events.MediaqueriesEvents.Callback ): this {
|
|
309
|
+
const obj = this.#functionHash[ this.#globalHashName ].find( o => o.callback === callback );
|
|
306
310
|
|
|
307
311
|
slice( this.#functionHash[ this.#globalHashName ], obj );
|
|
308
312
|
|
|
@@ -318,7 +322,7 @@ export default class MediaQueriesEvents {
|
|
|
318
322
|
return this;
|
|
319
323
|
}
|
|
320
324
|
|
|
321
|
-
this
|
|
325
|
+
this.#update( this.#currentBreakpoint, this.#currentBreakpoint.query.matches );
|
|
322
326
|
|
|
323
327
|
return this;
|
|
324
328
|
}
|
|
@@ -329,7 +333,7 @@ export default class MediaQueriesEvents {
|
|
|
329
333
|
*
|
|
330
334
|
* @param callback - Function to call
|
|
331
335
|
*/
|
|
332
|
-
get( callback:
|
|
336
|
+
get( callback: FLib.Events.MediaqueriesEvents.Callback ): this {
|
|
333
337
|
if ( !this.#currentBreakpoint || !callback ) {
|
|
334
338
|
return this;
|
|
335
339
|
}
|
|
@@ -346,9 +350,7 @@ export default class MediaQueriesEvents {
|
|
|
346
350
|
* @param breakpointName - Name of a breakpoint
|
|
347
351
|
*/
|
|
348
352
|
is( breakpointName: string ): boolean {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
breakpoint = this.getBreakpoint( breakpointName );
|
|
353
|
+
const breakpoint = this.#getBreakpoint( breakpointName );
|
|
352
354
|
|
|
353
355
|
return breakpoint ? breakpoint.query.matches : false;
|
|
354
356
|
}
|
package/Events/OnAnimationEnd.ts
CHANGED
|
@@ -4,12 +4,10 @@ import { animationendEventName } from '../Tools/PrefixedProperties';
|
|
|
4
4
|
/**
|
|
5
5
|
* Bind a one time animationend event on a DOM object
|
|
6
6
|
*
|
|
7
|
-
* @param $elem
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
8
|
+
* ```ts
|
|
10
9
|
* onAnimationEnd( $elem ).then( () => {} );
|
|
11
10
|
*
|
|
12
|
-
* @example
|
|
13
11
|
* // To remove the event binding, don't chain .then() directly after onAnimationEnd:
|
|
14
12
|
* let animationEnd = onAnimationEnd( $element );
|
|
15
13
|
* animationEnd.then( () => {} );
|
|
@@ -18,17 +16,18 @@ import { animationendEventName } from '../Tools/PrefixedProperties';
|
|
|
18
16
|
*
|
|
19
17
|
* // To watch for a animation end:
|
|
20
18
|
* onAnimationEnd( $elem, {
|
|
21
|
-
* "animationName": "name-of-my-css-animation"
|
|
19
|
+
* "animationName": [ "name-of-my-css-animation" ]
|
|
22
20
|
* } )
|
|
23
21
|
*
|
|
24
22
|
* // To watch a animation end on a pseudo element like "::after":
|
|
25
23
|
* onAnimationEnd( $elem, {
|
|
26
24
|
* "pseudoElement": "after"
|
|
27
25
|
* } )
|
|
26
|
+
* ```
|
|
28
27
|
*
|
|
29
28
|
* @returns Return a standard Promise + an .off() function to cancel event
|
|
30
29
|
*/
|
|
31
|
-
export default function onAnimationEnd( $element: Element, options: { pseudoElement?: 'after' | 'before' | 'both', animationName?: string } = {} ): Promise<any> & { off(); } {
|
|
30
|
+
export default function onAnimationEnd( $element: Element, options: { pseudoElement?: 'after' | 'before' | 'both', animationName?: string[] } = {} ): Promise<any> & { off(); } {
|
|
32
31
|
let _resolve;
|
|
33
32
|
|
|
34
33
|
const promise = new Promise( function( resolve ) {
|
|
@@ -44,7 +43,7 @@ export default function onAnimationEnd( $element: Element, options: { pseudoElem
|
|
|
44
43
|
function onAnimationEnd( e ) {
|
|
45
44
|
if (
|
|
46
45
|
e.target !== $element ||
|
|
47
|
-
( options.animationName && options.animationName
|
|
46
|
+
( options.animationName && !options.animationName.includes( e.animationName ) ) ||
|
|
48
47
|
( options.pseudoElement === 'after' && e.pseudoElement !== '::after' ) ||
|
|
49
48
|
( options.pseudoElement === 'before' && e.pseudoElement !== '::before' ) ||
|
|
50
49
|
( options.pseudoElement === 'both' && !e.pseudoElement ) ||
|
|
@@ -4,12 +4,11 @@ import { transitionendEventName } from '../Tools/PrefixedProperties';
|
|
|
4
4
|
/**
|
|
5
5
|
* Bind a one time transitionend event on a DOM object
|
|
6
6
|
*
|
|
7
|
-
* @param $element
|
|
8
|
-
*
|
|
9
7
|
* @example
|
|
10
|
-
* onTransitionEnd( $elem ).then( ()
|
|
8
|
+
* onTransitionEnd( $elem ).then( () => `{}` );
|
|
11
9
|
*
|
|
12
10
|
* @example
|
|
11
|
+
* ```ts
|
|
13
12
|
* // To remove the event binding, don't chain .then() directly after onTransitionEnd:
|
|
14
13
|
* let transitionEnd = onTransitionEnd( $element );
|
|
15
14
|
* transitionEnd.then( () => {} );
|
|
@@ -25,6 +24,7 @@ import { transitionendEventName } from '../Tools/PrefixedProperties';
|
|
|
25
24
|
* onTransitionEnd( $elem, {
|
|
26
25
|
* "pseudoElement": "after"
|
|
27
26
|
* } )
|
|
27
|
+
* ```
|
|
28
28
|
*
|
|
29
29
|
* @returns Return a standard Promise + an .off() function to cancel event
|
|
30
30
|
*/
|