tween.cjs.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. /**
  4. * The Ease class provides a collection of easing functions for use with tween.js.
  5. */
  6. var Easing = {
  7. Linear: {
  8. None: function (amount) {
  9. return amount;
  10. },
  11. },
  12. Quadratic: {
  13. In: function (amount) {
  14. return amount * amount;
  15. },
  16. Out: function (amount) {
  17. return amount * (2 - amount);
  18. },
  19. InOut: function (amount) {
  20. if ((amount *= 2) < 1) {
  21. return 0.5 * amount * amount;
  22. }
  23. return -0.5 * (--amount * (amount - 2) - 1);
  24. },
  25. },
  26. Cubic: {
  27. In: function (amount) {
  28. return amount * amount * amount;
  29. },
  30. Out: function (amount) {
  31. return --amount * amount * amount + 1;
  32. },
  33. InOut: function (amount) {
  34. if ((amount *= 2) < 1) {
  35. return 0.5 * amount * amount * amount;
  36. }
  37. return 0.5 * ((amount -= 2) * amount * amount + 2);
  38. },
  39. },
  40. Quartic: {
  41. In: function (amount) {
  42. return amount * amount * amount * amount;
  43. },
  44. Out: function (amount) {
  45. return 1 - --amount * amount * amount * amount;
  46. },
  47. InOut: function (amount) {
  48. if ((amount *= 2) < 1) {
  49. return 0.5 * amount * amount * amount * amount;
  50. }
  51. return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
  52. },
  53. },
  54. Quintic: {
  55. In: function (amount) {
  56. return amount * amount * amount * amount * amount;
  57. },
  58. Out: function (amount) {
  59. return --amount * amount * amount * amount * amount + 1;
  60. },
  61. InOut: function (amount) {
  62. if ((amount *= 2) < 1) {
  63. return 0.5 * amount * amount * amount * amount * amount;
  64. }
  65. return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
  66. },
  67. },
  68. Sinusoidal: {
  69. In: function (amount) {
  70. return 1 - Math.cos((amount * Math.PI) / 2);
  71. },
  72. Out: function (amount) {
  73. return Math.sin((amount * Math.PI) / 2);
  74. },
  75. InOut: function (amount) {
  76. return 0.5 * (1 - Math.cos(Math.PI * amount));
  77. },
  78. },
  79. Exponential: {
  80. In: function (amount) {
  81. return amount === 0 ? 0 : Math.pow(1024, amount - 1);
  82. },
  83. Out: function (amount) {
  84. return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
  85. },
  86. InOut: function (amount) {
  87. if (amount === 0) {
  88. return 0;
  89. }
  90. if (amount === 1) {
  91. return 1;
  92. }
  93. if ((amount *= 2) < 1) {
  94. return 0.5 * Math.pow(1024, amount - 1);
  95. }
  96. return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
  97. },
  98. },
  99. Circular: {
  100. In: function (amount) {
  101. return 1 - Math.sqrt(1 - amount * amount);
  102. },
  103. Out: function (amount) {
  104. return Math.sqrt(1 - --amount * amount);
  105. },
  106. InOut: function (amount) {
  107. if ((amount *= 2) < 1) {
  108. return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
  109. }
  110. return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
  111. },
  112. },
  113. Elastic: {
  114. In: function (amount) {
  115. if (amount === 0) {
  116. return 0;
  117. }
  118. if (amount === 1) {
  119. return 1;
  120. }
  121. return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
  122. },
  123. Out: function (amount) {
  124. if (amount === 0) {
  125. return 0;
  126. }
  127. if (amount === 1) {
  128. return 1;
  129. }
  130. return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
  131. },
  132. InOut: function (amount) {
  133. if (amount === 0) {
  134. return 0;
  135. }
  136. if (amount === 1) {
  137. return 1;
  138. }
  139. amount *= 2;
  140. if (amount < 1) {
  141. return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
  142. }
  143. return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
  144. },
  145. },
  146. Back: {
  147. In: function (amount) {
  148. var s = 1.70158;
  149. return amount * amount * ((s + 1) * amount - s);
  150. },
  151. Out: function (amount) {
  152. var s = 1.70158;
  153. return --amount * amount * ((s + 1) * amount + s) + 1;
  154. },
  155. InOut: function (amount) {
  156. var s = 1.70158 * 1.525;
  157. if ((amount *= 2) < 1) {
  158. return 0.5 * (amount * amount * ((s + 1) * amount - s));
  159. }
  160. return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
  161. },
  162. },
  163. Bounce: {
  164. In: function (amount) {
  165. return 1 - Easing.Bounce.Out(1 - amount);
  166. },
  167. Out: function (amount) {
  168. if (amount < 1 / 2.75) {
  169. return 7.5625 * amount * amount;
  170. }
  171. else if (amount < 2 / 2.75) {
  172. return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
  173. }
  174. else if (amount < 2.5 / 2.75) {
  175. return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
  176. }
  177. else {
  178. return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
  179. }
  180. },
  181. InOut: function (amount) {
  182. if (amount < 0.5) {
  183. return Easing.Bounce.In(amount * 2) * 0.5;
  184. }
  185. return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
  186. },
  187. },
  188. };
  189. var now;
  190. // Include a performance.now polyfill.
  191. // In node.js, use process.hrtime.
  192. // eslint-disable-next-line
  193. // @ts-ignore
  194. if (typeof self === 'undefined' && typeof process !== 'undefined' && process.hrtime) {
  195. now = function () {
  196. // eslint-disable-next-line
  197. // @ts-ignore
  198. var time = process.hrtime();
  199. // Convert [seconds, nanoseconds] to milliseconds.
  200. return time[0] * 1000 + time[1] / 1000000;
  201. };
  202. }
  203. // In a browser, use self.performance.now if it is available.
  204. else if (typeof self !== 'undefined' && self.performance !== undefined && self.performance.now !== undefined) {
  205. // This must be bound, because directly assigning this function
  206. // leads to an invocation exception in Chrome.
  207. now = self.performance.now.bind(self.performance);
  208. }
  209. // Use Date.now if it is available.
  210. else if (Date.now !== undefined) {
  211. now = Date.now;
  212. }
  213. // Otherwise, use 'new Date().getTime()'.
  214. else {
  215. now = function () {
  216. return new Date().getTime();
  217. };
  218. }
  219. var now$1 = now;
  220. /**
  221. * Controlling groups of tweens
  222. *
  223. * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
  224. * In these cases, you may want to create your own smaller groups of tween
  225. */
  226. var Group = /** @class */ (function () {
  227. function Group() {
  228. this._tweens = {};
  229. this._tweensAddedDuringUpdate = {};
  230. }
  231. Group.prototype.getAll = function () {
  232. var _this = this;
  233. return Object.keys(this._tweens).map(function (tweenId) {
  234. return _this._tweens[tweenId];
  235. });
  236. };
  237. Group.prototype.removeAll = function () {
  238. this._tweens = {};
  239. };
  240. Group.prototype.add = function (tween) {
  241. this._tweens[tween.getId()] = tween;
  242. this._tweensAddedDuringUpdate[tween.getId()] = tween;
  243. };
  244. Group.prototype.remove = function (tween) {
  245. delete this._tweens[tween.getId()];
  246. delete this._tweensAddedDuringUpdate[tween.getId()];
  247. };
  248. Group.prototype.update = function (time, preserve) {
  249. if (time === void 0) { time = now$1(); }
  250. if (preserve === void 0) { preserve = false; }
  251. var tweenIds = Object.keys(this._tweens);
  252. if (tweenIds.length === 0) {
  253. return false;
  254. }
  255. // Tweens are updated in "batches". If you add a new tween during an
  256. // update, then the new tween will be updated in the next batch.
  257. // If you remove a tween during an update, it may or may not be updated.
  258. // However, if the removed tween was added during the current batch,
  259. // then it will not be updated.
  260. while (tweenIds.length > 0) {
  261. this._tweensAddedDuringUpdate = {};
  262. for (var i = 0; i < tweenIds.length; i++) {
  263. var tween = this._tweens[tweenIds[i]];
  264. var autoStart = !preserve;
  265. if (tween && tween.update(time, autoStart) === false && !preserve) {
  266. delete this._tweens[tweenIds[i]];
  267. }
  268. }
  269. tweenIds = Object.keys(this._tweensAddedDuringUpdate);
  270. }
  271. return true;
  272. };
  273. return Group;
  274. }());
  275. /**
  276. *
  277. */
  278. var Interpolation = {
  279. Linear: function (v, k) {
  280. var m = v.length - 1;
  281. var f = m * k;
  282. var i = Math.floor(f);
  283. var fn = Interpolation.Utils.Linear;
  284. if (k < 0) {
  285. return fn(v[0], v[1], f);
  286. }
  287. if (k > 1) {
  288. return fn(v[m], v[m - 1], m - f);
  289. }
  290. return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
  291. },
  292. Bezier: function (v, k) {
  293. var b = 0;
  294. var n = v.length - 1;
  295. var pw = Math.pow;
  296. var bn = Interpolation.Utils.Bernstein;
  297. for (var i = 0; i <= n; i++) {
  298. b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
  299. }
  300. return b;
  301. },
  302. CatmullRom: function (v, k) {
  303. var m = v.length - 1;
  304. var f = m * k;
  305. var i = Math.floor(f);
  306. var fn = Interpolation.Utils.CatmullRom;
  307. if (v[0] === v[m]) {
  308. if (k < 0) {
  309. i = Math.floor((f = m * (1 + k)));
  310. }
  311. return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
  312. }
  313. else {
  314. if (k < 0) {
  315. return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
  316. }
  317. if (k > 1) {
  318. return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
  319. }
  320. 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);
  321. }
  322. },
  323. Utils: {
  324. Linear: function (p0, p1, t) {
  325. return (p1 - p0) * t + p0;
  326. },
  327. Bernstein: function (n, i) {
  328. var fc = Interpolation.Utils.Factorial;
  329. return fc(n) / fc(i) / fc(n - i);
  330. },
  331. Factorial: (function () {
  332. var a = [1];
  333. return function (n) {
  334. var s = 1;
  335. if (a[n]) {
  336. return a[n];
  337. }
  338. for (var i = n; i > 1; i--) {
  339. s *= i;
  340. }
  341. a[n] = s;
  342. return s;
  343. };
  344. })(),
  345. CatmullRom: function (p0, p1, p2, p3, t) {
  346. var v0 = (p2 - p0) * 0.5;
  347. var v1 = (p3 - p1) * 0.5;
  348. var t2 = t * t;
  349. var t3 = t * t2;
  350. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  351. },
  352. },
  353. };
  354. /**
  355. * Utils
  356. */
  357. var Sequence = /** @class */ (function () {
  358. function Sequence() {
  359. }
  360. Sequence.nextId = function () {
  361. return Sequence._nextId++;
  362. };
  363. Sequence._nextId = 0;
  364. return Sequence;
  365. }());
  366. var mainGroup = new Group();
  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 = mainGroup; }
  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 = Easing.Linear.None;
  394. this._interpolationFunction = Interpolation.Linear;
  395. this._chainedTweens = [];
  396. this._onStartCallbackFired = false;
  397. this._id = Sequence.nextId();
  398. this._isChainStopped = false;
  399. this._goToEnd = false;
  400. }
  401. Tween.prototype.getId = function () {
  402. return this._id;
  403. };
  404. Tween.prototype.isPlaying = function () {
  405. return this._isPlaying;
  406. };
  407. Tween.prototype.isPaused = function () {
  408. return this._isPaused;
  409. };
  410. Tween.prototype.to = function (properties, duration) {
  411. // TODO? restore this, then update the 07_dynamic_to example to set fox
  412. // tween's to on each update. That way the behavior is opt-in (there's
  413. // currently no opt-out).
  414. // for (const prop in properties) this._valuesEnd[prop] = properties[prop]
  415. this._valuesEnd = Object.create(properties);
  416. if (duration !== undefined) {
  417. this._duration = duration;
  418. }
  419. return this;
  420. };
  421. Tween.prototype.duration = function (d) {
  422. this._duration = d;
  423. return this;
  424. };
  425. Tween.prototype.start = function (time) {
  426. if (this._isPlaying) {
  427. return this;
  428. }
  429. // eslint-disable-next-line
  430. this._group && this._group.add(this);
  431. this._repeat = this._initialRepeat;
  432. if (this._reversed) {
  433. // If we were reversed (f.e. using the yoyo feature) then we need to
  434. // flip the tween direction back to forward.
  435. this._reversed = false;
  436. for (var property in this._valuesStartRepeat) {
  437. this._swapEndStartRepeatValues(property);
  438. this._valuesStart[property] = this._valuesStartRepeat[property];
  439. }
  440. }
  441. this._isPlaying = true;
  442. this._isPaused = false;
  443. this._onStartCallbackFired = false;
  444. this._isChainStopped = false;
  445. this._startTime = time !== undefined ? (typeof time === 'string' ? now$1() + parseFloat(time) : time) : now$1();
  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. this._group && this._group.remove(this);
  517. this._isPlaying = false;
  518. this._isPaused = false;
  519. if (this._onStopCallback) {
  520. this._onStopCallback(this._object);
  521. }
  522. return this;
  523. };
  524. Tween.prototype.end = function () {
  525. this._goToEnd = true;
  526. this.update(Infinity);
  527. return this;
  528. };
  529. Tween.prototype.pause = function (time) {
  530. if (time === void 0) { time = now$1(); }
  531. if (this._isPaused || !this._isPlaying) {
  532. return this;
  533. }
  534. this._isPaused = true;
  535. this._pauseStart = time;
  536. // eslint-disable-next-line
  537. this._group && this._group.remove(this);
  538. return this;
  539. };
  540. Tween.prototype.resume = function (time) {
  541. if (time === void 0) { time = now$1(); }
  542. if (!this._isPaused || !this._isPlaying) {
  543. return this;
  544. }
  545. this._isPaused = false;
  546. this._startTime += time - this._pauseStart;
  547. this._pauseStart = 0;
  548. // eslint-disable-next-line
  549. this._group && 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. /**
  616. * @returns true if the tween is still playing after the update, false
  617. * otherwise (calling update on a paused tween still returns true because
  618. * it is still playing, just paused).
  619. */
  620. Tween.prototype.update = function (time, autoStart) {
  621. if (time === void 0) { time = now$1(); }
  622. if (autoStart === void 0) { autoStart = true; }
  623. if (this._isPaused)
  624. return true;
  625. var property;
  626. var elapsed;
  627. var endTime = this._startTime + this._duration;
  628. if (!this._goToEnd && !this._isPlaying) {
  629. if (time > endTime)
  630. return false;
  631. if (autoStart)
  632. this.start(time);
  633. }
  634. this._goToEnd = false;
  635. if (time < this._startTime) {
  636. return true;
  637. }
  638. if (this._onStartCallbackFired === false) {
  639. if (this._onStartCallback) {
  640. this._onStartCallback(this._object);
  641. }
  642. this._onStartCallbackFired = true;
  643. }
  644. elapsed = (time - this._startTime) / this._duration;
  645. elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
  646. var value = this._easingFunction(elapsed);
  647. // properties transformations
  648. this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
  649. if (this._onUpdateCallback) {
  650. this._onUpdateCallback(this._object, elapsed);
  651. }
  652. if (elapsed === 1) {
  653. if (this._repeat > 0) {
  654. if (isFinite(this._repeat)) {
  655. this._repeat--;
  656. }
  657. // Reassign starting values, restart by making startTime = now
  658. for (property in this._valuesStartRepeat) {
  659. if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
  660. this._valuesStartRepeat[property] =
  661. // eslint-disable-next-line
  662. // @ts-ignore FIXME?
  663. this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
  664. }
  665. if (this._yoyo) {
  666. this._swapEndStartRepeatValues(property);
  667. }
  668. this._valuesStart[property] = this._valuesStartRepeat[property];
  669. }
  670. if (this._yoyo) {
  671. this._reversed = !this._reversed;
  672. }
  673. if (this._repeatDelayTime !== undefined) {
  674. this._startTime = time + this._repeatDelayTime;
  675. }
  676. else {
  677. this._startTime = time + this._delayTime;
  678. }
  679. if (this._onRepeatCallback) {
  680. this._onRepeatCallback(this._object);
  681. }
  682. return true;
  683. }
  684. else {
  685. if (this._onCompleteCallback) {
  686. this._onCompleteCallback(this._object);
  687. }
  688. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  689. // Make the chained tweens start exactly at the time they should,
  690. // even if the `update()` method was called way past the duration of the tween
  691. this._chainedTweens[i].start(this._startTime + this._duration);
  692. }
  693. this._isPlaying = false;
  694. return false;
  695. }
  696. }
  697. return true;
  698. };
  699. Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
  700. for (var property in _valuesEnd) {
  701. // Don't update properties that do not exist in the source object
  702. if (_valuesStart[property] === undefined) {
  703. continue;
  704. }
  705. var start = _valuesStart[property] || 0;
  706. var end = _valuesEnd[property];
  707. var startIsArray = Array.isArray(_object[property]);
  708. var endIsArray = Array.isArray(end);
  709. var isInterpolationList = !startIsArray && endIsArray;
  710. if (isInterpolationList) {
  711. _object[property] = this._interpolationFunction(end, value);
  712. }
  713. else if (typeof end === 'object' && end) {
  714. // eslint-disable-next-line
  715. // @ts-ignore FIXME?
  716. this._updateProperties(_object[property], start, end, value);
  717. }
  718. else {
  719. // Parses relative end values with start as base (e.g.: +10, -3)
  720. end = this._handleRelativeValue(start, end);
  721. // Protect against non numeric properties.
  722. if (typeof end === 'number') {
  723. // eslint-disable-next-line
  724. // @ts-ignore FIXME?
  725. _object[property] = start + (end - start) * value;
  726. }
  727. }
  728. }
  729. };
  730. Tween.prototype._handleRelativeValue = function (start, end) {
  731. if (typeof end !== 'string') {
  732. return end;
  733. }
  734. if (end.charAt(0) === '+' || end.charAt(0) === '-') {
  735. return start + parseFloat(end);
  736. }
  737. else {
  738. return parseFloat(end);
  739. }
  740. };
  741. Tween.prototype._swapEndStartRepeatValues = function (property) {
  742. var tmp = this._valuesStartRepeat[property];
  743. var endValue = this._valuesEnd[property];
  744. if (typeof endValue === 'string') {
  745. this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
  746. }
  747. else {
  748. this._valuesStartRepeat[property] = this._valuesEnd[property];
  749. }
  750. this._valuesEnd[property] = tmp;
  751. };
  752. return Tween;
  753. }());
  754. var VERSION = '18.6.4';
  755. /**
  756. * Tween.js - Licensed under the MIT license
  757. * https://github.com/tweenjs/tween.js
  758. * ----------------------------------------------
  759. *
  760. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  761. * Thank you all, you're awesome!
  762. */
  763. var nextId = Sequence.nextId;
  764. /**
  765. * Controlling groups of tweens
  766. *
  767. * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
  768. * In these cases, you may want to create your own smaller groups of tweens.
  769. */
  770. var TWEEN = mainGroup;
  771. // This is the best way to export things in a way that's compatible with both ES
  772. // Modules and CommonJS, without build hacks, and so as not to break the
  773. // existing API.
  774. // https://github.com/rollup/rollup/issues/1961#issuecomment-423037881
  775. var getAll = TWEEN.getAll.bind(TWEEN);
  776. var removeAll = TWEEN.removeAll.bind(TWEEN);
  777. var add = TWEEN.add.bind(TWEEN);
  778. var remove = TWEEN.remove.bind(TWEEN);
  779. var update = TWEEN.update.bind(TWEEN);
  780. var exports$1 = {
  781. Easing: Easing,
  782. Group: Group,
  783. Interpolation: Interpolation,
  784. now: now$1,
  785. Sequence: Sequence,
  786. nextId: nextId,
  787. Tween: Tween,
  788. VERSION: VERSION,
  789. getAll: getAll,
  790. removeAll: removeAll,
  791. add: add,
  792. remove: remove,
  793. update: update,
  794. };
  795. exports.Easing = Easing;
  796. exports.Group = Group;
  797. exports.Interpolation = Interpolation;
  798. exports.Sequence = Sequence;
  799. exports.Tween = Tween;
  800. exports.VERSION = VERSION;
  801. exports.add = add;
  802. exports.default = exports$1;
  803. exports.getAll = getAll;
  804. exports.nextId = nextId;
  805. exports.now = now$1;
  806. exports.remove = remove;
  807. exports.removeAll = removeAll;
  808. exports.update = update;