/** * Pure queries over the state node tree — ports of the XState `stateUtils` * helpers that do not depend on a transition or a history value * (`isAtomicStateNode`, `getChildren`, `getProperAncestors`, `isDescendant`, * `findLeastCommonAncestor`, `getInitialStateNodes`, `getAllStateNodes`, * `isInFinalState`, ...). No state, no side effects. * * One convention differs from XState (spec 3.4): "no node" is `null`, never * `undefined`. XState's root has `parent === undefined`, so * `isDescendant(node, undefined)` is true for every node and * `getProperAncestors(node, undefined)` reaches the root; our root has * `parent: null` and the helpers below reproduce exactly that behaviour for * `null`. */ import type { EventObject, MachineContext } from "../types/index.js"; import type { StateNode } from "./model.js"; /** XState `isAtomicStateNode`: leaves of the tree, i.e. `atomic` and `final` nodes. */ export declare function isAtomicStateNode(node: StateNode): boolean; export declare function isHistoryNode(node: StateNode): boolean; /** XState `getChildren`: children in document order, history nodes excluded. */ export declare function getChildren(node: StateNode): StateNode[]; /** XState `getHistoryNodes`: the history children of a node, in document order. */ export declare function getHistoryNodes(node: StateNode): StateNode[]; /** * XState `getProperAncestors`: the ancestors of `node` from its parent up to, * but excluding, `toNode`. With `toNode === null` every ancestor up to and * including the root is returned; `toNode === node` yields `[]`. */ export declare function getProperAncestors(node: StateNode, toNode: StateNode | null): StateNode[]; /** * XState `isDescendant`: strict descendant test (`isDescendant(a, a)` is * false). `ancestor === null` means "the virtual parent of the root", so it * matches every node including the root. */ export declare function isDescendant(node: StateNode, ancestor: StateNode | null): boolean; /** * XState `findLeastCommonAncestor`: the closest proper ancestor of the first * node that every other node descends from. `null` when there is none — which * happens when the root itself is among the nodes (the root descends from * nothing). */ export declare function findLeastCommonAncestor(nodes: readonly StateNode[]): StateNode | null; /** * XState `getInitialStateNodes`: `node` itself plus the nodes reached by * following `initial` through compound nodes and every region of parallel * nodes. Insertion order = visiting order (node before its descendants). */ export declare function getInitialStateNodes(node: StateNode): Set>; /** XState `getInitialStateNodesWithTheirAncestors`: `getInitialStateNodes(node)` plus the ancestors below `node`. */ export declare function getInitialStateNodesWithTheirAncestors(node: StateNode): Set>; /** * XState `getAllStateNodes`: completes a (possibly partial) node set into a * full configuration — compound nodes without an active child and parallel * regions that are missing get their initial descendants, then every ancestor * is added. A complete configuration comes back unchanged (same order); the * set is iterated while it grows, exactly like the original. */ export declare function getAllStateNodes(stateNodes: Iterable>): Set>; /** * XState `getAdjList`: parent -> active children, children in the iteration * order of `stateNodes`. Every node of the input gets an entry (possibly * empty), which is how `getValueFromAdj` tells an active leaf apart from an * absent one. */ export declare function getAdjacencyList(stateNodes: Iterable>): Map, StateNode[]>; /** * XState `isInFinalState`: a compound node is final when one of its `final` * children is active; a parallel node when every region is; a leaf when it is * itself `final`. The node's own membership in the set is not checked. */ export declare function isInFinalState(stateNodeSet: ReadonlySet>, node: StateNode): boolean; /** XState `hasIntersection`: do the two collections share an element? */ export declare function hasIntersection(first: Iterable, second: Iterable): boolean; /** XState `areStateNodeCollectionsEqual`: same members, order ignored. */ export declare function areStateNodeCollectionsEqual(previous: ReadonlySet>, next: ReadonlySet>): boolean; /** The `initial` child of a compound node; the model guarantees its presence. */ export declare function getInitialChild(node: StateNode): StateNode;