animejs 4.1.4 → 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 (188) hide show
  1. package/README.md +17 -8
  2. package/{lib → dist/bundles}/anime.esm.js +6476 -6106
  3. package/dist/bundles/anime.esm.min.js +7 -0
  4. package/dist/bundles/anime.umd.js +8809 -0
  5. package/dist/bundles/anime.umd.min.js +7 -0
  6. package/dist/modules/animatable/animatable.cjs +150 -0
  7. package/dist/modules/animatable/animatable.d.ts +28 -0
  8. package/dist/modules/animatable/animatable.js +147 -0
  9. package/dist/modules/animatable/index.cjs +15 -0
  10. package/dist/modules/animatable/index.d.ts +1 -0
  11. package/dist/modules/animatable/index.js +8 -0
  12. package/dist/modules/animation/additive.cjs +82 -0
  13. package/dist/modules/animation/additive.d.ts +15 -0
  14. package/dist/modules/animation/additive.js +79 -0
  15. package/dist/modules/animation/animation.cjs +667 -0
  16. package/dist/modules/animation/animation.d.ts +45 -0
  17. package/dist/modules/animation/animation.js +664 -0
  18. package/dist/modules/animation/composition.cjs +383 -0
  19. package/dist/modules/animation/composition.d.ts +10 -0
  20. package/dist/modules/animation/composition.js +377 -0
  21. package/dist/modules/animation/index.cjs +15 -0
  22. package/dist/modules/animation/index.d.ts +1 -0
  23. package/dist/modules/animation/index.js +8 -0
  24. package/dist/modules/core/clock.cjs +110 -0
  25. package/dist/modules/core/clock.d.ts +51 -0
  26. package/dist/modules/core/clock.js +108 -0
  27. package/dist/modules/core/colors.cjs +102 -0
  28. package/dist/modules/core/colors.d.ts +2 -0
  29. package/dist/modules/core/colors.js +100 -0
  30. package/dist/modules/core/consts.cjs +159 -0
  31. package/dist/modules/core/consts.d.ts +61 -0
  32. package/dist/modules/core/consts.js +124 -0
  33. package/dist/modules/core/globals.cjs +78 -0
  34. package/dist/modules/core/globals.d.ts +29 -0
  35. package/dist/modules/core/globals.js +73 -0
  36. package/dist/modules/core/helpers.cjs +304 -0
  37. package/dist/modules/core/helpers.d.ts +43 -0
  38. package/dist/modules/core/helpers.js +261 -0
  39. package/dist/modules/core/render.cjs +391 -0
  40. package/dist/modules/core/render.d.ts +4 -0
  41. package/dist/modules/core/render.js +388 -0
  42. package/dist/modules/core/styles.cjs +116 -0
  43. package/dist/modules/core/styles.d.ts +5 -0
  44. package/dist/modules/core/styles.js +113 -0
  45. package/dist/modules/core/targets.cjs +136 -0
  46. package/dist/modules/core/targets.d.ts +118 -0
  47. package/dist/modules/core/targets.js +132 -0
  48. package/dist/modules/core/transforms.cjs +49 -0
  49. package/dist/modules/core/transforms.d.ts +2 -0
  50. package/dist/modules/core/transforms.js +47 -0
  51. package/dist/modules/core/units.cjs +67 -0
  52. package/dist/modules/core/units.d.ts +3 -0
  53. package/dist/modules/core/units.js +65 -0
  54. package/dist/modules/core/values.cjs +226 -0
  55. package/dist/modules/core/values.d.ts +14 -0
  56. package/dist/modules/core/values.js +216 -0
  57. package/dist/modules/draggable/draggable.cjs +1226 -0
  58. package/dist/modules/draggable/draggable.d.ts +272 -0
  59. package/dist/modules/draggable/draggable.js +1223 -0
  60. package/dist/modules/draggable/index.cjs +15 -0
  61. package/dist/modules/draggable/index.d.ts +1 -0
  62. package/dist/modules/draggable/index.js +8 -0
  63. package/dist/modules/easings/cubic-bezier/index.cjs +64 -0
  64. package/dist/modules/easings/cubic-bezier/index.d.ts +2 -0
  65. package/dist/modules/easings/cubic-bezier/index.js +62 -0
  66. package/dist/modules/easings/eases/index.cjs +14 -0
  67. package/dist/modules/easings/eases/index.d.ts +1 -0
  68. package/dist/modules/easings/eases/index.js +8 -0
  69. package/dist/modules/easings/eases/parser.cjs +191 -0
  70. package/dist/modules/easings/eases/parser.d.ts +125 -0
  71. package/dist/modules/easings/eases/parser.js +185 -0
  72. package/dist/modules/easings/index.cjs +26 -0
  73. package/dist/modules/easings/index.d.ts +6 -0
  74. package/dist/modules/easings/index.js +13 -0
  75. package/dist/modules/easings/irregular/index.cjs +41 -0
  76. package/dist/modules/easings/irregular/index.d.ts +2 -0
  77. package/dist/modules/easings/irregular/index.js +39 -0
  78. package/dist/modules/easings/linear/index.cjs +59 -0
  79. package/dist/modules/easings/linear/index.d.ts +2 -0
  80. package/dist/modules/easings/linear/index.js +57 -0
  81. package/dist/modules/easings/none.cjs +19 -0
  82. package/dist/modules/easings/none.d.ts +8 -0
  83. package/dist/modules/easings/none.js +17 -0
  84. package/dist/modules/easings/spring/index.cjs +255 -0
  85. package/dist/modules/easings/spring/index.d.ts +53 -0
  86. package/dist/modules/easings/spring/index.js +251 -0
  87. package/dist/modules/easings/steps/index.cjs +30 -0
  88. package/dist/modules/easings/steps/index.d.ts +2 -0
  89. package/dist/modules/easings/steps/index.js +28 -0
  90. package/dist/modules/engine/engine.cjs +168 -0
  91. package/dist/modules/engine/engine.d.ts +21 -0
  92. package/dist/modules/engine/engine.js +166 -0
  93. package/dist/modules/engine/index.cjs +14 -0
  94. package/dist/modules/engine/index.d.ts +1 -0
  95. package/dist/modules/engine/index.js +8 -0
  96. package/dist/modules/events/index.cjs +16 -0
  97. package/dist/modules/events/index.d.ts +1 -0
  98. package/dist/modules/events/index.js +8 -0
  99. package/dist/modules/events/scroll.cjs +940 -0
  100. package/dist/modules/events/scroll.d.ts +191 -0
  101. package/dist/modules/events/scroll.js +936 -0
  102. package/dist/modules/index.cjs +102 -0
  103. package/dist/modules/index.d.ts +18 -0
  104. package/dist/modules/index.js +41 -0
  105. package/dist/modules/scope/index.cjs +15 -0
  106. package/dist/modules/scope/index.d.ts +1 -0
  107. package/dist/modules/scope/index.js +8 -0
  108. package/dist/modules/scope/scope.cjs +254 -0
  109. package/dist/modules/scope/scope.d.ts +115 -0
  110. package/dist/modules/scope/scope.js +251 -0
  111. package/dist/modules/svg/drawable.cjs +119 -0
  112. package/dist/modules/svg/drawable.d.ts +3 -0
  113. package/dist/modules/svg/drawable.js +117 -0
  114. package/dist/modules/svg/helpers.cjs +30 -0
  115. package/dist/modules/svg/helpers.d.ts +2 -0
  116. package/dist/modules/svg/helpers.js +28 -0
  117. package/dist/modules/svg/index.cjs +18 -0
  118. package/dist/modules/svg/index.d.ts +3 -0
  119. package/dist/modules/svg/index.js +10 -0
  120. package/dist/modules/svg/morphto.cjs +58 -0
  121. package/dist/modules/svg/morphto.d.ts +3 -0
  122. package/dist/modules/svg/morphto.js +56 -0
  123. package/dist/modules/svg/motionpath.cjs +79 -0
  124. package/dist/modules/svg/motionpath.d.ts +7 -0
  125. package/dist/modules/svg/motionpath.js +77 -0
  126. package/dist/modules/text/index.cjs +16 -0
  127. package/dist/modules/text/index.d.ts +1 -0
  128. package/dist/modules/text/index.js +8 -0
  129. package/dist/modules/text/split.cjs +488 -0
  130. package/dist/modules/text/split.d.ts +62 -0
  131. package/dist/modules/text/split.js +484 -0
  132. package/dist/modules/timeline/index.cjs +15 -0
  133. package/dist/modules/timeline/index.d.ts +1 -0
  134. package/dist/modules/timeline/index.js +8 -0
  135. package/dist/modules/timeline/position.cjs +72 -0
  136. package/dist/modules/timeline/position.d.ts +3 -0
  137. package/dist/modules/timeline/position.js +70 -0
  138. package/dist/modules/timeline/timeline.cjs +312 -0
  139. package/dist/modules/timeline/timeline.d.ts +163 -0
  140. package/dist/modules/timeline/timeline.js +309 -0
  141. package/dist/modules/timer/index.cjs +15 -0
  142. package/dist/modules/timer/index.d.ts +1 -0
  143. package/dist/modules/timer/index.js +8 -0
  144. package/dist/modules/timer/timer.cjs +491 -0
  145. package/dist/modules/timer/timer.d.ts +141 -0
  146. package/dist/modules/timer/timer.js +488 -0
  147. package/dist/modules/types/index.d.ts +404 -0
  148. package/dist/modules/utils/chainable.cjs +190 -0
  149. package/dist/modules/utils/chainable.d.ts +135 -0
  150. package/dist/modules/utils/chainable.js +177 -0
  151. package/dist/modules/utils/index.cjs +43 -0
  152. package/dist/modules/utils/index.d.ts +5 -0
  153. package/dist/modules/utils/index.js +14 -0
  154. package/dist/modules/utils/number.cjs +97 -0
  155. package/dist/modules/utils/number.d.ts +9 -0
  156. package/dist/modules/utils/number.js +85 -0
  157. package/dist/modules/utils/random.cjs +77 -0
  158. package/dist/modules/utils/random.d.ts +22 -0
  159. package/dist/modules/utils/random.js +72 -0
  160. package/dist/modules/utils/stagger.cjs +122 -0
  161. package/dist/modules/utils/stagger.d.ts +30 -0
  162. package/dist/modules/utils/stagger.js +120 -0
  163. package/dist/modules/utils/target.cjs +130 -0
  164. package/dist/modules/utils/target.d.ts +126 -0
  165. package/dist/modules/utils/target.js +125 -0
  166. package/dist/modules/utils/time.cjs +57 -0
  167. package/dist/modules/utils/time.d.ts +5 -0
  168. package/dist/modules/utils/time.js +54 -0
  169. package/dist/modules/waapi/composition.cjs +95 -0
  170. package/dist/modules/waapi/composition.d.ts +4 -0
  171. package/dist/modules/waapi/composition.js +92 -0
  172. package/dist/modules/waapi/index.cjs +15 -0
  173. package/dist/modules/waapi/index.d.ts +1 -0
  174. package/dist/modules/waapi/index.js +8 -0
  175. package/dist/modules/waapi/waapi.cjs +492 -0
  176. package/dist/modules/waapi/waapi.d.ts +116 -0
  177. package/dist/modules/waapi/waapi.js +489 -0
  178. package/package.json +166 -33
  179. package/lib/anime.cjs +0 -9
  180. package/lib/anime.esm.min.js +0 -9
  181. package/lib/anime.iife.js +0 -9
  182. package/lib/anime.iife.min.js +0 -9
  183. package/lib/anime.min.cjs +0 -9
  184. package/lib/anime.umd.js +0 -9
  185. package/lib/anime.umd.min.js +0 -9
  186. package/lib/gui/index.js +0 -6341
  187. package/types/index.d.ts +0 -1127
  188. package/types/index.js +0 -7395
