framer-motion 10.2.5 → 10.3.0

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.
@@ -1984,7 +1984,7 @@
1984
1984
  * This will be replaced by the build step with the latest version number.
1985
1985
  * When MotionValues are provided to motion components, warn if versions are mixed.
1986
1986
  */
1987
- this.version = "10.2.5";
1987
+ this.version = "10.3.0";
1988
1988
  /**
1989
1989
  * Duration, in milliseconds, since last updating frame.
1990
1990
  *
@@ -3517,6 +3517,20 @@
3517
3517
  return duration;
3518
3518
  }
3519
3519
  function animateValue({ autoplay = true, delay = 0, driver = frameloopDriver, keyframes: keyframes$1, type = "keyframes", repeat = 0, repeatDelay = 0, repeatType = "loop", onPlay, onStop, onComplete, onUpdate, ...options }) {
3520
+ let resolveFinishedPromise;
3521
+ let currentFinishedPromise;
3522
+ /**
3523
+ * Create a new finished Promise every time we enter the
3524
+ * finished state and resolve the old Promise. This is
3525
+ * WAAPI-compatible behaviour.
3526
+ */
3527
+ const updateFinishedPromise = () => {
3528
+ currentFinishedPromise = new Promise((resolve) => {
3529
+ resolveFinishedPromise = resolve;
3530
+ });
3531
+ };
3532
+ // Create the first finished promise
3533
+ updateFinishedPromise();
3520
3534
  let animationDriver;
3521
3535
  const generatorFactory = types[type] || keyframes;
3522
3536
  /**
@@ -3562,26 +3576,26 @@
3562
3576
  resolvedDuration = calculatedDuration + repeatDelay;
3563
3577
  totalDuration = resolvedDuration * (repeat + 1) - repeatDelay;
3564
3578
  }
3565
- let currentTime = 0;
3579
+ let time = 0;
3566
3580
  const tick = (timestamp) => {
3567
3581
  if (startTime === null)
3568
3582
  return;
3569
3583
  if (holdTime !== null) {
3570
- currentTime = holdTime;
3584
+ time = holdTime;
3571
3585
  }
3572
3586
  else {
3573
- currentTime = timestamp - startTime;
3587
+ time = timestamp - startTime;
3574
3588
  }
3575
3589
  // Rebase on delay
3576
- currentTime = Math.max(currentTime - delay, 0);
3590
+ time = Math.max(time - delay, 0);
3577
3591
  /**
3578
3592
  * If this animation has finished, set the current time
3579
3593
  * to the total duration.
3580
3594
  */
3581
3595
  if (playState === "finished" && holdTime === null) {
3582
- currentTime = totalDuration;
3596
+ time = totalDuration;
3583
3597
  }
3584
- let elapsed = currentTime;
3598
+ let elapsed = time;
3585
3599
  let frameGenerator = generator;
