@creative-web-solution/front-library 7.0.7 → 7.1.3

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.
Files changed (141) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/DOM/Class.ts +10 -12
  3. package/DOM/DocumentSize.ts +3 -1
  4. package/DOM/Filter.ts +0 -2
  5. package/DOM/Index.ts +1 -3
  6. package/DOM/Manipulation.ts +0 -3
  7. package/DOM/Matrix.ts +12 -12
  8. package/DOM/Offset.ts +4 -5
  9. package/DOM/OuterSize.ts +12 -12
  10. package/DOM/PageToDOM.ts +2 -2
  11. package/DOM/Position.ts +3 -3
  12. package/DOM/Size.ts +3 -7
  13. package/DOM/StrToDOM.ts +0 -1
  14. package/DOM/Styles.ts +3 -12
  15. package/DOM/Traversing.ts +0 -6
  16. package/DOM/WindowScroll.ts +3 -1
  17. package/DOM/WindowSize.ts +3 -1
  18. package/DOM/Wrap.ts +0 -1
  19. package/Events/DeviceOrientation.ts +27 -31
  20. package/Events/EventsManager.ts +10 -25
  21. package/Events/Gesture.ts +36 -37
  22. package/Events/HistoryController.ts +12 -18
  23. package/Events/ImageLoad.ts +35 -19
  24. package/Events/IntersectObserver.ts +15 -19
  25. package/Events/KeyboardHandler.ts +10 -8
  26. package/Events/MediaQueriesEvents.ts +53 -51
  27. package/Events/OnAnimationEnd.ts +2 -3
  28. package/Events/OnTransitionEnd.ts +3 -3
  29. package/Events/PubSub.ts +5 -8
  30. package/Events/TouchHover.ts +18 -21
  31. package/Events/WindowEvents.ts +26 -30
  32. package/Helpers/Colors.ts +7 -23
  33. package/Helpers/Cookie.ts +5 -12
  34. package/Helpers/Coordinates.ts +0 -7
  35. package/Helpers/Debounce.ts +3 -7
  36. package/Helpers/Defer.ts +1 -1
  37. package/Helpers/GetValue.ts +0 -2
  38. package/Helpers/Insert.ts +0 -1
  39. package/Helpers/Sequential.ts +0 -2
  40. package/Helpers/Slice.ts +0 -3
  41. package/Helpers/Throttle.ts +0 -1
  42. package/Helpers/TransitionHelpers.ts +8 -6
  43. package/Helpers/Type.ts +1 -14
  44. package/Helpers/Unique.ts +3 -3
  45. package/Helpers/UrlParser.ts +14 -23
  46. package/Helpers/Wait.ts +1 -1
  47. package/Modules/Accordion/Tab.ts +19 -17
  48. package/Modules/Accordion/index.ts +27 -19
  49. package/Modules/Autocomplete.ts +95 -101
  50. package/Modules/DragSlider.ts +72 -63
  51. package/Modules/GlobalState.ts +60 -53
  52. package/Modules/LoadGMap.ts +4 -7
  53. package/Modules/Notifications/Notification.ts +28 -32
  54. package/Modules/Notifications/index.ts +43 -36
  55. package/Modules/Popin/Popin.ts +100 -110
  56. package/Modules/Popin/PopinAccessibility.ts +8 -8
  57. package/Modules/Popin/PopinBackground.ts +12 -12
  58. package/Modules/Popin/PopinController.ts +24 -30
  59. package/Modules/Popin/Tools.ts +18 -19
  60. package/Modules/QuickTemplate.ts +4 -6
  61. package/Modules/ScrollSnap.ts +110 -104
  62. package/Modules/SkinCheckbox.ts +52 -38
  63. package/Modules/SkinFile.ts +63 -53
  64. package/Modules/SkinRadio.ts +63 -43
  65. package/Modules/SkinSelect.ts +117 -101
  66. package/Modules/Slider/Slide.ts +49 -52
  67. package/Modules/Slider/Slider.ts +100 -136
  68. package/Modules/Slider/SliderControls.ts +60 -59
  69. package/Modules/Tabs/Tab.ts +28 -24
  70. package/Modules/Tabs/index.ts +36 -26
  71. package/Modules/Validator/Date.ts +2 -1
  72. package/Modules/Validator/Equals.ts +1 -1
  73. package/Modules/Validator/Internal/Input.ts +366 -0
  74. package/Modules/Validator/Internal/InputValidator.ts +99 -0
  75. package/Modules/Validator/Internal/ValidatorFunctionsController.ts +58 -0
  76. package/Modules/Validator/Max.ts +1 -1
  77. package/Modules/Validator/Min.ts +1 -1
  78. package/Modules/Validator/MultiRequired.ts +5 -5
  79. package/Modules/Validator/Number.ts +1 -0
  80. package/Modules/Validator/Pattern.ts +1 -1
  81. package/Modules/Validator/Recaptcha.ts +1 -0
  82. package/Modules/Validator/Required.ts +3 -2
  83. package/Modules/Validator/ServerCheck.ts +23 -15
  84. package/Modules/Validator/Tools/GetQueryFromForm.ts +1 -6
  85. package/Modules/Validator/Tools/IsDate.ts +2 -3
  86. package/Modules/Validator/Tools/IsEmail.ts +2 -5
  87. package/Modules/Validator/Tools/IsEmpty.ts +0 -2
  88. package/Modules/Validator/Tools/IsNumber.ts +0 -2
  89. package/Modules/Validator/Tools/IsUrl.ts +1 -3
  90. package/Modules/Validator/Tools/Label.ts +5 -15
  91. package/Modules/Validator/Tools/RadioButton.ts +4 -10
  92. package/Modules/Validator/Url.ts +1 -0
  93. package/Modules/Validator/index.ts +36 -36
  94. package/Modules/YouTubePlayer.ts +18 -16
  95. package/README.md +1 -1
  96. package/Types/Accordion.d.ts +41 -0
  97. package/Types/Autocomplete.d.ts +94 -0
  98. package/Types/DOM.d.ts +69 -0
  99. package/Types/DragSlider.d.ts +56 -0
  100. package/Types/EventsHelpers.d.ts +390 -0
  101. package/Types/GLImageTransition.d.ts +47 -43
  102. package/Types/GlobalState.d.ts +9 -0
  103. package/Types/Helpers.d.ts +63 -0
  104. package/Types/Notifications.d.ts +48 -44
  105. package/Types/Popin.d.ts +113 -0
  106. package/Types/ScrollSnap.d.ts +66 -0
  107. package/Types/SkinCheckbox.d.ts +35 -0
  108. package/Types/SkinFile.d.ts +45 -0
  109. package/Types/SkinRadio.d.ts +37 -0
  110. package/Types/SkinSelect.d.ts +72 -0
  111. package/Types/Slider.d.ts +106 -0
  112. package/Types/Tabs.d.ts +33 -0
  113. package/Types/Validator.d.ts +99 -0
  114. package/Types/YouTubePlayer.d.ts +27 -0
  115. package/Types/index.d.ts +22 -21
  116. package/WebGL/GLImageTransition/GLImageTransition.ts +83 -80
  117. package/WebGL/GLImageTransition/Presets/Cellular.ts +11 -11
  118. package/WebGL/GLImageTransition/Presets/Fade.ts +2 -3
  119. package/WebGL/GLImageTransition/Presets/HorizontalMovingGrid.ts +9 -9
  120. package/WebGL/GLImageTransition/Presets/PresetSample.ts +11 -9
  121. package/WebGL/GLImageTransition/Presets/Solarisation.ts +7 -12
  122. package/package.json +1 -1
  123. package/Modules/Template.ts +0 -209
  124. package/Types/AccordionTypes.d.ts +0 -29
  125. package/Types/AutocompleteTypes.d.ts +0 -85
  126. package/Types/DOMTypes.d.ts +0 -62
  127. package/Types/DragSliderTypes.d.ts +0 -52
  128. package/Types/EventsHelpersTypes.d.ts +0 -370
  129. package/Types/GlobalStateTypes.d.ts +0 -5
  130. package/Types/HelpersTypes.d.ts +0 -23
  131. package/Types/MediaPreloaderTypes.d.ts +0 -12
  132. package/Types/PopinTypes.d.ts +0 -83
  133. package/Types/ScrollSnapTypes.d.ts +0 -62
  134. package/Types/SkinCheckboxTypes.d.ts +0 -23
  135. package/Types/SkinFileTypes.d.ts +0 -34
  136. package/Types/SkinRadioTypes.d.ts +0 -24
  137. package/Types/SkinSelectTypes.d.ts +0 -48
  138. package/Types/SliderTypes.d.ts +0 -97
  139. package/Types/TabsTypes.d.ts +0 -22
  140. package/Types/ValidatorTypes.d.ts +0 -61
  141. package/Types/YouTubePlayerTypes.d.ts +0 -23
