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,251 @@
1
+ /**
2
+ * Anime.js - scope - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ import { doc, win } from '../core/consts.js';
9
+ import { globals, scope } from '../core/globals.js';
10
+ import { mergeObjects, isFnc } from '../core/helpers.js';
11
+ import { parseTargets } from '../core/targets.js';
12
+ import { keepTime } from '../utils/time.js';
13
+
14
+ /**
15
+ * @import {
16
+ * Tickable,
17
+ * ScopeParams,
18
+ * DOMTarget,
19
+ * ReactRef,
20
+ * AngularRef,
21
+ * DOMTargetSelector,
22
+ * DefaultsParams,
23
+ * ScopeConstructorCallback,
24
+ * ScopeCleanupCallback,
25
+ * Revertible,
26
+ * ScopeMethod,
27
+ * ScopedCallback,
28
+ * } from '../types/index.js'
29
+ */
30
+
31
+ class Scope {
32
+ /** @param {ScopeParams} [parameters] */
33
+ constructor(parameters = {}) {
34
+ if (scope.current) scope.current.register(this);
35
+ const rootParam = parameters.root;
36
+ /** @type {Document|DOMTarget} */
37
+ let root = doc;
38
+ if (rootParam) {
39
+ root = /** @type {ReactRef} */(rootParam).current ||
40
+ /** @type {AngularRef} */(rootParam).nativeElement ||
41
+ parseTargets(/** @type {DOMTargetSelector} */(rootParam))[0] ||
42
+ doc;
43
+ }
44
+ const scopeDefaults = parameters.defaults;
45
+ const globalDefault = globals.defaults;
46
+ const mediaQueries = parameters.mediaQueries;
47
+ /** @type {DefaultsParams} */
48
+ this.defaults = scopeDefaults ? mergeObjects(scopeDefaults, globalDefault) : globalDefault;
49
+ /** @type {Document|DOMTarget} */
50
+ this.root = root;
51
+ /** @type {Array<ScopeConstructorCallback>} */
52
+ this.constructors = [];
53
+ /** @type {Array<ScopeCleanupCallback>} */
54
+ this.revertConstructors = [];
55
+ /** @type {Array<Revertible>} */
56
+ this.revertibles = [];
57
+ /** @type {Array<ScopeConstructorCallback | ((scope: this) => Tickable)>} */
58
+ this.constructorsOnce = [];
59
+ /** @type {Array<ScopeCleanupCallback>} */
60
+ this.revertConstructorsOnce = [];
61
+ /** @type {Array<Revertible>} */
62
+ this.revertiblesOnce = [];
63
+ /** @type {Boolean} */
64
+ this.once = false;
65
+ /** @type {Number} */
66
+ this.onceIndex = 0;
67
+ /** @type {Record<String, ScopeMethod>} */
68
+ this.methods = {};
69
+ /** @type {Record<String, Boolean>} */
70
+ this.matches = {};
71
+ /** @type {Record<String, MediaQueryList>} */
72
+ this.mediaQueryLists = {};
73
+ /** @type {Record<String, any>} */
74
+ this.data = {};
75
+ if (mediaQueries) {
76
+ for (let mq in mediaQueries) {
77
+ const _mq = win.matchMedia(mediaQueries[mq]);
78
+ this.mediaQueryLists[mq] = _mq;
79
+ _mq.addEventListener('change', this);
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * @param {Revertible} revertible
86
+ */
87
+ register(revertible) {
88
+ const store = this.once ? this.revertiblesOnce : this.revertibles;
89
+ store.push(revertible);
90
+ }
91
+
92
+ /**
93
+ * @template T
94
+ * @param {ScopedCallback<T>} cb
95
+ * @return {T}
96
+ */
97
+ execute(cb) {
98
+ let activeScope = scope.current;
99
+ let activeRoot = scope.root;
100
+ let activeDefaults = globals.defaults;
101
+ scope.current = this;
102
+ scope.root = this.root;
103
+ globals.defaults = this.defaults;
104
+ const mqs = this.mediaQueryLists;
105
+ for (let mq in mqs) this.matches[mq] = mqs[mq].matches;
106
+ const returned = cb(this);
107
+ scope.current = activeScope;
108
+ scope.root = activeRoot;
109
+ globals.defaults = activeDefaults;
110
+ return returned;
111
+ }
112
+
113
+ /**
114
+ * @return {this}
115
+ */
116
+ refresh() {
117
+ this.onceIndex = 0;
118
+ this.execute(() => {
119
+ let i = this.revertibles.length;
120
+ let y = this.revertConstructors.length;
121
+ while (i--) this.revertibles[i].revert();
122
+ while (y--) this.revertConstructors[y](this);
123
+ this.revertibles.length = 0;
124
+ this.revertConstructors.length = 0;
125
+ this.constructors.forEach((/** @type {ScopeConstructorCallback} */constructor) => {
126
+ const revertConstructor = constructor(this);
127
+ if (isFnc(revertConstructor)) {
128
+ this.revertConstructors.push(revertConstructor);
129
+ }
130
+ });
131
+ });
132
+ return this;
133
+ }
134
+
135
+ /**
136
+ * @overload
137
+ * @param {String} a1
138
+ * @param {ScopeMethod} a2
139
+ * @return {this}
140
+ *
141
+ * @overload
142
+ * @param {ScopeConstructorCallback} a1
143
+ * @return {this}
144
+ *
145
+ * @param {String|ScopeConstructorCallback} a1
146
+ * @param {ScopeMethod} [a2]
147
+ */
148
+ add(a1, a2) {
149
+ this.once = false;
150
+ if (isFnc(a1)) {
151
+ const constructor = /** @type {ScopeConstructorCallback} */(a1);
152
+ this.constructors.push(constructor);
153
+ this.execute(() => {
154
+ const revertConstructor = constructor(this);
155
+ if (isFnc(revertConstructor)) {
156
+ this.revertConstructors.push(revertConstructor);
157
+ }
158
+ });
159
+ } else {
160
+ this.methods[/** @type {String} */(a1)] = (/** @type {any} */...args) => this.execute(() => a2(...args));
161
+ }
162
+ return this;
163
+ }
164
+
165
+ /**
166
+ * @param {ScopeConstructorCallback} scopeConstructorCallback
167
+ * @return {this}
168
+ */
169
+ addOnce(scopeConstructorCallback) {
170
+ this.once = true;
171
+ if (isFnc(scopeConstructorCallback)) {
172
+ const currentIndex = this.onceIndex++;
173
+ const tracked = this.constructorsOnce[currentIndex];
174
+ if (tracked) return this;
175
+ const constructor = /** @type {ScopeConstructorCallback} */(scopeConstructorCallback);
176
+ this.constructorsOnce[currentIndex] = constructor;
177
+ this.execute(() => {
178
+ const revertConstructor = constructor(this);
179
+ if (isFnc(revertConstructor)) {
180
+ this.revertConstructorsOnce.push(revertConstructor);
181
+ }
182
+ });
183
+ }
184
+ return this;
185
+ }
186
+
187
+ /**
188
+ * @param {(scope: this) => Tickable} cb
189
+ * @return {Tickable}
190
+ */
191
+ keepTime(cb) {
192
+ this.once = true;
193
+ const currentIndex = this.onceIndex++;
194
+ const tracked = /** @type {(scope: this) => Tickable} */(this.constructorsOnce[currentIndex]);
195
+ if (isFnc(tracked)) return tracked(this);
196
+ const constructor = /** @type {(scope: this) => Tickable} */(keepTime(cb));
197
+ this.constructorsOnce[currentIndex] = constructor;
198
+ let trackedTickable;
199
+ this.execute(() => {
200
+ trackedTickable = constructor(this);
201
+ });
202
+ return trackedTickable;
203
+ }
204
+
205
+ /**
206
+ * @param {Event} e
207
+ */
208
+ handleEvent(e) {
209
+ switch (e.type) {
210
+ case 'change':
211
+ this.refresh();
212
+ break;
213
+ }
214
+ }
215
+
216
+ revert() {
217
+ const revertibles = this.revertibles;
218
+ const revertConstructors = this.revertConstructors;
219
+ const revertiblesOnce = this.revertiblesOnce;
220
+ const revertConstructorsOnce = this.revertConstructorsOnce;
221
+ const mqs = this.mediaQueryLists;
222
+ let i = revertibles.length;
223
+ let j = revertConstructors.length;
224
+ let k = revertiblesOnce.length;
225
+ let l = revertConstructorsOnce.length;
226
+ while (i--) revertibles[i].revert();
227
+ while (j--) revertConstructors[j](this);
228
+ while (k--) revertiblesOnce[k].revert();
229
+ while (l--) revertConstructorsOnce[l](this);
230
+ for (let mq in mqs) mqs[mq].removeEventListener('change', this);
231
+ revertibles.length = 0;
232
+ revertConstructors.length = 0;
233
+ this.constructors.length = 0;
234
+ revertiblesOnce.length = 0;
235
+ revertConstructorsOnce.length = 0;
236
+ this.constructorsOnce.length = 0;
237
+ this.onceIndex = 0;
238
+ this.matches = {};
239
+ this.methods = {};
240
+ this.mediaQueryLists = {};
241
+ this.data = {};
242
+ }
243
+ }
244
+
245
+ /**
246
+ * @param {ScopeParams} [params]
247
+ * @return {Scope}
248
+ */
249
+ const createScope = params => new Scope(params);
250
+
251
+ export { Scope, createScope };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Anime.js - spring - CJS
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var spring = require('./spring.cjs');
11
+
12
+
13
+
14
+ exports.Spring = spring.Spring;
15
+ exports.createSpring = spring.createSpring;
@@ -0,0 +1 @@
1
+ export * from "./spring.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Anime.js - spring - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ export { Spring, createSpring } from './spring.js';
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Anime.js - spring - CJS
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var consts = require('../core/consts.cjs');
11
+ var globals = require('../core/globals.cjs');
12
+ var helpers = require('../core/helpers.cjs');
13
+ var values = require('../core/values.cjs');
14
+
15
+ /**
16
+ * @import {
17
+ * EasingFunction,
18
+ * SpringParams,
19
+ * } from '../types/index.js'
20
+ */
21
+
22
+ /*
23
+ * Spring ease solver adapted from https://webkit.org/demos/spring/spring.js
24
+ * (c) 2016 Webkit - Apple Inc
25
+ */
26
+
27
+ const maxSpringParamValue = consts.K * 10;
28
+
29
+ class Spring {
30
+ /**
31
+ * @param {SpringParams} [parameters]
32
+ */
33
+ constructor(parameters = {}) {
34
+ this.timeStep = .02; // Interval fed to the solver to calculate duration
35
+ this.restThreshold = .0005; // Values below this threshold are considered resting position
36
+ this.restDuration = 200; // Duration in ms used to check if the spring is resting after reaching restThreshold
37
+ this.maxDuration = 60000; // The maximum allowed spring duration in ms (default 1 min)
38
+ this.maxRestSteps = this.restDuration / this.timeStep / consts.K; // How many steps allowed after reaching restThreshold before stopping the duration calculation
39
+ this.maxIterations = this.maxDuration / this.timeStep / consts.K; // Calculate the maximum iterations allowed based on maxDuration
40
+ this.m = helpers.clamp(values.setValue(parameters.mass, 1), 0, maxSpringParamValue);
41
+ this.s = helpers.clamp(values.setValue(parameters.stiffness, 100), 1, maxSpringParamValue);
42
+ this.d = helpers.clamp(values.setValue(parameters.damping, 10), .1, maxSpringParamValue);
43
+ this.v = helpers.clamp(values.setValue(parameters.velocity, 0), -maxSpringParamValue, maxSpringParamValue);
44
+ this.w0 = 0;
45
+ this.zeta = 0;
46
+ this.wd = 0;
47
+ this.b = 0;
48
+ this.solverDuration = 0;
49
+ this.duration = 0;
50
+ this.compute();
51
+ /** @type {EasingFunction} */
52
+ this.ease = t => t === 0 || t === 1 ? t : this.solve(t * this.solverDuration);
53
+ }
54
+
55
+ /** @type {EasingFunction} */
56
+ solve(time) {
57
+ const { zeta, w0, wd, b } = this;
58
+ let t = time;
59
+ if (zeta < 1) {
60
+ t = helpers.exp(-t * zeta * w0) * (1 * helpers.cos(wd * t) + b * helpers.sin(wd * t));
61
+ } else {
62
+ t = (1 + b * t) * helpers.exp(-t * w0);
63
+ }
64
+ return 1 - t;
65
+ }
66
+
67
+ compute() {
68
+ const { maxRestSteps, maxIterations, restThreshold, timeStep, m, d, s, v } = this;
69
+ const w0 = this.w0 = helpers.clamp(helpers.sqrt(s / m), consts.minValue, consts.K);
70
+ const zeta = this.zeta = d / (2 * helpers.sqrt(s * m));
71
+ const wd = this.wd = zeta < 1 ? w0 * helpers.sqrt(1 - zeta * zeta) : 0;
72
+ this.b = zeta < 1 ? (zeta * w0 + -v) / wd : -v + w0;
73
+ let solverTime = 0;
74
+ let restSteps = 0;
75
+ let iterations = 0;
76
+ while (restSteps < maxRestSteps && iterations < maxIterations) {
77
+ if (helpers.abs(1 - this.solve(solverTime)) < restThreshold) {
78
+ restSteps++;
79
+ } else {
80
+ restSteps = 0;
81
+ }
82
+ this.solverDuration = solverTime;
83
+ solverTime += timeStep;
84
+ iterations++;
85
+ }
86
+ this.duration = helpers.round(this.solverDuration * consts.K, 0) * globals.globals.timeScale;
87
+ }
88
+
89
+ get mass() {
90
+ return this.m;
91
+ }
92
+
93
+ set mass(v) {
94
+ this.m = helpers.clamp(values.setValue(v, 1), 0, maxSpringParamValue);
95
+ this.compute();
96
+ }
97
+
98
+ get stiffness() {
99
+ return this.s;
100
+ }
101
+
102
+ set stiffness(v) {
103
+ this.s = helpers.clamp(values.setValue(v, 100), 1, maxSpringParamValue);
104
+ this.compute();
105
+ }
106
+
107
+ get damping() {
108
+ return this.d;
109
+ }
110
+
111
+ set damping(v) {
112
+ this.d = helpers.clamp(values.setValue(v, 10), .1, maxSpringParamValue);
113
+ this.compute();
114
+ }
115
+
116
+ get velocity() {
117
+ return this.v;
118
+ }
119
+
120
+ set velocity(v) {
121
+ this.v = helpers.clamp(values.setValue(v, 0), -maxSpringParamValue, maxSpringParamValue);
122
+ this.compute();
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @param {SpringParams} [parameters]
128
+ * @returns {Spring}
129
+ */
130
+ const createSpring = (parameters) => new Spring(parameters);
131
+
132
+ exports.Spring = Spring;
133
+ exports.createSpring = createSpring;
@@ -0,0 +1,37 @@
1
+ export class Spring {
2
+ /**
3
+ * @param {SpringParams} [parameters]
4
+ */
5
+ constructor(parameters?: SpringParams);
6
+ timeStep: number;
7
+ restThreshold: number;
8
+ restDuration: number;
9
+ maxDuration: number;
10
+ maxRestSteps: number;
11
+ maxIterations: number;
12
+ m: number;
13
+ s: number;
14
+ d: number;
15
+ v: number;
16
+ w0: number;
17
+ zeta: number;
18
+ wd: number;
19
+ b: number;
20
+ solverDuration: number;
21
+ duration: number;
22
+ /** @type {EasingFunction} */
23
+ ease: EasingFunction;
24
+ solve(time: number): number;
25
+ compute(): void;
26
+ set mass(v: number);
27
+ get mass(): number;
28
+ set stiffness(v: number);
29
+ get stiffness(): number;
30
+ set damping(v: number);
31
+ get damping(): number;
32
+ set velocity(v: number);
33
+ get velocity(): number;
34
+ }
35
+ export function createSpring(parameters?: SpringParams): Spring;
36
+ import type { EasingFunction } from '../types/index.js';
37
+ import type { SpringParams } from '../types/index.js';
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Anime.js - spring - ESM
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ import { K, minValue } from '../core/consts.js';
9
+ import { globals } from '../core/globals.js';
10
+ import { clamp, sqrt, abs, round, exp, cos, sin } from '../core/helpers.js';
11
+ import { setValue } from '../core/values.js';
12
+
13
+ /**
14
+ * @import {
15
+ * EasingFunction,
16
+ * SpringParams,
17
+ * } from '../types/index.js'
18
+ */
19
+
20
+ /*
21
+ * Spring ease solver adapted from https://webkit.org/demos/spring/spring.js
22
+ * (c) 2016 Webkit - Apple Inc
23
+ */
24
+
25
+ const maxSpringParamValue = K * 10;
26
+
27
+ class Spring {
28
+ /**
29
+ * @param {SpringParams} [parameters]
30
+ */
31
+ constructor(parameters = {}) {
32
+ this.timeStep = .02; // Interval fed to the solver to calculate duration
33
+ this.restThreshold = .0005; // Values below this threshold are considered resting position
34
+ this.restDuration = 200; // Duration in ms used to check if the spring is resting after reaching restThreshold
35
+ this.maxDuration = 60000; // The maximum allowed spring duration in ms (default 1 min)
36
+ this.maxRestSteps = this.restDuration / this.timeStep / K; // How many steps allowed after reaching restThreshold before stopping the duration calculation
37
+ this.maxIterations = this.maxDuration / this.timeStep / K; // Calculate the maximum iterations allowed based on maxDuration
38
+ this.m = clamp(setValue(parameters.mass, 1), 0, maxSpringParamValue);
39
+ this.s = clamp(setValue(parameters.stiffness, 100), 1, maxSpringParamValue);
40
+ this.d = clamp(setValue(parameters.damping, 10), .1, maxSpringParamValue);
41
+ this.v = clamp(setValue(parameters.velocity, 0), -maxSpringParamValue, maxSpringParamValue);
42
+ this.w0 = 0;
43
+ this.zeta = 0;
44
+ this.wd = 0;
45
+ this.b = 0;
46
+ this.solverDuration = 0;
47
+ this.duration = 0;
48
+ this.compute();
49
+ /** @type {EasingFunction} */
50
+ this.ease = t => t === 0 || t === 1 ? t : this.solve(t * this.solverDuration);
51
+ }
52
+
53
+ /** @type {EasingFunction} */
54
+ solve(time) {
55
+ const { zeta, w0, wd, b } = this;
56
+ let t = time;
57
+ if (zeta < 1) {
58
+ t = exp(-t * zeta * w0) * (1 * cos(wd * t) + b * sin(wd * t));
59
+ } else {
60
+ t = (1 + b * t) * exp(-t * w0);
61
+ }
62
+ return 1 - t;
63
+ }
64
+
65
+ compute() {
66
+ const { maxRestSteps, maxIterations, restThreshold, timeStep, m, d, s, v } = this;
67
+ const w0 = this.w0 = clamp(sqrt(s / m), minValue, K);
68
+ const zeta = this.zeta = d / (2 * sqrt(s * m));
69
+ const wd = this.wd = zeta < 1 ? w0 * sqrt(1 - zeta * zeta) : 0;
70
+ this.b = zeta < 1 ? (zeta * w0 + -v) / wd : -v + w0;
71
+ let solverTime = 0;
72
+ let restSteps = 0;
73
+ let iterations = 0;
74
+ while (restSteps < maxRestSteps && iterations < maxIterations) {
75
+ if (abs(1 - this.solve(solverTime)) < restThreshold) {
76
+ restSteps++;
77
+ } else {
78
+ restSteps = 0;
79
+ }
80
+ this.solverDuration = solverTime;
81
+ solverTime += timeStep;
82
+ iterations++;
83
+ }
84
+ this.duration = round(this.solverDuration * K, 0) * globals.timeScale;
85
+ }
86
+
87
+ get mass() {
88
+ return this.m;
89
+ }
90
+
91
+ set mass(v) {
92
+ this.m = clamp(setValue(v, 1), 0, maxSpringParamValue);
93
+ this.compute();
94
+ }
95
+
96
+ get stiffness() {
97
+ return this.s;
98
+ }
99
+
100
+ set stiffness(v) {
101
+ this.s = clamp(setValue(v, 100), 1, maxSpringParamValue);
102
+ this.compute();
103
+ }
104
+
105
+ get damping() {
106
+ return this.d;
107
+ }
108
+
109
+ set damping(v) {
110
+ this.d = clamp(setValue(v, 10), .1, maxSpringParamValue);
111
+ this.compute();
112
+ }
113
+
114
+ get velocity() {
115
+ return this.v;
116
+ }
117
+
118
+ set velocity(v) {
119
+ this.v = clamp(setValue(v, 0), -maxSpringParamValue, maxSpringParamValue);
120
+ this.compute();
121
+ }
122
+ }
123
+
124
+ /**
125
+ * @param {SpringParams} [parameters]
126
+ * @returns {Spring}
127
+ */
128
+ const createSpring = (parameters) => new Spring(parameters);
129
+
130
+ export { Spring, createSpring };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Anime.js - svg - CJS
3
+ * @version v4.2.0
4
+ * @license MIT
5
+ * @copyright 2025 - Julian Garnier
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var consts = require('../core/consts.cjs');
11
+ var helpers = require('../core/helpers.cjs');
12
+ var targets = require('../core/targets.cjs');
13
+
14
+ /**
15
+ * @import {
16
+ * TargetsParam,
17
+ * DrawableSVGGeometry,
18
+ * } from '../types/index.js'
19
+ */
20
+
21
+ /**
22
+ * @param {SVGGeometryElement} [$el]
23
+ * @return {Number}
24
+ */
25
+ const getScaleFactor = $el => {
26
+ let scaleFactor = 1;
27
+ if ($el && $el.getCTM) {
28
+ const ctm = $el.getCTM();
29
+ if (ctm) {
30
+ const scaleX = helpers.sqrt(ctm.a * ctm.a + ctm.b * ctm.b);
31
+ const scaleY = helpers.sqrt(ctm.c * ctm.c + ctm.d * ctm.d);
32
+ scaleFactor = (scaleX + scaleY) / 2;
33
+ }
34
+ }
35
+ return scaleFactor;
36
+ };
37
+
38
+ /**
39
+ * Creates a proxy that wraps an SVGGeometryElement and adds drawing functionality.
40
+ * @param {SVGGeometryElement} $el - The SVG element to transform into a drawable
41
+ * @param {number} start - Starting position (0-1)
42
+ * @param {number} end - Ending position (0-1)
43
+ * @return {DrawableSVGGeometry} - Returns a proxy that preserves the original element's type with additional 'draw' attribute functionality
44
+ */
45
+ const createDrawableProxy = ($el, start, end) => {
46
+ const pathLength = consts.K;
47
+ const computedStyles = getComputedStyle($el);
48
+ const strokeLineCap = computedStyles.strokeLinecap;
49
+ // @ts-ignore
50
+ const $scalled = computedStyles.vectorEffect === 'non-scaling-stroke' ? $el : null;
51
+ let currentCap = strokeLineCap;
52
+
53
+ const proxy = new Proxy($el, {
54
+ get(target, property) {
55
+ const value = target[property];
56
+ if (property === consts.proxyTargetSymbol) return target;
57
+ if (property === 'setAttribute') {
58
+ return (...args) => {
59
+ if (args[0] === 'draw') {
60
+ const value = args[1];
61
+ const values = value.split(' ');
62
+ const v1 = +values[0];
63
+ const v2 = +values[1];
64
+ // TOTO: Benchmark if performing two slices is more performant than one split
65
+ // const spaceIndex = value.indexOf(' ');
66
+ // const v1 = round(+value.slice(0, spaceIndex), precision);
67
+ // const v2 = round(+value.slice(spaceIndex + 1), precision);
68
+ const scaleFactor = getScaleFactor($scalled);
69
+ const os = v1 * -pathLength * scaleFactor;
70
+ const d1 = (v2 * pathLength * scaleFactor) + os;
71
+ const d2 = (pathLength * scaleFactor +
72
+ ((v1 === 0 && v2 === 1) || (v1 === 1 && v2 === 0) ? 0 : 10 * scaleFactor) - d1);
73
+ if (strokeLineCap !== 'butt') {
74
+ const newCap = v1 === v2 ? 'butt' : strokeLineCap;
75
+ if (currentCap !== newCap) {
76
+ target.style.strokeLinecap = `${newCap}`;
77
+ currentCap = newCap;
78
+ }
79
+ }
80
+ target.setAttribute('stroke-dashoffset', `${os}`);
81
+ target.setAttribute('stroke-dasharray', `${d1} ${d2}`);
82
+ }
83
+ return Reflect.apply(value, target, args);
84
+ };
85
+ }
86
+
87
+ if (helpers.isFnc(value)) {
88
+ return (...args) => Reflect.apply(value, target, args);
89
+ } else {
90
+ return value;
91
+ }
92
+ }
93
+ });
94
+
95
+ if ($el.getAttribute('pathLength') !== `${pathLength}`) {
96
+ $el.setAttribute('pathLength', `${pathLength}`);
97
+ proxy.setAttribute('draw', `${start} ${end}`);
98
+ }
99
+
100
+ return /** @type {DrawableSVGGeometry} */(proxy);
101
+ };
102
+
103
+ /**
104
+ * Creates drawable proxies for multiple SVG elements.
105
+ * @param {TargetsParam} selector - CSS selector, SVG element, or array of elements and selectors
106
+ * @param {number} [start=0] - Starting position (0-1)
107
+ * @param {number} [end=0] - Ending position (0-1)
108
+ * @return {Array<DrawableSVGGeometry>} - Array of proxied elements with drawing functionality
109
+ */
110
+ const createDrawable = (selector, start = 0, end = 0) => {
111
+ const els = targets.parseTargets(selector);
112
+ return els.map($el => createDrawableProxy(
113
+ /** @type {SVGGeometryElement} */($el),
114
+ start,
115
+ end
116
+ ));
117
+ };
118
+
119
+ exports.createDrawable = createDrawable;
@@ -0,0 +1,3 @@
1
+ export function createDrawable(selector: TargetsParam, start?: number, end?: number): Array<DrawableSVGGeometry>;
2
+ import type { TargetsParam } from '../types/index.js';
3
+ import type { DrawableSVGGeometry } from '../types/index.js';