motion 11.17.0 → 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 +159 -119
- package/dist/cjs/react-m.js +184 -146
- 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.17.
|
|
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.17.
|
|
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.17.
|
|
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
|
|
@@ -8197,7 +8197,9 @@ const motionComponentSymbol = Symbol.for("motionComponentSymbol");
|
|
|
8197
8197
|
*/
|
|
8198
8198
|
function useMotionRef(visualState, visualElement, externalRef) {
|
|
8199
8199
|
return react.useCallback((instance) => {
|
|
8200
|
-
|
|
8200
|
+
if (instance) {
|
|
8201
|
+
visualState.onMount && visualState.onMount(instance);
|
|
8202
|
+
}
|
|
8201
8203
|
if (visualElement) {
|
|
8202
8204
|
if (instance) {
|
|
8203
8205
|
visualElement.mount(instance);
|
|
@@ -8491,87 +8493,6 @@ function isSVGComponent(Component) {
|
|
|
8491
8493
|
return false;
|
|
8492
8494
|
}
|
|
8493
8495
|
|
|
8494
|
-
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
8495
|
-
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
8496
|
-
// Loop over any CSS variables and assign those.
|
|
8497
|
-
for (const key in vars) {
|
|
8498
|
-
element.style.setProperty(key, vars[key]);
|
|
8499
|
-
}
|
|
8500
|
-
}
|
|
8501
|
-
|
|
8502
|
-
/**
|
|
8503
|
-
* A set of attribute names that are always read/written as camel case.
|
|
8504
|
-
*/
|
|
8505
|
-
const camelCaseAttributes = new Set([
|
|
8506
|
-
"baseFrequency",
|
|
8507
|
-
"diffuseConstant",
|
|
8508
|
-
"kernelMatrix",
|
|
8509
|
-
"kernelUnitLength",
|
|
8510
|
-
"keySplines",
|
|
8511
|
-
"keyTimes",
|
|
8512
|
-
"limitingConeAngle",
|
|
8513
|
-
"markerHeight",
|
|
8514
|
-
"markerWidth",
|
|
8515
|
-
"numOctaves",
|
|
8516
|
-
"targetX",
|
|
8517
|
-
"targetY",
|
|
8518
|
-
"surfaceScale",
|
|
8519
|
-
"specularConstant",
|
|
8520
|
-
"specularExponent",
|
|
8521
|
-
"stdDeviation",
|
|
8522
|
-
"tableValues",
|
|
8523
|
-
"viewBox",
|
|
8524
|
-
"gradientTransform",
|
|
8525
|
-
"pathLength",
|
|
8526
|
-
"startOffset",
|
|
8527
|
-
"textLength",
|
|
8528
|
-
"lengthAdjust",
|
|
8529
|
-
]);
|
|
8530
|
-
|
|
8531
|
-
function renderSVG(element, renderState, _styleProp, projection) {
|
|
8532
|
-
renderHTML(element, renderState, undefined, projection);
|
|
8533
|
-
for (const key in renderState.attrs) {
|
|
8534
|
-
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
8535
|
-
}
|
|
8536
|
-
}
|
|
8537
|
-
|
|
8538
|
-
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
8539
|
-
return (transformProps.has(key) ||
|
|
8540
|
-
key.startsWith("origin") ||
|
|
8541
|
-
((layout || layoutId !== undefined) &&
|
|
8542
|
-
(!!scaleCorrectors[key] || key === "opacity")));
|
|
8543
|
-
}
|
|
8544
|
-
|
|
8545
|
-
function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
8546
|
-
var _a;
|
|
8547
|
-
const { style } = props;
|
|
8548
|
-
const newValues = {};
|
|
8549
|
-
for (const key in style) {
|
|
8550
|
-
if (isMotionValue(style[key]) ||
|
|
8551
|
-
(prevProps.style &&
|
|
8552
|
-
isMotionValue(prevProps.style[key])) ||
|
|
8553
|
-
isForcedMotionValue(key, props) ||
|
|
8554
|
-
((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
|
|
8555
|
-
newValues[key] = style[key];
|
|
8556
|
-
}
|
|
8557
|
-
}
|
|
8558
|
-
return newValues;
|
|
8559
|
-
}
|
|
8560
|
-
|
|
8561
|
-
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
8562
|
-
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
8563
|
-
for (const key in props) {
|
|
8564
|
-
if (isMotionValue(props[key]) ||
|
|
8565
|
-
isMotionValue(prevProps[key])) {
|
|
8566
|
-
const targetKey = transformPropOrder.indexOf(key) !== -1
|
|
8567
|
-
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
8568
|
-
: key;
|
|
8569
|
-
newValues[targetKey] = props[key];
|
|
8570
|
-
}
|
|
8571
|
-
}
|
|
8572
|
-
return newValues;
|
|
8573
|
-
}
|
|
8574
|
-
|
|
8575
8496
|
/**
|
|
8576
8497
|
* Creates a constant value over the lifecycle of a component.
|
|
8577
8498
|
*
|
|
@@ -8587,13 +8508,19 @@ function useConstant(init) {
|
|
|
8587
8508
|
return ref.current;
|
|
8588
8509
|
}
|
|
8589
8510
|
|
|
8590
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
8511
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
|
|
8591
8512
|
const state = {
|
|
8592
8513
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
8593
8514
|
renderState: createRenderState(),
|
|
8594
8515
|
};
|
|
8595
|
-
if (
|
|
8596
|
-
|
|
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);
|
|
8597
8524
|
}
|
|
8598
8525
|
return state;
|
|
8599
8526
|
}
|
|
@@ -8659,18 +8586,6 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
8659
8586
|
return values;
|
|
8660
8587
|
}
|
|
8661
8588
|
|
|
8662
|
-
const createHtmlRenderState = () => ({
|
|
8663
|
-
style: {},
|
|
8664
|
-
transform: {},
|
|
8665
|
-
transformOrigin: {},
|
|
8666
|
-
vars: {},
|
|
8667
|
-
});
|
|
8668
|
-
|
|
8669
|
-
const createSvgRenderState = () => ({
|
|
8670
|
-
...createHtmlRenderState(),
|
|
8671
|
-
attrs: {},
|
|
8672
|
-
});
|
|
8673
|
-
|
|
8674
8589
|
/**
|
|
8675
8590
|
* Provided a value and a ValueType, returns the value as that value type.
|
|
8676
8591
|
*/
|
|
@@ -8886,34 +8801,157 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
8886
8801
|
}
|
|
8887
8802
|
}
|
|
8888
8803
|
|
|
8804
|
+
const createHtmlRenderState = () => ({
|
|
8805
|
+
style: {},
|
|
8806
|
+
transform: {},
|
|
8807
|
+
transformOrigin: {},
|
|
8808
|
+
vars: {},
|
|
8809
|
+
});
|
|
8810
|
+
|
|
8811
|
+
const createSvgRenderState = () => ({
|
|
8812
|
+
...createHtmlRenderState(),
|
|
8813
|
+
attrs: {},
|
|
8814
|
+
});
|
|
8815
|
+
|
|
8889
8816
|
const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
|
|
8890
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"];
|
|
8891
8917
|
const svgMotionConfig = {
|
|
8892
8918
|
useVisualState: makeUseVisualState({
|
|
8893
8919
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
8894
8920
|
createRenderState: createSvgRenderState,
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
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
|
+
}
|
|
8903
8931
|
}
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
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
|
+
}
|
|
8912
8947
|
}
|
|
8913
|
-
}
|
|
8948
|
+
}
|
|
8949
|
+
if (!needsMeasure)
|
|
8950
|
+
return;
|
|
8951
|
+
frame.read(() => updateSVGDimensions(current, renderState));
|
|
8914
8952
|
frame.render(() => {
|
|
8915
|
-
buildSVGAttrs(renderState, latestValues, isSVGTag(
|
|
8916
|
-
renderSVG(
|
|
8953
|
+
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
8954
|
+
renderSVG(current, renderState);
|
|
8917
8955
|
});
|
|
8918
8956
|
},
|
|
8919
8957
|
}),
|
|
@@ -9191,7 +9229,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
9191
9229
|
* and warn against mismatches.
|
|
9192
9230
|
*/
|
|
9193
9231
|
if (process.env.NODE_ENV === "development") {
|
|
9194
|
-
warnOnce(nextValue.version === "11.17.
|
|
9232
|
+
warnOnce(nextValue.version === "11.17.1", `Attempting to mix Motion versions ${nextValue.version} with 11.17.1 may not work as expected.`);
|
|
9195
9233
|
}
|
|
9196
9234
|
}
|
|
9197
9235
|
else if (isMotionValue(prevValue)) {
|
|
@@ -9324,7 +9362,8 @@ class VisualElement {
|
|
|
9324
9362
|
frame.render(this.render, false, true);
|
|
9325
9363
|
}
|
|
9326
9364
|
};
|
|
9327
|
-
const { latestValues, renderState } = visualState;
|
|
9365
|
+
const { latestValues, renderState, onUpdate } = visualState;
|
|
9366
|
+
this.onUpdate = onUpdate;
|
|
9328
9367
|
this.latestValues = latestValues;
|
|
9329
9368
|
this.baseTarget = { ...latestValues };
|
|
9330
9369
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -9524,6 +9563,7 @@ class VisualElement {
|
|
|
9524
9563
|
if (this.handleChildMotionValue) {
|
|
9525
9564
|
this.handleChildMotionValue();
|
|
9526
9565
|
}
|
|
9566
|
+
this.onUpdate && this.onUpdate(this);
|
|
9527
9567
|
}
|
|
9528
9568
|
getProps() {
|
|
9529
9569
|
return this.props;
|