motion 11.16.7 → 11.17.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 +5 -3
- package/dist/cjs/react-client.js +165 -122
- package/dist/cjs/react-m.js +184 -146
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +10 -7
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs +6 -3
- package/dist/es/framer-motion/dist/es/motion/utils/use-motion-ref.mjs +3 -1
- package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +11 -5
- package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +3 -1
- package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +54 -23
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/index.mjs +1 -1
- package/dist/motion.dev.js +5 -3
- package/dist/motion.js +1 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -1367,7 +1367,7 @@ class MotionValue {
|
|
|
1367
1367
|
* This will be replaced by the build step with the latest version number.
|
|
1368
1368
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
1369
1369
|
*/
|
|
1370
|
-
this.version = "11.
|
|
1370
|
+
this.version = "11.17.1";
|
|
1371
1371
|
/**
|
|
1372
1372
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
1373
1373
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -4297,7 +4297,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4297
4297
|
* and warn against mismatches.
|
|
4298
4298
|
*/
|
|
4299
4299
|
if (process.env.NODE_ENV === "development") {
|
|
4300
|
-
warnOnce(nextValue.version === "11.
|
|
4300
|
+
warnOnce(nextValue.version === "11.17.1", `Attempting to mix Motion versions ${nextValue.version} with 11.17.1 may not work as expected.`);
|
|
4301
4301
|
}
|
|
4302
4302
|
}
|
|
4303
4303
|
else if (isMotionValue(prevValue)) {
|
|
@@ -4430,7 +4430,8 @@ class VisualElement {
|
|
|
4430
4430
|
frame.render(this.render, false, true);
|
|
4431
4431
|
}
|
|
4432
4432
|
};
|
|
4433
|
-
const { latestValues, renderState } = visualState;
|
|
4433
|
+
const { latestValues, renderState, onUpdate } = visualState;
|
|
4434
|
+
this.onUpdate = onUpdate;
|
|
4434
4435
|
this.latestValues = latestValues;
|
|
4435
4436
|
this.baseTarget = { ...latestValues };
|
|
4436
4437
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -4630,6 +4631,7 @@ class VisualElement {
|
|
|
4630
4631
|
if (this.handleChildMotionValue) {
|
|
4631
4632
|
this.handleChildMotionValue();
|
|
4632
4633
|
}
|
|
4634
|
+
this.onUpdate && this.onUpdate(this);
|
|
4633
4635
|
}
|
|
4634
4636
|
getProps() {
|
|
4635
4637
|
return this.props;
|
package/dist/cjs/react-client.js
CHANGED
|
@@ -915,7 +915,7 @@ class MotionValue {
|
|
|
915
915
|
* This will be replaced by the build step with the latest version number.
|
|
916
916
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
917
917
|
*/
|
|
918
|
-
this.version = "11.
|
|
918
|
+
this.version = "11.17.1";
|
|
919
919
|
/**
|
|
920
920
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
921
921
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -5643,7 +5643,7 @@ const PresenceContext = react.createContext(null);
|
|
|
5643
5643
|
*
|
|
5644
5644
|
* @public
|
|
5645
5645
|
*/
|
|
5646
|
-
function usePresence() {
|
|
5646
|
+
function usePresence(subscribe = true) {
|
|
5647
5647
|
const context = react.useContext(PresenceContext);
|
|
5648
5648
|
if (context === null)
|
|
5649
5649
|
return [true, null];
|
|
@@ -5651,8 +5651,11 @@ function usePresence() {
|
|
|
5651
5651
|
// It's safe to call the following hooks conditionally (after an early return) because the context will always
|
|
5652
5652
|
// either be null or non-null for the lifespan of the component.
|
|
5653
5653
|
const id = react.useId();
|
|
5654
|
-
react.useEffect(() =>
|
|
5655
|
-
|
|
5654
|
+
react.useEffect(() => {
|
|
5655
|
+
if (subscribe)
|
|
5656
|
+
register(id);
|
|
5657
|
+
}, [subscribe]);
|
|
5658
|
+
const safeToRemove = react.useCallback(() => subscribe && onExitComplete && onExitComplete(id), [id, onExitComplete, subscribe]);
|
|
5656
5659
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
5657
5660
|
}
|
|
5658
5661
|
|
|
@@ -8194,7 +8197,9 @@ const motionComponentSymbol = Symbol.for("motionComponentSymbol");
|
|
|
8194
8197
|
*/
|
|
8195
8198
|
function useMotionRef(visualState, visualElement, externalRef) {
|
|
8196
8199
|
return react.useCallback((instance) => {
|
|
8197
|
-
|
|
8200
|
+
if (instance) {
|
|
8201
|
+
visualState.onMount && visualState.onMount(instance);
|
|
8202
|
+
}
|
|
8198
8203
|
if (visualElement) {
|
|
8199
8204
|
if (instance) {
|
|
8200
8205
|
visualElement.mount(instance);
|
|
@@ -8488,87 +8493,6 @@ function isSVGComponent(Component) {
|
|
|
8488
8493
|
return false;
|
|
8489
8494
|
}
|
|
8490
8495
|
|
|
8491
|
-
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
8492
|
-
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
8493
|
-
// Loop over any CSS variables and assign those.
|
|
8494
|
-
for (const key in vars) {
|
|
8495
|
-
element.style.setProperty(key, vars[key]);
|
|
8496
|
-
}
|
|
8497
|
-
}
|
|
8498
|
-
|
|
8499
|
-
/**
|
|
8500
|
-
* A set of attribute names that are always read/written as camel case.
|
|
8501
|
-
*/
|
|
8502
|
-
const camelCaseAttributes = new Set([
|
|
8503
|
-
"baseFrequency",
|
|
8504
|
-
"diffuseConstant",
|
|
8505
|
-
"kernelMatrix",
|
|
8506
|
-
"kernelUnitLength",
|
|
8507
|
-
"keySplines",
|
|
8508
|
-
"keyTimes",
|
|
8509
|
-
"limitingConeAngle",
|
|
8510
|
-
"markerHeight",
|
|
8511
|
-
"markerWidth",
|
|
8512
|
-
"numOctaves",
|
|
8513
|
-
"targetX",
|
|
8514
|
-
"targetY",
|
|
8515
|
-
"surfaceScale",
|
|
8516
|
-
"specularConstant",
|
|
8517
|
-
"specularExponent",
|
|
8518
|
-
"stdDeviation",
|
|
8519
|
-
"tableValues",
|
|
8520
|
-
"viewBox",
|
|
8521
|
-
"gradientTransform",
|
|
8522
|
-
"pathLength",
|
|
8523
|
-
"startOffset",
|
|
8524
|
-
"textLength",
|
|
8525
|
-
"lengthAdjust",
|
|
8526
|
-
]);
|
|
8527
|
-
|
|
8528
|
-
function renderSVG(element, renderState, _styleProp, projection) {
|
|
8529
|
-
renderHTML(element, renderState, undefined, projection);
|
|
8530
|
-
for (const key in renderState.attrs) {
|
|
8531
|
-
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
8532
|
-
}
|
|
8533
|
-
}
|
|
8534
|
-
|
|
8535
|
-
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
8536
|
-
return (transformProps.has(key) ||
|
|
8537
|
-
key.startsWith("origin") ||
|
|
8538
|
-
((layout || layoutId !== undefined) &&
|
|
8539
|
-
(!!scaleCorrectors[key] || key === "opacity")));
|
|
8540
|
-
}
|
|
8541
|
-
|
|
8542
|
-
function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
8543
|
-
var _a;
|
|
8544
|
-
const { style } = props;
|
|
8545
|
-
const newValues = {};
|
|
8546
|
-
for (const key in style) {
|
|
8547
|
-
if (isMotionValue(style[key]) ||
|
|
8548
|
-
(prevProps.style &&
|
|
8549
|
-
isMotionValue(prevProps.style[key])) ||
|
|
8550
|
-
isForcedMotionValue(key, props) ||
|
|
8551
|
-
((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
|
|
8552
|
-
newValues[key] = style[key];
|
|
8553
|
-
}
|
|
8554
|
-
}
|
|
8555
|
-
return newValues;
|
|
8556
|
-
}
|
|
8557
|
-
|
|
8558
|
-
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
8559
|
-
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
8560
|
-
for (const key in props) {
|
|
8561
|
-
if (isMotionValue(props[key]) ||
|
|
8562
|
-
isMotionValue(prevProps[key])) {
|
|
8563
|
-
const targetKey = transformPropOrder.indexOf(key) !== -1
|
|
8564
|
-
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
8565
|
-
: key;
|
|
8566
|
-
newValues[targetKey] = props[key];
|
|
8567
|
-
}
|
|
8568
|
-
}
|
|
8569
|
-
return newValues;
|
|
8570
|
-
}
|
|
8571
|
-
|
|
8572
8496
|
/**
|
|
8573
8497
|
* Creates a constant value over the lifecycle of a component.
|
|
8574
8498
|
*
|
|
@@ -8584,13 +8508,19 @@ function useConstant(init) {
|
|
|
8584
8508
|
return ref.current;
|
|
8585
8509
|
}
|
|
8586
8510
|
|
|
8587
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
8511
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
|
|
8588
8512
|
const state = {
|
|
8589
8513
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
8590
8514
|
renderState: createRenderState(),
|
|
8591
8515
|
};
|
|
8592
|
-
if (
|
|
8593
|
-
|
|
8516
|
+
if (onUpdate) {
|
|
8517
|
+
/**
|
|
8518
|
+
* onMount works without the VisualElement because it could be
|
|
8519
|
+
* called before the VisualElement payload has been hydrated.
|
|
8520
|
+
* (e.g. if someone is using m components <m.circle />)
|
|
8521
|
+
*/
|
|
8522
|
+
state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
|
|
8523
|
+
state.onUpdate = (visualElement) => onUpdate(visualElement);
|
|
8594
8524
|
}
|
|
8595
8525
|
return state;
|
|
8596
8526
|
}
|
|
@@ -8656,18 +8586,6 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
8656
8586
|
return values;
|
|
8657
8587
|
}
|
|
8658
8588
|
|
|
8659
|
-
const createHtmlRenderState = () => ({
|
|
8660
|
-
style: {},
|
|
8661
|
-
transform: {},
|
|
8662
|
-
transformOrigin: {},
|
|
8663
|
-
vars: {},
|
|
8664
|
-
});
|
|
8665
|
-
|
|
8666
|
-
const createSvgRenderState = () => ({
|
|
8667
|
-
...createHtmlRenderState(),
|
|
8668
|
-
attrs: {},
|
|
8669
|
-
});
|
|
8670
|
-
|
|
8671
8589
|
/**
|
|
8672
8590
|
* Provided a value and a ValueType, returns the value as that value type.
|
|
8673
8591
|
*/
|
|
@@ -8883,34 +8801,157 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
8883
8801
|
}
|
|
8884
8802
|
}
|
|
8885
8803
|
|
|
8804
|
+
const createHtmlRenderState = () => ({
|
|
8805
|
+
style: {},
|
|
8806
|
+
transform: {},
|
|
8807
|
+
transformOrigin: {},
|
|
8808
|
+
vars: {},
|
|
8809
|
+
});
|
|
8810
|
+
|
|
8811
|
+
const createSvgRenderState = () => ({
|
|
8812
|
+
...createHtmlRenderState(),
|
|
8813
|
+
attrs: {},
|
|
8814
|
+
});
|
|
8815
|
+
|
|
8886
8816
|
const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
|
|
8887
8817
|
|
|
8818
|
+
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
8819
|
+
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
8820
|
+
// Loop over any CSS variables and assign those.
|
|
8821
|
+
for (const key in vars) {
|
|
8822
|
+
element.style.setProperty(key, vars[key]);
|
|
8823
|
+
}
|
|
8824
|
+
}
|
|
8825
|
+
|
|
8826
|
+
/**
|
|
8827
|
+
* A set of attribute names that are always read/written as camel case.
|
|
8828
|
+
*/
|
|
8829
|
+
const camelCaseAttributes = new Set([
|
|
8830
|
+
"baseFrequency",
|
|
8831
|
+
"diffuseConstant",
|
|
8832
|
+
"kernelMatrix",
|
|
8833
|
+
"kernelUnitLength",
|
|
8834
|
+
"keySplines",
|
|
8835
|
+
"keyTimes",
|
|
8836
|
+
"limitingConeAngle",
|
|
8837
|
+
"markerHeight",
|
|
8838
|
+
"markerWidth",
|
|
8839
|
+
"numOctaves",
|
|
8840
|
+
"targetX",
|
|
8841
|
+
"targetY",
|
|
8842
|
+
"surfaceScale",
|
|
8843
|
+
"specularConstant",
|
|
8844
|
+
"specularExponent",
|
|
8845
|
+
"stdDeviation",
|
|
8846
|
+
"tableValues",
|
|
8847
|
+
"viewBox",
|
|
8848
|
+
"gradientTransform",
|
|
8849
|
+
"pathLength",
|
|
8850
|
+
"startOffset",
|
|
8851
|
+
"textLength",
|
|
8852
|
+
"lengthAdjust",
|
|
8853
|
+
]);
|
|
8854
|
+
|
|
8855
|
+
function renderSVG(element, renderState, _styleProp, projection) {
|
|
8856
|
+
renderHTML(element, renderState, undefined, projection);
|
|
8857
|
+
for (const key in renderState.attrs) {
|
|
8858
|
+
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
8859
|
+
}
|
|
8860
|
+
}
|
|
8861
|
+
|
|
8862
|
+
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
8863
|
+
return (transformProps.has(key) ||
|
|
8864
|
+
key.startsWith("origin") ||
|
|
8865
|
+
((layout || layoutId !== undefined) &&
|
|
8866
|
+
(!!scaleCorrectors[key] || key === "opacity")));
|
|
8867
|
+
}
|
|
8868
|
+
|
|
8869
|
+
function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
8870
|
+
var _a;
|
|
8871
|
+
const { style } = props;
|
|
8872
|
+
const newValues = {};
|
|
8873
|
+
for (const key in style) {
|
|
8874
|
+
if (isMotionValue(style[key]) ||
|
|
8875
|
+
(prevProps.style &&
|
|
8876
|
+
isMotionValue(prevProps.style[key])) ||
|
|
8877
|
+
isForcedMotionValue(key, props) ||
|
|
8878
|
+
((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
|
|
8879
|
+
newValues[key] = style[key];
|
|
8880
|
+
}
|
|
8881
|
+
}
|
|
8882
|
+
return newValues;
|
|
8883
|
+
}
|
|
8884
|
+
|
|
8885
|
+
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
8886
|
+
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
8887
|
+
for (const key in props) {
|
|
8888
|
+
if (isMotionValue(props[key]) ||
|
|
8889
|
+
isMotionValue(prevProps[key])) {
|
|
8890
|
+
const targetKey = transformPropOrder.indexOf(key) !== -1
|
|
8891
|
+
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
8892
|
+
: key;
|
|
8893
|
+
newValues[targetKey] = props[key];
|
|
8894
|
+
}
|
|
8895
|
+
}
|
|
8896
|
+
return newValues;
|
|
8897
|
+
}
|
|
8898
|
+
|
|
8899
|
+
function updateSVGDimensions(instance, renderState) {
|
|
8900
|
+
try {
|
|
8901
|
+
renderState.dimensions =
|
|
8902
|
+
typeof instance.getBBox === "function"
|
|
8903
|
+
? instance.getBBox()
|
|
8904
|
+
: instance.getBoundingClientRect();
|
|
8905
|
+
}
|
|
8906
|
+
catch (e) {
|
|
8907
|
+
// Most likely trying to measure an unrendered element under Firefox
|
|
8908
|
+
renderState.dimensions = {
|
|
8909
|
+
x: 0,
|
|
8910
|
+
y: 0,
|
|
8911
|
+
width: 0,
|
|
8912
|
+
height: 0,
|
|
8913
|
+
};
|
|
8914
|
+
}
|
|
8915
|
+
}
|
|
8916
|
+
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
|
|
8888
8917
|
const svgMotionConfig = {
|
|
8889
8918
|
useVisualState: makeUseVisualState({
|
|
8890
8919
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
8891
8920
|
createRenderState: createSvgRenderState,
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8921
|
+
onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
|
|
8922
|
+
if (!current)
|
|
8923
|
+
return;
|
|
8924
|
+
let hasTransform = !!props.drag;
|
|
8925
|
+
if (!hasTransform) {
|
|
8926
|
+
for (const key in latestValues) {
|
|
8927
|
+
if (transformProps.has(key)) {
|
|
8928
|
+
hasTransform = true;
|
|
8929
|
+
break;
|
|
8930
|
+
}
|
|
8900
8931
|
}
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8932
|
+
}
|
|
8933
|
+
if (!hasTransform)
|
|
8934
|
+
return;
|
|
8935
|
+
let needsMeasure = !prevProps;
|
|
8936
|
+
if (prevProps) {
|
|
8937
|
+
/**
|
|
8938
|
+
* Check the layout props for changes, if any are found we need to
|
|
8939
|
+
* measure the element again.
|
|
8940
|
+
*/
|
|
8941
|
+
for (let i = 0; i < layoutProps.length; i++) {
|
|
8942
|
+
const key = layoutProps[i];
|
|
8943
|
+
if (props[key] !==
|
|
8944
|
+
prevProps[key]) {
|
|
8945
|
+
needsMeasure = true;
|
|
8946
|
+
}
|
|
8909
8947
|
}
|
|
8910
|
-
}
|
|
8948
|
+
}
|
|
8949
|
+
if (!needsMeasure)
|
|
8950
|
+
return;
|
|
8951
|
+
frame.read(() => updateSVGDimensions(current, renderState));
|
|
8911
8952
|
frame.render(() => {
|
|
8912
|
-
buildSVGAttrs(renderState, latestValues, isSVGTag(
|
|
8913
|
-
renderSVG(
|
|
8953
|
+
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
8954
|
+
renderSVG(current, renderState);
|
|
8914
8955
|
});
|
|
8915
8956
|
},
|
|
8916
8957
|
}),
|
|
@@ -9188,7 +9229,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
9188
9229
|
* and warn against mismatches.
|
|
9189
9230
|
*/
|
|
9190
9231
|
if (process.env.NODE_ENV === "development") {
|
|
9191
|
-
warnOnce(nextValue.version === "11.
|
|
9232
|
+
warnOnce(nextValue.version === "11.17.1", `Attempting to mix Motion versions ${nextValue.version} with 11.17.1 may not work as expected.`);
|
|
9192
9233
|
}
|
|
9193
9234
|
}
|
|
9194
9235
|
else if (isMotionValue(prevValue)) {
|
|
@@ -9321,7 +9362,8 @@ class VisualElement {
|
|
|
9321
9362
|
frame.render(this.render, false, true);
|
|
9322
9363
|
}
|
|
9323
9364
|
};
|
|
9324
|
-
const { latestValues, renderState } = visualState;
|
|
9365
|
+
const { latestValues, renderState, onUpdate } = visualState;
|
|
9366
|
+
this.onUpdate = onUpdate;
|
|
9325
9367
|
this.latestValues = latestValues;
|
|
9326
9368
|
this.baseTarget = { ...latestValues };
|
|
9327
9369
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -9521,6 +9563,7 @@ class VisualElement {
|
|
|
9521
9563
|
if (this.handleChildMotionValue) {
|
|
9522
9564
|
this.handleChildMotionValue();
|
|
9523
9565
|
}
|
|
9566
|
+
this.onUpdate && this.onUpdate(this);
|
|
9524
9567
|
}
|
|
9525
9568
|
getProps() {
|
|
9526
9569
|
return this.props;
|