text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).XState={})}(this,function(t){"use strict";var e,n,r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}function o(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(a(arguments[e]));return t}(e=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var c=".",u={};var h=function(){function e(t){this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this.event=t.event,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=t.meta||{},this.events=t.events||[],Object.defineProperty(this,"tree",{value:t.tree,enumerable:!1})}return e.from=function(n,r){return n instanceof e?n.context!==r?new e({value:n.value,context:r,event:n.event,historyValue:n.historyValue,history:n.history,actions:[],activities:n.activities,meta:{},events:[],tree:n.tree}):n:new e({value:n,context:r,event:{type:t.ActionTypes.Init},historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[]})},e.create=function(t){return new e(t)},e.inert=function(n,r){if(n instanceof e){if(!n.actions.length)return n;var i={type:t.ActionTypes.Init};return new e({value:n.value,context:r,event:i,historyValue:n.historyValue,history:n.history,activities:n.activities,tree:n.tree})}return e.from(n,r)},Object.defineProperty(e.prototype,"inert",{get:function(){return e.inert(this,this.context)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nextEvents",{get:function(){return this.tree?this.tree.nextEvents:[]},enumerable:!0,configurable:!0}),e.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),ft(t))return[t];var r=J(t);return r.concat.apply(r,s(r.map(function(r){return n.toStrings(t[r]).map(function(t){return r+e+t})})))},e.prototype.matches=function(t){return K(t,this.value)},e}(),l=t.ActionTypes.Start,d=t.ActionTypes.Stop,f=t.ActionTypes.Raise,p=t.ActionTypes.Send,v=t.ActionTypes.Cancel,y=t.ActionTypes.NullEvent,m=t.ActionTypes.Assign,g=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),x=t.ActionTypes.Init,w=t.ActionTypes.Invoke,S=t.ActionTypes.ErrorExecution,b={type:x};function E(t,e){if(ft(t)||"number"==typeof t){var n={type:t};return e&&Object.assign(n,e),n}return t}function N(t,e){if(e){var n=e[t];if(n)return dt(n),n}}function T(t,e){var n;if(ft(t)||"number"==typeof t){var o=N(t,e);n=dt(o)?{type:t,exec:o}:o||{type:t,exec:void 0}}else if(dt(t))n={type:t.name||t.toString(),exec:t};else{if(dt(o=N(t.type,e)))n=r({},t,{exec:o});else if(o){var a=t.type,s=i(t,["type"]);n=r({type:a},o,s)}else n=t}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1,configurable:!0}),n}function O(t){var e=T(t);return r({id:ft(t)?t:e.id},e,{type:e.type})}function k(t){return{type:f,event:t}}function P(t,e){return{to:e?e.to:void 0,type:p,event:dt(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:dt(t)?t.name:Q(t)}}function A(e,n){return P(e,r({},n,{to:t.SpecialTargets.Parent}))}var j=function(t){return{type:v,sendId:t}};function V(e){var n=O(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function _(e){var n=O(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var I=function(t){return{type:m,assignment:t}};function L(e,n){var r=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+r}function D(e,n){var r=t.ActionTypes.DoneState+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function C(e,n){var r=t.ActionTypes.DoneInvoke+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function M(e,n){return{src:n,type:t.ActionTypes.ErrorExecution,data:e}}var z={resolved:!1},R=function(){function t(e,n,i){var o;void 0===i&&(i=z),this.stateNode=e,this.stateValue=n,this.nodes=n?ft(n)?((o={})[n]=new t(e.getStateNode(n),void 0),o):$(n,function(n,r){return new t(e.getStateNode(r),n)}):{};var a=r({},z,i);this.isResolved=a.resolved}return Object.defineProperty(t.prototype,"done",{get:function(){var t=this;switch(this.stateNode.type){case"final":return!0;case"compound":return"final"===this.nodes[J(this.nodes)[0]].stateNode.type;case"parallel":return J(this.nodes).every(function(e){return t.nodes[e].done});default:return!1}},enumerable:!0,configurable:!0}),t.prototype.getDoneData=function(t,e){if(this.done&&"compound"===this.stateNode.type){var n=this.nodes[J(this.nodes)[0]];if(!n.stateNode.data)return;return ot(n.stateNode.data,t,e)}},Object.defineProperty(t.prototype,"atomicNodes",{get:function(){var t=this;return"atomic"===this.stateNode.type||"final"===this.stateNode.type?[this.stateNode]:rt(J(this.value).map(function(e){return t.value[e].atomicNodes}))},enumerable:!0,configurable:!0}),t.prototype.getDoneEvents=function(t){var e=this;if(!t||!t.size)return[];if(t.has(this.stateNode)&&"final"===this.stateNode.type)return[D(this.stateNode.id,this.stateNode.data)];var n=rt(J(this.nodes).map(function(n){return e.nodes[n].getDoneEvents(t)}));if("parallel"===this.stateNode.type){var r=J(this.nodes).every(function(t){return e.nodes[t].done});return n&&r?n.concat(D(this.stateNode.id)):n}if(!this.done||!n.length)return n;var i=1===n.length?n[0].data:void 0;return n.concat(D(this.stateNode.id,i))},Object.defineProperty(t.prototype,"resolved",{get:function(){return new t(this.stateNode,this.stateNode.resolve(this.value),{resolved:!0})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return nt(this.value)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absolute",{get:function(){for(var e=this.stateValue,n={},r=n,i=0;i<this.stateNode.path.length;i++){var o=this.stateNode.path[i];i===this.stateNode.path.length-1?r[o]=e:(r[o]={},r=r[o])}return new t(this.stateNode.machine,n)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nextEvents",{get:function(){var t=this,e=this.stateNode.ownEvents,n=rt(J(this.nodes).map(function(e){return t.nodes[e].nextEvents}));return s(new Set(n.concat(e)))},enumerable:!0,configurable:!0}),t.prototype.clone=function(){return new t(this.stateNode,this.value)},t.prototype.combine=function(t){var e,n,r;if(t.stateNode!==this.stateNode)throw new Error("Cannot combine distinct trees");if("compound"===this.stateNode.type){var i=void 0;if(J(this.nodes).length&&J(t.nodes).length){var a=J(this.nodes)[0];return(e={})[a]=this.nodes[a].combine(t.nodes[a]),i=e,(c=this.clone()).nodes=i,c}return i=Object.assign({},this.nodes,t.nodes),(c=this.clone()).nodes=i,c}if("parallel"===this.stateNode.type){var c,u=new Set(s(J(this.nodes),J(t.nodes)));i={};try{for(var h=o(u),l=h.next();!l.done;l=h.next()){var d=l.value;this.nodes[d]&&t.nodes[d]?i[d]=this.nodes[d].combine(t.nodes[d]):i[d]=this.nodes[d]||t.nodes[d]}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}return(c=this.clone()).nodes=i,c}return this},Object.defineProperty(t.prototype,"value",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return $(this.nodes,function(t){return t.value});if("compound"===this.stateNode.type){if(0===J(this.nodes).length)return{};var t=this.nodes[J(this.nodes)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:$(this.nodes,function(t){return t.value})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return K(t,this.value)},t.prototype.getEntryExitStates=function(t,e){var n,r,i=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var a={exit:[],entry:[]},c=J(this.nodes)[0],u=J(t.nodes)[0];return c!==u?(a.exit=t.nodes[u].getExitStates(),a.entry=this.nodes[c].getEntryStates()):a=this.nodes[c].getEntryExitStates(t.nodes[u],e),e&&e.has(this.stateNode)&&(a.exit.push(this.stateNode),a.entry.unshift(this.stateNode)),a;case"parallel":var h=J(this.nodes).map(function(n){return i.nodes[n].getEntryExitStates(t.nodes[n],e)}),l={exit:[],entry:[]};try{for(var d=o(h),f=d.next();!f.done;f=d.next()){var p=f.value;l.exit=s(l.exit,p.exit),l.entry=s(l.entry,p.entry)}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}return e&&e.has(this.stateNode)&&(l.exit.push(this.stateNode),l.entry.unshift(this.stateNode)),l;case"atomic":default:return e&&e.has(this.stateNode)?{exit:[this.stateNode],entry:[this.stateNode]}:{exit:[],entry:[]}}},t.prototype.getEntryStates=function(){var t=this;return this.nodes?[this.stateNode].concat(rt(J(this.nodes).map(function(e){return t.nodes[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.nodes?rt(J(this.nodes).map(function(e){return t.nodes[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),F=".",G="",U={},q=function(t){return"#"===t[0]},B=function(){return{actions:{},guards:{},services:{},activities:{},delays:{},updater:ut}},X=function(){function e(t,n,i){var o=this;this._config=t,this.context=i,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.options=r({},B(),n),this.key=t.key||t.id||"(machine)",this.parent=t.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=t.delimiter||(this.parent?this.parent.delimiter:F),this.id=t.id||(this.machine?s([this.machine.key],this.path).join(this.delimiter):this.key),this.version=this.parent?this.parent.version:t.version,this.type=t.type||(t.parallel?"parallel":t.states&&J(t.states).length?"compound":t.history?"history":"atomic"),ht(!("parallel"in t),'The "parallel" property is deprecated and will be removed in version 4.1. '+(t.parallel?"Replace with `type: 'parallel'`":"Use `type: '"+this.type+"'`")+" in the config for state node '"+this.id+"' instead."),this.initial=t.initial,this.order=t.order||-1,this.states=t.states?$(t.states,function(t,n,i,a){var s,c=new e(r({},t,{key:n,order:void 0===t.order?a:t.order,parent:o}));return Object.assign(o.idMap,r(((s={})[c.id]=c,s),c.idMap)),c}):U,this.history=!0===t.history?"shallow":t.history||!1,this.transient=!(!t.on||!t.on[G]),this.strict=!!t.strict,this.onEntry=it(t.entry||t.onEntry).map(function(t){return T(t)}),this.onExit=it(t.exit||t.onExit).map(function(t){return T(t)}),this.meta=t.meta,this.data="final"===this.type?t.data:void 0,this.invoke=it(t.invoke).map(function(t,n){var i,a;if(t instanceof e)return(o.parent||o).options.services=r(((i={})[t.id]=t,i),(o.parent||o).options.services),{type:w,src:t.id,id:t.id};if("string"!=typeof t.src){var s=o.id+":invocation["+n+"]";return o.machine.options.services=r(((a={})[s]=t.src,a),o.machine.options.services),r({type:w,id:s},t,{src:s})}return r({},t,{type:w,id:t.id||t.src,src:t.src})}),this.activities=it(t.activities).concat(this.invoke).map(function(t){return O(t)}),this.after=this.getDelayedTransitions()}return e.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var i=this.options,o=i.actions,a=i.activities,s=i.guards,c=i.services,u=i.delays;return new e(this.definition,{actions:r({},o,t.actions),activities:r({},a,t.activities),guards:r({},s,t.guards),services:r({},c,t.services),delays:r({},u,t.delays)},n)},e.prototype.withContext=function(t){return new e(this.definition,this.options,t)},Object.defineProperty(e.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,type:this.type,initial:this.initial,history:this.history,states:$(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"config",{get:function(){var t=this._config;t.parent;return i(t,["parent"])},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"on",{get:function(){return this.formatTransitions()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){var t=this;return rt(J(this.on).map(function(e){return t.on[e]}))},enumerable:!0,configurable:!0}),e.prototype.getDelayedTransitions=function(){var t=this;if(this.after)return this.after;var e=this.config.after;if(!e)return[];if(lt(e))return e.map(function(e,n){var i,o=e.delay;dt(o)?(i=t.id+":delay["+n+"]",t.options.delays[i]=o):i=o;var a=L(i,t.id);return t.onEntry.push(P(a,{delay:o})),t.onExit.push(j(a)),r({event:a},e,{cond:e.cond?t.toGuard(e.cond):void 0,actions:it(e.actions).map(function(t){return T(t)})})});var n=rt(J(e).map(function(n){var i=e[n],o=isNaN(+n)?n:+n,a=L(o,t.id);return t.onEntry.push(P(a,{delay:o})),t.onExit.push(j(a)),ft(i)?[{target:i,delay:o,event:a,actions:[]}]:it(i).map(function(e){return r({event:a,delay:o},e,{cond:e.cond?t.toGuard(e.cond):void 0,actions:it(e.actions).map(function(t){return T(t)})})})}));return n.sort(function(t,e){return ft(t)||ft(e)?0:+t.delay-+e.delay}),n},e.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof h?t.value:Y(t,this.delimiter);if(ft(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=J(r);return o.map(function(t){return n.getStateNode(t)}).concat(o.reduce(function(t,e){var i=n.getStateNode(e).getStateNodes(r[e]);return t.concat(i)},[]))},e.prototype.handles=function(t){var e=Q(t);return-1!==this.events.indexOf(e)},e.prototype.resolveState=function(t){var e=this.getStateTree(t.value),n=this.resolve(t.value);return new h({value:n,context:t.context,event:t.event,historyValue:t.historyValue,history:t.history,actions:t.actions,activities:t.activities,meta:t.meta,events:t.events,tree:e})},e.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);if(!r.tree){var i=this.next(e,n),o=i.reentryStates,a=i.actions;return{tree:i.tree,source:e,reentryStates:o,actions:a}}return r},e.prototype.transitionCompoundNode=function(t,e,n){var r=J(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);if(!i.tree){var o=this.next(e,n),a=o.reentryStates,s=o.actions;return{tree:o.tree,source:e,reentryStates:a,actions:s}}return i},e.prototype.transitionParallelNode=function(t,e,n){var r,i,a=this,c={};try{for(var u=o(J(t)),h=u.next();!h.done;h=u.next()){var l=h.value,d=t[l];if(d){var f=this.getStateNode(l)._transition(d,e,n);f.tree,c[l]=f}}}catch(t){r={error:t}}finally{try{h&&!h.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}if(!J(c).some(function(t){return void 0!==c[t].tree})){var p=this.next(e,n),v=p.reentryStates,y=p.actions;return{tree:p.tree,source:e,reentryStates:v,actions:y}}var m=J(c).map(function(t){return c[t].tree}).filter(function(t){return void 0!==t}).reduce(function(t,e){return t.combine(e)});return 1!==m.paths.length||K(Y(this.path,this.delimiter),m.value)?{tree:J(c).map(function(t){var n=c[t],r=et(a.path)(n.tree?n.tree.value:e.value||e.value)[t];return new R(a.getStateNode(t),r).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,reentryStates:J(c).reduce(function(t,e){var n=c[e],r=n.tree,i=n.reentryStates;return r&&i?new Set(s(Array.from(t),Array.from(i))):t},new Set),actions:rt(J(c).map(function(t){return c[t].actions}))}:{tree:m,source:e,reentryStates:J(c).map(function(t){return c[t].reentryStates}).reduce(function(t,e){var n,r;if(!e)return t;try{for(var i=o(e),a=i.next();!a.done;a=i.next()){var s=a.value;t.add(s)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return t},new Set),actions:rt(J(c).map(function(t){return c[t].actions}))}},e.prototype._transition=function(t,e,n){return ft(t)?this.transitionLeafNode(t,e,n):1===J(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},e.prototype.next=function(t,e){var n,r,i=this,a=e.type,c=this.on[a],u=this.transient?[{type:y}]:[];if(!c||!c.length)return{tree:void 0,source:t,reentryStates:void 0,actions:u};var h,l=[];try{for(var d=o(c),f=d.next();!f.done;f=d.next()){var p=f.value,v=p.cond,m=p.in,g=t.context,x=!m||(ft(m)&&q(m)?t.matches(Y(this.getStateNodeById(m).path,this.delimiter)):K(Y(m,this.delimiter),et(this.path.slice(0,-2))(t.value)));if((!v||this.evaluateGuard(v,g,e,t))&&x){l=it(p.target),u.push.apply(u,s(it(p.actions))),h=p;break}}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}if(h&&0===l.length)return{tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,reentryStates:void 0,actions:u};if(!h&&0===l.length)return{tree:void 0,source:t,reentryStates:void 0,actions:u};var w=rt(l.map(function(e){return i.getRelativeStateNodes(e,t.historyValue)})),S=!!h.internal?[]:rt(w.map(function(t){return i.nodesFromChild(t)}));return{tree:w.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)}),source:t,reentryStates:new Set(S),actions:u}},Object.defineProperty(e.prototype,"tree",{get:function(){var t=Y(this.path,this.delimiter);return new R(this.machine,t)},enumerable:!0,configurable:!0}),e.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},e.prototype.getStateTree=function(t){return new R(this,t)},e.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},e.prototype.evaluateGuard=function(t,e,n,r){var i=this.machine.options.guards,o={state:r,cond:t};if("xstate.cond"===t.type)return t.predicate(e,n,o);if(!i[t.type])throw new Error("Guard (condition) '"+t.type+"' is not implemented on machine '"+this.machine.id+"'.");return(0,i[t.type])(e,n,o)},e.prototype.toGuard=function(t){return ft(t)?{type:t}:dt(t)?{type:"xstate.cond",predicate:t}:t},e.prototype.getActions=function(t,e){var n=this,r=t.tree?t.tree.resolved.getEntryExitStates(this.getStateTree(e.value),t.reentryStates?t.reentryStates:void 0):{entry:[],exit:[]},i=t.tree?t.tree.getDoneEvents(new Set(r.entry)):[];t.source||(r.exit=[],r.entry.unshift(this));var o=new Set(r.entry),c=new Set(r.exit),u=a([rt(Array.from(o).map(function(t){return s(t.activities.map(function(t){return V(t)}),t.onEntry)})).concat(i.map(k)),rt(Array.from(c).map(function(t){return s(t.onExit,t.activities.map(function(t){return _(t)}))}))],2),h=u[0];return u[1].concat(t.actions).concat(h).map(function(t){return T(t,n.machine.options.actions)})},e.prototype.transition=function(e,n,i){var o;if(e instanceof h)o=void 0===i?e:this.resolveState(h.from(e,i));else{var a=ft(e)?this.resolve(Z(this.getResolvedPath(e))):this.resolve(e),s=i||this.machine.context;o=this.resolveState(h.from(a,s))}var c=E(n),u=c.type;if(this.strict&&-1===this.events.indexOf(u)&&!function(e){if(0===e.indexOf(t.ActionTypes.DoneState)||0===e.indexOf(t.ActionTypes.DoneInvoke))return!0;if(e===t.ActionTypes.ErrorCommunication||e===t.ActionTypes.ErrorCommunication)return!0;return!1}(u))throw new Error("Machine '"+this.id+"' does not accept event '"+u+"'");var l=this._transition(o.value,o,c),d=r({},l,{tree:l.tree?l.tree.resolved:void 0});return this.resolveTransition(d,o,c)},e.prototype.resolveTransition=function(e,n,i){var c,u,v,g=this,x=e.tree?e.tree.value:void 0,w=n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0,S=this.getActions(e,n),N=r({},n.activities);try{for(var O=o(S),k=O.next();!k.done;k=O.next()){var P=k.value;P.type===l?N[P.activity.type]=P:P.type===d&&(N[P.activity.type]=!1)}}catch(t){c={error:t}}finally{try{k&&!k.done&&(u=O.return)&&u.call(O)}finally{if(c)throw c.error}}var A=a(st(S,function(t){return t.type===f||t.type===y}),2),j=A[0],V=a(st(A[1],function(t){return t.type===m}),2),_=V[0],I=V[1],L=_.length?this.options.updater(n.context,i,_):n.context,D=I.map(function(e){var n=T(e);if(n.type===p){var o=function(t,e,n){var i=dt(t.event)?E(t.event(e,n)):E(t.event),o=dt(t.delay)?t.delay(e,n):t.delay;return r({},t,{event:i,delay:o})}(n,L,i||{type:t.ActionTypes.Init});if(ft(o.delay)){if(!g.machine.options.delays||void 0===g.machine.options.delays[o.delay])return ht(!1,"No delay reference for delay expression '"+o.delay+"' was found on machine '"+g.machine.id+"'"),o;var a=g.machine.options.delays[o.delay];o.delay="number"==typeof a?a:a(L,i||{type:t.ActionTypes.Init})}return o}return T(n,g.options.actions)}),C=x?this.getStateNodes(x):[];C.some(function(t){return t.transient})&&j.push({type:y});var M,z,R=s([this],C).reduce(function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t},{}),F=x?new h({value:x,context:L,event:i||b,historyValue:w?(M=w,z=x,{current:z,states:ct(M,z)}):void 0,history:e.source?n:void 0,actions:D,activities:N,meta:R,events:j,tree:e.tree}):void 0;if(!F)return(F=new h({value:n.value,context:L,event:i,historyValue:n.historyValue,history:n,actions:[],activities:n.activities,meta:n.meta,events:[],tree:n.tree})).changed=!!_.length,F;var U=F.history;U&&delete U.history;for(var q=F;j.length;){var B=q.actions,X=j.shift();(q=this.transition(q,X.type===y?G:X.event,q.context)).event=i,(v=q.actions).unshift.apply(v,s(B))}var H=U?!!q.actions.length||!!_.length||typeof U.value!=typeof q.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(ft("string"===e||typeof n))return e===n;var r=J(e),i=J(n);return r.length===i.length&&r.every(function(r){return t(e[r],n[r])})}(q.value,U.value):void 0;return q.changed=H,q.historyValue=F.historyValue,q.history=U,q},e.prototype.ensureValidPaths=function(t){var e,n,r=this,i=new Map,a=rt(t.map(function(t){return r.getRelativeStateNodes(t)}));try{t:for(var s=o(a),c=s.next();!c.done;c=s.next())for(var u=c.value,h=u;h.parent;){if(i.has(h.parent)){if("parallel"===h.parent.type)continue t;throw new Error("State node '"+u.id+"' shares parent '"+h.parent.id+"' with state node '"+i.get(h.parent).map(function(t){return t.id})+"'")}i.get(h.parent)?i.get(h.parent).push(u):i.set(h.parent,[u]),h=h.parent}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}},e.prototype.getStateNode=function(t){if(q(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.");var e=this.states[t];if(!e)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return e},e.prototype.getStateNodeById=function(t){var e=q(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return n},e.prototype.getStateNodeByPath=function(t){for(var e=W(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();n=n.getStateNode(r)}return n},e.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||U;switch(this.type){case"parallel":return $(this.initialStateValue,function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):U});case"compound":if(ft(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return J(t).length?$(t,function(t,e){return t?n.getStateNode(e).resolve(t):U}):this.initialStateValue||{};default:return t||U}},Object.defineProperty(e.prototype,"resolvedStateValue",{get:function(){var t,e,n=this.key;if("parallel"===this.type)return(t={})[n]=tt(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!("history"===t.type)}),t;if(void 0===this.initial)return n;if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+n+"'");return(e={})[n]=this.states[this.initial].resolvedStateValue,e},enumerable:!0,configurable:!0}),e.prototype.getResolvedPath=function(t){if(q(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return W(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?tt(this.states,function(t){return t.initialStateValue||U},function(t){return!("history"===t.type)}):ft(this.resolvedStateValue)?void 0:this.resolvedStateValue[this.key];return this.__cache.initialState=t,this.__cache.initialState},enumerable:!0,configurable:!0}),e.prototype.getInitialState=function(e,n){var r,i,a,c;void 0===n&&(n=this.machine.context);var u={},l=[];try{for(var d=o(this.getStateNodes(e)),f=d.next();!f.done;f=d.next()){var p=f.value;if(p.onEntry&&l.push.apply(l,s(p.onEntry)),p.activities)try{for(var v=o(p.activities),y=v.next();!y.done;y=v.next()){var g=y.value;u[Q(g)]=g,l.push(V(g))}}catch(t){a={error:t}}finally{try{y&&!y.done&&(c=v.return)&&c.call(v)}finally{if(a)throw a.error}}}}catch(t){r={error:t}}finally{try{f&&!f.done&&(i=d.return)&&i.call(d)}finally{if(r)throw r.error}}var x=l.filter(function(t){return"object"==typeof t&&t.type===m}),w=this.options.updater(n,{type:t.ActionTypes.Init},x);return new h({value:e,context:w,event:b,activities:u})},Object.defineProperty(e.prototype,"initialState",{get:function(){var e=this.initialStateValue;if(!e)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");var n=this.getInitialState(e);return this.resolveTransition({tree:this.getStateTree(e),source:void 0,reentryStates:new Set(this.getStateNodes(e)),actions:[]},n,{type:t.ActionTypes.Init})},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=e.target&&ft(e.target)&&q(e.target)?Z(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),e.prototype.getStates=function(t){var e,n;if(ft(t))return[this.states[t]];var r=[];try{for(var i=o(J(t)),a=i.next();!a.done;a=i.next()){var c=a.value;r.push.apply(r,s(this.states[c].getStates(t[c])))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r},e.prototype.getRelativeStateNodes=function(t,e,n){if(void 0===n&&(n=!0),ft(t)&&q(t)){var r=this.getStateNodeById(t);return n?"history"===r.type?r.resolveHistory(e):r.initialStateNodes:[r]}var i=W(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return n?rt(o.map(function(t){return t.initialStateNodes})):o},Object.defineProperty(e.prototype,"initialStateNodes",{get:function(){var t=this;return"atomic"===this.type||"final"===this.type?[this]:"compound"!==this.type||this.initial?rt(nt(this.initialStateValue).map(function(e){return t.getFromRelativePath(e)})):(ht(!1,"Compound state node '"+this.id+"' has no initial state."),[this])},enumerable:!0,configurable:!0}),e.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var n=a(t),r=n[0],i=n.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+r+"' from node with no states");var o=this.getStateNode(r);if("history"===o.type)return o.resolveHistory(e);if(!this.states[r])throw new Error("Child state '"+r+"' does not exist on '"+this.id+"'");return this.states[r].getFromRelativePath(i,e)},e.prototype.historyValue=function(t){if(J(this.states).length)return{current:t||this.initialStateValue,states:tt(this.states,function(e,n){if(!t)return e.historyValue();var r=ft(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)},function(t){return!t.history})}},e.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t)return this.target?rt(nt(this.target).map(function(t){return n.getFromRelativePath(t)})):n.initialStateNodes;var r,i,a=(r=n.path,i="states",function(t){var e,n,a=t;try{for(var s=o(r),c=s.next();!c.done;c=s.next()){var u=c.value;a=a[i][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return a})(t).current;return ft(a)?[n.getStateNode(a)]:rt(nt(a).map(function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]}))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,e=rt(J(this.states).map(function(e){return t.states[e].stateIds}));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var i=this.states,a=new Set(this.ownEvents);if(i)try{for(var s=o(J(i)),c=s.next();!c.done;c=s.next()){var u=i[c.value];if(u.states)try{for(var h=o(u.events),l=h.next();!l.done;l=h.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ownEvents",{get:function(){var t=this,e=new Set(J(this.on).filter(function(e){return t.on[e].some(function(t){return!(!t.target&&!t.actions.length&&t.internal)})}));return Array.from(e)},enumerable:!0,configurable:!0}),e.prototype.formatTransition=function(t,n,i){var o=this,a=n?n.internal:void 0;if(void 0===t||""===t)return r({},n,{actions:n?it(n.actions).map(function(t){return T(t)}):[],cond:n&&n.cond?this.toGuard(n.cond):void 0,target:void 0,internal:void 0===a||a,event:i});var s=it(t).map(function(t){if(t instanceof e)return"#"+t.id;var n=ft(t)&&t[0]===o.delimiter;return a=void 0===a?n:a,n&&!o.parent?t.slice(1):n?o.key+t:""+t});return r({},n,{actions:n?it(n.actions).map(function(t){return T(t)}):[],cond:n&&n.cond?this.toGuard(n.cond):void 0,target:s,internal:a,event:i})},e.prototype.formatTransitions=function(){var t,n,i,a=this,s=this.config.on||U,c=this.config.onDone?((t={})[""+D(this.id)]=this.config.onDone,t):void 0,u=this.invoke.reduce(function(t,e){return e.onDone&&(t[C(e.id)]=e.onDone),e.onError&&(t[S]=e.onError),t},{}),h=this.after,l=$(r({},s,c,u),function(t,n){return void 0===t?[{target:void 0,event:n,actions:[],internal:!0}]:lt(t)?t.map(function(t){return a.formatTransition(t.target,t,n)}):ft(t)||t instanceof e?[a.formatTransition([t],void 0,n)]:[a.formatTransition(t.target,t,n)]});try{for(var d=o(h),f=d.next();!f.done;f=d.next()){var p=f.value;l[p.event]=l[p.event]||[],l[p.event].push(p)}}catch(t){n={error:t}}finally{try{f&&!f.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}return l},e}();function H(t){return!ft(t)&&("value"in t&&"tree"in t&&"history"in t)}function J(t){return Object.keys(t)}function K(t,e,n){void 0===n&&(n=c);var r=Y(t,n),i=Y(e,n);return ft(i)?!!ft(r)&&i===r:ft(r)?r in i:J(r).every(function(t){return t in i&&K(r[t],i[t])})}function Q(t){try{return ft(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function W(t,e){try{return lt(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function Y(t,e){return H(t)?t.value:lt(t)?Z(t):"string"==typeof t||H(t)?Z(W(t,e)):t}function Z(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 $(t,e){for(var n={},r=J(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function tt(t,e,n){var r,i,a={};try{for(var s=o(J(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];n(h)&&(a[u]=e(h,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}var et=function(t){return function(e){var n,r,i=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){i=i[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return i}};var nt=function(t){return t?ft(t)?[[t]]:rt(J(t).map(function(e){var n=t[e];return"string"==typeof n||Object.keys(n).length?nt(t[e]).map(function(t){return[e].concat(t)}):[[e]]})):[[]]};function rt(t){var e;return(e=[]).concat.apply(e,s(t))}function it(t){return lt(t)?t:void 0===t?[]:[t]}function ot(t,e,n){var r,i;if(dt(t))return t(e,n);var a={};try{for(var s=o(J(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];dt(h)?a[u]=h(e,n):a[u]=h}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}function at(t){return t instanceof Promise||!(null===t||!dt(t)&&"object"!=typeof t||!dt(t.then))}function st(t,e){var n,r,i=a([[],[]],2),s=i[0],c=i[1];try{for(var u=o(t),h=u.next();!h.done;h=u.next()){var l=h.value;e(l)?s.push(l):c.push(l)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}return[s,c]}function ct(t,e){return $(t.states,function(t,n){if(t){var r=(ft(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:ct(t,r)}}})}function ut(e,n,r){return e?r.reduce(function(e,r){var i,a,s=r.assignment,c={};if(dt(s))c=s(e,n||{type:t.ActionTypes.Init});else try{for(var u=o(J(s)),h=u.next();!h.done;h=u.next()){var l=h.value,d=s[l];c[l]=dt(d)?d(e,n):d}}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=u.return)&&a.call(u)}finally{if(i)throw i.error}}return Object.assign({},e,c)},e):e}var ht=function(){};function lt(t){return Array.isArray(t)}function dt(t){return"function"==typeof t}function ft(t){return"string"==typeof t}var pt={deferEvents:!1},vt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r({},pt,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.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.queue=[],t}finally{this.processingEvent=!1}},t}(),yt=function(){function e(n,i){void 0===i&&(i=e.defaultOptions);var o=this;this.machine=n,this.scheduler=new vt,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.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(lt(t))return o.batch(t),o.state;var n=E(t,e);if(!o.initialized&&o.options.deferEvents)ht(!1,'Event "'+n.type+'" was sent to uninitialized service "'+o.machine.id+'" and is deferred. Make sure .start() is called for this service.\nEvent: '+JSON.stringify(t));else if(!o.initialized)throw new Error('Event "'+n.type+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(n));return o.scheduler.schedule(function(){var t=o.nextState(n);o.update(t,n),o.forward(n)}),o.state},this.sender=function(t){return function(){return this.send(t)}.bind(o)},this.sendTo=function(e,n){var r=n===t.SpecialTargets.Parent,i=r?o.parent:o.children.get(n);if(i)i.send(e);else{if(!r)throw new Error("Unable to send event to child '"+n+"' from service '"+o.id+"'.");ht(!1,"Service '"+o.id+"' has no parent: unable to send event "+e.type)}};var a=r({},e.defaultOptions,i),s=a.clock,c=a.logger,u=a.parent,h=a.id,l=void 0!==h?h:n.id;Object.assign(this,{clock:s,logger:c,parent:u,id:l}),this.options=a,this.scheduler=new vt({deferEvents:this.options.deferEvents})}return Object.defineProperty(e.prototype,"initialState",{get:function(){return this.machine.initialState},enumerable:!0,configurable:!0}),e.prototype.execute=function(t){var e,n;try{for(var r=o(t.actions),i=r.next();!i.done;i=r.next()){var a=i.value;this.exec(a,t.context,t.event)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},e.prototype.update=function(t,e){var n,r,i,a,s,c,u,h;if(this.state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e,t),t.event)try{for(var l=o(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&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var f=o(this.listeners),p=f.next();!p.done;p=f.next()){(0,p.value)(t,t.event)}}catch(t){i={error:t}}finally{try{p&&!p.done&&(a=f.return)&&a.call(f)}finally{if(i)throw i.error}}try{for(var v=o(this.contextListeners),y=v.next();!y.done;y=v.next()){(0,y.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{y&&!y.done&&(c=v.return)&&c.call(v)}finally{if(s)throw s.error}}if(this.state.tree&&this.state.tree.done){var m=this.state.tree.getDoneData(this.state.context,E(e));try{for(var g=o(this.doneListeners),x=g.next();!x.done;x=g.next()){(0,x.value)(C(this.id,m))}}catch(t){u={error:t}}finally{try{x&&!x.done&&(h=g.return)&&h.call(g)}finally{if(u)throw u.error}}this.stop()}},e.prototype.onTransition=function(t){return this.listeners.add(t),this},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(t){return this.doneListeners.add(t),this},e.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},e.prototype.start=function(t){var e=this,n=void 0===t?this.machine.initialState:t instanceof h?this.machine.resolveState(t):this.machine.resolveState(h.from(t));return this.initialized=!0,this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){e.update(n,{type:x})}),this},e.prototype.stop=function(){var t,e,n,r,i,a,s,c,u,h;try{for(var l=o(this.listeners),d=l.next();!d.done;d=l.next()){var f=d.value;this.listeners.delete(f)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var p=o(this.stopListeners),v=p.next();!v.done;v=p.next()){(f=v.value)(),this.stopListeners.delete(f)}}catch(t){n={error:t}}finally{try{v&&!v.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}try{for(var y=o(this.contextListeners),m=y.next();!m.done;m=y.next()){f=m.value;this.contextListeners.delete(f)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(a=y.return)&&a.call(y)}finally{if(i)throw i.error}}try{for(var g=o(this.doneListeners),x=g.next();!x.done;x=g.next()){f=x.value;this.doneListeners.delete(f)}}catch(t){s={error:t}}finally{try{x&&!x.done&&(c=g.return)&&c.call(g)}finally{if(s)throw s.error}}this.children.forEach(function(t){dt(t.stop)&&t.stop()});try{for(var w=o(J(this.delayedEventsMap)),S=w.next();!S.done;S=w.next()){var b=S.value;this.clock.clearTimeout(this.delayedEventsMap[b])}}catch(t){u={error:t}}finally{try{S&&!S.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}return this.initialized=!1,this},e.prototype.batch=function(t){var e=this;if(!this.initialized&&this.options.deferEvents)ht(!1,t.length+' event(s) were sent to uninitialized service "'+this.machine.id+'" and are deferred. Make sure .start() is called for this service.\nEvent: '+JSON.stringify(event));else if(!this.initialized)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(function(){var n,i,a,c=e.state;try{for(var u=o(t),h=u.next();!h.done;h=u.next()){var l=E(h.value),d=c.actions.map(function(t){return n=c,i=(e=t).exec,r({},e,{exec:void 0!==i?function(){return i(n.context,n.event,{action:e,state:n})}:void 0});var e,n,i});(a=(c=e.machine.transition(c,l)).actions).unshift.apply(a,s(d)),e.forward(l)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}e.update(c,E(t[t.length-1]))})},e.prototype.nextState=function(t){var e=E(t);if(e.type===S&&-1===this.state.nextEvents.indexOf(S))throw e.data;return this.machine.transition(this.state,e,this.state.context)},e.prototype.forward=function(t){var e,n;try{for(var r=o(this.forwardTo),i=r.next();!i.done;i=r.next()){var a=i.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},e.prototype.defer=function(t){var e=this,n=t.delay;if(ft(n)){if(!this.machine.options.delays||void 0===this.machine.options.delays[n])return void ht(!1,"No delay reference for delay expression '"+n+"' was found on machine '"+this.machine.id+"' on service '"+this.id+"'.");var r=this.machine.options.delays[n];n="number"==typeof r?r:r(this.state.context,this.state.event)}this.delayedEventsMap[t.id]=this.clock.setTimeout(function(){t.to?e.sendTo(t.event,t.to):e.send(t.event)},n||0)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(e,n,r){if(e.exec)return e.exec(n,r,{action:e,state:this.state});switch(e.type){case p:var i=e;if(i.delay)return void this.defer(i);i.to?this.sendTo(i.event,i.to):this.send(i.event);break;case v:this.cancel(e.sendId);break;case l:var o=e.activity;if(!this.state.activities[o.type])break;if(o.type===t.ActionTypes.Invoke){var a=this.machine.options.services?this.machine.options.services[o.src]:void 0,s=o.id,c=o.data,u=!!o.forward;if(!a)return void ht(!1,"No service found for invocation '"+o.src+"' in machine '"+this.machine.id+"'.");var h=dt(a)?a(n,r):a;at(h)?this.spawnPromise(s,Promise.resolve(h)):dt(h)?this.spawnCallback(s,h):"string"!=typeof h&&this.spawn(c?h.withContext(ot(c,n,r)):h,{id:s,autoForward:u})}else this.spawnActivity(o);break;case d:this.stopChild(e.activity.id);break;case g:var f=e.expr?e.expr(n,r):void 0;e.label?this.logger(e.label,f):this.logger(f);break;default:ht(!1,"No implementation found for action type '"+e.type+"'")}},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&dt(e.stop)&&(e.stop(),this.children.delete(t),this.forwardTo.delete(t))},e.prototype.spawn=function(t,n){var r=this;void 0===n&&(n={});var i=new e(t,{parent:this,id:n.id||t.id});return i.onDone(function(t){r.send(t)}).start(),this.children.set(i.id,i),n.autoForward&&this.forwardTo.add(i.id),i},e.prototype.spawnPromise=function(t,e){var n=this,r=!1;e.then(function(e){r||n.send(C(t,e))}).catch(function(e){if(!r){var i=M(e,t);try{n.send(i)}catch(t){n.devTools&&n.devTools.send(i,n.state),n.machine.strict&&n.stop()}}}),this.children.set(t,{send:function(){},stop:function(){r=!0}})},e.prototype.spawnCallback=function(t,e){var n,r=this,i=function(e){ht(!1,"Event '"+e.type+"' sent to callback service '"+t+"' but was not handled by a listener.")};try{at(n=e(function(t){return r.send(t)},function(t){i=t}))&&Promise.resolve(n).catch(function(e){var n=M(e,t);try{r.send(n)}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}})}catch(e){this.send(M(e,t))}this.children.set(t,{send:i,stop:n})},e.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}else ht(!1,"No implementation found for activity '"+t.type+"'")},e.prototype.spawnEffect=function(t,e){this.children.set(t,{send:function(){},stop:e})},e.prototype.reportUnhandledExceptionOnInvocation=function(t,e,n){var r=t.stack?" Stacktrace was '"+t.stack+"'":"";if(t===e)console.error("Missing onError handler for invocation '"+n+"', error was '"+t+"'."+r);else{var i=e.stack?" Stacktrace was '"+e.stack+"'":"";console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '"+n+"'. Original error: '"+t+"'. "+r+" Current error is '"+e+"'."+i)}},e.prototype.attachDev=function(){this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&(this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect({name:this.id,features:{jump:!1,skip:!1}}),this.devTools.init(this.state))},e.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),e.interpret=mt,e}();function mt(t,e){return new yt(t,e)}var gt={raise:k,send:P,sendParent:A,log:function(t,e){return void 0===t&&(t=function(t,e){return{context:t,event:e}}),{type:g,label:e,expr:t}},cancel:j,start:V,stop:_,assign:I,after:L,done:D};t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new X(t,e,n)},t.StateNode=X,t.State=h,t.matchesState=K,t.mapState=function(t,e){var n,r,i;try{for(var a=o(J(t)),s=a.next();!s.done;s=a.next()){var c=s.value;K(c,e)&&(!i||e.length>i.length)&&(i=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[i]},t.actions=gt,t.assign=I,t.send=P,t.sendParent=A,t.interpret=mt,t.Interpreter=yt,t.matchState=function(t,e,n){var r,i,s=h.from(t,t instanceof h?t.context:void 0);try{for(var c=o(e),u=c.next();!u.done;u=c.next()){var l=a(u.value,2),d=l[0],f=l[1];if(s.matches(d))return f(s)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return n(s)},Object.defineProperty(t,"__esModule",{value:!0})});
  