@tamagui/create-menu 1.0.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.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/MenuPredefined.cjs +189 -0
  3. package/dist/cjs/MenuPredefined.js +168 -0
  4. package/dist/cjs/MenuPredefined.js.map +6 -0
  5. package/dist/cjs/MenuPredefined.native.js +192 -0
  6. package/dist/cjs/MenuPredefined.native.js.map +1 -0
  7. package/dist/cjs/createBaseMenu.cjs +1147 -0
  8. package/dist/cjs/createBaseMenu.js +884 -0
  9. package/dist/cjs/createBaseMenu.js.map +6 -0
  10. package/dist/cjs/createBaseMenu.native.js +1346 -0
  11. package/dist/cjs/createBaseMenu.native.js.map +1 -0
  12. package/dist/cjs/createNativeMenu/createNativeMenu.cjs +242 -0
  13. package/dist/cjs/createNativeMenu/createNativeMenu.js +184 -0
  14. package/dist/cjs/createNativeMenu/createNativeMenu.js.map +6 -0
  15. package/dist/cjs/createNativeMenu/createNativeMenu.native.js +307 -0
  16. package/dist/cjs/createNativeMenu/createNativeMenu.native.js.map +1 -0
  17. package/dist/cjs/createNativeMenu/createNativeMenuTypes.cjs +16 -0
  18. package/dist/cjs/createNativeMenu/createNativeMenuTypes.js +14 -0
  19. package/dist/cjs/createNativeMenu/createNativeMenuTypes.js.map +6 -0
  20. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.js +19 -0
  21. package/dist/cjs/createNativeMenu/createNativeMenuTypes.native.js.map +1 -0
  22. package/dist/cjs/createNativeMenu/utils.cjs +68 -0
  23. package/dist/cjs/createNativeMenu/utils.js +66 -0
  24. package/dist/cjs/createNativeMenu/utils.js.map +6 -0
  25. package/dist/cjs/createNativeMenu/utils.native.js +94 -0
  26. package/dist/cjs/createNativeMenu/utils.native.js.map +1 -0
  27. package/dist/cjs/createNativeMenu/withNativeMenu.cjs +37 -0
  28. package/dist/cjs/createNativeMenu/withNativeMenu.js +30 -0
  29. package/dist/cjs/createNativeMenu/withNativeMenu.js.map +6 -0
  30. package/dist/cjs/createNativeMenu/withNativeMenu.native.js +43 -0
  31. package/dist/cjs/createNativeMenu/withNativeMenu.native.js.map +1 -0
  32. package/dist/cjs/index.cjs +30 -0
  33. package/dist/cjs/index.js +24 -0
  34. package/dist/cjs/index.js.map +6 -0
  35. package/dist/cjs/index.native.js +33 -0
  36. package/dist/cjs/index.native.js.map +1 -0
  37. package/dist/esm/MenuPredefined.js +154 -0
  38. package/dist/esm/MenuPredefined.js.map +6 -0
  39. package/dist/esm/MenuPredefined.mjs +166 -0
  40. package/dist/esm/MenuPredefined.mjs.map +1 -0
  41. package/dist/esm/MenuPredefined.native.js +166 -0
  42. package/dist/esm/MenuPredefined.native.js.map +1 -0
  43. package/dist/esm/createBaseMenu.js +892 -0
  44. package/dist/esm/createBaseMenu.js.map +6 -0
  45. package/dist/esm/createBaseMenu.mjs +1113 -0
  46. package/dist/esm/createBaseMenu.mjs.map +1 -0
  47. package/dist/esm/createBaseMenu.native.js +1309 -0
  48. package/dist/esm/createBaseMenu.native.js.map +1 -0
  49. package/dist/esm/createNativeMenu/createNativeMenu.js +163 -0
  50. package/dist/esm/createNativeMenu/createNativeMenu.js.map +6 -0
  51. package/dist/esm/createNativeMenu/createNativeMenu.mjs +208 -0
  52. package/dist/esm/createNativeMenu/createNativeMenu.mjs.map +1 -0
  53. package/dist/esm/createNativeMenu/createNativeMenu.native.js +270 -0
  54. package/dist/esm/createNativeMenu/createNativeMenu.native.js.map +1 -0
  55. package/dist/esm/createNativeMenu/createNativeMenuTypes.js +1 -0
  56. package/dist/esm/createNativeMenu/createNativeMenuTypes.js.map +6 -0
  57. package/dist/esm/createNativeMenu/createNativeMenuTypes.mjs +2 -0
  58. package/dist/esm/createNativeMenu/createNativeMenuTypes.mjs.map +1 -0
  59. package/dist/esm/createNativeMenu/createNativeMenuTypes.native.js +2 -0
  60. package/dist/esm/createNativeMenu/createNativeMenuTypes.native.js.map +1 -0
  61. package/dist/esm/createNativeMenu/utils.js +47 -0
  62. package/dist/esm/createNativeMenu/utils.js.map +6 -0
  63. package/dist/esm/createNativeMenu/utils.mjs +29 -0
  64. package/dist/esm/createNativeMenu/utils.mjs.map +1 -0
  65. package/dist/esm/createNativeMenu/utils.native.js +52 -0
  66. package/dist/esm/createNativeMenu/utils.native.js.map +1 -0
  67. package/dist/esm/createNativeMenu/withNativeMenu.js +15 -0
  68. package/dist/esm/createNativeMenu/withNativeMenu.js.map +6 -0
  69. package/dist/esm/createNativeMenu/withNativeMenu.mjs +14 -0
  70. package/dist/esm/createNativeMenu/withNativeMenu.mjs.map +1 -0
  71. package/dist/esm/createNativeMenu/withNativeMenu.native.js +17 -0
  72. package/dist/esm/createNativeMenu/withNativeMenu.native.js.map +1 -0
  73. package/dist/esm/index.js +8 -0
  74. package/dist/esm/index.js.map +6 -0
  75. package/dist/esm/index.mjs +6 -0
  76. package/dist/esm/index.mjs.map +1 -0
  77. package/dist/esm/index.native.js +6 -0
  78. package/dist/esm/index.native.js.map +1 -0
  79. package/dist/jsx/MenuPredefined.js +154 -0
  80. package/dist/jsx/MenuPredefined.js.map +6 -0
  81. package/dist/jsx/MenuPredefined.mjs +166 -0
  82. package/dist/jsx/MenuPredefined.mjs.map +1 -0
  83. package/dist/jsx/MenuPredefined.native.js +192 -0
  84. package/dist/jsx/MenuPredefined.native.js.map +1 -0
  85. package/dist/jsx/createBaseMenu.js +892 -0
  86. package/dist/jsx/createBaseMenu.js.map +6 -0
  87. package/dist/jsx/createBaseMenu.mjs +1113 -0
  88. package/dist/jsx/createBaseMenu.mjs.map +1 -0
  89. package/dist/jsx/createBaseMenu.native.js +1346 -0
  90. package/dist/jsx/createBaseMenu.native.js.map +1 -0
  91. package/dist/jsx/createNativeMenu/createNativeMenu.js +163 -0
  92. package/dist/jsx/createNativeMenu/createNativeMenu.js.map +6 -0
  93. package/dist/jsx/createNativeMenu/createNativeMenu.mjs +208 -0
  94. package/dist/jsx/createNativeMenu/createNativeMenu.mjs.map +1 -0
  95. package/dist/jsx/createNativeMenu/createNativeMenu.native.js +307 -0
  96. package/dist/jsx/createNativeMenu/createNativeMenu.native.js.map +1 -0
  97. package/dist/jsx/createNativeMenu/createNativeMenuTypes.js +1 -0
  98. package/dist/jsx/createNativeMenu/createNativeMenuTypes.js.map +6 -0
  99. package/dist/jsx/createNativeMenu/createNativeMenuTypes.mjs +2 -0
  100. package/dist/jsx/createNativeMenu/createNativeMenuTypes.mjs.map +1 -0
  101. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.js +19 -0
  102. package/dist/jsx/createNativeMenu/createNativeMenuTypes.native.js.map +1 -0
  103. package/dist/jsx/createNativeMenu/utils.js +47 -0
  104. package/dist/jsx/createNativeMenu/utils.js.map +6 -0
  105. package/dist/jsx/createNativeMenu/utils.mjs +29 -0
  106. package/dist/jsx/createNativeMenu/utils.mjs.map +1 -0
  107. package/dist/jsx/createNativeMenu/utils.native.js +94 -0
  108. package/dist/jsx/createNativeMenu/utils.native.js.map +1 -0
  109. package/dist/jsx/createNativeMenu/withNativeMenu.js +15 -0
  110. package/dist/jsx/createNativeMenu/withNativeMenu.js.map +6 -0
  111. package/dist/jsx/createNativeMenu/withNativeMenu.mjs +14 -0
  112. package/dist/jsx/createNativeMenu/withNativeMenu.mjs.map +1 -0
  113. package/dist/jsx/createNativeMenu/withNativeMenu.native.js +43 -0
  114. package/dist/jsx/createNativeMenu/withNativeMenu.native.js.map +1 -0
  115. package/dist/jsx/index.js +8 -0
  116. package/dist/jsx/index.js.map +6 -0
  117. package/dist/jsx/index.mjs +6 -0
  118. package/dist/jsx/index.mjs.map +1 -0
  119. package/dist/jsx/index.native.js +33 -0
  120. package/dist/jsx/index.native.js.map +1 -0
  121. package/package.json +69 -0
  122. package/src/MenuPredefined.tsx +204 -0
  123. package/src/createBaseMenu.tsx +2031 -0
  124. package/src/createNativeMenu/createNativeMenu.tsx +400 -0
  125. package/src/createNativeMenu/createNativeMenuTypes.ts +214 -0
  126. package/src/createNativeMenu/utils.tsx +150 -0
  127. package/src/createNativeMenu/withNativeMenu.tsx +39 -0
  128. package/src/index.tsx +5 -0
  129. package/types/MenuPredefined.d.ts +31 -0
  130. package/types/MenuPredefined.d.ts.map +1 -0
  131. package/types/createBaseMenu.d.ts +298 -0
  132. package/types/createBaseMenu.d.ts.map +1 -0
  133. package/types/createNativeMenu/createNativeMenu.d.ts +42 -0
  134. package/types/createNativeMenu/createNativeMenu.d.ts.map +1 -0
  135. package/types/createNativeMenu/createNativeMenuTypes.d.ts +188 -0
  136. package/types/createNativeMenu/createNativeMenuTypes.d.ts.map +1 -0
  137. package/types/createNativeMenu/index.d.ts +4 -0
  138. package/types/createNativeMenu/utils.d.ts +38 -0
  139. package/types/createNativeMenu/utils.d.ts.map +1 -0
  140. package/types/createNativeMenu/withNativeMenu.d.ts +9 -0
  141. package/types/createNativeMenu/withNativeMenu.d.ts.map +1 -0
  142. package/types/index.d.ts +6 -0
  143. package/types/index.d.ts.map +1 -0
