@octanejs/floating-ui 0.1.32 → 0.1.34

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.
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var delayGroup_exports = {};
20
+ __export(delayGroup_exports, {
21
+ FloatingDelayGroup: () => FloatingDelayGroup,
22
+ FloatingDelayGroupContext: () => FloatingDelayGroupContext,
23
+ useDelayGroup: () => useDelayGroup,
24
+ useDelayGroupContext: () => useDelayGroupContext
25
+ });
26
+ module.exports = __toCommonJS(delayGroup_exports);
27
+ var import_octane = require("octane");
28
+ var import_internal = require("./internal.cjs");
29
+ var import_utils = require("./utils/index.cjs");
30
+ const NOOP = () => {
31
+ };
32
+ const FloatingDelayGroupContext = (0, import_octane.createContext)({
33
+ delay: 0,
34
+ initialDelay: 0,
35
+ timeoutMs: 0,
36
+ currentId: null,
37
+ setCurrentId: NOOP,
38
+ setState: NOOP,
39
+ isInstantPhase: false
40
+ });
41
+ const useDelayGroupContext = () => (0, import_octane.useContext)(FloatingDelayGroupContext);
42
+ function FloatingDelayGroup(props) {
43
+ const children = props.children;
44
+ const delay = props.delay;
45
+ const timeoutMs = props.timeoutMs ?? 0;
46
+ const [state, setState] = (0, import_octane.useReducer)(
47
+ (prev, next) => ({ ...prev, ...next }),
48
+ {
49
+ delay,
50
+ timeoutMs,
51
+ initialDelay: delay,
52
+ currentId: null,
53
+ isInstantPhase: false
54
+ },
55
+ (0, import_internal.S)("FloatingDelayGroup:state")
56
+ );
57
+ const initialCurrentIdRef = (0, import_octane.useRef)(null, (0, import_internal.S)("FloatingDelayGroup:initialId"));
58
+ const setCurrentId = (0, import_octane.useCallback)(
59
+ (currentId) => {
60
+ setState({ currentId });
61
+ },
62
+ [],
63
+ (0, import_internal.S)("FloatingDelayGroup:setId")
64
+ );
65
+ (0, import_utils.useModernLayoutEffect)(
66
+ () => {
67
+ if (state.currentId) {
68
+ if (initialCurrentIdRef.current === null) {
69
+ initialCurrentIdRef.current = state.currentId;
70
+ } else if (!state.isInstantPhase) {
71
+ setState({ isInstantPhase: true });
72
+ }
73
+ } else {
74
+ if (state.isInstantPhase) {
75
+ setState({ isInstantPhase: false });
76
+ }
77
+ initialCurrentIdRef.current = null;
78
+ }
79
+ },
80
+ [state.currentId, state.isInstantPhase],
81
+ (0, import_internal.S)("FloatingDelayGroup:eff")
82
+ );
83
+ const value = (0, import_octane.useMemo)(
84
+ () => ({ ...state, setState, setCurrentId }),
85
+ [state, setCurrentId],
86
+ (0, import_internal.S)("FloatingDelayGroup:value")
87
+ );
88
+ return (0, import_octane.createElement)(FloatingDelayGroupContext.Provider, { value, children });
89
+ }
90
+ function useDelayGroup(...args) {
91
+ const [user, slot] = (0, import_internal.splitSlot)(args);
92
+ const context = user[0];
93
+ const options = user[1] ?? {};
94
+ const open = context.open;
95
+ const onOpenChange = context.onOpenChange;
96
+ const floatingId = context.floatingId;
97
+ const optionId = options.id;
98
+ const enabled = options.enabled ?? true;
99
+ const id = optionId != null ? optionId : floatingId;
100
+ const groupContext = useDelayGroupContext();
101
+ const { currentId, setCurrentId, initialDelay, setState, timeoutMs } = groupContext;
102
+ (0, import_utils.useModernLayoutEffect)(
103
+ () => {
104
+ if (!enabled) return;
105
+ if (!currentId) return;
106
+ setState({
107
+ delay: { open: 1, close: (0, import_utils.getDelay)(initialDelay, "close") }
108
+ });
109
+ if (currentId !== id) {
110
+ onOpenChange(false);
111
+ }
112
+ },
113
+ [enabled, id, onOpenChange, setState, currentId, initialDelay],
114
+ (0, import_internal.subSlot)(slot, "e:sync")
115
+ );
116
+ (0, import_utils.useModernLayoutEffect)(
117
+ () => {
118
+ function unset() {
119
+ onOpenChange(false);
120
+ setState({ delay: initialDelay, currentId: null });
121
+ }
122
+ if (!enabled) return;
123
+ if (!currentId) return;
124
+ if (!open && currentId === id) {
125
+ if (timeoutMs) {
126
+ const timeout = window.setTimeout(unset, timeoutMs);
127
+ return () => {
128
+ clearTimeout(timeout);
129
+ };
130
+ }
131
+ unset();
132
+ }
133
+ },
134
+ [enabled, open, setState, currentId, id, onOpenChange, initialDelay, timeoutMs],
135
+ (0, import_internal.subSlot)(slot, "e:unset")
136
+ );
137
+ (0, import_utils.useModernLayoutEffect)(
138
+ () => {
139
+ if (!enabled) return;
140
+ if (setCurrentId === NOOP || !open) return;
141
+ setCurrentId(id);
142
+ },
143
+ [enabled, open, setCurrentId, id],
144
+ (0, import_internal.subSlot)(slot, "e:set")
145
+ );
146
+ return groupContext;
147
+ }
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ FloatingDelayGroup,
151
+ FloatingDelayGroupContext,
152
+ useDelayGroup,
153
+ useDelayGroupContext
154
+ });
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ Composite: () => import_Composite.Composite,
22
+ CompositeContext: () => import_Composite.CompositeContext,
23
+ CompositeItem: () => import_Composite.CompositeItem,
24
+ FloatingArrow: () => import_FloatingArrow.FloatingArrow,
25
+ FloatingDelayGroup: () => import_delayGroup.FloatingDelayGroup,
26
+ FloatingDelayGroupContext: () => import_delayGroup.FloatingDelayGroupContext,
27
+ FloatingFocusManager: () => import_FloatingFocusManager.FloatingFocusManager,
28
+ FloatingList: () => import_FloatingList.FloatingList,
29
+ FloatingListContext: () => import_FloatingList.FloatingListContext,
30
+ FloatingNode: () => import_tree.FloatingNode,
31
+ FloatingNodeContext: () => import_tree.FloatingNodeContext,
32
+ FloatingOverlay: () => import_FloatingOverlay.FloatingOverlay,
33
+ FloatingPortal: () => import_FloatingPortal.FloatingPortal,
34
+ FloatingTree: () => import_tree.FloatingTree,
35
+ FloatingTreeContext: () => import_tree.FloatingTreeContext,
36
+ FocusGuard: () => import_FloatingPortal.FocusGuard,
37
+ PortalContext: () => import_FloatingPortal.PortalContext,
38
+ VisuallyHiddenDismiss: () => import_FloatingFocusManager.VisuallyHiddenDismiss,
39
+ arrow: () => import_useFloating.arrow,
40
+ autoPlacement: () => import_dom.autoPlacement,
41
+ autoUpdate: () => import_dom.autoUpdate,
42
+ computePosition: () => import_dom.computePosition,
43
+ createPubSub: () => import_context.createPubSub,
44
+ detectOverflow: () => import_dom.detectOverflow,
45
+ flip: () => import_dom.flip,
46
+ getOverflowAncestors: () => import_dom.getOverflowAncestors,
47
+ hide: () => import_dom.hide,
48
+ inline: () => import_dom.inline,
49
+ limitShift: () => import_dom.limitShift,
50
+ offset: () => import_dom.offset,
51
+ platform: () => import_dom.platform,
52
+ safePolygon: () => import_safePolygon.safePolygon,
53
+ shift: () => import_dom.shift,
54
+ size: () => import_dom.size,
55
+ useClick: () => import_useClick.useClick,
56
+ useClientPoint: () => import_useClientPoint.useClientPoint,
57
+ useDelayGroup: () => import_delayGroup.useDelayGroup,
58
+ useDelayGroupContext: () => import_delayGroup.useDelayGroupContext,
59
+ useDismiss: () => import_useDismiss.useDismiss,
60
+ useFloating: () => import_context.useFloating,
61
+ useFloatingNodeId: () => import_tree.useFloatingNodeId,
62
+ useFloatingParentNodeId: () => import_tree.useFloatingParentNodeId,
63
+ useFloatingPortalNode: () => import_FloatingPortal.useFloatingPortalNode,
64
+ useFloatingRootContext: () => import_context.useFloatingRootContext,
65
+ useFloatingTree: () => import_tree.useFloatingTree,
66
+ useFocus: () => import_useFocus.useFocus,
67
+ useHover: () => import_useHover.useHover,
68
+ useId: () => import_useId.useId,
69
+ useInteractions: () => import_useInteractions.useInteractions,
70
+ useListItem: () => import_FloatingList.useListItem,
71
+ useListNavigation: () => import_useListNavigation.useListNavigation,
72
+ useMergeRefs: () => import_useMergeRefs.useMergeRefs,
73
+ usePortalContext: () => import_FloatingPortal.usePortalContext,
74
+ usePositionFloating: () => import_useFloating2.usePositionFloating,
75
+ useRole: () => import_useRole.useRole,
76
+ useTransitionStatus: () => import_transitions.useTransitionStatus,
77
+ useTransitionStyles: () => import_transitions.useTransitionStyles,
78
+ useTypeahead: () => import_useTypeahead.useTypeahead
79
+ });
80
+ module.exports = __toCommonJS(index_exports);
81
+ var import_dom = require("@floating-ui/dom");
82
+ var import_context = require("./context.cjs");
83
+ var import_useFloating = require("./useFloating.cjs");
84
+ var import_useFloating2 = require("./useFloating.cjs");
85
+ var import_useMergeRefs = require("./useMergeRefs.cjs");
86
+ var import_useId = require("./useId.cjs");
87
+ var import_tree = require("./tree.cjs");
88
+ var import_useInteractions = require("./useInteractions.cjs");
89
+ var import_useRole = require("./useRole.cjs");
90
+ var import_useClick = require("./useClick.cjs");
91
+ var import_useFocus = require("./useFocus.cjs");
92
+ var import_useDismiss = require("./useDismiss.cjs");
93
+ var import_useClientPoint = require("./useClientPoint.cjs");
94
+ var import_useListNavigation = require("./useListNavigation.cjs");
95
+ var import_useTypeahead = require("./useTypeahead.cjs");
96
+ var import_useHover = require("./useHover.cjs");
97
+ var import_safePolygon = require("./safePolygon.cjs");
98
+ var import_FloatingOverlay = require("./FloatingOverlay.cjs");
99
+ var import_FloatingPortal = require("./FloatingPortal.cjs");
100
+ var import_FloatingList = require("./FloatingList.cjs");
101
+ var import_FloatingArrow = require("./FloatingArrow.cjs");
102
+ var import_Composite = require("./Composite.cjs");
103
+ var import_FloatingFocusManager = require("./FloatingFocusManager.cjs");
104
+ var import_transitions = require("./transitions.cjs");
105
+ var import_delayGroup = require("./delayGroup.cjs");
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ Composite,
109
+ CompositeContext,
110
+ CompositeItem,
111
+ FloatingArrow,
112
+ FloatingDelayGroup,
113
+ FloatingDelayGroupContext,
114
+ FloatingFocusManager,
115
+ FloatingList,
116
+ FloatingListContext,
117
+ FloatingNode,
118
+ FloatingNodeContext,
119
+ FloatingOverlay,
120
+ FloatingPortal,
121
+ FloatingTree,
122
+ FloatingTreeContext,
123
+ FocusGuard,
124
+ PortalContext,
125
+ VisuallyHiddenDismiss,
126
+ arrow,
127
+ autoPlacement,
128
+ autoUpdate,
129
+ computePosition,
130
+ createPubSub,
131
+ detectOverflow,
132
+ flip,
133
+ getOverflowAncestors,
134
+ hide,
135
+ inline,
136
+ limitShift,
137
+ offset,
138
+ platform,
139
+ safePolygon,
140
+ shift,
141
+ size,
142
+ useClick,
143
+ useClientPoint,
144
+ useDelayGroup,
145
+ useDelayGroupContext,
146
+ useDismiss,
147
+ useFloating,
148
+ useFloatingNodeId,
149
+ useFloatingParentNodeId,
150
+ useFloatingPortalNode,
151
+ useFloatingRootContext,
152
+ useFloatingTree,
153
+ useFocus,
154
+ useHover,
155
+ useId,
156
+ useInteractions,
157
+ useListItem,
158
+ useListNavigation,
159
+ useMergeRefs,
160
+ usePortalContext,
161
+ usePositionFloating,
162
+ useRole,
163
+ useTransitionStatus,
164
+ useTransitionStyles,
165
+ useTypeahead
166
+ });
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var internal_exports = {};
20
+ __export(internal_exports, {
21
+ S: () => S,
22
+ splitSlot: () => splitSlot,
23
+ subSlot: () => subSlot
24
+ });
25
+ module.exports = __toCommonJS(internal_exports);
26
+ const subSlotCache = /* @__PURE__ */ new Map();
27
+ function subSlot(slot, tag) {
28
+ if (slot === void 0) return void 0;
29
+ let byTag = subSlotCache.get(slot);
30
+ if (byTag === void 0) subSlotCache.set(slot, byTag = /* @__PURE__ */ new Map());
31
+ let sym = byTag.get(tag);
32
+ if (sym === void 0) byTag.set(tag, sym = /* @__PURE__ */ Symbol.for((slot.description ?? "") + ":" + tag));
33
+ return sym;
34
+ }
35
+ function splitSlot(args) {
36
+ const tail = args[args.length - 1];
37
+ const slot = typeof tail === "symbol" ? tail : void 0;
38
+ return [slot !== void 0 ? args.slice(0, -1) : args, slot];
39
+ }
40
+ const sCache = /* @__PURE__ */ new Map();
41
+ function S(tag) {
42
+ let sym = sCache.get(tag);
43
+ if (sym === void 0) sCache.set(tag, sym = /* @__PURE__ */ Symbol.for("@octanejs/floating-ui:" + tag));
44
+ return sym;
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ S,
49
+ splitSlot,
50
+ subSlot
51
+ });
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var pubsub_exports = {};
20
+ __export(pubsub_exports, {
21
+ createPubSub: () => createPubSub
22
+ });
23
+ module.exports = __toCommonJS(pubsub_exports);
24
+ function createPubSub() {
25
+ const map = /* @__PURE__ */ new Map();
26
+ return {
27
+ emit(event, data) {
28
+ map.get(event)?.forEach((listener) => listener(data));
29
+ },
30
+ on(event, listener) {
31
+ if (!map.has(event)) {
32
+ map.set(event, /* @__PURE__ */ new Set());
33
+ }
34
+ map.get(event).add(listener);
35
+ },
36
+ off(event, listener) {
37
+ map.get(event)?.delete(listener);
38
+ }
39
+ };
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ createPubSub
44
+ });
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var safePolygon_exports = {};
20
+ __export(safePolygon_exports, {
21
+ safePolygon: () => safePolygon
22
+ });
23
+ module.exports = __toCommonJS(safePolygon_exports);
24
+ var import_dom = require("@floating-ui/utils/dom");
25
+ var import_utils = require("./utils/index.cjs");
26
+ function isPointInPolygon(point, polygon) {
27
+ const [x, y] = point;
28
+ let isInsideResult = 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
+ isInsideResult = !isInsideResult;
36
+ }
37
+ }
38
+ return isInsideResult;
39
+ }
40
+ function isInside(point, rect) {
41
+ return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
42
+ }
43
+ function safePolygon(options = {}) {
44
+ const { buffer = 0.5, blockPointerEvents = false, requireIntent = true } = options;
45
+ const timeoutRef = { current: -1 };
46
+ let hasLanded = false;
47
+ let lastX = null;
48
+ let lastY = null;
49
+ let lastCursorTime = typeof performance !== "undefined" ? performance.now() : 0;
50
+ function getCursorSpeed(x, y) {
51
+ const currentTime = performance.now();
52
+ const elapsedTime = currentTime - lastCursorTime;
53
+ if (lastX === null || lastY === null || elapsedTime === 0) {
54
+ lastX = x;
55
+ lastY = y;
56
+ lastCursorTime = currentTime;
57
+ return null;
58
+ }
59
+ const deltaX = x - lastX;
60
+ const deltaY = y - lastY;
61
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
62
+ const speed = distance / elapsedTime;
63
+ lastX = x;
64
+ lastY = y;
65
+ lastCursorTime = currentTime;
66
+ return speed;
67
+ }
68
+ const fn = (_ref) => {
69
+ const { x, y, placement, elements, onClose, nodeId, tree } = _ref;
70
+ return function onMouseMove(event) {
71
+ function close() {
72
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
73
+ onClose();
74
+ }
75
+ (0, import_utils.clearTimeoutIfSet)(timeoutRef);
76
+ if (!elements.domReference || !elements.floating || placement == null || x == null || y == null) {
77
+ return;
78
+ }
79
+ const { clientX, clientY } = event;
80
+ const clientPoint = [clientX, clientY];
81
+ const target = (0, import_utils.getTarget)(event);
82
+ const isLeave = event.type === "mouseleave";
83
+ const isOverFloatingEl = (0, import_utils.contains)(elements.floating, target);
84
+ const isOverReferenceEl = (0, import_utils.contains)(elements.domReference, target);
85
+ const refRect = elements.domReference.getBoundingClientRect();
86
+ const rect = elements.floating.getBoundingClientRect();
87
+ const side = placement.split("-")[0];
88
+ const cursorLeaveFromRight = x > rect.right - rect.width / 2;
89
+ const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
90
+ const isOverReferenceRect = isInside(clientPoint, refRect);
91
+ const isFloatingWider = rect.width > refRect.width;
92
+ const isFloatingTaller = rect.height > refRect.height;
93
+ const left = (isFloatingWider ? refRect : rect).left;
94
+ const right = (isFloatingWider ? refRect : rect).right;
95
+ const top = (isFloatingTaller ? refRect : rect).top;
96
+ const bottom = (isFloatingTaller ? refRect : rect).bottom;
97
+ if (isOverFloatingEl) {
98
+ hasLanded = true;
99
+ if (!isLeave) {
100
+ return;
101
+ }
102
+ }
103
+ if (isOverReferenceEl) {
104
+ hasLanded = false;
105
+ }
106
+ if (isOverReferenceEl && !isLeave) {
107
+ hasLanded = true;
108
+ return;
109
+ }
110
+ if (isLeave && (0, import_dom.isElement)(event.relatedTarget) && (0, import_utils.contains)(elements.floating, event.relatedTarget)) {
111
+ return;
112
+ }
113
+ if (tree && (0, import_utils.getNodeChildren)(tree.nodesRef.current, nodeId).length) {
114
+ return;
115
+ }
116
+ 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) {
117
+ return close();
118
+ }
119
+ let rectPoly = [];
120
+ switch (side) {
121
+ case "top":
122
+ rectPoly = [
123
+ [left, refRect.top + 1],
124
+ [left, rect.bottom - 1],
125
+ [right, rect.bottom - 1],
126
+ [right, refRect.top + 1]
127
+ ];
128
+ break;
129
+ case "bottom":
130
+ rectPoly = [
131
+ [left, rect.top + 1],
132
+ [left, refRect.bottom - 1],
133
+ [right, refRect.bottom - 1],
134
+ [right, rect.top + 1]
135
+ ];
136
+ break;
137
+ case "left":
138
+ rectPoly = [
139
+ [rect.right - 1, bottom],
140
+ [rect.right - 1, top],
141
+ [refRect.left + 1, top],
142
+ [refRect.left + 1, bottom]
143
+ ];
144
+ break;
145
+ case "right":
146
+ rectPoly = [
147
+ [refRect.right - 1, bottom],
148
+ [refRect.right - 1, top],
149
+ [rect.left + 1, top],
150
+ [rect.left + 1, bottom]
151
+ ];
152
+ break;
153
+ }
154
+ function getPolygon([px, py]) {
155
+ switch (side) {
156
+ case "top": {
157
+ const cursorPointOne = [
158
+ isFloatingWider ? px + buffer / 2 : cursorLeaveFromRight ? px + buffer * 4 : px - buffer * 4,
159
+ py + buffer + 1
160
+ ];
161
+ const cursorPointTwo = [
162
+ isFloatingWider ? px - buffer / 2 : cursorLeaveFromRight ? px + buffer * 4 : px - buffer * 4,
163
+ py + buffer + 1
164
+ ];
165
+ const commonPoints = [
166
+ [
167
+ rect.left,
168
+ cursorLeaveFromRight ? rect.bottom - buffer : isFloatingWider ? rect.bottom - buffer : rect.top
169
+ ],
170
+ [
171
+ rect.right,
172
+ cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer
173
+ ]
174
+ ];
175
+ return [cursorPointOne, cursorPointTwo, ...commonPoints];
176
+ }
177
+ case "bottom": {
178
+ const cursorPointOne = [
179
+ isFloatingWider ? px + buffer / 2 : cursorLeaveFromRight ? px + buffer * 4 : px - buffer * 4,
180
+ py - buffer
181
+ ];
182
+ const cursorPointTwo = [
183
+ isFloatingWider ? px - buffer / 2 : cursorLeaveFromRight ? px + buffer * 4 : px - buffer * 4,
184
+ py - buffer
185
+ ];
186
+ const commonPoints = [
187
+ [
188
+ rect.left,
189
+ cursorLeaveFromRight ? rect.top + buffer : isFloatingWider ? rect.top + buffer : rect.bottom
190
+ ],
191
+ [
192
+ rect.right,
193
+ cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer
194
+ ]
195
+ ];
196
+ return [cursorPointOne, cursorPointTwo, ...commonPoints];
197
+ }
198
+ case "left": {
199
+ const cursorPointOne = [
200
+ px + buffer + 1,
201
+ isFloatingTaller ? py + buffer / 2 : cursorLeaveFromBottom ? py + buffer * 4 : py - buffer * 4
202
+ ];
203
+ const cursorPointTwo = [
204
+ px + buffer + 1,
205
+ isFloatingTaller ? py - buffer / 2 : cursorLeaveFromBottom ? py + buffer * 4 : py - buffer * 4
206
+ ];
207
+ const commonPoints = [
208
+ [
209
+ cursorLeaveFromBottom ? rect.right - buffer : isFloatingTaller ? rect.right - buffer : rect.left,
210
+ rect.top
211
+ ],
212
+ [
213
+ cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer,
214
+ rect.bottom
215
+ ]
216
+ ];
217
+ return [...commonPoints, cursorPointOne, cursorPointTwo];
218
+ }
219
+ case "right": {
220
+ const cursorPointOne = [
221
+ px - buffer,
222
+ isFloatingTaller ? py + buffer / 2 : cursorLeaveFromBottom ? py + buffer * 4 : py - buffer * 4
223
+ ];
224
+ const cursorPointTwo = [
225
+ px - buffer,
226
+ isFloatingTaller ? py - buffer / 2 : cursorLeaveFromBottom ? py + buffer * 4 : py - buffer * 4
227
+ ];
228
+ const commonPoints = [
229
+ [
230
+ cursorLeaveFromBottom ? rect.left + buffer : isFloatingTaller ? rect.left + buffer : rect.right,
231
+ rect.top
232
+ ],
233
+ [
234
+ cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer,
235
+ rect.bottom
236
+ ]
237
+ ];
238
+ return [cursorPointOne, cursorPointTwo, ...commonPoints];
239
+ }
240
+ }
241
+ return [];
242
+ }
243
+ if (isPointInPolygon([clientX, clientY], rectPoly)) {
244
+ return;
245
+ }
246
+ if (hasLanded && !isOverReferenceRect) {
247
+ return close();
248
+ }
249
+ if (!isLeave && requireIntent) {
250
+ const cursorSpeed = getCursorSpeed(event.clientX, event.clientY);
251
+ const cursorSpeedThreshold = 0.1;
252
+ if (cursorSpeed !== null && cursorSpeed < cursorSpeedThreshold) {
253
+ return close();
254
+ }
255
+ }
256
+ if (!isPointInPolygon([clientX, clientY], getPolygon([x, y]))) {
257
+ close();
258
+ } else if (!hasLanded && requireIntent) {
259
+ timeoutRef.current = window.setTimeout(close, 40);
260
+ }
261
+ };
262
+ };
263
+ fn.__options = { blockPointerEvents };
264
+ return fn;
265
+ }
266
+ // Annotate the CommonJS export names for ESM import in node:
267
+ 0 && (module.exports = {
268
+ safePolygon
269
+ });