@hanzogui/popper 3.0.2 → 7.3.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.
@@ -4,140 +4,138 @@ import { useComposedRefs } from "@hanzogui/compose-refs";
4
4
  import { isWeb, useIsomorphicLayoutEffect } from "@hanzogui/constants";
5
5
  import { LayoutMeasurementController, View as GuiView, createStyledContext, getVariableValue, registerLayoutNode, styled } from "@hanzogui/core";
6
6
  import { FloatingOverrideContext } from "@hanzogui/floating";
7
- import { arrow, flip, getOverflowAncestors, offset as offsetFn, platform, shift, useFloating } from "@hanzogui/floating";
7
+ import { arrow, flip, getOverflowAncestors, offset as offsetFn, platform, shift, size as sizeMiddleware, useFloating } from "@hanzogui/floating";
8
8
  import { getSpace } from "@hanzogui/get-token";
9
9
  import { YStack } from "@hanzogui/stacks";
10
10
  import { startTransition } from "@hanzogui/start-transition";
11
11
  import * as React from "react";
12
12
  import { Keyboard, useWindowDimensions } from "react-native";
13
13
  function _instanceof(left, right) {
14
- return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
14
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);else return left instanceof right;
15
15
  }
16
16
  function _type_of(obj) {
17
17
  "@swc/helpers - typeof";
18
18
 
19
- return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
19
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
20
20
  }
21
21
  var PopperContextFast = createStyledContext(
22
- // since we always provide this we can avoid setting here
23
- {}, "Popper__"),
24
- PopperPositionContext = createStyledContext,
25
- {
26
- useStyledContext: usePopperContext,
27
- Provider: PopperProviderFast
28
- } = PopperContextFast,
29
- PopperContextSlow = createStyledContext(
30
- // since we always provide this we can avoid setting here
31
- {}, "PopperSlow__"),
32
- {
33
- useStyledContext: usePopperContextSlow,
34
- Provider: PopperProviderSlow
35
- } = PopperContextSlow,
36
- PopperProvider = function (param) {
37
- var {
38
- scope,
39
- children,
40
- ...context
41
- } = param,
42
- fns = React.useRef(context);
43
- fns.current = context;
44
- var [slowContext] = React.useState(function () {
45
- return {
46
- refs: context.refs,
47
- triggerElements: context.triggerElements,
48
- update() {
49
- for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) a[_key] = arguments[_key];
50
- fns.current.update(...a);
51
- },
52
- getReferenceProps(p) {
53
- var _fns_current_getReferenceProps, _fns_current;
54
- return (_fns_current_getReferenceProps = (_fns_current = fns.current).getReferenceProps) === null || _fns_current_getReferenceProps === void 0 ? void 0 : _fns_current_getReferenceProps.call(_fns_current, p);
55
- },
56
- onHoverReference(e) {
57
- var _fns_current_onHoverReference, _fns_current;
58
- (_fns_current_onHoverReference = (_fns_current = fns.current).onHoverReference) === null || _fns_current_onHoverReference === void 0 || _fns_current_onHoverReference.call(_fns_current, e);
59
- },
60
- onLeaveReference() {
61
- var _fns_current_onLeaveReference, _fns_current;
62
- (_fns_current_onLeaveReference = (_fns_current = fns.current).onLeaveReference) === null || _fns_current_onLeaveReference === void 0 || _fns_current_onLeaveReference.call(_fns_current);
63
- }
64
- };
65
- });
66
- return /* @__PURE__ */_jsx(PopperProviderFast, {
22
+ // since we always provide this we can avoid setting here
23
+ {}, "Popper__");
24
+ var PopperPositionContext = createStyledContext;
25
+ var {
26
+ useStyledContext: usePopperContext,
27
+ Provider: PopperProviderFast
28
+ } = PopperContextFast;
29
+ var PopperContextSlow = createStyledContext(
30
+ // since we always provide this we can avoid setting here
31
+ {}, "PopperSlow__");
32
+ var {
33
+ useStyledContext: usePopperContextSlow,
34
+ Provider: PopperProviderSlow
35
+ } = PopperContextSlow;
36
+ var PopperProvider = function (param) {
37
+ var {
38
+ scope,
39
+ children,
40
+ ...context
41
+ } = param;
42
+ var fns = React.useRef(context);
43
+ fns.current = context;
44
+ var [slowContext] = React.useState(function () {
45
+ return {
46
+ refs: context.refs,
47
+ triggerElements: context.triggerElements,
48
+ update() {
49
+ for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) a[_key] = arguments[_key];
50
+ fns.current.update(...a);
51
+ },
52
+ getReferenceProps(p) {
53
+ var _fns_current_getReferenceProps, _fns_current;
54
+ return (_fns_current_getReferenceProps = (_fns_current = fns.current).getReferenceProps) === null || _fns_current_getReferenceProps === void 0 ? void 0 : _fns_current_getReferenceProps.call(_fns_current, p);
55
+ },
56
+ onHoverReference(e) {
57
+ var _fns_current_onHoverReference, _fns_current;
58
+ (_fns_current_onHoverReference = (_fns_current = fns.current).onHoverReference) === null || _fns_current_onHoverReference === void 0 || _fns_current_onHoverReference.call(_fns_current, e);
59
+ },
60
+ onLeaveReference() {
61
+ var _fns_current_onLeaveReference, _fns_current;
62
+ (_fns_current_onLeaveReference = (_fns_current = fns.current).onLeaveReference) === null || _fns_current_onLeaveReference === void 0 || _fns_current_onLeaveReference.call(_fns_current);
63
+ }
64
+ };
65
+ });
66
+ return /* @__PURE__ */_jsx(PopperProviderFast, {
67
+ scope,
68
+ ...context,
69
+ children: /* @__PURE__ */_jsx(PopperProviderSlow, {
67
70
  scope,
68
- ...context,
69
- children: /* @__PURE__ */_jsx(PopperProviderSlow, {
70
- scope,
71
- ...slowContext,
72
- children
73
- })
74
- });
75
- },
76
- checkFloating = {
77
- name: "checkFloating",
78
- fn(data) {
79
- return {
80
- data: {
81
- hasFloating: !!data.rects.floating.width
82
- }
83
- };
84
- }
85
- },
86
- setupOptions = {};
71
+ ...slowContext,
72
+ children
73
+ })
74
+ });
75
+ };
76
+ var checkFloating = {
77
+ name: "checkFloating",
78
+ fn(data) {
79
+ return {
80
+ data: {
81
+ hasFloating: !!data.rects.floating.width
82
+ }
83
+ };
84
+ }
85
+ };
86
+ var setupOptions = {};
87
87
  function setupPopper(options) {
88
88
  Object.assign(setupOptions, options);
89
89
  }
