xstate 4.35.0 → 4.35.2
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/README.md +3 -2
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/StateNode.js +31 -16
- package/es/actions.d.ts +4 -1
- package/es/actions.js +22 -12
- package/es/interpreter.js +4 -1
- package/es/types.d.ts +2 -2
- package/lib/StateNode.js +31 -16
- package/lib/actions.d.ts +4 -1
- package/lib/actions.js +22 -12
- package/lib/interpreter.js +4 -1
- package/lib/types.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ toggleService.send('TOGGLE');
|
|
|
63
63
|
- [Why? (info about statecharts)](#why)
|
|
64
64
|
- [Installation](https://xstate.js.org/docs/guides/installation.html)
|
|
65
65
|
- [Finite State Machines](#finite-state-machines)
|
|
66
|
-
- [Hierarchical (Nested) State Machines](#hierarchical
|
|
66
|
+
- [Hierarchical (Nested) State Machines](#hierarchical--nested--state-machines)
|
|
67
67
|
- [Parallel State Machines](#parallel-state-machines)
|
|
68
68
|
- [History States](#history-states)
|
|
69
69
|
|
|
@@ -83,7 +83,8 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
|
|
|
83
83
|
- [The World of Statecharts](https://statecharts.github.io/) by Erik Mogensen
|
|
84
84
|
- [Pure UI](https://rauchg.com/2015/pure-ui) by Guillermo Rauch
|
|
85
85
|
- [Pure UI Control](https://medium.com/@asolove/pure-ui-control-ac8d1be97a8d) by Adam Solove
|
|
86
|
-
- [
|
|
86
|
+
- [Stately Discord](https://discord.gg/xstate) chat about anything related to statecharts and XState
|
|
87
|
+
- [GitHub Discussions](https://github.com/statelyai/xstate/discussions)
|
|
87
88
|
|
|
88
89
|
## Finite State Machines
|
|
89
90
|
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */var e,n,r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a,c={};function u(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:y(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return y(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function f(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 h(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}function d(t){return void 0===t?[]:function(t){return y(t)?t:[t]}(t)}function l(t,e,n){var r,o;if(g(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),c=a.next();!c.done;c=a.next()){var u=c.value,f=t[u];g(f)?s[u]=f(e,n.data):s[u]=f}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function p(t){return t instanceof Promise||!(null===t||!g(t)&&"object"!=typeof t||!g(t.then))}function v(t,e,n,r){return t?n.reduce((function(t,n){var o,s,a=n.assignment,c={state:r,action:n,_event:e},u={};if(g(a))u=a(t,e.data,c);else try{for(var f=i(Object.keys(a)),h=f.next();!h.done;h=f.next()){var d=h.value,l=a[d];u[d]=g(l)?l(t,e.data,c):l}}catch(t){o={error:t}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,u)}),t):t}function y(t){return Array.isArray(t)}function g(t){return"function"==typeof t}function m(t){return"string"==typeof t}var x=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function b(t){return!!t&&"__xstatenode"in t}(a={})[x]=function(){return this},a[Symbol.observable]=function(){return this};var w=function(){var t=0;return function(){return(++t).toString(16)}}();function S(t,e){return m(t)||"number"==typeof t?r({type:t},e):t}function _(t,e){if(!m(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=S(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t,e,n){var r=function(){},i="object"==typeof 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)}}var O=e.Start,I=e.Stop,T=e.Raise,A=e.Send,L=e.Cancel;e.NullEvent;var k=e.Assign;e.After,e.DoneState;var j=e.Log,C=e.Init;e.Invoke,e.ErrorExecution;var P=e.ErrorPlatform,N=e.ErrorCustom,D=e.Update,M=e.Choose,R=e.Pure,z=_({type:C});function V(t,e){return e&&e[t]||void 0}function J(t,e){var n;if(m(t)||"number"==typeof t)n=g(i=V(t,e))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(g(t))n={type:t.name||t.toString(),exec:t};else{var i;if(g(i=V(t.type,e)))n=r(r({},t),{exec:i});else if(i){var o=i.type||t.type;n=r(r(r({},i),t),{type:o})}else n=t}return n}var q=function(t,e){return t?(y(t)?t:[t]).map((function(t){return J(t,e)})):[]};function U(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function $(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function F(t,a,c,u,f,l,p){void 0===p&&(p=!1);var y=p?[]:function(t){var e,n,r=[];try{for(var o=i(t),s=o.next();!s.done;s=o.next())for(var a=s.value,c=0;c<a.length;)a[c].type!==k?c++:(r.push(a[c]),a.splice(c,1))}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}(f),x=y.length?v(c,u,y,a):c,b=p?[c]:void 0,w=[];function S(i){var f;switch(i.type){case T:return{type:T,_event:_(i.event)};case A:var h=function(t,e,n,i){var o,s={_event:n},a=_(g(t.event)?t.event(e,n.data,s):t.event);if(m(t.delay)){var c=i&&i[t.delay];o=g(c)?c(e,n.data,s):c}else o=g(t.delay)?t.delay(e,n.data,s):t.delay;var u=g(t.to)?t.to(e,n.data,s):t.to;return r(r({},t),{to:u,_event:a,event:a.data,delay:o})}(i,x,u,t.options.delays);return l&&h.to!==n.Internal&&w.push(h),h;case j:var y=function(t,e,n){return r(r({},t),{value:m(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})}(i,x,u);return null==l||l(y,x,u),y;case M:if(!(L=null===(f=i.conds.find((function(e){var n=function(t,e){if(t)return m(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:g(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}(e.cond,t.options.guards);return!n||function(t,e,n,r,i){var o=t.options.guards,s={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,s);var a=null==o?void 0:o[e.type];if(!a)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return a(n,r.data,s)}(t,n,x,u,l?void 0:a)})))||void 0===f?void 0:f.actions))return[];var S=o(F(t,a,x,u,[q(d(L),t.options.actions)],l,p),2),E=S[0],O=S[1];return x=O,null==b||b.push(x),E;case R:var L;if(!(L=i.get(x,u.data)))return[];var C=o(F(t,a,x,u,[q(d(L),t.options.actions)],l,p),2),P=C[0],N=C[1];return x=N,null==b||b.push(x),P;case I:y=function(t,n,r){var i=g(t.activity)?t.activity(n,r.data):t.activity,o="string"==typeof i?{id:i}:i;return{type:e.Stop,activity:o}}(i,x,u);return null==l||l(y,c,u),y;case k:x=v(x,u,[i],l?void 0:a),null==b||b.push(x);break;default:var D=J(i,t.options.actions),z=D.exec;if(l)l(D,x,u);else if(z&&b){var V=b.length-1;D=r(r({},D),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];z.apply(void 0,s([b[V]],o(e),!1))}})}return D}}return[h(f.map((function(t){var e,n,r=[];try{for(var o=i(t),s=o.next();!s.done;s=o.next()){var a=S(s.value);a&&(r=r.concat(a))}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return w.forEach((function(t){l(t,x,u)})),w.length=0,r}))),x]}var X=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=c,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||c,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],o(new Set(h(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(r.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=z;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),m(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,r){void 0===r&&(r=".");var i=u(e,r),o=u(n,r);return m(o)?!!m(i)&&o===i:m(i)?i in o:Object.keys(i).every((function(e){return e in o&&t(i[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),Q={deferEvents:!1},B=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},Q),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),G=[],H=function(t,e){G.push(t);var n=e(t);return G.pop(),n};function K(t,e,n){var r=function(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[x]=function(){return this},e}(e);if(r.deferred=!0,b(t)){var i=r.state=H(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var W=new Map,Y=0,Z=function(){return"x:".concat(Y++)},tt=function(t,e){return W.set(t,e),t},et=function(t){return W.get(t)},nt=function(t){W.delete(t)};function rt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function it(t){if(rt()){var e=function(){var t=rt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ot(t,e){void 0===e&&(e={});var n=t.initialState,i=new Set,o=[],s=!1,a=function(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[x]=function(){return this},e),t)}({id:e.id,send:function(e){o.push(e),function(){if(!s){for(s=!0;o.length>0;){var e=o.shift();n=t.transition(n,e,c),i.forEach((function(t){return t.next(n)}))}s=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=E(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),c={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(c):n,a}var st,at={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(st=t.InterpreterStatus||(t.InterpreterStatus={}))[st.NotStarted=0]="NotStarted",st[st.Running=1]="Running",st[st.Stopped=2]="Stopped";var ct=function(){function a(i,o){void 0===o&&(o=a.defaultOptions);var s=this;this.machine=i,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(e,n){if(y(e))return s.batch(e),s.state;var r=_(S(e,n));if(s.status===t.InterpreterStatus.Stopped)return s.state;if(s.status!==t.InterpreterStatus.Running&&!s.options.deferEvents)throw new Error('Event "'.concat(r.name,'" was sent to uninitialized service "').concat(s.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(r.data)));return s.scheduler.schedule((function(){s.forward(r);var t=s._nextState(r);s.update(t,r)})),s._state},this.sendTo=function(e,i,o){var a,c=s.parent&&(i===n.Parent||s.parent.id===i),u=c?s.parent:m(i)?s.children.get(i)||et(i):(a=i)&&"function"==typeof a.send?i:void 0;if(u)if("machine"in u){if(s.status!==t.InterpreterStatus.Stopped||s.parent!==u||s.state.done){var f=r(r({},e),{name:e.name===N?"".concat($(s.id)):e.name,origin:s.sessionId});!o&&s.machine.config.predictableActionArguments?s._outgoingQueue.push([u,f]):u.send(f)}}else!o&&s.machine.config.predictableActionArguments?s._outgoingQueue.push([u,e.data]):u.send(e.data);else if(!c)throw new Error("Unable to send event to child '".concat(i,"' from service '").concat(s.id,"'."))},this._exec=function(n,r,i,o){void 0===o&&(o=s.machine.options.actions);var a,c=n.exec||V(n.type,o),u=g(c)?c:c?c.exec:n.exec;if(u)try{return u(r,i.data,s.machine.config.predictableActionArguments?{action:n,_event:i}:{action:n,state:s.state,_event:i})}catch(t){throw s.parent&&s.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case A:var f=n;if("number"==typeof f.delay)return void s.defer(f);f.to?s.sendTo(f._event,f.to,i===z):s.send(f._event);break;case L:s.cancel(n.sendId);break;case O:if(s.status!==t.InterpreterStatus.Running)return;var h=n.activity;if(!s.machine.config.predictableActionArguments&&!s.state.activities[h.id||h.type])break;if(h.type===e.Invoke){var d="string"==typeof(a=h.src)?{type:a}:a,p=s.machine.options.services?s.machine.options.services[d.type]:void 0,v=h.id,y=h.data,m="autoForward"in h?h.autoForward:!!h.forward;if(!p)return;var x=y?l(y,r,i):void 0;if("string"==typeof p)return;var w=g(p)?p(r,i.data,{data:x,src:d,meta:h.meta}):p;if(!w)return;var S=void 0;b(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),s.spawn(w,v,S)}else s.spawnActivity(h);break;case I:s.stopChild(n.activity.id);break;case j:var _=n.label,E=n.value;_?s.logger(_,E):s.logger(E)}};var c=r(r({},a.defaultOptions),o),u=c.clock,f=c.logger,h=c.parent,d=c.id,p=void 0!==d?d:i.id;this.id=p,this.logger=f,this.clock=u,this.parent=h,this.options=c,this.scheduler=new B({deferEvents:this.options.deferEvents}),this.sessionId=Z()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:H(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,r;try{for(var o=i(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value;this.exec(a,t,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},a.prototype.update=function(t,e){var n,r,o,s,a,c,u,f,h=this;if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==z||!this.options.execute)for(var d=void 0;d=this._outgoingQueue.shift();)d[0].send(d[1]);else this.execute(this.state);if(this.children.forEach((function(t){h.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var p=i(this.eventListeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t.event)}}catch(t){n={error:t}}finally{try{v&&!v.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}try{for(var y=i(this.listeners),g=y.next();!g.done;g=y.next()){(0,g.value)(t,t.event)}}catch(t){o={error:t}}finally{try{g&&!g.done&&(s=y.return)&&s.call(y)}finally{if(o)throw o.error}}try{for(var m=i(this.contextListeners),x=m.next();!x.done;x=m.next()){(0,x.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(c=m.return)&&c.call(m)}finally{if(a)throw a.error}}if(this.state.done){var b=t.configuration.find((function(t){return"final"===t.type&&t.parent===h.machine})),w=b&&b.doneData?l(b.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),_=S.next();!_.done;_=S.next()){(0,_.value)(U(this.id,w))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(f=S.return)&&f.call(S)}finally{if(u)throw u.error}}this._stop(),this._stopChildren()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,r){var i=this,o=E(e,n,r);this.listeners.add(o.next),this.status!==t.InterpreterStatus.NotStarted&&o.next(this.state);var s=function(){i.doneListeners.delete(s),i.stopListeners.delete(s),o.complete()};return this.status===t.InterpreterStatus.Stopped?o.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:function(){i.listeners.delete(o.next),i.doneListeners.delete(s),i.stopListeners.delete(s)}}},a.prototype.onEvent=function(t){return this.eventListeners.add(t),this},a.prototype.onSend=function(t){return this.sendListeners.add(t),this},a.prototype.onChange=function(t){return this.contextListeners.add(t),this},a.prototype.onStop=function(t){return this.stopListeners.add(t),this},a.prototype.onDone=function(t){return this.doneListeners.add(t),this},a.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},a.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),tt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:H(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(X.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,z)})),this},a.prototype._stopChildren=function(){this.children.forEach((function(t){g(t.stop)&&t.stop()})),this.children.clear()},a.prototype._stop=function(){var e,n,r,o,s,a,c,u,f,h;try{for(var d=i(this.listeners),l=d.next();!l.done;l=d.next()){var p=l.value;this.listeners.delete(p)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(n=d.return)&&n.call(d)}finally{if(e)throw e.error}}try{for(var v=i(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){s={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(s)throw s.error}}try{for(var x=i(this.doneListeners),b=x.next();!b.done;b=x.next()){p=b.value;this.doneListeners.delete(p)}}catch(t){c={error:t}}finally{try{b&&!b.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0;try{for(var w=i(Object.keys(this.delayedEventsMap)),S=w.next();!S.done;S=w.next()){var _=S.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){f={error:t}}finally{try{S&&!S.done&&(h=w.return)&&h.call(w)}finally{if(f)throw f.error}}this.scheduler.clear(),this.scheduler=new B({deferEvents:this.options.deferEvents})},a.prototype.stop=function(){var t=this,e=this.scheduler;return this._stop(),e.schedule((function(){var e=_({type:"xstate.stop"}),r=H(t,(function(){var r=h(s([],o(t.state.configuration),!1).sort((function(t,e){return e.order-t.order})).map((function(e){return q(e.onExit,t.machine.options.actions)}))),i=o(F(t.machine,t.state,t.state.context,e,[r],t.machine.config.predictableActionArguments?t._exec:void 0,t.machine.config.predictableActionArguments||t.machine.config.preserveActionOrder),2),a=i[0],c=i[1],u=new X({value:t.state.value,context:c,_event:e,_sessionid:t.sessionId,historyValue:void 0,history:t.state,actions:a.filter((function(t){return t.type!==T&&(t.type!==A||!!t.to&&t.to!==n.Internal)})),activities:{},events:[],configuration:[],transitions:[],children:{},done:t.state.done,tags:t.state.tags,machine:t.machine});return u.changed=!0,u}));t.update(r,e),t._stopChildren(),nt(t.sessionId)})),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var a=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule((function(){var t,c,u=n.state,f=!1,h=[],d=function(t){var e=_(t);n.forward(e),u=H(n,(function(){return n.machine.transition(u,e,void 0,a||void 0)})),h.push.apply(h,s([],o(n.machine.config.predictableActionArguments?u.actions:u.actions.map((function(t){return function(t,e){var n=t.exec;return r(r({},t),{exec:void 0!==n?function(){return n(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0})}(t,u)}))),!1)),f=f||!!u.changed};try{for(var l=i(e),p=l.next();!p.done;p=l.next()){d(p.value)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(c=l.return)&&c.call(l)}finally{if(t)throw t.error}}u.changed=f,u.actions=h,n.update(u,_(e[e.length-1]))}))}},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype._nextState=function(t,e){var n=this;void 0===e&&(e=!!this.machine.config.predictableActionArguments&&this._exec);var r=_(t);if(0===r.name.indexOf(P)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(P)})))throw r.data.data;return H(this,(function(){return n.machine.transition(n.state,r,void 0,e||void 0)}))},a.prototype.nextState=function(t){return this._nextState(t,!1)},a.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(s,"'."));a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},a.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to,!0):e.send(t._event)}),t.delay)},a.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},a.prototype.exec=function(t,e,n){void 0===n&&(n=this.machine.options.actions),this._exec(t,e.context,e._event,n)},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),g(e.stop)&&e.stop())},a.prototype.spawn=function(e,n,i){if(this.status!==t.InterpreterStatus.Running)return K(e,n);if(p(e))return this.spawnPromise(Promise.resolve(e),n);if(g(e))return this.spawnCallback(e,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=e)&&"id"in s)return this.spawnActor(e,n);if(function(t){try{return"subscribe"in t&&g(t.subscribe)}catch(t){return!1}}(e))return this.spawnObservable(e,n);if(b(e))return this.spawnMachine(e,r(r({},i),{id:n}));if(null!==(o=e)&&"object"==typeof o&&"transition"in o&&"function"==typeof o.transition)return this.spawnBehavior(e,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof e,'".'));var o,s},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var i=new a(t,r(r({},this.options),{parent:this,id:e.id||t.id})),o=r(r({},at),e);o.sync&&i.onTransition((function(t){n.send(D,{state:t,id:i.id})}));var s=i;return this.children.set(i.id,s),o.autoForward&&this.forwardTo.add(i.id),i.onDone((function(t){n.removeChild(i.id),n.send(_(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=ot(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(_(U(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=$(e,t);try{i.send(_(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=E(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[x]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,r,i,o=this,s=!1,a=new Set,c=new Set;try{i=t((function(t){r=t,c.forEach((function(e){return e(t)})),s||o.send(_(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send($(e,t))}if(p(i))return this.spawnPromise(i,e);var u=((n={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){var e=E(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){s=!0,g(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[x]=function(){return this},n);return this.children.set(e,u),u},a.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(_(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(_($(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(_(U(e),{origin:e}))})),s=((n={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return r},toJSON:function(){return{id:e}}})[x]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},a.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[x]=function(){return this},n))},a.prototype.attachDev=function(){var t=rt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(r(r({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:r({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}it(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[x]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},a.interpret=ut,a}();function ut(t,e){return new ct(t,e)}t.Interpreter=ct,t.interpret=ut,t.spawn=function(t,e){var n=function(t){return m(t)?r(r({},at),{name:t}):r(r(r({},at),{name:w()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):K(t,n.name)}(G[G.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */var e,n,r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a,c={};function u(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:y(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return y(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function f(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 h(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}function d(t){return void 0===t?[]:function(t){return y(t)?t:[t]}(t)}function l(t,e,n){var r,o;if(g(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),c=a.next();!c.done;c=a.next()){var u=c.value,f=t[u];g(f)?s[u]=f(e,n.data):s[u]=f}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function p(t){return t instanceof Promise||!(null===t||!g(t)&&"object"!=typeof t||!g(t.then))}function v(t,e,n,r){return t?n.reduce((function(t,n){var o,s,a=n.assignment,c={state:r,action:n,_event:e},u={};if(g(a))u=a(t,e.data,c);else try{for(var f=i(Object.keys(a)),h=f.next();!h.done;h=f.next()){var d=h.value,l=a[d];u[d]=g(l)?l(t,e.data,c):l}}catch(t){o={error:t}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,u)}),t):t}function y(t){return Array.isArray(t)}function g(t){return"function"==typeof t}function m(t){return"string"==typeof t}var x=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function b(t){return!!t&&"__xstatenode"in t}(a={})[x]=function(){return this},a[Symbol.observable]=function(){return this};var w=function(){var t=0;return function(){return(++t).toString(16)}}();function S(t,e){return m(t)||"number"==typeof t?r({type:t},e):t}function _(t,e){if(!m(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=S(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t,e,n){var r=function(){},i="object"==typeof 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)}}var O=e.Start,I=e.Stop,T=e.Raise,A=e.Send,L=e.Cancel;e.NullEvent;var k=e.Assign;e.After,e.DoneState;var j=e.Log,C=e.Init;e.Invoke,e.ErrorExecution;var P=e.ErrorPlatform,N=e.ErrorCustom,D=e.Update,M=e.Choose,R=e.Pure,z=_({type:C});function V(t,e){return e&&e[t]||void 0}function J(t,e){var n;if(m(t)||"number"==typeof t)n=g(i=V(t,e))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(g(t))n={type:t.name||t.toString(),exec:t};else{var i;if(g(i=V(t.type,e)))n=r(r({},t),{exec:i});else if(i){var o=i.type||t.type;n=r(r(r({},i),t),{type:o})}else n=t}return n}var q=function(t,e){return t?(y(t)?t:[t]).map((function(t){return J(t,e)})):[]};function U(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function $(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function F(t,a,c,u,f,l,p){void 0===p&&(p=!1);var y=p?[]:function(t){var e,n,r=[];try{for(var o=i(t),s=o.next();!s.done;s=o.next())for(var a=s.value,c=0;c<a.actions.length;)a.actions[c].type!==k?c++:(r.push(a.actions[c]),a.actions.splice(c,1))}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}(f),x=y.length?v(c,u,y,a):c,b=p?[c]:void 0,w=[];function S(i,f){var h;switch(f.type){case T:return{type:T,_event:_(f.event)};case A:var y=function(t,e,n,i){var o,s={_event:n},a=_(g(t.event)?t.event(e,n.data,s):t.event);if(m(t.delay)){var c=i&&i[t.delay];o=g(c)?c(e,n.data,s):c}else o=g(t.delay)?t.delay(e,n.data,s):t.delay;var u=g(t.to)?t.to(e,n.data,s):t.to;return r(r({},t),{to:u,_event:a,event:a.data,delay:o})}(f,x,u,t.options.delays);return l&&y.to!==n.Internal&&("entry"===i?w.push(y):null==l||l(y,x,u)),y;case j:var S=function(t,e,n){return r(r({},t),{value:m(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})}(f,x,u);return null==l||l(S,x,u),S;case M:if(!(C=null===(h=f.conds.find((function(e){var n=function(t,e){if(t)return m(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:g(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}(e.cond,t.options.guards);return!n||function(t,e,n,r,i){var o=t.options.guards,s={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,s);var a=null==o?void 0:o[e.type];if(!a)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return a(n,r.data,s)}(t,n,x,u,l?void 0:a)})))||void 0===h?void 0:h.actions))return[];var E=o(F(t,a,x,u,[{type:i,actions:q(d(C),t.options.actions)}],l,p),2),O=E[0],L=E[1];return x=L,null==b||b.push(x),O;case R:var C;if(!(C=f.get(x,u.data)))return[];var P=o(F(t,a,x,u,[{type:i,actions:q(d(C),t.options.actions)}],l,p),2),N=P[0],D=P[1];return x=D,null==b||b.push(x),N;case I:S=function(t,n,r){var i=g(t.activity)?t.activity(n,r.data):t.activity,o="string"==typeof i?{id:i}:i;return{type:e.Stop,activity:o}}(f,x,u);return null==l||l(S,c,u),S;case k:x=v(x,u,[f],l?void 0:a),null==b||b.push(x);break;default:var z=J(f,t.options.actions),V=z.exec;if(l)l(z,x,u);else if(V&&b){var U=b.length-1;z=r(r({},z),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];V.apply(void 0,s([b[U]],o(e),!1))}})}return z}}return[h(f.map((function(t){var e,n,r=[];try{for(var o=i(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value,c=S(t.type,a);c&&(r=r.concat(c))}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return w.forEach((function(t){l(t,x,u)})),w.length=0,r}))),x]}var X=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=c,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||c,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],o(new Set(h(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(r.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=z;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),m(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,r){void 0===r&&(r=".");var i=u(e,r),o=u(n,r);return m(o)?!!m(i)&&o===i:m(i)?i in o:Object.keys(i).every((function(e){return e in o&&t(i[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),Q={deferEvents:!1},B=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},Q),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),G=[],H=function(t,e){G.push(t);var n=e(t);return G.pop(),n};function K(t,e,n){var r=function(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[x]=function(){return this},e}(e);if(r.deferred=!0,b(t)){var i=r.state=H(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var W=new Map,Y=0,Z=function(){return"x:".concat(Y++)},tt=function(t,e){return W.set(t,e),t},et=function(t){return W.get(t)},nt=function(t){W.delete(t)};function rt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function it(t){if(rt()){var e=function(){var t=rt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ot(t,e){void 0===e&&(e={});var n=t.initialState,i=new Set,o=[],s=!1,a=function(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[x]=function(){return this},e),t)}({id:e.id,send:function(e){o.push(e),function(){if(!s){for(s=!0;o.length>0;){var e=o.shift();n=t.transition(n,e,c),i.forEach((function(t){return t.next(n)}))}s=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=E(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),c={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(c):n,a}var st,at={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(st=t.InterpreterStatus||(t.InterpreterStatus={}))[st.NotStarted=0]="NotStarted",st[st.Running=1]="Running",st[st.Stopped=2]="Stopped";var ct=function(){function a(i,o){void 0===o&&(o=a.defaultOptions);var s=this;this.machine=i,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(e,n){if(y(e))return s.batch(e),s.state;var r=_(S(e,n));if(s.status===t.InterpreterStatus.Stopped)return s.state;if(s.status!==t.InterpreterStatus.Running&&!s.options.deferEvents)throw new Error('Event "'.concat(r.name,'" was sent to uninitialized service "').concat(s.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(r.data)));return s.scheduler.schedule((function(){s.forward(r);var t=s._nextState(r);s.update(t,r)})),s._state},this.sendTo=function(e,i,o){var a,c=s.parent&&(i===n.Parent||s.parent.id===i),u=c?s.parent:m(i)?s.children.get(i)||et(i):(a=i)&&"function"==typeof a.send?i:void 0;if(u)if("machine"in u){if(s.status!==t.InterpreterStatus.Stopped||s.parent!==u||s.state.done){var f=r(r({},e),{name:e.name===N?"".concat($(s.id)):e.name,origin:s.sessionId});!o&&s.machine.config.predictableActionArguments?s._outgoingQueue.push([u,f]):u.send(f)}}else!o&&s.machine.config.predictableActionArguments?s._outgoingQueue.push([u,e.data]):u.send(e.data);else if(!c)throw new Error("Unable to send event to child '".concat(i,"' from service '").concat(s.id,"'."))},this._exec=function(n,r,i,o){void 0===o&&(o=s.machine.options.actions);var a,c=n.exec||V(n.type,o),u=g(c)?c:c?c.exec:n.exec;if(u)try{return u(r,i.data,s.machine.config.predictableActionArguments?{action:n,_event:i}:{action:n,state:s.state,_event:i})}catch(t){throw s.parent&&s.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case A:var f=n;if("number"==typeof f.delay)return void s.defer(f);f.to?s.sendTo(f._event,f.to,i===z):s.send(f._event);break;case L:s.cancel(n.sendId);break;case O:if(s.status!==t.InterpreterStatus.Running)return;var h=n.activity;if(!s.machine.config.predictableActionArguments&&!s.state.activities[h.id||h.type])break;if(h.type===e.Invoke){var d="string"==typeof(a=h.src)?{type:a}:a,p=s.machine.options.services?s.machine.options.services[d.type]:void 0,v=h.id,y=h.data,m="autoForward"in h?h.autoForward:!!h.forward;if(!p)return;var x=y?l(y,r,i):void 0;if("string"==typeof p)return;var w=g(p)?p(r,i.data,{data:x,src:d,meta:h.meta}):p;if(!w)return;var S=void 0;b(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),s.spawn(w,v,S)}else s.spawnActivity(h);break;case I:s.stopChild(n.activity.id);break;case j:var _=n.label,E=n.value;_?s.logger(_,E):s.logger(E)}};var c=r(r({},a.defaultOptions),o),u=c.clock,f=c.logger,h=c.parent,d=c.id,p=void 0!==d?d:i.id;this.id=p,this.logger=f,this.clock=u,this.parent=h,this.options=c,this.scheduler=new B({deferEvents:this.options.deferEvents}),this.sessionId=Z()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:H(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,r;try{for(var o=i(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value;this.exec(a,t,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},a.prototype.update=function(t,e){var n,r,o,s,a,c,u,f,h=this;if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==z||!this.options.execute)for(var d=void 0;d=this._outgoingQueue.shift();)d[0].send(d[1]);else this.execute(this.state);if(this.children.forEach((function(t){h.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var p=i(this.eventListeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t.event)}}catch(t){n={error:t}}finally{try{v&&!v.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}try{for(var y=i(this.listeners),g=y.next();!g.done;g=y.next()){(0,g.value)(t,t.event)}}catch(t){o={error:t}}finally{try{g&&!g.done&&(s=y.return)&&s.call(y)}finally{if(o)throw o.error}}try{for(var m=i(this.contextListeners),x=m.next();!x.done;x=m.next()){(0,x.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(c=m.return)&&c.call(m)}finally{if(a)throw a.error}}if(this.state.done){var b=t.configuration.find((function(t){return"final"===t.type&&t.parent===h.machine})),w=b&&b.doneData?l(b.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),_=S.next();!_.done;_=S.next()){(0,_.value)(U(this.id,w))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(f=S.return)&&f.call(S)}finally{if(u)throw u.error}}this._stop(),this._stopChildren()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,r){var i=this,o=E(e,n,r);this.listeners.add(o.next),this.status!==t.InterpreterStatus.NotStarted&&o.next(this.state);var s=function(){i.doneListeners.delete(s),i.stopListeners.delete(s),o.complete()};return this.status===t.InterpreterStatus.Stopped?o.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:function(){i.listeners.delete(o.next),i.doneListeners.delete(s),i.stopListeners.delete(s)}}},a.prototype.onEvent=function(t){return this.eventListeners.add(t),this},a.prototype.onSend=function(t){return this.sendListeners.add(t),this},a.prototype.onChange=function(t){return this.contextListeners.add(t),this},a.prototype.onStop=function(t){return this.stopListeners.add(t),this},a.prototype.onDone=function(t){return this.doneListeners.add(t),this},a.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},a.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),tt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:H(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(X.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,z)})),this},a.prototype._stopChildren=function(){this.children.forEach((function(t){g(t.stop)&&t.stop()})),this.children.clear()},a.prototype._stop=function(){var e,n,r,o,s,a,c,u,f,h;try{for(var d=i(this.listeners),l=d.next();!l.done;l=d.next()){var p=l.value;this.listeners.delete(p)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(n=d.return)&&n.call(d)}finally{if(e)throw e.error}}try{for(var v=i(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){s={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(s)throw s.error}}try{for(var x=i(this.doneListeners),b=x.next();!b.done;b=x.next()){p=b.value;this.doneListeners.delete(p)}}catch(t){c={error:t}}finally{try{b&&!b.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0;try{for(var w=i(Object.keys(this.delayedEventsMap)),S=w.next();!S.done;S=w.next()){var _=S.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){f={error:t}}finally{try{S&&!S.done&&(h=w.return)&&h.call(w)}finally{if(f)throw f.error}}this.scheduler.clear(),this.scheduler=new B({deferEvents:this.options.deferEvents})},a.prototype.stop=function(){var t=this,e=this.scheduler;return this._stop(),e.schedule((function(){var e=_({type:"xstate.stop"}),r=H(t,(function(){var r=h(s([],o(t.state.configuration),!1).sort((function(t,e){return e.order-t.order})).map((function(e){return q(e.onExit,t.machine.options.actions)}))),i=o(F(t.machine,t.state,t.state.context,e,[{type:"exit",actions:r}],t.machine.config.predictableActionArguments?t._exec:void 0,t.machine.config.predictableActionArguments||t.machine.config.preserveActionOrder),2),a=i[0],c=i[1],u=new X({value:t.state.value,context:c,_event:e,_sessionid:t.sessionId,historyValue:void 0,history:t.state,actions:a.filter((function(t){return t.type!==T&&(t.type!==A||!!t.to&&t.to!==n.Internal)})),activities:{},events:[],configuration:[],transitions:[],children:{},done:t.state.done,tags:t.state.tags,machine:t.machine});return u.changed=!0,u}));t.update(r,e),t._stopChildren(),nt(t.sessionId)})),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var a=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule((function(){var t,c,u=n.state,f=!1,h=[],d=function(t){var e=_(t);n.forward(e),u=H(n,(function(){return n.machine.transition(u,e,void 0,a||void 0)})),h.push.apply(h,s([],o(n.machine.config.predictableActionArguments?u.actions:u.actions.map((function(t){return function(t,e){var n=t.exec;return r(r({},t),{exec:void 0!==n?function(){return n(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0})}(t,u)}))),!1)),f=f||!!u.changed};try{for(var l=i(e),p=l.next();!p.done;p=l.next()){d(p.value)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(c=l.return)&&c.call(l)}finally{if(t)throw t.error}}u.changed=f,u.actions=h,n.update(u,_(e[e.length-1]))}))}},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype._nextState=function(t,e){var n=this;void 0===e&&(e=!!this.machine.config.predictableActionArguments&&this._exec);var r=_(t);if(0===r.name.indexOf(P)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(P)})))throw r.data.data;return H(this,(function(){return n.machine.transition(n.state,r,void 0,e||void 0)}))},a.prototype.nextState=function(t){return this._nextState(t,!1)},a.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(s,"'."));a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},a.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to,!0):e.send(t._event)}),t.delay)},a.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},a.prototype.exec=function(t,e,n){void 0===n&&(n=this.machine.options.actions),this._exec(t,e.context,e._event,n)},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),g(e.stop)&&e.stop())},a.prototype.spawn=function(e,n,i){if(this.status!==t.InterpreterStatus.Running)return K(e,n);if(p(e))return this.spawnPromise(Promise.resolve(e),n);if(g(e))return this.spawnCallback(e,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=e)&&"id"in s)return this.spawnActor(e,n);if(function(t){try{return"subscribe"in t&&g(t.subscribe)}catch(t){return!1}}(e))return this.spawnObservable(e,n);if(b(e))return this.spawnMachine(e,r(r({},i),{id:n}));if(null!==(o=e)&&"object"==typeof o&&"transition"in o&&"function"==typeof o.transition)return this.spawnBehavior(e,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof e,'".'));var o,s},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var i=new a(t,r(r({},this.options),{parent:this,id:e.id||t.id})),o=r(r({},at),e);o.sync&&i.onTransition((function(t){n.send(D,{state:t,id:i.id})}));var s=i;return this.children.set(i.id,s),o.autoForward&&this.forwardTo.add(i.id),i.onDone((function(t){n.removeChild(i.id),n.send(_(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=ot(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(_(U(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=$(e,t);try{i.send(_(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=E(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[x]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,r,i,o=this,s=!1,a=new Set,c=new Set;try{i=t((function(t){r=t,c.forEach((function(e){return e(t)})),s||o.send(_(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send($(e,t))}if(p(i))return this.spawnPromise(i,e);var u=((n={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){var e=E(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){s=!0,g(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[x]=function(){return this},n);return this.children.set(e,u),u},a.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(_(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(_($(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(_(U(e),{origin:e}))})),s=((n={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return r},toJSON:function(){return{id:e}}})[x]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},a.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[x]=function(){return this},n))},a.prototype.attachDev=function(){var t=rt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(r(r({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:r({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}it(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[x]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},a.interpret=ut,a}();function ut(t,e){return new ct(t,e)}t.Interpreter=ct,t.interpret=ut,t.spawn=function(t,e){var n=function(t){return m(t)?r(r({},at),{name:t}):r(r(r({},at),{name:w()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):K(t,n.name)}(G[G.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/xstate.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */var e,n,r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function o(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}t.ActionTypes=void 0,(e=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",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.Update="xstate.update",e.Pure="xstate.pure",e.Choose="xstate.choose",t.SpecialTargets=void 0,(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var c,u=t.ActionTypes.Start,h=t.ActionTypes.Stop,f=t.ActionTypes.Raise,l=t.ActionTypes.Send,d=t.ActionTypes.Cancel,p=t.ActionTypes.NullEvent,v=t.ActionTypes.Assign,y=t.ActionTypes.After,g=t.ActionTypes.DoneState,m=t.ActionTypes.Log,x=t.ActionTypes.Init,S=t.ActionTypes.Invoke,b=t.ActionTypes.ErrorExecution,w=t.ActionTypes.ErrorPlatform,_=t.ActionTypes.ErrorCustom,T=t.ActionTypes.Update,E=t.ActionTypes.Choose,A=t.ActionTypes.Pure,O=Object.freeze({__proto__:null,start:u,stop:h,raise:f,send:l,cancel:d,nullEvent:p,assign:v,after:y,doneState:g,log:m,init:x,invoke:S,errorExecution:b,errorPlatform:w,error:_,update:T,choose:E,pure:A}),k={};function j(t,e,n){void 0===n&&(n=".");var r=P(t,n),i=P(e,n);return Q(i)?!!Q(r)&&i===r:Q(r)?r in i:Object.keys(r).every((function(t){return t in i&&j(r[t],i[t])}))}function N(t){try{return Q(t)||"number"==typeof t?"".concat(t):t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function I(t,e){try{return X(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function P(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:X(t)?C(t):"string"!=typeof t?t:C(I(t,e));var n}function C(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 L(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 V(t,e,n){var r,i,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];n(h)&&(a[u]=e(h,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}var D=function(t){return function(e){var n,r,i=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){i=i[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return i}};function R(t){return t?Q(t)?[[t]]:M(Object.keys(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?R(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function M(t){var e;return(e=[]).concat.apply(e,s([],a(t),!1))}function z(t){return X(t)?t:[t]}function B(t){return void 0===t?[]:z(t)}function U(t,e,n){var r,i;if($(t))return t(e,n.data);var a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];$(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}function F(t){return t instanceof Promise||!(null===t||!$(t)&&"object"!=typeof t||!$(t.then))}function J(t,e){return L(t.states,(function(t,n){if(t){var r=(Q(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:J(t,r)}}}))}function q(t,e,n,r){return t?n.reduce((function(t,n){var i,a,s=n.assignment,c={state:r,action:n,_event:e},u={};if($(s))u=s(t,e.data,c);else try{for(var h=o(Object.keys(s)),f=h.next();!f.done;f=h.next()){var l=f.value,d=s[l];u[l]=$(d)?d(t,e.data,c):d}}catch(t){i={error:t}}finally{try{f&&!f.done&&(a=h.return)&&a.call(h)}finally{if(i)throw i.error}}return Object.assign({},t,u)}),t):t}function X(t){return Array.isArray(t)}function $(t){return"function"==typeof t}function Q(t){return"string"==typeof t}function H(t,e){if(t)return Q(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:$(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var G=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function K(t){return!!t&&"__xstatenode"in t}(c={})[G]=function(){return this},c[Symbol.observable]=function(){return this};var W=function(){var t=0;return function(){return(++t).toString(16)}}();function Y(t,e){return Q(t)||"number"==typeof t?r({type:t},e):t}function Z(t,e){if(!Q(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=Y(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function tt(t,e){return z(e).map((function(e){return void 0===e||"string"==typeof e||K(e)?{target:e,event:t}:r(r({},e),{event:t})}))}function et(t,e,n,r,i){var o=t.options.guards,a={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,a);var s=null==o?void 0:o[e.type];if(!s)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return s(n,r.data,a)}function nt(t){return"string"==typeof t?{type:t}:t}function rt(t,e,n){var r=function(){},i="object"==typeof 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 it(t,e){return"".concat(t,":invocation[").concat(e,"]")}var ot=Z({type:x});function at(t,e){return e&&e[t]||void 0}function st(t,e){var n;if(Q(t)||"number"==typeof t)n=$(i=at(t,e))?{type:t,exec:i}:i||{type:t,exec:void 0};else if($(t))n={type:t.name||t.toString(),exec:t};else{var i;if($(i=at(t.type,e)))n=r(r({},t),{exec:i});else if(i){var o=i.type||t.type;n=r(r(r({},i),t),{type:o})}else n=t}return n}var ct=function(t,e){return t?(X(t)?t:[t]).map((function(t){return st(t,e)})):[]};function ut(t){var e=st(t);return r(r({id:Q(t)?t:e.id},e),{type:e.type})}function ht(e){return Q(e)?{type:f,event:e}:lt(e,{to:t.SpecialTargets.Internal})}function ft(t){return{type:f,_event:Z(t.event)}}function lt(t,e){return{to:e?e.to:void 0,type:l,event:$(t)?t:Y(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:$(t)?t.name:N(t)}}function dt(t,e,n,i){var o,a={_event:n},s=Z($(t.event)?t.event(e,n.data,a):t.event);if(Q(t.delay)){var c=i&&i[t.delay];o=$(c)?c(e,n.data,a):c}else o=$(t.delay)?t.delay(e,n.data,a):t.delay;var u=$(t.to)?t.to(e,n.data,a):t.to;return r(r({},t),{to:u,_event:s,event:s.data,delay:o})}function pt(e,n){return lt(e,r(r({},n),{to:t.SpecialTargets.Parent}))}function vt(t,e,n){return lt(e,r(r({},n),{to:t}))}function yt(){return pt(T)}var gt=function(t,e){return{context:t,event:e}};var mt=function(t,e,n){return r(r({},t),{value:Q(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})},xt=function(t){return{type:d,sendId:t}};function St(e){var n=ut(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function bt(e){var n=$(e)?e:ut(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function wt(e,n,r){var i=$(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}var _t=function(t){return{type:v,assignment:t}};function Tt(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Et(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function At(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Ot(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function kt(t,e){return lt((function(t,e){return e}),r(r({},e),{to:t}))}function jt(e,n,i,c,u,d,p){void 0===p&&(p=!1);var y=p?[]:function(t){var e,n,r=[];try{for(var i=o(t),a=i.next();!a.done;a=i.next())for(var s=a.value,c=0;c<s.length;)s[c].type!==v?c++:(r.push(s[c]),s.splice(c,1))}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}(u),g=y.length?q(i,c,y,n):i,x=p?[i]:void 0,S=[];function b(o){var u;switch(o.type){case f:return ft(o);case l:var y=dt(o,g,c,e.options.delays);return d&&y.to!==t.SpecialTargets.Internal&&S.push(y),y;case m:var b=mt(o,g,c);return null==d||d(b,g,c),b;case E:if(!(O=null===(u=o.conds.find((function(t){var r=H(t.cond,e.options.guards);return!r||et(e,r,g,c,d?void 0:n)})))||void 0===u?void 0:u.actions))return[];var w=a(jt(e,n,g,c,[ct(B(O),e.options.actions)],d,p),2),_=w[0],T=w[1];return g=T,null==x||x.push(g),_;case A:var O;if(!(O=o.get(g,c.data)))return[];var k=a(jt(e,n,g,c,[ct(B(O),e.options.actions)],d,p),2),j=k[0],N=k[1];return g=N,null==x||x.push(g),j;case h:b=wt(o,g,c);return null==d||d(b,i,c),b;case v:g=q(g,c,[o],d?void 0:n),null==x||x.push(g);break;default:var I=st(o,e.options.actions),P=I.exec;if(d)d(I,g,c);else if(P&&x){var C=x.length-1;I=r(r({},I),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];P.apply(void 0,s([x[C]],a(e),!1))}})}return I}}return[M(u.map((function(t){var e,n,r=[];try{for(var i=o(t),a=i.next();!a.done;a=i.next()){var s=b(a.value);s&&(r=r.concat(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return S.forEach((function(t){d(t,g,c)})),S.length=0,r}))),g]}var Nt=Object.freeze({__proto__:null,actionTypes:O,initEvent:ot,getActionFunction:at,toActionObject:st,toActionObjects:ct,toActivityDefinition:ut,raise:ht,resolveRaise:ft,send:lt,resolveSend:dt,sendParent:pt,sendTo:vt,sendUpdate:yt,respond:function(t,e){return lt(t,r(r({},e),{to:function(t,e,n){return n._event.origin}}))},log:function(t,e){return void 0===t&&(t=gt),{type:m,label:e,expr:t}},resolveLog:mt,cancel:xt,start:St,stop:bt,resolveStop:wt,assign:_t,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Tt,done:Et,doneInvoke:At,error:Ot,pure:function(e){return{type:t.ActionTypes.Pure,get:e}},forwardTo:kt,escalate:function(e,n){return pt((function(t,n,r){return{type:_,data:$(e)?e(t,n,r):e}}),r(r({},n),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},resolveActions:jt}),It=[],Pt=function(t,e){It.push(t);var n=e(t);return It.pop(),n};function Ct(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[G]=function(){return this},e}function Lt(t,e,n){var r=Ct(e);if(r.deferred=!0,K(t)){var i=r.state=Pt(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Vt(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[G]=function(){return this},e),t)}var Dt=function(t){return"atomic"===t.type||"final"===t.type};function Rt(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function Mt(t){return Rt(t).filter((function(t){return"history"!==t.type}))}function zt(t){var e=[t];return Dt(t)?e:e.concat(M(Mt(t).map(zt)))}function Bt(t,e){var n,r,i,a,s,c,u,h,f=Ut(new Set(t)),l=new Set(e);try{for(var d=o(l),p=d.next();!p.done;p=d.next())for(var v=(T=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=Ut(l);try{for(var g=o(l),m=g.next();!m.done;m=g.next()){if("compound"!==(T=m.value).type||y.get(T)&&y.get(T).length){if("parallel"===T.type)try{for(var x=(s=void 0,o(Mt(T))),S=x.next();!S.done;S=x.next()){var b=S.value;l.has(b)||(l.add(b),f.get(b)?f.get(b).forEach((function(t){return l.add(t)})):b.initialStateNodes.forEach((function(t){return l.add(t)})))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(T)?f.get(T).forEach((function(t){return l.add(t)})):T.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){i={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(i)throw i.error}}try{for(var w=o(l),_=w.next();!_.done;_=w.next()){var T;for(v=(T=_.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}return l}function Ut(t){var e,n,r=new Map;try{for(var i=o(t),a=i.next();!a.done;a=i.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}function Ft(t,e){return function t(e,n){var r=n.get(e);if(!r)return{};if("compound"===e.type){var i=r[0];if(!i)return{};if(Dt(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,Ut(Bt([t],e)))}function Jt(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function qt(t,e){return"compound"===e.type?Mt(e).some((function(e){return"final"===e.type&&Jt(t,e)})):"parallel"===e.type&&Mt(e).every((function(e){return qt(t,e)}))}function Xt(t){return new Set(M(t.map((function(t){return t.tags}))))}var $t=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=k,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||k,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],a(new Set(M(s([],a(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(r.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ot,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=ot;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),Q(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],a(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=i(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return j(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),Qt={deferEvents:!1},Ht=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},Qt),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Gt=new Map,Kt=0,Wt=function(){return"x:".concat(Kt++)},Yt=function(t,e){return Gt.set(t,e),t},Zt=function(t){return Gt.get(t)},te=function(t){Gt.delete(t)};function ee(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function ne(t){if(ee()){var e=function(){var t=ee();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function re(t,e){void 0===e&&(e={});var n=t.initialState,r=new Set,i=[],o=!1,a=Vt({id:e.id,send:function(e){i.push(e),function(){if(!o){for(o=!0;i.length>0;){var e=i.shift();n=t.transition(n,e,s),r.forEach((function(t){return t.next(n)}))}o=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,i){var o=rt(t,e,i);return r.add(o),o.next(n),{unsubscribe:function(){r.delete(o)}}}}),s={parent:e.parent,self:a,id:e.id||"anonymous",observers:r};return n=t.start?t.start(s):n,a}var ie,oe={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(ie=t.InterpreterStatus||(t.InterpreterStatus={}))[ie.NotStarted=0]="NotStarted",ie[ie.Running=1]="Running",ie[ie.Stopped=2]="Stopped";var ae=function(){function e(n,i){void 0===i&&(i=e.defaultOptions);var o=this;this.machine=n,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(e,n){if(X(e))return o.batch(e),o.state;var r=Z(Y(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'.concat(r.name,'" was sent to uninitialized service "').concat(o.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(r.data)));return o.scheduler.schedule((function(){o.forward(r);var t=o._nextState(r);o.update(t,r)})),o._state},this.sendTo=function(e,n,i){var a,s=o.parent&&(n===t.SpecialTargets.Parent||o.parent.id===n),c=s?o.parent:Q(n)?o.children.get(n)||Zt(n):(a=n)&&"function"==typeof a.send?n:void 0;if(c)if("machine"in c){if(o.status!==t.InterpreterStatus.Stopped||o.parent!==c||o.state.done){var u=r(r({},e),{name:e.name===_?"".concat(Ot(o.id)):e.name,origin:o.sessionId});!i&&o.machine.config.predictableActionArguments?o._outgoingQueue.push([c,u]):c.send(u)}}else!i&&o.machine.config.predictableActionArguments?o._outgoingQueue.push([c,e.data]):c.send(e.data);else if(!s)throw new Error("Unable to send event to child '".concat(n,"' from service '").concat(o.id,"'."))},this._exec=function(e,n,r,i){void 0===i&&(i=o.machine.options.actions);var a=e.exec||at(e.type,i),s=$(a)?a:a?a.exec:e.exec;if(s)try{return s(n,r.data,o.machine.config.predictableActionArguments?{action:e,_event:r}:{action:e,state:o.state,_event:r})}catch(t){throw o.parent&&o.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case l:var c=e;if("number"==typeof c.delay)return void o.defer(c);c.to?o.sendTo(c._event,c.to,r===ot):o.send(c._event);break;case d:o.cancel(e.sendId);break;case u:if(o.status!==t.InterpreterStatus.Running)return;var f=e.activity;if(!o.machine.config.predictableActionArguments&&!o.state.activities[f.id||f.type])break;if(f.type===t.ActionTypes.Invoke){var p=nt(f.src),v=o.machine.options.services?o.machine.options.services[p.type]:void 0,y=f.id,g=f.data,x="autoForward"in f?f.autoForward:!!f.forward;if(!v)return;var S=g?U(g,n,r):void 0;if("string"==typeof v)return;var b=$(v)?v(n,r.data,{data:S,src:p,meta:f.meta}):v;if(!b)return;var w=void 0;K(b)&&(b=S?b.withContext(S):b,w={autoForward:x}),o.spawn(b,y,w)}else o.spawnActivity(f);break;case h:o.stopChild(e.activity.id);break;case m:var _=e.label,T=e.value;_?o.logger(_,T):o.logger(T)}};var a=r(r({},e.defaultOptions),i),s=a.clock,c=a.logger,f=a.parent,p=a.id,v=void 0!==p?p:n.id;this.id=v,this.logger=c,this.clock=s,this.parent=f,this.options=a,this.scheduler=new Ht({deferEvents:this.options.deferEvents}),this.sessionId=Wt()}return Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Pt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),e.prototype.execute=function(t,e){var n,r;try{for(var i=o(t.actions),a=i.next();!a.done;a=i.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,r,i,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==ot||!this.options.execute)for(var l=void 0;l=this._outgoingQueue.shift();)l[0].send(l[1]);else this.execute(this.state);if(this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=o(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}try{for(var v=o(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){i={error:t}}finally{try{y&&!y.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{m&&!m.done&&(c=g.return)&&c.call(g)}finally{if(s)throw s.error}}if(this.state.done){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),S=x&&x.doneData?U(x.doneData,t.context,e):void 0;try{for(var b=o(this.doneListeners),w=b.next();!w.done;w=b.next()){(0,w.value)(At(this.id,S))}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this._stop(),this._stopChildren()}},e.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},e.prototype.subscribe=function(e,n,r){var i=this,o=rt(e,n,r);this.listeners.add(o.next),this.status!==t.InterpreterStatus.NotStarted&&o.next(this.state);var a=function(){i.doneListeners.delete(a),i.stopListeners.delete(a),o.complete()};return this.status===t.InterpreterStatus.Stopped?o.complete():(this.onDone(a),this.onStop(a)),{unsubscribe:function(){i.listeners.delete(o.next),i.doneListeners.delete(a),i.stopListeners.delete(a)}}},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(t){return this.doneListeners.add(t),this},e.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},e.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),Yt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:Pt(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState($t.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,ot)})),this},e.prototype._stopChildren=function(){this.children.forEach((function(t){$(t.stop)&&t.stop()})),this.children.clear()},e.prototype._stop=function(){var e,n,r,i,a,s,c,u,h,f;try{for(var l=o(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(t){e={error:t}}finally{try{d&&!d.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}try{for(var v=o(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(i=v.return)&&i.call(v)}finally{if(r)throw r.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(s=g.return)&&s.call(g)}finally{if(a)throw a.error}}try{for(var x=o(this.doneListeners),S=x.next();!S.done;S=x.next()){p=S.value;this.doneListeners.delete(p)}}catch(t){c={error:t}}finally{try{S&&!S.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0;try{for(var b=o(Object.keys(this.delayedEventsMap)),w=b.next();!w.done;w=b.next()){var _=w.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{w&&!w.done&&(f=b.return)&&f.call(b)}finally{if(h)throw h.error}}this.scheduler.clear(),this.scheduler=new Ht({deferEvents:this.options.deferEvents})},e.prototype.stop=function(){var e=this,n=this.scheduler;return this._stop(),n.schedule((function(){var n=Z({type:"xstate.stop"}),r=Pt(e,(function(){var r=M(s([],a(e.state.configuration),!1).sort((function(t,e){return e.order-t.order})).map((function(t){return ct(t.onExit,e.machine.options.actions)}))),i=a(jt(e.machine,e.state,e.state.context,n,[r],e.machine.config.predictableActionArguments?e._exec:void 0,e.machine.config.predictableActionArguments||e.machine.config.preserveActionOrder),2),o=i[0],c=i[1],u=new $t({value:e.state.value,context:c,_event:n,_sessionid:e.sessionId,historyValue:void 0,history:e.state,actions:o.filter((function(e){return e.type!==f&&(e.type!==l||!!e.to&&e.to!==t.SpecialTargets.Internal)})),activities:{},events:[],configuration:[],transitions:[],children:{},done:e.state.done,tags:e.state.tags,machine:e.machine});return u.changed=!0,u}));e.update(r,n),e._stopChildren(),te(e.sessionId)})),this},e.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var i=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule((function(){var t,c,u=n.state,h=!1,f=[],l=function(t){var e=Z(t);n.forward(e),u=Pt(n,(function(){return n.machine.transition(u,e,void 0,i||void 0)})),f.push.apply(f,s([],a(n.machine.config.predictableActionArguments?u.actions:u.actions.map((function(t){return function(t,e){var n=t.exec;return r(r({},t),{exec:void 0!==n?function(){return n(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0})}(t,u)}))),!1)),h=h||!!u.changed};try{for(var d=o(e),p=d.next();!p.done;p=d.next()){l(p.value)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(t)throw t.error}}u.changed=h,u.actions=f,n.update(u,Z(e[e.length-1]))}))}},e.prototype.sender=function(t){return this.send.bind(this,t)},e.prototype._nextState=function(t,e){var n=this;void 0===e&&(e=!!this.machine.config.predictableActionArguments&&this._exec);var r=Z(t);if(0===r.name.indexOf(w)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(w)})))throw r.data.data;return Pt(this,(function(){return n.machine.transition(n.state,r,void 0,e||void 0)}))},e.prototype.nextState=function(t){return this._nextState(t,!1)},e.prototype.forward=function(t){var e,n;try{for(var r=o(this.forwardTo),i=r.next();!i.done;i=r.next()){var a=i.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));s.send(t)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},e.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to,!0):e.send(t._event)}),t.delay)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(t,e,n){void 0===n&&(n=this.machine.options.actions),this._exec(t,e.context,e._event,n)},e.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),$(e.stop)&&e.stop())},e.prototype.spawn=function(e,n,i){if(this.status!==t.InterpreterStatus.Running)return Lt(e,n);if(F(e))return this.spawnPromise(Promise.resolve(e),n);if($(e))return this.spawnCallback(e,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(a=e)&&"id"in a)return this.spawnActor(e,n);if(function(t){try{return"subscribe"in t&&$(t.subscribe)}catch(t){return!1}}(e))return this.spawnObservable(e,n);if(K(e))return this.spawnMachine(e,r(r({},i),{id:n}));if(null!==(o=e)&&"object"==typeof o&&"transition"in o&&"function"==typeof o.transition)return this.spawnBehavior(e,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof e,'".'));var o,a},e.prototype.spawnMachine=function(t,n){var i=this;void 0===n&&(n={});var o=new e(t,r(r({},this.options),{parent:this,id:n.id||t.id})),a=r(r({},oe),n);a.sync&&o.onTransition((function(t){i.send(T,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(Z(t,{origin:o.id}))})).start(),s},e.prototype.spawnBehavior=function(t,e){var n=re(t,{id:e,parent:this});return this.children.set(e,n),n},e.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(Z(At(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=Ot(e,t);try{i.send(Z(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var a=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=rt(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[G]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnCallback=function(t,e){var n,r,i,o=this,a=!1,s=new Set,c=new Set;try{i=t((function(t){r=t,c.forEach((function(e){return e(t)})),a||o.send(Z(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(Ot(e,t))}if(F(i))return this.spawnPromise(i,e);var u=((n={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){var e=rt(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){a=!0,$(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[G]=function(){return this},n);return this.children.set(e,u),u},e.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(Z(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(Z(Ot(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(Z(At(e),{origin:e}))})),a=((n={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return r},toJSON:function(){return{id:e}}})[G]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},e.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},e.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[G]=function(){return this},n))},e.prototype.attachDev=function(){var t=ee();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(r(r({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:r({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}ne(this)}},e.prototype.toJSON=function(){return{id:this.id}},e.prototype[G]=function(){return this},e.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},e.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},e.interpret=se,e}();function se(t,e){return new ae(t,e)}function ce(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function ue(t){return r(r({type:S},t),{toJSON:function(){t.onDone,t.onError;var e=i(t,["onDone","onError"]);return r(r({},e),{type:S,src:ce(t.src)})}})}var he={},fe=function(t){return"#"===t[0]},le=function(){function e(t,n,i,c){void 0===i&&(i="context"in t?t.context:void 0);var u,h=this;this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==c?void 0:c.parent,this.key=this.config.key||(null==c?void 0:c.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||s([this.machine.key],a(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?L(this.config.states,(function(t,n){var i,o=new e(t,{},void 0,{parent:h,key:n});return Object.assign(h.idMap,r(((i={})[o.id]=o,i),o.idMap)),o})):he;var f=0;!function t(e){var n,r;e.order=f++;try{for(var i=o(Rt(e)),a=i.next();!a.done;a=i.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=B(this.config.entry||this.config.onEntry).map((function(t){return st(t)})),this.onExit=B(this.config.exit||this.config.onExit).map((function(t){return st(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=B(this.config.invoke).map((function(t,e){var n,i;if(K(t)){var o=it(h.id,e);return h.machine.options.services=r(((n={})[o]=t,n),h.machine.options.services),ue({src:o,id:o})}if(Q(t.src)){o=t.id||it(h.id,e);return ue(r(r({},t),{id:o,src:t.src}))}if(K(t.src)||$(t.src)){o=t.id||it(h.id,e);return h.machine.options.services=r(((i={})[o]=t.src,i),h.machine.options.services),ue(r(r({id:o},t),{src:o}))}var a=t.src;return ue(r(r({id:it(h.id,e)},t),{src:a}))})),this.activities=B(this.config.activities).concat(this.invoke).map((function(t){return ut(t)})),this.transition=this.transition.bind(this),this.tags=B(this.config.tags)}return e.prototype._init=function(){this.__cache.transitions||zt(this).forEach((function(t){return t.on}))},e.prototype.withConfig=function(t,n){var i=this.options,o=i.actions,a=i.activities,s=i.guards,c=i.services,u=i.delays;return new e(this.config,{actions:r(r({},o),t.actions),activities:r(r({},a),t.activities),guards:r(r({},s),t.guards),services:r(r({},c),t.services),delays:r(r({},u),t.delays)},null!=n?n:this.context)},e.prototype.withContext=function(t){return new e(this.config,this.options,t)},Object.defineProperty(e.prototype,"context",{get:function(){return $(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:L(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.definition},Object.defineProperty(e.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),e.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var r=n.eventType===t;return e?r:r||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},e.prototype.getDelayedTransitions=function(){var t=this,e=this.config.after;if(!e)return[];var n=function(e,n){var r=Tt($(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(lt(r,{delay:e})),t.onExit.push(xt(r)),r};return(X(e)?e.map((function(t,e){var i=n(t.delay,e);return r(r({},t),{event:i})})):M(Object.keys(e).map((function(t,i){var o=e[t],a=Q(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=n(s,i);return B(a).map((function(t){return r(r({},t),{event:c,delay:s})}))})))).map((function(e){var n=e.delay;return r(r({},t.formatTransition(e)),{delay:n})}))},e.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof $t?t.value:P(t,this.delimiter);if(Q(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this,this.states[r]]}var o=Object.keys(r),c=[this];return c.push.apply(c,s([],a(M(o.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),c},e.prototype.handles=function(t){var e=N(t);return this.events.includes(e)},e.prototype.resolveState=function(t){var e=t instanceof $t?t:$t.create(t),n=Array.from(Bt([],this.getStateNodes(e.value)));return new $t(r(r({},e),{value:this.resolve(e.value),configuration:n,done:qt(n,this),tags:Xt(n),machine:this.machine}))},e.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},e.prototype.transitionCompoundNode=function(t,e,n){var r=Object.keys(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},e.prototype.transitionParallelNode=function(t,e,n){var r,i,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];if(h){var f=this.getStateNode(u)._transition(h,e,n);f&&(a[u]=f)}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}var l=Object.keys(a).map((function(t){return a[t]})),d=M(l.map((function(t){return t.transitions})));if(!l.some((function(t){return t.transitions.length>0})))return this.next(e,n);var p=M(Object.keys(a).map((function(t){return a[t].configuration})));return{transitions:d,exitSet:M(l.map((function(t){return t.exitSet}))),configuration:p,source:e,actions:M(Object.keys(a).map((function(t){return a[t].actions})))}},e.prototype._transition=function(t,e,n){return Q(t)?this.transitionLeafNode(t,e,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},e.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,Z(e))},e.prototype.next=function(t,e){var n,r,i,c=this,u=e.name,h=[],f=[];try{for(var l=o(this.getCandidates(u)),d=l.next();!d.done;d=l.next()){var p=d.value,v=p.cond,y=p.in,g=t.context,m=!y||(Q(y)&&fe(y)?t.matches(P(this.getStateNodeById(y).path,this.delimiter)):j(P(y,this.delimiter),D(this.path.slice(0,-2))(t.value))),x=!1;try{x=!v||et(this.machine,v,g,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(v.name||v.type,"' in transition for event '").concat(u,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(x&&m){void 0!==p.target&&(f=p.target),h.push.apply(h,s([],a(p.actions),!1)),i=p;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(i){if(!f.length)return{transitions:[i],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var S=M(f.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)})));return{transitions:[i],exitSet:!!i.internal?[]:M(f.map((function(t){return c.getPotentiallyReenteringNodes(t)}))),configuration:S,source:t,actions:h}}},e.prototype.getPotentiallyReenteringNodes=function(t){if(this.order<t.order)return[this];for(var e=[],n=this,r=t;n&&n!==r;)e.push(n),n=n.parent;return n!==r?[]:(e.push(r),e)},e.prototype.getActions=function(e,n,r,i,c,u,h){var d,p,v,y,g=this,m=u?Bt([],this.getStateNodes(u.value)):[],x=new Set;try{for(var S=o(Array.from(e).sort((function(t,e){return t.order-e.order}))),b=S.next();!b.done;b=S.next()){(!Jt(m,T=b.value)||Jt(r.exitSet,T)||T.parent&&x.has(T.parent))&&x.add(T)}}catch(t){d={error:t}}finally{try{b&&!b.done&&(p=S.return)&&p.call(S)}finally{if(d)throw d.error}}try{for(var w=o(m),_=w.next();!_.done;_=w.next()){var T;Jt(e,T=_.value)&&!Jt(r.exitSet,T.parent)||r.exitSet.push(T)}}catch(t){v={error:t}}finally{try{_&&!_.done&&(y=w.return)&&y.call(w)}finally{if(v)throw v.error}}r.exitSet.sort((function(t,e){return e.order-t.order}));var E=Array.from(x).sort((function(t,e){return t.order-e.order})),A=new Set(r.exitSet),O=M(E.map((function(t){var e=[];if("final"!==t.type)return e;var n=t.parent;if(!n.parent)return e;e.push(Et(t.id,t.doneData),Et(n.id,t.doneData?U(t.doneData,i,c):void 0));var o=n.parent;return"parallel"===o.type&&Mt(o).every((function(t){return qt(r.configuration,t)}))&&e.push(Et(o.id)),e}))),k=E.map((function(t){var e=t.onEntry,n=t.activities.map((function(t){return St(t)}));return ct(h?s(s([],a(e),!1),a(n),!1):s(s([],a(n),!1),a(e),!1),g.machine.options.actions)})).concat([O.map(ht)]),j=Array.from(A).map((function(t){return ct(s(s([],a(t.onExit),!1),a(t.activities.map((function(t){return bt(t)}))),!1),g.machine.options.actions)})).concat([ct(r.actions,this.machine.options.actions)]).concat(k);if(n){var N=ct(M(s([],a(e),!1).sort((function(t,e){return e.order-t.order})).map((function(t){return t.onExit}))),this.machine.options.actions).filter((function(e){return e.type!==f&&(e.type!==l||!!e.to&&e.to!==t.SpecialTargets.Internal)}));return j.concat([N])}return j},e.prototype.transition=function(t,e,n,r){void 0===t&&(t=this.initialState);var i,o,c=Z(e);if(t instanceof $t)i=void 0===n?t:this.resolveState($t.from(t,n));else{var u=Q(t)?this.resolve(C(this.getResolvedPath(t))):this.resolve(t),h=null!=n?n:this.machine.context;i=this.resolveState($t.from(u,h))}if(this.strict&&!this.events.includes(c.name)&&(o=c.name,!/^(done|error)\./.test(o)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(c.name,"'"));var f=this._transition(i.value,i,c)||{transitions:[],configuration:[],exitSet:[],source:i,actions:[]},l=Bt([],this.getStateNodes(i.value)),d=f.configuration.length?Bt(l,f.configuration):l;return f.configuration=s([],a(d),!1),this.resolveTransition(f,i,i.context,r,c)},e.prototype.resolveRaisedTransition=function(t,e,n,r){var i,o=t.actions;return(t=this.transition(t,e,void 0,r))._event=n,t.event=n.data,(i=t.actions).unshift.apply(i,s([],a(o),!1)),t},e.prototype.resolveTransition=function(e,n,i,s,c){var d,v,y,g,m=this;void 0===c&&(c=ot);var x=e.configuration,b=!n||e.transitions.length>0,w=b?e.configuration:n?n.configuration:[],_=qt(w,this),E=b?Ft(this.machine,x):void 0,A=n?n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0:void 0,O=this.getActions(new Set(w),_,e,i,c,n,s),k=n?r({},n.activities):{};try{for(var j=o(O),N=j.next();!N.done;N=j.next()){var I=N.value;try{for(var P=(y=void 0,o(I)),C=P.next();!C.done;C=P.next()){var L=C.value;L.type===u?k[L.activity.id||L.activity.type]=L:L.type===h&&(k[L.activity.id||L.activity.type]=!1)}}catch(t){y={error:t}}finally{try{C&&!C.done&&(g=P.return)&&g.call(P)}finally{if(y)throw y.error}}}}catch(t){d={error:t}}finally{try{N&&!N.done&&(v=j.return)&&v.call(j)}finally{if(d)throw d.error}}var V,D,R=a(jt(this,n,i,c,O,s,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),M=R[0],z=R[1],B=a(function(t,e){var n,r,i=a([[],[]],2),s=i[0],c=i[1];try{for(var u=o(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}return[s,c]}(M,(function(e){return e.type===f||e.type===l&&e.to===t.SpecialTargets.Internal})),2),F=B[0],q=B[1],X=M.filter((function(t){var e;return t.type===u&&(null===(e=t.activity)||void 0===e?void 0:e.type)===S})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=nt(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?U(t.data,n,r):void 0,c=a?Lt(a,t.id,s):Ct(t.id);return c.meta=t,c}(e.activity,m.machine,z,c),t}),n?r({},n.children):{}),$=new $t({value:E||n.value,context:z,_event:c,_sessionid:n?n._sessionid:null,historyValue:E?A?(V=A,D=E,{current:D,states:J(V,D)}):void 0:n?n.historyValue:void 0,history:!E||e.source?n:void 0,actions:E?q:[],activities:E?k:n?n.activities:{},events:[],configuration:w,transitions:e.transitions,children:X,done:_,tags:Xt(w),machine:this}),H=i!==z;$.changed=c.name===T||H;var G=$.history;G&&delete G.history;var K=!_&&(this._transient||x.some((function(t){return t._transient})));if(!(b||K&&""!==c.name))return $;var W=$;if(!_)for(K&&(W=this.resolveRaisedTransition(W,{type:p},c,s));F.length;){var Y=F.shift();W=this.resolveRaisedTransition(W,Y._event,c,s)}var Z=W.changed||(G?!!W.actions.length||H||typeof G.value!=typeof W.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(Q(e)||Q(n))return e===n;var r=Object.keys(e),i=Object.keys(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(W.value,G.value):void 0);return W.changed=Z,W.history=G,W},e.prototype.getStateNode=function(t){if(fe(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '".concat(t,"' from '").concat(this.id,"'; no child states exist."));var e=this.states[t];if(!e)throw new Error("Child state '".concat(t,"' does not exist on '").concat(this.id,"'"));return e},e.prototype.getStateNodeById=function(t){var e=fe(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#".concat(e,"' does not exist on machine '").concat(this.id,"'"));return n},e.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&fe(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=I(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},e.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||he;switch(this.type){case"parallel":return L(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):he}));case"compound":if(Q(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return Object.keys(t).length?L(t,(function(t,e){return t?n.getStateNode(e).resolve(t):he})):this.initialStateValue||{};default:return t||he}},e.prototype.getResolvedPath=function(t){if(fe(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '".concat(t,"'"));return e.path}return I(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=V(this.states,(function(t){return t.initialStateValue||he}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));e=Dt(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),e.prototype.getInitialState=function(t,e){this._init();var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)},Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=Q(e.target)&&fe(e.target)?C(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),e.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(e.prototype,"initialStateNodes",{get:function(){var t=this;return Dt(this)?[this]:"compound"!==this.type||this.initial?M(R(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),e.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=a(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var i=this.getStateNode(n);if("history"===i.type)return i.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(r)},e.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:V(this.states,(function(e,n){if(!t)return e.historyValue();var r=Q(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},e.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var r=this.target;return r?M(R(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var i,a,s=(i=n.path,a="states",function(t){var e,n,r=t;try{for(var s=o(i),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return Q(s)?[n.getStateNode(s)]:M(R(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,e=M(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var i=this.states,a=new Set(this.ownEvents);if(i)try{for(var s=o(Object.keys(i)),c=s.next();!c.done;c=s.next()){var u=i[c.value];if(u.states)try{for(var h=(n=void 0,o(u.events)),f=h.next();!f.done;f=h.next()){var l=f.value;a.add("".concat(l))}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),e.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!Q(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var r=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(r);try{return e.parent.getStateNodeByPath(r)}catch(t){throw new Error("Invalid transition definition for state node '".concat(e.id,"':\n").concat(t.message))}}))},e.prototype.formatTransition=function(t){var e=this,n=function(t){if(void 0!==t&&""!==t)return B(t)}(t.target),i="internal"in t?t.internal:!n||n.some((function(t){return Q(t)&&t[0]===e.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(n),s=r(r({},t),{actions:ct(B(t.actions)),cond:H(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return r(r({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(e.id)})}});return s},e.prototype.formatTransitions=function(){var t,e,n,r=this;if(this.config.on)if(Array.isArray(this.config.on))n=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=i(c,["*"]);n=M(Object.keys(f).map((function(t){return tt(t,f[t])})).concat(tt("*",h)))}else n=[];var l=this.config.always?tt("",this.config.always):[],d=this.config.onDone?tt(String(Et(this.id)),this.config.onDone):[],p=M(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,s([],a(tt(String(At(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,s([],a(tt(String(Ot(t.id)),t.onError)),!1)),e}))),v=this.after,y=M(s(s(s(s([],a(d),!1),a(p),!1),a(n),!1),a(l),!1).map((function(t){return B(t).map((function(t){return r.formatTransition(t)}))})));try{for(var g=o(v),m=g.next();!m.done;m=g.next()){var x=m.value;y.push(x)}}catch(e){t={error:e}}finally{try{m&&!m.done&&(e=g.return)&&e.call(g)}finally{if(t)throw t.error}}return y},e}();function de(t){return t}var pe=de,ve=_t,ye=lt,ge=vt,me=pt,xe=yt,Se=kt,be=At,we=ht;t.Interpreter=ae,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new le(t,e,n)},t.State=$t,t.StateNode=le,t.actions=Nt,t.assign=ve,t.createMachine=function(t,e){return new le(t,e)},t.createSchema=de,t.doneInvoke=be,t.forwardTo=Se,t.interpret=se,t.mapState=function(t,e){var n,r,i;try{for(var a=o(Object.keys(t)),s=a.next();!s.done;s=a.next()){var c=s.value;j(c,e)&&(!i||e.length>i.length)&&(i=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[i]},t.matchState=function(t,e,n){var r,i,s=$t.from(t,t instanceof $t?t.context:void 0);try{for(var c=o(e),u=c.next();!u.done;u=c.next()){var h=a(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return n(s)},t.matchesState=j,t.raise=we,t.send=ye,t.sendParent=me,t.sendTo=ge,t.sendUpdate=xe,t.spawn=function(t,e){var n=function(t){return Q(t)?r(r({},oe),{name:t}):r(r(r({},oe),{name:W()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):Lt(t,n.name)}(It[It.length-1])},t.spawnBehavior=re,t.t=pe,t.toActorRef=Vt,t.toEventObject=Y,t.toObserver=rt,t.toSCXMLEvent=Z,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */var e,n,i=function(){return(i=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}function o(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return a}function s(t,e,n){if(n||2===arguments.length)for(var i,r=0,o=e.length;r<o;r++)!i&&r in e||(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}t.ActionTypes=void 0,(e=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",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.Update="xstate.update",e.Pure="xstate.pure",e.Choose="xstate.choose",t.SpecialTargets=void 0,(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var c,u=t.ActionTypes.Start,h=t.ActionTypes.Stop,f=t.ActionTypes.Raise,l=t.ActionTypes.Send,d=t.ActionTypes.Cancel,p=t.ActionTypes.NullEvent,v=t.ActionTypes.Assign,y=t.ActionTypes.After,g=t.ActionTypes.DoneState,m=t.ActionTypes.Log,x=t.ActionTypes.Init,S=t.ActionTypes.Invoke,b=t.ActionTypes.ErrorExecution,w=t.ActionTypes.ErrorPlatform,_=t.ActionTypes.ErrorCustom,T=t.ActionTypes.Update,E=t.ActionTypes.Choose,A=t.ActionTypes.Pure,O=Object.freeze({__proto__:null,start:u,stop:h,raise:f,send:l,cancel:d,nullEvent:p,assign:v,after:y,doneState:g,log:m,init:x,invoke:S,errorExecution:b,errorPlatform:w,error:_,update:T,choose:E,pure:A}),k={};function j(t,e,n){void 0===n&&(n=".");var i=P(t,n),r=P(e,n);return Q(r)?!!Q(i)&&r===i:Q(i)?i in r:Object.keys(i).every((function(t){return t in r&&j(i[t],r[t])}))}function N(t){try{return Q(t)||"number"==typeof t?"".concat(t):t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function I(t,e){try{return X(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function P(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:X(t)?C(t):"string"!=typeof t?t:C(I(t,e));var n}function C(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function L(t,e){for(var n={},i=Object.keys(t),r=0;r<i.length;r++){var o=i[r];n[o]=e(t[o],o,t,r)}return n}function V(t,e,n){var i,r,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];n(h)&&(a[u]=e(h,u,t))}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(i)throw i.error}}return a}var D=function(t){return function(e){var n,i,r=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){r=r[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return r}};function R(t){return t?Q(t)?[[t]]:M(Object.keys(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?R(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function M(t){var e;return(e=[]).concat.apply(e,s([],a(t),!1))}function z(t){return X(t)?t:[t]}function B(t){return void 0===t?[]:z(t)}function U(t,e,n){var i,r;if($(t))return t(e,n.data);var a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];$(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(i)throw i.error}}return a}function F(t){return t instanceof Promise||!(null===t||!$(t)&&"object"!=typeof t||!$(t.then))}function J(t,e){return L(t.states,(function(t,n){if(t){var i=(Q(e)?void 0:e[n])||(t?t.current:void 0);if(i)return{current:i,states:J(t,i)}}}))}function q(t,e,n,i){return t?n.reduce((function(t,n){var r,a,s=n.assignment,c={state:i,action:n,_event:e},u={};if($(s))u=s(t,e.data,c);else try{for(var h=o(Object.keys(s)),f=h.next();!f.done;f=h.next()){var l=f.value,d=s[l];u[l]=$(d)?d(t,e.data,c):d}}catch(t){r={error:t}}finally{try{f&&!f.done&&(a=h.return)&&a.call(h)}finally{if(r)throw r.error}}return Object.assign({},t,u)}),t):t}function X(t){return Array.isArray(t)}function $(t){return"function"==typeof t}function Q(t){return"string"==typeof t}function H(t,e){if(t)return Q(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:$(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var G=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function K(t){return!!t&&"__xstatenode"in t}(c={})[G]=function(){return this},c[Symbol.observable]=function(){return this};var W=function(){var t=0;return function(){return(++t).toString(16)}}();function Y(t,e){return Q(t)||"number"==typeof t?i({type:t},e):t}function Z(t,e){if(!Q(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=Y(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function tt(t,e){return z(e).map((function(e){return void 0===e||"string"==typeof e||K(e)?{target:e,event:t}:i(i({},e),{event:t})}))}function et(t,e,n,i,r){var o=t.options.guards,a={state:r,cond:e,_event:i};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,i.data,a);var s=null==o?void 0:o[e.type];if(!s)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return s(n,i.data,a)}function nt(t){return"string"==typeof t?{type:t}:t}function it(t,e,n){var i=function(){},r="object"==typeof t,o=r?t:null;return{next:((r?t.next:t)||i).bind(o),error:((r?t.error:e)||i).bind(o),complete:((r?t.complete:n)||i).bind(o)}}function rt(t,e){return"".concat(t,":invocation[").concat(e,"]")}var ot=Z({type:x});function at(t,e){return e&&e[t]||void 0}function st(t,e){var n;if(Q(t)||"number"==typeof t)n=$(r=at(t,e))?{type:t,exec:r}:r||{type:t,exec:void 0};else if($(t))n={type:t.name||t.toString(),exec:t};else{var r;if($(r=at(t.type,e)))n=i(i({},t),{exec:r});else if(r){var o=r.type||t.type;n=i(i(i({},r),t),{type:o})}else n=t}return n}var ct=function(t,e){return t?(X(t)?t:[t]).map((function(t){return st(t,e)})):[]};function ut(t){var e=st(t);return i(i({id:Q(t)?t:e.id},e),{type:e.type})}function ht(e){return Q(e)?{type:f,event:e}:lt(e,{to:t.SpecialTargets.Internal})}function ft(t){return{type:f,_event:Z(t.event)}}function lt(t,e){return{to:e?e.to:void 0,type:l,event:$(t)?t:Y(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:$(t)?t.name:N(t)}}function dt(t,e,n,r){var o,a={_event:n},s=Z($(t.event)?t.event(e,n.data,a):t.event);if(Q(t.delay)){var c=r&&r[t.delay];o=$(c)?c(e,n.data,a):c}else o=$(t.delay)?t.delay(e,n.data,a):t.delay;var u=$(t.to)?t.to(e,n.data,a):t.to;return i(i({},t),{to:u,_event:s,event:s.data,delay:o})}function pt(e,n){return lt(e,i(i({},n),{to:t.SpecialTargets.Parent}))}function vt(t,e,n){return lt(e,i(i({},n),{to:t}))}function yt(){return pt(T)}var gt=function(t,e){return{context:t,event:e}};var mt=function(t,e,n){return i(i({},t),{value:Q(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})},xt=function(t){return{type:d,sendId:t}};function St(e){var n=ut(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function bt(e){var n=$(e)?e:ut(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function wt(e,n,i){var r=$(e.activity)?e.activity(n,i.data):e.activity,o="string"==typeof r?{id:r}:r;return{type:t.ActionTypes.Stop,activity:o}}var _t=function(t){return{type:v,assignment:t}};function Tt(e,n){var i=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(i)}function Et(e,n){var i="".concat(t.ActionTypes.DoneState,".").concat(e),r={type:i,data:n,toString:function(){return i}};return r}function At(e,n){var i="".concat(t.ActionTypes.DoneInvoke,".").concat(e),r={type:i,data:n,toString:function(){return i}};return r}function Ot(e,n){var i="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),r={type:i,data:n,toString:function(){return i}};return r}function kt(t,e){return lt((function(t,e){return e}),i(i({},e),{to:t}))}function jt(e,n,r,c,u,d,p){void 0===p&&(p=!1);var y=p?[]:function(t){var e,n,i=[];try{for(var r=o(t),a=r.next();!a.done;a=r.next())for(var s=a.value,c=0;c<s.actions.length;)s.actions[c].type!==v?c++:(i.push(s.actions[c]),s.actions.splice(c,1))}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return i}(u),g=y.length?q(r,c,y,n):r,x=p?[r]:void 0,S=[];function b(o,u){var y;switch(u.type){case f:return ft(u);case l:var b=dt(u,g,c,e.options.delays);return d&&b.to!==t.SpecialTargets.Internal&&("entry"===o?S.push(b):null==d||d(b,g,c)),b;case m:var w=mt(u,g,c);return null==d||d(w,g,c),w;case E:if(!(k=null===(y=u.conds.find((function(t){var i=H(t.cond,e.options.guards);return!i||et(e,i,g,c,d?void 0:n)})))||void 0===y?void 0:y.actions))return[];var _=a(jt(e,n,g,c,[{type:o,actions:ct(B(k),e.options.actions)}],d,p),2),T=_[0],O=_[1];return g=O,null==x||x.push(g),T;case A:var k;if(!(k=u.get(g,c.data)))return[];var j=a(jt(e,n,g,c,[{type:o,actions:ct(B(k),e.options.actions)}],d,p),2),N=j[0],I=j[1];return g=I,null==x||x.push(g),N;case h:w=wt(u,g,c);return null==d||d(w,r,c),w;case v:g=q(g,c,[u],d?void 0:n),null==x||x.push(g);break;default:var P=st(u,e.options.actions),C=P.exec;if(d)d(P,g,c);else if(C&&x){var L=x.length-1;P=i(i({},P),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];C.apply(void 0,s([x[L]],a(e),!1))}})}return P}}return[M(u.map((function(t){var e,n,i=[];try{for(var r=o(t.actions),a=r.next();!a.done;a=r.next()){var s=a.value,u=b(t.type,s);u&&(i=i.concat(u))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return S.forEach((function(t){d(t,g,c)})),S.length=0,i}))),g]}var Nt=Object.freeze({__proto__:null,actionTypes:O,initEvent:ot,getActionFunction:at,toActionObject:st,toActionObjects:ct,toActivityDefinition:ut,raise:ht,resolveRaise:ft,send:lt,resolveSend:dt,sendParent:pt,sendTo:vt,sendUpdate:yt,respond:function(t,e){return lt(t,i(i({},e),{to:function(t,e,n){return n._event.origin}}))},log:function(t,e){return void 0===t&&(t=gt),{type:m,label:e,expr:t}},resolveLog:mt,cancel:xt,start:St,stop:bt,resolveStop:wt,assign:_t,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Tt,done:Et,doneInvoke:At,error:Ot,pure:function(e){return{type:t.ActionTypes.Pure,get:e}},forwardTo:kt,escalate:function(e,n){return pt((function(t,n,i){return{type:_,data:$(e)?e(t,n,i):e}}),i(i({},n),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},resolveActions:jt}),It=[],Pt=function(t,e){It.push(t);var n=e(t);return It.pop(),n};function Ct(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[G]=function(){return this},e}function Lt(t,e,n){var i=Ct(e);if(i.deferred=!0,K(t)){var r=i.state=Pt(void 0,(function(){return(n?t.withContext(n):t).initialState}));i.getSnapshot=function(){return r}}return i}function Vt(t){var e;return i(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[G]=function(){return this},e),t)}var Dt=function(t){return"atomic"===t.type||"final"===t.type};function Rt(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function Mt(t){return Rt(t).filter((function(t){return"history"!==t.type}))}function zt(t){var e=[t];return Dt(t)?e:e.concat(M(Mt(t).map(zt)))}function Bt(t,e){var n,i,r,a,s,c,u,h,f=Ut(new Set(t)),l=new Set(e);try{for(var d=o(l),p=d.next();!p.done;p=d.next())for(var v=(T=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=Ut(l);try{for(var g=o(l),m=g.next();!m.done;m=g.next()){if("compound"!==(T=m.value).type||y.get(T)&&y.get(T).length){if("parallel"===T.type)try{for(var x=(s=void 0,o(Mt(T))),S=x.next();!S.done;S=x.next()){var b=S.value;l.has(b)||(l.add(b),f.get(b)?f.get(b).forEach((function(t){return l.add(t)})):b.initialStateNodes.forEach((function(t){return l.add(t)})))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(T)?f.get(T).forEach((function(t){return l.add(t)})):T.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){r={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(r)throw r.error}}try{for(var w=o(l),_=w.next();!_.done;_=w.next()){var T;for(v=(T=_.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}return l}function Ut(t){var e,n,i=new Map;try{for(var r=o(t),a=r.next();!a.done;a=r.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return i}function Ft(t,e){return function t(e,n){var i=n.get(e);if(!i)return{};if("compound"===e.type){var r=i[0];if(!r)return{};if(Dt(r))return r.key}var o={};return i.forEach((function(e){o[e.key]=t(e,n)})),o}(t,Ut(Bt([t],e)))}function Jt(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function qt(t,e){return"compound"===e.type?Mt(e).some((function(e){return"final"===e.type&&Jt(t,e)})):"parallel"===e.type&&Mt(e).every((function(e){return qt(t,e)}))}function Xt(t){return new Set(M(t.map((function(t){return t.tags}))))}var $t=function(){function t(t){var e,n,i=this;this.actions=[],this.activities=k,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||k,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],a(new Set(M(s([],a(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(i.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ot,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=ot;return new t({value:e.value,context:n,_event:i,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),Q(t))return[t];var i=Object.keys(t);return i.concat.apply(i,s([],a(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=r(t,["configuration","transitions","tags","machine"]);return i(i({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return j(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),Qt={deferEvents:!1},Ht=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},Qt),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Gt=new Map,Kt=0,Wt=function(){return"x:".concat(Kt++)},Yt=function(t,e){return Gt.set(t,e),t},Zt=function(t){return Gt.get(t)},te=function(t){Gt.delete(t)};function ee(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function ne(t){if(ee()){var e=function(){var t=ee();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ie(t,e){void 0===e&&(e={});var n=t.initialState,i=new Set,r=[],o=!1,a=Vt({id:e.id,send:function(e){r.push(e),function(){if(!o){for(o=!0;r.length>0;){var e=r.shift();n=t.transition(n,e,s),i.forEach((function(t){return t.next(n)}))}o=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=it(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),s={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(s):n,a}var re,oe={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(re=t.InterpreterStatus||(t.InterpreterStatus={}))[re.NotStarted=0]="NotStarted",re[re.Running=1]="Running",re[re.Stopped=2]="Stopped";var ae=function(){function e(n,r){void 0===r&&(r=e.defaultOptions);var o=this;this.machine=n,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(e,n){if(X(e))return o.batch(e),o.state;var i=Z(Y(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'.concat(i.name,'" was sent to uninitialized service "').concat(o.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(i.data)));return o.scheduler.schedule((function(){o.forward(i);var t=o._nextState(i);o.update(t,i)})),o._state},this.sendTo=function(e,n,r){var a,s=o.parent&&(n===t.SpecialTargets.Parent||o.parent.id===n),c=s?o.parent:Q(n)?o.children.get(n)||Zt(n):(a=n)&&"function"==typeof a.send?n:void 0;if(c)if("machine"in c){if(o.status!==t.InterpreterStatus.Stopped||o.parent!==c||o.state.done){var u=i(i({},e),{name:e.name===_?"".concat(Ot(o.id)):e.name,origin:o.sessionId});!r&&o.machine.config.predictableActionArguments?o._outgoingQueue.push([c,u]):c.send(u)}}else!r&&o.machine.config.predictableActionArguments?o._outgoingQueue.push([c,e.data]):c.send(e.data);else if(!s)throw new Error("Unable to send event to child '".concat(n,"' from service '").concat(o.id,"'."))},this._exec=function(e,n,i,r){void 0===r&&(r=o.machine.options.actions);var a=e.exec||at(e.type,r),s=$(a)?a:a?a.exec:e.exec;if(s)try{return s(n,i.data,o.machine.config.predictableActionArguments?{action:e,_event:i}:{action:e,state:o.state,_event:i})}catch(t){throw o.parent&&o.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case l:var c=e;if("number"==typeof c.delay)return void o.defer(c);c.to?o.sendTo(c._event,c.to,i===ot):o.send(c._event);break;case d:o.cancel(e.sendId);break;case u:if(o.status!==t.InterpreterStatus.Running)return;var f=e.activity;if(!o.machine.config.predictableActionArguments&&!o.state.activities[f.id||f.type])break;if(f.type===t.ActionTypes.Invoke){var p=nt(f.src),v=o.machine.options.services?o.machine.options.services[p.type]:void 0,y=f.id,g=f.data,x="autoForward"in f?f.autoForward:!!f.forward;if(!v)return;var S=g?U(g,n,i):void 0;if("string"==typeof v)return;var b=$(v)?v(n,i.data,{data:S,src:p,meta:f.meta}):v;if(!b)return;var w=void 0;K(b)&&(b=S?b.withContext(S):b,w={autoForward:x}),o.spawn(b,y,w)}else o.spawnActivity(f);break;case h:o.stopChild(e.activity.id);break;case m:var _=e.label,T=e.value;_?o.logger(_,T):o.logger(T)}};var a=i(i({},e.defaultOptions),r),s=a.clock,c=a.logger,f=a.parent,p=a.id,v=void 0!==p?p:n.id;this.id=v,this.logger=c,this.clock=s,this.parent=f,this.options=a,this.scheduler=new Ht({deferEvents:this.options.deferEvents}),this.sessionId=Wt()}return Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Pt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),e.prototype.execute=function(t,e){var n,i;try{for(var r=o(t.actions),a=r.next();!a.done;a=r.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,i,r,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==ot||!this.options.execute)for(var l=void 0;l=this._outgoingQueue.shift();)l[0].send(l[1]);else this.execute(this.state);if(this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=o(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var v=o(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(a=v.return)&&a.call(v)}finally{if(r)throw r.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{m&&!m.done&&(c=g.return)&&c.call(g)}finally{if(s)throw s.error}}if(this.state.done){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),S=x&&x.doneData?U(x.doneData,t.context,e):void 0;try{for(var b=o(this.doneListeners),w=b.next();!w.done;w=b.next()){(0,w.value)(At(this.id,S))}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this._stop(),this._stopChildren()}},e.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},e.prototype.subscribe=function(e,n,i){var r=this,o=it(e,n,i);this.listeners.add(o.next),this.status!==t.InterpreterStatus.NotStarted&&o.next(this.state);var a=function(){r.doneListeners.delete(a),r.stopListeners.delete(a),o.complete()};return this.status===t.InterpreterStatus.Stopped?o.complete():(this.onDone(a),this.onStop(a)),{unsubscribe:function(){r.listeners.delete(o.next),r.doneListeners.delete(a),r.stopListeners.delete(a)}}},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(t){return this.doneListeners.add(t),this},e.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},e.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),Yt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:Pt(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState($t.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,ot)})),this},e.prototype._stopChildren=function(){this.children.forEach((function(t){$(t.stop)&&t.stop()})),this.children.clear()},e.prototype._stop=function(){var e,n,i,r,a,s,c,u,h,f;try{for(var l=o(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(t){e={error:t}}finally{try{d&&!d.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}try{for(var v=o(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){i={error:t}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(i)throw i.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(s=g.return)&&s.call(g)}finally{if(a)throw a.error}}try{for(var x=o(this.doneListeners),S=x.next();!S.done;S=x.next()){p=S.value;this.doneListeners.delete(p)}}catch(t){c={error:t}}finally{try{S&&!S.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0;try{for(var b=o(Object.keys(this.delayedEventsMap)),w=b.next();!w.done;w=b.next()){var _=w.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{w&&!w.done&&(f=b.return)&&f.call(b)}finally{if(h)throw h.error}}this.scheduler.clear(),this.scheduler=new Ht({deferEvents:this.options.deferEvents})},e.prototype.stop=function(){var e=this,n=this.scheduler;return this._stop(),n.schedule((function(){var n=Z({type:"xstate.stop"}),i=Pt(e,(function(){var i=M(s([],a(e.state.configuration),!1).sort((function(t,e){return e.order-t.order})).map((function(t){return ct(t.onExit,e.machine.options.actions)}))),r=a(jt(e.machine,e.state,e.state.context,n,[{type:"exit",actions:i}],e.machine.config.predictableActionArguments?e._exec:void 0,e.machine.config.predictableActionArguments||e.machine.config.preserveActionOrder),2),o=r[0],c=r[1],u=new $t({value:e.state.value,context:c,_event:n,_sessionid:e.sessionId,historyValue:void 0,history:e.state,actions:o.filter((function(e){return e.type!==f&&(e.type!==l||!!e.to&&e.to!==t.SpecialTargets.Internal)})),activities:{},events:[],configuration:[],transitions:[],children:{},done:e.state.done,tags:e.state.tags,machine:e.machine});return u.changed=!0,u}));e.update(i,n),e._stopChildren(),te(e.sessionId)})),this},e.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var r=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule((function(){var t,c,u=n.state,h=!1,f=[],l=function(t){var e=Z(t);n.forward(e),u=Pt(n,(function(){return n.machine.transition(u,e,void 0,r||void 0)})),f.push.apply(f,s([],a(n.machine.config.predictableActionArguments?u.actions:u.actions.map((function(t){return function(t,e){var n=t.exec;return i(i({},t),{exec:void 0!==n?function(){return n(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0})}(t,u)}))),!1)),h=h||!!u.changed};try{for(var d=o(e),p=d.next();!p.done;p=d.next()){l(p.value)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(t)throw t.error}}u.changed=h,u.actions=f,n.update(u,Z(e[e.length-1]))}))}},e.prototype.sender=function(t){return this.send.bind(this,t)},e.prototype._nextState=function(t,e){var n=this;void 0===e&&(e=!!this.machine.config.predictableActionArguments&&this._exec);var i=Z(t);if(0===i.name.indexOf(w)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(w)})))throw i.data.data;return Pt(this,(function(){return n.machine.transition(n.state,i,void 0,e||void 0)}))},e.prototype.nextState=function(t){return this._nextState(t,!1)},e.prototype.forward=function(t){var e,n;try{for(var i=o(this.forwardTo),r=i.next();!r.done;r=i.next()){var a=r.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));s.send(t)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},e.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to,!0):e.send(t._event)}),t.delay)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(t,e,n){void 0===n&&(n=this.machine.options.actions),this._exec(t,e.context,e._event,n)},e.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),$(e.stop)&&e.stop())},e.prototype.spawn=function(e,n,r){if(this.status!==t.InterpreterStatus.Running)return Lt(e,n);if(F(e))return this.spawnPromise(Promise.resolve(e),n);if($(e))return this.spawnCallback(e,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(a=e)&&"id"in a)return this.spawnActor(e,n);if(function(t){try{return"subscribe"in t&&$(t.subscribe)}catch(t){return!1}}(e))return this.spawnObservable(e,n);if(K(e))return this.spawnMachine(e,i(i({},r),{id:n}));if(null!==(o=e)&&"object"==typeof o&&"transition"in o&&"function"==typeof o.transition)return this.spawnBehavior(e,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof e,'".'));var o,a},e.prototype.spawnMachine=function(t,n){var r=this;void 0===n&&(n={});var o=new e(t,i(i({},this.options),{parent:this,id:n.id||t.id})),a=i(i({},oe),n);a.sync&&o.onTransition((function(t){r.send(T,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){r.removeChild(o.id),r.send(Z(t,{origin:o.id}))})).start(),s},e.prototype.spawnBehavior=function(t,e){var n=ie(t,{id:e,parent:this});return this.children.set(e,n),n},e.prototype.spawnPromise=function(t,e){var n,i,r=this,o=!1;t.then((function(t){o||(i=t,r.removeChild(e),r.send(Z(At(e,t),{origin:e})))}),(function(t){if(!o){r.removeChild(e);var n=Ot(e,t);try{r.send(Z(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var a=((n={id:e,send:function(){},subscribe:function(e,n,i){var r=it(e,n,i),o=!1;return t.then((function(t){o||(r.next(t),o||r.complete())}),(function(t){o||r.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return i}})[G]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnCallback=function(t,e){var n,i,r,o=this,a=!1,s=new Set,c=new Set;try{r=t((function(t){i=t,c.forEach((function(e){return e(t)})),a||o.send(Z(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(Ot(e,t))}if(F(r))return this.spawnPromise(r,e);var u=((n={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){var e=it(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){a=!0,$(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return i}})[G]=function(){return this},n);return this.children.set(e,u),u},e.prototype.spawnObservable=function(t,e){var n,i,r=this,o=t.subscribe((function(t){i=t,r.send(Z(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(Z(Ot(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(Z(At(e),{origin:e}))})),a=((n={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return i},toJSON:function(){return{id:e}}})[G]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},e.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},e.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[G]=function(){return this},n))},e.prototype.attachDev=function(){var t=ee();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:i({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}ne(this)}},e.prototype.toJSON=function(){return{id:this.id}},e.prototype[G]=function(){return this},e.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},e.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},e.interpret=se,e}();function se(t,e){return new ae(t,e)}function ce(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function ue(t){return i(i({type:S},t),{toJSON:function(){t.onDone,t.onError;var e=r(t,["onDone","onError"]);return i(i({},e),{type:S,src:ce(t.src)})}})}var he={},fe=function(t){return"#"===t[0]},le=function(){function e(t,n,r,c){void 0===r&&(r="context"in t?t.context:void 0);var u,h=this;this.config=t,this._context=r,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==c?void 0:c.parent,this.key=this.config.key||(null==c?void 0:c.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||s([this.machine.key],a(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?L(this.config.states,(function(t,n){var r,o=new e(t,{},void 0,{parent:h,key:n});return Object.assign(h.idMap,i(((r={})[o.id]=o,r),o.idMap)),o})):he;var f=0;!function t(e){var n,i;e.order=f++;try{for(var r=o(Rt(e)),a=r.next();!a.done;a=r.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=B(this.config.entry||this.config.onEntry).map((function(t){return st(t)})),this.onExit=B(this.config.exit||this.config.onExit).map((function(t){return st(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=B(this.config.invoke).map((function(t,e){var n,r;if(K(t)){var o=rt(h.id,e);return h.machine.options.services=i(((n={})[o]=t,n),h.machine.options.services),ue({src:o,id:o})}if(Q(t.src)){o=t.id||rt(h.id,e);return ue(i(i({},t),{id:o,src:t.src}))}if(K(t.src)||$(t.src)){o=t.id||rt(h.id,e);return h.machine.options.services=i(((r={})[o]=t.src,r),h.machine.options.services),ue(i(i({id:o},t),{src:o}))}var a=t.src;return ue(i(i({id:rt(h.id,e)},t),{src:a}))})),this.activities=B(this.config.activities).concat(this.invoke).map((function(t){return ut(t)})),this.transition=this.transition.bind(this),this.tags=B(this.config.tags)}return e.prototype._init=function(){this.__cache.transitions||zt(this).forEach((function(t){return t.on}))},e.prototype.withConfig=function(t,n){var r=this.options,o=r.actions,a=r.activities,s=r.guards,c=r.services,u=r.delays;return new e(this.config,{actions:i(i({},o),t.actions),activities:i(i({},a),t.activities),guards:i(i({},s),t.guards),services:i(i({},c),t.services),delays:i(i({},u),t.delays)},null!=n?n:this.context)},e.prototype.withContext=function(t){return new e(this.config,this.options,t)},Object.defineProperty(e.prototype,"context",{get:function(){return $(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:L(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.definition},Object.defineProperty(e.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),e.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var i=n.eventType===t;return e?i:i||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},e.prototype.getDelayedTransitions=function(){var t=this,e=this.config.after;if(!e)return[];var n=function(e,n){var i=Tt($(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(lt(i,{delay:e})),t.onExit.push(xt(i)),i};return(X(e)?e.map((function(t,e){var r=n(t.delay,e);return i(i({},t),{event:r})})):M(Object.keys(e).map((function(t,r){var o=e[t],a=Q(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=n(s,r);return B(a).map((function(t){return i(i({},t),{event:c,delay:s})}))})))).map((function(e){var n=e.delay;return i(i({},t.formatTransition(e)),{delay:n})}))},e.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var i=t instanceof $t?t.value:P(t,this.delimiter);if(Q(i)){var r=this.getStateNode(i).initial;return void 0!==r?this.getStateNodes(((e={})[i]=r,e)):[this,this.states[i]]}var o=Object.keys(i),c=[this];return c.push.apply(c,s([],a(M(o.map((function(t){return n.getStateNode(t).getStateNodes(i[t])})))),!1)),c},e.prototype.handles=function(t){var e=N(t);return this.events.includes(e)},e.prototype.resolveState=function(t){var e=t instanceof $t?t:$t.create(t),n=Array.from(Bt([],this.getStateNodes(e.value)));return new $t(i(i({},e),{value:this.resolve(e.value),configuration:n,done:qt(n,this),tags:Xt(n),machine:this.machine}))},e.prototype.transitionLeafNode=function(t,e,n){var i=this.getStateNode(t).next(e,n);return i&&i.transitions.length?i:this.next(e,n)},e.prototype.transitionCompoundNode=function(t,e,n){var i=Object.keys(t),r=this.getStateNode(i[0])._transition(t[i[0]],e,n);return r&&r.transitions.length?r:this.next(e,n)},e.prototype.transitionParallelNode=function(t,e,n){var i,r,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];if(h){var f=this.getStateNode(u)._transition(h,e,n);f&&(a[u]=f)}}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(i)throw i.error}}var l=Object.keys(a).map((function(t){return a[t]})),d=M(l.map((function(t){return t.transitions})));if(!l.some((function(t){return t.transitions.length>0})))return this.next(e,n);var p=M(Object.keys(a).map((function(t){return a[t].configuration})));return{transitions:d,exitSet:M(l.map((function(t){return t.exitSet}))),configuration:p,source:e,actions:M(Object.keys(a).map((function(t){return a[t].actions})))}},e.prototype._transition=function(t,e,n){return Q(t)?this.transitionLeafNode(t,e,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},e.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,Z(e))},e.prototype.next=function(t,e){var n,i,r,c=this,u=e.name,h=[],f=[];try{for(var l=o(this.getCandidates(u)),d=l.next();!d.done;d=l.next()){var p=d.value,v=p.cond,y=p.in,g=t.context,m=!y||(Q(y)&&fe(y)?t.matches(P(this.getStateNodeById(y).path,this.delimiter)):j(P(y,this.delimiter),D(this.path.slice(0,-2))(t.value))),x=!1;try{x=!v||et(this.machine,v,g,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(v.name||v.type,"' in transition for event '").concat(u,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(x&&m){void 0!==p.target&&(f=p.target),h.push.apply(h,s([],a(p.actions),!1)),r=p;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}if(r){if(!f.length)return{transitions:[r],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var S=M(f.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)})));return{transitions:[r],exitSet:!!r.internal?[]:M(f.map((function(t){return c.getPotentiallyReenteringNodes(t)}))),configuration:S,source:t,actions:h}}},e.prototype.getPotentiallyReenteringNodes=function(t){if(this.order<t.order)return[this];for(var e=[],n=this,i=t;n&&n!==i;)e.push(n),n=n.parent;return n!==i?[]:(e.push(i),e)},e.prototype.getActions=function(e,n,i,r,c,u,h){var d,p,v,y,g=this,m=u?Bt([],this.getStateNodes(u.value)):[],x=new Set;try{for(var S=o(Array.from(e).sort((function(t,e){return t.order-e.order}))),b=S.next();!b.done;b=S.next()){(!Jt(m,T=b.value)||Jt(i.exitSet,T)||T.parent&&x.has(T.parent))&&x.add(T)}}catch(t){d={error:t}}finally{try{b&&!b.done&&(p=S.return)&&p.call(S)}finally{if(d)throw d.error}}try{for(var w=o(m),_=w.next();!_.done;_=w.next()){var T;Jt(e,T=_.value)&&!Jt(i.exitSet,T.parent)||i.exitSet.push(T)}}catch(t){v={error:t}}finally{try{_&&!_.done&&(y=w.return)&&y.call(w)}finally{if(v)throw v.error}}i.exitSet.sort((function(t,e){return e.order-t.order}));var E=Array.from(x).sort((function(t,e){return t.order-e.order})),A=new Set(i.exitSet),O=M(E.map((function(t){var e=[];if("final"!==t.type)return e;var n=t.parent;if(!n.parent)return e;e.push(Et(t.id,t.doneData),Et(n.id,t.doneData?U(t.doneData,r,c):void 0));var o=n.parent;return"parallel"===o.type&&Mt(o).every((function(t){return qt(i.configuration,t)}))&&e.push(Et(o.id)),e}))),k=E.map((function(t){var e=t.onEntry,n=t.activities.map((function(t){return St(t)}));return{type:"entry",actions:ct(h?s(s([],a(e),!1),a(n),!1):s(s([],a(n),!1),a(e),!1),g.machine.options.actions)}})).concat({type:"state_done",actions:O.map(ht)}),j=Array.from(A).map((function(t){return{type:"exit",actions:ct(s(s([],a(t.onExit),!1),a(t.activities.map((function(t){return bt(t)}))),!1),g.machine.options.actions)}})).concat({type:"transition",actions:ct(i.actions,this.machine.options.actions)}).concat(k);if(n){var N=ct(M(s([],a(e),!1).sort((function(t,e){return e.order-t.order})).map((function(t){return t.onExit}))),this.machine.options.actions).filter((function(e){return e.type!==f&&(e.type!==l||!!e.to&&e.to!==t.SpecialTargets.Internal)}));return j.concat({type:"stop",actions:N})}return j},e.prototype.transition=function(t,e,n,i){void 0===t&&(t=this.initialState);var r,o,c=Z(e);if(t instanceof $t)r=void 0===n?t:this.resolveState($t.from(t,n));else{var u=Q(t)?this.resolve(C(this.getResolvedPath(t))):this.resolve(t),h=null!=n?n:this.machine.context;r=this.resolveState($t.from(u,h))}if(this.strict&&!this.events.includes(c.name)&&(o=c.name,!/^(done|error)\./.test(o)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(c.name,"'"));var f=this._transition(r.value,r,c)||{transitions:[],configuration:[],exitSet:[],source:r,actions:[]},l=Bt([],this.getStateNodes(r.value)),d=f.configuration.length?Bt(l,f.configuration):l;return f.configuration=s([],a(d),!1),this.resolveTransition(f,r,r.context,i,c)},e.prototype.resolveRaisedTransition=function(t,e,n,i){var r,o=t.actions;return(t=this.transition(t,e,void 0,i))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,s([],a(o),!1)),t},e.prototype.resolveTransition=function(e,n,r,s,c){var d,v,y,g,m=this;void 0===c&&(c=ot);var x=e.configuration,b=!n||e.transitions.length>0,w=b?e.configuration:n?n.configuration:[],_=qt(w,this),E=b?Ft(this.machine,x):void 0,A=n?n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0:void 0,O=this.getActions(new Set(w),_,e,r,c,n,s),k=n?i({},n.activities):{};try{for(var j=o(O),N=j.next();!N.done;N=j.next()){var I=N.value;try{for(var P=(y=void 0,o(I.actions)),C=P.next();!C.done;C=P.next()){var L=C.value;L.type===u?k[L.activity.id||L.activity.type]=L:L.type===h&&(k[L.activity.id||L.activity.type]=!1)}}catch(t){y={error:t}}finally{try{C&&!C.done&&(g=P.return)&&g.call(P)}finally{if(y)throw y.error}}}}catch(t){d={error:t}}finally{try{N&&!N.done&&(v=j.return)&&v.call(j)}finally{if(d)throw d.error}}var V,D,R=a(jt(this,n,r,c,O,s,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),M=R[0],z=R[1],B=a(function(t,e){var n,i,r=a([[],[]],2),s=r[0],c=r[1];try{for(var u=o(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}return[s,c]}(M,(function(e){return e.type===f||e.type===l&&e.to===t.SpecialTargets.Internal})),2),F=B[0],q=B[1],X=M.filter((function(t){var e;return t.type===u&&(null===(e=t.activity)||void 0===e?void 0:e.type)===S})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,i){var r,o=nt(t.src),a=null===(r=null==e?void 0:e.options.services)||void 0===r?void 0:r[o.type],s=t.data?U(t.data,n,i):void 0,c=a?Lt(a,t.id,s):Ct(t.id);return c.meta=t,c}(e.activity,m.machine,z,c),t}),n?i({},n.children):{}),$=new $t({value:E||n.value,context:z,_event:c,_sessionid:n?n._sessionid:null,historyValue:E?A?(V=A,D=E,{current:D,states:J(V,D)}):void 0:n?n.historyValue:void 0,history:!E||e.source?n:void 0,actions:E?q:[],activities:E?k:n?n.activities:{},events:[],configuration:w,transitions:e.transitions,children:X,done:_,tags:Xt(w),machine:this}),H=r!==z;$.changed=c.name===T||H;var G=$.history;G&&delete G.history;var K=!_&&(this._transient||x.some((function(t){return t._transient})));if(!(b||K&&""!==c.name))return $;var W=$;if(!_)for(K&&(W=this.resolveRaisedTransition(W,{type:p},c,s));F.length;){var Y=F.shift();W=this.resolveRaisedTransition(W,Y._event,c,s)}var Z=W.changed||(G?!!W.actions.length||H||typeof G.value!=typeof W.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(Q(e)||Q(n))return e===n;var i=Object.keys(e),r=Object.keys(n);return i.length===r.length&&i.every((function(i){return t(e[i],n[i])}))}(W.value,G.value):void 0);return W.changed=Z,W.history=G,W},e.prototype.getStateNode=function(t){if(fe(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '".concat(t,"' from '").concat(this.id,"'; no child states exist."));var e=this.states[t];if(!e)throw new Error("Child state '".concat(t,"' does not exist on '").concat(this.id,"'"));return e},e.prototype.getStateNodeById=function(t){var e=fe(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#".concat(e,"' does not exist on machine '").concat(this.id,"'"));return n},e.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&fe(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=I(t,this.delimiter).slice(),n=this;e.length;){var i=e.shift();if(!i.length)break;n=n.getStateNode(i)}return n},e.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||he;switch(this.type){case"parallel":return L(this.initialStateValue,(function(e,i){return e?n.getStateNode(i).resolve(t[i]||e):he}));case"compound":if(Q(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((e={})[t]=i.initialStateValue,e):t}return Object.keys(t).length?L(t,(function(t,e){return t?n.getStateNode(e).resolve(t):he})):this.initialStateValue||{};default:return t||he}},e.prototype.getResolvedPath=function(t){if(fe(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '".concat(t,"'"));return e.path}return I(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=V(this.states,(function(t){return t.initialStateValue||he}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));e=Dt(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),e.prototype.getInitialState=function(t,e){this._init();var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)},Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=Q(e.target)&&fe(e.target)?C(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),e.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(e.prototype,"initialStateNodes",{get:function(){var t=this;return Dt(this)?[this]:"compound"!==this.type||this.initial?M(R(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),e.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=a(t),n=e[0],i=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var r=this.getStateNode(n);if("history"===r.type)return r.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(i)},e.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:V(this.states,(function(e,n){if(!t)return e.historyValue();var i=Q(t)?void 0:t[n];return e.historyValue(i||e.initialStateValue)}),(function(t){return!t.history}))}},e.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?M(R(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var r,a,s=(r=n.path,a="states",function(t){var e,n,i=t;try{for(var s=o(r),c=s.next();!c.done;c=s.next()){var u=c.value;i=i[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return i})(t).current;return Q(s)?[n.getStateNode(s)]:M(R(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,e=M(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var r=this.states,a=new Set(this.ownEvents);if(r)try{for(var s=o(Object.keys(r)),c=s.next();!c.done;c=s.next()){var u=r[c.value];if(u.states)try{for(var h=(n=void 0,o(u.events)),f=h.next();!f.done;f=h.next()){var l=f.value;a.add("".concat(l))}}catch(t){n={error:t}}finally{try{f&&!f.done&&(i=h.return)&&i.call(h)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),e.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!Q(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var i=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(i);try{return e.parent.getStateNodeByPath(i)}catch(t){throw new Error("Invalid transition definition for state node '".concat(e.id,"':\n").concat(t.message))}}))},e.prototype.formatTransition=function(t){var e=this,n=function(t){if(void 0!==t&&""!==t)return B(t)}(t.target),r="internal"in t?t.internal:!n||n.some((function(t){return Q(t)&&t[0]===e.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(n),s=i(i({},t),{actions:ct(B(t.actions)),cond:H(t.cond,o),target:a,source:this,internal:r,eventType:t.event,toJSON:function(){return i(i({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(e.id)})}});return s},e.prototype.formatTransitions=function(){var t,e,n,i=this;if(this.config.on)if(Array.isArray(this.config.on))n=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=r(c,["*"]);n=M(Object.keys(f).map((function(t){return tt(t,f[t])})).concat(tt("*",h)))}else n=[];var l=this.config.always?tt("",this.config.always):[],d=this.config.onDone?tt(String(Et(this.id)),this.config.onDone):[],p=M(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,s([],a(tt(String(At(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,s([],a(tt(String(Ot(t.id)),t.onError)),!1)),e}))),v=this.after,y=M(s(s(s(s([],a(d),!1),a(p),!1),a(n),!1),a(l),!1).map((function(t){return B(t).map((function(t){return i.formatTransition(t)}))})));try{for(var g=o(v),m=g.next();!m.done;m=g.next()){var x=m.value;y.push(x)}}catch(e){t={error:e}}finally{try{m&&!m.done&&(e=g.return)&&e.call(g)}finally{if(t)throw t.error}}return y},e}();function de(t){return t}var pe=de,ve=_t,ye=lt,ge=vt,me=pt,xe=yt,Se=kt,be=At,we=ht;t.Interpreter=ae,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new le(t,e,n)},t.State=$t,t.StateNode=le,t.actions=Nt,t.assign=ve,t.createMachine=function(t,e){return new le(t,e)},t.createSchema=de,t.doneInvoke=be,t.forwardTo=Se,t.interpret=se,t.mapState=function(t,e){var n,i,r;try{for(var a=o(Object.keys(t)),s=a.next();!s.done;s=a.next()){var c=s.value;j(c,e)&&(!r||e.length>r.length)&&(r=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[r]},t.matchState=function(t,e,n){var i,r,s=$t.from(t,t instanceof $t?t.context:void 0);try{for(var c=o(e),u=c.next();!u.done;u=c.next()){var h=a(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(r=c.return)&&r.call(c)}finally{if(i)throw i.error}}return n(s)},t.matchesState=j,t.raise=we,t.send=ye,t.sendParent=me,t.sendTo=ge,t.sendUpdate=xe,t.spawn=function(t,e){var n=function(t){return Q(t)?i(i({},oe),{name:t}):i(i(i({},oe),{name:W()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):Lt(t,n.name)}(It[It.length-1])},t.spawnBehavior=ie,t.t=pe,t.toActorRef=Vt,t.toEventObject=Y,t.toObserver=it,t.toSCXMLEvent=Z,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/xstate.web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var t,e;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(t||(t={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(e||(e={}));const i=t.Start,n=t.Stop,s=t.Raise,o=t.Send,r=t.Cancel,a=t.NullEvent,c=t.Assign,h=t.After,d=t.DoneState,u=t.Log,l=t.Init,f=t.Invoke,p=t.ErrorExecution,g=t.ErrorPlatform,v=t.ErrorCustom,y=t.Update,m=t.Choose,b=t.Pure;var S=Object.freeze({__proto__:null,start:i,stop:n,raise:s,send:o,cancel:r,nullEvent:a,assign:c,after:h,doneState:d,log:u,init:l,invoke:f,errorExecution:p,errorPlatform:g,error:v,update:y,choose:m,pure:b});const O={};function
|
|
1
|
+
var t,e;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(t||(t={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(e||(e={}));const i=t.Start,n=t.Stop,s=t.Raise,o=t.Send,r=t.Cancel,a=t.NullEvent,c=t.Assign,h=t.After,d=t.DoneState,u=t.Log,l=t.Init,f=t.Invoke,p=t.ErrorExecution,g=t.ErrorPlatform,v=t.ErrorCustom,y=t.Update,m=t.Choose,b=t.Pure;var S=Object.freeze({__proto__:null,start:i,stop:n,raise:s,send:o,cancel:r,nullEvent:a,assign:c,after:h,doneState:d,log:u,init:l,invoke:f,errorExecution:p,errorPlatform:g,error:v,update:y,choose:m,pure:b});const O={};function x(t,e,i="."){const n=j(t,i),s=j(e,i);return z(s)?!!z(n)&&s===n:z(n)?n in s:Object.keys(n).every(t=>t in s&&x(n[t],s[t]))}function _(t){try{return z(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function w(t,e){try{return R(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function j(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(R(t))return E(t);if("string"!=typeof t)return t;return E(w(t,e))}function E(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function k(t,e){const i={},n=Object.keys(t);for(let s=0;s<n.length;s++){const o=n[s];i[o]=e(t[o],o,t,s)}return i}function N(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];i(o)&&(n[s]=e(o,s,t))}return n}const T=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function A(t){if(!t)return[[]];if(z(t))return[[t]];return $(Object.keys(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?A(t[e]).map(t=>[e].concat(t)):[[e]]}))}function $(t){return[].concat(...t)}function I(t){return R(t)?t:[t]}function P(t){return void 0===t?[]:I(t)}function C(t,e,i){if(M(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];M(o)?n[s]=o(e,i.data):n[s]=o}return n}function V(t){return t instanceof Promise||!(null===t||!M(t)&&"object"!=typeof t||!M(t.then))}function L(t,e){return k(t.states,(t,i)=>{if(!t)return;const n=(z(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:L(t,n)}:void 0})}function D(t,e,i,n){return t?i.reduce((t,i)=>{const{assignment:s}=i,o={state:n,action:i,_event:e};let r={};if(M(s))r=s(t,e.data,o);else for(const i of Object.keys(s)){const n=s[i];r[i]=M(n)?n(t,e.data,o):n}return Object.assign({},t,r)},t):t}function R(t){return Array.isArray(t)}function M(t){return"function"==typeof t}function z(t){return"string"==typeof t}function U(t,e){if(t)return z(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:M(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const B=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function F(t){return!!t&&"__xstatenode"in t}const J=(()=>{let t=0;return()=>(t++,t.toString(16))})();function q(t,e){return z(t)||"number"==typeof t?Object.assign({type:t},e):t}function Q(t,e){if(!z(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=q(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function X(t,e){return I(e).map(e=>void 0===e||"string"==typeof e||F(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function H(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=null==o?void 0:o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function G(t){return"string"==typeof t?{type:t}:t}function K(t,e,i){const n=()=>{},s="object"==typeof t,o=s?t:null;return{next:((s?t.next:t)||n).bind(o),error:((s?t.error:e)||n).bind(o),complete:((s?t.complete:i)||n).bind(o)}}function W(t,e){return`${t}:invocation[${e}]`}const Y=Q({type:l});function Z(t,e){return e&&e[t]||void 0}function tt(t,e){let i;if(z(t)||"number"==typeof t){const n=Z(t,e);i=M(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(M(t))i={type:t.name||t.toString(),exec:t};else{const n=Z(t.type,e);if(M(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const et=(t,e)=>{if(!t)return[];return(R(t)?t:[t]).map(t=>tt(t,e))};function it(t){const e=tt(t);return Object.assign(Object.assign({id:z(t)?t:e.id},e),{type:e.type})}function nt(t){return z(t)?{type:s,event:t}:ot(t,{to:e.Internal})}function st(t){return{type:s,_event:Q(t.event)}}function ot(t,e){return{to:e?e.to:void 0,type:o,event:M(t)?t:q(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:M(t)?t.name:_(t)}}function rt(t,e,i,n){const s={_event:i},o=Q(M(t.event)?t.event(e,i.data,s):t.event);let r;if(z(t.delay)){const o=n&&n[t.delay];r=M(o)?o(e,i.data,s):o}else r=M(t.delay)?t.delay(e,i.data,s):t.delay;const a=M(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}function at(t,i){return ot(t,Object.assign(Object.assign({},i),{to:e.Parent}))}const ct=(t,e)=>({context:t,event:e});const ht=(t,e,i)=>Object.assign(Object.assign({},t),{value:z(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),dt=t=>({type:r,sendId:t});function ut(e){const i=it(e);return{type:t.Start,activity:i,exec:void 0}}function lt(e){const i=M(e)?e:it(e);return{type:t.Stop,activity:i,exec:void 0}}function ft(e,i,n){const s=M(e.activity)?e.activity(i,n.data):e.activity,o="string"==typeof s?{id:s}:s;return{type:t.Stop,activity:o}}function pt(e,i){const n=i?"#"+i:"";return`${t.After}(${e})${n}`}function gt(e,i){const n=`${t.DoneState}.${e}`,s={type:n,data:i,toString:()=>n};return s}function vt(e,i){const n=`${t.DoneInvoke}.${e}`,s={type:n,data:i,toString:()=>n};return s}function yt(e,i){const n=`${t.ErrorPlatform}.${e}`,s={type:n,data:i,toString:()=>n};return s}function mt(t,i,r,a,h,d,l=!1){const f=l?[]:(t=>{const e=[];for(const i of t){let t=0;for(;t<i.actions.length;)i.actions[t].type!==c?t++:(e.push(i.actions[t]),i.actions.splice(t,1))}return e})(h);let p=f.length?D(r,a,f,i):r;const g=l?[r]:void 0,v=[];function y(h,f){var y;switch(f.type){case s:return st(f);case o:const S=rt(f,p,a,t.options.delays);return d&&S.to!==e.Internal&&("entry"===h?v.push(S):null==d||d(S,p,a)),S;case u:{const t=ht(f,p,a);return null==d||d(t,p,a),t}case m:{const e=null===(y=f.conds.find(e=>{const n=U(e.cond,t.options.guards);return!n||H(t,n,p,a,d?void 0:i)}))||void 0===y?void 0:y.actions;if(!e)return[];const[n,s]=mt(t,i,p,a,[{type:h,actions:et(P(e),t.options.actions)}],d,l);return p=s,null==g||g.push(p),n}case b:{const e=f.get(p,a.data);if(!e)return[];const[n,s]=mt(t,i,p,a,[{type:h,actions:et(P(e),t.options.actions)}],d,l);return p=s,null==g||g.push(p),n}case n:{const t=ft(f,p,a);return null==d||d(t,r,a),t}case c:p=D(p,a,[f],d?void 0:i),null==g||g.push(p);break;default:let O=tt(f,t.options.actions);const{exec:x}=O;if(d)d(O,p,a);else if(x&&g){const t=g.length-1;O=Object.assign(Object.assign({},O),{exec:(e,...i)=>{x(g[t],...i)}})}return O}}return[$(h.map((function(t){let e=[];for(const i of t.actions){const n=y(t.type,i);n&&(e=e.concat(n))}return v.forEach(t=>{d(t,p,a)}),v.length=0,e}))),p]}var bt=Object.freeze({__proto__:null,actionTypes:S,initEvent:Y,getActionFunction:Z,toActionObject:tt,toActionObjects:et,toActivityDefinition:it,raise:nt,resolveRaise:st,send:ot,resolveSend:rt,sendParent:at,sendTo:function(t,e,i){return ot(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return at(y)},respond:function(t,e){return ot(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=ct,e){return{type:u,label:e,expr:t}},resolveLog:ht,cancel:dt,start:ut,stop:lt,resolveStop:ft,assign:t=>({type:c,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:pt,done:gt,doneInvoke:vt,error:yt,pure:function(e){return{type:t.Pure,get:e}},forwardTo:function(t,e){return ot((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,i){return at((e,i,n)=>({type:v,data:M(t)?t(e,i,n):t}),Object.assign(Object.assign({},i),{to:e.Parent}))},choose:function(e){return{type:t.Choose,conds:e}},resolveActions:mt});const St=[],Ot=(t,e)=>{St.push(t);const i=e(t);return St.pop(),i};function xt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}}}function _t(t,e,i){const n=xt(e);if(n.deferred=!0,F(t)){const e=n.state=Ot(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function wt(t){return Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{},[B]:function(){return this}},t)}
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */function jt(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const Et=t=>"atomic"===t.type||"final"===t.type;function kt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){return kt(t).filter(t=>"history"!==t.type)}function Tt(t){const e=[t];return Et(t)?e:e.concat($(Nt(t).map(Tt)))}function At(t,e){const i=$t(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=$t(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Nt(t))n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t)))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function $t(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function It(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(Et(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,$t(At([t],e)))}function Pt(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Ct(t,e){return"compound"===e.type?Nt(e).some(e=>"final"===e.type&&Pt(t,e)):"parallel"===e.type&&Nt(e).every(e=>Ct(t,e))}function Vt(t){return new Set($(t.map(t=>t.tags)))}function Lt(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Dt{constructor(t){var e;this.actions=[],this.activities=O,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set($([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Dt)return t.context!==e?new Dt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Dt({value:t,context:e,_event:Y,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Dt(t)}static inert(t,e){if(t instanceof Dt){if(!t.actions.length)return t;const i=Y;return new Dt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Dt.from(t,e)}toStrings(t=this.value,e="."){if(z(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=jt(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return _(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const zt=new Map;let Ut=0;const Bt={bookId:()=>"x:"+Ut++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Ft(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Ft())return;const e=function(){const t=Ft();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=wt({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=K(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Qt={sync:!1,autoForward:!1};var Xt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Xt||(Xt={}));class Ht{constructor(s,a=Ht.defaultOptions){this.machine=s,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Xt.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=(t,e)=>{if(R(t))return this.batch(t),this.state;const i=Q(q(t,e));if(this.status===Xt.Stopped)return this.state;if(this.status!==Xt.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this._nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,i,n)=>{const s=this.parent&&(i===e.Parent||this.parent.id===i),o=s?this.parent:z(i)?this.children.get(i)||Bt.get(i):(r=i)&&"function"==typeof r.send?i:void 0;var r;if(o)if("machine"in o){if(this.status!==Xt.Stopped||this.parent!==o||this.state.done){const e=Object.assign(Object.assign({},t),{name:t.name===v?""+yt(this.id):t.name,origin:this.sessionId});!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,e]):o.send(e)}}else!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,t.data]):o.send(t.data);else if(!s)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)},this._exec=(e,s,a,c=this.machine.options.actions)=>{const h=e.exec||Z(e.type,c),d=M(h)?h:h?h.exec:e.exec;if(d)try{return d(s,a.data,this.machine.config.predictableActionArguments?{action:e,_event:a}:{action:e,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to,a===Y):this.send(c._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Xt.Running)return;const i=e.activity;if(!this.machine.config.predictableActionArguments&&!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=G(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:o}=i,r="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const c=o?C(o,s,a):void 0;if("string"==typeof e)return;let h,d=M(e)?e(s,a.data,{data:c,src:t,meta:i.meta}):e;if(!d)return;F(d)&&(d=c?d.withContext(c):d,h={autoForward:r}),this.spawn(d,n,h)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case u:const{label:h,value:d}=e;h?this.logger(h,d):this.logger(d)}};const c=Object.assign(Object.assign({},Ht.defaultOptions),a),{clock:h,logger:d,parent:l,id:f}=c,p=void 0!==f?f:s.id;this.id=p,this.logger=d,this.clock=h,this.parent=l,this.options=c,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Ot(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==Y||!this.options.execute){let t;for(;t=this._outgoingQueue.shift();)t[0].send(t[1])}else this.execute(this.state);if(this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);if(this.state.done){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?C(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(vt(this.id,n));this._stop(),this._stopChildren()}}onTransition(t){return this.listeners.add(t),this.status===Xt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){const n=K(t,e,i);this.listeners.add(n.next),this.status!==Xt.NotStarted&&n.next(this.state);const s=()=>{this.doneListeners.delete(s),this.stopListeners.delete(s),n.complete()};return this.status===Xt.Stopped?n.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:()=>{this.listeners.delete(n.next),this.doneListeners.delete(s),this.stopListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Xt.Running)return this;this.machine._init(),Bt.register(this.sessionId,this),this.initialized=!0,this.status=Xt.Running;const e=void 0===t?this.initialState:Ot(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Dt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Y)}),this}_stopChildren(){this.children.forEach(t=>{M(t.stop)&&t.stop()}),this.children.clear()}_stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.initialized=!1,this.status=Xt.Stopped,this._initialState=void 0;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);this.scheduler.clear(),this.scheduler=new Mt({deferEvents:this.options.deferEvents})}stop(){const t=this.scheduler;return this._stop(),t.schedule(()=>{const t=Q({type:"xstate.stop"}),i=Ot(this,()=>{const i=$([...this.state.configuration].sort((t,e)=>e.order-t.order).map(t=>et(t.onExit,this.machine.options.actions))),[n,r]=mt(this.machine,this.state,this.state.context,t,[i],this.machine.config.predictableActionArguments?this._exec:void 0,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),a=new Dt({value:this.state.value,context:r,_event:t,_sessionid:this.sessionId,historyValue:void 0,history:this.state,actions:n.filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal)),activities:{},events:[],configuration:[],transitions:[],children:{},done:this.state.done,tags:this.state.tags,machine:this.machine});return a.changed=!0,a});this.update(i,t),this._stopChildren(),Bt.free(this.sessionId)}),this}batch(t){if(this.status===Xt.NotStarted&&this.options.deferEvents);else if(this.status!==Xt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);if(!t.length)return;const e=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(()=>{let i=this.state,n=!1;const s=[];for(const o of t){const t=Q(o);this.forward(t),i=Ot(this,()=>this.machine.transition(i,t,void 0,e||void 0)),s.push(...this.machine.config.predictableActionArguments?i.actions:i.actions.map(t=>Lt(t,i))),n=n||!!i.changed}i.changed=n,i.actions=s,this.update(i,Q(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}_nextState(t,e=!!this.machine.config.predictableActionArguments&&this._exec){const i=Q(t);if(0===i.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw i.data.data;return Ot(this,()=>this.machine.transition(this.state,i,void 0,e||void 0))}nextState(t){return this._nextState(t,!1)}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to,!0):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){this._exec(t,e.context,e._event,i)}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),M(e.stop)&&e.stop())}spawn(t,e,i){if(this.status!==Xt.Running)return xt(t,e);if(V(t))return this.spawnPromise(Promise.resolve(t),e);if(M(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&M(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(F(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Ht(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Qt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(Q(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(Q(vt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=yt(e,t);try{this.send(Q(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=K(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(Q(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(yt(e,t))}if(V(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=K(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,M(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(Q(t,{origin:e}))},t=>{this.removeChild(e),this.send(Q(yt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(Q(vt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Ft();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Jt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Xt.NotStarted?this.initialState:this._state}}Ht.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1},Ht.interpret=Kt;function Gt(t,e){const i=(t=>z(t)?Object.assign(Object.assign({},Qt),{name:t}):Object.assign(Object.assign(Object.assign({},Qt),{name:J()}),t))(e);return(e=>e?e.spawn(t,i.name,i):xt(t,i.name))(St[St.length-1])}function Kt(t,e){return new Ht(t,e)}function Wt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Yt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=jt(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Wt(t.src)})}})}const Zt={},te=t=>"#"===t[0];class ee{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ee(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Zt;let o=0;!function t(e){e.order=o++;for(const i of kt(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=P(this.config.entry||this.config.onEntry).map(t=>tt(t)),this.onExit=P(this.config.exit||this.config.onExit).map(t=>tt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=P(this.config.invoke).map((t,e)=>{if(F(t)){const i=W(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(z(t.src)){const i=t.id||W(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(F(t.src)||M(t.src)){const i=t.id||W(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Yt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Yt(Object.assign(Object.assign({id:W(this.id,e)},t),{src:i}))}}),this.activities=P(this.config.activities).concat(this.invoke).map(t=>it(t)),this.transition=this.transition.bind(this),this.tags=P(this.config.tags)}_init(){this.__cache.transitions||Tt(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ee(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ee(this.config,this.options,t)}get context(){return M(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:k(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=pt(M(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ot(i,{delay:t})),this.onExit.push(dt(i)),i};return(R(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):$(Object.keys(t).map((i,n)=>{const s=t[i],o=z(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return P(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const e=t instanceof Dt?t.value:j(t,this.delimiter);if(z(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...$(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=x(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from(At([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Ct(i,this),tags:Vt(i),machine:this.machine}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=$(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=$(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,exitSet:$(s.map(t=>t.exitSet)),configuration:r,source:e,actions:$(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return z(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,Q(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,d=!c||(z(c)&&te(c)?t.matches(j(this.getStateNodeById(c).path,this.delimiter)):_(j(c,this.delimiter),T(this.path.slice(0,-2))(t.value)));let u=!1;try{u=!a||H(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(u&&d){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=$(o.map(e=>this.getRelativeStateNodes(e,t.historyValue)));return{transitions:[s],exitSet:!!s.internal?[]:$(o.map(t=>this.getPotentiallyReenteringNodes(t))),configuration:r,source:t,actions:n}}getPotentiallyReenteringNodes(t){if(this.order<t.order)return[this];const e=[];let i=this,n=t;for(;i&&i!==n;)e.push(i),i=i.parent;return i!==n?[]:(e.push(n),e)}getActions(t,i,n,r,a,c,h){const d=c?At([],this.getStateNodes(c.value)):[],u=new Set;for(const e of Array.from(t).sort((t,e)=>t.order-e.order))(!Pt(d,e)||Pt(n.exitSet,e)||e.parent&&u.has(e.parent))&&u.add(e);for(const e of d)Pt(t,e)&&!Pt(n.exitSet,e.parent)||n.exitSet.push(e);n.exitSet.sort((t,e)=>e.order-t.order);const l=Array.from(u).sort((t,e)=>t.order-e.order),f=new Set(n.exitSet),p=$(l.map(t=>{const e=[];if("final"!==t.type)return e;const i=t.parent;if(!i.parent)return e;e.push(gt(t.id,t.doneData),gt(i.id,t.doneData?C(t.doneData,r,a):void 0));const s=i.parent;return"parallel"===s.type&&Nt(s).every(t=>Ct(n.configuration,t))&&e.push(gt(s.id)),e})),g=l.map(t=>{const e=t.onEntry,i=t.activities.map(t=>ut(t));return et(h?[...e,...i]:[...i,...e],this.machine.options.actions)}).concat([p.map(nt)]),v=Array.from(f).map(t=>et([...t.onExit,...t.activities.map(t=>lt(t))],this.machine.options.actions)).concat([et(n.actions,this.machine.options.actions)]).concat(g);if(i){const i=et($([...t].sort((t,e)=>e.order-t.order).map(t=>t.onExit)),this.machine.options.actions).filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal));return v.concat([i])}return v}transition(t=this.initialState,e,i,n){const s=Q(e);let o;if(t instanceof Dt)o=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=z(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;o=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(s.name)&&(r=s.name,!/^(done|error)\./.test(r)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var r;const a=this._transition(o.value,o,s)||{transitions:[],configuration:[],exitSet:[],source:o,actions:[]},c=At([],this.getStateNodes(o.value)),h=a.configuration.length?At(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,o,o.context,n,s)}resolveRaisedTransition(t,e,i,n){const s=t.actions;return(t=this.transition(t,e,void 0,n))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,r,c,h,d=Y){const{configuration:u}=t,l=!r||t.transitions.length>0,p=l?t.configuration:r?r.configuration:[],g=Ct(p,this),v=l?It(this.machine,u):void 0,m=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,b=this.getActions(new Set(p),g,t,c,d,r,h),S=r?Object.assign({},r.activities):{};for(const t of b)for(const e of t)e.type===i?S[e.activity.id||e.activity.type]=e:e.type===n&&(S[e.activity.id||e.activity.type]=!1);const[O,_]=mt(this,r,c,d,b,h,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),[x,w]=function(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}(O,t=>t.type===s||t.type===o&&t.to===e.Internal),j=O.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=G(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?C(t.data,i,n):void 0,c=r?xt(r,t.id,a):_t(t.id);return c.meta=t,c}(e.activity,this.machine,_,d),t),r?Object.assign({},r.children):{}),E=new Dt({value:v||r.value,context:_,_event:d,_sessionid:r?r._sessionid:null,historyValue:v?m?(k=m,N=v,{current:N,states:L(k,N)}):void 0:r?r.historyValue:void 0,history:!v||t.source?r:void 0,actions:v?w:[],activities:v?S:r?r.activities:{},events:[],configuration:p,transitions:t.transitions,children:j,done:g,tags:Vt(p),machine:this});var k,N;const T=c!==_;E.changed=d.name===y||T;const{history:A}=E;A&&delete A.history;const $=!g&&(this._transient||u.some(t=>t._transient));if(!(l||$&&""!==d.name))return E;let I=E;if(!g)for($&&(I=this.resolveRaisedTransition(I,{type:a},d,h));x.length;){const t=x.shift();I=this.resolveRaisedTransition(I,t._event,d,h)}const P=I.changed||(A?!!I.actions.length||T||typeof A.value!=typeof I.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(z(e)||z(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(I.value,A.value):void 0);return I.changed=P,I.history=A,I}getStateNode(t){if(te(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=te(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&te(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=w(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Zt;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Zt);case"compound":if(z(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):Zt):this.initialStateValue||{};default:return t||Zt}}getResolvedPath(t){if(te(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return w(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=N(this.states,t=>t.initialStateValue||Zt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=Et(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=z(e.target)&&te(e.target)?E(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(Et(this))return[this];if("compound"===this.type&&!this.initial)return[this];return $(A(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:N(this.states,(e,i)=>{if(!t)return e.historyValue();const n=z(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?$(A(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return z(i)?[e.getStateNode(i)]:$(A(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=$(Object.keys(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const n=t[i];if(n.states)for(const t of n.events)e.add(""+t)}return this.__cache.events=Array.from(e)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!z(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return P(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>z(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:et(P(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=jt(e,[i+""]);t=$(Object.keys(o).map(t=>X(t,o[t])).concat(X("*",s)))}else t=[];const e=this.config.always?X("",this.config.always):[],i=this.config.onDone?X(String(gt(this.id)),this.config.onDone):[],n=$(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...X(String(vt(t.id)),t.onDone)),t.onError&&e.push(...X(String(yt(t.id)),t.onError)),e})),s=this.after,o=$([...i,...n,...t,...e].map(t=>P(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ie(t,e,i=t.context){return new ee(t,e,i)}function ne(t,e){return new ee(t,e)}function se(t,e){let i;for(const n of Object.keys(t))_(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function oe(t,e,i){const n=Dt.from(t,t instanceof Dt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function re(t){return t}const ae=re,{assign:ce,send:he,sendTo:de,sendParent:ue,sendUpdate:le,forwardTo:fe,doneInvoke:pe,raise:ge}=bt;export{t as ActionTypes,Ht as Interpreter,Xt as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,bt as actions,ce as assign,ne as createMachine,re as createSchema,pe as doneInvoke,fe as forwardTo,Kt as interpret,se as mapState,oe as matchState,_ as matchesState,ge as raise,he as send,ue as sendParent,de as sendTo,le as sendUpdate,Gt as spawn,qt as spawnBehavior,ae as t,wt as toActorRef,q as toEventObject,K as toObserver,Q as toSCXMLEvent};
|
|
15
|
+
***************************************************************************** */function jt(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const Et=t=>"atomic"===t.type||"final"===t.type;function kt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){return kt(t).filter(t=>"history"!==t.type)}function Tt(t){const e=[t];return Et(t)?e:e.concat($(Nt(t).map(Tt)))}function At(t,e){const i=$t(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=$t(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Nt(t))n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t)))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function $t(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function It(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(Et(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,$t(At([t],e)))}function Pt(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Ct(t,e){return"compound"===e.type?Nt(e).some(e=>"final"===e.type&&Pt(t,e)):"parallel"===e.type&&Nt(e).every(e=>Ct(t,e))}function Vt(t){return new Set($(t.map(t=>t.tags)))}function Lt(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Dt{constructor(t){var e;this.actions=[],this.activities=O,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set($([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Dt)return t.context!==e?new Dt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Dt({value:t,context:e,_event:Y,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Dt(t)}static inert(t,e){if(t instanceof Dt){if(!t.actions.length)return t;const i=Y;return new Dt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Dt.from(t,e)}toStrings(t=this.value,e="."){if(z(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=jt(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return x(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const zt=new Map;let Ut=0;const Bt={bookId:()=>"x:"+Ut++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Ft(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Ft())return;const e=function(){const t=Ft();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=wt({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=K(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Qt={sync:!1,autoForward:!1};var Xt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Xt||(Xt={}));class Ht{constructor(s,a=Ht.defaultOptions){this.machine=s,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Xt.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=(t,e)=>{if(R(t))return this.batch(t),this.state;const i=Q(q(t,e));if(this.status===Xt.Stopped)return this.state;if(this.status!==Xt.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this._nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,i,n)=>{const s=this.parent&&(i===e.Parent||this.parent.id===i),o=s?this.parent:z(i)?this.children.get(i)||Bt.get(i):(r=i)&&"function"==typeof r.send?i:void 0;var r;if(o)if("machine"in o){if(this.status!==Xt.Stopped||this.parent!==o||this.state.done){const e=Object.assign(Object.assign({},t),{name:t.name===v?""+yt(this.id):t.name,origin:this.sessionId});!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,e]):o.send(e)}}else!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,t.data]):o.send(t.data);else if(!s)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)},this._exec=(e,s,a,c=this.machine.options.actions)=>{const h=e.exec||Z(e.type,c),d=M(h)?h:h?h.exec:e.exec;if(d)try{return d(s,a.data,this.machine.config.predictableActionArguments?{action:e,_event:a}:{action:e,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to,a===Y):this.send(c._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Xt.Running)return;const i=e.activity;if(!this.machine.config.predictableActionArguments&&!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=G(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:o}=i,r="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const c=o?C(o,s,a):void 0;if("string"==typeof e)return;let h,d=M(e)?e(s,a.data,{data:c,src:t,meta:i.meta}):e;if(!d)return;F(d)&&(d=c?d.withContext(c):d,h={autoForward:r}),this.spawn(d,n,h)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case u:const{label:h,value:d}=e;h?this.logger(h,d):this.logger(d)}};const c=Object.assign(Object.assign({},Ht.defaultOptions),a),{clock:h,logger:d,parent:l,id:f}=c,p=void 0!==f?f:s.id;this.id=p,this.logger=d,this.clock=h,this.parent=l,this.options=c,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Ot(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==Y||!this.options.execute){let t;for(;t=this._outgoingQueue.shift();)t[0].send(t[1])}else this.execute(this.state);if(this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);if(this.state.done){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?C(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(vt(this.id,n));this._stop(),this._stopChildren()}}onTransition(t){return this.listeners.add(t),this.status===Xt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){const n=K(t,e,i);this.listeners.add(n.next),this.status!==Xt.NotStarted&&n.next(this.state);const s=()=>{this.doneListeners.delete(s),this.stopListeners.delete(s),n.complete()};return this.status===Xt.Stopped?n.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:()=>{this.listeners.delete(n.next),this.doneListeners.delete(s),this.stopListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Xt.Running)return this;this.machine._init(),Bt.register(this.sessionId,this),this.initialized=!0,this.status=Xt.Running;const e=void 0===t?this.initialState:Ot(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Dt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Y)}),this}_stopChildren(){this.children.forEach(t=>{M(t.stop)&&t.stop()}),this.children.clear()}_stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.initialized=!1,this.status=Xt.Stopped,this._initialState=void 0;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);this.scheduler.clear(),this.scheduler=new Mt({deferEvents:this.options.deferEvents})}stop(){const t=this.scheduler;return this._stop(),t.schedule(()=>{const t=Q({type:"xstate.stop"}),i=Ot(this,()=>{const i=$([...this.state.configuration].sort((t,e)=>e.order-t.order).map(t=>et(t.onExit,this.machine.options.actions))),[n,r]=mt(this.machine,this.state,this.state.context,t,[{type:"exit",actions:i}],this.machine.config.predictableActionArguments?this._exec:void 0,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),a=new Dt({value:this.state.value,context:r,_event:t,_sessionid:this.sessionId,historyValue:void 0,history:this.state,actions:n.filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal)),activities:{},events:[],configuration:[],transitions:[],children:{},done:this.state.done,tags:this.state.tags,machine:this.machine});return a.changed=!0,a});this.update(i,t),this._stopChildren(),Bt.free(this.sessionId)}),this}batch(t){if(this.status===Xt.NotStarted&&this.options.deferEvents);else if(this.status!==Xt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);if(!t.length)return;const e=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(()=>{let i=this.state,n=!1;const s=[];for(const o of t){const t=Q(o);this.forward(t),i=Ot(this,()=>this.machine.transition(i,t,void 0,e||void 0)),s.push(...this.machine.config.predictableActionArguments?i.actions:i.actions.map(t=>Lt(t,i))),n=n||!!i.changed}i.changed=n,i.actions=s,this.update(i,Q(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}_nextState(t,e=!!this.machine.config.predictableActionArguments&&this._exec){const i=Q(t);if(0===i.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw i.data.data;return Ot(this,()=>this.machine.transition(this.state,i,void 0,e||void 0))}nextState(t){return this._nextState(t,!1)}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to,!0):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){this._exec(t,e.context,e._event,i)}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),M(e.stop)&&e.stop())}spawn(t,e,i){if(this.status!==Xt.Running)return _t(t,e);if(V(t))return this.spawnPromise(Promise.resolve(t),e);if(M(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&M(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(F(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Ht(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Qt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(Q(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(Q(vt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=yt(e,t);try{this.send(Q(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=K(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(Q(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(yt(e,t))}if(V(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=K(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,M(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(Q(t,{origin:e}))},t=>{this.removeChild(e),this.send(Q(yt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(Q(vt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Ft();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Jt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Xt.NotStarted?this.initialState:this._state}}Ht.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1},Ht.interpret=Kt;function Gt(t,e){const i=(t=>z(t)?Object.assign(Object.assign({},Qt),{name:t}):Object.assign(Object.assign(Object.assign({},Qt),{name:J()}),t))(e);return(e=>e?e.spawn(t,i.name,i):_t(t,i.name))(St[St.length-1])}function Kt(t,e){return new Ht(t,e)}function Wt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Yt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=jt(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Wt(t.src)})}})}const Zt={},te=t=>"#"===t[0];class ee{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ee(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Zt;let o=0;!function t(e){e.order=o++;for(const i of kt(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=P(this.config.entry||this.config.onEntry).map(t=>tt(t)),this.onExit=P(this.config.exit||this.config.onExit).map(t=>tt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=P(this.config.invoke).map((t,e)=>{if(F(t)){const i=W(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(z(t.src)){const i=t.id||W(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(F(t.src)||M(t.src)){const i=t.id||W(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Yt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Yt(Object.assign(Object.assign({id:W(this.id,e)},t),{src:i}))}}),this.activities=P(this.config.activities).concat(this.invoke).map(t=>it(t)),this.transition=this.transition.bind(this),this.tags=P(this.config.tags)}_init(){this.__cache.transitions||Tt(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ee(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ee(this.config,this.options,t)}get context(){return M(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:k(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=pt(M(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ot(i,{delay:t})),this.onExit.push(dt(i)),i};return(R(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):$(Object.keys(t).map((i,n)=>{const s=t[i],o=z(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return P(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const e=t instanceof Dt?t.value:j(t,this.delimiter);if(z(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...$(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=_(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from(At([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Ct(i,this),tags:Vt(i),machine:this.machine}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=$(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=$(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,exitSet:$(s.map(t=>t.exitSet)),configuration:r,source:e,actions:$(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return z(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,Q(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,d=!c||(z(c)&&te(c)?t.matches(j(this.getStateNodeById(c).path,this.delimiter)):x(j(c,this.delimiter),T(this.path.slice(0,-2))(t.value)));let u=!1;try{u=!a||H(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(u&&d){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=$(o.map(e=>this.getRelativeStateNodes(e,t.historyValue)));return{transitions:[s],exitSet:!!s.internal?[]:$(o.map(t=>this.getPotentiallyReenteringNodes(t))),configuration:r,source:t,actions:n}}getPotentiallyReenteringNodes(t){if(this.order<t.order)return[this];const e=[];let i=this,n=t;for(;i&&i!==n;)e.push(i),i=i.parent;return i!==n?[]:(e.push(n),e)}getActions(t,i,n,r,a,c,h){const d=c?At([],this.getStateNodes(c.value)):[],u=new Set;for(const e of Array.from(t).sort((t,e)=>t.order-e.order))(!Pt(d,e)||Pt(n.exitSet,e)||e.parent&&u.has(e.parent))&&u.add(e);for(const e of d)Pt(t,e)&&!Pt(n.exitSet,e.parent)||n.exitSet.push(e);n.exitSet.sort((t,e)=>e.order-t.order);const l=Array.from(u).sort((t,e)=>t.order-e.order),f=new Set(n.exitSet),p=$(l.map(t=>{const e=[];if("final"!==t.type)return e;const i=t.parent;if(!i.parent)return e;e.push(gt(t.id,t.doneData),gt(i.id,t.doneData?C(t.doneData,r,a):void 0));const s=i.parent;return"parallel"===s.type&&Nt(s).every(t=>Ct(n.configuration,t))&&e.push(gt(s.id)),e})),g=l.map(t=>{const e=t.onEntry,i=t.activities.map(t=>ut(t));return{type:"entry",actions:et(h?[...e,...i]:[...i,...e],this.machine.options.actions)}}).concat({type:"state_done",actions:p.map(nt)}),v=Array.from(f).map(t=>({type:"exit",actions:et([...t.onExit,...t.activities.map(t=>lt(t))],this.machine.options.actions)})).concat({type:"transition",actions:et(n.actions,this.machine.options.actions)}).concat(g);if(i){const i=et($([...t].sort((t,e)=>e.order-t.order).map(t=>t.onExit)),this.machine.options.actions).filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal));return v.concat({type:"stop",actions:i})}return v}transition(t=this.initialState,e,i,n){const s=Q(e);let o;if(t instanceof Dt)o=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=z(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;o=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(s.name)&&(r=s.name,!/^(done|error)\./.test(r)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var r;const a=this._transition(o.value,o,s)||{transitions:[],configuration:[],exitSet:[],source:o,actions:[]},c=At([],this.getStateNodes(o.value)),h=a.configuration.length?At(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,o,o.context,n,s)}resolveRaisedTransition(t,e,i,n){const s=t.actions;return(t=this.transition(t,e,void 0,n))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,r,c,h,d=Y){const{configuration:u}=t,l=!r||t.transitions.length>0,p=l?t.configuration:r?r.configuration:[],g=Ct(p,this),v=l?It(this.machine,u):void 0,m=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,b=this.getActions(new Set(p),g,t,c,d,r,h),S=r?Object.assign({},r.activities):{};for(const t of b)for(const e of t.actions)e.type===i?S[e.activity.id||e.activity.type]=e:e.type===n&&(S[e.activity.id||e.activity.type]=!1);const[O,x]=mt(this,r,c,d,b,h,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),[_,w]=function(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}(O,t=>t.type===s||t.type===o&&t.to===e.Internal),j=O.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=G(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?C(t.data,i,n):void 0,c=r?_t(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,x,d),t),r?Object.assign({},r.children):{}),E=new Dt({value:v||r.value,context:x,_event:d,_sessionid:r?r._sessionid:null,historyValue:v?m?(k=m,N=v,{current:N,states:L(k,N)}):void 0:r?r.historyValue:void 0,history:!v||t.source?r:void 0,actions:v?w:[],activities:v?S:r?r.activities:{},events:[],configuration:p,transitions:t.transitions,children:j,done:g,tags:Vt(p),machine:this});var k,N;const T=c!==x;E.changed=d.name===y||T;const{history:A}=E;A&&delete A.history;const $=!g&&(this._transient||u.some(t=>t._transient));if(!(l||$&&""!==d.name))return E;let I=E;if(!g)for($&&(I=this.resolveRaisedTransition(I,{type:a},d,h));_.length;){const t=_.shift();I=this.resolveRaisedTransition(I,t._event,d,h)}const P=I.changed||(A?!!I.actions.length||T||typeof A.value!=typeof I.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(z(e)||z(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(I.value,A.value):void 0);return I.changed=P,I.history=A,I}getStateNode(t){if(te(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=te(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&te(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=w(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Zt;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Zt);case"compound":if(z(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):Zt):this.initialStateValue||{};default:return t||Zt}}getResolvedPath(t){if(te(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return w(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=N(this.states,t=>t.initialStateValue||Zt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=Et(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=z(e.target)&&te(e.target)?E(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(Et(this))return[this];if("compound"===this.type&&!this.initial)return[this];return $(A(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:N(this.states,(e,i)=>{if(!t)return e.historyValue();const n=z(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?$(A(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return z(i)?[e.getStateNode(i)]:$(A(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=$(Object.keys(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const n=t[i];if(n.states)for(const t of n.events)e.add(""+t)}return this.__cache.events=Array.from(e)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!z(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return P(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>z(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:et(P(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=jt(e,[i+""]);t=$(Object.keys(o).map(t=>X(t,o[t])).concat(X("*",s)))}else t=[];const e=this.config.always?X("",this.config.always):[],i=this.config.onDone?X(String(gt(this.id)),this.config.onDone):[],n=$(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...X(String(vt(t.id)),t.onDone)),t.onError&&e.push(...X(String(yt(t.id)),t.onError)),e})),s=this.after,o=$([...i,...n,...t,...e].map(t=>P(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ie(t,e,i=t.context){return new ee(t,e,i)}function ne(t,e){return new ee(t,e)}function se(t,e){let i;for(const n of Object.keys(t))x(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function oe(t,e,i){const n=Dt.from(t,t instanceof Dt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function re(t){return t}const ae=re,{assign:ce,send:he,sendTo:de,sendParent:ue,sendUpdate:le,forwardTo:fe,doneInvoke:pe,raise:ge}=bt;export{t as ActionTypes,Ht as Interpreter,Xt as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,bt as actions,ce as assign,ne as createMachine,re as createSchema,pe as doneInvoke,fe as forwardTo,Kt as interpret,se as mapState,oe as matchState,x as matchesState,ge as raise,he as send,ue as sendParent,de as sendTo,le as sendUpdate,Gt as spawn,qt as spawnBehavior,ae as t,wt as toActorRef,q as toEventObject,K as toObserver,Q as toSCXMLEvent};
|
package/es/StateNode.js
CHANGED
|
@@ -749,14 +749,26 @@ function () {
|
|
|
749
749
|
var invokeActions = stateNode.activities.map(function (activity) {
|
|
750
750
|
return start(activity);
|
|
751
751
|
});
|
|
752
|
-
return
|
|
753
|
-
|
|
752
|
+
return {
|
|
753
|
+
type: 'entry',
|
|
754
|
+
actions: toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions)
|
|
755
|
+
};
|
|
756
|
+
}).concat({
|
|
757
|
+
type: 'state_done',
|
|
758
|
+
actions: doneEvents.map(raise)
|
|
759
|
+
});
|
|
754
760
|
var exitActions = Array.from(exitStates).map(function (stateNode) {
|
|
755
|
-
return
|
|
756
|
-
|
|
757
|
-
|
|
761
|
+
return {
|
|
762
|
+
type: 'exit',
|
|
763
|
+
actions: toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
|
|
764
|
+
return stop(activity);
|
|
765
|
+
})), false), _this.machine.options.actions)
|
|
766
|
+
};
|
|
758
767
|
});
|
|
759
|
-
var actions = exitActions.concat(
|
|
768
|
+
var actions = exitActions.concat({
|
|
769
|
+
type: 'transition',
|
|
770
|
+
actions: toActionObjects(transition.actions, this.machine.options.actions)
|
|
771
|
+
}).concat(entryActions);
|
|
760
772
|
|
|
761
773
|
if (isDone) {
|
|
762
774
|
var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
|
|
@@ -766,7 +778,10 @@ function () {
|
|
|
766
778
|
})), this.machine.options.actions).filter(function (action) {
|
|
767
779
|
return action.type !== raise$1 && (action.type !== send || !!action.to && action.to !== SpecialTargets.Internal);
|
|
768
780
|
});
|
|
769
|
-
return actions.concat(
|
|
781
|
+
return actions.concat({
|
|
782
|
+
type: 'stop',
|
|
783
|
+
actions: stopActions
|
|
784
|
+
});
|
|
770
785
|
}
|
|
771
786
|
|
|
772
787
|
return actions;
|
|
@@ -861,8 +876,8 @@ function () {
|
|
|
861
876
|
var block = actionBlocks_1_1.value;
|
|
862
877
|
|
|
863
878
|
try {
|
|
864
|
-
for (var
|
|
865
|
-
var action =
|
|
879
|
+
for (var _c = (e_7 = void 0, __values(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
880
|
+
var action = _d.value;
|
|
866
881
|
|
|
867
882
|
if (action.type === start$1) {
|
|
868
883
|
activities[action.activity.id || action.activity.type] = action;
|
|
@@ -876,7 +891,7 @@ function () {
|
|
|
876
891
|
};
|
|
877
892
|
} finally {
|
|
878
893
|
try {
|
|
879
|
-
if (
|
|
894
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
880
895
|
} finally {
|
|
881
896
|
if (e_7) throw e_7.error;
|
|
882
897
|
}
|
|
@@ -894,15 +909,15 @@ function () {
|
|
|
894
909
|
}
|
|
895
910
|
}
|
|
896
911
|
|
|
897
|
-
var
|
|
898
|
-
resolvedActions =
|
|
899
|
-
updatedContext =
|
|
912
|
+
var _e = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
|
|
913
|
+
resolvedActions = _e[0],
|
|
914
|
+
updatedContext = _e[1];
|
|
900
915
|
|
|
901
|
-
var
|
|
916
|
+
var _f = __read(partition(resolvedActions, function (action) {
|
|
902
917
|
return action.type === raise$1 || action.type === send && action.to === SpecialTargets.Internal;
|
|
903
918
|
}), 2),
|
|
904
|
-
raisedEvents =
|
|
905
|
-
nonRaisedActions =
|
|
919
|
+
raisedEvents = _f[0],
|
|
920
|
+
nonRaisedActions = _f[1];
|
|
906
921
|
|
|
907
922
|
var invokeActions = resolvedActions.filter(function (action) {
|
|
908
923
|
var _a;
|
package/es/actions.d.ts
CHANGED
|
@@ -150,5 +150,8 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
150
150
|
*/
|
|
151
151
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
152
152
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
153
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<
|
|
153
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<{
|
|
154
|
+
type: string;
|
|
155
|
+
actions: Array<ActionObject<TContext, TEvent>>;
|
|
156
|
+
}>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
154
157
|
//# sourceMappingURL=actions.d.ts.map
|
package/es/actions.js
CHANGED
|
@@ -437,10 +437,10 @@ var pluckAssigns = function (actionBlocks) {
|
|
|
437
437
|
var block = actionBlocks_1_1.value;
|
|
438
438
|
var i = 0;
|
|
439
439
|
|
|
440
|
-
while (i < block.length) {
|
|
441
|
-
if (block[i].type === assign$1) {
|
|
442
|
-
assignActions.push(block[i]);
|
|
443
|
-
block.splice(i, 1);
|
|
440
|
+
while (i < block.actions.length) {
|
|
441
|
+
if (block.actions[i].type === assign$1) {
|
|
442
|
+
assignActions.push(block.actions[i]);
|
|
443
|
+
block.actions.splice(i, 1);
|
|
444
444
|
continue;
|
|
445
445
|
}
|
|
446
446
|
|
|
@@ -472,7 +472,7 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
472
472
|
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
|
|
473
473
|
var deferredToBlockEnd = [];
|
|
474
474
|
|
|
475
|
-
function handleAction(actionObject) {
|
|
475
|
+
function handleAction(blockType, actionObject) {
|
|
476
476
|
var _a;
|
|
477
477
|
|
|
478
478
|
switch (actionObject.type) {
|
|
@@ -491,7 +491,11 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
|
|
494
|
-
|
|
494
|
+
if (blockType === 'entry') {
|
|
495
|
+
deferredToBlockEnd.push(sendAction);
|
|
496
|
+
} else {
|
|
497
|
+
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
|
|
498
|
+
}
|
|
495
499
|
}
|
|
496
500
|
|
|
497
501
|
return sendAction;
|
|
@@ -515,7 +519,10 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
515
519
|
return [];
|
|
516
520
|
}
|
|
517
521
|
|
|
518
|
-
var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [
|
|
522
|
+
var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [{
|
|
523
|
+
type: blockType,
|
|
524
|
+
actions: toActionObjects(toArray(matchedActions), machine.options.actions)
|
|
525
|
+
}], predictableExec, preserveActionOrder), 2),
|
|
519
526
|
resolvedActionsFromChoose = _b[0],
|
|
520
527
|
resolvedContextFromChoose = _b[1];
|
|
521
528
|
|
|
@@ -532,7 +539,10 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
532
539
|
return [];
|
|
533
540
|
}
|
|
534
541
|
|
|
535
|
-
var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [
|
|
542
|
+
var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [{
|
|
543
|
+
type: blockType,
|
|
544
|
+
actions: toActionObjects(toArray(matchedActions), machine.options.actions)
|
|
545
|
+
}], predictableExec, preserveActionOrder), 2),
|
|
536
546
|
resolvedActionsFromPure = _c[0],
|
|
537
547
|
resolvedContext = _c[1];
|
|
538
548
|
|
|
@@ -586,9 +596,9 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
586
596
|
var resolvedActions = [];
|
|
587
597
|
|
|
588
598
|
try {
|
|
589
|
-
for (var
|
|
590
|
-
var action =
|
|
591
|
-
var resolved = handleAction(action);
|
|
599
|
+
for (var _b = __values(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
600
|
+
var action = _c.value;
|
|
601
|
+
var resolved = handleAction(block.type, action);
|
|
592
602
|
|
|
593
603
|
if (resolved) {
|
|
594
604
|
resolvedActions = resolvedActions.concat(resolved);
|
|
@@ -600,7 +610,7 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
600
610
|
};
|
|
601
611
|
} finally {
|
|
602
612
|
try {
|
|
603
|
-
if (
|
|
613
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
604
614
|
} finally {
|
|
605
615
|
if (e_2) throw e_2.error;
|
|
606
616
|
}
|
package/es/interpreter.js
CHANGED
|
@@ -801,7 +801,10 @@ function () {
|
|
|
801
801
|
return toActionObjects(stateNode.onExit, _this.machine.options.actions);
|
|
802
802
|
}));
|
|
803
803
|
|
|
804
|
-
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [
|
|
804
|
+
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [{
|
|
805
|
+
type: 'exit',
|
|
806
|
+
actions: exitActions
|
|
807
|
+
}], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
|
|
805
808
|
resolvedActions = _a[0],
|
|
806
809
|
updatedContext = _a[1];
|
|
807
810
|
|
package/es/types.d.ts
CHANGED
|
@@ -285,11 +285,11 @@ export interface InvokeConfig<TContext, TEvent extends EventObject> {
|
|
|
285
285
|
/**
|
|
286
286
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
287
287
|
*/
|
|
288
|
-
onDone?: string | SingleOrArray<
|
|
288
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
|
|
289
289
|
/**
|
|
290
290
|
* The transition to take upon the invoked child machine sending an error event.
|
|
291
291
|
*/
|
|
292
|
-
onError?: string | SingleOrArray<
|
|
292
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
|
|
293
293
|
/**
|
|
294
294
|
* Meta data related to this invocation
|
|
295
295
|
*/
|
package/lib/StateNode.js
CHANGED
|
@@ -753,14 +753,26 @@ function () {
|
|
|
753
753
|
var invokeActions = stateNode.activities.map(function (activity) {
|
|
754
754
|
return actions.start(activity);
|
|
755
755
|
});
|
|
756
|
-
return
|
|
757
|
-
|
|
756
|
+
return {
|
|
757
|
+
type: 'entry',
|
|
758
|
+
actions: actions.toActionObjects(predictableExec ? _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(entryActions), false), _tslib.__read(invokeActions), false) : _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(invokeActions), false), _tslib.__read(entryActions), false), _this.machine.options.actions)
|
|
759
|
+
};
|
|
760
|
+
}).concat({
|
|
761
|
+
type: 'state_done',
|
|
762
|
+
actions: doneEvents.map(actions.raise)
|
|
763
|
+
});
|
|
758
764
|
var exitActions = Array.from(exitStates).map(function (stateNode) {
|
|
759
|
-
return
|
|
760
|
-
|
|
761
|
-
|
|
765
|
+
return {
|
|
766
|
+
type: 'exit',
|
|
767
|
+
actions: actions.toActionObjects(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
|
|
768
|
+
return actions.stop(activity);
|
|
769
|
+
})), false), _this.machine.options.actions)
|
|
770
|
+
};
|
|
762
771
|
});
|
|
763
|
-
var actions$1 = exitActions.concat(
|
|
772
|
+
var actions$1 = exitActions.concat({
|
|
773
|
+
type: 'transition',
|
|
774
|
+
actions: actions.toActionObjects(transition.actions, this.machine.options.actions)
|
|
775
|
+
}).concat(entryActions);
|
|
764
776
|
|
|
765
777
|
if (isDone) {
|
|
766
778
|
var stopActions = actions.toActionObjects(utils.flatten(_tslib.__spreadArray([], _tslib.__read(resolvedConfig), false).sort(function (a, b) {
|
|
@@ -770,7 +782,10 @@ function () {
|
|
|
770
782
|
})), this.machine.options.actions).filter(function (action) {
|
|
771
783
|
return action.type !== actionTypes.raise && (action.type !== actionTypes.send || !!action.to && action.to !== types.SpecialTargets.Internal);
|
|
772
784
|
});
|
|
773
|
-
return actions$1.concat(
|
|
785
|
+
return actions$1.concat({
|
|
786
|
+
type: 'stop',
|
|
787
|
+
actions: stopActions
|
|
788
|
+
});
|
|
774
789
|
}
|
|
775
790
|
|
|
776
791
|
return actions$1;
|
|
@@ -865,8 +880,8 @@ function () {
|
|
|
865
880
|
var block = actionBlocks_1_1.value;
|
|
866
881
|
|
|
867
882
|
try {
|
|
868
|
-
for (var
|
|
869
|
-
var action =
|
|
883
|
+
for (var _c = (e_7 = void 0, _tslib.__values(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
884
|
+
var action = _d.value;
|
|
870
885
|
|
|
871
886
|
if (action.type === actionTypes.start) {
|
|
872
887
|
activities[action.activity.id || action.activity.type] = action;
|
|
@@ -880,7 +895,7 @@ function () {
|
|
|
880
895
|
};
|
|
881
896
|
} finally {
|
|
882
897
|
try {
|
|
883
|
-
if (
|
|
898
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
884
899
|
} finally {
|
|
885
900
|
if (e_7) throw e_7.error;
|
|
886
901
|
}
|
|
@@ -898,15 +913,15 @@ function () {
|
|
|
898
913
|
}
|
|
899
914
|
}
|
|
900
915
|
|
|
901
|
-
var
|
|
902
|
-
resolvedActions =
|
|
903
|
-
updatedContext =
|
|
916
|
+
var _e = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
|
|
917
|
+
resolvedActions = _e[0],
|
|
918
|
+
updatedContext = _e[1];
|
|
904
919
|
|
|
905
|
-
var
|
|
920
|
+
var _f = _tslib.__read(utils.partition(resolvedActions, function (action) {
|
|
906
921
|
return action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal;
|
|
907
922
|
}), 2),
|
|
908
|
-
raisedEvents =
|
|
909
|
-
nonRaisedActions =
|
|
923
|
+
raisedEvents = _f[0],
|
|
924
|
+
nonRaisedActions = _f[1];
|
|
910
925
|
|
|
911
926
|
var invokeActions = resolvedActions.filter(function (action) {
|
|
912
927
|
var _a;
|
package/lib/actions.d.ts
CHANGED
|
@@ -150,5 +150,8 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
|
|
|
150
150
|
*/
|
|
151
151
|
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
|
|
152
152
|
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
|
|
153
|
-
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<
|
|
153
|
+
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<{
|
|
154
|
+
type: string;
|
|
155
|
+
actions: Array<ActionObject<TContext, TEvent>>;
|
|
156
|
+
}>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
|
|
154
157
|
//# sourceMappingURL=actions.d.ts.map
|
package/lib/actions.js
CHANGED
|
@@ -439,10 +439,10 @@ var pluckAssigns = function (actionBlocks) {
|
|
|
439
439
|
var block = actionBlocks_1_1.value;
|
|
440
440
|
var i = 0;
|
|
441
441
|
|
|
442
|
-
while (i < block.length) {
|
|
443
|
-
if (block[i].type === actionTypes.assign) {
|
|
444
|
-
assignActions.push(block[i]);
|
|
445
|
-
block.splice(i, 1);
|
|
442
|
+
while (i < block.actions.length) {
|
|
443
|
+
if (block.actions[i].type === actionTypes.assign) {
|
|
444
|
+
assignActions.push(block.actions[i]);
|
|
445
|
+
block.actions.splice(i, 1);
|
|
446
446
|
continue;
|
|
447
447
|
}
|
|
448
448
|
|
|
@@ -474,7 +474,7 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
474
474
|
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
|
|
475
475
|
var deferredToBlockEnd = [];
|
|
476
476
|
|
|
477
|
-
function handleAction(actionObject) {
|
|
477
|
+
function handleAction(blockType, actionObject) {
|
|
478
478
|
var _a;
|
|
479
479
|
|
|
480
480
|
switch (actionObject.type) {
|
|
@@ -493,7 +493,11 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
if (predictableExec && sendAction.to !== types.SpecialTargets.Internal) {
|
|
496
|
-
|
|
496
|
+
if (blockType === 'entry') {
|
|
497
|
+
deferredToBlockEnd.push(sendAction);
|
|
498
|
+
} else {
|
|
499
|
+
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
|
|
500
|
+
}
|
|
497
501
|
}
|
|
498
502
|
|
|
499
503
|
return sendAction;
|
|
@@ -517,7 +521,10 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
517
521
|
return [];
|
|
518
522
|
}
|
|
519
523
|
|
|
520
|
-
var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [
|
|
524
|
+
var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [{
|
|
525
|
+
type: blockType,
|
|
526
|
+
actions: toActionObjects(utils.toArray(matchedActions), machine.options.actions)
|
|
527
|
+
}], predictableExec, preserveActionOrder), 2),
|
|
521
528
|
resolvedActionsFromChoose = _b[0],
|
|
522
529
|
resolvedContextFromChoose = _b[1];
|
|
523
530
|
|
|
@@ -534,7 +541,10 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
534
541
|
return [];
|
|
535
542
|
}
|
|
536
543
|
|
|
537
|
-
var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [
|
|
544
|
+
var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [{
|
|
545
|
+
type: blockType,
|
|
546
|
+
actions: toActionObjects(utils.toArray(matchedActions), machine.options.actions)
|
|
547
|
+
}], predictableExec, preserveActionOrder), 2),
|
|
538
548
|
resolvedActionsFromPure = _c[0],
|
|
539
549
|
resolvedContext = _c[1];
|
|
540
550
|
|
|
@@ -588,9 +598,9 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
588
598
|
var resolvedActions = [];
|
|
589
599
|
|
|
590
600
|
try {
|
|
591
|
-
for (var
|
|
592
|
-
var action =
|
|
593
|
-
var resolved = handleAction(action);
|
|
601
|
+
for (var _b = _tslib.__values(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
602
|
+
var action = _c.value;
|
|
603
|
+
var resolved = handleAction(block.type, action);
|
|
594
604
|
|
|
595
605
|
if (resolved) {
|
|
596
606
|
resolvedActions = resolvedActions.concat(resolved);
|
|
@@ -602,7 +612,7 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
|
|
|
602
612
|
};
|
|
603
613
|
} finally {
|
|
604
614
|
try {
|
|
605
|
-
if (
|
|
615
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
606
616
|
} finally {
|
|
607
617
|
if (e_2) throw e_2.error;
|
|
608
618
|
}
|
package/lib/interpreter.js
CHANGED
|
@@ -805,7 +805,10 @@ function () {
|
|
|
805
805
|
return actions.toActionObjects(stateNode.onExit, _this.machine.options.actions);
|
|
806
806
|
}));
|
|
807
807
|
|
|
808
|
-
var _a = _tslib.__read(actions.resolveActions(_this.machine, _this.state, _this.state.context, _event, [
|
|
808
|
+
var _a = _tslib.__read(actions.resolveActions(_this.machine, _this.state, _this.state.context, _event, [{
|
|
809
|
+
type: 'exit',
|
|
810
|
+
actions: exitActions
|
|
811
|
+
}], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
|
|
809
812
|
resolvedActions = _a[0],
|
|
810
813
|
updatedContext = _a[1];
|
|
811
814
|
|
package/lib/types.d.ts
CHANGED
|
@@ -285,11 +285,11 @@ export interface InvokeConfig<TContext, TEvent extends EventObject> {
|
|
|
285
285
|
/**
|
|
286
286
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
287
287
|
*/
|
|
288
|
-
onDone?: string | SingleOrArray<
|
|
288
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
|
|
289
289
|
/**
|
|
290
290
|
* The transition to take upon the invoked child machine sending an error event.
|
|
291
291
|
*/
|
|
292
|
-
onError?: string | SingleOrArray<
|
|
292
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
|
|
293
293
|
/**
|
|
294
294
|
* Meta data related to this invocation
|
|
295
295
|
*/
|