xstate 4.28.0 → 4.28.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # xstate
2
2
 
3
+ ## 4.28.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2943](https://github.com/statelyai/xstate/pull/2943) [`e9f3f07a1`](https://github.com/statelyai/xstate/commit/e9f3f07a1ee9fe97af7e8f532c5b3dd3c4f73cec) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an infinite loop when initially spawned actor (in an initial context) responded synchronously to its parent.
8
+
9
+ * [#2953](https://github.com/statelyai/xstate/pull/2953) [`90fa97008`](https://github.com/statelyai/xstate/commit/90fa97008970283f17a3f2f6aa9b1b7071593e80) Thanks [@Andarist](https://github.com/Andarist)! - Bring back the global type declaration for the `Symbol.observable` to fix consuming projects that do not use `skipLibCheck`.
10
+
11
+ - [#2903](https://github.com/statelyai/xstate/pull/2903) [`b6dde9075`](https://github.com/statelyai/xstate/commit/b6dde9075adb3bb3522b4b8f8eeb804d3221a527) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with exit actions being called in random order when stopping a machine. They should always be called in the reversed document order (the ones defined on children should be called before the ones defined on ancestors and the ones defined on states appearing later in the code should be called before the ones defined on their sibling states).
12
+
3
13
  ## 4.28.0
4
14
 
5
15
  ### Minor Changes
@@ -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,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){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 o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.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 s}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))}!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,u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(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,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,n){var i,o;if(v(t))return t(e,n.data);var s={};try{for(var a=r(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];v(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}var g=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}(),m=((a={})[g]=function(){return this},a);function b(t){try{return"__xstatenode"in t}catch(t){return!1}}var x=function(){var t=0;return function(){return(++t).toString(16)}}();function w(t,e){return y(t)||"number"==typeof t?i({type:t},e):t}function S(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=w(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t,e,n){if("object"==typeof t)return t;var i=function(){};return{next:t,error:e||i,complete:n||i}}function _(t){return c(t.states).map((function(e){return t.states[e]}))}function O(t){return s([],o(new Set(function(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}function T(t,e){return"compound"===e.type?_(e).some((function(e){return"final"===e.type&&(n=t,i=e,Array.isArray(n)?n.some((function(t){return t===i})):n instanceof Set&&n.has(i));var n,i})):"parallel"===e.type&&_(e).every((function(e){return T(t,e)}))}var I=e.Start,L=e.Stop,k=(e.Raise,e.Send),C=e.Cancel,P=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),j=e.Init,N=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),A=e.ErrorCustom,D=e.Update,M=(e.Choose,e.Pure,S({type:j}));function R(t,n){var i="".concat(e.DoneInvoke,".").concat(t),r={type:i,data:n,toString:function(){return i}};return r}function z(t,n){var i="".concat(e.ErrorPlatform,".").concat(t),r={type:i,data:n,toString:function(){return i}};return r}var V=function(){function t(t){var e,n,i=this;this.actions=[],this.activities=u,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||u,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 O(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:M,_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=M;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="."),y(t))return[t];var i=c(t);return i.concat.apply(i,s([],o(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,e=(t.configuration,t.transitions,t.tags),n=(t.machine,function(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}(t,["configuration","transitions","tags","machine"]));return i(i({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,i){void 0===i&&(i=".");var r=h(e,i),o=h(n,i);return y(o)?!!y(r)&&o===r:y(r)?r in o:c(r).every((function(e){return e in o&&t(r[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}(),J={deferEvents:!1},q=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},J),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}(),U=[],$=function(t,e){U.push(t);var n=e(t);return U.pop(),n};function F(t,e,n){var r=function(t){return i({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},m)}(e);if(r.deferred=!0,b(t)){var o=r.state=$(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return o}}return r}var X=new Map,B=0,G=function(){return"x:".concat(B++)},H=function(t,e){return X.set(t,e),t},K=function(t){return X.get(t)},Q=function(t){X.delete(t)};function W(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Y(t){if(W()){var e=function(){var t=W();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Z(t,e){void 0===e&&(e={});var n,r=t.initialState,o=new Set,s=[],a=!1,u=(n={id:e.id,send:function(e){s.push(e),function(){if(!a){for(a=!0;s.length>0;){var e=s.shift();r=t.transition(r,e,c),o.forEach((function(t){return t.next(r)}))}a=!1}}()},getSnapshot:function(){return r},subscribe:function(t,e,n){var i=E(t,e,n);return o.add(i),i.next(r),{unsubscribe:function(){o.delete(i)}}}},i(i({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},m),n)),c={parent:e.parent,self:u,id:e.id||"anonymous",observers:o};return r=t.start?t.start(c):r,u}var tt,et={sync:!1,autoForward:!1};(tt=t.InterpreterStatus||(t.InterpreterStatus={}))[tt.NotStarted=0]="NotStarted",tt[tt.Running=1]="Running",tt[tt.Stopped=2]="Stopped";var nt=function(){function a(e,r){var o=this;void 0===r&&(r=a.defaultOptions),this.machine=e,this.scheduler=new q,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.init=this.start,this.send=function(e,n){if(p(e))return o.batch(e),o.state;var i=S(w(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(t,e){var r,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:y(e)?o.children.get(e)||K(e):(r=e)&&"function"==typeof r.send?e:void 0;if(a)"machine"in a?a.send(i(i({},t),{name:t.name===A?"".concat(z(o.id)):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '".concat(e,"' from service '").concat(o.id,"'."))};var s=i(i({},a.defaultOptions),r),u=s.clock,c=s.logger,h=s.parent,f=s.id,l=void 0!==f?f:e.id;this.id=l,this.logger=c,this.clock=u,this.parent=h,this.options=s,this.scheduler=new q({deferEvents:this.options.deferEvents}),this.sessionId=G()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:$(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,i;try{for(var o=r(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&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},a.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),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=r(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=r(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var g=r(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){a={error:t}}finally{try{m&&!m.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var b=T(t.configuration||[],this.machine);if(this.state.configuration&&b){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?l(x.doneData,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(R(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},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,i){var r,o=this;if(!e)return{unsubscribe:function(){}};var s=i;return"function"==typeof e?r=e:(r=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(r),this.status===t.InterpreterStatus.Running&&r(this.state),s&&this.onDone(s),{unsubscribe:function(){r&&o.listeners.delete(r),s&&o.doneListeners.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;H(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:$(this,(function(){return!y(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(V.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,M)})),this},a.prototype.stop=function(){var e,n,i,o,s,a,u,h,f,l,d=this;try{for(var p=r(this.listeners),y=p.next();!y.done;y=p.next()){var g=y.value;this.listeners.delete(g)}}catch(t){e={error:t}}finally{try{y&&!y.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var m=r(this.stopListeners),b=m.next();!b.done;b=m.next()){(g=b.value)(),this.stopListeners.delete(g)}}catch(t){i={error:t}}finally{try{b&&!b.done&&(o=m.return)&&o.call(m)}finally{if(i)throw i.error}}try{for(var x=r(this.contextListeners),w=x.next();!w.done;w=x.next()){g=w.value;this.contextListeners.delete(g)}}catch(t){s={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(s)throw s.error}}try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){g=E.value;this.doneListeners.delete(g)}}catch(t){u={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var s=o.value;d.exec(s,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var _=r(c(this.delayedEventsMap)),O=_.next();!O.done;O=_.next()){var T=O.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Q(this.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.'));this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=S(t);n.forward(e),u=$(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,r=(e=t).exec,i(i({},e),{exec:void 0!==r?function(){return r(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,r}))),!1)),c=c||!!u.changed};try{for(var l=r(e),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,n.update(u,S(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=S(t);if(0===n.name.indexOf(N)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(N)})))throw n.data.data;return $(this,(function(){return e.machine.transition(e.state,n)}))},a.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.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=i.return)&&n.call(i)}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):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(n,i,r){void 0===r&&(r=this.machine.options.actions);var o,s=i.context,a=i._event,u=n.exec||function(t,e){return e&&e[t]||void 0}(n.type,r),c=v(u)?u:u?u.exec:n.exec;if(c)try{return c(s,a.data,{action:n,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case k:var h=n;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to):this.send(h._event);break;case C:this.cancel(n.sendId);break;case I:if(this.status!==t.InterpreterStatus.Running)return;var f=n.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===e.Invoke){var d="string"==typeof(o=f.src)?{type:o}:o,p=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=f.id,g=f.data,m="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var x=g?l(g,s,a):void 0;if("string"==typeof p)return;var w=v(p)?p(s,a.data,{data:x,src:d,meta:f.meta}):p;if(!w)return;var S=void 0;b(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),this.spawn(w,y,S)}else this.spawnActivity(f);break;case L:this.stopChild(n.activity.id);break;case P:var E=n.label,_=n.value;E?this.logger(E,_):this.logger(_)}},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),v(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&v(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(b(t))return this.spawnMachine(t,i(i({},n),{id:e}));if(null!==(r=t)&&"object"==typeof r&&"transition"in r&&"function"==typeof r.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'.concat(e,'" of type "').concat(typeof t,'".'));var r,o},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var r=new a(t,i(i({},this.options),{parent:this,id:e.id||t.id})),o=i(i({},et),e);o.sync&&r.onTransition((function(t){n.send(D,{state:t,id:r.id})}));var s=r;return this.children.set(r.id,s),o.autoForward&&this.forwardTo.add(r.id),r.onDone((function(t){n.removeChild(r.id),n.send(S(t,{origin:r.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=Z(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,r=this,o=!1;t.then((function(t){o||(n=t,r.removeChild(e),r.send(S(R(e,t),{origin:e})))}),(function(t){if(!o){r.removeChild(e);var n=z(e,t);try{r.send(S(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var s=i({id:e,send:function(){},subscribe:function(e,n,i){var r=E(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 n}},m);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,r,o=this,s=!1,a=new Set,u=new Set;try{r=t((function(t){n=t,u.forEach((function(e){return e(t)})),s||o.send(S(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(z(e,t))}if(d(r))return this.spawnPromise(r,e);var c=i({id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){return u.add(t),{unsubscribe:function(){u.delete(t)}}},stop:function(){s=!0,v(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}},m);return this.children.set(e,c),c},a.prototype.spawnObservable=function(t,e){var n,r=this,o=t.subscribe((function(t){n=t,r.send(S(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(S(z(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(S(R(e),{origin:e}))})),s=i({id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}},m);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){this.children.set(t,i({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},m))},a.prototype.attachDev=function(){var t=W();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)}Y(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[g]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),a.interpret=it,a}();function it(t,e){return new nt(t,e)}t.Interpreter=nt,t.interpret=it,t.spawn=function(t,e){var n=function(t){return y(t)?i(i({},et),{name:t}):i(i(i({},et),{name:x()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):F(t,n.name)}(U[U.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,u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(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 l(t,e,n){var r,o;if(v(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];v(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}var g=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}(),m=((a={})[g]=function(){return this},a);function b(t){try{return"__xstatenode"in t}catch(t){return!1}}var x=function(){var t=0;return function(){return(++t).toString(16)}}();function w(t,e){return y(t)||"number"==typeof t?r({type:t},e):t}function S(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=w(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function _(t){return c(t.states).map((function(e){return t.states[e]}))}function O(t){return s([],o(new Set(function(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}function T(t,e){return"compound"===e.type?_(e).some((function(e){return"final"===e.type&&(n=t,r=e,Array.isArray(n)?n.some((function(t){return t===r})):n instanceof Set&&n.has(r));var n,r})):"parallel"===e.type&&_(e).every((function(e){return T(t,e)}))}var I=e.Start,L=e.Stop,k=(e.Raise,e.Send),C=e.Cancel,P=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),j=e.Init,N=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),A=e.ErrorCustom,D=e.Update,M=(e.Choose,e.Pure,S({type:j}));function R(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function z(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}var V=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=u,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||u,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 O(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:M,_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=M;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="."),y(t))return[t];var r=c(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,e=(t.configuration,t.transitions,t.tags),n=(t.machine,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=h(e,r),o=h(n,r);return y(o)?!!y(i)&&o===i:y(i)?i in o:c(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}(),J={deferEvents:!1},q=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},J),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}(),U=[],$=function(t,e){U.push(t);var n=e(t);return U.pop(),n};function F(t,e,n){var i=function(t){return r({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},m)}(e);if(i.deferred=!0,b(t)){var o=i.state=$(void 0,(function(){return(n?t.withContext(n):t).initialState}));i.getSnapshot=function(){return o}}return i}var X=new Map,B=0,G=function(){return"x:".concat(B++)},H=function(t,e){return X.set(t,e),t},K=function(t){return X.get(t)},Q=function(t){X.delete(t)};function W(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Y(t){if(W()){var e=function(){var t=W();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Z(t,e){void 0===e&&(e={});var n,i=t.initialState,o=new Set,s=[],a=!1,u=(n={id:e.id,send:function(e){s.push(e),function(){if(!a){for(a=!0;s.length>0;){var e=s.shift();i=t.transition(i,e,c),o.forEach((function(t){return t.next(i)}))}a=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=E(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},r(r({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},m),n)),c={parent:e.parent,self:u,id:e.id||"anonymous",observers:o};return i=t.start?t.start(c):i,u}var tt,et={sync:!1,autoForward:!1};(tt=t.InterpreterStatus||(t.InterpreterStatus={}))[tt.NotStarted=0]="NotStarted",tt[tt.Running=1]="Running",tt[tt.Stopped=2]="Stopped";var nt=function(){function a(e,i){var o=this;void 0===i&&(i=a.defaultOptions),this.machine=e,this.scheduler=new q,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.init=this.start,this.send=function(e,n){if(p(e))return o.batch(e),o.state;var r=S(w(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(t,e){var i,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:y(e)?o.children.get(e)||K(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===A?"".concat(z(o.id)):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '".concat(e,"' from service '").concat(o.id,"'."))};var s=r(r({},a.defaultOptions),i),u=s.clock,c=s.logger,h=s.parent,f=s.id,l=void 0!==f?f:e.id;this.id=l,this.logger=c,this.clock=u,this.parent=h,this.options=s,this.scheduler=new q({deferEvents:this.options.deferEvents}),this.sessionId=G()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:$(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,u,c,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),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=i(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=i(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var g=i(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){a={error:t}}finally{try{m&&!m.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var b=T(t.configuration||[],this.machine);if(this.state.configuration&&b){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?l(x.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(R(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},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,o=this;if(!e)return{unsubscribe:function(){}};var s=r;return"function"==typeof e?i=e:(i=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),s&&this.onDone(s),{unsubscribe:function(){i&&o.listeners.delete(i),s&&o.doneListeners.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;H(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:$(this,(function(){return!y(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(V.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,M)})),this},a.prototype.stop=function(){var e,n,r,a,u,h,f,l,d,p,y=this;try{for(var g=i(this.listeners),m=g.next();!m.done;m=g.next()){var b=m.value;this.listeners.delete(b)}}catch(t){e={error:t}}finally{try{m&&!m.done&&(n=g.return)&&n.call(g)}finally{if(e)throw e.error}}try{for(var x=i(this.stopListeners),w=x.next();!w.done;w=x.next()){(b=w.value)(),this.stopListeners.delete(b)}}catch(t){r={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(r)throw r.error}}try{for(var S=i(this.contextListeners),E=S.next();!E.done;E=S.next()){b=E.value;this.contextListeners.delete(b)}}catch(t){u={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(u)throw u.error}}try{for(var _=i(this.doneListeners),O=_.next();!O.done;O=_.next()){b=O.value;this.doneListeners.delete(b)}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}if(!this.initialized)return this;s([],o(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var r=i(t.definition.exit),o=r.next();!o.done;o=r.next()){var s=o.value;y.exec(s,y.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var T=i(c(this.delayedEventsMap)),I=T.next();!I.done;I=T.next()){var L=I.value;this.clock.clearTimeout(this.delayedEventsMap[L])}}catch(t){d={error:t}}finally{try{I&&!I.done&&(p=T.return)&&p.call(T)}finally{if(d)throw d.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Q(this.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.'));this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=S(t);n.forward(e),u=$(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,i=(e=t).exec,r(r({},e),{exec:void 0!==i?function(){return i(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,i}))),!1)),c=c||!!u.changed};try{for(var l=i(e),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,n.update(u,S(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=S(t);if(0===n.name.indexOf(N)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(N)})))throw n.data.data;return $(this,(function(){return e.machine.transition(e.state,n)}))},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):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(n,r,i){void 0===i&&(i=this.machine.options.actions);var o,s=r.context,a=r._event,u=n.exec||function(t,e){return e&&e[t]||void 0}(n.type,i),c=v(u)?u:u?u.exec:n.exec;if(c)try{return c(s,a.data,{action:n,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case k:var h=n;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to):this.send(h._event);break;case C:this.cancel(n.sendId);break;case I:if(this.status!==t.InterpreterStatus.Running)return;var f=n.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===e.Invoke){var d="string"==typeof(o=f.src)?{type:o}:o,p=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=f.id,g=f.data,m="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var x=g?l(g,s,a):void 0;if("string"==typeof p)return;var w=v(p)?p(s,a.data,{data:x,src:d,meta:f.meta}):p;if(!w)return;var S=void 0;b(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),this.spawn(w,y,S)}else this.spawnActivity(f);break;case L:this.stopChild(n.activity.id);break;case P:var E=n.label,_=n.value;E?this.logger(E,_):this.logger(_)}},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),v(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&v(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(b(t))return this.spawnMachine(t,r(r({},n),{id:e}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'.concat(e,'" of type "').concat(typeof t,'".'));var i,o},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({},et),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(S(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=Z(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,i=this,o=!1;t.then((function(t){o||(n=t,i.removeChild(e),i.send(S(R(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=z(e,t);try{i.send(S(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=r({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 n}},m);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,i,o=this,s=!1,a=new Set,u=new Set;try{i=t((function(t){n=t,u.forEach((function(e){return e(t)})),s||o.send(S(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(z(e,t))}if(d(i))return this.spawnPromise(i,e);var c=r({id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){return u.add(t),{unsubscribe:function(){u.delete(t)}}},stop:function(){s=!0,v(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}},m);return this.children.set(e,c),c},a.prototype.spawnObservable=function(t,e){var n,i=this,o=t.subscribe((function(t){n=t,i.send(S(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(S(z(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(S(R(e),{origin:e}))})),s=r({id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}},m);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){this.children.set(t,r({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},m))},a.prototype.attachDev=function(){var t=W();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)}Y(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[g]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),a.interpret=rt,a}();function rt(t,e){return new nt(t,e)}t.Interpreter=nt,t.interpret=rt,t.spawn=function(t,e){var n=function(t){return y(t)?r(r({},et),{name:t}):r(r(r({},et),{name:x()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):F(t,n.name)}(U[U.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=function(){return(e=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 n(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 r(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 i(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 o(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))}var a,s={};function c(t){return Object.keys(t)}function u(t,e,n){void 0===n&&(n=".");var r=l(t,n),i=l(e,n);return O(i)?!!O(r)&&i===r:O(r)?r in i:c(r).every((function(t){return t in i&&u(r[t],i[t])}))}function h(t){try{return O(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 f(t,e){try{return N(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function l(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:N(t)?d(t):"string"!=typeof t?t:d(f(t,e));var n}function d(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function p(t,e){for(var n={},r=c(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 i,o,a={};try{for(var s=r(c(t)),u=s.next();!u.done;u=s.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}var y=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[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 o}};function g(t){return t?O(t)?[[t]]:m(c(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?g(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function m(t){var e;return(e=[]).concat.apply(e,o([],i(t),!1))}function S(t){return N(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(t,e,n){var i,o;if(A(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];A(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function b(t){return t instanceof Promise||!(null===t||!A(t)&&"object"!=typeof t||!A(t.then))}function _(t,e){var n,o,a=i([[],[]],2),s=a[0],c=a[1];try{for(var u=r(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&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function T(t,e){return p(t.states,(function(t,n){if(t){var r=(O(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:T(t,r)}}}))}function E(t,e,n,i){return t?n.reduce((function(t,n){var o,a,s=n.assignment,u={state:i,action:n,_event:e},h={};if(A(s))h=s(t,e.data,u);else try{for(var f=r(c(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[d];h[d]=A(p)?p(t,e.data,u):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,h)}),t):t}function N(t){return Array.isArray(t)}function A(t){return"function"==typeof t}function O(t){return"string"==typeof t}function P(t,e){if(t)return O(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:A(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var k=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}(),I=((a={})[k]=function(){return this},a);function j(t){try{return"__xstatenode"in t}catch(t){return!1}}var C,V,D=function(){var t=0;return function(){return(++t).toString(16)}}();function L(t,n){return O(t)||"number"==typeof t?e({type:t},n):t}function R(t,n){if(!O(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return S(n).map((function(n){return void 0===n||"string"==typeof n||j(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function z(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=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 F(t){return"string"==typeof t?{type:t}:t}function U(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function B(t,e){return"".concat(t,":invocation[").concat(e,"]")}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",C.Choose="xstate.choose",(V=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",V.Internal="#_internal";var J=function(t){return"atomic"===t.type||"final"===t.type};function q(t){return c(t.states).map((function(e){return t.states[e]}))}function $(t){var e=[t];return J(t)?e:e.concat(m(q(t).map($)))}function X(t,e){var n,i,o,a,s,c,u,h,f=H(new Set(t)),l=new Set(e);try{for(var d=r(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=H(l);try{for(var g=r(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 S=(s=void 0,r(q(T))),x=S.next();!x.done;x=S.next()){var w=x.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{x&&!x.done&&(c=S.return)&&c.call(S)}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){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.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=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function H(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.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=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i}function G(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(J(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,H(X([t],e)))}function K(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function Q(t,e){return"compound"===e.type?q(e).some((function(e){return"final"===e.type&&K(t,e)})):"parallel"===e.type&&q(e).every((function(e){return Q(t,e)}))}function W(t){return new Set(m(t.map((function(t){return t.tags}))))}var Y=t.ActionTypes.Start,Z=t.ActionTypes.Stop,tt=t.ActionTypes.Raise,et=t.ActionTypes.Send,nt=t.ActionTypes.Cancel,rt=t.ActionTypes.NullEvent,it=t.ActionTypes.Assign,ot=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),at=t.ActionTypes.Init,st=t.ActionTypes.Invoke,ct=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),ut=t.ActionTypes.ErrorCustom,ht=t.ActionTypes.Update,ft=t.ActionTypes.Choose,lt=t.ActionTypes.Pure,dt=R({type:at});function pt(t,e){return e&&e[t]||void 0}function vt(t,n){var r;if(O(t)||"number"==typeof t)r=A(i=pt(t,n))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(A(t))r={type:t.name||t.toString(),exec:t};else{var i;if(A(i=pt(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return r}var yt=function(t,e){return t?(N(t)?t:[t]).map((function(t){return vt(t,e)})):[]};function gt(t){var n=vt(t);return e(e({id:O(t)?t:n.id},n),{type:n.type})}function mt(e){return O(e)?{type:tt,event:e}:St(e,{to:t.SpecialTargets.Internal})}function St(t,e){return{to:e?e.to:void 0,type:et,event:A(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:A(t)?t.name:h(t)}}function xt(n,r){return St(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function wt(){return xt(ht)}var bt=function(t,e){return{context:t,event:e}};var _t=function(t){return{type:nt,sendId:t}};function Tt(e){var n=gt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function Et(e){var n=A(e)?e:gt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var Nt=function(t){return{type:it,assignment:t}};function At(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Ot(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Pt(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function kt(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function It(t,n){return St((function(t,e){return e}),e(e({},n),{to:t}))}function jt(n,r,a,s,c,u){void 0===u&&(u=!1);var h=i(u?[[],c]:_(c,(function(t){return t.type===it})),2),f=h[0],l=h[1],d=f.length?E(a,s,f,r):a,p=u?[a]:void 0;return[m(l.map((function(a){var c;switch(a.type){case tt:return{type:tt,_event:R(a.event)};case et:return function(t,n,r,i){var o,a={_event:r},s=R(A(t.event)?t.event(n,r.data,a):t.event);if(O(t.delay)){var c=i&&i[t.delay];o=A(c)?c(n,r.data,a):c}else o=A(t.delay)?t.delay(n,r.data,a):t.delay;var u=A(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(a,d,s,n.options.delays);case ot:return function(t,n,r){return e(e({},t),{value:O(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(a,d,s);case ft:if(!(v=null===(c=a.conds.find((function(t){var e=P(t.cond,n.options.guards);return!e||z(n,e,d,s,r)})))||void 0===c?void 0:c.actions))return[];var h=i(jt(n,r,d,s,yt(x(v),n.options.actions),u),2),f=h[0],l=h[1];return d=l,null==p||p.push(d),f;case lt:var v;if(!(v=a.get(d,s.data)))return[];var y=i(jt(n,r,d,s,yt(x(v),n.options.actions),u),2),g=y[0],m=y[1];return d=m,null==p||p.push(d),g;case Z:return function(e,n,r){var i=A(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(a,d,s);case it:d=E(d,s,[a],r),null==p||p.push(d);break;default:var S=vt(a,n.options.actions),w=S.exec;if(w&&p){var b=p.length-1;S=e(e({},S),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];w.apply(void 0,o([p[b]],i(e),!1))}})}return S}})).filter((function(t){return!!t}))),d]}var Ct=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=s,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||s,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 o([],i(new Set(m(o([],i(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:dt,_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=dt;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="."),O(t))return[t];var r=c(t);return r.concat.apply(r,o([],i(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,r=(t.configuration,t.transitions,t.tags),i=(t.machine,n(t,["configuration","transitions","tags","machine"]));return e(e({},i),{tags:Array.from(r)})},t.prototype.matches=function(t){return u(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}(),Vt=[],Dt=function(t,e){Vt.push(t);var n=e(t);return Vt.pop(),n};function Lt(t){return e({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},I)}function Rt(t,e,n){var r=Lt(e);if(r.deferred=!0,j(t)){var i=r.state=Dt(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Mt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function zt(t){return e(e({type:st},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:st,src:Mt(t.src)})}})}var Ft={},Ut=function(t){return"#"===t[0]},Bt=function(){function a(t,n,s){var u,h=this;void 0===s&&(s="context"in t?t.context:void 0),this.config=t,this._context=s,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=this.options._parent,this.key=this.config.key||this.options._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||o([this.machine.key],i(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&&c(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?p(this.config.states,(function(t,n){var r,i=new a(t,{_parent:h,_key:n});return Object.assign(h.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Ft;var f=0;!function t(e){var n,i;e.order=f++;try{for(var o=r(q(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}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=x(this.config.entry||this.config.onEntry).map((function(t){return vt(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return vt(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var r,i;if(j(t)){var o=B(h.id,n);return h.machine.options.services=e(((r={})[o]=t,r),h.machine.options.services),zt({src:o,id:o})}if(O(t.src)){o=t.id||B(h.id,n);return zt(e(e({},t),{id:o,src:t.src}))}if(j(t.src)||A(t.src)){o=t.id||B(h.id,n);return h.machine.options.services=e(((i={})[o]=t.src,i),h.machine.options.services),zt(e(e({id:o},t),{src:o}))}var a=t.src;return zt(e(e({id:B(h.id,n)},t),{src:a}))})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return gt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||$(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){var r=this.options,i=r.actions,o=r.activities,s=r.guards,c=r.services,u=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},null!=n?n:this.context)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"context",{get:function(){return A(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(a.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:p(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}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.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(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.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},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=At(A(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(St(r,{delay:e})),t.onExit.push(_t(r)),r};return(N(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):m(c(n).map((function(t,i){var o=n[t],a=O(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Ct?t.value:l(t,this.delimiter);if(O(r)){var a=this.getStateNode(r).initial;return void 0!==a?this.getStateNodes(((e={})[r]=a,e)):[this,this.states[r]]}var s=c(r),u=[this];return u.push.apply(u,o([],i(m(s.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),u},a.prototype.handles=function(t){var e=h(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(X([],this.getStateNodes(t.value)));return new Ct(e(e({},t),{value:this.resolve(t.value),configuration:n,done:Q(n,this),tags:W(n)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=c(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var s=r(c(t)),u=s.next();!u.done;u=s.next()){var h=u.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}var d=c(a).map((function(t){return a[t]})),p=m(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=m(d.map((function(t){return t.entrySet}))),y=m(c(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:m(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:m(c(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return O(t)?this.transitionLeafNode(t,e,n):1===c(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,R(e))},a.prototype.next=function(t,e){var n,a,s,c=this,h=e.name,f=[],d=[];try{for(var p=r(this.getCandidates(h)),v=p.next();!v.done;v=p.next()){var g=v.value,S=g.cond,x=g.in,w=t.context,b=!x||(O(x)&&Ut(x)?t.matches(l(this.getStateNodeById(x).path,this.delimiter)):u(l(x,this.delimiter),y(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||z(this.machine,S,w,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(S.name||S.type,"' in transition for event '").concat(h,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(_&&b){void 0!==g.target&&(d=g.target),f.push.apply(f,o([],i(g.actions),!1)),s=g;break}}}catch(t){n={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}if(s){if(!d.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:f};var T=m(d.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),E=!!s.internal;return{transitions:[s],entrySet:E?[]:m(T.map((function(t){return c.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:T,source:t,actions:f}}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],n=t;n&&n!==this;)e.push(n),n=n.parent;return e.push(this),e},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=X([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?X(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){K(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=r(f),y=v.next();!y.done;y=v.next()){var g;K(l,g=y.value)&&!K(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}var S=m(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Ot(r.id,r.doneData),Ot(o.id,r.doneData?w(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&q(a).every((function(e){return Q(t.configuration,e)}))&&i.push(Ot(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var x=new Set(t.entrySet),b=new Set(t.exitSet),_=i([m(Array.from(x).map((function(t){return o(o([],i(t.activities.map((function(t){return Tt(t)}))),!1),i(t.onEntry),!1)}))).concat(S.map(mt)),m(Array.from(b).map((function(t){return o(o([],i(t.onExit),!1),i(t.activities.map((function(t){return Et(t)}))),!1)})))],2),T=_[0],E=_[1];return yt(E.concat(t.actions).concat(T),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,a,s=R(e);if(t instanceof Ct)r=void 0===n?t:this.resolveState(Ct.from(t,n));else{var c=O(t)?this.resolve(d(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Ct.from(c,u))}if(this.strict&&!this.events.includes(s.name)&&(a=s.name,!/^(done|error)\./.test(a)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(s.name,"'"));var h=this._transition(r.value,r,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=X([],this.getStateNodes(r.value)),l=h.configuration.length?X(f,h.configuration):f;return h.configuration=o([],i(l),!1),this.resolveTransition(h,r,s)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,a=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o([],i(a),!1)),t},a.prototype.resolveTransition=function(n,o,a,s){var u,h,f=this;void 0===a&&(a=dt),void 0===s&&(s=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0,p=d?G(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=o?o.context:s,g=this.getActions(n,y,a,o),m=o?e({},o.activities):{};try{for(var S=r(g),x=S.next();!x.done;x=S.next()){var b=x.value;b.type===Y?m[b.activity.id||b.activity.type]=b:b.type===Z&&(m[b.activity.id||b.activity.type]=!1)}}catch(t){u={error:t}}finally{try{x&&!x.done&&(h=S.return)&&h.call(S)}finally{if(u)throw u.error}}var E,N,A=i(jt(this,o,y,a,g,this.machine.config.preserveActionOrder),2),P=A[0],k=A[1],I=i(_(P,(function(e){return e.type===tt||e.type===et&&e.to===t.SpecialTargets.Internal})),2),j=I[0],C=I[1],V=P.filter((function(t){var e;return t.type===Y&&(null===(e=t.activity)||void 0===e?void 0:e.type)===st})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=F(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?w(t.data,n,r):void 0,c=a?Rt(a,t.id,s):Lt(t.id);return c.meta=t,c}(e.activity,f.machine,k,a),t}),o?e({},o.children):{}),D=p?n.configuration:o?o.configuration:[],L=Q(D,this),R=new Ct({value:p||o.value,context:k,_event:a,_sessionid:o?o._sessionid:null,historyValue:p?v?(E=v,N=p,{current:N,states:T(E,N)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?C:[],activities:p?m:o?o.activities:{},events:[],configuration:D,transitions:n.transitions,children:V,done:L,tags:null==o?void 0:o.tags,machine:this}),M=y!==k;R.changed=a.name===ht||M;var z=R.history;z&&delete z.history;var U=!L&&(this._transient||l.some((function(t){return t._transient})));if(!(d||U&&""!==a.name))return R;var B=R;if(!L)for(U&&(B=this.resolveRaisedTransition(B,{type:rt},a));j.length;){var J=j.shift();B=this.resolveRaisedTransition(B,J._event,a)}var q=B.changed||(z?!!B.actions.length||M||typeof z.value!=typeof B.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(O(e)||O(n))return e===n;var r=c(e),i=c(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(B.value,z.value):void 0);return B.changed=q,B.history=z,B.tags=W(B.configuration),B},a.prototype.getStateNode=function(t){if(Ut(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},a.prototype.getStateNodeById=function(t){var e=Ut(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},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Ut(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=f(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Ft;switch(this.type){case"parallel":return p(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Ft}));case"compound":if(O(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return c(t).length?p(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Ft})):this.initialStateValue||{};default:return t||Ft}},a.prototype.getResolvedPath=function(t){if(Ut(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 f(t,this.delimiter)},Object.defineProperty(a.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||Ft}),(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=J(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}),a.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(a.prototype,"initialState",{get:function(){this._init();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(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=O(e.target)&&Ut(e.target)?d(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return J(this)?[this]:"compound"!==this.type||this.initial?m(g(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(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 o=this.getStateNode(n);if("history"===o.type)return o.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)},a.prototype.historyValue=function(t){if(c(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=O(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.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(g(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),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 O(s)?[n.getStateNode(s)]:m(g(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=m(c(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var s=r(c(o)),u=s.next();!u.done;u=s.next()){var h=o[u.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add("".concat(d))}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.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(a.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}),a.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!O(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))}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return O(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:yt(x(t.actions)),cond:P(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(n.id)})}});return s},a.prototype.formatTransitions=function(){var t,e,a,s=this;if(this.config.on)if(Array.isArray(this.config.on))a=this.config.on;else{var u=this.config.on,h=u["*"],f=void 0===h?[]:h,l=n(u,["*"]);a=m(c(l).map((function(t){return M(t,l[t])})).concat(M("*",f)))}else a=[];var d=this.config.always?M("",this.config.always):[],p=this.config.onDone?M(String(Ot(this.id)),this.config.onDone):[],v=m(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(M(String(Pt(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,o([],i(M(String(kt(t.id)),t.onError)),!1)),e}))),y=this.after,g=m(o(o(o(o([],i(p),!1),i(v),!1),i(a),!1),i(d),!1).map((function(t){return x(t).map((function(t){return s.formatTransition(t)}))})));try{for(var S=r(y),w=S.next();!w.done;w=S.next()){var b=w.value;g.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=S.return)&&e.call(S)}finally{if(t)throw t.error}}return g},a}();var Jt={deferEvents:!1},qt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Jt),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}(),$t=new Map,Xt=0,Ht=function(){return"x:".concat(Xt++)},Gt=function(t,e){return $t.set(t,e),t},Kt=function(t){return $t.get(t)},Qt=function(t){$t.delete(t)};function Wt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Yt(t){if(Wt()){var e=function(){var t=Wt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Zt(t,n){void 0===n&&(n={});var r,i=t.initialState,o=new Set,a=[],s=!1,c=(r={id:n.id,send:function(e){a.push(e),function(){if(!s){for(s=!0;a.length>0;){var e=a.shift();i=t.transition(i,e,u),o.forEach((function(t){return t.next(i)}))}s=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=U(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},e(e({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},I),r)),u={parent:n.parent,self:c,id:n.id||"anonymous",observers:o};return i=t.start?t.start(u):i,c}var te,ee={sync:!1,autoForward:!1};(te=t.InterpreterStatus||(t.InterpreterStatus={}))[te.NotStarted=0]="NotStarted",te[te.Running=1]="Running",te[te.Stopped=2]="Stopped";var ne=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new qt,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.init=this.start,this.send=function(e,n){if(N(e))return o.batch(e),o.state;var r=R(L(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(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:O(r)?o.children.get(r)||Kt(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ut?"".concat(kt(o.id)):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '".concat(r,"' from service '").concat(o.id,"'."))};var a=e(e({},n.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new qt({deferEvents:this.options.deferEvents}),this.sessionId=Ht()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Dt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t,t.event)}}catch(t){o={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}try{for(var y=r(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=Q(t.configuration||[],this.machine);if(this.state.configuration&&m){var S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),x=S&&S.doneData?w(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Pt(this.id,x))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.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},n.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;Gt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:Dt(this,(function(){return!O(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(Ct.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,dt)})),this},n.prototype.stop=function(){var e,n,i,o,a,s,u,h,f,l,d=this;try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){var y=v.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{v&&!v.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var g=r(this.stopListeners),m=g.next();!m.done;m=g.next()){(y=m.value)(),this.stopListeners.delete(y)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}try{for(var S=r(this.contextListeners),x=S.next();!x.done;x=S.next()){y=x.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(s=S.return)&&s.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.doneListeners),b=w.next();!b.done;b=w.next()){y=b.value;this.doneListeners.delete(y)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;d.exec(a,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){A(t.stop)&&t.stop()}));try{for(var _=r(c(this.delayedEventsMap)),T=_.next();!T.done;T=_.next()){var E=T.value;this.clock.clearTimeout(this.delayedEventsMap[E])}}catch(t){f={error:t}}finally{try{T&&!T.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Qt(this.sessionId),this},n.prototype.batch=function(n){var a=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(n.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.'));this.scheduler.schedule((function(){var t,s,c=a.state,u=!1,h=[],f=function(t){var n=R(t);a.forward(n),c=Dt(a,(function(){return a.machine.transition(c,n)})),h.push.apply(h,o([],i(c.actions.map((function(t){return r=c,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i}))),!1)),u=u||!!c.changed};try{for(var l=r(n),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(t)throw t.error}}c.changed=u,c.actions=h,a.update(c,R(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=R(t);if(0===n.name.indexOf(ct)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ct)})))throw n.data.data;return Dt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.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{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||pt(e.type,r),s=A(a)?a:a?a.exec:e.exec;if(s)try{return s(i,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case et:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case nt:this.cancel(e.sendId);break;case Y:if(this.status!==t.InterpreterStatus.Running)return;var u=e.activity;if(!this.state.activities[u.id||u.type])break;if(u.type===t.ActionTypes.Invoke){var h=F(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,p="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var v=d?w(d,i,o):void 0;if("string"==typeof f)return;var y=A(f)?f(i,o.data,{data:v,src:h,meta:u.meta}):f;if(!y)return;var g=void 0;j(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(u);break;case Z:this.stopChild(e.activity.id);break;case ot:var m=e.label,S=e.value;m?this.logger(m,S):this.logger(S)}},n.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]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),A(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(b(t))return this.spawnPromise(Promise.resolve(t),n);if(A(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,n);if(function(t){try{return"subscribe"in t&&A(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,n);if(j(t))return this.spawnMachine(t,e(e({},r),{id:n}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof t,'".'));var i,o},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},ee),r);a.sync&&o.onTransition((function(t){i.send(ht,{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(R(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=Zt(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,n){var r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(n),i.send(R(Pt(n,t),{origin:n})))}),(function(t){if(!o){i.removeChild(n);var e=kt(n,t);try{i.send(R(e,{origin:n}))}catch(t){i.devTools&&i.devTools.send(e,i.state),i.machine.strict&&i.stop()}}}));var a=e({id:n,send:function(){},subscribe:function(e,n,r){var i=U(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:n}},getSnapshot:function(){return r}},I);return this.children.set(n,a),a},n.prototype.spawnCallback=function(t,n){var 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(R(t,{origin:n}))}),(function(t){s.add(t)}))}catch(t){this.send(kt(n,t))}if(b(i))return this.spawnPromise(i,n);var u=e({id:n,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){return c.add(t),{unsubscribe:function(){c.delete(t)}}},stop:function(){a=!0,A(i)&&i()},toJSON:function(){return{id:n}},getSnapshot:function(){return r}},I);return this.children.set(n,u),u},n.prototype.spawnObservable=function(t,n){var r,i=this,o=t.subscribe((function(t){r=t,i.send(R(t,{origin:n}))}),(function(t){i.removeChild(n),i.send(R(kt(n,t),{origin:n}))}),(function(){i.removeChild(n),i.send(R(Pt(n),{origin:n}))})),a=e({id:n,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:n}}},I);return this.children.set(n,a),a},n.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},n.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)}},n.prototype.spawnEffect=function(t,n){this.children.set(t,e({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:n||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},I))},n.prototype.attachDev=function(){var t=Wt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Yt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[k]=function(){return this},n.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=re,n}();function re(t,e){return new ne(t,e)}var ie={raise:mt,send:St,sendParent:xt,sendTo:function(t,n,r){return St(n,e(e({},r),{to:t}))},sendUpdate:wt,log:function(t,e){return void 0===t&&(t=bt),{type:ot,label:e,expr:t}},cancel:_t,start:Tt,stop:Et,assign:Nt,after:At,done:Ot,respond:function(t,n){return St(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:It,escalate:function(n,r){return xt((function(t,e,r){return{type:ut,data:A(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=ne,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Bt(t,e,n)},t.State=Ct,t.StateNode=Bt,t.actions=ie,t.assign=Nt,t.createMachine=function(t,e){return new Bt(t,e)},t.createSchema=function(t){return t},t.doneInvoke=Pt,t.forwardTo=It,t.interpret=re,t.mapState=function(t,e){var n,i,o;try{for(var a=r(c(t)),s=a.next();!s.done;s=a.next()){var h=s.value;u(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Ct.from(t,t instanceof Ct?t.context:void 0);try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var h=i(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=u,t.send=St,t.sendParent=xt,t.sendUpdate=wt,t.spawn=function(t,n){var r=function(t){return O(t)?e(e({},ee),{name:t}):e(e(e({},ee),{name:D()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Rt(t,r.name)}(Vt[Vt.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var e=function(){return(e=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 n(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 r(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 i(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 o(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))}var a,s={};function c(t){return Object.keys(t)}function u(t,e,n){void 0===n&&(n=".");var r=l(t,n),i=l(e,n);return O(i)?!!O(r)&&i===r:O(r)?r in i:c(r).every((function(t){return t in i&&u(r[t],i[t])}))}function h(t){try{return O(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 f(t,e){try{return N(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function l(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:N(t)?d(t):"string"!=typeof t?t:d(f(t,e));var n}function d(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function p(t,e){for(var n={},r=c(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 i,o,a={};try{for(var s=r(c(t)),u=s.next();!u.done;u=s.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}var y=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[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 o}};function g(t){return t?O(t)?[[t]]:m(c(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?g(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function m(t){var e;return(e=[]).concat.apply(e,o([],i(t),!1))}function S(t){return N(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(t,e,n){var i,o;if(A(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];A(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function b(t){return t instanceof Promise||!(null===t||!A(t)&&"object"!=typeof t||!A(t.then))}function _(t,e){var n,o,a=i([[],[]],2),s=a[0],c=a[1];try{for(var u=r(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&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function T(t,e){return p(t.states,(function(t,n){if(t){var r=(O(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:T(t,r)}}}))}function E(t,e,n,i){return t?n.reduce((function(t,n){var o,a,s=n.assignment,u={state:i,action:n,_event:e},h={};if(A(s))h=s(t,e.data,u);else try{for(var f=r(c(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[d];h[d]=A(p)?p(t,e.data,u):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,h)}),t):t}function N(t){return Array.isArray(t)}function A(t){return"function"==typeof t}function O(t){return"string"==typeof t}function P(t,e){if(t)return O(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:A(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var k=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}(),I=((a={})[k]=function(){return this},a);function j(t){try{return"__xstatenode"in t}catch(t){return!1}}var C,V,D=function(){var t=0;return function(){return(++t).toString(16)}}();function L(t,n){return O(t)||"number"==typeof t?e({type:t},n):t}function R(t,n){if(!O(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return S(n).map((function(n){return void 0===n||"string"==typeof n||j(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function z(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=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 F(t){return"string"==typeof t?{type:t}:t}function U(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function B(t,e){return"".concat(t,":invocation[").concat(e,"]")}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",C.Choose="xstate.choose",(V=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",V.Internal="#_internal";var J=function(t){return"atomic"===t.type||"final"===t.type};function q(t){return c(t.states).map((function(e){return t.states[e]}))}function $(t){var e=[t];return J(t)?e:e.concat(m(q(t).map($)))}function X(t,e){var n,i,o,a,s,c,u,h,f=H(new Set(t)),l=new Set(e);try{for(var d=r(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=H(l);try{for(var g=r(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 S=(s=void 0,r(q(T))),x=S.next();!x.done;x=S.next()){var w=x.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{x&&!x.done&&(c=S.return)&&c.call(S)}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){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.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=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function H(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.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=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i}function G(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(J(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,H(X([t],e)))}function K(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function Q(t,e){return"compound"===e.type?q(e).some((function(e){return"final"===e.type&&K(t,e)})):"parallel"===e.type&&q(e).every((function(e){return Q(t,e)}))}function W(t){return new Set(m(t.map((function(t){return t.tags}))))}var Y=t.ActionTypes.Start,Z=t.ActionTypes.Stop,tt=t.ActionTypes.Raise,et=t.ActionTypes.Send,nt=t.ActionTypes.Cancel,rt=t.ActionTypes.NullEvent,it=t.ActionTypes.Assign,ot=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),at=t.ActionTypes.Init,st=t.ActionTypes.Invoke,ct=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),ut=t.ActionTypes.ErrorCustom,ht=t.ActionTypes.Update,ft=t.ActionTypes.Choose,lt=t.ActionTypes.Pure,dt=R({type:at});function pt(t,e){return e&&e[t]||void 0}function vt(t,n){var r;if(O(t)||"number"==typeof t)r=A(i=pt(t,n))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(A(t))r={type:t.name||t.toString(),exec:t};else{var i;if(A(i=pt(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return r}var yt=function(t,e){return t?(N(t)?t:[t]).map((function(t){return vt(t,e)})):[]};function gt(t){var n=vt(t);return e(e({id:O(t)?t:n.id},n),{type:n.type})}function mt(e){return O(e)?{type:tt,event:e}:St(e,{to:t.SpecialTargets.Internal})}function St(t,e){return{to:e?e.to:void 0,type:et,event:A(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:A(t)?t.name:h(t)}}function xt(n,r){return St(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function wt(){return xt(ht)}var bt=function(t,e){return{context:t,event:e}};var _t=function(t){return{type:nt,sendId:t}};function Tt(e){var n=gt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function Et(e){var n=A(e)?e:gt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var Nt=function(t){return{type:it,assignment:t}};function At(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Ot(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Pt(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function kt(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function It(t,n){return St((function(t,e){return e}),e(e({},n),{to:t}))}function jt(n,r,a,s,c,u){void 0===u&&(u=!1);var h=i(u?[[],c]:_(c,(function(t){return t.type===it})),2),f=h[0],l=h[1],d=f.length?E(a,s,f,r):a,p=u?[a]:void 0;return[m(l.map((function(a){var c;switch(a.type){case tt:return{type:tt,_event:R(a.event)};case et:return function(t,n,r,i){var o,a={_event:r},s=R(A(t.event)?t.event(n,r.data,a):t.event);if(O(t.delay)){var c=i&&i[t.delay];o=A(c)?c(n,r.data,a):c}else o=A(t.delay)?t.delay(n,r.data,a):t.delay;var u=A(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(a,d,s,n.options.delays);case ot:return function(t,n,r){return e(e({},t),{value:O(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(a,d,s);case ft:if(!(v=null===(c=a.conds.find((function(t){var e=P(t.cond,n.options.guards);return!e||z(n,e,d,s,r)})))||void 0===c?void 0:c.actions))return[];var h=i(jt(n,r,d,s,yt(x(v),n.options.actions),u),2),f=h[0],l=h[1];return d=l,null==p||p.push(d),f;case lt:var v;if(!(v=a.get(d,s.data)))return[];var y=i(jt(n,r,d,s,yt(x(v),n.options.actions),u),2),g=y[0],m=y[1];return d=m,null==p||p.push(d),g;case Z:return function(e,n,r){var i=A(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(a,d,s);case it:d=E(d,s,[a],r),null==p||p.push(d);break;default:var S=vt(a,n.options.actions),w=S.exec;if(w&&p){var b=p.length-1;S=e(e({},S),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];w.apply(void 0,o([p[b]],i(e),!1))}})}return S}})).filter((function(t){return!!t}))),d]}var Ct=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=s,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||s,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 o([],i(new Set(m(o([],i(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:dt,_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=dt;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="."),O(t))return[t];var r=c(t);return r.concat.apply(r,o([],i(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,r=(t.configuration,t.transitions,t.tags),i=(t.machine,n(t,["configuration","transitions","tags","machine"]));return e(e({},i),{tags:Array.from(r)})},t.prototype.matches=function(t){return u(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}(),Vt=[],Dt=function(t,e){Vt.push(t);var n=e(t);return Vt.pop(),n};function Lt(t){return e({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},I)}function Rt(t,e,n){var r=Lt(e);if(r.deferred=!0,j(t)){var i=r.state=Dt(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Mt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function zt(t){return e(e({type:st},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:st,src:Mt(t.src)})}})}var Ft={},Ut=function(t){return"#"===t[0]},Bt=function(){function a(t,n,s){var u,h=this;void 0===s&&(s="context"in t?t.context:void 0),this.config=t,this._context=s,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=this.options._parent,this.key=this.config.key||this.options._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||o([this.machine.key],i(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&&c(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?p(this.config.states,(function(t,n){var r,i=new a(t,{_parent:h,_key:n});return Object.assign(h.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Ft;var f=0;!function t(e){var n,i;e.order=f++;try{for(var o=r(q(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}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=x(this.config.entry||this.config.onEntry).map((function(t){return vt(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return vt(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var r,i;if(j(t)){var o=B(h.id,n);return h.machine.options.services=e(((r={})[o]=t,r),h.machine.options.services),zt({src:o,id:o})}if(O(t.src)){o=t.id||B(h.id,n);return zt(e(e({},t),{id:o,src:t.src}))}if(j(t.src)||A(t.src)){o=t.id||B(h.id,n);return h.machine.options.services=e(((i={})[o]=t.src,i),h.machine.options.services),zt(e(e({id:o},t),{src:o}))}var a=t.src;return zt(e(e({id:B(h.id,n)},t),{src:a}))})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return gt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||$(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){var r=this.options,i=r.actions,o=r.activities,s=r.guards,c=r.services,u=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},null!=n?n:this.context)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"context",{get:function(){return A(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(a.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:p(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}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.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(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.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},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=At(A(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(St(r,{delay:e})),t.onExit.push(_t(r)),r};return(N(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):m(c(n).map((function(t,i){var o=n[t],a=O(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Ct?t.value:l(t,this.delimiter);if(O(r)){var a=this.getStateNode(r).initial;return void 0!==a?this.getStateNodes(((e={})[r]=a,e)):[this,this.states[r]]}var s=c(r),u=[this];return u.push.apply(u,o([],i(m(s.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),u},a.prototype.handles=function(t){var e=h(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(X([],this.getStateNodes(t.value)));return new Ct(e(e({},t),{value:this.resolve(t.value),configuration:n,done:Q(n,this),tags:W(n)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=c(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var s=r(c(t)),u=s.next();!u.done;u=s.next()){var h=u.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}var d=c(a).map((function(t){return a[t]})),p=m(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=m(d.map((function(t){return t.entrySet}))),y=m(c(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:m(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:m(c(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return O(t)?this.transitionLeafNode(t,e,n):1===c(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,R(e))},a.prototype.next=function(t,e){var n,a,s,c=this,h=e.name,f=[],d=[];try{for(var p=r(this.getCandidates(h)),v=p.next();!v.done;v=p.next()){var g=v.value,S=g.cond,x=g.in,w=t.context,b=!x||(O(x)&&Ut(x)?t.matches(l(this.getStateNodeById(x).path,this.delimiter)):u(l(x,this.delimiter),y(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||z(this.machine,S,w,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(S.name||S.type,"' in transition for event '").concat(h,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(_&&b){void 0!==g.target&&(d=g.target),f.push.apply(f,o([],i(g.actions),!1)),s=g;break}}}catch(t){n={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}if(s){if(!d.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:f};var T=m(d.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),E=!!s.internal;return{transitions:[s],entrySet:E?[]:m(T.map((function(t){return c.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:T,source:t,actions:f}}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],n=t;n&&n!==this;)e.push(n),n=n.parent;return e.push(this),e},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=X([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?X(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){K(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=r(f),y=v.next();!y.done;y=v.next()){var g;K(l,g=y.value)&&!K(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}var S=m(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Ot(r.id,r.doneData),Ot(o.id,r.doneData?w(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&q(a).every((function(e){return Q(t.configuration,e)}))&&i.push(Ot(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var x=new Set(t.entrySet),b=new Set(t.exitSet),_=i([m(Array.from(x).map((function(t){return o(o([],i(t.activities.map((function(t){return Tt(t)}))),!1),i(t.onEntry),!1)}))).concat(S.map(mt)),m(Array.from(b).map((function(t){return o(o([],i(t.onExit),!1),i(t.activities.map((function(t){return Et(t)}))),!1)})))],2),T=_[0],E=_[1];return yt(E.concat(t.actions).concat(T),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,a,s=R(e);if(t instanceof Ct)r=void 0===n?t:this.resolveState(Ct.from(t,n));else{var c=O(t)?this.resolve(d(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Ct.from(c,u))}if(this.strict&&!this.events.includes(s.name)&&(a=s.name,!/^(done|error)\./.test(a)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(s.name,"'"));var h=this._transition(r.value,r,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=X([],this.getStateNodes(r.value)),l=h.configuration.length?X(f,h.configuration):f;return h.configuration=o([],i(l),!1),this.resolveTransition(h,r,r.context,s)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,a=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o([],i(a),!1)),t},a.prototype.resolveTransition=function(n,o,a,s){var u,h,f=this;void 0===s&&(s=dt);var l=n.configuration,d=!o||n.transitions.length>0,p=d?G(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=this.getActions(n,a,s,o),g=o?e({},o.activities):{};try{for(var m=r(y),S=m.next();!S.done;S=m.next()){var x=S.value;x.type===Y?g[x.activity.id||x.activity.type]=x:x.type===Z&&(g[x.activity.id||x.activity.type]=!1)}}catch(t){u={error:t}}finally{try{S&&!S.done&&(h=m.return)&&h.call(m)}finally{if(u)throw u.error}}var b,E,N=i(jt(this,o,a,s,y,this.machine.config.preserveActionOrder),2),A=N[0],P=N[1],k=i(_(A,(function(e){return e.type===tt||e.type===et&&e.to===t.SpecialTargets.Internal})),2),I=k[0],j=k[1],C=A.filter((function(t){var e;return t.type===Y&&(null===(e=t.activity)||void 0===e?void 0:e.type)===st})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=F(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?w(t.data,n,r):void 0,c=a?Rt(a,t.id,s):Lt(t.id);return c.meta=t,c}(e.activity,f.machine,P,s),t}),o?e({},o.children):{}),V=d?n.configuration:o?o.configuration:[],D=Q(V,this),L=new Ct({value:p||o.value,context:P,_event:s,_sessionid:o?o._sessionid:null,historyValue:p?v?(b=v,E=p,{current:E,states:T(b,E)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?j:[],activities:p?g:o?o.activities:{},events:[],configuration:V,transitions:n.transitions,children:C,done:D,tags:null==o?void 0:o.tags,machine:this}),R=a!==P;L.changed=s.name===ht||R;var M=L.history;M&&delete M.history;var z=!D&&(this._transient||l.some((function(t){return t._transient})));if(!(d||z&&""!==s.name))return L;var U=L;if(!D)for(z&&(U=this.resolveRaisedTransition(U,{type:rt},s));I.length;){var B=I.shift();U=this.resolveRaisedTransition(U,B._event,s)}var J=U.changed||(M?!!U.actions.length||R||typeof M.value!=typeof U.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(O(e)||O(n))return e===n;var r=c(e),i=c(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(U.value,M.value):void 0);return U.changed=J,U.history=M,U.tags=W(U.configuration),U},a.prototype.getStateNode=function(t){if(Ut(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},a.prototype.getStateNodeById=function(t){var e=Ut(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},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Ut(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=f(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Ft;switch(this.type){case"parallel":return p(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Ft}));case"compound":if(O(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return c(t).length?p(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Ft})):this.initialStateValue||{};default:return t||Ft}},a.prototype.getResolvedPath=function(t){if(Ut(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 f(t,this.delimiter)},Object.defineProperty(a.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||Ft}),(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=J(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}),a.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)},Object.defineProperty(a.prototype,"initialState",{get:function(){this._init();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(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=O(e.target)&&Ut(e.target)?d(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return J(this)?[this]:"compound"!==this.type||this.initial?m(g(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(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 o=this.getStateNode(n);if("history"===o.type)return o.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)},a.prototype.historyValue=function(t){if(c(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=O(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.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(g(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),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 O(s)?[n.getStateNode(s)]:m(g(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=m(c(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var s=r(c(o)),u=s.next();!u.done;u=s.next()){var h=o[u.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add("".concat(d))}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.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(a.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}),a.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!O(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))}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return O(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:yt(x(t.actions)),cond:P(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(n.id)})}});return s},a.prototype.formatTransitions=function(){var t,e,a,s=this;if(this.config.on)if(Array.isArray(this.config.on))a=this.config.on;else{var u=this.config.on,h=u["*"],f=void 0===h?[]:h,l=n(u,["*"]);a=m(c(l).map((function(t){return M(t,l[t])})).concat(M("*",f)))}else a=[];var d=this.config.always?M("",this.config.always):[],p=this.config.onDone?M(String(Ot(this.id)),this.config.onDone):[],v=m(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(M(String(Pt(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,o([],i(M(String(kt(t.id)),t.onError)),!1)),e}))),y=this.after,g=m(o(o(o(o([],i(p),!1),i(v),!1),i(a),!1),i(d),!1).map((function(t){return x(t).map((function(t){return s.formatTransition(t)}))})));try{for(var S=r(y),w=S.next();!w.done;w=S.next()){var b=w.value;g.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=S.return)&&e.call(S)}finally{if(t)throw t.error}}return g},a}();var Jt={deferEvents:!1},qt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Jt),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}(),$t=new Map,Xt=0,Ht=function(){return"x:".concat(Xt++)},Gt=function(t,e){return $t.set(t,e),t},Kt=function(t){return $t.get(t)},Qt=function(t){$t.delete(t)};function Wt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Yt(t){if(Wt()){var e=function(){var t=Wt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Zt(t,n){void 0===n&&(n={});var r,i=t.initialState,o=new Set,a=[],s=!1,c=(r={id:n.id,send:function(e){a.push(e),function(){if(!s){for(s=!0;a.length>0;){var e=a.shift();i=t.transition(i,e,u),o.forEach((function(t){return t.next(i)}))}s=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=U(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},e(e({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},I),r)),u={parent:n.parent,self:c,id:n.id||"anonymous",observers:o};return i=t.start?t.start(u):i,c}var te,ee={sync:!1,autoForward:!1};(te=t.InterpreterStatus||(t.InterpreterStatus={}))[te.NotStarted=0]="NotStarted",te[te.Running=1]="Running",te[te.Stopped=2]="Stopped";var ne=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new qt,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.init=this.start,this.send=function(e,n){if(N(e))return o.batch(e),o.state;var r=R(L(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(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:O(r)?o.children.get(r)||Kt(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ut?"".concat(kt(o.id)):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '".concat(r,"' from service '").concat(o.id,"'."))};var a=e(e({},n.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new qt({deferEvents:this.options.deferEvents}),this.sessionId=Ht()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Dt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t,t.event)}}catch(t){o={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}try{for(var y=r(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=Q(t.configuration||[],this.machine);if(this.state.configuration&&m){var S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),x=S&&S.doneData?w(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Pt(this.id,x))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.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},n.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;Gt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:Dt(this,(function(){return!O(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(Ct.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,dt)})),this},n.prototype.stop=function(){var e,n,a,s,u,h,f,l,d,p,v=this;try{for(var y=r(this.listeners),g=y.next();!g.done;g=y.next()){var m=g.value;this.listeners.delete(m)}}catch(t){e={error:t}}finally{try{g&&!g.done&&(n=y.return)&&n.call(y)}finally{if(e)throw e.error}}try{for(var S=r(this.stopListeners),x=S.next();!x.done;x=S.next()){(m=x.value)(),this.stopListeners.delete(m)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(s=S.return)&&s.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.contextListeners),b=w.next();!b.done;b=w.next()){m=b.value;this.contextListeners.delete(m)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}try{for(var _=r(this.doneListeners),T=_.next();!T.done;T=_.next()){m=T.value;this.doneListeners.delete(m)}}catch(t){f={error:t}}finally{try{T&&!T.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}if(!this.initialized)return this;o([],i(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;v.exec(a,v.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){A(t.stop)&&t.stop()}));try{for(var E=r(c(this.delayedEventsMap)),N=E.next();!N.done;N=E.next()){var O=N.value;this.clock.clearTimeout(this.delayedEventsMap[O])}}catch(t){d={error:t}}finally{try{N&&!N.done&&(p=E.return)&&p.call(E)}finally{if(d)throw d.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Qt(this.sessionId),this},n.prototype.batch=function(n){var a=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(n.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.'));this.scheduler.schedule((function(){var t,s,c=a.state,u=!1,h=[],f=function(t){var n=R(t);a.forward(n),c=Dt(a,(function(){return a.machine.transition(c,n)})),h.push.apply(h,o([],i(c.actions.map((function(t){return r=c,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i}))),!1)),u=u||!!c.changed};try{for(var l=r(n),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(t)throw t.error}}c.changed=u,c.actions=h,a.update(c,R(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=R(t);if(0===n.name.indexOf(ct)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ct)})))throw n.data.data;return Dt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.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{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||pt(e.type,r),s=A(a)?a:a?a.exec:e.exec;if(s)try{return s(i,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case et:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case nt:this.cancel(e.sendId);break;case Y:if(this.status!==t.InterpreterStatus.Running)return;var u=e.activity;if(!this.state.activities[u.id||u.type])break;if(u.type===t.ActionTypes.Invoke){var h=F(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,p="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var v=d?w(d,i,o):void 0;if("string"==typeof f)return;var y=A(f)?f(i,o.data,{data:v,src:h,meta:u.meta}):f;if(!y)return;var g=void 0;j(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(u);break;case Z:this.stopChild(e.activity.id);break;case ot:var m=e.label,S=e.value;m?this.logger(m,S):this.logger(S)}},n.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]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),A(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(b(t))return this.spawnPromise(Promise.resolve(t),n);if(A(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,n);if(function(t){try{return"subscribe"in t&&A(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,n);if(j(t))return this.spawnMachine(t,e(e({},r),{id:n}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof t,'".'));var i,o},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},ee),r);a.sync&&o.onTransition((function(t){i.send(ht,{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(R(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=Zt(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,n){var r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(n),i.send(R(Pt(n,t),{origin:n})))}),(function(t){if(!o){i.removeChild(n);var e=kt(n,t);try{i.send(R(e,{origin:n}))}catch(t){i.devTools&&i.devTools.send(e,i.state),i.machine.strict&&i.stop()}}}));var a=e({id:n,send:function(){},subscribe:function(e,n,r){var i=U(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:n}},getSnapshot:function(){return r}},I);return this.children.set(n,a),a},n.prototype.spawnCallback=function(t,n){var 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(R(t,{origin:n}))}),(function(t){s.add(t)}))}catch(t){this.send(kt(n,t))}if(b(i))return this.spawnPromise(i,n);var u=e({id:n,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){return c.add(t),{unsubscribe:function(){c.delete(t)}}},stop:function(){a=!0,A(i)&&i()},toJSON:function(){return{id:n}},getSnapshot:function(){return r}},I);return this.children.set(n,u),u},n.prototype.spawnObservable=function(t,n){var r,i=this,o=t.subscribe((function(t){r=t,i.send(R(t,{origin:n}))}),(function(t){i.removeChild(n),i.send(R(kt(n,t),{origin:n}))}),(function(){i.removeChild(n),i.send(R(Pt(n),{origin:n}))})),a=e({id:n,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:n}}},I);return this.children.set(n,a),a},n.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},n.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)}},n.prototype.spawnEffect=function(t,n){this.children.set(t,e({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:n||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},I))},n.prototype.attachDev=function(){var t=Wt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Yt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[k]=function(){return this},n.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=re,n}();function re(t,e){return new ne(t,e)}var ie={raise:mt,send:St,sendParent:xt,sendTo:function(t,n,r){return St(n,e(e({},r),{to:t}))},sendUpdate:wt,log:function(t,e){return void 0===t&&(t=bt),{type:ot,label:e,expr:t}},cancel:_t,start:Tt,stop:Et,assign:Nt,after:At,done:Ot,respond:function(t,n){return St(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:It,escalate:function(n,r){return xt((function(t,e,r){return{type:ut,data:A(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=ne,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Bt(t,e,n)},t.State=Ct,t.StateNode=Bt,t.actions=ie,t.assign=Nt,t.createMachine=function(t,e){return new Bt(t,e)},t.createSchema=function(t){return t},t.doneInvoke=Pt,t.forwardTo=It,t.interpret=re,t.mapState=function(t,e){var n,i,o;try{for(var a=r(c(t)),s=a.next();!s.done;s=a.next()){var h=s.value;u(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Ct.from(t,t instanceof Ct?t.context:void 0);try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var h=i(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=u,t.send=St,t.sendParent=xt,t.sendUpdate=wt,t.spawn=function(t,n){var r=function(t){return O(t)?e(e({},ee),{name:t}):e(e(e({},ee),{name:D()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Rt(t,r.name)}(Vt[Vt.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -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 L(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}var D,A;!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"}(D||(D={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(A||(A={}));const R=t=>"atomic"===t.type||"final"===t.type;function M(t){return e(t.states).map(e=>t.states[e])}function z(t){const e=[t];return R(t)?e:e.concat(d(M(t).map(z)))}function F(t,e){const i=B(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=B(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 M(t))"history"!==e.type&&(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 B(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 J(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(R(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,B(F([t],e)))}function U(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function q(t,e){return"compound"===e.type?M(e).some(e=>"final"===e.type&&U(t,e)):"parallel"===e.type&&M(e).every(e=>q(t,e))}function X(t){return new Set(d(t.map(t=>t.tags)))}const H=D.Start,G=D.Stop,K=D.Raise,Q=D.Send,W=D.Cancel,Y=D.NullEvent,Z=D.Assign,tt=(D.After,D.DoneState,D.Log),et=D.Init,it=D.Invoke,nt=(D.ErrorExecution,D.ErrorPlatform),st=D.ErrorCustom,ot=D.Update,rt=D.Choose,at=D.Pure,ct=T({type:et});function ht(t,e){return e&&e[t]||void 0}function ut(t,e){let i;if(w(t)||"number"==typeof t){const n=ht(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=ht(t.type,e);if(S(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 dt=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>ut(t,e))};function lt(t){const e=ut(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function ft(t){return w(t)?{type:K,event:t}:pt(t,{to:A.Internal})}function pt(t,e){return{to:e?e.to:void 0,type:Q,event:S(t)?t:N(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function gt(t,e){return pt(t,Object.assign(Object.assign({},e),{to:A.Parent}))}function vt(){return gt(ot)}const yt=(t,e)=>({context:t,event:e});const mt=t=>({type:W,sendId:t});function bt(t){const e=lt(t);return{type:D.Start,activity:e,exec:void 0}}function St(t){const e=S(t)?t:lt(t);return{type:D.Stop,activity:e,exec:void 0}}const wt=t=>({type:Z,assignment:t});function xt(t,e){const i=e?"#"+e:"";return`${D.After}(${t})${i}`}function Ot(t,e){const i=`${D.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function _t(t,e){const i=`${D.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function jt(t,e){const i=`${D.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Et(t,e){return pt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Nt(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Z);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[d(a.map(i=>{var s;switch(i.type){case K:return{type:K,_event:T(i.event)};case Q:return function(t,e,i,n){const s={_event:i},o=T(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(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})}(i,c,n,t.options.delays);case tt:return((t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(i,c,n);case rt:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||k(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,u]=Nt(t,e,c,n,dt(f(r),t.options.actions),o);return c=u,null==h||h.push(c),a}case at:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=Nt(t,e,c,n,dt(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case G:return function(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:D.Stop,activity:s}}(i,c,n);case Z:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=ut(i,t.options.actions);const{exec:a}=r;if(a&&h){const t=h.length-1;r=Object.assign(Object.assign({},r),{exec:(e,...i)=>{a(h[t],...i)}})}return r}}).filter(t=>!!t)),c]}function Tt(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 $t{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(d([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof $t)return t.context!==e?new $t({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 $t({value:t,context:e,_event:ct,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new $t(t)}static inert(t,e){if(t instanceof $t){if(!t.actions.length)return t;const i=ct;return new $t({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return $t.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=L(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(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 kt=[],Ct=(t,e)=>{kt.push(t);const i=e(t);return kt.pop(),i};function Pt(t){return Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})},_)}function Vt(t,e,i){const n=Pt(e);if(n.deferred=!0,j(t)){const e=n.state=Ct(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function It(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Lt(t){return Object.assign(Object.assign({type:it},t),{toJSON(){const e=L(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:it,src:It(t.src)})}})}const Dt={},At=t=>"#"===t[0];class Rt{constructor(t,i,n=("context"in t?t.context:void 0)){var s;this.config=t,this._context=n,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:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._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&&e(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?a(this.config.states,(t,e)=>{const i=new Rt(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Dt;let o=0;!function t(e){e.order=o++;for(const i of M(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=f(this.config.entry||this.config.onEntry).map(t=>ut(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ut(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(j(t)){const i=V(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Lt({src:i,id:i})}if(w(t.src)){const i=t.id||V(this.id,e);return Lt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(j(t.src)||S(t.src)){const i=t.id||V(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Lt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Lt(Object.assign(Object.assign({id:V(this.id,e)},t),{src:i}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>lt(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||z(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Rt(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 Rt(this.config,this.options,t)}get context(){return S(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:a(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 i=(t,e)=>{const i=xt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(pt(i,{delay:t})),this.onExit.push(mt(i)),i};return(b(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):d(e(t).map((e,n)=>{const s=t[e],o=w(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(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 i=t instanceof $t?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=[this];return s.push(...d(n.map(t=>this.getStateNode(t).getStateNodes(i[t])))),s}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(F([],this.getStateNodes(t.value)));return new $t(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:q(e,this),tags:X(e)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=d(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=d(o.map(t=>t.entrySet)),c=d(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:d(o.map(t=>t.exitSet)),configuration:c,source:i,actions:d(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}getTransitionData(t,e){return this._transition(t.value,t,T(e))}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:u,in:d}=c,l=t.context,f=!d||(w(d)&&At(d)?t.matches(o(this.getStateNodeById(d).path,this.delimiter)):i(o(d,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!u||k(this.machine,u,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${u.name||u.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=d(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),u=!!r.internal;return{transitions:[r],entrySet:u?[]:d(c.map(t=>this.nodesFromChild(t))),exitSet:u?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=F([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?F(s,t.configuration):s;for(const e of o)U(s,e)||t.entrySet.push(e);for(const e of s)U(o,e)&&!U(t.exitSet,e.parent)||t.exitSet.push(e);const r=d(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(Ot(n.id,n.doneData),Ot(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&M(r).every(e=>q(t.configuration,e))&&s.push(Ot(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,u]=[d(Array.from(a).map(t=>[...t.activities.map(t=>bt(t)),...t.onEntry])).concat(r.map(ft)),d(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>St(t))]))];return dt(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=T(e);let s;if(t instanceof $t)s=void 0===i?t:this.resolveState($t.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState($t.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=F([],this.getStateNodes(s.value)),h=a.configuration.length?F(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=ct,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?J(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=i?i.context:s,u=this.getActions(t,h,n,i),d=i?Object.assign({},i.activities):{};for(const t of u)t.type===H?d[t.activity.id||t.activity.type]=t:t.type===G&&(d[t.activity.id||t.activity.type]=!1);const[l,f]=Nt(this,i,h,n,u,this.machine.config.preserveActionOrder),[g,m]=v(l,t=>t.type===K||t.type===Q&&t.to===A.Internal),b=l.filter(t=>{var e;return t.type===H&&(null===(e=t.activity)||void 0===e?void 0:e.type)===it}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=C(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?Vt(r,t.id,a):Pt(t.id);return c.meta=t,c}(e.activity,this.machine,f,n),t),i?Object.assign({},i.children):{}),S=a?t.configuration:i?i.configuration:[],x=q(S,this),O=new $t({value:a||i.value,context:f,_event:n,_sessionid:i?i._sessionid:null,historyValue:a?c?(_=c,j=a,{current:j,states:y(_,j)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?m:[],activities:a?d:i?i.activities:{},events:[],configuration:S,transitions:t.transitions,children:b,done:x,tags:null==i?void 0:i.tags,machine:this});var _,j;const E=h!==f;O.changed=n.name===ot||E;const{history:N}=O;N&&delete N.history;const T=!x&&(this._transient||o.some(t=>t._transient));if(!(r||T&&""!==n.name))return O;let $=O;if(!x)for(T&&($=this.resolveRaisedTransition($,{type:Y},n));g.length;){const t=g.shift();$=this.resolveRaisedTransition($,t._event,n)}const k=$.changed||(N?!!$.actions.length||E||typeof N.value!=typeof $.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}($.value,N.value):void 0);return $.changed=k,$.history=N,$.tags=X($.configuration),$}getStateNode(t){if(At(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=At(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&&At(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(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||Dt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Dt);case"compound":if(w(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Dt):this.initialStateValue||{};default:return t||Dt}}getResolvedPath(t){if(At(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Dt,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=R(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){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();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=w(e.target)&&At(e.target)?r(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(R(this))return[this];if("compound"===this.type&&!this.initial)return[this];return d(u(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(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=w(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?d(u(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 w(i)?[e.getStateNode(i)]:d(u(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=d(e(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,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}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(!w(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 f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:dt(f(t.actions)),cond:x(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 i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=L(i,[n+""]);t=d(e(r).map(t=>$(t,r[t])).concat($("*",o)))}else t=[];const i=this.config.always?$("",this.config.always):[],n=this.config.onDone?$(String(Ot(this.id)),this.config.onDone):[],s=d(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(_t(t.id)),t.onDone)),t.onError&&e.push(...$(String(jt(t.id)),t.onError)),e})),o=this.after,r=d([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Mt(t,e,i=t.context){return new Rt(t,e,i)}function zt(t,e){return new Rt(t,e)}const Ft={deferEvents:!1};class Bt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Ft),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 Jt=new Map;let Ut=0;const qt={bookId:()=>"x:"+Ut++,register:(t,e)=>(Jt.set(t,e),t),get:t=>Jt.get(t),free(t){Jt.delete(t)}};function Xt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ht(t){if(!Xt())return;const e=function(){const t=Xt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function Gt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={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,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=P(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign(Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},_),a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const Kt={sync:!1,autoForward:!1};var Qt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Qt||(Qt={}));class Wt{constructor(t,e=Wt.defaultOptions){this.machine=t,this.scheduler=new Bt,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=Qt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(b(t))return this.batch(t),this.state;const i=T(N(t,e));if(this.status===Qt.Stopped)return this.state;if(this.status!==Qt.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,e)=>{const i=this.parent&&(e===A.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||qt.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===st?""+jt(this.id):t.name,origin:this.sessionId})):n.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Wt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new Bt({deferEvents:this.options.deferEvents}),this.sessionId=qt.bookId()}get initialState(){return this._initialState?this._initialState:Ct(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.options.execute&&this.execute(this.state),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);const i=q(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(_t(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Qt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Qt.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.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===Qt.Running)return this;qt.register(this.sessionId,this),this.initialized=!0,this.status=Qt.Running;const e=void 0===t?this.initialState:Ct(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState($t.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,ct)}),this}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.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Qt.Stopped,qt.free(this.sessionId),this}batch(t){if(this.status===Qt.NotStarted&&this.options.deferEvents);else if(this.status!==Qt.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.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=T(s);this.forward(t),e=Ct(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Tt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,T(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=T(t);if(0===e.name.indexOf(nt)&&!this.state.nextEvents.some(t=>0===t.indexOf(nt)))throw e.data.data;return Ct(this,()=>this.machine.transition(this.state,e))}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):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){const{context:n,_event:s}=e,o=t.exec||ht(t.type,i),r=S(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case Q:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case W:this.cancel(t.sendId);break;case H:{if(this.status!==Qt.Running)return;const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===D.Invoke){const t=C(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;if("string"==typeof i)return;let h,u=S(i)?i(n,s.data,{data:c,src:t,meta:e.meta}):i;if(!u)return;j(u)&&(u=c?u.withContext(c):u,h={autoForward:a}),this.spawn(u,o,h)}else this.spawnActivity(e);break}case G:this.stopChild(t.activity.id);break;case tt:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}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),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(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&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(j(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 Wt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Kt),e);n.sync&&i.onTransition(t=>{this.send(ot,{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(T(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=Gt(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(T(_t(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=jt(e,t);try{this.send(T(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>{const s=P(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},_);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(T(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(jt(e,t))}if(g(a))return this.spawnPromise(a,e);const c=Object.assign({id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o},_);return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(T(t,{origin:e}))},t=>{this.removeChild(e),this.send(T(jt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(T(_t(e),{origin:e}))}),s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})},_);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,Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})},_))}attachDev(){const t=Xt();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)}Ht(this)}}toJSON(){return{id:this.id}}[O](){return this}getSnapshot(){return this.status===Qt.NotStarted?this.initialState:this._state}}Wt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Wt.interpret=Zt;function Yt(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},Kt),{name:t}):Object.assign(Object.assign(Object.assign({},Kt),{name:E()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Vt(t,i.name))(kt[kt.length-1])}function Zt(t,e){return new Wt(t,e)}function te(t,e,i){const n=$t.from(t,t instanceof $t?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function ee(t){return t}const ie={raise:ft,send:pt,sendParent:gt,sendTo:function(t,e,i){return pt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:vt,log:function(t=yt,e){return{type:tt,label:e,expr:t}},cancel:mt,start:bt,stop:St,assign:wt,after:xt,done:Ot,respond:function(t,e){return pt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:Et,escalate:function(t,e){return gt((e,i,n)=>({type:st,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:A.Parent}))},choose:function(t){return{type:D.Choose,conds:t}},pure:function(t){return{type:D.Pure,get:t}}};export{D as ActionTypes,Wt as Interpreter,Qt as InterpreterStatus,Mt as Machine,A as SpecialTargets,$t as State,Rt as StateNode,ie as actions,wt as assign,zt as createMachine,ee as createSchema,_t as doneInvoke,Et as forwardTo,Zt as interpret,I as mapState,te as matchState,i as matchesState,pt as send,gt as sendParent,vt as sendUpdate,Yt as spawn};
15
+ ***************************************************************************** */function L(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}var D,A;!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"}(D||(D={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(A||(A={}));const R=t=>"atomic"===t.type||"final"===t.type;function M(t){return e(t.states).map(e=>t.states[e])}function z(t){const e=[t];return R(t)?e:e.concat(d(M(t).map(z)))}function F(t,e){const i=B(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=B(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 M(t))"history"!==e.type&&(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 B(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 J(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(R(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,B(F([t],e)))}function U(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function q(t,e){return"compound"===e.type?M(e).some(e=>"final"===e.type&&U(t,e)):"parallel"===e.type&&M(e).every(e=>q(t,e))}function X(t){return new Set(d(t.map(t=>t.tags)))}const H=D.Start,G=D.Stop,K=D.Raise,Q=D.Send,W=D.Cancel,Y=D.NullEvent,Z=D.Assign,tt=(D.After,D.DoneState,D.Log),et=D.Init,it=D.Invoke,nt=(D.ErrorExecution,D.ErrorPlatform),st=D.ErrorCustom,ot=D.Update,rt=D.Choose,at=D.Pure,ct=T({type:et});function ht(t,e){return e&&e[t]||void 0}function ut(t,e){let i;if(w(t)||"number"==typeof t){const n=ht(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=ht(t.type,e);if(S(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 dt=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>ut(t,e))};function lt(t){const e=ut(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function ft(t){return w(t)?{type:K,event:t}:pt(t,{to:A.Internal})}function pt(t,e){return{to:e?e.to:void 0,type:Q,event:S(t)?t:N(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function gt(t,e){return pt(t,Object.assign(Object.assign({},e),{to:A.Parent}))}function vt(){return gt(ot)}const yt=(t,e)=>({context:t,event:e});const mt=t=>({type:W,sendId:t});function bt(t){const e=lt(t);return{type:D.Start,activity:e,exec:void 0}}function St(t){const e=S(t)?t:lt(t);return{type:D.Stop,activity:e,exec:void 0}}const wt=t=>({type:Z,assignment:t});function xt(t,e){const i=e?"#"+e:"";return`${D.After}(${t})${i}`}function Ot(t,e){const i=`${D.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function _t(t,e){const i=`${D.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function jt(t,e){const i=`${D.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Et(t,e){return pt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Nt(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Z);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[d(a.map(i=>{var s;switch(i.type){case K:return{type:K,_event:T(i.event)};case Q:return function(t,e,i,n){const s={_event:i},o=T(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(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})}(i,c,n,t.options.delays);case tt:return((t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(i,c,n);case rt:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||k(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,u]=Nt(t,e,c,n,dt(f(r),t.options.actions),o);return c=u,null==h||h.push(c),a}case at:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=Nt(t,e,c,n,dt(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case G:return function(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:D.Stop,activity:s}}(i,c,n);case Z:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=ut(i,t.options.actions);const{exec:a}=r;if(a&&h){const t=h.length-1;r=Object.assign(Object.assign({},r),{exec:(e,...i)=>{a(h[t],...i)}})}return r}}).filter(t=>!!t)),c]}function Tt(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 $t{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(d([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof $t)return t.context!==e?new $t({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 $t({value:t,context:e,_event:ct,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new $t(t)}static inert(t,e){if(t instanceof $t){if(!t.actions.length)return t;const i=ct;return new $t({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return $t.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=L(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(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 kt=[],Ct=(t,e)=>{kt.push(t);const i=e(t);return kt.pop(),i};function Pt(t){return Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})},_)}function Vt(t,e,i){const n=Pt(e);if(n.deferred=!0,j(t)){const e=n.state=Ct(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function It(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Lt(t){return Object.assign(Object.assign({type:it},t),{toJSON(){const e=L(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:it,src:It(t.src)})}})}const Dt={},At=t=>"#"===t[0];class Rt{constructor(t,i,n=("context"in t?t.context:void 0)){var s;this.config=t,this._context=n,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:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._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&&e(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?a(this.config.states,(t,e)=>{const i=new Rt(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Dt;let o=0;!function t(e){e.order=o++;for(const i of M(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=f(this.config.entry||this.config.onEntry).map(t=>ut(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ut(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(j(t)){const i=V(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Lt({src:i,id:i})}if(w(t.src)){const i=t.id||V(this.id,e);return Lt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(j(t.src)||S(t.src)){const i=t.id||V(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Lt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Lt(Object.assign(Object.assign({id:V(this.id,e)},t),{src:i}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>lt(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||z(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Rt(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 Rt(this.config,this.options,t)}get context(){return S(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:a(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 i=(t,e)=>{const i=xt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(pt(i,{delay:t})),this.onExit.push(mt(i)),i};return(b(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):d(e(t).map((e,n)=>{const s=t[e],o=w(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(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 i=t instanceof $t?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=[this];return s.push(...d(n.map(t=>this.getStateNode(t).getStateNodes(i[t])))),s}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(F([],this.getStateNodes(t.value)));return new $t(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:q(e,this),tags:X(e)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=d(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=d(o.map(t=>t.entrySet)),c=d(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:d(o.map(t=>t.exitSet)),configuration:c,source:i,actions:d(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}getTransitionData(t,e){return this._transition(t.value,t,T(e))}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:u,in:d}=c,l=t.context,f=!d||(w(d)&&At(d)?t.matches(o(this.getStateNodeById(d).path,this.delimiter)):i(o(d,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!u||k(this.machine,u,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${u.name||u.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=d(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),u=!!r.internal;return{transitions:[r],entrySet:u?[]:d(c.map(t=>this.nodesFromChild(t))),exitSet:u?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=F([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?F(s,t.configuration):s;for(const e of o)U(s,e)||t.entrySet.push(e);for(const e of s)U(o,e)&&!U(t.exitSet,e.parent)||t.exitSet.push(e);const r=d(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(Ot(n.id,n.doneData),Ot(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&M(r).every(e=>q(t.configuration,e))&&s.push(Ot(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,u]=[d(Array.from(a).map(t=>[...t.activities.map(t=>bt(t)),...t.onEntry])).concat(r.map(ft)),d(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>St(t))]))];return dt(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=T(e);let s;if(t instanceof $t)s=void 0===i?t:this.resolveState($t.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState($t.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=F([],this.getStateNodes(s.value)),h=a.configuration.length?F(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,s.context,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n,s=ct){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?J(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=this.getActions(t,n,s,i),u=i?Object.assign({},i.activities):{};for(const t of h)t.type===H?u[t.activity.id||t.activity.type]=t:t.type===G&&(u[t.activity.id||t.activity.type]=!1);const[d,l]=Nt(this,i,n,s,h,this.machine.config.preserveActionOrder),[f,g]=v(d,t=>t.type===K||t.type===Q&&t.to===A.Internal),m=d.filter(t=>{var e;return t.type===H&&(null===(e=t.activity)||void 0===e?void 0:e.type)===it}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=C(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?Vt(r,t.id,a):Pt(t.id);return c.meta=t,c}(e.activity,this.machine,l,s),t),i?Object.assign({},i.children):{}),b=r?t.configuration:i?i.configuration:[],S=q(b,this),x=new $t({value:a||i.value,context:l,_event:s,_sessionid:i?i._sessionid:null,historyValue:a?c?(O=c,_=a,{current:_,states:y(O,_)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?g:[],activities:a?u:i?i.activities:{},events:[],configuration:b,transitions:t.transitions,children:m,done:S,tags:null==i?void 0:i.tags,machine:this});var O,_;const j=n!==l;x.changed=s.name===ot||j;const{history:E}=x;E&&delete E.history;const N=!S&&(this._transient||o.some(t=>t._transient));if(!(r||N&&""!==s.name))return x;let T=x;if(!S)for(N&&(T=this.resolveRaisedTransition(T,{type:Y},s));f.length;){const t=f.shift();T=this.resolveRaisedTransition(T,t._event,s)}const $=T.changed||(E?!!T.actions.length||j||typeof E.value!=typeof T.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}(T.value,E.value):void 0);return T.changed=$,T.history=E,T.tags=X(T.configuration),T}getStateNode(t){if(At(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=At(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&&At(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(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||Dt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Dt);case"compound":if(w(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Dt):this.initialStateValue||{};default:return t||Dt}}getResolvedPath(t){if(At(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Dt,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=R(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){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){this._init();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=w(e.target)&&At(e.target)?r(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(R(this))return[this];if("compound"===this.type&&!this.initial)return[this];return d(u(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(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=w(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?d(u(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 w(i)?[e.getStateNode(i)]:d(u(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=d(e(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,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}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(!w(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 f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:dt(f(t.actions)),cond:x(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 i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=L(i,[n+""]);t=d(e(r).map(t=>$(t,r[t])).concat($("*",o)))}else t=[];const i=this.config.always?$("",this.config.always):[],n=this.config.onDone?$(String(Ot(this.id)),this.config.onDone):[],s=d(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(_t(t.id)),t.onDone)),t.onError&&e.push(...$(String(jt(t.id)),t.onError)),e})),o=this.after,r=d([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Mt(t,e,i=t.context){return new Rt(t,e,i)}function zt(t,e){return new Rt(t,e)}const Ft={deferEvents:!1};class Bt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Ft),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 Jt=new Map;let Ut=0;const qt={bookId:()=>"x:"+Ut++,register:(t,e)=>(Jt.set(t,e),t),get:t=>Jt.get(t),free(t){Jt.delete(t)}};function Xt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ht(t){if(!Xt())return;const e=function(){const t=Xt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function Gt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={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,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=P(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign(Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},_),a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const Kt={sync:!1,autoForward:!1};var Qt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Qt||(Qt={}));class Wt{constructor(t,e=Wt.defaultOptions){this.machine=t,this.scheduler=new Bt,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=Qt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(b(t))return this.batch(t),this.state;const i=T(N(t,e));if(this.status===Qt.Stopped)return this.state;if(this.status!==Qt.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,e)=>{const i=this.parent&&(e===A.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||qt.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===st?""+jt(this.id):t.name,origin:this.sessionId})):n.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Wt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new Bt({deferEvents:this.options.deferEvents}),this.sessionId=qt.bookId()}get initialState(){return this._initialState?this._initialState:Ct(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.options.execute&&this.execute(this.state),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);const i=q(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(_t(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Qt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Qt.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.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===Qt.Running)return this;qt.register(this.sessionId,this),this.initialized=!0,this.status=Qt.Running;const e=void 0===t?this.initialState:Ct(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState($t.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,ct)}),this}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.state.configuration].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Qt.Stopped,qt.free(this.sessionId),this}batch(t){if(this.status===Qt.NotStarted&&this.options.deferEvents);else if(this.status!==Qt.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.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=T(s);this.forward(t),e=Ct(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Tt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,T(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=T(t);if(0===e.name.indexOf(nt)&&!this.state.nextEvents.some(t=>0===t.indexOf(nt)))throw e.data.data;return Ct(this,()=>this.machine.transition(this.state,e))}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):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){const{context:n,_event:s}=e,o=t.exec||ht(t.type,i),r=S(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case Q:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case W:this.cancel(t.sendId);break;case H:{if(this.status!==Qt.Running)return;const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===D.Invoke){const t=C(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;if("string"==typeof i)return;let h,u=S(i)?i(n,s.data,{data:c,src:t,meta:e.meta}):i;if(!u)return;j(u)&&(u=c?u.withContext(c):u,h={autoForward:a}),this.spawn(u,o,h)}else this.spawnActivity(e);break}case G:this.stopChild(t.activity.id);break;case tt:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}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),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(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&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(j(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 Wt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Kt),e);n.sync&&i.onTransition(t=>{this.send(ot,{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(T(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=Gt(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(T(_t(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=jt(e,t);try{this.send(T(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>{const s=P(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},_);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(T(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(jt(e,t))}if(g(a))return this.spawnPromise(a,e);const c=Object.assign({id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o},_);return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(T(t,{origin:e}))},t=>{this.removeChild(e),this.send(T(jt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(T(_t(e),{origin:e}))}),s=Object.assign({id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})},_);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,Object.assign({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})},_))}attachDev(){const t=Xt();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)}Ht(this)}}toJSON(){return{id:this.id}}[O](){return this}getSnapshot(){return this.status===Qt.NotStarted?this.initialState:this._state}}Wt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Wt.interpret=Zt;function Yt(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},Kt),{name:t}):Object.assign(Object.assign(Object.assign({},Kt),{name:E()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Vt(t,i.name))(kt[kt.length-1])}function Zt(t,e){return new Wt(t,e)}function te(t,e,i){const n=$t.from(t,t instanceof $t?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function ee(t){return t}const ie={raise:ft,send:pt,sendParent:gt,sendTo:function(t,e,i){return pt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:vt,log:function(t=yt,e){return{type:tt,label:e,expr:t}},cancel:mt,start:bt,stop:St,assign:wt,after:xt,done:Ot,respond:function(t,e){return pt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:Et,escalate:function(t,e){return gt((e,i,n)=>({type:st,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:A.Parent}))},choose:function(t){return{type:D.Choose,conds:t}},pure:function(t){return{type:D.Pure,get:t}}};export{D as ActionTypes,Wt as Interpreter,Qt as InterpreterStatus,Mt as Machine,A as SpecialTargets,$t as State,Rt as StateNode,ie as actions,wt as assign,zt as createMachine,ee as createSchema,_t as doneInvoke,Et as forwardTo,Zt as interpret,I as mapState,te as matchState,i as matchesState,pt as send,gt as sendParent,vt as sendUpdate,Yt as spawn};
package/es/StateNode.js CHANGED
@@ -823,7 +823,7 @@ function () {
823
823
  var prevConfig = getConfiguration([], this.getStateNodes(currentState.value));
824
824
  var resolvedConfig = stateTransition.configuration.length ? getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
825
825
  stateTransition.configuration = __spreadArray([], __read(resolvedConfig), false);
826
- return this.resolveTransition(stateTransition, currentState, _event);
826
+ return this.resolveTransition(stateTransition, currentState, currentState.context, _event);
827
827
  };
828
828
 
829
829
  StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
@@ -841,7 +841,7 @@ function () {
841
841
  return state;
842
842
  };
843
843
 
844
- StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
844
+ StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, _event) {
845
845
  var e_6, _a;
846
846
 
847
847
  var _this = this;
@@ -850,10 +850,6 @@ function () {
850
850
  _event = initEvent;
851
851
  }
852
852
 
853
- if (context === void 0) {
854
- context = this.machine.context;
855
- }
856
-
857
853
  var configuration = stateTransition.configuration; // Transition will "apply" if:
858
854
  // - this is the initial state (there is no current state)
859
855
  // - OR there are transitions
@@ -861,8 +857,7 @@ function () {
861
857
  var willTransition = !currentState || stateTransition.transitions.length > 0;
862
858
  var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
863
859
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
864
- var currentContext = currentState ? currentState.context : context;
865
- var actions = this.getActions(stateTransition, currentContext, _event, currentState);
860
+ var actions = this.getActions(stateTransition, context, _event, currentState);
866
861
  var activities = currentState ? __assign({}, currentState.activities) : {};
867
862
 
868
863
  try {
@@ -887,7 +882,7 @@ function () {
887
882
  }
888
883
  }
889
884
 
890
- var _b = __read(resolveActions(this, currentState, currentContext, _event, actions, this.machine.config.preserveActionOrder), 2),
885
+ var _b = __read(resolveActions(this, currentState, context, _event, actions, this.machine.config.preserveActionOrder), 2),
891
886
  resolvedActions = _b[0],
892
887
  updatedContext = _b[1];
893
888
 
@@ -906,7 +901,7 @@ function () {
906
901
  acc[action.activity.id] = createInvocableActor(action.activity, _this.machine, updatedContext, _event);
907
902
  return acc;
908
903
  }, currentState ? __assign({}, currentState.children) : {});
909
- var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
904
+ var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
910
905
  var isDone = isInFinalState(resolvedConfiguration, this);
911
906
  var nextState = new State({
912
907
  value: resolvedStateValue || currentState.value,
@@ -926,7 +921,7 @@ function () {
926
921
  tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
927
922
  machine: this
928
923
  });
929
- var didUpdateContext = currentContext !== updatedContext;
924
+ var didUpdateContext = context !== updatedContext;
930
925
  nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
931
926
 
932
927
  var history = nextState.history;
@@ -1154,7 +1149,7 @@ function () {
1154
1149
  transitions: [],
1155
1150
  source: undefined,
1156
1151
  actions: []
1157
- }, undefined, undefined, context);
1152
+ }, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
1158
1153
  };
1159
1154
 
1160
1155
  Object.defineProperty(StateNode.prototype, "initialState", {
package/es/index.d.ts CHANGED
@@ -29,4 +29,9 @@ declare const actions: {
29
29
  };
30
30
  export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
31
31
  export * from './types';
32
+ declare global {
33
+ interface SymbolConstructor {
34
+ readonly observable: symbol;
35
+ }
36
+ }
32
37
  //# sourceMappingURL=index.d.ts.map
package/es/interpreter.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __values, __assign, __spreadArray, __read } from './_virtual/_tslib.js';
1
+ import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
2
2
  import { IS_PRODUCTION } from './environment.js';
3
3
  import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, interopSymbols, symbolObservable, isArray, toEventObject, isString, isActor, toObserver, uniqueId } from './utils.js';
4
4
  import { ActionTypes, SpecialTargets } from './types.js';
@@ -558,7 +558,9 @@ function () {
558
558
  return this;
559
559
  }
560
560
 
561
- this.state.configuration.forEach(function (stateNode) {
561
+ __spreadArray([], __read(this.state.configuration), false).sort(function (a, b) {
562
+ return b.order - a.order;
563
+ }).forEach(function (stateNode) {
562
564
  var e_11, _a;
563
565
 
564
566
  try {
@@ -580,6 +582,7 @@ function () {
580
582
  }
581
583
  }); // Stop all children
582
584
 
585
+
583
586
  this.children.forEach(function (child) {
584
587
  if (isFunction(child.stop)) {
585
588
  child.stop();
package/es/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior } from './types';
3
2
  import { StateNode } from './StateNode';
4
3
  import { State } from './State';
package/lib/StateNode.js CHANGED
@@ -827,7 +827,7 @@ function () {
827
827
  var prevConfig = stateUtils.getConfiguration([], this.getStateNodes(currentState.value));
828
828
  var resolvedConfig = stateTransition.configuration.length ? stateUtils.getConfiguration(prevConfig, stateTransition.configuration) : prevConfig;
829
829
  stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
830
- return this.resolveTransition(stateTransition, currentState, _event);
830
+ return this.resolveTransition(stateTransition, currentState, currentState.context, _event);
831
831
  };
832
832
 
833
833
  StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
@@ -845,7 +845,7 @@ function () {
845
845
  return state;
846
846
  };
847
847
 
848
- StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
848
+ StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, _event) {
849
849
  var e_6, _a;
850
850
 
851
851
  var _this = this;
@@ -854,10 +854,6 @@ function () {
854
854
  _event = actions.initEvent;
855
855
  }
856
856
 
857
- if (context === void 0) {
858
- context = this.machine.context;
859
- }
860
-
861
857
  var configuration = stateTransition.configuration; // Transition will "apply" if:
862
858
  // - this is the initial state (there is no current state)
863
859
  // - OR there are transitions
@@ -865,8 +861,7 @@ function () {
865
861
  var willTransition = !currentState || stateTransition.transitions.length > 0;
866
862
  var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
867
863
  var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
868
- var currentContext = currentState ? currentState.context : context;
869
- var actions$1 = this.getActions(stateTransition, currentContext, _event, currentState);
864
+ var actions$1 = this.getActions(stateTransition, context, _event, currentState);
870
865
  var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
871
866
 
872
867
  try {
@@ -891,7 +886,7 @@ function () {
891
886
  }
892
887
  }
893
888
 
894
- var _b = _tslib.__read(actions.resolveActions(this, currentState, currentContext, _event, actions$1, this.machine.config.preserveActionOrder), 2),
889
+ var _b = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actions$1, this.machine.config.preserveActionOrder), 2),
895
890
  resolvedActions = _b[0],
896
891
  updatedContext = _b[1];
897
892
 
@@ -910,7 +905,7 @@ function () {
910
905
  acc[action.activity.id] = Actor.createInvocableActor(action.activity, _this.machine, updatedContext, _event);
911
906
  return acc;
912
907
  }, currentState ? _tslib.__assign({}, currentState.children) : {});
913
- var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
908
+ var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
914
909
  var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
915
910
  var nextState = new State.State({
916
911
  value: resolvedStateValue || currentState.value,
@@ -930,7 +925,7 @@ function () {
930
925
  tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
931
926
  machine: this
932
927
  });
933
- var didUpdateContext = currentContext !== updatedContext;
928
+ var didUpdateContext = context !== updatedContext;
934
929
  nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
935
930
 
936
931
  var history = nextState.history;
@@ -1158,7 +1153,7 @@ function () {
1158
1153
  transitions: [],
1159
1154
  source: undefined,
1160
1155
  actions: []
1161
- }, undefined, undefined, context);
1156
+ }, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
1162
1157
  };
1163
1158
 
1164
1159
  Object.defineProperty(StateNode.prototype, "initialState", {
package/lib/index.d.ts CHANGED
@@ -29,4 +29,9 @@ declare const actions: {
29
29
  };
30
30
  export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
31
31
  export * from './types';
32
+ declare global {
33
+ interface SymbolConstructor {
34
+ readonly observable: symbol;
35
+ }
36
+ }
32
37
  //# sourceMappingURL=index.d.ts.map
@@ -561,7 +561,9 @@ function () {
561
561
  return this;
562
562
  }
563
563
 
564
- this.state.configuration.forEach(function (stateNode) {
564
+ _tslib.__spreadArray([], _tslib.__read(this.state.configuration), false).sort(function (a, b) {
565
+ return b.order - a.order;
566
+ }).forEach(function (stateNode) {
565
567
  var e_11, _a;
566
568
 
567
569
  try {
@@ -583,6 +585,7 @@ function () {
583
585
  }
584
586
  }); // Stop all children
585
587
 
588
+
586
589
  this.children.forEach(function (child) {
587
590
  if (utils.isFunction(child.stop)) {
588
591
  child.stop();
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior } from './types';
3
2
  import { StateNode } from './StateNode';
4
3
  import { State } from './State';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.28.0",
3
+ "version": "4.28.1",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",