animejs 4.1.3 → 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.
- package/README.md +12 -8
- package/{lib → dist/bundles}/anime.esm.js +5237 -5049
- package/dist/bundles/anime.esm.min.js +7 -0
- package/dist/bundles/anime.umd.js +8621 -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 +660 -0
- package/dist/modules/animation/animation.d.ts +47 -0
- package/dist/modules/animation/animation.js +657 -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 +154 -0
- package/dist/modules/core/consts.d.ts +59 -0
- package/dist/modules/core/consts.js +121 -0
- package/dist/modules/core/globals.cjs +77 -0
- package/dist/modules/core/globals.d.ts +29 -0
- package/dist/modules/core/globals.js +72 -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 +389 -0
- package/dist/modules/core/render.d.ts +4 -0
- package/dist/modules/core/render.js +386 -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 +215 -0
- package/dist/modules/core/values.d.ts +14 -0
- package/dist/modules/core/values.js +205 -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.cjs +64 -0
- package/dist/modules/easings/cubic-bezier.d.ts +2 -0
- package/dist/modules/easings/cubic-bezier.js +62 -0
- package/dist/modules/easings/eases.cjs +149 -0
- package/dist/modules/easings/eases.d.ts +111 -0
- package/dist/modules/easings/eases.js +146 -0
- package/dist/modules/easings/index.cjs +24 -0
- package/dist/modules/easings/index.d.ts +6 -0
- package/dist/modules/easings/index.js +13 -0
- package/dist/modules/easings/irregular.cjs +41 -0
- package/dist/modules/easings/irregular.d.ts +2 -0
- package/dist/modules/easings/irregular.js +39 -0
- package/dist/modules/easings/linear.cjs +59 -0
- package/dist/modules/easings/linear.d.ts +2 -0
- package/dist/modules/easings/linear.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/parser.cjs +59 -0
- package/dist/modules/easings/parser.d.ts +21 -0
- package/dist/modules/easings/parser.js +55 -0
- package/dist/modules/easings/steps.cjs +30 -0
- package/dist/modules/easings/steps.d.ts +2 -0
- package/dist/modules/easings/steps.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 +936 -0
- package/dist/modules/events/scroll.d.ts +189 -0
- package/dist/modules/events/scroll.js +932 -0
- package/dist/modules/index.cjs +103 -0
- package/dist/modules/index.d.ts +19 -0
- package/dist/modules/index.js +42 -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/spring/index.cjs +15 -0
- package/dist/modules/spring/index.d.ts +1 -0
- package/dist/modules/spring/index.js +8 -0
- package/dist/modules/spring/spring.cjs +133 -0
- package/dist/modules/spring/spring.d.ts +37 -0
- package/dist/modules/spring/spring.js +130 -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 +387 -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 +89 -0
- package/dist/modules/waapi/composition.d.ts +4 -0
- package/dist/modules/waapi/composition.js +86 -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 +473 -0
- package/dist/modules/waapi/waapi.d.ts +114 -0
- package/dist/modules/waapi/waapi.js +470 -0
- package/package.json +130 -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 -1126
- package/types/index.js +0 -7388
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - timer - 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 globals = require('../core/globals.cjs');
|
|
13
|
+
var values = require('../core/values.cjs');
|
|
14
|
+
var render = require('../core/render.cjs');
|
|
15
|
+
var composition = require('../animation/composition.cjs');
|
|
16
|
+
var clock = require('../core/clock.cjs');
|
|
17
|
+
var engine = require('../engine/engine.cjs');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @import {
|
|
21
|
+
* Callback,
|
|
22
|
+
* TimerParams,
|
|
23
|
+
* Renderable,
|
|
24
|
+
* Tween,
|
|
25
|
+
* } from '../types/index.js'
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @import {
|
|
30
|
+
* ScrollObserver,
|
|
31
|
+
* } from '../events/scroll.js'
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @import {
|
|
36
|
+
* Timeline,
|
|
37
|
+
* } from '../timeline/timeline.js'
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {Timer} timer
|
|
42
|
+
* @return {Timer}
|
|
43
|
+
*/
|
|
44
|
+
const resetTimerProperties = timer => {
|
|
45
|
+
timer.paused = true;
|
|
46
|
+
timer.began = false;
|
|
47
|
+
timer.completed = false;
|
|
48
|
+
return timer;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Timer} timer
|
|
53
|
+
* @return {Timer}
|
|
54
|
+
*/
|
|
55
|
+
const reviveTimer = timer => {
|
|
56
|
+
if (!timer._cancelled) return timer;
|
|
57
|
+
if (timer._hasChildren) {
|
|
58
|
+
helpers.forEachChildren(timer, reviveTimer);
|
|
59
|
+
} else {
|
|
60
|
+
helpers.forEachChildren(timer, (/** @type {Tween} tween*/tween) => {
|
|
61
|
+
if (tween._composition !== consts.compositionTypes.none) {
|
|
62
|
+
composition.composeTween(tween, composition.getTweenSiblings(tween.target, tween.property));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
timer._cancelled = 0;
|
|
67
|
+
return timer;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let timerId = 0;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Base class used to create Timers, Animations and Timelines
|
|
74
|
+
*/
|
|
75
|
+
class Timer extends clock.Clock {
|
|
76
|
+
/**
|
|
77
|
+
* @param {TimerParams} [parameters]
|
|
78
|
+
* @param {Timeline} [parent]
|
|
79
|
+
* @param {Number} [parentPosition]
|
|
80
|
+
*/
|
|
81
|
+
constructor(parameters = {}, parent = null, parentPosition = 0) {
|
|
82
|
+
|
|
83
|
+
super(0);
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
id,
|
|
87
|
+
delay,
|
|
88
|
+
duration,
|
|
89
|
+
reversed,
|
|
90
|
+
alternate,
|
|
91
|
+
loop,
|
|
92
|
+
loopDelay,
|
|
93
|
+
autoplay,
|
|
94
|
+
frameRate,
|
|
95
|
+
playbackRate,
|
|
96
|
+
onComplete,
|
|
97
|
+
onLoop,
|
|
98
|
+
onPause,
|
|
99
|
+
onBegin,
|
|
100
|
+
onBeforeUpdate,
|
|
101
|
+
onUpdate,
|
|
102
|
+
} = parameters;
|
|
103
|
+
|
|
104
|
+
if (globals.scope.current) globals.scope.current.register(this);
|
|
105
|
+
|
|
106
|
+
const timerInitTime = parent ? 0 : engine.engine._elapsedTime;
|
|
107
|
+
const timerDefaults = parent ? parent.defaults : globals.globals.defaults;
|
|
108
|
+
const timerDelay = /** @type {Number} */(helpers.isFnc(delay) || helpers.isUnd(delay) ? timerDefaults.delay : +delay);
|
|
109
|
+
const timerDuration = helpers.isFnc(duration) || helpers.isUnd(duration) ? Infinity : +duration;
|
|
110
|
+
const timerLoop = values.setValue(loop, timerDefaults.loop);
|
|
111
|
+
const timerLoopDelay = values.setValue(loopDelay, timerDefaults.loopDelay);
|
|
112
|
+
const timerIterationCount = timerLoop === true ||
|
|
113
|
+
timerLoop === Infinity ||
|
|
114
|
+
/** @type {Number} */(timerLoop) < 0 ? Infinity :
|
|
115
|
+
/** @type {Number} */(timerLoop) + 1;
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
let offsetPosition = 0;
|
|
119
|
+
|
|
120
|
+
if (parent) {
|
|
121
|
+
offsetPosition = parentPosition;
|
|
122
|
+
} else {
|
|
123
|
+
// Make sure to tick the engine once if not currently running to get up to date engine._elapsedTime
|
|
124
|
+
// to avoid big gaps with the following offsetPosition calculation
|
|
125
|
+
if (!engine.engine.reqId) engine.engine.requestTick(helpers.now());
|
|
126
|
+
// Make sure to scale the offset position with globals.timeScale to properly handle seconds unit
|
|
127
|
+
offsetPosition = (engine.engine._elapsedTime - engine.engine._startTime) * globals.globals.timeScale;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Timer's parameters
|
|
131
|
+
this.id = !helpers.isUnd(id) ? id : ++timerId;
|
|
132
|
+
/** @type {Timeline} */
|
|
133
|
+
this.parent = parent;
|
|
134
|
+
// Total duration of the timer
|
|
135
|
+
this.duration = helpers.clampInfinity(((timerDuration + timerLoopDelay) * timerIterationCount) - timerLoopDelay) || consts.minValue;
|
|
136
|
+
/** @type {Boolean} */
|
|
137
|
+
this.backwards = false;
|
|
138
|
+
/** @type {Boolean} */
|
|
139
|
+
this.paused = true;
|
|
140
|
+
/** @type {Boolean} */
|
|
141
|
+
this.began = false;
|
|
142
|
+
/** @type {Boolean} */
|
|
143
|
+
this.completed = false;
|
|
144
|
+
/** @type {Callback<this>} */
|
|
145
|
+
this.onBegin = onBegin || timerDefaults.onBegin;
|
|
146
|
+
/** @type {Callback<this>} */
|
|
147
|
+
this.onBeforeUpdate = onBeforeUpdate || timerDefaults.onBeforeUpdate;
|
|
148
|
+
/** @type {Callback<this>} */
|
|
149
|
+
this.onUpdate = onUpdate || timerDefaults.onUpdate;
|
|
150
|
+
/** @type {Callback<this>} */
|
|
151
|
+
this.onLoop = onLoop || timerDefaults.onLoop;
|
|
152
|
+
/** @type {Callback<this>} */
|
|
153
|
+
this.onPause = onPause || timerDefaults.onPause;
|
|
154
|
+
/** @type {Callback<this>} */
|
|
155
|
+
this.onComplete = onComplete || timerDefaults.onComplete;
|
|
156
|
+
/** @type {Number} */
|
|
157
|
+
this.iterationDuration = timerDuration; // Duration of one loop
|
|
158
|
+
/** @type {Number} */
|
|
159
|
+
this.iterationCount = timerIterationCount; // Number of loops
|
|
160
|
+
/** @type {Boolean|ScrollObserver} */
|
|
161
|
+
this._autoplay = parent ? false : values.setValue(autoplay, timerDefaults.autoplay);
|
|
162
|
+
/** @type {Number} */
|
|
163
|
+
this._offset = offsetPosition;
|
|
164
|
+
/** @type {Number} */
|
|
165
|
+
this._delay = timerDelay;
|
|
166
|
+
/** @type {Number} */
|
|
167
|
+
this._loopDelay = timerLoopDelay;
|
|
168
|
+
/** @type {Number} */
|
|
169
|
+
this._iterationTime = 0;
|
|
170
|
+
/** @type {Number} */
|
|
171
|
+
this._currentIteration = 0; // Current loop index
|
|
172
|
+
/** @type {Function} */
|
|
173
|
+
this._resolve = consts.noop; // Used by .then()
|
|
174
|
+
/** @type {Boolean} */
|
|
175
|
+
this._running = false;
|
|
176
|
+
/** @type {Number} */
|
|
177
|
+
this._reversed = +values.setValue(reversed, timerDefaults.reversed);
|
|
178
|
+
/** @type {Number} */
|
|
179
|
+
this._reverse = this._reversed;
|
|
180
|
+
/** @type {Number} */
|
|
181
|
+
this._cancelled = 0;
|
|
182
|
+
/** @type {Boolean} */
|
|
183
|
+
this._alternate = values.setValue(alternate, timerDefaults.alternate);
|
|
184
|
+
/** @type {Renderable} */
|
|
185
|
+
this._prev = null;
|
|
186
|
+
/** @type {Renderable} */
|
|
187
|
+
this._next = null;
|
|
188
|
+
|
|
189
|
+
// Clock's parameters
|
|
190
|
+
/** @type {Number} */
|
|
191
|
+
this._elapsedTime = timerInitTime;
|
|
192
|
+
/** @type {Number} */
|
|
193
|
+
this._startTime = timerInitTime;
|
|
194
|
+
/** @type {Number} */
|
|
195
|
+
this._lastTime = timerInitTime;
|
|
196
|
+
/** @type {Number} */
|
|
197
|
+
this._fps = values.setValue(frameRate, timerDefaults.frameRate);
|
|
198
|
+
/** @type {Number} */
|
|
199
|
+
this._speed = values.setValue(playbackRate, timerDefaults.playbackRate);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get cancelled() {
|
|
203
|
+
return !!this._cancelled;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
set cancelled(cancelled) {
|
|
207
|
+
cancelled ? this.cancel() : this.reset(1).play();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
get currentTime() {
|
|
211
|
+
return helpers.clamp(helpers.round(this._currentTime, globals.globals.precision), -this._delay, this.duration);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
set currentTime(time) {
|
|
215
|
+
const paused = this.paused;
|
|
216
|
+
// Pausing the timer is necessary to avoid time jumps on a running instance
|
|
217
|
+
this.pause().seek(+time);
|
|
218
|
+
if (!paused) this.resume();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
get iterationCurrentTime() {
|
|
222
|
+
return helpers.round(this._iterationTime, globals.globals.precision);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
set iterationCurrentTime(time) {
|
|
226
|
+
this.currentTime = (this.iterationDuration * this._currentIteration) + time;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
get progress() {
|
|
230
|
+
return helpers.clamp(helpers.round(this._currentTime / this.duration, 10), 0, 1);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
set progress(progress) {
|
|
234
|
+
this.currentTime = this.duration * progress;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
get iterationProgress() {
|
|
238
|
+
return helpers.clamp(helpers.round(this._iterationTime / this.iterationDuration, 10), 0, 1);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
set iterationProgress(progress) {
|
|
242
|
+
const iterationDuration = this.iterationDuration;
|
|
243
|
+
this.currentTime = (iterationDuration * this._currentIteration) + (iterationDuration * progress);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
get currentIteration() {
|
|
247
|
+
return this._currentIteration;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
set currentIteration(iterationCount) {
|
|
251
|
+
this.currentTime = (this.iterationDuration * helpers.clamp(+iterationCount, 0, this.iterationCount - 1));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
get reversed() {
|
|
255
|
+
return !!this._reversed;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
set reversed(reverse) {
|
|
259
|
+
reverse ? this.reverse() : this.play();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
get speed() {
|
|
263
|
+
return super.speed;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
set speed(playbackRate) {
|
|
267
|
+
super.speed = playbackRate;
|
|
268
|
+
this.resetTime();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @param {Number} internalRender
|
|
273
|
+
* @return {this}
|
|
274
|
+
*/
|
|
275
|
+
reset(internalRender = 0) {
|
|
276
|
+
// If cancelled, revive the timer before rendering in order to have propertly composed tweens siblings
|
|
277
|
+
reviveTimer(this);
|
|
278
|
+
if (this._reversed && !this._reverse) this.reversed = false;
|
|
279
|
+
// Rendering before updating the completed flag to prevent skips and to make sure the properties are not overridden
|
|
280
|
+
// Setting the iterationTime at the end to force the rendering to happend backwards, otherwise calling .reset() on Timelines might not render children in the right order
|
|
281
|
+
// NOTE: This is only required for Timelines and might be better to move to the Timeline class?
|
|
282
|
+
this._iterationTime = this.iterationDuration;
|
|
283
|
+
// Set tickMode to tickModes.FORCE to force rendering
|
|
284
|
+
render.tick(this, 0, 1, internalRender, consts.tickModes.FORCE);
|
|
285
|
+
// Reset timer properties after revive / render to make sure the props are not updated again
|
|
286
|
+
resetTimerProperties(this);
|
|
287
|
+
// Also reset children properties
|
|
288
|
+
if (this._hasChildren) {
|
|
289
|
+
helpers.forEachChildren(this, resetTimerProperties);
|
|
290
|
+
}
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* @param {Number} internalRender
|
|
296
|
+
* @return {this}
|
|
297
|
+
*/
|
|
298
|
+
init(internalRender = 0) {
|
|
299
|
+
this.fps = this._fps;
|
|
300
|
+
this.speed = this._speed;
|
|
301
|
+
// Manually calling .init() on timelines should render all children intial state
|
|
302
|
+
// Forces all children to render once then render to 0 when reseted
|
|
303
|
+
if (!internalRender && this._hasChildren) {
|
|
304
|
+
render.tick(this, this.duration, 1, internalRender, consts.tickModes.FORCE);
|
|
305
|
+
}
|
|
306
|
+
this.reset(internalRender);
|
|
307
|
+
// Make sure to set autoplay to false to child timers so it doesn't attempt to autoplay / link
|
|
308
|
+
const autoplay = this._autoplay;
|
|
309
|
+
if (autoplay === true) {
|
|
310
|
+
this.resume();
|
|
311
|
+
} else if (autoplay && !helpers.isUnd(/** @type {ScrollObserver} */(autoplay).linked)) {
|
|
312
|
+
/** @type {ScrollObserver} */(autoplay).link(this);
|
|
313
|
+
}
|
|
314
|
+
return this;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** @return {this} */
|
|
318
|
+
resetTime() {
|
|
319
|
+
const timeScale = 1 / (this._speed * engine.engine._speed);
|
|
320
|
+
// TODO: See if we can safely use engine._elapsedTime here
|
|
321
|
+
// if (!engine.reqId) engine.requestTick(now())
|
|
322
|
+
// this._startTime = engine._elapsedTime - (this._currentTime + this._delay) * timeScale;
|
|
323
|
+
this._startTime = helpers.now() - (this._currentTime + this._delay) * timeScale;
|
|
324
|
+
return this;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** @return {this} */
|
|
328
|
+
pause() {
|
|
329
|
+
if (this.paused) return this;
|
|
330
|
+
this.paused = true;
|
|
331
|
+
this.onPause(this);
|
|
332
|
+
return this;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** @return {this} */
|
|
336
|
+
resume() {
|
|
337
|
+
if (!this.paused) return this;
|
|
338
|
+
this.paused = false;
|
|
339
|
+
// We can safely imediatly render a timer that has no duration and no children
|
|
340
|
+
if (this.duration <= consts.minValue && !this._hasChildren) {
|
|
341
|
+
render.tick(this, consts.minValue, 0, 0, consts.tickModes.FORCE);
|
|
342
|
+
} else {
|
|
343
|
+
if (!this._running) {
|
|
344
|
+
helpers.addChild(engine.engine, this);
|
|
345
|
+
engine.engine._hasChildren = true;
|
|
346
|
+
this._running = true;
|
|
347
|
+
}
|
|
348
|
+
this.resetTime();
|
|
349
|
+
// Forces the timer to advance by at least one frame when the next tick occurs
|
|
350
|
+
this._startTime -= 12;
|
|
351
|
+
engine.engine.wake();
|
|
352
|
+
}
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** @return {this} */
|
|
357
|
+
restart() {
|
|
358
|
+
return this.reset(0).resume();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* @param {Number} time
|
|
363
|
+
* @param {Boolean|Number} [muteCallbacks]
|
|
364
|
+
* @param {Boolean|Number} [internalRender]
|
|
365
|
+
* @return {this}
|
|
366
|
+
*/
|
|
367
|
+
seek(time, muteCallbacks = 0, internalRender = 0) {
|
|
368
|
+
// Recompose the tween siblings in case the timer has been cancelled
|
|
369
|
+
reviveTimer(this);
|
|
370
|
+
// If you seek a completed animation, otherwise the next play will starts at 0
|
|
371
|
+
this.completed = false;
|
|
372
|
+
const isPaused = this.paused;
|
|
373
|
+
this.paused = true;
|
|
374
|
+
// timer, time, muteCallbacks, internalRender, tickMode
|
|
375
|
+
render.tick(this, time + this._delay, ~~muteCallbacks, ~~internalRender, consts.tickModes.AUTO);
|
|
376
|
+
return isPaused ? this : this.resume();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** @return {this} */
|
|
380
|
+
alternate() {
|
|
381
|
+
const reversed = this._reversed;
|
|
382
|
+
const count = this.iterationCount;
|
|
383
|
+
const duration = this.iterationDuration;
|
|
384
|
+
// Calculate the maximum iterations possible given the iteration duration
|
|
385
|
+
const iterations = count === Infinity ? helpers.floor(consts.maxValue / duration) : count;
|
|
386
|
+
this._reversed = +(this._alternate && !(iterations % 2) ? reversed : !reversed);
|
|
387
|
+
if (count === Infinity) {
|
|
388
|
+
// Handle infinite loops to loop on themself
|
|
389
|
+
this.iterationProgress = this._reversed ? 1 - this.iterationProgress : this.iterationProgress;
|
|
390
|
+
} else {
|
|
391
|
+
this.seek((duration * iterations) - this._currentTime);
|
|
392
|
+
}
|
|
393
|
+
this.resetTime();
|
|
394
|
+
return this;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** @return {this} */
|
|
398
|
+
play() {
|
|
399
|
+
if (this._reversed) this.alternate();
|
|
400
|
+
return this.resume();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** @return {this} */
|
|
404
|
+
reverse() {
|
|
405
|
+
if (!this._reversed) this.alternate();
|
|
406
|
+
return this.resume();
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// TODO: Move all the animation / tweens / children related code to Animation / Timeline
|
|
410
|
+
|
|
411
|
+
/** @return {this} */
|
|
412
|
+
cancel() {
|
|
413
|
+
if (this._hasChildren) {
|
|
414
|
+
helpers.forEachChildren(this, (/** @type {Renderable} */child) => child.cancel(), true);
|
|
415
|
+
} else {
|
|
416
|
+
helpers.forEachChildren(this, composition.removeTweenSliblings);
|
|
417
|
+
}
|
|
418
|
+
this._cancelled = 1;
|
|
419
|
+
// Pausing the timer removes it from the engine
|
|
420
|
+
return this.pause();
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* @param {Number} newDuration
|
|
425
|
+
* @return {this}
|
|
426
|
+
*/
|
|
427
|
+
stretch(newDuration) {
|
|
428
|
+
const currentDuration = this.duration;
|
|
429
|
+
const normlizedDuration = helpers.normalizeTime(newDuration);
|
|
430
|
+
if (currentDuration === normlizedDuration) return this;
|
|
431
|
+
const timeScale = newDuration / currentDuration;
|
|
432
|
+
const isSetter = newDuration <= consts.minValue;
|
|
433
|
+
this.duration = isSetter ? consts.minValue : normlizedDuration;
|
|
434
|
+
this.iterationDuration = isSetter ? consts.minValue : helpers.normalizeTime(this.iterationDuration * timeScale);
|
|
435
|
+
this._offset *= timeScale;
|
|
436
|
+
this._delay *= timeScale;
|
|
437
|
+
this._loopDelay *= timeScale;
|
|
438
|
+
return this;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Cancels the timer by seeking it back to 0 and reverting the attached scroller if necessary
|
|
443
|
+
* @return {this}
|
|
444
|
+
*/
|
|
445
|
+
revert() {
|
|
446
|
+
render.tick(this, 0, 1, 0, consts.tickModes.AUTO);
|
|
447
|
+
const ap = /** @type {ScrollObserver} */(this._autoplay);
|
|
448
|
+
if (ap && ap.linked && ap.linked === this) ap.revert();
|
|
449
|
+
return this.cancel();
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Imediatly completes the timer, cancels it and triggers the onComplete callback
|
|
454
|
+
* @return {this}
|
|
455
|
+
*/
|
|
456
|
+
complete() {
|
|
457
|
+
return this.seek(this.duration).cancel();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* @param {Callback<this>} [callback]
|
|
462
|
+
* @return {Promise}
|
|
463
|
+
*/
|
|
464
|
+
then(callback = consts.noop) {
|
|
465
|
+
const then = this.then;
|
|
466
|
+
const onResolve = () => {
|
|
467
|
+
// this.then = null prevents infinite recursion if returned by an async function
|
|
468
|
+
// https://github.com/juliangarnierorg/anime-beta/issues/26
|
|
469
|
+
this.then = null;
|
|
470
|
+
callback(this);
|
|
471
|
+
this.then = then;
|
|
472
|
+
this._resolve = consts.noop;
|
|
473
|
+
};
|
|
474
|
+
return new Promise(r => {
|
|
475
|
+
this._resolve = () => r(onResolve());
|
|
476
|
+
// Make sure to resolve imediatly if the timer has already completed
|
|
477
|
+
if (this.completed) this._resolve();
|
|
478
|
+
return this;
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @param {TimerParams} [parameters]
|
|
486
|
+
* @return {Timer}
|
|
487
|
+
*/
|
|
488
|
+
const createTimer = parameters => new Timer(parameters, null, 0).init();
|
|
489
|
+
|
|
490
|
+
exports.Timer = Timer;
|
|
491
|
+
exports.createTimer = createTimer;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class used to create Timers, Animations and Timelines
|
|
3
|
+
*/
|
|
4
|
+
export class Timer extends Clock {
|
|
5
|
+
/**
|
|
6
|
+
* @param {TimerParams} [parameters]
|
|
7
|
+
* @param {Timeline} [parent]
|
|
8
|
+
* @param {Number} [parentPosition]
|
|
9
|
+
*/
|
|
10
|
+
constructor(parameters?: TimerParams, parent?: Timeline, parentPosition?: number);
|
|
11
|
+
id: string | number;
|
|
12
|
+
/** @type {Timeline} */
|
|
13
|
+
parent: Timeline;
|
|
14
|
+
duration: number;
|
|
15
|
+
/** @type {Boolean} */
|
|
16
|
+
backwards: boolean;
|
|
17
|
+
/** @type {Boolean} */
|
|
18
|
+
paused: boolean;
|
|
19
|
+
/** @type {Boolean} */
|
|
20
|
+
began: boolean;
|
|
21
|
+
/** @type {Boolean} */
|
|
22
|
+
completed: boolean;
|
|
23
|
+
/** @type {Callback<this>} */
|
|
24
|
+
onBegin: Callback<this>;
|
|
25
|
+
/** @type {Callback<this>} */
|
|
26
|
+
onBeforeUpdate: Callback<this>;
|
|
27
|
+
/** @type {Callback<this>} */
|
|
28
|
+
onUpdate: Callback<this>;
|
|
29
|
+
/** @type {Callback<this>} */
|
|
30
|
+
onLoop: Callback<this>;
|
|
31
|
+
/** @type {Callback<this>} */
|
|
32
|
+
onPause: Callback<this>;
|
|
33
|
+
/** @type {Callback<this>} */
|
|
34
|
+
onComplete: Callback<this>;
|
|
35
|
+
/** @type {Number} */
|
|
36
|
+
iterationDuration: number;
|
|
37
|
+
/** @type {Number} */
|
|
38
|
+
iterationCount: number;
|
|
39
|
+
/** @type {Boolean|ScrollObserver} */
|
|
40
|
+
_autoplay: boolean | ScrollObserver;
|
|
41
|
+
/** @type {Number} */
|
|
42
|
+
_offset: number;
|
|
43
|
+
/** @type {Number} */
|
|
44
|
+
_delay: number;
|
|
45
|
+
/** @type {Number} */
|
|
46
|
+
_loopDelay: number;
|
|
47
|
+
/** @type {Number} */
|
|
48
|
+
_iterationTime: number;
|
|
49
|
+
/** @type {Number} */
|
|
50
|
+
_currentIteration: number;
|
|
51
|
+
/** @type {Function} */
|
|
52
|
+
_resolve: Function;
|
|
53
|
+
/** @type {Boolean} */
|
|
54
|
+
_running: boolean;
|
|
55
|
+
/** @type {Number} */
|
|
56
|
+
_reversed: number;
|
|
57
|
+
/** @type {Number} */
|
|
58
|
+
_reverse: number;
|
|
59
|
+
/** @type {Number} */
|
|
60
|
+
_cancelled: number;
|
|
61
|
+
/** @type {Boolean} */
|
|
62
|
+
_alternate: boolean;
|
|
63
|
+
/** @type {Renderable} */
|
|
64
|
+
_prev: Renderable;
|
|
65
|
+
/** @type {Renderable} */
|
|
66
|
+
_next: Renderable;
|
|
67
|
+
set cancelled(cancelled: boolean);
|
|
68
|
+
get cancelled(): boolean;
|
|
69
|
+
set currentTime(time: number);
|
|
70
|
+
get currentTime(): number;
|
|
71
|
+
set iterationCurrentTime(time: number);
|
|
72
|
+
get iterationCurrentTime(): number;
|
|
73
|
+
set progress(progress: number);
|
|
74
|
+
get progress(): number;
|
|
75
|
+
set iterationProgress(progress: number);
|
|
76
|
+
get iterationProgress(): number;
|
|
77
|
+
set currentIteration(iterationCount: number);
|
|
78
|
+
get currentIteration(): number;
|
|
79
|
+
set reversed(reverse: boolean);
|
|
80
|
+
get reversed(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* @param {Number} internalRender
|
|
83
|
+
* @return {this}
|
|
84
|
+
*/
|
|
85
|
+
reset(internalRender?: number): this;
|
|
86
|
+
/**
|
|
87
|
+
* @param {Number} internalRender
|
|
88
|
+
* @return {this}
|
|
89
|
+
*/
|
|
90
|
+
init(internalRender?: number): this;
|
|
91
|
+
/** @return {this} */
|
|
92
|
+
resetTime(): this;
|
|
93
|
+
/** @return {this} */
|
|
94
|
+
pause(): this;
|
|
95
|
+
/** @return {this} */
|
|
96
|
+
resume(): this;
|
|
97
|
+
/** @return {this} */
|
|
98
|
+
restart(): this;
|
|
99
|
+
/**
|
|
100
|
+
* @param {Number} time
|
|
101
|
+
* @param {Boolean|Number} [muteCallbacks]
|
|
102
|
+
* @param {Boolean|Number} [internalRender]
|
|
103
|
+
* @return {this}
|
|
104
|
+
*/
|
|
105
|
+
seek(time: number, muteCallbacks?: boolean | number, internalRender?: boolean | number): this;
|
|
106
|
+
/** @return {this} */
|
|
107
|
+
alternate(): this;
|
|
108
|
+
/** @return {this} */
|
|
109
|
+
play(): this;
|
|
110
|
+
/** @return {this} */
|
|
111
|
+
reverse(): this;
|
|
112
|
+
/** @return {this} */
|
|
113
|
+
cancel(): this;
|
|
114
|
+
/**
|
|
115
|
+
* @param {Number} newDuration
|
|
116
|
+
* @return {this}
|
|
117
|
+
*/
|
|
118
|
+
stretch(newDuration: number): this;
|
|
119
|
+
/**
|
|
120
|
+
* Cancels the timer by seeking it back to 0 and reverting the attached scroller if necessary
|
|
121
|
+
* @return {this}
|
|
122
|
+
*/
|
|
123
|
+
revert(): this;
|
|
124
|
+
/**
|
|
125
|
+
* Imediatly completes the timer, cancels it and triggers the onComplete callback
|
|
126
|
+
* @return {this}
|
|
127
|
+
*/
|
|
128
|
+
complete(): this;
|
|
129
|
+
/**
|
|
130
|
+
* @param {Callback<this>} [callback]
|
|
131
|
+
* @return {Promise}
|
|
132
|
+
*/
|
|
133
|
+
then(callback?: Callback<this>): Promise<any>;
|
|
134
|
+
}
|
|
135
|
+
export function createTimer(parameters?: TimerParams): Timer;
|
|
136
|
+
import { Clock } from '../core/clock.js';
|
|
137
|
+
import type { Timeline } from '../timeline/timeline.js';
|
|
138
|
+
import type { Callback } from '../types/index.js';
|
|
139
|
+
import type { ScrollObserver } from '../events/scroll.js';
|
|
140
|
+
import type { Renderable } from '../types/index.js';
|
|
141
|
+
import type { TimerParams } from '../types/index.js';
|