@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.
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,49 +6,42 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var Popper_exports = {};
35
29
  __export(Popper_exports, {
36
- Popper: () => Popper,
37
- PopperAnchor: () => PopperAnchor,
38
- PopperArrow: () => PopperArrow,
39
- PopperArrowFrame: () => PopperArrowFrame,
40
- PopperContent: () => PopperContent,
41
- PopperContentFrame: () => PopperContentFrame,
42
- PopperContextFast: () => PopperContextFast,
43
- PopperContextSlow: () => PopperContextSlow,
44
- PopperPositionContext: () => PopperPositionContext,
45
- PopperProvider: () => PopperProvider,
46
- PopperProviderFast: () => PopperProviderFast,
47
- PopperProviderSlow: () => PopperProviderSlow,
48
- setupPopper: () => setupPopper,
49
- usePopperContext: () => usePopperContext,
50
- usePopperContextSlow: () => usePopperContextSlow
30
+ Popper: () => Popper,
31
+ PopperAnchor: () => PopperAnchor,
32
+ PopperArrow: () => PopperArrow,
33
+ PopperArrowFrame: () => PopperArrowFrame,
34
+ PopperContent: () => PopperContent,
35
+ PopperContentFrame: () => PopperContentFrame,
36
+ PopperContextFast: () => PopperContextFast,
37
+ PopperContextSlow: () => PopperContextSlow,
38
+ PopperPositionContext: () => PopperPositionContext,
39
+ PopperProvider: () => PopperProvider,
40
+ PopperProviderFast: () => PopperProviderFast,
41
+ PopperProviderSlow: () => PopperProviderSlow,
42
+ setupPopper: () => setupPopper,
43
+ usePopperContext: () => usePopperContext,
44
+ usePopperContextSlow: () => usePopperContextSlow
51
45
  });
52
46
  module.exports = __toCommonJS(Popper_exports);
53
47
  var import_react_dom = require("react-dom");
@@ -57,595 +51,469 @@ var import_core = require("@tamagui/core");
57
51
  var import_floating = require("@tamagui/floating");
58
52
  var import_floating2 = require("@tamagui/floating");
59
53
  var import_get_token = require("@tamagui/get-token");
60
- var import_stacks = require("@tamagui/stacks");
61
54
  var import_start_transition = require("@tamagui/start-transition");
62
55
  var React = __toESM(require("react"), 1);
63
56
  require("react-native-web");
64
57
  var import_jsx_runtime = require("react/jsx-runtime");
65
- const PopperContextFast = (0, import_core.createStyledContext)(
66
- // since we always provide this we can avoid setting here
67
- {}, "Popper__");
58
+ const PopperContextFast = (0, import_core.createStyledContext)({}, "Popper__");
68
59
  const PopperPositionContext = import_core.createStyledContext;
69
- const {
70
- useStyledContext: usePopperContext,
71
- Provider: PopperProviderFast
72
- } = PopperContextFast;
73
- const PopperContextSlow = (0, import_core.createStyledContext)(
74
- // since we always provide this we can avoid setting here
75
- {}, "PopperSlow__");
76
- const {
77
- useStyledContext: usePopperContextSlow,
78
- Provider: PopperProviderSlow
79
- } = PopperContextSlow;
80
- const PopperProvider = ({
81
- scope,
82
- children,
83
- ...context
84
- }) => {
85
- const fns = React.useRef(context);
86
- fns.current = context;
87
- const [slowContext] = React.useState(() => ({
88
- refs: context.refs,
89
- triggerElements: context.triggerElements,
90
- update(...a) {
91
- fns.current.update(...a);
92
- },
93
- getReferenceProps(p) {
94
- return fns.current.getReferenceProps?.(p);
95
- },
96
- onHoverReference(e) {
97
- fns.current.onHoverReference?.(e);
98
- },
99
- onLeaveReference() {
100
- fns.current.onLeaveReference?.();
101
- }
102
- }));
103
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProviderFast, {
104
- scope,
105
- ...context,
106
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProviderSlow, {
107
- scope,
108
- ...slowContext,
109
- children
110
- })
111
- });
60
+ const { useStyledContext: usePopperContext, Provider: PopperProviderFast } = PopperContextFast;
61
+ const PopperContextSlow = (0, import_core.createStyledContext)({}, "PopperSlow__");
62
+ const { useStyledContext: usePopperContextSlow, Provider: PopperProviderSlow } = PopperContextSlow;
63
+ const PopperProvider = ({ scope, children, ...context }) => {
64
+ const fns = React.useRef(context);
65
+ fns.current = context;
66
+ const [slowContext] = React.useState(() => ({
67
+ refs: context.refs,
68
+ triggerElements: context.triggerElements,
69
+ update(...a) {
70
+ fns.current.update(...a);
71
+ },
72
+ getReferenceProps(p) {
73
+ return fns.current.getReferenceProps?.(p);
74
+ },
75
+ onHoverReference(e) {
76
+ fns.current.onHoverReference?.(e);
77
+ },
78
+ onLeaveReference() {
79
+ fns.current.onLeaveReference?.();
80
+ }
81
+ }));
82
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProviderFast, {
83
+ scope,
84
+ ...context,
85
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProviderSlow, {
86
+ scope,
87
+ ...slowContext,
88
+ children
89
+ })
90
+ });
112
91
  };
