@thednp/tween 0.0.1
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/LICENSE +21 -0
- package/README.md +259 -0
- package/dist/index.cjs +621 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +184 -0
- package/dist/index.d.mts +184 -0
- package/dist/index.mjs +610 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.cjs +61 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +9 -0
- package/dist/react.d.mts +9 -0
- package/dist/react.mjs +55 -0
- package/dist/react.mjs.map +1 -0
- package/dist/solid.cjs +81 -0
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.d.cts +9 -0
- package/dist/solid.d.mts +9 -0
- package/dist/solid.mjs +75 -0
- package/dist/solid.mjs.map +1 -0
- package/dist/tween.iife.js +2 -0
- package/dist/tween.iife.js.map +1 -0
- package/package.json +96 -0
- package/wiki/Easing.md +58 -0
- package/wiki/React.md +255 -0
- package/wiki/Solid.md +149 -0
- package/wiki/Timeline.md +207 -0
- package/wiki/Tween.md +230 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/Now.ts
|
|
3
|
+
let _nowFunc = () => performance.now();
|
|
4
|
+
const now = () => {
|
|
5
|
+
return _nowFunc();
|
|
6
|
+
};
|
|
7
|
+
function setNow(nowFunction) {
|
|
8
|
+
_nowFunc = nowFunction;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/Runtime.ts
|
|
13
|
+
const Queue = [];
|
|
14
|
+
function addToQueue(newItem) {
|
|
15
|
+
const item = newItem;
|
|
16
|
+
if (Queue.includes(item)) return;
|
|
17
|
+
Queue.push(item);
|
|
18
|
+
if (!rafID) Runtime();
|
|
19
|
+
}
|
|
20
|
+
function removeFromQueue(removedItem) {
|
|
21
|
+
Queue.splice(Queue.indexOf(removedItem), 1);
|
|
22
|
+
}
|
|
23
|
+
let rafID = 0;
|
|
24
|
+
function Runtime(t = now()) {
|
|
25
|
+
let i = 0;
|
|
26
|
+
while (i < Queue.length) if (Queue[i].update(t)) i += 1;
|
|
27
|
+
else Queue.splice(i, 1);
|
|
28
|
+
if (Queue.length === 0) {
|
|
29
|
+
cancelAnimationFrame(rafID);
|
|
30
|
+
rafID = 0;
|
|
31
|
+
} else rafID = requestAnimationFrame(Runtime);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/Tween.ts
|
|
36
|
+
var Tween = class {
|
|
37
|
+
_interpolators = /* @__PURE__ */ new Map();
|
|
38
|
+
_state;
|
|
39
|
+
_startIsSet = false;
|
|
40
|
+
_startFired = false;
|
|
41
|
+
_propsStart = {};
|
|
42
|
+
_propsEnd = {};
|
|
43
|
+
_isPlaying = false;
|
|
44
|
+
_duration = 1e3;
|
|
45
|
+
_delay = 0;
|
|
46
|
+
_easing = (t) => t;
|
|
47
|
+
_startTime = 0;
|
|
48
|
+
_onUpdate;
|
|
49
|
+
_onComplete;
|
|
50
|
+
_onStart;
|
|
51
|
+
_onStop;
|
|
52
|
+
constructor(initialValues) {
|
|
53
|
+
this._state = initialValues;
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
get isPlaying() {
|
|
57
|
+
return this._isPlaying;
|
|
58
|
+
}
|
|
59
|
+
start(time = now(), overrideStart = false) {
|
|
60
|
+
if (this._isPlaying) return this;
|
|
61
|
+
if (!this._startIsSet || overrideStart) {
|
|
62
|
+
this._startIsSet = true;
|
|
63
|
+
this._setProps(this._state, this._propsStart, this._propsEnd, overrideStart);
|
|
64
|
+
}
|
|
65
|
+
this._isPlaying = true;
|
|
66
|
+
this._startTime = time;
|
|
67
|
+
this._startTime += this._delay;
|
|
68
|
+
addToQueue(this);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
startFromLast(time = now()) {
|
|
72
|
+
return this.start(time, true);
|
|
73
|
+
}
|
|
74
|
+
stop() {
|
|
75
|
+
if (!this._isPlaying) return this;
|
|
76
|
+
removeFromQueue(this);
|
|
77
|
+
this._isPlaying = false;
|
|
78
|
+
this._onStop?.(this._state);
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
from(startValues) {
|
|
82
|
+
Object.assign(this._propsStart, startValues);
|
|
83
|
+
this._startIsSet = false;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
to(endValues) {
|
|
87
|
+
this._propsEnd = endValues;
|
|
88
|
+
this._startIsSet = false;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
duration(seconds = 1) {
|
|
92
|
+
this._duration = seconds * 1e3;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
delay(seconds = 0) {
|
|
96
|
+
this._delay = seconds * 1e3;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
easing(easing = (t) => t) {
|
|
100
|
+
this._easing = easing;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
getDuration() {
|
|
104
|
+
return this._duration;
|
|
105
|
+
}
|
|
106
|
+
update(time = now(), autoStart) {
|
|
107
|
+
if (!this._isPlaying) if (autoStart) this.start(time, true);
|
|
108
|
+
else return false;
|
|
109
|
+
if (time < this._startTime) return true;
|
|
110
|
+
if (!this._startFired && this._onStart) {
|
|
111
|
+
this._onStart(this._state);
|
|
112
|
+
this._startFired = true;
|
|
113
|
+
}
|
|
114
|
+
let elapsed = (time - this._startTime) / this._duration;
|
|
115
|
+
elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed;
|
|
116
|
+
const progress = this._easing(elapsed);
|
|
117
|
+
this._setState(this._state, this._propsStart, this._propsEnd, progress);
|
|
118
|
+
this._onUpdate?.(this._state, elapsed, progress);
|
|
119
|
+
if (elapsed === 1) {
|
|
120
|
+
this._onComplete?.(this._state);
|
|
121
|
+
this._isPlaying = false;
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
onStart(callback) {
|
|
127
|
+
this._onStart = callback;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
onUpdate(callback) {
|
|
131
|
+
this._onUpdate = callback;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
onComplete(callback) {
|
|
135
|
+
this._onComplete = callback;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
onStop(callback) {
|
|
139
|
+
this._onStop = callback;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
_setState(object, valuesStart, valuesEnd, value) {
|
|
143
|
+
const endEntries = Object.entries(valuesEnd);
|
|
144
|
+
const len = endEntries.length;
|
|
145
|
+
let i = 0;
|
|
146
|
+
while (i < len) {
|
|
147
|
+
const [property, end] = endEntries[i];
|
|
148
|
+
i++;
|
|
149
|
+
if (valuesStart[property] === void 0) continue;
|
|
150
|
+
const start = valuesStart[property];
|
|
151
|
+
if (start.constructor !== end?.constructor) continue;
|
|
152
|
+
if (this._interpolators.has(property)) object[property] = this._interpolators.get(property)(start, end, value);
|
|
153
|
+
else if (typeof end === "number") object[property] = start + (end - start) * value;
|
|
154
|
+
else if (typeof end === "object") this._setState(object[property], start, end, value);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
_setProps(obj, propsStart, propsEnd, overrideStartingValues) {
|
|
158
|
+
const endKeys = Object.keys(propsEnd);
|
|
159
|
+
for (const property of endKeys) {
|
|
160
|
+
const startValue = obj[property];
|
|
161
|
+
if (typeof propsStart[property] === "undefined" || overrideStartingValues) propsStart[property] = startValue;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
use(property, interpolateFn) {
|
|
165
|
+
if (!this._interpolators.has(property)) this._interpolators.set(property, interpolateFn);
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/Timeline.ts
|
|
172
|
+
var Timeline = class {
|
|
173
|
+
state;
|
|
174
|
+
_state;
|
|
175
|
+
_entries = [];
|
|
176
|
+
_labels = /* @__PURE__ */ new Map();
|
|
177
|
+
_progress = 0;
|
|
178
|
+
_duration = 0;
|
|
179
|
+
_time = 0;
|
|
180
|
+
_pauseTime = 0;
|
|
181
|
+
_lastTime;
|
|
182
|
+
_isPlaying = false;
|
|
183
|
+
_repeat = 0;
|
|
184
|
+
_initialRepeat = 0;
|
|
185
|
+
_interpolators = /* @__PURE__ */ new Map();
|
|
186
|
+
_onStart;
|
|
187
|
+
_onStop;
|
|
188
|
+
_onPause;
|
|
189
|
+
_onResume;
|
|
190
|
+
_onUpdate;
|
|
191
|
+
_onComplete;
|
|
192
|
+
constructor(initialState) {
|
|
193
|
+
this.state = initialState;
|
|
194
|
+
this._state = { ...initialState };
|
|
195
|
+
}
|
|
196
|
+
to({ duration = 1, easing = (t) => t, ...values }, position = "+=0") {
|
|
197
|
+
const startTime = this._resolvePosition(position);
|
|
198
|
+
const to = values;
|
|
199
|
+
const entryDuration = duration * 1e3;
|
|
200
|
+
this._entries.push({
|
|
201
|
+
to,
|
|
202
|
+
startTime,
|
|
203
|
+
duration: entryDuration,
|
|
204
|
+
easing,
|
|
205
|
+
hasStarted: false
|
|
206
|
+
});
|
|
207
|
+
const endTime = startTime + entryDuration;
|
|
208
|
+
this._duration = Math.max(this._duration, endTime);
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
play() {
|
|
212
|
+
if (this._pauseTime) return this.resume();
|
|
213
|
+
if (this._isPlaying) return this;
|
|
214
|
+
this._isPlaying = true;
|
|
215
|
+
this._lastTime = void 0;
|
|
216
|
+
this._time = 0;
|
|
217
|
+
this._resetState();
|
|
218
|
+
this._updateEntries(0);
|
|
219
|
+
this._onStart?.(this.state, 0);
|
|
220
|
+
addToQueue(this);
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
pause() {
|
|
224
|
+
if (!this._isPlaying) return this;
|
|
225
|
+
this._isPlaying = false;
|
|
226
|
+
this._pauseTime = now();
|
|
227
|
+
this._onPause?.(this.state, this.progress);
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
resume(time = now()) {
|
|
231
|
+
if (this._isPlaying) return this;
|
|
232
|
+
this._isPlaying = true;
|
|
233
|
+
const dif = time - this._pauseTime;
|
|
234
|
+
this._pauseTime = 0;
|
|
235
|
+
this._lastTime = (this._lastTime || time) + dif;
|
|
236
|
+
this._onResume?.(this.state, this.progress);
|
|
237
|
+
addToQueue(this);
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
stop() {
|
|
241
|
+
if (!this._isPlaying) return this;
|
|
242
|
+
this._isPlaying = false;
|
|
243
|
+
this._time = 0;
|
|
244
|
+
this._pauseTime = 0;
|
|
245
|
+
removeFromQueue(this);
|
|
246
|
+
this._resetState();
|
|
247
|
+
this._updateEntries(0);
|
|
248
|
+
this._onStop?.(this.state, this._progress);
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
repeat(count = 0) {
|
|
252
|
+
this._repeat = count;
|
|
253
|
+
this._initialRepeat = count;
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
seek(pointer) {
|
|
257
|
+
const elapsed = this._resolvePosition(pointer);
|
|
258
|
+
this._resetState();
|
|
259
|
+
this._time = Math.max(0, elapsed);
|
|
260
|
+
this._updateEntries(this._time);
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
label(name, position) {
|
|
264
|
+
this._labels.set(name, this._resolvePosition(position));
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
onStart(cb) {
|
|
268
|
+
this._onStart = cb;
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
onPause(cb) {
|
|
272
|
+
this._onPause = cb;
|
|
273
|
+
return this;
|
|
274
|
+
}
|
|
275
|
+
onResume(cb) {
|
|
276
|
+
this._onResume = cb;
|
|
277
|
+
return this;
|
|
278
|
+
}
|
|
279
|
+
onStop(cb) {
|
|
280
|
+
this._onStop = cb;
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
onUpdate(cb) {
|
|
284
|
+
this._onUpdate = cb;
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
onComplete(cb) {
|
|
288
|
+
this._onComplete = cb;
|
|
289
|
+
return this;
|
|
290
|
+
}
|
|
291
|
+
get progress() {
|
|
292
|
+
return this._progress;
|
|
293
|
+
}
|
|
294
|
+
get duration() {
|
|
295
|
+
return this._duration;
|
|
296
|
+
}
|
|
297
|
+
get isPlaying() {
|
|
298
|
+
return this._isPlaying;
|
|
299
|
+
}
|
|
300
|
+
get isPaused() {
|
|
301
|
+
return !this._isPlaying && this._pauseTime > 0;
|
|
302
|
+
}
|
|
303
|
+
update(time = now()) {
|
|
304
|
+
if (!this._isPlaying) return false;
|
|
305
|
+
if (this._lastTime === void 0) this._lastTime = time;
|
|
306
|
+
const delta = time - this._lastTime;
|
|
307
|
+
this._lastTime = time;
|
|
308
|
+
this._time += delta;
|
|
309
|
+
this._updateEntries(this._time);
|
|
310
|
+
if (this._progress === 1) if (this._repeat === 0) {
|
|
311
|
+
this._isPlaying = false;
|
|
312
|
+
this._repeat = this._initialRepeat;
|
|
313
|
+
this._onComplete?.(this.state, 1);
|
|
314
|
+
} else {
|
|
315
|
+
if (this._repeat !== Infinity) this._repeat--;
|
|
316
|
+
this._time = 0;
|
|
317
|
+
this._resetState();
|
|
318
|
+
this._updateEntries(0);
|
|
319
|
+
}
|
|
320
|
+
return this._isPlaying;
|
|
321
|
+
}
|
|
322
|
+
_updateEntries(elapsed) {
|
|
323
|
+
this._progress = this._duration === 0 || elapsed >= this._duration ? 1 : elapsed / this._duration;
|
|
324
|
+
let i = 0;
|
|
325
|
+
const entriesLen = this._entries.length;
|
|
326
|
+
while (i < entriesLen) {
|
|
327
|
+
const entry = this._entries[i];
|
|
328
|
+
const localTime = elapsed - entry.startTime;
|
|
329
|
+
const tweenElapsed = Math.max(0, Math.min(1, localTime / entry.duration));
|
|
330
|
+
if (!entry.hasStarted && tweenElapsed > 0) {
|
|
331
|
+
entry.hasStarted = true;
|
|
332
|
+
entry.startValues = {};
|
|
333
|
+
for (const key in entry.to) entry.startValues[key] = this.state[key];
|
|
334
|
+
}
|
|
335
|
+
if (entry.hasStarted) this._setState(this.state, entry.startValues, entry.to, entry.easing(tweenElapsed));
|
|
336
|
+
i += 1;
|
|
337
|
+
}
|
|
338
|
+
this._onUpdate?.(this.state, this._progress);
|
|
339
|
+
}
|
|
340
|
+
_resolvePosition(pos) {
|
|
341
|
+
if (typeof pos === "number") return pos * 1e3;
|
|
342
|
+
if (typeof pos === "string") {
|
|
343
|
+
const labelTime = this._labels.get(pos);
|
|
344
|
+
if (labelTime !== void 0) return labelTime;
|
|
345
|
+
if (pos.startsWith("+=") || pos.startsWith("-=")) {
|
|
346
|
+
let offset = parseFloat(pos.slice(2));
|
|
347
|
+
if (isNaN(offset)) offset = 0;
|
|
348
|
+
offset *= 1e3;
|
|
349
|
+
return pos.startsWith("+=") ? this._duration + offset : Math.max(0, this._duration - offset);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return this._duration;
|
|
353
|
+
}
|
|
354
|
+
_setState(object, valuesStart, valuesEnd, value) {
|
|
355
|
+
const endEntries = Object.entries(valuesEnd);
|
|
356
|
+
const len = endEntries.length;
|
|
357
|
+
let i = 0;
|
|
358
|
+
while (i < len) {
|
|
359
|
+
const [property, end] = endEntries[i];
|
|
360
|
+
i++;
|
|
361
|
+
if (valuesStart[property] === void 0) continue;
|
|
362
|
+
const start = valuesStart[property];
|
|
363
|
+
if (start.constructor !== end?.constructor) continue;
|
|
364
|
+
if (this._interpolators.has(property)) object[property] = this._interpolators.get(property)(start, end, value);
|
|
365
|
+
else if (typeof end === "number") object[property] = start + (end - start) * value;
|
|
366
|
+
else if (typeof end === "object") this._setState(object[property], start, end, value);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
_resetState() {
|
|
370
|
+
Object.assign(this.state, this._state);
|
|
371
|
+
let i = 0;
|
|
372
|
+
const entriesLen = this._entries.length;
|
|
373
|
+
while (i < entriesLen) {
|
|
374
|
+
const entry = this._entries[i];
|
|
375
|
+
entry.hasStarted = false;
|
|
376
|
+
entry.startValues = void 0;
|
|
377
|
+
i += 1;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
clear() {
|
|
381
|
+
this._entries.length = 0;
|
|
382
|
+
this._duration = 0;
|
|
383
|
+
this._labels.clear();
|
|
384
|
+
this._time = 0;
|
|
385
|
+
this._progress = 0;
|
|
386
|
+
this._pauseTime = 0;
|
|
387
|
+
this._lastTime = void 0;
|
|
388
|
+
this._repeat = this._initialRepeat;
|
|
389
|
+
return this;
|
|
390
|
+
}
|
|
391
|
+
use(property, interpolateFn) {
|
|
392
|
+
if (!this._interpolators.has(property)) this._interpolators.set(property, interpolateFn);
|
|
393
|
+
return this;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/Easing.ts
|
|
399
|
+
const Easing = Object.freeze({
|
|
400
|
+
Linear: Object.freeze({
|
|
401
|
+
None(amount) {
|
|
402
|
+
return amount;
|
|
403
|
+
},
|
|
404
|
+
In(amount) {
|
|
405
|
+
return amount;
|
|
406
|
+
},
|
|
407
|
+
Out(amount) {
|
|
408
|
+
return amount;
|
|
409
|
+
},
|
|
410
|
+
InOut(amount) {
|
|
411
|
+
return amount;
|
|
412
|
+
}
|
|
413
|
+
}),
|
|
414
|
+
Quadratic: Object.freeze({
|
|
415
|
+
In(amount) {
|
|
416
|
+
return amount * amount;
|
|
417
|
+
},
|
|
418
|
+
Out(amount) {
|
|
419
|
+
return amount * (2 - amount);
|
|
420
|
+
},
|
|
421
|
+
InOut(amount) {
|
|
422
|
+
if ((amount *= 2) < 1) return .5 * amount * amount;
|
|
423
|
+
return -.5 * (--amount * (amount - 2) - 1);
|
|
424
|
+
}
|
|
425
|
+
}),
|
|
426
|
+
Cubic: Object.freeze({
|
|
427
|
+
In(amount) {
|
|
428
|
+
return amount * amount * amount;
|
|
429
|
+
},
|
|
430
|
+
Out(amount) {
|
|
431
|
+
return --amount * amount * amount + 1;
|
|
432
|
+
},
|
|
433
|
+
InOut(amount) {
|
|
434
|
+
if ((amount *= 2) < 1) return .5 * amount * amount * amount;
|
|
435
|
+
return .5 * ((amount -= 2) * amount * amount + 2);
|
|
436
|
+
}
|
|
437
|
+
}),
|
|
438
|
+
Quartic: Object.freeze({
|
|
439
|
+
In(amount) {
|
|
440
|
+
return amount * amount * amount * amount;
|
|
441
|
+
},
|
|
442
|
+
Out(amount) {
|
|
443
|
+
return 1 - --amount * amount * amount * amount;
|
|
444
|
+
},
|
|
445
|
+
InOut(amount) {
|
|
446
|
+
if ((amount *= 2) < 1) return .5 * amount * amount * amount * amount;
|
|
447
|
+
return -.5 * ((amount -= 2) * amount * amount * amount - 2);
|
|
448
|
+
}
|
|
449
|
+
}),
|
|
450
|
+
Quintic: Object.freeze({
|
|
451
|
+
In(amount) {
|
|
452
|
+
return amount * amount * amount * amount * amount;
|
|
453
|
+
},
|
|
454
|
+
Out(amount) {
|
|
455
|
+
return --amount * amount * amount * amount * amount + 1;
|
|
456
|
+
},
|
|
457
|
+
InOut(amount) {
|
|
458
|
+
if ((amount *= 2) < 1) return .5 * amount * amount * amount * amount * amount;
|
|
459
|
+
return .5 * ((amount -= 2) * amount * amount * amount * amount + 2);
|
|
460
|
+
}
|
|
461
|
+
}),
|
|
462
|
+
Sinusoidal: Object.freeze({
|
|
463
|
+
In(amount) {
|
|
464
|
+
return 1 - Math.sin((1 - amount) * Math.PI / 2);
|
|
465
|
+
},
|
|
466
|
+
Out(amount) {
|
|
467
|
+
return Math.sin(amount * Math.PI / 2);
|
|
468
|
+
},
|
|
469
|
+
InOut(amount) {
|
|
470
|
+
return .5 * (1 - Math.sin(Math.PI * (.5 - amount)));
|
|
471
|
+
}
|
|
472
|
+
}),
|
|
473
|
+
Exponential: Object.freeze({
|
|
474
|
+
In(amount) {
|
|
475
|
+
return amount === 0 ? 0 : Math.pow(1024, amount - 1);
|
|
476
|
+
},
|
|
477
|
+
Out(amount) {
|
|
478
|
+
return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount);
|
|
479
|
+
},
|
|
480
|
+
InOut(amount) {
|
|
481
|
+
if (amount === 0) return 0;
|
|
482
|
+
if (amount === 1) return 1;
|
|
483
|
+
if ((amount *= 2) < 1) return .5 * Math.pow(1024, amount - 1);
|
|
484
|
+
return .5 * (-Math.pow(2, -10 * (amount - 1)) + 2);
|
|
485
|
+
}
|
|
486
|
+
}),
|
|
487
|
+
Circular: Object.freeze({
|
|
488
|
+
In(amount) {
|
|
489
|
+
return 1 - Math.sqrt(1 - amount * amount);
|
|
490
|
+
},
|
|
491
|
+
Out(amount) {
|
|
492
|
+
return Math.sqrt(1 - --amount * amount);
|
|
493
|
+
},
|
|
494
|
+
InOut(amount) {
|
|
495
|
+
if ((amount *= 2) < 1) return -.5 * (Math.sqrt(1 - amount * amount) - 1);
|
|
496
|
+
return .5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1);
|
|
497
|
+
}
|
|
498
|
+
}),
|
|
499
|
+
Elastic: Object.freeze({
|
|
500
|
+
In(amount) {
|
|
501
|
+
if (amount === 0) return 0;
|
|
502
|
+
if (amount === 1) return 1;
|
|
503
|
+
return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
|
|
504
|
+
},
|
|
505
|
+
Out(amount) {
|
|
506
|
+
if (amount === 0) return 0;
|
|
507
|
+
if (amount === 1) return 1;
|
|
508
|
+
return Math.pow(2, -10 * amount) * Math.sin((amount - .1) * 5 * Math.PI) + 1;
|
|
509
|
+
},
|
|
510
|
+
InOut(amount) {
|
|
511
|
+
if (amount === 0) return 0;
|
|
512
|
+
if (amount === 1) return 1;
|
|
513
|
+
amount *= 2;
|
|
514
|
+
if (amount < 1) return -.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI);
|
|
515
|
+
return .5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1;
|
|
516
|
+
}
|
|
517
|
+
}),
|
|
518
|
+
Back: Object.freeze({
|
|
519
|
+
In(amount) {
|
|
520
|
+
const s = 1.70158;
|
|
521
|
+
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s);
|
|
522
|
+
},
|
|
523
|
+
Out(amount) {
|
|
524
|
+
const s = 1.70158;
|
|
525
|
+
return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1;
|
|
526
|
+
},
|
|
527
|
+
InOut(amount) {
|
|
528
|
+
const s = 1.70158 * 1.525;
|
|
529
|
+
if ((amount *= 2) < 1) return .5 * (amount * amount * ((s + 1) * amount - s));
|
|
530
|
+
return .5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2);
|
|
531
|
+
}
|
|
532
|
+
}),
|
|
533
|
+
Bounce: Object.freeze({
|
|
534
|
+
In(amount) {
|
|
535
|
+
return 1 - Easing.Bounce.Out(1 - amount);
|
|
536
|
+
},
|
|
537
|
+
Out(amount) {
|
|
538
|
+
if (amount < 1 / 2.75) return 7.5625 * amount * amount;
|
|
539
|
+
else if (amount < 2 / 2.75) return 7.5625 * (amount -= 1.5 / 2.75) * amount + .75;
|
|
540
|
+
else if (amount < 2.5 / 2.75) return 7.5625 * (amount -= 2.25 / 2.75) * amount + .9375;
|
|
541
|
+
else return 7.5625 * (amount -= 2.625 / 2.75) * amount + .984375;
|
|
542
|
+
},
|
|
543
|
+
InOut(amount) {
|
|
544
|
+
if (amount < .5) return Easing.Bounce.In(amount * 2) * .5;
|
|
545
|
+
return Easing.Bounce.Out(amount * 2 - 1) * .5 + .5;
|
|
546
|
+
}
|
|
547
|
+
}),
|
|
548
|
+
pow(power = 4) {
|
|
549
|
+
power = power < Number.EPSILON ? Number.EPSILON : power;
|
|
550
|
+
power = power > 1e4 ? 1e4 : power;
|
|
551
|
+
return {
|
|
552
|
+
In(amount) {
|
|
553
|
+
return amount ** power;
|
|
554
|
+
},
|
|
555
|
+
Out(amount) {
|
|
556
|
+
return 1 - (1 - amount) ** power;
|
|
557
|
+
},
|
|
558
|
+
InOut(amount) {
|
|
559
|
+
if (amount < .5) return (amount * 2) ** power / 2;
|
|
560
|
+
return (1 - (2 - amount * 2) ** power) / 2 + .5;
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/interpolators/array.ts
|
|
568
|
+
const interpolateArray = (start, end, value) => {
|
|
569
|
+
if (value === 0 && start.length !== end.length) {
|
|
570
|
+
console.warn("Array length mismatch. Returning first array.");
|
|
571
|
+
return start;
|
|
572
|
+
}
|
|
573
|
+
const result = [];
|
|
574
|
+
const len = end.length;
|
|
575
|
+
let i = 0;
|
|
576
|
+
while (i < len) {
|
|
577
|
+
result.push(start[i] + (end[i] - start[i]) * value);
|
|
578
|
+
i += 1;
|
|
579
|
+
}
|
|
580
|
+
return result;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/interpolators/path.ts
|
|
585
|
+
const interpolatePath = (start, end, t) => {
|
|
586
|
+
if (t === 0 && start.length !== end.length) {
|
|
587
|
+
console.warn("Path length mismatch. Returning start path.");
|
|
588
|
+
return start;
|
|
589
|
+
}
|
|
590
|
+
const result = [];
|
|
591
|
+
for (let i = 0; i < end.length; i += 1) {
|
|
592
|
+
const [pathCommand1, values1] = [start[i][0], start[i].slice(1)];
|
|
593
|
+
const [pathCommand2, values2] = [end[i][0], end[i].slice(1)];
|
|
594
|
+
const commandMismatch = pathCommand1 !== pathCommand2;
|
|
595
|
+
if (t === 0 && (values1.length !== values2.length || commandMismatch)) {
|
|
596
|
+
console.warn((commandMismatch ? "PathCommand" : "Params") + " mismatch at index: " + i + ". Returning start path.");
|
|
597
|
+
return start;
|
|
598
|
+
}
|
|
599
|
+
if (pathCommand1.toUpperCase() === "Z") result.push(["Z"]);
|
|
600
|
+
else {
|
|
601
|
+
const resValues = [];
|
|
602
|
+
for (let j = 0; j < values2.length; j += 1) resValues.push(values1[j] + (values2[j] - values1[j]) * t);
|
|
603
|
+
result.push([pathCommand2, ...resValues]);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return result;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
//#endregion
|
|
610
|
+
exports.Easing = Easing;
|
|
611
|
+
exports.Queue = Queue;
|
|
612
|
+
exports.Runtime = Runtime;
|
|
613
|
+
exports.Timeline = Timeline;
|
|
614
|
+
exports.Tween = Tween;
|
|
615
|
+
exports.addToQueue = addToQueue;
|
|
616
|
+
exports.interpolateArray = interpolateArray;
|
|
617
|
+
exports.interpolatePath = interpolatePath;
|
|
618
|
+
exports.now = now;
|
|
619
|
+
exports.removeFromQueue = removeFromQueue;
|
|
620
|
+
exports.setNow = setNow;
|
|
621
|
+
//# sourceMappingURL=index.cjs.map
|