2 lines
48 KiB
JavaScript
2 lines
48 KiB
JavaScript
!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",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,a={};try{for(var s=o(l(t)),u=s.next();!u.done;u=s.next()){var c=u.value,h=t[c];n(h)&&(a[c]=e(h,c,t))}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}var w=function(t){return function(e){var n,r,i=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){i=i[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return i}};function 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,s(t))}function E(t){return A(t)?t:void 0===t?[]:[t]}function N(t,e,n){var r,i;if(k(t))return t(e,n);var a={};try{for(var s=o(l(t)),u=s.next();!u.done;u=s.next()){var c=u.value,h=t[c];k(h)?a[c]=h(e,n):a[c]=h}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}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=a([[],[]],2),s=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)?s.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[s,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,a,s=r.assignment,u={};if(k(s))u=s(e,n||{type:t.ActionTypes.Init});else try{for(var c=o(l(s)),h=c.next();!h.done;h=c.next()){var d=h.value,f=s[d];u[d]=k(f)?f(e,n):f}}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=c.return)&&a.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,s(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,F=t.ActionTypes.Raise,U=t.ActionTypes.Send,B=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 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}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:F,event:t}}function rt(t,e){return{to:e?e.to:void 0,type:U,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:B,sendId:t}};function at(e){var n=et(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function st(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 a,s=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)?((a={})[n]=new t(e.getStateNode(n),void 0,void 0,this),a):m(n,function(n,r){return new t(e.getStateNode(r),n,void 0,s)}):{};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 N(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 a=new t(this.stateNode.machine,n);return a.reentryNodes=this.reentryNodes,a},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 s(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 a=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]),a=e,i.nodes=a,i}return a=Object.assign({},this.nodes,t.nodes),i.nodes=a,i}if("parallel"===this.stateNode.type){var c=new Set(s(l(this.nodes),l(t.nodes)));a={};try{for(var h=o(c),d=h.next();!d.done;d=h.next()){var f=d.value;this.nodes[f]&&t.nodes[f]?a[f]=this.nodes[f].combine(t.nodes[f]):a[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=a,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:s(i)};if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var a={exit:[],entry:[]},u=l(this.nodes)[0],c=l(t.nodes)[0];return u!==c?(a.exit=t.nodes[c].getExitStates(),a.entry=this.nodes[u].getEntryStates()):a=this.nodes[u].getEntryExitStates(t.nodes[c]),i&&i.has(this.stateNode)&&(a.exit.push(this.stateNode),a.entry.unshift(this.stateNode)),a;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=s(d.exit,v.exit),d.entry=s(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}();function vt(t){return l(t.states).map(function(e){return t.states[e]})}function yt(t,e){var n,r,i,a,s,u,c=gt(new Set(t)),h=new Set(e);try{for(var d=o(h),l=d.next();!l.done;l=d.next())for(var f=(g=l.value).parent;f&&!h.has(f);)h.add(f),f=f.parent}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var p=gt(h);try{for(var v=o(h),y=v.next();!y.done;y=v.next()){var g;if("compound"!==(g=y.value).type||p.get(g)&&p.get(g).length){if("parallel"===g.type)try{for(var m=o(vt(g)),x=m.next();!x.done;x=m.next()){var w=x.value;h.has(w)||(h.add(w),c.get(w)?c.get(w).forEach(function(t){return h.add(t)}):w.initialStateNodes.forEach(function(t){return h.add(t)}))}}catch(t){s={error:t}}finally{try{x&&!x.done&&(u=m.return)&&u.call(m)}finally{if(s)throw s.error}}}else c.get(g)?c.get(g).forEach(function(t){return h.add(t)}):g.initialStateNodes.forEach(function(t){return h.add(t)})}}catch(t){i={error:t}}finally{try{y&&!y.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}return h}function gt(t){var e,n,r=new Map;try{for(var i=o(t),a=i.next();!a.done;a=i.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}function mt(t,e){return function t(e,n){var r={},i=n.get(e);if(!i)return{};if("compound"===e.type){if(!i[0])return{};if("atomic"===i[0].type)return i[0].key}return i.forEach(function(e){r[e.key]=t(e,n)}),r}(t,gt(yt([t],e)))}var xt=".",wt="",bt={},St=function(t){return"#"===t[0]},Et=function(){return{actions:{},guards:{},services:{},activities:{},delays:{},updater:_}},Nt=function(){function e(t,n,o){var a=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({},Et(),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:xt),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&&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 s,u=new e(r({},t,{key:n,order:void 0===t.order?o:t.order,parent:a}));return Object.assign(a.idMap,r(((s={})[u.id]=u,s),u.idMap)),u}):bt,this.history=!0===t.history?"shallow":t.history||!1,this._transient=!(!t.on||!t.on[wt]),this.strict=!!t.strict,this.onEntry=E(t.entry||t.onEntry).map(function(t){return $(t)}),this.onExit=E(t.exit||t.onExit).map(function(t){return $(t)}),this.meta=t.meta,this.data="final"===this.type?t.data:void 0,this.invoke=E(t.invoke).map(function(t,e){var n,i;if(L(t))return(a.parent||a).options.services=r(((n={})[t.id]=t,n),(a.parent||a).options.services),{type:H,src:t.id,id:t.id};if("string"!=typeof t.src){var o=a.id+":invocation["+e+"]";return a.machine.options.services=r(((i={})[o]=t.src,i),a.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=E(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,a=i.activities,s=i.guards,u=i.services,c=i.delays;return new e(this.config,{actions:r({},o,t.actions),activities:r({},a,t.activities),guards:r({},s,t.guards),services:r({},u,t.services),delays:r({},c,t.delays)},n)},e.prototype.withContext=function(t){return new e(this.config,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,a=e.delay,s=e.target;k(a)?(o=t.id+":delay["+i+"]",t.options.delays[o]=a):o=a;var u=ct(o,t.id);return t.onEntry.push(rt(u,{delay:a})),t.onExit.push(ot(u)),r({event:u},e,{source:t,target:void 0===s?void 0:E(s),cond:j(e.cond,n),actions:E(e.actions).map(function(t){return $(t)})})});var i=S(l(e).map(function(i){var o=e[i],a=isNaN(+i)?i:+i,s=ct(a,t.id);return t.onEntry.push(rt(s,{delay:a})),t.onExit.push(ot(s)),V(o)?[{source:t,target:[o],delay:a,event:s,actions:[]}]:E(o).map(function(e){return r({event:s,delay:a},e,{source:t,target:void 0===e.target?e.target:E(e.target),cond:j(e.cond,n),actions:E(e.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,transitions:i.transitions,configuration:i.configuration,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),a=o.actions;return{tree:o.tree,transitions:o.transitions,configuration:o.configuration,source:e,actions:a}}return i},e.prototype.transitionParallelNode=function(t,e,n){var r,i,a={};try{for(var s=o(l(t)),u=s.next();!u.done;u=s.next()){var c=u.value,h=t[c];if(h){var d=this.getStateNode(c)._transition(h,e,n);d.tree,a[c]=d}}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}var p=l(a).map(function(t){return a[t]}),v=S(p.map(function(t){return t.transitions}));if(!p.some(function(t){return void 0!==t.tree})){var g=this.next(e,n),m=g.actions;return{tree:g.tree,transitions:g.transitions,configuration:g.configuration,source:e,actions:m}}var x=S(p.map(function(t){return t.configuration})),w=this.getStateNodes(t),b=mt(this.machine,yt(w,x)),E=new pt(this.machine,b),N=E.paths,T=S(l(a).map(function(t){return a[t].configuration}));return 1!==N.length||f(y(this.path,this.delimiter),E.value),{tree:E,transitions:v,configuration:T,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,n){var r,i,a=this,u=n.type,c=this.on[u];if(!c||!c.length)return{tree:void 0,transitions:[],configuration:[],source:t,actions:[]};var h,d=this._transient?[{type:J}]:[],l=[];try{for(var p=o(c),v=p.next();!v.done;v=p.next()){var g=v.value,m=g.cond,x=g.in,b=t.context,N=!x||(V(x)&&St(x)?t.matches(y(this.getStateNodeById(x).path,this.delimiter)):f(y(x,this.delimiter),w(this.path.slice(0,-2))(t.value))),T=!1;try{T=!m||this.evaluateGuard(m,b,n,t)}catch(t){throw new Error("Unable to evaluate guard '"+(m.name||m.type)+"' in transition for event '"+u+"' in state node '"+this.id+"':\n"+t.message)}if(T&&N){void 0!==g.target&&(l=g.target),d.push.apply(d,s(E(g.actions))),h=g;break}}}catch(t){r={error:t}}finally{try{v&&!v.done&&(i=p.return)&&i.call(p)}finally{if(r)throw r.error}}if(!l.length)return{tree:h&&t.value?new pt(this,w(this.path)(t.value)).absolute:void 0,transitions:[h],configuration:h&&t.value?[this]:[],source:t,actions:d};var O=S(l.map(function(n){return n instanceof e?n:a.getRelativeStateNodes(n,t.historyValue)})),P=!!h.internal?[]:S(O.map(function(t){return a.nodesFromChild(t)})),_=O.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)});return P.forEach(function(t){return _.addReentryNode(t)}),{tree:_,transitions:[h],configuration:O,source:t,actions:d}},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=a([S(Array.from(i).map(function(t){return s(t.activities.map(function(t){return at(t)}),t.onEntry)})).concat(r.map(nt)),S(Array.from(o).map(function(t){return s(t.onExit,t.activities.map(function(t){return st(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),a=r||this.machine.context;i=this.resolveState(M.from(o,a))}var s=Y(n),u=s.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,s);return c.tree&&(c.tree=c.tree.resolved),this.resolveTransition(c,i,s)},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 E=a(O(g,function(t){return t.type===F||t.type===J}),2),N=E[0],T=a(O(E[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===U){var n=(o=e,a=j,s=y||{type:t.ActionTypes.Init},u=k(o.event)?Y(o.event(a,s)):Y(o.event),c=k(o.delay)?o.delay(a,s):o.delay,h=k(o.to)?o.to(a,s):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,a,s,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})&&N.push({type:J});var D,C,B=s([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?B:n?n.meta:void 0,events:f?N:[],tree:f?e.tree:n?n.tree:void 0});X.changed=y.type===Q||!!_.length;var G=X.history;if(G&&delete G.history,!f)return X;for(var H=X;N.length;){var K=H.actions,Z=N.shift();(H=this.transition(H,Z.type===J?wt:Z.event,H.context)).event=y,(h=H.actions).unshift.apply(h,s(K))}var tt=H.changed||(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(e)||V(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=tt,H.historyValue=X.historyValue,H.history=G,H},e.prototype.ensureValidPaths=function(t){},e.prototype.getStateNode=function(t){if(St(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=St(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},e.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&St(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||bt;switch(this.type){case"parallel":return m(this.initialStateValue,function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):bt});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):bt}):this.initialStateValue||{};default:return t||bt}},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(St(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||bt},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),r=this.getStateNodes(t);return r.forEach(function(t){n.addReentryNode(t)}),this.resolveTransition({tree:n,configuration:r,transitions:[],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)&&St(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)),a=i.next();!a.done;a=i.next()){var u=a.value;r.push.apply(r,s(this.states[u].getStates(t[u])))}}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),V(t)&&St(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=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(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,a=(r=n.path,i="states",function(t){var e,n,a=t;try{for(var s=o(r),u=s.next();!u.done;u=s.next()){var c=u.value;a=a[i][c]}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return a})(t).current;return V(a)?[n.getStateNode(a)]:S(b(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=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,a=new Set(this.ownEvents);if(i)try{for(var s=o(l(i)),u=s.next();!u.done;u=s.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;a.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=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(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,a=E(t),s=this.machine.options.guards,u=a.map(function(t){if(!V(t))return"#"+t.id;var e=t[0]===i.delimiter;if(o=void 0===o?e:o,e&&!i.parent)return"#"+i.getStateNodeByPath(t.slice(1)).id;var r=e?i.key+t:""+t;if(!i.parent)return"#"+i.getStateNodeByPath(r).id;try{return"#"+i.parent.getStateNodeByPath(r).id}catch(t){throw new Error("Invalid transition for state node '"+i.id+"' on event '"+n+"':\n"+t.message)}});if(void 0===e)return{target:void 0===t?void 0:u,source:this,actions:[],internal:void 0===t||o,event:n};var c=void 0===t||""===t;return r({},e,{actions:tt(E(e.actions)),cond:j(e.cond,s),target:c?void 0:u,source:this,internal:c&&void 0===o||o,event:n})},e.prototype.formatTransitions=function(){var t,e,n,i=this,a=this.config.on||bt,s=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({},a,s,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 Tt={deferEvents:!1},Ot=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r({},Tt,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 Pt,_t={sync:!1,autoForward:!1},At=(Pt=[],function(t,e){t&&Pt.push(t);var n=e(t||Pt[Pt.length-1]);return t&&Pt.pop(),n}),kt=function(){function e(n,i){var o=this;void 0===i&&(i=e.defaultOptions),this.machine=n,this.scheduler=new Ot,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.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 a=r({},e.defaultOptions,i),s=a.clock,u=a.logger,c=a.parent,h=a.id,d=void 0!==h?h:n.id;this.id=d,this.logger=u,this.clock=s,this.parent=c,this.options=a,this.scheduler=new Ot({deferEvents:this.options.deferEvents}),this.initialState=this.state=At(this,function(){return o.machine.initialState})}return e.prototype.execute=function(t,e){var n,r;try{for(var i=o(t.actions),a=i.next();!a.done;a=i.next()){var s=a.value;this.exec(s,t.context,t.event,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,r,i,a,s,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&&(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&&(u=v.return)&&u.call(v)}finally{if(s)throw s.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=At(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,a,s,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&&(a=g.return)&&a.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){s={error:t}}finally{try{w&&!w.done&&(u=x.return)&&u.call(x)}finally{if(s)throw s.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 E=S.value;this.clock.clearTimeout(this.delayedEventsMap[E])}}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,a,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});(a=(u=e.machine.transition(u,f)).actions).unshift.apply(a,s(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.sender=function(t){return this.send.bind(this,t)},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 At(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 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(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,a=k(o)?o:o?o.exec:e.exec;if(a)return a(n,r,{action:e,state:this.state});switch(e.type){case U:var s=e;if(s.delay)return void this.defer(s);s.to?this.sendTo(s.event,s.to):this.send(s.event);break;case B: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="autoForward"in u?u.autoForward:!!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(N(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,n){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,r({},n,{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})),a=r({},_t,n);a.sync&&o.onTransition(function(t){i.send(Q,{state:t,id:o.id})}),o.onDone(function(t){i.send(t)}).start();var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),s},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 a={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,a),a},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=It,e}(),Vt=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},jt=function(t){return V(t)?r({},_t,{name:t}):r({},_t,{name:C()},t)};function It(t,e){return new kt(t,e)}var Lt={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:at,stop:st,assign:ut,after:ct,done:ht};t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Nt(t,e,n)},t.StateNode=Nt,t.State=M,t.matchesState=f,t.mapState=function(t,e){var n,r,i;try{for(var a=o(l(t)),s=a.next();!s.done;s=a.next()){var u=s.value;f(u,e)&&(!i||e.length>i.length)&&(i=u)}}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=Lt,t.assign=ut,t.send=rt,t.sendParent=it,t.interpret=It,t.Interpreter=kt,t.matchState=function(t,e,n){var r,i,s=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=a(c.value,2),d=h[0],l=h[1];if(s.matches(d))return l(s)}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}return n(s)},t.spawn=function(t,e){var n=jt(e);return At(void 0,function(e){return e?e.spawn(t,n.name,n):Vt(n.name)})},Object.defineProperty(t,"__esModule",{value:!0})});
|