animejs 4.2.0-beta.0 → 4.2.1

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 (147) hide show
  1. package/README.md +6 -1
  2. package/dist/bundles/anime.esm.js +543 -304
  3. package/dist/bundles/anime.esm.min.js +2 -2
  4. package/dist/bundles/anime.umd.js +544 -305
  5. package/dist/bundles/anime.umd.min.js +2 -2
  6. package/dist/modules/animatable/animatable.cjs +4 -4
  7. package/dist/modules/animatable/animatable.js +3 -3
  8. package/dist/modules/animatable/index.cjs +1 -1
  9. package/dist/modules/animatable/index.js +1 -1
  10. package/dist/modules/animation/additive.cjs +1 -1
  11. package/dist/modules/animation/additive.js +1 -1
  12. package/dist/modules/animation/animation.cjs +28 -17
  13. package/dist/modules/animation/animation.d.ts +8 -5
  14. package/dist/modules/animation/animation.js +27 -16
  15. package/dist/modules/animation/composition.cjs +1 -1
  16. package/dist/modules/animation/composition.js +1 -1
  17. package/dist/modules/animation/index.cjs +1 -1
  18. package/dist/modules/animation/index.js +1 -1
  19. package/dist/modules/core/clock.cjs +1 -1
  20. package/dist/modules/core/clock.js +1 -1
  21. package/dist/modules/core/colors.cjs +1 -1
  22. package/dist/modules/core/colors.js +1 -1
  23. package/dist/modules/core/consts.cjs +7 -2
  24. package/dist/modules/core/consts.d.ts +2 -0
  25. package/dist/modules/core/consts.js +6 -3
  26. package/dist/modules/core/globals.cjs +3 -2
  27. package/dist/modules/core/globals.js +3 -2
  28. package/dist/modules/core/helpers.cjs +1 -1
  29. package/dist/modules/core/helpers.js +1 -1
  30. package/dist/modules/core/render.cjs +4 -2
  31. package/dist/modules/core/render.js +4 -2
  32. package/dist/modules/core/styles.cjs +8 -8
  33. package/dist/modules/core/styles.js +10 -10
  34. package/dist/modules/core/targets.cjs +1 -1
  35. package/dist/modules/core/targets.js +1 -1
  36. package/dist/modules/core/transforms.cjs +1 -1
  37. package/dist/modules/core/transforms.js +1 -1
  38. package/dist/modules/core/units.cjs +1 -1
  39. package/dist/modules/core/units.js +1 -1
  40. package/dist/modules/core/values.cjs +17 -6
  41. package/dist/modules/core/values.js +19 -8
  42. package/dist/modules/draggable/draggable.cjs +32 -19
  43. package/dist/modules/draggable/draggable.d.ts +3 -1
  44. package/dist/modules/draggable/draggable.js +28 -15
  45. package/dist/modules/draggable/index.cjs +1 -1
  46. package/dist/modules/draggable/index.js +1 -1
  47. package/dist/modules/easings/{cubic-bezier.cjs → cubic-bezier/index.cjs} +4 -4
  48. package/dist/modules/easings/{cubic-bezier.d.ts → cubic-bezier/index.d.ts} +1 -1
  49. package/dist/modules/easings/{cubic-bezier.js → cubic-bezier/index.js} +4 -4
  50. package/dist/modules/easings/eases/index.cjs +14 -0
  51. package/dist/modules/easings/eases/index.d.ts +1 -0
  52. package/dist/modules/easings/eases/index.js +8 -0
  53. package/dist/modules/easings/{eases.cjs → eases/parser.cjs} +69 -27
  54. package/dist/modules/easings/{eases.d.ts → eases/parser.d.ts} +31 -17
  55. package/dist/modules/easings/{eases.js → eases/parser.js} +60 -21
  56. package/dist/modules/easings/index.cjs +15 -13
  57. package/dist/modules/easings/index.d.ts +6 -6
  58. package/dist/modules/easings/index.js +7 -7
  59. package/dist/modules/easings/{irregular.cjs → irregular/index.cjs} +5 -5
  60. package/dist/modules/easings/{irregular.d.ts → irregular/index.d.ts} +1 -1
  61. package/dist/modules/easings/{irregular.js → irregular/index.js} +4 -4
  62. package/dist/modules/easings/{linear.cjs → linear/index.cjs} +4 -4
  63. package/dist/modules/easings/{linear.d.ts → linear/index.d.ts} +1 -1
  64. package/dist/modules/easings/{linear.js → linear/index.js} +4 -4
  65. package/dist/modules/easings/none.cjs +1 -1
  66. package/dist/modules/easings/none.js +1 -1
  67. package/dist/modules/easings/spring/index.cjs +255 -0
  68. package/dist/modules/{spring/spring.d.ts → easings/spring/index.d.ts} +21 -5
  69. package/dist/modules/easings/spring/index.js +251 -0
  70. package/dist/modules/easings/{steps.cjs → steps/index.cjs} +3 -3
  71. package/dist/modules/easings/{steps.d.ts → steps/index.d.ts} +1 -1
  72. package/dist/modules/easings/{steps.js → steps/index.js} +3 -3
  73. package/dist/modules/engine/engine.cjs +1 -1
  74. package/dist/modules/engine/engine.js +1 -1
  75. package/dist/modules/engine/index.cjs +1 -1
  76. package/dist/modules/engine/index.js +1 -1
  77. package/dist/modules/events/index.cjs +1 -1
  78. package/dist/modules/events/index.js +1 -1
  79. package/dist/modules/events/scroll.cjs +17 -9
  80. package/dist/modules/events/scroll.d.ts +4 -0
  81. package/dist/modules/events/scroll.js +16 -8
  82. package/dist/modules/index.cjs +15 -16
  83. package/dist/modules/index.d.ts +0 -1
  84. package/dist/modules/index.js +7 -8
  85. package/dist/modules/scope/index.cjs +1 -1
  86. package/dist/modules/scope/index.js +1 -1
  87. package/dist/modules/scope/scope.cjs +1 -1
  88. package/dist/modules/scope/scope.js +1 -1
  89. package/dist/modules/svg/drawable.cjs +1 -1
  90. package/dist/modules/svg/drawable.js +1 -1
  91. package/dist/modules/svg/helpers.cjs +1 -1
  92. package/dist/modules/svg/helpers.js +1 -1
  93. package/dist/modules/svg/index.cjs +1 -1
  94. package/dist/modules/svg/index.js +1 -1
  95. package/dist/modules/svg/morphto.cjs +12 -2
  96. package/dist/modules/svg/morphto.js +12 -2
  97. package/dist/modules/svg/motionpath.cjs +18 -11
  98. package/dist/modules/svg/motionpath.d.ts +1 -1
  99. package/dist/modules/svg/motionpath.js +18 -11
  100. package/dist/modules/text/index.cjs +1 -1
  101. package/dist/modules/text/index.js +1 -1
  102. package/dist/modules/text/split.cjs +1 -1
  103. package/dist/modules/text/split.js +1 -1
  104. package/dist/modules/timeline/index.cjs +1 -1
  105. package/dist/modules/timeline/index.js +1 -1
  106. package/dist/modules/timeline/position.cjs +1 -1
  107. package/dist/modules/timeline/position.js +1 -1
  108. package/dist/modules/timeline/timeline.cjs +11 -7
  109. package/dist/modules/timeline/timeline.d.ts +8 -3
  110. package/dist/modules/timeline/timeline.js +10 -6
  111. package/dist/modules/timer/index.cjs +1 -1
  112. package/dist/modules/timer/index.js +1 -1
  113. package/dist/modules/timer/timer.cjs +17 -14
  114. package/dist/modules/timer/timer.d.ts +12 -7
  115. package/dist/modules/timer/timer.js +17 -14
  116. package/dist/modules/types/index.d.ts +35 -14
  117. package/dist/modules/utils/chainable.cjs +1 -1
  118. package/dist/modules/utils/chainable.js +1 -1
  119. package/dist/modules/utils/index.cjs +1 -1
  120. package/dist/modules/utils/index.js +1 -1
  121. package/dist/modules/utils/number.cjs +1 -1
  122. package/dist/modules/utils/number.js +1 -1
  123. package/dist/modules/utils/random.cjs +1 -1
  124. package/dist/modules/utils/random.js +1 -1
  125. package/dist/modules/utils/stagger.cjs +4 -4
  126. package/dist/modules/utils/stagger.js +3 -3
  127. package/dist/modules/utils/target.cjs +1 -1
  128. package/dist/modules/utils/target.js +1 -1
  129. package/dist/modules/utils/time.cjs +1 -1
  130. package/dist/modules/utils/time.js +1 -1
  131. package/dist/modules/waapi/composition.cjs +11 -5
  132. package/dist/modules/waapi/composition.d.ts +1 -1
  133. package/dist/modules/waapi/composition.js +11 -5
  134. package/dist/modules/waapi/index.cjs +1 -1
  135. package/dist/modules/waapi/index.js +1 -1
  136. package/dist/modules/waapi/waapi.cjs +58 -36
  137. package/dist/modules/waapi/waapi.d.ts +12 -7
  138. package/dist/modules/waapi/waapi.js +59 -37
  139. package/package.json +48 -13
  140. package/dist/modules/easings/parser.cjs +0 -59
  141. package/dist/modules/easings/parser.d.ts +0 -21
  142. package/dist/modules/easings/parser.js +0 -55
  143. package/dist/modules/spring/index.cjs +0 -15
  144. package/dist/modules/spring/index.d.ts +0 -1
  145. package/dist/modules/spring/index.js +0 -8
  146. package/dist/modules/spring/spring.cjs +0 -133
  147. package/dist/modules/spring/spring.js +0 -130
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -9,7 +9,7 @@
9
9
 
