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