JAVASCRIPT   38

anime.js

Guest on 12th August 2021 06:49:24 PM

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

Raw Paste


Login or Register to edit or fork this paste. It's free.