-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
1876 lines (1662 loc) · 79.8 KB
/
bundle.js
File metadata and controls
1876 lines (1662 loc) · 79.8 KB
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 = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var _animations = __webpack_require__(1);
var _animations2 = _interopRequireDefault(_animations);
var _start = __webpack_require__(9);
var _start2 = _interopRequireDefault(_start);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
__webpack_require__(10);
document.addEventListener("DOMContentLoaded", function () {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
(0, _start2.default)(ctx, canvas);
(0, _animations2.default)(ctx, canvas);
var modal = document.getElementById('myModal');
document.addEventListener('keydown', function (e) {
e.preventDefault();
$('#myModal').addClass('fadeOut');
var footer = document.getElementById('footer');
footer.style.zIndex = '1';
});
window.onclick = function (e) {
e.preventDefault();
if (e.target === modal) {
$('#myModal').addClass('fadeOut');
var footer = document.getElementById('footer');
footer.style.zIndex = '1';
}
};
});
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _animejs = __webpack_require__(2);
var _animejs2 = _interopRequireDefault(_animejs);
var _sound_set_ = __webpack_require__(3);
var _sound_set_2 = __webpack_require__(4);
var _sound_set_3 = __webpack_require__(5);
var _sound_set_4 = __webpack_require__(6);
var _howlerMin = __webpack_require__(7);
var _howlerMin2 = _interopRequireDefault(_howlerMin);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Animations = function Animations(ctx, canvas) {
//Set default state;
var numOfCircles = 25;
var distance = 300;
var actions = [];
var sound = void 0;
var colorSets = [
//colorset1
["#f8ffe5", "#06D6A0", "#1B9AAA", "#EF476F", "#FFC43D"],
//colorset2
["#5b507a", "#5B618A", "#9EADC8", "#B9E28C", "#D6D84F"],
//colorset3
["#5bc0eb", "#f9c80e", "#41ead4", "#fdfffc", "#b91372"],
//colorset4
["#f6e8ea", "#ef626c", "#de1a1a", "#acbed8", "#84dccf"]];
var fillSets = ["#312f2f", "#181819", "#0b111c", "#010e23"];
var soundSets = [_sound_set_.soundSet1, _sound_set_2.soundSet2, _sound_set_3.soundSet3, _sound_set_4.soundSet4];
var fontSize = function fontSize() {
return parseFloat(getComputedStyle(document.documentElement).fontSize);
};
var resizeCanvas = function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
};
var removeAction = function removeAction(action) {
var idx = actions.indexOf(action);
if (idx > -1) actions.splice(idx, 1);
};
var changeColorSet = function changeColorSet() {
var temp = colorSets.shift();
colorSets.push(temp);
};
var changeSoundSet = function changeSoundSet() {
var temp = soundSets.shift();
soundSets.push(temp);
};
var drawRipple = function drawRipple(x, y) {
//Choose a random colorset
var colorSet = colorSets[0];
var ripple = {};
ripple.x = x;
ripple.y = y;
ripple.color = colorSet[_animejs2.default.random(0, colorSet.length - 1)];
ripple.radius = 0;
ripple.alpha = 1;
ripple.lineWidth = 5;
ripple.draw = function () {
ctx.globalAlpha = ripple.alpha;
ctx.beginPath();
ctx.arc(ripple.x, ripple.y, ripple.radius, 2 * Math.PI, false);
ctx.lineWidth = ripple.lineWidth;
ctx.strokeStyle = ripple.color;
ctx.stroke();
ctx.globalAlpha = 1;
};
return ripple;
};
var drawCircle = function drawCircle(x, y) {
//Choose a random colorset
var colorSet = colorSets[0];
var circle = {};
circle.x = x;
circle.y = y;
circle.color = colorSet[_animejs2.default.random(0, colorSet.length - 1)];
circle.radius = _animejs2.default.random(fontSize(), fontSize() * 2);
circle.draw = function () {
ctx.beginPath();
ctx.arc(circle.x, circle.y, circle.radius, 2 * Math.PI, false);
ctx.fillStyle = circle.color;
ctx.fill();
};
return circle;
};
var drawCircles = function drawCircles(x, y) {
var circles = [];
for (var i = 0; i < numOfCircles; i++) {
var circle = drawCircle(x, y);
circles.push(circle);
}
return circles;
};
var animateRipple = function animateRipple(ripple, size) {
return (0, _animejs2.default)({
targets: ripple,
radius: function radius() {
return _animejs2.default.random(fontSize() * size, fontSize() * (size + 2));
},
lineWidth: 0,
alpha: {
value: 0,
easing: 'linear',
duration: function duration() {
return _animejs2.default.random(300, 500);
}
},
duration: function duration() {
return _animejs2.default.random(1000, 1300);
},
easing: 'easeOutExpo',
complete: removeAction
});
};
var animateCircles = function animateCircles(x, y) {
resizeCanvas();
//Draw shapes
var circles = drawCircles(x, y);
var ripple1 = drawRipple(x, y);
var ripple2 = drawRipple(x, y);
var ripple3 = drawRipple(x, y);
//Animate shapes
var circleAnimation = (0, _animejs2.default)({
targets: circles,
x: function x(circle) {
return circle.x + _animejs2.default.random(-distance, distance);
},
y: function y(circle) {
return circle.y + _animejs2.default.random(-distance, distance);
},
radius: 0,
duration: function duration() {
return _animejs2.default.random(1000, 1300);
},
easing: 'easeOutExpo',
complete: removeAction
});
//Animate ripples
var ripple1Animation = animateRipple(ripple1, 5);
var ripple2Animation = animateRipple(ripple2, 7);
var ripple3Animation = animateRipple(ripple3, 9);
actions.push(circleAnimation);
actions.push(ripple1Animation);
actions.push(ripple2Animation);
actions.push(ripple3Animation);
};
var animate = (0, _animejs2.default)({
duration: Infinity,
update: function update() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
actions.forEach(function (action) {
action.animatables.forEach(function (animatable) {
animatable.target.draw();
});
});
}
});
//Update coordinates after animation
var x = void 0,
y = void 0;
var updateCoords = function updateCoords() {
x = Math.random() * canvas.width;
y = Math.random() * canvas.height;
};
var removeContainer = function removeContainer() {
$('#title').removeClass('pulse');
$('#description').removeClass('pulse');
};
var pulseContainer = function pulseContainer() {
$('#title').addClass('pulse');
$('#description').addClass('pulse');
setTimeout(removeContainer, 300);
};
var removeLogo = function removeLogo() {
$('#logo').removeClass('pulse');
};
var pulseLogo = function pulseLogo() {
$('#logo').addClass('pulse');
setTimeout(removeLogo, 300);
};
document.addEventListener('keydown', function (e) {
e.preventDefault();
//Spacebar to change colorset and soundset
if (e.keyCode === 32) {
changeColorSet();
changeSoundSet();
var el = $('#logo');
var offset = el.offset();
animateCircles(offset.left + 25, offset.top + 25);
pulseLogo();
sound = new Howl({
src: soundSets[0][e.keyCode]
});
sound.play();
}
//Number and letter key to play sound
if (e.keyCode >= 65 && e.keyCode <= 90) {
updateCoords();
animateCircles(x, y);
pulseContainer();
sound = new Howl({
src: soundSets[0][e.keyCode]
});
sound.play();
}
});
window.addEventListener('resize', resizeCanvas);
};
exports.default = Animations;
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*
* Anime v1.1.3
* http://anime-js.com
* JavaScript animation engine
* Copyright (c) 2016 Julian Garnier
* http://juliangarnier.com
* Released under the MIT license
*/
(function (root, factory) {
if (true) {
// AMD. Register as an anonymous module.
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.anime = factory();
}
}(this, function () {
var version = '1.1.3';
// Defaults
var defaultSettings = {
duration: 1000,
delay: 0,
loop: false,
autoplay: true,
direction: 'normal',
easing: 'easeOutElastic',
elasticity: 400,
round: false,
begin: undefined,
update: undefined,
complete: undefined
}
// Transforms
var validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skewX', 'skewY'];
var transform, transformStr = 'transform';
// Utils
var is = {
arr: function(a) { return Array.isArray(a) },
obj: function(a) { return Object.prototype.toString.call(a).indexOf('Object') > -1 },
svg: function(a) { return a instanceof SVGElement },
dom: function(a) { return a.nodeType || is.svg(a) },
num: function(a) { return !isNaN(parseInt(a)) },
str: function(a) { return typeof a === 'string' },
fnc: function(a) { return typeof a === 'function' },
und: function(a) { return typeof a === 'undefined' },
nul: function(a) { return typeof a === 'null' },
hex: function(a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a) },
rgb: function(a) { return /^rgb/.test(a) },
hsl: function(a) { return /^hsl/.test(a) },
col: function(a) { return (is.hex(a) || is.rgb(a) || is.hsl(a)) }
}
// Easings functions adapted from http://jqueryui.com/
var easings = (function() {
var eases = {};
var names = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo'];
var functions = {
Sine: function(t) { return 1 + Math.sin(Math.PI / 2 * t - Math.PI / 2); },
Circ: function(t) { return 1 - Math.sqrt( 1 - t * t ); },
Elastic: function(t, m) {
if( t === 0 || t === 1 ) return t;
var p = (1 - Math.min(m, 998) / 1000), st = t / 1, st1 = st - 1, s = p / ( 2 * Math.PI ) * Math.asin( 1 );
return -( Math.pow( 2, 10 * st1 ) * Math.sin( ( st1 - s ) * ( 2 * Math.PI ) / p ) );
},
Back: function(t) { return t * t * ( 3 * t - 2 ); },
Bounce: function(t) {
var pow2, bounce = 4;
while ( t < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - t, 2 );
}
}
names.forEach(function(name, i) {
functions[name] = function(t) {
return Math.pow( t, i + 2 );
}
});
Object.keys(functions).forEach(function(name) {
var easeIn = functions[name];
eases['easeIn' + name] = easeIn;
eases['easeOut' + name] = function(t, m) { return 1 - easeIn(1 - t, m); };
eases['easeInOut' + name] = function(t, m) { return t < 0.5 ? easeIn(t * 2, m) / 2 : 1 - easeIn(t * -2 + 2, m) / 2; };
eases['easeOutIn' + name] = function(t, m) { return t < 0.5 ? (1 - easeIn(1 - 2 * t, m)) / 2 : (easeIn(t * 2 - 1, m) + 1) / 2; };
});
eases.linear = function(t) { return t; };
return eases;
})();
// Strings
var numberToString = function(val) {
return (is.str(val)) ? val : val + '';
}
var stringToHyphens = function(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
var selectString = function(str) {
if (is.col(str)) return false;
try {
var nodes = document.querySelectorAll(str);
return nodes;
} catch(e) {
return false;
}
}
// Numbers
var random = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Arrays
var flattenArray = function(arr) {
return arr.reduce(function(a, b) {
return a.concat(is.arr(b) ? flattenArray(b) : b);
}, []);
}
var toArray = function(o) {
if (is.arr(o)) return o;
if (is.str(o)) o = selectString(o) || o;
if (o instanceof NodeList || o instanceof HTMLCollection) return [].slice.call(o);
return [o];
}
var arrayContains = function(arr, val) {
return arr.some(function(a) { return a === val; });
}
var groupArrayByProps = function(arr, propsArr) {
var groups = {};
arr.forEach(function(o) {
var group = JSON.stringify(propsArr.map(function(p) { return o[p]; }));
groups[group] = groups[group] || [];
groups[group].push(o);
});
return Object.keys(groups).map(function(group) {
return groups[group];
});
}
var removeArrayDuplicates = function(arr) {
return arr.filter(function(item, pos, self) {
return self.indexOf(item) === pos;
});
}
// Objects
var cloneObject = function(o) {
var newObject = {};
for (var p in o) newObject[p] = o[p];
return newObject;
}
var mergeObjects = function(o1, o2) {
for (var p in o2) o1[p] = !is.und(o1[p]) ? o1[p] : o2[p];
return o1;
}
// Colors
var hexToRgb = function(hex) {
var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
var hex = hex.replace(rgx, function(m, r, g, b) { return r + r + g + g + b + b; });
var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
var r = parseInt(rgb[1], 16);
var g = parseInt(rgb[2], 16);
var b = parseInt(rgb[3], 16);
return 'rgb(' + r + ',' + g + ',' + b + ')';
}
var hslToRgb = function(hsl) {
var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hsl);
var h = parseInt(hsl[1]) / 360;
var s = parseInt(hsl[2]) / 100;
var l = parseInt(hsl[3]) / 100;
var hue2rgb = function(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var r, g, b;
if (s == 0) {
r = g = b = l;
} else {
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
return 'rgb(' + r * 255 + ',' + g * 255 + ',' + b * 255 + ')';
}
var colorToRgb = function(val) {
if (is.rgb(val)) return val;
if (is.hex(val)) return hexToRgb(val);
if (is.hsl(val)) return hslToRgb(val);
}
// Units
var getUnit = function(val) {
return /([\+\-]?[0-9|auto\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg)?/.exec(val)[2];
}
var addDefaultTransformUnit = function(prop, val, intialVal) {
if (getUnit(val)) return val;
if (prop.indexOf('translate') > -1) return getUnit(intialVal) ? val + getUnit(intialVal) : val + 'px';
if (prop.indexOf('rotate') > -1 || prop.indexOf('skew') > -1) return val + 'deg';
return val;
}
// Values
var getCSSValue = function(el, prop) {
// First check if prop is a valid CSS property
if (prop in el.style) {
// Then return the property value or fallback to '0' when getPropertyValue fails
return getComputedStyle(el).getPropertyValue(stringToHyphens(prop)) || '0';
}
}
var getTransformValue = function(el, prop) {
var defaultVal = prop.indexOf('scale') > -1 ? 1 : 0;
var str = el.style.transform;
if (!str) return defaultVal;
var rgx = /(\w+)\((.+?)\)/g;
var match = [];
var props = [];
var values = [];
while (match = rgx.exec(str)) {
props.push(match[1]);
values.push(match[2]);
}
var val = values.filter(function(f, i) { return props[i] === prop; });
return val.length ? val[0] : defaultVal;
}
var getAnimationType = function(el, prop) {
if ( is.dom(el) && arrayContains(validTransforms, prop)) return 'transform';
if ( is.dom(el) && (el.getAttribute(prop) || (is.svg(el) && el[prop]))) return 'attribute';
if ( is.dom(el) && (prop !== 'transform' && getCSSValue(el, prop))) return 'css';
if (!is.nul(el[prop]) && !is.und(el[prop])) return 'object';
}
var getInitialTargetValue = function(target, prop) {
switch (getAnimationType(target, prop)) {
case 'transform': return getTransformValue(target, prop);
case 'css': return getCSSValue(target, prop);
case 'attribute': return target.getAttribute(prop);
}
return target[prop] || 0;
}
var getValidValue = function(values, val, originalCSS) {
if (is.col(val)) return colorToRgb(val);
if (getUnit(val)) return val;
var unit = getUnit(values.to) ? getUnit(values.to) : getUnit(values.from);
if (!unit && originalCSS) unit = getUnit(originalCSS);
return unit ? val + unit : val;
}
var decomposeValue = function(val) {
var rgx = /-?\d*\.?\d+/g;
return {
original: val,
numbers: numberToString(val).match(rgx) ? numberToString(val).match(rgx).map(Number) : [0],
strings: numberToString(val).split(rgx)
}
}
var recomposeValue = function(numbers, strings, initialStrings) {
return strings.reduce(function(a, b, i) {
var b = (b ? b : initialStrings[i - 1]);
return a + numbers[i - 1] + b;
});
}
// Animatables
var getAnimatables = function(targets) {
var targets = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : [];
return targets.map(function(t, i) {
return { target: t, id: i };
});
}
// Properties
var getProperties = function(params, settings) {
var props = [];
for (var p in params) {
if (!defaultSettings.hasOwnProperty(p) && p !== 'targets') {
var prop = is.obj(params[p]) ? cloneObject(params[p]) : {value: params[p]};
prop.name = p;
props.push(mergeObjects(prop, settings));
}
}
return props;
}
var getPropertiesValues = function(target, prop, value, i) {
var values = toArray( is.fnc(value) ? value(target, i) : value);
return {
from: (values.length > 1) ? values[0] : getInitialTargetValue(target, prop),
to: (values.length > 1) ? values[1] : values[0]
}
}
// Tweens
var getTweenValues = function(prop, values, type, target) {
var valid = {};
if (type === 'transform') {
valid.from = prop + '(' + addDefaultTransformUnit(prop, values.from, values.to) + ')';
valid.to = prop + '(' + addDefaultTransformUnit(prop, values.to) + ')';
} else {
var originalCSS = (type === 'css') ? getCSSValue(target, prop) : undefined;
valid.from = getValidValue(values, values.from, originalCSS);
valid.to = getValidValue(values, values.to, originalCSS);
}
return { from: decomposeValue(valid.from), to: decomposeValue(valid.to) };
}
var getTweensProps = function(animatables, props) {
var tweensProps = [];
animatables.forEach(function(animatable, i) {
var target = animatable.target;
return props.forEach(function(prop) {
var animType = getAnimationType(target, prop.name);
if (animType) {
var values = getPropertiesValues(target, prop.name, prop.value, i);
var tween = cloneObject(prop);
tween.animatables = animatable;
tween.type = animType;
tween.from = getTweenValues(prop.name, values, tween.type, target).from;
tween.to = getTweenValues(prop.name, values, tween.type, target).to;
tween.round = (is.col(values.from) || tween.round) ? 1 : 0;
tween.delay = (is.fnc(tween.delay) ? tween.delay(target, i, animatables.length) : tween.delay) / animation.speed;
tween.duration = (is.fnc(tween.duration) ? tween.duration(target, i, animatables.length) : tween.duration) / animation.speed;
tweensProps.push(tween);
}
});
});
return tweensProps;
}
var getTweens = function(animatables, props) {
var tweensProps = getTweensProps(animatables, props);
var splittedProps = groupArrayByProps(tweensProps, ['name', 'from', 'to', 'delay', 'duration']);
return splittedProps.map(function(tweenProps) {
var tween = cloneObject(tweenProps[0]);
tween.animatables = tweenProps.map(function(p) { return p.animatables });
tween.totalDuration = tween.delay + tween.duration;
return tween;
});
}
var reverseTweens = function(anim, delays) {
anim.tweens.forEach(function(tween) {
var toVal = tween.to;
var fromVal = tween.from;
var delayVal = anim.duration - (tween.delay + tween.duration);
tween.from = toVal;
tween.to = fromVal;
if (delays) tween.delay = delayVal;
});
anim.reversed = anim.reversed ? false : true;
}
var getTweensDuration = function(tweens) {
return Math.max.apply(Math, tweens.map(function(tween){ return tween.totalDuration; }));
}
var getTweensDelay = function(tweens) {
return Math.min.apply(Math, tweens.map(function(tween){ return tween.delay; }));
}
// will-change
var getWillChange = function(anim) {
var props = [];
var els = [];
anim.tweens.forEach(function(tween) {
if (tween.type === 'css' || tween.type === 'transform' ) {
props.push(tween.type === 'css' ? stringToHyphens(tween.name) : 'transform');
tween.animatables.forEach(function(animatable) { els.push(animatable.target); });
}
});
return {
properties: removeArrayDuplicates(props).join(', '),
elements: removeArrayDuplicates(els)
}
}
var setWillChange = function(anim) {
var willChange = getWillChange(anim);
willChange.elements.forEach(function(element) {
element.style.willChange = willChange.properties;
});
}
var removeWillChange = function(anim) {
var willChange = getWillChange(anim);
willChange.elements.forEach(function(element) {
element.style.removeProperty('will-change');
});
}
/* Svg path */
var getPathProps = function(path) {
var el = is.str(path) ? selectString(path)[0] : path;
return {
path: el,
value: el.getTotalLength()
}
}
var snapProgressToPath = function(tween, progress) {
var pathEl = tween.path;
var pathProgress = tween.value * progress;
var point = function(offset) {
var o = offset || 0;
var p = progress > 1 ? tween.value + o : pathProgress + o;
return pathEl.getPointAtLength(p);
}
var p = point();
var p0 = point(-1);
var p1 = point(+1);
switch (tween.name) {
case 'translateX': return p.x;
case 'translateY': return p.y;
case 'rotate': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;
}
}
// Progress
var getTweenProgress = function(tween, time) {
var elapsed = Math.min(Math.max(time - tween.delay, 0), tween.duration);
var percent = elapsed / tween.duration;
var progress = tween.to.numbers.map(function(number, p) {
var start = tween.from.numbers[p];
var eased = easings[tween.easing](percent, tween.elasticity);
var val = tween.path ? snapProgressToPath(tween, eased) : start + eased * (number - start);
val = tween.round ? Math.round(val * tween.round) / tween.round : val;
return val;
});
return recomposeValue(progress, tween.to.strings, tween.from.strings);
}
var setAnimationProgress = function(anim, time) {
var transforms;
anim.currentTime = time;
anim.progress = (time / anim.duration) * 100;
for (var t = 0; t < anim.tweens.length; t++) {
var tween = anim.tweens[t];
tween.currentValue = getTweenProgress(tween, time);
var progress = tween.currentValue;
for (var a = 0; a < tween.animatables.length; a++) {
var animatable = tween.animatables[a];
var id = animatable.id;
var target = animatable.target;
var name = tween.name;
switch (tween.type) {
case 'css': target.style[name] = progress; break;
case 'attribute': target.setAttribute(name, progress); break;
case 'object': target[name] = progress; break;
case 'transform':
if (!transforms) transforms = {};
if (!transforms[id]) transforms[id] = [];
transforms[id].push(progress);
break;
}
}
}
if (transforms) {
if (!transform) transform = (getCSSValue(document.body, transformStr) ? '' : '-webkit-') + transformStr;
for (var t in transforms) {
anim.animatables[t].target.style[transform] = transforms[t].join(' ');
}
}
}
// Animation
var createAnimation = function(params) {
var anim = {};
anim.animatables = getAnimatables(params.targets);
anim.settings = mergeObjects(params, defaultSettings);
anim.properties = getProperties(params, anim.settings);
anim.tweens = getTweens(anim.animatables, anim.properties);
anim.duration = anim.tweens.length ? getTweensDuration(anim.tweens) : params.duration;
anim.delay = anim.tweens.length ? getTweensDelay(anim.tweens) : params.delay;
anim.currentTime = 0;
anim.progress = 0;
anim.ended = false;
return anim;
}
// Public
var animations = [];
var raf = 0;
var engine = (function() {
var play = function() { raf = requestAnimationFrame(step); };
var step = function(t) {
if (animations.length) {
for (var i = 0; i < animations.length; i++) animations[i].tick(t);
play();
} else {
cancelAnimationFrame(raf);
raf = 0;
}
}
return play;
})();
var animation = function(params) {
var anim = createAnimation(params);
var time = {};
anim.tick = function(now) {
anim.ended = false;
if (!time.start) time.start = now;
time.current = Math.min(Math.max(time.last + now - time.start, 0), anim.duration);
setAnimationProgress(anim, time.current);
var s = anim.settings;
if (time.current >= anim.delay) {
if (s.begin) s.begin(anim); s.begin = undefined;
if (s.update) s.update(anim);
}
if (time.current >= anim.duration) {
if (s.loop) {
time.start = now;
if (s.direction === 'alternate') reverseTweens(anim, true);
if (is.num(s.loop)) s.loop--;
} else {
anim.ended = true;
anim.pause();
if (s.complete) s.complete(anim);
}
time.last = 0;
}
}
anim.seek = function(progress) {
setAnimationProgress(anim, (progress / 100) * anim.duration);
}
anim.pause = function() {
removeWillChange(anim);
var i = animations.indexOf(anim);
if (i > -1) animations.splice(i, 1);
}
anim.play = function(params) {
anim.pause();
if (params) anim = mergeObjects(createAnimation(mergeObjects(params, anim.settings)), anim);
time.start = 0;
time.last = anim.ended ? 0 : anim.currentTime;
var s = anim.settings;
if (s.direction === 'reverse') reverseTweens(anim);
if (s.direction === 'alternate' && !s.loop) s.loop = 1;
setWillChange(anim);
animations.push(anim);
if (!raf) engine();
}
anim.restart = function() {
if (anim.reversed) reverseTweens(anim);
anim.pause();
anim.seek(0);
anim.play();
}
if (anim.settings.autoplay) anim.play();
return anim;
}
// Remove one or multiple targets from all active animations.
var remove = function(elements) {
var targets = flattenArray(is.arr(elements) ? elements.map(toArray) : toArray(elements));
for (var i = animations.length-1; i >= 0; i--) {
var animation = animations[i];
var tweens = animation.tweens;
for (var t = tweens.length-1; t >= 0; t--) {
var animatables = tweens[t].animatables;
for (var a = animatables.length-1; a >= 0; a--) {
if (arrayContains(targets, animatables[a].target)) {
animatables.splice(a, 1);
if (!animatables.length) tweens.splice(t, 1);
if (!tweens.length) animation.pause();
}
}
}
}
}
animation.version = version;
animation.speed = 1;
animation.list = animations;
animation.remove = remove;
animation.easings = easings;
animation.getValue = getInitialTargetValue;
animation.path = getPathProps;
animation.random = random;
return animation;
}));
/***/ },