0 | 11 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,9 @@ |
1 |
+The MIT License |
|
2 |
+ |
|
3 |
+Copyright (c) 2019 Julian Garnier |
|
4 |
+ |
|
5 |
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|
6 |
+ |
|
7 |
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|
8 |
+ |
|
9 |
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 | 10 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,8 @@ |
1 |
+Anime.js animation library |
|
2 |
+===== |
|
3 |
+ |
|
4 |
+This is a customized package of the [anime.js][1] animation library, provided and maintained by [vonRotenberg][2], to be integrated in [Contao Open Source CMS][3]. |
|
5 |
+ |
|
6 |
+[1]: https://animejs.com |
|
7 |
+[2]: https://www.vonrotenberg.de |
|
8 |
+[3]: https://contao.org |
|
0 | 9 |
\ No newline at end of file |
1 | 10 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,15 @@ |
1 |
+{ |
|
2 |
+ "name": "vonRotenberg/contao-component-animejs", |
|
3 |
+ "type": "contao-component", |
|
4 |
+ "description": "anime.js animation library integration for Contao Open Source CMS", |
|
5 |
+ "license": "MIT", |
|
6 |
+ "authors": [ |
|
7 |
+ { |
|
8 |
+ "name": "Benjamin Roth", |
|
9 |
+ "homepage": "https://www.vonrotenberg.de" |
|
10 |
+ } |
|
11 |
+ ], |
|
12 |
+ "require": { |
|
13 |
+ "contao-components/installer": "^1.2.0" |
|
14 |
+ } |
|
15 |
+} |
|
0 | 16 |
\ No newline at end of file |
1 | 17 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,1281 @@ |
1 |
+/* |
|
2 |
+ * anime.js v3.2.0 |
|
3 |
+ * (c) 2020 Julian Garnier |
|
4 |
+ * Released under the MIT license |
|
5 |
+ * animejs.com |
|
6 |
+ */ |
|
7 |
+ |
|
8 |
+// Defaults |
|
9 |
+ |
|
10 |
+var defaultInstanceSettings = { |
|
11 |
+ update: null, |
|
12 |
+ begin: null, |
|
13 |
+ loopBegin: null, |
|
14 |
+ changeBegin: null, |
|
15 |
+ change: null, |
|
16 |
+ changeComplete: null, |
|
17 |
+ loopComplete: null, |
|
18 |
+ complete: null, |
|
19 |
+ loop: 1, |
|
20 |
+ direction: 'normal', |
|
21 |
+ autoplay: true, |
|
22 |
+ timelineOffset: 0 |
|
23 |
+}; |
|
24 |
+ |
|
25 |
+var defaultTweenSettings = { |
|
26 |
+ duration: 1000, |
|
27 |
+ delay: 0, |
|
28 |
+ endDelay: 0, |
|
29 |
+ easing: 'easeOutElastic(1, .5)', |
|
30 |
+ round: 0 |
|
31 |
+}; |
|
32 |
+ |
|
33 |
+var validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'perspective', 'matrix', 'matrix3d']; |
|
34 |
+ |
|
35 |
+// Caching |
|
36 |
+ |
|
37 |
+var cache = { |
|
38 |
+ CSS: {}, |
|
39 |
+ springs: {} |
|
40 |
+}; |
|
41 |
+ |
|
42 |
+// Utils |
|
43 |
+ |
|
44 |
+function minMax(val, min, max) { |
|
45 |
+ return Math.min(Math.max(val, min), max); |
|
46 |
+} |
|
47 |
+ |
|
48 |
+function stringContains(str, text) { |
|
49 |
+ return str.indexOf(text) > -1; |
|
50 |
+} |
|
51 |
+ |
|
52 |
+function applyArguments(func, args) { |
|
53 |
+ return func.apply(null, args); |
|
54 |
+} |
|
55 |
+ |
|
56 |
+var is = { |
|
57 |
+ arr: function (a) { return Array.isArray(a); }, |
|
58 |
+ obj: function (a) { return stringContains(Object.prototype.toString.call(a), 'Object'); }, |
|
59 |
+ pth: function (a) { return is.obj(a) && a.hasOwnProperty('totalLength'); }, |
|
60 |
+ svg: function (a) { return a instanceof SVGElement; }, |
|
61 |
+ inp: function (a) { return a instanceof HTMLInputElement; }, |
|
62 |
+ dom: function (a) { return a.nodeType || is.svg(a); }, |
|
63 |
+ str: function (a) { return typeof a === 'string'; }, |
|
64 |
+ fnc: function (a) { return typeof a === 'function'; }, |
|
65 |
+ und: function (a) { return typeof a === 'undefined'; }, |
|
66 |
+ hex: function (a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a); }, |
|
67 |
+ rgb: function (a) { return /^rgb/.test(a); }, |
|
68 |
+ hsl: function (a) { return /^hsl/.test(a); }, |
|
69 |
+ col: function (a) { return (is.hex(a) || is.rgb(a) || is.hsl(a)); }, |
|
70 |
+ key: function (a) { return !defaultInstanceSettings.hasOwnProperty(a) && !defaultTweenSettings.hasOwnProperty(a) && a !== 'targets' && a !== 'keyframes'; } |
|
71 |
+}; |
|
72 |
+ |
|
73 |
+// Easings |
|
74 |
+ |
|
75 |
+function parseEasingParameters(string) { |
|
76 |
+ var match = /\(([^)]+)\)/.exec(string); |
|
77 |
+ return match ? match[1].split(',').map(function (p) { return parseFloat(p); }) : []; |
|
78 |
+} |
|
79 |
+ |
|
80 |
+// Spring solver inspired by Webkit Copyright © 2016 Apple Inc. All rights reserved. https://webkit.org/demos/spring/spring.js |
|
81 |
+ |
|
82 |
+function spring(string, duration) { |
|
83 |
+ |
|
84 |
+ var params = parseEasingParameters(string); |
|
85 |
+ var mass = minMax(is.und(params[0]) ? 1 : params[0], .1, 100); |
|
86 |
+ var stiffness = minMax(is.und(params[1]) ? 100 : params[1], .1, 100); |
|
87 |
+ var damping = minMax(is.und(params[2]) ? 10 : params[2], .1, 100); |
|
88 |
+ var velocity = minMax(is.und(params[3]) ? 0 : params[3], .1, 100); |
|
89 |
+ var w0 = Math.sqrt(stiffness / mass); |
|
90 |
+ var zeta = damping / (2 * Math.sqrt(stiffness * mass)); |
|
91 |
+ var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0; |
|
92 |
+ var a = 1; |
|
93 |
+ var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0; |
|
94 |
+ |
|
95 |
+ function solver(t) { |
|
96 |
+ var progress = duration ? (duration * t) / 1000 : t; |
|
97 |
+ if (zeta < 1) { |
|
98 |
+ progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress)); |
|
99 |
+ } else { |
|
100 |
+ progress = (a + b * progress) * Math.exp(-progress * w0); |
|
101 |
+ } |
|
102 |
+ if (t === 0 || t === 1) { return t; } |
|
103 |
+ return 1 - progress; |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ function getDuration() { |
|
107 |
+ var cached = cache.springs[string]; |
|
108 |
+ if (cached) { return cached; } |
|
109 |
+ var frame = 1/6; |
|
110 |
+ var elapsed = 0; |
|
111 |
+ var rest = 0; |
|
112 |
+ while(true) { |
|
113 |
+ elapsed += frame; |
|
114 |
+ if (solver(elapsed) === 1) { |
|
115 |
+ rest++; |
|
116 |
+ if (rest >= 16) { break; } |
|
117 |
+ } else { |
|
118 |
+ rest = 0; |
|
119 |
+ } |
|
120 |
+ } |
|
121 |
+ var duration = elapsed * frame * 1000; |
|
122 |
+ cache.springs[string] = duration; |
|
123 |
+ return duration; |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ return duration ? solver : getDuration; |
|
127 |
+ |
|
128 |
+} |
|
129 |
+ |
|
130 |
+// Basic steps easing implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function |
|
131 |
+ |
|
132 |
+function steps(steps) { |
|
133 |
+ if ( steps === void 0 ) steps = 10; |
|
134 |
+ |
|
135 |
+ return function (t) { return Math.ceil((minMax(t, 0.000001, 1)) * steps) * (1 / steps); }; |
|
136 |
+} |
|
137 |
+ |
|
138 |
+// BezierEasing https://github.com/gre/bezier-easing |
|
139 |
+ |
|
140 |
+var bezier = (function () { |
|
141 |
+ |
|
142 |
+ var kSplineTableSize = 11; |
|
143 |
+ var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); |
|
144 |
+ |
|
145 |
+ function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1 } |
|
146 |
+ function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1 } |
|
147 |
+ function C(aA1) { return 3.0 * aA1 } |
|
148 |
+ |
|
149 |
+ function calcBezier(aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT } |
|
150 |
+ function getSlope(aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1) } |
|
151 |
+ |
|
152 |
+ function binarySubdivide(aX, aA, aB, mX1, mX2) { |
|
153 |
+ var currentX, currentT, i = 0; |
|
154 |
+ do { |
|
155 |
+ currentT = aA + (aB - aA) / 2.0; |
|
156 |
+ currentX = calcBezier(currentT, mX1, mX2) - aX; |
|
157 |
+ if (currentX > 0.0) { aB = currentT; } else { aA = currentT; } |
|
158 |
+ } while (Math.abs(currentX) > 0.0000001 && ++i < 10); |
|
159 |
+ return currentT; |
|
160 |
+ } |
|
161 |
+ |
|
162 |
+ function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) { |
|
163 |
+ for (var i = 0; i < 4; ++i) { |
|
164 |
+ var currentSlope = getSlope(aGuessT, mX1, mX2); |
|
165 |
+ if (currentSlope === 0.0) { return aGuessT; } |
|
166 |
+ var currentX = calcBezier(aGuessT, mX1, mX2) - aX; |
|
167 |
+ aGuessT -= currentX / currentSlope; |
|
168 |
+ } |
|
169 |
+ return aGuessT; |
|
170 |
+ } |
|
171 |
+ |
|
172 |
+ function bezier(mX1, mY1, mX2, mY2) { |
|
173 |
+ |
|
174 |
+ if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { return; } |
|
175 |
+ var sampleValues = new Float32Array(kSplineTableSize); |
|
176 |
+ |
|
177 |
+ if (mX1 !== mY1 || mX2 !== mY2) { |
|
178 |
+ for (var i = 0; i < kSplineTableSize; ++i) { |
|
179 |
+ sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); |
|
180 |
+ } |
|
181 |
+ } |
|
182 |
+ |
|
183 |
+ function getTForX(aX) { |
|
184 |
+ |
|
185 |
+ var intervalStart = 0; |
|
186 |
+ var currentSample = 1; |
|
187 |
+ var lastSample = kSplineTableSize - 1; |
|
188 |
+ |
|
189 |
+ for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { |
|
190 |
+ intervalStart += kSampleStepSize; |
|
191 |
+ } |
|
192 |
+ |
|
193 |
+ --currentSample; |
|
194 |
+ |
|
195 |
+ var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); |
|
196 |
+ var guessForT = intervalStart + dist * kSampleStepSize; |
|
197 |
+ var initialSlope = getSlope(guessForT, mX1, mX2); |
|
198 |
+ |
|
199 |
+ if (initialSlope >= 0.001) { |
|
200 |
+ return newtonRaphsonIterate(aX, guessForT, mX1, mX2); |
|
201 |
+ } else if (initialSlope === 0.0) { |
|
202 |
+ return guessForT; |
|
203 |
+ } else { |
|
204 |
+ return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); |
|
205 |
+ } |
|
206 |
+ |
|
207 |
+ } |
|
208 |
+ |
|
209 |
+ return function (x) { |
|
210 |
+ if (mX1 === mY1 && mX2 === mY2) { return x; } |
|
211 |
+ if (x === 0 || x === 1) { return x; } |
|
212 |
+ return calcBezier(getTForX(x), mY1, mY2); |
|
213 |
+ } |
|
214 |
+ |
|
215 |
+ } |
|
216 |
+ |
|
217 |
+ return bezier; |
|
218 |
+ |
|
219 |
+})(); |
|
220 |
+ |
|
221 |
+var penner = (function () { |
|
222 |
+ |
|
223 |
+ // Based on jQuery UI's implemenation of easing equations from Robert Penner (http://www.robertpenner.com/easing) |
|
224 |
+ |
|
225 |
+ var eases = { linear: function () { return function (t) { return t; }; } }; |
|
226 |
+ |
|
227 |
+ var functionEasings = { |
|
228 |
+ Sine: function () { return function (t) { return 1 - Math.cos(t * Math.PI / 2); }; }, |
|
229 |
+ Circ: function () { return function (t) { return 1 - Math.sqrt(1 - t * t); }; }, |
|
230 |
+ Back: function () { return function (t) { return t * t * (3 * t - 2); }; }, |
|
231 |
+ Bounce: function () { return function (t) { |
|
232 |
+ var pow2, b = 4; |
|
233 |
+ while (t < (( pow2 = Math.pow(2, --b)) - 1) / 11) {} |
|
234 |
+ return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow(( pow2 * 3 - 2 ) / 22 - t, 2) |
|
235 |
+ }; }, |
|
236 |
+ Elastic: function (amplitude, period) { |
|
237 |
+ if ( amplitude === void 0 ) amplitude = 1; |
|
238 |
+ if ( period === void 0 ) period = .5; |
|
239 |
+ |
|
240 |
+ var a = minMax(amplitude, 1, 10); |
|
241 |
+ var p = minMax(period, .1, 2); |
|
242 |
+ return function (t) { |
|
243 |
+ return (t === 0 || t === 1) ? t : |
|
244 |
+ -a * Math.pow(2, 10 * (t - 1)) * Math.sin((((t - 1) - (p / (Math.PI * 2) * Math.asin(1 / a))) * (Math.PI * 2)) / p); |
|
245 |
+ } |
|
246 |
+ } |
|
247 |
+ }; |
|
248 |
+ |
|
249 |
+ var baseEasings = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo']; |
|
250 |
+ |
|
251 |
+ baseEasings.forEach(function (name, i) { |
|
252 |
+ functionEasings[name] = function () { return function (t) { return Math.pow(t, i + 2); }; }; |
|
253 |
+ }); |
|
254 |
+ |
|
255 |
+ Object.keys(functionEasings).forEach(function (name) { |
|
256 |
+ var easeIn = functionEasings[name]; |
|
257 |
+ eases['easeIn' + name] = easeIn; |
|
258 |
+ eases['easeOut' + name] = function (a, b) { return function (t) { return 1 - easeIn(a, b)(1 - t); }; }; |
|
259 |
+ eases['easeInOut' + name] = function (a, b) { return function (t) { return t < 0.5 ? easeIn(a, b)(t * 2) / 2 : |
|
260 |
+ 1 - easeIn(a, b)(t * -2 + 2) / 2; }; }; |
|
261 |
+ }); |
|
262 |
+ |
|
263 |
+ return eases; |
|
264 |
+ |
|
265 |
+})(); |
|
266 |
+ |
|
267 |
+function parseEasings(easing, duration) { |
|
268 |
+ if (is.fnc(easing)) { return easing; } |
|
269 |
+ var name = easing.split('(')[0]; |
|
270 |
+ var ease = penner[name]; |
|
271 |
+ var args = parseEasingParameters(easing); |
|
272 |
+ switch (name) { |
|
273 |
+ case 'spring' : return spring(easing, duration); |
|
274 |
+ case 'cubicBezier' : return applyArguments(bezier, args); |
|
275 |
+ case 'steps' : return applyArguments(steps, args); |
|
276 |
+ default : return applyArguments(ease, args); |
|
277 |
+ } |
|
278 |
+} |
|
279 |
+ |
|
280 |
+// Strings |
|
281 |
+ |
|
282 |
+function selectString(str) { |
|
283 |
+ try { |
|
284 |
+ var nodes = document.querySelectorAll(str); |
|
285 |
+ return nodes; |
|
286 |
+ } catch(e) { |
|
287 |
+ return; |
|
288 |
+ } |
|
289 |
+} |
|
290 |
+ |
|
291 |
+// Arrays |
|
292 |
+ |
|
293 |
+function filterArray(arr, callback) { |
|
294 |
+ var len = arr.length; |
|
295 |
+ var thisArg = arguments.length >= 2 ? arguments[1] : void 0; |
|
296 |
+ var result = []; |
|
297 |
+ for (var i = 0; i < len; i++) { |
|
298 |
+ if (i in arr) { |
|
299 |
+ var val = arr[i]; |
|
300 |
+ if (callback.call(thisArg, val, i, arr)) { |
|
301 |
+ result.push(val); |
|
302 |
+ } |
|
303 |
+ } |
|
304 |
+ } |
|
305 |
+ return result; |
|
306 |
+} |
|
307 |
+ |
|
308 |
+function flattenArray(arr) { |
|
309 |
+ return arr.reduce(function (a, b) { return a.concat(is.arr(b) ? flattenArray(b) : b); }, []); |
|
310 |
+} |
|
311 |
+ |
|
312 |
+function toArray(o) { |
|
313 |
+ if (is.arr(o)) { return o; } |
|
314 |
+ if (is.str(o)) { o = selectString(o) || o; } |
|
315 |
+ if (o instanceof NodeList || o instanceof HTMLCollection) { return [].slice.call(o); } |
|
316 |
+ return [o]; |
|
317 |
+} |
|
318 |
+ |
|
319 |
+function arrayContains(arr, val) { |
|
320 |
+ return arr.some(function (a) { return a === val; }); |
|
321 |
+} |
|
322 |
+ |
|
323 |
+// Objects |
|
324 |
+ |
|
325 |
+function cloneObject(o) { |
|
326 |
+ var clone = {}; |
|
327 |
+ for (var p in o) { clone[p] = o[p]; } |
|
328 |
+ return clone; |
|
329 |
+} |
|
330 |
+ |
|
331 |
+function replaceObjectProps(o1, o2) { |
|
332 |
+ var o = cloneObject(o1); |
|
333 |
+ for (var p in o1) { o[p] = o2.hasOwnProperty(p) ? o2[p] : o1[p]; } |
|
334 |
+ return o; |
|
335 |
+} |
|
336 |
+ |
|
337 |
+function mergeObjects(o1, o2) { |
|
338 |
+ var o = cloneObject(o1); |
|
339 |
+ for (var p in o2) { o[p] = is.und(o1[p]) ? o2[p] : o1[p]; } |
|
340 |
+ return o; |
|
341 |
+} |
|
342 |
+ |
|
343 |
+// Colors |
|
344 |
+ |
|
345 |
+function rgbToRgba(rgbValue) { |
|
346 |
+ var rgb = /rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g.exec(rgbValue); |
|
347 |
+ return rgb ? ("rgba(" + (rgb[1]) + ",1)") : rgbValue; |
|
348 |
+} |
|
349 |
+ |
|
350 |
+function hexToRgba(hexValue) { |
|
351 |
+ var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
|
352 |
+ var hex = hexValue.replace(rgx, function (m, r, g, b) { return r + r + g + g + b + b; } ); |
|
353 |
+ var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); |
|
354 |
+ var r = parseInt(rgb[1], 16); |
|
355 |
+ var g = parseInt(rgb[2], 16); |
|
356 |
+ var b = parseInt(rgb[3], 16); |
|
357 |
+ return ("rgba(" + r + "," + g + "," + b + ",1)"); |
|
358 |
+} |
|
359 |
+ |
|
360 |
+function hslToRgba(hslValue) { |
|
361 |
+ var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(hslValue); |
|
362 |
+ var h = parseInt(hsl[1], 10) / 360; |
|
363 |
+ var s = parseInt(hsl[2], 10) / 100; |
|
364 |
+ var l = parseInt(hsl[3], 10) / 100; |
|
365 |
+ var a = hsl[4] || 1; |
|
366 |
+ function hue2rgb(p, q, t) { |
|
367 |
+ if (t < 0) { t += 1; } |
|
368 |
+ if (t > 1) { t -= 1; } |
|
369 |
+ if (t < 1/6) { return p + (q - p) * 6 * t; } |
|
370 |
+ if (t < 1/2) { return q; } |
|
371 |
+ if (t < 2/3) { return p + (q - p) * (2/3 - t) * 6; } |
|
372 |
+ return p; |
|
373 |
+ } |
|
374 |
+ var r, g, b; |
|
375 |
+ if (s == 0) { |
|
376 |
+ r = g = b = l; |
|
377 |
+ } else { |
|
378 |
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s; |
|
379 |
+ var p = 2 * l - q; |
|
380 |
+ r = hue2rgb(p, q, h + 1/3); |
|
381 |
+ g = hue2rgb(p, q, h); |
|
382 |
+ b = hue2rgb(p, q, h - 1/3); |
|
383 |
+ } |
|
384 |
+ return ("rgba(" + (r * 255) + "," + (g * 255) + "," + (b * 255) + "," + a + ")"); |
|
385 |
+} |
|
386 |
+ |
|
387 |
+function colorToRgb(val) { |
|
388 |
+ if (is.rgb(val)) { return rgbToRgba(val); } |
|
389 |
+ if (is.hex(val)) { return hexToRgba(val); } |
|
390 |
+ if (is.hsl(val)) { return hslToRgba(val); } |
|
391 |
+} |
|
392 |
+ |
|
393 |
+// Units |
|
394 |
+ |
|
395 |
+function getUnit(val) { |
|
396 |
+ var split = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(val); |
|
397 |
+ if (split) { return split[1]; } |
|
398 |
+} |
|
399 |
+ |
|
400 |
+function getTransformUnit(propName) { |
|
401 |
+ if (stringContains(propName, 'translate') || propName === 'perspective') { return 'px'; } |
|
402 |
+ if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) { return 'deg'; } |
|
403 |
+} |
|
404 |
+ |
|
405 |
+// Values |
|
406 |
+ |
|
407 |
+function getFunctionValue(val, animatable) { |
|
408 |
+ if (!is.fnc(val)) { return val; } |
|
409 |
+ return val(animatable.target, animatable.id, animatable.total); |
|
410 |
+} |
|
411 |
+ |
|
412 |
+function getAttribute(el, prop) { |
|
413 |
+ return el.getAttribute(prop); |
|
414 |
+} |
|
415 |
+ |
|
416 |
+function convertPxToUnit(el, value, unit) { |
|
417 |
+ var valueUnit = getUnit(value); |
|
418 |
+ if (arrayContains([unit, 'deg', 'rad', 'turn'], valueUnit)) { return value; } |
|
419 |
+ var cached = cache.CSS[value + unit]; |
|
420 |
+ if (!is.und(cached)) { return cached; } |
|
421 |
+ var baseline = 100; |
|
422 |
+ var tempEl = document.createElement(el.tagName); |
|
423 |
+ var parentEl = (el.parentNode && (el.parentNode !== document)) ? el.parentNode : document.body; |
|
424 |
+ parentEl.appendChild(tempEl); |
|
425 |
+ tempEl.style.position = 'absolute'; |
|
426 |
+ tempEl.style.width = baseline + unit; |
|
427 |
+ var factor = baseline / tempEl.offsetWidth; |
|
428 |
+ parentEl.removeChild(tempEl); |
|
429 |
+ var convertedUnit = factor * parseFloat(value); |
|
430 |
+ cache.CSS[value + unit] = convertedUnit; |
|
431 |
+ return convertedUnit; |
|
432 |
+} |
|
433 |
+ |
|
434 |
+function getCSSValue(el, prop, unit) { |
|
435 |
+ if (prop in el.style) { |
|
436 |
+ var uppercasePropName = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
|
437 |
+ var value = el.style[prop] || getComputedStyle(el).getPropertyValue(uppercasePropName) || '0'; |
|
438 |
+ return unit ? convertPxToUnit(el, value, unit) : value; |
|
439 |
+ } |
|
440 |
+} |
|
441 |
+ |
|
442 |
+function getAnimationType(el, prop) { |
|
443 |
+ if (is.dom(el) && !is.inp(el) && (getAttribute(el, prop) || (is.svg(el) && el[prop]))) { return 'attribute'; } |
|
444 |
+ if (is.dom(el) && arrayContains(validTransforms, prop)) { return 'transform'; } |
|
445 |
+ if (is.dom(el) && (prop !== 'transform' && getCSSValue(el, prop))) { return 'css'; } |
|
446 |
+ if (el[prop] != null) { return 'object'; } |
|
447 |
+} |
|
448 |
+ |
|
449 |
+function getElementTransforms(el) { |
|
450 |
+ if (!is.dom(el)) { return; } |
|
451 |
+ var str = el.style.transform || ''; |
|
452 |
+ var reg = /(\w+)\(([^)]*)\)/g; |
|
453 |
+ var transforms = new Map(); |
|
454 |
+ var m; while (m = reg.exec(str)) { transforms.set(m[1], m[2]); } |
|
455 |
+ return transforms; |
|
456 |
+} |
|
457 |
+ |
|
458 |
+function getTransformValue(el, propName, animatable, unit) { |
|
459 |
+ var defaultVal = stringContains(propName, 'scale') ? 1 : 0 + getTransformUnit(propName); |
|
460 |
+ var value = getElementTransforms(el).get(propName) || defaultVal; |
|
461 |
+ if (animatable) { |
|
462 |
+ animatable.transforms.list.set(propName, value); |
|
463 |
+ animatable.transforms['last'] = propName; |
|
464 |
+ } |
|
465 |
+ return unit ? convertPxToUnit(el, value, unit) : value; |
|
466 |
+} |
|
467 |
+ |
|
468 |
+function getOriginalTargetValue(target, propName, unit, animatable) { |
|
469 |
+ switch (getAnimationType(target, propName)) { |
|
470 |
+ case 'transform': return getTransformValue(target, propName, animatable, unit); |
|
471 |
+ case 'css': return getCSSValue(target, propName, unit); |
|
472 |
+ case 'attribute': return getAttribute(target, propName); |
|
473 |
+ default: return target[propName] || 0; |
|
474 |
+ } |
|
475 |
+} |
|
476 |
+ |
|
477 |
+function getRelativeValue(to, from) { |
|
478 |
+ var operator = /^(\*=|\+=|-=)/.exec(to); |
|
479 |
+ if (!operator) { return to; } |
|
480 |
+ var u = getUnit(to) || 0; |
|
481 |
+ var x = parseFloat(from); |
|
482 |
+ var y = parseFloat(to.replace(operator[0], '')); |
|
483 |
+ switch (operator[0][0]) { |
|
484 |
+ case '+': return x + y + u; |
|
485 |
+ case '-': return x - y + u; |
|
486 |
+ case '*': return x * y + u; |
|
487 |
+ } |
|
488 |
+} |
|
489 |
+ |
|
490 |
+function validateValue(val, unit) { |
|
491 |
+ if (is.col(val)) { return colorToRgb(val); } |
|
492 |
+ if (/\s/g.test(val)) { return val; } |
|
493 |
+ var originalUnit = getUnit(val); |
|
494 |
+ var unitLess = originalUnit ? val.substr(0, val.length - originalUnit.length) : val; |
|
495 |
+ if (unit) { return unitLess + unit; } |
|
496 |
+ return unitLess; |
|
497 |
+} |
|
498 |
+ |
|
499 |
+// getTotalLength() equivalent for circle, rect, polyline, polygon and line shapes |
|
500 |
+// adapted from https://gist.github.com/SebLambla/3e0550c496c236709744 |
|
501 |
+ |
|
502 |
+function getDistance(p1, p2) { |
|
503 |
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)); |
|
504 |
+} |
|
505 |
+ |
|
506 |
+function getCircleLength(el) { |
|
507 |
+ return Math.PI * 2 * getAttribute(el, 'r'); |
|
508 |
+} |
|
509 |
+ |
|
510 |
+function getRectLength(el) { |
|
511 |
+ return (getAttribute(el, 'width') * 2) + (getAttribute(el, 'height') * 2); |
|
512 |
+} |
|
513 |
+ |
|
514 |
+function getLineLength(el) { |
|
515 |
+ return getDistance( |
|
516 |
+ {x: getAttribute(el, 'x1'), y: getAttribute(el, 'y1')}, |
|
517 |
+ {x: getAttribute(el, 'x2'), y: getAttribute(el, 'y2')} |
|
518 |
+ ); |
|
519 |
+} |
|
520 |
+ |
|
521 |
+function getPolylineLength(el) { |
|
522 |
+ var points = el.points; |
|
523 |
+ var totalLength = 0; |
|
524 |
+ var previousPos; |
|
525 |
+ for (var i = 0 ; i < points.numberOfItems; i++) { |
|
526 |
+ var currentPos = points.getItem(i); |
|
527 |
+ if (i > 0) { totalLength += getDistance(previousPos, currentPos); } |
|
528 |
+ previousPos = currentPos; |
|
529 |
+ } |
|
530 |
+ return totalLength; |
|
531 |
+} |
|
532 |
+ |
|
533 |
+function getPolygonLength(el) { |
|
534 |
+ var points = el.points; |
|
535 |
+ return getPolylineLength(el) + getDistance(points.getItem(points.numberOfItems - 1), points.getItem(0)); |
|
536 |
+} |
|
537 |
+ |
|
538 |
+// Path animation |
|
539 |
+ |
|
540 |
+function getTotalLength(el) { |
|
541 |
+ if (el.getTotalLength) { return el.getTotalLength(); } |
|
542 |
+ switch(el.tagName.toLowerCase()) { |
|
543 |
+ case 'circle': return getCircleLength(el); |
|
544 |
+ case 'rect': return getRectLength(el); |
|
545 |
+ case 'line': return getLineLength(el); |
|
546 |
+ case 'polyline': return getPolylineLength(el); |
|
547 |
+ case 'polygon': return getPolygonLength(el); |
|
548 |
+ } |
|
549 |
+} |
|
550 |
+ |
|
551 |
+function setDashoffset(el) { |
|
552 |
+ var pathLength = getTotalLength(el); |
|
553 |
+ el.setAttribute('stroke-dasharray', pathLength); |
|
554 |
+ return pathLength; |
|
555 |
+} |
|
556 |
+ |
|
557 |
+// Motion path |
|
558 |
+ |
|
559 |
+function getParentSvgEl(el) { |
|
560 |
+ var parentEl = el.parentNode; |
|
561 |
+ while (is.svg(parentEl)) { |
|
562 |
+ if (!is.svg(parentEl.parentNode)) { break; } |
|
563 |
+ parentEl = parentEl.parentNode; |
|
564 |
+ } |
|
565 |
+ return parentEl; |
|
566 |
+} |
|
567 |
+ |
|
568 |
+function getParentSvg(pathEl, svgData) { |
|
569 |
+ var svg = svgData || {}; |
|
570 |
+ var parentSvgEl = svg.el || getParentSvgEl(pathEl); |
|
571 |
+ var rect = parentSvgEl.getBoundingClientRect(); |
|
572 |
+ var viewBoxAttr = getAttribute(parentSvgEl, 'viewBox'); |
|
573 |
+ var width = rect.width; |
|
574 |
+ var height = rect.height; |
|
575 |
+ var viewBox = svg.viewBox || (viewBoxAttr ? viewBoxAttr.split(' ') : [0, 0, width, height]); |
|
576 |
+ return { |
|
577 |
+ el: parentSvgEl, |
|
578 |
+ viewBox: viewBox, |
|
579 |
+ x: viewBox[0] / 1, |
|
580 |
+ y: viewBox[1] / 1, |
|
581 |
+ w: width / viewBox[2], |
|
582 |
+ h: height / viewBox[3] |
|
583 |
+ } |
|
584 |
+} |
|
585 |
+ |
|
586 |
+function getPath(path, percent) { |
|
587 |
+ var pathEl = is.str(path) ? selectString(path)[0] : path; |
|
588 |
+ var p = percent || 100; |
|
589 |
+ return function(property) { |
|
590 |
+ return { |
|
591 |
+ property: property, |
|
592 |
+ el: pathEl, |
|
593 |
+ svg: getParentSvg(pathEl), |
|
594 |
+ totalLength: getTotalLength(pathEl) * (p / 100) |
|
595 |
+ } |
|
596 |
+ } |
|
597 |
+} |
|
598 |
+ |
|
599 |
+function getPathProgress(path, progress) { |
|
600 |
+ function point(offset) { |
|
601 |
+ if ( offset === void 0 ) offset = 0; |
|
602 |
+ |
|
603 |
+ var l = progress + offset >= 1 ? progress + offset : 0; |
|
604 |
+ return path.el.getPointAtLength(l); |
|
605 |
+ } |
|
606 |
+ var svg = getParentSvg(path.el, path.svg); |
|
607 |
+ var p = point(); |
|
608 |
+ var p0 = point(-1); |
|
609 |
+ var p1 = point(+1); |
|
610 |
+ switch (path.property) { |
|
611 |
+ case 'x': return (p.x - svg.x) * svg.w; |
|
612 |
+ case 'y': return (p.y - svg.y) * svg.h; |
|
613 |
+ case 'angle': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI; |
|
614 |
+ } |
|
615 |
+} |
|
616 |
+ |
|
617 |
+// Decompose value |
|
618 |
+ |
|
619 |
+function decomposeValue(val, unit) { |
|
620 |
+ // const rgx = /-?\d*\.?\d+/g; // handles basic numbers |
|
621 |
+ // const rgx = /[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation |
|
622 |
+ var rgx = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation |
|
623 |
+ var value = validateValue((is.pth(val) ? val.totalLength : val), unit) + ''; |
|
624 |
+ return { |
|
625 |
+ original: value, |
|
626 |
+ numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0], |
|
627 |
+ strings: (is.str(val) || unit) ? value.split(rgx) : [] |
|
628 |
+ } |
|
629 |
+} |
|
630 |
+ |
|
631 |
+// Animatables |
|
632 |
+ |
|
633 |
+function parseTargets(targets) { |
|
634 |
+ var targetsArray = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : []; |
|
635 |
+ return filterArray(targetsArray, function (item, pos, self) { return self.indexOf(item) === pos; }); |
|
636 |
+} |
|
637 |
+ |
|
638 |
+function getAnimatables(targets) { |
|
639 |
+ var parsed = parseTargets(targets); |
|
640 |
+ return parsed.map(function (t, i) { |
|
641 |
+ return {target: t, id: i, total: parsed.length, transforms: { list: getElementTransforms(t) } }; |
|
642 |
+ }); |
|
643 |
+} |
|
644 |
+ |
|
645 |
+// Properties |
|
646 |
+ |
|
647 |
+function normalizePropertyTweens(prop, tweenSettings) { |
|
648 |
+ var settings = cloneObject(tweenSettings); |
|
649 |
+ // Override duration if easing is a spring |
|
650 |
+ if (/^spring/.test(settings.easing)) { settings.duration = spring(settings.easing); } |
|
651 |
+ if (is.arr(prop)) { |
|
652 |
+ var l = prop.length; |
|
653 |
+ var isFromTo = (l === 2 && !is.obj(prop[0])); |
|
654 |
+ if (!isFromTo) { |
|
655 |
+ // Duration divided by the number of tweens |
|
656 |
+ if (!is.fnc(tweenSettings.duration)) { settings.duration = tweenSettings.duration / l; } |
|
657 |
+ } else { |
|
658 |
+ // Transform [from, to] values shorthand to a valid tween value |
|
659 |
+ prop = {value: prop}; |
|
660 |
+ } |
|
661 |
+ } |
|
662 |
+ var propArray = is.arr(prop) ? prop : [prop]; |
|
663 |
+ return propArray.map(function (v, i) { |
|
664 |
+ var obj = (is.obj(v) && !is.pth(v)) ? v : {value: v}; |
|
665 |
+ // Default delay value should only be applied to the first tween |
|
666 |
+ if (is.und(obj.delay)) { obj.delay = !i ? tweenSettings.delay : 0; } |
|
667 |
+ // Default endDelay value should only be applied to the last tween |
|
668 |
+ if (is.und(obj.endDelay)) { obj.endDelay = i === propArray.length - 1 ? tweenSettings.endDelay : 0; } |
|
669 |
+ return obj; |
|
670 |
+ }).map(function (k) { return mergeObjects(k, settings); }); |
|
671 |
+} |
|
672 |
+ |
|
673 |
+ |
|
674 |
+function flattenKeyframes(keyframes) { |
|
675 |
+ var propertyNames = filterArray(flattenArray(keyframes.map(function (key) { return Object.keys(key); })), function (p) { return is.key(p); }) |
|
676 |
+ .reduce(function (a,b) { if (a.indexOf(b) < 0) { a.push(b); } return a; }, []); |
|
677 |
+ var properties = {}; |
|
678 |
+ var loop = function ( i ) { |
|
679 |
+ var propName = propertyNames[i]; |
|
680 |
+ properties[propName] = keyframes.map(function (key) { |
|
681 |
+ var newKey = {}; |
|
682 |
+ for (var p in key) { |
|
683 |
+ if (is.key(p)) { |
|
684 |
+ if (p == propName) { newKey.value = key[p]; } |
|
685 |
+ } else { |
|
686 |
+ newKey[p] = key[p]; |
|
687 |
+ } |
|
688 |
+ } |
|
689 |
+ return newKey; |
|
690 |
+ }); |
|
691 |
+ }; |
|
692 |
+ |
|
693 |
+ for (var i = 0; i < propertyNames.length; i++) loop( i ); |
|
694 |
+ return properties; |
|
695 |
+} |
|
696 |
+ |
|
697 |
+function getProperties(tweenSettings, params) { |
|
698 |
+ var properties = []; |
|
699 |
+ var keyframes = params.keyframes; |
|
700 |
+ if (keyframes) { params = mergeObjects(flattenKeyframes(keyframes), params); } |
|
701 |
+ for (var p in params) { |
|
702 |
+ if (is.key(p)) { |
|
703 |
+ properties.push({ |
|
704 |
+ name: p, |
|
705 |
+ tweens: normalizePropertyTweens(params[p], tweenSettings) |
|
706 |
+ }); |
|
707 |
+ } |
|
708 |
+ } |
|
709 |
+ return properties; |
|
710 |
+} |
|
711 |
+ |
|
712 |
+// Tweens |
|
713 |
+ |
|
714 |
+function normalizeTweenValues(tween, animatable) { |
|
715 |
+ var t = {}; |
|
716 |
+ for (var p in tween) { |
|
717 |
+ var value = getFunctionValue(tween[p], animatable); |
|
718 |
+ if (is.arr(value)) { |
|
719 |
+ value = value.map(function (v) { return getFunctionValue(v, animatable); }); |
|
720 |
+ if (value.length === 1) { value = value[0]; } |
|
721 |
+ } |
|
722 |
+ t[p] = value; |
|
723 |
+ } |
|
724 |
+ t.duration = parseFloat(t.duration); |
|
725 |
+ t.delay = parseFloat(t.delay); |
|
726 |
+ return t; |
|
727 |
+} |
|
728 |
+ |
|
729 |
+function normalizeTweens(prop, animatable) { |
|
730 |
+ var previousTween; |
|
731 |
+ return prop.tweens.map(function (t) { |
|
732 |
+ var tween = normalizeTweenValues(t, animatable); |
|
733 |
+ var tweenValue = tween.value; |
|
734 |
+ var to = is.arr(tweenValue) ? tweenValue[1] : tweenValue; |
|
735 |
+ var toUnit = getUnit(to); |
|
736 |
+ var originalValue = getOriginalTargetValue(animatable.target, prop.name, toUnit, animatable); |
|
737 |
+ var previousValue = previousTween ? previousTween.to.original : originalValue; |
|
738 |
+ var from = is.arr(tweenValue) ? tweenValue[0] : previousValue; |
|
739 |
+ var fromUnit = getUnit(from) || getUnit(originalValue); |
|
740 |
+ var unit = toUnit || fromUnit; |
|
741 |
+ if (is.und(to)) { to = previousValue; } |
|
742 |
+ tween.from = decomposeValue(from, unit); |
|
743 |
+ tween.to = decomposeValue(getRelativeValue(to, from), unit); |
|
744 |
+ tween.start = previousTween ? previousTween.end : 0; |
|
745 |
+ tween.end = tween.start + tween.delay + tween.duration + tween.endDelay; |
|
746 |
+ tween.easing = parseEasings(tween.easing, tween.duration); |
|
747 |
+ tween.isPath = is.pth(tweenValue); |
|
748 |
+ tween.isColor = is.col(tween.from.original); |
|
749 |
+ if (tween.isColor) { tween.round = 1; } |
|
750 |
+ previousTween = tween; |
|
751 |
+ return tween; |
|
752 |
+ }); |
|
753 |
+} |
|
754 |
+ |
|
755 |
+// Tween progress |
|
756 |
+ |
|
757 |
+var setProgressValue = { |
|
758 |
+ css: function (t, p, v) { return t.style[p] = v; }, |
|
759 |
+ attribute: function (t, p, v) { return t.setAttribute(p, v); }, |
|
760 |
+ object: function (t, p, v) { return t[p] = v; }, |
|
761 |
+ transform: function (t, p, v, transforms, manual) { |
|
762 |
+ transforms.list.set(p, v); |
|
763 |
+ if (p === transforms.last || manual) { |
|
764 |
+ var str = ''; |
|
765 |
+ transforms.list.forEach(function (value, prop) { str += prop + "(" + value + ") "; }); |
|
766 |
+ t.style.transform = str; |
|
767 |
+ } |
|
768 |
+ } |
|
769 |
+}; |
|
770 |
+ |
|
771 |
+// Set Value helper |
|
772 |
+ |
|
773 |
+function setTargetsValue(targets, properties) { |
|
774 |
+ var animatables = getAnimatables(targets); |
|
775 |
+ animatables.forEach(function (animatable) { |
|
776 |
+ for (var property in properties) { |
|
777 |
+ var value = getFunctionValue(properties[property], animatable); |
|
778 |
+ var target = animatable.target; |
|
779 |
+ var valueUnit = getUnit(value); |
|
780 |
+ var originalValue = getOriginalTargetValue(target, property, valueUnit, animatable); |
|
781 |
+ var unit = valueUnit || getUnit(originalValue); |
|
782 |
+ var to = getRelativeValue(validateValue(value, unit), originalValue); |
|
783 |
+ var animType = getAnimationType(target, property); |
|
784 |
+ setProgressValue[animType](target, property, to, animatable.transforms, true); |
|
785 |
+ } |
|
786 |
+ }); |
|
787 |
+} |
|
788 |
+ |
|
789 |
+// Animations |
|
790 |
+ |
|
791 |
+function createAnimation(animatable, prop) { |
|
792 |
+ var animType = getAnimationType(animatable.target, prop.name); |
|
793 |
+ if (animType) { |
|
794 |
+ var tweens = normalizeTweens(prop, animatable); |
|
795 |
+ var lastTween = tweens[tweens.length - 1]; |
|
796 |
+ return { |
|
797 |
+ type: animType, |
|
798 |
+ property: prop.name, |
|
799 |
+ animatable: animatable, |
|
800 |
+ tweens: tweens, |
|
801 |
+ duration: lastTween.end, |
|
802 |
+ delay: tweens[0].delay, |
|
803 |
+ endDelay: lastTween.endDelay |
|
804 |
+ } |
|
805 |
+ } |
|
806 |
+} |
|
807 |
+ |
|
808 |
+function getAnimations(animatables, properties) { |
|
809 |
+ return filterArray(flattenArray(animatables.map(function (animatable) { |
|
810 |
+ return properties.map(function (prop) { |
|
811 |
+ return createAnimation(animatable, prop); |
|
812 |
+ }); |
|
813 |
+ })), function (a) { return !is.und(a); }); |
|
814 |
+} |
|
815 |
+ |
|
816 |
+// Create Instance |
|
817 |
+ |
|
818 |
+function getInstanceTimings(animations, tweenSettings) { |
|
819 |
+ var animLength = animations.length; |
|
820 |
+ var getTlOffset = function (anim) { return anim.timelineOffset ? anim.timelineOffset : 0; }; |
|
821 |
+ var timings = {}; |
|
822 |
+ timings.duration = animLength ? Math.max.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.duration; })) : tweenSettings.duration; |
|
823 |
+ timings.delay = animLength ? Math.min.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.delay; })) : tweenSettings.delay; |
|
824 |
+ timings.endDelay = animLength ? timings.duration - Math.max.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.duration - anim.endDelay; })) : tweenSettings.endDelay; |
|
825 |
+ return timings; |
|
826 |
+} |
|
827 |
+ |
|
828 |
+var instanceID = 0; |
|
829 |
+ |
|
830 |
+function createNewInstance(params) { |
|
831 |
+ var instanceSettings = replaceObjectProps(defaultInstanceSettings, params); |
|
832 |
+ var tweenSettings = replaceObjectProps(defaultTweenSettings, params); |
|
833 |
+ var properties = getProperties(tweenSettings, params); |
|
834 |
+ var animatables = getAnimatables(params.targets); |
|
835 |
+ var animations = getAnimations(animatables, properties); |
|
836 |
+ var timings = getInstanceTimings(animations, tweenSettings); |
|
837 |
+ var id = instanceID; |
|
838 |
+ instanceID++; |
|
839 |
+ return mergeObjects(instanceSettings, { |
|
840 |
+ id: id, |
|
841 |
+ children: [], |
|
842 |
+ animatables: animatables, |
|
843 |
+ animations: animations, |
|
844 |
+ duration: timings.duration, |
|
845 |
+ delay: timings.delay, |
|
846 |
+ endDelay: timings.endDelay |
|
847 |
+ }); |
|
848 |
+} |
|
849 |
+ |
|
850 |
+// Core |
|
851 |
+ |
|
852 |
+var activeInstances = []; |
|
853 |
+var pausedInstances = []; |
|
854 |
+var raf; |
|
855 |
+ |
|
856 |
+var engine = (function () { |
|
857 |
+ function play() { |
|
858 |
+ raf = requestAnimationFrame(step); |
|
859 |
+ } |
|
860 |
+ function step(t) { |
|
861 |
+ var activeInstancesLength = activeInstances.length; |
|
862 |
+ if (activeInstancesLength) { |
|
863 |
+ var i = 0; |
|
864 |
+ while (i < activeInstancesLength) { |
|
865 |
+ var activeInstance = activeInstances[i]; |
|
866 |
+ if (!activeInstance.paused) { |
|
867 |
+ activeInstance.tick(t); |
|
868 |
+ } else { |
|
869 |
+ var instanceIndex = activeInstances.indexOf(activeInstance); |
|
870 |
+ if (instanceIndex > -1) { |
|
871 |
+ activeInstances.splice(instanceIndex, 1); |
|
872 |
+ activeInstancesLength = activeInstances.length; |
|
873 |
+ } |
|
874 |
+ } |
|
875 |
+ i++; |
|
876 |
+ } |
|
877 |
+ play(); |
|
878 |
+ } else { |
|
879 |
+ raf = cancelAnimationFrame(raf); |
|
880 |
+ } |
|
881 |
+ } |
|
882 |
+ return play; |
|
883 |
+})(); |
|
884 |
+ |
|
885 |
+function handleVisibilityChange() { |
|
886 |
+ if (document.hidden) { |
|
887 |
+ activeInstances.forEach(function (ins) { return ins.pause(); }); |
|
888 |
+ pausedInstances = activeInstances.slice(0); |
|
889 |
+ anime.running = activeInstances = []; |
|
890 |
+ } else { |
|
891 |
+ pausedInstances.forEach(function (ins) { return ins.play(); }); |
|
892 |
+ } |
|
893 |
+} |
|
894 |
+ |
|
895 |
+if (typeof document !== 'undefined') { |
|
896 |
+ document.addEventListener('visibilitychange', handleVisibilityChange); |
|
897 |
+} |
|
898 |
+ |
|
899 |
+// Public Instance |
|
900 |
+ |
|
901 |
+function anime(params) { |
|
902 |
+ if ( params === void 0 ) params = {}; |
|
903 |
+ |
|
904 |
+ |
|
905 |
+ var startTime = 0, lastTime = 0, now = 0; |
|
906 |
+ var children, childrenLength = 0; |
|
907 |
+ var resolve = null; |
|
908 |
+ |
|
909 |
+ function makePromise(instance) { |
|
910 |
+ var promise = window.Promise && new Promise(function (_resolve) { return resolve = _resolve; }); |
|
911 |
+ instance.finished = promise; |
|
912 |
+ return promise; |
|
913 |
+ } |
|
914 |
+ |
|
915 |
+ var instance = createNewInstance(params); |
|
916 |
+ var promise = makePromise(instance); |
|
917 |
+ |
|
918 |
+ function toggleInstanceDirection() { |
|
919 |
+ var direction = instance.direction; |
|
920 |
+ if (direction !== 'alternate') { |
|
921 |
+ instance.direction = direction !== 'normal' ? 'normal' : 'reverse'; |
|
922 |
+ } |
|
923 |
+ instance.reversed = !instance.reversed; |
|
924 |
+ children.forEach(function (child) { return child.reversed = instance.reversed; }); |
|
925 |
+ } |
|
926 |
+ |
|
927 |
+ function adjustTime(time) { |
|
928 |
+ return instance.reversed ? instance.duration - time : time; |
|
929 |
+ } |
|
930 |
+ |
|
931 |
+ function resetTime() { |
|
932 |
+ startTime = 0; |
|
933 |
+ lastTime = adjustTime(instance.currentTime) * (1 / anime.speed); |
|
934 |
+ } |
|
935 |
+ |
|
936 |
+ function seekChild(time, child) { |
|
937 |
+ if (child) { child.seek(time - child.timelineOffset); } |
|
938 |
+ } |
|
939 |
+ |
|
940 |
+ function syncInstanceChildren(time) { |
|
941 |
+ if (!instance.reversePlayback) { |
|
942 |
+ for (var i = 0; i < childrenLength; i++) { seekChild(time, children[i]); } |
|
943 |
+ } else { |
|
944 |
+ for (var i$1 = childrenLength; i$1--;) { seekChild(time, children[i$1]); } |
|
945 |
+ } |
|
946 |
+ } |
|
947 |
+ |
|
948 |
+ function setAnimationsProgress(insTime) { |
|
949 |
+ var i = 0; |
|
950 |
+ var animations = instance.animations; |
|
951 |
+ var animationsLength = animations.length; |
|
952 |
+ while (i < animationsLength) { |
|
953 |
+ var anim = animations[i]; |
|
954 |
+ var animatable = anim.animatable; |
|
955 |
+ var tweens = anim.tweens; |
|
956 |
+ var tweenLength = tweens.length - 1; |
|
957 |
+ var tween = tweens[tweenLength]; |
|
958 |
+ // Only check for keyframes if there is more than one tween |
|
959 |
+ if (tweenLength) { tween = filterArray(tweens, function (t) { return (insTime < t.end); })[0] || tween; } |
|
960 |
+ var elapsed = minMax(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration; |
|
961 |
+ var eased = isNaN(elapsed) ? 1 : tween.easing(elapsed); |
|
962 |
+ var strings = tween.to.strings; |
|
963 |
+ var round = tween.round; |
|
964 |
+ var numbers = []; |
|
965 |
+ var toNumbersLength = tween.to.numbers.length; |
|
966 |
+ var progress = (void 0); |
|
967 |
+ for (var n = 0; n < toNumbersLength; n++) { |
|
968 |
+ var value = (void 0); |
|
969 |
+ var toNumber = tween.to.numbers[n]; |
|
970 |
+ var fromNumber = tween.from.numbers[n] || 0; |
|
971 |
+ if (!tween.isPath) { |
|
972 |
+ value = fromNumber + (eased * (toNumber - fromNumber)); |
|
973 |
+ } else { |
|
974 |
+ value = getPathProgress(tween.value, eased * toNumber); |
|
975 |
+ } |
|
976 |
+ if (round) { |
|
977 |
+ if (!(tween.isColor && n > 2)) { |
|
978 |
+ value = Math.round(value * round) / round; |
|
979 |
+ } |
|
980 |
+ } |
|
981 |
+ numbers.push(value); |
|
982 |
+ } |
|
983 |
+ // Manual Array.reduce for better performances |
|
984 |
+ var stringsLength = strings.length; |
|
985 |
+ if (!stringsLength) { |
|
986 |
+ progress = numbers[0]; |
|
987 |
+ } else { |
|
988 |
+ progress = strings[0]; |
|
989 |
+ for (var s = 0; s < stringsLength; s++) { |
|
990 |
+ var a = strings[s]; |
|
991 |
+ var b = strings[s + 1]; |
|
992 |
+ var n$1 = numbers[s]; |
|
993 |
+ if (!isNaN(n$1)) { |
|
994 |
+ if (!b) { |
|
995 |
+ progress += n$1 + ' '; |
|
996 |
+ } else { |
|
997 |
+ progress += n$1 + b; |
|
998 |
+ } |
|
999 |
+ } |
|
1000 |
+ } |
|
1001 |
+ } |
|
1002 |
+ setProgressValue[anim.type](animatable.target, anim.property, progress, animatable.transforms); |
|
1003 |
+ anim.currentValue = progress; |
|
1004 |
+ i++; |
|
1005 |
+ } |
|
1006 |
+ } |
|
1007 |
+ |
|
1008 |
+ function setCallback(cb) { |
|
1009 |
+ if (instance[cb] && !instance.passThrough) { instance[cb](instance); } |
|
1010 |
+ } |
|
1011 |
+ |
|
1012 |
+ function countIteration() { |
|
1013 |
+ if (instance.remaining && instance.remaining !== true) { |
|
1014 |
+ instance.remaining--; |
|
1015 |
+ } |
|
1016 |
+ } |
|
1017 |
+ |
|
1018 |
+ function setInstanceProgress(engineTime) { |
|
1019 |
+ var insDuration = instance.duration; |
|
1020 |
+ var insDelay = instance.delay; |
|
1021 |
+ var insEndDelay = insDuration - instance.endDelay; |
|
1022 |
+ var insTime = adjustTime(engineTime); |
|
1023 |
+ instance.progress = minMax((insTime / insDuration) * 100, 0, 100); |
|
1024 |
+ instance.reversePlayback = insTime < instance.currentTime; |
|
1025 |
+ if (children) { syncInstanceChildren(insTime); } |
|
1026 |
+ if (!instance.began && instance.currentTime > 0) { |
|
1027 |
+ instance.began = true; |
|
1028 |
+ setCallback('begin'); |
|
1029 |
+ } |
|
1030 |
+ if (!instance.loopBegan && instance.currentTime > 0) { |
|
1031 |
+ instance.loopBegan = true; |
|
1032 |
+ setCallback('loopBegin'); |
|
1033 |
+ } |
|
1034 |
+ if (insTime <= insDelay && instance.currentTime !== 0) { |
|
1035 |
+ setAnimationsProgress(0); |
|
1036 |
+ } |
|
1037 |
+ if ((insTime >= insEndDelay && instance.currentTime !== insDuration) || !insDuration) { |
|
1038 |
+ setAnimationsProgress(insDuration); |
|
1039 |
+ } |
|
1040 |
+ if (insTime > insDelay && insTime < insEndDelay) { |
|
1041 |
+ if (!instance.changeBegan) { |
|
1042 |
+ instance.changeBegan = true; |
|
1043 |
+ instance.changeCompleted = false; |
|
1044 |
+ setCallback('changeBegin'); |
|
1045 |
+ } |
|
1046 |
+ setCallback('change'); |
|
1047 |
+ setAnimationsProgress(insTime); |
|
1048 |
+ } else { |
|
1049 |
+ if (instance.changeBegan) { |
|
1050 |
+ instance.changeCompleted = true; |
|
1051 |
+ instance.changeBegan = false; |
|
1052 |
+ setCallback('changeComplete'); |
|
1053 |
+ } |
|
1054 |
+ } |
|
1055 |
+ instance.currentTime = minMax(insTime, 0, insDuration); |
|
1056 |
+ if (instance.began) { setCallback('update'); } |
|
1057 |
+ if (engineTime >= insDuration) { |
|
1058 |
+ lastTime = 0; |
|
1059 |
+ countIteration(); |
|
1060 |
+ if (!instance.remaining) { |
|
1061 |
+ instance.paused = true; |
|
1062 |
+ if (!instance.completed) { |
|
1063 |
+ instance.completed = true; |
|
1064 |
+ setCallback('loopComplete'); |
|
1065 |
+ setCallback('complete'); |
|
1066 |
+ if (!instance.passThrough && 'Promise' in window) { |
|
1067 |
+ resolve(); |
|
1068 |
+ promise = makePromise(instance); |
|
1069 |
+ } |
|
1070 |
+ } |
|
1071 |
+ } else { |
|
1072 |
+ startTime = now; |
|
1073 |
+ setCallback('loopComplete'); |
|
1074 |
+ instance.loopBegan = false; |
|
1075 |
+ if (instance.direction === 'alternate') { |
|
1076 |
+ toggleInstanceDirection(); |
|
1077 |
+ } |
|
1078 |
+ } |
|
1079 |
+ } |
|
1080 |
+ } |
|
1081 |
+ |
|
1082 |
+ instance.reset = function() { |
|
1083 |
+ var direction = instance.direction; |
|
1084 |
+ instance.passThrough = false; |
|
1085 |
+ instance.currentTime = 0; |
|
1086 |
+ instance.progress = 0; |
|
1087 |
+ instance.paused = true; |
|
1088 |
+ instance.began = false; |
|
1089 |
+ instance.loopBegan = false; |
|
1090 |
+ instance.changeBegan = false; |
|
1091 |
+ instance.completed = false; |
|
1092 |
+ instance.changeCompleted = false; |
|
1093 |
+ instance.reversePlayback = false; |
|
1094 |
+ instance.reversed = direction === 'reverse'; |
|
1095 |
+ instance.remaining = instance.loop; |
|
1096 |
+ children = instance.children; |
|
1097 |
+ childrenLength = children.length; |
|
1098 |
+ for (var i = childrenLength; i--;) { instance.children[i].reset(); } |
|
1099 |
+ if (instance.reversed && instance.loop !== true || (direction === 'alternate' && instance.loop === 1)) { instance.remaining++; } |
|
1100 |
+ setAnimationsProgress(instance.reversed ? instance.duration : 0); |
|
1101 |
+ }; |
|
1102 |
+ |
|
1103 |
+ // Set Value helper |
|
1104 |
+ |
|
1105 |
+ instance.set = function(targets, properties) { |
|
1106 |
+ setTargetsValue(targets, properties); |
|
1107 |
+ return instance; |
|
1108 |
+ }; |
|
1109 |
+ |
|
1110 |
+ instance.tick = function(t) { |
|
1111 |
+ now = t; |
|
1112 |
+ if (!startTime) { startTime = now; } |
|
1113 |
+ setInstanceProgress((now + (lastTime - startTime)) * anime.speed); |
|
1114 |
+ }; |
|
1115 |
+ |
|
1116 |
+ instance.seek = function(time) { |
|
1117 |
+ setInstanceProgress(adjustTime(time)); |
|
1118 |
+ }; |
|
1119 |
+ |
|
1120 |
+ instance.pause = function() { |
|
1121 |
+ instance.paused = true; |
|
1122 |
+ resetTime(); |
|
1123 |
+ }; |
|
1124 |
+ |
|
1125 |
+ instance.play = function() { |
|
1126 |
+ if (!instance.paused) { return; } |
|
1127 |
+ if (instance.completed) { instance.reset(); } |
|
1128 |
+ instance.paused = false; |
|
1129 |
+ activeInstances.push(instance); |
|
1130 |
+ resetTime(); |
|
1131 |
+ if (!raf) { engine(); } |
|
1132 |
+ }; |
|
1133 |
+ |
|
1134 |
+ instance.reverse = function() { |
|
1135 |
+ toggleInstanceDirection(); |
|
1136 |
+ instance.completed = instance.reversed ? false : true; |
|
1137 |
+ resetTime(); |
|
1138 |
+ }; |
|
1139 |
+ |
|
1140 |
+ instance.restart = function() { |
|
1141 |
+ instance.reset(); |
|
1142 |
+ instance.play(); |
|
1143 |
+ }; |
|
1144 |
+ |
|
1145 |
+ instance.reset(); |
|
1146 |
+ |
|
1147 |
+ if (instance.autoplay) { instance.play(); } |
|
1148 |
+ |
|
1149 |
+ return instance; |
|
1150 |
+ |
|
1151 |
+} |
|
1152 |
+ |
|
1153 |
+// Remove targets from animation |
|
1154 |
+ |
|
1155 |
+function removeTargetsFromAnimations(targetsArray, animations) { |
|
1156 |
+ for (var a = animations.length; a--;) { |
|
1157 |
+ if (arrayContains(targetsArray, animations[a].animatable.target)) { |
|
1158 |
+ animations.splice(a, 1); |
|
1159 |
+ } |
|
1160 |
+ } |
|
1161 |
+} |
|
1162 |
+ |
|
1163 |
+function removeTargets(targets) { |
|
1164 |
+ var targetsArray = parseTargets(targets); |
|
1165 |
+ for (var i = activeInstances.length; i--;) { |
|
1166 |
+ var instance = activeInstances[i]; |
|
1167 |
+ var animations = instance.animations; |
|
1168 |
+ var children = instance.children; |
|
1169 |
+ removeTargetsFromAnimations(targetsArray, animations); |
|
1170 |
+ for (var c = children.length; c--;) { |
|
1171 |
+ var child = children[c]; |
|
1172 |
+ var childAnimations = child.animations; |
|
1173 |
+ removeTargetsFromAnimations(targetsArray, childAnimations); |
|
1174 |
+ if (!childAnimations.length && !child.children.length) { children.splice(c, 1); } |
|
1175 |
+ } |
|
1176 |
+ if (!animations.length && !children.length) { instance.pause(); } |
|
1177 |
+ } |
|
1178 |
+} |
|
1179 |
+ |
|
1180 |
+// Stagger helpers |
|
1181 |
+ |
|
1182 |
+function stagger(val, params) { |
|
1183 |
+ if ( params === void 0 ) params = {}; |
|
1184 |
+ |
|
1185 |
+ var direction = params.direction || 'normal'; |
|
1186 |
+ var easing = params.easing ? parseEasings(params.easing) : null; |
|
1187 |
+ var grid = params.grid; |
|
1188 |
+ var axis = params.axis; |
|
1189 |
+ var fromIndex = params.from || 0; |
|
1190 |
+ var fromFirst = fromIndex === 'first'; |
|
1191 |
+ var fromCenter = fromIndex === 'center'; |
|
1192 |
+ var fromLast = fromIndex === 'last'; |
|
1193 |
+ var isRange = is.arr(val); |
|
1194 |
+ var val1 = isRange ? parseFloat(val[0]) : parseFloat(val); |
|
1195 |
+ var val2 = isRange ? parseFloat(val[1]) : 0; |
|
1196 |
+ var unit = getUnit(isRange ? val[1] : val) || 0; |
|
1197 |
+ var start = params.start || 0 + (isRange ? val1 : 0); |
|
1198 |
+ var values = []; |
|
1199 |
+ var maxValue = 0; |
|
1200 |
+ return function (el, i, t) { |
|
1201 |
+ if (fromFirst) { fromIndex = 0; } |
|
1202 |
+ if (fromCenter) { fromIndex = (t - 1) / 2; } |
|
1203 |
+ if (fromLast) { fromIndex = t - 1; } |
|
1204 |
+ if (!values.length) { |
|
1205 |
+ for (var index = 0; index < t; index++) { |
|
1206 |
+ if (!grid) { |
|
1207 |
+ values.push(Math.abs(fromIndex - index)); |
|
1208 |
+ } else { |
|
1209 |
+ var fromX = !fromCenter ? fromIndex%grid[0] : (grid[0]-1)/2; |
|
1210 |
+ var fromY = !fromCenter ? Math.floor(fromIndex/grid[0]) : (grid[1]-1)/2; |
|
1211 |
+ var toX = index%grid[0]; |
|
1212 |
+ var toY = Math.floor(index/grid[0]); |
|
1213 |
+ var distanceX = fromX - toX; |
|
1214 |
+ var distanceY = fromY - toY; |
|
1215 |
+ var value = Math.sqrt(distanceX * distanceX + distanceY * distanceY); |
|
1216 |
+ if (axis === 'x') { value = -distanceX; } |
|
1217 |
+ if (axis === 'y') { value = -distanceY; } |
|
1218 |
+ values.push(value); |
|
1219 |
+ } |
|
1220 |
+ maxValue = Math.max.apply(Math, values); |
|
1221 |
+ } |
|
1222 |
+ if (easing) { values = values.map(function (val) { return easing(val / maxValue) * maxValue; }); } |
|
1223 |
+ if (direction === 'reverse') { values = values.map(function (val) { return axis ? (val < 0) ? val * -1 : -val : Math.abs(maxValue - val); }); } |
|
1224 |
+ } |
|
1225 |
+ var spacing = isRange ? (val2 - val1) / maxValue : val1; |
|
1226 |
+ return start + (spacing * (Math.round(values[i] * 100) / 100)) + unit; |
|
1227 |
+ } |
|
1228 |
+} |
|
1229 |
+ |
|
1230 |
+// Timeline |
|
1231 |
+ |
|
1232 |
+function timeline(params) { |
|
1233 |
+ if ( params === void 0 ) params = {}; |
|
1234 |
+ |
|
1235 |
+ var tl = anime(params); |
|
1236 |
+ tl.duration = 0; |
|
1237 |
+ tl.add = function(instanceParams, timelineOffset) { |
|
1238 |
+ var tlIndex = activeInstances.indexOf(tl); |
|
1239 |
+ var children = tl.children; |
|
1240 |
+ if (tlIndex > -1) { activeInstances.splice(tlIndex, 1); } |
|
1241 |
+ function passThrough(ins) { ins.passThrough = true; } |
|
1242 |
+ for (var i = 0; i < children.length; i++) { passThrough(children[i]); } |
|
1243 |
+ var insParams = mergeObjects(instanceParams, replaceObjectProps(defaultTweenSettings, params)); |
|
1244 |
+ insParams.targets = insParams.targets || params.targets; |
|
1245 |
+ var tlDuration = tl.duration; |
|
1246 |
+ insParams.autoplay = false; |
|
1247 |
+ insParams.direction = tl.direction; |
|
1248 |
+ insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration); |
|
1249 |
+ passThrough(tl); |
|
1250 |
+ tl.seek(insParams.timelineOffset); |
|
1251 |
+ var ins = anime(insParams); |
|
1252 |
+ passThrough(ins); |
|
1253 |
+ children.push(ins); |
|
1254 |
+ var timings = getInstanceTimings(children, params); |
|
1255 |
+ tl.delay = timings.delay; |
|
1256 |
+ tl.endDelay = timings.endDelay; |
|
1257 |
+ tl.duration = timings.duration; |
|
1258 |
+ tl.seek(0); |
|
1259 |
+ tl.reset(); |
|
1260 |
+ if (tl.autoplay) { tl.play(); } |
|
1261 |
+ return tl; |
|
1262 |
+ }; |
|
1263 |
+ return tl; |
|
1264 |
+} |
|
1265 |
+ |
|
1266 |
+anime.version = '3.2.0'; |
|
1267 |
+anime.speed = 1; |
|
1268 |
+anime.running = activeInstances; |
|
1269 |
+anime.remove = removeTargets; |
|
1270 |
+anime.get = getOriginalTargetValue; |
|
1271 |
+anime.set = setTargetsValue; |
|
1272 |
+anime.convertPx = convertPxToUnit; |
|
1273 |
+anime.path = getPath; |
|
1274 |
+anime.setDashoffset = setDashoffset; |
|
1275 |
+anime.stagger = stagger; |
|
1276 |
+anime.timeline = timeline; |
|
1277 |
+anime.easing = parseEasings; |
|
1278 |
+anime.penner = penner; |
|
1279 |
+anime.random = function (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }; |
|
1280 |
+ |
|
1281 |
+export default anime; |
0 | 1282 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,1283 @@ |
1 |
+/* |
|
2 |
+ * anime.js v3.2.0 |
|
3 |
+ * (c) 2020 Julian Garnier |
|
4 |
+ * Released under the MIT license |
|
5 |
+ * animejs.com |
|
6 |
+ */ |
|
7 |
+ |
|
8 |
+'use strict'; |
|
9 |
+ |
|
10 |
+// Defaults |
|
11 |
+ |
|
12 |
+var defaultInstanceSettings = { |
|
13 |
+ update: null, |
|
14 |
+ begin: null, |
|
15 |
+ loopBegin: null, |
|
16 |
+ changeBegin: null, |
|
17 |
+ change: null, |
|
18 |
+ changeComplete: null, |
|
19 |
+ loopComplete: null, |
|
20 |
+ complete: null, |
|
21 |
+ loop: 1, |
|
22 |
+ direction: 'normal', |
|
23 |
+ autoplay: true, |
|
24 |
+ timelineOffset: 0 |
|
25 |
+}; |
|
26 |
+ |
|
27 |
+var defaultTweenSettings = { |
|
28 |
+ duration: 1000, |
|
29 |
+ delay: 0, |
|
30 |
+ endDelay: 0, |
|
31 |
+ easing: 'easeOutElastic(1, .5)', |
|
32 |
+ round: 0 |
|
33 |
+}; |
|
34 |
+ |
|
35 |
+var validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'perspective', 'matrix', 'matrix3d']; |
|
36 |
+ |
|
37 |
+// Caching |
|
38 |
+ |
|
39 |
+var cache = { |
|
40 |
+ CSS: {}, |
|
41 |
+ springs: {} |
|
42 |
+}; |
|
43 |
+ |
|
44 |
+// Utils |
|
45 |
+ |
|
46 |
+function minMax(val, min, max) { |
|
47 |
+ return Math.min(Math.max(val, min), max); |
|
48 |
+} |
|
49 |
+ |
|
50 |
+function stringContains(str, text) { |
|
51 |
+ return str.indexOf(text) > -1; |
|
52 |
+} |
|
53 |
+ |
|
54 |
+function applyArguments(func, args) { |
|
55 |
+ return func.apply(null, args); |
|
56 |
+} |
|
57 |
+ |
|
58 |
+var is = { |
|
59 |
+ arr: function (a) { return Array.isArray(a); }, |
|
60 |
+ obj: function (a) { return stringContains(Object.prototype.toString.call(a), 'Object'); }, |
|
61 |
+ pth: function (a) { return is.obj(a) && a.hasOwnProperty('totalLength'); }, |
|
62 |
+ svg: function (a) { return a instanceof SVGElement; }, |
|
63 |
+ inp: function (a) { return a instanceof HTMLInputElement; }, |
|
64 |
+ dom: function (a) { return a.nodeType || is.svg(a); }, |
|
65 |
+ str: function (a) { return typeof a === 'string'; }, |
|
66 |
+ fnc: function (a) { return typeof a === 'function'; }, |
|
67 |
+ und: function (a) { return typeof a === 'undefined'; }, |
|
68 |
+ hex: function (a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a); }, |
|
69 |
+ rgb: function (a) { return /^rgb/.test(a); }, |
|
70 |
+ hsl: function (a) { return /^hsl/.test(a); }, |
|
71 |
+ col: function (a) { return (is.hex(a) || is.rgb(a) || is.hsl(a)); }, |
|
72 |
+ key: function (a) { return !defaultInstanceSettings.hasOwnProperty(a) && !defaultTweenSettings.hasOwnProperty(a) && a !== 'targets' && a !== 'keyframes'; } |
|
73 |
+}; |
|
74 |
+ |
|
75 |
+// Easings |
|
76 |
+ |
|
77 |
+function parseEasingParameters(string) { |
|
78 |
+ var match = /\(([^)]+)\)/.exec(string); |
|
79 |
+ return match ? match[1].split(',').map(function (p) { return parseFloat(p); }) : []; |
|
80 |
+} |
|
81 |
+ |
|
82 |
+// Spring solver inspired by Webkit Copyright © 2016 Apple Inc. All rights reserved. https://webkit.org/demos/spring/spring.js |
|
83 |
+ |
|
84 |
+function spring(string, duration) { |
|
85 |
+ |
|
86 |
+ var params = parseEasingParameters(string); |
|
87 |
+ var mass = minMax(is.und(params[0]) ? 1 : params[0], .1, 100); |
|
88 |
+ var stiffness = minMax(is.und(params[1]) ? 100 : params[1], .1, 100); |
|
89 |
+ var damping = minMax(is.und(params[2]) ? 10 : params[2], .1, 100); |
|
90 |
+ var velocity = minMax(is.und(params[3]) ? 0 : params[3], .1, 100); |
|
91 |
+ var w0 = Math.sqrt(stiffness / mass); |
|
92 |
+ var zeta = damping / (2 * Math.sqrt(stiffness * mass)); |
|
93 |
+ var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0; |
|
94 |
+ var a = 1; |
|
95 |
+ var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0; |
|
96 |
+ |
|
97 |
+ function solver(t) { |
|
98 |
+ var progress = duration ? (duration * t) / 1000 : t; |
|
99 |
+ if (zeta < 1) { |
|
100 |
+ progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress)); |
|
101 |
+ } else { |
|
102 |
+ progress = (a + b * progress) * Math.exp(-progress * w0); |
|
103 |
+ } |
|
104 |
+ if (t === 0 || t === 1) { return t; } |
|
105 |
+ return 1 - progress; |
|
106 |
+ } |
|
107 |
+ |
|
108 |
+ function getDuration() { |
|
109 |
+ var cached = cache.springs[string]; |
|
110 |
+ if (cached) { return cached; } |
|
111 |
+ var frame = 1/6; |
|
112 |
+ var elapsed = 0; |
|
113 |
+ var rest = 0; |
|
114 |
+ while(true) { |
|
115 |
+ elapsed += frame; |
|
116 |
+ if (solver(elapsed) === 1) { |
|
117 |
+ rest++; |
|
118 |
+ if (rest >= 16) { break; } |
|
119 |
+ } else { |
|
120 |
+ rest = 0; |
|
121 |
+ } |
|
122 |
+ } |
|
123 |
+ var duration = elapsed * frame * 1000; |
|
124 |
+ cache.springs[string] = duration; |
|
125 |
+ return duration; |
|
126 |
+ } |
|
127 |
+ |
|
128 |
+ return duration ? solver : getDuration; |
|
129 |
+ |
|
130 |
+} |
|
131 |
+ |
|
132 |
+// Basic steps easing implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function |
|
133 |
+ |
|
134 |
+function steps(steps) { |
|
135 |
+ if ( steps === void 0 ) steps = 10; |
|
136 |
+ |
|
137 |
+ return function (t) { return Math.ceil((minMax(t, 0.000001, 1)) * steps) * (1 / steps); }; |
|
138 |
+} |
|
139 |
+ |
|
140 |
+// BezierEasing https://github.com/gre/bezier-easing |
|
141 |
+ |
|
142 |
+var bezier = (function () { |
|
143 |
+ |
|
144 |
+ var kSplineTableSize = 11; |
|
145 |
+ var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); |
|
146 |
+ |
|
147 |
+ function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1 } |
|
148 |
+ function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1 } |
|
149 |
+ function C(aA1) { return 3.0 * aA1 } |
|
150 |
+ |
|
151 |
+ function calcBezier(aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT } |
|
152 |
+ function getSlope(aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1) } |
|
153 |
+ |
|
154 |
+ function binarySubdivide(aX, aA, aB, mX1, mX2) { |
|
155 |
+ var currentX, currentT, i = 0; |
|
156 |
+ do { |
|
157 |
+ currentT = aA + (aB - aA) / 2.0; |
|
158 |
+ currentX = calcBezier(currentT, mX1, mX2) - aX; |
|
159 |
+ if (currentX > 0.0) { aB = currentT; } else { aA = currentT; } |
|
160 |
+ } while (Math.abs(currentX) > 0.0000001 && ++i < 10); |
|
161 |
+ return currentT; |
|
162 |
+ } |
|
163 |
+ |
|
164 |
+ function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) { |
|
165 |
+ for (var i = 0; i < 4; ++i) { |
|
166 |
+ var currentSlope = getSlope(aGuessT, mX1, mX2); |
|
167 |
+ if (currentSlope === 0.0) { return aGuessT; } |
|
168 |
+ var currentX = calcBezier(aGuessT, mX1, mX2) - aX; |
|
169 |
+ aGuessT -= currentX / currentSlope; |
|
170 |
+ } |
|
171 |
+ return aGuessT; |
|
172 |
+ } |
|
173 |
+ |
|
174 |
+ function bezier(mX1, mY1, mX2, mY2) { |
|
175 |
+ |
|
176 |
+ if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { return; } |
|
177 |
+ var sampleValues = new Float32Array(kSplineTableSize); |
|
178 |
+ |
|
179 |
+ if (mX1 !== mY1 || mX2 !== mY2) { |
|
180 |
+ for (var i = 0; i < kSplineTableSize; ++i) { |
|
181 |
+ sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); |
|
182 |
+ } |
|
183 |
+ } |
|
184 |
+ |
|
185 |
+ function getTForX(aX) { |
|
186 |
+ |
|
187 |
+ var intervalStart = 0; |
|
188 |
+ var currentSample = 1; |
|
189 |
+ var lastSample = kSplineTableSize - 1; |
|
190 |
+ |
|
191 |
+ for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { |
|
192 |
+ intervalStart += kSampleStepSize; |
|
193 |
+ } |
|
194 |
+ |
|
195 |
+ --currentSample; |
|
196 |
+ |
|
197 |
+ var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); |
|
198 |
+ var guessForT = intervalStart + dist * kSampleStepSize; |
|
199 |
+ var initialSlope = getSlope(guessForT, mX1, mX2); |
|
200 |
+ |
|
201 |
+ if (initialSlope >= 0.001) { |
|
202 |
+ return newtonRaphsonIterate(aX, guessForT, mX1, mX2); |
|
203 |
+ } else if (initialSlope === 0.0) { |
|
204 |
+ return guessForT; |
|
205 |
+ } else { |
|
206 |
+ return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); |
|
207 |
+ } |
|
208 |
+ |
|
209 |
+ } |
|
210 |
+ |
|
211 |
+ return function (x) { |
|
212 |
+ if (mX1 === mY1 && mX2 === mY2) { return x; } |
|
213 |
+ if (x === 0 || x === 1) { return x; } |
|
214 |
+ return calcBezier(getTForX(x), mY1, mY2); |
|
215 |
+ } |
|
216 |
+ |
|
217 |
+ } |
|
218 |
+ |
|
219 |
+ return bezier; |
|
220 |
+ |
|
221 |
+})(); |
|
222 |
+ |
|
223 |
+var penner = (function () { |
|
224 |
+ |
|
225 |
+ // Based on jQuery UI's implemenation of easing equations from Robert Penner (http://www.robertpenner.com/easing) |
|
226 |
+ |
|
227 |
+ var eases = { linear: function () { return function (t) { return t; }; } }; |
|
228 |
+ |
|
229 |
+ var functionEasings = { |
|
230 |
+ Sine: function () { return function (t) { return 1 - Math.cos(t * Math.PI / 2); }; }, |
|
231 |
+ Circ: function () { return function (t) { return 1 - Math.sqrt(1 - t * t); }; }, |
|
232 |
+ Back: function () { return function (t) { return t * t * (3 * t - 2); }; }, |
|
233 |
+ Bounce: function () { return function (t) { |
|
234 |
+ var pow2, b = 4; |
|
235 |
+ while (t < (( pow2 = Math.pow(2, --b)) - 1) / 11) {} |
|
236 |
+ return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow(( pow2 * 3 - 2 ) / 22 - t, 2) |
|
237 |
+ }; }, |
|
238 |
+ Elastic: function (amplitude, period) { |
|
239 |
+ if ( amplitude === void 0 ) amplitude = 1; |
|
240 |
+ if ( period === void 0 ) period = .5; |
|
241 |
+ |
|
242 |
+ var a = minMax(amplitude, 1, 10); |
|
243 |
+ var p = minMax(period, .1, 2); |
|
244 |
+ return function (t) { |
|
245 |
+ return (t === 0 || t === 1) ? t : |
|
246 |
+ -a * Math.pow(2, 10 * (t - 1)) * Math.sin((((t - 1) - (p / (Math.PI * 2) * Math.asin(1 / a))) * (Math.PI * 2)) / p); |
|
247 |
+ } |
|
248 |
+ } |
|
249 |
+ }; |
|
250 |
+ |
|
251 |
+ var baseEasings = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo']; |
|
252 |
+ |
|
253 |
+ baseEasings.forEach(function (name, i) { |
|
254 |
+ functionEasings[name] = function () { return function (t) { return Math.pow(t, i + 2); }; }; |
|
255 |
+ }); |
|
256 |
+ |
|
257 |
+ Object.keys(functionEasings).forEach(function (name) { |
|
258 |
+ var easeIn = functionEasings[name]; |
|
259 |
+ eases['easeIn' + name] = easeIn; |
|
260 |
+ eases['easeOut' + name] = function (a, b) { return function (t) { return 1 - easeIn(a, b)(1 - t); }; }; |
|
261 |
+ eases['easeInOut' + name] = function (a, b) { return function (t) { return t < 0.5 ? easeIn(a, b)(t * 2) / 2 : |
|
262 |
+ 1 - easeIn(a, b)(t * -2 + 2) / 2; }; }; |
|
263 |
+ }); |
|
264 |
+ |
|
265 |
+ return eases; |
|
266 |
+ |
|
267 |
+})(); |
|
268 |
+ |
|
269 |
+function parseEasings(easing, duration) { |
|
270 |
+ if (is.fnc(easing)) { return easing; } |
|
271 |
+ var name = easing.split('(')[0]; |
|
272 |
+ var ease = penner[name]; |
|
273 |
+ var args = parseEasingParameters(easing); |
|
274 |
+ switch (name) { |
|
275 |
+ case 'spring' : return spring(easing, duration); |
|
276 |
+ case 'cubicBezier' : return applyArguments(bezier, args); |
|
277 |
+ case 'steps' : return applyArguments(steps, args); |
|
278 |
+ default : return applyArguments(ease, args); |
|
279 |
+ } |
|
280 |
+} |
|
281 |
+ |
|
282 |
+// Strings |
|
283 |
+ |
|
284 |
+function selectString(str) { |
|
285 |
+ try { |
|
286 |
+ var nodes = document.querySelectorAll(str); |
|
287 |
+ return nodes; |
|
288 |
+ } catch(e) { |
|
289 |
+ return; |
|
290 |
+ } |
|
291 |
+} |
|
292 |
+ |
|
293 |
+// Arrays |
|
294 |
+ |
|
295 |
+function filterArray(arr, callback) { |
|
296 |
+ var len = arr.length; |
|
297 |
+ var thisArg = arguments.length >= 2 ? arguments[1] : void 0; |
|
298 |
+ var result = []; |
|
299 |
+ for (var i = 0; i < len; i++) { |
|
300 |
+ if (i in arr) { |
|
301 |
+ var val = arr[i]; |
|
302 |
+ if (callback.call(thisArg, val, i, arr)) { |
|
303 |
+ result.push(val); |
|
304 |
+ } |
|
305 |
+ } |
|
306 |
+ } |
|
307 |
+ return result; |
|
308 |
+} |
|
309 |
+ |
|
310 |
+function flattenArray(arr) { |
|
311 |
+ return arr.reduce(function (a, b) { return a.concat(is.arr(b) ? flattenArray(b) : b); }, []); |
|
312 |
+} |
|
313 |
+ |
|
314 |
+function toArray(o) { |
|
315 |
+ if (is.arr(o)) { return o; } |
|
316 |
+ if (is.str(o)) { o = selectString(o) || o; } |
|
317 |
+ if (o instanceof NodeList || o instanceof HTMLCollection) { return [].slice.call(o); } |
|
318 |
+ return [o]; |
|
319 |
+} |
|
320 |
+ |
|
321 |
+function arrayContains(arr, val) { |
|
322 |
+ return arr.some(function (a) { return a === val; }); |
|
323 |
+} |
|
324 |
+ |
|
325 |
+// Objects |
|
326 |
+ |
|
327 |
+function cloneObject(o) { |
|
328 |
+ var clone = {}; |
|
329 |
+ for (var p in o) { clone[p] = o[p]; } |
|
330 |
+ return clone; |
|
331 |
+} |
|
332 |
+ |
|
333 |
+function replaceObjectProps(o1, o2) { |
|
334 |
+ var o = cloneObject(o1); |
|
335 |
+ for (var p in o1) { o[p] = o2.hasOwnProperty(p) ? o2[p] : o1[p]; } |
|
336 |
+ return o; |
|
337 |
+} |
|
338 |
+ |
|
339 |
+function mergeObjects(o1, o2) { |
|
340 |
+ var o = cloneObject(o1); |
|
341 |
+ for (var p in o2) { o[p] = is.und(o1[p]) ? o2[p] : o1[p]; } |
|
342 |
+ return o; |
|
343 |
+} |
|
344 |
+ |
|
345 |
+// Colors |
|
346 |
+ |
|
347 |
+function rgbToRgba(rgbValue) { |
|
348 |
+ var rgb = /rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g.exec(rgbValue); |
|
349 |
+ return rgb ? ("rgba(" + (rgb[1]) + ",1)") : rgbValue; |
|
350 |
+} |
|
351 |
+ |
|
352 |
+function hexToRgba(hexValue) { |
|
353 |
+ var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i; |
|
354 |
+ var hex = hexValue.replace(rgx, function (m, r, g, b) { return r + r + g + g + b + b; } ); |
|
355 |
+ var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); |
|
356 |
+ var r = parseInt(rgb[1], 16); |
|
357 |
+ var g = parseInt(rgb[2], 16); |
|
358 |
+ var b = parseInt(rgb[3], 16); |
|
359 |
+ return ("rgba(" + r + "," + g + "," + b + ",1)"); |
|
360 |
+} |
|
361 |
+ |
|
362 |
+function hslToRgba(hslValue) { |
|
363 |
+ var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(hslValue); |
|
364 |
+ var h = parseInt(hsl[1], 10) / 360; |
|
365 |
+ var s = parseInt(hsl[2], 10) / 100; |
|
366 |
+ var l = parseInt(hsl[3], 10) / 100; |
|
367 |
+ var a = hsl[4] || 1; |
|
368 |
+ function hue2rgb(p, q, t) { |
|
369 |
+ if (t < 0) { t += 1; } |
|
370 |
+ if (t > 1) { t -= 1; } |
|
371 |
+ if (t < 1/6) { return p + (q - p) * 6 * t; } |
|
372 |
+ if (t < 1/2) { return q; } |
|
373 |
+ if (t < 2/3) { return p + (q - p) * (2/3 - t) * 6; } |
|
374 |
+ return p; |
|
375 |
+ } |
|
376 |
+ var r, g, b; |
|
377 |
+ if (s == 0) { |
|
378 |
+ r = g = b = l; |
|
379 |
+ } else { |
|
380 |
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s; |
|
381 |
+ var p = 2 * l - q; |
|
382 |
+ r = hue2rgb(p, q, h + 1/3); |
|
383 |
+ g = hue2rgb(p, q, h); |
|
384 |
+ b = hue2rgb(p, q, h - 1/3); |
|
385 |
+ } |
|
386 |
+ return ("rgba(" + (r * 255) + "," + (g * 255) + "," + (b * 255) + "," + a + ")"); |
|
387 |
+} |
|
388 |
+ |
|
389 |
+function colorToRgb(val) { |
|
390 |
+ if (is.rgb(val)) { return rgbToRgba(val); } |
|
391 |
+ if (is.hex(val)) { return hexToRgba(val); } |
|
392 |
+ if (is.hsl(val)) { return hslToRgba(val); } |
|
393 |
+} |
|
394 |
+ |
|
395 |
+// Units |
|
396 |
+ |
|
397 |
+function getUnit(val) { |
|
398 |
+ var split = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(val); |
|
399 |
+ if (split) { return split[1]; } |
|
400 |
+} |
|
401 |
+ |
|
402 |
+function getTransformUnit(propName) { |
|
403 |
+ if (stringContains(propName, 'translate') || propName === 'perspective') { return 'px'; } |
|
404 |
+ if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) { return 'deg'; } |
|
405 |
+} |
|
406 |
+ |
|
407 |
+// Values |
|
408 |
+ |
|
409 |
+function getFunctionValue(val, animatable) { |
|
410 |
+ if (!is.fnc(val)) { return val; } |
|
411 |
+ return val(animatable.target, animatable.id, animatable.total); |
|
412 |
+} |
|
413 |
+ |
|
414 |
+function getAttribute(el, prop) { |
|
415 |
+ return el.getAttribute(prop); |
|
416 |
+} |
|
417 |
+ |
|
418 |
+function convertPxToUnit(el, value, unit) { |
|
419 |
+ var valueUnit = getUnit(value); |
|
420 |
+ if (arrayContains([unit, 'deg', 'rad', 'turn'], valueUnit)) { return value; } |
|
421 |
+ var cached = cache.CSS[value + unit]; |
|
422 |
+ if (!is.und(cached)) { return cached; } |
|
423 |
+ var baseline = 100; |
|
424 |
+ var tempEl = document.createElement(el.tagName); |
|
425 |
+ var parentEl = (el.parentNode && (el.parentNode !== document)) ? el.parentNode : document.body; |
|
426 |
+ parentEl.appendChild(tempEl); |
|
427 |
+ tempEl.style.position = 'absolute'; |
|
428 |
+ tempEl.style.width = baseline + unit; |
|
429 |
+ var factor = baseline / tempEl.offsetWidth; |
|
430 |
+ parentEl.removeChild(tempEl); |
|
431 |
+ var convertedUnit = factor * parseFloat(value); |
|
432 |
+ cache.CSS[value + unit] = convertedUnit; |
|
433 |
+ return convertedUnit; |
|
434 |
+} |
|
435 |
+ |
|
436 |
+function getCSSValue(el, prop, unit) { |
|
437 |
+ if (prop in el.style) { |
|
438 |
+ var uppercasePropName = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
|
439 |
+ var value = el.style[prop] || getComputedStyle(el).getPropertyValue(uppercasePropName) || '0'; |
|
440 |
+ return unit ? convertPxToUnit(el, value, unit) : value; |
|
441 |
+ } |
|
442 |
+} |
|
443 |
+ |
|
444 |
+function getAnimationType(el, prop) { |
|
445 |
+ if (is.dom(el) && !is.inp(el) && (getAttribute(el, prop) || (is.svg(el) && el[prop]))) { return 'attribute'; } |
|
446 |
+ if (is.dom(el) && arrayContains(validTransforms, prop)) { return 'transform'; } |
|
447 |
+ if (is.dom(el) && (prop !== 'transform' && getCSSValue(el, prop))) { return 'css'; } |
|
448 |
+ if (el[prop] != null) { return 'object'; } |
|
449 |
+} |
|
450 |
+ |
|
451 |
+function getElementTransforms(el) { |
|
452 |
+ if (!is.dom(el)) { return; } |
|
453 |
+ var str = el.style.transform || ''; |
|
454 |
+ var reg = /(\w+)\(([^)]*)\)/g; |
|
455 |
+ var transforms = new Map(); |
|
456 |
+ var m; while (m = reg.exec(str)) { transforms.set(m[1], m[2]); } |
|
457 |
+ return transforms; |
|
458 |
+} |
|
459 |
+ |
|
460 |
+function getTransformValue(el, propName, animatable, unit) { |
|
461 |
+ var defaultVal = stringContains(propName, 'scale') ? 1 : 0 + getTransformUnit(propName); |
|
462 |
+ var value = getElementTransforms(el).get(propName) || defaultVal; |
|
463 |
+ if (animatable) { |
|
464 |
+ animatable.transforms.list.set(propName, value); |
|
465 |
+ animatable.transforms['last'] = propName; |
|
466 |
+ } |
|
467 |
+ return unit ? convertPxToUnit(el, value, unit) : value; |
|
468 |
+} |
|
469 |
+ |
|
470 |
+function getOriginalTargetValue(target, propName, unit, animatable) { |
|
471 |
+ switch (getAnimationType(target, propName)) { |
|
472 |
+ case 'transform': return getTransformValue(target, propName, animatable, unit); |
|
473 |
+ case 'css': return getCSSValue(target, propName, unit); |
|
474 |
+ case 'attribute': return getAttribute(target, propName); |
|
475 |
+ default: return target[propName] || 0; |
|
476 |
+ } |
|
477 |
+} |
|
478 |
+ |
|
479 |
+function getRelativeValue(to, from) { |
|
480 |
+ var operator = /^(\*=|\+=|-=)/.exec(to); |
|
481 |
+ if (!operator) { return to; } |
|
482 |
+ var u = getUnit(to) || 0; |
|
483 |
+ var x = parseFloat(from); |
|
484 |
+ var y = parseFloat(to.replace(operator[0], '')); |
|
485 |
+ switch (operator[0][0]) { |
|
486 |
+ case '+': return x + y + u; |
|
487 |
+ case '-': return x - y + u; |
|
488 |
+ case '*': return x * y + u; |
|
489 |
+ } |
|
490 |
+} |
|
491 |
+ |
|
492 |
+function validateValue(val, unit) { |
|
493 |
+ if (is.col(val)) { return colorToRgb(val); } |
|
494 |
+ if (/\s/g.test(val)) { return val; } |
|
495 |
+ var originalUnit = getUnit(val); |
|
496 |
+ var unitLess = originalUnit ? val.substr(0, val.length - originalUnit.length) : val; |
|
497 |
+ if (unit) { return unitLess + unit; } |
|
498 |
+ return unitLess; |
|
499 |
+} |
|
500 |
+ |
|
501 |
+// getTotalLength() equivalent for circle, rect, polyline, polygon and line shapes |
|
502 |
+// adapted from https://gist.github.com/SebLambla/3e0550c496c236709744 |
|
503 |
+ |
|
504 |
+function getDistance(p1, p2) { |
|
505 |
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)); |
|
506 |
+} |
|
507 |
+ |
|
508 |
+function getCircleLength(el) { |
|
509 |
+ return Math.PI * 2 * getAttribute(el, 'r'); |
|
510 |
+} |
|
511 |
+ |
|
512 |
+function getRectLength(el) { |
|
513 |
+ return (getAttribute(el, 'width') * 2) + (getAttribute(el, 'height') * 2); |
|
514 |
+} |
|
515 |
+ |
|
516 |
+function getLineLength(el) { |
|
517 |
+ return getDistance( |
|
518 |
+ {x: getAttribute(el, 'x1'), y: getAttribute(el, 'y1')}, |
|
519 |
+ {x: getAttribute(el, 'x2'), y: getAttribute(el, 'y2')} |
|
520 |
+ ); |
|
521 |
+} |
|
522 |
+ |
|
523 |
+function getPolylineLength(el) { |
|
524 |
+ var points = el.points; |
|
525 |
+ var totalLength = 0; |
|
526 |
+ var previousPos; |
|
527 |
+ for (var i = 0 ; i < points.numberOfItems; i++) { |
|
528 |
+ var currentPos = points.getItem(i); |
|
529 |
+ if (i > 0) { totalLength += getDistance(previousPos, currentPos); } |
|
530 |
+ previousPos = currentPos; |
|
531 |
+ } |
|
532 |
+ return totalLength; |
|
533 |
+} |
|
534 |
+ |
|
535 |
+function getPolygonLength(el) { |
|
536 |
+ var points = el.points; |
|
537 |
+ return getPolylineLength(el) + getDistance(points.getItem(points.numberOfItems - 1), points.getItem(0)); |
|
538 |
+} |
|
539 |
+ |
|
540 |
+// Path animation |
|
541 |
+ |
|
542 |
+function getTotalLength(el) { |
|
543 |
+ if (el.getTotalLength) { return el.getTotalLength(); } |
|
544 |
+ switch(el.tagName.toLowerCase()) { |
|
545 |
+ case 'circle': return getCircleLength(el); |
|
546 |
+ case 'rect': return getRectLength(el); |
|
547 |
+ case 'line': return getLineLength(el); |
|
548 |
+ case 'polyline': return getPolylineLength(el); |
|
549 |
+ case 'polygon': return getPolygonLength(el); |
|
550 |
+ } |
|
551 |
+} |
|
552 |
+ |
|
553 |
+function setDashoffset(el) { |
|
554 |
+ var pathLength = getTotalLength(el); |
|
555 |
+ el.setAttribute('stroke-dasharray', pathLength); |
|
556 |
+ return pathLength; |
|
557 |
+} |
|
558 |
+ |
|
559 |
+// Motion path |
|
560 |
+ |
|
561 |
+function getParentSvgEl(el) { |
|
562 |
+ var parentEl = el.parentNode; |
|
563 |
+ while (is.svg(parentEl)) { |
|
564 |
+ if (!is.svg(parentEl.parentNode)) { break; } |
|
565 |
+ parentEl = parentEl.parentNode; |
|
566 |
+ } |
|
567 |
+ return parentEl; |
|
568 |
+} |
|
569 |
+ |
|
570 |
+function getParentSvg(pathEl, svgData) { |
|
571 |
+ var svg = svgData || {}; |
|
572 |
+ var parentSvgEl = svg.el || getParentSvgEl(pathEl); |
|
573 |
+ var rect = parentSvgEl.getBoundingClientRect(); |
|
574 |
+ var viewBoxAttr = getAttribute(parentSvgEl, 'viewBox'); |
|
575 |
+ var width = rect.width; |
|
576 |
+ var height = rect.height; |
|
577 |
+ var viewBox = svg.viewBox || (viewBoxAttr ? viewBoxAttr.split(' ') : [0, 0, width, height]); |
|
578 |
+ return { |
|
579 |
+ el: parentSvgEl, |
|
580 |
+ viewBox: viewBox, |
|
581 |
+ x: viewBox[0] / 1, |
|
582 |
+ y: viewBox[1] / 1, |
|
583 |
+ w: width / viewBox[2], |
|
584 |
+ h: height / viewBox[3] |
|
585 |
+ } |
|
586 |
+} |
|
587 |
+ |
|
588 |
+function getPath(path, percent) { |
|
589 |
+ var pathEl = is.str(path) ? selectString(path)[0] : path; |
|
590 |
+ var p = percent || 100; |
|
591 |
+ return function(property) { |
|
592 |
+ return { |
|
593 |
+ property: property, |
|
594 |
+ el: pathEl, |
|
595 |
+ svg: getParentSvg(pathEl), |
|
596 |
+ totalLength: getTotalLength(pathEl) * (p / 100) |
|
597 |
+ } |
|
598 |
+ } |
|
599 |
+} |
|
600 |
+ |
|
601 |
+function getPathProgress(path, progress) { |
|
602 |
+ function point(offset) { |
|
603 |
+ if ( offset === void 0 ) offset = 0; |
|
604 |
+ |
|
605 |
+ var l = progress + offset >= 1 ? progress + offset : 0; |
|
606 |
+ return path.el.getPointAtLength(l); |
|
607 |
+ } |
|
608 |
+ var svg = getParentSvg(path.el, path.svg); |
|
609 |
+ var p = point(); |
|
610 |
+ var p0 = point(-1); |
|
611 |
+ var p1 = point(+1); |
|
612 |
+ switch (path.property) { |
|
613 |
+ case 'x': return (p.x - svg.x) * svg.w; |
|
614 |
+ case 'y': return (p.y - svg.y) * svg.h; |
|
615 |
+ case 'angle': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI; |
|
616 |
+ } |
|
617 |
+} |
|
618 |
+ |
|
619 |
+// Decompose value |
|
620 |
+ |
|
621 |
+function decomposeValue(val, unit) { |
|
622 |
+ // const rgx = /-?\d*\.?\d+/g; // handles basic numbers |
|
623 |
+ // const rgx = /[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation |
|
624 |
+ var rgx = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation |
|
625 |
+ var value = validateValue((is.pth(val) ? val.totalLength : val), unit) + ''; |
|
626 |
+ return { |
|
627 |
+ original: value, |
|
628 |
+ numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0], |
|
629 |
+ strings: (is.str(val) || unit) ? value.split(rgx) : [] |
|
630 |
+ } |
|
631 |
+} |
|
632 |
+ |
|
633 |
+// Animatables |
|
634 |
+ |
|
635 |
+function parseTargets(targets) { |
|
636 |
+ var targetsArray = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : []; |
|
637 |
+ return filterArray(targetsArray, function (item, pos, self) { return self.indexOf(item) === pos; }); |
|
638 |
+} |
|
639 |
+ |
|
640 |
+function getAnimatables(targets) { |
|
641 |
+ var parsed = parseTargets(targets); |
|
642 |
+ return parsed.map(function (t, i) { |
|
643 |
+ return {target: t, id: i, total: parsed.length, transforms: { list: getElementTransforms(t) } }; |
|
644 |
+ }); |
|
645 |
+} |
|
646 |
+ |
|
647 |
+// Properties |
|
648 |
+ |
|
649 |
+function normalizePropertyTweens(prop, tweenSettings) { |
|
650 |
+ var settings = cloneObject(tweenSettings); |
|
651 |
+ // Override duration if easing is a spring |
|
652 |
+ if (/^spring/.test(settings.easing)) { settings.duration = spring(settings.easing); } |
|
653 |
+ if (is.arr(prop)) { |
|
654 |
+ var l = prop.length; |
|
655 |
+ var isFromTo = (l === 2 && !is.obj(prop[0])); |
|
656 |
+ if (!isFromTo) { |
|
657 |
+ // Duration divided by the number of tweens |
|
658 |
+ if (!is.fnc(tweenSettings.duration)) { settings.duration = tweenSettings.duration / l; } |
|
659 |
+ } else { |
|
660 |
+ // Transform [from, to] values shorthand to a valid tween value |
|
661 |
+ prop = {value: prop}; |
|
662 |
+ } |
|
663 |
+ } |
|
664 |
+ var propArray = is.arr(prop) ? prop : [prop]; |
|
665 |
+ return propArray.map(function (v, i) { |
|
666 |
+ var obj = (is.obj(v) && !is.pth(v)) ? v : {value: v}; |
|
667 |
+ // Default delay value should only be applied to the first tween |
|
668 |
+ if (is.und(obj.delay)) { obj.delay = !i ? tweenSettings.delay : 0; } |
|
669 |
+ // Default endDelay value should only be applied to the last tween |
|
670 |
+ if (is.und(obj.endDelay)) { obj.endDelay = i === propArray.length - 1 ? tweenSettings.endDelay : 0; } |
|
671 |
+ return obj; |
|
672 |
+ }).map(function (k) { return mergeObjects(k, settings); }); |
|
673 |
+} |
|
674 |
+ |
|
675 |
+ |
|
676 |
+function flattenKeyframes(keyframes) { |
|
677 |
+ var propertyNames = filterArray(flattenArray(keyframes.map(function (key) { return Object.keys(key); })), function (p) { return is.key(p); }) |
|
678 |
+ .reduce(function (a,b) { if (a.indexOf(b) < 0) { a.push(b); } return a; }, []); |
|
679 |
+ var properties = {}; |
|
680 |
+ var loop = function ( i ) { |
|
681 |
+ var propName = propertyNames[i]; |
|
682 |
+ properties[propName] = keyframes.map(function (key) { |
|
683 |
+ var newKey = {}; |
|
684 |
+ for (var p in key) { |
|
685 |
+ if (is.key(p)) { |
|
686 |
+ if (p == propName) { newKey.value = key[p]; } |
|
687 |
+ } else { |
|
688 |
+ newKey[p] = key[p]; |
|
689 |
+ } |
|
690 |
+ } |
|
691 |
+ return newKey; |
|
692 |
+ }); |
|
693 |
+ }; |
|
694 |
+ |
|
695 |
+ for (var i = 0; i < propertyNames.length; i++) loop( i ); |
|
696 |
+ return properties; |
|
697 |
+} |
|
698 |
+ |
|
699 |
+function getProperties(tweenSettings, params) { |
|
700 |
+ var properties = []; |
|
701 |
+ var keyframes = params.keyframes; |
|
702 |
+ if (keyframes) { params = mergeObjects(flattenKeyframes(keyframes), params); } |
|
703 |
+ for (var p in params) { |
|
704 |
+ if (is.key(p)) { |
|
705 |
+ properties.push({ |
|
706 |
+ name: p, |
|
707 |
+ tweens: normalizePropertyTweens(params[p], tweenSettings) |
|
708 |
+ }); |
|
709 |
+ } |
|
710 |
+ } |
|
711 |
+ return properties; |
|
712 |
+} |
|
713 |
+ |
|
714 |
+// Tweens |
|
715 |
+ |
|
716 |
+function normalizeTweenValues(tween, animatable) { |
|
717 |
+ var t = {}; |
|
718 |
+ for (var p in tween) { |
|
719 |
+ var value = getFunctionValue(tween[p], animatable); |
|
720 |
+ if (is.arr(value)) { |
|
721 |
+ value = value.map(function (v) { return getFunctionValue(v, animatable); }); |
|
722 |
+ if (value.length === 1) { value = value[0]; } |
|
723 |
+ } |
|
724 |
+ t[p] = value; |
|
725 |
+ } |
|
726 |
+ t.duration = parseFloat(t.duration); |
|
727 |
+ t.delay = parseFloat(t.delay); |
|
728 |
+ return t; |
|
729 |
+} |
|
730 |
+ |
|
731 |
+function normalizeTweens(prop, animatable) { |
|
732 |
+ var previousTween; |
|
733 |
+ return prop.tweens.map(function (t) { |
|
734 |
+ var tween = normalizeTweenValues(t, animatable); |
|
735 |
+ var tweenValue = tween.value; |
|
736 |
+ var to = is.arr(tweenValue) ? tweenValue[1] : tweenValue; |
|
737 |
+ var toUnit = getUnit(to); |
|
738 |
+ var originalValue = getOriginalTargetValue(animatable.target, prop.name, toUnit, animatable); |
|
739 |
+ var previousValue = previousTween ? previousTween.to.original : originalValue; |
|
740 |
+ var from = is.arr(tweenValue) ? tweenValue[0] : previousValue; |
|
741 |
+ var fromUnit = getUnit(from) || getUnit(originalValue); |
|
742 |
+ var unit = toUnit || fromUnit; |
|
743 |
+ if (is.und(to)) { to = previousValue; } |
|
744 |
+ tween.from = decomposeValue(from, unit); |
|
745 |
+ tween.to = decomposeValue(getRelativeValue(to, from), unit); |
|
746 |
+ tween.start = previousTween ? previousTween.end : 0; |
|
747 |
+ tween.end = tween.start + tween.delay + tween.duration + tween.endDelay; |
|
748 |
+ tween.easing = parseEasings(tween.easing, tween.duration); |
|
749 |
+ tween.isPath = is.pth(tweenValue); |
|
750 |
+ tween.isColor = is.col(tween.from.original); |
|
751 |
+ if (tween.isColor) { tween.round = 1; } |
|
752 |
+ previousTween = tween; |
|
753 |
+ return tween; |
|
754 |
+ }); |
|
755 |
+} |
|
756 |
+ |
|
757 |
+// Tween progress |
|
758 |
+ |
|
759 |
+var setProgressValue = { |
|
760 |
+ css: function (t, p, v) { return t.style[p] = v; }, |
|
761 |
+ attribute: function (t, p, v) { return t.setAttribute(p, v); }, |
|
762 |
+ object: function (t, p, v) { return t[p] = v; }, |
|
763 |
+ transform: function (t, p, v, transforms, manual) { |
|
764 |
+ transforms.list.set(p, v); |
|
765 |
+ if (p === transforms.last || manual) { |
|
766 |
+ var str = ''; |
|
767 |
+ transforms.list.forEach(function (value, prop) { str += prop + "(" + value + ") "; }); |
|
768 |
+ t.style.transform = str; |
|
769 |
+ } |
|
770 |
+ } |
|
771 |
+}; |
|
772 |
+ |
|
773 |
+// Set Value helper |
|
774 |
+ |
|
775 |
+function setTargetsValue(targets, properties) { |
|
776 |
+ var animatables = getAnimatables(targets); |
|
777 |
+ animatables.forEach(function (animatable) { |
|
778 |
+ for (var property in properties) { |
|
779 |
+ var value = getFunctionValue(properties[property], animatable); |
|
780 |
+ var target = animatable.target; |
|
781 |
+ var valueUnit = getUnit(value); |
|
782 |
+ var originalValue = getOriginalTargetValue(target, property, valueUnit, animatable); |
|
783 |
+ var unit = valueUnit || getUnit(originalValue); |
|
784 |
+ var to = getRelativeValue(validateValue(value, unit), originalValue); |
|
785 |
+ var animType = getAnimationType(target, property); |
|
786 |
+ setProgressValue[animType](target, property, to, animatable.transforms, true); |
|
787 |
+ } |
|
788 |
+ }); |
|
789 |
+} |
|
790 |
+ |
|
791 |
+// Animations |
|
792 |
+ |
|
793 |
+function createAnimation(animatable, prop) { |
|
794 |
+ var animType = getAnimationType(animatable.target, prop.name); |
|
795 |
+ if (animType) { |
|
796 |
+ var tweens = normalizeTweens(prop, animatable); |
|
797 |
+ var lastTween = tweens[tweens.length - 1]; |
|
798 |
+ return { |
|
799 |
+ type: animType, |
|
800 |
+ property: prop.name, |
|
801 |
+ animatable: animatable, |
|
802 |
+ tweens: tweens, |
|
803 |
+ duration: lastTween.end, |
|
804 |
+ delay: tweens[0].delay, |
|
805 |
+ endDelay: lastTween.endDelay |
|
806 |
+ } |
|
807 |
+ } |
|
808 |
+} |
|
809 |
+ |
|
810 |
+function getAnimations(animatables, properties) { |
|
811 |
+ return filterArray(flattenArray(animatables.map(function (animatable) { |
|
812 |
+ return properties.map(function (prop) { |
|
813 |
+ return createAnimation(animatable, prop); |
|
814 |
+ }); |
|
815 |
+ })), function (a) { return !is.und(a); }); |
|
816 |
+} |
|
817 |
+ |
|
818 |
+// Create Instance |
|
819 |
+ |
|
820 |
+function getInstanceTimings(animations, tweenSettings) { |
|
821 |
+ var animLength = animations.length; |
|
822 |
+ var getTlOffset = function (anim) { return anim.timelineOffset ? anim.timelineOffset : 0; }; |
|
823 |
+ var timings = {}; |
|
824 |
+ timings.duration = animLength ? Math.max.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.duration; })) : tweenSettings.duration; |
|
825 |
+ timings.delay = animLength ? Math.min.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.delay; })) : tweenSettings.delay; |
|
826 |
+ timings.endDelay = animLength ? timings.duration - Math.max.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.duration - anim.endDelay; })) : tweenSettings.endDelay; |
|
827 |
+ return timings; |
|
828 |
+} |
|
829 |
+ |
|
830 |
+var instanceID = 0; |
|
831 |
+ |
|
832 |
+function createNewInstance(params) { |
|
833 |
+ var instanceSettings = replaceObjectProps(defaultInstanceSettings, params); |
|
834 |
+ var tweenSettings = replaceObjectProps(defaultTweenSettings, params); |
|
835 |
+ var properties = getProperties(tweenSettings, params); |
|
836 |
+ var animatables = getAnimatables(params.targets); |
|
837 |
+ var animations = getAnimations(animatables, properties); |
|
838 |
+ var timings = getInstanceTimings(animations, tweenSettings); |
|
839 |
+ var id = instanceID; |
|
840 |
+ instanceID++; |
|
841 |
+ return mergeObjects(instanceSettings, { |
|
842 |
+ id: id, |
|
843 |
+ children: [], |
|
844 |
+ animatables: animatables, |
|
845 |
+ animations: animations, |
|
846 |
+ duration: timings.duration, |
|
847 |
+ delay: timings.delay, |
|
848 |
+ endDelay: timings.endDelay |
|
849 |
+ }); |
|
850 |
+} |
|
851 |
+ |
|
852 |
+// Core |
|
853 |
+ |
|
854 |
+var activeInstances = []; |
|
855 |
+var pausedInstances = []; |
|
856 |
+var raf; |
|
857 |
+ |
|
858 |
+var engine = (function () { |
|
859 |
+ function play() { |
|
860 |
+ raf = requestAnimationFrame(step); |
|
861 |
+ } |
|
862 |
+ function step(t) { |
|
863 |
+ var activeInstancesLength = activeInstances.length; |
|
864 |
+ if (activeInstancesLength) { |
|
865 |
+ var i = 0; |
|
866 |
+ while (i < activeInstancesLength) { |
|
867 |
+ var activeInstance = activeInstances[i]; |
|
868 |
+ if (!activeInstance.paused) { |
|
869 |
+ activeInstance.tick(t); |
|
870 |
+ } else { |
|
871 |
+ var instanceIndex = activeInstances.indexOf(activeInstance); |
|
872 |
+ if (instanceIndex > -1) { |
|
873 |
+ activeInstances.splice(instanceIndex, 1); |
|
874 |
+ activeInstancesLength = activeInstances.length; |
|
875 |
+ } |
|
876 |
+ } |
|
877 |
+ i++; |
|
878 |
+ } |
|
879 |
+ play(); |
|
880 |
+ } else { |
|
881 |
+ raf = cancelAnimationFrame(raf); |
|
882 |
+ } |
|
883 |
+ } |
|
884 |
+ return play; |
|
885 |
+})(); |
|
886 |
+ |
|
887 |
+function handleVisibilityChange() { |
|
888 |
+ if (document.hidden) { |
|
889 |
+ activeInstances.forEach(function (ins) { return ins.pause(); }); |
|
890 |
+ pausedInstances = activeInstances.slice(0); |
|
891 |
+ anime.running = activeInstances = []; |
|
892 |
+ } else { |
|
893 |
+ pausedInstances.forEach(function (ins) { return ins.play(); }); |
|
894 |
+ } |
|
895 |
+} |
|
896 |
+ |
|
897 |
+if (typeof document !== 'undefined') { |
|
898 |
+ document.addEventListener('visibilitychange', handleVisibilityChange); |
|
899 |
+} |
|
900 |
+ |
|
901 |
+// Public Instance |
|
902 |
+ |
|
903 |
+function anime(params) { |
|
904 |
+ if ( params === void 0 ) params = {}; |
|
905 |
+ |
|
906 |
+ |
|
907 |
+ var startTime = 0, lastTime = 0, now = 0; |
|
908 |
+ var children, childrenLength = 0; |
|
909 |
+ var resolve = null; |
|
910 |
+ |
|
911 |
+ function makePromise(instance) { |
|
912 |
+ var promise = window.Promise && new Promise(function (_resolve) { return resolve = _resolve; }); |
|
913 |
+ instance.finished = promise; |
|
914 |
+ return promise; |
|
915 |
+ } |
|
916 |
+ |
|
917 |
+ var instance = createNewInstance(params); |
|
918 |
+ var promise = makePromise(instance); |
|
919 |
+ |
|
920 |
+ function toggleInstanceDirection() { |
|
921 |
+ var direction = instance.direction; |
|
922 |
+ if (direction !== 'alternate') { |
|
923 |
+ instance.direction = direction !== 'normal' ? 'normal' : 'reverse'; |
|
924 |
+ } |
|
925 |
+ instance.reversed = !instance.reversed; |
|
926 |
+ children.forEach(function (child) { return child.reversed = instance.reversed; }); |
|
927 |
+ } |
|
928 |
+ |
|
929 |
+ function adjustTime(time) { |
|
930 |
+ return instance.reversed ? instance.duration - time : time; |
|
931 |
+ } |
|
932 |
+ |
|
933 |
+ function resetTime() { |
|
934 |
+ startTime = 0; |
|
935 |
+ lastTime = adjustTime(instance.currentTime) * (1 / anime.speed); |
|
936 |
+ } |
|
937 |
+ |
|
938 |
+ function seekChild(time, child) { |
|
939 |
+ if (child) { child.seek(time - child.timelineOffset); } |
|
940 |
+ } |
|
941 |
+ |
|
942 |
+ function syncInstanceChildren(time) { |
|
943 |
+ if (!instance.reversePlayback) { |
|
944 |
+ for (var i = 0; i < childrenLength; i++) { seekChild(time, children[i]); } |
|
945 |
+ } else { |
|
946 |
+ for (var i$1 = childrenLength; i$1--;) { seekChild(time, children[i$1]); } |
|
947 |
+ } |
|
948 |
+ } |
|
949 |
+ |
|
950 |
+ function setAnimationsProgress(insTime) { |
|
951 |
+ var i = 0; |
|
952 |
+ var animations = instance.animations; |
|
953 |
+ var animationsLength = animations.length; |
|
954 |
+ while (i < animationsLength) { |
|
955 |
+ var anim = animations[i]; |
|
956 |
+ var animatable = anim.animatable; |
|
957 |
+ var tweens = anim.tweens; |
|
958 |
+ var tweenLength = tweens.length - 1; |
|
959 |
+ var tween = tweens[tweenLength]; |
|
960 |
+ // Only check for keyframes if there is more than one tween |
|
961 |
+ if (tweenLength) { tween = filterArray(tweens, function (t) { return (insTime < t.end); })[0] || tween; } |
|
962 |
+ var elapsed = minMax(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration; |
|
963 |
+ var eased = isNaN(elapsed) ? 1 : tween.easing(elapsed); |
|
964 |
+ var strings = tween.to.strings; |
|
965 |
+ var round = tween.round; |
|
966 |
+ var numbers = []; |
|
967 |
+ var toNumbersLength = tween.to.numbers.length; |
|
968 |
+ var progress = (void 0); |
|
969 |
+ for (var n = 0; n < toNumbersLength; n++) { |
|
970 |
+ var value = (void 0); |
|
971 |
+ var toNumber = tween.to.numbers[n]; |
|
972 |
+ var fromNumber = tween.from.numbers[n] || 0; |
|
973 |
+ if (!tween.isPath) { |
|
974 |
+ value = fromNumber + (eased * (toNumber - fromNumber)); |
|
975 |
+ } else { |
|
976 |
+ value = getPathProgress(tween.value, eased * toNumber); |
|
977 |
+ } |
|
978 |
+ if (round) { |
|
979 |
+ if (!(tween.isColor && n > 2)) { |
|
980 |
+ value = Math.round(value * round) / round; |
|
981 |
+ } |
|
982 |
+ } |
|
983 |
+ numbers.push(value); |
|
984 |
+ } |
|
985 |
+ // Manual Array.reduce for better performances |
|
986 |
+ var stringsLength = strings.length; |
|
987 |
+ if (!stringsLength) { |
|
988 |
+ progress = numbers[0]; |
|
989 |
+ } else { |
|
990 |
+ progress = strings[0]; |
|
991 |
+ for (var s = 0; s < stringsLength; s++) { |
|
992 |
+ var a = strings[s]; |
|
993 |
+ var b = strings[s + 1]; |
|
994 |
+ var n$1 = numbers[s]; |
|
995 |
+ if (!isNaN(n$1)) { |
|
996 |
+ if (!b) { |
|
997 |
+ progress += n$1 + ' '; |
|
998 |
+ } else { |
|
999 |
+ progress += n$1 + b; |
|
1000 |
+ } |
|
1001 |
+ } |
|
1002 |
+ } |
|
1003 |
+ } |
|
1004 |
+ setProgressValue[anim.type](animatable.target, anim.property, progress, animatable.transforms); |
|
1005 |
+ anim.currentValue = progress; |
|
1006 |
+ i++; |
|
1007 |
+ } |
|
1008 |
+ } |
|
1009 |
+ |
|
1010 |
+ function setCallback(cb) { |
|
1011 |
+ if (instance[cb] && !instance.passThrough) { instance[cb](instance); } |
|
1012 |
+ } |
|
1013 |
+ |
|
1014 |
+ function countIteration() { |
|
1015 |
+ if (instance.remaining && instance.remaining !== true) { |
|
1016 |
+ instance.remaining--; |
|
1017 |
+ } |
|
1018 |
+ } |
|
1019 |
+ |
|
1020 |
+ function setInstanceProgress(engineTime) { |
|
1021 |
+ var insDuration = instance.duration; |
|
1022 |
+ var insDelay = instance.delay; |
|
1023 |
+ var insEndDelay = insDuration - instance.endDelay; |
|
1024 |
+ var insTime = adjustTime(engineTime); |
|
1025 |
+ instance.progress = minMax((insTime / insDuration) * 100, 0, 100); |
|
1026 |
+ instance.reversePlayback = insTime < instance.currentTime; |
|
1027 |
+ if (children) { syncInstanceChildren(insTime); } |
|
1028 |
+ if (!instance.began && instance.currentTime > 0) { |
|
1029 |
+ instance.began = true; |
|
1030 |
+ setCallback('begin'); |
|
1031 |
+ } |
|
1032 |
+ if (!instance.loopBegan && instance.currentTime > 0) { |
|
1033 |
+ instance.loopBegan = true; |
|
1034 |
+ setCallback('loopBegin'); |
|
1035 |
+ } |
|
1036 |
+ if (insTime <= insDelay && instance.currentTime !== 0) { |
|
1037 |
+ setAnimationsProgress(0); |
|
1038 |
+ } |
|
1039 |
+ if ((insTime >= insEndDelay && instance.currentTime !== insDuration) || !insDuration) { |
|
1040 |
+ setAnimationsProgress(insDuration); |
|
1041 |
+ } |
|
1042 |
+ if (insTime > insDelay && insTime < insEndDelay) { |
|
1043 |
+ if (!instance.changeBegan) { |
|
1044 |
+ instance.changeBegan = true; |
|
1045 |
+ instance.changeCompleted = false; |
|
1046 |
+ setCallback('changeBegin'); |
|
1047 |
+ } |
|
1048 |
+ setCallback('change'); |
|
1049 |
+ setAnimationsProgress(insTime); |
|
1050 |
+ } else { |
|
1051 |
+ if (instance.changeBegan) { |
|
1052 |
+ instance.changeCompleted = true; |
|
1053 |
+ instance.changeBegan = false; |
|
1054 |
+ setCallback('changeComplete'); |
|
1055 |
+ } |
|
1056 |
+ } |
|
1057 |
+ instance.currentTime = minMax(insTime, 0, insDuration); |
|
1058 |
+ if (instance.began) { setCallback('update'); } |
|
1059 |
+ if (engineTime >= insDuration) { |
|
1060 |
+ lastTime = 0; |
|
1061 |
+ countIteration(); |
|
1062 |
+ if (!instance.remaining) { |
|
1063 |
+ instance.paused = true; |
|
1064 |
+ if (!instance.completed) { |
|
1065 |
+ instance.completed = true; |
|
1066 |
+ setCallback('loopComplete'); |
|
1067 |
+ setCallback('complete'); |
|
1068 |
+ if (!instance.passThrough && 'Promise' in window) { |
|
1069 |
+ resolve(); |
|
1070 |
+ promise = makePromise(instance); |
|
1071 |
+ } |
|
1072 |
+ } |
|
1073 |
+ } else { |
|
1074 |
+ startTime = now; |
|
1075 |
+ setCallback('loopComplete'); |
|
1076 |
+ instance.loopBegan = false; |
|
1077 |
+ if (instance.direction === 'alternate') { |
|
1078 |
+ toggleInstanceDirection(); |
|
1079 |
+ } |
|
1080 |
+ } |
|
1081 |
+ } |
|
1082 |
+ } |
|
1083 |
+ |
|
1084 |
+ instance.reset = function() { |
|
1085 |
+ var direction = instance.direction; |
|
1086 |
+ instance.passThrough = false; |
|
1087 |
+ instance.currentTime = 0; |
|
1088 |
+ instance.progress = 0; |
|
1089 |
+ instance.paused = true; |
|
1090 |
+ instance.began = false; |
|
1091 |
+ instance.loopBegan = false; |
|
1092 |
+ instance.changeBegan = false; |
|
1093 |
+ instance.completed = false; |
|
1094 |
+ instance.changeCompleted = false; |
|
1095 |
+ instance.reversePlayback = false; |
|
1096 |
+ instance.reversed = direction === 'reverse'; |
|
1097 |
+ instance.remaining = instance.loop; |
|
1098 |
+ children = instance.children; |
|
1099 |
+ childrenLength = children.length; |
|
1100 |
+ for (var i = childrenLength; i--;) { instance.children[i].reset(); } |
|
1101 |
+ if (instance.reversed && instance.loop !== true || (direction === 'alternate' && instance.loop === 1)) { instance.remaining++; } |
|
1102 |
+ setAnimationsProgress(instance.reversed ? instance.duration : 0); |
|
1103 |
+ }; |
|
1104 |
+ |
|
1105 |
+ // Set Value helper |
|
1106 |
+ |
|
1107 |
+ instance.set = function(targets, properties) { |
|
1108 |
+ setTargetsValue(targets, properties); |
|
1109 |
+ return instance; |
|
1110 |
+ }; |
|
1111 |
+ |
|
1112 |
+ instance.tick = function(t) { |
|
1113 |
+ now = t; |
|
1114 |
+ if (!startTime) { startTime = now; } |
|
1115 |
+ setInstanceProgress((now + (lastTime - startTime)) * anime.speed); |
|
1116 |
+ }; |
|
1117 |
+ |
|
1118 |
+ instance.seek = function(time) { |
|
1119 |
+ setInstanceProgress(adjustTime(time)); |
|
1120 |
+ }; |
|
1121 |
+ |
|
1122 |
+ instance.pause = function() { |
|
1123 |
+ instance.paused = true; |
|
1124 |
+ resetTime(); |
|
1125 |
+ }; |
|
1126 |
+ |
|
1127 |
+ instance.play = function() { |
|
1128 |
+ if (!instance.paused) { return; } |
|
1129 |
+ if (instance.completed) { instance.reset(); } |
|
1130 |
+ instance.paused = false; |
|
1131 |
+ activeInstances.push(instance); |
|
1132 |
+ resetTime(); |
|
1133 |
+ if (!raf) { engine(); } |
|
1134 |
+ }; |
|
1135 |
+ |
|
1136 |
+ instance.reverse = function() { |
|
1137 |
+ toggleInstanceDirection(); |
|
1138 |
+ instance.completed = instance.reversed ? false : true; |
|
1139 |
+ resetTime(); |
|
1140 |
+ }; |
|
1141 |
+ |
|
1142 |
+ instance.restart = function() { |
|
1143 |
+ instance.reset(); |
|
1144 |
+ instance.play(); |
|
1145 |
+ }; |
|
1146 |
+ |
|
1147 |
+ instance.reset(); |
|
1148 |
+ |
|
1149 |
+ if (instance.autoplay) { instance.play(); } |
|
1150 |
+ |
|
1151 |
+ return instance; |
|
1152 |
+ |
|
1153 |
+} |
|
1154 |
+ |
|
1155 |
+// Remove targets from animation |
|
1156 |
+ |
|
1157 |
+function removeTargetsFromAnimations(targetsArray, animations) { |
|
1158 |
+ for (var a = animations.length; a--;) { |
|
1159 |
+ if (arrayContains(targetsArray, animations[a].animatable.target)) { |
|
1160 |
+ animations.splice(a, 1); |
|
1161 |
+ } |
|
1162 |
+ } |
|
1163 |
+} |
|
1164 |
+ |
|
1165 |
+function removeTargets(targets) { |
|
1166 |
+ var targetsArray = parseTargets(targets); |
|
1167 |
+ for (var i = activeInstances.length; i--;) { |
|
1168 |
+ var instance = activeInstances[i]; |
|
1169 |
+ var animations = instance.animations; |
|
1170 |
+ var children = instance.children; |
|
1171 |
+ removeTargetsFromAnimations(targetsArray, animations); |
|
1172 |
+ for (var c = children.length; c--;) { |
|
1173 |
+ var child = children[c]; |
|
1174 |
+ var childAnimations = child.animations; |
|
1175 |
+ removeTargetsFromAnimations(targetsArray, childAnimations); |
|
1176 |
+ if (!childAnimations.length && !child.children.length) { children.splice(c, 1); } |
|
1177 |
+ } |
|
1178 |
+ if (!animations.length && !children.length) { instance.pause(); } |
|
1179 |
+ } |
|
1180 |
+} |
|
1181 |
+ |
|
1182 |
+// Stagger helpers |
|
1183 |
+ |
|
1184 |
+function stagger(val, params) { |
|
1185 |
+ if ( params === void 0 ) params = {}; |
|
1186 |
+ |
|
1187 |
+ var direction = params.direction || 'normal'; |
|
1188 |
+ var easing = params.easing ? parseEasings(params.easing) : null; |
|
1189 |
+ var grid = params.grid; |
|
1190 |
+ var axis = params.axis; |
|
1191 |
+ var fromIndex = params.from || 0; |
|
1192 |
+ var fromFirst = fromIndex === 'first'; |
|
1193 |
+ var fromCenter = fromIndex === 'center'; |
|
1194 |
+ var fromLast = fromIndex === 'last'; |
|
1195 |
+ var isRange = is.arr(val); |
|
1196 |
+ var val1 = isRange ? parseFloat(val[0]) : parseFloat(val); |
|
1197 |
+ var val2 = isRange ? parseFloat(val[1]) : 0; |
|
1198 |
+ var unit = getUnit(isRange ? val[1] : val) || 0; |
|
1199 |
+ var start = params.start || 0 + (isRange ? val1 : 0); |
|
1200 |
+ var values = []; |
|
1201 |
+ var maxValue = 0; |
|
1202 |
+ return function (el, i, t) { |
|
1203 |
+ if (fromFirst) { fromIndex = 0; } |
|
1204 |
+ if (fromCenter) { fromIndex = (t - 1) / 2; } |
|
1205 |
+ if (fromLast) { fromIndex = t - 1; } |
|
1206 |
+ if (!values.length) { |
|
1207 |
+ for (var index = 0; index < t; index++) { |
|
1208 |
+ if (!grid) { |
|
1209 |
+ values.push(Math.abs(fromIndex - index)); |
|
1210 |
+ } else { |
|
1211 |
+ var fromX = !fromCenter ? fromIndex%grid[0] : (grid[0]-1)/2; |
|
1212 |
+ var fromY = !fromCenter ? Math.floor(fromIndex/grid[0]) : (grid[1]-1)/2; |
|
1213 |
+ var toX = index%grid[0]; |
|
1214 |
+ var toY = Math.floor(index/grid[0]); |
|
1215 |
+ var distanceX = fromX - toX; |
|
1216 |
+ var distanceY = fromY - toY; |
|
1217 |
+ var value = Math.sqrt(distanceX * distanceX + distanceY * distanceY); |
|
1218 |
+ if (axis === 'x') { value = -distanceX; } |
|
1219 |
+ if (axis === 'y') { value = -distanceY; } |
|
1220 |
+ values.push(value); |
|
1221 |
+ } |
|
1222 |
+ maxValue = Math.max.apply(Math, values); |
|
1223 |
+ } |
|
1224 |
+ if (easing) { values = values.map(function (val) { return easing(val / maxValue) * maxValue; }); } |
|
1225 |
+ if (direction === 'reverse') { values = values.map(function (val) { return axis ? (val < 0) ? val * -1 : -val : Math.abs(maxValue - val); }); } |
|
1226 |
+ } |
|
1227 |
+ var spacing = isRange ? (val2 - val1) / maxValue : val1; |
|
1228 |
+ return start + (spacing * (Math.round(values[i] * 100) / 100)) + unit; |
|
1229 |
+ } |
|
1230 |
+} |
|
1231 |
+ |
|
1232 |
+// Timeline |
|
1233 |
+ |
|
1234 |
+function timeline(params) { |
|
1235 |
+ if ( params === void 0 ) params = {}; |
|
1236 |
+ |
|
1237 |
+ var tl = anime(params); |
|
1238 |
+ tl.duration = 0; |
|
1239 |
+ tl.add = function(instanceParams, timelineOffset) { |
|
1240 |
+ var tlIndex = activeInstances.indexOf(tl); |
|
1241 |
+ var children = tl.children; |
|
1242 |
+ if (tlIndex > -1) { activeInstances.splice(tlIndex, 1); } |
|
1243 |
+ function passThrough(ins) { ins.passThrough = true; } |
|
1244 |
+ for (var i = 0; i < children.length; i++) { passThrough(children[i]); } |
|
1245 |
+ var insParams = mergeObjects(instanceParams, replaceObjectProps(defaultTweenSettings, params)); |
|
1246 |
+ insParams.targets = insParams.targets || params.targets; |
|
1247 |
+ var tlDuration = tl.duration; |
|
1248 |
+ insParams.autoplay = false; |
|
1249 |
+ insParams.direction = tl.direction; |
|
1250 |
+ insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration); |
|
1251 |
+ passThrough(tl); |
|
1252 |
+ tl.seek(insParams.timelineOffset); |
|
1253 |
+ var ins = anime(insParams); |
|
1254 |
+ passThrough(ins); |
|
1255 |
+ children.push(ins); |
|
1256 |
+ var timings = getInstanceTimings(children, params); |
|
1257 |
+ tl.delay = timings.delay; |
|
1258 |
+ tl.endDelay = timings.endDelay; |
|
1259 |
+ tl.duration = timings.duration; |
|
1260 |
+ tl.seek(0); |
|
1261 |
+ tl.reset(); |
|
1262 |
+ if (tl.autoplay) { tl.play(); } |
|
1263 |
+ return tl; |
|
1264 |
+ }; |
|
1265 |
+ return tl; |
|
1266 |
+} |
|
1267 |
+ |
|
1268 |
+anime.version = '3.2.0'; |
|
1269 |
+anime.speed = 1; |
|
1270 |
+anime.running = activeInstances; |
|
1271 |
+anime.remove = removeTargets; |
|
1272 |
+anime.get = getOriginalTargetValue; |
|
1273 |
+anime.set = setTargetsValue; |
|
1274 |
+anime.convertPx = convertPxToUnit; |
|
1275 |
+anime.path = getPath; |
|
1276 |
+anime.setDashoffset = setDashoffset; |
|
1277 |
+anime.stagger = stagger; |
|
1278 |
+anime.timeline = timeline; |
|
1279 |
+anime.easing = parseEasings; |
|
1280 |
+anime.penner = penner; |
|
1281 |
+anime.random = function (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }; |
|
1282 |
+ |
|
1283 |
+module.exports = anime; |
0 | 1284 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,8 @@ |
1 |
+/* |
|
2 |
+ * anime.js v3.2.0 |
|
3 |
+ * (c) 2020 Julian Garnier |
|
4 |
+ * Released under the MIT license |
|
5 |
+ * animejs.com |
|
6 |
+ */ |
|
7 |
+ |
|
8 |
+!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.anime=e()}(this,function(){"use strict";var n={update:null,begin:null,loopBegin:null,changeBegin:null,change:null,changeComplete:null,loopComplete:null,complete:null,loop:1,direction:"normal",autoplay:!0,timelineOffset:0},e={duration:1e3,delay:0,endDelay:0,easing:"easeOutElastic(1, .5)",round:0},r=["translateX","translateY","translateZ","rotate","rotateX","rotateY","rotateZ","scale","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective","matrix","matrix3d"],t={CSS:{},springs:{}};function a(n,e,r){return Math.min(Math.max(n,e),r)}function o(n,e){return n.indexOf(e)>-1}function u(n,e){return n.apply(null,e)}var i={arr:function(n){return Array.isArray(n)},obj:function(n){return o(Object.prototype.toString.call(n),"Object")},pth:function(n){return i.obj(n)&&n.hasOwnProperty("totalLength")},svg:function(n){return n instanceof SVGElement},inp:function(n){return n instanceof HTMLInputElement},dom:function(n){return n.nodeType||i.svg(n)},str:function(n){return"string"==typeof n},fnc:function(n){return"function"==typeof n},und:function(n){return void 0===n},hex:function(n){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(n)},rgb:function(n){return/^rgb/.test(n)},hsl:function(n){return/^hsl/.test(n)},col:function(n){return i.hex(n)||i.rgb(n)||i.hsl(n)},key:function(r){return!n.hasOwnProperty(r)&&!e.hasOwnProperty(r)&&"targets"!==r&&"keyframes"!==r}};function c(n){var e=/\(([^)]+)\)/.exec(n);return e?e[1].split(",").map(function(n){return parseFloat(n)}):[]}function s(n,e){var r=c(n),o=a(i.und(r[0])?1:r[0],.1,100),u=a(i.und(r[1])?100:r[1],.1,100),s=a(i.und(r[2])?10:r[2],.1,100),f=a(i.und(r[3])?0:r[3],.1,100),l=Math.sqrt(u/o),d=s/(2*Math.sqrt(u*o)),p=d<1?l*Math.sqrt(1-d*d):0,h=1,v=d<1?(d*l-f)/p:-f+l;function g(n){var r=e?e*n/1e3:n;return r=d<1?Math.exp(-r*d*l)*(h*Math.cos(p*r)+v*Math.sin(p*r)):(h+v*r)*Math.exp(-r*l),0===n||1===n?n:1-r}return e?g:function(){var e=t.springs[n];if(e)return e;for(var r=0,a=0;;)if(1===g(r+=1/6)){if(++a>=16)break}else a=0;var o=r*(1/6)*1e3;return t.springs[n]=o,o}}function f(n){return void 0===n&&(n=10),function(e){return Math.ceil(a(e,1e-6,1)*n)*(1/n)}}var l,d,p=function(){var n=11,e=1/(n-1);function r(n,e){return 1-3*e+3*n}function t(n,e){return 3*e-6*n}function a(n){return 3*n}function o(n,e,o){return((r(e,o)*n+t(e,o))*n+a(e))*n}function u(n,e,o){return 3*r(e,o)*n*n+2*t(e,o)*n+a(e)}return function(r,t,a,i){if(0<=r&&r<=1&&0<=a&&a<=1){var c=new Float32Array(n);if(r!==t||a!==i)for(var s=0;s<n;++s)c[s]=o(s*e,r,a);return function(n){return r===t&&a===i?n:0===n||1===n?n:o(f(n),t,i)}}function f(t){for(var i=0,s=1,f=n-1;s!==f&&c[s]<=t;++s)i+=e;var l=i+(t-c[--s])/(c[s+1]-c[s])*e,d=u(l,r,a);return d>=.001?function(n,e,r,t){for(var a=0;a<4;++a){var i=u(e,r,t);if(0===i)return e;e-=(o(e,r,t)-n)/i}return e}(t,l,r,a):0===d?l:function(n,e,r,t,a){for(var u,i,c=0;(u=o(i=e+(r-e)/2,t,a)-n)>0?r=i:e=i,Math.abs(u)>1e-7&&++c<10;);return i}(t,i,i+e,r,a)}}}(),h=(l={linear:function(){return function(n){return n}}},d={Sine:function(){return function(n){return 1-Math.cos(n*Math.PI/2)}},Circ:function(){return function(n){return 1-Math.sqrt(1-n*n)}},Back:function(){return function(n){return n*n*(3*n-2)}},Bounce:function(){return function(n){for(var e,r=4;n<((e=Math.pow(2,--r))-1)/11;);return 1/Math.pow(4,3-r)-7.5625*Math.pow((3*e-2)/22-n,2)}},Elastic:function(n,e){void 0===n&&(n=1),void 0===e&&(e=.5);var r=a(n,1,10),t=a(e,.1,2);return function(n){return 0===n||1===n?n:-r*Math.pow(2,10*(n-1))*Math.sin((n-1-t/(2*Math.PI)*Math.asin(1/r))*(2*Math.PI)/t)}}},["Quad","Cubic","Quart","Quint","Expo"].forEach(function(n,e){d[n]=function(){return function(n){return Math.pow(n,e+2)}}}),Object.keys(d).forEach(function(n){var e=d[n];l["easeIn"+n]=e,l["easeOut"+n]=function(n,r){return function(t){return 1-e(n,r)(1-t)}},l["easeInOut"+n]=function(n,r){return function(t){return t<.5?e(n,r)(2*t)/2:1-e(n,r)(-2*t+2)/2}}}),l);function v(n,e){if(i.fnc(n))return n;var r=n.split("(")[0],t=h[r],a=c(n);switch(r){case"spring":return s(n,e);case"cubicBezier":return u(p,a);case"steps":return u(f,a);default:return u(t,a)}}function g(n){try{return document.querySelectorAll(n)}catch(n){return}}function m(n,e){for(var r=n.length,t=arguments.length>=2?arguments[1]:void 0,a=[],o=0;o<r;o++)if(o in n){var u=n[o];e.call(t,u,o,n)&&a.push(u)}return a}function y(n){return n.reduce(function(n,e){return n.concat(i.arr(e)?y(e):e)},[])}function b(n){return i.arr(n)?n:(i.str(n)&&(n=g(n)||n),n instanceof NodeList||n instanceof HTMLCollection?[].slice.call(n):[n])}function x(n,e){return n.some(function(n){return n===e})}function M(n){var e={};for(var r in n)e[r]=n[r];return e}function w(n,e){var r=M(n);for(var t in n)r[t]=e.hasOwnProperty(t)?e[t]:n[t];return r}function k(n,e){var r=M(n);for(var t in e)r[t]=i.und(n[t])?e[t]:n[t];return r}function O(n){return i.rgb(n)?(r=/rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g.exec(e=n))?"rgba("+r[1]+",1)":e:i.hex(n)?(t=n.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(n,e,r,t){return e+e+r+r+t+t}),a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t),"rgba("+parseInt(a[1],16)+","+parseInt(a[2],16)+","+parseInt(a[3],16)+",1)"):i.hsl(n)?function(n){var e,r,t,a=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(n)||/hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(n),o=parseInt(a[1],10)/360,u=parseInt(a[2],10)/100,i=parseInt(a[3],10)/100,c=a[4]||1;function s(n,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?n+6*(e-n)*r:r<.5?e:r<2/3?n+(e-n)*(2/3-r)*6:n}if(0==u)e=r=t=i;else{var f=i<.5?i*(1+u):i+u-i*u,l=2*i-f;e=s(l,f,o+1/3),r=s(l,f,o),t=s(l,f,o-1/3)}return"rgba("+255*e+","+255*r+","+255*t+","+c+")"}(n):void 0;var e,r,t,a}function C(n){var e=/[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(n);if(e)return e[1]}function B(n,e){return i.fnc(n)?n(e.target,e.id,e.total):n}function P(n,e){return n.getAttribute(e)}function I(n,e,r){if(x([r,"deg","rad","turn"],C(e)))return e;var a=t.CSS[e+r];if(!i.und(a))return a;var o=document.createElement(n.tagName),u=n.parentNode&&n.parentNode!==document?n.parentNode:document.body;u.appendChild(o),o.style.position="absolute",o.style.width=100+r;var c=100/o.offsetWidth;u.removeChild(o);var s=c*parseFloat(e);return t.CSS[e+r]=s,s}function T(n,e,r){if(e in n.style){var t=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),a=n.style[e]||getComputedStyle(n).getPropertyValue(t)||"0";return r?I(n,a,r):a}}function D(n,e){return i.dom(n)&&!i.inp(n)&&(P(n,e)||i.svg(n)&&n[e])?"attribute":i.dom(n)&&x(r,e)?"transform":i.dom(n)&&"transform"!==e&&T(n,e)?"css":null!=n[e]?"object":void 0}function E(n){if(i.dom(n)){for(var e,r=n.style.transform||"",t=/(\w+)\(([^)]*)\)/g,a=new Map;e=t.exec(r);)a.set(e[1],e[2]);return a}}function F(n,e,r,t){var a,u=o(e,"scale")?1:0+(o(a=e,"translate")||"perspective"===a?"px":o(a,"rotate")||o(a,"skew")?"deg":void 0),i=E(n).get(e)||u;return r&&(r.transforms.list.set(e,i),r.transforms.last=e),t?I(n,i,t):i}function N(n,e,r,t){switch(D(n,e)){case"transform":return F(n,e,t,r);case"css":return T(n,e,r);case"attribute":return P(n,e);default:return n[e]||0}}function A(n,e){var r=/^(\*=|\+=|-=)/.exec(n);if(!r)return n;var t=C(n)||0,a=parseFloat(e),o=parseFloat(n.replace(r[0],""));switch(r[0][0]){case"+":return a+o+t;case"-":return a-o+t;case"*":return a*o+t}}function L(n,e){if(i.col(n))return O(n);if(/\s/g.test(n))return n;var r=C(n),t=r?n.substr(0,n.length-r.length):n;return e?t+e:t}function j(n,e){return Math.sqrt(Math.pow(e.x-n.x,2)+Math.pow(e.y-n.y,2))}function S(n){for(var e,r=n.points,t=0,a=0;a<r.numberOfItems;a++){var o=r.getItem(a);a>0&&(t+=j(e,o)),e=o}return t}function q(n){if(n.getTotalLength)return n.getTotalLength();switch(n.tagName.toLowerCase()){case"circle":return o=n,2*Math.PI*P(o,"r");case"rect":return 2*P(a=n,"width")+2*P(a,"height");case"line":return j({x:P(t=n,"x1"),y:P(t,"y1")},{x:P(t,"x2"),y:P(t,"y2")});case"polyline":return S(n);case"polygon":return r=(e=n).points,S(e)+j(r.getItem(r.numberOfItems-1),r.getItem(0))}var e,r,t,a,o}function $(n,e){var r=e||{},t=r.el||function(n){for(var e=n.parentNode;i.svg(e)&&i.svg(e.parentNode);)e=e.parentNode;return e}(n),a=t.getBoundingClientRect(),o=P(t,"viewBox"),u=a.width,c=a.height,s=r.viewBox||(o?o.split(" "):[0,0,u,c]);return{el:t,viewBox:s,x:s[0]/1,y:s[1]/1,w:u/s[2],h:c/s[3]}}function X(n,e){function r(r){void 0===r&&(r=0);var t=e+r>=1?e+r:0;return n.el.getPointAtLength(t)}var t=$(n.el,n.svg),a=r(),o=r(-1),u=r(1);switch(n.property){case"x":return(a.x-t.x)*t.w;case"y":return(a.y-t.y)*t.h;case"angle":return 180*Math.atan2(u.y-o.y,u.x-o.x)/Math.PI}}function Y(n,e){var r=/[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g,t=L(i.pth(n)?n.totalLength:n,e)+"";return{original:t,numbers:t.match(r)?t.match(r).map(Number):[0],strings:i.str(n)||e?t.split(r):[]}}function Z(n){return m(n?y(i.arr(n)?n.map(b):b(n)):[],function(n,e,r){return r.indexOf(n)===e})}function Q(n){var e=Z(n);return e.map(function(n,r){return{target:n,id:r,total:e.length,transforms:{list:E(n)}}})}function V(n,e){var r=M(e);if(/^spring/.test(r.easing)&&(r.duration=s(r.easing)),i.arr(n)){var t=n.length;2===t&&!i.obj(n[0])?n={value:n}:i.fnc(e.duration)||(r.duration=e.duration/t)}var a=i.arr(n)?n:[n];return a.map(function(n,r){var t=i.obj(n)&&!i.pth(n)?n:{value:n};return i.und(t.delay)&&(t.delay=r?0:e.delay),i.und(t.endDelay)&&(t.endDelay=r===a.length-1?e.endDelay:0),t}).map(function(n){return k(n,r)})}function z(n,e){var r=[],t=e.keyframes;for(var a in t&&(e=k(function(n){for(var e=m(y(n.map(function(n){return Object.keys(n)})),function(n){return i.key(n)}).reduce(function(n,e){return n.indexOf(e)<0&&n.push(e),n},[]),r={},t=function(t){var a=e[t];r[a]=n.map(function(n){var e={};for(var r in n)i.key(r)?r==a&&(e.value=n[r]):e[r]=n[r];return e})},a=0;a<e.length;a++)t(a);return r}(t),e)),e)i.key(a)&&r.push({name:a,tweens:V(e[a],n)});return r}function H(n,e){var r;return n.tweens.map(function(t){var a=function(n,e){var r={};for(var t in n){var a=B(n[t],e);i.arr(a)&&1===(a=a.map(function(n){return B(n,e)})).length&&(a=a[0]),r[t]=a}return r.duration=parseFloat(r.duration),r.delay=parseFloat(r.delay),r}(t,e),o=a.value,u=i.arr(o)?o[1]:o,c=C(u),s=N(e.target,n.name,c,e),f=r?r.to.original:s,l=i.arr(o)?o[0]:f,d=C(l)||C(s),p=c||d;return i.und(u)&&(u=f),a.from=Y(l,p),a.to=Y(A(u,l),p),a.start=r?r.end:0,a.end=a.start+a.delay+a.duration+a.endDelay,a.easing=v(a.easing,a.duration),a.isPath=i.pth(o),a.isColor=i.col(a.from.original),a.isColor&&(a.round=1),r=a,a})}var G={css:function(n,e,r){return n.style[e]=r},attribute:function(n,e,r){return n.setAttribute(e,r)},object:function(n,e,r){return n[e]=r},transform:function(n,e,r,t,a){if(t.list.set(e,r),e===t.last||a){var o="";t.list.forEach(function(n,e){o+=e+"("+n+") "}),n.style.transform=o}}};function R(n,e){Q(n).forEach(function(n){for(var r in e){var t=B(e[r],n),a=n.target,o=C(t),u=N(a,r,o,n),i=A(L(t,o||C(u)),u),c=D(a,r);G[c](a,r,i,n.transforms,!0)}})}function W(n,e){return m(y(n.map(function(n){return e.map(function(e){return function(n,e){var r=D(n.target,e.name);if(r){var t=H(e,n),a=t[t.length-1];return{type:r,property:e.name,animatable:n,tweens:t,duration:a.end,delay:t[0].delay,endDelay:a.endDelay}}}(n,e)})})),function(n){return!i.und(n)})}function J(n,e){var r=n.length,t=function(n){return n.timelineOffset?n.timelineOffset:0},a={};return a.duration=r?Math.max.apply(Math,n.map(function(n){return t(n)+n.duration})):e.duration,a.delay=r?Math.min.apply(Math,n.map(function(n){return t(n)+n.delay})):e.delay,a.endDelay=r?a.duration-Math.max.apply(Math,n.map(function(n){return t(n)+n.duration-n.endDelay})):e.endDelay,a}var K=0;var U,_=[],nn=[],en=function(){function n(){U=requestAnimationFrame(e)}function e(e){var r=_.length;if(r){for(var t=0;t<r;){var a=_[t];if(a.paused){var o=_.indexOf(a);o>-1&&(_.splice(o,1),r=_.length)}else a.tick(e);t++}n()}else U=cancelAnimationFrame(U)}return n}();function rn(r){void 0===r&&(r={});var t,o=0,u=0,i=0,c=0,s=null;function f(n){var e=window.Promise&&new Promise(function(n){return s=n});return n.finished=e,e}var l,d,p,h,v,g,y,b,x=(d=w(n,l=r),p=w(e,l),h=z(p,l),v=Q(l.targets),g=W(v,h),y=J(g,p),b=K,K++,k(d,{id:b,children:[],animatables:v,animations:g,duration:y.duration,delay:y.delay,endDelay:y.endDelay}));f(x);function M(){var n=x.direction;"alternate"!==n&&(x.direction="normal"!==n?"normal":"reverse"),x.reversed=!x.reversed,t.forEach(function(n){return n.reversed=x.reversed})}function O(n){return x.reversed?x.duration-n:n}function C(){o=0,u=O(x.currentTime)*(1/rn.speed)}function B(n,e){e&&e.seek(n-e.timelineOffset)}function P(n){for(var e=0,r=x.animations,t=r.length;e<t;){var o=r[e],u=o.animatable,i=o.tweens,c=i.length-1,s=i[c];c&&(s=m(i,function(e){return n<e.end})[0]||s);for(var f=a(n-s.start-s.delay,0,s.duration)/s.duration,l=isNaN(f)?1:s.easing(f),d=s.to.strings,p=s.round,h=[],v=s.to.numbers.length,g=void 0,y=0;y<v;y++){var b=void 0,M=s.to.numbers[y],w=s.from.numbers[y]||0;b=s.isPath?X(s.value,l*M):w+l*(M-w),p&&(s.isColor&&y>2||(b=Math.round(b*p)/p)),h.push(b)}var k=d.length;if(k){g=d[0];for(var O=0;O<k;O++){d[O];var C=d[O+1],B=h[O];isNaN(B)||(g+=C?B+C:B+" ")}}else g=h[0];G[o.type](u.target,o.property,g,u.transforms),o.currentValue=g,e++}}function I(n){x[n]&&!x.passThrough&&x[n](x)}function T(n){var e=x.duration,r=x.delay,l=e-x.endDelay,d=O(n);x.progress=a(d/e*100,0,100),x.reversePlayback=d<x.currentTime,t&&function(n){if(x.reversePlayback)for(var e=c;e--;)B(n,t[e]);else for(var r=0;r<c;r++)B(n,t[r])}(d),!x.began&&x.currentTime>0&&(x.began=!0,I("begin")),!x.loopBegan&&x.currentTime>0&&(x.loopBegan=!0,I("loopBegin")),d<=r&&0!==x.currentTime&&P(0),(d>=l&&x.currentTime!==e||!e)&&P(e),d>r&&d<l?(x.changeBegan||(x.changeBegan=!0,x.changeCompleted=!1,I("changeBegin")),I("change"),P(d)):x.changeBegan&&(x.changeCompleted=!0,x.changeBegan=!1,I("changeComplete")),x.currentTime=a(d,0,e),x.began&&I("update"),n>=e&&(u=0,x.remaining&&!0!==x.remaining&&x.remaining--,x.remaining?(o=i,I("loopComplete"),x.loopBegan=!1,"alternate"===x.direction&&M()):(x.paused=!0,x.completed||(x.completed=!0,I("loopComplete"),I("complete"),!x.passThrough&&"Promise"in window&&(s(),f(x)))))}return x.reset=function(){var n=x.direction;x.passThrough=!1,x.currentTime=0,x.progress=0,x.paused=!0,x.began=!1,x.loopBegan=!1,x.changeBegan=!1,x.completed=!1,x.changeCompleted=!1,x.reversePlayback=!1,x.reversed="reverse"===n,x.remaining=x.loop,t=x.children;for(var e=c=t.length;e--;)x.children[e].reset();(x.reversed&&!0!==x.loop||"alternate"===n&&1===x.loop)&&x.remaining++,P(x.reversed?x.duration:0)},x.set=function(n,e){return R(n,e),x},x.tick=function(n){i=n,o||(o=i),T((i+(u-o))*rn.speed)},x.seek=function(n){T(O(n))},x.pause=function(){x.paused=!0,C()},x.play=function(){x.paused&&(x.completed&&x.reset(),x.paused=!1,_.push(x),C(),U||en())},x.reverse=function(){M(),x.completed=!x.reversed,C()},x.restart=function(){x.reset(),x.play()},x.reset(),x.autoplay&&x.play(),x}function tn(n,e){for(var r=e.length;r--;)x(n,e[r].animatable.target)&&e.splice(r,1)}return"undefined"!=typeof document&&document.addEventListener("visibilitychange",function(){document.hidden?(_.forEach(function(n){return n.pause()}),nn=_.slice(0),rn.running=_=[]):nn.forEach(function(n){return n.play()})}),rn.version="3.2.0",rn.speed=1,rn.running=_,rn.remove=function(n){for(var e=Z(n),r=_.length;r--;){var t=_[r],a=t.animations,o=t.children;tn(e,a);for(var u=o.length;u--;){var i=o[u],c=i.animations;tn(e,c),c.length||i.children.length||o.splice(u,1)}a.length||o.length||t.pause()}},rn.get=N,rn.set=R,rn.convertPx=I,rn.path=function(n,e){var r=i.str(n)?g(n)[0]:n,t=e||100;return function(n){return{property:n,el:r,svg:$(r),totalLength:q(r)*(t/100)}}},rn.setDashoffset=function(n){var e=q(n);return n.setAttribute("stroke-dasharray",e),e},rn.stagger=function(n,e){void 0===e&&(e={});var r=e.direction||"normal",t=e.easing?v(e.easing):null,a=e.grid,o=e.axis,u=e.from||0,c="first"===u,s="center"===u,f="last"===u,l=i.arr(n),d=l?parseFloat(n[0]):parseFloat(n),p=l?parseFloat(n[1]):0,h=C(l?n[1]:n)||0,g=e.start||0+(l?d:0),m=[],y=0;return function(n,e,i){if(c&&(u=0),s&&(u=(i-1)/2),f&&(u=i-1),!m.length){for(var v=0;v<i;v++){if(a){var b=s?(a[0]-1)/2:u%a[0],x=s?(a[1]-1)/2:Math.floor(u/a[0]),M=b-v%a[0],w=x-Math.floor(v/a[0]),k=Math.sqrt(M*M+w*w);"x"===o&&(k=-M),"y"===o&&(k=-w),m.push(k)}else m.push(Math.abs(u-v));y=Math.max.apply(Math,m)}t&&(m=m.map(function(n){return t(n/y)*y})),"reverse"===r&&(m=m.map(function(n){return o?n<0?-1*n:-n:Math.abs(y-n)}))}return g+(l?(p-d)/y:d)*(Math.round(100*m[e])/100)+h}},rn.timeline=function(n){void 0===n&&(n={});var r=rn(n);return r.duration=0,r.add=function(t,a){var o=_.indexOf(r),u=r.children;function c(n){n.passThrough=!0}o>-1&&_.splice(o,1);for(var s=0;s<u.length;s++)c(u[s]);var f=k(t,w(e,n));f.targets=f.targets||n.targets;var l=r.duration;f.autoplay=!1,f.direction=r.direction,f.timelineOffset=i.und(a)?l:A(a,l),c(r),r.seek(f.timelineOffset);var d=rn(f);c(d),u.push(d);var p=J(u,n);return r.delay=p.delay,r.endDelay=p.endDelay,r.duration=p.duration,r.seek(0),r.reset(),r.autoplay&&r.play(),r},r},rn.easing=v,rn.penner=h,rn.random=function(n,e){return Math.floor(Math.random()*(e-n+1))+n},rn}); |
|
0 | 9 |
\ No newline at end of file |