//#region src/types.d.ts /** * A transition target — either a state name or an object with target and guard. */ type TransitionConfig = TState | { target: TState; guard: (payload?: unknown) => boolean; }; /** * State definition — maps event names to transition configs. */ interface StateConfig { on?: Partial>>; } /** * Machine definition — initial state and state configs. */ interface MachineConfig { initial: TState; states: Record>; } /** * Event object passed to listeners. */ interface MachineEvent { type: TEvent; payload?: unknown; } /** * Callback for onEnter — receives the event that caused the transition. */ type EnterCallback = (event: MachineEvent) => void; /** * Callback for onTransition — receives from state, to state, and the event. */ type TransitionCallback = (from: TState, to: TState, event: MachineEvent) => void; /** * The machine instance returned by `createMachine()`. */ interface Machine { /** Read current state — reactive in effects/computeds/JSX */ (): TState; /** Send an event to trigger a transition */ send: (event: TEvent, payload?: unknown) => void; /** Check if the machine is in one of the given states — reactive */ matches: (...states: TState[]) => boolean; /** Check if an event would trigger a valid transition from current state */ can: (event: TEvent) => boolean; /** Get all valid events from the current state — reactive */ nextEvents: () => TEvent[]; /** Reset to initial state */ reset: () => void; /** Register a callback for when the machine enters a specific state */ onEnter: (state: TState, callback: EnterCallback) => () => void; /** Register a callback for any state transition */ onTransition: (callback: TransitionCallback) => () => void; /** Remove all listeners and clean up */ dispose: () => void; } /** Extract state names from a machine config */ type InferStates = T extends { states: Record; } ? S & string : never; /** Extract event names from a machine config */ type InferEvents = T extends { states: Record>; }>; } ? E & string : never; //#endregion //#region src/machine.d.ts /** * Create a reactive state machine — a constrained signal with type-safe transitions. * * The returned instance is callable (reads like a signal) and exposes * `send()`, `matches()`, `can()`, and listeners for state changes. * * @param config - Machine definition with initial state and state configs * @returns A reactive machine instance * * @example * ```tsx * const machine = createMachine({ * initial: 'idle', * states: { * idle: { on: { FETCH: 'loading' } }, * loading: { on: { SUCCESS: 'done', ERROR: 'error' } }, * done: {}, * error: { on: { RETRY: 'loading' } }, * }, * }) * * machine() // 'idle' * machine.send('FETCH') * machine() // 'loading' * * // Reactive in JSX * {() => machine.matches('loading') && } * ``` */ declare function createMachine>(config: TConfig): Machine, InferEvents>; //#endregion export { type EnterCallback, type InferEvents, type InferStates, type Machine, type MachineConfig, type MachineEvent, type StateConfig, type TransitionCallback, type TransitionConfig, createMachine }; //# sourceMappingURL=index2.d.ts.map