File tree 2 files changed +51
-6
lines changed
2 files changed +51
-6
lines changed Original file line number Diff line number Diff line change
1
+ import { describe , it , expect } from "@jest/globals" ;
2
+ import { getKeyframeKeys } from "./core" ;
3
+
4
+ describe ( "getKeyframeKeys" , ( ) => {
5
+ it ( "normal" , ( ) => {
6
+ expect (
7
+ getKeyframeKeys ( [
8
+ { transform : "rotate(-720deg) translateX(0px)" } ,
9
+ { transform : "rotate(-360deg) translateX(-250px)" , offset : 0.25 } ,
10
+ {
11
+ transform : "rotate(0deg) translateX(0px)" ,
12
+ fill : "red" ,
13
+ fontSize : "48px" ,
14
+ fontWeight : "bold" ,
15
+ offset : 0.75 ,
16
+ } ,
17
+ { transform : "rotate(360deg) translateX(0px)" , fill : "lightskyblue" } ,
18
+ ] )
19
+ ) . toEqual ( [ "transform" , "fill" , "fontSize" , "fontWeight" ] ) ;
20
+ } ) ;
21
+
22
+ it ( "ignore offset, easing and composite" , ( ) => {
23
+ expect (
24
+ getKeyframeKeys ( [
25
+ { transform : "rotate(-720deg) translateX(0px)" , easing : "ease" } ,
26
+ {
27
+ transform : "rotate(0deg) translateX(0px)" ,
28
+ offset : 0.75 ,
29
+ composite : "accumulate" ,
30
+ } ,
31
+ { transform : "rotate(360deg) translateX(0px)" } ,
32
+ ] )
33
+ ) . toEqual ( [ "transform" ] ) ;
34
+ } ) ;
35
+
36
+ it ( "map cssFloat and cssOffset" , ( ) => {
37
+ expect ( getKeyframeKeys ( [ { cssFloat : "left" , cssOffset : 10 } ] ) ) . toEqual ( [
38
+ "float" ,
39
+ "offset" ,
40
+ ] ) ;
41
+ } ) ;
42
+ } ) ;
Original file line number Diff line number Diff line change @@ -26,15 +26,18 @@ export interface AnimationOptions
26
26
}
27
27
28
28
export const getKeyframeKeys = ( keyframes : TypedKeyframe [ ] ) : string [ ] =>
29
- uniqBy ( keyframes . flatMap ( getKeys ) ) . map ( ( k ) => {
30
- if ( k === "cssFloat" ) {
31
- return "float" ;
29
+ uniqBy ( keyframes . flatMap ( getKeys ) ) . reduce ( ( acc , k ) => {
30
+ if ( [ "offset" , "easing" , "composite" ] . includes ( k ) ) {
31
+ // Ignore
32
+ } else if ( k === "cssFloat" ) {
33
+ acc . push ( "float" ) ;
32
34
} else if ( k === "cssOffset" ) {
33
- return "offset" ;
35
+ acc . push ( "offset" ) ;
34
36
} else {
35
- return k ;
37
+ acc . push ( k ) ;
36
38
}
37
- } ) ;
39
+ return acc ;
40
+ } , [ ] as string [ ] ) ;
38
41
39
42
export const createAnimation = (
40
43
el : HTMLElement | null ,
You can’t perform that action at this time.
0 commit comments