framer-motion 12.8.0 → 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-Bv1Fn_mR.js → create-M6GRDJBe.js} +55 -142
- package/dist/cjs/dom.js +18 -57
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/m.js +17 -136
- package/dist/dom.js +1 -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/framer-motion.dev.js +55 -144
- package/dist/framer-motion.js +1 -1
- 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 +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/{types.d-DUA-weyD.d.ts → types.d-DDSxwf0n.d.ts} +2 -12
- 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/cjs/client.js
CHANGED
|
@@ -2720,7 +2720,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
2720
2720
|
* and warn against mismatches.
|
|
2721
2721
|
*/
|
|
2722
2722
|
if (process.env.NODE_ENV === "development") {
|
|
2723
|
-
motionUtils.warnOnce(nextValue.version === "12.8.
|
|
2723
|
+
motionUtils.warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
|
|
2724
2724
|
}
|
|
2725
2725
|
}
|
|
2726
2726
|
else if (isMotionValue(prevValue)) {
|
|
@@ -2888,8 +2888,7 @@ class VisualElement {
|
|
|
2888
2888
|
motionDom.frame.render(this.render, false, true);
|
|
2889
2889
|
}
|
|
2890
2890
|
};
|
|
2891
|
-
const { latestValues, renderState
|
|
2892
|
-
this.onUpdate = onUpdate;
|
|
2891
|
+
const { latestValues, renderState } = visualState;
|
|
2893
2892
|
this.latestValues = latestValues;
|
|
2894
2893
|
this.baseTarget = { ...latestValues };
|
|
2895
2894
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -3091,7 +3090,6 @@ class VisualElement {
|
|
|
3091
3090
|
if (this.handleChildMotionValue) {
|
|
3092
3091
|
this.handleChildMotionValue();
|
|
3093
3092
|
}
|
|
3094
|
-
this.onUpdate && this.onUpdate(this);
|
|
3095
3093
|
}
|
|
3096
3094
|
getProps() {
|
|
3097
3095
|
return this.props;
|
|
@@ -4497,7 +4495,7 @@ function calcViewportConstraints(layoutBox, constraintsBox) {
|
|
|
4497
4495
|
* Calculate a transform origin relative to the source axis, between 0-1, that results
|
|
4498
4496
|
* in an asthetically pleasing scale/transform needed to project from source to target.
|
|
4499
4497
|
*/
|
|
4500
|
-
function calcOrigin
|
|
4498
|
+
function calcOrigin(source, target) {
|
|
4501
4499
|
let origin = 0.5;
|
|
4502
4500
|
const sourceLength = calcLength(source);
|
|
4503
4501
|
const targetLength = calcLength(target);
|
|
@@ -4891,7 +4889,7 @@ class VisualElementDragControls {
|
|
|
4891
4889
|
const axisValue = this.getAxisMotionValue(axis);
|
|
4892
4890
|
if (axisValue && this.constraints !== false) {
|
|
4893
4891
|
const latest = axisValue.get();
|
|
4894
|
-
boxProgress[axis] = calcOrigin
|
|
4892
|
+
boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]);
|
|
4895
4893
|
}
|
|
4896
4894
|
});
|
|
4897
4895
|
/**
|
|
@@ -5843,25 +5841,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
5843
5841
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
5844
5842
|
}
|
|
5845
5843
|
|
|
5846
|
-
function calcOrigin(origin, offset, size) {
|
|
5847
|
-
return typeof origin === "string"
|
|
5848
|
-
? origin
|
|
5849
|
-
: motionDom.px.transform(offset + size * origin);
|
|
5850
|
-
}
|
|
5851
|
-
/**
|
|
5852
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5853
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5854
|
-
*/
|
|
5855
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5856
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
5857
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
5858
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
5859
|
-
}
|
|
5860
|
-
|
|
5861
5844
|
/**
|
|
5862
5845
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
5863
5846
|
*/
|
|
5864
|
-
function buildSVGAttrs(state, { attrX, attrY, attrScale,
|
|
5847
|
+
function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
5865
5848
|
// This is object creation, which we try to avoid per-frame.
|
|
5866
5849
|
...latest }, isSVGTag, transformTemplate) {
|
|
5867
5850
|
buildHTMLStyles(state, latest, transformTemplate);
|
|
@@ -5877,20 +5860,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
5877
5860
|
}
|
|
5878
5861
|
state.attrs = state.style;
|
|
5879
5862
|
state.style = {};
|
|
5880
|
-
const { attrs, style
|
|
5863
|
+
const { attrs, style } = state;
|
|
5881
5864
|
/**
|
|
5882
|
-
* However, we apply transforms as CSS transforms.
|
|
5883
|
-
* and copy it into style.
|
|
5865
|
+
* However, we apply transforms as CSS transforms.
|
|
5866
|
+
* So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
|
|
5884
5867
|
*/
|
|
5885
5868
|
if (attrs.transform) {
|
|
5886
|
-
|
|
5887
|
-
style.transform = attrs.transform;
|
|
5869
|
+
style.transform = attrs.transform;
|
|
5888
5870
|
delete attrs.transform;
|
|
5889
5871
|
}
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5872
|
+
if (style.transform || attrs.transformOrigin) {
|
|
5873
|
+
style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
|
|
5874
|
+
delete attrs.transformOrigin;
|
|
5875
|
+
}
|
|
5876
|
+
if (style.transform) {
|
|
5877
|
+
/**
|
|
5878
|
+
* SVG's element transform-origin uses its own median as a reference.
|
|
5879
|
+
* Therefore, transformBox becomes a fill-box
|
|
5880
|
+
*/
|
|
5881
|
+
style.transformBox = "fill-box";
|
|
5882
|
+
delete attrs.transformBox;
|
|
5894
5883
|
}
|
|
5895
5884
|
// Render attrX/attrY/attrScale as attributes
|
|
5896
5885
|
if (attrX !== undefined)
|
|
@@ -5954,20 +5943,11 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
5954
5943
|
return useRender;
|
|
5955
5944
|
}
|
|
5956
5945
|
|
|
5957
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
5946
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
|
|
5958
5947
|
const state = {
|
|
5959
5948
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
5960
5949
|
renderState: createRenderState(),
|
|
5961
5950
|
};
|
|
5962
|
-
if (onUpdate) {
|
|
5963
|
-
/**
|
|
5964
|
-
* onMount works without the VisualElement because it could be
|
|
5965
|
-
* called before the VisualElement payload has been hydrated.
|
|
5966
|
-
* (e.g. if someone is using m components <m.circle />)
|
|
5967
|
-
*/
|
|
5968
|
-
state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
|
|
5969
|
-
state.onUpdate = (visualElement) => onUpdate(visualElement);
|
|
5970
|
-
}
|
|
5971
5951
|
return state;
|
|
5972
5952
|
}
|
|
5973
5953
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
@@ -6039,22 +6019,41 @@ const htmlMotionConfig = {
|
|
|
6039
6019
|
}),
|
|
6040
6020
|
};
|
|
6041
6021
|
|
|
6042
|
-
function
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
x: 0,
|
|
6053
|
-
y: 0,
|
|
6054
|
-
width: 0,
|
|
6055
|
-
height: 0,
|
|
6056
|
-
};
|
|
6022
|
+
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
6023
|
+
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
6024
|
+
for (const key in props) {
|
|
6025
|
+
if (isMotionValue(props[key]) ||
|
|
6026
|
+
isMotionValue(prevProps[key])) {
|
|
6027
|
+
const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
|
|
6028
|
+
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
6029
|
+
: key;
|
|
6030
|
+
newValues[targetKey] = props[key];
|
|
6031
|
+
}
|
|
6057
6032
|
}
|
|
6033
|
+
return newValues;
|
|
6034
|
+
}
|
|
6035
|
+
|
|
6036
|
+
const svgMotionConfig = {
|
|
6037
|
+
useVisualState: makeUseVisualState({
|
|
6038
|
+
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
6039
|
+
createRenderState: createSvgRenderState,
|
|
6040
|
+
}),
|
|
6041
|
+
};
|
|
6042
|
+
|
|
6043
|
+
function createMotionComponentFactory(preloadedFeatures, createVisualElement) {
|
|
6044
|
+
return function createMotionComponent(Component, { forwardMotionProps } = { forwardMotionProps: false }) {
|
|
6045
|
+
const baseConfig = isSVGComponent(Component)
|
|
6046
|
+
? svgMotionConfig
|
|
6047
|
+
: htmlMotionConfig;
|
|
6048
|
+
const config = {
|
|
6049
|
+
...baseConfig,
|
|
6050
|
+
preloadedFeatures,
|
|
6051
|
+
useRender: createUseRender(forwardMotionProps),
|
|
6052
|
+
createVisualElement,
|
|
6053
|
+
Component,
|
|
6054
|
+
};
|
|
6055
|
+
return createRendererMotionComponent(config);
|
|
6056
|
+
};
|
|
6058
6057
|
}
|
|
6059
6058
|
|
|
6060
6059
|
/**
|
|
@@ -6093,93 +6092,12 @@ function renderSVG(element, renderState, _styleProp, projection) {
|
|
|
6093
6092
|
}
|
|
6094
6093
|
}
|
|
6095
6094
|
|
|
6096
|
-
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
6097
|
-
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
6098
|
-
for (const key in props) {
|
|
6099
|
-
if (isMotionValue(props[key]) ||
|
|
6100
|
-
isMotionValue(prevProps[key])) {
|
|
6101
|
-
const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
|
|
6102
|
-
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
6103
|
-
: key;
|
|
6104
|
-
newValues[targetKey] = props[key];
|
|
6105
|
-
}
|
|
6106
|
-
}
|
|
6107
|
-
return newValues;
|
|
6108
|
-
}
|
|
6109
|
-
|
|
6110
|
-
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
|
|
6111
|
-
const svgMotionConfig = {
|
|
6112
|
-
useVisualState: makeUseVisualState({
|
|
6113
|
-
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
6114
|
-
createRenderState: createSvgRenderState,
|
|
6115
|
-
onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
|
|
6116
|
-
if (!current)
|
|
6117
|
-
return;
|
|
6118
|
-
let hasTransform = !!props.drag;
|
|
6119
|
-
if (!hasTransform) {
|
|
6120
|
-
for (const key in latestValues) {
|
|
6121
|
-
if (motionDom.transformProps.has(key)) {
|
|
6122
|
-
hasTransform = true;
|
|
6123
|
-
break;
|
|
6124
|
-
}
|
|
6125
|
-
}
|
|
6126
|
-
}
|
|
6127
|
-
if (!hasTransform)
|
|
6128
|
-
return;
|
|
6129
|
-
let needsMeasure = !prevProps;
|
|
6130
|
-
if (prevProps) {
|
|
6131
|
-
/**
|
|
6132
|
-
* Check the layout props for changes, if any are found we need to
|
|
6133
|
-
* measure the element again.
|
|
6134
|
-
*/
|
|
6135
|
-
for (let i = 0; i < layoutProps.length; i++) {
|
|
6136
|
-
const key = layoutProps[i];
|
|
6137
|
-
if (props[key] !==
|
|
6138
|
-
prevProps[key]) {
|
|
6139
|
-
needsMeasure = true;
|
|
6140
|
-
}
|
|
6141
|
-
}
|
|
6142
|
-
}
|
|
6143
|
-
if (!needsMeasure)
|
|
6144
|
-
return;
|
|
6145
|
-
motionDom.frame.read(() => {
|
|
6146
|
-
updateSVGDimensions(current, renderState);
|
|
6147
|
-
motionDom.frame.render(() => {
|
|
6148
|
-
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
6149
|
-
renderSVG(current, renderState);
|
|
6150
|
-
});
|
|
6151
|
-
});
|
|
6152
|
-
},
|
|
6153
|
-
}),
|
|
6154
|
-
};
|
|
6155
|
-
|
|
6156
|
-
function createMotionComponentFactory(preloadedFeatures, createVisualElement) {
|
|
6157
|
-
return function createMotionComponent(Component, { forwardMotionProps } = { forwardMotionProps: false }) {
|
|
6158
|
-
const baseConfig = isSVGComponent(Component)
|
|
6159
|
-
? svgMotionConfig
|
|
6160
|
-
: htmlMotionConfig;
|
|
6161
|
-
const config = {
|
|
6162
|
-
...baseConfig,
|
|
6163
|
-
preloadedFeatures,
|
|
6164
|
-
useRender: createUseRender(forwardMotionProps),
|
|
6165
|
-
createVisualElement,
|
|
6166
|
-
Component,
|
|
6167
|
-
};
|
|
6168
|
-
return createRendererMotionComponent(config);
|
|
6169
|
-
};
|
|
6170
|
-
}
|
|
6171
|
-
|
|
6172
6095
|
class SVGVisualElement extends DOMVisualElement {
|
|
6173
6096
|
constructor() {
|
|
6174
6097
|
super(...arguments);
|
|
6175
6098
|
this.type = "svg";
|
|
6176
6099
|
this.isSVGTag = false;
|
|
6177
6100
|
this.measureInstanceViewportBox = createBox;
|
|
6178
|
-
this.updateDimensions = () => {
|
|
6179
|
-
if (this.current && !this.renderState.dimensions) {
|
|
6180
|
-
updateSVGDimensions(this.current, this.renderState);
|
|
6181
|
-
}
|
|
6182
|
-
};
|
|
6183
6101
|
}
|
|
6184
6102
|
getBaseTargetFromProps(props, key) {
|
|
6185
6103
|
return props[key];
|
|
@@ -6195,11 +6113,6 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
6195
6113
|
scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
6196
6114
|
return scrapeMotionValuesFromProps(props, prevProps, visualElement);
|
|
6197
6115
|
}
|
|
6198
|
-
onBindTransform() {
|
|
6199
|
-
if (this.current && !this.renderState.dimensions) {
|
|
6200
|
-
motionDom.frame.postRender(this.updateDimensions);
|
|
6201
|
-
}
|
|
6202
|
-
}
|
|
6203
6116
|
build(renderState, latestValues, props) {
|
|
6204
6117
|
buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
|
|
6205
6118
|
}
|
package/dist/cjs/dom.js
CHANGED
|
@@ -759,7 +759,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
759
759
|
* and warn against mismatches.
|
|
760
760
|
*/
|
|
761
761
|
if (process.env.NODE_ENV === "development") {
|
|
762
|
-
motionUtils.warnOnce(nextValue.version === "12.8.
|
|
762
|
+
motionUtils.warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
|
|
763
763
|
}
|
|
764
764
|
}
|
|
765
765
|
else if (isMotionValue(prevValue)) {
|
|
@@ -892,8 +892,7 @@ class VisualElement {
|
|
|
892
892
|
motionDom.frame.render(this.render, false, true);
|
|
893
893
|
}
|
|
894
894
|
};
|
|
895
|
-
const { latestValues, renderState
|
|
896
|
-
this.onUpdate = onUpdate;
|
|
895
|
+
const { latestValues, renderState } = visualState;
|
|
897
896
|
this.latestValues = latestValues;
|
|
898
897
|
this.baseTarget = { ...latestValues };
|
|
899
898
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -1095,7 +1094,6 @@ class VisualElement {
|
|
|
1095
1094
|
if (this.handleChildMotionValue) {
|
|
1096
1095
|
this.handleChildMotionValue();
|
|
1097
1096
|
}
|
|
1098
|
-
this.onUpdate && this.onUpdate(this);
|
|
1099
1097
|
}
|
|
1100
1098
|
getProps() {
|
|
1101
1099
|
return this.props;
|
|
@@ -1437,25 +1435,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
1437
1435
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
1438
1436
|
}
|
|
1439
1437
|
|
|
1440
|
-
function calcOrigin(origin, offset, size) {
|
|
1441
|
-
return typeof origin === "string"
|
|
1442
|
-
? origin
|
|
1443
|
-
: motionDom.px.transform(offset + size * origin);
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
1447
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
1448
|
-
*/
|
|
1449
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
1450
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
1451
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
1452
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
1438
|
/**
|
|
1456
1439
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1457
1440
|
*/
|
|
1458
|
-
function buildSVGAttrs(state, { attrX, attrY, attrScale,
|
|
1441
|
+
function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
1459
1442
|
// This is object creation, which we try to avoid per-frame.
|
|
1460
1443
|
...latest }, isSVGTag, transformTemplate) {
|
|
1461
1444
|
buildHTMLStyles(state, latest, transformTemplate);
|
|
@@ -1471,20 +1454,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
1471
1454
|
}
|
|
1472
1455
|
state.attrs = state.style;
|
|
1473
1456
|
state.style = {};
|
|
1474
|
-
const { attrs, style
|
|
1457
|
+
const { attrs, style } = state;
|
|
1475
1458
|
/**
|
|
1476
|
-
* However, we apply transforms as CSS transforms.
|
|
1477
|
-
* and copy it into style.
|
|
1459
|
+
* However, we apply transforms as CSS transforms.
|
|
1460
|
+
* So if we detect a transform, transformOrigin we take it from attrs and copy it into style.
|
|
1478
1461
|
*/
|
|
1479
1462
|
if (attrs.transform) {
|
|
1480
|
-
|
|
1481
|
-
style.transform = attrs.transform;
|
|
1463
|
+
style.transform = attrs.transform;
|
|
1482
1464
|
delete attrs.transform;
|
|
1483
1465
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1466
|
+
if (style.transform || attrs.transformOrigin) {
|
|
1467
|
+
style.transformOrigin = attrs.transformOrigin ?? "50% 50%";
|
|
1468
|
+
delete attrs.transformOrigin;
|
|
1469
|
+
}
|
|
1470
|
+
if (style.transform) {
|
|
1471
|
+
/**
|
|
1472
|
+
* SVG's element transform-origin uses its own median as a reference.
|
|
1473
|
+
* Therefore, transformBox becomes a fill-box
|
|
1474
|
+
*/
|
|
1475
|
+
style.transformBox = "fill-box";
|
|
1476
|
+
delete attrs.transformBox;
|
|
1488
1477
|
}
|
|
1489
1478
|
// Render attrX/attrY/attrScale as attributes
|
|
1490
1479
|
if (attrX !== undefined)
|
|
@@ -1530,24 +1519,6 @@ const camelCaseAttributes = new Set([
|
|
|
1530
1519
|
|
|
1531
1520
|
const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
|
|
1532
1521
|
|
|
1533
|
-
function updateSVGDimensions(instance, renderState) {
|
|
1534
|
-
try {
|
|
1535
|
-
renderState.dimensions =
|
|
1536
|
-
typeof instance.getBBox === "function"
|
|
1537
|
-
? instance.getBBox()
|
|
1538
|
-
: instance.getBoundingClientRect();
|
|
1539
|
-
}
|
|
1540
|
-
catch (e) {
|
|
1541
|
-
// Most likely trying to measure an unrendered element under Firefox
|
|
1542
|
-
renderState.dimensions = {
|
|
1543
|
-
x: 0,
|
|
1544
|
-
y: 0,
|
|
1545
|
-
width: 0,
|
|
1546
|
-
height: 0,
|
|
1547
|
-
};
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
1522
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1552
1523
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
1553
1524
|
// Loop over any CSS variables and assign those.
|
|
@@ -1607,11 +1578,6 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
1607
1578
|
this.type = "svg";
|
|
1608
1579
|
this.isSVGTag = false;
|
|
1609
1580
|
this.measureInstanceViewportBox = createBox;
|
|
1610
|
-
this.updateDimensions = () => {
|
|
1611
|
-
if (this.current && !this.renderState.dimensions) {
|
|
1612
|
-
updateSVGDimensions(this.current, this.renderState);
|
|
1613
|
-
}
|
|
1614
|
-
};
|
|
1615
1581
|
}
|
|
1616
1582
|
getBaseTargetFromProps(props, key) {
|
|
1617
1583
|
return props[key];
|
|
@@ -1627,11 +1593,6 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
1627
1593
|
scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
1628
1594
|
return scrapeMotionValuesFromProps(props, prevProps, visualElement);
|
|
1629
1595
|
}
|
|
1630
|
-
onBindTransform() {
|
|
1631
|
-
if (this.current && !this.renderState.dimensions) {
|
|
1632
|
-
motionDom.frame.postRender(this.updateDimensions);
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
1596
|
build(renderState, latestValues, props) {
|
|
1636
1597
|
buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
|
|
1637
1598
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var create = require('./create-
|
|
7
|
+
var create = require('./create-M6GRDJBe.js');
|
|
8
8
|
var motionDom = require('motion-dom');
|
|
9
9
|
var motionUtils = require('motion-utils');
|
|
10
10
|
|
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)
|
|
@@ -934,20 +925,11 @@ function resolveMotionValue(value) {
|
|
|
934
925
|
return isMotionValue(value) ? value.get() : value;
|
|
935
926
|
}
|
|
936
927
|
|
|
937
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
928
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
|
|
938
929
|
const state = {
|
|
939
930
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
940
931
|
renderState: createRenderState(),
|
|
941
932
|
};
|
|
942
|
-
if (onUpdate) {
|
|
943
|
-
/**
|
|
944
|
-
* onMount works without the VisualElement because it could be
|
|
945
|
-
* called before the VisualElement payload has been hydrated.
|
|
946
|
-
* (e.g. if someone is using m components <m.circle />)
|
|
947
|
-
*/
|
|
948
|
-
state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
|
|
949
|
-
state.onUpdate = (visualElement) => onUpdate(visualElement);
|
|
950
|
-
}
|
|
951
933
|
return state;
|
|
952
934
|
}
|
|
953
935
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
@@ -1034,68 +1016,6 @@ const htmlMotionConfig = {
|
|
|
1034
1016
|
}),
|
|
1035
1017
|
};
|
|
1036
1018
|
|
|
1037
|
-
function updateSVGDimensions(instance, renderState) {
|
|
1038
|
-
try {
|
|
1039
|
-
renderState.dimensions =
|
|
1040
|
-
typeof instance.getBBox === "function"
|
|
1041
|
-
? instance.getBBox()
|
|
1042
|
-
: instance.getBoundingClientRect();
|
|
1043
|
-
}
|
|
1044
|
-
catch (e) {
|
|
1045
|
-
// Most likely trying to measure an unrendered element under Firefox
|
|
1046
|
-
renderState.dimensions = {
|
|
1047
|
-
x: 0,
|
|
1048
|
-
y: 0,
|
|
1049
|
-
width: 0,
|
|
1050
|
-
height: 0,
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1056
|
-
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
1057
|
-
// Loop over any CSS variables and assign those.
|
|
1058
|
-
for (const key in vars) {
|
|
1059
|
-
element.style.setProperty(key, vars[key]);
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
/**
|
|
1064
|
-
* A set of attribute names that are always read/written as camel case.
|
|
1065
|
-
*/
|
|
1066
|
-
const camelCaseAttributes = new Set([
|
|
1067
|
-
"baseFrequency",
|
|
1068
|
-
"diffuseConstant",
|
|
1069
|
-
"kernelMatrix",
|
|
1070
|
-
"kernelUnitLength",
|
|
1071
|
-
"keySplines",
|
|
1072
|
-
"keyTimes",
|
|
1073
|
-
"limitingConeAngle",
|
|
1074
|
-
"markerHeight",
|
|
1075
|
-
"markerWidth",
|
|
1076
|
-
"numOctaves",
|
|
1077
|
-
"targetX",
|
|
1078
|
-
"targetY",
|
|
1079
|
-
"surfaceScale",
|
|
1080
|
-
"specularConstant",
|
|
1081
|
-
"specularExponent",
|
|
1082
|
-
"stdDeviation",
|
|
1083
|
-
"tableValues",
|
|
1084
|
-
"viewBox",
|
|
1085
|
-
"gradientTransform",
|
|
1086
|
-
"pathLength",
|
|
1087
|
-
"startOffset",
|
|
1088
|
-
"textLength",
|
|
1089
|
-
"lengthAdjust",
|
|
1090
|
-
]);
|
|
1091
|
-
|
|
1092
|
-
function renderSVG(element, renderState, _styleProp, projection) {
|
|
1093
|
-
renderHTML(element, renderState, undefined, projection);
|
|
1094
|
-
for (const key in renderState.attrs) {
|
|
1095
|
-
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
1019
|
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
1100
1020
|
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
1101
1021
|
for (const key in props) {
|
|
@@ -1110,49 +1030,10 @@ function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
|
1110
1030
|
return newValues;
|
|
1111
1031
|
}
|
|
1112
1032
|
|
|
1113
|
-
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
|
|
1114
1033
|
const svgMotionConfig = {
|
|
1115
1034
|
useVisualState: makeUseVisualState({
|
|
1116
1035
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
1117
1036
|
createRenderState: createSvgRenderState,
|
|
1118
|
-
onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
|
|
1119
|
-
if (!current)
|
|
1120
|
-
return;
|
|
1121
|
-
let hasTransform = !!props.drag;
|
|
1122
|
-
if (!hasTransform) {
|
|
1123
|
-
for (const key in latestValues) {
|
|
1124
|
-
if (motionDom.transformProps.has(key)) {
|
|
1125
|
-
hasTransform = true;
|
|
1126
|
-
break;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
if (!hasTransform)
|
|
1131
|
-
return;
|
|
1132
|
-
let needsMeasure = !prevProps;
|
|
1133
|
-
if (prevProps) {
|
|
1134
|
-
/**
|
|
1135
|
-
* Check the layout props for changes, if any are found we need to
|
|
1136
|
-
* measure the element again.
|
|
1137
|
-
*/
|
|
1138
|
-
for (let i = 0; i < layoutProps.length; i++) {
|
|
1139
|
-
const key = layoutProps[i];
|
|
1140
|
-
if (props[key] !==
|
|
1141
|
-
prevProps[key]) {
|
|
1142
|
-
needsMeasure = true;
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
if (!needsMeasure)
|
|
1147
|
-
return;
|
|
1148
|
-
motionDom.frame.read(() => {
|
|
1149
|
-
updateSVGDimensions(current, renderState);
|
|
1150
|
-
motionDom.frame.render(() => {
|
|
1151
|
-
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
1152
|
-
renderSVG(current, renderState);
|
|
1153
|
-
});
|
|
1154
|
-
});
|
|
1155
|
-
},
|
|
1156
1037
|
}),
|
|
1157
1038
|
};
|
|
1158
1039
|
|