3586
3600
  if (repeat) {
3587
3601
  /**
@@ -3589,7 +3603,7 @@
3589
3603
  * than duration we'll get values like 2.5 (midway through the
3590
3604
  * third iteration)
3591
3605
  */
3592
- const progress = currentTime / resolvedDuration;
3606
+ const progress = time / resolvedDuration;
3593
3607
  /**
3594
3608
  * Get the current iteration (0 indexed). For instance the floor of
3595
3609
  * 2.5 is 2.
@@ -3623,7 +3637,7 @@
3623
3637
  frameGenerator = mirroredGenerator;
3624
3638
  }
3625
3639
  }
3626
- const p = currentTime >= totalDuration
3640
+ const p = time >= totalDuration
3627
3641
  ? repeatType === "reverse" && iterationIsOdd
3628
3642
  ? 0
3629
3643
  : 1
@@ -3636,19 +3650,25 @@
3636
3650
  onUpdate(mapNumbersToKeyframes ? mapNumbersToKeyframes(value) : value);
3637
3651
  }
3638
3652
  if (calculatedDuration !== null) {
3639
- done = currentTime >= totalDuration;
3653
+ done = time >= totalDuration;
3640
3654
  }
3641
3655
  const isAnimationFinished = holdTime === null &&
3642
3656
  (playState === "finished" || (playState === "running" && done));
3643
3657
  if (isAnimationFinished) {
3644
- playState = "finished";
3645
- onComplete && onComplete();
3646
- animationDriver && animationDriver.stop();
3658
+ finish();
3647
3659
  }
3648
3660
  return state;
3649
3661
  };
3662
+ const finish = () => {
3663
+ animationDriver && animationDriver.stop();
3664
+ playState = "finished";
3665
+ onComplete && onComplete();
3666
+ resolveFinishedPromise();
3667
+ updateFinishedPromise();
3668
+ };
3650
3669
  const play = () => {
3651
- animationDriver = driver(tick);
3670
+ if (!animationDriver)
3671
+ animationDriver = driver(tick);
3652
3672
  const now = animationDriver.now();
3653
3673
  onPlay && onPlay();
3654
3674
  playState = "running";
@@ -3667,21 +3687,30 @@
3667
3687
  play();
3668
3688
  }
3669
3689
  const controls = {
3670
- get currentTime() {
3671
- return millisecondsToSeconds(currentTime);
3690
+ then(resolve, reject) {
3691
+ return currentFinishedPromise.then(resolve, reject);
3672
3692
  },
3673
- set currentTime(newTime) {
3693
+ get time() {
3694
+ return millisecondsToSeconds(time);
3695
+ },
3696
+ set time(newTime) {
3697
+ const timeInMs = secondsToMilliseconds(newTime);
3674
3698
  if (holdTime !== null || !animationDriver) {
3675
- holdTime = 0;
3699
+ holdTime = timeInMs;
3676
3700
  }
3677
3701
  else {
3678
- startTime =
3679
- animationDriver.now() - secondsToMilliseconds(newTime);
3702
+ startTime = animationDriver.now() - timeInMs;
3680
3703
  }
3681
3704
  },
3705
+ play,
3706
+ pause: () => {
3707
+ playState = "paused";
3708
+ holdTime = time;
3709
+ },
3682
3710
  stop: () => {
3683
3711
  onStop && onStop();
3684
3712
  animationDriver && animationDriver.stop();
3713
+ animationDriver = undefined;
3685
3714
  },
3686
3715
  sample: (elapsed) => {
3687
3716
  startTime = 0;
@@ -3780,12 +3809,17 @@
3780
3809
  * Animation interrupt callback.
3781
3810
  */
3782
3811
  return {
3783
- get currentTime() {
3812
+ then(resolve, reject) {
3813
+ return animation.finished.then(resolve, reject);
3814
+ },
3815
+ get time() {
3784
3816
  return millisecondsToSeconds(animation.currentTime || 0);
3785
3817
  },
3786
- set currentTime(newTime) {
3818
+ set time(newTime) {
3787
3819
  animation.currentTime = secondsToMilliseconds(newTime);
3788
3820
  },
3821
+ play: () => animation.play(),
3822
+ pause: () => animation.pause(),
3789
3823
  stop: () => {
3790
3824
  /**
3791
3825
  * WAAPI doesn't natively have any interruption capabilities.
@@ -3813,8 +3847,11 @@
3813
3847
  onUpdate && onUpdate(keyframes[keyframes.length - 1]);
3814
3848
  onComplete && onComplete();
3815
3849
  return {
3816
- stop: () => { },
3817
- currentTime: 0,
3850
+ time: 0,
3851
+ play: (noop),
3852
+ pause: (noop),
3853
+ stop: (noop),
3854
+ then: Promise.resolve,
3818
3855
  };
3819
3856
  };
3820
3857
  return delayBy
@@ -5566,23 +5603,35 @@
5566
5603
  constructor(animations) {
5567
5604
  this.animations = animations.filter(Boolean);
5568
5605
  }
5606
+ then(onResolve, onReject) {
5607
+ return Promise.all(this.animations).then(onResolve).catch(onReject);
5608
+ }
5569
5609
  /**
5570
5610
  * TODO: Filter out cancelled or stopped animations before returning
5571
5611
  */
5572
- get currentTime() {
5573
- return this.animations[0].currentTime;
5612
+ get time() {
5613
+ return this.animations[0].time;
5574
5614
  }
5575
5615
  /**
5576
- * currentTime assignment could reasonably run every frame, so
5616
+ * time assignment could reasonably run every frame, so
5577
5617
  * we iterate using a normal loop to avoid function creation.
5578
5618
  */
5579
- set currentTime(time) {
5619
+ set time(time) {
5580
5620
  for (let i = 0; i < this.animations.length; i++) {
5581
- this.animations[i].currentTime = time;
5621
+ this.animations[i].time = time;
5582
5622
  }
5583
5623
  }
5624
+ runAll(methodName) {
5625
+ this.animations.forEach((controls) => controls[methodName]());
5626
+ }
5627
+ play() {
5628
+ this.runAll("play");
5629
+ }
5630
+ pause() {
5631
+ this.runAll("pause");
5632
+ }
5584
5633
  stop() {
5585
- this.animations.forEach((controls) => controls.stop());
5634
+ this.runAll("stop");
5586
5635
  }
5587
5636
  }
5588
5637
 
@@ -8394,7 +8443,7 @@
8394
8443
  * and warn against mismatches.
8395
8444
  */
8396
8445
  {
8397
- warnOnce(nextValue.version === "10.2.5", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.2.5 may not work as expected.`);
8446
+ warnOnce(nextValue.version === "10.3.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 10.3.0 may not work as expected.`);
8398
8447
  }
8399
8448
  }
8400
8449
  else if (isMotionValue(prevValue)) {
@@ -10555,7 +10604,7 @@
10555
10604
  */
10556
10605
  sync.update(() => {
10557
10606
  if (value.animation) {
10558
- value.animation.currentTime =
10607
+ value.animation.time =
10559
10608
  performance.now() - millisecondsToSeconds(sampledTime);
10560
10609
  }
10561
10610
  });