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