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