UNPKG

react-animation-engine

Version:

Extract famo.us transitionable capabilities in 14kb for react. Mixin to transition between state values.

120 lines 52.4 kB
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):"object"==typeof exports?exports.FamousAnimations=i():t.FamousAnimations=i()}(this,function(){return function(t){function i(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,i),o.loaded=!0,o.exports}var e={};return i.m=t,i.c=e,i.p="",i(0)}([function(t,i,e){"use strict";var n=function(t){return t&&t.__esModule?t:{"default":t}};Object.defineProperty(i,"__esModule",{value:!0});var o=e(1),s=n(o),r=e(2),a=n(r),c=e(3),u=n(c),h=e(4),p=e(5),l=e(6);a["default"].registerMethod("spring",h),a["default"].registerMethod("wall",p),a["default"].registerMethod("snap",l),i.TransitionableMixin=s["default"],i.Transitionable=a["default"],i.Easing=u["default"]},function(t,i,e){"use strict";function n(t){t=[].concat(t);var i={},e={componentWillUnmount:function(){t.forEach(function(t){delete i[t]})},componentWillMount:function(){var e=this;t.forEach(function(t){i[t]=new a["default"](e.state[t]);var n=t;Object.defineProperty(e,n,{get:function(){return i[n].get()},set:function(t){"object"!=typeof t&&(t={value:t});var i=t.value;delete t.value,t.curve||(t.curve=u["default"].inSine),this.tween(n,i,t)}});var o=i[n];o.update(e._syncProp.bind(e,n)),e._syncProp(n)})},_syncProp:function(t){var e=i[t],n=s({},t,e.get());this.setState(n)},tween:function(t,e,n,o){var s=i[t];s.val(e,n,o)},halt:function(e){if(e){var n=i[p];return void n.halt()}t.forEach(function(t){var e=i[t];e.halt()})}};return e}var o=function(t){return t&&t.__esModule?t:{"default":t}},s=function(t,i,e){return Object.defineProperty(t,i,{value:e,enumerable:null==i||"undefined"==typeof Symbol||i.constructor!==Symbol,configurable:!0,writable:!0})};Object.defineProperty(i,"__esModule",{value:!0});var r=e(2),a=o(r),c=e(3),u=o(c);i["default"]=n,t.exports=i["default"]},function(t,i,e){"use strict";function n(){return d.map(function(t){return t._isAnimating}).reduce(function(t,i){return t&&!i},!0)}function o(){for(var t in v)v[t]()}function s(){n()&&(cancelAnimationFrame(f),l=!1,f=null)}function r(){l&&(o(),f=requestAnimationFrame(r))}var a=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},c=function(){function t(t,i){for(var e=0;e<i.length;e++){var n=i[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(i,e,n){return e&&t(i.prototype,e),n&&t(i,n),i}}(),u=function g(t,i,e){var n=Object.getOwnPropertyDescriptor(t,i);if(void 0===n){var o=Object.getPrototypeOf(t);return null===o?void 0:g(o,i,e)}if("value"in n)return n.value;var s=n.get;return void 0===s?void 0:s.call(e)},h=function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Super expression must either be null or a function, not "+typeof i);t.prototype=Object.create(i&&i.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),i&&(t.__proto__=i)},p=e(7),l=!1,f=null,d=[],v=[],y=function(t){function i(t){var e=this;a(this,i),u(Object.getPrototypeOf(i.prototype),"constructor",this).call(this,t),d.push(this),this._listenerFn=function(){return e._executeListeners()},v.push(this._listenerFn),this._isAnimating=!1}return h(i,t),c(i,[{key:"update",value:function(t){this._listeners=this._listeners||[],this._listeners.push(t)}},{key:"val",value:function(t,i,e){var o=this;o.set(t,i,function(){f&&(o._isAnimating=!1),s(),e&&e()}),l=!0,n()&&r(),o._isAnimating=!0}},{key:"_executeListeners",value:function(){var t=this;this._listeners&&this._listeners.forEach(function(i){return i(t.get())})}}]),i}(p);t.exports=y},function(t,i,e){/* 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 n={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 i=1.70158,e=0,n=1;return 0===t?0:1===t?1:(e||(e=.3),i=e/(2*Math.PI)*Math.asin(1/n),-(n*Math.pow(2,10*(t-=1))*Math.sin(2*(t-i)*Math.PI/e)))},outElastic:function(t){var i=1.70158,e=0,n=1;return 0===t?0:1===t?1:(e||(e=.3),i=e/(2*Math.PI)*Math.asin(1/n),n*Math.pow(2,-10*t)*Math.sin(2*(t-i)*Math.PI/e)+1)},inOutElastic:function(t){var i=1.70158,e=0,n=1;return 0===t?0:2===(t/=.5)?1:(e||(e=.3*1.5),i=e/(2*Math.PI)*Math.asin(1/n),1>t?-.5*n*Math.pow(2,10*(t-=1))*Math.sin(2*(t-i)*Math.PI/e):n*Math.pow(2,-10*(t-=1))*Math.sin(2*(t-i)*Math.PI/e)*.5+1)},inBack:function(t,i){return void 0===i&&(i=1.70158),t*t*((i+1)*t-i)},outBack:function(t,i){return void 0===i&&(i=1.70158),--t*t*((i+1)*t+i)+1},inOutBack:function(t,i){return void 0===i&&(i=1.70158),(t/=.5)<1?.5*t*t*(((i*=1.525)+1)*t-i):.5*((t-=2)*t*(((i*=1.525)+1)*t+i)+2)},inBounce:function(t){return 1-n.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*n.inBounce(2*t):.5*n.outBounce(2*t-1)+.5}};t.exports=n},function(t,i,e){function n(t){t=t||0,this.endState=new m(t),this.initState=new m,this._dimensions=void 0,this._restTolerance=1e-10,this._absRestTolerance=this._restTolerance,this._callback=void 0,this.PE=new y,this.spring=new _({anchor:this.endState}),this.particle=new g,this.PE.addBody(this.particle),this.PE.attach(this.spring,this.particle)}function o(){return this.particle.getEnergy()+this.spring.getEnergy([this.particle])}function s(t){this.particle.setPosition(t)}function r(t){this.particle.setVelocity(t)}function a(){return 0===this._dimensions?this.particle.getPosition1D():this.particle.getPosition()}function c(){return 0===this._dimensions?this.particle.getVelocity1D():this.particle.getVelocity()}function u(t){this._callback=t}function h(){this.PE.wake()}function p(){this.PE.sleep()}function l(){if(this.PE.isSleeping()){if(this._callback){var t=this._callback;this._callback=void 0,t()}}else o.call(this)<this._absRestTolerance&&(s.call(this,this.endState),r.call(this,[0,0,0]),p.call(this))}function f(t){var i=n.DEFAULT_OPTIONS;void 0===t.period&&(t.period=i.period),void 0===t.dampingRatio&&(t.dampingRatio=i.dampingRatio),void 0===t.velocity&&(t.velocity=i.velocity),t.period<150&&(t.period=150,console.warn("The period of a SpringTransition is capped at 150 ms. Use a SnapTransition for faster transitions")),this.spring.setOptions({period:t.period,dampingRatio:t.dampingRatio}),r.call(this,t.velocity)}function d(){var t=this.endState.sub(this.initState).normSquared();this._absRestTolerance=0===t?this._restTolerance:this._restTolerance*t}function v(t){this.endState.set(t),d.call(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 y=e(8),g=e(9),_=e(10),m=e(11);n.SUPPORTS_MULTIPLE=3,n.DEFAULT_OPTIONS={period:300,dampingRatio:.5,velocity:0},n.prototype.reset=function(t,i){this._dimensions=t instanceof Array?t.length:0,this.initState.set(t),s.call(this,t),v.call(this,t),i&&r.call(this,i),u.call(this,void 0)},n.prototype.getVelocity=function(){return c.call(this)},n.prototype.setVelocity=function(t){this.call(this,r(t))},n.prototype.isActive=function(){return!this.PE.isSleeping()},n.prototype.halt=function(){this.set(this.get())},n.prototype.get=function(){return l.call(this),a.call(this)},n.prototype.set=function(t,i,e){return i?(this._dimensions=t instanceof Array?t.length:0,h.call(this),f.call(this,i),v.call(this,t),void u.call(this,e)):(this.reset(t),void(e&&e()))},t.exports=n},function(t,i,e){function n(t){t=t||0,this.endState=new O(t),this.initState=new O,this.spring=new _({anchor:this.endState}),this.wall=new m,this._restTolerance=1e-10,this._dimensions=1,this._absRestTolerance=this._restTolerance,this._callback=void 0,this.PE=new y,this.particle=new g,this.PE.addBody(this.particle),this.PE.attach([this.wall,this.spring],this.particle)}function o(){return this.particle.getEnergy()+this.spring.getEnergy([this.particle])}function s(){var t=this.endState.sub(this.initState).normSquared();this._absRestTolerance=0===t?this._restTolerance:this._restTolerance*t}function r(){this.PE.wake()}function a(){this.PE.sleep()}function c(t){this.endState.set(t);var i=this.endState.sub(this.initState).norm();this.wall.setOptions({distance:this.endState.norm(),normal:0===i?this.particle.velocity.normalize(-1):this.endState.sub(this.initState).normalize(-1)}),s.call(this)}function u(t){this.particle.position.set(t)}function h(t){this.particle.velocity.set(t)}function p(){return 0===this._dimensions?this.particle.getPosition1D():this.particle.getPosition()}function l(){return 0===this._dimensions?this.particle.getVelocity1D():this.particle.getVelocity()}function f(t){this._callback=t}function d(){if(this.PE.isSleeping()){if(this._callback){var t=this._callback;this._callback=void 0,t()}}else{var i=o.call(this);i<this._absRestTolerance&&(a.call(this),u.call(this,this.endState),h.call(this,[0,0,0]))}}function v(t){var i=n.DEFAULT_OPTIONS;void 0===t.period&&(t.period=i.period),void 0===t.dampingRatio&&(t.dampingRatio=i.dampingRatio),void 0===t.velocity&&(t.velocity=i.velocity),void 0===t.restitution&&(t.restitution=i.restitution),void 0===t.drift&&(t.drift=m.DEFAULT_OPTIONS.drift),void 0===t.slop&&(t.slop=m.DEFAULT_OPTIONS.slop),this.spring.setOptions({period:t.period,dampingRatio:t.dampingRatio}),this.wall.setOptions({restitution:t.restitution,drift:t.drift,slop:t.slop}),h.call(this,t.velocity)}/* 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 y=e(8),g=e(9),_=e(10),m=e(12),O=e(11);n.SUPPORTS_MULTIPLE=3,n.DEFAULT_OPTIONS={period:300,dampingRatio:.5,velocity:0,restitution:.5},n.prototype.reset=function(t,i){this._dimensions=t instanceof Array?t.length:0,this.initState.set(t),u.call(this,t),i&&h.call(this,i),c.call(this,t),f.call(this,void 0)},n.prototype.getVelocity=function(){return l.call(this)},n.prototype.setVelocity=function(t){this.call(this,h(t))},n.prototype.isActive=function(){return!this.PE.isSleeping()},n.prototype.halt=function(){this.set(this.get())},n.prototype.get=function(){return d.call(this),p.call(this)},n.prototype.set=function(t,i,e){return i?(this._dimensions=t instanceof Array?t.length:0,r.call(this),v.call(this,i),c.call(this,t),void f.call(this,e)):(this.reset(t),void(e&&e()))},t.exports=n},function(t,i,e){function n(t){t=t||0,this.endState=new m(t),this.initState=new m,this._dimensions=1,this._restTolerance=1e-10,this._absRestTolerance=this._restTolerance,this._callback=void 0,this.PE=new y,this.particle=new g,this.spring=new _({anchor:this.endState}),this.PE.addBody(this.particle),this.PE.attach(this.spring,this.particle)}function o(){return this.particle.getEnergy()+this.spring.getEnergy([this.particle])}function s(){var t=this.endState.sub(this.initState).normSquared();this._absRestTolerance=0===t?this._restTolerance:this._restTolerance*t}function r(t){this.endState.set(t),s.call(this)}function a(){this.PE.wake()}function c(){this.PE.sleep()}function u(t){this.particle.position.set(t)}function h(t){this.particle.velocity.set(t)}function p(){return 0===this._dimensions?this.particle.getPosition1D():this.particle.getPosition()}function l(){return 0===this._dimensions?this.particle.getVelocity1D():this.particle.getVelocity()}function f(t){this._callback=t}function d(t){var i=n.DEFAULT_OPTIONS;void 0===t.period&&(t.period=i.period),void 0===t.dampingRatio&&(t.dampingRatio=i.dampingRatio),void 0===t.velocity&&(t.velocity=i.velocity),this.spring.setOptions({period:t.period,dampingRatio:t.dampingRatio}),h.call(this,t.velocity)}function v(){if(this.PE.isSleeping()){if(this._callback){var t=this._callback;this._callback=void 0,t()}}else o.call(this)<this._absRestTolerance&&(u.call(this,this.endState),h.call(this,[0,0,0]),c.call(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 y=e(8),g=e(9),_=e(13),m=e(11);n.SUPPORTS_MULTIPLE=3,n.DEFAULT_OPTIONS={period:100,dampingRatio:.2,velocity:0},n.prototype.reset=function(t,i){this._dimensions=t instanceof Array?t.length:0,this.initState.set(t),u.call(this,t),r.call(this,t),i&&h.call(this,i),f.call(this,void 0)},n.prototype.getVelocity=function(){return l.call(this)},n.prototype.setVelocity=function(t){this.call(this,h(t))},n.prototype.isActive=function(){return!this.PE.isSleeping()},n.prototype.halt=function(){this.set(this.get())},n.prototype.get=function(){return v.call(this),p.call(this)},n.prototype.set=function(t,i,e){return i?(this._dimensions=t instanceof Array?t.length:0,a.call(this),d.call(this,i),r.call(this,t),void f.call(this,e)):(this.reset(t),void(e&&e()))},t.exports=n},function(t,i,e){function n(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 o(){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 i=null,e=this.currentAction[0],n=this.currentAction[1];n instanceof Object&&n.method?(i=n.method,"string"==typeof i&&(i=a[i])):i=r,this._currentMethod!==i&&(!(e instanceof Object)||i.SUPPORTS_MULTIPLE===!0||e.length<=i.SUPPORTS_MULTIPLE?this._engineInstance=new i:this._engineInstance=new s(i),this._currentMethod=i),this._engineInstance.reset(this.state,this.velocity),void 0!==this.velocity&&(n.velocity=this.velocity),this._engineInstance.set(e,n,o.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 s=e(14),r=e(15),a={};n.register=function(t){var i=!0;for(var e in t)n.registerMethod(e,t[e])||(i=!1);return i},n.registerMethod=function(t,i){return t in a?!1:(a[t]=i,!0)},n.unregisterMethod=function(t){return t in a?(delete a[t],!0):!1},n.prototype.set=function(t,i,e){if(!i)return this.reset(t),e&&e(),this;var n=[t,i];return this.actionQueue.push(n),this.callbackQueue.push(e),this.currentAction||o.call(this),this},n.prototype.reset=function(t,i){this._currentMethod=null,this._engineInstance=null,this._callback=void 0,this.state=t,this.velocity=i,this.currentAction=null,this.actionQueue=[],this.callbackQueue=[]},n.prototype.delay=function(t,i){var e;return e=this.actionQueue.length?this.actionQueue[this.actionQueue.length-1][0]:this.currentAction?this.currentAction[0]:this.get(),this.set(e,{duration:t,curve:function(){return 0}},i)},n.prototype.get=function(t){return this._engineInstance&&(this._engineInstance.getVelocity&&(this.velocity=this._engineInstance.getVelocity()),this.state=this._engineInstance.get(t)),this.state},n.prototype.isActive=function(){return!!this.currentAction},n.prototype.halt=function(){return this.set(this.get())},t.exports=n},function(t,i,e){function n(t){this.options=Object.create(n.DEFAULT_OPTIONS),t&&this.setOptions(t),this._particles=[],this._bodies=[],this._agentData={},this._forces=[],this._constraints=[],this._buffer=0,this._prevTime=M(),this._isSleeping=!1,this._eventHandler=null,this._currAgentId=0,this._hasBodies=!1,this._eventHandler=null}function o(t){return t.applyForce?this._forces:t.applyConstraint?this._constraints:void 0}function s(t,i,e){return void 0===i&&(i=this.getParticlesAndBodies()),i instanceof Array||(i=[i]),t.on("change",this.wake.bind(this)),this._agentData[this._currAgentId]={agent:t,id:this._currAgentId,targets:i,source:e},o.call(this,t).push(this._currAgentId),this._currAgentId++}function r(t){return this._agentData[t]}function a(t){var i=r.call(this,this._forces[t]);i.agent.applyForce(i.targets,i.source)}function c(){for(var t=this._forces.length-1;t>-1;t--)a.call(this,t)}function u(t,i){var e=this._agentData[this._constraints[t]];return e.agent.applyConstraint(e.targets,e.source,i)}function h(t){for(var i=0;i<this.options.constraintSteps;){for(var e=this._constraints.length-1;e>-1;e--)u.call(this,e,t);i++}}function p(t,i){t.integrateVelocity(i),this.options.velocityCap&&t.velocity.cap(this.options.velocityCap).put(t.velocity)}function l(t,i){t.integrateAngularMomentum(i),t.updateAngularVelocity(),this.options.angularVelocityCap&&t.angularVelocity.cap(this.options.angularVelocityCap).put(t.angularVelocity)}function f(t,i){t.integrateOrientation(i)}function d(t,i){t.integratePosition(i),t.emit(P.update,t)}function v(t){c.call(this,t),this.forEach(p,t),this.forEachBody(l,t),h.call(this,t),this.forEachBody(f,t),this.forEach(d,t)}function y(){var t=0,i=0;return this.forEach(function(e){i=e.getEnergy(),t+=i}),t}function g(){var t=0;for(var i in this._agentData)t+=this.getAgentEnergy(i);return t}/* 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 _=e(16),m=17,O=1e3/120,b=17,M=Date.now,P={start:"start",update:"update",end:"end"};n.DEFAULT_OPTIONS={constraintSteps:1,sleepTolerance:1e-7,velocityCap:void 0,angularVelocityCap:void 0},n.prototype.setOptions=function(t){for(var i in t)this.options[i]&&(this.options[i]=t[i])},n.prototype.addBody=function(t){return t._engine=this,t.isBody?(this._bodies.push(t),this._hasBodies=!0):this._particles.push(t),t.on("start",this.wake.bind(this)),t},n.prototype.removeBody=function(t){var i=t.isBody?this._bodies:this._particles,e=i.indexOf(t);if(e>-1){for(var n in this._agentData)this._agentData.hasOwnProperty(n)&&this.detachFrom(this._agentData[n].id,t);i.splice(e,1)}0===this.getBodies().length&&(this._hasBodies=!1)},n.prototype.attach=function(t,i,e){if(this.wake(),t instanceof Array){for(var n=[],o=0;o<t.length;o++)n[o]=s.call(this,t[o],i,e);return n}return s.call(this,t,i,e)},n.prototype.attachTo=function(t,i){r.call(this,t).targets.push(i)},n.prototype.detach=function(t){var i=this.getAgent(t),e=o.call(this,i),n=e.indexOf(t);e.splice(n,1),delete this._agentData[t]},n.prototype.detachFrom=function(t,i){var e=r.call(this,t);if(e.source===i)this.detach(t);else{var n=e.targets,o=n.indexOf(i);o>-1&&n.splice(o,1)}},n.prototype.detachAll=function(){this._agentData={},this._forces=[],this._constraints=[],this._currAgentId=0},n.prototype.getAgent=function(t){return r.call(this,t).agent},n.prototype.getParticles=function(){return this._particles},n.prototype.getBodies=function(){return this._bodies},n.prototype.getParticlesAndBodies=function(){return this.getParticles().concat(this.getBodies())},n.prototype.forEachParticle=function(t,i){for(var e=this.getParticles(),n=0,o=e.length;o>n;n++)t.call(this,e[n],i)},n.prototype.forEachBody=function(t,i){if(this._hasBodies)for(var e=this.getBodies(),n=0,o=e.length;o>n;n++)t.call(this,e[n],i)},n.prototype.forEach=function(t,i){this.forEachParticle(t,i),this.forEachBody(t,i)},n.prototype.getAgentEnergy=function(t){var i=r.call(this,t);return i.agent.getEnergy(i.targets,i.source)},n.prototype.getEnergy=function(){return y.call(this)+g.call(this)},n.prototype.step=function(){if(!this.isSleeping()){var t=M(),i=t-this._prevTime;this._prevTime=t,O>i||(i>b&&(i=b),v.call(this,m),this.emit(P.update,this),this.getEnergy()<this.options.sleepTolerance&&this.sleep())}},n.prototype.isSleeping=function(){return this._isSleeping},n.prototype.isActive=function(){return!this._isSleeping},n.prototype.sleep=function(){this._isSleeping||(this.forEach(function(t){t.sleep()}),this.emit(P.end,this),this._isSleeping=!0)},n.prototype.wake=function(){this._isSleeping&&(this._prevTime=M(),this.emit(P.start,this),this._isSleeping=!1)},n.prototype.emit=function(t,i){null!==this._eventHandler&&this._eventHandler.emit(t,i)},n.prototype.on=function(t,i){null===this._eventHandler&&(this._eventHandler=new _),this._eventHandler.on(t,i)},t.exports=n},function(t,i,e){function n(t){t=t||{};var i=n.DEFAULT_OPTIONS;this.position=new s,this.velocity=new s,this.force=new s,this._engine=null,this._isSleeping=!0,this._eventOutput=null,this.mass=void 0!==t.mass?t.mass:i.mass,this.inverseMass=1/this.mass,this.setPosition(t.position||i.position),this.setVelocity(t.velocity||i.velocity),this.force.set(t.force||[0,0,0]),this.transform=r.identity.slice(),this._spec={size:[!0,!0],target:{transform:this.transform,origin:[.5,.5],target:null}}}function o(){this._eventOutput=new a,this._eventOutput.bindThis(this),a.setOutputHandler(this,this._eventOutput)}/* 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 s=e(11),r=e(17),a=e(16),c=e(18);n.DEFAULT_OPTIONS={position:[0,0,0],velocity:[0,0,0],mass:1};var u={start:"start",update:"update",end:"end"},h=Date.now;n.prototype.isBody=!1,n.prototype.isActive=function(){return!this._isSleeping},n.prototype.sleep=function(){this._isSleeping||(this.emit(u.end,this),this._isSleeping=!0)},n.prototype.wake=function(){this._isSleeping&&(this.emit(u.start,this),this._isSleeping=!1,this._prevTime=h(),this._engine&&this._engine.wake())},n.prototype.setPosition=function(t){this.position.set(t)},n.prototype.setPosition1D=function(t){this.position.x=t},n.prototype.getPosition=function(){return this._engine.step(),this.position.get()},n.prototype.getPosition1D=function(){return this._engine.step(),this.position.x},n.prototype.setVelocity=function(t){this.velocity.set(t),(0!==t[0]||0!==t[1]||0!==t[2])&&this.wake()},n.prototype.setVelocity1D=function(t){this.velocity.x=t,0!==t&&this.wake()},n.prototype.getVelocity=function(){return this.velocity.get()},n.prototype.setForce=function(t){this.force.set(t),this.wake()},n.prototype.getVelocity1D=function(){return this.velocity.x},n.prototype.setMass=function(t){this.mass=t,this.inverseMass=1/t},n.prototype.getMass=function(){return this.mass},n.prototype.reset=function(t,i){this.setPosition(t||[0,0,0]),this.setVelocity(i||[0,0,0])},n.prototype.applyForce=function(t){t.isZero()||(this.force.add(t).put(this.force),this.wake())},n.prototype.applyImpulse=function(t){if(!t.isZero()){var i=this.velocity;i.add(t.mult(this.inverseMass)).put(i)}},n.prototype.integrateVelocity=function(t){c.integrateVelocity(this,t)},n.prototype.integratePosition=function(t){c.integratePosition(this,t)},n.prototype._integrate=function(t){this.integrateVelocity(t),this.integratePosition(t)},n.prototype.getEnergy=function(){return.5*this.mass*this.velocity.normSquared()},n.prototype.getTransform=function(){this._engine.step();var t=this.position,i=this.transform;return i[12]=t.x,i[13]=t.y,i[14]=t.z,i},n.prototype.modify=function(t){var i=this._spec.target;return i.transform=this.getTransform(),i.target=t,this._spec},n.prototype.emit=function(t,i){this._eventOutput&&this._eventOutput.emit(t,i)},n.prototype.on=function(){return o.call(this),this.on.apply(this,arguments)},n.prototype.removeListener=function(){return o.call(this),this.removeListener.apply(this,arguments)},n.prototype.pipe=function(){return o.call(this),this.pipe.apply(this,arguments)},n.prototype.unpipe=function(){return o.call(this),this.unpipe.apply(this,arguments)},t.exports=n},function(t,i,e){function n(t){a.call(this),this.options=Object.create(this.constructor.DEFAULT_OPTIONS),t&&this.setOptions(t),this.disp=new c(0,0,0),r.call(this)}function o(){var t=this.options;t.stiffness=Math.pow(2*u/t.period,2)}function s(){var t=this.options;t.damping=4*u*t.dampingRatio/t.period}function r(){o.call(this),s.call(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 a=e(19),c=e(11);n.prototype=Object.create(a.prototype),n.prototype.constructor=n;var u=Math.PI,h=150;n.FORCE_FUNCTIONS={FENE:function(t,i){var e=.99*i,n=Math.max(Math.min(t,e),-e);return n/(1-n*n/(i*i))},HOOK:function(t){return t}},n.DEFAULT_OPTIONS={period:300,dampingRatio:.1,length:0,maxLength:1/0,anchor:void 0,forceFunction:n.FORCE_FUNCTIONS.HOOK},n.prototype.setOptions=function(t){void 0!==t.anchor&&(t.anchor.position instanceof c&&(this.options.anchor=t.anchor.position),t.anchor instanceof c&&(this.options.anchor=t.anchor),t.anchor instanceof Array&&(this.options.anchor=new c(t.anchor))),void 0!==t.period&&(t.period<h&&(t.period=h,console.warn("The period of a SpringTransition is capped at "+h+" ms. Use a SnapTransition for faster transitions")),this.options.period=t.period),void 0!==t.dampingRatio&&(this.options.dampingRatio=t.dampingRatio),void 0!==t.length&&(this.options.length=t.length),void 0!==t.forceFunction&&(this.options.forceFunction=t.forceFunction),void 0!==t.maxLength&&(this.options.maxLength=t.maxLength),r.call(this),a.prototype.setOptions.call(this,t)},n.prototype.applyForce=function(t,i){var e,n,o,s,r,a,c=this.force,u=this.disp,h=this.options,p=h.stiffness,l=h.damping,f=h.length,d=h.maxLength,v=h.anchor||i.position,y=h.forceFunction;for(e=0;e<t.length;e++){if(n=t[e],o=n.position,s=n.velocity,v.sub(o).put(u),r=u.norm()-f,0===r)return;a=n.mass,p*=a,l*=a,u.normalize(p*y(r,d)).put(c),l&&(i?c.add(s.sub(i.velocity).mult(-l)).put(c):c.add(s.mult(-l)).put(c)),n.applyForce(c),i&&i.applyForce(c.mult(-1))}},n.prototype.getEnergy=function(t,i){for(var e=this.options,n=e.length,o=i?i.position:e.anchor,s=e.stiffness,r=0,a=0;a<t.length;a++){var c=t[a],u=o.sub(c.position).norm()-n;r+=.5*s*u*u}return r},t.exports=n},function(t,i,e){/* 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 n(t,i,e){return 1===arguments.length&&void 0!==t?this.set(t):(this.x=t||0,this.y=i||0,this.z=e||0),this}function o(t,i,e){return this.x=t,this.y=i,this.z=e,this}function s(t){return o.call(this,t[0],t[1],t[2]||0)}function r(t){return o.call(this,t.x,t.y,t.z)}function a(t){return o.call(this,t,0,0)}var c=new n(0,0,0);n.prototype.add=function(t){return o.call(c,this.x+t.x,this.y+t.y,this.z+t.z)},n.prototype.sub=function(t){return o.call(c,this.x-t.x,this.y-t.y,this.z-t.z)},n.prototype.mult=function(t){return o.call(c,t*this.x,t*this.y,t*this.z)},n.prototype.div=function(t){return this.mult(1/t)},n.prototype.cross=function(t){var i=this.x,e=this.y,n=this.z,s=t.x,r=t.y,a=t.z;return o.call(c,n*r-e*a,i*a-n*s,e*s-i*r)},n.prototype.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},n.prototype.rotateX=function(t){var i=this.x,e=this.y,n=this.z,s=Math.cos(t),r=Math.sin(t);return o.call(c,i,e*s-n*r,e*r+n*s)},n.prototype.rotateY=function(t){var i=this.x,e=this.y,n=this.z,s=Math.cos(t),r=Math.sin(t);return o.call(c,n*r+i*s,e,n*s-i*r)},n.prototype.rotateZ=function(t){var i=this.x,e=this.y,n=this.z,s=Math.cos(t),r=Math.sin(t);return o.call(c,i*s-e*r,i*r+e*s,n)},n.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},n.prototype.normSquared=function(){return this.dot(this)},n.prototype.norm=function(){return Math.sqrt(this.normSquared())},n.prototype.normalize=function(t){0===arguments.length&&(t=1);var i=this.norm();return i>1e-7?r.call(c,this.mult(t/i)):o.call(c,t,0,0)},n.prototype.clone=function(){return new n(this)},n.prototype.isZero=function(){return!(this.x||this.y||this.z)},n.prototype.set=function(t){return t instanceof Array?s.call(this,t):"number"==typeof t?a.call(this,t):r.call(this,t)},n.prototype.setXYZ=function(t,i,e){return o.apply(this,arguments)},n.prototype.set1D=function(t){return a.call(this,t)},n.prototype.put=function(t){this===c?r.call(t,c):r.call(t,this)},n.prototype.clear=function(){return o.call(this,0,0,0)},n.prototype.cap=function u(u){if(u===1/0)return r.call(c,this);var t=this.norm();return t>u?r.call(c,this.mult(u/t)):r.call(c,this)},n.prototype.project=function(t){return t.mult(this.dot(t))},n.prototype.reflectAcross=function(t){return t.normalize().put(t),r(c,this.sub(this.project(t).mult(2)))},n.prototype.get=function(){return[this.x,this.y,this.z]},n.prototype.get1D=function(){return this.x},t.exports=n},function(t,i,e){function n(t){this.options=Object.create(n.DEFAULT_OPTIONS),t&&this.setOptions(t),this.diff=new u,this.impulse=new u,c.call(this)}function o(t,i){return i.dot(t)}function s(t){var i=this.options.normal,e=this.options.distance;return t.dot(i)+e}function r(t,i,e){var o=t.position,s=t.velocity,r=t.mass,a=this.options.normal,c=this.options.onContact,u=this.options.restitution,h=this.impulse,p=this.options.drift,l=-this.options.slop,f=0;if(this._eventOutput){var d={particle:t,wall:this,overlap:i,normal:a};this._eventOutput.emit("preCollision",d),this._eventOutput.emit("collision",d)}switch(c){case n.ON_CONTACT.REFLECT:var v=l>i?-((1+u)*a.dot(s)+p/e*(i-l))/(r*e+f):-((1+u)*a.dot(s))/(r*e+f);h.set(a.mult(e*v)),t.applyImpulse(h),t.setPosition(o.add(a.mult(-i)))}this._eventOutput&&this._eventOutput.emit("postCollision",d)}function a(t,i,e){var o=this.options.onContact,s=t.position,r=this.options.normal;o===n.ON_CONTACT.REFLECT&&t.setPosition(s.add(r.mult(-i)))}/* 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 c=e(20),u=e(11);n.prototype=Object.create(c.prototype),n.prototype.constructor=n,n.ON_CONTACT={REFLECT:0,SILENT:1},n.DEFAULT_OPTIONS={restitution:.5,drift:.5,slop:0,normal:[1,0,0],distance:0,onContact:n.ON_CONTACT.REFLECT},n.prototype.setOptions=function(t){void 0!==t.normal&&(t.normal instanceof u&&(this.options.normal=t.normal.clone()),t.normal instanceof Array&&(this.options.normal=new u(t.normal))),void 0!==t.restitution&&(this.options.restitution=t.restitution),void 0!==t.drift&&(this.options.drift=t.drift),void 0!==t.slop&&(this.options.slop=t.slop),void 0!==t.distance&&(this.options.distance=t.distance),void 0!==t.onContact&&(this.options.onContact=t.onContact)},n.prototype.applyConstraint=function(t,i,e){for(var n=this.options.normal,c=0;c<t.length;c++){var u=t[c],h=u.position,p=u.velocity,l=u.radius||0,f=s.call(this,h.add(n.mult(-l))),d=o.call(this,n,p);0>=f&&(0>d?r.call(this,u,f,e):a.call(this,u,f,e))}},t.exports=n},function(t,i,e){function n(t){o.call(this),this.options=Object.create(this.constructor.DEFAULT_OPTIONS),t&&this.setOptions(t),this.pDiff=new s,this.vDiff=new s,this.impulse1=new s,this.impulse2=new s}/* 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 o=e(20),s=e(11);n.prototype=Object.create(o.prototype),n.prototype.constructor=n,n.DEFAULT_OPTIONS={period:300,dampingRatio:.1,length:0,anchor:void 0};var r=Math.PI;n.prototype.setOptions=function(t){void 0!==t.anchor&&(t.anchor instanceof s&&(this.options.anchor=t.anchor),t.anchor.position instanceof s&&(this.options.anchor=t.anchor.position),t.anchor instanceof Array&&(this.options.anchor=new s(t.anchor))),void 0!==t.length&&(this.options.length=t.length),void 0!==t.dampingRatio&&(this.options.dampingRatio=t.dampingRatio),void 0!==t.period&&(this.options.period=t.period),o.prototype.setOptions.call(this,t)},n.prototype.getEnergy=function(t,i){for(var e=this.options,n=e.length,o=e.anchor||i.position,s=Math.pow(2*r/e.period,2),a=0,c=0;c<t.length;c++){var u=t[c],h=o.sub(u.position).norm()-n;a+=.5*s*h*h}return a},n.prototype.applyConstraint=function(t,i,e){for(var n=this.options,o=this.pDiff,s=this.vDiff,a=this.impulse1,c=this.impulse2,u=n.length,h=n.anchor||i.position,p=n.period,l=n.dampingRatio,f=0;f<t.length;f++){var d=t[f],v=d.position,y=d.velocity,g=d.mass,_=d.inverseMass;o.set(v.sub(h));var m,O=o.norm()-u;if(i){var b=i.inverseMass,M=i.velocity;s.set(y.sub(M)),m=1/(_+b)}else s.set(y),m=g;var P,T;if(0===this.options.period)P=0,T=1;else{var w=4*m*r*r/(p*p),S=4*m*r*l/p;T=e*w/(S+e*w),P=1/(S+e*w)}var E=T/e*O;o.normalize(-E).sub(s).mult(e/(P+e/m)).put(a),d.applyImpulse(a),i&&(a.mult(-1).put(c),i.applyImpulse(c))}},t.exports=n},function(t,i,e){function n(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 o=e(21);n.SUPPORTS_MULTIPLE=!0,n.prototype.get=function(){for(var t=0;t<this._instances.length;t++)this.state[t]=this._instances[t].get();return this.state},n.prototype.set=function(t,i,e){for(var n=o.after(t.length,e),s=0;s<t.length;s++)this._instances[s]||(this._instances[s]=new this.method),this._instances[s].set(t[s],i,n)},n.prototype.reset=function(t){for(var i=0;i<t.length;i++)this._instances[i]||(this._instances[i]=new this.method),this._instances[i].reset(t[i])},t.exports=n},function(t,i,e){/* 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 n(t){this.options=Object.create(n.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 o(t,i,e){return(1-e)*t+e*i}function s(t){return t instanceof Object?t instanceof Array?t.slice(0):Object.create(t):t}function r(t,i){var e={curve:i.curve};return i.duration&&(e.duration=i.duration),i.speed&&(e.speed=i.speed),t instanceof Object&&(void 0!==t.duration&&(e.duration=t.duration),t.curve&&(e.curve=t.curve),t.speed&&(e.speed=t.speed)),"string"==typeof e.curve&&(e.curve=n.getCurve(e.curve)),e}function a(t,i,e,n,o){var s,r=1e-7,a=(e(o)-e(o-r))/r;if(t instanceof Array){s=[];for(var c=0;c<t.length;c++)"number"==typeof t[c]?s[c]=a*(t[c]-i[c])/n:s[c]=0}else s=a*(t-i)/n;return s}function c(t,i,e){var n;if(t instanceof Array){n=[];for(var s=0;s<t.length;s++)"number"==typeof t[s]?n[s]=o(t[s],i[s],e):n[s]=t[s]}else n=o(t,i,e);return n}n.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}},n.SUPPORTS_MULTIPLE=!0,n.DEFAULT_OPTIONS={curve:n.Curves.linear,duration:500,speed:0};var u={};n.registerCurve=function(t,i){return u[t]?!1:(u[t]=i,!0)},n.unregisterCurve=function(t){return u[t]?(delete u[t],!0):!1},n.getCurve=function(t){var i=u[t];if(void 0!==i)return i;throw new Error("curve not registered")},n.getCurves=function(){return u},n.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)},n.prototype.set=function(t,i,e){if(!i)return this.reset(t),void(e&&e());if(this._startValue=s(this.get()),i=r(i,this.options),i.speed){var n=this._startValue;if(n instanceof Object){var o=0;for(var a in n)o+=(t[a]-n[a])*(t[a]-n[a]);i.duration=Math.sqrt(o)/i.speed}else i.duration=Math.abs(t-n)/i.speed}this._startTime=Date.now(),this._endValue=s(t),this._startVelocity=s(i.velocity),this._duration=i.duration,this._curve=i.curve,this._active=!0,this._callback=e},n.prototype.reset=function(t,i){if(this._callback){var e=this._callback;this._callback=void 0,e()}this.state=s(t),this.velocity=s(i),this._startTime=0,this._duration=0,this._updateTime=0,this._startValue=this.state,this._startVelocity=this.velocity,this._endValue=this.state,this._active=!1},n.prototype.getVelocity=function(){return this.velocity},n.prototype.get=function(t){return this.update(t),this.state},n.prototype.update=function(t){if(this._active){if(t||(t=Date.now()),!(this._updateTime>=t)){this._updateTime=t;var i=t-this._startTime;if(i>=this._duration)this.state=this._endValue,this.velocity=a(this.state,this._startValue,this._curve,this._duration,1),this._active=!1;else if(0>i)this.state=this._startValue,this.velocity=this._startVelocity;else{var e=i/this._duration;this.state=c(this._startValue,this._endValue,this._curve(e)),this.velocity=a(this.state,this._startValue,this._curve,this._duration,e)}}}else if(this._callback){var n=this._callback;this._callback=void 0,n()}},n.prototype.isActive=function(){return this._active},n.prototype.halt=function(){this.reset(this.get())},n.registerCurve("linear",n.Curves.linear),n.registerCurve("easeIn",n.Curves.easeIn),n.registerCurve("easeOut",n.Curves.easeOut),n.registerCurve("easeInOut",n.Curves.easeInOut),n.registerCurve("easeOutBounce",n.Curves.easeOutBounce),n.registerCurve("spring",n.Curves.spring),n.customCurve=function(t,i){return t=t||0,i=i||0,function(e){return t*e+(-2*t-i+3)*e*e+(t+i-2)*e*e*e}},t.exports=n},function(t,i,e){function n(){o.apply(this,arguments),this.downstream=[],this.downstreamFn=[],this.upstream=[],this.upstreamListeners={}}/* 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 o=e(22);n.prototype=Object.create(o.prototype),n.prototype.constructor=n,n.setInputHandler=function(t,i){t.trigger=i.trigger.bind(i),i.subscribe&&i.unsubscribe&&(t.subscribe=i.subscribe.bind(i),t.unsubscribe=i.unsubscribe.bind(i))},n.setOutputHandler=function(t,i){i instanceof n&&i.bindThis(t),t.pipe=i.pipe.bind(i),t.unpipe=i.unpipe.bind(i),t.on=i.on.bind(i),t.addListener=t.on,t.removeListener=i.removeListener.bind(i)},n.prototype.emit=function(t,i){o.prototype.emit.apply(this,arguments);var e=0;for(e=0;e<this.downstream.length;e++)this.downstream[e].trigger&&this.downstream[e].trigger(t,i);for(e=0;e<this.downstreamFn.length;e++)this.downstreamFn[e](t,i);return this},n.prototype.trigger=n.prototype.emit,n.prototype.pipe=function(t){if(t.subscribe instanceof Function)return t.subscribe(this);var i=t instanceof Function?this.downstreamFn:this.downstream,e=i.indexOf(t);return 0>e&&i.push(t),t instanceof Function?t("pipe",null):t.trigger&&t.trigger("pipe",null),t},n.prototype.unpipe=function(t){if(t.unsubscribe instanceof Function)return t.unsubscribe(this);var i=t instanceof Function?this.downstreamFn:this.downstream,e=i.indexOf(t);return e>=0?(i.splice(e,1),t instanceof Function?t("unpipe",null):t.trigger&&t.trigger("unpipe",null),t):!1},n.prototype.on=function(t,i){if(o.prototype.on.apply(this,arguments),!(t in this.upstreamListeners)){var e=this.trigger.bind(this,t);this.upstreamListeners[t]=e;for(var n=0;n<this.upstream.length;n++)this.upstream[n].on(t,e)}return this},n.prototype.addListener=n.prototype.on,n.prototype.subscribe=function(t){var i=this.upstream.indexOf(t);if(0>i){this.upstream.push(t);for(var e in this.upstreamListeners)t.on(e,this.upstreamListeners[e])}return this},n.prototype.unsubscribe=function(t){var i=this.upstream.indexOf(t);if(i>=0){this.upstream.splice(i,1);for(var e in this.upstreamListeners)t.removeListener(e,this.upstreamListeners[e])}return this},t.exports=n},function(t,i,e){function n(t){return 2===t.length?t[0]*t[0]+t[1]*t[1]:t[0]*t[0]+t[1]*t[1]+t[2]*t[2]}function o(t){return Math.sqrt(n(t))}function s(t){return 0>t?-1:1}/* 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={};r.precision=1e-6,r.identity=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],r.multiply4x4=function(t,i){return[t[0]*i[0]+t[4]*i[1]+t[8]*i[2]+t[12]*i[3],t[1]*i[0]+t[5]*i[1]+t[9]*i[2]+t[13]*i[3],t[2]*i[0]+t[6]*i[1]+t[10]*i[2]+t[14]*i[3],t[3]*i[0]+t[7]*i[1]+t[11]*i[2]+t[15]*i[3],t[0]*i[4]+t[4]*i[5]+t[8]*i[6]+t[12]*i[7],t[1]*i[4]+t[5]*i[5]+t[9]*i[6]+t[13]*i[7],t[2]*i[4]+t[6]*i[5]+t[10]*i[6]+t[14]*i[7],t[3]*i[4]+t[7]*i[5]+t[11]*i[6]+t[15]*i[7],t[0]*i[8]+t[4]*i[9]+t[8]*i[10]+t[12]*i[11],t[1]*i[8]+t[5]*i[9]+t[9]*i[10]+t[13]*i[11],t[2]*i[8]+t[6]*i[9]+t[10]*i[10]+t[14]*i[11],t[3]*i[8]+t[7]*i[9]+t[11]*i[10]+t[15]*i[11],t[0]*i[12]+t[4]*i[13]+t[8]*i[14]+t[12]*i[15],t[1]*i[12]+t[5]*i[13]+t[9]*i[14]+t[13]*i[15],t[2]*i[12]+t[6]*i[13]+t[10]*i[14]+t[14]*i[15],t[3]*i[12]+t[7]*i[13]+t[11]*i[14]+t[15]*i[15]]},r.multiply=function(t,i){return[t[0]*i[0]+t[4]*i[1]+t[8]*i[2],t[1]*i[0]+t[5]*i[1]+t[9]*i[2],t[2]*i[0]+t[6]*i[1]+t[10]*i[2],0,t[0]*i[4]+t[4]*i[5]+t[8]*i[6],t[1]*i[4]+t[5]*i[5]+t[9]*i[6],t[2]*i[4]+t[6]*i[5]+t[10]*i[6],0,t[0]*i[8]+t[4]*i[9]+t[8]*i[10],t[1]*i[8]+t[5]*i[9]+t[9]*i[10],t[2]*i[8]+t[6]*i[9]+t[10]*i[10],0,t[0]*i[12]+t[4]*i[13]+t[8]*i[14]+t[12],t[1]*i[12]+t[5]*i[13]+t[9]*i[14]+t[13],t[2]*i[12]+t[6]*i[13]+t[10]*i[14]+t[14],1]},r.thenMove=function(t,i){return i[2]||(i[2]=0),[t[0],t[1],t[2],0,t[4],t[5],t[6],0,t[8],t[9],t[10],0,t[12]+i[0],t[13]+i[1],t[14]+i[2],1]},r.moveThen=function(t,i){t[2]||(t[2]=0);var e=t[0]*i[0]+t[1]*i[4]+t[2]*i[8],n=t[0]*i[1]+t[1]*i[5]+t[2]*i[9],o=t[0]*i[2]+t[1]*i[6]+t[2]*i[10];return r.thenMove(i,[e,n,o])},r.translate=function(t,i,e){return void 0===e&&(e=0),[1,0,0,0,0,1,0,0,0,0,1,0,t,i,e,1]},r.thenScale=function(t,i){return[i[0]*t[0],i[1]*t[1],i[2]*t[2],0,i[0]*t[4],i[1]*t[5],i[2]*t[6],0,i[0]*t[8],i[1]*t[9],i[2]*t[10],0,i[0]*t[12],i[1]*t[13],i[2]*t[14],1]},r.scale=function(t,i,e){return void 0===e&&(e=1),void 0===i&&(i=t),[t,0,0,0,0,i,0,0,0,0,e,0,0,0,0,1]},r.rotateX=function(t){var i=Math.cos(t),e=Math.sin(t);return[1,0,0,0,0,i,e,0,0,-e,i,0,0,0,0,1]},r.rotateY=function(t){var i=Math.cos(t),e=Math.sin(t);return[i,0,-e,0,0,1,0,0,e,0,i,0,0,0,0,1]},r.rotateZ=function(t){var i=Math.cos(t),e=Math.sin(t);return[i,e,0,0,-e,i,0,0,0,0,1,0,0,0,0,1]},r.rotate=function(t,i,e){var n=Math.cos(t),o=Math.sin(t),s=Math.cos(i),r=Math.sin(i),a=Math.cos(e),c=Math.sin(e),u=[s*a,n*c+o*r*a,o*c-n*r*a,0,-s*c,n*a-o*r*c,o*a+n*r*c,0,r,-o*s,n*s,0,0,0,0,1];return u},r.rotateAxis=function(t,i){var e=Math.sin(i),n=Math.cos(i),o=1-n,s=t[0]*t[0]*o,r=t[0]*t[1]*o,a=t[0]*t[2]*o,c=t[1]*t[1]*o,u=t[1]*t[2]*o,h=t[2]*t[2]*o,p=t[0]*e,l=t[1]*e,f=t[2]*e,d=[s+n,r+f,a-l,0,r-f,c+n,u+p,0,a+l,u-p,h+n,0,0,0,0,1];return d},r.aboutOrigin=function(t,i){var e=t[0]-(t[0]*i[0]+t[1]*i[4]+t[2]*i[8]),n=t[1]-(t[0]*i[1]+t[1]*i[5]+t[2]*i[9]),o=t[2]-(t[0]*i[2]+t[1]*i[6]+t[2]*i[10]);return r.thenMove(i,[e,n,o])},r.skew=function(t,i,e){return[1,Math.tan(i),0,0,Math.tan(e),1,0,0,0,Math.tan(t),1,0,0,0,0,1]},r.skewX=function(t){return[1,0,0,0,Math.tan(t),1,0,0,0,0,1,0,0,0,0,1]},r.skewY=function(t){return[1,Math.tan(t),0,0,0,1,0,0,0,0,1,0,0,0,0,1]},r.perspective=function(t){return[1,0,0,0,0,1,0,0,0,0,1,-1/t,0,0,0,1]},r.getTranslate=function(t){return[t[12],t[13],t[14]]},r.inverse=function(t){var i=t[5]*t[10]-t[6]*t[9],e=t[4]*t[10]-t[6]*t[8],n=t[4]*t[9]-t[5]*t[8],o=t[1]*t[10]-t[2]*t[9],s=t[0]*t[10]-t[2]*t[8],r=t[0]*t[9]-t[1]*t[8],a=t[1]*t[6]-t[2]*t[5],c=t[0]*t[6]-t[2]*t[4],u=t[0]*t[5]-t[1]*t[4],h=t[0]*i-t[1]*e+t[2]*n,p=1/h,l=[p*i,-p*o,p*a,0,-p*e,p*s,-p*c,0,p*n,-p*r,p*u,0,0,0,0,1];return l[12]=-t[12]*l[0]-t[13]*l[4]-t[14]*l[8],l[13]=-t[12]*l[1]-t[13]*l[5]-t[14]*l[9],l[14]=-t[12]*l[2]-t[13]*l[6]-t[14]*l[10],l},r.transpose=function(t){return[t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15]]},r.interpret=function(t){var i=[t[0],t[1],t[2]],e=s(i[0]),a=o(i),c=[i[0]+e*a,i[1],i[2]],u=2/n(c);if(u>=1/0)return{translate:r.getTranslate(t),rotate:[0,0,0],scale:[0,0,0],skew:[0,0,0]};var h=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];h[0]=1-u*c[0]*c[0],h[5]=1-u*c[1]*c[1],h[10]=1-u*c[2]*c[2],h[1]=-u*c[0]*c[1],h[2]=-u*c[0]*c[2],h[6]=-u*c[1]*c[2],h[4]=h[1],h[8]=h[2],h[9]=h[6];var p=r.multiply(h,t),l=[p[5],p[6]],f=s(l[0]),d=o(l),v=[l[0]+f*d,l[1]],y=2/n(v),g=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1];g[5]=1-y*v[0]*v[0],g[10]=1-y*v[1]*v[1],g[6]=-y*v[0]*v[1],g[9]=g[6];var _=r.multiply(g,h),m=r.multiply(_,t),O=r.scale(m[0]<0?-1:1,m[5]<0?-1:1,m[10]<0?-1:1);m=r.multiply(m,O),_=r.multiply(O,_);var b={};return b.translate=r.getTranslate(t),b.rotate=[Math.atan2(-_[6],_[10]),Math.asin(_[2]),Math.atan2(-_[1],_[0])],b.rotate[0]||(b.rotate[0]=0,b.rotate[2]=Math.atan2(_[4],_[5])),b.scale=[m[0],m[5],m[10]],b.skew=[Math.atan2(m[9],b.scale[2]),Math.atan2(m[8],b.scale[2]),Math.atan2(m[4],b.scale[0])],Math.abs(b.rotate[0])+Math.abs(b.rotate[2])>1.5*Math.PI&&(b.rotate[1]=Math.PI-b.rotate[1],b.rotate[1]>Math.PI&&(b.rotate[1]-=2*Math.PI),b.rotate[1]<-Math.PI&&(b.rotate[1]+=2*Math.PI),b.rotate[0]<0?b.rotate[0]+=Math.PI:b.rotate[0]-=Math.PI,b.rotate[2]<0?b.rotate[2]+=Math.PI:b.rotate[2]-=Math.PI),b},r.average=function(t,i,e){e=void 0===e?.5:e;for(var n=r.interpret(t),o=r.interpret(i),s={translate:[0,0,0],rotate:[0,0,0],scale:[0,0,0],skew:[0,0,0]},a=0;3>a;a++)s.translate[a]=(1-e)*n.translate[a]+e*o.translate[a],s.rotate[a]=(1-e)*n.rotate[a]+e*o.rotate[a],s.scale[a]=(1-e)*n.scale[a]+e*o.scale[a],s.skew[a]=(1-e)*n.skew[a]+e*o.skew[a];return r.build(s)},r.build=function(t){var i=r.scale(t.scale[0],t.scale[1],t.scale[2]),e=r.skew(t.skew[0],t.skew[1],t.skew[2]),n=r.rotate(t.rotate[0],t.rotate[1],t.rotate[2]);return r.thenMove(r.multiply(r.multiply(n,e),i),t.translate)},r.equals=function(t,i){return!r.notEquals(t,i)},r.notEquals=function(t,i){return t===i?!1:!(t&&i)||t[12]!==i[12]||t[13]!==i[13]||t[14]!==i[14]||t[0]!==i[0]||t[1]!==i[1]||t[2]!==i[2]||t[4]!==i[4]||t[5]!==i[5]||t[6]!==i[6]||t[8]!==i[8]||t[9]!==i[9]||t[10]!==i[10]},r.normalizeRotation=function(t){var i=t.slice(0);for((i[0]===.5*Math.PI||i[0]===.5*-Math.PI)&&(i[0]=-i[0],i[1]=Math.PI-i[1],i[2]-=Math.PI),i[0]>.5*Math.PI&&(i[0]=i[0]-Math.PI,i[1]=Math.PI-i[1],i[2]-=Math.PI),i[0]<.5*-Math.PI&&(i[0]=i[0]+Math.PI,i[1]=-Math.PI-i[1],i[2]-=Math.PI);i[1]<-Math.PI;)i[1]+=2*Math.PI;for(;i[1]>=Math.PI;)i[1]-=2*Math.PI;for(;i[2]<-Math.PI;)i[2]+=2*Math.PI;for(;i[2]>=Math.PI;)i[2]-=2*Math.PI;return i},r.inFront=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,.001,1],r.behind=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,-.001,1],t.exports=r},function(t,i,e){/* 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 n={};n.integrateVelocity=function(t,i){var e=t.velocity,n=t.inverseMass,o=t.force;o.isZero()||(e.add(o.mult(i*n)).put(e),o.clear())},n.integratePosition=function(t,i){var e=t.position,n=t.velocity;e.add(n.mult(i)).put(e)},n.integrateAngularMomentum=function(t,i){var e=t.angularMomentum,n=t.torque;n.isZero()||(e.add(n.mult(i)).put(e),n.clear())},n.integrateOrientation=function(t,i){var e=t.orientation,n=t.angularVelocity;n.isZero()||e.add(e.multiply(n).scalarMultiply(.5*i)).put(e)},t.exports=n},function(t,i,e){function n(t){this.force=new o(t),this._eventOutput=new s,s.setOutputHandler(this,this._eventOutput)}/* 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 o=e(11),s=e(16);n.prototype.setOptions=function(t){this._eventOutput.emit("change",t)},n.prototype.applyForce=function(t){for(var i=t.length;i--;)t[i].applyForce(this.force)},n.prototype.getEnergy=function(){return 0},t.exports=n},function(t,i,e){function n(){this.options=this.options||{},this._eventOutput=ne