@@ -0,0 +1,1346 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ };
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: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var createBaseMenu_exports = {};
35
+ __export(createBaseMenu_exports, {
36
+ createBaseMenu: () => createBaseMenu
37
+ });
38
+ module.exports = __toCommonJS(createBaseMenu_exports);
39
+ var import_jsx_runtime = require("react/jsx-runtime"),
40
+ import_animate = require("@tamagui/animate"),
41
+ import_animate_presence = require("@tamagui/animate-presence"),
42
+ import_collection = require("@tamagui/collection"),
43
+ import_dismissable = require("@tamagui/dismissable"),
44
+ import_focus_guard = require("@tamagui/focus-guard"),
45
+ import_focus_scope = require("@tamagui/focus-scope"),
46
+ PopperPrimitive = __toESM(require("@tamagui/popper"), 1),
47
+ import_portal = require("@tamagui/portal"),
48
+ import_remove_scroll = require("@tamagui/remove-scroll"),
49
+ import_roving_focus = require("@tamagui/roving-focus"),
50
+ import_use_callback_ref = require("@tamagui/use-callback-ref"),
51
+ import_use_direction = require("@tamagui/use-direction"),
52
+ import_web = require("@tamagui/web"),
53
+ React = __toESM(require("react"), 1),
54
+ import_react = require("react"),
55
+ import_MenuPredefined = require("./MenuPredefined.native.js");
56
+ function _type_of(obj) {
57
+ "@swc/helpers - typeof";
58
+
59
+ return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
60
+ }
61
+ function whenMouse(handler) {
62
+ return function (event) {
63
+ return event.pointerType === "mouse" ? handler(event) : void 0;
64
+ };
65
+ }
66
+ var SELECTION_KEYS = ["Enter", " "],
67
+ FIRST_KEYS = ["ArrowDown", "PageUp", "Home"],
68
+ LAST_KEYS = ["ArrowUp", "PageDown", "End"],
69
+ FIRST_LAST_KEYS = [...FIRST_KEYS, ...LAST_KEYS],
70
+ SUB_OPEN_KEYS = {
71
+ ltr: [...SELECTION_KEYS, "ArrowRight"],
72
+ rtl: [...SELECTION_KEYS, "ArrowLeft"]
73
+ },
74
+ SUB_CLOSE_KEYS = {
75
+ ltr: ["ArrowLeft"],
76
+ rtl: ["ArrowRight"]
77
+ },
78
+ MENU_NAME = "Menu",
79
+ [Collection, useCollection] = (0, import_collection.createCollection)(MENU_NAME),
80
+ {
81
+ Provider: MenuProvider,
82
+ useStyledContext: useMenuContext
83
+ } = (0, import_web.createStyledContext)(),
84
+ {
85
+ Provider: MenuRootProvider,
86
+ useStyledContext: useMenuRootContext
87
+ } = (0, import_web.createStyledContext)(),
88
+ MENU_CONTEXT = "MenuContext";
89
+ function createBaseMenu(param) {
90
+ var {
91
+ Item: _Item = import_MenuPredefined.MenuPredefined.MenuItem,
92
+ Title: _Title = import_MenuPredefined.MenuPredefined.Title,
93
+ SubTitle: _SubTitle = import_MenuPredefined.MenuPredefined.SubTitle,
94
+ Image: _Image = import_MenuPredefined.MenuPredefined.MenuImage,
95
+ Icon: _Icon = import_MenuPredefined.MenuPredefined.MenuIcon,
96
+ Indicator: _Indicator = import_MenuPredefined.MenuPredefined.MenuIndicator,
97
+ Separator: _Separator = import_MenuPredefined.MenuPredefined.MenuSeparator,
98
+ MenuGroup: _MenuGroup = import_MenuPredefined.MenuPredefined.MenuGroup,
99
+ Label: _Label = import_MenuPredefined.MenuPredefined.MenuLabel
100
+ } = param,
101
+ MenuComp = function (props) {
102
+ var direction = (0, import_use_direction.useDirection)(props.dir),
103
+ defaultPlacement = direction === "rtl" ? "bottom-end" : "bottom-start",
104
+ {
105
+ scope = MENU_CONTEXT,
106
+ open = !1,
107
+ children,
108
+ dir,
109
+ onOpenChange,
110
+ modal = !0,
111
+ allowFlip = {
112
+ padding: 10
113
+ },
114
+ stayInFrame = {
115
+ padding: 10
116
+ },
117
+ placement = defaultPlacement,
118
+ resize = !0,
119
+ offset = 10,
120
+ ...rest
121
+ } = props,
122
+ [content, setContent] = React.useState(null),
123
+ isUsingKeyboardRef = React.useRef(!1),
124
+ handleOpenChange = (0, import_use_callback_ref.useCallbackRef)(onOpenChange);
125
+ return import_web.isWeb && React.useEffect(function () {
126
+ var handleKeyDown = function () {
127
+ isUsingKeyboardRef.current = !0, document.addEventListener("pointerdown", handlePointer, {
128
+ capture: !0,
129
+ once: !0
130
+ }), document.addEventListener("pointermove", handlePointer, {
131
+ capture: !0,
132
+ once: !0
133
+ });
134
+ },
135
+ handlePointer = function () {
136
+ return isUsingKeyboardRef.current = !1;
137
+ };
138
+ return document.addEventListener("keydown", handleKeyDown, {
139
+ capture: !0
140
+ }), function () {
141
+ document.removeEventListener("keydown", handleKeyDown, {
142
+ capture: !0
143
+ }), document.removeEventListener("pointerdown", handlePointer, {
144
+ capture: !0
145
+ }), document.removeEventListener("pointermove", handlePointer, {
146
+ capture: !0
147
+ });
148
+ };
149
+ }, []), /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.Popper, {
150
+ scope,
151
+ open,
152
+ placement,
153
+ allowFlip,
154
+ stayInFrame,
155
+ resize,
156
+ offset,
157
+ ...rest,
158
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuProvider, {
159
+ scope,
160
+ open,
161
+ onOpenChange: handleOpenChange,
162
+ content,
163
+ onContentChange: setContent,
164
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootProvider, {
165
+ scope,
166
+ open,
167
+ onClose: React.useCallback(function () {
168
+ return handleOpenChange(!1);
169
+ }, [handleOpenChange]),
170
+ isUsingKeyboardRef,
171
+ dir: direction,
172
+ modal,
173
+ children: (/** this provider is just to avoid crashing when using useSubMenuContext() inside MenuPortal */
174
+ /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuSubProvider, {
175
+ scope,
176
+ children
177
+ }))
178
+ })
179
+ })
180
+ });
181
+ },
182
+ RepropagateMenuAndMenuRootProvider = function (props) {
183
+ var {
184
+ scope = MENU_CONTEXT,
185
+ menuContext,
186
+ rootContext,
187
+ popperContext,
188
+ menuSubContext,
189
+ children
190
+ } = props;
191
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperProvider, {
192
+ ...popperContext,
193
+ scope,
194
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuProvider, {
195
+ scope,
196
+ ...menuContext,
197
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootProvider, {
198
+ scope,
199
+ ...rootContext,
200
+ children: menuSubContext ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuSubProvider, {
201
+ scope,
202
+ ...menuSubContext,
203
+ children
204
+ }) : children
205
+ })
206
+ })
207
+ });
208
+ };
209
+ MenuComp.displayName = MENU_NAME;
210
+ var ANCHOR_NAME = "MenuAnchor",
211
+ MenuAnchor = function (props) {
212
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperAnchor, {
213
+ scope: MENU_CONTEXT,
214
+ ...props
215
+ });
216
+ };
217
+ MenuAnchor.displayName = ANCHOR_NAME;
218
+ var PORTAL_NAME = "MenuPortal",
219
+ {
220
+ Provider: PortalProvider,
221
+ useStyledContext: usePortalContext
222
+ } = (0, import_web.createStyledContext)(void 0, "Portal"),
223
+ MenuPortal = function (props) {
224
+ var {
225
+ scope = MENU_CONTEXT,
226
+ forceMount,
227
+ zIndex,
228
+ children
229
+ } = props,
230
+ menuContext = useMenuContext(scope),
231
+ rootContext = useMenuRootContext(scope),
232
+ popperContext = PopperPrimitive.usePopperContext(scope),
233
+ menuSubContext = useMenuSubContext(scope),
234
+ themeName = (0, import_web.useThemeName)(),
235
+ themedChildren = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_web.Theme, {
236
+ forceClassName: !0,
237
+ name: themeName,
238
+ children
239
+ }),
240
+ content = (0, import_portal.needsPortalRepropagation)() ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(RepropagateMenuAndMenuRootProvider, {
241
+ menuContext,
242
+ rootContext,
243
+ popperContext,
244
+ menuSubContext,
245
+ scope,
246
+ children: themedChildren
247
+ }) : themedChildren,
248
+ isPresent = forceMount || rootContext.open && menuContext.open;
249
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate.Animate, {
250
+ type: "presence",
251
+ present: isPresent,
252
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
253
+ stackZIndex: !0,
254
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
255
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PortalProvider, {
256
+ scope,
257
+ forceMount,
258
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_web.View, {
259
+ zIndex: zIndex || 100,
260
+ inset: 0,
261
+ position: "absolute",
262
+ children: [!!menuContext.open && !import_web.isWeb && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_web.View, {
263
+ inset: 0,
264
+ position: "absolute",
265
+ onPress: function () {
266
+ return menuContext.onOpenChange(!menuContext.open);
267
+ }
268
+ }), content]
269
+ })
270
+ })
271
+ })
272
+ })
273
+ });
274
+ };
275
+ MenuPortal.displayName = PORTAL_NAME;
276
+ var CONTENT_NAME = "MenuContent",
277
+ {
278
+ Provider: MenuContentProvider,
279
+ useStyledContext: useMenuContentContext
280
+ } = (0, import_web.createStyledContext)(),
281
+ MenuContentFrame = (0, import_web.styled)(PopperPrimitive.PopperContentFrame, {
282
+ name: CONTENT_NAME
283
+ }),
284
+ MenuContent = MenuContentFrame.styleable(function (props, forwardedRef) {
285
+ var scope = props.scope || MENU_CONTEXT,
286
+ portalContext = usePortalContext(scope),
287
+ {
288
+ forceMount = portalContext.forceMount,
289
+ ...contentProps
290
+ } = props,
291
+ rootContext = useMenuRootContext(scope);
292
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
293
+ scope,
294
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Slot, {
295
+ scope,
296
+ children: rootContext.modal ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootContentModal, {
297
+ ...contentProps,
298
+ ref: forwardedRef
299
+ }) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuRootContentNonModal, {
300
+ ...contentProps,
301
+ ref: forwardedRef
302
+ })
303
+ })
304
+ });
305
+ }),
306
+ MenuRootContentModal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
307
+ var scope = props.scope || MENU_CONTEXT,
308
+ context = useMenuContext(scope),
309
+ ref = React.useRef(null),
310
+ composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref);
311
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentImpl, {
312
+ ...props,
313
+ scope,
314
+ ref: composedRefs,
315
+ // we make sure we're not trapping once it's been closed
316
+ // (closed !== unmounted when animating out)
317
+ trapFocus: context.open,
318
+ // make sure to only disable pointer events when open
319
+ // this avoids blocking interactions while animating out
320
+ disableOutsidePointerEvents: context.open,
321
+ disableOutsideScroll: !1,
322
+ // When focus is trapped, a `focusout` event may still happen.
323
+ // We make sure we don't trigger our `onDismiss` in such case.
324
+ onFocusOutside: (0, import_web.composeEventHandlers)(props.onFocusOutside, function (event) {
325
+ return event.preventDefault();
326
+ }, {
327
+ checkDefaultPrevented: !1
328
+ }),
329
+ onDismiss: function () {
330
+ return context.onOpenChange(!1);
331
+ }
332
+ });
333
+ }),
334
+ MenuRootContentNonModal = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
335
+ var scope = props.scope || MENU_CONTEXT,
336
+ context = useMenuContext(scope);
337
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentImpl, {
338
+ ...props,
339
+ scope,
340
+ ref: forwardedRef,
341
+ trapFocus: !1,
342
+ disableOutsidePointerEvents: !1,
343
+ disableOutsideScroll: !1,
344
+ onDismiss: function () {
345
+ return context.onOpenChange(!1);
346
+ }
347
+ });
348
+ }),
349
+ MenuContentImpl = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
350
+ var {
351
+ scope = MENU_CONTEXT,
352
+ loop = !1,
353
+ trapFocus,
354
+ onOpenAutoFocus,
355
+ onCloseAutoFocus,
356
+ disableOutsidePointerEvents,
357
+ onEntryFocus,
358
+ onEscapeKeyDown,
359
+ onPointerDownOutside,
360
+ onFocusOutside,
361
+ onInteractOutside,
362
+ onDismiss,
363
+ disableOutsideScroll,
364
+ disableDismissOnScroll = !1,
365
+ unstyled = process.env.TAMAGUI_HEADLESS === "1",
366
+ ...contentProps
367
+ } = props,
368
+ context = useMenuContext(scope),
369
+ rootContext = useMenuRootContext(scope),
370
+ getItems = useCollection(scope),
371
+ [currentItemId, setCurrentItemId] = React.useState(null),
372
+ contentRef = React.useRef(null),
373
+ focusableContentRef = React.useRef(null),
374
+ composedRefs = (0, import_web.useComposedRefs)(forwardedRef, contentRef, context.onContentChange),
375
+ timerRef = React.useRef(0),
376
+ searchRef = React.useRef(""),
377
+ pointerGraceTimerRef = React.useRef(0),
378
+ pointerGraceIntentRef = React.useRef(null),
379
+ pointerDirRef = React.useRef("right"),
380
+ lastPointerXRef = React.useRef(0),
381
+ handleTypeaheadSearch = function (key) {
382
+ var _items_find,
383
+ _items_find1,
384
+ search = searchRef.current + key,
385
+ items = getItems().filter(function (item) {
386
+ return !item.disabled;
387
+ }),
388
+ currentItem = document.activeElement,
389
+ currentMatch = (_items_find = items.find(function (item) {
390
+ return item.ref.current === currentItem;
391
+ })) === null || _items_find === void 0 ? void 0 : _items_find.textValue,
392
+ values = items.map(function (item) {
393
+ return item.textValue;
394
+ }),
395
+ nextMatch = getNextMatch(values, search, currentMatch),
396
+ newItem = (_items_find1 = items.find(function (item) {
397
+ return item.textValue === nextMatch;
398
+ })) === null || _items_find1 === void 0 ? void 0 : _items_find1.ref.current;
399
+ (function updateSearch(value) {
400
+ searchRef.current = value, clearTimeout(timerRef.current), value !== "" && (timerRef.current = setTimeout(function () {
401
+ return updateSearch("");
402
+ }, 1e3));
403
+ })(search), newItem && setTimeout(function () {
404
+ return newItem.focus();
405
+ });
406
+ };
407
+ React.useEffect(function () {
408
+ return function () {
409
+ return clearTimeout(timerRef.current);
410
+ };
411
+ }, []), React.useEffect(function () {
412
+ if (!(!import_web.isWeb || !context.open)) {
413
+ var frame = requestAnimationFrame(function () {
414
+ var container = contentRef.current,
415
+ el = container?.querySelector("[data-tamagui-menu-content]");
416
+ el && (focusableContentRef.current = el);
417
+ });
418
+ return function () {
419
+ return cancelAnimationFrame(frame);
420
+ };
421
+ }
422
+ }, [context.open]), React.useEffect(function () {
423
+ if (!(!import_web.isWeb || disableDismissOnScroll || !context.open)) {
424
+ var handleScroll = function (event) {
425
+ var _contentRef_current,
426
+ target = event.target;
427
+ !((_contentRef_current = contentRef.current) === null || _contentRef_current === void 0) && _contentRef_current.contains(target) || onDismiss?.();
428
+ };
429
+ return window.addEventListener("scroll", handleScroll, {
430
+ capture: !0,
431
+ passive: !0
432
+ }), function () {
433
+ window.removeEventListener("scroll", handleScroll, {
434
+ capture: !0
435
+ });
436
+ };
437
+ }
438
+ }, [disableDismissOnScroll, context.open, onDismiss]), import_web.isWeb && (0, import_focus_guard.useFocusGuards)();
439
+ var isPointerMovingToSubmenu = React.useCallback(function (event) {
440
+ var _pointerGraceIntentRef_current,
441
+ _pointerGraceIntentRef_current1,
442
+ isMovingTowards = pointerDirRef.current === ((_pointerGraceIntentRef_current = pointerGraceIntentRef.current) === null || _pointerGraceIntentRef_current === void 0 ? void 0 : _pointerGraceIntentRef_current.side),
443
+ inArea = isPointerInGraceArea(event, (_pointerGraceIntentRef_current1 = pointerGraceIntentRef.current) === null || _pointerGraceIntentRef_current1 === void 0 ? void 0 : _pointerGraceIntentRef_current1.area);
444
+ return isMovingTowards && inArea;
445
+ }, []),
446
+ content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperContent, {
447
+ role: "menu",
448
+ // tabIndex allows the content to be focusable so that onItemLeave can
449
+ // focus the content frame and properly blur the previously focused item
450
+ tabIndex: -1,
451
+ unstyled,
452
+ ...(!unstyled && {
453
+ backgroundColor: "$background",
454
+ borderWidth: 1,
455
+ borderColor: "$borderColor",
456
+ outlineWidth: 0,
457
+ minWidth: 180
458
+ }),
459
+ "aria-orientation": "vertical",
460
+ "data-state": getOpenState(context.open),
461
+ "data-tamagui-menu-content": "",
462
+ // TODO
463
+ // @ts-ignore
464
+ dir: rootContext.dir,
465
+ scope: scope || MENU_CONTEXT,
466
+ ...contentProps,
467
+ ref: composedRefs,
468
+ className: contentProps.transition ? void 0 : contentProps.className,
469
+ ...(import_web.isWeb ? {
470
+ onKeyDown: (0, import_web.composeEventHandlers)(contentProps.onKeyDown, function (event) {
471
+ var target = event.target,
472
+ isKeyDownInside = target.closest("[data-tamagui-menu-content]") === event.currentTarget,
473
+ isModifierKey = event.ctrlKey || event.altKey || event.metaKey,
474
+ isCharacterKey = event.key.length === 1;
475
+ isKeyDownInside && (event.key === "Tab" && event.preventDefault(), !isModifierKey && isCharacterKey && handleTypeaheadSearch(event.key));
476
+ var isOnContentFrame = event.target.hasAttribute("data-tamagui-menu-content");
477
+ if (!(!isKeyDownInside || !isOnContentFrame) && FIRST_LAST_KEYS.includes(event.key)) {
478
+ event.preventDefault();
479
+ var items = getItems().filter(function (item) {
480
+ return !item.disabled;
481
+ }),
482
+ candidateNodes = items.map(function (item) {
483
+ return item.ref.current;
484
+ });
485
+ LAST_KEYS.includes(event.key) && candidateNodes.reverse(), focusFirst(candidateNodes, {
486
+ focusVisible: !0
487
+ });
488
+ }
489
+ }),
490
+ // TODO
491
+ // @ts-ignore
492
+ onBlur: (0, import_web.composeEventHandlers)(props.onBlur, function (event) {
493
+ var _event_currentTarget;
494
+ !((_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0) && _event_currentTarget.contains(event.target) || (clearTimeout(timerRef.current), searchRef.current = "");
495
+ }),
496
+ // TODO
497
+ onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, function (event) {
498
+ var _event_currentTarget;
499
+ if (event.pointerType === "mouse") {
500
+ var target = event.target,
501
+ pointerXHasChanged = lastPointerXRef.current !== event.clientX;
502
+ if (!((_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0) && _event_currentTarget.contains(target) && pointerXHasChanged) {
503
+ var newDir = event.clientX > lastPointerXRef.current ? "right" : "left";
504
+ pointerDirRef.current = newDir, lastPointerXRef.current = event.clientX;
505
+ }
506
+ }
507
+ })
508
+ } : {})
509
+ });
510
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentProvider, {
511
+ scope,
512
+ searchRef,
513
+ onItemEnter: React.useCallback(function (event) {
514
+ isPointerMovingToSubmenu(event) && event.preventDefault();
515
+ }, [isPointerMovingToSubmenu]),
516
+ onItemLeave: React.useCallback(function (event) {
517
+ var _focusableContentRef_current;
518
+ isPointerMovingToSubmenu(event) || ((_focusableContentRef_current = focusableContentRef.current) === null || _focusableContentRef_current === void 0 || _focusableContentRef_current.focus(), setCurrentItemId(null));
519
+ }, [isPointerMovingToSubmenu]),
520
+ onTriggerLeave: React.useCallback(function (event) {
521
+ isPointerMovingToSubmenu(event) && event.preventDefault();
522
+ }, [isPointerMovingToSubmenu]),
523
+ pointerGraceTimerRef,
524
+ onPointerGraceIntentChange: React.useCallback(function (intent) {
525
+ pointerGraceIntentRef.current = intent;
526
+ }, []),
527
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_remove_scroll.RemoveScroll, {
528
+ enabled: disableOutsideScroll,
529
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_focus_scope.FocusScope, {
530
+ asChild: !1,
531
+ trapped: trapFocus,
532
+ onMountAutoFocus: (0, import_web.composeEventHandlers)(onOpenAutoFocus, function (event) {
533
+ event.preventDefault();
534
+ var content2 = document.querySelector("[data-tamagui-menu-content]");
535
+ content2?.focus({
536
+ preventScroll: !0
537
+ });
538
+ }),
539
+ onUnmountAutoFocus: onCloseAutoFocus,
540
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
541
+ disableOutsidePointerEvents,
542
+ onEscapeKeyDown,
543
+ onPointerDownOutside,
544
+ onFocusOutside,
545
+ onInteractOutside,
546
+ onDismiss,
547
+ asChild: !0,
548
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup, {
549
+ asChild: !0,
550
+ __scopeRovingFocusGroup: scope || MENU_CONTEXT,
551
+ dir: rootContext.dir,
552
+ orientation: "vertical",
553
+ loop,
554
+ currentTabStopId: currentItemId,
555
+ onCurrentTabStopIdChange: setCurrentItemId,
556
+ onEntryFocus: (0, import_web.composeEventHandlers)(onEntryFocus, function (event) {
557
+ rootContext.isUsingKeyboardRef.current || event.preventDefault();
558
+ }),
559
+ children: content
560
+ })
561
+ })
562
+ })
563
+ })
564
+ });
565
+ });
566
+ MenuContent.displayName = CONTENT_NAME;
567
+ var ITEM_NAME = "MenuItem",
568
+ ITEM_SELECT = "menu.itemSelect",
569
+ MenuItem = _Item.styleable(function (props, forwardedRef) {
570
+ var {
571
+ disabled = !1,
572
+ onSelect,
573
+ preventCloseOnSelect,
574
+ children,
575
+ scope = MENU_CONTEXT,
576
+ // filter out native-only props that shouldn't reach the DOM
577
+ // @ts-ignore
578
+ destructive,
579
+ // @ts-ignore
580
+ hidden,
581
+ // @ts-ignore
582
+ androidIconName,
583
+ // @ts-ignore
584
+ iosIconName,
585
+ ...itemProps
586
+ } = props,
587
+ ref = React.useRef(null),
588
+ rootContext = useMenuRootContext(scope),
589
+ contentContext = useMenuContentContext(scope),
590
+ composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref),
591
+ isPointerDownRef = React.useRef(!1),
592
+ handleSelect = function () {
593
+ var menuItem = ref.current;
594
+ if (!disabled && menuItem) if (import_web.isWeb) {
595
+ var menuItemEl = menuItem,
596
+ itemSelectEvent = new CustomEvent(ITEM_SELECT, {
597
+ bubbles: !0,
598
+ cancelable: !0
599
+ });
600
+ menuItemEl.addEventListener(ITEM_SELECT, function (event) {
601
+ return onSelect?.(event);
602
+ }, {
603
+ once: !0
604
+ }), (0, import_dismissable.dispatchDiscreteCustomEvent)(menuItemEl, itemSelectEvent), itemSelectEvent.defaultPrevented || preventCloseOnSelect ? isPointerDownRef.current = !1 : rootContext.onClose();
605
+ } else onSelect?.({
606
+ target: menuItem
607
+ }), isPointerDownRef.current = !1, preventCloseOnSelect || rootContext.onClose();
608
+ },
609
+ content = typeof children == "string" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_web.Text, {
610
+ children
611
+ }) : children;
612
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItemImpl, {
613
+ outlineStyle: "none",
614
+ ...itemProps,
615
+ scope,
616
+ // @ts-ignore
617
+ ref: composedRefs,
618
+ disabled,
619
+ onPress: (0, import_web.composeEventHandlers)(props.onPress, handleSelect),
620
+ onPointerDown: function (event) {
621
+ var _props_onPointerDown;
622
+ (_props_onPointerDown = props.onPointerDown) === null || _props_onPointerDown === void 0 || _props_onPointerDown.call(props, event), isPointerDownRef.current = !0;
623
+ },
624
+ onPointerUp: (0, import_web.composeEventHandlers)(props.onPointerUp, function (event) {
625
+ if (import_web.isWeb) {
626
+ var _event_currentTarget;
627
+ isPointerDownRef.current || (_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 || _event_currentTarget.click();
628
+ }
629
+ }),
630
+ ...(import_web.isWeb ? {
631
+ onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function (event) {
632
+ var isTypingAhead = contentContext.searchRef.current !== "";
633
+ if (!(disabled || isTypingAhead && event.key === " ") && SELECTION_KEYS.includes(event.key)) {
634
+ var _event_currentTarget;
635
+ (_event_currentTarget = event.currentTarget) === null || _event_currentTarget === void 0 || _event_currentTarget.click(), event.preventDefault();
636
+ }
637
+ })
638
+ } : {}),
639
+ children: content
640
+ });
641
+ }),
642
+ MenuItemImpl = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
643
+ var {
644
+ scope = MENU_CONTEXT,
645
+ disabled = !1,
646
+ textValue,
647
+ unstyled = process.env.TAMAGUI_HEADLESS === "1",
648
+ ...itemProps
649
+ } = props,
650
+ contentContext = useMenuContentContext(scope),
651
+ ref = React.useRef(null),
652
+ composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref),
653
+ [isFocused, setIsFocused] = React.useState(!1),
654
+ [textContent, setTextContent] = React.useState("");
655
+ return import_web.isWeb && React.useEffect(function () {
656
+ var menuItem = ref.current;
657
+ if (menuItem) {
658
+ var _menuItem_textContent;
659
+ setTextContent(((_menuItem_textContent = menuItem.textContent) !== null && _menuItem_textContent !== void 0 ? _menuItem_textContent : "").trim());
660
+ }
661
+ }, [itemProps.children]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.ItemSlot, {
662
+ scope,
663
+ disabled,
664
+ textValue: textValue ?? textContent,
665
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_roving_focus.RovingFocusGroup.Item, {
666
+ asChild: !0,
667
+ __scopeRovingFocusGroup: scope,
668
+ focusable: !disabled,
669
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Item, {
670
+ unstyled,
671
+ componentName: ITEM_NAME,
672
+ role: "menuitem",
673
+ "data-highlighted": isFocused ? "" : void 0,
674
+ "aria-disabled": disabled || void 0,
675
+ "data-disabled": disabled ? "" : void 0,
676
+ ...itemProps,
677
+ ref: composedRefs,
678
+ /**
679
+ * We focus items on `pointerMove` to achieve the following:
680
+ *
681
+ * - Mouse over an item (it focuses)
682
+ * - Leave mouse where it is and use keyboard to focus a different item
683
+ * - Wiggle mouse without it leaving previously focused item
684
+ * - Previously focused item should re-focus
685
+ *
686
+ * If we used `mouseOver`/`mouseEnter` it would not re-focus when the mouse
687
+ * wiggles. This is to match native menu implementation.
688
+ */
689
+ onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove, function (event) {
690
+ if (event.pointerType === "mouse") {
691
+ if (disabled) contentContext.onItemLeave(event);else if (contentContext.onItemEnter(event), !event.defaultPrevented) {
692
+ var item = event.currentTarget;
693
+ item.focus({
694
+ preventScroll: !0,
695
+ focusVisible: !1
696
+ });
697
+ }
698
+ }
699
+ }),
700
+ onPointerLeave: (0, import_web.composeEventHandlers)(props.onPointerLeave, function (event) {
701
+ contentContext.onItemLeave(event);
702
+ }),
703
+ onFocus: (0, import_web.composeEventHandlers)(props.onFocus, function () {
704
+ return setIsFocused(!0);
705
+ }),
706
+ onBlur: (0, import_web.composeEventHandlers)(props.onBlur, function () {
707
+ return setIsFocused(!1);
708
+ })
709
+ })
710
+ })
711
+ });
712
+ });
713
+ MenuItem.displayName = ITEM_NAME;
714
+ var ITEM_TITLE_NAME = "MenuItemTitle",
715
+ MenuItemTitle = _Title.styleable(function (props, forwardedRef) {
716
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Title, {
717
+ ...props,
718
+ ref: forwardedRef
719
+ });
720
+ });
721
+ MenuItemTitle.displayName = ITEM_TITLE_NAME;
722
+ var ITEM_SUB_TITLE_NAME = "MenuItemSubTitle",
723
+ MenuItemSubTitle = _SubTitle.styleable(function (props, forwardedRef) {
724
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_SubTitle, {
725
+ ...props,
726
+ ref: forwardedRef
727
+ });
728
+ });
729
+ MenuItemSubTitle.displayName = ITEM_SUB_TITLE_NAME;
730
+ var ITEM_IMAGE = "MenuItemImage",
731
+ MenuItemImage = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
732
+ var {
733
+ // @ts-ignore - native menu ios config
734
+ ios,
735
+ // @ts-ignore
736
+ androidIconName,
737
+ // @ts-ignore
738
+ iosIconName,
739
+ ...rest
740
+ } = props;
741
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Image, {
742
+ ...rest,
743
+ ref: forwardedRef
744
+ });
745
+ });
746
+ MenuItemImage.displayName = ITEM_IMAGE;
747
+ var ITEM_ICON = "MenuItemIcon",
748
+ MenuItemIcon = _Icon.styleable(function (props, forwardedRef) {
749
+ var {
750
+ // @ts-ignore
751
+ ios,
752
+ // @ts-ignore
753
+ android,
754
+ // @ts-ignore
755
+ androidIconName,
756
+ // @ts-ignore
757
+ iosIconName,
758
+ ...rest
759
+ } = props;
760
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Icon, {
761
+ ...rest,
762
+ ref: forwardedRef
763
+ });
764
+ });
765
+ MenuItemIcon.displayName = ITEM_ICON;
766
+ var CHECKBOX_ITEM_NAME = "MenuCheckboxItem",
767
+ MenuCheckboxItem = _Item.styleable(function (props, forwardedRef) {
768
+ var {
769
+ checked = !1,
770
+ onCheckedChange,
771
+ scope = MENU_CONTEXT,
772
+ // filter out native-only props
773
+ // @ts-ignore - native menu value state
774
+ value,
775
+ // @ts-ignore - native menu value change handler
776
+ onValueChange,
777
+ ...checkboxItemProps
778
+ } = props;
779
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ItemIndicatorProvider, {
780
+ scope,
781
+ checked,
782
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItem, {
783
+ componentName: CHECKBOX_ITEM_NAME,
784
+ role: import_web.isWeb ? "menuitemcheckbox" : "menuitem",
785
+ "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
786
+ ...checkboxItemProps,
787
+ scope,
788
+ ref: forwardedRef,
789
+ "data-state": getCheckedState(checked),
790
+ onSelect: (0, import_web.composeEventHandlers)(checkboxItemProps.onSelect, function () {
791
+ return onCheckedChange?.(isIndeterminate(checked) ? !0 : !checked);
792
+ }, {
793
+ checkDefaultPrevented: !1
794
+ })
795
+ })
796
+ });
797
+ });
798
+ MenuCheckboxItem.displayName = CHECKBOX_ITEM_NAME;
799
+ var RADIO_GROUP_NAME = "MenuRadioGroup",
800
+ {
801
+ Provider: RadioGroupProvider,
802
+ useStyledContext: useRadioGroupContext
803
+ } = (0, import_web.createStyledContext)(),
804
+ MenuRadioGroup = _MenuGroup.styleable(function (props, forwardedRef) {
805
+ var {
806
+ value,
807
+ onValueChange,
808
+ scope = MENU_CONTEXT,
809
+ ...groupProps
810
+ } = props,
811
+ handleValueChange = (0, import_use_callback_ref.useCallbackRef)(onValueChange);
812
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(RadioGroupProvider, {
813
+ scope,
814
+ value,
815
+ onValueChange: handleValueChange,
816
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(_MenuGroup, {
817
+ componentName: RADIO_GROUP_NAME,
818
+ ...groupProps,
819
+ ref: forwardedRef
820
+ })
821
+ });
822
+ });
823
+ MenuRadioGroup.displayName = RADIO_GROUP_NAME;
824
+ var RADIO_ITEM_NAME = "MenuRadioItem",
825
+ MenuRadioItem = _Item.styleable(function (props, forwardedRef) {
826
+ var {
827
+ value,
828
+ scope = MENU_CONTEXT,
829
+ ...radioItemProps
830
+ } = props,
831
+ context = useRadioGroupContext(scope),
832
+ checked = value === context.value;
833
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ItemIndicatorProvider, {
834
+ scope,
835
+ checked,
836
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItem, {
837
+ componentName: RADIO_ITEM_NAME,
838
+ ...radioItemProps,
839
+ scope,
840
+ "aria-checked": checked,
841
+ ref: forwardedRef,
842
+ role: import_web.isWeb ? "menuitemradio" : "menuitem",
843
+ "data-state": getCheckedState(checked),
844
+ onSelect: (0, import_web.composeEventHandlers)(radioItemProps.onSelect, function () {
845
+ var _context_onValueChange;
846
+ return (_context_onValueChange = context.onValueChange) === null || _context_onValueChange === void 0 ? void 0 : _context_onValueChange.call(context, value);
847
+ }, {
848
+ checkDefaultPrevented: !1
849
+ })
850
+ })
851
+ });
852
+ });
853
+ MenuRadioItem.displayName = RADIO_ITEM_NAME;
854
+ var ITEM_INDICATOR_NAME = "MenuItemIndicator",
855
+ {
856
+ Provider: ItemIndicatorProvider,
857
+ useStyledContext: useItemIndicatorContext
858
+ } = (0, import_web.createStyledContext)(),
859
+ MenuItemIndicator = _Indicator.styleable(function (props, forwardedRef) {
860
+ var {
861
+ scope = MENU_CONTEXT,
862
+ forceMount,
863
+ ...itemIndicatorProps
864
+ } = props,
865
+ indicatorContext = useItemIndicatorContext(scope);
866
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
867
+ children: forceMount || isIndeterminate(indicatorContext.checked) || indicatorContext.checked === !0 ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Indicator, {
868
+ componentName: ITEM_INDICATOR_NAME,
869
+ render: "span",
870
+ ...itemIndicatorProps,
871
+ ref: forwardedRef,
872
+ "data-state": getCheckedState(indicatorContext.checked)
873
+ }) : null
874
+ });
875
+ });
876
+ MenuItemIndicator.displayName = ITEM_INDICATOR_NAME;
877
+ var MenuArrow = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
878
+ var {
879
+ scope = MENU_CONTEXT,
880
+ unstyled = process.env.TAMAGUI_HEADLESS === "1",
881
+ ...rest
882
+ } = props;
883
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.PopperArrow, {
884
+ scope,
885
+ componentName: "PopperArrow",
886
+ unstyled,
887
+ ...(!unstyled && {
888
+ backgroundColor: "$background"
889
+ }),
890
+ ...rest,
891
+ ref: forwardedRef
892
+ });
893
+ }),
894
+ SUB_NAME = "MenuSub",
895
+ {
896
+ Provider: MenuSubProvider,
897
+ useStyledContext: useMenuSubContext
898
+ } = (0, import_web.createStyledContext)(),
899
+ MenuSub = function (props) {
900
+ var _parentPopperContext_placement,
901
+ isTouchDevice = (0, import_web.useIsTouchDevice)(),
902
+ {
903
+ scope = MENU_CONTEXT
904
+ } = props,
905
+ rootContext = useMenuRootContext(scope),
906
+ parentPopperContext = PopperPrimitive.usePopperContext(scope),
907
+ parentSide = (_parentPopperContext_placement = parentPopperContext.placement) === null || _parentPopperContext_placement === void 0 ? void 0 : _parentPopperContext_placement.split("-")[0],
908
+ isNestedSubmenu = parentSide === "left" || parentSide === "right",
909
+ defaultPlacement = isTouchDevice ? "bottom" : isNestedSubmenu ? `${parentSide}-start` : rootContext.dir === "rtl" ? "left-start" : "right-start",
910
+ {
911
+ children,
912
+ open = !1,
913
+ onOpenChange,
914
+ allowFlip: allowFlipProp = {
915
+ padding: 10
916
+ },
917
+ stayInFrame = {
918
+ padding: 10
919
+ },
920
+ placement = defaultPlacement,
921
+ ...rest
922
+ } = props,
923
+ allowFlip = React.useMemo(function () {
924
+ if (!isNestedSubmenu || typeof allowFlipProp == "boolean" || allowFlipProp.fallbackPlacements) return allowFlipProp;
925
+ var side = placement.split("-")[0],
926
+ align = placement.split("-")[1] || "start",
927
+ otherAlign = align === "start" ? "end" : "start";
928
+ if (side === "left" || side === "right") {
929
+ var oppositeSide = side === "right" ? "left" : "right";
930
+ return {
931
+ ...((typeof allowFlipProp > "u" ? "undefined" : _type_of(allowFlipProp)) === "object" ? allowFlipProp : {}),
932
+ fallbackPlacements: [`${side}-${otherAlign}`, `${oppositeSide}-${align}`, `${oppositeSide}-${otherAlign}`]
933
+ };
934
+ }
935
+ return allowFlipProp;
936
+ }, [isNestedSubmenu, allowFlipProp, placement]),
937
+ parentMenuContext = useMenuContext(scope),
938
+ [trigger, setTrigger] = React.useState(null),
939
+ [content, setContent] = React.useState(null),
940
+ handleOpenChange = (0, import_use_callback_ref.useCallbackRef)(onOpenChange);
941
+ return React.useEffect(function () {
942
+ return parentMenuContext.open === !1 && handleOpenChange(!1), function () {
943
+ return handleOpenChange(!1);
944
+ };
945
+ }, [parentMenuContext.open, handleOpenChange]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperPrimitive.Popper, {
946
+ open,
947
+ placement,
948
+ allowFlip,
949
+ stayInFrame,
950
+ ...rest,
951
+ scope,
952
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuProvider, {
953
+ scope,
954
+ open,
955
+ onOpenChange: handleOpenChange,
956
+ content,
957
+ onContentChange: setContent,
958
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuSubProvider, {
959
+ scope,
960
+ contentId: (0, import_react.useId)(),
961
+ triggerId: (0, import_react.useId)(),
962
+ trigger,
963
+ onTriggerChange: setTrigger,
964
+ children
965
+ })
966
+ })
967
+ });
968
+ };
969
+ MenuSub.displayName = SUB_NAME;
970
+ var SUB_TRIGGER_NAME = "MenuSubTrigger",
971
+ MenuSubTrigger = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
972
+ var scope = props.scope || MENU_CONTEXT,
973
+ context = useMenuContext(scope),
974
+ rootContext = useMenuRootContext(scope),
975
+ subContext = useMenuSubContext(scope),
976
+ contentContext = useMenuContentContext(scope),
977
+ popperContext = PopperPrimitive.usePopperContext(scope),
978
+ openTimerRef = React.useRef(null),
979
+ {
980
+ pointerGraceTimerRef,
981
+ onPointerGraceIntentChange
982
+ } = contentContext,
983
+ effectiveDir = rootContext.dir,
984
+ clearOpenTimer = React.useCallback(function () {
985
+ openTimerRef.current && window.clearTimeout(openTimerRef.current), openTimerRef.current = null;
986
+ }, []);
987
+ return React.useEffect(function () {
988
+ return clearOpenTimer;
989
+ }, [clearOpenTimer]), React.useEffect(function () {
990
+ var pointerGraceTimer = pointerGraceTimerRef.current;
991
+ return function () {
992
+ window.clearTimeout(pointerGraceTimer), onPointerGraceIntentChange(null);
993
+ };
994
+ }, [pointerGraceTimerRef, onPointerGraceIntentChange]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuAnchor, {
995
+ componentName: SUB_TRIGGER_NAME,
996
+ asChild: "except-style",
997
+ scope,
998
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuItemImpl, {
999
+ id: subContext.triggerId,
1000
+ "aria-haspopup": "menu",
1001
+ "aria-expanded": context.open,
1002
+ "aria-controls": subContext.contentId,
1003
+ "data-state": getOpenState(context.open),
1004
+ outlineStyle: "none",
1005
+ ...props,
1006
+ ref: (0, import_web.composeRefs)(forwardedRef, subContext.onTriggerChange),
1007
+ // This is redundant for mouse users but we cannot determine pointer type from
1008
+ // click event and we cannot use pointerup event (see git history for reasons why)
1009
+ onPress: function (event) {
1010
+ var _props_onPress;
1011
+ (_props_onPress = props.onPress) === null || _props_onPress === void 0 || _props_onPress.call(props, event), !(props.disabled || event.defaultPrevented) && (import_web.isWeb && event.currentTarget.focus(), context.open || context.onOpenChange(!0));
1012
+ },
1013
+ onPointerMove: (0, import_web.composeEventHandlers)(props.onPointerMove,
1014
+ // @ts-ignore
1015
+ whenMouse(function (event) {
1016
+ contentContext.onItemEnter(event), !event.defaultPrevented && !props.disabled && !context.open && !openTimerRef.current && (contentContext.onPointerGraceIntentChange(null), openTimerRef.current = window.setTimeout(function () {
1017
+ context.onOpenChange(!0), clearOpenTimer();
1018
+ }, 100));
1019
+ })),
1020
+ onPointerLeave: (0, import_web.composeEventHandlers)(props.onPointerLeave, function (eventIn) {
1021
+ var _context_content,
1022
+ event = eventIn;
1023
+ clearOpenTimer();
1024
+ var contentRect = (_context_content = context.content) === null || _context_content === void 0 ? void 0 : _context_content.getBoundingClientRect();
1025
+ if (contentRect) {
1026
+ var _contentEl_dataset,
1027
+ _sideEl_dataset,
1028
+ contentEl = context.content,
1029
+ sideEl = !(contentEl == null || (_contentEl_dataset = contentEl.dataset) === null || _contentEl_dataset === void 0) && _contentEl_dataset.side ? contentEl : contentEl?.querySelector("[data-side]"),
1030
+ side = (sideEl == null || (_sideEl_dataset = sideEl.dataset) === null || _sideEl_dataset === void 0 ? void 0 : _sideEl_dataset.side) || "right",
1031
+ rightSide = side === "right",
1032
+ bleed = rightSide ? -5 : 5,
1033
+ contentNearEdge = contentRect[rightSide ? "left" : "right"],
1034
+ contentFarEdge = contentRect[rightSide ? "right" : "left"],
1035
+ polygon = {
1036
+ area: [
1037
+ // Apply a bleed on clientX to ensure that our exit point is
1038
+ // consistently within polygon bounds
1039
+ {
1040
+ x: event.clientX + bleed,
1041
+ y: event.clientY
1042
+ }, {
1043
+ x: contentNearEdge,
1044
+ y: contentRect.top
1045
+ }, {
1046
+ x: contentFarEdge,
1047
+ y: contentRect.top
1048
+ }, {
1049
+ x: contentFarEdge,
1050
+ y: contentRect.bottom
1051
+ }, {
1052
+ x: contentNearEdge,
1053
+ y: contentRect.bottom
1054
+ }],
1055
+ side
1056
+ };
1057
+ contentContext.onPointerGraceIntentChange(polygon), window.clearTimeout(pointerGraceTimerRef.current), pointerGraceTimerRef.current = window.setTimeout(function () {
1058
+ return contentContext.onPointerGraceIntentChange(null);
1059
+ }, 300);
1060
+ } else if (import_web.isWeb && subContext.trigger) {
1061
+ var triggerEl = subContext.trigger,
1062
+ triggerRect = triggerEl?.getBoundingClientRect();
1063
+ if (triggerRect) {
1064
+ var _popperContext_placement,
1065
+ placementSide = (_popperContext_placement = popperContext.placement) === null || _popperContext_placement === void 0 ? void 0 : _popperContext_placement.split("-")[0],
1066
+ side1 = placementSide === "left" || placementSide === "right" ? placementSide : rootContext.dir === "rtl" ? "left" : "right",
1067
+ rightSide1 = side1 === "right",
1068
+ bleed1 = rightSide1 ? -5 : 5,
1069
+ nearEdge = rightSide1 ? triggerRect.right + 4 : triggerRect.left - 4,
1070
+ farEdge = rightSide1 ? nearEdge + 200 : nearEdge - 200,
1071
+ polygon1 = {
1072
+ area: [{
1073
+ x: event.clientX + bleed1,
1074
+ y: event.clientY
1075
+ }, {
1076
+ x: nearEdge,
1077
+ y: triggerRect.top - 50
1078
+ }, {
1079
+ x: farEdge,
1080
+ y: triggerRect.top - 50
1081
+ }, {
1082
+ x: farEdge,
1083
+ y: triggerRect.bottom + 50
1084
+ }, {
1085
+ x: nearEdge,
1086
+ y: triggerRect.bottom + 50
1087
+ }],
1088
+ side: side1
1089
+ };
1090
+ contentContext.onPointerGraceIntentChange(polygon1), window.clearTimeout(pointerGraceTimerRef.current), pointerGraceTimerRef.current = window.setTimeout(function () {
1091
+ return contentContext.onPointerGraceIntentChange(null);
1092
+ }, 300);
1093
+ }
1094
+ } else {
1095
+ if (contentContext.onTriggerLeave(event), event.defaultPrevented) return;
1096
+ contentContext.onPointerGraceIntentChange(null);
1097
+ }
1098
+ }),
1099
+ ...(import_web.isWeb ? {
1100
+ onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function (event) {
1101
+ var isTypingAhead = contentContext.searchRef.current !== "";
1102
+ if (!(props.disabled || isTypingAhead && event.key === " ")) {
1103
+ var willOpen = SUB_OPEN_KEYS[effectiveDir].includes(event.key);
1104
+ if (willOpen) {
1105
+ var _popperContext_refs, _context_content;
1106
+ if (context.open && context.content) {
1107
+ var _contentEl_querySelector,
1108
+ contentEl = context.content,
1109
+ firstItem = (_contentEl_querySelector = contentEl.querySelector) === null || _contentEl_querySelector === void 0 ? void 0 : _contentEl_querySelector.call(contentEl, '[role="menuitem"]:not([data-disabled])');
1110
+ if (firstItem) {
1111
+ firstItem.focus({
1112
+ focusVisible: !0
1113
+ }), event.preventDefault();
1114
+ return;
1115
+ }
1116
+ }
1117
+ var triggerEl = event.currentTarget;
1118
+ (_popperContext_refs = popperContext.refs) === null || _popperContext_refs === void 0 || _popperContext_refs.setReference(triggerEl), context.onOpenChange(!0), requestAnimationFrame(function () {
1119
+ var _popperContext_update;
1120
+ (_popperContext_update = popperContext.update) === null || _popperContext_update === void 0 || _popperContext_update.call(popperContext);
1121
+ }), (_context_content = context.content) === null || _context_content === void 0 || _context_content.focus({
1122
+ focusVisible: !0
1123
+ }), event.preventDefault();
1124
+ }
1125
+ }
1126
+ })
1127
+ } : null)
1128
+ })
1129
+ });
1130
+ });
1131
+ MenuSubTrigger.displayName = SUB_TRIGGER_NAME;
1132
+ var SUB_CONTENT_NAME = "MenuSubContent",
1133
+ MenuSubContentFrame = (0, import_web.styled)(PopperPrimitive.PopperContentFrame, {
1134
+ name: SUB_CONTENT_NAME
1135
+ }),
1136
+ MenuSubContent = MenuSubContentFrame.styleable(function (props, forwardedRef) {
1137
+ var _popperContext_placement,
1138
+ scope = props.scope || MENU_CONTEXT,
1139
+ portalContext = usePortalContext(scope),
1140
+ {
1141
+ forceMount = portalContext.forceMount,
1142
+ ...subContentProps
1143
+ } = props,
1144
+ context = useMenuContext(scope),
1145
+ rootContext = useMenuRootContext(scope),
1146
+ subContext = useMenuSubContext(scope),
1147
+ popperContext = PopperPrimitive.usePopperContext(scope),
1148
+ ref = React.useRef(null),
1149
+ composedRefs = (0, import_web.useComposedRefs)(forwardedRef, ref),
1150
+ placementSide = (_popperContext_placement = popperContext.placement) === null || _popperContext_placement === void 0 ? void 0 : _popperContext_placement.split("-")[0],
1151
+ dataSide = placementSide === "left" || placementSide === "right" ? placementSide : rootContext.dir === "rtl" ? "left" : "right",
1152
+ effectiveDir = rootContext.dir;
1153
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
1154
+ scope,
1155
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Slot, {
1156
+ scope,
1157
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(MenuContentImpl, {
1158
+ id: subContext.contentId,
1159
+ "aria-labelledby": subContext.triggerId,
1160
+ ...subContentProps,
1161
+ ref: composedRefs,
1162
+ "data-side": dataSide,
1163
+ disableOutsidePointerEvents: !1,
1164
+ disableOutsideScroll: !1,
1165
+ trapFocus: !1,
1166
+ onOpenAutoFocus: function (event) {
1167
+ if (rootContext.isUsingKeyboardRef.current) {
1168
+ var _root_querySelector,
1169
+ _this,
1170
+ root = ref.current,
1171
+ content = root == null || (_root_querySelector = root.querySelector) === null || _root_querySelector === void 0 ? void 0 : _root_querySelector.call(root, "[data-tamagui-menu-content]");
1172
+ (_this = content || root) === null || _this === void 0 || _this.focus({
1173
+ preventScroll: !0
1174
+ });
1175
+ }
1176
+ event.preventDefault();
1177
+ },
1178
+ // The menu might close because of focusing another menu item in the parent menu. We
1179
+ // don't want it to refocus the trigger in that case so we handle trigger focus ourselves.
1180
+ onCloseAutoFocus: function (event) {
1181
+ return event.preventDefault();
1182
+ },
1183
+ onFocusOutside: (0, import_web.composeEventHandlers)(props.onFocusOutside, function (event) {
1184
+ event.target !== subContext.trigger && context.onOpenChange(!1);
1185
+ }),
1186
+ onEscapeKeyDown: (0, import_web.composeEventHandlers)(props.onEscapeKeyDown, function (event) {
1187
+ var _subContext_trigger;
1188
+ context.onOpenChange(!1), (_subContext_trigger = subContext.trigger) === null || _subContext_trigger === void 0 || _subContext_trigger.focus({
1189
+ focusVisible: !0
1190
+ }), event.preventDefault();
1191
+ }),
1192
+ ...(import_web.isWeb ? {
1193
+ onKeyDown: (0, import_web.composeEventHandlers)(props.onKeyDown, function (event) {
1194
+ var isKeyDownInside = event.currentTarget.contains(event.target),
1195
+ isCloseKey = SUB_CLOSE_KEYS[effectiveDir].includes(event.key);
1196
+ if (isKeyDownInside && isCloseKey) {
1197
+ var _subContext_trigger;
1198
+ context.onOpenChange(!1), (_subContext_trigger = subContext.trigger) === null || _subContext_trigger === void 0 || _subContext_trigger.focus({
1199
+ focusVisible: !0
1200
+ }), event.preventDefault();
1201
+ }
1202
+ })
1203
+ } : null)
1204
+ })
1205
+ })
1206
+ });
1207
+ });
1208
+ MenuSubContent.displayName = SUB_CONTENT_NAME;
1209
+ var Anchor = MenuAnchor,
1210
+ Portal = MenuPortal,
1211
+ Content = MenuContent,
1212
+ Group = _MenuGroup.styleable(function (props, ref) {
1213
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_MenuGroup, {
1214
+ ...props,
1215
+ ref
1216
+ });
1217
+ });
1218
+ Group.displayName = "MenuGroup";
1219
+ var Label = _Label.styleable(function (props, ref) {
1220
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Label, {
1221
+ ...props,
1222
+ ref
1223
+ });
1224
+ });
1225
+ Label.displayName = "MenuLabel";
1226
+ var Item = MenuItem,
1227
+ CheckboxItem = MenuCheckboxItem,
1228
+ RadioGroup = MenuRadioGroup,
1229
+ RadioItem = MenuRadioItem,
1230
+ ItemIndicator = MenuItemIndicator,
1231
+ Separator = _Separator.styleable(function (props, ref) {
1232
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(_Separator, {
1233
+ ...props,
1234
+ ref
1235
+ });
1236
+ });
1237
+ Separator.displayName = "MenuSeparator";
1238
+ var Arrow = MenuArrow,
1239
+ Sub = MenuSub,
1240
+ SubTrigger = MenuSubTrigger,
1241
+ SubContent = MenuSubContent,
1242
+ ItemTitle = MenuItemTitle,
1243
+ ItemSubtitle = MenuItemSubTitle,
1244
+ ItemImage = MenuItemImage,
1245
+ ItemIcon = MenuItemIcon,
1246
+ Menu = (0, import_web.withStaticProperties)(MenuComp, {
1247
+ Anchor,
1248
+ Portal,
1249
+ Content,
1250
+ Group,
1251
+ Label,
1252
+ Item,
1253
+ CheckboxItem,
1254
+ RadioGroup,
1255
+ RadioItem,
1256
+ ItemIndicator,
1257
+ Separator,
1258
+ Arrow,
1259
+ Sub,
1260
+ SubTrigger,
1261
+ SubContent,
1262
+ ItemTitle,
1263
+ ItemSubtitle,
1264
+ ItemImage,
1265
+ ItemIcon
1266
+ });
1267
+ return {
1268
+ Menu
1269
+ };
1270
+ }
1271
+ function getOpenState(open) {
1272
+ return open ? "open" : "closed";
1273
+ }
1274
+ function isIndeterminate(checked) {
1275
+ return checked === "indeterminate";
1276
+ }
1277
+ function getCheckedState(checked) {
1278
+ return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
1279
+ }
1280
+ function focusFirst(candidates, options) {
1281
+ var PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement,
1282
+ _iteratorNormalCompletion = !0,
1283
+ _didIteratorError = !1,
1284
+ _iteratorError = void 0;
1285
+ try {
1286
+ for (var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
1287
+ var candidate = _step.value;
1288
+ if (candidate === PREVIOUSLY_FOCUSED_ELEMENT || (candidate.focus({
1289
+ preventScroll: !0,
1290
+ focusVisible: options?.focusVisible
1291
+ }), document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT)) return;
1292
+ }
1293
+ } catch (err) {
1294
+ _didIteratorError = !0, _iteratorError = err;
1295
+ } finally {
1296
+ try {
1297
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
1298
+ } finally {
1299
+ if (_didIteratorError) throw _iteratorError;
1300
+ }
1301
+ }
1302
+ }
1303
+ function wrapArray(array, startIndex) {
1304
+ return array.map(function (_, index) {
1305
+ return array[(startIndex + index) % array.length];
1306
+ });
1307
+ }
1308
+ function getNextMatch(values, search, currentMatch) {
1309
+ var isRepeated = search.length > 1 && Array.from(search).every(function (char) {
1310
+ return char === search[0];
1311
+ }),
1312
+ normalizedSearch = isRepeated ? search[0] : search,
1313
+ currentMatchIndex = currentMatch ? values.indexOf(currentMatch) : -1,
1314
+ wrappedValues = wrapArray(values, Math.max(currentMatchIndex, 0)),
1315
+ excludeCurrentMatch = normalizedSearch.length === 1;
1316
+ excludeCurrentMatch && (wrappedValues = wrappedValues.filter(function (v) {
1317
+ return v !== currentMatch;
1318
+ }));
1319
+ var nextMatch = wrappedValues.find(function (value) {
1320
+ return value.toLowerCase().startsWith(normalizedSearch.toLowerCase());
1321
+ });
1322
+ return nextMatch !== currentMatch ? nextMatch : void 0;
1323
+ }
1324
+ function isPointInPolygon(point, polygon) {
1325
+ for (var {
1326
+ x,
1327
+ y
1328
+ } = point, inside = !1, i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
1329
+ var xi = polygon[i].x,
1330
+ yi = polygon[i].y,
1331
+ xj = polygon[j].x,
1332
+ yj = polygon[j].y,
1333
+ intersect = yi > y != yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi;
1334
+ intersect && (inside = !inside);
1335
+ }
1336
+ return inside;
1337
+ }
1338
+ function isPointerInGraceArea(event, area) {
1339
+ if (!area) return !1;
1340
+ var cursorPos = {
1341
+ x: event.clientX,
1342
+ y: event.clientY
1343
+ };
1344
+ return isPointInPolygon(cursorPos, area);
1345
+ }
1346
+ //# sourceMappingURL=createBaseMenu.native.js.map