@zj-dynamics/components 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (674) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.react-is +21 -0
  3. package/NOTICE.tabbable +22 -0
  4. package/README.md +23 -2
  5. package/compatibility.css +2 -0
  6. package/dist/Button.d.ts +90 -0
  7. package/dist/Button.js +58 -0
  8. package/dist/ButtonDismiss.d.ts +6 -0
  9. package/dist/ButtonDismiss.js +5 -0
  10. package/dist/Dialog.d.ts +75 -0
  11. package/dist/Dialog.js +59 -0
  12. package/dist/Icon.d.ts +20 -0
  13. package/dist/Icon.js +11 -0
  14. package/dist/InputText.d.ts +26 -0
  15. package/dist/InputText.js +63 -0
  16. package/dist/Switch.d.ts +8 -0
  17. package/dist/Switch.js +19 -0
  18. package/dist/Toast.d.ts +21 -0
  19. package/dist/Toast.js +58 -0
  20. package/dist/browserFocus.d.ts +11 -0
  21. package/dist/browserFocus.js +85 -0
  22. package/dist/browserHooks.d.ts +5 -0
  23. package/dist/browserHooks.js +4 -0
  24. package/dist/index.d.ts +100 -0
  25. package/dist/index.js +91 -0
  26. package/dist/legacyModalPortal.d.ts +1 -0
  27. package/dist/legacyModalPortal.js +2 -0
  28. package/dist/mockViewportWidth.d.ts +5 -0
  29. package/dist/mockViewportWidth.js +58 -0
  30. package/dist/slotChildren.d.ts +2 -0
  31. package/dist/slotChildren.js +6 -0
  32. package/dist/theme.d.ts +26 -0
  33. package/dist/theme.js +65 -0
  34. package/dist/unstyledPrimitives.d.ts +12 -0
  35. package/dist/unstyledPrimitives.js +12 -0
  36. package/dist/useBreakpoints.d.ts +3 -0
  37. package/dist/useBreakpoints.js +2 -0
  38. package/dist/useFocusTrap.d.ts +1 -0
  39. package/dist/useFocusTrap.js +1 -0
  40. package/dist/useInView.d.ts +1 -0
  41. package/dist/useInView.js +1 -0
  42. package/dist/useIsSmallScreen.d.ts +1 -0
  43. package/dist/useIsSmallScreen.js +1 -0
  44. package/dist/useLiveAnnounce.d.ts +1 -0
  45. package/dist/useLiveAnnounce.js +1 -0
  46. package/dist/useOnKeyDown.d.ts +1 -0
  47. package/dist/useOnKeyDown.js +1 -0
  48. package/dist/useRefocusOnActivator.d.ts +1 -0
  49. package/dist/useRefocusOnActivator.js +1 -0
  50. package/dist/useResizeObserver.d.ts +22 -0
  51. package/dist/useResizeObserver.js +47 -0
  52. package/dist/useWindowDimensions.d.ts +2 -0
  53. package/dist/useWindowDimensions.js +1 -0
  54. package/dist/viewport.d.ts +46 -0
  55. package/dist/viewport.js +141 -0
  56. package/foundation/ActivityIndicator/ActivityIndicator.d.ts +38 -0
  57. package/foundation/ActivityIndicator/index.d.mts +2 -0
  58. package/foundation/ActivityIndicator/index.mjs +6 -0
  59. package/foundation/ActivityIndicator-es.js +30 -0
  60. package/foundation/Autocomplete/Autocomplete.d.ts +8 -0
  61. package/foundation/Autocomplete/Autocomplete.types.d.ts +401 -0
  62. package/foundation/Autocomplete/hooks/useAutocompleteListNav.d.ts +30 -0
  63. package/foundation/Autocomplete/index.d.mts +3 -0
  64. package/foundation/Autocomplete/index.mjs +39 -0
  65. package/foundation/Autocomplete/utils/interactionUtils.d.ts +14 -0
  66. package/foundation/Autocomplete-es.js +1322 -0
  67. package/foundation/Avatar/Avatar.d.ts +77 -0
  68. package/foundation/Avatar/index.d.mts +1 -0
  69. package/foundation/Avatar/index.mjs +6 -0
  70. package/foundation/Avatar-es.js +80 -0
  71. package/foundation/Banner/Banner.d.ts +10 -0
  72. package/foundation/Banner/Banner.types.d.ts +165 -0
  73. package/foundation/Banner/index.d.mts +2 -0
  74. package/foundation/Banner/index.mjs +14 -0
  75. package/foundation/Banner-es.js +134 -0
  76. package/foundation/Body-es.js +45 -0
  77. package/foundation/BottomSheet-es.js +110 -0
  78. package/foundation/Box/Box.d.ts +3 -0
  79. package/foundation/Box/Box.types.d.ts +40 -0
  80. package/foundation/Box/index.d.mts +1 -0
  81. package/foundation/Box/index.mjs +4 -0
  82. package/foundation/Box-es.js +130 -0
  83. package/foundation/Button/Button.d.ts +17 -0
  84. package/foundation/Button/Button.types.d.ts +112 -0
  85. package/foundation/Button/ButtonInternals.d.ts +11 -0
  86. package/foundation/Button/ButtonProvider.d.ts +11 -0
  87. package/foundation/Button/index.d.mts +4 -0
  88. package/foundation/Button/useButtonStyles.d.ts +17 -0
  89. package/foundation/Button-es.js +122 -0
  90. package/foundation/ButtonDismiss/ButtonDismiss.d.ts +6 -0
  91. package/foundation/ButtonDismiss/index.d.mts +1 -0
  92. package/foundation/ButtonDismiss-es.js +9 -0
  93. package/foundation/Card/Card.d.ts +78 -0
  94. package/foundation/Card/cardcolors.module.d.ts +90 -0
  95. package/foundation/Card/index.d.mts +1 -0
  96. package/foundation/Card/index.mjs +37 -0
  97. package/foundation/Card/types.d.ts +63 -0
  98. package/foundation/Card-es.js +138 -0
  99. package/foundation/Checkbox/Checkbox.d.ts +7 -0
  100. package/foundation/Checkbox/Checkbox.types.d.ts +51 -0
  101. package/foundation/Checkbox/index.d.mts +2 -0
  102. package/foundation/Checkbox/index.mjs +8 -0
  103. package/foundation/Checkbox-es.js +57 -0
  104. package/foundation/Chip/Chip.d.ts +14 -0
  105. package/foundation/Chip/Chip.types.d.ts +70 -0
  106. package/foundation/Chip/components/ChipDismissible/ChipDismissible.d.ts +3 -0
  107. package/foundation/Chip/components/ChipPrefix/Chip.Prefix.d.ts +3 -0
  108. package/foundation/Chip/components/ChipSelectable/ChipSelectable.d.ts +3 -0
  109. package/foundation/Chip/components/ChipSuffix/Chip.Suffix.d.ts +9 -0
  110. package/foundation/Chip/index.d.mts +4 -0
  111. package/foundation/Chip/index.mjs +19 -0
  112. package/foundation/Chip-es.js +165 -0
  113. package/foundation/ChipDismissible-es.js +19 -0
  114. package/foundation/Chips/Chip.d.ts +9 -0
  115. package/foundation/Chips/ChipDismissible.d.ts +11 -0
  116. package/foundation/Chips/ChipTypes.d.ts +59 -0
  117. package/foundation/Chips/Chips.d.ts +8 -0
  118. package/foundation/Chips/ChipsTypes.d.ts +106 -0
  119. package/foundation/Chips/InternalChipButton.d.ts +11 -0
  120. package/foundation/Chips/index.d.mts +3 -0
  121. package/foundation/Chips/index.mjs +56 -0
  122. package/foundation/Chips-es.js +114 -0
  123. package/foundation/Cluster/Cluster.d.ts +3 -0
  124. package/foundation/Cluster/index.d.mts +2 -0
  125. package/foundation/Cluster/index.mjs +4 -0
  126. package/foundation/Cluster/types.d.ts +47 -0
  127. package/foundation/Cluster-es.js +12 -0
  128. package/foundation/Combobox/Combobox.d.ts +71 -0
  129. package/foundation/Combobox/Combobox.footer.d.ts +7 -0
  130. package/foundation/Combobox/Combobox.items.d.ts +25 -0
  131. package/foundation/Combobox/Combobox.selectAll.d.ts +4 -0
  132. package/foundation/Combobox/Combobox.slotFactory.d.ts +7 -0
  133. package/foundation/Combobox/Combobox.types.d.ts +168 -0
  134. package/foundation/Combobox/index.d.mts +2 -0
  135. package/foundation/Combobox/index.mjs +28 -0
  136. package/foundation/Combobox-es.js +782 -0
  137. package/foundation/ComboboxPrimitive-es.js +187 -0
  138. package/foundation/ComboboxSeparator-es.js +3541 -0
  139. package/foundation/ComponentSettingsContext/ComponentSettingsContext.d.ts +41 -0
  140. package/foundation/ComponentSettingsContext/index.d.mts +4 -0
  141. package/foundation/ComponentSettingsContext/index.mjs +5 -0
  142. package/foundation/ComponentSettingsContext-es.js +18 -0
  143. package/foundation/ConfirmationModal/ConfirmationModal.d.ts +79 -0
  144. package/foundation/ConfirmationModal/index.d.mts +1 -0
  145. package/foundation/ConfirmationModal/index.mjs +37 -0
  146. package/foundation/ConfirmationModal-es.js +111 -0
  147. package/foundation/Container/Container.d.ts +6 -0
  148. package/foundation/Container/index.d.mts +1 -0
  149. package/foundation/Container/index.mjs +3 -0
  150. package/foundation/Container/types.d.ts +22 -0
  151. package/foundation/Container-es.js +16 -0
  152. package/foundation/Content/Content.d.ts +22 -0
  153. package/foundation/Content/Spacing.module.d.ts +14 -0
  154. package/foundation/Content/index.d.mts +1 -0
  155. package/foundation/Content/index.mjs +3 -0
  156. package/foundation/Content-es.js +13 -0
  157. package/foundation/ContentBlock/ContentBlock.d.ts +3 -0
  158. package/foundation/ContentBlock/index.d.mts +2 -0
  159. package/foundation/ContentBlock/index.mjs +4 -0
  160. package/foundation/ContentBlock/types.d.ts +37 -0
  161. package/foundation/ContentBlock-es.js +29 -0
  162. package/foundation/Countdown/Countdown.d.ts +30 -0
  163. package/foundation/Countdown/index.d.mts +1 -0
  164. package/foundation/Countdown/index.mjs +4 -0
  165. package/foundation/Countdown-es.js +649 -0
  166. package/foundation/Cover/Cover.d.ts +6 -0
  167. package/foundation/Cover/index.d.mts +2 -0
  168. package/foundation/Cover/index.mjs +4 -0
  169. package/foundation/Cover/types.d.ts +34 -0
  170. package/foundation/Cover-es.js +14 -0
  171. package/foundation/DataDump/DataDump.d.ts +21 -0
  172. package/foundation/DataDump/index.d.mts +1 -0
  173. package/foundation/DataDump/index.mjs +40 -0
  174. package/foundation/DataDump-es.js +26 -0
  175. package/foundation/DataList/DataList.const.d.ts +22 -0
  176. package/foundation/DataList/DataList.d.ts +28 -0
  177. package/foundation/DataList/DataList.types.d.ts +323 -0
  178. package/foundation/DataList/components/DataListAction/DataListAction.d.ts +3 -0
  179. package/foundation/DataList/components/DataListAction/index.d.mts +1 -0
  180. package/foundation/DataList/components/DataListBulkActions/DataListBulkActions.d.ts +4 -0
  181. package/foundation/DataList/components/DataListBulkActions/index.d.mts +1 -0
  182. package/foundation/DataList/components/DataListEmptyState/DataListEmptyState.d.ts +4 -0
  183. package/foundation/DataList/components/DataListEmptyState/index.d.mts +1 -0
  184. package/foundation/DataList/components/DataListFilters/DataListFilters.d.ts +11 -0
  185. package/foundation/DataList/components/DataListFilters/index.d.mts +1 -0
  186. package/foundation/DataList/components/DataListItemActions/DataListItemActions.d.ts +9 -0
  187. package/foundation/DataList/components/DataListItemActions/index.d.mts +1 -0
  188. package/foundation/DataList/components/DataListLayout/DataListLayout.d.ts +3 -0
  189. package/foundation/DataList/components/DataListLayout/index.d.mts +1 -0
  190. package/foundation/DataList/components/DataListLayoutActions/DataListLayoutActions.d.ts +2 -0
  191. package/foundation/DataList/components/DataListLayoutActions/index.d.mts +1 -0
  192. package/foundation/DataList/components/DataListSearch/DataListSearch.d.ts +8 -0
  193. package/foundation/DataList/components/DataListSearch/index.d.mts +1 -0
  194. package/foundation/DataList/components/DataListStatusBar/DataListStatusBar.d.ts +11 -0
  195. package/foundation/DataList/components/DataListStatusBar/index.d.mts +1 -0
  196. package/foundation/DataList/index.d.mts +2 -0
  197. package/foundation/DataList/index.mjs +96 -0
  198. package/foundation/DataList-es.js +141 -0
  199. package/foundation/DataList.const-es.js +26 -0
  200. package/foundation/DataList.module-es.js +3 -0
  201. package/foundation/DataList.utils-es.js +167 -0
  202. package/foundation/DataListAction-es.js +43 -0
  203. package/foundation/DataListActions-es.js +53 -0
  204. package/foundation/DataListActionsMenu-es.js +52 -0
  205. package/foundation/DataListBulkActions-es.js +28 -0
  206. package/foundation/DataListContext-es.js +26 -0
  207. package/foundation/DataListEmptyState-es.js +54 -0
  208. package/foundation/DataListFilters-es.js +43 -0
  209. package/foundation/DataListHeader-es.js +130 -0
  210. package/foundation/DataListHeaderTile-es.js +86 -0
  211. package/foundation/DataListItem-es.js +118 -0
  212. package/foundation/DataListItemActions-es.js +29 -0
  213. package/foundation/DataListItemActionsOverflow-es.js +34 -0
  214. package/foundation/DataListItemClickable-es.js +45 -0
  215. package/foundation/DataListItems-es.js +19 -0
  216. package/foundation/DataListLayout-es.js +19 -0
  217. package/foundation/DataListLayoutActions-es.js +36 -0
  218. package/foundation/DataListLayoutContext-es.js +14 -0
  219. package/foundation/DataListLayoutContext-es2.js +8 -0
  220. package/foundation/DataListLoadMore-es.js +32 -0
  221. package/foundation/DataListLoadingState-es.js +22 -0
  222. package/foundation/DataListOverflowFade-es.js +22 -0
  223. package/foundation/DataListSearch-es.js +84 -0
  224. package/foundation/DataListSort-es.js +74 -0
  225. package/foundation/DataListSortingOptions-es.js +34 -0
  226. package/foundation/DataListStatusBar-es.js +22 -0
  227. package/foundation/DataListStickyHeader-es.js +23 -0
  228. package/foundation/DataListTags-es.js +62 -0
  229. package/foundation/DataListTotalCount-es.js +38 -0
  230. package/foundation/DataTable/DataTable.d.ts +74 -0
  231. package/foundation/DataTable/SortIcon.d.ts +11 -0
  232. package/foundation/DataTable/components/DataTableActions.d.ts +2 -0
  233. package/foundation/DataTable/components/DataTableBody.d.ts +2 -0
  234. package/foundation/DataTable/components/DataTableCell.d.ts +2 -0
  235. package/foundation/DataTable/components/DataTableContainer.d.ts +2 -0
  236. package/foundation/DataTable/components/DataTableFooter.d.ts +5 -0
  237. package/foundation/DataTable/components/DataTableHeader.d.ts +2 -0
  238. package/foundation/DataTable/components/DataTableHeaderCell.d.ts +5 -0
  239. package/foundation/DataTable/components/DataTablePagination.d.ts +5 -0
  240. package/foundation/DataTable/components/DataTablePaginationButton.d.ts +21 -0
  241. package/foundation/DataTable/components/DataTableRow.d.ts +2 -0
  242. package/foundation/DataTable/components/DataTableRowActions.d.ts +4 -0
  243. package/foundation/DataTable/components/DataTableSortableHeader.d.ts +24 -0
  244. package/foundation/DataTable/components/DataTableTable.d.ts +11 -0
  245. package/foundation/DataTable/components/index.d.mts +13 -0
  246. package/foundation/DataTable/index.d.mts +6 -0
  247. package/foundation/DataTable/index.mjs +29 -0
  248. package/foundation/DataTable/test-utilities/helpers.d.ts +1 -0
  249. package/foundation/DataTable/types.d.ts +83 -0
  250. package/foundation/DataTable-es.js +262 -0
  251. package/foundation/DataTableTable-es.js +117 -0
  252. package/foundation/DatePicker/DatePicker.d.ts +74 -0
  253. package/foundation/DatePicker/DatePickerActivator.d.ts +18 -0
  254. package/foundation/DatePicker/index.d.mts +1 -0
  255. package/foundation/DatePicker/index.mjs +26 -0
  256. package/foundation/DatePicker-es.js +13627 -0
  257. package/foundation/Dialog/dialogReturnFocus.d.ts +43 -0
  258. package/foundation/Disclosure/Disclosure.d.ts +68 -0
  259. package/foundation/Disclosure/index.d.mts +1 -0
  260. package/foundation/Disclosure/index.mjs +7 -0
  261. package/foundation/Disclosure-es.js +46 -0
  262. package/foundation/Divider/Divider.d.ts +39 -0
  263. package/foundation/Divider/DividerDirections.module.d.ts +6 -0
  264. package/foundation/Divider/DividerSizes.module.d.ts +8 -0
  265. package/foundation/Divider/index.d.mts +1 -0
  266. package/foundation/Divider/index.mjs +3 -0
  267. package/foundation/Divider-es.js +15 -0
  268. package/foundation/Drawer/Drawer.d.ts +14 -0
  269. package/foundation/Drawer/DrawerGrid.d.ts +7 -0
  270. package/foundation/Drawer/index.d.mts +2 -0
  271. package/foundation/Drawer/index.mjs +13 -0
  272. package/foundation/DrawerGrid-es.js +39 -0
  273. package/foundation/DrawerTitle-es.js +90 -0
  274. package/foundation/Emphasis/Emphasis.d.ts +12 -0
  275. package/foundation/Emphasis/index.d.mts +1 -0
  276. package/foundation/Emphasis/index.mjs +4 -0
  277. package/foundation/Emphasis-es.js +13 -0
  278. package/foundation/FeatureSwitch/FeatureSwitch.d.ts +52 -0
  279. package/foundation/FeatureSwitch/index.d.mts +1 -0
  280. package/foundation/FeatureSwitch/index.mjs +20 -0
  281. package/foundation/FeatureSwitch-es.js +66 -0
  282. package/foundation/FieldDescription-es.js +859 -0
  283. package/foundation/FilterPicker/FilterPicker.d.ts +11 -0
  284. package/foundation/FilterPicker/FilterPicker.types.d.ts +282 -0
  285. package/foundation/FilterPicker/FilterPickerProvider.d.ts +18 -0
  286. package/foundation/FilterPicker/components/FilterPickerAction/FilterPickerAction.d.ts +3 -0
  287. package/foundation/FilterPicker/components/FilterPickerAction/index.d.mts +1 -0
  288. package/foundation/FilterPicker/components/FilterPickerActivator/FilterPickerActivator.d.ts +3 -0
  289. package/foundation/FilterPicker/components/FilterPickerActivator/index.d.mts +1 -0
  290. package/foundation/FilterPicker/components/FilterPickerOption/FilterPickerOption.d.ts +3 -0
  291. package/foundation/FilterPicker/index.d.mts +3 -0
  292. package/foundation/FilterPicker/index.mjs +49 -0
  293. package/foundation/FilterPicker-es.js +110 -0
  294. package/foundation/FilterPicker.messages-es.js +56 -0
  295. package/foundation/FilterPickerAction-es.js +30 -0
  296. package/foundation/FilterPickerActivator-es.js +36 -0
  297. package/foundation/FilterPickerContent-es.js +180 -0
  298. package/foundation/FilterPickerContentHeader-es.js +23 -0
  299. package/foundation/FilterPickerContentList-es.js +74 -0
  300. package/foundation/FilterPickerContentSearch-es.js +35 -0
  301. package/foundation/FilterPickerLoadMore-es.js +14 -0
  302. package/foundation/FilterPickerOption-es.js +29 -0
  303. package/foundation/FilterPickerProvider-es.js +10 -0
  304. package/foundation/FilterPickerTrigger-es.js +19 -0
  305. package/foundation/Flex/Flex.d.ts +33 -0
  306. package/foundation/Flex/Flex.types.d.ts +6 -0
  307. package/foundation/Flex/index.d.mts +1 -0
  308. package/foundation/Flex/index.mjs +3 -0
  309. package/foundation/Flex-es.js +28 -0
  310. package/foundation/FormField/FormFieldAffix.d.ts +19 -0
  311. package/foundation/FormField/FormFieldTypes.d.ts +185 -0
  312. package/foundation/FormField/FormFieldWrapper.d.ts +57 -0
  313. package/foundation/FormField/hooks/useFormFieldName.d.ts +6 -0
  314. package/foundation/FormField/hooks/useFormFieldWrapperStyles.d.ts +35 -0
  315. package/foundation/FormField/index.d.mts +5 -0
  316. package/foundation/FormField/index.mjs +17 -0
  317. package/foundation/FormFieldPostFix-es.js +13 -0
  318. package/foundation/FormFieldWrapper-es.js +233 -0
  319. package/foundation/FormatFile/FormatFile.d.ts +42 -0
  320. package/foundation/FormatFile/index.d.mts +4 -0
  321. package/foundation/FormatFile/index.mjs +42 -0
  322. package/foundation/FormatFile/types.d.ts +27 -0
  323. package/foundation/FormatFile/useFormatFile.d.ts +5 -0
  324. package/foundation/FormatFile/useFormatFileStyles.d.ts +10 -0
  325. package/foundation/FormatFile-es.js +137 -0
  326. package/foundation/Frame/Frame.d.ts +3 -0
  327. package/foundation/Frame/index.d.mts +2 -0
  328. package/foundation/Frame/index.mjs +3 -0
  329. package/foundation/Frame/types.d.ts +24 -0
  330. package/foundation/Frame-es.js +10 -0
  331. package/foundation/Gallery/Gallery.d.ts +3 -0
  332. package/foundation/Gallery/GalleryTypes.d.ts +36 -0
  333. package/foundation/Gallery/index.d.mts +3 -0
  334. package/foundation/Gallery/index.mjs +64 -0
  335. package/foundation/Gallery-es.js +88 -0
  336. package/foundation/Glimmer/Glimmer.d.ts +71 -0
  337. package/foundation/Glimmer/index.d.mts +1 -0
  338. package/foundation/Glimmer/index.mjs +5 -0
  339. package/foundation/Glimmer/style/Shape.module.d.ts +9 -0
  340. package/foundation/Glimmer/style/Sizes.module.d.ts +10 -0
  341. package/foundation/Glimmer/style/Timing.module.d.ts +6 -0
  342. package/foundation/Glimmer-es.js +53 -0
  343. package/foundation/Grid/Grid.d.ts +32 -0
  344. package/foundation/Grid/GridAlign.module.d.ts +8 -0
  345. package/foundation/Grid/GridCell/GridCell.d.ts +23 -0
  346. package/foundation/Grid/GridCell/index.d.mts +1 -0
  347. package/foundation/Grid/index.d.mts +1 -0
  348. package/foundation/Grid/index.mjs +5 -0
  349. package/foundation/Grid-es.js +30 -0
  350. package/foundation/GridCell-es.js +34 -0
  351. package/foundation/Heading/Heading.d.ts +41 -0
  352. package/foundation/Heading/index.d.mts +2 -0
  353. package/foundation/Heading/index.mjs +4 -0
  354. package/foundation/Heading-es.js +55 -0
  355. package/foundation/HelperText-es.js +19 -0
  356. package/foundation/Icon/Icon.d.ts +47 -0
  357. package/foundation/Icon/index.d.mts +1 -0
  358. package/foundation/Icon-es.js +22 -0
  359. package/foundation/InlineLabel/InlineLabel.d.ts +18 -0
  360. package/foundation/InlineLabel/index.d.mts +1 -0
  361. package/foundation/InlineLabel/index.mjs +4 -0
  362. package/foundation/InlineLabel-es.js +19 -0
  363. package/foundation/InputAvatar/InputAvatar.d.ts +23 -0
  364. package/foundation/InputAvatar/index.d.mts +1 -0
  365. package/foundation/InputAvatar/index.mjs +22 -0
  366. package/foundation/InputAvatar-es.js +64 -0
  367. package/foundation/InputDate/InputDate.d.ts +3 -0
  368. package/foundation/InputDate/InputDate.types.d.ts +36 -0
  369. package/foundation/InputDate/index.d.mts +2 -0
  370. package/foundation/InputDate/index.mjs +39 -0
  371. package/foundation/InputDate-es.js +104 -0
  372. package/foundation/InputEmail/InputEmail.d.ts +3 -0
  373. package/foundation/InputEmail/InputEmail.types.d.ts +16 -0
  374. package/foundation/InputEmail/index.d.mts +2 -0
  375. package/foundation/InputEmail/index.mjs +22 -0
  376. package/foundation/InputEmail-es.js +105 -0
  377. package/foundation/InputFile/FileTypes.d.ts +17 -0
  378. package/foundation/InputFile/InputFile.d.ts +187 -0
  379. package/foundation/InputFile/InputFileButton.d.ts +6 -0
  380. package/foundation/InputFile/InputFileContentContext.d.ts +12 -0
  381. package/foundation/InputFile/InputFileDescription.d.ts +4 -0
  382. package/foundation/InputFile/InputFileDropzoneWrapper.d.ts +4 -0
  383. package/foundation/InputFile/InputFileHintText.d.ts +4 -0
  384. package/foundation/InputFile/index.d.mts +3 -0
  385. package/foundation/InputFile/index.mjs +16 -0
  386. package/foundation/InputFile-es.js +1780 -0
  387. package/foundation/InputGroup/InputGroup.d.ts +12 -0
  388. package/foundation/InputGroup/index.d.mts +1 -0
  389. package/foundation/InputGroup/index.mjs +3 -0
  390. package/foundation/InputGroup-es.js +26 -0
  391. package/foundation/InputNumber/InputNumber.d.ts +77 -0
  392. package/foundation/InputNumber/index.d.mts +2 -0
  393. package/foundation/InputNumber/index.mjs +33 -0
  394. package/foundation/InputNumber/types.d.ts +197 -0
  395. package/foundation/InputNumber-es.js +348 -0
  396. package/foundation/InputPhoneNumber/InputPhoneNumber.d.ts +3 -0
  397. package/foundation/InputPhoneNumber/InputPhoneNumber.types.d.ts +24 -0
  398. package/foundation/InputPhoneNumber/index.d.mts +2 -0
  399. package/foundation/InputPhoneNumber/index.mjs +22 -0
  400. package/foundation/InputPhoneNumber-es.js +188 -0
  401. package/foundation/InputText/InputText.d.ts +3 -0
  402. package/foundation/InputText/InputText.types.d.ts +58 -0
  403. package/foundation/InputText/index.d.mts +2 -0
  404. package/foundation/InputText/index.mjs +23 -0
  405. package/foundation/InputText-es.js +196 -0
  406. package/foundation/InputTime/InputTime.d.ts +3 -0
  407. package/foundation/InputTime/InputTime.types.d.ts +34 -0
  408. package/foundation/InputTime/index.d.mts +2 -0
  409. package/foundation/InputTime/index.mjs +23 -0
  410. package/foundation/InputTime-es.js +297 -0
  411. package/foundation/InputValidation/InputValidation.d.ts +10 -0
  412. package/foundation/InputValidation/index.d.mts +1 -0
  413. package/foundation/InputValidation/index.mjs +8 -0
  414. package/foundation/InputValidation-es.js +22 -0
  415. package/foundation/InternalChipDismissible-es.js +68 -0
  416. package/foundation/LICENSE +21 -0
  417. package/foundation/LegacySelect/LegacySelect.d.ts +7 -0
  418. package/foundation/LegacySelect/LegacySelect.types.d.ts +18 -0
  419. package/foundation/LegacySelect/Option.d.ts +18 -0
  420. package/foundation/LegacySelect/OptionGroup.d.ts +29 -0
  421. package/foundation/LegacySelect/index.d.mts +3 -0
  422. package/foundation/LegacySelect/index.mjs +23 -0
  423. package/foundation/LegacySelect-es.js +76 -0
  424. package/foundation/LegacyThemeContext/LegacyThemeContext.d.ts +5 -0
  425. package/foundation/LegacyThemeContext/index.d.mts +3 -0
  426. package/foundation/LegacyThemeContext/index.mjs +12 -0
  427. package/foundation/LegacyThemeContext/types.d.ts +59 -0
  428. package/foundation/LegacyThemeContext/updateTheme.d.ts +7 -0
  429. package/foundation/LegacyThemeContext-es.js +457 -0
  430. package/foundation/LightBox/LightBox.d.ts +165 -0
  431. package/foundation/LightBox/LightBox.types.d.ts +153 -0
  432. package/foundation/LightBox/LightBoxContext.d.ts +5 -0
  433. package/foundation/LightBox/index.d.mts +3 -0
  434. package/foundation/LightBox/index.mjs +50 -0
  435. package/foundation/LightBox-es.js +454 -0
  436. package/foundation/Link/Link.d.ts +9 -0
  437. package/foundation/Link/index.d.mts +2 -0
  438. package/foundation/Link/index.mjs +2 -0
  439. package/foundation/Link-es.js +12 -0
  440. package/foundation/List/List.d.ts +41 -0
  441. package/foundation/List/ListItem.d.ts +59 -0
  442. package/foundation/List/index.d.mts +2 -0
  443. package/foundation/List/index.mjs +22 -0
  444. package/foundation/List-es.js +199 -0
  445. package/foundation/Markdown/Markdown.d.ts +24 -0
  446. package/foundation/Markdown/index.d.mts +1 -0
  447. package/foundation/Markdown/index.mjs +10 -0
  448. package/foundation/Markdown-es.js +20558 -0
  449. package/foundation/Menu/Menu.d.ts +89 -0
  450. package/foundation/Menu/Menu.types.d.ts +105 -0
  451. package/foundation/Menu/index.d.mts +2 -0
  452. package/foundation/Menu/index.mjs +35 -0
  453. package/foundation/Menu/menuComposableTypes.d.ts +103 -0
  454. package/foundation/Menu-es.js +1033 -0
  455. package/foundation/MenuSubmenuTrigger-es.js +3088 -0
  456. package/foundation/Modal/Modal.rebuilt.d.ts +16 -0
  457. package/foundation/Modal/Modal.types.d.ts +138 -0
  458. package/foundation/Modal/ModalContext.rebuilt.d.ts +19 -0
  459. package/foundation/Modal/ModalSizes.module.d.ts +7 -0
  460. package/foundation/Modal/index.d.mts +17 -0
  461. package/foundation/Modal/index.mjs +302 -0
  462. package/foundation/Modal/useModalStyles.d.ts +12 -0
  463. package/foundation/MultiSelect/MultiSelect.d.ts +30 -0
  464. package/foundation/MultiSelect/index.d.mts +1 -0
  465. package/foundation/MultiSelect/index.mjs +9 -0
  466. package/foundation/MultiSelect/types.d.ts +13 -0
  467. package/foundation/MultiSelect-es.js +172 -0
  468. package/foundation/OverlaySeparator-es.js +13 -0
  469. package/foundation/Page/Page.d.ts +74 -0
  470. package/foundation/Page/index.d.mts +2 -0
  471. package/foundation/Page/index.mjs +42 -0
  472. package/foundation/Page/types.d.ts +123 -0
  473. package/foundation/Page-es.js +196 -0
  474. package/foundation/Popover/Popover.d.ts +9 -0
  475. package/foundation/Popover/Popover.types.d.ts +109 -0
  476. package/foundation/Popover/PopoverContext.d.ts +18 -0
  477. package/foundation/Popover/index.d.mts +4 -0
  478. package/foundation/Popover/index.mjs +27 -0
  479. package/foundation/Popover/usePopoverStyles.d.ts +5 -0
  480. package/foundation/Popover-es.js +166 -0
  481. package/foundation/ProgressBar/ProgressBar.d.ts +41 -0
  482. package/foundation/ProgressBar/ProgressBarSizes.module.d.ts +7 -0
  483. package/foundation/ProgressBar/index.d.mts +1 -0
  484. package/foundation/ProgressBar/index.mjs +5 -0
  485. package/foundation/ProgressBar-es.js +48 -0
  486. package/foundation/ProgressIndicator/ProgressIndicator.d.ts +60 -0
  487. package/foundation/ProgressIndicator/index.d.mts +1 -0
  488. package/foundation/ProgressIndicator/index.mjs +3 -0
  489. package/foundation/ProgressIndicator-es.js +41 -0
  490. package/foundation/RadioGroup/RadioGroup.d.ts +33 -0
  491. package/foundation/RadioGroup/RadioOption.d.ts +48 -0
  492. package/foundation/RadioGroup/index.d.mts +2 -0
  493. package/foundation/RadioGroup/index.mjs +5 -0
  494. package/foundation/RadioGroup-es.js +42 -0
  495. package/foundation/ResponsiveSwitcher/ResponsiveSwitcher.d.ts +3 -0
  496. package/foundation/ResponsiveSwitcher/index.d.mts +2 -0
  497. package/foundation/ResponsiveSwitcher/index.mjs +4 -0
  498. package/foundation/ResponsiveSwitcher/types.d.ts +26 -0
  499. package/foundation/ResponsiveSwitcher-es.js +11 -0
  500. package/foundation/RulnarPortalContent-es.js +1 -0
  501. package/foundation/ScrollAreaViewport-es.js +3959 -0
  502. package/foundation/SegmentedControl/SegmentedControl.d.ts +39 -0
  503. package/foundation/SegmentedControl/SegmentedControlBase.d.ts +7 -0
  504. package/foundation/SegmentedControl/SegmentedControlOption.d.ts +15 -0
  505. package/foundation/SegmentedControl/SegmentedControlProvider.d.ts +17 -0
  506. package/foundation/SegmentedControl/index.d.mts +2 -0
  507. package/foundation/SegmentedControl/index.mjs +3 -0
  508. package/foundation/SegmentedControl-es.js +64 -0
  509. package/foundation/Select/Select.d.ts +31 -0
  510. package/foundation/Select/Select.types.d.ts +145 -0
  511. package/foundation/Select/index.d.mts +2 -0
  512. package/foundation/Select/index.mjs +29 -0
  513. package/foundation/Select-es.js +227 -0
  514. package/foundation/SelectGroupLabel-es.js +1763 -0
  515. package/foundation/SelectPrimitive-es.js +126 -0
  516. package/foundation/Separator-es.js +33 -0
  517. package/foundation/SideDrawer/SideDrawer.d.ts +56 -0
  518. package/foundation/SideDrawer/SideDrawerActions.d.ts +3 -0
  519. package/foundation/SideDrawer/SideDrawerBackButton.d.ts +3 -0
  520. package/foundation/SideDrawer/SideDrawerFooter.d.ts +3 -0
  521. package/foundation/SideDrawer/SideDrawerTitle.d.ts +3 -0
  522. package/foundation/SideDrawer/SideDrawerToolbar.d.ts +2 -0
  523. package/foundation/SideDrawer/index.d.mts +1 -0
  524. package/foundation/SideDrawer/index.mjs +16 -0
  525. package/foundation/SideDrawer-es.js +198 -0
  526. package/foundation/SideKick/SideKick.d.ts +3 -0
  527. package/foundation/SideKick/index.d.mts +2 -0
  528. package/foundation/SideKick/index.mjs +4 -0
  529. package/foundation/SideKick/types.d.ts +35 -0
  530. package/foundation/SideKick-es.js +15 -0
  531. package/foundation/Spinner/Spinner.d.ts +22 -0
  532. package/foundation/Spinner/index.d.mts +1 -0
  533. package/foundation/Spinner/index.mjs +6 -0
  534. package/foundation/Spinner-es.js +21 -0
  535. package/foundation/Stack/Stack.d.ts +3 -0
  536. package/foundation/Stack/index.d.mts +2 -0
  537. package/foundation/Stack/index.mjs +4 -0
  538. package/foundation/Stack/types.d.ts +32 -0
  539. package/foundation/Stack-es.js +13 -0
  540. package/foundation/StatusIndicator/StatusIndicator.d.ts +7 -0
  541. package/foundation/StatusIndicator/StatusIndicator.type.d.ts +1 -0
  542. package/foundation/StatusIndicator/index.d.mts +2 -0
  543. package/foundation/StatusIndicator/index.mjs +2 -0
  544. package/foundation/StatusIndicator-es.js +9 -0
  545. package/foundation/StatusLabel/StatusLabel.d.ts +26 -0
  546. package/foundation/StatusLabel/index.d.mts +1 -0
  547. package/foundation/StatusLabel/index.mjs +5 -0
  548. package/foundation/StatusLabel-es.js +16 -0
  549. package/foundation/Table/Body.d.ts +7 -0
  550. package/foundation/Table/Cells/Cell.d.ts +8 -0
  551. package/foundation/Table/Cells/CellCurrency.d.ts +9 -0
  552. package/foundation/Table/Cells/CellNumeric.d.ts +5 -0
  553. package/foundation/Table/Footer.d.ts +7 -0
  554. package/foundation/Table/Header.d.ts +7 -0
  555. package/foundation/Table/Row.d.ts +7 -0
  556. package/foundation/Table/Table.d.ts +7 -0
  557. package/foundation/Table/index.d.mts +8 -0
  558. package/foundation/Table/index.mjs +4 -0
  559. package/foundation/Tabs/Tabs.d.ts +38 -0
  560. package/foundation/Tabs/index.d.mts +1 -0
  561. package/foundation/Tabs/index.mjs +8 -0
  562. package/foundation/Tabs-es.js +227 -0
  563. package/foundation/Text/Text.d.ts +29 -0
  564. package/foundation/Text/index.d.mts +2 -0
  565. package/foundation/Text/index.mjs +4 -0
  566. package/foundation/Text-es.js +25 -0
  567. package/foundation/Thumbnail/Thumbnail.d.ts +25 -0
  568. package/foundation/Thumbnail/index.d.mts +1 -0
  569. package/foundation/Thumbnail/index.mjs +9 -0
  570. package/foundation/Thumbnail-es.js +119 -0
  571. package/foundation/Tiles/Tiles.d.ts +3 -0
  572. package/foundation/Tiles/index.d.mts +2 -0
  573. package/foundation/Tiles/index.mjs +4 -0
  574. package/foundation/Tiles/types.d.ts +34 -0
  575. package/foundation/Tiles-es.js +11 -0
  576. package/foundation/Tooltip/Tooltip.d.ts +18 -0
  577. package/foundation/Tooltip/Tooltip.types.d.ts +1 -0
  578. package/foundation/Tooltip/index.d.mts +1 -0
  579. package/foundation/Tooltip/index.mjs +8 -0
  580. package/foundation/Tooltip-es.js +137 -0
  581. package/foundation/Typography/Typography.d.ts +64 -0
  582. package/foundation/Typography/css/Emphasis.module.d.ts +6 -0
  583. package/foundation/Typography/css/FontFamilies.module.d.ts +6 -0
  584. package/foundation/Typography/css/FontSizes.module.d.ts +12 -0
  585. package/foundation/Typography/css/FontWeights.module.d.ts +10 -0
  586. package/foundation/Typography/css/TextAlignment.module.d.ts +7 -0
  587. package/foundation/Typography/css/TextCases.module.d.ts +8 -0
  588. package/foundation/Typography/css/TextColors.module.d.ts +69 -0
  589. package/foundation/Typography/index.d.mts +1 -0
  590. package/foundation/Typography/index.mjs +3 -0
  591. package/foundation/Typography/types.d.ts +7 -0
  592. package/foundation/Typography-es.js +53 -0
  593. package/foundation/_baseAssignValue-es.js +29 -0
  594. package/foundation/_baseEach-es.js +1028 -0
  595. package/foundation/_baseFlatten-es.js +65 -0
  596. package/foundation/_baseFor-es.js +45 -0
  597. package/foundation/_commonjsHelpers-es.js +7 -0
  598. package/foundation/_getAllKeys-es.js +506 -0
  599. package/foundation/_getTag-es.js +133 -0
  600. package/foundation/_isIterateeCall-es.js +55 -0
  601. package/foundation/_setToString-es.js +168 -0
  602. package/foundation/buttonRenderAdapter-es.js +52 -0
  603. package/foundation/buttonStyles.d.mts +1 -0
  604. package/foundation/buttonStyles.mjs +1 -0
  605. package/foundation/clearable.d.ts +1 -0
  606. package/foundation/common.messages-es.js +18 -0
  607. package/foundation/compatHooks.mjs +2 -0
  608. package/foundation/constants-es.js +3 -0
  609. package/foundation/dateLocale-es.js +1142 -0
  610. package/foundation/debounce-es.js +329 -0
  611. package/foundation/dialogFocus.d.mts +1 -0
  612. package/foundation/dialogFocus.mjs +66 -0
  613. package/foundation/filterDataAttributes-es.js +24 -0
  614. package/foundation/floating-ui.react-es.js +6174 -0
  615. package/foundation/getMappedSpaceToken-es.js +18 -0
  616. package/foundation/helpers-es.js +15 -0
  617. package/foundation/identity-es.js +809 -0
  618. package/foundation/imageTypes.d.mts +1 -0
  619. package/foundation/imageTypes.mjs +1 -0
  620. package/foundation/index-es.js +1186 -0
  621. package/foundation/isObjectLike-es.js +190 -0
  622. package/foundation/isSymbol-es.js +33 -0
  623. package/foundation/isTypedArray-es.js +589 -0
  624. package/foundation/keysIn-es.js +385 -0
  625. package/foundation/linkEvents.d.mts +1 -0
  626. package/foundation/linkEvents.mjs +9 -0
  627. package/foundation/maxHeight-es.js +22 -0
  628. package/foundation/mergeClassName-es.js +10 -0
  629. package/foundation/mergeRefs-es.js +18 -0
  630. package/foundation/nestedEscape-es.js +91 -0
  631. package/foundation/noop-es.js +24 -0
  632. package/foundation/primitives/BottomSheet/BottomSheet.d.ts +37 -0
  633. package/foundation/primitives/BottomSheet/BottomSheet.types.d.ts +36 -0
  634. package/foundation/primitives/BottomSheet/index.d.mts +2 -0
  635. package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.d.ts +32 -0
  636. package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.types.d.ts +30 -0
  637. package/foundation/primitives/ComboboxPrimitive/index.d.mts +2 -0
  638. package/foundation/primitives/HelperText/HelperText.d.ts +25 -0
  639. package/foundation/primitives/HelperText/index.d.mts +1 -0
  640. package/foundation/primitives/OverlaySeparator/OverlaySeparator.d.ts +6 -0
  641. package/foundation/primitives/OverlaySeparator/index.d.mts +1 -0
  642. package/foundation/primitives/SelectPrimitive/SelectPrimitive.d.ts +74 -0
  643. package/foundation/primitives/SelectPrimitive/index.d.mts +2 -0
  644. package/foundation/primitives/SelectPrimitive/types.d.ts +31 -0
  645. package/foundation/primitives/index.d.mts +12 -0
  646. package/foundation/primitives/index.mjs +29 -0
  647. package/foundation/routerLink.d.mts +3 -0
  648. package/foundation/routerLink.mjs +1 -0
  649. package/foundation/scrollEdges-es.js +64 -0
  650. package/foundation/scrollable-es.js +54 -0
  651. package/foundation/sharedHelpers/getMappedBreakpointWidth.d.ts +8 -0
  652. package/foundation/sharedHelpers/types.d.ts +254 -0
  653. package/foundation/stringifyLocale-es.js +11 -0
  654. package/foundation/styles.css +16646 -0
  655. package/foundation/tslib.es6-es.js +97 -0
  656. package/foundation/unstyledPrimitives/index.d.mts +22 -0
  657. package/foundation/useActiveLayout-es.js +14 -0
  658. package/foundation/useBatchSelect-es.js +36 -0
  659. package/foundation/useChildComponent-es.js +15 -0
  660. package/foundation/useComponentMessages-es.js +86 -0
  661. package/foundation/useCompositeListItem-es.js +3955 -0
  662. package/foundation/useFormFieldFocus-es.js +37 -0
  663. package/foundation/useFormFieldName-es.js +11 -0
  664. package/foundation/useLabel-es.js +81 -0
  665. package/foundation/useRenderElement-es.js +628 -0
  666. package/foundation/useResponsiveSizing-es.js +8 -0
  667. package/foundation/useScrollLock-es.js +5746 -0
  668. package/foundation/useScrollToActive-es.js +581 -0
  669. package/foundation/utils/isNormalClick.d.ts +6 -0
  670. package/foundation/utils/isPreviewableImage.d.ts +1 -0
  671. package/foundation/utils/meta/meta.json +298 -0
  672. package/foundation.css +67 -0
  673. package/package.json +540 -4
  674. package/src/styles.css +181 -0