@@ -44,25 +44,27 @@ function isDataURI( src ) {
44
44
  * Preload an image
45
45
  *
46
46
  * @param $element - DOM image to preload
47
- * @param manageError - If true reject the promise on error (false)
48
- * @param callback - Function called on image load
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
- * onImageLoad( $image, manageError, callback ).then( () => {} )
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, manageError );
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, manageError?: boolean, callback?: ( $element: Element, type: ImageLoadEventType ) => void ): ImagePromiseType {
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: ImagePromiseType = new Promise( function( this: ImagePromiseType, resolve, reject ) {
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( $element, e.type );
76
+ callback( {
77
+ $element,
78
+ "type": e.type
79
+ } );
75
80
  }
76
81
 
77
- if ( manageError && e.type === 'error' ) {
82
+ if ( handleError && e.type === 'error' ) {
78
83
  reject();
79
84
  }
80
85
  else {
81
- resolve( [ $element, e.type ] );
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( $element, 'complete' );
114
+ callback({
115
+ $element,
116
+ "type": 'complete'
117
+ });
107
118
  }
108
119
 
109
- resolve( [ $element, 'complete' ] );
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 ImagePromiseType;
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 manageError - If true reject the promise on error (false)
137
- * @param callback - Function called on each image load ($element, eventType:string) => {}
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
- * onAllImagesLoad( $images, manageError, partialCallback ).then( () => {} )
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, manageError, callback );
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 ): ImagesPromiseType {
152
- const promArray: ImagePromiseType[] = [];
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: ImagesPromiseType = Promise.all( promArray ) as ImagesPromiseType;
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: IntersectObserverOptionsType;
35
+ #options: FLib.Events.IntersectObserver.Options;
36
36
  #observedElements;
37
37
 
38
38
 
39
- constructor( options: IntersectObserverOptionsType ) {
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.intersect.bind( this ), this.#options.ioOptions );
55
+ this.#elementObserver = new IntersectionObserver( this.#intersect.bind( this ), this.#options.ioOptions );
56
56
  }
57
57
 
58
58
 
59
- private intersect( entries: IntersectionObserverEntry[] ) {
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.unobserve( entry.target );
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
- private unobserve( $element: Element ) {
73
+ #unobserve = ( $element: Element ): void => {
74
74
  this.#elementObserver.unobserve( $element );
75
75
  slice( this.#observedElements, $element )
76
76
  }
77
77
 
78
78
 
79
- private observe( $element: Element ) {
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
- private toggle( $elements: Element | NodeList | Element[], isAddAction ) {
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.observe( $element ) : this.unobserve( $element );
93
+ isAddAction ? this.#observe( $element ) : this.#unobserve( $element );
94
94
  } );
95
95
 
96
96
  return;
97
97
  }
98
98
 
99
- isAddAction ? this.observe( $elements as Element ) : this.unobserve( $elements as Element );
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.toggle( $elements, true );
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.toggle( $elements, false );
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.toggle( this.#observedElements, false );
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: KeyboardHandlerOptions = {} ) {
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
- private handleCallbacks( event, $context, callbacks ) {
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.handleCallbacks( e, e.target, [ 'onKey' ] );
81
+ this.#handleCallbacks( e, e.target, [ 'onKey' ] );
82
82
 
83
- if ( this.#eventsName.has( key ) ) {
84
- this.handleCallbacks( e, e.target, this.#eventsName.get( key )( e ) );
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; // => {name, query, ...} or false
67
- * myBreakpoint.is( 'mob' ); // => true|false
68
- * myBreakpoint.in( ['mob', 'tab'] ); // => true|false
70
+ * myBreakpoint = mquery.currentBreakpoint; // =&gt; { name, query, ... } or false
71
+ * myBreakpoint.is( 'mob' ); // =&gt; true|false
72
+ * myBreakpoint.in( ['mob', 'tab'] ); // =&gt; 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 | undefined;
87
- #functionHash: { [ key: string ]: MediaQueriesEventsInternalCallbackType[] };
88
- #isSuspended: boolean = false;
89
- #options: MediaQueriesEventsOptions;
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: MediaQueriesEventsListOptions[], userOptions: MediaQueriesEventsOptions ) {
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.createQuery( breakpointItem ),
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.update( breakpoint, mql.matches );
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.getCurrentBreakpoint();
157
+ this.#currentBreakpoint = this.#getCurrentBreakpoint();
154
158
  }
155
159
 
156
160
 
157
161
  // TOOLS
158
162
 
159
163
 
160
- private processList( list, breakpoint, isMatching ) {
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
- private update( breakpoint: Breakpoint, isMatching: boolean ): void {
178
+ #update = ( breakpoint: FLib.Events.MediaqueriesEvents.Breakpoint, isMatching: boolean ): void => {
175
179
  if ( this.#functionHash[ breakpoint.name ] && this.#functionHash[ breakpoint.name ].length ) {
176
- this.processList( this.#functionHash[ breakpoint.name ], breakpoint, isMatching );
180
+ this.#processList( this.#functionHash[ breakpoint.name ], breakpoint, isMatching );
177
181
  }
178
182
 
179
183
  if ( this.#functionHash[ this.#globalHashName ].length ) {
180
- this.processList( this.#functionHash[ this.#globalHashName ], breakpoint, isMatching );
184
+ this.#processList( this.#functionHash[ this.#globalHashName ], breakpoint, isMatching );
181
185
  }
182
186
  }
183
187
 
184
188
 
185
- private getBreakpoint( breakpointName: string ): Breakpoint | undefined {
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
- private getCurrentBreakpoint(): Breakpoint | undefined {
194
+ #getCurrentBreakpoint = (): FLib.Events.MediaqueriesEvents.Breakpoint | undefined => {
191
195
  return this.#breakpointsList.find( bp => bp.query.matches );
192
196
  }
193
197
 
194
198
 
195
- private createQuery( breakpoint: MediaQueriesEventsListOptions ): MediaQueryList {
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
- * Ih the current breakpoint name is "small", it will return "val1"
237
+ * ```
234
238
  */
235
- getValue<Value>( obj: { [ key: string ]: Value } ): Value | undefined {
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 [type=MediaQueriesEvents.TYPE_ON_ENTER] - Select when the function will be called: when entering the query, when leaving it, or on both
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: MediaQueriesEventsCallback, breakpointName: string, type: MediaQueriesEventsCallbackType = 'enter' ): this {
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 {Function} callback - Function to remove from the registered function list
268
- * @param {String} breakpointName - Name of the breakpoint
271
+ * @param callback - Function to remove from the registered function list
272
+ * @param breakpointName - Name of the breakpoint
269
273
  */
270
- off( callback: MediaQueriesEventsCallback, breakpointName: string ): this {
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
- let obj = this.#functionHash[ breakpointName ].find( o => o.callback === callback );
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 {MediaQueriesEvents_Handler} callback - Function to call on mediaquery change
287
- * @param {String} [type=MediaQueriesEvents.TYPE_ON_ENTER] - Select when the function will be called: when entering the query, when leaving it, or on both
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: MediaQueriesEventsCallback, type: MediaQueriesEventsCallbackType = 'enter' ): this {
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: MediaQueriesEventsCallback ): this {
305
- let obj = this.#functionHash[ this.#globalHashName ].find( o => o.callback === callback );
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.update( this.#currentBreakpoint, this.#currentBreakpoint.query.matches );
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: MediaQueriesEventsCallback ): this {
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
- let breakpoint;
350
-
351
- breakpoint = this.getBreakpoint( breakpointName );
353
+ const breakpoint = this.#getBreakpoint( breakpointName );
352
354
 
353
355
  return breakpoint ? breakpoint.query.matches : false;
354
356
  }
@@ -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( () => {} );
@@ -25,6 +23,7 @@ import { animationendEventName } from '../Tools/PrefixedProperties';
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
  */
@@ -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( () =&gt; `{}` );
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
  */
package/Events/PubSub.ts CHANGED
@@ -11,6 +11,7 @@ interface PubSub {
11
11
  * Publish / Suscribe event system
12
12
  *
13
13
  * @example
14
+ * ```ts
14
15
  * pubSub.add([ "MY_EVENT_1", "MY_EVENT_2" ]);
15
16
  * pubSub.add( "MY_EVENT_3" );
16
17
  *
@@ -25,6 +26,7 @@ interface PubSub {
25
26
  * } );
26
27
  *
27
28
  * pubSub.fire( pubSub.MY_EVENT_2, { "myProp": "test" } );
29
+ * ```
28
30
  */
29
31
  class PubSub {
30
32
  #EVENTS_STORE = {};
@@ -54,7 +56,6 @@ class PubSub {
54
56
  /**
55
57
  * Fire an event
56
58
  *
57
- * @param eventName
58
59
  * @param data - Data to be send to the callback functions
59
60
  */
60
61
  fire( eventName: string, data? ): this {
@@ -70,10 +71,9 @@ class PubSub {
70
71
  /**
71
72
  * Bind an event
72
73
  *
73
- * @param eventName
74
- * @param callback - (data) => {}
74
+ * @param callback - (data) =&gt; `{}`
75
75
  */
76
- on( eventName: string, callback: PubSubCallbackType ): this {
76
+ on( eventName: string, callback: FLib.Events.PubSub.Callback ): this {
77
77
  on( this.#EVENTS_STORE, {
78
78
  "eventsName": eventName,
79
79
  "callback": callback
@@ -85,11 +85,8 @@ class PubSub {
85
85
 
86
86
  /**
87
87
  * Unbind an event
88
- *
89
- * @param eventName
90
- * @param callback
91
88
  */
92
- off( eventName: string, callback: PubSubCallbackType ): this {
89
+ off( eventName: string, callback: FLib.Events.PubSub.Callback ): this {
93
90
  off( this.#EVENTS_STORE, {
94
91
  "eventsName": eventName,
95
92
  "callback": callback