xstate 5.0.0-alpha.6 → 5.0.0-beta.10

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 (70) hide show
  1. package/actions/dist/xstate-actions.cjs.d.mts +2 -0
  2. package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
  3. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  4. package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
  5. package/actions/dist/xstate-actions.cjs.dev.js +2 -2
  6. package/actions/dist/xstate-actions.cjs.mjs +24 -0
  7. package/actions/dist/xstate-actions.cjs.prod.js +3 -3
  8. package/actions/dist/xstate-actions.esm.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js +1 -1
  10. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  11. package/actors/dist/xstate-actors.cjs.d.mts +2 -0
  12. package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
  13. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  14. package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
  15. package/actors/dist/xstate-actors.cjs.dev.js +2 -1
  16. package/actors/dist/xstate-actors.cjs.mjs +15 -0
  17. package/actors/dist/xstate-actors.cjs.prod.js +3 -2
  18. package/actors/dist/xstate-actors.esm.js +1 -1
  19. package/actors/dist/xstate-actors.umd.min.js +1 -1
  20. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dev/dist/xstate-dev.cjs.d.mts +2 -0
  22. package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
  23. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  24. package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
  25. package/dev/dist/xstate-dev.cjs.mjs +5 -0
  26. package/dev/dist/xstate-dev.cjs.prod.js +6 -43
  27. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  28. package/dist/{actions-bf7bb1c5.cjs.dev.js → actions-109712d3.cjs.dev.js} +386 -371
  29. package/dist/{actions-41b74cdc.esm.js → actions-67f1d04e.esm.js} +341 -358
  30. package/dist/{actions-c46e4911.cjs.prod.js → actions-d0262a43.cjs.prod.js} +409 -380
  31. package/dist/declarations/src/State.d.ts +2 -3
  32. package/dist/declarations/src/StateMachine.d.ts +6 -6
  33. package/dist/declarations/src/StateNode.d.ts +3 -9
  34. package/dist/declarations/src/actions/send.d.ts +0 -7
  35. package/dist/declarations/src/actions.d.ts +9 -8
  36. package/dist/declarations/src/actors/index.d.ts +2 -1
  37. package/dist/declarations/src/actors/observable.d.ts +1 -2
  38. package/dist/declarations/src/actors/promise.d.ts +1 -2
  39. package/dist/declarations/src/guards.d.ts +2 -2
  40. package/dist/declarations/src/index.d.ts +13 -29
  41. package/dist/declarations/src/interpreter.d.ts +5 -4
  42. package/dist/declarations/src/spawn.d.ts +2 -2
  43. package/dist/declarations/src/stateUtils.d.ts +9 -14
  44. package/dist/declarations/src/typegenTypes.d.ts +7 -1
  45. package/dist/declarations/src/types.d.ts +18 -92
  46. package/dist/declarations/src/utils.d.ts +3 -5
  47. package/dist/declarations/src/waitFor.d.ts +33 -0
  48. package/dist/index-0f3fdf0c.cjs.prod.js +52 -0
  49. package/dist/xstate.cjs.d.mts +2 -0
  50. package/dist/xstate.cjs.d.mts.map +1 -0
  51. package/dist/xstate.cjs.d.ts +1 -0
  52. package/dist/xstate.cjs.d.ts.map +1 -0
  53. package/dist/xstate.cjs.dev.js +117 -105
  54. package/dist/xstate.cjs.mjs +38 -0
  55. package/dist/xstate.cjs.prod.js +115 -106
  56. package/dist/xstate.esm.js +100 -93
  57. package/dist/xstate.umd.min.js +1 -1
  58. package/dist/xstate.umd.min.js.map +1 -1
  59. package/guards/dist/xstate-guards.cjs.d.mts +2 -0
  60. package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
  61. package/guards/dist/xstate-guards.cjs.d.ts +1 -0
  62. package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
  63. package/guards/dist/xstate-guards.cjs.dev.js +1 -1
  64. package/guards/dist/xstate-guards.cjs.mjs +8 -0
  65. package/guards/dist/xstate-guards.cjs.prod.js +2 -2
  66. package/guards/dist/xstate-guards.esm.js +1 -1
  67. package/guards/dist/xstate-guards.umd.min.js +1 -1
  68. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  69. package/package.json +7 -1
  70. package/dist/declarations/src/schema.d.ts +0 -2
@@ -1,28 +1,7 @@
1
- import { c as createDynamicAction, p as pure$1, t as toArray, a as toActionObjects, _ as _createClass, f as formatTransitions, b as toTransitionConfigArray, N as NULL_EVENT, d as formatTransition, m as mapValues, e as memo, g as _createForOfIteratorHelper, h as evaluateGuard, i as _toConsumableArray, j as flatten, k as _classCallCheck, l as _defineProperty, n as createInvokeId, o as toInvokeConfig, q as _objectSpread2, r as invoke, s as _objectWithoutProperties, u as getDelayedTransitions, v as formatInitialTransition, w as getCandidates, x as isString, y as createSpawner, z as createInitEvent, A as getConfiguration, B as getStateNodes, C as resolveStateValue, D as isInFinalState, S as State, E as toSCXMLEvent, F as isSCXMLErrorEvent, G as macrostep, H as transitionNode, I as _slicedToArray, J as getInitialConfiguration, K as resolveActionsAndContext, L as microstep, M as error, O as isStateId, P as getStateNodeByPath, Q as getPersistedState, R as resolveReferencedActor, T as interpret, U as STATE_DELIMITER, V as initEvent, W as matchesState, X as raise, Y as send, Z as sendParent, $ as sendTo, a0 as log, a1 as cancel, a2 as stop, a3 as assign, a4 as after, a5 as done, a6 as respond, a7 as forwardTo, a8 as escalate, a9 as choose } from './actions-41b74cdc.esm.js';
2
- export { af as ActionTypes, aa as Interpreter, ab as InterpreterStatus, ag as SpecialTargets, S as State, a3 as assign, ac as doneInvoke, a7 as forwardTo, B as getStateNodes, T as interpret, W as matchesState, ad as pathToStateValue, Y as send, Z as sendParent, $ as sendTo, ae as toObserver, E as toSCXMLEvent } from './actions-41b74cdc.esm.js';
1
+ import { _ as _createClass, f as formatTransitions, t as toTransitionConfigArray, N as NULL_EVENT, a as formatTransition, m as mapValues, b as memo, c as _createForOfIteratorHelper, e as evaluateGuard, d as _toConsumableArray, g as flatten, h as _classCallCheck, i as _defineProperty, j as toActionObjects, k as toArray, l as createInvokeId, n as toInvokeConfig, o as _objectSpread2, p as invoke, q as _objectWithoutProperties, r as getDelayedTransitions, s as formatInitialTransition, u as getCandidates, v as isString, w as createSpawner, x as getConfiguration, y as getStateNodes, z as resolveStateValue, A as isInFinalState, S as State, B as isErrorEvent, C as macrostep, D as transitionNode, E as _slicedToArray, F as getInitialConfiguration, G as createInitEvent, H as resolveActionsAndContext, I as microstep, J as error, K as isStateId, L as getStateNodeByPath, M as getPersistedState, O as resolveReferencedActor, P as interpret, Q as STATE_DELIMITER, R as initEvent, T as matchesState } from './actions-67f1d04e.esm.js';
2
+ export { ah as ActionTypes, X as Interpreter, Y as InterpreterStatus, ai as SpecialTargets, S as State, af as and, $ as assign, a0 as cancel, a1 as choose, Z as doneInvoke, W as forwardTo, aa as fromCallback, ab as fromEventObservable, a9 as fromObservable, a8 as fromPromise, ac as fromTransition, y as getStateNodes, P as interpret, a2 as log, T as matchesState, ae as not, ag as or, a6 as pathToStateValue, a3 as pure, a4 as raise, V as sendParent, U as sendTo, ad as stateIn, a5 as stop, a7 as toObserver } from './actions-67f1d04e.esm.js';
3
3
  import './index-50bd0aff.esm.js';
4
4
 
5
- function pure(getActions) {
6
- return createDynamicAction({
7
- type: pure$1,
8
- params: {
9
- get: getActions
10
- }
11
- }, function (_event, _ref) {
12
- var _toArray;
13
- var state = _ref.state;
14
- return [state, {
15
- type: pure$1,
16
- params: {
17
- actions: (_toArray = toArray(toActionObjects(getActions({
18
- context: state.context,
19
- event: _event.data
20
- })))) !== null && _toArray !== void 0 ? _toArray : []
21
- }
22
- }];
23
- });
24
- }
25
-
26
5
  var _excluded = ["onDone", "onError"];
27
6
  var EMPTY_OBJECT = {};