113
92
  const checkFloating = void 0;
114
93
  const setupOptions = {};
115
94
  function setupPopper(options) {
116
- Object.assign(setupOptions, options);
95
+ Object.assign(setupOptions, options);
117
96
  }
118
97
  function getSideAndAlignFromPlacement(placement) {
119
- const [side, align = "center"] = placement.split("-");
120
- return [side, align];
98
+ const [side, align = "center"] = placement.split("-");
99
+ return [side, align];
121
100
  }
122
- const transformOriginMiddleware = options => ({
123
- name: "transformOrigin",
124
- options,
125
- fn(data) {
126
- const {
127
- placement,
128
- rects,
129
- middlewareData
130
- } = data;
131
- const isArrowHidden = middlewareData.arrow?.centerOffset !== 0;
132
- const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
133
- const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
134
- const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
135
- const noArrowAlign = {
136
- start: "0%",
137
- center: "50%",
138
- end: "100%"
139
- }[placedAlign];
140
- const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
141
- const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
142
- let x = "";
143
- let y = "";
144
- if (placedSide === "bottom") {
145
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
146
- y = `${-arrowHeight}px`;
147
- } else if (placedSide === "top") {
148
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
149
- y = `${rects.floating.height + arrowHeight}px`;
150
- } else if (placedSide === "right") {
151
- x = `${-arrowHeight}px`;
152
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
153
- } else if (placedSide === "left") {
154
- x = `${rects.floating.width + arrowHeight}px`;
155
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
156
- }
157
- return {
158
- data: {
159
- x,
160
- y
161
- }
162
- };
163
- }
101
+ const transformOriginMiddleware = (options) => ({
102
+ name: "transformOrigin",
103
+ options,
104
+ fn(data) {
105
+ const { placement, rects, middlewareData } = data;
106
+ const isArrowHidden = middlewareData.arrow?.centerOffset !== 0;
107
+ const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
108
+ const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
109
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
110
+ const noArrowAlign = {
111
+ start: "0%",
112
+ center: "50%",
113
+ end: "100%"
114
+ }[placedAlign];
115
+ const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
116
+ const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
117
+ let x = "";
118
+ let y = "";
119
+ if (placedSide === "bottom") {
120
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
121
+ y = `${-arrowHeight}px`;
122
+ } else if (placedSide === "top") {
123
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
124
+ y = `${rects.floating.height + arrowHeight}px`;
125
+ } else if (placedSide === "right") {
126
+ x = `${-arrowHeight}px`;
127
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
128
+ } else if (placedSide === "left") {
129
+ x = `${rects.floating.width + arrowHeight}px`;
130
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
131
+ }
132
+ return { data: {
133
+ x,
134
+ y
135
+ } };
136
+ }
164
137
  });
165
138
  function tamaguiAutoUpdate(reference, floating, update) {
166
- update();
167
- let rafId = requestAnimationFrame(() => {
168
- update();
169
- rafId = 0;
170
- });
171
- const cleanups = [() => {
172
- if (rafId) cancelAnimationFrame(rafId);
173
- }];
174
- if (reference instanceof HTMLElement) cleanups.push((0, import_core.registerLayoutNode)(reference, update));
175
- if (typeof ResizeObserver !== "undefined") {
176
- let lastWidth = -1;
177
- let lastHeight = -1;
178
- const ro = new ResizeObserver(entries => {
179
- const entry = entries[entries.length - 1];
180
- if (!entry) return;
181
- const {
182
- width,
183
- height
184
- } = entry.contentRect;
185
- if (lastWidth === -1) {
186
- lastWidth = width;
187
- lastHeight = height;
188
- return;
189
- }
190
- if (width !== lastWidth || height !== lastHeight) {
191
- lastWidth = width;
192
- lastHeight = height;
193
- update();
194
- }
195
- });
196
- ro.observe(floating);
197
- cleanups.push(() => ro.disconnect());
198
- }
199
- const ancestors = [...(reference instanceof Element ? (0, import_floating2.getOverflowAncestors)(reference) : []), ...(0, import_floating2.getOverflowAncestors)(floating)];
200
- const uniqueAncestors = [...new Set(ancestors)];
201
- for (const ancestor of uniqueAncestors) ancestor.addEventListener("scroll", update, {
202
- passive: true
203
- });
204
- window.addEventListener("resize", update);
205
- cleanups.push(() => {
206
- for (const ancestor of uniqueAncestors) ancestor.removeEventListener("scroll", update);
207
- window.removeEventListener("resize", update);
208
- });
209
- return () => cleanups.forEach(fn => fn());
139
+ update();
140
+ let rafId = requestAnimationFrame(() => {
141
+ update();
142
+ rafId = 0;
143
+ });
144
+ const cleanups = [() => {
145
+ if (rafId) cancelAnimationFrame(rafId);
146
+ }];
147
+ if (reference instanceof HTMLElement) cleanups.push((0, import_core.registerLayoutNode)(reference, update));
148
+ if (typeof ResizeObserver !== "undefined") {
149
+ let lastWidth = -1;
150
+ let lastHeight = -1;
151
+ const ro = new ResizeObserver((entries) => {
152
+ const entry = entries[entries.length - 1];
153
+ if (!entry) return;
154
+ const { width, height } = entry.contentRect;
155
+ if (lastWidth === -1) {
156
+ lastWidth = width;
157
+ lastHeight = height;
158
+ return;
159
+ }
160
+ if (width !== lastWidth || height !== lastHeight) {
161
+ lastWidth = width;
162
+ lastHeight = height;
163
+ update();
164
+ }
165
+ });
166
+ ro.observe(floating);
167
+ cleanups.push(() => ro.disconnect());
168
+ }
169
+ const ancestors = [...reference instanceof Element ? (0, import_floating2.getOverflowAncestors)(reference) : [], ...(0, import_floating2.getOverflowAncestors)(floating)];
170
+ const uniqueAncestors = [...new Set(ancestors)];
171
+ for (const ancestor of uniqueAncestors) ancestor.addEventListener("scroll", update, { passive: true });
172
+ window.addEventListener("resize", update);
173
+ cleanups.push(() => {
174
+ for (const ancestor of uniqueAncestors) ancestor.removeEventListener("scroll", update);
175
+ window.removeEventListener("resize", update);
176
+ });
177
+ return () => cleanups.forEach((fn) => fn());
210
178
  }
211
179
  function Popper(props) {
212
- const {
213
- children,
214
- size,
215
- strategy = "absolute",
216
- placement = "bottom",
217
- stayInFrame,
218
- allowFlip,
219
- offset,
220
- disableRTL,
221
- resize,
222
- passThrough,
223
- open,
224
- scope
225
- } = props;
226
- const [arrowEl, setArrow] = React.useState(null);
227
- const [arrowSize, setArrowSize] = React.useState(0);
228
- const offsetOptions = offset ?? arrowSize;
229
- const floatingStyle = React.useRef({});
230
- const isOpen = passThrough ? false : open ?? true;
231
- const middlewareRef = React.useRef([]);
232
- if (isOpen) middlewareRef.current = [typeof offsetOptions !== "undefined" ? (0, import_floating2.offset)(offsetOptions) : null, allowFlip ? (0, import_floating2.flip)(typeof allowFlip === "boolean" ? {} : allowFlip) : null, stayInFrame ? (0, import_floating2.shift)({
233
- padding: 10,
234
- mainAxis: true,
235
- crossAxis: false,
236
- ...(typeof stayInFrame === "object" ? stayInFrame : null)
237
- }) : null, arrowEl ? (0, import_floating2.arrow)({
238
- element: arrowEl
239
- }) : null, checkFloating, resize ? (0, import_floating2.size)({
240
- padding: typeof stayInFrame === "object" ? stayInFrame.padding : 10,
241
- apply({
242
- availableHeight,
243
- availableWidth
244
- }) {
245
- if (passThrough) return;
246
- Object.assign(floatingStyle.current, {
247
- maxHeight: `${availableHeight}px`,
248
- maxWidth: `${availableWidth}px`
249
- });
250
- const floatingChild = floating.refs.floating.current?.firstChild;
251
- if (floatingChild && floatingChild instanceof HTMLElement) Object.assign(floatingChild.style, floatingStyle.current);
252
- },
253
- ...(typeof resize === "object" && resize)
254
- }) : null, (0, import_floating2.size)({
255
- apply({
256
- elements,
257
- rects,
258
- availableWidth,
259
- availableHeight
260
- }) {
261
- const {
262
- width: anchorWidth,
263
- height: anchorHeight
264
- } = rects.reference;
265
- const contentStyle = elements.floating.style;
266
- contentStyle.setProperty("--tamagui-popper-available-width", `${availableWidth}px`);
267
- contentStyle.setProperty("--tamagui-popper-available-height", `${availableHeight}px`);
268
- contentStyle.setProperty("--tamagui-popper-anchor-width", `${anchorWidth}px`);
269
- contentStyle.setProperty("--tamagui-popper-anchor-height", `${anchorHeight}px`);
270
- }
271
- }), transformOriginMiddleware({
272
- arrowHeight: arrowSize,
273
- arrowWidth: arrowSize
274
- })].filter(Boolean);
275
- let floating = (0, import_floating2.useFloating)({
276
- open: isOpen,
277
- strategy,
278
- placement,
279
- sameScrollView: false,
280
- whileElementsMounted: !isOpen ? void 0 : tamaguiAutoUpdate,
281
- platform: disableRTL ?? setupOptions.disableRTL ? {
282
- ...import_floating2.platform,
283
- isRTL(element) {
284
- return false;
285
- }
286
- } : import_floating2.platform,
287
- middleware: middlewareRef.current
288
- });
289
- floating = React.useMemo(() => {
290
- const og = floating.getFloatingProps;
291
- if (resize && og) floating.getFloatingProps = props2 => {
292
- return og({
293
- ...props2,
294
- style: {
295
- ...props2.style,
296
- ...floatingStyle.current
297
- }
298
- });
299
- };
300
- return floating;
301
- }, [floating, resize ? JSON.stringify(resize) : null]);
302
- const {
303
- middlewareData
304
- } = floating;
305
- const popperContext = React.useMemo(() => {
306
- return {
307
- size,
308
- arrowRef: setArrow,
309
- arrowStyle: middlewareData.arrow,
310
- onArrowSize: setArrowSize,
311
- hasFloating: middlewareData.checkFloating?.hasFloating,
312
- transformOrigin: middlewareData.transformOrigin,
313
- open: !!open,
314
- ...floating
315
- };
316
- }, [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]);
317
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProvider, {
318
- scope,
319
- ...popperContext,
320
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_floating.FloatingOverrideContext.Provider, {
321
- value: null,
322
- children
323
- })
324
- });
180
+ const { children, size, strategy = "absolute", placement = "bottom", stayInFrame, allowFlip, offset, disableRTL, resize, passThrough, open, scope } = props;
181
+ const [arrowEl, setArrow] = React.useState(null);
182
+ const [arrowSize, setArrowSize] = React.useState(0);
183
+ const offsetOptions = offset ?? arrowSize;
184
+ const floatingStyle = React.useRef({});
185
+ const isOpen = passThrough ? false : open ?? true;
186
+ const middlewareRef = React.useRef([]);
187
+ if (isOpen) middlewareRef.current = [
188
+ typeof offsetOptions !== "undefined" ? (0, import_floating2.offset)(offsetOptions) : null,
189
+ allowFlip ? (0, import_floating2.flip)(typeof allowFlip === "boolean" ? {} : allowFlip) : null,
190
+ stayInFrame ? (0, import_floating2.shift)({
191
+ padding: 10,
192
+ mainAxis: true,
193
+ crossAxis: false,
194
+ ...typeof stayInFrame === "object" ? stayInFrame : null
195
+ }) : null,
196
+ arrowEl ? (0, import_floating2.arrow)({ element: arrowEl }) : null,
197
+ checkFloating,
198
+ resize ? (0, import_floating2.size)({
199
+ padding: typeof stayInFrame === "object" ? stayInFrame.padding : 10,
200
+ apply({ availableHeight, availableWidth }) {
201
+ if (passThrough) return;
202
+ Object.assign(floatingStyle.current, {
203
+ maxHeight: `${availableHeight}px`,
204
+ maxWidth: `${availableWidth}px`
205
+ });
206
+ const floatingChild = floating.refs.floating.current?.firstChild;
207
+ if (floatingChild && floatingChild instanceof HTMLElement) Object.assign(floatingChild.style, floatingStyle.current);
208
+ },
209
+ ...typeof resize === "object" && resize
210
+ }) : null,
211
+ (0, import_floating2.size)({ apply({ elements, rects, availableWidth, availableHeight }) {
212
+ const { width: anchorWidth, height: anchorHeight } = rects.reference;
213
+ const contentStyle = elements.floating.style;
214
+ contentStyle.setProperty("--tamagui-popper-available-width", `${availableWidth}px`);
215
+ contentStyle.setProperty("--tamagui-popper-available-height", `${availableHeight}px`);
216
+ contentStyle.setProperty("--tamagui-popper-anchor-width", `${anchorWidth}px`);
217
+ contentStyle.setProperty("--tamagui-popper-anchor-height", `${anchorHeight}px`);
218
+ } }),
219
+ transformOriginMiddleware({
220
+ arrowHeight: arrowSize,
221
+ arrowWidth: arrowSize
222
+ })
223
+ ].filter(Boolean);
224
+ let floating = (0, import_floating2.useFloating)({
225
+ open: isOpen,
226
+ strategy,
227
+ placement,
228
+ sameScrollView: false,
229
+ whileElementsMounted: !isOpen ? void 0 : tamaguiAutoUpdate,
230
+ platform: disableRTL ?? setupOptions.disableRTL ? {
231
+ ...import_floating2.platform,
232
+ isRTL(element) {
233
+ return false;
234
+ }
235
+ } : import_floating2.platform,
236
+ middleware: middlewareRef.current
237
+ });
238
+ floating = React.useMemo(() => {
239
+ const og = floating.getFloatingProps;
240
+ if (resize && og) floating.getFloatingProps = (props2) => {
241
+ return og({
242
+ ...props2,
243
+ style: {
244
+ ...props2.style,
245
+ ...floatingStyle.current
246
+ }
247
+ });
248
+ };
249
+ return floating;
250
+ }, [floating, resize ? JSON.stringify(resize) : null]);
251
+ const { middlewareData } = floating;
252
+ const popperContext = React.useMemo(() => {
253
+ return {
254
+ size,
255
+ arrowRef: setArrow,
256
+ arrowStyle: middlewareData.arrow,
257
+ onArrowSize: setArrowSize,
258
+ hasFloating: middlewareData.checkFloating?.hasFloating,
259
+ transformOrigin: middlewareData.transformOrigin,
260
+ open: !!open,
261
+ ...floating
262
+ };
263
+ }, [
264
+ open,
265
+ size,
266
+ floating,
267
+ JSON.stringify(middlewareData.arrow || null),
268
+ JSON.stringify(middlewareData.transformOrigin || null)
269
+ ]);
270
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProvider, {
271
+ scope,
272
+ ...popperContext,
273
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_floating.FloatingOverrideContext.Provider, {
274
+ value: null,
275
+ children
276
+ })
277
+ });
325
278
  }
