UNPKG

@ariakit/react

Version:

Toolkit for building accessible web apps with React

1,070 lines (972 loc) 38.1 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw Error('Dynamic require of "' + x + '" is not supported'); }); var __commonJS = (cb, mod) => function __require2() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // ../ariakit-utils/dist/index.js function toArray(arg) { if (Array.isArray(arg)) return arg; return typeof arg !== "undefined" ? [arg] : []; } function flatten2DArray(array) { const flattened = []; for (const row of array) flattened.push(...row); return flattened; } function reverseArray(array) { return array.slice().reverse(); } function noop(..._) { } function shallowEqual(a, b) { if (a === b) return true; if (!a) return false; if (!b) return false; if (typeof a !== "object") return false; if (typeof b !== "object") return false; const aKeys = Object.keys(a); const bKeys = Object.keys(b); const { length } = aKeys; if (bKeys.length !== length) return false; for (const key of aKeys) if (a[key] !== b[key]) return false; return true; } function applyState(argument, currentValue) { if (isUpdater(argument)) return argument(isLazyValue(currentValue) ? currentValue() : currentValue); return argument; } function isUpdater(argument) { return typeof argument === "function"; } function isLazyValue(value) { return typeof value === "function"; } function isObject(arg) { return typeof arg === "object" && arg != null; } function hasOwnProperty(object, prop) { if (typeof Object.hasOwn === "function") return Object.hasOwn(object, prop); return Object.prototype.hasOwnProperty.call(object, prop); } function chain(...fns) { return (...args) => { for (const fn of fns) if (typeof fn === "function") fn(...args); }; } function cx(...args) { return args.filter(Boolean).join(" ") || void 0; } function normalizeString(str) { return str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } function omit(object, keys) { const result = { ...object }; for (const key of keys) if (hasOwnProperty(result, key)) delete result[key]; return result; } function pick(object, paths) { const result = {}; for (const key of paths) if (hasOwnProperty(object, key)) result[key] = object[key]; return result; } function identity(value) { return value; } function afterPaint(cb = noop) { let raf = requestAnimationFrame(() => { raf = requestAnimationFrame(cb); }); return () => cancelAnimationFrame(raf); } function invariant(condition, message) { if (condition) return; if (typeof message !== "string") throw new Error("Invariant failed"); throw new Error(message); } function getKeys(obj) { return Object.keys(obj); } function isFalsyBooleanCallback(booleanOrCallback, ...args) { const result = typeof booleanOrCallback === "function" ? booleanOrCallback(...args) : booleanOrCallback; if (result == null) return false; return !result; } function disabledFromProps(props) { return props.disabled || props["aria-disabled"] === true || props["aria-disabled"] === "true"; } function disabledFromElement(element) { if (element.getAttribute("aria-disabled") === "true") return true; if ("disabled" in element && element.disabled === true) return true; return false; } function removeUndefinedValues(obj) { const result = {}; for (const key in obj) if (obj[key] !== void 0) result[key] = obj[key]; return result; } function defaultValue(...values) { for (const value of values) if (value !== void 0) return value; } var canUseDOM = checkIsBrowser(); function checkIsBrowser() { var _a; return typeof window !== "undefined" && !!((_a = window.document) == null ? void 0 : _a.createElement); } function getDocument(node) { if (!node) return document; if ("self" in node) return node.document; return node.ownerDocument || document; } function getWindow(node) { if (!node) return self; if ("self" in node) return node.self; return getDocument(node).defaultView || window; } function getActiveElement(node, activeDescendant = false) { var _a; const { activeElement } = getDocument(node); if (!(activeElement == null ? void 0 : activeElement.nodeName)) return null; if (isFrame(activeElement) && ((_a = activeElement.contentDocument) == null ? void 0 : _a.body)) return getActiveElement(activeElement.contentDocument.body, activeDescendant); if (activeDescendant) { const id = activeElement.getAttribute("aria-activedescendant"); if (id) { const element = getDocument(activeElement).getElementById(id); if (element) return element; } } return activeElement; } function contains(parent, child) { return parent === child || parent.contains(child); } function isElement(target) { return (target == null ? void 0 : target.nodeType) === 1; } function isNode(target) { return typeof (target == null ? void 0 : target.nodeType) === "number"; } function isFrame(element) { return element.tagName === "IFRAME"; } function isButton(element) { const tagName = element.tagName.toLowerCase(); if (tagName === "button") return true; if (tagName === "input" && element.type) return buttonInputTypes.indexOf(element.type) !== -1; return false; } var buttonInputTypes = [ "button", "color", "file", "image", "reset", "submit" ]; function isVisible(element) { if (typeof element.checkVisibility === "function") return element.checkVisibility(); const htmlElement = element; return htmlElement.offsetWidth > 0 || htmlElement.offsetHeight > 0 || element.getClientRects().length > 0; } function isTextField(element) { try { if (element.tagName === "TEXTAREA") return true; if (element.tagName !== "INPUT") return false; return element.selectionStart !== null; } catch (_error) { return false; } } function isTextbox(element) { return element.isContentEditable || isTextField(element); } function getTextboxValue(element) { if (isTextField(element)) return element.value; if (element.isContentEditable) { const range = getDocument(element).createRange(); range.selectNodeContents(element); return range.toString(); } return ""; } function getTextboxSelection(element) { let start = 0; let end = 0; if (isTextField(element)) { start = element.selectionStart || 0; end = element.selectionEnd || 0; } else if (element.isContentEditable) { const selection = getDocument(element).getSelection(); if ((selection == null ? void 0 : selection.rangeCount) && selection.anchorNode && contains(element, selection.anchorNode) && selection.focusNode && contains(element, selection.focusNode)) { const range = selection.getRangeAt(0); const nextRange = range.cloneRange(); nextRange.selectNodeContents(element); nextRange.setEnd(range.startContainer, range.startOffset); start = nextRange.toString().length; nextRange.setEnd(range.endContainer, range.endOffset); end = nextRange.toString().length; } } return { start, end }; } var allowedPopupRoles = [ "dialog", "menu", "listbox", "tree", "grid" ]; var itemRoleByPopupRole = { menu: "menuitem", listbox: "option", tree: "treeitem" }; function getPopupRole(element, fallback) { const role = element == null ? void 0 : element.getAttribute("role"); if (role && allowedPopupRoles.indexOf(role) !== -1) return role; return fallback; } function getItemRoleByPopupRole(popupRole) { if (popupRole == null) return; if (!hasOwnProperty(itemRoleByPopupRole, popupRole)) return; return itemRoleByPopupRole[popupRole]; } function getPopupItemRole(element, fallback) { var _a; const popupRole = getPopupRole(element); if (typeof popupRole !== "string") return fallback; return (_a = getItemRoleByPopupRole(popupRole)) != null ? _a : fallback; } function getScrollingElement(element) { if (!element) return null; const isScrollableOverflow = (overflow) => { if (overflow === "auto") return true; if (overflow === "scroll") return true; return false; }; if (element.clientHeight && element.scrollHeight > element.clientHeight) { const { overflowY } = getComputedStyle(element); if (isScrollableOverflow(overflowY)) return element; } else if (element.clientWidth && element.scrollWidth > element.clientWidth) { const { overflowX } = getComputedStyle(element); if (isScrollableOverflow(overflowX)) return element; } const doc = getDocument(element); return getScrollingElement(element.parentElement) || doc.scrollingElement || doc.body; } function setSelectionRange(element, ...args) { if (/text|search|password|tel|url/i.test(element.type)) element.setSelectionRange(...args); } function sortBasedOnDOMPosition(items, getElement) { const pairs = items.map((item, index) => [index, item]); let isOrderDifferent = false; pairs.sort(([indexA, a], [indexB, b]) => { const elementA = getElement(a); const elementB = getElement(b); if (elementA === elementB) return 0; if (!elementA || !elementB) return 0; if (isElementPreceding(elementA, elementB)) { if (indexA > indexB) isOrderDifferent = true; return -1; } if (indexA < indexB) isOrderDifferent = true; return 1; }); if (isOrderDifferent) return pairs.map(([_, item]) => item); return items; } function isElementPreceding(a, b) { return Boolean(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING); } function isTouchDevice() { return canUseDOM && !!navigator.maxTouchPoints; } function isApple() { if (!canUseDOM) return false; return /mac|iphone|ipad|ipod/i.test(navigator.platform); } function isSafari() { return canUseDOM && isApple() && /apple/i.test(navigator.vendor); } function isFirefox() { return canUseDOM && /firefox\//i.test(navigator.userAgent); } function isMac() { return canUseDOM && navigator.platform.startsWith("Mac") && !isTouchDevice(); } function isPortalEvent(event) { const { currentTarget, target } = event; if (!currentTarget) return false; if (!isNode(target)) return true; return !contains(currentTarget, target); } function isSelfTarget(event) { return event.target === event.currentTarget; } function isActivatableNavigationTarget(element) { if (!isElement(element)) return false; const target = element; const tagName = target.tagName.toLowerCase(); if (tagName === "a") return true; if (tagName === "button" && target.type === "submit") return true; if (tagName === "input" && target.type === "submit") return true; return false; } function isOpeningInNewTab(event) { const isAppleDevice = isApple(); if (isAppleDevice && !event.metaKey) return false; if (!isAppleDevice && !event.ctrlKey) return false; return isActivatableNavigationTarget(event.currentTarget); } function isDownloading(event) { if (!event.altKey) return false; return isActivatableNavigationTarget(event.currentTarget); } function fireEvent(element, type, eventInit) { const event = new Event(type, eventInit); return element.dispatchEvent(event); } function fireBlurEvent(element, eventInit) { const event = new FocusEvent("blur", eventInit); const defaultAllowed = element.dispatchEvent(event); const bubbleInit = { ...eventInit, bubbles: true }; element.dispatchEvent(new FocusEvent("focusout", bubbleInit)); return defaultAllowed; } function fireKeyboardEvent(element, type, eventInit) { const event = new KeyboardEvent(type, eventInit); return element.dispatchEvent(event); } function fireClickEvent(element, eventInit) { const event = new MouseEvent("click", eventInit); return element.dispatchEvent(event); } function isFocusEventOutside(event, container) { const containerElement = container || event.currentTarget; const relatedTarget = event.relatedTarget; return !isNode(relatedTarget) || !contains(containerElement, relatedTarget); } function isInputEvent(event) { return event.type === "input"; } function queueBeforeEvent(element, type, callback, timeout) { const createTimer = (callback2) => { if (timeout) { const timerId2 = setTimeout(callback2, timeout); return () => clearTimeout(timerId2); } const timerId = requestAnimationFrame(callback2); return () => cancelAnimationFrame(timerId); }; const cancelTimer = createTimer(() => { element.removeEventListener(type, callSync, true); callback(); }); const callSync = () => { cancelTimer(); callback(); }; element.addEventListener(type, callSync, { once: true, capture: true }); return () => { cancelTimer(); element.removeEventListener(type, callSync, true); }; } function addGlobalEventListener(type, listener, options, scope = window) { const children = []; try { scope.document.addEventListener(type, listener, options); for (const frame of Array.from(scope.frames)) children.push(addGlobalEventListener(type, listener, options, frame)); } catch (e) { } const removeEventListener = () => { try { scope.document.removeEventListener(type, listener, options); } catch (e) { } for (const remove of children) remove(); }; return removeEventListener; } var selector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], summary, iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false'])"; function hasNegativeTabIndex(element) { return Number.parseInt(element.getAttribute("tabindex") || "0", 10) < 0; } function isFocusable(element) { if (!element.matches(selector)) return false; if (!isVisible(element)) return false; if (element.closest("[inert]")) return false; return true; } function isTabbable(element) { if (!isFocusable(element)) return false; if (hasNegativeTabIndex(element)) return false; if (!("form" in element)) return true; if (!element.form) return true; if (element.checked) return true; if (element.type !== "radio") return true; const radioGroup = element.form.elements.namedItem(element.name); if (!radioGroup) return true; if (!("length" in radioGroup)) return true; const activeElement = getActiveElement(element); if (!activeElement) return true; if (activeElement === element) return true; if (!("form" in activeElement)) return true; if (activeElement.form !== element.form) return true; if (activeElement.name !== element.name) return true; return false; } function getAllFocusableIn(container, includeContainer) { const elements = Array.from(container.querySelectorAll(selector)); if (includeContainer) elements.unshift(container); const focusableElements = elements.filter(isFocusable); focusableElements.forEach((element, i) => { var _a; if (!isFrame(element)) return; const frameBody = (_a = element.contentDocument) == null ? void 0 : _a.body; if (!frameBody) return; focusableElements.splice(i, 1, ...getAllFocusableIn(frameBody)); }); return focusableElements; } function getFirstFocusableIn(container, includeContainer) { const [first] = getAllFocusableIn(container, includeContainer); return first || null; } function getAllTabbableIn(container, includeContainer, fallbackToFocusable) { const tabbableElements = Array.from(container.querySelectorAll(selector)).filter(isTabbable); if (includeContainer && isTabbable(container)) tabbableElements.unshift(container); tabbableElements.forEach((element, i) => { var _a; if (!isFrame(element)) return; const frameBody = (_a = element.contentDocument) == null ? void 0 : _a.body; if (!frameBody) return; const allFrameTabbable = getAllTabbableIn(frameBody, false, fallbackToFocusable); tabbableElements.splice(i, 1, ...allFrameTabbable); }); if (!tabbableElements.length && fallbackToFocusable) return getAllFocusableIn(container); return tabbableElements; } function getFirstTabbableIn(container, includeContainer, fallbackToFocusable) { var _a, _b; if (includeContainer && isTabbable(container)) { if (!isFrame(container)) return container; const containerFrameBody = (_a = container.contentDocument) == null ? void 0 : _a.body; if (!containerFrameBody) return container; const frameTabbable = getFirstTabbableIn(containerFrameBody, false, fallbackToFocusable); if (frameTabbable) return frameTabbable; } const elements = container.querySelectorAll(selector); for (const element of elements) { if (!isTabbable(element)) continue; if (isFrame(element)) { const frameBody = (_b = element.contentDocument) == null ? void 0 : _b.body; if (!frameBody) return element; const frameTabbable = getFirstTabbableIn(frameBody, false, fallbackToFocusable); if (frameTabbable) return frameTabbable; continue; } return element; } if (fallbackToFocusable) return getFirstFocusableIn(container); return null; } function getTabbableInDirection({ container, includeContainer, reverse, fallbackToEdge, fallbackToFocusable }) { const activeElement = getActiveElement(container); const allFocusable = getAllFocusableIn(container, includeContainer); if (reverse) allFocusable.reverse(); const activeIndex = allFocusable.indexOf(activeElement); const candidates = allFocusable.slice(activeIndex + 1); return candidates.find(isTabbable) || (fallbackToEdge ? allFocusable.find(isTabbable) : null) || (fallbackToFocusable ? candidates[0] : null) || null; } function getNextTabbableIn(container, includeContainer, fallbackToFirst, fallbackToFocusable) { return getTabbableInDirection({ container, includeContainer, fallbackToEdge: fallbackToFirst, fallbackToFocusable }); } function getNextTabbable(fallbackToFirst, fallbackToFocusable) { return getNextTabbableIn(document.body, false, fallbackToFirst, fallbackToFocusable); } function getPreviousTabbableIn(container, includeContainer, fallbackToLast, fallbackToFocusable) { return getTabbableInDirection({ container, includeContainer, reverse: true, fallbackToEdge: fallbackToLast, fallbackToFocusable }); } function getPreviousTabbable(fallbackToLast, fallbackToFocusable) { return getPreviousTabbableIn(document.body, false, fallbackToLast, fallbackToFocusable); } function hasFocus(element) { const activeElement = getActiveElement(element); if (!activeElement) return false; if (activeElement === element) return true; const activeDescendant = activeElement.getAttribute("aria-activedescendant"); if (!activeDescendant) return false; return activeDescendant === element.id; } function hasFocusWithin(element) { const activeElement = getActiveElement(element); if (!activeElement) return false; if (contains(element, activeElement)) return true; const activeDescendant = activeElement.getAttribute("aria-activedescendant"); if (!activeDescendant) return false; if (!("id" in element)) return false; if (activeDescendant === element.id) return true; return !!element.querySelector(`#${CSS.escape(activeDescendant)}`); } function disableFocus(element) { var _a; const currentTabindex = (_a = element.getAttribute("tabindex")) != null ? _a : ""; element.setAttribute("data-tabindex", currentTabindex); element.setAttribute("tabindex", "-1"); } function disableFocusIn(container, includeContainer) { const tabbableElements = getAllTabbableIn(container, includeContainer); for (const element of tabbableElements) disableFocus(element); } function restoreFocusIn(container) { const elements = container.querySelectorAll("[data-tabindex]"); const restoreTabIndex = (element) => { const tabindex = element.getAttribute("data-tabindex"); element.removeAttribute("data-tabindex"); if (tabindex) element.setAttribute("tabindex", tabindex); else element.removeAttribute("tabindex"); }; if (container.hasAttribute("data-tabindex")) restoreTabIndex(container); for (const element of elements) restoreTabIndex(element); } function focusIntoView(element, options) { if (!("scrollIntoView" in element)) element.focus(); else { element.focus({ preventScroll: true }); element.scrollIntoView({ block: "nearest", inline: "nearest", ...options }); } } function createUndoCallback(callback) { return async () => { const redo = await (callback == null ? void 0 : callback()); return createUndoCallback(async () => { await (redo == null ? void 0 : redo()); return callback; }); }; } var UndoManager = createUndoManager(); function createUndoManager({ limit = 100 } = {}) { const undoStack = []; let redoStack = []; let currentGroup = null; const canUndo = () => undoStack.length > 0; const canRedo = () => redoStack.length > 0; const undo = async () => { var _a; if (!canUndo()) return; currentGroup = null; redoStack.push(await ((_a = undoStack.pop()) == null ? void 0 : _a())); }; const redo = async () => { var _a; if (!canRedo()) return; currentGroup = null; undoStack.push(await ((_a = redoStack.pop()) == null ? void 0 : _a())); }; const execute = async (callback, group) => { if (!callback) return; const sameGroup = group === currentGroup; currentGroup = group != null ? group : null; const nextIndex = sameGroup ? Math.max(0, undoStack.length - 1) : undoStack.length; const undoCallback = await callback(); if (!undoCallback) return; redoStack = []; const currentUndo = undoStack[nextIndex]; undoStack[nextIndex] = createUndoCallback(async () => { await (undoCallback == null ? void 0 : undoCallback()); const currentRedo = await (currentUndo == null ? void 0 : currentUndo()); return async () => { await (currentRedo == null ? void 0 : currentRedo()); await (callback == null ? void 0 : callback()); }; }); while (undoStack.length > limit) undoStack.shift(); }; return { canUndo, canRedo, undo, redo, execute }; } // ../ariakit-react-utils/dist/index.js var _react = require('react'); var React = _interopRequireWildcard(_react); var _jsxruntime = require('react/jsx-runtime'); function setRef(ref, value) { if (typeof ref === "function") { const cleanup = ref(value); if (typeof cleanup === "function") return cleanup; } else if (ref) ref.current = value; } function isValidElementWithRef(element) { if (!element) return false; if (!_react.isValidElement.call(void 0, element)) return false; if ("ref" in element.props) return true; if ("ref" in element) return true; return false; } function getRefProperty(element) { if (!isValidElementWithRef(element)) return null; return { ...element.props }.ref || element.ref; } function mergeProps(base, overrides) { const props = { ...base }; for (const key in overrides) { if (!hasOwnProperty(overrides, key)) continue; if (key === "className") { const prop = "className"; const baseClass = base[prop]; const overrideClass = overrides[prop]; if (baseClass && overrideClass) props[prop] = `${baseClass} ${overrideClass}`; else props[prop] = overrideClass || baseClass; continue; } if (key === "style") { const prop = "style"; props[prop] = base[prop] ? { ...base[prop], ...overrides[prop] } : overrides[prop]; continue; } const overrideValue = overrides[key]; if (key.startsWith("on")) { if (typeof overrideValue !== "function") continue; const baseValue = base[key]; if (typeof baseValue === "function") { props[key] = (...args) => { overrideValue(...args); baseValue(...args); }; continue; } } props[key] = overrideValue; } return props; } var _React = { ...React }; var useReactId = _React.useId; var useReactDeferredValue = _React.useDeferredValue; var useReactInsertionEffect = _React.useInsertionEffect; var useSafeLayoutEffect = canUseDOM ? _react.useLayoutEffect : _react.useEffect; function useInitialValue(value) { const [initialValue] = _react.useState.call(void 0, value); return initialValue; } function useLiveRef(value) { const ref = _react.useRef.call(void 0, value); useSafeLayoutEffect(() => { ref.current = value; }); return ref; } function useEvent(callback) { const ref = _react.useRef.call(void 0, () => { throw new Error("Cannot call an event handler while rendering."); }); if (useReactInsertionEffect) useReactInsertionEffect(() => { ref.current = callback; }); else ref.current = callback; return _react.useCallback.call(void 0, (...args) => { var _a; return (_a = ref.current) == null ? void 0 : _a.call(ref, ...args); }, []); } function useTransactionState(callback) { const [state, setState] = _react.useState.call(void 0, null); useSafeLayoutEffect(() => { if (state == null) return; if (!callback) return; let prevState = null; callback((prev) => { prevState = prev; return state; }); return () => { callback(prevState); }; }, [state, callback]); return [state, setState]; } function useMergeRefs(...refs) { return _react.useMemo.call(void 0, () => { if (!refs.some(Boolean)) return; return (value) => { const refEffects = []; for (const ref of refs) { if (!ref) continue; const cleanup = setRef(ref, value); refEffects.push({ ref, cleanup: typeof cleanup === "function" ? cleanup : void 0 }); } if (!refEffects.some((effect) => effect.cleanup)) return; return () => { for (const { ref, cleanup } of refEffects) if (cleanup) cleanup(); else setRef(ref, null); }; }; }, refs); } function useId(defaultId) { if (useReactId) { const reactId = useReactId(); if (defaultId) return defaultId; return reactId; } const [id, setId] = _react.useState.call(void 0, defaultId); useSafeLayoutEffect(() => { if (defaultId || id) return; setId(`id-${Math.random().toString(36).slice(2, 8)}`); }, [defaultId, id]); return defaultId || id; } function useTagName(refOrElement, type) { const stringOrUndefined = (type2) => { if (typeof type2 !== "string") return; return type2; }; const [tagName, setTagName] = _react.useState.call(void 0, () => stringOrUndefined(type)); useSafeLayoutEffect(() => { var _a; setTagName(((_a = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement) == null ? void 0 : _a.tagName.toLowerCase()) || stringOrUndefined(type)); }, [refOrElement, type]); return tagName; } function useAttribute(refOrElement, attributeName, defaultValue2) { const initialValue = useInitialValue(defaultValue2); const [attribute, setAttribute] = _react.useState.call(void 0, initialValue); _react.useEffect.call(void 0, () => { const element = refOrElement && "current" in refOrElement ? refOrElement.current : refOrElement; if (!element) return; const callback = () => { const value = element.getAttribute(attributeName); setAttribute(value == null ? initialValue : value); }; const observer = new MutationObserver(callback); observer.observe(element, { attributeFilter: [attributeName] }); callback(); return () => observer.disconnect(); }, [ refOrElement, attributeName, initialValue ]); return attribute; } function useUpdateEffect(effect, deps) { const mounted = _react.useRef.call(void 0, false); _react.useEffect.call(void 0, () => { if (mounted.current) return effect(); mounted.current = true; }, deps); _react.useEffect.call(void 0, () => () => { mounted.current = false; }, []); } function useUpdateLayoutEffect(effect, deps) { const mounted = _react.useRef.call(void 0, false); useSafeLayoutEffect(() => { if (mounted.current) return effect(); mounted.current = true; }, deps); useSafeLayoutEffect(() => () => { mounted.current = false; }, []); } function useForceUpdate() { return _react.useReducer.call(void 0, () => [], []); } function useBooleanEvent(booleanOrCallback) { return useEvent(typeof booleanOrCallback === "function" ? booleanOrCallback : () => booleanOrCallback); } function useWrapElement(props, callback, deps = []) { const wrapElement = _react.useCallback.call(void 0, (element) => { if (props.wrapElement) element = props.wrapElement(element); return callback(element); }, [...deps, props.wrapElement]); return { ...props, wrapElement }; } function usePortalRef(portalProp = false, portalRefProp) { const [portalNode, setPortalNode] = _react.useState.call(void 0, null); return { portalRef: useMergeRefs(setPortalNode, portalRefProp), portalNode, domReady: !portalProp || portalNode }; } function useMetadataProps(props, key, value) { const parent = props.onLoadedMetadataCapture; const onLoadedMetadataCapture = _react.useMemo.call(void 0, () => { return Object.assign(() => { }, parent, ...value !== void 0 ? [{ [key]: value }] : []); }, [ parent, key, value ]); return [parent == null ? void 0 : parent[key], { onLoadedMetadataCapture }]; } var hasInstalledGlobalEventListeners = false; function useIsMouseMoving() { _react.useEffect.call(void 0, () => { if (hasInstalledGlobalEventListeners) return; addGlobalEventListener("mousemove", setMouseMoving, true); addGlobalEventListener("mousedown", resetMouseMoving, true); addGlobalEventListener("mouseup", resetMouseMoving, true); addGlobalEventListener("keydown", resetMouseMoving, true); addGlobalEventListener("scroll", resetMouseMoving, true); hasInstalledGlobalEventListeners = true; }, []); return useEvent(() => mouseMoving); } var mouseMoving = false; var previousScreenX = 0; var previousScreenY = 0; function hasMouseMovement(event) { const movementX = event.movementX || event.screenX - previousScreenX; const movementY = event.movementY || event.screenY - previousScreenY; previousScreenX = event.screenX; previousScreenY = event.screenY; return movementX || movementY || process.env.NODE_ENV === "test"; } function setMouseMoving(event) { if (!hasMouseMovement(event)) return; mouseMoving = true; } function resetMouseMoving() { mouseMoving = false; } function forwardRef2(render) { const Role = React.forwardRef((props, ref) => render({ ...props, ref })); Role.displayName = render.displayName || render.name; return Role; } function memo2(Component, propsAreEqual) { return React.memo(Component, propsAreEqual); } function createElement(Type, props) { const { wrapElement, render, ...rest } = props; const mergedRef = useMergeRefs(props.ref, getRefProperty(render)); let element; if (React.isValidElement(render)) { const renderProps = { ...render.props, ref: mergedRef }; element = React.cloneElement(render, mergeProps(rest, renderProps)); } else if (render) element = render(rest); else element = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Type, { ...rest }); if (wrapElement) return wrapElement(element); return element; } function createHook(useProps) { const useRole = (props = {}) => { return useProps(props); }; useRole.displayName = useProps.name; return useRole; } function createStoreContext(providers = [], scopedProviders = []) { const context = React.createContext(void 0); const scopedContext = React.createContext(void 0); const useContext2 = () => React.useContext(context); const useScopedContext = (onlyScoped = false) => { const scoped = React.useContext(scopedContext); const store = useContext2(); if (onlyScoped) return scoped; return scoped || store; }; const useProviderContext = () => { const scoped = React.useContext(scopedContext); const store = useContext2(); if (scoped && scoped === store) return; return store; }; const ContextProvider = (props) => { return providers.reduceRight((children, Provider) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Provider, { ...props, children }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, context.Provider, { ...props })); }; const ScopedContextProvider = (props) => { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ContextProvider, { ...props, children: scopedProviders.reduceRight((children, Provider) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Provider, { ...props, children }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, scopedContext.Provider, { ...props })) }); }; return { context, scopedContext, useContext: useContext2, useScopedContext, useProviderContext, ContextProvider, ScopedContextProvider }; } exports.__require = __require; exports.__commonJS = __commonJS; exports.__toESM = __toESM; exports.toArray = toArray; exports.flatten2DArray = flatten2DArray; exports.reverseArray = reverseArray; exports.noop = noop; exports.shallowEqual = shallowEqual; exports.applyState = applyState; exports.isObject = isObject; exports.hasOwnProperty = hasOwnProperty; exports.chain = chain; exports.cx = cx; exports.normalizeString = normalizeString; exports.omit = omit; exports.pick = pick; exports.identity = identity; exports.afterPaint = afterPaint; exports.invariant = invariant; exports.getKeys = getKeys; exports.isFalsyBooleanCallback = isFalsyBooleanCallback; exports.disabledFromProps = disabledFromProps; exports.disabledFromElement = disabledFromElement; exports.removeUndefinedValues = removeUndefinedValues; exports.defaultValue = defaultValue; exports.getDocument = getDocument; exports.getWindow = getWindow; exports.getActiveElement = getActiveElement; exports.contains = contains; exports.isElement = isElement; exports.isNode = isNode; exports.isButton = isButton; exports.isTextField = isTextField; exports.isTextbox = isTextbox; exports.getTextboxValue = getTextboxValue; exports.getTextboxSelection = getTextboxSelection; exports.getPopupRole = getPopupRole; exports.getItemRoleByPopupRole = getItemRoleByPopupRole; exports.getPopupItemRole = getPopupItemRole; exports.getScrollingElement = getScrollingElement; exports.setSelectionRange = setSelectionRange; exports.sortBasedOnDOMPosition = sortBasedOnDOMPosition; exports.isTouchDevice = isTouchDevice; exports.isApple = isApple; exports.isSafari = isSafari; exports.isFirefox = isFirefox; exports.isMac = isMac; exports.isPortalEvent = isPortalEvent; exports.isSelfTarget = isSelfTarget; exports.isOpeningInNewTab = isOpeningInNewTab; exports.isDownloading = isDownloading; exports.fireEvent = fireEvent; exports.fireBlurEvent = fireBlurEvent; exports.fireKeyboardEvent = fireKeyboardEvent; exports.fireClickEvent = fireClickEvent; exports.isFocusEventOutside = isFocusEventOutside; exports.isInputEvent = isInputEvent; exports.queueBeforeEvent = queueBeforeEvent; exports.addGlobalEventListener = addGlobalEventListener; exports.isFocusable = isFocusable; exports.getAllTabbableIn = getAllTabbableIn; exports.getFirstTabbableIn = getFirstTabbableIn; exports.getNextTabbable = getNextTabbable; exports.getPreviousTabbable = getPreviousTabbable; exports.hasFocus = hasFocus; exports.hasFocusWithin = hasFocusWithin; exports.disableFocusIn = disableFocusIn; exports.restoreFocusIn = restoreFocusIn; exports.focusIntoView = focusIntoView; exports.setRef = setRef; exports.useSafeLayoutEffect = useSafeLayoutEffect; exports.useInitialValue = useInitialValue; exports.useLiveRef = useLiveRef; exports.useEvent = useEvent; exports.useTransactionState = useTransactionState; exports.useMergeRefs = useMergeRefs; exports.useId = useId; exports.useTagName = useTagName; exports.useAttribute = useAttribute; exports.useUpdateEffect = useUpdateEffect; exports.useUpdateLayoutEffect = useUpdateLayoutEffect; exports.useForceUpdate = useForceUpdate; exports.useBooleanEvent = useBooleanEvent; exports.useWrapElement = useWrapElement; exports.usePortalRef = usePortalRef; exports.useMetadataProps = useMetadataProps; exports.useIsMouseMoving = useIsMouseMoving; exports.forwardRef = forwardRef2; exports.memo = memo2; exports.createElement = createElement; exports.createHook = createHook; exports.createStoreContext = createStoreContext;