`, so it can be styled via any CSS solution you prefer.
+ * @see https://floating-ui.com/docs/FloatingOverlay
+ */
+const FloatingOverlay = /*#__PURE__*/React.forwardRef(function FloatingOverlay(_ref, ref) {
+ let {
+ lockScroll = false,
+ ...rest
+ } = _ref;
+ index(() => {
+ var _window$visualViewpor, _window$visualViewpor2;
+ if (!lockScroll) {
+ return;
+ }
+ const alreadyLocked = document.body.hasAttribute(identifier);
+ if (alreadyLocked) {
+ return;
+ }
+ document.body.setAttribute(identifier, '');
+
+ // RTL scrollbar
+ const scrollbarX = Math.round(document.documentElement.getBoundingClientRect().left) + document.documentElement.scrollLeft;
+ const paddingProp = scrollbarX ? 'paddingLeft' : 'paddingRight';
+ const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
+
+ // Only iOS doesn't respect `overflow: hidden` on document.body, and this
+ // technique has fewer side effects.
+ if (!/iP(hone|ad|od)|iOS/.test(getPlatform())) {
+ Object.assign(document.body.style, {
+ overflow: 'hidden',
+ [paddingProp]: scrollbarWidth + "px"
+ });
+ return () => {
+ document.body.removeAttribute(identifier);
+ Object.assign(document.body.style, {
+ overflow: '',
+ [paddingProp]: ''
+ });
+ };
+ }
+
+ // iOS 12 does not support `visualViewport`.
+ const offsetLeft = ((_window$visualViewpor = window.visualViewport) == null ? void 0 : _window$visualViewpor.offsetLeft) || 0;
+ const offsetTop = ((_window$visualViewpor2 = window.visualViewport) == null ? void 0 : _window$visualViewpor2.offsetTop) || 0;
+ const scrollX = window.pageXOffset;
+ const scrollY = window.pageYOffset;
+ Object.assign(document.body.style, {
+ position: 'fixed',
+ overflow: 'hidden',
+ top: -(scrollY - Math.floor(offsetTop)) + "px",
+ left: -(scrollX - Math.floor(offsetLeft)) + "px",
+ right: '0',
+ [paddingProp]: scrollbarWidth + "px"
+ });
+ return () => {
+ Object.assign(document.body.style, {
+ position: '',
+ overflow: '',
+ top: '',
+ left: '',
+ right: '',
+ [paddingProp]: ''
+ });
+ document.body.removeAttribute(identifier);
+ window.scrollTo(scrollX, scrollY);
+ };
+ }, [lockScroll]);
+ return /*#__PURE__*/React.createElement("div", _extends({
+ ref: ref
+ }, rest, {
+ style: {
+ position: 'fixed',
+ overflow: 'auto',
+ top: 0,
+ right: 0,
+ bottom: 0,
+ left: 0,
+ ...rest.style
+ }
+ }));
+});
+
+function isButtonTarget(event) {
+ return isHTMLElement(event.target) && event.target.tagName === 'BUTTON';
+}
+function isSpaceIgnored(element) {
+ return isTypeableElement(element);
+}
+/**
+ * Adds click event listeners that change the open state.
+ * @see https://floating-ui.com/docs/useClick
+ */
+const useClick = function (_ref, _temp) {
+ let {
+ open,
+ onOpenChange,
+ dataRef,
+ elements: {
+ domReference
+ }
+ } = _ref;
+ let {
+ enabled = true,
+ event: eventOption = 'click',
+ toggle = true,
+ ignoreMouse = false,
+ keyboardHandlers = true
+ } = _temp === void 0 ? {} : _temp;
+ const pointerTypeRef = React.useRef();
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ return {
+ reference: {
+ onPointerDown(event) {
+ pointerTypeRef.current = event.pointerType;
+ },
+ onMouseDown(event) {
+ // Ignore all buttons except for the "main" button.
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
+ if (event.button !== 0) {
+ return;
+ }
+ if (isMouseLikePointerType(pointerTypeRef.current, true) && ignoreMouse) {
+ return;
+ }
+ if (eventOption === 'click') {
+ return;
+ }
+ if (open) {
+ if (toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'mousedown' : true)) {
+ onOpenChange(false);
+ }
+ } else {
+ // Prevent stealing focus from the floating element
+ event.preventDefault();
+ onOpenChange(true);
+ }
+ dataRef.current.openEvent = event.nativeEvent;
+ },
+ onClick(event) {
+ if (dataRef.current.__syncReturnFocus) {
+ return;
+ }
+ if (eventOption === 'mousedown' && pointerTypeRef.current) {
+ pointerTypeRef.current = undefined;
+ return;
+ }
+ if (isMouseLikePointerType(pointerTypeRef.current, true) && ignoreMouse) {
+ return;
+ }
+ if (open) {
+ if (toggle && (dataRef.current.openEvent ? dataRef.current.openEvent.type === 'click' : true)) {
+ onOpenChange(false);
+ }
+ } else {
+ onOpenChange(true);
+ }
+ dataRef.current.openEvent = event.nativeEvent;
+ },
+ onKeyDown(event) {
+ pointerTypeRef.current = undefined;
+ if (!keyboardHandlers) {
+ return;
+ }
+ if (isButtonTarget(event)) {
+ return;
+ }
+ if (event.key === ' ' && !isSpaceIgnored(domReference)) {
+ // Prevent scrolling
+ event.preventDefault();
+ }
+ if (event.key === 'Enter') {
+ if (open) {
+ if (toggle) {
+ onOpenChange(false);
+ }
+ } else {
+ onOpenChange(true);
+ }
+ }
+ },
+ onKeyUp(event) {
+ if (!keyboardHandlers) {
+ return;
+ }
+ if (isButtonTarget(event) || isSpaceIgnored(domReference)) {
+ return;
+ }
+ if (event.key === ' ') {
+ if (open) {
+ if (toggle) {
+ onOpenChange(false);
+ }
+ } else {
+ onOpenChange(true);
+ }
+ }
+ }
+ }
+ };
+ }, [enabled, dataRef, eventOption, ignoreMouse, keyboardHandlers, domReference, toggle, open, onOpenChange]);
+};
+
+/**
+ * Check whether the event.target is within the provided node. Uses event.composedPath if available for custom element support.
+ *
+ * @param event The event whose target/composedPath to check
+ * @param node The node to check against
+ * @returns Whether the event.target/composedPath is within the node.
+ */
+function isEventTargetWithin(event, node) {
+ if (node == null) {
+ return false;
+ }
+ if ('composedPath' in event) {
+ return event.composedPath().includes(node);
+ }
+
+ // TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
+ const e = event;
+ return e.target != null && node.contains(e.target);
+}
+
+const bubbleHandlerKeys = {
+ pointerdown: 'onPointerDown',
+ mousedown: 'onMouseDown',
+ click: 'onClick'
+};
+const captureHandlerKeys = {
+ pointerdown: 'onPointerDownCapture',
+ mousedown: 'onMouseDownCapture',
+ click: 'onClickCapture'
+};
+const normalizeBubblesProp = function (bubbles) {
+ var _bubbles$escapeKey, _bubbles$outsidePress;
+ if (bubbles === void 0) {
+ bubbles = true;
+ }
+ return {
+ escapeKeyBubbles: typeof bubbles === 'boolean' ? bubbles : (_bubbles$escapeKey = bubbles.escapeKey) != null ? _bubbles$escapeKey : true,
+ outsidePressBubbles: typeof bubbles === 'boolean' ? bubbles : (_bubbles$outsidePress = bubbles.outsidePress) != null ? _bubbles$outsidePress : true
+ };
+};
+/**
+ * Adds listeners that dismiss (close) the floating element.
+ * @see https://floating-ui.com/docs/useDismiss
+ */
+const useDismiss = function (_ref, _temp) {
+ let {
+ open,
+ onOpenChange,
+ events,
+ nodeId,
+ elements: {
+ reference,
+ domReference,
+ floating
+ },
+ dataRef
+ } = _ref;
+ let {
+ enabled = true,
+ escapeKey = true,
+ outsidePress: unstable_outsidePress = true,
+ outsidePressEvent = 'pointerdown',
+ referencePress = false,
+ referencePressEvent = 'pointerdown',
+ ancestorScroll = false,
+ bubbles = true
+ } = _temp === void 0 ? {} : _temp;
+ const tree = useFloatingTree();
+ const nested = useFloatingParentNodeId() != null;
+ const outsidePressFn = useEvent(typeof unstable_outsidePress === 'function' ? unstable_outsidePress : () => false);
+ const outsidePress = typeof unstable_outsidePress === 'function' ? outsidePressFn : unstable_outsidePress;
+ const insideReactTreeRef = React.useRef(false);
+ const {
+ escapeKeyBubbles,
+ outsidePressBubbles
+ } = normalizeBubblesProp(bubbles);
+ React.useEffect(() => {
+ if (!open || !enabled) {
+ return;
+ }
+ dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
+ dataRef.current.__outsidePressBubbles = outsidePressBubbles;
+ function onKeyDown(event) {
+ if (event.key === 'Escape') {
+ const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
+ if (children.length > 0) {
+ let shouldDismiss = true;
+ children.forEach(child => {
+ var _child$context;
+ if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
+ shouldDismiss = false;
+ return;
+ }
+ });
+ if (!shouldDismiss) {
+ return;
+ }
+ }
+ events.emit('dismiss', {
+ type: 'escapeKey',
+ data: {
+ returnFocus: {
+ preventScroll: false
+ }
+ }
+ });
+ onOpenChange(false);
+ }
+ }
+ function onOutsidePress(event) {
+ // Given developers can stop the propagation of the synthetic event,
+ // we can only be confident with a positive value.
+ const insideReactTree = insideReactTreeRef.current;
+ insideReactTreeRef.current = false;
+ if (insideReactTree) {
+ return;
+ }
+ if (typeof outsidePress === 'function' && !outsidePress(event)) {
+ return;
+ }
+ const target = getTarget(event);
+
+ // Check if the click occurred on the scrollbar
+ if (isHTMLElement(target) && floating) {
+ const win = floating.ownerDocument.defaultView || window;
+ const canScrollX = target.scrollWidth > target.clientWidth;
+ const canScrollY = target.scrollHeight > target.clientHeight;
+ let xCond = canScrollY && event.offsetX > target.clientWidth;
+
+ // In some browsers it is possible to change the (or window)
+ // scrollbar to the left side, but is very rare and is difficult to
+ // check for. Plus, for modal dialogs with backdrops, it is more
+ // important that the backdrop is checked but not so much the window.
+ if (canScrollY) {
+ const isRTL = win.getComputedStyle(target).direction === 'rtl';
+ if (isRTL) {
+ xCond = event.offsetX <= target.offsetWidth - target.clientWidth;
+ }
+ }
+ if (xCond || canScrollX && event.offsetY > target.clientHeight) {
+ return;
+ }
+ }
+ const targetIsInsideChildren = tree && getChildren(tree.nodesRef.current, nodeId).some(node => {
+ var _node$context;
+ return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
+ });
+ if (isEventTargetWithin(event, floating) || isEventTargetWithin(event, domReference) || targetIsInsideChildren) {
+ return;
+ }
+ const children = tree ? getChildren(tree.nodesRef.current, nodeId) : [];
+ if (children.length > 0) {
+ let shouldDismiss = true;
+ children.forEach(child => {
+ var _child$context2;
+ if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
+ shouldDismiss = false;
+ return;
+ }
+ });
+ if (!shouldDismiss) {
+ return;
+ }
+ }
+ events.emit('dismiss', {
+ type: 'outsidePress',
+ data: {
+ returnFocus: nested ? {
+ preventScroll: true
+ } : isVirtualClick(event) || isVirtualPointerEvent(event)
+ }
+ });
+ onOpenChange(false);
+ }
+ function onScroll() {
+ onOpenChange(false);
+ }
+ const doc = getDocument(floating);
+ escapeKey && doc.addEventListener('keydown', onKeyDown);
+ outsidePress && doc.addEventListener(outsidePressEvent, onOutsidePress);
+ let ancestors = [];
+ if (ancestorScroll) {
+ if (isElement(domReference)) {
+ ancestors = getOverflowAncestors(domReference);
+ }
+ if (isElement(floating)) {
+ ancestors = ancestors.concat(getOverflowAncestors(floating));
+ }
+ if (!isElement(reference) && reference && reference.contextElement) {
+ ancestors = ancestors.concat(getOverflowAncestors(reference.contextElement));
+ }
+ }
+
+ // Ignore the visual viewport for scrolling dismissal (allow pinch-zoom)
+ ancestors = ancestors.filter(ancestor => {
+ var _doc$defaultView;
+ return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
+ });
+ ancestors.forEach(ancestor => {
+ ancestor.addEventListener('scroll', onScroll, {
+ passive: true
+ });
+ });
+ return () => {
+ escapeKey && doc.removeEventListener('keydown', onKeyDown);
+ outsidePress && doc.removeEventListener(outsidePressEvent, onOutsidePress);
+ ancestors.forEach(ancestor => {
+ ancestor.removeEventListener('scroll', onScroll);
+ });
+ };
+ }, [dataRef, floating, domReference, reference, escapeKey, outsidePress, outsidePressEvent, events, tree, nodeId, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, nested]);
+ React.useEffect(() => {
+ insideReactTreeRef.current = false;
+ }, [outsidePress, outsidePressEvent]);
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ return {
+ reference: {
+ [bubbleHandlerKeys[referencePressEvent]]: () => {
+ if (referencePress) {
+ events.emit('dismiss', {
+ type: 'referencePress',
+ data: {
+ returnFocus: false
+ }
+ });
+ onOpenChange(false);
+ }
+ }
+ },
+ floating: {
+ [captureHandlerKeys[outsidePressEvent]]: () => {
+ insideReactTreeRef.current = true;
+ }
+ }
+ };
+ }, [enabled, events, referencePress, outsidePressEvent, referencePressEvent, onOpenChange]);
+};
+
+/**
+ * Adds focus event listeners that change the open state, like CSS :focus.
+ * @see https://floating-ui.com/docs/useFocus
+ */
+const useFocus = function (_ref, _temp) {
+ let {
+ open,
+ onOpenChange,
+ dataRef,
+ events,
+ refs,
+ elements: {
+ floating,
+ domReference
+ }
+ } = _ref;
+ let {
+ enabled = true,
+ keyboardOnly = true
+ } = _temp === void 0 ? {} : _temp;
+ const pointerTypeRef = React.useRef('');
+ const blockFocusRef = React.useRef(false);
+ const timeoutRef = React.useRef();
+ React.useEffect(() => {
+ if (!enabled) {
+ return;
+ }
+ const doc = getDocument(floating);
+ const win = doc.defaultView || window;
+
+ // If the reference was focused and the user left the tab/window, and the
+ // floating element was not open, the focus should be blocked when they
+ // return to the tab/window.
+ function onBlur() {
+ if (!open && isHTMLElement(domReference) && domReference === activeElement$1(getDocument(domReference))) {
+ blockFocusRef.current = true;
+ }
+ }
+ win.addEventListener('blur', onBlur);
+ return () => {
+ win.removeEventListener('blur', onBlur);
+ };
+ }, [floating, domReference, open, enabled]);
+ React.useEffect(() => {
+ if (!enabled) {
+ return;
+ }
+ function onDismiss(payload) {
+ if (payload.type === 'referencePress' || payload.type === 'escapeKey') {
+ blockFocusRef.current = true;
+ }
+ }
+ events.on('dismiss', onDismiss);
+ return () => {
+ events.off('dismiss', onDismiss);
+ };
+ }, [events, enabled]);
+ React.useEffect(() => {
+ return () => {
+ clearTimeout(timeoutRef.current);
+ };
+ }, []);
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ return {
+ reference: {
+ onPointerDown(_ref2) {
+ let {
+ pointerType
+ } = _ref2;
+ pointerTypeRef.current = pointerType;
+ blockFocusRef.current = !!(pointerType && keyboardOnly);
+ },
+ onMouseLeave() {
+ blockFocusRef.current = false;
+ },
+ onFocus(event) {
+ var _dataRef$current$open;
+ if (blockFocusRef.current) {
+ return;
+ }
+
+ // Dismiss with click should ignore the subsequent `focus` trigger,
+ // but only if the click originated inside the reference element.
+ if (event.type === 'focus' && ((_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type) === 'mousedown' && dataRef.current.openEvent && isEventTargetWithin(dataRef.current.openEvent, domReference)) {
+ return;
+ }
+ dataRef.current.openEvent = event.nativeEvent;
+ onOpenChange(true);
+ },
+ onBlur(event) {
+ blockFocusRef.current = false;
+ const relatedTarget = event.relatedTarget;
+
+ // Hit the non-modal focus management portal guard. Focus will be
+ // moved into the floating element immediately after.
+ const movedToFocusGuard = isElement(relatedTarget) && relatedTarget.hasAttribute('data-floating-ui-focus-guard') && relatedTarget.getAttribute('data-type') === 'outside';
+
+ // Wait for the window blur listener to fire.
+ timeoutRef.current = setTimeout(() => {
+ // When focusing the reference element (e.g. regular click), then
+ // clicking into the floating element, prevent it from hiding.
+ // Note: it must be focusable, e.g. `tabindex="-1"`.
+ if (contains(refs.floating.current, relatedTarget) || contains(domReference, relatedTarget) || movedToFocusGuard) {
+ return;
+ }
+ onOpenChange(false);
+ });
+ }
+ }
+ };
+ }, [enabled, keyboardOnly, domReference, refs, dataRef, onOpenChange]);
+};
+
+let isPreventScrollSupported = false;
+const ARROW_UP = 'ArrowUp';
+const ARROW_DOWN = 'ArrowDown';
+const ARROW_LEFT = 'ArrowLeft';
+const ARROW_RIGHT = 'ArrowRight';
+function isDifferentRow(index, cols, prevRow) {
+ return Math.floor(index / cols) !== prevRow;
+}
+function isIndexOutOfBounds(listRef, index) {
+ return index < 0 || index >= listRef.current.length;
+}
+function findNonDisabledIndex(listRef, _temp) {
+ let {
+ startingIndex = -1,
+ decrement = false,
+ disabledIndices,
+ amount = 1
+ } = _temp === void 0 ? {} : _temp;
+ const list = listRef.current;
+ let index = startingIndex;
+ do {
+ var _list$index, _list$index2;
+ index = index + (decrement ? -amount : amount);
+ } while (index >= 0 && index <= list.length - 1 && (disabledIndices ? disabledIndices.includes(index) : list[index] == null || ((_list$index = list[index]) == null ? void 0 : _list$index.hasAttribute('disabled')) || ((_list$index2 = list[index]) == null ? void 0 : _list$index2.getAttribute('aria-disabled')) === 'true'));
+ return index;
+}
+function doSwitch(orientation, vertical, horizontal) {
+ switch (orientation) {
+ case 'vertical':
+ return vertical;
+ case 'horizontal':
+ return horizontal;
+ default:
+ return vertical || horizontal;
+ }
+}
+function isMainOrientationKey(key, orientation) {
+ const vertical = key === ARROW_UP || key === ARROW_DOWN;
+ const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
+ return doSwitch(orientation, vertical, horizontal);
+}
+function isMainOrientationToEndKey(key, orientation, rtl) {
+ const vertical = key === ARROW_DOWN;
+ const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
+ return doSwitch(orientation, vertical, horizontal) || key === 'Enter' || key == ' ' || key === '';
+}
+function isCrossOrientationOpenKey(key, orientation, rtl) {
+ const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
+ const horizontal = key === ARROW_DOWN;
+ return doSwitch(orientation, vertical, horizontal);
+}
+function isCrossOrientationCloseKey(key, orientation, rtl) {
+ const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;
+ const horizontal = key === ARROW_UP;
+ return doSwitch(orientation, vertical, horizontal);
+}
+function getMinIndex(listRef, disabledIndices) {
+ return findNonDisabledIndex(listRef, {
+ disabledIndices
+ });
+}
+function getMaxIndex(listRef, disabledIndices) {
+ return findNonDisabledIndex(listRef, {
+ decrement: true,
+ startingIndex: listRef.current.length,
+ disabledIndices
+ });
+}
+/**
+ * Adds focus-managed indexed navigation via arrow keys to a list of items
+ * within the floating element.
+ * @see https://floating-ui.com/docs/useListNavigation
+ */
+const useListNavigation = function (_ref, _temp2) {
+ let {
+ open,
+ onOpenChange,
+ refs,
+ elements: {
+ domReference
+ }
+ } = _ref;
+ let {
+ listRef,
+ activeIndex,
+ onNavigate: unstable_onNavigate = () => {},
+ enabled = true,
+ selectedIndex = null,
+ allowEscape = false,
+ loop = false,
+ nested = false,
+ rtl = false,
+ virtual = false,
+ focusItemOnOpen = 'auto',
+ focusItemOnHover = true,
+ openOnArrowKeyDown = true,
+ disabledIndices = undefined,
+ orientation = 'vertical',
+ cols = 1,
+ scrollItemIntoView = true
+ } = _temp2 === void 0 ? {
+ listRef: {
+ current: []
+ },
+ activeIndex: null,
+ onNavigate: () => {}
+ } : _temp2;
+ if (process.env.NODE_ENV !== "production") {
+ if (allowEscape) {
+ if (!loop) {
+ console.warn(['Floating UI: `useListNavigation` looping must be enabled to allow', 'escaping.'].join(' '));
+ }
+ if (!virtual) {
+ console.warn(['Floating UI: `useListNavigation` must be virtual to allow', 'escaping.'].join(' '));
+ }
+ }
+ if (orientation === 'vertical' && cols > 1) {
+ console.warn(['Floating UI: In grid list navigation mode (`cols` > 1), the', '`orientation` should be either "horizontal" or "both".'].join(' '));
+ }
+ }
+ const parentId = useFloatingParentNodeId();
+ const tree = useFloatingTree();
+ const onNavigate = useEvent(unstable_onNavigate);
+ const focusItemOnOpenRef = React.useRef(focusItemOnOpen);
+ const indexRef = React.useRef(selectedIndex != null ? selectedIndex : -1);
+ const keyRef = React.useRef(null);
+ const isPointerModalityRef = React.useRef(true);
+ const previousOnNavigateRef = React.useRef(onNavigate);
+ const previousOpenRef = React.useRef(open);
+ const forceSyncFocus = React.useRef(false);
+ const forceScrollIntoViewRef = React.useRef(false);
+ const disabledIndicesRef = useLatestRef(disabledIndices);
+ const latestOpenRef = useLatestRef(open);
+ const scrollItemIntoViewRef = useLatestRef(scrollItemIntoView);
+ const [activeId, setActiveId] = React.useState();
+ const focusItem = React.useCallback(function (listRef, indexRef, forceScrollIntoView) {
+ if (forceScrollIntoView === void 0) {
+ forceScrollIntoView = false;
+ }
+ const item = listRef.current[indexRef.current];
+ if (virtual) {
+ setActiveId(item == null ? void 0 : item.id);
+ } else {
+ enqueueFocus(item, {
+ preventScroll: true,
+ // Mac Safari does not move the virtual cursor unless the focus call
+ // is sync. However, for the very first focus call, we need to wait
+ // for the position to be ready in order to prevent unwanted
+ // scrolling. This means the virtual cursor will not move to the first
+ // item when first opening the floating element, but will on
+ // subsequent calls. `preventScroll` is supported in modern Safari,
+ // so we can use that instead.
+ // iOS Safari must be async or the first item will not be focused.
+ sync: isMac() && isSafari() ? isPreventScrollSupported || forceSyncFocus.current : false
+ });
+ }
+ requestAnimationFrame(() => {
+ const scrollIntoViewOptions = scrollItemIntoViewRef.current;
+ const shouldScrollIntoView = scrollIntoViewOptions && item && (forceScrollIntoView || !isPointerModalityRef.current);
+ if (shouldScrollIntoView) {
+ // JSDOM doesn't support `.scrollIntoView()` but it's widely supported
+ // by all browsers.
+ item.scrollIntoView == null ? void 0 : item.scrollIntoView(typeof scrollIntoViewOptions === 'boolean' ? {
+ block: 'nearest',
+ inline: 'nearest'
+ } : scrollIntoViewOptions);
+ }
+ });
+ }, [virtual, scrollItemIntoViewRef]);
+ index(() => {
+ document.createElement('div').focus({
+ get preventScroll() {
+ isPreventScrollSupported = true;
+ return false;
+ }
+ });
+ }, []);
+
+ // Sync `selectedIndex` to be the `activeIndex` upon opening the floating
+ // element. Also, reset `activeIndex` upon closing the floating element.
+ index(() => {
+ if (!enabled) {
+ return;
+ }
+ if (open) {
+ if (focusItemOnOpenRef.current && selectedIndex != null) {
+ // Regardless of the pointer modality, we want to ensure the selected
+ // item comes into view when the floating element is opened.
+ forceScrollIntoViewRef.current = true;
+ onNavigate(selectedIndex);
+ }
+ } else if (previousOpenRef.current) {
+ // Since the user can specify `onNavigate` conditionally
+ // (onNavigate: open ? setActiveIndex : setSelectedIndex),
+ // we store and call the previous function.
+ indexRef.current = -1;
+ previousOnNavigateRef.current(null);
+ }
+ }, [enabled, open, selectedIndex, onNavigate]);
+
+ // Sync `activeIndex` to be the focused item while the floating element is
+ // open.
+ index(() => {
+ if (!enabled) {
+ return;
+ }
+ if (open) {
+ if (activeIndex == null) {
+ forceSyncFocus.current = false;
+ if (selectedIndex != null) {
+ return;
+ }
+
+ // Reset while the floating element was open (e.g. the list changed).
+ if (previousOpenRef.current) {
+ indexRef.current = -1;
+ focusItem(listRef, indexRef);
+ }
+
+ // Initial sync.
+ if (!previousOpenRef.current && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === true && keyRef.current == null)) {
+ indexRef.current = keyRef.current == null || isMainOrientationToEndKey(keyRef.current, orientation, rtl) || nested ? getMinIndex(listRef, disabledIndicesRef.current) : getMaxIndex(listRef, disabledIndicesRef.current);
+ onNavigate(indexRef.current);
+ }
+ } else if (!isIndexOutOfBounds(listRef, activeIndex)) {
+ indexRef.current = activeIndex;
+ focusItem(listRef, indexRef, forceScrollIntoViewRef.current);
+ forceScrollIntoViewRef.current = false;
+ }
+ }
+ }, [enabled, open, activeIndex, selectedIndex, nested, listRef, orientation, rtl, onNavigate, focusItem, disabledIndicesRef]);
+
+ // Ensure the parent floating element has focus when a nested child closes
+ // to allow arrow key navigation to work after the pointer leaves the child.
+ index(() => {
+ if (!enabled) {
+ return;
+ }
+ if (previousOpenRef.current && !open) {
+ var _tree$nodesRef$curren, _tree$nodesRef$curren2;
+ const parentFloating = tree == null ? void 0 : (_tree$nodesRef$curren = tree.nodesRef.current.find(node => node.id === parentId)) == null ? void 0 : (_tree$nodesRef$curren2 = _tree$nodesRef$curren.context) == null ? void 0 : _tree$nodesRef$curren2.elements.floating;
+ if (parentFloating && !contains(parentFloating, activeElement$1(getDocument(parentFloating)))) {
+ parentFloating.focus({
+ preventScroll: true
+ });
+ }
+ }
+ }, [enabled, open, tree, parentId]);
+ index(() => {
+ keyRef.current = null;
+ previousOnNavigateRef.current = onNavigate;
+ previousOpenRef.current = open;
+ });
+ const hasActiveIndex = activeIndex != null;
+ const item = React.useMemo(() => {
+ function syncCurrentTarget(currentTarget) {
+ if (!open) return;
+ const index = listRef.current.indexOf(currentTarget);
+ if (index !== -1) {
+ onNavigate(index);
+ }
+ }
+ const props = {
+ onFocus(_ref2) {
+ let {
+ currentTarget
+ } = _ref2;
+ syncCurrentTarget(currentTarget);
+ },
+ onClick: _ref3 => {
+ let {
+ currentTarget
+ } = _ref3;
+ return currentTarget.focus({
+ preventScroll: true
+ });
+ },
+ // Safari
+ ...(focusItemOnHover && {
+ onMouseMove(_ref4) {
+ let {
+ currentTarget
+ } = _ref4;
+ syncCurrentTarget(currentTarget);
+ },
+ onPointerLeave() {
+ if (!isPointerModalityRef.current) {
+ return;
+ }
+ indexRef.current = -1;
+ focusItem(listRef, indexRef);
+
+ // Virtual cursor with VoiceOver on iOS needs this to be flushed
+ // synchronously or there is a glitch that prevents nested
+ // submenus from being accessible.
+ flushSync(() => onNavigate(null));
+ if (!virtual) {
+ var _refs$floating$curren;
+ // This also needs to be sync to prevent fast mouse movements
+ // from leaving behind a stale active item when landing on a
+ // disabled button item.
+ (_refs$floating$curren = refs.floating.current) == null ? void 0 : _refs$floating$curren.focus({
+ preventScroll: true
+ });
+ }
+ }
+ })
+ };
+ return props;
+ }, [open, refs, focusItem, focusItemOnHover, listRef, onNavigate, virtual]);
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ const disabledIndices = disabledIndicesRef.current;
+ function onKeyDown(event) {
+ isPointerModalityRef.current = false;
+ forceSyncFocus.current = true;
+
+ // If the floating element is animating out, ignore navigation. Otherwise,
+ // the `activeIndex` gets set to 0 despite not being open so the next time
+ // the user ArrowDowns, the first item won't be focused.
+ if (!latestOpenRef.current && event.currentTarget === refs.floating.current) {
+ return;
+ }
+ if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) {
+ stopEvent(event);
+ onOpenChange(false);
+ if (isHTMLElement(domReference)) {
+ domReference.focus();
+ }
+ return;
+ }
+ const currentIndex = indexRef.current;
+ const minIndex = getMinIndex(listRef, disabledIndices);
+ const maxIndex = getMaxIndex(listRef, disabledIndices);
+ if (event.key === 'Home') {
+ indexRef.current = minIndex;
+ onNavigate(indexRef.current);
+ }
+ if (event.key === 'End') {
+ indexRef.current = maxIndex;
+ onNavigate(indexRef.current);
+ }
+
+ // Grid navigation.
+ if (cols > 1) {
+ const prevIndex = indexRef.current;
+ if (event.key === ARROW_UP) {
+ stopEvent(event);
+ if (prevIndex === -1) {
+ indexRef.current = maxIndex;
+ } else {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex,
+ amount: cols,
+ decrement: true,
+ disabledIndices
+ });
+ if (loop && (prevIndex - cols < minIndex || indexRef.current < 0)) {
+ const col = prevIndex % cols;
+ const maxCol = maxIndex % cols;
+ const offset = maxIndex - (maxCol - col);
+ if (maxCol === col) {
+ indexRef.current = maxIndex;
+ } else {
+ indexRef.current = maxCol > col ? offset : offset - cols;
+ }
+ }
+ }
+ if (isIndexOutOfBounds(listRef, indexRef.current)) {
+ indexRef.current = prevIndex;
+ }
+ onNavigate(indexRef.current);
+ }
+ if (event.key === ARROW_DOWN) {
+ stopEvent(event);
+ if (prevIndex === -1) {
+ indexRef.current = minIndex;
+ } else {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex,
+ amount: cols,
+ disabledIndices
+ });
+ if (loop && prevIndex + cols > maxIndex) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex % cols - cols,
+ amount: cols,
+ disabledIndices
+ });
+ }
+ }
+ if (isIndexOutOfBounds(listRef, indexRef.current)) {
+ indexRef.current = prevIndex;
+ }
+ onNavigate(indexRef.current);
+ }
+
+ // Remains on the same row/column.
+ if (orientation === 'both') {
+ const prevRow = Math.floor(prevIndex / cols);
+ if (event.key === ARROW_RIGHT) {
+ stopEvent(event);
+ if (prevIndex % cols !== cols - 1) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex,
+ disabledIndices
+ });
+ if (loop && isDifferentRow(indexRef.current, cols, prevRow)) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex - prevIndex % cols - 1,
+ disabledIndices
+ });
+ }
+ } else if (loop) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex - prevIndex % cols - 1,
+ disabledIndices
+ });
+ }
+ if (isDifferentRow(indexRef.current, cols, prevRow)) {
+ indexRef.current = prevIndex;
+ }
+ }
+ if (event.key === ARROW_LEFT) {
+ stopEvent(event);
+ if (prevIndex % cols !== 0) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex,
+ disabledIndices,
+ decrement: true
+ });
+ if (loop && isDifferentRow(indexRef.current, cols, prevRow)) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex + (cols - prevIndex % cols),
+ decrement: true,
+ disabledIndices
+ });
+ }
+ } else if (loop) {
+ indexRef.current = findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex + (cols - prevIndex % cols),
+ decrement: true,
+ disabledIndices
+ });
+ }
+ if (isDifferentRow(indexRef.current, cols, prevRow)) {
+ indexRef.current = prevIndex;
+ }
+ }
+ const lastRow = Math.floor(maxIndex / cols) === prevRow;
+ if (isIndexOutOfBounds(listRef, indexRef.current)) {
+ if (loop && lastRow) {
+ indexRef.current = event.key === ARROW_LEFT ? maxIndex : findNonDisabledIndex(listRef, {
+ startingIndex: prevIndex - prevIndex % cols - 1,
+ disabledIndices
+ });
+ } else {
+ indexRef.current = prevIndex;
+ }
+ }
+ onNavigate(indexRef.current);
+ return;
+ }
+ }
+ if (isMainOrientationKey(event.key, orientation)) {
+ stopEvent(event);
+
+ // Reset the index if no item is focused.
+ if (open && !virtual && activeElement$1(event.currentTarget.ownerDocument) === event.currentTarget) {
+ indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex;
+ onNavigate(indexRef.current);
+ return;
+ }
+ if (isMainOrientationToEndKey(event.key, orientation, rtl)) {
+ if (loop) {
+ indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : findNonDisabledIndex(listRef, {
+ startingIndex: currentIndex,
+ disabledIndices
+ });
+ } else {
+ indexRef.current = Math.min(maxIndex, findNonDisabledIndex(listRef, {
+ startingIndex: currentIndex,
+ disabledIndices
+ }));
+ }
+ } else {
+ if (loop) {
+ indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : findNonDisabledIndex(listRef, {
+ startingIndex: currentIndex,
+ decrement: true,
+ disabledIndices
+ });
+ } else {
+ indexRef.current = Math.max(minIndex, findNonDisabledIndex(listRef, {
+ startingIndex: currentIndex,
+ decrement: true,
+ disabledIndices
+ }));
+ }
+ }
+ if (isIndexOutOfBounds(listRef, indexRef.current)) {
+ onNavigate(null);
+ } else {
+ onNavigate(indexRef.current);
+ }
+ }
+ }
+ function checkVirtualMouse(event) {
+ if (focusItemOnOpen === 'auto' && isVirtualClick(event.nativeEvent)) {
+ focusItemOnOpenRef.current = true;
+ }
+ }
+ function checkVirtualPointer(event) {
+ // `pointerdown` fires first, reset the state then perform the checks.
+ focusItemOnOpenRef.current = focusItemOnOpen;
+ if (focusItemOnOpen === 'auto' && isVirtualPointerEvent(event.nativeEvent)) {
+ focusItemOnOpenRef.current = true;
+ }
+ }
+ const ariaActiveDescendantProp = virtual && open && hasActiveIndex && {
+ 'aria-activedescendant': activeId
+ };
+ return {
+ reference: {
+ ...ariaActiveDescendantProp,
+ onKeyDown(event) {
+ isPointerModalityRef.current = false;
+ const isArrowKey = event.key.indexOf('Arrow') === 0;
+ if (virtual && open) {
+ return onKeyDown(event);
+ }
+
+ // If a floating element should not open on arrow key down, avoid
+ // setting `activeIndex` while it's closed.
+ if (!open && !openOnArrowKeyDown && isArrowKey) {
+ return;
+ }
+ const isNavigationKey = isArrowKey || event.key === 'Enter' || event.key === ' ' || event.key === '';
+ if (isNavigationKey) {
+ keyRef.current = event.key;
+ }
+ if (nested) {
+ if (isCrossOrientationOpenKey(event.key, orientation, rtl)) {
+ stopEvent(event);
+ if (open) {
+ indexRef.current = getMinIndex(listRef, disabledIndices);
+ onNavigate(indexRef.current);
+ } else {
+ onOpenChange(true);
+ }
+ }
+ return;
+ }
+ if (isMainOrientationKey(event.key, orientation)) {
+ if (selectedIndex != null) {
+ indexRef.current = selectedIndex;
+ }
+ stopEvent(event);
+ if (!open && openOnArrowKeyDown) {
+ onOpenChange(true);
+ } else {
+ onKeyDown(event);
+ }
+ if (open) {
+ onNavigate(indexRef.current);
+ }
+ }
+ },
+ onFocus() {
+ if (open) {
+ onNavigate(null);
+ }
+ },
+ onPointerDown: checkVirtualPointer,
+ onMouseDown: checkVirtualMouse,
+ onClick: checkVirtualMouse
+ },
+ floating: {
+ 'aria-orientation': orientation === 'both' ? undefined : orientation,
+ ...ariaActiveDescendantProp,
+ onKeyDown,
+ onPointerMove() {
+ isPointerModalityRef.current = true;
+ }
+ },
+ item
+ };
+ }, [domReference, refs, activeId, disabledIndicesRef, latestOpenRef, listRef, enabled, orientation, rtl, virtual, open, hasActiveIndex, nested, selectedIndex, openOnArrowKeyDown, allowEscape, cols, loop, focusItemOnOpen, onNavigate, onOpenChange, item]);
+};
+
+function useMergeRefs(refs) {
+ return React.useMemo(() => {
+ if (refs.every(ref => ref == null)) {
+ return null;
+ }
+ return value => {
+ refs.forEach(ref => {
+ if (typeof ref === 'function') {
+ ref(value);
+ } else if (ref != null) {
+ ref.current = value;
+ }
+ });
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, refs);
+}
+
+/**
+ * Adds relevant screen reader props for a given element `role`.
+ * @see https://floating-ui.com/docs/useRole
+ */
+const useRole = function (_ref, _temp) {
+ let {
+ open
+ } = _ref;
+ let {
+ enabled = true,
+ role = 'dialog'
+ } = _temp === void 0 ? {} : _temp;
+ const rootId = useId();
+ const referenceId = useId();
+ return React.useMemo(() => {
+ const floatingProps = {
+ id: rootId,
+ role
+ };
+ if (!enabled) {
+ return {};
+ }
+ if (role === 'tooltip') {
+ return {
+ reference: {
+ 'aria-describedby': open ? rootId : undefined
+ },
+ floating: floatingProps
+ };
+ }
+ return {
+ reference: {
+ 'aria-expanded': open ? 'true' : 'false',
+ 'aria-haspopup': role === 'alertdialog' ? 'dialog' : role,
+ 'aria-controls': open ? rootId : undefined,
+ ...(role === 'listbox' && {
+ role: 'combobox'
+ }),
+ ...(role === 'menu' && {
+ id: referenceId
+ })
+ },
+ floating: {
+ ...floatingProps,
+ ...(role === 'menu' && {
+ 'aria-labelledby': referenceId
+ })
+ }
+ };
+ }, [enabled, role, open, rootId, referenceId]);
+};
+
+// Converts a JS style key like `backgroundColor` to a CSS transition-property
+// like `background-color`.
+const camelCaseToKebabCase = str => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
+function useDelayUnmount(open, durationMs) {
+ const [isMounted, setIsMounted] = React.useState(open);
+ if (open && !isMounted) {
+ setIsMounted(true);
+ }
+ React.useEffect(() => {
+ if (!open) {
+ const timeout = setTimeout(() => setIsMounted(false), durationMs);
+ return () => clearTimeout(timeout);
+ }
+ }, [open, durationMs]);
+ return isMounted;
+}
+/**
+ * Provides a status string to apply CSS transitions to a floating element,
+ * correctly handling placement-aware transitions.
+ * @see https://floating-ui.com/docs/useTransition#usetransitionstatus
+ */
+function useTransitionStatus(_ref, _temp) {
+ let {
+ open,
+ elements: {
+ floating
+ }
+ } = _ref;
+ let {
+ duration = 250
+ } = _temp === void 0 ? {} : _temp;
+ const isNumberDuration = typeof duration === 'number';
+ const closeDuration = (isNumberDuration ? duration : duration.close) || 0;
+ const [initiated, setInitiated] = React.useState(false);
+ const [status, setStatus] = React.useState('unmounted');
+ const isMounted = useDelayUnmount(open, closeDuration);
+
+ // `initiated` check prevents this `setState` call from breaking
+ //
. This call is necessary to ensure subsequent opens
+ // after the initial one allows the correct side animation to play when the
+ // placement has changed.
+ index(() => {
+ if (initiated && !isMounted) {
+ setStatus('unmounted');
+ }
+ }, [initiated, isMounted]);
+ index(() => {
+ if (!floating) return;
+ if (open) {
+ setStatus('initial');
+ const frame = requestAnimationFrame(() => {
+ setStatus('open');
+ });
+ return () => {
+ cancelAnimationFrame(frame);
+ };
+ } else {
+ setInitiated(true);
+ setStatus('close');
+ }
+ }, [open, floating]);
+ return {
+ isMounted,
+ status
+ };
+}
+/**
+ * Provides styles to apply CSS transitions to a floating element, correctly
+ * handling placement-aware transitions. Wrapper around `useTransitionStatus`.
+ * @see https://floating-ui.com/docs/useTransition#usetransitionstyles
+ */
+function useTransitionStyles(context, _temp2) {
+ let {
+ initial: unstable_initial = {
+ opacity: 0
+ },
+ open: unstable_open,
+ close: unstable_close,
+ common: unstable_common,
+ duration = 250
+ } = _temp2 === void 0 ? {} : _temp2;
+ const placement = context.placement;
+ const side = placement.split('-')[0];
+ const [styles, setStyles] = React.useState({});
+ const {
+ isMounted,
+ status
+ } = useTransitionStatus(context, {
+ duration
+ });
+ const initialRef = useLatestRef(unstable_initial);
+ const openRef = useLatestRef(unstable_open);
+ const closeRef = useLatestRef(unstable_close);
+ const commonRef = useLatestRef(unstable_common);
+ const isNumberDuration = typeof duration === 'number';
+ const openDuration = (isNumberDuration ? duration : duration.open) || 0;
+ const closeDuration = (isNumberDuration ? duration : duration.close) || 0;
+ index(() => {
+ const fnArgs = {
+ side,
+ placement
+ };
+ const initial = initialRef.current;
+ const close = closeRef.current;
+ const open = openRef.current;
+ const common = commonRef.current;
+ const initialStyles = typeof initial === 'function' ? initial(fnArgs) : initial;
+ const closeStyles = typeof close === 'function' ? close(fnArgs) : close;
+ const commonStyles = typeof common === 'function' ? common(fnArgs) : common;
+ const openStyles = (typeof open === 'function' ? open(fnArgs) : open) || Object.keys(initialStyles).reduce((acc, key) => {
+ acc[key] = '';
+ return acc;
+ }, {});
+ if (status === 'initial') {
+ setStyles(styles => ({
+ transitionProperty: styles.transitionProperty,
+ ...commonStyles,
+ ...initialStyles
+ }));
+ }
+ if (status === 'open') {
+ setStyles({
+ transitionProperty: Object.keys(openStyles).map(camelCaseToKebabCase).join(','),
+ transitionDuration: openDuration + "ms",
+ ...commonStyles,
+ ...openStyles
+ });
+ }
+ if (status === 'close') {
+ const styles = closeStyles || initialStyles;
+ setStyles({
+ transitionProperty: Object.keys(styles).map(camelCaseToKebabCase).join(','),
+ transitionDuration: closeDuration + "ms",
+ ...commonStyles,
+ ...styles
+ });
+ }
+ }, [side, placement, closeDuration, closeRef, initialRef, openRef, commonRef, openDuration, status]);
+ return {
+ isMounted,
+ styles
+ };
+}
+
+/**
+ * Provides a matching callback that can be used to focus an item as the user
+ * types, often used in tandem with `useListNavigation()`.
+ * @see https://floating-ui.com/docs/useTypeahead
+ */
+const useTypeahead = function (_ref, _temp) {
+ var _ref2;
+ let {
+ open,
+ dataRef
+ } = _ref;
+ let {
+ listRef,
+ activeIndex,
+ onMatch: unstable_onMatch = () => {},
+ enabled = true,
+ findMatch = null,
+ resetMs = 1000,
+ ignoreKeys = [],
+ selectedIndex = null
+ } = _temp === void 0 ? {
+ listRef: {
+ current: []
+ },
+ activeIndex: null
+ } : _temp;
+ const timeoutIdRef = React.useRef();
+ const stringRef = React.useRef('');
+ const prevIndexRef = React.useRef((_ref2 = selectedIndex != null ? selectedIndex : activeIndex) != null ? _ref2 : -1);
+ const matchIndexRef = React.useRef(null);
+ const onMatch = useEvent(unstable_onMatch);
+ const findMatchRef = useLatestRef(findMatch);
+ const ignoreKeysRef = useLatestRef(ignoreKeys);
+ index(() => {
+ if (open) {
+ clearTimeout(timeoutIdRef.current);
+ matchIndexRef.current = null;
+ stringRef.current = '';
+ }
+ }, [open]);
+ index(() => {
+ // Sync arrow key navigation but not typeahead navigation.
+ if (open && stringRef.current === '') {
+ var _ref3;
+ prevIndexRef.current = (_ref3 = selectedIndex != null ? selectedIndex : activeIndex) != null ? _ref3 : -1;
+ }
+ }, [open, selectedIndex, activeIndex]);
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ function onKeyDown(event) {
+ // Correctly scope nested non-portalled floating elements. Since the nested
+ // floating element is inside of the another, we find the closest role
+ // that indicates the floating element scope.
+ const target = getTarget(event.nativeEvent);
+ if (isElement(target) && (activeElement$1(getDocument(target)) !== event.currentTarget ? target.closest('[role="dialog"],[role="menu"],[role="listbox"],[role="tree"],[role="grid"]') !== event.currentTarget : false)) {
+ return;
+ }
+ if (stringRef.current.length > 0 && stringRef.current[0] !== ' ') {
+ dataRef.current.typing = true;
+ if (event.key === ' ') {
+ stopEvent(event);
+ }
+ }
+ const listContent = listRef.current;
+ if (listContent == null || ignoreKeysRef.current.includes(event.key) ||
+ // Character key.
+ event.key.length !== 1 ||
+ // Modifier key.
+ event.ctrlKey || event.metaKey || event.altKey) {
+ return;
+ }
+
+ // Bail out if the list contains a word like "llama" or "aaron". TODO:
+ // allow it in this case, too.
+ const allowRapidSuccessionOfFirstLetter = listContent.every(text => {
+ var _text$, _text$2;
+ return text ? ((_text$ = text[0]) == null ? void 0 : _text$.toLocaleLowerCase()) !== ((_text$2 = text[1]) == null ? void 0 : _text$2.toLocaleLowerCase()) : true;
+ });
+
+ // Allows the user to cycle through items that start with the same letter
+ // in rapid succession.
+ if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
+ stringRef.current = '';
+ prevIndexRef.current = matchIndexRef.current;
+ }
+ stringRef.current += event.key;
+ clearTimeout(timeoutIdRef.current);
+ timeoutIdRef.current = setTimeout(() => {
+ stringRef.current = '';
+ prevIndexRef.current = matchIndexRef.current;
+ dataRef.current.typing = false;
+ }, resetMs);
+ const prevIndex = prevIndexRef.current;
+ const orderedList = [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)];
+ const str = findMatchRef.current ? findMatchRef.current(orderedList, stringRef.current) : orderedList.find(text => (text == null ? void 0 : text.toLocaleLowerCase().indexOf(stringRef.current.toLocaleLowerCase())) === 0);
+ const index = str ? listContent.indexOf(str) : -1;
+ if (index !== -1) {
+ onMatch(index);
+ matchIndexRef.current = index;
+ }
+ }
+ return {
+ reference: {
+ onKeyDown
+ },
+ floating: {
+ onKeyDown
+ }
+ };
+ }, [enabled, dataRef, listRef, resetMs, ignoreKeysRef, findMatchRef, onMatch]);
+};
+
+function getArgsWithCustomFloatingHeight(args, height) {
+ return {
+ ...args,
+ rects: {
+ ...args.rects,
+ floating: {
+ ...args.rects.floating,
+ height
+ }
+ }
+ };
+}
+/**
+ * Positions the floating element such that an inner element inside
+ * of it is anchored to the reference element.
+ * @see https://floating-ui.com/docs/inner
+ */
+const inner = props => ({
+ name: 'inner',
+ options: props,
+ async fn(middlewareArguments) {
+ const {
+ listRef,
+ overflowRef,
+ onFallbackChange,
+ offset: innerOffset = 0,
+ index = 0,
+ minItemsVisible = 4,
+ referenceOverflowThreshold = 0,
+ scrollRef,
+ ...detectOverflowOptions
+ } = props;
+ const {
+ rects,
+ elements: {
+ floating
+ }
+ } = middlewareArguments;
+ const item = listRef.current[index];
+ if (process.env.NODE_ENV !== "production") {
+ if (!middlewareArguments.placement.startsWith('bottom')) {
+ console.warn(['Floating UI: `placement` side must be "bottom" when using the', '`inner` middleware.'].join(' '));
+ }
+ }
+ if (!item) {
+ return {};
+ }
+ const nextArgs = {
+ ...middlewareArguments,
+ ...(await offset(-item.offsetTop - rects.reference.height / 2 - item.offsetHeight / 2 - innerOffset).fn(middlewareArguments))
+ };
+ const el = (scrollRef == null ? void 0 : scrollRef.current) || floating;
+ const overflow = await detectOverflow(getArgsWithCustomFloatingHeight(nextArgs, el.scrollHeight), detectOverflowOptions);
+ const refOverflow = await detectOverflow(nextArgs, {
+ ...detectOverflowOptions,
+ elementContext: 'reference'
+ });
+ const diffY = Math.max(0, overflow.top);
+ const nextY = nextArgs.y + diffY;
+ const maxHeight = Math.max(0, el.scrollHeight - diffY - Math.max(0, overflow.bottom));
+ el.style.maxHeight = maxHeight + "px";
+ el.scrollTop = diffY;
+
+ // There is not enough space, fallback to standard anchored positioning
+ if (onFallbackChange) {
+ if (el.offsetHeight < item.offsetHeight * Math.min(minItemsVisible, listRef.current.length - 1) - 1 || refOverflow.top >= -referenceOverflowThreshold || refOverflow.bottom >= -referenceOverflowThreshold) {
+ flushSync(() => onFallbackChange(true));
+ } else {
+ flushSync(() => onFallbackChange(false));
+ }
+ }
+ if (overflowRef) {
+ overflowRef.current = await detectOverflow(getArgsWithCustomFloatingHeight({
+ ...nextArgs,
+ y: nextY
+ }, el.offsetHeight), detectOverflowOptions);
+ }
+ return {
+ y: nextY
+ };
+ }
+});
+/**
+ * Changes the `inner` middleware's `offset` upon a `wheel` event to
+ * expand the floating element's height, revealing more list items.
+ * @see https://floating-ui.com/docs/inner
+ */
+const useInnerOffset = (_ref, _ref2) => {
+ let {
+ open,
+ elements
+ } = _ref;
+ let {
+ enabled = true,
+ overflowRef,
+ scrollRef,
+ onChange: unstable_onChange
+ } = _ref2;
+ const onChange = useEvent(unstable_onChange);
+ const controlledScrollingRef = React.useRef(false);
+ const prevScrollTopRef = React.useRef(null);
+ const initialOverflowRef = React.useRef(null);
+ React.useEffect(() => {
+ if (!enabled) {
+ return;
+ }
+ function onWheel(e) {
+ if (e.ctrlKey || !el || overflowRef.current == null) {
+ return;
+ }
+ const dY = e.deltaY;
+ const isAtTop = overflowRef.current.top >= -0.5;
+ const isAtBottom = overflowRef.current.bottom >= -0.5;
+ const remainingScroll = el.scrollHeight - el.clientHeight;
+ const sign = dY < 0 ? -1 : 1;
+ const method = dY < 0 ? 'max' : 'min';
+ if (el.scrollHeight <= el.clientHeight) {
+ return;
+ }
+ if (!isAtTop && dY > 0 || !isAtBottom && dY < 0) {
+ e.preventDefault();
+ flushSync(() => {
+ onChange(d => d + Math[method](dY, remainingScroll * sign));
+ });
+ } else if (/firefox/i.test(getUserAgent())) {
+ // Needed to propagate scrolling during momentum scrolling phase once
+ // it gets limited by the boundary. UX improvement, not critical.
+ el.scrollTop += dY;
+ }
+ }
+ const el = (scrollRef == null ? void 0 : scrollRef.current) || elements.floating;
+ if (open && el) {
+ el.addEventListener('wheel', onWheel);
+
+ // Wait for the position to be ready.
+ requestAnimationFrame(() => {
+ prevScrollTopRef.current = el.scrollTop;
+ if (overflowRef.current != null) {
+ initialOverflowRef.current = {
+ ...overflowRef.current
+ };
+ }
+ });
+ return () => {
+ prevScrollTopRef.current = null;
+ initialOverflowRef.current = null;
+ el.removeEventListener('wheel', onWheel);
+ };
+ }
+ }, [enabled, open, elements.floating, overflowRef, scrollRef, onChange]);
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ return {
+ floating: {
+ onKeyDown() {
+ controlledScrollingRef.current = true;
+ },
+ onWheel() {
+ controlledScrollingRef.current = false;
+ },
+ onPointerMove() {
+ controlledScrollingRef.current = false;
+ },
+ onScroll() {
+ const el = (scrollRef == null ? void 0 : scrollRef.current) || elements.floating;
+ if (!overflowRef.current || !el || !controlledScrollingRef.current) {
+ return;
+ }
+ if (prevScrollTopRef.current !== null) {
+ const scrollDiff = el.scrollTop - prevScrollTopRef.current;
+ if (overflowRef.current.bottom < -0.5 && scrollDiff < -1 || overflowRef.current.top < -0.5 && scrollDiff > 1) {
+ flushSync(() => onChange(d => d + scrollDiff));
+ }
+ }
+
+ // [Firefox] Wait for the height change to have been applied.
+ requestAnimationFrame(() => {
+ prevScrollTopRef.current = el.scrollTop;
+ });
+ }
+ }
+ };
+ }, [enabled, overflowRef, elements.floating, scrollRef, onChange]);
+};
+
+function isPointInPolygon(point, polygon) {
+ const [x, y] = point;
+ let isInside = false;
+ const length = polygon.length;
+ for (let i = 0, j = length - 1; i < length; j = i++) {
+ const [xi, yi] = polygon[i] || [0, 0];
+ const [xj, yj] = polygon[j] || [0, 0];
+ const intersect = yi >= y !== yj >= y && x <= (xj - xi) * (y - yi) / (yj - yi) + xi;
+ if (intersect) {
+ isInside = !isInside;
+ }
+ }
+ return isInside;
+}
+function isInside(point, rect) {
+ return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
+}
+function safePolygon(_temp) {
+ let {
+ restMs = 0,
+ buffer = 0.5,
+ blockPointerEvents = false
+ } = _temp === void 0 ? {} : _temp;
+ let timeoutId;
+ let isInsideRect = false;
+ let hasLanded = false;
+ const fn = _ref => {
+ let {
+ x,
+ y,
+ placement,
+ elements,
+ onClose,
+ nodeId,
+ tree
+ } = _ref;
+ return function onMouseMove(event) {
+ function close() {
+ clearTimeout(timeoutId);
+ onClose();
+ }
+ clearTimeout(timeoutId);
+ if (!elements.domReference || !elements.floating || placement == null || x == null || y == null) {
+ return;
+ }
+ const {
+ clientX,
+ clientY
+ } = event;
+ const clientPoint = [clientX, clientY];
+ const target = getTarget(event);
+ const isLeave = event.type === 'mouseleave';
+ const isOverFloatingEl = contains(elements.floating, target);
+ const isOverReferenceEl = contains(elements.domReference, target);
+ const refRect = elements.domReference.getBoundingClientRect();
+ const rect = elements.floating.getBoundingClientRect();
+ const side = placement.split('-')[0];
+ const cursorLeaveFromRight = x > rect.right - rect.width / 2;
+ const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
+ const isOverReferenceRect = isInside(clientPoint, refRect);
+ if (isOverFloatingEl) {
+ hasLanded = true;
+ }
+ if (isOverReferenceEl) {
+ hasLanded = false;
+ }
+ if (isOverReferenceEl && !isLeave) {
+ hasLanded = true;
+ return;
+ }
+
+ // Prevent overlapping floating element from being stuck in an open-close
+ // loop: https://github.com/floating-ui/floating-ui/issues/1910
+ if (isLeave && isElement(event.relatedTarget) && contains(elements.floating, event.relatedTarget)) {
+ return;
+ }
+
+ // If any nested child is open, abort.
+ if (tree && getChildren(tree.nodesRef.current, nodeId).some(_ref2 => {
+ let {
+ context
+ } = _ref2;
+ return context == null ? void 0 : context.open;
+ })) {
+ return;
+ }
+
+ // If the pointer is leaving from the opposite side, the "buffer" logic
+ // creates a point where the floating element remains open, but should be
+ // ignored.
+ // A constant of 1 handles floating point rounding errors.
+ if (side === 'top' && y >= refRect.bottom - 1 || side === 'bottom' && y <= refRect.top + 1 || side === 'left' && x >= refRect.right - 1 || side === 'right' && x <= refRect.left + 1) {
+ return close();
+ }
+
+ // Ignore when the cursor is within the rectangular trough between the
+ // two elements. Since the triangle is created from the cursor point,
+ // which can start beyond the ref element's edge, traversing back and
+ // forth from the ref to the floating element can cause it to close. This
+ // ensures it always remains open in that case.
+ let rectPoly = [];
+ switch (side) {
+ case 'top':
+ rectPoly = [[rect.left, refRect.top + 1], [rect.left, rect.bottom - 1], [rect.right, rect.bottom - 1], [rect.right, refRect.top + 1]];
+ isInsideRect = clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= refRect.top + 1;
+ break;
+ case 'bottom':
+ rectPoly = [[rect.left, rect.top + 1], [rect.left, refRect.bottom - 1], [rect.right, refRect.bottom - 1], [rect.right, rect.top + 1]];
+ isInsideRect = clientX >= rect.left && clientX <= rect.right && clientY >= refRect.bottom - 1 && clientY <= rect.bottom;
+ break;
+ case 'left':
+ rectPoly = [[rect.right - 1, rect.bottom], [rect.right - 1, rect.top], [refRect.left + 1, rect.top], [refRect.left + 1, rect.bottom]];
+ isInsideRect = clientX >= rect.left && clientX <= refRect.left + 1 && clientY >= rect.top && clientY <= rect.bottom;
+ break;
+ case 'right':
+ rectPoly = [[refRect.right - 1, rect.bottom], [refRect.right - 1, rect.top], [rect.left + 1, rect.top], [rect.left + 1, rect.bottom]];
+ isInsideRect = clientX >= refRect.right - 1 && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;
+ break;
+ }
+ function getPolygon(_ref3) {
+ let [x, y] = _ref3;
+ const isFloatingWider = rect.width > refRect.width;
+ const isFloatingTaller = rect.height > refRect.height;
+ switch (side) {
+ case 'top':
+ {
+ const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
+ const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y + buffer + 1];
+ const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.bottom - buffer : isFloatingWider ? rect.bottom - buffer : rect.top], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.bottom - buffer : rect.top : rect.bottom - buffer]];
+ return [cursorPointOne, cursorPointTwo, ...commonPoints];
+ }
+ case 'bottom':
+ {
+ const cursorPointOne = [isFloatingWider ? x + buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
+ const cursorPointTwo = [isFloatingWider ? x - buffer / 2 : cursorLeaveFromRight ? x + buffer * 4 : x - buffer * 4, y - buffer];
+ const commonPoints = [[rect.left, cursorLeaveFromRight ? rect.top + buffer : isFloatingWider ? rect.top + buffer : rect.bottom], [rect.right, cursorLeaveFromRight ? isFloatingWider ? rect.top + buffer : rect.bottom : rect.top + buffer]];
+ return [cursorPointOne, cursorPointTwo, ...commonPoints];
+ }
+ case 'left':
+ {
+ const cursorPointOne = [x + buffer + 1, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
+ const cursorPointTwo = [x + buffer + 1, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
+ const commonPoints = [[cursorLeaveFromBottom ? rect.right - buffer : isFloatingTaller ? rect.right - buffer : rect.left, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.right - buffer : rect.left : rect.right - buffer, rect.bottom]];
+ return [...commonPoints, cursorPointOne, cursorPointTwo];
+ }
+ case 'right':
+ {
+ const cursorPointOne = [x - buffer, isFloatingTaller ? y + buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
+ const cursorPointTwo = [x - buffer, isFloatingTaller ? y - buffer / 2 : cursorLeaveFromBottom ? y + buffer * 4 : y - buffer * 4];
+ const commonPoints = [[cursorLeaveFromBottom ? rect.left + buffer : isFloatingTaller ? rect.left + buffer : rect.right, rect.top], [cursorLeaveFromBottom ? isFloatingTaller ? rect.left + buffer : rect.right : rect.left + buffer, rect.bottom]];
+ return [cursorPointOne, cursorPointTwo, ...commonPoints];
+ }
+ }
+ }
+ const poly = isInsideRect ? rectPoly : getPolygon([x, y]);
+ if (isInsideRect) {
+ return;
+ } else if (hasLanded && !isOverReferenceRect) {
+ return close();
+ }
+ if (!isPointInPolygon([clientX, clientY], poly)) {
+ close();
+ } else if (restMs && !hasLanded) {
+ timeoutId = setTimeout(close, restMs);
+ }
+ };
+ };
+ fn.__options = {
+ blockPointerEvents
+ };
+ return fn;
+}
+
+function useFloating(options) {
+ if (options === void 0) {
+ options = {};
+ }
+ const {
+ open = false,
+ onOpenChange: unstable_onOpenChange,
+ nodeId
+ } = options;
+ const position = useFloating$1(options);
+ const tree = useFloatingTree();
+ const domReferenceRef = React.useRef(null);
+ const dataRef = React.useRef({});
+ const events = React.useState(() => createPubSub())[0];
+ const [domReference, setDomReference] = React.useState(null);
+ const setPositionReference = React.useCallback(node => {
+ const positionReference = isElement(node) ? {
+ getBoundingClientRect: () => node.getBoundingClientRect(),
+ contextElement: node
+ } : node;
+ position.refs.setReference(positionReference);
+ }, [position.refs]);
+ const setReference = React.useCallback(node => {
+ if (isElement(node) || node === null) {
+ domReferenceRef.current = node;
+ setDomReference(node);
+ }
+
+ // Backwards-compatibility for passing a virtual element to `reference`
+ // after it has set the DOM reference.
+ if (isElement(position.refs.reference.current) || position.refs.reference.current === null ||
+ // Don't allow setting virtual elements using the old technique back to
+ // `null` to support `positionReference` + an unstable `reference`
+ // callback ref.
+ node !== null && !isElement(node)) {
+ position.refs.setReference(node);
+ }
+ }, [position.refs]);
+ const refs = React.useMemo(() => ({
+ ...position.refs,
+ setReference,
+ setPositionReference,
+ domReference: domReferenceRef
+ }), [position.refs, setReference, setPositionReference]);
+ const elements = React.useMemo(() => ({
+ ...position.elements,
+ domReference: domReference
+ }), [position.elements, domReference]);
+ const onOpenChange = useEvent(unstable_onOpenChange);
+ const context = React.useMemo(() => ({
+ ...position,
+ refs,
+ elements,
+ dataRef,
+ nodeId,
+ events,
+ open,
+ onOpenChange
+ }), [position, nodeId, events, open, onOpenChange, refs, elements]);
+ index(() => {
+ const node = tree == null ? void 0 : tree.nodesRef.current.find(node => node.id === nodeId);
+ if (node) {
+ node.context = context;
+ }
+ });
+ return React.useMemo(() => ({
+ ...position,
+ context,
+ refs,
+ reference: setReference,
+ positionReference: setPositionReference
+ }), [position, refs, context, setReference, setPositionReference]);
+}
+
+function mergeProps(userProps, propsList, elementKey) {
+ const map = new Map();
+ return {
+ ...(elementKey === 'floating' && {
+ tabIndex: -1
+ }),
+ ...userProps,
+ ...propsList.map(value => value ? value[elementKey] : null).concat(userProps).reduce((acc, props) => {
+ if (!props) {
+ return acc;
+ }
+ Object.entries(props).forEach(_ref => {
+ let [key, value] = _ref;
+ if (key.indexOf('on') === 0) {
+ if (!map.has(key)) {
+ map.set(key, []);
+ }
+ if (typeof value === 'function') {
+ var _map$get;
+ (_map$get = map.get(key)) == null ? void 0 : _map$get.push(value);
+ acc[key] = function () {
+ var _map$get2;
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
+ args[_key] = arguments[_key];
+ }
+ (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.forEach(fn => fn(...args));
+ };
+ }
+ } else {
+ acc[key] = value;
+ }
+ });
+ return acc;
+ }, {})
+ };
+}
+const useInteractions = function (propsList) {
+ if (propsList === void 0) {
+ propsList = [];
+ }
+ // The dependencies are a dynamic array, so we can't use the linter's
+ // suggestion to add it to the deps array.
+ const deps = propsList;
+ const getReferenceProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'reference'),
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ deps);
+ const getFloatingProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'floating'),
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ deps);
+ const getItemProps = React.useCallback(userProps => mergeProps(userProps, propsList, 'item'),
+ // Granularly check for `item` changes, because the `getItemProps` getter
+ // should be as referentially stable as possible since it may be passed as
+ // a prop to many components. All `item` key values must therefore be
+ // memoized.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ propsList.map(key => key == null ? void 0 : key.item));
+ return React.useMemo(() => ({
+ getReferenceProps,
+ getFloatingProps,
+ getItemProps
+ }), [getReferenceProps, getFloatingProps, getItemProps]);
+};
+
+export { FloatingDelayGroup, FloatingFocusManager, FloatingNode, FloatingOverlay, FloatingPortal, FloatingTree, inner, safePolygon, useClick, useDelayGroup, useDelayGroupContext, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingPortalNode, useFloatingTree, useFocus, useHover, useId, useInnerOffset, useInteractions, useListNavigation, useMergeRefs, useRole, useTransitionStatus, useTransitionStyles, useTypeahead };
diff --git a/node_modules/@floating-ui/react/dist/floating-ui.react.esm.min.js b/node_modules/@floating-ui/react/dist/floating-ui.react.esm.min.js
new file mode 100644
index 0000000..5e91843
--- /dev/null
+++ b/node_modules/@floating-ui/react/dist/floating-ui.react.esm.min.js
@@ -0,0 +1 @@
+import*as e from"react";import{useLayoutEffect as t,useEffect as n,useRef as r}from"react";import{hideOthers as o}from"aria-hidden";import{tabbable as u}from"tabbable";import{createPortal as c,flushSync as i}from"react-dom";import{getOverflowAncestors as l,offset as s,detectOverflow as a,useFloating as f}from"@floating-ui/react-dom";export{arrow}from"@floating-ui/react-dom";export{autoPlacement,autoUpdate,computePosition,detectOverflow,flip,getOverflowAncestors,hide,inline,limitShift,offset,platform,shift,size}from"@floating-ui/dom";var d="undefined"!=typeof document?t:n;let m=!1,v=0;const p=()=>"floating-ui-"+v++;const g=e["useId".toString()]||function(){const[t,n]=e.useState((()=>m?p():void 0));return d((()=>{null==t&&n(p())}),[]),e.useEffect((()=>{m||(m=!0)}),[]),t};function b(){const e=new Map;return{emit(t,n){var r;null==(r=e.get(t))||r.forEach((e=>e(n)))},on(t,n){e.set(t,[...e.get(t)||[],n])},off(t,n){e.set(t,(e.get(t)||[]).filter((e=>e!==n)))}}}const h=e.createContext(null),y=e.createContext(null),w=()=>{var t;return(null==(t=e.useContext(h))?void 0:t.id)||null},E=()=>e.useContext(y),R=e=>{const t=g(),n=E(),r=w(),o=e||r;return d((()=>{const e={id:t,parentId:o};return null==n||n.addNode(e),()=>{null==n||n.removeNode(e)}}),[n,t,o]),t},x=t=>{let{children:n,id:r}=t;const o=w();return e.createElement(h.Provider,{value:e.useMemo((()=>({id:r,parentId:o})),[r,o])},n)},I=t=>{let{children:n}=t;const r=e.useRef([]),o=e.useCallback((e=>{r.current=[...r.current,e]}),[]),u=e.useCallback((e=>{r.current=r.current.filter((t=>t!==e))}),[]),c=e.useState((()=>b()))[0];return e.createElement(y.Provider,{value:e.useMemo((()=>({nodesRef:r,addNode:o,removeNode:u,events:c})),[r,o,u,c])},n)};function k(e){return(null==e?void 0:e.ownerDocument)||document}function T(){const e=navigator.userAgentData;return null!=e&&e.platform?e.platform:navigator.platform}function C(){const e=navigator.userAgentData;return e&&Array.isArray(e.brands)?e.brands.map((e=>{let{brand:t,version:n}=e;return t+"/"+n})).join(" "):navigator.userAgent}function M(e){return k(e).defaultView||window}function A(e){return!!e&&e instanceof M(e).Element}function L(e){return!!e&&e instanceof M(e).HTMLElement}function O(e){if(0===e.mozInputSource&&e.isTrusted)return!0;const t=/Android/i;return(t.test(T())||t.test(C()))&&e.pointerType?"click"===e.type&&1===e.buttons:0===e.detail&&!e.pointerType}function P(e){return 0===e.width&&0===e.height||1===e.width&&1===e.height&&0===e.pressure&&0===e.detail&&"mouse"!==e.pointerType||e.width<1&&e.height<1&&0===e.pressure&&0===e.detail}function S(){return/apple/i.test(navigator.vendor)}function D(){return T().toLowerCase().startsWith("mac")&&!navigator.maxTouchPoints}function F(e,t){const n=["mouse","pen"];return t||n.push("",void 0),n.includes(e)}function K(e){const t=r(e);return d((()=>{t.current=e})),t}function H(e,t,n){return n&&!F(n)?0:"number"==typeof e?e:null==e?void 0:e[t]}const N=function(t,n){let{enabled:r=!0,delay:o=0,handleClose:u=null,mouseOnly:c=!1,restMs:i=0,move:l=!0}=void 0===n?{}:n;const{open:s,onOpenChange:a,dataRef:f,events:m,elements:{domReference:v,floating:p},refs:g}=t,b=E(),h=w(),y=K(u),R=K(o),x=e.useRef(),I=e.useRef(),T=e.useRef(),C=e.useRef(),M=e.useRef(!0),L=e.useRef(!1),O=e.useRef((()=>{})),P=e.useCallback((()=>{var e;const t=null==(e=f.current.openEvent)?void 0:e.type;return(null==t?void 0:t.includes("mouse"))&&"mousedown"!==t}),[f]);e.useEffect((()=>{if(r)return m.on("dismiss",e),()=>{m.off("dismiss",e)};function e(){clearTimeout(I.current),clearTimeout(C.current),M.current=!0}}),[r,m]),e.useEffect((()=>{if(!r||!y.current||!s)return;function e(){P()&&a(!1)}const t=k(p).documentElement;return t.addEventListener("mouseleave",e),()=>{t.removeEventListener("mouseleave",e)}}),[p,s,a,r,y,f,P]);const S=e.useCallback((function(e){void 0===e&&(e=!0);const t=H(R.current,"close",x.current);t&&!T.current?(clearTimeout(I.current),I.current=setTimeout((()=>a(!1)),t)):e&&(clearTimeout(I.current),a(!1))}),[R,a]),D=e.useCallback((()=>{O.current(),T.current=void 0}),[]),N=e.useCallback((()=>{if(L.current){const e=k(g.floating.current).body;e.style.pointerEvents="",e.removeAttribute("data-floating-ui-safe-polygon"),L.current=!1}}),[g]);return e.useEffect((()=>{if(r&&A(v)){const e=v;return s&&e.addEventListener("mouseleave",u),null==p||p.addEventListener("mouseleave",u),l&&e.addEventListener("mousemove",n,{once:!0}),e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",o),()=>{s&&e.removeEventListener("mouseleave",u),null==p||p.removeEventListener("mouseleave",u),l&&e.removeEventListener("mousemove",n),e.removeEventListener("mouseenter",n),e.removeEventListener("mouseleave",o)}}function e(){return!!f.current.openEvent&&["click","mousedown"].includes(f.current.openEvent.type)}function n(e){if(clearTimeout(I.current),M.current=!1,c&&!F(x.current)||i>0&&0===H(R.current,"open"))return;f.current.openEvent=e;const t=H(R.current,"open",x.current);t?I.current=setTimeout((()=>{a(!0)}),t):a(!0)}function o(n){if(e())return;O.current();const r=k(p);if(clearTimeout(C.current),y.current){clearTimeout(I.current),T.current=y.current({...t,tree:b,x:n.clientX,y:n.clientY,onClose(){N(),D(),S()}});const e=T.current;return r.addEventListener("mousemove",e),void(O.current=()=>{r.removeEventListener("mousemove",e)})}S()}function u(n){e()||null==y.current||y.current({...t,tree:b,x:n.clientX,y:n.clientY,onClose(){D(),S()}})(n)}}),[v,p,r,t,c,i,l,S,D,N,a,s,b,R,y,f]),d((()=>{var e;if(r&&s&&null!=(e=y.current)&&e.__options.blockPointerEvents&&P()){const e=k(p).body;if(e.setAttribute("data-floating-ui-safe-polygon",""),e.style.pointerEvents="none",L.current=!0,A(v)&&p){var t,n;const e=v,r=null==b||null==(t=b.nodesRef.current.find((e=>e.id===h)))||null==(n=t.context)?void 0:n.elements.floating;return r&&(r.style.pointerEvents=""),e.style.pointerEvents="auto",p.style.pointerEvents="auto",()=>{e.style.pointerEvents="",p.style.pointerEvents=""}}}}),[r,s,h,p,v,b,y,f,P]),d((()=>{s||(x.current=void 0,D(),N())}),[s,D,N]),e.useEffect((()=>()=>{D(),clearTimeout(I.current),clearTimeout(C.current),N()}),[r,D,N]),e.useMemo((()=>{if(!r)return{};function e(e){x.current=e.pointerType}return{reference:{onPointerDown:e,onPointerEnter:e,onMouseMove(){s||0===i||(clearTimeout(C.current),C.current=setTimeout((()=>{M.current||a(!0)}),i))}},floating:{onMouseEnter(){clearTimeout(I.current)},onMouseLeave(){m.emit("dismiss",{type:"mouseLeave",data:{returnFocus:!1}}),S(!1)}}}}),[m,r,i,s,a,S])},B=e.createContext({delay:0,initialDelay:0,timeoutMs:0,currentId:null,setCurrentId:()=>{},setState:()=>{},isInstantPhase:!1}),_=()=>e.useContext(B),j=t=>{let{children:n,delay:r,timeoutMs:o=0}=t;const[u,c]=e.useReducer(((e,t)=>({...e,...t})),{delay:r,timeoutMs:o,initialDelay:r,currentId:null,isInstantPhase:!1}),i=e.useRef(null),l=e.useCallback((e=>{c({currentId:e})}),[]);return d((()=>{u.currentId?null===i.current?i.current=u.currentId:c({isInstantPhase:!0}):(c({isInstantPhase:!1}),i.current=null)}),[u.currentId]),e.createElement(B.Provider,{value:e.useMemo((()=>({...u,setState:c,setCurrentId:l})),[u,c,l])},n)},V=(t,n)=>{let{open:r,onOpenChange:o}=t,{id:u}=n;const{currentId:c,setCurrentId:i,initialDelay:l,setState:s,timeoutMs:a}=_();e.useEffect((()=>{c&&(s({delay:{open:1,close:H(l,"close")}}),c!==u&&o(!1))}),[u,o,s,c,l]),e.useEffect((()=>{function e(){o(!1),s({delay:l,currentId:null})}if(!r&&c===u){if(a){const t=window.setTimeout(e,a);return()=>{clearTimeout(t)}}e()}}),[r,s,c,u,o,l,a]),e.useEffect((()=>{r&&i(u)}),[r,i,u])};function W(){return W=Object.assign||function(e){for(var t=1;t
null==e?void 0:e.focus({preventScroll:n});o?u():U=requestAnimationFrame(u)}function Y(e,t){let n=e.filter((e=>{var n;return e.parentId===t&&(null==(n=e.context)?void 0:n.open)}))||[],r=n;for(;r.length;)r=e.filter((e=>{var t;return null==(t=r)?void 0:t.some((t=>{var n;return e.parentId===t.id&&(null==(n=e.context)?void 0:n.open)}))}))||[],n=n.concat(r);return n}function Z(e){return"composedPath"in e?e.composedPath()[0]:e.target}function G(e){return L(e)&&e.matches("input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])")}function J(e){e.preventDefault(),e.stopPropagation()}const Q=()=>({getShadowRoot:!0,displayCheck:"function"==typeof ResizeObserver&&ResizeObserver.toString().includes("[native code]")?"full":"none"});function $(e,t){const n=u(e,Q());"prev"===t&&n.reverse();const r=n.indexOf(q(k(e)));return n.slice(r+1)[0]}function ee(){return $(document.body,"next")}function te(){return $(document.body,"prev")}function ne(e,t){const n=t||e.currentTarget,r=e.relatedTarget;return!r||!z(n,r)}function re(e){u(e,Q()).forEach((e=>{e.dataset.tabindex=e.getAttribute("tabindex")||"",e.setAttribute("tabindex","-1")}))}function oe(e){e.querySelectorAll("[data-tabindex]").forEach((e=>{const t=e.dataset.tabindex;delete e.dataset.tabindex,t?e.setAttribute("tabindex",t):e.removeAttribute("tabindex")}))}const ue=e["useInsertionEffect".toString()]||(e=>e());function ce(t){const n=e.useRef((()=>{}));return ue((()=>{n.current=t})),e.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r(S()&&u("button"),document.addEventListener("keydown",ae),()=>{document.removeEventListener("keydown",ae)})),[]),e.createElement("span",W({},t,{ref:n,tabIndex:0,role:o,"aria-hidden":!o||void 0,"data-floating-ui-focus-guard":"",style:ie,onFocus:e=>{S()&&D()&&!function(e){const t=le===e.relatedTarget;return le=e.relatedTarget,clearTimeout(se),t}(e)?(e.persist(),se=window.setTimeout((()=>{r(e)}),50)):r(e)}}))})),de=e.createContext(null),me=function(t){let{id:n,enabled:r=!0}=void 0===t?{}:t;const[o,u]=e.useState(null),c=g(),i=pe();return d((()=>{if(!r)return;const e=n?document.getElementById(n):null;if(!e){const e=document.createElement("div");""!==n&&(e.id=n||c),e.setAttribute("data-floating-ui-portal",""),u(e);const t=(null==i?void 0:i.portalNode)||document.body;return t.appendChild(e),()=>{t.removeChild(e)}}e.setAttribute("data-floating-ui-portal",""),u(e)}),[n,i,c,r]),o},ve=t=>{let{children:n,id:r,root:o=null,preserveTabOrder:u=!0}=t;const i=me({id:r,enabled:!o}),[l,s]=e.useState(null),a=e.useRef(null),f=e.useRef(null),d=e.useRef(null),m=e.useRef(null),v=!!l&&!l.modal&&!(!o&&!i)&&u;return e.useEffect((()=>{if(i&&u&&(null==l||!l.modal))return i.addEventListener("focusin",e,!0),i.addEventListener("focusout",e,!0),()=>{i.removeEventListener("focusin",e,!0),i.removeEventListener("focusout",e,!0)};function e(e){if(i&&ne(e)){("focusin"===e.type?oe:re)(i)}}}),[i,u,null==l?void 0:l.modal]),e.createElement(de.Provider,{value:e.useMemo((()=>({preserveTabOrder:u,beforeOutsideRef:a,afterOutsideRef:f,beforeInsideRef:d,afterInsideRef:m,portalNode:i,setFocusManagerState:s})),[u,i])},v&&i&&e.createElement(fe,{"data-type":"outside",ref:a,onFocus:e=>{if(ne(e,i)){var t;null==(t=d.current)||t.focus()}else{const e=te()||(null==l?void 0:l.refs.domReference.current);null==e||e.focus()}}}),v&&i&&e.createElement("span",{"aria-owns":i.id,style:ie}),o?c(n,o):i?c(n,i):null,v&&i&&e.createElement(fe,{"data-type":"outside",ref:f,onFocus:e=>{if(ne(e,i)){var t;null==(t=m.current)||t.focus()}else{const e=ee()||(null==l?void 0:l.refs.domReference.current);null==e||e.focus(),(null==l?void 0:l.closeOnFocusOut)&&(null==l||l.onOpenChange(!1))}}}))},pe=()=>e.useContext(de),ge=e.forwardRef((function(t,n){return e.createElement("button",W({},t,{type:"button",ref:n,tabIndex:-1,style:ie}))}));function be(t){let{context:n,children:r,order:c=["content"],guards:i=!0,initialFocus:l=0,returnFocus:s=!0,modal:a=!0,visuallyHiddenDismiss:f=!1,closeOnFocusOut:m=!0}=t;const{refs:v,nodeId:p,onOpenChange:g,events:b,dataRef:h,elements:{domReference:y,floating:w}}=n,R=K(c),x=E(),I=pe(),[T,C]=e.useState(null),M="number"==typeof l&&l<0,A=e.useRef(null),O=e.useRef(null),P=e.useRef(!1),S=e.useRef(null),D=e.useRef(!1),F=null!=I,H=y&&"combobox"===y.getAttribute("role")&&G(y),N=e.useCallback((function(e){return void 0===e&&(e=w),e?u(e,Q()):[]}),[w]),B=e.useCallback((e=>{const t=N(e);return R.current.map((e=>y&&"reference"===e?y:w&&"floating"===e?w:t)).filter(Boolean).flat()}),[y,w,R,N]);e.useEffect((()=>{if(!a)return;function e(e){if("Tab"===e.key){0!==N().length||H||J(e);const t=B(),n=Z(e);"reference"===R.current[0]&&n===y&&(J(e),e.shiftKey?X(t[t.length-1]):X(t[1])),"floating"===R.current[1]&&n===w&&e.shiftKey&&(J(e),X(t[0]))}}const t=k(w);return t.addEventListener("keydown",e),()=>{t.removeEventListener("keydown",e)}}),[y,w,a,R,v,H,N,B]),e.useEffect((()=>{if(m)return w&&L(y)?(y.addEventListener("focusout",t),y.addEventListener("pointerdown",e),!a&&w.addEventListener("focusout",t),()=>{y.removeEventListener("focusout",t),y.removeEventListener("pointerdown",e),!a&&w.removeEventListener("focusout",t)}):void 0;function e(){D.current=!0,setTimeout((()=>{D.current=!1}))}function t(e){const t=e.relatedTarget,n=!(z(y,t)||z(w,t)||z(t,w)||z(null==I?void 0:I.portalNode,t)||null!=t&&t.hasAttribute("data-floating-ui-focus-guard")||x&&(Y(x.nodesRef.current,p).find((e=>{var n,r;return z(null==(n=e.context)?void 0:n.elements.floating,t)||z(null==(r=e.context)?void 0:r.elements.domReference,t)}))||function(e,t){var n;let r=[],o=null==(n=e.find((e=>e.id===t)))?void 0:n.parentId;for(;o;){const t=e.find((e=>e.id===o));o=null==t?void 0:t.parentId,t&&(r=r.concat(t))}return r}(x.nodesRef.current,p).find((e=>{var n,r;return(null==(n=e.context)?void 0:n.elements.floating)===t||(null==(r=e.context)?void 0:r.elements.domReference)===t}))));t&&n&&!D.current&&t!==S.current&&(P.current=!0,setTimeout((()=>g(!1))))}}),[y,w,a,p,x,I,g,m]),e.useEffect((()=>{var e;const t=Array.from((null==I||null==(e=I.portalNode)?void 0:e.querySelectorAll("[data-floating-ui-portal]"))||[]);if(w&&a){const e=[w,...t,...[A.current,O.current].filter(Boolean)],n=o(R.current.includes("reference")||H?e.concat(y||[]):e);return()=>{n()}}}),[y,w,a,R,I,H]),e.useEffect((()=>{if(a&&!i&&w){const e=[],t=Q(),n=u(k(w).body,t),r=B(),o=n.filter((e=>!r.includes(e)));return o.forEach(((t,n)=>{e[n]=t.getAttribute("tabindex"),t.setAttribute("tabindex","-1")})),()=>{o.forEach(((t,n)=>{const r=e[n];null==r?t.removeAttribute("tabindex"):t.setAttribute("tabindex",r)}))}}}),[w,a,i,B]),d((()=>{if(!w)return;const e=k(w);let t=s,n=!1;const r=q(e),o=h.current;S.current=r;const u=B(w),c=("number"==typeof l?u[l]:l.current)||w;function i(e){if("escapeKey"===e.type&&v.domReference.current&&(S.current=v.domReference.current),["referencePress","escapeKey"].includes(e.type))return;const r=e.data.returnFocus;"object"==typeof r?(t=!0,n=r.preventScroll):t=r}return!M&&X(c,{preventScroll:c===w}),b.on("dismiss",i),()=>{var r;(b.off("dismiss",i),z(w,q(e))&&v.domReference.current&&(S.current=v.domReference.current),t&&L(S.current)&&!P.current)&&(!v.domReference.current||D.current?X(S.current,{cancelPrevious:!1,preventScroll:n}):(o.__syncReturnFocus=!0,null==(r=S.current)||r.focus({preventScroll:n}),setTimeout((()=>{delete o.__syncReturnFocus}))))}}),[w,B,l,s,h,v,b,M]),d((()=>{if(I)return I.setFocusManagerState({...n,modal:a,closeOnFocusOut:m}),()=>{I.setFocusManagerState(null)}}),[I,a,m,n]),d((()=>{if(!M&&w&&(e(),"function"==typeof MutationObserver)){const t=new MutationObserver(e);return t.observe(w,{childList:!0,subtree:!0}),()=>{t.disconnect()}}function e(){C(N().length)}}),[w,N,M,v]);const _=i&&(F||a)&&!H;function j(t){return f&&a?e.createElement(ge,{ref:"start"===t?A:O,onClick:()=>g(!1)},"string"==typeof f?f:"Dismiss"):null}return e.createElement(e.Fragment,null,_&&e.createElement(fe,{"data-type":"inside",ref:null==I?void 0:I.beforeInsideRef,onFocus:e=>{if(a){const e=B();X("reference"===c[0]?e[0]:e[e.length-1])}else if(null!=I&&I.preserveTabOrder&&I.portalNode)if(P.current=!1,ne(e,I.portalNode)){const e=ee()||y;null==e||e.focus()}else{var t;null==(t=I.beforeOutsideRef.current)||t.focus()}}}),H?null:j("start"),e.cloneElement(r,0===T||c.includes("floating")?{tabIndex:0}:{}),j("end"),_&&e.createElement(fe,{"data-type":"inside",ref:null==I?void 0:I.afterInsideRef,onFocus:e=>{if(a)X(B()[0]);else if(null!=I&&I.preserveTabOrder&&I.portalNode)if(P.current=!0,ne(e,I.portalNode)){const e=te()||y;null==e||e.focus()}else{var t;null==(t=I.afterOutsideRef.current)||t.focus()}}}))}const he="data-floating-ui-scroll-lock",ye=e.forwardRef((function(t,n){let{lockScroll:r=!1,...o}=t;return d((()=>{var e,t;if(!r)return;if(document.body.hasAttribute(he))return;document.body.setAttribute(he,"");const n=Math.round(document.documentElement.getBoundingClientRect().left)+document.documentElement.scrollLeft?"paddingLeft":"paddingRight",o=window.innerWidth-document.documentElement.clientWidth;if(!/iP(hone|ad|od)|iOS/.test(T()))return Object.assign(document.body.style,{overflow:"hidden",[n]:o+"px"}),()=>{document.body.removeAttribute(he),Object.assign(document.body.style,{overflow:"",[n]:""})};const u=(null==(e=window.visualViewport)?void 0:e.offsetLeft)||0,c=(null==(t=window.visualViewport)?void 0:t.offsetTop)||0,i=window.pageXOffset,l=window.pageYOffset;return Object.assign(document.body.style,{position:"fixed",overflow:"hidden",top:-(l-Math.floor(c))+"px",left:-(i-Math.floor(u))+"px",right:"0",[n]:o+"px"}),()=>{Object.assign(document.body.style,{position:"",overflow:"",top:"",left:"",right:"",[n]:""}),document.body.removeAttribute(he),window.scrollTo(i,l)}}),[r]),e.createElement("div",W({ref:n},o,{style:{position:"fixed",overflow:"auto",top:0,right:0,bottom:0,left:0,...o.style}}))}));function we(e){return L(e.target)&&"BUTTON"===e.target.tagName}function Ee(e){return G(e)}const Re=function(t,n){let{open:r,onOpenChange:o,dataRef:u,elements:{domReference:c}}=t,{enabled:i=!0,event:l="click",toggle:s=!0,ignoreMouse:a=!1,keyboardHandlers:f=!0}=void 0===n?{}:n;const d=e.useRef();return e.useMemo((()=>i?{reference:{onPointerDown(e){d.current=e.pointerType},onMouseDown(e){0===e.button&&(F(d.current,!0)&&a||"click"!==l&&(r?!s||u.current.openEvent&&"mousedown"!==u.current.openEvent.type||o(!1):(e.preventDefault(),o(!0)),u.current.openEvent=e.nativeEvent))},onClick(e){u.current.__syncReturnFocus||("mousedown"===l&&d.current?d.current=void 0:F(d.current,!0)&&a||(r?!s||u.current.openEvent&&"click"!==u.current.openEvent.type||o(!1):o(!0),u.current.openEvent=e.nativeEvent))},onKeyDown(e){d.current=void 0,f&&(we(e)||(" "!==e.key||Ee(c)||e.preventDefault(),"Enter"===e.key&&(r?s&&o(!1):o(!0))))},onKeyUp(e){f&&(we(e)||Ee(c)||" "===e.key&&(r?s&&o(!1):o(!0)))}}}:{}),[i,u,l,a,f,c,s,r,o])};function xe(e,t){if(null==t)return!1;if("composedPath"in e)return e.composedPath().includes(t);const n=e;return null!=n.target&&t.contains(n.target)}const Ie={pointerdown:"onPointerDown",mousedown:"onMouseDown",click:"onClick"},ke={pointerdown:"onPointerDownCapture",mousedown:"onMouseDownCapture",click:"onClickCapture"},Te=function(t,n){let{open:r,onOpenChange:o,events:u,nodeId:c,elements:{reference:i,domReference:s,floating:a},dataRef:f}=t,{enabled:d=!0,escapeKey:m=!0,outsidePress:v=!0,outsidePressEvent:p="pointerdown",referencePress:g=!1,referencePressEvent:b="pointerdown",ancestorScroll:h=!1,bubbles:y=!0}=void 0===n?{}:n;const R=E(),x=null!=w(),I=ce("function"==typeof v?v:()=>!1),T="function"==typeof v?I:v,C=e.useRef(!1),{escapeKeyBubbles:M,outsidePressBubbles:S}=function(e){var t,n;return void 0===e&&(e=!0),{escapeKeyBubbles:"boolean"==typeof e?e:null==(t=e.escapeKey)||t,outsidePressBubbles:"boolean"==typeof e?e:null==(n=e.outsidePress)||n}}(y);return e.useEffect((()=>{if(!r||!d)return;function e(e){if("Escape"===e.key){const e=R?Y(R.nodesRef.current,c):[];if(e.length>0){let t=!0;if(e.forEach((e=>{var n;null==(n=e.context)||!n.open||e.context.dataRef.current.__escapeKeyBubbles||(t=!1)})),!t)return}u.emit("dismiss",{type:"escapeKey",data:{returnFocus:{preventScroll:!1}}}),o(!1)}}function t(e){const t=C.current;if(C.current=!1,t)return;if("function"==typeof T&&!T(e))return;const n=Z(e);if(L(n)&&a){const t=a.ownerDocument.defaultView||window,r=n.scrollWidth>n.clientWidth,o=n.scrollHeight>n.clientHeight;let u=o&&e.offsetX>n.clientWidth;if(o){"rtl"===t.getComputedStyle(n).direction&&(u=e.offsetX<=n.offsetWidth-n.clientWidth)}if(u||r&&e.offsetY>n.clientHeight)return}const r=R&&Y(R.nodesRef.current,c).some((t=>{var n;return xe(e,null==(n=t.context)?void 0:n.elements.floating)}));if(xe(e,a)||xe(e,s)||r)return;const i=R?Y(R.nodesRef.current,c):[];if(i.length>0){let e=!0;if(i.forEach((t=>{var n;null==(n=t.context)||!n.open||t.context.dataRef.current.__outsidePressBubbles||(e=!1)})),!e)return}u.emit("dismiss",{type:"outsidePress",data:{returnFocus:x?{preventScroll:!0}:O(e)||P(e)}}),o(!1)}function n(){o(!1)}f.current.__escapeKeyBubbles=M,f.current.__outsidePressBubbles=S;const v=k(a);m&&v.addEventListener("keydown",e),T&&v.addEventListener(p,t);let g=[];return h&&(A(s)&&(g=l(s)),A(a)&&(g=g.concat(l(a))),!A(i)&&i&&i.contextElement&&(g=g.concat(l(i.contextElement)))),g=g.filter((e=>{var t;return e!==(null==(t=v.defaultView)?void 0:t.visualViewport)})),g.forEach((e=>{e.addEventListener("scroll",n,{passive:!0})})),()=>{m&&v.removeEventListener("keydown",e),T&&v.removeEventListener(p,t),g.forEach((e=>{e.removeEventListener("scroll",n)}))}}),[f,a,s,i,m,T,p,u,R,c,r,o,h,d,M,S,x]),e.useEffect((()=>{C.current=!1}),[T,p]),e.useMemo((()=>d?{reference:{[Ie[b]]:()=>{g&&(u.emit("dismiss",{type:"referencePress",data:{returnFocus:!1}}),o(!1))}},floating:{[ke[p]]:()=>{C.current=!0}}}:{}),[d,u,g,p,b,o])},Ce=function(t,n){let{open:r,onOpenChange:o,dataRef:u,events:c,refs:i,elements:{floating:l,domReference:s}}=t,{enabled:a=!0,keyboardOnly:f=!0}=void 0===n?{}:n;const d=e.useRef(""),m=e.useRef(!1),v=e.useRef();return e.useEffect((()=>{if(!a)return;const e=k(l).defaultView||window;function t(){!r&&L(s)&&s===q(k(s))&&(m.current=!0)}return e.addEventListener("blur",t),()=>{e.removeEventListener("blur",t)}}),[l,s,r,a]),e.useEffect((()=>{if(a)return c.on("dismiss",e),()=>{c.off("dismiss",e)};function e(e){"referencePress"!==e.type&&"escapeKey"!==e.type||(m.current=!0)}}),[c,a]),e.useEffect((()=>()=>{clearTimeout(v.current)}),[]),e.useMemo((()=>a?{reference:{onPointerDown(e){let{pointerType:t}=e;d.current=t,m.current=!(!t||!f)},onMouseLeave(){m.current=!1},onFocus(e){var t;m.current||"focus"===e.type&&"mousedown"===(null==(t=u.current.openEvent)?void 0:t.type)&&u.current.openEvent&&xe(u.current.openEvent,s)||(u.current.openEvent=e.nativeEvent,o(!0))},onBlur(e){m.current=!1;const t=e.relatedTarget,n=A(t)&&t.hasAttribute("data-floating-ui-focus-guard")&&"outside"===t.getAttribute("data-type");v.current=setTimeout((()=>{z(i.floating.current,t)||z(s,t)||n||o(!1)}))}}}:{}),[a,f,s,i,u,o])};let Me=!1;function Ae(e,t,n){return Math.floor(e/t)!==n}function Le(e,t){return t<0||t>=e.current.length}function Oe(e,t){let{startingIndex:n=-1,decrement:r=!1,disabledIndices:o,amount:u=1}=void 0===t?{}:t;const c=e.current;let i=n;do{var l,s;i+=r?-u:u}while(i>=0&&i<=c.length-1&&(o?o.includes(i):null==c[i]||(null==(l=c[i])?void 0:l.hasAttribute("disabled"))||"true"===(null==(s=c[i])?void 0:s.getAttribute("aria-disabled"))));return i}function Pe(e,t,n){switch(e){case"vertical":return t;case"horizontal":return n;default:return t||n}}function Se(e,t){return Pe(t,"ArrowUp"===e||"ArrowDown"===e,"ArrowLeft"===e||"ArrowRight"===e)}function De(e,t,n){return Pe(t,"ArrowDown"===e,n?"ArrowLeft"===e:"ArrowRight"===e)||"Enter"===e||" "==e||""===e}function Fe(e,t){return Oe(e,{disabledIndices:t})}function Ke(e,t){return Oe(e,{decrement:!0,startingIndex:e.current.length,disabledIndices:t})}const He=function(t,n){let{open:r,onOpenChange:o,refs:u,elements:{domReference:c}}=t,{listRef:l,activeIndex:s,onNavigate:a=(()=>{}),enabled:f=!0,selectedIndex:m=null,allowEscape:v=!1,loop:p=!1,nested:g=!1,rtl:b=!1,virtual:h=!1,focusItemOnOpen:y="auto",focusItemOnHover:R=!0,openOnArrowKeyDown:x=!0,disabledIndices:I,orientation:T="vertical",cols:C=1,scrollItemIntoView:M=!0}=void 0===n?{listRef:{current:[]},activeIndex:null,onNavigate:()=>{}}:n;const A=w(),F=E(),H=ce(a),N=e.useRef(y),B=e.useRef(null!=m?m:-1),_=e.useRef(null),j=e.useRef(!0),V=e.useRef(H),W=e.useRef(r),U=e.useRef(!1),Y=e.useRef(!1),Z=K(I),G=K(r),Q=K(M),[$,ee]=e.useState(),te=e.useCallback((function(e,t,n){void 0===n&&(n=!1);const r=e.current[t.current];h?ee(null==r?void 0:r.id):X(r,{preventScroll:!0,sync:!(!D()||!S())&&(Me||U.current)}),requestAnimationFrame((()=>{const e=Q.current;e&&r&&(n||!j.current)&&(null==r.scrollIntoView||r.scrollIntoView("boolean"==typeof e?{block:"nearest",inline:"nearest"}:e))}))}),[h,Q]);d((()=>{document.createElement("div").focus({get preventScroll(){return Me=!0,!1}})}),[]),d((()=>{f&&(r?N.current&&null!=m&&(Y.current=!0,H(m)):W.current&&(B.current=-1,V.current(null)))}),[f,r,m,H]),d((()=>{if(f&&r)if(null==s){if(U.current=!1,null!=m)return;W.current&&(B.current=-1,te(l,B)),!W.current&&N.current&&(null!=_.current||!0===N.current&&null==_.current)&&(B.current=null==_.current||De(_.current,T,b)||g?Fe(l,Z.current):Ke(l,Z.current),H(B.current))}else Le(l,s)||(B.current=s,te(l,B,Y.current),Y.current=!1)}),[f,r,s,m,g,l,T,b,H,te,Z]),d((()=>{if(f&&W.current&&!r){var e,t;const n=null==F||null==(e=F.nodesRef.current.find((e=>e.id===A)))||null==(t=e.context)?void 0:t.elements.floating;n&&!z(n,q(k(n)))&&n.focus({preventScroll:!0})}}),[f,r,F,A]),d((()=>{_.current=null,V.current=H,W.current=r}));const ne=null!=s,re=e.useMemo((()=>{function e(e){if(!r)return;const t=l.current.indexOf(e);-1!==t&&H(t)}return{onFocus(t){let{currentTarget:n}=t;e(n)},onClick:e=>{let{currentTarget:t}=e;return t.focus({preventScroll:!0})},...R&&{onMouseMove(t){let{currentTarget:n}=t;e(n)},onPointerLeave(){var e;j.current&&(B.current=-1,te(l,B),i((()=>H(null))),h||null==(e=u.floating.current)||e.focus({preventScroll:!0}))}}}}),[r,u,te,R,l,H,h]);return e.useMemo((()=>{if(!f)return{};const e=Z.current;function t(t){if(j.current=!1,U.current=!0,!G.current&&t.currentTarget===u.floating.current)return;if(g&&function(e,t,n){return Pe(t,n?"ArrowRight"===e:"ArrowLeft"===e,"ArrowUp"===e)}(t.key,T,b))return J(t),o(!1),void(L(c)&&c.focus());const n=B.current,i=Fe(l,e),s=Ke(l,e);if("Home"===t.key&&(B.current=i,H(B.current)),"End"===t.key&&(B.current=s,H(B.current)),C>1){const n=B.current;if("ArrowUp"===t.key){if(J(t),-1===n)B.current=s;else if(B.current=Oe(l,{startingIndex:n,amount:C,decrement:!0,disabledIndices:e}),p&&(n-Ce?r:r-C}Le(l,B.current)&&(B.current=n),H(B.current)}if("ArrowDown"===t.key&&(J(t),-1===n?B.current=i:(B.current=Oe(l,{startingIndex:n,amount:C,disabledIndices:e}),p&&n+C>s&&(B.current=Oe(l,{startingIndex:n%C-C,amount:C,disabledIndices:e}))),Le(l,B.current)&&(B.current=n),H(B.current)),"both"===T){const r=Math.floor(n/C);"ArrowRight"===t.key&&(J(t),n%C!=C-1?(B.current=Oe(l,{startingIndex:n,disabledIndices:e}),p&&Ae(B.current,C,r)&&(B.current=Oe(l,{startingIndex:n-n%C-1,disabledIndices:e}))):p&&(B.current=Oe(l,{startingIndex:n-n%C-1,disabledIndices:e})),Ae(B.current,C,r)&&(B.current=n)),"ArrowLeft"===t.key&&(J(t),n%C!=0?(B.current=Oe(l,{startingIndex:n,disabledIndices:e,decrement:!0}),p&&Ae(B.current,C,r)&&(B.current=Oe(l,{startingIndex:n+(C-n%C),decrement:!0,disabledIndices:e}))):p&&(B.current=Oe(l,{startingIndex:n+(C-n%C),decrement:!0,disabledIndices:e})),Ae(B.current,C,r)&&(B.current=n));const o=Math.floor(s/C)===r;return Le(l,B.current)&&(B.current=p&&o?"ArrowLeft"===t.key?s:Oe(l,{startingIndex:n-n%C-1,disabledIndices:e}):n),void H(B.current)}}if(Se(t.key,T)){if(J(t),r&&!h&&q(t.currentTarget.ownerDocument)===t.currentTarget)return B.current=De(t.key,T,b)?i:s,void H(B.current);De(t.key,T,b)?B.current=p?n>=s?v&&n!==l.current.length?-1:i:Oe(l,{startingIndex:n,disabledIndices:e}):Math.min(s,Oe(l,{startingIndex:n,disabledIndices:e})):B.current=p?n<=i?v&&-1!==n?l.current.length:s:Oe(l,{startingIndex:n,decrement:!0,disabledIndices:e}):Math.max(i,Oe(l,{startingIndex:n,decrement:!0,disabledIndices:e})),Le(l,B.current)?H(null):H(B.current)}}function n(e){"auto"===y&&O(e.nativeEvent)&&(N.current=!0)}const i=h&&r&&ne&&{"aria-activedescendant":$};return{reference:{...i,onKeyDown(n){j.current=!1;const u=0===n.key.indexOf("Arrow");if(h&&r)return t(n);if(!r&&!x&&u)return;(u||"Enter"===n.key||" "===n.key||""===n.key)&&(_.current=n.key),g?function(e,t,n){return Pe(t,n?"ArrowLeft"===e:"ArrowRight"===e,"ArrowDown"===e)}(n.key,T,b)&&(J(n),r?(B.current=Fe(l,e),H(B.current)):o(!0)):Se(n.key,T)&&(null!=m&&(B.current=m),J(n),!r&&x?o(!0):t(n),r&&H(B.current))},onFocus(){r&&H(null)},onPointerDown:function(e){N.current=y,"auto"===y&&P(e.nativeEvent)&&(N.current=!0)},onMouseDown:n,onClick:n},floating:{"aria-orientation":"both"===T?void 0:T,...i,onKeyDown:t,onPointerMove(){j.current=!0}},item:re}}),[c,u,$,Z,G,l,f,T,b,h,r,ne,g,m,x,v,C,p,y,H,o,re])};function Ne(t){return e.useMemo((()=>t.every((e=>null==e))?null:e=>{t.forEach((t=>{"function"==typeof t?t(e):null!=t&&(t.current=e)}))}),t)}const Be=function(t,n){let{open:r}=t,{enabled:o=!0,role:u="dialog"}=void 0===n?{}:n;const c=g(),i=g();return e.useMemo((()=>{const e={id:c,role:u};return o?"tooltip"===u?{reference:{"aria-describedby":r?c:void 0},floating:e}:{reference:{"aria-expanded":r?"true":"false","aria-haspopup":"alertdialog"===u?"dialog":u,"aria-controls":r?c:void 0,..."listbox"===u&&{role:"combobox"},..."menu"===u&&{id:i}},floating:{...e,..."menu"===u&&{"aria-labelledby":i}}}:{}}),[o,u,r,c,i])},_e=e=>e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,((e,t)=>(t?"-":"")+e.toLowerCase()));function je(t,n){let{open:r,elements:{floating:o}}=t,{duration:u=250}=void 0===n?{}:n;const c=("number"==typeof u?u:u.close)||0,[i,l]=e.useState(!1),[s,a]=e.useState("unmounted"),f=function(t,n){const[r,o]=e.useState(t);return t&&!r&&o(!0),e.useEffect((()=>{if(!t){const e=setTimeout((()=>o(!1)),n);return()=>clearTimeout(e)}}),[t,n]),r}(r,c);return d((()=>{i&&!f&&a("unmounted")}),[i,f]),d((()=>{if(o){if(r){a("initial");const e=requestAnimationFrame((()=>{a("open")}));return()=>{cancelAnimationFrame(e)}}l(!0),a("close")}}),[r,o]),{isMounted:f,status:s}}function Ve(t,n){let{initial:r={opacity:0},open:o,close:u,common:c,duration:i=250}=void 0===n?{}:n;const l=t.placement,s=l.split("-")[0],[a,f]=e.useState({}),{isMounted:m,status:v}=je(t,{duration:i}),p=K(r),g=K(o),b=K(u),h=K(c),y="number"==typeof i,w=(y?i:i.open)||0,E=(y?i:i.close)||0;return d((()=>{const e={side:s,placement:l},t=p.current,n=b.current,r=g.current,o=h.current,u="function"==typeof t?t(e):t,c="function"==typeof n?n(e):n,i="function"==typeof o?o(e):o,a=("function"==typeof r?r(e):r)||Object.keys(u).reduce(((e,t)=>(e[t]="",e)),{});if("initial"===v&&f((e=>({transitionProperty:e.transitionProperty,...i,...u}))),"open"===v&&f({transitionProperty:Object.keys(a).map(_e).join(","),transitionDuration:w+"ms",...i,...a}),"close"===v){const e=c||u;f({transitionProperty:Object.keys(e).map(_e).join(","),transitionDuration:E+"ms",...i,...e})}}),[s,l,E,b,p,g,h,w,v]),{isMounted:m,styles:a}}const We=function(t,n){var r;let{open:o,dataRef:u}=t,{listRef:c,activeIndex:i,onMatch:l=(()=>{}),enabled:s=!0,findMatch:a=null,resetMs:f=1e3,ignoreKeys:m=[],selectedIndex:v=null}=void 0===n?{listRef:{current:[]},activeIndex:null}:n;const p=e.useRef(),g=e.useRef(""),b=e.useRef(null!=(r=null!=v?v:i)?r:-1),h=e.useRef(null),y=ce(l),w=K(a),E=K(m);return d((()=>{o&&(clearTimeout(p.current),h.current=null,g.current="")}),[o]),d((()=>{var e;o&&""===g.current&&(b.current=null!=(e=null!=v?v:i)?e:-1)}),[o,v,i]),e.useMemo((()=>{if(!s)return{};function e(e){const t=Z(e.nativeEvent);if(A(t)&&q(k(t))!==e.currentTarget&&t.closest('[role="dialog"],[role="menu"],[role="listbox"],[role="tree"],[role="grid"]')!==e.currentTarget)return;g.current.length>0&&" "!==g.current[0]&&(u.current.typing=!0," "===e.key&&J(e));const n=c.current;if(null==n||E.current.includes(e.key)||1!==e.key.length||e.ctrlKey||e.metaKey||e.altKey)return;n.every((e=>{var t,n;return!e||(null==(t=e[0])?void 0:t.toLocaleLowerCase())!==(null==(n=e[1])?void 0:n.toLocaleLowerCase())}))&&g.current===e.key&&(g.current="",b.current=h.current),g.current+=e.key,clearTimeout(p.current),p.current=setTimeout((()=>{g.current="",b.current=h.current,u.current.typing=!1}),f);const r=b.current,o=[...n.slice((r||0)+1),...n.slice(0,(r||0)+1)],i=w.current?w.current(o,g.current):o.find((e=>0===(null==e?void 0:e.toLocaleLowerCase().indexOf(g.current.toLocaleLowerCase())))),l=i?n.indexOf(i):-1;-1!==l&&(y(l),h.current=l)}return{reference:{onKeyDown:e},floating:{onKeyDown:e}}}),[s,u,c,f,E,w,y])};function qe(e,t){return{...e,rects:{...e.rects,floating:{...e.rects.floating,height:t}}}}const ze=e=>({name:"inner",options:e,async fn(t){const{listRef:n,overflowRef:r,onFallbackChange:o,offset:u=0,index:c=0,minItemsVisible:l=4,referenceOverflowThreshold:f=0,scrollRef:d,...m}=e,{rects:v,elements:{floating:p}}=t,g=n.current[c];if(!g)return{};const b={...t,...await s(-g.offsetTop-v.reference.height/2-g.offsetHeight/2-u).fn(t)},h=(null==d?void 0:d.current)||p,y=await a(qe(b,h.scrollHeight),m),w=await a(b,{...m,elementContext:"reference"}),E=Math.max(0,y.top),R=b.y+E,x=Math.max(0,h.scrollHeight-E-Math.max(0,y.bottom));return h.style.maxHeight=x+"px",h.scrollTop=E,o&&(h.offsetHeight=-f||w.bottom>=-f?i((()=>o(!0))):i((()=>o(!1)))),r&&(r.current=await a(qe({...b,y:R},h.offsetHeight),m)),{y:R}}}),Ue=(t,n)=>{let{open:r,elements:o}=t,{enabled:u=!0,overflowRef:c,scrollRef:l,onChange:s}=n;const a=ce(s),f=e.useRef(!1),d=e.useRef(null),m=e.useRef(null);return e.useEffect((()=>{if(!u)return;function e(e){if(e.ctrlKey||!t||null==c.current)return;const n=e.deltaY,r=c.current.top>=-.5,o=c.current.bottom>=-.5,u=t.scrollHeight-t.clientHeight,l=n<0?-1:1,s=n<0?"max":"min";t.scrollHeight<=t.clientHeight||(!r&&n>0||!o&&n<0?(e.preventDefault(),i((()=>{a((e=>e+Math[s](n,u*l)))}))):/firefox/i.test(C())&&(t.scrollTop+=n))}const t=(null==l?void 0:l.current)||o.floating;return r&&t?(t.addEventListener("wheel",e),requestAnimationFrame((()=>{d.current=t.scrollTop,null!=c.current&&(m.current={...c.current})})),()=>{d.current=null,m.current=null,t.removeEventListener("wheel",e)}):void 0}),[u,r,o.floating,c,l,a]),e.useMemo((()=>u?{floating:{onKeyDown(){f.current=!0},onWheel(){f.current=!1},onPointerMove(){f.current=!1},onScroll(){const e=(null==l?void 0:l.current)||o.floating;if(c.current&&e&&f.current){if(null!==d.current){const t=e.scrollTop-d.current;(c.current.bottom<-.5&&t<-1||c.current.top<-.5&&t>1)&&i((()=>a((e=>e+t))))}requestAnimationFrame((()=>{d.current=e.scrollTop}))}}}}:{}),[u,c,o.floating,l,a])};function Xe(e){let t,{restMs:n=0,buffer:r=.5,blockPointerEvents:o=!1}=void 0===e?{}:e,u=!1,c=!1;const i=e=>{let{x:o,y:i,placement:l,elements:s,onClose:a,nodeId:f,tree:d}=e;return function(e){function m(){clearTimeout(t),a()}if(clearTimeout(t),!s.domReference||!s.floating||null==l||null==o||null==i)return;const{clientX:v,clientY:p}=e,g=[v,p],b=Z(e),h="mouseleave"===e.type,y=z(s.floating,b),w=z(s.domReference,b),E=s.domReference.getBoundingClientRect(),R=s.floating.getBoundingClientRect(),x=l.split("-")[0],I=o>R.right-R.width/2,k=i>R.bottom-R.height/2,T=function(e,t){return e[0]>=t.x&&e[0]<=t.x+t.width&&e[1]>=t.y&&e[1]<=t.y+t.height}(g,E);if(y&&(c=!0),w&&(c=!1),w&&!h)return void(c=!0);if(h&&A(e.relatedTarget)&&z(s.floating,e.relatedTarget))return;if(d&&Y(d.nodesRef.current,f).some((e=>{let{context:t}=e;return null==t?void 0:t.open})))return;if("top"===x&&i>=E.bottom-1||"bottom"===x&&i<=E.top+1||"left"===x&&o>=E.right-1||"right"===x&&o<=E.left+1)return m();let C=[];switch(x){case"top":C=[[R.left,E.top+1],[R.left,R.bottom-1],[R.right,R.bottom-1],[R.right,E.top+1]],u=v>=R.left&&v<=R.right&&p>=R.top&&p<=E.top+1;break;case"bottom":C=[[R.left,R.top+1],[R.left,E.bottom-1],[R.right,E.bottom-1],[R.right,R.top+1]],u=v>=R.left&&v<=R.right&&p>=E.bottom-1&&p<=R.bottom;break;case"left":C=[[R.right-1,R.bottom],[R.right-1,R.top],[E.left+1,R.top],[E.left+1,R.bottom]],u=v>=R.left&&v<=E.left+1&&p>=R.top&&p<=R.bottom;break;case"right":C=[[E.right-1,R.bottom],[E.right-1,R.top],[R.left+1,R.top],[R.left+1,R.bottom]],u=v>=E.right-1&&v<=R.right&&p>=R.top&&p<=R.bottom}const M=u?C:function(e){let[t,n]=e;const o=R.width>E.width,u=R.height>E.height;switch(x){case"top":return[[o?t+r/2:I?t+4*r:t-4*r,n+r+1],[o?t-r/2:I?t+4*r:t-4*r,n+r+1],...[[R.left,I||o?R.bottom-r:R.top],[R.right,I?o?R.bottom-r:R.top:R.bottom-r]]];case"bottom":return[[o?t+r/2:I?t+4*r:t-4*r,n-r],[o?t-r/2:I?t+4*r:t-4*r,n-r],...[[R.left,I||o?R.top+r:R.bottom],[R.right,I?o?R.top+r:R.bottom:R.top+r]]];case"left":{const e=[t+r+1,u?n+r/2:k?n+4*r:n-4*r],o=[t+r+1,u?n-r/2:k?n+4*r:n-4*r];return[...[[k||u?R.right-r:R.left,R.top],[k?u?R.right-r:R.left:R.right-r,R.bottom]],e,o]}case"right":return[[t-r,u?n+r/2:k?n+4*r:n-4*r],[t-r,u?n-r/2:k?n+4*r:n-4*r],...[[k||u?R.left+r:R.right,R.top],[k?u?R.left+r:R.right:R.left+r,R.bottom]]]}}([o,i]);return u?void 0:c&&!T?m():void(!function(e,t){const[n,r]=e;let o=!1;const u=t.length;for(let e=0,c=u-1;e=r!=s>=r&&n<=(l-u)*(r-i)/(s-i)+u&&(o=!o)}return o}([v,p],M)?m():n&&!c&&(t=setTimeout(m,n)))}};return i.__options={blockPointerEvents:o},i}function Ye(t){void 0===t&&(t={});const{open:n=!1,onOpenChange:r,nodeId:o}=t,u=f(t),c=E(),i=e.useRef(null),l=e.useRef({}),s=e.useState((()=>b()))[0],[a,m]=e.useState(null),v=e.useCallback((e=>{const t=A(e)?{getBoundingClientRect:()=>e.getBoundingClientRect(),contextElement:e}:e;u.refs.setReference(t)}),[u.refs]),p=e.useCallback((e=>{(A(e)||null===e)&&(i.current=e,m(e)),(A(u.refs.reference.current)||null===u.refs.reference.current||null!==e&&!A(e))&&u.refs.setReference(e)}),[u.refs]),g=e.useMemo((()=>({...u.refs,setReference:p,setPositionReference:v,domReference:i})),[u.refs,p,v]),h=e.useMemo((()=>({...u.elements,domReference:a})),[u.elements,a]),y=ce(r),w=e.useMemo((()=>({...u,refs:g,elements:h,dataRef:l,nodeId:o,events:s,open:n,onOpenChange:y})),[u,o,s,n,y,g,h]);return d((()=>{const e=null==c?void 0:c.nodesRef.current.find((e=>e.id===o));e&&(e.context=w)})),e.useMemo((()=>({...u,context:w,refs:g,reference:p,positionReference:v})),[u,g,w,p,v])}function Ze(e,t,n){const r=new Map;return{..."floating"===n&&{tabIndex:-1},...e,...t.map((e=>e?e[n]:null)).concat(e).reduce(((e,t)=>t?(Object.entries(t).forEach((t=>{let[n,o]=t;var u;0===n.indexOf("on")?(r.has(n)||r.set(n,[]),"function"==typeof o&&(null==(u=r.get(n))||u.push(o),e[n]=function(){for(var e,t=arguments.length,o=new Array(t),u=0;ue(...o)))})):e[n]=o})),e):e),{})}}const Ge=function(t){void 0===t&&(t=[]);const n=t,r=e.useCallback((e=>Ze(e,t,"reference")),n),o=e.useCallback((e=>Ze(e,t,"floating")),n),u=e.useCallback((e=>Ze(e,t,"item")),t.map((e=>null==e?void 0:e.item)));return e.useMemo((()=>({getReferenceProps:r,getFloatingProps:o,getItemProps:u})),[r,o,u])};export{j as FloatingDelayGroup,be as FloatingFocusManager,x as FloatingNode,ye as FloatingOverlay,ve as FloatingPortal,I as FloatingTree,ze as inner,Xe as safePolygon,Re as useClick,V as useDelayGroup,_ as useDelayGroupContext,Te as useDismiss,Ye as useFloating,R as useFloatingNodeId,w as useFloatingParentNodeId,me as useFloatingPortalNode,E as useFloatingTree,Ce as useFocus,N as useHover,g as useId,Ue as useInnerOffset,Ge as useInteractions,He as useListNavigation,Ne as useMergeRefs,Be as useRole,je as useTransitionStatus,Ve as useTransitionStyles,We as useTypeahead};
diff --git a/node_modules/@floating-ui/react/dist/floating-ui.react.mjs b/node_modules/@floating-ui/react/dist/floating-ui.react.mjs
new file mode 100644
index 0000000..ee08421
--- /dev/null
+++ b/node_modules/@floating-ui/react/dist/floating-ui.react.mjs
@@ -0,0 +1,3348 @@
+import * as React from 'react';
+import { useLayoutEffect, useEffect, useRef } from 'react';
+import { hideOthers } from 'aria-hidden';
+import { tabbable } from 'tabbable';
+import { createPortal, flushSync } from 'react-dom';
+import { getOverflowAncestors, offset, detectOverflow, useFloating as useFloating$1 } from '@floating-ui/react-dom';
+export { arrow } from '@floating-ui/react-dom';
+export { autoPlacement, autoUpdate, computePosition, detectOverflow, flip, getOverflowAncestors, hide, inline, limitShift, offset, platform, shift, size } from '@floating-ui/dom';
+
+var index = typeof document !== 'undefined' ? useLayoutEffect : useEffect;
+
+let serverHandoffComplete = false;
+let count = 0;
+const genId = () => "floating-ui-" + count++;
+function useFloatingId() {
+ const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
+ index(() => {
+ if (id == null) {
+ setId(genId());
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+ React.useEffect(() => {
+ if (!serverHandoffComplete) {
+ serverHandoffComplete = true;
+ }
+ }, []);
+ return id;
+}
+
+// `toString()` prevents bundlers from trying to `import { useId } from 'react'`
+const useReactId = React[/*#__PURE__*/'useId'.toString()];
+
+/**
+ * Uses React 18's built-in `useId()` when available, or falls back to a
+ * slightly less performant (requiring a double render) implementation for
+ * earlier React versions.
+ * @see https://floating-ui.com/docs/useId
+ */
+const useId = useReactId || useFloatingId;
+
+function createPubSub() {
+ const map = new Map();
+ return {
+ emit(event, data) {
+ var _map$get;
+ (_map$get = map.get(event)) == null ? void 0 : _map$get.forEach(handler => handler(data));
+ },
+ on(event, listener) {
+ map.set(event, [...(map.get(event) || []), listener]);
+ },
+ off(event, listener) {
+ map.set(event, (map.get(event) || []).filter(l => l !== listener));
+ }
+ };
+}
+
+const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
+const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
+const useFloatingParentNodeId = () => {
+ var _React$useContext;
+ return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
+};
+const useFloatingTree = () => React.useContext(FloatingTreeContext);
+
+/**
+ * Registers a node into the floating tree, returning its id.
+ */
+const useFloatingNodeId = customParentId => {
+ const id = useId();
+ const tree = useFloatingTree();
+ const reactParentId = useFloatingParentNodeId();
+ const parentId = customParentId || reactParentId;
+ index(() => {
+ const node = {
+ id,
+ parentId
+ };
+ tree == null ? void 0 : tree.addNode(node);
+ return () => {
+ tree == null ? void 0 : tree.removeNode(node);
+ };
+ }, [tree, id, parentId]);
+ return id;
+};
+
+/**
+ * Provides parent node context for nested floating elements.
+ * @see https://floating-ui.com/docs/FloatingTree
+ */
+const FloatingNode = _ref => {
+ let {
+ children,
+ id
+ } = _ref;
+ const parentId = useFloatingParentNodeId();
+ return /*#__PURE__*/React.createElement(FloatingNodeContext.Provider, {
+ value: React.useMemo(() => ({
+ id,
+ parentId
+ }), [id, parentId])
+ }, children);
+};
+
+/**
+ * Provides context for nested floating elements when they are not children of
+ * each other on the DOM (i.e. portalled to a common node, rather than their
+ * respective parent).
+ * @see https://floating-ui.com/docs/FloatingTree
+ */
+const FloatingTree = _ref2 => {
+ let {
+ children
+ } = _ref2;
+ const nodesRef = React.useRef([]);
+ const addNode = React.useCallback(node => {
+ nodesRef.current = [...nodesRef.current, node];
+ }, []);
+ const removeNode = React.useCallback(node => {
+ nodesRef.current = nodesRef.current.filter(n => n !== node);
+ }, []);
+ const events = React.useState(() => createPubSub())[0];
+ return /*#__PURE__*/React.createElement(FloatingTreeContext.Provider, {
+ value: React.useMemo(() => ({
+ nodesRef,
+ addNode,
+ removeNode,
+ events
+ }), [nodesRef, addNode, removeNode, events])
+ }, children);
+};
+
+function getDocument(node) {
+ return (node == null ? void 0 : node.ownerDocument) || document;
+}
+
+// Avoid Chrome DevTools blue warning.
+function getPlatform() {
+ const uaData = navigator.userAgentData;
+ if (uaData != null && uaData.platform) {
+ return uaData.platform;
+ }
+ return navigator.platform;
+}
+function getUserAgent() {
+ const uaData = navigator.userAgentData;
+ if (uaData && Array.isArray(uaData.brands)) {
+ return uaData.brands.map(_ref => {
+ let {
+ brand,
+ version
+ } = _ref;
+ return brand + "/" + version;
+ }).join(' ');
+ }
+ return navigator.userAgent;
+}
+
+function getWindow(value) {
+ return getDocument(value).defaultView || window;
+}
+function isElement(value) {
+ return value ? value instanceof getWindow(value).Element : false;
+}
+function isHTMLElement(value) {
+ return value ? value instanceof getWindow(value).HTMLElement : false;
+}
+function isShadowRoot(node) {
+ // Browsers without `ShadowRoot` support
+ if (typeof ShadowRoot === 'undefined') {
+ return false;
+ }
+ const OwnElement = getWindow(node).ShadowRoot;
+ return node instanceof OwnElement || node instanceof ShadowRoot;
+}
+
+// License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts
+function isVirtualClick(event) {
+ if (event.mozInputSource === 0 && event.isTrusted) {
+ return true;
+ }
+ const androidRe = /Android/i;
+ if ((androidRe.test(getPlatform()) || androidRe.test(getUserAgent())) && event.pointerType) {
+ return event.type === 'click' && event.buttons === 1;
+ }
+ return event.detail === 0 && !event.pointerType;
+}
+function isVirtualPointerEvent(event) {
+ return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType !== 'mouse' ||
+ // iOS VoiceOver returns 0.333• for width/height.
+ event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0;
+}
+function isSafari() {
+ // Chrome DevTools does not complain about navigator.vendor
+ return /apple/i.test(navigator.vendor);
+}
+function isMac() {
+ return getPlatform().toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
+}
+function isMouseLikePointerType(pointerType, strict) {
+ // On some Linux machines with Chromium, mouse inputs return a `pointerType`
+ // of "pen": https://github.com/floating-ui/floating-ui/issues/2015
+ const values = ['mouse', 'pen'];
+ if (!strict) {
+ values.push('', undefined);
+ }
+ return values.includes(pointerType);
+}
+
+function useLatestRef(value) {
+ const ref = useRef(value);
+ index(() => {
+ ref.current = value;
+ });
+ return ref;
+}
+
+const safePolygonIdentifier = 'data-floating-ui-safe-polygon';
+function getDelay(value, prop, pointerType) {
+ if (pointerType && !isMouseLikePointerType(pointerType)) {
+ return 0;
+ }
+ if (typeof value === 'number') {
+ return value;
+ }
+ return value == null ? void 0 : value[prop];
+}
+/**
+ * Adds hover event listeners that change the open state, like CSS :hover.
+ * @see https://floating-ui.com/docs/useHover
+ */
+const useHover = function (context, _temp) {
+ let {
+ enabled = true,
+ delay = 0,
+ handleClose = null,
+ mouseOnly = false,
+ restMs = 0,
+ move = true
+ } = _temp === void 0 ? {} : _temp;
+ const {
+ open,
+ onOpenChange,
+ dataRef,
+ events,
+ elements: {
+ domReference,
+ floating
+ },
+ refs
+ } = context;
+ const tree = useFloatingTree();
+ const parentId = useFloatingParentNodeId();
+ const handleCloseRef = useLatestRef(handleClose);
+ const delayRef = useLatestRef(delay);
+ const pointerTypeRef = React.useRef();
+ const timeoutRef = React.useRef();
+ const handlerRef = React.useRef();
+ const restTimeoutRef = React.useRef();
+ const blockMouseMoveRef = React.useRef(true);
+ const performedPointerEventsMutationRef = React.useRef(false);
+ const unbindMouseMoveRef = React.useRef(() => {});
+ const isHoverOpen = React.useCallback(() => {
+ var _dataRef$current$open;
+ const type = (_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type;
+ return (type == null ? void 0 : type.includes('mouse')) && type !== 'mousedown';
+ }, [dataRef]);
+
+ // When dismissing before opening, clear the delay timeouts to cancel it
+ // from showing.
+ React.useEffect(() => {
+ if (!enabled) {
+ return;
+ }
+ function onDismiss() {
+ clearTimeout(timeoutRef.current);
+ clearTimeout(restTimeoutRef.current);
+ blockMouseMoveRef.current = true;
+ }
+ events.on('dismiss', onDismiss);
+ return () => {
+ events.off('dismiss', onDismiss);
+ };
+ }, [enabled, events]);
+ React.useEffect(() => {
+ if (!enabled || !handleCloseRef.current || !open) {
+ return;
+ }
+ function onLeave() {
+ if (isHoverOpen()) {
+ onOpenChange(false);
+ }
+ }
+ const html = getDocument(floating).documentElement;
+ html.addEventListener('mouseleave', onLeave);
+ return () => {
+ html.removeEventListener('mouseleave', onLeave);
+ };
+ }, [floating, open, onOpenChange, enabled, handleCloseRef, dataRef, isHoverOpen]);
+ const closeWithDelay = React.useCallback(function (runElseBranch) {
+ if (runElseBranch === void 0) {
+ runElseBranch = true;
+ }
+ const closeDelay = getDelay(delayRef.current, 'close', pointerTypeRef.current);
+ if (closeDelay && !handlerRef.current) {
+ clearTimeout(timeoutRef.current);
+ timeoutRef.current = setTimeout(() => onOpenChange(false), closeDelay);
+ } else if (runElseBranch) {
+ clearTimeout(timeoutRef.current);
+ onOpenChange(false);
+ }
+ }, [delayRef, onOpenChange]);
+ const cleanupMouseMoveHandler = React.useCallback(() => {
+ unbindMouseMoveRef.current();
+ handlerRef.current = undefined;
+ }, []);
+ const clearPointerEvents = React.useCallback(() => {
+ if (performedPointerEventsMutationRef.current) {
+ const body = getDocument(refs.floating.current).body;
+ body.style.pointerEvents = '';
+ body.removeAttribute(safePolygonIdentifier);
+ performedPointerEventsMutationRef.current = false;
+ }
+ }, [refs]);
+
+ // Registering the mouse events on the reference directly to bypass React's
+ // delegation system. If the cursor was on a disabled element and then entered
+ // the reference (no gap), `mouseenter` doesn't fire in the delegation system.
+ React.useEffect(() => {
+ if (!enabled) {
+ return;
+ }
+ function isClickLikeOpenEvent() {
+ return dataRef.current.openEvent ? ['click', 'mousedown'].includes(dataRef.current.openEvent.type) : false;
+ }
+ function onMouseEnter(event) {
+ clearTimeout(timeoutRef.current);
+ blockMouseMoveRef.current = false;
+ if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current) || restMs > 0 && getDelay(delayRef.current, 'open') === 0) {
+ return;
+ }
+ dataRef.current.openEvent = event;
+ const openDelay = getDelay(delayRef.current, 'open', pointerTypeRef.current);
+ if (openDelay) {
+ timeoutRef.current = setTimeout(() => {
+ onOpenChange(true);
+ }, openDelay);
+ } else {
+ onOpenChange(true);
+ }
+ }
+ function onMouseLeave(event) {
+ if (isClickLikeOpenEvent()) {
+ return;
+ }
+ unbindMouseMoveRef.current();
+ const doc = getDocument(floating);
+ clearTimeout(restTimeoutRef.current);
+ if (handleCloseRef.current) {
+ clearTimeout(timeoutRef.current);
+ handlerRef.current = handleCloseRef.current({
+ ...context,
+ tree,
+ x: event.clientX,
+ y: event.clientY,
+ onClose() {
+ clearPointerEvents();
+ cleanupMouseMoveHandler();
+ closeWithDelay();
+ }
+ });
+ const handler = handlerRef.current;
+ doc.addEventListener('mousemove', handler);
+ unbindMouseMoveRef.current = () => {
+ doc.removeEventListener('mousemove', handler);
+ };
+ return;
+ }
+ closeWithDelay();
+ }
+
+ // Ensure the floating element closes after scrolling even if the pointer
+ // did not move.
+ // https://github.com/floating-ui/floating-ui/discussions/1692
+ function onScrollMouseLeave(event) {
+ if (isClickLikeOpenEvent()) {
+ return;
+ }
+ handleCloseRef.current == null ? void 0 : handleCloseRef.current({
+ ...context,
+ tree,
+ x: event.clientX,
+ y: event.clientY,
+ onClose() {
+ cleanupMouseMoveHandler();
+ closeWithDelay();
+ }
+ })(event);
+ }
+ if (isElement(domReference)) {
+ const ref = domReference;
+ open && ref.addEventListener('mouseleave', onScrollMouseLeave);
+ floating == null ? void 0 : floating.addEventListener('mouseleave', onScrollMouseLeave);
+ move && ref.addEventListener('mousemove', onMouseEnter, {
+ once: true
+ });
+ ref.addEventListener('mouseenter', onMouseEnter);
+ ref.addEventListener('mouseleave', onMouseLeave);
+ return () => {
+ open && ref.removeEventListener('mouseleave', onScrollMouseLeave);
+ floating == null ? void 0 : floating.removeEventListener('mouseleave', onScrollMouseLeave);
+ move && ref.removeEventListener('mousemove', onMouseEnter);
+ ref.removeEventListener('mouseenter', onMouseEnter);
+ ref.removeEventListener('mouseleave', onMouseLeave);
+ };
+ }
+ }, [domReference, floating, enabled, context, mouseOnly, restMs, move, closeWithDelay, cleanupMouseMoveHandler, clearPointerEvents, onOpenChange, open, tree, delayRef, handleCloseRef, dataRef]);
+
+ // Block pointer-events of every element other than the reference and floating
+ // while the floating element is open and has a `handleClose` handler. Also
+ // handles nested floating elements.
+ // https://github.com/floating-ui/floating-ui/issues/1722
+ index(() => {
+ var _handleCloseRef$curre;
+ if (!enabled) {
+ return;
+ }
+ if (open && (_handleCloseRef$curre = handleCloseRef.current) != null && _handleCloseRef$curre.__options.blockPointerEvents && isHoverOpen()) {
+ const body = getDocument(floating).body;
+ body.setAttribute(safePolygonIdentifier, '');
+ body.style.pointerEvents = 'none';
+ performedPointerEventsMutationRef.current = true;
+ if (isElement(domReference) && floating) {
+ var _tree$nodesRef$curren, _tree$nodesRef$curren2;
+ const ref = domReference;
+ const parentFloating = tree == null ? void 0 : (_tree$nodesRef$curren = tree.nodesRef.current.find(node => node.id === parentId)) == null ? void 0 : (_tree$nodesRef$curren2 = _tree$nodesRef$curren.context) == null ? void 0 : _tree$nodesRef$curren2.elements.floating;
+ if (parentFloating) {
+ parentFloating.style.pointerEvents = '';
+ }
+ ref.style.pointerEvents = 'auto';
+ floating.style.pointerEvents = 'auto';
+ return () => {
+ ref.style.pointerEvents = '';
+ floating.style.pointerEvents = '';
+ };
+ }
+ }
+ }, [enabled, open, parentId, floating, domReference, tree, handleCloseRef, dataRef, isHoverOpen]);
+ index(() => {
+ if (!open) {
+ pointerTypeRef.current = undefined;
+ cleanupMouseMoveHandler();
+ clearPointerEvents();
+ }
+ }, [open, cleanupMouseMoveHandler, clearPointerEvents]);
+ React.useEffect(() => {
+ return () => {
+ cleanupMouseMoveHandler();
+ clearTimeout(timeoutRef.current);
+ clearTimeout(restTimeoutRef.current);
+ clearPointerEvents();
+ };
+ }, [enabled, cleanupMouseMoveHandler, clearPointerEvents]);
+ return React.useMemo(() => {
+ if (!enabled) {
+ return {};
+ }
+ function setPointerRef(event) {
+ pointerTypeRef.current = event.pointerType;
+ }
+ return {
+ reference: {
+ onPointerDown: setPointerRef,
+ onPointerEnter: setPointerRef,
+ onMouseMove() {
+ if (open || restMs === 0) {
+ return;
+ }
+ clearTimeout(restTimeoutRef.current);
+ restTimeoutRef.current = setTimeout(() => {
+ if (!blockMouseMoveRef.current) {
+ onOpenChange(true);
+ }
+ }, restMs);
+ }
+ },
+ floating: {
+ onMouseEnter() {
+ clearTimeout(timeoutRef.current);
+ },
+ onMouseLeave() {
+ events.emit('dismiss', {
+ type: 'mouseLeave',
+ data: {
+ returnFocus: false
+ }
+ });
+ closeWithDelay(false);
+ }
+ }
+ };
+ }, [events, enabled, restMs, open, onOpenChange, closeWithDelay]);
+};
+
+const FloatingDelayGroupContext = /*#__PURE__*/React.createContext({
+ delay: 0,
+ initialDelay: 0,
+ timeoutMs: 0,
+ currentId: null,
+ setCurrentId: () => {},
+ setState: () => {},
+ isInstantPhase: false
+});
+const useDelayGroupContext = () => React.useContext(FloatingDelayGroupContext);
+
+/**
+ * Provides context for a group of floating elements that should share a
+ * `delay`.
+ * @see https://floating-ui.com/docs/FloatingDelayGroup
+ */
+const FloatingDelayGroup = _ref => {
+ let {
+ children,
+ delay,
+ timeoutMs = 0
+ } = _ref;
+ const [state, setState] = React.useReducer((prev, next) => ({
+ ...prev,
+ ...next
+ }), {
+ delay,
+ timeoutMs,
+ initialDelay: delay,
+ currentId: null,
+ isInstantPhase: false
+ });
+ const initialCurrentIdRef = React.useRef(null);
+ const setCurrentId = React.useCallback(currentId => {
+ setState({
+ currentId
+ });
+ }, []);
+ index(() => {
+ if (state.currentId) {
+ if (initialCurrentIdRef.current === null) {
+ initialCurrentIdRef.current = state.currentId;
+ } else {
+ setState({
+ isInstantPhase: true
+ });
+ }
+ } else {
+ setState({
+ isInstantPhase: false
+ });
+ initialCurrentIdRef.current = null;
+ }
+ }, [state.currentId]);
+ return /*#__PURE__*/React.createElement(FloatingDelayGroupContext.Provider, {
+ value: React.useMemo(() => ({
+ ...state,
+ setState,
+ setCurrentId
+ }), [state, setState, setCurrentId])
+ }, children);
+};
+const useDelayGroup = (_ref2, _ref3) => {
+ let {
+ open,
+ onOpenChange
+ } = _ref2;
+ let {
+ id
+ } = _ref3;
+ const {
+ currentId,
+ setCurrentId,
+ initialDelay,
+ setState,
+ timeoutMs
+ } = useDelayGroupContext();
+ React.useEffect(() => {
+ if (currentId) {
+ setState({
+ delay: {
+ open: 1,
+ close: getDelay(initialDelay, 'close')
+ }
+ });
+ if (currentId !== id) {
+ onOpenChange(false);
+ }
+ }
+ }, [id, onOpenChange, setState, currentId, initialDelay]);
+ React.useEffect(() => {
+ function unset() {
+ onOpenChange(false);
+ setState({
+ delay: initialDelay,
+ currentId: null
+ });
+ }
+ if (!open && currentId === id) {
+ if (timeoutMs) {
+ const timeout = window.setTimeout(unset, timeoutMs);
+ return () => {
+ clearTimeout(timeout);
+ };
+ } else {
+ unset();
+ }
+ }
+ }, [open, setState, currentId, id, onOpenChange, initialDelay, timeoutMs]);
+ React.useEffect(() => {
+ if (open) {
+ setCurrentId(id);
+ }
+ }, [open, setCurrentId, id]);
+};
+
+function _extends() {
+ _extends = Object.assign || function (target) {
+ for (var i = 1; i < arguments.length; i++) {
+ var source = arguments[i];
+ for (var key in source) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ target[key] = source[key];
+ }
+ }
+ }
+ return target;
+ };
+ return _extends.apply(this, arguments);
+}
+
+/**
+ * Find the real active element. Traverses into shadowRoots.
+ */
+function activeElement$1(doc) {
+ let activeElement = doc.activeElement;
+ while (((_activeElement = activeElement) == null ? void 0 : (_activeElement$shadow = _activeElement.shadowRoot) == null ? void 0 : _activeElement$shadow.activeElement) != null) {
+ var _activeElement, _activeElement$shadow;
+ activeElement = activeElement.shadowRoot.activeElement;
+ }
+ return activeElement;
+}
+
+function contains(parent, child) {
+ if (!parent || !child) {
+ return false;
+ }
+ const rootNode = child.getRootNode && child.getRootNode();
+
+ // First, attempt with faster native method
+ if (parent.contains(child)) {
+ return true;
+ }
+ // then fallback to custom implementation with Shadow DOM support
+ else if (rootNode && isShadowRoot(rootNode)) {
+ let next = child;
+ do {
+ if (next && parent === next) {
+ return true;
+ }
+ // @ts-ignore
+ next = next.parentNode || next.host;
+ } while (next);
+ }
+
+ // Give up, the result is false
+ return false;
+}
+
+let rafId = 0;
+function enqueueFocus(el, options) {
+ if (options === void 0) {
+ options = {};
+ }
+ const {
+ preventScroll = false,
+ cancelPrevious = true,
+ sync = false
+ } = options;
+ cancelPrevious && cancelAnimationFrame(rafId);
+ const exec = () => el == null ? void 0 : el.focus({
+ preventScroll
+ });
+ if (sync) {
+ exec();
+ } else {
+ rafId = requestAnimationFrame(exec);
+ }
+}
+
+function getAncestors(nodes, id) {
+ var _nodes$find;
+ let allAncestors = [];
+ let currentParentId = (_nodes$find = nodes.find(node => node.id === id)) == null ? void 0 : _nodes$find.parentId;
+ while (currentParentId) {
+ const currentNode = nodes.find(node => node.id === currentParentId);
+ currentParentId = currentNode == null ? void 0 : currentNode.parentId;
+ if (currentNode) {
+ allAncestors = allAncestors.concat(currentNode);
+ }
+ }
+ return allAncestors;
+}
+
+function getChildren(nodes, id) {
+ let allChildren = nodes.filter(node => {
+ var _node$context;
+ return node.parentId === id && ((_node$context = node.context) == null ? void 0 : _node$context.open);
+ }) || [];
+ let currentChildren = allChildren;
+ while (currentChildren.length) {
+ currentChildren = nodes.filter(node => {
+ var _currentChildren;
+ return (_currentChildren = currentChildren) == null ? void 0 : _currentChildren.some(n => {
+ var _node$context2;
+ return node.parentId === n.id && ((_node$context2 = node.context) == null ? void 0 : _node$context2.open);
+ });
+ }) || [];
+ allChildren = allChildren.concat(currentChildren);
+ }
+ return allChildren;
+}
+
+function getTarget(event) {
+ if ('composedPath' in event) {
+ return event.composedPath()[0];
+ }
+
+ // TS thinks `event` is of type never as it assumes all browsers support
+ // `composedPath()`, but browsers without shadow DOM don't.
+ return event.target;
+}
+
+const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
+function isTypeableElement(element) {
+ return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
+}
+
+function stopEvent(event) {
+ event.preventDefault();
+ event.stopPropagation();
+}
+
+const getTabbableOptions = () => ({
+ getShadowRoot: true,
+ displayCheck:
+ // JSDOM does not support the `tabbable` library. To solve this we can
+ // check if `ResizeObserver` is a real function (not polyfilled), which
+ // determines if the current environment is JSDOM-like.
+ typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
+});
+function getTabbableIn(container, direction) {
+ const allTabbable = tabbable(container, getTabbableOptions());
+ if (direction === 'prev') {
+ allTabbable.reverse();
+ }
+ const activeIndex = allTabbable.indexOf(activeElement$1(getDocument(container)));
+ const nextTabbableElements = allTabbable.slice(activeIndex + 1);
+ return nextTabbableElements[0];
+}
+function getNextTabbable() {
+ return getTabbableIn(document.body, 'next');
+}
+function getPreviousTabbable() {
+ return getTabbableIn(document.body, 'prev');
+}
+function isOutsideEvent(event, container) {
+ const containerElement = container || event.currentTarget;
+ const relatedTarget = event.relatedTarget;
+ return !relatedTarget || !contains(containerElement, relatedTarget);
+}
+function disableFocusInside(container) {
+ const tabbableElements = tabbable(container, getTabbableOptions());
+ tabbableElements.forEach(element => {
+ element.dataset.tabindex = element.getAttribute('tabindex') || '';
+ element.setAttribute('tabindex', '-1');
+ });
+}
+function enableFocusInside(container) {
+ const elements = container.querySelectorAll('[data-tabindex]');
+ elements.forEach(element => {
+ const tabindex = element.dataset.tabindex;
+ delete element.dataset.tabindex;
+ if (tabindex) {
+ element.setAttribute('tabindex', tabindex);
+ } else {
+ element.removeAttribute('tabindex');
+ }
+ });
+}
+
+// `toString()` prevents bundlers from trying to `import { useInsertionEffect } from 'react'`
+const useInsertionEffect = React[/*#__PURE__*/'useInsertionEffect'.toString()];
+const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
+function useEvent(callback) {
+ const ref = React.useRef(() => {
+ if (process.env.NODE_ENV !== "production") {
+ throw new Error('Cannot call an event handler while rendering.');
+ }
+ });
+ useSafeInsertionEffect(() => {
+ ref.current = callback;
+ });
+ return React.useCallback(function () {
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
+ args[_key] = arguments[_key];
+ }
+ return ref.current == null ? void 0 : ref.current(...args);
+ }, []);
+}
+
+// See Diego Haz's Sandbox for making this logic work well on Safari/iOS:
+// https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/FocusTrap.tsx
+
+const HIDDEN_STYLES = {
+ border: 0,
+ clip: 'rect(0 0 0 0)',
+ height: '1px',
+ margin: '-1px',
+ overflow: 'hidden',
+ padding: 0,
+ position: 'fixed',
+ whiteSpace: 'nowrap',
+ width: '1px',
+ top: 0,
+ left: 0
+};
+let activeElement;
+let timeoutId;
+function setActiveElementOnTab(event) {
+ if (event.key === 'Tab') {
+ activeElement = event.target;
+ clearTimeout(timeoutId);
+ }
+}
+function isTabFocus(event) {
+ const result = activeElement === event.relatedTarget;
+ activeElement = event.relatedTarget;
+ clearTimeout(timeoutId);
+ return result;
+}
+const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref) {
+ const onFocus = useEvent(props.onFocus);
+ const [role, setRole] = React.useState();
+ index(() => {
+ if (isSafari()) {
+ // Unlike other screen readers such as NVDA and JAWS, the virtual cursor
+ // on VoiceOver does trigger the onFocus event, so we can use the focus
+ // trap element. On Safari, only buttons trigger the onFocus event.
+ // NB: "group" role in the Sandbox no longer appears to work, must be a
+ // button role.
+ setRole('button');
+ }
+ document.addEventListener('keydown', setActiveElementOnTab);
+ return () => {
+ document.removeEventListener('keydown', setActiveElementOnTab);
+ };
+ }, []);
+ return /*#__PURE__*/React.createElement("span", _extends({}, props, {
+ ref: ref,
+ tabIndex: 0
+ // Role is only for VoiceOver
+ ,
+ role: role,
+ "aria-hidden": role ? undefined : true,
+ "data-floating-ui-focus-guard": "",
+ style: HIDDEN_STYLES,
+ onFocus: event => {
+ if (isSafari() && isMac() && !isTabFocus(event)) {
+ // On macOS we need to wait a little bit before moving
+ // focus again.
+ event.persist();
+ timeoutId = window.setTimeout(() => {
+ onFocus(event);
+ }, 50);
+ } else {
+ onFocus(event);
+ }
+ }
+ }));
+});
+
+const PortalContext = /*#__PURE__*/React.createContext(null);
+const useFloatingPortalNode = function (_temp) {
+ let {
+ id,
+ enabled = true
+ } = _temp === void 0 ? {} : _temp;
+ const [portalEl, setPortalEl] = React.useState(null);
+ const uniqueId = useId();
+ const portalContext = usePortalContext();
+ index(() => {
+ if (!enabled) {
+ return;
+ }
+ const rootNode = id ? document.getElementById(id) : null;
+ if (rootNode) {
+ rootNode.setAttribute('data-floating-ui-portal', '');
+ setPortalEl(rootNode);
+ } else {
+ const newPortalEl = document.createElement('div');
+ if (id !== '') {
+ newPortalEl.id = id || uniqueId;
+ }
+ newPortalEl.setAttribute('data-floating-ui-portal', '');
+ setPortalEl(newPortalEl);
+ const container = (portalContext == null ? void 0 : portalContext.portalNode) || document.body;
+ container.appendChild(newPortalEl);
+ return () => {
+ container.removeChild(newPortalEl);
+ };
+ }
+ }, [id, portalContext, uniqueId, enabled]);
+ return portalEl;
+};
+
+/**
+ * Portals your floating element outside of the main app node.
+ * @see https://floating-ui.com/docs/FloatingPortal
+ */
+const FloatingPortal = _ref => {
+ let {
+ children,
+ id,
+ root = null,
+ preserveTabOrder = true
+ } = _ref;
+ const portalNode = useFloatingPortalNode({
+ id,
+ enabled: !root
+ });
+ const [focusManagerState, setFocusManagerState] = React.useState(null);
+ const beforeOutsideRef = React.useRef(null);
+ const afterOutsideRef = React.useRef(null);
+ const beforeInsideRef = React.useRef(null);
+ const afterInsideRef = React.useRef(null);
+ const shouldRenderGuards =
+ // The FocusManager and therefore floating element are currently open/
+ // rendered.
+ !!focusManagerState &&
+ // Guards are only for non-modal focus management.
+ !focusManagerState.modal && !!(root || portalNode) && preserveTabOrder;
+
+ // https://codesandbox.io/s/tabbable-portal-f4tng?file=/src/TabbablePortal.tsx
+ React.useEffect(() => {
+ if (!portalNode || !preserveTabOrder || focusManagerState != null && focusManagerState.modal) {
+ return;
+ }
+
+ // Make sure elements inside the portal element are tabbable only when the
+ // portal has already been focused, either by tabbing into a focus trap
+ // element outside or using the mouse.
+ function onFocus(event) {
+ if (portalNode && isOutsideEvent(event)) {
+ const focusing = event.type === 'focusin';
+ const manageFocus = focusing ? enableFocusInside : disableFocusInside;
+ manageFocus(portalNode);
+ }
+ }
+ // Listen to the event on the capture phase so they run before the focus
+ // trap elements onFocus prop is called.
+ portalNode.addEventListener('focusin', onFocus, true);
+ portalNode.addEventListener('focusout', onFocus, true);
+ return () => {
+ portalNode.removeEventListener('focusin', onFocus, true);
+ portalNode.removeEventListener('focusout', onFocus, true);
+ };
+ }, [portalNode, preserveTabOrder, focusManagerState == null ? void 0 : focusManagerState.modal]);
+ return /*#__PURE__*/React.createElement(PortalContext.Provider, {
+ value: React.useMemo(() => ({
+ preserveTabOrder,
+ beforeOutsideRef,
+ afterOutsideRef,
+ beforeInsideRef,
+ afterInsideRef,
+ portalNode,
+ setFocusManagerState
+ }), [preserveTabOrder, portalNode])
+ }, shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
+ "data-type": "outside",
+ ref: beforeOutsideRef,
+ onFocus: event => {
+ if (isOutsideEvent(event, portalNode)) {
+ var _beforeInsideRef$curr;
+ (_beforeInsideRef$curr = beforeInsideRef.current) == null ? void 0 : _beforeInsideRef$curr.focus();
+ } else {
+ const prevTabbable = getPreviousTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
+ prevTabbable == null ? void 0 : prevTabbable.focus();
+ }
+ }
+ }), shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement("span", {
+ "aria-owns": portalNode.id,
+ style: HIDDEN_STYLES
+ }), root ? /*#__PURE__*/createPortal(children, root) : portalNode ? /*#__PURE__*/createPortal(children, portalNode) : null, shouldRenderGuards && portalNode && /*#__PURE__*/React.createElement(FocusGuard, {
+ "data-type": "outside",
+ ref: afterOutsideRef,
+ onFocus: event => {
+ if (isOutsideEvent(event, portalNode)) {
+ var _afterInsideRef$curre;
+ (_afterInsideRef$curre = afterInsideRef.current) == null ? void 0 : _afterInsideRef$curre.focus();
+ } else {
+ const nextTabbable = getNextTabbable() || (focusManagerState == null ? void 0 : focusManagerState.refs.domReference.current);
+ nextTabbable == null ? void 0 : nextTabbable.focus();
+ (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) && (focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false));
+ }
+ }
+ }));
+};
+const usePortalContext = () => React.useContext(PortalContext);
+
+const VisuallyHiddenDismiss = /*#__PURE__*/React.forwardRef(function VisuallyHiddenDismiss(props, ref) {
+ return /*#__PURE__*/React.createElement("button", _extends({}, props, {
+ type: "button",
+ ref: ref,
+ tabIndex: -1,
+ style: HIDDEN_STYLES
+ }));
+});
+/**
+ * Provides focus management for the floating element.
+ * @see https://floating-ui.com/docs/FloatingFocusManager
+ */
+function FloatingFocusManager(_ref) {
+ let {
+ context,
+ children,
+ order = ['content'],
+ guards = true,
+ initialFocus = 0,
+ returnFocus = true,
+ modal = true,
+ visuallyHiddenDismiss = false,
+ closeOnFocusOut = true
+ } = _ref;
+ const {
+ refs,
+ nodeId,
+ onOpenChange,
+ events,
+ dataRef,
+ elements: {
+ domReference,
+ floating
+ }
+ } = context;
+ const orderRef = useLatestRef(order);
+ const tree = useFloatingTree();
+ const portalContext = usePortalContext();
+ const [tabbableContentLength, setTabbableContentLength] = React.useState(null);
+
+ // Controlled by `useListNavigation`.
+ const ignoreInitialFocus = typeof initialFocus === 'number' && initialFocus < 0;
+ const startDismissButtonRef = React.useRef(null);
+ const endDismissButtonRef = React.useRef(null);
+ const preventReturnFocusRef = React.useRef(false);
+ const previouslyFocusedElementRef = React.useRef(null);
+ const isPointerDownRef = React.useRef(false);
+ const isInsidePortal = portalContext != null;
+
+ // If the reference is a combobox and is typeable (e.g. input/textarea),
+ // there are different focus semantics. The guards should not be rendered, but
+ // aria-hidden should be applied to all nodes still. Further, the visually
+ // hidden dismiss button should only appear at the end of the list, not the
+ // start.
+ const isTypeableCombobox = domReference && domReference.getAttribute('role') === 'combobox' && isTypeableElement(domReference);
+ const getTabbableContent = React.useCallback(function (container) {
+ if (container === void 0) {
+ container = floating;
+ }
+ return container ? tabbable(container, getTabbableOptions()) : [];
+ }, [floating]);
+ const getTabbableElements = React.useCallback(container => {
+ const content = getTabbableContent(container);
+ return orderRef.current.map(type => {
+ if (domReference && type === 'reference') {
+ return domReference;
+ }
+ if (floating && type === 'floating') {
+ return floating;
+ }
+ return content;
+ }).filter(Boolean).flat();
+ }, [domReference, floating, orderRef, getTabbableContent]);
+ React.useEffect(() => {
+ if (!modal) {
+ return;
+ }
+ function onKeyDown(event) {
+ if (event.key === 'Tab') {
+ // The focus guards have nothing to focus, so we need to stop the event.
+ if (getTabbableContent().length === 0 && !isTypeableCombobox) {
+ stopEvent(event);
+ }
+ const els = getTabbableElements();
+ const target = getTarget(event);
+ if (orderRef.current[0] === 'reference' && target === domReference) {
+ stopEvent(event);
+ if (event.shiftKey) {
+ enqueueFocus(els[els.length - 1]);
+ } else {
+ enqueueFocus(els[1]);
+ }
+ }
+ if (orderRef.current[1] === 'floating' && target === floating && event.shiftKey) {
+ stopEvent(event);
+ enqueueFocus(els[0]);
+ }
+ }
+ }
+ const doc = getDocument(floating);
+ doc.addEventListener('keydown', onKeyDown);
+ return () => {
+ doc.removeEventListener('keydown', onKeyDown);
+ };
+ }, [domReference, floating, modal, orderRef, refs, isTypeableCombobox, getTabbableContent, getTabbableElements]);
+ React.useEffect(() => {
+ if (!closeOnFocusOut) {
+ return;
+ }
+
+ // In Safari, buttons lose focus when pressing them.
+ function handlePointerDown() {
+ isPointerDownRef.current = true;
+ setTimeout(() => {
+ isPointerDownRef.current = false;
+ });
+ }
+ function handleFocusOutside(event) {
+ const relatedTarget = event.relatedTarget;
+ const movedToUnrelatedNode = !(contains(domReference, relatedTarget) || contains(floating, relatedTarget) || contains(relatedTarget, floating) || contains(portalContext == null ? void 0 : portalContext.portalNode, relatedTarget) || relatedTarget != null && relatedTarget.hasAttribute('data-floating-ui-focus-guard') || tree && (getChildren(tree.nodesRef.current, nodeId).find(node => {
+ var _node$context, _node$context2;
+ return contains((_node$context = node.context) == null ? void 0 : _node$context.elements.floating, relatedTarget) || contains((_node$context2 = node.context) == null ? void 0 : _node$context2.elements.domReference, relatedTarget);
+ }) || getAncestors(tree.nodesRef.current, nodeId).find(node => {
+ var _node$context3, _node$context4;
+ return ((_node$context3 = node.context) == null ? void 0 : _node$context3.elements.floating) === relatedTarget || ((_node$context4 = node.context) == null ? void 0 : _node$context4.elements.domReference) === relatedTarget;
+ })));
+
+ // Focus did not move inside the floating tree, and there are no tabbable
+ // portal guards to handle closing.
+ if (relatedTarget && movedToUnrelatedNode && !isPointerDownRef.current &&
+ // Fix React 18 Strict Mode returnFocus due to double rendering.
+ relatedTarget !== previouslyFocusedElementRef.current) {
+ preventReturnFocusRef.current = true;
+ // On iOS VoiceOver, dismissing the nested submenu will cause the
+ // first item of the list to receive focus. Delaying it appears to fix
+ // the issue.
+ setTimeout(() => onOpenChange(false));
+ }
+ }
+ if (floating && isHTMLElement(domReference)) {
+ domReference.addEventListener('focusout', handleFocusOutside);
+ domReference.addEventListener('pointerdown', handlePointerDown);
+ !modal && floating.addEventListener('focusout', handleFocusOutside);
+ return () => {
+ domReference.removeEventListener('focusout', handleFocusOutside);
+ domReference.removeEventListener('pointerdown', handlePointerDown);
+ !modal && floating.removeEventListener('focusout', handleFocusOutside);
+ };
+ }
+ }, [domReference, floating, modal, nodeId, tree, portalContext, onOpenChange, closeOnFocusOut]);
+ React.useEffect(() => {
+ var _portalContext$portal;
+ // Don't hide portals nested within the parent portal.
+ const portalNodes = Array.from((portalContext == null ? void 0 : (_portalContext$portal = portalContext.portalNode) == null ? void 0 : _portalContext$portal.querySelectorAll('[data-floating-ui-portal]')) || []);
+ function getDismissButtons() {
+ return [startDismissButtonRef.current, endDismissButtonRef.current].filter(Boolean);
+ }
+ if (floating && modal) {
+ const insideNodes = [floating, ...portalNodes, ...getDismissButtons()];
+ const cleanup = hideOthers(orderRef.current.includes('reference') || isTypeableCombobox ? insideNodes.concat(domReference || []) : insideNodes);
+ return () => {
+ cleanup();
+ };
+ }
+ }, [domReference, floating, modal, orderRef, portalContext, isTypeableCombobox]);
+ React.useEffect(() => {
+ if (modal && !guards && floating) {
+ const tabIndexValues = [];
+ const options = getTabbableOptions();
+ const allTabbable = tabbable(getDocument(floating).body, options);
+ const floatingTabbable = getTabbableElements();
+
+ // Exclude all tabbable elements that are part of the order
+ const elements = allTabbable.filter(el => !floatingTabbable.includes(el));
+ elements.forEach((el, i) => {
+ tabIndexValues[i] = el.getAttribute('tabindex');
+ el.setAttribute('tabindex', '-1');
+ });
+ return () => {
+ elements.forEach((el, i) => {
+ const value = tabIndexValues[i];
+ if (value == null) {
+ el.removeAttribute('tabindex');
+ } else {
+ el.setAttribute('tabindex', value);
+ }
+ });
+ };
+ }
+ }, [floating, modal, guards, getTabbableElements]);
+ index(() => {
+ if (!floating) return;
+ const doc = getDocument(floating);
+ let returnFocusValue = returnFocus;
+ let preventReturnFocusScroll = false;
+ const previouslyFocusedElement = activeElement$1(doc);
+ const contextData = dataRef.current;
+ previouslyFocusedElementRef.current = previouslyFocusedElement;
+ const focusableElements = getTabbableElements(floating);
+ const elToFocus = (typeof initialFocus === 'number' ? focusableElements[initialFocus] : initialFocus.current) || floating;
+
+ // If the `useListNavigation` hook is active, always ignore `initialFocus`
+ // because it has its own handling of the initial focus.
+ !ignoreInitialFocus && enqueueFocus(elToFocus, {
+ preventScroll: elToFocus === floating
+ });
+
+ // Dismissing via outside press should always ignore `returnFocus` to
+ // prevent unwanted scrolling.
+ function onDismiss(payload) {
+ if (payload.type === 'escapeKey' && refs.domReference.current) {
+ previouslyFocusedElementRef.current = refs.domReference.current;
+ }
+ if (['referencePress', 'escapeKey'].includes(payload.type)) {
+ return;
+ }
+ const returnFocus = payload.data.returnFocus;
+ if (typeof returnFocus === 'object') {
+ returnFocusValue = true;
+ preventReturnFocusScroll = returnFocus.preventScroll;
+ } else {
+ returnFocusValue = returnFocus;
+ }
+ }
+ events.on('dismiss', onDismiss);
+ return () => {
+ events.off('dismiss', onDismiss);
+ if (contains(floating, activeElement$1(doc)) && refs.domReference.current) {
+ previouslyFocusedElementRef.current = refs.domReference.current;
+ }
+ if (returnFocusValue && isHTMLElement(previouslyFocusedElementRef.current) && !preventReturnFocusRef.current) {
+ // `isPointerDownRef.current` to avoid the focus ring from appearing on
+ // the reference element when click-toggling it.
+ if (!refs.domReference.current || isPointerDownRef.current) {
+ enqueueFocus(previouslyFocusedElementRef.current, {
+ // When dismissing nested floating elements, by the time the rAF has
+ // executed, the menus will all have been unmounted. When they try
+ // to get focused, the calls get ignored — leaving the root
+ // reference focused as desired.
+ cancelPrevious: false,
+ preventScroll: preventReturnFocusScroll
+ });
+ } else {
+ var _previouslyFocusedEle;
+ // If the user has specified a `keydown` listener that calls
+ // setOpen(false) (e.g. selecting an item and closing the floating
+ // element), then sync return focus causes `useClick` to immediately
+ // re-open it, unless they call `event.preventDefault()` in the
+ // `keydown` listener. This helps keep backwards compatibility with
+ // older examples.
+ contextData.__syncReturnFocus = true;
+
+ // In Safari, `useListNavigation` moves focus sync, so making this
+ // sync ensures the initial item remains focused despite this being
+ // invoked in Strict Mode due to double-invoked useEffects. This also
+ // has the positive side effect of closing a modally focus-managed
+ //