tween.umd.js 31 KB

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