motion 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/motion.dev.js +382 -152
- package/dist/motion.js +1 -1
- package/package.json +3 -3
package/dist/motion.dev.js
CHANGED
|
@@ -1732,25 +1732,53 @@
|
|
|
1732
1732
|
value: keyframeValues[0],
|
|
1733
1733
|
};
|
|
1734
1734
|
/**
|
|
1735
|
-
*
|
|
1736
|
-
* a
|
|
1735
|
+
* Two keyframes, or keyframes that hold, move once, then hold, as each
|
|
1736
|
+
* value of a sequence does, ease and mix only the pair that moves.
|
|
1737
1737
|
*/
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1738
|
+
let span = -1;
|
|
1739
|
+
if (!customMixer) {
|
|
1740
|
+
for (let i = 1; i < keyframeValues.length; i++) {
|
|
1741
|
+
if (keyframeValues[i] !== keyframeValues[i - 1]) {
|
|
1742
|
+
if (span >= 0) {
|
|
1743
|
+
span = -2;
|
|
1744
|
+
break;
|
|
1745
|
+
}
|
|
1746
|
+
span = i - 1;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
if (span >= 0) {
|
|
1751
|
+
const offsets = times && times.length === keyframeValues.length
|
|
1752
|
+
? times
|
|
1753
|
+
: defaultOffset$1(keyframeValues);
|
|
1754
|
+
const from = offsets[span] * duration;
|
|
1755
|
+
const to = offsets[span + 1] * duration;
|
|
1756
|
+
const origin = keyframeValues[span];
|
|
1757
|
+
const target = keyframeValues[span + 1];
|
|
1758
|
+
const ease = Array.isArray(easingFunctions)
|
|
1759
|
+
? easingFunctions[span]
|
|
1760
|
+
: easingFunctions;
|
|
1761
|
+
const mixer = (MotionGlobalConfig.mix || mix)(origin, target);
|
|
1762
|
+
const last = keyframeValues.length - 2;
|
|
1748
1763
|
return {
|
|
1749
1764
|
calculatedDuration: duration,
|
|
1750
1765
|
next: (t) => {
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1766
|
+
/**
|
|
1767
|
+
* Held keyframes either side of the move are mixed as
|
|
1768
|
+
* interpolate() mixes them, so colours keep its format.
|
|
1769
|
+
*/
|
|
1770
|
+
state.value =
|
|
1771
|
+
span && t < from
|
|
1772
|
+
? mixer(0)
|
|
1773
|
+
: span < last && (t >= to || !duration)
|
|
1774
|
+
? typeof target === "number"
|
|
1775
|
+
? target
|
|
1776
|
+
: mixer(1)
|
|
1777
|
+
: mixer(ease(t >= to || !duration
|
|
1778
|
+
? 1
|
|
1779
|
+
: t <= from
|
|
1780
|
+
? 0
|
|
1781
|
+
: (t - from) / (to - from)));
|
|
1754
1782
|
state.done = t >= duration;
|
|
1755
1783
|
return state;
|
|
1756
1784
|
},
|
|
@@ -1799,13 +1827,27 @@
|
|
|
1799
1827
|
: getGeneratorVelocity((s) => generator.next(s).value, t, generator.next(t).value);
|
|
1800
1828
|
}
|
|
1801
1829
|
|
|
1802
|
-
const isNotNull = (value) => value !== null;
|
|
1803
1830
|
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
1804
|
-
|
|
1831
|
+
/**
|
|
1832
|
+
* The first and last keyframes that aren't null, and how many there
|
|
1833
|
+
* are. Found in one pass rather than filtering into a new array, as
|
|
1834
|
+
* this runs for every value of every animation.
|
|
1835
|
+
*/
|
|
1836
|
+
let first;
|
|
1837
|
+
let last;
|
|
1838
|
+
let numResolved = 0;
|
|
1839
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
1840
|
+
const keyframe = keyframes[i];
|
|
1841
|
+
if (keyframe !== null) {
|
|
1842
|
+
if (!numResolved++)
|
|
1843
|
+
first = keyframe;
|
|
1844
|
+
last = keyframe;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1805
1847
|
const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
|
|
1806
|
-
const index = useFirstKeyframe ? 0 :
|
|
1848
|
+
const index = useFirstKeyframe ? 0 : numResolved - 1;
|
|
1807
1849
|
return !index || finalKeyframe === undefined
|
|
1808
|
-
?
|
|
1850
|
+
? (index ? last : first)
|
|
1809
1851
|
: finalKeyframe;
|
|
1810
1852
|
}
|
|
1811
1853
|
|
|
@@ -2484,14 +2526,26 @@
|
|
|
2484
2526
|
const getDefaultValueType = (key) => defaultValueTypes[key];
|
|
2485
2527
|
|
|
2486
2528
|
const customTypes = /*@__PURE__*/ new Set([filter, mask]);
|
|
2529
|
+
/**
|
|
2530
|
+
* The last call and its result. animate() on many elements asks for the
|
|
2531
|
+
* same none for each one, and parsing the value is the slow part.
|
|
2532
|
+
*/
|
|
2533
|
+
let lastKey;
|
|
2534
|
+
let lastValue;
|
|
2535
|
+
let lastNone;
|
|
2487
2536
|
function getAnimatableNone(key, value) {
|
|
2537
|
+
if (key === lastKey && value === lastValue)
|
|
2538
|
+
return lastNone;
|
|
2488
2539
|
let defaultValueType = getDefaultValueType(key);
|
|
2489
2540
|
if (!customTypes.has(defaultValueType))
|
|
2490
2541
|
defaultValueType = complex;
|
|
2491
2542
|
// If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
|
|
2492
|
-
|
|
2543
|
+
lastNone = defaultValueType.getAnimatableNone
|
|
2493
2544
|
? defaultValueType.getAnimatableNone(value)
|
|
2494
2545
|
: undefined;
|
|
2546
|
+
lastKey = key;
|
|
2547
|
+
lastValue = value;
|
|
2548
|
+
return lastNone;
|
|
2495
2549
|
}
|
|
2496
2550
|
|
|
2497
2551
|
function fillWildcards(keyframes) {
|
|
@@ -3526,7 +3580,8 @@
|
|
|
3526
3580
|
/**
|
|
3527
3581
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
3528
3582
|
*/
|
|
3529
|
-
const
|
|
3583
|
+
const nativeEasings = new Set(["linear", "easeIn", "easeOut", "easeInOut"]);
|
|
3584
|
+
const isNativeEasing = (ease) => nativeEasings.has(ease);
|
|
3530
3585
|
/**
|
|
3531
3586
|
* The last trace of each easing WAAPI can't run into linear(), with its
|
|
3532
3587
|
* number of samples, so the elements of a sequence that share an easing
|
|
@@ -3610,6 +3665,54 @@
|
|
|
3610
3665
|
*/
|
|
3611
3666
|
!needsMixer(options));
|
|
3612
3667
|
}
|
|
3668
|
+
/**
|
|
3669
|
+
* Starting or stopping tells the group to update its WAAPI animation.
|
|
3670
|
+
* The frame loop driver is only made once the group is on the main
|
|
3671
|
+
* thread, as accelerated animations never tick.
|
|
3672
|
+
*/
|
|
3673
|
+
class TransformDriver {
|
|
3674
|
+
constructor(element, update, makeDriver, animation) {
|
|
3675
|
+
this.element = element;
|
|
3676
|
+
this.update = update;
|
|
3677
|
+
this.makeDriver = makeDriver;
|
|
3678
|
+
this.animation = animation;
|
|
3679
|
+
}
|
|
3680
|
+
get js() {
|
|
3681
|
+
return (this.driver || (this.driver = this.makeDriver(this.update)));
|
|
3682
|
+
}
|
|
3683
|
+
now() {
|
|
3684
|
+
return this.driver || this.makeDriver !== frameloopDriver
|
|
3685
|
+
? this.js.now()
|
|
3686
|
+
: frameData.isProcessing
|
|
3687
|
+
? frameData.timestamp
|
|
3688
|
+
: time.now();
|
|
3689
|
+
}
|
|
3690
|
+
/**
|
|
3691
|
+
* keepAlive is false when seeking. Seeking the WAAPI animation is
|
|
3692
|
+
* free, but if a seek needs a rebuild and keeps happening, the group
|
|
3693
|
+
* moves to the main thread.
|
|
3694
|
+
*/
|
|
3695
|
+
start(keepAlive = true) {
|
|
3696
|
+
const group = getGroup(this.element);
|
|
3697
|
+
!group || group.isJS
|
|
3698
|
+
? this.js.start(keepAlive)
|
|
3699
|
+
: group.schedule(false, !keepAlive);
|
|
3700
|
+
}
|
|
3701
|
+
stopJS() {
|
|
3702
|
+
this.driver?.stop();
|
|
3703
|
+
}
|
|
3704
|
+
stop() {
|
|
3705
|
+
this.stopJS();
|
|
3706
|
+
const group = getGroup(this.element);
|
|
3707
|
+
group && !group.isFinishing && group.release(this.animation);
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
/**
|
|
3711
|
+
* JSAnimation's time setter, looked up on first use rather than at module
|
|
3712
|
+
* load, so the module has no top-level side effects and stays
|
|
3713
|
+
* tree-shakeable in flattened bundles.
|
|
3714
|
+
*/
|
|
3715
|
+
let setTime;
|
|
3613
3716
|
class TransformAnimation extends JSAnimation {
|
|
3614
3717
|
constructor(options) {
|
|
3615
3718
|
const element = getOwner(options).current;
|
|
@@ -3621,35 +3724,16 @@
|
|
|
3621
3724
|
const canAccelerate = canAccelerateTransform(options);
|
|
3622
3725
|
/**
|
|
3623
3726
|
* The driver ticks on the main thread only once the group has
|
|
3624
|
-
* moved there
|
|
3625
|
-
* update its WAAPI animation.
|
|
3727
|
+
* moved there, so its frame loop driver is made then.
|
|
3626
3728
|
*/
|
|
3627
|
-
options.driver = (update) =>
|
|
3628
|
-
const js = driver(update);
|
|
3629
|
-
return {
|
|
3630
|
-
js,
|
|
3631
|
-
now: js.now,
|
|
3632
|
-
start: (keepAlive = true) => {
|
|
3633
|
-
const group = getGroup(element);
|
|
3634
|
-
const isJS = !group || group.isJS;
|
|
3635
|
-
/**
|
|
3636
|
-
* keepAlive is false when seeking. Seeking the WAAPI
|
|
3637
|
-
* animation is free, but if a seek needs a rebuild and
|
|
3638
|
-
* keeps happening, the group moves to the main thread.
|
|
3639
|
-
*/
|
|
3640
|
-
isJS
|
|
3641
|
-
? js.start(keepAlive)
|
|
3642
|
-
: group.schedule(false, !keepAlive);
|
|
3643
|
-
},
|
|
3644
|
-
stop: () => {
|
|
3645
|
-
js.stop();
|
|
3646
|
-
const group = getGroup(element);
|
|
3647
|
-
group && !group.isFinishing && group.release(animation);
|
|
3648
|
-
},
|
|
3649
|
-
};
|
|
3650
|
-
};
|
|
3729
|
+
options.driver = (update) => new TransformDriver(element, update, driver, animation);
|
|
3651
3730
|
super(options);
|
|
3652
3731
|
animation = this;
|
|
3732
|
+
/**
|
|
3733
|
+
* The first driver is made in super(), before this was assigned.
|
|
3734
|
+
*/
|
|
3735
|
+
const firstDriver = this.driver;
|
|
3736
|
+
firstDriver && (firstDriver.animation = this);
|
|
3653
3737
|
this.canAccelerate = canAccelerate;
|
|
3654
3738
|
/**
|
|
3655
3739
|
* stop is bound in JSAnimation, so wrap it rather than override.
|
|
@@ -3663,12 +3747,29 @@
|
|
|
3663
3747
|
stop();
|
|
3664
3748
|
};
|
|
3665
3749
|
}
|
|
3750
|
+
/**
|
|
3751
|
+
* Each keyframe's offset, made once for the keyframes rather than on
|
|
3752
|
+
* every build.
|
|
3753
|
+
*/
|
|
3754
|
+
offsets() {
|
|
3755
|
+
const { keyframes, times } = this.options;
|
|
3756
|
+
if (times)
|
|
3757
|
+
return times;
|
|
3758
|
+
if (this.offsetsOf !== keyframes) {
|
|
3759
|
+
this.offsetsOf = keyframes;
|
|
3760
|
+
this.cachedOffsets = defaultOffset$1(keyframes);
|
|
3761
|
+
}
|
|
3762
|
+
return this.cachedOffsets;
|
|
3763
|
+
}
|
|
3666
3764
|
get group() {
|
|
3667
3765
|
return getGroup(getOwner(this.options).current);
|
|
3668
3766
|
}
|
|
3669
3767
|
get js() {
|
|
3670
3768
|
return this.driver?.js;
|
|
3671
3769
|
}
|
|
3770
|
+
stopJS() {
|
|
3771
|
+
this.driver?.stopJS();
|
|
3772
|
+
}
|
|
3672
3773
|
get name() {
|
|
3673
3774
|
return this.options.name;
|
|
3674
3775
|
}
|
|
@@ -3714,7 +3815,7 @@
|
|
|
3714
3815
|
* exactly, otherwise its function, to trace.
|
|
3715
3816
|
*/
|
|
3716
3817
|
tween() {
|
|
3717
|
-
const { keyframes: keyframes$1, type,
|
|
3818
|
+
const { keyframes: keyframes$1, type, repeat, delay = 0 } = this.options;
|
|
3718
3819
|
let span = -1;
|
|
3719
3820
|
if (repeat || type !== keyframes || this.holdTime !== null) {
|
|
3720
3821
|
return;
|
|
@@ -3729,7 +3830,7 @@
|
|
|
3729
3830
|
let { ease } = this.options;
|
|
3730
3831
|
if (isEasingArray(ease))
|
|
3731
3832
|
ease = ease[span];
|
|
3732
|
-
const offsets =
|
|
3833
|
+
const offsets = this.offsets();
|
|
3733
3834
|
const at = (i) => this.startTime +
|
|
3734
3835
|
(delay + offsets[i] * this.totalDuration) / this.speed;
|
|
3735
3836
|
if (span >= 0) {
|
|
@@ -3758,9 +3859,9 @@
|
|
|
3758
3859
|
*/
|
|
3759
3860
|
boundaries(from, to) {
|
|
3760
3861
|
const { startTime, speed, resolvedDuration, options } = this;
|
|
3761
|
-
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType,
|
|
3862
|
+
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType, type, } = options;
|
|
3762
3863
|
const offsets = (type || keyframes) === keyframes
|
|
3763
|
-
?
|
|
3864
|
+
? this.offsets()
|
|
3764
3865
|
: [0, 1];
|
|
3765
3866
|
const start = startTime + delay / speed;
|
|
3766
3867
|
const result = [];
|
|
@@ -3837,8 +3938,12 @@
|
|
|
3837
3938
|
}
|
|
3838
3939
|
return super.time;
|
|
3839
3940
|
}
|
|
3941
|
+
/**
|
|
3942
|
+
* Calls JSAnimation's setter directly, as `super.time =` is a slow
|
|
3943
|
+
* path in V8 and this runs for every animation of a seeked sequence.
|
|
3944
|
+
*/
|
|
3840
3945
|
set time(newTime) {
|
|
3841
|
-
|
|
3946
|
+
(setTime ?? (setTime = Object.getOwnPropertyDescriptor(JSAnimation.prototype, "time").set)).call(this, newTime);
|
|
3842
3947
|
}
|
|
3843
3948
|
/**
|
|
3844
3949
|
* Scroll timelines set time every frame, so run these on the main
|
|
@@ -3884,6 +3989,12 @@
|
|
|
3884
3989
|
let hasChurned = false;
|
|
3885
3990
|
let lastChurn = -Infinity;
|
|
3886
3991
|
let wake;
|
|
3992
|
+
let wakeAt = Infinity;
|
|
3993
|
+
/**
|
|
3994
|
+
* While waiting to build a tween that starts later, how long after
|
|
3995
|
+
* the last build to build it.
|
|
3996
|
+
*/
|
|
3997
|
+
let buildAt;
|
|
3887
3998
|
const has = (key) => {
|
|
3888
3999
|
for (const track of tracks)
|
|
3889
4000
|
if (track.name === key)
|
|
@@ -3952,6 +4063,8 @@
|
|
|
3952
4063
|
*/
|
|
3953
4064
|
const stop = (shouldCommit = true) => {
|
|
3954
4065
|
clearTimeout(wake);
|
|
4066
|
+
wakeAt = Infinity;
|
|
4067
|
+
buildAt = undefined;
|
|
3955
4068
|
shouldCommit && commit();
|
|
3956
4069
|
segments.forEach(({ animation }) => cancel(animation));
|
|
3957
4070
|
segments = [];
|
|
@@ -4181,7 +4294,13 @@
|
|
|
4181
4294
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
4182
4295
|
*/
|
|
4183
4296
|
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
4184
|
-
|
|
4297
|
+
/**
|
|
4298
|
+
* With an easing given, there's nothing to sample, so no need
|
|
4299
|
+
* for the boundaries.
|
|
4300
|
+
*/
|
|
4301
|
+
const bounds = nativeEasing
|
|
4302
|
+
? []
|
|
4303
|
+
: moving.flatMap((track) => track.boundaries(from, to));
|
|
4185
4304
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
4186
4305
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
4187
4306
|
const transform = times.map((t) => compose(t, settled));
|
|
@@ -4204,6 +4323,23 @@
|
|
|
4204
4323
|
easing: easing || "linear",
|
|
4205
4324
|
});
|
|
4206
4325
|
};
|
|
4326
|
+
/**
|
|
4327
|
+
* Check whether it's time to build in this long. A check that's due
|
|
4328
|
+
* sooner is kept, and checks again if it's early, so pausing and
|
|
4329
|
+
* playing don't each replace a timer. One due later, after a seek or
|
|
4330
|
+
* speed change while held, is replaced.
|
|
4331
|
+
*/
|
|
4332
|
+
const wakeIn = (delay) => {
|
|
4333
|
+
const at = time.now() + delay;
|
|
4334
|
+
if (at < wakeAt) {
|
|
4335
|
+
clearTimeout(wake);
|
|
4336
|
+
wakeAt = at;
|
|
4337
|
+
wake = setTimeout(() => {
|
|
4338
|
+
wakeAt = Infinity;
|
|
4339
|
+
group.schedule(false);
|
|
4340
|
+
}, delay);
|
|
4341
|
+
}
|
|
4342
|
+
};
|
|
4207
4343
|
/**
|
|
4208
4344
|
* Replace the WAAPI animations with ones built from now. Returns
|
|
4209
4345
|
* undefined if the animations can't be composed.
|
|
@@ -4279,7 +4415,7 @@
|
|
|
4279
4415
|
*/
|
|
4280
4416
|
if (from - now > buildAhead) {
|
|
4281
4417
|
moving.forEach((track) => track.sync());
|
|
4282
|
-
|
|
4418
|
+
wakeIn((buildAt = from - now - buildAhead));
|
|
4283
4419
|
return true;
|
|
4284
4420
|
}
|
|
4285
4421
|
easing =
|
|
@@ -4334,9 +4470,11 @@
|
|
|
4334
4470
|
/**
|
|
4335
4471
|
* If every animation has been paused, played, seeked or sped up
|
|
4336
4472
|
* together since the WAAPI animation was built, do the same to it.
|
|
4337
|
-
* Returns false if it needs rebuilding instead.
|
|
4473
|
+
* Returns false if it needs rebuilding instead. Seeking to before a
|
|
4474
|
+
* tween starts rebuilds, so a running group seeked every frame still
|
|
4475
|
+
* moves to the main thread.
|
|
4338
4476
|
*/
|
|
4339
|
-
const retime = (now) => {
|
|
4477
|
+
const retime = (now, isSeek) => {
|
|
4340
4478
|
let elapsed;
|
|
4341
4479
|
let rate = 0;
|
|
4342
4480
|
for (const track of tracks) {
|
|
@@ -4369,12 +4507,33 @@
|
|
|
4369
4507
|
}
|
|
4370
4508
|
if (elapsed === undefined)
|
|
4371
4509
|
return true;
|
|
4372
|
-
|
|
4373
|
-
|
|
4510
|
+
/**
|
|
4511
|
+
* Waiting to build a tween that starts later. Until then the
|
|
4512
|
+
* values hold where they start, so only when to build changes.
|
|
4513
|
+
* Held, it has nothing on the compositor, so it can be seeked.
|
|
4514
|
+
*/
|
|
4515
|
+
if (!segments.length) {
|
|
4516
|
+
if (buildAt === undefined || (isSeek && rate))
|
|
4517
|
+
return false;
|
|
4518
|
+
if (rate) {
|
|
4519
|
+
const delay = (buildAt - elapsed) / rate;
|
|
4520
|
+
if (delay < 1)
|
|
4521
|
+
return false;
|
|
4522
|
+
wakeIn(delay);
|
|
4523
|
+
}
|
|
4524
|
+
return true;
|
|
4525
|
+
}
|
|
4526
|
+
/**
|
|
4527
|
+
* Only a tween is built to start later, and it holds its first
|
|
4528
|
+
* keyframe until then, so it can be paused and played before it
|
|
4529
|
+
* starts.
|
|
4530
|
+
*/
|
|
4374
4531
|
for (const { offset, end, isDone } of segments) {
|
|
4375
4532
|
const local = elapsed - offset;
|
|
4376
4533
|
if (end < Infinity &&
|
|
4377
|
-
(isDone
|
|
4534
|
+
(isDone
|
|
4535
|
+
? local < end - 1
|
|
4536
|
+
: (local < 0 && (isSeek || offset <= 0)) || local >= end)) {
|
|
4378
4537
|
return false;
|
|
4379
4538
|
}
|
|
4380
4539
|
}
|
|
@@ -4395,7 +4554,8 @@
|
|
|
4395
4554
|
animation.updatePlaybackRate(rate);
|
|
4396
4555
|
}
|
|
4397
4556
|
else if (rate) {
|
|
4398
|
-
animation.playbackRate
|
|
4557
|
+
animation.playbackRate !== rate &&
|
|
4558
|
+
(animation.playbackRate = rate);
|
|
4399
4559
|
animation.startTime = now - local / rate;
|
|
4400
4560
|
}
|
|
4401
4561
|
else {
|
|
@@ -4469,12 +4629,12 @@
|
|
|
4469
4629
|
if (group.isJS) {
|
|
4470
4630
|
group.isJS = false;
|
|
4471
4631
|
needsBuild = true;
|
|
4472
|
-
tracks.forEach((track) => track.
|
|
4632
|
+
tracks.forEach((track) => track.stopJS());
|
|
4473
4633
|
}
|
|
4474
4634
|
const shouldBuild = needsBuild;
|
|
4475
4635
|
const churned = hasChurned;
|
|
4476
4636
|
needsBuild = hasChurned = false;
|
|
4477
|
-
if (shouldBuild || !retime(now)) {
|
|
4637
|
+
if (shouldBuild || !retime(now, churned)) {
|
|
4478
4638
|
if (churned) {
|
|
4479
4639
|
if (now - lastChurn < churnWindow)
|
|
4480
4640
|
return group.demote();
|
|
@@ -4483,6 +4643,13 @@
|
|
|
4483
4643
|
if (!animate(now))
|
|
4484
4644
|
return group.demote();
|
|
4485
4645
|
}
|
|
4646
|
+
else if (buildAt !== undefined && !churned) {
|
|
4647
|
+
/**
|
|
4648
|
+
* Still waiting to build, so the values still hold where
|
|
4649
|
+
* they start.
|
|
4650
|
+
*/
|
|
4651
|
+
return;
|
|
4652
|
+
}
|
|
4486
4653
|
/**
|
|
4487
4654
|
* Held animations don't move, so set their motion values to where
|
|
4488
4655
|
* they're held, as a JSAnimation would on its next tick. Pausing
|
|
@@ -4750,7 +4917,10 @@
|
|
|
4750
4917
|
class GroupAnimation {
|
|
4751
4918
|
constructor(animations) {
|
|
4752
4919
|
// Bound to accommodate common `return animation.stop` pattern
|
|
4753
|
-
this.stop = () =>
|
|
4920
|
+
this.stop = () => {
|
|
4921
|
+
for (const animation of this.animations)
|
|
4922
|
+
animation.stop();
|
|
4923
|
+
};
|
|
4754
4924
|
this.animations = animations.filter(Boolean);
|
|
4755
4925
|
}
|
|
4756
4926
|
get finished() {
|
|
@@ -4762,11 +4932,6 @@
|
|
|
4762
4932
|
getAll(propName) {
|
|
4763
4933
|
return this.animations[0][propName];
|
|
4764
4934
|
}
|
|
4765
|
-
setAll(propName, newValue) {
|
|
4766
|
-
for (let i = 0; i < this.animations.length; i++) {
|
|
4767
|
-
this.animations[i][propName] = newValue;
|
|
4768
|
-
}
|
|
4769
|
-
}
|
|
4770
4935
|
attachTimeline(timeline) {
|
|
4771
4936
|
const subscriptions = this.animations.map((animation) => animation.attachTimeline(timeline));
|
|
4772
4937
|
return () => {
|
|
@@ -4779,14 +4944,21 @@
|
|
|
4779
4944
|
get time() {
|
|
4780
4945
|
return this.getAll("time");
|
|
4781
4946
|
}
|
|
4947
|
+
/**
|
|
4948
|
+
* Setters and methods name the property directly, rather than through
|
|
4949
|
+
* a shared helper, so each call site stays monomorphic. Sequences
|
|
4950
|
+
* call these on every animation, many times a second.
|
|
4951
|
+
*/
|
|
4782
4952
|
set time(time) {
|
|
4783
|
-
this.
|
|
4953
|
+
for (const animation of this.animations)
|
|
4954
|
+
animation.time = time;
|
|
4784
4955
|
}
|
|
4785
4956
|
get speed() {
|
|
4786
4957
|
return this.getAll("speed");
|
|
4787
4958
|
}
|
|
4788
4959
|
set speed(speed) {
|
|
4789
|
-
this.
|
|
4960
|
+
for (const animation of this.animations)
|
|
4961
|
+
animation.speed = speed;
|
|
4790
4962
|
}
|
|
4791
4963
|
get state() {
|
|
4792
4964
|
return this.getAll("state");
|
|
@@ -4800,20 +4972,21 @@
|
|
|
4800
4972
|
get iterationDuration() {
|
|
4801
4973
|
return getMax(this.animations, "iterationDuration");
|
|
4802
4974
|
}
|
|
4803
|
-
runAll(methodName) {
|
|
4804
|
-
this.animations.forEach((controls) => controls[methodName]());
|
|
4805
|
-
}
|
|
4806
4975
|
play() {
|
|
4807
|
-
this.
|
|
4976
|
+
for (const animation of this.animations)
|
|
4977
|
+
animation.play();
|
|
4808
4978
|
}
|
|
4809
4979
|
pause() {
|
|
4810
|
-
this.
|
|
4980
|
+
for (const animation of this.animations)
|
|
4981
|
+
animation.pause();
|
|
4811
4982
|
}
|
|
4812
4983
|
cancel() {
|
|
4813
|
-
this.
|
|
4984
|
+
for (const animation of this.animations)
|
|
4985
|
+
animation.cancel();
|
|
4814
4986
|
}
|
|
4815
4987
|
complete() {
|
|
4816
|
-
this.
|
|
4988
|
+
for (const animation of this.animations)
|
|
4989
|
+
animation.complete();
|
|
4817
4990
|
}
|
|
4818
4991
|
}
|
|
4819
4992
|
function getMax(animations, propName) {
|
|
@@ -5173,28 +5346,32 @@
|
|
|
5173
5346
|
* @param animation - A function that starts the provided animation
|
|
5174
5347
|
*/
|
|
5175
5348
|
start(startAnimation) {
|
|
5349
|
+
return new Promise((resolve) => this.run(startAnimation, resolve));
|
|
5350
|
+
}
|
|
5351
|
+
/**
|
|
5352
|
+
* As start(), without making a promise, for animations started
|
|
5353
|
+
* internally, which complete through their own controls.
|
|
5354
|
+
*/
|
|
5355
|
+
run(startAnimation, onComplete) {
|
|
5176
5356
|
this.stop();
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
this.
|
|
5190
|
-
|
|
5191
|
-
this.animation = undefined;
|
|
5192
|
-
resolve();
|
|
5193
|
-
});
|
|
5194
|
-
if (!isComplete)
|
|
5195
|
-
this.animation = animation;
|
|
5196
|
-
this.events.animationStart?.notify();
|
|
5357
|
+
this.hasAnimated = true;
|
|
5358
|
+
/**
|
|
5359
|
+
* Guard against animations that complete before startAnimation
|
|
5360
|
+
* has returned.
|
|
5361
|
+
*/
|
|
5362
|
+
let isComplete = false;
|
|
5363
|
+
let animation;
|
|
5364
|
+
// eslint-disable-next-line prefer-const -- read by the callback before assignment when completing synchronously
|
|
5365
|
+
animation = startAnimation(() => {
|
|
5366
|
+
isComplete = true;
|
|
5367
|
+
this.events.animationComplete?.notify();
|
|
5368
|
+
if (this.animation === animation)
|
|
5369
|
+
this.animation = undefined;
|
|
5370
|
+
onComplete?.();
|
|
5197
5371
|
});
|
|
5372
|
+
if (!isComplete)
|
|
5373
|
+
this.animation = animation;
|
|
5374
|
+
this.events.animationStart?.notify();
|
|
5198
5375
|
}
|
|
5199
5376
|
/**
|
|
5200
5377
|
* Stop the currently active animation.
|
|
@@ -5816,7 +5993,7 @@
|
|
|
5816
5993
|
}
|
|
5817
5994
|
addValueToWillChange(visualElement, key);
|
|
5818
5995
|
const shouldReduceMotion = reduceMotion ?? visualElement.shouldReduceMotion;
|
|
5819
|
-
value.
|
|
5996
|
+
value.run(animateMotionValue(key, value, valueTarget, shouldReduceMotion && positionalKeys.has(key)
|
|
5820
5997
|
? { type: false }
|
|
5821
5998
|
: valueTransition, visualElement, isHandoff));
|
|
5822
5999
|
const animation = value.animation;
|
|
@@ -5951,9 +6128,14 @@
|
|
|
5951
6128
|
}
|
|
5952
6129
|
|
|
5953
6130
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
6131
|
+
/**
|
|
6132
|
+
* Passes isAsync to the base constructor rather than setting it as a
|
|
6133
|
+
* class field, which would compile to a constructor that spreads
|
|
6134
|
+
* `arguments` into super(). That spread is slow in the interpreter,
|
|
6135
|
+
* and animate() constructs one resolver per value.
|
|
6136
|
+
*/
|
|
6137
|
+
constructor(unresolvedKeyframes, onComplete, name, motionValue, element) {
|
|
6138
|
+
super(unresolvedKeyframes, onComplete, name, motionValue, element, true);
|
|
5957
6139
|
}
|
|
5958
6140
|
/**
|
|
5959
6141
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -6252,7 +6434,7 @@
|
|
|
6252
6434
|
frame.update(() => value.set(target));
|
|
6253
6435
|
continue;
|
|
6254
6436
|
}
|
|
6255
|
-
value.
|
|
6437
|
+
value.run(animateMotionValue(key, value, target, reduceMotion && positionalKeys.has(key)
|
|
6256
6438
|
? { type: false }
|
|
6257
6439
|
: transition, element));
|
|
6258
6440
|
value.animation &&
|
|
@@ -6282,8 +6464,14 @@
|
|
|
6282
6464
|
* measurement) via `element`.
|
|
6283
6465
|
*/
|
|
6284
6466
|
function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
6285
|
-
|
|
6286
|
-
|
|
6467
|
+
/**
|
|
6468
|
+
* Values made for this call are bound with one effect call, after the
|
|
6469
|
+
* loop, rather than one each.
|
|
6470
|
+
*/
|
|
6471
|
+
let created;
|
|
6472
|
+
let isBound = false;
|
|
6473
|
+
const animations = animateValues((key) => {
|
|
6474
|
+
let value = created?.[key] ?? effect.get(subject, key);
|
|
6287
6475
|
if (!value) {
|
|
6288
6476
|
let initial;
|
|
6289
6477
|
if (!element) {
|
|
@@ -6294,10 +6482,15 @@
|
|
|
6294
6482
|
exports.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
6295
6483
|
}
|
|
6296
6484
|
value = motionValue(initial, { owner: element });
|
|
6297
|
-
|
|
6485
|
+
isBound
|
|
6486
|
+
? effect(subject, { [key]: value })
|
|
6487
|
+
: ((created || (created = {}))[key] = value);
|
|
6298
6488
|
}
|
|
6299
6489
|
return value;
|
|
6300
6490
|
}, keyframes, transition, element);
|
|
6491
|
+
isBound = true;
|
|
6492
|
+
created && effect(subject, created);
|
|
6493
|
+
return animations;
|
|
6301
6494
|
}
|
|
6302
6495
|
function firstKeyframe(target) {
|
|
6303
6496
|
const first = Array.isArray(target) ? target[0] : undefined;
|
|
@@ -7293,7 +7486,7 @@
|
|
|
7293
7486
|
|
|
7294
7487
|
function animateSingleValue(value, keyframes, options) {
|
|
7295
7488
|
const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
|
|
7296
|
-
motionValue$1.
|
|
7489
|
+
motionValue$1.run(animateMotionValue("", motionValue$1, keyframes, options));
|
|
7297
7490
|
return motionValue$1.animation;
|
|
7298
7491
|
}
|
|
7299
7492
|
|
|
@@ -7793,13 +7986,7 @@
|
|
|
7793
7986
|
if (xTranslate || yTranslate || zTranslate) {
|
|
7794
7987
|
transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `;
|
|
7795
7988
|
}
|
|
7796
|
-
|
|
7797
|
-
* Apply scale correction for the tree transform.
|
|
7798
|
-
* This will apply scale to the screen-orientated axes.
|
|
7799
|
-
*/
|
|
7800
|
-
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
7801
|
-
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
7802
|
-
}
|
|
7989
|
+
let angles = "";
|
|
7803
7990
|
if (latestTransform) {
|
|
7804
7991
|
const { transformPerspective } = latestTransform;
|
|
7805
7992
|
if (transformPerspective)
|
|
@@ -7808,20 +7995,48 @@
|
|
|
7808
7995
|
const key = angleTransforms[i];
|
|
7809
7996
|
const value = latestTransform[key];
|
|
7810
7997
|
if (value)
|
|
7811
|
-
|
|
7998
|
+
angles += `${key}(${value}deg) `;
|
|
7812
7999
|
// Additive `rotate()` so user `rotate` isn't clobbered.
|
|
7813
8000
|
if (!i && latestTransform.pathRotation)
|
|
7814
|
-
|
|
8001
|
+
angles += `rotate(${latestTransform.pathRotation}deg) `;
|
|
7815
8002
|
}
|
|
7816
8003
|
}
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
8004
|
+
if (angles) {
|
|
8005
|
+
/**
|
|
8006
|
+
* Apply scale correction for the tree transform.
|
|
8007
|
+
* This will apply scale to the screen-orientated axes.
|
|
8008
|
+
*/
|
|
8009
|
+
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
8010
|
+
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
8011
|
+
}
|
|
8012
|
+
transform += angles;
|
|
8013
|
+
/**
|
|
8014
|
+
* Apply scale to match the size of the element to the size we want it.
|
|
8015
|
+
* This will apply scale to the element-orientated axes.
|
|
8016
|
+
*/
|
|
8017
|
+
const elementScaleX = delta.x.scale * treeScale.x;
|
|
8018
|
+
const elementScaleY = delta.y.scale * treeScale.y;
|
|
8019
|
+
if (elementScaleX !== 1 || elementScaleY !== 1) {
|
|
8020
|
+
transform += `scale(${elementScaleX}, ${elementScaleY})`;
|
|
8021
|
+
}
|
|
8022
|
+
}
|
|
8023
|
+
else if (delta.x.scale !== 1 || delta.y.scale !== 1) {
|
|
8024
|
+
/**
|
|
8025
|
+
* With no rotation or skew between them, the tree scale correction
|
|
8026
|
+
* (1 / treeScale) and the element scale (delta.scale * treeScale)
|
|
8027
|
+
* combine into a single scale. A shorter transform is quicker for
|
|
8028
|
+
* the browser to parse, which matters when it's set every frame.
|
|
8029
|
+
*/
|
|
8030
|
+
transform += `scale(${delta.x.scale}, ${delta.y.scale})`;
|
|
8031
|
+
}
|
|
8032
|
+
else if (!transform && (treeScale.x !== 1 || treeScale.y !== 1)) {
|
|
8033
|
+
/**
|
|
8034
|
+
* Inside a scaled tree the transform must never be "none", even when
|
|
8035
|
+
* this element's own delta is the identity: scale correction for
|
|
8036
|
+
* borderRadius and boxShadow is skipped for "none", and the element
|
|
8037
|
+
* would gain and lose its stacking context as the delta snaps.
|
|
8038
|
+
*/
|
|
8039
|
+
transform = "scale(1, 1)";
|
|
7825
8040
|
}
|
|
7826
8041
|
return transform || "none";
|
|
7827
8042
|
}
|
|
@@ -15345,6 +15560,13 @@
|
|
|
15345
15560
|
info.duration = totalDuration;
|
|
15346
15561
|
info.labels = timeLabels;
|
|
15347
15562
|
}
|
|
15563
|
+
/**
|
|
15564
|
+
* Exclude `type` from defaultTransition since springs have been
|
|
15565
|
+
* converted to duration-based easing functions in resolveValueSequence.
|
|
15566
|
+
* Including `type: "spring"` would cause JSAnimation to error when
|
|
15567
|
+
* the merged keyframes array has more than 2 keyframes.
|
|
15568
|
+
*/
|
|
15569
|
+
const { type: _type, ...remainingDefaultTransition } = defaultTransition;
|
|
15348
15570
|
/**
|
|
15349
15571
|
* For every element and value combination create a new animation.
|
|
15350
15572
|
*/
|
|
@@ -15395,13 +15617,6 @@
|
|
|
15395
15617
|
}
|
|
15396
15618
|
const definition = animationDefinitions.get(element);
|
|
15397
15619
|
definition.keyframes[key] = keyframes;
|
|
15398
|
-
/**
|
|
15399
|
-
* Exclude `type` from defaultTransition since springs have been
|
|
15400
|
-
* converted to duration-based easing functions in resolveValueSequence.
|
|
15401
|
-
* Including `type: "spring"` would cause JSAnimation to error when
|
|
15402
|
-
* the merged keyframes array has more than 2 keyframes.
|
|
15403
|
-
*/
|
|
15404
|
-
const { type: _type, ...remainingDefaultTransition } = defaultTransition;
|
|
15405
15620
|
definition.transition[key] = {
|
|
15406
15621
|
...remainingDefaultTransition,
|
|
15407
15622
|
duration: totalDuration,
|
|
@@ -16105,8 +16320,13 @@
|
|
|
16105
16320
|
}
|
|
16106
16321
|
}
|
|
16107
16322
|
|
|
16323
|
+
/**
|
|
16324
|
+
* A sequence has at least one segment or nested sequence. Labels alone
|
|
16325
|
+
* are never a sequence, as an array of strings isn't a subject either.
|
|
16326
|
+
*/
|
|
16108
16327
|
function isSequence(value) {
|
|
16109
|
-
return Array.isArray(value) &&
|
|
16328
|
+
return (Array.isArray(value) &&
|
|
16329
|
+
value.some((item) => Array.isArray(item) || item?.sequence));
|
|
16110
16330
|
}
|
|
16111
16331
|
/**
|
|
16112
16332
|
* Creates an animation function that is optionally scoped
|
|
@@ -16194,33 +16414,41 @@
|
|
|
16194
16414
|
});
|
|
16195
16415
|
|
|
16196
16416
|
function animateElements(elementOrSelector, keyframes, options, scope) {
|
|
16417
|
+
const animationDefinitions = [];
|
|
16418
|
+
addAnimationDefinitions(animationDefinitions, elementOrSelector, keyframes, options, scope);
|
|
16419
|
+
return startAnimationDefinitions(animationDefinitions);
|
|
16420
|
+
}
|
|
16421
|
+
/**
|
|
16422
|
+
* WAAPI doesn't support interrupting animations.
|
|
16423
|
+
*
|
|
16424
|
+
* Therefore, starting animations requires a three-step process:
|
|
16425
|
+
* 1. Stop existing animations (write styles to DOM)
|
|
16426
|
+
* 2. Resolve keyframes (read styles from DOM)
|
|
16427
|
+
* 3. Create new animations (write styles to DOM)
|
|
16428
|
+
*
|
|
16429
|
+
* The hybrid `animate()` function uses AsyncAnimation to resolve
|
|
16430
|
+
* keyframes before creating new animations, which removes style
|
|
16431
|
+
* thrashing. Here, we have much stricter filesize constraints.
|
|
16432
|
+
* Therefore we do this in a synchronous way that ensures that
|
|
16433
|
+
* at least within `animate()` calls there is no style thrashing.
|
|
16434
|
+
*
|
|
16435
|
+
* In the motion-native-animate-mini-interrupt benchmark this
|
|
16436
|
+
* was 80% faster than a single loop.
|
|
16437
|
+
*
|
|
16438
|
+
* Step 1, here, can run for many `animate()`-style calls (as for each
|
|
16439
|
+
* element of a sequence) before steps 2 and 3 start them all together.
|
|
16440
|
+
* Otherwise each call's read would force a style recalc after the last
|
|
16441
|
+
* call's write.
|
|
16442
|
+
*/
|
|
16443
|
+
function addAnimationDefinitions(animationDefinitions, elementOrSelector, keyframes, options, scope) {
|
|
16197
16444
|
// Gracefully handle null/undefined elements (e.g., from querySelector returning null)
|
|
16198
|
-
if (elementOrSelector == null)
|
|
16199
|
-
return
|
|
16200
|
-
}
|
|
16445
|
+
if (elementOrSelector == null)
|
|
16446
|
+
return;
|
|
16201
16447
|
const elements = resolveElements(elementOrSelector, scope);
|
|
16202
16448
|
const numElements = elements.length;
|
|
16203
16449
|
typeof process !== "undefined" &&
|
|
16204
16450
|
"development" !== "production" &&
|
|
16205
16451
|
exports.invariant(Boolean(numElements), "No valid elements provided.", "no-valid-elements");
|
|
16206
|
-
/**
|
|
16207
|
-
* WAAPI doesn't support interrupting animations.
|
|
16208
|
-
*
|
|
16209
|
-
* Therefore, starting animations requires a three-step process:
|
|
16210
|
-
* 1. Stop existing animations (write styles to DOM)
|
|
16211
|
-
* 2. Resolve keyframes (read styles from DOM)
|
|
16212
|
-
* 3. Create new animations (write styles to DOM)
|
|
16213
|
-
*
|
|
16214
|
-
* The hybrid `animate()` function uses AsyncAnimation to resolve
|
|
16215
|
-
* keyframes before creating new animations, which removes style
|
|
16216
|
-
* thrashing. Here, we have much stricter filesize constraints.
|
|
16217
|
-
* Therefore we do this in a synchronous way that ensures that
|
|
16218
|
-
* at least within `animate()` calls there is no style thrashing.
|
|
16219
|
-
*
|
|
16220
|
-
* In the motion-native-animate-mini-interrupt benchmark this
|
|
16221
|
-
* was 80% faster than a single loop.
|
|
16222
|
-
*/
|
|
16223
|
-
const animationDefinitions = [];
|
|
16224
16452
|
/**
|
|
16225
16453
|
* Step 1: Build options and stop existing animations (write)
|
|
16226
16454
|
*/
|
|
@@ -16264,6 +16492,8 @@
|
|
|
16264
16492
|
});
|
|
16265
16493
|
}
|
|
16266
16494
|
}
|
|
16495
|
+
}
|
|
16496
|
+
function startAnimationDefinitions(animationDefinitions) {
|
|
16267
16497
|
/**
|
|
16268
16498
|
* Step 2: Resolve keyframes (read)
|
|
16269
16499
|
*/
|