@tweenjs/tween.js 23.1.3 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tween.esm.js CHANGED
@@ -223,33 +223,61 @@ var now = function () { return performance.now(); };
223
223
  */
224
224
  var Group = /** @class */ (function () {
225
225
  function Group() {
226
+ var tweens = [];
227
+ for (var _i = 0; _i < arguments.length; _i++) {
228
+ tweens[_i] = arguments[_i];
229
+ }
226
230
  this._tweens = {};
227
231
  this._tweensAddedDuringUpdate = {};
232
+ this.add.apply(this, tweens);
228
233
  }
229
234
  Group.prototype.getAll = function () {
230
235
  var _this = this;
231
- return Object.keys(this._tweens).map(function (tweenId) {
232
- return _this._tweens[tweenId];
233
- });
236
+ return Object.keys(this._tweens).map(function (tweenId) { return _this._tweens[tweenId]; });
234
237
  };
235
238
  Group.prototype.removeAll = function () {
236
239
  this._tweens = {};
237
240
  };
238
- Group.prototype.add = function (tween) {
239
- this._tweens[tween.getId()] = tween;
240
- this._tweensAddedDuringUpdate[tween.getId()] = tween;
241
+ Group.prototype.add = function () {
242
+ var _a;
243
+ var tweens = [];
244
+ for (var _i = 0; _i < arguments.length; _i++) {
245
+ tweens[_i] = arguments[_i];
246
+ }
247
+ for (var _b = 0, tweens_1 = tweens; _b < tweens_1.length; _b++) {
248
+ var tween = tweens_1[_b];
249
+ // Remove from any other group first, a tween can only be in one group at a time.
250
+ // @ts-expect-error library internal access
251
+ (_a = tween._group) === null || _a === void 0 ? void 0 : _a.remove(tween);
252
+ // @ts-expect-error library internal access
253
+ tween._group = this;
254
+ this._tweens[tween.getId()] = tween;
255
+ this._tweensAddedDuringUpdate[tween.getId()] = tween;
256
+ }
257
+ };
258
+ Group.prototype.remove = function () {
259
+ var tweens = [];
260
+ for (var _i = 0; _i < arguments.length; _i++) {
261
+ tweens[_i] = arguments[_i];
262
+ }
263
+ for (var _a = 0, tweens_2 = tweens; _a < tweens_2.length; _a++) {
264
+ var tween = tweens_2[_a];
265
+ // @ts-expect-error library internal access
266
+ tween._group = undefined;
267
+ delete this._tweens[tween.getId()];
268
+ delete this._tweensAddedDuringUpdate[tween.getId()];
269
+ }
241
270
  };
242
- Group.prototype.remove = function (tween) {
243
- delete this._tweens[tween.getId()];
244
- delete this._tweensAddedDuringUpdate[tween.getId()];
271
+ /** Return true if all tweens in the group are not paused or playing. */
272
+ Group.prototype.allStopped = function () {
273
+ return this.getAll().every(function (tween) { return !tween.isPlaying(); });
245
274
  };
246
275
  Group.prototype.update = function (time, preserve) {
247
276
  if (time === void 0) { time = now(); }
248
- if (preserve === void 0) { preserve = false; }
277
+ if (preserve === void 0) { preserve = true; }
249
278
  var tweenIds = Object.keys(this._tweens);
250
- if (tweenIds.length === 0) {
251
- return false;
252
- }
279
+ if (tweenIds.length === 0)
280
+ return;
253
281
  // Tweens are updated in "batches". If you add a new tween during an
254
282
  // update, then the new tween will be updated in the next batch.
255
283
  // If you remove a tween during an update, it may or may not be updated.
@@ -260,13 +288,11 @@ var Group = /** @class */ (function () {
260
288
  for (var i = 0; i < tweenIds.length; i++) {
261
289
  var tween = this._tweens[tweenIds[i]];
262
290
  var autoStart = !preserve;
263
- if (tween && tween.update(time, autoStart) === false && !preserve) {
264
- delete this._tweens[tweenIds[i]];
265
- }
291
+ if (tween && tween.update(time, autoStart) === false && !preserve)
292
+ this.remove(tween);
266
293
  }
267
294
  tweenIds = Object.keys(this._tweensAddedDuringUpdate);
268
295
  }
269
- return true;
270
296
  };
271
297
  return Group;
272
298
  }());
@@ -375,10 +401,7 @@ var mainGroup = new Group();
375
401
  * Thank you all, you're awesome!
376
402
  */
377
403
  var Tween = /** @class */ (function () {
378
- function Tween(_object, _group) {
379
- if (_group === void 0) { _group = mainGroup; }
380
- this._object = _object;
381
- this._group = _group;
404
+ function Tween(object, group) {
382
405
  this._isPaused = false;
383
406
  this._pauseStart = 0;
384
407
  this._valuesStart = {};
@@ -403,6 +426,16 @@ var Tween = /** @class */ (function () {
403
426
  this._isChainStopped = false;
404
427
  this._propertiesAreSetUp = false;
405
428
  this._goToEnd = false;
429
+ this._object = object;
430
+ if (typeof group === 'object') {
431
+ this._group = group;
432
+ group.add(this);
433
+ }
434
+ // Use "true" to restore old behavior (will be removed in future release).
435
+ else if (group === true) {
436
+ this._group = mainGroup;
437
+ mainGroup.add(this);
438
+ }
406
439
  }
407
440
  Tween.prototype.getId = function () {
408
441
  return this._id;
@@ -441,8 +474,6 @@ var Tween = /** @class */ (function () {
441
474
  if (this._isPlaying) {
442
475
  return this;
443
476
  }
444
- // eslint-disable-next-line
445
- this._group && this._group.add(this);
446
477
  this._repeat = this._initialRepeat;
447
478
  if (this._reversed) {
448
479
  // If we were reversed (f.e. using the yoyo feature) then we need to
@@ -559,8 +590,6 @@ var Tween = /** @class */ (function () {
559
590
  if (!this._isPlaying) {
560
591
  return this;
561
592
  }
562
- // eslint-disable-next-line
563
- this._group && this._group.remove(this);
564
593
  this._isPlaying = false;
565
594
  this._isPaused = false;
566
595
  if (this._onStopCallback) {
@@ -580,8 +609,6 @@ var Tween = /** @class */ (function () {
580
609
  }
581
610
  this._isPaused = true;
582
611
  this._pauseStart = time;
583
- // eslint-disable-next-line
584
- this._group && this._group.remove(this);
585
612
  return this;
586
613
  };
587
614
  Tween.prototype.resume = function (time) {
@@ -592,8 +619,6 @@ var Tween = /** @class */ (function () {
592
619
  this._isPaused = false;
593
620
  this._startTime += time - this._pauseStart;
594
621
  this._pauseStart = 0;
595
- // eslint-disable-next-line
596
- this._group && this._group.add(this);
597
622
  return this;
598
623
  };
599
624
  Tween.prototype.stopChainedTweens = function () {
@@ -603,8 +628,19 @@ var Tween = /** @class */ (function () {
603
628
  return this;
604
629
  };
605
630
  Tween.prototype.group = function (group) {
606
- if (group === void 0) { group = mainGroup; }
607
- this._group = group;
631
+ if (!group) {
632
+ console.warn('tween.group() without args has been removed, use group.add(tween) instead.');
633
+ return this;
634
+ }
635
+ group.add(this);
636
+ return this;
637
+ };
638
+ /**
639
+ * Removes the tween from whichever group it is in.
640
+ */
641
+ Tween.prototype.remove = function () {
642
+ var _a;
643
+ (_a = this._group) === null || _a === void 0 ? void 0 : _a.remove(this);
608
644
  return this;
609
645
  };
610
646
  Tween.prototype.delay = function (amount) {
@@ -683,12 +719,11 @@ var Tween = /** @class */ (function () {
683
719
  if (this._isPaused)
684
720
  return true;
685
721
  var property;
686
- var endTime = this._startTime + this._duration;
687
722
  if (!this._goToEnd && !this._isPlaying) {
688
- if (time > endTime)
689
- return false;
690
723
  if (autoStart)
691
724
  this.start(time, true);
725
+ else
726
+ return false;
692
727
  }
693
728
  this._goToEnd = false;
694
729
  if (time < this._startTime) {
@@ -830,7 +865,7 @@ var Tween = /** @class */ (function () {
830
865
  return Tween;
831
866
  }());
832
867
 
833
- var VERSION = '23.1.3';
868
+ var VERSION = '24.0.0';
834
869
 
835
870
  /**
836
871
  * Tween.js - Licensed under the MIT license
@@ -852,10 +887,245 @@ var TWEEN = mainGroup;
852
887
  // Modules and CommonJS, without build hacks, and so as not to break the
853
888
  // existing API.
854
889
  // https://github.com/rollup/rollup/issues/1961#issuecomment-423037881
890
+ /**
891
+ * @deprecated The global TWEEN Group will be removed in a following major
892
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
893
+ * group.
894
+ *
895
+ * Old code:
896
+ *
897
+ * ```js
898
+ * import * as TWEEN from '@tweenjs/tween.js'
899
+ *
900
+ * //...
901
+ *
902
+ * const tween = new TWEEN.Tween(obj)
903
+ * const tween2 = new TWEEN.Tween(obj2)
904
+ *
905
+ * //...
906
+ *
907
+ * requestAnimationFrame(function loop(time) {
908
+ * TWEEN.update(time)
909
+ * requestAnimationFrame(loop)
910
+ * })
911
+ * ```
912
+ *
913
+ * New code:
914
+ *
915
+ * ```js
916
+ * import {Tween, Group} from '@tweenjs/tween.js'
917
+ *
918
+ * //...
919
+ *
920
+ * const tween = new Tween(obj)
921
+ * const tween2 = new TWEEN.Tween(obj2)
922
+ *
923
+ * //...
924
+ *
925
+ * const group = new Group()
926
+ * group.add(tween)
927
+ * group.add(tween2)
928
+ *
929
+ * //...
930
+ *
931
+ * requestAnimationFrame(function loop(time) {
932
+ * group.update(time)
933
+ * requestAnimationFrame(loop)
934
+ * })
935
+ * ```
936
+ */
855
937
  var getAll = TWEEN.getAll.bind(TWEEN);
938
+ /**
939
+ * @deprecated The global TWEEN Group will be removed in a following major
940
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
941
+ * group.
942
+ *
943
+ * Old code:
944
+ *
945
+ * ```js
946
+ * import * as TWEEN from '@tweenjs/tween.js'
947
+ *
948
+ * //...
949
+ *
950
+ * const tween = new TWEEN.Tween(obj)
951
+ * const tween2 = new TWEEN.Tween(obj2)
952
+ *
953
+ * //...
954
+ *
955
+ * requestAnimationFrame(function loop(time) {
956
+ * TWEEN.update(time)
957
+ * requestAnimationFrame(loop)
958
+ * })
959
+ * ```
960
+ *
961
+ * New code:
962
+ *
963
+ * ```js
964
+ * import {Tween, Group} from '@tweenjs/tween.js'
965
+ *
966
+ * //...
967
+ *
968
+ * const tween = new Tween(obj)
969
+ * const tween2 = new TWEEN.Tween(obj2)
970
+ *
971
+ * //...
972
+ *
973
+ * const group = new Group()
974
+ * group.add(tween)
975
+ * group.add(tween2)
976
+ *
977
+ * //...
978
+ *
979
+ * requestAnimationFrame(function loop(time) {
980
+ * group.update(time)
981
+ * requestAnimationFrame(loop)
982
+ * })
983
+ * ```
984
+ */
856
985
  var removeAll = TWEEN.removeAll.bind(TWEEN);
986
+ /**
987
+ * @deprecated The global TWEEN Group will be removed in a following major
988
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
989
+ * group.
990
+ *
991
+ * Old code:
992
+ *
993
+ * ```js
994
+ * import * as TWEEN from '@tweenjs/tween.js'
995
+ *
996
+ * //...
997
+ *
998
+ * const tween = new TWEEN.Tween(obj)
999
+ * const tween2 = new TWEEN.Tween(obj2)
1000
+ *
1001
+ * //...
1002
+ *
1003
+ * requestAnimationFrame(function loop(time) {
1004
+ * TWEEN.update(time)
1005
+ * requestAnimationFrame(loop)
1006
+ * })
1007
+ * ```
1008
+ *
1009
+ * New code:
1010
+ *
1011
+ * ```js
1012
+ * import {Tween, Group} from '@tweenjs/tween.js'
1013
+ *
1014
+ * //...
1015
+ *
1016
+ * const tween = new Tween(obj)
1017
+ * const tween2 = new TWEEN.Tween(obj2)
1018
+ *
1019
+ * //...
1020
+ *
1021
+ * const group = new Group()
1022
+ * group.add(tween)
1023
+ * group.add(tween2)
1024
+ *
1025
+ * //...
1026
+ *
1027
+ * requestAnimationFrame(function loop(time) {
1028
+ * group.update(time)
1029
+ * requestAnimationFrame(loop)
1030
+ * })
1031
+ * ```
1032
+ */
857
1033
  var add = TWEEN.add.bind(TWEEN);
1034
+ /**
1035
+ * @deprecated The global TWEEN Group will be removed in a following major
1036
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1037
+ * group.
1038
+ *
1039
+ * Old code:
1040
+ *
1041
+ * ```js
1042
+ * import * as TWEEN from '@tweenjs/tween.js'
1043
+ *
1044
+ * //...
1045
+ *
1046
+ * const tween = new TWEEN.Tween(obj)
1047
+ * const tween2 = new TWEEN.Tween(obj2)
1048
+ *
1049
+ * //...
1050
+ *
1051
+ * requestAnimationFrame(function loop(time) {
1052
+ * TWEEN.update(time)
1053
+ * requestAnimationFrame(loop)
1054
+ * })
1055
+ * ```
1056
+ *
1057
+ * New code:
1058
+ *
1059
+ * ```js
1060
+ * import {Tween, Group} from '@tweenjs/tween.js'
1061
+ *
1062
+ * //...
1063
+ *
1064
+ * const tween = new Tween(obj)
1065
+ * const tween2 = new TWEEN.Tween(obj2)
1066
+ *
1067
+ * //...
1068
+ *
1069
+ * const group = new Group()
1070
+ * group.add(tween)
1071
+ * group.add(tween2)
1072
+ *
1073
+ * //...
1074
+ *
1075
+ * requestAnimationFrame(function loop(time) {
1076
+ * group.update(time)
1077
+ * requestAnimationFrame(loop)
1078
+ * })
1079
+ * ```
1080
+ */
858
1081
  var remove = TWEEN.remove.bind(TWEEN);
1082
+ /**
1083
+ * @deprecated The global TWEEN Group will be removed in a following major
1084
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1085
+ * group.
1086
+ *
1087
+ * Old code:
1088
+ *
1089
+ * ```js
1090
+ * import * as TWEEN from '@tweenjs/tween.js'
1091
+ *
1092
+ * //...
1093
+ *
1094
+ * const tween = new TWEEN.Tween(obj)
1095
+ * const tween2 = new TWEEN.Tween(obj2)
1096
+ *
1097
+ * //...
1098
+ *
1099
+ * requestAnimationFrame(function loop(time) {
1100
+ * TWEEN.update(time)
1101
+ * requestAnimationFrame(loop)
1102
+ * })
1103
+ * ```
1104
+ *
1105
+ * New code:
1106
+ *
1107
+ * ```js
1108
+ * import {Tween, Group} from '@tweenjs/tween.js'
1109
+ *
1110
+ * //...
1111
+ *
1112
+ * const tween = new Tween(obj)
1113
+ * const tween2 = new TWEEN.Tween(obj2)
1114
+ *
1115
+ * //...
1116
+ *
1117
+ * const group = new Group()
1118
+ * group.add(tween)
1119
+ * group.add(tween2)
1120
+ *
1121
+ * //...
1122
+ *
1123
+ * requestAnimationFrame(function loop(time) {
1124
+ * group.update(time)
1125
+ * requestAnimationFrame(loop)
1126
+ * })
1127
+ * ```
1128
+ */
859
1129
  var update = TWEEN.update.bind(TWEEN);
860
1130
  var exports = {
861
1131
  Easing: Easing,
@@ -866,10 +1136,245 @@ var exports = {
866
1136
  nextId: nextId,
867
1137
  Tween: Tween,
868
1138
  VERSION: VERSION,
1139
+ /**
1140
+ * @deprecated The global TWEEN Group will be removed in a following major
1141
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1142
+ * group.
1143
+ *
1144
+ * Old code:
1145
+ *
1146
+ * ```js
1147
+ * import * as TWEEN from '@tweenjs/tween.js'
1148
+ *
1149
+ * //...
1150
+ *
1151
+ * const tween = new TWEEN.Tween(obj)
1152
+ * const tween2 = new TWEEN.Tween(obj2)
1153
+ *
1154
+ * //...
1155
+ *
1156
+ * requestAnimationFrame(function loop(time) {
1157
+ * TWEEN.update(time)
1158
+ * requestAnimationFrame(loop)
1159
+ * })
1160
+ * ```
1161
+ *
1162
+ * New code:
1163
+ *
1164
+ * ```js
1165
+ * import {Tween, Group} from '@tweenjs/tween.js'
1166
+ *
1167
+ * //...
1168
+ *
1169
+ * const tween = new Tween(obj)
1170
+ * const tween2 = new TWEEN.Tween(obj2)
1171
+ *
1172
+ * //...
1173
+ *
1174
+ * const group = new Group()
1175
+ * group.add(tween)
1176
+ * group.add(tween2)
1177
+ *
1178
+ * //...
1179
+ *
1180
+ * requestAnimationFrame(function loop(time) {
1181
+ * group.update(time)
1182
+ * requestAnimationFrame(loop)
1183
+ * })
1184
+ * ```
1185
+ */
869
1186
  getAll: getAll,
1187
+ /**
1188
+ * @deprecated The global TWEEN Group will be removed in a following major
1189
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1190
+ * group.
1191
+ *
1192
+ * Old code:
1193
+ *
1194
+ * ```js
1195
+ * import * as TWEEN from '@tweenjs/tween.js'
1196
+ *
1197
+ * //...
1198
+ *
1199
+ * const tween = new TWEEN.Tween(obj)
1200
+ * const tween2 = new TWEEN.Tween(obj2)
1201
+ *
1202
+ * //...
1203
+ *
1204
+ * requestAnimationFrame(function loop(time) {
1205
+ * TWEEN.update(time)
1206
+ * requestAnimationFrame(loop)
1207
+ * })
1208
+ * ```
1209
+ *
1210
+ * New code:
1211
+ *
1212
+ * ```js
1213
+ * import {Tween, Group} from '@tweenjs/tween.js'
1214
+ *
1215
+ * //...
1216
+ *
1217
+ * const tween = new Tween(obj)
1218
+ * const tween2 = new TWEEN.Tween(obj2)
1219
+ *
1220
+ * //...
1221
+ *
1222
+ * const group = new Group()
1223
+ * group.add(tween)
1224
+ * group.add(tween2)
1225
+ *
1226
+ * //...
1227
+ *
1228
+ * requestAnimationFrame(function loop(time) {
1229
+ * group.update(time)
1230
+ * requestAnimationFrame(loop)
1231
+ * })
1232
+ * ```
1233
+ */
870
1234
  removeAll: removeAll,
1235
+ /**
1236
+ * @deprecated The global TWEEN Group will be removed in a following major
1237
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1238
+ * group.
1239
+ *
1240
+ * Old code:
1241
+ *
1242
+ * ```js
1243
+ * import * as TWEEN from '@tweenjs/tween.js'
1244
+ *
1245
+ * //...
1246
+ *
1247
+ * const tween = new TWEEN.Tween(obj)
1248
+ * const tween2 = new TWEEN.Tween(obj2)
1249
+ *
1250
+ * //...
1251
+ *
1252
+ * requestAnimationFrame(function loop(time) {
1253
+ * TWEEN.update(time)
1254
+ * requestAnimationFrame(loop)
1255
+ * })
1256
+ * ```
1257
+ *
1258
+ * New code:
1259
+ *
1260
+ * ```js
1261
+ * import {Tween, Group} from '@tweenjs/tween.js'
1262
+ *
1263
+ * //...
1264
+ *
1265
+ * const tween = new Tween(obj)
1266
+ * const tween2 = new TWEEN.Tween(obj2)
1267
+ *
1268
+ * //...
1269
+ *
1270
+ * const group = new Group()
1271
+ * group.add(tween)
1272
+ * group.add(tween2)
1273
+ *
1274
+ * //...
1275
+ *
1276
+ * requestAnimationFrame(function loop(time) {
1277
+ * group.update(time)
1278
+ * requestAnimationFrame(loop)
1279
+ * })
1280
+ * ```
1281
+ */
871
1282
  add: add,
1283
+ /**
1284
+ * @deprecated The global TWEEN Group will be removed in a following major
1285
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1286
+ * group.
1287
+ *
1288
+ * Old code:
1289
+ *
1290
+ * ```js
1291
+ * import * as TWEEN from '@tweenjs/tween.js'
1292
+ *
1293
+ * //...
1294
+ *
1295
+ * const tween = new TWEEN.Tween(obj)
1296
+ * const tween2 = new TWEEN.Tween(obj2)
1297
+ *
1298
+ * //...
1299
+ *
1300
+ * requestAnimationFrame(function loop(time) {
1301
+ * TWEEN.update(time)
1302
+ * requestAnimationFrame(loop)
1303
+ * })
1304
+ * ```
1305
+ *
1306
+ * New code:
1307
+ *
1308
+ * ```js
1309
+ * import {Tween, Group} from '@tweenjs/tween.js'
1310
+ *
1311
+ * //...
1312
+ *
1313
+ * const tween = new Tween(obj)
1314
+ * const tween2 = new TWEEN.Tween(obj2)
1315
+ *
1316
+ * //...
1317
+ *
1318
+ * const group = new Group()
1319
+ * group.add(tween)
1320
+ * group.add(tween2)
1321
+ *
1322
+ * //...
1323
+ *
1324
+ * requestAnimationFrame(function loop(time) {
1325
+ * group.update(time)
1326
+ * requestAnimationFrame(loop)
1327
+ * })
1328
+ * ```
1329
+ */
872
1330
  remove: remove,
1331
+ /**
1332
+ * @deprecated The global TWEEN Group will be removed in a following major
1333
+ * release. To migrate, create a `new Group()` instead of using `TWEEN` as a
1334
+ * group.
1335
+ *
1336
+ * Old code:
1337
+ *
1338
+ * ```js
1339
+ * import * as TWEEN from '@tweenjs/tween.js'
1340
+ *
1341
+ * //...
1342
+ *
1343
+ * const tween = new TWEEN.Tween(obj)
1344
+ * const tween2 = new TWEEN.Tween(obj2)
1345
+ *
1346
+ * //...
1347
+ *
1348
+ * requestAnimationFrame(function loop(time) {
1349
+ * TWEEN.update(time)
1350
+ * requestAnimationFrame(loop)
1351
+ * })
1352
+ * ```
1353
+ *
1354
+ * New code:
1355
+ *
1356
+ * ```js
1357
+ * import {Tween, Group} from '@tweenjs/tween.js'
1358
+ *
1359
+ * //...
1360
+ *
1361
+ * const tween = new Tween(obj)
1362
+ * const tween2 = new TWEEN.Tween(obj2)
1363
+ *
1364
+ * //...
1365
+ *
1366
+ * const group = new Group()
1367
+ * group.add(tween)
1368
+ * group.add(tween2)
1369
+ *
1370
+ * //...
1371
+ *
1372
+ * requestAnimationFrame(function loop(time) {
1373
+ * group.update(time)
1374
+ * requestAnimationFrame(loop)
1375
+ * })
1376
+ * ```
1377
+ */
873
1378
  update: update,
874
1379
  };
875
1380