@dnd-kit/collision 0.0.6-beta-20240716134007 → 0.0.6-beta-20240716203233
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/index.cjs +68 -18
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +67 -18
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
21
21
|
var src_exports = {};
|
22
22
|
__export(src_exports, {
|
23
23
|
closestCenter: () => closestCenter,
|
24
|
+
closestCorners: () => closestCorners,
|
24
25
|
defaultCollisionDetection: () => defaultCollisionDetection,
|
25
26
|
directionBiased: () => directionBiased,
|
26
27
|
pointerDistance: () => pointerDistance,
|
@@ -63,15 +64,16 @@ var shapeIntersection = ({
|
|
63
64
|
dragOperation,
|
64
65
|
droppable
|
65
66
|
}) => {
|
66
|
-
|
67
|
+
const { shape } = dragOperation;
|
68
|
+
if (!droppable.shape || !(shape == null ? void 0 : shape.current)) {
|
67
69
|
return null;
|
68
70
|
}
|
69
|
-
const
|
70
|
-
const intersectionArea = shape == null ? void 0 : shape.current.intersectionArea(droppable.shape);
|
71
|
+
const intersectionArea = shape.current.intersectionArea(droppable.shape);
|
71
72
|
if (intersectionArea) {
|
72
73
|
const { position } = dragOperation;
|
73
74
|
const distance = import_geometry2.Point.distance(droppable.shape.center, position.current);
|
74
|
-
const
|
75
|
+
const intersectionRatio = intersectionArea / (shape.current.area + droppable.shape.area - intersectionArea);
|
76
|
+
const value = intersectionRatio / distance;
|
75
77
|
return {
|
76
78
|
id: droppable.id,
|
77
79
|
value,
|
@@ -88,9 +90,56 @@ var defaultCollisionDetection = (args) => {
|
|
88
90
|
return (_a = pointerIntersection(args)) != null ? _a : shapeIntersection(args);
|
89
91
|
};
|
90
92
|
|
91
|
-
// src/algorithms/
|
93
|
+
// src/algorithms/closestCorners.ts
|
92
94
|
var import_abstract3 = require("@dnd-kit/abstract");
|
93
95
|
var import_geometry3 = require("@dnd-kit/geometry");
|
96
|
+
var closestCorners = (input) => {
|
97
|
+
const { dragOperation, droppable } = input;
|
98
|
+
const { shape, position } = dragOperation;
|
99
|
+
if (!droppable.shape) {
|
100
|
+
return null;
|
101
|
+
}
|
102
|
+
const { left, top, right, bottom } = droppable.shape.boundingRectangle;
|
103
|
+
const corners = [
|
104
|
+
{
|
105
|
+
x: left,
|
106
|
+
y: top
|
107
|
+
},
|
108
|
+
{
|
109
|
+
x: right,
|
110
|
+
y: top
|
111
|
+
},
|
112
|
+
{
|
113
|
+
x: left,
|
114
|
+
y: bottom
|
115
|
+
},
|
116
|
+
{
|
117
|
+
x: right,
|
118
|
+
y: bottom
|
119
|
+
}
|
120
|
+
];
|
121
|
+
const distance = corners.reduce(
|
122
|
+
(acc, corner) => {
|
123
|
+
var _a;
|
124
|
+
return acc + import_geometry3.Point.distance(
|
125
|
+
import_geometry3.Point.from(corner),
|
126
|
+
(_a = shape == null ? void 0 : shape.current.center) != null ? _a : position.current
|
127
|
+
);
|
128
|
+
},
|
129
|
+
0
|
130
|
+
);
|
131
|
+
const value = distance / 4;
|
132
|
+
return {
|
133
|
+
id: droppable.id,
|
134
|
+
value: 1 / value,
|
135
|
+
type: import_abstract3.CollisionType.Collision,
|
136
|
+
priority: import_abstract3.CollisionPriority.Normal
|
137
|
+
};
|
138
|
+
};
|
139
|
+
|
140
|
+
// src/algorithms/closestCenter.ts
|
141
|
+
var import_abstract4 = require("@dnd-kit/abstract");
|
142
|
+
var import_geometry4 = require("@dnd-kit/geometry");
|
94
143
|
var closestCenter = (input) => {
|
95
144
|
var _a;
|
96
145
|
const { dragOperation, droppable } = input;
|
@@ -102,7 +151,7 @@ var closestCenter = (input) => {
|
|
102
151
|
if (collision) {
|
103
152
|
return collision;
|
104
153
|
}
|
105
|
-
const distance =
|
154
|
+
const distance = import_geometry4.Point.distance(
|
106
155
|
droppable.shape.center,
|
107
156
|
(_a = shape == null ? void 0 : shape.current.center) != null ? _a : position.current
|
108
157
|
);
|
@@ -110,14 +159,14 @@ var closestCenter = (input) => {
|
|
110
159
|
return {
|
111
160
|
id: droppable.id,
|
112
161
|
value,
|
113
|
-
type:
|
114
|
-
priority:
|
162
|
+
type: import_abstract4.CollisionType.Collision,
|
163
|
+
priority: import_abstract4.CollisionPriority.Normal
|
115
164
|
};
|
116
165
|
};
|
117
166
|
|
118
167
|
// src/algorithms/directionBiased.ts
|
119
|
-
var
|
120
|
-
var
|
168
|
+
var import_abstract5 = require("@dnd-kit/abstract");
|
169
|
+
var import_geometry5 = require("@dnd-kit/geometry");
|
121
170
|
var directionBiased = ({
|
122
171
|
dragOperation,
|
123
172
|
droppable
|
@@ -137,35 +186,36 @@ var directionBiased = ({
|
|
137
186
|
if (direction === "down" && boundingRectangle.bottom >= droppable.shape.center.y || direction === "up" && boundingRectangle.top <= droppable.shape.center.y || direction === "left" && boundingRectangle.left <= droppable.shape.center.x || direction === "right" && boundingRectangle.right >= droppable.shape.center.x) {
|
138
187
|
return {
|
139
188
|
id: droppable.id,
|
140
|
-
value: 1 /
|
141
|
-
type:
|
142
|
-
priority:
|
189
|
+
value: 1 / import_geometry5.Point.distance(droppable.shape.center, center),
|
190
|
+
type: import_abstract5.CollisionType.Collision,
|
191
|
+
priority: import_abstract5.CollisionPriority.Normal
|
143
192
|
};
|
144
193
|
}
|
145
194
|
return null;
|
146
195
|
};
|
147
196
|
|
148
197
|
// src/algorithms/pointerDistance.ts
|
149
|
-
var
|
150
|
-
var
|
198
|
+
var import_abstract6 = require("@dnd-kit/abstract");
|
199
|
+
var import_geometry6 = require("@dnd-kit/geometry");
|
151
200
|
var pointerDistance = (input) => {
|
152
201
|
const { dragOperation, droppable } = input;
|
153
202
|
const { position } = dragOperation;
|
154
203
|
if (!droppable.shape) {
|
155
204
|
return null;
|
156
205
|
}
|
157
|
-
const distance =
|
206
|
+
const distance = import_geometry6.Point.distance(droppable.shape.center, position.current);
|
158
207
|
const value = 1 / distance;
|
159
208
|
return {
|
160
209
|
id: droppable.id,
|
161
210
|
value,
|
162
|
-
type:
|
163
|
-
priority:
|
211
|
+
type: import_abstract6.CollisionType.Collision,
|
212
|
+
priority: import_abstract6.CollisionPriority.Normal
|
164
213
|
};
|
165
214
|
};
|
166
215
|
// Annotate the CommonJS export names for ESM import in node:
|
167
216
|
0 && (module.exports = {
|
168
217
|
closestCenter,
|
218
|
+
closestCorners,
|
169
219
|
defaultCollisionDetection,
|
170
220
|
directionBiased,
|
171
221
|
pointerDistance,
|
package/dist/index.d.cts
CHANGED
@@ -9,6 +9,11 @@ export { CollisionDetector } from '@dnd-kit/abstract';
|
|
9
9
|
*/
|
10
10
|
declare const defaultCollisionDetection: CollisionDetector;
|
11
11
|
|
12
|
+
/**
|
13
|
+
* Returns the distance between the corners of the droppable shape and the drag operation shape.
|
14
|
+
*/
|
15
|
+
declare const closestCorners: CollisionDetector;
|
16
|
+
|
12
17
|
/**
|
13
18
|
* Returns the distance between the droppable shape and the drag operation shape.
|
14
19
|
*/
|
@@ -38,4 +43,4 @@ declare const directionBiased: CollisionDetector;
|
|
38
43
|
*/
|
39
44
|
declare const pointerDistance: CollisionDetector;
|
40
45
|
|
41
|
-
export { closestCenter, defaultCollisionDetection, directionBiased, pointerDistance, pointerIntersection, shapeIntersection };
|
46
|
+
export { closestCenter, closestCorners, defaultCollisionDetection, directionBiased, pointerDistance, pointerIntersection, shapeIntersection };
|
package/dist/index.d.ts
CHANGED
@@ -9,6 +9,11 @@ export { CollisionDetector } from '@dnd-kit/abstract';
|
|
9
9
|
*/
|
10
10
|
declare const defaultCollisionDetection: CollisionDetector;
|
11
11
|
|
12
|
+
/**
|
13
|
+
* Returns the distance between the corners of the droppable shape and the drag operation shape.
|
14
|
+
*/
|
15
|
+
declare const closestCorners: CollisionDetector;
|
16
|
+
|
12
17
|
/**
|
13
18
|
* Returns the distance between the droppable shape and the drag operation shape.
|
14
19
|
*/
|
@@ -38,4 +43,4 @@ declare const directionBiased: CollisionDetector;
|
|
38
43
|
*/
|
39
44
|
declare const pointerDistance: CollisionDetector;
|
40
45
|
|
41
|
-
export { closestCenter, defaultCollisionDetection, directionBiased, pointerDistance, pointerIntersection, shapeIntersection };
|
46
|
+
export { closestCenter, closestCorners, defaultCollisionDetection, directionBiased, pointerDistance, pointerIntersection, shapeIntersection };
|
package/dist/index.js
CHANGED
@@ -32,15 +32,16 @@ var shapeIntersection = ({
|
|
32
32
|
dragOperation,
|
33
33
|
droppable
|
34
34
|
}) => {
|
35
|
-
|
35
|
+
const { shape } = dragOperation;
|
36
|
+
if (!droppable.shape || !(shape == null ? void 0 : shape.current)) {
|
36
37
|
return null;
|
37
38
|
}
|
38
|
-
const
|
39
|
-
const intersectionArea = shape == null ? void 0 : shape.current.intersectionArea(droppable.shape);
|
39
|
+
const intersectionArea = shape.current.intersectionArea(droppable.shape);
|
40
40
|
if (intersectionArea) {
|
41
41
|
const { position } = dragOperation;
|
42
42
|
const distance = Point2.distance(droppable.shape.center, position.current);
|
43
|
-
const
|
43
|
+
const intersectionRatio = intersectionArea / (shape.current.area + droppable.shape.area - intersectionArea);
|
44
|
+
const value = intersectionRatio / distance;
|
44
45
|
return {
|
45
46
|
id: droppable.id,
|
46
47
|
value,
|
@@ -57,9 +58,56 @@ var defaultCollisionDetection = (args) => {
|
|
57
58
|
return (_a = pointerIntersection(args)) != null ? _a : shapeIntersection(args);
|
58
59
|
};
|
59
60
|
|
60
|
-
// src/algorithms/
|
61
|
+
// src/algorithms/closestCorners.ts
|
61
62
|
import { CollisionPriority as CollisionPriority3, CollisionType as CollisionType3 } from "@dnd-kit/abstract";
|
62
63
|
import { Point as Point3 } from "@dnd-kit/geometry";
|
64
|
+
var closestCorners = (input) => {
|
65
|
+
const { dragOperation, droppable } = input;
|
66
|
+
const { shape, position } = dragOperation;
|
67
|
+
if (!droppable.shape) {
|
68
|
+
return null;
|
69
|
+
}
|
70
|
+
const { left, top, right, bottom } = droppable.shape.boundingRectangle;
|
71
|
+
const corners = [
|
72
|
+
{
|
73
|
+
x: left,
|
74
|
+
y: top
|
75
|
+
},
|
76
|
+
{
|
77
|
+
x: right,
|
78
|
+
y: top
|
79
|
+
},
|
80
|
+
{
|
81
|
+
x: left,
|
82
|
+
y: bottom
|
83
|
+
},
|
84
|
+
{
|
85
|
+
x: right,
|
86
|
+
y: bottom
|
87
|
+
}
|
88
|
+
];
|
89
|
+
const distance = corners.reduce(
|
90
|
+
(acc, corner) => {
|
91
|
+
var _a;
|
92
|
+
return acc + Point3.distance(
|
93
|
+
Point3.from(corner),
|
94
|
+
(_a = shape == null ? void 0 : shape.current.center) != null ? _a : position.current
|
95
|
+
);
|
96
|
+
},
|
97
|
+
0
|
98
|
+
);
|
99
|
+
const value = distance / 4;
|
100
|
+
return {
|
101
|
+
id: droppable.id,
|
102
|
+
value: 1 / value,
|
103
|
+
type: CollisionType3.Collision,
|
104
|
+
priority: CollisionPriority3.Normal
|
105
|
+
};
|
106
|
+
};
|
107
|
+
|
108
|
+
// src/algorithms/closestCenter.ts
|
109
|
+
import { CollisionPriority as CollisionPriority4, CollisionType as CollisionType4 } from "@dnd-kit/abstract";
|
110
|
+
import { Point as Point4 } from "@dnd-kit/geometry";
|
63
111
|
var closestCenter = (input) => {
|
64
112
|
var _a;
|
65
113
|
const { dragOperation, droppable } = input;
|
@@ -71,7 +119,7 @@ var closestCenter = (input) => {
|
|
71
119
|
if (collision) {
|
72
120
|
return collision;
|
73
121
|
}
|
74
|
-
const distance =
|
122
|
+
const distance = Point4.distance(
|
75
123
|
droppable.shape.center,
|
76
124
|
(_a = shape == null ? void 0 : shape.current.center) != null ? _a : position.current
|
77
125
|
);
|
@@ -79,14 +127,14 @@ var closestCenter = (input) => {
|
|
79
127
|
return {
|
80
128
|
id: droppable.id,
|
81
129
|
value,
|
82
|
-
type:
|
83
|
-
priority:
|
130
|
+
type: CollisionType4.Collision,
|
131
|
+
priority: CollisionPriority4.Normal
|
84
132
|
};
|
85
133
|
};
|
86
134
|
|
87
135
|
// src/algorithms/directionBiased.ts
|
88
|
-
import { CollisionPriority as
|
89
|
-
import { Point as
|
136
|
+
import { CollisionPriority as CollisionPriority5, CollisionType as CollisionType5 } from "@dnd-kit/abstract";
|
137
|
+
import { Point as Point5 } from "@dnd-kit/geometry";
|
90
138
|
var directionBiased = ({
|
91
139
|
dragOperation,
|
92
140
|
droppable
|
@@ -106,34 +154,35 @@ var directionBiased = ({
|
|
106
154
|
if (direction === "down" && boundingRectangle.bottom >= droppable.shape.center.y || direction === "up" && boundingRectangle.top <= droppable.shape.center.y || direction === "left" && boundingRectangle.left <= droppable.shape.center.x || direction === "right" && boundingRectangle.right >= droppable.shape.center.x) {
|
107
155
|
return {
|
108
156
|
id: droppable.id,
|
109
|
-
value: 1 /
|
110
|
-
type:
|
111
|
-
priority:
|
157
|
+
value: 1 / Point5.distance(droppable.shape.center, center),
|
158
|
+
type: CollisionType5.Collision,
|
159
|
+
priority: CollisionPriority5.Normal
|
112
160
|
};
|
113
161
|
}
|
114
162
|
return null;
|
115
163
|
};
|
116
164
|
|
117
165
|
// src/algorithms/pointerDistance.ts
|
118
|
-
import { CollisionPriority as
|
119
|
-
import { Point as
|
166
|
+
import { CollisionPriority as CollisionPriority6, CollisionType as CollisionType6 } from "@dnd-kit/abstract";
|
167
|
+
import { Point as Point6 } from "@dnd-kit/geometry";
|
120
168
|
var pointerDistance = (input) => {
|
121
169
|
const { dragOperation, droppable } = input;
|
122
170
|
const { position } = dragOperation;
|
123
171
|
if (!droppable.shape) {
|
124
172
|
return null;
|
125
173
|
}
|
126
|
-
const distance =
|
174
|
+
const distance = Point6.distance(droppable.shape.center, position.current);
|
127
175
|
const value = 1 / distance;
|
128
176
|
return {
|
129
177
|
id: droppable.id,
|
130
178
|
value,
|
131
|
-
type:
|
132
|
-
priority:
|
179
|
+
type: CollisionType6.Collision,
|
180
|
+
priority: CollisionPriority6.Normal
|
133
181
|
};
|
134
182
|
};
|
135
183
|
export {
|
136
184
|
closestCenter,
|
185
|
+
closestCorners,
|
137
186
|
defaultCollisionDetection,
|
138
187
|
directionBiased,
|
139
188
|
pointerDistance,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dnd-kit/collision",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.0.6-beta-
|
4
|
+
"version": "0.0.6-beta-20240716203233",
|
5
5
|
"main": "./dist/index.cjs",
|
6
6
|
"module": "./dist/index.js",
|
7
7
|
"types": "./dist/index.d.ts",
|
@@ -24,8 +24,8 @@
|
|
24
24
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
25
25
|
},
|
26
26
|
"dependencies": {
|
27
|
-
"@dnd-kit/abstract": "0.0.6-beta-
|
28
|
-
"@dnd-kit/geometry": "0.0.6-beta-
|
27
|
+
"@dnd-kit/abstract": "0.0.6-beta-20240716203233",
|
28
|
+
"@dnd-kit/geometry": "0.0.6-beta-20240716203233",
|
29
29
|
"tslib": "^2.6.2"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|