@@ -0,0 +1,3955 @@
1
+ import * as React from 'react';
2
+ import { useLayoutEffect } from 'react';
3
+ import { ae as evaluate, af as getSide, ag as getSideAxis, ah as getOppositePlacement, ai as getExpandedPlacements, aj as getOppositeAxisPlacements, ak as getAlignmentSides, al as getAlignment, am as min, an as max, ao as getAlignmentAxis, ap as getPaddingObject, aa as rectToClientRect, aq as getOppositeAxis, ar as clamp, as as getAxisLength, at as getDocumentElement, au as isElement, i as isHTMLElement, av as createCoords, aw as round, ax as isTopLayer, ay as getNodeName, az as isOverflowElement, aA as getNodeScroll, I as getWindow, b as getParentNode, a as isLastTraversableNode, aB as isTableElement, aC as isContainingBlock, aD as getContainingBlock, g as getComputedStyle$1, aE as getOverflowAncestors, aF as getFrameElement, aG as isWebKit, aH as floor, aI as useId, aJ as useFloatingParentNodeId, aK as FloatingRootStore, aL as PopupTriggerMap, c as useIsoLayoutEffect, aM as useFloatingTree, $ as getFloatingFocusElement, aN as isTypeableCombobox, w as useValueAsRef, d as useStableCallback, a8 as useAnimationFrame, aO as isIndexOutOfListBounds, aP as getMinListIndex, aQ as getMaxListIndex, D as activeElement, o as ownerDocument, a0 as contains, aR as stopEvent, h as createChangeEventDetails, aS as listNavigation, aT as findNonDisabledListIndex, e as getTarget, Y as focusOut, a9 as webkit, aU as enqueueFocus, ac as isVirtualClick, aV as isVirtualPointerEvent, aW as ARROW_UP, aX as ARROW_DOWN, aY as ARROW_LEFT, aZ as ARROW_RIGHT, q as useTimeout, a_ as isElementVisible, a$ as isListIndexDisabled, u as useBaseUiId, b0 as jsdom, a7 as useDirection, b1 as DISABLED_TRANSITIONS_STYLE, a6 as popupStateMapping, b2 as useScrollLock } from './useScrollLock-es.js';
4
+ import { a as useRefWithInit, c as EMPTY_ARRAY, N as NOOP, E as EMPTY_OBJECT, f as formatErrorMessage, u as useRenderElement } from './useRenderElement-es.js';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import * as ReactDOM from 'react-dom';
7
+
8
+ function useOnFirstRender(fn) {
9
+ const ref = React.useRef(true);
10
+ if (ref.current) {
11
+ ref.current = false;
12
+ fn();
13
+ }
14
+ }
15
+
16
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
17
+ let {
18
+ reference,
19
+ floating
20
+ } = _ref;
21
+ const sideAxis = getSideAxis(placement);
22
+ const alignmentAxis = getAlignmentAxis(placement);
23
+ const alignLength = getAxisLength(alignmentAxis);
24
+ const side = getSide(placement);
25
+ const isVertical = sideAxis === 'y';
26
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
27
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
28
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
29
+ let coords;
30
+ switch (side) {
31
+ case 'top':
32
+ coords = {
33
+ x: commonX,
34
+ y: reference.y - floating.height
35
+ };
36
+ break;
37
+ case 'bottom':
38
+ coords = {
39
+ x: commonX,
40
+ y: reference.y + reference.height
41
+ };
42
+ break;
43
+ case 'right':
44
+ coords = {
45
+ x: reference.x + reference.width,
46
+ y: commonY
47
+ };
48
+ break;
49
+ case 'left':
50
+ coords = {
51
+ x: reference.x - floating.width,
52
+ y: commonY
53
+ };
54
+ break;
55
+ default:
56
+ coords = {
57
+ x: reference.x,
58
+ y: reference.y
59
+ };
60
+ }
61
+ const alignment = getAlignment(placement);
62
+ if (alignment) {
63
+ coords[alignmentAxis] += commonAlign * (alignment === 'end' ? 1 : -1) * (rtl && isVertical ? -1 : 1);
64
+ }
65
+ return coords;
66
+ }
67
+
68
+ /**
69
+ * Resolves with an object of overflow side offsets that determine how much the
70
+ * element is overflowing a given clipping boundary on each side.
71
+ * - positive = overflowing the boundary by that number of pixels
72
+ * - negative = how many pixels left before it will overflow
73
+ * - 0 = lies flush with the boundary
74
+ * @see https://floating-ui.com/docs/detectOverflow
75
+ */
76
+ async function detectOverflow(state, options) {
77
+ var _await$platform$isEle;
78
+ if (options === void 0) {
79
+ options = {};
80
+ }
81
+ const {
82
+ x,
83
+ y,
84
+ platform,
85
+ rects,
86
+ elements,
87
+ strategy
88
+ } = state;
89
+ const {
90
+ boundary = 'clippingAncestors',
91
+ rootBoundary = 'viewport',
92
+ elementContext = 'floating',
93
+ altBoundary = false,
94
+ padding = 0
95
+ } = evaluate(options, state);
96
+ const paddingObject = getPaddingObject(padding);
97
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
98
+ const element = elements[altBoundary ? altContext : elementContext];
99
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
100
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
101
+ boundary,
102
+ rootBoundary,
103
+ strategy
104
+ }));
105
+ const rect = elementContext === 'floating' ? {
106
+ x,
107
+ y,
108
+ width: rects.floating.width,
109
+ height: rects.floating.height
110
+ } : rects.reference;
111
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
112
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) && (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
113
+ x: 1,
114
+ y: 1
115
+ };
116
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
117
+ elements,
118
+ rect,
119
+ offsetParent,
120
+ strategy
121
+ }) : rect);
122
+ return {
123
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
124
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
125
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
126
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
127
+ };
128
+ }
129
+
130
+ // Maximum number of resets that can occur before bailing to avoid infinite reset loops.
131
+ const MAX_RESET_COUNT = 50;
132
+
133
+ /**
134
+ * Computes the `x` and `y` coordinates that will place the floating element
135
+ * next to a given reference element.
136
+ *
137
+ * This export does not have any `platform` interface logic. You will need to
138
+ * write one for the platform you are using Floating UI with.
139
+ */
140
+ const computePosition$1 = async (reference, floating, config) => {
141
+ const {
142
+ placement = 'bottom',
143
+ strategy = 'absolute',
144
+ middleware = [],
145
+ platform
146
+ } = config;
147
+ const platformWithDetectOverflow = platform.detectOverflow ? platform : {
148
+ ...platform,
149
+ detectOverflow
150
+ };
151
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
152
+ let rects = await platform.getElementRects({
153
+ reference,
154
+ floating,
155
+ strategy
156
+ });
157
+ let {
158
+ x,
159
+ y
160
+ } = computeCoordsFromPlacement(rects, placement, rtl);
161
+ let statefulPlacement = placement;
162
+ let resetCount = 0;
163
+ const middlewareData = {};
164
+ for (let i = 0; i < middleware.length; i++) {
165
+ const currentMiddleware = middleware[i];
166
+ if (!currentMiddleware) {
167
+ continue;
168
+ }
169
+ const {
170
+ name,
171
+ fn
172
+ } = currentMiddleware;
173
+ const {
174
+ x: nextX,
175
+ y: nextY,
176
+ data,
177
+ reset
178
+ } = await fn({
179
+ x,
180
+ y,
181
+ initialPlacement: placement,
182
+ placement: statefulPlacement,
183
+ strategy,
184
+ middlewareData,
185
+ rects,
186
+ platform: platformWithDetectOverflow,
187
+ elements: {
188
+ reference,
189
+ floating
190
+ }
191
+ });
192
+ x = nextX != null ? nextX : x;
193
+ y = nextY != null ? nextY : y;
194
+ middlewareData[name] = {
195
+ ...middlewareData[name],
196
+ ...data
197
+ };
198
+ if (reset && resetCount < MAX_RESET_COUNT) {
199
+ resetCount++;
200
+ if (typeof reset === 'object') {
201
+ if (reset.placement) {
202
+ statefulPlacement = reset.placement;
203
+ }
204
+ if (reset.rects) {
205
+ rects = reset.rects === true ? await platform.getElementRects({
206
+ reference,
207
+ floating,
208
+ strategy
209
+ }) : reset.rects;
210
+ }
211
+ ({
212
+ x,
213
+ y
214
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
215
+ }
216
+ i = -1;
217
+ }
218
+ }
219
+ return {
220
+ x,
221
+ y,
222
+ placement: statefulPlacement,
223
+ strategy,
224
+ middlewareData
225
+ };
226
+ };
227
+
228
+ /**
229
+ * Optimizes the visibility of the floating element by flipping the `placement`
230
+ * in order to keep it in view when the preferred placement(s) will overflow the
231
+ * clipping boundary. Alternative to `autoPlacement`.
232
+ * @see https://floating-ui.com/docs/flip
233
+ */
234
+ const flip$2 = function (options) {
235
+ if (options === void 0) {
236
+ options = {};
237
+ }
238
+ return {
239
+ name: 'flip',
240
+ options,
241
+ async fn(state) {
242
+ var _middlewareData$arrow, _middlewareData$flip;
243
+ const {
244
+ placement,
245
+ middlewareData,
246
+ rects,
247
+ initialPlacement,
248
+ platform,
249
+ elements
250
+ } = state;
251
+ const {
252
+ mainAxis: checkMainAxis = true,
253
+ crossAxis: checkCrossAxis = true,
254
+ fallbackPlacements: specifiedFallbackPlacements,
255
+ fallbackStrategy = 'bestFit',
256
+ fallbackAxisSideDirection = 'none',
257
+ flipAlignment = true,
258
+ ...detectOverflowOptions
259
+ } = evaluate(options, state);
260
+
261
+ // If a reset by the arrow was caused due to an alignment offset being
262
+ // added, we should skip any logic now since `flip()` has already done its
263
+ // work.
264
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
265
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
266
+ return {};
267
+ }
268
+ const side = getSide(placement);
269
+ const initialSideAxis = getSideAxis(initialPlacement);
270
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
271
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
272
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
273
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
274
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
275
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
276
+ }
277
+ const placements = [initialPlacement, ...fallbackPlacements];
278
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
279
+ const overflows = [];
280
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
281
+ if (checkMainAxis) {
282
+ overflows.push(overflow[side]);
283
+ }
284
+ if (checkCrossAxis) {
285
+ const sides = getAlignmentSides(placement, rects, rtl);
286
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
287
+ }
288
+ overflowsData = [...overflowsData, {
289
+ placement,
290
+ overflows
291
+ }];
292
+
293
+ // One or more sides is overflowing.
294
+ if (!overflows.every(side => side <= 0)) {
295
+ var _middlewareData$flip2, _overflowsData$filter;
296
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
297
+ const nextPlacement = placements[nextIndex];
298
+ if (nextPlacement) {
299
+ const ignoreCrossAxisOverflow = checkCrossAxis === 'alignment' ? initialSideAxis !== getSideAxis(nextPlacement) : false;
300
+ if (!ignoreCrossAxisOverflow ||
301
+ // We leave the current main axis only if every placement on that axis
302
+ // overflows the main axis.
303
+ overflowsData.every(d => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
304
+ // Try next placement and re-run the lifecycle.
305
+ return {
306
+ data: {
307
+ index: nextIndex,
308
+ overflows: overflowsData
309
+ },
310
+ reset: {
311
+ placement: nextPlacement
312
+ }
313
+ };
314
+ }
315
+ }
316
+
317
+ // First, find the candidates that fit on the mainAxis side of overflow,
318
+ // then find the placement that fits the best on the main crossAxis side.
319
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
320
+
321
+ // Otherwise fallback.
322
+ if (!resetPlacement) {
323
+ switch (fallbackStrategy) {
324
+ case 'bestFit':
325
+ {
326
+ var _overflowsData$filter2;
327
+ const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
328
+ if (hasFallbackAxisSideDirection) {
329
+ const currentSideAxis = getSideAxis(d.placement);
330
+ return currentSideAxis === initialSideAxis ||
331
+ // Create a bias to the `y` side axis due to horizontal
332
+ // reading directions favoring greater width.
333
+ currentSideAxis === 'y';
334
+ }
335
+ return true;
336
+ }).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
337
+ if (placement) {
338
+ resetPlacement = placement;
339
+ }
340
+ break;
341
+ }
342
+ case 'initialPlacement':
343
+ resetPlacement = initialPlacement;
344
+ break;
345
+ }
346
+ }
347
+ if (placement !== resetPlacement) {
348
+ return {
349
+ reset: {
350
+ placement: resetPlacement
351
+ }
352
+ };
353
+ }
354
+ }
355
+ return {};
356
+ }
357
+ };
358
+ };
359
+
360
+ const originSides = /*#__PURE__*/new Set(['left', 'top']);
361
+
362
+ // For type backwards-compatibility, the `OffsetOptions` type was also
363
+ // Derivable.
364
+
365
+ async function convertValueToCoords(state, options) {
366
+ const {
367
+ placement,
368
+ platform,
369
+ elements
370
+ } = state;
371
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
372
+ const side = getSide(placement);
373
+ const alignment = getAlignment(placement);
374
+ const isVertical = getSideAxis(placement) === 'y';
375
+ const mainAxisMulti = originSides.has(side) ? -1 : 1;
376
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
377
+ const rawValue = evaluate(options, state);
378
+
379
+ // eslint-disable-next-line prefer-const
380
+ let {
381
+ mainAxis,
382
+ crossAxis,
383
+ alignmentAxis
384
+ } = typeof rawValue === 'number' ? {
385
+ mainAxis: rawValue,
386
+ crossAxis: 0,
387
+ alignmentAxis: null
388
+ } : {
389
+ mainAxis: rawValue.mainAxis || 0,
390
+ crossAxis: rawValue.crossAxis || 0,
391
+ alignmentAxis: rawValue.alignmentAxis
392
+ };
393
+ if (alignment && typeof alignmentAxis === 'number') {
394
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
395
+ }
396
+ return isVertical ? {
397
+ x: crossAxis * crossAxisMulti,
398
+ y: mainAxis * mainAxisMulti
399
+ } : {
400
+ x: mainAxis * mainAxisMulti,
401
+ y: crossAxis * crossAxisMulti
402
+ };
403
+ }
404
+
405
+ /**
406
+ * Modifies the placement by translating the floating element along the
407
+ * specified axes.
408
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
409
+ * object may be passed.
410
+ * @see https://floating-ui.com/docs/offset
411
+ */
412
+ const offset$2 = function (options) {
413
+ if (options === void 0) {
414
+ options = 0;
415
+ }
416
+ return {
417
+ name: 'offset',
418
+ options,
419
+ async fn(state) {
420
+ var _middlewareData$offse, _middlewareData$arrow;
421
+ const {
422
+ x,
423
+ y,
424
+ placement,
425
+ middlewareData
426
+ } = state;
427
+ const diffCoords = await convertValueToCoords(state, options);
428
+
429
+ // If the placement is the same and the arrow caused an alignment offset
430
+ // then we don't need to change the positioning coordinates.
431
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
432
+ return {};
433
+ }
434
+ return {
435
+ x: x + diffCoords.x,
436
+ y: y + diffCoords.y,
437
+ data: {
438
+ ...diffCoords,
439
+ placement
440
+ }
441
+ };
442
+ }
443
+ };
444
+ };
445
+
446
+ /**
447
+ * Optimizes the visibility of the floating element by shifting it in order to
448
+ * keep it in view when it will overflow the clipping boundary.
449
+ * @see https://floating-ui.com/docs/shift
450
+ */
451
+ const shift$2 = function (options) {
452
+ if (options === void 0) {
453
+ options = {};
454
+ }
455
+ return {
456
+ name: 'shift',
457
+ options,
458
+ async fn(state) {
459
+ const {
460
+ x,
461
+ y,
462
+ placement,
463
+ platform
464
+ } = state;
465
+ const {
466
+ mainAxis: checkMainAxis = true,
467
+ crossAxis: checkCrossAxis = false,
468
+ limiter = {
469
+ fn: _ref => {
470
+ let {
471
+ x,
472
+ y
473
+ } = _ref;
474
+ return {
475
+ x,
476
+ y
477
+ };
478
+ }
479
+ },
480
+ ...detectOverflowOptions
481
+ } = evaluate(options, state);
482
+ const coords = {
483
+ x,
484
+ y
485
+ };
486
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
487
+ const crossAxis = getSideAxis(placement);
488
+ const mainAxis = getOppositeAxis(crossAxis);
489
+ let mainAxisCoord = coords[mainAxis];
490
+ let crossAxisCoord = coords[crossAxis];
491
+ const clampCoord = (axis, coord) => clamp(coord + overflow[axis === 'y' ? 'top' : 'left'], coord, coord - overflow[axis === 'y' ? 'bottom' : 'right']);
492
+ if (checkMainAxis) {
493
+ mainAxisCoord = clampCoord(mainAxis, mainAxisCoord);
494
+ }
495
+ if (checkCrossAxis) {
496
+ crossAxisCoord = clampCoord(crossAxis, crossAxisCoord);
497
+ }
498
+ const limitedCoords = limiter.fn({
499
+ ...state,
500
+ [mainAxis]: mainAxisCoord,
501
+ [crossAxis]: crossAxisCoord
502
+ });
503
+ return {
504
+ ...limitedCoords,
505
+ data: {
506
+ x: limitedCoords.x - x,
507
+ y: limitedCoords.y - y,
508
+ enabled: {
509
+ [mainAxis]: checkMainAxis,
510
+ [crossAxis]: checkCrossAxis
511
+ }
512
+ }
513
+ };
514
+ }
515
+ };
516
+ };
517
+ /**
518
+ * Built-in `limiter` that will stop `shift()` at a certain point.
519
+ */
520
+ const limitShift$2 = function (options) {
521
+ if (options === void 0) {
522
+ options = {};
523
+ }
524
+ return {
525
+ options,
526
+ fn(state) {
527
+ var _rawOffset$mainAxis, _rawOffset$crossAxis;
528
+ const {
529
+ x,
530
+ y,
531
+ placement,
532
+ rects,
533
+ middlewareData
534
+ } = state;
535
+ const {
536
+ offset = 0,
537
+ mainAxis: checkMainAxis = true,
538
+ crossAxis: checkCrossAxis = true
539
+ } = evaluate(options, state);
540
+ const coords = {
541
+ x,
542
+ y
543
+ };
544
+ const crossAxis = getSideAxis(placement);
545
+ const mainAxis = getOppositeAxis(crossAxis);
546
+ let mainAxisCoord = coords[mainAxis];
547
+ let crossAxisCoord = coords[crossAxis];
548
+ const rawOffset = evaluate(offset, state);
549
+ const computedOffset = typeof rawOffset === 'number' ? {
550
+ mainAxis: rawOffset,
551
+ crossAxis: 0
552
+ } : {
553
+ mainAxis: (_rawOffset$mainAxis = rawOffset.mainAxis) != null ? _rawOffset$mainAxis : 0,
554
+ crossAxis: (_rawOffset$crossAxis = rawOffset.crossAxis) != null ? _rawOffset$crossAxis : 0
555
+ };
556
+ if (checkMainAxis) {
557
+ const len = mainAxis === 'y' ? 'height' : 'width';
558
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
559
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
560
+ if (mainAxisCoord < limitMin) {
561
+ mainAxisCoord = limitMin;
562
+ } else if (mainAxisCoord > limitMax) {
563
+ mainAxisCoord = limitMax;
564
+ }
565
+ }
566
+ if (checkCrossAxis) {
567
+ var _middlewareData$offse, _middlewareData$offse2;
568
+ const len = mainAxis === 'y' ? 'width' : 'height';
569
+ const isOriginSide = originSides.has(getSide(placement));
570
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
571
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
572
+ if (crossAxisCoord < limitMin) {
573
+ crossAxisCoord = limitMin;
574
+ } else if (crossAxisCoord > limitMax) {
575
+ crossAxisCoord = limitMax;
576
+ }
577
+ }
578
+ return {
579
+ [mainAxis]: mainAxisCoord,
580
+ [crossAxis]: crossAxisCoord
581
+ };
582
+ }
583
+ };
584
+ };
585
+
586
+ // Method syntax keeps callback parameters bivariant, but expressing the
587
+ // explicit `| undefined` required by `exactOptionalPropertyTypes` needs
588
+ // property syntax, which is contravariant under `strictFunctionTypes`.
589
+ // Extracting the function from a method position restores that bivariance so
590
+ // consumers can still assign callbacks with narrower parameter types.
591
+
592
+ /**
593
+ * Provides data that allows you to change the size of the floating element —
594
+ * for instance, prevent it from overflowing the clipping boundary or match the
595
+ * width of the reference element.
596
+ * @see https://floating-ui.com/docs/size
597
+ */
598
+ const size$2 = function (options) {
599
+ if (options === void 0) {
600
+ options = {};
601
+ }
602
+ return {
603
+ name: 'size',
604
+ options,
605
+ async fn(state) {
606
+ const {
607
+ placement,
608
+ rects,
609
+ platform,
610
+ elements
611
+ } = state;
612
+ const {
613
+ apply = () => {},
614
+ ...detectOverflowOptions
615
+ } = evaluate(options, state);
616
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
617
+ const side = getSide(placement);
618
+ const alignment = getAlignment(placement);
619
+ const isYAxis = getSideAxis(placement) === 'y';
620
+ const {
621
+ width,
622
+ height
623
+ } = rects.floating;
624
+ let heightSide;
625
+ let widthSide;
626
+ if (side === 'top' || side === 'bottom') {
627
+ heightSide = side;
628
+ widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
629
+ } else {
630
+ widthSide = side;
631
+ heightSide = alignment === 'end' ? 'top' : 'bottom';
632
+ }
633
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
634
+ const maximumClippingWidth = width - overflow.left - overflow.right;
635
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
636
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
637
+ const shiftData = state.middlewareData.shift;
638
+ const noShift = !shiftData;
639
+ let availableHeight = overflowAvailableHeight;
640
+ let availableWidth = overflowAvailableWidth;
641
+ if (shiftData != null && shiftData.enabled.x) {
642
+ availableWidth = maximumClippingWidth;
643
+ }
644
+ if (shiftData != null && shiftData.enabled.y) {
645
+ availableHeight = maximumClippingHeight;
646
+ }
647
+ if (noShift && !alignment) {
648
+ if (isYAxis) {
649
+ availableWidth = width - 2 * max(overflow.left, overflow.right);
650
+ } else {
651
+ availableHeight = height - 2 * max(overflow.top, overflow.bottom);
652
+ }
653
+ }
654
+ await apply({
655
+ ...state,
656
+ availableWidth,
657
+ availableHeight
658
+ });
659
+ const nextDimensions = await platform.getDimensions(elements.floating);
660
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
661
+ return {
662
+ reset: {
663
+ rects: true
664
+ }
665
+ };
666
+ }
667
+ return {};
668
+ }
669
+ };
670
+ };
671
+
672
+ function getCssDimensions(element) {
673
+ const css = getComputedStyle$1(element);
674
+ // In testing environments, the `width` and `height` properties are empty
675
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
676
+ let width = parseFloat(css.width) || 0;
677
+ let height = parseFloat(css.height) || 0;
678
+ const hasOffset = isHTMLElement(element);
679
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
680
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
681
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
682
+ if (shouldFallback) {
683
+ width = offsetWidth;
684
+ height = offsetHeight;
685
+ }
686
+ return {
687
+ width,
688
+ height,
689
+ $: shouldFallback
690
+ };
691
+ }
692
+
693
+ function unwrapElement(element) {
694
+ return !isElement(element) ? element.contextElement : element;
695
+ }
696
+
697
+ function getScale(element) {
698
+ const domElement = unwrapElement(element);
699
+ if (!isHTMLElement(domElement)) {
700
+ return createCoords(1);
701
+ }
702
+ const rect = domElement.getBoundingClientRect();
703
+ const {
704
+ width,
705
+ height,
706
+ $
707
+ } = getCssDimensions(domElement);
708
+ let x = ($ ? round(rect.width) : rect.width) / width;
709
+ let y = ($ ? round(rect.height) : rect.height) / height;
710
+
711
+ // 0, NaN, or Infinity should always fallback to 1.
712
+
713
+ if (!x || !Number.isFinite(x)) {
714
+ x = 1;
715
+ }
716
+ if (!y || !Number.isFinite(y)) {
717
+ y = 1;
718
+ }
719
+ return {
720
+ x,
721
+ y
722
+ };
723
+ }
724
+
725
+ const noOffsets = /*#__PURE__*/createCoords(0);
726
+ function getVisualOffsets(element) {
727
+ const win = getWindow(element);
728
+ if (!isWebKit() || !win.visualViewport) {
729
+ return noOffsets;
730
+ }
731
+ return {
732
+ x: win.visualViewport.offsetLeft,
733
+ y: win.visualViewport.offsetTop
734
+ };
735
+ }
736
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
737
+ if (isFixed === void 0) {
738
+ isFixed = false;
739
+ }
740
+ return !!floatingOffsetParent && isFixed && floatingOffsetParent === getWindow(element);
741
+ }
742
+
743
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
744
+ if (includeScale === void 0) {
745
+ includeScale = false;
746
+ }
747
+ if (isFixedStrategy === void 0) {
748
+ isFixedStrategy = false;
749
+ }
750
+ const clientRect = element.getBoundingClientRect();
751
+ const domElement = unwrapElement(element);
752
+ let scale = createCoords(1);
753
+ if (includeScale) {
754
+ if (offsetParent) {
755
+ if (isElement(offsetParent)) {
756
+ scale = getScale(offsetParent);
757
+ }
758
+ } else {
759
+ scale = getScale(element);
760
+ }
761
+ }
762
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
763
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
764
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
765
+ let width = clientRect.width / scale.x;
766
+ let height = clientRect.height / scale.y;
767
+ if (domElement && offsetParent) {
768
+ const win = getWindow(domElement);
769
+ const offsetWin = isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
770
+ let currentWin = win;
771
+ let currentIFrame = getFrameElement(currentWin);
772
+ while (currentIFrame && offsetWin !== currentWin) {
773
+ const iframeScale = getScale(currentIFrame);
774
+ const iframeRect = currentIFrame.getBoundingClientRect();
775
+ const css = getComputedStyle$1(currentIFrame);
776
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
777
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
778
+ x *= iframeScale.x;
779
+ y *= iframeScale.y;
780
+ width *= iframeScale.x;
781
+ height *= iframeScale.y;
782
+ x += left;
783
+ y += top;
784
+ currentWin = getWindow(currentIFrame);
785
+ currentIFrame = getFrameElement(currentWin);
786
+ }
787
+ }
788
+ return rectToClientRect({
789
+ width,
790
+ height,
791
+ x,
792
+ y
793
+ });
794
+ }
795
+
796
+ // If <html> has a CSS width greater than the viewport, then this will be
797
+ // incorrect for RTL.
798
+ function getWindowScrollBarX(element, rect) {
799
+ const leftScroll = getNodeScroll(element).scrollLeft;
800
+ if (!rect) {
801
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
802
+ }
803
+ return rect.left + leftScroll;
804
+ }
805
+
806
+ function getHTMLOffset(documentElement, scroll) {
807
+ const htmlRect = documentElement.getBoundingClientRect();
808
+ const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
809
+ const y = htmlRect.top + scroll.scrollTop;
810
+ return {
811
+ x,
812
+ y
813
+ };
814
+ }
815
+
816
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
817
+ let {
818
+ elements,
819
+ rect,
820
+ offsetParent,
821
+ strategy
822
+ } = _ref;
823
+ const isFixed = strategy === 'fixed';
824
+ const documentElement = getDocumentElement(offsetParent);
825
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
826
+ if (offsetParent === documentElement || topLayer && isFixed) {
827
+ return rect;
828
+ }
829
+ let scroll = {
830
+ scrollLeft: 0,
831
+ scrollTop: 0
832
+ };
833
+ let scale = createCoords(1);
834
+ const offsets = createCoords(0);
835
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
836
+ if (isOffsetParentAnElement || !isFixed) {
837
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
838
+ scroll = getNodeScroll(offsetParent);
839
+ }
840
+ if (isOffsetParentAnElement) {
841
+ const offsetRect = getBoundingClientRect(offsetParent);
842
+ scale = getScale(offsetParent);
843
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
844
+ offsets.y = offsetRect.y + offsetParent.clientTop;
845
+ }
846
+ }
847
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
848
+ return {
849
+ width: rect.width * scale.x,
850
+ height: rect.height * scale.y,
851
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
852
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
853
+ };
854
+ }
855
+
856
+ function getClientRects(element) {
857
+ return element.getClientRects ? Array.from(element.getClientRects()) : [];
858
+ }
859
+
860
+ // Gets the entire size of the scrollable document area, even extending outside
861
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
862
+ function getDocumentRect(html) {
863
+ const scroll = getNodeScroll(html);
864
+ const body = html.ownerDocument.body;
865
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
866
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
867
+ let x = -scroll.scrollLeft + getWindowScrollBarX(html);
868
+ const y = -scroll.scrollTop;
869
+ if (getComputedStyle$1(body).direction === 'rtl') {
870
+ x += max(html.clientWidth, body.clientWidth) - width;
871
+ }
872
+ return {
873
+ width,
874
+ height,
875
+ x,
876
+ y
877
+ };
878
+ }
879
+
880
+ // Safety check: ensure the scrollbar space is reasonable in case this
881
+ // calculation is affected by unusual styles.
882
+ // Most scrollbars leave 15-18px of space.
883
+ const SCROLLBAR_MAX = 25;
884
+ function getViewportRect(element, strategy, rootBoundary) {
885
+ if (rootBoundary === void 0) {
886
+ rootBoundary = 'viewport';
887
+ }
888
+ const isLayoutViewport = rootBoundary === 'layoutViewport';
889
+ const win = getWindow(element);
890
+ const html = getDocumentElement(element);
891
+ const visualViewport = win.visualViewport;
892
+ let width = html.clientWidth;
893
+ let height = html.clientHeight;
894
+ let x = 0;
895
+ let y = 0;
896
+ if (visualViewport) {
897
+ // Client coordinates are relative to the layout viewport, except in
898
+ // WebKit with an `absolute` strategy, where they are relative to the
899
+ // visual viewport.
900
+ const layoutRelativeClientCoords = !isWebKit() || strategy === 'fixed';
901
+ if (isLayoutViewport) {
902
+ if (!layoutRelativeClientCoords) {
903
+ x = -visualViewport.offsetLeft;
904
+ y = -visualViewport.offsetTop;
905
+ }
906
+ } else {
907
+ width = visualViewport.width;
908
+ height = visualViewport.height;
909
+ if (layoutRelativeClientCoords) {
910
+ x = visualViewport.offsetLeft;
911
+ y = visualViewport.offsetTop;
912
+ }
913
+ }
914
+ }
915
+ const windowScrollbarX = getWindowScrollBarX(html);
916
+ // `scrollbar-gutter: stable` on the <html> reserves gutter space that shrinks
917
+ // the visual width but isn't reflected in `html.clientWidth`, so subtract it.
918
+ // Only the inline-end (right) gutter can hold the scrollbar; `both-edges` also
919
+ // reserves an empty inline-start gutter that clips nothing, so exclude just
920
+ // the one scrollbar-side gutter — halve the measured (two-gutter) total. A
921
+ // left-side scrollbar (`windowScrollbarX > 0`) is already handled by
922
+ // `getHTMLOffset`/`visualViewport.width`; skip it here.
923
+ if (windowScrollbarX <= 0) {
924
+ const doc = html.ownerDocument;
925
+ const body = doc.body;
926
+ const bodyStyles = getComputedStyle(body);
927
+ const bodyMarginInline = doc.compatMode === 'CSS1Compat' ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
928
+ const reservedWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
929
+ const gutter = getComputedStyle(html).scrollbarGutter === 'stable both-edges' ? reservedWidth / 2 : reservedWidth;
930
+ if (gutter <= SCROLLBAR_MAX) {
931
+ width -= gutter;
932
+ }
933
+ }
934
+ return {
935
+ width,
936
+ height,
937
+ x,
938
+ y
939
+ };
940
+ }
941
+
942
+ // Returns the inner client rect, subtracting scrollbars if present.
943
+ function getInnerBoundingClientRect(element, strategy) {
944
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
945
+ const top = clientRect.top + element.clientTop;
946
+ const left = clientRect.left + element.clientLeft;
947
+ const scale = getScale(element);
948
+ const width = element.clientWidth * scale.x;
949
+ const height = element.clientHeight * scale.y;
950
+ const x = left * scale.x;
951
+ const y = top * scale.y;
952
+ return {
953
+ width,
954
+ height,
955
+ x,
956
+ y
957
+ };
958
+ }
959
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
960
+ let rect;
961
+ if (clippingAncestor === 'viewport' || clippingAncestor === 'layoutViewport') {
962
+ rect = getViewportRect(element, strategy, clippingAncestor);
963
+ } else if (clippingAncestor === 'document') {
964
+ rect = getDocumentRect(getDocumentElement(element));
965
+ } else if (isElement(clippingAncestor)) {
966
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
967
+ } else {
968
+ const visualOffsets = getVisualOffsets(element);
969
+ rect = {
970
+ x: clippingAncestor.x - visualOffsets.x,
971
+ y: clippingAncestor.y - visualOffsets.y,
972
+ width: clippingAncestor.width,
973
+ height: clippingAncestor.height
974
+ };
975
+ }
976
+ return rectToClientRect(rect);
977
+ }
978
+
979
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
980
+ // clipping (or hiding) child elements. This returns all clipping ancestors
981
+ // of the given element up the tree.
982
+ function getClippingElementAncestors(element, cache) {
983
+ const cachedResult = cache.get(element);
984
+ if (cachedResult) {
985
+ return cachedResult;
986
+ }
987
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
988
+ let lastKeptComputedStyle = null;
989
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
990
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
991
+
992
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
993
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
994
+ const computedStyle = getComputedStyle$1(currentNode);
995
+ const currentNodeIsContaining = isContainingBlock(currentNode);
996
+ // Position of the containing block chain below the current node. A fixed
997
+ // element whose containing block hasn't been found yet is a fixed chain.
998
+ const lastPosition = lastKeptComputedStyle ? lastKeptComputedStyle.position : elementIsFixed ? 'fixed' : '';
999
+
1000
+ // A non-containing ancestor does not clip the element when the chain
1001
+ // below it escapes it: a fixed chain escapes all ancestors up to the
1002
+ // next containing block, an absolute chain escapes static ancestors.
1003
+ const shouldDropCurrentNode = !currentNodeIsContaining && (lastPosition === 'fixed' || lastPosition === 'absolute' && computedStyle.position === 'static');
1004
+ if (shouldDropCurrentNode) {
1005
+ // Drop non-containing blocks.
1006
+ result = result.filter(ancestor => ancestor !== currentNode);
1007
+ } else {
1008
+ // The kept node carries the chain position for the next iteration.
1009
+ lastKeptComputedStyle = computedStyle;
1010
+ }
1011
+ currentNode = getParentNode(currentNode);
1012
+ }
1013
+ cache.set(element, result);
1014
+ return result;
1015
+ }
1016
+
1017
+ // Gets the maximum area that the element is visible in due to any number of
1018
+ // clipping ancestors.
1019
+ function getClippingRect(_ref) {
1020
+ let {
1021
+ element,
1022
+ boundary,
1023
+ rootBoundary,
1024
+ strategy
1025
+ } = _ref;
1026
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
1027
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1028
+ const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
1029
+ let top = firstRect.top;
1030
+ let right = firstRect.right;
1031
+ let bottom = firstRect.bottom;
1032
+ let left = firstRect.left;
1033
+ for (let i = 1; i < clippingAncestors.length; i++) {
1034
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
1035
+ top = max(rect.top, top);
1036
+ right = min(rect.right, right);
1037
+ bottom = min(rect.bottom, bottom);
1038
+ left = max(rect.left, left);
1039
+ }
1040
+ return {
1041
+ width: right - left,
1042
+ height: bottom - top,
1043
+ x: left,
1044
+ y: top
1045
+ };
1046
+ }
1047
+
1048
+ function getDimensions(element) {
1049
+ const {
1050
+ width,
1051
+ height
1052
+ } = getCssDimensions(element);
1053
+ return {
1054
+ width,
1055
+ height
1056
+ };
1057
+ }
1058
+
1059
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1060
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1061
+ const documentElement = getDocumentElement(offsetParent);
1062
+ const isFixed = strategy === 'fixed';
1063
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1064
+ let scroll = {
1065
+ scrollLeft: 0,
1066
+ scrollTop: 0
1067
+ };
1068
+ const offsets = createCoords(0);
1069
+ if (isOffsetParentAnElement || !isFixed) {
1070
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1071
+ scroll = getNodeScroll(offsetParent);
1072
+ }
1073
+ if (isOffsetParentAnElement) {
1074
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1075
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1076
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1077
+ }
1078
+ }
1079
+
1080
+ // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
1081
+ // Firefox with layout.scrollbar.side = 3 in about:config to test this.
1082
+ if (!isOffsetParentAnElement && documentElement) {
1083
+ offsets.x = getWindowScrollBarX(documentElement);
1084
+ }
1085
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
1086
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
1087
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
1088
+ return {
1089
+ x,
1090
+ y,
1091
+ width: rect.width,
1092
+ height: rect.height
1093
+ };
1094
+ }
1095
+
1096
+ function isStaticPositioned(element) {
1097
+ return getComputedStyle$1(element).position === 'static';
1098
+ }
1099
+
1100
+ function getTrueOffsetParent(element, polyfill) {
1101
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
1102
+ return null;
1103
+ }
1104
+ if (polyfill) {
1105
+ return polyfill(element);
1106
+ }
1107
+ let rawOffsetParent = element.offsetParent;
1108
+
1109
+ // Firefox returns the <html> element as the offsetParent if it's non-static,
1110
+ // while Chrome and Safari return the <body> element. The <body> element must
1111
+ // be used to perform the correct calculations even if the <html> element is
1112
+ // non-static.
1113
+ if (getDocumentElement(element) === rawOffsetParent) {
1114
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
1115
+ }
1116
+ return rawOffsetParent;
1117
+ }
1118
+
1119
+ // Gets the closest ancestor positioned element. Handles some edge cases,
1120
+ // such as table ancestors and cross browser bugs.
1121
+ function getOffsetParent(element, polyfill) {
1122
+ const win = getWindow(element);
1123
+ if (isTopLayer(element)) {
1124
+ return win;
1125
+ }
1126
+ if (!isHTMLElement(element)) {
1127
+ let svgOffsetParent = getParentNode(element);
1128
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
1129
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
1130
+ return svgOffsetParent;
1131
+ }
1132
+ svgOffsetParent = getParentNode(svgOffsetParent);
1133
+ }
1134
+ return win;
1135
+ }
1136
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1137
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
1138
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1139
+ }
1140
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
1141
+ return win;
1142
+ }
1143
+ return offsetParent || getContainingBlock(element) || win;
1144
+ }
1145
+
1146
+ const getElementRects = async function (data) {
1147
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1148
+ const getDimensionsFn = this.getDimensions;
1149
+ const floatingDimensions = await getDimensionsFn(data.floating);
1150
+ return {
1151
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
1152
+ floating: {
1153
+ x: 0,
1154
+ y: 0,
1155
+ width: floatingDimensions.width,
1156
+ height: floatingDimensions.height
1157
+ }
1158
+ };
1159
+ };
1160
+
1161
+ function isRTL(element) {
1162
+ return getComputedStyle$1(element).direction === 'rtl';
1163
+ }
1164
+
1165
+ const platform = {
1166
+ convertOffsetParentRelativeRectToViewportRelativeRect,
1167
+ getDocumentElement,
1168
+ getClippingRect,
1169
+ getOffsetParent,
1170
+ getElementRects,
1171
+ getClientRects,
1172
+ getDimensions,
1173
+ getScale,
1174
+ isElement,
1175
+ isRTL
1176
+ };
1177
+
1178
+ function rectsAreEqual(a, b) {
1179
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
1180
+ }
1181
+
1182
+ // https://samthor.au/2021/observing-dom/
1183
+ function observeMove(element, onMove, ancestorResize) {
1184
+ let io = null;
1185
+ let timeoutId;
1186
+ const root = getDocumentElement(element);
1187
+ function cleanup() {
1188
+ var _io;
1189
+ clearTimeout(timeoutId);
1190
+ (_io = io) == null || _io.disconnect();
1191
+ io = null;
1192
+ }
1193
+ function refresh(skip, threshold) {
1194
+ if (skip === void 0) {
1195
+ skip = false;
1196
+ }
1197
+ if (threshold === void 0) {
1198
+ threshold = 1;
1199
+ }
1200
+ cleanup();
1201
+ const elementRectForRootMargin = element.getBoundingClientRect();
1202
+ const {
1203
+ left,
1204
+ top,
1205
+ width,
1206
+ height
1207
+ } = elementRectForRootMargin;
1208
+ if (!skip) {
1209
+ onMove();
1210
+ }
1211
+ if (!width || !height) {
1212
+ return;
1213
+ }
1214
+ const insetTop = floor(top);
1215
+ const insetRight = floor(root.clientWidth - (left + width));
1216
+ const insetBottom = floor(root.clientHeight - (top + height));
1217
+ const insetLeft = floor(left);
1218
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
1219
+ const options = {
1220
+ rootMargin,
1221
+ threshold: max(0, min(1, threshold)) || 1
1222
+ };
1223
+ let isFirstUpdate = true;
1224
+ function handleObserve(entries) {
1225
+ const ratio = entries[0].intersectionRatio;
1226
+
1227
+ // The entry is a snapshot, so the reference may have moved since the
1228
+ // intersection was computed (under performance constraints, or between
1229
+ // consecutive frames of a multi-frame layout shift). The reported ratio
1230
+ // and the observed area are stale in that case and cannot be trusted to
1231
+ // detect subsequent movement, so refresh regardless of the ratio.
1232
+ if (!rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
1233
+ return refresh();
1234
+ }
1235
+ if (ratio !== threshold) {
1236
+ if (!isFirstUpdate) {
1237
+ return refresh();
1238
+ }
1239
+ if (!ratio) {
1240
+ // If the reference is clipped in place, the ratio is 0. Throttle
1241
+ // the refresh to prevent an infinite loop of updates.
1242
+ timeoutId = setTimeout(() => {
1243
+ refresh(false, 1e-7);
1244
+ }, 1000);
1245
+ } else {
1246
+ refresh(false, ratio);
1247
+ }
1248
+ }
1249
+ isFirstUpdate = false;
1250
+ }
1251
+
1252
+ // Older browsers don't support a `document` as the root and will throw an
1253
+ // error.
1254
+ try {
1255
+ io = new IntersectionObserver(handleObserve, {
1256
+ ...options,
1257
+ // Handle <iframe>s
1258
+ root: root.ownerDocument
1259
+ });
1260
+ } catch (_e) {
1261
+ io = new IntersectionObserver(handleObserve, options);
1262
+ }
1263
+ io.observe(element);
1264
+ }
1265
+ const win = getWindow(element);
1266
+ // The window is a resize ancestor, so when `ancestorResize` is enabled its
1267
+ // listener already runs the update on resize. Here we only need to rebuild
1268
+ // the `IntersectionObserver` for the new root size, skipping a redundant
1269
+ // update. When `ancestorResize` is disabled, this becomes the sole update.
1270
+ const handleResize = () => refresh(ancestorResize);
1271
+ win.addEventListener('resize', handleResize);
1272
+ refresh(true);
1273
+ return () => {
1274
+ win.removeEventListener('resize', handleResize);
1275
+ cleanup();
1276
+ };
1277
+ }
1278
+
1279
+ /**
1280
+ * Automatically updates the position of the floating element when necessary.
1281
+ * Should only be called when the floating element is mounted on the DOM or
1282
+ * visible on the screen.
1283
+ * @returns cleanup function that should be invoked when the floating element is
1284
+ * removed from the DOM or hidden from the screen.
1285
+ * @see https://floating-ui.com/docs/autoUpdate
1286
+ */
1287
+ function autoUpdate(reference, floating, update, options) {
1288
+ if (options === void 0) {
1289
+ options = {};
1290
+ }
1291
+ const {
1292
+ ancestorScroll = true,
1293
+ ancestorResize = true,
1294
+ elementResize = typeof ResizeObserver === 'function',
1295
+ layoutShift = typeof IntersectionObserver === 'function',
1296
+ animationFrame = false
1297
+ } = options;
1298
+ const referenceEl = unwrapElement(reference);
1299
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...(floating ? getOverflowAncestors(floating) : [])] : [];
1300
+ ancestors.forEach(ancestor => {
1301
+ ancestorScroll && ancestor.addEventListener('scroll', update);
1302
+ ancestorResize && ancestor.addEventListener('resize', update);
1303
+ });
1304
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update, ancestorResize) : null;
1305
+ let reobserveFrame = -1;
1306
+ let resizeObserver = null;
1307
+ if (elementResize) {
1308
+ resizeObserver = new ResizeObserver(_ref => {
1309
+ let [firstEntry] = _ref;
1310
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
1311
+ // Prevent update loops when using the `size` middleware.
1312
+ // https://github.com/floating-ui/floating-ui/issues/1740
1313
+ resizeObserver.unobserve(floating);
1314
+ cancelAnimationFrame(reobserveFrame);
1315
+ reobserveFrame = requestAnimationFrame(() => {
1316
+ var _resizeObserver;
1317
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
1318
+ });
1319
+ }
1320
+ update();
1321
+ });
1322
+ if (referenceEl && !animationFrame) {
1323
+ resizeObserver.observe(referenceEl);
1324
+ }
1325
+ if (floating) {
1326
+ resizeObserver.observe(floating);
1327
+ }
1328
+ }
1329
+ let frameId;
1330
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1331
+ if (animationFrame) {
1332
+ frameLoop();
1333
+ }
1334
+ function frameLoop() {
1335
+ const nextRefRect = getBoundingClientRect(reference);
1336
+ if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
1337
+ update();
1338
+ }
1339
+ prevRefRect = nextRefRect;
1340
+ frameId = requestAnimationFrame(frameLoop);
1341
+ }
1342
+ update();
1343
+ return () => {
1344
+ var _resizeObserver2;
1345
+ ancestors.forEach(ancestor => {
1346
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
1347
+ ancestorResize && ancestor.removeEventListener('resize', update);
1348
+ });
1349
+ cleanupIo == null || cleanupIo();
1350
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
1351
+ resizeObserver = null;
1352
+ if (animationFrame) {
1353
+ cancelAnimationFrame(frameId);
1354
+ }
1355
+ };
1356
+ }
1357
+
1358
+ /**
1359
+ * Modifies the placement by translating the floating element along the
1360
+ * specified axes.
1361
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
1362
+ * object may be passed.
1363
+ * @see https://floating-ui.com/docs/offset
1364
+ */
1365
+ const offset$1 = offset$2;
1366
+
1367
+ /**
1368
+ * Optimizes the visibility of the floating element by shifting it in order to
1369
+ * keep it in view when it will overflow the clipping boundary.
1370
+ * @see https://floating-ui.com/docs/shift
1371
+ */
1372
+ const shift$1 = shift$2;
1373
+
1374
+ /**
1375
+ * Optimizes the visibility of the floating element by flipping the `placement`
1376
+ * in order to keep it in view when the preferred placement(s) will overflow the
1377
+ * clipping boundary. Alternative to `autoPlacement`.
1378
+ * @see https://floating-ui.com/docs/flip
1379
+ */
1380
+ const flip$1 = flip$2;
1381
+
1382
+ /**
1383
+ * Provides data that allows you to change the size of the floating element —
1384
+ * for instance, prevent it from overflowing the clipping boundary or match the
1385
+ * width of the reference element.
1386
+ * @see https://floating-ui.com/docs/size
1387
+ */
1388
+ const size$1 = size$2;
1389
+
1390
+ /**
1391
+ * Built-in `limiter` that will stop `shift()` at a certain point.
1392
+ */
1393
+ const limitShift$1 = limitShift$2;
1394
+
1395
+ /**
1396
+ * Computes the `x` and `y` coordinates that will place the floating element
1397
+ * next to a given reference element.
1398
+ */
1399
+ const computePosition = (reference, floating, options) => {
1400
+ // This caches the expensive `getClippingElementAncestors` function so that
1401
+ // multiple lifecycle resets re-use the same result. It only lives for a
1402
+ // single call. If other functions become expensive, we can add them as well.
1403
+ const cache = new Map();
1404
+ const mergedOptions = options != null ? options : {};
1405
+ const platformWithCache = {
1406
+ ...platform,
1407
+ ...mergedOptions.platform,
1408
+ _c: cache
1409
+ };
1410
+ return computePosition$1(reference, floating, {
1411
+ ...mergedOptions,
1412
+ platform: platformWithCache
1413
+ });
1414
+ };
1415
+
1416
+ var isClient = typeof document !== 'undefined';
1417
+
1418
+ var noop = function noop() {};
1419
+ var index = isClient ? useLayoutEffect : noop;
1420
+
1421
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
1422
+ // functions
1423
+ function deepEqual(a, b) {
1424
+ if (a === b) {
1425
+ return true;
1426
+ }
1427
+ if (typeof a !== typeof b) {
1428
+ return false;
1429
+ }
1430
+ if (typeof a === 'function' && a.toString() === b.toString()) {
1431
+ return true;
1432
+ }
1433
+ let length;
1434
+ let i;
1435
+ let keys;
1436
+ if (a && b && typeof a === 'object') {
1437
+ if (Array.isArray(a)) {
1438
+ length = a.length;
1439
+ if (length !== b.length) return false;
1440
+ for (i = length; i-- !== 0;) {
1441
+ if (!deepEqual(a[i], b[i])) {
1442
+ return false;
1443
+ }
1444
+ }
1445
+ return true;
1446
+ }
1447
+ keys = Object.keys(a);
1448
+ length = keys.length;
1449
+ if (length !== Object.keys(b).length) {
1450
+ return false;
1451
+ }
1452
+ for (i = length; i-- !== 0;) {
1453
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
1454
+ return false;
1455
+ }
1456
+ }
1457
+ for (i = length; i-- !== 0;) {
1458
+ const key = keys[i];
1459
+ if (key === '_owner' && a.$$typeof) {
1460
+ continue;
1461
+ }
1462
+ if (!deepEqual(a[key], b[key])) {
1463
+ return false;
1464
+ }
1465
+ }
1466
+ return true;
1467
+ }
1468
+ return a !== a && b !== b;
1469
+ }
1470
+
1471
+ function getDPR(element) {
1472
+ if (typeof window === 'undefined') {
1473
+ return 1;
1474
+ }
1475
+ const win = element.ownerDocument.defaultView || window;
1476
+ return win.devicePixelRatio || 1;
1477
+ }
1478
+
1479
+ function roundByDPR(element, value) {
1480
+ const dpr = getDPR(element);
1481
+ return Math.round(value * dpr) / dpr;
1482
+ }
1483
+
1484
+ function useLatestRef(value) {
1485
+ const ref = React.useRef(value);
1486
+ index(() => {
1487
+ ref.current = value;
1488
+ });
1489
+ return ref;
1490
+ }
1491
+
1492
+ /**
1493
+ * Provides data to position a floating element.
1494
+ * @see https://floating-ui.com/docs/useFloating
1495
+ */
1496
+ function useFloating(options) {
1497
+ if (options === void 0) {
1498
+ options = {};
1499
+ }
1500
+ const {
1501
+ placement = 'bottom',
1502
+ strategy = 'absolute',
1503
+ middleware = [],
1504
+ platform,
1505
+ elements: {
1506
+ reference: externalReference,
1507
+ floating: externalFloating
1508
+ } = {},
1509
+ transform = true,
1510
+ whileElementsMounted,
1511
+ open
1512
+ } = options;
1513
+ const [data, setData] = React.useState({
1514
+ x: 0,
1515
+ y: 0,
1516
+ strategy,
1517
+ placement,
1518
+ middlewareData: {},
1519
+ isPositioned: false
1520
+ });
1521
+ const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
1522
+ if (!deepEqual(latestMiddleware, middleware)) {
1523
+ setLatestMiddleware(middleware);
1524
+ }
1525
+ const [_reference, _setReference] = React.useState(null);
1526
+ const [_floating, _setFloating] = React.useState(null);
1527
+ const setReference = React.useCallback(node => {
1528
+ if (node !== referenceRef.current) {
1529
+ referenceRef.current = node;
1530
+ _setReference(node);
1531
+ }
1532
+ }, []);
1533
+ const setFloating = React.useCallback(node => {
1534
+ if (node !== floatingRef.current) {
1535
+ floatingRef.current = node;
1536
+ _setFloating(node);
1537
+ }
1538
+ }, []);
1539
+ const referenceEl = externalReference || _reference;
1540
+ const floatingEl = externalFloating || _floating;
1541
+ const referenceRef = React.useRef(null);
1542
+ const floatingRef = React.useRef(null);
1543
+ const dataRef = React.useRef(data);
1544
+ const hasWhileElementsMounted = whileElementsMounted != null;
1545
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
1546
+ const platformRef = useLatestRef(platform);
1547
+ const openRef = useLatestRef(open);
1548
+ const update = React.useCallback(() => {
1549
+ if (!referenceRef.current || !floatingRef.current) {
1550
+ return;
1551
+ }
1552
+ const config = {
1553
+ placement,
1554
+ strategy,
1555
+ middleware: latestMiddleware
1556
+ };
1557
+ if (platformRef.current) {
1558
+ config.platform = platformRef.current;
1559
+ }
1560
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
1561
+ const fullData = {
1562
+ ...data,
1563
+ // The floating element's position may be recomputed while it's closed
1564
+ // but still mounted (such as when transitioning out). To ensure
1565
+ // `isPositioned` will be `false` initially on the next open, avoid
1566
+ // setting it to `true` when `open === false` (must be specified).
1567
+ isPositioned: openRef.current !== false
1568
+ };
1569
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
1570
+ dataRef.current = fullData;
1571
+ ReactDOM.flushSync(() => {
1572
+ setData(fullData);
1573
+ });
1574
+ }
1575
+ });
1576
+ }, [latestMiddleware, placement, strategy, platformRef, openRef]);
1577
+ index(() => {
1578
+ if (open === false && dataRef.current.isPositioned) {
1579
+ dataRef.current.isPositioned = false;
1580
+ setData(data => ({
1581
+ ...data,
1582
+ isPositioned: false
1583
+ }));
1584
+ }
1585
+ }, [open]);
1586
+ const isMountedRef = React.useRef(false);
1587
+ index(() => {
1588
+ isMountedRef.current = true;
1589
+ return () => {
1590
+ isMountedRef.current = false;
1591
+ };
1592
+ }, []);
1593
+ index(() => {
1594
+ if (referenceEl) referenceRef.current = referenceEl;
1595
+ if (floatingEl) floatingRef.current = floatingEl;
1596
+ if (referenceEl && floatingEl) {
1597
+ if (whileElementsMountedRef.current) {
1598
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
1599
+ }
1600
+ update();
1601
+ }
1602
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
1603
+ const refs = React.useMemo(() => ({
1604
+ reference: referenceRef,
1605
+ floating: floatingRef,
1606
+ setReference,
1607
+ setFloating
1608
+ }), [setReference, setFloating]);
1609
+ const elements = React.useMemo(() => ({
1610
+ reference: referenceEl,
1611
+ floating: floatingEl
1612
+ }), [referenceEl, floatingEl]);
1613
+ const floatingStyles = React.useMemo(() => {
1614
+ const initialStyles = {
1615
+ position: strategy,
1616
+ left: 0,
1617
+ top: 0
1618
+ };
1619
+ if (!elements.floating) {
1620
+ return initialStyles;
1621
+ }
1622
+ const x = roundByDPR(elements.floating, data.x);
1623
+ const y = roundByDPR(elements.floating, data.y);
1624
+ if (transform) {
1625
+ return {
1626
+ ...initialStyles,
1627
+ transform: "translate(" + x + "px, " + y + "px)",
1628
+ ...(getDPR(elements.floating) >= 1.5 && {
1629
+ willChange: 'transform'
1630
+ })
1631
+ };
1632
+ }
1633
+ return {
1634
+ position: strategy,
1635
+ left: x,
1636
+ top: y
1637
+ };
1638
+ }, [strategy, transform, elements.floating, data.x, data.y]);
1639
+ return React.useMemo(() => ({
1640
+ ...data,
1641
+ update,
1642
+ refs,
1643
+ elements,
1644
+ floatingStyles
1645
+ }), [data, update, refs, elements, floatingStyles]);
1646
+ }
1647
+
1648
+ /**
1649
+ * Modifies the placement by translating the floating element along the
1650
+ * specified axes.
1651
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
1652
+ * object may be passed.
1653
+ * @see https://floating-ui.com/docs/offset
1654
+ */
1655
+ const offset = (options, deps) => {
1656
+ const result = offset$1(options);
1657
+ return {
1658
+ name: result.name,
1659
+ fn: result.fn,
1660
+ options: [options, deps]
1661
+ };
1662
+ };
1663
+
1664
+ /**
1665
+ * Optimizes the visibility of the floating element by shifting it in order to
1666
+ * keep it in view when it will overflow the clipping boundary.
1667
+ * @see https://floating-ui.com/docs/shift
1668
+ */
1669
+ const shift = (options, deps) => {
1670
+ const result = shift$1(options);
1671
+ return {
1672
+ name: result.name,
1673
+ fn: result.fn,
1674
+ options: [options, deps]
1675
+ };
1676
+ };
1677
+
1678
+ /**
1679
+ * Built-in `limiter` that will stop `shift()` at a certain point.
1680
+ */
1681
+ const limitShift = (options, deps) => {
1682
+ const result = limitShift$1(options);
1683
+ return {
1684
+ fn: result.fn,
1685
+ options: [options, deps]
1686
+ };
1687
+ };
1688
+
1689
+ /**
1690
+ * Optimizes the visibility of the floating element by flipping the `placement`
1691
+ * in order to keep it in view when the preferred placement(s) will overflow the
1692
+ * clipping boundary. Alternative to `autoPlacement`.
1693
+ * @see https://floating-ui.com/docs/flip
1694
+ */
1695
+ const flip = (options, deps) => {
1696
+ const result = flip$1(options);
1697
+ return {
1698
+ name: result.name,
1699
+ fn: result.fn,
1700
+ options: [options, deps]
1701
+ };
1702
+ };
1703
+
1704
+ /**
1705
+ * Provides data that allows you to change the size of the floating element —
1706
+ * for instance, prevent it from overflowing the clipping boundary or match the
1707
+ * width of the reference element.
1708
+ * @see https://floating-ui.com/docs/size
1709
+ */
1710
+ const size = (options, deps) => {
1711
+ const result = size$1(options);
1712
+ return {
1713
+ name: result.name,
1714
+ fn: result.fn,
1715
+ options: [options, deps]
1716
+ };
1717
+ };
1718
+
1719
+ function useFloatingRootContext(options) {
1720
+ const {
1721
+ open = false,
1722
+ onOpenChange,
1723
+ elements = {}
1724
+ } = options;
1725
+ const floatingId = useId();
1726
+ const nested = useFloatingParentNodeId() != null;
1727
+ if (process.env.NODE_ENV !== 'production') {
1728
+ const optionDomReference = elements.reference;
1729
+ if (optionDomReference && !isElement(optionDomReference)) {
1730
+ console.error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `context.setPositionReference()`', 'instead.');
1731
+ }
1732
+ }
1733
+ const store = useRefWithInit(() => new FloatingRootStore({
1734
+ open,
1735
+ transitionStatus: undefined,
1736
+ onOpenChange,
1737
+ referenceElement: elements.reference ?? null,
1738
+ floatingElement: elements.floating ?? null,
1739
+ triggerElements: new PopupTriggerMap(),
1740
+ floatingId,
1741
+ syncOnly: false,
1742
+ nested
1743
+ })).current;
1744
+ useIsoLayoutEffect(() => {
1745
+ const valuesToSync = {
1746
+ open,
1747
+ floatingId
1748
+ };
1749
+
1750
+ // Only sync elements that are defined to avoid overwriting existing ones
1751
+ if (elements.reference !== undefined) {
1752
+ valuesToSync.referenceElement = elements.reference;
1753
+ valuesToSync.domReferenceElement = isElement(elements.reference) ? elements.reference : null;
1754
+ }
1755
+ if (elements.floating !== undefined) {
1756
+ valuesToSync.floatingElement = elements.floating;
1757
+ }
1758
+ store.update(valuesToSync);
1759
+ }, [open, floatingId, elements.reference, elements.floating, store]);
1760
+ store.context.onOpenChange = onOpenChange;
1761
+ store.context.nested = nested;
1762
+ return store;
1763
+ }
1764
+
1765
+ /**
1766
+ * Base UI's private `useFloating` path. The caller must supply the root store, so this skips the
1767
+ * internal root-context hook used by the public Floating UI-compatible API.
1768
+ */
1769
+ function useBaseUIFloating(options) {
1770
+ return useFloatingWithStore(options, options.rootContext);
1771
+ }
1772
+ function useFloatingWithStore(options, store) {
1773
+ const {
1774
+ nodeId,
1775
+ externalTree
1776
+ } = options;
1777
+ const referenceElement = store.useState('referenceElement');
1778
+ const floatingElement = store.useState('floatingElement');
1779
+ const domReferenceElement = store.useState('domReferenceElement');
1780
+ const open = store.useState('open');
1781
+ const floatingId = store.useState('floatingId');
1782
+ const [positionReference, setPositionReferenceRaw] = React.useState(null);
1783
+ const [localDomReference, setLocalDomReference] = React.useState(undefined);
1784
+ const [localFloatingElement, setLocalFloatingElement] = React.useState(undefined);
1785
+ const domReferenceRef = React.useRef(null);
1786
+ const tree = useFloatingTree(externalTree);
1787
+ const storeElements = React.useMemo(() => ({
1788
+ reference: referenceElement,
1789
+ floating: floatingElement,
1790
+ domReference: domReferenceElement
1791
+ }), [referenceElement, floatingElement, domReferenceElement]);
1792
+ const position = useFloating({
1793
+ ...options,
1794
+ elements: {
1795
+ ...storeElements,
1796
+ ...(positionReference && {
1797
+ reference: positionReference
1798
+ })
1799
+ }
1800
+ });
1801
+ const localDomReferenceElement = isElement(localDomReference) ? localDomReference : null;
1802
+ const syncedFloatingElement = localFloatingElement === undefined ? store.state.floatingElement : localFloatingElement;
1803
+ store.useSyncedValue('referenceElement', localDomReference ?? null);
1804
+ store.useSyncedValue('domReferenceElement', localDomReference === undefined ? domReferenceElement : localDomReferenceElement);
1805
+ store.useSyncedValue('floatingElement', syncedFloatingElement);
1806
+ const setPositionReference = React.useCallback(node => {
1807
+ const computedPositionReference = isElement(node) ? {
1808
+ getBoundingClientRect: () => node.getBoundingClientRect(),
1809
+ getClientRects: () => node.getClientRects(),
1810
+ contextElement: node
1811
+ } : node;
1812
+ // Store the positionReference in state if the DOM reference is specified externally via the
1813
+ // `elements.reference` option. This ensures that it won't be overridden on future renders.
1814
+ setPositionReferenceRaw(computedPositionReference);
1815
+ position.refs.setReference(computedPositionReference);
1816
+ }, [position.refs]);
1817
+ const setReference = React.useCallback(node => {
1818
+ if (isElement(node) || node === null) {
1819
+ domReferenceRef.current = node;
1820
+ setLocalDomReference(node);
1821
+ }
1822
+
1823
+ // Backwards-compatibility for passing a virtual element to `reference`
1824
+ // after it has set the DOM reference.
1825
+ if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
1826
+ // Don't allow setting virtual elements using the old technique back to
1827
+ // `null` to support `positionReference` + an unstable `reference`
1828
+ // callback ref.
1829
+ node !== null && !isElement(node)) {
1830
+ position.refs.setReference(node);
1831
+ }
1832
+ }, [position.refs, setLocalDomReference]);
1833
+ const setFloating = React.useCallback(node => {
1834
+ setLocalFloatingElement(node);
1835
+ position.refs.setFloating(node);
1836
+ }, [position.refs]);
1837
+ const refs = React.useMemo(() => ({
1838
+ ...position.refs,
1839
+ setReference,
1840
+ setFloating,
1841
+ setPositionReference,
1842
+ domReference: domReferenceRef
1843
+ }), [position.refs, setReference, setFloating, setPositionReference]);
1844
+ const elements = React.useMemo(() => ({
1845
+ ...position.elements,
1846
+ domReference: domReferenceElement
1847
+ }), [position.elements, domReferenceElement]);
1848
+ const context = React.useMemo(() => ({
1849
+ ...position,
1850
+ dataRef: store.context.dataRef,
1851
+ open,
1852
+ onOpenChange: store.setOpen,
1853
+ events: store.context.events,
1854
+ floatingId,
1855
+ refs,
1856
+ elements,
1857
+ nodeId,
1858
+ rootStore: store
1859
+ }), [position, refs, elements, nodeId, store, open, floatingId]);
1860
+ useIsoLayoutEffect(() => {
1861
+ if (domReferenceElement) {
1862
+ domReferenceRef.current = domReferenceElement;
1863
+ }
1864
+ }, [domReferenceElement]);
1865
+ useIsoLayoutEffect(() => {
1866
+ store.context.dataRef.current.floatingContext = context;
1867
+ const node = tree?.nodesRef.current.find(n => n.id === nodeId);
1868
+ if (node) {
1869
+ node.context = context;
1870
+ }
1871
+ });
1872
+ return React.useMemo(() => ({
1873
+ ...position,
1874
+ context,
1875
+ refs,
1876
+ elements,
1877
+ rootStore: store
1878
+ }), [position, refs, elements, context, store]);
1879
+ }
1880
+
1881
+ const ESCAPE = 'Escape';
1882
+
1883
+ // WebKit fires zero-delta `mousemove`/`pointermove` events when the list scrolls
1884
+ // beneath a stationary pointer, moving the highlight during keyboard navigation.
1885
+ // https://github.com/mui/base-ui/issues/4002
1886
+ function isStationaryWebKitPointer(event) {
1887
+ return webkit && event.movementX === 0 && event.movementY === 0;
1888
+ }
1889
+ function doSwitch(orientation, vertical, horizontal) {
1890
+ switch (orientation) {
1891
+ case 'vertical':
1892
+ return vertical;
1893
+ case 'horizontal':
1894
+ return horizontal;
1895
+ default:
1896
+ return vertical || horizontal;
1897
+ }
1898
+ }
1899
+ function isMainOrientationKey(key, orientation) {
1900
+ const vertical = key === ARROW_UP || key === ARROW_DOWN;
1901
+ const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
1902
+ return doSwitch(orientation, vertical, horizontal);
1903
+ }
1904
+ function isMainOrientationToEndKey(key, orientation, rtl) {
1905
+ const vertical = key === ARROW_DOWN;
1906
+ const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
1907
+ return doSwitch(orientation, vertical, horizontal) || key === 'Enter' || key === ' ' || key === '';
1908
+ }
1909
+ function isCrossOrientationOpenKey(key, orientation, rtl) {
1910
+ const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
1911
+ const horizontal = key === ARROW_DOWN;
1912
+ return doSwitch(orientation, vertical, horizontal);
1913
+ }
1914
+ function isCrossOrientationCloseKey(key, orientation, rtl, grid) {
1915
+ const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;
1916
+ const horizontal = key === ARROW_UP;
1917
+ if (orientation === 'both' || orientation === 'horizontal' && grid) {
1918
+ return key === ESCAPE;
1919
+ }
1920
+ return doSwitch(orientation, vertical, horizontal);
1921
+ }
1922
+ /**
1923
+ * Adds arrow key-based navigation of a list of items, either using real DOM
1924
+ * focus or virtual focus.
1925
+ * @see https://floating-ui.com/docs/useListNavigation
1926
+ */
1927
+ function useListNavigation(context, props) {
1928
+ const {
1929
+ listRef,
1930
+ activeIndex,
1931
+ onNavigate: onNavigateProp = () => {},
1932
+ enabled = true,
1933
+ selectedIndex = null,
1934
+ allowEscape = false,
1935
+ loopFocus = false,
1936
+ nested = false,
1937
+ rtl = false,
1938
+ virtual = false,
1939
+ focusItemOnOpen = 'auto',
1940
+ focusItemOnHover = true,
1941
+ openOnArrowKeyDown = true,
1942
+ disabledIndices = undefined,
1943
+ orientation = 'vertical',
1944
+ parentOrientation,
1945
+ id,
1946
+ resetOnPointerLeave = true,
1947
+ externalTree,
1948
+ grid: navigateGrid
1949
+ } = props;
1950
+ const isGrid = navigateGrid != null;
1951
+ if (process.env.NODE_ENV !== 'production') {
1952
+ if (allowEscape) {
1953
+ if (!loopFocus) {
1954
+ console.warn('`useListNavigation` looping must be enabled to allow escaping.');
1955
+ }
1956
+ if (!virtual) {
1957
+ console.warn('`useListNavigation` must be virtual to allow escaping.');
1958
+ }
1959
+ }
1960
+ if (orientation === 'vertical' && isGrid) {
1961
+ console.warn('In grid list navigation mode, the `orientation` should', 'be either "horizontal" or "both".');
1962
+ }
1963
+ }
1964
+ const store = 'rootStore' in context ? context.rootStore : context;
1965
+ const open = store.useState('open');
1966
+ const floatingElement = store.useState('floatingElement');
1967
+ const domReferenceElement = store.useState('domReferenceElement');
1968
+ const dataRef = store.context.dataRef;
1969
+ const floatingFocusElement = getFloatingFocusElement(floatingElement);
1970
+ const typeableComboboxReference = isTypeableCombobox(domReferenceElement);
1971
+ const floatingFocusElementRef = useValueAsRef(floatingFocusElement);
1972
+ const parentId = useFloatingParentNodeId();
1973
+ const tree = useFloatingTree(externalTree);
1974
+ const focusItemOnOpenRef = React.useRef(focusItemOnOpen);
1975
+ const indexRef = React.useRef(selectedIndex ?? -1);
1976
+ const keyRef = React.useRef(null);
1977
+ const isPointerModalityRef = React.useRef(true);
1978
+ const onNavigate = useStableCallback(event => {
1979
+ onNavigateProp(indexRef.current === -1 ? null : indexRef.current, event);
1980
+ });
1981
+ const previousMountedRef = React.useRef(!!floatingElement);
1982
+ const previousOpenRef = React.useRef(open);
1983
+ const forceSyncFocusRef = React.useRef(false);
1984
+ const forceScrollIntoViewRef = React.useRef(false);
1985
+ const cancelQueuedFocusRef = React.useRef(null);
1986
+ const disabledIndicesRef = useValueAsRef(disabledIndices);
1987
+ const latestOpenRef = useValueAsRef(open);
1988
+ const selectedIndexRef = useValueAsRef(selectedIndex);
1989
+ const resetOnPointerLeaveRef = useValueAsRef(resetOnPointerLeave);
1990
+ const focusFrame = useAnimationFrame();
1991
+ const waitForListPopulatedFrame = useAnimationFrame();
1992
+ const focusItem = useStableCallback(() => {
1993
+ function runFocus(item) {
1994
+ if (virtual) {
1995
+ tree?.events.emit('virtualfocus', item);
1996
+ } else {
1997
+ cancelQueuedFocusRef.current = enqueueFocus(item, {
1998
+ sync: forceSyncFocusRef.current,
1999
+ preventScroll: true
2000
+ });
2001
+ }
2002
+ }
2003
+ const initialItem = listRef.current[indexRef.current];
2004
+ const forceScrollIntoView = forceScrollIntoViewRef.current;
2005
+ if (initialItem) {
2006
+ runFocus(initialItem);
2007
+ }
2008
+ const scheduler = forceSyncFocusRef.current ? callback => callback() : callback => focusFrame.request(callback);
2009
+ scheduler(() => {
2010
+ const waitedItem = listRef.current[indexRef.current] || initialItem;
2011
+ if (!waitedItem) {
2012
+ return;
2013
+ }
2014
+ if (!initialItem) {
2015
+ runFocus(waitedItem);
2016
+ }
2017
+ const shouldScrollIntoView =
2018
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
2019
+ item && (forceScrollIntoView || !isPointerModalityRef.current);
2020
+ if (shouldScrollIntoView) {
2021
+ // JSDOM doesn't support `.scrollIntoView()` but it's widely supported
2022
+ // by all browsers.
2023
+ waitedItem.scrollIntoView?.({
2024
+ block: 'nearest',
2025
+ inline: 'nearest'
2026
+ });
2027
+ }
2028
+ });
2029
+ });
2030
+ useIsoLayoutEffect(() => {
2031
+ dataRef.current.orientation = orientation;
2032
+ }, [dataRef, orientation]);
2033
+
2034
+ // Sync `selectedIndex` to be the `activeIndex` upon opening the floating
2035
+ // element. Also, reset `activeIndex` upon closing the floating element.
2036
+ useIsoLayoutEffect(() => {
2037
+ if (!enabled) {
2038
+ return;
2039
+ }
2040
+ if (open && floatingElement) {
2041
+ indexRef.current = selectedIndex ?? -1;
2042
+ if (focusItemOnOpenRef.current && selectedIndex != null) {
2043
+ // Regardless of the pointer modality, we want to ensure the selected
2044
+ // item comes into view when the floating element is opened.
2045
+ forceScrollIntoViewRef.current = true;
2046
+ onNavigate();
2047
+ }
2048
+ } else if (previousMountedRef.current) {
2049
+ // Reset the active index when the list is no longer open and mounted (closing or
2050
+ // unmounting). `onNavigate` is a stable callback that always forwards to the latest
2051
+ // `onNavigate` prop.
2052
+ indexRef.current = -1;
2053
+ onNavigate();
2054
+ }
2055
+ }, [enabled, open, floatingElement, selectedIndex, onNavigate]);
2056
+
2057
+ // Sync `activeIndex` to be the focused item while the floating element is
2058
+ // open.
2059
+ useIsoLayoutEffect(() => {
2060
+ if (!enabled) {
2061
+ return;
2062
+ }
2063
+ if (!open) {
2064
+ forceSyncFocusRef.current = false;
2065
+ return;
2066
+ }
2067
+ if (!floatingElement) {
2068
+ return;
2069
+ }
2070
+ if (activeIndex == null) {
2071
+ forceSyncFocusRef.current = false;
2072
+ if (selectedIndexRef.current != null) {
2073
+ return;
2074
+ }
2075
+
2076
+ // Reset while the floating element was open (e.g. the list changed).
2077
+ if (previousMountedRef.current) {
2078
+ indexRef.current = -1;
2079
+ focusItem();
2080
+ }
2081
+
2082
+ // Initial sync.
2083
+ if ((!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === true && keyRef.current == null)) {
2084
+ let runs = 0;
2085
+ const waitForListPopulated = () => {
2086
+ if (listRef.current[0] == null) {
2087
+ // Avoid letting the browser paint if possible on the first try,
2088
+ // otherwise use rAF. Don't try more than twice, since something
2089
+ // is wrong otherwise.
2090
+ if (runs < 2) {
2091
+ const scheduler = runs ? callback => waitForListPopulatedFrame.request(callback) : queueMicrotask;
2092
+ scheduler(waitForListPopulated);
2093
+ }
2094
+ runs += 1;
2095
+ } else {
2096
+ // Initially focus the first non-disabled item. `disabledIndices` is deliberately
2097
+ // omitted here so attribute-disabled items (`disabled`/`aria-disabled`) are skipped
2098
+ // on open even when the consumer passes an empty `disabledIndices` array. Passing it
2099
+ // would regress that behavior (see mui/base-ui#2604).
2100
+ indexRef.current = keyRef.current == null || isMainOrientationToEndKey(keyRef.current, orientation, rtl) || nested ? getMinListIndex(listRef) : getMaxListIndex(listRef);
2101
+ keyRef.current = null;
2102
+ onNavigate();
2103
+ }
2104
+ };
2105
+ waitForListPopulated();
2106
+ }
2107
+ } else if (!isIndexOutOfListBounds(listRef.current, activeIndex)) {
2108
+ indexRef.current = activeIndex;
2109
+ focusItem();
2110
+ forceScrollIntoViewRef.current = false;
2111
+ }
2112
+ }, [enabled, open, floatingElement, activeIndex, selectedIndexRef, nested, listRef, orientation, rtl, onNavigate, focusItem, waitForListPopulatedFrame]);
2113
+
2114
+ // Ensure the parent floating element has focus when a nested child closes
2115
+ // to allow arrow key navigation to work after the pointer leaves the child.
2116
+ useIsoLayoutEffect(() => {
2117
+ if (!enabled || floatingElement || !tree || virtual || !previousMountedRef.current) {
2118
+ return;
2119
+ }
2120
+ const nodes = tree.nodesRef.current;
2121
+ const parent = nodes.find(node => node.id === parentId)?.context?.elements.floating;
2122
+ // `floatingElement` is null here (see the guard above), so resolve the owner document from an
2123
+ // in-DOM element for realm-safety (shadow DOM/iframes): the reference element, falling back to
2124
+ // the parent floating element when the reference is virtual (`domReferenceElement` is null).
2125
+ const activeEl = activeElement(ownerDocument(domReferenceElement ?? parent ?? null));
2126
+ const treeContainsActiveEl = nodes.some(node => node.context && contains(node.context.elements.floating, activeEl));
2127
+ if (parent && !treeContainsActiveEl && isPointerModalityRef.current) {
2128
+ parent.focus({
2129
+ preventScroll: true
2130
+ });
2131
+ }
2132
+ }, [enabled, floatingElement, domReferenceElement, tree, parentId, virtual]);
2133
+ useIsoLayoutEffect(() => {
2134
+ previousOpenRef.current = open;
2135
+ previousMountedRef.current = !!floatingElement;
2136
+ });
2137
+ useIsoLayoutEffect(() => {
2138
+ if (!open) {
2139
+ keyRef.current = null;
2140
+ focusItemOnOpenRef.current = focusItemOnOpen;
2141
+ }
2142
+ }, [open, focusItemOnOpen]);
2143
+ const hasActiveIndex = activeIndex != null;
2144
+ const syncCurrentTarget = useStableCallback(event => {
2145
+ if (!latestOpenRef.current) {
2146
+ return;
2147
+ }
2148
+ const index = listRef.current.indexOf(event.currentTarget);
2149
+ if (index !== -1 && (indexRef.current !== index || activeIndex !== index)) {
2150
+ indexRef.current = index;
2151
+ onNavigate(event);
2152
+ }
2153
+ });
2154
+ const getParentOrientation = useStableCallback(() => {
2155
+ return parentOrientation ?? tree?.nodesRef.current.find(node => node.id === parentId)?.context?.dataRef?.current.orientation;
2156
+ });
2157
+ const getMinEnabledIndex = useStableCallback(() => {
2158
+ return getMinListIndex(listRef, disabledIndicesRef.current);
2159
+ });
2160
+ const commonOnKeyDown = useStableCallback(event => {
2161
+ isPointerModalityRef.current = false;
2162
+ forceSyncFocusRef.current = true;
2163
+
2164
+ // When composing a character, Chrome fires ArrowDown twice. Firefox/Safari
2165
+ // don't appear to suffer from this. `event.isComposing` is avoided due to
2166
+ // Safari not supporting it properly (although it's not needed in the first
2167
+ // place for Safari, just avoiding any possible issues).
2168
+ if (event.which === 229) {
2169
+ return;
2170
+ }
2171
+
2172
+ // If the floating element is animating out, ignore navigation. Otherwise,
2173
+ // the `activeIndex` gets set to 0 despite not being open so the next time
2174
+ // the user ArrowDowns, the first item won't be focused.
2175
+ if (!latestOpenRef.current && event.currentTarget === floatingFocusElementRef.current) {
2176
+ return;
2177
+ }
2178
+ if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl, isGrid)) {
2179
+ // If the nested list's close key is also the parent navigation key,
2180
+ // let the parent navigate. Otherwise, stop propagating the event.
2181
+ if (!isMainOrientationKey(event.key, getParentOrientation())) {
2182
+ stopEvent(event);
2183
+ }
2184
+ store.setOpen(false, createChangeEventDetails(listNavigation, event.nativeEvent));
2185
+ if (isHTMLElement(domReferenceElement)) {
2186
+ if (virtual) {
2187
+ tree?.events.emit('virtualfocus', domReferenceElement);
2188
+ } else {
2189
+ domReferenceElement.focus();
2190
+ }
2191
+ }
2192
+ return;
2193
+ }
2194
+ const currentIndex = indexRef.current;
2195
+ const minIndex = getMinListIndex(listRef, disabledIndices);
2196
+ const maxIndex = getMaxListIndex(listRef, disabledIndices);
2197
+ if (!typeableComboboxReference) {
2198
+ if (event.key === 'Home') {
2199
+ stopEvent(event);
2200
+ indexRef.current = minIndex;
2201
+ onNavigate(event);
2202
+ }
2203
+ if (event.key === 'End') {
2204
+ stopEvent(event);
2205
+ indexRef.current = maxIndex;
2206
+ onNavigate(event);
2207
+ }
2208
+ }
2209
+
2210
+ // Grid navigation is injected by grid-capable consumers so non-grid
2211
+ // consumers (menu, select) tree-shake the grid helpers out.
2212
+ if (navigateGrid != null) {
2213
+ const index = navigateGrid(event, indexRef.current, listRef, orientation, loopFocus, rtl, disabledIndices, minIndex, maxIndex);
2214
+ if (index != null) {
2215
+ indexRef.current = index;
2216
+ onNavigate(event);
2217
+ }
2218
+ if (orientation === 'both') {
2219
+ return;
2220
+ }
2221
+ }
2222
+ if (isMainOrientationKey(event.key, orientation)) {
2223
+ stopEvent(event);
2224
+
2225
+ // Reset the index if no item is focused.
2226
+ if (open && !virtual && activeElement(event.currentTarget.ownerDocument) === event.currentTarget) {
2227
+ indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex;
2228
+ onNavigate(event);
2229
+ return;
2230
+ }
2231
+ if (isMainOrientationToEndKey(event.key, orientation, rtl)) {
2232
+ if (loopFocus) {
2233
+ if (currentIndex >= maxIndex) {
2234
+ if (allowEscape && currentIndex !== listRef.current.length) {
2235
+ indexRef.current = -1;
2236
+ } else {
2237
+ // Give time for virtualizers to update the listRef.
2238
+ forceSyncFocusRef.current = false;
2239
+ indexRef.current = minIndex;
2240
+ }
2241
+ } else {
2242
+ indexRef.current = findNonDisabledListIndex(listRef.current, {
2243
+ startingIndex: currentIndex,
2244
+ disabledIndices
2245
+ });
2246
+ }
2247
+ } else {
2248
+ indexRef.current = Math.min(maxIndex, findNonDisabledListIndex(listRef.current, {
2249
+ startingIndex: currentIndex,
2250
+ disabledIndices
2251
+ }));
2252
+ }
2253
+ } else if (loopFocus) {
2254
+ if (currentIndex <= minIndex) {
2255
+ if (allowEscape && currentIndex !== -1) {
2256
+ indexRef.current = listRef.current.length;
2257
+ } else {
2258
+ // Give time for virtualizers to update the listRef.
2259
+ forceSyncFocusRef.current = false;
2260
+ indexRef.current = maxIndex;
2261
+ }
2262
+ } else {
2263
+ indexRef.current = findNonDisabledListIndex(listRef.current, {
2264
+ startingIndex: currentIndex,
2265
+ decrement: true,
2266
+ disabledIndices
2267
+ });
2268
+ }
2269
+ } else {
2270
+ indexRef.current = Math.max(minIndex, findNonDisabledListIndex(listRef.current, {
2271
+ startingIndex: currentIndex,
2272
+ decrement: true,
2273
+ disabledIndices
2274
+ }));
2275
+ }
2276
+ if (isIndexOutOfListBounds(listRef.current, indexRef.current)) {
2277
+ indexRef.current = -1;
2278
+ }
2279
+ onNavigate(event);
2280
+ }
2281
+ });
2282
+ const item = React.useMemo(() => {
2283
+ const itemProps = {
2284
+ onFocus(event) {
2285
+ forceSyncFocusRef.current = true;
2286
+ syncCurrentTarget(event);
2287
+ },
2288
+ onClick: ({
2289
+ currentTarget
2290
+ }) => currentTarget.focus({
2291
+ preventScroll: true
2292
+ }),
2293
+ // Safari
2294
+ onMouseMove(event) {
2295
+ if (isStationaryWebKitPointer(event)) {
2296
+ return;
2297
+ }
2298
+ forceSyncFocusRef.current = true;
2299
+ forceScrollIntoViewRef.current = false;
2300
+ if (focusItemOnHover) {
2301
+ syncCurrentTarget(event);
2302
+ }
2303
+ },
2304
+ onPointerLeave(event) {
2305
+ if (!latestOpenRef.current || !isPointerModalityRef.current || event.pointerType === 'touch') {
2306
+ return;
2307
+ }
2308
+ forceSyncFocusRef.current = true;
2309
+ const relatedTarget = event.relatedTarget;
2310
+ if (!focusItemOnHover || listRef.current.includes(relatedTarget)) {
2311
+ return;
2312
+ }
2313
+ if (!resetOnPointerLeaveRef.current) {
2314
+ return;
2315
+ }
2316
+ cancelQueuedFocusRef.current?.();
2317
+ cancelQueuedFocusRef.current = null;
2318
+ indexRef.current = -1;
2319
+ onNavigate(event);
2320
+ if (!virtual) {
2321
+ const floatingFocusEl = floatingFocusElementRef.current;
2322
+ const activeEl = activeElement(ownerDocument(floatingFocusEl));
2323
+ if (floatingFocusEl && contains(floatingFocusEl, activeEl)) {
2324
+ floatingFocusEl.focus({
2325
+ preventScroll: true
2326
+ });
2327
+ }
2328
+ }
2329
+ }
2330
+ };
2331
+ return itemProps;
2332
+ }, [syncCurrentTarget, latestOpenRef, floatingFocusElementRef, focusItemOnHover, listRef, onNavigate, resetOnPointerLeaveRef, virtual]);
2333
+ const ariaActiveDescendantProp = React.useMemo(() => {
2334
+ return virtual && open && hasActiveIndex && {
2335
+ 'aria-activedescendant': `${id}-${activeIndex}`
2336
+ };
2337
+ }, [virtual, open, hasActiveIndex, id, activeIndex]);
2338
+ const floating = React.useMemo(() => {
2339
+ return {
2340
+ 'aria-orientation': orientation === 'both' ? undefined : orientation,
2341
+ ...(!typeableComboboxReference ? ariaActiveDescendantProp : {}),
2342
+ onKeyDown(event) {
2343
+ // Close submenu on Shift+Tab
2344
+ if (event.key === 'Tab' && event.shiftKey && open && !virtual) {
2345
+ // If the event originated from within a nested element (e.g., a Dialog opened from
2346
+ // within the menu), don't close the menu. The nested element has its own focus
2347
+ // management and should handle the Tab key.
2348
+ const target = getTarget(event.nativeEvent);
2349
+ if (target && !contains(floatingFocusElementRef.current, target)) {
2350
+ return;
2351
+ }
2352
+ stopEvent(event);
2353
+ store.setOpen(false, createChangeEventDetails(focusOut, event.nativeEvent));
2354
+ if (isHTMLElement(domReferenceElement)) {
2355
+ domReferenceElement.focus();
2356
+ }
2357
+ return;
2358
+ }
2359
+ commonOnKeyDown(event);
2360
+ },
2361
+ onPointerMove(event) {
2362
+ if (isStationaryWebKitPointer(event)) {
2363
+ return;
2364
+ }
2365
+ isPointerModalityRef.current = true;
2366
+ }
2367
+ };
2368
+ }, [ariaActiveDescendantProp, commonOnKeyDown, floatingFocusElementRef, orientation, typeableComboboxReference, store, open, virtual, domReferenceElement]);
2369
+ const trigger = React.useMemo(() => {
2370
+ function openOnNavigationKeyDown(event) {
2371
+ store.setOpen(true, createChangeEventDetails(listNavigation, event.nativeEvent, event.currentTarget));
2372
+ }
2373
+ function checkVirtualMouse(event) {
2374
+ if (focusItemOnOpen === 'auto' && isVirtualClick(event.nativeEvent)) {
2375
+ focusItemOnOpenRef.current = !virtual;
2376
+ }
2377
+ }
2378
+ function checkVirtualPointer(event) {
2379
+ // `pointerdown` fires first, reset the state then perform the checks.
2380
+ focusItemOnOpenRef.current = focusItemOnOpen;
2381
+ if (focusItemOnOpen === 'auto' && isVirtualPointerEvent(event.nativeEvent)) {
2382
+ focusItemOnOpenRef.current = true;
2383
+ }
2384
+ }
2385
+ return {
2386
+ onKeyDown(event) {
2387
+ // non-reactive open state (to prevent re-creation of the handler)
2388
+ const currentOpen = store.select('open');
2389
+ isPointerModalityRef.current = false;
2390
+ const isArrowKey = event.key.startsWith('Arrow');
2391
+ const isParentCrossOpenKey = isCrossOrientationOpenKey(event.key, getParentOrientation(), rtl);
2392
+ const isMainKey = isMainOrientationKey(event.key, orientation);
2393
+ const isNavigationKey = (nested ? isParentCrossOpenKey : isMainKey) || event.key === 'Enter' || event.key.trim() === '';
2394
+ if (virtual && currentOpen) {
2395
+ return commonOnKeyDown(event);
2396
+ }
2397
+
2398
+ // If a floating element should not open on arrow key down, avoid
2399
+ // setting `activeIndex` while it's closed.
2400
+ if (!currentOpen && !openOnArrowKeyDown && isArrowKey) {
2401
+ return undefined;
2402
+ }
2403
+ if (isNavigationKey) {
2404
+ const isParentMainKey = isMainOrientationKey(event.key, getParentOrientation());
2405
+ keyRef.current = nested && isParentMainKey ? null : event.key;
2406
+ }
2407
+ if (nested) {
2408
+ if (isParentCrossOpenKey) {
2409
+ stopEvent(event);
2410
+ if (currentOpen) {
2411
+ indexRef.current = getMinEnabledIndex();
2412
+ onNavigate(event);
2413
+ } else {
2414
+ openOnNavigationKeyDown(event);
2415
+ }
2416
+ }
2417
+ return undefined;
2418
+ }
2419
+ if (isMainKey) {
2420
+ if (selectedIndexRef.current != null) {
2421
+ indexRef.current = selectedIndexRef.current;
2422
+ }
2423
+ stopEvent(event);
2424
+ if (!currentOpen && openOnArrowKeyDown) {
2425
+ openOnNavigationKeyDown(event);
2426
+ } else {
2427
+ commonOnKeyDown(event);
2428
+ }
2429
+ if (currentOpen) {
2430
+ onNavigate(event);
2431
+ }
2432
+ }
2433
+ return undefined;
2434
+ },
2435
+ onFocus(event) {
2436
+ if (store.select('open') && !virtual) {
2437
+ indexRef.current = -1;
2438
+ onNavigate(event);
2439
+ }
2440
+ },
2441
+ onPointerDown: checkVirtualPointer,
2442
+ onPointerEnter: checkVirtualPointer,
2443
+ onMouseDown: checkVirtualMouse,
2444
+ onClick: checkVirtualMouse
2445
+ };
2446
+ }, [commonOnKeyDown, focusItemOnOpen, getMinEnabledIndex, nested, onNavigate, store, openOnArrowKeyDown, orientation, getParentOrientation, rtl, selectedIndexRef, virtual]);
2447
+ const reference = React.useMemo(() => {
2448
+ return {
2449
+ ...ariaActiveDescendantProp,
2450
+ ...trigger
2451
+ };
2452
+ }, [ariaActiveDescendantProp, trigger]);
2453
+ return React.useMemo(() => enabled ? {
2454
+ reference,
2455
+ floating,
2456
+ item,
2457
+ trigger
2458
+ } : {}, [enabled, reference, floating, trigger, item]);
2459
+ }
2460
+
2461
+ /**
2462
+ * Provides a matching callback that can be used to focus an item as the user
2463
+ * types, often used in tandem with `useListNavigation()`.
2464
+ * @see https://floating-ui.com/docs/useTypeahead
2465
+ */
2466
+ function useTypeahead(context, props) {
2467
+ const {
2468
+ listRef,
2469
+ elementsRef,
2470
+ activeIndex,
2471
+ onMatch: onMatchProp,
2472
+ disabledIndices,
2473
+ onTyping,
2474
+ enabled = true,
2475
+ resetMs = 750,
2476
+ selectedIndex = null
2477
+ } = props;
2478
+ const store = 'rootStore' in context ? context.rootStore : context;
2479
+ const open = store.useState('open');
2480
+ const timeout = useTimeout();
2481
+ const stringRef = React.useRef('');
2482
+ const prevIndexRef = React.useRef(selectedIndex ?? activeIndex ?? -1);
2483
+ const matchIndexRef = React.useRef(null);
2484
+ const onKeyDown = useStableCallback(event => {
2485
+ function getElement(index) {
2486
+ return elementsRef?.current[index];
2487
+ }
2488
+ function isItemAvailable(index) {
2489
+ const element = getElement(index);
2490
+ if (element && !isElementVisible(element) || element?.matches(':disabled')) {
2491
+ return false;
2492
+ }
2493
+ // Visibility and native disabled state are handled above; pass an empty
2494
+ // element list so `isListIndexDisabled` resolves only the explicit
2495
+ // `disabledIndices` (array/predicate) and skips its own fallbacks.
2496
+ // Consumers that don't pass `disabledIndices` keep matching every visible
2497
+ // item except native disabled elements provided through `elementsRef`.
2498
+ return disabledIndices == null || !isListIndexDisabled(EMPTY_ARRAY, index, disabledIndices);
2499
+ }
2500
+ function getMatchingIndex(list, string, startIndex = 0) {
2501
+ if (list.length === 0) {
2502
+ return -1;
2503
+ }
2504
+ const normalizedStartIndex = (startIndex % list.length + list.length) % list.length;
2505
+ const lowerString = string.toLowerCase();
2506
+ for (let offset = 0; offset < list.length; offset += 1) {
2507
+ const index = (normalizedStartIndex + offset) % list.length;
2508
+ const text = list[index];
2509
+ if (!text?.toLowerCase().startsWith(lowerString) || !isItemAvailable(index)) {
2510
+ continue;
2511
+ }
2512
+ return index;
2513
+ }
2514
+ return -1;
2515
+ }
2516
+ const listContent = listRef.current;
2517
+ if (stringRef.current.length > 0 && event.key === ' ') {
2518
+ // Space should continue the in-progress typeahead session.
2519
+ stopEvent(event);
2520
+ onTyping?.(true);
2521
+ }
2522
+ if (stringRef.current.length > 0 && stringRef.current[0] !== ' ') {
2523
+ if (getMatchingIndex(listContent, stringRef.current) === -1 && event.key !== ' ') {
2524
+ onTyping?.(false);
2525
+ }
2526
+ }
2527
+ if (listContent == null ||
2528
+ // Character key.
2529
+ event.key.length !== 1 ||
2530
+ // Modifier key.
2531
+ event.ctrlKey || event.metaKey || event.altKey) {
2532
+ return;
2533
+ }
2534
+ if (open && event.key !== ' ') {
2535
+ stopEvent(event);
2536
+ onTyping?.(true);
2537
+ }
2538
+
2539
+ // Capture whether this is a new typing session before mutating the string.
2540
+ const isNewSession = stringRef.current === '';
2541
+ if (isNewSession) {
2542
+ prevIndexRef.current = selectedIndex ?? activeIndex ?? -1;
2543
+ }
2544
+
2545
+ // Bail out if the list contains a word like "llama" or "aaron". TODO:
2546
+ // allow it in this case, too. Unavailable items are skipped while matching, so
2547
+ // they must be ignored here as well — otherwise a hidden or disabled double-letter
2548
+ // label would block rapid cycling through the available items.
2549
+ const allowRapidSuccessionOfFirstLetter = listContent.every((text, index) => text && isItemAvailable(index) ? text[0]?.toLowerCase() !== text[1]?.toLowerCase() : true);
2550
+
2551
+ // Allows the user to cycle through items that start with the same letter
2552
+ // in rapid succession.
2553
+ if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
2554
+ stringRef.current = '';
2555
+ prevIndexRef.current = matchIndexRef.current;
2556
+ }
2557
+ stringRef.current += event.key;
2558
+ timeout.start(resetMs, () => {
2559
+ stringRef.current = '';
2560
+ prevIndexRef.current = matchIndexRef.current;
2561
+ onTyping?.(false);
2562
+ });
2563
+
2564
+ // Compute the starting index for this search.
2565
+ // If this is a new typing session (string is empty), base it on the current
2566
+ // selection/active item; otherwise continue from the last matched index.
2567
+ const prevIndex = isNewSession ? selectedIndex ?? activeIndex ?? -1 : prevIndexRef.current;
2568
+ const startIndex = (prevIndex ?? 0) + 1;
2569
+ const index = getMatchingIndex(listContent, stringRef.current, startIndex);
2570
+ if (index !== -1) {
2571
+ onMatchProp?.(index);
2572
+ matchIndexRef.current = index;
2573
+ } else if (event.key !== ' ') {
2574
+ stringRef.current = '';
2575
+ onTyping?.(false);
2576
+ }
2577
+ });
2578
+ const onBlur = useStableCallback(event => {
2579
+ const next = event.relatedTarget;
2580
+ const currentDomReferenceElement = store.select('domReferenceElement');
2581
+ const currentFloatingElement = store.select('floatingElement');
2582
+ const withinComposite = contains(currentDomReferenceElement, next) || contains(currentFloatingElement, next);
2583
+
2584
+ // Keep the session if focus moves within the composite (reference <-> floating).
2585
+ if (withinComposite) {
2586
+ return;
2587
+ }
2588
+
2589
+ // End the current typing session when focus leaves the composite entirely.
2590
+ timeout.clear();
2591
+ stringRef.current = '';
2592
+ prevIndexRef.current = matchIndexRef.current;
2593
+ onTyping?.(false);
2594
+ });
2595
+ useIsoLayoutEffect(() => {
2596
+ if (!open && selectedIndex !== null) {
2597
+ return;
2598
+ }
2599
+ timeout.clear();
2600
+ matchIndexRef.current = null;
2601
+ if (stringRef.current !== '') {
2602
+ stringRef.current = '';
2603
+ }
2604
+ }, [open, selectedIndex, timeout]);
2605
+ const sharedProps = React.useMemo(() => ({
2606
+ onKeyDown,
2607
+ onBlur
2608
+ }), [onKeyDown, onBlur]);
2609
+ return React.useMemo(() => enabled ? {
2610
+ reference: sharedProps,
2611
+ floating: sharedProps
2612
+ } : {}, [enabled, sharedProps]);
2613
+ }
2614
+
2615
+ const defaultItemEquality = (itemValue, selectedValue) => Object.is(itemValue, selectedValue);
2616
+ function compareItemEquality(itemValue, selectedValue, comparer) {
2617
+ if (itemValue == null || selectedValue == null) {
2618
+ return Object.is(itemValue, selectedValue);
2619
+ }
2620
+ return comparer(itemValue, selectedValue);
2621
+ }
2622
+ function selectedValueIncludes(selectedValues, itemValue, comparer) {
2623
+ if (!selectedValues || selectedValues.length === 0) {
2624
+ return false;
2625
+ }
2626
+ return selectedValues.some(selectedValue => {
2627
+ if (selectedValue === undefined) {
2628
+ return false;
2629
+ }
2630
+ return compareItemEquality(itemValue, selectedValue, comparer);
2631
+ });
2632
+ }
2633
+ function findItemIndex(itemValues, selectedValue, comparer) {
2634
+ if (!itemValues || itemValues.length === 0) {
2635
+ return -1;
2636
+ }
2637
+ return itemValues.findIndex(itemValue => {
2638
+ if (itemValue === undefined) {
2639
+ return false;
2640
+ }
2641
+ return compareItemEquality(itemValue, selectedValue, comparer);
2642
+ });
2643
+ }
2644
+ function findSelectionIndex(itemValues, selectedValue, comparer, multiple) {
2645
+ // Only unwrap in multiple mode: an array can itself be a valid single-select value.
2646
+ const lastValue = multiple && Array.isArray(selectedValue) ? selectedValue[selectedValue.length - 1] : selectedValue;
2647
+ const index = findItemIndex(itemValues, lastValue, comparer);
2648
+ return index === -1 ? null : index;
2649
+ }
2650
+ function removeItem(selectedValues, itemValue, comparer) {
2651
+ return selectedValues.filter(selectedValue => !compareItemEquality(itemValue, selectedValue, comparer));
2652
+ }
2653
+
2654
+ function serializeValue(value) {
2655
+ if (value == null) {
2656
+ return '';
2657
+ }
2658
+ if (typeof value === 'string') {
2659
+ return value;
2660
+ }
2661
+ try {
2662
+ return JSON.stringify(value);
2663
+ } catch {
2664
+ return String(value);
2665
+ }
2666
+ }
2667
+
2668
+ function isGroupedItems(items) {
2669
+ return items != null && items.length > 0 && typeof items[0] === 'object' && items[0] != null && 'items' in items[0];
2670
+ }
2671
+
2672
+ /**
2673
+ * Checks if the items array contains an item with a null value that has a non-null label.
2674
+ */
2675
+ function hasNullItemLabel(items) {
2676
+ if (!Array.isArray(items)) {
2677
+ return items != null && 'null' in items;
2678
+ }
2679
+ const arrayItems = items;
2680
+ if (isGroupedItems(arrayItems)) {
2681
+ for (const group of arrayItems) {
2682
+ for (const item of group.items) {
2683
+ if (item && item.value == null && item.label != null) {
2684
+ return true;
2685
+ }
2686
+ }
2687
+ }
2688
+ return false;
2689
+ }
2690
+ for (const item of arrayItems) {
2691
+ if (item && item.value == null && item.label != null) {
2692
+ return true;
2693
+ }
2694
+ }
2695
+ return false;
2696
+ }
2697
+ function stringifyAsLabel(item, itemToStringLabel) {
2698
+ if (itemToStringLabel && item != null) {
2699
+ return itemToStringLabel(item) ?? '';
2700
+ }
2701
+ if (item && typeof item === 'object') {
2702
+ if ('label' in item && item.label != null) {
2703
+ return String(item.label);
2704
+ }
2705
+ if ('value' in item) {
2706
+ return String(item.value);
2707
+ }
2708
+ }
2709
+ return serializeValue(item);
2710
+ }
2711
+ function stringifyAsValue(item, itemToStringValue) {
2712
+ if (itemToStringValue && item != null) {
2713
+ return itemToStringValue(item) ?? '';
2714
+ }
2715
+ if (item && typeof item === 'object' && 'value' in item && 'label' in item) {
2716
+ return serializeValue(item.value);
2717
+ }
2718
+ return serializeValue(item);
2719
+ }
2720
+ function resolveSelectedLabel(value, items, itemToStringLabel) {
2721
+ function fallback() {
2722
+ return stringifyAsLabel(value, itemToStringLabel);
2723
+ }
2724
+ if (itemToStringLabel && value != null) {
2725
+ return itemToStringLabel(value);
2726
+ }
2727
+
2728
+ // Custom object with explicit label takes precedence
2729
+ if (value && typeof value === 'object' && 'label' in value && value.label != null) {
2730
+ return value.label;
2731
+ }
2732
+
2733
+ // Items provided as plain record map
2734
+ if (items && !Array.isArray(items)) {
2735
+ return items[value] ?? fallback();
2736
+ }
2737
+
2738
+ // Items provided as array (flat or grouped)
2739
+ if (Array.isArray(items)) {
2740
+ const arrayItems = items;
2741
+ const flatItems = isGroupedItems(arrayItems) ? arrayItems.flatMap(group => group.items) : arrayItems;
2742
+ if (value == null || typeof value !== 'object') {
2743
+ const match = flatItems.find(item => item.value === value);
2744
+ if (match && match.label != null) {
2745
+ return match.label;
2746
+ }
2747
+ return fallback();
2748
+ }
2749
+
2750
+ // Object without explicit label: try matching by its `value` property
2751
+ if ('value' in value) {
2752
+ const match = flatItems.find(item => item && item.value === value.value);
2753
+ if (match && match.label != null) {
2754
+ return match.label;
2755
+ }
2756
+ }
2757
+ }
2758
+ return fallback();
2759
+ }
2760
+ function resolveMultipleLabels(values, items, itemToStringLabel) {
2761
+ return values.reduce((acc, value, index) => {
2762
+ if (index > 0) {
2763
+ acc.push(', ');
2764
+ }
2765
+ acc.push(/*#__PURE__*/jsx(React.Fragment, {
2766
+ children: resolveSelectedLabel(value, items, itemToStringLabel)
2767
+ }, index));
2768
+ return acc;
2769
+ }, []);
2770
+ }
2771
+
2772
+ const DEFAULT_VALIDITY_STATE = {
2773
+ badInput: false,
2774
+ customError: false,
2775
+ patternMismatch: false,
2776
+ rangeOverflow: false,
2777
+ rangeUnderflow: false,
2778
+ stepMismatch: false,
2779
+ tooLong: false,
2780
+ tooShort: false,
2781
+ typeMismatch: false,
2782
+ valid: null,
2783
+ valueMissing: false
2784
+ };
2785
+ const DEFAULT_FIELD_STATE_ATTRIBUTES = {
2786
+ valid: null,
2787
+ touched: false,
2788
+ dirty: false,
2789
+ filled: false,
2790
+ focused: false
2791
+ };
2792
+ const DEFAULT_FIELD_ROOT_STATE = {
2793
+ disabled: false,
2794
+ ...DEFAULT_FIELD_STATE_ATTRIBUTES
2795
+ };
2796
+ const fieldValidityMapping = {
2797
+ valid(value) {
2798
+ if (value === null) {
2799
+ return null;
2800
+ }
2801
+ if (value) {
2802
+ return {
2803
+ 'data-valid': ''
2804
+ };
2805
+ }
2806
+ return {
2807
+ 'data-invalid': ''
2808
+ };
2809
+ }
2810
+ };
2811
+
2812
+ const DEFAULT_FIELD_ROOT_CONTEXT = {
2813
+ invalid: undefined,
2814
+ name: undefined,
2815
+ validityData: {
2816
+ state: DEFAULT_VALIDITY_STATE,
2817
+ errors: [],
2818
+ error: '',
2819
+ value: '',
2820
+ initialValue: null
2821
+ },
2822
+ setValidityData: NOOP,
2823
+ disabled: undefined,
2824
+ setTouched: NOOP,
2825
+ setDirty: NOOP,
2826
+ setFilled: NOOP,
2827
+ setFocused: NOOP,
2828
+ validationMode: 'onSubmit',
2829
+ shouldValidateOnChange: () => false,
2830
+ state: DEFAULT_FIELD_ROOT_STATE,
2831
+ registerFieldControl: NOOP,
2832
+ validation: {
2833
+ getValidationProps: (_disabled, props = EMPTY_OBJECT) => props,
2834
+ inputRef: {
2835
+ current: null
2836
+ },
2837
+ registeredInputs: new Map(),
2838
+ registerInput: NOOP,
2839
+ getInputControl: () => null,
2840
+ commit: async () => {},
2841
+ change: NOOP
2842
+ }
2843
+ };
2844
+ const FieldRootContext = /*#__PURE__*/React.createContext(DEFAULT_FIELD_ROOT_CONTEXT);
2845
+ if (process.env.NODE_ENV !== "production") FieldRootContext.displayName = "FieldRootContext";
2846
+ function useFieldRootContext(optional = true) {
2847
+ const context = React.useContext(FieldRootContext);
2848
+ if (context.setValidityData === NOOP && !optional) {
2849
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: FieldRootContext is missing. Field parts must be placed within <Field.Root>.' : formatErrorMessage(28));
2850
+ }
2851
+ return context;
2852
+ }
2853
+
2854
+ function useRegisterFieldControl(controlRef, id, value, getFormValueOverride, enabled = true, name) {
2855
+ const {
2856
+ registerFieldControl
2857
+ } = useFieldRootContext();
2858
+ const sourceRef = useRefWithInit(() => Symbol());
2859
+
2860
+ // Re-register without unregistering first: re-registration with the same id updates the
2861
+ // form's fields Map entry in place, while a delete + re-add would move the field to the
2862
+ // end of the Map every time its value changes.
2863
+ useIsoLayoutEffect(() => {
2864
+ const source = sourceRef.current;
2865
+ if (!enabled) {
2866
+ registerFieldControl(source, undefined);
2867
+ return;
2868
+ }
2869
+ const registration = {
2870
+ controlRef,
2871
+ getValue: getFormValueOverride,
2872
+ id,
2873
+ name,
2874
+ value
2875
+ };
2876
+ registerFieldControl(source, registration);
2877
+ }, [controlRef, enabled, getFormValueOverride, id, name, registerFieldControl, sourceRef, value]);
2878
+ useIsoLayoutEffect(() => {
2879
+ const source = sourceRef.current;
2880
+ return () => {
2881
+ registerFieldControl(source, undefined);
2882
+ };
2883
+ }, [registerFieldControl, sourceRef]);
2884
+ }
2885
+
2886
+ const FormContext = /*#__PURE__*/React.createContext({
2887
+ elementRef: {
2888
+ current: null
2889
+ },
2890
+ formRef: {
2891
+ current: {
2892
+ fields: new Map()
2893
+ }
2894
+ },
2895
+ errors: {},
2896
+ clearErrors: NOOP,
2897
+ validationMode: 'onSubmit',
2898
+ submitAttemptedRef: {
2899
+ current: false
2900
+ }
2901
+ });
2902
+ if (process.env.NODE_ENV !== "production") FormContext.displayName = "FormContext";
2903
+ function useFormContext() {
2904
+ return React.useContext(FormContext);
2905
+ }
2906
+
2907
+ /**
2908
+ * A context for providing [labelable elements](https://html.spec.whatwg.org/multipage/forms.html#category-label)\
2909
+ * with an accessible name (label) and description.
2910
+ */
2911
+ const LabelableContext = /*#__PURE__*/React.createContext({
2912
+ controlId: undefined,
2913
+ registerControlId: NOOP,
2914
+ labelId: undefined,
2915
+ setLabelId: NOOP,
2916
+ messageIds: [],
2917
+ setMessageIds: NOOP,
2918
+ getDescriptionProps: externalProps => externalProps
2919
+ });
2920
+ if (process.env.NODE_ENV !== "production") LabelableContext.displayName = "LabelableContext";
2921
+ function useLabelableContext() {
2922
+ return React.useContext(LabelableContext);
2923
+ }
2924
+
2925
+ function useLabelableId(params = {}) {
2926
+ const {
2927
+ id,
2928
+ implicit = false,
2929
+ controlRef
2930
+ } = params;
2931
+ const {
2932
+ controlId,
2933
+ registerControlId
2934
+ } = useLabelableContext();
2935
+ const defaultId = useBaseUiId(id);
2936
+ const controlIdForEffect = implicit ? controlId : undefined;
2937
+ const controlSourceRef = useRefWithInit(() => Symbol());
2938
+ const hasRegisteredRef = React.useRef(false);
2939
+ const hadExplicitIdRef = React.useRef(id != null);
2940
+ const unregisterControlId = useStableCallback(() => {
2941
+ if (!hasRegisteredRef.current || registerControlId === NOOP) {
2942
+ return;
2943
+ }
2944
+ hasRegisteredRef.current = false;
2945
+ registerControlId(controlSourceRef.current, undefined);
2946
+ });
2947
+ useIsoLayoutEffect(() => {
2948
+ if (registerControlId === NOOP) {
2949
+ return undefined;
2950
+ }
2951
+ let nextId;
2952
+ if (implicit) {
2953
+ const elem = controlRef?.current;
2954
+ if (isElement(elem) && elem.closest('label') != null) {
2955
+ nextId = id ?? null;
2956
+ } else {
2957
+ nextId = controlIdForEffect ?? defaultId;
2958
+ }
2959
+ } else if (id != null) {
2960
+ hadExplicitIdRef.current = true;
2961
+ nextId = id;
2962
+ } else if (hadExplicitIdRef.current) {
2963
+ nextId = defaultId;
2964
+ } else {
2965
+ unregisterControlId();
2966
+ return undefined;
2967
+ }
2968
+ if (nextId === undefined) {
2969
+ unregisterControlId();
2970
+ return undefined;
2971
+ }
2972
+ hasRegisteredRef.current = true;
2973
+ registerControlId(controlSourceRef.current, nextId);
2974
+ return undefined;
2975
+ }, [id, controlRef, controlIdForEffect, registerControlId, implicit, defaultId, controlSourceRef, unregisterControlId]);
2976
+ React.useEffect(() => {
2977
+ return unregisterControlId;
2978
+ }, [unregisterControlId]);
2979
+ return controlId ?? defaultId;
2980
+ }
2981
+
2982
+ function areArraysEqual(array1, array2, itemComparer = (a, b) => a === b) {
2983
+ return array1.length === array2.length && array1.every((value, index) => itemComparer(value, array2[index]));
2984
+ }
2985
+
2986
+ // Tolerance around the element bounds so a fast click whose pointer drifts slightly
2987
+ // during press-release isn't mistaken for a drag-off-and-release cancellation.
2988
+ // Matches typical OS/browser drag-initiation thresholds.
2989
+ const BOUNDARY_OFFSET = 5;
2990
+
2991
+ /**
2992
+ * Determines if a mouse event occurred within the bounds of an element
2993
+ * (including its pseudo-elements), with a small tolerance for pointer drift.
2994
+ */
2995
+ function isMouseWithinBounds(event, element) {
2996
+ const bounds = getPseudoElementBounds(element);
2997
+ return event.clientX >= bounds.left - BOUNDARY_OFFSET && event.clientX <= bounds.right + BOUNDARY_OFFSET && event.clientY >= bounds.top - BOUNDARY_OFFSET && event.clientY <= bounds.bottom + BOUNDARY_OFFSET;
2998
+ }
2999
+ function getPseudoElementBounds(element) {
3000
+ const elementRect = element.getBoundingClientRect();
3001
+ const win = getWindow(element);
3002
+
3003
+ // Avoid "Not implemented: window.getComputedStyle(elt, pseudoElt)" in jsdom.
3004
+ if (jsdom) {
3005
+ return elementRect;
3006
+ }
3007
+ const beforeStyles = win.getComputedStyle(element, '::before');
3008
+ const afterStyles = win.getComputedStyle(element, '::after');
3009
+ const hasPseudoElements = beforeStyles.content !== 'none' || afterStyles.content !== 'none';
3010
+ if (!hasPseudoElements) {
3011
+ return elementRect;
3012
+ }
3013
+
3014
+ // Get dimensions of pseudo-elements
3015
+ const beforeWidth = parseFloat(beforeStyles.width) || 0;
3016
+ const beforeHeight = parseFloat(beforeStyles.height) || 0;
3017
+ const afterWidth = parseFloat(afterStyles.width) || 0;
3018
+ const afterHeight = parseFloat(afterStyles.height) || 0;
3019
+
3020
+ // Calculate max dimensions including pseudo-elements
3021
+ const totalWidth = Math.max(elementRect.width, beforeWidth, afterWidth);
3022
+ const totalHeight = Math.max(elementRect.height, beforeHeight, afterHeight);
3023
+
3024
+ // Calculate the differences to extend the bounds
3025
+ const widthDiff = totalWidth - elementRect.width;
3026
+ const heightDiff = totalHeight - elementRect.height;
3027
+ return {
3028
+ left: elementRect.left - widthDiff / 2,
3029
+ right: elementRect.right + widthDiff / 2,
3030
+ top: elementRect.top - heightDiff / 2,
3031
+ bottom: elementRect.bottom + heightDiff / 2
3032
+ };
3033
+ }
3034
+
3035
+ function getDefaultLabelId(id) {
3036
+ return id == null ? undefined : `${id}-label`;
3037
+ }
3038
+ function resolveAriaLabelledBy(fieldLabelId, localLabelId) {
3039
+ return fieldLabelId ?? localLabelId;
3040
+ }
3041
+
3042
+ const CompositeListContext = /*#__PURE__*/React.createContext({
3043
+ register: () => {},
3044
+ unregister: () => {},
3045
+ subscribeMapChange: () => () => {},
3046
+ nextIndexRef: {
3047
+ current: 0
3048
+ }
3049
+ });
3050
+ if (process.env.NODE_ENV !== "production") CompositeListContext.displayName = "CompositeListContext";
3051
+ function useCompositeListContext() {
3052
+ return React.useContext(CompositeListContext);
3053
+ }
3054
+
3055
+ /* eslint-disable no-bitwise */
3056
+ /**
3057
+ * Provides context for a list of items in a composite component.
3058
+ */
3059
+ function CompositeList(props) {
3060
+ const {
3061
+ children,
3062
+ elementsRef,
3063
+ labelsRef,
3064
+ onMapChange: onMapChangeProp
3065
+ } = props;
3066
+ const onMapChange = useStableCallback(onMapChangeProp);
3067
+ const [, setMapTick] = React.useState(false);
3068
+ const listeners = useRefWithInit(createListeners).current;
3069
+ const map = useRefWithInit(createMap).current;
3070
+ const nextIndexRef = React.useRef(0);
3071
+ const isDirtyRef = React.useRef(true);
3072
+ const itemsRef = React.useRef([]);
3073
+ const mutationObserverRef = React.useRef(null);
3074
+
3075
+ // Item effects can run without their parent rendering. Schedule one synchronous
3076
+ // parent update for the whole commit so refs are rebuilt before paint and while
3077
+ // the originating React event is still inside `act()` in tests.
3078
+ const scheduleMapUpdate = useStableCallback(() => {
3079
+ if (isDirtyRef.current) {
3080
+ return;
3081
+ }
3082
+ isDirtyRef.current = true;
3083
+ setMapTick(tick => !tick);
3084
+ });
3085
+ const register = useStableCallback((node, registration) => {
3086
+ map.set(node, registration);
3087
+ scheduleMapUpdate();
3088
+ });
3089
+ const unregister = useStableCallback(node => {
3090
+ map.delete(node);
3091
+ scheduleMapUpdate();
3092
+ });
3093
+ const syncRefs = useStableCallback(items => {
3094
+ const nextMap = new Map();
3095
+ elementsRef.current.length = 0;
3096
+ if (labelsRef) {
3097
+ labelsRef.current.length = 0;
3098
+ }
3099
+ items.forEach(item => {
3100
+ nextMap.set(item.element, {
3101
+ ...(item.registration.metadata ?? {}),
3102
+ index: item.index
3103
+ });
3104
+ elementsRef.current[item.index] = item.element;
3105
+ if (labelsRef) {
3106
+ labelsRef.current[item.index] = item.registration.label !== undefined ? item.registration.label : item.registration.textRef?.current?.textContent ?? item.element.textContent;
3107
+ }
3108
+ });
3109
+ nextIndexRef.current = elementsRef.current.length;
3110
+ return nextMap;
3111
+ });
3112
+ function observe(sortedNodes) {
3113
+ mutationObserverRef.current?.disconnect();
3114
+ mutationObserverRef.current = null;
3115
+
3116
+ // A single item can't reorder.
3117
+ if (typeof MutationObserver !== 'function' || sortedNodes.length < 2) {
3118
+ return;
3119
+ }
3120
+ const mutationObserver = new MutationObserver(entries => {
3121
+ // Only verify the order after a move: a node that was removed and later
3122
+ // re-added within the same batch. Additions and removals alone can't
3123
+ // change the relative order of the remaining items, and items that mount
3124
+ // or unmount re-sort through `register`/`unregister`.
3125
+ if (!hasMovedNode(entries)) {
3126
+ return;
3127
+ }
3128
+ let previousConnectedNode = null;
3129
+
3130
+ // If any connected node now appears before the previous connected node,
3131
+ // wrappers/items moved and the index map needs to be rebuilt.
3132
+ for (const node of sortedNodes) {
3133
+ if (!node.isConnected) {
3134
+ continue;
3135
+ }
3136
+ if (previousConnectedNode && sortByDocumentPosition(previousConnectedNode, node) > 0) {
3137
+ mutationObserver.disconnect();
3138
+ scheduleMapUpdate();
3139
+ return;
3140
+ }
3141
+ previousConnectedNode = node;
3142
+ }
3143
+ });
3144
+ mutationObserverRef.current = mutationObserver;
3145
+
3146
+ // A reorder that changes item indexes must invert at least one adjacent pair
3147
+ // from the previous sorted order. Observing each pair's common parent catches
3148
+ // both direct item moves and ancestor wrapper moves at the boundary.
3149
+ const roots = new Set();
3150
+ for (let i = 1; i < sortedNodes.length; i += 1) {
3151
+ const root = getCommonAncestor(sortedNodes[i - 1], sortedNodes[i]);
3152
+ if (root) {
3153
+ roots.add(root);
3154
+ }
3155
+ }
3156
+ roots.forEach(root => mutationObserver.observe(root, {
3157
+ childList: true
3158
+ }));
3159
+ }
3160
+ const flush = useStableCallback(() => {
3161
+ const [items, automaticNodes] = getCompositeListSnapshot(map);
3162
+ const nextMap = syncRefs(items);
3163
+ observe(automaticNodes);
3164
+ itemsRef.current = items;
3165
+ isDirtyRef.current = false;
3166
+ listeners.forEach(listener => listener(nextMap));
3167
+ onMapChange(nextMap);
3168
+ });
3169
+ useIsoLayoutEffect(() => {
3170
+ // Re-copy the last committed snapshot when the ref objects change or Strict Mode replays
3171
+ // effects without reattaching callback refs.
3172
+ if (!isDirtyRef.current) {
3173
+ syncRefs(itemsRef.current);
3174
+ }
3175
+ return () => {
3176
+ elementsRef.current = [];
3177
+ if (labelsRef) {
3178
+ labelsRef.current = [];
3179
+ }
3180
+ };
3181
+ }, [elementsRef, labelsRef, syncRefs]);
3182
+ useIsoLayoutEffect(() => {
3183
+ if (isDirtyRef.current) {
3184
+ flush();
3185
+ }
3186
+ });
3187
+ useIsoLayoutEffect(() => {
3188
+ return () => {
3189
+ mutationObserverRef.current?.disconnect();
3190
+ // React 18 Strict Mode replays effects without replaying callback refs.
3191
+ // Mark the retained map dirty so the replay rebuilds refs and observation.
3192
+ isDirtyRef.current = true;
3193
+ };
3194
+ }, []);
3195
+ const subscribeMapChange = useStableCallback(fn => {
3196
+ listeners.add(fn);
3197
+ return () => {
3198
+ listeners.delete(fn);
3199
+ };
3200
+ });
3201
+ const contextValue = React.useMemo(() => ({
3202
+ register,
3203
+ unregister,
3204
+ subscribeMapChange,
3205
+ nextIndexRef
3206
+ }), [register, unregister, subscribeMapChange, nextIndexRef]);
3207
+ return /*#__PURE__*/jsx(CompositeListContext.Provider, {
3208
+ value: contextValue,
3209
+ children: children
3210
+ });
3211
+ }
3212
+ function createMap() {
3213
+ return new Map();
3214
+ }
3215
+ function createListeners() {
3216
+ return new Set();
3217
+ }
3218
+ function getCompositeListSnapshot(map) {
3219
+ const reservedIndices = new Set();
3220
+ const items = [];
3221
+ const automaticItems = [];
3222
+ map.forEach((registration, node) => {
3223
+ if (!node.isConnected) {
3224
+ return;
3225
+ }
3226
+ const index = registration.index;
3227
+ const item = {
3228
+ index: index ?? -1,
3229
+ element: node,
3230
+ registration
3231
+ };
3232
+ if (index === null) {
3233
+ automaticItems.push(item);
3234
+ } else if (index >= 0) {
3235
+ reservedIndices.add(index);
3236
+ items.push(item);
3237
+ }
3238
+ });
3239
+ let nextAutomaticIndex = 0;
3240
+ automaticItems.sort((a, b) => sortByDocumentPosition(a.element, b.element));
3241
+ automaticItems.forEach(item => {
3242
+ while (reservedIndices.has(nextAutomaticIndex)) {
3243
+ nextAutomaticIndex += 1;
3244
+ }
3245
+ item.index = nextAutomaticIndex;
3246
+ items.push(item);
3247
+ nextAutomaticIndex += 1;
3248
+ });
3249
+ if (reservedIndices.size > 0) {
3250
+ items.sort((a, b) => a.index - b.index);
3251
+ }
3252
+ return [items, automaticItems.map(item => item.element)];
3253
+ }
3254
+ function getCommonAncestor(firstNode, lastNode) {
3255
+ let ancestor = firstNode.parentElement;
3256
+
3257
+ // The `parentElement` walk cannot cross shadow boundaries, so the native
3258
+ // `contains` is sufficient here.
3259
+ while (ancestor && !ancestor.contains(lastNode)) {
3260
+ ancestor = ancestor.parentElement;
3261
+ }
3262
+ return ancestor;
3263
+ }
3264
+ function hasMovedNode(entries) {
3265
+ for (const entry of entries) {
3266
+ for (let i = 0; i < entry.removedNodes.length; i += 1) {
3267
+ if (entry.removedNodes[i].isConnected) {
3268
+ return true;
3269
+ }
3270
+ }
3271
+ }
3272
+ return false;
3273
+ }
3274
+ function sortByDocumentPosition(a, b) {
3275
+ // `DOCUMENT_POSITION_CONTAINED_BY` is always reported alongside `FOLLOWING`, and `CONTAINS`
3276
+ // alongside `PRECEDING`, so testing `FOLLOWING` alone orders siblings and nested items alike.
3277
+ return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
3278
+ }
3279
+
3280
+ /**
3281
+ * Fork of the original `arrow` middleware from Floating UI that allows
3282
+ * configuring the offset parent.
3283
+ */
3284
+ const baseArrow = options => ({
3285
+ name: 'arrow',
3286
+ options,
3287
+ async fn(state) {
3288
+ const {
3289
+ x,
3290
+ y,
3291
+ placement,
3292
+ rects,
3293
+ platform,
3294
+ elements,
3295
+ middlewareData
3296
+ } = state;
3297
+ // Since `element` is required, we don't Partial<> the type.
3298
+ const {
3299
+ element,
3300
+ padding = 0,
3301
+ offsetParent = 'real'
3302
+ } = evaluate(options, state) || {};
3303
+ if (element == null) {
3304
+ return {};
3305
+ }
3306
+ const paddingObject = getPaddingObject(padding);
3307
+ const coords = {
3308
+ x,
3309
+ y
3310
+ };
3311
+ const axis = getAlignmentAxis(placement);
3312
+ const length = getAxisLength(axis);
3313
+ const arrowDimensions = await platform.getDimensions(element);
3314
+ const isYAxis = axis === 'y';
3315
+ const minProp = isYAxis ? 'top' : 'left';
3316
+ const maxProp = isYAxis ? 'bottom' : 'right';
3317
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
3318
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
3319
+ const startDiff = coords[axis] - rects.reference[axis];
3320
+ const arrowOffsetParent = offsetParent === 'real' ? await platform.getOffsetParent?.(element) : elements.floating;
3321
+ let clientSize = elements.floating[clientProp] || rects.floating[length];
3322
+
3323
+ // DOM platform can return `window` as the `offsetParent`.
3324
+ if (!clientSize || !(await platform.isElement?.(arrowOffsetParent))) {
3325
+ clientSize = elements.floating[clientProp] || rects.floating[length];
3326
+ }
3327
+ const centerToReference = endDiff / 2 - startDiff / 2;
3328
+
3329
+ // If the padding is large enough that it causes the arrow to no longer be
3330
+ // centered, modify the padding so that it is centered.
3331
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
3332
+ const minPadding = Math.min(paddingObject[minProp], largestPossiblePadding);
3333
+ const maxPadding = Math.min(paddingObject[maxProp], largestPossiblePadding);
3334
+
3335
+ // Make sure the arrow doesn't overflow the floating element if the center
3336
+ // point is outside the floating element's bounds.
3337
+ const min = minPadding;
3338
+ const max = clientSize - arrowDimensions[length] - maxPadding;
3339
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
3340
+ const offset = clamp(min, center, max);
3341
+
3342
+ // If the reference is small enough that the arrow's padding causes it to
3343
+ // to point to nothing for an aligned placement, adjust the offset of the
3344
+ // floating element itself. To ensure `shift()` continues to take action,
3345
+ // a single reset is performed when this is true.
3346
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
3347
+ // eslint-disable-next-line no-nested-ternary
3348
+ const alignmentOffset = shouldAddOffset ? center < min ? center - min : center - max : 0;
3349
+ return {
3350
+ [axis]: coords[axis] + alignmentOffset,
3351
+ data: {
3352
+ [axis]: offset,
3353
+ centerOffset: center - offset - alignmentOffset,
3354
+ ...(shouldAddOffset && {
3355
+ alignmentOffset
3356
+ })
3357
+ },
3358
+ reset: shouldAddOffset
3359
+ };
3360
+ }
3361
+ });
3362
+
3363
+ /**
3364
+ * Provides data to position an inner element of the floating element so that it
3365
+ * appears centered to the reference element.
3366
+ * This wraps the core `arrow` middleware to allow React refs as the element.
3367
+ * @see https://floating-ui.com/docs/arrow
3368
+ */
3369
+ const arrow = (options, deps) => ({
3370
+ ...baseArrow(options),
3371
+ options: [options, deps]
3372
+ });
3373
+
3374
+ const hide = {
3375
+ name: 'hide',
3376
+ async fn(state) {
3377
+ const {
3378
+ width,
3379
+ height,
3380
+ x,
3381
+ y
3382
+ } = state.rects.reference;
3383
+ const anchorHidden = width === 0 && height === 0 && x === 0 && y === 0;
3384
+ // Mirrors Floating UI's `hide()` referenceHidden strategy. Floating UI injects
3385
+ // `detectOverflow` into the middleware platform before invoking middleware.
3386
+ const overflow = await state.platform.detectOverflow(state, {
3387
+ elementContext: 'reference'
3388
+ });
3389
+ const referenceHidden = overflow.top - height >= 0 || overflow.right - width >= 0 || overflow.bottom - height >= 0 || overflow.left - width >= 0;
3390
+ return {
3391
+ data: {
3392
+ referenceHidden: referenceHidden || anchorHidden
3393
+ }
3394
+ };
3395
+ }
3396
+ };
3397
+
3398
+ const DEFAULT_SIDES = {
3399
+ sideX: 'left',
3400
+ sideY: 'top'
3401
+ };
3402
+
3403
+ // Self-contained stand-in for Floating UI's `Middleware` type. Referencing the real type in
3404
+ // store state makes `tsc` declaration emit reference `Platform`/`detectOverflow` from
3405
+ // `@floating-ui/core` internals, which fails as non-portable (TS2883) in consuming builds.
3406
+
3407
+ const AVAILABLE_WIDTH_VAR = '--available-width';
3408
+ const AVAILABLE_HEIGHT_VAR = '--available-height';
3409
+ function getLogicalSide(sideParam, renderedSide, isRtl) {
3410
+ const isLogicalSideParam = sideParam === 'inline-start' || sideParam === 'inline-end';
3411
+ const logicalRight = isRtl ? 'inline-start' : 'inline-end';
3412
+ const logicalLeft = isRtl ? 'inline-end' : 'inline-start';
3413
+ return {
3414
+ top: 'top',
3415
+ right: isLogicalSideParam ? logicalRight : 'right',
3416
+ bottom: 'bottom',
3417
+ left: isLogicalSideParam ? logicalLeft : 'left'
3418
+ }[renderedSide];
3419
+ }
3420
+ function getOffsetData(state, sideParam, isRtl) {
3421
+ const {
3422
+ rects,
3423
+ placement
3424
+ } = state;
3425
+ const data = {
3426
+ side: getLogicalSide(sideParam, getSide(placement), isRtl),
3427
+ align: getAlignment(placement) || 'center',
3428
+ anchor: {
3429
+ width: rects.reference.width,
3430
+ height: rects.reference.height
3431
+ },
3432
+ positioner: {
3433
+ width: rects.floating.width,
3434
+ height: rects.floating.height
3435
+ }
3436
+ };
3437
+ return data;
3438
+ }
3439
+ /**
3440
+ * Provides standardized anchor positioning behavior for floating elements. Wraps Floating UI's
3441
+ * `useFloating` hook.
3442
+ */
3443
+ function useAnchorPositioning(params) {
3444
+ return useAnchorPositioningWithHook(params, useBaseUIFloating);
3445
+ }
3446
+ function useAnchorPositioningWithHook(params, useFloatingHook) {
3447
+ const {
3448
+ // Public parameters
3449
+ anchor,
3450
+ positionMethod = 'absolute',
3451
+ side: sideParam = 'bottom',
3452
+ sideOffset = 0,
3453
+ align = 'center',
3454
+ alignOffset = 0,
3455
+ collisionBoundary,
3456
+ collisionPadding: collisionPaddingParam = 5,
3457
+ sticky = false,
3458
+ arrowPadding = 5,
3459
+ disableAnchorTracking = false,
3460
+ inline: inlineMiddleware,
3461
+ // Private parameters
3462
+ keepMounted = false,
3463
+ floatingRootContext,
3464
+ mounted,
3465
+ collisionAvoidance,
3466
+ shift: shift$1,
3467
+ nodeId,
3468
+ adaptiveOrigin,
3469
+ lazyFlip = false,
3470
+ externalTree
3471
+ } = params;
3472
+ const [mountSide, setMountSide] = React.useState(null);
3473
+ if (!mounted && mountSide !== null) {
3474
+ setMountSide(null);
3475
+ }
3476
+ const collisionAvoidanceSide = collisionAvoidance.side || 'flip';
3477
+ const collisionAvoidanceAlign = collisionAvoidance.align || 'flip';
3478
+ const collisionAvoidanceFallbackAxisSide = collisionAvoidance.fallbackAxisSide || 'end';
3479
+ const shiftCrossAxis = shift$1?.crossAxis ?? false;
3480
+ const shiftRootBoundary = shift$1?.rootBoundary;
3481
+ const anchorFn = typeof anchor === 'function' ? anchor : undefined;
3482
+ const anchorFnCallback = useStableCallback(anchorFn);
3483
+ const anchorDep = anchorFn ? anchorFnCallback : anchor;
3484
+ const anchorValueRef = useValueAsRef(anchor);
3485
+ const mountedRef = useValueAsRef(mounted);
3486
+ const direction = useDirection();
3487
+ const isRtl = direction === 'rtl';
3488
+ const side = mountSide || {
3489
+ top: 'top',
3490
+ right: 'right',
3491
+ bottom: 'bottom',
3492
+ left: 'left',
3493
+ 'inline-end': isRtl ? 'left' : 'right',
3494
+ 'inline-start': isRtl ? 'right' : 'left'
3495
+ }[sideParam];
3496
+ const placement = align === 'center' ? side : `${side}-${align}`;
3497
+ let collisionPadding = collisionPaddingParam;
3498
+ if (typeof collisionPadding === 'number') {
3499
+ collisionPadding = {
3500
+ top: collisionPadding,
3501
+ right: collisionPadding,
3502
+ bottom: collisionPadding,
3503
+ left: collisionPadding
3504
+ };
3505
+ } else if (collisionPadding) {
3506
+ collisionPadding = {
3507
+ top: collisionPadding.top || 0,
3508
+ right: collisionPadding.right || 0,
3509
+ bottom: collisionPadding.bottom || 0,
3510
+ left: collisionPadding.left || 0
3511
+ };
3512
+ }
3513
+
3514
+ // Create a bias to the preferred side.
3515
+ // On iOS, when the mobile software keyboard opens, the input is exactly centered
3516
+ // in the viewport, but this can cause it to flip to the top undesirably.
3517
+ // The bias is only applied to `flip()` so it doesn't shift the resting position
3518
+ // computed by `shift()` and `size()` away from the requested `collisionPadding`.
3519
+ const bias = 1;
3520
+ const biasTop = sideParam === 'bottom' ? bias : 0;
3521
+ const biasBottom = sideParam === 'top' ? bias : 0;
3522
+ const biasLeft = sideParam === 'right' ? bias : 0;
3523
+ const biasRight = sideParam === 'left' ? bias : 0;
3524
+ const commonCollisionProps = {
3525
+ boundary: collisionBoundary === 'clipping-ancestors' ? 'clippingAncestors' : collisionBoundary,
3526
+ padding: collisionPadding
3527
+ };
3528
+
3529
+ // Using a ref assumes that the arrow element is always present in the DOM for the lifetime of the
3530
+ // popup. If this assumption ends up being false, we can switch to state to manage the arrow's
3531
+ // presence.
3532
+ const arrowRef = React.useRef(null);
3533
+
3534
+ // Keep these reactive if they're not functions
3535
+ const sideOffsetRef = useValueAsRef(sideOffset);
3536
+ const alignOffsetRef = useValueAsRef(alignOffset);
3537
+ const sideOffsetDep = typeof sideOffset !== 'function' ? sideOffset : 0;
3538
+ const alignOffsetDep = typeof alignOffset !== 'function' ? alignOffset : 0;
3539
+ const middleware = [];
3540
+ if (inlineMiddleware) {
3541
+ middleware.push(inlineMiddleware);
3542
+ }
3543
+ middleware.push(offset(state => {
3544
+ const data = getOffsetData(state, sideParam, isRtl);
3545
+ const sideAxis = typeof sideOffsetRef.current === 'function' ? sideOffsetRef.current(data) : sideOffsetRef.current;
3546
+ const alignAxis = typeof alignOffsetRef.current === 'function' ? alignOffsetRef.current(data) : alignOffsetRef.current;
3547
+ return {
3548
+ mainAxis: sideAxis,
3549
+ crossAxis: alignAxis,
3550
+ alignmentAxis: alignAxis
3551
+ };
3552
+ }, [sideOffsetDep, alignOffsetDep, isRtl, sideParam]));
3553
+ const shiftDisabled = collisionAvoidanceAlign === 'none' && collisionAvoidanceSide !== 'shift';
3554
+ const crossAxisShiftEnabled = !shiftDisabled && (sticky || shiftCrossAxis || collisionAvoidanceSide === 'shift');
3555
+ const flipMiddleware = collisionAvoidanceSide === 'none' ? null : flip({
3556
+ ...commonCollisionProps,
3557
+ // Ensure the popup flips if it's been limited by its --available-height and it resizes.
3558
+ // Since the size() padding is smaller than the flip() padding, flip() will take precedence.
3559
+ padding: {
3560
+ top: collisionPadding.top + bias + biasTop,
3561
+ right: collisionPadding.right + bias + biasRight,
3562
+ bottom: collisionPadding.bottom + bias + biasBottom,
3563
+ left: collisionPadding.left + bias + biasLeft
3564
+ },
3565
+ mainAxis: !shiftCrossAxis && collisionAvoidanceSide === 'flip',
3566
+ crossAxis: collisionAvoidanceAlign === 'flip' ? 'alignment' : false,
3567
+ fallbackAxisSideDirection: collisionAvoidanceFallbackAxisSide
3568
+ });
3569
+ const shiftMiddleware = shiftDisabled ? null : shift({
3570
+ ...commonCollisionProps,
3571
+ // Use the Layout Viewport to avoid shifting around when pinch-zooming.
3572
+ rootBoundary: shiftRootBoundary,
3573
+ mainAxis: collisionAvoidanceAlign !== 'none',
3574
+ crossAxis: crossAxisShiftEnabled,
3575
+ limiter: sticky || shiftCrossAxis ? undefined : limitShift(limitData => {
3576
+ if (!arrowRef.current) {
3577
+ return {};
3578
+ }
3579
+ const {
3580
+ width,
3581
+ height
3582
+ } = arrowRef.current.getBoundingClientRect();
3583
+ const sideAxis = getSideAxis(getSide(limitData.placement));
3584
+ const arrowSize = sideAxis === 'y' ? width : height;
3585
+ const offsetAmount = sideAxis === 'y' ? collisionPadding.left + collisionPadding.right : collisionPadding.top + collisionPadding.bottom;
3586
+ return {
3587
+ offset: arrowSize / 2 + offsetAmount / 2
3588
+ };
3589
+ })
3590
+ }, [commonCollisionProps, sticky, shiftCrossAxis, shiftRootBoundary, collisionPadding, collisionAvoidanceAlign]);
3591
+
3592
+ // https://floating-ui.com/docs/flip#combining-with-shift
3593
+ if (collisionAvoidanceSide === 'shift' || collisionAvoidanceAlign === 'shift' || align === 'center') {
3594
+ middleware.push(shiftMiddleware, flipMiddleware);
3595
+ } else {
3596
+ middleware.push(flipMiddleware, shiftMiddleware);
3597
+ }
3598
+ middleware.push(size({
3599
+ ...commonCollisionProps,
3600
+ apply({
3601
+ elements: {
3602
+ floating
3603
+ },
3604
+ availableWidth,
3605
+ availableHeight,
3606
+ rects
3607
+ }) {
3608
+ if (!mountedRef.current) {
3609
+ return;
3610
+ }
3611
+ const floatingStyle = floating.style;
3612
+ floatingStyle.setProperty(AVAILABLE_WIDTH_VAR, `${availableWidth}px`);
3613
+ floatingStyle.setProperty(AVAILABLE_HEIGHT_VAR, `${availableHeight}px`);
3614
+
3615
+ // Snap anchor dimensions to device pixels to ensure the popup's visual width matches the anchor's one.
3616
+ const dpr = getWindow(floating).devicePixelRatio || 1;
3617
+ const {
3618
+ x,
3619
+ y,
3620
+ width,
3621
+ height
3622
+ } = rects.reference;
3623
+ const anchorWidth = (Math.round((x + width) * dpr) - Math.round(x * dpr)) / dpr;
3624
+ const anchorHeight = (Math.round((y + height) * dpr) - Math.round(y * dpr)) / dpr;
3625
+ floatingStyle.setProperty('--anchor-width', `${anchorWidth}px`);
3626
+ floatingStyle.setProperty('--anchor-height', `${anchorHeight}px`);
3627
+ }
3628
+ }), arrow(state => ({
3629
+ // `transform-origin` calculations rely on an element existing. If the arrow hasn't been set,
3630
+ // we'll create a fake element.
3631
+ element: arrowRef.current || ownerDocument(state.elements.floating).createElement('div'),
3632
+ padding: arrowPadding,
3633
+ offsetParent: 'floating'
3634
+ }), [arrowPadding]), {
3635
+ name: 'transformOrigin',
3636
+ fn(state) {
3637
+ const {
3638
+ elements,
3639
+ middlewareData,
3640
+ placement: renderedPlacement,
3641
+ rects,
3642
+ y
3643
+ } = state;
3644
+ const currentRenderedSide = getSide(renderedPlacement);
3645
+ const currentRenderedAxis = getSideAxis(currentRenderedSide);
3646
+ const arrowEl = arrowRef.current;
3647
+ const arrowX = middlewareData.arrow?.x || 0;
3648
+ const arrowY = middlewareData.arrow?.y || 0;
3649
+ const arrowWidth = arrowEl?.clientWidth || 0;
3650
+ const arrowHeight = arrowEl?.clientHeight || 0;
3651
+ const transformX = arrowX + arrowWidth / 2;
3652
+ const transformY = arrowY + arrowHeight / 2;
3653
+ const shiftY = Math.abs(middlewareData.shift?.y || 0);
3654
+ const halfAnchorHeight = rects.reference.height / 2;
3655
+ const sideOffsetValue = typeof sideOffset === 'function' ? sideOffset(getOffsetData(state, sideParam, isRtl)) : sideOffset;
3656
+ const isOverlappingAnchor = shiftY > sideOffsetValue;
3657
+ const adjacentTransformOrigin = {
3658
+ top: `${transformX}px calc(100% + ${sideOffsetValue}px)`,
3659
+ bottom: `${transformX}px ${-sideOffsetValue}px`,
3660
+ left: `calc(100% + ${sideOffsetValue}px) ${transformY}px`,
3661
+ right: `${-sideOffsetValue}px ${transformY}px`
3662
+ }[currentRenderedSide];
3663
+ const overlapTransformOrigin = `${transformX}px ${rects.reference.y + halfAnchorHeight - y}px`;
3664
+ elements.floating.style.setProperty('--transform-origin', crossAxisShiftEnabled && currentRenderedAxis === 'y' && isOverlappingAnchor ? overlapTransformOrigin : adjacentTransformOrigin);
3665
+ return {};
3666
+ }
3667
+ }, hide, adaptiveOrigin);
3668
+ useIsoLayoutEffect(() => {
3669
+ // Ensure positioning doesn't run initially for `keepMounted` elements that
3670
+ // aren't initially open.
3671
+ if (!mounted && floatingRootContext) {
3672
+ floatingRootContext.update({
3673
+ referenceElement: null,
3674
+ floatingElement: null,
3675
+ domReferenceElement: null,
3676
+ positionReference: null
3677
+ });
3678
+ }
3679
+ }, [mounted, floatingRootContext]);
3680
+ const autoUpdateOptions = React.useMemo(() => ({
3681
+ elementResize: !disableAnchorTracking && typeof ResizeObserver !== 'undefined',
3682
+ layoutShift: !disableAnchorTracking && typeof IntersectionObserver !== 'undefined'
3683
+ }), [disableAnchorTracking]);
3684
+ const {
3685
+ refs,
3686
+ elements,
3687
+ x,
3688
+ y,
3689
+ middlewareData,
3690
+ update,
3691
+ placement: renderedPlacement,
3692
+ context,
3693
+ isPositioned,
3694
+ floatingStyles: originalFloatingStyles
3695
+ } = useFloatingHook({
3696
+ rootContext: floatingRootContext,
3697
+ open: keepMounted ? mounted : undefined,
3698
+ placement,
3699
+ middleware,
3700
+ strategy: positionMethod,
3701
+ whileElementsMounted: keepMounted ? undefined : (...args) => autoUpdate(...args, autoUpdateOptions),
3702
+ nodeId,
3703
+ externalTree
3704
+ });
3705
+ const {
3706
+ sideX,
3707
+ sideY
3708
+ } = middlewareData.adaptiveOrigin || DEFAULT_SIDES;
3709
+
3710
+ // Default to `fixed` when not positioned to prevent `autoFocus` scroll jumps.
3711
+ // This ensures the popup is inside the viewport initially before it gets positioned.
3712
+ const resolvedPosition = isPositioned ? positionMethod : 'fixed';
3713
+ const floatingStyles = React.useMemo(() => {
3714
+ let base;
3715
+ if (!isPositioned) {
3716
+ // Until a position for the current open is computed, ignore any coordinates retained from a
3717
+ // previous open (or from a pass that measured the hidden popup as 0x0). Rendering the
3718
+ // full-size popup at such stale coordinates can overflow the layout viewport, which makes
3719
+ // mobile Chrome zoom the page out and reflow everything the popup is anchored to.
3720
+ base = {
3721
+ position: resolvedPosition,
3722
+ top: 0,
3723
+ left: 0
3724
+ };
3725
+ } else if (adaptiveOrigin) {
3726
+ base = {
3727
+ position: resolvedPosition,
3728
+ [sideX]: x,
3729
+ [sideY]: y
3730
+ };
3731
+ } else {
3732
+ base = {
3733
+ ...originalFloatingStyles,
3734
+ position: resolvedPosition
3735
+ };
3736
+ }
3737
+
3738
+ // Seed the available size vars so consumer `max-height: min(x, var(--available-height))` rules
3739
+ // resolve to a valid length on the first positioning pass, before `size()` writes the real
3740
+ // values. Without a fallback the unresolved `var()` invalidates the whole declaration, so the
3741
+ // popup is measured unconstrained while `flip()` picks its side, against the full content
3742
+ // height rather than the capped one. Seeded unconditionally (not only while `!isPositioned`):
3743
+ // the keys must stay present with a constant value so React's per-property style diff never
3744
+ // rewrites them after mount, preserving the px values `size()` sets imperatively. Moving them
3745
+ // into the `!isPositioned` branch makes React remove them once positioned, wiping `size()`'s
3746
+ // values and leaving the popup unconstrained.
3747
+ base[AVAILABLE_WIDTH_VAR] = '100vw';
3748
+ base[AVAILABLE_HEIGHT_VAR] = '100vh';
3749
+ if (!isPositioned) {
3750
+ base.opacity = 0;
3751
+ }
3752
+ return base;
3753
+ }, [adaptiveOrigin, resolvedPosition, sideX, x, sideY, y, originalFloatingStyles, isPositioned]);
3754
+ const registeredPositionReferenceRef = React.useRef(null);
3755
+ useIsoLayoutEffect(() => {
3756
+ if (!mounted) {
3757
+ return;
3758
+ }
3759
+ const anchorValue = anchorValueRef.current;
3760
+ const resolvedAnchor = typeof anchorValue === 'function' ? anchorValue() : anchorValue;
3761
+ const unwrappedElement = (isRef(resolvedAnchor) ? resolvedAnchor.current : resolvedAnchor) || null;
3762
+ const finalAnchor = unwrappedElement || null;
3763
+ if (finalAnchor !== registeredPositionReferenceRef.current) {
3764
+ refs.setPositionReference(finalAnchor);
3765
+ registeredPositionReferenceRef.current = finalAnchor;
3766
+ }
3767
+ }, [mounted, refs, anchorDep, anchorValueRef]);
3768
+ React.useEffect(() => {
3769
+ if (!mounted) {
3770
+ return;
3771
+ }
3772
+ const anchorValue = anchorValueRef.current;
3773
+
3774
+ // Refs from parent components are set after useLayoutEffect runs and are available in useEffect.
3775
+ // Therefore, if the anchor is a ref, we need to update the position reference in useEffect.
3776
+ if (typeof anchorValue === 'function') {
3777
+ return;
3778
+ }
3779
+ if (isRef(anchorValue) && anchorValue.current !== registeredPositionReferenceRef.current) {
3780
+ refs.setPositionReference(anchorValue.current);
3781
+ registeredPositionReferenceRef.current = anchorValue.current;
3782
+ }
3783
+ }, [mounted, refs, anchorDep, anchorValueRef]);
3784
+ React.useEffect(() => {
3785
+ if (keepMounted && mounted && elements.reference && elements.floating) {
3786
+ return autoUpdate(elements.reference, elements.floating, update, autoUpdateOptions);
3787
+ }
3788
+ return undefined;
3789
+ }, [keepMounted, mounted, elements, update, autoUpdateOptions]);
3790
+ const renderedSide = getSide(renderedPlacement);
3791
+ const logicalRenderedSide = getLogicalSide(sideParam, renderedSide, isRtl);
3792
+ const renderedAlign = getAlignment(renderedPlacement) || 'center';
3793
+ const anchorHidden = Boolean(middlewareData.hide?.referenceHidden);
3794
+
3795
+ // Locks the flip (makes it "sticky") so it doesn't prefer a given placement
3796
+ // and flips back lazily, not eagerly. Ideal for filtered lists that change
3797
+ // the size of the popup dynamically to avoid unwanted flipping when typing.
3798
+ useIsoLayoutEffect(() => {
3799
+ if (lazyFlip && mounted && isPositioned && renderedSide !== side) {
3800
+ setMountSide(renderedSide);
3801
+ }
3802
+ }, [lazyFlip, mounted, isPositioned, renderedSide, side]);
3803
+ const arrowStyles = React.useMemo(() => ({
3804
+ position: 'absolute',
3805
+ top: middlewareData.arrow?.y,
3806
+ left: middlewareData.arrow?.x
3807
+ }), [middlewareData.arrow]);
3808
+ const arrowUncentered = middlewareData.arrow?.centerOffset !== 0;
3809
+ return React.useMemo(() => ({
3810
+ positionerStyles: floatingStyles,
3811
+ arrowStyles,
3812
+ arrowRef,
3813
+ arrowUncentered,
3814
+ side: logicalRenderedSide,
3815
+ align: renderedAlign,
3816
+ physicalSide: renderedSide,
3817
+ anchorHidden,
3818
+ refs,
3819
+ context,
3820
+ isPositioned,
3821
+ update
3822
+ }), [floatingStyles, arrowStyles, arrowRef, arrowUncentered, logicalRenderedSide, renderedAlign, renderedSide, anchorHidden, refs, context, isPositioned, update]);
3823
+ }
3824
+ function isRef(param) {
3825
+ return param != null && 'current' in param;
3826
+ }
3827
+
3828
+ function getDisabledMountTransitionStyles(transitionStatus) {
3829
+ return transitionStatus === 'starting' ? DISABLED_TRANSITIONS_STYLE : EMPTY_OBJECT;
3830
+ }
3831
+
3832
+ /**
3833
+ * Renders the shared outer Positioner element used by popup components.
3834
+ * Applies the common role, hidden state, transition styles, state attributes, and optional inert styling.
3835
+ */
3836
+ function usePositioner(componentProps, state, {
3837
+ styles,
3838
+ transitionStatus,
3839
+ props,
3840
+ refs,
3841
+ hidden,
3842
+ inert = false
3843
+ }) {
3844
+ const style = {
3845
+ ...styles
3846
+ };
3847
+ if (inert) {
3848
+ style.pointerEvents = 'none';
3849
+ }
3850
+ return useRenderElement('div', componentProps, {
3851
+ state,
3852
+ ref: refs,
3853
+ props: [{
3854
+ role: 'presentation',
3855
+ hidden,
3856
+ style
3857
+ }, getDisabledMountTransitionStyles(transitionStatus), props],
3858
+ stateAttributesMapping: popupStateMapping
3859
+ });
3860
+ }
3861
+
3862
+ // Touch-opened popups normally avoid scroll locking so users can still swipe outside to dismiss.
3863
+ // This hook re-enables scroll lock only when the popup is effectively full-width.
3864
+ // Treat popups with up to 20px of total horizontal gutter as full-width so common ~10px side
3865
+ // padding still locks scroll, since that leaves too little outside space for a reliable swipe.
3866
+ const VIEWPORT_WIDTH_TOLERANCE_PX = 20;
3867
+
3868
+ /**
3869
+ * Manages scroll lock for anchored popups. For non-touch opens, scroll lock is applied when
3870
+ * enabled. For touch opens, scroll lock is applied only when the positioner width is effectively
3871
+ * viewport-sized.
3872
+ */
3873
+ function useAnchoredPopupScrollLock(enabled, touchOpen, positionerElement, referenceElement) {
3874
+ const [touchOpenShouldLockScroll, setTouchOpenShouldLockScroll] = React.useState(false);
3875
+ useIsoLayoutEffect(() => {
3876
+ if (!enabled || !touchOpen || positionerElement == null) {
3877
+ setTouchOpenShouldLockScroll(false);
3878
+ return;
3879
+ }
3880
+ const viewportWidth = ownerDocument(positionerElement).documentElement.clientWidth;
3881
+ const popupWidth = positionerElement.offsetWidth;
3882
+ setTouchOpenShouldLockScroll(viewportWidth > 0 && popupWidth > 0 && popupWidth >= viewportWidth - VIEWPORT_WIDTH_TOLERANCE_PX);
3883
+ }, [enabled, touchOpen, positionerElement]);
3884
+ useScrollLock(enabled && (!touchOpen || touchOpenShouldLockScroll), referenceElement);
3885
+ }
3886
+
3887
+ /**
3888
+ * Used to register a list item and its index (DOM position) in the `CompositeList`.
3889
+ */
3890
+ function useCompositeListItem(params = {}) {
3891
+ const {
3892
+ guess,
3893
+ label,
3894
+ metadata,
3895
+ textRef,
3896
+ index: externalIndex
3897
+ } = params;
3898
+ const {
3899
+ register,
3900
+ unregister,
3901
+ subscribeMapChange,
3902
+ nextIndexRef
3903
+ } = useCompositeListContext();
3904
+
3905
+ // Guess the index from the render order. This avoids a re-render after mount for
3906
+ // flat lists rendered in DOM order; when the guess is wrong (grouped or out-of-order
3907
+ // rendering), the commit flush corrects it before paint.
3908
+ const indexRef = React.useRef(-1);
3909
+ const [internalIndex, setInternalIndex] = React.useState(externalIndex == null && guess ? () => {
3910
+ if (indexRef.current === -1) {
3911
+ const newIndex = nextIndexRef.current;
3912
+ nextIndexRef.current += 1;
3913
+ indexRef.current = newIndex;
3914
+ }
3915
+ return indexRef.current;
3916
+ } : -1);
3917
+ const index = externalIndex ?? internalIndex;
3918
+ const componentRef = React.useRef(null);
3919
+
3920
+ // Deliberately identity-sensitive: nested items sharing one DOM node rely on ref attachment
3921
+ // order to decide which registration wins, and republishing from an effect instead would let
3922
+ // an inner item's later update silently take ownership from the outer one.
3923
+ const ref = React.useCallback(node => {
3924
+ const previousNode = componentRef.current;
3925
+ if (previousNode) {
3926
+ unregister(previousNode);
3927
+ }
3928
+ componentRef.current = node;
3929
+ if (node) {
3930
+ register(node, {
3931
+ metadata: metadata ?? null,
3932
+ index: externalIndex ?? null,
3933
+ label,
3934
+ textRef
3935
+ });
3936
+ }
3937
+ }, [externalIndex, register, unregister, metadata, label, textRef]);
3938
+ useIsoLayoutEffect(() => {
3939
+ if (externalIndex != null) {
3940
+ return undefined;
3941
+ }
3942
+ return subscribeMapChange(map => {
3943
+ const i = componentRef.current ? map.get(componentRef.current)?.index : null;
3944
+ if (i != null) {
3945
+ setInternalIndex(i);
3946
+ }
3947
+ });
3948
+ }, [externalIndex, subscribeMapChange]);
3949
+ return {
3950
+ ref,
3951
+ index
3952
+ };
3953
+ }
3954
+
3955
+ export { useCompositeListItem as A, removeItem as B, CompositeList as C, DEFAULT_VALIDITY_STATE as D, isGroupedItems as E, FieldRootContext as F, findSelectionIndex as G, selectedValueIncludes as H, DEFAULT_FIELD_ROOT_CONTEXT as I, DEFAULT_FIELD_STATE_ATTRIBUTES as J, getDefaultLabelId as K, LabelableContext as L, DEFAULT_SIDES as M, useFormContext as a, useFieldRootContext as b, useLabelableId as c, useRegisterFieldControl as d, compareItemEquality as e, fieldValidityMapping as f, findItemIndex as g, hasNullItemLabel as h, useFloatingRootContext as i, useListNavigation as j, useTypeahead as k, useOnFirstRender as l, defaultItemEquality as m, stringifyAsLabel as n, areArraysEqual as o, isMouseWithinBounds as p, resolveMultipleLabels as q, resolveAriaLabelledBy as r, stringifyAsValue as s, resolveSelectedLabel as t, useLabelableContext as u, useAnchoredPopupScrollLock as v, useAnchorPositioning as w, usePositioner as x, platform as y, getDisabledMountTransitionStyles as z };