tween.umd.js 31 KB

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