@hanzogui/floating 3.0.6 → 4.4.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.
Files changed (119) hide show
  1. package/dist/cjs/Floating.cjs +7 -5
  2. package/dist/cjs/Floating.native.js +18 -16
  3. package/dist/cjs/Floating.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +28 -26
  5. package/dist/cjs/index.native.js +28 -26
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/interactions/PopupTriggerMap.cjs +21 -12
  8. package/dist/cjs/interactions/PopupTriggerMap.native.js +51 -27
  9. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -1
  10. package/dist/cjs/interactions/createFloatingEvents.cjs +21 -12
  11. package/dist/cjs/interactions/createFloatingEvents.native.js +22 -13
  12. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -1
  13. package/dist/cjs/interactions/safePolygon.cjs +213 -131
  14. package/dist/cjs/interactions/safePolygon.native.js +182 -103
  15. package/dist/cjs/interactions/safePolygon.native.js.map +1 -1
  16. package/dist/cjs/interactions/types.cjs +7 -5
  17. package/dist/cjs/interactions/types.native.js +7 -5
  18. package/dist/cjs/interactions/types.native.js.map +1 -1
  19. package/dist/cjs/interactions/useClick.cjs +91 -49
  20. package/dist/cjs/interactions/useClick.native.js +96 -54
  21. package/dist/cjs/interactions/useClick.native.js.map +1 -1
  22. package/dist/cjs/interactions/useDelayGroup.cjs +63 -44
  23. package/dist/cjs/interactions/useDelayGroup.native.js +74 -58
  24. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -1
  25. package/dist/cjs/interactions/useFocus.cjs +73 -44
  26. package/dist/cjs/interactions/useFocus.native.js +75 -49
  27. package/dist/cjs/interactions/useFocus.native.js.map +1 -1
  28. package/dist/cjs/interactions/useHover.cjs +242 -109
  29. package/dist/cjs/interactions/useHover.native.js +268 -143
  30. package/dist/cjs/interactions/useHover.native.js.map +1 -1
  31. package/dist/cjs/interactions/useInnerOffset.cjs +88 -64
  32. package/dist/cjs/interactions/useInnerOffset.native.js +88 -65
  33. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -1
  34. package/dist/cjs/interactions/useInteractions.cjs +60 -31
  35. package/dist/cjs/interactions/useInteractions.native.js +133 -81
  36. package/dist/cjs/interactions/useInteractions.native.js.map +1 -1
  37. package/dist/cjs/interactions/useListNavigation.cjs +346 -181
  38. package/dist/cjs/interactions/useListNavigation.native.js +350 -214
  39. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -1
  40. package/dist/cjs/interactions/useRole.cjs +83 -73
  41. package/dist/cjs/interactions/useRole.native.js +107 -99
  42. package/dist/cjs/interactions/useRole.native.js.map +1 -1
  43. package/dist/cjs/interactions/useTypeahead.cjs +115 -65
  44. package/dist/cjs/interactions/useTypeahead.native.js +122 -77
  45. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -1
  46. package/dist/cjs/interactions/utils.cjs +68 -38
  47. package/dist/cjs/interactions/utils.native.js +93 -54
  48. package/dist/cjs/interactions/utils.native.js.map +1 -1
  49. package/dist/cjs/middleware/inner.cjs +79 -67
  50. package/dist/cjs/middleware/inner.native.js +86 -76
  51. package/dist/cjs/middleware/inner.native.js.map +1 -1
  52. package/dist/cjs/useFloating.cjs +48 -45
  53. package/dist/cjs/useFloating.native.js +50 -48
  54. package/dist/cjs/useFloating.native.js.map +1 -1
  55. package/dist/esm/Floating.native.js +5 -5
  56. package/dist/esm/Floating.native.js.map +1 -1
  57. package/dist/esm/interactions/PopupTriggerMap.mjs +9 -2
  58. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -1
  59. package/dist/esm/interactions/PopupTriggerMap.native.js +39 -17
  60. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -1
  61. package/dist/esm/interactions/createFloatingEvents.mjs +9 -2
  62. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -1
  63. package/dist/esm/interactions/createFloatingEvents.native.js +10 -3
  64. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -1
  65. package/dist/esm/interactions/safePolygon.mjs +201 -121
  66. package/dist/esm/interactions/safePolygon.mjs.map +1 -1
  67. package/dist/esm/interactions/safePolygon.native.js +170 -93
  68. package/dist/esm/interactions/safePolygon.native.js.map +1 -1
  69. package/dist/esm/interactions/useClick.mjs +79 -39
  70. package/dist/esm/interactions/useClick.mjs.map +1 -1
  71. package/dist/esm/interactions/useClick.native.js +82 -42
  72. package/dist/esm/interactions/useClick.native.js.map +1 -1
  73. package/dist/esm/interactions/useDelayGroup.mjs +39 -22
  74. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -1
  75. package/dist/esm/interactions/useDelayGroup.native.js +42 -28
  76. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -1
  77. package/dist/esm/interactions/useFocus.mjs +59 -32
  78. package/dist/esm/interactions/useFocus.mjs.map +1 -1
  79. package/dist/esm/interactions/useFocus.native.js +61 -37
  80. package/dist/esm/interactions/useFocus.native.js.map +1 -1
  81. package/dist/esm/interactions/useHover.mjs +215 -84
  82. package/dist/esm/interactions/useHover.mjs.map +1 -1
  83. package/dist/esm/interactions/useHover.native.js +240 -117
  84. package/dist/esm/interactions/useHover.native.js.map +1 -1
  85. package/dist/esm/interactions/useInnerOffset.mjs +61 -39
  86. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -1
  87. package/dist/esm/interactions/useInnerOffset.native.js +61 -40
  88. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -1
  89. package/dist/esm/interactions/useInteractions.mjs +48 -21
  90. package/dist/esm/interactions/useInteractions.mjs.map +1 -1
  91. package/dist/esm/interactions/useInteractions.native.js +121 -71
  92. package/dist/esm/interactions/useInteractions.native.js.map +1 -1
  93. package/dist/esm/interactions/useListNavigation.mjs +331 -168
  94. package/dist/esm/interactions/useListNavigation.mjs.map +1 -1
  95. package/dist/esm/interactions/useListNavigation.native.js +335 -201
  96. package/dist/esm/interactions/useListNavigation.native.js.map +1 -1
  97. package/dist/esm/interactions/useRole.mjs +59 -51
  98. package/dist/esm/interactions/useRole.mjs.map +1 -1
  99. package/dist/esm/interactions/useRole.native.js +82 -76
  100. package/dist/esm/interactions/useRole.native.js.map +1 -1
  101. package/dist/esm/interactions/useTypeahead.mjs +100 -52
  102. package/dist/esm/interactions/useTypeahead.mjs.map +1 -1
  103. package/dist/esm/interactions/useTypeahead.native.js +107 -64
  104. package/dist/esm/interactions/useTypeahead.native.js.map +1 -1
  105. package/dist/esm/interactions/utils.mjs +56 -28
  106. package/dist/esm/interactions/utils.mjs.map +1 -1
  107. package/dist/esm/interactions/utils.native.js +81 -44
  108. package/dist/esm/interactions/utils.native.js.map +1 -1
  109. package/dist/esm/middleware/inner.mjs +54 -44
  110. package/dist/esm/middleware/inner.mjs.map +1 -1
  111. package/dist/esm/middleware/inner.native.js +61 -53
  112. package/dist/esm/middleware/inner.native.js.map +1 -1
  113. package/dist/esm/useFloating.mjs +22 -21
  114. package/dist/esm/useFloating.mjs.map +1 -1
  115. package/dist/esm/useFloating.native.js +24 -24
  116. package/dist/esm/useFloating.native.js.map +1 -1
  117. package/package.json +3 -3
  118. package/src/middleware/inner.ts +4 -5
  119. package/types/middleware/inner.d.ts.map +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
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
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 = !1;
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
- [xj, yj] = polygon[j] || [0, 0];
34
- yi >= y != yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi && (isInside2 = !isInside2);
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 || (debugSvg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), debugSvg.id = "__safe-polygon-debug", Object.assign(debugSvg.style, {
44
- position: "fixed",
45
- inset: "0",
46
- width: "100vw",
47
- height: "100vh",
48
- pointerEvents: "none",
49
- zIndex: "999999"
50
- }), document.body.appendChild(debugSvg)), debugSvg.innerHTML = "", trough.length) {
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(" ")), troughEl.setAttribute("fill", "rgba(0,100,255,0.15)"), troughEl.setAttribute("stroke", "rgba(0,100,255,0.6)"), troughEl.setAttribute("stroke-width", "1"), debugSvg.appendChild(troughEl);
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(" ")), polyEl.setAttribute("fill", "rgba(255,50,50,0.2)"), polyEl.setAttribute("stroke", "rgba(255,50,50,0.8)"), polyEl.setAttribute("stroke-width", "1.5"), debugSvg.appendChild(polyEl);
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])), anchorCircle.setAttribute("cy", String(anchor[1])), anchorCircle.setAttribute("r", "5"), anchorCircle.setAttribute("fill", "lime"), anchorCircle.setAttribute("stroke", "darkgreen"), anchorCircle.setAttribute("stroke-width", "1.5"), debugSvg.appendChild(anchorCircle);
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])), cursorCircle.setAttribute("cy", String(cursor[1])), cursorCircle.setAttribute("r", "4"), cursorCircle.setAttribute("fill", "yellow"), cursorCircle.setAttribute("stroke", "orange"), cursorCircle.setAttribute("stroke-width", "1.5"), debugSvg.appendChild(cursorCircle);
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
- debugSvg && (debugSvg.remove(), debugSvg = null);
96
+ if (debugSvg) {
97
+ debugSvg.remove();
98
+ debugSvg = null;
99
+ }
65
100
  }
