react-animation-engine
Version:
Extract famo.us transitionable capabilities in 14kb for react. Mixin to transition between state values.
36 lines • 14.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.FamousAnimations=e():t.FamousAnimations=e()}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return t[i].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";var i=function(t){return t&&t.__esModule?t:{"default":t}};Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),u=i(r),o=n(2),s=i(o),a=n(3),c=i(a);e.TransitionableMixin=u["default"],e.Transitionable=s["default"],e.Easing=c["default"]},function(t,e,n){"use strict";function i(t){t=[].concat(t);var e={},n={componentWillUnmount:function(){t.forEach(function(t){delete e[t]})},componentWillMount:function(){var n=this;t.forEach(function(t){e[t]=new s["default"](n.state[t]);var i=t;Object.defineProperty(n,i,{get:function(){return e[i].get()},set:function(t){"object"!=typeof t&&(t={value:t});var e=t.value;delete t.value,t.curve||(t.curve=c["default"].inSine),this.tween(i,e,t)}});var r=e[i];r.update(n._syncProp.bind(n,i)),n._syncProp(i)})},_syncProp:function(t){var n=e[t],i=u({},t,n.get());this.setState(i)},tween:function(t,n,i,r){var u=e[t];u.val(n,i,r)},halt:function(n){if(n){var i=e[p];return void i.halt()}t.forEach(function(t){var n=e[t];n.halt()})}};return n}var r=function(t){return t&&t.__esModule?t:{"default":t}},u=function(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:null==e||"undefined"==typeof Symbol||e.constructor!==Symbol,configurable:!0,writable:!0})};Object.defineProperty(e,"__esModule",{value:!0});var o=n(2),s=r(o),a=n(3),c=r(a);e["default"]=i,t.exports=e["default"]},function(t,e,n){"use strict";function i(){return p.map(function(t){return t._isAnimating}).reduce(function(t,e){return t&&!e},!0)}function r(){for(var t in d)d[t]()}function u(){i()&&(cancelAnimationFrame(v),l=!1,v=null)}function o(){l&&(r(),v=requestAnimationFrame(o))}var s=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},a=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),c=function y(t,e,n){var i=Object.getOwnPropertyDescriptor(t,e);if(void 0===i){var r=Object.getPrototypeOf(t);return null===r?void 0:y(r,e,n)}if("value"in i)return i.value;var u=i.get;return void 0===u?void 0:u.call(n)},h=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(t.__proto__=e)},f=n(4),l=!1,v=null,p=[],d=[],_=function(t){function e(t){var n=this;s(this,e),c(Object.getPrototypeOf(e.prototype),"constructor",this).call(this,t),p.push(this),this._listenerFn=function(){return n._executeListeners()},d.push(this._listenerFn),this._isAnimating=!1}return h(e,t),a(e,[{key:"update",value:function(t){this._listeners=this._listeners||[],this._listeners.push(t)}},{key:"val",value:function(t,e,n){var i=this;i.set(t,e,function(){v&&(i._isAnimating=!1),u(),n&&n()}),i._isAnimating=!0,l=!0,o()}},{key:"_executeListeners",value:function(){var t=this;this._listeners&&this._listeners.forEach(function(e){return e(t.get())})}}]),e}(f);t.exports=_},function(t,e,n){/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @license MPL 2.0
* @copyright Famous Industries, Inc. 2015
*/
var i={inQuad:function(t){return t*t},outQuad:function(t){return-(t-=1)*t+1},inOutQuad:function(t){return(t/=.5)<1?.5*t*t:-.5*(--t*(t-2)-1)},inCubic:function(t){return t*t*t},outCubic:function(t){return--t*t*t+1},inOutCubic:function(t){return(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2)},inQuart:function(t){return t*t*t*t},outQuart:function(t){return-(--t*t*t*t-1)},inOutQuart:function(t){return(t/=.5)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)},inQuint:function(t){return t*t*t*t*t},outQuint:function(t){return--t*t*t*t*t+1},inOutQuint:function(t){return(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)},inSine:function(t){return-1*Math.cos(t*(Math.PI/2))+1},outSine:function(t){return Math.sin(t*(Math.PI/2))},inOutSine:function(t){return-.5*(Math.cos(Math.PI*t)-1)},inExpo:function(t){return 0===t?0:Math.pow(2,10*(t-1))},outExpo:function(t){return 1===t?1:-Math.pow(2,-10*t)+1},inOutExpo:function(t){return 0===t?0:1===t?1:(t/=.5)<1?.5*Math.pow(2,10*(t-1)):.5*(-Math.pow(2,-10*--t)+2)},inCirc:function(t){return-(Math.sqrt(1-t*t)-1)},outCirc:function(t){return Math.sqrt(1- --t*t)},inOutCirc:function(t){return(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)},inElastic:function(t){var e=1.70158,n=0,i=1;return 0===t?0:1===t?1:(n||(n=.3),e=n/(2*Math.PI)*Math.asin(1/i),-(i*Math.pow(2,10*(t-=1))*Math.sin(2*(t-e)*Math.PI/n)))},outElastic:function(t){var e=1.70158,n=0,i=1;return 0===t?0:1===t?1:(n||(n=.3),e=n/(2*Math.PI)*Math.asin(1/i),i*Math.pow(2,-10*t)*Math.sin(2*(t-e)*Math.PI/n)+1)},inOutElastic:function(t){var e=1.70158,n=0,i=1;return 0===t?0:2===(t/=.5)?1:(n||(n=.3*1.5),e=n/(2*Math.PI)*Math.asin(1/i),1>t?-.5*i*Math.pow(2,10*(t-=1))*Math.sin(2*(t-e)*Math.PI/n):i*Math.pow(2,-10*(t-=1))*Math.sin(2*(t-e)*Math.PI/n)*.5+1)},inBack:function(t,e){return void 0===e&&(e=1.70158),t*t*((e+1)*t-e)},outBack:function(t,e){return void 0===e&&(e=1.70158),--t*t*((e+1)*t+e)+1},inOutBack:function(t,e){return void 0===e&&(e=1.70158),(t/=.5)<1?.5*t*t*(((e*=1.525)+1)*t-e):.5*((t-=2)*t*(((e*=1.525)+1)*t+e)+2)},inBounce:function(t){return 1-i.outBounce(1-t)},outBounce:function(t){return 1/2.75>t?7.5625*t*t:2/2.75>t?7.5625*(t-=1.5/2.75)*t+.75:2.5/2.75>t?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},inOutBounce:function(t){return.5>t?.5*i.inBounce(2*t):.5*i.outBounce(2*t-1)+.5}};t.exports=i},function(t,e,n){function i(t){this.currentAction=null,this.actionQueue=[],this.callbackQueue=[],this.state=0,this.velocity=void 0,this._callback=void 0,this._engineInstance=null,this._currentMethod=null,this.set(t)}function r(){if(this._callback){var t=this._callback;this._callback=void 0,t()}if(this.actionQueue.length<=0)return void this.set(this.get());this.currentAction=this.actionQueue.shift(),this._callback=this.callbackQueue.shift();var e=null,n=this.currentAction[0],i=this.currentAction[1];i instanceof Object&&i.method?(e=i.method,"string"==typeof e&&(e=s[e])):e=o,this._currentMethod!==e&&(!(n instanceof Object)||e.SUPPORTS_MULTIPLE===!0||n.length<=e.SUPPORTS_MULTIPLE?this._engineInstance=new e:this._engineInstance=new u(e),this._currentMethod=e),this._engineInstance.reset(this.state,this.velocity),void 0!==this.velocity&&(i.velocity=this.velocity),this._engineInstance.set(n,i,r.bind(this))}/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @license MPL 2.0
* @copyright Famous Industries, Inc. 2015
*/
var u=n(5),o=n(6),s={};i.register=function(t){var e=!0;for(var n in t)i.registerMethod(n,t[n])||(e=!1);return e},i.registerMethod=function(t,e){return t in s?!1:(s[t]=e,!0)},i.unregisterMethod=function(t){return t in s?(delete s[t],!0):!1},i.prototype.set=function(t,e,n){if(!e)return this.reset(t),n&&n(),this;var i=[t,e];return this.actionQueue.push(i),this.callbackQueue.push(n),this.currentAction||r.call(this),this},i.prototype.reset=function(t,e){this._currentMethod=null,this._engineInstance=null,this._callback=void 0,this.state=t,this.velocity=e,this.currentAction=null,this.actionQueue=[],this.callbackQueue=[]},i.prototype.delay=function(t,e){var n;return n=this.actionQueue.length?this.actionQueue[this.actionQueue.length-1][0]:this.currentAction?this.currentAction[0]:this.get(),this.set(n,{duration:t,curve:function(){return 0}},e)},i.prototype.get=function(t){return this._engineInstance&&(this._engineInstance.getVelocity&&(this.velocity=this._engineInstance.getVelocity()),this.state=this._engineInstance.get(t)),this.state},i.prototype.isActive=function(){return!!this.currentAction},i.prototype.halt=function(){return this.set(this.get())},t.exports=i},function(t,e,n){function i(t){this.method=t,this._instances=[],this.state=[]}/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @license MPL 2.0
* @copyright Famous Industries, Inc. 2015
*/
var r=n(7);i.SUPPORTS_MULTIPLE=!0,i.prototype.get=function(){for(var t=0;t<this._instances.length;t++)this.state[t]=this._instances[t].get();return this.state},i.prototype.set=function(t,e,n){for(var i=r.after(t.length,n),u=0;u<t.length;u++)this._instances[u]||(this._instances[u]=new this.method),this._instances[u].set(t[u],e,i)},i.prototype.reset=function(t){for(var e=0;e<t.length;e++)this._instances[e]||(this._instances[e]=new this.method),this._instances[e].reset(t[e])},t.exports=i},function(t,e,n){/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @license MPL 2.0
* @copyright Famous Industries, Inc. 2015
*/
function i(t){this.options=Object.create(i.DEFAULT_OPTIONS),t&&this.setOptions(t),this._startTime=0,this._startValue=0,this._updateTime=0,this._endValue=0,this._curve=void 0,this._duration=0,this._active=!1,this._callback=void 0,this.state=0,this.velocity=void 0}function r(t,e,n){return(1-n)*t+n*e}function u(t){return t instanceof Object?t instanceof Array?t.slice(0):Object.create(t):t}function o(t,e){var n={curve:e.curve};return e.duration&&(n.duration=e.duration),e.speed&&(n.speed=e.speed),t instanceof Object&&(void 0!==t.duration&&(n.duration=t.duration),t.curve&&(n.curve=t.curve),t.speed&&(n.speed=t.speed)),"string"==typeof n.curve&&(n.curve=i.getCurve(n.curve)),n}function s(t,e,n,i,r){var u,o=1e-7,s=(n(r)-n(r-o))/o;if(t instanceof Array){u=[];for(var a=0;a<t.length;a++)"number"==typeof t[a]?u[a]=s*(t[a]-e[a])/i:u[a]=0}else u=s*(t-e)/i;return u}function a(t,e,n){var i;if(t instanceof Array){i=[];for(var u=0;u<t.length;u++)"number"==typeof t[u]?i[u]=r(t[u],e[u],n):i[u]=t[u]}else i=r(t,e,n);return i}i.Curves={linear:function(t){return t},easeIn:function(t){return t*t},easeOut:function(t){return t*(2-t)},easeInOut:function(t){return.5>=t?2*t*t:-2*t*t+4*t-1},easeOutBounce:function(t){return t*(3-2*t)},spring:function(t){return(1-t)*Math.sin(6*Math.PI*t)+t}},i.SUPPORTS_MULTIPLE=!0,i.DEFAULT_OPTIONS={curve:i.Curves.linear,duration:500,speed:0};var c={};i.registerCurve=function(t,e){return c[t]?!1:(c[t]=e,!0)},i.unregisterCurve=function(t){return c[t]?(delete c[t],!0):!1},i.getCurve=function(t){var e=c[t];if(void 0!==e)return e;throw new Error("curve not registered")},i.getCurves=function(){return c},i.prototype.setOptions=function(t){void 0!==t.curve&&(this.options.curve=t.curve),void 0!==t.duration&&(this.options.duration=t.duration),void 0!==t.speed&&(this.options.speed=t.speed)},i.prototype.set=function(t,e,n){if(!e)return this.reset(t),void(n&&n());if(this._startValue=u(this.get()),e=o(e,this.options),e.speed){var i=this._startValue;if(i instanceof Object){var r=0;for(var s in i)r+=(t[s]-i[s])*(t[s]-i[s]);e.duration=Math.sqrt(r)/e.speed}else e.duration=Math.abs(t-i)/e.speed}this._startTime=Date.now(),this._endValue=u(t),this._startVelocity=u(e.velocity),this._duration=e.duration,this._curve=e.curve,this._active=!0,this._callback=n},i.prototype.reset=function(t,e){if(this._callback){var n=this._callback;this._callback=void 0,n()}this.state=u(t),this.velocity=u(e),this._startTime=0,this._duration=0,this._updateTime=0,this._startValue=this.state,this._startVelocity=this.velocity,this._endValue=this.state,this._active=!1},i.prototype.getVelocity=function(){return this.velocity},i.prototype.get=function(t){return this.update(t),this.state},i.prototype.update=function(t){if(this._active){if(t||(t=Date.now()),!(this._updateTime>=t)){this._updateTime=t;var e=t-this._startTime;if(e>=this._duration)this.state=this._endValue,this.velocity=s(this.state,this._startValue,this._curve,this._duration,1),this._active=!1;else if(0>e)this.state=this._startValue,this.velocity=this._startVelocity;else{var n=e/this._duration;this.state=a(this._startValue,this._endValue,this._curve(n)),this.velocity=s(this.state,this._startValue,this._curve,this._duration,n)}}}else if(this._callback){var i=this._callback;this._callback=void 0,i()}},i.prototype.isActive=function(){return this._active},i.prototype.halt=function(){this.reset(this.get())},i.registerCurve("linear",i.Curves.linear),i.registerCurve("easeIn",i.Curves.easeIn),i.registerCurve("easeOut",i.Curves.easeOut),i.registerCurve("easeInOut",i.Curves.easeInOut),i.registerCurve("easeOutBounce",i.Curves.easeOutBounce),i.registerCurve("spring",i.Curves.spring),i.customCurve=function(t,e){return t=t||0,e=e||0,function(n){return t*n+(-2*t-e+3)*n*n+(t+e-2)*n*n*n}},t.exports=i},function(t,e,n){/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* @license MPL 2.0
* @copyright Famous Industries, Inc. 2015
*/
var i={};i.Direction={X:0,Y:1,Z:2},i.after=function(t,e){var n=t;return function(){n--,0===n&&e.apply(this,arguments)}},i.loadURL=function(t,e){var n=new XMLHttpRequest;n.onreadystatechange=function(){4===this.readyState&&e&&e(this.responseText)},n.open("GET",t),n.send()},i.createDocumentFragmentFromHTML=function(t){var e=document.createElement("div");e.innerHTML=t;for(var n=document.createDocumentFragment();e.hasChildNodes();)n.appendChild(e.firstChild);return n},i.clone=function(t){var e;if("object"==typeof t){e=t instanceof Array?[]:{};for(var n in t)if("object"==typeof t[n]&&null!==t[n])if(t[n]instanceof Array){e[n]=new Array(t[n].length);for(var r=0;r<t[n].length;r++)e[n][r]=i.clone(t[n][r])}else e[n]=i.clone(t[n]);else e[n]=t[n]}else e=t;return e},t.exports=i}])});