@creative-web-solution/front-library 6.2.8 → 6.2.10

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,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 6.2.10
4
+
5
+ * Fix file import name
6
+
7
+ ## 6.2.9
8
+
9
+ * Add transition helper
10
+
3
11
 
4
12
  ## 6.2.8
5
13
 
@@ -1,4 +1,4 @@
1
- import { slice } from '../Helpers/Slice';
1
+ import { slice } from '../Helpers/slice';
2
2
 
3
3
 
4
4
  let passiveSupported = false,
@@ -0,0 +1,95 @@
1
+ import onTransitionEnd from '../Events/OnTransitionEnd';
2
+ import onAnimationEnd from '../Events/OnAnimationEnd';
3
+ import { wait } from './Wait';
4
+
5
+
6
+ const KEY = Symbol( 'TransitionHelper' );
7
+
8
+
9
+ function addWatcher( $element, styleChange, isAnimation, options = {} ) {
10
+ if ( $element[ KEY ] ) {
11
+ $element[ KEY ].off();
12
+ }
13
+
14
+ if ( typeof options.delay !== undefined ) {
15
+ options.delay = 'idle'
16
+ }
17
+
18
+ $element[ KEY ] = isAnimation ?
19
+ onAnimationEnd( $element, {
20
+ "animationName": options.animationName,
21
+ "pseudoElement": options.pseudoElement
22
+ } ) :
23
+ onTransitionEnd( $element, {
24
+ "property": options.property,
25
+ "pseudoElement": options.pseudoElement
26
+ } );
27
+
28
+ wait( options.delay ).then( () => styleChange( $element ) );
29
+
30
+ $element[ KEY ].then( () => {
31
+ $element[ KEY ] = null;
32
+ return $element;
33
+ } );
34
+
35
+ return $element[ KEY ];
36
+ }
37
+
38
+
39
+ /**
40
+ * @param styleChange - Change the style of $element inside this function by adding a class or set a style property
41
+ * @param delay - Delay betwwen the add of the listener and call of styleChange.
42
+ *
43
+ * delay = 'idle' : window.requestIdleCallback
44
+ * delay < 0 : window.requestAnimationFrame
45
+ * delay >= 0 : setTimeout
46
+ *
47
+ * @example
48
+ * ```js
49
+ * // Watch for the end of the transition of the property "opacity" on the pseudo element ::after on $element
50
+ *
51
+ * const myWatcher = transitionWatcher( $elment, () => $element.classList.add('some-class'), {
52
+ * "pseudoElement": "after",
53
+ * "property": "opacity"
54
+ * } );
55
+ * ```
56
+ */
57
+ export function transitionWatcher( $element, styleChange, options ) {
58
+ return addWatcher( $element, styleChange, false, options );
59
+ }
60
+
61
+
62
+ /**
63
+ * @param animationStart - Start the animation of $element inside this function by adding a class or set a style property
64
+ * @param delay - Delay betwwen the add of the listener and call of animationStart.
65
+ *
66
+ * delay = 'idle' : window.requestIdleCallback
67
+ * delay < 0 : window.requestAnimationFrame
68
+ * delay >= 0 : setTimeout
69
+ *
70
+ * @example
71
+ * ```js
72
+ * //Watch for the end of the animation "my-animation" on the pseudo element ::after on $element
73
+ *
74
+ * const myWatcher = animationWatcher( $elment, () => $element.classList.add('some-class'), {
75
+ * "pseudoElement": "after",
76
+ * "animationName": ["my-animation"]
77
+ * } );
78
+ * ```
79
+ */
80
+ export function animationWatcher( $element, animationStart, options ) {
81
+ return addWatcher( $element, animationStart, true, options );
82
+ }
83
+
84
+
85
+ /**
86
+ * @example Kill a transition or animation watcher on $element
87
+ *
88
+ * killWatcher( $elment )
89
+ */
90
+ export function killWatcher( $element ) {
91
+ if ( $element[ KEY ] ) {
92
+ $element[ KEY ].off();
93
+ $element[ KEY ] = null;
94
+ }
95
+ }
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 6.2.8
3
+ @version: 6.2.10
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": "6.2.8",
5
+ "version": "6.2.10",
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": [],