animejs 4.2.0-beta.0 → 4.2.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.
Files changed (73) hide show
  1. package/README.md +6 -1
  2. package/dist/bundles/anime.esm.js +448 -260
  3. package/dist/bundles/anime.esm.min.js +1 -1
  4. package/dist/bundles/anime.umd.js +449 -261
  5. package/dist/bundles/anime.umd.min.js +1 -1
  6. package/dist/modules/animatable/animatable.cjs +2 -2
  7. package/dist/modules/animatable/animatable.js +1 -1
  8. package/dist/modules/animation/animation.cjs +21 -14
  9. package/dist/modules/animation/animation.d.ts +0 -2
  10. package/dist/modules/animation/animation.js +20 -13
  11. package/dist/modules/core/consts.cjs +6 -1
  12. package/dist/modules/core/consts.d.ts +2 -0
  13. package/dist/modules/core/consts.js +5 -2
  14. package/dist/modules/core/globals.cjs +1 -0
  15. package/dist/modules/core/globals.js +1 -0
  16. package/dist/modules/core/render.cjs +3 -1
  17. package/dist/modules/core/render.js +3 -1
  18. package/dist/modules/core/styles.cjs +7 -7
  19. package/dist/modules/core/styles.js +9 -9
  20. package/dist/modules/core/values.cjs +16 -5
  21. package/dist/modules/core/values.js +18 -7
  22. package/dist/modules/draggable/draggable.cjs +16 -16
  23. package/dist/modules/draggable/draggable.d.ts +1 -1
  24. package/dist/modules/draggable/draggable.js +11 -11
  25. package/dist/modules/easings/{cubic-bezier.cjs → cubic-bezier/index.cjs} +3 -3
  26. package/dist/modules/easings/{cubic-bezier.d.ts → cubic-bezier/index.d.ts} +1 -1
  27. package/dist/modules/easings/{cubic-bezier.js → cubic-bezier/index.js} +3 -3
  28. package/dist/modules/easings/eases/index.cjs +14 -0
  29. package/dist/modules/easings/eases/index.d.ts +1 -0
  30. package/dist/modules/{spring → easings/eases}/index.js +2 -2
  31. package/dist/modules/easings/{eases.cjs → eases/parser.cjs} +68 -26
  32. package/dist/modules/easings/{eases.d.ts → eases/parser.d.ts} +31 -17
  33. package/dist/modules/easings/{eases.js → eases/parser.js} +59 -20
  34. package/dist/modules/easings/index.cjs +14 -12
  35. package/dist/modules/easings/index.d.ts +6 -6
  36. package/dist/modules/easings/index.js +6 -6
  37. package/dist/modules/easings/{irregular.cjs → irregular/index.cjs} +4 -4
  38. package/dist/modules/easings/{irregular.d.ts → irregular/index.d.ts} +1 -1
  39. package/dist/modules/easings/{irregular.js → irregular/index.js} +3 -3
  40. package/dist/modules/easings/{linear.cjs → linear/index.cjs} +3 -3
  41. package/dist/modules/easings/{linear.d.ts → linear/index.d.ts} +1 -1
  42. package/dist/modules/easings/{linear.js → linear/index.js} +3 -3
  43. package/dist/modules/easings/spring/index.cjs +255 -0
  44. package/dist/modules/{spring/spring.d.ts → easings/spring/index.d.ts} +21 -5
  45. package/dist/modules/easings/spring/index.js +251 -0
  46. package/dist/modules/easings/{steps.cjs → steps/index.cjs} +2 -2
  47. package/dist/modules/easings/{steps.d.ts → steps/index.d.ts} +1 -1
  48. package/dist/modules/easings/{steps.js → steps/index.js} +2 -2
  49. package/dist/modules/events/scroll.cjs +10 -6
  50. package/dist/modules/events/scroll.d.ts +2 -0
  51. package/dist/modules/events/scroll.js +9 -5
  52. package/dist/modules/index.cjs +14 -15
  53. package/dist/modules/index.d.ts +0 -1
  54. package/dist/modules/index.js +6 -7
  55. package/dist/modules/timeline/timeline.cjs +2 -2
  56. package/dist/modules/timeline/timeline.js +1 -1
  57. package/dist/modules/types/index.d.ts +30 -13
  58. package/dist/modules/utils/stagger.cjs +3 -3
  59. package/dist/modules/utils/stagger.js +2 -2
  60. package/dist/modules/waapi/composition.cjs +10 -4
  61. package/dist/modules/waapi/composition.d.ts +1 -1
  62. package/dist/modules/waapi/composition.js +10 -4
  63. package/dist/modules/waapi/waapi.cjs +50 -31
  64. package/dist/modules/waapi/waapi.d.ts +4 -2
  65. package/dist/modules/waapi/waapi.js +51 -32
  66. package/package.json +46 -10
  67. package/dist/modules/easings/parser.cjs +0 -59
  68. package/dist/modules/easings/parser.d.ts +0 -21
  69. package/dist/modules/easings/parser.js +0 -55
  70. package/dist/modules/spring/index.cjs +0 -15
  71. package/dist/modules/spring/index.d.ts +0 -1
  72. package/dist/modules/spring/spring.cjs +0 -133
  73. package/dist/modules/spring/spring.js +0 -130