326
- const PopperAnchor = import_stacks.YStack.styleable(function PopperAnchor2(props, forwardedRef) {
327
- const {
328
- virtualRef,
329
- scope,
330
- ...rest
331
- } = props;
332
- const context = usePopperContextSlow(scope);
333
- const {
334
- getReferenceProps,
335
- refs,
336
- update
337
- } = context;
338
- const ref = React.useRef(null);
339
- const triggerId = React.useId();
340
- React.useEffect(() => {
341
- if (!scope || !context.triggerElements || !ref.current) return;
342
- if (!(ref.current instanceof Element)) return;
343
- const el = ref.current;
344
- context.triggerElements.add(triggerId, el);
345
- return () => {
346
- context.triggerElements?.delete(triggerId);
347
- };
348
- }, [scope, triggerId, context.triggerElements]);
349
- React.useEffect(() => {
350
- if (virtualRef) {
351
- refs.setReference(virtualRef.current);
352
- update();
353
- }
354
- }, [virtualRef]);
355
- const refProps = getReferenceProps?.({
356
- ...rest,
357
- ref
358
- }) || null;
359
- const safeSetReference = React.useCallback(node => {
360
- (0, import_start_transition.startTransition)(() => {
361
- refs.setReference(node);
362
- });
363
- },
364
- // it was refs.setRefernce but its stable and refs is undefined on server
365
- [refs]);
366
- const shouldHandleInHover = import_constants.isWeb && scope;
367
- const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref,
368
- // web handles this onMouseEnter below so it can support multiple targets + hovering
369
- shouldHandleInHover ? void 0 : safeSetReference);
370
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
371
- ...rest,
372
- ...refProps,
373
- ref: composedRefs,
374
- ...(shouldHandleInHover && {
375
- onMouseEnter: e => {
376
- const el = e.currentTarget ?? ref.current;
377
- if (el instanceof HTMLElement) {
378
- (0, import_react_dom.flushSync)(() => refs.setReference(el));
379
- update();
380
- if (!refProps) return;
381
- refProps.onPointerEnter?.(e);
382
- context.onHoverReference?.(e.nativeEvent);
383
- }
384
- },
385
- onMouseLeave: e => {
386
- context.onLeaveReference?.();
387
- refProps?.onMouseLeave?.(e);
388
- }
389
- })
390
- });
279
+ const PopperAnchor = (0, import_core.createStyledHOC)(import_core.View, function PopperAnchor2(props, forwardedRef) {
280
+ const { virtualRef, scope, ...rest } = props;
281
+ const context = usePopperContextSlow(scope);
282
+ const { getReferenceProps, refs, update } = context;
283
+ const ref = React.useRef(null);
284
+ const triggerId = React.useId();
285
+ React.useEffect(() => {
286
+ if (!scope || !context.triggerElements || !ref.current) return;
287
+ if (!(ref.current instanceof Element)) return;
288
+ const el = ref.current;
289
+ context.triggerElements.add(triggerId, el);
290
+ return () => {
291
+ context.triggerElements?.delete(triggerId);
292
+ };
293
+ }, [
294
+ scope,
295
+ triggerId,
296
+ context.triggerElements
297
+ ]);
298
+ React.useEffect(() => {
299
+ if (virtualRef) {
300
+ refs.setReference(virtualRef.current);
301
+ update();
302
+ }
303
+ }, [virtualRef]);
304
+ const refProps = getReferenceProps?.({
305
+ ...rest,
306
+ ref
307
+ }) || null;
308
+ const safeSetReference = React.useCallback((node) => {
309
+ (0, import_start_transition.startTransition)(() => {
310
+ refs.setReference(node);
311
+ });
312
+ }, [refs]);
313
+ const shouldHandleInHover = import_constants.isWeb && scope;
314
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, shouldHandleInHover ? void 0 : safeSetReference);
315
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
316
+ ...rest,
317
+ ...refProps,
318
+ ref: composedRefs,
319
+ ...shouldHandleInHover && {
320
+ onMouseEnter: (e) => {
321
+ const el = e.currentTarget ?? ref.current;
322
+ if (el instanceof HTMLElement) {
323
+ (0, import_react_dom.flushSync)(() => refs.setReference(el));
324
+ update();
325
+ if (!refProps) return;
326
+ refProps.onPointerEnter?.(e);
327
+ context.onHoverReference?.(e.nativeEvent);
328
+ }
329
+ },
330
+ onMouseLeave: (e) => {
331
+ context.onLeaveReference?.();
332
+ refProps?.onMouseLeave?.(e);
333
+ }
334
+ }
335
+ });
391
336
  });
