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/client.js
CHANGED
|
@@ -364,28 +364,13 @@ function delay(callback, timeout) {
|
|
|
364
364
|
return () => motionDom.cancelFrame(checkElapsed);
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
const isKeyframesTarget = (v) => {
|
|
368
|
-
return Array.isArray(v);
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
const isCustomValue = (v) => {
|
|
372
|
-
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
373
|
-
};
|
|
374
|
-
const resolveFinalValueInKeyframes = (v) => {
|
|
375
|
-
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
376
|
-
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
377
|
-
};
|
|
378
|
-
|
|
379
367
|
/**
|
|
380
368
|
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
381
369
|
*
|
|
382
370
|
* TODO: Remove and move to library
|
|
383
371
|
*/
|
|
384
372
|
function resolveMotionValue(value) {
|
|
385
|
-
|
|
386
|
-
return isCustomValue(unwrappedValue)
|
|
387
|
-
? unwrappedValue.toValue()
|
|
388
|
-
: unwrappedValue;
|
|
373
|
+
return isMotionValue(value) ? value.get() : value;
|
|
389
374
|
}
|
|
390
375
|
|
|
391
376
|
const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
|
|
@@ -2735,7 +2720,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
2735
2720
|
* and warn against mismatches.
|
|
2736
2721
|
*/
|
|
2737
2722
|
if (process.env.NODE_ENV === "development") {
|
|
2738
|
-
motionUtils.warnOnce(nextValue.version === "12.
|
|
2723
|
+
motionUtils.warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
|
|
2739
2724
|
}
|
|
2740
2725
|
}
|
|
2741
2726
|
else if (isMotionValue(prevValue)) {
|
|
@@ -2903,8 +2888,7 @@ class VisualElement {
|
|
|
2903
2888
|
motionDom.frame.render(this.render, false, true);
|
|
2904
2889
|
}
|
|
2905
2890
|
};
|
|
2906
|
-
const { latestValues, renderState
|
|
2907
|
-
this.onUpdate = onUpdate;
|
|
2891
|
+
const { latestValues, renderState } = visualState;
|
|
2908
2892
|
this.latestValues = latestValues;
|
|
2909
2893
|
this.baseTarget = { ...latestValues };
|
|
2910
2894
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -3106,7 +3090,6 @@ class VisualElement {
|
|
|
3106
3090
|
if (this.handleChildMotionValue) {
|
|
3107
3091
|
this.handleChildMotionValue();
|
|
3108
3092
|
}
|
|
3109
|
-
this.onUpdate && this.onUpdate(this);
|
|
3110
3093
|
}
|
|
3111
3094
|
getProps() {
|
|
3112
3095
|
return this.props;
|
|
@@ -3609,6 +3592,10 @@ function resolveVariant(visualElement, definition, custom) {
|
|
|
3609
3592
|
return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, visualElement);
|
|
3610
3593
|
}
|
|
3611
3594
|
|
|
3595
|
+
const isKeyframesTarget = (v) => {
|
|
3596
|
+
return Array.isArray(v);
|
|
3597
|
+
};
|
|
3598
|
+
|
|
3612
3599
|
/**
|
|
3613
3600
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
3614
3601
|
* it doesn't exist.
|
|
@@ -3621,6 +3608,10 @@ function setMotionValue(visualElement, key, value) {
|
|
|
3621
3608
|
visualElement.addValue(key, motionDom.motionValue(value));
|
|
3622
3609
|
}
|
|
3623
3610
|
}
|
|
3611
|
+
function resolveFinalValueInKeyframes(v) {
|
|
3612
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
3613
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
3614
|
+
}
|
|
3624
3615
|
function setTarget(visualElement, definition) {
|
|
3625
3616
|
const resolved = resolveVariant(visualElement, definition);
|
|
3626
3617
|
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
|
|
@@ -4504,7 +4495,7 @@ function calcViewportConstraints(layoutBox, constraintsBox) {
|
|
|
4504
4495
|
* Calculate a transform origin relative to the source axis, between 0-1, that results
|
|
4505
4496
|
* in an asthetically pleasing scale/transform needed to project from source to target.
|
|
4506
4497
|
*/
|
|
4507
|
-
function calcOrigin
|
|
4498
|
+
function calcOrigin(source, target) {
|
|
4508
4499
|
let origin = 0.5;
|
|
4509
4500
|
const sourceLength = calcLength(source);
|
|
4510
4501
|
const targetLength = calcLength(target);
|
|
@@ -4898,7 +4889,7 @@ class VisualElementDragControls {
|
|
|
4898
4889
|
const axisValue = this.getAxisMotionValue(axis);
|
|
4899
4890
|
if (axisValue && this.constraints !== false) {
|
|
4900
4891
|
const latest = axisValue.get();
|
|
4901
|
-
boxProgress[axis] = calcOrigin
|
|
4892
|
+
boxProgress[axis] = calcOrigin({ min: latest, max: latest }, this.constraints[axis]);
|
|
4902
4893
|
}
|
|
4903
4894
|
});
|
|
4904
4895
|
/**
|
|
@@ -5850,25 +5841,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
5850
5841
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
5851
5842
|
}
|
|
5852
5843
|
|
|
5853
|
-
function calcOrigin(origin, offset, size) {
|
|
5854
|
-
return typeof origin === "string"
|
|
5855
|
-
? origin
|
|
5856
|
-
: motionDom.px.transform(offset + size * origin);
|
|
5857
|
-
}
|
|
5858
|
-
/**
|
|
5859
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
5860
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
5861
|
-
*/
|
|
5862
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
5863
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
5864
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
5865
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
5866
|
-
}
|
|
5867
|
-
|
|
5868
5844
|
/**
|
|
5869
5845
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
5870
5846
|
*/
|
|
5871
|
-
function buildSVGAttrs(state, { attrX, attrY, attrScale,
|
|
5847
|
+
function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
5872
5848
|
// This is object creation, which we try to avoid per-frame.
|
|
5873
5849
|
...latest }, isSVGTag, transformTemplate) {
|
|
5874
5850
|
buildHTMLStyles(state, latest, transformTemplate);
|
|
@@ -5884,20 +5860,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
5884
5860
|
}
|
|
5885
5861
|
state.attrs = state.style;
|
|
5886
5862
|
state.style = {};
|
|
5887
|
-
const { attrs, style
|
|
5863
|
+
const { attrs, style } = state;
|
|
5888
5864
|
/**
|
|
5889
|
-
* However, we apply transforms as CSS transforms.
|
|
5890
|
-
* 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.
|
|
5891
5867
|
*/
|
|
5892
5868
|
if (attrs.transform) {
|
|
5893
|
-
|
|
5894
|
-
style.transform = attrs.transform;
|
|
5869
|
+
style.transform = attrs.transform;
|
|
5895
5870
|
delete attrs.transform;
|
|
5896
5871
|
}
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
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;
|
|
5901
5883
|
}
|
|
5902
5884
|
// Render attrX/attrY/attrScale as attributes
|
|
5903
5885
|
if (attrX !== undefined)
|
|
@@ -5961,20 +5943,11 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
5961
5943
|
return useRender;
|
|
5962
5944
|
}
|
|
5963
5945
|
|
|
5964
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
5946
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, }, props, context, presenceContext) {
|
|
5965
5947
|
const state = {
|
|
5966
5948
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
5967
5949
|
renderState: createRenderState(),
|
|
5968
5950
|
};
|
|
5969
|
-
if (onUpdate) {
|
|
5970
|
-
/**
|
|
5971
|
-
* onMount works without the VisualElement because it could be
|
|
5972
|
-
* called before the VisualElement payload has been hydrated.
|
|
5973
|
-
* (e.g. if someone is using m components <m.circle />)
|
|
5974
|
-
*/
|
|
5975
|
-
state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
|
|
5976
|
-
state.onUpdate = (visualElement) => onUpdate(visualElement);
|
|
5977
|
-
}
|
|
5978
5951
|
return state;
|
|
5979
5952
|
}
|
|
5980
5953
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
@@ -6046,22 +6019,41 @@ const htmlMotionConfig = {
|
|
|
6046
6019
|
}),
|
|
6047
6020
|
};
|
|
6048
6021
|
|
|
6049
|
-
function
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
x: 0,
|
|
6060
|
-
y: 0,
|
|
6061
|
-
width: 0,
|
|
6062
|
-
height: 0,
|
|
6063
|
-
};
|
|
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
|
+
}
|
|
6064
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
|
+
};
|
|
6065
6057
|
}
|
|
6066
6058
|
|
|
6067
6059
|
/**
|
|
@@ -6100,93 +6092,12 @@ function renderSVG(element, renderState, _styleProp, projection) {
|
|
|
6100
6092
|
}
|
|
6101
6093
|
}
|
|
6102
6094
|
|
|
6103
|
-
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
6104
|
-
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
6105
|
-
for (const key in props) {
|
|
6106
|
-
if (isMotionValue(props[key]) ||
|
|
6107
|
-
isMotionValue(prevProps[key])) {
|
|
6108
|
-
const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
|
|
6109
|
-
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
6110
|
-
: key;
|
|
6111
|
-
newValues[targetKey] = props[key];
|
|
6112
|
-
}
|
|
6113
|
-
}
|
|
6114
|
-
return newValues;
|
|
6115
|
-
}
|
|
6116
|
-
|
|
6117
|
-
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
|
|
6118
|
-
const svgMotionConfig = {
|
|
6119
|
-
useVisualState: makeUseVisualState({
|
|
6120
|
-
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
6121
|
-
createRenderState: createSvgRenderState,
|
|
6122
|
-
onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
|
|
6123
|
-
if (!current)
|
|
6124
|
-
return;
|
|
6125
|
-
let hasTransform = !!props.drag;
|
|
6126
|
-
if (!hasTransform) {
|
|
6127
|
-
for (const key in latestValues) {
|
|
6128
|
-
if (motionDom.transformProps.has(key)) {
|
|
6129
|
-
hasTransform = true;
|
|
6130
|
-
break;
|
|
6131
|
-
}
|
|
6132
|
-
}
|
|
6133
|
-
}
|
|
6134
|
-
if (!hasTransform)
|
|
6135
|
-
return;
|
|
6136
|
-
let needsMeasure = !prevProps;
|
|
6137
|
-
if (prevProps) {
|
|
6138
|
-
/**
|
|
6139
|
-
* Check the layout props for changes, if any are found we need to
|
|
6140
|
-
* measure the element again.
|
|
6141
|
-
*/
|
|
6142
|
-
for (let i = 0; i < layoutProps.length; i++) {
|
|
6143
|
-
const key = layoutProps[i];
|
|
6144
|
-
if (props[key] !==
|
|
6145
|
-
prevProps[key]) {
|
|
6146
|
-
needsMeasure = true;
|
|
6147
|
-
}
|
|
6148
|
-
}
|
|
6149
|
-
}
|
|
6150
|
-
if (!needsMeasure)
|
|
6151
|
-
return;
|
|
6152
|
-
motionDom.frame.read(() => {
|
|
6153
|
-
updateSVGDimensions(current, renderState);
|
|
6154
|
-
motionDom.frame.render(() => {
|
|
6155
|
-
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
6156
|
-
renderSVG(current, renderState);
|
|
6157
|
-
});
|
|
6158
|
-
});
|
|
6159
|
-
},
|
|
6160
|
-
}),
|
|
6161
|
-
};
|
|
6162
|
-
|
|
6163
|
-
function createMotionComponentFactory(preloadedFeatures, createVisualElement) {
|
|
6164
|
-
return function createMotionComponent(Component, { forwardMotionProps } = { forwardMotionProps: false }) {
|
|
6165
|
-
const baseConfig = isSVGComponent(Component)
|
|
6166
|
-
? svgMotionConfig
|
|
6167
|
-
: htmlMotionConfig;
|
|
6168
|
-
const config = {
|
|
6169
|
-
...baseConfig,
|
|
6170
|
-
preloadedFeatures,
|
|
6171
|
-
useRender: createUseRender(forwardMotionProps),
|
|
6172
|
-
createVisualElement,
|
|
6173
|
-
Component,
|
|
6174
|
-
};
|
|
6175
|
-
return createRendererMotionComponent(config);
|
|
6176
|
-
};
|
|
6177
|
-
}
|
|
6178
|
-
|
|
6179
6095
|
class SVGVisualElement extends DOMVisualElement {
|
|
6180
6096
|
constructor() {
|
|
6181
6097
|
super(...arguments);
|
|
6182
6098
|
this.type = "svg";
|
|
6183
6099
|
this.isSVGTag = false;
|
|
6184
6100
|
this.measureInstanceViewportBox = createBox;
|
|
6185
|
-
this.updateDimensions = () => {
|
|
6186
|
-
if (this.current && !this.renderState.dimensions) {
|
|
6187
|
-
updateSVGDimensions(this.current, this.renderState);
|
|
6188
|
-
}
|
|
6189
|
-
};
|
|
6190
6101
|
}
|
|
6191
6102
|
getBaseTargetFromProps(props, key) {
|
|
6192
6103
|
return props[key];
|
|
@@ -6202,11 +6113,6 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
6202
6113
|
scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
6203
6114
|
return scrapeMotionValuesFromProps(props, prevProps, visualElement);
|
|
6204
6115
|
}
|
|
6205
|
-
onBindTransform() {
|
|
6206
|
-
if (this.current && !this.renderState.dimensions) {
|
|
6207
|
-
motionDom.frame.postRender(this.updateDimensions);
|
|
6208
|
-
}
|
|
6209
|
-
}
|
|
6210
6116
|
build(renderState, latestValues, props) {
|
|
6211
6117
|
buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
|
|
6212
6118
|
}
|
package/dist/cjs/dom.js
CHANGED
|
@@ -345,11 +345,6 @@ const isKeyframesTarget = (v) => {
|
|
|
345
345
|
return Array.isArray(v);
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
-
const resolveFinalValueInKeyframes = (v) => {
|
|
349
|
-
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
350
|
-
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
351
|
-
};
|
|
352
|
-
|
|
353
348
|
function getValueState(visualElement) {
|
|
354
349
|
const state = [{}, {}];
|
|
355
350
|
visualElement?.values.forEach((value, key) => {
|
|
@@ -402,6 +397,10 @@ function setMotionValue(visualElement, key, value) {
|
|
|
402
397
|
visualElement.addValue(key, motionDom.motionValue(value));
|
|
403
398
|
}
|
|
404
399
|
}
|
|
400
|
+
function resolveFinalValueInKeyframes(v) {
|
|
401
|
+
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
402
|
+
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
403
|
+
}
|
|
405
404
|
function setTarget(visualElement, definition) {
|
|
406
405
|
const resolved = resolveVariant(visualElement, definition);
|
|
407
406
|
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
|
|
@@ -760,7 +759,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
760
759
|
* and warn against mismatches.
|
|
761
760
|
*/
|
|
762
761
|
if (process.env.NODE_ENV === "development") {
|
|
763
|
-
motionUtils.warnOnce(nextValue.version === "12.
|
|
762
|
+
motionUtils.warnOnce(nextValue.version === "12.8.2", `Attempting to mix Motion versions ${nextValue.version} with 12.8.2 may not work as expected.`);
|
|
764
763
|
}
|
|
765
764
|
}
|
|
766
765
|
else if (isMotionValue(prevValue)) {
|
|
@@ -893,8 +892,7 @@ class VisualElement {
|
|
|
893
892
|
motionDom.frame.render(this.render, false, true);
|
|
894
893
|
}
|
|
895
894
|
};
|
|
896
|
-
const { latestValues, renderState
|
|
897
|
-
this.onUpdate = onUpdate;
|
|
895
|
+
const { latestValues, renderState } = visualState;
|
|
898
896
|
this.latestValues = latestValues;
|
|
899
897
|
this.baseTarget = { ...latestValues };
|
|
900
898
|
this.initialValues = props.initial ? { ...latestValues } : {};
|
|
@@ -1096,7 +1094,6 @@ class VisualElement {
|
|
|
1096
1094
|
if (this.handleChildMotionValue) {
|
|
1097
1095
|
this.handleChildMotionValue();
|
|
1098
1096
|
}
|
|
1099
|
-
this.onUpdate && this.onUpdate(this);
|
|
1100
1097
|
}
|
|
1101
1098
|
getProps() {
|
|
1102
1099
|
return this.props;
|
|
@@ -1438,25 +1435,10 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
1438
1435
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
1439
1436
|
}
|
|
1440
1437
|
|
|
1441
|
-
function calcOrigin(origin, offset, size) {
|
|
1442
|
-
return typeof origin === "string"
|
|
1443
|
-
? origin
|
|
1444
|
-
: motionDom.px.transform(offset + size * origin);
|
|
1445
|
-
}
|
|
1446
|
-
/**
|
|
1447
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
1448
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
1449
|
-
*/
|
|
1450
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
1451
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
1452
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
1453
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
1438
|
/**
|
|
1457
1439
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1458
1440
|
*/
|
|
1459
|
-
function buildSVGAttrs(state, { attrX, attrY, attrScale,
|
|
1441
|
+
function buildSVGAttrs(state, { attrX, attrY, attrScale, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
1460
1442
|
// This is object creation, which we try to avoid per-frame.
|
|
1461
1443
|
...latest }, isSVGTag, transformTemplate) {
|
|
1462
1444
|
buildHTMLStyles(state, latest, transformTemplate);
|
|
@@ -1472,20 +1454,26 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
1472
1454
|
}
|
|
1473
1455
|
state.attrs = state.style;
|
|
1474
1456
|
state.style = {};
|
|
1475
|
-
const { attrs, style
|
|
1457
|
+
const { attrs, style } = state;
|
|
1476
1458
|
/**
|
|
1477
|
-
* However, we apply transforms as CSS transforms.
|
|
1478
|
-
* 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.
|
|
1479
1461
|
*/
|
|
1480
1462
|
if (attrs.transform) {
|
|
1481
|
-
|
|
1482
|
-
style.transform = attrs.transform;
|
|
1463
|
+
style.transform = attrs.transform;
|
|
1483
1464
|
delete attrs.transform;
|
|
1484
1465
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
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;
|
|
1489
1477
|
}
|
|
1490
1478
|
// Render attrX/attrY/attrScale as attributes
|
|
1491
1479
|
if (attrX !== undefined)
|
|
@@ -1531,24 +1519,6 @@ const camelCaseAttributes = new Set([
|
|
|
1531
1519
|
|
|
1532
1520
|
const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
|
|
1533
1521
|
|
|
1534
|
-
function updateSVGDimensions(instance, renderState) {
|
|
1535
|
-
try {
|
|
1536
|
-
renderState.dimensions =
|
|
1537
|
-
typeof instance.getBBox === "function"
|
|
1538
|
-
? instance.getBBox()
|
|
1539
|
-
: instance.getBoundingClientRect();
|
|
1540
|
-
}
|
|
1541
|
-
catch (e) {
|
|
1542
|
-
// Most likely trying to measure an unrendered element under Firefox
|
|
1543
|
-
renderState.dimensions = {
|
|
1544
|
-
x: 0,
|
|
1545
|
-
y: 0,
|
|
1546
|
-
width: 0,
|
|
1547
|
-
height: 0,
|
|
1548
|
-
};
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
1522
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1553
1523
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
1554
1524
|
// Loop over any CSS variables and assign those.
|
|
@@ -1608,11 +1578,6 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
1608
1578
|
this.type = "svg";
|
|
1609
1579
|
this.isSVGTag = false;
|
|
1610
1580
|
this.measureInstanceViewportBox = createBox;
|
|
1611
|
-
this.updateDimensions = () => {
|
|
1612
|
-
if (this.current && !this.renderState.dimensions) {
|
|
1613
|
-
updateSVGDimensions(this.current, this.renderState);
|
|
1614
|
-
}
|
|
1615
|
-
};
|
|
1616
1581
|
}
|
|
1617
1582
|
getBaseTargetFromProps(props, key) {
|
|
1618
1583
|
return props[key];
|
|
@@ -1628,11 +1593,6 @@ class SVGVisualElement extends DOMVisualElement {
|
|
|
1628
1593
|
scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
1629
1594
|
return scrapeMotionValuesFromProps(props, prevProps, visualElement);
|
|
1630
1595
|
}
|
|
1631
|
-
onBindTransform() {
|
|
1632
|
-
if (this.current && !this.renderState.dimensions) {
|
|
1633
|
-
motionDom.frame.postRender(this.updateDimensions);
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
1596
|
build(renderState, latestValues, props) {
|
|
1637
1597
|
buildSVGAttrs(renderState, latestValues, this.isSVGTag, props.transformTemplate);
|
|
1638
1598
|
}
|
|
@@ -2589,24 +2549,6 @@ function distance2D(a, b) {
|
|
|
2589
2549
|
return Math.sqrt(xDelta ** 2 + yDelta ** 2);
|
|
2590
2550
|
}
|
|
2591
2551
|
|
|
2592
|
-
const isCustomValueType = (v) => {
|
|
2593
|
-
return v && typeof v === "object" && v.mix;
|
|
2594
|
-
};
|
|
2595
|
-
const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
|
|
2596
|
-
function transform(...args) {
|
|
2597
|
-
const useImmediate = !Array.isArray(args[0]);
|
|
2598
|
-
const argOffset = useImmediate ? 0 : -1;
|
|
2599
|
-
const inputValue = args[0 + argOffset];
|
|
2600
|
-
const inputRange = args[1 + argOffset];
|
|
2601
|
-
const outputRange = args[2 + argOffset];
|
|
2602
|
-
const options = args[3 + argOffset];
|
|
2603
|
-
const interpolator = motionDom.interpolate(inputRange, outputRange, {
|
|
2604
|
-
mixer: getMixer(outputRange[0]),
|
|
2605
|
-
...options,
|
|
2606
|
-
});
|
|
2607
|
-
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
2552
|
exports.animate = animate;
|
|
2611
2553
|
exports.animateMini = animateMini;
|
|
2612
2554
|
exports.createScopedAnimate = createScopedAnimate;
|
|
@@ -2617,7 +2559,6 @@ exports.inView = inView;
|
|
|
2617
2559
|
exports.scroll = scroll;
|
|
2618
2560
|
exports.scrollInfo = scrollInfo;
|
|
2619
2561
|
exports.stagger = stagger;
|
|
2620
|
-
exports.transform = transform;
|
|
2621
2562
|
Object.keys(motionDom).forEach(function (k) {
|
|
2622
2563
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2623
2564
|
enumerable: true,
|
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
|
|
|
@@ -636,24 +636,6 @@ function useMotionValue(initial) {
|
|
|
636
636
|
return value;
|
|
637
637
|
}
|
|
638
638
|
|
|
639
|
-
const isCustomValueType = (v) => {
|
|
640
|
-
return v && typeof v === "object" && v.mix;
|
|
641
|
-
};
|
|
642
|
-
const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
|
|
643
|
-
function transform(...args) {
|
|
644
|
-
const useImmediate = !Array.isArray(args[0]);
|
|
645
|
-
const argOffset = useImmediate ? 0 : -1;
|
|
646
|
-
const inputValue = args[0 + argOffset];
|
|
647
|
-
const inputRange = args[1 + argOffset];
|
|
648
|
-
const outputRange = args[2 + argOffset];
|
|
649
|
-
const options = args[3 + argOffset];
|
|
650
|
-
const interpolator = motionDom.interpolate(inputRange, outputRange, {
|
|
651
|
-
mixer: getMixer(outputRange[0]),
|
|
652
|
-
...options,
|
|
653
|
-
});
|
|
654
|
-
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
639
|
function useCombineMotionValues(values, combineValues) {
|
|
658
640
|
/**
|
|
659
641
|
* Initialise the returned motion value. This remains the same between renders.
|
|
@@ -707,7 +689,7 @@ function useTransform(input, inputRangeOrTransformer, outputRange, options) {
|
|
|
707
689
|
}
|
|
708
690
|
const transformer = typeof inputRangeOrTransformer === "function"
|
|
709
691
|
? inputRangeOrTransformer
|
|
710
|
-
: transform(inputRangeOrTransformer, outputRange, options);
|
|
692
|
+
: motionDom.transform(inputRangeOrTransformer, outputRange, options);
|
|
711
693
|
return Array.isArray(input)
|
|
712
694
|
? useListTransform(input, transformer)
|
|
713
695
|
: useListTransform([input], ([latest]) => transformer(latest));
|
|
@@ -3021,7 +3003,6 @@ exports.scroll = scroll;
|
|
|
3021
3003
|
exports.scrollInfo = scrollInfo;
|
|
3022
3004
|
exports.stagger = stagger;
|
|
3023
3005
|
exports.startOptimizedAppearAnimation = startOptimizedAppearAnimation;
|
|
3024
|
-
exports.transform = transform;
|
|
3025
3006
|
exports.unwrapMotionComponent = unwrapMotionComponent;
|
|
3026
3007
|
exports.useAnimate = useAnimate;
|
|
3027
3008
|
exports.useAnimateMini = useAnimateMini;
|