| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TWEEN = {}));
- })(this, (function (exports) { 'use strict';
-
- /**
- * The Ease class provides a collection of easing functions for use with tween.js.
- */
- var Easing = Object.freeze({
- Linear: Object.freeze({
- None: function (amount) {
- return amount;
- },
- In: function (amount) {
- return amount;
- },
- Out: function (amount) {
- return amount;
- },
- InOut: function (amount) {
- return amount;
- },
- }),
- Quadratic: Object.freeze({
- In: function (amount) {
- return amount * amount;
- },
- Out: function (amount) {
- return amount * (2 - amount);
- },
- InOut: function (amount) {
- if ((amount *= 2) < 1) {
- return 0.5 * amount * amount;
- }
- return -0.5 * (--amount * (amount - 2) - 1);
- },
- }),
- Cubic: Object.freeze({
- In: function (amount) {
- return amount * amount * amount;
- },
- Out: function (amount) {
- return --amount * amount * amount + 1;
- },
- InOut: function (amount) {
- if ((amount *= 2) < 1) {
- return 0.5 * amount * amount * amount;
- }
- return 0.5 * ((amount -= 2) * amount * amount + 2);
- },
- }),
- Quartic: Object.freeze({
- In: function (amount) {
- return amount * amount * amount * amount;
- },
- Out: function (amount) {
- return 1 - --amount * amount * amount * amount;
- },
- InOut: function (amount) {
- if ((amount *= 2) < 1) {
- return 0.5 * amount * amount * amount * amount;
- }
- return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
- },
- }),
- Quintic: Object.freeze({
- In: function (amount) {
- return amount * amount * amount * amount * amount;
- },
- Out: function (amount) {
- return --amount * amount * amount * amount * amount + 1;
- },
- InOut: function (amount) {
- if ((amount *= 2) < 1) {
- return 0.5 * amount * amount * amount * amount * amount;
- }
- return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
- },
- }),
- Sinusoidal: Object.freeze({
- In: function (amount) {
- return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
- },
- Out: function (amount) {
- return Math.sin((amount * Math.PI) / 2);
- },
- InOut: function (amount) {
- return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
- },
- }),
- Exponential: Object.freeze({
- In: function (amount) {
- return amount === 0 ? 0 : Math.pow(1024, amount - 1);
- },
- Out: function (amount) {
- return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
- },
- InOut: function (amount) {
- if (amount === 0) {
- return 0;
- }
- if (amount === 1) {
- return 1;
- }
- if ((amount *= 2) < 1) {
- return 0.5 * Math.pow(1024, amount - 1);
- }
- return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
- },
- }),
- Circular: Object.freeze({
- In: function (amount) {
- return 1 - Math.sqrt(1 - amount * amount);
- },
- Out: function (amount) {
- return Math.sqrt(1 - --amount * amount);
- },
- InOut: function (amount) {
- if ((amount *= 2) < 1) {
- return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
- }
- return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
- },
- }),
- Elastic: Object.freeze({
- In: function (amount) {
- if (amount === 0) {
- return 0;
- }
- if (amount === 1) {
- return 1;
- }
- return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
- },
- Out: function (amount) {
- if (amount === 0) {
- return 0;
- }
- if (amount === 1) {
- return 1;
- }
- return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
- },
- InOut: function (amount) {
- if (amount === 0) {
- return 0;
- }
- if (amount === 1) {
- return 1;
- }
- amount *= 2;
- if (amount < 1) {
- return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
- }
- return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
- },
- }),
- Back: Object.freeze({
- In: function (amount) {
- var s = 1.70158;
- return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
- },
- Out: function (amount) {
- var s = 1.70158;
- return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
- },
- InOut: function (amount) {
- var s = 1.70158 * 1.525;
- if ((amount *= 2) < 1) {
- return 0.5 * (amount * amount * ((s + 1) * amount - s));
- }
- return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
- },
- }),
- Bounce: Object.freeze({
- In: function (amount) {
- return 1 - Easing.Bounce.Out(1 - amount);
- },
- Out: function (amount) {
- if (amount < 1 / 2.75) {
- return 7.5625 * amount * amount;
- }
- else if (amount < 2 / 2.75) {
- return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
- }
- else if (amount < 2.5 / 2.75) {
- return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
- }
- else {
- return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
- }
- },
- InOut: function (amount) {
- if (amount < 0.5) {
- return Easing.Bounce.In(amount * 2) * 0.5;
- }
- return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
- },
- }),
- generatePow: function (power) {
- if (power === void 0) { power = 4; }
- power = power < Number.EPSILON ? Number.EPSILON : power;
- power = power > 10000 ? 10000 : power;
- return {
- In: function (amount) {
- return Math.pow(amount, power);
- },
- Out: function (amount) {
- return 1 - Math.pow((1 - amount), power);
- },
- InOut: function (amount) {
- if (amount < 0.5) {
- return Math.pow((amount * 2), power) / 2;
- }
- return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
- },
- };
- },
- });
-
- var now = function () { return performance.now(); };
-
- /**
- * Controlling groups of tweens
- *
- * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
- * In these cases, you may want to create your own smaller groups of tween
- */
- var Group = /** @class */ (function () {
- function Group() {
- var tweens = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- tweens[_i] = arguments[_i];
- }
- this._tweens = {};
- this._tweensAddedDuringUpdate = {};
- this.add.apply(this, tweens);
- }
- Group.prototype.getAll = function () {
- var _this = this;
- return Object.keys(this._tweens).map(function (tweenId) { return _this._tweens[tweenId]; });
- };
- Group.prototype.removeAll = function () {
- this._tweens = {};
- };
- Group.prototype.add = function () {
- var _a;
- var tweens = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- tweens[_i] = arguments[_i];
- }
- for (var _b = 0, tweens_1 = tweens; _b < tweens_1.length; _b++) {
- var tween = tweens_1[_b];
- // Remove from any other group first, a tween can only be in one group at a time.
- // @ts-expect-error library internal access
- (_a = tween._group) === null || _a === void 0 ? void 0 : _a.remove(tween);
- // @ts-expect-error library internal access
- tween._group = this;
- this._tweens[tween.getId()] = tween;
- this._tweensAddedDuringUpdate[tween.getId()] = tween;
- }
- };
- Group.prototype.remove = function () {
- var tweens = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- tweens[_i] = arguments[_i];
- }
- for (var _a = 0, tweens_2 = tweens; _a < tweens_2.length; _a++) {
- var tween = tweens_2[_a];
- // @ts-expect-error library internal access
- tween._group = undefined;
- delete this._tweens[tween.getId()];
- delete this._tweensAddedDuringUpdate[tween.getId()];
- }
- };
- /** Return true if all tweens in the group are not paused or playing. */
- Group.prototype.allStopped = function () {
- return this.getAll().every(function (tween) { return !tween.isPlaying(); });
- };
- Group.prototype.update = function (time, preserve) {
- if (time === void 0) { time = now(); }
- if (preserve === void 0) { preserve = true; }
- var tweenIds = Object.keys(this._tweens);
- if (tweenIds.length === 0)
- return;
- // Tweens are updated in "batches". If you add a new tween during an
- // update, then the new tween will be updated in the next batch.
- // If you remove a tween during an update, it may or may not be updated.
- // However, if the removed tween was added during the current batch,
- // then it will not be updated.
- while (tweenIds.length > 0) {
- this._tweensAddedDuringUpdate = {};
- for (var i = 0; i < tweenIds.length; i++) {
- var tween = this._tweens[tweenIds[i]];
- var autoStart = !preserve;
- if (tween && tween.update(time, autoStart) === false && !preserve)
- this.remove(tween);
- }
- tweenIds = Object.keys(this._tweensAddedDuringUpdate);
- }
- };
- return Group;
- }());
-
- /**
- *
- */
- var Interpolation = {
- Linear: function (v, k) {
- var m = v.length - 1;
- var f = m * k;
- var i = Math.floor(f);
- var fn = Interpolation.Utils.Linear;
- if (k < 0) {
- return fn(v[0], v[1], f);
- }
- if (k > 1) {
- return fn(v[m], v[m - 1], m - f);
- }
- return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
- },
- Bezier: function (v, k) {
- var b = 0;
- var n = v.length - 1;
- var pw = Math.pow;
- var bn = Interpolation.Utils.Bernstein;
- for (var i = 0; i <= n; i++) {
- b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
- }
- return b;
- },
- CatmullRom: function (v, k) {
- var m = v.length - 1;
- var f = m * k;
- var i = Math.floor(f);
- var fn = Interpolation.Utils.CatmullRom;
- if (v[0] === v[m]) {
- if (k < 0) {
- i = Math.floor((f = m * (1 + k)));
- }
- return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
- }
- else {
- if (k < 0) {
- return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
- }
- if (k > 1) {
- return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
- }
- return fn(v[i ? i - 1 : 0], v[i], v[m < i + 1 ? m : i + 1], v[m < i + 2 ? m : i + 2], f - i);
- }
- },
- Utils: {
- Linear: function (p0, p1, t) {
- return (p1 - p0) * t + p0;
- },
- Bernstein: function (n, i) {
- var fc = Interpolation.Utils.Factorial;
- return fc(n) / fc(i) / fc(n - i);
- },
- Factorial: (function () {
- var a = [1];
- return function (n) {
- var s = 1;
- if (a[n]) {
- return a[n];
- }
- for (var i = n; i > 1; i--) {
- s *= i;
- }
- a[n] = s;
- return s;
- };
- })(),
- CatmullRom: function (p0, p1, p2, p3, t) {
- var v0 = (p2 - p0) * 0.5;
- var v1 = (p3 - p1) * 0.5;
- var t2 = t * t;
- var t3 = t * t2;
- return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
- },
- },
- };
-
- /**
- * Utils
- */
- var Sequence = /** @class */ (function () {
- function Sequence() {
- }
- Sequence.nextId = function () {
- return Sequence._nextId++;
- };
- Sequence._nextId = 0;
- return Sequence;
- }());
-
- var mainGroup = new Group();
-
- /**
- * Tween.js - Licensed under the MIT license
- * https://github.com/tweenjs/tween.js
- * ----------------------------------------------
- *
- * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
- * Thank you all, you're awesome!
- */
- var Tween = /** @class */ (function () {
- function Tween(object, group) {
- this._isPaused = false;
- this._pauseStart = 0;
- this._valuesStart = {};
- this._valuesEnd = {};
- this._valuesStartRepeat = {};
- this._duration = 1000;
- this._isDynamic = false;
- this._initialRepeat = 0;
- this._repeat = 0;
- this._yoyo = false;
- this._isPlaying = false;
- this._reversed = false;
- this._delayTime = 0;
- this._startTime = 0;
- this._easingFunction = Easing.Linear.None;
- this._interpolationFunction = Interpolation.Linear;
- // eslint-disable-next-line
- this._chainedTweens = [];
- this._onStartCallbackFired = false;
- this._onEveryStartCallbackFired = false;
- this._id = Sequence.nextId();
- this._isChainStopped = false;
- this._propertiesAreSetUp = false;
- this._goToEnd = false;
- this._object = object;
- if (typeof group === 'object') {
- this._group = group;
- group.add(this);
- }
- // Use "true" to restore old behavior (will be removed in future release).
- else if (group === true) {
- this._group = mainGroup;
- mainGroup.add(this);
- }
- }
- Tween.prototype.getId = function () {
- return this._id;
- };
- Tween.prototype.isPlaying = function () {
- return this._isPlaying;
- };
- Tween.prototype.isPaused = function () {
- return this._isPaused;
- };
- Tween.prototype.getDuration = function () {
- return this._duration;
- };
- Tween.prototype.to = function (target, duration) {
- if (duration === void 0) { duration = 1000; }
- if (this._isPlaying)
- throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
- this._valuesEnd = target;
- this._propertiesAreSetUp = false;
- this._duration = duration < 0 ? 0 : duration;
- return this;
- };
- Tween.prototype.duration = function (duration) {
- if (duration === void 0) { duration = 1000; }
- this._duration = duration < 0 ? 0 : duration;
- return this;
- };
- Tween.prototype.dynamic = function (dynamic) {
- if (dynamic === void 0) { dynamic = false; }
- this._isDynamic = dynamic;
- return this;
- };
- Tween.prototype.start = function (time, overrideStartingValues) {
- if (time === void 0) { time = now(); }
- if (overrideStartingValues === void 0) { overrideStartingValues = false; }
- if (this._isPlaying) {
- return this;
- }
- this._repeat = this._initialRepeat;
- if (this._reversed) {
- // If we were reversed (f.e. using the yoyo feature) then we need to
- // flip the tween direction back to forward.
- this._reversed = false;
- for (var property in this._valuesStartRepeat) {
- this._swapEndStartRepeatValues(property);
- this._valuesStart[property] = this._valuesStartRepeat[property];
- }
- }
- this._isPlaying = true;
- this._isPaused = false;
- this._onStartCallbackFired = false;
- this._onEveryStartCallbackFired = false;
- this._isChainStopped = false;
- this._startTime = time;
- this._startTime += this._delayTime;
- if (!this._propertiesAreSetUp || overrideStartingValues) {
- this._propertiesAreSetUp = true;
- // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
- if (!this._isDynamic) {
- var tmp = {};
- for (var prop in this._valuesEnd)
- tmp[prop] = this._valuesEnd[prop];
- this._valuesEnd = tmp;
- }
- this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
- }
- return this;
- };
- Tween.prototype.startFromCurrentValues = function (time) {
- return this.start(time, true);
- };
- Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
- for (var property in _valuesEnd) {
- var startValue = _object[property];
- var startValueIsArray = Array.isArray(startValue);
- var propType = startValueIsArray ? 'array' : typeof startValue;
- var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
- // If `to()` specifies a property that doesn't exist in the source object,
- // we should not set that property in the object
- if (propType === 'undefined' || propType === 'function') {
- continue;
- }
- // Check if an Array was provided as property value
- if (isInterpolationList) {
- var endValues = _valuesEnd[property];
- if (endValues.length === 0) {
- continue;
- }
- // Handle an array of relative values.
- // Creates a local copy of the Array with the start value at the front
- var temp = [startValue];
- for (var i = 0, l = endValues.length; i < l; i += 1) {
- var value = this._handleRelativeValue(startValue, endValues[i]);
- if (isNaN(value)) {
- isInterpolationList = false;
- console.warn('Found invalid interpolation list. Skipping.');
- break;
- }
- temp.push(value);
- }
- if (isInterpolationList) {
- // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
- _valuesEnd[property] = temp;
- // }
- }
- }
- // handle the deepness of the values
- if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
- _valuesStart[property] = startValueIsArray ? [] : {};
- var nestedObject = startValue;
- for (var prop in nestedObject) {
- _valuesStart[property][prop] = nestedObject[prop];
- }
- // TODO? repeat nested values? And yoyo? And array values?
- _valuesStartRepeat[property] = startValueIsArray ? [] : {};
- var endValues = _valuesEnd[property];
- // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
- if (!this._isDynamic) {
- var tmp = {};
- for (var prop in endValues)
- tmp[prop] = endValues[prop];
- _valuesEnd[property] = endValues = tmp;
- }
- this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
- }
- else {
- // Save the starting value, but only once unless override is requested.
- if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
- _valuesStart[property] = startValue;
- }
- if (!startValueIsArray) {
- // eslint-disable-next-line
- // @ts-ignore FIXME?
- _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
- }
- if (isInterpolationList) {
- // eslint-disable-next-line
- // @ts-ignore FIXME?
- _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
- }
- else {
- _valuesStartRepeat[property] = _valuesStart[property] || 0;
- }
- }
- }
- };
- Tween.prototype.stop = function () {
- if (!this._isChainStopped) {
- this._isChainStopped = true;
- this.stopChainedTweens();
- }
- if (!this._isPlaying) {
- return this;
- }
- this._isPlaying = false;
- this._isPaused = false;
- if (this._onStopCallback) {
- this._onStopCallback(this._object);
- }
- return this;
- };
- Tween.prototype.end = function () {
- this._goToEnd = true;
- this.update(this._startTime + this._duration);
- return this;
- };
- Tween.prototype.pause = function (time) {
- if (time === void 0) { time = now(); }
- if (this._isPaused || !this._isPlaying) {
- return this;
- }
- this._isPaused = true;
- this._pauseStart = time;
- return this;
- };
- Tween.prototype.resume = function (time) {
- if (time === void 0) { time = now(); }
- if (!this._isPaused || !this._isPlaying) {
- return this;
- }
- this._isPaused = false;
- this._startTime += time - this._pauseStart;
- this._pauseStart = 0;
- return this;
- };
- Tween.prototype.stopChainedTweens = function () {
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
- this._chainedTweens[i].stop();
- }
- return this;
- };
- Tween.prototype.group = function (group) {
- if (!group) {
- console.warn('tween.group() without args has been removed, use group.add(tween) instead.');
- return this;
- }
- group.add(this);
- return this;
- };
- /**
- * Removes the tween from whichever group it is in.
- */
- Tween.prototype.remove = function () {
- var _a;
- (_a = this._group) === null || _a === void 0 ? void 0 : _a.remove(this);
- return this;
- };
- Tween.prototype.delay = function (amount) {
- if (amount === void 0) { amount = 0; }
- this._delayTime = amount;
- return this;
- };
- Tween.prototype.repeat = function (times) {
- if (times === void 0) { times = 0; }
- this._initialRepeat = times;
- this._repeat = times;
- return this;
- };
- Tween.prototype.repeatDelay = function (amount) {
- this._repeatDelayTime = amount;
- return this;
- };
- Tween.prototype.yoyo = function (yoyo) {
- if (yoyo === void 0) { yoyo = false; }
- this._yoyo = yoyo;
- return this;
- };
- Tween.prototype.easing = function (easingFunction) {
- if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
- this._easingFunction = easingFunction;
- return this;
- };
- Tween.prototype.interpolation = function (interpolationFunction) {
- if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
- this._interpolationFunction = interpolationFunction;
- return this;
- };
- // eslint-disable-next-line
- Tween.prototype.chain = function () {
- var tweens = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- tweens[_i] = arguments[_i];
- }
- this._chainedTweens = tweens;
- return this;
- };
- Tween.prototype.onStart = function (callback) {
- this._onStartCallback = callback;
- return this;
- };
- Tween.prototype.onEveryStart = function (callback) {
- this._onEveryStartCallback = callback;
- return this;
- };
- Tween.prototype.onUpdate = function (callback) {
- this._onUpdateCallback = callback;
- return this;
- };
- Tween.prototype.onRepeat = function (callback) {
- this._onRepeatCallback = callback;
- return this;
- };
- Tween.prototype.onComplete = function (callback) {
- this._onCompleteCallback = callback;
- return this;
- };
- Tween.prototype.onStop = function (callback) {
- this._onStopCallback = callback;
- return this;
- };
- /**
- * @returns true if the tween is still playing after the update, false
- * otherwise (calling update on a paused tween still returns true because
- * it is still playing, just paused).
- *
- * @param autoStart - When true, calling update will implicitly call start()
- * as well. Note, if you stop() or end() the tween, but are still calling
- * update(), it will start again!
- */
- Tween.prototype.update = function (time, autoStart) {
- var _this = this;
- var _a;
- if (time === void 0) { time = now(); }
- if (autoStart === void 0) { autoStart = Tween.autoStartOnUpdate; }
- if (this._isPaused)
- return true;
- var property;
- if (!this._goToEnd && !this._isPlaying) {
- if (autoStart)
- this.start(time, true);
- else
- return false;
- }
- this._goToEnd = false;
- if (time < this._startTime) {
- return true;
- }
- if (this._onStartCallbackFired === false) {
- if (this._onStartCallback) {
- this._onStartCallback(this._object);
- }
- this._onStartCallbackFired = true;
- }
- if (this._onEveryStartCallbackFired === false) {
- if (this._onEveryStartCallback) {
- this._onEveryStartCallback(this._object);
- }
- this._onEveryStartCallbackFired = true;
- }
- var elapsedTime = time - this._startTime;
- var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
- var totalTime = this._duration + this._repeat * durationAndDelay;
- var calculateElapsedPortion = function () {
- if (_this._duration === 0)
- return 1;
- if (elapsedTime > totalTime) {
- return 1;
- }
- var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
- var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
- // TODO use %?
- // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
- var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
- if (portion === 0 && elapsedTime === _this._duration) {
- return 1;
- }
- return portion;
- };
- var elapsed = calculateElapsedPortion();
- var value = this._easingFunction(elapsed);
- // properties transformations
- this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
- if (this._onUpdateCallback) {
- this._onUpdateCallback(this._object, elapsed);
- }
- if (this._duration === 0 || elapsedTime >= this._duration) {
- if (this._repeat > 0) {
- var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
- if (isFinite(this._repeat)) {
- this._repeat -= completeCount;
- }
- // Reassign starting values, restart by making startTime = now
- for (property in this._valuesStartRepeat) {
- if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
- this._valuesStartRepeat[property] =
- // eslint-disable-next-line
- // @ts-ignore FIXME?
- this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
- }
- if (this._yoyo) {
- this._swapEndStartRepeatValues(property);
- }
- this._valuesStart[property] = this._valuesStartRepeat[property];
- }
- if (this._yoyo) {
- this._reversed = !this._reversed;
- }
- this._startTime += durationAndDelay * completeCount;
- if (this._onRepeatCallback) {
- this._onRepeatCallback(this._object);
- }
- this._onEveryStartCallbackFired = false;
- return true;
- }
- else {
- if (this._onCompleteCallback) {
- this._onCompleteCallback(this._object);
- }
- for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
- // Make the chained tweens start exactly at the time they should,
- // even if the `update()` method was called way past the duration of the tween
- this._chainedTweens[i].start(this._startTime + this._duration, false);
- }
- this._isPlaying = false;
- return false;
- }
- }
- return true;
- };
- Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
- for (var property in _valuesEnd) {
- // Don't update properties that do not exist in the source object
- if (_valuesStart[property] === undefined) {
- continue;
- }
- var start = _valuesStart[property] || 0;
- var end = _valuesEnd[property];
- var startIsArray = Array.isArray(_object[property]);
- var endIsArray = Array.isArray(end);
- var isInterpolationList = !startIsArray && endIsArray;
- if (isInterpolationList) {
- _object[property] = this._interpolationFunction(end, value);
- }
- else if (typeof end === 'object' && end) {
- // eslint-disable-next-line
- // @ts-ignore FIXME?
- this._updateProperties(_object[property], start, end, value);
- }
- else {
- // Parses relative end values with start as base (e.g.: +10, -3)
- end = this._handleRelativeValue(start, end);
- // Protect against non numeric properties.
- if (typeof end === 'number') {
- // eslint-disable-next-line
- // @ts-ignore FIXME?
- _object[property] = start + (end - start) * value;
- }
- }
- }
- };
- Tween.prototype._handleRelativeValue = function (start, end) {
- if (typeof end !== 'string') {
- return end;
- }
- if (end.charAt(0) === '+' || end.charAt(0) === '-') {
- return start + parseFloat(end);
- }
- return parseFloat(end);
- };
- Tween.prototype._swapEndStartRepeatValues = function (property) {
- var tmp = this._valuesStartRepeat[property];
- var endValue = this._valuesEnd[property];
- if (typeof endValue === 'string') {
- this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
- }
- else {
- this._valuesStartRepeat[property] = this._valuesEnd[property];
- }
- this._valuesEnd[property] = tmp;
- };
- Tween.autoStartOnUpdate = false;
- return Tween;
- }());
-
- var VERSION = '25.0.0';
-
- /**
- * Tween.js - Licensed under the MIT license
- * https://github.com/tweenjs/tween.js
- * ----------------------------------------------
- *
- * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
- * Thank you all, you're awesome!
- */
- var nextId = Sequence.nextId;
- /**
- * Controlling groups of tweens
- *
- * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
- * In these cases, you may want to create your own smaller groups of tweens.
- */
- var TWEEN = mainGroup;
- // This is the best way to export things in a way that's compatible with both ES
- // Modules and CommonJS, without build hacks, and so as not to break the
- // existing API.
- // https://github.com/rollup/rollup/issues/1961#issuecomment-423037881
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- var getAll = TWEEN.getAll.bind(TWEEN);
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- var removeAll = TWEEN.removeAll.bind(TWEEN);
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- var add = TWEEN.add.bind(TWEEN);
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- var remove = TWEEN.remove.bind(TWEEN);
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- var update = TWEEN.update.bind(TWEEN);
- var exports$1 = {
- Easing: Easing,
- Group: Group,
- Interpolation: Interpolation,
- now: now,
- Sequence: Sequence,
- nextId: nextId,
- Tween: Tween,
- VERSION: VERSION,
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- getAll: getAll,
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- removeAll: removeAll,
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- add: add,
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- remove: remove,
- /**
- * @deprecated The global TWEEN Group will be removed in a following major
- * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
- * group.
- *
- * Old code:
- *
- * ```js
- * import * as TWEEN from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new TWEEN.Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * TWEEN.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- *
- * New code:
- *
- * ```js
- * import {Tween, Group} from '@tweenjs/tween.js'
- *
- * //...
- *
- * const tween = new Tween(obj)
- * const tween2 = new TWEEN.Tween(obj2)
- *
- * //...
- *
- * const group = new Group()
- * group.add(tween)
- * group.add(tween2)
- *
- * //...
- *
- * requestAnimationFrame(function loop(time) {
- * group.update(time)
- * requestAnimationFrame(loop)
- * })
- * ```
- */
- update: update,
- };
-
- exports.Easing = Easing;
- exports.Group = Group;
- exports.Interpolation = Interpolation;
- exports.Sequence = Sequence;
- exports.Tween = Tween;
- exports.VERSION = VERSION;
- exports.add = add;
- exports.default = exports$1;
- exports.getAll = getAll;
- exports.nextId = nextId;
- exports.now = now;
- exports.remove = remove;
- exports.removeAll = removeAll;
- exports.update = update;
-
- Object.defineProperty(exports, '__esModule', { value: true });
-
- }));
|