/** * Transition algebra — ports of the XState `stateUtils` functions that relate * transitions to the configuration: event descriptor matching and candidate * lookup (`matchesEventDescriptor`, `getCandidates`), history resolution * (`resolveHistoryDefaultTransition`, `getEffectiveTargetStates`), the * transition domain and exit set (`getTransitionDomain`, `computeExitSet`), * conflict resolution (`removeConflictingTransitions`) and the entry set * (`computeEntrySet` with `addDescendantStatesToEnter` / * `addAncestorStatesToEnter`). Pure functions; the "no node is `null`" * convention of `configuration.ts` applies to the domain. */ import type { EventObject, MachineContext } from "../types/index.js"; import type { MachineState, StateNode, Transition } from "./model.js"; /** History node id -> nodes recorded when its parent was last exited. */ export type HistoryValue = MachineState["historyValue"]; /** * XState `matchesEventDescriptor`: exact match, the catch-all `"*"`, or a * partial `"prefix.*"` whose leading tokens equal the event's. Infix * wildcards never match (the normalizer rejects them anyway). */ export declare function matchesEventDescriptor(eventType: string, descriptor: string): boolean; /** * XState `getCandidates`: the transitions of `node` that may handle * `eventType` — the exact descriptor's list first, then the matching * wildcard descriptors from the most specific (longest) to the least, each * list in config order. Computed fresh on every call (like XState v5): the * work is a small filter/sort over the node's own descriptors, and a * per-(node, event type) memo would grow without bound for machines that * receive dynamically named events (StateNodes live as long as the * machine's model, typically a module-level singleton). */ export declare function getCandidates(node: StateNode, eventType: string): readonly Transition[]; export interface HistoryDefaultTransition { readonly target: readonly StateNode[]; /** True when the parent's `initial` transition was used (the parent then joins `statesForDefaultEntry`). */ readonly isParentInitial: boolean; } /** * XState `resolveHistoryDefaultTransition`: where a history node leads when * nothing was recorded — its own `target`, else the parallel parent itself, * else the compound parent's `initial` child. */ export declare function resolveHistoryDefaultTransition(historyNode: StateNode): HistoryDefaultTransition; /** * XState `getEffectiveTargetStates`: the targets with history nodes replaced * by their recorded nodes (or their default targets, recursively). * Deduplicated, in first-seen order. */ export declare function getEffectiveTargetStates(targets: readonly StateNode[] | null, historyValue: HistoryValue): StateNode[]; /** * XState `getTransitionDomain`: the node whose descendants are exited by the * transition. The source itself for internal transitions (`reenter: false` * and every target inside the source), else the least common ancestor of the * source and the effective targets. `null` ("no domain": everything, root * included, is exited and re-entered) for a root-sourced `reenter: true` * transition; the root when the LCA is missing otherwise (a target that is * the root itself). */ export declare function getTransitionDomain(transition: Transition, historyValue: HistoryValue): StateNode | null; /** * XState `computeExitSet`: every active descendant of each transition's * domain, plus the domain itself when the transition re-enters its own * source. Targetless transitions exit nothing. Insertion order (not yet * sorted; `exitStates` sorts by document order descending). */ export declare function computeExitSet(transitions: readonly Transition[], stateNodeSet: ReadonlySet>, historyValue: HistoryValue): StateNode[]; /** * XState `removeConflictingTransitions` (SCXML): when two enabled transitions * would exit overlapping sets, the one sourced from the deeper node wins; * otherwise the earlier one stays. Order of the survivors = order of first * acceptance. */ export declare function removeConflictingTransitions(enabledTransitions: readonly Transition[], stateNodeSet: ReadonlySet>, historyValue: HistoryValue): Transition[]; export interface EntrySet { /** Nodes to enter (unsorted; `enterStates` sorts by document order ascending). */ readonly statesToEnter: Set>; /** Nodes entered through their own `initial` (as opposed to a deep explicit target). */ readonly statesForDefaultEntry: Set>; } /** XState `computeEntrySet`: the nodes entered by the given (conflict-free) transitions. */ export declare function computeEntrySet(transitions: readonly Transition[], historyValue: HistoryValue): EntrySet;