tween.js
Advanced tools
Comparing version 16.3.4 to 16.3.5
{ | ||
"name": "tween.js", | ||
"description": "Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equations.", | ||
"version": "16.3.4", | ||
"version": "16.3.5", | ||
"main": "src/Tween.js", | ||
@@ -22,5 +22,5 @@ "homepage": "https://github.com/tweenjs/tween.js", | ||
"test": "npm run test-unit && npm run test-correctness && npm run test-style", | ||
"test-unit": "nodeunit $(pwd)/test/unit/nodeunitheadless.js", | ||
"test-correctness": "jshint --config $(pwd)/test/jshintrc $(pwd)/src/Tween.js", | ||
"test-style": "jscs --config $(pwd)/test/jscs.json $(pwd)/src/Tween.js", | ||
"test-unit": "nodeunit test/unit/nodeunitheadless.js", | ||
"test-correctness": "jshint --config test/jshintrc src/Tween.js", | ||
"test-style": "jscs --config test/jscs.json src/Tween.js", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
@@ -27,0 +27,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
# tween.js | ||
# tween.js | ||
@@ -70,3 +70,3 @@ JavaScript tweening engine for easy animations, incorporating optimised Robert Penner's equations. | ||
Then reference the library source: | ||
Then reference the library source: | ||
@@ -134,2 +134,3 @@ ```html | ||
[![A-Frame VR](http://tweenjs.github.io/tween.js/assets/projects/10_aframe.png)](https://aframe.io) | ||
[![MOMA Inventing Abstraction 1910-1925](http://tweenjs.github.io/tween.js/assets/projects/09_moma.png)](http://www.moma.org/interactives/exhibitions/2012/inventingabstraction/) | ||
@@ -136,0 +137,0 @@ [![Web Lab](http://tweenjs.github.io/tween.js/assets/projects/08_web_lab.png)](http://www.chromeweblab.com/) |
110
src/Tween.js
@@ -10,25 +10,2 @@ /** | ||
// Include a performance.now polyfill | ||
(function () { | ||
if ('performance' in window === false) { | ||
window.performance = {}; | ||
} | ||
// IE 8 | ||
Date.now = (Date.now || function () { | ||
return new Date().getTime(); | ||
}); | ||
if ('now' in window.performance === false) { | ||
var offset = window.performance.timing && window.performance.timing.navigationStart ? window.performance.timing.navigationStart | ||
: Date.now(); | ||
window.performance.now = function () { | ||
return Date.now() - offset; | ||
}; | ||
} | ||
})(); | ||
var TWEEN = TWEEN || (function () { | ||
@@ -68,3 +45,3 @@ | ||
update: function (time) { | ||
update: function (time, preserve) { | ||
@@ -77,7 +54,7 @@ if (_tweens.length === 0) { | ||
time = time !== undefined ? time : window.performance.now(); | ||
time = time !== undefined ? time : TWEEN.now(); | ||
while (i < _tweens.length) { | ||
if (_tweens[i].update(time)) { | ||
if (_tweens[i].update(time) || preserve) { | ||
i++; | ||
@@ -97,2 +74,36 @@ } else { | ||
// Include a performance.now polyfill | ||
(function () { | ||
// In node.js, use process.hrtime. | ||
if (this.window === undefined && this.process !== undefined) { | ||
TWEEN.now = function () { | ||
var time = process.hrtime(); | ||
// Convert [seconds, microseconds] to milliseconds. | ||
return time[0] * 1000 + time[1] / 1000; | ||
}; | ||
} | ||
// In a browser, use window.performance.now if it is available. | ||
else if (this.window !== undefined && | ||
window.performance !== undefined && | ||
window.performance.now !== undefined) { | ||
// This must be bound, because directly assigning this function | ||
// leads to an invocation exception in Chrome. | ||
TWEEN.now = window.performance.now.bind(window.performance); | ||
} | ||
// Use Date.now if it is available. | ||
else if (Date.now !== undefined) { | ||
TWEEN.now = Date.now; | ||
} | ||
// Otherwise, use 'new Date().getTime()'. | ||
else { | ||
TWEEN.now = function () { | ||
return new Date().getTime(); | ||
}; | ||
} | ||
})(); | ||
TWEEN.Tween = function (object) { | ||
@@ -145,3 +156,3 @@ | ||
_startTime = time !== undefined ? time : window.performance.now(); | ||
_startTime = time !== undefined ? time : TWEEN.now(); | ||
_startTime += _delayTime; | ||
@@ -324,3 +335,3 @@ | ||
if (end.startsWith('+') || end.startsWith('-')) { | ||
if (end.charAt(0) === '+' || end.charAt(0) === '-') { | ||
end = start + parseFloat(end, 10); | ||
@@ -606,6 +617,2 @@ } else { | ||
var s; | ||
var a = 0.1; | ||
var p = 0.4; | ||
if (k === 0) { | ||
@@ -619,11 +626,4 @@ return 0; | ||
if (!a || a < 1) { | ||
a = 1; | ||
s = p / 4; | ||
} else { | ||
s = p * Math.asin(1 / a) / (2 * Math.PI); | ||
} | ||
return -Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); | ||
return - (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p)); | ||
}, | ||
@@ -633,6 +633,2 @@ | ||
var s; | ||
var a = 0.1; | ||
var p = 0.4; | ||
if (k === 0) { | ||
@@ -646,11 +642,4 @@ return 0; | ||
if (!a || a < 1) { | ||
a = 1; | ||
s = p / 4; | ||
} else { | ||
s = p * Math.asin(1 / a) / (2 * Math.PI); | ||
} | ||
return Math.pow(2, -10 * k) * Math.sin((k - 0.1) * 5 * Math.PI) + 1; | ||
return (a * Math.pow(2, - 10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1); | ||
}, | ||
@@ -660,6 +649,2 @@ | ||
var s; | ||
var a = 0.1; | ||
var p = 0.4; | ||
if (k === 0) { | ||
@@ -673,14 +658,9 @@ return 0; | ||
if (!a || a < 1) { | ||
a = 1; | ||
s = p / 4; | ||
} else { | ||
s = p * Math.asin(1 / a) / (2 * Math.PI); | ||
} | ||
k *= 2; | ||
if ((k *= 2) < 1) { | ||
return - 0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p)); | ||
if (k < 1) { | ||
return -0.5 * Math.pow(2, 10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI); | ||
} | ||
return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1; | ||
return 0.5 * Math.pow(2, -10 * (k - 1)) * Math.sin((k - 1.1) * 5 * Math.PI) + 1; | ||
@@ -687,0 +667,0 @@ } |
152
23461
538