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