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,470 @@
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, isStr, toLowerCase, 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, easeTypes, easeInPower } from '../easings/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 '../spring/spring.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(fn(i / samples));
54
+ return `linear(${points.join(', ')})`;
55
+ };
56
+
57
+ const WAAPIEasesLookups = {
58
+ in: 'ease-in',
59
+ out: 'ease-out',
60
+ inOut: 'ease-in-out',
61
+ };
62
+
63
+ const WAAPIeases = /*#__PURE__*/(() => {
64
+ const list = {};
65
+ for (let type in easeTypes) list[type] = (/** @type {String|Number} */p) => easeTypes[type](easeInPower(p));
66
+ return /** @type {Record<String, EasingFunction>} */(list);
67
+ })();
68
+
69
+ /**
70
+ * @param {EasingParam} ease
71
+ * @return {String}
72
+ */
73
+ const parseWAAPIEasing = (ease) => {
74
+ let parsedEase = WAAPIEasesLookups[ease];
75
+ if (parsedEase) return parsedEase;
76
+ parsedEase = 'linear';
77
+ if (isStr(ease)) {
78
+ if (
79
+ stringStartsWith(ease, 'linear') ||
80
+ stringStartsWith(ease, 'cubic-') ||
81
+ stringStartsWith(ease, 'steps') ||
82
+ stringStartsWith(ease, 'ease')
83
+ ) {
84
+ parsedEase = ease;
85
+ } else if (stringStartsWith(ease, 'cubicB')) {
86
+ parsedEase = toLowerCase(ease);
87
+ } else {
88
+ const parsed = parseEaseString(ease, WAAPIeases, WAAPIEasesLookups);
89
+ if (isFnc(parsed)) parsedEase = parsed === none ? 'linear' : easingToLinear(parsed);
90
+ }
91
+ WAAPIEasesLookups[ease] = parsedEase;
92
+ } else if (isFnc(ease)) {
93
+ const easing = easingToLinear(ease);
94
+ if (easing) parsedEase = easing;
95
+ } else if (/** @type {Spring} */(ease).ease) {
96
+ parsedEase = easingToLinear(/** @type {Spring} */(ease).ease);
97
+ }
98
+ return parsedEase;
99
+ };
100
+
101
+ const transformsShorthands = ['x', 'y', 'z'];
102
+ const commonDefaultPXProperties = [
103
+ 'perspective',
104
+ 'width',
105
+ 'height',
106
+ 'margin',
107
+ 'padding',
108
+ 'top',
109
+ 'right',
110
+ 'bottom',
111
+ 'left',
112
+ 'borderWidth',
113
+ 'fontSize',
114
+ 'borderRadius',
115
+ ...transformsShorthands
116
+ ];
117
+
118
+ const validIndividualTransforms = /*#__PURE__*/ (() => [...transformsShorthands, ...validTransforms.filter(t => ['X', 'Y', 'Z'].some(axis => t.endsWith(axis)))])();
119
+
120
+ let transformsPropertiesRegistered = null;
121
+
122
+ /**
123
+ * @param {String} propName
124
+ * @param {WAAPIKeyframeValue} value
125
+ * @param {DOMTarget} $el
126
+ * @param {Number} i
127
+ * @param {Number} targetsLength
128
+ * @return {String}
129
+ */
130
+ const normalizeTweenValue = (propName, value, $el, i, targetsLength) => {
131
+ let v = getFunctionValue(/** @type {any} */(value), $el, i, targetsLength);
132
+ if (!isNum(v)) return v;
133
+ if (commonDefaultPXProperties.includes(propName) || stringStartsWith(propName, 'translate')) return `${v}px`;
134
+ if (stringStartsWith(propName, 'rotate') || stringStartsWith(propName, 'skew')) return `${v}deg`;
135
+ return `${v}`;
136
+ };
137
+
138
+ /**
139
+ * @param {DOMTarget} $el
140
+ * @param {String} propName
141
+ * @param {WAAPIKeyframeValue} from
142
+ * @param {WAAPIKeyframeValue} to
143
+ * @param {Number} i
144
+ * @param {Number} targetsLength
145
+ * @return {WAAPITweenValue}
146
+ */
147
+ const parseIndividualTweenValue = ($el, propName, from, to, i, targetsLength) => {
148
+ /** @type {WAAPITweenValue} */
149
+ let tweenValue = '0';
150
+ const computedTo = !isUnd(to) ? normalizeTweenValue(propName, to, $el, i, targetsLength) : getComputedStyle($el)[propName];
151
+ if (!isUnd(from)) {
152
+ const computedFrom = normalizeTweenValue(propName, from, $el, i, targetsLength);
153
+ tweenValue = [computedFrom, computedTo];
154
+ } else {
155
+ tweenValue = isArr(to) ? to.map((/** @type {any} */v) => normalizeTweenValue(propName, v, $el, i, targetsLength)) : computedTo;
156
+ }
157
+ return tweenValue;
158
+ };
159
+
160
+ class WAAPIAnimation {
161
+ /**
162
+ * @param {DOMTargetsParam} targets
163
+ * @param {WAAPIAnimationParams} params
164
+ */
165
+ constructor(targets, params) {
166
+
167
+ if (scope.current) scope.current.register(this);
168
+
169
+ // Skip the registration and fallback to no animation in case CSS.registerProperty is not supported
170
+ if (isNil(transformsPropertiesRegistered)) {
171
+ if (isBrowser && (isUnd(CSS) || !Object.hasOwnProperty.call(CSS, 'registerProperty'))) {
172
+ transformsPropertiesRegistered = false;
173
+ } else {
174
+ validTransforms.forEach(t => {
175
+ const isSkew = stringStartsWith(t, 'skew');
176
+ const isScale = stringStartsWith(t, 'scale');
177
+ const isRotate = stringStartsWith(t, 'rotate');
178
+ const isTranslate = stringStartsWith(t, 'translate');
179
+ const isAngle = isRotate || isSkew;
180
+ const syntax = isAngle ? '<angle>' : isScale ? "<number>" : isTranslate ? "<length-percentage>" : "*";
181
+ try {
182
+ CSS.registerProperty({
183
+ name: '--' + t,
184
+ syntax,
185
+ inherits: false,
186
+ initialValue: isTranslate ? '0px' : isAngle ? '0deg' : isScale ? '1' : '0',
187
+ });
188
+ } catch {} });
189
+ transformsPropertiesRegistered = true;
190
+ }
191
+ }
192
+
193
+ const parsedTargets = registerTargets(targets);
194
+ const targetsLength = parsedTargets.length;
195
+
196
+ if (!targetsLength) {
197
+ console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`);
198
+ }
199
+
200
+ const ease = setValue(params.ease, parseWAAPIEasing(globals.defaults.ease));
201
+ const spring = /** @type {Spring} */(ease).ease && ease;
202
+ const autoplay = setValue(params.autoplay, globals.defaults.autoplay);
203
+ const scroll = autoplay && /** @type {ScrollObserver} */(autoplay).link ? autoplay : false;
204
+ const alternate = params.alternate && /** @type {Boolean} */(params.alternate) === true;
205
+ const reversed = params.reversed && /** @type {Boolean} */(params.reversed) === true;
206
+ const loop = setValue(params.loop, globals.defaults.loop);
207
+ const iterations = /** @type {Number} */((loop === true || loop === Infinity) ? Infinity : isNum(loop) ? loop + 1 : 1);
208
+ /** @type {PlaybackDirection} */
209
+ const direction = alternate ? reversed ? 'alternate-reverse' : 'alternate' : reversed ? 'reverse' : 'normal';
210
+ /** @type {FillMode} */
211
+ const fill = 'forwards';
212
+ /** @type {String} */
213
+ const easing = parseWAAPIEasing(ease);
214
+ const timeScale = (globals.timeScale === 1 ? 1 : K);
215
+
216
+ /** @type {DOMTargetsArray}] */
217
+ this.targets = parsedTargets;
218
+ /** @type {Array<globalThis.Animation>}] */
219
+ this.animations = [];
220
+ /** @type {globalThis.Animation}] */
221
+ this.controlAnimation = null;
222
+ /** @type {Callback<this>} */
223
+ this.onComplete = params.onComplete || noop;
224
+ /** @type {Number} */
225
+ this.duration = 0;
226
+ /** @type {Boolean} */
227
+ this.muteCallbacks = false;
228
+ /** @type {Boolean} */
229
+ this.completed = false;
230
+ /** @type {Boolean} */
231
+ this.paused = !autoplay || scroll !== false;
232
+ /** @type {Boolean} */
233
+ this.reversed = reversed;
234
+ /** @type {Boolean|ScrollObserver} */
235
+ this.autoplay = autoplay;
236
+ /** @type {Number} */
237
+ this._speed = setValue(params.playbackRate, globals.defaults.playbackRate);
238
+ /** @type {Function} */
239
+ this._resolve = noop; // Used by .then()
240
+ /** @type {Number} */
241
+ this._completed = 0;
242
+ /** @type {Array<Object>}] */
243
+ this._inlineStyles = parsedTargets.map($el => $el.getAttribute('style'));
244
+
245
+ parsedTargets.forEach(($el, i) => {
246
+
247
+ const cachedTransforms = $el[transformsSymbol];
248
+
249
+ const hasIndividualTransforms = validIndividualTransforms.some(t => params.hasOwnProperty(t));
250
+
251
+ /** @type {Number} */
252
+ const duration = (spring ? /** @type {Spring} */(spring).duration : getFunctionValue(setValue(params.duration, globals.defaults.duration), $el, i, targetsLength)) * timeScale;
253
+ /** @type {Number} */
254
+ const delay = getFunctionValue(setValue(params.delay, globals.defaults.delay), $el, i, targetsLength) * timeScale;
255
+ /** @type {CompositeOperation} */
256
+ const composite = /** @type {CompositeOperation} */(setValue(params.composition, 'replace'));
257
+
258
+ for (let name in params) {
259
+ if (!isKey(name)) continue;
260
+ /** @type {PropertyIndexedKeyframes} */
261
+ const keyframes = {};
262
+ /** @type {KeyframeAnimationOptions} */
263
+ const tweenParams = { iterations, direction, fill, easing, duration, delay, composite };
264
+ const propertyValue = params[name];
265
+ const individualTransformProperty = hasIndividualTransforms ? validTransforms.includes(name) ? name : shortTransforms.get(name) : false;
266
+ let parsedPropertyValue;
267
+ if (isObj(propertyValue)) {
268
+ const tweenOptions = /** @type {WAAPITweenOptions} */(propertyValue);
269
+ const tweenOptionsEase = setValue(tweenOptions.ease, ease);
270
+ const tweenOptionsSpring = /** @type {Spring} */(tweenOptionsEase).ease && tweenOptionsEase;
271
+ const to = /** @type {WAAPITweenOptions} */(tweenOptions).to;
272
+ const from = /** @type {WAAPITweenOptions} */(tweenOptions).from;
273
+ /** @type {Number} */
274
+ tweenParams.duration = (tweenOptionsSpring ? /** @type {Spring} */(tweenOptionsSpring).duration : getFunctionValue(setValue(tweenOptions.duration, duration), $el, i, targetsLength)) * timeScale;
275
+ /** @type {Number} */
276
+ tweenParams.delay = getFunctionValue(setValue(tweenOptions.delay, delay), $el, i, targetsLength) * timeScale;
277
+ /** @type {CompositeOperation} */
278
+ tweenParams.composite = /** @type {CompositeOperation} */(setValue(tweenOptions.composition, composite));
279
+ /** @type {String} */
280
+ tweenParams.easing = parseWAAPIEasing(tweenOptionsEase);
281
+ parsedPropertyValue = parseIndividualTweenValue($el, name, from, to, i, targetsLength);
282
+ if (individualTransformProperty) {
283
+ keyframes[`--${individualTransformProperty}`] = parsedPropertyValue;
284
+ cachedTransforms[individualTransformProperty] = parsedPropertyValue;
285
+ } else {
286
+ keyframes[name] = parseIndividualTweenValue($el, name, from, to, i, targetsLength);
287
+ }
288
+ addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
289
+ if (!isUnd(from)) {
290
+ if (!individualTransformProperty) {
291
+ $el.style[name] = keyframes[name][0];
292
+ } else {
293
+ const key = `--${individualTransformProperty}`;
294
+ $el.style.setProperty(key, keyframes[key][0]);
295
+ }
296
+ }
297
+ } else {
298
+ parsedPropertyValue = isArr(propertyValue) ?
299
+ propertyValue.map((/** @type {any} */v) => normalizeTweenValue(name, v, $el, i, targetsLength)) :
300
+ normalizeTweenValue(name, /** @type {any} */(propertyValue), $el, i, targetsLength);
301
+ if (individualTransformProperty) {
302
+ keyframes[`--${individualTransformProperty}`] = parsedPropertyValue;
303
+ cachedTransforms[individualTransformProperty] = parsedPropertyValue;
304
+ } else {
305
+ keyframes[name] = parsedPropertyValue;
306
+ }
307
+ addWAAPIAnimation(this, $el, name, keyframes, tweenParams);
308
+ }
309
+ }
310
+ if (hasIndividualTransforms) {
311
+ let transforms = emptyString;
312
+ for (let t in cachedTransforms) {
313
+ transforms += `${transformsFragmentStrings[t]}var(--${t})) `;
314
+ }
315
+ $el.style.transform = transforms;
316
+ }
317
+ });
318
+
319
+ if (scroll) {
320
+ /** @type {ScrollObserver} */(this.autoplay).link(this);
321
+ }
322
+ }
323
+
324
+ /**
325
+ * @callback forEachCallback
326
+ * @param {globalThis.Animation} animation
327
+ */
328
+
329
+ /**
330
+ * @param {forEachCallback|String} callback
331
+ * @return {this}
332
+ */
333
+ forEach(callback) {
334
+ const cb = isStr(callback) ? (/** @type {globalThis.Animation} */a) => a[callback]() : callback;
335
+ this.animations.forEach(cb);
336
+ return this;
337
+ }
338
+
339
+ get speed() {
340
+ return this._speed;
341
+ }
342
+
343
+ set speed(speed) {
344
+ this._speed = +speed;
345
+ this.forEach(anim => anim.playbackRate = speed);
346
+ }
347
+
348
+ get currentTime() {
349
+ const controlAnimation = this.controlAnimation;
350
+ const timeScale = globals.timeScale;
351
+ return this.completed ? this.duration : controlAnimation ? +controlAnimation.currentTime * (timeScale === 1 ? 1 : timeScale) : 0;
352
+ }
353
+
354
+ set currentTime(time) {
355
+ const t = time * (globals.timeScale === 1 ? 1 : K);
356
+ this.forEach(anim => {
357
+ // Make sure the animation playState is not 'paused' in order to properly trigger an onfinish callback.
358
+ // The "paused" play state supersedes the "finished" play state; if the animation is both paused and finished, the "paused" state is the one that will be reported.
359
+ // https://developer.mozilla.org/en-US/docs/Web/API/Animation/finish_event
360
+ if (t >= this.duration) anim.play();
361
+ anim.currentTime = t;
362
+ });
363
+ }
364
+
365
+ get progress() {
366
+ return this.currentTime / this.duration;
367
+ }
368
+
369
+ set progress(progress) {
370
+ this.forEach(anim => anim.currentTime = progress * this.duration || 0);
371
+ }
372
+
373
+ resume() {
374
+ if (!this.paused) return this;
375
+ this.paused = false;
376
+ // TODO: Store the current time, and seek back to the last position
377
+ return this.forEach('play');
378
+ }
379
+
380
+ pause() {
381
+ if (this.paused) return this;
382
+ this.paused = true;
383
+ return this.forEach('pause');
384
+ }
385
+
386
+ alternate() {
387
+ this.reversed = !this.reversed;
388
+ this.forEach('reverse');
389
+ if (this.paused) this.forEach('pause');
390
+ return this;
391
+ }
392
+
393
+ play() {
394
+ if (this.reversed) this.alternate();
395
+ return this.resume();
396
+ }
397
+
398
+ reverse() {
399
+ if (!this.reversed) this.alternate();
400
+ return this.resume();
401
+ }
402
+
403
+ /**
404
+ * @param {Number} time
405
+ * @param {Boolean} muteCallbacks
406
+ */
407
+ seek(time, muteCallbacks = false) {
408
+ if (muteCallbacks) this.muteCallbacks = true;
409
+ if (time < this.duration) this.completed = false;
410
+ this.currentTime = time;
411
+ this.muteCallbacks = false;
412
+ if (this.paused) this.pause();
413
+ return this;
414
+ }
415
+
416
+ restart() {
417
+ this.completed = false;
418
+ return this.seek(0, true).resume();
419
+ }
420
+
421
+ commitStyles() {
422
+ return this.forEach('commitStyles');
423
+ }
424
+
425
+ complete() {
426
+ return this.seek(this.duration);
427
+ }
428
+
429
+ cancel() {
430
+ this.forEach('cancel');
431
+ return this.pause();
432
+ }
433
+
434
+ revert() {
435
+ this.cancel();
436
+ this.targets.forEach(($el, i) => $el.setAttribute('style', this._inlineStyles[i]) );
437
+ return this;
438
+ }
439
+
440
+ /**
441
+ * @param {WAAPICallback} [callback]
442
+ * @return {Promise}
443
+ */
444
+ then(callback = noop) {
445
+ const then = this.then;
446
+ const onResolve = () => {
447
+ this.then = null;
448
+ callback(this);
449
+ this.then = then;
450
+ this._resolve = noop;
451
+ };
452
+ return new Promise(r => {
453
+ this._resolve = () => r(onResolve());
454
+ if (this.completed) this._resolve();
455
+ return this;
456
+ });
457
+ }
458
+ }
459
+
460
+ const waapi = {
461
+ /**
462
+ * @param {DOMTargetsParam} targets
463
+ * @param {WAAPIAnimationParams} params
464
+ * @return {WAAPIAnimation}
465
+ */
466
+ animate: (targets, params) => new WAAPIAnimation(targets, params),
467
+ convertEase: easingToLinear
468
+ };
469
+
470
+ export { WAAPIAnimation, waapi };
package/package.json CHANGED
@@ -1,62 +1,159 @@
1
1
  {
2
2
  "name": "animejs",
3
- "version": "4.1.2",
3
+ "version": "4.2.0-beta.0",
4
+ "description": "JavaScript animation engine",
4
5
  "homepage": "https://animejs.com",
6
+ "author": "Julian Garnier <julian@animejs.com>",
7
+ "license": "MIT",
5
8
  "repository": {
6
9
  "type": "git",
7
10
  "url": "git+https://github.com/juliangarnier/anime.git"
8
11
  },
9
- "description": "JavaScript animation engine",
10
- "main": "lib/anime.umd.js",
11
- "module": "lib/anime.esm.js",
12
- "types": "types/index.d.ts",
13
- "type": "module",
14
- "exports": {
15
- ".": {
16
- "types": "./types/index.d.ts",
17
- "import": "./lib/anime.esm.js",
18
- "require": "./lib/anime.cjs"
19
- },
20
- "./package.json": "./package.json"
21
- },
22
- "license": "MIT",
23
- "author": "Julian Garnier <hello@julian.gr>",
24
- "sideEffects": false,
25
12
  "bugs": {
26
13
  "url": "https://github.com/juliangarnier/anime/issues"
27
14
  },
28
- "files": [
29
- "lib",
30
- "types"
31
- ],
15
+ "funding": {
16
+ "type": "github",
17
+ "url": "https://github.com/sponsors/juliangarnier"
18
+ },
32
19
  "keywords": [
33
20
  "anime",
21
+ "animejs",
34
22
  "anime.js",
35
23
  "animation",
24
+ "timeline",
25
+ "easings",
26
+ "spring",
27
+ "scroll",
28
+ "drag",
29
+ "text",
36
30
  "JavaScript",
37
31
  "CSS",
38
- "transforms",
39
32
  "SVG",
40
- "canvas"
33
+ "WAAPI",
34
+ "Canvas",
35
+ "WebGL"
41
36
  ],
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "sideEffects": false,
41
+ "type": "module",
42
+ "main": "./dist/modules/index.cjs",
43
+ "module": "./dist/modules/index.js",
44
+ "types": "./dist/modules/index.d.ts",
45
+ "jsdelivr": "./dist/bundles/anime.umd.min.js",
46
+ "unpkg": "./dist/bundles/anime.umd.min.js",
47
+ "exports": {
48
+ "./package.json": "./package.json",
49
+ ".": {
50
+ "types": "./dist/modules/index.d.ts",
51
+ "require": "./dist/modules/index.cjs",
52
+ "import": "./dist/modules/index.js",
53
+ "default": "./dist/modules/index.cjs"
54
+ },
55
+ "./timer": {
56
+ "types": "./dist/modules/timer/index.d.ts",
57
+ "require": "./dist/modules/timer/index.cjs",
58
+ "import": "./dist/modules/timer/index.js",
59
+ "default": "./dist/modules/timer/index.cjs"
60
+ },
61
+ "./animation": {
62
+ "types": "./dist/modules/animation/index.d.ts",
63
+ "require": "./dist/modules/animation/index.cjs",
64
+ "import": "./dist/modules/animation/index.js",
65
+ "default": "./dist/modules/animation/index.cjs"
66
+ },
67
+ "./timeline": {
68
+ "types": "./dist/modules/timeline/index.d.ts",
69
+ "require": "./dist/modules/timeline/index.cjs",
70
+ "import": "./dist/modules/timeline/index.js",
71
+ "default": "./dist/modules/timeline/index.cjs"
72
+ },
73
+ "./animatable": {
74
+ "types": "./dist/modules/animatable/index.d.ts",
75
+ "require": "./dist/modules/animatable/index.cjs",
76
+ "import": "./dist/modules/animatable/index.js",
77
+ "default": "./dist/modules/animatable/index.cjs"
78
+ },
79
+ "./draggable": {
80
+ "types": "./dist/modules/draggable/index.d.ts",
81
+ "require": "./dist/modules/draggable/index.cjs",
82
+ "import": "./dist/modules/draggable/index.js",
83
+ "default": "./dist/modules/draggable/index.cjs"
84
+ },
85
+ "./scope": {
86
+ "types": "./dist/modules/scope/index.d.ts",
87
+ "require": "./dist/modules/scope/index.cjs",
88
+ "import": "./dist/modules/scope/index.js",
89
+ "default": "./dist/modules/scope/index.cjs"
90
+ },
91
+ "./engine": {
92
+ "types": "./dist/modules/engine/index.d.ts",
93
+ "require": "./dist/modules/engine/index.cjs",
94
+ "import": "./dist/modules/engine/index.js",
95
+ "default": "./dist/modules/engine/index.cjs"
96
+ },
97
+ "./events": {
98
+ "types": "./dist/modules/events/index.d.ts",
99
+ "require": "./dist/modules/events/index.cjs",
100
+ "import": "./dist/modules/events/index.js",
101
+ "default": "./dist/modules/events/index.cjs"
102
+ },
103
+ "./spring": {
104
+ "types": "./dist/modules/spring/index.d.ts",
105
+ "require": "./dist/modules/spring/index.cjs",
106
+ "import": "./dist/modules/spring/index.js",
107
+ "default": "./dist/modules/spring/index.cjs"
108
+ },
109
+ "./easings": {
110
+ "types": "./dist/modules/easings/index.d.ts",
111
+ "require": "./dist/modules/easings/index.cjs",
112
+ "import": "./dist/modules/easings/index.js",
113
+ "default": "./dist/modules/easings/index.cjs"
114
+ },
115
+ "./utils": {
116
+ "types": "./dist/modules/utils/index.d.ts",
117
+ "require": "./dist/modules/utils/index.cjs",
118
+ "import": "./dist/modules/utils/index.js",
119
+ "default": "./dist/modules/utils/index.cjs"
120
+ },
121
+ "./svg": {
122
+ "types": "./dist/modules/svg/index.d.ts",
123
+ "require": "./dist/modules/svg/index.cjs",
124
+ "import": "./dist/modules/svg/index.js",
125
+ "default": "./dist/modules/svg/index.cjs"
126
+ },
127
+ "./text": {
128
+ "types": "./dist/modules/text/index.d.ts",
129
+ "require": "./dist/modules/text/index.cjs",
130
+ "import": "./dist/modules/text/index.js",
131
+ "default": "./dist/modules/text/index.cjs"
132
+ },
133
+ "./waapi": {
134
+ "types": "./dist/modules/waapi/index.d.ts",
135
+ "require": "./dist/modules/waapi/index.cjs",
136
+ "import": "./dist/modules/waapi/index.js",
137
+ "default": "./dist/modules/waapi/index.cjs"
138
+ }
139
+ },
42
140
  "devDependencies": {
43
141
  "@rollup/plugin-terser": "^0.4.4",
142
+ "@types/node": "^24.3.0",
44
143
  "browser-sync": "^2.29.3",
45
144
  "chai": "^4.3.10",
46
145
  "mocha": "^10.2.0",
146
+ "nodemon": "^3.1.10",
47
147
  "rollup": "^4.9.1",
48
- "rollup-plugin-filesize": "^10.0.0",
49
- "rollup-plugin-ts": "^3.4.5",
50
148
  "three": "^0.160.0",
51
- "typescript": "5.1.6"
149
+ "typescript": "^5.9.2"
52
150
  },
53
151
  "scripts": {
54
- "dev": "rollup -c -w",
55
- "dev-types": "types=true rollup -c -w",
56
- "build": "build=true types=true rollup -c",
57
- "release": "build=true release=true types=true rollup -c",
58
- "open-examples": "browser-sync start --startPath examples --server --no-notify --directory --files '**/*.js'",
59
- "test-browser": "browser-sync start --startPath tests/index.html --server --files '**/*.js' --no-notify --directory",
60
- "test-node": "node --allow-natives-syntax \"node_modules/.bin/mocha\" -u tdd --timeout 20000 \"./tests/suites/node.test.js\""
152
+ "dev": "nodemon --quiet --watch src --ext js --exec \"rollup -c && tsc -p tsconfig.types.json && echo '\\n\\033[32m✓ modules and types compiled\\n\\033[36m⊙ watching for changes...\\n\\033[0m'\"",
153
+ "dev:test": "npm run dev & npm run test:browser",
154
+ "build": "rm -rf dist && build=true rollup -c && tsc -p tsconfig.types.json && echo '\\n\\033[32m✓ build completed\\n\\033[0m'",
155
+ "test:browser": "browser-sync start --startPath tests/index.html --server --files 'dist/modules/**/*.js' 'tests/suites/**/*.js' --no-notify --directory",
156
+ "test:node": "node --allow-natives-syntax \"node_modules/.bin/mocha\" -u tdd --timeout 20000 \"./tests/suites/node.test.js\"",
157
+ "open:examples": "browser-sync start --startPath examples --server --no-notify --directory --files '**/*.js'"
61
158
  }
62
159
  }