11{
2-
2+ // The function that's called from After Effects
3+ // as eKeys.animate()
34'animate' : function (
45 inputKeyframes = requiredArgumentError ( 'Keyframe Array' , '.animate() inputs' ) ,
56 inputTime = requiredArgumentError ( 'Input Time' , '.animate() inputs' )
@@ -98,7 +99,9 @@ const validKeys = inputKeyframes
9899checkTypes ( [ [ inputTime , 'number' ] ] ) ;
99100
100101// Returns the final animated value
102+ // This is the function that's returned
101103const animateBetweenKeys = function ( keys , time ) {
104+
102105 // Creates bezier curve and returns function
103106 // to calculate eased value
104107 const bezier = ( mX1 , mY1 , mX2 , mY2 ) => {
@@ -229,10 +232,9 @@ const animateBetweenKeys = function(keys, time) {
229232 return bezierEasing ;
230233 } ;
231234
235+ // Set current key to most recent keyframe
232236 function getCurrentKeyNum ( keys , time ) {
233237 const lastKeyNum = keys . length - 1 ;
234-
235- // Set current key to most recent keyframe
236238 let curKeyNum = 0 ;
237239 while ( curKeyNum < lastKeyNum && time >= keys [ curKeyNum + 1 ] . keyTime ) {
238240 curKeyNum ++ ;
@@ -270,19 +272,13 @@ const animateBetweenKeys = function(keys, time) {
270272 1 - nextKey . velocityIn / 100
271273 ) ;
272274
273- // Delta calculations
274- const deltaT = nextKey . keyTime - curKey . keyTime ;
275-
276- // Create incrementing time value that is zero
277- // at start keyframe time
275+ // Incrementing time value that
276+ // starts from the current keyTime
278277 const movedTime = Math . max ( time - curKey . keyTime , 0 ) ;
279278
280- // Normalize time input to maximum of one
281- // and to correct speed
282- const timeInput = Math . min ( 1 , movedTime / deltaT ) ;
283-
284- // Get progress value according to easing spline
285- const progress = easingCurve ( timeInput ) ;
279+ const animationLength = nextKey . keyTime - curKey . keyTime ;
280+ const linearProgress = Math . min ( 1 , movedTime / animationLength ) ;
281+ const easedProgress = easingCurve ( linearProgress ) ;
286282
287283 // Performs animation on each element of array individually
288284 const animateArrayFromProgress = ( startArray , endArray , progressAmount ) => {
@@ -295,14 +291,15 @@ const animateBetweenKeys = function(keys, time) {
295291 // Add to current key and return
296292 return startArray . map ( ( item , index ) => item + deltaProgressed [ index ] ) ;
297293 } ;
294+
298295 // Animate between values according to progress
299296 const animateValueFromProgress = ( startVal , endVal , progressAmount ) => {
300297 const valueDelta = endVal - startVal ;
301298 return startVal + valueDelta * progressAmount ;
302299 } ;
303300
304301 // Return animation according to whether values are an array
305- const animateProps = [ curKey . keyValue , nextKey . keyValue , progress ] ;
302+ const animateProps = [ curKey . keyValue , nextKey . keyValue , easedProgress ] ;
306303 return Array . isArray ( curKey . keyValue ) || Array . isArray ( nextKey . keyValue )
307304 ? animateArrayFromProgress ( ...animateProps )
308305 : animateValueFromProgress ( ...animateProps ) ;
0 commit comments