90
- function tamaguiAutoUpdate(reference, floating, update) {
90
+ function guiAutoUpdate(reference, floating, update) {
91
91
  update();
92
92
  var rafId = requestAnimationFrame(function () {
93
- update(), rafId = 0;
94
- }),
95
- cleanups = [function () {
96
- rafId && cancelAnimationFrame(rafId);
97
- }];
98
- _instanceof(reference, HTMLElement) && cleanups.push(registerLayoutNode(reference, update));
99
- var refAncestors = _instanceof(reference, Element) ? getOverflowAncestors(reference) : [],
100
- ancestors = [...refAncestors, ...getOverflowAncestors(floating)],
101
- uniqueAncestors = [...new Set(ancestors)],
102
- _iteratorNormalCompletion = !0,
103
- _didIteratorError = !1,
93
+ update();
94
+ rafId = 0;
95
+ });
96
+ var cleanups = [function () {
97
+ if (rafId) cancelAnimationFrame(rafId);
98
+ }];
99
+ if (_instanceof(reference, HTMLElement)) cleanups.push(registerLayoutNode(reference, update));
100
+ var ancestors = [...(_instanceof(reference, Element) ? getOverflowAncestors(reference) : []), ...getOverflowAncestors(floating)];
101
+ var uniqueAncestors = [...new Set(ancestors)];
102
+ var _iteratorNormalCompletion = true,
103
+ _didIteratorError = false,
104
104
  _iteratorError = void 0;