10
10
  var consts = require('../core/consts.cjs');
11
11
  var helpers = require('../core/helpers.cjs');
12
- var eases = require('../easings/eases.cjs');
12
+ var parser = require('../easings/eases/parser.cjs');
13
13
  var position = require('../timeline/position.cjs');
14
14
  var values = require('../core/values.cjs');
15
15
  var targets = require('../core/targets.cjs');
@@ -25,7 +25,7 @@ var random = require('./random.cjs');
25
25
  /**
26
26
  * @import {
27
27
  * Spring,
28
- * } from '../spring/spring.js'
28
+ * } from '../easings/spring/index.js'
29
29
  */
30
30
 
31
31
  /**
@@ -65,7 +65,7 @@ const stagger = (val, params = {}) => {
65
65
  const ease = params.ease;
66
66
  const hasEasing = !helpers.isUnd(ease);
67
67
  const hasSpring = hasEasing && !helpers.isUnd(/** @type {Spring} */(ease).ease);
68
- const staggerEase = hasSpring ? /** @type {Spring} */(ease).ease : hasEasing ? eases.parseEase(ease) : null;
68
+ const staggerEase = hasSpring ? /** @type {Spring} */(ease).ease : hasEasing ? parser.parseEase(ease) : null;
69
69
  const grid = params.grid;
