nanotween
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -1,7 +0,9 @@ | ||
function group(tweens) { | ||
function Chain(tweens) { | ||
var self = this; | ||
this.current = 0; | ||
var evts = { start: [], stop: [], step: [], complete: [] }; | ||
var evts = { start: [], stop: [], step: [], update: [], complete: [] }; | ||
this.on = function(evt, cb) { | ||
self.current = 0; | ||
self.tweens = tweens; | ||
self.on = function(evt, cb) { | ||
evts[evt].push(cb); | ||
@@ -11,15 +13,16 @@ return this | ||
this.start = function() { | ||
self.start = function() { | ||
self.stop(); | ||
tweens[0].start(); | ||
}; | ||
this.stop = function() { | ||
self.stop = function() { | ||
tweens[self.current].stop(); | ||
}; | ||
this.play = function() { | ||
self.play = function() { | ||
tweens[self.current].play(); | ||
}; | ||
this.pause = function() { | ||
self.pause = function() { | ||
tweens[self.current].pause(); | ||
@@ -51,2 +54,17 @@ }; | ||
}) | ||
.on('play', function(meta) { | ||
evts.play.forEach(function(cb) { | ||
cb(meta, index); | ||
}); | ||
}) | ||
.on('pause', function(meta) { | ||
evts.pause.forEach(function(cb) { | ||
cb(meta, index); | ||
}); | ||
}) | ||
.on('update', function(meta) { | ||
evts.update.forEach(function(cb) { | ||
cb(meta, index); | ||
}); | ||
}) | ||
.on('complete', function() { | ||
@@ -63,2 +81,2 @@ if (index !== tweens.length - 1) { | ||
module.exports = group; | ||
module.exports = Chain; |
@@ -1,16 +0,15 @@ | ||
function fromTo(from, to) { | ||
function def(from, to, k) { | ||
return from + (to - from) * k | ||
} | ||
function fromTo(from, to, cb) { | ||
return function(instance) { | ||
var fn = function(k) { | ||
switch (typeof from) { | ||
case 'number': | ||
return from + (to - from) * k | ||
case 'object': | ||
return Object.keys.reduce(function(acc, key) { | ||
acc[key] = fromTo(from[key], to[key]); | ||
}, {}) | ||
default: | ||
return from | ||
} | ||
return typeof from === 'object' | ||
? Object.keys(from).reduce(function(acc, key) { | ||
acc[key] = fromTo(from[key], to[key]); | ||
}, {}) | ||
: (cb || def)(from, to, k) | ||
}; | ||
instance.enhance(fn); | ||
instance.convert(fn); | ||
} | ||
@@ -17,0 +16,0 @@ } |
@@ -1,3 +0,5 @@ | ||
function group(tweens) { | ||
var self = this;['start', 'stop', 'play', 'pause', 'complete'].forEach(function(method) { | ||
function Group(tweens) { | ||
var self = this; | ||
Object.keys(tweens[0]).forEach(function(method) { | ||
if (typeof method !== 'function') return | ||
self[method] = function() { | ||
@@ -8,7 +10,8 @@ var args = arguments; | ||
}); | ||
return self | ||
}; | ||
}); | ||
return self | ||
self.tweens = tweens; | ||
} | ||
module.exports = group; | ||
module.exports = Group; |
@@ -1,7 +0,9 @@ | ||
export default function group(tweens) { | ||
export default function Chain(tweens) { | ||
var self = this | ||
this.current = 0 | ||
var evts = { start: [], stop: [], step: [], complete: [] } | ||
var evts = { start: [], stop: [], step: [], update: [], complete: [] } | ||
this.on = function(evt, cb) { | ||
self.current = 0 | ||
self.tweens = tweens | ||
self.on = function(evt, cb) { | ||
evts[evt].push(cb) | ||
@@ -11,15 +13,16 @@ return this | ||
this.start = function() { | ||
self.start = function() { | ||
self.stop() | ||
tweens[0].start() | ||
} | ||
this.stop = function() { | ||
self.stop = function() { | ||
tweens[self.current].stop() | ||
} | ||
this.play = function() { | ||
self.play = function() { | ||
tweens[self.current].play() | ||
} | ||
this.pause = function() { | ||
self.pause = function() { | ||
tweens[self.current].pause() | ||
@@ -51,2 +54,17 @@ } | ||
}) | ||
.on('play', function(meta) { | ||
evts.play.forEach(function(cb) { | ||
cb(meta, index) | ||
}) | ||
}) | ||
.on('pause', function(meta) { | ||
evts.pause.forEach(function(cb) { | ||
cb(meta, index) | ||
}) | ||
}) | ||
.on('update', function(meta) { | ||
evts.update.forEach(function(cb) { | ||
cb(meta, index) | ||
}) | ||
}) | ||
.on('complete', function() { | ||
@@ -53,0 +71,0 @@ if (index !== tweens.length - 1) { |
@@ -1,17 +0,16 @@ | ||
export default function fromTo(from, to) { | ||
function def(from, to, k) { | ||
return from + (to - from) * k | ||
} | ||
export default function fromTo(from, to, cb) { | ||
return function(instance) { | ||
var fn = function(k) { | ||
switch (typeof from) { | ||
case 'number': | ||
return from + (to - from) * k | ||
case 'object': | ||
return Object.keys.reduce(function(acc, key) { | ||
acc[key] = fromTo(from[key], to[key]) | ||
}, {}) | ||
default: | ||
return from | ||
} | ||
return typeof from === 'object' | ||
? Object.keys(from).reduce(function(acc, key) { | ||
acc[key] = fromTo(from[key], to[key]) | ||
}, {}) | ||
: (cb || def)(from, to, k) | ||
} | ||
instance.enhance(fn) | ||
instance.convert(fn) | ||
} | ||
} |
@@ -1,4 +0,5 @@ | ||
export default function group(tweens) { | ||
export default function Group(tweens) { | ||
var self = this | ||
;['start', 'stop', 'play', 'pause', 'complete'].forEach(function(method) { | ||
Object.keys(tweens[0]).forEach(function(method) { | ||
if (typeof method !== 'function') return | ||
self[method] = function() { | ||
@@ -9,5 +10,6 @@ var args = arguments | ||
}) | ||
return self | ||
} | ||
}) | ||
return self | ||
self.tweens = tweens | ||
} |
export { default as yoyo } from './yoyo' | ||
export { default as chain } from './chain' | ||
export { default as group } from './group' | ||
export { default as Chain } from './chain' | ||
export { default as Group } from './group' |
{ | ||
"name": "nanotween", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Tiny library for tweening", | ||
@@ -11,3 +11,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "size-limit && rollup -c", | ||
"build": "node size-limit.js && rollup -c", | ||
"lint": "eslint src/*.js test/*.js", | ||
@@ -27,7 +27,7 @@ "pretest": "npm run build", | ||
"path": "./helpers/chain.js", | ||
"limit": "250 B" | ||
"limit": "270 B" | ||
}, | ||
{ | ||
"path": "./helpers/group.js", | ||
"limit": "100 B" | ||
"limit": "110 B" | ||
}, | ||
@@ -40,3 +40,3 @@ { | ||
"path": "./helpers/fromTo.js", | ||
"limit": "150 B" | ||
"limit": "120 B" | ||
}, | ||
@@ -43,0 +43,0 @@ { |
29988
1056