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,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
return !node.isLayoutDirty && node.willUpdate(false);
|
|
3
|
-
};
|
|
1
|
+
const notify = (node) => !node.isLayoutDirty && node.willUpdate(false);
|
|
4
2
|
function nodeGroup() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const nodes = new Set();
|
|
4
|
+
const subscriptions = new WeakMap();
|
|
5
|
+
const dirtyAll = () => nodes.forEach(notify);
|
|
8
6
|
return {
|
|
9
|
-
add:
|
|
7
|
+
add: (node) => {
|
|
10
8
|
nodes.add(node);
|
|
11
9
|
subscriptions.set(node, node.addEventListener("willUpdate", dirtyAll));
|
|
12
10
|
},
|
|
13
|
-
remove:
|
|
11
|
+
remove: (node) => {
|
|
14
12
|
var _a;
|
|
15
13
|
nodes.delete(node);
|
|
16
14
|
(_a = subscriptions.get(node)) === null || _a === void 0 ? void 0 : _a();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useConstant } from '../../utils/use-constant.mjs';
|
|
2
2
|
import { globalProjectionState } from './state.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
let id = 1;
|
|
5
5
|
function useProjectionId() {
|
|
6
|
-
return useConstant(
|
|
6
|
+
return useConstant(() => {
|
|
7
7
|
if (globalProjectionState.hasEverUpdated) {
|
|
8
8
|
return id++;
|
|
9
9
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* persist through server requests. If we need instanced states we
|
|
4
4
|
* could lazy-init via root.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const globalProjectionState = {
|
|
7
7
|
/**
|
|
8
8
|
* Global flag as to whether the tree has animated since the last time
|
|
9
9
|
* we resized the window
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import { addUniqueItem, removeItem } from '../../utils/array.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class NodeStack {
|
|
4
|
+
constructor() {
|
|
5
5
|
this.members = [];
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
add(node) {
|
|
8
8
|
addUniqueItem(this.members, node);
|
|
9
9
|
node.scheduleRender();
|
|
10
|
-
}
|
|
11
|
-
|
|
10
|
+
}
|
|
11
|
+
remove(node) {
|
|
12
12
|
removeItem(this.members, node);
|
|
13
13
|
if (node === this.prevLead) {
|
|
14
14
|
this.prevLead = undefined;
|
|
15
15
|
}
|
|
16
16
|
if (node === this.lead) {
|
|
17
|
-
|
|
17
|
+
const prevLead = this.members[this.members.length - 1];
|
|
18
18
|
if (prevLead) {
|
|
19
19
|
this.promote(prevLead);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
}
|
|
23
|
+
relegate(node) {
|
|
24
|
+
const indexOfNode = this.members.findIndex((member) => node === member);
|
|
25
25
|
if (indexOfNode === 0)
|
|
26
26
|
return false;
|
|
27
27
|
/**
|
|
28
28
|
* Find the next projection node that is present
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
for (
|
|
32
|
-
|
|
30
|
+
let prevLead;
|
|
31
|
+
for (let i = indexOfNode; i >= 0; i--) {
|
|
32
|
+
const member = this.members[i];
|
|
33
33
|
if (member.isPresent !== false) {
|
|
34
34
|
prevLead = member;
|
|
35
35
|
break;
|
|
@@ -42,10 +42,10 @@ var NodeStack = /** @class */ (function () {
|
|
|
42
42
|
else {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
-
}
|
|
46
|
-
|
|
45
|
+
}
|
|
46
|
+
promote(node, preserveFollowOpacity) {
|
|
47
47
|
var _a;
|
|
48
|
-
|
|
48
|
+
const prevLead = this.lead;
|
|
49
49
|
if (node === prevLead)
|
|
50
50
|
return;
|
|
51
51
|
this.prevLead = prevLead;
|
|
@@ -67,7 +67,7 @@ var NodeStack = /** @class */ (function () {
|
|
|
67
67
|
if ((_a = node.root) === null || _a === void 0 ? void 0 : _a.isUpdating) {
|
|
68
68
|
node.isLayoutDirty = true;
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
const { crossfade } = node.options;
|
|
71
71
|
if (crossfade === false) {
|
|
72
72
|
prevLead.hide();
|
|
73
73
|
}
|
|
@@ -84,29 +84,28 @@ var NodeStack = /** @class */ (function () {
|
|
|
84
84
|
* - layoutId changes mid animation
|
|
85
85
|
*/
|
|
86
86
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
this.members.forEach(
|
|
87
|
+
}
|
|
88
|
+
exitAnimationComplete() {
|
|
89
|
+
this.members.forEach((node) => {
|
|
90
90
|
var _a, _b, _c, _d, _e;
|
|
91
91
|
(_b = (_a = node.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
92
92
|
(_e = (_c = node.resumingFrom) === null || _c === void 0 ? void 0 : (_d = _c.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
93
93
|
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
this.members.forEach(
|
|
94
|
+
}
|
|
95
|
+
scheduleRender() {
|
|
96
|
+
this.members.forEach((node) => {
|
|
97
97
|
node.instance && node.scheduleRender(false);
|
|
98
98
|
});
|
|
99
|
-
}
|
|
99
|
+
}
|
|
100
100
|
/**
|
|
101
101
|
* Clear any leads that have been removed this render to prevent them from being
|
|
102
102
|
* used in future animations and to prevent memory leaks
|
|
103
103
|
*/
|
|
104
|
-
|
|
104
|
+
removeLeadSnapshot() {
|
|
105
105
|
if (this.lead && this.lead.snapshot) {
|
|
106
106
|
this.lead.snapshot = undefined;
|
|
107
107
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
}());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
111
110
|
|
|
112
111
|
export { NodeStack };
|
|
@@ -12,8 +12,8 @@ function pixelsToPercent(pixels, axis) {
|
|
|
12
12
|
* borderRadius in both states. If we animate between the two in pixels that will trigger
|
|
13
13
|
* a paint each time. If we animate between the two in percentage we'll avoid a paint.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
correct:
|
|
15
|
+
const correctBorderRadius = {
|
|
16
|
+
correct: (latest, node) => {
|
|
17
17
|
if (!node.target)
|
|
18
18
|
return latest;
|
|
19
19
|
/**
|
|
@@ -32,9 +32,9 @@ var correctBorderRadius = {
|
|
|
32
32
|
* If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
|
|
33
33
|
* pixel value as a percentage of each axis
|
|
34
34
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
35
|
+
const x = pixelsToPercent(latest, node.target.x);
|
|
36
|
+
const y = pixelsToPercent(latest, node.target.y);
|
|
37
|
+
return `${x}% ${y}%`;
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
40
|
|
|
@@ -2,31 +2,30 @@ import { mix } from 'popmotion';
|
|
|
2
2
|
import { complex } from 'style-value-types';
|
|
3
3
|
import { cssVariableRegex } from '../../render/dom/utils/css-variables-conversion.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
correct:
|
|
8
|
-
|
|
9
|
-
var original = latest;
|
|
5
|
+
const varToken = "_$css";
|
|
6
|
+
const correctBoxShadow = {
|
|
7
|
+
correct: (latest, { treeScale, projectionDelta }) => {
|
|
8
|
+
const original = latest;
|
|
10
9
|
/**
|
|
11
10
|
* We need to first strip and store CSS variables from the string.
|
|
12
11
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const containsCSSVariables = latest.includes("var(");
|
|
13
|
+
const cssVariables = [];
|
|
15
14
|
if (containsCSSVariables) {
|
|
16
|
-
latest = latest.replace(cssVariableRegex,
|
|
15
|
+
latest = latest.replace(cssVariableRegex, (match) => {
|
|
17
16
|
cssVariables.push(match);
|
|
18
17
|
return varToken;
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
const shadow = complex.parse(latest);
|
|
22
21
|
// TODO: Doesn't support multiple shadows
|
|
23
22
|
if (shadow.length > 5)
|
|
24
23
|
return original;
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const template = complex.createTransformer(latest);
|
|
25
|
+
const offset = typeof shadow[0] !== "number" ? 1 : 0;
|
|
27
26
|
// Calculate the overall context scale
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const xScale = projectionDelta.x.scale * treeScale.x;
|
|
28
|
+
const yScale = projectionDelta.y.scale * treeScale.y;
|
|
30
29
|
shadow[0 + offset] /= xScale;
|
|
31
30
|
shadow[1 + offset] /= yScale;
|
|
32
31
|
/**
|
|
@@ -35,19 +34,19 @@ var correctBoxShadow = {
|
|
|
35
34
|
* We could potentially improve the outcome of this by incorporating the ratio between
|
|
36
35
|
* the two scales.
|
|
37
36
|
*/
|
|
38
|
-
|
|
37
|
+
const averageScale = mix(xScale, yScale, 0.5);
|
|
39
38
|
// Blur
|
|
40
39
|
if (typeof shadow[2 + offset] === "number")
|
|
41
40
|
shadow[2 + offset] /= averageScale;
|
|
42
41
|
// Spread
|
|
43
42
|
if (typeof shadow[3 + offset] === "number")
|
|
44
43
|
shadow[3 + offset] /= averageScale;
|
|
45
|
-
|
|
44
|
+
let output = template(shadow);
|
|
46
45
|
if (containsCSSVariables) {
|
|
47
|
-
|
|
48
|
-
output = output.replace(varToken,
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
let i = 0;
|
|
47
|
+
output = output.replace(varToken, () => {
|
|
48
|
+
const cssVariable = cssVariables[i];
|
|
49
|
+
i++;
|
|
51
50
|
return cssVariable;
|
|
52
51
|
});
|
|
53
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const identityProjection = "translate3d(0px, 0px, 0) scale(1, 1) scale(1, 1)";
|
|
2
2
|
function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
3
3
|
/**
|
|
4
4
|
* The translations we use to calculate are always relative to the viewport coordinate space.
|
|
@@ -6,30 +6,30 @@ function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
|
6
6
|
* For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need
|
|
7
7
|
* to move an element 100 pixels, we actually need to move it 200 in within that scaled space.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const xTranslate = delta.x.translate / treeScale.x;
|
|
10
|
+
const yTranslate = delta.y.translate / treeScale.y;
|
|
11
|
+
let transform = `translate3d(${xTranslate}px, ${yTranslate}px, 0) `;
|
|
12
12
|
/**
|
|
13
13
|
* Apply scale correction for the tree transform.
|
|
14
14
|
* This will apply scale to the screen-orientated axes.
|
|
15
15
|
*/
|
|
16
|
-
transform +=
|
|
16
|
+
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
17
17
|
if (latestTransform) {
|
|
18
|
-
|
|
18
|
+
const { rotate, rotateX, rotateY } = latestTransform;
|
|
19
19
|
if (rotate)
|
|
20
|
-
transform +=
|
|
20
|
+
transform += `rotate(${rotate}deg) `;
|
|
21
21
|
if (rotateX)
|
|
22
|
-
transform +=
|
|
22
|
+
transform += `rotateX(${rotateX}deg) `;
|
|
23
23
|
if (rotateY)
|
|
24
|
-
transform +=
|
|
24
|
+
transform += `rotateY(${rotateY}deg) `;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Apply scale to match the size of the element to the size we want it.
|
|
28
28
|
* This will apply scale to the element-orientated axes.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
transform +=
|
|
30
|
+
const elementScaleX = delta.x.scale * treeScale.x;
|
|
31
|
+
const elementScaleY = delta.y.scale * treeScale.y;
|
|
32
|
+
transform += `scale(${elementScaleX}, ${elementScaleY})`;
|
|
33
33
|
return transform === identityProjection ? "none" : transform;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -2,8 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import { rootProjectionNode } from './node/HTMLProjectionNode.mjs';
|
|
3
3
|
|
|
4
4
|
function useResetProjection() {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const reset = React.useCallback(() => {
|
|
6
|
+
const root = rootProjectionNode.current;
|
|
7
7
|
if (!root)
|
|
8
8
|
return;
|
|
9
9
|
root.resetTree();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
function isIdentityScale(scale) {
|
|
2
2
|
return scale === undefined || scale === 1;
|
|
3
3
|
}
|
|
4
|
-
function hasScale(
|
|
5
|
-
var scale = _a.scale, scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
4
|
+
function hasScale({ scale, scaleX, scaleY }) {
|
|
6
5
|
return (!isIdentityScale(scale) ||
|
|
7
6
|
!isIdentityScale(scaleX) ||
|
|
8
7
|
!isIdentityScale(scaleY));
|
|
@@ -5,8 +5,8 @@ function measureViewportBox(instance, transformPoint) {
|
|
|
5
5
|
return convertBoundingBoxToBox(transformBoxPoints(instance.getBoundingClientRect(), transformPoint));
|
|
6
6
|
}
|
|
7
7
|
function measurePageBox(element, rootProjectionNode, transformPagePoint) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const viewportBox = measureViewportBox(element, transformPagePoint);
|
|
9
|
+
const { scroll } = rootProjectionNode;
|
|
10
10
|
if (scroll) {
|
|
11
11
|
translateAxis(viewportBox.x, scroll.x);
|
|
12
12
|
translateAxis(viewportBox.y, scroll.y);
|
|
@@ -2,7 +2,7 @@ import { htmlVisualElement } from '../html/visual-element.mjs';
|
|
|
2
2
|
import { svgVisualElement } from '../svg/visual-element.mjs';
|
|
3
3
|
import { isSVGComponent } from './utils/is-svg-component.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const createDomVisualElement = (Component, options) => {
|
|
6
6
|
return isSVGComponent(Component)
|
|
7
7
|
? svgVisualElement(options, { enableHardwareAcceleration: false })
|
|
8
8
|
: htmlVisualElement(options, { enableHardwareAcceleration: true });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { animations } from '../../motion/features/animations.mjs';
|
|
3
2
|
import { gestureAnimations } from '../../motion/features/gestures.mjs';
|
|
4
3
|
import { createDomVisualElement } from './create-visual-element.mjs';
|
|
@@ -6,6 +5,6 @@ import { createDomVisualElement } from './create-visual-element.mjs';
|
|
|
6
5
|
/**
|
|
7
6
|
* @public
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
const domAnimation = Object.assign(Object.assign({ renderer: createDomVisualElement }, animations), gestureAnimations);
|
|
10
9
|
|
|
11
10
|
export { domAnimation };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { drag } from '../../motion/features/drag.mjs';
|
|
3
2
|
import { layoutFeatures } from '../../motion/features/layout/index.mjs';
|
|
4
3
|
import { domAnimation } from './features-animation.mjs';
|
|
@@ -7,6 +6,6 @@ import { HTMLProjectionNode } from '../../projection/node/HTMLProjectionNode.mjs
|
|
|
7
6
|
/**
|
|
8
7
|
* @public
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
const domMax = Object.assign(Object.assign(Object.assign(Object.assign({}, domAnimation), drag), layoutFeatures), { projectionNodeConstructor: HTMLProjectionNode });
|
|
11
10
|
|
|
12
11
|
export { domMax };
|
|
@@ -15,8 +15,7 @@ import { createMotionComponent } from '../../motion/index.mjs';
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
function createMotionProxy(createConfig) {
|
|
18
|
-
function custom(Component, customMotionComponentConfig) {
|
|
19
|
-
if (customMotionComponentConfig === void 0) { customMotionComponentConfig = {}; }
|
|
18
|
+
function custom(Component, customMotionComponentConfig = {}) {
|
|
20
19
|
return createMotionComponent(createConfig(Component, customMotionComponentConfig));
|
|
21
20
|
}
|
|
22
21
|
if (typeof Proxy === "undefined") {
|
|
@@ -26,14 +25,14 @@ function createMotionProxy(createConfig) {
|
|
|
26
25
|
* A cache of generated `motion` components, e.g `motion.div`, `motion.input` etc.
|
|
27
26
|
* Rather than generating them anew every render.
|
|
28
27
|
*/
|
|
29
|
-
|
|
28
|
+
const componentCache = new Map();
|
|
30
29
|
return new Proxy(custom, {
|
|
31
30
|
/**
|
|
32
31
|
* Called when `motion` is referenced with a prop: `motion.div`, `motion.input` etc.
|
|
33
32
|
* The prop name is passed through as `key` and we can use that to generate a `motion`
|
|
34
33
|
* DOM component with that name.
|
|
35
34
|
*/
|
|
36
|
-
get:
|
|
35
|
+
get: (_target, key) => {
|
|
37
36
|
/**
|
|
38
37
|
* If this element doesn't exist in the component cache, create it and cache.
|
|
39
38
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { createMotionComponent } from '../../motion/index.mjs';
|
|
3
2
|
import { createMotionProxy } from './motion-proxy.mjs';
|
|
4
3
|
import { createDomMotionConfig } from './utils/create-config.mjs';
|
|
@@ -9,16 +8,14 @@ import { createDomVisualElement } from './create-visual-element.mjs';
|
|
|
9
8
|
import { layoutFeatures } from '../../motion/features/layout/index.mjs';
|
|
10
9
|
import { HTMLProjectionNode } from '../../projection/node/HTMLProjectionNode.mjs';
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
const featureBundle = Object.assign(Object.assign(Object.assign(Object.assign({}, animations), gestureAnimations), drag), layoutFeatures);
|
|
13
12
|
/**
|
|
14
13
|
* HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
|
15
14
|
* drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
|
16
15
|
*
|
|
17
16
|
* @public
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
return createDomMotionConfig(Component, config, featureBundle, createDomVisualElement, HTMLProjectionNode);
|
|
21
|
-
});
|
|
18
|
+
const motion = /*@__PURE__*/ createMotionProxy((Component, config) => createDomMotionConfig(Component, config, featureBundle, createDomVisualElement, HTMLProjectionNode));
|
|
22
19
|
/**
|
|
23
20
|
* Create a DOM `motion` component with the provided string. This is primarily intended
|
|
24
21
|
* as a full alternative to `motion` for consumers who have to support environments that don't
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { createElement } from 'react';
|
|
3
2
|
import { useHTMLProps } from '../html/use-props.mjs';
|
|
4
3
|
import { filterProps } from './utils/filter-props.mjs';
|
|
5
4
|
import { isSVGComponent } from './utils/is-svg-component.mjs';
|
|
6
5
|
import { useSVGProps } from '../svg/use-props.mjs';
|
|
7
6
|
|
|
8
|
-
function createUseRender(forwardMotionProps) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var latestValues = _a.latestValues;
|
|
12
|
-
var useVisualProps = isSVGComponent(Component)
|
|
7
|
+
function createUseRender(forwardMotionProps = false) {
|
|
8
|
+
const useRender = (Component, props, projectionId, ref, { latestValues }, isStatic) => {
|
|
9
|
+
const useVisualProps = isSVGComponent(Component)
|
|
13
10
|
? useSVGProps
|
|
14
11
|
: useHTMLProps;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const visualProps = useVisualProps(props, latestValues, isStatic);
|
|
13
|
+
const filteredProps = filterProps(props, typeof Component === "string", forwardMotionProps);
|
|
14
|
+
const elementProps = Object.assign(Object.assign(Object.assign({}, filteredProps), visualProps), { ref });
|
|
18
15
|
if (projectionId) {
|
|
19
16
|
elementProps["data-projection-id"] = projectionId;
|
|
20
17
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
|
|
2
|
+
const REPLACE_TEMPLATE = "$1-$2";
|
|
3
3
|
/**
|
|
4
4
|
* Convert camelCase to dash-case properties.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
return str.replace(CAMEL_CASE_PATTERN, REPLACE_TEMPLATE).toLowerCase();
|
|
8
|
-
};
|
|
6
|
+
const camelToDash = (str) => str.replace(CAMEL_CASE_PATTERN, REPLACE_TEMPLATE).toLowerCase();
|
|
9
7
|
|
|
10
8
|
export { camelToDash };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { isSVGComponent } from './is-svg-component.mjs';
|
|
3
2
|
import { createUseRender } from '../use-render.mjs';
|
|
4
3
|
import { svgMotionConfig } from '../../svg/config-motion.mjs';
|
|
5
4
|
import { htmlMotionConfig } from '../../html/config-motion.mjs';
|
|
6
5
|
|
|
7
|
-
function createDomMotionConfig(Component,
|
|
8
|
-
|
|
9
|
-
var baseConfig = isSVGComponent(Component)
|
|
6
|
+
function createDomMotionConfig(Component, { forwardMotionProps = false }, preloadedFeatures, createVisualElement, projectionNodeConstructor) {
|
|
7
|
+
const baseConfig = isSVGComponent(Component)
|
|
10
8
|
? svgMotionConfig
|
|
11
9
|
: htmlMotionConfig;
|
|
12
|
-
return
|
|
10
|
+
return Object.assign(Object.assign({}, baseConfig), { preloadedFeatures, useRender: createUseRender(forwardMotionProps), createVisualElement,
|
|
11
|
+
projectionNodeConstructor,
|
|
12
|
+
Component });
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export { createDomMotionConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { invariant } from 'hey-listen';
|
|
3
3
|
|
|
4
4
|
function isCSSVariable(value) {
|
|
@@ -13,24 +13,23 @@ function isCSSVariable(value) {
|
|
|
13
13
|
*
|
|
14
14
|
* @param current
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
const cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
|
|
17
17
|
function parseCSSVariable(current) {
|
|
18
|
-
|
|
18
|
+
const match = cssVariableRegex.exec(current);
|
|
19
19
|
if (!match)
|
|
20
20
|
return [,];
|
|
21
|
-
|
|
21
|
+
const [, token, fallback] = match;
|
|
22
22
|
return [token, fallback];
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
function getVariableValue(current, element, depth) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var _a = __read(parseCSSVariable(current), 2), token = _a[0], fallback = _a[1];
|
|
24
|
+
const maxDepth = 4;
|
|
25
|
+
function getVariableValue(current, element, depth = 1) {
|
|
26
|
+
invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`);
|
|
27
|
+
const [token, fallback] = parseCSSVariable(current);
|
|
29
28
|
// No CSS variable detected
|
|
30
29
|
if (!token)
|
|
31
30
|
return;
|
|
32
31
|
// Attempt to read this CSS variable off the element
|
|
33
|
-
|
|
32
|
+
const resolved = window.getComputedStyle(element).getPropertyValue(token);
|
|
34
33
|
if (resolved) {
|
|
35
34
|
return resolved.trim();
|
|
36
35
|
}
|
|
@@ -50,30 +49,30 @@ function getVariableValue(current, element, depth) {
|
|
|
50
49
|
function resolveCSSVariables(visualElement, _a, transitionEnd) {
|
|
51
50
|
var _b;
|
|
52
51
|
var target = __rest(_a, []);
|
|
53
|
-
|
|
52
|
+
const element = visualElement.getInstance();
|
|
54
53
|
if (!(element instanceof Element))
|
|
55
|
-
return { target
|
|
54
|
+
return { target, transitionEnd };
|
|
56
55
|
// If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
|
|
57
56
|
// only if they change but I think this reads clearer and this isn't a performance-critical path.
|
|
58
57
|
if (transitionEnd) {
|
|
59
|
-
transitionEnd =
|
|
58
|
+
transitionEnd = Object.assign({}, transitionEnd);
|
|
60
59
|
}
|
|
61
60
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
62
|
-
visualElement.forEachValue(
|
|
63
|
-
|
|
61
|
+
visualElement.forEachValue((value) => {
|
|
62
|
+
const current = value.get();
|
|
64
63
|
if (!isCSSVariable(current))
|
|
65
64
|
return;
|
|
66
|
-
|
|
65
|
+
const resolved = getVariableValue(current, element);
|
|
67
66
|
if (resolved)
|
|
68
67
|
value.set(resolved);
|
|
69
68
|
});
|
|
70
69
|
// Cycle through every target property and resolve CSS variables. Currently
|
|
71
70
|
// we only read single-var properties like `var(--foo)`, not `calc(var(--foo) + 20px)`
|
|
72
|
-
for (
|
|
73
|
-
|
|
71
|
+
for (const key in target) {
|
|
72
|
+
const current = target[key];
|
|
74
73
|
if (!isCSSVariable(current))
|
|
75
74
|
continue;
|
|
76
|
-
|
|
75
|
+
const resolved = getVariableValue(current, element);
|
|
77
76
|
if (!resolved)
|
|
78
77
|
continue;
|
|
79
78
|
// Clone target if it hasn't already been
|
|
@@ -84,7 +83,7 @@ function resolveCSSVariables(visualElement, _a, transitionEnd) {
|
|
|
84
83
|
if (transitionEnd)
|
|
85
84
|
(_b = transitionEnd[key]) !== null && _b !== void 0 ? _b : (transitionEnd[key] = current);
|
|
86
85
|
}
|
|
87
|
-
return { target
|
|
86
|
+
return { target, transitionEnd };
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
export { cssVariableRegex, parseCSSVariable, resolveCSSVariables };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { isValidMotionProp } from '../../../motion/utils/valid-prop.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let shouldForward = (key) => !isValidMotionProp(key);
|
|
4
4
|
function loadExternalIsValidProp(isValidProp) {
|
|
5
5
|
if (!isValidProp)
|
|
6
6
|
return;
|
|
7
7
|
// Explicitly filter our events
|
|
8
|
-
shouldForward =
|
|
9
|
-
return key.startsWith("on") ? !isValidMotionProp(key) : isValidProp(key);
|
|
10
|
-
};
|
|
8
|
+
shouldForward = (key) => key.startsWith("on") ? !isValidMotionProp(key) : isValidProp(key);
|
|
11
9
|
}
|
|
12
10
|
/**
|
|
13
11
|
* Emotion and Styled Components both allow users to pass through arbitrary props to their components
|
|
@@ -34,8 +32,8 @@ catch (_a) {
|
|
|
34
32
|
// We don't need to actually do anything here - the fallback is the existing `isPropValid`.
|
|
35
33
|
}
|
|
36
34
|
function filterProps(props, isDom, forwardMotionProps) {
|
|
37
|
-
|
|
38
|
-
for (
|
|
35
|
+
const filteredProps = {};
|
|
36
|
+
for (const key in props) {
|
|
39
37
|
if (shouldForward(key) ||
|
|
40
38
|
(forwardMotionProps === true && isValidMotionProp(key)) ||
|
|
41
39
|
(!isDom && !isValidMotionProp(key)) ||
|
|
@@ -5,8 +5,8 @@ import { unitConversion } from './unit-conversion.mjs';
|
|
|
5
5
|
* Parse a DOM variant to make it animatable. This involves resolving CSS variables
|
|
6
6
|
* and ensuring animations like "20%" => "calc(50vw)" are performed in pixels.
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const parseDomVariant = (visualElement, target, origin, transitionEnd) => {
|
|
9
|
+
const resolved = resolveCSSVariables(visualElement, target, transitionEnd);
|
|
10
10
|
target = resolved.target;
|
|
11
11
|
transitionEnd = resolved.transitionEnd;
|
|
12
12
|
return unitConversion(visualElement, target, origin, transitionEnd);
|