@@ -0,0 +1,489 @@
1
+ /**
2
+ * Anime.js - waapi - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ import { isNil, isUnd, stringStartsWith, isKey, isObj, isArr, toLowerCase, round, isStr, isFnc, isNum } from '../core/helpers.js';
9
+ import { scope, globals } from '../core/globals.js';
10
+ import { registerTargets } from '../core/targets.js';
11
+ import { setValue, getFunctionValue } from '../core/values.js';
12
+ import { isBrowser, validTransforms, noop, transformsSymbol, shortTransforms, transformsFragmentStrings, emptyString, K } from '../core/consts.js';
13
+ import { none } from '../easings/none.js';
14
+ import { parseEaseString } from '../easings/eases/parser.js';
15
+ import { addWAAPIAnimation } from './composition.js';
16
+
17
+ /**
18
+ * @import {
19
+ * Callback,
20
+ * EasingFunction,
21
+ * EasingParam,
22
+ * DOMTarget,
23
+ * DOMTargetsParam,
24
+ * DOMTargetsArray,
25
+ * WAAPIAnimationParams,
26
+ * WAAPITweenOptions,
27
+ * WAAPIKeyframeValue,
28
+ * WAAPICallback,
29
+ * WAAPITweenValue
30
+ * } from '../types/index.js'
31
+ */
32
+
33
+ /**
34
+ * @import {
35
+ * Spring,
36
+ * } from '../easings/spring/index.js'
37
+ */
38
+
39
+ /**
40
+ * @import {
41
+ * ScrollObserver,
42
+ * } from '../events/scroll.js'
43
+ */
44
+
45
+ /**
46
+ * Converts an easing function into a valid CSS linear() timing function string
47
+ * @param {EasingFunction} fn
48
+ * @param {number} [samples=100]
49
+ * @returns {string} CSS linear() timing function
50
+ */
51
+ const easingToLinear = (fn, samples = 100) => {
52
+ const points = [];
53
+ for (let i = 0; i <= samples; i++) points.push(round(fn(i / samples), 4));
54
+ return `linear(${points.join(', ')})`;
55
+ };
56
+
57
+ const WAAPIEasesLookups = {};
58
+
59
+ /**
60
+ * @param {EasingParam} ease
61
+ * @return {String}
62
+ */
63
+ const parseWAAPIEasing = (ease) => {
64
+ let parsedEase = WAAPIEasesLookups[ease];
65
+ if (parsedEase) return parsedEase;
66
+ parsedEase = 'linear';
67
+ if (isStr(ease)) {
68
+ if (
69
+ stringStartsWith(ease, 'linear') ||
70
+ stringStartsWith(ease, 'cubic-') ||
71
+ stringStartsWith(ease, 'steps') ||
72
+ stringStartsWith(ease, 'ease')
73
+ ) {
74
+ parsedEase = ease;
75
+ } else if (stringStartsWith(ease, 'cubicB')) {
76
+ parsedEase = toLowerCase(ease);
77
+ } else {
78
+ const parsed = parseEaseString(ease);
79
+ if (isFnc(parsed)) parsedEase = parsed === none ? 'linear' : easingToLinear(parsed);
80
+ }
81
+ // Only cache string based easing name, otherwise function arguments get lost
82
+ WAAPIEasesLookups[ease] = parsedEase;
83
+ } else if (isFnc(ease)) {
84
+ const easing = easingToLinear(ease);
85
+ if (easing) parsedEase = easing;
86
+ } else if (/** @type {Spring} */(ease).ease) {
87
+ parsedEase = easingToLinear(/** @type {Spring} */(ease).ease);
88
+ }
89
+ return parsedEase;
90
+ };
91
+
92
+ const transformsShorthands = ['x', 'y', 'z'];
93
+ const commonDefaultPXProperties = [
94
+ 'perspective',
95
+ 'width',
96
+ 'height',
97
+ 'margin',
98
+ 'padding',
99
+ 'top',
100
+ 'right',
101
+ 'bottom',
102
+ 'left',
103
+ 'borderWidth',
104
+ 'fontSize',
105
+ 'borderRadius',
106
+ ...transformsShorthands
107
+ ];
108
+
109
+ const validIndividualTransforms = /*#__PURE__*/ (() => [...transformsShorthands, ...validTransforms.filter(t => ['X', 'Y', 'Z'].some(axis => t.endsWith(axis)))])();
110
+
111
+ let transformsPropertiesRegistered = null;
112
+
113
+ /**
114
+ * @param {String} propName
115
+ * @param {WAAPIKeyframeValue} value
116
+ * @param {DOMTarget} $el
117
+ * @param {Number} i
118
+ * @param {Number} targetsLength
119
+ * @return {String}
120
+ */
121
+ const normalizeTweenValue = (propName, 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);
124
+ if (!isNum(v)) return v;
125
+ if (commonDefaultPXProperties.includes(propName) || stringStartsWith(propName, 'translate')) return `${v}px`;
126
+ if (stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew')) return `${v}deg`;
127
+ return `${v}`;
128
+ };
129
+
130
+ /**
131
+ * @param {DOMTarget} $el
132
+ * @param {String} propName
133
+ * @param {WAAPIKeyframeValue} from
134
+ * @param {WAAPIKeyframeValue} to
135
+ * @param {Number} i
136
+ * @param {Number} targetsLength
137
+ * @return {WAAPITweenValue}
138
+ */
139
+ const parseIndividualTweenValue = ($el, propName, from, to, i, targetsLength) => {
140
+ /** @type {WAAPITweenValue} */
141
+ let tweenValue = '0';
142
+ const computedTo = !isUnd(to) ? normalizeTweenValue(propName, to, $el, i, targetsLength) : getComputedStyle($el)[propName];
143
+ if (!isUnd(from)) {
144
+ const computedFrom = normalizeTweenValue(propName, from, $el, i, targetsLength);
145
+ tweenValue = [computedFrom, computedTo];
146
+ } else {
147
+ tweenValue = isArr(to) ? to.map((/** @type {any} */v) => normalizeTweenValue(propName, v, $el, i, targetsLength)) : computedTo;
148
+ }
149
+ return tweenValue;
150
+ };
151
+
152
+ class WAAPIAnimation {
153
+ /**
154
+ * @param {DOMTargetsParam} targets
155
+ * @param {WAAPIAnimationParams} params
156
+ */
157
+ constructor(targets, params) {
158
+
159
+ if (scope.current) scope.current.register(this);
160
+
161
+ // Skip the registration and fallback to no animation in case CSS.registerProperty is not supported
162
+ if (isNil(transformsPropertiesRegistered)) {
163
+ if (isBrowser && (isUnd(CSS) || !Object.hasOwnProperty.call(CSS, 'registerProperty'))) {
164
+ transformsPropertiesRegistered = false;
165
+ } else {
166
+ validTransforms.forEach(t => {
167
+ const isSkew = stringStartsWith(t, 'skew');
168
+ const isScale = stringStartsWith(t, 'scale');
169
+ const isRotate = stringStartsWith(t, 'rotate');
170
+ const isTranslate = stringStartsWith(t, 'translate');
171
+ const isAngle = isRotate || isSkew;
172
+ const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*";
173
+ try {
174
+ CSS.registerProperty({
175
+ name: '--' + t,
176
+ syntax,
177
+ inherits: false,
178
+ initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
179
+ });
180
+ } catch {} });
181
+ transformsPropertiesRegistered = true;
182
+ }
183
+ }
184
+
185
+ const parsedTargets = registerTargets(targets);
186
+ const targetsLength = parsedTargets.length;
187
+
188
+ if (!targetsLength) {
189
+ console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`);
190
+ }
191
+
192
+ const ease = setValue(params.ease, parseWAAPIEasing(globals.defaults.ease));
193
+ const spring = /** @type {Spring} */(ease).ease && ease;
194
+ const autoplay = setValue(params.autoplay, globals.defaults.autoplay);
195
+ const scroll = autoplay && /** @type {ScrollObserver} */(autoplay).link ? autoplay : false;
196
+ const alternate = params.alternate && /** @type {Boolean} */(params.alternate) === true;
197
+ const reversed = params.reversed && /** @type {Boolean} */(params.reversed) === true;
198
+ const loop = setValue(params.loop, globals.defaults.loop);
199
+ const iterations = /** @type {Number} */((loop === true || loop === Infinity) ? Infinity : isNum(loop) ? loop + 1 : 1);
200
+ /** @type {PlaybackDirection} */
201
+ const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal';
202
+ /** @type {FillMode} */
203
+ const fill = 'both'; // We use 'both' here because the animation can be reversed during playback
204
+ /** @type {String} */
205
+ const easing = parseWAAPIEasing(ease);
206
+ const timeScale = (globals.timeScale === 1 ? 1 : K);
207
+
208
+ /** @type {DOMTargetsArray}] */
209
+ this.targets = parsedTargets;
210
+ /** @type {Array<globalThis.Animation>}] */
211
+ this.animations = [];
212
+ /** @type {globalThis.Animation}] */
213
+ this.controlAnimation = null;
214
+ /** @type {Callback<this>} */
215
+ this.onComplete = params.onComplete || /** @type {Callback<WAAPIAnimation>} */(/** @type {unknown} */(globals.defaults.onComplete));
216
+ /** @type {Number} */
217
+ this.duration = 0;
218
+ /** @type {Boolean} */
219
+ this.muteCallbacks = false;
220
+ /** @type {Boolean} */
221
+ this.completed = false;
222
+ /** @type {Boolean} */
223
+ this.paused = !autoplay || scroll !== false;
224
+ /** @type {Boolean} */
225
+ this.reversed = reversed;
226
+ /** @type {Boolean} */
227
+ this.persist = setValue(params.persist, globals.defaults.persist);
228
+ /** @type {Boolean|ScrollObserver} */
229
+ this.autoplay = autoplay;
230
+ /** @type {Number} */
231
+ this._speed = setValue(params.playbackRate, globals.defaults.playbackRate);
232
+ /** @type {Function} */
233
+ this._resolve = noop; // Used by .then()
234
+ /** @type {Number} */
235
+ this._completed = 0;
236
+ /** @type {Array.<Object>} */
237
+ this._inlineStyles = [];
238
+
239
+ parsedTargets.forEach(($el, i) => {
240
+
241
+ const cachedTransforms = $el[transformsSymbol];
242
+ const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t));
243
+ const elStyle = $el.style;
244
+ const inlineStyles = this._inlineStyles[i] = {};
245
+
246
+ /** @type {Number} */
247
+ const duration = (spring ? /** @type {Spring} */(spring).settlingDuration : getFunctionValue(setValue(params.duration, globals.defaults.duration), $el, i, targetsLength)) * timeScale;
248
+ /** @type {Number} */
249
+ const delay = getFunctionValue(setValue(params.delay, globals.defaults.delay), $el, i, targetsLength) * timeScale;
250
+ /** @type {CompositeOperation} */
251
+ const composite = /** @type {CompositeOperation} */(setValue(params.composition, 'replace'));
252
+
253
+ for (let name in params) {
254
+ if (!isKey(name)) continue;
255
+ /** @type {PropertyIndexedKeyframes} */
256
+ const keyframes = {};
257
+ /** @type {KeyframeAnimationOptions} */
258
+ const tweenParams = { iterations, direction, fill, easing, duration, delay, composite };
259
+ const propertyValue = params[name];
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
+
267
+ let parsedPropertyValue;
268
+ if (isObj(propertyValue)) {
269
+ const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue);
270
+ const tweenOptionsEase = setValue(tweenOptions.ease, ease);
271
+ const tweenOptionsSpring = /** @type {Spring} */(tweenOptionsEase).ease && tweenOptionsEase;
272
+ const to = /** @type {WAAPITweenOptions} */(tweenOptions).to;
273
+ const from = /** @type {WAAPITweenOptions} */(tweenOptions).from;
274
+ /** @type {Number} */
275
+ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).settlingDuration : getFunctionValue(setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
276
+ /** @type {Number} */
277
+ tweenParams.delay = getFunctionValue(setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale;
278
+ /** @type {CompositeOperation} */
279
+ tweenParams.composite = /** @type {CompositeOperation} */(setValue(tweenOptions.composition, composite));
280
+ /** @type {String} */
281
+ tweenParams.easing = parseWAAPIEasing(tweenOptionsEase);
282
+ parsedPropertyValue = parseIndividualTweenValue($el, name, from, to, i, targetsLength);
283
+ if (individualTransformProperty) {
284
+ keyframes[`--${individualTransformProperty}`] = parsedPropertyValue;
285
+ cachedTransforms[individualTransformProperty] = parsedPropertyValue;
286
+ } else {
287
+ keyframes[name] = parseIndividualTweenValue($el, name, from, to, i, targetsLength);
288
+ }
289
+ addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
290
+ if (!isUnd(from)) {
291
+ if (!individualTransformProperty) {
292
+ elStyle[name] = keyframes[name][0];
293
+ } else {
294
+ const key = `--${individualTransformProperty}`;
295
+ elStyle.setProperty(key, keyframes[key][0]);
296
+ }
297
+ }
298
+ } else {
299
+ parsedPropertyValue = isArr(propertyValue) ?
300
+ propertyValue.map((/** @type {any} */v) => normalizeTweenValue(name, v, $el, i, targetsLength)) :
301
+ normalizeTweenValue(name, /** @type {any} */(propertyValue), $el, i, targetsLength);
302
+ if (individualTransformProperty) {
303
+ keyframes[`--${individualTransformProperty}`] = parsedPropertyValue;
304
+ cachedTransforms[individualTransformProperty] = parsedPropertyValue;
305
+ } else {
306
+ keyframes[name] = parsedPropertyValue;
307
+ }
308
+ addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
309
+ }
310
+ }
311
+ if (hasIndividualTransforms) {
312
+ let transforms = emptyString;
313
+ for (let t in cachedTransforms) {
314
+ transforms += `${transformsFragmentStrings[t]}var(--${t})) `;
315
+ }
316
+ elStyle.transform = transforms;
317
+ }
318
+ });
319
+
320
+ if (scroll) {
321
+ /** @type {ScrollObserver} */(this.autoplay).link(this);
322
+ }
323
+ }
324
+
325
+ /**
326
+ * @callback forEachCallback
327
+ * @param {globalThis.Animation} animation
328
+ */
329
+
330
+ /**
331
+ * @param {forEachCallback|String} callback
332
+ * @return {this}
333
+ */
334
+ forEach(callback) {
335
+ const cb = isStr(callback) ? (/** @type {globalThis.Animation} */a) => a[callback]() : callback;
336
+ this.animations.forEach(cb);
337
+ return this;
338
+ }
339
+
340
+ get speed() {
341
+ return this._speed;
342
+ }
343
+
344
+ set speed(speed) {
345
+ this._speed = +speed;
346
+ this.forEach(anim => anim.playbackRate = speed);
347
+ }
348
+
349
+ get currentTime() {
350
+ const controlAnimation = this.controlAnimation;
351
+ const timeScale = globals.timeScale;
352
+ return this.completed ? this.duration : controlAnimation ? +controlAnimation.currentTime * (timeScale === 1 ? 1 : timeScale) : 0;
353
+ }
354
+
355
+ set currentTime(time) {
356
+ const t = time * (globals.timeScale === 1 ? 1 : K);
357
+ this.forEach(anim => {
358
+ // Make sure the animation playState is not 'paused' in order to properly trigger an onfinish callback.
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.
360
+ // https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event
361
+ // This is not needed for persisting animations since they never finish.
362
+ if (!this.persist && t >= this.duration) anim.play();
363
+ anim.currentTime = t;
364
+ });
365
+ }
366
+
367
+ get progress() {
368
+ return this.currentTime / this.duration;
369
+ }
370
+
371
+ set progress(progress) {
372
+ this.forEach(anim => anim.currentTime = progress * this.duration || 0);
373
+ }
374
+
375
+ resume() {
376
+ if (!this.paused) return this;
377
+ this.paused = false;
378
+ // TODO: Store the current time, and seek back to the last position
379
+ return this.forEach('play');
380
+ }
381
+
382
+ pause() {
383
+ if (this.paused) return this;
384
+ this.paused = true;
385
+ return this.forEach('pause');
386
+ }
387
+
388
+ alternate() {
389
+ this.reversed = !this.reversed;
390
+ this.forEach('reverse');
391
+ if (this.paused) this.forEach('pause');
392
+ return this;
393
+ }
394
+
395
+ play() {
396
+ if (this.reversed) this.alternate();
397
+ return this.resume();
398
+ }
399
+
400
+ reverse() {
401
+ if (!this.reversed) this.alternate();
402
+ return this.resume();
403
+ }
404
+
405
+ /**
406
+ * @param {Number} time
407
+ * @param {Boolean} muteCallbacks
408
+ */
409
+ seek(time, muteCallbacks = false) {
410
+ if (muteCallbacks) this.muteCallbacks = true;
411
+ if (time < this.duration) this.completed = false;
412
+ this.currentTime = time;
413
+ this.muteCallbacks = false;
414
+ if (this.paused) this.pause();
415
+ return this;
416
+ }
417
+
418
+ restart() {
419
+ this.completed = false;
420
+ return this.seek(0, true).resume();
421
+ }
422
+
423
+ commitStyles() {
424
+ return this.forEach('commitStyles');
425
+ }
426
+
427
+ complete() {
428
+ return this.seek(this.duration);
429
+ }
430
+
431
+ cancel() {
432
+ this.muteCallbacks = true; // This prevents triggering the onComplete callback and resolving the Promise
433
+ return this.commitStyles().forEach('cancel');
434
+ }
435
+
436
+ revert() {
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
+ });
456
+ return this;
457
+ }
458
+
459
+ /**
460
+ * @param {WAAPICallback} [callback]
461
+ * @return {Promise}
462
+ */
463
+ then(callback = noop) {
464
+ const then = this.then;
465
+ const onResolve = () => {
466
+ this.then = null;
467
+ callback(this);
468
+ this.then = then;
469
+ this._resolve = noop;
470
+ };
471
+ return new Promise(r => {
472
+ this._resolve = () => r(onResolve());
473
+ if (this.completed) this._resolve();
474
+ return this;
475
+ });
476
+ }
477
+ }
478
+
479
+ const waapi = {
480
+ /**
481
+ * @param {DOMTargetsParam} targets
482
+ * @param {WAAPIAnimationParams} params
483
+ * @return {WAAPIAnimation}
484
+ */
485
+ animate: (targets, params) => new WAAPIAnimation(targets, params),
486
+ convertEase: easingToLinear
487
+ };
488
+
489
+ export { WAAPIAnimation, waapi };