animejs 4.4.1 → 4.5.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 (165) hide show
  1. package/README.md +2 -3
  2. package/dist/bundles/anime.esm.js +462 -213
  3. package/dist/bundles/anime.esm.min.js +2 -2
  4. package/dist/bundles/anime.umd.js +462 -213
  5. package/dist/bundles/anime.umd.min.js +2 -2
  6. package/dist/modules/adapters/index.cjs +14 -0
  7. package/dist/modules/adapters/index.d.ts +1 -0
  8. package/dist/modules/adapters/index.js +8 -0
  9. package/dist/modules/adapters/registry.cjs +149 -0
  10. package/dist/modules/adapters/registry.d.ts +65 -0
  11. package/dist/modules/adapters/registry.js +146 -0
  12. package/dist/modules/adapters/three/adapter.cjs +26 -0
  13. package/dist/modules/adapters/three/adapter.d.ts +15 -0
  14. package/dist/modules/adapters/three/adapter.js +24 -0
  15. package/dist/modules/adapters/three/helpers.cjs +297 -0
  16. package/dist/modules/adapters/three/helpers.d.ts +89 -0
  17. package/dist/modules/adapters/three/helpers.js +280 -0
  18. package/dist/modules/adapters/three/index.cjs +20 -0
  19. package/dist/modules/adapters/three/index.d.ts +2 -0
  20. package/dist/modules/adapters/three/index.js +12 -0
  21. package/dist/modules/adapters/three/instance.cjs +368 -0
  22. package/dist/modules/adapters/three/instance.d.ts +133 -0
  23. package/dist/modules/adapters/three/instance.js +365 -0
  24. package/dist/modules/adapters/three/object3d.cjs +214 -0
  25. package/dist/modules/adapters/three/object3d.d.ts +1 -0
  26. package/dist/modules/adapters/three/object3d.js +212 -0
  27. package/dist/modules/adapters/three/resolvers.cjs +105 -0
  28. package/dist/modules/adapters/three/resolvers.d.ts +1 -0
  29. package/dist/modules/adapters/three/resolvers.js +103 -0
  30. package/dist/modules/adapters/three/uniform.cjs +41 -0
  31. package/dist/modules/adapters/three/uniform.d.ts +1 -0
  32. package/dist/modules/adapters/three/uniform.js +39 -0
  33. package/dist/modules/animatable/animatable.cjs +2 -1
  34. package/dist/modules/animatable/animatable.d.ts +2 -1
  35. package/dist/modules/animatable/animatable.js +2 -1
  36. package/dist/modules/animatable/index.cjs +1 -1
  37. package/dist/modules/animatable/index.js +1 -1
  38. package/dist/modules/animation/additive.cjs +1 -1
  39. package/dist/modules/animation/additive.js +1 -1
  40. package/dist/modules/animation/animation.cjs +43 -16
  41. package/dist/modules/animation/animation.d.ts +5 -0
  42. package/dist/modules/animation/animation.js +45 -18
  43. package/dist/modules/animation/composition.cjs +38 -35
  44. package/dist/modules/animation/composition.js +38 -35
  45. package/dist/modules/animation/index.cjs +1 -1
  46. package/dist/modules/animation/index.js +1 -1
  47. package/dist/modules/core/clock.cjs +11 -15
  48. package/dist/modules/core/clock.d.ts +0 -2
  49. package/dist/modules/core/clock.js +11 -15
  50. package/dist/modules/core/colors.cjs +1 -1
  51. package/dist/modules/core/colors.js +1 -1
  52. package/dist/modules/core/consts.cjs +15 -1
  53. package/dist/modules/core/consts.d.ts +2 -0
  54. package/dist/modules/core/consts.js +14 -2
  55. package/dist/modules/core/globals.cjs +7 -4
  56. package/dist/modules/core/globals.d.ts +8 -2
  57. package/dist/modules/core/globals.js +8 -5
  58. package/dist/modules/core/helpers.cjs +2 -2
  59. package/dist/modules/core/helpers.js +3 -3
  60. package/dist/modules/core/render.cjs +64 -14
  61. package/dist/modules/core/render.js +65 -15
  62. package/dist/modules/core/styles.cjs +16 -2
  63. package/dist/modules/core/styles.js +16 -2
  64. package/dist/modules/core/targets.cjs +11 -13
  65. package/dist/modules/core/targets.js +11 -13
  66. package/dist/modules/core/transforms.cjs +1 -1
  67. package/dist/modules/core/transforms.js +1 -1
  68. package/dist/modules/core/units.cjs +1 -1
  69. package/dist/modules/core/units.js +1 -1
  70. package/dist/modules/core/values.cjs +73 -82
  71. package/dist/modules/core/values.d.ts +1 -2
  72. package/dist/modules/core/values.js +76 -84
  73. package/dist/modules/draggable/draggable.cjs +1 -1
  74. package/dist/modules/draggable/draggable.js +1 -1
  75. package/dist/modules/draggable/index.cjs +1 -1
  76. package/dist/modules/draggable/index.js +1 -1
  77. package/dist/modules/easings/cubic-bezier/index.cjs +1 -1
  78. package/dist/modules/easings/cubic-bezier/index.js +1 -1
  79. package/dist/modules/easings/eases/index.cjs +1 -1
  80. package/dist/modules/easings/eases/index.js +1 -1
  81. package/dist/modules/easings/eases/parser.cjs +3 -3
  82. package/dist/modules/easings/eases/parser.d.ts +4 -5
  83. package/dist/modules/easings/eases/parser.js +3 -3
  84. package/dist/modules/easings/index.cjs +1 -1
  85. package/dist/modules/easings/index.js +1 -1
  86. package/dist/modules/easings/irregular/index.cjs +1 -1
  87. package/dist/modules/easings/irregular/index.js +1 -1
  88. package/dist/modules/easings/linear/index.cjs +1 -1
  89. package/dist/modules/easings/linear/index.js +1 -1
  90. package/dist/modules/easings/none.cjs +1 -1
  91. package/dist/modules/easings/none.js +1 -1
  92. package/dist/modules/easings/spring/index.cjs +1 -1
  93. package/dist/modules/easings/spring/index.js +1 -1
  94. package/dist/modules/easings/steps/index.cjs +1 -1
  95. package/dist/modules/easings/steps/index.js +1 -1
  96. package/dist/modules/engine/engine.cjs +4 -2
  97. package/dist/modules/engine/engine.js +4 -2
  98. package/dist/modules/engine/index.cjs +1 -1
  99. package/dist/modules/engine/index.js +1 -1
  100. package/dist/modules/events/index.cjs +1 -1
  101. package/dist/modules/events/index.js +1 -1
  102. package/dist/modules/events/scroll.cjs +3 -1
  103. package/dist/modules/events/scroll.js +3 -1
  104. package/dist/modules/index.cjs +1 -1
  105. package/dist/modules/index.js +1 -1
  106. package/dist/modules/layout/index.cjs +1 -1
  107. package/dist/modules/layout/index.js +1 -1
  108. package/dist/modules/layout/layout.cjs +1 -1
  109. package/dist/modules/layout/layout.js +1 -1
  110. package/dist/modules/scope/index.cjs +1 -1
  111. package/dist/modules/scope/index.js +1 -1
  112. package/dist/modules/scope/scope.cjs +1 -1
  113. package/dist/modules/scope/scope.js +1 -1
  114. package/dist/modules/svg/drawable.cjs +1 -1
  115. package/dist/modules/svg/drawable.js +1 -1
  116. package/dist/modules/svg/helpers.cjs +1 -1
  117. package/dist/modules/svg/helpers.js +1 -1
  118. package/dist/modules/svg/index.cjs +1 -1
  119. package/dist/modules/svg/index.js +1 -1
  120. package/dist/modules/svg/morphto.cjs +1 -1
  121. package/dist/modules/svg/morphto.js +1 -1
  122. package/dist/modules/svg/motionpath.cjs +1 -1
  123. package/dist/modules/svg/motionpath.js +1 -1
  124. package/dist/modules/text/index.cjs +1 -1
  125. package/dist/modules/text/index.js +1 -1
  126. package/dist/modules/text/scramble.cjs +12 -2
  127. package/dist/modules/text/scramble.d.ts +9 -1
  128. package/dist/modules/text/scramble.js +12 -2
  129. package/dist/modules/text/split.cjs +2 -1
  130. package/dist/modules/text/split.js +2 -1
  131. package/dist/modules/timeline/index.cjs +1 -1
  132. package/dist/modules/timeline/index.js +1 -1
  133. package/dist/modules/timeline/position.cjs +1 -1
  134. package/dist/modules/timeline/position.js +1 -1
  135. package/dist/modules/timeline/timeline.cjs +14 -5
  136. package/dist/modules/timeline/timeline.d.ts +3 -3
  137. package/dist/modules/timeline/timeline.js +14 -5
  138. package/dist/modules/timer/index.cjs +1 -1
  139. package/dist/modules/timer/index.js +1 -1
  140. package/dist/modules/timer/timer.cjs +1 -1
  141. package/dist/modules/timer/timer.js +1 -1
  142. package/dist/modules/types/index.d.ts +36 -11
  143. package/dist/modules/utils/chainable.cjs +1 -1
  144. package/dist/modules/utils/chainable.js +1 -1
  145. package/dist/modules/utils/index.cjs +1 -1
  146. package/dist/modules/utils/index.js +1 -1
  147. package/dist/modules/utils/number.cjs +1 -1
  148. package/dist/modules/utils/number.js +1 -1
  149. package/dist/modules/utils/random.cjs +4 -3
  150. package/dist/modules/utils/random.d.ts +1 -1
  151. package/dist/modules/utils/random.js +4 -3
  152. package/dist/modules/utils/stagger.cjs +67 -13
  153. package/dist/modules/utils/stagger.js +69 -15
  154. package/dist/modules/utils/target.cjs +4 -1
  155. package/dist/modules/utils/target.js +4 -1
  156. package/dist/modules/utils/time.cjs +6 -5
  157. package/dist/modules/utils/time.d.ts +1 -1
  158. package/dist/modules/utils/time.js +6 -5
  159. package/dist/modules/waapi/composition.cjs +1 -1
  160. package/dist/modules/waapi/composition.js +1 -1
  161. package/dist/modules/waapi/index.cjs +1 -1
  162. package/dist/modules/waapi/index.js +1 -1
  163. package/dist/modules/waapi/waapi.cjs +1 -1
  164. package/dist/modules/waapi/waapi.js +1 -1
  165. package/package.json +38 -5
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -63,11 +63,12 @@ const randomPick = items => items[random(0, items.length - 1)];
63
63
  * Adapted from https://bost.ocks.org/mike/shuffle/
