tween.esm.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. var NOW;
  2. // Include a performance.now polyfill.
  3. // In node.js, use process.hrtime.
  4. // eslint-disable-next-line
  5. // @ts-ignore
  6. if (typeof self === 'undefined' && typeof process !== 'undefined' && process.hrtime) {
  7. NOW = function () {
  8. // eslint-disable-next-line
  9. // @ts-ignore
  10. var time = process.hrtime();
  11. // Convert [seconds, nanoseconds] to milliseconds.
  12. return time[0] * 1000 + time[1] / 1000000;
  13. };
  14. }
  15. // In a browser, use self.performance.now if it is available.
  16. else if (typeof self !== 'undefined' && self.performance !== undefined && self.performance.now !== undefined) {
  17. // This must be bound, because directly assigning this function
  18. // leads to an invocation exception in Chrome.
  19. NOW = self.performance.now.bind(self.performance);
  20. }
  21. // Use Date.now if it is available.
  22. else if (Date.now !== undefined) {
  23. NOW = Date.now;
  24. }
  25. // Otherwise, use 'new Date().getTime()'.
  26. else {
  27. NOW = function () {
  28. return new Date().getTime();
  29. };
  30. }
  31. var NOW$1 = NOW;
  32. /**
  33. * Controlling groups of tweens
  34. *
  35. * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
  36. * In these cases, you may want to create your own smaller groups of tween
  37. */
  38. var Group = /** @class */ (function () {
  39. function Group() {
  40. this._tweens = {};
  41. this._tweensAddedDuringUpdate = {};
  42. }
  43. Group.prototype.getAll = function () {
  44. var _this = this;
  45. return Object.keys(this._tweens).map(function (tweenId) {
  46. return _this._tweens[tweenId];
  47. });
  48. };
  49. Group.prototype.removeAll = function () {
  50. this._tweens = {};
  51. };
  52. Group.prototype.add = function (tween) {
  53. this._tweens[tween.getId()] = tween;
  54. this._tweensAddedDuringUpdate[tween.getId()] = tween;
  55. };
  56. Group.prototype.remove = function (tween) {
  57. delete this._tweens[tween.getId()];
  58. delete this._tweensAddedDuringUpdate[tween.getId()];
  59. };
  60. Group.prototype.update = function (time, preserve) {
  61. var tweenIds = Object.keys(this._tweens);
  62. if (tweenIds.length === 0) {
  63. return false;
  64. }
  65. time = time !== undefined ? time : NOW$1();
  66. // Tweens are updated in "batches". If you add a new tween during an
  67. // update, then the new tween will be updated in the next batch.
  68. // If you remove a tween during an update, it may or may not be updated.
  69. // However, if the removed tween was added during the current batch,
  70. // then it will not be updated.
  71. while (tweenIds.length > 0) {
  72. this._tweensAddedDuringUpdate = {};
  73. for (var i = 0; i < tweenIds.length; i++) {
  74. var tween = this._tweens[tweenIds[i]];
  75. if (tween && tween.update(time) === false && !preserve) {
  76. delete this._tweens[tweenIds[i]];
  77. }
  78. }
  79. tweenIds = Object.keys(this._tweensAddedDuringUpdate);
  80. }
  81. return true;
  82. };
  83. return Group;
  84. }());
  85. /**
  86. * The Ease class provides a collection of easing functions for use with tween.js.
  87. */
  88. var Easing = {
  89. Linear: {
  90. None: function (amount) {
  91. return amount;
  92. },
  93. },
  94. Quadratic: {
  95. In: function (amount) {
  96. return amount * amount;
  97. },
  98. Out: function (amount) {
  99. return amount * (2 - amount);
  100. },
  101. InOut: function (amount) {
  102. if ((amount *= 2) < 1) {
  103. return 0.5 * amount * amount;
  104. }
  105. return -0.5 * (--amount * (amount - 2) - 1);
  106. },
  107. },
  108. Cubic: {
  109. In: function (amount) {
  110. return amount * amount * amount;
  111. },
  112. Out: function (amount) {
  113. return --amount * amount * amount + 1;
  114. },
  115. InOut: function (amount) {
  116. if ((amount *= 2) < 1) {
  117. return 0.5 * amount * amount * amount;
  118. }
  119. return 0.5 * ((amount -= 2) * amount * amount + 2);
  120. },
  121. },
  122. Quartic: {
  123. In: function (amount) {
  124. return amount * amount * amount * amount;
  125. },
  126. Out: function (amount) {
  127. return 1 - --amount * amount * amount * amount;
  128. },
  129. InOut: function (amount) {
  130. if ((amount *= 2) < 1) {
  131. return 0.5 * amount * amount * amount * amount;
  132. }
  133. return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
  134. },
  135. },
  136. Quintic: {
  137. In: function (amount) {
  138. return amount * amount * amount * amount * amount;
  139. },
  140. Out: function (amount) {
  141. return --amount * amount * amount * amount * amount + 1;
  142. },
  143. InOut: function (amount) {
  144. if ((amount *= 2) < 1) {
  145. return 0.5 * amount * amount * amount * amount * amount;
  146. }
  147. return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
  148. },
  149. },
  150. Sinusoidal: {
  151. In: function (amount) {
  152. return 1 - Math.cos((amount * Math.PI) / 2);
  153. },
  154. Out: function (amount) {
  155. return Math.sin((amount * Math.PI) / 2);
  156. },
  157. InOut: function (amount) {
  158. return 0.5 * (1 - Math.cos(Math.PI * amount));
  159. },
  160. },
  161. Exponential: {
  162. In: function (amount) {
  163. return amount === 0 ? 0 : Math.pow(1024, amount - 1);
  164. },
  165. Out: function (amount) {
  166. return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
  167. },
  168. InOut: function (amount) {
  169. if (amount === 0) {
  170. return 0;
  171. }
  172. if (amount === 1) {
  173. return 1;
  174. }
  175. if ((amount *= 2) < 1) {
  176. return 0.5 * Math.pow(1024, amount - 1);
  177. }
  178. return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
  179. },
  180. },
  181. Circular: {
  182. In: function (amount) {
  183. return 1 - Math.sqrt(1 - amount * amount);
  184. },
  185. Out: function (amount) {
  186. return Math.sqrt(1 - --amount * amount);
  187. },
  188. InOut: function (amount) {
  189. if ((amount *= 2) < 1) {
  190. return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
  191. }
  192. return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
  193. },
  194. },
  195. Elastic: {
  196. In: function (amount) {
  197. if (amount === 0) {
  198. return 0;
  199. }
  200. if (amount === 1) {
  201. return 1;
  202. }
  203. return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
  204. },
  205. Out: function (amount) {
  206. if (amount === 0) {
  207. return 0;
  208. }
  209. if (amount === 1) {
  210. return 1;
  211. }
  212. return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
  213. },
  214. InOut: function (amount) {
  215. if (amount === 0) {
  216. return 0;
  217. }
  218. if (amount === 1) {
  219. return 1;
  220. }
  221. amount *= 2;
  222. if (amount < 1) {
  223. return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
  224. }
  225. return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
  226. },
  227. },
  228. Back: {
  229. In: function (amount) {
  230. var s = 1.70158;
  231. return amount * amount * ((s + 1) * amount - s);
  232. },
  233. Out: function (amount) {
  234. var s = 1.70158;
  235. return --amount * amount * ((s + 1) * amount + s) + 1;
  236. },
  237. InOut: function (amount) {
  238. var s = 1.70158 * 1.525;
  239. if ((amount *= 2) < 1) {
  240. return 0.5 * (amount * amount * ((s + 1) * amount - s));
  241. }
  242. return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
  243. },
  244. },
  245. Bounce: {
  246. In: function (amount) {
  247. return 1 - Easing.Bounce.Out(1 - amount);
  248. },
  249. Out: function (amount) {
  250. if (amount < 1 / 2.75) {
  251. return 7.5625 * amount * amount;
  252. }
  253. else if (amount < 2 / 2.75) {
  254. return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
  255. }
  256. else if (amount < 2.5 / 2.75) {
  257. return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
  258. }
  259. else {
  260. return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
  261. }
  262. },
  263. InOut: function (amount) {
  264. if (amount < 0.5) {
  265. return Easing.Bounce.In(amount * 2) * 0.5;
  266. }
  267. return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
  268. },
  269. },
  270. };
  271. /**
  272. *
  273. */
  274. var Interpolation = {
  275. Linear: function (v, k) {
  276. var m = v.length - 1;
  277. var f = m * k;
  278. var i = Math.floor(f);
  279. var fn = Interpolation.Utils.Linear;
  280. if (k < 0) {
  281. return fn(v[0], v[1], f);
  282. }
  283. if (k > 1) {
  284. return fn(v[m], v[m - 1], m - f);
  285. }
  286. return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
  287. },
  288. Bezier: function (v, k) {
  289. var b = 0;
  290. var n = v.length - 1;
  291. var pw = Math.pow;
  292. var bn = Interpolation.Utils.Bernstein;
  293. for (var i = 0; i <= n; i++) {
  294. b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
  295. }
  296. return b;
  297. },
  298. CatmullRom: function (v, k) {
  299. var m = v.length - 1;
  300. var f = m * k;
  301. var i = Math.floor(f);
  302. var fn = Interpolation.Utils.CatmullRom;
  303. if (v[0] === v[m]) {
  304. if (k < 0) {
  305. i = Math.floor((f = m * (1 + k)));
  306. }
  307. return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
  308. }
  309. else {
  310. if (k < 0) {
  311. return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
  312. }
  313. if (k > 1) {
  314. return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
  315. }
  316. 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);
  317. }
  318. },
  319. Utils: {
  320. Linear: function (p0, p1, t) {
  321. return (p1 - p0) * t + p0;
  322. },
  323. Bernstein: function (n, i) {
  324. var fc = Interpolation.Utils.Factorial;
  325. return fc(n) / fc(i) / fc(n - i);
  326. },
  327. Factorial: (function () {
  328. var a = [1];
  329. return function (n) {
  330. var s = 1;
  331. if (a[n]) {
  332. return a[n];
  333. }
  334. for (var i = n; i > 1; i--) {
  335. s *= i;
  336. }
  337. a[n] = s;
  338. return s;
  339. };
  340. })(),
  341. CatmullRom: function (p0, p1, p2, p3, t) {
  342. var v0 = (p2 - p0) * 0.5;
  343. var v1 = (p3 - p1) * 0.5;
  344. var t2 = t * t;
  345. var t3 = t * t2;
  346. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  347. },
  348. },
  349. };
  350. /**
  351. * Utils
  352. */
  353. var Sequence = /** @class */ (function () {
  354. function Sequence() {
  355. }
  356. Sequence.nextId = function () {
  357. return Sequence._nextId++;
  358. };
  359. Sequence._nextId = 0;
  360. return Sequence;
  361. }());
  362. /**
  363. * Tween.js - Licensed under the MIT license
  364. * https://github.com/tweenjs/tween.js
  365. * ----------------------------------------------
  366. *
  367. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  368. * Thank you all, you're awesome!
  369. */
  370. var Tween = /** @class */ (function () {
  371. function Tween(_object, _group) {
  372. if (_group === void 0) { _group = TWEEN; }
  373. this._object = _object;
  374. this._group = _group;
  375. this._isPaused = false;
  376. this._pauseStart = 0;
  377. this._valuesStart = {};
  378. this._valuesEnd = {};
  379. this._valuesStartRepeat = {};
  380. this._duration = 1000;
  381. this._initialRepeat = 0;
  382. this._repeat = 0;
  383. this._yoyo = false;
  384. this._isPlaying = false;
  385. this._reversed = false;
  386. this._delayTime = 0;
  387. this._startTime = 0;
  388. this._easingFunction = TWEEN.Easing.Linear.None;
  389. this._interpolationFunction = TWEEN.Interpolation.Linear;
  390. this._chainedTweens = [];
  391. this._onStartCallbackFired = false;
  392. this._id = TWEEN.nextId();
  393. this._isChainStopped = false;
  394. }
  395. Tween.prototype.getId = function () {
  396. return this._id;
  397. };
  398. Tween.prototype.isPlaying = function () {
  399. return this._isPlaying;
  400. };
  401. Tween.prototype.isPaused = function () {
  402. return this._isPaused;
  403. };
  404. Tween.prototype.to = function (properties, duration) {
  405. // to (properties, duration) {
  406. for (var prop in properties) {
  407. this._valuesEnd[prop] = properties[prop];
  408. }
  409. if (duration !== undefined) {
  410. this._duration = duration;
  411. }
  412. return this;
  413. };
  414. Tween.prototype.duration = function (d) {
  415. this._duration = d;
  416. return this;
  417. };
  418. Tween.prototype.start = function (time) {
  419. if (this._isPlaying) {
  420. return this;
  421. }
  422. // eslint-disable-next-line
  423. // @ts-ignore FIXME?
  424. this._group.add(this);
  425. this._repeat = this._initialRepeat;
  426. if (this._reversed) {
  427. // If we were reversed (f.e. using the yoyo feature) then we need to
  428. // flip the tween direction back to forward.
  429. this._reversed = false;
  430. for (var property in this._valuesStartRepeat) {
  431. this._swapEndStartRepeatValues(property);
  432. this._valuesStart[property] = this._valuesStartRepeat[property];
  433. }
  434. }
  435. this._isPlaying = true;
  436. this._isPaused = false;
  437. this._onStartCallbackFired = false;
  438. this._isChainStopped = false;
  439. this._startTime =
  440. time !== undefined ? (typeof time === 'string' ? TWEEN.now() + parseFloat(time) : time) : TWEEN.now();
  441. this._startTime += this._delayTime;
  442. this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat);
  443. return this;
  444. };
  445. Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat) {
  446. for (var property in _valuesEnd) {
  447. var startValue = _object[property];
  448. var startValueIsArray = Array.isArray(startValue);
  449. var propType = startValueIsArray ? 'array' : typeof startValue;
  450. var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
  451. // If `to()` specifies a property that doesn't exist in the source object,
  452. // we should not set that property in the object
  453. if (propType === 'undefined' || propType === 'function') {
  454. continue;
  455. }
  456. // Check if an Array was provided as property value
  457. if (isInterpolationList) {
  458. var endValues = _valuesEnd[property];
  459. if (endValues.length === 0) {
  460. continue;
  461. }
  462. // handle an array of relative values
  463. endValues = endValues.map(this._handleRelativeValue.bind(this, startValue));
  464. // Create a local copy of the Array with the start value at the front
  465. _valuesEnd[property] = [startValue].concat(endValues);
  466. }
  467. // handle the deepness of the values
  468. if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
  469. _valuesStart[property] = startValueIsArray ? [] : {};
  470. // eslint-disable-next-line
  471. for (var prop in startValue) {
  472. // eslint-disable-next-line
  473. // @ts-ignore FIXME?
  474. _valuesStart[property][prop] = startValue[prop];
  475. }
  476. _valuesStartRepeat[property] = startValueIsArray ? [] : {}; // TODO? repeat nested values? And yoyo? And array values?
  477. // eslint-disable-next-line
  478. // @ts-ignore FIXME?
  479. this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]);
  480. }
  481. else {
  482. // Save the starting value, but only once.
  483. if (typeof _valuesStart[property] === 'undefined') {
  484. _valuesStart[property] = startValue;
  485. }
  486. if (!startValueIsArray) {
  487. // eslint-disable-next-line
  488. // @ts-ignore FIXME?
  489. _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
  490. }
  491. if (isInterpolationList) {
  492. // eslint-disable-next-line
  493. // @ts-ignore FIXME?
  494. _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
  495. }
  496. else {
  497. _valuesStartRepeat[property] = _valuesStart[property] || 0;
  498. }
  499. }
  500. }
  501. };
  502. Tween.prototype.stop = function () {
  503. if (!this._isChainStopped) {
  504. this._isChainStopped = true;
  505. this.stopChainedTweens();
  506. }
  507. if (!this._isPlaying) {
  508. return this;
  509. }
  510. // eslint-disable-next-line
  511. // @ts-ignore FIXME?
  512. this._group.remove(this);
  513. this._isPlaying = false;
  514. this._isPaused = false;
  515. if (this._onStopCallback) {
  516. this._onStopCallback(this._object);
  517. }
  518. return this;
  519. };
  520. Tween.prototype.end = function () {
  521. this.update(Infinity);
  522. return this;
  523. };
  524. Tween.prototype.pause = function (time) {
  525. if (this._isPaused || !this._isPlaying) {
  526. return this;
  527. }
  528. this._isPaused = true;
  529. this._pauseStart = time === undefined ? TWEEN.now() : time;
  530. // eslint-disable-next-line
  531. // @ts-ignore FIXME?
  532. this._group.remove(this);
  533. return this;
  534. };
  535. Tween.prototype.resume = function (time) {
  536. if (!this._isPaused || !this._isPlaying) {
  537. return this;
  538. }
  539. this._isPaused = false;
  540. this._startTime += (time === undefined ? TWEEN.now() : time) - this._pauseStart;
  541. this._pauseStart = 0;
  542. // eslint-disable-next-line
  543. // @ts-ignore FIXME?
  544. this._group.add(this);
  545. return this;
  546. };
  547. Tween.prototype.stopChainedTweens = function () {
  548. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  549. this._chainedTweens[i].stop();
  550. }
  551. return this;
  552. };
  553. Tween.prototype.group = function (group) {
  554. this._group = group;
  555. return this;
  556. };
  557. Tween.prototype.delay = function (amount) {
  558. this._delayTime = amount;
  559. return this;
  560. };
  561. Tween.prototype.repeat = function (times) {
  562. this._initialRepeat = times;
  563. this._repeat = times;
  564. return this;
  565. };
  566. Tween.prototype.repeatDelay = function (amount) {
  567. this._repeatDelayTime = amount;
  568. return this;
  569. };
  570. Tween.prototype.yoyo = function (yoyo) {
  571. this._yoyo = yoyo;
  572. return this;
  573. };
  574. Tween.prototype.easing = function (easingFunction) {
  575. this._easingFunction = easingFunction;
  576. return this;
  577. };
  578. Tween.prototype.interpolation = function (interpolationFunction) {
  579. this._interpolationFunction = interpolationFunction;
  580. return this;
  581. };
  582. Tween.prototype.chain = function () {
  583. var tweens = [];
  584. for (var _i = 0; _i < arguments.length; _i++) {
  585. tweens[_i] = arguments[_i];
  586. }
  587. this._chainedTweens = tweens;
  588. return this;
  589. };
  590. Tween.prototype.onStart = function (callback) {
  591. this._onStartCallback = callback;
  592. return this;
  593. };
  594. Tween.prototype.onUpdate = function (callback) {
  595. this._onUpdateCallback = callback;
  596. return this;
  597. };
  598. Tween.prototype.onRepeat = function (callback) {
  599. this._onRepeatCallback = callback;
  600. return this;
  601. };
  602. Tween.prototype.onComplete = function (callback) {
  603. this._onCompleteCallback = callback;
  604. return this;
  605. };
  606. Tween.prototype.onStop = function (callback) {
  607. this._onStopCallback = callback;
  608. return this;
  609. };
  610. Tween.prototype.update = function (time) {
  611. var property;
  612. var elapsed;
  613. var endTime = this._startTime + this._duration;
  614. if (time > endTime && !this._isPlaying) {
  615. return false;
  616. }
  617. // If the tween was already finished,
  618. if (!this.isPlaying) {
  619. this.start(time);
  620. }
  621. if (time < this._startTime) {
  622. return true;
  623. }
  624. if (this._onStartCallbackFired === false) {
  625. if (this._onStartCallback) {
  626. this._onStartCallback(this._object);
  627. }
  628. this._onStartCallbackFired = true;
  629. }
  630. elapsed = (time - this._startTime) / this._duration;
  631. elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
  632. var value = this._easingFunction(elapsed);
  633. // properties transformations
  634. this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
  635. if (this._onUpdateCallback) {
  636. this._onUpdateCallback(this._object, elapsed);
  637. }
  638. if (elapsed === 1) {
  639. if (this._repeat > 0) {
  640. if (isFinite(this._repeat)) {
  641. this._repeat--;
  642. }
  643. // Reassign starting values, restart by making startTime = now
  644. for (property in this._valuesStartRepeat) {
  645. if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
  646. this._valuesStartRepeat[property] =
  647. // eslint-disable-next-line
  648. // @ts-ignore FIXME?
  649. this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
  650. }
  651. if (this._yoyo) {
  652. this._swapEndStartRepeatValues(property);
  653. }
  654. this._valuesStart[property] = this._valuesStartRepeat[property];
  655. }
  656. if (this._yoyo) {
  657. this._reversed = !this._reversed;
  658. }
  659. if (this._repeatDelayTime !== undefined) {
  660. this._startTime = time + this._repeatDelayTime;
  661. }
  662. else {
  663. this._startTime = time + this._delayTime;
  664. }
  665. if (this._onRepeatCallback) {
  666. this._onRepeatCallback(this._object);
  667. }
  668. return true;
  669. }
  670. else {
  671. if (this._onCompleteCallback) {
  672. this._onCompleteCallback(this._object);
  673. }
  674. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  675. // Make the chained tweens start exactly at the time they should,
  676. // even if the `update()` method was called way past the duration of the tween
  677. this._chainedTweens[i].start(this._startTime + this._duration);
  678. }
  679. this._isPlaying = false;
  680. return false;
  681. }
  682. }
  683. return true;
  684. };
  685. Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
  686. for (var property in _valuesEnd) {
  687. // Don't update properties that do not exist in the source object
  688. if (_valuesStart[property] === undefined) {
  689. continue;
  690. }
  691. var start = _valuesStart[property] || 0;
  692. var end = _valuesEnd[property];
  693. var startIsArray = Array.isArray(_object[property]);
  694. var endIsArray = Array.isArray(end);
  695. var isInterpolationList = !startIsArray && endIsArray;
  696. if (isInterpolationList) {
  697. _object[property] = this._interpolationFunction(end, value);
  698. }
  699. else if (typeof end === 'object' && end) {
  700. // eslint-disable-next-line
  701. // @ts-ignore FIXME?
  702. this._updateProperties(_object[property], start, end, value);
  703. }
  704. else {
  705. // Parses relative end values with start as base (e.g.: +10, -3)
  706. end = this._handleRelativeValue(start, end);
  707. // Protect against non numeric properties.
  708. if (typeof end === 'number') {
  709. // eslint-disable-next-line
  710. // @ts-ignore FIXME?
  711. _object[property] = start + (end - start) * value;
  712. }
  713. }
  714. }
  715. };
  716. Tween.prototype._handleRelativeValue = function (start, end) {
  717. if (typeof end !== 'string') {
  718. return end;
  719. }
  720. if (end.charAt(0) === '+' || end.charAt(0) === '-') {
  721. return start + parseFloat(end);
  722. }
  723. else {
  724. return parseFloat(end);
  725. }
  726. };
  727. Tween.prototype._swapEndStartRepeatValues = function (property) {
  728. var tmp = this._valuesStartRepeat[property];
  729. if (typeof this._valuesEnd[property] === 'string') {
  730. // eslint-disable-next-line
  731. // @ts-ignore FIXME?
  732. this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
  733. }
  734. else {
  735. this._valuesStartRepeat[property] = this._valuesEnd[property];
  736. }
  737. this._valuesEnd[property] = tmp;
  738. };
  739. return Tween;
  740. }());
  741. var VERSION = '18.5.0';
  742. /**
  743. * Tween.js - Licensed under the MIT license
  744. * https://github.com/tweenjs/tween.js
  745. * ----------------------------------------------
  746. *
  747. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  748. * Thank you all, you're awesome!
  749. */
  750. var __extends = (this && this.__extends) || (function () {
  751. var extendStatics = function (d, b) {
  752. extendStatics = Object.setPrototypeOf ||
  753. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  754. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  755. return extendStatics(d, b);
  756. };
  757. return function (d, b) {
  758. extendStatics(d, b);
  759. function __() { this.constructor = d; }
  760. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  761. };
  762. })();
  763. /**
  764. * Controlling groups of tweens
  765. *
  766. * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
  767. * In these cases, you may want to create your own smaller groups of tween
  768. */
  769. var Main = /** @class */ (function (_super) {
  770. __extends(Main, _super);
  771. function Main() {
  772. var _this = _super !== null && _super.apply(this, arguments) || this;
  773. _this.version = VERSION;
  774. _this.now = NOW$1;
  775. _this.Group = Group;
  776. _this.Easing = Easing;
  777. _this.Interpolation = Interpolation;
  778. _this.nextId = Sequence.nextId;
  779. _this.Tween = Tween;
  780. return _this;
  781. }
  782. return Main;
  783. }(Group));
  784. var TWEEN = new Main();
  785. export default TWEEN;