tween.amd.js 31 KB

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