物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1409 lines
46 KiB

  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 = Object.freeze({
  10. Linear: Object.freeze({
  11. None: function (amount) {
  12. return amount;
  13. },
  14. In: function (amount) {
  15. return amount;
  16. },
  17. Out: function (amount) {
  18. return amount;
  19. },
  20. InOut: function (amount) {
  21. return amount;
  22. },
  23. }),
  24. Quadratic: Object.freeze({
  25. In: function (amount) {
  26. return amount * amount;
  27. },
  28. Out: function (amount) {
  29. return amount * (2 - amount);
  30. },
  31. InOut: function (amount) {
  32. if ((amount *= 2) < 1) {
  33. return 0.5 * amount * amount;
  34. }
  35. return -0.5 * (--amount * (amount - 2) - 1);
  36. },
  37. }),
  38. Cubic: Object.freeze({
  39. In: function (amount) {
  40. return amount * amount * amount;
  41. },
  42. Out: function (amount) {
  43. return --amount * amount * amount + 1;
  44. },
  45. InOut: function (amount) {
  46. if ((amount *= 2) < 1) {
  47. return 0.5 * amount * amount * amount;
  48. }
  49. return 0.5 * ((amount -= 2) * amount * amount + 2);
  50. },
  51. }),
  52. Quartic: Object.freeze({
  53. In: function (amount) {
  54. return amount * amount * amount * amount;
  55. },
  56. Out: function (amount) {
  57. return 1 - --amount * amount * amount * amount;
  58. },
  59. InOut: function (amount) {
  60. if ((amount *= 2) < 1) {
  61. return 0.5 * amount * amount * amount * amount;
  62. }
  63. return -0.5 * ((amount -= 2) * amount * amount * amount - 2);
  64. },
  65. }),
  66. Quintic: Object.freeze({
  67. In: function (amount) {
  68. return amount * amount * amount * amount * amount;
  69. },
  70. Out: function (amount) {
  71. return --amount * amount * amount * amount * amount + 1;
  72. },
  73. InOut: function (amount) {
  74. if ((amount *= 2) < 1) {
  75. return 0.5 * amount * amount * amount * amount * amount;
  76. }
  77. return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2);
  78. },
  79. }),
  80. Sinusoidal: Object.freeze({
  81. In: function (amount) {
  82. return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2);
  83. },
  84. Out: function (amount) {
  85. return Math.sin((amount * Math.PI) / 2);
  86. },
  87. InOut: function (amount) {
  88. return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)));
  89. },
  90. }),
  91. Exponential: Object.freeze({
  92. In: function (amount) {
  93. return amount === 0 ? 0 : Math.pow(1024, amount - 1);
  94. },
  95. Out: function (amount) {
  96. return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
  97. },
  98. InOut: function (amount) {
  99. if (amount === 0) {
  100. return 0;
  101. }
  102. if (amount === 1) {
  103. return 1;
  104. }
  105. if ((amount *= 2) < 1) {
  106. return 0.5 * Math.pow(1024, amount - 1);
  107. }
  108. return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
  109. },
  110. }),
  111. Circular: Object.freeze({
  112. In: function (amount) {
  113. return 1 - Math.sqrt(1 - amount * amount);
  114. },
  115. Out: function (amount) {
  116. return Math.sqrt(1 - --amount * amount);
  117. },
  118. InOut: function (amount) {
  119. if ((amount *= 2) < 1) {
  120. return -0.5 * (Math.sqrt(1 - amount * amount) - 1);
  121. }
  122. return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
  123. },
  124. }),
  125. Elastic: Object.freeze({
  126. In: 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 - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
  134. },
  135. Out: function (amount) {
  136. if (amount === 0) {
  137. return 0;
  138. }
  139. if (amount === 1) {
  140. return 1;
  141. }
  142. return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1;
  143. },
  144. InOut: function (amount) {
  145. if (amount === 0) {
  146. return 0;
  147. }
  148. if (amount === 1) {
  149. return 1;
  150. }
  151. amount *= 2;
  152. if (amount < 1) {
  153. return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
  154. }
  155. return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
  156. },
  157. }),
  158. Back: Object.freeze({
  159. In: function (amount) {
  160. var s = 1.70158;
  161. return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
  162. },
  163. Out: function (amount) {
  164. var s = 1.70158;
  165. return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
  166. },
  167. InOut: function (amount) {
  168. var s = 1.70158 * 1.525;
  169. if ((amount *= 2) < 1) {
  170. return 0.5 * (amount * amount * ((s + 1) * amount - s));
  171. }
  172. return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
  173. },
  174. }),
  175. Bounce: Object.freeze({
  176. In: function (amount) {
  177. return 1 - Easing.Bounce.Out(1 - amount);
  178. },
  179. Out: function (amount) {
  180. if (amount < 1 / 2.75) {
  181. return 7.5625 * amount * amount;
  182. }
  183. else if (amount < 2 / 2.75) {
  184. return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75;
  185. }
  186. else if (amount < 2.5 / 2.75) {
  187. return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375;
  188. }
  189. else {
  190. return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375;
  191. }
  192. },
  193. InOut: function (amount) {
  194. if (amount < 0.5) {
  195. return Easing.Bounce.In(amount * 2) * 0.5;
  196. }
  197. return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5;
  198. },
  199. }),
  200. generatePow: function (power) {
  201. if (power === void 0) { power = 4; }
  202. power = power < Number.EPSILON ? Number.EPSILON : power;
  203. power = power > 10000 ? 10000 : power;
  204. return {
  205. In: function (amount) {
  206. return Math.pow(amount, power);
  207. },
  208. Out: function (amount) {
  209. return 1 - Math.pow((1 - amount), power);
  210. },
  211. InOut: function (amount) {
  212. if (amount < 0.5) {
  213. return Math.pow((amount * 2), power) / 2;
  214. }
  215. return (1 - Math.pow((2 - amount * 2), power)) / 2 + 0.5;
  216. },
  217. };
  218. },
  219. });
  220. var now = function () { return performance.now(); };
  221. /**
  222. * Controlling groups of tweens
  223. *
  224. * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
  225. * In these cases, you may want to create your own smaller groups of tween
  226. */
  227. var Group = /** @class */ (function () {
  228. function Group() {
  229. var tweens = [];
  230. for (var _i = 0; _i < arguments.length; _i++) {
  231. tweens[_i] = arguments[_i];
  232. }
  233. this._tweens = {};
  234. this._tweensAddedDuringUpdate = {};
  235. this.add.apply(this, tweens);
  236. }
  237. Group.prototype.getAll = function () {
  238. var _this = this;
  239. return Object.keys(this._tweens).map(function (tweenId) { return _this._tweens[tweenId]; });
  240. };
  241. Group.prototype.removeAll = function () {
  242. this._tweens = {};
  243. };
  244. Group.prototype.add = function () {
  245. var _a;
  246. var tweens = [];
  247. for (var _i = 0; _i < arguments.length; _i++) {
  248. tweens[_i] = arguments[_i];
  249. }
  250. for (var _b = 0, tweens_1 = tweens; _b < tweens_1.length; _b++) {
  251. var tween = tweens_1[_b];
  252. // Remove from any other group first, a tween can only be in one group at a time.
  253. // @ts-expect-error library internal access
  254. (_a = tween._group) === null || _a === void 0 ? void 0 : _a.remove(tween);
  255. // @ts-expect-error library internal access
  256. tween._group = this;
  257. this._tweens[tween.getId()] = tween;
  258. this._tweensAddedDuringUpdate[tween.getId()] = tween;
  259. }
  260. };
  261. Group.prototype.remove = function () {
  262. var tweens = [];
  263. for (var _i = 0; _i < arguments.length; _i++) {
  264. tweens[_i] = arguments[_i];
  265. }
  266. for (var _a = 0, tweens_2 = tweens; _a < tweens_2.length; _a++) {
  267. var tween = tweens_2[_a];
  268. // @ts-expect-error library internal access
  269. tween._group = undefined;
  270. delete this._tweens[tween.getId()];
  271. delete this._tweensAddedDuringUpdate[tween.getId()];
  272. }
  273. };
  274. /** Return true if all tweens in the group are not paused or playing. */
  275. Group.prototype.allStopped = function () {
  276. return this.getAll().every(function (tween) { return !tween.isPlaying(); });
  277. };
  278. Group.prototype.update = function (time, preserve) {
  279. if (time === void 0) { time = now(); }
  280. if (preserve === void 0) { preserve = true; }
  281. var tweenIds = Object.keys(this._tweens);
  282. if (tweenIds.length === 0)
  283. return;
  284. // Tweens are updated in "batches". If you add a new tween during an
  285. // update, then the new tween will be updated in the next batch.
  286. // If you remove a tween during an update, it may or may not be updated.
  287. // However, if the removed tween was added during the current batch,
  288. // then it will not be updated.
  289. while (tweenIds.length > 0) {
  290. this._tweensAddedDuringUpdate = {};
  291. for (var i = 0; i < tweenIds.length; i++) {
  292. var tween = this._tweens[tweenIds[i]];
  293. var autoStart = !preserve;
  294. if (tween && tween.update(time, autoStart) === false && !preserve)
  295. this.remove(tween);
  296. }
  297. tweenIds = Object.keys(this._tweensAddedDuringUpdate);
  298. }
  299. };
  300. return Group;
  301. }());
  302. /**
  303. *
  304. */
  305. var Interpolation = {
  306. Linear: function (v, k) {
  307. var m = v.length - 1;
  308. var f = m * k;
  309. var i = Math.floor(f);
  310. var fn = Interpolation.Utils.Linear;
  311. if (k < 0) {
  312. return fn(v[0], v[1], f);
  313. }
  314. if (k > 1) {
  315. return fn(v[m], v[m - 1], m - f);
  316. }
  317. return fn(v[i], v[i + 1 > m ? m : i + 1], f - i);
  318. },
  319. Bezier: function (v, k) {
  320. var b = 0;
  321. var n = v.length - 1;
  322. var pw = Math.pow;
  323. var bn = Interpolation.Utils.Bernstein;
  324. for (var i = 0; i <= n; i++) {
  325. b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i);
  326. }
  327. return b;
  328. },
  329. CatmullRom: function (v, k) {
  330. var m = v.length - 1;
  331. var f = m * k;
  332. var i = Math.floor(f);
  333. var fn = Interpolation.Utils.CatmullRom;
  334. if (v[0] === v[m]) {
  335. if (k < 0) {
  336. i = Math.floor((f = m * (1 + k)));
  337. }
  338. return fn(v[(i - 1 + m) % m], v[i], v[(i + 1) % m], v[(i + 2) % m], f - i);
  339. }
  340. else {
  341. if (k < 0) {
  342. return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]);
  343. }
  344. if (k > 1) {
  345. return v[m] - (fn(v[m], v[m], v[m - 1], v[m - 1], f - m) - v[m]);
  346. }
  347. 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);
  348. }
  349. },
  350. Utils: {
  351. Linear: function (p0, p1, t) {
  352. return (p1 - p0) * t + p0;
  353. },
  354. Bernstein: function (n, i) {
  355. var fc = Interpolation.Utils.Factorial;
  356. return fc(n) / fc(i) / fc(n - i);
  357. },
  358. Factorial: (function () {
  359. var a = [1];
  360. return function (n) {
  361. var s = 1;
  362. if (a[n]) {
  363. return a[n];
  364. }
  365. for (var i = n; i > 1; i--) {
  366. s *= i;
  367. }
  368. a[n] = s;
  369. return s;
  370. };
  371. })(),
  372. CatmullRom: function (p0, p1, p2, p3, t) {
  373. var v0 = (p2 - p0) * 0.5;
  374. var v1 = (p3 - p1) * 0.5;
  375. var t2 = t * t;
  376. var t3 = t * t2;
  377. return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
  378. },
  379. },
  380. };
  381. /**
  382. * Utils
  383. */
  384. var Sequence = /** @class */ (function () {
  385. function Sequence() {
  386. }
  387. Sequence.nextId = function () {
  388. return Sequence._nextId++;
  389. };
  390. Sequence._nextId = 0;
  391. return Sequence;
  392. }());
  393. var mainGroup = new Group();
  394. /**
  395. * Tween.js - Licensed under the MIT license
  396. * https://github.com/tweenjs/tween.js
  397. * ----------------------------------------------
  398. *
  399. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  400. * Thank you all, you're awesome!
  401. */
  402. var Tween = /** @class */ (function () {
  403. function Tween(object, group) {
  404. this._isPaused = false;
  405. this._pauseStart = 0;
  406. this._valuesStart = {};
  407. this._valuesEnd = {};
  408. this._valuesStartRepeat = {};
  409. this._duration = 1000;
  410. this._isDynamic = false;
  411. this._initialRepeat = 0;
  412. this._repeat = 0;
  413. this._yoyo = false;
  414. this._isPlaying = false;
  415. this._reversed = false;
  416. this._delayTime = 0;
  417. this._startTime = 0;
  418. this._easingFunction = Easing.Linear.None;
  419. this._interpolationFunction = Interpolation.Linear;
  420. // eslint-disable-next-line
  421. this._chainedTweens = [];
  422. this._onStartCallbackFired = false;
  423. this._onEveryStartCallbackFired = false;
  424. this._id = Sequence.nextId();
  425. this._isChainStopped = false;
  426. this._propertiesAreSetUp = false;
  427. this._goToEnd = false;
  428. this._object = object;
  429. if (typeof group === 'object') {
  430. this._group = group;
  431. group.add(this);
  432. }
  433. // Use "true" to restore old behavior (will be removed in future release).
  434. else if (group === true) {
  435. this._group = mainGroup;
  436. mainGroup.add(this);
  437. }
  438. }
  439. Tween.prototype.getId = function () {
  440. return this._id;
  441. };
  442. Tween.prototype.isPlaying = function () {
  443. return this._isPlaying;
  444. };
  445. Tween.prototype.isPaused = function () {
  446. return this._isPaused;
  447. };
  448. Tween.prototype.getDuration = function () {
  449. return this._duration;
  450. };
  451. Tween.prototype.to = function (target, duration) {
  452. if (duration === void 0) { duration = 1000; }
  453. if (this._isPlaying)
  454. throw new Error('Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.');
  455. this._valuesEnd = target;
  456. this._propertiesAreSetUp = false;
  457. this._duration = duration < 0 ? 0 : duration;
  458. return this;
  459. };
  460. Tween.prototype.duration = function (duration) {
  461. if (duration === void 0) { duration = 1000; }
  462. this._duration = duration < 0 ? 0 : duration;
  463. return this;
  464. };
  465. Tween.prototype.dynamic = function (dynamic) {
  466. if (dynamic === void 0) { dynamic = false; }
  467. this._isDynamic = dynamic;
  468. return this;
  469. };
  470. Tween.prototype.start = function (time, overrideStartingValues) {
  471. if (time === void 0) { time = now(); }
  472. if (overrideStartingValues === void 0) { overrideStartingValues = false; }
  473. if (this._isPlaying) {
  474. return this;
  475. }
  476. this._repeat = this._initialRepeat;
  477. if (this._reversed) {
  478. // If we were reversed (f.e. using the yoyo feature) then we need to
  479. // flip the tween direction back to forward.
  480. this._reversed = false;
  481. for (var property in this._valuesStartRepeat) {
  482. this._swapEndStartRepeatValues(property);
  483. this._valuesStart[property] = this._valuesStartRepeat[property];
  484. }
  485. }
  486. this._isPlaying = true;
  487. this._isPaused = false;
  488. this._onStartCallbackFired = false;
  489. this._onEveryStartCallbackFired = false;
  490. this._isChainStopped = false;
  491. this._startTime = time;
  492. this._startTime += this._delayTime;
  493. if (!this._propertiesAreSetUp || overrideStartingValues) {
  494. this._propertiesAreSetUp = true;
  495. // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
  496. if (!this._isDynamic) {
  497. var tmp = {};
  498. for (var prop in this._valuesEnd)
  499. tmp[prop] = this._valuesEnd[prop];
  500. this._valuesEnd = tmp;
  501. }
  502. this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues);
  503. }
  504. return this;
  505. };
  506. Tween.prototype.startFromCurrentValues = function (time) {
  507. return this.start(time, true);
  508. };
  509. Tween.prototype._setupProperties = function (_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) {
  510. for (var property in _valuesEnd) {
  511. var startValue = _object[property];
  512. var startValueIsArray = Array.isArray(startValue);
  513. var propType = startValueIsArray ? 'array' : typeof startValue;
  514. var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]);
  515. // If `to()` specifies a property that doesn't exist in the source object,
  516. // we should not set that property in the object
  517. if (propType === 'undefined' || propType === 'function') {
  518. continue;
  519. }
  520. // Check if an Array was provided as property value
  521. if (isInterpolationList) {
  522. var endValues = _valuesEnd[property];
  523. if (endValues.length === 0) {
  524. continue;
  525. }
  526. // Handle an array of relative values.
  527. // Creates a local copy of the Array with the start value at the front
  528. var temp = [startValue];
  529. for (var i = 0, l = endValues.length; i < l; i += 1) {
  530. var value = this._handleRelativeValue(startValue, endValues[i]);
  531. if (isNaN(value)) {
  532. isInterpolationList = false;
  533. console.warn('Found invalid interpolation list. Skipping.');
  534. break;
  535. }
  536. temp.push(value);
  537. }
  538. if (isInterpolationList) {
  539. // if (_valuesStart[property] === undefined) { // handle end values only the first time. NOT NEEDED? setupProperties is now guarded by _propertiesAreSetUp.
  540. _valuesEnd[property] = temp;
  541. // }
  542. }
  543. }
  544. // handle the deepness of the values
  545. if ((propType === 'object' || startValueIsArray) && startValue && !isInterpolationList) {
  546. _valuesStart[property] = startValueIsArray ? [] : {};
  547. var nestedObject = startValue;
  548. for (var prop in nestedObject) {
  549. _valuesStart[property][prop] = nestedObject[prop];
  550. }
  551. // TODO? repeat nested values? And yoyo? And array values?
  552. _valuesStartRepeat[property] = startValueIsArray ? [] : {};
  553. var endValues = _valuesEnd[property];
  554. // If dynamic is not enabled, clone the end values instead of using the passed-in end values.
  555. if (!this._isDynamic) {
  556. var tmp = {};
  557. for (var prop in endValues)
  558. tmp[prop] = endValues[prop];
  559. _valuesEnd[property] = endValues = tmp;
  560. }
  561. this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues);
  562. }
  563. else {
  564. // Save the starting value, but only once unless override is requested.
  565. if (typeof _valuesStart[property] === 'undefined' || overrideStartingValues) {
  566. _valuesStart[property] = startValue;
  567. }
  568. if (!startValueIsArray) {
  569. // eslint-disable-next-line
  570. // @ts-ignore FIXME?
  571. _valuesStart[property] *= 1.0; // Ensures we're using numbers, not strings
  572. }
  573. if (isInterpolationList) {
  574. // eslint-disable-next-line
  575. // @ts-ignore FIXME?
  576. _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse();
  577. }
  578. else {
  579. _valuesStartRepeat[property] = _valuesStart[property] || 0;
  580. }
  581. }
  582. }
  583. };
  584. Tween.prototype.stop = function () {
  585. if (!this._isChainStopped) {
  586. this._isChainStopped = true;
  587. this.stopChainedTweens();
  588. }
  589. if (!this._isPlaying) {
  590. return this;
  591. }
  592. this._isPlaying = false;
  593. this._isPaused = false;
  594. if (this._onStopCallback) {
  595. this._onStopCallback(this._object);
  596. }
  597. return this;
  598. };
  599. Tween.prototype.end = function () {
  600. this._goToEnd = true;
  601. this.update(this._startTime + this._duration);
  602. return this;
  603. };
  604. Tween.prototype.pause = function (time) {
  605. if (time === void 0) { time = now(); }
  606. if (this._isPaused || !this._isPlaying) {
  607. return this;
  608. }
  609. this._isPaused = true;
  610. this._pauseStart = time;
  611. return this;
  612. };
  613. Tween.prototype.resume = function (time) {
  614. if (time === void 0) { time = now(); }
  615. if (!this._isPaused || !this._isPlaying) {
  616. return this;
  617. }
  618. this._isPaused = false;
  619. this._startTime += time - this._pauseStart;
  620. this._pauseStart = 0;
  621. return this;
  622. };
  623. Tween.prototype.stopChainedTweens = function () {
  624. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  625. this._chainedTweens[i].stop();
  626. }
  627. return this;
  628. };
  629. Tween.prototype.group = function (group) {
  630. if (!group) {
  631. console.warn('tween.group() without args has been removed, use group.add(tween) instead.');
  632. return this;
  633. }
  634. group.add(this);
  635. return this;
  636. };
  637. /**
  638. * Removes the tween from whichever group it is in.
  639. */
  640. Tween.prototype.remove = function () {
  641. var _a;
  642. (_a = this._group) === null || _a === void 0 ? void 0 : _a.remove(this);
  643. return this;
  644. };
  645. Tween.prototype.delay = function (amount) {
  646. if (amount === void 0) { amount = 0; }
  647. this._delayTime = amount;
  648. return this;
  649. };
  650. Tween.prototype.repeat = function (times) {
  651. if (times === void 0) { times = 0; }
  652. this._initialRepeat = times;
  653. this._repeat = times;
  654. return this;
  655. };
  656. Tween.prototype.repeatDelay = function (amount) {
  657. this._repeatDelayTime = amount;
  658. return this;
  659. };
  660. Tween.prototype.yoyo = function (yoyo) {
  661. if (yoyo === void 0) { yoyo = false; }
  662. this._yoyo = yoyo;
  663. return this;
  664. };
  665. Tween.prototype.easing = function (easingFunction) {
  666. if (easingFunction === void 0) { easingFunction = Easing.Linear.None; }
  667. this._easingFunction = easingFunction;
  668. return this;
  669. };
  670. Tween.prototype.interpolation = function (interpolationFunction) {
  671. if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; }
  672. this._interpolationFunction = interpolationFunction;
  673. return this;
  674. };
  675. // eslint-disable-next-line
  676. Tween.prototype.chain = function () {
  677. var tweens = [];
  678. for (var _i = 0; _i < arguments.length; _i++) {
  679. tweens[_i] = arguments[_i];
  680. }
  681. this._chainedTweens = tweens;
  682. return this;
  683. };
  684. Tween.prototype.onStart = function (callback) {
  685. this._onStartCallback = callback;
  686. return this;
  687. };
  688. Tween.prototype.onEveryStart = function (callback) {
  689. this._onEveryStartCallback = callback;
  690. return this;
  691. };
  692. Tween.prototype.onUpdate = function (callback) {
  693. this._onUpdateCallback = callback;
  694. return this;
  695. };
  696. Tween.prototype.onRepeat = function (callback) {
  697. this._onRepeatCallback = callback;
  698. return this;
  699. };
  700. Tween.prototype.onComplete = function (callback) {
  701. this._onCompleteCallback = callback;
  702. return this;
  703. };
  704. Tween.prototype.onStop = function (callback) {
  705. this._onStopCallback = callback;
  706. return this;
  707. };
  708. /**
  709. * @returns true if the tween is still playing after the update, false
  710. * otherwise (calling update on a paused tween still returns true because
  711. * it is still playing, just paused).
  712. *
  713. * @param autoStart - When true, calling update will implicitly call start()
  714. * as well. Note, if you stop() or end() the tween, but are still calling
  715. * update(), it will start again!
  716. */
  717. Tween.prototype.update = function (time, autoStart) {
  718. var _this = this;
  719. var _a;
  720. if (time === void 0) { time = now(); }
  721. if (autoStart === void 0) { autoStart = Tween.autoStartOnUpdate; }
  722. if (this._isPaused)
  723. return true;
  724. var property;
  725. if (!this._goToEnd && !this._isPlaying) {
  726. if (autoStart)
  727. this.start(time, true);
  728. else
  729. return false;
  730. }
  731. this._goToEnd = false;
  732. if (time < this._startTime) {
  733. return true;
  734. }
  735. if (this._onStartCallbackFired === false) {
  736. if (this._onStartCallback) {
  737. this._onStartCallback(this._object);
  738. }
  739. this._onStartCallbackFired = true;
  740. }
  741. if (this._onEveryStartCallbackFired === false) {
  742. if (this._onEveryStartCallback) {
  743. this._onEveryStartCallback(this._object);
  744. }
  745. this._onEveryStartCallbackFired = true;
  746. }
  747. var elapsedTime = time - this._startTime;
  748. var durationAndDelay = this._duration + ((_a = this._repeatDelayTime) !== null && _a !== void 0 ? _a : this._delayTime);
  749. var totalTime = this._duration + this._repeat * durationAndDelay;
  750. var calculateElapsedPortion = function () {
  751. if (_this._duration === 0)
  752. return 1;
  753. if (elapsedTime > totalTime) {
  754. return 1;
  755. }
  756. var timesRepeated = Math.trunc(elapsedTime / durationAndDelay);
  757. var timeIntoCurrentRepeat = elapsedTime - timesRepeated * durationAndDelay;
  758. // TODO use %?
  759. // const timeIntoCurrentRepeat = elapsedTime % durationAndDelay
  760. var portion = Math.min(timeIntoCurrentRepeat / _this._duration, 1);
  761. if (portion === 0 && elapsedTime === _this._duration) {
  762. return 1;
  763. }
  764. return portion;
  765. };
  766. var elapsed = calculateElapsedPortion();
  767. var value = this._easingFunction(elapsed);
  768. // properties transformations
  769. this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value);
  770. if (this._onUpdateCallback) {
  771. this._onUpdateCallback(this._object, elapsed);
  772. }
  773. if (this._duration === 0 || elapsedTime >= this._duration) {
  774. if (this._repeat > 0) {
  775. var completeCount = Math.min(Math.trunc((elapsedTime - this._duration) / durationAndDelay) + 1, this._repeat);
  776. if (isFinite(this._repeat)) {
  777. this._repeat -= completeCount;
  778. }
  779. // Reassign starting values, restart by making startTime = now
  780. for (property in this._valuesStartRepeat) {
  781. if (!this._yoyo && typeof this._valuesEnd[property] === 'string') {
  782. this._valuesStartRepeat[property] =
  783. // eslint-disable-next-line
  784. // @ts-ignore FIXME?
  785. this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]);
  786. }
  787. if (this._yoyo) {
  788. this._swapEndStartRepeatValues(property);
  789. }
  790. this._valuesStart[property] = this._valuesStartRepeat[property];
  791. }
  792. if (this._yoyo) {
  793. this._reversed = !this._reversed;
  794. }
  795. this._startTime += durationAndDelay * completeCount;
  796. if (this._onRepeatCallback) {
  797. this._onRepeatCallback(this._object);
  798. }
  799. this._onEveryStartCallbackFired = false;
  800. return true;
  801. }
  802. else {
  803. if (this._onCompleteCallback) {
  804. this._onCompleteCallback(this._object);
  805. }
  806. for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) {
  807. // Make the chained tweens start exactly at the time they should,
  808. // even if the `update()` method was called way past the duration of the tween
  809. this._chainedTweens[i].start(this._startTime + this._duration, false);
  810. }
  811. this._isPlaying = false;
  812. return false;
  813. }
  814. }
  815. return true;
  816. };
  817. Tween.prototype._updateProperties = function (_object, _valuesStart, _valuesEnd, value) {
  818. for (var property in _valuesEnd) {
  819. // Don't update properties that do not exist in the source object
  820. if (_valuesStart[property] === undefined) {
  821. continue;
  822. }
  823. var start = _valuesStart[property] || 0;
  824. var end = _valuesEnd[property];
  825. var startIsArray = Array.isArray(_object[property]);
  826. var endIsArray = Array.isArray(end);
  827. var isInterpolationList = !startIsArray && endIsArray;
  828. if (isInterpolationList) {
  829. _object[property] = this._interpolationFunction(end, value);
  830. }
  831. else if (typeof end === 'object' && end) {
  832. // eslint-disable-next-line
  833. // @ts-ignore FIXME?
  834. this._updateProperties(_object[property], start, end, value);
  835. }
  836. else {
  837. // Parses relative end values with start as base (e.g.: +10, -3)
  838. end = this._handleRelativeValue(start, end);
  839. // Protect against non numeric properties.
  840. if (typeof end === 'number') {
  841. // eslint-disable-next-line
  842. // @ts-ignore FIXME?
  843. _object[property] = start + (end - start) * value;
  844. }
  845. }
  846. }
  847. };
  848. Tween.prototype._handleRelativeValue = function (start, end) {
  849. if (typeof end !== 'string') {
  850. return end;
  851. }
  852. if (end.charAt(0) === '+' || end.charAt(0) === '-') {
  853. return start + parseFloat(end);
  854. }
  855. return parseFloat(end);
  856. };
  857. Tween.prototype._swapEndStartRepeatValues = function (property) {
  858. var tmp = this._valuesStartRepeat[property];
  859. var endValue = this._valuesEnd[property];
  860. if (typeof endValue === 'string') {
  861. this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue);
  862. }
  863. else {
  864. this._valuesStartRepeat[property] = this._valuesEnd[property];
  865. }
  866. this._valuesEnd[property] = tmp;
  867. };
  868. Tween.autoStartOnUpdate = false;
  869. return Tween;
  870. }());
  871. var VERSION = '25.0.0';
  872. /**
  873. * Tween.js - Licensed under the MIT license
  874. * https://github.com/tweenjs/tween.js
  875. * ----------------------------------------------
  876. *
  877. * See https://github.com/tweenjs/tween.js/graphs/contributors for the full list of contributors.
  878. * Thank you all, you're awesome!
  879. */
  880. var nextId = Sequence.nextId;
  881. /**
  882. * Controlling groups of tweens
  883. *
  884. * Using the TWEEN singleton to manage your tweens can cause issues in large apps with many components.
  885. * In these cases, you may want to create your own smaller groups of tweens.
  886. */
  887. var TWEEN = mainGroup;
  888. // This is the best way to export things in a way that's compatible with both ES
  889. // Modules and CommonJS, without build hacks, and so as not to break the
  890. // existing API.
  891. // https://github.com/rollup/rollup/issues/1961#issuecomment-423037881
  892. /**
  893. * @deprecated The global TWEEN Group will be removed in a following major
  894. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  895. * group.
  896. *
  897. * Old code:
  898. *
  899. * ```js
  900. * import * as TWEEN from '@tweenjs/tween.js'
  901. *
  902. * //...
  903. *
  904. * const tween = new TWEEN.Tween(obj)
  905. * const tween2 = new TWEEN.Tween(obj2)
  906. *
  907. * //...
  908. *
  909. * requestAnimationFrame(function loop(time) {
  910. * TWEEN.update(time)
  911. * requestAnimationFrame(loop)
  912. * })
  913. * ```
  914. *
  915. * New code:
  916. *
  917. * ```js
  918. * import {Tween, Group} from '@tweenjs/tween.js'
  919. *
  920. * //...
  921. *
  922. * const tween = new Tween(obj)
  923. * const tween2 = new TWEEN.Tween(obj2)
  924. *
  925. * //...
  926. *
  927. * const group = new Group()
  928. * group.add(tween)
  929. * group.add(tween2)
  930. *
  931. * //...
  932. *
  933. * requestAnimationFrame(function loop(time) {
  934. * group.update(time)
  935. * requestAnimationFrame(loop)
  936. * })
  937. * ```
  938. */
  939. var getAll = TWEEN.getAll.bind(TWEEN);
  940. /**
  941. * @deprecated The global TWEEN Group will be removed in a following major
  942. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  943. * group.
  944. *
  945. * Old code:
  946. *
  947. * ```js
  948. * import * as TWEEN from '@tweenjs/tween.js'
  949. *
  950. * //...
  951. *
  952. * const tween = new TWEEN.Tween(obj)
  953. * const tween2 = new TWEEN.Tween(obj2)
  954. *
  955. * //...
  956. *
  957. * requestAnimationFrame(function loop(time) {
  958. * TWEEN.update(time)
  959. * requestAnimationFrame(loop)
  960. * })
  961. * ```
  962. *
  963. * New code:
  964. *
  965. * ```js
  966. * import {Tween, Group} from '@tweenjs/tween.js'
  967. *
  968. * //...
  969. *
  970. * const tween = new Tween(obj)
  971. * const tween2 = new TWEEN.Tween(obj2)
  972. *
  973. * //...
  974. *
  975. * const group = new Group()
  976. * group.add(tween)
  977. * group.add(tween2)
  978. *
  979. * //...
  980. *
  981. * requestAnimationFrame(function loop(time) {
  982. * group.update(time)
  983. * requestAnimationFrame(loop)
  984. * })
  985. * ```
  986. */
  987. var removeAll = TWEEN.removeAll.bind(TWEEN);
  988. /**
  989. * @deprecated The global TWEEN Group will be removed in a following major
  990. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  991. * group.
  992. *
  993. * Old code:
  994. *
  995. * ```js
  996. * import * as TWEEN from '@tweenjs/tween.js'
  997. *
  998. * //...
  999. *
  1000. * const tween = new TWEEN.Tween(obj)
  1001. * const tween2 = new TWEEN.Tween(obj2)
  1002. *
  1003. * //...
  1004. *
  1005. * requestAnimationFrame(function loop(time) {
  1006. * TWEEN.update(time)
  1007. * requestAnimationFrame(loop)
  1008. * })
  1009. * ```
  1010. *
  1011. * New code:
  1012. *
  1013. * ```js
  1014. * import {Tween, Group} from '@tweenjs/tween.js'
  1015. *
  1016. * //...
  1017. *
  1018. * const tween = new Tween(obj)
  1019. * const tween2 = new TWEEN.Tween(obj2)
  1020. *
  1021. * //...
  1022. *
  1023. * const group = new Group()
  1024. * group.add(tween)
  1025. * group.add(tween2)
  1026. *
  1027. * //...
  1028. *
  1029. * requestAnimationFrame(function loop(time) {
  1030. * group.update(time)
  1031. * requestAnimationFrame(loop)
  1032. * })
  1033. * ```
  1034. */
  1035. var add = TWEEN.add.bind(TWEEN);
  1036. /**
  1037. * @deprecated The global TWEEN Group will be removed in a following major
  1038. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1039. * group.
  1040. *
  1041. * Old code:
  1042. *
  1043. * ```js
  1044. * import * as TWEEN from '@tweenjs/tween.js'
  1045. *
  1046. * //...
  1047. *
  1048. * const tween = new TWEEN.Tween(obj)
  1049. * const tween2 = new TWEEN.Tween(obj2)
  1050. *
  1051. * //...
  1052. *
  1053. * requestAnimationFrame(function loop(time) {
  1054. * TWEEN.update(time)
  1055. * requestAnimationFrame(loop)
  1056. * })
  1057. * ```
  1058. *
  1059. * New code:
  1060. *
  1061. * ```js
  1062. * import {Tween, Group} from '@tweenjs/tween.js'
  1063. *
  1064. * //...
  1065. *
  1066. * const tween = new Tween(obj)
  1067. * const tween2 = new TWEEN.Tween(obj2)
  1068. *
  1069. * //...
  1070. *
  1071. * const group = new Group()
  1072. * group.add(tween)
  1073. * group.add(tween2)
  1074. *
  1075. * //...
  1076. *
  1077. * requestAnimationFrame(function loop(time) {
  1078. * group.update(time)
  1079. * requestAnimationFrame(loop)
  1080. * })
  1081. * ```
  1082. */
  1083. var remove = TWEEN.remove.bind(TWEEN);
  1084. /**
  1085. * @deprecated The global TWEEN Group will be removed in a following major
  1086. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1087. * group.
  1088. *
  1089. * Old code:
  1090. *
  1091. * ```js
  1092. * import * as TWEEN from '@tweenjs/tween.js'
  1093. *
  1094. * //...
  1095. *
  1096. * const tween = new TWEEN.Tween(obj)
  1097. * const tween2 = new TWEEN.Tween(obj2)
  1098. *
  1099. * //...
  1100. *
  1101. * requestAnimationFrame(function loop(time) {
  1102. * TWEEN.update(time)
  1103. * requestAnimationFrame(loop)
  1104. * })
  1105. * ```
  1106. *
  1107. * New code:
  1108. *
  1109. * ```js
  1110. * import {Tween, Group} from '@tweenjs/tween.js'
  1111. *
  1112. * //...
  1113. *
  1114. * const tween = new Tween(obj)
  1115. * const tween2 = new TWEEN.Tween(obj2)
  1116. *
  1117. * //...
  1118. *
  1119. * const group = new Group()
  1120. * group.add(tween)
  1121. * group.add(tween2)
  1122. *
  1123. * //...
  1124. *
  1125. * requestAnimationFrame(function loop(time) {
  1126. * group.update(time)
  1127. * requestAnimationFrame(loop)
  1128. * })
  1129. * ```
  1130. */
  1131. var update = TWEEN.update.bind(TWEEN);
  1132. var exports$1 = {
  1133. Easing: Easing,
  1134. Group: Group,
  1135. Interpolation: Interpolation,
  1136. now: now,
  1137. Sequence: Sequence,
  1138. nextId: nextId,
  1139. Tween: Tween,
  1140. VERSION: VERSION,
  1141. /**
  1142. * @deprecated The global TWEEN Group will be removed in a following major
  1143. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1144. * group.
  1145. *
  1146. * Old code:
  1147. *
  1148. * ```js
  1149. * import * as TWEEN from '@tweenjs/tween.js'
  1150. *
  1151. * //...
  1152. *
  1153. * const tween = new TWEEN.Tween(obj)
  1154. * const tween2 = new TWEEN.Tween(obj2)
  1155. *
  1156. * //...
  1157. *
  1158. * requestAnimationFrame(function loop(time) {
  1159. * TWEEN.update(time)
  1160. * requestAnimationFrame(loop)
  1161. * })
  1162. * ```
  1163. *
  1164. * New code:
  1165. *
  1166. * ```js
  1167. * import {Tween, Group} from '@tweenjs/tween.js'
  1168. *
  1169. * //...
  1170. *
  1171. * const tween = new Tween(obj)
  1172. * const tween2 = new TWEEN.Tween(obj2)
  1173. *
  1174. * //...
  1175. *
  1176. * const group = new Group()
  1177. * group.add(tween)
  1178. * group.add(tween2)
  1179. *
  1180. * //...
  1181. *
  1182. * requestAnimationFrame(function loop(time) {
  1183. * group.update(time)
  1184. * requestAnimationFrame(loop)
  1185. * })
  1186. * ```
  1187. */
  1188. getAll: getAll,
  1189. /**
  1190. * @deprecated The global TWEEN Group will be removed in a following major
  1191. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1192. * group.
  1193. *
  1194. * Old code:
  1195. *
  1196. * ```js
  1197. * import * as TWEEN from '@tweenjs/tween.js'
  1198. *
  1199. * //...
  1200. *
  1201. * const tween = new TWEEN.Tween(obj)
  1202. * const tween2 = new TWEEN.Tween(obj2)
  1203. *
  1204. * //...
  1205. *
  1206. * requestAnimationFrame(function loop(time) {
  1207. * TWEEN.update(time)
  1208. * requestAnimationFrame(loop)
  1209. * })
  1210. * ```
  1211. *
  1212. * New code:
  1213. *
  1214. * ```js
  1215. * import {Tween, Group} from '@tweenjs/tween.js'
  1216. *
  1217. * //...
  1218. *
  1219. * const tween = new Tween(obj)
  1220. * const tween2 = new TWEEN.Tween(obj2)
  1221. *
  1222. * //...
  1223. *
  1224. * const group = new Group()
  1225. * group.add(tween)
  1226. * group.add(tween2)
  1227. *
  1228. * //...
  1229. *
  1230. * requestAnimationFrame(function loop(time) {
  1231. * group.update(time)
  1232. * requestAnimationFrame(loop)
  1233. * })
  1234. * ```
  1235. */
  1236. removeAll: removeAll,
  1237. /**
  1238. * @deprecated The global TWEEN Group will be removed in a following major
  1239. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1240. * group.
  1241. *
  1242. * Old code:
  1243. *
  1244. * ```js
  1245. * import * as TWEEN from '@tweenjs/tween.js'
  1246. *
  1247. * //...
  1248. *
  1249. * const tween = new TWEEN.Tween(obj)
  1250. * const tween2 = new TWEEN.Tween(obj2)
  1251. *
  1252. * //...
  1253. *
  1254. * requestAnimationFrame(function loop(time) {
  1255. * TWEEN.update(time)
  1256. * requestAnimationFrame(loop)
  1257. * })
  1258. * ```
  1259. *
  1260. * New code:
  1261. *
  1262. * ```js
  1263. * import {Tween, Group} from '@tweenjs/tween.js'
  1264. *
  1265. * //...
  1266. *
  1267. * const tween = new Tween(obj)
  1268. * const tween2 = new TWEEN.Tween(obj2)
  1269. *
  1270. * //...
  1271. *
  1272. * const group = new Group()
  1273. * group.add(tween)
  1274. * group.add(tween2)
  1275. *
  1276. * //...
  1277. *
  1278. * requestAnimationFrame(function loop(time) {
  1279. * group.update(time)
  1280. * requestAnimationFrame(loop)
  1281. * })
  1282. * ```
  1283. */
  1284. add: add,
  1285. /**
  1286. * @deprecated The global TWEEN Group will be removed in a following major
  1287. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1288. * group.
  1289. *
  1290. * Old code:
  1291. *
  1292. * ```js
  1293. * import * as TWEEN from '@tweenjs/tween.js'
  1294. *
  1295. * //...
  1296. *
  1297. * const tween = new TWEEN.Tween(obj)
  1298. * const tween2 = new TWEEN.Tween(obj2)
  1299. *
  1300. * //...
  1301. *
  1302. * requestAnimationFrame(function loop(time) {
  1303. * TWEEN.update(time)
  1304. * requestAnimationFrame(loop)
  1305. * })
  1306. * ```
  1307. *
  1308. * New code:
  1309. *
  1310. * ```js
  1311. * import {Tween, Group} from '@tweenjs/tween.js'
  1312. *
  1313. * //...
  1314. *
  1315. * const tween = new Tween(obj)
  1316. * const tween2 = new TWEEN.Tween(obj2)
  1317. *
  1318. * //...
  1319. *
  1320. * const group = new Group()
  1321. * group.add(tween)
  1322. * group.add(tween2)
  1323. *
  1324. * //...
  1325. *
  1326. * requestAnimationFrame(function loop(time) {
  1327. * group.update(time)
  1328. * requestAnimationFrame(loop)
  1329. * })
  1330. * ```
  1331. */
  1332. remove: remove,
  1333. /**
  1334. * @deprecated The global TWEEN Group will be removed in a following major
  1335. * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
  1336. * group.
  1337. *
  1338. * Old code:
  1339. *
  1340. * ```js
  1341. * import * as TWEEN from '@tweenjs/tween.js'
  1342. *
  1343. * //...
  1344. *
  1345. * const tween = new TWEEN.Tween(obj)
  1346. * const tween2 = new TWEEN.Tween(obj2)
  1347. *
  1348. * //...
  1349. *
  1350. * requestAnimationFrame(function loop(time) {
  1351. * TWEEN.update(time)
  1352. * requestAnimationFrame(loop)
  1353. * })
  1354. * ```
  1355. *
  1356. * New code:
  1357. *
  1358. * ```js
  1359. * import {Tween, Group} from '@tweenjs/tween.js'
  1360. *
  1361. * //...
  1362. *
  1363. * const tween = new Tween(obj)
  1364. * const tween2 = new TWEEN.Tween(obj2)
  1365. *
  1366. * //...
  1367. *
  1368. * const group = new Group()
  1369. * group.add(tween)
  1370. * group.add(tween2)
  1371. *
  1372. * //...
  1373. *
  1374. * requestAnimationFrame(function loop(time) {
  1375. * group.update(time)
  1376. * requestAnimationFrame(loop)
  1377. * })
  1378. * ```
  1379. */
  1380. update: update,
  1381. };
  1382. exports.Easing = Easing;
  1383. exports.Group = Group;
  1384. exports.Interpolation = Interpolation;
  1385. exports.Sequence = Sequence;
  1386. exports.Tween = Tween;
  1387. exports.VERSION = VERSION;
  1388. exports.add = add;
  1389. exports.default = exports$1;
  1390. exports.getAll = getAll;
  1391. exports.nextId = nextId;
  1392. exports.now = now;
  1393. exports.remove = remove;
  1394. exports.removeAll = removeAll;
  1395. exports.update = update;
  1396. Object.defineProperty(exports, '__esModule', { value: true });
  1397. }));