nanotween
Advanced tools
Comparing version 0.4.9 to 0.5.0
@@ -1,1 +0,1 @@ | ||
var NanoTween=function(){function e(e,t){return e(t={exports:{}},t.exports),t.exports}var t=e(function(e){if("undefined"==typeof window&&"undefined"!=typeof process){function t(){var e=process.hrtime();return 1e9*e[0]+e[1]}var n=1e9*process.uptime(),r=t()-n;e.exports=function(){return(t()-r)/1e6}}else if("undefined"!=typeof window&&void 0!==window.performance&&void 0!==window.performance.now)e.exports=window.performance.now.bind(window.performance);else{r=Date.now();e.exports=function(){return Date.now()-r}}}),n=e(function(e){(e.exports=function(){this.events={}}).prototype={on:function(e,t){return(e=this.events[e]=this.events[e]||[]).push(t),function(){e.splice(e.indexOf(t)>>>0,1)}},emit:function(e){var t=this.events[e];if(t&&t[0]){var n=t.slice.call(arguments,1);t.slice().map(function(e){e.apply(this,n)})}}}}),r=0,s=[];function i(){var e=this,t={id:s.length,delay:0,repeats:1,duration:0,easing:function(e){return e},converters:[]};function r(){return{progress:e.state.progress,value:e.state.value,remaining:e.state.repeats+1,completed:t.repeats-e.state.repeats-1}}function i(n){e.state.progress=n;var r=t.easing;r.reverse=r.reverse||r;var s=e.state.reversed?1-r.reverse(e.state.progress):r(e.state.progress);e.state.value=t.converters.reduce(function(e,t){return t(e)},s),e.bus.emit("update",e.state.value)}e.state={isRunning:!1,current:void 0,progress:0,reversed:!1,repeats:0},e.bus=new n,s.push(e),e.use=function(t){return t(e),e},e.easing=function(n){return t.easing=n,e},e.duration=function(n){return t.duration=n,e},e.delay=function(n){return t.delay=n,e},e.repeat=function(n){return t.repeats=n,e},e.reverse=function(t){return e.state.reversed=void 0!==t?t:!e.state.reversed,e.state.progress=1-e.state.progress,e},e.on=function(t,n){return e.bus.on(t,n),e},e.convert=function(n){return t.converters.push(n),e},e.set=function(t){if(t>1){var n=Math.floor(t);if(e.complete(n),!e.state.isRunning)return;i(t-n)}else i(t);return e},e.tick=function(n){e.set(e.state.progress+n/t.duration)},e.start=function(){return e._i=setTimeout(function(){e.set(0),e.state.repeats=t.repeats-1,e.state.isRunning=!0,e.bus.emit("start")},t.delay),e},e.stop=function(){return e.set(1),e.state.repeats=0,e.state.isRunning=!1,e.bus.emit("stop"),e},e.complete=function(t){i(1);for(var n=e.state.repeats<t,r=n?e.state.repeats:t;r>0;)e.state.repeats--,e.bus.emit("step",r),r--;return n&&(e.state.isRunning=!1,e.bus.emit("complete")),e},e.play=function(){return e.state.isRunning=!0,e.bus.emit("play",r()),e},e.pause=function(){return e.state.isRunning=!1,e.bus.emit("pause",r()),e}}return i.update=function(){if(!document.hidden){var e=t();s.forEach(function(t){t.state.isRunning&&t.tick(e-r)}),r=e}},i}(); | ||
var NanoTween=function(){var e,t=(function(e){(e.exports=function(){this.events={}}).prototype={on:function(e,t){return(e=this.events[e]=this.events[e]||[]).push(t),function(){e.splice(e.indexOf(t)>>>0,1)}},emit:function(e){var t=this.events[e];if(t&&t[0]){var n=t.slice.call(arguments,1);t.slice().map(function(e){e.apply(this,n)})}}}}(e={exports:{}},e.exports),e.exports),n=0,s=[];function r(){var e=this,n={id:s.length,delay:0,repeats:1,duration:0,easing:function(e){return e},converters:[]};function r(){return{progress:e.state.progress,value:e.state.value,remaining:e.state.repeats+1,completed:n.repeats-e.state.repeats-1}}function u(t){e.state.progress=t;var s=n.easing;s.reverse=s.reverse||s;var r=e.state.reversed?1-s.reverse(e.state.progress):s(e.state.progress);e.state.value=n.converters.reduce(function(e,t){return t(e)},r),e.bus.emit("update",e.state.value)}e.state={isRunning:!1,current:void 0,progress:0,reversed:!1,repeats:0},e.bus=new t,s.push(e),e.use=function(t){return t(e),e},e.easing=function(t){return n.easing=t,e},e.duration=function(t){return n.duration=t,e},e.delay=function(t){return n.delay=t,e},e.repeat=function(t){return n.repeats=t,e},e.reverse=function(t){return e.state.reversed=void 0!==t?t:!e.state.reversed,e.state.progress=1-e.state.progress,e},e.on=function(t,n){return e.bus.on(t,n),e},e.convert=function(t){return n.converters.push(t),e},e.set=function(t){if(t>1){var n=Math.floor(t);if(e.complete(n),!e.state.isRunning)return;u(t-n)}else u(t);return e},e.tick=function(t){e.set(e.state.progress+t/n.duration)},e.start=function(){return e._i=setTimeout(function(){e.set(0),e.state.repeats=n.repeats-1,e.state.isRunning=!0,e.bus.emit("start")},n.delay),e},e.stop=function(){return e.set(1),e.state.repeats=0,e.state.isRunning=!1,e.bus.emit("stop"),e},e.complete=function(t){u(1);for(var n=e.state.repeats<t,s=n?e.state.repeats:t;s>0;)e.state.repeats--,e.bus.emit("step",s),s--;return n&&(e.state.isRunning=!1,e.bus.emit("complete")),e},e.play=function(){return e.state.isRunning=!0,e.bus.emit("play",r()),e},e.pause=function(){return e.state.isRunning=!1,e.bus.emit("pause",r()),e}}return r.update=function(e){document.hidden||(s.forEach(function(t){t.state.isRunning&&t.tick(e-n)}),n=e)},r}(); |
@@ -1,2 +0,1 @@ | ||
import uptime from 'nanouptime' | ||
import NanoEvents from 'nanoevents' | ||
@@ -159,5 +158,4 @@ | ||
Tween.update = function() { | ||
Tween.update = function(now) { | ||
if (document.hidden) return | ||
var now = uptime() | ||
tweens.forEach(function(tween) { | ||
@@ -164,0 +162,0 @@ if (tween.state.isRunning) { |
{ | ||
"name": "nanotween", | ||
"version": "0.4.9", | ||
"version": "0.5.0", | ||
"description": "Tiny library for tweening", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"path": "./index.js", | ||
"limit": "1.5 KB" | ||
"limit": "1 KB" | ||
}, | ||
@@ -55,3 +55,2 @@ { | ||
"jest": "^22.0.4", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.53.3", | ||
@@ -65,5 +64,4 @@ "rollup-plugin-commonjs": "^8.2.6", | ||
"dependencies": { | ||
"nanoevents": "^1.0.2", | ||
"nanouptime": "^0.1.0" | ||
"nanoevents": "^1.0.2" | ||
} | ||
} |
# NanoTween | ||
1.5 KB is quite enough for full-featured and comfortable tweening | ||
![image](https://user-images.githubusercontent.com/4208480/34745457-a234e4b4-f5a1-11e7-8565-920006935cb4.png) | ||
@@ -9,12 +8,18 @@ ## Is it small enough? | ||
I made some researches with [bundlephobia](https://bundlephobia.com) and [size-limit](https://github.com/ai/size-limit) and here's what I can say | ||
> **For now, NanoTween is the smallest tweening library on NPM** | ||
> **For now, NanoTween core is the smallest tweening core on NPM** | ||
``` | ||
library ¦ size | ||
-----------¦------- | ||
gsap ¦ 37 KB | ||
moofx ¦ 7.4 KB | ||
es6-tween ¦ 6.0 KB | ||
animejs ¦ 5.7 KB | ||
kute ¦ 5.6 KB | ||
tweenr ¦ 4.7 KB | ||
shifty ¦ 4.2 KB | ||
kute ¦ 3.4 KB | ||
tweenjs ¦ 2.9 KB | ||
tweeno ¦ 2.8 KB | ||
nanotween ¦ 1.6 KB | ||
anim ¦ 1.1 KB | ||
nanotween ¦ 754 B | ||
``` | ||
@@ -31,3 +36,3 @@ ## Included features | ||
* Ultra small size (only **<1.5KB** core, **2KB** with all helpers, **<3KB** with all easings) | ||
* Ultra small size (only **<1KB** core, **1.5KB** with **all** helpers, **<2.5KB** with **all** easings) | ||
* Low-level API lets you easily adapt it to your needs | ||
@@ -34,0 +39,0 @@ * Big list of ready-to-use easing functions |
25531
1
14
46
89
515
- Removednanouptime@^0.1.0
- Removednanouptime@0.1.0(transitive)