@realsee/dnalogel
Version:
404 lines (403 loc) • 16.8 kB
JavaScript
var d = Object.freeze({
Linear: Object.freeze({
None: function(t) {
return t;
},
In: function(t) {
return this.None(t);
},
Out: function(t) {
return this.None(t);
},
InOut: function(t) {
return this.None(t);
}
}),
Quadratic: Object.freeze({
In: function(t) {
return t * t;
},
Out: function(t) {
return t * (2 - t);
},
InOut: function(t) {
return (t *= 2) < 1 ? 0.5 * t * t : -0.5 * (--t * (t - 2) - 1);
}
}),
Cubic: Object.freeze({
In: function(t) {
return t * t * t;
},
Out: function(t) {
return --t * t * t + 1;
},
InOut: function(t) {
return (t *= 2) < 1 ? 0.5 * t * t * t : 0.5 * ((t -= 2) * t * t + 2);
}
}),
Quartic: Object.freeze({
In: function(t) {
return t * t * t * t;
},
Out: function(t) {
return 1 - --t * t * t * t;
},
InOut: function(t) {
return (t *= 2) < 1 ? 0.5 * t * t * t * t : -0.5 * ((t -= 2) * t * t * t - 2);
}
}),
Quintic: Object.freeze({
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 ? 0.5 * t * t * t * t * t : 0.5 * ((t -= 2) * t * t * t * t + 2);
}
}),
Sinusoidal: Object.freeze({
In: function(t) {
return 1 - Math.sin((1 - t) * Math.PI / 2);
},
Out: function(t) {
return Math.sin(t * Math.PI / 2);
},
InOut: function(t) {
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - t)));
}
}),
Exponential: Object.freeze({
In: function(t) {
return t === 0 ? 0 : Math.pow(1024, t - 1);
},
Out: function(t) {
return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
},
InOut: function(t) {
return t === 0 ? 0 : t === 1 ? 1 : (t *= 2) < 1 ? 0.5 * Math.pow(1024, t - 1) : 0.5 * (-Math.pow(2, -10 * (t - 1)) + 2);
}
}),
Circular: Object.freeze({
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 ? -0.5 * (Math.sqrt(1 - t * t) - 1) : 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
}
}),
Elastic: Object.freeze({
In: function(t) {
return t === 0 ? 0 : t === 1 ? 1 : -Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1.1) * 5 * Math.PI);
},
Out: function(t) {
return t === 0 ? 0 : t === 1 ? 1 : Math.pow(2, -10 * t) * Math.sin((t - 0.1) * 5 * Math.PI) + 1;
},
InOut: function(t) {
return t === 0 ? 0 : t === 1 ? 1 : (t *= 2, t < 1 ? -0.5 * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1.1) * 5 * Math.PI) : 0.5 * Math.pow(2, -10 * (t - 1)) * Math.sin((t - 1.1) * 5 * Math.PI) + 1);
}
}),
Back: Object.freeze({
In: function(t) {
var e = 1.70158;
return t === 1 ? 1 : t * t * ((e + 1) * t - e);
},
Out: function(t) {
var e = 1.70158;
return t === 0 ? 0 : --t * t * ((e + 1) * t + e) + 1;
},
InOut: function(t) {
var e = 2.5949095;
return (t *= 2) < 1 ? 0.5 * (t * t * ((e + 1) * t - e)) : 0.5 * ((t -= 2) * t * ((e + 1) * t + e) + 2);
}
}),
Bounce: Object.freeze({
In: function(t) {
return 1 - d.Bounce.Out(1 - t);
},
Out: function(t) {
return t < 0.36363636363636365 ? 7.5625 * t * t : t < 0.7272727272727273 ? 7.5625 * (t -= 0.5454545454545454) * t + 0.75 : t < 0.9090909090909091 ? 7.5625 * (t -= 0.8181818181818182) * t + 0.9375 : 7.5625 * (t -= 0.9545454545454546) * t + 0.984375;
},
InOut: function(t) {
return t < 0.5 ? d.Bounce.In(t * 2) * 0.5 : d.Bounce.Out(t * 2 - 1) * 0.5 + 0.5;
}
}),
generatePow: function(t) {
return t === void 0 && (t = 4), t = t < Number.EPSILON ? Number.EPSILON : t, t = t > 1e4 ? 1e4 : t, {
In: function(e) {
return Math.pow(e, t);
},
Out: function(e) {
return 1 - Math.pow(1 - e, t);
},
InOut: function(e) {
return e < 0.5 ? Math.pow(e * 2, t) / 2 : (1 - Math.pow(2 - e * 2, t)) / 2 + 0.5;
}
};
}
}), _ = function() {
return performance.now();
}, w = (
/** @class */
function() {
function t() {
this._tweens = {}, this._tweensAddedDuringUpdate = {};
}
return t.prototype.getAll = function() {
var e = this;
return Object.keys(this._tweens).map(function(i) {
return e._tweens[i];
});
}, t.prototype.removeAll = function() {
this._tweens = {};
}, t.prototype.add = function(e) {
this._tweens[e.getId()] = e, this._tweensAddedDuringUpdate[e.getId()] = e;
}, t.prototype.remove = function(e) {
delete this._tweens[e.getId()], delete this._tweensAddedDuringUpdate[e.getId()];
}, t.prototype.update = function(e, i) {
e === void 0 && (e = _()), i === void 0 && (i = !1);
var r = Object.keys(this._tweens);
if (r.length === 0)
return !1;
for (; r.length > 0; ) {
this._tweensAddedDuringUpdate = {};
for (var n = 0; n < r.length; n++) {
var a = this._tweens[r[n]], s = !i;
a && a.update(e, s) === !1 && !i && delete this._tweens[r[n]];
}
r = Object.keys(this._tweensAddedDuringUpdate);
}
return !0;
}, t;
}()
), c = {
Linear: function(t, e) {
var i = t.length - 1, r = i * e, n = Math.floor(r), a = c.Utils.Linear;
return e < 0 ? a(t[0], t[1], r) : e > 1 ? a(t[i], t[i - 1], i - r) : a(t[n], t[n + 1 > i ? i : n + 1], r - n);
},
Bezier: function(t, e) {
for (var i = 0, r = t.length - 1, n = Math.pow, a = c.Utils.Bernstein, s = 0; s <= r; s++)
i += n(1 - e, r - s) * n(e, s) * t[s] * a(r, s);
return i;
},
CatmullRom: function(t, e) {
var i = t.length - 1, r = i * e, n = Math.floor(r), a = c.Utils.CatmullRom;
return t[0] === t[i] ? (e < 0 && (n = Math.floor(r = i * (1 + e))), a(t[(n - 1 + i) % i], t[n], t[(n + 1) % i], t[(n + 2) % i], r - n)) : e < 0 ? t[0] - (a(t[0], t[0], t[1], t[1], -r) - t[0]) : e > 1 ? t[i] - (a(t[i], t[i], t[i - 1], t[i - 1], r - i) - t[i]) : a(t[n ? n - 1 : 0], t[n], t[i < n + 1 ? i : n + 1], t[i < n + 2 ? i : n + 2], r - n);
},
Utils: {
Linear: function(t, e, i) {
return (e - t) * i + t;
},
Bernstein: function(t, e) {
var i = c.Utils.Factorial;
return i(t) / i(e) / i(t - e);
},
Factorial: function() {
var t = [1];
return function(e) {
var i = 1;
if (t[e])
return t[e];
for (var r = e; r > 1; r--)
i *= r;
return t[e] = i, i;
};
}(),
CatmullRom: function(t, e, i, r, n) {
var a = (i - t) * 0.5, s = (r - e) * 0.5, h = n * n, f = n * h;
return (2 * e - 2 * i + a + s) * f + (-3 * e + 3 * i - 2 * a - s) * h + a * n + e;
}
}
}, S = (
/** @class */
function() {
function t() {
}
return t.nextId = function() {
return t._nextId++;
}, t._nextId = 0, t;
}()
), g = new w(), T = (
/** @class */
function() {
function t(e, i) {
i === void 0 && (i = g), this._object = e, this._group = i, this._isPaused = !1, this._pauseStart = 0, this._valuesStart = {}, this._valuesEnd = {}, this._valuesStartRepeat = {}, this._duration = 1e3, this._isDynamic = !1, this._initialRepeat = 0, this._repeat = 0, this._yoyo = !1, this._isPlaying = !1, this._reversed = !1, this._delayTime = 0, this._startTime = 0, this._easingFunction = d.Linear.None, this._interpolationFunction = c.Linear, this._chainedTweens = [], this._onStartCallbackFired = !1, this._onEveryStartCallbackFired = !1, this._id = S.nextId(), this._isChainStopped = !1, this._propertiesAreSetUp = !1, this._goToEnd = !1;
}
return t.prototype.getId = function() {
return this._id;
}, t.prototype.isPlaying = function() {
return this._isPlaying;
}, t.prototype.isPaused = function() {
return this._isPaused;
}, t.prototype.to = function(e, i) {
if (i === void 0 && (i = 1e3), this._isPlaying)
throw new Error("Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.");
return this._valuesEnd = e, this._propertiesAreSetUp = !1, this._duration = i, this;
}, t.prototype.duration = function(e) {
return e === void 0 && (e = 1e3), this._duration = e, this;
}, t.prototype.dynamic = function(e) {
return e === void 0 && (e = !1), this._isDynamic = e, this;
}, t.prototype.start = function(e, i) {
if (e === void 0 && (e = _()), i === void 0 && (i = !1), this._isPlaying)
return this;
if (this._group && this._group.add(this), this._repeat = this._initialRepeat, this._reversed) {
this._reversed = !1;
for (var r in this._valuesStartRepeat)
this._swapEndStartRepeatValues(r), this._valuesStart[r] = this._valuesStartRepeat[r];
}
if (this._isPlaying = !0, this._isPaused = !1, this._onStartCallbackFired = !1, this._onEveryStartCallbackFired = !1, this._isChainStopped = !1, this._startTime = e, this._startTime += this._delayTime, !this._propertiesAreSetUp || i) {
if (this._propertiesAreSetUp = !0, !this._isDynamic) {
var n = {};
for (var a in this._valuesEnd)
n[a] = this._valuesEnd[a];
this._valuesEnd = n;
}
this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, i);
}
return this;
}, t.prototype.startFromCurrentValues = function(e) {
return this.start(e, !0);
}, t.prototype._setupProperties = function(e, i, r, n, a) {
for (var s in r) {
var h = e[s], f = Array.isArray(h), p = f ? "array" : typeof h, l = !f && Array.isArray(r[s]);
if (!(p === "undefined" || p === "function")) {
if (l) {
var o = r[s];
if (o.length === 0)
continue;
for (var C = [h], y = 0, P = o.length; y < P; y += 1) {
var I = this._handleRelativeValue(h, o[y]);
if (isNaN(I)) {
l = !1, console.warn("Found invalid interpolation list. Skipping.");
break;
}
C.push(I);
}
l && (r[s] = C);
}
if ((p === "object" || f) && h && !l) {
i[s] = f ? [] : {};
var b = h;
for (var v in b)
i[s][v] = b[v];
n[s] = f ? [] : {};
var o = r[s];
if (!this._isDynamic) {
var O = {};
for (var v in o)
O[v] = o[v];
r[s] = o = O;
}
this._setupProperties(b, i[s], o, n[s], a);
} else
(typeof i[s] == "undefined" || a) && (i[s] = h), f || (i[s] *= 1), l ? n[s] = r[s].slice().reverse() : n[s] = i[s] || 0;
}
}
}, t.prototype.stop = function() {
return this._isChainStopped || (this._isChainStopped = !0, this.stopChainedTweens()), this._isPlaying ? (this._group && this._group.remove(this), this._isPlaying = !1, this._isPaused = !1, this._onStopCallback && this._onStopCallback(this._object), this) : this;
}, t.prototype.end = function() {
return this._goToEnd = !0, this.update(1 / 0), this;
}, t.prototype.pause = function(e) {
return e === void 0 && (e = _()), this._isPaused || !this._isPlaying ? this : (this._isPaused = !0, this._pauseStart = e, this._group && this._group.remove(this), this);
}, t.prototype.resume = function(e) {
return e === void 0 && (e = _()), !this._isPaused || !this._isPlaying ? this : (this._isPaused = !1, this._startTime += e - this._pauseStart, this._pauseStart = 0, this._group && this._group.add(this), this);
}, t.prototype.stopChainedTweens = function() {
for (var e = 0, i = this._chainedTweens.length; e < i; e++)
this._chainedTweens[e].stop();
return this;
}, t.prototype.group = function(e) {
return e === void 0 && (e = g), this._group = e, this;
}, t.prototype.delay = function(e) {
return e === void 0 && (e = 0), this._delayTime = e, this;
}, t.prototype.repeat = function(e) {
return e === void 0 && (e = 0), this._initialRepeat = e, this._repeat = e, this;
}, t.prototype.repeatDelay = function(e) {
return this._repeatDelayTime = e, this;
}, t.prototype.yoyo = function(e) {
return e === void 0 && (e = !1), this._yoyo = e, this;
}, t.prototype.easing = function(e) {
return e === void 0 && (e = d.Linear.None), this._easingFunction = e, this;
}, t.prototype.interpolation = function(e) {
return e === void 0 && (e = c.Linear), this._interpolationFunction = e, this;
}, t.prototype.chain = function() {
for (var e = [], i = 0; i < arguments.length; i++)
e[i] = arguments[i];
return this._chainedTweens = e, this;
}, t.prototype.onStart = function(e) {
return this._onStartCallback = e, this;
}, t.prototype.onEveryStart = function(e) {
return this._onEveryStartCallback = e, this;
}, t.prototype.onUpdate = function(e) {
return this._onUpdateCallback = e, this;
}, t.prototype.onRepeat = function(e) {
return this._onRepeatCallback = e, this;
}, t.prototype.onComplete = function(e) {
return this._onCompleteCallback = e, this;
}, t.prototype.onStop = function(e) {
return this._onStopCallback = e, this;
}, t.prototype.update = function(e, i) {
if (e === void 0 && (e = _()), i === void 0 && (i = !0), this._isPaused)
return !0;
var r, n, a = this._startTime + this._duration;
if (!this._goToEnd && !this._isPlaying) {
if (e > a)
return !1;
i && this.start(e, !0);
}
if (this._goToEnd = !1, e < this._startTime)
return !0;
this._onStartCallbackFired === !1 && (this._onStartCallback && this._onStartCallback(this._object), this._onStartCallbackFired = !0), this._onEveryStartCallbackFired === !1 && (this._onEveryStartCallback && this._onEveryStartCallback(this._object), this._onEveryStartCallbackFired = !0), n = (e - this._startTime) / this._duration, n = this._duration === 0 || n > 1 ? 1 : n;
var s = this._easingFunction(n);
if (this._updateProperties(this._object, this._valuesStart, this._valuesEnd, s), this._onUpdateCallback && this._onUpdateCallback(this._object, n), n === 1)
if (this._repeat > 0) {
isFinite(this._repeat) && this._repeat--;
for (r in this._valuesStartRepeat)
!this._yoyo && typeof this._valuesEnd[r] == "string" && (this._valuesStartRepeat[r] = // eslint-disable-next-line
// @ts-ignore FIXME?
this._valuesStartRepeat[r] + parseFloat(this._valuesEnd[r])), this._yoyo && this._swapEndStartRepeatValues(r), this._valuesStart[r] = this._valuesStartRepeat[r];
return this._yoyo && (this._reversed = !this._reversed), this._repeatDelayTime !== void 0 ? this._startTime = e + this._repeatDelayTime : this._startTime = e + this._delayTime, this._onRepeatCallback && this._onRepeatCallback(this._object), this._onEveryStartCallbackFired = !1, !0;
} else {
this._onCompleteCallback && this._onCompleteCallback(this._object);
for (var h = 0, f = this._chainedTweens.length; h < f; h++)
this._chainedTweens[h].start(this._startTime + this._duration, !1);
return this._isPlaying = !1, !1;
}
return !0;
}, t.prototype._updateProperties = function(e, i, r, n) {
for (var a in r)
if (i[a] !== void 0) {
var s = i[a] || 0, h = r[a], f = Array.isArray(e[a]), p = Array.isArray(h), l = !f && p;
l ? e[a] = this._interpolationFunction(h, n) : typeof h == "object" && h ? this._updateProperties(e[a], s, h, n) : (h = this._handleRelativeValue(s, h), typeof h == "number" && (e[a] = s + (h - s) * n));
}
}, t.prototype._handleRelativeValue = function(e, i) {
return typeof i != "string" ? i : i.charAt(0) === "+" || i.charAt(0) === "-" ? e + parseFloat(i) : parseFloat(i);
}, t.prototype._swapEndStartRepeatValues = function(e) {
var i = this._valuesStartRepeat[e], r = this._valuesEnd[e];
typeof r == "string" ? this._valuesStartRepeat[e] = this._valuesStartRepeat[e] + parseFloat(r) : this._valuesStartRepeat[e] = this._valuesEnd[e], this._valuesEnd[e] = i;
}, t;
}()
), M = "20.0.3", E = S.nextId, u = g, R = u.getAll.bind(u), k = u.removeAll.bind(u), A = u.add.bind(u), j = u.remove.bind(u), F = u.update.bind(u), U = {
Easing: d,
Group: w,
Interpolation: c,
now: _,
Sequence: S,
nextId: E,
Tween: T,
VERSION: M,
getAll: R,
removeAll: k,
add: A,
remove: j,
update: F
};
export {
d as Easing,
T as Tween,
U as exports,
j as remove
};