es6-tween
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,0 +0,0 @@ (function webpackUniversalModuleDefinition(root, factory) { |
{ | ||
"name": "es6-tween", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/Tween.js", |
@@ -35,2 +35,6 @@ # es6-tween | ||
### CDN-Hosted version | ||
#### Using `unpkg` hosted version | ||
You can also reference a `unpkg`-hosted version in your code, thanks to <a href="https://unpkg.com/#/">unpkg</a>. For example: | ||
@@ -42,2 +46,11 @@ | ||
#### Using [@jsdelivr](https://github.com/jsdelivr) hosted version (coming soon) | ||
You can also reference a @jsdelivr-hosted version in your code, thanks to [@jsdelivr](https://github.com/jsdelivr). For example: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/es6-tween/latest/dist/Tween.min.js"></script> | ||
``` | ||
### More advanced users might want to... | ||
@@ -48,3 +61,3 @@ | ||
```javascript | ||
import TWEEN from './src/Tween'; | ||
import * as TWEEN from './node_modules/es6-tween/src/Tween'; | ||
``` | ||
@@ -51,0 +64,0 @@ |
@@ -7,2 +7,3 @@ // TWEEN.js | ||
let _tick; | ||
let _events = {}; | ||
@@ -13,3 +14,3 @@ const getAll = () => { | ||
const autoPlay = (state) => { | ||
const autoPlay = ( state ) => { | ||
_autoPlay = state; | ||
@@ -22,7 +23,7 @@ } | ||
const add = (tween) => { | ||
_tweens.push(tween); | ||
const add = ( tween ) => { | ||
_tweens.push( tween ); | ||
if (_autoPlay && !isStarted) { | ||
autoStart(now()); | ||
if ( _autoPlay && !isStarted ) { | ||
autoStart( now() ); | ||
isStarted = true; | ||
@@ -33,6 +34,56 @@ } | ||
const remove = (tween) => { | ||
_tweens.filter(tweens => tweens !== tween); | ||
const emit = ( ev, ...args ) { | ||
if ( _events[ ev ] !== undefined ) { | ||
_events[ ev ].map( event => event( ...args ) ); | ||
} | ||
} | ||
const off = ( ev, fn ) { | ||
if ( ev === undefined || _events[ ev ] === undefined ) { | ||
return; | ||
} | ||
if ( fn !== undefined ) { | ||
let eventsList = _events[ name ] | ||
, i = 0; | ||
while ( i < eventsList.length ) { | ||
if ( eventsList[ i ] === fn ) { | ||
eventsList.splice( i, 1 ); | ||
} | ||
i++ | ||
} | ||
} else { | ||
_events[ name ] = []; | ||
} | ||
} | ||
const on = ( ev, fn ) { | ||
if ( _events[ ev ] === undefined ) { | ||
_events[ ev ] = []; | ||
} | ||
_events[ ev ].push( fn ); | ||
} | ||
const once = ( ev, fn ) { | ||
if ( _events[ ev ] === undefined ) { | ||
_events[ ev ] = []; | ||
} | ||
on( ev, ( ...args ) => { | ||
fn( ...args ); | ||
off( ev ); | ||
} ); | ||
} | ||
const remove = ( tween ) => { | ||
_tweens.filter( tweens => tweens !== tween ); | ||
let i = 0 | ||
, tweenFind; | ||
while ( i < _tweens.length ) { | ||
tweenFind = _tweens[ i ]; | ||
if ( tweenFind === tween ) { | ||
_tweens.splice( i, 1 ); | ||
} | ||
i++ | ||
} | ||
} | ||
const now = () => { | ||
@@ -42,3 +93,3 @@ return _time; | ||
const update = (time, preserve) => { | ||
const update = ( time, preserve ) => { | ||
@@ -49,4 +100,6 @@ time = time !== undefined ? time : now(); | ||
if (_tweens.length === 0) { | ||
emit( 'update', time ); | ||
if ( _tweens.length === 0 ) { | ||
return false; | ||
@@ -56,9 +109,11 @@ | ||
emit( 'realupdate', time, _tweens ); | ||
let i = 0; | ||
while (i < _tweens.length) { | ||
while ( i < _tweens.length ) { | ||
if (_tweens[i].update(time) || preserve) { | ||
if ( _tweens[ i ].update( time ) || preserve ) { | ||
i++; | ||
} else { | ||
_tweens.splice(i, 1); | ||
_tweens.splice( i, 1 ); | ||
} | ||
@@ -71,12 +126,12 @@ | ||
function autoStart(time) { | ||
if (update(_time)) { | ||
function autoStart( time ) { | ||
if ( update( _time ) ) { | ||
_time = time; | ||
_tick = requestAnimationFrame(autoStart); | ||
_tick = requestAnimationFrame( autoStart ); | ||
} else { | ||
isStarted = false; | ||
cancelAnimationFrame(_tick); | ||
cancelAnimationFrame( _tick ); | ||
} | ||
} | ||
export { getAll, removeAll, remove, add, now, update, autoPlay }; | ||
export { getAll, removeAll, remove, add, now, update, autoPlay, on, once, off, emit }; |
@@ -11,5 +11,2 @@ import { | ||
class Tween { | ||
static createEmptyConst (oldObject) { | ||
return typeof(oldObject) === "number" ? 0 : Array.isArray(oldObject) ? [] : typeof(oldObject) === "object" ? {} : ''; | ||
} | ||
constructor( object = {} ) { | ||
@@ -44,2 +41,5 @@ | ||
} | ||
static createEmptyConst (oldObject) { | ||
return typeof(oldObject) === "number" ? 0 : Array.isArray(oldObject) ? [] : typeof(oldObject) === "object" ? {} : ''; | ||
} | ||
isPlaying() { | ||
@@ -87,8 +87,9 @@ return this._isPlaying; | ||
if ( name !== undefined && fn !== undefined ) { | ||
this._events[ name ].filter( event => { | ||
if ( event === fn ) { | ||
return false; | ||
let eventsList = this._events[ name ], i = 0; | ||
while (i < eventsList.length) { | ||
if ( eventsList[i] === fn ) { | ||
eventsList.splice(i, 1); | ||
} | ||
return true; | ||
} ); | ||
i++ | ||
} | ||
} else if ( name !== undefined && fn === undefined ) { | ||
@@ -95,0 +96,0 @@ this._events[ name ] = []; |
@@ -5,4 +5,2 @@ import "./shim/object_assign"; | ||
import "./shim/set"; | ||
import { getAll, add, removeAll, remove, update, autoPlay, now } from './dist/core'; | ||
@@ -9,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
335346
1732
179
20