JavaScript animation engine
Update examples
Julian Garniera1b5b0104bbd
diff --git a/documentation/assets/js/anime.2.1.0.js b/documentation/assets/js/anime.2.1.0.jsnew file mode 100644index 00000000..affd65ec--- /dev/null+++ b/documentation/assets/js/anime.2.1.0.js@@ -0,0 +1,939 @@+/**+ * http://animejs.com+ * JavaScript animation engine+ * @version v2.1.0+ * @author Julian Garnier+ * @copyright ©2017 Julian Garnier+ * Released under the MIT license+**/++(function(root, factory) {+ if (typeof define === 'function' && define.amd) {+ // AMD. Register as an anonymous module.+ define([], factory);+ } else if (typeof module === 'object' && module.exports) {+ // Node. Does not work with strict CommonJS, but+ // only CommonJS-like environments that support module.exports,+ // like Node.+ module.exports = factory();+ } else {+ // Browser globals (root is window)+ root.anime = factory();+ }+}(this, () => {++ // Defaults++ const defaultInstanceSettings = {+ update: undefined,+ begin: undefined,+ run: undefined,+ complete: undefined,+ loop: 1,+ direction: 'normal',+ autoplay: true,+ offset: 0+ }++ const defaultTweenSettings = {+ duration: 1000,+ delay: 0,+ easing: 'easeOutElastic',+ elasticity: 500,+ round: 0+ }++ const validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skewX', 'skewY', 'perspective'];+ let transformString;++ // Utils++ 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++ 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;+ }++ 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);+ }+ }++ 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;++ })();++ const easings = (() => {++ const names = ['Quad', 'Cubic', 'Quart', 'Quint', 'Sine', 'Expo', 'Circ', 'Back', 'Elastic'];++ // Elastic easing adapted from jQueryUI http://api.jqueryui.com/easings/++ function elastic(t, p) {+ return t === 0 || t === 1 ? t :+ -Math.pow(2, 10 * (t - 1)) * Math.sin((((t - 1) - (p / (Math.PI * 2.0) * Math.asin(1))) * (Math.PI * 2)) / p );+ }++ // Approximated Penner equations http://matthewlein.com/ceaser/++ const equations = {+ 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.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.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 */+ ]+ }++ let functions = {+ linear: bezier(0.250, 0.250, 0.750, 0.750)+ }++ 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();+ }++ function selectString(str) {+ if (is.col(str)) return;+ try {+ let nodes = document.querySelectorAll(str);+ return nodes;+ } catch(e) {+ return;+ }+ }++ // Arrays++ function flattenArray(arr) {+ return arr.reduce((a, b) => a.concat(is.arr(b) ? flattenArray(b) : b), []);+ }++ 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];+ }++ function arrayContains(arr, val) {+ return arr.some(a => a === val);+ }++ // Objects++ function objectHas(obj, prop) {+ return obj.hasOwnProperty(prop);+ }++ function cloneObject(o) {+ let clone = {};+ for (let p in o) clone[p] = o[p];+ return clone;+ }++ function replaceObjectProps(o1, o2) {+ let o = cloneObject(o1);+ for (let p in o1) o[p] = objectHas(o2, p) ? o2[p] : o1[p];+ return o;+ }++ 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++ 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;+ if (t < 1/2) return q;+ if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;+ return p;+ }+ let r, g, b;+ if (s == 0) {+ r = g = b = l;+ } else {+ 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})`;+ }++ function colorToRgb(val) {+ if (is.rgb(val)) return val;+ if (is.hex(val)) return hexToRgb(val);+ if (is.hsl(val)) return hslToRgb(val);+ }++ // Units++ function getUnit(val) {+ const split = /([\+\-]?[0-9#\.]+)(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(val);+ if (split) return split[2];+ }++ function getTransformUnit(propName) {+ if (stringContains(propName, 'translate') || propName === 'perspective') return 'px';+ if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) return 'deg';+ }++ // Values++ function minMaxValue(val, min, max) {+ return Math.min(Math.max(val, min), max);+ }++ function getFunctionValue(val, animatable) {+ if (!is.fnc(val)) return val;+ return val(animatable.target, animatable.id, animatable.total);+ }++ function getCSSValue(el, prop) {+ if (prop in el.style) {+ return getComputedStyle(el).getPropertyValue(stringToHyphens(prop)) || '0';+ }+ }++ 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;+ let match = [];+ let props = [];+ let values = [];+ const rgx = /(\w+)\((.+?)\)/g;+ while (match = rgx.exec(str)) {+ props.push(match[1]);+ values.push(match[2]);+ }+ const value = values.filter((val, i) => props[i] === propName );+ return value.length ? 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 getRelativeValue(to, from) {+ const operator = /^(\*=|\+=|-=)/.exec(to);+ if (!operator) return to;+ const u = getUnit(to) || 0;+ const x = parseFloat(from);+ const y = parseFloat(to.replace(operator[0], ''));+ switch (operator[0][0]) {+ case '+': return x + y + u;+ case '-': return x - y + u;+ case '*': return x * y + u;+ }+ }++ function validateValue(val, unit) {+ if (is.col(val)) return colorToRgb(val);+ const originalUnit = getUnit(val);+ const unitLess = originalUnit ? val.substr(0, val.length - originalUnit.length) : val;+ return unit && !/\s/g.test(val) ? unitLess + unit : unitLess;+ }++ // getTotalLength() equivalent for circle, rect, polyline, polygon and line shapes.+ // adapted from https://gist.github.com/SebLambla/3e0550c496c236709744++ function getDistance(p1, p2) {+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));+ }++ function getCircleLength(el) {+ return 2 * Math.PI * el.getAttribute('r');+ }++ function getRectLength(el) {+ return (el.getAttribute('width') * 2) + (el.getAttribute('height') * 2);+ }++ function getLineLength(el) {+ return getDistance(+ {x: el.getAttribute('x1'), y: el.getAttribute('y1')},+ {x: el.getAttribute('x2'), y: el.getAttribute('y2')}+ );+ }++ function getPolylineLength(el) {+ const points = el.points;+ let totalLength = 0;+ let previousPos;+ for (let i = 0 ; i < points.numberOfItems; i++) {+ const currentPos = points.getItem(i);+ if (i > 0) totalLength += getDistance(previousPos, currentPos);+ previousPos = currentPos;+ }+ return totalLength;+ }++ function getPolygonLength(el) {+ const points = el.points;+ return getPolylineLength(el) + getDistance(points.getItem(points.numberOfItems - 1), points.getItem(0));+ }++ // Path animation++ function getTotalLength(el) {+ if (el.getTotalLength) return el.getTotalLength();+ switch(el.tagName.toLowerCase()) {+ case 'circle': return getCircleLength(el);+ case 'rect': return getRectLength(el);+ case 'line': return getLineLength(el);+ case 'polyline': return getPolylineLength(el);+ case 'polygon': return getPolygonLength(el);+ }+ }++ function setDashoffset(el) {+ const pathLength = getTotalLength(el);+ el.setAttribute('stroke-dasharray', pathLength);+ return pathLength;+ }++ // Motion path++ function isPath(val) {+ return is.obj(val) && objectHas(val, 'totalLength');+ }++ 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: getTotalLength(el) * (p / 100)+ }+ }+ }++ function getPathProgress(path, progress) {+ function point(offset = 0) {+ const l = progress + offset >= 1 ? progress + offset : 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;+ }+ }++ // Decompose / recompose functions adapted from Animate Plus https://github.com/bendc/animateplus++ function decomposeValue(val, unit) {+ const rgx = /-?\d*\.?\d+/g;+ const value = validateValue((isPath(val) ? val.totalLength : val), unit) + '';+ return {+ original: value,+ numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0],+ strings: (is.str(val) || unit) ? value.split(rgx) : []+ }+ }++ function recomposeValue(numbers, strings) {+ return (strings.length === 0) ? numbers[0] : strings.reduce((a, b, i) => a + numbers[i - 1] + (b ? b : ' '));+ }++ // Animatables++ 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: parsed.length};+ });+ }++ // Properties++ function normalizePropertyTweens(prop, tweenSettings) {+ let settings = cloneObject(tweenSettings);+ if (is.arr(prop)) {+ const l = prop.length;+ const isFromTo = (l === 2 && !is.obj(prop[0]));+ if (!isFromTo) {+ // Duration divided by the number of tweens+ if (!is.fnc(tweenSettings.duration)) settings.duration = tweenSettings.duration / l;+ } else {+ // Transform [from, to] values shorthand to a valid tween value+ prop = {value: prop};+ }+ }+ return toArray(prop).map((v, i) => {+ // Default delay value should be applied only on the first tween+ const delay = !i ? tweenSettings.delay : 0;+ // Use path object as a tween value+ let obj = is.obj(v) && !isPath(v) ? v : {value: v};+ // Set default delay value+ if (is.und(obj.delay)) obj.delay = delay;+ return obj;+ }).map(k => mergeObjects(k, settings));+ }++ function getProperties(instanceSettings, tweenSettings, params) {+ let properties = [];+ const settings = mergeObjects(instanceSettings, tweenSettings);+ for (let p in params) {+ if (!objectHas(settings, p) && p !== 'targets') {+ properties.push({+ name: p,+ offset: settings['offset'],+ tweens: normalizePropertyTweens(params[p], tweenSettings)+ });+ }+ }+ return properties;+ }++ // Tweens++ 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 (value.length === 1) value = value[0];+ }+ t[p] = value;+ }+ t.duration = parseFloat(t.duration);+ t.delay = parseFloat(t.delay);+ 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(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 = getRelativeValue(is.arr(tweenValue) ? tweenValue[1] : tweenValue, from);+ const unit = getUnit(to) || getUnit(from) || getUnit(originalValue);+ tween.isPath = isPath(tweenValue);+ tween.from = decomposeValue(from, unit);+ tween.to = decomposeValue(to, unit);+ tween.start = previousTween ? previousTween.end : prop.offset;+ tween.end = tween.start + tween.delay + tween.duration;+ tween.easing = normalizeEasing(tween.easing);+ tween.elasticity = (1000 - minMaxValue(tween.elasticity, 1, 999)) / 1000;+ if (is.col(tween.from.original)) tween.round = 1;+ previousTween = tween;+ return tween;+ });+ }++ // Tween progress++ const setTweenProgress = {+ 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})`);+ }+ }++ // 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[tweens.length - 1].end,+ delay: tweens[0].delay+ }+ }+ }++ function getAnimations(animatables, properties) {+ return flattenArray(animatables.map(animatable => {+ return properties.map(prop => {+ return createAnimation(animatable, prop);+ });+ })).filter(a => !is.und(a));+ }++ // Create Instance++ function getInstanceTimings(type, animations, tweenSettings) {+ const math = (type === 'delay') ? Math.min : Math.max;+ return animations.length ? math.apply(Math, animations.map(anim => anim[type])) : tweenSettings[type];+ }++ function createNewInstance(params) {+ const instanceSettings = replaceObjectProps(defaultInstanceSettings, params);+ const tweenSettings = replaceObjectProps(defaultTweenSettings, params);+ const animatables = getAnimatables(params.targets);+ const properties = getProperties(instanceSettings, tweenSettings, params);+ const animations = getAnimations(animatables, properties);+ return mergeObjects(instanceSettings, {+ children: [],+ animatables: animatables,+ animations: animations,+ duration: getInstanceTimings('duration', animations, tweenSettings),+ delay: getInstanceTimings('delay', animations, tweenSettings)+ });+ }++ // Core++ let activeInstances = [];+ let raf = 0;++ const engine = (() => {+ function play() { raf = requestAnimationFrame(step); };+ function step(t) {+ const activeLength = activeInstances.length;+ if (activeLength) {+ let i = 0;+ while (i < activeLength) {+ if (activeInstances[i]) activeInstances[i].tick(t);+ i++;+ }+ play();+ } else {+ cancelAnimationFrame(raf);+ raf = 0;+ }+ }+ return play;+ })();+++ // Public Instance++ function anime(params = {}) {++ let now, startTime, lastTime = 0;++ let resolve = null;++ function makePromise() {+ return window.Promise && new Promise(_resolve => resolve = _resolve);+ }++ let promise = makePromise();++ let instance = createNewInstance(params);++ function toggleInstanceDirection() {+ instance.reversed = !instance.reversed;+ }++ function adjustTime(time) {+ return instance.reversed ? instance.duration - time : time;+ }++ function syncInstanceChildren(time) {+ const children = instance.children;+ if (time >= instance.currentTime) {+ for (let i = 0; i < children.length; i++) children[i].seek(time);+ } else {+ for (let i = children.length; i--;) children[i].seek(time);+ }+ }++ function setAnimationsProgress(insTime) {+ let i = 0;+ let transforms = {};+ const animations = instance.animations;+ while (i < animations.length) {+ const anim = animations[i];+ const animatable = anim.animatable;+ const tweens = anim.tweens;+ const tween = tweens.filter(t => (insTime < t.end))[0] || tweens[tweens.length - 1];+ const elapsed = minMaxValue(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration;+ const eased = isNaN(elapsed) ? 1 : tween.easing(elapsed, tween.elasticity);+ const round = tween.round;+ const progress = recomposeValue(tween.to.numbers.map((number, p) => {+ const start = tween.from.numbers[p];+ let value = start + eased * (number - start);+ if (tween.isPath) value = getPathProgress(tween.value, value);+ if (round) value = Math.round(value * round) / round;+ return value;+ }), tween.to.strings);+ setTweenProgress[anim.type](animatable.target, anim.property, progress, transforms, animatable.id);+ anim.currentValue = progress;+ i++;+ }+ if (transforms) {+ let id; for (id in transforms) {+ if (!transformString) {+ const t = 'transform';+ transformString = (getCSSValue(document.body, t) ? t : `-webkit-${t}`);+ }+ instance.animatables[id].target.style[transformString] = transforms[id].join(' ');+ }+ }+ instance.currentTime = insTime;+ instance.progress = (insTime / instance.duration) * 100;+ }++ function setCallback(cb) {+ if (instance[cb]) instance[cb](instance);+ }++ function countIteration() {+ if (instance.remaining && instance.remaining !== true) {+ instance.remaining--;+ }+ }++ function setInstanceProgress(engineTime) {+ const insDuration = instance.duration;+ const insOffset = instance.offset;+ const insDelay = instance.delay;+ const insCurrentTime = instance.currentTime;+ const insReversed = instance.reversed;+ const insTime = adjustTime(engineTime);+ if (instance.children.length) syncInstanceChildren(insTime);+ if (insTime >= insDelay) {+ setCallback('run');+ if (!instance.began) {+ instance.began = true;+ setCallback('begin');+ }+ }+ if (insTime > insOffset && insTime < insDuration) {+ setAnimationsProgress(insTime);+ } else {+ if (insTime <= insOffset && insCurrentTime !== 0) {+ setAnimationsProgress(0);+ if (insReversed) countIteration();+ }+ if (insTime >= insDuration && insCurrentTime !== insDuration) {+ setAnimationsProgress(insDuration);+ if (!insReversed) countIteration();+ }+ }+ setCallback('update');+ if (engineTime >= insDuration) {+ if (instance.remaining) {+ startTime = now;+ if (instance.direction === 'alternate') toggleInstanceDirection();+ } else {+ instance.pause();+ if (!instance.completed) {+ instance.completed = true;+ setCallback('complete');+ if ('Promise' in window) {+ resolve();+ promise = makePromise();+ }+ }+ }+ lastTime = 0;+ }+ }++ instance.reset = function() {+ const direction = instance.direction;+ const loops = instance.loop;+ instance.currentTime = 0;+ instance.progress = 0;+ instance.paused = true;+ instance.began = false;+ instance.completed = false;+ instance.reversed = direction === 'reverse';+ instance.remaining = direction === 'alternate' && loops === 1 ? 2 : loops;+ setAnimationsProgress(0);+ for (let i = instance.children.length; i--; ){+ instance.children[i].reset();+ }+ }++ instance.tick = function(t) {+ now = t;+ if (!startTime) startTime = now;+ const engineTime = (lastTime + now - startTime) * anime.speed;+ setInstanceProgress(engineTime);+ }++ instance.seek = function(time) {+ setInstanceProgress(adjustTime(time));+ }++ instance.pause = function() {+ const i = activeInstances.indexOf(instance);+ if (i > -1) activeInstances.splice(i, 1);+ instance.paused = true;+ }++ instance.play = function() {+ if (!instance.paused) return;+ instance.paused = false;+ startTime = 0;+ lastTime = adjustTime(instance.currentTime);+ activeInstances.push(instance);+ if (!raf) engine();+ }++ instance.reverse = function() {+ toggleInstanceDirection();+ startTime = 0;+ lastTime = adjustTime(instance.currentTime);+ }++ instance.restart = function() {+ instance.pause();+ instance.reset();+ instance.play();+ }++ instance.finished = promise;++ instance.reset();++ if (instance.autoplay) instance.play();++ return instance;++ }++ // Remove targets from animation++ function removeTargets(targets) {+ const targetsArray = parseTargets(targets);+ for (let i = activeInstances.length; i--;) {+ const instance = activeInstances[i];+ const animations = instance.animations;+ for (let a = animations.length; a--;) {+ if (arrayContains(targetsArray, animations[a].animatable.target)) {+ animations.splice(a, 1);+ if (!animations.length) instance.pause();+ }+ }+ }+ }++ // Timeline++ function timeline(params) {+ let tl = anime(params);+ tl.pause();+ tl.duration = 0;+ tl.add = function(instancesParams) {+ tl.children.forEach(i => { i.began = true; i.completed = true; });+ toArray(instancesParams).forEach(instanceParams => {+ let insParams = mergeObjects(instanceParams, replaceObjectProps(defaultTweenSettings, params || {}));+ insParams.targets = insParams.targets || params.targets;+ const tlDuration = tl.duration;+ const insOffset = insParams.offset;+ insParams.autoplay = false;+ insParams.offset = is.und(insOffset) ? tlDuration : getRelativeValue(insOffset, tlDuration);+ tl.began = true;+ tl.completed = true;+ tl.seek(insParams.offset);+ const ins = anime(insParams);+ ins.began = true;+ ins.completed = true;+ if (ins.duration > tlDuration) tl.duration = ins.duration;+ tl.children.push(ins);+ });+ tl.seek(0);+ tl.reset();+ if (tl.autoplay) tl.restart();+ return tl;+ }+ return tl;+ }++ anime.version = '2.1.0';+ anime.speed = 1;+ anime.running = activeInstances;+ anime.remove = removeTargets;+ anime.getValue = getOriginalTargetValue;+ anime.path = getPath;+ anime.setDashoffset = setDashoffset;+ anime.bezier = bezier;+ anime.easings = easings;+ anime.timeline = timeline;+ anime.random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;++ return anime;++}));diff --git a/documentation/examples/anime-DOM-stress-test.html b/documentation/examples/anime-DOM-stress-test.htmlindex 0907d0d5..44913f64 100644--- a/documentation/examples/anime-DOM-stress-test.html+++ b/documentation/examples/anime-DOM-stress-test.html@@ -34,8 +34,8 @@height: 1em;margin: -.5em 0 0 -.5em;border: 1px solid currentColor;- /*background-color: currentColor;*/- font-size: 40px;+ background-color: currentColor;+ font-size: 30px;border-radius: 50%;transform: scale(0);}@@ -46,11 +46,12 @@<script>const wrapperEl = document.body;- const numberOfEls = 360;- const duration = 3000;+ const numberOfEls = 500;+ const duration = 2000;const delay = duration / numberOfEls;const radius = window.innerWidth < window.innerHeight ? window.innerWidth : window.innerHeight;- const distance = radius / 4 <= 150 ? 150 : radius / 2.5;+ const distance = (radius / 4 <= 150 ? 150 : radius) + 100;+let tl = anime.timeline({duration: delay,complete: function() { tl.restart(); }@@ -59,22 +60,23 @@function createEl(i) {let el = document.createElement('div');const hue = Math.round(360 / numberOfEls * i);- const angle = Math.round(180 / numberOfEls * i * 3);+ // const angle = Math.round(360 / numberOfEls * i * 5);+ var angle = Math.random() * Math.PI * 2;el.classList.add('el');el.style.color = 'hsl(' + hue + ', 40%, 60%)';- el.style.transform = 'scale(0)';+ // el.style.transform = 'scale(0)';el.style.zIndex = numberOfEls - i;tl.add({begin: function() {anime({targets: el,- translateX: [0, Math.sin(angle) * distance],- translateY: [0,Math.cos(angle) * distance ],+ translateX: ['0px', Math.sin(angle) * distance + 'px'],+ translateY: ['0px', Math.cos(angle) * distance + 'px'],// scale: [0, 32],- scale: [- {value: [0, 1], duration: duration / 2, easing: 'easeOutBack'},- {value: 0, duration: duration / 2, easing: 'easeInBack'}- ],+ // scale: [+ // {value: [0, 1], duration: duration / 2, easing: 'easeOutBack'},+ // {value: 0, duration: duration / 2, easing: 'easeInBack'}+ // ],easing: 'easeInOutSine',duration: duration});diff --git a/documentation/examples/anime-complex-properties.html b/documentation/examples/anime-complex-properties.htmlindex a75bb686..e2910f66 100644--- a/documentation/examples/anime-complex-properties.html+++ b/documentation/examples/anime-complex-properties.html@@ -50,7 +50,8 @@<div class="rgba item color-09"></div><div class="calc item color-11"></div><div class="zero-value item color-02"></div>- <div class="clip-path item color-04"></div>+ <div class="round-value item color-04"></div>+ <div class="clip-path item color-06"></div><script>var boxShadow = anime({targets: '.box-shadow',@@ -105,6 +106,14 @@direction: 'alternate',easing: 'linear'});+ var roundValue = anime({+ targets: '.round-value',+ translateY: 100,+ loop: true,+ round: 1,+ direction: 'alternate',+ easing: 'linear'+ });var clipPath = anime({targets: '.clip-path',clipPath: ['circle(0px at center)', 'circle(100px at center)'],diff --git a/documentation/examples/anime-speed-test.html b/documentation/examples/anime-speed-test.htmlindex ad7ef83c..d56b2a82 100644--- a/documentation/examples/anime-speed-test.html+++ b/documentation/examples/anime-speed-test.html@@ -17,15 +17,15 @@<link rel="icon" type="image/png" href="../assets/img/icons/favicon.png"><link href="../assets/css/anime.css" rel="stylesheet"><script src="../../anime.js"></script>- <!-- <script src="../../anime-dev.js"></script> -->+ <!-- <script src="../assets/js/anime.2.1.0.js"></script> --><!-- <script src="../assets/js/anime.2.0.1.js"></script> --><!-- <script src="../assets/js/anime.1.3.js"></script> --><style>body {+ overflow: hidden;position: absolute;width: 100%;height: 100%;- overflow: hidden;}.wrapper {position: absolute;@@ -33,55 +33,42 @@left: 0;width: 100%;height: 100%;- overflow: hidden;}.particule {position: absolute;- width: 1px;- height: 1px;- border-radius: 50%;- /*background-color: #FBF38C;*/- background-color: currentColor;}</style></head><body><script>- var maxElements = 500;+ var numberOfEls = 1000;var duration = 1000;- var width = window.innerWidth;- var height = window.innerHeight;- var centerX = width / 2;- var centerY = height / 2;- var radius = Math.sqrt(centerX * centerX + centerY * centerY);+ var midScreenX = window.innerWidth / 2;+ var midScreenY = window.innerHeight / 2;+ var radius = Math.sqrt(midScreenX * midScreenX + midScreenY * midScreenY);var fragment = document.createDocumentFragment();- var colors = ['#FF1461', '#18FF92', '#5A87FF'];- var i = 0;- while (i <= maxElements) {+ for (var i = 0; i < numberOfEls; i++) {+ var hue = Math.round(360 / numberOfEls * i);var angle = Math.random() * Math.PI * 2;var el = document.createElement('div');- var color = Math.round((i/maxElements)*(colors.length-1));- // el.style.color = colors[anime.random(0, 3)];- // el.style.color = colors[color];+ el.classList.add('particule');+ el.style.backgroundColor = 'hsl(' + hue + ', 40%, 60%)';el.style.width = '1px';el.style.height = '1px';- el.classList.add('particule');anime({targets: el,- width: ['1px', '16px'],- height: ['1px', '16px'],- left: [centerX + 'px', Math.cos(angle) * radius + (width/2) + 'px'],- top: [centerY + 'px', Math.sin(angle) * radius + (height/2) + 'px'],- color: ['#FF1461', '#5A87FF'],- delay: (duration / maxElements) * i,+ width: ['1px', '20px'],+ height: ['1px', '20px'],+ left: [midScreenX + 'px', Math.cos(angle) * radius + midScreenX + 'px'],+ top: [midScreenY + 'px', Math.sin(angle) * radius + midScreenY + 'px'],+ delay: (duration / numberOfEls) * i,duration: duration,- easing: 'easeInCubic',+ easing: 'easeInExpo',loop: true});fragment.appendChild(el);- i++;}document.body.appendChild(fragment);diff --git a/documentation/examples/anime-staggered-animations-02.html b/documentation/examples/anime-staggered-animations-02.htmlindex 80d74926..8e17af57 100644--- a/documentation/examples/anime-staggered-animations-02.html+++ b/documentation/examples/anime-staggered-animations-02.html@@ -17,7 +17,7 @@<link rel="icon" type="image/png" href="../assets/img/icons/favicon.png"><link href="../assets/css/anime.css" rel="stylesheet"><script src="../../anime.js"></script>- <!-- <script src="../../anime-dev.js"></script> -->+ <!-- <script src="../assets/js/anime.2.1.0.js"></script> --><!-- <script src="../assets/js/anime.2.0.2.js"></script> --><!-- <script src="../assets/js/anime.1.3.js"></script> --><style>@@ -41,7 +41,7 @@border-radius: 50%;top: 50%;left: 50%;- border: 1px solid currentColor;+ border: 2px solid currentColor;/*background-color: currentColor;*/}</style>@@ -51,10 +51,10 @@<script>const wrapperEl = document.querySelector('.wrapper');- const numberOfEls = 300;- const duration = 8000;+ const numberOfEls = 72;+ const duration = 6000;const delay = duration / numberOfEls;- const gap = 8;+ const gap = 10;let tl = anime.timeline({duration: delay / 2,@@ -75,17 +75,19 @@el.style.marginTop = -(diameter / 2) + 'px';el.style.marginLeft = -(diameter / 2) + 'px';el.style.opacity = 0;- el.style.color = 'hsl(' + hue + ', 30%, 30%)';+ // el.style.color = 'hsl(' + hue + ', 10%, 10%)';tl.add({begin: function() {anime({targets: el,opacity: [0, 1],- color: ['hsl(' + hue + ', 30%, 30%)', 'hsl(' + hue + ', 50%, 50%)'],+ color: ['hsl(' + hue + ', 10%, 10%)', 'hsl(' + hue + ', 50%, 50%)'],translateY: [0, translateY],- // scale: [1, 2],- // rotate: [0, 45],- // borderRadius: ['50%', '40%'],+ rotate: [0, 90],+ borderRadius: {+ value: ['30%', '50%'],+ easing: 'easeInOutQuad'+ },easing: 'easeInOutSine',direction: 'alternate',duration: duration / 4diff --git a/documentation/examples/anime-staggered-animations.html b/documentation/examples/anime-staggered-animations.htmlindex ea40ddaa..57534550 100644--- a/documentation/examples/anime-staggered-animations.html+++ b/documentation/examples/anime-staggered-animations.html@@ -53,7 +53,7 @@<script>const wrapperEl = document.querySelector('.wrapper');- const numberOfEls = 180;+ const numberOfEls = 90;const duration = 6000;const delay = duration / numberOfEls;diff --git a/documentation/examples/anime-svg-tests.html b/documentation/examples/anime-svg-tests.htmlnew file mode 100644index 00000000..778fbbde--- /dev/null+++ b/documentation/examples/anime-svg-tests.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<html>+<head>+ <title>SVG tests | anime.js</title>+ <meta charset="utf-8">+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">+ <meta property="og:title" content="anime.js">+ <meta property="og:url" content="http://animejs.com">+ <meta property="og:description" content="Javascript Animation Engine">+ <meta property="og:image" content="http://animejs.com/documentation/assets/img/icons/og.png">+ <meta name="twitter:card" content="summary">+ <meta name="twitter:title" content="anime.js">+ <meta name="twitter:site" content="@juliangarnier">+ <meta name="twitter:description" content="Javascript Animation Engine">+ <meta name="twitter:image" content="http://animejs.com/documentation/assets/img/icons/twitter.png">+ <link rel="apple-touch-icon-precomposed" href="../assets/img/icons/apple-touch-icon.png">+ <link rel="icon" type="image/png" href="../assets/img/icons/favicon.png">+ <link href="../assets/css/anime.css" rel="stylesheet">+ <script src="../../anime.js"></script>+ <!-- <script src="../assets/js/anime.1.3.js"></script> -->+ <!-- <script src="../assets/js/anime.2.0.1.js"></script> -->+ <style>+ body {+ display: flex;+ justify-content: center;+ align-items: center;+ min-height: 100vh;+ }+ </style>+</head>+<body>+ <svg xmlns="http://www.w3.org/2000/svg" id="svg8" width="500" height="500" viewBox="0 0 500 500">+ <g id="layer1">+ <path id="right" fill="none" stroke="#c3c3c3" stroke-width="3" d="M226.07 433.57c1.43-75 67.5-231.78 233.22-140.36"/>+ <path id="left" fill="none" stroke="#c3c3c3" stroke-width="3" d="M226.07 433.57c1.43-75-73.93-166.07-179.64-208.2"/>+ <path id="middle" fill="none" stroke="#c3c3c3" stroke-width="3" d="M226.07 433.57c1.43-75 .36-212.5-40.36-350.36"/>+ <path id="gras" fill="none" stroke="#FFF" stroke-width="3" d="M226.07 433.57c1.43-75-73.93-166.07-179.64-208.2"/>+ </g>+ </svg>+ <svg xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 700 700">+ <path id="morph" fill="#FF0000" fill-rule="evenodd" d="M207.16 334.2c-11.66-52.7 16.3-93.27 54.68-181.1 38.37-87.84 90.58-150.57 188.5-136 97.92 14.59 66.56 161.92 30.21 235.42-36.35 73.51-33.76 120.9-37.72 248.87-3.97 127.96-36.96 182.41-133.5 182.75-96.55.34-112.66-14.67-123.57-158.64-10.92-143.98 33.06-138.6 21.4-191.3z"/>+ </svg>+ <script>+ anime({+ targets: '#gras',+ d: [+ 'M226.07 433.57c1.43-75-73.93-166.07-179.64-208.2',+ 'M226.07 433.57c1.43-75 .36-212.5-40.36-350.36',+ 'M226.07 433.57c1.43-75 67.5-231.78 233.22-140.36',+ 'M226.07 433.57c1.43-75 .36-212.5-40.36-350.36',+ 'M226.07 433.57c1.43-75-73.93-166.07-179.64-208.2',+ ],+ duration: 3000,+ loop: true,+ });+ anime({+ targets: '#morph',+ d: 'M241.38 318.26c-11.66-52.7-44.84-99.51-6.93-170.64 37.9-71.13 186.18-166.6 252.91-118.68 66.74 47.92 41.33 158.28 0 227.64-41.32 69.36-64.65 170-30.2 272.98 34.43 102.97-50.96 163.97-141.02 158.64-90.05-5.32-187.73-158.89-121.2-225.6 66.52-66.72 58.1-91.64 46.44-144.34z',+ duration: 3000,+ direction: 'alternate',+ loop: true,+ });+ </script>+</body>+</html>diff --git a/documentation/examples/anime-tests.html b/documentation/examples/anime-tests.htmlindex dc9fde31..de33938e 100644--- a/documentation/examples/anime-tests.html+++ b/documentation/examples/anime-tests.html@@ -1,7 +1,7 @@<!DOCTYPE html><html><head>- <title>tests | anime.js</title>+ <title>Tests | anime.js</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta property="og:title" content="anime.js">@@ -19,151 +19,45 @@<script src="../../anime.js"></script><!-- <script src="../assets/js/anime.2.0.2.js"></script> --><!-- <script src="../assets/js/anime.1.3.js"></script> -->+ <style><style>body {display: flex;justify-content: center;align-items: center;- width: 100%;- height: 100vh;+ min-height: 100vh;}- .el {- position: relative;- width: 20px;- height: 20px;- background: currentColor;+ .item {+ width: 100px;+ height: 100px;+ border-radius: 50%;+ background-color: currentColor;+ margin: 10px;}</style></head><body>- <div class="el color-01"></div>- <div class="el color-04"></div>- <div class="el color-08"></div>- <div class="el color-12"></div>+ <div class="item duration-0 color-01"></div>+ <div class="item seek-0 color-04"></div><script>-- var rgba = anime({- targets: '.color-01',- backgroundColor: ['rgba(255,255,0,.1)', 'rgba(255,0,0,.5)'],- easing: 'linear',- loop: true- });-- console.log(rgba);-- var hsl = anime({- targets: '.color-04',- backgroundColor: ['hsl(100,60%,60%)', 'hsl(300,40%,80%)'],- easing: 'linear',- loop: true+ anime({+ targets: '.duration-0',+ translateX: 100,+ duration: 0,+ begin: function() {console.log('duration-0 begin') },+ update: function() {console.log('duration-0 update') },+ complete: function() {console.log('duration-0 complte') }});-- console.log(hsl);-- var hsla = anime({- targets: '.color-08',- backgroundColor: ['hsla(100,60%,60%,.1)', 'hsla(300,40%,80%,.5)'],- easing: 'linear',- loop: true+ var seek0 = anime({+ targets: '.seek-0',+ translateX: [100, 0],+ autoplay: false,+ begin: function() {console.log('seek-0 begin') },+ update: function() {console.log('seek-0 update') },+ complete: function() {console.log('seek-0 complte') }});- console.log(hsla);-- var hslaRgba = anime({- targets: '.color-12',- backgroundColor: ['hsla(100,60%,60%,.2)', 'rgba(200,0,0,.1)'],- easing: 'linear',- loop: true- });-- console.log(hslaRgba);-- // var seek0 = anime({- // targets: '.color-01',- // translateY: [200, 100],- // delay: 1000,- // loop: true,- // autoplay: false,- // update: function(anim) { console.log('seek0 updating', anim.currentTime);},- // begin: function(anim) { console.log('seek0 began', anim.currentTime);},- // run: function(anim) { console.log('seek0 runing', anim.currentTime);},- // complete: function(anim) { console.log('seek0 completed', anim.currentTime);}- // });- // seek0.seek(0);- // var duration0 = anime({- // targets: '.color-04',- // translateY: [100, 200],- // autoplay: false,- // duration: 0,- // update: function() { console.log('duration0 update');},- // begin: function() { console.log('duration0 began');},- // run: function() { console.log('duration0 runing');},- // complete: function() { console.log('duration0 completed');}- // });-- // var tl = anime.timeline({- // targets: '.color-08',- // easing: 'easeOutExpo',- // duration: 500,- // autoplay: true,- // // update: function(anim) { console.log('TL updating', anim.currentTime);},- // begin: function(anim) { console.log('TL began', anim.currentTime);},- // // run: function(anim) { console.log('TL runing', anim.currentTime);},- // complete: function(anim) { console.log('TL completed', anim.currentTime);}- // });-- // tl.add({- // translateY: [-100, 200],- // begin: function() {- // console.log('01 began');- // },- // complete: function() {- // console.log('01 completed');- // }- // }).add({- // translateY: 0,- // easing: 'easeOutElastic',- // begin: function() {- // console.log('02 began');- // },- // complete: function() {- // console.log('02 completed');- // }- // }).add({- // targets: '.color-12',- // translateY: [0, 100],- // easing: 'easeInElastic',- // begin: function() {- // console.log('03 began');- // },- // complete: function() {- // console.log('03 completed');- // },- // offset: 0- // }).add({- // translateY: 100,- // begin: function() {- // console.log('04 began');- // },- // complete: function() {- // console.log('04 completed');- // }- // }).add({- // translateY: 0,- // begin: function() {- // console.log('05 began');- // },- // complete: function() {- // console.log('05 completed');- // }- // });-- // var promise = tl.finished.then(function() {- // console.log('FINISHED');- // tl.restart();- // });-+ seek0.seek(0);</script>- <!-- <script src="../assets/js/stats.js"></script> --></body>-</html>+</html>\ No newline at end of file