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