UNPKG

1.63 kBJavaScriptView Raw
1import * as is from '../../is';
2
3function getEasedValue( type, start, end, percent, easingFn ){
4 if( percent === 1 ){
5 return end;
6 }
7
8 if( start === end ){
9 return end;
10 }
11
12 let val = easingFn( start, end, percent );
13
14 if( type == null ){
15 return val;
16 }
17
18 if( type.roundValue || type.color ){
19 val = Math.round( val );
20 }
21
22 if( type.min !== undefined ){
23 val = Math.max( val, type.min );
24 }
25
26 if( type.max !== undefined ){
27 val = Math.min( val, type.max );
28 }
29
30 return val;
31}
32
33function getValue( prop, spec ){
34 if( prop.pfValue != null || prop.value != null ){
35 if( prop.pfValue != null && (spec == null || spec.type.units !== '%') ){
36 return prop.pfValue;
37 } else {
38 return prop.value;
39 }
40 } else {
41 return prop;
42 }
43}
44
45function ease( startProp, endProp, percent, easingFn, propSpec ){
46 let type = propSpec != null ? propSpec.type : null;
47
48 if( percent < 0 ){
49 percent = 0;
50 } else if( percent > 1 ){
51 percent = 1;
52 }
53
54 let start = getValue( startProp, propSpec );
55 let end = getValue( endProp, propSpec );
56
57 if( is.number( start ) && is.number( end ) ){
58 return getEasedValue( type, start, end, percent, easingFn );
59
60 } else if( is.array( start ) && is.array( end ) ){
61 let easedArr = [];
62
63 for( let i = 0; i < end.length; i++ ){
64 let si = start[ i ];
65 let ei = end[ i ];
66
67 if( si != null && ei != null ){
68 let val = getEasedValue( type, si, ei, percent, easingFn );
69
70 easedArr.push( val );
71 } else {
72 easedArr.push( ei );
73 }
74 }
75
76 return easedArr;
77 }
78
79 return undefined;
80}
81
82export default ease;