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/cjs/index.js
CHANGED
|
@@ -890,7 +890,7 @@ function mixVisibility(origin, target) {
|
|
|
890
890
|
function mixNumber(a, b) {
|
|
891
891
|
return (p) => mixNumber$1(a, b, p);
|
|
892
892
|
}
|
|
893
|
-
function getMixer
|
|
893
|
+
function getMixer(a) {
|
|
894
894
|
if (typeof a === "number") {
|
|
895
895
|
return mixNumber;
|
|
896
896
|
}
|
|
@@ -912,7 +912,7 @@ function getMixer$1(a) {
|
|
|
912
912
|
function mixArray(a, b) {
|
|
913
913
|
const output = [...a];
|
|
914
914
|
const numValues = output.length;
|
|
915
|
-
const blendValue = a.map((v, i) => getMixer
|
|
915
|
+
const blendValue = a.map((v, i) => getMixer(v)(v, b[i]));
|
|
916
916
|
return (p) => {
|
|
917
917
|
for (let i = 0; i < numValues; i++) {
|
|
918
918
|
output[i] = blendValue[i](p);
|
|
@@ -925,7 +925,7 @@ function mixObject(a, b) {
|
|
|
925
925
|
const blendValue = {};
|
|
926
926
|
for (const key in output) {
|
|
927
927
|
if (a[key] !== undefined && b[key] !== undefined) {
|
|
928
|
-
blendValue[key] = getMixer
|
|
928
|
+
blendValue[key] = getMixer(a[key])(a[key], b[key]);
|
|
929
929
|
}
|
|
930
930
|
}
|
|
931
931
|
return (v) => {
|
|
@@ -975,7 +975,7 @@ function mix(from, to, p) {
|
|
|
975
975
|
typeof p === "number") {
|
|
976
976
|
return mixNumber$1(from, to, p);
|
|
977
977
|
}
|
|
978
|
-
const mixer = getMixer
|
|
978
|
+
const mixer = getMixer(from);
|
|
979
979
|
return mixer(from, to);
|
|
980
980
|
}
|
|
981
981
|
|
|
@@ -3084,7 +3084,6 @@ const numberValueTypes = {
|
|
|
3084
3084
|
backgroundPositionY: px,
|
|
3085
3085
|
...transformValueTypes,
|
|
3086
3086
|
zIndex: int,
|
|
3087
|
-
size: px,
|
|
3088
3087
|
// SVG
|
|
3089
3088
|
fillOpacity: alpha,
|
|
3090
3089
|
strokeOpacity: alpha,
|
|
@@ -3738,6 +3737,17 @@ function recordStats() {
|
|
|
3738
3737
|
return reportStats;
|
|
3739
3738
|
}
|
|
3740
3739
|
|
|
3740
|
+
function transform(...args) {
|
|
3741
|
+
const useImmediate = !Array.isArray(args[0]);
|
|
3742
|
+
const argOffset = useImmediate ? 0 : -1;
|
|
3743
|
+
const inputValue = args[0 + argOffset];
|
|
3744
|
+
const inputRange = args[1 + argOffset];
|
|
3745
|
+
const outputRange = args[2 + argOffset];
|
|
3746
|
+
const options = args[3 + argOffset];
|
|
3747
|
+
const interpolator = interpolate(inputRange, outputRange, options);
|
|
3748
|
+
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3741
3751
|
/**
|
|
3742
3752
|
* Maximum time between the value of two frames, beyond which we
|
|
3743
3753
|
* assume the velocity has since been 0.
|
|
@@ -3766,7 +3776,7 @@ class MotionValue {
|
|
|
3766
3776
|
* This will be replaced by the build step with the latest version number.
|
|
3767
3777
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3768
3778
|
*/
|
|
3769
|
-
this.version = "12.
|
|
3779
|
+
this.version = "12.8.0";
|
|
3770
3780
|
/**
|
|
3771
3781
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
3772
3782
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -4035,6 +4045,7 @@ class MotionValue {
|
|
|
4035
4045
|
* @public
|
|
4036
4046
|
*/
|
|
4037
4047
|
destroy() {
|
|
4048
|
+
this.events.destroy?.notify();
|
|
4038
4049
|
this.clearListeners();
|
|
4039
4050
|
this.stop();
|
|
4040
4051
|
if (this.stopPassiveEffect) {
|
|
@@ -4046,6 +4057,89 @@ function motionValue(init, options) {
|
|
|
4046
4057
|
return new MotionValue(init, options);
|
|
4047
4058
|
}
|
|
4048
4059
|
|
|
4060
|
+
function subscribeValue(inputValues, outputValue, getLatest) {
|
|
4061
|
+
const update = () => outputValue.set(getLatest());
|
|
4062
|
+
const scheduleUpdate = () => frame.preRender(update, false, true);
|
|
4063
|
+
const subscriptions = inputValues.map((v) => v.on("change", scheduleUpdate));
|
|
4064
|
+
outputValue.on("destroy", () => {
|
|
4065
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
4066
|
+
cancelFrame(update);
|
|
4067
|
+
});
|
|
4068
|
+
}
|
|
4069
|
+
|
|
4070
|
+
/**
|
|
4071
|
+
* Create a `MotionValue` that transforms the output of other `MotionValue`s by
|
|
4072
|
+
* passing their latest values through a transform function.
|
|
4073
|
+
*
|
|
4074
|
+
* Whenever a `MotionValue` referred to in the provided function is updated,
|
|
4075
|
+
* it will be re-evaluated.
|
|
4076
|
+
*
|
|
4077
|
+
* ```jsx
|
|
4078
|
+
* const x = motionValue(0)
|
|
4079
|
+
* const y = transformValue(() => x.get() * 2) // double x
|
|
4080
|
+
* ```
|
|
4081
|
+
*
|
|
4082
|
+
* @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
|
|
4083
|
+
* @returns `MotionValue`
|
|
4084
|
+
*
|
|
4085
|
+
* @public
|
|
4086
|
+
*/
|
|
4087
|
+
function transformValue(transform) {
|
|
4088
|
+
const collectedValues = [];
|
|
4089
|
+
/**
|
|
4090
|
+
* Open session of collectMotionValues. Any MotionValue that calls get()
|
|
4091
|
+
* inside transform will be saved into this array.
|
|
4092
|
+
*/
|
|
4093
|
+
collectMotionValues.current = collectedValues;
|
|
4094
|
+
const initialValue = transform();
|
|
4095
|
+
collectMotionValues.current = undefined;
|
|
4096
|
+
const value = motionValue(initialValue);
|
|
4097
|
+
subscribeValue(collectedValues, value, transform);
|
|
4098
|
+
return value;
|
|
4099
|
+
}
|
|
4100
|
+
|
|
4101
|
+
/**
|
|
4102
|
+
* Create a `MotionValue` that maps the output of another `MotionValue` by
|
|
4103
|
+
* mapping it from one range of values into another.
|
|
4104
|
+
*
|
|
4105
|
+
* @remarks
|
|
4106
|
+
*
|
|
4107
|
+
* Given an input range of `[-200, -100, 100, 200]` and an output range of
|
|
4108
|
+
* `[0, 1, 1, 0]`, the returned `MotionValue` will:
|
|
4109
|
+
*
|
|
4110
|
+
* - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
|
|
4111
|
+
* - When provided a value between `-100` and `100`, will return `1`.
|
|
4112
|
+
* - When provided a value between `100` and `200`, will return a value between `1` and `0`
|
|
4113
|
+
*
|
|
4114
|
+
* The input range must be a linear series of numbers. The output range
|
|
4115
|
+
* can be any value type supported by Motion: numbers, colors, shadows, etc.
|
|
4116
|
+
*
|
|
4117
|
+
* Every value in the output range must be of the same type and in the same format.
|
|
4118
|
+
*
|
|
4119
|
+
* ```jsx
|
|
4120
|
+
* const x = motionValue(0)
|
|
4121
|
+
* const xRange = [-200, -100, 100, 200]
|
|
4122
|
+
* const opacityRange = [0, 1, 1, 0]
|
|
4123
|
+
* const opacity = mapValue(x, xRange, opacityRange)
|
|
4124
|
+
* ```
|
|
4125
|
+
*
|
|
4126
|
+
* @param inputValue - `MotionValue`
|
|
4127
|
+
* @param inputRange - A linear series of numbers (either all increasing or decreasing)
|
|
4128
|
+
* @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
|
|
4129
|
+
* @param options -
|
|
4130
|
+
*
|
|
4131
|
+
* - clamp: boolean. Clamp values to within the given range. Defaults to `true`
|
|
4132
|
+
* - 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.
|
|
4133
|
+
*
|
|
4134
|
+
* @returns `MotionValue`
|
|
4135
|
+
*
|
|
4136
|
+
* @public
|
|
4137
|
+
*/
|
|
4138
|
+
function mapValue(inputValue, inputRange, outputRange, options) {
|
|
4139
|
+
const map = transform(inputRange, outputRange, options);
|
|
4140
|
+
return transformValue(() => map(inputValue.get()));
|
|
4141
|
+
}
|
|
4142
|
+
|
|
4049
4143
|
/**
|
|
4050
4144
|
* A list of all ValueTypes
|
|
4051
4145
|
*/
|
|
@@ -4731,11 +4825,6 @@ const isKeyframesTarget = (v) => {
|
|
|
4731
4825
|
return Array.isArray(v);
|
|
4732
4826
|
};
|
|
4733
4827
|
|
|
4734
|
-
const resolveFinalValueInKeyframes = (v) => {
|
|
4735
|
-
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
4736
|
-
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
4737
|
-
};
|
|
4738
|
-
|
|
4739
4828
|
function getValueState(visualElement) {
|
|
4740
4829
|
const state = [{}, {}];
|
|
4741
4830
|
visualElement?.values.forEach((value, key) => {
|
|
@@ -4788,6 +4877,10 @@ function setMotionValue(visualElement, key, value) {
|
|
|
4788
4877
|
visualElement.addValue(key, motionValue(value));
|
|
4789
4878
|
}
|
|
4790
4879
|
}
|
|
4880
|
+
function resolveFinalValueInKeyframes(v) {
|
|
4881
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
4882
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
4883
|
+
}
|
|
4791
4884
|
function setTarget(visualElement, definition) {
|
|
4792
4885
|
const resolved = resolveVariant(visualElement, definition);
|
|
4793
4886
|
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
|
|
@@ -5146,7 +5239,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
5146
5239
|
* and warn against mismatches.
|
|
5147
5240
|
*/
|
|
5148
5241
|
if (process.env.NODE_ENV === "development") {
|
|
5149
|
-
warnOnce(nextValue.version === "12.
|
|
5242
|
+
warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
|
|
5150
5243
|
}
|
|
5151
5244
|
}
|
|
5152
5245
|
else if (isMotionValue(prevValue)) {
|
|
@@ -6975,24 +7068,6 @@ function distance2D(a, b) {
|
|
|
6975
7068
|
return Math.sqrt(xDelta ** 2 + yDelta ** 2);
|
|
6976
7069
|
}
|
|
6977
7070
|
|
|
6978
|
-
const isCustomValueType = (v) => {
|
|
6979
|
-
return v && typeof v === "object" && v.mix;
|
|
6980
|
-
};
|
|
6981
|
-
const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
|
|
6982
|
-
function transform(...args) {
|
|
6983
|
-
const useImmediate = !Array.isArray(args[0]);
|
|
6984
|
-
const argOffset = useImmediate ? 0 : -1;
|
|
6985
|
-
const inputValue = args[0 + argOffset];
|
|
6986
|
-
const inputRange = args[1 + argOffset];
|
|
6987
|
-
const outputRange = args[2 + argOffset];
|
|
6988
|
-
const options = args[3 + argOffset];
|
|
6989
|
-
const interpolator = interpolate(inputRange, outputRange, {
|
|
6990
|
-
mixer: getMixer(outputRange[0]),
|
|
6991
|
-
...options,
|
|
6992
|
-
});
|
|
6993
|
-
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
6994
|
-
}
|
|
6995
|
-
|
|
6996
7071
|
exports.AsyncMotionValueAnimation = AsyncMotionValueAnimation;
|
|
6997
7072
|
exports.DOMKeyframesResolver = DOMKeyframesResolver;
|
|
6998
7073
|
exports.GroupAnimation = GroupAnimation;
|
|
@@ -7064,7 +7139,7 @@ exports.getAnimationMap = getAnimationMap;
|
|
|
7064
7139
|
exports.getComputedStyle = getComputedStyle$2;
|
|
7065
7140
|
exports.getDefaultValueType = getDefaultValueType;
|
|
7066
7141
|
exports.getEasingForSegment = getEasingForSegment;
|
|
7067
|
-
exports.getMixer = getMixer
|
|
7142
|
+
exports.getMixer = getMixer;
|
|
7068
7143
|
exports.getValueAsType = getValueAsType;
|
|
7069
7144
|
exports.getValueTransition = getValueTransition$1;
|
|
7070
7145
|
exports.getVariableValue = getVariableValue;
|
|
@@ -7091,6 +7166,7 @@ exports.isWaapiSupportedEasing = isWaapiSupportedEasing;
|
|
|
7091
7166
|
exports.isZeroValueString = isZeroValueString;
|
|
7092
7167
|
exports.keyframes = keyframes;
|
|
7093
7168
|
exports.mapEasingToNativeEasing = mapEasingToNativeEasing;
|
|
7169
|
+
exports.mapValue = mapValue;
|
|
7094
7170
|
exports.maxGeneratorDuration = maxGeneratorDuration;
|
|
7095
7171
|
exports.memo = memo;
|
|
7096
7172
|
exports.microtask = microtask;
|
|
@@ -7150,6 +7226,7 @@ exports.time = time;
|
|
|
7150
7226
|
exports.transform = transform;
|
|
7151
7227
|
exports.transformPropOrder = transformPropOrder;
|
|
7152
7228
|
exports.transformProps = transformProps;
|
|
7229
|
+
exports.transformValue = transformValue;
|
|
7153
7230
|
exports.transformValueTypes = transformValueTypes;
|
|
7154
7231
|
exports.velocityPerSecond = velocityPerSecond;
|
|
7155
7232
|
exports.vh = vh;
|
package/dist/cjs/react-client.js
CHANGED
|
@@ -2983,7 +2983,6 @@ const numberValueTypes = {
|
|
|
2983
2983
|
backgroundPositionY: px,
|
|
2984
2984
|
...transformValueTypes,
|
|
2985
2985
|
zIndex: int,
|
|
2986
|
-
size: px,
|
|
2987
2986
|
// SVG
|
|
2988
2987
|
fillOpacity: alpha,
|
|
2989
2988
|
strokeOpacity: alpha,
|
|
@@ -3450,7 +3449,7 @@ class MotionValue {
|
|
|
3450
3449
|
* This will be replaced by the build step with the latest version number.
|
|
3451
3450
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3452
3451
|
*/
|
|
3453
|
-
this.version = "12.
|
|
3452
|
+
this.version = "12.8.0";
|
|
3454
3453
|
/**
|
|
3455
3454
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
3456
3455
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -3716,6 +3715,7 @@ class MotionValue {
|
|
|
3716
3715
|
* @public
|
|
3717
3716
|
*/
|
|
3718
3717
|
destroy() {
|
|
3718
|
+
this.events.destroy?.notify();
|
|
3719
3719
|
this.clearListeners();
|
|
3720
3720
|
this.stop();
|
|
3721
3721
|
if (this.stopPassiveEffect) {
|
|
@@ -3749,14 +3749,6 @@ const isKeyframesTarget = (v) => {
|
|
|
3749
3749
|
return Array.isArray(v);
|
|
3750
3750
|
};
|
|
3751
3751
|
|
|
3752
|
-
const isCustomValue = (v) => {
|
|
3753
|
-
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
3754
|
-
};
|
|
3755
|
-
const resolveFinalValueInKeyframes = (v) => {
|
|
3756
|
-
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
3757
|
-
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
3758
|
-
};
|
|
3759
|
-
|
|
3760
3752
|
/**
|
|
3761
3753
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
3762
3754
|
* it doesn't exist.
|
|
@@ -3769,6 +3761,10 @@ function setMotionValue(visualElement, key, value) {
|
|
|
3769
3761
|
visualElement.addValue(key, motionValue(value));
|
|
3770
3762
|
}
|
|
3771
3763
|
}
|
|
3764
|
+
function resolveFinalValueInKeyframes(v) {
|
|
3765
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
3766
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
3767
|
+
}
|
|
3772
3768
|
function setTarget(visualElement, definition) {
|
|
3773
3769
|
const resolved = resolveVariant(visualElement, definition);
|
|
3774
3770
|
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
|
|
@@ -5989,10 +5985,7 @@ function delay(callback, timeout) {
|
|
|
5989
5985
|
* TODO: Remove and move to library
|
|
5990
5986
|
*/
|
|
5991
5987
|
function resolveMotionValue(value) {
|
|
5992
|
-
|
|
5993
|
-
return isCustomValue(unwrappedValue)
|
|
5994
|
-
? unwrappedValue.toValue()
|
|
5995
|
-
: unwrappedValue;
|
|
5988
|
+
return isMotionValue(value) ? value.get() : value;
|
|
5996
5989
|
}
|
|
5997
5990
|
|
|
5998
5991
|
const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
|
|
@@ -9239,7 +9232,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
9239
9232
|
* and warn against mismatches.
|
|
9240
9233
|
*/
|
|
9241
9234
|
if (process.env.NODE_ENV === "development") {
|
|
9242
|
-
warnOnce(nextValue.version === "12.
|
|
9235
|
+
warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
|
|
9243
9236
|
}
|
|
9244
9237
|
}
|
|
9245
9238
|
else if (isMotionValue(prevValue)) {
|
package/dist/cjs/react-m.js
CHANGED
|
@@ -484,7 +484,6 @@ const numberValueTypes = {
|
|
|
484
484
|
backgroundPositionY: px,
|
|
485
485
|
...transformValueTypes,
|
|
486
486
|
zIndex: int,
|
|
487
|
-
size: px,
|
|
488
487
|
// SVG
|
|
489
488
|
fillOpacity: alpha,
|
|
490
489
|
strokeOpacity: alpha,
|
|
@@ -1273,20 +1272,13 @@ function useConstant(init) {
|
|
|
1273
1272
|
return ref.current;
|
|
1274
1273
|
}
|
|
1275
1274
|
|
|
1276
|
-
const isCustomValue = (v) => {
|
|
1277
|
-
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
1278
|
-
};
|
|
1279
|
-
|
|
1280
1275
|
/**
|
|
1281
1276
|
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
1282
1277
|
*
|
|
1283
1278
|
* TODO: Remove and move to library
|
|
1284
1279
|
*/
|
|
1285
1280
|
function resolveMotionValue(value) {
|
|
1286
|
-
|
|
1287
|
-
return isCustomValue(unwrappedValue)
|
|
1288
|
-
? unwrappedValue.toValue()
|
|
1289
|
-
: unwrappedValue;
|
|
1281
|
+
return isMotionValue(value) ? value.get() : value;
|
|
1290
1282
|
}
|
|
1291
1283
|
|
|
1292
1284
|
function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
|
|
@@ -17,7 +17,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
17
17
|
* and warn against mismatches.
|
|
18
18
|
*/
|
|
19
19
|
if (process.env.NODE_ENV === "development") {
|
|
20
|
-
warnOnce(nextValue.version === "12.
|
|
20
|
+
warnOnce(nextValue.version === "12.8.0", `Attempting to mix Motion versions ${nextValue.version} with 12.8.0 may not work as expected.`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
else if (isMotionValue(prevValue)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isKeyframesTarget } from '../../animation/utils/is-keyframes-target.mjs';
|
|
2
2
|
import { resolveVariant } from './resolve-dynamic-variants.mjs';
|
|
3
3
|
import { motionValue } from '../../../../../motion-dom/dist/es/value/index.mjs';
|
|
4
4
|
|
|
@@ -14,6 +14,10 @@ function setMotionValue(visualElement, key, value) {
|
|
|
14
14
|
visualElement.addValue(key, motionValue(value));
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
function resolveFinalValueInKeyframes(v) {
|
|
18
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
19
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
20
|
+
}
|
|
17
21
|
function setTarget(visualElement, definition) {
|
|
18
22
|
const resolved = resolveVariant(visualElement, definition);
|
|
19
23
|
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { transform } from '../utils/transform.mjs';
|
|
2
1
|
import { useConstant } from '../utils/use-constant.mjs';
|
|
3
2
|
import { useCombineMotionValues } from './use-combine-values.mjs';
|
|
4
3
|
import { useComputed } from './use-computed.mjs';
|
|
4
|
+
import { transform } from '../../../../motion-dom/dist/es/utils/transform.mjs';
|
|
5
5
|
|
|
6
6
|
function useTransform(input, inputRangeOrTransformer, outputRange, options) {
|
|
7
7
|
if (typeof input === "function") {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isCustomValue } from '../../utils/resolve-value.mjs';
|
|
2
1
|
import { isMotionValue } from './is-motion-value.mjs';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -7,10 +6,7 @@ import { isMotionValue } from './is-motion-value.mjs';
|
|
|
7
6
|
* TODO: Remove and move to library
|
|
8
7
|
*/
|
|
9
8
|
function resolveMotionValue(value) {
|
|
10
|
-
|
|
11
|
-
return isCustomValue(unwrappedValue)
|
|
12
|
-
? unwrappedValue.toValue()
|
|
13
|
-
: unwrappedValue;
|
|
9
|
+
return isMotionValue(value) ? value.get() : value;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
12
|
export { resolveMotionValue };
|
|
@@ -6,7 +6,6 @@ export { inView } from '../../framer-motion/dist/es/render/dom/viewport/index.mj
|
|
|
6
6
|
export { stagger } from '../../framer-motion/dist/es/animation/utils/stagger.mjs';
|
|
7
7
|
export { delayInSeconds as delay } from '../../framer-motion/dist/es/utils/delay.mjs';
|
|
8
8
|
export { distance, distance2D } from '../../framer-motion/dist/es/utils/distance.mjs';
|
|
9
|
-
export { transform } from '../../framer-motion/dist/es/utils/transform.mjs';
|
|
10
9
|
export { AsyncMotionValueAnimation } from '../../motion-dom/dist/es/animation/AsyncMotionValueAnimation.mjs';
|
|
11
10
|
export { GroupAnimation } from '../../motion-dom/dist/es/animation/GroupAnimation.mjs';
|
|
12
11
|
export { GroupAnimationWithThen } from '../../motion-dom/dist/es/animation/GroupAnimationWithThen.mjs';
|
|
@@ -69,7 +68,10 @@ export { resolveElements } from '../../motion-dom/dist/es/utils/resolve-elements
|
|
|
69
68
|
export { supportsFlags } from '../../motion-dom/dist/es/utils/supports/flags.mjs';
|
|
70
69
|
export { supportsLinearEasing } from '../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
|
|
71
70
|
export { supportsScrollTimeline } from '../../motion-dom/dist/es/utils/supports/scroll-timeline.mjs';
|
|
71
|
+
export { transform } from '../../motion-dom/dist/es/utils/transform.mjs';
|
|
72
72
|
export { MotionValue, collectMotionValues, motionValue } from '../../motion-dom/dist/es/value/index.mjs';
|
|
73
|
+
export { mapValue } from '../../motion-dom/dist/es/value/map-value.mjs';
|
|
74
|
+
export { transformValue } from '../../motion-dom/dist/es/value/transform-value.mjs';
|
|
73
75
|
export { color } from '../../motion-dom/dist/es/value/types/color/index.mjs';
|
|
74
76
|
export { hex } from '../../motion-dom/dist/es/value/types/color/hex.mjs';
|
|
75
77
|
export { hsla } from '../../motion-dom/dist/es/value/types/color/hsla.mjs';
|
|
@@ -78,7 +78,6 @@ export { scroll } from '../../framer-motion/dist/es/render/dom/scroll/index.mjs'
|
|
|
78
78
|
export { scrollInfo } from '../../framer-motion/dist/es/render/dom/scroll/track.mjs';
|
|
79
79
|
export { inView } from '../../framer-motion/dist/es/render/dom/viewport/index.mjs';
|
|
80
80
|
export { stagger } from '../../framer-motion/dist/es/animation/utils/stagger.mjs';
|
|
81
|
-
export { transform } from '../../framer-motion/dist/es/utils/transform.mjs';
|
|
82
81
|
export { distance, distance2D } from '../../framer-motion/dist/es/utils/distance.mjs';
|
|
83
82
|
export { addUniqueItem, moveItem, removeItem } from '../../motion-utils/dist/es/array.mjs';
|
|
84
83
|
export { clamp } from '../../motion-utils/dist/es/clamp.mjs';
|
|
@@ -168,7 +167,10 @@ export { resolveElements } from '../../motion-dom/dist/es/utils/resolve-elements
|
|
|
168
167
|
export { supportsFlags } from '../../motion-dom/dist/es/utils/supports/flags.mjs';
|
|
169
168
|
export { supportsLinearEasing } from '../../motion-dom/dist/es/utils/supports/linear-easing.mjs';
|
|
170
169
|
export { supportsScrollTimeline } from '../../motion-dom/dist/es/utils/supports/scroll-timeline.mjs';
|
|
170
|
+
export { transform } from '../../motion-dom/dist/es/utils/transform.mjs';
|
|
171
171
|
export { MotionValue, collectMotionValues, motionValue } from '../../motion-dom/dist/es/value/index.mjs';
|
|
172
|
+
export { mapValue } from '../../motion-dom/dist/es/value/map-value.mjs';
|
|
173
|
+
export { transformValue } from '../../motion-dom/dist/es/value/transform-value.mjs';
|
|
172
174
|
export { color } from '../../motion-dom/dist/es/value/types/color/index.mjs';
|
|
173
175
|
export { hex } from '../../motion-dom/dist/es/value/types/color/hex.mjs';
|
|
174
176
|
export { hsla } from '../../motion-dom/dist/es/value/types/color/hsla.mjs';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { interpolate } from '
|
|
1
|
+
import { interpolate } from './interpolate.mjs';
|
|
2
2
|
|
|
3
|
-
const isCustomValueType = (v) => {
|
|
4
|
-
return v && typeof v === "object" && v.mix;
|
|
5
|
-
};
|
|
6
|
-
const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
|
|
7
3
|
function transform(...args) {
|
|
8
4
|
const useImmediate = !Array.isArray(args[0]);
|
|
9
5
|
const argOffset = useImmediate ? 0 : -1;
|
|
@@ -11,10 +7,7 @@ function transform(...args) {
|
|
|
11
7
|
const inputRange = args[1 + argOffset];
|
|
12
8
|
const outputRange = args[2 + argOffset];
|
|
13
9
|
const options = args[3 + argOffset];
|
|
14
|
-
const interpolator = interpolate(inputRange, outputRange,
|
|
15
|
-
mixer: getMixer(outputRange[0]),
|
|
16
|
-
...options,
|
|
17
|
-
});
|
|
10
|
+
const interpolator = interpolate(inputRange, outputRange, options);
|
|
18
11
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
19
12
|
}
|
|
20
13
|
|
|
@@ -32,7 +32,7 @@ class MotionValue {
|
|
|
32
32
|
* This will be replaced by the build step with the latest version number.
|
|
33
33
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
34
34
|
*/
|
|
35
|
-
this.version = "12.
|
|
35
|
+
this.version = "12.8.0";
|
|
36
36
|
/**
|
|
37
37
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
38
38
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -301,6 +301,7 @@ class MotionValue {
|
|
|
301
301
|
* @public
|
|
302
302
|
*/
|
|
303
303
|
destroy() {
|
|
304
|
+
this.events.destroy?.notify();
|
|
304
305
|
this.clearListeners();
|
|
305
306
|
this.stop();
|
|
306
307
|
if (this.stopPassiveEffect) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { transform } from '../utils/transform.mjs';
|
|
2
|
+
import { transformValue } from './transform-value.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a `MotionValue` that maps the output of another `MotionValue` by
|
|
6
|
+
* mapping it from one range of values into another.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
*
|
|
10
|
+
* Given an input range of `[-200, -100, 100, 200]` and an output range of
|
|
11
|
+
* `[0, 1, 1, 0]`, the returned `MotionValue` will:
|
|
12
|
+
*
|
|
13
|
+
* - When provided a value between `-200` and `-100`, will return a value between `0` and `1`.
|
|
14
|
+
* - When provided a value between `-100` and `100`, will return `1`.
|
|
15
|
+
* - When provided a value between `100` and `200`, will return a value between `1` and `0`
|
|
16
|
+
*
|
|
17
|
+
* The input range must be a linear series of numbers. The output range
|
|
18
|
+
* can be any value type supported by Motion: numbers, colors, shadows, etc.
|
|
19
|
+
*
|
|
20
|
+
* Every value in the output range must be of the same type and in the same format.
|
|
21
|
+
*
|
|
22
|
+
* ```jsx
|
|
23
|
+
* const x = motionValue(0)
|
|
24
|
+
* const xRange = [-200, -100, 100, 200]
|
|
25
|
+
* const opacityRange = [0, 1, 1, 0]
|
|
26
|
+
* const opacity = mapValue(x, xRange, opacityRange)
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param inputValue - `MotionValue`
|
|
30
|
+
* @param inputRange - A linear series of numbers (either all increasing or decreasing)
|
|
31
|
+
* @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
|
|
32
|
+
* @param options -
|
|
33
|
+
*
|
|
34
|
+
* - clamp: boolean. Clamp values to within the given range. Defaults to `true`
|
|
35
|
+
* - 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.
|
|
36
|
+
*
|
|
37
|
+
* @returns `MotionValue`
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
function mapValue(inputValue, inputRange, outputRange, options) {
|
|
42
|
+
const map = transform(inputRange, outputRange, options);
|
|
43
|
+
return transformValue(() => map(inputValue.get()));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { mapValue };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cancelFrame, frame } from '../frameloop/frame.mjs';
|
|
2
|
+
|
|
3
|
+
function subscribeValue(inputValues, outputValue, getLatest) {
|
|
4
|
+
const update = () => outputValue.set(getLatest());
|
|
5
|
+
const scheduleUpdate = () => frame.preRender(update, false, true);
|
|
6
|
+
const subscriptions = inputValues.map((v) => v.on("change", scheduleUpdate));
|
|
7
|
+
outputValue.on("destroy", () => {
|
|
8
|
+
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
9
|
+
cancelFrame(update);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { subscribeValue };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { collectMotionValues, motionValue } from './index.mjs';
|
|
2
|
+
import { subscribeValue } from './subscribe-value.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a `MotionValue` that transforms the output of other `MotionValue`s by
|
|
6
|
+
* passing their latest values through a transform function.
|
|
7
|
+
*
|
|
8
|
+
* Whenever a `MotionValue` referred to in the provided function is updated,
|
|
9
|
+
* it will be re-evaluated.
|
|
10
|
+
*
|
|
11
|
+
* ```jsx
|
|
12
|
+
* const x = motionValue(0)
|
|
13
|
+
* const y = transformValue(() => x.get() * 2) // double x
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
|
|
17
|
+
* @returns `MotionValue`
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
function transformValue(transform) {
|
|
22
|
+
const collectedValues = [];
|
|
23
|
+
/**
|
|
24
|
+
* Open session of collectMotionValues. Any MotionValue that calls get()
|
|
25
|
+
* inside transform will be saved into this array.
|
|
26
|
+
*/
|
|
27
|
+
collectMotionValues.current = collectedValues;
|
|
28
|
+
const initialValue = transform();
|
|
29
|
+
collectMotionValues.current = undefined;
|
|
30
|
+
const value = motionValue(initialValue);
|
|
31
|
+
subscribeValue(collectedValues, value, transform);
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { transformValue };
|