392
- const PopperContentFrame = (0, import_core.styled)(import_stacks.YStack, {
393
- name: "PopperContent",
394
- variants: {
395
- unstyled: {
396
- true: {}
397
- },
398
- size: {
399
- "...size": (val, {
400
- tokens
401
- }) => {
402
- return {
403
- padding: tokens.space[val],
404
- borderRadius: tokens.radius[val]
405
- };
406
- }
407
- }
408
- }
337
+ const PopperContentFrame = (0, import_core.styled)(import_core.View, { displayName: "PopperContent" });
338
+ const PopperContent = (0, import_core.createRefComponent)(function PopperContent2(props, forwardedRef) {
339
+ const isAnimatePosControlled = "animatePosition" in props;
340
+ const { scope, animatePosition, children, passThrough, ...rest } = props;
341
+ const animatePos = animatePosition;
342
+ const context = usePopperContext(scope);
343
+ const { strategy, placement, refs, x, y, getFloatingProps, isPositioned, transformOrigin, update } = context;
344
+ const updateRef = React.useRef(update);
345
+ updateRef.current = update;
346
+ const lastNodeRef = React.useRef(null);
347
+ const safeSetFloating = React.useCallback((node) => {
348
+ const isNewNode = node !== lastNodeRef.current;
349
+ if (node) {
350
+ lastNodeRef.current = node;
351
+ refs.setFloating(node);
352
+ if (!isNewNode) updateRef.current?.();
353
+ }
354
+ }, [refs.setFloating]);
355
+ React.useEffect(() => {
356
+ return () => {
357
+ const ourNode = lastNodeRef.current;
358
+ if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
359
+ lastNodeRef.current = null;
360
+ };
361
+ }, []);
362
+ const contentRefs = (0, import_compose_refs.useComposedRefs)(safeSetFloating, forwardedRef);
363
+ const [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
364
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
365
+ if (needsMeasure && x && y) setNeedsMeasure(false);
366
+ }, [
367
+ needsMeasure,
368
+ animatePos,
369
+ x,
370
+ y
371
+ ]);
372
+ const hasBeenPositioned = React.useRef(false);
373
+ const lastGoodPosition = React.useRef({
374
+ x: 0,
375
+ y: 0
376
+ });
377
+ if (x !== 0 || y !== 0) {
378
+ lastGoodPosition.current = {
379
+ x,
380
+ y
381
+ };
382
+ if (isPositioned) hasBeenPositioned.current = true;
383
+ }
384
+ const brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
385
+ const effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
386
+ const effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
387
+ const hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
388
+ const disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
389
+ const [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
390
+ React.useEffect(() => {
391
+ setDisableAnimation(disableAnimationProp);
392
+ }, [disableAnimationProp]);
393
+ const frameProps = {
394
+ ref: contentRefs,
395
+ ...hide ? {} : {
396
+ x: effectiveX || 0,
397
+ y: effectiveY || 0
398
+ },
399
+ top: 0,
400
+ left: 0,
401
+ position: strategy,
402
+ opacity: hide ? 0 : 1,
403
+ ...isAnimatePosControlled && {
404
+ transition: animatePos ? rest.transition : void 0,
405
+ animateOnly: animatePos && !disableAnimation ? rest.animateOnly : [],
406
+ animatePresence: false
407
+ }
408
+ };
409
+ const { style, ...floatingProps } = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
410
+ const transformOriginStyle = import_constants.isWeb && transformOrigin ? { transformOrigin: `${transformOrigin.x} ${transformOrigin.y}` } : void 0;
411
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
412
+ disable: !context.open,
413
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
414
+ passThrough,
415
+ ref: contentRefs,
416
+ direction: rest.direction,
417
+ ...passThrough ? null : floatingProps,
418
+ ...!passThrough && animatePos && { "data-popper-animate-position": "true" },
419
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperContentFrame, {
420
+ passThrough,
421
+ ...!passThrough && {
422
+ "data-placement": placement,
423
+ "data-strategy": strategy,
424
+ ...style,
425
+ ...transformOriginStyle,
426
+ ...rest
427
+ },
428
+ children
429
+ }, "popper-content-frame")
430
+ })
431
+ });
409
432
  });
