1- define ( [ 'exports' ] , function ( exports ) { 'use strict' ;
1+ define ( [ 'exports' ] , ( function ( exports ) { 'use strict' ;
22
33 /**
44 * The Ease class provides a collection of easing functions for use with tween.js.
@@ -215,37 +215,7 @@ define(['exports'], function (exports) { 'use strict';
215215 } ,
216216 } ) ;
217217
218- var now ;
219- // Include a performance.now polyfill.
220- // In node.js, use process.hrtime.
221- // eslint-disable-next-line
222- // @ts -ignore
223- if ( typeof self === 'undefined' && typeof process !== 'undefined' && process . hrtime ) {
224- now = function ( ) {
225- // eslint-disable-next-line
226- // @ts -ignore
227- var time = process . hrtime ( ) ;
228- // Convert [seconds, nanoseconds] to milliseconds.
229- return time [ 0 ] * 1000 + time [ 1 ] / 1000000 ;
230- } ;
231- }
232- // In a browser, use self.performance.now if it is available.
233- else if ( typeof self !== 'undefined' && self . performance !== undefined && self . performance . now !== undefined ) {
234- // This must be bound, because directly assigning this function
235- // leads to an invocation exception in Chrome.
236- now = self . performance . now . bind ( self . performance ) ;
237- }
238- // Use Date.now if it is available.
239- else if ( Date . now !== undefined ) {
240- now = Date . now ;
241- }
242- // Otherwise, use 'new Date().getTime()'.
243- else {
244- now = function ( ) {
245- return new Date ( ) . getTime ( ) ;
246- } ;
247- }
248- var now$1 = now ;
218+ var now = function ( ) { return performance . now ( ) ; } ;
249219
250220 /**
251221 * Controlling groups of tweens
@@ -276,7 +246,7 @@ define(['exports'], function (exports) { 'use strict';
276246 delete this . _tweensAddedDuringUpdate [ tween . getId ( ) ] ;
277247 } ;
278248 Group . prototype . update = function ( time , preserve ) {
279- if ( time === void 0 ) { time = now$1 ( ) ; }
249+ if ( time === void 0 ) { time = now ( ) ; }
280250 if ( preserve === void 0 ) { preserve = false ; }
281251 var tweenIds = Object . keys ( this . _tweens ) ;
282252 if ( tweenIds . length === 0 ) {
@@ -417,6 +387,7 @@ define(['exports'], function (exports) { 'use strict';
417387 this . _valuesEnd = { } ;
418388 this . _valuesStartRepeat = { } ;
419389 this . _duration = 1000 ;
390+ this . _isDynamic = false ;
420391 this . _initialRepeat = 0 ;
421392 this . _repeat = 0 ;
422393 this . _yoyo = false ;
@@ -432,6 +403,7 @@ define(['exports'], function (exports) { 'use strict';
432403 this . _onEveryStartCallbackFired = false ;
433404 this . _id = Sequence . nextId ( ) ;
434405 this . _isChainStopped = false ;
406+ this . _propertiesAreSetUp = false ;
435407 this . _goToEnd = false ;
436408 }
437409 Tween . prototype . getId = function ( ) {
@@ -443,24 +415,27 @@ define(['exports'], function (exports) { 'use strict';
443415 Tween . prototype . isPaused = function ( ) {
444416 return this . _isPaused ;
445417 } ;
446- Tween . prototype . to = function ( properties , duration ) {
447- // TODO? restore this, then update the 07_dynamic_to example to set fox
448- // tween's to on each update. That way the behavior is opt-in (there's
449- // currently no opt-out).
450- // for (const prop in properties) this._valuesEnd[prop] = properties[prop]
451- this . _valuesEnd = Object . create ( properties ) ;
452- if ( duration !== undefined ) {
453- this . _duration = duration ;
454- }
418+ Tween . prototype . to = function ( target , duration ) {
419+ if ( duration === void 0 ) { duration = 1000 ; }
420+ if ( this . _isPlaying )
421+ throw new Error ( 'Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.' ) ;
422+ this . _valuesEnd = target ;
423+ this . _propertiesAreSetUp = false ;
424+ this . _duration = duration ;
455425 return this ;
456426 } ;
457- Tween . prototype . duration = function ( d ) {
458- if ( d === void 0 ) { d = 1000 ; }
459- this . _duration = d ;
427+ Tween . prototype . duration = function ( duration ) {
428+ if ( duration === void 0 ) { duration = 1000 ; }
429+ this . _duration = duration ;
430+ return this ;
431+ } ;
432+ Tween . prototype . dynamic = function ( dynamic ) {
433+ if ( dynamic === void 0 ) { dynamic = false ; }
434+ this . _isDynamic = dynamic ;
460435 return this ;
461436 } ;
462437 Tween . prototype . start = function ( time , overrideStartingValues ) {
463- if ( time === void 0 ) { time = now$1 ( ) ; }
438+ if ( time === void 0 ) { time = now ( ) ; }
464439 if ( overrideStartingValues === void 0 ) { overrideStartingValues = false ; }
465440 if ( this . _isPlaying ) {
466441 return this ;
@@ -484,7 +459,17 @@ define(['exports'], function (exports) { 'use strict';
484459 this . _isChainStopped = false ;
485460 this . _startTime = time ;
486461 this . _startTime += this . _delayTime ;
487- this . _setupProperties ( this . _object , this . _valuesStart , this . _valuesEnd , this . _valuesStartRepeat , overrideStartingValues ) ;
462+ if ( ! this . _propertiesAreSetUp || overrideStartingValues ) {
463+ this . _propertiesAreSetUp = true ;
464+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
465+ if ( ! this . _isDynamic ) {
466+ var tmp = { } ;
467+ for ( var prop in this . _valuesEnd )
468+ tmp [ prop ] = this . _valuesEnd [ prop ] ;
469+ this . _valuesEnd = tmp ;
470+ }
471+ this . _setupProperties ( this . _object , this . _valuesStart , this . _valuesEnd , this . _valuesStartRepeat , overrideStartingValues ) ;
472+ }
488473 return this ;
489474 } ;
490475 Tween . prototype . startFromCurrentValues = function ( time ) {
@@ -507,26 +492,42 @@ define(['exports'], function (exports) { 'use strict';
507492 if ( endValues . length === 0 ) {
508493 continue ;
509494 }
510- // handle an array of relative values
511- endValues = endValues . map ( this . _handleRelativeValue . bind ( this , startValue ) ) ;
512- // Create a local copy of the Array with the start value at the front
513- if ( _valuesStart [ property ] === undefined ) {
514- _valuesEnd [ property ] = [ startValue ] . concat ( endValues ) ;
495+ // Handle an array of relative values.
496+ // Creates a local copy of the Array with the start value at the front
497+ var temp = [ startValue ] ;
498+ for ( var i = 0 , l = endValues . length ; i < l ; i += 1 ) {
499+ var value = this . _handleRelativeValue ( startValue , endValues [ i ] ) ;
500+ if ( isNaN ( value ) ) {
501+ isInterpolationList = false ;
502+ console . warn ( 'Found invalid interpolation list. Skipping.' ) ;
503+ break ;
504+ }
505+ temp . push ( value ) ;
506+ }
507+ if ( isInterpolationList ) {
508+ // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
509+ _valuesEnd [ property ] = temp ;
510+ // }
515511 }
516512 }
517513 // handle the deepness of the values
518514 if ( ( propType === 'object' || startValueIsArray ) && startValue && ! isInterpolationList ) {
519515 _valuesStart [ property ] = startValueIsArray ? [ ] : { } ;
520- // eslint-disable-next-line
521- for ( var prop in startValue ) {
522- // eslint-disable-next-line
523- // @ts -ignore FIXME?
524- _valuesStart [ property ] [ prop ] = startValue [ prop ] ;
516+ var nestedObject = startValue ;
517+ for ( var prop in nestedObject ) {
518+ _valuesStart [ property ] [ prop ] = nestedObject [ prop ] ;
525519 }
526- _valuesStartRepeat [ property ] = startValueIsArray ? [ ] : { } ; // TODO? repeat nested values? And yoyo? And array values?
527- // eslint-disable-next-line
528- // @ts -ignore FIXME?
529- this . _setupProperties ( startValue , _valuesStart [ property ] , _valuesEnd [ property ] , _valuesStartRepeat [ property ] , overrideStartingValues ) ;
520+ // TODO? repeat nested values? And yoyo? And array values?
521+ _valuesStartRepeat [ property ] = startValueIsArray ? [ ] : { } ;
522+ var endValues = _valuesEnd [ property ] ;
523+ // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
524+ if ( ! this . _isDynamic ) {
525+ var tmp = { } ;
526+ for ( var prop in endValues )
527+ tmp [ prop ] = endValues [ prop ] ;
528+ _valuesEnd [ property ] = endValues = tmp ;
529+ }
530+ this . _setupProperties ( nestedObject , _valuesStart [ property ] , endValues , _valuesStartRepeat [ property ] , overrideStartingValues ) ;
530531 }
531532 else {
532533 // Save the starting value, but only once unless override is requested.
@@ -572,7 +573,7 @@ define(['exports'], function (exports) { 'use strict';
572573 return this ;
573574 } ;
574575 Tween . prototype . pause = function ( time ) {
575- if ( time === void 0 ) { time = now$1 ( ) ; }
576+ if ( time === void 0 ) { time = now ( ) ; }
576577 if ( this . _isPaused || ! this . _isPlaying ) {
577578 return this ;
578579 }
@@ -583,7 +584,7 @@ define(['exports'], function (exports) { 'use strict';
583584 return this ;
584585 } ;
585586 Tween . prototype . resume = function ( time ) {
586- if ( time === void 0 ) { time = now$1 ( ) ; }
587+ if ( time === void 0 ) { time = now ( ) ; }
587588 if ( ! this . _isPaused || ! this . _isPlaying ) {
588589 return this ;
589590 }
@@ -674,7 +675,7 @@ define(['exports'], function (exports) { 'use strict';
674675 * it is still playing, just paused).
675676 */
676677 Tween . prototype . update = function ( time , autoStart ) {
677- if ( time === void 0 ) { time = now$1 ( ) ; }
678+ if ( time === void 0 ) { time = now ( ) ; }
678679 if ( autoStart === void 0 ) { autoStart = true ; }
679680 if ( this . _isPaused )
680681 return true ;
@@ -797,9 +798,7 @@ define(['exports'], function (exports) { 'use strict';
797798 if ( end . charAt ( 0 ) === '+' || end . charAt ( 0 ) === '-' ) {
798799 return start + parseFloat ( end ) ;
799800 }
800- else {
801- return parseFloat ( end ) ;
802- }
801+ return parseFloat ( end ) ;
803802 } ;
804803 Tween . prototype . _swapEndStartRepeatValues = function ( property ) {
805804 var tmp = this . _valuesStartRepeat [ property ] ;
@@ -815,7 +814,7 @@ define(['exports'], function (exports) { 'use strict';
815814 return Tween ;
816815 } ( ) ) ;
817816
818- var VERSION = '19 .0.0' ;
817+ var VERSION = '20 .0.0' ;
819818
820819 /**
821820 * Tween.js - Licensed under the MIT license
@@ -846,7 +845,7 @@ define(['exports'], function (exports) { 'use strict';
846845 Easing : Easing ,
847846 Group : Group ,
848847 Interpolation : Interpolation ,
849- now : now$1 ,
848+ now : now ,
850849 Sequence : Sequence ,
851850 nextId : nextId ,
852851 Tween : Tween ,
@@ -868,11 +867,11 @@ define(['exports'], function (exports) { 'use strict';
868867 exports . default = exports$1 ;
869868 exports . getAll = getAll ;
870869 exports . nextId = nextId ;
871- exports . now = now$1 ;
870+ exports . now = now ;
872871 exports . remove = remove ;
873872 exports . removeAll = removeAll ;
874873 exports . update = update ;
875874
876875 Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
877876
878- } ) ;
877+ } ) ) ;
0 commit comments