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.
- package/README.md +17 -8
- package/{lib → dist/bundles}/anime.esm.js +6476 -6106
- package/dist/bundles/anime.esm.min.js +7 -0
- package/dist/bundles/anime.umd.js +8809 -0
- package/dist/bundles/anime.umd.min.js +7 -0
- package/dist/modules/animatable/animatable.cjs +150 -0
- package/dist/modules/animatable/animatable.d.ts +28 -0
- package/dist/modules/animatable/animatable.js +147 -0
- package/dist/modules/animatable/index.cjs +15 -0
- package/dist/modules/animatable/index.d.ts +1 -0
- package/dist/modules/animatable/index.js +8 -0
- package/dist/modules/animation/additive.cjs +82 -0
- package/dist/modules/animation/additive.d.ts +15 -0
- package/dist/modules/animation/additive.js +79 -0
- package/dist/modules/animation/animation.cjs +667 -0
- package/dist/modules/animation/animation.d.ts +45 -0
- package/dist/modules/animation/animation.js +664 -0
- package/dist/modules/animation/composition.cjs +383 -0
- package/dist/modules/animation/composition.d.ts +10 -0
- package/dist/modules/animation/composition.js +377 -0
- package/dist/modules/animation/index.cjs +15 -0
- package/dist/modules/animation/index.d.ts +1 -0
- package/dist/modules/animation/index.js +8 -0
- package/dist/modules/core/clock.cjs +110 -0
- package/dist/modules/core/clock.d.ts +51 -0
- package/dist/modules/core/clock.js +108 -0
- package/dist/modules/core/colors.cjs +102 -0
- package/dist/modules/core/colors.d.ts +2 -0
- package/dist/modules/core/colors.js +100 -0
- package/dist/modules/core/consts.cjs +159 -0
- package/dist/modules/core/consts.d.ts +61 -0
- package/dist/modules/core/consts.js +124 -0
- package/dist/modules/core/globals.cjs +78 -0
- package/dist/modules/core/globals.d.ts +29 -0
- package/dist/modules/core/globals.js +73 -0
- package/dist/modules/core/helpers.cjs +304 -0
- package/dist/modules/core/helpers.d.ts +43 -0
- package/dist/modules/core/helpers.js +261 -0
- package/dist/modules/core/render.cjs +391 -0
- package/dist/modules/core/render.d.ts +4 -0
- package/dist/modules/core/render.js +388 -0
- package/dist/modules/core/styles.cjs +116 -0
- package/dist/modules/core/styles.d.ts +5 -0
- package/dist/modules/core/styles.js +113 -0
- package/dist/modules/core/targets.cjs +136 -0
- package/dist/modules/core/targets.d.ts +118 -0
- package/dist/modules/core/targets.js +132 -0
- package/dist/modules/core/transforms.cjs +49 -0
- package/dist/modules/core/transforms.d.ts +2 -0
- package/dist/modules/core/transforms.js +47 -0
- package/dist/modules/core/units.cjs +67 -0
- package/dist/modules/core/units.d.ts +3 -0
- package/dist/modules/core/units.js +65 -0
- package/dist/modules/core/values.cjs +226 -0
- package/dist/modules/core/values.d.ts +14 -0
- package/dist/modules/core/values.js +216 -0
- package/dist/modules/draggable/draggable.cjs +1226 -0
- package/dist/modules/draggable/draggable.d.ts +272 -0
- package/dist/modules/draggable/draggable.js +1223 -0
- package/dist/modules/draggable/index.cjs +15 -0
- package/dist/modules/draggable/index.d.ts +1 -0
- package/dist/modules/draggable/index.js +8 -0
- package/dist/modules/easings/cubic-bezier/index.cjs +64 -0
- package/dist/modules/easings/cubic-bezier/index.d.ts +2 -0
- package/dist/modules/easings/cubic-bezier/index.js +62 -0
- package/dist/modules/easings/eases/index.cjs +14 -0
- package/dist/modules/easings/eases/index.d.ts +1 -0
- package/dist/modules/easings/eases/index.js +8 -0
- package/dist/modules/easings/eases/parser.cjs +191 -0
- package/dist/modules/easings/eases/parser.d.ts +125 -0
- package/dist/modules/easings/eases/parser.js +185 -0
- package/dist/modules/easings/index.cjs +26 -0
- package/dist/modules/easings/index.d.ts +6 -0
- package/dist/modules/easings/index.js +13 -0
- package/dist/modules/easings/irregular/index.cjs +41 -0
- package/dist/modules/easings/irregular/index.d.ts +2 -0
- package/dist/modules/easings/irregular/index.js +39 -0
- package/dist/modules/easings/linear/index.cjs +59 -0
- package/dist/modules/easings/linear/index.d.ts +2 -0
- package/dist/modules/easings/linear/index.js +57 -0
- package/dist/modules/easings/none.cjs +19 -0
- package/dist/modules/easings/none.d.ts +8 -0
- package/dist/modules/easings/none.js +17 -0
- package/dist/modules/easings/spring/index.cjs +255 -0
- package/dist/modules/easings/spring/index.d.ts +53 -0
- package/dist/modules/easings/spring/index.js +251 -0
- package/dist/modules/easings/steps/index.cjs +30 -0
- package/dist/modules/easings/steps/index.d.ts +2 -0
- package/dist/modules/easings/steps/index.js +28 -0
- package/dist/modules/engine/engine.cjs +168 -0
- package/dist/modules/engine/engine.d.ts +21 -0
- package/dist/modules/engine/engine.js +166 -0
- package/dist/modules/engine/index.cjs +14 -0
- package/dist/modules/engine/index.d.ts +1 -0
- package/dist/modules/engine/index.js +8 -0
- package/dist/modules/events/index.cjs +16 -0
- package/dist/modules/events/index.d.ts +1 -0
- package/dist/modules/events/index.js +8 -0
- package/dist/modules/events/scroll.cjs +940 -0
- package/dist/modules/events/scroll.d.ts +191 -0
- package/dist/modules/events/scroll.js +936 -0
- package/dist/modules/index.cjs +102 -0
- package/dist/modules/index.d.ts +18 -0
- package/dist/modules/index.js +41 -0
- package/dist/modules/scope/index.cjs +15 -0
- package/dist/modules/scope/index.d.ts +1 -0
- package/dist/modules/scope/index.js +8 -0
- package/dist/modules/scope/scope.cjs +254 -0
- package/dist/modules/scope/scope.d.ts +115 -0
- package/dist/modules/scope/scope.js +251 -0
- package/dist/modules/svg/drawable.cjs +119 -0
- package/dist/modules/svg/drawable.d.ts +3 -0
- package/dist/modules/svg/drawable.js +117 -0
- package/dist/modules/svg/helpers.cjs +30 -0
- package/dist/modules/svg/helpers.d.ts +2 -0
- package/dist/modules/svg/helpers.js +28 -0
- package/dist/modules/svg/index.cjs +18 -0
- package/dist/modules/svg/index.d.ts +3 -0
- package/dist/modules/svg/index.js +10 -0
- package/dist/modules/svg/morphto.cjs +58 -0
- package/dist/modules/svg/morphto.d.ts +3 -0
- package/dist/modules/svg/morphto.js +56 -0
- package/dist/modules/svg/motionpath.cjs +79 -0
- package/dist/modules/svg/motionpath.d.ts +7 -0
- package/dist/modules/svg/motionpath.js +77 -0
- package/dist/modules/text/index.cjs +16 -0
- package/dist/modules/text/index.d.ts +1 -0
- package/dist/modules/text/index.js +8 -0
- package/dist/modules/text/split.cjs +488 -0
- package/dist/modules/text/split.d.ts +62 -0
- package/dist/modules/text/split.js +484 -0
- package/dist/modules/timeline/index.cjs +15 -0
- package/dist/modules/timeline/index.d.ts +1 -0
- package/dist/modules/timeline/index.js +8 -0
- package/dist/modules/timeline/position.cjs +72 -0
- package/dist/modules/timeline/position.d.ts +3 -0
- package/dist/modules/timeline/position.js +70 -0
- package/dist/modules/timeline/timeline.cjs +312 -0
- package/dist/modules/timeline/timeline.d.ts +163 -0
- package/dist/modules/timeline/timeline.js +309 -0
- package/dist/modules/timer/index.cjs +15 -0
- package/dist/modules/timer/index.d.ts +1 -0
- package/dist/modules/timer/index.js +8 -0
- package/dist/modules/timer/timer.cjs +491 -0
- package/dist/modules/timer/timer.d.ts +141 -0
- package/dist/modules/timer/timer.js +488 -0
- package/dist/modules/types/index.d.ts +404 -0
- package/dist/modules/utils/chainable.cjs +190 -0
- package/dist/modules/utils/chainable.d.ts +135 -0
- package/dist/modules/utils/chainable.js +177 -0
- package/dist/modules/utils/index.cjs +43 -0
- package/dist/modules/utils/index.d.ts +5 -0
- package/dist/modules/utils/index.js +14 -0
- package/dist/modules/utils/number.cjs +97 -0
- package/dist/modules/utils/number.d.ts +9 -0
- package/dist/modules/utils/number.js +85 -0
- package/dist/modules/utils/random.cjs +77 -0
- package/dist/modules/utils/random.d.ts +22 -0
- package/dist/modules/utils/random.js +72 -0
- package/dist/modules/utils/stagger.cjs +122 -0
- package/dist/modules/utils/stagger.d.ts +30 -0
- package/dist/modules/utils/stagger.js +120 -0
- package/dist/modules/utils/target.cjs +130 -0
- package/dist/modules/utils/target.d.ts +126 -0
- package/dist/modules/utils/target.js +125 -0
- package/dist/modules/utils/time.cjs +57 -0
- package/dist/modules/utils/time.d.ts +5 -0
- package/dist/modules/utils/time.js +54 -0
- package/dist/modules/waapi/composition.cjs +95 -0
- package/dist/modules/waapi/composition.d.ts +4 -0
- package/dist/modules/waapi/composition.js +92 -0
- package/dist/modules/waapi/index.cjs +15 -0
- package/dist/modules/waapi/index.d.ts +1 -0
- package/dist/modules/waapi/index.js +8 -0
- package/dist/modules/waapi/waapi.cjs +492 -0
- package/dist/modules/waapi/waapi.d.ts +116 -0
- package/dist/modules/waapi/waapi.js +489 -0
- package/package.json +166 -33
- package/lib/anime.cjs +0 -9
- package/lib/anime.esm.min.js +0 -9
- package/lib/anime.iife.js +0 -9
- package/lib/anime.iife.min.js +0 -9
- package/lib/anime.min.cjs +0 -9
- package/lib/anime.umd.js +0 -9
- package/lib/anime.umd.min.js +0 -9
- package/lib/gui/index.js +0 -6341
- package/types/index.d.ts +0 -1127
- package/types/index.js +0 -7395
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - easings - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { K, minValue, noop } from '../../core/consts.js';
|
|
9
|
+
import { globals } from '../../core/globals.js';
|
|
10
|
+
import { isUnd, clamp, pow, PI, round, sqrt, abs, exp, cos, sin } from '../../core/helpers.js';
|
|
11
|
+
import { setValue } from '../../core/values.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @import {
|
|
15
|
+
* JSAnimation,
|
|
16
|
+
* } from '../../animation/animation.js'
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @import {
|
|
21
|
+
* EasingFunction,
|
|
22
|
+
* SpringParams,
|
|
23
|
+
* Callback,
|
|
24
|
+
* } from '../../types/index.js'
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Spring easing solver adapted from https://webkit.org/demos/spring/spring.js
|
|
29
|
+
* (c) 2016 Webkit - Apple Inc
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const maxSpringParamValue = K * 10;
|
|
33
|
+
|
|
34
|
+
class Spring {
|
|
35
|
+
/**
|
|
36
|
+
* @param {SpringParams} [parameters]
|
|
37
|
+
*/
|
|
38
|
+
constructor(parameters = {}) {
|
|
39
|
+
const hasBounceOrDuration = !isUnd(parameters.bounce) || !isUnd(parameters.duration);
|
|
40
|
+
this.timeStep = .02; // Interval fed to the solver to calculate duration
|
|
41
|
+
this.restThreshold = .0005; // Values below this threshold are considered resting position
|
|
42
|
+
this.restDuration = 200; // Duration in ms used to check if the spring is resting after reaching restThreshold
|
|
43
|
+
this.maxDuration = 60000; // The maximum allowed spring duration in ms (default 1 min)
|
|
44
|
+
this.maxRestSteps = this.restDuration / this.timeStep / K; // How many steps allowed after reaching restThreshold before stopping the duration calculation
|
|
45
|
+
this.maxIterations = this.maxDuration / this.timeStep / K; // Calculate the maximum iterations allowed based on maxDuration
|
|
46
|
+
this.bn = clamp(setValue(parameters.bounce, .5), -1, 1); // The bounce percentage between -1 and 1.
|
|
47
|
+
this.pd = clamp(setValue(parameters.duration, 628), 10 * globals.timeScale, maxSpringParamValue * globals.timeScale); // The perceived duration
|
|
48
|
+
this.m = clamp(setValue(parameters.mass, 1), 1, maxSpringParamValue);
|
|
49
|
+
this.s = clamp(setValue(parameters.stiffness, 100), minValue, maxSpringParamValue);
|
|
50
|
+
this.d = clamp(setValue(parameters.damping, 10), minValue, maxSpringParamValue);
|
|
51
|
+
this.v = clamp(setValue(parameters.velocity, 0), -maxSpringParamValue, maxSpringParamValue);
|
|
52
|
+
this.w0 = 0;
|
|
53
|
+
this.zeta = 0;
|
|
54
|
+
this.wd = 0;
|
|
55
|
+
this.b = 0;
|
|
56
|
+
this.completed = false;
|
|
57
|
+
this.solverDuration = 0;
|
|
58
|
+
this.settlingDuration = 0;
|
|
59
|
+
/** @type {JSAnimation} */
|
|
60
|
+
this.parent = null;
|
|
61
|
+
/** @type {Callback<JSAnimation>} */
|
|
62
|
+
this.onComplete = parameters.onComplete || noop;
|
|
63
|
+
if (hasBounceOrDuration) this.calculateSDFromBD();
|
|
64
|
+
this.compute();
|
|
65
|
+
/** @type {EasingFunction} */
|
|
66
|
+
this.ease = t => {
|
|
67
|
+
const currentTime = t * this.settlingDuration;
|
|
68
|
+
const completed = this.completed;
|
|
69
|
+
const perceivedTime = this.pd;
|
|
70
|
+
if (currentTime >= perceivedTime && !completed) {
|
|
71
|
+
this.completed = true;
|
|
72
|
+
this.onComplete(this.parent);
|
|
73
|
+
}
|
|
74
|
+
if (currentTime < perceivedTime && completed) {
|
|
75
|
+
this.completed = false;
|
|
76
|
+
}
|
|
77
|
+
return t === 0 || t === 1 ? t : this.solve(t * this.solverDuration);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @type {EasingFunction} */
|
|
82
|
+
solve(time) {
|
|
83
|
+
const { zeta, w0, wd, b } = this;
|
|
84
|
+
let t = time;
|
|
85
|
+
if (zeta < 1) {
|
|
86
|
+
// Underdamped
|
|
87
|
+
t = exp(-t * zeta * w0) * (1 * cos(wd * t) + b * sin(wd * t));
|
|
88
|
+
} else if (zeta === 1) {
|
|
89
|
+
// Critically damped
|
|
90
|
+
t = (1 + b * t) * exp(-t * w0);
|
|
91
|
+
} else {
|
|
92
|
+
// Overdamped
|
|
93
|
+
// Using exponential instead of cosh and sinh functions to prevent Infinity
|
|
94
|
+
// Original exp(-zeta * w0 * t) * (cosh(wd * t) + b * sinh(wd * t))
|
|
95
|
+
t = ((1 + b) * exp((-zeta * w0 + wd) * t) + (1 - b) * exp((-zeta * w0 - wd) * t)) / 2;
|
|
96
|
+
}
|
|
97
|
+
return 1 - t;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
calculateSDFromBD() {
|
|
101
|
+
// Apple's SwiftUI perceived spring duration implementation https://developer.apple.com/videos/play/wwdc2023/10158/?time=1010
|
|
102
|
+
// Equations taken from Kevin Grajeda's article https://www.kvin.me/posts/effortless-ui-spring-animations
|
|
103
|
+
const pds = globals.timeScale === 1 ? this.pd / K : this.pd;
|
|
104
|
+
// Mass and velocity should be set to their default values
|
|
105
|
+
this.m = 1;
|
|
106
|
+
this.v = 0;
|
|
107
|
+
// Stiffness = (2π ÷ perceptualDuration)²
|
|
108
|
+
this.s = pow((2 * PI) / pds, 2);
|
|
109
|
+
if (this.bn >= 0) {
|
|
110
|
+
// For bounce ≥ 0 (critically damped to underdamped)
|
|
111
|
+
// damping = ((1 - bounce) × 4π) ÷ perceptualDuration
|
|
112
|
+
this.d = ((1 - this.bn) * 4 * PI) / pds;
|
|
113
|
+
} else {
|
|
114
|
+
// For bounce < 0 (overdamped)
|
|
115
|
+
// damping = 4π ÷ (perceptualDuration × (1 + bounce))
|
|
116
|
+
// Note: (1 + bounce) is positive since bounce is negative
|
|
117
|
+
this.d = (4 * PI) / (pds * (1 + this.bn));
|
|
118
|
+
}
|
|
119
|
+
this.s = round(clamp(this.s, minValue, maxSpringParamValue), 3);
|
|
120
|
+
this.d = round(clamp(this.d, minValue, 300), 3); // Clamping to 300 is needed to prevent insane values in the solver
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
calculateBDFromSD() {
|
|
124
|
+
// Calculate perceived duration and bounce from stiffness and damping
|
|
125
|
+
// Note: We assumes m = 1 and v = 0 for these calculations
|
|
126
|
+
const pds = (2 * PI) / sqrt(this.s);
|
|
127
|
+
this.pd = pds * (globals.timeScale === 1 ? K : 1);
|
|
128
|
+
const zeta = this.d / (2 * sqrt(this.s));
|
|
129
|
+
if (zeta <= 1) {
|
|
130
|
+
// Critically damped to underdamped
|
|
131
|
+
this.bn = 1 - (this.d * pds) / (4 * PI);
|
|
132
|
+
} else {
|
|
133
|
+
// Overdamped
|
|
134
|
+
this.bn = (4 * PI) / (this.d * pds) - 1;
|
|
135
|
+
}
|
|
136
|
+
this.bn = round(clamp(this.bn, -1, 1), 3);
|
|
137
|
+
this.pd = round(clamp(this.pd, 10 * globals.timeScale, maxSpringParamValue * globals.timeScale), 3);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
compute() {
|
|
141
|
+
const { maxRestSteps, maxIterations, restThreshold, timeStep, m, d, s, v } = this;
|
|
142
|
+
const w0 = this.w0 = clamp(sqrt(s / m), minValue, K);
|
|
143
|
+
const bouncedZeta = this.zeta = d / (2 * sqrt(s * m));
|
|
144
|
+
// Calculate wd based on damping type
|
|
145
|
+
if (bouncedZeta < 1) {
|
|
146
|
+
// Underdamped
|
|
147
|
+
this.wd = w0 * sqrt(1 - bouncedZeta * bouncedZeta);
|
|
148
|
+
this.b = (bouncedZeta * w0 + -v) / this.wd;
|
|
149
|
+
} else if (bouncedZeta === 1) {
|
|
150
|
+
// Critically damped
|
|
151
|
+
this.wd = 0;
|
|
152
|
+
this.b = -v + w0;
|
|
153
|
+
} else {
|
|
154
|
+
// Overdamped
|
|
155
|
+
this.wd = w0 * sqrt(bouncedZeta * bouncedZeta - 1);
|
|
156
|
+
this.b = (bouncedZeta * w0 + -v) / this.wd;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let solverTime = 0;
|
|
160
|
+
let restSteps = 0;
|
|
161
|
+
let iterations = 0;
|
|
162
|
+
while (restSteps <= maxRestSteps && iterations <= maxIterations) {
|
|
163
|
+
if (abs(1 - this.solve(solverTime)) < restThreshold) {
|
|
164
|
+
restSteps++;
|
|
165
|
+
} else {
|
|
166
|
+
restSteps = 0;
|
|
167
|
+
}
|
|
168
|
+
this.solverDuration = solverTime;
|
|
169
|
+
solverTime += timeStep;
|
|
170
|
+
iterations++;
|
|
171
|
+
}
|
|
172
|
+
this.settlingDuration = round(this.solverDuration * K, 0) * globals.timeScale;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
get bounce() {
|
|
176
|
+
return this.bn;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
set bounce(v) {
|
|
180
|
+
this.bn = clamp(setValue(v, 1), -1, 1);
|
|
181
|
+
this.calculateSDFromBD();
|
|
182
|
+
this.compute();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
get duration() {
|
|
186
|
+
return this.pd;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
set duration(v) {
|
|
190
|
+
this.pd = clamp(setValue(v, 1), 10 * globals.timeScale, maxSpringParamValue * globals.timeScale);
|
|
191
|
+
this.calculateSDFromBD();
|
|
192
|
+
this.compute();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
get stiffness() {
|
|
196
|
+
return this.s;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
set stiffness(v) {
|
|
200
|
+
this.s = clamp(setValue(v, 100), minValue, maxSpringParamValue);
|
|
201
|
+
this.calculateBDFromSD();
|
|
202
|
+
this.compute();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
get damping() {
|
|
206
|
+
return this.d;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
set damping(v) {
|
|
210
|
+
this.d = clamp(setValue(v, 10), minValue, maxSpringParamValue);
|
|
211
|
+
this.calculateBDFromSD();
|
|
212
|
+
this.compute();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
get mass() {
|
|
216
|
+
return this.m;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
set mass(v) {
|
|
220
|
+
this.m = clamp(setValue(v, 1), 1, maxSpringParamValue);
|
|
221
|
+
this.compute();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
get velocity() {
|
|
225
|
+
return this.v;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
set velocity(v) {
|
|
229
|
+
this.v = clamp(setValue(v, 0), -maxSpringParamValue, maxSpringParamValue);
|
|
230
|
+
this.compute();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @param {SpringParams} [parameters]
|
|
236
|
+
* @returns {Spring}
|
|
237
|
+
*/
|
|
238
|
+
const spring = (parameters) => new Spring(parameters);
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @deprecated createSpring() is deprecated use spring() instead
|
|
242
|
+
*
|
|
243
|
+
* @param {SpringParams} [parameters]
|
|
244
|
+
* @returns {Spring}
|
|
245
|
+
*/
|
|
246
|
+
const createSpring = (parameters) => {
|
|
247
|
+
console.warn('createSpring() is deprecated use spring() instead');
|
|
248
|
+
return new Spring(parameters);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export { Spring, createSpring, spring };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - easings - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var helpers = require('../../core/helpers.cjs');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import {
|
|
14
|
+
* EasingFunction,
|
|
15
|
+
* } from '../../types/index.js'
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Steps ease implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function
|
|
20
|
+
* Only covers 'end' and 'start' jumpterms
|
|
21
|
+
* @param {Number} steps
|
|
22
|
+
* @param {Boolean} [fromStart]
|
|
23
|
+
* @return {EasingFunction}
|
|
24
|
+
*/
|
|
25
|
+
const steps = (steps = 10, fromStart) => {
|
|
26
|
+
const roundMethod = fromStart ? helpers.ceil : helpers.floor;
|
|
27
|
+
return t => roundMethod(helpers.clamp(t, 0, 1) * steps) * (1 / steps);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.steps = steps;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - easings - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ceil, floor, clamp } from '../../core/helpers.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @import {
|
|
12
|
+
* EasingFunction,
|
|
13
|
+
* } from '../../types/index.js'
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Steps ease implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function
|
|
18
|
+
* Only covers 'end' and 'start' jumpterms
|
|
19
|
+
* @param {Number} steps
|
|
20
|
+
* @param {Boolean} [fromStart]
|
|
21
|
+
* @return {EasingFunction}
|
|
22
|
+
*/
|
|
23
|
+
const steps = (steps = 10, fromStart) => {
|
|
24
|
+
const roundMethod = fromStart ? ceil : floor;
|
|
25
|
+
return t => roundMethod(clamp(t, 0, 1) * steps) * (1 / steps);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { steps };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - engine - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var globals = require('../core/globals.cjs');
|
|
11
|
+
var consts = require('../core/consts.cjs');
|
|
12
|
+
var helpers = require('../core/helpers.cjs');
|
|
13
|
+
var clock = require('../core/clock.cjs');
|
|
14
|
+
var render = require('../core/render.cjs');
|
|
15
|
+
var additive = require('../animation/additive.cjs');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @import {
|
|
19
|
+
* DefaultsParams,
|
|
20
|
+
* } from '../types/index.js'
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @import {
|
|
25
|
+
* Tickable,
|
|
26
|
+
* } from '../types/index.js'
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const engineTickMethod = /*#__PURE__*/ (() => consts.isBrowser ? requestAnimationFrame : setImmediate)();
|
|
30
|
+
const engineCancelMethod = /*#__PURE__*/ (() => consts.isBrowser ? cancelAnimationFrame : clearImmediate)();
|
|
31
|
+
|
|
32
|
+
class Engine extends clock.Clock {
|
|
33
|
+
|
|
34
|
+
/** @param {Number} [initTime] */
|
|
35
|
+
constructor(initTime) {
|
|
36
|
+
super(initTime);
|
|
37
|
+
this.useDefaultMainLoop = true;
|
|
38
|
+
this.pauseOnDocumentHidden = true;
|
|
39
|
+
/** @type {DefaultsParams} */
|
|
40
|
+
this.defaults = globals.defaults;
|
|
41
|
+
// this.paused = isBrowser && doc.hidden ? true : false;
|
|
42
|
+
this.paused = true;
|
|
43
|
+
/** @type {Number|NodeJS.Immediate} */
|
|
44
|
+
this.reqId = 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
update() {
|
|
48
|
+
const time = this._currentTime = helpers.now();
|
|
49
|
+
if (this.requestTick(time)) {
|
|
50
|
+
this.computeDeltaTime(time);
|
|
51
|
+
const engineSpeed = this._speed;
|
|
52
|
+
const engineFps = this._fps;
|
|
53
|
+
let activeTickable = /** @type {Tickable} */(this._head);
|
|
54
|
+
while (activeTickable) {
|
|
55
|
+
const nextTickable = activeTickable._next;
|
|
56
|
+
if (!activeTickable.paused) {
|
|
57
|
+
render.tick(
|
|
58
|
+
activeTickable,
|
|
59
|
+
(time - activeTickable._startTime) * activeTickable._speed * engineSpeed,
|
|
60
|
+
0, // !muteCallbacks
|
|
61
|
+
0, // !internalRender
|
|
62
|
+
activeTickable._fps < engineFps ? activeTickable.requestTick(time) : consts.tickModes.AUTO
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
helpers.removeChild(this, activeTickable);
|
|
66
|
+
this._hasChildren = !!this._tail;
|
|
67
|
+
activeTickable._running = false;
|
|
68
|
+
if (activeTickable.completed && !activeTickable._cancelled) {
|
|
69
|
+
activeTickable.cancel();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
activeTickable = nextTickable;
|
|
73
|
+
}
|
|
74
|
+
additive.additive.update();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
wake() {
|
|
79
|
+
if (this.useDefaultMainLoop && !this.reqId) {
|
|
80
|
+
// Imediatly request a tick to update engine._elapsedTime and get accurate offsetPosition calculation in timer.js
|
|
81
|
+
this.requestTick(helpers.now());
|
|
82
|
+
this.reqId = engineTickMethod(tickEngine);
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
pause() {
|
|
88
|
+
if (!this.reqId) return;
|
|
89
|
+
this.paused = true;
|
|
90
|
+
return killEngine();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
resume() {
|
|
94
|
+
if (!this.paused) return;
|
|
95
|
+
this.paused = false;
|
|
96
|
+
helpers.forEachChildren(this, (/** @type {Tickable} */child) => child.resetTime());
|
|
97
|
+
return this.wake();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Getter and setter for speed
|
|
101
|
+
get speed() {
|
|
102
|
+
return this._speed * (globals.globals.timeScale === 1 ? 1 : consts.K);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
set speed(playbackRate) {
|
|
106
|
+
this._speed = playbackRate * globals.globals.timeScale;
|
|
107
|
+
helpers.forEachChildren(this, (/** @type {Tickable} */child) => child.speed = child._speed);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Getter and setter for timeUnit
|
|
111
|
+
get timeUnit() {
|
|
112
|
+
return globals.globals.timeScale === 1 ? 'ms' : 's';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
set timeUnit(unit) {
|
|
116
|
+
const secondsScale = 0.001;
|
|
117
|
+
const isSecond = unit === 's';
|
|
118
|
+
const newScale = isSecond ? secondsScale : 1;
|
|
119
|
+
if (globals.globals.timeScale !== newScale) {
|
|
120
|
+
globals.globals.timeScale = newScale;
|
|
121
|
+
globals.globals.tickThreshold = 200 * newScale;
|
|
122
|
+
const scaleFactor = isSecond ? secondsScale : consts.K;
|
|
123
|
+
/** @type {Number} */
|
|
124
|
+
(this.defaults.duration) *= scaleFactor;
|
|
125
|
+
this._speed *= scaleFactor;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Getter and setter for precision
|
|
130
|
+
get precision() {
|
|
131
|
+
return globals.globals.precision;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
set precision(precision) {
|
|
135
|
+
globals.globals.precision = precision;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const engine = /*#__PURE__*/(() => {
|
|
141
|
+
const engine = new Engine(helpers.now());
|
|
142
|
+
if (consts.isBrowser) {
|
|
143
|
+
globals.globalVersions.engine = engine;
|
|
144
|
+
consts.doc.addEventListener('visibilitychange', () => {
|
|
145
|
+
if (!engine.pauseOnDocumentHidden) return;
|
|
146
|
+
consts.doc.hidden ? engine.pause() : engine.resume();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return engine;
|
|
150
|
+
})();
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
const tickEngine = () => {
|
|
154
|
+
if (engine._head) {
|
|
155
|
+
engine.reqId = engineTickMethod(tickEngine);
|
|
156
|
+
engine.update();
|
|
157
|
+
} else {
|
|
158
|
+
engine.reqId = 0;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const killEngine = () => {
|
|
163
|
+
engineCancelMethod(/** @type {NodeJS.Immediate & Number} */(engine.reqId));
|
|
164
|
+
engine.reqId = 0;
|
|
165
|
+
return engine;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
exports.engine = engine;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const engine: Engine;
|
|
2
|
+
declare class Engine extends Clock {
|
|
3
|
+
useDefaultMainLoop: boolean;
|
|
4
|
+
pauseOnDocumentHidden: boolean;
|
|
5
|
+
/** @type {DefaultsParams} */
|
|
6
|
+
defaults: DefaultsParams;
|
|
7
|
+
paused: boolean;
|
|
8
|
+
/** @type {Number|NodeJS.Immediate} */
|
|
9
|
+
reqId: number | NodeJS.Immediate;
|
|
10
|
+
update(): void;
|
|
11
|
+
wake(): this;
|
|
12
|
+
pause(): Engine;
|
|
13
|
+
resume(): this;
|
|
14
|
+
set timeUnit(unit: "ms" | "s");
|
|
15
|
+
get timeUnit(): "ms" | "s";
|
|
16
|
+
set precision(precision: number);
|
|
17
|
+
get precision(): number;
|
|
18
|
+
}
|
|
19
|
+
import { Clock } from '../core/clock.js';
|
|
20
|
+
import type { DefaultsParams } from '../types/index.js';
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - engine - ESM
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { globalVersions, defaults, globals } from '../core/globals.js';
|
|
9
|
+
import { isBrowser, doc, tickModes, K } from '../core/consts.js';
|
|
10
|
+
import { now, removeChild, forEachChildren } from '../core/helpers.js';
|
|
11
|
+
import { Clock } from '../core/clock.js';
|
|
12
|
+
import { tick } from '../core/render.js';
|
|
13
|
+
import { additive } from '../animation/additive.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @import {
|
|
17
|
+
* DefaultsParams,
|
|
18
|
+
* } from '../types/index.js'
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @import {
|
|
23
|
+
* Tickable,
|
|
24
|
+
* } from '../types/index.js'
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const engineTickMethod = /*#__PURE__*/ (() => isBrowser ? requestAnimationFrame : setImmediate)();
|
|
28
|
+
const engineCancelMethod = /*#__PURE__*/ (() => isBrowser ? cancelAnimationFrame : clearImmediate)();
|
|
29
|
+
|
|
30
|
+
class Engine extends Clock {
|
|
31
|
+
|
|
32
|
+
/** @param {Number} [initTime] */
|
|
33
|
+
constructor(initTime) {
|
|
34
|
+
super(initTime);
|
|
35
|
+
this.useDefaultMainLoop = true;
|
|
36
|
+
this.pauseOnDocumentHidden = true;
|
|
37
|
+
/** @type {DefaultsParams} */
|
|
38
|
+
this.defaults = defaults;
|
|
39
|
+
// this.paused = isBrowser && doc.hidden ? true : false;
|
|
40
|
+
this.paused = true;
|
|
41
|
+
/** @type {Number|NodeJS.Immediate} */
|
|
42
|
+
this.reqId = 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
update() {
|
|
46
|
+
const time = this._currentTime = now();
|
|
47
|
+
if (this.requestTick(time)) {
|
|
48
|
+
this.computeDeltaTime(time);
|
|
49
|
+
const engineSpeed = this._speed;
|
|
50
|
+
const engineFps = this._fps;
|
|
51
|
+
let activeTickable = /** @type {Tickable} */(this._head);
|
|
52
|
+
while (activeTickable) {
|
|
53
|
+
const nextTickable = activeTickable._next;
|
|
54
|
+
if (!activeTickable.paused) {
|
|
55
|
+
tick(
|
|
56
|
+
activeTickable,
|
|
57
|
+
(time - activeTickable._startTime) * activeTickable._speed * engineSpeed,
|
|
58
|
+
0, // !muteCallbacks
|
|
59
|
+
0, // !internalRender
|
|
60
|
+
activeTickable._fps < engineFps ? activeTickable.requestTick(time) : tickModes.AUTO
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
removeChild(this, activeTickable);
|
|
64
|
+
this._hasChildren = !!this._tail;
|
|
65
|
+
activeTickable._running = false;
|
|
66
|
+
if (activeTickable.completed && !activeTickable._cancelled) {
|
|
67
|
+
activeTickable.cancel();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
activeTickable = nextTickable;
|
|
71
|
+
}
|
|
72
|
+
additive.update();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
wake() {
|
|
77
|
+
if (this.useDefaultMainLoop && !this.reqId) {
|
|
78
|
+
// Imediatly request a tick to update engine._elapsedTime and get accurate offsetPosition calculation in timer.js
|
|
79
|
+
this.requestTick(now());
|
|
80
|
+
this.reqId = engineTickMethod(tickEngine);
|
|
81
|
+
}
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
pause() {
|
|
86
|
+
if (!this.reqId) return;
|
|
87
|
+
this.paused = true;
|
|
88
|
+
return killEngine();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
resume() {
|
|
92
|
+
if (!this.paused) return;
|
|
93
|
+
this.paused = false;
|
|
94
|
+
forEachChildren(this, (/** @type {Tickable} */child) => child.resetTime());
|
|
95
|
+
return this.wake();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Getter and setter for speed
|
|
99
|
+
get speed() {
|
|
100
|
+
return this._speed * (globals.timeScale === 1 ? 1 : K);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
set speed(playbackRate) {
|
|
104
|
+
this._speed = playbackRate * globals.timeScale;
|
|
105
|
+
forEachChildren(this, (/** @type {Tickable} */child) => child.speed = child._speed);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Getter and setter for timeUnit
|
|
109
|
+
get timeUnit() {
|
|
110
|
+
return globals.timeScale === 1 ? 'ms' : 's';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
set timeUnit(unit) {
|
|
114
|
+
const secondsScale = 0.001;
|
|
115
|
+
const isSecond = unit === 's';
|
|
116
|
+
const newScale = isSecond ? secondsScale : 1;
|
|
117
|
+
if (globals.timeScale !== newScale) {
|
|
118
|
+
globals.timeScale = newScale;
|
|
119
|
+
globals.tickThreshold = 200 * newScale;
|
|
120
|
+
const scaleFactor = isSecond ? secondsScale : K;
|
|
121
|
+
/** @type {Number} */
|
|
122
|
+
(this.defaults.duration) *= scaleFactor;
|
|
123
|
+
this._speed *= scaleFactor;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Getter and setter for precision
|
|
128
|
+
get precision() {
|
|
129
|
+
return globals.precision;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
set precision(precision) {
|
|
133
|
+
globals.precision = precision;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const engine = /*#__PURE__*/(() => {
|
|
139
|
+
const engine = new Engine(now());
|
|
140
|
+
if (isBrowser) {
|
|
141
|
+
globalVersions.engine = engine;
|
|
142
|
+
doc.addEventListener('visibilitychange', () => {
|
|
143
|
+
if (!engine.pauseOnDocumentHidden) return;
|
|
144
|
+
doc.hidden ? engine.pause() : engine.resume();
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return engine;
|
|
148
|
+
})();
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
const tickEngine = () => {
|
|
152
|
+
if (engine._head) {
|
|
153
|
+
engine.reqId = engineTickMethod(tickEngine);
|
|
154
|
+
engine.update();
|
|
155
|
+
} else {
|
|
156
|
+
engine.reqId = 0;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const killEngine = () => {
|
|
161
|
+
engineCancelMethod(/** @type {NodeJS.Immediate & Number} */(engine.reqId));
|
|
162
|
+
engine.reqId = 0;
|
|
163
|
+
return engine;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export { engine };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./engine.js";
|