Socket
Socket
Sign inDemoInstall

rebound

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.10 to 0.0.11

docs/public/fonts/roboto-black.eot

2

package.json
{
"name": "rebound",
"version": "0.0.10",
"version": "0.0.11",
"description": "A simple library for modeling spring dynamics",

@@ -5,0 +5,0 @@ "main": "rebound.js",

@@ -1,16 +0,31 @@

[![Build Status](https://travis-ci.org/facebook/rebound-js.svg?branch=master)](https://travis-ci.org/facebook/rebound-js)
[![Build
Status](https://travis-ci.org/facebook/rebound-js.svg?branch=master)](https://travis-ci.org/facebook/rebound-js)
###REBOUND
Rebound is a simple library that models Spring dynamics for the purpose of driving physical animations.
Rebound is a simple library that models Spring dynamics for the purpose of
driving physical animations.
###ORIGIN
Rebound was originally written in Java to provide a lightweight physics system for Facebook Home and Chat Heads on Android. It’s now been adopted by several other Android applications. This JavaScript port was written to provide a quick way to demonstrate Rebound animations on the web for a conference talk. Since then the JavaScript version has been used to build some really nice interfaces. Check out [brandonwalkin.com](http://brandonwalkin.com) for an example.
Rebound was originally written in Java to provide a lightweight physics system
for Facebook Home and Chat Heads on Android. It’s now been adopted by several
other Android applications. This JavaScript port was written to provide a quick
way to demonstrate Rebound animations on the web for a conference talk. Since
then the JavaScript version has been used to build some really nice interfaces.
Check out [brandonwalkin.com](http://brandonwalkin.com) for an example.
###OVERVIEW
The Library provides a SpringSystem for maintaining a set of Spring objects and iterating those Springs through a physics solver loop until equilibrium is achieved. The Spring class is the basic animation driver provided by Rebound. By attaching a listener to a Spring, you can observe its motion. The observer function is notified of position changes on the spring as it solves for equilibrium. These position updates can be mapped to an animation range to drive animated property updates on your user interface elements (translation, rotation, scale, etc).
The Library provides a SpringSystem for maintaining a set of Spring objects and
iterating those Springs through a physics solver loop until equilibrium is
achieved. The Spring class is the basic animation driver provided by Rebound.
By attaching a listener to a Spring, you can observe its motion. The observer
function is notified of position changes on the spring as it solves for
equilibrium. These position updates can be mapped to an animation range to
drive animated property updates on your user interface elements (translation,
rotation, scale, etc).
Check out the [examples](http://facebook.github.io/rebound-js/examples) and [docco](http://facebook.github.io/rebound-js/docs/rebound.html) for
more details.
Check out the [docco](http://facebook.github.io/rebound-js/docs/rebound.html),
[tests](http://facebook.github.io/rebound-js/browser_test/index.html), and
[examples](http://facebook.github.io/rebound-js/examples) for more details.

@@ -10,9 +10,9 @@ // Rebound

// in Java to provide a lightweight physics system for
// [Facebook Home](https://play.google.com/store/apps/details?id=com.facebook.home)
// and [Chat Heads](https://play.google.com/store/apps/details?id=com.facebook.orca)
// [Home](https://play.google.com/store/apps/details?id=com.facebook.home) and
// [Chat Heads](https://play.google.com/store/apps/details?id=com.facebook.orca)
// on Android. It's now been adopted by several other Android
// applications. This JavaScript port was written to provide a quick
// way to demonstrate Rebound animations on the web for a
// [conference talk](https://www.youtube.com/watch?v=s5kNm-DgyjY). Since then the
// JavaScript version has been used to build some really nice interfaces.
// [conference talk](https://www.youtube.com/watch?v=s5kNm-DgyjY). Since then
// the JavaScript version has been used to build some really nice interfaces.
// Check out [brandonwalkin.com](http://brandonwalkin.com) for an

@@ -39,3 +39,6 @@ // example.

// <div style="text-align:center; margin-bottom:50px; margin-top:50px">
// <img src="http://facebook.github.io/rebound/images/rebound.png" id="logo" />
// <img
// src="http://facebook.github.io/rebound/images/rebound.png"
// id="logo"
// />
// </div>

@@ -131,3 +134,3 @@ // <script src="../rebound.min.js"></script>

util.bind = function bind(func, context) {
args = slice.call(arguments, 2);
var args = slice.call(arguments, 2);
return function() {

@@ -181,19 +184,40 @@ func.apply(context, concat.call(args, slice.call(arguments)));

setLooper: function(looper) {
this.looper = looper
this.looper = looper;
looper.springSystem = this;
},
// Create and register a new spring with the SpringSystem. This
// Spring will now be solved for during the physics iteration loop. By default
// the spring will use the default Origami spring config with 40 tension and 7
// friction, but you can also provide your own values here.
// Add a new spring to this SpringSystem. This Spring will now be solved for
// during the physics iteration loop. By default the spring will use the
// default Origami spring config with 40 tension and 7 friction, but you can
// also provide your own values here.
createSpring: function(tension, friction) {
var springConfig;
if (tension === undefined || friction === undefined) {
springConfig = SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG;
} else {
springConfig =
SpringConfig.fromOrigamiTensionAndFriction(tension, friction);
}
return this.createSpringWithConfig(springConfig);
},
// Add a spring with a specified bounciness and speed. To replicate Origami
// compositions based on PopAnimation patches, use this factory method to
// create matching springs.
createSpringWithBouncinessAndSpeed: function(bounciness, speed) {
var springConfig;
if (bounciness === undefined || speed === undefined) {
springConfig = SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG;
} else {
springConfig =
SpringConfig.fromBouncinessAndSpeed(bounciness, speed);
}
return this.createSpringWithConfig(springConfig);
},
// Add a spring with the provided SpringConfig.
createSpringWithConfig: function(springConfig) {
var spring = new Spring(this);
this.registerSpring(spring);
if (typeof tension === 'undefined' || typeof friction === 'undefined') {
spring.setSpringConfig(SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG);
} else {
var springConfig = SpringConfig.fromOrigamiTensionAndFriction(tension, friction);
spring.setSpringConfig(springConfig);
}
spring.setSpringConfig(springConfig);
return spring;

@@ -285,3 +309,3 @@ },

for (i = 0; i < len; i++) {
var listener = this.listeners[i];
listener = this.listeners[i];
listener.onBeforeIntegrate && listener.onBeforeIntegrate(this);

@@ -297,3 +321,3 @@ }

for (i = 0; i < len; i++) {
var listener = this.listeners[i];
listener = this.listeners[i];
listener.onAfterIntegrate && listener.onAfterIntegrate(this);

@@ -345,6 +369,6 @@ }

// tension which is a force multipler on the displacement of the
// spring from its rest point or `endValue` as defined by [Hooke’s
// spring from its rest point or `endValue` as defined by [Hooke's
// law](http://en.wikipedia.org/wiki/Hooke's_law). Springs also have
// configurable friction, which ensures that they do not oscillate
// infinitely. When a Spring is displaced by updating it’s resting
// infinitely. When a Spring is displaced by updating it's resting
// or `currentValue`, the SpringSystems that contain that Spring

@@ -478,3 +502,4 @@ // will automatically start looping to solve for equilibrium. As each

// Get the absolute distance of the Spring from it’s resting endValue position.
// Get the absolute distance of the Spring from it's resting endValue
// position.
getCurrentDisplacementDistance: function() {

@@ -503,3 +528,4 @@ return this.getDisplacementDistanceForState(this._currentState);

var listener = this.listeners[i];
listener.onSpringEndStateChange && listener.onSpringEndStateChange(this);
var onChange = listener.onSpringEndStateChange;
onChange && onChange(this);
}

@@ -578,5 +604,7 @@ return this;

isOvershooting: function() {
var start = this._startValue;
var end = this._endValue;
return this._springConfig.tension > 0 &&
((this._startValue < this._endValue && this.getCurrentValue() > this._endValue) ||
(this._startValue > this._endValue && this.getCurrentValue() < this._endValue));
((start < end && this.getCurrentValue() > end) ||
(start > end && this.getCurrentValue() < end));
},

@@ -628,22 +656,31 @@

aVelocity = velocity;
aAcceleration = (tension * (this._endValue - tempPosition)) - friction * velocity;
aAcceleration =
(tension * (this._endValue - tempPosition)) - friction * velocity;
tempPosition = position + aVelocity * Spring.SOLVER_TIMESTEP_SEC * 0.5;
tempVelocity = velocity + aAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
tempVelocity =
velocity + aAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
bVelocity = tempVelocity;
bAcceleration = (tension * (this._endValue - tempPosition)) - friction * tempVelocity;
bAcceleration =
(tension * (this._endValue - tempPosition)) - friction * tempVelocity;
tempPosition = position + bVelocity * Spring.SOLVER_TIMESTEP_SEC * 0.5;
tempVelocity = velocity + bAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
tempVelocity =
velocity + bAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
cVelocity = tempVelocity;
cAcceleration = (tension * (this._endValue - tempPosition)) - friction * tempVelocity;
cAcceleration =
(tension * (this._endValue - tempPosition)) - friction * tempVelocity;
tempPosition = position + cVelocity * Spring.SOLVER_TIMESTEP_SEC * 0.5;
tempVelocity = velocity + cAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
tempVelocity =
velocity + cAcceleration * Spring.SOLVER_TIMESTEP_SEC * 0.5;
dVelocity = tempVelocity;
dAcceleration = (tension * (this._endValue - tempPosition)) - friction * tempVelocity;
dAcceleration =
(tension * (this._endValue - tempPosition)) - friction * tempVelocity;
dxdt = 1.0/6.0 * (aVelocity + 2.0 * (bVelocity + cVelocity) + dVelocity);
dvdt = 1.0/6.0 *
(aAcceleration + 2.0 * (bAcceleration + cAcceleration) + dAcceleration);
dxdt =
1.0/6.0 * (aVelocity + 2.0 * (bVelocity + cVelocity) + dVelocity);
dvdt = 1.0/6.0 * (
aAcceleration + 2.0 * (bAcceleration + cAcceleration) + dAcceleration
);

@@ -723,3 +760,3 @@ position += dxdt * Spring.SOLVER_TIMESTEP_SEC;

// Check if the Spring is atRest meaning that it’s currentValue and
// Check if the Spring is atRest meaning that it's currentValue and
// endValue are the same and that it has no velocity. The previously

@@ -732,3 +769,4 @@ // described thresholds for speed and displacement define the bounds

return Math.abs(this._currentState.velocity) < this._restSpeedThreshold &&
(this.getDisplacementDistanceForState(this._currentState) <= this._displacementFromRestThreshold ||
(this.getDisplacementDistanceForState(this._currentState) <=
this._displacementFromRestThreshold ||
this._springConfig.tension === 0);

@@ -807,5 +845,5 @@ },

// -------
// **AnimationLooper** plays each frame of the SpringSystem on animation timing loop.
// This is the default type of looper for a new spring system as it is the most common
// when developing UI.
// **AnimationLooper** plays each frame of the SpringSystem on animation
// timing loop. This is the default type of looper for a new spring system
// as it is the most common when developing UI.
var AnimationLooper = rebound.AnimationLooper = function AnimationLooper() {

@@ -820,12 +858,12 @@ this.springSystem = null;

util.onFrame(_run);
}
};
};
// **SimulationLooper** resolves the SpringSystem to a resting state in a
// tight and blocking loop. This is useful for synchronously generating pre-recorded
// animations that can then be played on a timing loop later. Sometimes this lead to
// better performance to pre-record a single spring curve and use it to drive many
// animations; however, it can make dynamic response to user input a bit trickier to
// implement.
var SimulationLooper = rebound.SimulationLooper = function SimulationLooper(timestep) {
// tight and blocking loop. This is useful for synchronously generating
// pre-recorded animations that can then be played on a timing loop later.
// Sometimes this lead to better performance to pre-record a single spring
// curve and use it to drive many animations; however, it can make dynamic
// response to user input a bit trickier to implement.
rebound.SimulationLooper = function SimulationLooper(timestep) {
this.springSystem = null;

@@ -845,15 +883,16 @@ var time = 0;

running = false;
}
};
};
// **SteppingSimulationLooper** resolves the SpringSystem one step at a time controlled
// by an outside loop. This is useful for testing and verifying the behavior of a SpringSystem
// or if you want to control your own timing loop for some reason e.g. slowing down or speeding
// up the simulation.
var SteppingSimulationLooper = rebound.SteppingSimulationLooper = function(timestep) {
// **SteppingSimulationLooper** resolves the SpringSystem one step at a
// time controlled by an outside loop. This is useful for testing and
// verifying the behavior of a SpringSystem or if you want to control your own
// timing loop for some reason e.g. slowing down or speeding up the
// simulation.
rebound.SteppingSimulationLooper = function(timestep) {
this.springSystem = null;
var time = 0;
var running = false;
// this.run is NOOP'd here to allow control from the outside using this.step.
// this.run is NOOP'd here to allow control from the outside using
// this.step.
this.run = function(){};

@@ -864,3 +903,3 @@

this.springSystem.loop(time+=timestep);
}
};
};

@@ -891,2 +930,68 @@

// BouncyConversion provides math for converting from Origami PopAnimation
// config values to regular Origami tension and friction values. If you are
// trying to replicate prototypes made with PopAnimation patches in Origami,
// then you should create your springs with
// SpringSystem.createSpringWithBouncinessAndSpeed, which uses this Math
// internally to create a spring to match the provided PopAnimation
// configuration from Origami.
var BouncyConversion = rebound.BouncyConversion = function(bounciness, speed){
this.bounciness = bounciness;
this.speed = speed;
var b = this.normalize(bounciness / 1.7, 0, 20.0);
b = this.projectNormal(b, 0.0, 0.8);
var s = this.normalize(speed / 1.7, 0, 20.0);
this.bouncyTension = this.projectNormal(s, 0.5, 200)
this.bouncyFriction = this.quadraticOutInterpolation(
b,
this.b3Nobounce(this.bouncyTension),
0.01);
}
util.extend(BouncyConversion.prototype, {
normalize: function(value, startValue, endValue) {
return (value - startValue) / (endValue - startValue);
},
projectNormal: function(n, start, end) {
return start + (n * (end - start));
},
linearInterpolation: function(t, start, end) {
return t * end + (1.0 - t) * start;
},
quadraticOutInterpolation: function(t, start, end) {
return this.linearInterpolation(2*t - t*t, start, end);
},
b3Friction1: function(x) {
return (0.0007 * Math.pow(x, 3)) -
(0.031 * Math.pow(x, 2)) + 0.64 * x + 1.28;
},
b3Friction2: function(x) {
return (0.000044 * Math.pow(x, 3)) -
(0.006 * Math.pow(x, 2)) + 0.36 * x + 2.;
},
b3Friction3: function(x) {
return (0.00000045 * Math.pow(x, 3)) -
(0.000332 * Math.pow(x, 2)) + 0.1078 * x + 5.84;
},
b3Nobounce: function(tension) {
var friction = 0;
if (tension <= 18) {
friction = this.b3Friction1(tension);
} else if (tension > 18 && tension <= 44) {
friction = this.b3Friction2(tension);
} else {
friction = this.b3Friction3(tension);
}
return friction;
}
});
util.extend(SpringConfig, {

@@ -903,10 +1008,24 @@ // Convert an origami Spring tension and friction to Rebound spring

// Create a SpringConfig with no tension or a coasting spring with some amount
// of Friction so that it does not coast infininitely.
// Convert an origami PopAnimation Spring bounciness and speed to Rebound
// spring constants. If you are using PopAnimation patches in Origami, this
// utility will provide springs that match your prototype.
fromBouncinessAndSpeed: function(bounciness, speed) {
var bouncyConversion = new rebound.BouncyConversion(bounciness, speed);
return this.fromOrigamiTensionAndFriction(
bouncyConversion.bouncyTension,
bouncyConversion.bouncyFriction);
},
// Create a SpringConfig with no tension or a coasting spring with some
// amount of Friction so that it does not coast infininitely.
coastingConfigWithOrigamiFriction: function(friction) {
return new SpringConfig(0, OrigamiValueConverter.frictionFromOrigamiValue(friction));
return new SpringConfig(
0,
OrigamiValueConverter.frictionFromOrigamiValue(friction)
);
}
});
SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG = SpringConfig.fromOrigamiTensionAndFriction(40, 7);
SpringConfig.DEFAULT_ORIGAMI_SPRING_CONFIG =
SpringConfig.fromOrigamiTensionAndFriction(40, 7);

@@ -916,3 +1035,4 @@ util.extend(SpringConfig.prototype, {friction: 0, tension: 0});

// Here are a couple of function to convert colors between hex codes and RGB
// component values. These are handy when performing color tweening animations.
// component values. These are handy when performing color
// tweening animations.
var colorCache = {};

@@ -929,3 +1049,3 @@ util.hexToRGB = function(color) {

var color = {
var ret = {
r: parseInt(parts[0], 16),

@@ -936,4 +1056,4 @@ g: parseInt(parts[1], 16),

colorCache[color] = color;
return color;
colorCache[color] = ret;
return ret;
};

@@ -967,13 +1087,20 @@

// Interpolate two hex colors in a 0 - 1 range or optionally provide a custom range
// with fromLow,fromHight. The output will be in hex by default unless asRGB is true
// in which case it will be returned as an rgb string.
interpolateColor: function(val, startColor, endColor, fromLow, fromHigh, asRGB) {
fromLow = typeof fromLow === 'undefined' ? 0 : fromLow;
fromHigh = typeof fromHigh === 'undefined' ? 1 : fromHigh;
var startColor = util.hexToRGB(startColor);
var endColor = util.hexToRGB(endColor);
var r = Math.floor(util.mapValueInRange(val, fromLow, fromHigh, startColor.r, endColor.r));
var g = Math.floor(util.mapValueInRange(val, fromLow, fromHigh, startColor.g, endColor.g));
var b = Math.floor(util.mapValueInRange(val, fromLow, fromHigh, startColor.b, endColor.b));
// Interpolate two hex colors in a 0 - 1 range or optionally provide a
// custom range with fromLow,fromHight. The output will be in hex by default
// unless asRGB is true in which case it will be returned as an rgb string.
interpolateColor:
function(val, startColor, endColor, fromLow, fromHigh, asRGB) {
fromLow = fromLow === undefined ? 0 : fromLow;
fromHigh = fromHigh === undefined ? 1 : fromHigh;
startColor = util.hexToRGB(startColor);
endColor = util.hexToRGB(endColor);
var r = Math.floor(
util.mapValueInRange(val, fromLow, fromHigh, startColor.r, endColor.r)
);
var g = Math.floor(
util.mapValueInRange(val, fromLow, fromHigh, startColor.g, endColor.g)
);
var b = Math.floor(
util.mapValueInRange(val, fromLow, fromHigh, startColor.b, endColor.b)
);
if (asRGB) {

@@ -1024,3 +1151,3 @@ return 'rgb(' + r + ',' + g + ',' + b + ')';

return _onFrame(func);
}
};

@@ -1036,2 +1163,3 @@ // Export the public api using exports for common js or the window for

// Legal Stuff

@@ -1038,0 +1166,0 @@ // -----------

@@ -1,1 +0,1 @@

(function(){var k={};var a=k.util={};var d=Array.prototype.concat;var m=Array.prototype.slice;a.bind=function s(u,t){args=m.call(arguments,2);return function(){u.apply(t,d.call(args,m.call(arguments)))}};a.extend=function o(v,u){for(var t in u){if(u.hasOwnProperty(t)){v[t]=u[t]}}};var e=k.SpringSystem=function e(t){this._springRegistry={};this._activeSprings=[];this.listeners=[];this._idleSpringIndices=[];this.looper=t||new g();this.looper.springSystem=this};a.extend(e.prototype,{_springRegistry:null,_isIdle:true,_lastTimeMillis:-1,_activeSprings:null,listeners:null,_idleSpringIndices:null,setLooper:function(t){this.looper=t;t.springSystem=this},createSpring:function(u,w){var t=new i(this);this.registerSpring(t);if(typeof u==="undefined"||typeof w==="undefined"){t.setSpringConfig(c.DEFAULT_ORIGAMI_SPRING_CONFIG)}else{var v=c.fromOrigamiTensionAndFriction(u,w);t.setSpringConfig(v)}return t},getIsIdle:function(){return this._isIdle},getSpringById:function(t){return this._springRegistry[t]},getAllSprings:function(){var t=[];for(var u in this._springRegistry){if(this._springRegistry.hasOwnProperty(u)){t.push(this._springRegistry[u])}}return t},registerSpring:function(t){this._springRegistry[t.getId()]=t},deregisterSpring:function(t){f(this._activeSprings,t);delete this._springRegistry[t.getId()]},advance:function(y,w){while(this._idleSpringIndices.length>0){this._idleSpringIndices.pop()}for(var x=0,u=this._activeSprings.length;x<u;x++){var v=this._activeSprings[x];if(v.systemShouldAdvance()){v.advance(y/1000,w/1000)}else{this._idleSpringIndices.push(this._activeSprings.indexOf(v))}}while(this._idleSpringIndices.length>0){var t=this._idleSpringIndices.pop();t>=0&&this._activeSprings.splice(t,1)}},loop:function(x){var w;if(this._lastTimeMillis===-1){this._lastTimeMillis=x-1}var u=x-this._lastTimeMillis;this._lastTimeMillis=x;var v=0,t=this.listeners.length;for(v=0;v<t;v++){var w=this.listeners[v];w.onBeforeIntegrate&&w.onBeforeIntegrate(this)}this.advance(x,u);if(this._activeSprings.length===0){this._isIdle=true;this._lastTimeMillis=-1}for(v=0;v<t;v++){var w=this.listeners[v];w.onAfterIntegrate&&w.onAfterIntegrate(this)}if(!this._isIdle){this.looper.run()}},activateSpring:function(u){var t=this._springRegistry[u];if(this._activeSprings.indexOf(t)==-1){this._activeSprings.push(t)}if(this.getIsIdle()){this._isIdle=false;this.looper.run()}},addListener:function(t){this.listeners.push(t)},removeListener:function(t){f(this.listeners,t)},removeAllListeners:function(){this.listeners=[]}});var i=k.Spring=function i(t){this._id="s"+i._ID++;this._springSystem=t;this.listeners=[];this._currentState=new p();this._previousState=new p();this._tempState=new p()};a.extend(i,{_ID:0,MAX_DELTA_TIME_SEC:0.064,SOLVER_TIMESTEP_SEC:0.001});a.extend(i.prototype,{_id:0,_springConfig:null,_overshootClampingEnabled:false,_currentState:null,_previousState:null,_tempState:null,_startValue:0,_endValue:0,_wasAtRest:true,_restSpeedThreshold:0.001,_displacementFromRestThreshold:0.001,listeners:null,_timeAccumulator:0,_springSystem:null,destroy:function(){this.listeners=[];this.frames=[];this._springSystem.deregisterSpring(this)},getId:function(){return this._id},setSpringConfig:function(t){this._springConfig=t;return this},getSpringConfig:function(){return this._springConfig},setCurrentValue:function(u,t){this._startValue=u;this._currentState.position=u;if(!t){this.setAtRest()}this.notifyPositionUpdated(false,false);return this},getStartValue:function(){return this._startValue},getCurrentValue:function(){return this._currentState.position},getCurrentDisplacementDistance:function(){return this.getDisplacementDistanceForState(this._currentState)},getDisplacementDistanceForState:function(t){return Math.abs(this._endValue-t.position)},setEndValue:function(u){if(this._endValue==u&&this.isAtRest()){return this}this._startValue=this.getCurrentValue();this._endValue=u;this._springSystem.activateSpring(this.getId());for(var v=0,t=this.listeners.length;v<t;v++){var w=this.listeners[v];w.onSpringEndStateChange&&w.onSpringEndStateChange(this)}return this},getEndValue:function(){return this._endValue},setVelocity:function(t){if(t===this._currentState.velocity){return this}this._currentState.velocity=t;this._springSystem.activateSpring(this.getId());return this},getVelocity:function(){return this._currentState.velocity},setRestSpeedThreshold:function(t){this._restSpeedThreshold=t;return this},getRestSpeedThreshold:function(){return this._restSpeedThreshold},setRestDisplacementThreshold:function(t){this._displacementFromRestThreshold=t},getRestDisplacementThreshold:function(){return this._displacementFromRestThreshold},setOvershootClampingEnabled:function(t){this._overshootClampingEnabled=t;return this},isOvershootClampingEnabled:function(){return this._overshootClampingEnabled},isOvershooting:function(){return this._springConfig.tension>0&&((this._startValue<this._endValue&&this.getCurrentValue()>this._endValue)||(this._startValue>this._endValue&&this.getCurrentValue()<this._endValue))},advance:function(z,B){var H=this.isAtRest();if(H&&this._wasAtRest){return}var x=B;if(B>i.MAX_DELTA_TIME_SEC){x=i.MAX_DELTA_TIME_SEC}this._timeAccumulator+=x;var D=this._springConfig.tension,y=this._springConfig.friction,N=this._currentState.position,E=this._currentState.velocity,K=this._tempState.position,I=this._tempState.velocity,u,L,G,O,t,w,F,A,M,J;while(this._timeAccumulator>=i.SOLVER_TIMESTEP_SEC){this._timeAccumulator-=i.SOLVER_TIMESTEP_SEC;if(this._timeAccumulator<i.SOLVER_TIMESTEP_SEC){this._previousState.position=N;this._previousState.velocity=E}u=E;L=(D*(this._endValue-K))-y*E;K=N+u*i.SOLVER_TIMESTEP_SEC*0.5;I=E+L*i.SOLVER_TIMESTEP_SEC*0.5;G=I;O=(D*(this._endValue-K))-y*I;K=N+G*i.SOLVER_TIMESTEP_SEC*0.5;I=E+O*i.SOLVER_TIMESTEP_SEC*0.5;t=I;w=(D*(this._endValue-K))-y*I;K=N+t*i.SOLVER_TIMESTEP_SEC*0.5;I=E+w*i.SOLVER_TIMESTEP_SEC*0.5;F=I;A=(D*(this._endValue-K))-y*I;M=1/6*(u+2*(G+t)+F);J=1/6*(L+2*(O+w)+A);N+=M*i.SOLVER_TIMESTEP_SEC;E+=J*i.SOLVER_TIMESTEP_SEC}this._tempState.position=K;this._tempState.velocity=I;this._currentState.position=N;this._currentState.velocity=E;if(this._timeAccumulator>0){this.interpolate(this._timeAccumulator/i.SOLVER_TIMESTEP_SEC)}if(this.isAtRest()||this._overshootClampingEnabled&&this.isOvershooting()){if(this._springConfig.tension>0){this._startValue=this._endValue;this._currentState.position=this._endValue}else{this._endValue=this._currentState.position;this._startValue=this._endValue}this.setVelocity(0);H=true}var v=false;if(this._wasAtRest){this._wasAtRest=false;v=true}var C=false;if(H){this._wasAtRest=true;C=true}this.notifyPositionUpdated(v,C)},notifyPositionUpdated:function(u,v){for(var w=0,t=this.listeners.length;w<t;w++){var x=this.listeners[w];if(u&&x.onSpringActivate){x.onSpringActivate(this)}if(x.onSpringUpdate){x.onSpringUpdate(this)}if(v&&x.onSpringAtRest){x.onSpringAtRest(this)}}},systemShouldAdvance:function(){return !this.isAtRest()||!this.wasAtRest()},wasAtRest:function(){return this._wasAtRest},isAtRest:function(){return Math.abs(this._currentState.velocity)<this._restSpeedThreshold&&(this.getDisplacementDistanceForState(this._currentState)<=this._displacementFromRestThreshold||this._springConfig.tension===0)},setAtRest:function(){this._endValue=this._currentState.position;this._tempState.position=this._currentState.position;this._currentState.velocity=0;return this},interpolate:function(t){this._currentState.position=this._currentState.position*t+this._previousState.position*(1-t);this._currentState.velocity=this._currentState.velocity*t+this._previousState.velocity*(1-t)},getListeners:function(){return this.listeners},addListener:function(t){this.listeners.push(t);return this},removeListener:function(t){f(this.listeners,t);return this},removeAllListeners:function(){this.listeners=[];return this},currentValueIsApproximately:function(t){return Math.abs(this.getCurrentValue()-t)<=this.getRestDisplacementThreshold()}});var p=function p(){};a.extend(p.prototype,{position:0,velocity:0});var c=k.SpringConfig=function c(t,u){this.tension=t;this.friction=u};var g=k.AnimationLooper=function g(){this.springSystem=null;var u=this;var t=function(){u.springSystem.loop(Date.now())};this.run=function(){a.onFrame(t)}};var j=k.SimulationLooper=function j(t){this.springSystem=null;var v=0;var u=false;t=t||16.667;this.run=function(){if(u){return}u=true;while(!this.springSystem.getIsIdle()){this.springSystem.loop(v+=t)}u=false}};var n=k.SteppingSimulationLooper=function(t){this.springSystem=null;var v=0;var u=false;this.run=function(){};this.step=function(w){this.springSystem.loop(v+=w)}};var r=k.OrigamiValueConverter={tensionFromOrigamiValue:function(t){return(t-30)*3.62+194},origamiValueFromTension:function(t){return(t-194)/3.62+30},frictionFromOrigamiValue:function(t){return(t-8)*3+25},origamiFromFriction:function(t){return(t-25)/3+8}};a.extend(c,{fromOrigamiTensionAndFriction:function(t,u){return new c(r.tensionFromOrigamiValue(t),r.frictionFromOrigamiValue(u))},coastingConfigWithOrigamiFriction:function(t){return new c(0,r.frictionFromOrigamiValue(t))}});c.DEFAULT_ORIGAMI_SPRING_CONFIG=c.fromOrigamiTensionAndFriction(40,7);a.extend(c.prototype,{friction:0,tension:0});var h={};a.hexToRGB=function(t){if(h[t]){return h[t]}t=t.replace("#","");if(t.length===3){t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]}var u=t.match(/.{2}/g);var t={r:parseInt(u[0],16),g:parseInt(u[1],16),b:parseInt(u[2],16)};h[t]=t;return t};a.rgbToHex=function(v,u,t){v=v.toString(16);u=u.toString(16);t=t.toString(16);v=v.length<2?"0"+v:v;u=u.length<2?"0"+u:u;t=t.length<2?"0"+t:t;return"#"+v+u+t};var q=k.MathUtil={mapValueInRange:function(z,v,A,y,x){var w=A-v;var t=x-y;var u=(z-v)/w;return y+(u*t)},interpolateColor:function(u,x,v,B,z,A){B=typeof B==="undefined"?0:B;z=typeof z==="undefined"?1:z;var x=a.hexToRGB(x);var v=a.hexToRGB(v);var t=Math.floor(a.mapValueInRange(u,B,z,x.r,v.r));var w=Math.floor(a.mapValueInRange(u,B,z,x.g,v.g));var y=Math.floor(a.mapValueInRange(u,B,z,x.b,v.b));if(A){return"rgb("+t+","+w+","+y+")"}else{return a.rgbToHex(t,w,y)}},degreesToRadians:function(t){return(t*Math.PI)/180},radiansToDegrees:function(t){return(t*180)/Math.PI}};a.extend(a,q);function f(v,u){var t=v.indexOf(u);t!=-1&&v.splice(t,1)}var l;if(typeof process!=="undefined"&&process.title==="node"){l=setImmediate}if(typeof l==="undefined"){l=window&&window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame}a.onFrame=function b(t){return l(t)};if(typeof exports!="undefined"){a.extend(exports,k)}else{if(typeof window!="undefined"){window.rebound=k}}})();
!function(){function a(a,b){var c=a.indexOf(b);-1!=c&&a.splice(c,1)}var b={},c=b.util={},d=Array.prototype.concat,e=Array.prototype.slice;c.bind=function(a,b){var c=e.call(arguments,2);return function(){a.apply(b,d.call(c,e.call(arguments)))}},c.extend=function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])};var f=b.SpringSystem=function(a){this._springRegistry={},this._activeSprings=[],this.listeners=[],this._idleSpringIndices=[],this.looper=a||new j,this.looper.springSystem=this};c.extend(f.prototype,{_springRegistry:null,_isIdle:!0,_lastTimeMillis:-1,_activeSprings:null,listeners:null,_idleSpringIndices:null,setLooper:function(a){this.looper=a,a.springSystem=this},createSpring:function(a,b){var c;return c=void 0===a||void 0===b?i.DEFAULT_ORIGAMI_SPRING_CONFIG:i.fromOrigamiTensionAndFriction(a,b),this.createSpringWithConfig(c)},createSpringWithBouncinessAndSpeed:function(a,b){var c;return c=void 0===a||void 0===b?i.DEFAULT_ORIGAMI_SPRING_CONFIG:i.fromBouncinessAndSpeed(a,b),this.createSpringWithConfig(c)},createSpringWithConfig:function(a){var b=new g(this);return this.registerSpring(b),b.setSpringConfig(a),b},getIsIdle:function(){return this._isIdle},getSpringById:function(a){return this._springRegistry[a]},getAllSprings:function(){var a=[];for(var b in this._springRegistry)this._springRegistry.hasOwnProperty(b)&&a.push(this._springRegistry[b]);return a},registerSpring:function(a){this._springRegistry[a.getId()]=a},deregisterSpring:function(b){a(this._activeSprings,b),delete this._springRegistry[b.getId()]},advance:function(a,b){for(;this._idleSpringIndices.length>0;)this._idleSpringIndices.pop();for(var c=0,d=this._activeSprings.length;d>c;c++){var e=this._activeSprings[c];e.systemShouldAdvance()?e.advance(a/1e3,b/1e3):this._idleSpringIndices.push(this._activeSprings.indexOf(e))}for(;this._idleSpringIndices.length>0;){var f=this._idleSpringIndices.pop();f>=0&&this._activeSprings.splice(f,1)}},loop:function(a){var b;-1===this._lastTimeMillis&&(this._lastTimeMillis=a-1);var c=a-this._lastTimeMillis;this._lastTimeMillis=a;var d=0,e=this.listeners.length;for(d=0;e>d;d++)b=this.listeners[d],b.onBeforeIntegrate&&b.onBeforeIntegrate(this);for(this.advance(a,c),0===this._activeSprings.length&&(this._isIdle=!0,this._lastTimeMillis=-1),d=0;e>d;d++)b=this.listeners[d],b.onAfterIntegrate&&b.onAfterIntegrate(this);this._isIdle||this.looper.run()},activateSpring:function(a){var b=this._springRegistry[a];-1==this._activeSprings.indexOf(b)&&this._activeSprings.push(b),this.getIsIdle()&&(this._isIdle=!1,this.looper.run())},addListener:function(a){this.listeners.push(a)},removeListener:function(b){a(this.listeners,b)},removeAllListeners:function(){this.listeners=[]}});var g=b.Spring=function p(a){this._id="s"+p._ID++,this._springSystem=a,this.listeners=[],this._currentState=new h,this._previousState=new h,this._tempState=new h};c.extend(g,{_ID:0,MAX_DELTA_TIME_SEC:.064,SOLVER_TIMESTEP_SEC:.001}),c.extend(g.prototype,{_id:0,_springConfig:null,_overshootClampingEnabled:!1,_currentState:null,_previousState:null,_tempState:null,_startValue:0,_endValue:0,_wasAtRest:!0,_restSpeedThreshold:.001,_displacementFromRestThreshold:.001,listeners:null,_timeAccumulator:0,_springSystem:null,destroy:function(){this.listeners=[],this.frames=[],this._springSystem.deregisterSpring(this)},getId:function(){return this._id},setSpringConfig:function(a){return this._springConfig=a,this},getSpringConfig:function(){return this._springConfig},setCurrentValue:function(a,b){return this._startValue=a,this._currentState.position=a,b||this.setAtRest(),this.notifyPositionUpdated(!1,!1),this},getStartValue:function(){return this._startValue},getCurrentValue:function(){return this._currentState.position},getCurrentDisplacementDistance:function(){return this.getDisplacementDistanceForState(this._currentState)},getDisplacementDistanceForState:function(a){return Math.abs(this._endValue-a.position)},setEndValue:function(a){if(this._endValue==a&&this.isAtRest())return this;this._startValue=this.getCurrentValue(),this._endValue=a,this._springSystem.activateSpring(this.getId());for(var b=0,c=this.listeners.length;c>b;b++){var d=this.listeners[b],e=d.onSpringEndStateChange;e&&e(this)}return this},getEndValue:function(){return this._endValue},setVelocity:function(a){return a===this._currentState.velocity?this:(this._currentState.velocity=a,this._springSystem.activateSpring(this.getId()),this)},getVelocity:function(){return this._currentState.velocity},setRestSpeedThreshold:function(a){return this._restSpeedThreshold=a,this},getRestSpeedThreshold:function(){return this._restSpeedThreshold},setRestDisplacementThreshold:function(a){this._displacementFromRestThreshold=a},getRestDisplacementThreshold:function(){return this._displacementFromRestThreshold},setOvershootClampingEnabled:function(a){return this._overshootClampingEnabled=a,this},isOvershootClampingEnabled:function(){return this._overshootClampingEnabled},isOvershooting:function(){var a=this._startValue,b=this._endValue;return this._springConfig.tension>0&&(b>a&&this.getCurrentValue()>b||a>b&&this.getCurrentValue()<b)},advance:function(a,b){var c=this.isAtRest();if(!c||!this._wasAtRest){var d=b;b>g.MAX_DELTA_TIME_SEC&&(d=g.MAX_DELTA_TIME_SEC),this._timeAccumulator+=d;for(var e,f,h,i,j,k,l,m,n,o,p=this._springConfig.tension,q=this._springConfig.friction,r=this._currentState.position,s=this._currentState.velocity,t=this._tempState.position,u=this._tempState.velocity;this._timeAccumulator>=g.SOLVER_TIMESTEP_SEC;)this._timeAccumulator-=g.SOLVER_TIMESTEP_SEC,this._timeAccumulator<g.SOLVER_TIMESTEP_SEC&&(this._previousState.position=r,this._previousState.velocity=s),e=s,f=p*(this._endValue-t)-q*s,t=r+e*g.SOLVER_TIMESTEP_SEC*.5,u=s+f*g.SOLVER_TIMESTEP_SEC*.5,h=u,i=p*(this._endValue-t)-q*u,t=r+h*g.SOLVER_TIMESTEP_SEC*.5,u=s+i*g.SOLVER_TIMESTEP_SEC*.5,j=u,k=p*(this._endValue-t)-q*u,t=r+j*g.SOLVER_TIMESTEP_SEC*.5,u=s+k*g.SOLVER_TIMESTEP_SEC*.5,l=u,m=p*(this._endValue-t)-q*u,n=1/6*(e+2*(h+j)+l),o=1/6*(f+2*(i+k)+m),r+=n*g.SOLVER_TIMESTEP_SEC,s+=o*g.SOLVER_TIMESTEP_SEC;this._tempState.position=t,this._tempState.velocity=u,this._currentState.position=r,this._currentState.velocity=s,this._timeAccumulator>0&&this.interpolate(this._timeAccumulator/g.SOLVER_TIMESTEP_SEC),(this.isAtRest()||this._overshootClampingEnabled&&this.isOvershooting())&&(this._springConfig.tension>0?(this._startValue=this._endValue,this._currentState.position=this._endValue):(this._endValue=this._currentState.position,this._startValue=this._endValue),this.setVelocity(0),c=!0);var v=!1;this._wasAtRest&&(this._wasAtRest=!1,v=!0);var w=!1;c&&(this._wasAtRest=!0,w=!0),this.notifyPositionUpdated(v,w)}},notifyPositionUpdated:function(a,b){for(var c=0,d=this.listeners.length;d>c;c++){var e=this.listeners[c];a&&e.onSpringActivate&&e.onSpringActivate(this),e.onSpringUpdate&&e.onSpringUpdate(this),b&&e.onSpringAtRest&&e.onSpringAtRest(this)}},systemShouldAdvance:function(){return!this.isAtRest()||!this.wasAtRest()},wasAtRest:function(){return this._wasAtRest},isAtRest:function(){return Math.abs(this._currentState.velocity)<this._restSpeedThreshold&&(this.getDisplacementDistanceForState(this._currentState)<=this._displacementFromRestThreshold||0===this._springConfig.tension)},setAtRest:function(){return this._endValue=this._currentState.position,this._tempState.position=this._currentState.position,this._currentState.velocity=0,this},interpolate:function(a){this._currentState.position=this._currentState.position*a+this._previousState.position*(1-a),this._currentState.velocity=this._currentState.velocity*a+this._previousState.velocity*(1-a)},getListeners:function(){return this.listeners},addListener:function(a){return this.listeners.push(a),this},removeListener:function(b){return a(this.listeners,b),this},removeAllListeners:function(){return this.listeners=[],this},currentValueIsApproximately:function(a){return Math.abs(this.getCurrentValue()-a)<=this.getRestDisplacementThreshold()}});var h=function(){};c.extend(h.prototype,{position:0,velocity:0});var i=b.SpringConfig=function(a,b){this.tension=a,this.friction=b},j=b.AnimationLooper=function(){this.springSystem=null;var a=this,b=function(){a.springSystem.loop(Date.now())};this.run=function(){c.onFrame(b)}};b.SimulationLooper=function(a){this.springSystem=null;var b=0,c=!1;a=a||16.667,this.run=function(){if(!c){for(c=!0;!this.springSystem.getIsIdle();)this.springSystem.loop(b+=a);c=!1}}},b.SteppingSimulationLooper=function(){this.springSystem=null;var a=0;this.run=function(){},this.step=function(b){this.springSystem.loop(a+=b)}};var k=b.OrigamiValueConverter={tensionFromOrigamiValue:function(a){return 3.62*(a-30)+194},origamiValueFromTension:function(a){return(a-194)/3.62+30},frictionFromOrigamiValue:function(a){return 3*(a-8)+25},origamiFromFriction:function(a){return(a-25)/3+8}},l=b.BouncyConversion=function(a,b){this.bounciness=a,this.speed=b;var c=this.normalize(a/1.7,0,20);c=this.projectNormal(c,0,.8);var d=this.normalize(b/1.7,0,20);this.bouncyTension=this.projectNormal(d,.5,200),this.bouncyFriction=this.quadraticOutInterpolation(c,this.b3Nobounce(this.bouncyTension),.01)};c.extend(l.prototype,{normalize:function(a,b,c){return(a-b)/(c-b)},projectNormal:function(a,b,c){return b+a*(c-b)},linearInterpolation:function(a,b,c){return a*c+(1-a)*b},quadraticOutInterpolation:function(a,b,c){return this.linearInterpolation(2*a-a*a,b,c)},b3Friction1:function(a){return 7e-4*Math.pow(a,3)-.031*Math.pow(a,2)+.64*a+1.28},b3Friction2:function(a){return 44e-6*Math.pow(a,3)-.006*Math.pow(a,2)+.36*a+2},b3Friction3:function(a){return 4.5e-7*Math.pow(a,3)-332e-6*Math.pow(a,2)+.1078*a+5.84},b3Nobounce:function(a){var b=0;return b=18>=a?this.b3Friction1(a):a>18&&44>=a?this.b3Friction2(a):this.b3Friction3(a)}}),c.extend(i,{fromOrigamiTensionAndFriction:function(a,b){return new i(k.tensionFromOrigamiValue(a),k.frictionFromOrigamiValue(b))},fromBouncinessAndSpeed:function(a,c){var d=new b.BouncyConversion(a,c);return this.fromOrigamiTensionAndFriction(d.bouncyTension,d.bouncyFriction)},coastingConfigWithOrigamiFriction:function(a){return new i(0,k.frictionFromOrigamiValue(a))}}),i.DEFAULT_ORIGAMI_SPRING_CONFIG=i.fromOrigamiTensionAndFriction(40,7),c.extend(i.prototype,{friction:0,tension:0});var m={};c.hexToRGB=function(a){if(m[a])return m[a];a=a.replace("#",""),3===a.length&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]);var b=a.match(/.{2}/g),c={r:parseInt(b[0],16),g:parseInt(b[1],16),b:parseInt(b[2],16)};return m[a]=c,c},c.rgbToHex=function(a,b,c){return a=a.toString(16),b=b.toString(16),c=c.toString(16),a=a.length<2?"0"+a:a,b=b.length<2?"0"+b:b,c=c.length<2?"0"+c:c,"#"+a+b+c};var n=b.MathUtil={mapValueInRange:function(a,b,c,d,e){var f=c-b,g=e-d,h=(a-b)/f;return d+h*g},interpolateColor:function(a,b,d,e,f,g){e=void 0===e?0:e,f=void 0===f?1:f,b=c.hexToRGB(b),d=c.hexToRGB(d);var h=Math.floor(c.mapValueInRange(a,e,f,b.r,d.r)),i=Math.floor(c.mapValueInRange(a,e,f,b.g,d.g)),j=Math.floor(c.mapValueInRange(a,e,f,b.b,d.b));return g?"rgb("+h+","+i+","+j+")":c.rgbToHex(h,i,j)},degreesToRadians:function(a){return a*Math.PI/180},radiansToDegrees:function(a){return 180*a/Math.PI}};c.extend(c,n);var o;"undefined"!=typeof window&&(o=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame),o||"undefined"==typeof process||"node"!==process.title||(o=setImmediate),c.onFrame=function(a){return o(a)},"undefined"!=typeof exports?c.extend(exports,b):"undefined"!=typeof window&&(window.rebound=b)}();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc