import { a as IsolateStatus, i as TIsolate, n as IsolateKey, o as IsolateKeys, r as IsolatePayload, t as Isolate } from "./Isolate-C-a7xY5w.cjs";
import { t as IsolateSerializer } from "./IsolateSerializer-CbPmwndf.cjs";
import * as vest_utils0 from "vest-utils";
import { BusType, CB, DynamicValue, Maybe, Nullable, Nullish, OneOrMoreOf, Result, TinyState } from "vest-utils";

//#region rolldown:runtime
//#endregion
//#region src/RuntimeEvents.d.ts
type RuntimeEvents = {
  ASYNC_ISOLATE_DONE: TIsolate;
  ISOLATE_DONE: TIsolate;
  ISOLATE_ENTER: TIsolate;
  ISOLATE_PENDING: TIsolate;
  ISOLATE_RECONCILED: TIsolate;
};
//#endregion
//#region src/Reconciler.d.ts
interface IReconciler<I = any> {
  (currentNode: I, historyNode: I): Nullable<I>;
}
declare class Reconciler {
  /**
   * Reconciles the current isolate with the history isolate.
   * If the current isolate is of a different type than the history isolate,
   * the current isolate is returned.
   * Otherwise, the reconciler function is called to determine the next isolate.
   * If the reconciler function returns null or undefined, the base reconciler is used.
   * If no history isolate exists, the current isolate is returned.
   * @param node The current isolate to reconcile.
   * @returns The next isolate after reconciliation.
   */
  static reconcile(node: TIsolate): TIsolate;
  static dropNextNodesOnReorder<I extends TIsolate>(reorderLogic: (newNode: I, prevNode: Maybe<TIsolate>) => boolean, newNode: I, prevNode: Maybe<TIsolate>): boolean;
  static handleIsolateNodeWithKey<I extends TIsolate>(node: TIsolate, revoke: ((node: I) => boolean) | false): TIsolate;
}
declare namespace IsolateWalker_d_exports {
  export { closest, closestExists, every, find, findAll, findClosest, has, mapFirst, pluck, reduce, some, walk };
}
type VisitOnlyPredicate = (isolate: TIsolate) => boolean;
/**
 * Walks the isolate tree starting from the given node.
 * @param startNode - The starting node for the traversal.
 * @param callback - The callback function to be called for each visited node.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 */
declare function walk(startNode: TIsolate, callback: (isolate: TIsolate) => Result<void>, visitOnly?: VisitOnlyPredicate): Result<void>;
/**
 * Reduces the isolate tree to a single value.
 * @param startNode - The starting node for the traversal.
 * @param callback - The reducer function.
 * @param initialValue - The initial value for the accumulator.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 * @returns The final accumulated value.
 */
declare function reduce<T>(startNode: TIsolate, callback: (acc: T, isolate: TIsolate) => Result<T>, initialValue: T, visitOnly?: VisitOnlyPredicate): T;
/**
 * Checks if any node in the tree satisfies the predicate.
 * @param startNode - The starting node for the traversal.
 * @param predicate - The predicate function to test each node.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 * @returns True if any node satisfies the predicate, false otherwise.
 */
declare function some(startNode: TIsolate, predicate: (node: TIsolate) => boolean, visitOnly?: VisitOnlyPredicate): boolean;
/**
 * Checks if the tree contains a node that matches the predicate.
 * @param startNode - The starting node for the traversal.
 * @param match - The predicate function to match nodes.
 * @returns True if a matching node is found, false otherwise.
 */
declare function has(startNode: TIsolate, match: VisitOnlyPredicate): boolean;
/**
 * Traverses up the tree to find the closest ancestor that satisfies the predicate,
 * then returns the first direct descendant of that ancestor that satisfies the predicate.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match.
 * @returns The found node or null.
 */
declare function findClosest<I extends TIsolate = TIsolate>(startNode: TIsolate, predicate: (node: TIsolate) => boolean): Nullable<I>;
/**
 * Finds the first node in the tree that satisfies the predicate.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 * @returns The found node or null.
 */
declare function find(startNode: TIsolate, predicate: (node: TIsolate) => boolean, visitOnly?: VisitOnlyPredicate): Nullable<TIsolate>;
/**
 * Finds all nodes in the tree that satisfy the predicate.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 * @returns An array of found nodes.
 */
declare function findAll(startNode: TIsolate, predicate: (node: TIsolate) => boolean, visitOnly?: VisitOnlyPredicate): TIsolate[];
/**
 * Checks if every node in the tree satisfies the predicate.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 * @returns True if all nodes satisfy the predicate, false otherwise.
 */
declare function every(startNode: TIsolate, predicate: (node: TIsolate) => boolean, visitOnly?: VisitOnlyPredicate): boolean;
/**
 * Removes nodes from the tree that satisfy the predicate.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match nodes to remove.
 * @param visitOnly - Optional predicate to filter which nodes to visit.
 */
declare function pluck(startNode: TIsolate, predicate: (node: TIsolate) => boolean, visitOnly?: VisitOnlyPredicate): void;
/**
 * Finds the closest ancestor of the startNode that satisfies the predicate.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match.
 * @returns The found ancestor or null.
 */
declare function closest<I extends TIsolate = TIsolate>(startNode: TIsolate, predicate: (node: TIsolate) => boolean): Nullable<I>;
/**
 * Checks if an ancestor satisfying the predicate exists.
 * @param startNode - The starting node.
 * @param predicate - The predicate to match.
 * @returns True if such an ancestor exists, false otherwise.
 */
declare function closestExists(startNode: TIsolate, predicate: (node: TIsolate) => boolean): boolean;
/**
 * Traverses the tree and returns the first non-nullish value returned by the callback.
 * It optimizes traversal by only visiting nodes that have pending isolates or are pending themselves.
 */
declare function mapFirst<T>(startNode: TIsolate, callback: (isolate: TIsolate, breakout: (value: T) => void) => void): T | null;
//#endregion
//#region src/Orchestrator/RuntimeStates.d.ts
declare enum RuntimeState {
  PENDING = "PENDING",
  STABLE = "STABLE",
}
//#endregion
//#region src/VestRuntime.d.ts
type CTXType = StateRefType & {
  historyNode: Nullable<TIsolate>;
  runtimeNode: Nullable<TIsolate>;
  runtimeRoot: Nullable<TIsolate>;
  stateRef: StateRefType;
};
/**
 * The state reference type for the Vest runtime.
 * Holds all mutable state for the runtime instance.
 */
type StateRefType = {
  Bus: BusType<RuntimeEvents>;
  appData: Record<string, any>;
  historyRoot: TinyState<Nullable<TIsolate>>;
  Reconciler: IReconciler;
  implicitOnlyNodes: Set<TIsolate>;
};
/**
 * Retrieves the current runtime state (e.g., STABLE, PENDING).
 */
declare function useRuntimeState(): RuntimeState;
/**
 * Checks if the runtime is currently stable (no pending tests).
 */
declare function useIsStable(): boolean;
/**
 * Retrieves the application-specific data stored in the runtime.
 */
declare function useXAppData<T = object>(): T;
/**
 * Creates a new state reference for such as the history root, pending isolates, and the current runtime state.
 */
declare function createRef(Reconciler: IReconciler, setter: DynamicValue<Record<string, any>>): StateRefType;
/**
 * Dispatches a runtime event to the internal Bus.
 * This is used to trigger state changes and notifications.
 */
declare function dispatch<T extends keyof RuntimeEvents>(event: RuntimeEvents[T] extends void ? {
  type: T;
  payload?: void;
} : {
  type: T;
  payload: RuntimeEvents[T];
}): void;
/**
 * Registers an isolate as pending.
 * This is used to track async tests and other async operations.
 */
declare function registerPending(isolate: TIsolate): void;
/**
 * Removes an isolate from the pending set.
 * This is used when an async test or operation completes.
 */
declare function removePending(isolate: TIsolate): void;
/**
 * Persists the current runtime context to a callback function.
 * This allows the callback to be executed later (e.g. in an async operation)
 * while still having access to the correct runtime context.
 */
declare function persist<T extends (...args: any[]) => any>(cb: T): T;
/**
 * Retrieves the history root state.
 */
declare function useHistoryRoot(): [value: Nullable<TIsolate>, setValue: (next: Nullable<TIsolate> | vest_utils0.CB<Nullable<TIsolate>, [prev: Nullable<TIsolate>]>) => void, resetValue: () => void];
/**
 * Sets the history root for the runtime.
 * This is used to hydrate the runtime with previous results.
 */
declare function useSetHistoryRoot(history: TIsolate): void;
/**
 * Retrieves the current cursor position within the active isolate.
 */
declare function useCurrentCursor(): number;
/**
 * Adds a child isolate to the current isolate and sets the parent-child relationship.
 */
declare function useSetNextIsolateChild(child: TIsolate): void;
/**
 * Returns the available root isolate.
 * If a runtime root exists (i.e. we are currently running a suite), it returns that.
 * Otherwise, it returns the history root (i.e. the result of the last run).
 */
declare function useAvailableRoot<I extends TIsolate = TIsolate>(): I;
/**
 * Checks whether a specific key is heavily focused out.
 */
declare function useIsFocusedOut(key?: string): boolean;
declare function hasImplicitOnly(): boolean;
/**
 * Resets the history root.
 */
declare function reset(): void;
declare const RuntimeApi: {
  Run: <R>(value: Partial<CTXType>, fn: () => R) => R;
  createRef: typeof createRef;
  dispatch: typeof dispatch;
  hasImplicitOnly: typeof hasImplicitOnly;
  persist: typeof persist;
  registerPending: typeof registerPending;
  removePending: typeof removePending;
  reset: typeof reset;
  useAvailableRoot: typeof useAvailableRoot;
  useCurrentCursor: typeof useCurrentCursor;
  useHistoryRoot: typeof useHistoryRoot;
  useIsFocusedOut: typeof useIsFocusedOut;
  useIsStable: typeof useIsStable;
  useRuntimeState: typeof useRuntimeState;
  useSetHistoryRoot: typeof useSetHistoryRoot;
  useSetNextIsolateChild: typeof useSetNextIsolateChild;
  useXAppData: typeof useXAppData;
};
//#endregion
//#region src/Isolate/IsolateInspector.d.ts
declare class IsolateInspector {
  static at(isolate: Nullable<TIsolate>, at: number): Nullable<TIsolate>;
  static cursor(isolate: Nullable<TIsolate>): number;
  static canReorder<I extends TIsolate>(isolate: Nullable<I>): boolean;
  static allowsReorder<I extends Record<any, any>>(isolate: Nullable<I>): boolean;
  static usesKey(isolate: Nullable<TIsolate>): boolean;
  static getChildByKey(isolate: Nullable<TIsolate>, key: string): Nullable<TIsolate>;
  static getStatus(isolate: Nullable<TIsolate>): IsolateStatus;
  static statusEquals(isolate: Nullable<TIsolate>, status: IsolateStatus): boolean;
  static isPending(isolate: Nullable<TIsolate>): boolean;
  static isHasPending(isolate: Nullable<TIsolate>): boolean;
  static hasPending(isolate: Nullable<TIsolate>): boolean;
  static hasActiveChildren(isolate: Nullable<TIsolate>): boolean;
  static getParent(isolate: Nullable<TIsolate>): Nullable<TIsolate>;
}
//#endregion
//#region src/Isolate/IsolateMutator.d.ts
declare class IsolateMutator {
  static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate;
  static saveOutput(isolate: TIsolate, output: any): TIsolate;
  static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate;
  static addChild(isolate: TIsolate, child: TIsolate): void;
  static removeChild(isolate: TIsolate, node: TIsolate): void;
  static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void;
  static slice(isolate: TIsolate, at: number): void;
  static setData(isolate: TIsolate, data: any): void;
  static abort(isolate: TIsolate, reason?: string): void;
  static setStatus(isolate: TIsolate, status: IsolateStatus, payload?: any): Result<IsolateStatus, string>;
  static setPending(isolate: TIsolate): void;
  static setHasPending(isolate: TIsolate): Result<IsolateStatus, string>;
  static setDone(isolate: TIsolate): void;
}
declare namespace Bus_d_exports {
  export { useBus, useEmit, usePrepareEmitter };
}
declare function useBus<E extends Record<string, any> = RuntimeEvents>(): BusType<E>;
declare function useEmit<E extends Record<string, any> = RuntimeEvents, T extends keyof E = keyof E>(event: T, ...args: E[T] extends void ? [payload?: E[T]] : [payload: E[T]]): void;
declare function useEmit<_E extends Record<string, any> = RuntimeEvents>(): (event: string, data?: any) => void;
declare function usePrepareEmitter<E extends Record<string, any> = RuntimeEvents, T extends keyof E = keyof E>(event: T): (arg: E[T]) => void;
declare namespace IsolateSelectors_d_exports {
  export { isIsolateType, isSameIsolateIdentity, isSameIsolateType };
}
declare function isIsolateType<I extends TIsolate>(node: Maybe<TIsolate>, type: string): node is I;
declare function isSameIsolateType<A extends TIsolate, B extends TIsolate>(a: A, b: B): boolean;
declare function isSameIsolateIdentity<A extends TIsolate, B extends TIsolate>(a: A, b: B): boolean;
//#endregion
//#region src/Isolate/IsolateStateMachine.d.ts
declare const IsolateStateMachine: vest_utils0.TStateMachineApi<IsolateStatus | "*", string>;
declare namespace IsolateRegistry_d_exports {
  export { RegistryCategoryConfig, RegistryIndex, useClearRegistry, useGetFromRegistry, useHasFromRegistry, useRemoveFieldFromRegistry, useUpdateRegistry };
}
/**
 * A registry index, mapping group keys (like field names) to sets of isolates.
 */