66
101
  function safePolygon(options = {}) {
67
102
  const {
68
- buffer = 0.5,
69
- blockPointerEvents = !1,
70
- requireIntent = !0,
71
- __debug = !1
72
- } = options,
73
- timeoutRef = {
74
- current: -1
75
- };
76
- let hasLanded = !1,
77
- lastX = null,
78
- lastY = null,
79
- lastCursorTime = typeof performance < "u" ? performance.now() : 0;
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
- elapsedTime = currentTime - lastCursorTime;
83
- if (lastX === null || lastY === null || elapsedTime === 0) return lastX = x, lastY = y, lastCursorTime = currentTime, null;
84
- const deltaX = x - lastX,
85
- deltaY = y - lastY,
86
- speed = Math.sqrt(deltaX * deltaX + deltaY * deltaY) / elapsedTime;
87
- return lastX = x, lastY = y, lastCursorTime = currentTime, speed;
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
- }) => (hasLanded = !1, lastX = null, lastY = null, function (event) {
96
- function close() {
97
- (0, import_utils.clearTimeoutIfSet)(timeoutRef), onClose();
98
- }
99
- (0, import_utils.clearTimeoutIfSet)(timeoutRef);
100
- const domReference = elements.domReference ?? elements.reference;
101
- if (!domReference || !elements.floating || placement == null || x == null || y == null) return;
102
- const {
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
- if (isOverFloatingEl && (hasLanded = !0, !isLeave)) return;
124
- if (isOverReferenceEl && (hasLanded = !1), isOverReferenceEl && !isLeave) {
125
- hasLanded = !0;
126
- return;
127
- }
128
- if (!isOverReferenceEl && isOverReferenceRect && !isLeave || isLeave && event.relatedTarget && (0, import_utils.contains)(elements.floating, event.relatedTarget)) return;
129
- 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) return close();
130
- let rectPoly = [];
131
- switch (side) {
132
- case "top":
133
- rectPoly = [[left, refRect.top + 1], [left, rect.bottom - 1], [right, rect.bottom - 1], [right, refRect.top + 1]];
134
- break;
135
- case "bottom":
136
- rectPoly = [[left, rect.top + 1], [left, refRect.bottom - 1], [right, refRect.bottom - 1], [right, rect.top + 1]];
137
- break;
138
- case "left":
139
- rectPoly = [[rect.right - 1, bottom], [rect.right - 1, top], [refRect.left + 1, top], [refRect.left + 1, bottom]];
140
- break;
141
- case "right":
142
- rectPoly = [[refRect.right - 1, bottom], [refRect.right - 1, top], [rect.left + 1, top], [rect.left + 1, bottom]];
143
- break;
144
- }
145
- function getPolygon([x2, y2]) {
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
- const cursorPointOne = [isFloatingWider ? x2 + buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 + buffer + 1],
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
- const cursorPointOne = [isFloatingWider ? x2 + buffer / 2 : cursorLeaveFromRight ? x2 + buffer * 4 : x2 - buffer * 4, y2 - buffer],
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
- const cursorPointOne = [x2 + buffer + 1, isFloatingTaller ? y2 + buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
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
- const cursorPointOne = [x2 - buffer, isFloatingTaller ? y2 + buffer / 2 : cursorLeaveFromBottom ? y2 + buffer * 4 : y2 - buffer * 4],
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
- const poly = getPolygon([x, y]);
177
- if (__debug && debugDrawPolygon(poly, rectPoly, clientPoint, [x, y]), !isPointInPolygon([clientX, clientY], rectPoly)) {
178
- if (hasLanded && !isOverReferenceRect) return __debug && debugClear(), close();
179
- if (!isPointInPolygon([clientX, clientY], poly)) {
180
- if (!isLeave && requireIntent) {
181
- const cursorSpeed = getCursorSpeed(clientX, clientY);
182
- if (cursorSpeed !== null && cursorSpeed < 0.1) return __debug && debugClear(), close();
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
- return fn.__options = {
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
- }, fn;
271
+ };
272
+ return fn;
191
273
  }