forked from julianshapiro/velocity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
velocity.es5.js
4848 lines (4710 loc) · 179 KB
/
velocity.es5.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
/**
* velocity-animate (C) 2014-2017 Julian Shapiro.
*
* Licensed under the MIT license. See LICENSE file in the project root for details.
*/
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
/**
* Check if a variable is a boolean.
*/
function isBoolean(variable) {
return variable === true || variable === false;
}
/**
* Check if a variable is a function.
*/
function isFunction(variable) {
return Object.prototype.toString.call(variable) === "[object Function]";
}
/**
* Check if a variable is an HTMLElement or SVGElement.
*/
function isNode(variable) {
return !!(variable && variable.nodeType);
}
/**
* Check if a variable is a number.
*/
function isNumber(variable) {
return typeof variable === "number";
}
/**
* Check if a variable is a plain object (and not an instance).
*/
function isPlainObject(variable) {
if (!variable || (typeof variable === "undefined" ? "undefined" : _typeof(variable)) !== "object" || variable.nodeType || Object.prototype.toString.call(variable) !== "[object Object]") {
return false;
}
var proto = Object.getPrototypeOf(variable);
return !proto || proto.hasOwnProperty("constructor") && proto.constructor === Object;
}
/**
* Check if a variable is a string.
*/
function isString(variable) {
return typeof variable === "string";
}
/**
* Check if a variable is the result of calling Velocity.
*/
function isVelocityResult(variable) {
return variable && isNumber(variable.length) && isFunction(variable.velocity);
}
/**
* Check if a variable is an array-like wrapped jQuery, Zepto or similar, where
* each indexed value is a Node.
*/
function isWrapped(variable) {
return variable && variable !== window && isNumber(variable.length) && !isString(variable) && !isFunction(variable) && !isNode(variable) && (variable.length === 0 || isNode(variable[0]));
}
/**
* Check is a property is an enumerable member of an object.
*/
function propertyIsEnumerable(obj, property) {
return Object.prototype.propertyIsEnumerable.call(obj, property);
}
// Project
/**
* Add a single className to an Element.
*/
function addClass(element, className) {
if (element instanceof Element) {
if (element.classList) {
element.classList.add(className);
} else {
removeClass(element, className);
element.className += (element.className.length ? " " : "") + className;
}
}
}
/**
* Clone an array, works for array-like too.
*/
function cloneArray(arrayLike) {
return Array.prototype.slice.call(arrayLike, 0);
}
/**
* The <strong><code>defineProperty()</code></strong> function provides a
* shortcut to defining a property that cannot be accidentally iterated across.
*/
function defineProperty$1(proto, name, value, readonly) {
if (proto) {
Object.defineProperty(proto, name, {
configurable: !readonly,
writable: !readonly,
value: value
});
}
}
/**
* When there are multiple locations for a value pass them all in, then get the
* first value that is valid.
*/
function getValue() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = args[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var arg = _step.value;
if (arg !== undefined && arg === arg) {
return arg;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
/**
* Shim to get the current milliseconds - on anything except old IE it'll use
* Date.now() and save creating an object. If that doesn't exist then it'll
* create one that gets GC.
*/
var now = Date.now ? Date.now : function () {
return new Date().getTime();
};
/**
* Remove a single className from an Element.
*/
function removeClass(element, className) {
if (element instanceof Element) {
if (element.classList) {
element.classList.remove(className);
} else {
// TODO: Need some jsperf tests on performance - can we get rid of the regex and maybe use split / array manipulation?
element.className = element.className.replace(new RegExp("(^|\\s)" + className + "(\\s|$)", "gi"), " ");
}
}
}
// Project
// Constants
var Actions = {};
/**
* Used to register an action. This should never be called by users
* directly, instead it should be called via an action:<br/>
* <code>Velocity("registerAction", "name", VelocityActionFn);</code>
*/
function registerAction(args, internal) {
var name = args[0],
callback = args[1];
if (!isString(name)) {
console.warn("VelocityJS: Trying to set 'registerAction' name to an invalid value:", name);
} else if (!isFunction(callback)) {
console.warn("VelocityJS: Trying to set 'registerAction' callback to an invalid value:", name, callback);
} else if (Actions[name] && !propertyIsEnumerable(Actions, name)) {
console.warn("VelocityJS: Trying to override internal 'registerAction' callback", name);
} else if (internal === true) {
defineProperty$1(Actions, name, callback);
} else {
Actions[name] = callback;
}
}
registerAction(["registerAction", registerAction], true);
/**
* Without this it will only un-prefix properties that have a valid "normal"
* version.
*/
var DURATION_FAST = 200;
var DURATION_NORMAL = 400;
var DURATION_SLOW = 600;
var FUZZY_MS_PER_SECOND = 980;
var DEFAULT_CACHE = true;
var DEFAULT_DELAY = 0;
var DEFAULT_DURATION = DURATION_NORMAL;
var DEFAULT_EASING = "swing";
var DEFAULT_FPSLIMIT = 60;
var DEFAULT_LOOP = 0;
var DEFAULT_PROMISE = true;
var DEFAULT_PROMISE_REJECT_EMPTY = true;
var DEFAULT_QUEUE = "";
var DEFAULT_REPEAT = 0;
var DEFAULT_SPEED = 1;
var DEFAULT_SYNC = true;
var CLASSNAME = "velocity-animating";
var Duration = {
fast: DURATION_FAST,
normal: DURATION_NORMAL,
slow: DURATION_SLOW
};
// Project
// Constants
var Easings = {};
/**
* Used to register a easing. This should never be called by users
* directly, instead it should be called via an action:<br/>
* <code>Velocity("registerEasing", "name", VelocityEasingFn);</code>
*/
function registerEasing(args) {
var name = args[0],
callback = args[1];
if (!isString(name)) {
console.warn("VelocityJS: Trying to set 'registerEasing' name to an invalid value:", name);
} else if (!isFunction(callback)) {
console.warn("VelocityJS: Trying to set 'registerEasing' callback to an invalid value:", name, callback);
} else if (Easings[name]) {
console.warn("VelocityJS: Trying to override 'registerEasing' callback", name);
} else {
Easings[name] = callback;
}
}
registerAction(["registerEasing", registerEasing], true);
/**
* Linear easing, used for sequence parts that don't have an actual easing
* function.
*/
function linearEasing(percentComplete, startValue, endValue, property) {
return startValue + percentComplete * (endValue - startValue);
}
/**
* Swing is the default for jQuery and Velocity.
*/
function swingEasing(percentComplete, startValue, endValue) {
return startValue + (0.5 - Math.cos(percentComplete * Math.PI) / 2) * (endValue - startValue);
}
/**
* A less exaggerated version of easeInOutElastic.
*/
function springEasing(percentComplete, startValue, endValue) {
return startValue + (1 - Math.cos(percentComplete * 4.5 * Math.PI) * Math.exp(-percentComplete * 6)) * (endValue - startValue);
}
registerEasing(["linear", linearEasing]);
registerEasing(["swing", swingEasing]);
registerEasing(["spring", springEasing]);
// Project
/**
* Fix to a range of <code>0 <= num <= 1</code>.
*/
function fixRange(num) {
return Math.min(Math.max(num, 0), 1);
}
function A(aA1, aA2) {
return 1 - 3 * aA2 + 3 * aA1;
}
function B(aA1, aA2) {
return 3 * aA2 - 6 * aA1;
}
function C(aA1) {
return 3 * aA1;
}
function calcBezier(aT, aA1, aA2) {
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
}
function getSlope(aT, aA1, aA2) {
return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
}
function generateBezier() {
var NEWTON_ITERATIONS = 4,
NEWTON_MIN_SLOPE = 0.001,
SUBDIVISION_PRECISION = 0.0000001,
SUBDIVISION_MAX_ITERATIONS = 10,
kSplineTableSize = 11,
kSampleStepSize = 1 / (kSplineTableSize - 1),
float32ArraySupported = "Float32Array" in window;
/* Must contain four args. */
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args.length !== 4) {
return;
}
/* Args must be numbers. */
for (var i = 0; i < 4; ++i) {
if (typeof args[i] !== "number" || isNaN(args[i]) || !isFinite(args[i])) {
return;
}
}
/* X values must be in the [0, 1] range. */
var mX1 = fixRange(args[0]);
var mY1 = args[1];
var mX2 = fixRange(args[2]);
var mY2 = args[3];
var mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
function newtonRaphsonIterate(aX, aGuessT) {
for (var _i = 0; _i < NEWTON_ITERATIONS; ++_i) {
var currentSlope = getSlope(aGuessT, mX1, mX2);
if (currentSlope === 0) {
return aGuessT;
}
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
aGuessT -= currentX / currentSlope;
}
return aGuessT;
}
function calcSampleValues() {
for (var _i2 = 0; _i2 < kSplineTableSize; ++_i2) {
mSampleValues[_i2] = calcBezier(_i2 * kSampleStepSize, mX1, mX2);
}
}
function binarySubdivide(aX, aA, aB) {
var currentX = void 0,
currentT = void 0,
i = 0;
do {
currentT = aA + (aB - aA) / 2;
currentX = calcBezier(currentT, mX1, mX2) - aX;
if (currentX > 0) {
aB = currentT;
} else {
aA = currentT;
}
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
return currentT;
}
function getTForX(aX) {
var lastSample = kSplineTableSize - 1;
var intervalStart = 0,
currentSample = 1;
for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
intervalStart += kSampleStepSize;
}
--currentSample;
var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]),
guessForT = intervalStart + dist * kSampleStepSize,
initialSlope = getSlope(guessForT, mX1, mX2);
if (initialSlope >= NEWTON_MIN_SLOPE) {
return newtonRaphsonIterate(aX, guessForT);
} else if (initialSlope === 0) {
return guessForT;
} else {
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize);
}
}
var precomputed = false;
function precompute() {
precomputed = true;
if (mX1 !== mY1 || mX2 !== mY2) {
calcSampleValues();
}
}
var str = "generateBezier(" + [mX1, mY1, mX2, mY2] + ")",
f = function f(percentComplete, startValue, endValue, property) {
if (!precomputed) {
precompute();
}
if (percentComplete === 0) {
return startValue;
}
if (percentComplete === 1) {
return endValue;
}
if (mX1 === mY1 && mX2 === mY2) {
return startValue + percentComplete * (endValue - startValue);
}
return startValue + calcBezier(getTForX(percentComplete), mY1, mY2) * (endValue - startValue);
};
f.getControlPoints = function () {
return [{ x: mX1, y: mY1 }, { x: mX2, y: mY2 }];
};
f.toString = function () {
return str;
};
return f;
}
/* Common easings */
var easeIn = generateBezier(0.42, 0, 1, 1),
easeOut = generateBezier(0, 0, 0.58, 1),
easeInOut = generateBezier(0.42, 0, 0.58, 1);
registerEasing(["ease", generateBezier(0.25, 0.1, 0.25, 1)]);
registerEasing(["easeIn", easeIn]);
registerEasing(["ease-in", easeIn]);
registerEasing(["easeOut", easeOut]);
registerEasing(["ease-out", easeOut]);
registerEasing(["easeInOut", easeInOut]);
registerEasing(["ease-in-out", easeInOut]);
registerEasing(["easeInSine", generateBezier(0.47, 0, 0.745, 0.715)]);
registerEasing(["easeOutSine", generateBezier(0.39, 0.575, 0.565, 1)]);
registerEasing(["easeInOutSine", generateBezier(0.445, 0.05, 0.55, 0.95)]);
registerEasing(["easeInQuad", generateBezier(0.55, 0.085, 0.68, 0.53)]);
registerEasing(["easeOutQuad", generateBezier(0.25, 0.46, 0.45, 0.94)]);
registerEasing(["easeInOutQuad", generateBezier(0.455, 0.03, 0.515, 0.955)]);
registerEasing(["easeInCubic", generateBezier(0.55, 0.055, 0.675, 0.19)]);
registerEasing(["easeOutCubic", generateBezier(0.215, 0.61, 0.355, 1)]);
registerEasing(["easeInOutCubic", generateBezier(0.645, 0.045, 0.355, 1)]);
registerEasing(["easeInQuart", generateBezier(0.895, 0.03, 0.685, 0.22)]);
registerEasing(["easeOutQuart", generateBezier(0.165, 0.84, 0.44, 1)]);
registerEasing(["easeInOutQuart", generateBezier(0.77, 0, 0.175, 1)]);
registerEasing(["easeInQuint", generateBezier(0.755, 0.05, 0.855, 0.06)]);
registerEasing(["easeOutQuint", generateBezier(0.23, 1, 0.32, 1)]);
registerEasing(["easeInOutQuint", generateBezier(0.86, 0, 0.07, 1)]);
registerEasing(["easeInExpo", generateBezier(0.95, 0.05, 0.795, 0.035)]);
registerEasing(["easeOutExpo", generateBezier(0.19, 1, 0.22, 1)]);
registerEasing(["easeInOutExpo", generateBezier(1, 0, 0, 1)]);
registerEasing(["easeInCirc", generateBezier(0.6, 0.04, 0.98, 0.335)]);
registerEasing(["easeOutCirc", generateBezier(0.075, 0.82, 0.165, 1)]);
registerEasing(["easeInOutCirc", generateBezier(0.785, 0.135, 0.15, 0.86)]);
/* Runge-Kutta spring physics function generator. Adapted from Framer.js, copyright Koen Bok. MIT License: http://en.wikipedia.org/wiki/MIT_License */
/* Given a tension, friction, and duration, a simulation at 60FPS will first run without a defined duration in order to calculate the full path. A second pass
then adjusts the time delta -- using the relation between actual time and duration -- to calculate the path for the duration-constrained animation. */
function springAccelerationForState(state) {
return -state.tension * state.x - state.friction * state.v;
}
function springEvaluateStateWithDerivative(initialState, dt, derivative) {
var state = {
x: initialState.x + derivative.dx * dt,
v: initialState.v + derivative.dv * dt,
tension: initialState.tension,
friction: initialState.friction
};
return {
dx: state.v,
dv: springAccelerationForState(state)
};
}
function springIntegrateState(state, dt) {
var a = {
dx: state.v,
dv: springAccelerationForState(state)
},
b = springEvaluateStateWithDerivative(state, dt * 0.5, a),
c = springEvaluateStateWithDerivative(state, dt * 0.5, b),
d = springEvaluateStateWithDerivative(state, dt, c),
dxdt = 1 / 6 * (a.dx + 2 * (b.dx + c.dx) + d.dx),
dvdt = 1 / 6 * (a.dv + 2 * (b.dv + c.dv) + d.dv);
state.x = state.x + dxdt * dt;
state.v = state.v + dvdt * dt;
return state;
}
function generateSpringRK4(tension, friction, duration) {
var initState = {
x: -1,
v: 0,
tension: parseFloat(tension) || 500,
friction: parseFloat(friction) || 20
},
path = [0],
tolerance = 1 / 10000,
DT = 16 / 1000,
haveDuration = duration != null; // deliberate "==", as undefined == null != 0
var timeLapsed = 0,
dt = void 0,
lastState = void 0;
/* Calculate the actual time it takes for this animation to complete with the provided conditions. */
if (haveDuration) {
/* Run the simulation without a duration. */
timeLapsed = generateSpringRK4(initState.tension, initState.friction);
/* Compute the adjusted time delta. */
dt = timeLapsed / duration * DT;
} else {
dt = DT;
}
while (true) {
/* Next/step function .*/
lastState = springIntegrateState(lastState || initState, dt);
/* Store the position. */
path.push(1 + lastState.x);
timeLapsed += 16;
/* If the change threshold is reached, break. */
if (!(Math.abs(lastState.x) > tolerance && Math.abs(lastState.v) > tolerance)) {
break;
}
}
/* If duration is not defined, return the actual time required for completing this animation. Otherwise, return a closure that holds the
computed path and returns a snapshot of the position according to a given percentComplete. */
return !haveDuration ? timeLapsed : function (percentComplete, startValue, endValue) {
if (percentComplete === 0) {
return startValue;
}
if (percentComplete === 1) {
return endValue;
}
return startValue + path[Math.floor(percentComplete * (path.length - 1))] * (endValue - startValue);
};
}
// Constants
var cache = {};
function generateStep(steps) {
var fn = cache[steps];
if (fn) {
return fn;
}
return cache[steps] = function (percentComplete, startValue, endValue) {
if (percentComplete === 0) {
return startValue;
}
if (percentComplete === 1) {
return endValue;
}
return startValue + Math.round(percentComplete * steps) * (1 / steps) * (endValue - startValue);
};
}
// Project
/**
* Parse a duration value and return an ms number. Optionally return a
* default value if the number is not valid.
*/
function parseDuration(duration, def) {
if (isNumber(duration)) {
return duration;
}
if (isString(duration)) {
return Duration[duration.toLowerCase()] || parseFloat(duration.replace("ms", "").replace("s", "000"));
}
return def == null ? undefined : parseDuration(def);
}
/**
* Validate a <code>cache</code> option.
*/
function validateCache(value) {
if (isBoolean(value)) {
return value;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'cache' to an invalid value:", value);
}
}
/**
* Validate a <code>begin</code> option.
*/
function validateBegin(value) {
if (isFunction(value)) {
return value;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'begin' to an invalid value:", value);
}
}
/**
* Validate a <code>complete</code> option.
*/
function validateComplete(value, noError) {
if (isFunction(value)) {
return value;
}
if (value != null && !noError) {
console.warn("VelocityJS: Trying to set 'complete' to an invalid value:", value);
}
}
/**
* Validate a <code>delay</code> option.
*/
function validateDelay(value) {
var parsed = parseDuration(value);
if (!isNaN(parsed)) {
return parsed;
}
if (value != null) {
console.error("VelocityJS: Trying to set 'delay' to an invalid value:", value);
}
}
/**
* Validate a <code>duration</code> option.
*/
function validateDuration(value, noError) {
var parsed = parseDuration(value);
if (!isNaN(parsed) && parsed >= 0) {
return parsed;
}
if (value != null && !noError) {
console.error("VelocityJS: Trying to set 'duration' to an invalid value:", value);
}
}
/**
* Validate a <code>easing</code> option.
*/
function validateEasing(value, duration, noError) {
if (isString(value)) {
// Named easing
return Easings[value];
}
if (isFunction(value)) {
return value;
}
// TODO: We should only do these if the correct function exists - don't force loading.
if (Array.isArray(value)) {
if (value.length === 1) {
// Steps
return generateStep(value[0]);
}
if (value.length === 2) {
// springRK4 must be passed the animation's duration.
// Note: If the springRK4 array contains non-numbers,
// generateSpringRK4() returns an easing function generated with
// default tension and friction values.
return generateSpringRK4(value[0], value[1], duration);
}
if (value.length === 4) {
// Note: If the bezier array contains non-numbers, generateBezier()
// returns undefined.
return generateBezier.apply(null, value) || false;
}
}
if (value != null && !noError) {
console.error("VelocityJS: Trying to set 'easing' to an invalid value:", value);
}
}
/**
* Validate a <code>fpsLimit</code> option.
*/
function validateFpsLimit(value) {
if (value === false) {
return 0;
} else {
var parsed = parseInt(value, 10);
if (!isNaN(parsed) && parsed >= 0) {
return Math.min(parsed, 60);
}
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'fpsLimit' to an invalid value:", value);
}
}
/**
* Validate a <code>loop</code> option.
*/
function validateLoop(value) {
switch (value) {
case false:
return 0;
case true:
return true;
default:
var parsed = parseInt(value, 10);
if (!isNaN(parsed) && parsed >= 0) {
return parsed;
}
break;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'loop' to an invalid value:", value);
}
}
/**
* Validate a <code>progress</code> option.
*/
function validateProgress(value) {
if (isFunction(value)) {
return value;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'progress' to an invalid value:", value);
}
}
/**
* Validate a <code>promise</code> option.
*/
function validatePromise(value) {
if (isBoolean(value)) {
return value;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'promise' to an invalid value:", value);
}
}
/**
* Validate a <code>promiseRejectEmpty</code> option.
*/
function validatePromiseRejectEmpty(value) {
if (isBoolean(value)) {
return value;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'promiseRejectEmpty' to an invalid value:", value);
}
}
/**
* Validate a <code>queue</code> option.
*/
function validateQueue(value, noError) {
if (value === false || isString(value)) {
return value;
}
if (value != null && !noError) {
console.warn("VelocityJS: Trying to set 'queue' to an invalid value:", value);
}
}
/**
* Validate a <code>repeat</code> option.
*/
function validateRepeat(value) {
switch (value) {
case false:
return 0;
case true:
return true;
default:
var parsed = parseInt(value, 10);
if (!isNaN(parsed) && parsed >= 0) {
return parsed;
}
break;
}
if (value != null) {
console.warn("VelocityJS: Trying to set 'repeat' to an invalid value:", value);
}
}
/**
* Validate a <code>speed</code> option.
*/
function validateSpeed(value) {
if (isNumber(value)) {
return value;
}
if (value != null) {
console.error("VelocityJS: Trying to set 'speed' to an invalid value:", value);
}
}
/**
* Validate a <code>sync</code> option.
*/
function validateSync(value) {
if (isBoolean(value)) {
return value;
}
if (value != null) {
console.error("VelocityJS: Trying to set 'sync' to an invalid value:", value);
}
}
// Project
// NOTE: Add the variable here, then add the default state in "reset" below.
var cache$1 = void 0,
begin = void 0,
complete = void 0,
delay = void 0,
duration = void 0,
easing = void 0,
fpsLimit = void 0,
loop = void 0,
mobileHA = void 0,
minFrameTime = void 0,
promise = void 0,
promiseRejectEmpty = void 0,
queue = void 0,
repeat = void 0,
speed = void 0,
sync = void 0;
var defaults$1 = function () {
function defaults$$1() {
classCallCheck(this, defaults$$1);
}
createClass(defaults$$1, null, [{
key: "reset",
value: function reset() {
cache$1 = DEFAULT_CACHE;
begin = undefined;
complete = undefined;
delay = DEFAULT_DELAY;
duration = DEFAULT_DURATION;
easing = validateEasing(DEFAULT_EASING, DEFAULT_DURATION);
fpsLimit = DEFAULT_FPSLIMIT;
loop = DEFAULT_LOOP;
minFrameTime = FUZZY_MS_PER_SECOND / DEFAULT_FPSLIMIT;
promise = DEFAULT_PROMISE;
promiseRejectEmpty = DEFAULT_PROMISE_REJECT_EMPTY;
queue = DEFAULT_QUEUE;
repeat = DEFAULT_REPEAT;
speed = DEFAULT_SPEED;
sync = DEFAULT_SYNC;
}
}, {
key: "cache",
get: function get$$1() {
return cache$1;
},
set: function set$$1(value) {
value = validateCache(value);
if (value !== undefined) {
cache$1 = value;
}
}
}, {
key: "begin",
get: function get$$1() {
return begin;
},
set: function set$$1(value) {
value = validateBegin(value);
if (value !== undefined) {
begin = value;
}
}
}, {
key: "complete",
get: function get$$1() {
return complete;
},
set: function set$$1(value) {
value = validateComplete(value);
if (value !== undefined) {
complete = value;
}
}
}, {
key: "delay",
get: function get$$1() {
return delay;
},
set: function set$$1(value) {
value = validateDelay(value);
if (value !== undefined) {
delay = value;
}
}
}, {
key: "duration",
get: function get$$1() {
return duration;
},
set: function set$$1(value) {
value = validateDuration(value);
if (value !== undefined) {
duration = value;
}
}
}, {
key: "easing",
get: function get$$1() {
return easing;
},
set: function set$$1(value) {
value = validateEasing(value, duration);
if (value !== undefined) {
easing = value;
}
}
}, {
key: "fpsLimit",
get: function get$$1() {
return fpsLimit;
},
set: function set$$1(value) {
value = validateFpsLimit(value);
if (value !== undefined) {
fpsLimit = value;
minFrameTime = FUZZY_MS_PER_SECOND / value;
}
}
}, {
key: "loop",
get: function get$$1() {
return loop;
},
set: function set$$1(value) {
value = validateLoop(value);
if (value !== undefined) {
loop = value;
}
}
}, {
key: "mobileHA",
get: function get$$1() {
return mobileHA;
},
set: function set$$1(value) {
if (isBoolean(value)) {
mobileHA = value;
}
}
}, {
key: "minFrameTime",
get: function get$$1() {
return minFrameTime;
}
}, {
key: "promise",
get: function get$$1() {
return promise;
},
set: function set$$1(value) {
value = validatePromise(value);
if (value !== undefined) {
promise = value;
}
}
}, {
key: "promiseRejectEmpty",
get: function get$$1() {
return promiseRejectEmpty;
},
set: function set$$1(value) {
value = validatePromiseRejectEmpty(value);
if (value !== undefined) {
promiseRejectEmpty = value;
}
}
}, {
key: "queue",
get: function get$$1() {
return queue;
},
set: function set$$1(value) {
value = validateQueue(value);
if (value !== undefined) {
queue = value;
}
}
}, {
key: "repeat",
get: function get$$1() {
return repeat;
},
set: function set$$1(value) {
value = validateRepeat(value);
if (value !== undefined) {
repeat = value;
}
}
}, {
key: "repeatAgain",
get: function get$$1() {
return repeat;
}
}, {
key: "speed",
get: function get$$1() {
return speed;
},
set: function set$$1(value) {
value = validateSpeed(value);
if (value !== undefined) {
speed = value;
}
}
}, {
key: "sync",
get: function get$$1() {
return sync;
},