xstate 5.0.0-beta.21 → 5.0.0-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.js +1 -1
- package/actions/dist/xstate-actions.development.cjs.js +1 -1
- package/actions/dist/xstate-actions.development.esm.js +1 -1
- package/actions/dist/xstate-actions.esm.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.cjs.js +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/{actions-a95d2e66.development.cjs.js → actions-4b70fc8d.development.cjs.js} +38 -20
- package/dist/{actions-c619a105.cjs.js → actions-8f2e997e.cjs.js} +38 -20
- package/dist/{actions-49f0501e.development.esm.js → actions-d4305983.development.esm.js} +36 -20
- package/dist/{actions-5039c951.esm.js → actions-fb7384f8.esm.js} +36 -20
- package/dist/declarations/src/dev/index.d.ts +6 -6
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/interpreter.d.ts +30 -16
- package/dist/declarations/src/types.d.ts +14 -7
- package/dist/xstate.cjs.js +7 -5
- package/dist/xstate.cjs.mjs +3 -1
- package/dist/xstate.development.cjs.js +7 -5
- package/dist/xstate.development.cjs.mjs +3 -1
- package/dist/xstate.development.esm.js +4 -4
- package/dist/xstate.esm.js +4 -4
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ServiceListener = (service:
|
|
1
|
+
import { AnyActor, DevToolsAdapter } from "../types.js";
|
|
2
|
+
type ServiceListener = (service: AnyActor) => void;
|
|
3
3
|
export interface XStateDevInterface {
|
|
4
|
-
register: (service:
|
|
5
|
-
unregister: (service:
|
|
4
|
+
register: (service: AnyActor) => void;
|
|
5
|
+
unregister: (service: AnyActor) => void;
|
|
6
6
|
onRegister: (listener: ServiceListener) => {
|
|
7
7
|
unsubscribe: () => void;
|
|
8
8
|
};
|
|
9
|
-
services: Set<
|
|
9
|
+
services: Set<AnyActor>;
|
|
10
10
|
}
|
|
11
11
|
export declare function getGlobal(): typeof globalThis | undefined;
|
|
12
|
-
export declare function registerService(service:
|
|
12
|
+
export declare function registerService(service: AnyActor): void;
|
|
13
13
|
export declare const devToolsAdapter: DevToolsAdapter;
|
|
14
14
|
export {};
|
|
@@ -6,7 +6,7 @@ export { log } from "./actions/log.js";
|
|
|
6
6
|
export { pure } from "./actions/pure.js";
|
|
7
7
|
export { raise } from "./actions/raise.js";
|
|
8
8
|
export { stop } from "./actions/stop.js";
|
|
9
|
-
import { interpret,
|
|
9
|
+
import { createActor, interpret, Actor, ActorStatus, InterpreterStatus, Interpreter } from "./interpreter.js";
|
|
10
10
|
import { createMachine } from "./Machine.js";
|
|
11
11
|
import { mapState } from "./mapState.js";
|
|
12
12
|
import { State } from "./State.js";
|
|
@@ -18,7 +18,8 @@ export { waitFor } from "./waitFor.js";
|
|
|
18
18
|
export * from "./typegenTypes.js";
|
|
19
19
|
export * from "./types.js";
|
|
20
20
|
export { matchesState, pathToStateValue, toObserver } from "./utils.js";
|
|
21
|
-
export { StateNode, State, mapState, sendTo, sendParent, forwardTo,
|
|
21
|
+
export { StateNode, State, mapState, sendTo, sendParent, forwardTo, createActor, interpret, // deprecated
|
|
22
|
+
Actor, type Interpreter, ActorStatus, InterpreterStatus, doneInvoke, createMachine };
|
|
22
23
|
export { fromPromise, fromObservable, fromCallback, fromEventObservable, fromTransition } from "./actors/index.js";
|
|
23
24
|
export { stateIn, not, and, or } from "./guards.js";
|
|
24
25
|
declare global {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { symbolObservable } from "./symbolObservable.js";
|
|
2
2
|
import { AreAllImplementationsAssumedToBeProvided, MissingImplementationsError } from "./typegenTypes.js";
|
|
3
|
-
import type { ActorSystem, AnyActorLogic, AnyStateMachine, EventFromLogic,
|
|
4
|
-
import { ActorRef, EventObject, InteropSubscribable,
|
|
3
|
+
import type { ActorSystem, AnyActorLogic, AnyStateMachine, EventFromLogic, PersistedStateFrom, SnapshotFrom, AnyActorRef } from "./types.js";
|
|
4
|
+
import { ActorRef, EventObject, InteropSubscribable, ActorOptions, Observer, Subscription } from "./types.js";
|
|
5
5
|
export type SnapshotListener<TLogic extends AnyActorLogic> = (state: SnapshotFrom<TLogic>) => void;
|
|
6
6
|
export type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;
|
|
7
7
|
export type Listener = () => void;
|
|
@@ -15,17 +15,21 @@ export declare enum ActorStatus {
|
|
|
15
15
|
Running = 1,
|
|
16
16
|
Stopped = 2
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `ActorStatus` instead.
|
|
20
|
+
*/
|
|
21
|
+
export declare const InterpreterStatus: typeof ActorStatus;
|
|
22
|
+
export declare class Actor<TLogic extends AnyActorLogic, TEvent extends EventObject = EventFromLogic<TLogic>> implements ActorRef<TEvent, SnapshotFrom<TLogic>> {
|
|
19
23
|
logic: TLogic;
|
|
20
24
|
/**
|
|
21
|
-
* The current state of the
|
|
25
|
+
* The current internal state of the actor.
|
|
22
26
|
*/
|
|
23
27
|
private _state;
|
|
24
28
|
/**
|
|
25
29
|
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
26
30
|
*/
|
|
27
31
|
clock: Clock;
|
|
28
|
-
options: Readonly<
|
|
32
|
+
options: Readonly<ActorOptions<TLogic>>;
|
|
29
33
|
/**
|
|
30
34
|
* The unique identifier for this actor relative to its parent.
|
|
31
35
|
*/
|
|
@@ -50,32 +54,32 @@ export declare class Interpreter<TLogic extends AnyActorLogic, TEvent extends Ev
|
|
|
50
54
|
private _doneEvent?;
|
|
51
55
|
src?: string;
|
|
52
56
|
/**
|
|
53
|
-
* Creates a new
|
|
57
|
+
* Creates a new actor instance for the given logic with the provided options, if any.
|
|
54
58
|
*
|
|
55
|
-
* @param logic The logic to
|
|
56
|
-
* @param options
|
|
59
|
+
* @param logic The logic to create an actor from
|
|
60
|
+
* @param options Actor options
|
|
57
61
|
*/
|
|
58
|
-
constructor(logic: TLogic, options?:
|
|
62
|
+
constructor(logic: TLogic, options?: ActorOptions<TLogic>);
|
|
59
63
|
private _initState;
|
|
60
64
|
private _deferred;
|
|
61
65
|
private update;
|
|
62
66
|
subscribe(observer: Observer<SnapshotFrom<TLogic>>): Subscription;
|
|
63
67
|
subscribe(nextListener?: (state: SnapshotFrom<TLogic>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
|
|
64
68
|
/**
|
|
65
|
-
* Starts the
|
|
69
|
+
* Starts the Actor from the initial state
|
|
66
70
|
*/
|
|
67
71
|
start(): this;
|
|
68
72
|
private _process;
|
|
69
73
|
private _stop;
|
|
70
74
|
/**
|
|
71
|
-
* Stops the
|
|
75
|
+
* Stops the Actor and unsubscribe all listeners.
|
|
72
76
|
*/
|
|
73
77
|
stop(): this;
|
|
74
78
|
private _complete;
|
|
75
79
|
private _error;
|
|
76
80
|
private _stopProcedure;
|
|
77
81
|
/**
|
|
78
|
-
* Sends an event to the running
|
|
82
|
+
* Sends an event to the running Actor to trigger a transition.
|
|
79
83
|
*
|
|
80
84
|
* @param event The event to send
|
|
81
85
|
*/
|
|
@@ -95,11 +99,21 @@ export declare class Interpreter<TLogic extends AnyActorLogic, TEvent extends Ev
|
|
|
95
99
|
[Symbol.observable](): InteropSubscribable<SnapshotFrom<TLogic>>;
|
|
96
100
|
getSnapshot(): SnapshotFrom<TLogic>;
|
|
97
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new `ActorRef` instance for the given machine with the provided options, if any.
|
|
104
|
+
*
|
|
105
|
+
* @param machine The machine to create an actor from
|
|
106
|
+
* @param options `ActorRef` options
|
|
107
|
+
*/
|
|
108
|
+
export declare function createActor<TMachine extends AnyStateMachine>(machine: AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends true ? TMachine : MissingImplementationsError<TMachine['__TResolvedTypesMeta']>, options?: ActorOptions<TMachine>): Actor<TMachine>;
|
|
109
|
+
export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: ActorOptions<TLogic>): Actor<TLogic>;
|
|
98
110
|
/**
|
|
99
111
|
* Creates a new Interpreter instance for the given machine with the provided options, if any.
|
|
100
112
|
*
|
|
101
|
-
* @
|
|
102
|
-
|
|
113
|
+
* @deprecated Use `createActor` instead
|
|
114
|
+
*/
|
|
115
|
+
export declare const interpret: typeof createActor;
|
|
116
|
+
/**
|
|
117
|
+
* @deprecated Use `Actor` instead.
|
|
103
118
|
*/
|
|
104
|
-
export
|
|
105
|
-
export declare function interpret<TLogic extends AnyActorLogic>(logic: TLogic, options?: InterpreterOptions<TLogic>): Interpreter<TLogic>;
|
|
119
|
+
export type Interpreter = typeof Actor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
2
|
import type { State } from "./State.js";
|
|
3
|
-
import type { ActorStatus, Clock,
|
|
3
|
+
import type { ActorStatus, Clock, Actor } from "./interpreter.js";
|
|
4
4
|
import type { StateMachine } from "./StateMachine.js";
|
|
5
5
|
import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from "./typegenTypes.js";
|
|
6
6
|
import { PromiseActorLogic } from "./actors/promise.js";
|
|
@@ -645,7 +645,7 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
645
645
|
machine?: StateMachine<TContext, TEvent, any, any, any, any>;
|
|
646
646
|
_internalQueue?: Array<TEvent>;
|
|
647
647
|
}
|
|
648
|
-
export interface
|
|
648
|
+
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
649
649
|
/**
|
|
650
650
|
* Whether state actions should be executed immediately upon transition. Defaults to `true`.
|
|
651
651
|
*/
|
|
@@ -686,7 +686,11 @@ export interface InterpreterOptions<TLogic extends AnyActorLogic> {
|
|
|
686
686
|
*/
|
|
687
687
|
src?: string;
|
|
688
688
|
}
|
|
689
|
-
export type
|
|
689
|
+
export type AnyActor = Actor<any, any>;
|
|
690
|
+
/**
|
|
691
|
+
* @deprecated Use `AnyActor` instead.
|
|
692
|
+
*/
|
|
693
|
+
export type AnyInterpreter = AnyActor;
|
|
690
694
|
export type Observer<T> = {
|
|
691
695
|
next?: (value: T) => void;
|
|
692
696
|
error?: (err: any) => void;
|
|
@@ -732,8 +736,11 @@ export interface ActorRef<TEvent extends EventObject, TSnapshot = any> extends S
|
|
|
732
736
|
export type AnyActorRef = ActorRef<any, any>;
|
|
733
737
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
734
738
|
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, any, any, any, infer TResolvedTypesMeta> ? ActorRef<TEvent, State<TContext, TEvent, TODO, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TEvent, infer TSnapshot, infer _, infer __, infer ___, infer ____, infer _____> ? ActorRef<TEvent, TSnapshot> : never : never;
|
|
735
|
-
export type DevToolsAdapter = (service:
|
|
736
|
-
|
|
739
|
+
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
740
|
+
/**
|
|
741
|
+
* @deprecated Use `Actor<T>` instead.
|
|
742
|
+
*/
|
|
743
|
+
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer _TAction, infer TActor, infer TInput, infer TResolvedTypesMeta> ? Actor<ActorLogic<TEvent, State<TContext, TEvent, TActor, TResolvedTypesMeta>, State<TContext, TEvent, TActor, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TActor, TResolvedTypesMeta>>, ActorSystem<any>, TInput>> : never;
|
|
737
744
|
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TAction, infer TActor, infer _TInput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
738
745
|
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
739
746
|
export type EventOfMachine<TMachine extends AnyStateMachine> = TMachine extends StateMachine<any, infer E, any, any, any, any> ? E : never;
|
|
@@ -775,13 +782,13 @@ any, // persisted state
|
|
|
775
782
|
any, // system
|
|
776
783
|
any, // input
|
|
777
784
|
any>;
|
|
778
|
-
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends
|
|
785
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TSnapshot> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____, infer ______> ? StateFrom<R> : R extends ActorLogic<infer _, infer TSnapshot, infer __, infer ___, infer ____> ? TSnapshot : R extends ActorContext<infer _, infer TSnapshot, infer __> ? TSnapshot : never : never;
|
|
779
786
|
export type EventFromLogic<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer TEvent, infer _, infer __, infer ___, infer ____> ? TEvent : never;
|
|
780
787
|
export type PersistedStateFrom<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer _TEvent, infer _TSnapshot, infer _TInternalState, infer TPersisted> ? TPersisted : never;
|
|
781
788
|
export type InternalStateFrom<TLogic extends ActorLogic<any, any>> = TLogic extends ActorLogic<infer _TEvent, infer _TSnapshot, infer TInternalState, infer _TPersisted> ? TInternalState : never;
|
|
782
789
|
type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer TEvent, infer __, infer ___, infer ____, infer _____> ? TEvent : R extends State<infer _TContext, infer TEvent, infer _TAction, infer _TActor> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
|
|
783
790
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
784
|
-
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____, infer _____> ? TContext : R extends State<infer TContext, infer _TEvent, infer _TAction, infer _TActor> ? TContext : R extends
|
|
791
|
+
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____, infer _____> ? TContext : R extends State<infer TContext, infer _TEvent, infer _TAction, infer _TActor> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TActions, infer _TActors, infer _TInput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
785
792
|
export type InferEvent<E extends EventObject> = {
|
|
786
793
|
[T in E['type']]: {
|
|
787
794
|
type: T;
|
package/dist/xstate.cjs.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-8f2e997e.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
@@ -577,7 +577,7 @@ class StateMachine {
|
|
|
577
577
|
return;
|
|
578
578
|
}
|
|
579
579
|
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
580
|
-
const actorRef = actors_dist_xstateActors.
|
|
580
|
+
const actorRef = actors_dist_xstateActors.createActor(logic, {
|
|
581
581
|
id: actorId,
|
|
582
582
|
state: actorState
|
|
583
583
|
});
|
|
@@ -601,7 +601,7 @@ class StateMachine {
|
|
|
601
601
|
}
|
|
602
602
|
const referenced = actors_dist_xstateActors.resolveReferencedActor(this.implementations.actors[src]);
|
|
603
603
|
if (referenced) {
|
|
604
|
-
const actorRef = actors_dist_xstateActors.
|
|
604
|
+
const actorRef = actors_dist_xstateActors.createActor(referenced.src, {
|
|
605
605
|
id,
|
|
606
606
|
parent: _actorCtx?.self,
|
|
607
607
|
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
|
@@ -751,15 +751,17 @@ function waitFor(actorRef, predicate, options) {
|
|
|
751
751
|
});
|
|
752
752
|
}
|
|
753
753
|
|
|
754
|
+
exports.Actor = actors_dist_xstateActors.Actor;
|
|
755
|
+
exports.ActorStatus = actors_dist_xstateActors.ActorStatus;
|
|
754
756
|
exports.ConstantPrefix = actors_dist_xstateActors.ConstantPrefix;
|
|
755
|
-
exports.
|
|
756
|
-
exports.InterpreterStatus = actors_dist_xstateActors.ActorStatus;
|
|
757
|
+
exports.InterpreterStatus = actors_dist_xstateActors.InterpreterStatus;
|
|
757
758
|
exports.SpecialTargets = actors_dist_xstateActors.SpecialTargets;
|
|
758
759
|
exports.State = actors_dist_xstateActors.State;
|
|
759
760
|
exports.and = actors_dist_xstateActors.and;
|
|
760
761
|
exports.assign = actors_dist_xstateActors.assign;
|
|
761
762
|
exports.cancel = actors_dist_xstateActors.cancel;
|
|
762
763
|
exports.choose = actors_dist_xstateActors.choose;
|
|
764
|
+
exports.createActor = actors_dist_xstateActors.createActor;
|
|
763
765
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
764
766
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
765
767
|
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
package/dist/xstate.cjs.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var actors_dist_xstateActors = require('./actions-
|
|
5
|
+
var actors_dist_xstateActors = require('./actions-4b70fc8d.development.cjs.js');
|
|
6
6
|
require('../dev/dist/xstate-dev.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
const EMPTY_OBJECT = {};
|
|
@@ -577,7 +577,7 @@ class StateMachine {
|
|
|
577
577
|
return;
|
|
578
578
|
}
|
|
579
579
|
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
580
|
-
const actorRef = actors_dist_xstateActors.
|
|
580
|
+
const actorRef = actors_dist_xstateActors.createActor(logic, {
|
|
581
581
|
id: actorId,
|
|
582
582
|
state: actorState
|
|
583
583
|
});
|
|
@@ -601,7 +601,7 @@ class StateMachine {
|
|
|
601
601
|
}
|
|
602
602
|
const referenced = actors_dist_xstateActors.resolveReferencedActor(this.implementations.actors[src]);
|
|
603
603
|
if (referenced) {
|
|
604
|
-
const actorRef = actors_dist_xstateActors.
|
|
604
|
+
const actorRef = actors_dist_xstateActors.createActor(referenced.src, {
|
|
605
605
|
id,
|
|
606
606
|
parent: _actorCtx?.self,
|
|
607
607
|
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
|
@@ -754,15 +754,17 @@ function waitFor(actorRef, predicate, options) {
|
|
|
754
754
|
});
|
|
755
755
|
}
|
|
756
756
|
|
|
757
|
+
exports.Actor = actors_dist_xstateActors.Actor;
|
|
758
|
+
exports.ActorStatus = actors_dist_xstateActors.ActorStatus;
|
|
757
759
|
exports.ConstantPrefix = actors_dist_xstateActors.ConstantPrefix;
|
|
758
|
-
exports.
|
|
759
|
-
exports.InterpreterStatus = actors_dist_xstateActors.ActorStatus;
|
|
760
|
+
exports.InterpreterStatus = actors_dist_xstateActors.InterpreterStatus;
|
|
760
761
|
exports.SpecialTargets = actors_dist_xstateActors.SpecialTargets;
|
|
761
762
|
exports.State = actors_dist_xstateActors.State;
|
|
762
763
|
exports.and = actors_dist_xstateActors.and;
|
|
763
764
|
exports.assign = actors_dist_xstateActors.assign;
|
|
764
765
|
exports.cancel = actors_dist_xstateActors.cancel;
|
|
765
766
|
exports.choose = actors_dist_xstateActors.choose;
|
|
767
|
+
exports.createActor = actors_dist_xstateActors.createActor;
|
|
766
768
|
exports.doneInvoke = actors_dist_xstateActors.doneInvoke;
|
|
767
769
|
exports.forwardTo = actors_dist_xstateActors.forwardTo;
|
|
768
770
|
exports.fromCallback = actors_dist_xstateActors.fromCallback;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as cloneState, u as macrostep, v as transitionNode, w as getInitialConfiguration, x as resolveActionsAndContext, y as assign, z as createInitEvent, A as microstep, B as isAtomicStateNode, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as
|
|
2
|
-
export {
|
|
1
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as cloneState, u as macrostep, v as transitionNode, w as getInitialConfiguration, x as resolveActionsAndContext, y as assign, z as createInitEvent, A as microstep, B as isAtomicStateNode, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as createActor, H as matchesState } from './actions-d4305983.development.esm.js';
|
|
2
|
+
export { M as Actor, O as ActorStatus, a7 as ConstantPrefix, P as InterpreterStatus, a8 as SpecialTargets, p as State, a5 as and, y as assign, R as cancel, T as choose, G as createActor, Q as doneInvoke, K as forwardTo, a0 as fromCallback, a1 as fromEventObservable, $ as fromObservable, _ as fromPromise, a2 as fromTransition, n as getStateNodes, L as interpret, U as log, H as matchesState, a4 as not, a6 as or, Y as pathToStateValue, V as pure, W as raise, J as sendParent, I as sendTo, a3 as stateIn, X as stop, Z as toObserver } from './actions-d4305983.development.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
@@ -574,7 +574,7 @@ class StateMachine {
|
|
|
574
574
|
return;
|
|
575
575
|
}
|
|
576
576
|
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
577
|
-
const actorRef =
|
|
577
|
+
const actorRef = createActor(logic, {
|
|
578
578
|
id: actorId,
|
|
579
579
|
state: actorState
|
|
580
580
|
});
|
|
@@ -598,7 +598,7 @@ class StateMachine {
|
|
|
598
598
|
}
|
|
599
599
|
const referenced = resolveReferencedActor(this.implementations.actors[src]);
|
|
600
600
|
if (referenced) {
|
|
601
|
-
const actorRef =
|
|
601
|
+
const actorRef = createActor(referenced.src, {
|
|
602
602
|
id,
|
|
603
603
|
parent: _actorCtx?.self,
|
|
604
604
|
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as cloneState, u as macrostep, v as transitionNode, w as getInitialConfiguration, x as resolveActionsAndContext, y as assign, z as createInitEvent, A as microstep, B as isAtomicStateNode, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as
|
|
2
|
-
export {
|
|
1
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, c as memo, e as evaluateGuard, d as flatten, g as createInvokeId, h as getDelayedTransitions, i as formatInitialTransition, j as getCandidates, k as toInvokeConfig, l as getConfiguration, n as getStateNodes, r as resolveStateValue, o as isInFinalState, p as State, q as isErrorEvent, s as cloneState, u as macrostep, v as transitionNode, w as getInitialConfiguration, x as resolveActionsAndContext, y as assign, z as createInitEvent, A as microstep, B as isAtomicStateNode, C as isStateId, D as getStateNodeByPath, E as getPersistedState, F as resolveReferencedActor, G as createActor, H as matchesState } from './actions-fb7384f8.esm.js';
|
|
2
|
+
export { M as Actor, O as ActorStatus, a7 as ConstantPrefix, P as InterpreterStatus, a8 as SpecialTargets, p as State, a5 as and, y as assign, R as cancel, T as choose, G as createActor, Q as doneInvoke, K as forwardTo, a0 as fromCallback, a1 as fromEventObservable, $ as fromObservable, _ as fromPromise, a2 as fromTransition, n as getStateNodes, L as interpret, U as log, H as matchesState, a4 as not, a6 as or, Y as pathToStateValue, V as pure, W as raise, J as sendParent, I as sendTo, a3 as stateIn, X as stop, Z as toObserver } from './actions-fb7384f8.esm.js';
|
|
3
3
|
import '../dev/dist/xstate-dev.esm.js';
|
|
4
4
|
|
|
5
5
|
const EMPTY_OBJECT = {};
|
|
@@ -574,7 +574,7 @@ class StateMachine {
|
|
|
574
574
|
return;
|
|
575
575
|
}
|
|
576
576
|
const actorState = logic.restoreState?.(childState, _actorCtx);
|
|
577
|
-
const actorRef =
|
|
577
|
+
const actorRef = createActor(logic, {
|
|
578
578
|
id: actorId,
|
|
579
579
|
state: actorState
|
|
580
580
|
});
|
|
@@ -598,7 +598,7 @@ class StateMachine {
|
|
|
598
598
|
}
|
|
599
599
|
const referenced = resolveReferencedActor(this.implementations.actors[src]);
|
|
600
600
|
if (referenced) {
|
|
601
|
-
const actorRef =
|
|
601
|
+
const actorRef = createActor(referenced.src, {
|
|
602
602
|
id,
|
|
603
603
|
parent: _actorCtx?.self,
|
|
604
604
|
input: 'input' in invokeConfig ? invokeConfig.input : referenced.input
|
package/dist/xstate.umd.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";let e=function(t){return t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});e.After,e.DoneState;const s=e.ErrorExecution,i=e.ErrorPlatform,o=e.ErrorCustom,r=".",a="",c="",u="xstate.init";function f(t,e,s,{to:i,event:o,id:r,delay:a}){const c=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const u="function"==typeof o?o(s):o;let f;if("string"==typeof a){const t=c&&c[a];f="function"==typeof t?t(s):t}else f="function"==typeof a?a(s):a;const h="function"==typeof i?i(s):i;let d;if("string"==typeof h){if(d=h===n.Parent?t?.self._parent:h===n.Internal?t?.self:h.startsWith("#_")?e.children[h.slice(2)]:e.children[h],!d)throw new Error(`Unable to send event to actor '${h}' from machine '${e.machine.id}'.`)}else d=h||t?.self;return[e,{to:d,event:u,id:r,delay:f}]}function h(t,e){if("number"==typeof e.delay)return void t.self.delaySend(e);const{to:n,event:s}=e;t.defer((()=>{n.send(s.type===o?{type:`${Yt(t.self.id)}`,data:s.data}:s)}))}function d(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=f,s.execute=h,s}const p=new WeakMap;function l(t,e,n){let s=p.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},p.set(t,s)),s[e]}function y(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function g(t,e){t.self.cancel(e)}function m(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=y,e.execute=g,e}class v{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}const _="function"==typeof Symbol&&Symbol.observable||"@@observable";function b(t,e){const n=S(t),s=S(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&b(n[t],s[t])))}function x(t){try{return O(t)?t:t.toString().split(r)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function S(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(O(t))return w(t);if("string"!=typeof t)return t;return w(x(t))}function w(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function $(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function k(t){return[].concat(...t)}function E(t){return O(t)?t:[t]}function I(t){return void 0===t?[]:E(t)}function T(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function O(t){return Array.isArray(t)}function j(t){return E(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function P(t){if(void 0!==t&&t!==a)return I(t)}function M(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}function N(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}const A="$$xstate.resolve",C="$$xstate.reject";const D="xstate.init",R="xstate.stop";function Q(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const J=t=>{const e=Q();e&&e.register(t)};function V(t){setTimeout((()=>{throw t}))}let B=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const z={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class U{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new v(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=B.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...z,...e},{clock:s,logger:i,parent:o,id:r,systemId:a}=n;this.system=o?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)try{t.next?.(e)}catch(t){V(t)}const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=Kt(this.id,s.data),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(s.data),this._parent?.send(Yt(this.id,s.data))}}subscribe(t,e,n){const s=M(t,e,n);if(this.status!==B.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){V(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===B.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=B.Running;const t=this.logic.getStatus?.(this._state);switch(t?.status){case"done":this.update(this._state);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(Yt(this.id,t)),this}return this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(Yt(this.id,t))}this.update(e),t.type===R&&(this._stopProcedure(),this._complete())}_stop(){return this.status===B.Stopped?this:(this.mailbox.clear(),this.status===B.NotStarted?(this.status=B.Stopped,this):(this.mailbox.enqueue({type:R}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){V(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||V(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){V(t)}}this.observers.clear(),e&&V(t)}_stopProcedure(){if(this.status!==B.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new v(this._process.bind(this)),this.status=B.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==B.Stopped){if(this.status!==B.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend({event:t,id:e,delay:n,to:s}){const i=this.clock.setTimeout((()=>{s?s.send(t):this.send(t)}),n);e&&(this.delayedEventsMap[e]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:J)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[_](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function W(t,e){return new U(t,e)}function q(t,e,n,{id:s,systemId:i,src:o,input:r}){const a=N(e.machine.implementations.actors[o]);let c;if(a){const u=r||a.input;c=W(a.src,{id:s,src:o,parent:t?.self,systemId:i,input:"function"==typeof u?u({context:e.context,event:n.event,self:t?.self}):u})}return[Dt(e,{children:{...e.children,[s]:c}}),{id:s,actorRef:c}]}function F(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n.status!==B.Stopped)try{n.start?.()}catch(n){return void t.self.send(Yt(e,n))}}))}function G({id:t,systemId:e,src:n,input:s}){function i(t){}return i.type="xstate.invoke",i.id=t,i.systemId=e,i.src=n,i.input=s,i.resolve=q,i.execute=F,i}function L(t,e,n,s){const{machine:i}=s,o=i?.implementations?.guards?.[t.type]??t.predicate;if(!o)throw new Error(`Guard '${t.type}' is not implemented.'.`);return o({context:e,event:n,state:s,guard:t,evaluate:L})}function X(t,e){if("string"==typeof t){const n=e?.(t);return"function"==typeof n?{type:t,predicate:n,params:{type:t}}:n||{type:t,params:{type:t}}}if("function"==typeof t)return{type:t.name,predicate:t,params:{type:t.name,name:t.name}};const n=e?.(t.type);return"function"==typeof n?{type:t.type,params:t.params||t,children:t.children?.map((t=>X(t,e))),predicate:e?.(t.type)||t.predicate}:n||{type:t.type,params:t.params||t,children:t.children?.map((t=>X(t,e))),predicate:t.predicate}}const H=t=>"atomic"===t.type||"final"===t.type;function K(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function Y(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function Z(t){const e=new Set(t),n=new Set(t),s=et(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of K(t))if("history"!==e.type&&!n.has(e))for(const t of ft(e))n.add(t)}else ft(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function tt(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(H(t))return t.key}const s={};for(const t of n)s[t.key]=tt(t,e);return s}function et(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function nt(t,e){return tt(t,et(Z(e)))}function st(t,e=t[0].machine.root){return"compound"===e.type?K(e).some((e=>"final"===e.type&&t.includes(e))):"parallel"===e.type&&K(e).every((e=>st(t,e)))}const it=t=>"#"===t[0];function ot(t){const n=t.config.after;if(!n)return[];const s=(n,s)=>{const i=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`}("function"==typeof n?`${t.id}:delay[${s}]`:n,t.id);return t.entry.push(Gt({type:i},{id:i,delay:n})),t.exit.push(m(i)),i};return(O(n)?n.map(((t,e)=>{const n=s(t.delay,e);return{...t,event:n}})):Object.keys(n).flatMap(((t,e)=>{const i=n[t],o="string"==typeof i?{target:i}:i,r=isNaN(+t)?t:+t,a=s(r,e);return I(o).map((t=>({...t,event:a,delay:r})))}))).map((e=>{const{delay:n}=e;return{...rt(t,e.event,e),delay:n}}))}function rt(t,e,n){const s=P(n.target),i=n.reenter??!1,{guards:o}=t.machine.implementations,r=at(t,s),a={...n,actions:I(n.actions),guard:n.guard?X(n.guard,(t=>o[t])):void 0,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function at(t,e){if(void 0!==e)return e.map((e=>{if("string"!=typeof e)return e;if(it(e))return t.machine.getStateNodeById(e);const n=e[0]===r;if(n&&!t.parent)return dt(t,e.slice(1));const s=n?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return dt(t.parent,s)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}function ct(t){const e=P(t.target);return e?e.map((e=>"string"==typeof e?dt(t.parent,e):e)):t.parent.initial.target}function ut(t){return"history"===t.type}function ft(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const i of s.initial.target){for(const n of Y(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of K(s))n(t)}(t),[...e]}function ht(t,e){if(it(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function dt(t,e){if("string"==typeof e&&it(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=x(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=ht(s,t)}return s}function pt(t,e){const n=e instanceof Ct?e.value:S(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>ht(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=ht(t,s);if(!i)return e;const o=pt(i,n[s]);return e.concat(o)}),[]))}function lt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=ht(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=lt(ht(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=lt(ht(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function yt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function gt(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function mt(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function vt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function _t(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(vt(St([i],e,n),St([r],e,n))){if(!gt(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function bt(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(ut(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of bt({target:ct(s)},e))n.add(t);else n.add(s);return[...n]}function xt(t,e){const n=bt(t,e);if(!n)return null;if(!t.reenter&&"parallel"!==t.source.type&&n.every((e=>gt(e,t.source))))return t.source;return function(t){const[e]=t;let n=mt(e),s=[];for(const e of t){const t=mt(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function St(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=xt(i,n);for(const n of e)gt(n,t)&&s.add(n)}return[...s]}function wt(t,e,n,s,i){const o=new Set(e.configuration);if(!t.length)return e;const r=function(t,e,n,s,i,o){const r=[],a={...e.historyValue},c=_t(t,n,a),u=[...e._internalQueue];o||function(t,e,n,s){const i=St(t,e,n);i.sort(((t,e)=>e.order-t.order));for(const t of i)for(const s of yt(t)){let i;i="deep"===s.history?e=>H(e)&>(e,t):e=>e.parent===t,n[s.id]=Array.from(e).filter(i)}for(const t of i)s.push(...t.exit,...t.invoke.map((t=>Jt(t.id)))),e.delete(t)}(c,n,a,r);r.push(...c.flatMap((t=>t.actions))),$t(s,c,n,r,u,e,a,o,i);const f=[...n],h=st(f);if(h){const t=f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit));r.push(...t)}try{const t=Tt(r,s,e,i),n=h?function(t,e,n,s){const i=t[0].machine,o=t.find((t=>"final"===t.type&&t.parent===i.root));return o&&o.output?T(o.output,e,n,s):void 0}(f,t.context,s,i.self):void 0;return u.push(...t._internalQueue),Dt(e,{configuration:f,historyValue:a,_internalQueue:u,context:t.context,done:h,output:n,children:t.children})}catch(t){throw t}}(t,e,o,s,n,i);return Dt(r,{value:{}})}function $t(t,e,n,s,i,o,r,a,c){const u=new Set,f=new Set;kt(e,r,f,u),a&&f.add(o.machine.root);for(const e of[...u].sort(((t,e)=>t.order-e.order))){n.add(e);for(const t of e.invoke)s.push(G(t));if(s.push(...e.entry),f.has(e))for(const t of f){const e=t.initial.actions;s.push(...e)}if("final"===e.type){const s=e.parent;if(!s.parent)continue;if(i.push(Ht(s.id,e.output?T(e.output,o.context,t,c.self):void 0)),s.parent){const t=s.parent;"parallel"===t.type&&K(t).every((t=>st([...n],t)))&&i.push(Ht(t.id))}}}}function kt(t,e,n,s){for(const i of t){for(const t of i.target||[])Et(t,e,n,s);const t=xt(i,e),o=bt(i,e);for(const i of o)It(i,t,s,e,n)}}function Et(t,e,n,s){if(ut(t))if(e[t.id]){const i=e[t.id];for(const t of i)Et(t,e,n,s);for(const o of i){It(o,t.parent,s,e,n);for(const t of n)n.add(t)}}else{const i=ct(t);for(const t of i)Et(t,e,n,s);for(const o of i){It(o,t,s,e,n);for(const t of n)n.add(t)}}else if(s.add(t),"compound"===t.type){n.add(t);const i=t.initial.target;for(const t of i)Et(t,e,n,s);for(const o of i)It(o,t,s,e,n)}else if("parallel"===t.type)for(const i of K(t).filter((t=>!ut(t))))[...s].some((t=>gt(t,i)))||Et(i,e,n,s)}function It(t,e,n,s,i){const o=Y(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of K(t).filter((t=>!ut(t))))[...n].some((t=>gt(t,e)))||Et(e,s,i,n)}function Tt(t,e,n,s){const{machine:i}=n;let o=Dt(n,{_internalQueue:[]});for(const n of t){const t="function"==typeof n?n:i.implementations.actions["string"==typeof n?n:n.type];if(!t)continue;const r={context:o.context,event:e,self:s?.self,system:s?.system,action:"string"==typeof n?{type:n}:n};if(!("resolve"in t)){s?.self.status===B.Running?t(r):s?.defer((()=>t(r)));continue}const a=t,[c,u,f]=a.resolve(s,o,r,t);o=c,"execute"in t&&(s?.self.status===B.Running?a.execute(s,u):s?.defer(a.execute.bind(null,s,u))),f&&(o=Tt(f,e,o,s))}return o}function Ot(t,e,n){let s=t;const i=[];if(e.type===R)return s=jt(e,s,n),i.push(s),{state:s,microstates:i};let o=e;if(o.type!==u){s=wt(Pt(o,s),t,n,o,!1),i.push(s)}for(;!s.done;){let t=Mt(s,o);if(t.length)s=wt(t,s,n,o,!1),i.push(s);else{if(!s._internalQueue.length)break;o=s._internalQueue[0];s=wt(Pt(o,s),s,n,o,!1),s._internalQueue.shift(),i.push(s)}}return s.done&&jt(o,s,n),{state:s,microstates:i}}function jt(t,e,n){const s=[];for(const t of e.configuration.sort(((t,e)=>e.order-t.order)))s.push(...t.exit);for(const t of Object.values(e.children))s.push(Jt(t));return Tt(s,t,e,n)}function Pt(t,e){return e.machine.getTransitionData(e,t)}function Mt(t,e){const n=new Set,s=t.configuration.filter(H);for(const i of s)t:for(const s of[i].concat(Y(i,null)))if(s.always)for(const i of s.always)if(void 0===i.guard||L(i.guard,t.context,e,t)){n.add(i);break t}return _t(Array.from(n),new Set(t.configuration),t.historyValue)}function Nt(t,e){return nt(t,[...Z(pt(t,e))])}function At(t){const e=[],n=t.initial,s=new Set;kt([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}class Ct{static from(t,e={},n){if(t instanceof Ct)return t.context!==e?new Ct({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=Z(pt(n.root,t));return new Ct({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.error=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(Z(pt(e.root,t.value))),this.children=t.children,this.value=nt(e.root,this.configuration),this.tags=new Set(k(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output,this.error=t.error}toStrings(t=this.value){if("string"==typeof t)return[t];const e=Object.keys(t);return e.concat(...e.map((e=>this.toStrings(t[e]).map((t=>e+r+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return b(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return l(this,"nextEvents",(()=>[...new Set(k([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function Dt(t,e={}){return new Ct({...t,...e},t.machine)}function Rt(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[Dt(e,{children:r}),o]}function Qt(t,e){e&&(e.status===B.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function Jt(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=Rt,e.execute=Qt,e}function Vt(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function Bt({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function zt(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a}=r;if("string"==typeof o){const c=N(e.implementations.actors[o]);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:c.input,f=W(c.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,systemId:a});return i[f.id]=f,f}return W(o,{id:r.id,parent:t.self,input:r.input,systemId:a})})(o,r);return i[a.id]=a,t.defer((()=>{if(a.status!==B.Stopped)try{a.start?.()}catch(e){return void t.self.send(Yt(a.id,e))}})),a}}function Ut(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:zt(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[Dt(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Wt(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ut,e}function qt(t,e,n,{event:s,id:i,delay:o}){const r=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const a="function"==typeof s?s(n):s;let c;if("string"==typeof o){const t=r&&r[o];c="function"==typeof t?t(n):t}else c="function"==typeof o?o(n):o;return["number"!=typeof c?Dt(e,{_internalQueue:e._internalQueue.concat(a)}):e,{event:a,id:i,delay:c}]}function Ft(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Gt(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=qt,n.execute=Ft,n}function Lt(t,e,n,{branches:s}){const i=s.find((t=>{const s=t.guard&&X(t.guard,(t=>e.machine.implementations.guards[t]));return!s||L(s,e.context,n.event,e)}))?.actions;return[e,void 0,I(i)]}function Xt(t,e,n,{get:s}){return[e,void 0,I(s({context:e.context,event:n.event}))]}function Ht(t,n){const s=`${e.DoneState}.${t}`,i={type:s,output:n,toString:()=>s};return i}function Kt(t,n){const s=`${e.DoneInvoke}.${t}`,i={type:s,output:n,toString:()=>s};return i}function Yt(t,n){const s=`${e.ErrorPlatform}.${t}`,i={type:s,data:n,toString:()=>s};return i}const Zt={},te=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ee{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(r),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?$(this.config.states,((t,e)=>new ee(t,{_parent:this,_key:e,_machine:this.machine}))):Zt,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=I(this.config.entry),this.exit=I(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=I(t.tags)}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===c)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,j(s).map((e=>rt(t,n,e))))}if(t.config.onDone){const n=String(Ht(t.id));e.set(n,j(t.config.onDone).map((e=>rt(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`done.invoke.${n.id}`;e.set(s,j(n.onDone).map((e=>rt(t,s,e))))}if(n.onError){const s=`error.platform.${n.id}`;e.set(s,j(n.onError).map((e=>rt(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,j(n.onSnapshot).map((e=>rt(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=j(this.config.always).map((t=>rt(this,c,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(te),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(te),eventType:null})}:void 0,history:this.history,states:$(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(te)}))),entry:this.entry.map(te),exit:this.exit.map(te),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return l(this,"invoke",(()=>I(this.config.invoke).map(((t,e)=>{const n=`${this.id}:invocation[${e}]`;const s=function(t,e){if("object"==typeof t){if("src"in t)return t;if("transition"in t)return{id:e,src:t}}return{id:e,src:t}}(t,n),i=s.id||n,o=s.src,{systemId:r}=s,a="string"==typeof o||"type"in o?o:i;return this.machine.implementations.actors[i]||"string"==typeof o||"type"in o||(this.machine.implementations.actors={...this.machine.implementations.actors,[i]:o}),{...s,src:a,id:i,systemId:r,toJSON(){const{onDone:t,onError:e,...n}=s;return{...n,type:"xstate.invoke",src:a,id:i}}}}))))}get on(){return l(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return l(this,"delayedTransitions",(()=>ot(this)))}get initial(){return l(this,"initial",(()=>function(t,e){if("string"==typeof e||O(e)){const n=I(e).map((e=>{const n="string"==typeof e?it(e)?t.machine.getStateNodeById(e):t.states[e]:e;if(!n)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);if(!gt(n,t))throw new Error(`Invalid initial target: state node #${n.id} is not a descendant of #${t.id}`);return n})),s=at(t,n),i={source:t,actions:[],eventType:null,reenter:!1,target:s,toJSON:()=>({...i,source:`#${t.id}`,target:s?s.map((t=>`#${t.id}`)):void 0})};return i}return rt(t,"__INITIAL__",{target:I(e.target).map((t=>"string"==typeof t?it(t)?t:`${r}${t}`:t)),actions:e.actions})}(this,this.config.initial||[])))}next(t,e){const n=e.type,s=[];let i;const o=l(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],i=s[t];if("*"===e)return t===n.length-1;if(e!==i)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||L(o,a,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${o.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get target(){if("history"===this.type){return this.config.target}}get stateIds(){const t=k(Object.keys(this.states).map((t=>this.states[t].stateIds)));return[this.id].concat(t)}get events(){return l(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class ne{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TAction=void 0,this.__TActor=void 0,this.__TResolvedTypesMeta=void 0,this.__TInput=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.root=new ee(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.implementations;return new ne(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=Z(pt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Nt(this.root,t.value),configuration:n,done:st(n)})}resolveStateValue(t,...[e]){const n=Nt(this.root,t);return this.resolveState(Ct.from(n,e,this))}transition(t,e,n){if(function(t){return"string"==typeof t.type&&(t.type===s||t.type.startsWith(i))}(e)&&!t.nextEvents.some((t=>t===e.type)))return Dt(t,{error:e.data});const{state:o}=Ot(t,e,n);return o}microstep(t,e,n){return Ot(t,e,n).microstates}getTransitionData(t,e){return lt(this.root,t.value,t,e)||[]}getPreInitialState(t,e){const{context:n}=this.config,s=this.resolveState(this.createState({value:{},context:"function"!=typeof n&&n?n:{},meta:void 0,configuration:At(this.root),children:{}}));if("function"==typeof n){return Tt([Wt((({spawn:t,event:e})=>n({spawn:t,input:e.input})))],e,s,t)}return s}getInitialState(t,e){const n=function(t){return{type:u,input:t}}(e),s=this.getPreInitialState(t,n),i=wt([{target:[...s.configuration].filter(H),source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,n,!0),{state:o}=Ot(i,n,t);return o}start(t){Object.values(t.children).forEach((t=>{0===t.status&&t.start?.()}))}getStateNodeById(t){const e=t.split(r),n=e.slice(1),s=it(e[0])?e[0].slice(1):e[0],i=this.idMap.get(s);if(!i)throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);return dt(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t){return function(t){const{configuration:e,tags:n,machine:s,children:i,...o}=t,r={};for(const t in i)r[t]={state:i[t].getPersistedState?.(),src:i[t].src};return{...o,children:r}}(t)}createState(t){return t instanceof Ct?t:new Ct(t,this)}getStatus(t){return t.error?{status:"error",data:t.error}:t.done?{status:"done",data:t.output}:{status:"active"}}restoreState(t,e){const n={};Object.keys(t.children).forEach((s=>{const i=t.children[s],o=i.state,r=i.src,a=r?N(this.implementations.actors[r])?.src:void 0;if(!a)return;const c=a.restoreState?.(o,e),u=W(a,{id:s,state:c});n[s]=u}));const s=this.createState(new Ct({...t,children:n},this));return s.configuration.forEach((t=>{t.invoke&&t.invoke.forEach((t=>{const{id:s,src:i}=t;if(n[s])return;const o=N(this.implementations.actors[i]);if(o){const i=W(o.src,{id:s,parent:e?.self,input:"input"in t?t.input:o.input});n[s]=i}}))})),s}}const se={timeout:1e4};t.ConstantPrefix=e,t.Interpreter=U,t.InterpreterStatus=B,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=n,t.State=Ct,t.StateMachine=ne,t.StateNode=ee,t.and=function(t){return{type:"xstate.boolean",params:{op:"and"},children:t.map((t=>X(t))),predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>e.children.every((e=>t(e,n,s,i)))}},t.assign=Wt,t.cancel=m,t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=Lt,e},t.createMachine=function(t,e){return new ne(t,e)},t.doneInvoke=Kt,t.forwardTo=function(t,e){return d(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e})=>{e.send({type:D})},transition:(e,n,{self:s,id:i,system:o})=>{if(n.type===D){const n=t=>{e.canceled||s._parent?.send(t)},a=t=>{e.receivers.add(t)};return e.dispose=t({input:e.input,system:o,self:s,sendBack:n,receive:a}),((r=e.dispose)instanceof Promise||null!==r&&("function"==typeof r||"object"==typeof r)&&"function"==typeof r.then)&&e.dispose.then((t=>{s._parent?.send(Kt(i,t)),e.canceled=!0}),(t=>{e.canceled=!0,s._parent?.send(Yt(i,t))})),e}var r;return n.type===R?(e.canceled=!0,"function"==typeof e.dispose&&e.dispose(),e):(function(t){return t.type===D||t.type===R}(n)||e.receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({canceled:!1,receivers:new Set,dispose:void 0,input:e}),getSnapshot:()=>{},getPersistedState:({input:t,canceled:e})=>({input:t,canceled:e})}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",input:void 0,data:s.data,subscription:void 0};case n:return{...t,status:"done",input:void 0,subscription:void 0};case R:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(s,{self:i,system:o})=>{"done"!==s.status&&(s.subscription=t({input:s.input,system:o,self:i}).subscribe({next:t=>{i._parent?.send(t)},error:t=>{i.send({type:e,data:t})},complete:()=>{i.send({type:n})}}))},getSnapshot:t=>{},getPersistedState:({status:t,data:e,input:n})=>({status:t,data:e,input:n}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:r,defer:a})=>{if("active"!==t.status)return t;switch(i.type){case e:return a((()=>{o._parent?.send({type:`xstate.snapshot.${r}`,data:i.data})})),{...t,data:i.data};case n:return{...t,status:"error",input:void 0,data:i.data,subscription:void 0};case s:return{...t,status:"done",input:void 0,subscription:void 0};case R:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(i,{self:o,system:r})=>{"done"!==i.status&&(i.subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{o.send({type:e,data:t})},error:t=>{o.send({type:n,data:t})},complete:()=>{o.send({type:s})}}))},getSnapshot:t=>t.data,getPersistedState:({status:t,data:e,input:n})=>({status:t,data:e,input:n}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case A:return{...t,status:"done",data:e.data,input:void 0};case C:return{...t,status:"error",data:e.data,input:void 0};case R:return{...t,status:"canceled",input:void 0};default:return t}},start:(e,{self:n,system:s})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:s,self:n})).then((t=>{"active"===n._state.status&&n.send({type:A,data:t})}),(t=>{"active"===n._state.status&&n.send({type:C,data:t})}))},getInitialState:(t,e)=>({status:"active",data:void 0,input:e}),getSnapshot:t=>t.data,getStatus:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=function(t,e){return{config:t,transition:(e,n,s)=>t(e,n,s),getInitialState:(t,n)=>"function"==typeof e?e({input:n}):e,getSnapshot:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.getStateNodes=pt,t.interpret=W,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=Vt,n.execute=Bt,n},t.mapState=function(t,e){let n;for(const s of Object.keys(t))b(s,e)&&(!n||e.length>n.length)&&(n=s);return t[n]},t.matchesState=b,t.not=function(t){return{type:"xstate.boolean",params:{op:"not"},children:[X(t)],predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>!t(e.children[0],n,s,i)}},t.or=function(t){return{type:"xstate.boolean",params:{op:"or"},children:t.map((t=>X(t))),predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>e.children.some((e=>t(e,n,s,i)))}},t.pathToStateValue=w,t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=Xt,e},t.raise=Gt,t.sendParent=function(t,e){return d(n.Parent,t,e)},t.sendTo=d,t.stateIn=function(t){return{type:"xstate.guard:in",params:{stateValue:t},predicate:({state:e})=>"string"==typeof t&&it(t)?e.configuration.some((e=>e.id===t.slice(1))):e.matches(t)}},t.stop=Jt,t.toObserver=M,t.waitFor=function(t,e,n){const s={...se,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";let e=function(t){return t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});e.After,e.DoneState;const s=e.ErrorExecution,i=e.ErrorPlatform,o=e.ErrorCustom,r=".",a="",c="",u="xstate.init";function f(t,e,s,{to:i,event:o,id:r,delay:a}){const c=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);const u="function"==typeof o?o(s):o;let f;if("string"==typeof a){const t=c&&c[a];f="function"==typeof t?t(s):t}else f="function"==typeof a?a(s):a;const h="function"==typeof i?i(s):i;let d;if("string"==typeof h){if(d=h===n.Parent?t?.self._parent:h===n.Internal?t?.self:h.startsWith("#_")?e.children[h.slice(2)]:e.children[h],!d)throw new Error(`Unable to send event to actor '${h}' from machine '${e.machine.id}'.`)}else d=h||t?.self;return[e,{to:d,event:u,id:r,delay:f}]}function h(t,e){if("number"==typeof e.delay)return void t.self.delaySend(e);const{to:n,event:s}=e;t.defer((()=>{n.send(s.type===o?{type:`${te(t.self.id)}`,data:s.data}:s)}))}function d(t,e,n){function s(t){}return s.type="xstate.sendTo",s.to=t,s.event=e,s.id=n?.id,s.delay=n?.delay,s.resolve=f,s.execute=h,s}const p=new WeakMap;function l(t,e,n){let s=p.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},p.set(t,s)),s[e]}function y(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function g(t,e){t.self.cancel(e)}function m(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=y,e.execute=g,e}class v{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}const _="function"==typeof Symbol&&Symbol.observable||"@@observable";function b(t,e){const n=S(t),s=S(e);return"string"==typeof s?"string"==typeof n&&s===n:"string"==typeof n?n in s:Object.keys(n).every((t=>t in s&&b(n[t],s[t])))}function x(t){try{return O(t)?t:t.toString().split(r)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function S(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(O(t))return w(t);if("string"!=typeof t)return t;return w(x(t))}function w(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)n[t[e]]=t[e+1];else{const s=n;n={},s[t[e]]=n}return e}function $(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function k(t){return[].concat(...t)}function E(t){return O(t)?t:[t]}function I(t){return void 0===t?[]:E(t)}function T(t,e,n,s){return"function"==typeof t?t({context:e,event:n,self:s}):t}function O(t){return Array.isArray(t)}function j(t){return E(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function P(t){if(void 0!==t&&t!==a)return I(t)}function M(t,e,n){const s="object"==typeof t,i=s?t:void 0;return{next:(s?t.next:t)?.bind(i),error:(s?t.error:e)?.bind(i),complete:(s?t.complete:n)?.bind(i)}}function N(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}const A="$$xstate.resolve",C="$$xstate.reject";const D="xstate.init",R="xstate.stop";function Q(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const J=t=>{const e=Q();e&&e.register(t)};function V(t){setTimeout((()=>{throw t}))}let B=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const z=B,U={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class W{constructor(t,e){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new v(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=B.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...U,...e},{clock:s,logger:i,parent:o,id:r,systemId:a}=n;this.system=o?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.logic.restoreState?this.logic.restoreState(this.options.state,this._actorContext):this.options.state:this.logic.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n();for(const t of this.observers)try{t.next?.(e)}catch(t){V(t)}const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=Zt(this.id,s.data),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(s.data),this._parent?.send(te(this.id,s.data))}}subscribe(t,e,n){const s=M(t,e,n);if(this.status!==B.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){V(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===B.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=B.Running;const t=this.logic.getStatus?.(this._state);switch(t?.status){case"done":this.update(this._state);case"error":return this}if(this.logic.start)try{this.logic.start(this._state,this._actorContext)}catch(t){return this._stopProcedure(),this._error(t),this._parent?.send(te(this.id,t)),this}return this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,n;try{e=this.logic.transition(this._state,t,this._actorContext)}catch(t){n={err:t}}if(n){const{err:t}=n;return this._stopProcedure(),this._error(t),void this._parent?.send(te(this.id,t))}this.update(e),t.type===R&&(this._stopProcedure(),this._complete())}_stop(){return this.status===B.Stopped?this:(this.mailbox.clear(),this.status===B.NotStarted?(this.status=B.Stopped,this):(this.mailbox.enqueue({type:R}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){V(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||V(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){V(t)}}this.observers.clear(),e&&V(t)}_stopProcedure(){if(this.status!==B.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new v(this._process.bind(this)),this.status=B.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==B.Stopped){if(this.status!==B.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend({event:t,id:e,delay:n,to:s}){const i=this.clock.setTimeout((()=>{s?s.send(t):this.send(t)}),n);e&&(this.delayedEventsMap[e]=i)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:J)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.logic.getPersistedState?.(this._state)}[_](){return this}getSnapshot(){return this.logic.getSnapshot?this.logic.getSnapshot(this._state):this._state}}function q(t,e){return new W(t,e)}const F=q;function G(t,e,n,{id:s,systemId:i,src:o,input:r}){const a=N(e.machine.implementations.actors[o]);let c;if(a){const u=r||a.input;c=q(a.src,{id:s,src:o,parent:t?.self,systemId:i,input:"function"==typeof u?u({context:e.context,event:n.event,self:t?.self}):u})}return[Qt(e,{children:{...e.children,[s]:c}}),{id:s,actorRef:c}]}function L(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n.status!==B.Stopped)try{n.start?.()}catch(n){return void t.self.send(te(e,n))}}))}function X({id:t,systemId:e,src:n,input:s}){function i(t){}return i.type="xstate.invoke",i.id=t,i.systemId=e,i.src=n,i.input=s,i.resolve=G,i.execute=L,i}function H(t,e,n,s){const{machine:i}=s,o=i?.implementations?.guards?.[t.type]??t.predicate;if(!o)throw new Error(`Guard '${t.type}' is not implemented.'.`);return o({context:e,event:n,state:s,guard:t,evaluate:H})}function K(t,e){if("string"==typeof t){const n=e?.(t);return"function"==typeof n?{type:t,predicate:n,params:{type:t}}:n||{type:t,params:{type:t}}}if("function"==typeof t)return{type:t.name,predicate:t,params:{type:t.name,name:t.name}};const n=e?.(t.type);return"function"==typeof n?{type:t.type,params:t.params||t,children:t.children?.map((t=>K(t,e))),predicate:e?.(t.type)||t.predicate}:n||{type:t.type,params:t.params||t,children:t.children?.map((t=>K(t,e))),predicate:t.predicate}}const Y=t=>"atomic"===t.type||"final"===t.type;function Z(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function tt(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function et(t){const e=new Set(t),n=new Set(t),s=st(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Z(t))if("history"!==e.type&&!n.has(e))for(const t of dt(e))n.add(t)}else dt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function nt(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(Y(t))return t.key}const s={};for(const t of n)s[t.key]=nt(t,e);return s}function st(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function it(t,e){return nt(t,st(et(e)))}function ot(t,e=t[0].machine.root){return"compound"===e.type?Z(e).some((e=>"final"===e.type&&t.includes(e))):"parallel"===e.type&&Z(e).every((e=>ot(t,e)))}const rt=t=>"#"===t[0];function at(t){const n=t.config.after;if(!n)return[];const s=(n,s)=>{const i=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`}("function"==typeof n?`${t.id}:delay[${s}]`:n,t.id);return t.entry.push(Xt({type:i},{id:i,delay:n})),t.exit.push(m(i)),i};return(O(n)?n.map(((t,e)=>{const n=s(t.delay,e);return{...t,event:n}})):Object.keys(n).flatMap(((t,e)=>{const i=n[t],o="string"==typeof i?{target:i}:i,r=isNaN(+t)?t:+t,a=s(r,e);return I(o).map((t=>({...t,event:a,delay:r})))}))).map((e=>{const{delay:n}=e;return{...ct(t,e.event,e),delay:n}}))}function ct(t,e,n){const s=P(n.target),i=n.reenter??!1,{guards:o}=t.machine.implementations,r=ut(t,s),a={...n,actions:I(n.actions),guard:n.guard?K(n.guard,(t=>o[t])):void 0,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ut(t,e){if(void 0!==e)return e.map((e=>{if("string"!=typeof e)return e;if(rt(e))return t.machine.getStateNodeById(e);const n=e[0]===r;if(n&&!t.parent)return lt(t,e.slice(1));const s=n?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return lt(t.parent,s)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}function ft(t){const e=P(t.target);return e?e.map((e=>"string"==typeof e?lt(t.parent,e):e)):t.parent.initial.target}function ht(t){return"history"===t.type}function dt(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const i of s.initial.target){for(const n of tt(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of Z(s))n(t)}(t),[...e]}function pt(t,e){if(rt(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function lt(t,e){if("string"==typeof e&&rt(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=x(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=pt(s,t)}return s}function yt(t,e){const n=e instanceof Rt?e.value:S(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>pt(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=pt(t,s);if(!i)return e;const o=yt(i,n[s]);return e.concat(o)}),[]))}function gt(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=pt(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=gt(pt(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=gt(pt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function mt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function vt(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function _t(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function bt(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function xt(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(bt($t([i],e,n),$t([r],e,n))){if(!vt(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function St(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(ht(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of St({target:ft(s)},e))n.add(t);else n.add(s);return[...n]}function wt(t,e){const n=St(t,e);if(!n)return null;if(!t.reenter&&"parallel"!==t.source.type&&n.every((e=>vt(e,t.source))))return t.source;return function(t){const[e]=t;let n=_t(e),s=[];for(const e of t){const t=_t(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function $t(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=wt(i,n);for(const n of e)vt(n,t)&&s.add(n)}return[...s]}function kt(t,e,n,s,i){const o=new Set(e.configuration);if(!t.length)return e;const r=function(t,e,n,s,i,o){const r=[],a={...e.historyValue},c=xt(t,n,a),u=[...e._internalQueue];o||function(t,e,n,s){const i=$t(t,e,n);i.sort(((t,e)=>e.order-t.order));for(const t of i)for(const s of mt(t)){let i;i="deep"===s.history?e=>Y(e)&&vt(e,t):e=>e.parent===t,n[s.id]=Array.from(e).filter(i)}for(const t of i)s.push(...t.exit,...t.invoke.map((t=>Bt(t.id)))),e.delete(t)}(c,n,a,r);r.push(...c.flatMap((t=>t.actions))),Et(s,c,n,r,u,e,a,o,i);const f=[...n],h=ot(f);if(h){const t=f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit));r.push(...t)}try{const t=jt(r,s,e,i),n=h?function(t,e,n,s){const i=t[0].machine,o=t.find((t=>"final"===t.type&&t.parent===i.root));return o&&o.output?T(o.output,e,n,s):void 0}(f,t.context,s,i.self):void 0;return u.push(...t._internalQueue),Qt(e,{configuration:f,historyValue:a,_internalQueue:u,context:t.context,done:h,output:n,children:t.children})}catch(t){throw t}}(t,e,o,s,n,i);return Qt(r,{value:{}})}function Et(t,e,n,s,i,o,r,a,c){const u=new Set,f=new Set;It(e,r,f,u),a&&f.add(o.machine.root);for(const e of[...u].sort(((t,e)=>t.order-e.order))){n.add(e);for(const t of e.invoke)s.push(X(t));if(s.push(...e.entry),f.has(e))for(const t of f){const e=t.initial.actions;s.push(...e)}if("final"===e.type){const s=e.parent;if(!s.parent)continue;if(i.push(Yt(s.id,e.output?T(e.output,o.context,t,c.self):void 0)),s.parent){const t=s.parent;"parallel"===t.type&&Z(t).every((t=>ot([...n],t)))&&i.push(Yt(t.id))}}}}function It(t,e,n,s){for(const i of t){for(const t of i.target||[])Tt(t,e,n,s);const t=wt(i,e),o=St(i,e);for(const i of o)Ot(i,t,s,e,n)}}function Tt(t,e,n,s){if(ht(t))if(e[t.id]){const i=e[t.id];for(const t of i)Tt(t,e,n,s);for(const o of i){Ot(o,t.parent,s,e,n);for(const t of n)n.add(t)}}else{const i=ft(t);for(const t of i)Tt(t,e,n,s);for(const o of i){Ot(o,t,s,e,n);for(const t of n)n.add(t)}}else if(s.add(t),"compound"===t.type){n.add(t);const i=t.initial.target;for(const t of i)Tt(t,e,n,s);for(const o of i)Ot(o,t,s,e,n)}else if("parallel"===t.type)for(const i of Z(t).filter((t=>!ht(t))))[...s].some((t=>vt(t,i)))||Tt(i,e,n,s)}function Ot(t,e,n,s,i){const o=tt(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of Z(t).filter((t=>!ht(t))))[...n].some((t=>vt(t,e)))||Tt(e,s,i,n)}function jt(t,e,n,s){const{machine:i}=n;let o=Qt(n,{_internalQueue:[]});for(const n of t){const t="function"==typeof n?n:i.implementations.actions["string"==typeof n?n:n.type];if(!t)continue;const r={context:o.context,event:e,self:s?.self,system:s?.system,action:"string"==typeof n?{type:n}:n};if(!("resolve"in t)){s?.self.status===B.Running?t(r):s?.defer((()=>t(r)));continue}const a=t,[c,u,f]=a.resolve(s,o,r,t);o=c,"execute"in t&&(s?.self.status===B.Running?a.execute(s,u):s?.defer(a.execute.bind(null,s,u))),f&&(o=jt(f,e,o,s))}return o}function Pt(t,e,n){let s=t;const i=[];if(e.type===R)return s=Mt(e,s,n),i.push(s),{state:s,microstates:i};let o=e;if(o.type!==u){s=kt(Nt(o,s),t,n,o,!1),i.push(s)}for(;!s.done;){let t=At(s,o);if(t.length)s=kt(t,s,n,o,!1),i.push(s);else{if(!s._internalQueue.length)break;o=s._internalQueue[0];s=kt(Nt(o,s),s,n,o,!1),s._internalQueue.shift(),i.push(s)}}return s.done&&Mt(o,s,n),{state:s,microstates:i}}function Mt(t,e,n){const s=[];for(const t of e.configuration.sort(((t,e)=>e.order-t.order)))s.push(...t.exit);for(const t of Object.values(e.children))s.push(Bt(t));return jt(s,t,e,n)}function Nt(t,e){return e.machine.getTransitionData(e,t)}function At(t,e){const n=new Set,s=t.configuration.filter(Y);for(const i of s)t:for(const s of[i].concat(tt(i,null)))if(s.always)for(const i of s.always)if(void 0===i.guard||H(i.guard,t.context,e,t)){n.add(i);break t}return xt(Array.from(n),new Set(t.configuration),t.historyValue)}function Ct(t,e){return it(t,[...et(yt(t,e))])}function Dt(t){const e=[],n=t.initial,s=new Set;It([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}class Rt{static from(t,e={},n){if(t instanceof Rt)return t.context!==e?new Rt({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=et(yt(n.root,t));return new Rt({value:t,context:e,meta:void 0,configuration:Array.from(s),children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.error=void 0,this.context=void 0,this.historyValue={},this._internalQueue=void 0,this.configuration=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.historyValue=t.historyValue||{},this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(et(yt(e.root,t.value))),this.children=t.children,this.value=it(e.root,this.configuration),this.tags=new Set(k(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output,this.error=t.error}toStrings(t=this.value){if("string"==typeof t)return[t];const e=Object.keys(t);return e.concat(...e.map((e=>this.toStrings(t[e]).map((t=>e+r+t)))))}toJSON(){const{configuration:t,tags:e,machine:n,...s}=this;return{...s,tags:Array.from(e),meta:this.meta}}matches(t){return b(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return l(this,"nextEvents",(()=>[...new Set(k([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function Qt(t,e={}){return new Rt({...t,...e},t.machine)}function Jt(t,e,n,{actorRef:s}){const i="function"==typeof s?s(n):s,o="string"==typeof i?e.children[i]:i;let r=e.children;return o&&(r={...r},delete r[o.id]),[Qt(e,{children:r}),o]}function Vt(t,e){e&&(e.status===B.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function Bt(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=Jt,e.execute=Vt,e}function zt(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function Ut({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function Wt(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a}=r;if("string"==typeof o){const c=N(e.implementations.actors[o]);if(!c)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const u="input"in r?r.input:c.input,f=q(c.src,{id:r.id,parent:t.self,input:"function"==typeof u?u({context:n,event:s,self:t.self}):u,systemId:a});return i[f.id]=f,f}return q(o,{id:r.id,parent:t.self,input:r.input,systemId:a})})(o,r);return i[a.id]=a,t.defer((()=>{if(a.status!==B.Stopped)try{a.start?.()}catch(e){return void t.self.send(te(a.id,e))}})),a}}function qt(t,e,n,{assignment:s}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},o={context:e.context,event:n.event,action:n.action,spawn:Wt(t,e,n.event,i),self:t?.self,system:t?.system};let r={};if("function"==typeof s)r=s(o);else for(const t of Object.keys(s)){const e=s[t];r[t]="function"==typeof e?e(o):e}return[Qt(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Ft(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=qt,e}function Gt(t,e,n,{event:s,id:i,delay:o}){const r=e.machine.implementations.delays;if("string"==typeof s)throw new Error(`Only event objects may be used with raise; use raise({ type: "${s}" }) instead`);const a="function"==typeof s?s(n):s;let c;if("string"==typeof o){const t=r&&r[o];c="function"==typeof t?t(n):t}else c="function"==typeof o?o(n):o;return["number"!=typeof c?Qt(e,{_internalQueue:e._internalQueue.concat(a)}):e,{event:a,id:i,delay:c}]}function Lt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Xt(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Gt,n.execute=Lt,n}function Ht(t,e,n,{branches:s}){const i=s.find((t=>{const s=t.guard&&K(t.guard,(t=>e.machine.implementations.guards[t]));return!s||H(s,e.context,n.event,e)}))?.actions;return[e,void 0,I(i)]}function Kt(t,e,n,{get:s}){return[e,void 0,I(s({context:e.context,event:n.event}))]}function Yt(t,n){const s=`${e.DoneState}.${t}`,i={type:s,output:n,toString:()=>s};return i}function Zt(t,n){const s=`${e.DoneInvoke}.${t}`,i={type:s,output:n,toString:()=>s};return i}function te(t,n){const s=`${e.ErrorPlatform}.${t}`,i={type:s,data:n,toString:()=>s};return i}const ee={},ne=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class se{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(r),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?$(this.config.states,((t,e)=>new se(t,{_parent:this,_key:e,_machine:this.machine}))):ee,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=I(this.config.entry),this.exit=I(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=I(t.tags)}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===c)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const s=t.config.on[n];e.set(n,j(s).map((e=>ct(t,n,e))))}if(t.config.onDone){const n=String(Yt(t.id));e.set(n,j(t.config.onDone).map((e=>ct(t,n,e))))}for(const n of t.invoke){if(n.onDone){const s=`done.invoke.${n.id}`;e.set(s,j(n.onDone).map((e=>ct(t,s,e))))}if(n.onError){const s=`error.platform.${n.id}`;e.set(s,j(n.onError).map((e=>ct(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,j(n.onSnapshot).map((e=>ct(t,s,e))))}}for(const n of t.after){let t=e.get(n.eventType);t||(t=[],e.set(n.eventType,t)),t.push(n)}return e}(this),this.config.always&&(this.always=j(this.config.always).map((t=>ct(this,c,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(ne),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(ne),eventType:null})}:void 0,history:this.history,states:$(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(ne)}))),entry:this.entry.map(ne),exit:this.exit.map(ne),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return l(this,"invoke",(()=>I(this.config.invoke).map(((t,e)=>{const n=`${this.id}:invocation[${e}]`;const s=function(t,e){if("object"==typeof t){if("src"in t)return t;if("transition"in t)return{id:e,src:t}}return{id:e,src:t}}(t,n),i=s.id||n,o=s.src,{systemId:r}=s,a="string"==typeof o||"type"in o?o:i;return this.machine.implementations.actors[i]||"string"==typeof o||"type"in o||(this.machine.implementations.actors={...this.machine.implementations.actors,[i]:o}),{...s,src:a,id:i,systemId:r,toJSON(){const{onDone:t,onError:e,...n}=s;return{...n,type:"xstate.invoke",src:a,id:i}}}}))))}get on(){return l(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,n])=>(t[e]=t[e]||[],t[e].push(n),t)),{})))}get after(){return l(this,"delayedTransitions",(()=>at(this)))}get initial(){return l(this,"initial",(()=>function(t,e){if("string"==typeof e||O(e)){const n=I(e).map((e=>{const n="string"==typeof e?rt(e)?t.machine.getStateNodeById(e):t.states[e]:e;if(!n)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);if(!vt(n,t))throw new Error(`Invalid initial target: state node #${n.id} is not a descendant of #${t.id}`);return n})),s=ut(t,n),i={source:t,actions:[],eventType:null,reenter:!1,target:s,toJSON:()=>({...i,source:`#${t.id}`,target:s?s.map((t=>`#${t.id}`)):void 0})};return i}return ct(t,"__INITIAL__",{target:I(e.target).map((t=>"string"==typeof t?rt(t)?t:`${r}${t}`:t)),actions:e.actions})}(this,this.config.initial||[])))}next(t,e){const n=e.type,s=[];let i;const o=l(this,`candidates-${n}`,(()=>{return e=n,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const n=t.split("."),s=e.split(".");for(let t=0;t<n.length;t++){const e=n[t],i=s[t];if("*"===e)return t===n.length-1;if(e!==i)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||H(o,a,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${o.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get target(){if("history"===this.type){return this.config.target}}get stateIds(){const t=k(Object.keys(this.states).map((t=>this.states[t].stateIds)));return[this.id].concat(t)}get events(){return l(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class ie{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TAction=void 0,this.__TActor=void 0,this.__TResolvedTypesMeta=void 0,this.__TInput=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.root=new se(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.implementations;return new ie(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=et(yt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Ct(this.root,t.value),configuration:n,done:ot(n)})}resolveStateValue(t,...[e]){const n=Ct(this.root,t);return this.resolveState(Rt.from(n,e,this))}transition(t,e,n){if(function(t){return"string"==typeof t.type&&(t.type===s||t.type.startsWith(i))}(e)&&!t.nextEvents.some((t=>t===e.type)))return Qt(t,{error:e.data});const{state:o}=Pt(t,e,n);return o}microstep(t,e,n){return Pt(t,e,n).microstates}getTransitionData(t,e){return gt(this.root,t.value,t,e)||[]}getPreInitialState(t,e){const{context:n}=this.config,s=this.resolveState(this.createState({value:{},context:"function"!=typeof n&&n?n:{},meta:void 0,configuration:Dt(this.root),children:{}}));if("function"==typeof n){return jt([Ft((({spawn:t,event:e})=>n({spawn:t,input:e.input})))],e,s,t)}return s}getInitialState(t,e){const n=function(t){return{type:u,input:t}}(e),s=this.getPreInitialState(t,n),i=kt([{target:[...s.configuration].filter(Y),source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,n,!0),{state:o}=Pt(i,n,t);return o}start(t){Object.values(t.children).forEach((t=>{0===t.status&&t.start?.()}))}getStateNodeById(t){const e=t.split(r),n=e.slice(1),s=rt(e[0])?e[0].slice(1):e[0],i=this.idMap.get(s);if(!i)throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);return lt(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t){return function(t){const{configuration:e,tags:n,machine:s,children:i,...o}=t,r={};for(const t in i)r[t]={state:i[t].getPersistedState?.(),src:i[t].src};return{...o,children:r}}(t)}createState(t){return t instanceof Rt?t:new Rt(t,this)}getStatus(t){return t.error?{status:"error",data:t.error}:t.done?{status:"done",data:t.output}:{status:"active"}}restoreState(t,e){const n={};Object.keys(t.children).forEach((s=>{const i=t.children[s],o=i.state,r=i.src,a=r?N(this.implementations.actors[r])?.src:void 0;if(!a)return;const c=a.restoreState?.(o,e),u=q(a,{id:s,state:c});n[s]=u}));const s=this.createState(new Rt({...t,children:n},this));return s.configuration.forEach((t=>{t.invoke&&t.invoke.forEach((t=>{const{id:s,src:i}=t;if(n[s])return;const o=N(this.implementations.actors[i]);if(o){const i=q(o.src,{id:s,parent:e?.self,input:"input"in t?t.input:o.input});n[s]=i}}))})),s}}const oe={timeout:1e4};t.Actor=W,t.ActorStatus=B,t.ConstantPrefix=e,t.InterpreterStatus=z,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=n,t.State=Rt,t.StateMachine=ie,t.StateNode=se,t.and=function(t){return{type:"xstate.boolean",params:{op:"and"},children:t.map((t=>K(t))),predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>e.children.every((e=>t(e,n,s,i)))}},t.assign=Ft,t.cancel=m,t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=Ht,e},t.createActor=q,t.createMachine=function(t,e){return new ie(t,e)},t.doneInvoke=Zt,t.forwardTo=function(t,e){return d(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e})=>{e.send({type:D})},transition:(e,n,{self:s,id:i,system:o})=>{if(n.type===D){const n=t=>{e.canceled||s._parent?.send(t)},a=t=>{e.receivers.add(t)};return e.dispose=t({input:e.input,system:o,self:s,sendBack:n,receive:a}),((r=e.dispose)instanceof Promise||null!==r&&("function"==typeof r||"object"==typeof r)&&"function"==typeof r.then)&&e.dispose.then((t=>{s._parent?.send(Zt(i,t)),e.canceled=!0}),(t=>{e.canceled=!0,s._parent?.send(te(i,t))})),e}var r;return n.type===R?(e.canceled=!0,"function"==typeof e.dispose&&e.dispose(),e):(function(t){return t.type===D||t.type===R}(n)||e.receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({canceled:!1,receivers:new Set,dispose:void 0,input:e}),getSnapshot:()=>{},getPersistedState:({input:t,canceled:e})=>({input:t,canceled:e})}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",input:void 0,data:s.data,subscription:void 0};case n:return{...t,status:"done",input:void 0,subscription:void 0};case R:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(s,{self:i,system:o})=>{"done"!==s.status&&(s.subscription=t({input:s.input,system:o,self:i}).subscribe({next:t=>{i._parent?.send(t)},error:t=>{i.send({type:e,data:t})},complete:()=>{i.send({type:n})}}))},getSnapshot:t=>{},getPersistedState:({status:t,data:e,input:n})=>({status:t,data:e,input:n}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:r,defer:a})=>{if("active"!==t.status)return t;switch(i.type){case e:return a((()=>{o._parent?.send({type:`xstate.snapshot.${r}`,data:i.data})})),{...t,data:i.data};case n:return{...t,status:"error",input:void 0,data:i.data,subscription:void 0};case s:return{...t,status:"done",input:void 0,subscription:void 0};case R:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(i,{self:o,system:r})=>{"done"!==i.status&&(i.subscription=t({input:i.input,system:r,self:o}).subscribe({next:t=>{o.send({type:e,data:t})},error:t=>{o.send({type:n,data:t})},complete:()=>{o.send({type:s})}}))},getSnapshot:t=>t.data,getPersistedState:({status:t,data:e,input:n})=>({status:t,data:e,input:n}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case A:return{...t,status:"done",data:e.data,input:void 0};case C:return{...t,status:"error",data:e.data,input:void 0};case R:return{...t,status:"canceled",input:void 0};default:return t}},start:(e,{self:n,system:s})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:s,self:n})).then((t=>{"active"===n._state.status&&n.send({type:A,data:t})}),(t=>{"active"===n._state.status&&n.send({type:C,data:t})}))},getInitialState:(t,e)=>({status:"active",data:void 0,input:e}),getSnapshot:t=>t.data,getStatus:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=function(t,e){return{config:t,transition:(e,n,s)=>t(e,n,s),getInitialState:(t,n)=>"function"==typeof e?e({input:n}):e,getSnapshot:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.getStateNodes=yt,t.interpret=F,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function n(t){}return n.type="xstate.log",n.value=t,n.label=e,n.resolve=zt,n.execute=Ut,n},t.mapState=function(t,e){let n;for(const s of Object.keys(t))b(s,e)&&(!n||e.length>n.length)&&(n=s);return t[n]},t.matchesState=b,t.not=function(t){return{type:"xstate.boolean",params:{op:"not"},children:[K(t)],predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>!t(e.children[0],n,s,i)}},t.or=function(t){return{type:"xstate.boolean",params:{op:"or"},children:t.map((t=>K(t))),predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>e.children.some((e=>t(e,n,s,i)))}},t.pathToStateValue=w,t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=Kt,e},t.raise=Xt,t.sendParent=function(t,e){return d(n.Parent,t,e)},t.sendTo=d,t.stateIn=function(t){return{type:"xstate.guard:in",params:{stateValue:t},predicate:({state:e})=>"string"==typeof t&&rt(t)?e.configuration.some((e=>e.id===t.slice(1))):e.matches(t)}},t.stop=Bt,t.toObserver=M,t.waitFor=function(t,e,n){const s={...oe,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate.umd.min.js.map
|