framer-motion 5.4.0 → 5.4.3
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 +3721 -0
- package/dist/cjs/three-entry.js +305 -0
- package/dist/{framer-motion-three.cjs.js → cjs/use-motion-value-73ed7c77.js} +2961 -1318
- package/dist/es/components/AnimatePresence/use-presence.mjs +27 -1
- package/dist/es/context/MotionContext/index.mjs +1 -1
- package/dist/es/events/use-dom-event.mjs +31 -2
- package/dist/es/events/use-pointer-event.mjs +5 -2
- package/dist/es/gestures/utils/event-type.mjs +8 -1
- package/dist/es/projection/geometry/models.mjs +11 -1
- package/dist/es/projection/node/create-projection-node.mjs +1167 -4
- package/dist/es/render/dom/value-types/dimensions.mjs +8 -1
- package/dist/es/render/utils/animation.mjs +4 -1
- package/dist/es/render/utils/setters.mjs +39 -2
- package/dist/es/utils/array.mjs +13 -2
- package/package.json +6 -6
- package/dist/framer-motion.cjs.js +0 -8340
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var useMotionValue = require('./use-motion-value-73ed7c77.js');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var popmotion = require('popmotion');
|
|
9
|
+
var three = require('three');
|
|
10
|
+
var fiber = require('@react-three/fiber');
|
|
11
|
+
require('hey-listen');
|
|
12
|
+
require('framesync');
|
|
13
|
+
require('style-value-types');
|
|
14
|
+
|
|
15
|
+
function _interopNamespace(e) {
|
|
16
|
+
if (e && e.__esModule) return e;
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n["default"] = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
|
+
|
|
35
|
+
function useHover(isStatic, _a, visualElement) {
|
|
36
|
+
var whileHover = _a.whileHover, onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, onPointerOver = _a.onPointerOver, onPointerOut = _a.onPointerOut;
|
|
37
|
+
var isHoverEnabled = whileHover || onHoverStart || onHoverEnd;
|
|
38
|
+
if (isStatic || !visualElement || !isHoverEnabled)
|
|
39
|
+
return {};
|
|
40
|
+
return {
|
|
41
|
+
onPointerOver: function (event) {
|
|
42
|
+
var _a;
|
|
43
|
+
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(useMotionValue.AnimationType.Hover, true);
|
|
44
|
+
onPointerOver === null || onPointerOver === void 0 ? void 0 : onPointerOver(event);
|
|
45
|
+
},
|
|
46
|
+
onPointerOut: function (event) {
|
|
47
|
+
var _a;
|
|
48
|
+
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(useMotionValue.AnimationType.Hover, false);
|
|
49
|
+
onPointerOut === null || onPointerOut === void 0 ? void 0 : onPointerOut(event);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function useTap(isStatic, _a, visualElement) {
|
|
55
|
+
var whileTap = _a.whileTap, onTapStart = _a.onTapStart, onTap = _a.onTap, onTapCancel = _a.onTapCancel, onPointerDown = _a.onPointerDown;
|
|
56
|
+
var isTapEnabled = onTap || onTapStart || onTapCancel || whileTap;
|
|
57
|
+
var isPressing = React.useRef(false);
|
|
58
|
+
var cancelPointerEndListeners = React.useRef(null);
|
|
59
|
+
if (isStatic || !visualElement || !isTapEnabled)
|
|
60
|
+
return {};
|
|
61
|
+
function removePointerEndListener() {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
|
|
64
|
+
cancelPointerEndListeners.current = null;
|
|
65
|
+
}
|
|
66
|
+
function checkPointerEnd() {
|
|
67
|
+
var _a;
|
|
68
|
+
removePointerEndListener();
|
|
69
|
+
isPressing.current = false;
|
|
70
|
+
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(useMotionValue.AnimationType.Tap, false);
|
|
71
|
+
return !useMotionValue.isDragActive();
|
|
72
|
+
}
|
|
73
|
+
function onPointerUp(event, info) {
|
|
74
|
+
if (!checkPointerEnd())
|
|
75
|
+
return;
|
|
76
|
+
/**
|
|
77
|
+
* We only count this as a tap gesture if the event.target is the same
|
|
78
|
+
* as, or a child of, this component's element
|
|
79
|
+
*/
|
|
80
|
+
onTap === null || onTap === void 0 ? void 0 : onTap(event, info);
|
|
81
|
+
}
|
|
82
|
+
function onPointerCancel(event, info) {
|
|
83
|
+
if (!checkPointerEnd())
|
|
84
|
+
return;
|
|
85
|
+
onTapCancel === null || onTapCancel === void 0 ? void 0 : onTapCancel(event, info);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
onPointerDown: useMotionValue.wrapHandler(function (event, info) {
|
|
89
|
+
var _a;
|
|
90
|
+
removePointerEndListener();
|
|
91
|
+
if (isPressing.current)
|
|
92
|
+
return;
|
|
93
|
+
isPressing.current = true;
|
|
94
|
+
cancelPointerEndListeners.current = popmotion.pipe(useMotionValue.addPointerEvent(window, "pointerup", onPointerUp), useMotionValue.addPointerEvent(window, "pointercancel", onPointerCancel));
|
|
95
|
+
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(useMotionValue.AnimationType.Tap, true);
|
|
96
|
+
onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown(event);
|
|
97
|
+
onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
|
|
98
|
+
}, true),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var useRender = function (Component, props, _projectionId, ref, _state, isStatic, visualElement) {
|
|
103
|
+
return React.createElement(Component, tslib.__assign(tslib.__assign(tslib.__assign(tslib.__assign({ ref: ref }, useMotionValue.filterProps(props, false, false)), { onUpdate: props.onInstanceUpdate }), useHover(isStatic, props, visualElement)), useTap(isStatic, props, visualElement)));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var setVector = function (name, defaultValue) {
|
|
107
|
+
return function (i) {
|
|
108
|
+
return function (instance, value) {
|
|
109
|
+
var _a;
|
|
110
|
+
(_a = instance[name]) !== null && _a !== void 0 ? _a : (instance[name] = new three.Vector3(defaultValue));
|
|
111
|
+
var vector = instance[name];
|
|
112
|
+
vector.setComponent(i, value);
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
var setEuler = function (name, defaultValue) {
|
|
117
|
+
return function (axis) {
|
|
118
|
+
return function (instance, value) {
|
|
119
|
+
var _a;
|
|
120
|
+
(_a = instance[name]) !== null && _a !== void 0 ? _a : (instance[name] = new three.Euler(defaultValue));
|
|
121
|
+
var euler = instance[name];
|
|
122
|
+
euler[axis] = value;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
var setColor = function (name) { return function (instance, value) {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = instance[name]) !== null && _a !== void 0 ? _a : (instance[name] = new three.Color(value));
|
|
129
|
+
instance[name].set(value);
|
|
130
|
+
}; };
|
|
131
|
+
var setScale = setVector("scale", 1);
|
|
132
|
+
var setPosition = setVector("position", 0);
|
|
133
|
+
var setRotation = setEuler("rotation", 0);
|
|
134
|
+
var setters = {
|
|
135
|
+
x: setPosition(0),
|
|
136
|
+
y: setPosition(1),
|
|
137
|
+
z: setPosition(2),
|
|
138
|
+
scale: function (instance, value) {
|
|
139
|
+
var _a;
|
|
140
|
+
(_a = instance.scale) !== null && _a !== void 0 ? _a : (instance.scale = new three.Vector3(1));
|
|
141
|
+
var scale = instance.scale;
|
|
142
|
+
scale.set(value, value, value);
|
|
143
|
+
},
|
|
144
|
+
scaleX: setScale(0),
|
|
145
|
+
scaleY: setScale(1),
|
|
146
|
+
scaleZ: setScale(2),
|
|
147
|
+
rotateX: setRotation("x"),
|
|
148
|
+
rotateY: setRotation("y"),
|
|
149
|
+
rotateZ: setRotation("z"),
|
|
150
|
+
color: setColor("color"),
|
|
151
|
+
specular: setColor("specular"),
|
|
152
|
+
};
|
|
153
|
+
function setThreeValue(instance, key, values) {
|
|
154
|
+
if (setters[key]) {
|
|
155
|
+
setters[key](instance, values[key]);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
instance[key] = values[key];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
var readVector = function (name, defaultValue) {
|
|
163
|
+
return function (axis) {
|
|
164
|
+
return function (instance) {
|
|
165
|
+
var value = instance[name];
|
|
166
|
+
return value ? value[axis] : defaultValue;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
var readPosition = readVector("position", 0);
|
|
171
|
+
var readScale = readVector("scale", 1);
|
|
172
|
+
var readRotation = readVector("rotation", 0);
|
|
173
|
+
var readers = {
|
|
174
|
+
x: readPosition("x"),
|
|
175
|
+
y: readPosition("y"),
|
|
176
|
+
z: readPosition("z"),
|
|
177
|
+
scale: readScale("x"),
|
|
178
|
+
scaleX: readScale("x"),
|
|
179
|
+
scaleY: readScale("y"),
|
|
180
|
+
scaleZ: readScale("z"),
|
|
181
|
+
rotateX: readRotation("x"),
|
|
182
|
+
rotateY: readRotation("y"),
|
|
183
|
+
rotateZ: readRotation("z"),
|
|
184
|
+
};
|
|
185
|
+
function readAnimatableValue(value) {
|
|
186
|
+
if (!value)
|
|
187
|
+
return;
|
|
188
|
+
if (value instanceof three.Color) {
|
|
189
|
+
return value.getStyle();
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function readThreeValue(instance, name) {
|
|
196
|
+
var _a;
|
|
197
|
+
return readers[name]
|
|
198
|
+
? readers[name](instance)
|
|
199
|
+
: (_a = readAnimatableValue(instance[name])) !== null && _a !== void 0 ? _a : 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
var axes = ["x", "y", "z"];
|
|
203
|
+
var valueMap = {
|
|
204
|
+
"position-x": "x",
|
|
205
|
+
"position-y": "y",
|
|
206
|
+
"position-z": "z",
|
|
207
|
+
"rotation-x": "rotateX",
|
|
208
|
+
"rotation-y": "rotateY",
|
|
209
|
+
"rotation-z": "rotateZ",
|
|
210
|
+
"scale-x": "scaleX",
|
|
211
|
+
"scale-y": "scaleY",
|
|
212
|
+
"scale-z": "scaleZ",
|
|
213
|
+
};
|
|
214
|
+
var scrapeMotionValuesFromProps = function (props) {
|
|
215
|
+
var motionValues = {};
|
|
216
|
+
for (var key in props) {
|
|
217
|
+
var prop = props[key];
|
|
218
|
+
if (useMotionValue.isMotionValue(prop)) {
|
|
219
|
+
motionValues[valueMap[key] || key] = prop;
|
|
220
|
+
}
|
|
221
|
+
else if (Array.isArray(prop)) {
|
|
222
|
+
for (var i = 0; i < prop.length; i++) {
|
|
223
|
+
var value = prop[i];
|
|
224
|
+
if (useMotionValue.isMotionValue(value)) {
|
|
225
|
+
var name_1 = valueMap[key + "-" + axes[i]];
|
|
226
|
+
motionValues[name_1] = value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return motionValues;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
var createRenderState = function () { return ({}); };
|
|
235
|
+
var threeVisualElement = useMotionValue.visualElement({
|
|
236
|
+
treeType: "three",
|
|
237
|
+
readValueFromInstance: readThreeValue,
|
|
238
|
+
getBaseTarget: function () {
|
|
239
|
+
return undefined;
|
|
240
|
+
},
|
|
241
|
+
sortNodePosition: function (a, b) {
|
|
242
|
+
return a.id - b.id;
|
|
243
|
+
},
|
|
244
|
+
makeTargetAnimatable: function (element, target) {
|
|
245
|
+
useMotionValue.checkTargetForNewValues(element, target, {});
|
|
246
|
+
return target;
|
|
247
|
+
},
|
|
248
|
+
restoreTransform: function () { },
|
|
249
|
+
resetTransform: function () { },
|
|
250
|
+
removeValueFromRenderState: function (_key, _renderState) { },
|
|
251
|
+
measureViewportBox: useMotionValue.createBox,
|
|
252
|
+
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
253
|
+
build: function (_element, state, latestValues) {
|
|
254
|
+
for (var key in latestValues) {
|
|
255
|
+
state[key] = latestValues[key];
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
render: function (instance, renderState) {
|
|
259
|
+
for (var key in renderState) {
|
|
260
|
+
setThreeValue(instance, key, renderState);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
var createVisualElement = function (_, options) {
|
|
265
|
+
return threeVisualElement(options);
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
var useVisualState = useMotionValue.makeUseVisualState({
|
|
269
|
+
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
270
|
+
createRenderState: createRenderState,
|
|
271
|
+
});
|
|
272
|
+
var preloadedFeatures = tslib.__assign({}, useMotionValue.animations);
|
|
273
|
+
function custom(Component) {
|
|
274
|
+
return useMotionValue.createMotionComponent({
|
|
275
|
+
Component: Component,
|
|
276
|
+
preloadedFeatures: preloadedFeatures,
|
|
277
|
+
useRender: useRender,
|
|
278
|
+
useVisualState: useVisualState,
|
|
279
|
+
createVisualElement: createVisualElement,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
var componentCache = new Map();
|
|
283
|
+
var motion = new Proxy(custom, {
|
|
284
|
+
get: function (_, key) {
|
|
285
|
+
!componentCache.has(key) && componentCache.set(key, custom(key));
|
|
286
|
+
return componentCache.get(key);
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
function MotionCanvas(_a) {
|
|
291
|
+
var children = _a.children, props = tslib.__rest(_a, ["children"]);
|
|
292
|
+
var motionContext = React.useContext(useMotionValue.MotionContext);
|
|
293
|
+
return (React__namespace.createElement(fiber.Canvas, tslib.__assign({}, props),
|
|
294
|
+
React__namespace.createElement(useMotionValue.MotionContext.Provider, { value: motionContext }, children)));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function useTime() {
|
|
298
|
+
var time = useMotionValue.useMotionValue(0);
|
|
299
|
+
fiber.useFrame(function (state) { return time.set(state.clock.getElapsedTime()); });
|
|
300
|
+
return time;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
exports.MotionCanvas = MotionCanvas;
|
|
304
|
+
exports.motion = motion;
|
|
305
|
+
exports.useTime = useTime;
|