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