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