xstate 5.0.0-beta.9 → 5.0.1

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 (107) hide show
  1. package/README.md +10 -8
  2. package/actions/dist/xstate-actions.cjs.js +19 -5
  3. package/actions/dist/xstate-actions.cjs.mjs +3 -15
  4. package/actions/dist/xstate-actions.development.cjs.js +21 -0
  5. package/actions/dist/xstate-actions.development.cjs.mjs +13 -0
  6. package/actions/dist/xstate-actions.development.esm.js +3 -0
  7. package/actions/dist/xstate-actions.esm.js +3 -2
  8. package/actions/dist/xstate-actions.umd.min.js +1 -1
  9. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  10. package/actors/dist/xstate-actors.cjs.js +621 -4
  11. package/actors/dist/xstate-actors.cjs.mjs +1 -8
  12. package/actors/dist/xstate-actors.development.cjs.js +624 -0
  13. package/actors/dist/xstate-actors.development.cjs.mjs +8 -0
  14. package/actors/dist/xstate-actors.development.esm.js +615 -0
  15. package/actors/dist/xstate-actors.esm.js +615 -2
  16. package/actors/dist/xstate-actors.umd.min.js +1 -1
  17. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  18. package/dev/dist/xstate-dev.cjs.js +45 -4
  19. package/{dist/index-0f3fdf0c.cjs.prod.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
  20. package/dev/dist/xstate-dev.development.cjs.mjs +5 -0
  21. package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
  22. package/dev/dist/xstate-dev.esm.js +42 -1
  23. package/dev/dist/xstate-dev.umd.min.js +1 -1
  24. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  25. package/dist/declarations/src/SimulatedClock.d.ts +1 -1
  26. package/dist/declarations/src/State.d.ts +47 -73
  27. package/dist/declarations/src/StateMachine.d.ts +29 -57
  28. package/dist/declarations/src/StateNode.d.ts +36 -33
  29. package/dist/declarations/src/actions/assign.d.ts +11 -2
  30. package/dist/declarations/src/actions/cancel.d.ts +7 -3
  31. package/dist/declarations/src/actions/enqueueActions.d.ts +32 -0
  32. package/dist/declarations/src/actions/log.d.ts +7 -3
  33. package/dist/declarations/src/actions/raise.d.ts +7 -2
  34. package/dist/declarations/src/actions/send.d.ts +14 -36
  35. package/dist/declarations/src/actions/spawnChild.d.ts +29 -0
  36. package/dist/declarations/src/actions/stopChild.d.ts +18 -0
  37. package/dist/declarations/src/actions.d.ts +8 -48
  38. package/dist/declarations/src/actors/callback.d.ts +91 -8
  39. package/dist/declarations/src/actors/index.d.ts +6 -28
  40. package/dist/declarations/src/actors/observable.d.ts +101 -18
  41. package/dist/declarations/src/actors/promise.d.ts +80 -10
  42. package/dist/declarations/src/actors/transition.d.ts +64 -9
  43. package/dist/declarations/src/constants.d.ts +3 -0
  44. package/dist/declarations/src/createMachine.d.ts +20 -0
  45. package/dist/declarations/src/dev/index.d.ts +6 -6
  46. package/dist/declarations/src/guards.d.ts +41 -8
  47. package/dist/declarations/src/index.d.ts +18 -23
  48. package/dist/declarations/src/interpreter.d.ts +149 -41
  49. package/dist/declarations/src/setup.d.ts +51 -0
  50. package/dist/declarations/src/spawn.d.ts +23 -2
  51. package/dist/declarations/src/stateUtils.d.ts +30 -45
  52. package/dist/declarations/src/system.d.ts +26 -2
  53. package/dist/declarations/src/typegenTypes.d.ts +34 -22
  54. package/dist/declarations/src/types.d.ts +527 -669
  55. package/dist/declarations/src/utils.d.ts +15 -52
  56. package/dist/declarations/src/waitFor.d.ts +2 -2
  57. package/dist/log-22e678c5.esm.js +364 -0
  58. package/dist/log-5e226275.cjs.js +372 -0
  59. package/dist/log-641cd926.development.cjs.js +394 -0
  60. package/dist/log-f196f85f.development.esm.js +386 -0
  61. package/dist/raise-34e25c2c.cjs.js +2368 -0
  62. package/dist/raise-62704519.development.cjs.js +2422 -0
  63. package/dist/raise-89c581c4.development.esm.js +2371 -0
  64. package/dist/raise-8bc422d1.esm.js +2317 -0
  65. package/dist/xstate.cjs.js +728 -4
  66. package/dist/xstate.cjs.mjs +9 -9
  67. package/dist/xstate.development.cjs.js +737 -0
  68. package/dist/xstate.development.cjs.mjs +39 -0
  69. package/dist/xstate.development.esm.js +699 -0
  70. package/dist/xstate.esm.js +561 -770
  71. package/dist/xstate.umd.min.js +1 -1
  72. package/dist/xstate.umd.min.js.map +1 -1
  73. package/guards/dist/xstate-guards.cjs.js +12 -5
  74. package/guards/dist/xstate-guards.cjs.mjs +1 -2
  75. package/guards/dist/xstate-guards.development.cjs.js +14 -0
  76. package/guards/dist/xstate-guards.development.cjs.mjs +7 -0
  77. package/guards/dist/xstate-guards.development.esm.js +2 -0
  78. package/guards/dist/xstate-guards.esm.js +2 -2
  79. package/guards/dist/xstate-guards.umd.min.js +1 -1
  80. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  81. package/package.json +53 -1
  82. package/actions/dist/xstate-actions.cjs.dev.js +0 -32
  83. package/actions/dist/xstate-actions.cjs.prod.js +0 -32
  84. package/actions/dynamicAction.ts +0 -42
  85. package/actors/dist/xstate-actors.cjs.dev.js +0 -22
  86. package/actors/dist/xstate-actors.cjs.prod.js +0 -22
  87. package/dev/dist/xstate-dev.cjs.dev.js +0 -11
  88. package/dev/dist/xstate-dev.cjs.prod.js +0 -11
  89. package/dist/actions-b6357569.cjs.dev.js +0 -4437
  90. package/dist/actions-bd4a184d.cjs.prod.js +0 -4423
  91. package/dist/actions-de434a04.esm.js +0 -4348
  92. package/dist/declarations/actions/dynamicAction.d.ts +0 -5
  93. package/dist/declarations/src/Machine.d.ts +0 -4
  94. package/dist/declarations/src/Mailbox.d.ts +0 -12
  95. package/dist/declarations/src/actionTypes.d.ts +0 -16
  96. package/dist/declarations/src/actions/choose.d.ts +0 -3
  97. package/dist/declarations/src/actions/invoke.d.ts +0 -3
  98. package/dist/declarations/src/actions/pure.d.ts +0 -6
  99. package/dist/declarations/src/actions/stop.d.ts +0 -7
  100. package/dist/declarations/src/environment.d.ts +0 -1
  101. package/dist/declarations/src/mapState.d.ts +0 -3
  102. package/dist/declarations/src/memo.d.ts +0 -2
  103. package/dist/index-ebaab3c9.cjs.dev.js +0 -52
  104. package/dist/xstate.cjs.dev.js +0 -950
  105. package/dist/xstate.cjs.prod.js +0 -947
  106. package/guards/dist/xstate-guards.cjs.dev.js +0 -15
  107. package/guards/dist/xstate-guards.cjs.prod.js +0 -15
@@ -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;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,a=t.ActionTypes.Send,o=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 _(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 x(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,a,o,s=[],u=!0,c=!1;try{if(a=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=a.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&&(o=n.return(),Object(o)!==o))return}finally{if(c)throw i}}return s}}(t,e)||_(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 w(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)||_(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=_(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 a,o=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){s=!0,a=t},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}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},E(t)}var T=".",I="",O="",j="*";function A(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:T,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 J(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"===E(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:J(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 a=r[i];n[a]=e(t[a],a,t,i)}return n}function D(t){var e;return(e=[]).concat.apply(e,w(t))}function $(t){return J(t)?t:[t]}function Q(t){return void 0===t?[]:$(t)}function R(t,e,n){if(B(t))return t({context:e,event:n.data});for(var r={},i={context:e,event:n.data},a=0,o=Object.keys(t);a<o.length;a++){var s=o[a],u=t[s];B(u)?r[s]=u(i):r[s]=u}return r}var V=function(){};function J(t){return Array.isArray(t)}function B(t){return"function"==typeof t}function z(t){return"string"==typeof t}function U(t){return"$$type"in t&&"scxml"===t.$$type}function W(t,e){return U(t)?t:b({name:t.type,data:t,$$type:"scxml",type:"external"},e)}function q(t,e){return $(e).map((function(e){return void 0===e||"string"==typeof e?{target:e,event:t}:b(b({},e),{},{event:t})}))}function L(t){if(void 0!==t&&t!==I)return Q(t)}function X(t,e,n){var r=function(){},i="object"===E(t),a=i?t:null;return{next:((i?t.next:t)||r).bind(a),error:((i?t.error:e)||r).bind(a),complete:((i?t.complete:n)||r).bind(a)}}function F(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function G(t,e){return{type:t.type,params:t.params,resolve:e}}function H(t){return"object"===E(t)&&null!==t&&"resolve"in t}function K(e,n){return G({type:a,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 o,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.data,_event:r,self:null!==(o=null==s?void 0:s.self)&&void 0!==o?o: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=W(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:a,params:b(b({},c),{},{to:y,_event:h,event:h.data,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(){var e=t.self,i=b(b({},r),{},{name:r.name===v?"".concat(ye(e.id)):r.name,origin:e});n.send(i)}))}else t.self.delaySend(e)}};return[u,g]}))}function Y(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Z(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 tt(t,e,n){return e&&Z(t.prototype,e),n&&Z(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var et=function(){function t(e){Y(this,t),this._process=e,m(this,"_active",!1),m(this,"_current",null),m(this,"_last",null)}return tt(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}(),nt="function"==typeof Symbol&&Symbol.observable||"@@observable";var rt="xstate.init",it="xstate.stop";function at(t){return t===rt||t===it}function ot(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var st,ut=function(t){var e=ot();e&&e.register(t)};t.InterpreterStatus=void 0,(st=t.InterpreterStatus||(t.InterpreterStatus={}))[st.NotStarted=0]="NotStarted",st[st.Running=1]="Running",st[st.Stopped=2]="Stopped";var ct={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},lt=function(){function e(n,r){var i,a=this;Y(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 et(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 o,s,u,c,l=b(b({},ct),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:(o=0,s=new Map,u=new Map,c=new WeakMap,{_bookId:function(){return"x:".concat(o++)},_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){a._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==a)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(a.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return tt(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 a,o=this.getSnapshot();a=this._deferred.shift();)a(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,o)}}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=pe(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(W(this._doneEvent,{origin:this,invokeid:this.id})),this._complete();break;case"error":this._stopProcedure(),null===(i=this._parent)||void 0===i||i.send(W(ye(this.id,f.data),{origin:this})),this._error(f.data)}}},{key:"subscribe",value:function(e,n,r){var i,a=this,o=X(e,n,r);(this.observers.add(o),this.status===t.InterpreterStatus.Stopped)&&(null===(i=o.complete)||void 0===i||i.call(o),this.observers.delete(o));return{unsubscribe:function(){a.observers.delete(o)}}}},{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===it&&(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(W({type:it})),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 et(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'));var n=W(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)}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:ut)(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:nt,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),e}();function ft(t,e){return new lt(t,e)}function dt(e){var n=e;return G({type:r,params:{actor:n}},(function(e,r){var i=r.state,a=B(n)?n({context:i.context,event:e.data}):n,o="string"==typeof a?i.children[a]:a;return[i,{type:"xstate.stop",params:{actor:o},execute:function(e){o&&(o.status===t.InterpreterStatus.Running?e.defer((function(){e.stopChild(o)})):e.stopChild(o))}}]}))}var vt=function(t){return{context:t.context,event:t.event}};function ht(t){return G({type:o,params:{sendId:t}},(function(e,n){var r,i=n.state,a=n.actorContext,o=B(t)?t({context:i.context,event:e.data,_event:e,self:null!==(r=null==a?void 0:a.self)&&void 0!==r?r:{},system:null==a?void 0:a.system}):t;return[i,{type:"xstate.cancel",params:{sendId:o},execute:function(t){t.self.cancel(o)}}]}))}function pt(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},a=Object.keys(t);for(r=0;r<a.length;r++)n=a[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);for(r=0;r<a.length;r++)n=a[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var yt=new WeakMap;function mt(t,e,n){var r=yt.get(t);return r?e in r||(r[e]=n()):(r=m({},e,n()),yt.set(t,r)),r[e]}function gt(t,e,n,r){var i,a,o,s=r.machine,u=null!==(i=null==s||null===(a=s.options)||void 0===a||null===(o=a.guards)||void 0===o?void 0:o[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:gt})}function bt(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 bt(t,e)})),predicate:(null==e?void 0:e(t.type))||t.predicate}}var St=function(t){return"atomic"===t.type||"final"===t.type};function _t(t){return Object.values(t.states).filter((function(t){return"history"!==t.type}))}function xt(t,e){for(var n=[],r=t.parent;r&&r!==e;)n.push(r),r=r.parent;return n}function wt(t){var e,n=new Set(t),r=new Set(t),i=Et(r),a=k(n);try{for(a.s();!(e=a.n()).done;){var o=e.value;if("compound"!==o.type||i.get(o)&&i.get(o).length){if("parallel"===o.type){var s,u=k(_t(o));try{for(u.s();!(s=u.n()).done;){var c=s.value;if("history"!==c.type&&!r.has(c))for(var l=0,f=Nt(c);l<f.length;l++){var d=f[l];r.add(d)}}}catch(t){u.e(t)}finally{u.f()}}}else Nt(o).forEach((function(t){return r.add(t)}))}}catch(t){a.e(t)}finally{a.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 kt(t,e){var n=e.get(t);if(!n)return{};if("compound"===t.type){var r=n[0];if(!r)return{};if(St(r))return r.key}var i,a={},o=k(n);try{for(o.s();!(i=o.n()).done;){var s=i.value;a[s.key]=kt(s,e)}}catch(t){o.e(t)}finally{o.f()}return a}function Et(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 Tt(t,e){return kt(t,Et(wt(e)))}function It(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t[0].machine.root;return"compound"===e.type?_t(e).some((function(e){return"final"===e.type&&t.includes(e)})):"parallel"===e.type&&_t(e).every((function(e){return It(t,e)}))}var Ot=function(t){return"#"===t[0]};function jt(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(le({type:i},{delay:n})),e.exit.push(ht(i)),i};return(J(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],a=z(i)?{target:i}:i,o=isNaN(+t)?t:+t,s=r(o,e);return Q(a).map((function(t){return b(b({},t),{},{event:s,delay:o})}))}))).map((function(t){var n=t.delay;return b(b({},At(e,t)),{},{delay:n})}))}function At(t,e){var n,r=L(e.target),i=null!==(n=e.reenter)&&void 0!==n&&n,a=t.machine.options.guards,o=Pt(t,r),s=b(b({},e),{},{actions:ve(Q(e.actions)),guard:e.guard?bt(e.guard,(function(t){return a[t]})):void 0,target:o,source:t,reenter:i,eventType:e.event,toJSON:function(){return b(b({},s),{},{source:"#".concat(t.id),target:o?o.map((function(t){return"#".concat(t.id)})):void 0})}});return s}function Pt(t,e){if(void 0!==e)return e.map((function(e){if(!z(e))return e;if(Ot(e))return t.machine.getStateNodeById(e);var n=e[0]===t.machine.delimiter;if(n&&!t.parent)return $t(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 $t(t.parent,r)}catch(e){throw new Error("Invalid transition definition for state node '".concat(t.id,"':\n").concat(e.message))}}))}function Ct(t){var e=L(t.target);return e?e.map((function(e){return"string"==typeof e?$t(t.parent,e):e})):t.parent.initial.target}function Mt(t){return"history"===t.type}function Nt(t){var e=new Set;return function n(r){if(!e.has(r))if(e.add(r),"compound"===r.type){var i,a=k(r.initial.target);try{for(a.s();!(i=a.n()).done;){var o,s=i.value,u=k(xt(s,t));try{for(u.s();!(o=u.n()).done;){var c=o.value;e.add(c)}}catch(t){u.e(t)}finally{u.f()}n(s)}}catch(t){a.e(t)}finally{a.f()}}else if("parallel"===r.type){var l,f=k(_t(r));try{for(f.s();!(l=f.n()).done;){n(l.value)}}catch(t){f.e(t)}finally{f.f()}}}(t),w(e)}function Dt(t,e){if(Ot(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 $t(t,e){if("string"==typeof e&&Ot(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=Dt(r,i)}return r}function Qt(t,e){var n=e instanceof oe?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 Dt(t,e)})).filter(Boolean);return[t.machine.root,t].concat(i,r.reduce((function(e,r){var i=Dt(t,r);if(!i)return e;var a=Qt(i,n[r]);return e.concat(a)}),[]))}function Rt(t,e,n,r){return z(e)?function(t,e,n,r){var i=Dt(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),a=Rt(Dt(t,i[0]),e[i[0]],n,r);return a&&a.length?a:t.next(n,r)}(t,e,n,r):function(t,e,n,r){for(var i=[],a=0,o=Object.keys(e);a<o.length;a++){var s=o[a],u=e[s];if(u){var c=Rt(Dt(t,s),u,n,r);c&&i.push.apply(i,w(c))}}return i.length?i:t.next(n,r)}(t,e,n,r)}function Vt(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 Bt(t,e){var n,r=new Set(t),i=new Set(e),a=k(r);try{for(a.s();!(n=a.n()).done;){var o=n.value;if(i.has(o))return!0}}catch(t){a.e(t)}finally{a.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 zt(t,e,n){var r,i=new Set,a=k(t);try{for(a.s();!(r=a.n()).done;){var o,s=r.value,u=!1,c=new Set,l=k(i);try{for(l.s();!(o=l.n()).done;){var f=o.value;if(Bt(qt([s],e,n),qt([f],e,n))){if(!Vt(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){a.e(t)}finally{a.f()}return Array.from(i)}function Ut(t,e){if(!t.target)return[];var n,r=new Set,i=k(t.target);try{for(i.s();!(n=i.n()).done;){var a=n.value;if(Mt(a))if(e[a.id]){var o,s=k(e[a.id]);try{for(s.s();!(o=s.n()).done;){var u=o.value;r.add(u)}}catch(t){s.e(t)}finally{s.f()}}else{var c,l=k(Ut({target:Ct(a)},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(a)}}catch(t){i.e(t)}finally{i.f()}return w(r)}function Wt(t,e){var n=Ut(t,e);return n?!t.reenter&&"parallel"!==t.source.type&&n.every((function(e){return Vt(e,t.source)}))?t.source:function(t){var e,n=Jt(x(t,1)[0]),r=[],i=k(t);try{var a=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;)a()}catch(t){i.e(t)}finally{i.f()}return n[n.length-1]}(n.concat(t.source)):null}function qt(t,e,n){var r,i=new Set,a=k(t);try{for(a.s();!(r=a.n()).done;){var o,s=r.value;if(null!==(o=s.target)&&void 0!==o&&o.length){var u,c=Wt(s,n),l=k(e);try{for(l.s();!(u=l.n()).done;){var f=u.value;Vt(f,c)&&i.add(f)}}catch(t){l.e(t)}finally{l.f()}}}}catch(t){a.e(t)}finally{a.f()}return w(i)}function Lt(t,e,n,i){var a=e.machine,o=e._initial||t.length>0,s=new Set(e.configuration);if(!e._initial&&!o){var u=se(e,{_event:i,actions:[],transitions:[]});return u.changed=!1,u}var c=function(t,e,n,r,i){var a=e.machine,o=[],s=b({},e.historyValue),u=zt(t,n,s),c=w(e._internalQueue);e._initial||function(t,e,n,r){var i=qt(t,e,n);i.sort((function(t,e){return e.order-t.order}));var a,o=k(i);try{var s=function(){var t,r,i=a.value,o=k((r=i,Object.keys(r.states).map((function(t){return r.states[t]})).filter((function(t){return"history"===t.type}))));try{for(o.s();!(t=o.n()).done;){var s=t.value,u=void 0;u="deep"===s.history?function(t){return St(t)&&Vt(t,i)}:function(t){return t.parent===i},n[s.id]=Array.from(e).filter(u)}}catch(t){o.e(t)}finally{o.f()}};for(o.s();!(a=o.n()).done;)s()}catch(t){o.e(t)}finally{o.f()}var u,c=k(i);try{for(c.s();!(u=c.n()).done;){var l=u.value;r.push.apply(r,w(l.exit.flat()).concat(w(l.invoke.map((function(t){return dt(t.id)}))))),e.delete(l)}}catch(t){c.e(t)}finally{c.f()}}(u,n,s,o);o.push.apply(o,w(u.flatMap((function(t){return t.actions})))),Xt(u,n,o,c,e,s);var l=w(n),f=It(l);if(f){var d=l.sort((function(t,e){return e.order-t.order})).flatMap((function(t){return t.exit}));o.push.apply(o,w(d))}try{var v=Kt(o,r,e,i).nextState,h=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?R(i.output,e,n):void 0}(l,v.context,r):void 0;return c.push.apply(c,w(v._internalQueue)),se(e,{actions:v.actions,configuration:l,historyValue:s,_internalQueue:c,context:v.context,_event:r,done:f,output:h,children:v.children})}catch(t){if(a.config.scxml)return se(e,{actions:[],configuration:Array.from(n),historyValue:s,_internalQueue:[W({type:"error.execution"})],context:e.context});throw t}}(e._initial?[{target:w(e.configuration).filter(St),source:a.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),a=k(e);try{for(a.s();!(n=a.n()).done;){var o=n.value;if(o.type===l&&o.params.ref){var s=o.params.ref;s&&(i[s.id]=s)}else if(o.type===r){var u=o.params.actor;u&&delete i[u.id]}}}catch(t){a.e(t)}finally{a.f()}return i}(e,c.actions),v=se(c,{value:{},transitions:t,children:d});return v.changed=e._initial?void 0:!re(v.value,e.value)||v.actions.length>0||f!==e.context,v}function Xt(t,e,n,r,i,a){var o=new Set,s=new Set;Ft(t,a,s,o),i._initial&&s.add(i.machine.root);var u,c=k(w(o).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(ue(v))}}catch(t){d.e(t)}finally{d.f()}if(n.push.apply(n,w(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,w(y))}}catch(t){p.e(t)}finally{p.f()}}if("final"===l.type){var m=l.parent;if(!m.parent)continue;if(r.push(W(he(m.id,l.output?R(l.output,i.context,i._event):void 0))),m.parent){var g=m.parent;"parallel"===g.type&&_t(g).every((function(t){return It(w(e),t)}))&&r.push(W(he(g.id)))}}}}catch(t){c.e(t)}finally{c.f()}}function Ft(t,e,n,r){var i,a=k(t);try{for(a.s();!(i=a.n()).done;){var o,s=i.value,u=k(s.target||[]);try{for(u.s();!(o=u.n()).done;){Gt(o.value,e,n,r)}}catch(t){u.e(t)}finally{u.f()}var c,l=Wt(s,e),f=k(Ut(s,e));try{for(f.s();!(c=f.n()).done;){Ht(c.value,l,r,e,n)}}catch(t){f.e(t)}finally{f.f()}}}catch(t){a.e(t)}finally{a.f()}}function Gt(t,e,n,r){if(Mt(t))if(e[t.id]){var i,a=e[t.id],o=k(a);try{for(o.s();!(i=o.n()).done;){Gt(i.value,e,n,r)}}catch(t){o.e(t)}finally{o.f()}var s,u=k(a);try{for(u.s();!(s=u.n()).done;){Ht(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=Ct(t),h=k(v);try{for(h.s();!(d=h.n()).done;){Gt(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;){Ht(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,_=t.initial.target,x=k(_);try{for(x.s();!(S=x.n()).done;){Gt(S.value,e,n,r)}}catch(t){x.e(t)}finally{x.f()}var E,T=k(_);try{for(T.s();!(E=T.n()).done;){Ht(E.value,t,r,e,n)}}catch(t){T.e(t)}finally{T.f()}}else if("parallel"===t.type){var I,O=k(_t(t).filter((function(t){return!Mt(t)})));try{var j=function(){var t=I.value;w(r).some((function(e){return Vt(e,t)}))||Gt(t,e,n,r)};for(O.s();!(I=O.n()).done;)j()}catch(t){O.e(t)}finally{O.f()}}}function Ht(t,e,n,r,i){var a,o=k(xt(t,e));try{for(o.s();!(a=o.n()).done;){var s=a.value;if(n.add(s),"parallel"===s.type){var u,c=k(_t(s).filter((function(t){return!Mt(t)})));try{var l=function(){var t=u.value;w(n).some((function(e){return Vt(e,t)}))||Gt(t,r,i,n)};for(c.s();!(u=c.n()).done;)l()}catch(t){c.e(t)}finally{c.f()}}}}catch(t){o.e(t)}finally{o.f()}}function Kt(e,n,r,o){var s=r.machine,u=[],c=[],l=r;function f(e){var n;(u.push(e),(null==o?void 0:o.self.status)===t.InterpreterStatus.Running)&&(null===(n=e.execute)||void 0===n||n.call(e,o),delete e.execute)}function d(t){var e=function(t,e){if(H(t))return t;var n,r=e[t.type];return"function"==typeof r?G({type:"xstate.function",params:null!==(n=t.params)&&void 0!==n?n:{}},(function(e,n){var i=n.state,a={type:t.type,params:t.params,execute:function(t){return r({context:i.context,event:e.data,action:a,_event:e,system:t.system,self:t.self})}};return[i,a]})):r||t}(t,s.options.actions);if(H(e)){var r,u=x(e.resolve(n,{state:l,action:t,actorContext:o}),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===a&&h.params.internal)&&"number"!=typeof h.params.delay&&c.push(h),h.type!==p&&f(h),void ve(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:se(l,{actions:u,_internalQueue:c.map((function(t){return t.params._event}))})}}function Yt(t,e,n){var r=t,i=[];if((null==e?void 0:e.name)===it)return r=Zt(e,r,n),i.push(r),{state:r,microstates:i};e.name!==c&&(r=Lt(te(e,r),t,n,e),i.push(r));for(;!r.done;){var a=ee(r);if(0===a.length){if(r.configuration.some((function(t){return t.always}))&&(r.transitions=[]),!r._internalQueue.length)break;var o,s=r.actions,u=r._internalQueue[0];(r=Lt(te(u,r),r,n,u))._internalQueue.shift(),(o=r.actions).unshift.apply(o,w(s)),i.push(r)}if(a.length){var l,f=r.actions;(l=(r=Lt(a,r,n,r._event)).actions).unshift.apply(l,w(f)),i.push(r)}}return r.done&&Zt(r._event,r,n),{state:r,microstates:i}}function Zt(t,e,n){var r,i=[],a=k(e.configuration.sort((function(t,e){return e.order-t.order})));try{for(a.s();!(r=a.n()).done;){var o=r.value;i.push.apply(i,w(o.exit))}}catch(t){a.e(t)}finally{a.f()}for(var s=0,u=Object.values(e.children);s<u.length;s++){var c=u[s];i.push(dt(c))}return Kt(i,t,e,n).nextState}function te(t,e){return e.machine.getTransitionData(e,t)}function ee(t){var e,n=new Set,r=k(t.configuration.filter(St));try{for(r.s();!(e=r.n()).done;){var i,a=e.value,o=k([a].concat(xt(a,null)));try{t:for(o.s();!(i=o.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||gt(l.guard,t.context,t._event,t)){n.add(l);break t}}}catch(t){c.e(t)}finally{c.f()}}}}catch(t){o.e(t)}finally{o.f()}}}catch(t){r.e(t)}finally{r.f()}return zt(Array.from(n),new Set(t.configuration),t.historyValue)}function ne(t,e){return Tt(t,w(wt(Qt(t,e))))}function re(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 re(t[n],e[n])}))}var ie=["configuration","transitions","tags","machine"],ae=["configuration","transitions","tags","machine","children"],oe=function(){function t(e,n){var r,i,a,o;Y(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!==(a=e.configuration)&&void 0!==a?a:Array.from(wt(Qt(n.root,e.value))),this.transitions=e.transitions,this.children=e.children,this.value=Tt(n.root,this.configuration),this.tags=new Set(D(this.configuration.map((function(t){return t.tags})))),this.done=null!==(o=e.done)&&void 0!==o&&o,this.output=e.output}return tt(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,w(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({},pt(this,ie)),{},{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){V(!!this.machine,"state.can(...) used outside of a machine-created State object; this will always return false.");var e=this.machine.getTransitionData(this,W(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 mt(this,"nextEvents",(function(){return w(new Set(D(w(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=me({}),a=wt(Qt(r.root,e));return new t({value:e,context:n,_event:i,actions:[],meta:void 0,configuration:Array.from(a),transitions:[],children:{}},r)}}]),t}();function se(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new oe(b(b({},t),e),t.machine)}function ue(e){return G({type:l,params:e},(function(n,r){var i,a,o=r.state,s=r.actorContext,u=l,c=e.id,f=e.src;if((a=f)&&"object"===E(a)&&"function"==typeof a.send)i={type:u,params:b(b({},e),{},{ref:f})};else{var d=F(o.machine.options.actors[f]);if(d){var v="input"in e?e.input:d.input,h=ft(d.src,{id:c,src:f,parent:null==s?void 0:s.self,systemId:e.systemId,input:"function"==typeof v?v({context:o.context,event:n.data,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=se(o,{children:b(b({},o.children),{},m({},c,p))});return i.execute=function(e){var n=e.self,r=i.params,a=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(ye(a,t))}}))},[y,i]}))}function ce(t,e,n,r,i){return function(a){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(z(a)){var s=F(e.options.actors[a]);if(s){var u,c=null!==(u=o.id)&&void 0!==u?u:"anon",l="input"in o?o.input:s.input,f=ft(s.src,{id:c,parent:t,input:"function"==typeof l?l({context:n,event:r.data,self:t}):l});return i.push(ue({id:f.id,src:f,ref:f,meta:void 0,input:l})),f}throw new Error("Behavior '".concat(a,"' not implemented in machine '").concat(e.id,"'"))}var d=ft(a,{id:o.id||"anonymous",parent:t,input:o.input});return i.push(ue({src:d,ref:d,id:d.id,meta:void 0,input:o.input})),d}}function le(t,e){return G({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 a,o=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:o.context,event:n.data,_event:n,self:null!==(a=null==s?void 0:s.self)&&void 0!==a?a:{},system:null==s?void 0:s.system},l=o.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=W("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,event:d.data,delay:f}),execute:function(t){"number"!=typeof h.params.delay||t.self.delaySend(h)}};return[o,h]}))}var fe=W({type:c});function de(t){if(H(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){var e="xstate.function";return G({type:e,params:{}},(function(n,r){var i=r.state,a={type:e,params:{function:t},execute:function(e){return t({context:i.context,event:n.data,action:a,_event:n,self:e.self,system:e.system})}};return[i,a]}))}return t}var ve=function(t){return t?(J(t)?t:[t]).map(de):[]};function he(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function pe(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function ye(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function me(t){return W({type:c,input:t})}var ge=["onDone","onError"],be={},Se=function(){function t(e,n){var r=this;if(Y(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(w(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})})):be,"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=ve(this.config.entry),this.exit=ve(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=Q(e.tags)}return tt(t,[{key:"_initialize",value:function(){var t=this;this.transitions=function(t){var e=[];if(Array.isArray(t.config.on))e.push.apply(e,w(t.config.on));else if(t.config.on){for(var n=t.config.on,r=n[j],i=void 0===r?[]:r,a=pt(n,[j].map(y)),o=0,s=Object.keys(a);o<s.length;o++){var u=s[o];if(u===O)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');var c=q(u,a[u]);e.push.apply(e,w(c))}e.push.apply(e,w(q(j,i)))}var l,f=t.config.onDone?q(String(he(t.id)),t.config.onDone):[],d=t.invoke.flatMap((function(t){var e=[];return t.onDone&&e.push.apply(e,w(q("done.invoke.".concat(t.id),t.onDone))),t.onError&&e.push.apply(e,w(q("error.platform.".concat(t.id),t.onError))),t.onSnapshot&&e.push.apply(e,w(q("xstate.snapshot.".concat(t.id),t.onSnapshot))),e})),v=t.after,h=[].concat(w(f),w(d),e).flatMap((function(e){return Q(e).map((function(e){return At(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=q(O,this.config.always).map((function(e){return At(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 mt(this,"invoke",(function(){return Q(t.config.invoke).map((function(e,n){var r,i,a=(r=t.id,i=n,"".concat(r,":invocation[").concat(i,"]")),o=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,a),s=o.id||a,u=o.src,c=o.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},o),{},{src:f,id:s,systemId:c,toJSON:function(){return o.onDone,o.onError,b(b({},pt(o,ge)),{},{type:l,src:f,id:s})}})}))}))}},{key:"on",get:function(){var t=this;return mt(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 mt(this,"delayedTransitions",(function(){return jt(t)}))}},{key:"initial",get:function(){var t=this;return mt(this,"initial",(function(){return function(t,e){if(z(e)||J(e)){var n=Q(e).map((function(e){var n=z(e)?Ot(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(!Vt(n,t))throw new Error("Invalid initial target: state node #".concat(n.id," is not a descendant of #").concat(t.id));return n})),r=Pt(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 At(t,{target:Q(e.target).map((function(e){return z(e)?Ot(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,a=e.name,o=[],s=mt(this,"candidates-".concat(a.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===j)return!0;if(!n&&!r.endsWith(".*"))return!1;for(var i=r.split("."),a=e.split("."),o=0;o<i.length;o++){var s=i[o],u=a[o];if("*"===s)return o===i.length-1;if(s!==u)return!1}return!0}))}(i,a,i.machine.config.scxml)})),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||gt(l,f,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(l.type,"' in transition for event '").concat(a,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(d){o.push.apply(o,w(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 mt(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 a=e[i[r]];if(a.states){var o,s=k(a.events);try{for(s.s();!(o=s.n()).done;){var u=o.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 _e=function(){function t(e,n){var r;Y(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||T,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 Se(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}return tt(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:ce(null==t?void 0:t.self,this,void 0,me(e),n),input:e}):r)||{},n]}},{key:"provide",value:function(e){var n=this.options,r=n.actions,i=n.guards,a=n.actors,o=n.delays;return new t(this.config,{actions:b(b({},r),e.actions),guards:b(b({},i),e.guards),actors:b(b({},a),e.actors),delays:b(b({},o),e.delays)})}},{key:"resolveState",value:function(t){var e=wt(Qt(this.root,t.value)),n=Array.from(e);return this.createState(b(b({},t),{},{value:ne(this.root,t.value),configuration:n,done:It(n)}))}},{key:"resolveStateValue",value:function(t){var e=ne(this.root,t),n=this.getContext();return this.resolveState(oe.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 oe?t:this.resolveStateValue(t),i=W(e);if(function(t){return"string"==typeof t.name&&(t.name===f||t.name.startsWith(d))}(i)&&!r.nextEvents.some((function(t){return t===i.name})))throw i.data.data;return Yt(r,i,n).state}},{key:"microstep",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,e=arguments.length>2?arguments[2]:void 0;return Yt(t,W(arguments.length>1?arguments[1]:void 0),e).microstates}},{key:"getTransitionData",value:function(t,e){return Rt(this.root,t.value,t,e)||[]}},{key:"getPreInitialState",value:function(t,e){var n,r=x(this.getContextAndActions(t,e),2),i=r[0],a=r[1],o=function(t){var e=[],n=t.initial,r=new Set;Ft([n],{},new Set([t]),r);var i,a=k(w(r).sort((function(t,e){return t.order-e.order})));try{for(a.s();!(i=a.n()).done;){var o=i.value;e.push(o)}}catch(t){a.e(t)}finally{a.f()}return e}(this.root),s=this.resolveState(this.createState({value:{},context:i,_event:me({}),actions:[],meta:void 0,configuration:o,transitions:[],children:{}}));if(s._initial=!0,(n=s.actions).unshift.apply(n,w(a)),t){var u=Kt(a,fe,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=me(e),i=this.getPreInitialState(t,e),a=Lt([],i,t,r);return(n=a.actions).unshift.apply(n,w(i.actions)),Yt(a,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(ye(t.id,n))}}))}},{key:"getStateNodeById",value:function(t){var e=t.split(this.delimiter),n=e.slice(1),r=Ot(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 $t(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=pt(t,ae),r={};for(var i in e){var a,o;r[i]={state:null===(a=(o=e[i]).getPersistedState)||void 0===a?void 0:a.call(o),src:e[i].src}}return b(b({},n),{},{children:r})}(t)}},{key:"createState",value:function(t){var e=t instanceof oe?t:new oe(t,this);return Kt(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 a,o,s=t.children[i],u=s.state,c=s.src,l=c?null===(a=F(n.options.actors[c]))||void 0===a?void 0:a.src:void 0;if(l){var f=ft(l,{id:i,state:null===(o=l.restoreState)||void 0===o?void 0:o.call(l,u,e)});r[i]=f}}));var i=this.createState(new oe(b(b({},t),{},{children:r}),this));return i.configuration.forEach((function(t){t.invoke&&t.invoke.forEach((function(t){var i=t.id,a=t.src;if(!r[i]){var o=F(n.options.actors[a]);if(o){var s=ft(o.src,{id:i,parent:null==e?void 0:e.self,input:"input"in t?t.input:o.input});r[i]=s}}}))})),i.actions=[],i}}]),t}();var xe=function(){function t(){Y(this,t),m(this,"timeouts",new Map),m(this,"_now",0),m(this,"_id",0)}return tt(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;w(this.timeouts).sort((function(t,e){var n=x(t,2);n[0];var r=n[1],i=x(e,2);i[0];var a=i[1],o=r.start+r.timeout;return a.start+a.timeout>o?-1:1})).forEach((function(e){var n=x(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}(),we={timeout:1e4};t.Interpreter=lt,t.SimulatedClock=xe,t.State=oe,t.StateMachine=_e,t.StateNode=Se,t.and=function(t){return{type:"xstate.boolean",params:{op:"and"},children:t.map((function(t){return bt(t)})),predicate:function(t){var e=t.evaluate,n=t.guard,r=t.context,i=t._event,a=t.state;return n.children.every((function(t){return e(t,r,i,a)}))}}},t.assign=function(t){return G({type:s,params:{assignment:t}},(function(e,n){var r,i=n.state,a=n.action,o=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:a,_event:e,spawn:ce(null==o?void 0:o.self,i.machine,i.context,e,u),self:null!==(r=null==o?void 0:o.self)&&void 0!==r?r:{},system:null==o?void 0:o.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[se(i,{context:p}),{type:s,params:{context:p,actions:u}}]}))},t.cancel=ht,t.choose=function(t){return G({type:h,params:{guards:t}},(function(e,n){var r,i=n.state,a=null===(r=t.find((function(t){var n=t.guard&&bt(t.guard,(function(t){return i.machine.options.guards[t]}));return!n||gt(n,i.context,e,i)})))||void 0===r?void 0:r.actions;return[i,{type:h,params:{actions:ve(a)}}]}))},t.createMachine=function(t,e){return new _e(t,e)},t.doneInvoke=pe,t.forwardTo=function(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 K((function(t){return t.event}),b(b({},e),{},{to:t}))},t.fromCallback=function(t){return{start:function(t,e){e.self.send({type:rt})},transition:function(e,n,r){var i,a=r.self,o=r.id,s=W(n);if(s.name===rt){return e.dispose=t((function(t){var n;e.canceled||null===(n=a._parent)||void 0===n||n.send(W(t,{origin:a}))}),(function(t){e.receivers.add(t)}),{input:e.input}),((i=e.dispose)instanceof Promise||null!==i&&(B(i)||"object"===E(i))&&B(i.then))&&e.dispose.then((function(t){var n;null===(n=a._parent)||void 0===n||n.send(W(pe(o,t),{origin:a})),e.canceled=!0}),(function(t){var n,r=ye(o,t);null===(n=a._parent)||void 0===n||n.send(W(r,{origin:a})),e.canceled=!0})),e}if(s.name===it)return e.canceled=!0,B(e.dispose)&&e.dispose(),e;if(at(s.name))return e;var u=U(n)?n.data:n;return at(u.type)||e.receivers.forEach((function(t){return t(u)})),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{transition:function(t,r){var i=W(r);if("active"!==t.status)return t;switch(i.name){case e:return b(b({},t),{},{status:"error",input:void 0,data:i.data.data,subscription:void 0});case n:return b(b({},t),{},{status:"done",input:void 0,subscription:void 0});case it: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 a=i.self;"done"!==r.status&&(r.subscription=t({input:r.input}).subscribe({next:function(t){var e;null===(e=a._parent)||void 0===e||e.send(W(t,{origin:a}))},error:function(t){a.send({type:e,data:t})},complete:function(){a.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{transition:function(t,i,a){var o=a.self,s=a.id,u=a.defer,c=W(i);if("active"!==t.status)return t;switch(c.name){case e:return u((function(){var t;null===(t=o._parent)||void 0===t||t.send(W({type:"xstate.snapshot.".concat(s),data:c.data.data},{origin:o}))})),b(b({},t),{},{data:i.data.data});case n:return b(b({},t),{},{status:"error",input:void 0,data:c.data.data,subscription:void 0});case r:return b(b({},t),{},{status:"done",input:void 0,subscription:void 0});case it: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,a){var o=a.self;"done"!==i.status&&(i.subscription=t({input:i.input}).subscribe({next:function(t){o.send({type:e,data:t})},error:function(t){o.send({type:n,data:t})},complete:function(){o.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{transition:function(t,r){var i=W(r);if("active"!==t.status)return t;var a=i.data;switch(i.name){case e:return b(b({},t),{},{status:"done",data:a.data,input:void 0});case n:return b(b({},t),{},{status:"error",data:a.data,input:void 0});case it:return b(b({},t),{},{status:"canceled",input:void 0});default:return t}},start:function(r,i){var a=i.self;"active"===r.status&&Promise.resolve(t({input:r.input})).then((function(t){"active"===a._state.status&&a.send({type:e,data:t})}),(function(t){"active"===a._state.status&&a.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{transition:function(e,n,r){var i=U(n)?n.data:n;return t(e,i,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=Qt,t.interpret=ft,t.log=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:vt,e=arguments.length>1?arguments[1]:void 0;return G({type:u,params:{label:e,expr:t}},(function(n,r){var i,a=r.state,o=r.actorContext,s="function"==typeof t?t({context:a.context,event:n.data,_event:n,self:null!==(i=null==o?void 0:o.self)&&void 0!==i?i:{},system:null==o?void 0:o.system}):t;return[a,{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 a=i[r];A(a,e)&&(!n||e.length>n.length)&&(n=a)}return t[n]},t.matchesState=A,t.not=function(t){return{type:"xstate.boolean",params:{op:"not"},children:[bt(t)],predicate:function(t){var e=t.evaluate,n=t.guard,r=t.context,i=t._event,a=t.state;return!e(n.children[0],r,i,a)}}},t.or=function(t){return{type:"xstate.boolean",params:{op:"or"},children:t.map((function(t){return bt(t)})),predicate:function(t){var e=t.evaluate,n=t.guard,r=t.context,i=t._event,a=t.state;return n.children.some((function(t){return e(t,r,i,a)}))}}},t.pathToStateValue=M,t.pure=function(t){return G({type:p,params:{get:t}},(function(e,n){var r,i=n.state;return[i,{type:p,params:{actions:null!==(r=Q(ve(t({context:i.context,event:e.data}))))&&void 0!==r?r:[]}}]}))},t.raise=le,t.sendParent=function(e,n){return K(e,b(b({},n),{},{to:t.SpecialTargets.Parent}))},t.sendTo=function(t,e,n){return K(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)&&Ot(t)?n.configuration.some((function(e){return e.id===t.slice(1)})):n.matches(t)}}},t.stop=dt,t.toObserver=X,t.toSCXMLEvent=W,t.waitFor=function(t,e,n){var r=b(b({},we),n);return new Promise((function(n,i){var a=!1,o=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(o),a=!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"))}});a&&c.unsubscribe()}))},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";class e{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const s=".",n="",o="",i="xstate.init",r="xstate.error",a="xstate.stop";function c(t,e){return{type:`xstate.done.state.${t}`,output:e}}function u(t,e){return{type:`xstate.error.actor.${t}`,error:e}}function h(t){return{type:i,input:t}}function f(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const d=t=>{const e=f();e&&e.register(t)};function p(t){setTimeout((()=>{throw t}))}const l="function"==typeof Symbol&&Symbol.observable||"@@observable";let y=0;function v(t,e){const s=m(t),n=m(e);return"string"==typeof n?"string"==typeof s&&n===s:"string"==typeof s?s in n:Object.keys(s).every((t=>t in n&&v(s[t],n[t])))}function g(t){return k(t)?t:t.split(s)}function m(t){if(Pt(t))return t.value;if("string"!=typeof t)return t;return _(g(t))}function _(t){if(1===t.length)return t[0];const e={};let s=e;for(let e=0;e<t.length-1;e++)if(e===t.length-2)s[t[e]]=t[e+1];else{const n=s;s={},n[t[e]]=s}return e}function b(t,e){const s={},n=Object.keys(t);for(let o=0;o<n.length;o++){const i=n[o];s[i]=e(t[i],i,t,o)}return s}function S(t){return k(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(t,e,s,n){return"function"==typeof t?t({context:e,event:s,self:n}):t}function k(t){return Array.isArray(t)}function I(t){return S(t).map((t=>void 0===t||"string"==typeof t?{target:t}:t))}function $(t){if(void 0!==t&&t!==n)return x(t)}function E(t,e,s){const n="object"==typeof t,o=n?t:void 0;return{next:(n?t.next:t)?.bind(o),error:(n?t.error:e)?.bind(o),complete:(n?t.complete:s)?.bind(o)}}function T(t,e){return`${e}.${t}`}function O(t,e){const s=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return t.implementations.actors[e];const[,n,o]=s,i=t.getStateNodeById(o).config.invoke;return(Array.isArray(i)?i[n]:i).src}const M=1;let j=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const N={clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class A{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new e(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this._processingStatus=j.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...N,...s},{clock:o,logger:i,parent:r,syncSnapshot:a,id:c,systemId:u,inspect:h}=n;this.system=r?.system??function(t){const e=new Map,s=new Map,n=new WeakMap,o=new Set,i={_bookId:()=>"x:"+y++,_register:(t,s)=>(e.set(t,s),t),_unregister:t=>{e.delete(t.sessionId);const o=n.get(t);void 0!==o&&(s.delete(o),n.delete(t))},get:t=>s.get(t),_set:(t,e)=>{const o=s.get(t);if(o&&o!==e)throw new Error(`Actor with system ID '${t}' already exists.`);s.set(t,e),n.set(e,t)},inspect:t=>{o.add(t)},_sendInspectionEvent:e=>{const s={...e,rootId:t.sessionId};o.forEach((t=>t.next?.(s)))},_relay:(t,e,s)=>{i._sendInspectionEvent({type:"@xstate.event",sourceRef:t,actorRef:e,event:s}),e._send(s)}};return i}(this),h&&!r&&this.system.inspect(E(h)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=i,this.clock=o,this._parent=r,this._syncSnapshot=a,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),u&&(this._systemId=u,this.system._set(u,this)),this._initState(s?.snapshot??s?.state),u&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(t){this._snapshot={status:"error",output:void 0,error:t}}}update(t,e){let s;for(this._snapshot=t;s=this._deferred.shift();)try{s()}catch(e){this._deferred.length=0,this._snapshot={...t,status:"error",error:e}}switch(this._snapshot.status){case"active":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}break;case"done":for(const e of this.observers)try{e.next?.(t)}catch(t){p(t)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,o=this._snapshot.output,{type:`xstate.done.actor.${n}`,output:o}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}var n,o;this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:e,snapshot:t})}subscribe(t,e,s){const n=E(t,e,s);if(this._processingStatus!==j.Stopped)this.observers.add(n);else try{n.complete?.()}catch(t){p(t)}return{unsubscribe:()=>{this.observers.delete(n)}}}start(){if(this._processingStatus===j.Running)return this;this._syncSnapshot&&this.subscribe({next:t=>{"active"===t.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:t})},error:()=>{}}),this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this._processingStatus=j.Running;const t=h(this.options.input);this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t});switch(this._snapshot.status){case"done":return this.update(this._snapshot,t),this;case"error":return this._error(this._snapshot.error),this}if(this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(t){return this._snapshot={...this._snapshot,status:"error",error:t},this._error(t),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let e,s;try{e=this.logic.transition(this._snapshot,t,this._actorScope)}catch(t){s={err:t}}if(s){const{err:t}=s;return this._snapshot={...this._snapshot,status:"error",error:t},void this._error(t)}this.update(e,t),t.type===a&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===j.Stopped?this:(this.mailbox.clear(),this._processingStatus===j.NotStarted?(this._processingStatus=j.Stopped,this):(this.mailbox.enqueue({type:a}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(t){p(t)}this.observers.clear()}_reportError(t){if(!this.observers.size)return void(this._parent||p(t));let e=!1;for(const s of this.observers){const n=s.error;e||=!n;try{n?.(t)}catch(t){p(t)}}this.observers.clear(),e&&p(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,u(this.id,t))}_stopProcedure(){if(this._processingStatus!==j.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new e(this._process.bind(this)),this._processingStatus=j.Stopped,this.system._unregister(this),this}_send(t){this._processingStatus!==j.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}delaySend(t){const{event:e,id:s,delay:n}=t,o=this.clock.setTimeout((()=>{this.system._relay(this,t.to??this,e)}),n);s&&(this.delayedEventsMap[s]=o)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:d)(this)}}toJSON(){return{xstate$$type:M,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[l](){return this}getSnapshot(){return this._snapshot}}function P(t,e){return new A(t,e)}const R=P;function C(t,e,s,n,{sendId:o}){return[e,"function"==typeof o?o(s,n):o]}function D(t,e){t.self.cancel(e)}function J(t){function e(t,e){}return e.type="xstate.cancel",e.sendId=t,e.resolve=C,e.execute=D,e}function V(t,e,s,n,{id:o,systemId:i,src:r,input:a,syncSnapshot:c}){const u="string"==typeof r?O(e.machine,r):r,h="function"==typeof o?o(s):o;let f;return u&&(f=P(u,{id:h,src:r,parent:t?.self,syncSnapshot:c,systemId:i,input:"function"==typeof a?a({context:e.context,event:s.event,self:t?.self}):a})),[qt(e,{children:{...e.children,[h]:f}}),{id:o,actorRef:f}]}function B(t,{id:e,actorRef:s}){s&&t.defer((()=>{s._processingStatus!==j.Stopped&&s.start()}))}function q(...[t,{id:e,systemId:s,input:n,syncSnapshot:o=!1}={}]){function i(t,e){}return i.type="snapshot.spawnChild",i.id=e,i.systemId=s,i.src=t,i.input=n,i.syncSnapshot=o,i.resolve=V,i.execute=B,i}function z(t,e,s,n,{actorRef:o}){const i="function"==typeof o?o(s,n):o,r="string"==typeof i?e.children[i]:i;let a=e.children;return r&&(a={...a},delete a[r.id]),[qt(e,{children:a}),r]}function W(t,e){e&&(t.system._unregister(e),e._processingStatus===j.Running?t.defer((()=>{t.stopChild(e)})):t.stopChild(e))}function U(t){function e(t,e){}return e.type="xstate.stopChild",e.actorRef=t,e.resolve=z,e.execute=W,e}const Q=U;function F(t,e,{stateValue:s}){if("string"==typeof s&&it(s)){const e=t.machine.getStateNodeById(s);return t._nodes.some((t=>t===e))}return t.matches(s)}function G(t,{context:e,event:s},{guards:n}){return!K(n[0],e,s,t)}function X(t,{context:e,event:s},{guards:n}){return n.every((n=>K(n,e,s,t)))}function H(t,{context:e,event:s},{guards:n}){return n.some((n=>K(n,e,s,t)))}function K(t,e,s,n){const{machine:o}=n,i="function"==typeof t,r=i?t:o.implementations.guards["string"==typeof t?t:t.type];if(!i&&!r)throw new Error(`Guard '${"string"==typeof t?t:t.type}' is not implemented.'.`);if("function"!=typeof r)return K(r,e,s,n);const a={context:e,event:s},c=i||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:e,event:s}):t.params:void 0;if(!("check"in r))return r(a,c);return r.check(n,a,r)}const L=t=>"atomic"===t.type||"final"===t.type;function Y(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function Z(t,e){const s=[];if(e===t)return s;let n=t.parent;for(;n&&n!==e;)s.push(n),n=n.parent;return s}function tt(t){const e=new Set(t),s=st(e);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const s of Y(t))if("history"!==s.type&&!e.has(s)){const t=ht(s);for(const s of t)e.add(s)}}else ht(t).forEach((t=>e.add(t)));for(const t of e){let s=t.parent;for(;s;)e.add(s),s=s.parent}return e}function et(t,e){const s=e.get(t);if(!s)return{};if("compound"===t.type){const t=s[0];if(!t)return{};if(L(t))return t.key}const n={};for(const t of s)n[t.key]=et(t,e);return n}function st(t){const e=new Map;for(const s of t)e.has(s)||e.set(s,[]),s.parent&&(e.has(s.parent)||e.set(s.parent,[]),e.get(s.parent).push(s));return e}function nt(t,e){return et(t,st(tt(e)))}function ot(t,e){return"compound"===e.type?Y(e).some((e=>"final"===e.type&&t.has(e))):"parallel"===e.type?Y(e).every((e=>ot(t,e))):"final"===e.type}const it=t=>"#"===t[0];function rt(t){const e=t.config.after;if(!e)return[];return Object.keys(e).flatMap(((s,n)=>{const o=e[s],i="string"==typeof o?{target:o}:o,r=Number.isNaN(+s)?s:+s,a=((e,s)=>{const n=(o=e,i=t.id,{type:`xstate.after.${o}.${i}`});var o,i;const r=n.type;return t.entry.push(Xt(n,{id:r,delay:e})),t.exit.push(J(r)),r})(r);return x(i).map((t=>({...t,event:a,delay:r})))})).map((e=>{const{delay:s}=e;return{...at(t,e.event,e),delay:s}}))}function at(t,e,n){const o=$(n.target),i=n.reenter??!1,r=function(t,e){if(void 0===e)return;return e.map((e=>{if("string"!=typeof e)return e;if(it(e))return t.machine.getStateNodeById(e);const n=e[0]===s;if(n&&!t.parent)return pt(t,e.slice(1));const o=n?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return pt(t.parent,o)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}(t,o),a={...n,actions:x(n.actions),guard:n.guard,target:r,source:t,reenter:i,eventType:e,toJSON:()=>({...a,source:`#${t.id}`,target:r?r.map((t=>`#${t.id}`)):void 0})};return a}function ct(t){const e=$(t.config.target);return e?{target:e.map((e=>"string"==typeof e?pt(t.parent,e):e))}:t.parent.initial}function ut(t){return"history"===t.type}function ht(t){const e=ft(t);for(const s of e)for(const n of Z(s,t))e.add(n);return e}function ft(t){const e=new Set;return function t(s){if(!e.has(s))if(e.add(s),"compound"===s.type)t(s.initial.target[0]);else if("parallel"===s.type)for(const e of Y(s))t(e)}(t),e}function dt(t,e){if(it(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const s=t.states[e];if(!s)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return s}function pt(t,e){if("string"==typeof e&&it(e))try{return t.machine.getStateNodeById(e)}catch(t){}const s=g(e).slice();let n=t;for(;s.length;){const t=s.shift();if(!t.length)break;n=dt(n,t)}return n}function lt(t,e){if("string"==typeof e)return[t,t.states[e]];const s=Object.keys(e),n=s.map((e=>dt(t,e))).filter(Boolean);return[t.machine.root,t].concat(n,s.reduce(((s,n)=>{const o=dt(t,n);if(!o)return s;const i=lt(o,e[n]);return s.concat(i)}),[]))}function yt(t,e,s,n){return"string"==typeof e?function(t,e,s,n){const o=dt(t,e).next(s,n);return o&&o.length?o:t.next(s,n)}(t,e,s,n):1===Object.keys(e).length?function(t,e,s,n){const o=Object.keys(e),i=yt(dt(t,o[0]),e[o[0]],s,n);return i&&i.length?i:t.next(s,n)}(t,e,s,n):function(t,e,s,n){const o=[];for(const i of Object.keys(e)){const r=e[i];if(!r)continue;const a=yt(dt(t,i),r,s,n);a&&o.push(...a)}return o.length?o:t.next(s,n)}(t,e,s,n)}function vt(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function gt(t,e){let s=t;for(;s.parent&&s.parent!==e;)s=s.parent;return s.parent===e}function mt(t,e){const s=new Set(t),n=new Set(e);for(const t of s)if(n.has(t))return!0;for(const t of n)if(s.has(t))return!0;return!1}function _t(t,e,s){const n=new Set;for(const o of t){let t=!1;const i=new Set;for(const r of n)if(mt(xt([o],e,s),xt([r],e,s))){if(!gt(o.source,r.source)){t=!0;break}i.add(r)}if(!t){for(const t of i)n.delete(t);n.add(o)}}return Array.from(n)}function bt(t,e){if(!t.target)return[];const s=new Set;for(const n of t.target)if(ut(n))if(e[n.id])for(const t of e[n.id])s.add(t);else for(const t of bt(ct(n),e))s.add(t);else s.add(n);return[...s]}function St(t,e){const s=bt(t,e);if(!s)return;if(!t.reenter&&s.every((e=>e===t.source||gt(e,t.source))))return t.source;const n=function(t){const[e,...s]=t;for(const t of Z(e,void 0))if(s.every((e=>gt(e,t))))return t}(s.concat(t.source));return n||(t.reenter?void 0:t.source.machine.root)}function xt(t,e,s){const n=new Set;for(const o of t)if(o.target?.length){const t=St(o,s);o.reenter&&o.source===t&&n.add(t);for(const s of e)gt(s,t)&&n.add(s)}return[...n]}function wt(t,e,s,n,o,i){if(!t.length)return e;const r=new Set(e._nodes);let a=e.historyValue;const u=_t(t,r,a);let h=e;o||([h,a]=function(t,e,s,n,o,i,r){let a=t;const c=xt(n,o,i);let u;c.sort(((t,e)=>e.order-t.order));for(const t of c)for(const e of vt(t)){let s;s="deep"===e.history?e=>L(e)&&gt(e,t):e=>e.parent===t,u??={...i},u[e.id]=Array.from(o).filter(s)}for(const t of c)a=Ot(a,e,s,[...t.exit,...t.invoke.map((t=>U(t.id)))],r),o.delete(t);return[a,u||i]}(h,n,s,u,r,a,i)),h=Ot(h,n,s,u.flatMap((t=>t.actions)),i),h=function(t,e,s,n,o,i,r,a){let u=t;const h=new Set,f=new Set;(function(t,e,s,n){for(const o of t){const t=St(o,e);for(const i of o.target||[])ut(i)||o.source===i&&o.source===t&&!o.reenter||(n.add(i),s.add(i)),It(i,e,s,n);const i=bt(o,e);for(const r of i){const i=Z(r,t);"parallel"===t?.type&&i.push(t),$t(n,e,s,i,!o.source.parent&&o.reenter?void 0:t)}}})(n,r,f,h),a&&f.add(t.machine.root);const d=new Set;for(const t of[...h].sort(((t,e)=>t.order-e.order))){o.add(t);const n=[];n.push(...t.entry);for(const e of t.invoke)n.push(q(e.src,{...e,syncSnapshot:!!e.onSnapshot}));if(f.has(t)){const e=t.initial.actions;n.push(...e)}if(u=Ot(u,e,s,n,i,t.invoke.map((t=>t.id))),"final"===t.type){const n=t.parent;let r="parallel"===n?.type?n:n?.parent,a=r||t;for("compound"===n?.type&&i.push(c(n.id,t.output?w(t.output,u.context,e,s.self):void 0));"parallel"===r?.type&&!d.has(r)&&ot(o,r);)d.add(r),i.push(c(r.id)),a=r,r=r.parent;if(r)continue;u=qt(u,{status:"done",output:kt(u,e,s,u.machine.root,a)})}}return u}(h,n,s,u,r,i,a,o);const f=[...r];"done"===h.status&&(h=Ot(h,n,s,f.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit)),i));try{return a===e.historyValue&&function(t,e){if(t.length!==e.size)return!1;for(const s of t)if(!e.has(s))return!1;return!0}(e._nodes,r)?h:qt(h,{_nodes:f,historyValue:a})}catch(t){throw t}}function kt(t,e,s,n,o){if(!n.output)return;const i=c(o.id,o.output&&o.parent?w(o.output,t.context,e,s.self):void 0);return w(n.output,t.context,i,s.self)}function It(t,e,s,n){if(ut(t))if(e[t.id]){const o=e[t.id];for(const t of o)n.add(t),It(t,e,s,n);for(const i of o)Et(i,t.parent,n,e,s)}else{const o=ct(t);for(const i of o.target)n.add(i),o===t.parent?.initial&&s.add(t.parent),It(i,e,s,n);for(const i of o.target)Et(i,t,n,e,s)}else if("compound"===t.type){const[o]=t.initial.target;ut(o)||(n.add(o),s.add(o)),It(o,e,s,n),Et(o,t,n,e,s)}else if("parallel"===t.type)for(const o of Y(t).filter((t=>!ut(t))))[...n].some((t=>gt(t,o)))||(ut(o)||(n.add(o),s.add(o)),It(o,e,s,n))}function $t(t,e,s,n,o){for(const i of n)if(o&&!gt(i,o)||t.add(i),"parallel"===i.type)for(const n of Y(i).filter((t=>!ut(t))))[...t].some((t=>gt(t,n)))||(t.add(n),It(n,e,s,t))}function Et(t,e,s,n,o){$t(s,n,o,Z(t,e))}function Tt(t,e,s,n,o,i){const{machine:r}=t;let a=t;for(const t of n){const n="function"==typeof t,c=n?t:r.implementations.actions["string"==typeof t?t:t.type];if(!c)continue;const u={context:a.context,event:e,self:s?.self,system:s?.system},h=n||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:a.context,event:e}):t.params:void 0;if(!("resolve"in c)){s?.self._processingStatus===j.Running?c(u,h):s?.defer((()=>{c(u,h)}));continue}const f=c,[d,p,l]=f.resolve(s,a,u,h,c,o);a=d,"retryResolve"in f&&i?.push([f,p]),"execute"in f&&(s?.self._processingStatus===j.Running?f.execute(s,p):s?.defer(f.execute.bind(null,s,p))),l&&(a=Tt(a,e,s,l,o,i))}return a}function Ot(t,e,s,n,o,i){const r=i?[]:void 0,a=Tt(t,e,s,n,{internalQueue:o,deferredActorIds:i},r);return r?.forEach((([t,e])=>{t.retryResolve(s,a,e)})),a}function Mt(t,e,s,n=[]){let o=t;const r=[];if(e.type===a)return o=qt(jt(o,e,s),{status:"stopped"}),r.push(o),{snapshot:o,microstates:r};let c=e;if(c.type!==i){const e=c,i=function(t){return t.type.startsWith("xstate.error.actor")}(e),a=Nt(e,o);if(i&&!a.length)return o=qt(t,{status:"error",error:e.error}),r.push(o),{snapshot:o,microstates:r};o=wt(a,t,s,c,!1,n),r.push(o)}let u=!0;for(;"active"===o.status;){let t=u?At(o,c):[];const e=t.length?o:void 0;if(!t.length){if(!n.length)break;c=n.shift(),t=Nt(c,o)}o=wt(t,o,s,c,!1,n),u=o!==e,r.push(o)}return"active"!==o.status&&jt(o,c,s),{snapshot:o,microstates:r}}function jt(t,e,s){return Ot(t,e,s,Object.values(t.children).map((t=>U(t))),[])}function Nt(t,e){return e.machine.getTransitionData(e,t)}function At(t,e){const s=new Set,n=t._nodes.filter(L);for(const o of n)t:for(const n of[o].concat(Z(o,void 0)))if(n.always)for(const o of n.always)if(void 0===o.guard||K(o.guard,t.context,e,t)){s.add(o);break t}return _t(Array.from(s),new Set(t._nodes),t.historyValue)}function Pt(t){return!!t&&"object"==typeof t&&"machine"in t&&"value"in t}const Rt=function(t){return v(t,this.value)},Ct=function(t){return this.tags.has(t)},Dt=function(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))},Jt=function(){const{_nodes:t,tags:e,machine:s,getMeta:n,toJSON:o,can:i,hasTag:r,matches:a,...c}=this;return{...c,tags:Array.from(e)}},Vt=function(){return this._nodes.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})};function Bt(t,e){return{status:t.status,output:t.output,error:t.error,machine:e,context:t.context,_nodes:t._nodes,value:nt(e.root,t._nodes),tags:new Set(t._nodes.flatMap((t=>t.tags))),children:t.children,historyValue:t.historyValue||{},matches:Rt,hasTag:Ct,can:Dt,getMeta:Vt,toJSON:Jt}}function qt(t,e={}){return Bt({...t,...e},t.machine)}function zt(t){let e;for(const s in t){const n=t[s];if(n&&"object"==typeof n)if("sessionId"in n&&"send"in n&&"ref"in n)e??=Array.isArray(t)?t.slice():{...t},e[s]={xstate$$type:M,id:n.id};else{const o=zt(n);o!==n&&(e??=Array.isArray(t)?t.slice():{...t},e[s]=o)}}return e??t}function Wt(t,{machine:e,context:s},n,o){return(i,r)=>{const a=((i,r={})=>{const{systemId:a,input:c}=r;if("string"==typeof i){const u=O(e,i);if(!u)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const h=P(u,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:"function"==typeof c?c({context:s,event:n,self:t.self}):c,src:i,systemId:a});return o[h.id]=h,h}return P(i,{id:r.id,parent:t.self,syncSnapshot:r.syncSnapshot,input:r.input,src:i,systemId:a})})(i,r);return o[a.id]=a,t.defer((()=>{a._processingStatus!==j.Stopped&&a.start()})),a}}function Ut(t,e,s,n,{assignment:o}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const i={},r={context:e.context,event:s.event,spawn:Wt(t,e,s.event,i),self:t?.self,system:t?.system};let a={};if("function"==typeof o)a=o(r,n);else for(const t of Object.keys(o)){const e=o[t];a[t]="function"==typeof e?e(r,n):e}return[qt(e,{context:Object.assign({},e.context,a),children:Object.keys(i).length?{...e.children,...i}:e.children})]}function Qt(t){function e(t,e){}return e.type="xstate.assign",e.assignment=t,e.resolve=Ut,e}function Ft(t,e,s,n,{event:o,id:i,delay:r},{internalQueue:a}){const c=e.machine.implementations.delays;if("string"==typeof o)throw new Error(`Only event objects may be used with raise; use raise({ type: "${o}" }) instead`);const u="function"==typeof o?o(s,n):o;let h;if("string"==typeof r){const t=c&&c[r];h="function"==typeof t?t(s,n):t}else h="function"==typeof r?r(s,n):r;return"number"!=typeof h&&a.push(u),[e,{event:u,id:i,delay:h}]}function Gt(t,e){"number"!=typeof e.delay||t.self.delaySend(e)}function Xt(t,e){function s(t,e){}return s.type="xstate.raise",s.event=t,s.id=e?.id,s.delay=e?.delay,s.resolve=Ft,s.execute=Gt,s}let Ht=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});function Kt(t,e,s,n,{to:o,event:i,id:r,delay:a},c){const u=e.machine.implementations.delays;if("string"==typeof i)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${i}" }) instead`);const h="function"==typeof i?i(s,n):i;let f;if("string"==typeof a){const t=u&&u[a];f="function"==typeof t?t(s,n):t}else f="function"==typeof a?a(s,n):a;const d="function"==typeof o?o(s,n):o;let p;if("string"==typeof d){if(p=d===Ht.Parent?t?.self._parent:d===Ht.Internal?t?.self:d.startsWith("#_")?e.children[d.slice(2)]:c.deferredActorIds?.includes(d)?d:e.children[d],!p)throw new Error(`Unable to send event to actor '${d}' from machine '${e.machine.id}'.`)}else p=d||t?.self;return[e,{to:p,event:h,id:r,delay:f}]}function Lt(t,e,s){"string"==typeof s.to&&(s.to=e.children[s.to])}function Yt(t,e){"number"!=typeof e.delay?t.defer((()=>{const{to:s,event:n}=e;t?.system._relay(t.self,s,n.type===r?u(t.self.id,n.data):n)})):t.self.delaySend(e)}function Zt(t,e,s){function n(t,e){}return n.type="xsnapshot.sendTo",n.to=t,n.event=e,n.id=s?.id,n.delay=s?.delay,n.resolve=Kt,n.retryResolve=Lt,n.execute=Yt,n}function te(t,e,s,n,{collect:o}){const i=[],r=function(t){i.push(t)};return r.assign=(...t)=>{i.push(Qt(...t))},r.cancel=(...t)=>{i.push(J(...t))},r.raise=(...t)=>{i.push(Xt(...t))},r.sendTo=(...t)=>{i.push(Zt(...t))},r.spawnChild=(...t)=>{i.push(q(...t))},r.stopChild=(...t)=>{i.push(U(...t))},o({context:s.context,event:s.event,enqueue:r,check:t=>K(t,e.context,s.event,e)}),[e,void 0,i]}function ee(t,e,s,n,{value:o,label:i}){return[e,{value:"function"==typeof o?o(s,n):o,label:i}]}function se({logger:t},{value:e,label:s}){s?t(s,e):t(e)}function ne(t,e){return{config:t,transition:(e,s,n)=>({...e,context:t(e.context,s,n)}),getInitialSnapshot:(t,s)=>({status:"active",output:void 0,error:void 0,context:"function"==typeof e?e({input:s}):e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}}const oe=new WeakMap;const ie="xstate.observable.next",re="xstate.observable.error",ae="xstate.observable.complete";const ce="xstate.promise.resolve",ue="xstate.promise.reject";const he=ne((t=>{}),void 0);const fe=new WeakMap;function de(t,e,s){let n=fe.get(t);return n?e in n||(n[e]=s()):(n={[e]:s()},fe.set(t,n)),n[e]}const pe={},le=t=>"string"==typeof t?{type:t}:"function"==typeof t?"resolve"in t?{type:t.type}:{type:t.name}:t;class ye{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(s),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?b(this.config.states,((t,e)=>new ye(t,{_parent:this,_key:e,_machine:this.machine}))):pe,"compound"===this.type&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=x(this.config.entry).slice(),this.exit=x(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=x(t.tags).slice()}_initialize(){this.transitions=function(t){const e=new Map;if(t.config.on)for(const s of Object.keys(t.config.on)){if(s===o)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=t.config.on[s];e.set(s,I(n).map((e=>at(t,s,e))))}if(t.config.onDone){const s=`xstate.done.state.${t.id}`;e.set(s,I(t.config.onDone).map((e=>at(t,s,e))))}for(const s of t.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;e.set(n,I(s.onDone).map((e=>at(t,n,e))))}if(s.onError){const n=`xstate.error.actor.${s.id}`;e.set(n,I(s.onError).map((e=>at(t,n,e))))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;e.set(n,I(s.onSnapshot).map((e=>at(t,n,e))))}}for(const s of t.after){let t=e.get(s.eventType);t||(t=[],e.set(s.eventType,t)),t.push(s)}return e}(this),this.config.always&&(this.always=I(this.config.always).map((t=>at(this,o,t)))),Object.keys(this.states).forEach((t=>{this.states[t]._initialize()}))}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(le),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions.map(le),eventType:null})}:void 0,history:this.history,states:b(this.states,(t=>t.definition)),on:this.on,transitions:[...this.transitions.values()].flat().map((t=>({...t,actions:t.actions.map(le)}))),entry:this.entry.map(le),exit:this.exit.map(le),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return de(this,"invoke",(()=>x(this.config.invoke).map(((t,e)=>{const{src:s,systemId:n}=t,o=t.id??T(this.id,e),i="string"==typeof s?s:`xstate.invoke.${T(this.id,e)}`;return{...t,src:i,id:o,systemId:n,toJSON(){const{onDone:e,onError:s,...n}=t;return{...n,type:"xstate.invoke",src:i,id:o}}}}))))}get on(){return de(this,"on",(()=>[...this.transitions].flatMap((([t,e])=>e.map((e=>[t,e])))).reduce(((t,[e,s])=>(t[e]=t[e]||[],t[e].push(s),t)),{})))}get after(){return de(this,"delayedTransitions",(()=>rt(this)))}get initial(){return de(this,"initial",(()=>function(t,e){const s="string"==typeof e?t.states[e]:e?t.states[e.target]:void 0;if(!s&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);const n={source:t,actions:e&&"string"!=typeof e?x(e.actions):[],eventType:null,reenter:!1,target:s?[s]:[],toJSON:()=>({...n,source:`#${t.id}`,target:s?[`#${s.id}`]:[]})};return n}(this,this.config.initial)))}next(t,e){const s=e.type,n=[];let o;const i=de(this,`candidates-${s}`,(()=>{return e=s,(t=this).transitions.get(e)||[...t.transitions.keys()].filter((t=>{if("*"===t)return!0;if(!t.endsWith(".*"))return!1;const s=t.split("."),n=e.split(".");for(let t=0;t<s.length;t++){const e=s[t],o=n[t];if("*"===e)return t===s.length-1;if(e!==o)return!1}return!0})).sort(((t,e)=>e.length-t.length)).flatMap((e=>t.transitions.get(e)));var t,e}));for(const r of i){const{guard:i}=r,a=t.context;let c=!1;try{c=!i||K(i,a,e,t)}catch(t){const e="string"==typeof i?i:"object"==typeof i?i.type:void 0;throw new Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(c){n.push(...r.actions),o=r;break}}return o?[o]:void 0}get events(){return de(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const s of Object.keys(t)){const n=t[s];if(n.states)for(const t of n.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set([...this.transitions.keys()].filter((t=>this.transitions.get(t).some((t=>!(!t.target&&!t.actions.length&&!t.reenter))))));return Array.from(t)}}class ve{constructor(t,e){this.config=t,this.version=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.implementations={actors:e?.actors??{},actions:e?.actions??{},delays:e?.delays??{},guards:e?.guards??{}},this.version=this.config.version,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new ye(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:s,actors:n,delays:o}=this.implementations;return new ve(this.config,{actions:{...e,...t.actions},guards:{...s,...t.guards},actors:{...n,...t.actors},delays:{...o,...t.delays}})}resolveState(t){const e=(s=this.root,n=t.value,nt(s,[...tt(lt(s,n))]));var s,n;const o=tt(lt(this.root,e));return Bt({_nodes:[...o],context:t.context||{},children:{},status:ot(o,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,e,s){return Mt(t,e,s).snapshot}microstep(t,e,s){return Mt(t,e,s).microstates}getTransitionData(t,e){return yt(this.root,t.value,t,e)||[]}getPreInitialState(t,e,s){const{context:n}=this.config,o=Bt({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);if("function"==typeof n){return Ot(o,e,t,[Qt((({spawn:t,event:e})=>n({spawn:t,input:e.input})))],s)}return o}getInitialSnapshot(t,e){const s=h(e),n=[],o=this.getPreInitialState(t,s,n),i=wt([{target:[...ft(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],o,t,s,!0,n),{snapshot:r}=Mt(i,s,t,n);return r}start(t){Object.values(t.children).forEach((t=>{"active"===t.getSnapshot().status&&t.start()}))}getStateNodeById(t){const e=t.split(s),n=e.slice(1),o=it(e[0])?e[0].slice(1):e[0],i=this.idMap.get(o);if(!i)throw new Error(`Child state node '#${o}' does not exist on machine '${this.id}'`);return pt(i,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,e){return function(t,e){const{_nodes:s,tags:n,machine:o,children:i,context:r,can:a,hasTag:c,matches:u,getMeta:h,toJSON:f,...d}=t,p={};for(const t in i){const s=i[t];p[t]={snapshot:s.getPersistedSnapshot(e),src:s.src,systemId:s._systemId,syncSnapshot:s._syncSnapshot}}return{...d,context:zt(r),children:p}}(t,e)}restoreSnapshot(t,e){const s={},n=t.children;Object.keys(n).forEach((t=>{const o=n[t],i=o.snapshot,r=o.src,a="string"==typeof r?O(this,r):r;if(!a)return;const c=P(a,{id:t,parent:e?.self,syncSnapshot:o.syncSnapshot,snapshot:i,src:r,systemId:o.systemId});s[t]=c}));const o=Bt({...t,children:s,_nodes:Array.from(tt(lt(this.root,t.value)))},this);let i=new Set;return function t(e,s){if(!i.has(e)){i.add(e);for(let n in e){const o=e[n];if(o&&"object"==typeof o){if("xstate$$type"in o&&o.xstate$$type===M){e[n]=s[o.id];continue}t(o,s)}}}}(o.context,s),o}}const ge={timeout:1/0};function me(t,e){return new ve(t,e)}t.Actor=A,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const s=this.getId();return this.timeouts.set(s,{start:this.now(),timeout:e,fn:t}),s}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[s,n])=>{const o=e.start+e.timeout;return n.start+n.timeout>o?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=Ht,t.StateMachine=ve,t.StateNode=ye,t.__unsafe_getAllOwnEventDescriptors=function(t){return[...new Set([...t._nodes.flatMap((t=>t.ownEvents))])]},t.and=function(t){function e(t,e){return!1}return e.check=X,e.guards=t,e},t.assign=Qt,t.cancel=J,t.createActor=P,t.createEmptyActor=function(){return P(he)},t.createMachine=me,t.enqueueActions=function(t){function e(t,e){}return e.type="xstate.enqueueActions",e.collect=t,e.resolve=te,e},t.forwardTo=function(t,e){return Zt(t,(({event:t})=>t),e)},t.fromCallback=function(t){return{config:t,start:(e,s)=>{const{self:n,system:o}=s,i={receivers:void 0,dispose:void 0};oe.set(n,i),i.dispose=t({input:e.input,system:o,self:n,sendBack:t=>{"stopped"!==n.getSnapshot().status&&n._parent&&o._relay(n,n._parent,t)},receive:t=>{i.receivers??=new Set,i.receivers.add(t)}})},transition:(t,e,s)=>{const n=oe.get(s.self);return e.type===a?(t={...t,status:"stopped",error:void 0},n.dispose?.(),t):(n.receivers?.forEach((t=>t(e))),t)},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromEventObservable=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case re:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ae:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{s._parent&&n._relay(s,s._parent,t)},error:t=>{n._relay(s,s,{type:re,data:t})},complete:()=>{n._relay(s,s,{type:ae})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromObservable=function(t){return{config:t,transition:(t,e,{self:s,id:n,defer:o,system:i})=>{if("active"!==t.status)return t;switch(e.type){case ie:return{...t,context:e.data};case re:return{...t,status:"error",error:e.data,input:void 0,_subscription:void 0};case ae:return{...t,status:"done",input:void 0,_subscription:void 0};case a:return t._subscription.unsubscribe(),{...t,status:"stopped",input:void 0,_subscription:void 0};default:return t}},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,context:void 0,input:e,_subscription:void 0}),start:(e,{self:s,system:n})=>{"done"!==e.status&&(e._subscription=t({input:e.input,system:n,self:s}).subscribe({next:t=>{n._relay(s,s,{type:ie,data:t})},error:t=>{n._relay(s,s,{type:re,data:t})},complete:()=>{n._relay(s,s,{type:ae})}}))},getPersistedSnapshot:({_subscription:t,...e})=>e,restoreSnapshot:t=>({...t,_subscription:void 0})}},t.fromPromise=function(t){return{config:t,transition:(t,e)=>{if("active"!==t.status)return t;switch(e.type){case ce:{const s=e.data;return{...t,status:"done",output:s,input:void 0}}case ue:return{...t,status:"error",error:e.data,input:void 0};case a:return{...t,status:"stopped",input:void 0};default:return t}},start:(e,{self:s,system:n})=>{if("active"!==e.status)return;Promise.resolve(t({input:e.input,system:n,self:s})).then((t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:ce,data:t})}),(t=>{"active"===s.getSnapshot().status&&n._relay(s,s,{type:ue,data:t})}))},getInitialSnapshot:(t,e)=>({status:"active",output:void 0,error:void 0,input:e}),getPersistedSnapshot:t=>t,restoreSnapshot:t=>t}},t.fromTransition=ne,t.getStateNodes=lt,t.interpret=R,t.isMachineSnapshot=Pt,t.log=function(t=(({context:t,event:e})=>({context:t,event:e})),e){function s(t,e){}return s.type="xstate.log",s.value=t,s.label=e,s.resolve=ee,s.execute=se,s},t.matchesState=v,t.not=function(t){function e(t,e){return!1}return e.check=G,e.guards=[t],e},t.or=function(t){function e(t,e){return!1}return e.check=H,e.guards=t,e},t.pathToStateValue=_,t.raise=Xt,t.sendParent=function(t,e){return Zt(Ht.Parent,t,e)},t.sendTo=Zt,t.setup=function({actors:t,actions:e,guards:s,delays:n}){return{createMachine:o=>me(o,{actors:t,actions:e,guards:s,delays:n})}},t.spawnChild=q,t.stateIn=function(t){function e(t,e){return!1}return e.check=F,e.stateValue=t,e},t.stop=Q,t.stopChild=U,t.toObserver=E,t.waitFor=function(t,e,s){const n={...ge,...s};return new Promise(((s,o)=>{let i=!1;const r=n.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),o(new Error(`Timeout of ${n.timeout} ms exceeded`))}),n.timeout),a=()=>{clearTimeout(r),i=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),s(t))}let u;c(t.getSnapshot()),i||(u=t.subscribe({next:c,error:t=>{a(),o(t)},complete:()=>{a(),o(new Error("Actor terminated without satisfying predicate"))}}),i&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=xstate.umd.min.js.map