es6-tween
Advanced tools
Comparing version 3.5.9 to 3.6.0
@@ -8,32 +8,24 @@ (function (global, factory) { | ||
/* global global */ | ||
var root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this; | ||
var create = Object.create || function (source) { | ||
return Object.assign({}, source || {}) | ||
}; | ||
var assign = Object.assign || function (source) { | ||
var args = [], len$1 = arguments.length - 1; | ||
while ( len$1-- > 0 ) args[ len$1 ] = arguments[ len$1 + 1 ]; | ||
if (!Object.assign) { | ||
Object.assign = function (source) { | ||
var args = [], len$1 = arguments.length - 1; | ||
while ( len$1-- > 0 ) args[ len$1 ] = arguments[ len$1 + 1 ]; | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
var arg = args[i]; | ||
for (var p in arg) { | ||
source[p] = arg[p]; | ||
} | ||
} | ||
return source | ||
}; | ||
for (var i = 0, len = args.length; i < len; i++) { | ||
var arg = args[i]; | ||
for (var p in arg) { | ||
source[p] = arg[p]; | ||
} | ||
} | ||
return source | ||
}; | ||
} | ||
if (!Object.create) { | ||
Object.create = function (source) { | ||
return Object.assign({}, source || {}) | ||
}; | ||
} | ||
if (!Array.isArray) { | ||
Array.isArray = function (source) { return source && source.push && source.splice; }; | ||
} | ||
if (typeof (requestAnimationFrame) === 'undefined') { | ||
root.requestAnimationFrame = function (fn) { return root.setTimeout(fn, 16); }; | ||
} | ||
if (typeof (cancelAnimationFrame) === 'undefined') { | ||
root.cancelAnimationFrame = function (id) { return root.clearTimeout(id); }; | ||
} | ||
var root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this; | ||
var requestAnimationFrame = root.requestAnimationFrame || function (fn) { return root.setTimeout(fn, 16) }; | ||
var cancelAnimationFrame = root.cancelAnimationFrame || function (id) { return root.clearTimeout(id) }; | ||
@@ -45,4 +37,4 @@ /* global process */ | ||
var _tick; | ||
var _ticker = root.requestAnimationFrame; | ||
var _stopTicker = root.cancelAnimationFrame; | ||
var _ticker = requestAnimationFrame; | ||
var _stopTicker = cancelAnimationFrame; | ||
@@ -432,3 +424,2 @@ var add = function (tween) { | ||
* @license MIT-License | ||
* First Release at 20 August 2017, by @dalisoft | ||
*/ | ||
@@ -452,5 +443,6 @@ | ||
var numRegExp = | ||
/\s+|([A-Za-z?().,{}:""[\]#]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g; | ||
/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g; | ||
var hexColor = /^#([0-9a-f]{6}|[0-9a-f]{3})$/i; | ||
var trimRegExp = /\n|\r|\t/g; | ||
var colorSpaceExp = /, | ,| , /g; | ||
var rgbMax = 255; | ||
@@ -483,3 +475,3 @@ | ||
function trim(str) { | ||
return typeof str === "string" ? str.replace(trimRegExp, "") : str; | ||
return typeof str === "string" ? str.replace(trimRegExp, "").replace(colorSpaceExp, ',') : str; | ||
} | ||
@@ -520,3 +512,4 @@ var relativeModes = { | ||
function s2n(str) { | ||
return h2r(str).match(numRegExp).map(s2f); | ||
var hr = h2r(str); | ||
return typeof hr === 'string' ? hr.match(numRegExp).map(s2f) : str; | ||
} | ||
@@ -539,3 +532,5 @@ | ||
var rv = []; | ||
for (var i = 0, len = ev.length; i < len; i++) { | ||
var i = 0; | ||
var len = ev.length; | ||
for (; i < len; i++) { | ||
var ve = ev[i], | ||
@@ -551,7 +546,8 @@ vs = sv[i]; | ||
} | ||
ev[i] = vs === ve ? null : rv[i] !== null ? r2n(vs, ve) : typeof ve === 'number' ? ve - vs : ve; | ||
ev[i] = vs === ve ? null : rv[i] !== null ? r2n(vs, ve) : ve; | ||
} | ||
return function (t) { | ||
var str = ''; | ||
for (var i = 0, len = ev.length; i < len; i++) { | ||
i = 0; | ||
for (; i < len; i++) { | ||
var a = sv[i], | ||
@@ -561,7 +557,7 @@ b = ev[i], | ||
str += typeof b === 'number' ? cm !== null && i > cm && | ||
i < cmls ? (a + b * t) | 0 : (((a + b * t) * d) | | ||
i < cmls ? (a + ( b - a ) * t) | 0 : (((a + ( b - a ) * t) * d) | | ||
0) / d : a; | ||
if (t === 1 && r !== null) { | ||
sv[i] += b; | ||
ev[i] = r2n(sv[i], r); | ||
sv[i] = b; | ||
ev[i] = r2n(b, r); | ||
} | ||
@@ -581,3 +577,3 @@ } | ||
for (var i = 0, len = vs.length; i < len; i++) { | ||
sv[i] = vs[i](t); | ||
sv[i] = typeof vs[i] === 'function' ? vs[i](t) : typeof vs[i] === 'number' ? vs[i] + (ev - vs[i]) * t : vs[i]; | ||
} | ||
@@ -617,3 +613,3 @@ return sv; | ||
rv[i] = typeof ve === 'string' && ve.indexOf('=') === 1 ? ve : null; | ||
s[i] = ve.nodeType ? ve : ve.update ? ve : vs === ve ? null : isArray(ve) ? | ||
s[i] = ve.nodeType || ve.update ? ve.update : vs === ve ? null : isArray(ve) ? | ||
isArray(vs) && ve.length === vs.length ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof vs === 'object' ? | ||
@@ -656,3 +652,3 @@ objectTween(vs, ve, d) : typeof vs === 'string' ? | ||
} | ||
return function (t) { | ||
return s === e && ev[0] === u ? ev : function (t) { | ||
var v = ((((s + (e - s) * t) * d) | 0) / d) + u; | ||
@@ -674,9 +670,9 @@ if (r && t === 1) { | ||
var s = {}; | ||
for (var i in sv) { | ||
s[i] = sv[i]; | ||
for (var i in ev) { | ||
s[i] = sv && sv[i]; | ||
var vs = s[i], | ||
ve = ev[i]; | ||
rv[i] = typeof ve === 'string' && ve.indexOf('=') === 1 ? ve : null; | ||
if (ve === undefined) { continue; } | ||
s[i] = ve.nodeType || ve.update ? ve : vs === ve ? null : isArray(ve) ? | ||
if (sv[i] === undefined) { continue; } | ||
s[i] = ve.nodeType ? ve : ve.update ? ve : vs === ve ? null : isArray(ve) ? | ||
isArray(vs) && ve.length === vs.length ? arrayTween(vs, ve, d) : parseInterpolatables(vs, ve) : isArray(vs) ? tweenThemTo(vs, ve) : typeof vs === 'object' ? | ||
@@ -731,3 +727,3 @@ objectTween(vs, ve, d) : typeof vs === 'string' ? | ||
var NodeCache = function (node, tween) { | ||
if (!node || !node.nodeType) { return tween } | ||
if (!node || !node.nodeType || !tween) { return tween } | ||
var ID = node.queueID || 'queue_' + Math.round(Math.random() * 1000 + Date.now()); | ||
@@ -739,3 +735,3 @@ if (!node.queueID) { | ||
if (tween) { | ||
Store[ID] = Object.assign(Store[ID], tween); | ||
Store[ID] = assign(Store[ID], tween); | ||
} | ||
@@ -816,2 +812,4 @@ return Store[ID] | ||
Object.create = create; | ||
// Events list | ||
@@ -851,2 +849,3 @@ var EVENT_UPDATE = 'update'; | ||
this._valuesEnd = null; | ||
this._valuesFunc = {}; | ||
@@ -867,2 +866,3 @@ this._duration = 1000; | ||
this._isFinite = true; | ||
this._elapsed = 0; | ||
@@ -876,2 +876,21 @@ return this | ||
Tween.fromTo = function fromTo (node, object, to, params) { | ||
if ( params === void 0 ) params = {}; | ||
params.quickRender = params.quickRender ? params.quickRender : !to; | ||
var tween = new Tween(node, object).to(to, params); | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime); | ||
tween._rendered = false; | ||
tween._onStartCallbackFired = false; | ||
} | ||
return tween | ||
}; | ||
Tween.to = function to (node, to$1, params) { | ||
return Tween.fromTo(node, null, to$1, params) | ||
}; | ||
Tween.from = function from (node, from$1, params) { | ||
return Tween.fromTo(node, from$1, null, params) | ||
}; | ||
Tween.prototype.isPlaying = function isPlaying () { | ||
@@ -961,4 +980,9 @@ return this._isPlaying | ||
for (var prop in duration) { | ||
if (this$1[prop]) { | ||
(ref = this$1)[prop].apply(ref, (Array.isArray(duration) ? duration : [duration])); | ||
if (typeof this$1[prop] === 'function') { | ||
var ref = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]]; | ||
var arg1 = ref[0]; | ||
var arg2 = ref[1]; | ||
var arg3 = ref[2]; | ||
var arg4 = ref[3]; | ||
this$1[prop](arg1, arg2, arg3, arg4); | ||
} | ||
@@ -969,3 +993,2 @@ } | ||
return this | ||
var ref; | ||
}; | ||
@@ -982,6 +1005,17 @@ | ||
var _valuesEnd = ref._valuesEnd; | ||
var _valuesFunc = ref._valuesFunc; | ||
var _valuesStart = ref._valuesStart; | ||
var object = ref.object; | ||
var Renderer = ref.Renderer; | ||
var node = ref.node; | ||
var InitialValues = ref.InitialValues; | ||
if (node && InitialValues) { | ||
if (!object) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd)); | ||
} else if (!_valuesEnd) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object); | ||
} | ||
} | ||
for (var property in _valuesEnd) { | ||
@@ -992,15 +1026,15 @@ var start = object[property]; | ||
if (Plugins[property]) { | ||
_valuesEnd[property] = new Plugins[property](this$1, start, end); | ||
_valuesFunc[property] = new Plugins[property](this$1, start, end); | ||
continue | ||
} | ||
if (object[property] === undefined) { | ||
if (!object || object[property] === undefined) { | ||
continue | ||
} | ||
if (typeof start === 'number' && typeof end === 'number') { | ||
if (typeof end === 'number' && typeof start === 'number') { | ||
_valuesStart[property] = start; | ||
_valuesEnd[property] = end; | ||
} else { | ||
_valuesEnd[property] = intertween(start, end); | ||
_valuesFunc[property] = intertween(start, end); | ||
} | ||
@@ -1031,2 +1065,4 @@ } | ||
var object = ref.object; | ||
var _startTime = ref._startTime; | ||
var _duration = ref._duration; | ||
@@ -1037,2 +1073,4 @@ if (!_isPlaying) { | ||
this.update(_startTime + _duration); | ||
remove(this); | ||
@@ -1044,10 +1082,2 @@ this._isPlaying = false; | ||
Tween.prototype.end = function end () { | ||
var ref = this; | ||
var _startTime = ref._startTime; | ||
var _duration = ref._duration; | ||
return this.update(_startTime + _duration) | ||
}; | ||
Tween.prototype.delay = function delay (amount) { | ||
@@ -1131,4 +1161,6 @@ this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount; | ||
var _valuesEnd = ref._valuesEnd; | ||
var _valuesFunc = ref._valuesFunc; | ||
var object = ref.object; | ||
var _isFinite = ref._isFinite; | ||
var _isPlaying = ref._isPlaying; | ||
var __render = ref.__render; | ||
@@ -1142,3 +1174,3 @@ | ||
if (time < _startTime) { | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
@@ -1162,2 +1194,6 @@ } | ||
if (!object) { | ||
return true | ||
} | ||
for (property in _valuesEnd) { | ||
@@ -1168,9 +1204,12 @@ value = _easingFunction[property] ? _easingFunction[property](elapsed) : typeof _easingFunction === 'function' ? _easingFunction(elapsed) : defaultEasing(elapsed); | ||
var end = _valuesEnd[property]; | ||
var fnc = _valuesFunc[property]; | ||
if (end.update) { | ||
end.update(value, elapsed); | ||
if (fnc && fnc.update) { | ||
fnc.update(value, elapsed); | ||
} else if (fnc) { | ||
object[property] = fnc(value); | ||
} else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value; | ||
} else if (typeof end === 'function') { | ||
object[property] = end(value); | ||
} else { | ||
object[property] = end; | ||
} | ||
@@ -1210,4 +1249,6 @@ } | ||
} | ||
this._isPlaying = false; | ||
this.emit(EVENT_COMPLETE, object); | ||
this._repeat = this._r; | ||
_id--; | ||
@@ -1291,3 +1332,3 @@ return false | ||
this._startTime = now(); | ||
this._tweens = {}; | ||
this._tweens = []; | ||
this._elapsed = 0; | ||
@@ -1307,2 +1348,26 @@ this._id = _id$1++; | ||
Timeline.prototype.fromTo = function fromTo (nodes, from, to, params) { | ||
var this$1 = this; | ||
if (Array.isArray(nodes)) { | ||
if (this._defaultParams) { | ||
params = Object.assign(this._defaultParams, params); | ||
} | ||
var position = params.label; | ||
var offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
nodes.map(function (node, i) { | ||
this$1.add(Tween$$1.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : from, typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), offset + (params.stagger || 0) * i); | ||
}); | ||
} | ||
return this.start() | ||
}; | ||
Timeline.prototype.from = function from (nodes, from$1, params) { | ||
return this.fromTo(nodes, from$1, null, params) | ||
}; | ||
Timeline.prototype.to = function to (nodes, to$1, params) { | ||
return this.fromTo(nodes, null, to$1, params) | ||
}; | ||
Timeline.prototype.addLabel = function addLabel (name, offset) { | ||
@@ -1316,5 +1381,5 @@ this.position.addLabel(name, offset); | ||
for (var tween in this$1._tweens) { | ||
var _tween = this$1._tweens[tween]; | ||
fn(_tween, +tween); | ||
for (var i = 0, len = this._tweens.length; i < len; i++) { | ||
var _tween = this$1._tweens[i]; | ||
fn(_tween, i); | ||
this$1._totalDuration = Math.max(this$1._totalDuration, _tween._duration + _tween._startTime); | ||
@@ -1343,3 +1408,5 @@ } | ||
for (var method in _defaultParams) { | ||
tween[method](_defaultParams[method]); | ||
if (typeof tween[method] === 'function') { | ||
tween[method](_defaultParams[method]); | ||
} | ||
} | ||
@@ -1349,6 +1416,7 @@ } | ||
var offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null); | ||
tween._startTime = this._startTime; | ||
tween._startTime = Math.max(this._startTime, tween._delayTime); | ||
tween._startTime += offset; | ||
tween._isPlaying = true; | ||
this._totalDuration = Math.max(_totalDuration, tween._startTime + tween._delayTime + tween._duration); | ||
this._tweens[tween.id] = tween; | ||
this._tweens.push(tween); | ||
this.position.setLabel('afterLast', this._totalDuration); | ||
@@ -1374,7 +1442,2 @@ return this | ||
Timeline.prototype.reverse = function reverse () { | ||
this._reversed = !this._reversed; | ||
return this.emit(EVENT_REVERSE) | ||
}; | ||
Timeline.prototype.update = function update$$1 (time) { | ||
@@ -1391,9 +1454,16 @@ var ref = this; | ||
var _isFinite = ref._isFinite; | ||
var _elapsed = ref._elapsed; | ||
var _isPlaying = ref._isPlaying; | ||
if (time < _startTime) { | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
} | ||
var elapsed = Math.min(1, Math.max(0, (time - _startTime) / _totalDuration)); | ||
var elapsed = (time - _startTime) / _totalDuration; | ||
elapsed = elapsed > 1 ? 1 : elapsed; | ||
elapsed = _reversed ? 1 - elapsed : elapsed; | ||
elapsed = ((elapsed * 1000) | 0) / 1000; | ||
if (elapsed === _elapsed) { | ||
return true | ||
} | ||
this._elapsed = elapsed; | ||
@@ -1404,11 +1474,6 @@ | ||
for (var tween in _tweens) { | ||
var _tween = _tweens[tween]; | ||
if (_tween.skip) { | ||
_tween.skip = false; | ||
} else if (_tween.update(_timing)) { | ||
continue | ||
} else { | ||
_tween.skip = true; | ||
} | ||
var i = 0; | ||
while (i < _tweens.length) { | ||
_tweens[i].update(_timing); | ||
i++; | ||
} | ||
@@ -1427,19 +1492,16 @@ | ||
if (_yoyo) { | ||
this.reverse(); | ||
this._reversed = !_reversed; | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime += _totalDuration + _repeatDelayTime; | ||
this._startTime = time + _repeatDelayTime; | ||
} else if (_reversed && _reverseDelayTime) { | ||
this._startTime += _totalDuration + _reverseDelayTime; | ||
this._startTime = time + _reverseDelayTime; | ||
} else { | ||
this._startTime += _totalDuration; | ||
this._startTime = time; | ||
} | ||
for (var tween$1 in _tweens) { | ||
var _tween$1 = _tweens[tween$1]; | ||
if (_tween$1.skip) { | ||
_tween$1.skip = false; | ||
} | ||
_tween$1.reassignValues(); | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues(); | ||
i++; | ||
} | ||
@@ -1452,8 +1514,4 @@ | ||
for (var tween$2 in _tweens) { | ||
var _tween$2 = _tweens[tween$2]; | ||
if (_tween$2.skip) { | ||
_tween$2.skip = false; | ||
} | ||
} | ||
remove(this); | ||
this._isPlaying = false; | ||
@@ -1460,0 +1518,0 @@ return false |
@@ -1,3 +0,3 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN=t.TWEEN||{})}(this,function(t){"use strict";var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:this;Object.assign||(Object.assign=function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];for(var r=0,i=e.length;r<i;r++){var o=e[r];for(var s in o)t[s]=o[s]}return t}),Object.create||(Object.create=function(t){return Object.assign({},t||{})}),Array.isArray||(Array.isArray=function(t){return t&&t.push&&t.splice}),"undefined"==typeof requestAnimationFrame&&(e.requestAnimationFrame=function(t){return e.setTimeout(t,16)}),"undefined"==typeof cancelAnimationFrame&&(e.cancelAnimationFrame=function(t){return e.clearTimeout(t)});var n,r=[],i=!1,o=!1,s=e.requestAnimationFrame,a=e.cancelAnimationFrame,u=function(t){r.push(t),o&&!i&&(n=s(c),i=!0)},f=function(t){for(var e=0;e<r.length;e++)if(t===r[e])return r[e];return null},p=function(t){var e=r.indexOf(t);-1!==e&&r.splice(e,1)},h=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==e.performance&&void 0!==e.performance.now)return e.performance.now.bind(e.performance);var t=e.performance&&e.performance.timing&&e.performance.timing.navigationStart?e.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),c=function(t,e){if(t=void 0!==t?t:h(),n=s(c),0===r.length)return a(n),i=!1,!1;for(var o=0;o<r.length;)r[o].update(t,e),o++;return!0},l={};if(e.document&&e.document.addEventListener){var d=0,v=0;e.document.addEventListener("visibilitychange",function(){if(document.hidden)v=h(),a(n),i=!1;else{d=h()-v;for(var t=0,e=r.length;t<e;t++)r[t]._startTime+=d;n=s(c),i=!0}return!0})}var y={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-y.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*y.Bounce.In(2*t):.5*y.Bounce.Out(2*t-1)+.5}}},_="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},m=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){!function(e,n){t.exports?t.exports=n():e.InterTween=n()}("undefined"!=typeof window?window:_,function(){function t(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}function e(t,e){var n,r,i;3===e.length&&(e=(n=e[0])+n+(r=e[1])+r+(i=e[2])+i);var o=parseInt(e,16);return n=o>>16&_,r=o>>8&_,i=o&_,"rgb("+n+","+r+","+i+")"}function n(t){return"string"==typeof t?t.replace(y,""):t}function r(t,e){if("number"==typeof e)return e;var n=g[e.substr(0,2)],r=e.substr(2);if(1===n){var i=e[0]+r;return t+parseFloat(i)}return 2===n?t*+r:3===n?t/+r:4===n?t*(+r/100):e}function i(e){return b(e).match(d).map(t)}function o(t,e,n){if(n=void 0!==n?n:1e4,!d.test(e))return e;var o=i(t),s=i(e),a=f(o,s,n);if(a)return a;a=null;for(var u=null,p=null,h=[],v=0,y=s.length;v<y;v++){var _=s[v],m=o[v];h[v]="string"==typeof _&&1===_.indexOf("=")?e:null,l.test(_)?(u=v+2,p=v+11):c.test(_)&&(u=v,p=v+9),s[v]=m===_?null:null!==h[v]?r(m,_):"number"==typeof _?_-m:_}return function(t){for(var e="",i=0,a=s.length;i<a;i++){var f=o[i],c=s[i],l=h[i];e+="number"==typeof c?null!==u&&i>u&&i<p?f+c*t|0:((f+c*t)*n|0)/n:f,1===t&&null!==l&&(o[i]+=c,s[i]=r(o[i],l))}return e}}function s(t,e){for(var n=[],r=0,i=t.length;r<i;r++){var s=t[r];n[r]=m(s)?u(s,e):"object"==typeof s?p(s,e):"string"==typeof s?o(s,e):s}return function(e){for(var r=0,i=n.length;r<i;r++)t[r]=n[r](e);return t}}function a(t,e){for(var n=[],r=0,i=e.length;r<i;r++){var o=e[r];n[r]=h(0===r?t:e[r-1],o)}var s=e[e.length-1];n.push(h(s,s));var a=n.length-1;return function(t){var e=t*a,r=Math.floor(e),i=e-r;return(0,n[r])(i)}}function u(t,e,n){n=void 0!==n?n:1e4;for(var i=t.slice(),f=[],h=Math.min(t.length,e.length),c=0;c<h;c++){var l=i[c],d=e[c];f[c]="string"==typeof d&&1===d.indexOf("=")?d:null,i[c]=d.nodeType?d:d.update?d:l===d?null:m(d)?m(l)&&d.length===l.length?u(l,d,n):a(l,d):m(l)?s(l,d):"object"==typeof l?p(l,d,n):"string"==typeof l?o(l,d,n):void 0!==l?l:d,e[c]=null!==f[c]?r(l,d):d}return function(o){for(var s=0;s<h;s++){var a=i[s],u=e[s],p=f[s];null!==a&&void 0!==a&&(t[s]="number"==typeof a?((a+(u-a)*o)*n|0)/n:"function"==typeof a?a(o):a.update?a.update(o):u&&u.update?u.update(o):u,p&&1===o&&(i[s]=u,e[s]=r(i[s],p)))}return t}}function f(t,e,n){if(n=void 0!==n?n:1e4,2===e.length&&2===t.length&&-1!==T.indexOf(e[1])){var i=+t[0],o=+e[0],s=e[1],a="string"==typeof e[0]&&1===e[0].indexOf("=")?e[0]:null;return a&&(o=r(i,o)),function(t){var e=((i+(o-i)*t)*n|0)/n+s;return a&&1===t&&(o=r(i=o,a)),e}}return!1}function p(t,e,n){n=void 0!==n?n:1e4;var i={},f={};for(var h in t){f[h]=t[h];var c=f[h],l=e[h];i[h]="string"==typeof l&&1===l.indexOf("=")?l:null,void 0!==l&&(f[h]=l.nodeType||l.update?l:c===l?null:m(l)?m(c)&&l.length===c.length?u(c,l,n):a(c,l):m(c)?s(c,l):"object"==typeof c?p(c,l,n):"string"==typeof c?o(c,l,n):void 0!==c?c:l,e[h]=null!==i[h]?r(c,l):l)}return function(o){for(var s in e){var a=f[s],u=e[s],p=i[s];null!==a&&void 0!==a&&(t[s]="number"==typeof a?((a+(u-a)*o)*n|0)/n:"function"==typeof a?a(o):a.update?a.update(o):u.update?u.update(o):u,p&&1===o&&(f[s]=u,e[s]=r(f[s],p)))}return t}}function h(t,e,n){n=void 0!==n?n:1e4;var i="string"==typeof e&&"number"==typeof t&&1===e.indexOf("=")?e:null;return i&&(e=r(t,i)),e.nodeType?e:t.nodeType?t:m(e)?m(t)&&t.length===e.length?u(t,e,n):a(t,e):m(t)?s(t,e):"object"==typeof e?p(t,e,n):"string"==typeof e?o(t,e,n):"function"==typeof e?e:function(o){var s="number"==typeof e?((t+(e-t)*o)*n|0)/n:t;return i&&1===o&&(e=r(t+=e,i)),s}}var c=/rgb/g,l=/argb/g,d=/\s+|([A-Za-z?().,{}:""[\]#]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,v=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,y=/\n|\r|\t/g,_=255,m=Array.isArray,g={"+=":1,"-=":1,"*=":2,"/=":3,"%=":4},b=function(t){return"string"!=typeof t?t:n(t).replace(v,e)},T=["px","pt","pc","deg","rad","turn","em","ex","cm","mm","dm","inch","in","rem","vw","vh","vmin","vmax","%"];return h})}),g={},b=function(t,e){if(!t||!t.nodeType)return e;var n=t.queueID||"queue_"+Math.round(1e3*Math.random()+Date.now());return t.queueID||(t.queueID=n),g[n]?(e&&(g[n]=Object.assign(g[n],e)),g[n]):(g[n]=e,g[n])},T=function(){this._events={}};T.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},T.prototype.once=function(t,e){var n=this;this._events[t]||(this._events[t]=[]);var r=this._events,i=r[t].length;return this._events[t].push(function(){for(var o=[],s=arguments.length;s--;)o[s]=arguments[s];e.apply(n,o),r[t].splice(i,1)}),this},T.prototype.off=function(t,e){var n=this._events;return void 0!==t&&n[t]?(e?this._events[t]=this._events[t].filter(function(t){return t!==e}):this._events[t].length=0,this):this},T.prototype.emit=function(t,e,n,r,i){var o=this._events[t];if(!o||!o.length)return this;for(var s=0,a=o.length;s<a;s++)o[s](e,n,r,i)};var O=0,w=y.Linear.None,M=function(t){function e(e,n){t.call(this),this.id=O++,void 0===e||n||e.nodeType?void 0!==e&&(this.node=e,"object"==typeof n?n=this.object=b(e,n):this.object=n):(n=this.object=e,e=null);var r=this.isArr=Array.isArray(n);return this._valuesStart=r?[]:{},this._valuesEnd=null,this._duration=1e3,this._easingFunction=w,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this._isFinite=!0,this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.isPlaying=function(){return this._isPlaying},e.prototype.isStarted=function(){return this._onStartCallbackFired},e.prototype.reverse=function(){var t=this._reversed;return this._reversed=!t,this},e.prototype.reversed=function(){return this._reversed},e.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,p(this),this._pausedTime=h(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=h()-this._pausedTime,u(this),this._pausedTime=h(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this._startTime=h()+(t?0:this._delayTime),this._isPlaying||u(this),this.emit("restart",this._object)},e.prototype.seek=function(t,e){return this._startTime=h()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()},e.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},e.prototype.to=function(t,e){var n=this;if(void 0===e&&(e=1e3),this._valuesEnd=t,"number"==typeof e||"function"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var r in e)n[r]&&(i=n)[r].apply(i,Array.isArray(e)?e:[e]);return this;var i},e.prototype.render=function(){var t=this;if(this._rendered)return this;var e=this,n=e._valuesEnd,r=e._valuesStart,i=e.object,o=e.Renderer;for(var s in n){var a=i[s],u=n[s];l[s]?n[s]=new l[s](t,a,u):void 0!==i[s]&&("number"==typeof a&&"number"==typeof u?(r[s]=a,n[s]=u):n[s]=m(a,u))}return o&&this.node&&(this.__render=new o(this,i,n)),this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:h(),this._startTime+=this._delayTime,u(this),this._isPlaying=!0,this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object;return e?(p(this),this._isPlaying=!1,this.emit("stop",n)):this},e.prototype.end=function(){var t=this,e=t._startTime,n=t._duration;return this.update(e+n)},e.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this._startTime+=this._delayTime,this},e.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},e.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},e.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},e.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.reassignValues=function(){var t=this,e=t._valuesStart,n=t._valuesEnd,r=t.object,i=t.isArr;for(var o in n){i&&(o*=1);var s=e[o],a=n[o];r[o]="function"==typeof a?a(0):s}return this},e.prototype.get=function(t){return this.update(t),this.object},e.prototype.update=function(t,e){var n,r,i,o=this,s=o._onStartCallbackFired,a=o._easingFunction,u=o._repeat,f=o._repeatDelayTime,c=o._reverseDelayTime,l=o._yoyo,d=o._reversed,v=o._startTime,y=o._duration,_=o._valuesStart,m=o._valuesEnd,g=o.object,b=o._isFinite,T=o.__render;if((t=void 0!==t?t:h())<v)return!0;s||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",g),this._onStartCallbackFired=!0),n=(n=(t-v)/y)>1?1:n,n=d?1-n:n;for(i in m){r=a[i]?a[i](n):"function"==typeof a?a(n):w(n);var O=_[i],M=m[i];M.update?M.update(r,n):"number"==typeof M?g[i]=O+(M-O)*r:"function"==typeof M&&(g[i]=M(r))}return T&&T.update(g,n),this.emit("update",g,n),!(1===n||d&&0===n)||(u?(b&&this._repeat--,l&&(this._reversed=!d),this.emit(l&&!d?"reverse":"repeat",g),this._startTime=!d&&f?t+f:d&&c?t+c:t,!0):(e||p(this),this.emit("complete",g),this._repeat=this._r,!1))},e}(T),I=function(){this.totalTime=0,this.labels=[],this.offsets=[]};I.prototype.parseLabel=function(t,e){var n=this,r=n.offsets,i=n.labels,o=i.indexOf(t);if("string"==typeof t&&-1!==t.indexOf("=")&&!e&&-1===o){var s=t.substr(t.indexOf("=")-1,2),a=t.split(s);e=2===a.length?s+a[1]:null,t=a[0],o=i.indexOf(t)}if(-1!==o&&t){var u=r[o]||0;if("number"==typeof e)u=e;else if("string"==typeof e&&-1!==e.indexOf("=")){var f=e.charAt(0);e=Number(e.substr(2)),"+"===f||"-"===f?u+=parseFloat(f+e):"*"===f?u*=e:"/"===f?u/=e:"%"===f&&(u*=e/100)}return u}return"number"==typeof e?e:0},I.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},I.prototype.setLabel=function(t,e){var n=this.labels.indexOf(t);return-1!==n&&this.offsets.splice(n,1,this.parseLabel(t,e)),this},I.prototype.eraseLabel=function(t){var e=this.labels.indexOf(t);return-1!==e&&(this.labels.splice(e,1),this.offsets.splice(e,1)),this};var x=0,j=function(t){function e(e){return t.call(this),this._totalDuration=0,this._startTime=h(),this._tweens={},this._elapsed=0,this._id=x++,this._defaultParams=e,this.position=new I,this.position.addLabel("afterLast",this._totalDuration),this.position.addLabel("afterInit",this._startTime),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.addLabel=function(t,e){return this.position.addLabel(t,e),this},e.prototype.map=function(t){var e=this;for(var n in e._tweens){var r=e._tweens[n];t(r,+n),e._totalDuration=Math.max(e._totalDuration,r._duration+r._startTime)}return this},e.prototype.add=function(e,n){var r=this;if(Array.isArray(e))return e.map(function(t){r.add(t,n)}),this;"object"!=typeof e||e instanceof t||(e=new t(e.from).to(e.to,e));var i=this,o=i._defaultParams,s=i._totalDuration;if(o)for(var a in o)e[a](o[a]);var u="number"==typeof n?n:this.position.parseLabel(void 0!==n?n:"afterLast",null);return e._startTime=this._startTime,e._startTime+=u,this._totalDuration=Math.max(s,e._startTime+e._delayTime+e._duration),this._tweens[e.id]=e,this.position.setLabel("afterLast",this._totalDuration),this},e.prototype.restart=function(){return this._startTime+=h(),u(this),this.emit("restart")},e.prototype.easing=function(t){return this.map(function(e){return e.easing(t)})},e.prototype.interpolation=function(t){return this.map(function(e){return e.interpolation(t)})},e.prototype.reverse=function(){return this._reversed=!this._reversed,this.emit("reverse")},e.prototype.update=function(t){var e=this,n=e._tweens,r=e._totalDuration,i=e._repeatDelayTime,o=e._reverseDelayTime,s=e._startTime,a=e._reversed,u=e._yoyo,f=e._repeat,p=e._isFinite;if(t<s)return!0;var h=Math.min(1,Math.max(0,(t-s)/r));h=a?1-h:h,this._elapsed=h;var c=t-s,l=a?r-c:c;for(var d in n){var v=n[d];if(v.skip)v.skip=!1;else{if(v.update(l))continue;v.skip=!0}}if(this.emit("update",h,c),1===h||a&&0===h){if(f){p&&this._repeat--,this.emit(a?"reverse":"repeat"),u&&this.reverse(),this._startTime+=!a&&i?r+i:a&&o?r+o:r;for(var y in n){var _=n[y];_.skip&&(_.skip=!1),_.reassignValues()}return!0}this.emit("complete"),this._repeat=this._r;for(var m in n){var g=n[m];g.skip&&(g.skip=!1)}return!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._totalDuration):this._elapsed},e.prototype.seek=function(t){return this.update(t<1.1?t*this._totalDuration:t)},e}(M);t.Plugins=l,t.Interpolator=m,t.has=function(t){return null!==f(t)},t.get=f,t.getAll=function(){return r},t.removeAll=function(){r.length=0},t.remove=p,t.add=u,t.now=h,t.update=c,t.autoPlay=function(t){o=t},t.isRunning=function(){return i},t.Tween=M,t.Easing=y,t.Timeline=j,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.TWEEN=t.TWEEN||{})}(this,function(t){"use strict";var e=Object.create||function(t){return Object.assign({},t||{})},n=Object.assign||function(t){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];for(var r=0,i=e.length;r<i;r++){var o=e[r];for(var s in o)t[s]=o[s]}return t};Array.isArray||(Array.isArray=function(t){return t&&t.push&&t.splice});var r,i="undefined"!=typeof window?window:"undefined"!=typeof global?global:this,o=[],s=!1,u=!1,a=i.requestAnimationFrame||function(t){return i.setTimeout(t,16)},f=i.cancelAnimationFrame||function(t){return i.clearTimeout(t)},h=function(t){o.push(t),u&&!s&&(r=a(d),s=!0)},p=function(t){for(var e=0;e<o.length;e++)if(t===o[e])return o[e];return null},l=function(t){var e=o.indexOf(t);-1!==e&&o.splice(e,1)},c=function(){if("undefined"!=typeof process&&void 0!==process.hrtime)return function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6};if(void 0!==i.performance&&void 0!==i.performance.now)return i.performance.now.bind(i.performance);var t=i.performance&&i.performance.timing&&i.performance.timing.navigationStart?i.performance.timing.navigationStart:Date.now();return function(){return Date.now()-t}}(),d=function(t,e){if(t=void 0!==t?t:c(),r=a(d),0===o.length)return f(r),s=!1,!1;for(var n=0;n<o.length;)o[n].update(t,e),n++;return!0},y={};if(i.document&&i.document.addEventListener){var _=0,v=0;i.document.addEventListener("visibilitychange",function(){if(document.hidden)v=c(),f(r),s=!1;else{_=c()-v;for(var t=0,e=o.length;t<e;t++)o[t]._startTime+=_;r=a(d),s=!0}return!0})}var m={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-m.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*m.Bounce.In(2*t):.5*m.Bounce.Out(2*t-1)+.5}}},g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},b=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){!function(e,n){t.exports?t.exports=n():e.InterTween=n()}("undefined"!=typeof window?window:g,function(){function t(t){var e=parseFloat(t);return"number"!=typeof e||isNaN(e)?t:e}function e(t,e){var n,r,i;3===e.length&&(e=(n=e[0])+n+(r=e[1])+r+(i=e[2])+i);var o=parseInt(e,16);return n=o>>16&m,r=o>>8&m,i=o&m,"rgb("+n+","+r+","+i+")"}function n(t){return"string"==typeof t?t.replace(_,"").replace(v,","):t}function r(t,e){if("number"==typeof e)return e;var n=b[e.substr(0,2)],r=e.substr(2);if(1===n){var i=e[0]+r;return t+parseFloat(i)}return 2===n?t*+r:3===n?t/+r:4===n?t*(+r/100):e}function i(e){var n=T(e);return"string"==typeof n?n.match(d).map(t):e}function o(t,e,n){if(n=void 0!==n?n:1e4,!d.test(e))return e;var o=i(t),s=i(e),u=f(o,s,n);if(u)return u;u=null;for(var a=null,h=null,p=[],y=0,_=s.length;y<_;y++){var v=s[y],m=o[y];p[y]="string"==typeof v&&1===v.indexOf("=")?e:null,c.test(v)?(a=y+2,h=y+11):l.test(v)&&(a=y,h=y+9),s[y]=m===v?null:null!==p[y]?r(m,v):v}return function(t){var e="";for(y=0;y<_;y++){var i=o[y],u=s[y],f=p[y];e+="number"==typeof u?null!==a&&y>a&&y<h?i+(u-i)*t|0:((i+(u-i)*t)*n|0)/n:i,1===t&&null!==f&&(o[y]=u,s[y]=r(u,f))}return e}}function s(t,e){for(var n=[],r=0,i=t.length;r<i;r++){var s=t[r];n[r]=g(s)?a(s,e):"object"==typeof s?h(s,e):"string"==typeof s?o(s,e):s}return function(r){for(var i=0,o=n.length;i<o;i++)t[i]="function"==typeof n[i]?n[i](r):"number"==typeof n[i]?n[i]+(e-n[i])*r:n[i];return t}}function u(t,e){for(var n=[],r=0,i=e.length;r<i;r++){var o=e[r];n[r]=p(0===r?t:e[r-1],o)}var s=e[e.length-1];n.push(p(s,s));var u=n.length-1;return function(t){var e=t*u,r=Math.floor(e),i=e-r;return(0,n[r])(i)}}function a(t,e,n){n=void 0!==n?n:1e4;for(var i=t.slice(),f=[],p=Math.min(t.length,e.length),l=0;l<p;l++){var c=i[l],d=e[l];f[l]="string"==typeof d&&1===d.indexOf("=")?d:null,i[l]=d.nodeType||d.update?d.update:c===d?null:g(d)?g(c)&&d.length===c.length?a(c,d,n):u(c,d):g(c)?s(c,d):"object"==typeof c?h(c,d,n):"string"==typeof c?o(c,d,n):void 0!==c?c:d,e[l]=null!==f[l]?r(c,d):d}return function(o){for(var s=0;s<p;s++){var u=i[s],a=e[s],h=f[s];null!==u&&void 0!==u&&(t[s]="number"==typeof u?((u+(a-u)*o)*n|0)/n:"function"==typeof u?u(o):u.update?u.update(o):a&&a.update?a.update(o):a,h&&1===o&&(i[s]=a,e[s]=r(i[s],h)))}return t}}function f(t,e,n){if(n=void 0!==n?n:1e4,2===e.length&&2===t.length&&-1!==O.indexOf(e[1])){var i=+t[0],o=+e[0],s=e[1],u="string"==typeof e[0]&&1===e[0].indexOf("=")?e[0]:null;return u&&(o=r(i,o)),i===o&&e[0]===s?e:function(t){var e=((i+(o-i)*t)*n|0)/n+s;return u&&1===t&&(o=r(i=o,u)),e}}return!1}function h(t,e,n){n=void 0!==n?n:1e4;var i={},f={};for(var p in e){f[p]=t&&t[p];var l=f[p],c=e[p];i[p]="string"==typeof c&&1===c.indexOf("=")?c:null,void 0!==t[p]&&(f[p]=c.nodeType?c:c.update?c:l===c?null:g(c)?g(l)&&c.length===l.length?a(l,c,n):u(l,c):g(l)?s(l,c):"object"==typeof l?h(l,c,n):"string"==typeof l?o(l,c,n):void 0!==l?l:c,e[p]=null!==i[p]?r(l,c):c)}return function(o){for(var s in e){var u=f[s],a=e[s],h=i[s];null!==u&&void 0!==u&&(t[s]="number"==typeof u?((u+(a-u)*o)*n|0)/n:"function"==typeof u?u(o):u.update?u.update(o):a.update?a.update(o):a,h&&1===o&&(f[s]=a,e[s]=r(f[s],h)))}return t}}function p(t,e,n){n=void 0!==n?n:1e4;var i="string"==typeof e&&"number"==typeof t&&1===e.indexOf("=")?e:null;return i&&(e=r(t,i)),e.nodeType?e:t.nodeType?t:g(e)?g(t)&&t.length===e.length?a(t,e,n):u(t,e):g(t)?s(t,e):"object"==typeof e?h(t,e,n):"string"==typeof e?o(t,e,n):"function"==typeof e?e:function(o){var s="number"==typeof e?((t+(e-t)*o)*n|0)/n:t;return i&&1===o&&(e=r(t+=e,i)),s}}var l=/rgb/g,c=/argb/g,d=/\s+|([A-Za-z?().,{}:""[\]#\%]+)|([-+/*%]+=)?([-+*/%]+)?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,y=/^#([0-9a-f]{6}|[0-9a-f]{3})$/i,_=/\n|\r|\t/g,v=/, | ,| , /g,m=255,g=Array.isArray,b={"+=":1,"-=":1,"*=":2,"/=":3,"%=":4},T=function(t){return"string"!=typeof t?t:n(t).replace(y,e)},O=["px","pt","pc","deg","rad","turn","em","ex","cm","mm","dm","inch","in","rem","vw","vh","vmin","vmax","%"];return p})}),T={},O=function(t,e){if(!t||!t.nodeType||!e)return e;var r=t.queueID||"queue_"+Math.round(1e3*Math.random()+Date.now());return t.queueID||(t.queueID=r),T[r]?(e&&(T[r]=n(T[r],e)),T[r]):(T[r]=e,T[r])},w=function(){this._events={}};w.prototype.on=function(t,e){return this._events[t]||(this._events[t]=[]),this._events[t].push(e),this},w.prototype.once=function(t,e){var n=this;this._events[t]||(this._events[t]=[]);var r=this._events,i=r[t].length;return this._events[t].push(function(){for(var o=[],s=arguments.length;s--;)o[s]=arguments[s];e.apply(n,o),r[t].splice(i,1)}),this},w.prototype.off=function(t,e){var n=this._events;return void 0!==t&&n[t]?(e?this._events[t]=this._events[t].filter(function(t){return t!==e}):this._events[t].length=0,this):this},w.prototype.emit=function(t,e,n,r,i){var o=this._events[t];if(!o||!o.length)return this;for(var s=0,u=o.length;s<u;s++)o[s](e,n,r,i)},Object.create=e;var I=0,M=m.Linear.None,x=function(t){function e(e,n){t.call(this),this.id=I++,void 0===e||n||e.nodeType?void 0!==e&&(this.node=e,"object"==typeof n?n=this.object=O(e,n):this.object=n):(n=this.object=e,e=null);var r=this.isArr=Array.isArray(n);return this._valuesStart=r?[]:{},this._valuesEnd=null,this._valuesFunc={},this._duration=1e3,this._easingFunction=M,this._startTime=0,this._delayTime=0,this._repeat=0,this._r=0,this._isPlaying=!1,this._yoyo=!1,this._reversed=!1,this._onStartCallbackFired=!1,this._pausedTime=null,this._isFinite=!0,this._elapsed=0,this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.fromTo=function(t,n,r,i){void 0===i&&(i={}),i.quickRender=i.quickRender?i.quickRender:!r;var o=new e(t,n).to(r,i);return i.quickRender&&(o.render().update(o._startTime),o._rendered=!1,o._onStartCallbackFired=!1),o},e.to=function(t,n,r){return e.fromTo(t,null,n,r)},e.from=function(t,n,r){return e.fromTo(t,n,null,r)},e.prototype.isPlaying=function(){return this._isPlaying},e.prototype.isStarted=function(){return this._onStartCallbackFired},e.prototype.reverse=function(){var t=this._reversed;return this._reversed=!t,this},e.prototype.reversed=function(){return this._reversed},e.prototype.pause=function(){return this._isPlaying?(this._isPlaying=!1,l(this),this._pausedTime=c(),this.emit("pause",this.object)):this},e.prototype.play=function(){return this._isPlaying?this:(this._isPlaying=!0,this._startTime+=c()-this._pausedTime,h(this),this._pausedTime=c(),this.emit("play",this.object))},e.prototype.restart=function(t){return this._repeat=this._r,this._startTime=c()+(t?0:this._delayTime),this._isPlaying||h(this),this.emit("restart",this._object)},e.prototype.seek=function(t,e){return this._startTime=c()+Math.max(0,Math.min(t,this._duration)),this.emit("seek",t,this._object),e?this:this.pause()},e.prototype.duration=function(t){return this._duration="function"==typeof t?t(this._duration):t,this},e.prototype.to=function(t,e){var n=this;if(void 0===e&&(e=1e3),this._valuesEnd=t,"number"==typeof e||"function"==typeof e)this._duration="function"==typeof e?e(this._duration):e;else if("object"==typeof e)for(var r in e)if("function"==typeof n[r]){var i=Array.isArray(e[r])?e[r]:[e[r]],o=i[0],s=i[1],u=i[2],a=i[3];n[r](o,s,u,a)}return this},e.prototype.render=function(){var t=this;if(this._rendered)return this;var e=this,n=e._valuesEnd,r=e._valuesFunc,i=e._valuesStart,o=e.object,s=e.Renderer,u=e.node,a=e.InitialValues;u&&a&&(o?n||(n=this._valuesEnd=a(u,o)):o=this.object=O(u,a(u,n)));for(var f in n){var h=o[f],p=n[f];y[f]?r[f]=new y[f](t,h,p):o&&void 0!==o[f]&&("number"==typeof p&&"number"==typeof h?(i[f]=h,n[f]=p):r[f]=b(h,p))}return s&&this.node&&(this.__render=new s(this,o,n)),this},e.prototype.start=function(t){return this._startTime=void 0!==t?t:c(),this._startTime+=this._delayTime,h(this),this._isPlaying=!0,this},e.prototype.stop=function(){var t=this,e=t._isPlaying,n=t.object,r=t._startTime,i=t._duration;return e?(this.update(r+i),l(this),this._isPlaying=!1,this.emit("stop",n)):this},e.prototype.delay=function(t){return this._delayTime="function"==typeof t?t(this._delayTime):t,this._startTime+=this._delayTime,this},e.prototype.repeat=function(t){return this._repeat="function"==typeof t?t(this._repeat):t,this._r=this._repeat,this._isFinite=isFinite(t),this},e.prototype.repeatDelay=function(t){return this._repeatDelayTime="function"==typeof t?t(this._repeatDelayTime):t,this},e.prototype.reverseDelay=function(t){return this._reverseDelayTime="function"==typeof t?t(this._reverseDelayTime):t,this},e.prototype.yoyo=function(t){return this._yoyo="function"==typeof t?t(this._yoyo):t,this},e.prototype.easing=function(t){return this._easingFunction=t,this},e.prototype.reassignValues=function(){var t=this,e=t._valuesStart,n=t._valuesEnd,r=t.object,i=t.isArr;for(var o in n){i&&(o*=1);var s=e[o],u=n[o];r[o]="function"==typeof u?u(0):s}return this},e.prototype.get=function(t){return this.update(t),this.object},e.prototype.update=function(t,e){var n,r,i,o=this,s=o._onStartCallbackFired,u=o._easingFunction,a=o._repeat,f=o._repeatDelayTime,h=o._reverseDelayTime,p=o._yoyo,d=o._reversed,y=o._startTime,_=o._duration,v=o._valuesStart,m=o._valuesEnd,g=o._valuesFunc,b=o.object,T=o._isFinite,O=o._isPlaying,w=o.__render;if(t=void 0!==t?t:c(),!O||t<y)return!0;if(s||(this._rendered||(this.render(),this._rendered=!0),this.emit("start",b),this._onStartCallbackFired=!0),n=(t-y)/_,n=n>1?1:n,n=d?1-n:n,!b)return!0;for(i in m){r=u[i]?u[i](n):"function"==typeof u?u(n):M(n);var x=v[i],P=m[i],j=g[i];j&&j.update?j.update(r,n):b[i]=j?j(r):"number"==typeof P?x+(P-x)*r:P}return w&&w.update(b,n),this.emit("update",b,n),!(1===n||d&&0===n)||(a?(T&&this._repeat--,p&&(this._reversed=!d),this.emit(p&&!d?"reverse":"repeat",b),this._startTime=!d&&f?t+f:d&&h?t+h:t,!0):(e||l(this),this._isPlaying=!1,this.emit("complete",b),this._repeat=this._r,I--,!1))},e}(w),P=function(){this.totalTime=0,this.labels=[],this.offsets=[]};P.prototype.parseLabel=function(t,e){var n=this,r=n.offsets,i=n.labels,o=i.indexOf(t);if("string"==typeof t&&-1!==t.indexOf("=")&&!e&&-1===o){var s=t.substr(t.indexOf("=")-1,2),u=t.split(s);e=2===u.length?s+u[1]:null,t=u[0],o=i.indexOf(t)}if(-1!==o&&t){var a=r[o]||0;if("number"==typeof e)a=e;else if("string"==typeof e&&-1!==e.indexOf("=")){var f=e.charAt(0);e=Number(e.substr(2)),"+"===f||"-"===f?a+=parseFloat(f+e):"*"===f?a*=e:"/"===f?a/=e:"%"===f&&(a*=e/100)}return a}return"number"==typeof e?e:0},P.prototype.addLabel=function(t,e){return this.labels.push(t),this.offsets.push(this.parseLabel(t,e)),this},P.prototype.setLabel=function(t,e){var n=this.labels.indexOf(t);return-1!==n&&this.offsets.splice(n,1,this.parseLabel(t,e)),this},P.prototype.eraseLabel=function(t){var e=this.labels.indexOf(t);return-1!==e&&(this.labels.splice(e,1),this.offsets.splice(e,1)),this};var j=0,D=function(t){function e(e){return t.call(this),this._totalDuration=0,this._startTime=c(),this._tweens=[],this._elapsed=0,this._id=j++,this._defaultParams=e,this.position=new P,this.position.addLabel("afterLast",this._totalDuration),this.position.addLabel("afterInit",this._startTime),this}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.fromTo=function(e,n,r,i){var o=this;if(Array.isArray(e)){this._defaultParams&&(i=Object.assign(this._defaultParams,i));var s=i.label,u="number"==typeof s?s:this.position.parseLabel(void 0!==s?s:"afterLast",null);e.map(function(s,a){o.add(t.fromTo(s,"function"==typeof n?n(a,e.length):n,"function"==typeof r?r(a,e.length):r,"function"==typeof i?i(a,e.length):i),u+(i.stagger||0)*a)})}return this.start()},e.prototype.from=function(t,e,n){return this.fromTo(t,e,null,n)},e.prototype.to=function(t,e,n){return this.fromTo(t,null,e,n)},e.prototype.addLabel=function(t,e){return this.position.addLabel(t,e),this},e.prototype.map=function(t){for(var e=this,n=0,r=this._tweens.length;n<r;n++){var i=e._tweens[n];t(i,n),e._totalDuration=Math.max(e._totalDuration,i._duration+i._startTime)}return this},e.prototype.add=function(e,n){var r=this;if(Array.isArray(e))return e.map(function(t){r.add(t,n)}),this;"object"!=typeof e||e instanceof t||(e=new t(e.from).to(e.to,e));var i=this,o=i._defaultParams,s=i._totalDuration;if(o)for(var u in o)"function"==typeof e[u]&&e[u](o[u]);var a="number"==typeof n?n:this.position.parseLabel(void 0!==n?n:"afterLast",null);return e._startTime=Math.max(this._startTime,e._delayTime),e._startTime+=a,e._isPlaying=!0,this._totalDuration=Math.max(s,e._startTime+e._delayTime+e._duration),this._tweens.push(e),this.position.setLabel("afterLast",this._totalDuration),this},e.prototype.restart=function(){return this._startTime+=c(),h(this),this.emit("restart")},e.prototype.easing=function(t){return this.map(function(e){return e.easing(t)})},e.prototype.interpolation=function(t){return this.map(function(e){return e.interpolation(t)})},e.prototype.update=function(t){var e=this,n=e._tweens,r=e._totalDuration,i=e._repeatDelayTime,o=e._reverseDelayTime,s=e._startTime,u=e._reversed,a=e._yoyo,f=e._repeat,h=e._isFinite,p=e._elapsed;if(!e._isPlaying||t<s)return!0;var c=(t-s)/r;if(c=c>1?1:c,c=u?1-c:c,(c=(1e3*c|0)/1e3)===p)return!0;this._elapsed=c;for(var d=t-s,y=u?r-d:d,_=0;_<n.length;)n[_].update(y),_++;if(this.emit("update",c,d),1===c||u&&0===c){if(f){for(h&&this._repeat--,this.emit(u?"reverse":"repeat"),a&&(this._reversed=!u),this._startTime=!u&&i?t+i:u&&o?t+o:t;_<n.length;)n[_].reassignValues(),_++;return!0}return this.emit("complete"),this._repeat=this._r,l(this),this._isPlaying=!1,!1}return!0},e.prototype.elapsed=function(t){return void 0!==t?this.update(t*this._totalDuration):this._elapsed},e.prototype.seek=function(t){return this.update(t<1.1?t*this._totalDuration:t)},e}(x);t.Plugins=y,t.Interpolator=b,t.has=function(t){return null!==p(t)},t.get=p,t.getAll=function(){return o},t.removeAll=function(){o.length=0},t.remove=l,t.add=h,t.now=c,t.update=d,t.autoPlay=function(t){u=t},t.isRunning=function(){return s},t.Tween=x,t.Easing=m,t.Timeline=D,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=dist/Tween.min.js.map | ||
//# sourceMappingURL=Tween.min.js.map |
{ | ||
"name": "es6-tween", | ||
"version": "3.5.9", | ||
"version": "3.6.0", | ||
"description": "ES6 implementation of amazing tween.js", | ||
@@ -16,3 +16,8 @@ "browser": "dist/Tween.min.js", | ||
"build": "npm run source && npm run minify", | ||
"source-lite": "rollup -c lite.js --environment min:false", | ||
"minify-lite": "rollup -c lite.js --environment min:true", | ||
"build-lite": "npm run source-lite && npm run minify-lite", | ||
"prepare": "npm run build && npm run build-lite", | ||
"dev": "rollup -c -w", | ||
"dev-lite": "rollup -c lite.js -w", | ||
"lint": "eslint src", | ||
@@ -22,3 +27,3 @@ "fix": "eslint --fix src", | ||
"test": "npm run lint && ava --verbose", | ||
"prepublishOnly": "npm run lint && npm run build && ava --verbose" | ||
"prepublishOnly": "npm run lint && npm run prepare && ava --verbose" | ||
}, | ||
@@ -25,0 +30,0 @@ "repository": { |
@@ -5,2 +5,22 @@ # es6-tween | ||
# News (`Lite` version is released)! | ||
You can use the `Lite` version of ES6 which lighter (~8Kb minified), faster (~10% faster executioin), simpler (like the original one), memory effecient and better (can tween second-level Objects/Array). Optimized for runtime performance, no-lag anymore. | ||
When you want building mobile apps that loading files from server, use `Lite` for better performance. | ||
Differences when using `Lite`: | ||
* 2-times lighter size | ||
* No `Timeline` instance | ||
* No `String` tween support | ||
* No `Deep tween` support (does 2-level) | ||
* Uses original `Interpolation` instances for `Bezier` interpolation | ||
* Faster performance and execution speed | ||
* Memory effecient | ||
* No more shims required | ||
* No `Plugins` support | ||
* No `DOM Get/Set`, `Renderer` instance/plugin/add-on support | ||
* No full-Event system, just 3 event support (`onStart`, `onUpdate`, `onComplete`) | ||
* No `seek`, `reverse` support | ||
* No event fire when `stop`, `pause`, `etc` | ||
* No `*`, `/`, `%` relatives support | ||
[![size](http://img.badgesize.io/https://unpkg.com/es6-tween?cache=false)](http://unpkg.com/es6-tween) | ||
@@ -7,0 +27,0 @@ [![gzipsize](http://img.badgesize.io/https://unpkg.com/es6-tween?compression=gzip&cache=false)](http://unpkg.com/es6-tween) |
/* global process */ | ||
import { root } from '../shim' | ||
import { root, requestAnimationFrame, cancelAnimationFrame } from '../shim' | ||
@@ -8,4 +8,4 @@ let _tweens = [] | ||
let _tick | ||
const _ticker = root.requestAnimationFrame | ||
const _stopTicker = root.cancelAnimationFrame | ||
const _ticker = requestAnimationFrame | ||
const _stopTicker = cancelAnimationFrame | ||
@@ -12,0 +12,0 @@ const add = tween => { |
@@ -0,4 +1,6 @@ | ||
import { assign } from '../shim' | ||
let Store = {} | ||
export default function (node, tween) { | ||
if (!node || !node.nodeType) return tween | ||
if (!node || !node.nodeType || !tween) return tween | ||
var ID = node.queueID || 'queue_' + Math.round(Math.random() * 1000 + Date.now()) | ||
@@ -10,3 +12,3 @@ if (!node.queueID) { | ||
if (tween) { | ||
Store[ID] = Object.assign(Store[ID], tween) | ||
Store[ID] = assign(Store[ID], tween) | ||
} | ||
@@ -13,0 +15,0 @@ return Store[ID] |
import Tween, { EVENT_UPDATE, EVENT_RS, EVENT_REPEAT, EVENT_REVERSE, EVENT_COMPLETE } from './Tween' | ||
import { add, now } from './core' | ||
import { add, now, remove } from './core' | ||
import PlaybackPosition from './PlaybackPosition' | ||
@@ -11,3 +11,3 @@ | ||
this._startTime = now() | ||
this._tweens = {} | ||
this._tweens = [] | ||
this._elapsed = 0 | ||
@@ -23,2 +23,24 @@ this._id = _id++ | ||
fromTo (nodes, from, to, params) { | ||
if (Array.isArray(nodes)) { | ||
if (this._defaultParams) { | ||
params = Object.assign(this._defaultParams, params) | ||
} | ||
const position = params.label | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null) | ||
nodes.map((node, i) => { | ||
this.add(Tween.fromTo(node, typeof from === 'function' ? from(i, nodes.length) : from, typeof to === 'function' ? to(i, nodes.length) : to, typeof params === 'function' ? params(i, nodes.length) : params), offset + (params.stagger || 0) * i) | ||
}) | ||
} | ||
return this.start() | ||
} | ||
from (nodes, from, params) { | ||
return this.fromTo(nodes, from, null, params) | ||
} | ||
to (nodes, to, params) { | ||
return this.fromTo(nodes, null, to, params) | ||
} | ||
addLabel (name, offset) { | ||
@@ -30,5 +52,5 @@ this.position.addLabel(name, offset) | ||
map (fn) { | ||
for (let tween in this._tweens) { | ||
let _tween = this._tweens[tween] | ||
fn(_tween, +tween) | ||
for (let i = 0, len = this._tweens.length; i < len; i++) { | ||
let _tween = this._tweens[i] | ||
fn(_tween, i) | ||
this._totalDuration = Math.max(this._totalDuration, _tween._duration + _tween._startTime) | ||
@@ -56,3 +78,5 @@ } | ||
for (let method in _defaultParams) { | ||
tween[method](_defaultParams[method]) | ||
if (typeof tween[method] === 'function') { | ||
tween[method](_defaultParams[method]) | ||
} | ||
} | ||
@@ -62,6 +86,7 @@ } | ||
const offset = typeof position === 'number' ? position : this.position.parseLabel(typeof position !== 'undefined' ? position : 'afterLast', null) | ||
tween._startTime = this._startTime | ||
tween._startTime = Math.max(this._startTime, tween._delayTime) | ||
tween._startTime += offset | ||
tween._isPlaying = true | ||
this._totalDuration = Math.max(_totalDuration, tween._startTime + tween._delayTime + tween._duration) | ||
this._tweens[tween.id] = tween | ||
this._tweens.push(tween) | ||
this.position.setLabel('afterLast', this._totalDuration) | ||
@@ -87,7 +112,2 @@ return this | ||
reverse () { | ||
this._reversed = !this._reversed | ||
return this.emit(EVENT_REVERSE) | ||
} | ||
update (time) { | ||
@@ -103,11 +123,18 @@ let { | ||
_repeat, | ||
_isFinite | ||
_isFinite, | ||
_elapsed, | ||
_isPlaying | ||
} = this | ||
if (time < _startTime) { | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
} | ||
let elapsed = Math.min(1, Math.max(0, (time - _startTime) / _totalDuration)) | ||
let elapsed = (time - _startTime) / _totalDuration | ||
elapsed = elapsed > 1 ? 1 : elapsed | ||
elapsed = _reversed ? 1 - elapsed : elapsed | ||
elapsed = ((elapsed * 1000) | 0) / 1000 | ||
if (elapsed === _elapsed) { | ||
return true | ||
} | ||
this._elapsed = elapsed | ||
@@ -118,11 +145,6 @@ | ||
for (let tween in _tweens) { | ||
let _tween = _tweens[tween] | ||
if (_tween.skip) { | ||
_tween.skip = false | ||
} else if (_tween.update(_timing)) { | ||
continue | ||
} else { | ||
_tween.skip = true | ||
} | ||
let i = 0 | ||
while (i < _tweens.length) { | ||
_tweens[i].update(_timing) | ||
i++ | ||
} | ||
@@ -141,19 +163,16 @@ | ||
if (_yoyo) { | ||
this.reverse() | ||
this._reversed = !_reversed | ||
} | ||
if (!_reversed && _repeatDelayTime) { | ||
this._startTime += _totalDuration + _repeatDelayTime | ||
this._startTime = time + _repeatDelayTime | ||
} else if (_reversed && _reverseDelayTime) { | ||
this._startTime += _totalDuration + _reverseDelayTime | ||
this._startTime = time + _reverseDelayTime | ||
} else { | ||
this._startTime += _totalDuration | ||
this._startTime = time | ||
} | ||
for (let tween in _tweens) { | ||
let _tween = _tweens[tween] | ||
if (_tween.skip) { | ||
_tween.skip = false | ||
} | ||
_tween.reassignValues() | ||
while (i < _tweens.length) { | ||
_tweens[i].reassignValues() | ||
i++ | ||
} | ||
@@ -166,8 +185,4 @@ | ||
for (let tween in _tweens) { | ||
let _tween = _tweens[tween] | ||
if (_tween.skip) { | ||
_tween.skip = false | ||
} | ||
} | ||
remove(this) | ||
this._isPlaying = false | ||
@@ -174,0 +189,0 @@ return false |
@@ -12,3 +12,6 @@ import { | ||
import EventClass from './Event' | ||
import { create } from '../shim' | ||
Object.create = create | ||
// Events list | ||
@@ -30,2 +33,18 @@ export const EVENT_UPDATE = 'update' | ||
class Tween extends EventClass { | ||
static fromTo (node, object, to, params = {}) { | ||
params.quickRender = params.quickRender ? params.quickRender : !to | ||
let tween = new Tween(node, object).to(to, params) | ||
if (params.quickRender) { | ||
tween.render().update(tween._startTime) | ||
tween._rendered = false | ||
tween._onStartCallbackFired = false | ||
} | ||
return tween | ||
} | ||
static to (node, to, params) { | ||
return Tween.fromTo(node, null, to, params) | ||
} | ||
static from (node, from, params) { | ||
return Tween.fromTo(node, from, null, params) | ||
} | ||
constructor (node, object) { | ||
@@ -49,2 +68,3 @@ super() | ||
this._valuesEnd = null | ||
this._valuesFunc = {} | ||
@@ -65,2 +85,3 @@ this._duration = 1000 | ||
this._isFinite = true | ||
this._elapsed = 0 | ||
@@ -152,4 +173,5 @@ return this | ||
for (let prop in duration) { | ||
if (this[prop]) { | ||
this[prop](...(Array.isArray(duration) ? duration : [duration])) | ||
if (typeof this[prop] === 'function') { | ||
let [arg1, arg2, arg3, arg4] = Array.isArray(duration[prop]) ? duration[prop] : [duration[prop]] | ||
this[prop](arg1, arg2, arg3, arg4) | ||
} | ||
@@ -169,7 +191,18 @@ } | ||
_valuesEnd, | ||
_valuesFunc, | ||
_valuesStart, | ||
object, | ||
Renderer | ||
Renderer, | ||
node, | ||
InitialValues | ||
} = this | ||
if (node && InitialValues) { | ||
if (!object) { | ||
object = this.object = NodeCache(node, InitialValues(node, _valuesEnd)) | ||
} else if (!_valuesEnd) { | ||
_valuesEnd = this._valuesEnd = InitialValues(node, object) | ||
} | ||
} | ||
for (let property in _valuesEnd) { | ||
@@ -180,15 +213,15 @@ let start = object[property] | ||
if (Plugins[property]) { | ||
_valuesEnd[property] = new Plugins[property](this, start, end) | ||
_valuesFunc[property] = new Plugins[property](this, start, end) | ||
continue | ||
} | ||
if (object[property] === undefined) { | ||
if (!object || object[property] === undefined) { | ||
continue | ||
} | ||
if (typeof start === 'number' && typeof end === 'number') { | ||
if (typeof end === 'number' && typeof start === 'number') { | ||
_valuesStart[property] = start | ||
_valuesEnd[property] = end | ||
} else { | ||
_valuesEnd[property] = InterTween(start, end) | ||
_valuesFunc[property] = InterTween(start, end) | ||
} | ||
@@ -218,3 +251,5 @@ } | ||
_isPlaying, | ||
object | ||
object, | ||
_startTime, | ||
_duration | ||
} = this | ||
@@ -226,2 +261,4 @@ | ||
this.update(_startTime + _duration) | ||
remove(this) | ||
@@ -233,11 +270,2 @@ this._isPlaying = false | ||
end () { | ||
const { | ||
_startTime, | ||
_duration | ||
} = this | ||
return this.update(_startTime + _duration) | ||
} | ||
delay (amount) { | ||
@@ -322,4 +350,6 @@ this._delayTime = typeof (amount) === 'function' ? amount(this._delayTime) : amount | ||
_valuesEnd, | ||
_valuesFunc, | ||
object, | ||
_isFinite, | ||
_isPlaying, | ||
__render | ||
@@ -334,3 +364,3 @@ } = this | ||
if (time < _startTime) { | ||
if (!_isPlaying || time < _startTime) { | ||
return true | ||
@@ -354,2 +384,6 @@ } | ||
if (!object) { | ||
return true | ||
} | ||
for (property in _valuesEnd) { | ||
@@ -360,9 +394,12 @@ value = _easingFunction[property] ? _easingFunction[property](elapsed) : typeof _easingFunction === 'function' ? _easingFunction(elapsed) : defaultEasing(elapsed) | ||
let end = _valuesEnd[property] | ||
let fnc = _valuesFunc[property] | ||
if (end.update) { | ||
end.update(value, elapsed) | ||
if (fnc && fnc.update) { | ||
fnc.update(value, elapsed) | ||
} else if (fnc) { | ||
object[property] = fnc(value) | ||
} else if (typeof end === 'number') { | ||
object[property] = start + (end - start) * value | ||
} else if (typeof end === 'function') { | ||
object[property] = end(value) | ||
} else { | ||
object[property] = end | ||
} | ||
@@ -402,4 +439,6 @@ } | ||
} | ||
this._isPlaying = false | ||
this.emit(EVENT_COMPLETE, object) | ||
this._repeat = this._r | ||
_id-- | ||
@@ -406,0 +445,0 @@ return false |
/* global global */ | ||
export let root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this | ||
if (!Object.assign) { | ||
Object.assign = (source, ...args) => { | ||
for (let i = 0, len = args.length; i < len; i++) { | ||
let arg = args[i] | ||
for (let p in arg) { | ||
source[p] = arg[p] | ||
} | ||
export let create = Object.create || function (source) { | ||
return Object.assign({}, source || {}) | ||
} | ||
export let assign = Object.assign || function (source, ...args) { | ||
for (let i = 0, len = args.length; i < len; i++) { | ||
let arg = args[i] | ||
for (let p in arg) { | ||
source[p] = arg[p] | ||
} | ||
return source | ||
} | ||
return source | ||
} | ||
if (!Object.create) { | ||
Object.create = source => { | ||
return Object.assign({}, source || {}) | ||
} | ||
} | ||
if (!Array.isArray) { | ||
Array.isArray = source => source && source.push && source.splice | ||
} | ||
if (typeof (requestAnimationFrame) === 'undefined') { | ||
root.requestAnimationFrame = fn => root.setTimeout(fn, 16) | ||
} | ||
if (typeof (cancelAnimationFrame) === 'undefined') { | ||
root.cancelAnimationFrame = id => root.clearTimeout(id) | ||
} | ||
export let root = typeof (window) !== 'undefined' ? window : typeof (global) !== 'undefined' ? global : this | ||
export let requestAnimationFrame = root.requestAnimationFrame || function (fn) { return root.setTimeout(fn, 16) } | ||
export let cancelAnimationFrame = root.cancelAnimationFrame || function (id) { return root.clearTimeout(id) } |
16
test.js
@@ -49,3 +49,3 @@ import test from 'ava' | ||
let obj = { a: 0, b: 'B value 1', c: { x: 2 }, d: [3], _e: 4 } | ||
let obj = { a: 0, b: 'B value 1', c: { x: 2 }, d: [3], _e: 4, g: 5 } | ||
@@ -58,3 +58,3 @@ Object.defineProperty(obj, 'e', { | ||
let tween = new Tween(obj) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5 }, 100) | ||
.to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+=1' }, 100) | ||
.start(0) | ||
@@ -69,2 +69,3 @@ | ||
t.is(obj.e, 4) | ||
t.is(obj.g, 5) | ||
@@ -88,3 +89,6 @@ update(50) | ||
t.is(obj.g, 5.5, 'Relative number interpolation not worked as excepted') | ||
t.log('Relative number interpolation worked as excepted') | ||
update(100) | ||
@@ -97,2 +101,3 @@ | ||
t.is(obj.e, 5) | ||
t.is(obj.g, 6) | ||
@@ -103,5 +108,5 @@ }) | ||
let obj = { x: 0 } | ||
let obj = { x: 0, y: [2, 4, 6] } | ||
let tween = new Tween(obj) | ||
.to({ x: [1, 3, 5] }, 100) | ||
.to({ x: [1, 3, 5], y: 10 }, 100) | ||
.start(0) | ||
@@ -116,2 +121,5 @@ | ||
t.deepEqual(obj.y, [6, 7, 8], 'Tween-them failed') | ||
t.log('Start-value interpolation was done') | ||
tween.update(100) | ||
@@ -118,0 +126,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
695843
38
3560
219
3
2