64
64
  *
65
65
  * @param {Array} items - The array to shuffle (will be modified in-place)
66
+ * @param {RandomNumberGenerator} [rnd] - Optional RNG matching the random() signature (defaults to random)
66
67
  * @return {Array} The same array reference, now shuffled
67
68
  */
68
- const shuffle = items => {
69
+ const shuffle = (items, rnd = random) => {
69
70
  let m = items.length, t, i;
70
- while (m) { i = random(0, --m); t = items[m]; items[m] = items[i]; items[i] = t; }
71
+ while (m) { i = rnd(0, --m); t = items[m]; items[m] = items[i]; items[i] = t; }
71
72
  return items;
72
73
  };
73
74
 
@@ -15,7 +15,7 @@
15
15
  export const random: RandomNumberGenerator;
16
16
  export function createSeededRandom(seed?: number, seededMin?: number, seededMax?: number, seededDecimalLength?: number): RandomNumberGenerator;
17
17
  export function randomPick<T>(items: string | Array<T>): string | T;
18
- export function shuffle(items: any[]): any[];
18
+ export function shuffle(items: any[], rnd?: RandomNumberGenerator): any[];
19
19
  /**
20
20
  * Generate a random number between optional min and max (inclusive) and decimal precision
21
21
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -61,11 +61,12 @@ const randomPick = items => items[random(0, items.length - 1)];
61
61
  * Adapted from https://bost.ocks.org/mike/shuffle/
62
62
  *
63
63
  * @param {Array} items - The array to shuffle (will be modified in-place)
64
+ * @param {RandomNumberGenerator} [rnd] - Optional RNG matching the random() signature (defaults to random)
64
65
  * @return {Array} The same array reference, now shuffled
65
66
  */
66
- const shuffle = items => {
67
+ const shuffle = (items, rnd = random) => {
67
68
  let m = items.length, t, i;
68
- while (m) { i = random(0, --m); t = items[m]; items[m] = items[i]; items[i] = t; }
69
+ while (m) { i = rnd(0, --m); t = items[m]; items[m] = items[i]; items[i] = t; }
69
70
  return items;
70
71
  };
71
72
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -66,6 +66,7 @@ const stagger = (val, params = {}) => {
66
66
  let values$1 = [];
67
67
  let maxValue = 0;
68
68
  let cachedOffset;
69
+ let jitterSamples = null;
69
70
  const from = params.from;
70
71
  const reversed = params.reversed;
71
72
  const ease = params.ease;
@@ -87,27 +88,42 @@ const stagger = (val, params = {}) => {
87
88
  const val2 = isRange ? helpers.parseNumber(val[1]) : 0;
88
89
  const unitMatch = consts.unitsExecRgx.exec((isRange ? val[1] : val) + consts.emptyString);
89
90
  const start = params.start || 0 + (isRange ? val1 : 0);
91
+ const seed = params.seed;
92
+ const hasSeed = !helpers.isUnd(seed) && seed !== false;
93
+ const rng = hasSeed ? random.createSeededRandom(seed === true ? 0 : /** @type {Number} */(seed)) : random.random;
94
+ const jitter = params.jitter;
95
+ const hasJitter = !helpers.isUnd(jitter);
96
+ const jitterIsArr = helpers.isArr(jitter);
97
+ const jitterStart = jitterIsArr ? /** @type {[Number,Number]} */(jitter)[0] : /** @type {Number} */(jitter) || 0;
98
+ const jitterEnd = jitterIsArr ? /** @type {[Number,Number]} */(jitter)[1] : /** @type {Number} */(jitter) || 0;
90
99
  let fromIndex = fromFirst ? 0 : helpers.isNum(from) ? from : 0;
91
100
  return (target, i, t, _, tl) => {
92
101
  const [ registeredTarget ] = targets.registerTargets(target);
93
102
  const total = helpers.isUnd(customTotal) ? t.length : customTotal;
94
103
  const customIndex = !helpers.isUnd(useProp) ? helpers.isFnc(useProp) ? useProp(registeredTarget, i, total) : values.getOriginalAnimatableValue(registeredTarget, useProp) : false;
95
- const staggerIndex = helpers.isNum(customIndex) || helpers.isStr(customIndex) && helpers.isNum(+customIndex) ? +customIndex : i;
104
+ const customIdx = helpers.isNum(customIndex) || helpers.isStr(customIndex) && helpers.isNum(+customIndex) ? +customIndex : i;
105
+ // Fall back to the natural index when the resolved value lands outside [0, total) so values[staggerIndex] never reads undefined.
106
+ const staggerIndex = customIdx >= 0 && customIdx < total ? customIdx : i;
96
107
  if (fromCenter) fromIndex = (total - 1) / 2;
97
108
  if (fromLast) fromIndex = total - 1;
98
109
  if (!values$1.length) {
99
110
  if (autoGrid) {
100
111
  let hasPositions = true;
112
+ let has3D = false;
101
113
  let minPosX = Infinity;
102
114
  let minPosY = Infinity;
115
+ let minPosZ = Infinity;
103
116
  let maxPosX = -Infinity;
104
117
  let maxPosY = -Infinity;
118
+ let maxPosZ = -Infinity;
105
119
  const pxArr = [];
106
120
  const pyArr = [];
121
+ const pzArr = [];
107
122
  for (let index = 0; index < total; index++) {
108
123
  const el = t[index];
109
124
  let px = 0;
110
125
  let py = 0;
126
+ let pz = 0;
111
127
  let found = false;
112
128
  if (el && helpers.isFnc(el.getBoundingClientRect)) {
113
129
  const rect = el.getBoundingClientRect();
@@ -119,6 +135,10 @@ const stagger = (val, params = {}) => {
119
135
  if (obj && helpers.isNum(obj.x) && helpers.isNum(obj.y)) {
120
136
  px = obj.x;
121
137
  py = obj.y;
138
+ if (helpers.isNum(obj.z)) {
139
+ pz = obj.z;
140
+ has3D = true;
141
+ }
122
142
  found = true;
123
143
  }
124
144
  }
@@ -128,42 +148,52 @@ const stagger = (val, params = {}) => {
128
148
  }
129
149
  pxArr.push(px);
130
150
  pyArr.push(py);
151
+ pzArr.push(pz);
131
152
  if (px < minPosX) minPosX = px;
132
153
  if (py < minPosY) minPosY = py;
154
+ if (pz < minPosZ) minPosZ = pz;
133
155
  if (px > maxPosX) maxPosX = px;
134
156
  if (py > maxPosY) maxPosY = py;
157
+ if (pz > maxPosZ) maxPosZ = pz;
135
158
  }
136
159
  if (hasPositions) {
137
160
  let fX = pxArr[0];
138
161
  let fY = pyArr[0];
162
+ let fZ = pzArr[0];
139
163
  if (fromArr) {
140
164
  fX = minPosX + from[0] * (maxPosX - minPosX);
141
165
  fY = minPosY + from[1] * (maxPosY - minPosY);
166
+ fZ = has3D ? minPosZ + (from.length >= 3 ? from[2] : 0.5) * (maxPosZ - minPosZ) : 0;
142
167
  } else if (fromCenter) {
143
168
  fX = (minPosX + maxPosX) / 2;
144
169
  fY = (minPosY + maxPosY) / 2;
170
+ fZ = (minPosZ + maxPosZ) / 2;
145
171
  } else if (fromLast) {
146
172
  fX = pxArr[total - 1];
147
173
  fY = pyArr[total - 1];
174
+ fZ = pzArr[total - 1];
148
175
  } else if (helpers.isNum(from)) {
149
176
  fX = pxArr[from];
150
177
  fY = pyArr[from];
178
+ fZ = pzArr[from];
151
179
  }
152
180
  for (let index = 0; index < total; index++) {
153
181
  const distanceX = fX - pxArr[index];
154
182
  const distanceY = fY - pyArr[index];
155
- let value = helpers.sqrt(distanceX * distanceX + distanceY * distanceY);
183
+ const distanceZ = fZ - pzArr[index];
184
+ let value = helpers.sqrt(distanceX * distanceX + distanceY * distanceY + (has3D ? distanceZ * distanceZ : 0));
156
185
  if (axis === 'x') value = -distanceX;
157
186
  if (axis === 'y') value = -distanceY;
187
+ if (axis === 'z') value = -distanceZ;
158
188
  values$1.push(value);
159
189
  }
160
190
  let minDist = Infinity;
161
- for (let index = 0, l = values$1.length; index < l; index++) {
191
+ for (let index = 0; index < total; index++) {
162
192
  const absVal = helpers.abs(values$1[index]);
163
193
  if (absVal > 0 && absVal < minDist) minDist = absVal;
164
194
  }
165
195
  if (minDist > 0 && minDist < Infinity) {
166
- for (let index = 0, l = values$1.length; index < l; index++) {
196
+ for (let index = 0; index < total; index++) {
167
197
  values$1[index] = values$1[index] / minDist;
168
198
  }
169
199
  }
@@ -177,32 +207,51 @@ const stagger = (val, params = {}) => {
177
207
  if (!grid) {
178
208
  values$1.push(helpers.abs(fromIndex - index));
179
209
  } else {
180
- let fromX, fromY;
210
+ const dims = grid.length;
211
+ const wh = grid[0] * grid[1];
212
+ let fromX, fromY, fromZ;
181
213
  if (fromArr) {
182
214
  fromX = from[0] * (grid[0] - 1);
183
215
  fromY = from[1] * (grid[1] - 1);
216
+ fromZ = dims === 3 ? (from.length >= 3 ? from[2] : 0.5) * (grid[2] - 1) : 0;
184
217
  } else if (fromCenter) {
185
218
  fromX = (grid[0] - 1) / 2;
186
219
  fromY = (grid[1] - 1) / 2;
220
+ fromZ = dims === 3 ? (grid[2] - 1) / 2 : 0;
187
221
  } else {
188
222
  fromX = fromIndex % grid[0];
189
- fromY = helpers.floor(fromIndex / grid[0]);
223
+ fromY = helpers.floor(fromIndex / grid[0]) % grid[1];
224
+ fromZ = dims === 3 ? helpers.floor(fromIndex / wh) : 0;
190
225
  }
191
226
  const toX = index % grid[0];
192
- const toY = helpers.floor(index / grid[0]);
227
+ const toY = helpers.floor(index / grid[0]) % grid[1];
228
+ const toZ = dims === 3 ? helpers.floor(index / wh) : 0;
193
229
  const distanceX = fromX - toX;
194
230
  const distanceY = fromY - toY;
195
- let value = helpers.sqrt(distanceX * distanceX + distanceY * distanceY);
231
+ const distanceZ = fromZ - toZ;
232
+ let value = helpers.sqrt(distanceX * distanceX + distanceY * distanceY + (dims === 3 ? distanceZ * distanceZ : 0));
196
233
  if (axis === 'x') value = -distanceX;
197
234
  if (axis === 'y') value = -distanceY;
235
+ if (axis === 'z') value = -distanceZ;
198
236
  values$1.push(value);
199
237
  }
200
238
  }
201
239
  }
202
- maxValue = helpers.max(...values$1);
203
- if (staggerEase) values$1 = values$1.map(val => staggerEase(val / maxValue) * maxValue);
204
- if (reversed) values$1 = values$1.map(val => axis ? (val < 0) ? val * -1 : -val : helpers.abs(maxValue - val));
205
- if (fromRandom) values$1 = random.shuffle(values$1);
240
+ maxValue = values$1[0];
241
+ for (let k = 1; k < total; k++) if (values$1[k] > maxValue) maxValue = values$1[k];
242
+ if (staggerEase || reversed) {
243
+ for (let k = 0; k < total; k++) {
244
+ let v = values$1[k];
245
+ if (staggerEase) v = staggerEase(v / maxValue) * maxValue;
246
+ if (reversed) v = axis ? -v : helpers.abs(maxValue - v);
247
+ values$1[k] = v;
248
+ }
249
+ }
250
+ if (hasJitter) {
251
+ jitterSamples = new Array(total);
252
+ for (let k = 0; k < total; k++) jitterSamples[k] = rng(-1, 1, 4);
253
+ }
254
+ if (fromRandom) values$1 = random.shuffle(values$1, rng);
206
255
  }
207
256
  const spacing = isRange ? (val2 - val1) / maxValue : val1;
208
257
  if (helpers.isUnd(cachedOffset)) {
@@ -210,6 +259,11 @@ const stagger = (val, params = {}) => {
210
259
  }
211
260
  /** @type {String|Number} */
212
261
  let output = cachedOffset + ((spacing * helpers.round(values$1[staggerIndex], 2)) || 0);
262
+ if (hasJitter) {
263
+ const progress = maxValue ? values$1[staggerIndex] / maxValue : 0;
264
+ const mag = jitterStart + (jitterEnd - jitterStart) * progress;
265
+ output = /** @type {Number} */(output) + jitterSamples[staggerIndex] * mag;
266
+ }
213
267
  if (params.modifier) output = params.modifier(/** @type {Number} */(output));
214
268
  if (unitMatch) output = `${output}${unitMatch[2]}`;
215
269
  return output;
@@ -1,17 +1,17 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
7
7
 
8
8
  import { unitsExecRgx, emptyString } from '../core/consts.js';
9
- import { isUnd, parseNumber, isFnc, isNum, sqrt, abs, floor, max, round, isArr, isStr } from '../core/helpers.js';
9
+ import { isUnd, parseNumber, isFnc, isNum, sqrt, abs, floor, round, isArr, isStr } from '../core/helpers.js';
10
10
  import { parseEase } from '../easings/eases/parser.js';
11
11
  import { parseTimelinePosition } from '../timeline/position.js';
12
12
  import { getOriginalAnimatableValue } from '../core/values.js';
13
13
  import { registerTargets } from '../core/targets.js';
14
- import { shuffle } from './random.js';
14
+ import { createSeededRandom, random, shuffle } from './random.js';
15
15
 
16
16
  /**
17
17
  * @import {
@@ -64,6 +64,7 @@ const stagger = (val, params = {}) => {
64
64
  let values = [];
65
65
  let maxValue = 0;
66
66
  let cachedOffset;
67
+ let jitterSamples = null;
67
68
  const from = params.from;
68
69
  const reversed = params.reversed;
69
70
  const ease = params.ease;
@@ -85,27 +86,42 @@ const stagger = (val, params = {}) => {
85
86
  const val2 = isRange ? parseNumber(val[1]) : 0;
86
87
  const unitMatch = unitsExecRgx.exec((isRange ? val[1] : val) + emptyString);
87
88
  const start = params.start || 0 + (isRange ? val1 : 0);
89
+ const seed = params.seed;
90
+ const hasSeed = !isUnd(seed) && seed !== false;
91
+ const rng = hasSeed ? createSeededRandom(seed === true ? 0 : /** @type {Number} */(seed)) : random;
92
+ const jitter = params.jitter;
93
+ const hasJitter = !isUnd(jitter);
94
+ const jitterIsArr = isArr(jitter);
95
+ const jitterStart = jitterIsArr ? /** @type {[Number,Number]} */(jitter)[0] : /** @type {Number} */(jitter) || 0;
96
+ const jitterEnd = jitterIsArr ? /** @type {[Number,Number]} */(jitter)[1] : /** @type {Number} */(jitter) || 0;
88
97
  let fromIndex = fromFirst ? 0 : isNum(from) ? from : 0;
89
98
  return (target, i, t, _, tl) => {
90
99
  const [ registeredTarget ] = registerTargets(target);
91
100
  const total = isUnd(customTotal) ? t.length : customTotal;
92
101
  const customIndex = !isUnd(useProp) ? isFnc(useProp) ? useProp(registeredTarget, i, total) : getOriginalAnimatableValue(registeredTarget, useProp) : false;
93
- const staggerIndex = isNum(customIndex) || isStr(customIndex) && isNum(+customIndex) ? +customIndex : i;
102
+ const customIdx = isNum(customIndex) || isStr(customIndex) && isNum(+customIndex) ? +customIndex : i;
103
+ // Fall back to the natural index when the resolved value lands outside [0, total) so values[staggerIndex] never reads undefined.
104
+ const staggerIndex = customIdx >= 0 && customIdx < total ? customIdx : i;
94
105
  if (fromCenter) fromIndex = (total - 1) / 2;
95
106
  if (fromLast) fromIndex = total - 1;
96
107
  if (!values.length) {
97
108
  if (autoGrid) {
98
109
  let hasPositions = true;
110
+ let has3D = false;
99
111
  let minPosX = Infinity;
100
112
  let minPosY = Infinity;
113
+ let minPosZ = Infinity;
101
114
  let maxPosX = -Infinity;
102
115
  let maxPosY = -Infinity;
116
+ let maxPosZ = -Infinity;
103
117
  const pxArr = [];
104
118
  const pyArr = [];
119
+ const pzArr = [];
105
120
  for (let index = 0; index < total; index++) {
106
121
  const el = t[index];
107
122
  let px = 0;
108
123
  let py = 0;
124
+ let pz = 0;
109
125
  let found = false;
110
126
  if (el && isFnc(el.getBoundingClientRect)) {
111
127
  const rect = el.getBoundingClientRect();
@@ -117,6 +133,10 @@ const stagger = (val, params = {}) => {
117
133
  if (obj && isNum(obj.x) && isNum(obj.y)) {
118
134
  px = obj.x;
119
135
  py = obj.y;
136
+ if (isNum(obj.z)) {
137
+ pz = obj.z;
138
+ has3D = true;
139
+ }
120
140
  found = true;
121
141
  }
122
142
  }
@@ -126,42 +146,52 @@ const stagger = (val, params = {}) => {
126
146
  }
127
147
  pxArr.push(px);
128
148
  pyArr.push(py);
149
+ pzArr.push(pz);
129
150
  if (px < minPosX) minPosX = px;
130
151
  if (py < minPosY) minPosY = py;
152
+ if (pz < minPosZ) minPosZ = pz;
131
153
  if (px > maxPosX) maxPosX = px;
132
154
  if (py > maxPosY) maxPosY = py;
155
+ if (pz > maxPosZ) maxPosZ = pz;
133
156
  }
134
157
  if (hasPositions) {
135
158
  let fX = pxArr[0];
136
159
  let fY = pyArr[0];
160
+ let fZ = pzArr[0];
137
161
  if (fromArr) {
138
162
  fX = minPosX + from[0] * (maxPosX - minPosX);
139
163
  fY = minPosY + from[1] * (maxPosY - minPosY);
164
+ fZ = has3D ? minPosZ + (from.length >= 3 ? from[2] : 0.5) * (maxPosZ - minPosZ) : 0;
140
165
  } else if (fromCenter) {
141
166
  fX = (minPosX + maxPosX) / 2;
142
167
  fY = (minPosY + maxPosY) / 2;
168
+ fZ = (minPosZ + maxPosZ) / 2;
143
169
  } else if (fromLast) {
144
170
  fX = pxArr[total - 1];
145
171
  fY = pyArr[total - 1];
172
+ fZ = pzArr[total - 1];
146
173
  } else if (isNum(from)) {
147
174
  fX = pxArr[from];
148
175
  fY = pyArr[from];
176
+ fZ = pzArr[from];
149
177
  }
150
178
  for (let index = 0; index < total; index++) {
151
179
  const distanceX = fX - pxArr[index];
152
180
  const distanceY = fY - pyArr[index];
153
- let value = sqrt(distanceX * distanceX + distanceY * distanceY);
181
+ const distanceZ = fZ - pzArr[index];
182
+ let value = sqrt(distanceX * distanceX + distanceY * distanceY + (has3D ? distanceZ * distanceZ : 0));
154
183
  if (axis === 'x') value = -distanceX;
155
184
  if (axis === 'y') value = -distanceY;
185
+ if (axis === 'z') value = -distanceZ;
156
186
  values.push(value);
157
187
  }
158
188
  let minDist = Infinity;
159
- for (let index = 0, l = values.length; index < l; index++) {
189
+ for (let index = 0; index < total; index++) {
160
190
  const absVal = abs(values[index]);
161
191
  if (absVal > 0 && absVal < minDist) minDist = absVal;
162
192
  }
163
193
  if (minDist > 0 && minDist < Infinity) {
164
- for (let index = 0, l = values.length; index < l; index++) {
194
+ for (let index = 0; index < total; index++) {
165
195
  values[index] = values[index] / minDist;
166
196
  }
167
197
  }
@@ -175,32 +205,51 @@ const stagger = (val, params = {}) => {
175
205
  if (!grid) {
176
206
  values.push(abs(fromIndex - index));
177
207
  } else {
178
- let fromX, fromY;
208
+ const dims = grid.length;
209
+ const wh = grid[0] * grid[1];
210
+ let fromX, fromY, fromZ;
179
211
  if (fromArr) {
180
212
  fromX = from[0] * (grid[0] - 1);
181
213
  fromY = from[1] * (grid[1] - 1);
214
+ fromZ = dims === 3 ? (from.length >= 3 ? from[2] : 0.5) * (grid[2] - 1) : 0;
182
215
  } else if (fromCenter) {
183
216
  fromX = (grid[0] - 1) / 2;
184
217
  fromY = (grid[1] - 1) / 2;
218
+ fromZ = dims === 3 ? (grid[2] - 1) / 2 : 0;
185
219
  } else {
186
220
  fromX = fromIndex % grid[0];
187
- fromY = floor(fromIndex / grid[0]);
221
+ fromY = floor(fromIndex / grid[0]) % grid[1];
222
+ fromZ = dims === 3 ? floor(fromIndex / wh) : 0;
188
223
  }
189
224
  const toX = index % grid[0];
190
- const toY = floor(index / grid[0]);
225
+ const toY = floor(index / grid[0]) % grid[1];
226
+ const toZ = dims === 3 ? floor(index / wh) : 0;
191
227
  const distanceX = fromX - toX;
192
228
  const distanceY = fromY - toY;
193
- let value = sqrt(distanceX * distanceX + distanceY * distanceY);
229
+ const distanceZ = fromZ - toZ;
230
+ let value = sqrt(distanceX * distanceX + distanceY * distanceY + (dims === 3 ? distanceZ * distanceZ : 0));
194
231
  if (axis === 'x') value = -distanceX;
195
232
  if (axis === 'y') value = -distanceY;
233
+ if (axis === 'z') value = -distanceZ;
196
234
  values.push(value);
197
235
  }
198
236
  }
199
237
  }
200
- maxValue = max(...values);
201
- if (staggerEase) values = values.map(val => staggerEase(val / maxValue) * maxValue);
202
- if (reversed) values = values.map(val => axis ? (val < 0) ? val * -1 : -val : abs(maxValue - val));
203
- if (fromRandom) values = shuffle(values);
238
+ maxValue = values[0];
239
+ for (let k = 1; k < total; k++) if (values[k] > maxValue) maxValue = values[k];
240
+ if (staggerEase || reversed) {
241
+ for (let k = 0; k < total; k++) {
242
+ let v = values[k];
243
+ if (staggerEase) v = staggerEase(v / maxValue) * maxValue;
244
+ if (reversed) v = axis ? -v : abs(maxValue - v);
245
+ values[k] = v;
246
+ }
247
+ }
248
+ if (hasJitter) {
249
+ jitterSamples = new Array(total);
250
+ for (let k = 0; k < total; k++) jitterSamples[k] = rng(-1, 1, 4);
251
+ }
252
+ if (fromRandom) values = shuffle(values, rng);
204
253
  }
205
254
  const spacing = isRange ? (val2 - val1) / maxValue : val1;
206
255
  if (isUnd(cachedOffset)) {
@@ -208,6 +257,11 @@ const stagger = (val, params = {}) => {
208
257
  }
209
258
  /** @type {String|Number} */
210
259
  let output = cachedOffset + ((spacing * round(values[staggerIndex], 2)) || 0);
260
+ if (hasJitter) {
261
+ const progress = maxValue ? values[staggerIndex] / maxValue : 0;
262
+ const mag = jitterStart + (jitterEnd - jitterStart) * progress;
263
+ output = /** @type {Number} */(output) + jitterSamples[staggerIndex] * mag;
264
+ }
211
265
  if (params.modifier) output = params.modifier(/** @type {Number} */(output));
212
266
  if (unitMatch) output = `${output}${unitMatch[2]}`;
213
267
  return output;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -93,6 +93,9 @@ function get(targetSelector, propName, unit) {
93
93
  */
94
94
  const set = (targets, parameters) => {
95
95
  if (helpers.isUnd(parameters)) return;
96
+ if (globals.globals.editor && globals.globals.editor.addSet) {
97
+ return globals.globals.editor.addSet(targets, parameters);
98
+ }
96
99
  parameters.duration = consts.minValue;
97
100
  // Do not overrides currently active tweens by default
98
101
  parameters.composition = values.setValue(parameters.composition, consts.compositionTypes.none);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -92,6 +92,9 @@ function get(targetSelector, propName, unit) {
92
92
  */
93
93
  const set = (targets, parameters) => {
94
94
  if (isUnd(parameters)) return;
95
+ if (globals.editor && globals.editor.addSet) {
96
+ return globals.editor.addSet(targets, parameters);
97
+ }
95
98
  parameters.duration = minValue;
96
99
  // Do not overrides currently active tweens by default
97
100
  parameters.composition = setValue(parameters.composition, compositionTypes.none);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -28,13 +28,14 @@ const sync = (callback = consts.noop) => {
28
28
  };
29
29
 
30
30
  /**
31
- * @param {(...args: any[]) => Tickable | ((...args: any[]) => void) | void} constructor
32
- * @return {(...args: any[]) => Tickable | ((...args: any[]) => void)}
31
+ * @template {Tickable | ((...args: any[]) => void) | void} T
32
+ * @param {(...args: any[]) => T} constructor
33
+ * @return {(...args: any[]) => T extends void ? () => void : T}
33
34
  */
34
35
  const keepTime = constructor => {
35
36
  /** @type {Tickable} */
36
37
  let tracked;
37
- return (...args) => {
38
+ return /** @type {(...args: any[]) => T extends void ? () => void : T} */(/** @type {*} */((...args) => {
38
39
  let currentIteration, currentIterationProgress, reversed, alternate, startTime;
39
40
  if (tracked) {
40
41
  currentIteration = tracked.currentIteration;
@@ -52,7 +53,7 @@ const keepTime = constructor => {
52
53
  /** @type {Tickable} */(tracked)._startTime = startTime;
53
54
  }
54
55
  return cleanup || consts.noop;
55
- }
56
+ }));
56
57
  };
57
58
 
58
59
  exports.keepTime = keepTime;
@@ -1,5 +1,5 @@
1
1
  export function sync(callback?: Callback<Timer>): Timer;
2
- export function keepTime(constructor: (...args: any[]) => Tickable | ((...args: any[]) => void) | void): (...args: any[]) => Tickable | ((...args: any[]) => void);
2
+ export function keepTime<T extends Tickable | ((...args: any[]) => void) | void>(constructor: (...args: any[]) => T): (...args: any[]) => T extends void ? () => void : T;
3
3
  import { Timer } from '../timer/timer.js';
4
4
  import type { Callback } from '../types/index.js';
5
5
  import type { Tickable } from '../types/index.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - utils - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -26,13 +26,14 @@ const sync = (callback = noop) => {
26
26
  };
27
27
 
28
28
  /**
29
- * @param {(...args: any[]) => Tickable | ((...args: any[]) => void) | void} constructor
30
- * @return {(...args: any[]) => Tickable | ((...args: any[]) => void)}
29
+ * @template {Tickable | ((...args: any[]) => void) | void} T
30
+ * @param {(...args: any[]) => T} constructor
31
+ * @return {(...args: any[]) => T extends void ? () => void : T}
31
32
  */
32
33
  const keepTime = constructor => {
33
34
  /** @type {Tickable} */
34
35
  let tracked;
35
- return (...args) => {
36
+ return /** @type {(...args: any[]) => T extends void ? () => void : T} */(/** @type {*} */((...args) => {
36
37
  let currentIteration, currentIterationProgress, reversed, alternate, startTime;
37
38
  if (tracked) {
38
39
  currentIteration = tracked.currentIteration;
@@ -50,7 +51,7 @@ const keepTime = constructor => {
50
51
  /** @type {Tickable} */(tracked)._startTime = startTime;
51
52
  }
52
53
  return cleanup || noop;
53
- }
54
+ }));
54
55
  };
55
56
 
56
57
  export { keepTime, sync };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - CJS
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anime.js - waapi - ESM
3
- * @version v4.4.1
3
+ * @version v4.5.0
4
4
  * @license MIT
5
5
  * @copyright 2026 - Julian Garnier
6
6
  */