xstate 5.0.0-beta.52 → 5.0.0-beta.53

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.
Files changed (40) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +17 -17
  8. package/actors/dist/xstate-actors.development.cjs.js +17 -17
  9. package/actors/dist/xstate-actors.development.esm.js +17 -17
  10. package/actors/dist/xstate-actors.esm.js +17 -17
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/State.d.ts +2 -2
  14. package/dist/declarations/src/StateMachine.d.ts +4 -4
  15. package/dist/declarations/src/StateNode.d.ts +1 -1
  16. package/dist/declarations/src/actors/transition.d.ts +1 -1
  17. package/dist/declarations/src/guards.d.ts +1 -1
  18. package/dist/declarations/src/interpreter.d.ts +5 -5
  19. package/dist/declarations/src/stateUtils.d.ts +9 -9
  20. package/dist/declarations/src/types.d.ts +14 -10
  21. package/dist/{log-826c9895.development.esm.js → log-1fd7d00a.development.esm.js} +23 -23
  22. package/dist/{log-6bc0e1e7.esm.js → log-60ab9eaf.esm.js} +23 -23
  23. package/dist/{log-3d815f5e.cjs.js → log-717bb5a1.cjs.js} +23 -23
  24. package/dist/{log-d160285c.development.cjs.js → log-c8797128.development.cjs.js} +23 -23
  25. package/dist/{raise-1caefe80.development.esm.js → raise-953b1eb5.development.esm.js} +127 -127
  26. package/dist/{raise-367eeb6f.cjs.js → raise-a8367773.cjs.js} +127 -127
  27. package/dist/{raise-f71460d6.esm.js → raise-be2f20bc.esm.js} +127 -127
  28. package/dist/{raise-9dd3e757.development.cjs.js → raise-d9fd8932.development.cjs.js} +127 -127
  29. package/dist/xstate.cjs.js +17 -17
  30. package/dist/xstate.development.cjs.js +17 -17
  31. package/dist/xstate.development.esm.js +19 -19
  32. package/dist/xstate.esm.js +19 -19
  33. package/dist/xstate.umd.min.js +1 -1
  34. package/dist/xstate.umd.min.js.map +1 -1
  35. package/guards/dist/xstate-guards.cjs.js +1 -1
  36. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  37. package/guards/dist/xstate-guards.development.esm.js +1 -1
  38. package/guards/dist/xstate-guards.esm.js +1 -1
  39. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  40. package/package.json +1 -1
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-367eeb6f.cjs.js');
7
- var log = require('./log-3d815f5e.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-a8367773.cjs.js');
7
+ var log = require('./log-717bb5a1.cjs.js');
8
8
  require('../dev/dist/xstate-dev.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -297,7 +297,7 @@ class StateNode {
297
297
  get initial() {
298
298
  return memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial));
299
299
  }
