//#region src/array.d.ts /** * Array helpers used by Ariakit packages. * @module Array utilities */ /** * Transforms `arg` into an array if it's not already. * @example * toArray("a"); // ["a"] * toArray(["a"]); // ["a"] */ declare function toArray(arg: T): T extends readonly any[] ? T : T[]; /** * Immutably adds an item to an array. * @example * addItemToArray(["a", "b", "d"], "c", 2); // ["a", "b", "c", "d"] * @returns {Array} A new array with the item in the passed array index. */ declare function addItemToArray(array: T, item: T[number], index?: number): T; /** * Flattens a 2D array into a one-dimensional array. * @example * flatten2DArray([["a"], ["b"], ["c"]]); // ["a", "b", "c"] * * @returns {Array} A one-dimensional array. */ declare function flatten2DArray(array: T[][]): T[]; /** * Immutably reverses an array. * @example * reverseArray(["a", "b", "c"]); // ["c", "b", "a"] * @returns {Array} Reversed array. */ declare function reverseArray(array: T[]): T[]; //#endregion //#region src/types.d.ts /** * Shared type utilities used across Ariakit packages. * @module Type utilities */ /** * Any object. */ type AnyObject = Record; /** * Empty object. */ type EmptyObject = Record; /** * Any function. */ type AnyFunction = (...args: any) => any; /** * Workaround for variance issues. * @template T The type of the callback. */ type BivariantCallback = { bivarianceHack(...args: Parameters): ReturnType; }["bivarianceHack"]; /** * @template T The state type. */ type SetStateAction = T | BivariantCallback<(prevState: T) => T>; /** * The type of the `setState` function in `[state, setState] = useState()`. * @template T The type of the state. */ type SetState = BivariantCallback<(value: SetStateAction) => void>; /** * A boolean value or a callback that returns a boolean value. * @template T The type of the callback parameter. */ type BooleanOrCallback = boolean | BivariantCallback<(arg: T) => boolean>; /** * A string that will provide autocomplete for specific strings. * @template T The specific strings. */ type StringWithValue = T | (string & Record); /** * Transforms a type into a primitive type. * @template T The type to transform. * @example * // string * ToPrimitive<"a">; * // number * ToPrimitive<1>; */ type ToPrimitive = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends AnyFunction ? (...args: Parameters) => ReturnType : T; /** * Picks only the properties from a type that have a specific value. * @template T The type to pick from. * @template Value The value to pick. */ type PickByValue = { [K in keyof T as [Value] extends [T[K]] ? T[K] extends Value | undefined ? K : never : never]: T[K]; }; /** * Picks only the required properties from a type. * @template T The type to pick from. * @template P The properties to pick. */ type PickRequired = T & { [K in keyof T]: Pick, K>; }[P]; /** * Indicates the availability and type of interactive popup element, such as * menu or dialog, that can be triggered by an element. */ type AriaHasPopup = boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined; /** * All the WAI-ARIA 1.1 role attribute values from * https://www.w3.org/TR/wai-aria-1.1/#role_definitions */ type AriaRole = "alert" | "alertdialog" | "application" | "article" | "banner" | "button" | "cell" | "checkbox" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "dialog" | "directory" | "document" | "feed" | "figure" | "form" | "grid" | "gridcell" | "group" | "heading" | "img" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "navigation" | "none" | "note" | "option" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem" | (string & {}); //#endregion //#region src/dom.d.ts /** * It's `true` if it is running in a browser environment or `false` if it is not * (SSR). * @example * const title = canUseDOM ? document.title : ""; */ declare const canUseDOM: boolean; /** * Returns `element.ownerDocument || document`. */ declare function getDocument(node?: Window | Document | Node | null): Document; /** * Returns `element.ownerDocument.defaultView || window`. */ declare function getWindow(node?: Window | Document | Node | null): Window; /** * Returns `element.ownerDocument.activeElement`. */ declare function getActiveElement(node?: Node | null, activeDescendant?: boolean): HTMLElement | null; /** * Similar to `Element.prototype.contains`, but a little bit faster when * `element` is the same as `child`. * @example * contains( * document.getElementById("parent"), * document.getElementById("child") * ); */ declare function contains(parent: Node, child: Node): boolean; /** * Checks whether the given event target is an element. * * `event.target` and `event.relatedTarget` are `EventTarget`s, which aren't * necessarily elements — for example `window` or an `XMLHttpRequest` when an * event is dispatched programmatically. Calling `Element`-only methods such as * `hasAttribute` on those throws, so guard with this before treating them as * elements. When you only need a `Node` — for example to call `contains` — use * `isNode` instead. * * It tests `nodeType` rather than `instanceof Element` so that elements coming * from same-origin child frames (which `addGlobalEventListener` also listens * on) aren't wrongly rejected for belonging to a different realm. * @example * if (isElement(event.target)) { * event.target.hasAttribute("data-active"); * } */ declare function isElement(target: EventTarget | null | undefined): target is Element; /** * Checks whether the given event target is a node. * * Like `isElement`, but only requires the target to be a `Node` rather than an * element — useful before calling `contains`, which accepts any node. It still * rejects non-node `EventTarget`s (such as `window` or an `XMLHttpRequest`) * that would make `contains` throw. * @example * if (isNode(event.target)) { * contains(element, event.target); * } */ declare function isNode(target: EventTarget | null | undefined): target is Node; /** * Checks whether `element` is a frame element. */ declare function isFrame(element: Element): element is HTMLIFrameElement; /** * Checks whether `element` is a native HTML button element. * @example * isButton(document.querySelector("button")); // true * isButton(document.querySelector("input[type='button']")); // true * isButton(document.querySelector("div")); // false * isButton(document.querySelector("input[type='text']")); // false * isButton(document.querySelector("div[role='button']")); // false */ declare function isButton(element: { tagName: string; type?: string; }): boolean; /** * Checks if the element is visible or not. */ declare function isVisible(element: Element): boolean; /** * Check whether the given element is a text field, where text field is defined * by the ability to select within the input. * @example * isTextField(document.querySelector("div")); // false * isTextField(document.querySelector("input")); // true * isTextField(document.querySelector("input[type='button']")); // false * isTextField(document.querySelector("textarea")); // true */ declare function isTextField(element: Element): element is HTMLInputElement | HTMLTextAreaElement; /** * Check whether the given element is a text field or a content editable * element. */ declare function isTextbox(element: HTMLElement): boolean; /** * Returns the value of the text field or content editable element as a string. */ declare function getTextboxValue(element: HTMLElement): string; /** * Returns the start and end offsets of the selection in the element. */ declare function getTextboxSelection(element: HTMLElement): { start: number; end: number; }; /** * Returns the popup role from the element's role attribute, if it has one. */ declare function getPopupRole(element?: Element | null, fallback?: AriaHasPopup): AriaHasPopup; /** * Returns the item role based on the popup role. */ declare function getItemRoleByPopupRole(popupRole?: string | null): string | undefined; /** * Returns the item role attribute based on the popup's role. */ declare function getPopupItemRole(element?: Element | null, fallback?: AriaRole): string | undefined; /** * Calls `element.scrollIntoView()` if the element is hidden or partly hidden in * the viewport. */ declare function scrollIntoViewIfNeeded(element: Element, arg?: boolean | ScrollIntoViewOptions): void; /** * Returns the scrolling container element of a given element. */ declare function getScrollingElement(element?: Element | null): HTMLElement | Element | null; /** * Determines whether an element is hidden or partially hidden in the viewport. */ declare function isPartiallyHidden(element: Element): boolean; /** * SelectionRange only works on a few types of input. Calling * `setSelectionRange` on an unsupported input type may throw an error on * certain browsers. To avoid it, we check if its type supports SelectionRange * first. It will be a noop to non-supported types until we find a workaround. * * @see * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange */ declare function setSelectionRange(element: HTMLInputElement | HTMLTextAreaElement, ...args: Parameters): void; /** * Sort the items based on their DOM position. */ declare function sortBasedOnDOMPosition(items: T[], getElement: (item: T) => Element | null | undefined): T[]; //#endregion //#region src/events.d.ts /** * Event helpers for dispatching and interpreting browser events. * @module Event utilities */ /** * Returns `true` if `event` has been fired within a React Portal element. */ declare function isPortalEvent(event: Pick): boolean; /** * Returns `true` if `event.target` and `event.currentTarget` are the same. */ declare function isSelfTarget(event: Pick): boolean; /** * Checks whether the user event is triggering a page navigation in a new tab. */ declare function isOpeningInNewTab(event: Pick): boolean; /** * Checks whether the user event is triggering a download. */ declare function isDownloading(event: Pick): boolean; /** * Creates and dispatches an event. * @example * fireEvent(document.getElementById("id"), "blur", { * bubbles: true, * cancelable: true, * }); */ declare function fireEvent(element: Element, type: string, eventInit?: EventInit): boolean; /** * Creates and dispatches a blur event. * @example * fireBlurEvent(document.getElementById("id")); */ declare function fireBlurEvent(element: Element, eventInit?: FocusEventInit): boolean; /** * Creates and dispatches a focus event. * @example * fireFocusEvent(document.getElementById("id")); */ declare function fireFocusEvent(element: Element, eventInit?: FocusEventInit): boolean; /** * Creates and dispatches a keyboard event. * @example * fireKeyboardEvent(document.getElementById("id"), "keydown", { * key: "ArrowDown", * shiftKey: true, * }); */ declare function fireKeyboardEvent(element: Element, type: string, eventInit?: KeyboardEventInit): boolean; /** * Creates and dispatches a click event. * @example * fireClickEvent(document.getElementById("id")); */ declare function fireClickEvent(element: Element, eventInit?: PointerEventInit): boolean; /** * Checks whether the focus/blur event is happening from/to outside of the * container element. * @example * const element = document.getElementById("id"); * element.addEventListener("blur", (event) => { * if (isFocusEventOutside(event)) { * // ... * } * }); */ declare function isFocusEventOutside(event: Pick, container?: Element | null): boolean; /** * Returns the `inputType` property of the event, if available. */ declare function getInputType(event: Event | { nativeEvent: Event; }): string | undefined; /** * Checks whether the event is an input event. */ declare function isInputEvent(event: Event): event is InputEvent; /** * Runs a callback on the next animation frame, but before a certain event. */ declare function queueBeforeEvent(element: Element, type: string, callback: () => void, timeout?: number): () => void; declare function addGlobalEventListener(type: K, listener: (event: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions, scope?: Window): () => void; declare function addGlobalEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions, scope?: Window): () => void; //#endregion //#region src/focus.d.ts /** * Focus management helpers for focusable and tabbable elements. * @module Focus utilities */ /** * Checks whether `element` is focusable or not. * @example * isFocusable(document.querySelector("input")); // true * isFocusable(document.querySelector("input[tabindex='-1']")); // true * isFocusable(document.querySelector("input[hidden]")); // false * isFocusable(document.querySelector("input:disabled")); // false */ declare function isFocusable(element: Element): boolean; /** * Checks whether `element` is tabbable or not. * @example * isTabbable(document.querySelector("input")); // true * isTabbable(document.querySelector("input[tabindex='-1']")); // false * isTabbable(document.querySelector("input[hidden]")); // false * isTabbable(document.querySelector("input:disabled")); // false */ declare function isTabbable(element: Element | HTMLElement | HTMLInputElement): element is HTMLElement; /** * Returns all the focusable elements in `container`. */ declare function getAllFocusableIn(container: HTMLElement, includeContainer?: boolean): HTMLElement[]; /** * Returns all the focusable elements in the document. */ declare function getAllFocusable(includeBody?: boolean): HTMLElement[]; /** * Returns the first focusable element in `container`. */ declare function getFirstFocusableIn(container: HTMLElement, includeContainer?: boolean): HTMLElement | null; /** * Returns the first focusable element in the document. */ declare function getFirstFocusable(includeBody?: boolean): HTMLElement | null; /** * Returns all the tabbable elements in `container`, including the container * itself. */ declare function getAllTabbableIn(container: HTMLElement, includeContainer?: boolean, fallbackToFocusable?: boolean): HTMLElement[]; /** * Returns all the tabbable elements in the document. */ declare function getAllTabbable(fallbackToFocusable?: boolean): HTMLElement[]; /** * Returns the first tabbable element in `container`, including the container * itself if it's tabbable. */ declare function getFirstTabbableIn(container: HTMLElement, includeContainer?: boolean, fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the first tabbable element in the document. */ declare function getFirstTabbable(fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the last tabbable element in `container`, including the container * itself if it's tabbable. */ declare function getLastTabbableIn(container: HTMLElement, includeContainer?: boolean, fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the last tabbable element in the document. */ declare function getLastTabbable(fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the next tabbable element in `container`. */ declare function getNextTabbableIn(container: HTMLElement, includeContainer?: boolean, fallbackToFirst?: boolean, fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the next tabbable element in the document. */ declare function getNextTabbable(fallbackToFirst?: boolean, fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the previous tabbable element in `container`. * */ declare function getPreviousTabbableIn(container: HTMLElement, includeContainer?: boolean, fallbackToLast?: boolean, fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the previous tabbable element in the document. */ declare function getPreviousTabbable(fallbackToLast?: boolean, fallbackToFocusable?: boolean): HTMLElement | null; /** * Returns the closest focusable element. */ declare function getClosestFocusable(element?: HTMLElement | null): HTMLElement | null; /** * Checks if `element` has focus. Elements that are referenced by * `aria-activedescendant` are also considered. * @example * hasFocus(document.getElementById("id")); */ declare function hasFocus(element: Element): boolean; /** * Checks if `element` has focus within. Elements that are referenced by * `aria-activedescendant` are also considered. * @example * hasFocusWithin(document.getElementById("id")); */ declare function hasFocusWithin(element: Node | Element): boolean; /** * Focus on an element only if it's not already focused. */ declare function focusIfNeeded(element: HTMLElement): void; /** * Disable focus on `element`. */ declare function disableFocus(element: HTMLElement): void; /** * Makes elements inside container not tabbable. */ declare function disableFocusIn(container: HTMLElement, includeContainer?: boolean): void; /** * Restores tabbable elements inside container that were affected by * disableFocusIn. */ declare function restoreFocusIn(container: HTMLElement): void; /** * Focus on element and scroll into view. */ declare function focusIntoView(element: HTMLElement, options?: ScrollIntoViewOptions): void; //#endregion //#region src/misc.d.ts /** * Empty function. */ declare function noop(..._: any[]): any; /** * Compares two objects. * @example * shallowEqual({ a: "a" }, {}); // false * shallowEqual({ a: "a" }, { b: "b" }); // false * shallowEqual({ a: "a" }, { a: "a" }); // true * shallowEqual({ a: "a" }, { a: "a", b: "b" }); // false */ declare function shallowEqual(a?: AnyObject, b?: AnyObject): boolean; /** * Receives a `setState` argument and calls it with `currentValue` if it's a * function. Otherwise return the argument as the new value. * @example * applyState((value) => value + 1, 1); // 2 * applyState(2, 1); // 2 */ declare function applyState(argument: SetStateAction, currentValue: T | (() => T)): T; /** * Checks whether `arg` is an object or not. * @returns {boolean} */ declare function isObject(arg: any): arg is Record; /** * Checks whether `arg` is empty or not. * @example * isEmpty([]); // true * isEmpty(["a"]); // false * isEmpty({}); // true * isEmpty({ a: "a" }); // false * isEmpty(); // true * isEmpty(null); // true * isEmpty(undefined); // true * isEmpty(""); // true */ declare function isEmpty(arg: any): boolean; /** * Checks whether `arg` is an integer or not. * @example * isInteger(1); // true * isInteger(1.5); // false * isInteger("1"); // true * isInteger("1.5"); // false */ declare function isInteger(arg: any): boolean; /** * Checks whether `prop` is an own property of `obj` or not. */ declare function hasOwnProperty(object: T, prop: keyof any): prop is keyof T; /** * Receives functions as arguments and returns a new function that calls all. */ declare function chain(...fns: T[]): (...args: T extends AnyFunction ? Parameters : never) => void; /** * Returns a string with the truthy values of `args` separated by space. */ declare function cx(...args: Array): string | undefined; /** * Removes diacritics from a string. */ declare function normalizeString(str: string): string; /** * Omits specific keys from an object. * @example * omit({ a: "a", b: "b" }, ["a"]); // { b: "b" } */ declare function omit(object: T, keys: ReadonlyArray | K[]): Omit; /** * Picks specific keys from an object. * @example * pick({ a: "a", b: "b" }, ["a"]); // { a: "a" } */ declare function pick(object: T, paths: ReadonlyArray | K[]): Pick; /** * Returns the same argument. */ declare function identity(value: T): T; /** * Runs right before the next paint. */ declare function beforePaint(cb?: () => void): () => void; /** * Runs after the next paint. */ declare function afterPaint(cb?: () => void): () => void; /** * Logs a warning only once for each message and key. * @example * if (process.env.NODE_ENV !== "production") { * warnOnce("Warning"); * } */ declare function warnOnce(message: string, key?: object): void; /** * Asserts that a condition is true, otherwise throws an error. * @example * invariant( * condition, * process.env.NODE_ENV !== "production" && "Invariant failed" * ); */ declare function invariant(condition: any, message?: string | boolean): asserts condition; /** * Similar to `Object.keys` but returns a type-safe array of keys. */ declare function getKeys(obj: T): Array; /** * Checks whether a boolean event prop (e.g., hideOnInteractOutside) was * intentionally set to false, either with a boolean value or a callback that * returns false. */ declare function isFalsyBooleanCallback(booleanOrCallback?: boolean | ((...args: T) => boolean), ...args: T): boolean; /** * Checks whether something is disabled or not based on its props. */ declare function disabledFromProps(props: { disabled?: boolean; "aria-disabled"?: boolean | "true" | "false"; }): boolean; /** * Checks whether something is disabled or not based on its DOM attributes. */ declare function disabledFromElement(element: Element): boolean; /** * Removes undefined values from an object. */ declare function removeUndefinedValues(obj: T): T; /** * Returns the first value that is not `undefined`. */ declare function defaultValue(...values: T): DefaultValue; type DefaultValue = T extends [infer Head, ...infer Rest] ? Rest extends [] ? T[number] | Other : undefined extends Head ? DefaultValue> : Exclude : never; //#endregion //#region src/platform.d.ts /** * Browser and platform detection helpers. * @module Platform utilities */ /** * Detects if the device has touch capabilities. */ declare function isTouchDevice(): boolean; /** * Detects Apple device. */ declare function isApple(): boolean; /** * Detects Safari browser. */ declare function isSafari(): boolean; /** * Detects Firefox browser. */ declare function isFirefox(): boolean; /** * Detects Mac computer. */ declare function isMac(): boolean; //#endregion //#region src/undo.d.ts /** * Undo and redo manager utilities. * @module Undo utilities */ type Callback = void | (() => Callback | Promise); interface CreateUndoManagerOptions { limit?: number; } /** * Shared undo manager instance. */ declare const UndoManager: { canUndo: () => boolean; canRedo: () => boolean; undo: () => Promise; redo: () => Promise; execute: (callback: Callback, group?: string) => Promise; }; /** * Creates an undo manager with undo and redo stacks. */ declare function createUndoManager({ limit }?: CreateUndoManagerOptions): { canUndo: () => boolean; canRedo: () => boolean; undo: () => Promise; redo: () => Promise; execute: (callback: Callback, group?: string) => Promise; }; //#endregion export { AnyFunction, AnyObject, AriaHasPopup, AriaRole, BivariantCallback, BooleanOrCallback, EmptyObject, PickByValue, PickRequired, SetState, SetStateAction, StringWithValue, ToPrimitive, UndoManager, addGlobalEventListener, addItemToArray, afterPaint, applyState, beforePaint, canUseDOM, chain, contains, createUndoManager, cx, defaultValue, disableFocus, disableFocusIn, disabledFromElement, disabledFromProps, fireBlurEvent, fireClickEvent, fireEvent, fireFocusEvent, fireKeyboardEvent, flatten2DArray, focusIfNeeded, focusIntoView, getActiveElement, getAllFocusable, getAllFocusableIn, getAllTabbable, getAllTabbableIn, getClosestFocusable, getDocument, getFirstFocusable, getFirstFocusableIn, getFirstTabbable, getFirstTabbableIn, getInputType, getItemRoleByPopupRole, getKeys, getLastTabbable, getLastTabbableIn, getNextTabbable, getNextTabbableIn, getPopupItemRole, getPopupRole, getPreviousTabbable, getPreviousTabbableIn, getScrollingElement, getTextboxSelection, getTextboxValue, getWindow, hasFocus, hasFocusWithin, hasOwnProperty, identity, invariant, isApple, isButton, isDownloading, isElement, isEmpty, isFalsyBooleanCallback, isFirefox, isFocusEventOutside, isFocusable, isFrame, isInputEvent, isInteger, isMac, isNode, isObject, isOpeningInNewTab, isPartiallyHidden, isPortalEvent, isSafari, isSelfTarget, isTabbable, isTextField, isTextbox, isTouchDevice, isVisible, noop, normalizeString, omit, pick, queueBeforeEvent, removeUndefinedValues, restoreFocusIn, reverseArray, scrollIntoViewIfNeeded, setSelectionRange, shallowEqual, sortBasedOnDOMPosition, toArray, warnOnce }; //# sourceMappingURL=index.d.ts.map