type RegistryIndex = Map<string, Set<TIsolate>>;
/**
 * Configuration for a registry category.
 */
type RegistryCategoryConfig = {
  predicate: (isolate: TIsolate) => boolean;
  getKey: (isolate: TIsolate) => string;
};
/**
 * Updates the registration of an isolate in all relevant indices based on provided predicates.
 *
 * @param isolate - The isolate node to update.
 * @param predicates - A record of category keys and their corresponding predicate configurations.
 */
declare function useUpdateRegistry(isolate: TIsolate, predicates: Record<string, RegistryCategoryConfig>): void;
/**
 * Retrieves isolates from the registry based on a category and an optional key.
 */
declare function useGetFromRegistry(category: string, key?: string): Set<TIsolate>;
/**
 * Checks if the registry contains any isolates for a given category and optional key.
 */
declare function useHasFromRegistry(category: string, key?: string): boolean;
/**
 * Removes all entries for a specific key from the registry.
 */
declare function useRemoveFieldFromRegistry(key: string): void;
/**
 * Clears all registry entries from the root isolate.
 */
declare function useClearRegistry(root: TIsolate): void;
//#endregion
//#region src/Isolate/IsolateReorderable.d.ts
declare function IsolateReorderable<Payload extends Record<string, any>>(callback: CB, type?: string, payload?: Payload): TIsolate<Payload & {
  allowReorder: true;
}>;
//#endregion
//#region src/Isolate/IsolateTransient.d.ts
/**
 * Creates a transient isolate.
 *
 * Transient isolates are isolates that:
 * 1. Do not persist in the history tree.
 * 2. Are not reconciled with previous runs.
 * 3. Do not appear in the serialized suite dump.
 * 4. Do not interfere with the index of their siblings (they are skipped by the reconciler).
 *
 * This is useful for "structural" isolates that are used for control flow or grouping
 * but do not hold state that needs to be preserved between runs, such as `focused` (skip/only) isolates.
 */
declare function IsolateTransient<Payload extends IsolatePayload>(callback: CB, type?: string, payload?: Payload): TIsolate<Payload>;
//#endregion
//#region src/Isolate/IsolateFocused.d.ts
declare enum FocusModes {
  SKIP = "skip",
  ONLY = "only",
}
type FocusMatchExclusion = Maybe<OneOrMoreOf<string>>;
type TIsolateFocused = TIsolate<IsolateFocusedPayload>;
type IsolateFocusedPayload = {
  focusMode: FocusModes;
  match: FocusMatchExclusion;
  matchAll: boolean;
};
/**
 * Creates a focused isolate.
 * Focused isolates are transient because they only affect the current run
 * and do not need to be preserved in history or appearing in the suite result.
 */
declare function IsolateFocused(focusMode: FocusModes, match?: true | FocusMatchExclusion): TIsolateFocused | undefined;
declare class FocusSelectors {
  static isSkipFocused(focus: Nullish<TIsolateFocused>, fieldName?: string): boolean;
  static isOnlyFocused(focus: Nullish<TIsolateFocused>, fieldName?: string): boolean;
  static isIsolateFocused(isolate: TIsolate): isolate is TIsolateFocused;
}
//#endregion
export { Bus_d_exports as Bus, FocusModes, FocusSelectors, type IReconciler, Isolate, IsolateFocused, IsolateInspector, type IsolateKey, IsolateKeys, IsolateMutator, IsolateRegistry_d_exports as IsolateRegistry, IsolateReorderable, IsolateSelectors_d_exports as IsolateSelectors, IsolateSerializer, IsolateStateMachine, IsolateStatus, IsolateTransient, Reconciler, type RegistryCategoryConfig, type RegistryIndex, type RuntimeEvents, type TIsolate, type TIsolateFocused, RuntimeApi as VestRuntime, IsolateWalker_d_exports as Walker };
//# sourceMappingURL=vestjs-runtime.d.cts.map