410
- const PopperContent = React.forwardRef(function PopperContent2(props, forwardedRef) {
411
- const isAnimatePosControlled = "animatePosition" in props || "enableAnimationForPositionChange" in props;
412
- const {
413
- scope,
414
- animatePosition,
415
- enableAnimationForPositionChange,
416
- children,
417
- passThrough,
418
- unstyled,
419
- ...rest
420
- } = props;
421
- const animatePos = animatePosition ?? enableAnimationForPositionChange;
422
- const context = usePopperContext(scope);
423
- const {
424
- strategy,
425
- placement,
426
- refs,
427
- x,
428
- y,
429
- getFloatingProps,
430
- size,
431
- isPositioned,
432
- transformOrigin,
433
- update
434
- } = context;
435
- const updateRef = React.useRef(update);
436
- updateRef.current = update;
437
- const lastNodeRef = React.useRef(null);
438
- const safeSetFloating = React.useCallback(node => {
439
- const isNewNode = node !== lastNodeRef.current;
440
- if (node) {
441
- lastNodeRef.current = node;
442
- refs.setFloating(node);
443
- if (!isNewNode) updateRef.current?.();
444
- }
445
- }, [refs.setFloating]);
446
- React.useEffect(() => {
447
- return () => {
448
- const ourNode = lastNodeRef.current;
449
- if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
450
- lastNodeRef.current = null;
451
- };
452
- }, []);
453
- const contentRefs = (0, import_compose_refs.useComposedRefs)(safeSetFloating, forwardedRef);
454
- const [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
455
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
456
- if (needsMeasure && x && y) setNeedsMeasure(false);
457
- }, [needsMeasure, animatePos, x, y]);
458
- const hasBeenPositioned = React.useRef(false);
459
- const lastGoodPosition = React.useRef({
460
- x: 0,
461
- y: 0
462
- });
463
- if (x !== 0 || y !== 0) {
464
- lastGoodPosition.current = {
465
- x,
466
- y
467
- };
468
- if (isPositioned) hasBeenPositioned.current = true;
469
- }
470
- const brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
471
- const effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
472
- const effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
473
- const hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
474
- const disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
475
- const [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
476
- React.useEffect(() => {
477
- setDisableAnimation(disableAnimationProp);
478
- }, [disableAnimationProp]);
479
- const frameProps = {
480
- ref: contentRefs,
481
- ...(hide ? {} : {
482
- x: effectiveX || 0,
483
- y: effectiveY || 0
484
- }),
485
- top: 0,
486
- left: 0,
487
- position: strategy,
488
- opacity: hide ? 0 : 1,
489
- ...(isAnimatePosControlled && {
490
- transition: animatePos ? rest.transition : void 0,
491
- animateOnly: animatePos && !disableAnimation ? rest.animateOnly : [],
492
- animatePresence: false
493
- })
494
- };
495
- const {
496
- style,
497
- ...floatingProps
498
- } = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
499
- const transformOriginStyle = import_constants.isWeb && transformOrigin ? {
500
- transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
501
- } : void 0;
502
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
503
- disable: !context.open,
504
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
505
- passThrough,
506
- ref: contentRefs,
507
- direction: rest.direction,
508
- ...(passThrough ? null : floatingProps),
509
- ...(!passThrough && animatePos && {
510
- "data-popper-animate-position": "true"
511
- }),
512
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperContentFrame, {
513
- passThrough,
514
- unstyled,
515
- ...(!passThrough && {
516
- "data-placement": placement,
517
- "data-strategy": strategy,
518
- size,
519
- ...style,
520
- ...transformOriginStyle,
521
- ...rest
522
- }),
523
- children
524
- }, "popper-content-frame")
525
- })
526
- });
433
+ const PopperArrowFrame = (0, import_core.styled)(import_core.View, {
434
+ displayName: "PopperArrow",
435
+ position: "relative"
527
436
  });
