@@ -678,11 +678,13 @@ define(['exports'], (function (exports) { 'use strict';
678678 * it is still playing, just paused).
679679 */
680680 Tween . prototype . update = function ( time , autoStart ) {
681+ var _this = this ;
681682 var _a ;
682683 if ( time === void 0 ) { time = now ( ) ; }
683684 if ( autoStart === void 0 ) { autoStart = true ; }
684685 if ( this . _isPaused )
685686 return true ;
687+ var property ;
686688 var endTime = this . _startTime + this . _duration ;
687689 if ( ! this . _goToEnd && ! this . _isPlaying ) {
688690 if ( time > endTime )
@@ -709,85 +711,72 @@ define(['exports'], (function (exports) { 'use strict';
709711 var elapsedTime = time - this . _startTime ;
710712 var durationAndDelay = this . _duration + ( ( _a = this . _repeatDelayTime ) !== null && _a !== void 0 ? _a : this . _delayTime ) ;
711713 var totalTime = this . _duration + this . _repeat * durationAndDelay ;
712- var elapsed = this . _calculateElapsedPortion ( elapsedTime , durationAndDelay , totalTime ) ;
714+ var calculateElapsedPortion = function ( ) {
715+ if ( _this . _duration === 0 )
716+ return 1 ;
717+ if ( elapsedTime > totalTime ) {
718+ return 1 ;
719+ }
720+ var timesRepeated = Math . trunc ( elapsedTime / durationAndDelay ) ;
721+ var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay ;
722+ // TODO use %?
723+ // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
724+ var portion = Math . min ( timeIntoCurrentRepeat / _this . _duration , 1 ) ;
725+ if ( portion === 0 && elapsedTime === _this . _duration ) {
726+ return 1 ;
727+ }
728+ return portion ;
729+ } ;
730+ var elapsed = calculateElapsedPortion ( ) ;
713731 var value = this . _easingFunction ( elapsed ) ;
714- var status = this . _calculateCompletionStatus ( elapsedTime , durationAndDelay ) ;
715- if ( status === 'repeat' ) {
716- // the current update is happening after the instant the tween repeated
717- this . _processRepetition ( elapsedTime , durationAndDelay ) ;
718- }
732+ // properties transformations
719733 this . _updateProperties ( this . _object , this . _valuesStart , this . _valuesEnd , value ) ;
720- if ( status === 'about-to-repeat' ) {
721- // the current update is happening at the exact instant the tween is going to repeat
722- // the values should match the end of the tween, not the beginning,
723- // that's why _processRepetition happens after _updateProperties
724- this . _processRepetition ( elapsedTime , durationAndDelay ) ;
725- }
726734 if ( this . _onUpdateCallback ) {
727735 this . _onUpdateCallback ( this . _object , elapsed ) ;
728736 }
729- if ( status === 'repeat' || status === 'about-to-repeat' ) {
730- if ( this . _onRepeatCallback ) {
731- this . _onRepeatCallback ( this . _object ) ;
732- }
733- this . _onEveryStartCallbackFired = false ;
734- }
735- else if ( status === 'completed' ) {
736- this . _isPlaying = false ;
737- if ( this . _onCompleteCallback ) {
738- this . _onCompleteCallback ( this . _object ) ;
739- }
740- for ( var i = 0 , numChainedTweens = this . _chainedTweens . length ; i < numChainedTweens ; i ++ ) {
741- // Make the chained tweens start exactly at the time they should,
742- // even if the `update()` method was called way past the duration of the tween
743- this . _chainedTweens [ i ] . start ( this . _startTime + this . _duration , false ) ;
744- }
745- }
746- return status !== 'completed' ;
747- } ;
748- Tween . prototype . _calculateElapsedPortion = function ( elapsedTime , durationAndDelay , totalTime ) {
749- if ( this . _duration === 0 || elapsedTime > totalTime ) {
750- return 1 ;
751- }
752- var timeIntoCurrentRepeat = elapsedTime % durationAndDelay ;
753- var portion = Math . min ( timeIntoCurrentRepeat / this . _duration , 1 ) ;
754- if ( portion === 0 && elapsedTime !== 0 && elapsedTime % this . _duration === 0 ) {
755- return 1 ;
756- }
757- return portion ;
758- } ;
759- Tween . prototype . _calculateCompletionStatus = function ( elapsedTime , durationAndDelay ) {
760- if ( this . _duration !== 0 && elapsedTime < this . _duration ) {
761- return 'playing' ;
762- }
763- if ( this . _repeat <= 0 ) {
764- return 'completed' ;
765- }
766- if ( elapsedTime === this . _duration ) {
767- return 'about-to-repeat' ;
768- }
769- return 'repeat' ;
770- } ;
771- Tween . prototype . _processRepetition = function ( elapsedTime , durationAndDelay ) {
772- var completeCount = Math . min ( Math . trunc ( ( elapsedTime - this . _duration ) / durationAndDelay ) + 1 , this . _repeat ) ;
773- if ( isFinite ( this . _repeat ) ) {
774- this . _repeat -= completeCount ;
775- }
776- // Reassign starting values, restart by making startTime = now
777- for ( var property in this . _valuesStartRepeat ) {
778- var valueEnd = this . _valuesEnd [ property ] ;
779- if ( ! this . _yoyo && typeof valueEnd === 'string' ) {
780- this . _valuesStartRepeat [ property ] = this . _valuesStartRepeat [ property ] + parseFloat ( valueEnd ) ;
737+ if ( this . _duration === 0 || elapsedTime >= this . _duration ) {
738+ if ( this . _repeat > 0 ) {
739+ var completeCount = Math . min ( Math . trunc ( ( elapsedTime - this . _duration ) / durationAndDelay ) + 1 , this . _repeat ) ;
740+ if ( isFinite ( this . _repeat ) ) {
741+ this . _repeat -= completeCount ;
742+ }
743+ // Reassign starting values, restart by making startTime = now
744+ for ( property in this . _valuesStartRepeat ) {
745+ if ( ! this . _yoyo && typeof this . _valuesEnd [ property ] === 'string' ) {
746+ this . _valuesStartRepeat [ property ] =
747+ // eslint-disable-next-line
748+ // @ts -ignore FIXME?
749+ this . _valuesStartRepeat [ property ] + parseFloat ( this . _valuesEnd [ property ] ) ;
750+ }
751+ if ( this . _yoyo ) {
752+ this . _swapEndStartRepeatValues ( property ) ;
753+ }
754+ this . _valuesStart [ property ] = this . _valuesStartRepeat [ property ] ;
755+ }
756+ if ( this . _yoyo ) {
757+ this . _reversed = ! this . _reversed ;
758+ }
759+ this . _startTime += durationAndDelay * completeCount ;
760+ if ( this . _onRepeatCallback ) {
761+ this . _onRepeatCallback ( this . _object ) ;
762+ }
763+ this . _onEveryStartCallbackFired = false ;
764+ return true ;
781765 }
782- if ( this . _yoyo ) {
783- this . _swapEndStartRepeatValues ( property ) ;
766+ else {
767+ if ( this . _onCompleteCallback ) {
768+ this . _onCompleteCallback ( this . _object ) ;
769+ }
770+ for ( var i = 0 , numChainedTweens = this . _chainedTweens . length ; i < numChainedTweens ; i ++ ) {
771+ // Make the chained tweens start exactly at the time they should,
772+ // even if the `update()` method was called way past the duration of the tween
773+ this . _chainedTweens [ i ] . start ( this . _startTime + this . _duration , false ) ;
774+ }
775+ this . _isPlaying = false ;
776+ return false ;
784777 }
785- this . _valuesStart [ property ] = this . _valuesStartRepeat [ property ] ;
786778 }
787- if ( this . _yoyo ) {
788- this . _reversed = ! this . _reversed ;
789- }
790- this . _startTime += durationAndDelay * completeCount ;
779+ return true ;
791780 } ;
792781 Tween . prototype . _updateProperties = function ( _object , _valuesStart , _valuesEnd , value ) {
793782 for ( var property in _valuesEnd ) {
0 commit comments