300
- next(state, event) {
300
+ next(snapshot, event) {
301
301
  const eventType = event.type;
302
302
  const actions = [];
303
303
  let selectedTransition;
@@ -306,10 +306,10 @@ class StateNode {
306
306
  const {
307
307
  guard
308
308
  } = candidate;
309
- const resolvedContext = state.context;
309
+ const resolvedContext = snapshot.context;
310
310
  let guardPassed = false;
311
311
  try {
312
- guardPassed = !guard || guards_dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, state);
312
+ guardPassed = !guard || guards_dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, snapshot);
313
313
  } catch (err) {
314
314
  const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
315
315
  throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
@@ -390,7 +390,7 @@ class StateMachine {
390
390
  this.version = this.config.version;
391
391
  this.transition = this.transition.bind(this);
392
392
  this.getInitialState = this.getInitialState.bind(this);
393
- this.restoreState = this.restoreState.bind(this);
393
+ this.restoreSnapshot = this.restoreSnapshot.bind(this);
394
394
  this.start = this.start.bind(this);
395
395
  this.root = new StateNode(config, {
396
396
  _key: this.id,
@@ -458,7 +458,7 @@ class StateMachine {
458
458
  * @param event The received event
459
459
  */
460
460
  transition(snapshot, event, actorScope) {
461
- return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).state;
461
+ return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).snapshot;
462
462
  }
463
463
 
464
464
  /**
@@ -468,8 +468,8 @@ class StateMachine {
468
468
  * @param state The current state
469
469
  * @param event The received event
470
470
  */
471
- microstep(state, event, actorScope) {
472
- return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
471
+ microstep(snapshot, event, actorScope) {
472
+ return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).microstates;
473
473
  }
474
474
  getTransitionData(snapshot, event) {
475
475
  return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
@@ -518,12 +518,12 @@ class StateMachine {
518
518
  toJSON: null // TODO: fix
519
519
  }], preInitialState, actorScope, initEvent, true, internalQueue);
520
520
  const {
521
- state: macroState
521
+ snapshot: macroState
522
522
  } = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
523
523
  return macroState;
524
524
  }
525
- start(state) {
526
- Object.values(state.children).forEach(child => {
525
+ start(snapshot) {
526
+ Object.values(snapshot.children).forEach(child => {
527
527
  if (child.getSnapshot().status === 'active') {
528
528
  child.start();
529
529
  }
@@ -545,15 +545,15 @@ class StateMachine {
545
545
  toJSON() {
546
546
  return this.definition;
547
547
  }
548
- getPersistedState(state, options) {
549
- return guards_dist_xstateGuards.getPersistedState(state, options);
548
+ getPersistedSnapshot(snapshot, options) {
549
+ return guards_dist_xstateGuards.getPersistedSnapshot(snapshot, options);
550
550
  }
551
- restoreState(snapshot, _actorScope) {
551
+ restoreSnapshot(snapshot, _actorScope) {
552
552
  const children = {};
553
553
  const snapshotChildren = snapshot.children;
554
554
  Object.keys(snapshotChildren).forEach(actorId => {
555
555
  const actorData = snapshotChildren[actorId];
556
- const childState = actorData.state;
556
+ const childState = actorData.snapshot;
557
557
  const src = actorData.src;
558
558
  const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
559
559
  if (!logic) {
@@ -563,7 +563,7 @@ class StateMachine {
563
563
  id: actorId,
564
564
  parent: _actorScope?.self,
565
565
  syncSnapshot: actorData.syncSnapshot,
566
- state: childState,
566
+ snapshot: childState,
567
567
  src,
568
568
  systemId: actorData.systemId
569
569
  });
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-9dd3e757.development.cjs.js');
7
- var log = require('./log-d160285c.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-d9fd8932.development.cjs.js');
7
+ var log = require('./log-c8797128.development.cjs.js');
8
8
  require('../dev/dist/xstate-dev.development.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -297,7 +297,7 @@ class StateNode {
297
297
  get initial() {
298
298
  return memo(this, 'initial', () => guards_dist_xstateGuards.formatInitialTransition(this, this.config.initial));
299
299
  }
300
- next(state, event) {
300
+ next(snapshot, event) {
301
301
  const eventType = event.type;
302
302
  const actions = [];
303
303
  let selectedTransition;
@@ -306,10 +306,10 @@ class StateNode {
306
306
  const {
307
307
  guard
308
308
  } = candidate;
309
- const resolvedContext = state.context;
309
+ const resolvedContext = snapshot.context;
310
310
  let guardPassed = false;
311
311
  try {
312
- guardPassed = !guard || guards_dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, state);
312
+ guardPassed = !guard || guards_dist_xstateGuards.evaluateGuard(guard, resolvedContext, event, snapshot);
313
313
  } catch (err) {
314
314
  const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
315
315
  throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
@@ -390,7 +390,7 @@ class StateMachine {
390
390
  this.version = this.config.version;
391
391
  this.transition = this.transition.bind(this);
392
392
  this.getInitialState = this.getInitialState.bind(this);
393
- this.restoreState = this.restoreState.bind(this);
393
+ this.restoreSnapshot = this.restoreSnapshot.bind(this);
394
394
  this.start = this.start.bind(this);
395
395
  this.root = new StateNode(config, {
396
396
  _key: this.id,
@@ -461,7 +461,7 @@ class StateMachine {
461
461
  * @param event The received event
462
462
  */
463
463
  transition(snapshot, event, actorScope) {
464
- return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).state;
464
+ return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).snapshot;
465
465
  }
466
466
 
467
467
  /**
@@ -471,8 +471,8 @@ class StateMachine {
471
471
  * @param state The current state
472
472
  * @param event The received event
473
473
  */
474
- microstep(state, event, actorScope) {
475
- return guards_dist_xstateGuards.macrostep(state, event, actorScope).microstates;
474
+ microstep(snapshot, event, actorScope) {
475
+ return guards_dist_xstateGuards.macrostep(snapshot, event, actorScope).microstates;
476
476
  }
477
477
  getTransitionData(snapshot, event) {
478
478
  return guards_dist_xstateGuards.transitionNode(this.root, snapshot.value, snapshot, event) || [];
@@ -521,12 +521,12 @@ class StateMachine {
521
521
  toJSON: null // TODO: fix
522
522
  }], preInitialState, actorScope, initEvent, true, internalQueue);
523
523
  const {
524
- state: macroState
524
+ snapshot: macroState
525
525
  } = guards_dist_xstateGuards.macrostep(nextState, initEvent, actorScope, internalQueue);
526
526
  return macroState;
527
527
  }
528
- start(state) {
529
- Object.values(state.children).forEach(child => {
528
+ start(snapshot) {
529
+ Object.values(snapshot.children).forEach(child => {
530
530
  if (child.getSnapshot().status === 'active') {
531
531
  child.start();
532
532
  }
@@ -548,15 +548,15 @@ class StateMachine {
548
548
  toJSON() {
549
549
  return this.definition;
550
550
  }
551
- getPersistedState(state, options) {
552
- return guards_dist_xstateGuards.getPersistedState(state, options);
551
+ getPersistedSnapshot(snapshot, options) {
552
+ return guards_dist_xstateGuards.getPersistedSnapshot(snapshot, options);
553
553
  }
554
- restoreState(snapshot, _actorScope) {
554
+ restoreSnapshot(snapshot, _actorScope) {
555
555
  const children = {};
556
556
  const snapshotChildren = snapshot.children;
557
557
  Object.keys(snapshotChildren).forEach(actorId => {
558
558
  const actorData = snapshotChildren[actorId];
559
- const childState = actorData.state;
559
+ const childState = actorData.snapshot;
560
560
  const src = actorData.src;
561
561
  const logic = typeof src === 'string' ? guards_dist_xstateGuards.resolveReferencedActor(this, src) : src;
562
562
  if (!logic) {
@@ -566,7 +566,7 @@ class StateMachine {
566
566
  id: actorId,
567
567
  parent: _actorScope?.self,
568
568
  syncSnapshot: actorData.syncSnapshot,
569
- state: childState,
569
+ snapshot: childState,
570
570
  src,
571
571
  systemId: actorData.systemId
572
572
  });
@@ -1,8 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
2
- import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedState, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-1caefe80.development.esm.js';
3
- export { A as Actor, G as __unsafe_getAllOwnEventDescriptors, H as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, D as matchesState, I as not, J as or, E as pathToStateValue, M as raise, O as spawnChild, K as stateIn, P as stop, Q as stopChild, F as toObserver } from './raise-1caefe80.development.esm.js';
4
- import { a as assign } from './log-826c9895.development.esm.js';
5
- export { S as SpecialTargets, a as assign, e as enqueueActions, b as escalate, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-826c9895.development.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-953b1eb5.development.esm.js';
3
+ export { A as Actor, G as __unsafe_getAllOwnEventDescriptors, H as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, D as matchesState, I as not, J as or, E as pathToStateValue, M as raise, O as spawnChild, K as stateIn, P as stop, Q as stopChild, F as toObserver } from './raise-953b1eb5.development.esm.js';
4
+ import { a as assign } from './log-1fd7d00a.development.esm.js';
5
+ export { S as SpecialTargets, a as assign, e as enqueueActions, b as escalate, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-1fd7d00a.development.esm.js';
6
6
  import '../dev/dist/xstate-dev.development.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -295,7 +295,7 @@ class StateNode {
295
295
  get initial() {
296
296
  return memo(this, 'initial', () => formatInitialTransition(this, this.config.initial));
297
297
  }
298
- next(state, event) {
298
+ next(snapshot, event) {
299
299
  const eventType = event.type;
300
300
  const actions = [];
301
301
  let selectedTransition;
@@ -304,10 +304,10 @@ class StateNode {
304
304
  const {
305
305
  guard
306
306
  } = candidate;
307
- const resolvedContext = state.context;
307
+ const resolvedContext = snapshot.context;
308
308
  let guardPassed = false;
309
309
  try {
310
- guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, state);
310
+ guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, snapshot);
311
311
  } catch (err) {
312
312
  const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
313
313
  throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
@@ -388,7 +388,7 @@ class StateMachine {
388
388
  this.version = this.config.version;
389
389
  this.transition = this.transition.bind(this);
390
390
  this.getInitialState = this.getInitialState.bind(this);
391
- this.restoreState = this.restoreState.bind(this);
391
+ this.restoreSnapshot = this.restoreSnapshot.bind(this);
392
392
  this.start = this.start.bind(this);
393
393
  this.root = new StateNode(config, {
394
394
  _key: this.id,
@@ -459,7 +459,7 @@ class StateMachine {
459
459
  * @param event The received event
460
460
  */
461
461
  transition(snapshot, event, actorScope) {
462
- return macrostep(snapshot, event, actorScope).state;
462
+ return macrostep(snapshot, event, actorScope).snapshot;
463
463
  }
464
464
 
465
465
  /**
@@ -469,8 +469,8 @@ class StateMachine {
469
469
  * @param state The current state
470
470
  * @param event The received event
471
471
  */
472
- microstep(state, event, actorScope) {
473
- return macrostep(state, event, actorScope).microstates;
472
+ microstep(snapshot, event, actorScope) {
473
+ return macrostep(snapshot, event, actorScope).microstates;
474
474
  }
475
475
  getTransitionData(snapshot, event) {
476
476
  return transitionNode(this.root, snapshot.value, snapshot, event) || [];
@@ -519,12 +519,12 @@ class StateMachine {
519
519
  toJSON: null // TODO: fix
520
520
  }], preInitialState, actorScope, initEvent, true, internalQueue);
521
521
  const {
522
- state: macroState
522
+ snapshot: macroState
523
523
  } = macrostep(nextState, initEvent, actorScope, internalQueue);
524
524
  return macroState;
525
525
  }
526
- start(state) {
527
- Object.values(state.children).forEach(child => {
526
+ start(snapshot) {
527
+ Object.values(snapshot.children).forEach(child => {
528
528
  if (child.getSnapshot().status === 'active') {
529
529
  child.start();
530
530
  }
@@ -546,15 +546,15 @@ class StateMachine {
546
546
  toJSON() {
547
547
  return this.definition;
548
548
  }
549
- getPersistedState(state, options) {
550
- return getPersistedState(state, options);
549
+ getPersistedSnapshot(snapshot, options) {
550
+ return getPersistedSnapshot(snapshot, options);
551
551
  }
552
- restoreState(snapshot, _actorScope) {
552
+ restoreSnapshot(snapshot, _actorScope) {
553
553
  const children = {};
554
554
  const snapshotChildren = snapshot.children;
555
555
  Object.keys(snapshotChildren).forEach(actorId => {
556
556
  const actorData = snapshotChildren[actorId];
557
- const childState = actorData.state;
557
+ const childState = actorData.snapshot;
558
558
  const src = actorData.src;
559
559
  const logic = typeof src === 'string' ? resolveReferencedActor(this, src) : src;
560
560
  if (!logic) {
@@ -564,7 +564,7 @@ class StateMachine {
564
564
  id: actorId,
565
565
  parent: _actorScope?.self,
566
566
  syncSnapshot: actorData.syncSnapshot,
567
- state: childState,
567
+ snapshot: childState,
568
568
  src,
569
569
  systemId: actorData.systemId
570
570
  });
@@ -1,8 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
2
- import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedState, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-f71460d6.esm.js';
3
- export { A as Actor, G as __unsafe_getAllOwnEventDescriptors, H as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, D as matchesState, I as not, J as or, E as pathToStateValue, M as raise, O as spawnChild, K as stateIn, P as stop, Q as stopChild, F as toObserver } from './raise-f71460d6.esm.js';
4
- import { a as assign } from './log-6bc0e1e7.esm.js';
5
- export { S as SpecialTargets, a as assign, e as enqueueActions, b as escalate, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-6bc0e1e7.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-be2f20bc.esm.js';
3
+ export { A as Actor, G as __unsafe_getAllOwnEventDescriptors, H as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, D as matchesState, I as not, J as or, E as pathToStateValue, M as raise, O as spawnChild, K as stateIn, P as stop, Q as stopChild, F as toObserver } from './raise-be2f20bc.esm.js';
4
+ import { a as assign } from './log-60ab9eaf.esm.js';
5
+ export { S as SpecialTargets, a as assign, e as enqueueActions, b as escalate, f as forwardTo, l as log, s as sendParent, c as sendTo } from './log-60ab9eaf.esm.js';
6
6
  import '../dev/dist/xstate-dev.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -295,7 +295,7 @@ class StateNode {
295
295
  get initial() {
296
296
  return memo(this, 'initial', () => formatInitialTransition(this, this.config.initial));
297
297
  }
298
- next(state, event) {
298
+ next(snapshot, event) {
299
299
  const eventType = event.type;
300
300
  const actions = [];
301
301
  let selectedTransition;
@@ -304,10 +304,10 @@ class StateNode {
304
304
  const {
305
305
  guard
306
306
  } = candidate;
307
- const resolvedContext = state.context;
307
+ const resolvedContext = snapshot.context;
308
308
  let guardPassed = false;
309
309
  try {
310
- guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, state);
310
+ guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, snapshot);
311
311
  } catch (err) {
312
312
  const guardType = typeof guard === 'string' ? guard : typeof guard === 'object' ? guard.type : undefined;
313
313
  throw new Error(`Unable to evaluate guard ${guardType ? `'${guardType}' ` : ''}in transition for event '${eventType}' in state node '${this.id}':\n${err.message}`);
@@ -388,7 +388,7 @@ class StateMachine {
388
388
  this.version = this.config.version;
389
389
  this.transition = this.transition.bind(this);
390
390
  this.getInitialState = this.getInitialState.bind(this);
391
- this.restoreState = this.restoreState.bind(this);
391
+ this.restoreSnapshot = this.restoreSnapshot.bind(this);
392
392
  this.start = this.start.bind(this);
393
393
  this.root = new StateNode(config, {
394
394
  _key: this.id,
@@ -456,7 +456,7 @@ class StateMachine {
456
456
  * @param event The received event
457
457
  */
458
458
  transition(snapshot, event, actorScope) {
459
- return macrostep(snapshot, event, actorScope).state;
459
+ return macrostep(snapshot, event, actorScope).snapshot;
460
460
  }
461
461
 
462
462
  /**
@@ -466,8 +466,8 @@ class StateMachine {
466
466
  * @param state The current state
467
467
  * @param event The received event
468
468
  */
469
- microstep(state, event, actorScope) {
470
- return macrostep(state, event, actorScope).microstates;
469
+ microstep(snapshot, event, actorScope) {
470
+ return macrostep(snapshot, event, actorScope).microstates;
471
471
  }
472
472
  getTransitionData(snapshot, event) {
473
473
  return transitionNode(this.root, snapshot.value, snapshot, event) || [];
@@ -516,12 +516,12 @@ class StateMachine {
516
516
  toJSON: null // TODO: fix
517
517
  }], preInitialState, actorScope, initEvent, true, internalQueue);
518
518
  const {
519
- state: macroState
519
+ snapshot: macroState
520
520
  } = macrostep(nextState, initEvent, actorScope, internalQueue);
521
521
  return macroState;
522
522
  }
523
- start(state) {
524
- Object.values(state.children).forEach(child => {
523
+ start(snapshot) {
524
+ Object.values(snapshot.children).forEach(child => {
525
525
  if (child.getSnapshot().status === 'active') {
526
526
  child.start();
527
527
  }
@@ -543,15 +543,15 @@ class StateMachine {
543
543
  toJSON() {
544
544
  return this.definition;
545
545
  }
546
- getPersistedState(state, options) {
547
- return getPersistedState(state, options);
546
+ getPersistedSnapshot(snapshot, options) {
547
+ return getPersistedSnapshot(snapshot, options);
548
548
  }
549
- restoreState(snapshot, _actorScope) {
549
+ restoreSnapshot(snapshot, _actorScope) {
550
550
  const children = {};
551
551
  const snapshotChildren = snapshot.children;
552
552
  Object.keys(snapshotChildren).forEach(actorId => {
553
553
  const actorData = snapshotChildren[actorId];
554
- const childState = actorData.state;
554
+ const childState = actorData.snapshot;
555
555
  const src = actorData.src;
556
556
  const logic = typeof src === 'string' ? resolveReferencedActor(this, src) : src;
557
557
  if (!logic) {
@@ -561,7 +561,7 @@ class StateMachine {
561
561
  id: actorId,
562
562
  parent: _actorScope?.self,
563
563
  syncSnapshot: actorData.syncSnapshot,
564
- state: childState,
564
+ snapshot: childState,
565
565
  src,
566
566
  systemId: actorData.systemId
567
567
  });
@@ -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";class e{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)}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),this._current=t.next}this._last=null}}const s=".",n="",i="",o="xstate.init",r="xstate.error",a="xstate.stop";function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function h(t){return{type:o,input:t}}function f(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=f();e&&e.register(t)};function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function v(t,e){const s=m(t),n=m(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&v(s[t],n[t])))}function g(t){return k(t)?t:t.split(s)}function m(t){if(Pt(t))return t.value;if("string"!=typeof t)return t;return _(g(t))}function _(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function b(t,e){const s={},n=Object.keys(t);for(let i=0;i<n.length;i++){const o=n[i];s[o]=e(t[o],o,t,i)}return s}function S(t){return k(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function $(t){if(void 0!==t&&t!==n)return x(t)}function E(t,e,s){const n="object"==typeof t,i=n?t:void 0;return{next:(n?t.next:t)?.bind(i),error:(n?t.error:e)?.bind(i),complete:(n?t.complete:s)?.bind(i)}}function T(t,e){return`${e}.${t}`}function O(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,i]=s,o=t.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[n]:o).src}const M=1;let j=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const N={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class A{constructor(t,s){this.logic=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=j.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=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={...N,...s},{clock:i,logger:o,parent:r,syncSnapshot:a,id:c,systemId:u,inspect:h}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,i=new Set,o={_bookId:()=>"x:"+y++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const i=n.get(t);void 0!==i&&(s.delete(i),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const i=s.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{i.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};i.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{o._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return o}(this),h&&!r&&this.system.inspect(E(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=o,this.clock=i,this._parent=r,this._syncSnapshot=a,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={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.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),u&&(this._systemId=u,this.system._set(u,this)),this._initState(s?.state),u&&"active"!==this._state.status&&this.system._unregister(this)}_initState(t){try{this._state=t?this.logic.restoreState?this.logic.restoreState(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}catch(t){this._state={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._state=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._state={...t,status:"error",error:e}}switch(this._state.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,i=this._state.output,{type:`xstate.done.actor.${n}`,output:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._state.error)}var n,i;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=E(t,e,s);if(this._processingStatus!==j.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){p(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===j.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=j.Running;const t=h(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._state.status){case"done":return this.update(this._state,t),this;case"error":return this._error(this._state.error),this}if(this.logic.start)try{this.logic.start(this._state,this._actorScope)}catch(t){return this._state={...this._state,status:"error",error:t},this._error(t),this}return this.update(this._state,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._state,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._state={...this._state,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===j.Stopped?this:(this.mailbox.clear(),this._processingStatus===j.NotStarted?(this._processingStatus=j.Stopped,this):(this.mailbox.enqueue({type:a}),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){p(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,u(this.id,t))}_stopProcedure(){if(this._processingStatus!==j.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=j.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==j.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,i=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=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:d)(this)}}toJSON(){return{xstate$$type:M,id:this.id}}getPersistedState(t){return this.logic.getPersistedState(this._state,t)}[l](){return this}getSnapshot(){return this._state}}function P(t,e){return new A(t,e)}const R=P;function C(t,e,s,n,{sendId:i}){return[e,"function"==typeof i?i(s,n):i]}function D(t,e){t.self.cancel(e)}function J(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=C,e.execute=D,e}function V(t,e,s,n,{id:i,systemId:o,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?O(e.machine,r):r,h="function"==typeof i?i(s):i;let f;return u&&(f=P(u,{id:h,src:r,parent:t?.self,syncSnapshot:c,systemId:o,input:"function"==typeof a?a({context:e.context,event:s.event,self:t?.self}):a})),[qt(e,{children:{...e.children,[h]:f}}),{id:i,actorRef:f}]}function B(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==j.Stopped&&s.start()}))}function q(...[t,{id:e,systemId:s,input:n,syncSnapshot:i=!1}={}]){function o(t,e){}return o.type="xstate.spawnChild",o.id=e,o.systemId=s,o.src=t,o.input=n,o.syncSnapshot=i,o.resolve=V,o.execute=B,o}function z(t,e,s,n,{actorRef:i}){const o="function"==typeof i?i(s,n):i,r="string"==typeof o?e.children[o]:o;let a=e.children;return r&&(a={...a},delete a[r.id]),[qt(e,{children:a}),r]}function W(t,e){e&&(t.system._unregister(e),e._processingStatus===j.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function U(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=z,e.execute=W,e}const Q=U;function F(t,e,{stateValue:s}){if("string"==typeof s&&ot(s)){const e=t.machine.getStateNodeById(s);return t._nodes.some((t=>t===e))}return t.matches(s)}function G(t,{context:e,event:s},{guards:n}){return!K(n[0],e,s,t)}function X(t,{context:e,event:s},{guards:n}){return n.every((n=>K(n,e,s,t)))}function H(t,{context:e,event:s},{guards:n}){return n.some((n=>K(n,e,s,t)))}function K(t,e,s,n){const{machine:i}=n,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 K(r,e,s,n);const a={context:e,event:s},c=o||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(n,a,r)}const L=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 s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function tt(t){const e=new Set(t),s=st(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of Y(t))if("history"!==s.type&&!e.has(s)){const t=ht(s);for(const s of t)e.add(s)}}else ht(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}function et(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(L(t))return t.key}const n={};for(const t of s)n[t.key]=et(t,e);return n}function st(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function nt(t,e){return et(t,st(tt(e)))}function it(t,e){return"compound"===e.type?Y(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?Y(e).every((e=>it(t,e))):"final"===e.type}const ot=t=>"#"===t[0];function rt(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((s,n)=>{const i=e[s],o="string"==typeof i?{target:i}:i,r=Number.isNaN(+s)?s:+s,a=((e,s)=>{const n=(i=e,o=t.id,{type:`xstate.after.${i}.${o}`});var i,o;const r=n.type;return t.entry.push(Xt(n,{id:r,delay:e})),t.exit.push(J(r)),r})(r);return x(o).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:s}=e;return{...at(t,e.event,e),delay:s}}))}function at(t,e,n){const i=$(n.target),o=n.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(ot(e))return t.machine.getStateNodeById(e);const n=e[0]===s;if(n&&!t.parent)return pt(t,e.slice(1));const i=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 pt(t.parent,i)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,i),a={...n,actions:x(n.actions),guard:n.guard,target:r,source:t,reenter:o,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ct(t){const e=$(t.config.target);return e?{target:e.map((e=>"string"==typeof e?pt(t.parent,e):e))}:t.parent.initial}function ut(t){return"history"===t.type}function ht(t){const e=ft(t);for(const s of e)for(const n of Z(s,t))e.add(n);return e}function ft(t){const e=new Set;return function t(s){if(!e.has(s))if(e.add(s),"compound"===s.type)t(s.initial.target[0]);else if("parallel"===s.type)for(const e of Y(s))t(e)}(t),e}function dt(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 s=t.states[e];if(!s)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return s}function pt(t,e){if("string"==typeof e&&ot(e))try{return t.machine.getStateNodeById(e)}catch(t){}const s=g(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=dt(n,t)}return n}function lt(t,e){if("string"==typeof e)return[t,t.states[e]];const s=Object.keys(e),n=s.map((e=>dt(t,e))).filter(Boolean);return[t.machine.root,t].concat(n,s.reduce(((s,n)=>{const i=dt(t,n);if(!i)return s;const o=lt(i,e[n]);return s.concat(o)}),[]))}function yt(t,e,s,n){return"string"==typeof e?function(t,e,s,n){const i=dt(t,e).next(s,n);return i&&i.length?i:t.next(s,n)}(t,e,s,n):1===Object.keys(e).length?function(t,e,s,n){const i=Object.keys(e),o=yt(dt(t,i[0]),e[i[0]],s,n);return o&&o.length?o:t.next(s,n)}(t,e,s,n):function(t,e,s,n){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=yt(dt(t,o),r,s,n);a&&i.push(...a)}return i.length?i:t.next(s,n)}(t,e,s,n)}function vt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function gt(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function mt(t,e){const s=new Set(t),n=new Set(e);for(const t of s)if(n.has(t))return!0;for(const t of n)if(s.has(t))return!0;return!1}function _t(t,e,s){const n=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of n)if(mt(xt([i],e,s),xt([r],e,s))){if(!gt(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)n.delete(t);n.add(i)}}return Array.from(n)}function bt(t,e){if(!t.target)return[];const s=new Set;for(const n of t.target)if(ut(n))if(e[n.id])for(const t of e[n.id])s.add(t);else for(const t of bt(ct(n),e))s.add(t);else s.add(n);return[...s]}function St(t,e){const s=bt(t,e);if(!s)return;if(!t.reenter&&s.every((e=>e===t.source||gt(e,t.source))))return t.source;const n=function(t){const[e,...s]=t;for(const t of Z(e,void 0))if(s.every((e=>gt(e,t))))return t}(s.concat(t.source));return n||(t.reenter?void 0:t.source.machine.root)}function xt(t,e,s){const n=new Set;for(const i of t)if(i.target?.length){const t=St(i,s);i.reenter&&i.source===t&&n.add(t);for(const s of e)gt(s,t)&&n.add(s)}return[...n]}function wt(t,e,s,n,i,o){if(!t.length)return e;const r=new Set(e._nodes);let a=e.historyValue;const u=_t(t,r,a);let h=e;i||([h,a]=function(t,e,s,n,i,o,r){let a=t;const c=xt(n,i,o);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of vt(t)){let s;s="deep"===e.history?e=>L(e)&&gt(e,t):e=>e.parent===t,u??={...o},u[e.id]=Array.from(i).filter(s)}for(const t of c)a=Ot(a,e,s,[...t.exit,...t.invoke.map((t=>U(t.id)))],r),i.delete(t);return[a,u||o]}(h,n,s,u,r,a,o)),h=Ot(h,n,s,u.flatMap((t=>t.actions)),o),h=function(t,e,s,n,i,o,r,a){let u=t;const h=new Set,f=new Set;(function(t,e,s,n){for(const i of t){const t=St(i,e);for(const o of i.target||[])ut(o)||i.source===o&&i.source===t&&!i.reenter||(n.add(o),s.add(o)),It(o,e,s,n);const o=bt(i,e);for(const r of o){const o=Z(r,t);"parallel"===t?.type&&o.push(t),$t(n,e,s,o,!i.source.parent&&i.reenter?void 0:t)}}})(n,r,f,h),a&&f.add(t.machine.root);const d=new Set;for(const t of[...h].sort(((t,e)=>t.order-e.order))){i.add(t);const n=[];n.push(...t.entry);for(const e of t.invoke)n.push(q(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(f.has(t)){const e=t.initial.actions;n.push(...e)}if(u=Ot(u,e,s,n,o,t.invoke.map((t=>t.id))),"final"===t.type){const n=t.parent;let r="parallel"===n?.type?n:n?.parent,a=r||t;for("compound"===n?.type&&o.push(c(n.id,t.output?w(t.output,u.context,e,s.self):void 0));"parallel"===r?.type&&!d.has(r)&&it(i,r);)d.add(r),o.push(c(r.id)),a=r,r=r.parent;if(r)continue;u=qt(u,{status:"done",output:kt(u,e,s,u.machine.root,a)})}}return u}(h,n,s,u,r,o,a,i);const f=[...r];"done"===h.status&&(h=Ot(h,n,s,f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),o));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;return!0}(e._nodes,r)?h:qt(h,{_nodes:f,historyValue:a})}catch(t){throw t}}function kt(t,e,s,n,i){if(!n.output)return;const o=c(i.id,i.output&&i.parent?w(i.output,t.context,e,s.self):void 0);return w(n.output,t.context,o,s.self)}function It(t,e,s,n){if(ut(t))if(e[t.id]){const i=e[t.id];for(const t of i)n.add(t),It(t,e,s,n);for(const o of i)Et(o,t.parent,n,e,s)}else{const i=ct(t);for(const o of i.target)n.add(o),i===t.parent?.initial&&s.add(t.parent),It(o,e,s,n);for(const o of i.target)Et(o,t,n,e,s)}else if("compound"===t.type){const[i]=t.initial.target;ut(i)||(n.add(i),s.add(i)),It(i,e,s,n),Et(i,t,n,e,s)}else if("parallel"===t.type)for(const i of Y(t).filter((t=>!ut(t))))[...n].some((t=>gt(t,i)))||(ut(i)||(n.add(i),s.add(i)),It(i,e,s,n))}function $t(t,e,s,n,i){for(const o of n)if(i&&!gt(o,i)||t.add(o),"parallel"===o.type)for(const n of Y(o).filter((t=>!ut(t))))[...t].some((t=>gt(t,n)))||(t.add(n),It(n,e,s,t))}function Et(t,e,s,n,i){$t(s,n,i,Z(t,e))}function Tt(t,e,s,n,i,o){const{machine:r}=t;let a=t;for(const t of n){const n="function"==typeof t,c=n?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:s?.self,system:s?.system},h=n||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in c)){s?.self._processingStatus===j.Running?c(u,h):s?.defer((()=>{c(u,h)}));continue}const f=c,[d,p,l]=f.resolve(s,a,u,h,c,i);a=d,"retryResolve"in f&&o?.push([f,p]),"execute"in f&&(s?.self._processingStatus===j.Running?f.execute(s,p):s?.defer(f.execute.bind(null,s,p))),l&&(a=Tt(a,e,s,l,i,o))}return a}function Ot(t,e,s,n,i,o){const r=o?[]:void 0,a=Tt(t,e,s,n,{internalQueue:i,deferredActorIds:o},r);return r?.forEach((([t,e])=>{t.retryResolve(s,a,e)})),a}function Mt(t,e,s,n=[]){let i=t;const r=[];if(e.type===a)return i=qt(jt(i,e,s),{status:"stopped"}),r.push(i),{state:i,microstates:r};let c=e;if(c.type!==o){const e=c,o=function(t){return t.type.startsWith("xstate.error.actor")}(e),a=Nt(e,i);if(o&&!a.length)return i=qt(t,{status:"error",error:e.data}),r.push(i),{state:i,microstates:r};i=wt(a,t,s,c,!1,n),r.push(i)}let u=!0;for(;"active"===i.status;){let t=u?At(i,c):[];const e=t.length?i:void 0;if(!t.length){if(!n.length)break;c=n.shift(),t=Nt(c,i)}i=wt(t,i,s,c,!1,n),u=i!==e,r.push(i)}return"active"!==i.status&&jt(i,c,s),{state:i,microstates:r}}function jt(t,e,s){return Ot(t,e,s,Object.values(t.children).map((t=>U(t))),[])}function Nt(t,e){return e.machine.getTransitionData(e,t)}function At(t,e){const s=new Set,n=t._nodes.filter(L);for(const i of n)t:for(const n of[i].concat(Z(i,void 0)))if(n.always)for(const i of n.always)if(void 0===i.guard||K(i.guard,t.context,e,t)){s.add(i);break t}return _t(Array.from(s),new Set(t._nodes),t.historyValue)}function Pt(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Rt=function(t){return v(t,this.value)},Ct=function(t){return this.tags.has(t)},Dt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Jt=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:i,can:o,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Vt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Bt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:nt(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Rt,hasTag:Ct,can:Dt,getMeta:Vt,toJSON:Jt}}function qt(t,e={}){return Bt({...t,...e},t.machine)}function zt(t){let e;for(const s in t){const n=t[s];if(n&&"object"==typeof n)if("sessionId"in n&&"send"in n&&"ref"in n)e??=Array.isArray(t)?t.slice():{...t},e[s]={xstate$$type:M,id:n.id};else{const i=zt(n);i!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=i)}}return e??t}function Wt(t,{machine:e,context:s},n,i){return(o,r)=>{const a=((o,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof o){const u=O(e,o);if(!u)throw new Error(`Actor logic '${o}' not implemented in machine '${e.id}'`);const h=P(u,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof c?c({context:s,event:n,self:t.self}):c,src:o,systemId:a});return i[h.id]=h,h}return P(o,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:o,systemId:a})})(o,r);return i[a.id]=a,t.defer((()=>{a._processingStatus!==j.Stopped&&a.start()})),a}}function Ut(t,e,s,n,{assignment:i}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const o={},r={context:e.context,event:s.event,spawn:Wt(t,e,s.event,o),self:t?.self,system:t?.system};let a={};if("function"==typeof i)a=i(r,n);else for(const t of Object.keys(i)){const e=i[t];a[t]="function"==typeof e?e(r,n):e}return[qt(e,{context:Object.assign({},e.context,a),children:Object.keys(o).length?{...e.children,...o}:e.children})]}function Qt(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ut,e}function Ft(t,e,s,n,{event:i,id:o,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const u="function"==typeof i?i(s,n):i;let h;if("string"==typeof r){const t=c&&c[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&a.push(u),[e,{event:u,id:o,delay:h}]}function Gt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Xt(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Ft,s.execute=Gt,s}let Ht=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Kt(t,e,s,n,{to:i,event:o,id:r,delay:a},c){const u=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 h="function"==typeof o?o(s,n):o;let f;if("string"==typeof a){const t=u&&u[a];f="function"==typeof t?t(s,n):t}else f="function"==typeof a?a(s,n):a;const d="function"==typeof i?i(s,n):i;let p;if("string"==typeof d){if(p=d===Ht.Parent?t?.self._parent:d===Ht.Internal?t?.self:d.startsWith("#_")?e.children[d.slice(2)]:c.deferredActorIds?.includes(d)?d:e.children[d],!p)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else p=d||t?.self;return[e,{to:p,event:h,id:r,delay:f}]}function Lt(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function Yt(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:n}=e;t?.system._relay(t.self,s,n.type===r?u(t.self.id,n.data):n)})):t.self.delaySend(e)}function Zt(t,e,s){function n(t,e){}return n.type="xstate.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Kt,n.retryResolve=Lt,n.execute=Yt,n}function te(t,e){return Zt(Ht.Parent,t,e)}function ee(t,e,s,n,{collect:i}){const o=[],r=function(t){o.push(t)};return r.assign=(...t)=>{o.push(Qt(...t))},r.cancel=(...t)=>{o.push(J(...t))},r.raise=(...t)=>{o.push(Xt(...t))},r.sendTo=(...t)=>{o.push(Zt(...t))},r.spawnChild=(...t)=>{o.push(q(...t))},r.stopChild=(...t)=>{o.push(U(...t))},i({context:s.context,event:s.event,enqueue:r,check:t=>K(t,e.context,s.event,e)}),[e,void 0,o]}function se(t,e,s,n,{value:i,label:o}){return[e,{value:"function"==typeof i?i(s,n):i,label:o}]}function ne({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function ie(t,e){return{config:t,transition:(e,s,n)=>({...e,context:t(e.context,s,n)}),getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:s}):e}),getPersistedState:t=>t,restoreState:t=>t}}const oe=new WeakMap;const re="xstate.observable.next",ae="xstate.observable.error",ce="xstate.observable.complete";const ue="xstate.promise.resolve",he="xstate.promise.reject";const fe=ie((t=>{}),void 0);const de=new WeakMap;function pe(t,e,s){let n=de.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},de.set(t,n)),n[e]}const le={},ye=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ve{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(s),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?b(this.config.states,((t,e)=>new ve(t,{_parent:this,_key:e,_machine:this.machine}))):le,"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=x(this.config.entry).slice(),this.exit=x(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=x(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const s of Object.keys(t.config.on)){if(s===i)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,I(n).map((e=>at(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,I(t.config.onDone).map((e=>at(t,s,e))))}for(const s of t.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;e.set(n,I(s.onDone).map((e=>at(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,I(s.onError).map((e=>at(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,I(s.onSnapshot).map((e=>at(t,n,e))))}}for(const s of t.after){let t=e.get(s.eventType);t||(t=[],e.set(s.eventType,t)),t.push(s)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>at(this,i,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(ye),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(ye),eventType:null})}:void 0,history:this.history,states:b(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(ye)}))),entry:this.entry.map(ye),exit:this.exit.map(ye),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 pe(this,"invoke",(()=>x(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,i=t.id??T(this.id,e),o="string"==typeof s?s:`xstate.invoke.${T(this.id,e)}`;return{...t,src:o,id:i,systemId:n,toJSON(){const{onDone:e,onError:s,...n}=t;return{...n,type:"xstate.invoke",src:o,id:i}}}}))))}get on(){return pe(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,s])=>(t[e]=t[e]||[],t[e].push(s),t)),{})))}get after(){return pe(this,"delayedTransitions",(()=>rt(this)))}get initial(){return pe(this,"initial",(()=>function(t,e){const s="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!s&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const n={source:t,actions:e&&"string"!=typeof e?x(e.actions):[],eventType:null,reenter:!1,target:s?[s]:[],toJSON:()=>({...n,source:`#${t.id}`,target:s?[`#${s.id}`]:[]})};return n}(this,this.config.initial)))}next(t,e){const s=e.type,n=[];let i;const o=pe(this,`candidates-${s}`,(()=>{return e=s,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const s=t.split("."),n=e.split(".");for(let t=0;t<s.length;t++){const e=s[t],i=n[t];if("*"===e)return t===s.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||K(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 '${s}' in state node '${this.id}':\n${t.message}`)}if(c){n.push(...r.actions),i=r;break}}return i?[i]:void 0}get events(){return pe(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const n=t[s];if(n.states)for(const t of n.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 ge{constructor(t,e){this.config=t,this.version=void 0,this.implementations=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.__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.transition=this.transition.bind(this),this.getInitialState=this.getInitialState.bind(this),this.restoreState=this.restoreState.bind(this),this.start=this.start.bind(this),this.root=new ve(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:s,actors:n,delays:i}=this.implementations;return new ge(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...n,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=(s=this.root,n=t.value,nt(s,[...tt(lt(s,n))]));var s,n;const i=tt(lt(this.root,e));return Bt({_nodes:[...i],context:t.context||{},children:{},status:it(i,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return Mt(t,e,s).state}microstep(t,e,s){return Mt(t,e,s).microstates}getTransitionData(t,e){return yt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,i=Bt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return Ot(i,e,t,[Qt((({spawn:t,event:e})=>n({spawn:t,input:e.input})))],s)}return i}getInitialState(t,e){const s=h(e),n=[],i=this.getPreInitialState(t,s,n),o=wt([{target:[...ft(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],i,t,s,!0,n),{state:r}=Mt(o,s,t,n);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(s),n=e.slice(1),i=ot(e[0])?e[0].slice(1):e[0],o=this.idMap.get(i);if(!o)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return pt(o,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedState(t,e){return function(t,e){const{_nodes:s,tags:n,machine:i,children:o,context:r,can:a,hasTag:c,matches:u,getMeta:h,toJSON:f,...d}=t,p={};for(const t in o){const s=o[t];p[t]={state:s.getPersistedState(e),src:s.src,systemId:s._systemId,syncSnapshot:s._syncSnapshot}}return{...d,context:zt(r),children:p}}(t,e)}restoreState(t,e){const s={},n=t.children;Object.keys(n).forEach((t=>{const i=n[t],o=i.state,r=i.src,a="string"==typeof r?O(this,r):r;if(!a)return;const c=P(a,{id:t,parent:e?.self,syncSnapshot:i.syncSnapshot,state:o,src:r,systemId:i.systemId});s[t]=c}));const i=Bt({...t,children:s,_nodes:Array.from(tt(lt(this.root,t.value)))},this);let o=new Set;return function t(e,s){if(!o.has(e)){o.add(e);for(let n in e){const i=e[n];if(i&&"object"==typeof i){if("xstate$$type"in i&&i.xstate$$type===M){e[n]=s[i.id];continue}t(i,s)}}}}(i.context,s),i}}const me={timeout:1/0};function _e(t,e){return new ge(t,e)}t.Actor=A,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 s=this.getId();return this.timeouts.set(s,{start:this.now(),timeout:e,fn:t}),s}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],[s,n])=>{const i=e.start+e.timeout;return n.start+n.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=Ht,t.StateMachine=ge,t.StateNode=ve,t.__unsafe_getAllOwnEventDescriptors=function(t){return[...new Set([...t._nodes.flatMap((t=>t.ownEvents))])]},t.and=function(t){function e(t,e){return!1}return e.check=X,e.guards=t,e},t.assign=Qt,t.cancel=J,t.createActor=P,t.createEmptyActor=function(){return P(fe)},t.createMachine=_e,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=ee,e},t.escalate=function(t,e){return te((e=>({type:r,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return Zt(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(e,s)=>{const{self:n,system:i}=s,o={receivers:void 0,dispose:void 0};oe.set(n,o),o.dispose=t({input:e.input,system:i,self:n,sendBack:t=>{"stopped"!==n.getSnapshot().status&&n._parent&&i._relay(n,n._parent,t)},receive:t=>{o.receivers??=new Set,o.receivers.add(t)}})},transition:(t,e,s)=>{const n=oe.get(s.self);return e.type===a?(t={...t,status:"stopped",error:void 0},n.dispose?.(),t):(n.receivers?.forEach((t=>t(e))),t)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedState:({_subscription:t,...e})=>e,restoreState:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,e,{self:s,id:n,defer:i,system:o})=>{if("active"!==t.status)return t;switch(e.type){case re:return{...t,context:e.data};case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{n._relay(s,s,{type:re,data:t})},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedState:({_subscription:t,...e})=>e,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 ue:{const s=e.data;return{...t,status:"done",output:s,input:void 0}}case he:return{...t,status:"error",error:e.data,input:void 0};case a:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:s,system:n})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:n,self:s})).then((t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:ue,data:t})}),(t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:he,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=ie,t.getStateNodes=lt,t.interpret=R,t.isMachineSnapshot=Pt,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=se,s.execute=ne,s},t.matchesState=v,t.not=function(t){function e(t,e){return!1}return e.check=G,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=H,e.guards=t,e},t.pathToStateValue=_,t.raise=Xt,t.sendParent=te,t.sendTo=Zt,t.setup=function({actors:t,actions:e,guards:s,delays:n}){return{createMachine:i=>_e(i,{actors:t,actions:e,guards:s,delays:n})}},t.spawnChild=q,t.stateIn=function(t){function e(t,e){return!1}return e.check=F,e.stateValue=t,e},t.stop=Q,t.stopChild=U,t.toObserver=E,t.waitFor=function(t,e,s){const n={...me,...s};return new Promise(((s,i)=>{let o=!1;const r=n.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),s(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";class e{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)}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),this._current=t.next}this._last=null}}const s=".",n="",o="",i="xstate.init",r="xstate.error",a="xstate.stop";function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,data:e}}function h(t){return{type:i,input:t}}function f(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=f();e&&e.register(t)};function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function v(t,e){const s=m(t),n=m(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&v(s[t],n[t])))}function g(t){return k(t)?t:t.split(s)}function m(t){if(Pt(t))return t.value;if("string"!=typeof t)return t;return _(g(t))}function _(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function b(t,e){const s={},n=Object.keys(t);for(let o=0;o<n.length;o++){const i=n[o];s[i]=e(t[i],i,t,o)}return s}function S(t){return k(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function $(t){if(void 0!==t&&t!==n)return x(t)}function E(t,e,s){const n="object"==typeof t,o=n?t:void 0;return{next:(n?t.next:t)?.bind(o),error:(n?t.error:e)?.bind(o),complete:(n?t.complete:s)?.bind(o)}}function T(t,e){return`${e}.${t}`}function O(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,o]=s,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[n]:i).src}const M=1;let j=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const N={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class A{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=j.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=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={...N,...s},{clock:o,logger:i,parent:r,syncSnapshot:a,id:c,systemId:u,inspect:h}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,o=new Set,i={_bookId:()=>"x:"+y++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const o=n.get(t);void 0!==o&&(s.delete(o),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const o=s.get(t);if(o&&o!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{o.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};o.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{i._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return i}(this),h&&!r&&this.system.inspect(E(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=i,this.clock=o,this._parent=r,this._syncSnapshot=a,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={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.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),u&&(this._systemId=u,this.system._set(u,this)),this._initState(s?.snapshot??s?.state),u&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialState(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._snapshot=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var n,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=E(t,e,s);if(this._processingStatus!==j.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){p(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===j.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=j.Running;const t=h(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===j.Stopped?this:(this.mailbox.clear(),this._processingStatus===j.NotStarted?(this._processingStatus=j.Stopped,this):(this.mailbox.enqueue({type:a}),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){p(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,u(this.id,t))}_stopProcedure(){if(this._processingStatus!==j.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=j.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==j.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,o=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=o)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:d)(this)}}toJSON(){return{xstate$$type:M,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[l](){return this}getSnapshot(){return this._snapshot}}function P(t,e){return new A(t,e)}const R=P;function C(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function D(t,e){t.self.cancel(e)}function J(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=C,e.execute=D,e}function V(t,e,s,n,{id:o,systemId:i,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?O(e.machine,r):r,h="function"==typeof o?o(s):o;let f;return u&&(f=P(u,{id:h,src:r,parent:t?.self,syncSnapshot:c,systemId:i,input:"function"==typeof a?a({context:e.context,event:s.event,self:t?.self}):a})),[qt(e,{children:{...e.children,[h]:f}}),{id:o,actorRef:f}]}function B(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==j.Stopped&&s.start()}))}function q(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=V,i.execute=B,i}function z(t,e,s,n,{actorRef:o}){const i="function"==typeof o?o(s,n):o,r="string"==typeof i?e.children[i]:i;let a=e.children;return r&&(a={...a},delete a[r.id]),[qt(e,{children:a}),r]}function W(t,e){e&&(t.system._unregister(e),e._processingStatus===j.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function U(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=z,e.execute=W,e}const Q=U;function F(t,e,{stateValue:s}){if("string"==typeof s&&it(s)){const e=t.machine.getStateNodeById(s);return t._nodes.some((t=>t===e))}return t.matches(s)}function G(t,{context:e,event:s},{guards:n}){return!K(n[0],e,s,t)}function X(t,{context:e,event:s},{guards:n}){return n.every((n=>K(n,e,s,t)))}function H(t,{context:e,event:s},{guards:n}){return n.some((n=>K(n,e,s,t)))}function K(t,e,s,n){const{machine:o}=n,i="function"==typeof t,r=i?t:o.implementations.guards["string"==typeof t?t:t.type];if(!i&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return K(r,e,s,n);const a={context:e,event:s},c=i||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(n,a,r)}const L=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 s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function tt(t){const e=new Set(t),s=st(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of Y(t))if("history"!==s.type&&!e.has(s)){const t=ht(s);for(const s of t)e.add(s)}}else ht(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}function et(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(L(t))return t.key}const n={};for(const t of s)n[t.key]=et(t,e);return n}function st(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function nt(t,e){return et(t,st(tt(e)))}function ot(t,e){return"compound"===e.type?Y(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?Y(e).every((e=>ot(t,e))):"final"===e.type}const it=t=>"#"===t[0];function rt(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((s,n)=>{const o=e[s],i="string"==typeof o?{target:o}:o,r=Number.isNaN(+s)?s:+s,a=((e,s)=>{const n=(o=e,i=t.id,{type:`xstate.after.${o}.${i}`});var o,i;const r=n.type;return t.entry.push(Xt(n,{id:r,delay:e})),t.exit.push(J(r)),r})(r);return x(i).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:s}=e;return{...at(t,e.event,e),delay:s}}))}function at(t,e,n){const o=$(n.target),i=n.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(it(e))return t.machine.getStateNodeById(e);const n=e[0]===s;if(n&&!t.parent)return pt(t,e.slice(1));const o=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 pt(t.parent,o)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,o),a={...n,actions:x(n.actions),guard:n.guard,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ct(t){const e=$(t.config.target);return e?{target:e.map((e=>"string"==typeof e?pt(t.parent,e):e))}:t.parent.initial}function ut(t){return"history"===t.type}function ht(t){const e=ft(t);for(const s of e)for(const n of Z(s,t))e.add(n);return e}function ft(t){const e=new Set;return function t(s){if(!e.has(s))if(e.add(s),"compound"===s.type)t(s.initial.target[0]);else if("parallel"===s.type)for(const e of Y(s))t(e)}(t),e}function dt(t,e){if(it(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const s=t.states[e];if(!s)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return s}function pt(t,e){if("string"==typeof e&&it(e))try{return t.machine.getStateNodeById(e)}catch(t){}const s=g(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=dt(n,t)}return n}function lt(t,e){if("string"==typeof e)return[t,t.states[e]];const s=Object.keys(e),n=s.map((e=>dt(t,e))).filter(Boolean);return[t.machine.root,t].concat(n,s.reduce(((s,n)=>{const o=dt(t,n);if(!o)return s;const i=lt(o,e[n]);return s.concat(i)}),[]))}function yt(t,e,s,n){return"string"==typeof e?function(t,e,s,n){const o=dt(t,e).next(s,n);return o&&o.length?o:t.next(s,n)}(t,e,s,n):1===Object.keys(e).length?function(t,e,s,n){const o=Object.keys(e),i=yt(dt(t,o[0]),e[o[0]],s,n);return i&&i.length?i:t.next(s,n)}(t,e,s,n):function(t,e,s,n){const o=[];for(const i of Object.keys(e)){const r=e[i];if(!r)continue;const a=yt(dt(t,i),r,s,n);a&&o.push(...a)}return o.length?o:t.next(s,n)}(t,e,s,n)}function vt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function gt(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function mt(t,e){const s=new Set(t),n=new Set(e);for(const t of s)if(n.has(t))return!0;for(const t of n)if(s.has(t))return!0;return!1}function _t(t,e,s){const n=new Set;for(const o of t){let t=!1;const i=new Set;for(const r of n)if(mt(xt([o],e,s),xt([r],e,s))){if(!gt(o.source,r.source)){t=!0;break}i.add(r)}if(!t){for(const t of i)n.delete(t);n.add(o)}}return Array.from(n)}function bt(t,e){if(!t.target)return[];const s=new Set;for(const n of t.target)if(ut(n))if(e[n.id])for(const t of e[n.id])s.add(t);else for(const t of bt(ct(n),e))s.add(t);else s.add(n);return[...s]}function St(t,e){const s=bt(t,e);if(!s)return;if(!t.reenter&&s.every((e=>e===t.source||gt(e,t.source))))return t.source;const n=function(t){const[e,...s]=t;for(const t of Z(e,void 0))if(s.every((e=>gt(e,t))))return t}(s.concat(t.source));return n||(t.reenter?void 0:t.source.machine.root)}function xt(t,e,s){const n=new Set;for(const o of t)if(o.target?.length){const t=St(o,s);o.reenter&&o.source===t&&n.add(t);for(const s of e)gt(s,t)&&n.add(s)}return[...n]}function wt(t,e,s,n,o,i){if(!t.length)return e;const r=new Set(e._nodes);let a=e.historyValue;const u=_t(t,r,a);let h=e;o||([h,a]=function(t,e,s,n,o,i,r){let a=t;const c=xt(n,o,i);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of vt(t)){let s;s="deep"===e.history?e=>L(e)&&gt(e,t):e=>e.parent===t,u??={...i},u[e.id]=Array.from(o).filter(s)}for(const t of c)a=Ot(a,e,s,[...t.exit,...t.invoke.map((t=>U(t.id)))],r),o.delete(t);return[a,u||i]}(h,n,s,u,r,a,i)),h=Ot(h,n,s,u.flatMap((t=>t.actions)),i),h=function(t,e,s,n,o,i,r,a){let u=t;const h=new Set,f=new Set;(function(t,e,s,n){for(const o of t){const t=St(o,e);for(const i of o.target||[])ut(i)||o.source===i&&o.source===t&&!o.reenter||(n.add(i),s.add(i)),It(i,e,s,n);const i=bt(o,e);for(const r of i){const i=Z(r,t);"parallel"===t?.type&&i.push(t),$t(n,e,s,i,!o.source.parent&&o.reenter?void 0:t)}}})(n,r,f,h),a&&f.add(t.machine.root);const d=new Set;for(const t of[...h].sort(((t,e)=>t.order-e.order))){o.add(t);const n=[];n.push(...t.entry);for(const e of t.invoke)n.push(q(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(f.has(t)){const e=t.initial.actions;n.push(...e)}if(u=Ot(u,e,s,n,i,t.invoke.map((t=>t.id))),"final"===t.type){const n=t.parent;let r="parallel"===n?.type?n:n?.parent,a=r||t;for("compound"===n?.type&&i.push(c(n.id,t.output?w(t.output,u.context,e,s.self):void 0));"parallel"===r?.type&&!d.has(r)&&ot(o,r);)d.add(r),i.push(c(r.id)),a=r,r=r.parent;if(r)continue;u=qt(u,{status:"done",output:kt(u,e,s,u.machine.root,a)})}}return u}(h,n,s,u,r,i,a,o);const f=[...r];"done"===h.status&&(h=Ot(h,n,s,f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),i));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;return!0}(e._nodes,r)?h:qt(h,{_nodes:f,historyValue:a})}catch(t){throw t}}function kt(t,e,s,n,o){if(!n.output)return;const i=c(o.id,o.output&&o.parent?w(o.output,t.context,e,s.self):void 0);return w(n.output,t.context,i,s.self)}function It(t,e,s,n){if(ut(t))if(e[t.id]){const o=e[t.id];for(const t of o)n.add(t),It(t,e,s,n);for(const i of o)Et(i,t.parent,n,e,s)}else{const o=ct(t);for(const i of o.target)n.add(i),o===t.parent?.initial&&s.add(t.parent),It(i,e,s,n);for(const i of o.target)Et(i,t,n,e,s)}else if("compound"===t.type){const[o]=t.initial.target;ut(o)||(n.add(o),s.add(o)),It(o,e,s,n),Et(o,t,n,e,s)}else if("parallel"===t.type)for(const o of Y(t).filter((t=>!ut(t))))[...n].some((t=>gt(t,o)))||(ut(o)||(n.add(o),s.add(o)),It(o,e,s,n))}function $t(t,e,s,n,o){for(const i of n)if(o&&!gt(i,o)||t.add(i),"parallel"===i.type)for(const n of Y(i).filter((t=>!ut(t))))[...t].some((t=>gt(t,n)))||(t.add(n),It(n,e,s,t))}function Et(t,e,s,n,o){$t(s,n,o,Z(t,e))}function Tt(t,e,s,n,o,i){const{machine:r}=t;let a=t;for(const t of n){const n="function"==typeof t,c=n?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:s?.self,system:s?.system},h=n||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in c)){s?.self._processingStatus===j.Running?c(u,h):s?.defer((()=>{c(u,h)}));continue}const f=c,[d,p,l]=f.resolve(s,a,u,h,c,o);a=d,"retryResolve"in f&&i?.push([f,p]),"execute"in f&&(s?.self._processingStatus===j.Running?f.execute(s,p):s?.defer(f.execute.bind(null,s,p))),l&&(a=Tt(a,e,s,l,o,i))}return a}function Ot(t,e,s,n,o,i){const r=i?[]:void 0,a=Tt(t,e,s,n,{internalQueue:o,deferredActorIds:i},r);return r?.forEach((([t,e])=>{t.retryResolve(s,a,e)})),a}function Mt(t,e,s,n=[]){let o=t;const r=[];if(e.type===a)return o=qt(jt(o,e,s),{status:"stopped"}),r.push(o),{snapshot:o,microstates:r};let c=e;if(c.type!==i){const e=c,i=function(t){return t.type.startsWith("xstate.error.actor")}(e),a=Nt(e,o);if(i&&!a.length)return o=qt(t,{status:"error",error:e.data}),r.push(o),{snapshot:o,microstates:r};o=wt(a,t,s,c,!1,n),r.push(o)}let u=!0;for(;"active"===o.status;){let t=u?At(o,c):[];const e=t.length?o:void 0;if(!t.length){if(!n.length)break;c=n.shift(),t=Nt(c,o)}o=wt(t,o,s,c,!1,n),u=o!==e,r.push(o)}return"active"!==o.status&&jt(o,c,s),{snapshot:o,microstates:r}}function jt(t,e,s){return Ot(t,e,s,Object.values(t.children).map((t=>U(t))),[])}function Nt(t,e){return e.machine.getTransitionData(e,t)}function At(t,e){const s=new Set,n=t._nodes.filter(L);for(const o of n)t:for(const n of[o].concat(Z(o,void 0)))if(n.always)for(const o of n.always)if(void 0===o.guard||K(o.guard,t.context,e,t)){s.add(o);break t}return _t(Array.from(s),new Set(t._nodes),t.historyValue)}function Pt(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Rt=function(t){return v(t,this.value)},Ct=function(t){return this.tags.has(t)},Dt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Jt=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:o,can:i,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Vt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Bt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:nt(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Rt,hasTag:Ct,can:Dt,getMeta:Vt,toJSON:Jt}}function qt(t,e={}){return Bt({...t,...e},t.machine)}function zt(t){let e;for(const s in t){const n=t[s];if(n&&"object"==typeof n)if("sessionId"in n&&"send"in n&&"ref"in n)e??=Array.isArray(t)?t.slice():{...t},e[s]={xstate$$type:M,id:n.id};else{const o=zt(n);o!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=o)}}return e??t}function Wt(t,{machine:e,context:s},n,o){return(i,r)=>{const a=((i,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof i){const u=O(e,i);if(!u)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const h=P(u,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof c?c({context:s,event:n,self:t.self}):c,src:i,systemId:a});return o[h.id]=h,h}return P(i,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:i,systemId:a})})(i,r);return o[a.id]=a,t.defer((()=>{a._processingStatus!==j.Stopped&&a.start()})),a}}function Ut(t,e,s,n,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},r={context:e.context,event:s.event,spawn:Wt(t,e,s.event,i),self:t?.self,system:t?.system};let a={};if("function"==typeof o)a=o(r,n);else for(const t of Object.keys(o)){const e=o[t];a[t]="function"==typeof e?e(r,n):e}return[qt(e,{context:Object.assign({},e.context,a),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Qt(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ut,e}function Ft(t,e,s,n,{event:o,id:i,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const u="function"==typeof o?o(s,n):o;let h;if("string"==typeof r){const t=c&&c[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&a.push(u),[e,{event:u,id:i,delay:h}]}function Gt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Xt(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Ft,s.execute=Gt,s}let Ht=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Kt(t,e,s,n,{to:o,event:i,id:r,delay:a},c){const u=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 h="function"==typeof i?i(s,n):i;let f;if("string"==typeof a){const t=u&&u[a];f="function"==typeof t?t(s,n):t}else f="function"==typeof a?a(s,n):a;const d="function"==typeof o?o(s,n):o;let p;if("string"==typeof d){if(p=d===Ht.Parent?t?.self._parent:d===Ht.Internal?t?.self:d.startsWith("#_")?e.children[d.slice(2)]:c.deferredActorIds?.includes(d)?d:e.children[d],!p)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else p=d||t?.self;return[e,{to:p,event:h,id:r,delay:f}]}function Lt(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function Yt(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:n}=e;t?.system._relay(t.self,s,n.type===r?u(t.self.id,n.data):n)})):t.self.delaySend(e)}function Zt(t,e,s){function n(t,e){}return n.type="xsnapshot.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Kt,n.retryResolve=Lt,n.execute=Yt,n}function te(t,e){return Zt(Ht.Parent,t,e)}function ee(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(Qt(...t))},r.cancel=(...t)=>{i.push(J(...t))},r.raise=(...t)=>{i.push(Xt(...t))},r.sendTo=(...t)=>{i.push(Zt(...t))},r.spawnChild=(...t)=>{i.push(q(...t))},r.stopChild=(...t)=>{i.push(U(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>K(t,e.context,s.event,e)}),[e,void 0,i]}function se(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function ne({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function oe(t,e){return{config:t,transition:(e,s,n)=>({...e,context:t(e.context,s,n)}),getInitialState:(t,s)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:s}):e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const ie=new WeakMap;const re="xstate.observable.next",ae="xstate.observable.error",ce="xstate.observable.complete";const ue="xstate.promise.resolve",he="xstate.promise.reject";const fe=oe((t=>{}),void 0);const de=new WeakMap;function pe(t,e,s){let n=de.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},de.set(t,n)),n[e]}const le={},ye=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ve{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(s),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?b(this.config.states,((t,e)=>new ve(t,{_parent:this,_key:e,_machine:this.machine}))):le,"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=x(this.config.entry).slice(),this.exit=x(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=x(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const s of Object.keys(t.config.on)){if(s===o)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,I(n).map((e=>at(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,I(t.config.onDone).map((e=>at(t,s,e))))}for(const s of t.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;e.set(n,I(s.onDone).map((e=>at(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,I(s.onError).map((e=>at(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,I(s.onSnapshot).map((e=>at(t,n,e))))}}for(const s of t.after){let t=e.get(s.eventType);t||(t=[],e.set(s.eventType,t)),t.push(s)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>at(this,o,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(ye),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(ye),eventType:null})}:void 0,history:this.history,states:b(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(ye)}))),entry:this.entry.map(ye),exit:this.exit.map(ye),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 pe(this,"invoke",(()=>x(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,o=t.id??T(this.id,e),i="string"==typeof s?s:`xstate.invoke.${T(this.id,e)}`;return{...t,src:i,id:o,systemId:n,toJSON(){const{onDone:e,onError:s,...n}=t;return{...n,type:"xstate.invoke",src:i,id:o}}}}))))}get on(){return pe(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,s])=>(t[e]=t[e]||[],t[e].push(s),t)),{})))}get after(){return pe(this,"delayedTransitions",(()=>rt(this)))}get initial(){return pe(this,"initial",(()=>function(t,e){const s="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!s&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const n={source:t,actions:e&&"string"!=typeof e?x(e.actions):[],eventType:null,reenter:!1,target:s?[s]:[],toJSON:()=>({...n,source:`#${t.id}`,target:s?[`#${s.id}`]:[]})};return n}(this,this.config.initial)))}next(t,e){const s=e.type,n=[];let o;const i=pe(this,`candidates-${s}`,(()=>{return e=s,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const s=t.split("."),n=e.split(".");for(let t=0;t<s.length;t++){const e=s[t],o=n[t];if("*"===e)return t===s.length-1;if(e!==o)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of i){const{guard:i}=r,a=t.context;let c=!1;try{c=!i||K(i,a,e,t)}catch(t){const e="string"==typeof i?i:"object"==typeof i?i.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(c){n.push(...r.actions),o=r;break}}return o?[o]:void 0}get events(){return pe(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const n=t[s];if(n.states)for(const t of n.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 ge{constructor(t,e){this.config=t,this.version=void 0,this.implementations=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.__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.transition=this.transition.bind(this),this.getInitialState=this.getInitialState.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new ve(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:s,actors:n,delays:o}=this.implementations;return new ge(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...n,...t.actors},delays:{...o,...t.delays}})}resolveState(t){const e=(s=this.root,n=t.value,nt(s,[...tt(lt(s,n))]));var s,n;const o=tt(lt(this.root,e));return Bt({_nodes:[...o],context:t.context||{},children:{},status:ot(o,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return Mt(t,e,s).snapshot}microstep(t,e,s){return Mt(t,e,s).microstates}getTransitionData(t,e){return yt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,o=Bt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return Ot(o,e,t,[Qt((({spawn:t,event:e})=>n({spawn:t,input:e.input})))],s)}return o}getInitialState(t,e){const s=h(e),n=[],o=this.getPreInitialState(t,s,n),i=wt([{target:[...ft(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],o,t,s,!0,n),{snapshot:r}=Mt(i,s,t,n);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(s),n=e.slice(1),o=it(e[0])?e[0].slice(1):e[0],i=this.idMap.get(o);if(!i)throw new Error(`Child state node '#${o}' does not exist on machine '${this.id}'`);return pt(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return function(t,e){const{_nodes:s,tags:n,machine:o,children:i,context:r,can:a,hasTag:c,matches:u,getMeta:h,toJSON:f,...d}=t,p={};for(const t in i){const s=i[t];p[t]={snapshot:s.getPersistedSnapshot(e),src:s.src,systemId:s._systemId,syncSnapshot:s._syncSnapshot}}return{...d,context:zt(r),children:p}}(t,e)}restoreSnapshot(t,e){const s={},n=t.children;Object.keys(n).forEach((t=>{const o=n[t],i=o.snapshot,r=o.src,a="string"==typeof r?O(this,r):r;if(!a)return;const c=P(a,{id:t,parent:e?.self,syncSnapshot:o.syncSnapshot,snapshot:i,src:r,systemId:o.systemId});s[t]=c}));const o=Bt({...t,children:s,_nodes:Array.from(tt(lt(this.root,t.value)))},this);let i=new Set;return function t(e,s){if(!i.has(e)){i.add(e);for(let n in e){const o=e[n];if(o&&"object"==typeof o){if("xstate$$type"in o&&o.xstate$$type===M){e[n]=s[o.id];continue}t(o,s)}}}}(o.context,s),o}}const me={timeout:1/0};function _e(t,e){return new ge(t,e)}t.Actor=A,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 s=this.getId();return this.timeouts.set(s,{start:this.now(),timeout:e,fn:t}),s}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],[s,n])=>{const o=e.start+e.timeout;return n.start+n.timeout>o?-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=Ht,t.StateMachine=ge,t.StateNode=ve,t.__unsafe_getAllOwnEventDescriptors=function(t){return[...new Set([...t._nodes.flatMap((t=>t.ownEvents))])]},t.and=function(t){function e(t,e){return!1}return e.check=X,e.guards=t,e},t.assign=Qt,t.cancel=J,t.createActor=P,t.createEmptyActor=function(){return P(fe)},t.createMachine=_e,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=ee,e},t.escalate=function(t,e){return te((e=>({type:r,data:"function"==typeof t?t(e):t})),e)},t.forwardTo=function(t,e){return Zt(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(e,s)=>{const{self:n,system:o}=s,i={receivers:void 0,dispose:void 0};ie.set(n,i),i.dispose=t({input:e.input,system:o,self:n,sendBack:t=>{"stopped"!==n.getSnapshot().status&&n._parent&&o._relay(n,n._parent,t)},receive:t=>{i.receivers??=new Set,i.receivers.add(t)}})},transition:(t,e,s)=>{const n=ie.get(s.self);return e.type===a?(t={...t,status:"stopped",error:void 0},n.dispose?.(),t):(n.receivers?.forEach((t=>t(e))),t)},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,e,{self:s,id:n,defer:o,system:i})=>{if("active"!==t.status)return t;switch(e.type){case re:return{...t,context:e.data};case ae:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ce:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{n._relay(s,s,{type:re,data:t})},error:t=>{n._relay(s,s,{type:ae,data:t})},complete:()=>{n._relay(s,s,{type:ce})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot: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 ue:{const s=e.data;return{...t,status:"done",output:s,input:void 0}}case he:return{...t,status:"error",error:e.data,input:void 0};case a:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:s,system:n})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:n,self:s})).then((t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:ue,data:t})}),(t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:he,data:t})}))},getInitialState:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=oe,t.getStateNodes=lt,t.interpret=R,t.isMachineSnapshot=Pt,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=se,s.execute=ne,s},t.matchesState=v,t.not=function(t){function e(t,e){return!1}return e.check=G,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=H,e.guards=t,e},t.pathToStateValue=_,t.raise=Xt,t.sendParent=te,t.sendTo=Zt,t.setup=function({actors:t,actions:e,guards:s,delays:n}){return{createMachine:o=>_e(o,{actors:t,actions:e,guards:s,delays:n})}},t.spawnChild=q,t.stateIn=function(t){function e(t,e){return!1}return e.check=F,e.stateValue=t,e},t.stop=Q,t.stopChild=U,t.toObserver=E,t.waitFor=function(t,e,s){const n={...me,...s};return new Promise(((s,o)=>{let i=!1;const r=n.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),o(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),a=()=>{clearTimeout(r),i=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),s(t))}let u;c(t.getSnapshot()),i||(u=t.subscribe({next:c,error:t=>{a(),o(t)},complete:()=>{a(),o(new Error("Actor terminated without satisfying predicate"))}}),i&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate.umd.min.js.map