70
70
  const axis = params.axis;
71
71
  const customTotal = params.total;
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
7
7
 
8
8
  import { unitsExecRgx, emptyString } from '../core/consts.js';
9
9
  import { isUnd, parseNumber, isFnc, abs, floor, sqrt, round, isArr, isNum, isStr, max } from '../core/helpers.js';
10
- import { parseEase } from '../easings/eases.js';
10
+ import { parseEase } from '../easings/eases/parser.js';
11
11
  import { parseTimelinePosition } from '../timeline/position.js';
12
12
  import { getOriginalAnimatableValue } from '../core/values.js';
13
13
  import { registerTargets } from '../core/targets.js';
@@ -23,7 +23,7 @@ import { shuffle } from './random.js';
23
23
  /**
24
24
  * @import {
25
25
  * Spring,
26
- * } from '../spring/spring.js'
26
+ * } from '../easings/spring/index.js'
27
27
  */
28
28
 
29
29
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - CJS
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -30,16 +30,18 @@ const WAAPIAnimationsLookups = {
30
30
  * @param {DOMTarget} $el
31
31
  * @param {String} [property]
32
32
  * @param {WAAPIAnimation} [parent]
33
+ * @return {globalThis.Animation}
33
34
  */
34
35
  const removeWAAPIAnimation = ($el, property, parent) => {
35
36
  let nextLookup = WAAPIAnimationsLookups._head;
37
+ let anim;
36
38
  while (nextLookup) {
37
39
  const next = nextLookup._next;
38
40
  const matchTarget = nextLookup.$el === $el;
39
41
  const matchProperty = !property || nextLookup.property === property;
40
42
  const matchParent = !parent || nextLookup.parent === parent;
41
43
  if (matchTarget && matchProperty && matchParent) {
42
- const anim = nextLookup.animation;
44
+ anim = nextLookup.animation;
43
45
  try { anim.commitStyles(); } catch {} anim.cancel();
44
46
  helpers.removeChild(WAAPIAnimationsLookups, nextLookup);
45
47
  const lookupParent = nextLookup.parent;
@@ -47,8 +49,8 @@ const removeWAAPIAnimation = ($el, property, parent) => {
47
49
  lookupParent._completed++;
48
50
  if (lookupParent.animations.length === lookupParent._completed) {
49
51
  lookupParent.completed = true;
52
+ lookupParent.paused = true;
50
53
  if (!lookupParent.muteCallbacks) {
51
- lookupParent.paused = true;
52
54
  lookupParent.onComplete(lookupParent);
53
55
  lookupParent._resolve(lookupParent);
54
56
  }
@@ -57,6 +59,7 @@ const removeWAAPIAnimation = ($el, property, parent) => {
57
59
  }
58
60
  nextLookup = next;
59
61
  }
62
+ return anim;
60
63
  };
61
64
 
62
65
  /**
@@ -65,7 +68,7 @@ const removeWAAPIAnimation = ($el, property, parent) => {
65
68
  * @param {String} property
66
69
  * @param {PropertyIndexedKeyframes} keyframes
67
70
  * @param {KeyframeAnimationOptions} params
68
- * @retun {Animation}
71
+ * @retun {globalThis.Animation}
69
72
  */
70
73
  const addWAAPIAnimation = (parent, $el, property, keyframes, params) => {
71
74
  const animation = $el.animate(keyframes, params);
@@ -80,8 +83,11 @@ const addWAAPIAnimation = (parent, $el, property, keyframes, params) => {
80
83
  removeWAAPIAnimation($el, property);
81
84
  helpers.addChild(WAAPIAnimationsLookups, { parent, animation, $el, property, _next: null, _prev: null });
82
85
  const handleRemove = () => { removeWAAPIAnimation($el, property, parent); };
86
+ animation.oncancel = handleRemove;
83
87
  animation.onremove = handleRemove;
84
- animation.onfinish = handleRemove;
88
+ if (!parent.persist) {
89
+ animation.onfinish = handleRemove;
90
+ }
85
91
  return animation;
86
92
  };
87
93
 
@@ -1,4 +1,4 @@
1
- export function removeWAAPIAnimation($el: DOMTarget, property?: string, parent?: WAAPIAnimation): void;
1
+ export function removeWAAPIAnimation($el: DOMTarget, property?: string, parent?: WAAPIAnimation): globalThis.Animation;
2
2
  export function addWAAPIAnimation(parent: WAAPIAnimation, $el: DOMTarget, property: string, keyframes: PropertyIndexedKeyframes, params: KeyframeAnimationOptions): Animation;
3
3
  import type { DOMTarget } from '../types/index.js';
4
4
  import type { WAAPIAnimation } from '../waapi/waapi.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - ESM
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -28,16 +28,18 @@ const WAAPIAnimationsLookups = {
28
28
  * @param {DOMTarget} $el
29
29
  * @param {String} [property]
30
30
  * @param {WAAPIAnimation} [parent]
31
+ * @return {globalThis.Animation}
31
32
  */
32
33
  const removeWAAPIAnimation = ($el, property, parent) => {
33
34
  let nextLookup = WAAPIAnimationsLookups._head;
35
+ let anim;
34
36
  while (nextLookup) {
35
37
  const next = nextLookup._next;
36
38
  const matchTarget = nextLookup.$el === $el;
37
39
  const matchProperty = !property || nextLookup.property === property;
38
40
  const matchParent = !parent || nextLookup.parent === parent;
39
41
  if (matchTarget && matchProperty && matchParent) {
40
- const anim = nextLookup.animation;
42
+ anim = nextLookup.animation;
41
43
  try { anim.commitStyles(); } catch {} anim.cancel();
42
44
  removeChild(WAAPIAnimationsLookups, nextLookup);
43
45
  const lookupParent = nextLookup.parent;
@@ -45,8 +47,8 @@ const removeWAAPIAnimation = ($el, property, parent) => {
45
47
  lookupParent._completed++;
46
48
  if (lookupParent.animations.length === lookupParent._completed) {
47
49
  lookupParent.completed = true;
50
+ lookupParent.paused = true;
48
51
  if (!lookupParent.muteCallbacks) {
49
- lookupParent.paused = true;
50
52
  lookupParent.onComplete(lookupParent);
51
53
  lookupParent._resolve(lookupParent);
52
54
  }
@@ -55,6 +57,7 @@ const removeWAAPIAnimation = ($el, property, parent) => {
55
57
  }
56
58
  nextLookup = next;
57
59
  }
60
+ return anim;
58
61
  };
59
62
 
60
63
  /**
@@ -63,7 +66,7 @@ const removeWAAPIAnimation = ($el, property, parent) => {
63
66
  * @param {String} property
64
67
  * @param {PropertyIndexedKeyframes} keyframes
65
68
  * @param {KeyframeAnimationOptions} params
66
- * @retun {Animation}
69
+ * @retun {globalThis.Animation}
67
70
  */
68
71
  const addWAAPIAnimation = (parent, $el, property, keyframes, params) => {
69
72
  const animation = $el.animate(keyframes, params);
@@ -78,8 +81,11 @@ const addWAAPIAnimation = (parent, $el, property, keyframes, params) => {
78
81
  removeWAAPIAnimation($el, property);
79
82
  addChild(WAAPIAnimationsLookups, { parent, animation, $el, property, _next: null, _prev: null });
80
83
  const handleRemove = () => { removeWAAPIAnimation($el, property, parent); };
84
+ animation.oncancel = handleRemove;
81
85
  animation.onremove = handleRemove;
82
- animation.onfinish = handleRemove;
86
+ if (!parent.persist) {
87
+ animation.onfinish = handleRemove;
88
+ }
83
89
  return animation;
84
90
  };
85
91
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - CJS
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - ESM
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - CJS
3
- * @version v4.2.0
3
+ * @version v4.2.1
4
4
  * @license MIT
5
5
  * @copyright 2025 - Julian Garnier
6
6
  */
@@ -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
  /**
@@ -27,7 +27,6 @@ var composition = require('./composition.cjs');
27
27
  * WAAPIAnimationParams,
28
28
  * WAAPITweenOptions,
29
29
  * WAAPIKeyframeValue,
30
- * WAAPICallback,
31
30
  * WAAPITweenValue
32
31
  * } from '../types/index.js'
33
32
  */
@@ -35,7 +34,7 @@ var composition = require('./composition.cjs');
35
34
  /**
36
35
  * @import {
37
36
  * Spring,
38
- * } from '../spring/spring.js'
37
+ * } from '../easings/spring/index.js'
39
38
  */
40
39
 
41
40
  /**
@@ -52,21 +51,11 @@ var composition = require('./composition.cjs');
52
51
  */
53
52
  const easingToLinear = (fn, samples = 100) => {
54
53
  const points = [];
55
- for (let i = 0; i <= samples; i++) points.push(fn(i / samples));
54
+ for (let i = 0; i <= samples; i++) points.push(helpers.round(fn(i / samples), 4));
56
55
  return `linear(${points.join(', ')})`;
57
56
  };
58
57
 
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
- })();
58
+ const WAAPIEasesLookups = {};
70
59
 
71
60
  /**
72
61
  * @param {EasingParam} ease
@@ -87,9 +76,10 @@ const parseWAAPIEasing = (ease) => {
87
76
  } else if (helpers.stringStartsWith(ease, 'cubicB')) {
88
77
  parsedEase = helpers.toLowerCase(ease);
89
78
  } else {
90
- const parsed = parser.parseEaseString(ease, WAAPIeases, WAAPIEasesLookups);
79
+ const parsed = parser.parseEaseString(ease);
91
80
  if (helpers.isFnc(parsed)) parsedEase = parsed === none.none ? 'linear' : easingToLinear(parsed);
92
81
  }
82
+ // Only cache string based easing name, otherwise function arguments get lost
93
83
  WAAPIEasesLookups[ease] = parsedEase;
94
84
  } else if (helpers.isFnc(ease)) {
95
85
  const easing = easingToLinear(ease);
@@ -130,7 +120,8 @@ let transformsPropertiesRegistered = null;
130
120
  * @return {String}
131
121
  */
132
122
  const normalizeTweenValue = (propName, value, $el, i, targetsLength) => {
133
- let v = values.getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
123
+ // Do not try to compute strings with getFunctionValue otherwise it will convert CSS variables
124
+ let v = helpers.isStr(value) ? value : values.getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
134
125
  if (!helpers.isNum(v)) return v;
135
126
  if (commonDefaultPXProperties.includes(propName) || helpers.stringStartsWith(propName, 'translate')) return `${v}px`;
136
127
  if (helpers.stringStartsWith(propName, 'rotate') || helpers.stringStartsWith(propName, 'skew')) return `${v}deg`;
@@ -210,7 +201,7 @@ class WAAPIAnimation {
210
201
  /** @type {PlaybackDirection} */
211
202
  const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal';
212
203
  /** @type {FillMode} */
213
- const fill = 'forwards';
204
+ const fill = 'both'; // We use 'both' here because the animation can be reversed during playback
214
205
  /** @type {String} */
215
206
  const easing = parseWAAPIEasing(ease);
216
207
  const timeScale = (globals.globals.timeScale === 1 ? 1 : consts.K);
@@ -222,7 +213,7 @@ class WAAPIAnimation {
222
213
  /** @type {globalThis.Animation}] */
223
214
  this.controlAnimation = null;
224
215
  /** @type {Callback<this>} */
225
- this.onComplete = params.onComplete || consts.noop;
216
+ this.onComplete = params.onComplete || /** @type {Callback<WAAPIAnimation>} */(/** @type {unknown} */(globals.globals.defaults.onComplete));
226
217
  /** @type {Number} */
227
218
  this.duration = 0;
228
219
  /** @type {Boolean} */
@@ -233,6 +224,8 @@ class WAAPIAnimation {
233
224
  this.paused = !autoplay || scroll !== false;
234
225
  /** @type {Boolean} */
235
226
  this.reversed = reversed;
227
+ /** @type {Boolean} */
228
+ this.persist = values.setValue(params.persist, globals.globals.defaults.persist);
236
229
  /** @type {Boolean|ScrollObserver} */
237
230
  this.autoplay = autoplay;
238
231
  /** @type {Number} */
@@ -241,17 +234,18 @@ class WAAPIAnimation {
241
234
  this._resolve = consts.noop; // Used by .then()
242
235
  /** @type {Number} */
243
236
  this._completed = 0;
244
- /** @type {Array<Object>}] */
245
- this._inlineStyles = parsedTargets.map($el => $el.getAttribute('style'));
237
+ /** @type {Array.<Object>} */
238
+ this._inlineStyles = [];
246
239
 
247
240
  parsedTargets.forEach(($el, i) => {
248
241
 
249
242
  const cachedTransforms = $el[consts.transformsSymbol];
250
-
251
243
  const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t));
244
+ const elStyle = $el.style;
245
+ const inlineStyles = this._inlineStyles[i] = {};
252
246
 
253
247
  /** @type {Number} */
254
- const duration = (spring ? /** @type {Spring} */(spring).duration : values.getFunctionValue(values.setValue(params.duration, globals.globals.defaults.duration), $el, i, targetsLength)) * timeScale;
248
+ const duration = (spring ? /** @type {Spring} */(spring).settlingDuration : values.getFunctionValue(values.setValue(params.duration, globals.globals.defaults.duration), $el, i, targetsLength)) * timeScale;
255
249
  /** @type {Number} */
256
250
  const delay = values.getFunctionValue(values.setValue(params.delay, globals.globals.defaults.delay), $el, i, targetsLength) * timeScale;
257
251
  /** @type {CompositeOperation} */
@@ -265,6 +259,12 @@ class WAAPIAnimation {
265
259
  const tweenParams = { iterations, direction, fill, easing, duration, delay, composite };
266
260
  const propertyValue = params[name];
267
261
  const individualTransformProperty = hasIndividualTransforms ? consts.validTransforms.includes(name) ? name : consts.shortTransforms.get(name) : false;
262
+
263
+ const styleName = individualTransformProperty ? 'transform' : name;
264
+ if (!inlineStyles[styleName]) {
265
+ inlineStyles[styleName] = elStyle[styleName];
266
+ }
267
+
268
268
  let parsedPropertyValue;
269
269
  if (helpers.isObj(propertyValue)) {
270
270
  const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue);
@@ -273,7 +273,7 @@ class WAAPIAnimation {
273
273
  const to = /** @type {WAAPITweenOptions} */(tweenOptions).to;
274
274
  const from = /** @type {WAAPITweenOptions} */(tweenOptions).from;
275
275
  /** @type {Number} */
276
- tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).duration : values.getFunctionValue(values.setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
276
+ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).settlingDuration : values.getFunctionValue(values.setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
277
277
  /** @type {Number} */
278
278
  tweenParams.delay = values.getFunctionValue(values.setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale;
279
279
  /** @type {CompositeOperation} */
@@ -290,10 +290,10 @@ class WAAPIAnimation {
290
290
  composition.addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
291
291
  if (!helpers.isUnd(from)) {
292
292
  if (!individualTransformProperty) {
293
- $el.style[name] = keyframes[name][0];
293
+ elStyle[name] = keyframes[name][0];
294
294
  } else {
295
295
  const key = `--${individualTransformProperty}`;
296
- $el.style.setProperty(key, keyframes[key][0]);
296
+ elStyle.setProperty(key, keyframes[key][0]);
297
297
  }
298
298
  }
299
299
  } else {
@@ -314,7 +314,7 @@ class WAAPIAnimation {
314
314
  for (let t in cachedTransforms) {
315
315
  transforms += `${consts.transformsFragmentStrings[t]}var(--${t})) `;
316
316
  }
317
- $el.style.transform = transforms;
317
+ elStyle.transform = transforms;
318
318
  }
319
319
  });
320
320
 
@@ -359,7 +359,8 @@ class WAAPIAnimation {
359
359
  // Make sure the animation playState is not 'paused' in order to properly trigger an onfinish callback.
360
360
  // 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
361
  // https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event
362
- if (t >= this.duration) anim.play();
362
+ // This is not needed for persisting animations since they never finish.
363
+ if (!this.persist && t >= this.duration) anim.play();
363
364
  anim.currentTime = t;
364
365
  });
365
366
  }
@@ -429,25 +430,46 @@ class WAAPIAnimation {
429
430
  }
430
431
 
431
432
  cancel() {
432
- this.forEach('cancel');
433
- return this.pause();
433
+ this.muteCallbacks = true; // This prevents triggering the onComplete callback and resolving the Promise
434
+ return this.commitStyles().forEach('cancel');
434
435
  }
435
436
 
436
437
  revert() {
437
- this.cancel();
438
- this.targets.forEach(($el, i) => $el.setAttribute('style', this._inlineStyles[i]) );
438
+ // NOTE: We need a better way to revert the transforms, since right now the entire transform property value is reverted,
439
+ // This means if you have multiple animations animating different transforms on the same target,
440
+ // reverting one of them will also override the transform property of the other animations.
441
+ // A better approach would be to store the original custom property values is they exist instead of the entire transform value,
442
+ // and update the CSS variables with the orignal value
443
+ this.cancel().targets.forEach(($el, i) => {
444
+ const targetStyle = $el.style;
445
+ const targetInlineStyles = this._inlineStyles[i];
446
+ for (let name in targetInlineStyles) {
447
+ const originalInlinedValue = targetInlineStyles[name];
448
+ if (helpers.isUnd(originalInlinedValue) || originalInlinedValue === consts.emptyString) {
449
+ targetStyle.removeProperty(helpers.toLowerCase(name));
450
+ } else {
451
+ targetStyle[name] = originalInlinedValue;
452
+ }
453
+ }
454
+ // Remove style attribute if empty
455
+ if ($el.getAttribute('style') === consts.emptyString) $el.removeAttribute('style');
456
+ });
439
457
  return this;
440
458
  }
441
459
 
442
460
  /**
443
- * @param {WAAPICallback} [callback]
444
- * @return {Promise}
461
+ * @typedef {this & {then: null}} ResolvedWAAPIAnimation
462
+ */
463
+
464
+ /**
465
+ * @param {Callback<ResolvedWAAPIAnimation>} [callback]
466
+ * @return Promise<this>
445
467
  */
446
468
  then(callback = consts.noop) {
447
469
  const then = this.then;
448
470
  const onResolve = () => {
449
471
  this.then = null;
450
- callback(this);
472
+ callback(/** @type {ResolvedWAAPIAnimation} */(this));
451
473
  this.then = then;
452
474
  this._resolve = consts.noop;
453
475
  };
@@ -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
@@ -63,10 +65,15 @@ export class WAAPIAnimation {
63
65
  cancel(): this;
64
66
  revert(): this;
65
67
  /**
66
- * @param {WAAPICallback} [callback]
67
- * @return {Promise}
68
+ * @typedef {this & {then: null}} ResolvedWAAPIAnimation
69
+ */
70
+ /**
71
+ * @param {Callback<ResolvedWAAPIAnimation>} [callback]
72
+ * @return Promise<this>
68
73
  */
69
- then(callback?: WAAPICallback): Promise<any>;
74
+ then(callback?: Callback<this & {
75
+ then: null;
76
+ }>): Promise<any>;
70
77
  }
71
78
  export namespace waapi {
72
79
  export function animate(targets: DOMTargetsParam, params: WAAPIAnimationParams): WAAPIAnimation;
@@ -75,7 +82,6 @@ export namespace waapi {
75
82
  import type { DOMTargetsArray } from '../types/index.js';
76
83
  import type { Callback } from '../types/index.js';
77
84
  import type { ScrollObserver } from '../events/scroll.js';
78
- import type { WAAPICallback } from '../types/index.js';
79
85
  import type { DOMTargetsParam } from '../types/index.js';
80
86
  import type { WAAPIAnimationParams } from '../types/index.js';
81
87
  /**
@@ -89,14 +95,13 @@ import type { WAAPIAnimationParams } from '../types/index.js';
89
95
  * WAAPIAnimationParams,
90
96
  * WAAPITweenOptions,
91
97
  * WAAPIKeyframeValue,
92
- * WAAPICallback,
93
98
  * WAAPITweenValue
94
99
  * } from '../types/index.js'
95
100
  */
96
101
  /**
97
102
  * @import {
98
103
  * Spring,
99
- * } from '../spring/spring.js'
104
+ * } from '../easings/spring/index.js'
100
105
  */
101
106
  /**
102
107
  * @import {