framer-motion 12.7.5 → 12.8.2
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/client.js +1 -1
- package/dist/cjs/{create-RWnxg4Sz.js → create-M6GRDJBe.js} +64 -158
- package/dist/cjs/dom.js +22 -81
- package/dist/cjs/index.js +2 -21
- package/dist/cjs/m.js +18 -144
- package/dist/dom.d.ts +1 -94
- package/dist/dom.js +1 -1
- package/dist/es/dom.mjs +0 -1
- package/dist/es/index.mjs +0 -1
- package/dist/es/motion/utils/use-visual-state.mjs +1 -10
- package/dist/es/render/VisualElement.mjs +1 -3
- package/dist/es/render/svg/SVGVisualElement.mjs +1 -12
- package/dist/es/render/svg/config-motion.mjs +0 -44
- package/dist/es/render/svg/utils/build-attrs.mjs +16 -11
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/render/utils/setters.mjs +5 -1
- package/dist/es/value/use-transform.mjs +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs +1 -5
- package/dist/framer-motion.dev.js +166 -184
- package/dist/framer-motion.js +1 -1
- package/dist/m.d.ts +7 -28
- package/dist/size-rollup-animate.js +1 -1
- package/dist/size-rollup-dom-animation-assets.js +1 -1
- package/dist/size-rollup-dom-animation-m.js +1 -1
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -1
- package/dist/types/client.d.ts +2 -2
- package/dist/types/index.d.ts +9 -102
- package/dist/{types.d-B1Voffvi.d.ts → types.d-DDSxwf0n.d.ts} +11 -42
- package/package.json +3 -3
- package/dist/es/render/svg/utils/measure.mjs +0 -19
- package/dist/es/render/svg/utils/transform-origin.mjs +0 -18
- package/dist/es/utils/resolve-value.mjs +0 -11
- package/dist/es/utils/transform.mjs +0 -21
package/dist/cjs/m.js
CHANGED
|
@@ -764,25 +764,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
764
764
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
765
765
|
}
|
|
766
766
|
|
|
767
|
-
function calcOrigin(origin, offset, size) {
|
|
768
|
-
return typeof origin === "string"
|
|
769
|
-
? origin
|
|
770
|
-
: motionDom.px.transform(offset + size * origin);
|
|
771
|
-
}
|
|
772
|
-
/**
|
|
773
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
774
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
775
|
-
*/
|
|
776
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
777
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
778
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
779
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
767
|
/**
|
|
783
768
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
784
769
|
*/
|
|
785
|
-
function buildSVGAttrs(state, { attrX, attrY, attrScale,
|
|
770
|
+
function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
786
771
|
// This is object creation, which we try to avoid per-frame.
|
|
787
772
|
...latest }, isSVGTag, transformTemplate) {
|
|
788
773
|
buildHTMLStyles(state, latest, transformTemplate);
|
|
@@ -798,20 +783,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
798
783
|
}
|
|
799
784
|
state.attrs = state.style;
|
|
800
785
|
state.style = {};
|
|
801
|
-
const { attrs, style
|
|
786
|
+
const { attrs, style } = state;
|
|
802
787
|
/**
|
|
803
|
-
* However, we apply transforms as CSS transforms.
|
|
804
|
-
* and copy it into style.
|
|
788
|
+
* However, we apply transforms as CSS transforms.
|
|
789
|
+
* So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
|
|
805
790
|
*/
|
|
806
791
|
if (attrs.transform) {
|
|
807
|
-
|
|
808
|
-
style.transform = attrs.transform;
|
|
792
|
+
style.transform = attrs.transform;
|
|
809
793
|
delete attrs.transform;
|
|
810
794
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
795
|
+
if (style.transform || attrs.transformOrigin) {
|
|
796
|
+
style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
|
|
797
|
+
delete attrs.transformOrigin;
|
|
798
|
+
}
|
|
799
|
+
if (style.transform) {
|
|
800
|
+
/**
|
|
801
|
+
* SVG's element transform-origin uses its own median as a reference.
|
|
802
|
+
* Therefore, transformBox becomes a fill-box
|
|
803
|
+
*/
|
|
804
|
+
style.transformBox = "fill-box";
|
|
805
|
+
delete attrs.transformBox;
|
|
815
806
|
}
|
|
816
807
|
// Render attrX/attrY/attrScale as attributes
|
|
817
808
|
if (attrX !== undefined)
|
|
@@ -925,36 +916,20 @@ function useConstant(init) {
|
|
|
925
916
|
return ref.current;
|
|
926
917
|
}
|
|
927
918
|
|
|
928
|
-
const isCustomValue = (v) => {
|
|
929
|
-
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
930
|
-
};
|
|
931
|
-
|
|
932
919
|
/**
|
|
933
920
|
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
934
921
|
*
|
|
935
922
|
* TODO: Remove and move to library
|
|
936
923
|
*/
|
|
937
924
|
function resolveMotionValue(value) {
|
|
938
|
-
|
|
939
|
-
return isCustomValue(unwrappedValue)
|
|
940
|
-
? unwrappedValue.toValue()
|
|
941
|
-
: unwrappedValue;
|
|
925
|
+
return isMotionValue(value) ? value.get() : value;
|
|
942
926
|
}
|
|
943
927
|
|
|
944
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
928
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
|
|
945
929
|
const state = {
|
|
946
930
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
947
931
|
renderState: createRenderState(),
|
|
948
932
|
};
|
|
949
|
-
if (onUpdate) {
|
|
950
|
-
/**
|
|
951
|
-
* onMount works without the VisualElement because it could be
|
|
952
|
-
* called before the VisualElement payload has been hydrated.
|
|
953
|
-
* (e.g. if someone is using m components <m.circle />)
|
|
954
|
-
*/
|
|
955
|
-
state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
|
|
956
|
-
state.onUpdate = (visualElement) => onUpdate(visualElement);
|
|
957
|
-
}
|
|
958
933
|
return state;
|
|
959
934
|
}
|
|
960
935
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
@@ -1041,68 +1016,6 @@ const htmlMotionConfig = {
|
|
|
1041
1016
|
}),
|
|
1042
1017
|
};
|
|
1043
1018
|
|
|
1044
|
-
function updateSVGDimensions(instance, renderState) {
|
|
1045
|
-
try {
|
|
1046
|
-
renderState.dimensions =
|
|
1047
|
-
typeof instance.getBBox === "function"
|
|
1048
|
-
? instance.getBBox()
|
|
1049
|
-
: instance.getBoundingClientRect();
|
|
1050
|
-
}
|
|
1051
|
-
catch (e) {
|
|
1052
|
-
// Most likely trying to measure an unrendered element under Firefox
|
|
1053
|
-
renderState.dimensions = {
|
|
1054
|
-
x: 0,
|
|
1055
|
-
y: 0,
|
|
1056
|
-
width: 0,
|
|
1057
|
-
height: 0,
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1063
|
-
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
1064
|
-
// Loop over any CSS variables and assign those.
|
|
1065
|
-
for (const key in vars) {
|
|
1066
|
-
element.style.setProperty(key, vars[key]);
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
/**
|
|
1071
|
-
* A set of attribute names that are always read/written as camel case.
|
|
1072
|
-
*/
|
|
1073
|
-
const camelCaseAttributes = new Set([
|
|
1074
|
-
"baseFrequency",
|
|
1075
|
-
"diffuseConstant",
|
|
1076
|
-
"kernelMatrix",
|
|
1077
|
-
"kernelUnitLength",
|
|
1078
|
-
"keySplines",
|
|
1079
|
-
"keyTimes",
|
|
1080
|
-
"limitingConeAngle",
|
|
1081
|
-
"markerHeight",
|
|
1082
|
-
"markerWidth",
|
|
1083
|
-
"numOctaves",
|
|
1084
|
-
"targetX",
|
|
1085
|
-
"targetY",
|
|
1086
|
-
"surfaceScale",
|
|
1087
|
-
"specularConstant",
|
|
1088
|
-
"specularExponent",
|
|
1089
|
-
"stdDeviation",
|
|
1090
|
-
"tableValues",
|
|
1091
|
-
"viewBox",
|
|
1092
|
-
"gradientTransform",
|
|
1093
|
-
"pathLength",
|
|
1094
|
-
"startOffset",
|
|
1095
|
-
"textLength",
|
|
1096
|
-
"lengthAdjust",
|
|
1097
|
-
]);
|
|
1098
|
-
|
|
1099
|
-
function renderSVG(element, renderState, _styleProp, projection) {
|
|
1100
|
-
renderHTML(element, renderState, undefined, projection);
|
|
1101
|
-
for (const key in renderState.attrs) {
|
|
1102
|
-
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
1019
|
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
1107
1020
|
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
1108
1021
|
for (const key in props) {
|
|
@@ -1117,49 +1030,10 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
|
1117
1030
|
return newValues;
|
|
1118
1031
|
}
|
|
1119
1032
|
|
|
1120
|
-
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
|
|
1121
1033
|
const svgMotionConfig = {
|
|
1122
1034
|
useVisualState: makeUseVisualState({
|
|
1123
1035
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
1124
1036
|
createRenderState: createSvgRenderState,
|
|
1125
|
-
onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
|
|
1126
|
-
if (!current)
|
|
1127
|
-
return;
|
|
1128
|
-
let hasTransform = !!props.drag;
|
|
1129
|
-
if (!hasTransform) {
|
|
1130
|
-
for (const key in latestValues) {
|
|
1131
|
-
if (motionDom.transformProps.has(key)) {
|
|
1132
|
-
hasTransform = true;
|
|
1133
|
-
break;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
if (!hasTransform)
|
|
1138
|
-
return;
|
|
1139
|
-
let needsMeasure = !prevProps;
|
|
1140
|
-
if (prevProps) {
|
|
1141
|
-
/**
|
|
1142
|
-
* Check the layout props for changes, if any are found we need to
|
|
1143
|
-
* measure the element again.
|
|
1144
|
-
*/
|
|
1145
|
-
for (let i = 0; i < layoutProps.length; i++) {
|
|
1146
|
-
const key = layoutProps[i];
|
|
1147
|
-
if (props[key] !==
|
|
1148
|
-
prevProps[key]) {
|
|
1149
|
-
needsMeasure = true;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
if (!needsMeasure)
|
|
1154
|
-
return;
|
|
1155
|
-
motionDom.frame.read(() => {
|
|
1156
|
-
updateSVGDimensions(current, renderState);
|
|
1157
|
-
motionDom.frame.render(() => {
|
|
1158
|
-
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
1159
|
-
renderSVG(current, renderState);
|
|
1160
|
-
});
|
|
1161
|
-
});
|
|
1162
|
-
},
|
|
1163
1037
|
}),
|
|
1164
1038
|
};
|
|
1165
1039
|
|
package/dist/dom.d.ts
CHANGED
|
@@ -158,97 +158,4 @@ declare function delayInSeconds(callback: DelayedFunction, timeout: number): ()
|
|
|
158
158
|
declare const distance: (a: number, b: number) => number;
|
|
159
159
|
declare function distance2D(a: Point, b: Point): number;
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
* @public
|
|
163
|
-
*/
|
|
164
|
-
interface TransformOptions<T> {
|
|
165
|
-
/**
|
|
166
|
-
* Clamp values to within the given range. Defaults to `true`
|
|
167
|
-
*
|
|
168
|
-
* @public
|
|
169
|
-
*/
|
|
170
|
-
clamp?: boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Easing functions to use on the interpolations between each value in the input and output ranges.
|
|
173
|
-
*
|
|
174
|
-
* 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.
|
|
175
|
-
*
|
|
176
|
-
* @public
|
|
177
|
-
*/
|
|
178
|
-
ease?: EasingFunction | EasingFunction[];
|
|
179
|
-
/**
|
|
180
|
-
* Provide a function that can interpolate between any two values in the provided range.
|
|
181
|
-
*
|
|
182
|
-
* @public
|
|
183
|
-
*/
|
|
184
|
-
mixer?: (from: T, to: T) => (v: number) => any;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Transforms numbers into other values by mapping them from an input range to an output range.
|
|
188
|
-
* Returns the type of the input provided.
|
|
189
|
-
*
|
|
190
|
-
* @remarks
|
|
191
|
-
*
|
|
192
|
-
* Given an input range of `[0, 200]` and an output range of
|
|
193
|
-
* `[0, 1]`, this function will return a value between `0` and `1`.
|
|
194
|
-
* The input range must be a linear series of numbers. The output range
|
|
195
|
-
* can be any supported value type, such as numbers, colors, shadows, arrays, objects and more.
|
|
196
|
-
* Every value in the output range must be of the same type and in the same format.
|
|
197
|
-
*
|
|
198
|
-
* ```jsx
|
|
199
|
-
* import * as React from "react"
|
|
200
|
-
* import { transform } from "framer-motion"
|
|
201
|
-
*
|
|
202
|
-
* export function MyComponent() {
|
|
203
|
-
* const inputRange = [0, 200]
|
|
204
|
-
* const outputRange = [0, 1]
|
|
205
|
-
* const output = transform(100, inputRange, outputRange)
|
|
206
|
-
*
|
|
207
|
-
* // Returns 0.5
|
|
208
|
-
* return <div>{output}</div>
|
|
209
|
-
* }
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @param inputValue - A number to transform between the input and output ranges.
|
|
213
|
-
* @param inputRange - A linear series of numbers (either all increasing or decreasing).
|
|
214
|
-
* @param outputRange - A series of numbers, colors, strings, or arrays/objects of those. Must be the same length as `inputRange`.
|
|
215
|
-
* @param options - Clamp: Clamp values to within the given range. Defaults to `true`.
|
|
216
|
-
*
|
|
217
|
-
* @public
|
|
218
|
-
*/
|
|
219
|
-
declare function transform<T>(inputValue: number, inputRange: number[], outputRange: T[], options?: TransformOptions<T>): T;
|
|
220
|
-
/**
|
|
221
|
-
*
|
|
222
|
-
* Transforms numbers into other values by mapping them from an input range to an output range.
|
|
223
|
-
*
|
|
224
|
-
* Given an input range of `[0, 200]` and an output range of
|
|
225
|
-
* `[0, 1]`, this function will return a value between `0` and `1`.
|
|
226
|
-
* The input range must be a linear series of numbers. The output range
|
|
227
|
-
* can be any supported value type, such as numbers, colors, shadows, arrays, objects and more.
|
|
228
|
-
* Every value in the output range must be of the same type and in the same format.
|
|
229
|
-
*
|
|
230
|
-
* ```jsx
|
|
231
|
-
* import * as React from "react"
|
|
232
|
-
* import { Frame, transform } from "framer"
|
|
233
|
-
*
|
|
234
|
-
* export function MyComponent() {
|
|
235
|
-
* const inputRange = [-200, -100, 100, 200]
|
|
236
|
-
* const outputRange = [0, 1, 1, 0]
|
|
237
|
-
* const convertRange = transform(inputRange, outputRange)
|
|
238
|
-
* const output = convertRange(-150)
|
|
239
|
-
*
|
|
240
|
-
* // Returns 0.5
|
|
241
|
-
* return <div>{output}</div>
|
|
242
|
-
* }
|
|
243
|
-
*
|
|
244
|
-
* ```
|
|
245
|
-
*
|
|
246
|
-
* @param inputRange - A linear series of numbers (either all increasing or decreasing).
|
|
247
|
-
* @param outputRange - A series of numbers, colors or strings. Must be the same length as `inputRange`.
|
|
248
|
-
* @param options - Clamp: clamp values to within the given range. Defaults to `true`.
|
|
249
|
-
*
|
|
250
|
-
* @public
|
|
251
|
-
*/
|
|
252
|
-
declare function transform<T>(inputRange: number[], outputRange: T[], options?: TransformOptions<T>): (inputValue: number) => T;
|
|
253
|
-
|
|
254
|
-
export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo, stagger, transform };
|
|
161
|
+
export { type AbsoluteKeyframe, type AnimationSequence, type At, type DOMSegment, type DOMSegmentWithTransition, type DelayedFunction, type MotionValueSegment, type MotionValueSegmentWithTransition, type ObjectSegment, type ObjectSegmentWithTransition, type ObjectTarget, type ResolvedAnimationDefinition, type ResolvedAnimationDefinitions, type Segment, type SequenceLabel, type SequenceLabelWithTime, type SequenceMap, type SequenceOptions, type SequenceTime, type ValueSequence, animate, animateMini, createScopedAnimate, delayInSeconds as delay, distance, distance2D, inView, scroll, scrollInfo, stagger };
|