@@ -13,7 +13,7 @@ var targets = require('../core/targets.cjs');
13
13
  var values = require('../core/values.cjs');
14
14
  var consts = require('../core/consts.cjs');
15
15
  var none = require('../easings/none.cjs');
16
- var parser = require('../easings/parser.cjs');
16
+ var parser = require('../easings/eases/parser.cjs');
17
17
  var composition = require('./composition.cjs');
18
18
 
19
19
  /**
@@ -35,7 +35,7 @@ var composition = require('./composition.cjs');
35
35
  /**
36
36
  * @import {
37
37
  * Spring,
38
- * } from '../spring/spring.js'
38
+ * } from '../easings/spring/index.js'
39
39
  */
40
40
 
41
41
  /**
@@ -52,21 +52,11 @@ var composition = require('./composition.cjs');
52
52
  */
53
53
  const easingToLinear = (fn, samples = 100) => {
54
54
  const points = [];
55
- for (let i = 0; i <= samples; i++) points.push(fn(i / samples));
55
+ for (let i = 0; i <= samples; i++) points.push(helpers.round(fn(i / samples), 4));
56
56
  return `linear(${points.join(', ')})`;
57
57
  };
58
58
 
59
- const WAAPIEasesLookups = {
60
- in: 'ease-in',
61
- out: 'ease-out',
62
- inOut: 'ease-in-out',
63
- };
64
-
65
- const WAAPIeases = /*#__PURE__*/(() => {
66
- const list = {};
67
- for (let type in parser.easeTypes) list[type] = (/** @type {String|Number} */p) => parser.easeTypes[type](parser.easeInPower(p));
68
- return /** @type {Record<String, EasingFunction>} */(list);
69
- })();
59
+ const WAAPIEasesLookups = {};
70
60
 
71
61
  /**
72
62
  * @param {EasingParam} ease
@@ -87,9 +77,10 @@ const parseWAAPIEasing = (ease) => {
87
77
  } else if (helpers.stringStartsWith(ease, 'cubicB')) {
88
78
  parsedEase = helpers.toLowerCase(ease);
89
79
  } else {
90
- const parsed = parser.parseEaseString(ease, WAAPIeases, WAAPIEasesLookups);
80
+ const parsed = parser.parseEaseString(ease);
91
81
  if (helpers.isFnc(parsed)) parsedEase = parsed === none.none ? 'linear' : easingToLinear(parsed);
92
82
  }
83
+ // Only cache string based easing name, otherwise function arguments get lost
93
84
  WAAPIEasesLookups[ease] = parsedEase;
94
85
  } else if (helpers.isFnc(ease)) {
95
86
  const easing = easingToLinear(ease);
@@ -130,7 +121,8 @@ let transformsPropertiesRegistered = null;
130
121
  * @return {String}
131
122
  */
