Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

2.0

Julian Garnierfeeea15f7ec8
diff --git a/anime.js b/anime.js
index 6324c320..894d7f01 100644
--- a/anime.js
+++ b/anime.js
@@ -1,13 +1,13 @@
-/*
- * Anime v1.1.3
+/**
* http://anime-js.com
* JavaScript animation engine
- * Copyright (c) 2016 Julian Garnier
- * http://juliangarnier.com
+ * @version v2.0.0
+ * @author Julian Garnier
+ * @copyright © 2016 Julian Garnier
* Released under the MIT license
- */
+**/
-(function (root, factory) {
+(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
@@ -20,179 +20,279 @@
// Browser globals (root is window)
root.anime = factory();
}
-}(this, function () {
+}(this, () => {
- var version = '1.1.3';
+ const version = '2.0.0';
+ const speed = 1.0;
// Defaults
- var defaultSettings = {
- duration: 1000,
- delay: 0,
- loop: false,
- autoplay: true,
- direction: 'normal',
- easing: 'easeOutElastic',
- elasticity: 400,
- round: false,
+ const defaultAnimationSettings = {
begin: undefined,
update: undefined,
- complete: undefined
+ complete: undefined,
+ loop: 0,
+ direction: 'normal',
+ autoplay: true
}
- // Transforms
+ const defaultTweenSettings = {
+ duration: 1000,
+ delay: 0,
+ easing: 'easeOutElastic',
+ elasticity: 500,
+ round: 0
+ }
- var validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skewX', 'skewY'];
- var transform, transformStr = 'transform';
+ const validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skewX', 'skewY'];
// Utils
- var is = {
- arr: function(a) { return Array.isArray(a) },
- obj: function(a) { return Object.prototype.toString.call(a).indexOf('Object') > -1 },
- svg: function(a) { return a instanceof SVGElement },
- dom: function(a) { return a.nodeType || is.svg(a) },
- num: function(a) { return !isNaN(parseInt(a)) },
- str: function(a) { return typeof a === 'string' },
- fnc: function(a) { return typeof a === 'function' },
- und: function(a) { return typeof a === 'undefined' },
- nul: function(a) { return typeof a === 'null' },
- hex: function(a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a) },
- rgb: function(a) { return /^rgb/.test(a) },
- hsl: function(a) { return /^hsl/.test(a) },
- col: function(a) { return (is.hex(a) || is.rgb(a) || is.hsl(a)) }
- }
-
- // Easings functions adapted from http://jqueryui.com/
-
- var easings = (function() {
- var eases = {};
- var names = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo'];
- var functions = {
- Sine: function(t) { return 1 + Math.sin(Math.PI / 2 * t - Math.PI / 2); },
- Circ: function(t) { return 1 - Math.sqrt( 1 - t * t ); },
- Elastic: function(t, m) {
- if( t === 0 || t === 1 ) return t;
- var p = (1 - Math.min(m, 998) / 1000), st = t / 1, st1 = st - 1, s = p / ( 2 * Math.PI ) * Math.asin( 1 );
- return -( Math.pow( 2, 10 * st1 ) * Math.sin( ( st1 - s ) * ( 2 * Math.PI ) / p ) );
- },
- Back: function(t) { return t * t * ( 3 * t - 2 ); },
- Bounce: function(t) {
- var pow2, bounce = 4;
- while ( t < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
- return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - t, 2 );
+ function stringContains(str, text) {
+ return str.indexOf(text) > -1;
+ }
+
+ const is = {
+ arr: a => Array.isArray(a),
+ obj: a => stringContains(Object.prototype.toString.call(a), 'Object'),
+ svg: a => a instanceof SVGElement,
+ dom: a => a.nodeType || is.svg(a),
+ str: a => typeof a === 'string',
+ fnc: a => typeof a === 'function',
+ und: a => typeof a === 'undefined',
+ hex: a => /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a),
+ rgb: a => /^rgb/.test(a),
+ hsl: a => /^hsl/.test(a),
+ col: a => (is.hex(a) || is.rgb(a) || is.hsl(a))
+ }
+
+ // BezierEasing https://github.com/gre/bezier-easing
+ // © 2014 Gaëtan Renaudeau – MIT License
+
+ const bezier = (() => {
+
+ const kSplineTableSize = 11;
+ const kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
+
+ function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1 };
+ function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1 };
+ function C (aA1) { return 3.0 * aA1 };
+
+ function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT };
+ function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1) };
+
+ function binarySubdivide (aX, aA, aB, mX1, mX2) {
+ let currentX, currentT, i = 0;
+ do {
+ currentT = aA + (aB - aA) / 2.0;
+ currentX = calcBezier(currentT, mX1, mX2) - aX;
+ if (currentX > 0.0) { aB = currentT } else { aA = currentT };
+ } while (Math.abs(currentX) > 0.0000001 && ++i < 10);
+ return currentT;
+ }
+
+ function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) {
+ for (let i = 0; i < 4; ++i) {
+ const currentSlope = getSlope(aGuessT, mX1, mX2);
+ if (currentSlope === 0.0) return aGuessT;
+ const currentX = calcBezier(aGuessT, mX1, mX2) - aX;
+ aGuessT -= currentX / currentSlope;
}
+ return aGuessT;
}
- names.forEach(function(name, i) {
- functions[name] = function(t) {
- return Math.pow( t, i + 2 );
+
+ function bezier(mX1, mY1, mX2, mY2) {
+
+ if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) return;
+ let sampleValues = new Float32Array(kSplineTableSize);
+
+ if (mX1 !== mY1 || mX2 !== mY2) {
+ for (let i = 0; i < kSplineTableSize; ++i) {
+ sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
+ }
}
- });
- Object.keys(functions).forEach(function(name) {
- var easeIn = functions[name];
- eases['easeIn' + name] = easeIn;
- eases['easeOut' + name] = function(t, m) { return 1 - easeIn(1 - t, m); };
- eases['easeInOut' + name] = function(t, m) { return t < 0.5 ? easeIn(t * 2, m) / 2 : 1 - easeIn(t * -2 + 2, m) / 2; };
- eases['easeOutIn' + name] = function(t, m) { return t < 0.5 ? (1 - easeIn(1 - 2 * t, m)) / 2 : (easeIn(t * 2 - 1, m) + 1) / 2; };
- });
- eases.linear = function(t) { return t; };
- return eases;
+
+ function getTForX(aX) {
+
+ let intervalStart = 0.0;
+ let currentSample = 1;
+ const lastSample = kSplineTableSize - 1;
+
+ for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
+ intervalStart += kSampleStepSize;
+ }
+ --currentSample;
+
+ const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
+ const guessForT = intervalStart + dist * kSampleStepSize;
+ const initialSlope = getSlope(guessForT, mX1, mX2);
+
+ if (initialSlope >= 0.001) {
+ return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
+ } else if (initialSlope === 0.0) {
+ return guessForT;
+ } else {
+ return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
+ }
+
+ }
+
+ return (x) => {
+ if (mX1 === mY1 && mX2 === mY2) return x;
+ if (x === 0) return 0;
+ if (x === 1) return 1;
+ return calcBezier(getTForX(x), mY1, mY2);
+ }
+
+ }
+
+ return bezier;
+
})();
- // Strings
+ const easings = (() => {
- var numberToString = function(val) {
- return (is.str(val)) ? val : val + '';
- }
+ function elastic(t, f) {
+ return t === 0 || t === 1 ? t :
+ -Math.pow(2, 8 * (t - 1)) * Math.sin(((t - 1) * (Math.min(Math.max(f, 0), 1000) / 8.25) - 7.5) * Math.PI / 15);
+ }
+
+ const names = ['', 'Quad', 'Cubic', 'Quart', 'Quint', 'Sine', 'Expo', 'Circ', 'Back', 'Elastic'];
+
+ // Approximated Penner equations http://matthewlein.com/ceaser/
+ // © Matthew Lein
+
+ const equations = {
+ In: [
+ [0.420, 0.000, 1.000, 1.000], /* In */
+ [0.550, 0.085, 0.680, 0.530], /* InQuad */
+ [0.550, 0.055, 0.675, 0.190], /* InCubic */
+ [0.895, 0.030, 0.685, 0.220], /* InQuart */
+ [0.755, 0.050, 0.855, 0.060], /* InQuint */
+ [0.470, 0.000, 0.745, 0.715], /* InSine */
+ [0.950, 0.050, 0.795, 0.035], /* InExpo */
+ [0.600, 0.040, 0.980, 0.335], /* InCirc */
+ [0.600, -0.280, 0.735, 0.045], /* InBack */
+ elastic /* InElastic */
+ ], Out: [
+ [0.000, 0.000, 0.580, 1.000], /* Ou */
+ [0.250, 0.460, 0.450, 0.940], /* OutQuad */
+ [0.215, 0.610, 0.355, 1.000], /* OutCubic */
+ [0.165, 0.840, 0.440, 1.000], /* OutQuart */
+ [0.230, 1.000, 0.320, 1.000], /* OutQuint */
+ [0.390, 0.575, 0.565, 1.000], /* OutSine */
+ [0.190, 1.000, 0.220, 1.000], /* OutExpo */
+ [0.075, 0.820, 0.165, 1.000], /* OutCirc */
+ [0.175, 0.885, 0.320, 1.275], /* OutBack */
+ (t, f) => 1 - elastic(1 - t, f) /* OutElastic */
+ ], InOut: [
+ [0.420, 0.000, 0.580, 1.000], /* InOut */
+ [0.455, 0.030, 0.515, 0.955], /* InOutQuad */
+ [0.645, 0.045, 0.355, 1.000], /* InOutCubic */
+ [0.770, 0.000, 0.175, 1.000], /* InOutQuart */
+ [0.860, 0.000, 0.070, 1.000], /* InOutQuint */
+ [0.445, 0.050, 0.550, 0.950], /* InOutSine */
+ [1.000, 0.000, 0.000, 1.000], /* InOutExpo */
+ [0.785, 0.135, 0.150, 0.860], /* InOutCirc */
+ [0.680, -0.550, 0.265, 1.550], /* InOutBack */
+ (t, f) => t < .5 ? elastic(t * 2, f) / 2 : 1 - elastic(t * -2 + 2, f) / 2 /* InOutElastic */
+ ]
+ }
- var stringToHyphens = function(str) {
+ let functions = {
+ linear: bezier(0.250, 0.250, 0.750, 0.750),
+ ease: bezier(0.250, 0.100, 0.250, 1.000)
+ }
+
+ for (let type in equations) {
+ equations[type].forEach((f, i) => {
+ functions['ease'+type+names[i]] = is.fnc(f) ? f : bezier.apply(this, f);
+ });
+ }
+
+ return functions;
+
+ })();
+
+ // Strings
+
+ function stringToHyphens(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
- var selectString = function(str) {
- if (is.col(str)) return false;
+ function selectString(str) {
+ if (is.col(str)) return;
try {
- var nodes = document.querySelectorAll(str);
+ let nodes = document.querySelectorAll(str);
return nodes;
} catch(e) {
- return false;
+ return;
}
}
- // Numbers
+ // Arrays
- var random = function(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
+ function arrayLength(arr) {
+ return arr.length;
}
- // Arrays
-
- var flattenArray = function(arr) {
- return arr.reduce(function(a, b) {
- return a.concat(is.arr(b) ? flattenArray(b) : b);
- }, []);
+ function flattenArray(arr) {
+ return arr.reduce((a, b) => a.concat(is.arr(b) ? flattenArray(b) : b), []);
}
- var toArray = function(o) {
+ function toArray(o) {
if (is.arr(o)) return o;
if (is.str(o)) o = selectString(o) || o;
if (o instanceof NodeList || o instanceof HTMLCollection) return [].slice.call(o);
return [o];
}
- var arrayContains = function(arr, val) {
- return arr.some(function(a) { return a === val; });
+ function arrayContains(arr, val) {
+ return arr.some((a) => a === val);
}
- var groupArrayByProps = function(arr, propsArr) {
- var groups = {};
- arr.forEach(function(o) {
- var group = JSON.stringify(propsArr.map(function(p) { return o[p]; }));
- groups[group] = groups[group] || [];
- groups[group].push(o);
- });
- return Object.keys(groups).map(function(group) {
- return groups[group];
- });
- }
+ // Objects
- var removeArrayDuplicates = function(arr) {
- return arr.filter(function(item, pos, self) {
- return self.indexOf(item) === pos;
- });
+ function objectHas(obj, prop) {
+ return obj.hasOwnProperty(prop);
}
- // Objects
+ function cloneObject(o) {
+ let clone = {};
+ for (let p in o) clone[p] = o[p];
+ return clone;
+ }
- var cloneObject = function(o) {
- var newObject = {};
- for (var p in o) newObject[p] = o[p];
- return newObject;
+ function replaceObjectProps(o1, o2) {
+ let o = cloneObject(o1);
+ for (let p in o1) o[p] = objectHas(o2, p) ? o2[p] : o1[p];
+ return o;
}
- var mergeObjects = function(o1, o2) {
- for (var p in o2) o1[p] = !is.und(o1[p]) ? o1[p] : o2[p];
- return o1;
+ function mergeObjects(o1, o2) {
+ let o = cloneObject(o1);
+ for (let p in o2) o[p] = is.und(o1[p]) ? o2[p] : o1[p];
+ return o;
}
// Colors
- var hexToRgb = function(hex) {
- var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
- var hex = hex.replace(rgx, function(m, r, g, b) { return r + r + g + g + b + b; });
- var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
- var r = parseInt(rgb[1], 16);
- var g = parseInt(rgb[2], 16);
- var b = parseInt(rgb[3], 16);
- return 'rgb(' + r + ',' + g + ',' + b + ')';
- }
-
- var hslToRgb = function(hsl) {
- var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hsl);
- var h = parseInt(hsl[1]) / 360;
- var s = parseInt(hsl[2]) / 100;
- var l = parseInt(hsl[3]) / 100;
- var hue2rgb = function(p, q, t) {
+ function hexToRgb(hexValue) {
+ const rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
+ const hex = hexValue.replace(rgx, (m, r, g, b) => r + r + g + g + b + b );
+ const rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
+ const r = parseInt(rgb[1], 16);
+ const g = parseInt(rgb[2], 16);
+ const b = parseInt(rgb[3], 16);
+ return `rgb(${r},${g},${b})`;
+ }
+
+ function hslToRgb(hslValue) {
+ const hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue);
+ const h = parseInt(hsl[1]) / 360;
+ const s = parseInt(hsl[2]) / 100;
+ const l = parseInt(hsl[3]) / 100;
+ function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
@@ -200,20 +300,20 @@
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
- var r, g, b;
+ let r, g, b;
if (s == 0) {
r = g = b = l;
} else {
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
- var p = 2 * l - q;
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
+ const p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
- return 'rgb(' + r * 255 + ',' + g * 255 + ',' + b * 255 + ')';
+ return `rgb(${r * 255},${g * 255},${b * 255})`;
}
- var colorToRgb = function(val) {
+ function colorToRgb(val) {
if (is.rgb(val)) return val;
if (is.hex(val)) return hexToRgb(val);
if (is.hsl(val)) return hslToRgb(val);
@@ -221,316 +321,323 @@
// Units
- var getUnit = function(val) {
- return /([\+\-]?[0-9|auto\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg)?/.exec(val)[2];
+ function getUnit(val) {
+ return /([\+\-]?[0-9|auto|#\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg)?/.exec(val)[2];
}
- var addDefaultTransformUnit = function(prop, val, intialVal) {
- if (getUnit(val)) return val;
- if (prop.indexOf('translate') > -1) return getUnit(intialVal) ? val + getUnit(intialVal) : val + 'px';
- if (prop.indexOf('rotate') > -1 || prop.indexOf('skew') > -1) return val + 'deg';
- return val;
+ function getTransformUnit(propName) {
+ if (stringContains(propName, 'translate')) return 'px';
+ if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) return 'deg';
}
// Values
- var getCSSValue = function(el, prop) {
- // First check if prop is a valid CSS property
+ function getCSSValue(el, prop) {
if (prop in el.style) {
- // Then return the property value or fallback to '0' when getPropertyValue fails
return getComputedStyle(el).getPropertyValue(stringToHyphens(prop)) || '0';
}
}
- var getTransformValue = function(el, prop) {
- var defaultVal = prop.indexOf('scale') > -1 ? 1 : 0;
- var str = el.style.transform;
+ function getAnimationType(el, prop) {
+ if (is.dom(el) && arrayContains(validTransforms, prop)) return 'transform';
+ if (is.dom(el) && (el.getAttribute(prop) || (is.svg(el) && el[prop]))) return 'attribute';
+ if (is.dom(el) && (prop !== 'transform' && getCSSValue(el, prop))) return 'css';
+ if (el[prop] != null) return 'object';
+ }
+
+ function getTransformValue(el, propName) {
+ const defaultUnit = getTransformUnit(propName);
+ const defaultVal = stringContains(propName, 'scale') ? 1 : 0 + defaultUnit;
+ const str = el.style.transform;
if (!str) return defaultVal;
- var rgx = /(\w+)\((.+?)\)/g;
- var match = [];
- var props = [];
- var values = [];
+ let match = [];
+ let props = [];
+ let values = [];
+ const rgx = /(\w+)\((.+?)\)/g;
while (match = rgx.exec(str)) {
props.push(match[1]);
values.push(match[2]);
}
- var val = values.filter(function(f, i) { return props[i] === prop; });
- return val.length ? val[0] : defaultVal;
+ const value = values.filter((val, i) => props[i] === propName );
+ return arrayLength(value) ? value[0] : defaultVal;
+ }
+
+ function getOriginalTargetValue(target, propName) {
+ switch (getAnimationType(target, propName)) {
+ case 'transform': return getTransformValue(target, propName);
+ case 'css': return getCSSValue(target, propName);
+ case 'attribute': return target.getAttribute(propName);
+ }
+ return target[propName] || 0;
+ }
+
+ function validateValue(val, unit) {
+ if (is.col(val)) return colorToRgb(val);
+ const originalUnit = getUnit(val);
+ const unitLess = originalUnit ? val.substr(0, arrayLength(val) - arrayLength(originalUnit)) : val;
+ return unit ? unitLess + unit : unitLess;
}
- var getAnimationType = function(el, prop) {
- if ( is.dom(el) && arrayContains(validTransforms, prop)) return 'transform';
- if ( is.dom(el) && (el.getAttribute(prop) || (is.svg(el) && el[prop]))) return 'attribute';
- if ( is.dom(el) && (prop !== 'transform' && getCSSValue(el, prop))) return 'css';
- if (!is.nul(el[prop]) && !is.und(el[prop])) return 'object';
+ // Motion path
+
+ function isPath(val) {
+ return is.obj(val) && objectHas(val, 'totalLength');
}
- var getInitialTargetValue = function(target, prop) {
- switch (getAnimationType(target, prop)) {
- case 'transform': return getTransformValue(target, prop);
- case 'css': return getCSSValue(target, prop);
- case 'attribute': return target.getAttribute(prop);
+ function getPath(path, percent) {
+ const el = is.str(path) ? selectString(path)[0] : path;
+ const p = percent || 100;
+ return function(prop) {
+ return {
+ el: el,
+ property: prop,
+ totalLength: el.getTotalLength() * (p / 100)
+ }
}
- return target[prop] || 0;
}
- var getValidValue = function(values, val, originalCSS) {
- if (is.col(val)) return colorToRgb(val);
- if (getUnit(val)) return val;
- var unit = getUnit(values.to) ? getUnit(values.to) : getUnit(values.from);
- if (!unit && originalCSS) unit = getUnit(originalCSS);
- return unit ? val + unit : val;
+ function getPathProgress(path, progress) {
+ function point(offset) {
+ const o = offset || 0;
+ const l = progress + o >= 1 ? progress + o : 0;
+ return path.el.getPointAtLength(l);
+ }
+ const p = point();
+ const p0 = point(-1);
+ const p1 = point(+1);
+ switch (path.property) {
+ case 'x': return p.x;
+ case 'y': return p.y;
+ case 'angle': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;
+ }
}
- var decomposeValue = function(val) {
- var rgx = /-?\d*\.?\d+/g;
+ // Decompose / recompose functions adapted from Animate Plus https://github.com/bendc/animateplus
+ // © 2015 Benjamin De Cock
+
+ function decomposeValue(val, unit) {
+ const rgx = /-?\d*\.?\d+/g;
+ const value = validateValue((isPath(val) ? val.totalLength : val), unit) + '';
return {
- original: val,
- numbers: numberToString(val).match(rgx) ? numberToString(val).match(rgx).map(Number) : [0],
- strings: numberToString(val).split(rgx)
+ original: value,
+ numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0],
+ strings: value.split(rgx)
}
}
- var recomposeValue = function(numbers, strings, initialStrings) {
- return strings.reduce(function(a, b, i) {
- var b = (b ? b : initialStrings[i - 1]);
- return a + numbers[i - 1] + b;
- });
+ function recomposeValue(numbers, strings) {
+ return strings.reduce((a, b, i) => a + numbers[i - 1] + b);
}
// Animatables
- var getAnimatables = function(targets) {
- var targets = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : [];
- return targets.map(function(t, i) {
- return { target: t, id: i };
+ function parseTargets(targets) {
+ const targetsArray = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : [];
+ return targetsArray.filter((item, pos, self) => self.indexOf(item) === pos);
+ }
+
+ function getAnimatables(targets) {
+ const parsed = parseTargets(targets);
+ return parsed.map((t, i) => {
+ return {target: t, id: i, total: arrayLength(parsed)};
});
}
// Properties
- var getProperties = function(params, settings) {
- var props = [];
- for (var p in params) {
- if (!defaultSettings.hasOwnProperty(p) && p !== 'targets') {
- var prop = is.obj(params[p]) ? cloneObject(params[p]) : {value: params[p]};
- prop.name = p;
- props.push(mergeObjects(prop, settings));
- }
+ function normalizePropertyTweens(tween, settings) {
+ let t = tween;
+ let s = settings;
+ const l = arrayLength(t);
+ if (is.arr(t)) {
+ // Duration divided by the number of tweens
+ if (!is.fnc(settings.duration) && l > 2) s.duration = settings.duration / l;
+ // Transform [from, to] values shorthand to a valid tween value
+ if ((l === 2 && !is.arr(t[0]) && !is.obj(t[0]))) t = {value: tween};
}
- return props;
- }
-
- var getPropertiesValues = function(target, prop, value, i) {
- var values = toArray( is.fnc(value) ? value(target, i) : value);
- return {
- from: (values.length > 1) ? values[0] : getInitialTargetValue(target, prop),
- to: (values.length > 1) ? values[1] : values[0]
+ return toArray(t).map((v, i) => {
+ // Default default value should be applied only on the first tween
+ const delay = !i ? s.delay : 0;
+ // Use path object as a tween value
+ let obj = is.obj(v) && !isPath(v) ? v : {value: v};
+ // Set default delay value
+ obj.delay = obj.delay || delay;
+ return obj;
+ }).map(k => mergeObjects(k, s));
+ }
+
+ function getProperties(animationSettings, tweenSettings, params) {
+ let properties = [];
+ const settings = mergeObjects(animationSettings, tweenSettings);
+ for (let p in params) {
+ if (!objectHas(settings, p) && p !== 'targets') {
+ properties.push({
+ name: p,
+ tweens: normalizePropertyTweens(params[p], tweenSettings)
+ });
+ }
}
+ return properties;
}
// Tweens
- var getTweenValues = function(prop, values, type, target) {
- var valid = {};
- if (type === 'transform') {
- valid.from = prop + '(' + addDefaultTransformUnit(prop, values.from, values.to) + ')';
- valid.to = prop + '(' + addDefaultTransformUnit(prop, values.to) + ')';
- } else {
- var originalCSS = (type === 'css') ? getCSSValue(target, prop) : undefined;
- valid.from = getValidValue(values, values.from, originalCSS);
- valid.to = getValidValue(values, values.to, originalCSS);
- }
- return { from: decomposeValue(valid.from), to: decomposeValue(valid.to) };
- }
-
- var getTweensProps = function(animatables, props) {
- var tweensProps = [];
- animatables.forEach(function(animatable, i) {
- var target = animatable.target;
- return props.forEach(function(prop) {
- var animType = getAnimationType(target, prop.name);
- if (animType) {
- var values = getPropertiesValues(target, prop.name, prop.value, i);
- var tween = cloneObject(prop);
- tween.animatables = animatable;
- tween.type = animType;
- tween.from = getTweenValues(prop.name, values, tween.type, target).from;
- tween.to = getTweenValues(prop.name, values, tween.type, target).to;
- tween.round = (is.col(values.from) || tween.round) ? 1 : 0;
- tween.delay = (is.fnc(tween.delay) ? tween.delay(target, i, animatables.length) : tween.delay) / animation.speed;
- tween.duration = (is.fnc(tween.duration) ? tween.duration(target, i, animatables.length) : tween.duration) / animation.speed;
- tweensProps.push(tween);
- }
- });
- });
- return tweensProps;
+ function getFunctionValue(val, animatable) {
+ if (!is.fnc(val)) return val;
+ return val(animatable.target, animatable.id, animatable.total);
}
- var getTweens = function(animatables, props) {
- var tweensProps = getTweensProps(animatables, props);
- var splittedProps = groupArrayByProps(tweensProps, ['name', 'from', 'to', 'delay', 'duration']);
- return splittedProps.map(function(tweenProps) {
- var tween = cloneObject(tweenProps[0]);
- tween.animatables = tweenProps.map(function(p) { return p.animatables });
- tween.totalDuration = tween.delay + tween.duration;
+ function normalizeTweenValues(tween, animatable) {
+ let t = {};
+ for (let p in tween) {
+ let value = getFunctionValue(tween[p], animatable);
+ if (is.arr(value)) {
+ value = value.map(v => getFunctionValue(v, animatable));
+ if (arrayLength(value) === 1) value = value[0];
+ }
+ t[p] = value;
+ }
+ return t;
+ }
+
+ function normalizeEasing(val) {
+ return is.arr(val) ? bezier.apply(this, val) : easings[val];
+ }
+
+ function normalizeTweens(prop, animatable) {
+ let previousTween;
+ return prop.tweens.map(function(t) {
+ let tween = normalizeTweenValues(t, animatable);
+ const tweenValue = tween.value;
+ const originalValue = getOriginalTargetValue(animatable.target, prop.name);
+ const previousValue = previousTween ? previousTween.to.original : originalValue;
+ const from = is.arr(tweenValue) ? tweenValue[0] : previousValue;
+ const to = is.arr(tweenValue) ? tweenValue[1] : tweenValue;
+ const unit = getUnit(to) || getUnit(from) || getUnit(originalValue);
+ tween.from = decomposeValue(from, unit);
+ tween.to = decomposeValue(to, unit);
+ tween.start = previousTween ? previousTween.end + tween.delay : tween.delay;
+ tween.end = tween.start + tween.duration;
+ tween.easing = normalizeEasing(tween.easing);
+ tween.round = (is.col(tween.from.original) || tween.round) ? 1 : 0;
+ previousTween = tween;
return tween;
});
}
- var reverseTweens = function(anim, delays) {
- anim.tweens.forEach(function(tween) {
- var toVal = tween.to;
- var fromVal = tween.from;
- var delayVal = anim.duration - (tween.delay + tween.duration);
- tween.from = toVal;
- tween.to = fromVal;
- if (delays) tween.delay = delayVal;
- });
- anim.reversed = anim.reversed ? false : true;
- }
-
- var getTweensDuration = function(tweens) {
- return Math.max.apply(Math, tweens.map(function(tween){ return tween.totalDuration; }));
- }
-
- var getTweensDelay = function(tweens) {
- return Math.min.apply(Math, tweens.map(function(tween){ return tween.delay; }));
- }
-
- // will-change
-
- var getWillChange = function(anim) {
- var props = [];
- var els = [];
- anim.tweens.forEach(function(tween) {
- if (tween.type === 'css' || tween.type === 'transform' ) {
- props.push(tween.type === 'css' ? stringToHyphens(tween.name) : 'transform');
- tween.animatables.forEach(function(animatable) { els.push(animatable.target); });
+ // Tween progress
+
+ function getTweenProgress(tween, time) {
+ const elapsed = Math.min(Math.max(time - tween.start, 0), tween.duration);
+ let progress = (elapsed / tween.duration);
+ const round = tween.round;
+ return recomposeValue(tween.to.numbers.map((number, p) => {
+ const eased = tween.easing(progress, tween.elasticity);
+ const start = tween.from.numbers[p];
+ let value = start + eased * (number - start);
+ if (isPath(tween.value)) value = getPathProgress(tween.value, value);
+ if (round) value = Math.round(value * round) / round;
+ return value;
+ }), tween.to.strings);
+ }
+
+ // Animations
+
+ function createAnimation(animatable, prop) {
+ const animType = getAnimationType(animatable.target, prop.name);
+ if (animType) {
+ const tweens = normalizeTweens(prop, animatable);
+ return {
+ type: animType,
+ property: prop.name,
+ animatable: animatable,
+ tweens: tweens,
+ duration: tweens.reduce((a, b) => a + b.delay + b.duration, 0),
+ delay: tweens[0].delay
}
- });
- return {
- properties: removeArrayDuplicates(props).join(', '),
- elements: removeArrayDuplicates(els)
}
}
- var setWillChange = function(anim) {
- var willChange = getWillChange(anim);
- willChange.elements.forEach(function(element) {
- element.style.willChange = willChange.properties;
- });
+ function getAnimations(animatables, properties) {
+ return flattenArray(animatables.map(animatable => {
+ return properties.map(prop => {
+ return createAnimation(animatable, prop);
+ });
+ })).filter(a => !is.und(a));
}
- var removeWillChange = function(anim) {
- var willChange = getWillChange(anim);
- willChange.elements.forEach(function(element) {
- element.style.removeProperty('will-change');
- });
+ const setAnimationProgress = {
+ css: (t, p, v) => t.style[p] = v,
+ attribute: (t, p, v) => t.setAttribute(p, v),
+ object: (t, p, v) => t[p] = v,
+ transform: (t, p, v, transforms, id) => {
+ if (!transforms[id]) transforms[id] = [];
+ transforms[id].push(`${p}(${v})`);
+ }
}
- /* Svg path */
+ // Instance
- var getPathProps = function(path) {
- var el = is.str(path) ? selectString(path)[0] : path;
- return {
- path: el,
- value: el.getTotalLength()
- }
+ function toggleInstanceDirection(instance) {
+ instance.reversed = !instance.reversed;
}
- var snapProgressToPath = function(tween, progress) {
- var pathEl = tween.path;
- var pathProgress = tween.value * progress;
- var point = function(offset) {
- var o = offset || 0;
- var p = progress > 1 ? tween.value + o : pathProgress + o;
- return pathEl.getPointAtLength(p);
- }
- var p = point();
- var p0 = point(-1);
- var p1 = point(+1);
- switch (tween.name) {
- case 'translateX': return p.x;
- case 'translateY': return p.y;
- case 'rotate': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;
- }
+ function adjustInstanceTime(instance, time) {
+ return instance.reversed ? instance.duration - time : time;
}
- // Progress
-
- var getTweenProgress = function(tween, time) {
- var elapsed = Math.min(Math.max(time - tween.delay, 0), tween.duration);
- var percent = elapsed / tween.duration;
- var progress = tween.to.numbers.map(function(number, p) {
- var start = tween.from.numbers[p];
- var eased = easings[tween.easing](percent, tween.elasticity);
- var val = tween.path ? snapProgressToPath(tween, eased) : start + eased * (number - start);
- val = tween.round ? Math.round(val * tween.round) / tween.round : val;
- return val;
- });
- return recomposeValue(progress, tween.to.strings, tween.from.strings);
- }
-
- var setAnimationProgress = function(anim, time) {
- var transforms;
- anim.currentTime = time;
- anim.progress = (time / anim.duration) * 100;
- for (var t = 0; t < anim.tweens.length; t++) {
- var tween = anim.tweens[t];
- tween.currentValue = getTweenProgress(tween, time);
- var progress = tween.currentValue;
- for (var a = 0; a < tween.animatables.length; a++) {
- var animatable = tween.animatables[a];
- var id = animatable.id;
- var target = animatable.target;
- var name = tween.name;
- switch (tween.type) {
- case 'css': target.style[name] = progress; break;
- case 'attribute': target.setAttribute(name, progress); break;
- case 'object': target[name] = progress; break;
- case 'transform':
- if (!transforms) transforms = {};
- if (!transforms[id]) transforms[id] = [];
- transforms[id].push(progress);
- break;
- }
- }
+ function setInstanceProgress(instance, time) {
+ let transforms = {};
+ const animations = instance.animations;
+ const currentTime = adjustInstanceTime(instance, time);
+ instance.currentTime = currentTime;
+ instance.progress = (currentTime / instance.duration) * 100;
+ for (let i = 0; i < arrayLength(animations); i++) {
+ const anim = animations[i];
+ const tweens = anim.tweens;
+ const tween = tweens.filter(tween => (tween.start - tween.delay <= currentTime && tween.end >= currentTime))[0];
+ const activeTween = tween || tweens[arrayLength(tweens) - 1];
+ const progress = getTweenProgress(activeTween, currentTime);
+ const animatable = anim.animatable;
+ const setProgress = setAnimationProgress[anim.type];
+ setProgress(animatable.target, anim.property, progress, transforms, animatable.id);
}
if (transforms) {
- if (!transform) transform = (getCSSValue(document.body, transformStr) ? '' : '-webkit-') + transformStr;
- for (var t in transforms) {
- anim.animatables[t].target.style[transform] = transforms[t].join(' ');
+ let id; for (id in transforms) {
+ instance.animatables[id].target.style.transform = transforms[id].join(' ');
}
}
+ if (instance.settings.update) instance.settings.update(instance);
}
- // Animation
-
- var createAnimation = function(params) {
- var anim = {};
- anim.animatables = getAnimatables(params.targets);
- anim.settings = mergeObjects(params, defaultSettings);
- anim.properties = getProperties(params, anim.settings);
- anim.tweens = getTweens(anim.animatables, anim.properties);
- anim.duration = anim.tweens.length ? getTweensDuration(anim.tweens) : params.duration;
- anim.delay = anim.tweens.length ? getTweensDelay(anim.tweens) : params.delay;
- anim.currentTime = 0;
- anim.progress = 0;
- anim.ended = false;
- return anim;
+ function createNewInstance(params) {
+ const animationSettings = replaceObjectProps(defaultAnimationSettings, params);
+ const tweenSettings = replaceObjectProps(defaultTweenSettings, params);
+ const animatables = getAnimatables(params.targets);
+ const properties = getProperties(animationSettings, tweenSettings, params);
+ const animations = getAnimations(animatables, properties);
+ return {
+ settings: animationSettings,
+ animatables: animatables,
+ animations: animations,
+ duration: arrayLength(animations) ? Math.max.apply(Math, animations.map((anim) => anim.duration )) : tweenSettings.duration,
+ delay: arrayLength(animations) ? Math.min.apply(Math, animations.map((anim) => anim.delay )) : tweenSettings.delay,
+ currentTime: 0,
+ progress: 0,
+ ended: false
+ }
}
- // Public
+ // Core
- var animations = [];
- var raf = 0;
+ let instances = [];
+ let raf = 0;
- var engine = (function() {
- var play = function() { raf = requestAnimationFrame(step); };
- var step = function(t) {
- if (animations.length) {
- for (var i = 0; i < animations.length; i++) animations[i].tick(t);
+ const engine = (() => {
+ function play() { raf = requestAnimationFrame(step); };
+ function step(t) {
+ if (arrayLength(instances)) {
+ for (let i = 0; i < arrayLength(instances); i++) instances[i].tick(t);
play();
} else {
cancelAnimationFrame(raf);
@@ -540,100 +647,95 @@
return play;
})();
- var animation = function(params) {
+ // Public
- var anim = createAnimation(params);
- var time = {};
+ function anime(params) {
- anim.tick = function(now) {
- anim.ended = false;
- if (!time.start) time.start = now;
- time.current = Math.min(Math.max(time.last + now - time.start, 0), anim.duration);
- setAnimationProgress(anim, time.current);
- var s = anim.settings;
- if (time.current >= anim.delay) {
- if (s.begin) s.begin(anim); s.begin = undefined;
- if (s.update) s.update(anim);
- }
- if (time.current >= anim.duration) {
+ let startTime, lastTime = 0;
+ let instance = createNewInstance(params);
+
+ instance.tick = function(now) {
+ instance.ended = false;
+ let s = instance.settings;
+ if (!startTime) startTime = now;
+ const currentTime = (lastTime + now - startTime) * anime.speed;
+ const instanceTime = Math.min(Math.max(currentTime, 0), instance.duration);
+ setInstanceProgress(instance, instanceTime);
+ if (s.begin && instanceTime >= instance.delay) s.begin(instance); s.begin = undefined;
+ if (instanceTime >= instance.duration) {
if (s.loop) {
- time.start = now;
- if (s.direction === 'alternate') reverseTweens(anim, true);
- if (is.num(s.loop)) s.loop--;
+ startTime = now;
+ if (s.direction === 'alternate') toggleInstanceDirection(instance);
+ if (!isNaN(parseInt(s.loop))) s.loop--;
} else {
- anim.ended = true;
- anim.pause();
- if (s.complete) s.complete(anim);
+ instance.ended = true;
+ instance.pause();
+ if (s.complete) s.complete(instance);
}
- time.last = 0;
+ lastTime = 0;
}
}
- anim.seek = function(progress) {
- setAnimationProgress(anim, (progress / 100) * anim.duration);
+ instance.seek = function(percent) {
+ const time = instance.duration * (percent / 100);
+ const now = adjustInstanceTime(instance, time);
+ setInstanceProgress(instance, now);
}
- anim.pause = function() {
- removeWillChange(anim);
- var i = animations.indexOf(anim);
- if (i > -1) animations.splice(i, 1);
+ instance.pause = function() {
+ const i = instances.indexOf(instance);
+ if (i > -1) instances.splice(i, 1);
}
- anim.play = function(params) {
- anim.pause();
- if (params) anim = mergeObjects(createAnimation(mergeObjects(params, anim.settings)), anim);
- time.start = 0;
- time.last = anim.ended ? 0 : anim.currentTime;
- var s = anim.settings;
- if (s.direction === 'reverse') reverseTweens(anim);
+ instance.play = function(params) {
+ instance.pause();
+ if (params) instance = mergeObjects(createNewInstance(mergeObjects(params, instance.settings)), instance);
+ startTime = 0;
+ lastTime = instance.ended ? 0 : adjustInstanceTime(instance, instance.currentTime);
+ let s = instance.settings;
+ if (s.direction === 'reverse' && !instance.reversed) toggleInstanceDirection(instance);
if (s.direction === 'alternate' && !s.loop) s.loop = 1;
- setWillChange(anim);
- animations.push(anim);
+ instances.push(instance);
if (!raf) engine();
}
- anim.restart = function() {
- if (anim.reversed) reverseTweens(anim);
- anim.pause();
- anim.seek(0);
- anim.play();
+ instance.restart = function() {
+ if (instance.reversed) toggleInstanceDirection(instance);
+ instance.pause();
+ instance.seek(0);
+ instance.play();
}
- if (anim.settings.autoplay) anim.play();
+ if (instance.settings.autoplay) instance.play();
- return anim;
+ return instance;
}
- // Remove one or multiple targets from all active animations.
-
- var remove = function(elements) {
- var targets = flattenArray(is.arr(elements) ? elements.map(toArray) : toArray(elements));
- for (var i = animations.length-1; i >= 0; i--) {
- var animation = animations[i];
- var tweens = animation.tweens;
- for (var t = tweens.length-1; t >= 0; t--) {
- var animatables = tweens[t].animatables;
- for (var a = animatables.length-1; a >= 0; a--) {
- if (arrayContains(targets, animatables[a].target)) {
- animatables.splice(a, 1);
- if (!animatables.length) tweens.splice(t, 1);
- if (!tweens.length) animation.pause();
- }
+ function removeTargets(targets) {
+ const targetsArray = parseTargets(targets);
+ for (let i = arrayLength(instances)-1; i >= 0; i--) {
+ const instance = instances[i];
+ const animations = instance.animations;
+ for (let a = arrayLength(animations)-1; a >= 0; a--) {
+ if (arrayContains(targetsArray, animations[a].animatable.target)) {
+ animations.splice(a, 1);
+ if (!arrayLength(animations)) instance.pause();
}
}
}
}
- animation.version = version;
- animation.speed = 1;
- animation.list = animations;
- animation.remove = remove;
- animation.easings = easings;
- animation.getValue = getInitialTargetValue;
- animation.path = getPathProps;
- animation.random = random;
+ anime.version = version;
+ anime.speed = speed;
+ anime.list = instances;
+ anime.remove = removeTargets;
+ anime.getValue = getOriginalTargetValue;
+ anime.path = getPath;
+ anime.bezier = bezier;
+ anime.easings = easings;
+ anime.random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
- return animation;
+ return anime;
}));
diff --git a/anime.min.js b/anime.min.js
deleted file mode 100644
index 9ba26528..00000000
--- a/anime.min.js
+++ /dev/null
@@ -1,19 +0,0 @@
-(function(t,q){"function"===typeof define&&define.amd?define([],q):"object"===typeof module&&module.exports?module.exports=q():t.anime=q()})(this,function(){var t={duration:1E3,delay:0,loop:!1,autoplay:!0,direction:"normal",easing:"easeOutElastic",elasticity:400,round:!1,begin:void 0,update:void 0,complete:void 0},q="translateX translateY translateZ rotate rotateX rotateY rotateZ scale scaleX scaleY scaleZ skewX skewY".split(" "),x,f={arr:function(a){return Array.isArray(a)},obj:function(a){return-1<
-Object.prototype.toString.call(a).indexOf("Object")},svg:function(a){return a instanceof SVGElement},dom:function(a){return a.nodeType||f.svg(a)},num:function(a){return!isNaN(parseInt(a))},str:function(a){return"string"===typeof a},fnc:function(a){return"function"===typeof a},und:function(a){return"undefined"===typeof a},nul:function(a){return"null"===typeof a},hex:function(a){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a)},rgb:function(a){return/^rgb/.test(a)},hsl:function(a){return/^hsl/.test(a)},
-col:function(a){return f.hex(a)||f.rgb(a)||f.hsl(a)}},C=function(){var a={},b={Sine:function(a){return 1+Math.sin(Math.PI/2*a-Math.PI/2)},Circ:function(a){return 1-Math.sqrt(1-a*a)},Elastic:function(a,b){if(0===a||1===a)return a;var c=1-Math.min(b,998)/1E3,d=a/1-1;return-(Math.pow(2,10*d)*Math.sin(2*(d-c/(2*Math.PI)*Math.asin(1))*Math.PI/c))},Back:function(a){return a*a*(3*a-2)},Bounce:function(a){for(var b,c=4;a<((b=Math.pow(2,--c))-1)/11;);return 1/Math.pow(4,3-c)-7.5625*Math.pow((3*b-2)/22-a,2)}};
-["Quad","Cubic","Quart","Quint","Expo"].forEach(function(a,d){b[a]=function(a){return Math.pow(a,d+2)}});Object.keys(b).forEach(function(c){var d=b[c];a["easeIn"+c]=d;a["easeOut"+c]=function(a,b){return 1-d(1-a,b)};a["easeInOut"+c]=function(a,b){return.5>a?d(2*a,b)/2:1-d(-2*a+2,b)/2};a["easeOutIn"+c]=function(a,b){return.5>a?(1-d(1-2*a,b))/2:(d(2*a-1,b)+1)/2}});a.linear=function(a){return a};return a}(),y=function(a){return f.str(a)?a:a+""},D=function(a){return a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()},
-E=function(a){if(f.col(a))return!1;try{return document.querySelectorAll(a)}catch(b){return!1}},z=function(a){return a.reduce(function(a,c){return a.concat(f.arr(c)?z(c):c)},[])},r=function(a){if(f.arr(a))return a;f.str(a)&&(a=E(a)||a);return a instanceof NodeList||a instanceof HTMLCollection?[].slice.call(a):[a]},F=function(a,b){return a.some(function(a){return a===b})},Q=function(a,b){var c={};a.forEach(function(a){var d=JSON.stringify(b.map(function(b){return a[b]}));c[d]=c[d]||[];c[d].push(a)});
-return Object.keys(c).map(function(a){return c[a]})},G=function(a){return a.filter(function(a,c,d){return d.indexOf(a)===c})},A=function(a){var b={},c;for(c in a)b[c]=a[c];return b},u=function(a,b){for(var c in b)a[c]=f.und(a[c])?b[c]:a[c];return a},R=function(a){a=a.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(a,b,c,l){return b+b+c+c+l+l});var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);a=parseInt(b[1],16);var c=parseInt(b[2],16),b=parseInt(b[3],16);return"rgb("+a+","+c+","+b+")"},
-S=function(a){a=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(a);var b=parseInt(a[1])/360,c=parseInt(a[2])/100,d=parseInt(a[3])/100;a=function(a,b,c){0>c&&(c+=1);1<c&&--c;return c<1/6?a+6*(b-a)*c:.5>c?b:c<2/3?a+(b-a)*(2/3-c)*6:a};if(0==c)c=d=b=d;else var e=.5>d?d*(1+c):d+c-d*c,h=2*d-e,c=a(h,e,b+1/3),d=a(h,e,b),b=a(h,e,b-1/3);return"rgb("+255*c+","+255*d+","+255*b+")"},p=function(a){return/([\+\-]?[0-9|auto\.]+)(%|px|pt|em|rem|in|cm|mm|ex|pc|vw|vh|deg)?/.exec(a)[2]},H=function(a,b,c){return p(b)?
-b:-1<a.indexOf("translate")?p(c)?b+p(c):b+"px":-1<a.indexOf("rotate")||-1<a.indexOf("skew")?b+"deg":b},v=function(a,b){if(b in a.style)return getComputedStyle(a).getPropertyValue(D(b))||"0"},T=function(a,b){var c=-1<b.indexOf("scale")?1:0,d=a.style.transform;if(!d)return c;for(var e=/(\w+)\((.+?)\)/g,h=[],l=[],f=[];h=e.exec(d);)l.push(h[1]),f.push(h[2]);d=f.filter(function(a,c){return l[c]===b});return d.length?d[0]:c},I=function(a,b){if(f.dom(a)&&F(q,b))return"transform";if(f.dom(a)&&(a.getAttribute(b)||
-f.svg(a)&&a[b]))return"attribute";if(f.dom(a)&&"transform"!==b&&v(a,b))return"css";if(!f.nul(a[b])&&!f.und(a[b]))return"object"},J=function(a,b){switch(I(a,b)){case "transform":return T(a,b);case "css":return v(a,b);case "attribute":return a.getAttribute(b)}return a[b]||0},K=function(a,b,c){if(f.col(b))return b=f.rgb(b)?b:f.hex(b)?R(b):f.hsl(b)?S(b):void 0,b;if(p(b))return b;a=p(a.to)?p(a.to):p(a.from);!a&&c&&(a=p(c));return a?b+a:b},L=function(a){var b=/-?\d*\.?\d+/g;return{original:a,numbers:y(a).match(b)?
-y(a).match(b).map(Number):[0],strings:y(a).split(b)}},U=function(a,b,c){return b.reduce(function(b,e,h){e=e?e:c[h-1];return b+a[h-1]+e})},V=function(a){a=a?z(f.arr(a)?a.map(r):r(a)):[];return a.map(function(a,c){return{target:a,id:c}})},M=function(a,b,c,d){"transform"===c?(c=a+"("+H(a,b.from,b.to)+")",b=a+"("+H(a,b.to)+")"):(a="css"===c?v(d,a):void 0,c=K(b,b.from,a),b=K(b,b.to,a));return{from:L(c),to:L(b)}},W=function(a,b){var c=[];a.forEach(function(d,e){var h=d.target;return b.forEach(function(b){var l=
-I(h,b.name);if(l){var m;m=b.name;var g=b.value,g=r(f.fnc(g)?g(h,e):g);m={from:1<g.length?g[0]:J(h,m),to:1<g.length?g[1]:g[0]};g=A(b);g.animatables=d;g.type=l;g.from=M(b.name,m,g.type,h).from;g.to=M(b.name,m,g.type,h).to;g.round=f.col(m.from)||g.round?1:0;g.delay=(f.fnc(g.delay)?g.delay(h,e,a.length):g.delay)/k.speed;g.duration=(f.fnc(g.duration)?g.duration(h,e,a.length):g.duration)/k.speed;c.push(g)}})});return c},X=function(a,b){var c=W(a,b);return Q(c,["name","from","to","delay","duration"]).map(function(a){var b=
-A(a[0]);b.animatables=a.map(function(a){return a.animatables});b.totalDuration=b.delay+b.duration;return b})},B=function(a,b){a.tweens.forEach(function(c){var d=c.from,e=a.duration-(c.delay+c.duration);c.from=c.to;c.to=d;b&&(c.delay=e)});a.reversed=a.reversed?!1:!0},Y=function(a){return Math.max.apply(Math,a.map(function(a){return a.totalDuration}))},Z=function(a){return Math.min.apply(Math,a.map(function(a){return a.delay}))},N=function(a){var b=[],c=[];a.tweens.forEach(function(a){if("css"===a.type||
-"transform"===a.type)b.push("css"===a.type?D(a.name):"transform"),a.animatables.forEach(function(a){c.push(a.target)})});return{properties:G(b).join(", "),elements:G(c)}},aa=function(a){var b=N(a);b.elements.forEach(function(a){a.style.willChange=b.properties})},ba=function(a){N(a).elements.forEach(function(a){a.style.removeProperty("will-change")})},ca=function(a,b){var c=a.path,d=a.value*b,e=function(e){e=e||0;return c.getPointAtLength(1<b?a.value+e:d+e)},h=e(),f=e(-1),e=e(1);switch(a.name){case "translateX":return h.x;
-case "translateY":return h.y;case "rotate":return 180*Math.atan2(e.y-f.y,e.x-f.x)/Math.PI}},da=function(a,b){var c=Math.min(Math.max(b-a.delay,0),a.duration)/a.duration,d=a.to.numbers.map(function(b,d){var e=a.from.numbers[d],f=C[a.easing](c,a.elasticity),e=a.path?ca(a,f):e+f*(b-e);return e=a.round?Math.round(e*a.round)/a.round:e});return U(d,a.to.strings,a.from.strings)},O=function(a,b){var c;a.currentTime=b;a.progress=b/a.duration*100;for(var d=0;d<a.tweens.length;d++){var e=a.tweens[d];e.currentValue=
-da(e,b);for(var f=e.currentValue,l=0;l<e.animatables.length;l++){var k=e.animatables[l],m=k.id,k=k.target,g=e.name;switch(e.type){case "css":k.style[g]=f;break;case "attribute":k.setAttribute(g,f);break;case "object":k[g]=f;break;case "transform":c||(c={}),c[m]||(c[m]=[]),c[m].push(f)}}}if(c)for(d in x||(x=(v(document.body,"transform")?"":"-webkit-")+"transform"),c)a.animatables[d].target.style[x]=c[d].join(" ")},P=function(a){var b={};b.animatables=V(a.targets);b.settings=u(a,t);var c=b.settings,
-d=[],e;for(e in a)if(!t.hasOwnProperty(e)&&"targets"!==e){var h=f.obj(a[e])?A(a[e]):{value:a[e]};h.name=e;d.push(u(h,c))}b.properties=d;b.tweens=X(b.animatables,b.properties);b.duration=b.tweens.length?Y(b.tweens):a.duration;b.delay=b.tweens.length?Z(b.tweens):a.delay;b.currentTime=0;b.progress=0;b.ended=!1;return b},n=[],w=0,ea=function(){var a=function(){w=requestAnimationFrame(b)},b=function(b){if(n.length){for(var c=0;c<n.length;c++)n[c].tick(b);a()}else cancelAnimationFrame(w),w=0};return a}(),
-k=function(a){var b=P(a),c={};b.tick=function(a){b.ended=!1;c.start||(c.start=a);c.current=Math.min(Math.max(c.last+a-c.start,0),b.duration);O(b,c.current);var d=b.settings;c.current>=b.delay&&(d.begin&&d.begin(b),d.begin=void 0,d.update&&d.update(b));c.current>=b.duration&&(d.loop?(c.start=a,"alternate"===d.direction&&B(b,!0),f.num(d.loop)&&d.loop--):(b.ended=!0,b.pause(),d.complete&&d.complete(b)),c.last=0)};b.seek=function(a){O(b,a/100*b.duration)};b.pause=function(){ba(b);var a=n.indexOf(b);-1<
-a&&n.splice(a,1)};b.play=function(a){b.pause();a&&(b=u(P(u(a,b.settings)),b));c.start=0;c.last=b.ended?0:b.currentTime;a=b.settings;"reverse"===a.direction&&B(b);"alternate"!==a.direction||a.loop||(a.loop=1);aa(b);n.push(b);w||ea()};b.restart=function(){b.reversed&&B(b);b.pause();b.seek(0);b.play()};b.settings.autoplay&&b.play();return b};k.version="1.1.3";k.speed=1;k.list=n;k.remove=function(a){a=z(f.arr(a)?a.map(r):r(a));for(var b=n.length-1;0<=b;b--)for(var c=n[b],d=c.tweens,e=d.length-1;0<=e;e--)for(var h=
-d[e].animatables,k=h.length-1;0<=k;k--)F(a,h[k].target)&&(h.splice(k,1),h.length||d.splice(e,1),d.length||c.pause())};k.easings=C;k.getValue=J;k.path=function(a){a=f.str(a)?E(a)[0]:a;return{path:a,value:a.getTotalLength()}};k.random=function(a,b){return Math.floor(Math.random()*(b-a+1))+a};return k});
diff --git a/package.json b/package.json
index 3cce6710..62d0b7c6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "animejs",
- "version": "1.1.3",
+ "version": "2.0.0",
"description": "JavaScript animation engine",
"main": "anime.js",
"repository": {