xstate 5.0.0-beta.26 → 5.0.0-beta.28
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/README.md +9 -7
- package/actions/dist/xstate-actions.cjs.js +14 -18
- package/actions/dist/xstate-actions.cjs.mjs +0 -6
- package/actions/dist/xstate-actions.development.cjs.js +14 -18
- package/actions/dist/xstate-actions.development.cjs.mjs +0 -6
- package/actions/dist/xstate-actions.development.esm.js +3 -1
- package/actions/dist/xstate-actions.esm.js +3 -1
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +439 -14
- package/actors/dist/xstate-actors.cjs.mjs +0 -5
- package/actors/dist/xstate-actors.development.cjs.js +439 -14
- package/actors/dist/xstate-actors.development.cjs.mjs +0 -5
- package/actors/dist/xstate-actors.development.esm.js +435 -1
- package/actors/dist/xstate-actors.esm.js +435 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/Machine.d.ts +4 -3
- package/dist/declarations/src/State.d.ts +1 -1
- package/dist/declarations/src/StateNode.d.ts +3 -12
- package/dist/declarations/src/actions/assign.d.ts +11 -11
- package/dist/declarations/src/actions/cancel.d.ts +5 -12
- package/dist/declarations/src/actions/choose.d.ts +9 -7
- package/dist/declarations/src/actions/log.d.ts +5 -20
- package/dist/declarations/src/actions/pure.d.ts +11 -9
- package/dist/declarations/src/actions/raise.d.ts +6 -5
- package/dist/declarations/src/actions/send.d.ts +7 -12
- package/dist/declarations/src/actions/stop.d.ts +5 -12
- package/dist/declarations/src/actions.d.ts +8 -42
- package/dist/declarations/src/actors/index.d.ts +2 -22
- package/dist/declarations/src/actors/promise.d.ts +2 -1
- package/dist/declarations/src/constants.d.ts +8 -0
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +11 -18
- package/dist/declarations/src/spawn.d.ts +25 -0
- package/dist/declarations/src/stateUtils.d.ts +1 -1
- package/dist/declarations/src/typegenTypes.d.ts +5 -5
- package/dist/declarations/src/types.d.ts +81 -108
- package/dist/declarations/src/utils.d.ts +2 -3
- package/dist/interpreter-672794ae.cjs.js +792 -0
- package/dist/interpreter-a1432c7d.development.cjs.js +800 -0
- package/dist/interpreter-a77bb0ec.development.esm.js +765 -0
- package/dist/interpreter-b5203bcb.esm.js +757 -0
- package/dist/raise-436a57a2.cjs.js +1458 -0
- package/dist/raise-74b72ca5.development.cjs.js +1498 -0
- package/dist/raise-a60c9290.development.esm.js +1468 -0
- package/dist/raise-b9c9a234.esm.js +1428 -0
- package/dist/send-35e1a689.cjs.js +349 -0
- package/dist/send-4192e7bc.esm.js +339 -0
- package/dist/send-e63b7b83.development.esm.js +364 -0
- package/dist/send-e8b55d00.development.cjs.js +374 -0
- package/dist/xstate.cjs.js +140 -160
- package/dist/xstate.cjs.mjs +4 -2
- package/dist/xstate.development.cjs.js +140 -160
- package/dist/xstate.development.cjs.mjs +4 -2
- package/dist/xstate.development.esm.js +75 -95
- package/dist/xstate.esm.js +75 -95
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +7 -6
- package/guards/dist/xstate-guards.development.cjs.js +7 -6
- package/guards/dist/xstate-guards.development.esm.js +2 -1
- package/guards/dist/xstate-guards.esm.js +2 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/actions-0971b43d.development.cjs.js +0 -3168
- package/dist/actions-319cefe7.cjs.js +0 -3095
- package/dist/actions-5943a9db.esm.js +0 -3018
- package/dist/actions-cf69419d.development.esm.js +0 -3091
- package/dist/declarations/src/constantPrefixes.d.ts +0 -6
|
@@ -1,7 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition, isActorRef, toActorRef } from '../actors/dist/xstate-actors.development.esm.js';
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-a77bb0ec.development.esm.js';
|
|
3
|
+
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-a77bb0ec.development.esm.js';
|
|
4
|
+
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-a60c9290.development.esm.js';
|
|
5
|
+
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-a60c9290.development.esm.js';
|
|
6
|
+
import { a as assign } from './send-e63b7b83.development.esm.js';
|
|
7
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-e63b7b83.development.esm.js';
|
|
3
8
|
import '../dev/dist/xstate-dev.development.esm.js';
|
|
4
9
|
|
|
10
|
+
class SimulatedClock {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.timeouts = new Map();
|
|
13
|
+
this._now = 0;
|
|
14
|
+
this._id = 0;
|
|
15
|
+
}
|
|
16
|
+
now() {
|
|
17
|
+
return this._now;
|
|
18
|
+
}
|
|
19
|
+
getId() {
|
|
20
|
+
return this._id++;
|
|
21
|
+
}
|
|
22
|
+
setTimeout(fn, timeout) {
|
|
23
|
+
const id = this.getId();
|
|
24
|
+
this.timeouts.set(id, {
|
|
25
|
+
start: this.now(),
|
|
26
|
+
timeout,
|
|
27
|
+
fn
|
|
28
|
+
});
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
clearTimeout(id) {
|
|
32
|
+
this.timeouts.delete(id);
|
|
33
|
+
}
|
|
34
|
+
set(time) {
|
|
35
|
+
if (this._now > time) {
|
|
36
|
+
throw new Error('Unable to travel back in time');
|
|
37
|
+
}
|
|
38
|
+
this._now = time;
|
|
39
|
+
this.flushTimeouts();
|
|
40
|
+
}
|
|
41
|
+
flushTimeouts() {
|
|
42
|
+
[...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
43
|
+
const endA = timeoutA.start + timeoutA.timeout;
|
|
44
|
+
const endB = timeoutB.start + timeoutB.timeout;
|
|
45
|
+
return endB > endA ? -1 : 1;
|
|
46
|
+
}).forEach(([id, timeout]) => {
|
|
47
|
+
if (this.now() - timeout.start >= timeout.timeout) {
|
|
48
|
+
this.timeouts.delete(id);
|
|
49
|
+
timeout.fn.call(null);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
increment(ms) {
|
|
54
|
+
this._now += ms;
|
|
55
|
+
this.flushTimeouts();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
5
59
|
const EMPTY_OBJECT = {};
|
|
6
60
|
const toSerializableActon = action => {
|
|
7
61
|
if (typeof action === 'string') {
|
|
@@ -76,7 +130,7 @@ class StateNode {
|
|
|
76
130
|
*/
|
|
77
131
|
|
|
78
132
|
/**
|
|
79
|
-
* The output data sent with the "done.state._id_" event if this is a final state node.
|
|
133
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a final state node.
|
|
80
134
|
*/
|
|
81
135
|
|
|
82
136
|
/**
|
|
@@ -194,15 +248,12 @@ class StateNode {
|
|
|
194
248
|
* The logic invoked as actors by this state node.
|
|
195
249
|
*/
|
|
196
250
|
get invoke() {
|
|
197
|
-
return memo(this, 'invoke', () => toArray(this.config.invoke).map((
|
|
198
|
-
const generatedId = createInvokeId(this.id, i);
|
|
199
|
-
const invokeConfig = toInvokeConfig(invocable, generatedId);
|
|
200
|
-
const resolvedId = invokeConfig.id || generatedId;
|
|
201
|
-
const src = invokeConfig.src;
|
|
251
|
+
return memo(this, 'invoke', () => toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
202
252
|
const {
|
|
253
|
+
src,
|
|
203
254
|
systemId
|
|
204
255
|
} = invokeConfig;
|
|
205
|
-
|
|
256
|
+
const resolvedId = invokeConfig.id || createInvokeId(this.id, i);
|
|
206
257
|
// TODO: resolving should not happen here
|
|
207
258
|
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
208
259
|
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
@@ -279,28 +330,6 @@ class StateNode {
|
|
|
279
330
|
return selectedTransition ? [selectedTransition] : undefined;
|
|
280
331
|
}
|
|
281
332
|
|
|
282
|
-
/**
|
|
283
|
-
* The target state value of the history state node, if it exists. This represents the
|
|
284
|
-
* default state value to transition to if no history value exists yet.
|
|
285
|
-
*/
|
|
286
|
-
get target() {
|
|
287
|
-
if (this.type === 'history') {
|
|
288
|
-
const historyConfig = this.config;
|
|
289
|
-
return historyConfig.target;
|
|
290
|
-
}
|
|
291
|
-
return undefined;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* All the state node IDs of this state node and its descendant state nodes.
|
|
296
|
-
*/
|
|
297
|
-
get stateIds() {
|
|
298
|
-
const childStateIds = flatten(Object.keys(this.states).map(stateKey => {
|
|
299
|
-
return this.states[stateKey].stateIds;
|
|
300
|
-
}));
|
|
301
|
-
return [this.id].concat(childStateIds);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
333
|
/**
|
|
305
334
|
* All the event types accepted by this state node and its descendants.
|
|
306
335
|
*/
|
|
@@ -454,7 +483,7 @@ class StateMachine {
|
|
|
454
483
|
*/
|
|
455
484
|
transition(state, event, actorCtx) {
|
|
456
485
|
// TODO: handle error events in a better way
|
|
457
|
-
if (
|
|
486
|
+
if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
458
487
|
return cloneState(state, {
|
|
459
488
|
error: event.data
|
|
460
489
|
});
|
|
@@ -619,69 +648,6 @@ class StateMachine {
|
|
|
619
648
|
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
620
649
|
}
|
|
621
650
|
|
|
622
|
-
function createMachine(config, implementations) {
|
|
623
|
-
return new StateMachine(config, implementations);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
function mapState(stateMap, stateId) {
|
|
627
|
-
let foundStateId;
|
|
628
|
-
for (const mappedStateId of Object.keys(stateMap)) {
|
|
629
|
-
if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
630
|
-
foundStateId = mappedStateId;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
return stateMap[foundStateId];
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
class SimulatedClock {
|
|
637
|
-
constructor() {
|
|
638
|
-
this.timeouts = new Map();
|
|
639
|
-
this._now = 0;
|
|
640
|
-
this._id = 0;
|
|
641
|
-
}
|
|
642
|
-
now() {
|
|
643
|
-
return this._now;
|
|
644
|
-
}
|
|
645
|
-
getId() {
|
|
646
|
-
return this._id++;
|
|
647
|
-
}
|
|
648
|
-
setTimeout(fn, timeout) {
|
|
649
|
-
const id = this.getId();
|
|
650
|
-
this.timeouts.set(id, {
|
|
651
|
-
start: this.now(),
|
|
652
|
-
timeout,
|
|
653
|
-
fn
|
|
654
|
-
});
|
|
655
|
-
return id;
|
|
656
|
-
}
|
|
657
|
-
clearTimeout(id) {
|
|
658
|
-
this.timeouts.delete(id);
|
|
659
|
-
}
|
|
660
|
-
set(time) {
|
|
661
|
-
if (this._now > time) {
|
|
662
|
-
throw new Error('Unable to travel back in time');
|
|
663
|
-
}
|
|
664
|
-
this._now = time;
|
|
665
|
-
this.flushTimeouts();
|
|
666
|
-
}
|
|
667
|
-
flushTimeouts() {
|
|
668
|
-
[...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
669
|
-
const endA = timeoutA.start + timeoutA.timeout;
|
|
670
|
-
const endB = timeoutB.start + timeoutB.timeout;
|
|
671
|
-
return endB > endA ? -1 : 1;
|
|
672
|
-
}).forEach(([id, timeout]) => {
|
|
673
|
-
if (this.now() - timeout.start >= timeout.timeout) {
|
|
674
|
-
this.timeouts.delete(id);
|
|
675
|
-
timeout.fn.call(null);
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
increment(ms) {
|
|
680
|
-
this._now += ms;
|
|
681
|
-
this.flushTimeouts();
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
651
|
const defaultWaitForOptions = {
|
|
686
652
|
timeout: 10_000 // 10 seconds
|
|
687
653
|
};
|
|
@@ -756,4 +722,18 @@ function waitFor(actorRef, predicate, options) {
|
|
|
756
722
|
});
|
|
757
723
|
}
|
|
758
724
|
|
|
725
|
+
function createMachine(config, implementations) {
|
|
726
|
+
return new StateMachine(config, implementations);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function mapState(stateMap, stateId) {
|
|
730
|
+
let foundStateId;
|
|
731
|
+
for (const mappedStateId of Object.keys(stateMap)) {
|
|
732
|
+
if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
733
|
+
foundStateId = mappedStateId;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return stateMap[foundStateId];
|
|
737
|
+
}
|
|
738
|
+
|
|
759
739
|
export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };
|
package/dist/xstate.esm.js
CHANGED
|
@@ -1,7 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition, isActorRef, toActorRef } from '../actors/dist/xstate-actors.esm.js';
|
|
2
|
+
import { S as STATE_DELIMITER, m as mapValues, t as toArray, a as toTransitionConfigArray, N as NULL_EVENT, c as createInvokeId, i as isErrorActorEvent, b as createInitEvent, r as resolveReferencedActor, d as createActor, e as matchesState } from './interpreter-b5203bcb.esm.js';
|
|
3
|
+
export { A as Actor, f as ActorStatus, I as InterpreterStatus, d as createActor, g as interpret, e as matchesState, p as pathToStateValue, h as toObserver } from './interpreter-b5203bcb.esm.js';
|
|
4
|
+
import { f as formatTransitions, a as formatTransition, m as memo, e as evaluateGuard, g as getDelayedTransitions, b as formatInitialTransition, c as getCandidates, d as getConfiguration, h as getStateNodes, r as resolveStateValue, i as isInFinalState, S as State, j as cloneState, k as macrostep, t as transitionNode, l as getInitialConfiguration, n as resolveActionsAndContext, o as microstep, p as isAtomicStateNode, q as isStateId, s as getStateNodeByPath, u as getPersistedState } from './raise-b9c9a234.esm.js';
|
|
5
|
+
export { S as State, v as and, z as cancel, h as getStateNodes, w as not, x as or, A as raise, y as stateIn, B as stop } from './raise-b9c9a234.esm.js';
|
|
6
|
+
import { a as assign } from './send-4192e7bc.esm.js';
|
|
7
|
+
export { S as SpecialTargets, a as assign, c as choose, e as escalate, f as forwardTo, l as log, p as pure, s as sendParent, b as sendTo } from './send-4192e7bc.esm.js';
|
|
3
8
|
import '../dev/dist/xstate-dev.esm.js';
|
|
4
9
|
|
|
10
|
+
class SimulatedClock {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.timeouts = new Map();
|
|
13
|
+
this._now = 0;
|
|
14
|
+
this._id = 0;
|
|
15
|
+
}
|
|
16
|
+
now() {
|
|
17
|
+
return this._now;
|
|
18
|
+
}
|
|
19
|
+
getId() {
|
|
20
|
+
return this._id++;
|
|
21
|
+
}
|
|
22
|
+
setTimeout(fn, timeout) {
|
|
23
|
+
const id = this.getId();
|
|
24
|
+
this.timeouts.set(id, {
|
|
25
|
+
start: this.now(),
|
|
26
|
+
timeout,
|
|
27
|
+
fn
|
|
28
|
+
});
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
clearTimeout(id) {
|
|
32
|
+
this.timeouts.delete(id);
|
|
33
|
+
}
|
|
34
|
+
set(time) {
|
|
35
|
+
if (this._now > time) {
|
|
36
|
+
throw new Error('Unable to travel back in time');
|
|
37
|
+
}
|
|
38
|
+
this._now = time;
|
|
39
|
+
this.flushTimeouts();
|
|
40
|
+
}
|
|
41
|
+
flushTimeouts() {
|
|
42
|
+
[...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
43
|
+
const endA = timeoutA.start + timeoutA.timeout;
|
|
44
|
+
const endB = timeoutB.start + timeoutB.timeout;
|
|
45
|
+
return endB > endA ? -1 : 1;
|
|
46
|
+
}).forEach(([id, timeout]) => {
|
|
47
|
+
if (this.now() - timeout.start >= timeout.timeout) {
|
|
48
|
+
this.timeouts.delete(id);
|
|
49
|
+
timeout.fn.call(null);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
increment(ms) {
|
|
54
|
+
this._now += ms;
|
|
55
|
+
this.flushTimeouts();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
5
59
|
const EMPTY_OBJECT = {};
|
|
6
60
|
const toSerializableActon = action => {
|
|
7
61
|
if (typeof action === 'string') {
|
|
@@ -76,7 +130,7 @@ class StateNode {
|
|
|
76
130
|
*/
|
|
77
131
|
|
|
78
132
|
/**
|
|
79
|
-
* The output data sent with the "done.state._id_" event if this is a final state node.
|
|
133
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a final state node.
|
|
80
134
|
*/
|
|
81
135
|
|
|
82
136
|
/**
|
|
@@ -194,15 +248,12 @@ class StateNode {
|
|
|
194
248
|
* The logic invoked as actors by this state node.
|
|
195
249
|
*/
|
|
196
250
|
get invoke() {
|
|
197
|
-
return memo(this, 'invoke', () => toArray(this.config.invoke).map((
|
|
198
|
-
const generatedId = createInvokeId(this.id, i);
|
|
199
|
-
const invokeConfig = toInvokeConfig(invocable, generatedId);
|
|
200
|
-
const resolvedId = invokeConfig.id || generatedId;
|
|
201
|
-
const src = invokeConfig.src;
|
|
251
|
+
return memo(this, 'invoke', () => toArray(this.config.invoke).map((invokeConfig, i) => {
|
|
202
252
|
const {
|
|
253
|
+
src,
|
|
203
254
|
systemId
|
|
204
255
|
} = invokeConfig;
|
|
205
|
-
|
|
256
|
+
const resolvedId = invokeConfig.id || createInvokeId(this.id, i);
|
|
206
257
|
// TODO: resolving should not happen here
|
|
207
258
|
const resolvedSrc = typeof src === 'string' ? src : !('type' in src) ? resolvedId : src;
|
|
208
259
|
if (!this.machine.implementations.actors[resolvedId] && typeof src !== 'string' && !('type' in src)) {
|
|
@@ -279,28 +330,6 @@ class StateNode {
|
|
|
279
330
|
return selectedTransition ? [selectedTransition] : undefined;
|
|
280
331
|
}
|
|
281
332
|
|
|
282
|
-
/**
|
|
283
|
-
* The target state value of the history state node, if it exists. This represents the
|
|
284
|
-
* default state value to transition to if no history value exists yet.
|
|
285
|
-
*/
|
|
286
|
-
get target() {
|
|
287
|
-
if (this.type === 'history') {
|
|
288
|
-
const historyConfig = this.config;
|
|
289
|
-
return historyConfig.target;
|
|
290
|
-
}
|
|
291
|
-
return undefined;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* All the state node IDs of this state node and its descendant state nodes.
|
|
296
|
-
*/
|
|
297
|
-
get stateIds() {
|
|
298
|
-
const childStateIds = flatten(Object.keys(this.states).map(stateKey => {
|
|
299
|
-
return this.states[stateKey].stateIds;
|
|
300
|
-
}));
|
|
301
|
-
return [this.id].concat(childStateIds);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
333
|
/**
|
|
305
334
|
* All the event types accepted by this state node and its descendants.
|
|
306
335
|
*/
|
|
@@ -454,7 +483,7 @@ class StateMachine {
|
|
|
454
483
|
*/
|
|
455
484
|
transition(state, event, actorCtx) {
|
|
456
485
|
// TODO: handle error events in a better way
|
|
457
|
-
if (
|
|
486
|
+
if (isErrorActorEvent(event) && !state.nextEvents.some(nextEvent => nextEvent === event.type)) {
|
|
458
487
|
return cloneState(state, {
|
|
459
488
|
error: event.data
|
|
460
489
|
});
|
|
@@ -619,69 +648,6 @@ class StateMachine {
|
|
|
619
648
|
/**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
|
|
620
649
|
}
|
|
621
650
|
|
|
622
|
-
function createMachine(config, implementations) {
|
|
623
|
-
return new StateMachine(config, implementations);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
function mapState(stateMap, stateId) {
|
|
627
|
-
let foundStateId;
|
|
628
|
-
for (const mappedStateId of Object.keys(stateMap)) {
|
|
629
|
-
if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
630
|
-
foundStateId = mappedStateId;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
return stateMap[foundStateId];
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
class SimulatedClock {
|
|
637
|
-
constructor() {
|
|
638
|
-
this.timeouts = new Map();
|
|
639
|
-
this._now = 0;
|
|
640
|
-
this._id = 0;
|
|
641
|
-
}
|
|
642
|
-
now() {
|
|
643
|
-
return this._now;
|
|
644
|
-
}
|
|
645
|
-
getId() {
|
|
646
|
-
return this._id++;
|
|
647
|
-
}
|
|
648
|
-
setTimeout(fn, timeout) {
|
|
649
|
-
const id = this.getId();
|
|
650
|
-
this.timeouts.set(id, {
|
|
651
|
-
start: this.now(),
|
|
652
|
-
timeout,
|
|
653
|
-
fn
|
|
654
|
-
});
|
|
655
|
-
return id;
|
|
656
|
-
}
|
|
657
|
-
clearTimeout(id) {
|
|
658
|
-
this.timeouts.delete(id);
|
|
659
|
-
}
|
|
660
|
-
set(time) {
|
|
661
|
-
if (this._now > time) {
|
|
662
|
-
throw new Error('Unable to travel back in time');
|
|
663
|
-
}
|
|
664
|
-
this._now = time;
|
|
665
|
-
this.flushTimeouts();
|
|
666
|
-
}
|
|
667
|
-
flushTimeouts() {
|
|
668
|
-
[...this.timeouts].sort(([_idA, timeoutA], [_idB, timeoutB]) => {
|
|
669
|
-
const endA = timeoutA.start + timeoutA.timeout;
|
|
670
|
-
const endB = timeoutB.start + timeoutB.timeout;
|
|
671
|
-
return endB > endA ? -1 : 1;
|
|
672
|
-
}).forEach(([id, timeout]) => {
|
|
673
|
-
if (this.now() - timeout.start >= timeout.timeout) {
|
|
674
|
-
this.timeouts.delete(id);
|
|
675
|
-
timeout.fn.call(null);
|
|
676
|
-
}
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
increment(ms) {
|
|
680
|
-
this._now += ms;
|
|
681
|
-
this.flushTimeouts();
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
651
|
const defaultWaitForOptions = {
|
|
686
652
|
timeout: 10_000 // 10 seconds
|
|
687
653
|
};
|
|
@@ -753,4 +719,18 @@ function waitFor(actorRef, predicate, options) {
|
|
|
753
719
|
});
|
|
754
720
|
}
|
|
755
721
|
|
|
722
|
+
function createMachine(config, implementations) {
|
|
723
|
+
return new StateMachine(config, implementations);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function mapState(stateMap, stateId) {
|
|
727
|
+
let foundStateId;
|
|
728
|
+
for (const mappedStateId of Object.keys(stateMap)) {
|
|
729
|
+
if (matchesState(mappedStateId, stateId) && (!foundStateId || stateId.length > foundStateId.length)) {
|
|
730
|
+
foundStateId = mappedStateId;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return stateMap[foundStateId];
|
|
734
|
+
}
|
|
735
|
+
|
|
756
736
|
export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };
|
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:`${se(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 l=new WeakMap;function p(t,e,n){let s=l.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},l.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 v(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=y,e.execute=g,e}class m{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=x(t),s=x(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 S(t){try{return O(t)?t:t.toString().split(r)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function x(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(S(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 m(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=ne(this.id,s.data),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(s.data),this._parent?.send(se(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(se(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(se(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 m(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 G=q;function F(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[Bt(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(se(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=F,i.execute=L,i}function H(t,e,{stateValue:n}){return"string"==typeof n&&ut(n)?t.configuration.some((t=>t.id===n.slice(1))):t.matches(n)}function K(t,{context:e,event:n},{guards:s}){return!tt(s[0],e,n,t)}function Y(t,{context:e,event:n},{guards:s}){return s.every((s=>tt(s,e,n,t)))}function Z(t,{context:e,event:n},{guards:s}){return s.some((s=>tt(s,e,n,t)))}function tt(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return tt(r,e,n,s);const a={context:e,event:n,guard:o?void 0:"string"==typeof t?{type:t}:t};if(!("check"in r))return r(a);return r.check(s,a,r)}const et=t=>"atomic"===t.type||"final"===t.type;function nt(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function st(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function it(t){const e=new Set(t),n=new Set(t),s=rt(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 nt(t))if("history"!==e.type&&!n.has(e))for(const t of yt(e))n.add(t)}else yt(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 ot(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(et(t))return t.key}const s={};for(const t of n)s[t.key]=ot(t,e);return s}function rt(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 at(t,e){return ot(t,rt(it(e)))}function ct(t,e=t[0].machine.root){return"compound"===e.type?nt(e).some((e=>"final"===e.type&&t.includes(e))):"parallel"===e.type&&nt(e).every((e=>ct(t,e)))}const ut=t=>"#"===t[0];function ft(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(Yt({type:i},{id:i,delay:n})),t.exit.push(v(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{...ht(t,e.event,e),delay:n}}))}function ht(t,e,n){const s=P(n.target),i=n.reenter??!1,o=dt(t,s),r={...n,actions:I(n.actions),guard:n.guard,target:o,source:t,reenter:i,eventType:e,toJSON:()=>({...r,source:`#${t.id}`,target:o?o.map((t=>`#${t.id}`)):void 0})};return r}function dt(t,e){if(void 0!==e)return e.map((e=>{if("string"!=typeof e)return e;if(ut(e))return t.machine.getStateNodeById(e);const n=e[0]===r;if(n&&!t.parent)return vt(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 vt(t.parent,s)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}function lt(t){const e=P(t.target);return e?e.map((e=>"string"==typeof e?vt(t.parent,e):e)):t.parent.initial.target}function pt(t){return"history"===t.type}function yt(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 st(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of nt(s))n(t)}(t),[...e]}function gt(t,e){if(ut(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 vt(t,e){if("string"==typeof e&&ut(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=S(e).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=gt(s,t)}return s}function mt(t,e){const n=e instanceof Vt?e.value:x(e);if("string"==typeof n)return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>gt(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=gt(t,s);if(!i)return e;const o=mt(i,n[s]);return e.concat(o)}),[]))}function _t(t,e,n,s){return"string"==typeof e?function(t,e,n,s){const i=gt(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=_t(gt(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=_t(gt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function bt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function St(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function xt(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function wt(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(wt(It([i],e,n),It([r],e,n))){if(!St(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 kt(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(pt(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of kt({target:lt(s)},e))n.add(t);else n.add(s);return[...n]}function Et(t,e){const n=kt(t,e);if(!n)return null;if(!t.reenter&&"parallel"!==t.source.type&&n.every((e=>St(e,t.source))))return t.source;return function(t){const[e]=t;let n=xt(e),s=[];for(const e of t){const t=xt(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function It(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=Et(i,n);for(const n of e)St(n,t)&&s.add(n)}return[...s]}function Tt(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=It(t,e,n);i.sort(((t,e)=>e.order-t.order));for(const t of i)for(const s of bt(t)){let i;i="deep"===s.history?e=>et(e)&&St(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=>Wt(t.id)))),e.delete(t)}(c,n,a,r);r.push(...c.flatMap((t=>t.actions))),Ot(s,c,n,r,u,e,a,o,i);const f=[...n],h=ct(f);if(h){const t=f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit));r.push(...t)}try{const t=Nt(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),Bt(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 Bt(r,{value:{}})}function Ot(t,e,n,s,i,o,r,a,c){const u=new Set,f=new Set;jt(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(ee(s.id,e.output?T(e.output,o.context,t,c.self):void 0)),s.parent){const t=s.parent;"parallel"===t.type&&nt(t).every((t=>ct([...n],t)))&&i.push(ee(t.id))}}}}function jt(t,e,n,s){for(const i of t){for(const t of i.target||[])Pt(t,e,n,s);const t=Et(i,e),o=kt(i,e);for(const i of o)Mt(i,t,s,e,n)}}function Pt(t,e,n,s){if(pt(t))if(e[t.id]){const i=e[t.id];for(const t of i)Pt(t,e,n,s);for(const o of i){Mt(o,t.parent,s,e,n);for(const t of n)n.add(t)}}else{const i=lt(t);for(const t of i)Pt(t,e,n,s);for(const o of i){Mt(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)Pt(t,e,n,s);for(const o of i)Mt(o,t,s,e,n)}else if("parallel"===t.type)for(const i of nt(t).filter((t=>!pt(t))))[...s].some((t=>St(t,i)))||Pt(i,e,n,s)}function Mt(t,e,n,s,i){const o=st(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of nt(t).filter((t=>!pt(t))))[...n].some((t=>St(t,e)))||Pt(e,s,i,n)}function Nt(t,e,n,s){const{machine:i}=n;let o=Bt(n,{_internalQueue:[]});for(const n of t){const t="function"==typeof n,r=t?n:i.implementations.actions["string"==typeof n?n:n.type];if(!r)continue;const a={context:o.context,event:e,self:s?.self,system:s?.system,action:t?void 0:"string"==typeof n?{type:n}:n};if(!("resolve"in r)){s?.self.status===B.Running?r(a):s?.defer((()=>r(a)));continue}const c=r,[u,f,h]=c.resolve(s,o,a,r);o=u,"execute"in r&&(s?.self.status===B.Running?c.execute(s,f):s?.defer(c.execute.bind(null,s,f))),h&&(o=Nt(h,e,o,s))}return o}function At(t,e,n){let s=t;const i=[];if(e.type===R)return s=Ct(e,s,n),i.push(s),{state:s,microstates:i};let o=e;if(o.type!==u){s=Tt(Dt(o,s),t,n,o,!1),i.push(s)}for(;!s.done;){let t=Rt(s,o);if(t.length)s=Tt(t,s,n,o,!1),i.push(s);else{if(!s._internalQueue.length)break;o=s._internalQueue[0];s=Tt(Dt(o,s),s,n,o,!1),s._internalQueue.shift(),i.push(s)}}return s.done&&Ct(o,s,n),{state:s,microstates:i}}function Ct(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(Wt(t));return Nt(s,t,e,n)}function Dt(t,e){return e.machine.getTransitionData(e,t)}function Rt(t,e){const n=new Set,s=t.configuration.filter(et);for(const i of s)t:for(const s of[i].concat(st(i,null)))if(s.always)for(const i of s.always)if(void 0===i.guard||tt(i.guard,t.context,e,t)){n.add(i);break t}return $t(Array.from(n),new Set(t.configuration),t.historyValue)}function Qt(t,e){return at(t,[...it(mt(t,e))])}function Jt(t){const e=[],n=t.initial,s=new Set;jt([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}class Vt{static from(t,e={},n){if(t instanceof Vt)return t.context!==e?new Vt({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=it(mt(n.root,t));return new Vt({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(it(mt(e.root,t.value))),this.children=t.children,this.value=at(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 p(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 Bt(t,e={}){return new Vt({...t,...e},t.machine)}function zt(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]),[Bt(e,{children:r}),o]}function Ut(t,e){e&&(e.status===B.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function Wt(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=zt,e.execute=Ut,e}function qt(t,e,n,{value:s,label:i}){return[e,{value:"function"==typeof s?s(n):s,label:i}]}function Gt({logger:t},{value:e,label:n}){n?t(n,e):t(e)}function Ft(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(se(a.id,e))}})),a}}function Lt(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:Ft(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[Bt(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Xt(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=Lt,e}function Ht(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?Bt(e,{_internalQueue:e._internalQueue.concat(a)}):e,{event:a,id:i,delay:c}]}function Kt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Yt(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Ht,n.execute=Kt,n}function Zt(t,e,n,{branches:s}){const i=s.find((t=>!t.guard||tt(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,I(i)]}function te(t,e,n,{get:s}){return[e,void 0,I(s({context:n.context,event:n.event}))]}function ee(t,n){const s=`${e.DoneState}.${t}`,i={type:s,output:n,toString:()=>s};return i}function ne(t,n){const s=`${e.DoneInvoke}.${t}`,i={type:s,output:n,toString:()=>s};return i}function se(t,n){const s=`${e.ErrorPlatform}.${t}`,i={type:s,data:n,toString:()=>s};return i}const ie={},oe=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class re{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 re(t,{_parent:this,_key:e,_machine:this.machine}))):ie,"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).slice(),this.exit=I(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=I(t.tags).slice()}_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=>ht(t,n,e))))}if(t.config.onDone){const n=String(ee(t.id));e.set(n,j(t.config.onDone).map((e=>ht(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=>ht(t,s,e))))}if(n.onError){const s=`error.platform.${n.id}`;e.set(s,j(n.onError).map((e=>ht(t,s,e))))}if(n.onSnapshot){const s=`xstate.snapshot.${n.id}`;e.set(s,j(n.onSnapshot).map((e=>ht(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=>ht(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(oe),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(oe),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(oe)}))),entry:this.entry.map(oe),exit:this.exit.map(oe),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 p(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 p(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 p(this,"delayedTransitions",(()=>ft(this)))}get initial(){return p(this,"initial",(()=>function(t,e){if("string"==typeof e||O(e)){const n=I(e).map((e=>{const n="string"==typeof e?ut(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(!St(n,t))throw new Error(`Invalid initial target: state node #${n.id} is not a descendant of #${t.id}`);return n})),s=dt(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 ht(t,"__INITIAL__",{target:I(e.target).map((t=>"string"==typeof t?ut(t)?t:`${r}${t}`:t)),actions:e.actions})}(this,this.config.initial||[])))}next(t,e){const n=e.type,s=[];let i;const o=p(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||tt(o,a,e,t)}catch(t){const e="string"==typeof o?o:"object"==typeof o?o.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}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 p(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 ae{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.__TActor=void 0,this.__TAction=void 0,this.__TGuard=void 0,this.__TDelay=void 0,this.__TTag=void 0,this.__TInput=void 0,this.__TOutput=void 0,this.__TResolvedTypesMeta=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 re(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 ae(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=it(mt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Qt(this.root,t.value),configuration:n,done:ct(n)})}resolveStateValue(t,...[e]){const n=Qt(this.root,t);return this.resolveState(Vt.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 Bt(t,{error:e.data});const{state:o}=At(t,e,n);return o}microstep(t,e,n){return At(t,e,n).microstates}getTransitionData(t,e){return _t(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:Jt(this.root),children:{}}));if("function"==typeof n){return Nt([Xt((({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=Tt([{target:[...s.configuration].filter(et),source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,n,!0),{state:o}=At(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=ut(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 vt(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 Vt?t:new Vt(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 Vt({...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 ce={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=Vt,t.StateMachine=ae,t.StateNode=re,t.and=function(t){function e(t){return!1}return e.check=Y,e.guards=t,e},t.assign=Xt,t.cancel=v,t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=Zt,e},t.createActor=q,t.createMachine=function(t,e){return new ae(t,e)},t.doneInvoke=ne,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(ne(i,t)),e.canceled=!0}),(t=>{e.canceled=!0,s._parent?.send(se(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=mt,t.interpret=G,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=qt,n.execute=Gt,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){function e(t){return!1}return e.check=K,e.guards=[t],e},t.or=function(t){function e(t){return!1}return e.check=Z,e.guards=t,e},t.pathToStateValue=w,t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=te,e},t.raise=Yt,t.sendParent=function(t,e){return d(n.Parent,t,e)},t.sendTo=d,t.stateIn=function(t){function e(t){return!1}return e.check=H,e.stateValue=t,e},t.stop=Wt,t.toObserver=M,t.waitFor=function(t,e,n){const s={...ce,...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";const e=".",n="",s="",i="xstate.init",o="xstate.error",r="xstate.stop",a=new WeakMap;function c(t,e,n){let s=a.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},a.set(t,s)),s[e]}function u(t,e){return{type:`xstate.done.state.${t}`,output:e}}function f(t,e){return{type:`xstate.done.actor.${t}`,output:e}}function h(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function d(t,e,n,{sendId:s}){return[e,"function"==typeof s?s(n):s]}function l(t,e){t.self.cancel(e)}function p(t){function e(t){}return e.type="xstate.cancel",e.sendId=t,e.resolve=d,e.execute=l,e}class y{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}}function g(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const v=t=>{const e=g();e&&e.register(t)};function m(t){setTimeout((()=>{throw t}))}const _="function"==typeof Symbol&&Symbol.observable||"@@observable";function b(t,e){const n=w(t),s=w(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(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function w(t){if("object"==typeof(e=t)&&"value"in e&&"context"in e&&"event"in e)return t.value;var e;if(O(t))return S(t);if("string"!=typeof t)return t;return S(x(t))}function S(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 T(t){return void 0===t?[]:E(t)}function I(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 M(t){if(void 0!==t&&t!==n)return T(t)}function N(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 P(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}let A=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const R=A,C={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class D{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 y(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=A.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={...C,...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){m(t)}const s=this.logic.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._complete(),this._doneEvent=f(this.id,s.data),this._parent?.send(this._doneEvent);break;case"error":this._stopProcedure(),this._error(s.data),this._parent?.send(h(this.id,s.data))}}subscribe(t,e,n){const s=N(t,e,n);if(this.status!==A.Stopped)this.observers.add(s);else try{s.complete?.()}catch(t){m(t)}return{unsubscribe:()=>{this.observers.delete(s)}}}start(){if(this.status===A.Running)return this;this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=A.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(h(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(h(this.id,t))}this.update(e),t.type===r&&(this._stopProcedure(),this._complete())}_stop(){return this.status===A.Stopped?this:(this.mailbox.clear(),this.status===A.NotStarted?(this.status=A.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){m(t)}this.observers.clear()}_error(t){if(!this.observers.size)return void(this._parent||m(t));let e=!1;for(const n of this.observers){const s=n.error;e||=!s;try{s?.(t)}catch(t){m(t)}}this.observers.clear(),e&&m(t)}_stopProcedure(){if(this.status!==A.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new y(this._process.bind(this)),this.status=A.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!==A.Stopped){if(this.status!==A.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:v)(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 D(t,e)}const J=Q;function V(t,e,n,{id:s,systemId:i,src:o,input:r}){const a=P(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[Rt(e,{children:{...e.children,[s]:c}}),{id:s,actorRef:c}]}function B(t,{id:e,actorRef:n}){n&&t.defer((()=>{if(n.status!==A.Stopped)try{n.start?.()}catch(n){return void t.self.send(h(e,n))}}))}function z({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=V,i.execute=B,i}function U(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]),[Rt(e,{children:r}),o]}function W(t,e){e&&(e.status===A.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function q(t){function e(t){}return e.type="xstate.stop",e.actorRef=t,e.resolve=U,e.execute=W,e}function G(t,e,{stateValue:n}){return"string"==typeof n&&ot(n)?t.configuration.some((t=>t.id===n.slice(1))):t.matches(n)}function F(t,{context:e,event:n},{guards:s}){return!H(s[0],e,n,t)}function L(t,{context:e,event:n},{guards:s}){return s.every((s=>H(s,e,n,t)))}function X(t,{context:e,event:n},{guards:s}){return s.some((s=>H(s,e,n,t)))}function H(t,e,n,s){const{machine:i}=s,o="function"==typeof t,r=o?t:i.implementations.guards["string"==typeof t?t:t.type];if(!o&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return H(r,e,n,s);const a={context:e,event:n,guard:o?void 0:"string"==typeof t?{type:t}:"function"==typeof t.params?{type:t.type,params:t.params({context:e,event:n})}:t};if(!("check"in r))return r(a);return r.check(s,a,r)}const K=t=>"atomic"===t.type||"final"===t.type;function Y(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function Z(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function tt(t){const e=new Set(t),n=new Set(t),s=nt(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 Y(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 et(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(K(t))return t.key}const s={};for(const t of n)s[t.key]=et(t,e);return s}function nt(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 st(t,e){return et(t,nt(tt(e)))}function it(t,e=t[0].machine.root){return"compound"===e.type?Y(e).some((e=>"final"===e.type&&t.includes(e))):"parallel"===e.type&&Y(e).every((e=>it(t,e)))}const ot=t=>"#"===t[0];function rt(t,e,n){const s=M(n.target),i=n.reenter??!1,o=at(t,s),r={...n,actions:T(n.actions),guard:n.guard,target:o,source:t,reenter:i,eventType:e,toJSON:()=>({...r,source:`#${t.id}`,target:o?o.map((t=>`#${t.id}`)):void 0})};return r}function at(t,n){if(void 0!==n)return n.map((n=>{if("string"!=typeof n)return n;if(ot(n))return t.machine.getStateNodeById(n);const s=n[0]===e;if(s&&!t.parent)return dt(t,n.slice(1));const i=s?t.key+n:n;if(!t.parent)throw new Error(`Invalid target: "${n}" is not a valid target from the root node. Did you mean ".${n}"?`);try{return dt(t.parent,i)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}function ct(t){const e=M(t.config.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 Z(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of Y(s))n(t)}(t),[...e]}function ht(t,e){if(ot(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&&ot(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 lt(t,e){const n=e instanceof At?e.value:w(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=lt(i,n[s]);return e.concat(o)}),[]))}function pt(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=pt(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=pt(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 vt(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function mt(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(mt(wt([i],e,n),wt([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=vt(e),s=[];for(const e of t){const t=vt(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function wt(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 St(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),f=[...e._internalQueue];o||function(t,e,n,s){const i=wt(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=>K(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=>q(t.id)))),e.delete(t)}(c,n,a,r);r.push(...c.flatMap((t=>t.actions))),function(t,e,n,s,i,o,r,a,c){const f=new Set,h=new Set;$t(e,r,h,f),a&&h.add(o.machine.root);for(const e of[...f].sort(((t,e)=>t.order-e.order))){n.add(e);for(const t of e.invoke)s.push(z(t));if(s.push(...e.entry),h.has(e))for(const t of h){const e=t.initial.actions;s.push(...e)}if("final"===e.type){const s=e.parent;if(!s.parent)continue;if(i.push(u(s.id,e.output?I(e.output,o.context,t,c.self):void 0)),s.parent){const t=s.parent;"parallel"===t.type&&Y(t).every((t=>it([...n],t)))&&i.push(u(t.id))}}}}(s,c,n,r,f,e,a,o,i);const h=[...n],d=it(h);if(d){const t=h.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit));r.push(...t)}try{const t=Tt(r,s,e,i),n=d?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?I(o.output,e,n,s):void 0}(h,t.context,s,i.self):void 0;return f.push(...t._internalQueue),Rt(e,{configuration:h,historyValue:a,_internalQueue:f,context:t.context,done:d,output:n,children:t.children})}catch(t){throw t}}(t,e,o,s,n,i);return Rt(r,{value:{}})}function $t(t,e,n,s){for(const i of t){for(const t of i.target||[])kt(t,e,n,s);const t=xt(i,e),o=bt(i,e);for(const i of o)Et(i,t,s,e,n)}}function kt(t,e,n,s){if(ut(t))if(e[t.id]){const i=e[t.id];for(const t of i)kt(t,e,n,s);for(const o of i){Et(o,t.parent,s,e,n);for(const t of n)n.add(t)}}else{const i=ct(t);for(const t of i)kt(t,e,n,s);for(const o of i){Et(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)kt(t,e,n,s);for(const o of i)Et(o,t,s,e,n)}else if("parallel"===t.type)for(const i of Y(t).filter((t=>!ut(t))))[...s].some((t=>gt(t,i)))||kt(i,e,n,s)}function Et(t,e,n,s,i){const o=Z(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of Y(t).filter((t=>!ut(t))))[...n].some((t=>gt(t,e)))||kt(e,s,i,n)}function Tt(t,e,n,s){const{machine:i}=n;let o=Rt(n,{_internalQueue:[]});for(const n of t){const t="function"==typeof n,r=t?n:i.implementations.actions["string"==typeof n?n:n.type];if(!r)continue;const a={context:o.context,event:e,self:s?.self,system:s?.system,action:t?void 0:"string"==typeof n?{type:n}:"function"==typeof n.params?{type:n.type,params:n.params({context:o.context,event:e})}:n};if(!("resolve"in r)){s?.self.status===A.Running?r(a):s?.defer((()=>r(a)));continue}const c=r,[u,f,h]=c.resolve(s,o,a,r);o=u,"execute"in r&&(s?.self.status===A.Running?c.execute(s,f):s?.defer(c.execute.bind(null,s,f))),h&&(o=Tt(h,e,o,s))}return o}function It(t,e,n){let s=t;const o=[];if(e.type===r)return s=Ot(e,s,n),o.push(s),{state:s,microstates:o};let a=e;if(a.type!==i){s=St(jt(a,s),t,n,a,!1),o.push(s)}for(;!s.done;){let t=Mt(s,a);if(t.length)s=St(t,s,n,a,!1),o.push(s);else{if(!s._internalQueue.length)break;a=s._internalQueue[0];s=St(jt(a,s),s,n,a,!1),s._internalQueue.shift(),o.push(s)}}return s.done&&Ot(a,s,n),{state:s,microstates:o}}function Ot(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(q(t));return Tt(s,t,e,n)}function jt(t,e){return e.machine.getTransitionData(e,t)}function Mt(t,e){const n=new Set,s=t.configuration.filter(K);for(const i of s)t:for(const s of[i].concat(Z(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 _t(Array.from(n),new Set(t.configuration),t.historyValue)}function Nt(t,e){return st(t,[...tt(lt(t,e))])}function Pt(t){const e=[],n=t.initial,s=new Set;$t([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}class At{static from(t,e={},n){if(t instanceof At)return t.context!==e?new At({value:t.value,context:e,meta:{},configuration:[],children:{}},n):t;const s=tt(lt(n.root,t));return new At({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(tt(lt(e.root,t.value))),this.children=t.children,this.value=st(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 n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n]).map((t=>n+e+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 c(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 Rt(t,e={}){return new At({...t,...e},t.machine)}function Ct(t,{machine:e,context:n},s,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a}=r;if("string"==typeof o){const c=P(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!==A.Stopped)try{a.start?.()}catch(e){return void t.self.send(h(a.id,e))}})),a}}function Dt(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:Ct(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[Rt(e,{context:Object.assign({},e.context,r),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Qt(t){function e(t){}return e.type="xstate.assign",e.assignment=t,e.resolve=Dt,e}function Jt(t,e,n,{branches:s}){const i=s.find((t=>!t.guard||H(t.guard,e.context,n.event,e)))?.actions;return[e,void 0,T(i)]}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,e,n,{get:s}){return[e,void 0,T(s({context:n.context,event:n.event}))]}function Ut(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?Rt(e,{_internalQueue:e._internalQueue.concat(a)}):e,{event:a,id:i,delay:c}]}function Wt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function qt(t,e){function n(t){}return n.type="xstate.raise",n.event=t,n.id=e?.id,n.delay=e?.delay,n.resolve=Ut,n.execute=Wt,n}let Gt=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Ft(t,e,n,{to:s,event:i,id:o,delay:r}){const a=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const c="function"==typeof i?i(n):i;let u;if("string"==typeof r){const t=a&&a[r];u="function"==typeof t?t(n):t}else u="function"==typeof r?r(n):r;const f="function"==typeof s?s(n):s;let h;if("string"==typeof f){if(h=f===Gt.Parent?t?.self._parent:f===Gt.Internal?t?.self:f.startsWith("#_")?e.children[f.slice(2)]:e.children[f],!h)throw new Error(`Unable to send event to actor '${f}' from machine '${e.machine.id}'.`)}else h=f||t?.self;return[e,{to:h,event:c,id:o,delay:u}]}function Lt(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?h(t.self.id,s.data):s)}))}function Xt(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=Ft,s.execute=Lt,s}function Ht(t,e){return Xt(Gt.Parent,t,e)}function Kt(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}}const Yt="$$xstate.resolve",Zt="$$xstate.reject";const te=Kt((t=>{}),void 0);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,n){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=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(e),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=T(this.config.entry).slice(),this.exit=T(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=T(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const n of Object.keys(t.config.on)){if(n===s)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const i=t.config.on[n];e.set(n,j(i).map((e=>rt(t,n,e))))}if(t.config.onDone){const n=`xstate.done.state.${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=`xstate.done.actor.${n.id}`;e.set(s,j(n.onDone).map((e=>rt(t,s,e))))}if(n.onError){const s=`xstate.error.actor.${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,s,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 c(this,"invoke",(()=>T(this.config.invoke).map(((t,e)=>{const{src:n,systemId:s}=t,i=t.id||`${this.id}:invocation[${e}]`;const o="string"==typeof n||"type"in n?n:i;return this.machine.implementations.actors[i]||"string"==typeof n||"type"in n||(this.machine.implementations.actors={...this.machine.implementations.actors,[i]:n}),{...t,src:o,id:i,systemId:s,toJSON(){const{onDone:e,onError:n,...s}=t;return{...s,type:"xstate.invoke",src:o,id:i}}}}))))}get on(){return c(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 c(this,"delayedTransitions",(()=>function(t){const e=t.config.after;if(!e)return[];const n=(e,n)=>{const s=(o="function"==typeof e?`${t.id}:delay[${n}]`:e,r=t.id,{type:`xstate.after(${o})${r?`#${r}`:""}`}),i=s.type;var o,r;return t.entry.push(qt(s,{id:i,delay:e})),t.exit.push(p(i)),i};return(O(e)?e.map(((t,e)=>{const s=n(t.delay,e);return{...t,event:s}})):Object.keys(e).flatMap(((t,s)=>{const i=e[t],o="string"==typeof i?{target:i}:i,r=isNaN(+t)?t:+t,a=n(r,s);return T(o).map((t=>({...t,event:a,delay:r})))}))).map((e=>{const{delay:n}=e;return{...rt(t,e.event,e),delay:n}}))}(this)))}get initial(){return c(this,"initial",(()=>function(t,n){if("string"==typeof n||O(n)){const e=T(n).map((e=>{const n="string"==typeof e?ot(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,e),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:T(n.target).map((t=>"string"==typeof t?ot(t)?t:`${e}${t}`:t)),actions:n.actions})}(this,this.config.initial||[])))}next(t,e){const n=e.type,s=[];let i;const o=c(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){const e="string"==typeof o?o:"object"==typeof o?o.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}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 events(){return c(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.__TActor=void 0,this.__TAction=void 0,this.__TGuard=void 0,this.__TDelay=void 0,this.__TTag=void 0,this.__TInput=void 0,this.__TOutput=void 0,this.__TResolvedTypesMeta=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=tt(lt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Nt(this.root,t.value),configuration:n,done:it(n)})}resolveStateValue(t,...[e]){const n=Nt(this.root,t);return this.resolveState(At.from(n,e,this))}transition(t,e,n){if(function(t){return t.type.startsWith("xstate.error.actor")}(e)&&!t.nextEvents.some((t=>t===e.type)))return Rt(t,{error:e.data});const{state:s}=It(t,e,n);return s}microstep(t,e,n){return It(t,e,n).microstates}getTransitionData(t,e){return pt(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:Pt(this.root),children:{}}));if("function"==typeof n){return Tt([Qt((({spawn:t,event:e})=>n({spawn:t,input:e.input})))],e,s,t)}return s}getInitialState(t,e){const n=function(t){return{type:i,input:t}}(e),s=this.getPreInitialState(t,n),o=St([{target:[...s.configuration].filter(K),source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],s,t,n,!0),{state:r}=It(o,n,t);return r}start(t){Object.values(t.children).forEach((t=>{0===t.status&&t.start?.()}))}getStateNodeById(t){const n=t.split(e),s=n.slice(1),i=ot(n[0])?n[0].slice(1):n[0],o=this.idMap.get(i);if(!o)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return dt(o,s)}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 At?t:new At(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?P(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 At({...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=P(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=D,t.ActorStatus=A,t.InterpreterStatus=R,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=Gt,t.State=At,t.StateMachine=ie,t.StateNode=se,t.and=function(t){function e(t){return!1}return e.check=L,e.guards=t,e},t.assign=Qt,t.cancel=p,t.choose=function(t){function e(t){}return e.type="xstate.choose",e.branches=t,e.resolve=Jt,e},t.createActor=Q,t.createEmptyActor=function(){return Q(te)},t.createMachine=function(t,e){return new ie(t,e)},t.escalate=function(t,e){return Ht((e=>({type:o,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return Xt(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(t,{self:e})=>{e.send({type:i})},transition:(e,n,{self:s,id:o,system:a})=>{if(n.type===i){const n=t=>{e.canceled||s._parent?.send(t)},i=t=>{e.receivers.add(t)};return e.dispose=t({input:e.input,system:a,self:s,sendBack:n,receive:i}),((c=e.dispose)instanceof Promise||null!==c&&("function"==typeof c||"object"==typeof c)&&"function"==typeof c.then)&&e.dispose.then((t=>{s._parent?.send(f(o,t)),e.canceled=!0}),(t=>{e.canceled=!0,s._parent?.send(h(o,t))})),e}var c;return n.type===r?(e.canceled=!0,"function"==typeof e.dispose&&e.dispose(),e):(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:a,defer:c})=>{if("active"!==t.status)return t;switch(i.type){case e:return c((()=>{o._parent?.send({type:`xstate.snapshot.${a}`,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 Yt:return{...t,status:"done",data:e.data,input:void 0};case Zt: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:Yt,data:t})}),(t=>{"active"===n._state.status&&n.send({type:Zt,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=Kt,t.getStateNodes=lt,t.interpret=J,t.isActorRef=function(t){return!!t&&"object"==typeof t&&"function"==typeof t.send},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){function e(t){return!1}return e.check=F,e.guards=[t],e},t.or=function(t){function e(t){return!1}return e.check=X,e.guards=t,e},t.pathToStateValue=S,t.pure=function(t){function e(t){}return e.type="xstate.pure",e.get=t,e.resolve=zt,e},t.raise=qt,t.sendParent=Ht,t.sendTo=Xt,t.stateIn=function(t){function e(t){return!1}return e.check=G,e.stateValue=t,e},t.stop=q,t.toActorRef=function(t){return{subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",sessionId:"",getSnapshot:()=>{},[_]:function(){return this},status:A.Running,stop:()=>{},...t}},t.toObserver=N,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
|