28
7
  var StateNode = /*#__PURE__*/function () {
@@ -84,7 +63,7 @@ var StateNode = /*#__PURE__*/function () {
84
63
  */
85
64
 
86
65
  /**
87
- * The order this state node appears. Corresponds to the implicit SCXML document order.
66
+ * The order this state node appears. Corresponds to the implicit document order.
88
67
  */
89
68
 
90
69
  function StateNode(
@@ -173,7 +152,7 @@ var StateNode = /*#__PURE__*/function () {
173
152
  source: this,
174
153
  actions: this.initial.actions,
175
154
  eventType: null,
176
- external: false,
155
+ reenter: false,
177
156
  toJSON: function toJSON() {
178
157
  return {
179
158
  target: _this3.initial.target.map(function (t) {
@@ -232,9 +211,9 @@ var StateNode = /*#__PURE__*/function () {
232
211
  id: resolvedId,
233
212
  systemId: systemId,
234
213
  toJSON: function toJSON() {
235
- var onDone = invokeConfig.onDone,
236
- onError = invokeConfig.onError,
237
- invokeDefValues = _objectWithoutProperties(invokeConfig, _excluded);
214
+ invokeConfig.onDone;
215
+ invokeConfig.onError;
216
+ var invokeDefValues = _objectWithoutProperties(invokeConfig, _excluded);
238
217
  return _objectSpread2(_objectSpread2({}, invokeDefValues), {}, {
239
218
  type: invoke,
240
219
  src: resolvedSrc,
@@ -278,27 +257,15 @@ var StateNode = /*#__PURE__*/function () {
278
257
  return formatInitialTransition(_this7, _this7.config.initial || []);
279
258
  });
280
259
  }
281
-
282
- /**
283
- * Returns `true` if this state node explicitly handles the given event.
284
- *
285
- * @param event The event in question
286
- */
287
- }, {
288
- key: "handles",
289
- value: function handles(event) {
290
- return this.events.includes(event.type);
291
- }
292
260
  }, {
293
261
  key: "next",
294
- value: function next(state, _event) {
262
+ value: function next(state, event) {
295
263
  var _this8 = this;
296
- var eventName = _event.name;
264
+ var eventType = event.type;
297
265
  var actions = [];
298
266
  var selectedTransition;
299
- var candidates = memo(this, "candidates-".concat(eventName.toString()), function () {
300
- return getCandidates(_this8, eventName, _this8.machine.config.scxml // Whether token matching should be used
301
- );
267
+ var candidates = memo(this, "candidates-".concat(eventType), function () {
268
+ return getCandidates(_this8, eventType);
302
269
  });
303
270
  var _iterator = _createForOfIteratorHelper(candidates),
304
271
  _step;
@@ -309,9 +276,9 @@ var StateNode = /*#__PURE__*/function () {
309
276
  var resolvedContext = state.context;
310
277
  var guardPassed = false;
311
278
  try {
312
- guardPassed = !guard || evaluateGuard(guard, resolvedContext, _event, state);
279
+ guardPassed = !guard || evaluateGuard(guard, resolvedContext, event, state);
313
280
  } catch (err) {
314
- throw new Error("Unable to evaluate guard '".concat(guard.type, "' in transition for event '").concat(eventName, "' in state node '").concat(this.id, "':\n").concat(err.message));
281
+ throw new Error("Unable to evaluate guard '".concat(guard.type, "' in transition for event '").concat(eventType, "' in state node '").concat(this.id, "':\n").concat(err.message));
315
282
  }
316
283
  if (guardPassed) {
317
284
  actions.push.apply(actions, _toConsumableArray(candidate.actions));
@@ -397,7 +364,7 @@ var StateNode = /*#__PURE__*/function () {
397
364
  key: "ownEvents",
398
365
  get: function get() {
399
366
  var events = new Set(this.transitions.filter(function (transition) {
400
- return !(!transition.target && !transition.actions.length && !transition.external);
367
+ return !(!transition.target && !transition.actions.length && !transition.reenter);
401
368
  }).map(function (transition) {
402
369
  return transition.eventType;
403
370
  }));
@@ -423,13 +390,13 @@ var StateMachine = /*#__PURE__*/function () {
423
390
  * The raw config used to create the machine.
424
391
  */
425
392
  config, options) {
426
- var _this$config$schema;
393
+ var _this$config$types;
427
394
  _classCallCheck(this, StateMachine);
428
395
  this.config = config;
429
396
  _defineProperty(this, "version", void 0);
430
397
  _defineProperty(this, "delimiter", void 0);
431
398
  _defineProperty(this, "options", void 0);
432
- _defineProperty(this, "schema", void 0);
399
+ _defineProperty(this, "types", void 0);
433
400
  _defineProperty(this, "__xstatenode", true);
434
401
  _defineProperty(this, "idMap", new Map());
435
402
  _defineProperty(this, "root", void 0);
@@ -445,7 +412,7 @@ var StateMachine = /*#__PURE__*/function () {
445
412
  this.options = Object.assign(createDefaultOptions(), options);
446
413
  this.delimiter = this.config.delimiter || STATE_DELIMITER;
447
414
  this.version = this.config.version;
448
- this.schema = (_this$config$schema = this.config.schema) !== null && _this$config$schema !== void 0 ? _this$config$schema : {};
415
+ this.types = (_this$config$types = this.config.types) !== null && _this$config$types !== void 0 ? _this$config$types : {};
449
416
  this.transition = this.transition.bind(this);
450
417
  this.root = new StateNode(config, {
451
418
  _key: this.id,
@@ -545,13 +512,12 @@ var StateMachine = /*#__PURE__*/function () {
545
512
  var actorCtx = arguments.length > 2 ? arguments[2] : undefined;
546
513
  var currentState = state instanceof State ? state : this.resolveStateValue(state);
547
514
  // TODO: handle error events in a better way
548
- var scxmlEvent = toSCXMLEvent(event);
549
- if (isSCXMLErrorEvent(scxmlEvent) && !currentState.nextEvents.some(function (nextEvent) {
550
- return nextEvent === scxmlEvent.name;
515
+ if (isErrorEvent(event) && !currentState.nextEvents.some(function (nextEvent) {
516
+ return nextEvent === event.type;
551
517
  })) {
552
- throw scxmlEvent.data.data;
518
+ throw event.data;
553
519
  }
554
- var _macrostep = macrostep(currentState, scxmlEvent, actorCtx),
520
+ var _macrostep = macrostep(currentState, event, actorCtx),
555
521
  nextState = _macrostep.state;
556
522
  return nextState;
557
523
  }
@@ -569,15 +535,12 @@ var StateMachine = /*#__PURE__*/function () {
569
535
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.initialState;
570
536
  var event = arguments.length > 1 ? arguments[1] : undefined;
571
537
  var actorCtx = arguments.length > 2 ? arguments[2] : undefined;
572
- var scxmlEvent = toSCXMLEvent(event);
573
- var _macrostep2 = macrostep(state, scxmlEvent, actorCtx),
574
- microstates = _macrostep2.microstates;
575
- return microstates;
538
+ return macrostep(state, event, actorCtx).microstates;
576
539
  }
577
540
  }, {
578
541
  key: "getTransitionData",
579
- value: function getTransitionData(state, _event) {
580
- return transitionNode(this.root, state.value, state, _event) || [];
542
+ value: function getTransitionData(state, event) {
543
+ return transitionNode(this.root, state.value, state, event) || [];
581
544
  }
582
545
 
583
546
  /**
@@ -597,7 +560,7 @@ var StateMachine = /*#__PURE__*/function () {
597
560
  value: {},
598
561
  // TODO: this is computed in state constructor
599
562
  context: context,
600
- _event: createInitEvent({}),
563
+ event: createInitEvent({}),
601
564
  actions: [],
602
565
  meta: undefined,
603
566
  configuration: config,
@@ -637,8 +600,8 @@ var StateMachine = /*#__PURE__*/function () {
637
600
  var preInitialState = this.getPreInitialState(actorCtx, input);
638
601
  var nextState = microstep([], preInitialState, actorCtx, initEvent);
639
602
  (_nextState$actions = nextState.actions).unshift.apply(_nextState$actions, _toConsumableArray(preInitialState.actions));
640
- var _macrostep3 = macrostep(nextState, initEvent, actorCtx),
641
- macroState = _macrostep3.state;
603
+ var _macrostep2 = macrostep(nextState, initEvent, actorCtx),
604
+ macroState = _macrostep2.state;
642
605
  return macroState;
643
606
  }
644
607
  }, {
@@ -693,7 +656,7 @@ var StateMachine = /*#__PURE__*/function () {
693
656
  key: "createState",
694
657
  value: function createState(stateConfig) {
695
658
  var state = stateConfig instanceof State ? stateConfig : new State(stateConfig, this);
696
- var _resolveActionsAndCon2 = resolveActionsAndContext(state.actions, state._event, state, undefined),
659
+ var _resolveActionsAndCon2 = resolveActionsAndContext(state.actions, state.event, state, undefined),
697
660
  resolvedState = _resolveActionsAndCon2.nextState;
698
661
  return resolvedState;
699
662
  }
@@ -777,11 +740,6 @@ function mapState(stateMap, stateId) {
777
740
  return stateMap[foundStateId];
778
741
  }
779
742
 
780
- function createSchema(schema) {
781
- return schema;
782
- }
783
- var t = createSchema;
784
-
785
743
  var SimulatedClock = /*#__PURE__*/function () {
786
744
  function SimulatedClock() {
787
745
  _classCallCheck(this, SimulatedClock);
@@ -829,12 +787,12 @@ var SimulatedClock = /*#__PURE__*/function () {
829
787
  value: function flushTimeouts() {
830
788
  var _this = this;
831
789
  _toConsumableArray(this.timeouts).sort(function (_ref, _ref2) {
832
- var _ref3 = _slicedToArray(_ref, 2),
833
- _idA = _ref3[0],
834
- timeoutA = _ref3[1];
835
- var _ref4 = _slicedToArray(_ref2, 2),
836
- _idB = _ref4[0],
837
- timeoutB = _ref4[1];
790
+ var _ref3 = _slicedToArray(_ref, 2);
791
+ _ref3[0];
792
+ var timeoutA = _ref3[1];
793
+ var _ref4 = _slicedToArray(_ref2, 2);
794
+ _ref4[0];
795
+ var timeoutB = _ref4[1];
838
796
  var endA = timeoutA.start + timeoutA.timeout;
839
797
  var endB = timeoutB.start + timeoutB.timeout;
840
798
  return endB > endA ? -1 : 1;
@@ -858,22 +816,71 @@ var SimulatedClock = /*#__PURE__*/function () {
858
816
  return SimulatedClock;
859
817
  }();
860
818
 
861
- var actions = {
862
- raise: raise,
863
- send: send,
864
- sendParent: sendParent,
865
- sendTo: sendTo,
866
- log: log,
867
- cancel: cancel,
868
- stop: stop,
869
- assign: assign,
870
- after: after,
871
- done: done,
872
- respond: respond,
873
- forwardTo: forwardTo,
874
- escalate: escalate,
875
- choose: choose,
876
- pure: pure
819
+ var defaultWaitForOptions = {
820
+ timeout: 10000 // 10 seconds
877
821
  };
878
822
 
879
- export { SimulatedClock, StateMachine, StateNode, actions, createMachine, createSchema, mapState, t };
823
+ /**
824
+ * Subscribes to an actor ref and waits for its emitted value to satisfy
825
+ * a predicate, and then resolves with that value.
826
+ * Will throw if the desired state is not reached after a timeout
827
+ * (defaults to 10 seconds).
828
+ *
829
+ * @example
830
+ * ```js
831
+ * const state = await waitFor(someService, state => {
832
+ * return state.hasTag('loaded');
833
+ * });
834
+ *
835
+ * state.hasTag('loaded'); // true
836
+ * ```
837
+ *
838
+ * @param actorRef The actor ref to subscribe to
839
+ * @param predicate Determines if a value matches the condition to wait for
840
+ * @param options
841
+ * @returns A promise that eventually resolves to the emitted value
842
+ * that matches the condition
843
+ */
844
+ function waitFor(actorRef, predicate, options) {
845
+ var resolvedOptions = _objectSpread2(_objectSpread2({}, defaultWaitForOptions), options);
846
+ return new Promise(function (res, rej) {
847
+ var done = false;
848
+ if (process.env.NODE_ENV !== 'production' && resolvedOptions.timeout < 0) {
849
+ console.error('`timeout` passed to `waitFor` is negative and it will reject its internal promise immediately.');
850
+ }
851
+ var handle = resolvedOptions.timeout === Infinity ? undefined : setTimeout(function () {
852
+ sub.unsubscribe();
853
+ rej(new Error("Timeout of ".concat(resolvedOptions.timeout, " ms exceeded")));
854
+ }, resolvedOptions.timeout);
855
+ var dispose = function dispose() {
856
+ clearTimeout(handle);
857
+ done = true;
858
+ sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
859
+ };
860
+ function checkEmitted(emitted) {
861
+ if (predicate(emitted)) {
862
+ dispose();
863
+ res(emitted);
864
+ }
865
+ }
866
+
867
+ // See if the current snapshot already matches the predicate
868
+ checkEmitted(actorRef.getSnapshot());
869
+ var sub = actorRef.subscribe({
870
+ next: checkEmitted,
871
+ error: function error(err) {
872
+ dispose();
873
+ rej(err);
874
+ },
875
+ complete: function complete() {
876
+ dispose();
877
+ rej(new Error("Actor terminated without satisfying predicate"));
878
+ }
879
+ });
880
+ if (done) {
881
+ sub.unsubscribe();
882
+ }
883
+ });
884
+ }
885
+
886
+ export { SimulatedClock, StateMachine, StateNode, createMachine, mapState, waitFor };
@@ -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";var e,n;(e=t.ActionTypes||(t.ActionTypes={})).Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Pure="xstate.pure",e.Choose="xstate.choose",(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var r=t.ActionTypes.Stop,i=t.ActionTypes.Raise,o=t.ActionTypes.Send,a=t.ActionTypes.Cancel,s=t.ActionTypes.Assign,u=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),c=t.ActionTypes.Init,l=t.ActionTypes.Invoke,f=t.ActionTypes.ErrorExecution,v=t.ActionTypes.ErrorPlatform,h=t.ActionTypes.ErrorCustom,d=t.ActionTypes.Choose,p=t.ActionTypes.Pure;function y(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function m(t,e,n){return(e=y(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function g(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){m(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function _(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function x(t,e){if(t){if("string"==typeof t)return _(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_(t,e):void 0}}function S(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,s=[],u=!0,c=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);u=!0);}catch(t){c=!0,i=t}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return s}}(t,e)||x(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(t){return function(t){if(Array.isArray(t))return _(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||x(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=x(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function E(t){return(E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var T="*";function I(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".",r=j(t,n),i=j(e,n);return J(i)?!!J(r)&&i===r:J(r)?r in i:Object.keys(r).every((function(t){return t in i&&I(r[t],i[t])}))}function O(t,e){try{return Q(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function j(t,e){return"object"===E(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:Q(t)?A(t):"string"!=typeof t?t:A(O(t,e));var n}function A(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function C(t,e){for(var n={},r=Object.keys(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function P(t){var e;return(e=[]).concat.apply(e,k(t))}function M(t){return Q(t)?t:[t]}function N(t){return void 0===t?[]:M(t)}function D(t,e,n){if(R(t))return t({context:e,event:n.data});for(var r={},i={context:e,event:n.data},o=0,a=Object.keys(t);o<a.length;o++){var s=a[o],u=t[s];R(u)?r[s]=u(i):r[s]=u}return r}function Q(t){return Array.isArray(t)}function R(t){return"function"==typeof t}function J(t){return"string"==typeof t}function V(t){return"string"==typeof t.name&&(t.name===f||t.name.startsWith(v))}function B(t,e){return function(t){return"$$type"in t&&"scxml"===t.$$type}(t)?t:b({name:t.type,data:t,$$type:"scxml",type:"external"},e)}function $(t,e){return M(e).map((function(e){return void 0===e||"string"==typeof e?{target:e,event:t}:b(b({},e),{},{event:t})}))}function z(t){if(void 0!==t&&""!==t)return N(t)}function U(t,e,n){var r=function(){},i="object"===E(t),o=i?t:null;return{next:((i?t.next:t)||r).bind(o),error:((i?t.error:e)||r).bind(o),complete:((i?t.complete:n)||r).bind(o)}}function W(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function q(t,e){return{type:t.type,params:t.params,resolve:e}}function L(t){return"object"===E(t)&&null!==t&&"resolve"in t}function X(e,n){return q({type:o,params:{to:n?n.to:void 0,delay:n?n.delay:void 0,event:e,id:n&&void 0!==n.id?n.id:R(e)?e.name:e.type}},(function(r,i){var a,s,u=i.actorContext,c=i.state,l={to:n?n.to:void 0,delay:n?n.delay:void 0,event:e,id:n&&void 0!==n.id?n.id:R(e)?e.name:e.type},f={context:c.context,event:r.data,_event:r,self:null!==(a=null==u?void 0:u.self)&&void 0!==a?a:null,system:null==u?void 0:u.system},v=c.machine.options.delays,d=B(R(e)?e(f):e);if(J(l.delay)){var p=v&&v[l.delay];s=R(p)?p(f):p}else s=R(l.delay)?l.delay(f):l.delay;var y,m=R(l.to)?l.to(f):l.to;if("string"==typeof m){if(!(y=m===t.SpecialTargets.Parent?null==u?void 0:u.self._parent:m===t.SpecialTargets.Internal?null==u?void 0:u.self:m.startsWith("#_")?c.children[m.slice(2)]:c.children[m]))throw new Error("Unable to send event to actor '".concat(m,"' from machine '").concat(c.machine.id,"'."))}else y=m||(null==u?void 0:u.self);var g={type:o,params:b(b({},l),{},{to:y,_event:d,event:d.data,delay:s,internal:m===t.SpecialTargets.Internal}),execute:function(t){var e=g;if("number"!=typeof e.params.delay){var n=e.params.to,r=e.params._event;t.defer((function(){var e=t.self,i=b(b({},r),{},{name:r.name===h?"".concat(he(e.id)):r.name,origin:e});n.send(i)}))}else t.self.delaySend(e)}};return[c,g]}))}function G(e,n){return X(e,b(b({},n),{},{to:t.SpecialTargets.Parent}))}function F(t,e){if("production"!==process.env.NODE_END&&(!t||"function"==typeof t)){var n=t;t=function(){var t="function"==typeof n?n.apply(void 0,arguments):n;if(!t)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return t}}return X((function(t){return t.event}),b(b({},e),{},{to:t}))}function H(t,e,n){return X(e,b(b({},n),{},{to:t}))}function K(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Y(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,y(r.key),r)}}function Z(t,e,n){return e&&Y(t.prototype,e),n&&Y(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var tt=function(){function t(e){K(this,t),this._process=e,m(this,"_active",!1),m(this,"_current",null),m(this,"_last",null)}return Z(t,[{key:"start",value:function(){this._active=!0,this.flush()}},{key:"clear",value:function(){this._current&&(this._current.next=null,this._last=this._current)}},{key:"prepend",value:function(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}},{key:"enqueue",value:function(t){var 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()}},{key:"flush",value:function(){for(;this._current;){var t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}]),t}(),et="function"==typeof Symbol&&Symbol.observable||"@@observable",nt="xstate.stop";function rt(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var it,ot=function(t){var e=rt();e&&e.register(t)};(it=t.InterpreterStatus||(t.InterpreterStatus={}))[it.NotStarted=0]="NotStarted",it[it.Running=1]="Running",it[it.Stopped=2]="Stopped";var at={deferEvents:!0,clock:{setTimeout:function(t){function e(e,n){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t,e){return setTimeout(t,e)})),clearTimeout:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return clearTimeout(t)}))},logger:console.log.bind(console),devTools:!1},st=function(){function e(n,r){var i,o=this;K(this,e),this.behavior=n,m(this,"_state",void 0),m(this,"clock",void 0),m(this,"options",void 0),m(this,"id",void 0),m(this,"mailbox",new tt(this._process.bind(this))),m(this,"delayedEventsMap",{}),m(this,"observers",new Set),m(this,"logger",void 0),m(this,"status",t.InterpreterStatus.NotStarted),m(this,"_parent",void 0),m(this,"ref",void 0),m(this,"_actorContext",void 0),m(this,"_systemId",void 0),m(this,"sessionId",void 0),m(this,"system",void 0),m(this,"_doneEvent",void 0),m(this,"src",void 0),m(this,"_deferred",[]);var a,s,u,c,l=b(b({},at),r),f=l.clock,v=l.logger,h=l.parent,d=l.id,p=l.systemId;this.system=null!==(i=null==h?void 0:h.system)&&void 0!==i?i:(a=0,s=new Map,u=new Map,c=new WeakMap,{_bookId:function(){return"x:".concat(a++)},_register:function(t,e){return s.set(t,e),t},_unregister:function(t){s.delete(t.sessionId);var e=c.get(t);void 0!==e&&(u.delete(e),c.delete(t))},get:function(t){return u.get(t)},_set:function(t,e){var n=u.get(t);if(n&&n!==e)throw new Error("Actor with system ID '".concat(t,"' already exists."));u.set(t,e),c.set(e,t)}}),p&&(this._systemId=p,this.system._set(p,this)),this.sessionId=this.system._bookId(),this.id=null!=d?d:this.sessionId,this.logger=v,this.clock=f,this._parent=h,this.options=l,this.src=l.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:function(t){o._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==o)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(o.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return Z(e,[{key:"_initState",value:function(){var t;this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,null===(t=this.options)||void 0===t?void 0:t.input)}},{key:"update",value:function(t){var e,n,r,i;this._state=t;for(var o,a=this.getSnapshot();o=this._deferred.shift();)o(t);var s,u=w(this.observers);try{for(u.s();!(s=u.n()).done;){var c,l=s.value;null===(c=l.next)||void 0===c||c.call(l,a)}}catch(t){u.e(t)}finally{u.f()}var f=null===(e=(n=this.behavior).getStatus)||void 0===e?void 0:e.call(n,t);switch(null==f?void 0:f.status){case"done":this._doneEvent=ve(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(B(this._doneEvent,{origin:this,invokeid:this.id})),this._stopProcedure();break;case"error":null===(i=this._parent)||void 0===i||i.send(B(he(this.id,f.data),{origin:this}));var v,h=w(this.observers);try{for(h.s();!(v=h.n()).done;){var d,p=v.value;null===(d=p.error)||void 0===d||d.call(p,f.data)}}catch(t){h.e(t)}finally{h.f()}}}},{key:"subscribe",value:function(e,n,r){var i,o=this,a=U(e,n,r);(this.observers.add(a),this.status===t.InterpreterStatus.Stopped)&&(null===(i=a.complete)||void 0===i||i.call(a),this.observers.delete(a));return{unsubscribe:function(){o.observers.delete(a)}}}},{key:"onDone",value:function(e){var n=this;return this.status===t.InterpreterStatus.Stopped&&this._doneEvent?e(this._doneEvent):this.observers.add({complete:function(){n._doneEvent&&e(n._doneEvent)}}),this}},{key:"start",value:function(){return this.status===t.InterpreterStatus.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=t.InterpreterStatus.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}},{key:"_process",value:function(t){try{var e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.name===nt&&this._stopProcedure()}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((function(e){var n;null===(n=e.error)||void 0===n||n.call(e,t)})),this.stop()}}},{key:"_stop",value:function(){return this.status===t.InterpreterStatus.Stopped?this:(this.mailbox.clear(),this.status===t.InterpreterStatus.NotStarted?(this.status=t.InterpreterStatus.Stopped,this):(this.mailbox.enqueue(B({type:nt})),this))}},{key:"stop",value:function(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}},{key:"_complete",value:function(){var t,e=w(this.observers);try{for(e.s();!(t=e.n()).done;){var n,r=t.value;null===(n=r.complete)||void 0===n||n.call(r)}}catch(t){e.e(t)}finally{e.f()}this.observers.clear()}},{key:"_stopProcedure",value:function(){if(this._complete(),this.status!==t.InterpreterStatus.Running)return this;for(var e=0,n=Object.keys(this.delayedEventsMap);e<n.length;e++){var r=n[e];this.clock.clearTimeout(this.delayedEventsMap[r])}return this.mailbox.clear(),this.mailbox=new tt(this._process.bind(this)),this.status=t.InterpreterStatus.Stopped,this.system._unregister(this),this}},{key:"send",value:function(e){var n=B(e);if(this.status!==t.InterpreterStatus.Stopped){if(this.status!==t.InterpreterStatus.Running&&!this.options.deferEvents)throw new Error('Event "'.concat(n.name,'" was sent to uninitialized actor "').concat(this.id,'". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ').concat(JSON.stringify(n.data)));this.mailbox.enqueue(n)}}},{key:"delaySend",value:function(t){var e=this;this.delayedEventsMap[t.params.id]=this.clock.setTimeout((function(){"to"in t.params&&t.params.to?t.params.to.send(t.params._event):e.send(t.params._event)}),t.params.delay)}},{key:"cancel",value:function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}},{key:"attachDevTools",value:function(){var t=this.options.devTools;t&&("function"==typeof t?t:ot)(this)}},{key:"toJSON",value:function(){return{id:this.id}}},{key:"getPersistedState",value:function(){var t,e;return null===(t=(e=this.behavior).getPersistedState)||void 0===t?void 0:t.call(e,this._state)}},{key:et,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),e}();function ut(t,e){return new st(t,e)}function ct(e){var n=e;return q({type:r,params:{actor:n}},(function(e,r){var i=r.state,o=R(n)?n({context:i.context,event:e.data}):n,a="string"==typeof o?i.children[o]:o;return[i,{type:"xstate.stop",params:{actor:a},execute:function(e){a&&(a.status===t.InterpreterStatus.Running?e.defer((function(){e.stopChild(a)})):e.stopChild(a))}}]}))}var lt=function(t){return{context:t.context,event:t.event}};function ft(t){return q({type:a,params:{sendId:t}},(function(e,n){var r,i=n.state,o=n.actorContext,a=R(t)?t({context:i.context,event:e.data,_event:e,self:null!==(r=null==o?void 0:o.self)&&void 0!==r?r:{},system:null==o?void 0:o.system}):t;return[i,{type:"xstate.cancel",params:{sendId:a},execute:function(t){t.self.cancel(a)}}]}))}function vt(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var ht=new WeakMap;function dt(t,e,n){var r=ht.get(t);return r?e in r||(r[e]=n()):(r=m({},e,n()),ht.set(t,r)),r[e]}function pt(t,e,n,r){var i,o,a,s=r.machine,u=null!==(i=null==s||null===(o=s.options)||void 0===o||null===(a=o.guards)||void 0===a?void 0:a[t.type])&&void 0!==i?i:t.predicate;if(!u)throw new Error("Guard '".concat(t.type,"' is not implemented.'."));return u({context:e,event:n.data,state:r,guard:t,_event:n,evaluate:pt})}function yt(t,e){var n;return J(t)?{type:t,predicate:(null==e?void 0:e(t))||void 0,params:{type:t}}:R(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:null===(n=t.children)||void 0===n?void 0:n.map((function(t){return yt(t,e)})),predicate:(null==e?void 0:e(t.type))||t.predicate}}var mt=function(t){return"atomic"===t.type||"final"===t.type};function gt(t){return Object.values(t.states).filter((function(t){return"history"!==t.type}))}function bt(t,e){for(var n=[],r=t.parent;r&&r!==e;)n.push(r),r=r.parent;return n}function _t(t){var e,n=new Set(t),r=new Set(t),i=St(r),o=w(n);try{for(o.s();!(e=o.n()).done;){var a=e.value;if("compound"!==a.type||i.get(a)&&i.get(a).length){if("parallel"===a.type){var s,u=w(gt(a));try{for(u.s();!(s=u.n()).done;){var c=s.value;if("history"!==c.type&&!r.has(c))for(var l=0,f=At(c);l<f.length;l++){var v=f[l];r.add(v)}}}catch(t){u.e(t)}finally{u.f()}}}else At(a).forEach((function(t){return r.add(t)}))}}catch(t){o.e(t)}finally{o.f()}var h,d=w(r);try{for(d.s();!(h=d.n()).done;)for(var p=h.value.parent;p;)r.add(p),p=p.parent}catch(t){d.e(t)}finally{d.f()}return r}function xt(t,e){var n=e.get(t);if(!n)return{};if("compound"===t.type){var r=n[0];if(!r)return{};if(mt(r))return r.key}var i,o={},a=w(n);try{for(a.s();!(i=a.n()).done;){var s=i.value;o[s.key]=xt(s,e)}}catch(t){a.e(t)}finally{a.f()}return o}function St(t){var e,n=new Map,r=w(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.has(i)||n.set(i,[]),i.parent&&(n.has(i.parent)||n.set(i.parent,[]),n.get(i.parent).push(i))}}catch(t){r.e(t)}finally{r.f()}return n}function kt(t,e){return xt(t,St(_t(e)))}function wt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t[0].machine.root;return"compound"===e.type?gt(e).some((function(e){return"final"===e.type&&t.includes(e)})):"parallel"===e.type&&gt(e).every((function(e){return wt(t,e)}))}var Et=function(t){return"#"===t[0]};function Tt(t,e){var n,r=z(e.target),i=null!==(n=e.external)&&void 0!==n&&n,o=t.machine.options.guards,a=It(t,r),s=b(b({},e),{},{actions:ce(N(e.actions)),guard:e.guard?yt(e.guard,(function(t){return o[t]})):void 0,target:a,source:t,external:i,eventType:e.event,toJSON:function(){return b(b({},s),{},{source:"#".concat(t.id),target:a?a.map((function(t){return"#".concat(t.id)})):void 0})}});return s}function It(t,e){if(void 0!==e)return e.map((function(e){if(!J(e))return e;if(Et(e))return t.machine.getStateNodeById(e);var n=e[0]===t.machine.delimiter;if(n&&!t.parent)return Pt(t,e.slice(1));var r=n?t.key+e:e;if(!t.parent)throw new Error('Invalid target: "'.concat(e,'" is not a valid target from the root node. Did you mean ".').concat(e,'"?'));try{return Pt(t.parent,r)}catch(e){throw new Error("Invalid transition definition for state node '".concat(t.id,"':\n").concat(e.message))}}))}function Ot(t){var e=z(t.target);return e?e.map((function(e){return"string"==typeof e?Pt(t.parent,e):e})):t.parent.initial.target}function jt(t){return"history"===t.type}function At(t){var e=new Set;return function n(r){if(!e.has(r))if(e.add(r),"compound"===r.type){var i,o=w(r.initial.target);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=w(bt(s,t));try{for(u.s();!(a=u.n()).done;){var c=a.value;e.add(c)}}catch(t){u.e(t)}finally{u.f()}n(s)}}catch(t){o.e(t)}finally{o.f()}}else if("parallel"===r.type){var l,f=w(gt(r));try{for(f.s();!(l=f.n()).done;){n(l.value)}}catch(t){f.e(t)}finally{f.f()}}}(t),k(e)}function Ct(t,e){if(Et(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(t.id,"'; no child states exist."));var n=t.states[e];if(!n)throw new Error("Child state '".concat(e,"' does not exist on '").concat(t.id,"'"));return n}function Pt(t,e){if("string"==typeof e&&Et(e))try{return t.machine.getStateNodeById(e)}catch(t){}for(var n=O(e,t.machine.delimiter).slice(),r=t;n.length;){var i=n.shift();if(!i.length)break;r=Ct(r,i)}return r}function Mt(t,e){var n=e instanceof ne?e.value:j(e,t.machine.delimiter);if(J(n))return[t,t.states[n]];var r=Object.keys(n),i=r.map((function(e){return Ct(t,e)})).filter(Boolean);return[t.machine.root,t].concat(i,r.reduce((function(e,r){var i=Ct(t,r);if(!i)return e;var o=Mt(i,n[r]);return e.concat(o)}),[]))}function Nt(t,e,n,r){return J(e)?function(t,e,n,r){var i=Ct(t,e).next(n,r);return i&&i.length?i:t.next(n,r)}(t,e,n,r):1===Object.keys(e).length?function(t,e,n,r){var i=Object.keys(e),o=Nt(Ct(t,i[0]),e[i[0]],n,r);return o&&o.length?o:t.next(n,r)}(t,e,n,r):function(t,e,n,r){for(var i=[],o=0,a=Object.keys(e);o<a.length;o++){var s=a[o],u=e[s];if(u){var c=Nt(Ct(t,s),u,n,r);c&&i.push.apply(i,k(c))}}return i.length?i:t.next(n,r)}(t,e,n,r)}function Dt(t,e){for(var n=t;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function Qt(t){for(var e=[],n=t.parent;n;)e.unshift(n),n=n.parent;return e}function Rt(t,e){var n,r=new Set(t),i=new Set(e),o=w(r);try{for(o.s();!(n=o.n()).done;){var a=n.value;if(i.has(a))return!0}}catch(t){o.e(t)}finally{o.f()}var s,u=w(i);try{for(u.s();!(s=u.n()).done;){var c=s.value;if(r.has(c))return!0}}catch(t){u.e(t)}finally{u.f()}return!1}function Jt(t,e,n){var r,i=new Set,o=w(t);try{for(o.s();!(r=o.n()).done;){var a,s=r.value,u=!1,c=new Set,l=w(i);try{for(l.s();!(a=l.n()).done;){var f=a.value;if(Rt($t([s],e,n),$t([f],e,n))){if(!Dt(s.source,f.source)){u=!0;break}c.add(f)}}}catch(t){l.e(t)}finally{l.f()}if(!u){var v,h=w(c);try{for(h.s();!(v=h.n()).done;){var d=v.value;i.delete(d)}}catch(t){h.e(t)}finally{h.f()}i.add(s)}}}catch(t){o.e(t)}finally{o.f()}return Array.from(i)}function Vt(t,e){if(!t.target)return[];var n,r=new Set,i=w(t.target);try{for(i.s();!(n=i.n()).done;){var o=n.value;if(jt(o))if(e[o.id]){var a,s=w(e[o.id]);try{for(s.s();!(a=s.n()).done;){var u=a.value;r.add(u)}}catch(t){s.e(t)}finally{s.f()}}else{var c,l=w(Vt({target:Ot(o)},e));try{for(l.s();!(c=l.n()).done;){var f=c.value;r.add(f)}}catch(t){l.e(t)}finally{l.f()}}else r.add(o)}}catch(t){i.e(t)}finally{i.f()}return k(r)}function Bt(t,e){var n=Vt(t,e);return n?!t.external&&"compound"===t.source.type&&n.every((function(e){return Dt(e,t.source)}))?t.source:function(t){var e,n=Qt(S(t,1)[0]),r=[],i=w(t);try{var o=function(){var t=Qt(e.value);r=n.filter((function(e){return t.includes(e)})),n=r,r=[]};for(i.s();!(e=i.n()).done;)o()}catch(t){i.e(t)}finally{i.f()}return n[n.length-1]}(n.concat(t.source)):null}function $t(t,e,n){var r,i=new Set,o=w(t);try{for(o.s();!(r=o.n()).done;){var a,s=r.value;if(null!==(a=s.target)&&void 0!==a&&a.length){var u,c=Bt(s,n),l=w(e);try{for(l.s();!(u=l.n()).done;){var f=u.value;Dt(f,c)&&i.add(f)}}catch(t){l.e(t)}finally{l.f()}}}}catch(t){o.e(t)}finally{o.f()}return k(i)}function zt(t,e,n,i){var o=e.machine,a=e._initial||t.length>0,s=new Set(e.configuration);if(!e._initial&&!a){var u=re(e,{_event:i,actions:[],transitions:[]});return u.changed=!1,u}var c=function(t,e,n,r,i){var o=e.machine,a=[],s=b({},e.historyValue),u=Jt(t,n,s),c=k(e._internalQueue);e._initial||function(t,e,n,r){var i=$t(t,e,n);i.sort((function(t,e){return e.order-t.order}));var o,a=w(i);try{var s=function(){var t,r,i=o.value,a=w((r=i,Object.keys(r.states).map((function(t){return r.states[t]})).filter((function(t){return"history"===t.type}))));try{for(a.s();!(t=a.n()).done;){var s=t.value,u=void 0;u="deep"===s.history?function(t){return mt(t)&&Dt(t,i)}:function(t){return t.parent===i},n[s.id]=Array.from(e).filter(u)}}catch(t){a.e(t)}finally{a.f()}};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}var u,c=w(i);try{for(c.s();!(u=c.n()).done;){var l=u.value;r.push.apply(r,k(l.exit.flat()).concat(k(l.invoke.map((function(t){return ct(t.id)}))))),e.delete(l)}}catch(t){c.e(t)}finally{c.f()}}(u,n,s,a);a.push.apply(a,k(u.flatMap((function(t){return t.actions})))),Ut(u,n,a,c,e,s);var l=k(n),f=wt(l);if(f){var v=l.sort((function(t,e){return e.order-t.order})).flatMap((function(t){return t.exit}));a.push.apply(a,k(v))}try{var h=Xt(a,r,e,i).nextState,d=f?function(t,e,n){var r=t[0].machine,i=t.find((function(t){return"final"===t.type&&t.parent===r.root}));return i&&i.output?D(i.output,e,n):void 0}(l,h.context,r):void 0;return c.push.apply(c,k(h._internalQueue)),re(e,{actions:h.actions,configuration:l,historyValue:s,_internalQueue:c,context:h.context,_event:r,done:f,output:d,children:h.children})}catch(t){if(o.config.scxml)return re(e,{actions:[],configuration:Array.from(n),historyValue:s,_internalQueue:[B({type:"error.execution"})],context:e.context});throw t}}(e._initial?[{target:k(e.configuration).filter(mt),source:o.root,external:!0,actions:[],eventType:null,toJSON:null}]:t,e,s,i,n),f=c.context,v=re(c,{value:{},transitions:t,children:function(t,e){var n,i=b({},t.children),o=w(e);try{for(o.s();!(n=o.n()).done;){var a=n.value;if(a.type===l&&a.params.ref){var s=a.params.ref;s&&(i[s.id]=s)}else if(a.type===r){var u=a.params.actor;u&&delete i[u.id]}}}catch(t){o.e(t)}finally{o.f()}return i}(e,c.actions)});return v.changed=e._initial?void 0:!Zt(v.value,e.value)||v.actions.length>0||f!==e.context,v}function Ut(t,e,n,r,i,o){var a=new Set,s=new Set;Wt(t,o,s,a),i._initial&&s.add(i.machine.root);var u,c=w(k(a).sort((function(t,e){return t.order-e.order})));try{for(c.s();!(u=c.n()).done;){var l=u.value;e.add(l);var f,v=w(l.invoke);try{for(v.s();!(f=v.n()).done;){var h=f.value;n.push(ie(h))}}catch(t){v.e(t)}finally{v.f()}if(n.push.apply(n,k(l.entry)),s.has(l)){var d,p=w(s);try{for(p.s();!(d=p.n()).done;){var y=d.value.initial.actions;n.push.apply(n,k(y))}}catch(t){p.e(t)}finally{p.f()}}if("final"===l.type){var m=l.parent;if(!m.parent)continue;if(r.push(B(fe(m.id,l.output?D(l.output,i.context,i._event):void 0))),m.parent){var g=m.parent;"parallel"===g.type&&gt(g).every((function(t){return wt(k(e),t)}))&&r.push(B(fe(g.id)))}}}}catch(t){c.e(t)}finally{c.f()}}function Wt(t,e,n,r){var i,o=w(t);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=w(s.target||[]);try{for(u.s();!(a=u.n()).done;){qt(a.value,e,n,r)}}catch(t){u.e(t)}finally{u.f()}var c,l=Bt(s,e),f=w(Vt(s,e));try{for(f.s();!(c=f.n()).done;){Lt(c.value,l,r,e,n)}}catch(t){f.e(t)}finally{f.f()}}}catch(t){o.e(t)}finally{o.f()}}function qt(t,e,n,r){if(jt(t))if(e[t.id]){var i,o=e[t.id],a=w(o);try{for(a.s();!(i=a.n()).done;){qt(i.value,e,n,r)}}catch(t){a.e(t)}finally{a.f()}var s,u=w(o);try{for(u.s();!(s=u.n()).done;){Lt(s.value,t.parent,r,e,n);var c,l=w(n);try{for(l.s();!(c=l.n()).done;){var f=c.value;n.add(f)}}catch(t){l.e(t)}finally{l.f()}}}catch(t){u.e(t)}finally{u.f()}}else{var v,h=Ot(t),d=w(h);try{for(d.s();!(v=d.n()).done;){qt(v.value,e,n,r)}}catch(t){d.e(t)}finally{d.f()}var p,y=w(h);try{for(y.s();!(p=y.n()).done;){Lt(p.value,t,r,e,n);var m,g=w(n);try{for(g.s();!(m=g.n()).done;){var b=m.value;n.add(b)}}catch(t){g.e(t)}finally{g.f()}}}catch(t){y.e(t)}finally{y.f()}}else if(r.add(t),"compound"===t.type){n.add(t);var _,x=t.initial.target,S=w(x);try{for(S.s();!(_=S.n()).done;){qt(_.value,e,n,r)}}catch(t){S.e(t)}finally{S.f()}var E,T=w(x);try{for(T.s();!(E=T.n()).done;){Lt(E.value,t,r,e,n)}}catch(t){T.e(t)}finally{T.f()}}else if("parallel"===t.type){var I,O=w(gt(t).filter((function(t){return!jt(t)})));try{var j=function(){var t=I.value;k(r).some((function(e){return Dt(e,t)}))||qt(t,e,n,r)};for(O.s();!(I=O.n()).done;)j()}catch(t){O.e(t)}finally{O.f()}}}function Lt(t,e,n,r,i){var o,a=w(bt(t,e));try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.add(s),"parallel"===s.type){var u,c=w(gt(s).filter((function(t){return!jt(t)})));try{var l=function(){var t=u.value;k(n).some((function(e){return Dt(e,t)}))||qt(t,r,i,n)};for(c.s();!(u=c.n()).done;)l()}catch(t){c.e(t)}finally{c.f()}}}}catch(t){a.e(t)}finally{a.f()}}function Xt(e,n,r,a){var s=r.machine,u=[],c=[],l=r;function f(e){var n;(u.push(e),(null==a?void 0:a.self.status)===t.InterpreterStatus.Running)&&(null===(n=e.execute)||void 0===n||n.call(e,a),delete e.execute)}function v(t){var e=function(t,e){if(L(t))return t;var n,r=e[t.type];return"function"==typeof r?q({type:"xstate.function",params:null!==(n=t.params)&&void 0!==n?n:{}},(function(e,n){var i=n.state,o={type:t.type,params:t.params,execute:function(t){return r({context:i.context,event:i.event,action:o,_event:i._event,system:t.system,self:t.self})}};return[i,o]})):r||t}(t,s.options.actions);if(L(e)){var r,u=S(e.resolve(n,{state:l,action:t,actorContext:a}),2),h=u[0],d=u[1],y=null===(r=d.params)||void 0===r?void 0:r.actions;return l=h,(d.type===i||d.type===o&&d.params.internal)&&"number"!=typeof d.params.delay&&c.push(d),d.type!==p&&f(d),void ce(y).forEach(v)}f(e)}var h,d=w(e);try{for(d.s();!(h=d.n()).done;){v(h.value)}}catch(t){d.e(t)}finally{d.f()}return{nextState:re(l,{actions:u,_internalQueue:c.map((function(t){return t.params._event}))})}}function Gt(t,e,n){var r=t,i=[];if((null==e?void 0:e.name)===nt)return r=Ft(e,r,n),i.push(r),{state:r,microstates:i};e.name!==c&&(r=zt(Ht(e,r),t,n,e),i.push(r));for(;!r.done;){var o=Kt(r);if(0===o.length){if(r.configuration.some((function(t){return t.always}))&&(r.transitions=[]),!r._internalQueue.length)break;var a,s=r.actions,u=r._internalQueue[0];(r=zt(Ht(u,r),r,n,u))._internalQueue.shift(),(a=r.actions).unshift.apply(a,k(s)),i.push(r)}if(o.length){var l,f=r.actions;(l=(r=zt(o,r,n,r._event)).actions).unshift.apply(l,k(f)),i.push(r)}}return r.done&&Ft(r._event,r,n),{state:r,microstates:i}}function Ft(t,e,n){var r,i=[],o=w(e.configuration.sort((function(t,e){return e.order-t.order})));try{for(o.s();!(r=o.n()).done;){var a=r.value;i.push.apply(i,k(a.exit))}}catch(t){o.e(t)}finally{o.f()}for(var s=0,u=Object.values(e.children);s<u.length;s++){var c=u[s];i.push(ct(c))}return Xt(i,t,e,n).nextState}function Ht(t,e){return e.machine.getTransitionData(e,t)}function Kt(t){var e,n=new Set,r=w(t.configuration.filter(mt));try{for(r.s();!(e=r.n()).done;){var i,o=e.value,a=w([o].concat(bt(o,null)));try{t:for(a.s();!(i=a.n()).done;){var s=i.value;if(s.always){var u,c=w(s.always);try{for(c.s();!(u=c.n()).done;){var l=u.value;if(void 0===l.guard||pt(l.guard,t.context,t._event,t)){n.add(l);break t}}}catch(t){c.e(t)}finally{c.f()}}}}catch(t){a.e(t)}finally{a.f()}}}catch(t){r.e(t)}finally{r.f()}return Jt(Array.from(n),new Set(t.configuration),t.historyValue)}function Yt(t,e){return kt(t,k(_t(Mt(t,e))))}function Zt(t,e){if(t===e)return!0;if(void 0===t||void 0===e)return!1;if(J(t)||J(e))return t===e;var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every((function(n){return Zt(t[n],e[n])}))}var te=["configuration","transitions","tags","machine"],ee=["configuration","transitions","tags","machine","children"],ne=function(){function t(e,n){var r,i,o,a;K(this,t),this.machine=n,m(this,"tags",void 0),m(this,"value",void 0),m(this,"done",void 0),m(this,"output",void 0),m(this,"context",void 0),m(this,"historyValue",{}),m(this,"actions",[]),m(this,"event",void 0),m(this,"_internalQueue",void 0),m(this,"_event",void 0),m(this,"_initial",!1),m(this,"changed",void 0),m(this,"configuration",void 0),m(this,"transitions",void 0),m(this,"children",void 0),this.context=e.context,this._event=e._event,this._internalQueue=null!==(r=e._internalQueue)&&void 0!==r?r:[],this.event=this._event.data,this.historyValue=e.historyValue||{},this.actions=null!==(i=e.actions)&&void 0!==i?i:[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=null!==(o=e.configuration)&&void 0!==o?o:Array.from(_t(Mt(n.root,e.value))),this.transitions=e.transitions,this.children=e.children,this.value=kt(n.root,this.configuration),this.tags=new Set(P(this.configuration.map((function(t){return t.tags})))),this.done=null!==(a=e.done)&&void 0!==a&&a,this.output=e.output}return Z(t,[{key:"toStrings",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.value,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";if(J(e))return[e];var r=Object.keys(e);return r.concat.apply(r,k(r.map((function(r){return t.toStrings(e[r],n).map((function(t){return r+n+t}))}))))}},{key:"toJSON",value:function(){this.configuration,this.transitions;var t=this.tags;this.machine;return b(b({},vt(this,te)),{},{tags:Array.from(t),meta:this.meta})}},{key:"matches",value:function(t){return I(t,this.value)}},{key:"hasTag",value:function(t){return this.tags.has(t)}},{key:"can",value:function(t){this.machine;var e=this.machine.getTransitionData(this,B(t));return!(null==e||!e.length)&&e.some((function(t){return void 0!==t.target||t.actions.length}))}},{key:"nextEvents",get:function(){var t=this;return dt(this,"nextEvents",(function(){return k(new Set(P(k(t.configuration.map((function(t){return t.ownEvents}))))))}))}},{key:"meta",get:function(){return this.configuration.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})}}],[{key:"from",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;if(e instanceof t)return e.context!==n?new t({value:e.value,context:n,_event:e._event,actions:[],meta:{},configuration:[],transitions:[],children:{}},r):e;var i=de({}),o=_t(Mt(r.root,e));return new t({value:e,context:n,_event:i,actions:[],meta:void 0,configuration:Array.from(o),transitions:[],children:{}},r)}}]),t}();function re(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new ne(b(b({},t),e),t.machine)}function ie(e){return q({type:l,params:e},(function(n,r){var i,o,a=r.state,s=r.actorContext,u=l,c=e.id,f=e.src;if((o=f)&&"object"===E(o)&&"function"==typeof o.send)i={type:u,params:b(b({},e),{},{ref:f})};else{var v=W(a.machine.options.actors[f]);if(v){var h="input"in e?e.input:v.input,d=ut(v.src,{id:c,src:f,parent:null==s?void 0:s.self,systemId:e.systemId,input:"function"==typeof h?h({context:a.context,event:n.data,self:null==s?void 0:s.self}):h});i={type:u,params:b(b({},e),{},{ref:d})}}else i={type:u,params:e}}var p=i.params.ref,y=re(a,{children:b(b({},a.children),{},m({},c,p))});return i.execute=function(e){var n=e.self,r=i.params,o=r.id;r.ref&&e.defer((function(){if(p.status!==t.InterpreterStatus.Stopped)try{var e;null===(e=p.start)||void 0===e||e.call(p)}catch(t){return void n.send(he(o,t))}}))},[y,i]}))}function oe(t,e,n,r,i){return function(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(J(o)){var s=W(e.options.actors[o]);if(s){var u,c=null!==(u=a.id)&&void 0!==u?u:"anon",l="input"in a?a.input:s.input,f=ut(s.src,{id:c,parent:t,input:"function"==typeof l?l({context:n,event:r.data,self:t}):l});return i.push(ie({id:f.id,src:f,ref:f,meta:void 0,input:l})),f}throw new Error("Behavior '".concat(o,"' not implemented in machine '").concat(e.id,"'"))}var v=ut(o,{id:a.id||"anonymous",parent:t,input:a.input});return i.push(ie({src:v,ref:v,id:v.id,meta:void 0,input:a.input})),v}}function ae(t){return q({type:s,params:{assignment:t}},(function(e,n){var r,i=n.state,o=n.action,a=n.actorContext,u=[];if(!i.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");var c={context:i.context,event:e.data,action:o,_event:e,spawn:oe(null==a?void 0:a.self,i.machine,i.context,e,u),self:null!==(r=null==a?void 0:a.self)&&void 0!==r?r:{},system:null==a?void 0:a.system},l={};if(R(t))l=t(c);else for(var f=0,v=Object.keys(t);f<v.length;f++){var h=v[f],d=t[h];l[h]=R(d)?d(c):d}var p=Object.assign({},i.context,l);return[re(i,{context:p}),{type:s,params:{context:p,actions:u}}]}))}var se=B({type:c});function ue(t){if(L(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){var e="xstate.function";return q({type:e,params:{}},(function(n,r){var i=r.state,o={type:e,params:{function:t},execute:function(e){return t({context:i.context,event:n.data,action:o,_event:n,self:e.self,system:e.system})}};return[i,o]}))}return t}var ce=function(t){return t?(Q(t)?t:[t]).map(ue):[]};function le(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function fe(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function ve(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function he(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function de(t){return B({type:c,input:t})}var pe=["onDone","onError"],ye={},me=function(){function t(e,n){var r=this;if(K(this,t),this.config=e,m(this,"key",void 0),m(this,"id",void 0),m(this,"type",void 0),m(this,"path",void 0),m(this,"states",void 0),m(this,"history",void 0),m(this,"entry",void 0),m(this,"exit",void 0),m(this,"parent",void 0),m(this,"machine",void 0),m(this,"meta",void 0),m(this,"output",void 0),m(this,"order",-1),m(this,"description",void 0),m(this,"tags",[]),m(this,"transitions",void 0),m(this,"always",void 0),this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id].concat(k(this.path)).join(this.machine.delimiter),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?C(this.config.states,(function(e,n){return new t(e,{_parent:r,_key:n,_machine:r.machine})})):ye,"compound"===this.type&&!this.config.initial)throw new Error('No initial state specified for compound state node "#'.concat(this.id,'". Try adding { initial: "').concat(Object.keys(this.states)[0],'" } to the state config.'));this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=ce(this.config.entry),this.exit=ce(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=N(e.tags)}return Z(t,[{key:"_initialize",value:function(){var t=this;this.transitions=function(t){var e=[];if(Array.isArray(t.config.on))e.push.apply(e,k(t.config.on));else if(t.config.on){for(var n=t.config.on,r=n[T],i=void 0===r?[]:r,o=vt(n,[T].map(y)),a=0,s=Object.keys(o);a<s.length;a++){var u=s[a];if(""===u)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');var c=$(u,o[u]);e.push.apply(e,k(c))}e.push.apply(e,k($(T,i)))}var l,f=t.config.onDone?$(String(fe(t.id)),t.config.onDone):[],v=t.invoke.flatMap((function(t){var e=[];return t.onDone&&e.push.apply(e,k($("done.invoke.".concat(t.id),t.onDone))),t.onError&&e.push.apply(e,k($("error.platform.".concat(t.id),t.onError))),t.onSnapshot&&e.push.apply(e,k($("xstate.snapshot.".concat(t.id),t.onSnapshot))),e})),h=t.after,d=[].concat(k(f),k(v),e).flatMap((function(e){return N(e).map((function(e){return Tt(t,e)}))})),p=w(h);try{for(p.s();!(l=p.n()).done;){var m=l.value;d.push(m)}}catch(t){p.e(t)}finally{p.f()}return d}(this),this.config.always&&(this.always=$("",this.config.always).map((function(e){return Tt(t,e)}))),Object.keys(this.states).forEach((function(e){t.states[e]._initialize()}))}},{key:"definition",get:function(){var t=this;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,eventType:null,external:!1,toJSON:function(){return{target:t.initial.target.map((function(t){return"#".concat(t.id)})),source:"#".concat(t.id),actions:t.initial.actions,eventType:null}}}:void 0,history:this.history,states:C(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.entry,exit:this.exit,meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}},{key:"toJSON",value:function(){return this.definition}},{key:"invoke",get:function(){var t=this;return dt(this,"invoke",(function(){return N(t.config.invoke).map((function(e,n){var r,i,o=(r=t.id,i=n,"".concat(r,":invocation[").concat(i,"]")),a=function(t,e){if("object"===E(t)){if("src"in t)return t;if("transition"in t)return{id:e,src:t}}return{id:e,src:t}}(e,o),s=a.id||o,u=a.src,c=a.systemId,f=J(u)||"type"in u?u:s;return t.machine.options.actors[s]||"string"==typeof u||"type"in u||(t.machine.options.actors=b(b({},t.machine.options.actors),{},m({},s,u))),b(b({type:l},a),{},{src:f,id:s,systemId:c,toJSON:function(){a.onDone,a.onError;return b(b({},vt(a,pe)),{},{type:l,src:f,id:s})}})}))}))}},{key:"on",get:function(){var t=this;return dt(this,"on",(function(){return t.transitions.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})}))}},{key:"after",get:function(){var t=this;return dt(this,"delayedTransitions",(function(){return function(t){var e=t.config.after;if(!e)return[];var n=function(e,n){var r=le(R(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.entry.push(X({type:r},{delay:e})),t.exit.push(ft(r)),r};return(Q(e)?e.map((function(t,e){var r=n(t.delay,e);return b(b({},t),{},{event:r})})):Object.keys(e).flatMap((function(t,r){var i=e[t],o=J(i)?{target:i}:i,a=isNaN(+t)?t:+t,s=n(a,r);return N(o).map((function(t){return b(b({},t),{},{event:s,delay:a})}))}))).map((function(e){var n=e.delay;return b(b({},Tt(t,e)),{},{delay:n})}))}(t)}))}},{key:"initial",get:function(){var t=this;return dt(this,"initial",(function(){return function(t,e){if(J(e)||Q(e)){var n=N(e).map((function(e){var n=J(e)?Et(e)?t.machine.getStateNodeById(e):t.states[e]:e;if(!n)throw new Error('Initial state node "'.concat(e,'" not found on parent state node #').concat(t.id));if(!Dt(n,t))throw new Error("Invalid initial target: state node #".concat(n.id," is not a descendant of #").concat(t.id));return n})),r=It(t,n),i={source:t,actions:[],eventType:null,external:!1,target:r,toJSON:function(){return b(b({},i),{},{source:"#".concat(t.id),target:r?r.map((function(t){return"#".concat(t.id)})):void 0})}};return i}return Tt(t,{target:N(e.target).map((function(e){return J(e)?Et(e)?e:"".concat(t.machine.delimiter).concat(e):e})),actions:e.actions,event:null})}(t,t.config.initial||[])}))}},{key:"handles",value:function(t){return this.events.includes(t.type)}},{key:"next",value:function(t,e){var n,r,i=this,o=e.name,a=[],s=w(dt(this,"candidates-".concat(o.toString()),(function(){return function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.transitions.filter((function(t){var r=t.eventType;if(r===e)return!0;if(r===T)return!0;if(!n&&!r.endsWith(".*"))return!1;for(var i=r.split("."),o=e.split("."),a=0;a<i.length;a++){var s=i[a],u=o[a];if("*"===s)return a===i.length-1;if(s!==u)return!1}return!0}))}(i,o,i.machine.config.scxml)})));try{for(s.s();!(r=s.n()).done;){var u=r.value,c=u.guard,l=t.context,f=!1;try{f=!c||pt(c,l,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(c.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(f){a.push.apply(a,k(u.actions)),n=u;break}}}catch(t){s.e(t)}finally{s.f()}return n?[n]:void 0}},{key:"target",get:function(){if("history"===this.type)return this.config.target}},{key:"stateIds",get:function(){var t=this,e=P(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)}},{key:"events",get:function(){var t=this;return dt(this,"events",(function(){var e=t.states,n=new Set(t.ownEvents);if(e)for(var r=0,i=Object.keys(e);r<i.length;r++){var o=e[i[r]];if(o.states){var a,s=w(o.events);try{for(s.s();!(a=s.n()).done;){var u=a.value;n.add("".concat(u))}}catch(t){s.e(t)}finally{s.f()}}}return Array.from(n)}))}},{key:"ownEvents",get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&!t.external)})).map((function(t){return t.eventType})));return Array.from(t)}}]),t}();var ge=function(){function t(e,n){var r;K(this,t),this.config=e,m(this,"version",void 0),m(this,"delimiter",void 0),m(this,"options",void 0),m(this,"schema",void 0),m(this,"__xstatenode",!0),m(this,"idMap",new Map),m(this,"root",void 0),m(this,"id",void 0),m(this,"states",void 0),m(this,"events",void 0),m(this,"__TContext",void 0),m(this,"__TEvent",void 0),m(this,"__TAction",void 0),m(this,"__TActorMap",void 0),m(this,"__TResolvedTypesMeta",void 0),this.id=e.id||"(machine)",this.options=Object.assign({actions:{},actors:{},delays:{},guards:{},context:{}},n),this.delimiter=this.config.delimiter||".",this.version=this.config.version,this.schema=null!==(r=this.config.schema)&&void 0!==r?r:{},this.transition=this.transition.bind(this),this.root=new me(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}return Z(t,[{key:"getContext",value:function(t){return this.getContextAndActions(void 0,t)[0]}},{key:"getContextAndActions",value:function(t,e){var n=[],r=this.config.context;return[("function"==typeof r?r({spawn:oe(null==t?void 0:t.self,this,void 0,de(e),n),input:e}):r)||{},n]}},{key:"provide",value:function(e){var n=this.options,r=n.actions,i=n.guards,o=n.actors,a=n.delays;return new t(this.config,{actions:b(b({},r),e.actions),guards:b(b({},i),e.guards),actors:b(b({},o),e.actors),delays:b(b({},a),e.delays)})}},{key:"resolveState",value:function(t){var e=_t(Mt(this.root,t.value)),n=Array.from(e);return this.createState(b(b({},t),{},{value:Yt(this.root,t.value),configuration:n,done:wt(n)}))}},{key:"resolveStateValue",value:function(t){var e=Yt(this.root,t),n=this.getContext();return this.resolveState(ne.from(e,n,this))}},{key:"transition",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=t instanceof ne?t:this.resolveStateValue(t),i=B(e);if(V(i)&&!r.nextEvents.some((function(t){return t===i.name})))throw i.data.data;var o=Gt(r,i,n),a=o.state;return a}},{key:"microstep",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=B(e),i=Gt(t,r,n),o=i.microstates;return o}},{key:"getTransitionData",value:function(t,e){return Nt(this.root,t.value,t,e)||[]}},{key:"getPreInitialState",value:function(t,e){var n,r=S(this.getContextAndActions(t,e),2),i=r[0],o=r[1],a=function(t){var e=[],n=t.initial,r=new Set;Wt([n],{},new Set([t]),r);var i,o=w(k(r).sort((function(t,e){return t.order-e.order})));try{for(o.s();!(i=o.n()).done;){var a=i.value;e.push(a)}}catch(t){o.e(t)}finally{o.f()}return e}(this.root),s=this.resolveState(this.createState({value:{},context:i,_event:de({}),actions:[],meta:void 0,configuration:a,transitions:[],children:{}}));if(s._initial=!0,(n=s.actions).unshift.apply(n,k(o)),t){var u=Xt(o,se,s,t).nextState;s.children=u.children,s.actions=u.actions}return s}},{key:"initialState",get:function(){return this.getInitialState()}},{key:"getInitialState",value:function(t,e){var n,r=de(e),i=this.getPreInitialState(t,e),o=zt([],i,t,r);return(n=o.actions).unshift.apply(n,k(i.actions)),Gt(o,r,t).state}},{key:"start",value:function(t,e){t.actions.forEach((function(t){var n;null===(n=t.execute)||void 0===n||n.call(t,e)})),Object.values(t.children).forEach((function(t){if(0===t.status)try{var n;null===(n=t.start)||void 0===n||n.call(t)}catch(n){e.self.send(he(t.id,n))}}))}},{key:"getStateNodeById",value:function(t){var e=t.split(this.delimiter),n=e.slice(1),r=Et(e[0])?e[0].slice("#".length):e[0],i=this.idMap.get(r);if(!i)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return Pt(i,n)}},{key:"definition",get:function(){return b({context:this.getContext()},this.root.definition)}},{key:"toJSON",value:function(){return this.definition}},{key:"getPersistedState",value:function(t){return function(t){t.configuration,t.transitions,t.tags,t.machine;var e=t.children,n=vt(t,ee),r={};for(var i in e){var o,a;r[i]={state:null===(o=(a=e[i]).getPersistedState)||void 0===o?void 0:o.call(a),src:e[i].src}}return b(b({},n),{},{children:r})}(t)}},{key:"createState",value:function(t){var e=t instanceof ne?t:new ne(t,this);return Xt(e.actions,e._event,e,void 0).nextState}},{key:"getStatus",value:function(t){return t.done?{status:"done",data:t.output}:{status:"active"}}},{key:"restoreState",value:function(t,e){var n=this,r={};Object.keys(t.children).forEach((function(i){var o,a,s=t.children[i],u=s.state,c=s.src,l=c?null===(o=W(n.options.actors[c]))||void 0===o?void 0:o.src:void 0;if(l){var f=ut(l,{id:i,state:null===(a=l.restoreState)||void 0===a?void 0:a.call(l,u,e)});r[i]=f}}));var i=this.createState(new ne(b(b({},t),{},{children:r}),this));return i.configuration.forEach((function(t){t.invoke&&t.invoke.forEach((function(t){var i=t.id,o=t.src;if(!r[i]){var a=W(n.options.actors[o]);if(a){var s=ut(a.src,{id:i,parent:null==e?void 0:e.self,input:"input"in t?t.input:a.input});r[i]=s}}}))})),i.actions=[],i}}]),t}();function be(t){return t}var _e=be,xe=function(){function t(){K(this,t),m(this,"timeouts",new Map),m(this,"_now",0),m(this,"_id",0)}return Z(t,[{key:"now",value:function(){return this._now}},{key:"getId",value:function(){return this._id++}},{key:"setTimeout",value:function(t,e){var n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}},{key:"clearTimeout",value:function(t){this.timeouts.delete(t)}},{key:"set",value:function(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}},{key:"flushTimeouts",value:function(){var t=this;k(this.timeouts).sort((function(t,e){var n=S(t,2),r=(n[0],n[1]),i=S(e,2),o=(i[0],i[1]),a=r.start+r.timeout;return o.start+o.timeout>a?-1:1})).forEach((function(e){var n=S(e,2),r=n[0],i=n[1];t.now()-i.start>=i.timeout&&(t.timeouts.delete(r),i.fn.call(null))}))}},{key:"increment",value:function(t){this._now+=t,this.flushTimeouts()}}]),t}(),Se={raise:function(t,e){return q({type:i,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},(function(n,r){var o,a,s=r.state,u=r.actorContext,c={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},l={context:s.context,event:n.data,_event:n,self:null!==(o=null==u?void 0:u.self)&&void 0!==o?o:{},system:null==u?void 0:u.system},f=s.machine.options.delays,v=B("function"==typeof t?t(l):t);if("string"==typeof c.delay){var h=f&&f[c.delay];a="function"==typeof h?h(l):h}else a="function"==typeof c.delay?c.delay(l):c.delay;var d={type:i,params:b(b({},c),{},{_event:v,event:v.data,delay:a}),execute:function(t){"number"!=typeof d.params.delay||t.self.delaySend(d)}};return[s,d]}))},send:X,sendParent:G,sendTo:H,log:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:lt,e=arguments.length>1?arguments[1]:void 0;return q({type:u,params:{label:e,expr:t}},(function(n,r){var i,o=r.state,a=r.actorContext,s="function"==typeof t?t({context:o.context,event:n.data,_event:n,self:null!==(i=null==a?void 0:a.self)&&void 0!==i?i:{},system:null==a?void 0:a.system}):t;return[o,{type:"xstate.log",params:{label:e,value:s},execute:function(t){var n,r;e?null===(n=t.logger)||void 0===n||n.call(t,e,s):null===(r=t.logger)||void 0===r||r.call(t,s)}}]}))},cancel:ft,stop:ct,assign:ae,after:le,done:fe,respond:function(t,e){return X(t,b(b({},e),{},{to:function(t){return t._event.origin}}))},forwardTo:F,escalate:function(e,n){return G((function(t){return{type:h,data:R(e)?e(t):e}}),b(b({},n),{},{to:t.SpecialTargets.Parent}))},choose:function(t){return q({type:d,params:{guards:t}},(function(e,n){var r,i=n.state,o=null===(r=t.find((function(t){var n=t.guard&&yt(t.guard,(function(t){return i.machine.options.guards[t]}));return!n||pt(n,i.context,e,i)})))||void 0===r?void 0:r.actions;return[i,{type:d,params:{actions:ce(o)}}]}))},pure:function(t){return q({type:p,params:{get:t}},(function(e,n){var r,i=n.state;return[i,{type:p,params:{actions:null!==(r=N(ce(t({context:i.context,event:e.data}))))&&void 0!==r?r:[]}}]}))}};t.Interpreter=st,t.SimulatedClock=xe,t.State=ne,t.StateMachine=ge,t.StateNode=me,t.actions=Se,t.assign=ae,t.createMachine=function(t,e){return new ge(t,e)},t.createSchema=be,t.doneInvoke=ve,t.forwardTo=F,t.getStateNodes=Mt,t.interpret=ut,t.mapState=function(t,e){for(var n,r=0,i=Object.keys(t);r<i.length;r++){var o=i[r];I(o,e)&&(!n||e.length>n.length)&&(n=o)}return t[n]},t.matchesState=I,t.pathToStateValue=A,t.send=X,t.sendParent=G,t.sendTo=H,t.t=_e,t.toObserver=U,t.toSCXMLEvent=B,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";var e,n;t.ActionTypes=void 0,(e=t.ActionTypes||(t.ActionTypes={})).Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Pure="xstate.pure",e.Choose="xstate.choose",t.SpecialTargets=void 0,(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var r=t.ActionTypes.Stop,i=t.ActionTypes.Raise,o=t.ActionTypes.Send,a=t.ActionTypes.Cancel,s=t.ActionTypes.Assign;t.ActionTypes.After,t.ActionTypes.DoneState;var u=t.ActionTypes.Log,c=t.ActionTypes.Init,l=t.ActionTypes.Invoke,f=t.ActionTypes.ErrorExecution,d=t.ActionTypes.ErrorPlatform,v=t.ActionTypes.ErrorCustom,h=t.ActionTypes.Choose,p=t.ActionTypes.Pure;function y(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function m(t,e,n){return(e=y(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function g(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){m(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function S(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function x(t,e){if(t){if("string"==typeof t)return S(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?S(t,e):void 0}}function w(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,s=[],u=!0,c=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);u=!0);}catch(t){c=!0,i=t}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return s}}(t,e)||x(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _(t){return function(t){if(Array.isArray(t))return S(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||x(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=x(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function T(t){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},T(t)}var E=".",I="",O="",j="*";function A(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:E,r=C(t,n),i=C(e,n);return z(i)?!!z(r)&&i===r:z(r)?r in i:Object.keys(r).every((function(t){return t in i&&A(r[t],i[t])}))}function P(t,e){try{return V(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function C(t,e){return"object"===T(n=t)&&"value"in n&&"context"in n&&"event"in n?t.value:V(t)?M(t):"string"!=typeof t?t:M(P(t,e));var n}function M(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function N(t,e){for(var n={},r=Object.keys(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function D(t){var e;return(e=[]).concat.apply(e,_(t))}function $(t){return V(t)?t:[t]}function R(t){return void 0===t?[]:$(t)}function J(t,e,n){if(B(t))return t({context:e,event:n});for(var r={},i={context:e,event:n},o=0,a=Object.keys(t);o<a.length;o++){var s=a[o],u=t[s];B(u)?r[s]=u(i):r[s]=u}return r}var Q=function(){};function V(t){return Array.isArray(t)}function B(t){return"function"==typeof t}function z(t){return"string"==typeof t}function U(t,e){return $(e).map((function(e){return void 0===e||"string"==typeof e?{target:e,event:t}:b(b({},e),{},{event:t})}))}function W(t){if(void 0!==t&&t!==I)return R(t)}function q(t,e,n){var r=function(){},i="object"===T(t),o=i?t:null;return{next:((i?t.next:t)||r).bind(o),error:((i?t.error:e)||r).bind(o),complete:((i?t.complete:n)||r).bind(o)}}function L(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function F(t,e){return{type:t.type,params:t.params,resolve:e}}function G(t){return"object"===T(t)&&null!==t&&"resolve"in t}function X(e,n){return F({type:o,params:{to:n?n.to:void 0,delay:n?n.delay:void 0,event:e,id:n&&void 0!==n.id?n.id:B(e)?e.name:e.type}},(function(r,i){var a,s=i.actorContext,u=i.state,c={to:n?n.to:void 0,delay:n?n.delay:void 0,event:e,id:n&&void 0!==n.id?n.id:B(e)?e.name:e.type},l={context:u.context,event:r,self:null!==(a=null==s?void 0:s.self)&&void 0!==a?a:null,system:null==s?void 0:s.system},f=u.machine.options.delays;if("string"==typeof e)throw new Error('Only event objects may be used with sendTo; use sendTo({ type: "'.concat(e,'" }) instead'));var d,h=B(e)?e(l):e;if(z(c.delay)){var p=f&&f[c.delay];d=B(p)?p(l):p}else d=B(c.delay)?c.delay(l):c.delay;var y,m=B(c.to)?c.to(l):c.to;if("string"==typeof m){if(!(y=m===t.SpecialTargets.Parent?null==s?void 0:s.self._parent:m===t.SpecialTargets.Internal?null==s?void 0:s.self:m.startsWith("#_")?u.children[m.slice(2)]:u.children[m]))throw new Error("Unable to send event to actor '".concat(m,"' from machine '").concat(u.machine.id,"'."))}else y=m||(null==s?void 0:s.self);var g={type:o,params:b(b({},c),{},{to:y,event:h,delay:d,internal:m===t.SpecialTargets.Internal}),execute:function(t){var e=g;if("number"!=typeof e.params.delay){var n=e.params.to,r=e.params.event;t.defer((function(){n.send(r.type===v?{type:"".concat(he(t.self.id)),data:r.data}:e.params.event)}))}else t.self.delaySend(e)}};return[u,g]}))}function H(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function K(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,y(r.key),r)}}function Y(t,e,n){return e&&K(t.prototype,e),n&&K(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var Z=function(){function t(e){H(this,t),this._process=e,m(this,"_active",!1),m(this,"_current",null),m(this,"_last",null)}return Y(t,[{key:"start",value:function(){this._active=!0,this.flush()}},{key:"clear",value:function(){this._current&&(this._current.next=null,this._last=this._current)}},{key:"prepend",value:function(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}},{key:"enqueue",value:function(t){var 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()}},{key:"flush",value:function(){for(;this._current;){var t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}]),t}(),tt="function"==typeof Symbol&&Symbol.observable||"@@observable";var et="xstate.init",nt="xstate.stop";function rt(t){return t===et||t===nt}function it(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var ot,at=function(t){var e=it();e&&e.register(t)};t.InterpreterStatus=void 0,(ot=t.InterpreterStatus||(t.InterpreterStatus={}))[ot.NotStarted=0]="NotStarted",ot[ot.Running=1]="Running",ot[ot.Stopped=2]="Stopped";var st={deferEvents:!0,clock:{setTimeout:function(t){function e(e,n){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t,e){return setTimeout(t,e)})),clearTimeout:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return clearTimeout(t)}))},logger:console.log.bind(console),devTools:!1},ut=function(){function e(n,r){var i,o=this;H(this,e),this.behavior=n,m(this,"_state",void 0),m(this,"clock",void 0),m(this,"options",void 0),m(this,"id",void 0),m(this,"mailbox",new Z(this._process.bind(this))),m(this,"delayedEventsMap",{}),m(this,"observers",new Set),m(this,"logger",void 0),m(this,"status",t.InterpreterStatus.NotStarted),m(this,"_parent",void 0),m(this,"ref",void 0),m(this,"_actorContext",void 0),m(this,"_systemId",void 0),m(this,"sessionId",void 0),m(this,"system",void 0),m(this,"_doneEvent",void 0),m(this,"src",void 0),m(this,"_deferred",[]);var a,s,u,c,l=b(b({},st),r),f=l.clock,d=l.logger,v=l.parent,h=l.id,p=l.systemId;this.system=null!==(i=null==v?void 0:v.system)&&void 0!==i?i:(a=0,s=new Map,u=new Map,c=new WeakMap,{_bookId:function(){return"x:".concat(a++)},_register:function(t,e){return s.set(t,e),t},_unregister:function(t){s.delete(t.sessionId);var e=c.get(t);void 0!==e&&(u.delete(e),c.delete(t))},get:function(t){return u.get(t)},_set:function(t,e){var n=u.get(t);if(n&&n!==e)throw new Error("Actor with system ID '".concat(t,"' already exists."));u.set(t,e),c.set(e,t)}}),p&&(this._systemId=p,this.system._set(p,this)),this.sessionId=this.system._bookId(),this.id=null!=h?h:this.sessionId,this.logger=d,this.clock=f,this._parent=v,this.options=l,this.src=l.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:function(t){o._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==o)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(o.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return Y(e,[{key:"_initState",value:function(){var t;this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,null===(t=this.options)||void 0===t?void 0:t.input)}},{key:"update",value:function(t){var e,n,r,i;this._state=t;for(var o,a=this.getSnapshot();o=this._deferred.shift();)o(t);var s,u=k(this.observers);try{for(u.s();!(s=u.n()).done;){var c,l=s.value;null===(c=l.next)||void 0===c||c.call(l,a)}}catch(t){u.e(t)}finally{u.f()}var f=null===(e=(n=this.behavior).getStatus)||void 0===e?void 0:e.call(n,t);switch(null==f?void 0:f.status){case"done":this._stopProcedure(),this._doneEvent=ve(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),null===(i=this._parent)||void 0===i||i.send(he(this.id,f.data)),this._error(f.data)}}},{key:"subscribe",value:function(e,n,r){var i,o=this,a=q(e,n,r);(this.observers.add(a),this.status===t.InterpreterStatus.Stopped)&&(null===(i=a.complete)||void 0===i||i.call(a),this.observers.delete(a));return{unsubscribe:function(){o.observers.delete(a)}}}},{key:"onDone",value:function(e){var n=this;return this.status===t.InterpreterStatus.Stopped&&this._doneEvent?e(this._doneEvent):this.observers.add({complete:function(){n._doneEvent&&e(n._doneEvent)}}),this}},{key:"start",value:function(){return this.status===t.InterpreterStatus.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=t.InterpreterStatus.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}},{key:"_process",value:function(t){try{var e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.type===nt&&(this._stopProcedure(),this._complete())}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((function(e){var n;null===(n=e.error)||void 0===n||n.call(e,t)})),this.stop()}}},{key:"_stop",value:function(){return this.status===t.InterpreterStatus.Stopped?this:(this.mailbox.clear(),this.status===t.InterpreterStatus.NotStarted?(this.status=t.InterpreterStatus.Stopped,this):(this.mailbox.enqueue({type:nt}),this))}},{key:"stop",value:function(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}},{key:"_complete",value:function(){var t,e=k(this.observers);try{for(e.s();!(t=e.n()).done;){var n,r=t.value;null===(n=r.complete)||void 0===n||n.call(r)}}catch(t){e.e(t)}finally{e.f()}this.observers.clear()}},{key:"_error",value:function(t){var e,n=k(this.observers);try{for(n.s();!(e=n.n()).done;){var r,i=e.value;null===(r=i.error)||void 0===r||r.call(i,t)}}catch(t){n.e(t)}finally{n.f()}this.observers.clear()}},{key:"_stopProcedure",value:function(){if(this.status!==t.InterpreterStatus.Running)return this;for(var e=0,n=Object.keys(this.delayedEventsMap);e<n.length;e++){var r=n[e];this.clock.clearTimeout(this.delayedEventsMap[r])}return this.mailbox.clear(),this.mailbox=new Z(this._process.bind(this)),this.status=t.InterpreterStatus.Stopped,this.system._unregister(this),this}},{key:"send",value:function(e){if("string"==typeof e)throw new Error('Only event objects may be sent to actors; use .send({ type: "'.concat(e,'" }) instead'));if(this.status!==t.InterpreterStatus.Stopped){if(this.status!==t.InterpreterStatus.Running&&!this.options.deferEvents)throw new Error('Event "'.concat(e.type,'" was sent to uninitialized actor "').concat(this.id,'". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ').concat(JSON.stringify(e)));this.mailbox.enqueue(e)}else;}},{key:"delaySend",value:function(t){var e=this;this.delayedEventsMap[t.params.id]=this.clock.setTimeout((function(){"to"in t.params&&t.params.to?t.params.to.send(t.params.event):e.send(t.params.event)}),t.params.delay)}},{key:"cancel",value:function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}},{key:"attachDevTools",value:function(){var t=this.options.devTools;t&&("function"==typeof t?t:at)(this)}},{key:"toJSON",value:function(){return{id:this.id}}},{key:"getPersistedState",value:function(){var t,e;return null===(t=(e=this.behavior).getPersistedState)||void 0===t?void 0:t.call(e,this._state)}},{key:tt,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),e}();function ct(t,e){return new ut(t,e)}function lt(e){var n=e;return F({type:r,params:{actor:n}},(function(e,r){var i=r.state,o=B(n)?n({context:i.context,event:e}):n,a="string"==typeof o?i.children[o]:o;return[i,{type:"xstate.stop",params:{actor:a},execute:function(e){a&&(a.status===t.InterpreterStatus.Running?e.defer((function(){e.stopChild(a)})):e.stopChild(a))}}]}))}var ft=function(t){return{context:t.context,event:t.event}};function dt(t){return F({type:a,params:{sendId:t}},(function(e,n){var r,i=n.state,o=n.actorContext,a=B(t)?t({context:i.context,event:e,self:null!==(r=null==o?void 0:o.self)&&void 0!==r?r:{},system:null==o?void 0:o.system}):t;return[i,{type:"xstate.cancel",params:{sendId:a},execute:function(t){t.self.cancel(a)}}]}))}function vt(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var ht=new WeakMap;function pt(t,e,n){var r=ht.get(t);return r?e in r||(r[e]=n()):(r=m({},e,n()),ht.set(t,r)),r[e]}function yt(t,e,n,r){var i,o,a,s=r.machine,u=null!==(i=null==s||null===(o=s.options)||void 0===o||null===(a=o.guards)||void 0===a?void 0:a[t.type])&&void 0!==i?i:t.predicate;if(!u)throw new Error("Guard '".concat(t.type,"' is not implemented.'."));return u({context:e,event:n,state:r,guard:t,evaluate:yt})}function mt(t,e){var n;return z(t)?{type:t,predicate:(null==e?void 0:e(t))||void 0,params:{type:t}}:B(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:null===(n=t.children)||void 0===n?void 0:n.map((function(t){return mt(t,e)})),predicate:(null==e?void 0:e(t.type))||t.predicate}}var gt=function(t){return"atomic"===t.type||"final"===t.type};function bt(t){return Object.values(t.states).filter((function(t){return"history"!==t.type}))}function St(t,e){for(var n=[],r=t.parent;r&&r!==e;)n.push(r),r=r.parent;return n}function xt(t){var e,n=new Set(t),r=new Set(t),i=_t(r),o=k(n);try{for(o.s();!(e=o.n()).done;){var a=e.value;if("compound"!==a.type||i.get(a)&&i.get(a).length){if("parallel"===a.type){var s,u=k(bt(a));try{for(u.s();!(s=u.n()).done;){var c=s.value;if("history"!==c.type&&!r.has(c))for(var l=0,f=Ct(c);l<f.length;l++){var d=f[l];r.add(d)}}}catch(t){u.e(t)}finally{u.f()}}}else Ct(a).forEach((function(t){return r.add(t)}))}}catch(t){o.e(t)}finally{o.f()}var v,h=k(r);try{for(h.s();!(v=h.n()).done;)for(var p=v.value.parent;p;)r.add(p),p=p.parent}catch(t){h.e(t)}finally{h.f()}return r}function wt(t,e){var n=e.get(t);if(!n)return{};if("compound"===t.type){var r=n[0];if(!r)return{};if(gt(r))return r.key}var i,o={},a=k(n);try{for(a.s();!(i=a.n()).done;){var s=i.value;o[s.key]=wt(s,e)}}catch(t){a.e(t)}finally{a.f()}return o}function _t(t){var e,n=new Map,r=k(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.has(i)||n.set(i,[]),i.parent&&(n.has(i.parent)||n.set(i.parent,[]),n.get(i.parent).push(i))}}catch(t){r.e(t)}finally{r.f()}return n}function kt(t,e){return wt(t,_t(xt(e)))}function Tt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t[0].machine.root;return"compound"===e.type?bt(e).some((function(e){return"final"===e.type&&t.includes(e)})):"parallel"===e.type&&bt(e).every((function(e){return Tt(t,e)}))}var Et=function(t){return"#"===t[0]};function It(e){var n=e.config.after;if(!n)return[];var r=function(n,r){var i=function(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}(B(n)?"".concat(e.id,":delay[").concat(r,"]"):n,e.id);return e.entry.push(ue({type:i},{delay:n})),e.exit.push(dt(i)),i};return(V(n)?n.map((function(t,e){var n=r(t.delay,e);return b(b({},t),{},{event:n})})):Object.keys(n).flatMap((function(t,e){var i=n[t],o=z(i)?{target:i}:i,a=isNaN(+t)?t:+t,s=r(a,e);return R(o).map((function(t){return b(b({},t),{},{event:s,delay:a})}))}))).map((function(t){var n=t.delay;return b(b({},Ot(e,t)),{},{delay:n})}))}function Ot(t,e){var n,r=W(e.target),i=null!==(n=e.reenter)&&void 0!==n&&n,o=t.machine.options.guards,a=jt(t,r),s=b(b({},e),{},{actions:fe(R(e.actions)),guard:e.guard?mt(e.guard,(function(t){return o[t]})):void 0,target:a,source:t,reenter:i,eventType:e.event,toJSON:function(){return b(b({},s),{},{source:"#".concat(t.id),target:a?a.map((function(t){return"#".concat(t.id)})):void 0})}});return s}function jt(t,e){if(void 0!==e)return e.map((function(e){if(!z(e))return e;if(Et(e))return t.machine.getStateNodeById(e);var n=e[0]===t.machine.delimiter;if(n&&!t.parent)return Nt(t,e.slice(1));var r=n?t.key+e:e;if(!t.parent)throw new Error('Invalid target: "'.concat(e,'" is not a valid target from the root node. Did you mean ".').concat(e,'"?'));try{return Nt(t.parent,r)}catch(e){throw new Error("Invalid transition definition for state node '".concat(t.id,"':\n").concat(e.message))}}))}function At(t){var e=W(t.target);return e?e.map((function(e){return"string"==typeof e?Nt(t.parent,e):e})):t.parent.initial.target}function Pt(t){return"history"===t.type}function Ct(t){var e=new Set;return function n(r){if(!e.has(r))if(e.add(r),"compound"===r.type){var i,o=k(r.initial.target);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=k(St(s,t));try{for(u.s();!(a=u.n()).done;){var c=a.value;e.add(c)}}catch(t){u.e(t)}finally{u.f()}n(s)}}catch(t){o.e(t)}finally{o.f()}}else if("parallel"===r.type){var l,f=k(bt(r));try{for(f.s();!(l=f.n()).done;){n(l.value)}}catch(t){f.e(t)}finally{f.f()}}}(t),_(e)}function Mt(t,e){if(Et(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(t.id,"'; no child states exist."));var n=t.states[e];if(!n)throw new Error("Child state '".concat(e,"' does not exist on '").concat(t.id,"'"));return n}function Nt(t,e){if("string"==typeof e&&Et(e))try{return t.machine.getStateNodeById(e)}catch(t){}for(var n=P(e,t.machine.delimiter).slice(),r=t;n.length;){var i=n.shift();if(!i.length)break;r=Mt(r,i)}return r}function Dt(t,e){var n=e instanceof ie?e.value:C(e,t.machine.delimiter);if(z(n))return[t,t.states[n]];var r=Object.keys(n),i=r.map((function(e){return Mt(t,e)})).filter(Boolean);return[t.machine.root,t].concat(i,r.reduce((function(e,r){var i=Mt(t,r);if(!i)return e;var o=Dt(i,n[r]);return e.concat(o)}),[]))}function $t(t,e,n,r){return z(e)?function(t,e,n,r){var i=Mt(t,e).next(n,r);return i&&i.length?i:t.next(n,r)}(t,e,n,r):1===Object.keys(e).length?function(t,e,n,r){var i=Object.keys(e),o=$t(Mt(t,i[0]),e[i[0]],n,r);return o&&o.length?o:t.next(n,r)}(t,e,n,r):function(t,e,n,r){for(var i=[],o=0,a=Object.keys(e);o<a.length;o++){var s=a[o],u=e[s];if(u){var c=$t(Mt(t,s),u,n,r);c&&i.push.apply(i,_(c))}}return i.length?i:t.next(n,r)}(t,e,n,r)}function Rt(t,e){for(var n=t;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function Jt(t){for(var e=[],n=t.parent;n;)e.unshift(n),n=n.parent;return e}function Qt(t,e){var n,r=new Set(t),i=new Set(e),o=k(r);try{for(o.s();!(n=o.n()).done;){var a=n.value;if(i.has(a))return!0}}catch(t){o.e(t)}finally{o.f()}var s,u=k(i);try{for(u.s();!(s=u.n()).done;){var c=s.value;if(r.has(c))return!0}}catch(t){u.e(t)}finally{u.f()}return!1}function Vt(t,e,n){var r,i=new Set,o=k(t);try{for(o.s();!(r=o.n()).done;){var a,s=r.value,u=!1,c=new Set,l=k(i);try{for(l.s();!(a=l.n()).done;){var f=a.value;if(Qt(Ut([s],e,n),Ut([f],e,n))){if(!Rt(s.source,f.source)){u=!0;break}c.add(f)}}}catch(t){l.e(t)}finally{l.f()}if(!u){var d,v=k(c);try{for(v.s();!(d=v.n()).done;){var h=d.value;i.delete(h)}}catch(t){v.e(t)}finally{v.f()}i.add(s)}}}catch(t){o.e(t)}finally{o.f()}return Array.from(i)}function Bt(t,e){if(!t.target)return[];var n,r=new Set,i=k(t.target);try{for(i.s();!(n=i.n()).done;){var o=n.value;if(Pt(o))if(e[o.id]){var a,s=k(e[o.id]);try{for(s.s();!(a=s.n()).done;){var u=a.value;r.add(u)}}catch(t){s.e(t)}finally{s.f()}}else{var c,l=k(Bt({target:At(o)},e));try{for(l.s();!(c=l.n()).done;){var f=c.value;r.add(f)}}catch(t){l.e(t)}finally{l.f()}}else r.add(o)}}catch(t){i.e(t)}finally{i.f()}return _(r)}function zt(t,e){var n=Bt(t,e);return n?!t.reenter&&"parallel"!==t.source.type&&n.every((function(e){return Rt(e,t.source)}))?t.source:function(t){var e,n=Jt(w(t,1)[0]),r=[],i=k(t);try{var o=function(){var t=Jt(e.value);r=n.filter((function(e){return t.includes(e)})),n=r,r=[]};for(i.s();!(e=i.n()).done;)o()}catch(t){i.e(t)}finally{i.f()}return n[n.length-1]}(n.concat(t.source)):null}function Ut(t,e,n){var r,i=new Set,o=k(t);try{for(o.s();!(r=o.n()).done;){var a,s=r.value;if(null!==(a=s.target)&&void 0!==a&&a.length){var u,c=zt(s,n),l=k(e);try{for(l.s();!(u=l.n()).done;){var f=u.value;Rt(f,c)&&i.add(f)}}catch(t){l.e(t)}finally{l.f()}}}}catch(t){o.e(t)}finally{o.f()}return _(i)}function Wt(t,e,n,i){var o=e.machine,a=e._initial||t.length>0,s=new Set(e.configuration);if(!e._initial&&!a){var u=oe(e,{event:i,actions:[],transitions:[]});return u.changed=!1,u}var c=function(t,e,n,r,i){var o=[],a=b({},e.historyValue),s=Vt(t,n,a),u=_(e._internalQueue);e._initial||function(t,e,n,r){var i=Ut(t,e,n);i.sort((function(t,e){return e.order-t.order}));var o,a=k(i);try{var s=function(){var t,r,i=o.value,a=k((r=i,Object.keys(r.states).map((function(t){return r.states[t]})).filter((function(t){return"history"===t.type}))));try{for(a.s();!(t=a.n()).done;){var s=t.value,u=void 0;u="deep"===s.history?function(t){return gt(t)&&Rt(t,i)}:function(t){return t.parent===i},n[s.id]=Array.from(e).filter(u)}}catch(t){a.e(t)}finally{a.f()}};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}var u,c=k(i);try{for(c.s();!(u=c.n()).done;){var l=u.value;r.push.apply(r,_(l.exit.flat()).concat(_(l.invoke.map((function(t){return lt(t.id)}))))),e.delete(l)}}catch(t){c.e(t)}finally{c.f()}}(s,n,a,o);o.push.apply(o,_(s.flatMap((function(t){return t.actions})))),qt(s,n,o,u,e,a);var c=_(n),l=Tt(c);if(l){var f=c.sort((function(t,e){return e.order-t.order})).flatMap((function(t){return t.exit}));o.push.apply(o,_(f))}try{var d=Xt(o,r,e,i).nextState,v=l?function(t,e,n){var r=t[0].machine,i=t.find((function(t){return"final"===t.type&&t.parent===r.root}));return i&&i.output?J(i.output,e,n):void 0}(c,d.context,r):void 0;return u.push.apply(u,_(d._internalQueue)),oe(e,{actions:d.actions,configuration:c,historyValue:a,_internalQueue:u,context:d.context,event:r,done:l,output:v,children:d.children})}catch(t){throw t}}(e._initial?[{target:_(e.configuration).filter(gt),source:o.root,reenter:!0,actions:[],eventType:null,toJSON:null}]:t,e,s,i,n),f=c.context,d=function(t,e){var n,i=b({},t.children),o=k(e);try{for(o.s();!(n=o.n()).done;){var a=n.value;if(a.type===l&&a.params.ref){var s=a.params.ref;s&&(i[s.id]=s)}else if(a.type===r){var u=a.params.actor;u&&delete i[u.id]}}}catch(t){o.e(t)}finally{o.f()}return i}(e,c.actions),v=oe(c,{value:{},transitions:t,children:d});return v.changed=e._initial?void 0:!ee(v.value,e.value)||v.actions.length>0||f!==e.context,v}function qt(t,e,n,r,i,o){var a=new Set,s=new Set;Lt(t,o,s,a),i._initial&&s.add(i.machine.root);var u,c=k(_(a).sort((function(t,e){return t.order-e.order})));try{for(c.s();!(u=c.n()).done;){var l=u.value;e.add(l);var f,d=k(l.invoke);try{for(d.s();!(f=d.n()).done;){var v=f.value;n.push(ae(v))}}catch(t){d.e(t)}finally{d.f()}if(n.push.apply(n,_(l.entry)),s.has(l)){var h,p=k(s);try{for(p.s();!(h=p.n()).done;){var y=h.value.initial.actions;n.push.apply(n,_(y))}}catch(t){p.e(t)}finally{p.f()}}if("final"===l.type){var m=l.parent;if(!m.parent)continue;if(r.push(de(m.id,l.output?J(l.output,i.context,i.event):void 0)),m.parent){var g=m.parent;"parallel"===g.type&&bt(g).every((function(t){return Tt(_(e),t)}))&&r.push(de(g.id))}}}}catch(t){c.e(t)}finally{c.f()}}function Lt(t,e,n,r){var i,o=k(t);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=k(s.target||[]);try{for(u.s();!(a=u.n()).done;){Ft(a.value,e,n,r)}}catch(t){u.e(t)}finally{u.f()}var c,l=zt(s,e),f=k(Bt(s,e));try{for(f.s();!(c=f.n()).done;){Gt(c.value,l,r,e,n)}}catch(t){f.e(t)}finally{f.f()}}}catch(t){o.e(t)}finally{o.f()}}function Ft(t,e,n,r){if(Pt(t))if(e[t.id]){var i,o=e[t.id],a=k(o);try{for(a.s();!(i=a.n()).done;){Ft(i.value,e,n,r)}}catch(t){a.e(t)}finally{a.f()}var s,u=k(o);try{for(u.s();!(s=u.n()).done;){Gt(s.value,t.parent,r,e,n);var c,l=k(n);try{for(l.s();!(c=l.n()).done;){var f=c.value;n.add(f)}}catch(t){l.e(t)}finally{l.f()}}}catch(t){u.e(t)}finally{u.f()}}else{var d,v=At(t),h=k(v);try{for(h.s();!(d=h.n()).done;){Ft(d.value,e,n,r)}}catch(t){h.e(t)}finally{h.f()}var p,y=k(v);try{for(y.s();!(p=y.n()).done;){Gt(p.value,t,r,e,n);var m,g=k(n);try{for(g.s();!(m=g.n()).done;){var b=m.value;n.add(b)}}catch(t){g.e(t)}finally{g.f()}}}catch(t){y.e(t)}finally{y.f()}}else if(r.add(t),"compound"===t.type){n.add(t);var S,x=t.initial.target,w=k(x);try{for(w.s();!(S=w.n()).done;){Ft(S.value,e,n,r)}}catch(t){w.e(t)}finally{w.f()}var T,E=k(x);try{for(E.s();!(T=E.n()).done;){Gt(T.value,t,r,e,n)}}catch(t){E.e(t)}finally{E.f()}}else if("parallel"===t.type){var I,O=k(bt(t).filter((function(t){return!Pt(t)})));try{var j=function(){var t=I.value;_(r).some((function(e){return Rt(e,t)}))||Ft(t,e,n,r)};for(O.s();!(I=O.n()).done;)j()}catch(t){O.e(t)}finally{O.f()}}}function Gt(t,e,n,r,i){var o,a=k(St(t,e));try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.add(s),"parallel"===s.type){var u,c=k(bt(s).filter((function(t){return!Pt(t)})));try{var l=function(){var t=u.value;_(n).some((function(e){return Rt(e,t)}))||Ft(t,r,i,n)};for(c.s();!(u=c.n()).done;)l()}catch(t){c.e(t)}finally{c.f()}}}}catch(t){a.e(t)}finally{a.f()}}function Xt(e,n,r,a){var s=r.machine,u=[],c=[],l=r;function f(e){var n;(u.push(e),(null==a?void 0:a.self.status)===t.InterpreterStatus.Running)&&(null===(n=e.execute)||void 0===n||n.call(e,a),delete e.execute)}function d(t){var e=function(t,e){if(G(t))return t;var n,r=e[t.type];return"function"==typeof r?F({type:"xstate.function",params:null!==(n=t.params)&&void 0!==n?n:{}},(function(e,n){var i=n.state,o={type:t.type,params:t.params,execute:function(t){return r({context:i.context,event:e,action:o,system:t.system,self:t.self})}};return[i,o]})):r||t}(t,s.options.actions);if(G(e)){var r,u=w(e.resolve(n,{state:l,action:t,actorContext:a}),2),v=u[0],h=u[1],y=null===(r=h.params)||void 0===r?void 0:r.actions;return l=v,(h.type===i||h.type===o&&h.params.internal)&&"number"!=typeof h.params.delay&&c.push(h),h.type!==p&&f(h),void fe(y).forEach(d)}f(e)}var v,h=k(e);try{for(h.s();!(v=h.n()).done;){d(v.value)}}catch(t){h.e(t)}finally{h.f()}return{nextState:oe(l,{actions:u,_internalQueue:c.map((function(t){return t.params.event}))})}}function Ht(t,e,n){var r=t,i=[];if(e.type===nt)return r=Kt(e,r,n),i.push(r),{state:r,microstates:i};e.type!==c&&(r=Wt(Yt(e,r),t,n,e),i.push(r));for(;!r.done;){var o=Zt(r);if(0===o.length){if(r.configuration.some((function(t){return t.always}))&&(r.transitions=[]),!r._internalQueue.length)break;var a,s=r.actions,u=r._internalQueue[0];(r=Wt(Yt(u,r),r,n,u))._internalQueue.shift(),(a=r.actions).unshift.apply(a,_(s)),i.push(r)}if(o.length){var l,f=r.actions;(l=(r=Wt(o,r,n,r.event)).actions).unshift.apply(l,_(f)),i.push(r)}}return r.done&&Kt(r.event,r,n),{state:r,microstates:i}}function Kt(t,e,n){var r,i=[],o=k(e.configuration.sort((function(t,e){return e.order-t.order})));try{for(o.s();!(r=o.n()).done;){var a=r.value;i.push.apply(i,_(a.exit))}}catch(t){o.e(t)}finally{o.f()}for(var s=0,u=Object.values(e.children);s<u.length;s++){var c=u[s];i.push(lt(c))}return Xt(i,t,e,n).nextState}function Yt(t,e){return e.machine.getTransitionData(e,t)}function Zt(t){var e,n=new Set,r=k(t.configuration.filter(gt));try{for(r.s();!(e=r.n()).done;){var i,o=e.value,a=k([o].concat(St(o,null)));try{t:for(a.s();!(i=a.n()).done;){var s=i.value;if(s.always){var u,c=k(s.always);try{for(c.s();!(u=c.n()).done;){var l=u.value;if(void 0===l.guard||yt(l.guard,t.context,t.event,t)){n.add(l);break t}}}catch(t){c.e(t)}finally{c.f()}}}}catch(t){a.e(t)}finally{a.f()}}}catch(t){r.e(t)}finally{r.f()}return Vt(Array.from(n),new Set(t.configuration),t.historyValue)}function te(t,e){return kt(t,_(xt(Dt(t,e))))}function ee(t,e){if(t===e)return!0;if(void 0===t||void 0===e)return!1;if(z(t)||z(e))return t===e;var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every((function(n){return ee(t[n],e[n])}))}var ne=["configuration","transitions","tags","machine"],re=["configuration","transitions","tags","machine","children"],ie=function(){function t(e,n){var r,i,o,a;H(this,t),this.machine=n,m(this,"tags",void 0),m(this,"value",void 0),m(this,"done",void 0),m(this,"output",void 0),m(this,"context",void 0),m(this,"historyValue",{}),m(this,"actions",[]),m(this,"event",void 0),m(this,"_internalQueue",void 0),m(this,"_initial",!1),m(this,"changed",void 0),m(this,"configuration",void 0),m(this,"transitions",void 0),m(this,"children",void 0),this.context=e.context,this._internalQueue=null!==(r=e._internalQueue)&&void 0!==r?r:[],this.event=e.event,this.historyValue=e.historyValue||{},this.actions=null!==(i=e.actions)&&void 0!==i?i:[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=null!==(o=e.configuration)&&void 0!==o?o:Array.from(xt(Dt(n.root,e.value))),this.transitions=e.transitions,this.children=e.children,this.value=kt(n.root,this.configuration),this.tags=new Set(D(this.configuration.map((function(t){return t.tags})))),this.done=null!==(a=e.done)&&void 0!==a&&a,this.output=e.output}return Y(t,[{key:"toStrings",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.value,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";if(z(e))return[e];var r=Object.keys(e);return r.concat.apply(r,_(r.map((function(r){return t.toStrings(e[r],n).map((function(t){return r+n+t}))}))))}},{key:"toJSON",value:function(){this.configuration,this.transitions;var t=this.tags;return this.machine,b(b({},vt(this,ne)),{},{tags:Array.from(t),meta:this.meta})}},{key:"matches",value:function(t){return A(t,this.value)}},{key:"hasTag",value:function(t){return this.tags.has(t)}},{key:"can",value:function(t){Q(!!this.machine,"state.can(...) used outside of a machine-created State object; this will always return false.");var e=this.machine.getTransitionData(this,t);return!(null==e||!e.length)&&e.some((function(t){return void 0!==t.target||t.actions.length}))}},{key:"nextEvents",get:function(){var t=this;return pt(this,"nextEvents",(function(){return _(new Set(D(_(t.configuration.map((function(t){return t.ownEvents}))))))}))}},{key:"meta",get:function(){return this.configuration.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})}}],[{key:"from",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;if(e instanceof t)return e.context!==n?new t({value:e.value,context:n,event:e.event,actions:[],meta:{},configuration:[],transitions:[],children:{}},r):e;var i=pe({}),o=xt(Dt(r.root,e));return new t({value:e,context:n,event:i,actions:[],meta:void 0,configuration:Array.from(o),transitions:[],children:{}},r)}}]),t}();function oe(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new ie(b(b({},t),e),t.machine)}function ae(e){return F({type:l,params:e},(function(n,r){var i,o,a=r.state,s=r.actorContext,u=l,c=e.id,f=e.src;if((o=f)&&"object"===T(o)&&"function"==typeof o.send)i={type:u,params:b(b({},e),{},{ref:f})};else{var d=L(a.machine.options.actors[f]);if(d){var v="input"in e?e.input:d.input,h=ct(d.src,{id:c,src:f,parent:null==s?void 0:s.self,systemId:e.systemId,input:"function"==typeof v?v({context:a.context,event:n,self:null==s?void 0:s.self}):v});i={type:u,params:b(b({},e),{},{ref:h})}}else i={type:u,params:e}}var p=i.params.ref,y=oe(a,{children:b(b({},a.children),{},m({},c,p))});return i.execute=function(e){var n=e.self,r=i.params,o=r.id;r.ref&&e.defer((function(){if(p.status!==t.InterpreterStatus.Stopped)try{var e;null===(e=p.start)||void 0===e||e.call(p)}catch(t){return void n.send(he(o,t))}}))},[y,i]}))}function se(t,e,n,r,i){return function(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(z(o)){var s=L(e.options.actors[o]);if(s){var u,c=null!==(u=a.id)&&void 0!==u?u:"anon",l="input"in a?a.input:s.input,f=ct(s.src,{id:c,parent:t,input:"function"==typeof l?l({context:n,event:r,self:t}):l});return i.push(ae({id:f.id,src:f,ref:f,meta:void 0,input:l})),f}throw new Error("Behavior '".concat(o,"' not implemented in machine '").concat(e.id,"'"))}var d=ct(o,{id:a.id||"anonymous",parent:t,input:a.input});return i.push(ae({src:d,ref:d,id:d.id,meta:void 0,input:a.input})),d}}function ue(t,e){return F({type:i,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},(function(n,r){var o,a=r.state,s=r.actorContext,u={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},c={context:a.context,event:n,self:null!==(o=null==s?void 0:s.self)&&void 0!==o?o:{},system:null==s?void 0:s.system},l=a.machine.options.delays;if("string"==typeof t)throw new Error('Only event objects may be used with raise; use raise({ type: "'.concat(t,'" }) instead'));var f,d="function"==typeof t?t(c):t;if("string"==typeof u.delay){var v=l&&l[u.delay];f="function"==typeof v?v(c):v}else f="function"==typeof u.delay?u.delay(c):u.delay;var h={type:i,params:b(b({},u),{},{event:d,delay:f}),execute:function(t){"number"!=typeof h.params.delay||t.self.delaySend(h)}};return[a,h]}))}var ce={type:c};function le(t){if(G(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){var e="xstate.function";return F({type:e,params:{}},(function(n,r){var i=r.state,o={type:e,params:{function:t},execute:function(e){return t({context:i.context,event:n,action:o,self:e.self,system:e.system})}};return[i,o]}))}return t}var fe=function(t){return t?(V(t)?t:[t]).map(le):[]};function de(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function ve(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function he(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function pe(t){return{type:c,input:t}}var ye=["onDone","onError"],me={},ge=function(){function t(e,n){var r=this;if(H(this,t),this.config=e,m(this,"key",void 0),m(this,"id",void 0),m(this,"type",void 0),m(this,"path",void 0),m(this,"states",void 0),m(this,"history",void 0),m(this,"entry",void 0),m(this,"exit",void 0),m(this,"parent",void 0),m(this,"machine",void 0),m(this,"meta",void 0),m(this,"output",void 0),m(this,"order",-1),m(this,"description",void 0),m(this,"tags",[]),m(this,"transitions",void 0),m(this,"always",void 0),this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id].concat(_(this.path)).join(this.machine.delimiter),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?N(this.config.states,(function(e,n){return new t(e,{_parent:r,_key:n,_machine:r.machine})})):me,"compound"===this.type&&!this.config.initial)throw new Error('No initial state specified for compound state node "#'.concat(this.id,'". Try adding { initial: "').concat(Object.keys(this.states)[0],'" } to the state config.'));this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=fe(this.config.entry),this.exit=fe(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=R(e.tags)}return Y(t,[{key:"_initialize",value:function(){var t=this;this.transitions=function(t){var e=[];if(Array.isArray(t.config.on))e.push.apply(e,_(t.config.on));else if(t.config.on){for(var n=t.config.on,r=n[j],i=void 0===r?[]:r,o=vt(n,[j].map(y)),a=0,s=Object.keys(o);a<s.length;a++){var u=s[a];if(u===O)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');var c=U(u,o[u]);e.push.apply(e,_(c))}e.push.apply(e,_(U(j,i)))}var l,f=t.config.onDone?U(String(de(t.id)),t.config.onDone):[],d=t.invoke.flatMap((function(t){var e=[];return t.onDone&&e.push.apply(e,_(U("done.invoke.".concat(t.id),t.onDone))),t.onError&&e.push.apply(e,_(U("error.platform.".concat(t.id),t.onError))),t.onSnapshot&&e.push.apply(e,_(U("xstate.snapshot.".concat(t.id),t.onSnapshot))),e})),v=t.after,h=[].concat(_(f),_(d),e).flatMap((function(e){return R(e).map((function(e){return Ot(t,e)}))})),p=k(v);try{for(p.s();!(l=p.n()).done;){var m=l.value;h.push(m)}}catch(t){p.e(t)}finally{p.f()}return h}(this),this.config.always&&(this.always=U(O,this.config.always).map((function(e){return Ot(t,e)}))),Object.keys(this.states).forEach((function(e){t.states[e]._initialize()}))}},{key:"definition",get:function(){var t=this;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,eventType:null,reenter:!1,toJSON:function(){return{target:t.initial.target.map((function(t){return"#".concat(t.id)})),source:"#".concat(t.id),actions:t.initial.actions,eventType:null}}}:void 0,history:this.history,states:N(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.entry,exit:this.exit,meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}},{key:"toJSON",value:function(){return this.definition}},{key:"invoke",get:function(){var t=this;return pt(this,"invoke",(function(){return R(t.config.invoke).map((function(e,n){var r,i,o=(r=t.id,i=n,"".concat(r,":invocation[").concat(i,"]")),a=function(t,e){if("object"===T(t)){if("src"in t)return t;if("transition"in t)return{id:e,src:t}}return{id:e,src:t}}(e,o),s=a.id||o,u=a.src,c=a.systemId,f=z(u)||"type"in u?u:s;return t.machine.options.actors[s]||"string"==typeof u||"type"in u||(t.machine.options.actors=b(b({},t.machine.options.actors),{},m({},s,u))),b(b({type:l},a),{},{src:f,id:s,systemId:c,toJSON:function(){return a.onDone,a.onError,b(b({},vt(a,ye)),{},{type:l,src:f,id:s})}})}))}))}},{key:"on",get:function(){var t=this;return pt(this,"on",(function(){return t.transitions.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})}))}},{key:"after",get:function(){var t=this;return pt(this,"delayedTransitions",(function(){return It(t)}))}},{key:"initial",get:function(){var t=this;return pt(this,"initial",(function(){return function(t,e){if(z(e)||V(e)){var n=R(e).map((function(e){var n=z(e)?Et(e)?t.machine.getStateNodeById(e):t.states[e]:e;if(!n)throw new Error('Initial state node "'.concat(e,'" not found on parent state node #').concat(t.id));if(!Rt(n,t))throw new Error("Invalid initial target: state node #".concat(n.id," is not a descendant of #").concat(t.id));return n})),r=jt(t,n),i={source:t,actions:[],eventType:null,reenter:!1,target:r,toJSON:function(){return b(b({},i),{},{source:"#".concat(t.id),target:r?r.map((function(t){return"#".concat(t.id)})):void 0})}};return i}return Ot(t,{target:R(e.target).map((function(e){return z(e)?Et(e)?e:"".concat(t.machine.delimiter).concat(e):e})),actions:e.actions,event:null})}(t,t.config.initial||[])}))}},{key:"next",value:function(t,e){var n,r,i=this,o=e.type,a=[],s=pt(this,"candidates-".concat(o),(function(){return t=o,i.transitions.filter((function(e){var n=e.eventType;if(n===t)return!0;if(n===j)return!0;if(!n.endsWith(".*"))return!1;for(var r=n.split("."),i=t.split("."),o=0;o<r.length;o++){var a=r[o],s=i[o];if("*"===a)return o===r.length-1;if(a!==s)return!1}return!0}));var t})),u=k(s);try{for(u.s();!(r=u.n()).done;){var c=r.value,l=c.guard,f=t.context,d=!1;try{d=!l||yt(l,f,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(l.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(d){a.push.apply(a,_(c.actions)),n=c;break}}}catch(t){u.e(t)}finally{u.f()}return n?[n]:void 0}},{key:"target",get:function(){if("history"===this.type)return this.config.target}},{key:"stateIds",get:function(){var t=this,e=D(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)}},{key:"events",get:function(){var t=this;return pt(this,"events",(function(){var e=t.states,n=new Set(t.ownEvents);if(e)for(var r=0,i=Object.keys(e);r<i.length;r++){var o=e[i[r]];if(o.states){var a,s=k(o.events);try{for(s.s();!(a=s.n()).done;){var u=a.value;n.add("".concat(u))}}catch(t){s.e(t)}finally{s.f()}}}return Array.from(n)}))}},{key:"ownEvents",get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&!t.reenter)})).map((function(t){return t.eventType})));return Array.from(t)}}]),t}();var be=function(){function t(e,n){var r;H(this,t),this.config=e,m(this,"version",void 0),m(this,"delimiter",void 0),m(this,"options",void 0),m(this,"types",void 0),m(this,"__xstatenode",!0),m(this,"idMap",new Map),m(this,"root",void 0),m(this,"id",void 0),m(this,"states",void 0),m(this,"events",void 0),m(this,"__TContext",void 0),m(this,"__TEvent",void 0),m(this,"__TAction",void 0),m(this,"__TActorMap",void 0),m(this,"__TResolvedTypesMeta",void 0),this.id=e.id||"(machine)",this.options=Object.assign({actions:{},actors:{},delays:{},guards:{},context:{}},n),this.delimiter=this.config.delimiter||E,this.version=this.config.version,this.types=null!==(r=this.config.types)&&void 0!==r?r:{},this.transition=this.transition.bind(this),this.root=new ge(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}return Y(t,[{key:"getContext",value:function(t){return this.getContextAndActions(void 0,t)[0]}},{key:"getContextAndActions",value:function(t,e){var n=[],r=this.config.context;return[("function"==typeof r?r({spawn:se(null==t?void 0:t.self,this,void 0,pe(e),n),input:e}):r)||{},n]}},{key:"provide",value:function(e){var n=this.options,r=n.actions,i=n.guards,o=n.actors,a=n.delays;return new t(this.config,{actions:b(b({},r),e.actions),guards:b(b({},i),e.guards),actors:b(b({},o),e.actors),delays:b(b({},a),e.delays)})}},{key:"resolveState",value:function(t){var e=xt(Dt(this.root,t.value)),n=Array.from(e);return this.createState(b(b({},t),{},{value:te(this.root,t.value),configuration:n,done:Tt(n)}))}},{key:"resolveStateValue",value:function(t){var e=te(this.root,t),n=this.getContext();return this.resolveState(ie.from(e,n,this))}},{key:"transition",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=t instanceof ie?t:this.resolveStateValue(t);if(function(t){return"string"==typeof t.type&&(t.type===f||t.type.startsWith(d))}(e)&&!r.nextEvents.some((function(t){return t===e.type})))throw e.data;return Ht(r,e,n).state}},{key:"microstep",value:function(){return Ht(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,arguments.length>1?arguments[1]:void 0,arguments.length>2?arguments[2]:void 0).microstates}},{key:"getTransitionData",value:function(t,e){return $t(this.root,t.value,t,e)||[]}},{key:"getPreInitialState",value:function(t,e){var n,r=w(this.getContextAndActions(t,e),2),i=r[0],o=r[1],a=function(t){var e=[],n=t.initial,r=new Set;Lt([n],{},new Set([t]),r);var i,o=k(_(r).sort((function(t,e){return t.order-e.order})));try{for(o.s();!(i=o.n()).done;){var a=i.value;e.push(a)}}catch(t){o.e(t)}finally{o.f()}return e}(this.root),s=this.resolveState(this.createState({value:{},context:i,event:pe({}),actions:[],meta:void 0,configuration:a,transitions:[],children:{}}));if(s._initial=!0,(n=s.actions).unshift.apply(n,_(o)),t){var u=Xt(o,ce,s,t).nextState;s.children=u.children,s.actions=u.actions}return s}},{key:"initialState",get:function(){return this.getInitialState()}},{key:"getInitialState",value:function(t,e){var n,r=pe(e),i=this.getPreInitialState(t,e),o=Wt([],i,t,r);return(n=o.actions).unshift.apply(n,_(i.actions)),Ht(o,r,t).state}},{key:"start",value:function(t,e){t.actions.forEach((function(t){var n;null===(n=t.execute)||void 0===n||n.call(t,e)})),Object.values(t.children).forEach((function(t){if(0===t.status)try{var n;null===(n=t.start)||void 0===n||n.call(t)}catch(n){e.self.send(he(t.id,n))}}))}},{key:"getStateNodeById",value:function(t){var e=t.split(this.delimiter),n=e.slice(1),r=Et(e[0])?e[0].slice(1):e[0],i=this.idMap.get(r);if(!i)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return Nt(i,n)}},{key:"definition",get:function(){return b({context:this.getContext()},this.root.definition)}},{key:"toJSON",value:function(){return this.definition}},{key:"getPersistedState",value:function(t){return function(t){t.configuration,t.transitions,t.tags,t.machine;var e=t.children,n=vt(t,re),r={};for(var i in e){var o,a;r[i]={state:null===(o=(a=e[i]).getPersistedState)||void 0===o?void 0:o.call(a),src:e[i].src}}return b(b({},n),{},{children:r})}(t)}},{key:"createState",value:function(t){var e=t instanceof ie?t:new ie(t,this);return Xt(e.actions,e.event,e,void 0).nextState}},{key:"getStatus",value:function(t){return t.done?{status:"done",data:t.output}:{status:"active"}}},{key:"restoreState",value:function(t,e){var n=this,r={};Object.keys(t.children).forEach((function(i){var o,a,s=t.children[i],u=s.state,c=s.src,l=c?null===(o=L(n.options.actors[c]))||void 0===o?void 0:o.src:void 0;if(l){var f=ct(l,{id:i,state:null===(a=l.restoreState)||void 0===a?void 0:a.call(l,u,e)});r[i]=f}}));var i=this.createState(new ie(b(b({},t),{},{children:r}),this));return i.configuration.forEach((function(t){t.invoke&&t.invoke.forEach((function(t){var i=t.id,o=t.src;if(!r[i]){var a=L(n.options.actors[o]);if(a){var s=ct(a.src,{id:i,parent:null==e?void 0:e.self,input:"input"in t?t.input:a.input});r[i]=s}}}))})),i.actions=[],i}}]),t}();var Se=function(){function t(){H(this,t),m(this,"timeouts",new Map),m(this,"_now",0),m(this,"_id",0)}return Y(t,[{key:"now",value:function(){return this._now}},{key:"getId",value:function(){return this._id++}},{key:"setTimeout",value:function(t,e){var n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}},{key:"clearTimeout",value:function(t){this.timeouts.delete(t)}},{key:"set",value:function(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}},{key:"flushTimeouts",value:function(){var t=this;_(this.timeouts).sort((function(t,e){var n=w(t,2);n[0];var r=n[1],i=w(e,2);i[0];var o=i[1],a=r.start+r.timeout;return o.start+o.timeout>a?-1:1})).forEach((function(e){var n=w(e,2),r=n[0],i=n[1];t.now()-i.start>=i.timeout&&(t.timeouts.delete(r),i.fn.call(null))}))}},{key:"increment",value:function(t){this._now+=t,this.flushTimeouts()}}]),t}(),xe={timeout:1e4};t.Interpreter=ut,t.SimulatedClock=Se,t.State=ie,t.StateMachine=be,t.StateNode=ge,t.and=function(t){return{type:"xstate.boolean",params:{op:"and"},children:t.map((function(t){return mt(t)})),predicate:function(t){var e=t.evaluate,n=t.guard,r=t.context,i=t.event,o=t.state;return n.children.every((function(t){return e(t,r,i,o)}))}}},t.assign=function(t){return F({type:s,params:{assignment:t}},(function(e,n){var r,i=n.state,o=n.action,a=n.actorContext,u=[];if(!i.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");var c={context:i.context,event:e,action:o,spawn:se(null==a?void 0:a.self,i.machine,i.context,e,u),self:null!==(r=null==a?void 0:a.self)&&void 0!==r?r:{},system:null==a?void 0:a.system},l={};if(B(t))l=t(c);else for(var f=0,d=Object.keys(t);f<d.length;f++){var v=d[f],h=t[v];l[v]=B(h)?h(c):h}var p=Object.assign({},i.context,l);return[oe(i,{context:p}),{type:s,params:{context:p,actions:u}}]}))},t.cancel=dt,t.choose=function(t){return F({type:h,params:{guards:t}},(function(e,n){var r,i=n.state,o=null===(r=t.find((function(t){var n=t.guard&&mt(t.guard,(function(t){return i.machine.options.guards[t]}));return!n||yt(n,i.context,e,i)})))||void 0===r?void 0:r.actions;return[i,{type:h,params:{actions:fe(o)}}]}))},t.createMachine=function(t,e){return new be(t,e)},t.doneInvoke=ve,t.forwardTo=function(t,e){return X((function(t){return t.event}),b(b({},e),{},{to:t}))},t.fromCallback=function(t){return{config:t,start:function(t,e){e.self.send({type:et})},transition:function(e,n,r){var i,o=r.self,a=r.id;if(n.type===et){return e.dispose=t((function(t){var n;e.canceled||null===(n=o._parent)||void 0===n||n.send(t)}),(function(t){e.receivers.add(t)}),{input:e.input}),((i=e.dispose)instanceof Promise||null!==i&&(B(i)||"object"===T(i))&&B(i.then))&&e.dispose.then((function(t){var n;null===(n=o._parent)||void 0===n||n.send(ve(a,t)),e.canceled=!0}),(function(t){var n;e.canceled=!0,null===(n=o._parent)||void 0===n||n.send(he(a,t))})),e}return n.type===nt?(e.canceled=!0,B(e.dispose)&&e.dispose(),e):(rt(n.type)||rt(n.type)||e.receivers.forEach((function(t){return t(n)})),e)},getInitialState:function(t,e){return{canceled:!1,receivers:new Set,dispose:void 0,input:e}},getSnapshot:function(){},getPersistedState:function(t){return t.input}}},t.fromEventObservable=function(t){var e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:function(t,r){if("active"!==t.status)return t;switch(r.type){case e:return b(b({},t),{},{status:"error",input:void 0,data:r.data,subscription:void 0});case n:return b(b({},t),{},{status:"done",input:void 0,subscription:void 0});case nt:return t.subscription.unsubscribe(),b(b({},t),{},{status:"canceled",input:void 0,subscription:void 0});default:return t}},getInitialState:function(){return{subscription:void 0,status:"active",data:void 0}},start:function(r,i){var o=i.self;"done"!==r.status&&(r.subscription=t({input:r.input}).subscribe({next:function(t){var e;null===(e=o._parent)||void 0===e||e.send(t)},error:function(t){o.send({type:e,data:t})},complete:function(){o.send({type:n})}}))},getSnapshot:function(t){},getPersistedState:function(t){return{status:t.status,data:t.data,input:t.input}},getStatus:function(t){return t},restoreState:function(t){return b(b({},t),{},{subscription:void 0})}}},t.fromObservable=function(t){var e="$$xstate.next",n="$$xstate.error",r="$$xstate.complete";return{config:t,transition:function(t,i,o){var a=o.self,s=o.id,u=o.defer;if("active"!==t.status)return t;switch(i.type){case e:return u((function(){var t;null===(t=a._parent)||void 0===t||t.send({type:"xstate.snapshot.".concat(s),data:i.data})})),b(b({},t),{},{data:i.data});case n:return b(b({},t),{},{status:"error",input:void 0,data:i.data,subscription:void 0});case r:return b(b({},t),{},{status:"done",input:void 0,subscription:void 0});case nt:return t.subscription.unsubscribe(),b(b({},t),{},{status:"canceled",input:void 0,subscription:void 0});default:return t}},getInitialState:function(t,e){return{subscription:void 0,status:"active",data:void 0,input:e}},start:function(i,o){var a=o.self;"done"!==i.status&&(i.subscription=t({input:i.input}).subscribe({next:function(t){a.send({type:e,data:t})},error:function(t){a.send({type:n,data:t})},complete:function(){a.send({type:r})}}))},getSnapshot:function(t){return t.data},getPersistedState:function(t){return{status:t.status,data:t.data,input:t.input}},getStatus:function(t){return t},restoreState:function(t){return b(b({},t),{},{subscription:void 0})}}},t.fromPromise=function(t){var e="$$xstate.resolve",n="$$xstate.reject";return{config:t,transition:function(t,r){if("active"!==t.status)return t;switch(r.type){case e:return b(b({},t),{},{status:"done",data:r.data,input:void 0});case n:return b(b({},t),{},{status:"error",data:r.data,input:void 0});case nt:return b(b({},t),{},{status:"canceled",input:void 0});default:return t}},start:function(r,i){var o=i.self;"active"===r.status&&Promise.resolve(t({input:r.input})).then((function(t){"active"===o._state.status&&o.send({type:e,data:t})}),(function(t){"active"===o._state.status&&o.send({type:n,data:t})}))},getInitialState:function(t,e){return{status:"active",data:void 0,input:e}},getSnapshot:function(t){return t.data},getStatus:function(t){return t},getPersistedState:function(t){return t},restoreState:function(t){return t}}},t.fromTransition=function(t,e){return{config:t,transition:function(e,n,r){return t(e,n,r)},getInitialState:function(t,n){return"function"==typeof e?e({input:n}):e},getSnapshot:function(t){return t},getPersistedState:function(t){return t},restoreState:function(t){return t}}},t.getStateNodes=Dt,t.interpret=ct,t.log=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ft,e=arguments.length>1?arguments[1]:void 0;return F({type:u,params:{label:e,expr:t}},(function(n,r){var i,o=r.state,a=r.actorContext,s="function"==typeof t?t({context:o.context,event:n,self:null!==(i=null==a?void 0:a.self)&&void 0!==i?i:{},system:null==a?void 0:a.system}):t;return[o,{type:"xstate.log",params:{label:e,value:s},execute:function(t){var n,r;e?null===(n=t.logger)||void 0===n||n.call(t,e,s):null===(r=t.logger)||void 0===r||r.call(t,s)}}]}))},t.mapState=function(t,e){for(var n,r=0,i=Object.keys(t);r<i.length;r++){var o=i[r];A(o,e)&&(!n||e.length>n.length)&&(n=o)}return t[n]},t.matchesState=A,t.not=function(t){return{type:"xstate.boolean",params:{op:"not"},children:[mt(t)],predicate:function(t){var e=t.evaluate,n=t.guard,r=t.context,i=t.event,o=t.state;return!e(n.children[0],r,i,o)}}},t.or=function(t){return{type:"xstate.boolean",params:{op:"or"},children:t.map((function(t){return mt(t)})),predicate:function(t){var e=t.evaluate,n=t.guard,r=t.context,i=t.event,o=t.state;return n.children.some((function(t){return e(t,r,i,o)}))}}},t.pathToStateValue=M,t.pure=function(t){return F({type:p,params:{get:t}},(function(e,n){var r,i=n.state;return[i,{type:p,params:{actions:null!==(r=R(fe(t({context:i.context,event:e}))))&&void 0!==r?r:[]}}]}))},t.raise=ue,t.sendParent=function(e,n){return X(e,b(b({},n),{},{to:t.SpecialTargets.Parent}))},t.sendTo=function(t,e,n){return X(e,b(b({},n),{},{to:t}))},t.stateIn=function(t){return{type:"xstate.guard:in",params:{stateValue:t},predicate:function(e){var n=e.state;return z(t)&&Et(t)?n.configuration.some((function(e){return e.id===t.slice(1)})):n.matches(t)}}},t.stop=lt,t.toObserver=q,t.waitFor=function(t,e,n){var r=b(b({},xe),n);return new Promise((function(n,i){var o=!1,a=r.timeout===1/0?void 0:setTimeout((function(){c.unsubscribe(),i(new Error("Timeout of ".concat(r.timeout," ms exceeded")))}),r.timeout),s=function(){clearTimeout(a),o=!0,null==c||c.unsubscribe()};function u(t){e(t)&&(s(),n(t))}u(t.getSnapshot());var c=t.subscribe({next:u,error:function(t){s(),i(t)},complete:function(){s(),i(new Error("Actor terminated without satisfying predicate"))}});o&&c.unsubscribe()}))},Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate.umd.min.js.map