UNPKG

device-navigation

Version:

Navigate HTML elements in two dimensions with non-pointer devices.

39 lines (38 loc) 1.32 kB
import { type NavEntry } from '../directives/nav-entry.js'; import { type Coords } from '../util/coords.js'; import { type NavTree, type NavTreeNode } from './nav-tree.js'; /** * Callback type for `walkNavTree`. * * @category Internal */ export type WalkNavTreeCallback = (params: WalkResult) => boolean; /** * Output from {@link walkNavTree}. * * @category Internal */ export type WalkResult = { ancestorChain: ReadonlyArray<WalkResult>; node: Readonly<NavTreeNode | NavTree>; nodeCoords: Readonly<Coords>; }; /** * Walk each node in the tree with a depth-first traversal. Walking stops if the callback returns * true. * * @category Internal * @returns The nav tree node that the callback returned `true` on, if any. Otherwise, `undefined`. */ export declare function walkNavTree( /** The tree to walk. */ tree: NavTree, /** The callback to call on each node. If this returns `true`, the walking stops. */ callback: WalkNavTreeCallback): WalkResult | undefined; /** * Finds the given {@link NavEntry} in the given {@link NavTree}. If it does not exist, error out. * * @category Internal * @throws Error if the {@link NavEntry} is not found in the {@link NavTree}. */ export declare function findNavTreeNodeByNavEntry(navTree: Readonly<NavTree>, navEntry: Readonly<NavEntry>): WalkResult;