motion-dom 14.9.1 → 14.10.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/dist/cjs/index.js +729 -183
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/GroupAnimation.mjs +21 -15
- package/dist/es/animation/GroupAnimation.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +6 -0
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/NativeAnimation.mjs +5 -0
- package/dist/es/animation/NativeAnimation.mjs.map +1 -1
- package/dist/es/animation/animate/effects.mjs +15 -4
- package/dist/es/animation/animate/effects.mjs.map +1 -1
- package/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/animation/animate/single-value.mjs.map +1 -1
- package/dist/es/animation/generators/keyframes.mjs +44 -16
- package/dist/es/animation/generators/keyframes.mjs.map +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs +1 -1
- package/dist/es/animation/interfaces/visual-element-target.mjs.map +1 -1
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs +8 -3
- package/dist/es/animation/keyframes/DOMKeyframesResolver.mjs.map +1 -1
- package/dist/es/animation/keyframes/get-final.mjs +18 -4
- package/dist/es/animation/keyframes/get-final.mjs.map +1 -1
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs +347 -88
- package/dist/es/animation/waapi/transforms/TransformAnimation.mjs.map +1 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +3 -3
- package/dist/es/gestures/drag/VisualElementDragControls.mjs.map +1 -1
- package/dist/es/gestures/drag/index.mjs +4 -1
- package/dist/es/gestures/drag/index.mjs.map +1 -1
- package/dist/es/gestures/pan/PanSession.mjs +6 -2
- package/dist/es/gestures/pan/PanSession.mjs.map +1 -1
- package/dist/es/gestures/press/index.mjs +179 -8
- package/dist/es/gestures/press/index.mjs.map +1 -1
- package/dist/es/gestures/press/utils/keyboard.mjs +1 -1
- package/dist/es/gestures/press/utils/keyboard.mjs.map +1 -1
- package/dist/es/projection/styles/transform.mjs +39 -17
- package/dist/es/projection/styles/transform.mjs.map +1 -1
- package/dist/es/value/index.mjs +24 -20
- package/dist/es/value/index.mjs.map +1 -1
- package/dist/es/value/types/utils/animatable-none.mjs +13 -1
- package/dist/es/value/types/utils/animatable-none.mjs.map +1 -1
- package/dist/index.d.ts +163 -13
- package/dist/motion-dom.dev.js +729 -183
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-motion-value.js +1 -1
- package/dist/size-rollup-motion-value.js.map +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBezierDefinition, millisecondsToSeconds, clamp, progress } from 'motion-utils';
|
|
1
|
+
import { isEasingArray, isBezierDefinition, easingDefinitionToFunction, millisecondsToSeconds, clamp, progress } from 'motion-utils';
|
|
2
2
|
import { frame } from '../../../frameloop/frame.mjs';
|
|
3
3
|
import { frameData } from '../../../frameloop/frame-data.mjs';
|
|
4
4
|
import { time } from '../../../frameloop/sync-time.mjs';
|
|
@@ -37,10 +37,40 @@ const scaleTolerance = 0.001;
|
|
|
37
37
|
* rebuilding the WAAPI animation every frame.
|
|
38
38
|
*/
|
|
39
39
|
const churnWindow = 100;
|
|
40
|
+
/**
|
|
41
|
+
* A WAAPI animation that starts moving later than this, as most segments
|
|
42
|
+
* of a long sequence do, is built this long before it starts, rather than
|
|
43
|
+
* all at once at the start.
|
|
44
|
+
*/
|
|
45
|
+
const buildAhead = 100;
|
|
40
46
|
/**
|
|
41
47
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
42
48
|
*/
|
|
43
|
-
const
|
|
49
|
+
const nativeEasings = new Set(["linear", "easeIn", "easeOut", "easeInOut"]);
|
|
50
|
+
const isNativeEasing = (ease) => nativeEasings.has(ease);
|
|
51
|
+
/**
|
|
52
|
+
* The last trace of each easing WAAPI can't run into linear(), with its
|
|
53
|
+
* number of samples, so the elements of a sequence that share an easing
|
|
54
|
+
* and duration trace it once.
|
|
55
|
+
*/
|
|
56
|
+
const traced = new WeakMap();
|
|
57
|
+
const trace = (ease, samples) => {
|
|
58
|
+
let last = traced.get(ease);
|
|
59
|
+
if (last?.[0] !== samples) {
|
|
60
|
+
last = [
|
|
61
|
+
samples,
|
|
62
|
+
"linear(" +
|
|
63
|
+
defaultOffset(Array(samples + 1)).map((p) => round(ease(p)) + " " + round(p * 100) + "%") +
|
|
64
|
+
")",
|
|
65
|
+
];
|
|
66
|
+
traced.set(ease, last);
|
|
67
|
+
}
|
|
68
|
+
return last[1];
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* How many samples trace an easing between two timestamps.
|
|
72
|
+
*/
|
|
73
|
+
const countSamples = (from, to) => Math.min(maxSamples, Math.max(2, Math.ceil((to - from) / sampleDelta)));
|
|
44
74
|
/**
|
|
45
75
|
* Whether two eased progresses match. False if either is NaN.
|
|
46
76
|
*/
|
|
@@ -101,6 +131,54 @@ function canAccelerateTransform(options) {
|
|
|
101
131
|
*/
|
|
102
132
|
!needsMixer(options));
|
|
103
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Starting or stopping tells the group to update its WAAPI animation.
|
|
136
|
+
* The frame loop driver is only made once the group is on the main
|
|
137
|
+
* thread, as accelerated animations never tick.
|
|
138
|
+
*/
|
|
139
|
+
class TransformDriver {
|
|
140
|
+
constructor(element, update, makeDriver, animation) {
|
|
141
|
+
this.element = element;
|
|
142
|
+
this.update = update;
|
|
143
|
+
this.makeDriver = makeDriver;
|
|
144
|
+
this.animation = animation;
|
|
145
|
+
}
|
|
146
|
+
get js() {
|
|
147
|
+
return (this.driver || (this.driver = this.makeDriver(this.update)));
|
|
148
|
+
}
|
|
149
|
+
now() {
|
|
150
|
+
return this.driver || this.makeDriver !== frameloopDriver
|
|
151
|
+
? this.js.now()
|
|
152
|
+
: frameData.isProcessing
|
|
153
|
+
? frameData.timestamp
|
|
154
|
+
: time.now();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* keepAlive is false when seeking. Seeking the WAAPI animation is
|
|
158
|
+
* free, but if a seek needs a rebuild and keeps happening, the group
|
|
159
|
+
* moves to the main thread.
|
|
160
|
+
*/
|
|
161
|
+
start(keepAlive = true) {
|
|
162
|
+
const group = getGroup(this.element);
|
|
163
|
+
!group || group.isJS
|
|
164
|
+
? this.js.start(keepAlive)
|
|
165
|
+
: group.schedule(false, !keepAlive);
|
|
166
|
+
}
|
|
167
|
+
stopJS() {
|
|
168
|
+
this.driver?.stop();
|
|
169
|
+
}
|
|
170
|
+
stop() {
|
|
171
|
+
this.stopJS();
|
|
172
|
+
const group = getGroup(this.element);
|
|
173
|
+
group && !group.isFinishing && group.release(this.animation);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* JSAnimation's time setter, looked up on first use rather than at module
|
|
178
|
+
* load, so the module has no top-level side effects and stays
|
|
179
|
+
* tree-shakeable in flattened bundles.
|
|
180
|
+
*/
|
|
181
|
+
let setTime;
|
|
104
182
|
class TransformAnimation extends JSAnimation {
|
|
105
183
|
constructor(options) {
|
|
106
184
|
const element = getOwner(options).current;
|
|
@@ -112,35 +190,16 @@ class TransformAnimation extends JSAnimation {
|
|
|
112
190
|
const canAccelerate = canAccelerateTransform(options);
|
|
113
191
|
/**
|
|
114
192
|
* The driver ticks on the main thread only once the group has
|
|
115
|
-
* moved there
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
options.driver = (update) => {
|
|
119
|
-
const js = driver(update);
|
|
120
|
-
return {
|
|
121
|
-
js,
|
|
122
|
-
now: js.now,
|
|
123
|
-
start: (keepAlive = true) => {
|
|
124
|
-
const group = getGroup(element);
|
|
125
|
-
const isJS = !group || group.isJS;
|
|
126
|
-
/**
|
|
127
|
-
* keepAlive is false when seeking. Seeking the WAAPI
|
|
128
|
-
* animation is free, but if a seek needs a rebuild and
|
|
129
|
-
* keeps happening, the group moves to the main thread.
|
|
130
|
-
*/
|
|
131
|
-
isJS
|
|
132
|
-
? js.start(keepAlive)
|
|
133
|
-
: group.schedule(false, !keepAlive);
|
|
134
|
-
},
|
|
135
|
-
stop: () => {
|
|
136
|
-
js.stop();
|
|
137
|
-
const group = getGroup(element);
|
|
138
|
-
group && !group.isFinishing && group.release(animation);
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
};
|
|
193
|
+
* moved there, so its frame loop driver is made then.
|
|
194
|
+
*/
|
|
195
|
+
options.driver = (update) => new TransformDriver(element, update, driver, animation);
|
|
142
196
|
super(options);
|
|
143
197
|
animation = this;
|
|
198
|
+
/**
|
|
199
|
+
* The first driver is made in super(), before this was assigned.
|
|
200
|
+
*/
|
|
201
|
+
const firstDriver = this.driver;
|
|
202
|
+
firstDriver && (firstDriver.animation = this);
|
|
144
203
|
this.canAccelerate = canAccelerate;
|
|
145
204
|
/**
|
|
146
205
|
* stop is bound in JSAnimation, so wrap it rather than override.
|
|
@@ -154,12 +213,29 @@ class TransformAnimation extends JSAnimation {
|
|
|
154
213
|
stop();
|
|
155
214
|
};
|
|
156
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Each keyframe's offset, made once for the keyframes rather than on
|
|
218
|
+
* every build.
|
|
219
|
+
*/
|
|
220
|
+
offsets() {
|
|
221
|
+
const { keyframes, times } = this.options;
|
|
222
|
+
if (times)
|
|
223
|
+
return times;
|
|
224
|
+
if (this.offsetsOf !== keyframes) {
|
|
225
|
+
this.offsetsOf = keyframes;
|
|
226
|
+
this.cachedOffsets = defaultOffset(keyframes);
|
|
227
|
+
}
|
|
228
|
+
return this.cachedOffsets;
|
|
229
|
+
}
|
|
157
230
|
get group() {
|
|
158
231
|
return getGroup(getOwner(this.options).current);
|
|
159
232
|
}
|
|
160
233
|
get js() {
|
|
161
234
|
return this.driver?.js;
|
|
162
235
|
}
|
|
236
|
+
stopJS() {
|
|
237
|
+
this.driver?.stopJS();
|
|
238
|
+
}
|
|
163
239
|
get name() {
|
|
164
240
|
return this.options.name;
|
|
165
241
|
}
|
|
@@ -199,22 +275,48 @@ class TransformAnimation extends JSAnimation {
|
|
|
199
275
|
return this.isAccelerated() ? this.sampleAt(time.now()) : undefined;
|
|
200
276
|
}
|
|
201
277
|
/**
|
|
202
|
-
* If this
|
|
203
|
-
*
|
|
278
|
+
* If this moves between two keyframes only, holding still either side
|
|
279
|
+
* of them, as each value of a sequence segment does, when it starts
|
|
280
|
+
* and stops moving, and its easing: as a string if WAAPI runs it
|
|
281
|
+
* exactly, otherwise its function, to trace.
|
|
204
282
|
*/
|
|
205
283
|
tween() {
|
|
206
|
-
const { keyframes: keyframes$1, type,
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
284
|
+
const { keyframes: keyframes$1, type, repeat, delay = 0 } = this.options;
|
|
285
|
+
let span = -1;
|
|
286
|
+
if (repeat || type !== keyframes || this.holdTime !== null) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
for (let i = 1; i < keyframes$1.length; i++) {
|
|
290
|
+
if (keyframes$1[i] !== keyframes$1[i - 1]) {
|
|
291
|
+
if (span >= 0)
|
|
292
|
+
return;
|
|
293
|
+
span = i - 1;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
let { ease } = this.options;
|
|
297
|
+
if (isEasingArray(ease))
|
|
298
|
+
ease = ease[span];
|
|
299
|
+
const offsets = this.offsets();
|
|
300
|
+
const at = (i) => this.startTime +
|
|
301
|
+
(delay + offsets[i] * this.totalDuration) / this.speed;
|
|
302
|
+
if (span >= 0) {
|
|
303
|
+
const easing = isBezierDefinition(ease)
|
|
304
|
+
? cubicBezierAsString(ease)
|
|
305
|
+
: isNativeEasing(ease)
|
|
306
|
+
? supportedWaapiEasing[ease]
|
|
307
|
+
: easingDefinitionToFunction(ease);
|
|
308
|
+
/**
|
|
309
|
+
* An easing that doesn't run from 0 to 1 doesn't move between
|
|
310
|
+
* the keyframes, so is traced from the values it gives instead.
|
|
311
|
+
*/
|
|
312
|
+
return [
|
|
313
|
+
at(span),
|
|
314
|
+
at(span + 1),
|
|
315
|
+
typeof easing === "string" ||
|
|
316
|
+
(isNear(easing(0), 0) && isNear(easing(1), 1))
|
|
317
|
+
? easing
|
|
318
|
+
: undefined,
|
|
319
|
+
];
|
|
218
320
|
}
|
|
219
321
|
}
|
|
220
322
|
/**
|
|
@@ -223,9 +325,9 @@ class TransformAnimation extends JSAnimation {
|
|
|
223
325
|
*/
|
|
224
326
|
boundaries(from, to) {
|
|
225
327
|
const { startTime, speed, resolvedDuration, options } = this;
|
|
226
|
-
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType,
|
|
328
|
+
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType, type, } = options;
|
|
227
329
|
const offsets = (type || keyframes) === keyframes
|
|
228
|
-
?
|
|
330
|
+
? this.offsets()
|
|
229
331
|
: [0, 1];
|
|
230
332
|
const start = startTime + delay / speed;
|
|
231
333
|
const result = [];
|
|
@@ -258,7 +360,14 @@ class TransformAnimation extends JSAnimation {
|
|
|
258
360
|
*/
|
|
259
361
|
sync() {
|
|
260
362
|
const now = time.now();
|
|
261
|
-
|
|
363
|
+
const value = this.sampleAt(now, true);
|
|
364
|
+
/**
|
|
365
|
+
* A held value doesn't move, so there's no need to sample it
|
|
366
|
+
* twice.
|
|
367
|
+
*/
|
|
368
|
+
this.options.motionValue.setWithVelocity(this.holdTime === null
|
|
369
|
+
? this.sampleAt(now - sampleDelta, true)
|
|
370
|
+
: value, value, sampleDelta);
|
|
262
371
|
}
|
|
263
372
|
play() {
|
|
264
373
|
/**
|
|
@@ -272,10 +381,7 @@ class TransformAnimation extends JSAnimation {
|
|
|
272
381
|
}
|
|
273
382
|
pause() {
|
|
274
383
|
super.pause();
|
|
275
|
-
|
|
276
|
-
this.sync();
|
|
277
|
-
this.group.schedule(false);
|
|
278
|
-
}
|
|
384
|
+
this.isAccelerated() && this.group.schedule(false);
|
|
279
385
|
}
|
|
280
386
|
/**
|
|
281
387
|
* JSAnimation finishes on its next tick, which only happens once the
|
|
@@ -299,13 +405,11 @@ class TransformAnimation extends JSAnimation {
|
|
|
299
405
|
return super.time;
|
|
300
406
|
}
|
|
301
407
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* when this next stops.
|
|
408
|
+
* Calls JSAnimation's setter directly, as `super.time =` is a slow
|
|
409
|
+
* path in V8 and this runs for every animation of a seeked sequence.
|
|
305
410
|
*/
|
|
306
411
|
set time(newTime) {
|
|
307
|
-
|
|
308
|
-
this.isAccelerated() && this.sync();
|
|
412
|
+
(setTime ?? (setTime = Object.getOwnPropertyDescriptor(JSAnimation.prototype, "time").set)).call(this, newTime);
|
|
309
413
|
}
|
|
310
414
|
/**
|
|
311
415
|
* Scroll timelines set time every frame, so run these on the main
|
|
@@ -317,6 +421,20 @@ class TransformAnimation extends JSAnimation {
|
|
|
317
421
|
return super.attachTimeline(timeline);
|
|
318
422
|
}
|
|
319
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Groups that build straight after the current task build in one
|
|
426
|
+
* microtask, rather than one each.
|
|
427
|
+
*/
|
|
428
|
+
let builds;
|
|
429
|
+
const buildSoon = (build) => {
|
|
430
|
+
builds ||
|
|
431
|
+
queueMicrotask(() => {
|
|
432
|
+
const queue = builds;
|
|
433
|
+
builds = undefined;
|
|
434
|
+
queue.forEach((build) => build());
|
|
435
|
+
});
|
|
436
|
+
(builds || (builds = [])).push(build);
|
|
437
|
+
};
|
|
320
438
|
function createGroup(owner) {
|
|
321
439
|
const element = owner.current;
|
|
322
440
|
const tracks = new Set();
|
|
@@ -336,6 +454,13 @@ function createGroup(owner) {
|
|
|
336
454
|
let isEnded = false;
|
|
337
455
|
let hasChurned = false;
|
|
338
456
|
let lastChurn = -Infinity;
|
|
457
|
+
let wake;
|
|
458
|
+
let wakeAt = Infinity;
|
|
459
|
+
/**
|
|
460
|
+
* While waiting to build a tween that starts later, how long after
|
|
461
|
+
* the last build to build it.
|
|
462
|
+
*/
|
|
463
|
+
let buildAt;
|
|
339
464
|
const has = (key) => {
|
|
340
465
|
for (const track of tracks)
|
|
341
466
|
if (track.name === key)
|
|
@@ -403,6 +528,9 @@ function createGroup(owner) {
|
|
|
403
528
|
* transform. The renderer writes its own version on its next render.
|
|
404
529
|
*/
|
|
405
530
|
const stop = (shouldCommit = true) => {
|
|
531
|
+
clearTimeout(wake);
|
|
532
|
+
wakeAt = Infinity;
|
|
533
|
+
buildAt = undefined;
|
|
406
534
|
shouldCommit && commit();
|
|
407
535
|
segments.forEach(({ animation }) => cancel(animation));
|
|
408
536
|
segments = [];
|
|
@@ -456,12 +584,31 @@ function createGroup(owner) {
|
|
|
456
584
|
* two timestamps, the easing that describes it.
|
|
457
585
|
*/
|
|
458
586
|
const getEasing = (moving, from, to, bounds) => {
|
|
459
|
-
const samples =
|
|
587
|
+
const samples = countSamples(from, to);
|
|
460
588
|
/**
|
|
461
589
|
* Too many keyframes or repeats to follow with this many samples.
|
|
462
590
|
*/
|
|
463
591
|
if (bounds.length * 4 > samples)
|
|
464
592
|
return;
|
|
593
|
+
/**
|
|
594
|
+
* First check half way, where values with different easings
|
|
595
|
+
* usually differ, before sampling every value many times.
|
|
596
|
+
*/
|
|
597
|
+
let quick;
|
|
598
|
+
for (const track of moving) {
|
|
599
|
+
const first = track.numberAt(from);
|
|
600
|
+
const p = (track.numberAt((from + to) / 2) - first) /
|
|
601
|
+
(track.numberAt(to) - first);
|
|
602
|
+
/**
|
|
603
|
+
* NaN if it doesn't move.
|
|
604
|
+
*/
|
|
605
|
+
if (p !== p)
|
|
606
|
+
continue;
|
|
607
|
+
if (quick === undefined)
|
|
608
|
+
quick = p;
|
|
609
|
+
else if (!isNear(p, quick))
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
465
612
|
const at = spread(from, to, samples).concat(bounds).sort(byTime);
|
|
466
613
|
const position = (t) => progress(from, to, t);
|
|
467
614
|
let shared;
|
|
@@ -518,11 +665,30 @@ function createGroup(owner) {
|
|
|
518
665
|
*/
|
|
519
666
|
const sample = (moving, from, to, bounds) => {
|
|
520
667
|
const times = [from];
|
|
668
|
+
/**
|
|
669
|
+
* A linear tween is straight between its keyframes, so only the
|
|
670
|
+
* other values can curve, and a tween only while it moves.
|
|
671
|
+
*/
|
|
672
|
+
const curved = [];
|
|
673
|
+
let curveFrom = to;
|
|
674
|
+
let curveTo = from;
|
|
675
|
+
for (const track of moving) {
|
|
676
|
+
const tween = track.tween();
|
|
677
|
+
if (tween?.[2] !== "linear") {
|
|
678
|
+
const [trackEnd, cycle] = track.timing();
|
|
679
|
+
const [a, b] = tween || [from, cycle ? to : trackEnd];
|
|
680
|
+
curveFrom = Math.min(curveFrom, a);
|
|
681
|
+
curveTo = Math.max(curveTo, b);
|
|
682
|
+
curved.push(track);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
curveFrom = Math.max(from, curveFrom);
|
|
686
|
+
curveTo = Math.min(to, curveTo);
|
|
521
687
|
/**
|
|
522
688
|
* Values that aren't numbers, like calc(), are left to the
|
|
523
689
|
* browser to interpolate.
|
|
524
690
|
*/
|
|
525
|
-
const isStraight = (a, b) =>
|
|
691
|
+
const isStraight = (a, b) => curved.every((track) => !(Math.abs(track.numberAt((a + b) / 2) -
|
|
526
692
|
(track.numberAt(a) + track.numberAt(b)) / 2) >
|
|
527
693
|
(track.name.startsWith("scale")
|
|
528
694
|
? scaleTolerance
|
|
@@ -547,10 +713,13 @@ function createGroup(owner) {
|
|
|
547
713
|
}
|
|
548
714
|
};
|
|
549
715
|
/**
|
|
550
|
-
* Split at least every 100ms, and at every
|
|
551
|
-
* either side of where a value can jump.
|
|
716
|
+
* Split at least every 100ms where a value can curve, and at every
|
|
717
|
+
* keyframe and repeat, either side of where a value can jump.
|
|
552
718
|
*/
|
|
553
|
-
const ends =
|
|
719
|
+
const ends = curveTo > curveFrom
|
|
720
|
+
? spread(curveFrom, curveTo, Math.ceil((curveTo - curveFrom) / 100))
|
|
721
|
+
: [];
|
|
722
|
+
ends.push(to);
|
|
554
723
|
for (const t of bounds)
|
|
555
724
|
ends.push(t, Math.min(t + 0.01, to));
|
|
556
725
|
let start = from;
|
|
@@ -570,12 +739,20 @@ function createGroup(owner) {
|
|
|
570
739
|
for (const track of moving) {
|
|
571
740
|
const tween = track.tween();
|
|
572
741
|
if (!tween ||
|
|
573
|
-
shared
|
|
574
|
-
|
|
575
|
-
|
|
742
|
+
(shared &&
|
|
743
|
+
(Math.abs(tween[0] - shared[0]) > 1 ||
|
|
744
|
+
Math.abs(tween[1] - shared[1]) > 1))) {
|
|
576
745
|
return;
|
|
577
746
|
}
|
|
578
|
-
|
|
747
|
+
/**
|
|
748
|
+
* Easings that differ, like the springs a sequence makes for
|
|
749
|
+
* each value, can still be the same curve.
|
|
750
|
+
*/
|
|
751
|
+
shared = [
|
|
752
|
+
tween[0],
|
|
753
|
+
tween[1],
|
|
754
|
+
!shared || tween[2] === shared[2] ? tween[2] : undefined,
|
|
755
|
+
];
|
|
579
756
|
}
|
|
580
757
|
return shared;
|
|
581
758
|
};
|
|
@@ -583,7 +760,13 @@ function createGroup(owner) {
|
|
|
583
760
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
584
761
|
*/
|
|
585
762
|
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
586
|
-
|
|
763
|
+
/**
|
|
764
|
+
* With an easing given, there's nothing to sample, so no need
|
|
765
|
+
* for the boundaries.
|
|
766
|
+
*/
|
|
767
|
+
const bounds = nativeEasing
|
|
768
|
+
? []
|
|
769
|
+
: moving.flatMap((track) => track.boundaries(from, to));
|
|
587
770
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
588
771
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
589
772
|
const transform = times.map((t) => compose(t, settled));
|
|
@@ -606,6 +789,23 @@ function createGroup(owner) {
|
|
|
606
789
|
easing: easing || "linear",
|
|
607
790
|
});
|
|
608
791
|
};
|
|
792
|
+
/**
|
|
793
|
+
* Check whether it's time to build in this long. A check that's due
|
|
794
|
+
* sooner is kept, and checks again if it's early, so pausing and
|
|
795
|
+
* playing don't each replace a timer. One due later, after a seek or
|
|
796
|
+
* speed change while held, is replaced.
|
|
797
|
+
*/
|
|
798
|
+
const wakeIn = (delay) => {
|
|
799
|
+
const at = time.now() + delay;
|
|
800
|
+
if (at < wakeAt) {
|
|
801
|
+
clearTimeout(wake);
|
|
802
|
+
wakeAt = at;
|
|
803
|
+
wake = setTimeout(() => {
|
|
804
|
+
wakeAt = Infinity;
|
|
805
|
+
group.schedule(false);
|
|
806
|
+
}, delay);
|
|
807
|
+
}
|
|
808
|
+
};
|
|
609
809
|
/**
|
|
610
810
|
* Replace the WAAPI animations with ones built from now. Returns
|
|
611
811
|
* undefined if the animations can't be composed.
|
|
@@ -630,14 +830,8 @@ function createGroup(owner) {
|
|
|
630
830
|
const [trackEnd, trackCycle] = track.timing();
|
|
631
831
|
const isHeld = trackEnd === Infinity;
|
|
632
832
|
built.set(track, [track.at(now), track.speed, isHeld]);
|
|
633
|
-
|
|
634
|
-
* Held animations don't move, so keep their motion values up
|
|
635
|
-
* to date, as a JSAnimation would on a seek.
|
|
636
|
-
*/
|
|
637
|
-
if (isHeld) {
|
|
638
|
-
track.sync();
|
|
833
|
+
if (isHeld)
|
|
639
834
|
continue;
|
|
640
|
-
}
|
|
641
835
|
if (track.speed < 0)
|
|
642
836
|
return;
|
|
643
837
|
if (trackCycle) {
|
|
@@ -677,12 +871,35 @@ function createGroup(owner) {
|
|
|
677
871
|
*/
|
|
678
872
|
const tween = !cycle && getTween(moving);
|
|
679
873
|
try {
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
874
|
+
if (end > now) {
|
|
875
|
+
let easing;
|
|
876
|
+
if (tween && tween[1] > now) {
|
|
877
|
+
const [from, to, ease] = tween;
|
|
878
|
+
/**
|
|
879
|
+
* Until it's built, the motion values hold where it
|
|
880
|
+
* starts, for the renderer to write.
|
|
881
|
+
*/
|
|
882
|
+
if (from - now > buildAhead) {
|
|
883
|
+
moving.forEach((track) => track.sync());
|
|
884
|
+
wakeIn((buildAt = from - now - buildAhead));
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
887
|
+
easing =
|
|
888
|
+
typeof ease === "string"
|
|
889
|
+
? ease
|
|
890
|
+
: ease
|
|
891
|
+
? trace(ease, countSamples(from, to))
|
|
892
|
+
: getEasing(moving, from, to, []);
|
|
893
|
+
/**
|
|
894
|
+
* It holds its last keyframe until the animations end.
|
|
895
|
+
*/
|
|
896
|
+
easing &&
|
|
897
|
+
add(run(moving, from, to, easing, {
|
|
898
|
+
fill: "both",
|
|
899
|
+
endDelay: end - to,
|
|
900
|
+
}), from - now, end - from);
|
|
901
|
+
}
|
|
902
|
+
easing || add(run(moving, now, end), 0, end - now);
|
|
686
903
|
/**
|
|
687
904
|
* Animations that end sooner finish on the events of
|
|
688
905
|
* empty animations that end with them.
|
|
@@ -719,9 +936,11 @@ function createGroup(owner) {
|
|
|
719
936
|
/**
|
|
720
937
|
* If every animation has been paused, played, seeked or sped up
|
|
721
938
|
* together since the WAAPI animation was built, do the same to it.
|
|
722
|
-
* Returns false if it needs rebuilding instead.
|
|
939
|
+
* Returns false if it needs rebuilding instead. Seeking to before a
|
|
940
|
+
* tween starts rebuilds, so a running group seeked every frame still
|
|
941
|
+
* moves to the main thread.
|
|
723
942
|
*/
|
|
724
|
-
const retime = (now) => {
|
|
943
|
+
const retime = (now, isSeek) => {
|
|
725
944
|
let elapsed;
|
|
726
945
|
let rate = 0;
|
|
727
946
|
for (const track of tracks) {
|
|
@@ -731,9 +950,14 @@ function createGroup(owner) {
|
|
|
731
950
|
const [builtTime, builtSpeed, wasHeld] = state;
|
|
732
951
|
const trackTime = track.at(now);
|
|
733
952
|
const isHeld = track.timing()[0] === Infinity;
|
|
953
|
+
/**
|
|
954
|
+
* With nothing on the compositor, a held animation is set
|
|
955
|
+
* where it's held, so it can be seeked as often as needed.
|
|
956
|
+
*/
|
|
734
957
|
if (wasHeld) {
|
|
735
|
-
if (isHeld && trackTime === builtTime)
|
|
958
|
+
if (isHeld && (trackTime === builtTime || !segments.length)) {
|
|
736
959
|
continue;
|
|
960
|
+
}
|
|
737
961
|
return false;
|
|
738
962
|
}
|
|
739
963
|
const trackElapsed = (trackTime - builtTime) / builtSpeed;
|
|
@@ -749,12 +973,33 @@ function createGroup(owner) {
|
|
|
749
973
|
}
|
|
750
974
|
if (elapsed === undefined)
|
|
751
975
|
return true;
|
|
752
|
-
|
|
753
|
-
|
|
976
|
+
/**
|
|
977
|
+
* Waiting to build a tween that starts later. Until then the
|
|
978
|
+
* values hold where they start, so only when to build changes.
|
|
979
|
+
* Held, it has nothing on the compositor, so it can be seeked.
|
|
980
|
+
*/
|
|
981
|
+
if (!segments.length) {
|
|
982
|
+
if (buildAt === undefined || (isSeek && rate))
|
|
983
|
+
return false;
|
|
984
|
+
if (rate) {
|
|
985
|
+
const delay = (buildAt - elapsed) / rate;
|
|
986
|
+
if (delay < 1)
|
|
987
|
+
return false;
|
|
988
|
+
wakeIn(delay);
|
|
989
|
+
}
|
|
990
|
+
return true;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Only a tween is built to start later, and it holds its first
|
|
994
|
+
* keyframe until then, so it can be paused and played before it
|
|
995
|
+
* starts.
|
|
996
|
+
*/
|
|
754
997
|
for (const { offset, end, isDone } of segments) {
|
|
755
998
|
const local = elapsed - offset;
|
|
756
999
|
if (end < Infinity &&
|
|
757
|
-
(isDone
|
|
1000
|
+
(isDone
|
|
1001
|
+
? local < end - 1
|
|
1002
|
+
: (local < 0 && (isSeek || offset <= 0)) || local >= end)) {
|
|
758
1003
|
return false;
|
|
759
1004
|
}
|
|
760
1005
|
}
|
|
@@ -775,7 +1020,8 @@ function createGroup(owner) {
|
|
|
775
1020
|
animation.updatePlaybackRate(rate);
|
|
776
1021
|
}
|
|
777
1022
|
else if (rate) {
|
|
778
|
-
animation.playbackRate
|
|
1023
|
+
animation.playbackRate !== rate &&
|
|
1024
|
+
(animation.playbackRate = rate);
|
|
779
1025
|
animation.startTime = now - local / rate;
|
|
780
1026
|
}
|
|
781
1027
|
else {
|
|
@@ -849,12 +1095,12 @@ function createGroup(owner) {
|
|
|
849
1095
|
if (group.isJS) {
|
|
850
1096
|
group.isJS = false;
|
|
851
1097
|
needsBuild = true;
|
|
852
|
-
tracks.forEach((track) => track.
|
|
1098
|
+
tracks.forEach((track) => track.stopJS());
|
|
853
1099
|
}
|
|
854
1100
|
const shouldBuild = needsBuild;
|
|
855
1101
|
const churned = hasChurned;
|
|
856
1102
|
needsBuild = hasChurned = false;
|
|
857
|
-
if (shouldBuild || !retime(now)) {
|
|
1103
|
+
if (shouldBuild || !retime(now, churned)) {
|
|
858
1104
|
if (churned) {
|
|
859
1105
|
if (now - lastChurn < churnWindow)
|
|
860
1106
|
return group.demote();
|
|
@@ -863,6 +1109,19 @@ function createGroup(owner) {
|
|
|
863
1109
|
if (!animate(now))
|
|
864
1110
|
return group.demote();
|
|
865
1111
|
}
|
|
1112
|
+
else if (buildAt !== undefined && !churned) {
|
|
1113
|
+
/**
|
|
1114
|
+
* Still waiting to build, so the values still hold where
|
|
1115
|
+
* they start.
|
|
1116
|
+
*/
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Held animations don't move, so set their motion values to where
|
|
1121
|
+
* they're held, as a JSAnimation would on its next tick. Pausing
|
|
1122
|
+
* and seeking schedule this, so it's once however many there are.
|
|
1123
|
+
*/
|
|
1124
|
+
tracks.forEach((track) => track.timing()[0] === Infinity && track.sync());
|
|
866
1125
|
};
|
|
867
1126
|
const group = {
|
|
868
1127
|
tracks,
|
|
@@ -882,7 +1141,7 @@ function createGroup(owner) {
|
|
|
882
1141
|
isScheduled = true;
|
|
883
1142
|
frameData.isProcessing
|
|
884
1143
|
? frame.render(build, false, true)
|
|
885
|
-
:
|
|
1144
|
+
: buildSoon(build);
|
|
886
1145
|
}
|
|
887
1146
|
},
|
|
888
1147
|
/**
|