528
- const PopperArrowFrame = (0, import_core.styled)(import_stacks.YStack, {
529
- name: "PopperArrow",
530
- variants: {
531
- unstyled: {
532
- false: {
533
- borderColor: "$borderColor",
534
- backgroundColor: "$background",
535
- position: "relative"
536
- }
537
- }
538
- },
539
- defaultVariants: {
540
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
541
- }
542
- });
543
- const PopperArrowOuterFrame = (0, import_core.styled)(import_stacks.YStack, {
544
- name: "PopperArrowOuter",
545
- variants: {
546
- unstyled: {
547
- false: {
548
- position: "absolute",
549
- zIndex: 1e6,
550
- pointerEvents: "none",
551
- overflow: "hidden",
552
- alignItems: "center",
553
- justifyContent: "center"
554
- }
555
- }
556
- },
557
- defaultVariants: {
558
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
559
- }
437
+ const PopperArrowOuterFrame = (0, import_core.styled)(import_core.View, {
438
+ displayName: "PopperArrowOuter",
439
+ position: "absolute",
440
+ zIndex: 1e6,
441
+ pointerEvents: "none",
442
+ overflow: "hidden",
443
+ alignItems: "center",
444
+ justifyContent: "center"
560
445
  });
561
446
  const opposites = {
562
- top: "bottom",
563
- right: "left",
564
- bottom: "top",
565
- left: "right"
447
+ top: "bottom",
448
+ right: "left",
449
+ bottom: "top",
450
+ left: "right"
566
451
  };
567
- const PopperArrow = React.forwardRef(function PopperArrow2(propsIn, forwardedRef) {
568
- const isAnimatePosControlled = "animatePosition" in propsIn;
569
- const {
570
- scope,
571
- animatePosition,
572
- transition,
573
- ...rest
574
- } = propsIn;
575
- const {
576
- offset,
577
- size: sizeProp,
578
- borderWidth = 0,
579
- ...arrowProps
580
- } = rest;
581
- const context = usePopperContext(scope);
582
- const sizeVal = typeof sizeProp === "number" ? sizeProp : (0, import_core.getVariableValue)((0, import_get_token.getSpace)(sizeProp ?? context.size, {
583
- shift: -2,
584
- bounds: [2]
585
- }));
586
- const size = Math.max(0, +sizeVal);
587
- const {
588
- placement
589
- } = context;
590
- const refs = (0, import_compose_refs.useComposedRefs)(context.arrowRef, forwardedRef);
591
- const x = context.arrowStyle?.x || 0;
592
- const y = context.arrowStyle?.y || 0;
593
- const arrowPositioned = context.arrowStyle != null;
594
- const primaryPlacement = placement ? placement.split("-")[0] : "top";
595
- const arrowStyle = {
596
- x,
597
- y,
598
- width: size,
599
- height: size
600
- };
601
- const innerArrowStyle = {};
602
- const isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
603
- if (primaryPlacement) {
604
- arrowStyle[isVertical ? "width" : "height"] = size * 2;
605
- const oppSide = opposites[primaryPlacement];
606
- if (oppSide) {
607
- arrowStyle[oppSide] = -size;
608
- innerArrowStyle[oppSide] = size / 2;
609
- }
610
- if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
611
- if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
612
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
613
- context.onArrowSize?.(size);
614
- }, [size, context.onArrowSize]);
615
- }
616
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperArrowOuterFrame, {
617
- ref: refs,
618
- ...arrowStyle,
619
- ...(!arrowPositioned && {
620
- opacity: 0
621
- }),
622
- ...(isAnimatePosControlled && {
623
- transition: animatePosition ? transition : void 0,
624
- animateOnly: animatePosition ? ["transform"] : [],
625
- animatePresence: false
626
- }),
627
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperArrowFrame, {
628
- width: size,
629
- height: size,
630
- ...arrowProps,
631
- ...innerArrowStyle,
632
- rotate: "45deg",
633
- ...(primaryPlacement === "bottom" && {
634
- borderLeftWidth: borderWidth,
635
- borderTopWidth: borderWidth
636
- }),
637
- ...(primaryPlacement === "top" && {
638
- borderBottomWidth: borderWidth,
639
- borderRightWidth: borderWidth
640
- }),
641
- ...(primaryPlacement === "right" && {
642
- borderLeftWidth: borderWidth,
643
- borderBottomWidth: borderWidth
644
- }),
645
- ...(primaryPlacement === "left" && {
646
- borderTopWidth: borderWidth,
647
- borderRightWidth: borderWidth
648
- })
649
- })
650
- });
651
- });
452
+ const PopperArrow = (0, import_core.createRefComponent)(function PopperArrow2(propsIn, forwardedRef) {
453
+ const isAnimatePosControlled = "animatePosition" in propsIn;
454
+ const { scope, animatePosition, transition, ...rest } = propsIn;
455
+ const { offset, size: sizeProp, borderWidth = 0, ...arrowProps } = rest;
456
+ const context = usePopperContext(scope);
457
+ const sizeVal = typeof sizeProp === "number" ? sizeProp : (0, import_core.getVariableValue)((0, import_get_token.getSize)(sizeProp ?? context.size)) * .52 - 11.5;
458
+ const size = Math.max(0, +sizeVal);
459
+ const { placement } = context;
460
+ const refs = (0, import_compose_refs.useComposedRefs)(context.arrowRef, forwardedRef);
461
+ const x = context.arrowStyle?.x || 0;
462
+ const y = context.arrowStyle?.y || 0;
463
+ const arrowPositioned = context.arrowStyle != null;
464
+ const primaryPlacement = placement ? placement.split("-")[0] : "top";
465
+ const arrowStyle = {
466
+ x,
467
+ y,
468
+ width: size,
469
+ height: size
470
+ };
471
+ const innerArrowStyle = {};
472
+ const isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
473
+ if (primaryPlacement) {
474
+ arrowStyle[isVertical ? "width" : "height"] = size * 2;
475
+ const oppSide = opposites[primaryPlacement];
476
+ if (oppSide) {
477
+ arrowStyle[oppSide] = -size;
478
+ innerArrowStyle[oppSide] = size / 2;
479
+ }
480
+ if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
481
+ if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
482
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
483
+ context.onArrowSize?.(size);
484
+ }, [size, context.onArrowSize]);
485
+ }
486
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperArrowOuterFrame, {
487
+ ref: refs,
488
+ ...arrowStyle,
489
+ ...!arrowPositioned && { opacity: 0 },
490
+ ...isAnimatePosControlled && {
491
+ transition: animatePosition ? transition : void 0,
492
+ animateOnly: animatePosition ? ["transform"] : [],
493
+ animatePresence: false
494
+ },
495
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperArrowFrame, {
496
+ width: size,
497
+ height: size,
498
+ ...arrowProps,
499
+ ...innerArrowStyle,
500
+ rotate: "45deg",
501
+ ...primaryPlacement === "bottom" && {
502
+ borderLeftWidth: borderWidth,
503
+ borderTopWidth: borderWidth
504
+ },
505
+ ...primaryPlacement === "top" && {
506
+ borderBottomWidth: borderWidth,
507
+ borderRightWidth: borderWidth
508
+ },
509
+ ...primaryPlacement === "right" && {
510
+ borderLeftWidth: borderWidth,
511
+ borderBottomWidth: borderWidth
512
+ },
513
+ ...primaryPlacement === "left" && {
514
+ borderTopWidth: borderWidth,
515
+ borderRightWidth: borderWidth
516
+ }
517
+ })
518
+ });
519
+ });