import { Ref, proxy, ref, snapshot, subscribe } from "@destyler/store"; //#region src/deep-merge.d.ts export declare function deepMerge>(source: T, ...objects: (Partial | undefined | null)[]): T; export declare function deepMerge, U extends Record[]>(source: T, ...objects: (U[number] | undefined | null)[]): T & UnionToIntersection$1; type UnionToIntersection$1 = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; //#endregion //#region src/machine.d.ts declare const stoppingKey: unique symbol; declare const startingKey: unique symbol; declare const lifecycleVersionKey: unique symbol; declare const runVersionKey: unique symbol; declare const exitingStateKey: unique symbol; declare const stopPhaseKey: unique symbol; declare const pendingStopsKey: unique symbol; export declare class Machine { status: MachineStatus; readonly state: XState; private [stoppingKey]; private [startingKey]; private [stopPhaseKey]; private [pendingStopsKey]; private [lifecycleVersionKey]; private [runVersionKey]; private [exitingStateKey]; initialState: StateInfo | undefined; initialContext: TContext; id: string; type: MachineType; private activityEvents; private delayedEvents; private stateListeners; private doneListeners; private contextWatchers; private removeStateListener; private parent?; private children; private guardMap; private actionMap; private delayMap; private activityMap; private sync; options: MachineOptions; config: MachineConfig; constructor(config: MachineConfig, options?: MachineOptions); private get stateSnapshot(); getState(): XState; get contextSnapshot(): TContext; _created: () => void; start: (init?: StateInit) => this; private setupContextWatchers; stop: () => this | undefined; private stopStateListeners; private stopContextWatchers; private stopDelayedEvents; private stopActivities; /** * Function to send event to spawned child machine or actor */ sendChild: (evt: Event, to: string | ((ctx: TContext) => string)) => void; /** * Function to stop a running child machine or actor */ stopChild: (id: string) => void; removeChild: (id: string) => void; private stopChildren; private setParent; spawn: (src: MachineSrc, id?: string) => Machine; private stopActivity; private addActivityCleanup; private setState; /** * To used within side effects for React or Vue to update context */ setContext: (context: Partial> | undefined) => void; setOptions: (options: Partial>) => void; private getStateNode; private getNextStateInfo; private getAfterActions; /** * All `after` events leverage `setTimeout` and `clearTimeout`, * we invoke the `clearTimeout` on exit and `setTimeout` on entry. * * To achieve this, we split the `after` definition into `entry` and `exit` * functions and append them to the state's `entry` and `exit` actions */ private getDelayedEventActions; /** * A reference to the instance methods of the machine. * Useful when spawning child machines and managing the communication between them. */ private get self(); private get meta(); private get guardMeta(); /** * Function to executes defined actions. It can accept actions as string * (referencing `options.actions`) or actual functions. */ private executeActions; /** * Function to execute running activities and registers * their cleanup function internally (to be called later on when we exit the state) */ private executeActivities; /** * Normalizes the `every` definition to transition. `every` can be: * - An array of possible actions to run (we need to pick the first match based on guard) * - An object of intervals and actions */ private createEveryActivities; private setEvent; private performExitEffects; private performEntryEffects; private performTransitionEffects; /** * Performs all the requires side-effects or reactions when * we move from state A => state B. * * The Effect order: * Exit actions (current state) => Transition actions => Go to state => Entry actions (next state) */ private performStateChangeEffects; private determineTransition; /** * Function to send event to parent machine from spawned child */ sendParent: (evt: Event) => void; private log; /** * Function to send an event to current machine */ send: (evt: Event) => void; transition: (state: TState["value"] | StateInfo | null, evt: Event) => StateNode | undefined; subscribe: (listener: StateListener) => () => void; onDone: (listener: StateListener) => this; onTransition: (listener: StateListener) => this; get [Symbol.toStringTag](): string; getHydrationState(): StateInit; } export type MachineSrc = Machine | (() => Machine); export type AnyMachine = Machine; export declare function createMachine(config: MachineConfig, options?: MachineOptions): Machine; export declare function isMachine(value: any): value is AnyMachine; //#endregion //#region src/type.d.ts type Dict = Record; type MaybeArray = T | T[]; type VoidFunction = () => void; type IfEquals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B; type WritableKey = { [P in keyof T]: IfEquals<{ [Q in P]: T[P]; }, { -readonly [Q in P]: T[P]; }, P, never>; }[keyof T]; type Writable = Pick>; type Computed = Omit>; /** * Context types */ /** Combined context type with readonly computed properties */ type Context = V & Readonly; /** Computed context properties definition */ type TComputedContext = { [K in keyof Computed]: (ctx: T) => T[K]; }; /** User-provided context (only writable properties) */ type UserContext = Partial>; /** Context change listener callback */ type ContextListener = (context: TContext) => void; /** * Event types - can be either a string or object */ /** Base event object interface */ interface EventObject { type: string; } /** Event can be a type string or event object */ type Event = TEvent['type'] | TEvent; /** Event object with additional properties */ interface AnyEventObject extends EventObject { [key: string]: any; } /** Function to send events to the machine */ type XSend = (event: Event) => void; /** Event listener callback */ type EventListener = (event: TEvent) => void; /** Extract specific event type from union */ type ExtractEvent = K extends TEvent['type'] ? Extract : EventObject; /** * Expression types - actions and activities are expressions */ type Expression = (context: TContext, event: TEvent) => TReturn; /** Meta information passed to expressions */ interface Meta { state: XState; guards: Dict; send: XSend; self: XSelf; initialContext: TContext; initialState: string; getState: () => XState; getAction: (key: string) => ExpressionWithMeta; getGuard: (key: string) => GuardExpression; } /** Expression with access to meta information */ type ExpressionWithMeta = (context: TContext, event: TEvent, meta: Meta) => TReturn; /** * Action types */ /** Single action - can be string reference or function */ type Action = string | ExpressionWithMeta; /** Multiple actions - can include conditional actions */ type Actions = ChooseHelper | MaybeArray>; /** Pure actions without conditional logic */ type PureActions = MaybeArray>; /** Map of action names to implementations */ interface ActionMap { [action: string]: ExpressionWithMeta; } /** * Activity types */ /** Activity - long-running process with cleanup */ type Activity = string | ExpressionWithMeta; /** Multiple activities */ type Activities = MaybeArray>; /** Map of activity names to implementations */ interface ActivityMap { [activity: string]: ExpressionWithMeta; } /** * Transition types */ /** Transition definition with target, actions, and guards */ interface TransitionDefinition { /** Target state to transition to */ target?: TState['value'] | undefined; /** Actions to execute during transition */ actions?: Actions | undefined; /** Guard condition for the transition */ guard?: Guard | undefined; /** Whether this is an internal transition */ internal?: boolean | undefined; } /** Delay expression function */ type DelayExpression = Expression; /** Delay specification - string, number, or expression */ type Delay = string | number | DelayExpression; /** Map of delay names to implementations */ interface DelayMap { [delay: string]: number | DelayExpression; } /** Transition with delay specification for 'after' and 'every' */ type DelayedTransition = TransitionDefinition & { /** The time to delay the event, in milliseconds */ delay?: Delay | undefined; }; /** Collection of delayed transitions */ type DelayedTransitions = Record>> | Array>; /** Transition can be a string (target) or full definition object */ type Transition = TState['value'] | TransitionDefinition; /** Multiple transition possibilities with guards */ type Transitions = Transition | Array>; /** Map of event types to their transitions */ type TransitionDefinitionMap = { [K in TEvent['type']]?: TState['value'] | MaybeArray>> | undefined; }; /** * State node definition */ /** Configuration for a single state node */ interface StateNode { /** The type of this state node */ type?: 'final' | undefined; /** The tags for the state node */ tags?: MaybeArray | undefined; /** Activities to start on entry and stop on exit */ activities?: Activities | undefined; /** Event to transition mappings */ on?: TransitionDefinitionMap | undefined; /** Actions to execute on state entry */ entry?: Actions | undefined; /** Actions to execute on state exit */ exit?: Actions | undefined; /** Meta data associated with this state node */ meta?: string | Dict | undefined; /** Delayed transitions using setTimeout */ after?: DelayedTransitions | undefined; /** Interval-based actions using setInterval */ every?: Record> | Array<{ delay?: number | string | Expression; actions: Actions; guard?: Guard; }> | undefined; } /** * Guard types */ /** Meta information available to guard functions */ interface GuardMeta { state: Pick, 'matches'>; } /** Guard expression function */ type GuardExpression = (context: TContext, event: TEvent, guardMeta: GuardMeta) => TReturn; /** Guard helper for complex guard logic */ interface GuardHelper { predicate: (guards: Dict) => GuardExpression; } /** Helper for conditional action selection */ interface ChooseHelper { predicate: (guards: Dict) => GuardExpression | undefined>; } /** Guard can be string reference, function, or helper */ type Guard = string | GuardExpression | GuardHelper; /** Map of guard names to implementations */ interface GuardMap { [guard: string]: GuardExpression; } /** * State types */ /** Schema defining state structure */ interface StateSchema { value: string; tags?: string | undefined; } /** State initialization object */ interface StateInitObject { context?: TContext | undefined; value: TState['value'] | null; tags?: TState['tags'][] | undefined; } /** State initialization type */ type StateInit = StateInitObject; /** State change listener callback */ type StateListener = (state: XState) => void; /** Information about state transition */ interface StateInfo { /** Whether the state was re-entered */ reenter: boolean; /** Whether the state changed */ changed: boolean; /** The transition definition that caused this state */ transition: TransitionDefinition | undefined; /** The state node configuration */ stateNode: StateNode | undefined; /** The target state value */ target: TState['value']; } /** * Machine configuration types */ /** Main machine configuration */ interface MachineConfig { /** Actions to run after machine instantiation */ created?: Actions | undefined; /** Actions to run when machine starts */ entry?: Actions | undefined; /** Actions to run when machine stops */ exit?: Actions | undefined; /** Root level activities */ activities?: Activities | undefined; /** Unique machine identifier */ id?: string | undefined; /** Extended state data */ context?: Writable | undefined; /** Context change watchers */ watch?: { [K in keyof TContext]?: Actions; } | undefined; /** Computed properties */ computed?: Partial> | undefined; /** Initial state */ initial?: TState['value'] | undefined; /** State node configurations */ states?: Partial>> | undefined; /** Root level event transitions */ on?: TransitionDefinitionMap | undefined; } /** Current state representation */ interface XState { /** Current state value */ value: TState['value'] | null; /** Previous state value */ previousValue: TState['value'] | null; /** Current event */ event: TEvent; /** Previous event */ previousEvent: TEvent; /** Current context */ context: TContext; /** Whether machine is in final state */ done: boolean; /** Check if event can be sent */ can: (event: string) => boolean; /** Check if state matches given values */ matches: (...value: TState['value'][]) => boolean; /** Check if state has given tag */ hasTag: (value: TState['tags']) => boolean; /** Events that can be sent from current state */ nextEvents: string[]; /** Whether state has changed */ changed: boolean; /** Current state tags */ tags: TState['tags'][]; } /** * Machine options types */ /** Options for machine configuration */ interface MachineOptions { /** Enable debug logging */ debug?: boolean | undefined; /** Guard implementations */ guards?: GuardMap | undefined; /** Action implementations */ actions?: ActionMap | undefined; /** Delay implementations */ delays?: DelayMap | undefined; /** Activity implementations */ activities?: ActivityMap | undefined; /** Synchronous execution mode */ sync?: boolean | undefined; /** Custom comparison functions for context properties */ compareFns?: { [K in keyof TContext]?: CompareFn; } | undefined; } /** Options for machine hooks */ interface HookOptions { /** Synchronous execution mode */ sync?: boolean; /** Action implementations */ actions?: ActionMap | undefined; /** Initial state */ state?: StateInit | undefined; /** Initial context */ context?: UserContext | undefined; } /** Machine self-reference for advanced operations */ interface XSelf { /** Machine identifier */ id: string; /** Send event to this machine */ send: (event: Event) => void; /** Send event to parent machine */ sendParent: (evt: AnyEventObject) => void; /** Send event to child machine */ sendChild: (evt: Event, to: string | ((ctx: TContext) => string)) => void; /** Stop this machine */ stop: VoidFunction; /** Stop child machine */ stopChild: (id: string) => void; /** Stop activity */ stopActivity: (id: string) => void; /** Spawn new actor */ spawn: (src: T | (() => T), id?: string) => T; /** Current state */ state: XState; /** Initial context */ initialContext: TContext; /** Initial state */ initialState: string; } /** Machine status enumeration */ export declare enum MachineStatus { NotStarted = "Not Started", Running = "Running", Stopped = "Stopped" } /** Built-in action types */ export declare enum ActionTypes { Start = "machine.start", Stop = "machine.stop", Created = "machine.created", Init = "machine.init" } /** Machine type enumeration */ export declare enum MachineType { Machine = "machine", Actor = "machine.actor" } /** Comparison function type */ type CompareFn = (prev: T, next: T) => boolean; type AnyFunction = (...args: any[]) => any; type ReturnTypeOrValue = T extends AnyFunction ? ReturnType : T; type StateFrom = ReturnTypeOrValue extends (infer R) ? R extends Machine ? XState : never : never; type ContextFrom = ReturnTypeOrValue extends (infer R) ? (R extends Machine ? TContext : never) : never; type EventFrom = ReturnTypeOrValue extends (infer R) ? (R extends Machine ? TEvent : never) : never; interface ContextRef { current: T | undefined; } //#endregion //#region src/guard-utils.d.ts declare function or(...conditions: Array>): GuardHelper; declare function and(...conditions: Array>): GuardHelper; declare function not(condition: Guard): GuardHelper; declare function stateIn(...values: TState['value'][]): GuardExpression; export declare const guards: { or: typeof or; and: typeof and; not: typeof not; stateIn: typeof stateIn; }; export declare function choose(actions: Array<{ guard?: Guard; actions: PureActions; }>): ChooseHelper; //#endregion //#region src/merge-props.d.ts interface Props { [key: string]: any; } type TupleTypes = T[number]; type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; export declare function mergeProps(...args: T[]): UnionToIntersection>; //#endregion export { type Action, type ActionMap, type Actions, type Activities, type Activity, type ActivityMap, type AnyEventObject, type ChooseHelper, type Context, type ContextFrom, type ContextListener, type ContextRef, type Delay, type DelayExpression, type DelayMap, type DelayedTransition, type DelayedTransitions, type Event, type EventFrom, type EventListener, type EventObject, type ExtractEvent, type Guard, type GuardExpression, type GuardHelper, type GuardMap, type GuardMeta, type HookOptions, type MachineConfig, type MachineOptions, type Meta, type PureActions, type Ref, type StateFrom, type StateInfo, type StateInit, type StateInitObject, type StateListener, type StateNode, type StateSchema, type TComputedContext, type Transition, type TransitionDefinition, type TransitionDefinitionMap, type Transitions, type UserContext, type XSelf, type XSend, type XState, proxy, ref, snapshot, subscribe };