motion-dom 12.27.5 → 12.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +116 -59
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/effects/style/transform.mjs +2 -1
- package/dist/es/effects/style/transform.mjs.map +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/render/html/utils/build-transform.mjs +2 -1
- package/dist/es/render/html/utils/build-transform.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs +102 -0
- package/dist/es/value/follow-value.mjs.map +1 -0
- package/dist/es/value/spring-value.mjs +16 -61
- package/dist/es/value/spring-value.mjs.map +1 -1
- package/dist/index.d.ts +50 -3
- package/dist/motion-dom.dev.js +116 -59
- package/dist/motion-dom.js +1 -1
- package/dist/size-rollup-style-effect.js +1 -1
- package/dist/size-rollup-style-effect.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -4067,7 +4067,8 @@ function buildTransform$1(state) {
|
|
|
4067
4067
|
valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
|
|
4068
4068
|
}
|
|
4069
4069
|
else {
|
|
4070
|
-
|
|
4070
|
+
const parsed = parseFloat(value);
|
|
4071
|
+
valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
|
|
4071
4072
|
}
|
|
4072
4073
|
if (!valueIsDefault) {
|
|
4073
4074
|
transformIsDefault = false;
|
|
@@ -4682,6 +4683,101 @@ function transform(...args) {
|
|
|
4682
4683
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
4683
4684
|
}
|
|
4684
4685
|
|
|
4686
|
+
/**
|
|
4687
|
+
* Create a `MotionValue` that animates to its latest value using any transition type.
|
|
4688
|
+
* Can either be a value or track another `MotionValue`.
|
|
4689
|
+
*
|
|
4690
|
+
* ```jsx
|
|
4691
|
+
* const x = motionValue(0)
|
|
4692
|
+
* const y = followValue(x, { type: "spring", stiffness: 300 })
|
|
4693
|
+
* // or with tween
|
|
4694
|
+
* const z = followValue(x, { type: "tween", duration: 0.5, ease: "easeOut" })
|
|
4695
|
+
* ```
|
|
4696
|
+
*
|
|
4697
|
+
* @param source - Initial value or MotionValue to track
|
|
4698
|
+
* @param options - Animation transition options
|
|
4699
|
+
* @returns `MotionValue`
|
|
4700
|
+
*
|
|
4701
|
+
* @public
|
|
4702
|
+
*/
|
|
4703
|
+
function followValue(source, options) {
|
|
4704
|
+
const initialValue = isMotionValue(source) ? source.get() : source;
|
|
4705
|
+
const value = motionValue(initialValue);
|
|
4706
|
+
attachFollow(value, source, options);
|
|
4707
|
+
return value;
|
|
4708
|
+
}
|
|
4709
|
+
/**
|
|
4710
|
+
* Attach an animation to a MotionValue that will animate whenever the value changes.
|
|
4711
|
+
* Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)
|
|
4712
|
+
*
|
|
4713
|
+
* @param value - The MotionValue to animate
|
|
4714
|
+
* @param source - Initial value or MotionValue to track
|
|
4715
|
+
* @param options - Animation transition options
|
|
4716
|
+
* @returns Cleanup function
|
|
4717
|
+
*
|
|
4718
|
+
* @public
|
|
4719
|
+
*/
|
|
4720
|
+
function attachFollow(value, source, options = {}) {
|
|
4721
|
+
const initialValue = value.get();
|
|
4722
|
+
let activeAnimation = null;
|
|
4723
|
+
let latestValue = initialValue;
|
|
4724
|
+
let latestSetter;
|
|
4725
|
+
const unit = typeof initialValue === "string"
|
|
4726
|
+
? initialValue.replace(/[\d.-]/g, "")
|
|
4727
|
+
: undefined;
|
|
4728
|
+
const stopAnimation = () => {
|
|
4729
|
+
if (activeAnimation) {
|
|
4730
|
+
activeAnimation.stop();
|
|
4731
|
+
activeAnimation = null;
|
|
4732
|
+
}
|
|
4733
|
+
};
|
|
4734
|
+
const startAnimation = () => {
|
|
4735
|
+
stopAnimation();
|
|
4736
|
+
const currentValue = asNumber$1(value.get());
|
|
4737
|
+
const targetValue = asNumber$1(latestValue);
|
|
4738
|
+
// Don't animate if we're already at the target
|
|
4739
|
+
if (currentValue === targetValue) {
|
|
4740
|
+
return;
|
|
4741
|
+
}
|
|
4742
|
+
activeAnimation = new JSAnimation({
|
|
4743
|
+
keyframes: [currentValue, targetValue],
|
|
4744
|
+
velocity: value.getVelocity(),
|
|
4745
|
+
// Default to spring if no type specified (matches useSpring behavior)
|
|
4746
|
+
type: "spring",
|
|
4747
|
+
restDelta: 0.001,
|
|
4748
|
+
restSpeed: 0.01,
|
|
4749
|
+
...options,
|
|
4750
|
+
onUpdate: latestSetter,
|
|
4751
|
+
});
|
|
4752
|
+
};
|
|
4753
|
+
value.attach((v, set) => {
|
|
4754
|
+
latestValue = v;
|
|
4755
|
+
latestSetter = (latest) => set(parseValue(latest, unit));
|
|
4756
|
+
frame.postRender(() => {
|
|
4757
|
+
startAnimation();
|
|
4758
|
+
value["events"].animationStart?.notify();
|
|
4759
|
+
activeAnimation?.then(() => {
|
|
4760
|
+
value["events"].animationComplete?.notify();
|
|
4761
|
+
});
|
|
4762
|
+
});
|
|
4763
|
+
}, stopAnimation);
|
|
4764
|
+
if (isMotionValue(source)) {
|
|
4765
|
+
const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
|
|
4766
|
+
const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
|
|
4767
|
+
return () => {
|
|
4768
|
+
removeSourceOnChange();
|
|
4769
|
+
removeValueOnDestroy();
|
|
4770
|
+
};
|
|
4771
|
+
}
|
|
4772
|
+
return stopAnimation;
|
|
4773
|
+
}
|
|
4774
|
+
function parseValue(v, unit) {
|
|
4775
|
+
return unit ? v + unit : v;
|
|
4776
|
+
}
|
|
4777
|
+
function asNumber$1(v) {
|
|
4778
|
+
return typeof v === "number" ? v : parseFloat(v);
|
|
4779
|
+
}
|
|
4780
|
+
|
|
4685
4781
|
function subscribeValue(inputValues, outputValue, getLatest) {
|
|
4686
4782
|
const update = () => outputValue.set(getLatest());
|
|
4687
4783
|
const scheduleUpdate = () => frame.preRender(update, false, true);
|
|
@@ -4771,72 +4867,30 @@ function mapValue(inputValue, inputRange, outputRange, options) {
|
|
|
4771
4867
|
*
|
|
4772
4868
|
* ```jsx
|
|
4773
4869
|
* const x = motionValue(0)
|
|
4774
|
-
* const y =
|
|
4870
|
+
* const y = springValue(x, { stiffness: 300 })
|
|
4775
4871
|
* ```
|
|
4776
4872
|
*
|
|
4777
|
-
* @param
|
|
4873
|
+
* @param source - Initial value or MotionValue to track
|
|
4874
|
+
* @param options - Spring configuration options
|
|
4778
4875
|
* @returns `MotionValue`
|
|
4779
4876
|
*
|
|
4780
4877
|
* @public
|
|
4781
4878
|
*/
|
|
4782
4879
|
function springValue(source, options) {
|
|
4783
|
-
|
|
4784
|
-
const value = motionValue(initialValue);
|
|
4785
|
-
attachSpring(value, source, options);
|
|
4786
|
-
return value;
|
|
4880
|
+
return followValue(source, { type: "spring", ...options });
|
|
4787
4881
|
}
|
|
4882
|
+
/**
|
|
4883
|
+
* Attach a spring animation to a MotionValue that will animate whenever the value changes.
|
|
4884
|
+
*
|
|
4885
|
+
* @param value - The MotionValue to animate
|
|
4886
|
+
* @param source - Initial value or MotionValue to track
|
|
4887
|
+
* @param options - Spring configuration options
|
|
4888
|
+
* @returns Cleanup function
|
|
4889
|
+
*
|
|
4890
|
+
* @public
|
|
4891
|
+
*/
|
|
4788
4892
|
function attachSpring(value, source, options) {
|
|
4789
|
-
|
|
4790
|
-
let activeAnimation = null;
|
|
4791
|
-
let latestValue = initialValue;
|
|
4792
|
-
let latestSetter;
|
|
4793
|
-
const unit = typeof initialValue === "string"
|
|
4794
|
-
? initialValue.replace(/[\d.-]/g, "")
|
|
4795
|
-
: undefined;
|
|
4796
|
-
const stopAnimation = () => {
|
|
4797
|
-
if (activeAnimation) {
|
|
4798
|
-
activeAnimation.stop();
|
|
4799
|
-
activeAnimation = null;
|
|
4800
|
-
}
|
|
4801
|
-
};
|
|
4802
|
-
const startAnimation = () => {
|
|
4803
|
-
stopAnimation();
|
|
4804
|
-
activeAnimation = new JSAnimation({
|
|
4805
|
-
keyframes: [asNumber$1(value.get()), asNumber$1(latestValue)],
|
|
4806
|
-
velocity: value.getVelocity(),
|
|
4807
|
-
type: "spring",
|
|
4808
|
-
restDelta: 0.001,
|
|
4809
|
-
restSpeed: 0.01,
|
|
4810
|
-
...options,
|
|
4811
|
-
onUpdate: latestSetter,
|
|
4812
|
-
});
|
|
4813
|
-
};
|
|
4814
|
-
value.attach((v, set) => {
|
|
4815
|
-
latestValue = v;
|
|
4816
|
-
latestSetter = (latest) => set(parseValue(latest, unit));
|
|
4817
|
-
frame.postRender(() => {
|
|
4818
|
-
startAnimation();
|
|
4819
|
-
value['events'].animationStart?.notify();
|
|
4820
|
-
activeAnimation?.then(() => {
|
|
4821
|
-
value['events'].animationComplete?.notify();
|
|
4822
|
-
});
|
|
4823
|
-
});
|
|
4824
|
-
}, stopAnimation);
|
|
4825
|
-
if (isMotionValue(source)) {
|
|
4826
|
-
const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
|
|
4827
|
-
const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
|
|
4828
|
-
return () => {
|
|
4829
|
-
removeSourceOnChange();
|
|
4830
|
-
removeValueOnDestroy();
|
|
4831
|
-
};
|
|
4832
|
-
}
|
|
4833
|
-
return stopAnimation;
|
|
4834
|
-
}
|
|
4835
|
-
function parseValue(v, unit) {
|
|
4836
|
-
return unit ? v + unit : v;
|
|
4837
|
-
}
|
|
4838
|
-
function asNumber$1(v) {
|
|
4839
|
-
return typeof v === "number" ? v : parseFloat(v);
|
|
4893
|
+
return attachFollow(value, source, { type: "spring", ...options });
|
|
4840
4894
|
}
|
|
4841
4895
|
|
|
4842
4896
|
/**
|
|
@@ -6036,7 +6090,8 @@ function buildTransform(latestValues, transform, transformTemplate) {
|
|
|
6036
6090
|
valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
|
|
6037
6091
|
}
|
|
6038
6092
|
else {
|
|
6039
|
-
|
|
6093
|
+
const parsed = parseFloat(value);
|
|
6094
|
+
valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
|
|
6040
6095
|
}
|
|
6041
6096
|
if (!valueIsDefault || transformTemplate) {
|
|
6042
6097
|
const valueAsType = getValueAsType(value, numberValueTypes[key]);
|
|
@@ -9387,6 +9442,7 @@ exports.applyPointDelta = applyPointDelta;
|
|
|
9387
9442
|
exports.applyPxDefaults = applyPxDefaults;
|
|
9388
9443
|
exports.applyTreeDeltas = applyTreeDeltas;
|
|
9389
9444
|
exports.aspectRatio = aspectRatio;
|
|
9445
|
+
exports.attachFollow = attachFollow;
|
|
9390
9446
|
exports.attachSpring = attachSpring;
|
|
9391
9447
|
exports.attrEffect = attrEffect;
|
|
9392
9448
|
exports.axisDeltaEquals = axisDeltaEquals;
|
|
@@ -9451,6 +9507,7 @@ exports.fillWildcards = fillWildcards;
|
|
|
9451
9507
|
exports.findDimensionValueType = findDimensionValueType;
|
|
9452
9508
|
exports.findValueType = findValueType;
|
|
9453
9509
|
exports.flushKeyframeResolvers = flushKeyframeResolvers;
|
|
9510
|
+
exports.followValue = followValue;
|
|
9454
9511
|
exports.frame = frame;
|
|
9455
9512
|
exports.frameData = frameData;
|
|
9456
9513
|
exports.frameSteps = frameSteps;
|