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