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 s(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 a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(s(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",e.ErrorPlatform="error.platform",e.Update="xstate.update",e.Pure="xstate.pure",(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var u=".",c={},h="xstate.guard";function d(t){return!V(t)&&("value"in t&&"tree"in t&&"history"in t)}function l(t){return Object.keys(t)}function f(t,e,n){void 0===n&&(n=u);var r=y(t,n),i=y(e,n);return V(i)?!!V(r)&&i===r:V(r)?r in i:l(r).every(function(t){return t in i&&f(r[t],i[t])})}function p(t){try{return V(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 v(t,e){try{return A(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function y(t,e){return d(t)?t.value:A(t)?g(t):"string"==typeof t||d(t)?g(v(t,e)):t}function g(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 m(t,e){for(var n={},r=l(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function x(t,e,n){var r,i,s={};try{for(var a=o(l(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];n(h)&&(s[c]=e(h,c,t))}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return s}var w=function(t){return function(e){var n,r,i=e;try{for(var s=o(t),a=s.next();!a.done;a=s.next()){i=i[a.value]}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}return i}};function b(t){return t?V(t)?[[t]]:S(l(t).map(function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?b(t[e]).map(function(t){return[e].concat(t)}):[[e]]})):[[]]}function S(t){var e;return(e=[]).concat.apply(e,a(t))}function N(t){return A(t)?t:void 0===t?[]:[t]}function E(t,e,n){var r,i;if(k(t))return t(e,n);var s={};try{for(var a=o(l(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];k(h)?s[c]=h(e,n):s[c]=h}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return s}function T(t){return t instanceof Promise||!(null===t||!k(t)&&"object"!=typeof t||!k(t.then))}function O(t,e){var n,r,i=s([[],[]],2),a=i[0],u=i[1];try{for(var c=o(t),h=c.next();!h.done;h=c.next()){var d=h.value;e(d)?a.push(d):u.push(d)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}return[a,u]}function P(t,e){return m(t.states,function(t,n){if(t){var r=(V(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:P(t,r)}}})}function _(e,n,r){return e?r.reduce(function(e,r){var i,s,a=r.assignment,u={};if(k(a))u=a(e,n||{type:t.ActionTypes.Init});else try{for(var c=o(l(a)),h=c.next();!h.done;h=c.next()){var d=h.value,f=a[d];u[d]=k(f)?f(e,n):f}}catch(t){i={error:t}}finally{try{h&&!h.done&&(s=c.return)&&s.call(c)}finally{if(i)throw i.error}}return Object.assign({},e,u)},e):e}function A(t){return Array.isArray(t)}function k(t){return"function"==typeof t}function V(t){return"string"==typeof t}function j(t,e){if(t)return V(t)?{type:h,name:t,predicate:e?e[t]:void 0}:k(t)?{type:h,name:t.name,predicate:t}:t}function I(t){try{return"subscribe"in t&&k(t.subscribe)}catch(t){return!1}}function L(t){try{return"__xstatenode"in t}catch(t){return!1}}var D,C=(D=0,function(){return(++D).toString(16)});var M=function(){function e(t){this.actions=[],this.activities=c,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||c,this.meta=t.meta||{},this.events=t.events||[],Object.defineProperty(this,"tree",{value:t.tree,enumerable:!1}),this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this)}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="."),V(t))return[t];var r=l(t);return r.concat.apply(r,a(r.map(function(r){return n.toStrings(t[r]).map(function(t){return r+e+t})})))},e.prototype.matches=function(t){return f(t,this.value)},e}(),R=t.ActionTypes.Start,z=t.ActionTypes.Stop,U=t.ActionTypes.Raise,B=t.ActionTypes.Send,F=t.ActionTypes.Cancel,J=t.ActionTypes.NullEvent,q=t.ActionTypes.Assign,X=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),G=t.ActionTypes.Init,H=t.ActionTypes.Invoke,K=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),Q=t.ActionTypes.Update,W={type:G};function Y(t,e){if(V(t)||"number"==typeof t){var n={type:t};return e&&Object.assign(n,e),n}return t}function Z(t,e){return e&&e[t]||void 0}function $(t,e){var n;if(V(t)||"number"==typeof t){var o=Z(t,e);n=k(o)?{type:t,exec:o}:o||{type:t,exec:void 0}}else if(k(t))n={type:t.name||t.toString(),exec:t};else{if(k(o=Z(t.type,e)))n=r({},t,{exec:o});else if(o){var s=t.type,a=i(t,["type"]);n=r({type:s},o,a)}else n=t}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1,configurable:!0}),n}var tt=function(t,e){return t?(A(t)?t:[t]).map(function(t){return $(t,e)}):[]};function et(t){var e=$(t);return r({id:V(t)?t:e.id},e,{type:e.type})}function nt(t){return{type:U,event:t}}function rt(t,e){return{to:e?e.to:void 0,type:B,event:k(t)?t:Y(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:k(t)?t.name:p(t)}}function it(e,n){return rt(e,r({},n,{to:t.SpecialTargets.Parent}))}var ot=function(t){return{type:F,sendId:t}};function st(e){var n=et(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function at(e){var n=et(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var ut=function(t){return{type:q,assignment:t}};function ct(e,n){var r=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+r}function ht(e,n){var r=t.ActionTypes.DoneState+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function dt(e,n){var r=t.ActionTypes.DoneInvoke+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function lt(e,n){var r=t.ActionTypes.ErrorPlatform+"."+e,i={type:r,data:n,toString:function(){return r}};return i}var ft={resolved:!1},pt=function(){function t(e,n,i,o){var s,a=this;void 0===i&&(i=ft),this.stateNode=e,this.stateValue=n,this.parent=o,this.reentryNodes=new Set,this.root=this.parent?this.parent.root:this,this.nodes=n?V(n)?((s={})[n]=new t(e.getStateNode(n),void 0,void 0,this),s):m(n,function(n,r){return new t(e.getStateNode(r),n,void 0,a)}):{};var u=r({},ft,i);this.isResolved=u.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[l(this.nodes)[0]].stateNode.type;case"parallel":return l(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[l(this.nodes)[0]];if(!n.stateNode.data)return;return E(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]:S(l(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[ht(this.stateNode.id,this.stateNode.data)];var n=S(l(this.nodes).map(function(n){return e.nodes[n].getDoneEvents(t)}));if("parallel"===this.stateNode.type){var r=l(this.nodes).every(function(t){return e.nodes[t].done});return n&&r?n.concat(ht(this.stateNode.id)):n}if(!this.done||!n.length)return n;var i=1===n.length?n[0].data:void 0;return n.concat(ht(this.stateNode.id,i))},Object.defineProperty(t.prototype,"resolved",{get:function(){var e=new t(this.stateNode,this.stateNode.resolve(this.value),{resolved:!0});return e.reentryNodes=this.reentryNodes,e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return b(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])}var s=new t(this.stateNode.machine,n);return s.reentryNodes=this.reentryNodes,s},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nextEvents",{get:function(){var t=this,e=this.stateNode.ownEvents,n=S(l(this.nodes).map(function(e){return t.nodes[e].nextEvents}));return a(new Set(n.concat(e)))},enumerable:!0,configurable:!0}),t.prototype.clone=function(){return new t(this.stateNode,this.value,void 0,this.parent)},t.prototype.combine=function(t){var e,n,r;if(t.stateNode!==this.stateNode)throw new Error("Cannot combine distinct trees");var i=this.clone();if(t.root.reentryNodes.forEach(function(t){i.root.addReentryNode(t)}),"compound"===this.stateNode.type){var s=void 0;if(l(this.nodes).length&&l(t.nodes).length){var u=l(this.nodes)[0];return(e={})[u]=this.nodes[u].combine(t.nodes[u]),s=e,i.nodes=s,i}return s=Object.assign({},this.nodes,t.nodes),i.nodes=s,i}if("parallel"===this.stateNode.type){var c=new Set(a(l(this.nodes),l(t.nodes)));s={};try{for(var h=o(c),d=h.next();!d.done;d=h.next()){var f=d.value;this.nodes[f]&&t.nodes[f]?s[f]=this.nodes[f].combine(t.nodes[f]):s[f]=this.nodes[f]||t.nodes[f]}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}return i.nodes=s,i}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 m(this.nodes,function(t){return t.value});if("compound"===this.stateNode.type){if(0===l(this.nodes).length)return{};var t=this.nodes[l(this.nodes)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:m(this.nodes,function(t){return t.value})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return f(t,this.value)},t.prototype.getEntryExitStates=function(t){var e,n,r=this,i=this.root.reentryNodes;if(!t)return{exit:[],entry:a(i)};if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var s={exit:[],entry:[]},u=l(this.nodes)[0],c=l(t.nodes)[0];return u!==c?(s.exit=t.nodes[c].getExitStates(),s.entry=this.nodes[u].getEntryStates()):s=this.nodes[u].getEntryExitStates(t.nodes[c]),i&&i.has(this.stateNode)&&(s.exit.push(this.stateNode),s.entry.unshift(this.stateNode)),s;case"parallel":var h=l(this.nodes).map(function(e){return r.nodes[e].getEntryExitStates(t.nodes[e])}),d={exit:[],entry:[]};try{for(var f=o(h),p=f.next();!p.done;p=f.next()){var v=p.value;d.exit=a(d.exit,v.exit),d.entry=a(d.entry,v.entry)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(n=f.return)&&n.call(f)}finally{if(e)throw e.error}}return i&&i.has(this.stateNode)&&(d.exit.push(this.stateNode),d.entry.unshift(this.stateNode)),d;case"atomic":default:return i&&i.has(this.stateNode)?{exit:[this.stateNode],entry:[this.stateNode]}:{exit:[],entry:[]}}},t.prototype.getEntryStates=function(){var t=this;return this.nodes?[this.stateNode].concat(S(l(this.nodes).map(function(e){return t.nodes[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.nodes?S(l(this.nodes).map(function(e){return t.nodes[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t.prototype.addReentryNode=function(t){this.root.reentryNodes.add(t)},t}(),vt=".",yt="",gt={},mt=function(t){return"#"===t[0]},xt=function(){return{actions:{},guards:{},services:{},activities:{},delays:{},updater:_}},wt=function(){function e(t,n,o){var s=this;this.context=o,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,transitions:void 0},this.idMap={};var u=t.parent,c=i(t,["parent"]);this.config=c,this.parent=u,this.options=r({},xt(),n),this.key=t.key||t.id||"(machine)",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:vt),this.id=t.id||(this.machine?a([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&&l(t.states).length?"compound":t.history?"history":"atomic"),this.initial=t.initial,this.order=t.order||-1,this.states=t.states?m(t.states,function(t,n,i,o){var a,u=new e(r({},t,{key:n,order:void 0===t.order?o:t.order,parent:s}));return Object.assign(s.idMap,r(((a={})[u.id]=u,a),u.idMap)),u}):gt,this.history=!0===t.history?"shallow":t.history||!1,this._transient=!(!t.on||!t.on[yt]),this.strict=!!t.strict,this.onEntry=N(t.entry||t.onEntry).map(function(t){return $(t)}),this.onExit=N(t.exit||t.onExit).map(function(t){return $(t)}),this.meta=t.meta,this.data="final"===this.type?t.data:void 0,this.invoke=N(t.invoke).map(function(t,e){var n,i;if(L(t))return(s.parent||s).options.services=r(((n={})[t.id]=t,n),(s.parent||s).options.services),{type:H,src:t.id,id:t.id};if("string"!=typeof t.src){var o=s.id+":invocation["+e+"]";return s.machine.options.services=r(((i={})[o]=t.src,i),s.machine.options.services),r({type:H,id:o},t,{src:o})}return r({},t,{type:H,id:t.id||t.src,src:t.src})}),this.activities=N(t.activities).concat(this.invoke).map(function(t){return et(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,s=i.activities,a=i.guards,u=i.services,c=i.delays;return new e(this.config,{actions:r({},o,t.actions),activities:r({},s,t.activities),guards:r({},a,t.guards),services:r({},u,t.services),delays:r({},c,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:m(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,invoke:this.invoke}},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return this.definition},Object.defineProperty(e.prototype,"on",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){var t=this;return S(l(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,n=this.machine.options.guards;if(!e)return[];if(A(e))return e.map(function(e,i){var o,s=e.delay,a=e.target;k(s)?(o=t.id+":delay["+i+"]",t.options.delays[o]=s):o=s;var u=ct(o,t.id);return t.onEntry.push(rt(u,{delay:s})),t.onExit.push(ot(u)),r({event:u},e,{target:void 0===a?void 0:N(a),cond:j(e.cond,n),actions:N(e.actions).map(function(t){return $(t)})})});var i=S(l(e).map(function(i){var o=e[i],s=isNaN(+i)?i:+i,a=ct(s,t.id);return t.onEntry.push(rt(a,{delay:s})),t.onExit.push(ot(a)),V(o)?[{target:[o],delay:s,event:a,actions:[]}]:N(o).map(function(t){return r({event:a,delay:s},t,{target:void 0===t.target?t.target:N(t.target),cond:j(t.cond,n),actions:N(t.actions).map(function(t){return $(t)})})})}));return i.sort(function(t,e){return V(t)||V(e)?0:+t.delay-+e.delay}),i},e.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof M?t.value:y(t,this.delimiter);if(V(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=l(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=p(t);return-1!==this.events.indexOf(e)},e.prototype.resolveState=function(t){return new M(r({},t,{value:this.resolve(t.value),tree:this.getStateTree(t.value)}))},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.actions;return{tree:i.tree,source:e,actions:o}}return r},e.prototype.transitionCompoundNode=function(t,e,n){var r=l(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);if(!i.tree){var o=this.next(e,n),s=o.actions;return{tree:o.tree,source:e,actions:s}}return i},e.prototype.transitionParallelNode=function(t,e,n){var r,i,s=this,a={};try{for(var u=o(l(t)),c=u.next();!c.done;c=u.next()){var h=c.value,d=t[h];if(d){var p=this.getStateNode(h)._transition(d,e,n);p.tree,a[h]=p}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}if(!l(a).some(function(t){return void 0!==a[t].tree})){var v=this.next(e,n),g=v.actions;return{tree:v.tree,source:e,actions:g}}var m=l(a).map(function(t){return a[t].tree}).filter(function(t){return void 0!==t}).reduce(function(t,e){return t.combine(e)});return 1!==m.paths.length||f(y(this.path,this.delimiter),m.value)?{tree:l(a).map(function(t){var n=a[t].tree;if(n)return n;var r=w(s.path)(e.value)[t];return new pt(s.getStateNode(t),r).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,actions:S(l(a).map(function(t){return a[t].actions}))}:{tree:m,source:e,actions:S(l(a).map(function(t){return a[t].actions}))}},e.prototype._transition=function(t,e,n){return V(t)?this.transitionLeafNode(t,e,n):1===l(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},e.prototype.next=function(t,e){var n,r,i=this,s=e.type,u=this.on[s];if(!u||!u.length)return{tree:void 0,source:t,actions:[]};var c,h=this._transient?[{type:J}]:[],d=[];try{for(var l=o(u),p=l.next();!p.done;p=l.next()){var v=p.value,g=v.cond,m=v.in,x=t.context,b=!m||(V(m)&&mt(m)?t.matches(y(this.getStateNodeById(m).path,this.delimiter)):f(y(m,this.delimiter),w(this.path.slice(0,-2))(t.value)));if((!g||this.evaluateGuard(g,x,e,t))&&b){void 0!==v.target&&(d=v.target),h.push.apply(h,a(N(v.actions))),c=v;break}}}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(!d.length)return{tree:c&&t.value?new pt(this,w(this.path)(t.value)).absolute:void 0,source:t,actions:h};var E=S(d.map(function(e){return i.getRelativeStateNodes(e,t.historyValue)})),T=!!c.internal?[]:S(E.map(function(t){return i.nodesFromChild(t)})),O=E.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)});return T.forEach(function(t){return O.addReentryNode(t)}),{tree:O,source:t,actions:h}},Object.defineProperty(e.prototype,"tree",{get:function(){var t=y(this.path,this.delimiter);return new pt(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 pt(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(t.type===h)return t.predicate(e,n,o);if(!i[t.type])throw new Error("Guard '"+t.type+"' is not implemented on machine '"+this.machine.id+"'.");return(0,i[t.type])(e,n,o)},e.prototype.getActions=function(t,e){var n=t.tree?t.tree.resolved.getEntryExitStates(e?this.getStateTree(e.value):void 0):{entry:[],exit:[]},r=t.tree?t.tree.getDoneEvents(new Set(n.entry)):[];t.source||(n.exit=[],n.entry.unshift(this));var i=new Set(n.entry),o=new Set(n.exit),u=s([S(Array.from(i).map(function(t){return a(t.activities.map(function(t){return st(t)}),t.onEntry)})).concat(r.map(nt)),S(Array.from(o).map(function(t){return a(t.onExit,t.activities.map(function(t){return at(t)}))}))],2),c=u[0],h=u[1];return tt(h.concat(t.actions).concat(c),this.machine.options.actions)},e.prototype.transition=function(e,n,r){var i;if(e instanceof M)i=void 0===r?e:this.resolveState(M.from(e,r));else{var o=V(e)?this.resolve(g(this.getResolvedPath(e))):this.resolve(e),s=r||this.machine.context;i=this.resolveState(M.from(o,s))}var a=Y(n),u=a.type;if(this.strict&&-1===this.events.indexOf(u)&&!function(e){return 0===e.indexOf(t.ActionTypes.DoneState)||0===e.indexOf(t.ActionTypes.DoneInvoke)||e===t.ActionTypes.ErrorCommunication||e===t.ActionTypes.ErrorExecution||0===e.indexOf(t.ActionTypes.ErrorPlatform)}(u))throw new Error("Machine '"+this.id+"' does not accept event '"+u+"'");var c=this._transition(i.value,i,a);return c.tree&&(c.tree=c.tree.resolved),this.resolveTransition(c,i,a)},e.prototype.resolveTransition=function(e,n,i){var u,c,h,d=this,f=e.tree?e.tree.value:void 0,p=n?n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0:void 0,v=n?n.context:e.context||this.machine.context,y=i||{type:t.ActionTypes.Init},g=this.getActions(e,n),m=n?r({},n.activities):{};try{for(var x=o(g),w=x.next();!w.done;w=x.next()){var b=w.value;b.type===R?m[b.activity.type]=b:b.type===z&&(m[b.activity.type]=!1)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(c=x.return)&&c.call(x)}finally{if(u)throw u.error}}var N=s(O(g,function(t){return t.type===U||t.type===J}),2),E=N[0],T=s(O(N[1],function(t){return t.type===q}),2),_=T[0],A=T[1],j=_.length?this.options.updater(v,y,_):v,I=S(A.map(function(e){if(e.type===B){var n=(o=e,s=j,a=y||{type:t.ActionTypes.Init},u=k(o.event)?Y(o.event(s,a)):Y(o.event),c=k(o.delay)?o.delay(s,a):o.delay,h=k(o.to)?o.to(s,a):o.to,r({},o,{to:h,event:u,delay:c}));if(V(n.delay)){if(!d.machine.options.delays||void 0===d.machine.options.delays[n.delay])return n;var i=d.machine.options.delays[n.delay];n.delay="number"==typeof i?i:i(j,y||{type:t.ActionTypes.Init})}return n}var o,s,a,u,c,h;return e.type===t.ActionTypes.Pure?e.get(j,y)||[]:$(e,d.options.actions)})),L=f?this.getStateNodes(f):[];L.some(function(t){return t._transient})&&E.push({type:J});var D,C,F=a([this],L).reduce(function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t},{}),X=new M({value:f||n.value,context:j,event:y||W,historyValue:f?p?(D=p,C=f,{current:C,states:P(D,C)}):void 0:n?n.historyValue:void 0,history:!f||e.source?n:void 0,actions:f?I:[],activities:f?m:n?n.activities:{},meta:f?F:n?n.meta:void 0,events:f?E:[],tree:f?e.tree:n?n.tree:void 0});X.changed=!!_.length;var G=X.history;if(G&&delete G.history,!f)return X;for(var H=X;E.length;){var K=H.actions,Q=E.shift();(H=this.transition(H,Q.type===J?yt:Q.event,H.context)).event=y,(h=H.actions).unshift.apply(h,a(K))}var Z=G?!!H.actions.length||!!_.length||typeof G.value!=typeof H.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(V("string"===e||typeof n))return e===n;var r=l(e),i=l(n);return r.length===i.length&&r.every(function(r){return t(e[r],n[r])})}(H.value,G.value):void 0;return H.changed=Z,H.historyValue=X.historyValue,H.history=G,H},e.prototype.ensureValidPaths=function(t){},e.prototype.getStateNode=function(t){if(mt(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=mt(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){if("string"==typeof t&&mt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=v(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},e.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||gt;switch(this.type){case"parallel":return m(this.initialStateValue,function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):gt});case"compound":if(V(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return l(t).length?m(t,function(t,e){return t?n.getStateNode(e).resolve(t):gt}):this.initialStateValue||{};default:return t||gt}},Object.defineProperty(e.prototype,"resolvedStateValue",{get:function(){var t,e,n=this.key;if("parallel"===this.type)return(t={})[n]=x(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(mt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return v(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var t="parallel"===this.type?x(this.states,function(t){return t.initialStateValue||gt},function(t){return!("history"===t.type)}):V(this.resolvedStateValue)?void 0:this.resolvedStateValue[this.key];return this.__cache.initialStateValue=t,this.__cache.initialStateValue},enumerable:!0,configurable:!0}),e.prototype.getInitialState=function(t,e){void 0===e&&(e=this.machine.context);var n=this.getStateTree(t);return this.getStateNodes(t).forEach(function(t){n.addReentryNode(t)}),this.resolveTransition({tree:n,source:void 0,actions:[],context:e})},Object.defineProperty(e.prototype,"initialState",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.__cache.initialState=this.getInitialState(t),this.__cache.initialState},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=e.target&&V(e.target)&&mt(e.target)?g(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(V(t))return[this.states[t]];var r=[];try{for(var i=o(l(t)),s=i.next();!s.done;s=i.next()){var u=s.value;r.push.apply(r,a(this.states[u].getStates(t[u])))}}catch(t){e={error:t}}finally{try{s&&!s.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),V(t)&&mt(t)){var r=this.getStateNodeById(t);return n?"history"===r.type?r.resolveHistory(e):r.initialStateNodes:[r]}var i=v(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return n?S(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?S(b(this.initialStateValue).map(function(e){return t.getFromRelativePath(e)})):[this]},enumerable:!0,configurable:!0}),e.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var n=s(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(l(this.states).length)return{current:t||this.initialStateValue,states:x(this.states,function(e,n){if(!t)return e.historyValue();var r=V(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?S(b(this.target).map(function(t){return n.getFromRelativePath(t)})):n.initialStateNodes;var r,i,s=(r=n.path,i="states",function(t){var e,n,s=t;try{for(var a=o(r),u=a.next();!u.done;u=a.next()){var c=u.value;s=s[i][c]}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return s})(t).current;return V(s)?[n.getStateNode(s)]:S(b(s).map(function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]}))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,e=S(l(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,s=new Set(this.ownEvents);if(i)try{for(var a=o(l(i)),u=a.next();!u.done;u=a.next()){var c=i[u.value];if(c.states)try{for(var h=o(c.events),d=h.next();!d.done;d=h.next()){var f=d.value;s.add(""+f)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(s)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ownEvents",{get:function(){var t=this,e=new Set(l(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,e,n){var i=this,o=e?e.internal:void 0,s=N(t),a=this.machine.options.guards,u=s.map(function(t){if(L(t))return"#"+t.id;var e=V(t)&&t[0]===i.delimiter;if(o=void 0===o?e:o,e&&!i.parent)return"#"+i.getStateNodeByPath(t.slice(1)).id;var n=e?i.key+t:""+t;return i.parent?"#"+i.parent.getStateNodeByPath(n).id:"#"+i.getStateNodeByPath(n).id});if(void 0===e)return{target:void 0===t?void 0:u,actions:[],internal:void 0===t||o,event:n};var c=void 0===t||""===t;return r({},e,{actions:tt(N(e.actions)),cond:j(e.cond,a),target:c?void 0:u,internal:c&&void 0===o||o,event:n})},e.prototype.formatTransitions=function(){var t,e,n,i=this,s=this.config.on||gt,a=this.config.onDone?((t={})[""+ht(this.id)]=this.config.onDone,t):void 0,u=this.invoke.reduce(function(t,e){return e.onDone&&(t[dt(e.id)]=e.onDone),e.onError&&(t[lt(e.id)]=e.onError),t},{}),c=this.after,h=m(r({},s,a,u),function(t,e){return void 0===t?[{target:void 0,event:e,actions:[],internal:!0}]:A(t)?t.map(function(t){return i.formatTransition(t.target,t,e)}):V(t)||L(t)?[i.formatTransition([t],void 0,e)]:[i.formatTransition(t.target,t,e)]});try{for(var d=o(c),l=d.next();!l.done;l=d.next()){var f=l.value;h[f.event]=h[f.event]||[],h[f.event].push(f)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(n=d.return)&&n.call(d)}finally{if(e)throw e.error}}return h},e}();var bt={deferEvents:!1},St=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r({},bt,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}();var Nt,Et=(Nt=[],function(t,e){t&&Nt.push(t);var n=e(t||Nt[Nt.length-1]);return t&&Nt.pop(),n}),Tt=function(){function e(n,i){var o=this;void 0===i&&(i=e.defaultOptions),this.machine=n,this.scheduler=new St,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(A(t))return o.batch(t),o.state;var n=Y(t,e);if(!o.initialized&&o.options.deferEvents);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:function(t){try{return"function"==typeof t.send}catch(t){return!1}}(n)?n: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+"'.")};var s=r({},e.defaultOptions,i),a=s.clock,u=s.logger,c=s.parent,h=s.id,d=void 0!==h?h:n.id;this.id=d,this.logger=u,this.clock=a,this.parent=c,this.options=s,this.scheduler=new St({deferEvents:this.options.deferEvents}),this.initialState=this.state=Et(this,function(){return o.machine.initialState})}return e.prototype.execute=function(t,e){var n,r;try{for(var i=o(t.actions),s=i.next();!s.done;s=i.next()){var a=s.value;this.exec(a,t.context,t.event,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,r,i,s,a,u,c,h;if(this.state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e,t),t.event)try{for(var d=o(this.eventListeners),l=d.next();!l.done;l=d.next()){(0,l.value)(t.event)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}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&&(s=f.return)&&s.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){a={error:t}}finally{try{y&&!y.done&&(u=v.return)&&u.call(v)}finally{if(a)throw a.error}}if(this.state.tree&&this.state.tree.done){var g=this.state.tree.getDoneData(this.state.context,Y(e));try{for(var m=o(this.doneListeners),x=m.next();!x.done;x=m.next()){(0,x.value)(dt(this.id,g))}}catch(t){c={error:t}}finally{try{x&&!x.done&&(h=m.return)&&h.call(m)}finally{if(c)throw c.error}}this.stop()}},e.prototype.onTransition=function(t){return this.listeners.add(t),this},e.prototype.subscribe=function(t,e,n){var r=this;return t&&this.onTransition(t),n&&this.onDone(n),{unsubscribe:function(){t&&r.listeners.delete(t),n&&r.doneListeners.delete(n)}}},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;if(this.initialized)return this;this.initialized=!0;var n=Et(this,function(){return void 0===t?e.machine.initialState:t instanceof M?e.machine.resolveState(t):e.machine.resolveState(M.from(t))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){e.update(n,{type:G})}),this},e.prototype.stop=function(){var t,e,n,r,i,s,a,u,c,h;try{for(var d=o(this.listeners),f=d.next();!f.done;f=d.next()){var p=f.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{f&&!f.done&&(e=d.return)&&e.call(d)}finally{if(t)throw t.error}}try{for(var v=o(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(n)throw n.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}try{for(var x=o(this.doneListeners),w=x.next();!w.done;w=x.next()){p=w.value;this.doneListeners.delete(p)}}catch(t){a={error:t}}finally{try{w&&!w.done&&(u=x.return)&&u.call(x)}finally{if(a)throw a.error}}this.children.forEach(function(t){k(t.stop)&&t.stop()});try{for(var b=o(l(this.delayedEventsMap)),S=b.next();!S.done;S=b.next()){var N=S.value;this.clock.clearTimeout(this.delayedEventsMap[N])}}catch(t){c={error:t}}finally{try{S&&!S.done&&(h=b.return)&&h.call(b)}finally{if(c)throw c.error}}return this.initialized=!1,this},e.prototype.batch=function(t){var e=this;if(!this.initialized&&this.options.deferEvents);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,s,u=e.state;try{for(var c=o(t),h=c.next();!h.done;h=c.next()){var d=h.value,l=u.changed,f=Y(d),p=u.actions.map(function(t){return n=u,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});(s=(u=e.machine.transition(u,f)).actions).unshift.apply(s,a(p)),u.changed=u.changed||!!l,e.forward(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(i=c.return)&&i.call(c)}finally{if(n)throw n.error}}e.update(u,Y(t[t.length-1]))})},e.prototype.nextState=function(t){var e=this,n=Y(t);if(0===n.type.indexOf(K)&&!this.state.nextEvents.some(function(t){return 0===t.indexOf(K)}))throw n.data;return Et(this,function(){return e.machine.transition(e.state,n,e.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 s=i.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+s+"'.");a.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(V(n)){if(!this.machine.options.delays||void 0===this.machine.options.delays[n])return;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,i){var o=Z(e.type,i)||e.exec,s=k(o)?o:o?o.exec:e.exec;if(s)return s(n,r,{action:e,state:this.state});switch(e.type){case B:var a=e;if(a.delay)return void this.defer(a);a.to?this.sendTo(a.event,a.to):this.send(a.event);break;case F:this.cancel(e.sendId);break;case R:var u=e.activity;if(!this.state.activities[u.type])break;if(u.type===t.ActionTypes.Invoke){var c=this.machine.options.services?this.machine.options.services[u.src]:void 0,h=u.id,d=u.data,l=!!u.forward;if(!c)return;var f=k(c)?c(n,r):c;T(f)?this.spawnPromise(Promise.resolve(f),h):k(f)?this.spawnCallback(f,h):I(f)?this.spawnObservable(f,h):L(f)&&this.spawnMachine(d?f.withContext(E(d,n,r)):f,{id:h,autoForward:l})}else this.spawnActivity(u);break;case z:this.stopChild(e.activity.id);break;case X:var p=e.expr?e.expr(n,r):void 0;e.label?this.logger(e.label,p):this.logger(p)}},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),k(e.stop)&&e.stop())},e.prototype.spawn=function(t,e){if(T(t))return this.spawnPromise(Promise.resolve(t),e);if(k(t))return this.spawnCallback(t,e);if(I(t))return this.spawnObservable(t,e);if(L(t))return this.spawnMachine(t,{id:e});throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".')},e.prototype.spawnMachine=function(t,n){var i=this;void 0===n&&(n={});var o=new e(t,r({},this.options,{parent:this,id:n.id||t.id}));return n.subscribe&&o.onTransition(function(t){i.send(Q,{state:t,id:o.id})}),o.onDone(function(t){i.send(t)}).start(),this.children.set(o.id,o),n.autoForward&&this.forwardTo.add(o.id),o},e.prototype.spawnPromise=function(t,e){var n=this,r=!1;t.then(function(t){r||n.send(dt(e,t))},function(t){if(!r){var i=lt(e,t);try{n.send(i)}catch(r){n.reportUnhandledExceptionOnInvocation(t,r,e),n.devTools&&n.devTools.send(i,n.state),n.machine.strict&&n.stop()}}});var i={id:e,send:function(){},subscribe:function(e,n,r){var i=!1;return t.then(function(t){i||(e&&e(t),i||r&&r())},function(t){i||n(t)}),{unsubscribe:function(){return i=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},e.prototype.spawnCallback=function(t,e){var n,r=this,i=!1,o=new Set;try{n=t(function(t){i||r.send(t)},function(t){o.add(t)})}catch(t){this.send(lt(e,t))}if(T(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach(function(e){return e(t)})},subscribe:function(t){return o.add(t),{unsubscribe:function(){o.delete(t)}}},stop:function(){i=!0,k(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},e.prototype.spawnObservable=function(t,e){var n=this,r=t.subscribe(function(t){n.send(t)},function(t){n.send(lt(e,t))},function(){n.send(dt(e))}),i={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return r.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},e.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},e.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},e.prototype.reportUnhandledExceptionOnInvocation=function(t,e,n){},e.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(r({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t,{features:r({jump:!1,skip:!1},t?t.features:void 0)})),this.devTools.init(this.state)}},e.prototype.toJSON=function(){return{id:this.id}},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=Pt,e}(),Ot=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}};function Pt(t,e){return new Tt(t,e)}var _t={raise:nt,send:rt,sendParent:it,log:function(t,e){return void 0===t&&(t=function(t,e){return{context:t,event:e}}),{type:X,label:e,expr:t}},cancel:ot,start:st,stop:at,assign:ut,after:ct,done:ht};t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new wt(t,e,n)},t.StateNode=wt,t.State=M,t.matchesState=f,t.mapState=function(t,e){var n,r,i;try{for(var s=o(l(t)),a=s.next();!a.done;a=s.next()){var u=a.value;f(u,e)&&(!i||e.length>i.length)&&(i=u)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}return t[i]},t.actions=_t,t.assign=ut,t.send=rt,t.sendParent=it,t.interpret=Pt,t.Interpreter=Tt,t.matchState=function(t,e,n){var r,i,a=M.from(t,t instanceof M?t.context:void 0);try{for(var u=o(e),c=u.next();!c.done;c=u.next()){var h=s(c.value,2),d=h[0],l=h[1];if(a.matches(d))return l(a)}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}return n(a)},t.spawn=function(t,e){return Et(void 0,function(n){return n?n.spawn(t,e||C()):Ot(e)})},Object.defineProperty(t,"__esModule",{value:!0})});
  