framer-motion 7.0.3 → 7.1.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/index.js +2090 -2304
- package/dist/es/animation/animate.mjs +4 -5
- package/dist/es/animation/animation-controls.mjs +22 -24
- package/dist/es/animation/use-animated-state.mjs +23 -25
- package/dist/es/animation/use-animation.mjs +2 -2
- package/dist/es/animation/utils/default-transitions.mjs +13 -14
- package/dist/es/animation/utils/easing.mjs +20 -21
- package/dist/es/animation/utils/is-animatable.mjs +1 -1
- package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +30 -31
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
- package/dist/es/components/AnimatePresence/index.mjs +33 -35
- package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
- package/dist/es/components/AnimateSharedLayout.mjs +4 -5
- package/dist/es/components/LayoutGroup/index.mjs +12 -16
- package/dist/es/components/LazyMotion/index.mjs +9 -10
- package/dist/es/components/MotionConfig/index.mjs +5 -5
- package/dist/es/components/Reorder/Group.mjs +16 -16
- package/dist/es/components/Reorder/Item.mjs +14 -18
- package/dist/es/components/Reorder/index.mjs +3 -3
- package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
- package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
- package/dist/es/context/LayoutGroupContext.mjs +1 -1
- package/dist/es/context/LazyContext.mjs +1 -1
- package/dist/es/context/MotionConfigContext.mjs +2 -2
- package/dist/es/context/MotionContext/create.mjs +2 -2
- package/dist/es/context/MotionContext/index.mjs +1 -1
- package/dist/es/context/MotionContext/utils.mjs +1 -1
- package/dist/es/context/PresenceContext.mjs +1 -1
- package/dist/es/context/ReorderContext.mjs +1 -1
- package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
- package/dist/es/events/event-info.mjs +11 -17
- package/dist/es/events/use-dom-event.mjs +4 -5
- package/dist/es/events/use-pointer-event.mjs +2 -2
- package/dist/es/events/utils.mjs +3 -9
- package/dist/es/gestures/PanSession.mjs +42 -47
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
- package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
- package/dist/es/gestures/drag/use-drag.mjs +4 -4
- package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
- package/dist/es/gestures/drag/utils/lock.mjs +17 -17
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +2 -3
- package/dist/es/gestures/use-pan-gesture.mjs +9 -10
- package/dist/es/gestures/use-tap-gesture.mjs +5 -6
- package/dist/es/gestures/utils/event-type.mjs +1 -1
- package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/animations.mjs +9 -11
- package/dist/es/motion/features/definitions.mjs +5 -5
- package/dist/es/motion/features/drag.mjs +1 -1
- package/dist/es/motion/features/gestures.mjs +1 -1
- package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
- package/dist/es/motion/features/layout/index.mjs +1 -1
- package/dist/es/motion/features/use-features.mjs +8 -9
- package/dist/es/motion/features/use-projection.mjs +10 -11
- package/dist/es/motion/features/viewport/observers.mjs +12 -12
- package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
- package/dist/es/motion/index.mjs +13 -16
- package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
- package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
- package/dist/es/motion/utils/use-visual-element.mjs +13 -13
- package/dist/es/motion/utils/use-visual-state.mjs +26 -31
- package/dist/es/motion/utils/valid-prop.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +12 -16
- package/dist/es/projection/geometry/conversion.mjs +4 -6
- package/dist/es/projection/geometry/delta-apply.mjs +14 -20
- package/dist/es/projection/geometry/delta-calc.mjs +2 -5
- package/dist/es/projection/geometry/delta-remove.mjs +6 -13
- package/dist/es/projection/geometry/models.mjs +7 -7
- package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
- package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
- package/dist/es/projection/node/create-projection-node.mjs +283 -307
- package/dist/es/projection/node/group.mjs +6 -8
- package/dist/es/projection/node/id.mjs +2 -2
- package/dist/es/projection/node/state.mjs +1 -1
- package/dist/es/projection/shared/stack.mjs +26 -27
- package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
- package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection/styles/transform.mjs +12 -12
- package/dist/es/projection/use-reset-projection.mjs +2 -2
- package/dist/es/projection/utils/has-transform.mjs +1 -2
- package/dist/es/projection/utils/measure.mjs +2 -2
- package/dist/es/render/dom/create-visual-element.mjs +1 -1
- package/dist/es/render/dom/features-animation.mjs +1 -2
- package/dist/es/render/dom/features-max.mjs +1 -2
- package/dist/es/render/dom/motion-minimal.mjs +1 -1
- package/dist/es/render/dom/motion-proxy.mjs +3 -4
- package/dist/es/render/dom/motion.mjs +2 -5
- package/dist/es/render/dom/use-render.mjs +6 -9
- package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
- package/dist/es/render/dom/utils/create-config.mjs +5 -5
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
- package/dist/es/render/dom/utils/filter-props.mjs +4 -6
- package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
- package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
- package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
- package/dist/es/render/dom/value-types/defaults.mjs +4 -5
- package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
- package/dist/es/render/dom/value-types/find.mjs +2 -3
- package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
- package/dist/es/render/dom/value-types/number.mjs +2 -2
- package/dist/es/render/dom/value-types/test.mjs +1 -1
- package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
- package/dist/es/render/dom/value-types/type-int.mjs +1 -2
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +11 -13
- package/dist/es/render/html/utils/build-styles.mjs +8 -8
- package/dist/es/render/html/utils/build-transform.mjs +11 -16
- package/dist/es/render/html/utils/create-render-state.mjs +2 -2
- package/dist/es/render/html/utils/render.mjs +2 -3
- package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/html/utils/transform.mjs +6 -10
- package/dist/es/render/html/visual-element.mjs +22 -23
- package/dist/es/render/index.mjs +359 -364
- package/dist/es/render/svg/config-motion.mjs +2 -3
- package/dist/es/render/svg/lowercase-elements.mjs +1 -1
- package/dist/es/render/svg/use-props.mjs +5 -6
- package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
- package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
- package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +7 -10
- package/dist/es/render/svg/utils/render.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
- package/dist/es/render/svg/visual-element.mjs +6 -4
- package/dist/es/render/utils/animation-state.mjs +71 -87
- package/dist/es/render/utils/animation.mjs +48 -60
- package/dist/es/render/utils/compare-by-depth.mjs +1 -3
- package/dist/es/render/utils/flat-tree.mjs +9 -10
- package/dist/es/render/utils/lifecycles.mjs +12 -19
- package/dist/es/render/utils/motion-values.mjs +16 -8
- package/dist/es/render/utils/setters.mjs +19 -19
- package/dist/es/render/utils/variants.mjs +6 -8
- package/dist/es/utils/array.mjs +9 -10
- package/dist/es/utils/is-browser.mjs +1 -1
- package/dist/es/utils/is-numerical-string.mjs +1 -1
- package/dist/es/utils/is-zero-value-string.mjs +1 -1
- package/dist/es/utils/process.mjs +2 -2
- package/dist/es/utils/resolve-value.mjs +2 -2
- package/dist/es/utils/shallow-compare.mjs +2 -2
- package/dist/es/utils/subscription-manager.mjs +15 -17
- package/dist/es/utils/time-conversion.mjs +1 -1
- package/dist/es/utils/transform.mjs +10 -15
- package/dist/es/utils/use-animation-frame.mjs +5 -6
- package/dist/es/utils/use-constant.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +9 -10
- package/dist/es/utils/use-force-update.mjs +4 -5
- package/dist/es/utils/use-in-view.mjs +7 -9
- package/dist/es/utils/use-instant-transition-state.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +6 -9
- package/dist/es/utils/use-is-mounted.mjs +3 -3
- package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
- package/dist/es/utils/use-reduced-motion.mjs +8 -11
- package/dist/es/utils/use-unmount-effect.mjs +1 -1
- package/dist/es/utils/warn-once.mjs +1 -1
- package/dist/es/value/index.mjs +53 -59
- package/dist/es/value/use-combine-values.mjs +3 -3
- package/dist/es/value/use-inverted-scale.mjs +9 -11
- package/dist/es/value/use-motion-template.mjs +5 -9
- package/dist/es/value/use-motion-value.mjs +4 -5
- package/dist/es/value/use-on-change.mjs +4 -4
- package/dist/es/value/use-scroll.mjs +9 -11
- package/dist/es/value/use-spring.mjs +8 -10
- package/dist/es/value/use-time.mjs +2 -2
- package/dist/es/value/use-transform.mjs +6 -10
- package/dist/es/value/use-velocity.mjs +3 -3
- package/dist/es/value/use-will-change/index.mjs +50 -0
- package/dist/es/value/use-will-change/is.mjs +7 -0
- package/dist/es/value/utils/is-motion-value.mjs +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
- package/dist/framer-motion.dev.js +2134 -2414
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/projection.dev.js +1154 -1300
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +0 -1
- package/package.json +12 -12
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { __assign, __read } from 'tslib';
|
|
2
1
|
import { px, number } from 'style-value-types';
|
|
3
2
|
import { isKeyframesTarget } from '../../../animation/utils/is-keyframes-target.mjs';
|
|
4
3
|
import { invariant } from 'hey-listen';
|
|
5
4
|
import { transformProps } from '../../html/utils/transform.mjs';
|
|
6
5
|
import { findDimensionValueType } from '../value-types/dimensions.mjs';
|
|
6
|
+
import { isBrowser } from '../../../utils/is-browser.mjs';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const positionalKeys = new Set([
|
|
9
9
|
"width",
|
|
10
10
|
"height",
|
|
11
11
|
"top",
|
|
@@ -15,19 +15,17 @@ var positionalKeys = new Set([
|
|
|
15
15
|
"x",
|
|
16
16
|
"y",
|
|
17
17
|
]);
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const isPositionalKey = (key) => positionalKeys.has(key);
|
|
19
|
+
const hasPositionalKey = (target) => {
|
|
20
20
|
return Object.keys(target).some(isPositionalKey);
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
const setAndResetVelocity = (value, to) => {
|
|
23
23
|
// Looks odd but setting it twice doesn't render, it'll just
|
|
24
24
|
// set both prev and current to the latest value
|
|
25
25
|
value.set(to, false);
|
|
26
26
|
value.set(to);
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
return v === number || v === px;
|
|
30
|
-
};
|
|
28
|
+
const isNumOrPxType = (v) => v === number || v === px;
|
|
31
29
|
var BoundingBoxDimension;
|
|
32
30
|
(function (BoundingBoxDimension) {
|
|
33
31
|
BoundingBoxDimension["width"] = "width";
|
|
@@ -37,35 +35,30 @@ var BoundingBoxDimension;
|
|
|
37
35
|
BoundingBoxDimension["top"] = "top";
|
|
38
36
|
BoundingBoxDimension["bottom"] = "bottom";
|
|
39
37
|
})(BoundingBoxDimension || (BoundingBoxDimension = {}));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
const getPosFromMatrix = (matrix, pos) => parseFloat(matrix.split(", ")[pos]);
|
|
39
|
+
const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
|
|
40
|
+
if (transform === "none" || !transform)
|
|
41
|
+
return 0;
|
|
42
|
+
const matrix3d = transform.match(/^matrix3d\((.+)\)$/);
|
|
43
|
+
if (matrix3d) {
|
|
44
|
+
return getPosFromMatrix(matrix3d[1], pos3);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const matrix = transform.match(/^matrix\((.+)\)$/);
|
|
48
|
+
if (matrix) {
|
|
49
|
+
return getPosFromMatrix(matrix[1], pos2);
|
|
51
50
|
}
|
|
52
51
|
else {
|
|
53
|
-
|
|
54
|
-
if (matrix) {
|
|
55
|
-
return getPosFromMatrix(matrix[1], pos2);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
52
|
+
return 0;
|
|
60
53
|
}
|
|
61
|
-
}
|
|
54
|
+
}
|
|
62
55
|
};
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
const transformKeys = new Set(["x", "y", "z"]);
|
|
57
|
+
const nonTranslationalTransformKeys = transformProps.filter((key) => !transformKeys.has(key));
|
|
65
58
|
function removeNonTranslationalTransform(visualElement) {
|
|
66
|
-
|
|
67
|
-
nonTranslationalTransformKeys.forEach(
|
|
68
|
-
|
|
59
|
+
const removedTransforms = [];
|
|
60
|
+
nonTranslationalTransformKeys.forEach((key) => {
|
|
61
|
+
const value = visualElement.getValue(key);
|
|
69
62
|
if (value !== undefined) {
|
|
70
63
|
removedTransforms.push([key, value.get()]);
|
|
71
64
|
value.set(key.startsWith("scale") ? 1 : 0);
|
|
@@ -76,46 +69,24 @@ function removeNonTranslationalTransform(visualElement) {
|
|
|
76
69
|
visualElement.syncRender();
|
|
77
70
|
return removedTransforms;
|
|
78
71
|
}
|
|
79
|
-
|
|
72
|
+
const positionalValues = {
|
|
80
73
|
// Dimensions
|
|
81
|
-
width:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
var y = _a.y;
|
|
88
|
-
var _c = _b.paddingTop, paddingTop = _c === void 0 ? "0" : _c, _d = _b.paddingBottom, paddingBottom = _d === void 0 ? "0" : _d;
|
|
89
|
-
return y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom);
|
|
90
|
-
},
|
|
91
|
-
top: function (_bbox, _a) {
|
|
92
|
-
var top = _a.top;
|
|
93
|
-
return parseFloat(top);
|
|
94
|
-
},
|
|
95
|
-
left: function (_bbox, _a) {
|
|
96
|
-
var left = _a.left;
|
|
97
|
-
return parseFloat(left);
|
|
98
|
-
},
|
|
99
|
-
bottom: function (_a, _b) {
|
|
100
|
-
var y = _a.y;
|
|
101
|
-
var top = _b.top;
|
|
102
|
-
return parseFloat(top) + (y.max - y.min);
|
|
103
|
-
},
|
|
104
|
-
right: function (_a, _b) {
|
|
105
|
-
var x = _a.x;
|
|
106
|
-
var left = _b.left;
|
|
107
|
-
return parseFloat(left) + (x.max - x.min);
|
|
108
|
-
},
|
|
74
|
+
width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) => x.max - x.min - parseFloat(paddingLeft) - parseFloat(paddingRight),
|
|
75
|
+
height: ({ y }, { paddingTop = "0", paddingBottom = "0" }) => y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom),
|
|
76
|
+
top: (_bbox, { top }) => parseFloat(top),
|
|
77
|
+
left: (_bbox, { left }) => parseFloat(left),
|
|
78
|
+
bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
|
|
79
|
+
right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
|
|
109
80
|
// Transform
|
|
110
81
|
x: getTranslateFromMatrix(4, 13),
|
|
111
82
|
y: getTranslateFromMatrix(5, 14),
|
|
112
83
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
84
|
+
const convertChangedValueTypes = (target, visualElement, changedKeys) => {
|
|
85
|
+
const originBbox = visualElement.measureViewportBox();
|
|
86
|
+
const element = visualElement.getInstance();
|
|
87
|
+
const elementComputedStyle = getComputedStyle(element);
|
|
88
|
+
const { display } = elementComputedStyle;
|
|
89
|
+
const origin = {};
|
|
119
90
|
// If the element is currently set to display: "none", make it visible before
|
|
120
91
|
// measuring the target bounding box
|
|
121
92
|
if (display === "none") {
|
|
@@ -124,50 +95,48 @@ var convertChangedValueTypes = function (target, visualElement, changedKeys) {
|
|
|
124
95
|
/**
|
|
125
96
|
* Record origins before we render and update styles
|
|
126
97
|
*/
|
|
127
|
-
changedKeys.forEach(
|
|
98
|
+
changedKeys.forEach((key) => {
|
|
128
99
|
origin[key] = positionalValues[key](originBbox, elementComputedStyle);
|
|
129
100
|
});
|
|
130
101
|
// Apply the latest values (as set in checkAndConvertChangedValueTypes)
|
|
131
102
|
visualElement.syncRender();
|
|
132
|
-
|
|
133
|
-
changedKeys.forEach(
|
|
103
|
+
const targetBbox = visualElement.measureViewportBox();
|
|
104
|
+
changedKeys.forEach((key) => {
|
|
134
105
|
// Restore styles to their **calculated computed style**, not their actual
|
|
135
106
|
// originally set style. This allows us to animate between equivalent pixel units.
|
|
136
|
-
|
|
107
|
+
const value = visualElement.getValue(key);
|
|
137
108
|
setAndResetVelocity(value, origin[key]);
|
|
138
109
|
target[key] = positionalValues[key](targetBbox, elementComputedStyle);
|
|
139
110
|
});
|
|
140
111
|
return target;
|
|
141
112
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
transitionEnd = __assign({}, transitionEnd);
|
|
147
|
-
var targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
113
|
+
const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
|
|
114
|
+
target = Object.assign({}, target);
|
|
115
|
+
transitionEnd = Object.assign({}, transitionEnd);
|
|
116
|
+
const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
148
117
|
// We want to remove any transform values that could affect the element's bounding box before
|
|
149
118
|
// it's measured. We'll reapply these later.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
targetPositionalKeys.forEach(
|
|
154
|
-
|
|
119
|
+
let removedTransformValues = [];
|
|
120
|
+
let hasAttemptedToRemoveTransformValues = false;
|
|
121
|
+
const changedValueTypeKeys = [];
|
|
122
|
+
targetPositionalKeys.forEach((key) => {
|
|
123
|
+
const value = visualElement.getValue(key);
|
|
155
124
|
if (!visualElement.hasValue(key))
|
|
156
125
|
return;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
126
|
+
let from = origin[key];
|
|
127
|
+
let fromType = findDimensionValueType(from);
|
|
128
|
+
const to = target[key];
|
|
129
|
+
let toType;
|
|
161
130
|
// TODO: The current implementation of this basically throws an error
|
|
162
131
|
// if you try and do value conversion via keyframes. There's probably
|
|
163
132
|
// a way of doing this but the performance implications would need greater scrutiny,
|
|
164
133
|
// as it'd be doing multiple resize-remeasure operations.
|
|
165
134
|
if (isKeyframesTarget(to)) {
|
|
166
|
-
|
|
167
|
-
|
|
135
|
+
const numKeyframes = to.length;
|
|
136
|
+
const fromIndex = to[0] === null ? 1 : 0;
|
|
168
137
|
from = to[fromIndex];
|
|
169
138
|
fromType = findDimensionValueType(from);
|
|
170
|
-
for (
|
|
139
|
+
for (let i = fromIndex; i < numKeyframes; i++) {
|
|
171
140
|
if (!toType) {
|
|
172
141
|
toType = findDimensionValueType(to[i]);
|
|
173
142
|
invariant(toType === fromType ||
|
|
@@ -185,7 +154,7 @@ var checkAndConvertChangedValueTypes = function (visualElement, target, origin,
|
|
|
185
154
|
// If they're both just number or px, convert them both to numbers rather than
|
|
186
155
|
// relying on resize/remeasure to convert (which is wasteful in this situation)
|
|
187
156
|
if (isNumOrPxType(fromType) && isNumOrPxType(toType)) {
|
|
188
|
-
|
|
157
|
+
const current = value.get();
|
|
189
158
|
if (typeof current === "string") {
|
|
190
159
|
value.set(parseFloat(current));
|
|
191
160
|
}
|
|
@@ -226,26 +195,26 @@ var checkAndConvertChangedValueTypes = function (visualElement, target, origin,
|
|
|
226
195
|
}
|
|
227
196
|
});
|
|
228
197
|
if (changedValueTypeKeys.length) {
|
|
229
|
-
|
|
198
|
+
const scrollY = changedValueTypeKeys.indexOf("height") >= 0
|
|
230
199
|
? window.pageYOffset
|
|
231
200
|
: null;
|
|
232
|
-
|
|
201
|
+
const convertedTarget = convertChangedValueTypes(target, visualElement, changedValueTypeKeys);
|
|
233
202
|
// If we removed transform values, reapply them before the next render
|
|
234
203
|
if (removedTransformValues.length) {
|
|
235
|
-
removedTransformValues.forEach(
|
|
236
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
204
|
+
removedTransformValues.forEach(([key, value]) => {
|
|
237
205
|
visualElement.getValue(key).set(value);
|
|
238
206
|
});
|
|
239
207
|
}
|
|
240
208
|
// Reapply original values
|
|
241
209
|
visualElement.syncRender();
|
|
242
210
|
// Restore scroll position
|
|
243
|
-
if (
|
|
244
|
-
window.scrollTo({ top:
|
|
245
|
-
|
|
211
|
+
if (isBrowser && scrollY !== null) {
|
|
212
|
+
window.scrollTo({ top: scrollY });
|
|
213
|
+
}
|
|
214
|
+
return { target: convertedTarget, transitionEnd };
|
|
246
215
|
}
|
|
247
216
|
else {
|
|
248
|
-
return { target
|
|
217
|
+
return { target, transitionEnd };
|
|
249
218
|
}
|
|
250
219
|
};
|
|
251
220
|
/**
|
|
@@ -258,7 +227,7 @@ var checkAndConvertChangedValueTypes = function (visualElement, target, origin,
|
|
|
258
227
|
function unitConversion(visualElement, target, origin, transitionEnd) {
|
|
259
228
|
return hasPositionalKey(target)
|
|
260
229
|
? checkAndConvertChangedValueTypes(visualElement, target, origin, transitionEnd)
|
|
261
|
-
: { target
|
|
230
|
+
: { target, transitionEnd };
|
|
262
231
|
}
|
|
263
232
|
|
|
264
233
|
export { BoundingBoxDimension, positionalValues, unitConversion };
|
|
@@ -3,7 +3,7 @@ import { getDefaultValueType } from './defaults.mjs';
|
|
|
3
3
|
|
|
4
4
|
function getAnimatableNone(key, value) {
|
|
5
5
|
var _a;
|
|
6
|
-
|
|
6
|
+
let defaultValueType = getDefaultValueType(key);
|
|
7
7
|
if (defaultValueType !== filter)
|
|
8
8
|
defaultValueType = complex;
|
|
9
9
|
// If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { color, filter } from 'style-value-types';
|
|
3
2
|
import { numberValueTypes } from './number.mjs';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* A map of default value types for common values
|
|
7
6
|
*/
|
|
8
|
-
|
|
7
|
+
const defaultValueTypes = Object.assign(Object.assign({}, numberValueTypes), {
|
|
9
8
|
// Color props
|
|
10
|
-
color
|
|
9
|
+
color, backgroundColor: color, outlineColor: color, fill: color, stroke: color,
|
|
11
10
|
// Border props
|
|
12
|
-
borderColor: color, borderTopColor: color, borderRightColor: color, borderBottomColor: color, borderLeftColor: color, filter
|
|
11
|
+
borderColor: color, borderTopColor: color, borderRightColor: color, borderBottomColor: color, borderLeftColor: color, filter, WebkitFilter: filter });
|
|
13
12
|
/**
|
|
14
13
|
* Gets the default ValueType for the provided value key
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
const getDefaultValueType = (key) => defaultValueTypes[key];
|
|
17
16
|
|
|
18
17
|
export { defaultValueTypes, getDefaultValueType };
|
|
@@ -5,12 +5,10 @@ import { auto } from './type-auto.mjs';
|
|
|
5
5
|
/**
|
|
6
6
|
* A list of value types commonly used for dimensions
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
const dimensionValueTypes = [number, px, percent, degrees, vw, vh, auto];
|
|
9
9
|
/**
|
|
10
10
|
* Tests a dimensional value against the list of dimension ValueTypes
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
return dimensionValueTypes.find(testValueType(v));
|
|
14
|
-
};
|
|
12
|
+
const findDimensionValueType = (v) => dimensionValueTypes.find(testValueType(v));
|
|
15
13
|
|
|
16
14
|
export { dimensionValueTypes, findDimensionValueType };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __spreadArray, __read } from 'tslib';
|
|
2
1
|
import { color, complex } from 'style-value-types';
|
|
3
2
|
import { dimensionValueTypes } from './dimensions.mjs';
|
|
4
3
|
import { testValueType } from './test.mjs';
|
|
@@ -6,10 +5,10 @@ import { testValueType } from './test.mjs';
|
|
|
6
5
|
/**
|
|
7
6
|
* A list of all ValueTypes
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
const valueTypes = [...dimensionValueTypes, color, complex];
|
|
10
9
|
/**
|
|
11
10
|
* Tests a value against the list of ValueTypes
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
14
13
|
|
|
15
14
|
export { findValueType };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { px, degrees, scale, alpha, progressPercentage } from 'style-value-types';
|
|
2
2
|
import { int } from './type-int.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const numberValueTypes = {
|
|
5
5
|
// Border props
|
|
6
6
|
borderWidth: px,
|
|
7
7
|
borderTopWidth: px,
|
|
@@ -40,7 +40,7 @@ var numberValueTypes = {
|
|
|
40
40
|
rotateX: degrees,
|
|
41
41
|
rotateY: degrees,
|
|
42
42
|
rotateZ: degrees,
|
|
43
|
-
scale
|
|
43
|
+
scale,
|
|
44
44
|
scaleX: scale,
|
|
45
45
|
scaleY: scale,
|
|
46
46
|
scaleZ: scale,
|
|
@@ -2,7 +2,7 @@ import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
|
|
|
2
2
|
import { scrapeMotionValuesFromProps } from './utils/scrape-motion-values.mjs';
|
|
3
3
|
import { createHtmlRenderState } from './utils/create-render-state.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const htmlMotionConfig = {
|
|
6
6
|
useVisualState: makeUseVisualState({
|
|
7
7
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
8
8
|
createRenderState: createHtmlRenderState,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { useMemo } from 'react';
|
|
3
2
|
import { isForcedMotionValue } from '../../motion/utils/is-forced-motion-value.mjs';
|
|
4
3
|
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
@@ -6,24 +5,23 @@ import { buildHTMLStyles } from './utils/build-styles.mjs';
|
|
|
6
5
|
import { createHtmlRenderState } from './utils/create-render-state.mjs';
|
|
7
6
|
|
|
8
7
|
function copyRawValuesOnly(target, source, props) {
|
|
9
|
-
for (
|
|
8
|
+
for (const key in source) {
|
|
10
9
|
if (!isMotionValue(source[key]) && !isForcedMotionValue(key, props)) {
|
|
11
10
|
target[key] = source[key];
|
|
12
11
|
}
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
|
-
function useInitialMotionValues(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var state = createHtmlRenderState();
|
|
14
|
+
function useInitialMotionValues({ transformTemplate }, visualState, isStatic) {
|
|
15
|
+
return useMemo(() => {
|
|
16
|
+
const state = createHtmlRenderState();
|
|
19
17
|
buildHTMLStyles(state, visualState, { enableHardwareAcceleration: !isStatic }, transformTemplate);
|
|
20
|
-
|
|
21
|
-
return
|
|
18
|
+
const { vars, style } = state;
|
|
19
|
+
return Object.assign(Object.assign({}, vars), style);
|
|
22
20
|
}, [visualState]);
|
|
23
21
|
}
|
|
24
22
|
function useStyle(props, visualState, isStatic) {
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const styleProp = props.style || {};
|
|
24
|
+
let style = {};
|
|
27
25
|
/**
|
|
28
26
|
* Copy non-Motion Values straight into style
|
|
29
27
|
*/
|
|
@@ -36,8 +34,8 @@ function useStyle(props, visualState, isStatic) {
|
|
|
36
34
|
}
|
|
37
35
|
function useHTMLProps(props, visualState, isStatic) {
|
|
38
36
|
// The `any` isn't ideal but it is the type of createElement props argument
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const htmlProps = {};
|
|
38
|
+
const style = useStyle(props, visualState, isStatic);
|
|
41
39
|
if (Boolean(props.drag) && props.dragListener !== false) {
|
|
42
40
|
// Disable the ghost element when a user drags
|
|
43
41
|
htmlProps.draggable = false;
|
|
@@ -50,7 +48,7 @@ function useHTMLProps(props, visualState, isStatic) {
|
|
|
50
48
|
style.touchAction =
|
|
51
49
|
props.drag === true
|
|
52
50
|
? "none"
|
|
53
|
-
:
|
|
51
|
+
: `pan-${props.drag === "x" ? "y" : "x"}`;
|
|
54
52
|
}
|
|
55
53
|
htmlProps.style = style;
|
|
56
54
|
return htmlProps;
|
|
@@ -6,24 +6,24 @@ import { numberValueTypes } from '../../dom/value-types/number.mjs';
|
|
|
6
6
|
|
|
7
7
|
function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
8
8
|
var _a;
|
|
9
|
-
|
|
9
|
+
const { style, vars, transform, transformKeys, transformOrigin } = state;
|
|
10
10
|
// Empty the transformKeys array. As we're throwing out refs to its items
|
|
11
11
|
// this might not be as cheap as suspected. Maybe using the array as a buffer
|
|
12
12
|
// with a manual incrementation would be better.
|
|
13
13
|
transformKeys.length = 0;
|
|
14
14
|
// Track whether we encounter any transform or transformOrigin values.
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
let hasTransform = false;
|
|
16
|
+
let hasTransformOrigin = false;
|
|
17
17
|
// Does the calculated transform essentially equal "none"?
|
|
18
|
-
|
|
18
|
+
let transformIsNone = true;
|
|
19
19
|
/**
|
|
20
20
|
* Loop over all our latest animated values and decide whether to handle them
|
|
21
21
|
* as a style or CSS variable.
|
|
22
22
|
*
|
|
23
23
|
* Transforms and transform origins are kept seperately for further processing.
|
|
24
24
|
*/
|
|
25
|
-
for (
|
|
26
|
-
|
|
25
|
+
for (const key in latestValues) {
|
|
26
|
+
const value = latestValues[key];
|
|
27
27
|
/**
|
|
28
28
|
* If this is a CSS variable we don't do any further processing.
|
|
29
29
|
*/
|
|
@@ -32,8 +32,8 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
const valueType = numberValueTypes[key];
|
|
36
|
+
const valueAsType = getValueAsType(value, valueType);
|
|
37
37
|
if (isTransformProp(key)) {
|
|
38
38
|
// If this is a transform, flag to enable further transform processing
|
|
39
39
|
hasTransform = true;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sortTransformProps } from './transform.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const translateAlias = {
|
|
4
4
|
x: "translateX",
|
|
5
5
|
y: "translateY",
|
|
6
6
|
z: "translateZ",
|
|
@@ -12,30 +12,26 @@ var translateAlias = {
|
|
|
12
12
|
* This outputs with a default order of transforms/scales/rotations, this can be customised by
|
|
13
13
|
* providing a transformTemplate function.
|
|
14
14
|
*/
|
|
15
|
-
function buildTransform(
|
|
16
|
-
var transform = _a.transform, transformKeys = _a.transformKeys;
|
|
17
|
-
var _c = _b.enableHardwareAcceleration, enableHardwareAcceleration = _c === void 0 ? true : _c, _d = _b.allowTransformNone, allowTransformNone = _d === void 0 ? true : _d;
|
|
15
|
+
function buildTransform({ transform, transformKeys }, { enableHardwareAcceleration = true, allowTransformNone = true, }, transformIsDefault, transformTemplate) {
|
|
18
16
|
// The transform string we're going to build into.
|
|
19
|
-
|
|
17
|
+
let transformString = "";
|
|
20
18
|
// Transform keys into their default order - this will determine the output order.
|
|
21
19
|
transformKeys.sort(sortTransformProps);
|
|
22
20
|
// Track whether the defined transform has a defined z so we don't add a
|
|
23
21
|
// second to enable hardware acceleration
|
|
24
|
-
|
|
22
|
+
let transformHasZ = false;
|
|
25
23
|
// Loop over each transform and build them into transformString
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
|
|
29
|
-
transformString +=
|
|
24
|
+
const numTransformKeys = transformKeys.length;
|
|
25
|
+
for (let i = 0; i < numTransformKeys; i++) {
|
|
26
|
+
const key = transformKeys[i];
|
|
27
|
+
transformString += `${translateAlias[key] || key}(${transform[key]}) `;
|
|
30
28
|
if (key === "z")
|
|
31
29
|
transformHasZ = true;
|
|
32
30
|
}
|
|
33
31
|
if (!transformHasZ && enableHardwareAcceleration) {
|
|
34
32
|
transformString += "translateZ(0)";
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
transformString = transformString.trim();
|
|
38
|
-
}
|
|
34
|
+
transformString = transformString.trim();
|
|
39
35
|
// If we have a custom `transform` template, pass our transform values and
|
|
40
36
|
// generated transformString to that before returning
|
|
41
37
|
if (transformTemplate) {
|
|
@@ -50,9 +46,8 @@ function buildTransform(_a, _b, transformIsDefault, transformTemplate) {
|
|
|
50
46
|
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
51
47
|
* undefined origins.
|
|
52
48
|
*/
|
|
53
|
-
function buildTransformOrigin(
|
|
54
|
-
|
|
55
|
-
return "".concat(originX, " ").concat(originY, " ").concat(originZ);
|
|
49
|
+
function buildTransformOrigin({ originX = "50%", originY = "50%", originZ = 0, }) {
|
|
50
|
+
return `${originX} ${originY} ${originZ}`;
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
export { buildTransform, buildTransformOrigin };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
function renderHTML(element,
|
|
2
|
-
var style = _a.style, vars = _a.vars;
|
|
1
|
+
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
3
2
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
4
3
|
// Loop over any CSS variables and assign those.
|
|
5
|
-
for (
|
|
4
|
+
for (const key in vars) {
|
|
6
5
|
element.style.setProperty(key, vars[key]);
|
|
7
6
|
}
|
|
8
7
|
}
|
|
@@ -2,9 +2,9 @@ import { isForcedMotionValue } from '../../../motion/utils/is-forced-motion-valu
|
|
|
2
2
|
import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
|
|
3
3
|
|
|
4
4
|
function scrapeMotionValuesFromProps(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (
|
|
5
|
+
const { style } = props;
|
|
6
|
+
const newValues = {};
|
|
7
|
+
for (const key in style) {
|
|
8
8
|
if (isMotionValue(style[key]) || isForcedMotionValue(key, props)) {
|
|
9
9
|
newValues[key] = style[key];
|
|
10
10
|
}
|