motion 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/motion.dev.js +877 -252
- 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
|
|
|
@@ -2192,6 +2234,12 @@
|
|
|
2192
2234
|
return millisecondsToSeconds(this.currentTime);
|
|
2193
2235
|
}
|
|
2194
2236
|
set time(newTime) {
|
|
2237
|
+
/**
|
|
2238
|
+
* Seeking out of "finished" leaves the animation paused, so play()
|
|
2239
|
+
* won't renew finished. Renew it here.
|
|
2240
|
+
*/
|
|
2241
|
+
if (this.state === "finished")
|
|
2242
|
+
this.updateFinished();
|
|
2195
2243
|
newTime = secondsToMilliseconds(newTime);
|
|
2196
2244
|
this.currentTime = newTime;
|
|
2197
2245
|
if (this.startTime === null ||
|
|
@@ -2478,14 +2526,26 @@
|
|
|
2478
2526
|
const getDefaultValueType = (key) => defaultValueTypes[key];
|
|
2479
2527
|
|
|
2480
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;
|
|
2481
2536
|
function getAnimatableNone(key, value) {
|
|
2537
|
+
if (key === lastKey && value === lastValue)
|
|
2538
|
+
return lastNone;
|
|
2482
2539
|
let defaultValueType = getDefaultValueType(key);
|
|
2483
2540
|
if (!customTypes.has(defaultValueType))
|
|
2484
2541
|
defaultValueType = complex;
|
|
2485
2542
|
// If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
|
|
2486
|
-
|
|
2543
|
+
lastNone = defaultValueType.getAnimatableNone
|
|
2487
2544
|
? defaultValueType.getAnimatableNone(value)
|
|
2488
2545
|
: undefined;
|
|
2546
|
+
lastKey = key;
|
|
2547
|
+
lastValue = value;
|
|
2548
|
+
return lastNone;
|
|
2489
2549
|
}
|
|
2490
2550
|
|
|
2491
2551
|
function fillWildcards(keyframes) {
|
|
@@ -3077,8 +3137,13 @@
|
|
|
3077
3137
|
this.manualStartTime = null;
|
|
3078
3138
|
this.finishedTime = null;
|
|
3079
3139
|
this.animation.currentTime = secondsToMilliseconds(newTime);
|
|
3140
|
+
/**
|
|
3141
|
+
* Seeking out of "finished" leaves the animation paused, so play()
|
|
3142
|
+
* won't renew finished. Renew it here.
|
|
3143
|
+
*/
|
|
3080
3144
|
if (wasFinished) {
|
|
3081
3145
|
this.animation.pause();
|
|
3146
|
+
this.updateFinished();
|
|
3082
3147
|
}
|
|
3083
3148
|
}
|
|
3084
3149
|
/**
|
|
@@ -3506,10 +3571,40 @@
|
|
|
3506
3571
|
* rebuilding the WAAPI animation every frame.
|
|
3507
3572
|
*/
|
|
3508
3573
|
const churnWindow = 100;
|
|
3574
|
+
/**
|
|
3575
|
+
* A WAAPI animation that starts moving later than this, as most segments
|
|
3576
|
+
* of a long sequence do, is built this long before it starts, rather than
|
|
3577
|
+
* all at once at the start.
|
|
3578
|
+
*/
|
|
3579
|
+
const buildAhead = 100;
|
|
3509
3580
|
/**
|
|
3510
3581
|
* Named easings that are the same cubic-bezier in JS and CSS.
|
|
3511
3582
|
*/
|
|
3512
|
-
const
|
|
3583
|
+
const nativeEasings = new Set(["linear", "easeIn", "easeOut", "easeInOut"]);
|
|
3584
|
+
const isNativeEasing = (ease) => nativeEasings.has(ease);
|
|
3585
|
+
/**
|
|
3586
|
+
* The last trace of each easing WAAPI can't run into linear(), with its
|
|
3587
|
+
* number of samples, so the elements of a sequence that share an easing
|
|
3588
|
+
* and duration trace it once.
|
|
3589
|
+
*/
|
|
3590
|
+
const traced = new WeakMap();
|
|
3591
|
+
const trace = (ease, samples) => {
|
|
3592
|
+
let last = traced.get(ease);
|
|
3593
|
+
if (last?.[0] !== samples) {
|
|
3594
|
+
last = [
|
|
3595
|
+
samples,
|
|
3596
|
+
"linear(" +
|
|
3597
|
+
defaultOffset$1(Array(samples + 1)).map((p) => round(ease(p)) + " " + round(p * 100) + "%") +
|
|
3598
|
+
")",
|
|
3599
|
+
];
|
|
3600
|
+
traced.set(ease, last);
|
|
3601
|
+
}
|
|
3602
|
+
return last[1];
|
|
3603
|
+
};
|
|
3604
|
+
/**
|
|
3605
|
+
* How many samples trace an easing between two timestamps.
|
|
3606
|
+
*/
|
|
3607
|
+
const countSamples = (from, to) => Math.min(maxSamples, Math.max(2, Math.ceil((to - from) / sampleDelta)));
|
|
3513
3608
|
/**
|
|
3514
3609
|
* Whether two eased progresses match. False if either is NaN.
|
|
3515
3610
|
*/
|
|
@@ -3570,6 +3665,54 @@
|
|
|
3570
3665
|
*/
|
|
3571
3666
|
!needsMixer(options));
|
|
3572
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;
|
|
3573
3716
|
class TransformAnimation extends JSAnimation {
|
|
3574
3717
|
constructor(options) {
|
|
3575
3718
|
const element = getOwner(options).current;
|
|
@@ -3581,35 +3724,16 @@
|
|
|
3581
3724
|
const canAccelerate = canAccelerateTransform(options);
|
|
3582
3725
|
/**
|
|
3583
3726
|
* The driver ticks on the main thread only once the group has
|
|
3584
|
-
* moved there
|
|
3585
|
-
* update its WAAPI animation.
|
|
3727
|
+
* moved there, so its frame loop driver is made then.
|
|
3586
3728
|
*/
|
|
3587
|
-
options.driver = (update) =>
|
|
3588
|
-
const js = driver(update);
|
|
3589
|
-
return {
|
|
3590
|
-
js,
|
|
3591
|
-
now: js.now,
|
|
3592
|
-
start: (keepAlive = true) => {
|
|
3593
|
-
const group = getGroup(element);
|
|
3594
|
-
const isJS = !group || group.isJS;
|
|
3595
|
-
/**
|
|
3596
|
-
* keepAlive is false when seeking. Seeking the WAAPI
|
|
3597
|
-
* animation is free, but if a seek needs a rebuild and
|
|
3598
|
-
* keeps happening, the group moves to the main thread.
|
|
3599
|
-
*/
|
|
3600
|
-
isJS
|
|
3601
|
-
? js.start(keepAlive)
|
|
3602
|
-
: group.schedule(false, !keepAlive);
|
|
3603
|
-
},
|
|
3604
|
-
stop: () => {
|
|
3605
|
-
js.stop();
|
|
3606
|
-
const group = getGroup(element);
|
|
3607
|
-
group && !group.isFinishing && group.release(animation);
|
|
3608
|
-
},
|
|
3609
|
-
};
|
|
3610
|
-
};
|
|
3729
|
+
options.driver = (update) => new TransformDriver(element, update, driver, animation);
|
|
3611
3730
|
super(options);
|
|
3612
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);
|
|
3613
3737
|
this.canAccelerate = canAccelerate;
|
|
3614
3738
|
/**
|
|
3615
3739
|
* stop is bound in JSAnimation, so wrap it rather than override.
|
|
@@ -3623,12 +3747,29 @@
|
|
|
3623
3747
|
stop();
|
|
3624
3748
|
};
|
|
3625
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
|
+
}
|
|
3626
3764
|
get group() {
|
|
3627
3765
|
return getGroup(getOwner(this.options).current);
|
|
3628
3766
|
}
|
|
3629
3767
|
get js() {
|
|
3630
3768
|
return this.driver?.js;
|
|
3631
3769
|
}
|
|
3770
|
+
stopJS() {
|
|
3771
|
+
this.driver?.stopJS();
|
|
3772
|
+
}
|
|
3632
3773
|
get name() {
|
|
3633
3774
|
return this.options.name;
|
|
3634
3775
|
}
|
|
@@ -3668,22 +3809,48 @@
|
|
|
3668
3809
|
return this.isAccelerated() ? this.sampleAt(time.now()) : undefined;
|
|
3669
3810
|
}
|
|
3670
3811
|
/**
|
|
3671
|
-
* If this
|
|
3672
|
-
*
|
|
3812
|
+
* If this moves between two keyframes only, holding still either side
|
|
3813
|
+
* of them, as each value of a sequence segment does, when it starts
|
|
3814
|
+
* and stops moving, and its easing: as a string if WAAPI runs it
|
|
3815
|
+
* exactly, otherwise its function, to trace.
|
|
3673
3816
|
*/
|
|
3674
3817
|
tween() {
|
|
3675
|
-
const { keyframes: keyframes$1, type,
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3818
|
+
const { keyframes: keyframes$1, type, repeat, delay = 0 } = this.options;
|
|
3819
|
+
let span = -1;
|
|
3820
|
+
if (repeat || type !== keyframes || this.holdTime !== null) {
|
|
3821
|
+
return;
|
|
3822
|
+
}
|
|
3823
|
+
for (let i = 1; i < keyframes$1.length; i++) {
|
|
3824
|
+
if (keyframes$1[i] !== keyframes$1[i - 1]) {
|
|
3825
|
+
if (span >= 0)
|
|
3826
|
+
return;
|
|
3827
|
+
span = i - 1;
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
let { ease } = this.options;
|
|
3831
|
+
if (isEasingArray(ease))
|
|
3832
|
+
ease = ease[span];
|
|
3833
|
+
const offsets = this.offsets();
|
|
3834
|
+
const at = (i) => this.startTime +
|
|
3835
|
+
(delay + offsets[i] * this.totalDuration) / this.speed;
|
|
3836
|
+
if (span >= 0) {
|
|
3837
|
+
const easing = isBezierDefinition(ease)
|
|
3838
|
+
? cubicBezierAsString(ease)
|
|
3839
|
+
: isNativeEasing(ease)
|
|
3840
|
+
? supportedWaapiEasing[ease]
|
|
3841
|
+
: easingDefinitionToFunction(ease);
|
|
3842
|
+
/**
|
|
3843
|
+
* An easing that doesn't run from 0 to 1 doesn't move between
|
|
3844
|
+
* the keyframes, so is traced from the values it gives instead.
|
|
3845
|
+
*/
|
|
3846
|
+
return [
|
|
3847
|
+
at(span),
|
|
3848
|
+
at(span + 1),
|
|
3849
|
+
typeof easing === "string" ||
|
|
3850
|
+
(isNear$1(easing(0), 0) && isNear$1(easing(1), 1))
|
|
3851
|
+
? easing
|
|
3852
|
+
: undefined,
|
|
3853
|
+
];
|
|
3687
3854
|
}
|
|
3688
3855
|
}
|
|
3689
3856
|
/**
|
|
@@ -3692,9 +3859,9 @@
|
|
|
3692
3859
|
*/
|
|
3693
3860
|
boundaries(from, to) {
|
|
3694
3861
|
const { startTime, speed, resolvedDuration, options } = this;
|
|
3695
|
-
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType,
|
|
3862
|
+
const { delay = 0, repeat = 0, repeatDelay = 0, repeatType, type, } = options;
|
|
3696
3863
|
const offsets = (type || keyframes) === keyframes
|
|
3697
|
-
?
|
|
3864
|
+
? this.offsets()
|
|
3698
3865
|
: [0, 1];
|
|
3699
3866
|
const start = startTime + delay / speed;
|
|
3700
3867
|
const result = [];
|
|
@@ -3727,7 +3894,14 @@
|
|
|
3727
3894
|
*/
|
|
3728
3895
|
sync() {
|
|
3729
3896
|
const now = time.now();
|
|
3730
|
-
|
|
3897
|
+
const value = this.sampleAt(now, true);
|
|
3898
|
+
/**
|
|
3899
|
+
* A held value doesn't move, so there's no need to sample it
|
|
3900
|
+
* twice.
|
|
3901
|
+
*/
|
|
3902
|
+
this.options.motionValue.setWithVelocity(this.holdTime === null
|
|
3903
|
+
? this.sampleAt(now - sampleDelta, true)
|
|
3904
|
+
: value, value, sampleDelta);
|
|
3731
3905
|
}
|
|
3732
3906
|
play() {
|
|
3733
3907
|
/**
|
|
@@ -3741,10 +3915,7 @@
|
|
|
3741
3915
|
}
|
|
3742
3916
|
pause() {
|
|
3743
3917
|
super.pause();
|
|
3744
|
-
|
|
3745
|
-
this.sync();
|
|
3746
|
-
this.group.schedule(false);
|
|
3747
|
-
}
|
|
3918
|
+
this.isAccelerated() && this.group.schedule(false);
|
|
3748
3919
|
}
|
|
3749
3920
|
/**
|
|
3750
3921
|
* JSAnimation finishes on its next tick, which only happens once the
|
|
@@ -3768,13 +3939,11 @@
|
|
|
3768
3939
|
return super.time;
|
|
3769
3940
|
}
|
|
3770
3941
|
/**
|
|
3771
|
-
*
|
|
3772
|
-
*
|
|
3773
|
-
* when this next stops.
|
|
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.
|
|
3774
3944
|
*/
|
|
3775
3945
|
set time(newTime) {
|
|
3776
|
-
|
|
3777
|
-
this.isAccelerated() && this.sync();
|
|
3946
|
+
(setTime ?? (setTime = Object.getOwnPropertyDescriptor(JSAnimation.prototype, "time").set)).call(this, newTime);
|
|
3778
3947
|
}
|
|
3779
3948
|
/**
|
|
3780
3949
|
* Scroll timelines set time every frame, so run these on the main
|
|
@@ -3786,6 +3955,20 @@
|
|
|
3786
3955
|
return super.attachTimeline(timeline);
|
|
3787
3956
|
}
|
|
3788
3957
|
}
|
|
3958
|
+
/**
|
|
3959
|
+
* Groups that build straight after the current task build in one
|
|
3960
|
+
* microtask, rather than one each.
|
|
3961
|
+
*/
|
|
3962
|
+
let builds;
|
|
3963
|
+
const buildSoon = (build) => {
|
|
3964
|
+
builds ||
|
|
3965
|
+
queueMicrotask(() => {
|
|
3966
|
+
const queue = builds;
|
|
3967
|
+
builds = undefined;
|
|
3968
|
+
queue.forEach((build) => build());
|
|
3969
|
+
});
|
|
3970
|
+
(builds || (builds = [])).push(build);
|
|
3971
|
+
};
|
|
3789
3972
|
function createGroup(owner) {
|
|
3790
3973
|
const element = owner.current;
|
|
3791
3974
|
const tracks = new Set();
|
|
@@ -3805,6 +3988,13 @@
|
|
|
3805
3988
|
let isEnded = false;
|
|
3806
3989
|
let hasChurned = false;
|
|
3807
3990
|
let lastChurn = -Infinity;
|
|
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;
|
|
3808
3998
|
const has = (key) => {
|
|
3809
3999
|
for (const track of tracks)
|
|
3810
4000
|
if (track.name === key)
|
|
@@ -3872,6 +4062,9 @@
|
|
|
3872
4062
|
* transform. The renderer writes its own version on its next render.
|
|
3873
4063
|
*/
|
|
3874
4064
|
const stop = (shouldCommit = true) => {
|
|
4065
|
+
clearTimeout(wake);
|
|
4066
|
+
wakeAt = Infinity;
|
|
4067
|
+
buildAt = undefined;
|
|
3875
4068
|
shouldCommit && commit();
|
|
3876
4069
|
segments.forEach(({ animation }) => cancel(animation));
|
|
3877
4070
|
segments = [];
|
|
@@ -3925,12 +4118,31 @@
|
|
|
3925
4118
|
* two timestamps, the easing that describes it.
|
|
3926
4119
|
*/
|
|
3927
4120
|
const getEasing = (moving, from, to, bounds) => {
|
|
3928
|
-
const samples =
|
|
4121
|
+
const samples = countSamples(from, to);
|
|
3929
4122
|
/**
|
|
3930
4123
|
* Too many keyframes or repeats to follow with this many samples.
|
|
3931
4124
|
*/
|
|
3932
4125
|
if (bounds.length * 4 > samples)
|
|
3933
4126
|
return;
|
|
4127
|
+
/**
|
|
4128
|
+
* First check half way, where values with different easings
|
|
4129
|
+
* usually differ, before sampling every value many times.
|
|
4130
|
+
*/
|
|
4131
|
+
let quick;
|
|
4132
|
+
for (const track of moving) {
|
|
4133
|
+
const first = track.numberAt(from);
|
|
4134
|
+
const p = (track.numberAt((from + to) / 2) - first) /
|
|
4135
|
+
(track.numberAt(to) - first);
|
|
4136
|
+
/**
|
|
4137
|
+
* NaN if it doesn't move.
|
|
4138
|
+
*/
|
|
4139
|
+
if (p !== p)
|
|
4140
|
+
continue;
|
|
4141
|
+
if (quick === undefined)
|
|
4142
|
+
quick = p;
|
|
4143
|
+
else if (!isNear$1(p, quick))
|
|
4144
|
+
return;
|
|
4145
|
+
}
|
|
3934
4146
|
const at = spread(from, to, samples).concat(bounds).sort(byTime);
|
|
3935
4147
|
const position = (t) => progress(from, to, t);
|
|
3936
4148
|
let shared;
|
|
@@ -3987,11 +4199,30 @@
|
|
|
3987
4199
|
*/
|
|
3988
4200
|
const sample = (moving, from, to, bounds) => {
|
|
3989
4201
|
const times = [from];
|
|
4202
|
+
/**
|
|
4203
|
+
* A linear tween is straight between its keyframes, so only the
|
|
4204
|
+
* other values can curve, and a tween only while it moves.
|
|
4205
|
+
*/
|
|
4206
|
+
const curved = [];
|
|
4207
|
+
let curveFrom = to;
|
|
4208
|
+
let curveTo = from;
|
|
4209
|
+
for (const track of moving) {
|
|
4210
|
+
const tween = track.tween();
|
|
4211
|
+
if (tween?.[2] !== "linear") {
|
|
4212
|
+
const [trackEnd, cycle] = track.timing();
|
|
4213
|
+
const [a, b] = tween || [from, cycle ? to : trackEnd];
|
|
4214
|
+
curveFrom = Math.min(curveFrom, a);
|
|
4215
|
+
curveTo = Math.max(curveTo, b);
|
|
4216
|
+
curved.push(track);
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
curveFrom = Math.max(from, curveFrom);
|
|
4220
|
+
curveTo = Math.min(to, curveTo);
|
|
3990
4221
|
/**
|
|
3991
4222
|
* Values that aren't numbers, like calc(), are left to the
|
|
3992
4223
|
* browser to interpolate.
|
|
3993
4224
|
*/
|
|
3994
|
-
const isStraight = (a, b) =>
|
|
4225
|
+
const isStraight = (a, b) => curved.every((track) => !(Math.abs(track.numberAt((a + b) / 2) -
|
|
3995
4226
|
(track.numberAt(a) + track.numberAt(b)) / 2) >
|
|
3996
4227
|
(track.name.startsWith("scale")
|
|
3997
4228
|
? scaleTolerance
|
|
@@ -4016,10 +4247,13 @@
|
|
|
4016
4247
|
}
|
|
4017
4248
|
};
|
|
4018
4249
|
/**
|
|
4019
|
-
* Split at least every 100ms, and at every
|
|
4020
|
-
* either side of where a value can jump.
|
|
4250
|
+
* Split at least every 100ms where a value can curve, and at every
|
|
4251
|
+
* keyframe and repeat, either side of where a value can jump.
|
|
4021
4252
|
*/
|
|
4022
|
-
const ends =
|
|
4253
|
+
const ends = curveTo > curveFrom
|
|
4254
|
+
? spread(curveFrom, curveTo, Math.ceil((curveTo - curveFrom) / 100))
|
|
4255
|
+
: [];
|
|
4256
|
+
ends.push(to);
|
|
4023
4257
|
for (const t of bounds)
|
|
4024
4258
|
ends.push(t, Math.min(t + 0.01, to));
|
|
4025
4259
|
let start = from;
|
|
@@ -4039,12 +4273,20 @@
|
|
|
4039
4273
|
for (const track of moving) {
|
|
4040
4274
|
const tween = track.tween();
|
|
4041
4275
|
if (!tween ||
|
|
4042
|
-
shared
|
|
4043
|
-
|
|
4044
|
-
|
|
4276
|
+
(shared &&
|
|
4277
|
+
(Math.abs(tween[0] - shared[0]) > 1 ||
|
|
4278
|
+
Math.abs(tween[1] - shared[1]) > 1))) {
|
|
4045
4279
|
return;
|
|
4046
4280
|
}
|
|
4047
|
-
|
|
4281
|
+
/**
|
|
4282
|
+
* Easings that differ, like the springs a sequence makes for
|
|
4283
|
+
* each value, can still be the same curve.
|
|
4284
|
+
*/
|
|
4285
|
+
shared = [
|
|
4286
|
+
tween[0],
|
|
4287
|
+
tween[1],
|
|
4288
|
+
!shared || tween[2] === shared[2] ? tween[2] : undefined,
|
|
4289
|
+
];
|
|
4048
4290
|
}
|
|
4049
4291
|
return shared;
|
|
4050
4292
|
};
|
|
@@ -4052,7 +4294,13 @@
|
|
|
4052
4294
|
* A WAAPI animation of the composed transform between two timestamps.
|
|
4053
4295
|
*/
|
|
4054
4296
|
const run = (moving, from, to, nativeEasing, options = { fill: "both" }, settled) => {
|
|
4055
|
-
|
|
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));
|
|
4056
4304
|
const easing = nativeEasing || getEasing(moving, from, to, bounds);
|
|
4057
4305
|
const times = easing ? [from, to] : sample(moving, from, to, bounds);
|
|
4058
4306
|
const transform = times.map((t) => compose(t, settled));
|
|
@@ -4075,6 +4323,23 @@
|
|
|
4075
4323
|
easing: easing || "linear",
|
|
4076
4324
|
});
|
|
4077
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
|
+
};
|
|
4078
4343
|
/**
|
|
4079
4344
|
* Replace the WAAPI animations with ones built from now. Returns
|
|
4080
4345
|
* undefined if the animations can't be composed.
|
|
@@ -4099,14 +4364,8 @@
|
|
|
4099
4364
|
const [trackEnd, trackCycle] = track.timing();
|
|
4100
4365
|
const isHeld = trackEnd === Infinity;
|
|
4101
4366
|
built.set(track, [track.at(now), track.speed, isHeld]);
|
|
4102
|
-
|
|
4103
|
-
* Held animations don't move, so keep their motion values up
|
|
4104
|
-
* to date, as a JSAnimation would on a seek.
|
|
4105
|
-
*/
|
|
4106
|
-
if (isHeld) {
|
|
4107
|
-
track.sync();
|
|
4367
|
+
if (isHeld)
|
|
4108
4368
|
continue;
|
|
4109
|
-
}
|
|
4110
4369
|
if (track.speed < 0)
|
|
4111
4370
|
return;
|
|
4112
4371
|
if (trackCycle) {
|
|
@@ -4146,12 +4405,35 @@
|
|
|
4146
4405
|
*/
|
|
4147
4406
|
const tween = !cycle && getTween(moving);
|
|
4148
4407
|
try {
|
|
4149
|
-
if (
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4408
|
+
if (end > now) {
|
|
4409
|
+
let easing;
|
|
4410
|
+
if (tween && tween[1] > now) {
|
|
4411
|
+
const [from, to, ease] = tween;
|
|
4412
|
+
/**
|
|
4413
|
+
* Until it's built, the motion values hold where it
|
|
4414
|
+
* starts, for the renderer to write.
|
|
4415
|
+
*/
|
|
4416
|
+
if (from - now > buildAhead) {
|
|
4417
|
+
moving.forEach((track) => track.sync());
|
|
4418
|
+
wakeIn((buildAt = from - now - buildAhead));
|
|
4419
|
+
return true;
|
|
4420
|
+
}
|
|
4421
|
+
easing =
|
|
4422
|
+
typeof ease === "string"
|
|
4423
|
+
? ease
|
|
4424
|
+
: ease
|
|
4425
|
+
? trace(ease, countSamples(from, to))
|
|
4426
|
+
: getEasing(moving, from, to, []);
|
|
4427
|
+
/**
|
|
4428
|
+
* It holds its last keyframe until the animations end.
|
|
4429
|
+
*/
|
|
4430
|
+
easing &&
|
|
4431
|
+
add(run(moving, from, to, easing, {
|
|
4432
|
+
fill: "both",
|
|
4433
|
+
endDelay: end - to,
|
|
4434
|
+
}), from - now, end - from);
|
|
4435
|
+
}
|
|
4436
|
+
easing || add(run(moving, now, end), 0, end - now);
|
|
4155
4437
|
/**
|
|
4156
4438
|
* Animations that end sooner finish on the events of
|
|
4157
4439
|
* empty animations that end with them.
|
|
@@ -4188,9 +4470,11 @@
|
|
|
4188
4470
|
/**
|
|
4189
4471
|
* If every animation has been paused, played, seeked or sped up
|
|
4190
4472
|
* together since the WAAPI animation was built, do the same to it.
|
|
4191
|
-
* 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.
|
|
4192
4476
|
*/
|
|
4193
|
-
const retime = (now) => {
|
|
4477
|
+
const retime = (now, isSeek) => {
|
|
4194
4478
|
let elapsed;
|
|
4195
4479
|
let rate = 0;
|
|
4196
4480
|
for (const track of tracks) {
|
|
@@ -4200,9 +4484,14 @@
|
|
|
4200
4484
|
const [builtTime, builtSpeed, wasHeld] = state;
|
|
4201
4485
|
const trackTime = track.at(now);
|
|
4202
4486
|
const isHeld = track.timing()[0] === Infinity;
|
|
4487
|
+
/**
|
|
4488
|
+
* With nothing on the compositor, a held animation is set
|
|
4489
|
+
* where it's held, so it can be seeked as often as needed.
|
|
4490
|
+
*/
|
|
4203
4491
|
if (wasHeld) {
|
|
4204
|
-
if (isHeld && trackTime === builtTime)
|
|
4492
|
+
if (isHeld && (trackTime === builtTime || !segments.length)) {
|
|
4205
4493
|
continue;
|
|
4494
|
+
}
|
|
4206
4495
|
return false;
|
|
4207
4496
|
}
|
|
4208
4497
|
const trackElapsed = (trackTime - builtTime) / builtSpeed;
|
|
@@ -4218,12 +4507,33 @@
|
|
|
4218
4507
|
}
|
|
4219
4508
|
if (elapsed === undefined)
|
|
4220
4509
|
return true;
|
|
4221
|
-
|
|
4222
|
-
|
|
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
|
+
*/
|
|
4223
4531
|
for (const { offset, end, isDone } of segments) {
|
|
4224
4532
|
const local = elapsed - offset;
|
|
4225
4533
|
if (end < Infinity &&
|
|
4226
|
-
(isDone
|
|
4534
|
+
(isDone
|
|
4535
|
+
? local < end - 1
|
|
4536
|
+
: (local < 0 && (isSeek || offset <= 0)) || local >= end)) {
|
|
4227
4537
|
return false;
|
|
4228
4538
|
}
|
|
4229
4539
|
}
|
|
@@ -4244,7 +4554,8 @@
|
|
|
4244
4554
|
animation.updatePlaybackRate(rate);
|
|
4245
4555
|
}
|
|
4246
4556
|
else if (rate) {
|
|
4247
|
-
animation.playbackRate
|
|
4557
|
+
animation.playbackRate !== rate &&
|
|
4558
|
+
(animation.playbackRate = rate);
|
|
4248
4559
|
animation.startTime = now - local / rate;
|
|
4249
4560
|
}
|
|
4250
4561
|
else {
|
|
@@ -4318,12 +4629,12 @@
|
|
|
4318
4629
|
if (group.isJS) {
|
|
4319
4630
|
group.isJS = false;
|
|
4320
4631
|
needsBuild = true;
|
|
4321
|
-
tracks.forEach((track) => track.
|
|
4632
|
+
tracks.forEach((track) => track.stopJS());
|
|
4322
4633
|
}
|
|
4323
4634
|
const shouldBuild = needsBuild;
|
|
4324
4635
|
const churned = hasChurned;
|
|
4325
4636
|
needsBuild = hasChurned = false;
|
|
4326
|
-
if (shouldBuild || !retime(now)) {
|
|
4637
|
+
if (shouldBuild || !retime(now, churned)) {
|
|
4327
4638
|
if (churned) {
|
|
4328
4639
|
if (now - lastChurn < churnWindow)
|
|
4329
4640
|
return group.demote();
|
|
@@ -4332,6 +4643,19 @@
|
|
|
4332
4643
|
if (!animate(now))
|
|
4333
4644
|
return group.demote();
|
|
4334
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
|
+
}
|
|
4653
|
+
/**
|
|
4654
|
+
* Held animations don't move, so set their motion values to where
|
|
4655
|
+
* they're held, as a JSAnimation would on its next tick. Pausing
|
|
4656
|
+
* and seeking schedule this, so it's once however many there are.
|
|
4657
|
+
*/
|
|
4658
|
+
tracks.forEach((track) => track.timing()[0] === Infinity && track.sync());
|
|
4335
4659
|
};
|
|
4336
4660
|
const group = {
|
|
4337
4661
|
tracks,
|
|
@@ -4351,7 +4675,7 @@
|
|
|
4351
4675
|
isScheduled = true;
|
|
4352
4676
|
frameData.isProcessing
|
|
4353
4677
|
? frame.render(build, false, true)
|
|
4354
|
-
:
|
|
4678
|
+
: buildSoon(build);
|
|
4355
4679
|
}
|
|
4356
4680
|
},
|
|
4357
4681
|
/**
|
|
@@ -4593,7 +4917,10 @@
|
|
|
4593
4917
|
class GroupAnimation {
|
|
4594
4918
|
constructor(animations) {
|
|
4595
4919
|
// Bound to accommodate common `return animation.stop` pattern
|
|
4596
|
-
this.stop = () =>
|
|
4920
|
+
this.stop = () => {
|
|
4921
|
+
for (const animation of this.animations)
|
|
4922
|
+
animation.stop();
|
|
4923
|
+
};
|
|
4597
4924
|
this.animations = animations.filter(Boolean);
|
|
4598
4925
|
}
|
|
4599
4926
|
get finished() {
|
|
@@ -4605,11 +4932,6 @@
|
|
|
4605
4932
|
getAll(propName) {
|
|
4606
4933
|
return this.animations[0][propName];
|
|
4607
4934
|
}
|
|
4608
|
-
setAll(propName, newValue) {
|
|
4609
|
-
for (let i = 0; i < this.animations.length; i++) {
|
|
4610
|
-
this.animations[i][propName] = newValue;
|
|
4611
|
-
}
|
|
4612
|
-
}
|
|
4613
4935
|
attachTimeline(timeline) {
|
|
4614
4936
|
const subscriptions = this.animations.map((animation) => animation.attachTimeline(timeline));
|
|
4615
4937
|
return () => {
|
|
@@ -4622,14 +4944,21 @@
|
|
|
4622
4944
|
get time() {
|
|
4623
4945
|
return this.getAll("time");
|
|
4624
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
|
+
*/
|
|
4625
4952
|
set time(time) {
|
|
4626
|
-
this.
|
|
4953
|
+
for (const animation of this.animations)
|
|
4954
|
+
animation.time = time;
|
|
4627
4955
|
}
|
|
4628
4956
|
get speed() {
|
|
4629
4957
|
return this.getAll("speed");
|
|
4630
4958
|
}
|
|
4631
4959
|
set speed(speed) {
|
|
4632
|
-
this.
|
|
4960
|
+
for (const animation of this.animations)
|
|
4961
|
+
animation.speed = speed;
|
|
4633
4962
|
}
|
|
4634
4963
|
get state() {
|
|
4635
4964
|
return this.getAll("state");
|
|
@@ -4643,20 +4972,21 @@
|
|
|
4643
4972
|
get iterationDuration() {
|
|
4644
4973
|
return getMax(this.animations, "iterationDuration");
|
|
4645
4974
|
}
|
|
4646
|
-
runAll(methodName) {
|
|
4647
|
-
this.animations.forEach((controls) => controls[methodName]());
|
|
4648
|
-
}
|
|
4649
4975
|
play() {
|
|
4650
|
-
this.
|
|
4976
|
+
for (const animation of this.animations)
|
|
4977
|
+
animation.play();
|
|
4651
4978
|
}
|
|
4652
4979
|
pause() {
|
|
4653
|
-
this.
|
|
4980
|
+
for (const animation of this.animations)
|
|
4981
|
+
animation.pause();
|
|
4654
4982
|
}
|
|
4655
4983
|
cancel() {
|
|
4656
|
-
this.
|
|
4984
|
+
for (const animation of this.animations)
|
|
4985
|
+
animation.cancel();
|
|
4657
4986
|
}
|
|
4658
4987
|
complete() {
|
|
4659
|
-
this.
|
|
4988
|
+
for (const animation of this.animations)
|
|
4989
|
+
animation.complete();
|
|
4660
4990
|
}
|
|
4661
4991
|
}
|
|
4662
4992
|
function getMax(animations, propName) {
|
|
@@ -5016,28 +5346,32 @@
|
|
|
5016
5346
|
* @param animation - A function that starts the provided animation
|
|
5017
5347
|
*/
|
|
5018
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) {
|
|
5019
5356
|
this.stop();
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
this.
|
|
5033
|
-
|
|
5034
|
-
this.animation = undefined;
|
|
5035
|
-
resolve();
|
|
5036
|
-
});
|
|
5037
|
-
if (!isComplete)
|
|
5038
|
-
this.animation = animation;
|
|
5039
|
-
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?.();
|
|
5040
5371
|
});
|
|
5372
|
+
if (!isComplete)
|
|
5373
|
+
this.animation = animation;
|
|
5374
|
+
this.events.animationStart?.notify();
|
|
5041
5375
|
}
|
|
5042
5376
|
/**
|
|
5043
5377
|
* Stop the currently active animation.
|
|
@@ -5659,7 +5993,7 @@
|
|
|
5659
5993
|
}
|
|
5660
5994
|
addValueToWillChange(visualElement, key);
|
|
5661
5995
|
const shouldReduceMotion = reduceMotion ?? visualElement.shouldReduceMotion;
|
|
5662
|
-
value.
|
|
5996
|
+
value.run(animateMotionValue(key, value, valueTarget, shouldReduceMotion && positionalKeys.has(key)
|
|
5663
5997
|
? { type: false }
|
|
5664
5998
|
: valueTransition, visualElement, isHandoff));
|
|
5665
5999
|
const animation = value.animation;
|
|
@@ -5794,9 +6128,14 @@
|
|
|
5794
6128
|
}
|
|
5795
6129
|
|
|
5796
6130
|
class DOMKeyframesResolver extends KeyframeResolver {
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
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);
|
|
5800
6139
|
}
|
|
5801
6140
|
/**
|
|
5802
6141
|
* Keyframes that don't need reading from the DOM, or measuring,
|
|
@@ -6095,7 +6434,7 @@
|
|
|
6095
6434
|
frame.update(() => value.set(target));
|
|
6096
6435
|
continue;
|
|
6097
6436
|
}
|
|
6098
|
-
value.
|
|
6437
|
+
value.run(animateMotionValue(key, value, target, reduceMotion && positionalKeys.has(key)
|
|
6099
6438
|
? { type: false }
|
|
6100
6439
|
: transition, element));
|
|
6101
6440
|
value.animation &&
|
|
@@ -6125,8 +6464,14 @@
|
|
|
6125
6464
|
* measurement) via `element`.
|
|
6126
6465
|
*/
|
|
6127
6466
|
function animateEffectSubject(effect, subject, keyframes, transition, element) {
|
|
6128
|
-
|
|
6129
|
-
|
|
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);
|
|
6130
6475
|
if (!value) {
|
|
6131
6476
|
let initial;
|
|
6132
6477
|
if (!element) {
|
|
@@ -6137,10 +6482,15 @@
|
|
|
6137
6482
|
exports.invariant(initial !== undefined, `"${key}" can't be read from the animated subject. Provide [from, to] keyframes.`, "effect-unreadable-value");
|
|
6138
6483
|
}
|
|
6139
6484
|
value = motionValue(initial, { owner: element });
|
|
6140
|
-
|
|
6485
|
+
isBound
|
|
6486
|
+
? effect(subject, { [key]: value })
|
|
6487
|
+
: ((created || (created = {}))[key] = value);
|
|
6141
6488
|
}
|
|
6142
6489
|
return value;
|
|
6143
6490
|
}, keyframes, transition, element);
|
|
6491
|
+
isBound = true;
|
|
6492
|
+
created && effect(subject, created);
|
|
6493
|
+
return animations;
|
|
6144
6494
|
}
|
|
6145
6495
|
function firstKeyframe(target) {
|
|
6146
6496
|
const first = Array.isArray(target) ? target[0] : undefined;
|
|
@@ -7136,7 +7486,7 @@
|
|
|
7136
7486
|
|
|
7137
7487
|
function animateSingleValue(value, keyframes, options) {
|
|
7138
7488
|
const motionValue$1 = isMotionValue(value) ? value : motionValue(value);
|
|
7139
|
-
motionValue$1.
|
|
7489
|
+
motionValue$1.run(animateMotionValue("", motionValue$1, keyframes, options));
|
|
7140
7490
|
return motionValue$1.animation;
|
|
7141
7491
|
}
|
|
7142
7492
|
|
|
@@ -7636,13 +7986,7 @@
|
|
|
7636
7986
|
if (xTranslate || yTranslate || zTranslate) {
|
|
7637
7987
|
transform = `translate3d(${xTranslate}px, ${yTranslate}px, ${zTranslate}px) `;
|
|
7638
7988
|
}
|
|
7639
|
-
|
|
7640
|
-
* Apply scale correction for the tree transform.
|
|
7641
|
-
* This will apply scale to the screen-orientated axes.
|
|
7642
|
-
*/
|
|
7643
|
-
if (treeScale.x !== 1 || treeScale.y !== 1) {
|
|
7644
|
-
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
7645
|
-
}
|
|
7989
|
+
let angles = "";
|
|
7646
7990
|
if (latestTransform) {
|
|
7647
7991
|
const { transformPerspective } = latestTransform;
|
|
7648
7992
|
if (transformPerspective)
|
|
@@ -7651,20 +7995,48 @@
|
|
|
7651
7995
|
const key = angleTransforms[i];
|
|
7652
7996
|
const value = latestTransform[key];
|
|
7653
7997
|
if (value)
|
|
7654
|
-
|
|
7998
|
+
angles += `${key}(${value}deg) `;
|
|
7655
7999
|
// Additive `rotate()` so user `rotate` isn't clobbered.
|
|
7656
8000
|
if (!i && latestTransform.pathRotation)
|
|
7657
|
-
|
|
8001
|
+
angles += `rotate(${latestTransform.pathRotation}deg) `;
|
|
7658
8002
|
}
|
|
7659
8003
|
}
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
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)";
|
|
7668
8040
|
}
|
|
7669
8041
|
return transform || "none";
|
|
7670
8042
|
}
|
|
@@ -10880,7 +11252,7 @@
|
|
|
10880
11252
|
|
|
10881
11253
|
const overflowStyles = /*#__PURE__*/ new Set(["auto", "scroll"]);
|
|
10882
11254
|
class PanSession {
|
|
10883
|
-
constructor(event, handlers, { transformPagePoint, contextWindow = window, dragSnapToOrigin = false, distanceThreshold = 3, element, } = {}) {
|
|
11255
|
+
constructor(event, handlers, { transformPagePoint, contextWindow = window, dragSnapToOrigin = false, distanceThreshold = 3, element, immediate, } = {}) {
|
|
10884
11256
|
this.startEvent = null;
|
|
10885
11257
|
this.lastMoveEvent = null;
|
|
10886
11258
|
this.lastMoveEventInfo = null;
|
|
@@ -10966,7 +11338,7 @@
|
|
|
10966
11338
|
this.dragSnapToOrigin = dragSnapToOrigin;
|
|
10967
11339
|
this.handlers = handlers;
|
|
10968
11340
|
this.transformPagePoint = transformPagePoint;
|
|
10969
|
-
this.distanceThreshold = distanceThreshold;
|
|
11341
|
+
this.distanceThreshold = immediate ? 0 : distanceThreshold;
|
|
10970
11342
|
this.contextWindow = contextWindow || window;
|
|
10971
11343
|
const info = extractEventInfo(event);
|
|
10972
11344
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
@@ -10990,6 +11362,10 @@
|
|
|
10990
11362
|
if (element) {
|
|
10991
11363
|
this.startScrollTracking(element);
|
|
10992
11364
|
}
|
|
11365
|
+
if (immediate) {
|
|
11366
|
+
this.handlePointerMove(event, info);
|
|
11367
|
+
this.updatePoint();
|
|
11368
|
+
}
|
|
10993
11369
|
}
|
|
10994
11370
|
/**
|
|
10995
11371
|
* Start tracking scroll on ancestors and window.
|
|
@@ -11365,14 +11741,14 @@
|
|
|
11365
11741
|
this.visualElement = visualElement;
|
|
11366
11742
|
this.readProps = readProps;
|
|
11367
11743
|
}
|
|
11368
|
-
start(originEvent,
|
|
11744
|
+
start(originEvent, options = {}) {
|
|
11369
11745
|
/**
|
|
11370
11746
|
* Don't start dragging if this component is exiting
|
|
11371
11747
|
*/
|
|
11372
11748
|
if (this.visualElement.presenceContext?.isPresent === false)
|
|
11373
11749
|
return;
|
|
11374
11750
|
const onSessionStart = (event) => {
|
|
11375
|
-
if (snapToCursor)
|
|
11751
|
+
if (options.snapToCursor)
|
|
11376
11752
|
this.snapToCursor(event);
|
|
11377
11753
|
this.stopAnimation();
|
|
11378
11754
|
};
|
|
@@ -11494,9 +11870,9 @@
|
|
|
11494
11870
|
onSessionEnd,
|
|
11495
11871
|
resumeAnimation,
|
|
11496
11872
|
}, {
|
|
11873
|
+
...options,
|
|
11497
11874
|
transformPagePoint: this.visualElement.getTransformPagePoint(),
|
|
11498
11875
|
dragSnapToOrigin,
|
|
11499
|
-
distanceThreshold,
|
|
11500
11876
|
contextWindow: this.visualElement.current?.ownerDocument.defaultView,
|
|
11501
11877
|
element: this.visualElement.current,
|
|
11502
11878
|
});
|
|
@@ -11944,8 +12320,10 @@
|
|
|
11944
12320
|
return isElementConstraints(dragConstraints) && !!onMeasureDragConstraints;
|
|
11945
12321
|
}
|
|
11946
12322
|
|
|
11947
|
-
const toProps = ({ axis, constraints, elastic, momentum, transition, snapToOrigin, directionLock, propagation, onStart, onMove, onEnd, onDirectionLock, onTransitionEnd, onMeasureConstraints, }) => ({
|
|
12323
|
+
const toProps = ({ axis, constraints, elastic, momentum, transition, snapToOrigin, directionLock, propagation, onStart, onMove, onEnd, onDirectionLock, onTransitionEnd, onMeasureConstraints, x, y, }) => ({
|
|
11948
12324
|
drag: axis || true,
|
|
12325
|
+
_dragX: x || (y && motionValue(0)),
|
|
12326
|
+
_dragY: y || (x && motionValue(0)),
|
|
11949
12327
|
dragConstraints: constraints,
|
|
11950
12328
|
dragElastic: elastic,
|
|
11951
12329
|
dragMomentum: momentum,
|
|
@@ -12154,7 +12532,7 @@
|
|
|
12154
12532
|
*/
|
|
12155
12533
|
let isKeyPressing = false;
|
|
12156
12534
|
const handleKeydown = filterEvents(() => {
|
|
12157
|
-
if (isPressing.has(element))
|
|
12535
|
+
if (isKeyPressing || isPressing.has(element))
|
|
12158
12536
|
return;
|
|
12159
12537
|
isKeyPressing = true;
|
|
12160
12538
|
firePointerEvent(element, "down");
|
|
@@ -12186,6 +12564,18 @@
|
|
|
12186
12564
|
return isPrimaryPointer(event) && !isDragActive();
|
|
12187
12565
|
}
|
|
12188
12566
|
const claimedPointerDownEvents = new WeakSet();
|
|
12567
|
+
/**
|
|
12568
|
+
* Max distance in px between consecutive presses of a `count` sequence.
|
|
12569
|
+
* Android's `ViewConfiguration` double tap slop is 100dp.
|
|
12570
|
+
*/
|
|
12571
|
+
const sequenceSlop = 100;
|
|
12572
|
+
/**
|
|
12573
|
+
* Max distance in px a pointer can move during a held press (`hold`
|
|
12574
|
+
* pending, or `repeat`). Android's `ViewConfiguration` touch slop is 8dp.
|
|
12575
|
+
*/
|
|
12576
|
+
const holdSlop = 8;
|
|
12577
|
+
const exceeds = (a, b, max) => Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) > max;
|
|
12578
|
+
const preventDefault = (event) => event.preventDefault();
|
|
12189
12579
|
/**
|
|
12190
12580
|
* Create a press gesture.
|
|
12191
12581
|
*
|
|
@@ -12203,22 +12593,110 @@
|
|
|
12203
12593
|
* to be focusable for this to work, whereas a press gesture will
|
|
12204
12594
|
* make an element focusable by default.
|
|
12205
12595
|
*
|
|
12596
|
+
* `onPressStart` fires on the first pointer or key down, and can return
|
|
12597
|
+
* a function to call when the press ends, or an object of handlers for
|
|
12598
|
+
* this press:
|
|
12599
|
+
*
|
|
12600
|
+
* ```js
|
|
12601
|
+
* press(button, () => ({
|
|
12602
|
+
* onHold: (progress) => {},
|
|
12603
|
+
* onComplete: (event, { success }) => {},
|
|
12604
|
+
* }), { hold: 0.5 })
|
|
12605
|
+
* ```
|
|
12606
|
+
*
|
|
12206
12607
|
* @public
|
|
12207
12608
|
*/
|
|
12208
12609
|
function press(targetOrSelector, onPressStart, options = {}) {
|
|
12209
12610
|
onPressStart = bindToScope(onPressStart);
|
|
12210
12611
|
const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
|
|
12612
|
+
const sequences = new WeakMap();
|
|
12211
12613
|
const startPress = (startEvent) => {
|
|
12212
12614
|
const target = startEvent.currentTarget;
|
|
12213
12615
|
if (!isValidPressEvent(startEvent))
|
|
12214
12616
|
return;
|
|
12215
12617
|
if (claimedPointerDownEvents.has(startEvent))
|
|
12216
12618
|
return;
|
|
12217
|
-
isPressing.add(target);
|
|
12218
12619
|
if (options.stopPropagation) {
|
|
12219
12620
|
claimedPointerDownEvents.add(startEvent);
|
|
12220
12621
|
}
|
|
12221
|
-
|
|
12622
|
+
/**
|
|
12623
|
+
* Options are read per press so they can be updated between presses.
|
|
12624
|
+
*/
|
|
12625
|
+
const { count: presses = 1, countTimeout = 0.3, hold = 0, repeat, } = options;
|
|
12626
|
+
const downTime = time.now();
|
|
12627
|
+
const holdTime = secondsToMilliseconds(hold);
|
|
12628
|
+
const timeout = secondsToMilliseconds(countTimeout);
|
|
12629
|
+
let previous = sequences.get(target);
|
|
12630
|
+
/**
|
|
12631
|
+
* A press during a `count` sequence continues it. If it's too late
|
|
12632
|
+
* or too far away, the sequence is cancelled and this press starts
|
|
12633
|
+
* a new one.
|
|
12634
|
+
*/
|
|
12635
|
+
if (previous?.expire(exceeds(previous.event, startEvent, sequenceSlop))) {
|
|
12636
|
+
previous = undefined;
|
|
12637
|
+
}
|
|
12638
|
+
else if (previous) {
|
|
12639
|
+
cancelFrame(previous.expire);
|
|
12640
|
+
sequences.delete(target);
|
|
12641
|
+
}
|
|
12642
|
+
const count = previous ? previous.count + 1 : 1;
|
|
12643
|
+
const isFinal = count >= presses;
|
|
12644
|
+
const isHeld = isFinal && (hold || repeat);
|
|
12645
|
+
let isActive = !hold;
|
|
12646
|
+
let repeats = 0;
|
|
12647
|
+
let handlers;
|
|
12648
|
+
isPressing.add(target);
|
|
12649
|
+
if (previous) {
|
|
12650
|
+
handlers = previous.handlers;
|
|
12651
|
+
}
|
|
12652
|
+
else {
|
|
12653
|
+
const result = onPressStart(target, startEvent);
|
|
12654
|
+
handlers =
|
|
12655
|
+
typeof result === "function"
|
|
12656
|
+
? { onComplete: result }
|
|
12657
|
+
: result || {};
|
|
12658
|
+
}
|
|
12659
|
+
isFinal && isActive && handlers.onActive?.();
|
|
12660
|
+
/**
|
|
12661
|
+
* While held, `onHold` reports progress from 0 to 1 over `hold`,
|
|
12662
|
+
* then over each `repeat`. Each cycle reports exactly 1 at its end,
|
|
12663
|
+
* then 0 on the next frame.
|
|
12664
|
+
*/
|
|
12665
|
+
const repeatTime = secondsToMilliseconds(repeat);
|
|
12666
|
+
let length = holdTime || repeatTime;
|
|
12667
|
+
let cycleEnd = downTime + length;
|
|
12668
|
+
let isCycleStart = true;
|
|
12669
|
+
const tick = () => {
|
|
12670
|
+
if (eventOptions.signal.aborted)
|
|
12671
|
+
return cancelFrame(tick);
|
|
12672
|
+
let progress = Math.min(1 - (cycleEnd - time.now()) / length, 1);
|
|
12673
|
+
/**
|
|
12674
|
+
* The frame after a boundary reports 0, so each cycle visibly
|
|
12675
|
+
* restarts. Boundaries are timed from `downTime`, so this
|
|
12676
|
+
* doesn't delay the next one. If a long frame has already
|
|
12677
|
+
* passed the next boundary, it reports 1 instead.
|
|
12678
|
+
*/
|
|
12679
|
+
if (isCycleStart && progress < 1)
|
|
12680
|
+
progress = 0;
|
|
12681
|
+
isCycleStart = false;
|
|
12682
|
+
handlers.onHold?.(progress);
|
|
12683
|
+
if (progress < 1)
|
|
12684
|
+
return;
|
|
12685
|
+
if (isActive) {
|
|
12686
|
+
handlers.onRepeat?.(++repeats);
|
|
12687
|
+
}
|
|
12688
|
+
else {
|
|
12689
|
+
isActive = true;
|
|
12690
|
+
handlers.onActive?.();
|
|
12691
|
+
}
|
|
12692
|
+
if (repeat) {
|
|
12693
|
+
isCycleStart = true;
|
|
12694
|
+
cycleEnd += length = repeatTime;
|
|
12695
|
+
}
|
|
12696
|
+
else {
|
|
12697
|
+
cancelFrame(tick);
|
|
12698
|
+
}
|
|
12699
|
+
};
|
|
12222
12700
|
/**
|
|
12223
12701
|
* End listeners run in the capture phase so a descendant calling
|
|
12224
12702
|
* stopPropagation() in its own pointerup handler can't prevent the
|
|
@@ -12229,14 +12707,55 @@
|
|
|
12229
12707
|
const onPointerEnd = (endEvent, success) => {
|
|
12230
12708
|
window.removeEventListener("pointerup", onPointerUp, endEventOptions);
|
|
12231
12709
|
window.removeEventListener("pointercancel", onPointerCancel, endEventOptions);
|
|
12232
|
-
|
|
12233
|
-
|
|
12234
|
-
|
|
12235
|
-
|
|
12710
|
+
window.removeEventListener("pointermove", onPointerMove, endEventOptions);
|
|
12711
|
+
target.removeEventListener("contextmenu", preventDefault);
|
|
12712
|
+
cancelFrame(tick);
|
|
12713
|
+
isPressing.delete(target);
|
|
12714
|
+
if (!isPrimaryPointer(endEvent))
|
|
12236
12715
|
return;
|
|
12716
|
+
/**
|
|
12717
|
+
* A press that ends while a drag is active is a cancel.
|
|
12718
|
+
*/
|
|
12719
|
+
if (isDragActive())
|
|
12720
|
+
success = false;
|
|
12721
|
+
if (success && !isFinal) {
|
|
12722
|
+
/**
|
|
12723
|
+
* Wait for the next press of the sequence, and cancel the
|
|
12724
|
+
* gesture if it doesn't arrive in time.
|
|
12725
|
+
*/
|
|
12726
|
+
const end = time.now();
|
|
12727
|
+
/**
|
|
12728
|
+
* Cancels the sequence if it's `force`d, or the interval
|
|
12729
|
+
* has passed. Runs every frame, where `force` is frame
|
|
12730
|
+
* data, so it's checked with `=== true`.
|
|
12731
|
+
*/
|
|
12732
|
+
const expire = (force) => {
|
|
12733
|
+
const isAborted = eventOptions.signal.aborted;
|
|
12734
|
+
if (isAborted ||
|
|
12735
|
+
force === true ||
|
|
12736
|
+
time.now() - end > timeout) {
|
|
12737
|
+
cancelFrame(expire);
|
|
12738
|
+
sequences.delete(target);
|
|
12739
|
+
isAborted ||
|
|
12740
|
+
handlers.onComplete?.(endEvent, { success: false });
|
|
12741
|
+
return true;
|
|
12742
|
+
}
|
|
12743
|
+
};
|
|
12744
|
+
sequences.set(target, {
|
|
12745
|
+
count,
|
|
12746
|
+
event: startEvent,
|
|
12747
|
+
handlers,
|
|
12748
|
+
expire,
|
|
12749
|
+
});
|
|
12750
|
+
frame.update(expire, true);
|
|
12237
12751
|
}
|
|
12238
|
-
|
|
12239
|
-
|
|
12752
|
+
else {
|
|
12753
|
+
/**
|
|
12754
|
+
* Releasing before `hold` is reached is a cancel.
|
|
12755
|
+
*/
|
|
12756
|
+
handlers.onComplete?.(endEvent, {
|
|
12757
|
+
success: success && isActive,
|
|
12758
|
+
});
|
|
12240
12759
|
}
|
|
12241
12760
|
};
|
|
12242
12761
|
const onPointerUp = (upEvent) => {
|
|
@@ -12248,8 +12767,35 @@
|
|
|
12248
12767
|
const onPointerCancel = (cancelEvent) => {
|
|
12249
12768
|
onPointerEnd(cancelEvent, false);
|
|
12250
12769
|
};
|
|
12770
|
+
/**
|
|
12771
|
+
* Moving during a pending long press, or a repeating press, cancels
|
|
12772
|
+
* it, so scrolling on touch devices doesn't trigger it. A drag
|
|
12773
|
+
* starting during a `count` sequence cancels it.
|
|
12774
|
+
*/
|
|
12775
|
+
const onPointerMove = (moveEvent) => {
|
|
12776
|
+
if (isPrimaryPointer(moveEvent) &&
|
|
12777
|
+
(((repeat || !isActive) &&
|
|
12778
|
+
exceeds(startEvent, moveEvent, holdSlop)) ||
|
|
12779
|
+
(presses > 1 && isDragActive()))) {
|
|
12780
|
+
onPointerCancel(moveEvent);
|
|
12781
|
+
}
|
|
12782
|
+
};
|
|
12251
12783
|
window.addEventListener("pointerup", onPointerUp, endEventOptions);
|
|
12252
12784
|
window.addEventListener("pointercancel", onPointerCancel, endEventOptions);
|
|
12785
|
+
if (isHeld || presses > 1) {
|
|
12786
|
+
window.addEventListener("pointermove", onPointerMove, endEventOptions);
|
|
12787
|
+
}
|
|
12788
|
+
if (isHeld) {
|
|
12789
|
+
frame.update(tick, true);
|
|
12790
|
+
/**
|
|
12791
|
+
* Touch devices open a context menu or callout on long press,
|
|
12792
|
+
* which would cancel the gesture.
|
|
12793
|
+
*/
|
|
12794
|
+
target.addEventListener("contextmenu", preventDefault, {
|
|
12795
|
+
...eventOptions,
|
|
12796
|
+
passive: false,
|
|
12797
|
+
});
|
|
12798
|
+
}
|
|
12253
12799
|
};
|
|
12254
12800
|
targets.forEach((target) => {
|
|
12255
12801
|
const pointerDownTarget = options.useGlobalTarget ? window : target;
|
|
@@ -15014,6 +15560,13 @@
|
|
|
15014
15560
|
info.duration = totalDuration;
|
|
15015
15561
|
info.labels = timeLabels;
|
|
15016
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;
|
|
15017
15570
|
/**
|
|
15018
15571
|
* For every element and value combination create a new animation.
|
|
15019
15572
|
*/
|
|
@@ -15064,13 +15617,6 @@
|
|
|
15064
15617
|
}
|
|
15065
15618
|
const definition = animationDefinitions.get(element);
|
|
15066
15619
|
definition.keyframes[key] = keyframes;
|
|
15067
|
-
/**
|
|
15068
|
-
* Exclude `type` from defaultTransition since springs have been
|
|
15069
|
-
* converted to duration-based easing functions in resolveValueSequence.
|
|
15070
|
-
* Including `type: "spring"` would cause JSAnimation to error when
|
|
15071
|
-
* the merged keyframes array has more than 2 keyframes.
|
|
15072
|
-
*/
|
|
15073
|
-
const { type: _type, ...remainingDefaultTransition } = defaultTransition;
|
|
15074
15620
|
definition.transition[key] = {
|
|
15075
15621
|
...remainingDefaultTransition,
|
|
15076
15622
|
duration: totalDuration,
|
|
@@ -15185,13 +15731,45 @@
|
|
|
15185
15731
|
return segment;
|
|
15186
15732
|
});
|
|
15187
15733
|
const animationDefinitions = createAnimationsFromSequence(processedSequence, options, scope, { spring }, info);
|
|
15734
|
+
/**
|
|
15735
|
+
* Transitions are made per value, but reduceMotion is read from the
|
|
15736
|
+
* top level. animate() resolves it into options, and the default
|
|
15737
|
+
* transition covers timelines made directly.
|
|
15738
|
+
*/
|
|
15739
|
+
const reduceMotion = options?.reduceMotion ??
|
|
15740
|
+
options?.defaultTransition?.reduceMotion;
|
|
15188
15741
|
animationDefinitions.forEach(({ keyframes, transition }, subject) => {
|
|
15189
|
-
animations.push(...animateSubject(subject, keyframes,
|
|
15742
|
+
animations.push(...animateSubject(subject, keyframes, {
|
|
15743
|
+
...transition,
|
|
15744
|
+
reduceMotion,
|
|
15745
|
+
}));
|
|
15190
15746
|
});
|
|
15191
15747
|
return animations;
|
|
15192
15748
|
}
|
|
15193
15749
|
|
|
15194
15750
|
let markerId = 0;
|
|
15751
|
+
/**
|
|
15752
|
+
* Split a time across repeats into its repeat and the playhead position in
|
|
15753
|
+
* the sequence. A time on a repeat boundary is the end of the repeat
|
|
15754
|
+
* before it, as it is for the clock's value. With `index`, join a position
|
|
15755
|
+
* in that repeat back into a time. Mirrored and reversed repeats play
|
|
15756
|
+
* every other repeat backwards.
|
|
15757
|
+
*/
|
|
15758
|
+
function inRepeat({ repeat = 0, repeatDelay = 0, repeatType = "loop", delay = 0, }, duration, time, index) {
|
|
15759
|
+
const cycle = duration + repeatDelay;
|
|
15760
|
+
const isSplit = index === undefined;
|
|
15761
|
+
if (isSplit) {
|
|
15762
|
+
const t = Math.max(0, time - delay);
|
|
15763
|
+
index =
|
|
15764
|
+
cycle && t > 0
|
|
15765
|
+
? Math.min(repeat, Math.ceil(t / cycle - 1e-9) - 1)
|
|
15766
|
+
: 0;
|
|
15767
|
+
time = Math.min(t - index * cycle, duration);
|
|
15768
|
+
}
|
|
15769
|
+
if (repeatType !== "loop" && index % 2)
|
|
15770
|
+
time = duration - time;
|
|
15771
|
+
return [index, isSplit ? time : delay + index * cycle + time];
|
|
15772
|
+
}
|
|
15195
15773
|
/**
|
|
15196
15774
|
* Copy a segment with a new `at`, adding a transition if it has none.
|
|
15197
15775
|
*/
|
|
@@ -15279,15 +15857,6 @@
|
|
|
15279
15857
|
this.invalidate();
|
|
15280
15858
|
this.flush();
|
|
15281
15859
|
}
|
|
15282
|
-
/**
|
|
15283
|
-
* Register with the scope (for instance from useAnimate()) so it
|
|
15284
|
-
* stops when the scope is torn down.
|
|
15285
|
-
*/
|
|
15286
|
-
const { scope } = options;
|
|
15287
|
-
if (scope) {
|
|
15288
|
-
scope.animations.push(this);
|
|
15289
|
-
this.finished.then(() => removeItem(scope.animations, this));
|
|
15290
|
-
}
|
|
15291
15860
|
}
|
|
15292
15861
|
/**
|
|
15293
15862
|
* Add a segment, label or timeline. `at` overrides any `at` already
|
|
@@ -15362,10 +15931,18 @@
|
|
|
15362
15931
|
* Play forwards or backwards to a time or label, then pause there.
|
|
15363
15932
|
*/
|
|
15364
15933
|
playTo(position) {
|
|
15365
|
-
const
|
|
15934
|
+
const stopAt = this.resolve(position);
|
|
15935
|
+
const duration = this.iterationDuration;
|
|
15936
|
+
/**
|
|
15937
|
+
* A repeating timeline plays to the position in the repeat it's
|
|
15938
|
+
* already in, rather than all the way back to the first.
|
|
15939
|
+
*/
|
|
15940
|
+
const time = this.time;
|
|
15941
|
+
const [index] = inRepeat(this.options, duration, time);
|
|
15942
|
+
const target = inRepeat(this.options, duration, stopAt, index)[1];
|
|
15366
15943
|
const speed = Math.abs(this.speed);
|
|
15367
|
-
this.speed = target <
|
|
15368
|
-
this.stopAt =
|
|
15944
|
+
this.speed = target < time ? -speed : speed;
|
|
15945
|
+
this.stopAt = stopAt;
|
|
15369
15946
|
this.clock || this.invalidate();
|
|
15370
15947
|
this.play();
|
|
15371
15948
|
return this;
|
|
@@ -15493,6 +16070,9 @@
|
|
|
15493
16070
|
this.parent = parent;
|
|
15494
16071
|
}
|
|
15495
16072
|
build() {
|
|
16073
|
+
const prevDuration = this.isWrapped
|
|
16074
|
+
? this.group.iterationDuration
|
|
16075
|
+
: this.totalDuration;
|
|
15496
16076
|
this.isDirty = false;
|
|
15497
16077
|
this.isWrapped = false;
|
|
15498
16078
|
const prev = this.group;
|
|
@@ -15577,9 +16157,19 @@
|
|
|
15577
16157
|
})));
|
|
15578
16158
|
}
|
|
15579
16159
|
const group = (this.group = new GroupAnimationWithThen(animations));
|
|
15580
|
-
|
|
15581
|
-
|
|
16160
|
+
/**
|
|
16161
|
+
* Keep the playhead in the same repeat and at the same position,
|
|
16162
|
+
* so changing a repeating timeline doesn't jump it.
|
|
16163
|
+
*/
|
|
16164
|
+
const { delay = 0, repeat = 0, repeatDelay = 0 } = this.options;
|
|
16165
|
+
const [index, position] = inRepeat(this.options, prevDuration, time);
|
|
16166
|
+
if (time > delay) {
|
|
16167
|
+
time = inRepeat(this.options, duration, Math.min(position, duration), index)[1];
|
|
16168
|
+
}
|
|
16169
|
+
if (this.isDone &&
|
|
16170
|
+
time < delay + (repeat + 1) * (duration + repeatDelay) - repeatDelay) {
|
|
15582
16171
|
this.newFinished();
|
|
16172
|
+
}
|
|
15583
16173
|
if (this.scrollTimeline) {
|
|
15584
16174
|
this.detachScroll = group.attachTimeline(this.scrollTimeline);
|
|
15585
16175
|
}
|
|
@@ -15626,12 +16216,7 @@
|
|
|
15626
16216
|
* The repeat the clock is in, from its time across all repeats.
|
|
15627
16217
|
*/
|
|
15628
16218
|
currentRepeat() {
|
|
15629
|
-
|
|
15630
|
-
const cycle = this.totalDuration + repeatDelay;
|
|
15631
|
-
const time = (this.clockAnimation?.time ?? 0) - delay;
|
|
15632
|
-
return cycle && time > 0
|
|
15633
|
-
? Math.min(repeat, Math.floor(time / cycle))
|
|
15634
|
-
: 0;
|
|
16219
|
+
return inRepeat(this.options, this.totalDuration, this.clockAnimation?.time ?? 0)[0];
|
|
15635
16220
|
}
|
|
15636
16221
|
onClock(time) {
|
|
15637
16222
|
let prevTime = this.prevTime;
|
|
@@ -15640,22 +16225,23 @@
|
|
|
15640
16225
|
return;
|
|
15641
16226
|
const { onUpdate, onRepeat, repeatType = "loop" } = this.options;
|
|
15642
16227
|
onUpdate?.(time);
|
|
16228
|
+
/**
|
|
16229
|
+
* A frame can cross any number of repeats. Finish crossing each
|
|
16230
|
+
* repeat it leaves, then cross the next from its edge. A loop
|
|
16231
|
+
* starts each repeat from the same edge. The others turn around.
|
|
16232
|
+
*/
|
|
15643
16233
|
const repeatIndex = this.currentRepeat();
|
|
15644
|
-
|
|
15645
|
-
|
|
16234
|
+
const step = repeatIndex > this.repeatIndex ? 1 : -1;
|
|
16235
|
+
while (repeatIndex !== this.repeatIndex) {
|
|
16236
|
+
const isForward = (this.speed > 0) ===
|
|
16237
|
+
(repeatType === "loop" || !(this.repeatIndex % 2));
|
|
16238
|
+
const edge = isForward ? this.totalDuration : 0;
|
|
16239
|
+
if (this.cross(prevTime, edge))
|
|
16240
|
+
return;
|
|
16241
|
+
this.repeatIndex += step;
|
|
15646
16242
|
onRepeat?.();
|
|
15647
|
-
|
|
15648
|
-
|
|
15649
|
-
* end when playing backwards. Finish crossing the repeat
|
|
15650
|
-
* that ended, then cross the new one from its edge.
|
|
15651
|
-
*/
|
|
15652
|
-
if (repeatType === "loop") {
|
|
15653
|
-
const isForward = this.speed > 0;
|
|
15654
|
-
if (this.cross(prevTime, isForward ? this.totalDuration : 0)) {
|
|
15655
|
-
return;
|
|
15656
|
-
}
|
|
15657
|
-
prevTime = isForward ? -1 : Infinity;
|
|
15658
|
-
}
|
|
16243
|
+
prevTime =
|
|
16244
|
+
repeatType === "loop" ? (isForward ? -1 : Infinity) : edge;
|
|
15659
16245
|
}
|
|
15660
16246
|
this.cross(prevTime, time);
|
|
15661
16247
|
}
|
|
@@ -15682,9 +16268,12 @@
|
|
|
15682
16268
|
return true;
|
|
15683
16269
|
}
|
|
15684
16270
|
}
|
|
15685
|
-
|
|
16271
|
+
/**
|
|
16272
|
+
* Pause at a playhead position in the current repeat.
|
|
16273
|
+
*/
|
|
16274
|
+
pauseAt(position) {
|
|
15686
16275
|
this.pause();
|
|
15687
|
-
this.time =
|
|
16276
|
+
this.time = inRepeat(this.options, this.totalDuration, position, this.repeatIndex)[1];
|
|
15688
16277
|
return true;
|
|
15689
16278
|
}
|
|
15690
16279
|
watch() {
|
|
@@ -15699,8 +16288,13 @@
|
|
|
15699
16288
|
* direction, as it does for a single animation.
|
|
15700
16289
|
*/
|
|
15701
16290
|
const callback = (this.speed < 0 && onReverseComplete) || onComplete;
|
|
16291
|
+
/**
|
|
16292
|
+
* Resolve this run's promise, even if the callback plays the
|
|
16293
|
+
* timeline again and so makes a new one.
|
|
16294
|
+
*/
|
|
16295
|
+
const resolve = this.resolveFinished;
|
|
15702
16296
|
callback?.();
|
|
15703
|
-
|
|
16297
|
+
resolve();
|
|
15704
16298
|
});
|
|
15705
16299
|
}
|
|
15706
16300
|
newFinished() {
|
|
@@ -15709,19 +16303,30 @@
|
|
|
15709
16303
|
this.resolveFinished = resolve;
|
|
15710
16304
|
});
|
|
15711
16305
|
/**
|
|
15712
|
-
* Stay in the scope
|
|
15713
|
-
*
|
|
16306
|
+
* Stay in the scopeMotion() scope this was created in, and the
|
|
16307
|
+
* useAnimate() scope, while playing. Each replay, including a
|
|
16308
|
+
* change that restarts a finished timeline, registers again.
|
|
15714
16309
|
*/
|
|
16310
|
+
const { scope } = this.options;
|
|
15715
16311
|
const remove = this.motionScope?.add(() => {
|
|
15716
16312
|
this.isKilled = true;
|
|
15717
16313
|
this.stop();
|
|
15718
16314
|
});
|
|
15719
|
-
|
|
16315
|
+
scope?.animations.push(this);
|
|
16316
|
+
this.finished.then(() => {
|
|
16317
|
+
remove?.();
|
|
16318
|
+
scope && removeItem(scope.animations, this);
|
|
16319
|
+
});
|
|
15720
16320
|
}
|
|
15721
16321
|
}
|
|
15722
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
|
+
*/
|
|
15723
16327
|
function isSequence(value) {
|
|
15724
|
-
return Array.isArray(value) &&
|
|
16328
|
+
return (Array.isArray(value) &&
|
|
16329
|
+
value.some((item) => Array.isArray(item) || item?.sequence));
|
|
15725
16330
|
}
|
|
15726
16331
|
/**
|
|
15727
16332
|
* Creates an animation function that is optionally scoped
|
|
@@ -15752,6 +16357,16 @@
|
|
|
15752
16357
|
...sequenceOptions.defaultTransition,
|
|
15753
16358
|
};
|
|
15754
16359
|
}
|
|
16360
|
+
/**
|
|
16361
|
+
* Resolve reduceMotion in the same order as a single
|
|
16362
|
+
* animation: options, then the default transition (which
|
|
16363
|
+
* includes the scope's), then useAnimate()'s.
|
|
16364
|
+
*/
|
|
16365
|
+
sequenceOptions.reduceMotion =
|
|
16366
|
+
optionsOrKeyframes?.reduceMotion ??
|
|
16367
|
+
sequenceOptions.defaultTransition
|
|
16368
|
+
?.reduceMotion ??
|
|
16369
|
+
reduceMotion;
|
|
15755
16370
|
timeline = new Timeline(subjectOrSequence, sequenceOptions);
|
|
15756
16371
|
}
|
|
15757
16372
|
else {
|
|
@@ -15799,33 +16414,41 @@
|
|
|
15799
16414
|
});
|
|
15800
16415
|
|
|
15801
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) {
|
|
15802
16444
|
// Gracefully handle null/undefined elements (e.g., from querySelector returning null)
|
|
15803
|
-
if (elementOrSelector == null)
|
|
15804
|
-
return
|
|
15805
|
-
}
|
|
16445
|
+
if (elementOrSelector == null)
|
|
16446
|
+
return;
|
|
15806
16447
|
const elements = resolveElements(elementOrSelector, scope);
|
|
15807
16448
|
const numElements = elements.length;
|
|
15808
16449
|
typeof process !== "undefined" &&
|
|
15809
16450
|
"development" !== "production" &&
|
|
15810
16451
|
exports.invariant(Boolean(numElements), "No valid elements provided.", "no-valid-elements");
|
|
15811
|
-
/**
|
|
15812
|
-
* WAAPI doesn't support interrupting animations.
|
|
15813
|
-
*
|
|
15814
|
-
* Therefore, starting animations requires a three-step process:
|
|
15815
|
-
* 1. Stop existing animations (write styles to DOM)
|
|
15816
|
-
* 2. Resolve keyframes (read styles from DOM)
|
|
15817
|
-
* 3. Create new animations (write styles to DOM)
|
|
15818
|
-
*
|
|
15819
|
-
* The hybrid `animate()` function uses AsyncAnimation to resolve
|
|
15820
|
-
* keyframes before creating new animations, which removes style
|
|
15821
|
-
* thrashing. Here, we have much stricter filesize constraints.
|
|
15822
|
-
* Therefore we do this in a synchronous way that ensures that
|
|
15823
|
-
* at least within `animate()` calls there is no style thrashing.
|
|
15824
|
-
*
|
|
15825
|
-
* In the motion-native-animate-mini-interrupt benchmark this
|
|
15826
|
-
* was 80% faster than a single loop.
|
|
15827
|
-
*/
|
|
15828
|
-
const animationDefinitions = [];
|
|
15829
16452
|
/**
|
|
15830
16453
|
* Step 1: Build options and stop existing animations (write)
|
|
15831
16454
|
*/
|
|
@@ -15869,6 +16492,8 @@
|
|
|
15869
16492
|
});
|
|
15870
16493
|
}
|
|
15871
16494
|
}
|
|
16495
|
+
}
|
|
16496
|
+
function startAnimationDefinitions(animationDefinitions) {
|
|
15872
16497
|
/**
|
|
15873
16498
|
* Step 2: Resolve keyframes (read)
|
|
15874
16499
|
*/
|