animejs 4.1.2 → 4.2.0-beta.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 (191) hide show
  1. package/README.md +18 -8
  2. package/{lib → dist/bundles}/anime.esm.js +6549 -6265
  3. package/dist/bundles/anime.esm.min.js +7 -0
  4. package/dist/bundles/anime.umd.js +8621 -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 +660 -0
  16. package/dist/modules/animation/animation.d.ts +47 -0
  17. package/dist/modules/animation/animation.js +657 -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 +154 -0
  31. package/dist/modules/core/consts.d.ts +59 -0
  32. package/dist/modules/core/consts.js +121 -0
  33. package/dist/modules/core/globals.cjs +77 -0
  34. package/dist/modules/core/globals.d.ts +29 -0
  35. package/dist/modules/core/globals.js +72 -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 +389 -0
  40. package/dist/modules/core/render.d.ts +4 -0
  41. package/dist/modules/core/render.js +386 -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 +215 -0
  55. package/dist/modules/core/values.d.ts +14 -0
  56. package/dist/modules/core/values.js +205 -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.cjs +64 -0
  64. package/dist/modules/easings/cubic-bezier.d.ts +2 -0
  65. package/dist/modules/easings/cubic-bezier.js +62 -0
  66. package/dist/modules/easings/eases.cjs +149 -0
  67. package/dist/modules/easings/eases.d.ts +111 -0
  68. package/dist/modules/easings/eases.js +146 -0
  69. package/dist/modules/easings/index.cjs +24 -0
  70. package/dist/modules/easings/index.d.ts +6 -0
  71. package/dist/modules/easings/index.js +13 -0
  72. package/dist/modules/easings/irregular.cjs +41 -0
  73. package/dist/modules/easings/irregular.d.ts +2 -0
  74. package/dist/modules/easings/irregular.js +39 -0
  75. package/dist/modules/easings/linear.cjs +59 -0
  76. package/dist/modules/easings/linear.d.ts +2 -0
  77. package/dist/modules/easings/linear.js +57 -0
  78. package/dist/modules/easings/none.cjs +19 -0
  79. package/dist/modules/easings/none.d.ts +8 -0
  80. package/dist/modules/easings/none.js +17 -0
  81. package/dist/modules/easings/parser.cjs +59 -0
  82. package/dist/modules/easings/parser.d.ts +21 -0
  83. package/dist/modules/easings/parser.js +55 -0
  84. package/dist/modules/easings/steps.cjs +30 -0
  85. package/dist/modules/easings/steps.d.ts +2 -0
  86. package/dist/modules/easings/steps.js +28 -0
  87. package/dist/modules/engine/engine.cjs +168 -0
  88. package/dist/modules/engine/engine.d.ts +21 -0
  89. package/dist/modules/engine/engine.js +166 -0
  90. package/dist/modules/engine/index.cjs +14 -0
  91. package/dist/modules/engine/index.d.ts +1 -0
  92. package/dist/modules/engine/index.js +8 -0
  93. package/dist/modules/events/index.cjs +16 -0
  94. package/dist/modules/events/index.d.ts +1 -0
  95. package/dist/modules/events/index.js +8 -0
  96. package/dist/modules/events/scroll.cjs +936 -0
  97. package/dist/modules/events/scroll.d.ts +189 -0
  98. package/dist/modules/events/scroll.js +932 -0
  99. package/dist/modules/index.cjs +103 -0
  100. package/dist/modules/index.d.ts +19 -0
  101. package/dist/modules/index.js +42 -0
  102. package/dist/modules/scope/index.cjs +15 -0
  103. package/dist/modules/scope/index.d.ts +1 -0
  104. package/dist/modules/scope/index.js +8 -0
  105. package/dist/modules/scope/scope.cjs +254 -0
  106. package/dist/modules/scope/scope.d.ts +115 -0
  107. package/dist/modules/scope/scope.js +251 -0
  108. package/dist/modules/spring/index.cjs +15 -0
  109. package/dist/modules/spring/index.d.ts +1 -0
  110. package/dist/modules/spring/index.js +8 -0
  111. package/dist/modules/spring/spring.cjs +133 -0
  112. package/dist/modules/spring/spring.d.ts +37 -0
  113. package/dist/modules/spring/spring.js +130 -0
  114. package/dist/modules/svg/drawable.cjs +119 -0
  115. package/dist/modules/svg/drawable.d.ts +3 -0
  116. package/dist/modules/svg/drawable.js +117 -0
  117. package/dist/modules/svg/helpers.cjs +30 -0
  118. package/dist/modules/svg/helpers.d.ts +2 -0
  119. package/dist/modules/svg/helpers.js +28 -0
  120. package/dist/modules/svg/index.cjs +18 -0
  121. package/dist/modules/svg/index.d.ts +3 -0
  122. package/dist/modules/svg/index.js +10 -0
  123. package/dist/modules/svg/morphto.cjs +58 -0
  124. package/dist/modules/svg/morphto.d.ts +3 -0
  125. package/dist/modules/svg/morphto.js +56 -0
  126. package/dist/modules/svg/motionpath.cjs +79 -0
  127. package/dist/modules/svg/motionpath.d.ts +7 -0
  128. package/dist/modules/svg/motionpath.js +77 -0
  129. package/dist/modules/text/index.cjs +16 -0
  130. package/dist/modules/text/index.d.ts +1 -0
  131. package/dist/modules/text/index.js +8 -0
  132. package/dist/modules/text/split.cjs +488 -0
  133. package/dist/modules/text/split.d.ts +62 -0
  134. package/dist/modules/text/split.js +484 -0
  135. package/dist/modules/timeline/index.cjs +15 -0
  136. package/dist/modules/timeline/index.d.ts +1 -0
  137. package/dist/modules/timeline/index.js +8 -0
  138. package/dist/modules/timeline/position.cjs +72 -0
  139. package/dist/modules/timeline/position.d.ts +3 -0
  140. package/dist/modules/timeline/position.js +70 -0
  141. package/dist/modules/timeline/timeline.cjs +312 -0
  142. package/dist/modules/timeline/timeline.d.ts +163 -0
  143. package/dist/modules/timeline/timeline.js +309 -0
  144. package/dist/modules/timer/index.cjs +15 -0
  145. package/dist/modules/timer/index.d.ts +1 -0
  146. package/dist/modules/timer/index.js +8 -0
  147. package/dist/modules/timer/timer.cjs +491 -0
  148. package/dist/modules/timer/timer.d.ts +141 -0
  149. package/dist/modules/timer/timer.js +488 -0
  150. package/dist/modules/types/index.d.ts +387 -0
  151. package/dist/modules/utils/chainable.cjs +190 -0
  152. package/dist/modules/utils/chainable.d.ts +135 -0
  153. package/dist/modules/utils/chainable.js +177 -0
  154. package/dist/modules/utils/index.cjs +43 -0
  155. package/dist/modules/utils/index.d.ts +5 -0
  156. package/dist/modules/utils/index.js +14 -0
  157. package/dist/modules/utils/number.cjs +97 -0
  158. package/dist/modules/utils/number.d.ts +9 -0
  159. package/dist/modules/utils/number.js +85 -0
  160. package/dist/modules/utils/random.cjs +77 -0
  161. package/dist/modules/utils/random.d.ts +22 -0
  162. package/dist/modules/utils/random.js +72 -0
  163. package/dist/modules/utils/stagger.cjs +122 -0
  164. package/dist/modules/utils/stagger.d.ts +30 -0
  165. package/dist/modules/utils/stagger.js +120 -0
  166. package/dist/modules/utils/target.cjs +130 -0
  167. package/dist/modules/utils/target.d.ts +126 -0
  168. package/dist/modules/utils/target.js +125 -0
  169. package/dist/modules/utils/time.cjs +57 -0
  170. package/dist/modules/utils/time.d.ts +5 -0
  171. package/dist/modules/utils/time.js +54 -0
  172. package/dist/modules/waapi/composition.cjs +89 -0
  173. package/dist/modules/waapi/composition.d.ts +4 -0
  174. package/dist/modules/waapi/composition.js +86 -0
  175. package/dist/modules/waapi/index.cjs +15 -0
  176. package/dist/modules/waapi/index.d.ts +1 -0
  177. package/dist/modules/waapi/index.js +8 -0
  178. package/dist/modules/waapi/waapi.cjs +473 -0
  179. package/dist/modules/waapi/waapi.d.ts +114 -0
  180. package/dist/modules/waapi/waapi.js +470 -0
  181. package/package.json +130 -33
  182. package/lib/anime.cjs +0 -9
  183. package/lib/anime.esm.min.js +0 -9
  184. package/lib/anime.iife.js +0 -9
  185. package/lib/anime.iife.min.js +0 -9
  186. package/lib/anime.min.cjs +0 -9
  187. package/lib/anime.umd.js +0 -9
  188. package/lib/anime.umd.min.js +0 -9
  189. package/lib/gui/index.js +0 -6341
  190. package/types/index.d.ts +0 -1081
  191. package/types/index.js +0 -7407
