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