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,377 @@
1
+ /**
2
+ * Anime.js - animation - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ import { minValue, compositionTypes, tweenTypes } from '../core/consts.js';
9
+ import { forEachChildren, removeChild, isUnd, addChild, round, cloneArray } from '../core/helpers.js';
10
+ import { sanitizePropertyName } from '../core/styles.js';
11
+ import { engine } from '../engine/engine.js';
12
+ import { addAdditiveAnimation, additive } from './additive.js';
13
+
14
+ /**
15
+ * @import {
16
+ * TweenReplaceLookups,
17
+ * TweenAdditiveLookups,
18
+ * TweenPropertySiblings,
19
+ * Tween,
20
+ * Target,
21
+ * TargetsArray,
22
+ * Renderable,
23
+ * } from '../types/index.js'
24
+ *
25
+ * @import {
26
+ * JSAnimation,
27
+ * } from '../animation/animation.js'
28
+ */
29
+
30
+ const lookups = {
31
+ /** @type {TweenReplaceLookups} */
32
+ _rep: new WeakMap(),
33
+ /** @type {TweenAdditiveLookups} */
34
+ _add: new Map(),
35
+ };
36
+
37
+ /**
38
+ * @param {Target} target
39
+ * @param {String} property
40
+ * @param {String} lookup
41
+ * @return {TweenPropertySiblings}
42
+ */
43
+ const getTweenSiblings = (target, property, lookup = '_rep') => {
44
+ const lookupMap = lookups[lookup];
45
+ let targetLookup = lookupMap.get(target);
46
+ if (!targetLookup) {
47
+ targetLookup = {};
48
+ lookupMap.set(target, targetLookup);
49
+ }
50
+ return targetLookup[property] ? targetLookup[property] : targetLookup[property] = {
51
+ _head: null,
52
+ _tail: null,
53
+ }
54
+ };
55
+
56
+ /**
57
+ * @param {Tween} p
58
+ * @param {Tween} c
59
+ * @return {Number|Boolean}
60
+ */
61
+ const addTweenSortMethod = (p, c) => {
62
+ return p._isOverridden || p._absoluteStartTime > c._absoluteStartTime;
63
+ };
64
+
65
+ /**
66
+ * @param {Tween} tween
67
+ */
68
+ const overrideTween = tween => {
69
+ tween._isOverlapped = 1;
70
+ tween._isOverridden = 1;
71
+ tween._changeDuration = minValue;
72
+ tween._currentTime = minValue;
73
+ };
74
+
75
+ /**
76
+ * @param {Tween} tween
77
+ * @param {TweenPropertySiblings} siblings
78
+ * @return {Tween}
79
+ */
80
+ const composeTween = (tween, siblings) => {
81
+
82
+ const tweenCompositionType = tween._composition;
83
+
84
+ // Handle replaced tweens
85
+
86
+ if (tweenCompositionType === compositionTypes.replace) {
87
+
88
+ const tweenAbsStartTime = tween._absoluteStartTime;
89
+
90
+ addChild(siblings, tween, addTweenSortMethod, '_prevRep', '_nextRep');
91
+
92
+ const prevSibling = tween._prevRep;
93
+
94
+ // Update the previous siblings for composition replace tweens
95
+
96
+ if (prevSibling) {
97
+
98
+ const prevParent = prevSibling.parent;
99
+ const prevAbsEndTime = prevSibling._absoluteStartTime + prevSibling._changeDuration;
100
+
101
+ // Handle looped animations tween
102
+
103
+ if (
104
+ // Check if the previous tween is from a different animation
105
+ tween.parent.id !== prevParent.id &&
106
+ // Check if the animation has loops
107
+ prevParent.iterationCount> 1 &&
108
+ // Check if _absoluteChangeEndTime of last loop overlaps the current tween
109
+ prevAbsEndTime + (prevParent.duration - prevParent.iterationDuration) > tweenAbsStartTime
110
+ ) {
111
+
112
+ // TODO: Find a way to only override the iterations overlapping with the tween
113
+ overrideTween(prevSibling);
114
+
115
+ let prevPrevSibling = prevSibling._prevRep;
116
+
117
+ // If the tween was part of a set of keyframes, override its siblings
118
+ while (prevPrevSibling && prevPrevSibling.parent.id === prevParent.id) {
119
+ overrideTween(prevPrevSibling);
120
+ prevPrevSibling = prevPrevSibling._prevRep;
121
+ }
122
+
123
+ }
124
+
125
+ const absoluteUpdateStartTime = tweenAbsStartTime - tween._delay;
126
+
127
+ if (prevAbsEndTime > absoluteUpdateStartTime) {
128
+
129
+ const prevChangeStartTime = prevSibling._startTime;
130
+ const prevTLOffset = prevAbsEndTime - (prevChangeStartTime + prevSibling._updateDuration);
131
+ // Rounding is necessary here to minimize floating point errors when working in seconds
132
+ const updatedPrevChangeDuration = round(absoluteUpdateStartTime - prevTLOffset - prevChangeStartTime, 12);
133
+
134
+ prevSibling._changeDuration = updatedPrevChangeDuration;
135
+ prevSibling._currentTime = updatedPrevChangeDuration;
136
+ prevSibling._isOverlapped = 1;
137
+
138
+ // Override the previous tween if its new _changeDuration is lower than minValue
139
+ // TODO: See if it's even neceseeary to test against minValue, checking for 0 might be enough
140
+ if (updatedPrevChangeDuration < minValue) {
141
+ overrideTween(prevSibling);
142
+ }
143
+ }
144
+
145
+ // Pause (and cancel) the parent if it only contains overlapped tweens
146
+
147
+ let pausePrevParentAnimation = true;
148
+
149
+ forEachChildren(prevParent, (/** @type Tween */t) => {
150
+ if (!t._isOverlapped) pausePrevParentAnimation = false;
151
+ });
152
+
153
+ if (pausePrevParentAnimation) {
154
+ const prevParentTL = prevParent.parent;
155
+ if (prevParentTL) {
156
+ let pausePrevParentTL = true;
157
+ forEachChildren(prevParentTL, (/** @type JSAnimation */a) => {
158
+ if (a !== prevParent) {
159
+ forEachChildren(a, (/** @type Tween */t) => {
160
+ if (!t._isOverlapped) pausePrevParentTL = false;
161
+ });
162
+ }
163
+ });
164
+ if (pausePrevParentTL) {
165
+ prevParentTL.cancel();
166
+ }
167
+ } else {
168
+ prevParent.cancel();
169
+ // Previously, calling .cancel() on a timeline child would affect the render order of other children
170
+ // Worked around this by marking it as .completed and using .pause() for safe removal in the engine loop
171
+ // This is no longer needed since timeline tween composition is now handled separately
172
+ // Keeping this here for reference
173
+ // prevParent.completed = true;
174
+ // prevParent.pause();
175
+ }
176
+ }
177
+
178
+ }
179
+
180
+ // let nextSibling = tween._nextRep;
181
+
182
+ // // All the next siblings are automatically overridden
183
+
184
+ // if (nextSibling && nextSibling._absoluteStartTime >= tweenAbsStartTime) {
185
+ // while (nextSibling) {
186
+ // overrideTween(nextSibling);
187
+ // nextSibling = nextSibling._nextRep;
188
+ // }
189
+ // }
190
+
191
+ // if (nextSibling && nextSibling._absoluteStartTime < tweenAbsStartTime) {
192
+ // while (nextSibling) {
193
+ // overrideTween(nextSibling);
194
+ // console.log(tween.id, nextSibling.id);
195
+ // nextSibling = nextSibling._nextRep;
196
+ // }
197
+ // }
198
+
199
+ // Handle additive tweens composition
200
+
201
+ } else if (tweenCompositionType === compositionTypes.blend) {
202
+
203
+ const additiveTweenSiblings = getTweenSiblings(tween.target, tween.property, '_add');
204
+ const additiveAnimation = addAdditiveAnimation(lookups._add);
205
+
206
+ let lookupTween = additiveTweenSiblings._head;
207
+
208
+ if (!lookupTween) {
209
+ lookupTween = { ...tween };
210
+ lookupTween._composition = compositionTypes.replace;
211
+ lookupTween._updateDuration = minValue;
212
+ lookupTween._startTime = 0;
213
+ lookupTween._numbers = cloneArray(tween._fromNumbers);
214
+ lookupTween._number = 0;
215
+ lookupTween._next = null;
216
+ lookupTween._prev = null;
217
+ addChild(additiveTweenSiblings, lookupTween);
218
+ addChild(additiveAnimation, lookupTween);
219
+ }
220
+
221
+ // Convert the values of TO to FROM and set TO to 0
222
+
223
+ const toNumber = tween._toNumber;
224
+ tween._fromNumber = lookupTween._fromNumber - toNumber;
225
+ tween._toNumber = 0;
226
+ tween._numbers = cloneArray(tween._fromNumbers);
227
+ tween._number = 0;
228
+ lookupTween._fromNumber = toNumber;
229
+
230
+ if (tween._toNumbers) {
231
+ const toNumbers = cloneArray(tween._toNumbers);
232
+ if (toNumbers) {
233
+ toNumbers.forEach((value, i) => {
234
+ tween._fromNumbers[i] = lookupTween._fromNumbers[i] - value;
235
+ tween._toNumbers[i] = 0;
236
+ });
237
+ }
238
+ lookupTween._fromNumbers = toNumbers;
239
+ }
240
+
241
+ addChild(additiveTweenSiblings, tween, null, '_prevAdd', '_nextAdd');
242
+
243
+ }
244
+
245
+ return tween;
246
+
247
+ };
248
+
249
+ /**
250
+ * @param {Tween} tween
251
+ * @return {Tween}
252
+ */
253
+ const removeTweenSliblings = tween => {
254
+ const tweenComposition = tween._composition;
255
+ if (tweenComposition !== compositionTypes.none) {
256
+ const tweenTarget = tween.target;
257
+ const tweenProperty = tween.property;
258
+ const replaceTweensLookup = lookups._rep;
259
+ const replaceTargetProps = replaceTweensLookup.get(tweenTarget);
260
+ const tweenReplaceSiblings = replaceTargetProps[tweenProperty];
261
+ removeChild(tweenReplaceSiblings, tween, '_prevRep', '_nextRep');
262
+ if (tweenComposition === compositionTypes.blend) {
263
+ const addTweensLookup = lookups._add;
264
+ const addTargetProps = addTweensLookup.get(tweenTarget);
265
+ if (!addTargetProps) return;
266
+ const additiveTweenSiblings = addTargetProps[tweenProperty];
267
+ const additiveAnimation = additive.animation;
268
+ removeChild(additiveTweenSiblings, tween, '_prevAdd', '_nextAdd');
269
+ // If only one tween is left in the additive lookup, it's the tween lookup
270
+ const lookupTween = additiveTweenSiblings._head;
271
+ if (lookupTween && lookupTween === additiveTweenSiblings._tail) {
272
+ removeChild(additiveTweenSiblings, lookupTween, '_prevAdd', '_nextAdd');
273
+ removeChild(additiveAnimation, lookupTween);
274
+ let shouldClean = true;
275
+ for (let prop in addTargetProps) {
276
+ if (addTargetProps[prop]._head) {
277
+ shouldClean = false;
278
+ break;
279
+ }
280
+ }
281
+ if (shouldClean) {
282
+ addTweensLookup.delete(tweenTarget);
283
+ }
284
+ }
285
+ }
286
+ }
287
+ return tween;
288
+ };
289
+
290
+ /**
291
+ * @param {TargetsArray} targetsArray
292
+ * @param {JSAnimation} animation
293
+ * @param {String} [propertyName]
294
+ * @return {Boolean}
295
+ */
296
+ const removeTargetsFromJSAnimation = (targetsArray, animation, propertyName) => {
297
+ let tweensMatchesTargets = false;
298
+ forEachChildren(animation, (/**@type {Tween} */tween) => {
299
+ const tweenTarget = tween.target;
300
+ if (targetsArray.includes(tweenTarget)) {
301
+ const tweenName = tween.property;
302
+ const tweenType = tween._tweenType;
303
+ const normalizePropName = sanitizePropertyName(propertyName, tweenTarget, tweenType);
304
+ if (!normalizePropName || normalizePropName && normalizePropName === tweenName) {
305
+ // Make sure to flag the previous CSS transform tween to renderTransform
306
+ if (tween.parent._tail === tween &&
307
+ tween._tweenType === tweenTypes.TRANSFORM &&
308
+ tween._prev &&
309
+ tween._prev._tweenType === tweenTypes.TRANSFORM
310
+ ) {
311
+ tween._prev._renderTransforms = 1;
312
+ }
313
+ // Removes the tween from the selected animation
314
+ removeChild(animation, tween);
315
+ // Detach the tween from its siblings to make sure blended tweens are correctlly removed
316
+ removeTweenSliblings(tween);
317
+ tweensMatchesTargets = true;
318
+ }
319
+ }
320
+ }, true);
321
+ return tweensMatchesTargets;
322
+ };
323
+
324
+ /**
325
+ * @param {TargetsArray} targetsArray
326
+ * @param {Renderable} [renderable]
327
+ * @param {String} [propertyName]
328
+ */
329
+ const removeTargetsFromRenderable = (targetsArray, renderable, propertyName) => {
330
+ const parent = /** @type {Renderable|typeof engine} **/(renderable ? renderable : engine);
331
+ let removeMatches;
332
+ if (parent._hasChildren) {
333
+ let iterationDuration = 0;
334
+ forEachChildren(parent, (/** @type {Renderable} */child) => {
335
+ if (!child._hasChildren) {
336
+ removeMatches = removeTargetsFromJSAnimation(targetsArray, /** @type {JSAnimation} */(child), propertyName);
337
+ // Remove the child from its parent if no tweens and no children left after the removal
338
+ if (removeMatches && !child._head) {
339
+ child.cancel();
340
+ removeChild(parent, child);
341
+ } else {
342
+ // Calculate the new iterationDuration value to handle onComplete with last child in render()
343
+ const childTLOffset = child._offset + child._delay;
344
+ const childDur = childTLOffset + child.duration;
345
+ if (childDur > iterationDuration) {
346
+ iterationDuration = childDur;
347
+ }
348
+ }
349
+ }
350
+ // Make sure to also remove engine's children targets
351
+ // NOTE: Avoid recursion?
352
+ if (child._head) {
353
+ removeTargetsFromRenderable(targetsArray, child, propertyName);
354
+ } else {
355
+ child._hasChildren = false;
356
+ }
357
+ }, true);
358
+ // Update iterationDuration value to handle onComplete with last child in render()
359
+ if (!isUnd(/** @type {Renderable} */(parent).iterationDuration)) {
360
+ /** @type {Renderable} */(parent).iterationDuration = iterationDuration;
361
+ }
362
+ } else {
363
+ removeMatches = removeTargetsFromJSAnimation(
364
+ targetsArray,
365
+ /** @type {JSAnimation} */(parent),
366
+ propertyName
367
+ );
368
+ }
369
+ if (removeMatches && !parent._head) {
370
+ parent._hasChildren = false;
371
+ // Cancel the parent if there are no tweens and no children left after the removal
372
+ // We have to check if the .cancel() method exist to handle cases where the parent is the engine itself
373
+ if (/** @type {Renderable} */(parent).cancel) /** @type {Renderable} */(parent).cancel();
374
+ }
375
+ };
376
+
377
+ export { composeTween, getTweenSiblings, overrideTween, removeTargetsFromRenderable, removeTweenSliblings };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Anime.js - animation - CJS
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var animation = require('./animation.cjs');
11
+
12
+
13
+
14
+ exports.JSAnimation = animation.JSAnimation;
15
+ exports.animate = animation.animate;
@@ -0,0 +1 @@
1
+ export * from "./animation.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Anime.js - animation - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ export { JSAnimation, animate } from './animation.js';
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Anime.js - core - CJS
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var consts = require('./consts.cjs');
11
+ var helpers = require('./helpers.cjs');
12
+
13
+ /**
14
+ * @import {
15
+ * Tickable,
16
+ * Tween,
17
+ * } from '../types/index.js'
18
+ */
19
+
20
+ /*
21
+ * Base class to control framerate and playback rate.
22
+ * Inherited by Engine, Timer, Animation and Timeline.
23
+ */
24
+ class Clock {
25
+
26
+ /** @param {Number} [initTime] */
27
+ constructor(initTime = 0) {
28
+ /** @type {Number} */
29
+ this.deltaTime = 0;
30
+ /** @type {Number} */
31
+ this._currentTime = initTime;
32
+ /** @type {Number} */
33
+ this._elapsedTime = initTime;
34
+ /** @type {Number} */
35
+ this._startTime = initTime;
36
+ /** @type {Number} */
37
+ this._lastTime = initTime;
38
+ /** @type {Number} */
39
+ this._scheduledTime = 0;
40
+ /** @type {Number} */
41
+ this._frameDuration = helpers.round(consts.K / consts.maxFps, 0);
42
+ /** @type {Number} */
43
+ this._fps = consts.maxFps;
44
+ /** @type {Number} */
45
+ this._speed = 1;
46
+ /** @type {Boolean} */
47
+ this._hasChildren = false;
48
+ /** @type {Tickable|Tween} */
49
+ this._head = null;
50
+ /** @type {Tickable|Tween} */
51
+ this._tail = null;
52
+ }
53
+
54
+ get fps() {
55
+ return this._fps;
56
+ }
57
+
58
+ set fps(frameRate) {
59
+ const previousFrameDuration = this._frameDuration;
60
+ const fr = +frameRate;
61
+ const fps = fr < consts.minValue ? consts.minValue : fr;
62
+ const frameDuration = helpers.round(consts.K / fps, 0);
63
+ this._fps = fps;
64
+ this._frameDuration = frameDuration;
65
+ this._scheduledTime += frameDuration - previousFrameDuration;
66
+ }
67
+
68
+ get speed() {
69
+ return this._speed;
70
+ }
71
+
72
+ set speed(playbackRate) {
73
+ const pbr = +playbackRate;
74
+ this._speed = pbr < consts.minValue ? consts.minValue : pbr;
75
+ }
76
+
77
+ /**
78
+ * @param {Number} time
79
+ * @return {tickModes}
80
+ */
81
+ requestTick(time) {
82
+ const scheduledTime = this._scheduledTime;
83
+ const elapsedTime = this._elapsedTime;
84
+ this._elapsedTime += (time - elapsedTime);
85
+ // If the elapsed time is lower than the scheduled time
86
+ // this means not enough time has passed to hit one frameDuration
87
+ // so skip that frame
88
+ if (elapsedTime < scheduledTime) return consts.tickModes.NONE;
89
+ const frameDuration = this._frameDuration;
90
+ const frameDelta = elapsedTime - scheduledTime;
91
+ // Ensures that _scheduledTime progresses in steps of at least 1 frameDuration.
92
+ // Skips ahead if the actual elapsed time is higher.
93
+ this._scheduledTime += frameDelta < frameDuration ? frameDuration : frameDelta;
94
+ return consts.tickModes.AUTO;
95
+ }
96
+
97
+ /**
98
+ * @param {Number} time
99
+ * @return {Number}
100
+ */
101
+ computeDeltaTime(time) {
102
+ const delta = time - this._lastTime;
103
+ this.deltaTime = delta;
104
+ this._lastTime = time;
105
+ return delta;
106
+ }
107
+
108
+ }
109
+
110
+ exports.Clock = Clock;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @import {
3
+ * Tickable,
4
+ * Tween,
5
+ * } from '../types/index.js'
6
+ */
7
+ export class Clock {
8
+ /** @param {Number} [initTime] */
9
+ constructor(initTime?: number);
10
+ /** @type {Number} */
11
+ deltaTime: number;
12
+ /** @type {Number} */
13
+ _currentTime: number;
14
+ /** @type {Number} */
15
+ _elapsedTime: number;
16
+ /** @type {Number} */
17
+ _startTime: number;
18
+ /** @type {Number} */
19
+ _lastTime: number;
20
+ /** @type {Number} */
21
+ _scheduledTime: number;
22
+ /** @type {Number} */
23
+ _frameDuration: number;
24
+ /** @type {Number} */
25
+ _fps: number;
26
+ /** @type {Number} */
27
+ _speed: number;
28
+ /** @type {Boolean} */
29
+ _hasChildren: boolean;
30
+ /** @type {Tickable|Tween} */
31
+ _head: Tickable | Tween;
32
+ /** @type {Tickable|Tween} */
33
+ _tail: Tickable | Tween;
34
+ set fps(frameRate: number);
35
+ get fps(): number;
36
+ set speed(playbackRate: number);
37
+ get speed(): number;
38
+ /**
39
+ * @param {Number} time
40
+ * @return {tickModes}
41
+ */
42
+ requestTick(time: number): tickModes;
43
+ /**
44
+ * @param {Number} time
45
+ * @return {Number}
46
+ */
47
+ computeDeltaTime(time: number): number;
48
+ }
49
+ import type { Tickable } from '../types/index.js';
50
+ import type { Tween } from '../types/index.js';
51
+ import { tickModes } from './consts.js';
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Anime.js - core - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ import { K, maxFps, minValue, tickModes } from './consts.js';
9
+ import { round } from './helpers.js';
10
+
11
+ /**
12
+ * @import {
13
+ * Tickable,
14
+ * Tween,
15
+ * } from '../types/index.js'
16
+ */
17
+
18
+ /*
19
+ * Base class to control framerate and playback rate.
20
+ * Inherited by Engine, Timer, Animation and Timeline.
21
+ */
22
+ class Clock {
23
+
24
+ /** @param {Number} [initTime] */
25
+ constructor(initTime = 0) {
26
+ /** @type {Number} */
27
+ this.deltaTime = 0;
28
+ /** @type {Number} */
29
+ this._currentTime = initTime;
30
+ /** @type {Number} */
31
+ this._elapsedTime = initTime;
32
+ /** @type {Number} */
33
+ this._startTime = initTime;
34
+ /** @type {Number} */
35
+ this._lastTime = initTime;
36
+ /** @type {Number} */
37
+ this._scheduledTime = 0;
38
+ /** @type {Number} */
39
+ this._frameDuration = round(K / maxFps, 0);
40
+ /** @type {Number} */
41
+ this._fps = maxFps;
42
+ /** @type {Number} */
43
+ this._speed = 1;
44
+ /** @type {Boolean} */
45
+ this._hasChildren = false;
46
+ /** @type {Tickable|Tween} */
47
+ this._head = null;
48
+ /** @type {Tickable|Tween} */
49
+ this._tail = null;
50
+ }
51
+
52
+ get fps() {
53
+ return this._fps;
54
+ }
55
+
56
+ set fps(frameRate) {
57
+ const previousFrameDuration = this._frameDuration;
58
+ const fr = +frameRate;
59
+ const fps = fr < minValue ? minValue : fr;
60
+ const frameDuration = round(K / fps, 0);
61
+ this._fps = fps;
62
+ this._frameDuration = frameDuration;
63
+ this._scheduledTime += frameDuration - previousFrameDuration;
64
+ }
65
+
66
+ get speed() {
67
+ return this._speed;
68
+ }
69
+
70
+ set speed(playbackRate) {
71
+ const pbr = +playbackRate;
72
+ this._speed = pbr < minValue ? minValue : pbr;
73
+ }
74
+
75
+ /**
76
+ * @param {Number} time
77
+ * @return {tickModes}
78
+ */
79
+ requestTick(time) {
80
+ const scheduledTime = this._scheduledTime;
81
+ const elapsedTime = this._elapsedTime;
82
+ this._elapsedTime += (time - elapsedTime);
83
+ // If the elapsed time is lower than the scheduled time
84
+ // this means not enough time has passed to hit one frameDuration
85
+ // so skip that frame
86
+ if (elapsedTime < scheduledTime) return tickModes.NONE;
87
+ const frameDuration = this._frameDuration;
88
+ const frameDelta = elapsedTime - scheduledTime;
89
+ // Ensures that _scheduledTime progresses in steps of at least 1 frameDuration.
90
+ // Skips ahead if the actual elapsed time is higher.
91
+ this._scheduledTime += frameDelta < frameDuration ? frameDuration : frameDelta;
92
+ return tickModes.AUTO;
93
+ }
94
+
95
+ /**
96
+ * @param {Number} time
97
+ * @return {Number}
98
+ */
99
+ computeDeltaTime(time) {
100
+ const delta = time - this._lastTime;
101
+ this.deltaTime = delta;
102
+ this._lastTime = time;
103
+ return delta;
104
+ }
105
+
106
+ }
107
+
108
+ export { Clock };