animejs 4.1.3 → 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 +12 -8
  2. package/{lib → dist/bundles}/anime.esm.js +5237 -5049
  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 -1126
  191. package/types/index.js +0 -7388
@@ -0,0 +1,660 @@
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 consts = require('../core/consts.cjs');
11
+ var helpers = require('../core/helpers.cjs');
12
+ var globals = require('../core/globals.cjs');
13
+ var targets = require('../core/targets.cjs');
14
+ var values = require('../core/values.cjs');
15
+ var styles = require('../core/styles.cjs');
16
+ var units = require('../core/units.cjs');
17
+ var eases = require('../easings/eases.cjs');
18
+ var timer = require('../timer/timer.cjs');
19
+ var composition = require('./composition.cjs');
20
+ var additive = require('./additive.cjs');
21
+
22
+ /**
23
+ * @import {
24
+ * Tween,
25
+ * TweenKeyValue,
26
+ * TweenParamsOptions,
27
+ * TweenValues,
28
+ * DurationKeyframes,
29
+ * PercentageKeyframes,
30
+ * AnimationParams,
31
+ * TweenPropValue,
32
+ * ArraySyntaxValue,
33
+ * TargetsParam,
34
+ * TimerParams,
35
+ * TweenParamValue,
36
+ * DOMTarget,
37
+ * TargetsArray,
38
+ * Callback,
39
+ * EasingFunction,
40
+ * } from '../types/index.js'
41
+ *
42
+ * @import {
43
+ * Timeline,
44
+ * } from '../timeline/timeline.js'
45
+ *
46
+ * @import {
47
+ * Spring,
48
+ * } from '../spring/spring.js'
49
+ */
50
+
51
+ // Defines decomposed values target objects only once and mutate their properties later to avoid GC
52
+ // TODO: Maybe move the objects creation to values.js and use the decompose function to create the base object
53
+ const fromTargetObject = values.createDecomposedValueTargetObject();
54
+ const toTargetObject = values.createDecomposedValueTargetObject();
55
+ const toFunctionStore = { func: null };
56
+ const keyframesTargetArray = [null];
57
+ const fastSetValuesArray = [null, null];
58
+ /** @type {TweenKeyValue} */
59
+ const keyObjectTarget = { to: null };
60
+
61
+ let tweenId = 0;
62
+ let keyframes;
63
+ /** @type {TweenParamsOptions & TweenValues} */
64
+ let key;
65
+
66
+ /**
67
+ * @param {DurationKeyframes | PercentageKeyframes} keyframes
68
+ * @param {AnimationParams} parameters
69
+ * @return {AnimationParams}
70
+ */
71
+ const generateKeyframes = (keyframes, parameters) => {
72
+ /** @type {AnimationParams} */
73
+ const properties = {};
74
+ if (helpers.isArr(keyframes)) {
75
+ const propertyNames = [].concat(.../** @type {DurationKeyframes} */(keyframes).map(key => Object.keys(key))).filter(helpers.isKey);
76
+ for (let i = 0, l = propertyNames.length; i < l; i++) {
77
+ const propName = propertyNames[i];
78
+ const propArray = /** @type {DurationKeyframes} */(keyframes).map(key => {
79
+ /** @type {TweenKeyValue} */
80
+ const newKey = {};
81
+ for (let p in key) {
82
+ const keyValue = /** @type {TweenPropValue} */(key[p]);
83
+ if (helpers.isKey(p)) {
84
+ if (p === propName) {
85
+ newKey.to = keyValue;
86
+ }
87
+ } else {
88
+ newKey[p] = keyValue;
89
+ }
90
+ }
91
+ return newKey;
92
+ });
93
+ properties[propName] = /** @type {ArraySyntaxValue} */(propArray);
94
+ }
95
+
96
+ } else {
97
+ const totalDuration = /** @type {Number} */(values.setValue(parameters.duration, globals.globals.defaults.duration));
98
+ const keys = Object.keys(keyframes)
99
+ .map(key => { return {o: parseFloat(key) / 100, p: keyframes[key]} })
100
+ .sort((a, b) => a.o - b.o);
101
+ keys.forEach(key => {
102
+ const offset = key.o;
103
+ const prop = key.p;
104
+ for (let name in prop) {
105
+ if (helpers.isKey(name)) {
106
+ let propArray = /** @type {Array} */(properties[name]);
107
+ if (!propArray) propArray = properties[name] = [];
108
+ const duration = offset * totalDuration;
109
+ let length = propArray.length;
110
+ let prevKey = propArray[length - 1];
111
+ const keyObj = { to: prop[name] };
112
+ let durProgress = 0;
113
+ for (let i = 0; i < length; i++) {
114
+ durProgress += propArray[i].duration;
115
+ }
116
+ if (length === 1) {
117
+ keyObj.from = prevKey.to;
118
+ }
119
+ if (prop.ease) {
120
+ keyObj.ease = prop.ease;
121
+ }
122
+ keyObj.duration = duration - (length ? durProgress : 0);
123
+ propArray.push(keyObj);
124
+ }
125
+ }
126
+ return key;
127
+ });
128
+
129
+ for (let name in properties) {
130
+ const propArray = /** @type {Array} */(properties[name]);
131
+ let prevEase;
132
+ // let durProgress = 0
133
+ for (let i = 0, l = propArray.length; i < l; i++) {
134
+ const prop = propArray[i];
135
+ // Emulate WAPPI easing parameter position
136
+ const currentEase = prop.ease;
137
+ prop.ease = prevEase ? prevEase : undefined;
138
+ prevEase = currentEase;
139
+ // durProgress += prop.duration;
140
+ // if (i === l - 1 && durProgress !== totalDuration) {
141
+ // propArray.push({ from: prop.to, ease: prop.ease, duration: totalDuration - durProgress })
142
+ // }
143
+ }
144
+ if (!propArray[0].duration) {
145
+ propArray.shift();
146
+ }
147
+ }
148
+
149
+ }
150
+
151
+ return properties;
152
+ };
153
+
154
+ class JSAnimation extends timer.Timer {
155
+ /**
156
+ * @param {TargetsParam} targets
157
+ * @param {AnimationParams} parameters
158
+ * @param {Timeline} [parent]
159
+ * @param {Number} [parentPosition]
160
+ * @param {Boolean} [fastSet=false]
161
+ * @param {Number} [index=0]
162
+ * @param {Number} [length=0]
163
+ */
164
+ constructor(
165
+ targets$1,
166
+ parameters,
167
+ parent,
168
+ parentPosition,
169
+ fastSet = false,
170
+ index = 0,
171
+ length = 0
172
+ ) {
173
+
174
+ super(/** @type {TimerParams & AnimationParams} */(parameters), parent, parentPosition);
175
+
176
+ const parsedTargets = targets.registerTargets(targets$1);
177
+ const targetsLength = parsedTargets.length;
178
+
179
+ // If the parameters object contains a "keyframes" property, convert all the keyframes values to regular properties
180
+
181
+ const kfParams = /** @type {AnimationParams} */(parameters).keyframes;
182
+ const params = /** @type {AnimationParams} */(kfParams ? helpers.mergeObjects(generateKeyframes(/** @type {DurationKeyframes} */(kfParams), parameters), parameters) : parameters);
183
+
184
+ const {
185
+ delay,
186
+ duration,
187
+ ease,
188
+ playbackEase,
189
+ modifier,
190
+ composition: composition$1,
191
+ onRender,
192
+ } = params;
193
+
194
+ const animDefaults = parent ? parent.defaults : globals.globals.defaults;
195
+ const animaPlaybackEase = values.setValue(playbackEase, animDefaults.playbackEase);
196
+ const animEase = animaPlaybackEase ? eases.parseEase(animaPlaybackEase) : null;
197
+ const hasSpring = !helpers.isUnd(ease) && !helpers.isUnd(/** @type {Spring} */(ease).ease);
198
+ const tEasing = hasSpring ? /** @type {Spring} */(ease).ease : values.setValue(ease, animEase ? 'linear' : animDefaults.ease);
199
+ const tDuration = hasSpring ? /** @type {Spring} */(ease).duration : values.setValue(duration, animDefaults.duration);
200
+ const tDelay = values.setValue(delay, animDefaults.delay);
201
+ const tModifier = modifier || animDefaults.modifier;
202
+ // If no composition is defined and the targets length is high (>= 1000) set the composition to 'none' (0) for faster tween creation
203
+ const tComposition = helpers.isUnd(composition$1) && targetsLength >= consts.K ? consts.compositionTypes.none : !helpers.isUnd(composition$1) ? composition$1 : animDefaults.composition;
204
+ // TODO: Do not create an empty object until we know the animation will generate inline styles
205
+ const animInlineStyles = {};
206
+ // const absoluteOffsetTime = this._offset;
207
+ const absoluteOffsetTime = this._offset + (parent ? parent._offset : 0);
208
+
209
+ let iterationDuration = NaN;
210
+ let iterationDelay = NaN;
211
+ let animationAnimationLength = 0;
212
+ let shouldTriggerRender = 0;
213
+
214
+ for (let targetIndex = 0; targetIndex < targetsLength; targetIndex++) {
215
+
216
+ const target = parsedTargets[targetIndex];
217
+ const ti = index || targetIndex;
218
+ const tl = length || targetsLength;
219
+
220
+ let lastTransformGroupIndex = NaN;
221
+ let lastTransformGroupLength = NaN;
222
+
223
+ for (let p in params) {
224
+
225
+ if (helpers.isKey(p)) {
226
+
227
+ const tweenType = values.getTweenType(target, p);
228
+
229
+ const propName = styles.sanitizePropertyName(p, target, tweenType);
230
+
231
+ let propValue = params[p];
232
+
233
+ const isPropValueArray = helpers.isArr(propValue);
234
+
235
+ if (fastSet && !isPropValueArray) {
236
+ fastSetValuesArray[0] = propValue;
237
+ fastSetValuesArray[1] = propValue;
238
+ propValue = fastSetValuesArray;
239
+ }
240
+
241
+ // TODO: Allow nested keyframes inside ObjectValue value (prop: { to: [.5, 1, .75, 2, 3] })
242
+ // Normalize property values to valid keyframe syntax:
243
+ // [x, y] to [{to: [x, y]}] or {to: x} to [{to: x}] or keep keys syntax [{}, {}, {}...]
244
+ // const keyframes = isArr(propValue) ? propValue.length === 2 && !isObj(propValue[0]) ? [{ to: propValue }] : propValue : [propValue];
245
+ if (isPropValueArray) {
246
+ const arrayLength = /** @type {Array} */(propValue).length;
247
+ const isNotObjectValue = !helpers.isObj(propValue[0]);
248
+ // Convert [x, y] to [{to: [x, y]}]
249
+ if (arrayLength === 2 && isNotObjectValue) {
250
+ keyObjectTarget.to = /** @type {TweenParamValue} */(/** @type {unknown} */(propValue));
251
+ keyframesTargetArray[0] = keyObjectTarget;
252
+ keyframes = keyframesTargetArray;
253
+ // Convert [x, y, z] to [[x, y], z]
254
+ } else if (arrayLength > 2 && isNotObjectValue) {
255
+ keyframes = [];
256
+ /** @type {Array.<Number>} */(propValue).forEach((v, i) => {
257
+ if (!i) {
258
+ fastSetValuesArray[0] = v;
259
+ } else if (i === 1) {
260
+ fastSetValuesArray[1] = v;
261
+ keyframes.push(fastSetValuesArray);
262
+ } else {
263
+ keyframes.push(v);
264
+ }
265
+ });
266
+ } else {
267
+ keyframes = /** @type {Array.<TweenKeyValue>} */(propValue);
268
+ }
269
+ } else {
270
+ keyframesTargetArray[0] = propValue;
271
+ keyframes = keyframesTargetArray;
272
+ }
273
+
274
+ let siblings = null;
275
+ let prevTween = null;
276
+ let firstTweenChangeStartTime = NaN;
277
+ let lastTweenChangeEndTime = 0;
278
+ let tweenIndex = 0;
279
+
280
+ for (let l = keyframes.length; tweenIndex < l; tweenIndex++) {
281
+
282
+ const keyframe = keyframes[tweenIndex];
283
+
284
+ if (helpers.isObj(keyframe)) {
285
+ key = keyframe;
286
+ } else {
287
+ keyObjectTarget.to = /** @type {TweenParamValue} */(keyframe);
288
+ key = keyObjectTarget;
289
+ }
290
+
291
+ toFunctionStore.func = null;
292
+
293
+ const computedToValue = values.getFunctionValue(key.to, target, ti, tl, toFunctionStore);
294
+
295
+ let tweenToValue;
296
+ // Allows function based values to return an object syntax value ({to: v})
297
+ if (helpers.isObj(computedToValue) && !helpers.isUnd(computedToValue.to)) {
298
+ key = computedToValue;
299
+ tweenToValue = computedToValue.to;
300
+ } else {
301
+ tweenToValue = computedToValue;
302
+ }
303
+ const tweenFromValue = values.getFunctionValue(key.from, target, ti, tl);
304
+ const keyEasing = key.ease;
305
+ const hasSpring = !helpers.isUnd(keyEasing) && !helpers.isUnd(/** @type {Spring} */(keyEasing).ease);
306
+ // Easing are treated differently and don't accept function based value to prevent having to pass a function wrapper that returns an other function all the time
307
+ const tweenEasing = hasSpring ? /** @type {Spring} */(keyEasing).ease : keyEasing || tEasing;
308
+ // Calculate default individual keyframe duration by dividing the tl of keyframes
309
+ const tweenDuration = hasSpring ? /** @type {Spring} */(keyEasing).duration : values.getFunctionValue(values.setValue(key.duration, (l > 1 ? values.getFunctionValue(tDuration, target, ti, tl) / l : tDuration)), target, ti, tl);
310
+ // Default delay value should only be applied to the first tween
311
+ const tweenDelay = values.getFunctionValue(values.setValue(key.delay, (!tweenIndex ? tDelay : 0)), target, ti, tl);
312
+ const computedComposition = values.getFunctionValue(values.setValue(key.composition, tComposition), target, ti, tl);
313
+ const tweenComposition = helpers.isNum(computedComposition) ? computedComposition : consts.compositionTypes[computedComposition];
314
+ // Modifiers are treated differently and don't accept function based value to prevent having to pass a function wrapper
315
+ const tweenModifier = key.modifier || tModifier;
316
+ const hasFromvalue = !helpers.isUnd(tweenFromValue);
317
+ const hasToValue = !helpers.isUnd(tweenToValue);
318
+ const isFromToArray = helpers.isArr(tweenToValue);
319
+ const isFromToValue = isFromToArray || (hasFromvalue && hasToValue);
320
+ const tweenStartTime = prevTween ? lastTweenChangeEndTime + tweenDelay : tweenDelay;
321
+ // Rounding is necessary here to minimize floating point errors when working in seconds
322
+ const absoluteStartTime = helpers.round(absoluteOffsetTime + tweenStartTime, 12);
323
+
324
+ // Force a onRender callback if the animation contains at least one from value and autoplay is set to false
325
+ if (!shouldTriggerRender && (hasFromvalue || isFromToArray)) shouldTriggerRender = 1;
326
+
327
+ let prevSibling = prevTween;
328
+
329
+ if (tweenComposition !== consts.compositionTypes.none) {
330
+ if (!siblings) siblings = composition.getTweenSiblings(target, propName);
331
+ let nextSibling = siblings._head;
332
+ // Iterate trough all the next siblings until we find a sibling with an equal or inferior start time
333
+ while (nextSibling && !nextSibling._isOverridden && nextSibling._absoluteStartTime <= absoluteStartTime) {
334
+ prevSibling = nextSibling;
335
+ nextSibling = nextSibling._nextRep;
336
+ // Overrides all the next siblings if the next sibling starts at the same time of after as the new tween start time
337
+ if (nextSibling && nextSibling._absoluteStartTime >= absoluteStartTime) {
338
+ while (nextSibling) {
339
+ composition.overrideTween(nextSibling);
340
+ // This will ends both the current while loop and the upper one once all the next sibllings have been overriden
341
+ nextSibling = nextSibling._nextRep;
342
+ }
343
+ }
344
+ }
345
+ }
346
+
347
+ // Decompose values
348
+ if (isFromToValue) {
349
+ values.decomposeRawValue(isFromToArray ? values.getFunctionValue(tweenToValue[0], target, ti, tl) : tweenFromValue, fromTargetObject);
350
+ values.decomposeRawValue(isFromToArray ? values.getFunctionValue(tweenToValue[1], target, ti, tl, toFunctionStore) : tweenToValue, toTargetObject);
351
+ if (fromTargetObject.t === consts.valueTypes.NUMBER) {
352
+ if (prevSibling) {
353
+ if (prevSibling._valueType === consts.valueTypes.UNIT) {
354
+ fromTargetObject.t = consts.valueTypes.UNIT;
355
+ fromTargetObject.u = prevSibling._unit;
356
+ }
357
+ } else {
358
+ values.decomposeRawValue(
359
+ values.getOriginalAnimatableValue(target, propName, tweenType, animInlineStyles),
360
+ values.decomposedOriginalValue
361
+ );
362
+ if (values.decomposedOriginalValue.t === consts.valueTypes.UNIT) {
363
+ fromTargetObject.t = consts.valueTypes.UNIT;
364
+ fromTargetObject.u = values.decomposedOriginalValue.u;
365
+ }
366
+ }
367
+ }
368
+ } else {
369
+ if (hasToValue) {
370
+ values.decomposeRawValue(tweenToValue, toTargetObject);
371
+ } else {
372
+ if (prevTween) {
373
+ values.decomposeTweenValue(prevTween, toTargetObject);
374
+ } else {
375
+ // No need to get and parse the original value if the tween is part of a timeline and has a previous sibling part of the same timeline
376
+ values.decomposeRawValue(parent && prevSibling && prevSibling.parent.parent === parent ? prevSibling._value :
377
+ values.getOriginalAnimatableValue(target, propName, tweenType, animInlineStyles), toTargetObject);
378
+ }
379
+ }
380
+ if (hasFromvalue) {
381
+ values.decomposeRawValue(tweenFromValue, fromTargetObject);
382
+ } else {
383
+ if (prevTween) {
384
+ values.decomposeTweenValue(prevTween, fromTargetObject);
385
+ } else {
386
+ values.decomposeRawValue(parent && prevSibling && prevSibling.parent.parent === parent ? prevSibling._value :
387
+ // No need to get and parse the original value if the tween is part of a timeline and has a previous sibling part of the same timeline
388
+ values.getOriginalAnimatableValue(target, propName, tweenType, animInlineStyles), fromTargetObject);
389
+ }
390
+ }
391
+ }
392
+
393
+ // Apply operators
394
+ if (fromTargetObject.o) {
395
+ fromTargetObject.n = values.getRelativeValue(
396
+ !prevSibling ? values.decomposeRawValue(
397
+ values.getOriginalAnimatableValue(target, propName, tweenType, animInlineStyles),
398
+ values.decomposedOriginalValue
399
+ ).n : prevSibling._toNumber,
400
+ fromTargetObject.n,
401
+ fromTargetObject.o
402
+ );
403
+ }
404
+
405
+ if (toTargetObject.o) {
406
+ toTargetObject.n = values.getRelativeValue(fromTargetObject.n, toTargetObject.n, toTargetObject.o);
407
+ }
408
+
409
+ // Values omogenisation in cases of type difference between "from" and "to"
410
+ if (fromTargetObject.t !== toTargetObject.t) {
411
+ if (fromTargetObject.t === consts.valueTypes.COMPLEX || toTargetObject.t === consts.valueTypes.COMPLEX) {
412
+ const complexValue = fromTargetObject.t === consts.valueTypes.COMPLEX ? fromTargetObject : toTargetObject;
413
+ const notComplexValue = fromTargetObject.t === consts.valueTypes.COMPLEX ? toTargetObject : fromTargetObject;
414
+ notComplexValue.t = consts.valueTypes.COMPLEX;
415
+ notComplexValue.s = helpers.cloneArray(complexValue.s);
416
+ notComplexValue.d = complexValue.d.map(() => notComplexValue.n);
417
+ } else if (fromTargetObject.t === consts.valueTypes.UNIT || toTargetObject.t === consts.valueTypes.UNIT) {
418
+ const unitValue = fromTargetObject.t === consts.valueTypes.UNIT ? fromTargetObject : toTargetObject;
419
+ const notUnitValue = fromTargetObject.t === consts.valueTypes.UNIT ? toTargetObject : fromTargetObject;
420
+ notUnitValue.t = consts.valueTypes.UNIT;
421
+ notUnitValue.u = unitValue.u;
422
+ } else if (fromTargetObject.t === consts.valueTypes.COLOR || toTargetObject.t === consts.valueTypes.COLOR) {
423
+ const colorValue = fromTargetObject.t === consts.valueTypes.COLOR ? fromTargetObject : toTargetObject;
424
+ const notColorValue = fromTargetObject.t === consts.valueTypes.COLOR ? toTargetObject : fromTargetObject;
425
+ notColorValue.t = consts.valueTypes.COLOR;
426
+ notColorValue.s = colorValue.s;
427
+ notColorValue.d = [0, 0, 0, 1];
428
+ }
429
+ }
430
+
431
+ // Unit conversion
432
+ if (fromTargetObject.u !== toTargetObject.u) {
433
+ let valueToConvert = toTargetObject.u ? fromTargetObject : toTargetObject;
434
+ valueToConvert = units.convertValueUnit(/** @type {DOMTarget} */(target), valueToConvert, toTargetObject.u ? toTargetObject.u : fromTargetObject.u, false);
435
+ // TODO:
436
+ // convertValueUnit(target, to.u ? from : to, to.u ? to.u : from.u);
437
+ }
438
+
439
+ // Fill in non existing complex values
440
+ if (toTargetObject.d && fromTargetObject.d && (toTargetObject.d.length !== fromTargetObject.d.length)) {
441
+ const longestValue = fromTargetObject.d.length > toTargetObject.d.length ? fromTargetObject : toTargetObject;
442
+ const shortestValue = longestValue === fromTargetObject ? toTargetObject : fromTargetObject;
443
+ // TODO: Check if n should be used instead of 0 for default complex values
444
+ shortestValue.d = longestValue.d.map((/** @type {Number} */_, /** @type {Number} */i) => helpers.isUnd(shortestValue.d[i]) ? 0 : shortestValue.d[i]);
445
+ shortestValue.s = helpers.cloneArray(longestValue.s);
446
+ }
447
+
448
+ // Tween factory
449
+
450
+ // Rounding is necessary here to minimize floating point errors when working in seconds
451
+ const tweenUpdateDuration = helpers.round(+tweenDuration || consts.minValue, 12);
452
+
453
+ /** @type {Tween} */
454
+ const tween = {
455
+ parent: this,
456
+ id: tweenId++,
457
+ property: propName,
458
+ target: target,
459
+ _value: null,
460
+ _func: toFunctionStore.func,
461
+ _ease: eases.parseEase(tweenEasing),
462
+ _fromNumbers: helpers.cloneArray(fromTargetObject.d),
463
+ _toNumbers: helpers.cloneArray(toTargetObject.d),
464
+ _strings: helpers.cloneArray(toTargetObject.s),
465
+ _fromNumber: fromTargetObject.n,
466
+ _toNumber: toTargetObject.n,
467
+ _numbers: helpers.cloneArray(fromTargetObject.d), // For additive tween and animatables
468
+ _number: fromTargetObject.n, // For additive tween and animatables
469
+ _unit: toTargetObject.u,
470
+ _modifier: tweenModifier,
471
+ _currentTime: 0,
472
+ _startTime: tweenStartTime,
473
+ _delay: +tweenDelay,
474
+ _updateDuration: tweenUpdateDuration,
475
+ _changeDuration: tweenUpdateDuration,
476
+ _absoluteStartTime: absoluteStartTime,
477
+ // NOTE: Investigate bit packing to stores ENUM / BOOL
478
+ _tweenType: tweenType,
479
+ _valueType: toTargetObject.t,
480
+ _composition: tweenComposition,
481
+ _isOverlapped: 0,
482
+ _isOverridden: 0,
483
+ _renderTransforms: 0,
484
+ _prevRep: null, // For replaced tween
485
+ _nextRep: null, // For replaced tween
486
+ _prevAdd: null, // For additive tween
487
+ _nextAdd: null, // For additive tween
488
+ _prev: null,
489
+ _next: null,
490
+ };
491
+
492
+ if (tweenComposition !== consts.compositionTypes.none) {
493
+ composition.composeTween(tween, siblings);
494
+ }
495
+
496
+ if (isNaN(firstTweenChangeStartTime)) {
497
+ firstTweenChangeStartTime = tween._startTime;
498
+ }
499
+ // Rounding is necessary here to minimize floating point errors when working in seconds
500
+ lastTweenChangeEndTime = helpers.round(tweenStartTime + tweenUpdateDuration, 12);
501
+ prevTween = tween;
502
+ animationAnimationLength++;
503
+
504
+ helpers.addChild(this, tween);
505
+
506
+ }
507
+
508
+ // Update animation timings with the added tweens properties
509
+
510
+ if (isNaN(iterationDelay) || firstTweenChangeStartTime < iterationDelay) {
511
+ iterationDelay = firstTweenChangeStartTime;
512
+ }
513
+
514
+ if (isNaN(iterationDuration) || lastTweenChangeEndTime > iterationDuration) {
515
+ iterationDuration = lastTweenChangeEndTime;
516
+ }
517
+
518
+ // TODO: Find a way to inline tween._renderTransforms = 1 here
519
+ if (tweenType === consts.tweenTypes.TRANSFORM) {
520
+ lastTransformGroupIndex = animationAnimationLength - tweenIndex;
521
+ lastTransformGroupLength = animationAnimationLength;
522
+ }
523
+
524
+ }
525
+
526
+ }
527
+
528
+ // Set _renderTransforms to last transform property to correctly render the transforms list
529
+ if (!isNaN(lastTransformGroupIndex)) {
530
+ let i = 0;
531
+ helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
532
+ if (i >= lastTransformGroupIndex && i < lastTransformGroupLength) {
533
+ tween._renderTransforms = 1;
534
+ if (tween._composition === consts.compositionTypes.blend) {
535
+ helpers.forEachChildren(additive.additive.animation, (/** @type {Tween} */additiveTween) => {
536
+ if (additiveTween.id === tween.id) {
537
+ additiveTween._renderTransforms = 1;
538
+ }
539
+ });
540
+ }
541
+ }
542
+ i++;
543
+ });
544
+ }
545
+
546
+ }
547
+
548
+ if (!targetsLength) {
549
+ console.warn(`No target found. Make sure the element you're trying to animate is accessible before creating your animation.`);
550
+ }
551
+
552
+ if (iterationDelay) {
553
+ helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
554
+ // If (startTime - delay) equals 0, this means the tween is at the begining of the animation so we need to trim the delay too
555
+ if (!(tween._startTime - tween._delay)) {
556
+ tween._delay -= iterationDelay;
557
+ }
558
+ tween._startTime -= iterationDelay;
559
+ });
560
+ iterationDuration -= iterationDelay;
561
+ } else {
562
+ iterationDelay = 0;
563
+ }
564
+
565
+ // Prevents iterationDuration to be NaN if no valid animatable props have been provided
566
+ // Prevents _iterationCount to be NaN if no valid animatable props have been provided
567
+ if (!iterationDuration) {
568
+ iterationDuration = consts.minValue;
569
+ this.iterationCount = 0;
570
+ }
571
+ /** @type {TargetsArray} */
572
+ this.targets = parsedTargets;
573
+ /** @type {Number} */
574
+ this.duration = iterationDuration === consts.minValue ? consts.minValue : helpers.clampInfinity(((iterationDuration + this._loopDelay) * this.iterationCount) - this._loopDelay) || consts.minValue;
575
+ /** @type {Callback<this>} */
576
+ this.onRender = onRender || animDefaults.onRender;
577
+ /** @type {EasingFunction} */
578
+ this._ease = animEase;
579
+ /** @type {Number} */
580
+ this._delay = iterationDelay;
581
+ // NOTE: I'm keeping delay values separated from offsets in timelines because delays can override previous tweens and it could be confusing to debug a timeline with overridden tweens and no associated visible delays.
582
+ // this._delay = parent ? 0 : iterationDelay;
583
+ // this._offset += parent ? iterationDelay : 0;
584
+ /** @type {Number} */
585
+ this.iterationDuration = iterationDuration;
586
+ /** @type {{}} */
587
+ this._inlineStyles = animInlineStyles;
588
+
589
+ if (!this._autoplay && shouldTriggerRender) this.onRender(this);
590
+ }
591
+
592
+ /**
593
+ * @param {Number} newDuration
594
+ * @return {this}
595
+ */
596
+ stretch(newDuration) {
597
+ const currentDuration = this.duration;
598
+ if (currentDuration === helpers.normalizeTime(newDuration)) return this;
599
+ const timeScale = newDuration / currentDuration;
600
+ // NOTE: Find a better way to handle the stretch of an animation after stretch = 0
601
+ helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
602
+ // Rounding is necessary here to minimize floating point errors
603
+ tween._updateDuration = helpers.normalizeTime(tween._updateDuration * timeScale);
604
+ tween._changeDuration = helpers.normalizeTime(tween._changeDuration * timeScale);
605
+ tween._currentTime *= timeScale;
606
+ tween._startTime *= timeScale;
607
+ tween._absoluteStartTime *= timeScale;
608
+ });
609
+ return super.stretch(newDuration);
610
+ }
611
+
612
+ /**
613
+ * @return {this}
614
+ */
615
+ refresh() {
616
+ helpers.forEachChildren(this, (/** @type {Tween} */tween) => {
617
+ const tweenFunc = tween._func;
618
+ if (tweenFunc) {
619
+ const ogValue = values.getOriginalAnimatableValue(tween.target, tween.property, tween._tweenType);
620
+ values.decomposeRawValue(ogValue, values.decomposedOriginalValue);
621
+ values.decomposeRawValue(tweenFunc(), toTargetObject);
622
+ tween._fromNumbers = helpers.cloneArray(values.decomposedOriginalValue.d);
623
+ tween._fromNumber = values.decomposedOriginalValue.n;
624
+ tween._toNumbers = helpers.cloneArray(toTargetObject.d);
625
+ tween._strings = helpers.cloneArray(toTargetObject.s);
626
+ // Make sure to apply relative operators https://github.com/juliangarnier/anime/issues/1025
627
+ tween._toNumber = toTargetObject.o ? values.getRelativeValue(values.decomposedOriginalValue.n, toTargetObject.n, toTargetObject.o) : toTargetObject.n;
628
+ }
629
+ });
630
+ return this;
631
+ }
632
+
633
+ /**
634
+ * Cancel the animation and revert all the values affected by this animation to their original state
635
+ * @return {this}
636
+ */
637
+ revert() {
638
+ super.revert();
639
+ return styles.cleanInlineStyles(this);
640
+ }
641
+
642
+ /**
643
+ * @param {Callback<this>} [callback]
644
+ * @return {Promise}
645
+ */
646
+ then(callback) {
647
+ return super.then(callback);
648
+ }
649
+
650
+ }
651
+
652
+ /**
653
+ * @param {TargetsParam} targets
654
+ * @param {AnimationParams} parameters
655
+ * @return {JSAnimation}
656
+ */
657
+ const animate = (targets, parameters) => new JSAnimation(targets, parameters, null, 0, false).init();
658
+
659
+ exports.JSAnimation = JSAnimation;
660
+ exports.animate = animate;