/
mo.js
9263 lines (7985 loc) · 271 KB
/
mo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "build/";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(53);
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
__webpack_require__(59);
__webpack_require__(58);
module.exports = __webpack_require__(65)('iterator');
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _getPrototypeOf = __webpack_require__(26);
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = __webpack_require__(21);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = __webpack_require__(22);
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = __webpack_require__(23);
var _get3 = _interopRequireDefault(_get2);
var _createClass2 = __webpack_require__(24);
var _createClass3 = _interopRequireDefault(_createClass2);
var _inherits2 = __webpack_require__(20);
var _inherits3 = _interopRequireDefault(_inherits2);
var _h = __webpack_require__(16);
var _h2 = _interopRequireDefault(_h);
var _tweener = __webpack_require__(9);
var _tweener2 = _interopRequireDefault(_tweener);
var _easing = __webpack_require__(19);
var _easing2 = _interopRequireDefault(_easing);
var _module = __webpack_require__(13);
var _module2 = _interopRequireDefault(_module);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// import h from '../h';
var Tween = function (_Module) {
(0, _inherits3.default)(Tween, _Module);
(0, _createClass3.default)(Tween, [{
key: '_declareDefaults',
/*
Method do declare defaults with this._defaults object.
@private
*/
value: function _declareDefaults() {
// DEFAULTS
this._defaults = {
/* duration of the tween [0..∞] */
duration: 350,
/* delay of the tween [-∞..∞] */
delay: 0,
/* repeat of the tween [0..∞], means how much to
repeat the tween regardless first run,
for instance repeat: 2 will make the tween run 3 times */
repeat: 0,
/* speed of playback [0..∞], speed that is less then 1
will slowdown playback, for instance .5 will make tween
run 2x slower. Speed of 2 will speedup the tween to 2x. */
speed: 1,
/* flip onUpdate's progress on each even period.
note that callbacks order won't flip at least
for now (under consideration). */
yoyo: false,
/* easing for the tween, could be any easing type [link to easing-types.md] */
easing: 'Ease.Out',
/* custom tween's name */
name: null,
/* custom tween's base name */
nameBase: 'Tween',
/*
onProgress callback runs before any other callback.
@param {Number} The entire, not eased, progress
of the tween regarding repeat option.
@param {Boolean} The direction of the tween.
`true` for forward direction.
`false` for backward direction(tween runs in reverse).
*/
onProgress: null,
/*
onStart callback runs on very start of the tween just after onProgress
one. Runs on very end of the tween if tween is reversed.
@param {Boolean} Direction of the tween.
`true` for forward direction.
`false` for backward direction(tween runs in reverse).
*/
onStart: null,
onComplete: null,
onRepeatStart: null,
onRepeatComplete: null,
onFirstUpdate: null,
onUpdate: null,
isChained: false,
// playback callbacks
onPlaybackStart: null,
onPlaybackPause: null,
onPlaybackStop: null,
onPlaybackComplete: null,
// context which all callbacks will be called with
callbacksContext: null
};
}
/*
API method to run the Tween.
@public
@param {Number} Shift time in milliseconds.
@return {Object} Self.
*/
}, {
key: 'play',
value: function play() {
var shift = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
if (this._state === 'play' && this._isRunning) {
return this;
}
this._props.isReversed = false;
this._subPlay(shift, 'play');
this._setPlaybackState('play');
return this;
}
/*
API method to run the Tween in reverse.
@public
@param {Number} Shift time in milliseconds.
@return {Object} Self.
*/
}, {
key: 'playBackward',
value: function playBackward() {
var shift = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
if (this._state === 'reverse' && this._isRunning) {
return this;
}
this._props.isReversed = true;
this._subPlay(shift, 'reverse');
this._setPlaybackState('reverse');
return this;
}
/*
API method to pause Tween.
@public
@returns {Object} Self.
*/
}, {
key: 'pause',
value: function pause() {
if (this._state === 'pause' || this._state === 'stop') {
return this;
}
this._removeFromTweener();
this._setPlaybackState('pause');
return this;
}
/*
API method to stop the Tween.
@public
@param {Number} Progress [0..1] to set when stopped.
@returns {Object} Self.
*/
}, {
key: 'stop',
value: function stop(progress) {
if (this._state === 'stop') {
return this;
}
this._props.isReversed = false;
this._removeFromTweener();
// if progress passed - use it
var stopProc = progress != null ? progress
/* if no progress passsed - set 1 if tween
is playingBackward, otherwise set to 0 */
: this._state === 'reverse' ? 1 : 0;
this.setProgress(stopProc);
this._setPlaybackState('stop');
this._prevTime = null;
return this;
}
/*
API method to replay(restart) the Tween.
@public
@param {Number} Shift time in milliseconds.
@returns {Object} Self.
*/
}, {
key: 'replay',
value: function replay() {
var shift = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
this.stop();
this.play(shift);
return this;
}
/*
API method to replay(restart) backward the Tween.
@public
@param {Number} Shift time in milliseconds.
@returns {Object} Self.
*/
}, {
key: 'replayBackward',
value: function replayBackward() {
var shift = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
this.stop();
this.playBackward(shift);
return this;
}
/*
API method to set progress on tween.
@public
@param {Number} Progress to set.
@returns {Object} Self.
*/
}, {
key: 'setProgress',
value: function setProgress(progress) {
var p = this._props;
// set start time if there is no one yet.
!p.startTime && this._setStartTime();
// reset play time
this._playTime = null;
// progress should be in range of [0..1]
progress < 0 && (progress = 0);
progress > 1 && (progress = 1);
// update self with calculated time
this._update(p.startTime - p.delay + progress * p.repeatTime);
return this;
}
/*
Method to set tween's speed.
@public
@param {Number} Speed value.
@returns this.
*/
}, {
key: 'setSpeed',
value: function setSpeed(speed) {
this._props.speed = speed;
// if playing - normalize _startTime and _prevTime to the current point.
if (this._state === 'play' || this._state === 'reverse') {
this._setResumeTime(this._state);
}
return this;
}
// ^ PUBLIC METHOD(S) ^
// v PRIVATE METHOD(S) v
/*
Method to launch play. Used as launch
method for bothplay and reverse methods.
@private
@param {Number} Shift time in milliseconds.
@param {String} Play or reverse state.
@return {Object} Self.
*/
}, {
key: '_subPlay',
value: function _subPlay() {
var shift = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
var state = arguments[1];
var resumeTime,
startTime,
p = this._props,
// check if direction of playback changes,
// if so, the _progressTime needs to be flipped
_state = this._state,
_prevState = this._prevState,
isPause = _state === 'pause',
wasPlay = _state === 'play' || isPause && _prevState === 'play',
wasReverse = _state === 'reverse' || isPause && _prevState === 'reverse',
isFlip = wasPlay && state === 'reverse' || wasReverse && state === 'play';
// if tween was ended, set progress to 0 if not, set to elapsed progress
this._progressTime = this._progressTime >= p.repeatTime ? 0 : this._progressTime;
// flip the _progressTime if playback direction changed
if (isFlip) {
this._progressTime = p.repeatTime - this._progressTime;
}
// set resume time and normalize prev/start times
this._setResumeTime(state, shift);
// add self to tweener = play
_tweener2.default.add(this);
return this;
}
/*
Method to set _resumeTime, _startTime and _prevTime.
@private
@param {String} Current state. [play, reverse]
@param {Number} Time shift. *Default* is 0.
*/
}, {
key: '_setResumeTime',
value: function _setResumeTime(state) {
var shift = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
// get current moment as resume time
this._resumeTime = performance.now();
// set start time regarding passed `shift` and `procTime`
var startTime = this._resumeTime - Math.abs(shift) - this._progressTime;
this._setStartTime(startTime, false);
// if we have prevTime - we need to normalize
// it for the current resume time
if (this._prevTime != null) {
this._prevTime = state === 'play' ? this._normPrevTimeForward() : this._props.endTime - this._progressTime;
}
}
/*
Method recalculate _prevTime for forward direction.
@private
@return {Number} Normalized prev time.
*/
}, {
key: '_normPrevTimeForward',
value: function _normPrevTimeForward() {
var p = this._props;
return p.startTime + this._progressTime - p.delay;
}
/*
Constructor of the class.
@private
*/
}]);
function Tween() {
var _ret;
var o = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
(0, _classCallCheck3.default)(this, Tween);
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Tween).call(this, o));
_this._props.name == null && _this._setSelfName();
return _ret = _this, (0, _possibleConstructorReturn3.default)(_this, _ret);
}
/*
Method to set self name to generic one.
@private
*/
(0, _createClass3.default)(Tween, [{
key: '_setSelfName',
value: function _setSelfName() {
var globalName = '_' + this._props.nameBase + 's';
// track amount of tweens globally
_tweener2.default[globalName] = _tweener2.default[globalName] == null ? 1 : ++_tweener2.default[globalName];
// and set generic tween's name || Tween # ||
this._props.name = this._props.nameBase + ' ' + _tweener2.default[globalName];
}
/*
Method set playback state string.
@private
@param {String} State name
*/
}, {
key: '_setPlaybackState',
value: function _setPlaybackState(state) {
// save previous state
this._prevState = this._state;
this._state = state;
// callbacks
var wasPause = this._prevState === 'pause',
wasStop = this._prevState === 'stop',
wasPlay = this._prevState === 'play',
wasReverse = this._prevState === 'reverse',
wasPlaying = wasPlay || wasReverse,
wasStill = wasStop || wasPause;
if ((state === 'play' || state === 'reverse') && wasStill) {
this._playbackStart();
}
if (state === 'pause' && wasPlaying) {
this._playbackPause();
}
if (state === 'stop' && (wasPlaying || wasPause)) {
this._playbackStop();
}
}
/*
Method to declare some vars.
@private
*/
}, {
key: '_vars',
value: function _vars() {
// call _vars @ Module
// super._vars();
this.progress = 0;
this._prevTime = null;
this._progressTime = 0;
this._negativeShift = 0;
this._state = 'stop';
// if negative delay was specified,
// save it to _negativeShift property and
// reset it back to 0
if (this._props.delay < 0) {
this._negativeShift = this._props.delay;
this._props.delay = 0;
}
return this._calcDimentions();
}
/*
Method to calculate tween's dimentions.
@private
*/
}, {
key: '_calcDimentions',
value: function _calcDimentions() {
this._props.time = this._props.duration + this._props.delay;
this._props.repeatTime = this._props.time * (this._props.repeat + 1);
}
/*
Method to extend defaults by options and put them in _props.
@private
*/
}, {
key: '_extendDefaults',
value: function _extendDefaults() {
// save callback overrides object with fallback to empty one
this._callbackOverrides = this._o.callbackOverrides || {};
delete this._o.callbackOverrides;
// call the _extendDefaults @ Module
(0, _get3.default)((0, _getPrototypeOf2.default)(Tween.prototype), '_extendDefaults', this).call(this);
this._props.easing = _easing2.default.parseEasing(this._props.easing);
}
/*
Method for setting start and end time to props.
@private
@param {Number(Timestamp)}, {Null} Start time.
@param {Boolean} Should reset flags.
@returns this
*/
}, {
key: '_setStartTime',
value: function _setStartTime(time) {
var isResetFlags = arguments.length <= 1 || arguments[1] === undefined ? true : arguments[1];
var p = this._props,
shiftTime = p.shiftTime || 0;
// reset flags
if (isResetFlags) {
this._isCompleted = false;this._isRepeatCompleted = false;
this._isStarted = false;
}
// set start time to passed time or to the current moment
var startTime = time == null ? performance.now() : time;
// calculate bounds
// - negativeShift is negative delay in options hash
// - shift time is shift of the parent
p.startTime = startTime + p.delay + this._negativeShift + shiftTime;
p.endTime = p.startTime + p.repeatTime - p.delay;
// set play time to the startTime
// if playback controls are used - use _resumeTime as play time,
// else use shifted startTime -- shift is needed for timelines append chains
this._playTime = this._resumeTime != null ? this._resumeTime : startTime + shiftTime;
this._resumeTime = null;
return this;
}
/*
Method to update tween's progress.
@private
@param {Number} Current update time.
-- next params only present when parent Timeline calls the method.
@param {Number} Previous Timeline's update time.
@param {Boolean} Was parent in yoyo period.
@param {Number} [-1, 0, 1] If update is on edge.
-1 = edge jump in negative direction.
0 = no edge jump.
1 = edge jump in positive direction.
*/
}, {
key: '_update',
value: function _update(time, timelinePrevTime, wasYoyo, onEdge) {
var p = this._props;
// if we don't the _prevTime thus the direction we are heading to,
// but prevTime was passed thus we are child of a Timeline
// set _prevTime to passed one and pretent that there was unknown
// update to not to block start/complete callbacks
if (this._prevTime == null && timelinePrevTime != null) {
this._prevTime = timelinePrevTime;
this._wasUknownUpdate = true;
}
// cache vars
var startPoint = p.startTime - p.delay;
// if speed param was defined - calculate
// new time regarding speed
if (p.speed && this._playTime) {
// play point + ( speed * delta )
time = this._playTime + p.speed * (time - this._playTime);
}
// if parent is onEdge but not very start nor very end
if (onEdge && wasYoyo != null) {
var T = this._getPeriod(time),
isYoyo = !!(p.yoyo && this._props.repeat && T % 2 === 1);
// forward edge direction
if (onEdge === 1) {
// jumped from yoyo period?
if (wasYoyo) {
this._prevTime = time + 1;
this._repeatStart(time, isYoyo);
this._start(time, isYoyo);
} else {
this._prevTime = time - 1;
this._repeatComplete(time, isYoyo);
this._complete(time, isYoyo);
}
// backward edge direction
} else if (onEdge === -1) {
// jumped from yoyo period?
if (wasYoyo) {
this._prevTime = time - 1;
this._repeatComplete(time, isYoyo);
this._complete(time, isYoyo);
} else {
// call _start callbacks only if prev time was in active area
// not always true for append chains
if (this._prevTime >= p.startTime && this._prevTime <= p.endTime) {
this._prevTime = time + 1;
this._repeatStart(time, isYoyo);
this._start(time, isYoyo);
// reset isCOmpleted immediately to prevent onComplete cb
this._isCompleted = true;
}
}
}
// reset the _prevTime - drop one frame to undestand
// where we are heading
this._prevTime = null;
}
// if in active area and not ended - save progress time
// for pause/play purposes.
if (time > startPoint && time < p.endTime) {
this._progressTime = time - startPoint;
}
// else if not started or ended set progress time to 0
else if (time <= startPoint) {
this._progressTime = 0;
} else if (time >= p.endTime) {
// set progress time to repeat time + tiny cofficient
// to make it extend further than the end time
this._progressTime = p.repeatTime + .00000000001;
}
// reverse time if _props.isReversed is set
if (p.isReversed) {
time = p.endTime - this._progressTime;
}
// We need to know what direction we are heading to,
// so if we don't have the previous update value - this is very first
// update, - skip it entirely and wait for the next value
if (this._prevTime === null) {
this._prevTime = time;
this._wasUknownUpdate = true;
return false;
}
// ====== AFTER SKIPPED FRAME ======
// handle onProgress callback
if (time >= startPoint && time <= p.endTime) {
this._progress((time - startPoint) / p.repeatTime, time);
}
/*
if time is inside the active area of the tween.
active area is the area from start time to end time,
with all the repeat and delays in it
*/
if (time >= p.startTime && time <= p.endTime) {
this._updateInActiveArea(time);
} else {
this._isInActiveArea && this._updateInInactiveArea(time);
}
this._prevTime = time;
// console.log(this._prevTime)
return time >= p.endTime || time <= startPoint;
}
/*
Method to handle tween's progress in inactive area.
@private
@param {Number} Current update time.
*/
}, {
key: '_updateInInactiveArea',
value: function _updateInInactiveArea(time) {
if (!this._isInActiveArea) {
return;
}
var p = this._props;
// complete if time is larger then end time
if (time > p.endTime && !this._isCompleted) {
this._progress(1, time);
// get period number
var T = this._getPeriod(p.endTime),
isYoyo = p.yoyo && T % 2 === 0;
this._setProgress(isYoyo ? 0 : 1, time, isYoyo);
this._repeatComplete(time, isYoyo);
this._complete(time, isYoyo);
}
// if was active and went to - inactive area "-"
if (time < this._prevTime && time < p.startTime && !this._isStarted) {
// if was in active area and didn't fire onStart callback
this._progress(0, time, false);
this._setProgress(0, time, false);
this._isRepeatStart = false;
this._repeatStart(time, false);
this._start(time, false);
}
this._isInActiveArea = false;
}
/*
Method to handle tween's progress in active area.
@private
@param {Number} Current update time.
*/
}, {
key: '_updateInActiveArea',
value: function _updateInActiveArea(time) {
var props = this._props,
delayDuration = props.delay + props.duration,
startPoint = props.startTime - props.delay,
elapsed = (time - props.startTime + props.delay) % delayDuration,
TCount = Math.round((props.endTime - props.startTime + props.delay) / delayDuration),
T = this._getPeriod(time),
TValue = this._delayT,
prevT = this._getPeriod(this._prevTime),
TPrevValue = this._delayT;
// "zero" and "one" value regarding yoyo and it's period
var isYoyo = props.yoyo && T % 2 === 1,
isYoyoPrev = props.yoyo && prevT % 2 === 1,
yoyoZero = isYoyo ? 1 : 0,
yoyoOne = 1 - yoyoZero;
if (time === this._props.endTime) {
this._wasUknownUpdate = false;
// if `time` is equal to `endTime`, T represents the next period,
// so we need to decrement T and calculate "one" value regarding yoyo
var isYoyo = props.yoyo && (T - 1) % 2 === 1;
this._setProgress(isYoyo ? 0 : 1, time, isYoyo);
if (time > this._prevTime) {
this._isRepeatCompleted = false;
}
this._repeatComplete(time, isYoyo);
return this._complete(time, isYoyo);
}
// reset callback flags
this._isCompleted = false;
// if time is inside the duration area of the tween
if (startPoint + elapsed >= props.startTime) {
this._isInActiveArea = true;this._isRepeatCompleted = false;
this._isRepeatStart = false;this._isStarted = false;
// active zone or larger then end
var elapsed2 = (time - props.startTime) % delayDuration,
proc = elapsed2 / props.duration;
// |=====|=====|=====| >>>
// ^1^2
var isOnEdge = T > 0 && prevT < T;
// |=====|=====|=====| <<<
// ^2^1
var isOnReverseEdge = prevT > T;
// for use in timeline
this._onEdge = 0;
isOnEdge && (this._onEdge = 1);
isOnReverseEdge && (this._onEdge = -1);
if (this._wasUknownUpdate) {
if (time > this._prevTime) {
this._start(time, isYoyo);
this._repeatStart(time, isYoyo);
this._firstUpdate(time, isYoyo);
}
if (time < this._prevTime) {
this._complete(time, isYoyo);
this._repeatComplete(time, isYoyo);
this._firstUpdate(time, isYoyo);
// reset isCompleted immediately
this._isCompleted = false;
}
}
if (isOnEdge) {
// if not just after delay
// |---=====|---=====|---=====| >>>
// ^1 ^2
// because we have already handled
// 1 and onRepeatComplete in delay gap
if (this.progress !== 1) {
// prevT
var isThisYoyo = props.yoyo && (T - 1) % 2 === 1;
this._repeatComplete(time, isThisYoyo);
}
// if on edge but not at very start
// |=====|=====|=====| >>>
// ^! ^here ^here
if (prevT >= 0) {
this._repeatStart(time, isYoyo);
}
}
if (time > this._prevTime) {
// |=====|=====|=====| >>>
// ^1 ^2
if (!this._isStarted && this._prevTime <= props.startTime) {
this._start(time, isYoyo);
this._repeatStart(time, isYoyo);
// it was zero anyways
// restart flags immediately in case if we will
// return to '-' inactive area on the next step
this._isStarted = false;
this._isRepeatStart = false;
}
this._firstUpdate(time, isYoyo);
}
if (isOnReverseEdge) {
// if on edge but not at very end
// |=====|=====|=====| <<<
// ^here ^here ^not here
if (this.progress !== 0 && this.progress !== 1 && prevT != TCount) {
this._repeatStart(time, isYoyoPrev);
}
// if on very end edge
// |=====|=====|=====| <<<
// ^! ^! ^2 ^1
// we have handled the case in this._wasUknownUpdate
// block so filter that
if (prevT === TCount && !this._wasUknownUpdate) {
this._complete(time, isYoyo);
this._repeatComplete(time, isYoyo);
this._firstUpdate(time, isYoyo);
// reset isComplete flag call
// cuz we returned to active area
// this._isRepeatCompleted = false;
this._isCompleted = false;
}
this._repeatComplete(time, isYoyo);
}
if (prevT === 'delay') {
// if just before delay gap
// |---=====|---=====|---=====| <<<
// ^2 ^1
if (T < TPrevValue) {
this._repeatComplete(time, isYoyo);
}
// if just after delay gap
// |---=====|---=====|---=====| >>>
// ^1 ^2
if (T === TPrevValue && T > 0) {
this._repeatStart(time, isYoyo);
}
}
// swap progress and repeatStart based on direction
if (time > this._prevTime) {
// if progress is equal 0 and progress grows
if (proc === 0) {
this._repeatStart(time, isYoyo);
}
if (time !== props.endTime) {
this._setProgress(isYoyo ? 1 - proc : proc, time, isYoyo);
}
} else {
if (time !== props.endTime) {
this._setProgress(isYoyo ? 1 - proc : proc, time, isYoyo);
}
// if progress is equal 0 and progress grows
if (proc === 0) {
this._repeatStart(time, isYoyo);
}
}
if (time === props.startTime) {
this._start(time, isYoyo);
}
// delay gap - react only once
} else if (this._isInActiveArea) {
// because T will be string of "delay" here,
// let's normalize it be setting to TValue
var t = T === 'delay' ? TValue : T,
isGrows = time > this._prevTime;
// decrement period if forward direction of update
isGrows && t--;
// calculate normalized yoyoZero value
yoyoZero = props.yoyo && t % 2 === 1 ? 1 : 0;
// if was in active area and previous time was larger
// |---=====|---=====|---=====| <<<
// ^2 ^1 ^2 ^1 ^2 ^1
if (time < this._prevTime) {
this._setProgress(yoyoZero, time, yoyoZero === 1);
this._repeatStart(time, yoyoZero === 1);
}
// set 1 or 0 regarding direction and yoyo
this._setProgress(isGrows ? 1 - yoyoZero : yoyoZero, time, yoyoZero === 1);
// if time grows
if (time > this._prevTime) {
// if reverse direction and in delay gap, then progress will be 0
// if so we don't need to call the onRepeatComplete callback
// |---=====|---=====|---=====| <<<
// ^0 ^0 ^0
// OR we have flipped 0 to 1 regarding yoyo option
if (this.progress !== 0 || yoyoZero === 1) {
// since we repeatComplete for previous period
// invert isYoyo option
// is elapsed is 0 - count as previous period
this._repeatComplete(time, yoyoZero === 1);
}
}
// set flag to indicate inactive area
this._isInActiveArea = false;
}
// we've got the first update now
this._wasUknownUpdate = false;
}
/*
Method to remove the Tween from the tweener.
@private
@returns {Object} Self.
*/
}, {
key: '_removeFromTweener',
value: function _removeFromTweener() {
_tweener2.default.remove(this);return this;
}
/*
Method to get current period number.
@private
@param {Number} Time to get the period for.
@returns {Number} Current period number.
*/
}, {
key: '_getPeriod',
value: function _getPeriod(time) {
var p = this._props,
TTime = p.delay + p.duration,
dTime = p.delay + time - p.startTime,
T = dTime / TTime,
// if time if equal to endTime we need to set the elapsed
// time to 0 to fix the occasional precision js bug, which
// causes 0 to be something like 1e-12
elapsed = time < p.endTime ? dTime % TTime : 0;
// If the latest period, round the result, otherwise floor it.
// Basically we always can floor the result, but because of js
// precision issues, sometimes the result is 2.99999998 which
// will result in 2 instead of 3 after the floor operation.
T = time >= p.endTime ? Math.round(T) : Math.floor(T);
// if time is larger then the end time
if (time > p.endTime) {
// set equal to the periods count
T = Math.round((p.endTime - p.startTime + p.delay) / TTime);
// if in delay gap, set _delayT to current
// period number and return "delay"
} else if (elapsed > 0 && elapsed < p.delay) {
this._delayT = T;T = 'delay';
}
// if the end of period and there is a delay
return T;
}
/*
Method to set Tween's progress and call onUpdate callback.
@private
@override @ Module
@param {Number} Progress to set.
@param {Number} Current update time.
@param {Boolean} Is yoyo perido. Used in Timeline to pass to Tween.
@returns {Object} Self.
*/
}, {
key: '_setProgress',
value: function _setProgress(proc, time, isYoyo) {
var p = this._props,
isYoyoChanged = p.wasYoyo !== isYoyo;
this.progress = proc;
this.easedProgress = p.easing(this.progress);
if (p.prevEasedProgress !== this.easedProgress || isYoyoChanged) {
if (p.onUpdate != null && typeof p.onUpdate === 'function') {
p.onUpdate.call(p.callbacksContext || this, this.easedProgress, this.progress, time > this._prevTime, isYoyo);
}
}
p.prevEasedProgress = this.easedProgress;
p.wasYoyo = isYoyo;
return this;
}
/*