framer-motion 12.12.2 → 12.13.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.
@@ -1682,12 +1682,10 @@
1682
1682
  * This method is bound to the instance to fix a pattern where
1683
1683
  * animation.stop is returned as a reference from a useEffect.
1684
1684
  */
1685
- this.stop = (sync = true) => {
1686
- if (sync) {
1687
- const { motionValue } = this.options;
1688
- if (motionValue && motionValue.updatedAt !== time.now()) {
1689
- this.tick(time.now());
1690
- }
1685
+ this.stop = () => {
1686
+ const { motionValue } = this.options;
1687
+ if (motionValue && motionValue.updatedAt !== time.now()) {
1688
+ this.tick(time.now());
1691
1689
  }
1692
1690
  this.isStopped = true;
1693
1691
  if (this.state === "idle")
@@ -3429,22 +3427,6 @@
3429
3427
  // "background-color"
3430
3428
  ]);
3431
3429
 
3432
- function resolveElements(elementOrSelector, scope, selectorCache) {
3433
- if (elementOrSelector instanceof EventTarget) {
3434
- return [elementOrSelector];
3435
- }
3436
- else if (typeof elementOrSelector === "string") {
3437
- let root = document;
3438
- if (scope) {
3439
- root = scope.current;
3440
- }
3441
- const elements = selectorCache?.[elementOrSelector] ??
3442
- root.querySelectorAll(elementOrSelector);
3443
- return elements ? Array.from(elements) : [];
3444
- }
3445
- return Array.from(elementOrSelector);
3446
- }
3447
-
3448
3430
  /**
3449
3431
  * Maximum time between the value of two frames, beyond which we
3450
3432
  * assume the velocity has since been 0.
@@ -3767,6 +3749,37 @@
3767
3749
  return new MotionValue(init, options);
3768
3750
  }
3769
3751
 
3752
+ function resolveElements(elementOrSelector, scope, selectorCache) {
3753
+ if (elementOrSelector instanceof EventTarget) {
3754
+ return [elementOrSelector];
3755
+ }
3756
+ else if (typeof elementOrSelector === "string") {
3757
+ let root = document;
3758
+ if (scope) {
3759
+ root = scope.current;
3760
+ }
3761
+ const elements = selectorCache?.[elementOrSelector] ??
3762
+ root.querySelectorAll(elementOrSelector);
3763
+ return elements ? Array.from(elements) : [];
3764
+ }
3765
+ return Array.from(elementOrSelector);
3766
+ }
3767
+
3768
+ function createSelectorEffect(subjectEffect) {
3769
+ return (subject, values) => {
3770
+ const elements = resolveElements(subject);
3771
+ const subscriptions = [];
3772
+ for (const element of elements) {
3773
+ const remove = subjectEffect(element, values);
3774
+ subscriptions.push(remove);
3775
+ }
3776
+ return () => {
3777
+ for (const remove of subscriptions)
3778
+ remove();
3779
+ };
3780
+ };
3781
+ }
3782
+
3770
3783
  /**
3771
3784
  * Provided a value and a ValueType, returns the value as that value type.
3772
3785
  */
@@ -3781,13 +3794,19 @@
3781
3794
  this.latest = {};
3782
3795
  this.values = new Map();
3783
3796
  }
3784
- set(name, value, render, computed) {
3797
+ set(name, value, render, computed, useDefaultValueType = true) {
3785
3798
  const existingValue = this.values.get(name);
3786
3799
  if (existingValue) {
3787
3800
  existingValue.onRemove();
3788
3801
  }
3789
3802
  const onChange = () => {
3790
- this.latest[name] = getValueAsType(value.get(), numberValueTypes[name]);
3803
+ const v = value.get();
3804
+ if (useDefaultValueType) {
3805
+ this.latest[name] = getValueAsType(v, numberValueTypes[name]);
3806
+ }
3807
+ else {
3808
+ this.latest[name] = v;
3809
+ }
3791
3810
  render && frame.render(render);
3792
3811
  };
3793
3812
  onChange();
@@ -3812,6 +3831,24 @@
3812
3831
  }
3813
3832
  }
3814
3833
 
3834
+ function createEffect(addValue) {
3835
+ const stateCache = new WeakMap();
3836
+ const subscriptions = [];
3837
+ return (subject, values) => {
3838
+ const state = stateCache.get(subject) ?? new MotionValueState();
3839
+ stateCache.set(subject, state);
3840
+ for (const key in values) {
3841
+ const value = values[key];
3842
+ const remove = addValue(subject, state, key, value);
3843
+ subscriptions.push(remove);
3844
+ }
3845
+ return () => {
3846
+ for (const cancel of subscriptions)
3847
+ cancel();
3848
+ };
3849
+ };
3850
+ }
3851
+
3815
3852
  const translateAlias$1 = {
3816
3853
  x: "translateX",
3817
3854
  y: "translateY",
@@ -3847,26 +3884,7 @@
3847
3884
  return transformIsDefault ? "none" : transform.trim();
3848
3885
  }
