motion 12.7.5 → 12.8.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.
- package/dist/cjs/index.js +108 -31
- package/dist/cjs/react-client.js +8 -15
- package/dist/cjs/react-m.js +1 -9
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/utils/setters.mjs +5 -1
- package/dist/es/framer-motion/dist/es/value/use-transform.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/utils/resolve-motion-value.mjs +1 -5
- package/dist/es/motion/lib/index.mjs +3 -1
- package/dist/es/motion/lib/react.mjs +3 -1
- package/dist/es/{framer-motion → motion-dom}/dist/es/utils/transform.mjs +2 -9
- package/dist/es/motion-dom/dist/es/value/index.mjs +2 -1
- package/dist/es/motion-dom/dist/es/value/map-value.mjs +46 -0
- package/dist/es/motion-dom/dist/es/value/subscribe-value.mjs +13 -0
- package/dist/es/motion-dom/dist/es/value/transform-value.mjs +35 -0
- package/dist/es/motion-dom/dist/es/value/types/maps/number.mjs +0 -1
- package/dist/motion.dev.js +108 -31
- package/dist/motion.js +1 -1
- package/package.json +3 -3
- package/dist/es/framer-motion/dist/es/utils/resolve-value.mjs +0 -11
package/dist/motion.dev.js
CHANGED
|
@@ -892,7 +892,7 @@
|
|
|
892
892
|
function mixNumber(a, b) {
|
|
893
893
|
return (p) => mixNumber$1(a, b, p);
|
|
894
894
|
}
|
|
895
|
-
function getMixer
|
|
895
|
+
function getMixer(a) {
|
|
896
896
|
if (typeof a === "number") {
|
|
897
897
|
return mixNumber;
|
|
898
898
|
}
|
|
@@ -914,7 +914,7 @@
|
|
|
914
914
|
function mixArray(a, b) {
|
|
915
915
|
const output = [...a];
|
|
916
916
|
const numValues = output.length;
|
|
917
|
-
const blendValue = a.map((v, i) => getMixer
|
|
917
|
+
const blendValue = a.map((v, i) => getMixer(v)(v, b[i]));
|
|
918
918
|
return (p) => {
|
|
919
919
|
for (let i = 0; i < numValues; i++) {
|
|
920
920
|
output[i] = blendValue[i](p);
|
|
@@ -927,7 +927,7 @@
|
|
|
927
927
|
const blendValue = {};
|
|
928
928
|
for (const key in output) {
|
|
929
929
|
if (a[key] !== undefined && b[key] !== undefined) {
|
|
930
|
-
blendValue[key] = getMixer
|
|
930
|
+
blendValue[key] = getMixer(a[key])(a[key], b[key]);
|
|
931
931
|
}
|
|
932
932
|
}
|
|
933
933
|
return (v) => {
|
|
@@ -977,7 +977,7 @@
|
|
|
977
977
|
typeof p === "number") {
|
|
978
978
|
return mixNumber$1(from, to, p);
|
|
979
979
|
}
|
|
980
|
-
const mixer = getMixer
|
|
980
|
+
const mixer = getMixer(from);
|
|
981
981
|
return mixer(from, to);
|
|
982
982
|
}
|
|
983
983
|
|
|
@@ -3085,7 +3085,6 @@
|
|
|
3085
3085
|
backgroundPositionY: px,
|
|
3086
3086
|
...transformValueTypes,
|
|
3087
3087
|
zIndex: int,
|
|
3088
|
-
size: px,
|
|
3089
3088
|
// SVG
|
|
3090
3089
|
fillOpacity: alpha,
|
|
3091
3090
|
strokeOpacity: alpha,
|
|
@@ -3739,6 +3738,17 @@
|
|
|
3739
3738
|
return reportStats;
|
|
3740
3739
|
}
|
|
3741
3740
|
|
|
3741
|
+
function transform(...args) {
|
|
3742
|
+
const useImmediate = !Array.isArray(args[0]);
|
|
3743
|
+
const argOffset = useImmediate ? 0 : -1;
|
|
3744
|
+
const inputValue = args[0 + argOffset];
|
|
3745
|
+
const inputRange = args[1 + argOffset];
|
|
3746
|
+
const outputRange = args[2 + argOffset];
|
|
3747
|
+
const options = args[3 + argOffset];
|
|
3748
|
+
const interpolator = interpolate(inputRange, outputRange, options);
|
|
3749
|
+
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
3750
|
+
}
|
|
3751
|
+
|
|
3742
3752
|
/**
|
|
3743
3753
|
* Maximum time between the value of two frames, beyond which we
|
|
3744
3754
|
* assume the velocity has since been 0.
|
|
@@ -3767,7 +3777,7 @@
|
|
|
3767
3777
|
* This will be replaced by the build step with the latest version number.
|
|
3768
3778
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3769
3779
|
*/
|
|
3770
|
-
this.version = "12.
|
|
3780
|
+
this.version = "12.8.0";
|
|
3771
3781
|
/**
|
|
3772
3782
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
3773
3783
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -4036,6 +4046,7 @@
|
|
|
4036
4046
|
* @public
|
|
4037
4047
|
*/
|
|
4038
4048
|
destroy() {
|
|
4049
|
+
this.events.destroy?.notify();
|
|
4039
4050
|
this.clearListeners();
|
|
4040
4051
|
this.stop();
|
|
4041
4052
|
if (this.stopPassiveEffect) {
|
|
@@ -4047,6 +4058,89 @@
|
|
|
4047
4058
|
return new MotionValue(init, options);
|
|
4048
4059
|
}
|
|
4049
4060
|
|
|
4061
|
+
function subscribeValue(inputValues, outputValue, getLatest) {
|
|
4062
|
+
const update = () => outputValue.set(getLatest());
|
|
4063
|
+
const scheduleUpdate = () => frame.preRender(update, false, true);
|
|
4064
|
+
const subscriptions = inputValues.map((v) => v.on("change", scheduleUpdate));
|
|
4065
|
+
outputValue.on("destroy", () => {
|
|
4066
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
4067
|
+
cancelFrame(update);
|
|
4068
|
+
});
|
|
4069
|
+
}
|
|
4070
|
+
|
|
4071
|
+
/**
|
|
4072
|
+
* Create a `MotionValue` that transforms the output of other `MotionValue`s by
|
|
4073
|
+
* passing their latest values through a transform function.
|
|
4074
|
+
*
|
|
4075
|
+
* Whenever a `MotionValue` referred to in the provided function is updated,
|
|
4076
|
+
* it will be re-evaluated.
|
|
4077
|
+
*
|
|
4078
|
+
* ```jsx
|
|
4079
|
+
* const x = motionValue(0)
|
|
4080
|
+
* const y = transformValue(() => x.get() * 2) // double x
|
|
4081
|
+
* ```
|
|
4082
|
+
*
|
|
4083
|
+
* @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
|
|
4084
|
+
* @returns `MotionValue`
|
|
4085
|
+
*
|
|
4086
|
+
* @public
|
|
4087
|
+
*/
|
|
4088
|
+
function transformValue(transform) {
|
|
4089
|
+
const collectedValues = [];
|
|
4090
|
+
/**
|
|
4091
|
+
* Open session of collectMotionValues. Any MotionValue that calls get()
|
|
4092
|
+
* inside transform will be saved into this array.
|
|
4093
|
+
*/
|
|
4094
|
+
collectMotionValues.current = collectedValues;
|
|
4095
|
+
const initialValue = transform();
|
|
4096
|
+
collectMotionValues.current = undefined;
|
|
4097
|
+
const value = motionValue(initialValue);
|
|
4098
|
+
subscribeValue(collectedValues, value, transform);
|
|
4099
|
+
return value;
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
/**
|
|
4103
|
+
* Create a `MotionValue` that maps the output of another `MotionValue` by
|
|
4104
|
+
* mapping it from one range of values into another.
|
|
4105
|
+
*
|
|
4106
|
+
* @remarks
|
|
4107
|
+
*
|
|
4108
|
+
* Given an input range of `[-200, -100, 100, 200]` and an output range of
|
|
4109
|
+
* `[0, 1, 1, 0]`, the returned `MotionValue` will:
|
|
4110
|
+
*
|
|
4111
|
+
* - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
|
|
4112
|
+
* - When provided a value between `-100` and `100`, will return `1`.
|
|
4113
|
+
* - When provided a value between `100` and `200`, will return a value between `1` and `0`
|
|
4114
|
+
*
|
|
4115
|
+
* The input range must be a linear series of numbers. The output range
|
|
4116
|
+
* can be any value type supported by Motion: numbers, colors, shadows, etc.
|
|
4117
|
+
*
|
|
4118
|
+
* Every value in the output range must be of the same type and in the same format.
|
|
4119
|
+
*
|
|
4120
|
+
* ```jsx
|
|
4121
|
+
* const x = motionValue(0)
|
|
4122
|
+
* const xRange = [-200, -100, 100, 200]
|
|
4123
|
+
* const opacityRange = [0, 1, 1, 0]
|
|
4124
|
+
* const opacity = mapValue(x, xRange, opacityRange)
|
|
4125
|
+
* ```
|
|
4126
|
+
*
|
|
4127
|
+
* @param inputValue - `MotionValue`
|
|
4128
|
+
* @param inputRange - A linear series of numbers (either all increasing or decreasing)
|
|
4129
|
+
* @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
|
|
4130
|
+
* @param options -
|
|
4131
|
+
*
|
|
4132
|
+
* - clamp: boolean. Clamp values to within the given range. Defaults to `true`
|
|
4133
|
+
* - ease: EasingFunction[]. Easing functions to use on the interpolations between each value in the input and output ranges. If provided as an array, the array must be one item shorter than the input and output ranges, as the easings apply to the transition between each.
|
|
4134
|
+
*
|
|
4135
|
+
* @returns `MotionValue`
|
|
4136
|
+
*
|
|
4137
|
+
* @public
|
|
4138
|
+
*/
|
|
4139
|
+
function mapValue(inputValue, inputRange, outputRange, options) {
|
|
4140
|
+
const map = transform(inputRange, outputRange, options);
|
|
4141
|
+
return transformValue(() => map(inputValue.get()));
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4050
4144
|
/**
|
|
4051
4145
|
* A list of all ValueTypes
|
|
4052
4146
|
*/
|
|
@@ -4732,11 +4826,6 @@
|
|
|
4732
4826
|
return Array.isArray(v);
|
|
4733
4827
|
};
|
|
4734
4828
|
|
|
4735
|
-
const resolveFinalValueInKeyframes = (v) => {
|
|
4736
|
-
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
4737
|
-
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
4738
|
-
};
|
|
4739
|
-
|
|
4740
4829
|
function getValueState(visualElement) {
|
|
4741
4830
|
const state = [{}, {}];
|
|
4742
4831
|
visualElement?.values.forEach((value, key) => {
|
|
@@ -4789,6 +4878,10 @@
|
|
|
4789
4878
|
visualElement.addValue(key, motionValue(value));
|
|
4790
4879
|
}
|
|
4791
4880
|
}
|
|
4881
|
+
function resolveFinalValueInKeyframes(v) {
|
|
4882
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
4883
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
4884
|
+
}
|
|
4792
4885
|
function setTarget(visualElement, definition) {
|
|
4793
4886
|
const resolved = resolveVariant(visualElement, definition);
|
|
4794
4887
|
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
|
|
@@ -5147,7 +5240,7 @@
|
|
|
5147
5240
|
* and warn against mismatches.
|
|
5148
5241
|
*/
|
|
5149
5242
|
{
|
|
5150
|
-
warnOnce(nextValue.version === "12.
|
|
5243
|
+
warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
|
|
5151
5244
|
}
|
|
5152
5245
|
}
|
|
5153
5246
|
else if (isMotionValue(prevValue)) {
|
|
@@ -6976,24 +7069,6 @@
|
|
|
6976
7069
|
return Math.sqrt(xDelta ** 2 + yDelta ** 2);
|
|
6977
7070
|
}
|
|
6978
7071
|
|
|
6979
|
-
const isCustomValueType = (v) => {
|
|
6980
|
-
return v && typeof v === "object" && v.mix;
|
|
6981
|
-
};
|
|
6982
|
-
const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
|
|
6983
|
-
function transform(...args) {
|
|
6984
|
-
const useImmediate = !Array.isArray(args[0]);
|
|
6985
|
-
const argOffset = useImmediate ? 0 : -1;
|
|
6986
|
-
const inputValue = args[0 + argOffset];
|
|
6987
|
-
const inputRange = args[1 + argOffset];
|
|
6988
|
-
const outputRange = args[2 + argOffset];
|
|
6989
|
-
const options = args[3 + argOffset];
|
|
6990
|
-
const interpolator = interpolate(inputRange, outputRange, {
|
|
6991
|
-
mixer: getMixer(outputRange[0]),
|
|
6992
|
-
...options,
|
|
6993
|
-
});
|
|
6994
|
-
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
6995
|
-
}
|
|
6996
|
-
|
|
6997
7072
|
exports.AsyncMotionValueAnimation = AsyncMotionValueAnimation;
|
|
6998
7073
|
exports.DOMKeyframesResolver = DOMKeyframesResolver;
|
|
6999
7074
|
exports.GroupAnimation = GroupAnimation;
|
|
@@ -7065,7 +7140,7 @@
|
|
|
7065
7140
|
exports.getComputedStyle = getComputedStyle$2;
|
|
7066
7141
|
exports.getDefaultValueType = getDefaultValueType;
|
|
7067
7142
|
exports.getEasingForSegment = getEasingForSegment;
|
|
7068
|
-
exports.getMixer = getMixer
|
|
7143
|
+
exports.getMixer = getMixer;
|
|
7069
7144
|
exports.getValueAsType = getValueAsType;
|
|
7070
7145
|
exports.getValueTransition = getValueTransition$1;
|
|
7071
7146
|
exports.getVariableValue = getVariableValue;
|
|
@@ -7092,6 +7167,7 @@
|
|
|
7092
7167
|
exports.isZeroValueString = isZeroValueString;
|
|
7093
7168
|
exports.keyframes = keyframes;
|
|
7094
7169
|
exports.mapEasingToNativeEasing = mapEasingToNativeEasing;
|
|
7170
|
+
exports.mapValue = mapValue;
|
|
7095
7171
|
exports.maxGeneratorDuration = maxGeneratorDuration;
|
|
7096
7172
|
exports.memo = memo;
|
|
7097
7173
|
exports.microtask = microtask;
|
|
@@ -7151,6 +7227,7 @@
|
|
|
7151
7227
|
exports.transform = transform;
|
|
7152
7228
|
exports.transformPropOrder = transformPropOrder;
|
|
7153
7229
|
exports.transformProps = transformProps;
|
|
7230
|
+
exports.transformValue = transformValue;
|
|
7154
7231
|
exports.transformValueTypes = transformValueTypes;
|
|
7155
7232
|
exports.velocityPerSecond = velocityPerSecond;
|
|
7156
7233
|
exports.vh = vh;
|