105
105
  try {
106
- for (var _iterator = uniqueAncestors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
107
- var ancestor = _step.value;
108
- ancestor.addEventListener("scroll", update, {
109
- passive: !0
110
- });
111
- }
106
+ for (var _iterator = uniqueAncestors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _step.value.addEventListener("scroll", update, {
107
+ passive: true
108
+ });
112
109
  } catch (err) {
113
- _didIteratorError = !0, _iteratorError = err;
110
+ _didIteratorError = true;
111
+ _iteratorError = err;
114
112
  } finally {
115
113
  try {
116
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
114
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
117
115
  } finally {
118
116
  if (_didIteratorError) throw _iteratorError;
119
117
  }
120
118
  }
121
- return window.addEventListener("resize", update), cleanups.push(function () {
122
- var _iteratorNormalCompletion2 = !0,
123
- _didIteratorError2 = !1,
119
+ window.addEventListener("resize", update);
120
+ cleanups.push(function () {
121
+ var _iteratorNormalCompletion2 = true,
122
+ _didIteratorError2 = false,
124
123
  _iteratorError2 = void 0;
125
124
  try {
126
- for (var _iterator2 = uniqueAncestors[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = !0) {
127
- var ancestor2 = _step2.value;
128
- ancestor2.removeEventListener("scroll", update);
129
- }
125
+ for (var _iterator2 = uniqueAncestors[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) _step2.value.removeEventListener("scroll", update);
130
126
  } catch (err) {
131
- _didIteratorError2 = !0, _iteratorError2 = err;
127
+ _didIteratorError2 = true;
128
+ _iteratorError2 = err;
132
129
  } finally {
133
130
  try {
134
- !_iteratorNormalCompletion2 && _iterator2.return != null && _iterator2.return();
131
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) _iterator2.return();
135
132
  } finally {
136
133
  if (_didIteratorError2) throw _iteratorError2;
137
134
  }
138
135
  }
139
136
  window.removeEventListener("resize", update);
140
- }), function () {
137
+ });
138
+ return function () {
141
139
  return cleanups.forEach(function (fn) {
142
140
  return fn();
143
141
  });
@@ -145,437 +143,433 @@ function tamaguiAutoUpdate(reference, floating, update) {
145
143
  }
146
144
  function Popper(props) {
147
145
  var {
148
- children,
149
- size,
150
- strategy = "absolute",
151
- placement = "bottom",
152
- stayInFrame,
153
- allowFlip,
154
- offset,
155
- disableRTL,
156
- resize,
157
- passThrough,
158
- open,
159
- scope
160
- } = props,
161
- [arrowEl, setArrow] = React.useState(null),
162
- [arrowSize, setArrowSize] = React.useState(0),
163
- offsetOptions = offset ?? arrowSize,
164
- floatingStyle = React.useRef({}),
165
- isOpen = passThrough ? !1 : open ?? !0,
166
- middlewareRef = React.useRef([]);
167
- isOpen && (middlewareRef.current = [
168
- // order matters: offset first, then flip, then shift, then arrow
169
- typeof offsetOptions < "u" ? offsetFn(offsetOptions) : null, allowFlip ? flip(typeof allowFlip == "boolean" ? {} : allowFlip) : null,
170
- // NOTE: shift's axis terminology is reversed vs flip/offset:
171
- // for top/bottom placements: mainAxis = horizontal, crossAxis = vertical
172
- // for left/right placements: mainAxis = vertical, crossAxis = horizontal
173
- // default to horizontal shift only (mainAxis: true, crossAxis: false)
174
- stayInFrame ? shift({
146
+ children,
147
+ size,
148
+ strategy = "absolute",
149
+ placement = "bottom",
150
+ stayInFrame,
151
+ allowFlip,
152
+ offset,
153
+ disableRTL,
154
+ resize,
155
+ passThrough,
156
+ open,
157
+ scope
158
+ } = props;
159
+ var [arrowEl, setArrow] = React.useState(null);
160
+ var [arrowSize, setArrowSize] = React.useState(0);
161
+ var offsetOptions = offset !== null && offset !== void 0 ? offset : arrowSize;
162
+ React.useRef({});
163
+ var isOpen = passThrough ? false : open !== null && open !== void 0 ? open : true;
164
+ var middlewareRef = React.useRef([]);
165
+ if (isOpen) middlewareRef.current = [typeof offsetOptions !== "undefined" ? offsetFn(offsetOptions) : null, allowFlip ? flip(typeof allowFlip === "boolean" ? {} : allowFlip) : null, stayInFrame ? shift({
175
166
  padding: 10,
176
- mainAxis: !0,
177
- crossAxis: !1,
178
- ...((typeof stayInFrame > "u" ? "undefined" : _type_of(stayInFrame)) === "object" ? stayInFrame : null)
167
+ mainAxis: true,
168
+ crossAxis: false,
169
+ ...((typeof stayInFrame === "undefined" ? "undefined" : _type_of(stayInFrame)) === "object" ? stayInFrame : null)
179
170
  }) : null, arrowEl ? arrow({
180
171
  element: arrowEl
181
- }) : null, checkFloating, null, null, null].filter(Boolean));
172
+ }) : null, checkFloating, null, null, null].filter(Boolean);
182
173
  var floating = useFloating({
183
- open: isOpen,
184
- strategy,
185
- placement,
186
- sameScrollView: !1,
187
- // this only takes effect on native
188
- whileElementsMounted: isOpen ? tamaguiAutoUpdate : void 0,
189
- platform: disableRTL ?? setupOptions.disableRTL ? {
190
- ...platform,
191
- isRTL(element) {
192
- return !1;
193
- }
194
- } : platform,
195
- middleware: middlewareRef.current
196
- }),
197
- {
198
- middlewareData
199
- } = floating,
200
- dimensions = useWindowDimensions(),
201
- [keyboardOpen, setKeyboardOpen] = React.useState(!1);
174
+ open: isOpen,
175
+ strategy,
176
+ placement,
177
+ sameScrollView: false,
178
+ whileElementsMounted: !isOpen ? void 0 : guiAutoUpdate,
179
+ platform: (disableRTL !== null && disableRTL !== void 0 ? disableRTL : setupOptions.disableRTL) ? {
180
+ ...platform,
181
+ isRTL(element) {
182
+ return false;
183
+ }
184
+ } : platform,
185
+ middleware: middlewareRef.current
186
+ });
187
+ var {
188
+ middlewareData
189
+ } = floating;
190
+ var dimensions = useWindowDimensions();
191
+ var [keyboardOpen, setKeyboardOpen] = React.useState(false);
202
192
  React.useEffect(function () {
203
193
  var showSubscription = Keyboard.addListener("keyboardDidShow", function () {
204
- startTransition(function () {
205
- setKeyboardOpen(!0);
206
- });
207
- }),
208
- hideSubscription = Keyboard.addListener("keyboardDidHide", function () {
209
- startTransition(function () {
210
- setKeyboardOpen(!1);
211
- });
194
+ startTransition(function () {
195
+ setKeyboardOpen(true);
196
+ });
197
+ });
198
+ var hideSubscription = Keyboard.addListener("keyboardDidHide", function () {
199
+ startTransition(function () {
200
+ setKeyboardOpen(false);
212
201
  });
202
+ });
213
203
  return function () {
214
- showSubscription.remove(), hideSubscription.remove();
204
+ showSubscription.remove();
205
+ hideSubscription.remove();
215
206
  };
216
- }, []), useIsomorphicLayoutEffect(function () {
217
- passThrough || floating.update();
207
+ }, []);
208
+ useIsomorphicLayoutEffect(function () {
209
+ if (passThrough) return;
210
+ floating.update();
218
211
  }, [passThrough, dimensions, keyboardOpen]);
219
- var popperContext = React.useMemo(function () {
220
- var _middlewareData_checkFloating;
221
- return {
222
- size,
223
- arrowRef: setArrow,
224
- arrowStyle: middlewareData.arrow,
225
- onArrowSize: setArrowSize,
226
- hasFloating: (_middlewareData_checkFloating = middlewareData.checkFloating) === null || _middlewareData_checkFloating === void 0 ? void 0 : _middlewareData_checkFloating.hasFloating,
227
- transformOrigin: middlewareData.transformOrigin,
228
- open: !!open,
229
- ...floating
230
- };
231
- }, [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]);
232
212
  return /* @__PURE__ */_jsx(PopperProvider, {
233
213
  scope,
234
- ...popperContext,
235
- children: (
236
- /* reset FloatingOverrideContext so it doesn't leak into nested Poppers —
237
- each Popper consumes the override for its own useFloating, children
238
- should not inherit it (e.g. a Menu inside a Tooltip's tree) */
239
- /* @__PURE__ */
240
- _jsx(FloatingOverrideContext.Provider, {
214
+ ...React.useMemo(function () {
215
+ var _middlewareData_checkFloating;
216
+ return {
217
+ size,
218
+ arrowRef: setArrow,
219
+ arrowStyle: middlewareData.arrow,
220
+ onArrowSize: setArrowSize,
221
+ hasFloating: (_middlewareData_checkFloating = middlewareData.checkFloating) === null || _middlewareData_checkFloating === void 0 ? void 0 : _middlewareData_checkFloating.hasFloating,
222
+ transformOrigin: middlewareData.transformOrigin,
223
+ open: !!open,
224
+ ...floating
225
+ };
226
+ }, [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]),
227
+ children: /* @__PURE__ */_jsx(FloatingOverrideContext.Provider, {
241
228
  value: null,
242
229
  children
243
- }))
230
+ })
244
231
  });
245
232
  }
246
- var PopperAnchor = YStack.styleable(function (props, forwardedRef) {
247
- var {
248
- virtualRef,
249
- scope,
250
- ...rest
251
- } = props,
252
- context = usePopperContextSlow(scope),
253
- {
254
- getReferenceProps,
255
- refs,
256
- update
257
- } = context,
258
- ref = React.useRef(null),
259
- triggerId = React.useId();
260
- React.useEffect(function () {
261
- if (!(!scope || !context.triggerElements || !ref.current) && _instanceof(ref.current, Element)) {
262
- var el = ref.current;
263
- return context.triggerElements.add(triggerId, el), function () {
264
- var _context_triggerElements;
265
- (_context_triggerElements = context.triggerElements) === null || _context_triggerElements === void 0 || _context_triggerElements.delete(triggerId);
266
- };
267
- }
268
- }, [scope, triggerId, context.triggerElements]), React.useEffect(function () {
269
- virtualRef && (refs.setReference(virtualRef.current), update());
270
- }, [virtualRef]);
271
- var refProps = getReferenceProps?.({
272
- ...rest,
273
- ref
274
- }) || null,
275
- safeSetReference = React.useCallback(function (node) {
276
- startTransition(function () {
277
- refs.setReference(node);
278
- });
279
- },
280
- // it was refs.setRefernce but its stable and refs is undefined on server
281
- [refs]),
282
- shouldHandleInHover = isWeb && scope,
283
- composedRefs = useComposedRefs(forwardedRef, ref,
284
- // web handles this onMouseEnter below so it can support multiple targets + hovering
285
- shouldHandleInHover ? void 0 : safeSetReference);
286
- return /* @__PURE__ */_jsx(GuiView, {
287
- ...rest,
288
- ...refProps,
289
- ref: composedRefs,
290
- ...(shouldHandleInHover && {
291
- // scoped poppers with multiple triggers: set the reference on
292
- // mouseEnter so floating-ui positions relative to the hovered
293
- // trigger, not the last one rendered.
294
- //
295
- // flushSync is critical here: without it, setReference batches
296
- // with React's async state updates and the arrow/content position
297
- // computes against the OLD reference element. this causes the
298
- // arrow to flash at x=0 (top-left) during trigger switches.
299
- // flushSync forces synchronous commit so update() below reads
300
- // the correct reference element immediately.
301
- onMouseEnter: function (e) {
302
- var _e_currentTarget,
303
- el = (_e_currentTarget = e.currentTarget) !== null && _e_currentTarget !== void 0 ? _e_currentTarget : ref.current;
304
- if (_instanceof(el, HTMLElement)) {
305
- var _refProps_onPointerEnter, _context_onHoverReference;
306
- if (flushSync(function () {
307
- return refs.setReference(el);
308
- }), update(), !refProps) return;
309
- (_refProps_onPointerEnter = refProps.onPointerEnter) === null || _refProps_onPointerEnter === void 0 || _refProps_onPointerEnter.call(refProps, e), (_context_onHoverReference = context.onHoverReference) === null || _context_onHoverReference === void 0 || _context_onHoverReference.call(context, e.nativeEvent);
310
- }
311
- },
312
- onMouseLeave: function (e) {
313
- var _context_onLeaveReference, _refProps_onMouseLeave;
314
- (_context_onLeaveReference = context.onLeaveReference) === null || _context_onLeaveReference === void 0 || _context_onLeaveReference.call(context), refProps == null || (_refProps_onMouseLeave = refProps.onMouseLeave) === null || _refProps_onMouseLeave === void 0 || _refProps_onMouseLeave.call(refProps, e);
315
- }
316
- })
233
+ var PopperAnchor = YStack.styleable(function PopperAnchor2(props, forwardedRef) {
234
+ var {
235
+ virtualRef,
236
+ scope,
237
+ ...rest
238
+ } = props;
239
+ var context = usePopperContextSlow(scope);
240
+ var {
241
+ getReferenceProps,
242
+ refs,
243
+ update
244
+ } = context;
245
+ var ref = React.useRef(null);
246
+ var triggerId = React.useId();
247
+ React.useEffect(function () {
248
+ if (!scope || !context.triggerElements || !ref.current) return;
249
+ if (!_instanceof(ref.current, Element)) return;
250
+ var el = ref.current;
251
+ context.triggerElements.add(triggerId, el);
252
+ return function () {
253
+ var _context_triggerElements;
254
+ (_context_triggerElements = context.triggerElements) === null || _context_triggerElements === void 0 || _context_triggerElements.delete(triggerId);
255
+ };
256
+ }, [scope, triggerId, context.triggerElements]);
257
+ React.useEffect(function () {
258
+ if (virtualRef) {
259
+ refs.setReference(virtualRef.current);
260
+ update();
261
+ }
262
+ }, [virtualRef]);
263
+ var refProps = (getReferenceProps === null || getReferenceProps === void 0 ? void 0 : getReferenceProps({
264
+ ...rest,
265
+ ref
266
+ })) || null;
267
+ var safeSetReference = React.useCallback(function (node) {
268
+ startTransition(function () {
269
+ refs.setReference(node);
317
270
  });
318
- }),
319
- PopperContentFrame = styled(YStack, {
320
- name: "PopperContent",
321
- variants: {
322
- unstyled: {
323
- true: {}
324
- },
325
- size: {
326
- "...size": function (val, param) {
327
- var {
328
- tokens
329
- } = param;
330
- return {
331
- padding: tokens.space[val],
332
- borderRadius: tokens.radius[val]
333
- };
271
+ },
272
+ // it was refs.setRefernce but its stable and refs is undefined on server
273
+ [refs]);
274
+ var shouldHandleInHover = isWeb && scope;
275
+ var composedRefs = useComposedRefs(forwardedRef, ref,
276
+ // web handles this onMouseEnter below so it can support multiple targets + hovering
277
+ shouldHandleInHover ? void 0 : safeSetReference);
278
+ return /* @__PURE__ */_jsx(GuiView, {
279
+ ...rest,
280
+ ...refProps,
281
+ ref: composedRefs,
282
+ ...(shouldHandleInHover && {
283
+ onMouseEnter: function (e) {
284
+ var _e_currentTarget;
285
+ var el = (_e_currentTarget = e.currentTarget) !== null && _e_currentTarget !== void 0 ? _e_currentTarget : ref.current;
286
+ if (_instanceof(el, HTMLElement)) {
287
+ var _refProps_onPointerEnter, _context_onHoverReference;
288
+ flushSync(function () {
289
+ return refs.setReference(el);
290
+ });
291
+ update();
292
+ if (!refProps) return;
293
+ (_refProps_onPointerEnter = refProps.onPointerEnter) === null || _refProps_onPointerEnter === void 0 || _refProps_onPointerEnter.call(refProps, e);
294
+ (_context_onHoverReference = context.onHoverReference) === null || _context_onHoverReference === void 0 || _context_onHoverReference.call(context, e.nativeEvent);
334
295
  }
296
+ },
297
+ onMouseLeave: function (e) {
298
+ var _context_onLeaveReference, _refProps_onMouseLeave;
299
+ (_context_onLeaveReference = context.onLeaveReference) === null || _context_onLeaveReference === void 0 || _context_onLeaveReference.call(context);
300
+ refProps === null || refProps === void 0 || (_refProps_onMouseLeave = refProps.onMouseLeave) == null || _refProps_onMouseLeave.call(refProps, e);
301
+ }
302
+ })
303
+ });
304
+ });
305
+ var PopperContentFrame = styled(YStack, {
306
+ name: "PopperContent",
307
+ variants: {
308
+ unstyled: {
309
+ true: {}
310
+ },
311
+ size: {
312
+ "...size": function (val, param) {
313
+ var {
314
+ tokens
315
+ } = param;
316
+ return {
317
+ padding: tokens.space[val],
318
+ borderRadius: tokens.radius[val]
319
+ };
335
320
  }
336
321
  }
337
- }),
338
- PopperContent = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
339
- var {
340
- scope,
341
- animatePosition,
342
- enableAnimationForPositionChange,
343
- children,
344
- passThrough,
345
- unstyled,
346
- ...rest
347
- } = props,
348
- animatePos = animatePosition ?? enableAnimationForPositionChange,
349
- context = usePopperContext(scope),
350
- {
351
- strategy,
352
- placement,
353
- refs,
354
- x,
355
- y,
356
- getFloatingProps,
357
- size,
358
- isPositioned,
359
- transformOrigin,
360
- update
361
- } = context,
362
- updateRef = React.useRef(update);
363
- updateRef.current = update;
364
- var lastNodeRef = React.useRef(null),
365
- safeSetFloating = React.useCallback(function (node) {
366
- var isNewNode = node !== lastNodeRef.current;
367
- if (node && (lastNodeRef.current = node, refs.setFloating(node), !isNewNode)) {
368
- var _updateRef_current;
369
- (_updateRef_current = updateRef.current) === null || _updateRef_current === void 0 || _updateRef_current.call(updateRef);
370
- }
371
- },
372
- // null calls are blocked: cycling nulls are transient, genuine unmount
373
- // is handled by the useEffect cleanup below
374
- [refs.setFloating]);
375
- React.useEffect(function () {
376
- return function () {
377
- var ourNode = lastNodeRef.current;
378
- ourNode && refs.floating.current === ourNode && refs.setFloating(null), lastNodeRef.current = null;
379
- };
380
- }, []);
381
- var contentRefs = useComposedRefs(safeSetFloating, forwardedRef),
382
- [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
383
- useIsomorphicLayoutEffect(function () {
384
- needsMeasure && x && y && setNeedsMeasure(!1);
385
- }, [needsMeasure, animatePos, x, y]);
386
- var hasBeenPositioned = React.useRef(!1),
387
- lastGoodPosition = React.useRef({
388
- x: 0,
389
- y: 0
390
- });
391
- (x !== 0 || y !== 0) && (lastGoodPosition.current = {
322
+ }
323
+ });
324
+ var PopperContent = /* @__PURE__ */React.forwardRef(function PopperContent2(props, forwardedRef) {
325
+ var {
326
+ scope,
327
+ animatePosition,
328
+ enableAnimationForPositionChange,
329
+ children,
330
+ passThrough,
331
+ unstyled,
332
+ ...rest
333
+ } = props;
334
+ var animatePos = animatePosition !== null && animatePosition !== void 0 ? animatePosition : enableAnimationForPositionChange;
335
+ var context = usePopperContext(scope);
336
+ var {
337
+ strategy,
338
+ placement,
339
+ refs,
340
+ x,
341
+ y,
342
+ getFloatingProps,
343
+ size,
344
+ isPositioned,
345
+ transformOrigin,
346
+ update
347
+ } = context;
348
+ var updateRef = React.useRef(update);
349
+ updateRef.current = update;
350
+ var lastNodeRef = React.useRef(null);
351
+ var safeSetFloating = React.useCallback(function (node) {
352
+ var isNewNode = node !== lastNodeRef.current;
353
+ if (node) {
354
+ lastNodeRef.current = node;
355
+ refs.setFloating(node);
356
+ if (!isNewNode) {
357
+ var _updateRef_current;
358
+ (_updateRef_current = updateRef.current) === null || _updateRef_current === void 0 || _updateRef_current.call(updateRef);
359
+ }
360
+ }
361
+ },
362
+ // null calls are blocked: cycling nulls are transient, genuine unmount
363
+ // is handled by the useEffect cleanup below
364
+ [refs.setFloating]);
365
+ React.useEffect(function () {
366
+ return function () {
367
+ var ourNode = lastNodeRef.current;
368
+ if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
369
+ lastNodeRef.current = null;
370
+ };
371
+ }, []);
372
+ var contentRefs = useComposedRefs(safeSetFloating, forwardedRef);
373
+ var [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
374
+ useIsomorphicLayoutEffect(function () {
375
+ if (needsMeasure && x && y) setNeedsMeasure(false);
376
+ }, [needsMeasure, animatePos, x, y]);
377
+ var hasBeenPositioned = React.useRef(false);
378
+ var lastGoodPosition = React.useRef({
379
+ x: 0,
380
+ y: 0
381
+ });
382
+ if (x !== 0 || y !== 0) {
383
+ lastGoodPosition.current = {
392
384
  x,
393
385
  y
394
- }, isPositioned && (hasBeenPositioned.current = !0));
395
- var brieflyZero = hasBeenPositioned.current && x === 0 && y === 0,
396
- effectiveX = brieflyZero ? lastGoodPosition.current.x : x,
397
- effectiveY = brieflyZero ? lastGoodPosition.current.y : y,
398
- hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0,
399
- disableAnimationProp =
400
- // if they want to animate also when re-positioning allow it
401
- animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure,
402
- [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
403
- React.useEffect(function () {
404
- setDisableAnimation(disableAnimationProp);
405
- }, [disableAnimationProp]);
406
- var positionProps = hide ? {} :
407
- // omit x/y when hiding - prevents motion driver from animating from origin
408
- {
409
- x: effectiveX || 0,
410
- y: effectiveY || 0
411
- },
412
- frameProps = {
413
- ref: contentRefs,
414
- ...positionProps,
415
- top: 0,
416
- left: 0,
417
- position: strategy,
418
- opacity: hide ? 0 : 1,
419
- ...(animatePos && {
420
- transition: rest.transition,
421
- // animateOnly: [] turns off transitions while keeping styles applied,
422
- // letting the element move to its position silently before animations start
423
- animateOnly: disableAnimation ? [] : rest.animateOnly,
424
- animatePresence: !1
425
- })
426
- },
427
- {
428
- style,
429
- ...floatingProps
430
- } = getFloatingProps ? getFloatingProps(frameProps) : frameProps,
431
- transformOriginStyle = isWeb && transformOrigin ? {
432
- transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
433
- } : void 0;
434
- return /* @__PURE__ */_jsx(LayoutMeasurementController, {
435
- disable: !context.open,
436
- children: /* @__PURE__ */_jsx(GuiView, {
386
+ };
387
+ if (isPositioned) hasBeenPositioned.current = true;
388
+ }
389
+ var brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
390
+ var effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
391
+ var effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
392
+ var hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
393
+ var disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
394
+ var [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
395
+ React.useEffect(function () {
396
+ setDisableAnimation(disableAnimationProp);
397
+ }, [disableAnimationProp]);
398
+ var frameProps = {
399
+ ref: contentRefs,
400
+ ...(hide ? {} :
401
+ // omit x/y when hiding - prevents motion driver from animating from origin
402
+ {
403
+ x: effectiveX || 0,
404
+ y: effectiveY || 0
405
+ }),
406
+ top: 0,
407
+ left: 0,
408
+ position: strategy,
409
+ opacity: hide ? 0 : 1,
410
+ ...(animatePos && {
411
+ transition: rest.transition,
412
+ animateOnly: disableAnimation ? [] : rest.animateOnly,
413
+ animatePresence: false
414
+ })
415
+ };
416
+ var {
417
+ style,
418
+ ...floatingProps
419
+ } = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
420
+ var transformOriginStyle = isWeb && transformOrigin ? {
421
+ transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
422
+ } : void 0;
423
+ return /* @__PURE__ */_jsx(LayoutMeasurementController, {
424
+ disable: !context.open,
425
+ children: /* @__PURE__ */_jsx(GuiView, {
426
+ passThrough,
427
+ ref: contentRefs,
428
+ direction: rest.direction,
429
+ ...(passThrough ? null : floatingProps),
430
+ ...(!passThrough && animatePos && {
431
+ "data-popper-animate-position": "true"
432
+ }),
433
+ children: /* @__PURE__ */_jsx(PopperContentFrame, {
437
434
  passThrough,
438
- ref: contentRefs,
439
- direction: rest.direction,
440
- ...(passThrough ? null : floatingProps),
441
- ...(!passThrough && animatePos && {
442
- "data-popper-animate-position": "true"
435
+ unstyled,
436
+ ...(!passThrough && {
437
+ "data-placement": placement,
438
+ "data-strategy": strategy,
439
+ size,
440
+ ...style,
441
+ ...transformOriginStyle,
442
+ ...rest
443
443
  }),
444
- children: /* @__PURE__ */_jsx(PopperContentFrame, {
445
- passThrough,
446
- unstyled,
447
- ...(!passThrough && {
448
- "data-placement": placement,
449
- "data-strategy": strategy,
450
- size,
451
- ...style,
452
- ...transformOriginStyle,
453
- ...rest
454
- }),
455
- children
456
- }, "popper-content-frame")
457
- })
458
- });
459
- }),
460
- PopperArrowFrame = styled(YStack, {
461
- name: "PopperArrow",
462
- variants: {
463
- unstyled: {
464
- false: {
465
- borderColor: "$borderColor",
466
- backgroundColor: "$background",
467
- position: "relative"
468
- }
444
+ children
445
+ }, "popper-content-frame")
446
+ })
447
+ });
448
+ });
449
+ var PopperArrowFrame = styled(YStack, {
450
+ name: "PopperArrow",
451
+ variants: {
452
+ unstyled: {
453
+ false: {
454
+ borderColor: "$borderColor",
455
+ backgroundColor: "$background",
456
+ position: "relative"
469
457
  }
470
- },
471
- defaultVariants: {
472
- unstyled: process.env.HANZO_GUI_HEADLESS === "1"
473
458
  }
474
- }),
475
- PopperArrowOuterFrame = styled(YStack, {
476
- name: "PopperArrowOuter",
477
- variants: {
478
- unstyled: {
479
- false: {
480
- position: "absolute",
481
- zIndex: 1e6,
482
- pointerEvents: "none",
483
- overflow: "hidden",
484
- alignItems: "center",
485
- justifyContent: "center"
486
- }
459
+ },
460
+ defaultVariants: {
461
+ unstyled: process.env.GUI_HEADLESS === "1"
462
+ }
463
+ });
464
+ var PopperArrowOuterFrame = styled(YStack, {
465
+ name: "PopperArrowOuter",
466
+ variants: {
467
+ unstyled: {
468
+ false: {
469
+ position: "absolute",
470
+ zIndex: 1e6,
471
+ pointerEvents: "none",
472
+ overflow: "hidden",
473
+ alignItems: "center",
474
+ justifyContent: "center"
487
475
  }
488
- },
489
- defaultVariants: {
490
- unstyled: process.env.HANZO_GUI_HEADLESS === "1"
491
476
  }
492
- }),
493
- opposites = {
494
- top: "bottom",
495
- right: "left",
496
- bottom: "top",
497
- left: "right"
498
477
  },
499
- PopperArrow = /* @__PURE__ */React.forwardRef(function (propsIn, forwardedRef) {
500
- var _context_arrowStyle,
501
- _context_arrowStyle1,
502
- {
503
- scope,
504
- animatePosition,
505
- transition,
506
- ...rest
507
- } = propsIn,
508
- {
509
- offset,
510
- size: sizeProp,
511
- borderWidth = 0,
512
- ...arrowProps
513
- } = rest,
514
- context = usePopperContext(scope),
515
- sizeVal = typeof sizeProp == "number" ? sizeProp : getVariableValue(getSpace(sizeProp ?? context.size, {
516
- shift: -2,
517
- bounds: [2]
518
- })),
519
- size = Math.max(0, +sizeVal),
520
- {
521
- placement
522
- } = context,
523
- refs = useComposedRefs(context.arrowRef, forwardedRef),
524
- x = ((_context_arrowStyle = context.arrowStyle) === null || _context_arrowStyle === void 0 ? void 0 : _context_arrowStyle.x) || 0,
525
- y = ((_context_arrowStyle1 = context.arrowStyle) === null || _context_arrowStyle1 === void 0 ? void 0 : _context_arrowStyle1.y) || 0,
526
- arrowPositioned = context.arrowStyle != null,
527
- primaryPlacement = placement ? placement.split("-")[0] : "top",
528
- arrowStyle = {
529
- x,
530
- y,
531
- width: size,
532
- height: size
533
- },
534
- innerArrowStyle = {},
535
- isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
536
- if (primaryPlacement) {
537
- arrowStyle[isVertical ? "width" : "height"] = size * 2;
538
- var oppSide = opposites[primaryPlacement];
539
- oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0), useIsomorphicLayoutEffect(function () {
540
- var _context_onArrowSize;
541
- (_context_onArrowSize = context.onArrowSize) === null || _context_onArrowSize === void 0 || _context_onArrowSize.call(context, size);
542
- }, [size, context.onArrowSize]);
478
+ defaultVariants: {
479
+ unstyled: process.env.GUI_HEADLESS === "1"
480
+ }
481
+ });
482
+ var opposites = {
483
+ top: "bottom",
484
+ right: "left",
485
+ bottom: "top",
486
+ left: "right"
487
+ };
488
+ var PopperArrow = /* @__PURE__ */React.forwardRef(function PopperArrow2(propsIn, forwardedRef) {
489
+ var _context_arrowStyle, _context_arrowStyle1;
490
+ var {
491
+ scope,
492
+ animatePosition,
493
+ transition,
494
+ ...rest
495
+ } = propsIn;
496
+ var {
497
+ offset,
498
+ size: sizeProp,
499
+ borderWidth = 0,
500
+ ...arrowProps
501
+ } = rest;
502
+ var context = usePopperContext(scope);
503
+ var sizeVal = typeof sizeProp === "number" ? sizeProp : getVariableValue(getSpace(sizeProp !== null && sizeProp !== void 0 ? sizeProp : context.size, {
504
+ shift: -2,
505
+ bounds: [2]
506
+ }));
507
+ var size = Math.max(0, +sizeVal);
508
+ var {
509
+ placement
510
+ } = context;
511
+ var refs = useComposedRefs(context.arrowRef, forwardedRef);
512
+ var x = ((_context_arrowStyle = context.arrowStyle) === null || _context_arrowStyle === void 0 ? void 0 : _context_arrowStyle.x) || 0;
513
+ var y = ((_context_arrowStyle1 = context.arrowStyle) === null || _context_arrowStyle1 === void 0 ? void 0 : _context_arrowStyle1.y) || 0;
514
+ var arrowPositioned = context.arrowStyle != null;
515
+ var primaryPlacement = placement ? placement.split("-")[0] : "top";
516
+ var arrowStyle = {
517
+ x,
518
+ y,
519
+ width: size,
520
+ height: size
521
+ };
522
+ var innerArrowStyle = {};
523
+ var isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
524
+ if (primaryPlacement) {
525
+ arrowStyle[isVertical ? "width" : "height"] = size * 2;
526
+ var oppSide = opposites[primaryPlacement];
527
+ if (oppSide) {
528
+ arrowStyle[oppSide] = -size;
529
+ innerArrowStyle[oppSide] = size / 2;
543
530
  }
544
- return /* @__PURE__ */_jsx(PopperArrowOuterFrame, {
545
- ref: refs,
546
- ...arrowStyle,
547
- ...(!arrowPositioned && {
548
- opacity: 0
531
+ if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
532
+ if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
533
+ useIsomorphicLayoutEffect(function () {
534
+ var _context_onArrowSize;
535
+ (_context_onArrowSize = context.onArrowSize) === null || _context_onArrowSize === void 0 || _context_onArrowSize.call(context, size);
536
+ }, [size, context.onArrowSize]);
537
+ }
538
+ return /* @__PURE__ */_jsx(PopperArrowOuterFrame, {
539
+ ref: refs,
540
+ ...arrowStyle,
541
+ ...(!arrowPositioned && {
542
+ opacity: 0
543
+ }),
544
+ ...(animatePosition && {
545
+ transition,
546
+ animateOnly: ["transform"],
547
+ animatePresence: false
548
+ }),
549
+ children: /* @__PURE__ */_jsx(PopperArrowFrame, {
550
+ width: size,
551
+ height: size,
552
+ ...arrowProps,
553
+ ...innerArrowStyle,
554
+ rotate: "45deg",
555
+ ...(primaryPlacement === "bottom" && {
556
+ borderLeftWidth: borderWidth,
557
+ borderTopWidth: borderWidth
549
558
  }),
550
- ...(animatePosition && {
551
- transition,
552
- animateOnly: ["transform"],
553
- animatePresence: !1
559
+ ...(primaryPlacement === "top" && {
560
+ borderBottomWidth: borderWidth,
561
+ borderRightWidth: borderWidth
554
562
  }),
555
- children: /* @__PURE__ */_jsx(PopperArrowFrame, {
556
- width: size,
557
- height: size,
558
- ...arrowProps,
559
- ...innerArrowStyle,
560
- rotate: "45deg",
561
- ...(primaryPlacement === "bottom" && {
562
- borderLeftWidth: borderWidth,
563
- borderTopWidth: borderWidth
564
- }),
565
- ...(primaryPlacement === "top" && {
566
- borderBottomWidth: borderWidth,
567
- borderRightWidth: borderWidth
568
- }),
569
- ...(primaryPlacement === "right" && {
570
- borderLeftWidth: borderWidth,
571
- borderBottomWidth: borderWidth
572
- }),
573
- ...(primaryPlacement === "left" && {
574
- borderTopWidth: borderWidth,
575
- borderRightWidth: borderWidth
576
- })
563
+ ...(primaryPlacement === "right" && {
564
+ borderLeftWidth: borderWidth,
565
+ borderBottomWidth: borderWidth
566
+ }),
567
+ ...(primaryPlacement === "left" && {
568
+ borderTopWidth: borderWidth,
569
+ borderRightWidth: borderWidth
577
570
  })
578
- });
571
+ })
579
572
  });
573
+ });
580
574
  export { Popper, PopperAnchor, PopperArrow, PopperArrowFrame, PopperContent, PopperContentFrame, PopperContextFast, PopperContextSlow, PopperPositionContext, PopperProvider, PopperProviderFast, PopperProviderSlow, setupPopper, usePopperContext, usePopperContextSlow };
581
575
  //# sourceMappingURL=Popper.native.js.map