3849
3886
 
3850
- const stateMap = new WeakMap();
3851
- function styleEffect(subject, values) {
3852
- const elements = resolveElements(subject);
3853
- const subscriptions = [];
3854
- for (let i = 0; i < elements.length; i++) {
3855
- const element = elements[i];
3856
- const state = stateMap.get(element) ?? new MotionValueState();
3857
- stateMap.set(element, state);
3858
- for (const key in values) {
3859
- const value = values[key];
3860
- const remove = addValue(element, state, key, value);
3861
- subscriptions.push(remove);
3862
- }
3863
- }
3864
- return () => {
3865
- for (const cancel of subscriptions)
3866
- cancel();
3867
- };
3868
- }
3869
- function addValue(element, state, key, value) {
3887
+ const addStyleValue = (element, state, key, value) => {
3870
3888
  let render = undefined;
3871
3889
  let computed = undefined;
3872
3890
  if (transformProps.has(key)) {
@@ -3888,7 +3906,8 @@
3888
3906
  };
3889
3907
  }
3890
3908
  return state.set(key, value, render, computed);
3891
- }
3909
+ };
3910
+ const styleEffect = createSelectorEffect(createEffect(addStyleValue));
3892
3911
 
3893
3912
  const { schedule: microtask, cancel: cancelMicrotask } =
3894
3913
  /* @__PURE__ */ createRenderBatcher(queueMicrotask, false);
@@ -6262,7 +6281,6 @@
6262
6281
  this.resumingFrom = this.resumeFrom;
6263
6282
  this.resumingFrom.resumingFrom = undefined;
6264
6283
  }
6265
- this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
6266
6284
  const animationOptions = {
6267
6285
  ...getValueTransition$1(layoutTransition, "layout"),
6268
6286
  onPlay: onLayoutAnimationStart,
@@ -6274,6 +6292,11 @@
6274
6292
  animationOptions.type = false;
6275
6293
  }
6276
6294
  this.startAnimation(animationOptions);
6295
+ /**
6296
+ * Set animation origin after starting animation to avoid layout jump
6297
+ * caused by stopping previous layout animation
6298
+ */
6299
+ this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
6277
6300
  }
6278
6301
  else {
6279
6302
  /**
@@ -7009,8 +7032,8 @@
7009
7032
  }
7010
7033
  startAnimation(options) {
7011
7034
  this.notifyListeners("animationStart");
7012
- this.currentAnimation?.stop(false);
7013
- this.resumingFrom?.currentAnimation?.stop(false);
7035
+ this.currentAnimation?.stop();
7036
+ this.resumingFrom?.currentAnimation?.stop();
7014
7037
  if (this.pendingAnimation) {
7015
7038
  cancelFrame(this.pendingAnimation);
7016
7039
  this.pendingAnimation = undefined;
@@ -7062,7 +7085,7 @@
7062
7085
  finishAnimation() {
7063
7086
  if (this.currentAnimation) {
7064
7087
  this.mixTargetDelta && this.mixTargetDelta(animationTarget);
7065
- this.currentAnimation.stop(false);
7088
+ this.currentAnimation.stop();
7066
7089
  }
7067
7090
  this.completeAnimation();
7068
7091
  }
@@ -7327,7 +7350,7 @@
7327
7350
  }
7328
7351
  // Only run on root
7329
7352
  resetTree() {
7330
- this.root.nodes.forEach((node) => node.currentAnimation?.stop(false));
7353
+ this.root.nodes.forEach((node) => node.currentAnimation?.stop());
7331
7354
  this.root.nodes.forEach(clearMeasurements);
7332
7355
  this.root.sharedNodes.clear();
7333
7356
  }
@@ -13794,6 +13817,7 @@
13794
13817
  exports.addPointerEvent = addPointerEvent;
13795
13818
  exports.addPointerInfo = addPointerInfo;
13796
13819
  exports.addScaleCorrector = addScaleCorrector;
13820
+ exports.addStyleValue = addStyleValue;
13797
13821
  exports.addUniqueItem = addUniqueItem;
13798
13822
  exports.alpha = alpha;
13799
13823
  exports.analyseComplexValue = analyseComplexValue;