animejs 4.1.4 → 4.2.0

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