@hanzogui/floating 3.0.6 → 4.3.1
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/Floating.cjs +7 -5
- package/dist/cjs/Floating.native.js +18 -16
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +28 -26
- package/dist/cjs/index.native.js +28 -26
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +21 -12
- package/dist/cjs/interactions/PopupTriggerMap.native.js +51 -27
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -1
- package/dist/cjs/interactions/createFloatingEvents.cjs +21 -12
- package/dist/cjs/interactions/createFloatingEvents.native.js +22 -13
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -1
- package/dist/cjs/interactions/safePolygon.cjs +213 -131
- package/dist/cjs/interactions/safePolygon.native.js +182 -103
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -1
- package/dist/cjs/interactions/types.cjs +7 -5
- package/dist/cjs/interactions/types.native.js +7 -5
- package/dist/cjs/interactions/types.native.js.map +1 -1
- package/dist/cjs/interactions/useClick.cjs +91 -49
- package/dist/cjs/interactions/useClick.native.js +96 -54
- package/dist/cjs/interactions/useClick.native.js.map +1 -1
- package/dist/cjs/interactions/useDelayGroup.cjs +63 -44
- package/dist/cjs/interactions/useDelayGroup.native.js +74 -58
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -1
- package/dist/cjs/interactions/useFocus.cjs +73 -44
- package/dist/cjs/interactions/useFocus.native.js +75 -49
- package/dist/cjs/interactions/useFocus.native.js.map +1 -1
- package/dist/cjs/interactions/useHover.cjs +242 -109
- package/dist/cjs/interactions/useHover.native.js +268 -143
- package/dist/cjs/interactions/useHover.native.js.map +1 -1
- package/dist/cjs/interactions/useInnerOffset.cjs +88 -64
- package/dist/cjs/interactions/useInnerOffset.native.js +88 -65
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -1
- package/dist/cjs/interactions/useInteractions.cjs +60 -31
- package/dist/cjs/interactions/useInteractions.native.js +133 -81
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -1
- package/dist/cjs/interactions/useListNavigation.cjs +346 -181
- package/dist/cjs/interactions/useListNavigation.native.js +350 -214
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -1
- package/dist/cjs/interactions/useRole.cjs +83 -73
- package/dist/cjs/interactions/useRole.native.js +107 -99
- package/dist/cjs/interactions/useRole.native.js.map +1 -1
- package/dist/cjs/interactions/useTypeahead.cjs +115 -65
- package/dist/cjs/interactions/useTypeahead.native.js +122 -77
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -1
- package/dist/cjs/interactions/utils.cjs +68 -38
- package/dist/cjs/interactions/utils.native.js +93 -54
- package/dist/cjs/interactions/utils.native.js.map +1 -1
- package/dist/cjs/middleware/inner.cjs +80 -67
- package/dist/cjs/middleware/inner.native.js +87 -76
- package/dist/cjs/middleware/inner.native.js.map +1 -1
- package/dist/cjs/useFloating.cjs +48 -45
- package/dist/cjs/useFloating.native.js +50 -48
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.native.js +5 -5
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.mjs +9 -2
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.native.js +39 -17
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -1
- package/dist/esm/interactions/createFloatingEvents.mjs +9 -2
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -1
- package/dist/esm/interactions/createFloatingEvents.native.js +10 -3
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -1
- package/dist/esm/interactions/safePolygon.mjs +201 -121
- package/dist/esm/interactions/safePolygon.mjs.map +1 -1
- package/dist/esm/interactions/safePolygon.native.js +170 -93
- package/dist/esm/interactions/safePolygon.native.js.map +1 -1
- package/dist/esm/interactions/useClick.mjs +79 -39
- package/dist/esm/interactions/useClick.mjs.map +1 -1
- package/dist/esm/interactions/useClick.native.js +82 -42
- package/dist/esm/interactions/useClick.native.js.map +1 -1
- package/dist/esm/interactions/useDelayGroup.mjs +39 -22
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -1
- package/dist/esm/interactions/useDelayGroup.native.js +42 -28
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -1
- package/dist/esm/interactions/useFocus.mjs +59 -32
- package/dist/esm/interactions/useFocus.mjs.map +1 -1
- package/dist/esm/interactions/useFocus.native.js +61 -37
- package/dist/esm/interactions/useFocus.native.js.map +1 -1
- package/dist/esm/interactions/useHover.mjs +215 -84
- package/dist/esm/interactions/useHover.mjs.map +1 -1
- package/dist/esm/interactions/useHover.native.js +240 -117
- package/dist/esm/interactions/useHover.native.js.map +1 -1
- package/dist/esm/interactions/useInnerOffset.mjs +61 -39
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -1
- package/dist/esm/interactions/useInnerOffset.native.js +61 -40
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -1
- package/dist/esm/interactions/useInteractions.mjs +48 -21
- package/dist/esm/interactions/useInteractions.mjs.map +1 -1
- package/dist/esm/interactions/useInteractions.native.js +121 -71
- package/dist/esm/interactions/useInteractions.native.js.map +1 -1
- package/dist/esm/interactions/useListNavigation.mjs +331 -168
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -1
- package/dist/esm/interactions/useListNavigation.native.js +335 -201
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -1
- package/dist/esm/interactions/useRole.mjs +59 -51
- package/dist/esm/interactions/useRole.mjs.map +1 -1
- package/dist/esm/interactions/useRole.native.js +82 -76
- package/dist/esm/interactions/useRole.native.js.map +1 -1
- package/dist/esm/interactions/useTypeahead.mjs +100 -52
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -1
- package/dist/esm/interactions/useTypeahead.native.js +107 -64
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -1
- package/dist/esm/interactions/utils.mjs +56 -28
- package/dist/esm/interactions/utils.mjs.map +1 -1
- package/dist/esm/interactions/utils.native.js +81 -44
- package/dist/esm/interactions/utils.native.js.map +1 -1
- package/dist/esm/middleware/inner.mjs +54 -43
- package/dist/esm/middleware/inner.mjs.map +1 -1
- package/dist/esm/middleware/inner.native.js +61 -52
- package/dist/esm/middleware/inner.native.js.map +1 -1
- package/dist/esm/useFloating.mjs +22 -21
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +24 -24
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var safePolygon_exports = {};
|
|
22
24
|
__export(safePolygon_exports, {
|
|
@@ -26,12 +28,15 @@ module.exports = __toCommonJS(safePolygon_exports);
|
|
|
26
28
|
var import_utils = require("./utils.cjs");
|
|
27
29
|
function isPointInPolygon(point, polygon) {
|
|
28
30
|
const [x, y] = point;
|
|
29
|
-
let isInside2 =
|
|
31
|
+
let isInside2 = false;
|
|
30
32
|
const length = polygon.length;
|
|
31
33
|
for (let i = 0, j = length - 1; i < length; j = i++) {
|
|
32
|
-
const [xi, yi] = polygon[i] || [0, 0]
|
|
33
|
-
|
|
34
|
-
yi >= y
|
|
34
|
+
const [xi, yi] = polygon[i] || [0, 0];
|
|
35
|
+
const [xj, yj] = polygon[j] || [0, 0];
|
|
36
|
+
const intersect = yi >= y !== yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi;
|
|
37
|
+
if (intersect) {
|
|
38
|
+
isInside2 = !isInside2;
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
return isInside2;
|
|
37
42
|
}
|
|
@@ -40,51 +45,90 @@ function isInside(point, rect) {
|
|
|
40
45
|
}
|
|
41
46
|
let debugSvg = null;
|
|
42
47
|
function debugDrawPolygon(polygon, trough, cursor, anchor) {
|
|
43
|
-
if (debugSvg
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (!debugSvg) {
|
|
49
|
+
debugSvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
50
|
+
debugSvg.id = "__safe-polygon-debug";
|
|
51
|
+
Object.assign(debugSvg.style, {
|
|
52
|
+
position: "fixed",
|
|
53
|
+
inset: "0",
|
|
54
|
+
width: "100vw",
|
|
55
|
+
height: "100vh",
|
|
56
|
+
pointerEvents: "none",
|
|
57
|
+
zIndex: "999999"
|
|
58
|
+
});
|
|
59
|
+
document.body.appendChild(debugSvg);
|
|
60
|
+
}
|
|
61
|
+
debugSvg.innerHTML = "";
|
|
62
|
+
if (trough.length) {
|
|
51
63
|
const troughEl = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
52
|
-
troughEl.setAttribute("points", trough.map(p => p.join(",")).join(" "))
|
|
64
|
+
troughEl.setAttribute("points", trough.map(p => p.join(",")).join(" "));
|
|
65
|
+
troughEl.setAttribute("fill", "rgba(0,100,255,0.15)");
|
|
66
|
+
troughEl.setAttribute("stroke", "rgba(0,100,255,0.6)");
|
|
67
|
+
troughEl.setAttribute("stroke-width", "1");
|
|
68
|
+
debugSvg.appendChild(troughEl);
|
|
53
69
|
}
|
|
54
70
|
if (polygon.length) {
|
|
55
71
|
const polyEl = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
|
|
56
|
-
polyEl.setAttribute("points", polygon.map(p => p.join(",")).join(" "))
|
|
72
|
+
polyEl.setAttribute("points", polygon.map(p => p.join(",")).join(" "));
|
|
73
|
+
polyEl.setAttribute("fill", "rgba(255,50,50,0.2)");
|
|
74
|
+
polyEl.setAttribute("stroke", "rgba(255,50,50,0.8)");
|
|
75
|
+
polyEl.setAttribute("stroke-width", "1.5");
|
|
76
|
+
debugSvg.appendChild(polyEl);
|
|
57
77
|
}
|
|
58
78
|
const anchorCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
59
|
-
anchorCircle.setAttribute("cx", String(anchor[0]))
|
|
79
|
+
anchorCircle.setAttribute("cx", String(anchor[0]));
|
|
80
|
+
anchorCircle.setAttribute("cy", String(anchor[1]));
|
|
81
|
+
anchorCircle.setAttribute("r", "5");
|
|
82
|
+
anchorCircle.setAttribute("fill", "lime");
|
|
83
|
+
anchorCircle.setAttribute("stroke", "darkgreen");
|
|
84
|
+
anchorCircle.setAttribute("stroke-width", "1.5");
|
|
85
|
+
debugSvg.appendChild(anchorCircle);
|
|
60
86
|
const cursorCircle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
|
61
|
-
cursorCircle.setAttribute("cx", String(cursor[0]))
|
|
87
|
+
cursorCircle.setAttribute("cx", String(cursor[0]));
|
|
88
|
+
cursorCircle.setAttribute("cy", String(cursor[1]));
|
|
89
|
+
cursorCircle.setAttribute("r", "4");
|
|
90
|
+
cursorCircle.setAttribute("fill", "yellow");
|
|
91
|
+
cursorCircle.setAttribute("stroke", "orange");
|
|
92
|
+
cursorCircle.setAttribute("stroke-width", "1.5");
|
|
93
|
+
debugSvg.appendChild(cursorCircle);
|
|
62
94
|
}
|
|
63
95
|
function debugClear() {
|
|
64
|
-
|
|
96
|
+
if (debugSvg) {
|
|
97
|
+
debugSvg.remove();
|
|
98
|
+
debugSvg = null;
|
|
99
|
+
}
|
|
65
100
|
}
|
|
66
101
|
function safePolygon(options = {}) {
|
|
67
102
|
const {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let hasLanded =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
103
|
+
buffer = 0.5,
|
|
104
|
+
blockPointerEvents = false,
|
|
105
|
+
requireIntent = true,
|
|
106
|
+
__debug = false
|
|
107
|
+
} = options;
|
|
108
|
+
const timeoutRef = {
|
|
109
|
+
current: -1
|
|
110
|
+
};
|
|
111
|
+
let hasLanded = false;
|
|
112
|
+
let lastX = null;
|
|
113
|
+
let lastY = null;
|
|
114
|
+
let lastCursorTime = typeof performance !== "undefined" ? performance.now() : 0;
|
|
80
115
|
function getCursorSpeed(x, y) {
|
|
81
|
-
const currentTime = performance.now()
|
|
82
|
-
|
|
83
|
-
if (lastX === null || lastY === null || elapsedTime === 0)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
116
|
+
const currentTime = performance.now();
|
|
117
|
+
const elapsedTime = currentTime - lastCursorTime;
|
|
118
|
+
if (lastX === null || lastY === null || elapsedTime === 0) {
|
|
119
|
+
lastX = x;
|
|
120
|
+
lastY = y;
|
|
121
|
+
lastCursorTime = currentTime;
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const deltaX = x - lastX;
|
|
125
|
+
const deltaY = y - lastY;
|
|
126
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
127
|
+
const speed = distance / elapsedTime;
|
|
128
|
+
lastX = x;
|
|
129
|
+
lastY = y;
|
|
130
|
+
lastCursorTime = currentTime;
|
|
131
|
+
return speed;
|
|
88
132
|
}
|
|
89
133
|
const fn = ({
|
|
90
134
|
x,
|
|
@@ -92,100 +136,138 @@ function safePolygon(options = {}) {
|
|
|
92
136
|
placement,
|
|
93
137
|
elements,
|
|
94
138
|
onClose
|
|
95
|
-
}) =>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
139
|
+
}) => {
|
|
140
|
+
hasLanded = false;
|
|
141
|
+
lastX = null;
|
|
142
|
+
lastY = null;
|
|
143
|
+
return function onMouseMove(event) {
|
|
144
|
+
function close() {
|
|
145
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
146
|
+
onClose();
|
|
147
|
+
}
|
|
148
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
149
|
+
const domReference = elements.domReference ?? elements.reference;
|
|
150
|
+
if (!domReference || !elements.floating || placement == null || x == null || y == null) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const {
|
|
103
154
|
clientX,
|
|
104
155
|
clientY
|
|
105
|
-
} = event
|
|
106
|
-
clientPoint = [clientX, clientY]
|
|
107
|
-
target = (0, import_utils.getTarget)(event)
|
|
108
|
-
isLeave = event.type === "mouseleave"
|
|
109
|
-
isOverFloatingEl = (0, import_utils.contains)(elements.floating, target)
|
|
110
|
-
isOverReferenceEl = (0, import_utils.contains)(domReference, target)
|
|
111
|
-
refRect = domReference.getBoundingClientRect()
|
|
112
|
-
rect = elements.floating.getBoundingClientRect()
|
|
113
|
-
side = placement.split("-")[0]
|
|
114
|
-
cursorLeaveFromRight = x > rect.right - rect.width / 2
|
|
115
|
-
cursorLeaveFromBottom = y > rect.bottom - rect.height / 2
|
|
116
|
-
isOverReferenceRect = isInside(clientPoint, refRect)
|
|
117
|
-
isFloatingWider = rect.width > refRect.width
|
|
118
|
-
isFloatingTaller = rect.height > refRect.height
|
|
119
|
-
left = (isFloatingWider ? refRect : rect).left
|
|
120
|
-
right = (isFloatingWider ? refRect : rect).right
|
|
121
|
-
top = (isFloatingTaller ? refRect : rect).top
|
|
122
|
-
bottom = (isFloatingTaller ? refRect : rect).bottom;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
} = event;
|
|
157
|
+
const clientPoint = [clientX, clientY];
|
|
158
|
+
const target = (0, import_utils.getTarget)(event);
|
|
159
|
+
const isLeave = event.type === "mouseleave";
|
|
160
|
+
const isOverFloatingEl = (0, import_utils.contains)(elements.floating, target);
|
|
161
|
+
const isOverReferenceEl = (0, import_utils.contains)(domReference, target);
|
|
162
|
+
const refRect = domReference.getBoundingClientRect();
|
|
163
|
+
const rect = elements.floating.getBoundingClientRect();
|
|
164
|
+
const side = placement.split("-")[0];
|
|
165
|
+
const cursorLeaveFromRight = x > rect.right - rect.width / 2;
|
|
166
|
+
const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
|
|
167
|
+
const isOverReferenceRect = isInside(clientPoint, refRect);
|
|
168
|
+
const isFloatingWider = rect.width > refRect.width;
|
|
169
|
+
const isFloatingTaller = rect.height > refRect.height;
|
|
170
|
+
const left = (isFloatingWider ? refRect : rect).left;
|
|
171
|
+
const right = (isFloatingWider ? refRect : rect).right;
|
|
172
|
+
const top = (isFloatingTaller ? refRect : rect).top;
|
|
173
|
+
const bottom = (isFloatingTaller ? refRect : rect).bottom;
|
|
174
|
+
if (isOverFloatingEl) {
|
|
175
|
+
hasLanded = true;
|
|
176
|
+
if (!isLeave) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (isOverReferenceEl) {
|
|
181
|
+
hasLanded = false;
|
|
182
|
+
}
|
|
183
|
+
if (isOverReferenceEl && !isLeave) {
|
|
184
|
+
hasLanded = true;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!isOverReferenceEl && isOverReferenceRect && !isLeave) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (isLeave && event.relatedTarget && (0, import_utils.contains)(elements.floating, event.relatedTarget)) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (side === "top" && y >= refRect.bottom - 1 || side === "bottom" && y <= refRect.top + 1 || side === "left" && x >= refRect.right - 1 || side === "right" && x <= refRect.left + 1) {
|
|
194
|
+
return close();
|
|
195
|
+
}
|
|
196
|
+
let rectPoly = [];
|
|
146
197
|
switch (side) {
|
|
147
198
|
case "top":
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
cursorPointTwo = [isFloatingWider ? x2 - buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 + buffer + 1],
|
|
151
|
-
commonPoints = [[rect.left, cursorLeaveFromRight || isFloatingWider ? rect.bottom - buffer : rect.top], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer]];
|
|
152
|
-
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
153
|
-
}
|
|
199
|
+
rectPoly = [[left, refRect.top + 1], [left, rect.bottom - 1], [right, rect.bottom - 1], [right, refRect.top + 1]];
|
|
200
|
+
break;
|
|
154
201
|
case "bottom":
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
cursorPointTwo = [isFloatingWider ? x2 - buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 - buffer],
|
|
158
|
-
commonPoints = [[rect.left, cursorLeaveFromRight || isFloatingWider ? rect.top + buffer : rect.bottom], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer]];
|
|
159
|
-
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
160
|
-
}
|
|
202
|
+
rectPoly = [[left, rect.top + 1], [left, refRect.bottom - 1], [right, refRect.bottom - 1], [right, rect.top + 1]];
|
|
203
|
+
break;
|
|
161
204
|
case "left":
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
cursorPointTwo = [x2 + buffer + 1, isFloatingTaller ? y2 - buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4];
|
|
165
|
-
return [...[[cursorLeaveFromBottom || isFloatingTaller ? rect.right - buffer : rect.left, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer, rect.bottom]], cursorPointOne, cursorPointTwo];
|
|
166
|
-
}
|
|
205
|
+
rectPoly = [[rect.right - 1, bottom], [rect.right - 1, top], [refRect.left + 1, top], [refRect.left + 1, bottom]];
|
|
206
|
+
break;
|
|
167
207
|
case "right":
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
cursorPointTwo = [x2 - buffer, isFloatingTaller ? y2 - buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
|
|
171
|
-
commonPoints = [[cursorLeaveFromBottom || isFloatingTaller ? rect.left + buffer : rect.right, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer, rect.bottom]];
|
|
172
|
-
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
173
|
-
}
|
|
208
|
+
rectPoly = [[refRect.right - 1, bottom], [refRect.right - 1, top], [rect.left + 1, top], [rect.left + 1, bottom]];
|
|
209
|
+
break;
|
|
174
210
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
211
|
+
function getPolygon([x2, y2]) {
|
|
212
|
+
switch (side) {
|
|
213
|
+
case "top":
|
|
214
|
+
{
|
|
215
|
+
const cursorPointOne = [isFloatingWider ? x2 + buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 + buffer + 1];
|
|
216
|
+
const cursorPointTwo = [isFloatingWider ? x2 - buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 + buffer + 1];
|
|
217
|
+
const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.bottom - buffer : isFloatingWider ? rect.bottom - buffer : rect.top], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer]];
|
|
218
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
219
|
+
}
|
|
220
|
+
case "bottom":
|
|
221
|
+
{
|
|
222
|
+
const cursorPointOne = [isFloatingWider ? x2 + buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 - buffer];
|
|
223
|
+
const cursorPointTwo = [isFloatingWider ? x2 - buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 - buffer];
|
|
224
|
+
const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.top + buffer : isFloatingWider ? rect.top + buffer : rect.bottom], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer]];
|
|
225
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
226
|
+
}
|
|
227
|
+
case "left":
|
|
228
|
+
{
|
|
229
|
+
const cursorPointOne = [x2 + buffer + 1, isFloatingTaller ? y2 + buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4];
|
|
230
|
+
const cursorPointTwo = [x2 + buffer + 1, isFloatingTaller ? y2 - buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4];
|
|
231
|
+
const commonPoints = [[cursorLeaveFromBottom ? rect.right - buffer : isFloatingTaller ? rect.right - buffer : rect.left, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer, rect.bottom]];
|
|
232
|
+
return [...commonPoints, cursorPointOne, cursorPointTwo];
|
|
233
|
+
}
|
|
234
|
+
case "right":
|
|
235
|
+
{
|
|
236
|
+
const cursorPointOne = [x2 - buffer, isFloatingTaller ? y2 + buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4];
|
|
237
|
+
const cursorPointTwo = [x2 - buffer, isFloatingTaller ? y2 - buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4];
|
|
238
|
+
const commonPoints = [[cursorLeaveFromBottom ? rect.left + buffer : isFloatingTaller ? rect.left + buffer : rect.right, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer, rect.bottom]];
|
|
239
|
+
return [cursorPointOne, cursorPointTwo, ...commonPoints];
|
|
240
|
+
}
|
|
183
241
|
}
|
|
184
|
-
__debug && debugClear(), close();
|
|
185
242
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
243
|
+
const poly = getPolygon([x, y]);
|
|
244
|
+
if (__debug) {
|
|
245
|
+
debugDrawPolygon(poly, rectPoly, clientPoint, [x, y]);
|
|
246
|
+
}
|
|
247
|
+
if (isPointInPolygon([clientX, clientY], rectPoly)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (hasLanded && !isOverReferenceRect) {
|
|
251
|
+
if (__debug) debugClear();
|
|
252
|
+
return close();
|
|
253
|
+
}
|
|
254
|
+
if (isPointInPolygon([clientX, clientY], poly)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (!isLeave && requireIntent) {
|
|
258
|
+
const cursorSpeed = getCursorSpeed(clientX, clientY);
|
|
259
|
+
const cursorSpeedThreshold = 0.1;
|
|
260
|
+
if (cursorSpeed !== null && cursorSpeed < cursorSpeedThreshold) {
|
|
261
|
+
if (__debug) debugClear();
|
|
262
|
+
return close();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (__debug) debugClear();
|
|
266
|
+
close();
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
fn.__options = {
|
|
189
270
|
blockPointerEvents
|
|
190
|
-
}
|
|
271
|
+
};
|
|
272
|
+
return fn;
|
|
191
273
|
}
|