xstate 5.0.0-alpha.6 → 5.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/dist/xstate-actions.cjs.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.js +29 -5
- package/actions/dist/xstate-actions.cjs.mjs +24 -0
- package/actions/dist/{xstate-actions.cjs.dev.js → xstate-actions.development.cjs.js} +3 -3
- package/actions/dist/xstate-actions.development.esm.js +2 -0
- package/actions/dist/xstate-actions.esm.js +2 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.js +20 -5
- package/actors/dist/xstate-actors.cjs.mjs +15 -0
- package/actors/dist/{xstate-actors.cjs.dev.js → xstate-actors.development.cjs.js} +3 -2
- package/actors/dist/xstate-actors.development.esm.js +2 -0
- package/actors/dist/xstate-actors.esm.js +2 -2
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.js +45 -4
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/{dist/index-ebaab3c9.cjs.dev.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
- package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
- package/dev/dist/xstate-dev.esm.js +42 -1
- package/dev/dist/xstate-dev.umd.min.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/actions-26f9aa9d.cjs.js +3388 -0
- package/dist/actions-acbe7aa1.development.cjs.js +3423 -0
- package/dist/actions-b82e841e.esm.js +3306 -0
- package/dist/actions-cff79077.development.esm.js +3341 -0
- package/dist/declarations/src/State.d.ts +2 -3
- package/dist/declarations/src/StateMachine.d.ts +6 -6
- package/dist/declarations/src/StateNode.d.ts +3 -9
- package/dist/declarations/src/actions/send.d.ts +0 -7
- package/dist/declarations/src/actions.d.ts +9 -8
- package/dist/declarations/src/actors/index.d.ts +2 -1
- package/dist/declarations/src/actors/observable.d.ts +1 -2
- package/dist/declarations/src/actors/promise.d.ts +1 -2
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +13 -29
- package/dist/declarations/src/interpreter.d.ts +5 -4
- package/dist/declarations/src/stateUtils.d.ts +9 -14
- package/dist/declarations/src/typegenTypes.d.ts +7 -1
- package/dist/declarations/src/types.d.ts +18 -92
- package/dist/declarations/src/utils.d.ts +3 -6
- package/dist/declarations/src/waitFor.d.ts +33 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.js +802 -4
- package/dist/xstate.cjs.mjs +38 -0
- package/dist/xstate.development.cjs.js +808 -0
- package/dist/xstate.development.esm.js +770 -0
- package/dist/xstate.esm.js +594 -706
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.js +13 -5
- package/guards/dist/xstate-guards.cjs.mjs +8 -0
- package/guards/dist/{xstate-guards.cjs.dev.js → xstate-guards.development.cjs.js} +2 -2
- package/guards/dist/xstate-guards.development.esm.js +2 -0
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +58 -1
- package/actions/dist/xstate-actions.cjs.prod.js +0 -31
- package/actors/dist/xstate-actors.cjs.prod.js +0 -21
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -48
- package/dist/actions-41b74cdc.esm.js +0 -4287
- package/dist/actions-bf7bb1c5.cjs.dev.js +0 -4342
- package/dist/actions-c46e4911.cjs.prod.js +0 -4304
- package/dist/declarations/actions/dynamicAction.d.ts +0 -5
- package/dist/declarations/src/Mailbox.d.ts +0 -12
- package/dist/declarations/src/actions/invoke.d.ts +0 -3
- package/dist/declarations/src/environment.d.ts +0 -1
- package/dist/declarations/src/memo.d.ts +0 -2
- package/dist/declarations/src/schema.d.ts +0 -2
- package/dist/declarations/src/spawn.d.ts +0 -2
- package/dist/declarations/src/system.d.ts +0 -2
- package/dist/xstate.cjs.dev.js +0 -921
- package/dist/xstate.cjs.prod.js +0 -921
- package/guards/dist/xstate-guards.cjs.prod.js +0 -15
package/dist/xstate.umd.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";var e,n;(e=t.ActionTypes||(t.ActionTypes={})).Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Pure="xstate.pure",e.Choose="xstate.choose",(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var r=t.ActionTypes.Stop,i=t.ActionTypes.Raise,o=t.ActionTypes.Send,a=t.ActionTypes.Cancel,s=t.ActionTypes.Assign,u=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),c=t.ActionTypes.Init,l=t.ActionTypes.Invoke,f=t.ActionTypes.ErrorExecution,v=t.ActionTypes.ErrorPlatform,h=t.ActionTypes.ErrorCustom,d=t.ActionTypes.Choose,p=t.ActionTypes.Pure;function y(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function m(t,e,n){return(e=y(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function g(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){m(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function _(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function x(t,e){if(t){if("string"==typeof t)return _(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_(t,e):void 0}}function S(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,s=[],u=!0,c=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(s.push(r.value),s.length!==e);u=!0);}catch(t){c=!0,i=t}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return s}}(t,e)||x(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(t){return function(t){if(Array.isArray(t))return _(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||x(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=x(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,i=function(){};return{s:i,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw o}}}}function E(t){return(E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var T="*";function I(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:".",r=j(t,n),i=j(e,n);return J(i)?!!J(r)&&i===r:J(r)?r in i:Object.keys(r).every((function(t){return t in i&&I(r[t],i[t])}))}function O(t,e){try{return Q(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function j(t,e){return"object"===E(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:Q(t)?A(t):"string"!=typeof t?t:A(O(t,e));var n}function A(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function C(t,e){for(var n={},r=Object.keys(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function P(t){var e;return(e=[]).concat.apply(e,k(t))}function M(t){return Q(t)?t:[t]}function N(t){return void 0===t?[]:M(t)}function D(t,e,n){if(R(t))return t({context:e,event:n.data});for(var r={},i={context:e,event:n.data},o=0,a=Object.keys(t);o<a.length;o++){var s=a[o],u=t[s];R(u)?r[s]=u(i):r[s]=u}return r}function Q(t){return Array.isArray(t)}function R(t){return"function"==typeof t}function J(t){return"string"==typeof t}function V(t){return"string"==typeof t.name&&(t.name===f||t.name.startsWith(v))}function B(t,e){return function(t){return"$$type"in t&&"scxml"===t.$$type}(t)?t:b({name:t.type,data:t,$$type:"scxml",type:"external"},e)}function $(t,e){return M(e).map((function(e){return void 0===e||"string"==typeof e?{target:e,event:t}:b(b({},e),{},{event:t})}))}function z(t){if(void 0!==t&&""!==t)return N(t)}function U(t,e,n){var r=function(){},i="object"===E(t),o=i?t:null;return{next:((i?t.next:t)||r).bind(o),error:((i?t.error:e)||r).bind(o),complete:((i?t.complete:n)||r).bind(o)}}function W(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function q(t,e){return{type:t.type,params:t.params,resolve:e}}function L(t){return"object"===E(t)&&null!==t&&"resolve"in t}function X(e,n){return q({type:o,params:{to:n?n.to:void 0,delay:n?n.delay:void 0,event:e,id:n&&void 0!==n.id?n.id:R(e)?e.name:e.type}},(function(r,i){var a,s,u=i.actorContext,c=i.state,l={to:n?n.to:void 0,delay:n?n.delay:void 0,event:e,id:n&&void 0!==n.id?n.id:R(e)?e.name:e.type},f={context:c.context,event:r.data,_event:r,self:null!==(a=null==u?void 0:u.self)&&void 0!==a?a:null,system:null==u?void 0:u.system},v=c.machine.options.delays,d=B(R(e)?e(f):e);if(J(l.delay)){var p=v&&v[l.delay];s=R(p)?p(f):p}else s=R(l.delay)?l.delay(f):l.delay;var y,m=R(l.to)?l.to(f):l.to;if("string"==typeof m){if(!(y=m===t.SpecialTargets.Parent?null==u?void 0:u.self._parent:m===t.SpecialTargets.Internal?null==u?void 0:u.self:m.startsWith("#_")?c.children[m.slice(2)]:c.children[m]))throw new Error("Unable to send event to actor '".concat(m,"' from machine '").concat(c.machine.id,"'."))}else y=m||(null==u?void 0:u.self);var g={type:o,params:b(b({},l),{},{to:y,_event:d,event:d.data,delay:s,internal:m===t.SpecialTargets.Internal}),execute:function(t){var e=g;if("number"!=typeof e.params.delay){var n=e.params.to,r=e.params._event;t.defer((function(){var e=t.self,i=b(b({},r),{},{name:r.name===h?"".concat(he(e.id)):r.name,origin:e});n.send(i)}))}else t.self.delaySend(e)}};return[c,g]}))}function G(e,n){return X(e,b(b({},n),{},{to:t.SpecialTargets.Parent}))}function F(t,e){if("production"!==process.env.NODE_END&&(!t||"function"==typeof t)){var n=t;t=function(){var t="function"==typeof n?n.apply(void 0,arguments):n;if(!t)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return t}}return X((function(t){return t.event}),b(b({},e),{},{to:t}))}function H(t,e,n){return X(e,b(b({},n),{},{to:t}))}function K(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Y(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,y(r.key),r)}}function Z(t,e,n){return e&&Y(t.prototype,e),n&&Y(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}var tt=function(){function t(e){K(this,t),this._process=e,m(this,"_active",!1),m(this,"_current",null),m(this,"_last",null)}return Z(t,[{key:"start",value:function(){this._active=!0,this.flush()}},{key:"clear",value:function(){this._current&&(this._current.next=null,this._last=this._current)}},{key:"prepend",value:function(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}},{key:"enqueue",value:function(t){var e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}},{key:"flush",value:function(){for(;this._current;){var t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}]),t}(),et="function"==typeof Symbol&&Symbol.observable||"@@observable",nt="xstate.stop";function rt(){var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}var it,ot=function(t){var e=rt();e&&e.register(t)};(it=t.InterpreterStatus||(t.InterpreterStatus={}))[it.NotStarted=0]="NotStarted",it[it.Running=1]="Running",it[it.Stopped=2]="Stopped";var at={deferEvents:!0,clock:{setTimeout:function(t){function e(e,n){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t,e){return setTimeout(t,e)})),clearTimeout:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}((function(t){return clearTimeout(t)}))},logger:console.log.bind(console),devTools:!1},st=function(){function e(n,r){var i,o=this;K(this,e),this.behavior=n,m(this,"_state",void 0),m(this,"clock",void 0),m(this,"options",void 0),m(this,"id",void 0),m(this,"mailbox",new tt(this._process.bind(this))),m(this,"delayedEventsMap",{}),m(this,"observers",new Set),m(this,"logger",void 0),m(this,"status",t.InterpreterStatus.NotStarted),m(this,"_parent",void 0),m(this,"ref",void 0),m(this,"_actorContext",void 0),m(this,"_systemId",void 0),m(this,"sessionId",void 0),m(this,"system",void 0),m(this,"_doneEvent",void 0),m(this,"src",void 0),m(this,"_deferred",[]);var a,s,u,c,l=b(b({},at),r),f=l.clock,v=l.logger,h=l.parent,d=l.id,p=l.systemId;this.system=null!==(i=null==h?void 0:h.system)&&void 0!==i?i:(a=0,s=new Map,u=new Map,c=new WeakMap,{_bookId:function(){return"x:".concat(a++)},_register:function(t,e){return s.set(t,e),t},_unregister:function(t){s.delete(t.sessionId);var e=c.get(t);void 0!==e&&(u.delete(e),c.delete(t))},get:function(t){return u.get(t)},_set:function(t,e){var n=u.get(t);if(n&&n!==e)throw new Error("Actor with system ID '".concat(t,"' already exists."));u.set(t,e),c.set(e,t)}}),p&&(this._systemId=p,this.system._set(p,this)),this.sessionId=this.system._bookId(),this.id=null!=d?d:this.sessionId,this.logger=v,this.clock=f,this._parent=h,this.options=l,this.src=l.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:function(t){o._deferred.push(t)},system:this.system,stopChild:function(t){if(t._parent!==o)throw new Error("Cannot stop child actor ".concat(t.id," of ").concat(o.id," because it is not a child"));t._stop()}},this.send=this.send.bind(this),this._initState()}return Z(e,[{key:"_initState",value:function(){var t;this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,null===(t=this.options)||void 0===t?void 0:t.input)}},{key:"update",value:function(t){var e,n,r,i;this._state=t;for(var o,a=this.getSnapshot();o=this._deferred.shift();)o(t);var s,u=w(this.observers);try{for(u.s();!(s=u.n()).done;){var c,l=s.value;null===(c=l.next)||void 0===c||c.call(l,a)}}catch(t){u.e(t)}finally{u.f()}var f=null===(e=(n=this.behavior).getStatus)||void 0===e?void 0:e.call(n,t);switch(null==f?void 0:f.status){case"done":this._doneEvent=ve(this.id,f.data),null===(r=this._parent)||void 0===r||r.send(B(this._doneEvent,{origin:this,invokeid:this.id})),this._stopProcedure();break;case"error":null===(i=this._parent)||void 0===i||i.send(B(he(this.id,f.data),{origin:this}));var v,h=w(this.observers);try{for(h.s();!(v=h.n()).done;){var d,p=v.value;null===(d=p.error)||void 0===d||d.call(p,f.data)}}catch(t){h.e(t)}finally{h.f()}}}},{key:"subscribe",value:function(e,n,r){var i,o=this,a=U(e,n,r);(this.observers.add(a),this.status===t.InterpreterStatus.Stopped)&&(null===(i=a.complete)||void 0===i||i.call(a),this.observers.delete(a));return{unsubscribe:function(){o.observers.delete(a)}}}},{key:"onDone",value:function(e){var n=this;return this.status===t.InterpreterStatus.Stopped&&this._doneEvent?e(this._doneEvent):this.observers.add({complete:function(){n._doneEvent&&e(n._doneEvent)}}),this}},{key:"start",value:function(){return this.status===t.InterpreterStatus.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=t.InterpreterStatus.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}},{key:"_process",value:function(t){try{var e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.name===nt&&this._stopProcedure()}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((function(e){var n;null===(n=e.error)||void 0===n||n.call(e,t)})),this.stop()}}},{key:"_stop",value:function(){return this.status===t.InterpreterStatus.Stopped?this:(this.mailbox.clear(),this.status===t.InterpreterStatus.NotStarted?(this.status=t.InterpreterStatus.Stopped,this):(this.mailbox.enqueue(B({type:nt})),this))}},{key:"stop",value:function(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}},{key:"_complete",value:function(){var t,e=w(this.observers);try{for(e.s();!(t=e.n()).done;){var n,r=t.value;null===(n=r.complete)||void 0===n||n.call(r)}}catch(t){e.e(t)}finally{e.f()}this.observers.clear()}},{key:"_stopProcedure",value:function(){if(this._complete(),this.status!==t.InterpreterStatus.Running)return this;for(var e=0,n=Object.keys(this.delayedEventsMap);e<n.length;e++){var r=n[e];this.clock.clearTimeout(this.delayedEventsMap[r])}return this.mailbox.clear(),this.mailbox=new tt(this._process.bind(this)),this.status=t.InterpreterStatus.Stopped,this.system._unregister(this),this}},{key:"send",value:function(e){var n=B(e);if(this.status!==t.InterpreterStatus.Stopped){if(this.status!==t.InterpreterStatus.Running&&!this.options.deferEvents)throw new Error('Event "'.concat(n.name,'" was sent to uninitialized actor "').concat(this.id,'". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ').concat(JSON.stringify(n.data)));this.mailbox.enqueue(n)}}},{key:"delaySend",value:function(t){var e=this;this.delayedEventsMap[t.params.id]=this.clock.setTimeout((function(){"to"in t.params&&t.params.to?t.params.to.send(t.params._event):e.send(t.params._event)}),t.params.delay)}},{key:"cancel",value:function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}},{key:"attachDevTools",value:function(){var t=this.options.devTools;t&&("function"==typeof t?t:ot)(this)}},{key:"toJSON",value:function(){return{id:this.id}}},{key:"getPersistedState",value:function(){var t,e;return null===(t=(e=this.behavior).getPersistedState)||void 0===t?void 0:t.call(e,this._state)}},{key:et,value:function(){return this}},{key:"getSnapshot",value:function(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}]),e}();function ut(t,e){return new st(t,e)}function ct(e){var n=e;return q({type:r,params:{actor:n}},(function(e,r){var i=r.state,o=R(n)?n({context:i.context,event:e.data}):n,a="string"==typeof o?i.children[o]:o;return[i,{type:"xstate.stop",params:{actor:a},execute:function(e){a&&(a.status===t.InterpreterStatus.Running?e.defer((function(){e.stopChild(a)})):e.stopChild(a))}}]}))}var lt=function(t){return{context:t.context,event:t.event}};function ft(t){return q({type:a,params:{sendId:t}},(function(e,n){var r,i=n.state,o=n.actorContext,a=R(t)?t({context:i.context,event:e.data,_event:e,self:null!==(r=null==o?void 0:o.self)&&void 0!==r?r:{},system:null==o?void 0:o.system}):t;return[i,{type:"xstate.cancel",params:{sendId:a},execute:function(t){t.self.cancel(a)}}]}))}function vt(t,e){if(null==t)return{};var n,r,i=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(i[n]=t[n]);return i}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(i[n]=t[n])}return i}var ht=new WeakMap;function dt(t,e,n){var r=ht.get(t);return r?e in r||(r[e]=n()):(r=m({},e,n()),ht.set(t,r)),r[e]}function pt(t,e,n,r){var i,o,a,s=r.machine,u=null!==(i=null==s||null===(o=s.options)||void 0===o||null===(a=o.guards)||void 0===a?void 0:a[t.type])&&void 0!==i?i:t.predicate;if(!u)throw new Error("Guard '".concat(t.type,"' is not implemented.'."));return u({context:e,event:n.data,state:r,guard:t,_event:n,evaluate:pt})}function yt(t,e){var n;return J(t)?{type:t,predicate:(null==e?void 0:e(t))||void 0,params:{type:t}}:R(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:null===(n=t.children)||void 0===n?void 0:n.map((function(t){return yt(t,e)})),predicate:(null==e?void 0:e(t.type))||t.predicate}}var mt=function(t){return"atomic"===t.type||"final"===t.type};function gt(t){return Object.values(t.states).filter((function(t){return"history"!==t.type}))}function bt(t,e){for(var n=[],r=t.parent;r&&r!==e;)n.push(r),r=r.parent;return n}function _t(t){var e,n=new Set(t),r=new Set(t),i=St(r),o=w(n);try{for(o.s();!(e=o.n()).done;){var a=e.value;if("compound"!==a.type||i.get(a)&&i.get(a).length){if("parallel"===a.type){var s,u=w(gt(a));try{for(u.s();!(s=u.n()).done;){var c=s.value;if("history"!==c.type&&!r.has(c))for(var l=0,f=At(c);l<f.length;l++){var v=f[l];r.add(v)}}}catch(t){u.e(t)}finally{u.f()}}}else At(a).forEach((function(t){return r.add(t)}))}}catch(t){o.e(t)}finally{o.f()}var h,d=w(r);try{for(d.s();!(h=d.n()).done;)for(var p=h.value.parent;p;)r.add(p),p=p.parent}catch(t){d.e(t)}finally{d.f()}return r}function xt(t,e){var n=e.get(t);if(!n)return{};if("compound"===t.type){var r=n[0];if(!r)return{};if(mt(r))return r.key}var i,o={},a=w(n);try{for(a.s();!(i=a.n()).done;){var s=i.value;o[s.key]=xt(s,e)}}catch(t){a.e(t)}finally{a.f()}return o}function St(t){var e,n=new Map,r=w(t);try{for(r.s();!(e=r.n()).done;){var i=e.value;n.has(i)||n.set(i,[]),i.parent&&(n.has(i.parent)||n.set(i.parent,[]),n.get(i.parent).push(i))}}catch(t){r.e(t)}finally{r.f()}return n}function kt(t,e){return xt(t,St(_t(e)))}function wt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t[0].machine.root;return"compound"===e.type?gt(e).some((function(e){return"final"===e.type&&t.includes(e)})):"parallel"===e.type&>(e).every((function(e){return wt(t,e)}))}var Et=function(t){return"#"===t[0]};function Tt(t,e){var n,r=z(e.target),i=null!==(n=e.external)&&void 0!==n&&n,o=t.machine.options.guards,a=It(t,r),s=b(b({},e),{},{actions:ce(N(e.actions)),guard:e.guard?yt(e.guard,(function(t){return o[t]})):void 0,target:a,source:t,external:i,eventType:e.event,toJSON:function(){return b(b({},s),{},{source:"#".concat(t.id),target:a?a.map((function(t){return"#".concat(t.id)})):void 0})}});return s}function It(t,e){if(void 0!==e)return e.map((function(e){if(!J(e))return e;if(Et(e))return t.machine.getStateNodeById(e);var n=e[0]===t.machine.delimiter;if(n&&!t.parent)return Pt(t,e.slice(1));var r=n?t.key+e:e;if(!t.parent)throw new Error('Invalid target: "'.concat(e,'" is not a valid target from the root node. Did you mean ".').concat(e,'"?'));try{return Pt(t.parent,r)}catch(e){throw new Error("Invalid transition definition for state node '".concat(t.id,"':\n").concat(e.message))}}))}function Ot(t){var e=z(t.target);return e?e.map((function(e){return"string"==typeof e?Pt(t.parent,e):e})):t.parent.initial.target}function jt(t){return"history"===t.type}function At(t){var e=new Set;return function n(r){if(!e.has(r))if(e.add(r),"compound"===r.type){var i,o=w(r.initial.target);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=w(bt(s,t));try{for(u.s();!(a=u.n()).done;){var c=a.value;e.add(c)}}catch(t){u.e(t)}finally{u.f()}n(s)}}catch(t){o.e(t)}finally{o.f()}}else if("parallel"===r.type){var l,f=w(gt(r));try{for(f.s();!(l=f.n()).done;){n(l.value)}}catch(t){f.e(t)}finally{f.f()}}}(t),k(e)}function Ct(t,e){if(Et(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(t.id,"'; no child states exist."));var n=t.states[e];if(!n)throw new Error("Child state '".concat(e,"' does not exist on '").concat(t.id,"'"));return n}function Pt(t,e){if("string"==typeof e&&Et(e))try{return t.machine.getStateNodeById(e)}catch(t){}for(var n=O(e,t.machine.delimiter).slice(),r=t;n.length;){var i=n.shift();if(!i.length)break;r=Ct(r,i)}return r}function Mt(t,e){var n=e instanceof ne?e.value:j(e,t.machine.delimiter);if(J(n))return[t,t.states[n]];var r=Object.keys(n),i=r.map((function(e){return Ct(t,e)})).filter(Boolean);return[t.machine.root,t].concat(i,r.reduce((function(e,r){var i=Ct(t,r);if(!i)return e;var o=Mt(i,n[r]);return e.concat(o)}),[]))}function Nt(t,e,n,r){return J(e)?function(t,e,n,r){var i=Ct(t,e).next(n,r);return i&&i.length?i:t.next(n,r)}(t,e,n,r):1===Object.keys(e).length?function(t,e,n,r){var i=Object.keys(e),o=Nt(Ct(t,i[0]),e[i[0]],n,r);return o&&o.length?o:t.next(n,r)}(t,e,n,r):function(t,e,n,r){for(var i=[],o=0,a=Object.keys(e);o<a.length;o++){var s=a[o],u=e[s];if(u){var c=Nt(Ct(t,s),u,n,r);c&&i.push.apply(i,k(c))}}return i.length?i:t.next(n,r)}(t,e,n,r)}function Dt(t,e){for(var n=t;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function Qt(t){for(var e=[],n=t.parent;n;)e.unshift(n),n=n.parent;return e}function Rt(t,e){var n,r=new Set(t),i=new Set(e),o=w(r);try{for(o.s();!(n=o.n()).done;){var a=n.value;if(i.has(a))return!0}}catch(t){o.e(t)}finally{o.f()}var s,u=w(i);try{for(u.s();!(s=u.n()).done;){var c=s.value;if(r.has(c))return!0}}catch(t){u.e(t)}finally{u.f()}return!1}function Jt(t,e,n){var r,i=new Set,o=w(t);try{for(o.s();!(r=o.n()).done;){var a,s=r.value,u=!1,c=new Set,l=w(i);try{for(l.s();!(a=l.n()).done;){var f=a.value;if(Rt($t([s],e,n),$t([f],e,n))){if(!Dt(s.source,f.source)){u=!0;break}c.add(f)}}}catch(t){l.e(t)}finally{l.f()}if(!u){var v,h=w(c);try{for(h.s();!(v=h.n()).done;){var d=v.value;i.delete(d)}}catch(t){h.e(t)}finally{h.f()}i.add(s)}}}catch(t){o.e(t)}finally{o.f()}return Array.from(i)}function Vt(t,e){if(!t.target)return[];var n,r=new Set,i=w(t.target);try{for(i.s();!(n=i.n()).done;){var o=n.value;if(jt(o))if(e[o.id]){var a,s=w(e[o.id]);try{for(s.s();!(a=s.n()).done;){var u=a.value;r.add(u)}}catch(t){s.e(t)}finally{s.f()}}else{var c,l=w(Vt({target:Ot(o)},e));try{for(l.s();!(c=l.n()).done;){var f=c.value;r.add(f)}}catch(t){l.e(t)}finally{l.f()}}else r.add(o)}}catch(t){i.e(t)}finally{i.f()}return k(r)}function Bt(t,e){var n=Vt(t,e);return n?!t.external&&"compound"===t.source.type&&n.every((function(e){return Dt(e,t.source)}))?t.source:function(t){var e,n=Qt(S(t,1)[0]),r=[],i=w(t);try{var o=function(){var t=Qt(e.value);r=n.filter((function(e){return t.includes(e)})),n=r,r=[]};for(i.s();!(e=i.n()).done;)o()}catch(t){i.e(t)}finally{i.f()}return n[n.length-1]}(n.concat(t.source)):null}function $t(t,e,n){var r,i=new Set,o=w(t);try{for(o.s();!(r=o.n()).done;){var a,s=r.value;if(null!==(a=s.target)&&void 0!==a&&a.length){var u,c=Bt(s,n),l=w(e);try{for(l.s();!(u=l.n()).done;){var f=u.value;Dt(f,c)&&i.add(f)}}catch(t){l.e(t)}finally{l.f()}}}}catch(t){o.e(t)}finally{o.f()}return k(i)}function zt(t,e,n,i){var o=e.machine,a=e._initial||t.length>0,s=new Set(e.configuration);if(!e._initial&&!a){var u=re(e,{_event:i,actions:[],transitions:[]});return u.changed=!1,u}var c=function(t,e,n,r,i){var o=e.machine,a=[],s=b({},e.historyValue),u=Jt(t,n,s),c=k(e._internalQueue);e._initial||function(t,e,n,r){var i=$t(t,e,n);i.sort((function(t,e){return e.order-t.order}));var o,a=w(i);try{var s=function(){var t,r,i=o.value,a=w((r=i,Object.keys(r.states).map((function(t){return r.states[t]})).filter((function(t){return"history"===t.type}))));try{for(a.s();!(t=a.n()).done;){var s=t.value,u=void 0;u="deep"===s.history?function(t){return mt(t)&&Dt(t,i)}:function(t){return t.parent===i},n[s.id]=Array.from(e).filter(u)}}catch(t){a.e(t)}finally{a.f()}};for(a.s();!(o=a.n()).done;)s()}catch(t){a.e(t)}finally{a.f()}var u,c=w(i);try{for(c.s();!(u=c.n()).done;){var l=u.value;r.push.apply(r,k(l.exit.flat()).concat(k(l.invoke.map((function(t){return ct(t.id)}))))),e.delete(l)}}catch(t){c.e(t)}finally{c.f()}}(u,n,s,a);a.push.apply(a,k(u.flatMap((function(t){return t.actions})))),Ut(u,n,a,c,e,s);var l=k(n),f=wt(l);if(f){var v=l.sort((function(t,e){return e.order-t.order})).flatMap((function(t){return t.exit}));a.push.apply(a,k(v))}try{var h=Xt(a,r,e,i).nextState,d=f?function(t,e,n){var r=t[0].machine,i=t.find((function(t){return"final"===t.type&&t.parent===r.root}));return i&&i.output?D(i.output,e,n):void 0}(l,h.context,r):void 0;return c.push.apply(c,k(h._internalQueue)),re(e,{actions:h.actions,configuration:l,historyValue:s,_internalQueue:c,context:h.context,_event:r,done:f,output:d,children:h.children})}catch(t){if(o.config.scxml)return re(e,{actions:[],configuration:Array.from(n),historyValue:s,_internalQueue:[B({type:"error.execution"})],context:e.context});throw t}}(e._initial?[{target:k(e.configuration).filter(mt),source:o.root,external:!0,actions:[],eventType:null,toJSON:null}]:t,e,s,i,n),f=c.context,v=re(c,{value:{},transitions:t,children:function(t,e){var n,i=b({},t.children),o=w(e);try{for(o.s();!(n=o.n()).done;){var a=n.value;if(a.type===l&&a.params.ref){var s=a.params.ref;s&&(i[s.id]=s)}else if(a.type===r){var u=a.params.actor;u&&delete i[u.id]}}}catch(t){o.e(t)}finally{o.f()}return i}(e,c.actions)});return v.changed=e._initial?void 0:!Zt(v.value,e.value)||v.actions.length>0||f!==e.context,v}function Ut(t,e,n,r,i,o){var a=new Set,s=new Set;Wt(t,o,s,a),i._initial&&s.add(i.machine.root);var u,c=w(k(a).sort((function(t,e){return t.order-e.order})));try{for(c.s();!(u=c.n()).done;){var l=u.value;e.add(l);var f,v=w(l.invoke);try{for(v.s();!(f=v.n()).done;){var h=f.value;n.push(ie(h))}}catch(t){v.e(t)}finally{v.f()}if(n.push.apply(n,k(l.entry)),s.has(l)){var d,p=w(s);try{for(p.s();!(d=p.n()).done;){var y=d.value.initial.actions;n.push.apply(n,k(y))}}catch(t){p.e(t)}finally{p.f()}}if("final"===l.type){var m=l.parent;if(!m.parent)continue;if(r.push(B(fe(m.id,l.output?D(l.output,i.context,i._event):void 0))),m.parent){var g=m.parent;"parallel"===g.type&>(g).every((function(t){return wt(k(e),t)}))&&r.push(B(fe(g.id)))}}}}catch(t){c.e(t)}finally{c.f()}}function Wt(t,e,n,r){var i,o=w(t);try{for(o.s();!(i=o.n()).done;){var a,s=i.value,u=w(s.target||[]);try{for(u.s();!(a=u.n()).done;){qt(a.value,e,n,r)}}catch(t){u.e(t)}finally{u.f()}var c,l=Bt(s,e),f=w(Vt(s,e));try{for(f.s();!(c=f.n()).done;){Lt(c.value,l,r,e,n)}}catch(t){f.e(t)}finally{f.f()}}}catch(t){o.e(t)}finally{o.f()}}function qt(t,e,n,r){if(jt(t))if(e[t.id]){var i,o=e[t.id],a=w(o);try{for(a.s();!(i=a.n()).done;){qt(i.value,e,n,r)}}catch(t){a.e(t)}finally{a.f()}var s,u=w(o);try{for(u.s();!(s=u.n()).done;){Lt(s.value,t.parent,r,e,n);var c,l=w(n);try{for(l.s();!(c=l.n()).done;){var f=c.value;n.add(f)}}catch(t){l.e(t)}finally{l.f()}}}catch(t){u.e(t)}finally{u.f()}}else{var v,h=Ot(t),d=w(h);try{for(d.s();!(v=d.n()).done;){qt(v.value,e,n,r)}}catch(t){d.e(t)}finally{d.f()}var p,y=w(h);try{for(y.s();!(p=y.n()).done;){Lt(p.value,t,r,e,n);var m,g=w(n);try{for(g.s();!(m=g.n()).done;){var b=m.value;n.add(b)}}catch(t){g.e(t)}finally{g.f()}}}catch(t){y.e(t)}finally{y.f()}}else if(r.add(t),"compound"===t.type){n.add(t);var _,x=t.initial.target,S=w(x);try{for(S.s();!(_=S.n()).done;){qt(_.value,e,n,r)}}catch(t){S.e(t)}finally{S.f()}var E,T=w(x);try{for(T.s();!(E=T.n()).done;){Lt(E.value,t,r,e,n)}}catch(t){T.e(t)}finally{T.f()}}else if("parallel"===t.type){var I,O=w(gt(t).filter((function(t){return!jt(t)})));try{var j=function(){var t=I.value;k(r).some((function(e){return Dt(e,t)}))||qt(t,e,n,r)};for(O.s();!(I=O.n()).done;)j()}catch(t){O.e(t)}finally{O.f()}}}function Lt(t,e,n,r,i){var o,a=w(bt(t,e));try{for(a.s();!(o=a.n()).done;){var s=o.value;if(n.add(s),"parallel"===s.type){var u,c=w(gt(s).filter((function(t){return!jt(t)})));try{var l=function(){var t=u.value;k(n).some((function(e){return Dt(e,t)}))||qt(t,r,i,n)};for(c.s();!(u=c.n()).done;)l()}catch(t){c.e(t)}finally{c.f()}}}}catch(t){a.e(t)}finally{a.f()}}function Xt(e,n,r,a){var s=r.machine,u=[],c=[],l=r;function f(e){var n;(u.push(e),(null==a?void 0:a.self.status)===t.InterpreterStatus.Running)&&(null===(n=e.execute)||void 0===n||n.call(e,a),delete e.execute)}function v(t){var e=function(t,e){if(L(t))return t;var n,r=e[t.type];return"function"==typeof r?q({type:"xstate.function",params:null!==(n=t.params)&&void 0!==n?n:{}},(function(e,n){var i=n.state,o={type:t.type,params:t.params,execute:function(t){return r({context:i.context,event:i.event,action:o,_event:i._event,system:t.system,self:t.self})}};return[i,o]})):r||t}(t,s.options.actions);if(L(e)){var r,u=S(e.resolve(n,{state:l,action:t,actorContext:a}),2),h=u[0],d=u[1],y=null===(r=d.params)||void 0===r?void 0:r.actions;return l=h,(d.type===i||d.type===o&&d.params.internal)&&"number"!=typeof d.params.delay&&c.push(d),d.type!==p&&f(d),void ce(y).forEach(v)}f(e)}var h,d=w(e);try{for(d.s();!(h=d.n()).done;){v(h.value)}}catch(t){d.e(t)}finally{d.f()}return{nextState:re(l,{actions:u,_internalQueue:c.map((function(t){return t.params._event}))})}}function Gt(t,e,n){var r=t,i=[];if((null==e?void 0:e.name)===nt)return r=Ft(e,r,n),i.push(r),{state:r,microstates:i};e.name!==c&&(r=zt(Ht(e,r),t,n,e),i.push(r));for(;!r.done;){var o=Kt(r);if(0===o.length){if(r.configuration.some((function(t){return t.always}))&&(r.transitions=[]),!r._internalQueue.length)break;var a,s=r.actions,u=r._internalQueue[0];(r=zt(Ht(u,r),r,n,u))._internalQueue.shift(),(a=r.actions).unshift.apply(a,k(s)),i.push(r)}if(o.length){var l,f=r.actions;(l=(r=zt(o,r,n,r._event)).actions).unshift.apply(l,k(f)),i.push(r)}}return r.done&&Ft(r._event,r,n),{state:r,microstates:i}}function Ft(t,e,n){var r,i=[],o=w(e.configuration.sort((function(t,e){return e.order-t.order})));try{for(o.s();!(r=o.n()).done;){var a=r.value;i.push.apply(i,k(a.exit))}}catch(t){o.e(t)}finally{o.f()}for(var s=0,u=Object.values(e.children);s<u.length;s++){var c=u[s];i.push(ct(c))}return Xt(i,t,e,n).nextState}function Ht(t,e){return e.machine.getTransitionData(e,t)}function Kt(t){var e,n=new Set,r=w(t.configuration.filter(mt));try{for(r.s();!(e=r.n()).done;){var i,o=e.value,a=w([o].concat(bt(o,null)));try{t:for(a.s();!(i=a.n()).done;){var s=i.value;if(s.always){var u,c=w(s.always);try{for(c.s();!(u=c.n()).done;){var l=u.value;if(void 0===l.guard||pt(l.guard,t.context,t._event,t)){n.add(l);break t}}}catch(t){c.e(t)}finally{c.f()}}}}catch(t){a.e(t)}finally{a.f()}}}catch(t){r.e(t)}finally{r.f()}return Jt(Array.from(n),new Set(t.configuration),t.historyValue)}function Yt(t,e){return kt(t,k(_t(Mt(t,e))))}function Zt(t,e){if(t===e)return!0;if(void 0===t||void 0===e)return!1;if(J(t)||J(e))return t===e;var n=Object.keys(t),r=Object.keys(e);return n.length===r.length&&n.every((function(n){return Zt(t[n],e[n])}))}var te=["configuration","transitions","tags","machine"],ee=["configuration","transitions","tags","machine","children"],ne=function(){function t(e,n){var r,i,o,a;K(this,t),this.machine=n,m(this,"tags",void 0),m(this,"value",void 0),m(this,"done",void 0),m(this,"output",void 0),m(this,"context",void 0),m(this,"historyValue",{}),m(this,"actions",[]),m(this,"event",void 0),m(this,"_internalQueue",void 0),m(this,"_event",void 0),m(this,"_initial",!1),m(this,"changed",void 0),m(this,"configuration",void 0),m(this,"transitions",void 0),m(this,"children",void 0),this.context=e.context,this._event=e._event,this._internalQueue=null!==(r=e._internalQueue)&&void 0!==r?r:[],this.event=this._event.data,this.historyValue=e.historyValue||{},this.actions=null!==(i=e.actions)&&void 0!==i?i:[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=null!==(o=e.configuration)&&void 0!==o?o:Array.from(_t(Mt(n.root,e.value))),this.transitions=e.transitions,this.children=e.children,this.value=kt(n.root,this.configuration),this.tags=new Set(P(this.configuration.map((function(t){return t.tags})))),this.done=null!==(a=e.done)&&void 0!==a&&a,this.output=e.output}return Z(t,[{key:"toStrings",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.value,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".";if(J(e))return[e];var r=Object.keys(e);return r.concat.apply(r,k(r.map((function(r){return t.toStrings(e[r],n).map((function(t){return r+n+t}))}))))}},{key:"toJSON",value:function(){this.configuration,this.transitions;var t=this.tags;this.machine;return b(b({},vt(this,te)),{},{tags:Array.from(t),meta:this.meta})}},{key:"matches",value:function(t){return I(t,this.value)}},{key:"hasTag",value:function(t){return this.tags.has(t)}},{key:"can",value:function(t){this.machine;var e=this.machine.getTransitionData(this,B(t));return!(null==e||!e.length)&&e.some((function(t){return void 0!==t.target||t.actions.length}))}},{key:"nextEvents",get:function(){var t=this;return dt(this,"nextEvents",(function(){return k(new Set(P(k(t.configuration.map((function(t){return t.ownEvents}))))))}))}},{key:"meta",get:function(){return this.configuration.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})}}],[{key:"from",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0;if(e instanceof t)return e.context!==n?new t({value:e.value,context:n,_event:e._event,actions:[],meta:{},configuration:[],transitions:[],children:{}},r):e;var i=de({}),o=_t(Mt(r.root,e));return new t({value:e,context:n,_event:i,actions:[],meta:void 0,configuration:Array.from(o),transitions:[],children:{}},r)}}]),t}();function re(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new ne(b(b({},t),e),t.machine)}function ie(e){return q({type:l,params:e},(function(n,r){var i,o,a=r.state,s=r.actorContext,u=l,c=e.id,f=e.src;if((o=f)&&"object"===E(o)&&"function"==typeof o.send)i={type:u,params:b(b({},e),{},{ref:f})};else{var v=W(a.machine.options.actors[f]);if(v){var h="input"in e?e.input:v.input,d=ut(v.src,{id:c,src:f,parent:null==s?void 0:s.self,systemId:e.systemId,input:"function"==typeof h?h({context:a.context,event:n.data,self:null==s?void 0:s.self}):h});i={type:u,params:b(b({},e),{},{ref:d})}}else i={type:u,params:e}}var p=i.params.ref,y=re(a,{children:b(b({},a.children),{},m({},c,p))});return i.execute=function(e){var n=e.self,r=i.params,o=r.id;r.ref&&e.defer((function(){if(p.status!==t.InterpreterStatus.Stopped)try{var e;null===(e=p.start)||void 0===e||e.call(p)}catch(t){return void n.send(he(o,t))}}))},[y,i]}))}function oe(t,e,n,r,i){return function(o){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(J(o)){var s=W(e.options.actors[o]);if(s){var u,c=null!==(u=a.id)&&void 0!==u?u:"anon",l="input"in a?a.input:s.input,f=ut(s.src,{id:c,parent:t,input:"function"==typeof l?l({context:n,event:r.data,self:t}):l});return i.push(ie({id:f.id,src:f,ref:f,meta:void 0,input:l})),f}throw new Error("Behavior '".concat(o,"' not implemented in machine '").concat(e.id,"'"))}var v=ut(o,{id:a.id||"anonymous",parent:t,input:a.input});return i.push(ie({src:v,ref:v,id:v.id,meta:void 0,input:a.input})),v}}function ae(t){return q({type:s,params:{assignment:t}},(function(e,n){var r,i=n.state,o=n.action,a=n.actorContext,u=[];if(!i.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");var c={context:i.context,event:e.data,action:o,_event:e,spawn:oe(null==a?void 0:a.self,i.machine,i.context,e,u),self:null!==(r=null==a?void 0:a.self)&&void 0!==r?r:{},system:null==a?void 0:a.system},l={};if(R(t))l=t(c);else for(var f=0,v=Object.keys(t);f<v.length;f++){var h=v[f],d=t[h];l[h]=R(d)?d(c):d}var p=Object.assign({},i.context,l);return[re(i,{context:p}),{type:s,params:{context:p,actions:u}}]}))}var se=B({type:c});function ue(t){if(L(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){var e="xstate.function";return q({type:e,params:{}},(function(n,r){var i=r.state,o={type:e,params:{function:t},execute:function(e){return t({context:i.context,event:n.data,action:o,_event:n,self:e.self,system:e.system})}};return[i,o]}))}return t}var ce=function(t){return t?(Q(t)?t:[t]).map(ue):[]};function le(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function fe(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function ve(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,output:n,toString:function(){return r}};return i}function he(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function de(t){return B({type:c,input:t})}var pe=["onDone","onError"],ye={},me=function(){function t(e,n){var r=this;if(K(this,t),this.config=e,m(this,"key",void 0),m(this,"id",void 0),m(this,"type",void 0),m(this,"path",void 0),m(this,"states",void 0),m(this,"history",void 0),m(this,"entry",void 0),m(this,"exit",void 0),m(this,"parent",void 0),m(this,"machine",void 0),m(this,"meta",void 0),m(this,"output",void 0),m(this,"order",-1),m(this,"description",void 0),m(this,"tags",[]),m(this,"transitions",void 0),m(this,"always",void 0),this.parent=n._parent,this.key=n._key,this.machine=n._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id].concat(k(this.path)).join(this.machine.delimiter),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?C(this.config.states,(function(e,n){return new t(e,{_parent:r,_key:n,_machine:r.machine})})):ye,"compound"===this.type&&!this.config.initial)throw new Error('No initial state specified for compound state node "#'.concat(this.id,'". Try adding { initial: "').concat(Object.keys(this.states)[0],'" } to the state config.'));this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=ce(this.config.entry),this.exit=ce(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=N(e.tags)}return Z(t,[{key:"_initialize",value:function(){var t=this;this.transitions=function(t){var e=[];if(Array.isArray(t.config.on))e.push.apply(e,k(t.config.on));else if(t.config.on){for(var n=t.config.on,r=n[T],i=void 0===r?[]:r,o=vt(n,[T].map(y)),a=0,s=Object.keys(o);a<s.length;a++){var u=s[a];if(""===u)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');var c=$(u,o[u]);e.push.apply(e,k(c))}e.push.apply(e,k($(T,i)))}var l,f=t.config.onDone?$(String(fe(t.id)),t.config.onDone):[],v=t.invoke.flatMap((function(t){var e=[];return t.onDone&&e.push.apply(e,k($("done.invoke.".concat(t.id),t.onDone))),t.onError&&e.push.apply(e,k($("error.platform.".concat(t.id),t.onError))),t.onSnapshot&&e.push.apply(e,k($("xstate.snapshot.".concat(t.id),t.onSnapshot))),e})),h=t.after,d=[].concat(k(f),k(v),e).flatMap((function(e){return N(e).map((function(e){return Tt(t,e)}))})),p=w(h);try{for(p.s();!(l=p.n()).done;){var m=l.value;d.push(m)}}catch(t){p.e(t)}finally{p.f()}return d}(this),this.config.always&&(this.always=$("",this.config.always).map((function(e){return Tt(t,e)}))),Object.keys(this.states).forEach((function(e){t.states[e]._initialize()}))}},{key:"definition",get:function(){var t=this;return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions,eventType:null,external:!1,toJSON:function(){return{target:t.initial.target.map((function(t){return"#".concat(t.id)})),source:"#".concat(t.id),actions:t.initial.actions,eventType:null}}}:void 0,history:this.history,states:C(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.entry,exit:this.exit,meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}},{key:"toJSON",value:function(){return this.definition}},{key:"invoke",get:function(){var t=this;return dt(this,"invoke",(function(){return N(t.config.invoke).map((function(e,n){var r,i,o=(r=t.id,i=n,"".concat(r,":invocation[").concat(i,"]")),a=function(t,e){if("object"===E(t)){if("src"in t)return t;if("transition"in t)return{id:e,src:t}}return{id:e,src:t}}(e,o),s=a.id||o,u=a.src,c=a.systemId,f=J(u)||"type"in u?u:s;return t.machine.options.actors[s]||"string"==typeof u||"type"in u||(t.machine.options.actors=b(b({},t.machine.options.actors),{},m({},s,u))),b(b({type:l},a),{},{src:f,id:s,systemId:c,toJSON:function(){a.onDone,a.onError;return b(b({},vt(a,pe)),{},{type:l,src:f,id:s})}})}))}))}},{key:"on",get:function(){var t=this;return dt(this,"on",(function(){return t.transitions.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})}))}},{key:"after",get:function(){var t=this;return dt(this,"delayedTransitions",(function(){return function(t){var e=t.config.after;if(!e)return[];var n=function(e,n){var r=le(R(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.entry.push(X({type:r},{delay:e})),t.exit.push(ft(r)),r};return(Q(e)?e.map((function(t,e){var r=n(t.delay,e);return b(b({},t),{},{event:r})})):Object.keys(e).flatMap((function(t,r){var i=e[t],o=J(i)?{target:i}:i,a=isNaN(+t)?t:+t,s=n(a,r);return N(o).map((function(t){return b(b({},t),{},{event:s,delay:a})}))}))).map((function(e){var n=e.delay;return b(b({},Tt(t,e)),{},{delay:n})}))}(t)}))}},{key:"initial",get:function(){var t=this;return dt(this,"initial",(function(){return function(t,e){if(J(e)||Q(e)){var n=N(e).map((function(e){var n=J(e)?Et(e)?t.machine.getStateNodeById(e):t.states[e]:e;if(!n)throw new Error('Initial state node "'.concat(e,'" not found on parent state node #').concat(t.id));if(!Dt(n,t))throw new Error("Invalid initial target: state node #".concat(n.id," is not a descendant of #").concat(t.id));return n})),r=It(t,n),i={source:t,actions:[],eventType:null,external:!1,target:r,toJSON:function(){return b(b({},i),{},{source:"#".concat(t.id),target:r?r.map((function(t){return"#".concat(t.id)})):void 0})}};return i}return Tt(t,{target:N(e.target).map((function(e){return J(e)?Et(e)?e:"".concat(t.machine.delimiter).concat(e):e})),actions:e.actions,event:null})}(t,t.config.initial||[])}))}},{key:"handles",value:function(t){return this.events.includes(t.type)}},{key:"next",value:function(t,e){var n,r,i=this,o=e.name,a=[],s=w(dt(this,"candidates-".concat(o.toString()),(function(){return function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.transitions.filter((function(t){var r=t.eventType;if(r===e)return!0;if(r===T)return!0;if(!n&&!r.endsWith(".*"))return!1;for(var i=r.split("."),o=e.split("."),a=0;a<i.length;a++){var s=i[a],u=o[a];if("*"===s)return a===i.length-1;if(s!==u)return!1}return!0}))}(i,o,i.machine.config.scxml)})));try{for(s.s();!(r=s.n()).done;){var u=r.value,c=u.guard,l=t.context,f=!1;try{f=!c||pt(c,l,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(c.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(f){a.push.apply(a,k(u.actions)),n=u;break}}}catch(t){s.e(t)}finally{s.f()}return n?[n]:void 0}},{key:"target",get:function(){if("history"===this.type)return this.config.target}},{key:"stateIds",get:function(){var t=this,e=P(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)}},{key:"events",get:function(){var t=this;return dt(this,"events",(function(){var e=t.states,n=new Set(t.ownEvents);if(e)for(var r=0,i=Object.keys(e);r<i.length;r++){var o=e[i[r]];if(o.states){var a,s=w(o.events);try{for(s.s();!(a=s.n()).done;){var u=a.value;n.add("".concat(u))}}catch(t){s.e(t)}finally{s.f()}}}return Array.from(n)}))}},{key:"ownEvents",get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&!t.external)})).map((function(t){return t.eventType})));return Array.from(t)}}]),t}();var ge=function(){function t(e,n){var r;K(this,t),this.config=e,m(this,"version",void 0),m(this,"delimiter",void 0),m(this,"options",void 0),m(this,"schema",void 0),m(this,"__xstatenode",!0),m(this,"idMap",new Map),m(this,"root",void 0),m(this,"id",void 0),m(this,"states",void 0),m(this,"events",void 0),m(this,"__TContext",void 0),m(this,"__TEvent",void 0),m(this,"__TAction",void 0),m(this,"__TActorMap",void 0),m(this,"__TResolvedTypesMeta",void 0),this.id=e.id||"(machine)",this.options=Object.assign({actions:{},actors:{},delays:{},guards:{},context:{}},n),this.delimiter=this.config.delimiter||".",this.version=this.config.version,this.schema=null!==(r=this.config.schema)&&void 0!==r?r:{},this.transition=this.transition.bind(this),this.root=new me(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}return Z(t,[{key:"getContext",value:function(t){return this.getContextAndActions(void 0,t)[0]}},{key:"getContextAndActions",value:function(t,e){var n=[],r=this.config.context;return[("function"==typeof r?r({spawn:oe(null==t?void 0:t.self,this,void 0,de(e),n),input:e}):r)||{},n]}},{key:"provide",value:function(e){var n=this.options,r=n.actions,i=n.guards,o=n.actors,a=n.delays;return new t(this.config,{actions:b(b({},r),e.actions),guards:b(b({},i),e.guards),actors:b(b({},o),e.actors),delays:b(b({},a),e.delays)})}},{key:"resolveState",value:function(t){var e=_t(Mt(this.root,t.value)),n=Array.from(e);return this.createState(b(b({},t),{},{value:Yt(this.root,t.value),configuration:n,done:wt(n)}))}},{key:"resolveStateValue",value:function(t){var e=Yt(this.root,t),n=this.getContext();return this.resolveState(ne.from(e,n,this))}},{key:"transition",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=t instanceof ne?t:this.resolveStateValue(t),i=B(e);if(V(i)&&!r.nextEvents.some((function(t){return t===i.name})))throw i.data.data;var o=Gt(r,i,n),a=o.state;return a}},{key:"microstep",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.initialState,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=B(e),i=Gt(t,r,n),o=i.microstates;return o}},{key:"getTransitionData",value:function(t,e){return Nt(this.root,t.value,t,e)||[]}},{key:"getPreInitialState",value:function(t,e){var n,r=S(this.getContextAndActions(t,e),2),i=r[0],o=r[1],a=function(t){var e=[],n=t.initial,r=new Set;Wt([n],{},new Set([t]),r);var i,o=w(k(r).sort((function(t,e){return t.order-e.order})));try{for(o.s();!(i=o.n()).done;){var a=i.value;e.push(a)}}catch(t){o.e(t)}finally{o.f()}return e}(this.root),s=this.resolveState(this.createState({value:{},context:i,_event:de({}),actions:[],meta:void 0,configuration:a,transitions:[],children:{}}));if(s._initial=!0,(n=s.actions).unshift.apply(n,k(o)),t){var u=Xt(o,se,s,t).nextState;s.children=u.children,s.actions=u.actions}return s}},{key:"initialState",get:function(){return this.getInitialState()}},{key:"getInitialState",value:function(t,e){var n,r=de(e),i=this.getPreInitialState(t,e),o=zt([],i,t,r);return(n=o.actions).unshift.apply(n,k(i.actions)),Gt(o,r,t).state}},{key:"start",value:function(t,e){t.actions.forEach((function(t){var n;null===(n=t.execute)||void 0===n||n.call(t,e)})),Object.values(t.children).forEach((function(t){if(0===t.status)try{var n;null===(n=t.start)||void 0===n||n.call(t)}catch(n){e.self.send(he(t.id,n))}}))}},{key:"getStateNodeById",value:function(t){var e=t.split(this.delimiter),n=e.slice(1),r=Et(e[0])?e[0].slice("#".length):e[0],i=this.idMap.get(r);if(!i)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return Pt(i,n)}},{key:"definition",get:function(){return b({context:this.getContext()},this.root.definition)}},{key:"toJSON",value:function(){return this.definition}},{key:"getPersistedState",value:function(t){return function(t){t.configuration,t.transitions,t.tags,t.machine;var e=t.children,n=vt(t,ee),r={};for(var i in e){var o,a;r[i]={state:null===(o=(a=e[i]).getPersistedState)||void 0===o?void 0:o.call(a),src:e[i].src}}return b(b({},n),{},{children:r})}(t)}},{key:"createState",value:function(t){var e=t instanceof ne?t:new ne(t,this);return Xt(e.actions,e._event,e,void 0).nextState}},{key:"getStatus",value:function(t){return t.done?{status:"done",data:t.output}:{status:"active"}}},{key:"restoreState",value:function(t,e){var n=this,r={};Object.keys(t.children).forEach((function(i){var o,a,s=t.children[i],u=s.state,c=s.src,l=c?null===(o=W(n.options.actors[c]))||void 0===o?void 0:o.src:void 0;if(l){var f=ut(l,{id:i,state:null===(a=l.restoreState)||void 0===a?void 0:a.call(l,u,e)});r[i]=f}}));var i=this.createState(new ne(b(b({},t),{},{children:r}),this));return i.configuration.forEach((function(t){t.invoke&&t.invoke.forEach((function(t){var i=t.id,o=t.src;if(!r[i]){var a=W(n.options.actors[o]);if(a){var s=ut(a.src,{id:i,parent:null==e?void 0:e.self,input:"input"in t?t.input:a.input});r[i]=s}}}))})),i.actions=[],i}}]),t}();function be(t){return t}var _e=be,xe=function(){function t(){K(this,t),m(this,"timeouts",new Map),m(this,"_now",0),m(this,"_id",0)}return Z(t,[{key:"now",value:function(){return this._now}},{key:"getId",value:function(){return this._id++}},{key:"setTimeout",value:function(t,e){var n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}},{key:"clearTimeout",value:function(t){this.timeouts.delete(t)}},{key:"set",value:function(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}},{key:"flushTimeouts",value:function(){var t=this;k(this.timeouts).sort((function(t,e){var n=S(t,2),r=(n[0],n[1]),i=S(e,2),o=(i[0],i[1]),a=r.start+r.timeout;return o.start+o.timeout>a?-1:1})).forEach((function(e){var n=S(e,2),r=n[0],i=n[1];t.now()-i.start>=i.timeout&&(t.timeouts.delete(r),i.fn.call(null))}))}},{key:"increment",value:function(t){this._now+=t,this.flushTimeouts()}}]),t}(),Se={raise:function(t,e){return q({type:i,params:{delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type}},(function(n,r){var o,a,s=r.state,u=r.actorContext,c={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},l={context:s.context,event:n.data,_event:n,self:null!==(o=null==u?void 0:u.self)&&void 0!==o?o:{},system:null==u?void 0:u.system},f=s.machine.options.delays,v=B("function"==typeof t?t(l):t);if("string"==typeof c.delay){var h=f&&f[c.delay];a="function"==typeof h?h(l):h}else a="function"==typeof c.delay?c.delay(l):c.delay;var d={type:i,params:b(b({},c),{},{_event:v,event:v.data,delay:a}),execute:function(t){"number"!=typeof d.params.delay||t.self.delaySend(d)}};return[s,d]}))},send:X,sendParent:G,sendTo:H,log:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:lt,e=arguments.length>1?arguments[1]:void 0;return q({type:u,params:{label:e,expr:t}},(function(n,r){var i,o=r.state,a=r.actorContext,s="function"==typeof t?t({context:o.context,event:n.data,_event:n,self:null!==(i=null==a?void 0:a.self)&&void 0!==i?i:{},system:null==a?void 0:a.system}):t;return[o,{type:"xstate.log",params:{label:e,value:s},execute:function(t){var n,r;e?null===(n=t.logger)||void 0===n||n.call(t,e,s):null===(r=t.logger)||void 0===r||r.call(t,s)}}]}))},cancel:ft,stop:ct,assign:ae,after:le,done:fe,respond:function(t,e){return X(t,b(b({},e),{},{to:function(t){return t._event.origin}}))},forwardTo:F,escalate:function(e,n){return G((function(t){return{type:h,data:R(e)?e(t):e}}),b(b({},n),{},{to:t.SpecialTargets.Parent}))},choose:function(t){return q({type:d,params:{guards:t}},(function(e,n){var r,i=n.state,o=null===(r=t.find((function(t){var n=t.guard&&yt(t.guard,(function(t){return i.machine.options.guards[t]}));return!n||pt(n,i.context,e,i)})))||void 0===r?void 0:r.actions;return[i,{type:d,params:{actions:ce(o)}}]}))},pure:function(t){return q({type:p,params:{get:t}},(function(e,n){var r,i=n.state;return[i,{type:p,params:{actions:null!==(r=N(ce(t({context:i.context,event:e.data}))))&&void 0!==r?r:[]}}]}))}};t.Interpreter=st,t.SimulatedClock=xe,t.State=ne,t.StateMachine=ge,t.StateNode=me,t.actions=Se,t.assign=ae,t.createMachine=function(t,e){return new ge(t,e)},t.createSchema=be,t.doneInvoke=ve,t.forwardTo=F,t.getStateNodes=Mt,t.interpret=ut,t.mapState=function(t,e){for(var n,r=0,i=Object.keys(t);r<i.length;r++){var o=i[r];I(o,e)&&(!n||e.length>n.length)&&(n=o)}return t[n]},t.matchesState=I,t.pathToStateValue=A,t.send=X,t.sendParent=G,t.sendTo=H,t.t=_e,t.toObserver=U,t.toSCXMLEvent=B,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";let e=function(t){return t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Pure="xstate.pure",t.Choose="xstate.choose",t}({}),n=function(t){return t.Parent="#_parent",t.Internal="#_internal",t}({});const s=e.Stop,i=e.Raise,o=e.Send,r=e.Cancel,a=e.Assign;e.After,e.DoneState;const c=e.Log,u=e.Init,h=e.Invoke,d=e.ErrorExecution,f=e.ErrorPlatform,p=e.ErrorCustom,l=e.Choose,y=e.Pure,v=".",m="",g="",x="*";function b(t,e,n=v){const s=S(t,n),i=S(e,n);return C(i)?!!C(s)&&i===s:C(s)?s in i:Object.keys(s).every((t=>t in i&&b(s[t],i[t])))}function _(t,e){try{return O(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function S(t,e){if("object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n)return t.value;var n;if(O(t))return w(t);if("string"!=typeof t)return t;return w(_(t,e))}function w(t){if(1===t.length)return t[0];const e={};let n=e;for(let e=0;e<t.length-1;e++)e===t.length-2?n[t[e]]=t[e+1]:(n[t[e]]={},n=n[t[e]]);return e}function $(t,e){const n={},s=Object.keys(t);for(let i=0;i<s.length;i++){const o=s[i];n[o]=e(t[o],o,t,i)}return n}function E(t){return[].concat(...t)}function k(t){return O(t)?t:[t]}function I(t){return void 0===t?[]:k(t)}function T(t,e,n){if(j(t))return t({context:e,event:n});const s={},i={context:e,event:n};for(const e of Object.keys(t)){const n=t[e];j(n)?s[e]=n(i):s[e]=n}return s}function O(t){return Array.isArray(t)}function j(t){return"function"==typeof t}function C(t){return"string"==typeof t}function A(t,e){return k(e).map((e=>void 0===e||"string"==typeof e?{target:e,event:t}:{...e,event:t}))}function P(t){if(void 0!==t&&t!==m)return I(t)}function M(t,e,n){const s=()=>{},i="object"==typeof t,o=i?t:null;return{next:((i?t.next:t)||s).bind(o),error:((i?t.error:e)||s).bind(o),complete:((i?t.complete:n)||s).bind(o)}}function N(t){return t?"transition"in t?{src:t,input:void 0}:t:void 0}function D(t,e){return{type:t.type,params:t.params,resolve:e}}function R(t){return"object"==typeof t&&null!==t&&"resolve"in t}function J(t,e){return D({type:o,params:{to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:j(t)?t.name:t.type}},((s,{actorContext:i,state:r})=>{const a={to:e?e.to:void 0,delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:j(t)?t.name:t.type},c={context:r.context,event:s,self:i?.self??null,system:i?.system},u=r.machine.options.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${t}" }) instead`);const h=j(t)?t(c):t;let d;if(C(a.delay)){const t=u&&u[a.delay];d=j(t)?t(c):t}else d=j(a.delay)?a.delay(c):a.delay;const f=j(a.to)?a.to(c):a.to;let l;if("string"==typeof f){if(l=f===n.Parent?i?.self._parent:f===n.Internal?i?.self:f.startsWith("#_")?r.children[f.slice(2)]:r.children[f],!l)throw new Error(`Unable to send event to actor '${f}' from machine '${r.machine.id}'.`)}else l=f||i?.self;const y={type:o,params:{...a,to:l,event:h,delay:d,internal:f===n.Internal},execute:t=>{const e=y;if("number"!=typeof e.params.delay){const n=e.params.to,s=e.params.event;t.defer((()=>{n.send(s.type===p?{type:`${Yt(t.self.id)}`,data:s.data}:e.params.event)}))}else t.self.delaySend(e)}};return[r,y]}))}class Q{constructor(t){this._process=t,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}prepend(t){this._current?this._current={value:t,next:this._current}:this.enqueue(t)}enqueue(t){const e={value:t,next:null};if(this._current)return this._last.next=e,void(this._last=e);this._current=e,this._last=e,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),t===this._current&&(this._current=this._current.next)}this._last=null}}const V="function"==typeof Symbol&&Symbol.observable||"@@observable";const B="xstate.init",z="xstate.stop";function U(t){return t===B||t===z}function W(){const t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:window;if(t.__xstate__)return t.__xstate__}const q=t=>{const e=W();e&&e.register(t)};let L=function(t){return t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped",t}({});const F={deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1};class G{constructor(t,e){this.behavior=t,this._state=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Q(this._process.bind(this)),this.delayedEventsMap={},this.observers=new Set,this.logger=void 0,this.status=L.NotStarted,this._parent=void 0,this.ref=void 0,this._actorContext=void 0,this._systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const n={...F,...e},{clock:s,logger:i,parent:o,id:r,systemId:a}=n;this.system=o?.system??function(){let t=0;const e=new Map,n=new Map,s=new WeakMap;return{_bookId:()=>"x:"+t++,_register:(t,n)=>(e.set(t,n),t),_unregister:t=>{e.delete(t.sessionId);const i=s.get(t);void 0!==i&&(n.delete(i),s.delete(t))},get:t=>n.get(t),_set:(t,e)=>{const i=n.get(t);if(i&&i!==e)throw new Error(`Actor with system ID '${t}' already exists.`);n.set(t,e),s.set(e,t)}}}(),a&&(this._systemId=a,this.system._set(a,this)),this.sessionId=this.system._bookId(),this.id=r??this.sessionId,this.logger=i,this.clock=s,this._parent=o,this.options=n,this.src=n.src,this.ref=this,this._actorContext={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:t=>{this._deferred.push(t)},system:this.system,stopChild:t=>{if(t._parent!==this)throw new Error(`Cannot stop child actor ${t.id} of ${this.id} because it is not a child`);t._stop()}},this.send=this.send.bind(this),this._initState()}_initState(){this._state=this.options.state?this.behavior.restoreState?this.behavior.restoreState(this.options.state,this._actorContext):this.options.state:this.behavior.getInitialState(this._actorContext,this.options?.input)}update(t){this._state=t;const e=this.getSnapshot();let n;for(;n=this._deferred.shift();)n(t);for(const t of this.observers)t.next?.(e);const s=this.behavior.getStatus?.(t);switch(s?.status){case"done":this._stopProcedure(),this._doneEvent=Kt(this.id,s.data),this._parent?.send(this._doneEvent),this._complete();break;case"error":this._stopProcedure(),this._parent?.send(Yt(this.id,s.data)),this._error(s.data)}}subscribe(t,e,n){const s=M(t,e,n);return this.observers.add(s),this.status===L.Stopped&&(s.complete?.(),this.observers.delete(s)),{unsubscribe:()=>{this.observers.delete(s)}}}onDone(t){return this.status===L.Stopped&&this._doneEvent?t(this._doneEvent):this.observers.add({complete:()=>{this._doneEvent&&t(this._doneEvent)}}),this}start(){return this.status===L.Running||(this.system._register(this.sessionId,this),this._systemId&&this.system._set(this._systemId,this),this.status=L.Running,this.behavior.start&&this.behavior.start(this._state,this._actorContext),this.update(this._state),this.options.devTools&&this.attachDevTools(),this.mailbox.start()),this}_process(t){try{const e=this.behavior.transition(this._state,t,this._actorContext);this.update(e),t.type===z&&(this._stopProcedure(),this._complete())}catch(t){if(!(this.observers.size>0))throw t;this.observers.forEach((e=>{e.error?.(t)})),this.stop()}}_stop(){return this.status===L.Stopped?this:(this.mailbox.clear(),this.status===L.NotStarted?(this.status=L.Stopped,this):(this.mailbox.enqueue({type:z}),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)t.complete?.();this.observers.clear()}_error(t){for(const e of this.observers)e.error?.(t);this.observers.clear()}_stopProcedure(){if(this.status!==L.Running)return this;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.mailbox.clear(),this.mailbox=new Q(this._process.bind(this)),this.status=L.Stopped,this.system._unregister(this),this}send(t){if("string"==typeof t)throw new Error(`Only event objects may be sent to actors; use .send({ type: "${t}" }) instead`);if(this.status!==L.Stopped){if(this.status!==L.Running&&!this.options.deferEvents)throw new Error(`Event "${t.type}" was sent to uninitialized actor "${this.id}". Make sure .start() is called for this actor, or set { deferEvents: true } in the actor options.\nEvent: ${JSON.stringify(t)}`);this.mailbox.enqueue(t)}}delaySend(t){this.delayedEventsMap[t.params.id]=this.clock.setTimeout((()=>{"to"in t.params&&t.params.to?t.params.to.send(t.params.event):this.send(t.params.event)}),t.params.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}attachDevTools(){const{devTools:t}=this.options;if(t){("function"==typeof t?t:q)(this)}}toJSON(){return{id:this.id}}getPersistedState(){return this.behavior.getPersistedState?.(this._state)}[V](){return this}getSnapshot(){return this.behavior.getSnapshot?this.behavior.getSnapshot(this._state):this._state}}function X(t,e){return new G(t,e)}function H(t){const e=t;return D({type:s,params:{actor:e}},((t,{state:n})=>{const s=j(e)?e({context:n.context,event:t}):e,i="string"==typeof s?n.children[s]:s;return[n,{type:"xstate.stop",params:{actor:i},execute:t=>{i&&(i.status===L.Running?t.defer((()=>{t.stopChild(i)})):t.stopChild(i))}}]}))}const K=({context:t,event:e})=>({context:t,event:e});function Y(t){return D({type:r,params:{sendId:t}},((e,{state:n,actorContext:s})=>{const i=j(t)?t({context:n.context,event:e,self:s?.self??{},system:s?.system}):t;return[n,{type:"xstate.cancel",params:{sendId:i},execute:t=>{t.self.cancel(i)}}]}))}const Z=new WeakMap;function tt(t,e,n){let s=Z.get(t);return s?e in s||(s[e]=n()):(s={[e]:n()},Z.set(t,s)),s[e]}function et(t,e,n,s){const{machine:i}=s,o=i?.options?.guards?.[t.type]??t.predicate;if(!o)throw new Error(`Guard '${t.type}' is not implemented.'.`);return o({context:e,event:n,state:s,guard:t,evaluate:et})}function nt(t,e){return C(t)?{type:t,predicate:e?.(t)||void 0,params:{type:t}}:j(t)?{type:t.name,predicate:t,params:{type:t.name,name:t.name}}:{type:t.type,params:t.params||t,children:t.children?.map((t=>nt(t,e))),predicate:e?.(t.type)||t.predicate}}const st=t=>"atomic"===t.type||"final"===t.type;function it(t){return Object.values(t.states).filter((t=>"history"!==t.type))}function ot(t,e){const n=[];let s=t.parent;for(;s&&s!==e;)n.push(s),s=s.parent;return n}function rt(t){const e=new Set(t),n=new Set(t),s=ct(n);for(const t of e)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of it(t))if("history"!==e.type&&!n.has(e))for(const t of mt(e))n.add(t)}else mt(t).forEach((t=>n.add(t)));for(const t of n){let e=t.parent;for(;e;)n.add(e),e=e.parent}return n}function at(t,e){const n=e.get(t);if(!n)return{};if("compound"===t.type){const t=n[0];if(!t)return{};if(st(t))return t.key}const s={};for(const t of n)s[t.key]=at(t,e);return s}function ct(t){const e=new Map;for(const n of t)e.has(n)||e.set(n,[]),n.parent&&(e.has(n.parent)||e.set(n.parent,[]),e.get(n.parent).push(n));return e}function ut(t,e){return at(t,ct(rt(e)))}function ht(t,e=t[0].machine.root){return"compound"===e.type?it(e).some((e=>"final"===e.type&&t.includes(e))):"parallel"===e.type&&it(e).every((e=>ht(t,e)))}const dt=t=>"#"===t[0];function ft(t){const n=t.config.after;if(!n)return[];const s=(n,s)=>{const i=function(t,n){const s=n?`#${n}`:"";return`${e.After}(${t})${s}`}(j(n)?`${t.id}:delay[${s}]`:n,t.id);return t.entry.push(Lt({type:i},{delay:n})),t.exit.push(Y(i)),i};return(O(n)?n.map(((t,e)=>{const n=s(t.delay,e);return{...t,event:n}})):Object.keys(n).flatMap(((t,e)=>{const i=n[t],o=C(i)?{target:i}:i,r=isNaN(+t)?t:+t,a=s(r,e);return I(o).map((t=>({...t,event:a,delay:r})))}))).map((e=>{const{delay:n}=e;return{...pt(t,e),delay:n}}))}function pt(t,e){const n=P(e.target),s=e.reenter??!1,{guards:i}=t.machine.options,o=lt(t,n),r={...e,actions:Xt(I(e.actions)),guard:e.guard?nt(e.guard,(t=>i[t])):void 0,target:o,source:t,reenter:s,eventType:e.event,toJSON:()=>({...r,source:`#${t.id}`,target:o?o.map((t=>`#${t.id}`)):void 0})};return r}function lt(t,e){if(void 0!==e)return e.map((e=>{if(!C(e))return e;if(dt(e))return t.machine.getStateNodeById(e);const n=e[0]===t.machine.delimiter;if(n&&!t.parent)return xt(t,e.slice(1));const s=n?t.key+e:e;if(!t.parent)throw new Error(`Invalid target: "${e}" is not a valid target from the root node. Did you mean ".${e}"?`);try{return xt(t.parent,s)}catch(e){throw new Error(`Invalid transition definition for state node '${t.id}':\n${e.message}`)}}))}function yt(t){const e=P(t.target);return e?e.map((e=>"string"==typeof e?xt(t.parent,e):e)):t.parent.initial.target}function vt(t){return"history"===t.type}function mt(t){const e=new Set;return function n(s){if(!e.has(s))if(e.add(s),"compound"===s.type)for(const i of s.initial.target){for(const n of ot(i,t))e.add(n);n(i)}else if("parallel"===s.type)for(const t of it(s))n(t)}(t),[...e]}function gt(t,e){if(dt(e))return t.machine.getStateNodeById(e);if(!t.states)throw new Error(`Unable to retrieve child state '${e}' from '${t.id}'; no child states exist.`);const n=t.states[e];if(!n)throw new Error(`Child state '${e}' does not exist on '${t.id}'`);return n}function xt(t,e){if("string"==typeof e&&dt(e))try{return t.machine.getStateNodeById(e)}catch(t){}const n=_(e,t.machine.delimiter).slice();let s=t;for(;n.length;){const t=n.shift();if(!t.length)break;s=gt(s,t)}return s}function bt(t,e){const n=e instanceof zt?e.value:S(e,t.machine.delimiter);if(C(n))return[t,t.states[n]];const s=Object.keys(n),i=s.map((e=>gt(t,e))).filter(Boolean);return[t.machine.root,t].concat(i,s.reduce(((e,s)=>{const i=gt(t,s);if(!i)return e;const o=bt(i,n[s]);return e.concat(o)}),[]))}function _t(t,e,n,s){return C(e)?function(t,e,n,s){const i=gt(t,e).next(n,s);return i&&i.length?i:t.next(n,s)}(t,e,n,s):1===Object.keys(e).length?function(t,e,n,s){const i=Object.keys(e),o=_t(gt(t,i[0]),e[i[0]],n,s);return o&&o.length?o:t.next(n,s)}(t,e,n,s):function(t,e,n,s){const i=[];for(const o of Object.keys(e)){const r=e[o];if(!r)continue;const a=_t(gt(t,o),r,n,s);a&&i.push(...a)}return i.length?i:t.next(n,s)}(t,e,n,s)}function St(t){return Object.keys(t.states).map((e=>t.states[e])).filter((t=>"history"===t.type))}function wt(t,e){let n=t;for(;n.parent&&n.parent!==e;)n=n.parent;return n.parent===e}function $t(t){const e=[];let n=t.parent;for(;n;)e.unshift(n),n=n.parent;return e}function Et(t,e){const n=new Set(t),s=new Set(e);for(const t of n)if(s.has(t))return!0;for(const t of s)if(n.has(t))return!0;return!1}function kt(t,e,n){const s=new Set;for(const i of t){let t=!1;const o=new Set;for(const r of s)if(Et(Ot([i],e,n),Ot([r],e,n))){if(!wt(i.source,r.source)){t=!0;break}o.add(r)}if(!t){for(const t of o)s.delete(t);s.add(i)}}return Array.from(s)}function It(t,e){if(!t.target)return[];const n=new Set;for(const s of t.target)if(vt(s))if(e[s.id])for(const t of e[s.id])n.add(t);else for(const t of It({target:yt(s)},e))n.add(t);else n.add(s);return[...n]}function Tt(t,e){const n=It(t,e);if(!n)return null;if(!t.reenter&&"parallel"!==t.source.type&&n.every((e=>wt(e,t.source))))return t.source;return function(t){const[e]=t;let n=$t(e),s=[];for(const e of t){const t=$t(e);s=n.filter((e=>t.includes(e))),n=s,s=[]}return n[n.length-1]}(n.concat(t.source))}function Ot(t,e,n){const s=new Set;for(const i of t)if(i.target?.length){const t=Tt(i,n);for(const n of e)wt(n,t)&&s.add(n)}return[...s]}function jt(t,e,n,i){const{machine:o}=e,r=e._initial||t.length>0,a=new Set(e.configuration);if(!e._initial&&!r){const t=Ut(e,{event:i,actions:[],transitions:[]});return t.changed=!1,t}const c=function(t,e,n,s,i){const o=[],r={...e.historyValue},a=kt(t,n,r),c=[...e._internalQueue];e._initial||function(t,e,n,s){const i=Ot(t,e,n);i.sort(((t,e)=>e.order-t.order));for(const t of i)for(const s of St(t)){let i;i="deep"===s.history?e=>st(e)&&wt(e,t):e=>e.parent===t,n[s.id]=Array.from(e).filter(i)}for(const t of i)s.push(...t.exit.flat(),...t.invoke.map((t=>H(t.id)))),e.delete(t)}(a,n,r,o);o.push(...a.flatMap((t=>t.actions))),Ct(a,n,o,c,e,r);const u=[...n],h=ht(u);if(h){const t=u.sort(((t,e)=>e.order-t.order)).flatMap((t=>t.exit));o.push(...t)}try{const{nextState:t}=Nt(o,s,e,i),n=h?function(t,e,n){const s=t[0].machine,i=t.find((t=>"final"===t.type&&t.parent===s.root));return i&&i.output?T(i.output,e,n):void 0}(u,t.context,s):void 0;return c.push(...t._internalQueue),Ut(e,{actions:t.actions,configuration:u,historyValue:r,_internalQueue:c,context:t.context,event:s,done:h,output:n,children:t.children})}catch(t){throw t}}(e._initial?[{target:[...e.configuration].filter(st),source:o.root,reenter:!0,actions:[],eventType:null,toJSON:null}]:t,e,a,i,n),{context:u,actions:d}=c,f=function(t,e){const n={...t.children};for(const t of e)if(t.type===h&&t.params.ref){const e=t.params.ref;e&&(n[e.id]=e)}else if(t.type===s){const e=t.params.actor;e&&delete n[e.id]}return n}(e,d),p=Ut(c,{value:{},transitions:t,children:f});return p.changed=e._initial?void 0:!Bt(p.value,e.value)||p.actions.length>0||u!==e.context,p}function Ct(t,e,n,s,i,o){const r=new Set,a=new Set;At(t,o,a,r),i._initial&&a.add(i.machine.root);for(const t of[...r].sort(((t,e)=>t.order-e.order))){e.add(t);for(const e of t.invoke)n.push(Wt(e));if(n.push(...t.entry),a.has(t))for(const t of a){const e=t.initial.actions;n.push(...e)}if("final"===t.type){const n=t.parent;if(!n.parent)continue;if(s.push(Ht(n.id,t.output?T(t.output,i.context,i.event):void 0)),n.parent){const t=n.parent;"parallel"===t.type&&it(t).every((t=>ht([...e],t)))&&s.push(Ht(t.id))}}}}function At(t,e,n,s){for(const i of t){for(const t of i.target||[])Pt(t,e,n,s);const t=Tt(i,e),o=It(i,e);for(const i of o)Mt(i,t,s,e,n)}}function Pt(t,e,n,s){if(vt(t))if(e[t.id]){const i=e[t.id];for(const t of i)Pt(t,e,n,s);for(const o of i){Mt(o,t.parent,s,e,n);for(const t of n)n.add(t)}}else{const i=yt(t);for(const t of i)Pt(t,e,n,s);for(const o of i){Mt(o,t,s,e,n);for(const t of n)n.add(t)}}else if(s.add(t),"compound"===t.type){n.add(t);const i=t.initial.target;for(const t of i)Pt(t,e,n,s);for(const o of i)Mt(o,t,s,e,n)}else if("parallel"===t.type)for(const i of it(t).filter((t=>!vt(t))))[...s].some((t=>wt(t,i)))||Pt(i,e,n,s)}function Mt(t,e,n,s,i){const o=ot(t,e);for(const t of o)if(n.add(t),"parallel"===t.type)for(const e of it(t).filter((t=>!vt(t))))[...n].some((t=>wt(t,e)))||Pt(e,s,i,n)}function Nt(t,e,n,s){const{machine:r}=n,a=[],c=[];let u=n;function h(t){a.push(t),s?.self.status===L.Running&&(t.execute?.(s),delete t.execute)}function d(t){const n=function(t,e){if(R(t))return t;const n=e[t.type];return"function"==typeof n?D({type:"xstate.function",params:t.params??{}},((e,{state:s})=>{const i={type:t.type,params:t.params,execute:t=>n({context:s.context,event:e,action:i,system:t.system,self:t.self})};return[s,i]})):n||t}(t,r.options.actions);if(R(n)){const[r,a]=n.resolve(e,{state:u,action:t,actorContext:s}),f=a.params?.actions;return u=r,(a.type===i||a.type===o&&a.params.internal)&&"number"!=typeof a.params.delay&&c.push(a),a.type!==y&&h(a),void Xt(f).forEach(d)}h(n)}for(const e of t)d(e);return{nextState:Ut(u,{actions:a,_internalQueue:c.map((t=>t.params.event))})}}function Dt(t,e,n){let s=t;const i=[];if(e.type===z)return s=Rt(e,s,n),i.push(s),{state:s,microstates:i};if(e.type!==u){s=jt(Jt(e,s),t,n,e),i.push(s)}for(;!s.done;){let t=Qt(s);if(0===t.length){if(s.configuration.some((t=>t.always))&&(s.transitions=[]),!s._internalQueue.length)break;{const t=s.actions,e=s._internalQueue[0];s=jt(Jt(e,s),s,n,e),s._internalQueue.shift(),s.actions.unshift(...t),i.push(s)}}if(t.length){const e=s.actions;s=jt(t,s,n,s.event),s.actions.unshift(...e),i.push(s)}}return s.done&&Rt(s.event,s,n),{state:s,microstates:i}}function Rt(t,e,n){const s=[];for(const t of e.configuration.sort(((t,e)=>e.order-t.order)))s.push(...t.exit);for(const t of Object.values(e.children))s.push(H(t));const{nextState:i}=Nt(s,t,e,n);return i}function Jt(t,e){return e.machine.getTransitionData(e,t)}function Qt(t){const e=new Set,n=t.configuration.filter(st);for(const s of n)t:for(const n of[s].concat(ot(s,null)))if(n.always)for(const s of n.always)if(void 0===s.guard||et(s.guard,t.context,t.event,t)){e.add(s);break t}return kt(Array.from(e),new Set(t.configuration),t.historyValue)}function Vt(t,e){return ut(t,[...rt(bt(t,e))])}function Bt(t,e){if(t===e)return!0;if(void 0===t||void 0===e)return!1;if(C(t)||C(e))return t===e;const n=Object.keys(t),s=Object.keys(e);return n.length===s.length&&n.every((n=>Bt(t[n],e[n])))}class zt{static from(t,e={},n){if(t instanceof zt)return t.context!==e?new zt({value:t.value,context:e,event:t.event,actions:[],meta:{},configuration:[],transitions:[],children:{}},n):t;const s=Zt({}),i=rt(bt(n.root,t));return new zt({value:t,context:e,event:s,actions:[],meta:void 0,configuration:Array.from(i),transitions:[],children:{}},n)}constructor(t,e){this.machine=e,this.tags=void 0,this.value=void 0,this.done=void 0,this.output=void 0,this.context=void 0,this.historyValue={},this.actions=[],this.event=void 0,this._internalQueue=void 0,this._initial=!1,this.changed=void 0,this.configuration=void 0,this.transitions=void 0,this.children=void 0,this.context=t.context,this._internalQueue=t._internalQueue??[],this.event=t.event,this.historyValue=t.historyValue||{},this.actions=t.actions??[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration??Array.from(rt(bt(e.root,t.value))),this.transitions=t.transitions,this.children=t.children,this.value=ut(e.root,this.configuration),this.tags=new Set(E(this.configuration.map((t=>t.tags)))),this.done=t.done??!1,this.output=t.output}toStrings(t=this.value,e="."){if(C(t))return[t];const n=Object.keys(t);return n.concat(...n.map((n=>this.toStrings(t[n],e).map((t=>n+e+t)))))}toJSON(){const{configuration:t,transitions:e,tags:n,machine:s,...i}=this;return{...i,tags:Array.from(n),meta:this.meta}}matches(t){return b(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){const e=this.machine.getTransitionData(this,t);return!!e?.length&&e.some((t=>void 0!==t.target||t.actions.length))}get nextEvents(){return tt(this,"nextEvents",(()=>[...new Set(E([...this.configuration.map((t=>t.ownEvents))]))]))}get meta(){return this.configuration.reduce(((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t)),{})}}function Ut(t,e={}){return new zt({...t,...e},t.machine)}function Wt(t){return D({type:h,params:t},((e,{state:n,actorContext:s})=>{const i=h,{id:o,src:r}=t;let a;if((c=r)&&"object"==typeof c&&"function"==typeof c.send)a={type:i,params:{...t,ref:r}};else{const c=N(n.machine.options.actors[r]);if(c){const u="input"in t?t.input:c.input,h=X(c.src,{id:o,src:r,parent:s?.self,systemId:t.systemId,input:"function"==typeof u?u({context:n.context,event:e,self:s?.self}):u});a={type:i,params:{...t,ref:h}}}else a={type:i,params:t}}var c;const u=a.params.ref,d=Ut(n,{children:{...n.children,[o]:u}});return a.execute=t=>{const e=t.self,{id:n,ref:s}=a.params;s&&t.defer((()=>{if(u.status!==L.Stopped)try{u.start?.()}catch(t){return void e.send(Yt(n,t))}}))},[d,a]}))}function qt(t,e,n,s,i){return(o,r={})=>{if(C(o)){const a=N(e.options.actors[o]);if(a){const e=r.id??"anon",o="input"in r?r.input:a.input,c=X(a.src,{id:e,parent:t,input:"function"==typeof o?o({context:n,event:s,self:t}):o});return i.push(Wt({id:c.id,src:c,ref:c,meta:void 0,input:o})),c}throw new Error(`Behavior '${o}' not implemented in machine '${e.id}'`)}{const e=X(o,{id:r.id||"anonymous",parent:t,input:r.input});return i.push(Wt({src:e,ref:e,id:e.id,meta:void 0,input:r.input})),e}}}function Lt(t,e){return D({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}},((n,{state:s,actorContext:o})=>{const r={delay:e?e.delay:void 0,event:t,id:e&&void 0!==e.id?e.id:"function"==typeof t?t.name:t.type},a={context:s.context,event:n,self:o?.self??{},system:o?.system},c=s.machine.options.delays;if("string"==typeof t)throw new Error(`Only event objects may be used with raise; use raise({ type: "${t}" }) instead`);const u="function"==typeof t?t(a):t;let h;if("string"==typeof r.delay){const t=c&&c[r.delay];h="function"==typeof t?t(a):t}else h="function"==typeof r.delay?r.delay(a):r.delay;const d={type:i,params:{...r,event:u,delay:h},execute:t=>{"number"!=typeof d.params.delay||t.self.delaySend(d)}};return[s,d]}))}const Ft={type:u};function Gt(t){if(R(t))return t;if("string"==typeof t)return{type:t,params:{}};if("function"==typeof t){const e="xstate.function";return D({type:e,params:{}},((n,{state:s})=>{const i={type:e,params:{function:t},execute:e=>t({context:s.context,event:n,action:i,self:e.self,system:e.system})};return[s,i]}))}return t}const Xt=t=>{if(!t)return[];return(O(t)?t:[t]).map(Gt)};function Ht(t,n){const s=`${e.DoneState}.${t}`,i={type:s,output:n,toString:()=>s};return i}function Kt(t,n){const s=`${e.DoneInvoke}.${t}`,i={type:s,output:n,toString:()=>s};return i}function Yt(t,n){const s=`${e.ErrorPlatform}.${t}`,i={type:s,data:n,toString:()=>s};return i}function Zt(t){return{type:u,input:t}}const te={};class ee{constructor(t,e){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=e._parent,this.key=e._key,this.machine=e._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(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?$(this.config.states,((t,e)=>new ee(t,{_parent:this,_key:e,_machine:this.machine}))):te,"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=Xt(this.config.entry),this.exit=Xt(this.config.exit),this.meta=this.config.meta,this.output="final"===this.type?this.config.output:void 0,this.tags=I(t.tags)}_initialize(){this.transitions=function(t){const e=[];if(Array.isArray(t.config.on))e.push(...t.config.on);else if(t.config.on){const{[x]:n=[],...s}=t.config.on;for(const t of Object.keys(s)){if(t===g)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=A(t,s[t]);e.push(...n)}e.push(...A(x,n))}const n=t.config.onDone?A(String(Ht(t.id)),t.config.onDone):[],s=t.invoke.flatMap((t=>{const e=[];return t.onDone&&e.push(...A(`done.invoke.${t.id}`,t.onDone)),t.onError&&e.push(...A(`error.platform.${t.id}`,t.onError)),t.onSnapshot&&e.push(...A(`xstate.snapshot.${t.id}`,t.onSnapshot)),e})),i=t.after,o=[...n,...s,...e].flatMap((e=>I(e).map((e=>pt(t,e)))));for(const t of i)o.push(t);return o}(this),this.config.always&&(this.always=A(g,this.config.always).map((t=>pt(this,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,eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map((t=>`#${t.id}`)),source:`#${this.id}`,actions:this.initial.actions,eventType:null})}:void 0,history:this.history,states:$(this.states,(t=>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}}toJSON(){return this.definition}get invoke(){return tt(this,"invoke",(()=>I(this.config.invoke).map(((t,e)=>{const n=`${this.id}:invocation[${e}]`;const s=function(t,e){if("object"==typeof t){if("src"in t)return t;if("transition"in t)return{id:e,src:t}}return{id:e,src:t}}(t,n),i=s.id||n,{src:o,systemId:r}=s,a=C(o)||"type"in o?o:i;return this.machine.options.actors[i]||"string"==typeof o||"type"in o||(this.machine.options.actors={...this.machine.options.actors,[i]:o}),{type:h,...s,src:a,id:i,systemId:r,toJSON(){const{onDone:t,onError:e,...n}=s;return{...n,type:h,src:a,id:i}}}}))))}get on(){return tt(this,"on",(()=>this.transitions.reduce(((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t)),{})))}get after(){return tt(this,"delayedTransitions",(()=>ft(this)))}get initial(){return tt(this,"initial",(()=>function(t,e){if(C(e)||O(e)){const n=I(e).map((e=>{const n=C(e)?dt(e)?t.machine.getStateNodeById(e):t.states[e]:e;if(!n)throw new Error(`Initial state node "${e}" not found on parent state node #${t.id}`);if(!wt(n,t))throw new Error(`Invalid initial target: state node #${n.id} is not a descendant of #${t.id}`);return n})),s=lt(t,n),i={source:t,actions:[],eventType:null,reenter:!1,target:s,toJSON:()=>({...i,source:`#${t.id}`,target:s?s.map((t=>`#${t.id}`)):void 0})};return i}return pt(t,{target:I(e.target).map((e=>C(e)?dt(e)?e:`${t.machine.delimiter}${e}`:e)),actions:e.actions,event:null})}(this,this.config.initial||[])))}next(t,e){const n=e.type,s=[];let i;const o=tt(this,`candidates-${n}`,(()=>{return t=n,this.transitions.filter((e=>{const{eventType:n}=e;if(n===t)return!0;if(n===x)return!0;if(!n.endsWith(".*"))return!1;const s=n.split("."),i=t.split(".");for(let t=0;t<s.length;t++){const e=s[t],n=i[t];if("*"===e)return t===s.length-1;if(e!==n)return!1}return!0}));var t}));for(const r of o){const{guard:o}=r,a=t.context;let c=!1;try{c=!o||et(o,a,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${o.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(c){s.push(...r.actions),i=r;break}}return i?[i]:void 0}get target(){if("history"===this.type){return this.config.target}}get stateIds(){const t=E(Object.keys(this.states).map((t=>this.states[t].stateIds)));return[this.id].concat(t)}get events(){return tt(this,"events",(()=>{const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const s=t[n];if(s.states)for(const t of s.events)e.add(`${t}`)}return Array.from(e)}))}get ownEvents(){const t=new Set(this.transitions.filter((t=>!(!t.target&&!t.actions.length&&!t.reenter))).map((t=>t.eventType)));return Array.from(t)}}class ne{getContext(t){return this.getContextAndActions(void 0,t)[0]}getContextAndActions(t,e){const n=[],{context:s}=this.config;return[("function"==typeof s?s({spawn:qt(t?.self,this,void 0,Zt(e),n),input:e}):s)||{},n]}constructor(t,e){this.config=t,this.version=void 0,this.delimiter=void 0,this.options=void 0,this.types=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.__TContext=void 0,this.__TEvent=void 0,this.__TAction=void 0,this.__TActorMap=void 0,this.__TResolvedTypesMeta=void 0,this.id=t.id||"(machine)",this.options=Object.assign({actions:{},actors:{},delays:{},guards:{},context:{}},e),this.delimiter=this.config.delimiter||v,this.version=this.config.version,this.types=this.config.types??{},this.transition=this.transition.bind(this),this.root=new ee(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:e,guards:n,actors:s,delays:i}=this.options;return new ne(this.config,{actions:{...e,...t.actions},guards:{...n,...t.guards},actors:{...s,...t.actors},delays:{...i,...t.delays}})}resolveState(t){const e=rt(bt(this.root,t.value)),n=Array.from(e);return this.createState({...t,value:Vt(this.root,t.value),configuration:n,done:ht(n)})}resolveStateValue(t){const e=Vt(this.root,t),n=this.getContext();return this.resolveState(zt.from(e,n,this))}transition(t=this.initialState,e,n){const s=t instanceof zt?t:this.resolveStateValue(t);if(function(t){return"string"==typeof t.type&&(t.type===d||t.type.startsWith(f))}(e)&&!s.nextEvents.some((t=>t===e.type)))throw e.data;const{state:i}=Dt(s,e,n);return i}microstep(t=this.initialState,e,n){return Dt(t,e,n).microstates}getTransitionData(t,e){return _t(this.root,t.value,t,e)||[]}getPreInitialState(t,e){const[n,s]=this.getContextAndActions(t,e),i=function(t){const e=[],n=t.initial,s=new Set;At([n],{},new Set([t]),s);for(const t of[...s].sort(((t,e)=>t.order-e.order)))e.push(t);return e}(this.root),o=this.resolveState(this.createState({value:{},context:n,event:Zt({}),actions:[],meta:void 0,configuration:i,transitions:[],children:{}}));if(o._initial=!0,o.actions.unshift(...s),t){const{nextState:e}=Nt(s,Ft,o,t);o.children=e.children,o.actions=e.actions}return o}get initialState(){return this.getInitialState()}getInitialState(t,e){const n=Zt(e),s=this.getPreInitialState(t,e),i=jt([],s,t,n);i.actions.unshift(...s.actions);const{state:o}=Dt(i,n,t);return o}start(t,e){t.actions.forEach((t=>{t.execute?.(e)})),Object.values(t.children).forEach((t=>{if(0===t.status)try{t.start?.()}catch(n){e.self.send(Yt(t.id,n))}}))}getStateNodeById(t){const e=t.split(this.delimiter),n=e.slice(1),s=dt(e[0])?e[0].slice(1):e[0],i=this.idMap.get(s);if(!i)throw new Error(`Child state node '#${s}' does not exist on machine '${this.id}'`);return xt(i,n)}get definition(){return{context:this.getContext(),...this.root.definition}}toJSON(){return this.definition}getPersistedState(t){return function(t){const{configuration:e,transitions:n,tags:s,machine:i,children:o,...r}=t,a={};for(const t in o)a[t]={state:o[t].getPersistedState?.(),src:o[t].src};return{...r,children:a}}(t)}createState(t){const e=t instanceof zt?t:new zt(t,this),{nextState:n}=Nt(e.actions,e.event,e,void 0);return n}getStatus(t){return t.done?{status:"done",data:t.output}:{status:"active"}}restoreState(t,e){const n={};Object.keys(t.children).forEach((s=>{const i=t.children[s],o=i.state,r=i.src,a=r?N(this.options.actors[r])?.src:void 0;if(!a)return;const c=a.restoreState?.(o,e),u=X(a,{id:s,state:c});n[s]=u}));const s=this.createState(new zt({...t,children:n},this));return s.configuration.forEach((t=>{t.invoke&&t.invoke.forEach((t=>{const{id:s,src:i}=t;if(n[s])return;const o=N(this.options.actors[i]);if(o){const i=X(o.src,{id:s,parent:e?.self,input:"input"in t?t.input:o.input});n[s]=i}}))})),s.actions=[],s}}const se={timeout:1e4};t.ActionTypes=e,t.Interpreter=G,t.InterpreterStatus=L,t.SimulatedClock=class{constructor(){this.timeouts=new Map,this._now=0,this._id=0}now(){return this._now}getId(){return this._id++}setTimeout(t,e){const n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n}clearTimeout(t){this.timeouts.delete(t)}set(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()}flushTimeouts(){[...this.timeouts].sort((([t,e],[n,s])=>{const i=e.start+e.timeout;return s.start+s.timeout>i?-1:1})).forEach((([t,e])=>{this.now()-e.start>=e.timeout&&(this.timeouts.delete(t),e.fn.call(null))}))}increment(t){this._now+=t,this.flushTimeouts()}},t.SpecialTargets=n,t.State=zt,t.StateMachine=ne,t.StateNode=ee,t.and=function(t){return{type:"xstate.boolean",params:{op:"and"},children:t.map((t=>nt(t))),predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>e.children.every((e=>t(e,n,s,i)))}},t.assign=function(t){return D({type:a,params:{assignment:t}},((e,{state:n,action:s,actorContext:i})=>{const o=[];if(!n.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={context:n.context,event:e,action:s,spawn:qt(i?.self,n.machine,n.context,e,o),self:i?.self??{},system:i?.system};let c={};if(j(t))c=t(r);else for(const e of Object.keys(t)){const n=t[e];c[e]=j(n)?n(r):n}const u=Object.assign({},n.context,c);return[Ut(n,{context:u}),{type:a,params:{context:u,actions:o}}]}))},t.cancel=Y,t.choose=function(t){return D({type:l,params:{guards:t}},((e,{state:n})=>{const s=t.find((t=>{const s=t.guard&&nt(t.guard,(t=>n.machine.options.guards[t]));return!s||et(s,n.context,e,n)}))?.actions;return[n,{type:l,params:{actions:Xt(s)}}]}))},t.createMachine=function(t,e){return new ne(t,e)},t.doneInvoke=Kt,t.forwardTo=function(t,e){return J((({event:t})=>t),{...e,to:t})},t.fromCallback=function(t){return{config:t,start:(t,{self:e})=>{e.send({type:B})},transition:(e,n,{self:s,id:i})=>{if(n.type===B){const n=t=>{e.canceled||s._parent?.send(t)},r=t=>{e.receivers.add(t)};return e.dispose=t(n,r,{input:e.input}),((o=e.dispose)instanceof Promise||null!==o&&(j(o)||"object"==typeof o)&&j(o.then))&&e.dispose.then((t=>{s._parent?.send(Kt(i,t)),e.canceled=!0}),(t=>{e.canceled=!0,s._parent?.send(Yt(i,t))})),e}var o;return n.type===z?(e.canceled=!0,j(e.dispose)&&e.dispose(),e):(U(n.type)||U(n.type)||e.receivers.forEach((t=>t(n))),e)},getInitialState:(t,e)=>({canceled:!1,receivers:new Set,dispose:void 0,input:e}),getSnapshot:()=>{},getPersistedState:({input:t})=>t}},t.fromEventObservable=function(t){const e="$$xstate.error",n="$$xstate.complete";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"error",input:void 0,data:s.data,subscription:void 0};case n:return{...t,status:"done",input:void 0,subscription:void 0};case z:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(s,{self:i})=>{"done"!==s.status&&(s.subscription=t({input:s.input}).subscribe({next:t=>{i._parent?.send(t)},error:t=>{i.send({type:e,data:t})},complete:()=>{i.send({type:n})}}))},getSnapshot:t=>{},getPersistedState:({status:t,data:e,input:n})=>({status:t,data:e,input:n}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromObservable=function(t){const e="$$xstate.next",n="$$xstate.error",s="$$xstate.complete";return{config:t,transition:(t,i,{self:o,id:r,defer:a})=>{if("active"!==t.status)return t;switch(i.type){case e:return a((()=>{o._parent?.send({type:`xstate.snapshot.${r}`,data:i.data})})),{...t,data:i.data};case n:return{...t,status:"error",input:void 0,data:i.data,subscription:void 0};case s:return{...t,status:"done",input:void 0,subscription:void 0};case z:return t.subscription.unsubscribe(),{...t,status:"canceled",input:void 0,subscription:void 0};default:return t}},getInitialState:(t,e)=>({subscription:void 0,status:"active",data:void 0,input:e}),start:(i,{self:o})=>{"done"!==i.status&&(i.subscription=t({input:i.input}).subscribe({next:t=>{o.send({type:e,data:t})},error:t=>{o.send({type:n,data:t})},complete:()=>{o.send({type:s})}}))},getSnapshot:t=>t.data,getPersistedState:({status:t,data:e,input:n})=>({status:t,data:e,input:n}),getStatus:t=>t,restoreState:t=>({...t,subscription:void 0})}},t.fromPromise=function(t){const e="$$xstate.resolve",n="$$xstate.reject";return{config:t,transition:(t,s)=>{if("active"!==t.status)return t;switch(s.type){case e:return{...t,status:"done",data:s.data,input:void 0};case n:return{...t,status:"error",data:s.data,input:void 0};case z:return{...t,status:"canceled",input:void 0};default:return t}},start:(s,{self:i})=>{if("active"!==s.status)return;Promise.resolve(t({input:s.input})).then((t=>{"active"===i._state.status&&i.send({type:e,data:t})}),(t=>{"active"===i._state.status&&i.send({type:n,data:t})}))},getInitialState:(t,e)=>({status:"active",data:void 0,input:e}),getSnapshot:t=>t.data,getStatus:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.fromTransition=function(t,e){return{config:t,transition:(e,n,s)=>t(e,n,s),getInitialState:(t,n)=>"function"==typeof e?e({input:n}):e,getSnapshot:t=>t,getPersistedState:t=>t,restoreState:t=>t}},t.getStateNodes=bt,t.interpret=X,t.log=function(t=K,e){return D({type:c,params:{label:e,expr:t}},((n,{state:s,actorContext:i})=>{const o="function"==typeof t?t({context:s.context,event:n,self:i?.self??{},system:i?.system}):t;return[s,{type:"xstate.log",params:{label:e,value:o},execute:t=>{e?t.logger?.(e,o):t.logger?.(o)}}]}))},t.mapState=function(t,e){let n;for(const s of Object.keys(t))b(s,e)&&(!n||e.length>n.length)&&(n=s);return t[n]},t.matchesState=b,t.not=function(t){return{type:"xstate.boolean",params:{op:"not"},children:[nt(t)],predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>!t(e.children[0],n,s,i)}},t.or=function(t){return{type:"xstate.boolean",params:{op:"or"},children:t.map((t=>nt(t))),predicate:({evaluate:t,guard:e,context:n,event:s,state:i})=>e.children.some((e=>t(e,n,s,i)))}},t.pathToStateValue=w,t.pure=function(t){return D({type:y,params:{get:t}},((e,{state:n})=>[n,{type:y,params:{actions:I(Xt(t({context:n.context,event:e})))??[]}}]))},t.raise=Lt,t.sendParent=function(t,e){return J(t,{...e,to:n.Parent})},t.sendTo=function(t,e,n){return J(e,{...n,to:t})},t.stateIn=function(t){return{type:"xstate.guard:in",params:{stateValue:t},predicate:({state:e})=>C(t)&&dt(t)?e.configuration.some((e=>e.id===t.slice(1))):e.matches(t)}},t.stop=H,t.toObserver=M,t.waitFor=function(t,e,n){const s={...se,...n};return new Promise(((n,i)=>{let o=!1;const r=s.timeout===1/0?void 0:setTimeout((()=>{u.unsubscribe(),i(new Error(`Timeout of ${s.timeout} ms exceeded`))}),s.timeout),a=()=>{clearTimeout(r),o=!0,u?.unsubscribe()};function c(t){e(t)&&(a(),n(t))}let u;c(t.getSnapshot()),o||(u=t.subscribe({next:c,error:t=>{a(),i(t)},complete:()=>{a(),i(new Error("Actor terminated without satisfying predicate"))}}),o&&u.unsubscribe())}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=xstate.umd.min.js.map
|