/** * Tree traversal utilities using the simplest Tree Node representation. While traversing descendant nodes it support two modalities (child first / parent first) and several policies to break the iteration. * * TODO: test */ export interface Node { childNodes?: Node[]; parentNode?: Node; } export declare function visitChildren(n: T, v: (c: T) => void): void; export declare function mapChildren(n: N, v: (c: N) => T): T[]; export declare function findChildren(n: T, p: NodePredicate): T | undefined; export declare function filterChildren(n: Node, p: NodePredicate): T[]; /** * @param getChildrenMode if true it will use `node.getChildren()` o obtain children instead of default * behavior that is using `node.forEachChild`. * @param children if caller already have called getChildren he can pass it here so this call is faster. */ export declare function getChildIndex(node: Node, children?: Node[] | undefined): number; /** */ export declare function getNextSibling(node: Node): Node | undefined; /** */ export declare function getSiblings(node: Node, getChildrenMode?: boolean): Node[]; /** */ export declare function getPreviousSibling(node: Node): Node | undefined; export declare function visitAncestors(n: T, v: Visitor, o?: {}): boolean; export declare function findAncestor(n: T, p: NodePredicate, o?: {}): T | undefined; export declare function findRootElement(n: T): T | undefined; export declare function filterAncestors(n: T, p: NodeSimplePredicate, o?: VisitorOptions): T[]; export declare type Visitor = (n: T) => boolean; /** * settings for visitDescendants regarding visiting order and visit interruption modes. */ export interface VisitorOptions { childrenFirst?: boolean; /** * if a descendant visitor returned true, we stop visiting and signal up */ breakOnDescendantSignal?: boolean; /** * no matter if visitor returns true for a node, it will still visit its descendants and then break the chain */ visitDescendantsOnSelfSignalAnyway?: boolean; andSelf?: boolean; } /** * Visit node's descendants until the visitor function return true or there are no more. In the first * different modes on which visiting the rest of descenda|nts or Ancestors are configurable through the * options. By default, first the parent is evaluated which is configurable configurable with * [[[VisitorOptions.childrenFirst]] * */ export declare function visitDescendants(n: T, v: Visitor, o?: VisitorOptions, inRecursion?: boolean): boolean; export declare type NodeSimplePredicate = (n: T, i?: number, a?: T[]) => boolean; export declare type NodeKindPredicate = (n: T, i?: number, a?: T[]) => n is T; export declare type NodePredicate = NodeSimplePredicate | (NodeKindPredicate); export declare function filterDescendants(n: T, p: NodePredicate, o?: VisitorOptions): T[]; export declare function mapDescendants(n: T, p: (p: T) => V, o?: VisitorOptions): V[]; export declare function findDescendant(n: T, p: NodePredicate, o?: VisitorOptions): T | undefined; /** * Gets given node's Ancestors in order from node.parent to top most one . */ export declare function getAncestors(node: T | undefined): T[]; /** * Get the distance from given node to its Ancestor . */ export declare function getDistanceToAncestor(node?: T, ancestor?: T): number;