motion-dom 14.10.0 → 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 +339 -124
- 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/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 +155 -42
- package/dist/es/animation/waapi/transforms/TransformAnimation.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 +17 -3
- package/dist/motion-dom.dev.js +339 -124
- 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
package/dist/cjs/index.js
CHANGED
|
@@ -1425,25 +1425,53 @@ function keyframes({ duration = 300, keyframes: keyframeValues, times, ease = "e
|
|
|
1425
1425
|
value: keyframeValues[0],
|
|
1426
1426
|
};
|
|
1427
1427
|
/**
|
|
1428
|
-
*
|
|
1429
|
-
* a
|
|
1430
|
-
*/
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1428
|
+
* Two keyframes, or keyframes that hold, move once, then hold, as each
|
|
1429
|
+
* value of a sequence does, ease and mix only the pair that moves.
|
|
1430
|
+
*/
|
|
1431
|
+
let span = -1;
|
|
1432
|
+
if (!customMixer) {
|
|
1433
|
+
for (let i = 1; i < keyframeValues.length; i++) {
|
|
1434
|
+
if (keyframeValues[i] !== keyframeValues[i - 1]) {
|
|
1435
|
+
if (span >= 0) {
|
|
1436
|
+
span = -2;
|
|
1437
|
+
break;
|
|
1438
|
+
}
|
|
1439
|
+
span = i - 1;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
if (span >= 0) {
|
|
1444
|
+
const offsets = times && times.length === keyframeValues.length
|
|
1445
|
+
? times
|
|
1446
|
+
: defaultOffset(keyframeValues);
|
|
1447
|
+
const from = offsets[span] * duration;
|
|
1448
|
+
const to = offsets[span + 1] * duration;
|
|
1449
|
+
const origin = keyframeValues[span];
|
|
1450
|
+
const target = keyframeValues[span + 1];
|
|
1451
|
+
const ease = Array.isArray(easingFunctions)
|
|
1452
|
+
? easingFunctions[span]
|
|
1453
|
+
: easingFunctions;
|
|
1454
|
+
const mixer = (motionUtils.MotionGlobalConfig.mix || mix)(origin, target);
|
|
1455
|
+
const last = keyframeValues.length - 2;
|
|
1441
1456
|
return {
|
|
1442
1457
|
calculatedDuration: duration,
|
|
1443
1458
|
next: (t) => {
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1459
|
+
/**
|
|
1460
|
+
* Held keyframes either side of the move are mixed as
|
|
1461
|
+
* interpolate() mixes them, so colours keep its format.
|
|
1462
|
+
*/
|
|
1463
|
+
state.value =
|
|
1464
|
+
span && t < from
|
|
1465
|
+
? mixer(0)
|
|
1466
|
+
: span < last && (t >= to || !duration)
|
|
1467
|
+
? typeof target === "number"
|
|
1468
|
+
? target
|
|
1469
|
+
: mixer(1)
|
|
1470
|
+
: mixer(ease(t >= to || !duration
|
|
1471
|
+
? 1
|
|
1472
|
+
: t <= from
|
|
1473
|
+
? 0
|
|
1474
|
+
: (t - from) / (to - from)));
|
|
1447
1475
|
state.done = t >= duration;
|
|
1448
1476
|
return state;
|
|
1449
1477
|
},
|
|
@@ -1492,13 +1520,27 @@ function calcGeneratorVelocity(generator, t, initialVelocity = 0) {
|
|
|
1492
1520
|
: getGeneratorVelocity((s) => generator.next(s).value, t, generator.next(t).value);
|
|
1493
1521
|
}
|
|
1494
1522
|
|
|
1495
|
-
const isNotNull = (value) => value !== null;
|
|
1496
1523
|
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
1497
|
-
|
|
1524
|
+
/**
|
|
1525
|
+
* The first and last keyframes that aren't null, and how many there
|
|
1526
|
+
* are. Found in one pass rather than filtering into a new array, as
|
|
1527
|
+
* this runs for every value of every animation.
|
|
1528
|
+
*/
|
|
1529
|
+
let first;
|
|
1530
|
+
let last;
|
|
1531
|
+
let numResolved = 0;
|
|
1532
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
1533
|
+
const keyframe = keyframes[i];
|
|
1534
|
+
if (keyframe !== null) {
|
|
1535
|
+
if (!numResolved++)
|
|
1536
|
+
first = keyframe;
|
|
1537
|
+
last = keyframe;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1498
1540
|
const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
|
|
1499
|
-
const index = useFirstKeyframe ? 0 :
|
|
1541
|
+
const index = useFirstKeyframe ? 0 : numResolved - 1;
|
|
1500
1542
|
return !index || finalKeyframe === undefined
|
|
1501
|
-
?
|
|
1543
|
+
? (index ? last : first)
|
|
1502
1544
|
: finalKeyframe;
|
|
1503
1545
|
}
|
|
1504
1546
|
|
|
@@ -2178,14 +2220,26 @@ const defaultValueTypes = {
|
|
|
2178
2220
|
const getDefaultValueType = (key) => defaultValueTypes[key];
|
|
2179
2221
|
|
|
2180
2222
|
const customTypes = /*@__PURE__*/ new Set([filter, mask]);
|
|
2223
|
+
/**
|
|
2224
|
+
* The last call and its result. animate() on many elements asks for the
|
|
2225
|
+
* same none for each one, and parsing the value is the slow part.
|
|
2226
|
+
*/
|
|
2227
|
+
let lastKey;
|
|
2228
|
+
let lastValue;
|
|
2229
|
+
let lastNone;
|
|
2181
2230
|
function getAnimatableNone(key, value) {
|
|
2231
|
+
if (key === lastKey && value === lastValue)
|
|
2232
|
+
return lastNone;
|
|
2182
2233
|
let defaultValueType = getDefaultValueType(key);
|
|
2183
2234
|
if (!customTypes.has(defaultValueType))
|
|
2184
2235
|
defaultValueType = complex;
|
|
2185
2236
|
// If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
|
|
2186
|
-
|
|
2237
|
+
lastNone = defaultValueType.getAnimatableNone
|
|
2187
2238
|
? defaultValueType.getAnimatableNone(value)
|
|
2188
2239
|
: undefined;
|
|
2240
|
+
lastKey = key;
|
|
2241
|
+
lastValue = value;
|
|
2242
|
+
return lastNone;
|
|
2189
2243
|
}
|
|
2190
2244
|
|
|
2191
2245
|
function fillWildcards(keyframes) {
|
|
@@ -3220,7 +3274,8 @@ const buildAhead = 100;
|
|
|
3220
3274
|
/**
|
|
3221
3275
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
3222
3276
|
*/
|
|
3223
|
-
const
|
|
3277
|
+
const nativeEasings = new Set(["linear", "easeIn", "easeOut", "easeInOut"]);
|
|
3278
|
+
const isNativeEasing = (ease) => nativeEasings.has(ease);
|
|
3224
3279
|
/**
|
|
3225
3280
|
* The last trace of each easing WAAPI can't run into linear(), with its
|
|
3226
3281
|
* number of samples, so the elements of a sequence that share an easing
|
|
@@ -3304,6 +3359,54 @@ function canAccelerateTransform(options) {
|
|
|
3304
3359
|
*/
|
|
3305
3360
|
!needsMixer(options));
|
|
3306
3361
|
}
|
|
3362
|
+
/**
|
|
3363
|
+
* Starting or stopping tells the group to update its WAAPI animation.
|
|
3364
|
+
* The frame loop driver is only made once the group is on the main
|
|
3365
|
+
* thread, as accelerated animations never tick.
|
|
3366
|
+
*/
|
|
3367
|
+
class TransformDriver {
|
|
3368
|
+
constructor(element, update, makeDriver, animation) {
|
|
3369
|
+
this.element = element;
|
|
3370
|
+
this.update = update;
|
|
3371
|
+
this.makeDriver = makeDriver;
|
|
3372
|
+
this.animation = animation;
|
|
3373
|
+
}
|
|
3374
|
+
get js() {
|
|
3375
|
+
return (this.driver || (this.driver = this.makeDriver(this.update)));
|
|
3376
|
+
}
|
|
3377
|
+
now() {
|
|
3378
|
+
return this.driver || this.makeDriver !== frameloopDriver
|
|
3379
|
+
? this.js.now()
|
|
3380
|
+
: frameData.isProcessing
|
|
3381
|
+
? frameData.timestamp
|
|
3382
|
+
: time.now();
|
|
3383
|
+
}
|
|
3384
|
+
/**
|
|
3385
|
+
* keepAlive is false when seeking. Seeking the WAAPI animation is
|
|
3386
|
+
* free, but if a seek needs a rebuild and keeps happening, the group
|
|
3387
|
+
* moves to the main thread.
|
|
3388
|
+
*/
|
|
3389
|
+
start(keepAlive = true) {
|
|
3390
|
+
const group = getGroup(this.element);
|
|
3391
|
+
!group || group.isJS
|
|
3392
|
+
? this.js.start(keepAlive)
|
|
3393
|
+
: group.schedule(false, !keepAlive);
|
|
3394
|
+
}
|
|
3395
|
+
stopJS() {
|
|
3396
|
+
this.driver?.stop();
|
|
3397
|
+
}
|
|
3398
|
+
stop() {
|
|
3399
|
+
this.stopJS();
|
|
3400
|
+
const group = getGroup(this.element);
|
|
3401
|
+
group && !group.isFinishing && group.release(this.animation);
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
/**
|
|
3405
|
+
* JSAnimation's time setter, looked up on first use rather than at module
|
|
3406
|
+
* load, so the module has no top-level side effects and stays
|
|
3407
|
+
* tree-shakeable in flattened bundles.
|
|
3408
|
+
*/
|
|
3409
|
+
let setTime;
|
|
3307
3410
|
class TransformAnimation extends JSAnimation {
|
|
3308
3411
|
constructor(options) {
|
|
3309
3412
|
const element = getOwner(options).current;
|
|
@@ -3315,35 +3418,16 @@ class TransformAnimation extends JSAnimation {
|
|
|
3315
3418
|
const canAccelerate = canAccelerateTransform(options);
|
|
3316
3419
|
/**
|
|
3317
3420
|
* The driver ticks on the main thread only once the group has
|
|
3318
|
-
* moved there
|
|
3319
|
-
* update its WAAPI animation.
|
|
3421
|
+
* moved there, so its frame loop driver is made then.
|
|
3320
3422
|
*/
|
|
3321
|
-
options.driver = (update) =>
|
|
3322
|
-
const js = driver(update);
|
|
3323
|
-
return {
|
|
3324
|
-
js,
|
|
3325
|
-
now: js.now,
|
|
3326
|
-
start: (keepAlive = true) => {
|
|
3327
|
-
const group = getGroup(element);
|
|
3328
|
-
const isJS = !group || group.isJS;
|
|
3329
|
-
/**
|
|
3330
|
-
* keepAlive is false when seeking. Seeking the WAAPI
|
|
3331
|
-
* animation is free, but if a seek needs a rebuild and
|
|
3332
|
-
* keeps happening, the group moves to the main thread.
|
|
3333
|
-
*/
|
|
3334
|
-
isJS
|
|
3335
|
-
? js.start(keepAlive)
|
|
3336
|
-
: group.schedule(false, !keepAlive);
|
|
3337
|
-
},
|
|
3338
|
-
stop: () => {
|
|
3339
|
-
js.stop();
|
|
3340
|
-
const group = getGroup(element);
|
|
3341
|
-
group && !group.isFinishing && group.release(animation);
|
|
3342
|
-
},
|
|
3343
|
-
};
|
|
3344
|
-
};
|
|
3423
|
+
options.driver = (update) => new TransformDriver(element, update, driver, animation);
|
|
3345
3424
|
super(options);
|
|
3346
3425
|
animation = this;
|
|
3426
|
+
/**
|
|
3427
|
+
* The first driver is made in super(), before this was assigned.
|
|
3428
|
+
*/
|
|
3429
|
+
const firstDriver = this.driver;
|
|
3430
|
+
firstDriver && (firstDriver.animation = this);
|
|
3347
3431
|
this.canAccelerate = canAccelerate;
|
|
3348
3432
|
/**
|
|
3349
3433
|
* stop is bound in JSAnimation, so wrap it rather than override.
|
|
@@ -3357,12 +3441,29 @@ class TransformAnimation extends JSAnimation {
|
|
|
3357
3441
|
stop();
|
|
3358
3442
|
};
|
|
3359
3443
|
}
|
|
3444
|
+
/**
|
|
3445
|
+
* Each keyframe's offset, made once for the keyframes rather than on
|
|
3446
|
+
* every build.
|
|
3447
|
+
*/
|
|
3448
|
+
offsets() {
|
|
3449
|
+
const { keyframes, times } = this.options;
|
|
3450
|
+
if (times)
|
|
3451
|
+
return times;
|
|
3452
|
+
if (this.offsetsOf !== keyframes) {
|
|
3453
|
+
this.offsetsOf = keyframes;
|
|
3454
|
+
this.cachedOffsets = defaultOffset(keyframes);
|
|
3455
|
+
}
|
|
3456
|
+
return this.cachedOffsets;
|
|
3457
|
+
}
|
|
3360
3458
|
get group() {
|
|
3361
3459
|
return getGroup(getOwner(this.options).current);
|
|
3362
3460
|
}
|
|
3363
3461
|
get js() {
|
|
3364
3462
|
return this.driver?.js;
|
|
3365
3463
|
}
|
|
3464
|
+
stopJS() {
|
|
3465
|
+
this.driver?.stopJS();
|
|
3466
|
+
}
|
|
3366
3467
|
get name() {
|
|
3367
3468
|
return this.options.name;
|
|
3368
3469
|
}
|
|
@@ -3408,7 +3509,7 @@ class TransformAnimation extends JSAnimation {
|
|
|
3408
3509
|
* exactly, otherwise its function, to trace.
|
|
3409
3510
|
*/
|
|
3410
3511
|
tween() {
|
|
3411
|
-
const { keyframes: keyframes$1, type,
|
|
3512
|
+
const { keyframes: keyframes$1, type, repeat, delay = 0 } = this.options;
|
|
3412
3513
|
let span = -1;
|
|
3413
3514
|
if (repeat || type !== keyframes || this.holdTime !== null) {
|
|
3414
3515
|
return;
|
|
@@ -3423,7 +3524,7 @@ class TransformAnimation extends JSAnimation {
|
|
|
3423
3524
|
let { ease } = this.options;
|
|
3424
3525
|
if (motionUtils.isEasingArray(ease))
|
|
3425
3526
|
ease = ease[span];
|
|
3426
|
-
const offsets =
|
|
3527
|
+
const offsets = this.offsets();
|
|
3427
3528
|
const at = (i) => this.startTime +
|
|
3428
3529
|
(delay + offsets[i] * this.totalDuration) / this.speed;
|
|
3429
3530
|
if (span >= 0) {
|
|
@@ -3452,9 +3553,9 @@ class TransformAnimation extends JSAnimation {
|
|
|
3452
3553
|
*/
|
|
3453
3554
|
boundaries(from, to) {
|
|
3454
3555
|
const { startTime, speed, resolvedDuration, options } = this;
|
|
3455
|
-
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType,
|
|
3556
|
+
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType, type, } = options;
|
|
3456
3557
|
const offsets = (type || keyframes) === keyframes
|
|
3457
|
-
?
|
|
3558
|
+
? this.offsets()
|
|
3458
3559
|
: [0, 1];
|
|
3459
3560
|
const start = startTime + delay / speed;
|
|
3460
3561
|
const result = [];
|
|
@@ -3531,8 +3632,12 @@ class TransformAnimation extends JSAnimation {
|
|
|
3531
3632
|
}
|
|
3532
3633
|
return super.time;
|
|
3533
3634
|
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Calls JSAnimation's setter directly, as `super.time =` is a slow
|
|
3637
|
+
* path in V8 and this runs for every animation of a seeked sequence.
|
|
3638
|
+
*/
|
|
3534
3639
|
set time(newTime) {
|
|
3535
|
-
|
|
3640
|
+
(setTime ?? (setTime = Object.getOwnPropertyDescriptor(JSAnimation.prototype, "time").set)).call(this, newTime);
|
|
3536
3641
|
}
|
|
3537
3642
|
/**
|
|
3538
3643
|
* Scroll timelines set time every frame, so run these on the main
|
|
@@ -3578,6 +3683,12 @@ function createGroup(owner) {
|
|
|
3578
3683
|
let hasChurned = false;
|
|
3579
3684
|
let lastChurn = -Infinity;
|
|
3580
3685
|
let wake;
|
|
3686
|
+
let wakeAt = Infinity;
|
|
3687
|
+
/**
|
|
3688
|
+
* While waiting to build a tween that starts later, how long after
|
|
3689
|
+
* the last build to build it.
|
|
3690
|
+
*/
|
|
3691
|
+
let buildAt;
|
|
3581
3692
|
const has = (key) => {
|
|
3582
3693
|
for (const track of tracks)
|
|
3583
3694
|
if (track.name === key)
|
|
@@ -3646,6 +3757,8 @@ function createGroup(owner) {
|
|
|
3646
3757
|
*/
|
|
3647
3758
|
const stop = (shouldCommit = true) => {
|
|
3648
3759
|
clearTimeout(wake);
|
|
3760
|
+
wakeAt = Infinity;
|
|
3761
|
+
buildAt = undefined;
|
|
3649
3762
|
shouldCommit && commit();
|
|
3650
3763
|
segments.forEach(({ animation }) => cancel(animation));
|
|
3651
3764
|
segments = [];
|
|
@@ -3875,7 +3988,13 @@ function createGroup(owner) {
|
|
|
3875
3988
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
3876
3989
|
*/
|
|
3877
3990
|
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
3878
|
-
|
|
3991
|
+
/**
|
|
3992
|
+
* With an easing given, there's nothing to sample, so no need
|
|
3993
|
+
* for the boundaries.
|
|
3994
|
+
*/
|
|
3995
|
+
const bounds = nativeEasing
|
|
3996
|
+
? []
|
|
3997
|
+
: moving.flatMap((track) => track.boundaries(from, to));
|
|
3879
3998
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
3880
3999
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
3881
4000
|
const transform = times.map((t) => compose(t, settled));
|
|
@@ -3898,6 +4017,23 @@ function createGroup(owner) {
|
|
|
3898
4017
|
easing: easing || "linear",
|
|
3899
4018
|
});
|
|
3900
4019
|
};
|
|
4020
|
+
/**
|
|
4021
|
+
* Check whether it's time to build in this long. A check that's due
|
|
4022
|
+
* sooner is kept, and checks again if it's early, so pausing and
|
|
4023
|
+
* playing don't each replace a timer. One due later, after a seek or
|
|
4024
|
+
* speed change while held, is replaced.
|
|
4025
|
+
*/
|
|
4026
|
+
const wakeIn = (delay) => {
|
|
4027
|
+
const at = time.now() + delay;
|
|
4028
|
+
if (at < wakeAt) {
|
|
4029
|
+
clearTimeout(wake);
|
|
4030
|
+
wakeAt = at;
|
|
4031
|
+
wake = setTimeout(() => {
|
|
4032
|
+
wakeAt = Infinity;
|
|
4033
|
+
group.schedule(false);
|
|
4034
|
+
}, delay);
|
|
4035
|
+
}
|
|
4036
|
+
};
|
|
3901
4037
|
/**
|
|
3902
4038
|
* Replace the WAAPI animations with ones built from now. Returns
|
|
3903
4039
|
* undefined if the animations can't be composed.
|
|
@@ -3973,7 +4109,7 @@ function createGroup(owner) {
|
|
|
3973
4109
|
*/
|
|
3974
4110
|
if (from - now > buildAhead) {
|
|
3975
4111
|
moving.forEach((track) => track.sync());
|
|
3976
|
-
|
|
4112
|
+
wakeIn((buildAt = from - now - buildAhead));
|
|
3977
4113
|
return true;
|
|
3978
4114
|
}
|
|
3979
4115
|
easing =
|
|
@@ -4028,9 +4164,11 @@ function createGroup(owner) {
|
|
|
4028
4164
|
/**
|
|
4029
4165
|
* If every animation has been paused, played, seeked or sped up
|
|
4030
4166
|
* together since the WAAPI animation was built, do the same to it.
|
|
4031
|
-
* Returns false if it needs rebuilding instead.
|
|
4167
|
+
* Returns false if it needs rebuilding instead. Seeking to before a
|
|
4168
|
+
* tween starts rebuilds, so a running group seeked every frame still
|
|
4169
|
+
* moves to the main thread.
|
|
4032
4170
|
*/
|
|
4033
|
-
const retime = (now) => {
|
|
4171
|
+
const retime = (now, isSeek) => {
|
|
4034
4172
|
let elapsed;
|
|
4035
4173
|
let rate = 0;
|
|
4036
4174
|
for (const track of tracks) {
|
|
@@ -4063,12 +4201,33 @@ function createGroup(owner) {
|
|
|
4063
4201
|
}
|
|
4064
4202
|
if (elapsed === undefined)
|
|
4065
4203
|
return true;
|
|
4066
|
-
|
|
4067
|
-
|
|
4204
|
+
/**
|
|
4205
|
+
* Waiting to build a tween that starts later. Until then the
|
|
4206
|
+
* values hold where they start, so only when to build changes.
|
|
4207
|
+
* Held, it has nothing on the compositor, so it can be seeked.
|
|
4208
|
+
*/
|
|
4209
|
+
if (!segments.length) {
|
|
4210
|
+
if (buildAt === undefined || (isSeek && rate))
|
|
4211
|
+
return false;
|
|
4212
|
+
if (rate) {
|
|
4213
|
+
const delay = (buildAt - elapsed) / rate;
|
|
4214
|
+
if (delay < 1)
|
|
4215
|
+
return false;
|
|
4216
|
+
wakeIn(delay);
|
|
4217
|
+
}
|
|
4218
|
+
return true;
|
|
4219
|
+
}
|
|
4220
|
+
/**
|
|
4221
|
+
* Only a tween is built to start later, and it holds its first
|
|
4222
|
+
* keyframe until then, so it can be paused and played before it
|
|
4223
|
+
* starts.
|
|
4224
|
+
*/
|
|
4068
4225
|
for (const { offset, end, isDone } of segments) {
|
|
4069
4226
|
const local = elapsed - offset;
|
|
4070
4227
|
if (end < Infinity &&
|
|
4071
|
-
(isDone
|
|
4228
|
+
(isDone
|
|
4229
|
+
? local < end - 1
|
|
4230
|
+
: (local < 0 && (isSeek || offset <= 0)) || local >= end)) {
|
|
4072
4231
|
return false;
|
|
4073
4232
|
}
|
|
4074
4233
|
}
|
|
@@ -4089,7 +4248,8 @@ function createGroup(owner) {
|
|
|
4089
4248
|
animation.updatePlaybackRate(rate);
|
|
4090
4249
|
}
|
|
4091
4250
|
else if (rate) {
|
|
4092
|
-
animation.playbackRate
|
|
4251
|
+
animation.playbackRate !== rate &&
|
|
4252
|
+
(animation.playbackRate = rate);
|
|
4093
4253
|
animation.startTime = now - local / rate;
|
|
4094
4254
|
}
|
|
4095
4255
|
else {
|
|
@@ -4163,12 +4323,12 @@ function createGroup(owner) {
|
|
|
4163
4323
|
if (group.isJS) {
|
|
4164
4324
|
group.isJS = false;
|
|
4165
4325
|
needsBuild = true;
|
|
4166
|
-
tracks.forEach((track) => track.
|
|
4326
|
+
tracks.forEach((track) => track.stopJS());
|
|
4167
4327
|
}
|
|
4168
4328
|
const shouldBuild = needsBuild;
|
|
4169
4329
|
const churned = hasChurned;
|
|
4170
4330
|
needsBuild = hasChurned = false;
|
|
4171
|
-
if (shouldBuild || !retime(now)) {
|
|
4331
|
+
if (shouldBuild || !retime(now, churned)) {
|
|
4172
4332
|
if (churned) {
|
|
4173
4333
|
if (now - lastChurn < churnWindow)
|
|
4174
4334
|
return group.demote();
|
|
@@ -4177,6 +4337,13 @@ function createGroup(owner) {
|
|
|
4177
4337
|
if (!animate(now))
|
|
4178
4338
|
return group.demote();
|
|
4179
4339
|
}
|
|
4340
|
+
else if (buildAt !== undefined && !churned) {
|
|
4341
|
+
/**
|
|
4342
|
+
* Still waiting to build, so the values still hold where
|
|
4343
|
+
* they start.
|
|
4344
|
+
*/
|
|
4345
|
+
return;
|
|
4346
|
+
}
|
|
4180
4347
|
/**
|
|
4181
4348
|
* Held animations don't move, so set their motion values to where
|
|
4182
4349
|
* they're held, as a JSAnimation would on its next tick. Pausing
|
|
@@ -4444,7 +4611,10 @@ class AsyncMotionValueAnimation extends WithPromise {
|
|
|
4444
4611
|
class GroupAnimation {
|
|
4445
4612
|
constructor(animations) {
|
|
4446
4613
|
// Bound to accommodate common `return animation.stop` pattern
|
|
4447
|
-
this.stop = () =>
|
|
4614
|
+
this.stop = () => {
|
|
4615
|
+
for (const animation of this.animations)
|
|
4616
|
+
animation.stop();
|
|
4617
|
+
};
|
|
4448
4618
|
this.animations = animations.filter(Boolean);
|
|
4449
4619
|
}
|
|
4450
4620
|
get finished() {
|
|
@@ -4456,11 +4626,6 @@ class GroupAnimation {
|
|
|
4456
4626
|
getAll(propName) {
|
|
4457
4627
|
return this.animations[0][propName];
|
|
4458
4628
|
}
|
|
4459
|
-
setAll(propName, newValue) {
|
|
4460
|
-
for (let i = 0; i < this.animations.length; i++) {
|
|
4461
|
-
this.animations[i][propName] = newValue;
|
|
4462
|
-
}
|
|
4463
|
-
}
|
|
4464
4629
|
attachTimeline(timeline) {
|
|
4465
4630
|
const subscriptions = this.animations.map((animation) => animation.attachTimeline(timeline));
|
|
4466
4631
|
return () => {
|
|
@@ -4473,14 +4638,21 @@ class GroupAnimation {
|
|
|
4473
4638
|
get time() {
|
|
4474
4639
|
return this.getAll("time");
|
|
4475
4640
|
}
|
|
4641
|
+
/**
|
|
4642
|
+
* Setters and methods name the property directly, rather than through
|
|
4643
|
+
* a shared helper, so each call site stays monomorphic. Sequences
|
|
4644
|
+
* call these on every animation, many times a second.
|
|
4645
|
+
*/
|
|
4476
4646
|
set time(time) {
|
|
4477
|
-
this.
|
|
4647
|
+
for (const animation of this.animations)
|
|
4648
|
+
animation.time = time;
|
|
4478
4649
|
}
|
|
4479
4650
|
get speed() {
|
|
4480
4651
|
return this.getAll("speed");
|
|
4481
4652
|
}
|
|
4482
4653
|
set speed(speed) {
|
|
4483
|
-
this.
|
|
4654
|
+
for (const animation of this.animations)
|
|
4655
|
+
animation.speed = speed;
|
|
4484
4656
|
}
|
|
4485
4657
|
get state() {
|
|
4486
4658
|
return this.getAll("state");
|
|
@@ -4494,20 +4666,21 @@ class GroupAnimation {
|
|
|
4494
4666
|
get iterationDuration() {
|
|
4495
4667
|
return getMax(this.animations, "iterationDuration");
|
|
4496
4668
|
}
|
|
4497
|
-
runAll(methodName) {
|
|
4498
|
-
this.animations.forEach((controls) => controls[methodName]());
|
|
4499
|
-
}
|
|
4500
4669
|
play() {
|
|
4501
|
-
this.
|
|
4670
|
+
for (const animation of this.animations)
|
|
4671
|
+
animation.play();
|
|
4502
4672
|
}
|
|
4503
4673
|
pause() {
|
|
4504
|
-
this.
|
|
4674
|
+
for (const animation of this.animations)
|
|
4675
|
+
animation.pause();
|
|
4505
4676
|
}
|
|
4506
4677
|
cancel() {
|
|
4507
|
-
this.
|
|
4678
|
+
for (const animation of this.animations)
|
|
4679
|
+
animation.cancel();
|
|
4508
4680
|
}
|
|
4509
4681
|
complete() {
|
|
4510
|
-
this.
|
|
4682
|
+
for (const animation of this.animations)
|
|
4683
|
+
animation.complete();
|
|
4511
4684
|
}
|
|
4512
4685
|
}
|
|
4513
4686
|
function getMax(animations, propName) {
|
|
@@ -4867,28 +5040,32 @@ class MotionValue {
|
|
|
4867
5040
|
* @param animation - A function that starts the provided animation
|
|
4868
5041
|
*/
|
|
4869
5042
|
start(startAnimation) {
|
|
5043
|
+
return new Promise((resolve) => this.run(startAnimation, resolve));
|
|
5044
|
+
}
|
|
5045
|
+
/**
|
|
5046
|
+
* As start(), without making a promise, for animations started
|
|
5047
|
+
* internally, which complete through their own controls.
|
|
5048
|
+
*/
|
|
5049
|
+
run(startAnimation, onComplete) {
|
|
4870
5050
|
this.stop();
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
this.
|
|
4884
|
-
|
|
4885
|
-
this.animation = undefined;
|
|
4886
|
-
resolve();
|
|
4887
|
-
});
|
|
4888
|
-
if (!isComplete)
|
|
4889
|
-
this.animation = animation;
|
|
4890
|
-
this.events.animationStart?.notify();
|
|
5051
|
+
this.hasAnimated = true;
|
|
5052
|
+
/**
|
|
5053
|
+
* Guard against animations that complete before startAnimation
|
|
5054
|
+
* has returned.
|
|
5055
|
+
*/
|
|
5056
|
+
let isComplete = false;
|
|
5057
|
+
let animation;
|
|
5058
|
+
// eslint-disable-next-line prefer-const -- read by the callback before assignment when completing synchronously
|
|
5059
|
+
animation = startAnimation(() => {
|
|
5060
|
+
isComplete = true;
|
|
5061
|
+
this.events.animationComplete?.notify();
|
|
5062
|
+
if (this.animation === animation)
|
|
5063
|
+
this.animation = undefined;
|
|
5064
|
+
onComplete?.();
|
|
4891
5065
|
});
|
|
5066
|
+
if (!isComplete)
|
|
5067
|
+
this.animation = animation;
|
|
5068
|
+
this.events.animationStart?.notify();
|
|
4892
5069
|
}
|
|
4893
5070
|
/**
|
|
4894
5071
|
* Stop the currently active animation.
|
|
@@ -5511,7 +5688,7 @@ function animateTarget(visualElement, targetAndTransition, { delay = 0, transiti
|
|
|
5511
5688
|
}
|
|
5512
5689
|
addValueToWillChange(visualElement, key);
|
|
5513
5690
|
const shouldReduceMotion = reduceMotion ?? visualElement.shouldReduceMotion;
|
|
5514
|
-
value.
|
|
5691
|
+
value.run(animateMotionValue(key, value, valueTarget, shouldReduceMotion && positionalKeys.has(key)
|
|
5515
5692
|
? { type: false }
|
|
5516
5693
|
: valueTransition, visualElement, isHandoff));
|
|
5517
5694
|
const animation = value.animation;
|
|
@@ -5646,9 +5823,14 @@ function makeNoneKeyframesAnimatable(unresolvedKeyframes, noneKeyframeIndexes, n
|
|
|
5646
5823
|
}
|
|
5647
5824
|
|
|
5648
5825
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5826
|
+
/**
|
|
5827
|
+
* Passes isAsync to the base constructor rather than setting it as a
|
|
5828
|
+
* class field, which would compile to a constructor that spreads
|
|
5829
|
+
* `arguments` into super(). That spread is slow in the interpreter,
|
|
5830
|
+
* and animate() constructs one resolver per value.
|
|
5831
|
+
*/
|
|
5832
|
+
constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
|
|
5833
|
+
super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
|
|
5652
5834
|
}
|
|
5653
5835
|
/**
|
|
5654
5836
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -5948,7 +6130,7 @@ function animateValues(getValue, keyframes, transition = {}, element) {
|
|
|
5948
6130
|
frame.update(() => value.set(target));
|
|
5949
6131
|
continue;
|
|
5950
6132
|
}
|
|
5951
|
-
value.
|
|
6133
|
+
value.run(animateMotionValue(key, value, target, reduceMotion && positionalKeys.has(key)
|
|
5952
6134
|
? { type: false }
|
|
5953
6135
|
: transition, element));
|
|
5954
6136
|
value.animation &&
|
|
@@ -5978,8 +6160,14 @@ function animateValues(getValue, keyframes, transition = {}, element) {
|
|
|
5978
6160
|
* measurement) via `element`.
|
|
5979
6161
|
*/
|
|
5980
6162
|
function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
5981
|
-
|
|
5982
|
-
|
|
6163
|
+
/**
|
|
6164
|
+
* Values made for this call are bound with one effect call, after the
|
|
6165
|
+
* loop, rather than one each.
|
|
6166
|
+
*/
|
|
6167
|
+
let created;
|
|
6168
|
+
let isBound = false;
|
|
6169
|
+
const animations = animateValues((key) => {
|
|
6170
|
+
let value = created?.[key] ?? effect.get(subject, key);
|
|
5983
6171
|
if (!value) {
|
|
5984
6172
|
let initial;
|
|
5985
6173
|
if (!element) {
|
|
@@ -5991,10 +6179,15 @@ function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
|
5991
6179
|
motionUtils.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
5992
6180
|
}
|
|
5993
6181
|
value = motionValue(initial, { owner: element });
|
|
5994
|
-
|
|
6182
|
+
isBound
|
|
6183
|
+
? effect(subject, { [key]: value })
|
|
6184
|
+
: ((created || (created = {}))[key] = value);
|
|
5995
6185
|
}
|
|
5996
6186
|
return value;
|
|
5997
6187
|
}, keyframes, transition, element);
|
|
6188
|
+
isBound = true;
|
|
6189
|
+
created && effect(subject, created);
|
|
6190
|
+
return animations;
|
|
5998
6191
|
}
|
|
5999
6192
|
function firstKeyframe(target) {
|
|
6000
6193
|
const first = Array.isArray(target) ? target[0] : undefined;
|
|
@@ -6990,7 +7183,7 @@ const processFrame = (timestamp = time.now()) => {
|
|
|
6990
7183
|
|
|
6991
7184
|
function animateSingleValue(value, keyframes, options) {
|
|
6992
7185
|
const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
|
|
6993
|
-
motionValue$1.
|
|
7186
|
+
motionValue$1.run(animateMotionValue("", motionValue$1, keyframes, options));
|
|
6994
7187
|
return motionValue$1.animation;
|
|
6995
7188
|
}
|
|
6996
7189
|
|
|
@@ -7497,13 +7690,7 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
7497
7690
|
if (xTranslate || yTranslate || zTranslate) {
|
|
7498
7691
|
transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `;
|
|
7499
7692
|
}
|
|
7500
|
-
|
|
7501
|
-
* Apply scale correction for the tree transform.
|
|
7502
|
-
* This will apply scale to the screen-orientated axes.
|
|
7503
|
-
*/
|
|
7504
|
-
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
7505
|
-
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
7506
|
-
}
|
|
7693
|
+
let angles = "";
|
|
7507
7694
|
if (latestTransform) {
|
|
7508
7695
|
const { transformPerspective } = latestTransform;
|
|
7509
7696
|
if (transformPerspective)
|
|
@@ -7512,20 +7699,48 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
7512
7699
|
const key = angleTransforms[i];
|
|
7513
7700
|
const value = latestTransform[key];
|
|
7514
7701
|
if (value)
|
|
7515
|
-
|
|
7702
|
+
angles += `${key}(${value}deg) `;
|
|
7516
7703
|
// Additive `rotate()` so user `rotate` isn't clobbered.
|
|
7517
7704
|
if (!i && latestTransform.pathRotation)
|
|
7518
|
-
|
|
7705
|
+
angles += `rotate(${latestTransform.pathRotation}deg) `;
|
|
7519
7706
|
}
|
|
7520
7707
|
}
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7708
|
+
if (angles) {
|
|
7709
|
+
/**
|
|
7710
|
+
* Apply scale correction for the tree transform.
|
|
7711
|
+
* This will apply scale to the screen-orientated axes.
|
|
7712
|
+
*/
|
|
7713
|
+
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
7714
|
+
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
7715
|
+
}
|
|
7716
|
+
transform += angles;
|
|
7717
|
+
/**
|
|
7718
|
+
* Apply scale to match the size of the element to the size we want it.
|
|
7719
|
+
* This will apply scale to the element-orientated axes.
|
|
7720
|
+
*/
|
|
7721
|
+
const elementScaleX = delta.x.scale * treeScale.x;
|
|
7722
|
+
const elementScaleY = delta.y.scale * treeScale.y;
|
|
7723
|
+
if (elementScaleX !== 1 || elementScaleY !== 1) {
|
|
7724
|
+
transform += `scale(${elementScaleX}, ${elementScaleY})`;
|
|
7725
|
+
}
|
|
7726
|
+
}
|
|
7727
|
+
else if (delta.x.scale !== 1 || delta.y.scale !== 1) {
|
|
7728
|
+
/**
|
|
7729
|
+
* With no rotation or skew between them, the tree scale correction
|
|
7730
|
+
* (1 / treeScale) and the element scale (delta.scale * treeScale)
|
|
7731
|
+
* combine into a single scale. A shorter transform is quicker for
|
|
7732
|
+
* the browser to parse, which matters when it's set every frame.
|
|
7733
|
+
*/
|
|
7734
|
+
transform += `scale(${delta.x.scale}, ${delta.y.scale})`;
|
|
7735
|
+
}
|
|
7736
|
+
else if (!transform && (treeScale.x !== 1 || treeScale.y !== 1)) {
|
|
7737
|
+
/**
|
|
7738
|
+
* Inside a scaled tree the transform must never be "none", even when
|
|
7739
|
+
* this element's own delta is the identity: scale correction for
|
|
7740
|
+
* borderRadius and boxShadow is skipped for "none", and the element
|
|
7741
|
+
* would gain and lose its stacking context as the delta snaps.
|
|
7742
|
+
*/
|
|
7743
|
+
transform = "scale(1, 1)";
|
|
7529
7744
|
}
|
|
7530
7745
|
return transform || "none";
|
|
7531
7746
|
}
|