132
123
  const normalizeTweenValue = (propName, value, $el, i, targetsLength) => {
133
- let v = values.getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
124
+ // Do not try to compute strings with getFunctionValue otherwise it will convert CSS variables
125
+ let v = helpers.isStr(value) ? value : values.getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
134
126
  if (!helpers.isNum(v)) return v;
135
127
  if (commonDefaultPXProperties.includes(propName) || helpers.stringStartsWith(propName, 'translate')) return `${v}px`;
136
128
  if (helpers.stringStartsWith(propName, 'rotate') || helpers.stringStartsWith(propName, 'skew')) return `${v}deg`;
@@ -210,7 +202,7 @@ class WAAPIAnimation {
210
202
  /** @type {PlaybackDirection} */
211
203
  const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal';
212
204
  /** @type {FillMode} */
213
- const fill = 'forwards';
205
+ const fill = 'both'; // We use 'both' here because the animation can be reversed during playback
214
206
  /** @type {String} */
215
207
  const easing = parseWAAPIEasing(ease);
216
208
  const timeScale = (globals.globals.timeScale === 1 ? 1 : consts.K);
@@ -222,7 +214,7 @@ class WAAPIAnimation {
222
214
  /** @type {globalThis.Animation}] */
223
215
  this.controlAnimation = null;
224
216
  /** @type {Callback<this>} */
225
- this.onComplete = params.onComplete || consts.noop;
217
+ this.onComplete = params.onComplete || /** @type {Callback<WAAPIAnimation>} */(/** @type {unknown} */(globals.globals.defaults.onComplete));
226
218
  /** @type {Number} */
227
219
  this.duration = 0;
228
220
  /** @type {Boolean} */
@@ -233,6 +225,8 @@ class WAAPIAnimation {
233
225
  this.paused = !autoplay || scroll !== false;
234
226
  /** @type {Boolean} */
235
227
  this.reversed = reversed;
228
+ /** @type {Boolean} */
229
+ this.persist = values.setValue(params.persist, globals.globals.defaults.persist);
236
230
  /** @type {Boolean|ScrollObserver} */
237
231
  this.autoplay = autoplay;
238
232
  /** @type {Number} */
@@ -241,17 +235,18 @@ class WAAPIAnimation {
241
235
  this._resolve = consts.noop; // Used by .then()
242
236
  /** @type {Number} */
243
237
  this._completed = 0;
244
- /** @type {Array<Object>}] */
245
- this._inlineStyles = parsedTargets.map($el => $el.getAttribute('style'));
238
+ /** @type {Array.<Object>} */
239
+ this._inlineStyles = [];
246
240
 
247
241
  parsedTargets.forEach(($el, i) => {
248
242
 
249
243
  const cachedTransforms = $el[consts.transformsSymbol];
250
-
251
244
  const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t));
245
+ const elStyle = $el.style;
246
+ const inlineStyles = this._inlineStyles[i] = {};
252
247
 
253
248
  /** @type {Number} */
254
- const duration = (spring ? /** @type {Spring} */(spring).duration : values.getFunctionValue(values.setValue(params.duration, globals.globals.defaults.duration), $el, i, targetsLength)) * timeScale;
249
+ const duration = (spring ? /** @type {Spring} */(spring).settlingDuration : values.getFunctionValue(values.setValue(params.duration, globals.globals.defaults.duration), $el, i, targetsLength)) * timeScale;
255
250
  /** @type {Number} */
256
251
  const delay = values.getFunctionValue(values.setValue(params.delay, globals.globals.defaults.delay), $el, i, targetsLength) * timeScale;
257
252
  /** @type {CompositeOperation} */
@@ -265,6 +260,12 @@ class WAAPIAnimation {
265
260
  const tweenParams = { iterations, direction, fill, easing, duration, delay, composite };
266
261
  const propertyValue = params[name];
267
262
  const individualTransformProperty = hasIndividualTransforms ? consts.validTransforms.includes(name) ? name : consts.shortTransforms.get(name) : false;
263
+
264
+ const styleName = individualTransformProperty ? 'transform' : name;
265
+ if (!inlineStyles[styleName]) {
266
+ inlineStyles[styleName] = elStyle[styleName];
267
+ }
268
+
268
269
  let parsedPropertyValue;
269
270
  if (helpers.isObj(propertyValue)) {
270
271
  const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue);
@@ -273,7 +274,7 @@ class WAAPIAnimation {
273
274
  const to = /** @type {WAAPITweenOptions} */(tweenOptions).to;
274
275
  const from = /** @type {WAAPITweenOptions} */(tweenOptions).from;
275
276
  /** @type {Number} */
276
- tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).duration : values.getFunctionValue(values.setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
277
+ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).settlingDuration : values.getFunctionValue(values.setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
277
278
  /** @type {Number} */
278
279
  tweenParams.delay = values.getFunctionValue(values.setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale;
279
280
  /** @type {CompositeOperation} */
@@ -290,10 +291,10 @@ class WAAPIAnimation {
290
291
  composition.addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
291
292
  if (!helpers.isUnd(from)) {
292
293
  if (!individualTransformProperty) {
293
- $el.style[name] = keyframes[name][0];
294
+ elStyle[name] = keyframes[name][0];
294
295
  } else {
295
296
  const key = `--${individualTransformProperty}`;
296
- $el.style.setProperty(key, keyframes[key][0]);
297
+ elStyle.setProperty(key, keyframes[key][0]);
297
298
  }
298
299
  }
299
300
  } else {
@@ -314,7 +315,7 @@ class WAAPIAnimation {
314
315
  for (let t in cachedTransforms) {
315
316
  transforms += `${consts.transformsFragmentStrings[t]}var(--${t})) `;
316
317
  }
317
- $el.style.transform = transforms;
318
+ elStyle.transform = transforms;
318
319
  }
319
320
  });
320
321
 
@@ -359,7 +360,8 @@ class WAAPIAnimation {
359
360
  // Make sure the animation playState is not 'paused' in order to properly trigger an onfinish callback.
360
361
  // The "paused" play state supersedes the "finished" play state; if the animation is both paused and finished, the "paused" state is the one that will be reported.
361
362
  // https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event
362
- if (t >= this.duration) anim.play();
363
+ // This is not needed for persisting animations since they never finish.
364
+ if (!this.persist && t >= this.duration) anim.play();
363
365
  anim.currentTime = t;
364
366
  });
365
367
  }
@@ -429,13 +431,30 @@ class WAAPIAnimation {
429
431
  }
430
432
 
431
433
  cancel() {
432
- this.forEach('cancel');
433
- return this.pause();
434
+ this.muteCallbacks = true; // This prevents triggering the onComplete callback and resolving the Promise
435
+ return this.commitStyles().forEach('cancel');
434
436
  }
435
437
 
436
438
  revert() {
437
- this.cancel();
438
- this.targets.forEach(($el, i) => $el.setAttribute('style', this._inlineStyles[i]) );
439
+ // NOTE: We need a better way to revert the transforms, since right now the entire transform property value is reverted,
440
+ // This means if you have multiple animations animating different transforms on the same target,
441
+ // reverting one of them will also override the transform property of the other animations.
442
+ // A better approach would be to store the original custom property values is they exist instead of the entire transform value,
443
+ // and update the CSS variables with the orignal value
444
+ this.cancel().targets.forEach(($el, i) => {
445
+ const targetStyle = $el.style;
446
+ const targetInlineStyles = this._inlineStyles[i];
447
+ for (let name in targetInlineStyles) {
448
+ const originalInlinedValue = targetInlineStyles[name];
449
+ if (helpers.isUnd(originalInlinedValue) || originalInlinedValue === consts.emptyString) {
450
+ targetStyle.removeProperty(helpers.toLowerCase(name));
451
+ } else {
452
+ targetStyle[name] = originalInlinedValue;
453
+ }
454
+ }
455
+ // Remove style attribute if empty
456
+ if ($el.getAttribute('style') === consts.emptyString) $el.removeAttribute('style');
457
+ });
439
458
  return this;
440
459
  }
441
460
 
@@ -22,6 +22,8 @@ export class WAAPIAnimation {
22
22
  paused: boolean;
23
23
  /** @type {Boolean} */
24
24
  reversed: boolean;
25
+ /** @type {Boolean} */
26
+ persist: boolean;
25
27
  /** @type {Boolean|ScrollObserver} */
26
28
  autoplay: boolean | ScrollObserver;
27
29
  /** @type {Number} */
@@ -30,7 +32,7 @@ export class WAAPIAnimation {
30
32
  _resolve: Function;
31
33
  /** @type {Number} */
32
34
  _completed: number;
33
- /** @type {Array<Object>}] */
35
+ /** @type {Array.<Object>} */
34
36
  _inlineStyles: Array<any>;
35
37
  /**
36
38
  * @callback forEachCallback
@@ -96,7 +98,7 @@ import type { WAAPIAnimationParams } from '../types/index.js';
96
98
  /**
97
99
  * @import {
98
100
  * Spring,
99
- * } from '../spring/spring.js'
101
+ * } from '../easings/spring/index.js'
100
102
  */
101
103
  /**
102
104
  * @import {
@@ -5,13 +5,13 @@
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
7
7
 
8
- import { isNil, isUnd, stringStartsWith, isKey, isObj, isArr, isStr, toLowerCase, isFnc, isNum } from '../core/helpers.js';
8
+ import { isNil, isUnd, stringStartsWith, isKey, isObj, isArr, toLowerCase, round, isStr, isFnc, isNum } from '../core/helpers.js';
9
9
  import { scope, globals } from '../core/globals.js';
10
10
  import { registerTargets } from '../core/targets.js';
11
11
  import { setValue, getFunctionValue } from '../core/values.js';
12
12
  import { isBrowser, validTransforms, noop, transformsSymbol, shortTransforms, transformsFragmentStrings, emptyString, K } from '../core/consts.js';
13
13
  import { none } from '../easings/none.js';
14
- import { parseEaseString, easeTypes, easeInPower } from '../easings/parser.js';
14
+ import { parseEaseString } from '../easings/eases/parser.js';
15
15
  import { addWAAPIAnimation } from './composition.js';
16
16
 
17
17
  /**
@@ -33,7 +33,7 @@ import { addWAAPIAnimation } from './composition.js';
33
33
  /**
34
34
  * @import {
35
35
  * Spring,
36
- * } from '../spring/spring.js'
36
+ * } from '../easings/spring/index.js'
37
37
  */
38
38
 
39
39
  /**
@@ -50,21 +50,11 @@ import { addWAAPIAnimation } from './composition.js';
50
50
  */
51
51
  const easingToLinear = (fn, samples = 100) => {
52
52
  const points = [];
53
- for (let i = 0; i <= samples; i++) points.push(fn(i / samples));
53
+ for (let i = 0; i <= samples; i++) points.push(round(fn(i / samples), 4));
54
54
  return `linear(${points.join(', ')})`;
55
55
  };
56
56
 
57
- const WAAPIEasesLookups = {
58
- in: 'ease-in',
59
- out: 'ease-out',
60
- inOut: 'ease-in-out',
61
- };
62
-
63
- const WAAPIeases = /*#__PURE__*/(() => {
64
- const list = {};
65
- for (let type in easeTypes) list[type] = (/** @type {String|Number} */p) => easeTypes[type](easeInPower(p));
66
- return /** @type {Record<String, EasingFunction>} */(list);
67
- })();
57
+ const WAAPIEasesLookups = {};
68
58
 
69
59
  /**
70
60
  * @param {EasingParam} ease
@@ -85,9 +75,10 @@ const parseWAAPIEasing = (ease) => {
85
75
  } else if (stringStartsWith(ease, 'cubicB')) {
86
76
  parsedEase = toLowerCase(ease);
87
77
  } else {
88
- const parsed = parseEaseString(ease, WAAPIeases, WAAPIEasesLookups);
78
+ const parsed = parseEaseString(ease);
89
79
  if (isFnc(parsed)) parsedEase = parsed === none ? 'linear' : easingToLinear(parsed);
90
80
  }
81
+ // Only cache string based easing name, otherwise function arguments get lost
91
82
  WAAPIEasesLookups[ease] = parsedEase;
92
83
  } else if (isFnc(ease)) {
93
84
  const easing = easingToLinear(ease);
@@ -128,7 +119,8 @@ let transformsPropertiesRegistered = null;
128
119
  * @return {String}
129
120
  */
130
121
  const normalizeTweenValue = (propName, value, $el, i, targetsLength) => {
131
- let v = getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
122
+ // Do not try to compute strings with getFunctionValue otherwise it will convert CSS variables
123
+ let v = isStr(value) ? value : getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
132
124
  if (!isNum(v)) return v;
133
125
  if (commonDefaultPXProperties.includes(propName) || stringStartsWith(propName, 'translate')) return `${v}px`;
134
126
  if (stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew')) return `${v}deg`;
@@ -208,7 +200,7 @@ class WAAPIAnimation {
208
200
  /** @type {PlaybackDirection} */
209
201
  const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal';
210
202
  /** @type {FillMode} */
211
- const fill = 'forwards';
203
+ const fill = 'both'; // We use 'both' here because the animation can be reversed during playback
212
204
  /** @type {String} */
213
205
  const easing = parseWAAPIEasing(ease);
214
206
  const timeScale = (globals.timeScale === 1 ? 1 : K);
@@ -220,7 +212,7 @@ class WAAPIAnimation {
220
212
  /** @type {globalThis.Animation}] */
221
213
  this.controlAnimation = null;
222
214
  /** @type {Callback<this>} */
223
- this.onComplete = params.onComplete || noop;
215
+ this.onComplete = params.onComplete || /** @type {Callback<WAAPIAnimation>} */(/** @type {unknown} */(globals.defaults.onComplete));
224
216
  /** @type {Number} */
225
217
  this.duration = 0;
226
218
  /** @type {Boolean} */
@@ -231,6 +223,8 @@ class WAAPIAnimation {
231
223
  this.paused = !autoplay || scroll !== false;
232
224
  /** @type {Boolean} */
233
225
  this.reversed = reversed;
226
+ /** @type {Boolean} */
227
+ this.persist = setValue(params.persist, globals.defaults.persist);
234
228
  /** @type {Boolean|ScrollObserver} */
235
229
  this.autoplay = autoplay;
236
230
  /** @type {Number} */
@@ -239,17 +233,18 @@ class WAAPIAnimation {
239
233
  this._resolve = noop; // Used by .then()
240
234
  /** @type {Number} */
241
235
  this._completed = 0;
242
- /** @type {Array<Object>}] */
243
- this._inlineStyles = parsedTargets.map($el => $el.getAttribute('style'));
236
+ /** @type {Array.<Object>} */
237
+ this._inlineStyles = [];
244
238
 
245
239
  parsedTargets.forEach(($el, i) => {
246
240
 
247
241
  const cachedTransforms = $el[transformsSymbol];
248
-
249
242
  const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t));
243
+ const elStyle = $el.style;
244
+ const inlineStyles = this._inlineStyles[i] = {};
250
245
 
251
246
  /** @type {Number} */
252
- const duration = (spring ? /** @type {Spring} */(spring).duration : getFunctionValue(setValue(params.duration, globals.defaults.duration), $el, i, targetsLength)) * timeScale;
247
+ const duration = (spring ? /** @type {Spring} */(spring).settlingDuration : getFunctionValue(setValue(params.duration, globals.defaults.duration), $el, i, targetsLength)) * timeScale;
253
248
  /** @type {Number} */
254
249
  const delay = getFunctionValue(setValue(params.delay, globals.defaults.delay), $el, i, targetsLength) * timeScale;
255
250
  /** @type {CompositeOperation} */
@@ -263,6 +258,12 @@ class WAAPIAnimation {
263
258
  const tweenParams = { iterations, direction, fill, easing, duration, delay, composite };
264
259
  const propertyValue = params[name];
265
260
  const individualTransformProperty = hasIndividualTransforms ? validTransforms.includes(name) ? name : shortTransforms.get(name) : false;
261
+
262
+ const styleName = individualTransformProperty ? 'transform' : name;
263
+ if (!inlineStyles[styleName]) {
264
+ inlineStyles[styleName] = elStyle[styleName];
265
+ }
266
+
266
267
  let parsedPropertyValue;
267
268
  if (isObj(propertyValue)) {
268
269
  const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue);
@@ -271,7 +272,7 @@ class WAAPIAnimation {
271
272
  const to = /** @type {WAAPITweenOptions} */(tweenOptions).to;
272
273
  const from = /** @type {WAAPITweenOptions} */(tweenOptions).from;
273
274
  /** @type {Number} */
274
- tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).duration : getFunctionValue(setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
275
+ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).settlingDuration : getFunctionValue(setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
275
276
  /** @type {Number} */
276
277
  tweenParams.delay = getFunctionValue(setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale;
277
278
  /** @type {CompositeOperation} */
@@ -288,10 +289,10 @@ class WAAPIAnimation {
288
289
  addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
289
290
  if (!isUnd(from)) {
290
291
  if (!individualTransformProperty) {
291
- $el.style[name] = keyframes[name][0];
292
+ elStyle[name] = keyframes[name][0];
292
293
  } else {
293
294
  const key = `--${individualTransformProperty}`;
294
- $el.style.setProperty(key, keyframes[key][0]);
295
+ elStyle.setProperty(key, keyframes[key][0]);
295
296
  }
296
297
  }
297
298
  } else {
@@ -312,7 +313,7 @@ class WAAPIAnimation {
312
313
  for (let t in cachedTransforms) {
313
314
  transforms += `${transformsFragmentStrings[t]}var(--${t})) `;
314
315
  }
315
- $el.style.transform = transforms;
316
+ elStyle.transform = transforms;
316
317
  }
317
318
  });
318
319
 
@@ -357,7 +358,8 @@ class WAAPIAnimation {
357
358
  // Make sure the animation playState is not 'paused' in order to properly trigger an onfinish callback.
358
359
  // The "paused" play state supersedes the "finished" play state; if the animation is both paused and finished, the "paused" state is the one that will be reported.
359
360
  // https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event
360
- if (t >= this.duration) anim.play();
361
+ // This is not needed for persisting animations since they never finish.
362
+ if (!this.persist && t >= this.duration) anim.play();
361
363
  anim.currentTime = t;
362
364
  });
363
365
  }
@@ -427,13 +429,30 @@ class WAAPIAnimation {
427
429
  }
428
430
 
429
431
  cancel() {
430
- this.forEach('cancel');
431
- return this.pause();
432
+ this.muteCallbacks = true; // This prevents triggering the onComplete callback and resolving the Promise
433
+ return this.commitStyles().forEach('cancel');
432
434
  }
433
435
 
434
436
  revert() {
435
- this.cancel();
436
- this.targets.forEach(($el, i) => $el.setAttribute('style', this._inlineStyles[i]) );
437
+ // NOTE: We need a better way to revert the transforms, since right now the entire transform property value is reverted,
438
+ // This means if you have multiple animations animating different transforms on the same target,
439
+ // reverting one of them will also override the transform property of the other animations.
440
+ // A better approach would be to store the original custom property values is they exist instead of the entire transform value,
441
+ // and update the CSS variables with the orignal value
442
+ this.cancel().targets.forEach(($el, i) => {
443
+ const targetStyle = $el.style;
444
+ const targetInlineStyles = this._inlineStyles[i];
445
+ for (let name in targetInlineStyles) {
446
+ const originalInlinedValue = targetInlineStyles[name];
447
+ if (isUnd(originalInlinedValue) || originalInlinedValue === emptyString) {
448
+ targetStyle.removeProperty(toLowerCase(name));
449
+ } else {
450
+ targetStyle[name] = originalInlinedValue;
451
+ }
452
+ }
453
+ // Remove style attribute if empty
454
+ if ($el.getAttribute('style') === emptyString) $el.removeAttribute('style');
455
+ });
437
456
  return this;
438
457
  }
439
458
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "animejs",
3
- "version": "4.2.0-beta.0",
4
- "description": "JavaScript animation engine",
3
+ "version": "4.2.0",
5
4
  "homepage": "https://animejs.com",
5
+ "description": "JavaScript animation engine",
6
6
  "author": "Julian Garnier <julian@animejs.com>",
7
7
  "license": "MIT",
8
8
  "repository": {
@@ -20,12 +20,17 @@
20
20
  "anime",
21
21
  "animejs",
22
22
  "anime.js",
23
+ "timer",
23
24
  "animation",
24
25
  "timeline",
26
+ "animatable",
27
+ "draggable",
28
+ "scope",
29
+ "engine",
30
+ "scroll",
25
31
  "easings",
32
+ "cubic-bezier",
26
33
  "spring",
27
- "scroll",
28
- "drag",
29
34
  "text",
30
35
  "JavaScript",
31
36
  "CSS",
@@ -100,18 +105,48 @@
100
105
  "import": "./dist/modules/events/index.js",
101
106
  "default": "./dist/modules/events/index.cjs"
102
107
  },
103
- "./spring": {
104
- "types": "./dist/modules/spring/index.d.ts",
105
- "require": "./dist/modules/spring/index.cjs",
106
- "import": "./dist/modules/spring/index.js",
107
- "default": "./dist/modules/spring/index.cjs"
108
- },
109
108
  "./easings": {
110
109
  "types": "./dist/modules/easings/index.d.ts",
111
110
  "require": "./dist/modules/easings/index.cjs",
112
111
  "import": "./dist/modules/easings/index.js",
113
112
  "default": "./dist/modules/easings/index.cjs"
114
113
  },
114
+ "./easings/eases": {
115
+ "types": "./dist/modules/easings/eases/index.d.ts",
116
+ "require": "./dist/modules/easings/eases/index.cjs",
117
+ "import": "./dist/modules/easings/eases/index.js",
118
+ "default": "./dist/modules/easings/eases/index.cjs"
119
+ },
120
+ "./easings/linear": {
121
+ "types": "./dist/modules/easings/linear/index.d.ts",
122
+ "require": "./dist/modules/easings/linear/index.cjs",
123
+ "import": "./dist/modules/easings/linear/index.js",
124
+ "default": "./dist/modules/easings/linear/index.cjs"
125
+ },
126
+ "./easings/steps": {
127
+ "types": "./dist/modules/easings/steps/index.d.ts",
128
+ "require": "./dist/modules/easings/steps/index.cjs",
129
+ "import": "./dist/modules/easings/steps/index.js",
130
+ "default": "./dist/modules/easings/steps/index.cjs"
131
+ },
132
+ "./easings/irregular": {
133
+ "types": "./dist/modules/easings/irregular/index.d.ts",
134
+ "require": "./dist/modules/easings/irregular/index.cjs",
135
+ "import": "./dist/modules/easings/irregular/index.js",
136
+ "default": "./dist/modules/easings/irregular/index.cjs"
137
+ },
138
+ "./easings/cubic-bezier": {
139
+ "types": "./dist/modules/easings/cubic-bezier/index.d.ts",
140
+ "require": "./dist/modules/easings/cubic-bezier/index.cjs",
141
+ "import": "./dist/modules/easings/cubic-bezier/index.js",
142
+ "default": "./dist/modules/easings/cubic-bezier/index.cjs"
143
+ },
144
+ "./easings/spring": {
145
+ "types": "./dist/modules/easings/spring/index.d.ts",
146
+ "require": "./dist/modules/easings/spring/index.cjs",
147
+ "import": "./dist/modules/easings/spring/index.js",
148
+ "default": "./dist/modules/easings/spring/index.cjs"
149
+ },
115
150
  "./utils": {
116
151
  "types": "./dist/modules/utils/index.d.ts",
117
152
  "require": "./dist/modules/utils/index.cjs",
@@ -139,6 +174,7 @@
139
174
  },
140
175
  "devDependencies": {
141
176
  "@rollup/plugin-terser": "^0.4.4",
177
+ "@types/mocha": "^10.0.10",
142
178
  "@types/node": "^24.3.0",
143
179
  "browser-sync": "^2.29.3",
144
180
  "chai": "^4.3.10",
@@ -1,59 +0,0 @@
1
- /**
2
- * Anime.js - easings - CJS
3
- * @version v4.2.0
4
- * @license MIT
5
- * @copyright 2025 - Julian Garnier
6
- */
7
-
8
- 'use strict';
9
-
10
- var helpers = require('../core/helpers.cjs');
11
- var none = require('./none.cjs');
12
-
13
- /**
14
- * @import {
15
- * EasingFunction,
16
- * PowerEasing,
17
- * EasingFunctionWithParams,
18
- * } from '../types/index.js'
19
- */
20
-
21
- /** @type {PowerEasing} */
22
- const easeInPower = (p = 1.68) => t => helpers.pow(t, +p);
23
-
24
- /**
25
- * @callback EaseType
26
- * @param {EasingFunction} Ease
27
- * @return {EasingFunction}
28
- */
29
-
30
- /** @type {Record<String, EaseType>} */
31
- const easeTypes = {
32
- in: easeIn => t => easeIn(t),
33
- out: easeIn => t => 1 - easeIn(1 - t),
34
- inOut: easeIn => t => t < .5 ? easeIn(t * 2) / 2 : 1 - easeIn(t * -2 + 2) / 2,
35
- outIn: easeIn => t => t < .5 ? (1 - easeIn(1 - t * 2)) / 2 : (easeIn(t * 2 - 1) + 1) / 2,
36
- };
37
-
38
- /**
39
- * @param {String} string
40
- * @param {Record<String, EasingFunctionWithParams|EasingFunction>} easesFunctions
41
- * @param {Object} easesLookups
42
- * @return {EasingFunction}
43
- */
44
- const parseEaseString = (string, easesFunctions, easesLookups) => {
45
- if (easesLookups[string]) return easesLookups[string];
46
- if (string.indexOf('(') <= -1) {
47
- const hasParams = easeTypes[string] || string.includes('Back') || string.includes('Elastic');
48
- const parsedFn = /** @type {EasingFunction} */(hasParams ? /** @type {EasingFunctionWithParams} */(easesFunctions[string])() : easesFunctions[string]);
49
- return parsedFn ? easesLookups[string] = parsedFn : none.none;
50
- } else {
51
- const split = string.slice(0, -1).split('(');
52
- const parsedFn = /** @type {EasingFunctionWithParams} */(easesFunctions[split[0]]);
53
- return parsedFn ? easesLookups[string] = parsedFn(...split[1].split(',')) : none.none;
54
- }
55
- };
56
-
57
- exports.easeInPower = easeInPower;
58
- exports.easeTypes = easeTypes;
59
- exports.parseEaseString = parseEaseString;
@@ -1,21 +0,0 @@
1
- /**
2
- * @import {
3
- * EasingFunction,
4
- * PowerEasing,
5
- * EasingFunctionWithParams,
6
- * } from '../types/index.js'
7
- */
8
- /** @type {PowerEasing} */
9
- export const easeInPower: PowerEasing;
10
- /**
11
- * @callback EaseType
12
- * @param {EasingFunction} Ease
13
- * @return {EasingFunction}
14
- */
15
- /** @type {Record<String, EaseType>} */
16
- export const easeTypes: Record<string, EaseType>;
17
- export function parseEaseString(string: string, easesFunctions: Record<string, EasingFunctionWithParams | EasingFunction>, easesLookups: any): EasingFunction;
18
- export type EaseType = (Ease: EasingFunction) => EasingFunction;
19
- import type { PowerEasing } from '../types/index.js';
20
- import type { EasingFunctionWithParams } from '../types/index.js';
21
- import type { EasingFunction } from '../types/index.js';
@@ -1,55 +0,0 @@
1
- /**
2
- * Anime.js - easings - ESM
3
- * @version v4.2.0
4
- * @license MIT
5
- * @copyright 2025 - Julian Garnier
6
- */
7
-
8
- import { pow } from '../core/helpers.js';
9
- import { none } from './none.js';
10
-
11
- /**
12
- * @import {
13
- * EasingFunction,
14
- * PowerEasing,
15
- * EasingFunctionWithParams,
16
- * } from '../types/index.js'
17
- */
18
-
19
- /** @type {PowerEasing} */
20
- const easeInPower = (p = 1.68) => t => pow(t, +p);
21
-
22
- /**
23
- * @callback EaseType
24
- * @param {EasingFunction} Ease
25
- * @return {EasingFunction}
26
- */
27
-
28
- /** @type {Record<String, EaseType>} */
29
- const easeTypes = {
30
- in: easeIn => t => easeIn(t),
31
- out: easeIn => t => 1 - easeIn(1 - t),
32
- inOut: easeIn => t => t < .5 ? easeIn(t * 2) / 2 : 1 - easeIn(t * -2 + 2) / 2,
33
- outIn: easeIn => t => t < .5 ? (1 - easeIn(1 - t * 2)) / 2 : (easeIn(t * 2 - 1) + 1) / 2,
34
- };
35
-
36
- /**
37
- * @param {String} string
38
- * @param {Record<String, EasingFunctionWithParams|EasingFunction>} easesFunctions
39
- * @param {Object} easesLookups
40
- * @return {EasingFunction}
41
- */
42
- const parseEaseString = (string, easesFunctions, easesLookups) => {
43
- if (easesLookups[string]) return easesLookups[string];
44
- if (string.indexOf('(') <= -1) {
45
- const hasParams = easeTypes[string] || string.includes('Back') || string.includes('Elastic');
46
- const parsedFn = /** @type {EasingFunction} */(hasParams ? /** @type {EasingFunctionWithParams} */(easesFunctions[string])() : easesFunctions[string]);
47
- return parsedFn ? easesLookups[string] = parsedFn : none;
48
- } else {
49
- const split = string.slice(0, -1).split('(');
50
- const parsedFn = /** @type {EasingFunctionWithParams} */(easesFunctions[split[0]]);
51
- return parsedFn ? easesLookups[string] = parsedFn(...split[1].split(',')) : none;
52
- }
53
- };
54
-
55
- export { easeInPower, easeTypes, parseEaseString };