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