@@ -0,0 +1,473 @@
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/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 '../spring/spring.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(fn(i / samples));
56
+ return `linear(${points.join(', ')})`;
57
+ };
58
+
59
+ const WAAPIEasesLookups = {
60
+ in: 'ease-in',
61
+ out: 'ease-out',
62
+ inOut: 'ease-in-out',
63
+ };
64
+
65
+ const WAAPIeases = /*#__PURE__*/(() => {
66
+ const list = {};
67
+ for (let type in parser.easeTypes) list[type] = (/** @type {String|Number} */p) => parser.easeTypes[type](parser.easeInPower(p));
68
+ return /** @type {Record<String, EasingFunction>} */(list);
69
+ })();
70
+
71
+ /**
72
+ * @param {EasingParam} ease
73
+ * @return {String}
74
+ */
75
+ const parseWAAPIEasing = (ease) => {
76
+ let parsedEase = WAAPIEasesLookups[ease];
77
+ if (parsedEase) return parsedEase;
78
+ parsedEase = 'linear';
79
+ if (helpers.isStr(ease)) {
80
+ if (
81
+ helpers.stringStartsWith(ease, 'linear') ||
82
+ helpers.stringStartsWith(ease, 'cubic-') ||
83
+ helpers.stringStartsWith(ease, 'steps') ||
84
+ helpers.stringStartsWith(ease, 'ease')
85
+ ) {
86
+ parsedEase = ease;
87
+ } else if (helpers.stringStartsWith(ease, 'cubicB')) {
88
+ parsedEase = helpers.toLowerCase(ease);
89
+ } else {
90
+ const parsed = parser.parseEaseString(ease, WAAPIeases, WAAPIEasesLookups);
91
+ if (helpers.isFnc(parsed)) parsedEase = parsed === none.none ? 'linear' : easingToLinear(parsed);
92
+ }
93
+ WAAPIEasesLookups[ease] = parsedEase;
94
+ } else if (helpers.isFnc(ease)) {
95
+ const easing = easingToLinear(ease);
96
+ if (easing) parsedEase = easing;
97
+ } else if (/** @type {Spring} */(ease).ease) {
98
+ parsedEase = easingToLinear(/** @type {Spring} */(ease).ease);
99
+ }
100
+ return parsedEase;
101
+ };
102
+
103
+ const transformsShorthands = ['x', 'y', 'z'];
104
+ const commonDefaultPXProperties = [
105
+ 'perspective',
106
+ 'width',
107
+ 'height',
108
+ 'margin',
109
+ 'padding',
110
+ 'top',
111
+ 'right',
112
+ 'bottom',
113
+ 'left',
114
+ 'borderWidth',
115
+ 'fontSize',
116
+ 'borderRadius',
117
+ ...transformsShorthands
118
+ ];
119
+
120
+ const validIndividualTransforms = /*#__PURE__*/ (() => [...transformsShorthands, ...consts.validTransforms.filter(t => ['X', 'Y', 'Z'].some(axis => t.endsWith(axis)))])();
121
+
122
+ let transformsPropertiesRegistered = null;
123
+
124
+ /**
125
+ * @param {String} propName
126
+ * @param {WAAPIKeyframeValue} value
127
+ * @param {DOMTarget} $el
128
+ * @param {Number} i
129
+ * @param {Number} targetsLength
130
+ * @return {String}
131
+ */
132
+ const normalizeTweenValue = (propName, value, $el, i, targetsLength) => {
133
+ let v = values.getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
134
+ if (!helpers.isNum(v)) return v;
135
+ if (commonDefaultPXProperties.includes(propName) || helpers.stringStartsWith(propName, 'translate')) return `${v}px`;
136
+ if (helpers.stringStartsWith(propName, 'rotate') || helpers.stringStartsWith(propName, 'skew')) return `${v}deg`;
137
+ return `${v}`;
138
+ };
139
+
140
+ /**
141
+ * @param {DOMTarget} $el
142
+ * @param {String} propName
143
+ * @param {WAAPIKeyframeValue} from
144
+ * @param {WAAPIKeyframeValue} to
145
+ * @param {Number} i
146
+ * @param {Number} targetsLength
147
+ * @return {WAAPITweenValue}
148
+ */
149
+ const parseIndividualTweenValue = ($el, propName, from, to, i, targetsLength) => {
150
+ /** @type {WAAPITweenValue} */
151
+ let tweenValue = '0';
152
+ const computedTo = !helpers.isUnd(to) ? normalizeTweenValue(propName, to, $el, i, targetsLength) : getComputedStyle($el)[propName];
153
+ if (!helpers.isUnd(from)) {
154
+ const computedFrom = normalizeTweenValue(propName, from, $el, i, targetsLength);
155
+ tweenValue = [computedFrom, computedTo];
156
+ } else {
157
+ tweenValue = helpers.isArr(to) ? to.map((/** @type {any} */v) => normalizeTweenValue(propName, v, $el, i, targetsLength)) : computedTo;
158
+ }
159
+ return tweenValue;
160
+ };
161
+
162
+ class WAAPIAnimation {
163
+ /**
164
+ * @param {DOMTargetsParam} targets
165
+ * @param {WAAPIAnimationParams} params
166
+ */
167
+ constructor(targets$1, params) {
168
+
169
+ if (globals.scope.current) globals.scope.current.register(this);
170
+
171
+ // Skip the registration and fallback to no animation in case CSS.registerProperty is not supported
172
+ if (helpers.isNil(transformsPropertiesRegistered)) {
173
+ if (consts.isBrowser && (helpers.isUnd(CSS) || !Object.hasOwnProperty.call(CSS, 'registerProperty'))) {
174
+ transformsPropertiesRegistered = false;
175
+ } else {
176
+ consts.validTransforms.forEach(t => {
177
+ const isSkew = helpers.stringStartsWith(t, 'skew');
178
+ const isScale = helpers.stringStartsWith(t, 'scale');
179
+ const isRotate = helpers.stringStartsWith(t, 'rotate');
180
+ const isTranslate = helpers.stringStartsWith(t, 'translate');
181
+ const isAngle = isRotate || isSkew;
182
+ const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*";
183
+ try {
184
+ CSS.registerProperty({
185
+ name: '--' + t,
186
+ syntax,
187
+ inherits: false,
188
+ initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
189
+ });
190
+ } catch {} });
191
+ transformsPropertiesRegistered = true;
192
+ }
193
+ }
194
+
195
+ const parsedTargets = targets.registerTargets(targets$1);
196
+ const targetsLength = parsedTargets.length;
197
+
198
+ if (!targetsLength) {
199
+ console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`);
200
+ }
201
+
202
+ const ease = values.setValue(params.ease, parseWAAPIEasing(globals.globals.defaults.ease));
203
+ const spring = /** @type {Spring} */(ease).ease && ease;
204
+ const autoplay = values.setValue(params.autoplay, globals.globals.defaults.autoplay);
205
+ const scroll = autoplay && /** @type {ScrollObserver} */(autoplay).link ? autoplay : false;
206
+ const alternate = params.alternate && /** @type {Boolean} */(params.alternate) === true;
207
+ const reversed = params.reversed && /** @type {Boolean} */(params.reversed) === true;
208
+ const loop = values.setValue(params.loop, globals.globals.defaults.loop);
209
+ const iterations = /** @type {Number} */((loop === true || loop === Infinity) ? Infinity : helpers.isNum(loop) ? loop + 1 : 1);
210
+ /** @type {PlaybackDirection} */
211
+ const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal';
212
+ /** @type {FillMode} */
213
+ const fill = 'forwards';
214
+ /** @type {String} */
215
+ const easing = parseWAAPIEasing(ease);
216
+ const timeScale = (globals.globals.timeScale === 1 ? 1 : consts.K);
217
+
218
+ /** @type {DOMTargetsArray}] */
219
+ this.targets = parsedTargets;
220
+ /** @type {Array<globalThis.Animation>}] */
221
+ this.animations = [];
222
+ /** @type {globalThis.Animation}] */
223
+ this.controlAnimation = null;
224
+ /** @type {Callback<this>} */
225
+ this.onComplete = params.onComplete || consts.noop;
226
+ /** @type {Number} */
227
+ this.duration = 0;
228
+ /** @type {Boolean} */
229
+ this.muteCallbacks = false;
230
+ /** @type {Boolean} */
231
+ this.completed = false;
232
+ /** @type {Boolean} */
233
+ this.paused = !autoplay || scroll !== false;
234
+ /** @type {Boolean} */
235
+ this.reversed = reversed;
236
+ /** @type {Boolean|ScrollObserver} */
237
+ this.autoplay = autoplay;
238
+ /** @type {Number} */
239
+ this._speed = values.setValue(params.playbackRate, globals.globals.defaults.playbackRate);
240
+ /** @type {Function} */
241
+ this._resolve = consts.noop; // Used by .then()
242
+ /** @type {Number} */
243
+ this._completed = 0;
244
+ /** @type {Array<Object>}] */
245
+ this._inlineStyles = parsedTargets.map($el => $el.getAttribute('style'));
246
+
247
+ parsedTargets.forEach(($el, i) => {
248
+
249
+ const cachedTransforms = $el[consts.transformsSymbol];
250
+
251
+ const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t));
252
+
253
+ /** @type {Number} */
254
+ const duration = (spring ? /** @type {Spring} */(spring).duration : values.getFunctionValue(values.setValue(params.duration, globals.globals.defaults.duration), $el, i, targetsLength)) * timeScale;
255
+ /** @type {Number} */
256
+ const delay = values.getFunctionValue(values.setValue(params.delay, globals.globals.defaults.delay), $el, i, targetsLength) * timeScale;
257
+ /** @type {CompositeOperation} */
258
+ const composite = /** @type {CompositeOperation} */(values.setValue(params.composition, 'replace'));
259
+
260
+ for (let name in params) {
261
+ if (!helpers.isKey(name)) continue;
262
+ /** @type {PropertyIndexedKeyframes} */
263
+ const keyframes = {};
264
+ /** @type {KeyframeAnimationOptions} */
265
+ const tweenParams = { iterations, direction, fill, easing, duration, delay, composite };
266
+ const propertyValue = params[name];
267
+ const individualTransformProperty = hasIndividualTransforms ? consts.validTransforms.includes(name) ? name : consts.shortTransforms.get(name) : false;
268
+ let parsedPropertyValue;
269
+ if (helpers.isObj(propertyValue)) {
270
+ const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue);
271
+ const tweenOptionsEase = values.setValue(tweenOptions.ease, ease);
272
+ const tweenOptionsSpring = /** @type {Spring} */(tweenOptionsEase).ease && tweenOptionsEase;
273
+ const to = /** @type {WAAPITweenOptions} */(tweenOptions).to;
274
+ const from = /** @type {WAAPITweenOptions} */(tweenOptions).from;
275
+ /** @type {Number} */
276
+ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).duration : values.getFunctionValue(values.setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
277
+ /** @type {Number} */
278
+ tweenParams.delay = values.getFunctionValue(values.setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale;
279
+ /** @type {CompositeOperation} */
280
+ tweenParams.composite = /** @type {CompositeOperation} */(values.setValue(tweenOptions.composition, composite));
281
+ /** @type {String} */
282
+ tweenParams.easing = parseWAAPIEasing(tweenOptionsEase);
283
+ parsedPropertyValue = parseIndividualTweenValue($el, name, from, to, i, targetsLength);
284
+ if (individualTransformProperty) {
285
+ keyframes[`--${individualTransformProperty}`] = parsedPropertyValue;
286
+ cachedTransforms[individualTransformProperty] = parsedPropertyValue;
287
+ } else {
288
+ keyframes[name] = parseIndividualTweenValue($el, name, from, to, i, targetsLength);
289
+ }
290
+ composition.addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
291
+ if (!helpers.isUnd(from)) {
292
+ if (!individualTransformProperty) {
293
+ $el.style[name] = keyframes[name][0];
294
+ } else {
295
+ const key = `--${individualTransformProperty}`;
296
+ $el.style.setProperty(key, keyframes[key][0]);
297
+ }
298
+ }
299
+ } else {
300
+ parsedPropertyValue = helpers.isArr(propertyValue) ?
301
+ propertyValue.map((/** @type {any} */v) => normalizeTweenValue(name, v, $el, i, targetsLength)) :
302
+ normalizeTweenValue(name, /** @type {any} */(propertyValue), $el, i, targetsLength);
303
+ if (individualTransformProperty) {
304
+ keyframes[`--${individualTransformProperty}`] = parsedPropertyValue;
305
+ cachedTransforms[individualTransformProperty] = parsedPropertyValue;
306
+ } else {
307
+ keyframes[name] = parsedPropertyValue;
308
+ }
309
+ composition.addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
310
+ }
311
+ }
312
+ if (hasIndividualTransforms) {
313
+ let transforms = consts.emptyString;
314
+ for (let t in cachedTransforms) {
315
+ transforms += `${consts.transformsFragmentStrings[t]}var(--${t})) `;
316
+ }
317
+ $el.style.transform = transforms;
318
+ }
319
+ });
320
+
321
+ if (scroll) {
322
+ /** @type {ScrollObserver} */(this.autoplay).link(this);
323
+ }
324
+ }
325
+
326
+ /**
327
+ * @callback forEachCallback
328
+ * @param {globalThis.Animation} animation
329
+ */
330
+
331
+ /**
332
+ * @param {forEachCallback|String} callback
333
+ * @return {this}
334
+ */
335
+ forEach(callback) {
336
+ const cb = helpers.isStr(callback) ? (/** @type {globalThis.Animation} */a) => a[callback]() : callback;
337
+ this.animations.forEach(cb);
338
+ return this;
339
+ }
340
+
341
+ get speed() {
342
+ return this._speed;
343
+ }
344
+
345
+ set speed(speed) {
346
+ this._speed = +speed;
347
+ this.forEach(anim => anim.playbackRate = speed);
348
+ }
349
+
350
+ get currentTime() {
351
+ const controlAnimation = this.controlAnimation;
352
+ const timeScale = globals.globals.timeScale;
353
+ return this.completed ? this.duration : controlAnimation ? +controlAnimation.currentTime * (timeScale === 1 ? 1 : timeScale) : 0;
354
+ }
355
+
356
+ set currentTime(time) {
357
+ const t = time * (globals.globals.timeScale === 1 ? 1 : consts.K);
358
+ this.forEach(anim => {
359
+ // Make sure the animation playState is not 'paused' in order to properly trigger an onfinish callback.
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
+ // https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event
362
+ if (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.forEach('cancel');
433
+ return this.pause();
434
+ }
435
+
436
+ revert() {
437
+ this.cancel();
438
+ this.targets.forEach(($el, i) => $el.setAttribute('style', this._inlineStyles[i]) );
439
+ return this;
440
+ }
441
+
442
+ /**
443
+ * @param {WAAPICallback} [callback]
444
+ * @return {Promise}
445
+ */
446
+ then(callback = consts.noop) {
447
+ const then = this.then;
448
+ const onResolve = () => {
449
+ this.then = null;
450
+ callback(this);
451
+ this.then = then;
452
+ this._resolve = consts.noop;
453
+ };
454
+ return new Promise(r => {
455
+ this._resolve = () => r(onResolve());
456
+ if (this.completed) this._resolve();
457
+ return this;
458
+ });
459
+ }
460
+ }
461
+
462
+ const waapi = {
463
+ /**
464
+ * @param {DOMTargetsParam} targets
465
+ * @param {WAAPIAnimationParams} params
466
+ * @return {WAAPIAnimation}
467
+ */
468
+ animate: (targets, params) => new WAAPIAnimation(targets, params),
469
+ convertEase: easingToLinear
470
+ };
471
+
472
+ exports.WAAPIAnimation = WAAPIAnimation;
473
+ exports.waapi = waapi;
@@ -0,0 +1,114 @@
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|ScrollObserver} */
26
+ autoplay: boolean | ScrollObserver;
27
+ /** @type {Number} */
28
+ _speed: number;
29
+ /** @type {Function} */
30
+ _resolve: Function;
31
+ /** @type {Number} */
32
+ _completed: number;
33
+ /** @type {Array<Object>}] */
34
+ _inlineStyles: Array<any>;
35
+ /**
36
+ * @callback forEachCallback
37
+ * @param {globalThis.Animation} animation
38
+ */
39
+ /**
40
+ * @param {forEachCallback|String} callback
41
+ * @return {this}
42
+ */
43
+ forEach(callback: ((animation: globalThis.Animation) => any) | string): this;
44
+ set speed(speed: number);
45
+ get speed(): number;
46
+ set currentTime(time: number);
47
+ get currentTime(): number;
48
+ set progress(progress: number);
49
+ get progress(): number;
50
+ resume(): this;
51
+ pause(): this;
52
+ alternate(): this;
53
+ play(): this;
54
+ reverse(): this;
55
+ /**
56
+ * @param {Number} time
57
+ * @param {Boolean} muteCallbacks
58
+ */
59
+ seek(time: number, muteCallbacks?: boolean): this;
60
+ restart(): this;
61
+ commitStyles(): this;
62
+ complete(): this;
63
+ cancel(): this;
64
+ revert(): this;
65
+ /**
66
+ * @param {WAAPICallback} [callback]
67
+ * @return {Promise}
68
+ */
69
+ then(callback?: WAAPICallback): Promise<any>;
70
+ }
71
+ export namespace waapi {
72
+ export function animate(targets: DOMTargetsParam, params: WAAPIAnimationParams): WAAPIAnimation;
73
+ export { easingToLinear as convertEase };
74
+ }
75
+ import type { DOMTargetsArray } from '../types/index.js';
76
+ import type { Callback } from '../types/index.js';
77
+ import type { ScrollObserver } from '../events/scroll.js';
78
+ import type { WAAPICallback } from '../types/index.js';
79
+ import type { DOMTargetsParam } from '../types/index.js';
80
+ import type { WAAPIAnimationParams } from '../types/index.js';
81
+ /**
82
+ * @import {
83
+ * Callback,
84
+ * EasingFunction,
85
+ * EasingParam,
86
+ * DOMTarget,
87
+ * DOMTargetsParam,
88
+ * DOMTargetsArray,
89
+ * WAAPIAnimationParams,
90
+ * WAAPITweenOptions,
91
+ * WAAPIKeyframeValue,
92
+ * WAAPICallback,
93
+ * WAAPITweenValue
94
+ * } from '../types/index.js'
95
+ */
96
+ /**
97
+ * @import {
98
+ * Spring,
99
+ * } from '../spring/spring.js'
100
+ */
101
+ /**
102
+ * @import {
103
+ * ScrollObserver,
104
+ * } from '../events/scroll.js'
105
+ */
106
+ /**
107
+ * Converts an easing function into a valid CSS linear() timing function string
108
+ * @param {EasingFunction} fn
109
+ * @param {number} [samples=100]
110
+ * @returns {string} CSS linear() timing function
111
+ */
112
+ declare function easingToLinear(fn: EasingFunction, samples?: number): string;
113
+ import type { EasingFunction } from '../types/index.js';
114
+ export {};