framer-motion 12.22.0 → 12.23.0
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-Dr1Bf9gl.js → create-C-c1JfhA.js} +31 -6
- package/dist/cjs/index.js +29 -1
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +31 -6
- package/dist/es/gestures/drag/use-drag-controls.mjs +28 -0
- package/dist/framer-motion.dev.js +59 -6
- package/dist/framer-motion.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-motion.js +1 -1
- package/dist/types/index.d.ts +20 -0
- package/package.json +2 -2
package/dist/cjs/client.js
CHANGED
|
@@ -4607,6 +4607,14 @@ class VisualElementDragControls {
|
|
|
4607
4607
|
* The per-axis resolved elastic values.
|
|
4608
4608
|
*/
|
|
4609
4609
|
this.elastic = createBox();
|
|
4610
|
+
/**
|
|
4611
|
+
* The latest pointer event. Used as fallback when the `cancel` and `stop` functions are called without arguments.
|
|
4612
|
+
*/
|
|
4613
|
+
this.latestPointerEvent = null;
|
|
4614
|
+
/**
|
|
4615
|
+
* The latest pan info. Used as fallback when the `cancel` and `stop` functions are called without arguments.
|
|
4616
|
+
*/
|
|
4617
|
+
this.latestPanInfo = null;
|
|
4610
4618
|
this.visualElement = visualElement;
|
|
4611
4619
|
}
|
|
4612
4620
|
start(originEvent, { snapToCursor = false, distanceThreshold } = {}) {
|
|
@@ -4636,6 +4644,8 @@ class VisualElementDragControls {
|
|
|
4636
4644
|
if (!this.openDragLock)
|
|
4637
4645
|
return;
|
|
4638
4646
|
}
|
|
4647
|
+
this.latestPointerEvent = event;
|
|
4648
|
+
this.latestPanInfo = info;
|
|
4639
4649
|
this.isDragging = true;
|
|
4640
4650
|
this.currentDirection = null;
|
|
4641
4651
|
this.resolveConstraints();
|
|
@@ -4672,7 +4682,8 @@ class VisualElementDragControls {
|
|
|
4672
4682
|
animationState && animationState.setActive("whileDrag", true);
|
|
4673
4683
|
};
|
|
4674
4684
|
const onMove = (event, info) => {
|
|
4675
|
-
|
|
4685
|
+
this.latestPointerEvent = event;
|
|
4686
|
+
this.latestPanInfo = info;
|
|
4676
4687
|
const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
|
|
4677
4688
|
// If we didn't successfully receive the gesture lock, early return.
|
|
4678
4689
|
if (!dragPropagation && !this.openDragLock)
|
|
@@ -4703,7 +4714,13 @@ class VisualElementDragControls {
|
|
|
4703
4714
|
*/
|
|
4704
4715
|
onDrag && onDrag(event, info);
|
|
4705
4716
|
};
|
|
4706
|
-
const onSessionEnd = (event, info) =>
|
|
4717
|
+
const onSessionEnd = (event, info) => {
|
|
4718
|
+
this.latestPointerEvent = event;
|
|
4719
|
+
this.latestPanInfo = info;
|
|
4720
|
+
this.stop(event, info);
|
|
4721
|
+
this.latestPointerEvent = null;
|
|
4722
|
+
this.latestPanInfo = null;
|
|
4723
|
+
};
|
|
4707
4724
|
const resumeAnimation = () => eachAxis((axis) => this.getAnimationState(axis) === "paused" &&
|
|
4708
4725
|
this.getAxisMotionValue(axis).animation?.play());
|
|
4709
4726
|
const { dragSnapToOrigin } = this.getProps();
|
|
@@ -4720,18 +4737,26 @@ class VisualElementDragControls {
|
|
|
4720
4737
|
contextWindow: getContextWindow(this.visualElement),
|
|
4721
4738
|
});
|
|
4722
4739
|
}
|
|
4723
|
-
|
|
4740
|
+
/**
|
|
4741
|
+
* @internal
|
|
4742
|
+
*/
|
|
4743
|
+
stop(event, panInfo) {
|
|
4744
|
+
const finalEvent = event || this.latestPointerEvent;
|
|
4745
|
+
const finalPanInfo = panInfo || this.latestPanInfo;
|
|
4724
4746
|
const isDragging = this.isDragging;
|
|
4725
4747
|
this.cancel();
|
|
4726
|
-
if (!isDragging)
|
|
4748
|
+
if (!isDragging || !finalPanInfo || !finalEvent)
|
|
4727
4749
|
return;
|
|
4728
|
-
const { velocity } =
|
|
4750
|
+
const { velocity } = finalPanInfo;
|
|
4729
4751
|
this.startAnimation(velocity);
|
|
4730
4752
|
const { onDragEnd } = this.getProps();
|
|
4731
4753
|
if (onDragEnd) {
|
|
4732
|
-
motionDom.frame.postRender(() => onDragEnd(
|
|
4754
|
+
motionDom.frame.postRender(() => onDragEnd(finalEvent, finalPanInfo));
|
|
4733
4755
|
}
|
|
4734
4756
|
}
|
|
4757
|
+
/**
|
|
4758
|
+
* @internal
|
|
4759
|
+
*/
|
|
4735
4760
|
cancel() {
|
|
4736
4761
|
this.isDragging = false;
|
|
4737
4762
|
const { projection, animationState } = this.visualElement;
|
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-C-c1JfhA.js');
|
|
8
8
|
var motionDom = require('motion-dom');
|
|
9
9
|
var motionUtils = require('motion-utils');
|
|
10
10
|
|
|
@@ -2309,6 +2309,34 @@ class DragControls {
|
|
|
2309
2309
|
controls.start(event.nativeEvent || event, options);
|
|
2310
2310
|
});
|
|
2311
2311
|
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Cancels a drag gesture.
|
|
2314
|
+
*
|
|
2315
|
+
* ```jsx
|
|
2316
|
+
* dragControls.cancel()
|
|
2317
|
+
* ```
|
|
2318
|
+
*
|
|
2319
|
+
* @public
|
|
2320
|
+
*/
|
|
2321
|
+
cancel() {
|
|
2322
|
+
this.componentControls.forEach((controls) => {
|
|
2323
|
+
controls.cancel();
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Stops a drag gesture.
|
|
2328
|
+
*
|
|
2329
|
+
* ```jsx
|
|
2330
|
+
* dragControls.stop()
|
|
2331
|
+
* ```
|
|
2332
|
+
*
|
|
2333
|
+
* @public
|
|
2334
|
+
*/
|
|
2335
|
+
stop() {
|
|
2336
|
+
this.componentControls.forEach((controls) => {
|
|
2337
|
+
controls.stop();
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2312
2340
|
}
|
|
2313
2341
|
const createDragControls = () => new DragControls();
|
|
2314
2342
|
/**
|
|
@@ -31,6 +31,14 @@ class VisualElementDragControls {
|
|
|
31
31
|
* The per-axis resolved elastic values.
|
|
32
32
|
*/
|
|
33
33
|
this.elastic = createBox();
|
|
34
|
+
/**
|
|
35
|
+
* The latest pointer event. Used as fallback when the `cancel` and `stop` functions are called without arguments.
|
|
36
|
+
*/
|
|
37
|
+
this.latestPointerEvent = null;
|
|
38
|
+
/**
|
|
39
|
+
* The latest pan info. Used as fallback when the `cancel` and `stop` functions are called without arguments.
|
|
40
|
+
*/
|
|
41
|
+
this.latestPanInfo = null;
|
|
34
42
|
this.visualElement = visualElement;
|
|
35
43
|
}
|
|
36
44
|
start(originEvent, { snapToCursor = false, distanceThreshold } = {}) {
|
|
@@ -60,6 +68,8 @@ class VisualElementDragControls {
|
|
|
60
68
|
if (!this.openDragLock)
|
|
61
69
|
return;
|
|
62
70
|
}
|
|
71
|
+
this.latestPointerEvent = event;
|
|
72
|
+
this.latestPanInfo = info;
|
|
63
73
|
this.isDragging = true;
|
|
64
74
|
this.currentDirection = null;
|
|
65
75
|
this.resolveConstraints();
|
|
@@ -96,7 +106,8 @@ class VisualElementDragControls {
|
|
|
96
106
|
animationState && animationState.setActive("whileDrag", true);
|
|
97
107
|
};
|
|
98
108
|
const onMove = (event, info) => {
|
|
99
|
-
|
|
109
|
+
this.latestPointerEvent = event;
|
|
110
|
+
this.latestPanInfo = info;
|
|
100
111
|
const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
|
|
101
112
|
// If we didn't successfully receive the gesture lock, early return.
|
|
102
113
|
if (!dragPropagation && !this.openDragLock)
|
|
@@ -127,7 +138,13 @@ class VisualElementDragControls {
|
|
|
127
138
|
*/
|
|
128
139
|
onDrag && onDrag(event, info);
|
|
129
140
|
};
|
|
130
|
-
const onSessionEnd = (event, info) =>
|
|
141
|
+
const onSessionEnd = (event, info) => {
|
|
142
|
+
this.latestPointerEvent = event;
|
|
143
|
+
this.latestPanInfo = info;
|
|
144
|
+
this.stop(event, info);
|
|
145
|
+
this.latestPointerEvent = null;
|
|
146
|
+
this.latestPanInfo = null;
|
|
147
|
+
};
|
|
131
148
|
const resumeAnimation = () => eachAxis((axis) => this.getAnimationState(axis) === "paused" &&
|
|
132
149
|
this.getAxisMotionValue(axis).animation?.play());
|
|
133
150
|
const { dragSnapToOrigin } = this.getProps();
|
|
@@ -144,18 +161,26 @@ class VisualElementDragControls {
|
|
|
144
161
|
contextWindow: getContextWindow(this.visualElement),
|
|
145
162
|
});
|
|
146
163
|
}
|
|
147
|
-
|
|
164
|
+
/**
|
|
165
|
+
* @internal
|
|
166
|
+
*/
|
|
167
|
+
stop(event, panInfo) {
|
|
168
|
+
const finalEvent = event || this.latestPointerEvent;
|
|
169
|
+
const finalPanInfo = panInfo || this.latestPanInfo;
|
|
148
170
|
const isDragging = this.isDragging;
|
|
149
171
|
this.cancel();
|
|
150
|
-
if (!isDragging)
|
|
172
|
+
if (!isDragging || !finalPanInfo || !finalEvent)
|
|
151
173
|
return;
|
|
152
|
-
const { velocity } =
|
|
174
|
+
const { velocity } = finalPanInfo;
|
|
153
175
|
this.startAnimation(velocity);
|
|
154
176
|
const { onDragEnd } = this.getProps();
|
|
155
177
|
if (onDragEnd) {
|
|
156
|
-
frame.postRender(() => onDragEnd(
|
|
178
|
+
frame.postRender(() => onDragEnd(finalEvent, finalPanInfo));
|
|
157
179
|
}
|
|
158
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
159
184
|
cancel() {
|
|
160
185
|
this.isDragging = false;
|
|
161
186
|
const { projection, animationState } = this.visualElement;
|
|
@@ -53,6 +53,34 @@ class DragControls {
|
|
|
53
53
|
controls.start(event.nativeEvent || event, options);
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Cancels a drag gesture.
|
|
58
|
+
*
|
|
59
|
+
* ```jsx
|
|
60
|
+
* dragControls.cancel()
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
cancel() {
|
|
66
|
+
this.componentControls.forEach((controls) => {
|
|
67
|
+
controls.cancel();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Stops a drag gesture.
|
|
72
|
+
*
|
|
73
|
+
* ```jsx
|
|
74
|
+
* dragControls.stop()
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
stop() {
|
|
80
|
+
this.componentControls.forEach((controls) => {
|
|
81
|
+
controls.stop();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
56
84
|
}
|
|
57
85
|
const createDragControls = () => new DragControls();
|
|
58
86
|
/**
|
|
@@ -10105,6 +10105,14 @@
|
|
|
10105
10105
|
* The per-axis resolved elastic values.
|
|
10106
10106
|
*/
|
|
10107
10107
|
this.elastic = createBox();
|
|
10108
|
+
/**
|
|
10109
|
+
* The latest pointer event. Used as fallback when the `cancel` and `stop` functions are called without arguments.
|
|
10110
|
+
*/
|
|
10111
|
+
this.latestPointerEvent = null;
|
|
10112
|
+
/**
|
|
10113
|
+
* The latest pan info. Used as fallback when the `cancel` and `stop` functions are called without arguments.
|
|
10114
|
+
*/
|
|
10115
|
+
this.latestPanInfo = null;
|
|
10108
10116
|
this.visualElement = visualElement;
|
|
10109
10117
|
}
|
|
10110
10118
|
start(originEvent, { snapToCursor = false, distanceThreshold } = {}) {
|
|
@@ -10134,6 +10142,8 @@
|
|
|
10134
10142
|
if (!this.openDragLock)
|
|
10135
10143
|
return;
|
|
10136
10144
|
}
|
|
10145
|
+
this.latestPointerEvent = event;
|
|
10146
|
+
this.latestPanInfo = info;
|
|
10137
10147
|
this.isDragging = true;
|
|
10138
10148
|
this.currentDirection = null;
|
|
10139
10149
|
this.resolveConstraints();
|
|
@@ -10170,7 +10180,8 @@
|
|
|
10170
10180
|
animationState && animationState.setActive("whileDrag", true);
|
|
10171
10181
|
};
|
|
10172
10182
|
const onMove = (event, info) => {
|
|
10173
|
-
|
|
10183
|
+
this.latestPointerEvent = event;
|
|
10184
|
+
this.latestPanInfo = info;
|
|
10174
10185
|
const { dragPropagation, dragDirectionLock, onDirectionLock, onDrag, } = this.getProps();
|
|
10175
10186
|
// If we didn't successfully receive the gesture lock, early return.
|
|
10176
10187
|
if (!dragPropagation && !this.openDragLock)
|
|
@@ -10201,7 +10212,13 @@
|
|
|
10201
10212
|
*/
|
|
10202
10213
|
onDrag && onDrag(event, info);
|
|
10203
10214
|
};
|
|
10204
|
-
const onSessionEnd = (event, info) =>
|
|
10215
|
+
const onSessionEnd = (event, info) => {
|
|
10216
|
+
this.latestPointerEvent = event;
|
|
10217
|
+
this.latestPanInfo = info;
|
|
10218
|
+
this.stop(event, info);
|
|
10219
|
+
this.latestPointerEvent = null;
|
|
10220
|
+
this.latestPanInfo = null;
|
|
10221
|
+
};
|
|
10205
10222
|
const resumeAnimation = () => eachAxis((axis) => this.getAnimationState(axis) === "paused" &&
|
|
10206
10223
|
this.getAxisMotionValue(axis).animation?.play());
|
|
10207
10224
|
const { dragSnapToOrigin } = this.getProps();
|
|
@@ -10218,18 +10235,26 @@
|
|
|
10218
10235
|
contextWindow: getContextWindow(this.visualElement),
|
|
10219
10236
|
});
|
|
10220
10237
|
}
|
|
10221
|
-
|
|
10238
|
+
/**
|
|
10239
|
+
* @internal
|
|
10240
|
+
*/
|
|
10241
|
+
stop(event, panInfo) {
|
|
10242
|
+
const finalEvent = event || this.latestPointerEvent;
|
|
10243
|
+
const finalPanInfo = panInfo || this.latestPanInfo;
|
|
10222
10244
|
const isDragging = this.isDragging;
|
|
10223
10245
|
this.cancel();
|
|
10224
|
-
if (!isDragging)
|
|
10246
|
+
if (!isDragging || !finalPanInfo || !finalEvent)
|
|
10225
10247
|
return;
|
|
10226
|
-
const { velocity } =
|
|
10248
|
+
const { velocity } = finalPanInfo;
|
|
10227
10249
|
this.startAnimation(velocity);
|
|
10228
10250
|
const { onDragEnd } = this.getProps();
|
|
10229
10251
|
if (onDragEnd) {
|
|
10230
|
-
frame.postRender(() => onDragEnd(
|
|
10252
|
+
frame.postRender(() => onDragEnd(finalEvent, finalPanInfo));
|
|
10231
10253
|
}
|
|
10232
10254
|
}
|
|
10255
|
+
/**
|
|
10256
|
+
* @internal
|
|
10257
|
+
*/
|
|
10233
10258
|
cancel() {
|
|
10234
10259
|
this.isDragging = false;
|
|
10235
10260
|
const { projection, animationState } = this.visualElement;
|
|
@@ -13449,6 +13474,34 @@
|
|
|
13449
13474
|
controls.start(event.nativeEvent || event, options);
|
|
13450
13475
|
});
|
|
13451
13476
|
}
|
|
13477
|
+
/**
|
|
13478
|
+
* Cancels a drag gesture.
|
|
13479
|
+
*
|
|
13480
|
+
* ```jsx
|
|
13481
|
+
* dragControls.cancel()
|
|
13482
|
+
* ```
|
|
13483
|
+
*
|
|
13484
|
+
* @public
|
|
13485
|
+
*/
|
|
13486
|
+
cancel() {
|
|
13487
|
+
this.componentControls.forEach((controls) => {
|
|
13488
|
+
controls.cancel();
|
|
13489
|
+
});
|
|
13490
|
+
}
|
|
13491
|
+
/**
|
|
13492
|
+
* Stops a drag gesture.
|
|
13493
|
+
*
|
|
13494
|
+
* ```jsx
|
|
13495
|
+
* dragControls.stop()
|
|
13496
|
+
* ```
|
|
13497
|
+
*
|
|
13498
|
+
* @public
|
|
13499
|
+
*/
|
|
13500
|
+
stop() {
|
|
13501
|
+
this.componentControls.forEach((controls) => {
|
|
13502
|
+
controls.stop();
|
|
13503
|
+
});
|
|
13504
|
+
}
|
|
13452
13505
|
}
|
|
13453
13506
|
const createDragControls = () => new DragControls();
|
|
13454
13507
|
/**
|