-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
6428 lines (5351 loc) · 233 KB
/
script.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
// modules are defined as an array
// [ module function, map of requires ]
//
// map of requires is short require name -> numeric require
//
// anything defined in a previous bundle is accessed via the
// orig method which is the require for previous bundles
parcelRequire = (function (modules, cache, entry, globalName) {
// Save the require from previous bundle to this closure if any
var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
var nodeRequire = typeof require === 'function' && require;
function newRequire(name, jumped) {
if (!cache[name]) {
if (!modules[name]) {
// if we cannot find the module within our internal map or
// cache jump to the current global require ie. the last bundle
// that was added to the page.
var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
if (!jumped && currentRequire) {
return currentRequire(name, true);
}
// If there are other bundles on this page the require from the
// previous one is saved to 'previousRequire'. Repeat this as
// many times as there are bundles until the module is found or
// we exhaust the require chain.
if (previousRequire) {
return previousRequire(name, true);
}
// Try the node require function if it exists.
if (nodeRequire && typeof name === 'string') {
return nodeRequire(name);
}
var err = new Error('Cannot find module \'' + name + '\'');
err.code = 'MODULE_NOT_FOUND';
throw err;
}
localRequire.resolve = resolve;
localRequire.cache = {};
var module = cache[name] = new newRequire.Module(name);
modules[name][0].call(module.exports, localRequire, module, module.exports, this);
}
return cache[name].exports;
function localRequire(x){
return newRequire(localRequire.resolve(x));
}
function resolve(x){
return modules[name][1][x] || x;
}
}
function Module(moduleName) {
this.id = moduleName;
this.bundle = newRequire;
this.exports = {};
}
newRequire.isParcelRequire = true;
newRequire.Module = Module;
newRequire.modules = modules;
newRequire.cache = cache;
newRequire.parent = previousRequire;
newRequire.register = function (id, exports) {
modules[id] = [function (require, module) {
module.exports = exports;
}, {}];
};
var error;
for (var i = 0; i < entry.length; i++) {
try {
newRequire(entry[i]);
} catch (e) {
// Save first error but execute all entries
if (!error) {
error = e;
}
}
}
if (entry.length) {
// Expose entry point to Node, AMD or browser globals
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
var mainExports = newRequire(entry[entry.length - 1]);
// CommonJS
if (typeof exports === "object" && typeof module !== "undefined") {
module.exports = mainExports;
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(function () {
return mainExports;
});
// <script>
} else if (globalName) {
this[globalName] = mainExports;
}
}
// Override the current require with this new one
parcelRequire = newRequire;
if (error) {
// throw error from earlier, _after updating parcelRequire_
throw error;
}
return newRequire;
})({"TNS6":[function(require,module,exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports._getCache = exports._getSetter = exports._missingPlugin = exports._round = exports._roundModifier = exports._config = exports._ticker = exports._plugins = exports._checkPlugin = exports._replaceRandom = exports._colorStringFilter = exports._sortPropTweensByPriority = exports._forEachName = exports._removeLinkedListItem = exports._setDefaults = exports._relExp = exports._renderComplexString = exports._isUndefined = exports._isString = exports._numWithUnitExp = exports._numExp = exports._getProperty = exports.shuffle = exports.interpolate = exports.unitize = exports.pipe = exports.mapRange = exports.toArray = exports.splitColor = exports.clamp = exports.getUnit = exports.normalize = exports.snap = exports.random = exports.distribute = exports.wrapYoyo = exports.wrap = exports.Circ = exports.Expo = exports.Sine = exports.Bounce = exports.SteppedEase = exports.Back = exports.Elastic = exports.Strong = exports.Quint = exports.Quart = exports.Cubic = exports.Quad = exports.Linear = exports.Power4 = exports.Power3 = exports.Power2 = exports.Power1 = exports.Power0 = exports.default = exports.gsap = exports.PropTween = exports.TweenLite = exports.TweenMax = exports.Tween = exports.TimelineLite = exports.TimelineMax = exports.Timeline = exports.Animation = exports.GSCache = void 0;
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
/*!
* GSAP 3.3.1
* https://greensock.com
*
* @license Copyright 2008-2020, GreenSock. All rights reserved.
* Subject to the terms at https://greensock.com/standard-license or for
* Club GreenSock members, the agreement issued with that membership.
* @author: Jack Doyle, [email protected]
*/
/* eslint-disable */
var _config = {
autoSleep: 120,
force3D: "auto",
nullTargetWarn: 1,
units: {
lineHeight: ""
}
},
_defaults = {
duration: .5,
overwrite: false,
delay: 0
},
_bigNum = 1e8,
_tinyNum = 1 / _bigNum,
_2PI = Math.PI * 2,
_HALF_PI = _2PI / 4,
_gsID = 0,
_sqrt = Math.sqrt,
_cos = Math.cos,
_sin = Math.sin,
_isString = function _isString(value) {
return typeof value === "string";
},
_isFunction = function _isFunction(value) {
return typeof value === "function";
},
_isNumber = function _isNumber(value) {
return typeof value === "number";
},
_isUndefined = function _isUndefined(value) {
return typeof value === "undefined";
},
_isObject = function _isObject(value) {
return typeof value === "object";
},
_isNotFalse = function _isNotFalse(value) {
return value !== false;
},
_windowExists = function _windowExists() {
return typeof window !== "undefined";
},
_isFuncOrString = function _isFuncOrString(value) {
return _isFunction(value) || _isString(value);
},
_isArray = Array.isArray,
_strictNumExp = /(?:-?\.?\d|\.)+/gi,
//only numbers (including negatives and decimals) but NOT relative values.
_numExp = /[-+=.]*\d+[.e\-+]*\d*[e\-\+]*\d*/g,
//finds any numbers, including ones that start with += or -=, negative numbers, and ones in scientific notation like 1e-8.
_numWithUnitExp = /[-+=.]*\d+[.e-]*\d*[a-z%]*/g,
_complexStringNumExp = /[-+=.]*\d+(?:\.|e-|e)*\d*/gi,
//duplicate so that while we're looping through matches from exec(), it doesn't contaminate the lastIndex of _numExp which we use to search for colors too.
_parenthesesExp = /\(([^()]+)\)/i,
//finds the string between parentheses.
_relExp = /[+-]=-?[\.\d]+/,
_delimitedValueExp = /[#\-+.]*\b[a-z\d-=+%.]+/gi,
_globalTimeline,
_win,
_coreInitted,
_doc,
_globals = {},
_installScope = {},
_coreReady,
_install = function _install(scope) {
return (_installScope = _merge(scope, _globals)) && gsap;
},
_missingPlugin = function _missingPlugin(property, value) {
return console.warn("Invalid property", property, "set to", value, "Missing plugin? gsap.registerPlugin()");
},
_warn = function _warn(message, suppress) {
return !suppress && console.warn(message);
},
_addGlobal = function _addGlobal(name, obj) {
return name && (_globals[name] = obj) && _installScope && (_installScope[name] = obj) || _globals;
},
_emptyFunc = function _emptyFunc() {
return 0;
},
_reservedProps = {},
_lazyTweens = [],
_lazyLookup = {},
_lastRenderedFrame,
_plugins = {},
_effects = {},
_nextGCFrame = 30,
_harnessPlugins = [],
_callbackNames = "",
_harness = function _harness(targets) {
var target = targets[0],
harnessPlugin,
i;
if (!_isObject(target) && !_isFunction(target)) {
targets = [targets];
}
if (!(harnessPlugin = (target._gsap || {}).harness)) {
i = _harnessPlugins.length;
while (i-- && !_harnessPlugins[i].targetTest(target)) {}
harnessPlugin = _harnessPlugins[i];
}
i = targets.length;
while (i--) {
targets[i] && (targets[i]._gsap || (targets[i]._gsap = new GSCache(targets[i], harnessPlugin))) || targets.splice(i, 1);
}
return targets;
},
_getCache = function _getCache(target) {
return target._gsap || _harness(toArray(target))[0]._gsap;
},
_getProperty = function _getProperty(target, property) {
var currentValue = target[property];
return _isFunction(currentValue) ? target[property]() : _isUndefined(currentValue) && target.getAttribute(property) || currentValue;
},
_forEachName = function _forEachName(names, func) {
return (names = names.split(",")).forEach(func) || names;
},
//split a comma-delimited list of names into an array, then run a forEach() function and return the split array (this is just a way to consolidate/shorten some code).
_round = function _round(value) {
return Math.round(value * 100000) / 100000 || 0;
},
_arrayContainsAny = function _arrayContainsAny(toSearch, toFind) {
//searches one array to find matches for any of the items in the toFind array. As soon as one is found, it returns true. It does NOT return all the matches; it's simply a boolean search.
var l = toFind.length,
i = 0;
for (; toSearch.indexOf(toFind[i]) < 0 && ++i < l;) {}
return i < l;
},
_parseVars = function _parseVars(params, type, parent) {
//reads the arguments passed to one of the key methods and figures out if the user is defining things with the OLD/legacy syntax where the duration is the 2nd parameter, and then it adjusts things accordingly and spits back the corrected vars object (with the duration added if necessary, as well as runBackwards or startAt or immediateRender). type 0 = to()/staggerTo(), 1 = from()/staggerFrom(), 2 = fromTo()/staggerFromTo()
var isLegacy = _isNumber(params[1]),
varsIndex = (isLegacy ? 2 : 1) + (type < 2 ? 0 : 1),
vars = params[varsIndex],
irVars;
if (isLegacy) {
vars.duration = params[1];
}
vars.parent = parent;
if (type) {
irVars = vars;
while (parent && !("immediateRender" in irVars)) {
// inheritance hasn't happened yet, but someone may have set a default in an ancestor timeline. We could do vars.immediateRender = _isNotFalse(_inheritDefaults(vars).immediateRender) but that'd exact a slight performance penalty because _inheritDefaults() also runs in the Tween constructor. We're paying a small kb price here to gain speed.
irVars = parent.vars.defaults || {};
parent = _isNotFalse(parent.vars.inherit) && parent.parent;
}
vars.immediateRender = _isNotFalse(irVars.immediateRender);
if (type < 2) {
vars.runBackwards = 1;
} else {
vars.startAt = params[varsIndex - 1]; // "from" vars
}
}
return vars;
},
_lazyRender = function _lazyRender() {
var l = _lazyTweens.length,
a = _lazyTweens.slice(0),
i,
tween;
_lazyLookup = {};
_lazyTweens.length = 0;
for (i = 0; i < l; i++) {
tween = a[i];
tween && tween._lazy && (tween.render(tween._lazy[0], tween._lazy[1], true)._lazy = 0);
}
},
_lazySafeRender = function _lazySafeRender(animation, time, suppressEvents, force) {
_lazyTweens.length && _lazyRender();
animation.render(time, suppressEvents, force);
_lazyTweens.length && _lazyRender(); //in case rendering caused any tweens to lazy-init, we should render them because typically when someone calls seek() or time() or progress(), they expect an immediate render.
},
_numericIfPossible = function _numericIfPossible(value) {
var n = parseFloat(value);
return (n || n === 0) && (value + "").match(_delimitedValueExp).length < 2 ? n : value;
},
_passThrough = function _passThrough(p) {
return p;
},
_setDefaults = function _setDefaults(obj, defaults) {
for (var p in defaults) {
if (!(p in obj)) {
obj[p] = defaults[p];
}
}
return obj;
},
_setKeyframeDefaults = function _setKeyframeDefaults(obj, defaults) {
for (var p in defaults) {
if (!(p in obj) && p !== "duration" && p !== "ease") {
obj[p] = defaults[p];
}
}
},
_merge = function _merge(base, toMerge) {
for (var p in toMerge) {
base[p] = toMerge[p];
}
return base;
},
_mergeDeep = function _mergeDeep(base, toMerge) {
for (var p in toMerge) {
base[p] = _isObject(toMerge[p]) ? _mergeDeep(base[p] || (base[p] = {}), toMerge[p]) : toMerge[p];
}
return base;
},
_copyExcluding = function _copyExcluding(obj, excluding) {
var copy = {},
p;
for (p in obj) {
p in excluding || (copy[p] = obj[p]);
}
return copy;
},
_inheritDefaults = function _inheritDefaults(vars) {
var parent = vars.parent || _globalTimeline,
func = vars.keyframes ? _setKeyframeDefaults : _setDefaults;
if (_isNotFalse(vars.inherit)) {
while (parent) {
func(vars, parent.vars.defaults);
parent = parent.parent || parent._dp;
}
}
return vars;
},
_arraysMatch = function _arraysMatch(a1, a2) {
var i = a1.length,
match = i === a2.length;
while (match && i-- && a1[i] === a2[i]) {}
return i < 0;
},
_addLinkedListItem = function _addLinkedListItem(parent, child, firstProp, lastProp, sortBy) {
if (firstProp === void 0) {
firstProp = "_first";
}
if (lastProp === void 0) {
lastProp = "_last";
}
var prev = parent[lastProp],
t;
if (sortBy) {
t = child[sortBy];
while (prev && prev[sortBy] > t) {
prev = prev._prev;
}
}
if (prev) {
child._next = prev._next;
prev._next = child;
} else {
child._next = parent[firstProp];
parent[firstProp] = child;
}
if (child._next) {
child._next._prev = child;
} else {
parent[lastProp] = child;
}
child._prev = prev;
child.parent = child._dp = parent;
return child;
},
_removeLinkedListItem = function _removeLinkedListItem(parent, child, firstProp, lastProp) {
if (firstProp === void 0) {
firstProp = "_first";
}
if (lastProp === void 0) {
lastProp = "_last";
}
var prev = child._prev,
next = child._next;
if (prev) {
prev._next = next;
} else if (parent[firstProp] === child) {
parent[firstProp] = next;
}
if (next) {
next._prev = prev;
} else if (parent[lastProp] === child) {
parent[lastProp] = prev;
}
child._next = child._prev = child.parent = null; // don't delete the _dp just so we can revert if necessary. But parent should be null to indicate the item isn't in a linked list.
},
_removeFromParent = function _removeFromParent(child, onlyIfParentHasAutoRemove) {
if (child.parent && (!onlyIfParentHasAutoRemove || child.parent.autoRemoveChildren)) {
child.parent.remove(child);
}
child._act = 0;
},
_uncache = function _uncache(animation) {
var a = animation;
while (a) {
a._dirty = 1;
a = a.parent;
}
return animation;
},
_recacheAncestors = function _recacheAncestors(animation) {
var parent = animation.parent;
while (parent && parent.parent) {
//sometimes we must force a re-sort of all children and update the duration/totalDuration of all ancestor timelines immediately in case, for example, in the middle of a render loop, one tween alters another tween's timeScale which shoves its startTime before 0, forcing the parent timeline to shift around and shiftChildren() which could affect that next tween's render (startTime). Doesn't matter for the root timeline though.
parent._dirty = 1;
parent.totalDuration();
parent = parent.parent;
}
return animation;
},
_hasNoPausedAncestors = function _hasNoPausedAncestors(animation) {
return !animation || animation._ts && _hasNoPausedAncestors(animation.parent);
},
_elapsedCycleDuration = function _elapsedCycleDuration(animation) {
return animation._repeat ? _animationCycle(animation._tTime, animation = animation.duration() + animation._rDelay) * animation : 0;
},
// feed in the totalTime and cycleDuration and it'll return the cycle (iteration minus 1) and if the playhead is exactly at the very END, it will NOT bump up to the next cycle.
_animationCycle = function _animationCycle(tTime, cycleDuration) {
return (tTime /= cycleDuration) && ~~tTime === tTime ? ~~tTime - 1 : ~~tTime;
},
_parentToChildTotalTime = function _parentToChildTotalTime(parentTime, child) {
return (parentTime - child._start) * child._ts + (child._ts >= 0 ? 0 : child._dirty ? child.totalDuration() : child._tDur);
},
_setEnd = function _setEnd(animation) {
return animation._end = _round(animation._start + (animation._tDur / Math.abs(animation._ts || animation._rts || _tinyNum) || 0));
},
/*
_totalTimeToTime = (clampedTotalTime, duration, repeat, repeatDelay, yoyo) => {
let cycleDuration = duration + repeatDelay,
time = _round(clampedTotalTime % cycleDuration);
if (time > duration) {
time = duration;
}
return (yoyo && (~~(clampedTotalTime / cycleDuration) & 1)) ? duration - time : time;
},
*/
_postAddChecks = function _postAddChecks(timeline, child) {
var t;
if (child._time || child._initted && !child._dur) {
//in case, for example, the _start is moved on a tween that has already rendered. Imagine it's at its end state, then the startTime is moved WAY later (after the end of this timeline), it should render at its beginning.
t = _parentToChildTotalTime(timeline.rawTime(), child);
if (!child._dur || _clamp(0, child.totalDuration(), t) - child._tTime > _tinyNum) {
child.render(t, true);
}
} //if the timeline has already ended but the inserted tween/timeline extends the duration, we should enable this timeline again so that it renders properly. We should also align the playhead with the parent timeline's when appropriate.
if (_uncache(timeline)._dp && timeline._initted && timeline._time >= timeline._dur && timeline._ts) {
//in case any of the ancestors had completed but should now be enabled...
if (timeline._dur < timeline.duration()) {
t = timeline;
while (t._dp) {
t.rawTime() >= 0 && t.totalTime(t._tTime); //moves the timeline (shifts its startTime) if necessary, and also enables it. If it's currently zero, though, it may not be scheduled to render until later so there's no need to force it to align with the current playhead position. Only move to catch up with the playhead.
t = t._dp;
}
}
timeline._zTime = -_tinyNum; // helps ensure that the next render() will be forced (crossingStart = true in render()), even if the duration hasn't changed (we're adding a child which would need to get rendered). Definitely an edge case. Note: we MUST do this AFTER the loop above where the totalTime() might trigger a render() because this _addToTimeline() method gets called from the Animation constructor, BEFORE tweens even record their targets, etc. so we wouldn't want things to get triggered in the wrong order.
}
},
_addToTimeline = function _addToTimeline(timeline, child, position, skipChecks) {
child.parent && _removeFromParent(child);
child._start = _round(position + child._delay);
child._end = _round(child._start + (child.totalDuration() / Math.abs(child.timeScale()) || 0));
_addLinkedListItem(timeline, child, "_first", "_last", timeline._sort ? "_start" : 0);
timeline._recent = child;
skipChecks || _postAddChecks(timeline, child);
return timeline;
},
_scrollTrigger = function _scrollTrigger(animation, trigger) {
return (_globals.ScrollTrigger || _missingPlugin("scrollTrigger", trigger)) && _globals.ScrollTrigger.create(trigger, animation);
},
_attemptInitTween = function _attemptInitTween(tween, totalTime, force, suppressEvents) {
_initTween(tween, totalTime);
if (!tween._initted) {
return 1;
}
if (!force && tween._pt && (tween._dur && tween.vars.lazy !== false || !tween._dur && tween.vars.lazy) && _lastRenderedFrame !== _ticker.frame) {
_lazyTweens.push(tween);
tween._lazy = [totalTime, suppressEvents];
return 1;
}
},
_renderZeroDurationTween = function _renderZeroDurationTween(tween, totalTime, suppressEvents, force) {
var prevRatio = tween.ratio,
ratio = totalTime < 0 || prevRatio && !totalTime && !tween._start && !tween._dp._lock ? 0 : 1,
// check parent's _lock because when a timeline repeats/yoyos and does its artificial wrapping, we shouldn't force the ratio back to 0.
repeatDelay = tween._rDelay,
tTime = 0,
pt,
iteration,
prevIteration;
if (repeatDelay && tween._repeat) {
// in case there's a zero-duration tween that has a repeat with a repeatDelay
tTime = _clamp(0, tween._tDur, totalTime);
iteration = _animationCycle(tTime, repeatDelay);
prevIteration = _animationCycle(tween._tTime, repeatDelay);
if (iteration !== prevIteration) {
prevRatio = 1 - ratio;
tween.vars.repeatRefresh && tween._initted && tween.invalidate();
}
}
if (!tween._initted && _attemptInitTween(tween, totalTime, force, suppressEvents)) {
// if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately.
return;
}
if (ratio !== prevRatio || force || tween._zTime === _tinyNum || !totalTime && tween._zTime) {
prevIteration = tween._zTime;
tween._zTime = totalTime || (suppressEvents ? _tinyNum : 0); // when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect.
suppressEvents || (suppressEvents = totalTime && !prevIteration); // if it was rendered previously at exactly 0 (_zTime) and now the playhead is moving away, DON'T fire callbacks otherwise they'll seem like duplicates.
tween.ratio = ratio;
tween._from && (ratio = 1 - ratio);
tween._time = 0;
tween._tTime = tTime;
suppressEvents || _callback(tween, "onStart");
pt = tween._pt;
while (pt) {
pt.r(ratio, pt.d);
pt = pt._next;
}
if (!ratio && tween._startAt && !tween._onUpdate && tween._start) {
//if the tween is positioned at the VERY beginning (_start 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values.
tween._startAt.render(totalTime, true, force);
}
tween._onUpdate && !suppressEvents && _callback(tween, "onUpdate");
tTime && tween._repeat && !suppressEvents && tween.parent && _callback(tween, "onRepeat");
if ((totalTime >= tween._tDur || totalTime < 0) && tween.ratio === ratio) {
ratio && _removeFromParent(tween, 1);
if (!suppressEvents) {
_callback(tween, ratio ? "onComplete" : "onReverseComplete", true);
tween._prom && tween._prom();
}
}
} else if (!tween._zTime) {
tween._zTime = totalTime;
}
},
_findNextPauseTween = function _findNextPauseTween(animation, prevTime, time) {
var child;
if (time > prevTime) {
child = animation._first;
while (child && child._start <= time) {
if (!child._dur && child.data === "isPause" && child._start > prevTime) {
return child;
}
child = child._next;
}
} else {
child = animation._last;
while (child && child._start >= time) {
if (!child._dur && child.data === "isPause" && child._start < prevTime) {
return child;
}
child = child._prev;
}
}
},
_setDuration = function _setDuration(animation, duration, skipUncache) {
var repeat = animation._repeat,
dur = _round(duration) || 0;
animation._dur = dur;
animation._tDur = !repeat ? dur : repeat < 0 ? 1e10 : _round(dur * (repeat + 1) + animation._rDelay * repeat);
if (animation._time > dur) {
animation._time = dur;
animation._tTime = Math.min(animation._tTime, animation._tDur);
}
!skipUncache && _uncache(animation.parent);
animation.parent && _setEnd(animation);
return animation;
},
_onUpdateTotalDuration = function _onUpdateTotalDuration(animation) {
return animation instanceof Timeline ? _uncache(animation) : _setDuration(animation, animation._dur);
},
_zeroPosition = {
_start: 0,
endTime: _emptyFunc
},
_parsePosition = function _parsePosition(animation, position) {
var labels = animation.labels,
recent = animation._recent || _zeroPosition,
clippedDuration = animation.duration() >= _bigNum ? recent.endTime(false) : animation._dur,
//in case there's a child that infinitely repeats, users almost never intend for the insertion point of a new child to be based on a SUPER long value like that so we clip it and assume the most recently-added child's endTime should be used instead.
i,
offset;
if (_isString(position) && (isNaN(position) || position in labels)) {
//if the string is a number like "1", check to see if there's a label with that name, otherwise interpret it as a number (absolute value).
i = position.charAt(0);
if (i === "<" || i === ">") {
return (i === "<" ? recent._start : recent.endTime(recent._repeat >= 0)) + (parseFloat(position.substr(1)) || 0);
}
i = position.indexOf("=");
if (i < 0) {
position in labels || (labels[position] = clippedDuration);
return labels[position];
}
offset = +(position.charAt(i - 1) + position.substr(i + 1));
return i > 1 ? _parsePosition(animation, position.substr(0, i - 1)) + offset : clippedDuration + offset;
}
return position == null ? clippedDuration : +position;
},
_conditionalReturn = function _conditionalReturn(value, func) {
return value || value === 0 ? func(value) : func;
},
_clamp = function _clamp(min, max, value) {
return value < min ? min : value > max ? max : value;
},
getUnit = function getUnit(value) {
return (value + "").substr((parseFloat(value) + "").length);
},
clamp = function clamp(min, max, value) {
return _conditionalReturn(value, function (v) {
return _clamp(min, max, v);
});
},
_slice = [].slice,
_isArrayLike = function _isArrayLike(value, nonEmpty) {
return value && _isObject(value) && "length" in value && (!nonEmpty && !value.length || value.length - 1 in value && _isObject(value[0])) && !value.nodeType && value !== _win;
},
_flatten = function _flatten(ar, leaveStrings, accumulator) {
if (accumulator === void 0) {
accumulator = [];
}
return ar.forEach(function (value) {
var _accumulator;
return _isString(value) && !leaveStrings || _isArrayLike(value, 1) ? (_accumulator = accumulator).push.apply(_accumulator, toArray(value)) : accumulator.push(value);
}) || accumulator;
},
//takes any value and returns an array. If it's a string (and leaveStrings isn't true), it'll use document.querySelectorAll() and convert that to an array. It'll also accept iterables like jQuery objects.
toArray = function toArray(value, leaveStrings) {
return _isString(value) && !leaveStrings && (_coreInitted || !_wake()) ? _slice.call(_doc.querySelectorAll(value), 0) : _isArray(value) ? _flatten(value, leaveStrings) : _isArrayLike(value) ? _slice.call(value, 0) : value ? [value] : [];
},
shuffle = function shuffle(a) {
return a.sort(function () {
return .5 - Math.random();
});
},
// alternative that's a bit faster and more reliably diverse but bigger: for (let j, v, i = a.length; i; j = Math.floor(Math.random() * i), v = a[--i], a[i] = a[j], a[j] = v); return a;
//for distributing values across an array. Can accept a number, a function or (most commonly) a function which can contain the following properties: {base, amount, from, ease, grid, axis, length, each}. Returns a function that expects the following parameters: index, target, array. Recognizes the following
distribute = function distribute(v) {
if (_isFunction(v)) {
return v;
}
var vars = _isObject(v) ? v : {
each: v
},
//n:1 is just to indicate v was a number; we leverage that later to set v according to the length we get. If a number is passed in, we treat it like the old stagger value where 0.1, for example, would mean that things would be distributed with 0.1 between each element in the array rather than a total "amount" that's chunked out among them all.
ease = _parseEase(vars.ease),
from = vars.from || 0,
base = parseFloat(vars.base) || 0,
cache = {},
isDecimal = from > 0 && from < 1,
ratios = isNaN(from) || isDecimal,
axis = vars.axis,
ratioX = from,
ratioY = from;
if (_isString(from)) {
ratioX = ratioY = {
center: .5,
edges: .5,
end: 1
}[from] || 0;
} else if (!isDecimal && ratios) {
ratioX = from[0];
ratioY = from[1];
}
return function (i, target, a) {
var l = (a || vars).length,
distances = cache[l],
originX,
originY,
x,
y,
d,
j,
max,
min,
wrapAt;
if (!distances) {
wrapAt = vars.grid === "auto" ? 0 : (vars.grid || [1, _bigNum])[1];
if (!wrapAt) {
max = -_bigNum;
while (max < (max = a[wrapAt++].getBoundingClientRect().left) && wrapAt < l) {}
wrapAt--;
}
distances = cache[l] = [];
originX = ratios ? Math.min(wrapAt, l) * ratioX - .5 : from % wrapAt;
originY = ratios ? l * ratioY / wrapAt - .5 : from / wrapAt | 0;
max = 0;
min = _bigNum;
for (j = 0; j < l; j++) {
x = j % wrapAt - originX;
y = originY - (j / wrapAt | 0);
distances[j] = d = !axis ? _sqrt(x * x + y * y) : Math.abs(axis === "y" ? y : x);
d > max && (max = d);
d < min && (min = d);
}
from === "random" && shuffle(distances);
distances.max = max - min;
distances.min = min;
distances.v = l = (parseFloat(vars.amount) || parseFloat(vars.each) * (wrapAt > l ? l - 1 : !axis ? Math.max(wrapAt, l / wrapAt) : axis === "y" ? l / wrapAt : wrapAt) || 0) * (from === "edges" ? -1 : 1);
distances.b = l < 0 ? base - l : base;
distances.u = getUnit(vars.amount || vars.each) || 0; //unit
ease = ease && l < 0 ? _invertEase(ease) : ease;
}
l = (distances[i] - distances.min) / distances.max || 0;
return _round(distances.b + (ease ? ease(l) : l) * distances.v) + distances.u; //round in order to work around floating point errors
};
},
_roundModifier = function _roundModifier(v) {
//pass in 0.1 get a function that'll round to the nearest tenth, or 5 to round to the closest 5, or 0.001 to the closest 1000th, etc.
var p = v < 1 ? Math.pow(10, (v + "").length - 2) : 1; //to avoid floating point math errors (like 24 * 0.1 == 2.4000000000000004), we chop off at a specific number of decimal places (much faster than toFixed()
return function (raw) {
return Math.floor(Math.round(parseFloat(raw) / v) * v * p) / p + (_isNumber(raw) ? 0 : getUnit(raw));
};
},
snap = function snap(snapTo, value) {
var isArray = _isArray(snapTo),
radius,
is2D;
if (!isArray && _isObject(snapTo)) {
radius = isArray = snapTo.radius || _bigNum;
if (snapTo.values) {
snapTo = toArray(snapTo.values);
if (is2D = !_isNumber(snapTo[0])) {
radius *= radius; //performance optimization so we don't have to Math.sqrt() in the loop.
}
} else {
snapTo = _roundModifier(snapTo.increment);
}
}
return _conditionalReturn(value, !isArray ? _roundModifier(snapTo) : _isFunction(snapTo) ? function (raw) {
is2D = snapTo(raw);
return Math.abs(is2D - raw) <= radius ? is2D : raw;
} : function (raw) {
var x = parseFloat(is2D ? raw.x : raw),
y = parseFloat(is2D ? raw.y : 0),
min = _bigNum,
closest = 0,
i = snapTo.length,
dx,
dy;
while (i--) {
if (is2D) {
dx = snapTo[i].x - x;
dy = snapTo[i].y - y;
dx = dx * dx + dy * dy;
} else {
dx = Math.abs(snapTo[i] - x);
}
if (dx < min) {
min = dx;
closest = i;
}
}
closest = !radius || min <= radius ? snapTo[closest] : raw;
return is2D || closest === raw || _isNumber(raw) ? closest : closest + getUnit(raw);
});
},
random = function random(min, max, roundingIncrement, returnFunction) {
return _conditionalReturn(_isArray(min) ? !max : roundingIncrement === true ? !!(roundingIncrement = 0) : !returnFunction, function () {
return _isArray(min) ? min[~~(Math.random() * min.length)] : (roundingIncrement = roundingIncrement || 1e-5) && (returnFunction = roundingIncrement < 1 ? Math.pow(10, (roundingIncrement + "").length - 2) : 1) && Math.floor(Math.round((min + Math.random() * (max - min)) / roundingIncrement) * roundingIncrement * returnFunction) / returnFunction;
});
},
pipe = function pipe() {
for (var _len = arguments.length, functions = new Array(_len), _key = 0; _key < _len; _key++) {
functions[_key] = arguments[_key];
}
return function (value) {
return functions.reduce(function (v, f) {
return f(v);
}, value);
};
},
unitize = function unitize(func, unit) {
return function (value) {
return func(parseFloat(value)) + (unit || getUnit(value));
};
},
normalize = function normalize(min, max, value) {
return mapRange(min, max, 0, 1, value);
},
_wrapArray = function _wrapArray(a, wrapper, value) {
return _conditionalReturn(value, function (index) {
return a[~~wrapper(index)];
});
},
wrap = function wrap(min, max, value) {
// NOTE: wrap() CANNOT be an arrow function! A very odd compiling bug causes problems (unrelated to GSAP).
var range = max - min;
return _isArray(min) ? _wrapArray(min, wrap(0, min.length), max) : _conditionalReturn(value, function (value) {
return (range + (value - min) % range) % range + min;
});
},
wrapYoyo = function wrapYoyo(min, max, value) {
var range = max - min,
total = range * 2;
return _isArray(min) ? _wrapArray(min, wrapYoyo(0, min.length - 1), max) : _conditionalReturn(value, function (value) {
value = (total + (value - min) % total) % total;
return min + (value > range ? total - value : value);
});
},
_replaceRandom = function _replaceRandom(value) {
//replaces all occurrences of random(...) in a string with the calculated random value. can be a range like random(-100, 100, 5) or an array like random([0, 100, 500])
var prev = 0,
s = "",
i,
nums,
end,
isArray;
while (~(i = value.indexOf("random(", prev))) {
end = value.indexOf(")", i);
isArray = value.charAt(i + 7) === "[";
nums = value.substr(i + 7, end - i - 7).match(isArray ? _delimitedValueExp : _strictNumExp);
s += value.substr(prev, i - prev) + random(isArray ? nums : +nums[0], +nums[1], +nums[2] || 1e-5);
prev = end + 1;
}
return s + value.substr(prev, value.length - prev);
},
mapRange = function mapRange(inMin, inMax, outMin, outMax, value) {
var inRange = inMax - inMin,
outRange = outMax - outMin;
return _conditionalReturn(value, function (value) {
return outMin + ((value - inMin) / inRange * outRange || 0);
});
},
interpolate = function interpolate(start, end, progress, mutate) {
var func = isNaN(start + end) ? 0 : function (p) {
return (1 - p) * start + p * end;
};
if (!func) {
var isString = _isString(start),
master = {},
p,
i,
interpolators,
l,
il;
progress === true && (mutate = 1) && (progress = null);
if (isString) {
start = {
p: start
};
end = {
p: end
};