Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 | !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.xstateInterpreter={})}(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){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 o(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 a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.Null="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var s=e.Start,u=e.Stop,c=e.Raise,h=e.Send,f=e.Cancel,p=e.Null,d=e.Assign,l=(e.After,e.DoneState,e.Log),y=(e.Init,e.Invoke,"."),v={};function g(t){return"string"!=typeof t&&("value"in t&&"tree"in t&&"history"in t)}function m(t){return Object.keys(t)}function S(t,e,n){void 0===n&&(n=y);var r=x(t,n),i=x(e,n);return"string"==typeof i?"string"==typeof r&&i===r:"string"==typeof r?r in i:m(r).every(function(t){return t in i&&S(r[t],i[t])})}function b(t){try{return"string"==typeof t||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function w(t,e){try{return Array.isArray(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function x(t,e){return g(t)?t.value:Array.isArray(t)?N(t):"string"==typeof t||g(t)?N(w(t,e)):t}function N(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 E(t,e){var n={};return m(t).forEach(function(r,i){n[r]=e(t[r],r,t,i)}),n}function O(t,e,n){var r={};return m(t).forEach(function(i){var o=t[i];n(o)&&(r[i]=e(o,i,t))}),r}var P=function(t){return function(e){var n,r,o=e;try{for(var a=i(t),s=a.next();!s.done;s=a.next()){o=o[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 o}};var j=function(t){return t?"string"==typeof t?[[t]]:A(m(t).map(function(e){return j(t[e]).map(function(t){return[e].concat(t)})})):[[]]};function A(t){var e;return(e=[]).concat.apply(e,a(t))}function _(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function k(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function V(t,e){if(e){var n=e[t];if(n)return"function"==typeof n?n:n.exec}}var T=function(t,e){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:V(t,e)};else{if("function"!=typeof t){var i=V(t.type,e);return i?r({},t,{exec:i}):t}n={type:t.name,exec:t}}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1}),n};function I(t){var e=T(t);return r({id:"string"==typeof t?t:e.id},e,{type:e.type})}function L(t){return{type:c,event:t}}function C(t){var n=I(t);return{type:e.Start,activity:n,exec:void 0}}function M(t,n){var r=n?"#"+n:"";return e.After+"("+t+")"+r}function R(t){return e.DoneState+"."+t}var D=function(){function t(t,e,n,r,i,o,a,s,u){void 0===i&&(i=[]),void 0===o&&(o=v),void 0===a&&(a={}),void 0===s&&(s=[]),this.value=t,this.context=e,this.historyValue=n,this.history=r,this.actions=i,this.activities=o,this.data=a,this.events=s,Object.defineProperty(this,"tree",{value:u,enumerable:!1})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t(e.value,n,e.historyValue,e.history,[],e.activities,{},[],e.tree):e:new t(e,n,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,n){return e instanceof t?e.actions.length?new t(e.value,n,e.historyValue,e.history,void 0,e.activities,void 0,void 0,e.tree):e:t.from(e,n)},Object.defineProperty(t.prototype,"nextEvents",{get:function(){return this.tree?this.tree.nextEvents:[]},enumerable:!0,configurable:!0}),t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),"string"==typeof t)return[t];var r=m(t);return r.concat.apply(r,a(r.map(function(r){return n.toStrings(t[r]).map(function(t){return r+e+t})})))},t.prototype.matches=function(t){return S(t,this.value)},Object.defineProperty(t.prototype,"changed",{get:function(){if(this.history)return!!this.actions.length||typeof this.history.value!=typeof this.value||("string"==typeof this.value?this.value!==this.history.value:function t(e,n){if(e===n)return!0;var r=m(e),i=m(n);return r.length===i.length&&r.every(function(r){return t(e[r],n[r])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}(),F={resolved:!1},z=function(){function t(e,n,i){var o;void 0===i&&(i=F),this.stateNode=e,this._stateValue=n,this.nodes=n?"string"==typeof n?((o={})[n]=new t(e.getStateNode(n),void 0),o):E(n,function(n,r){return new t(e.getStateNode(r),n)}):{};var a=r({},F,i);this.isResolved=a.resolved}return Object.defineProperty(t.prototype,"done",{get:function(){var t=this;switch(this.stateNode.type){case"final":return!0;case"compound":return"final"===this.nodes[m(this.nodes)[0]].stateNode.type;case"parallel":return m(this.nodes).some(function(e){return t.nodes[e].done});default:return!1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"atomicNodes",{get:function(){var t=this;return"atomic"===this.stateNode.type||"final"===this.stateNode.type?[this.stateNode]:A(m(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[R(this.stateNode.id)];var n=A(m(this.nodes).map(function(n){return e.nodes[n].getDoneEvents(t)}));if("parallel"===this.stateNode.type){var r=m(this.nodes).every(function(t){return e.nodes[t].done});return n&&r?[R(this.stateNode.id)].concat(n):n}return this.done&&n.length?[R(this.stateNode.id)].concat(n):n},Object.defineProperty(t.prototype,"resolved",{get:function(){return new t(this.stateNode,this.stateNode.resolve(this.value),{resolved:!0})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return j(this.value)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absolute",{get:function(){var e=this,n=this._stateValue,r={},i=r;return this.stateNode.path.forEach(function(t,r){r===e.stateNode.path.length-1?i[t]=n:(i[t]={},i=i[t])}),new t(this.stateNode.machine,r)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"nextEvents",{get:function(){var t=this,e=this.stateNode.ownEvents,n=A(m(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)},t.prototype.combine=function(t){var e,n=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot combine distinct trees");if("compound"===this.stateNode.type){var r=void 0;if(m(this.nodes).length&&m(t.nodes).length){var i=m(this.nodes)[0];return(e={})[i]=this.nodes[i].combine(t.nodes[i]),r=e,(o=this.clone()).nodes=r,o}return r=Object.assign({},this.nodes,t.nodes),(o=this.clone()).nodes=r,o}if("parallel"===this.stateNode.type){var o,s=new Set(a(m(this.nodes),m(t.nodes))),u={};return s.forEach(function(e){n.nodes[e]&&t.nodes[e]?u[e]=n.nodes[e].combine(t.nodes[e]):u[e]=n.nodes[e]||t.nodes[e]}),(o=this.clone()).nodes=u,o}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 E(this.nodes,function(t){return t.value});if("compound"===this.stateNode.type){if(0===m(this.nodes).length)return{};var t=this.nodes[m(this.nodes)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:E(this.nodes,function(t){return t.value})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return S(t,this.value)},t.prototype.getEntryExitStates=function(t,e){var n=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var r={exit:[],entry:[]},i=m(this.nodes)[0],o=m(t.nodes)[0];return i!==o?(r.exit=t.nodes[o].getExitStates(),r.entry=this.nodes[i].getEntryStates()):r=this.nodes[i].getEntryExitStates(t.nodes[o],e),e&&e.has(this.stateNode)&&(r.exit.push(this.stateNode),r.entry.unshift(this.stateNode)),r;case"parallel":var s=m(this.nodes).map(function(r){return n.nodes[r].getEntryExitStates(t.nodes[r],e)}),u={exit:[],entry:[]};return s.forEach(function(t){u.exit=a(u.exit,t.exit),u.entry=a(u.entry,t.entry)}),e&&e.has(this.stateNode)&&(u.exit.push(this.stateNode),u.entry.unshift(this.stateNode)),u;case"atomic":default:return e&&e.has(this.stateNode)?{exit:[this.stateNode],entry:[this.stateNode]}:{exit:[],entry:[]}}},t.prototype.getEntryStates=function(){var t=this;return this.nodes?[this.stateNode].concat(A(m(this.nodes).map(function(e){return t.nodes[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.nodes?A(m(this.nodes).map(function(e){return t.nodes[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),B=".",H="",Q={},U=function(t){return"#"===t[0]},G=function(){return{guards:Q}},J=function(){function t(e,n,i){void 0===n&&(n=G());var o=this;this._config=e,this.options=n,this.context=i,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.key=e.key||e.id||"(machine)",this.type=e.type||(e.parallel?"parallel":e.states&&m(e.states).length?"compound":e.history?"history":"atomic"),this.parent=e.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=e.delimiter||(this.parent?this.parent.delimiter:B),this.id=e.id||(this.machine?a([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=e.initial,this.order=e.order||-1,this.states=e.states?E(e.states,function(e,n,i,a){var s,u=new t(r({},e,{key:n,order:void 0===e.order?e.order:a,parent:o}));return Object.assign(o.idMap,r(((s={})[u.id]=u,s),u.idMap)),u}):Q,this.history=!0===e.history?"shallow":e.history||!1,this.transient=!(!e.on||!e.on[H]),this.strict=!!e.strict,this.onEntry=_(e.onEntry),this.onExit=_(e.onExit),this.data=e.data,this.activities=_(e.activities).map(function(t){return o.resolveActivity(t)})}return t.prototype.withConfig=function(e,n){return new t(this.definition,{actions:r({},this.options.actions,e.actions),activities:r({},this.options.activities,e.activities),guards:r({},this.options.guards,e.guards)},n)},Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:E(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||[],data:this.data,order:this.order||-1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"config",{get:function(){var t=this._config;t.parent;return function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}(t,["parent"])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"on",{get:function(){return this.formatTransitions()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){var t=this,e=this.config.after;if(!e)return[];if(Array.isArray(e))return e.map(function(e){return r({event:M(e.delay,t.id)},e,{actions:_(e.actions)})});var n=A(m(e).map(function(n){var i=e[n],o=+n,a=M(o,t.id);return"string"==typeof i?[{target:i,delay:o,event:a,actions:[]}]:_(i).map(function(t){return r({event:a,delay:o},t,{actions:_(t.actions)})})}));return n.sort(function(t,e){return t.delay-e.delay}),n},enumerable:!0,configurable:!0}),t.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof D?t.value:x(t,this.delimiter);if("string"==typeof r){var i=this.getStateNode(r).initial;return i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=m(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)},[]))},t.prototype.handles=function(t){var e=b(t);return-1!==this.events.indexOf(e)},t.prototype.transitionLeafNode=function(t,e,n,r){var i=this.getStateNode(t).next(e,n,r);if(!i.tree){var o=this.next(e,n,r),a=o.reentryStates,s=o.actions;return{tree:o.tree,source:e,reentryStates:a,actions:s}}return i},t.prototype.transitionCompoundNode=function(t,e,n,r){var i=m(t),o=this.getStateNode(i[0])._transition(t[i[0]],e,n,r);if(!o.tree){var a=this.next(e,n,r),s=a.reentryStates,u=a.actions;return{tree:a.tree,source:e,reentryStates:s,actions:u}}return o},t.prototype.transitionParallelNode=function(t,e,n,r){var i=this,o={};if(m(t).forEach(function(a){var s=t[a];if(s){var u=i.getStateNode(a)._transition(s,e,n,r);u.tree,o[a]=u}}),!m(o).some(function(t){return void 0!==o[t].tree})){var s=this.next(e,n,r),u=s.reentryStates,c=s.actions;return{tree:s.tree,source:e,reentryStates:u,actions:c}}var h=m(o).map(function(t){return o[t].tree}).filter(function(t){return void 0!==t}).reduce(function(t,e){return t.combine(e)});return 1!==h.paths.length||S(x(this.path,this.delimiter),h.value)?{tree:m(o).map(function(t){var n=o[t],r=P(i.path)(n.tree?n.tree.value:e.value||e.value)[t];return new z(i.getStateNode(t),r).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,reentryStates:m(o).reduce(function(t,e){var n=o[e],r=n.tree,i=n.reentryStates;return r&&i?new Set(a(Array.from(t),Array.from(i))):t},new Set),actions:A(m(o).map(function(t){return o[t].actions}))}:{tree:h,source:e,reentryStates:m(o).map(function(t){return o[t].reentryStates}).reduce(function(t,e){return new Set(a(Array.from(t||[]),Array.from(e||[])))},new Set),actions:A(m(o).map(function(t){return o[t].actions}))}},t.prototype._transition=function(t,e,n,r){return"string"==typeof t?this.transitionLeafNode(t,e,n,r):1===m(t).length?this.transitionCompoundNode(t,e,n,r):this.transitionParallelNode(t,e,n,r)},t.prototype.next=function(t,e,n){var r,o,s=this,u=e.type,c=this.on[u],h=this.transient?[{type:p}]:[];if(!c||!c.length)return{tree:void 0,source:t,reentryStates:void 0,actions:h};var f,d=[];try{for(var l=i(c),y=l.next();!y.done;y=l.next()){var v=y.value,g=v,m=g.cond,b=g.in,w=n||Q,N=!b||S(x(b,this.delimiter),P(this.path.slice(0,-2))(t.value));if((!m||this.evaluateGuard(m,w,e,t.value))&&N){d=_(v.target),h.push.apply(h,a(_(v.actions))),f=v;break}}}catch(t){r={error:t}}finally{try{y&&!y.done&&(o=l.return)&&o.call(l)}finally{if(r)throw r.error}}if(f&&0===d.length)return{tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,reentryStates:void 0,actions:h};if(!f&&0===d.length)return{tree:void 0,source:t,reentryStates:void 0,actions:h};var E=A(d.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),O=!!f.internal?[]:A(E.map(function(t){return s.nodesFromChild(t)}));return{tree:E.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)}),source:t,reentryStates:new Set(O),actions:h}},Object.defineProperty(t.prototype,"tree",{get:function(){var t=x(this.path,this.delimiter);return new z(this.machine,t)},enumerable:!0,configurable:!0}),t.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},t.prototype.getStateTree=function(t){return new z(this,t)},t.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},t.prototype.evaluateGuard=function(t,e,n,r){var i,o=this.machine.options.guards;if("string"==typeof t){if(!o||!o[t])throw new Error("Condition '"+t+"' is not implemented on machine '"+this.machine.id+"'.");i=o[t]}else i=t;return i(e,n,r)},Object.defineProperty(t.prototype,"delays",{get:function(){var t=this;return Array.from(new Set(this.after.map(function(t){return t.delay}))).map(function(e){return{id:t.id,delay:e}})},enumerable:!0,configurable:!0}),t.prototype.getActions=function(t,n){var r=this,i=t.tree?t.tree.resolved.getEntryExitStates(this.getStateTree(n.value),t.reentryStates?t.reentryStates:void 0):{entry:[],exit:[]},o=t.tree?t.tree.getDoneEvents(new Set(i.entry)):[];t.source||(i.exit=[]);var s={entry:A(Array.from(new Set(i.entry)).map(function(t){return a(t.onEntry,t.activities.map(function(t){return C(t)}),t.delays.map(function(t){var e,n,r=t.delay,i=t.id;return e=M(r,i),{target:(n={delay:r})?n.target:void 0,type:h,event:k(e),delay:n?n.delay:void 0,id:n&&void 0!==n.id?n.id:b(e)}}))})).concat(o.map(L)),exit:A(Array.from(new Set(i.exit)).map(function(t){return a(t.onExit,t.activities.map(function(t){return function(t){var n=I(t);return{type:e.Stop,activity:n,exec:void 0}}(t)}),t.delays.map(function(t){var e,n=t.delay,r=t.id;return e=M(n,r),{type:f,sendId:e}}))}))};return s.exit.concat(t.actions).concat(s.entry).map(function(t){return"string"==typeof t?r.resolveAction(t):t})},t.prototype.resolveAction=function(t){var e=this.machine.options.actions;return(e?e[t]:t)||t},t.prototype.resolveActivity=function(t){return I(t)},t.prototype.getActivities=function(t,e){if(!t)return Q;var n=r({},e);return Array.from(t.exit).forEach(function(t){t.activities&&t.activities.forEach(function(t){n[t.type]=!1})}),Array.from(t.entry).forEach(function(t){t.activities&&t.activities.forEach(function(t){n[t.type]=!0})}),n},t.prototype.transition=function(t,e,n){var i="string"==typeof t?this.resolve(N(this.getResolvedPath(t))):t instanceof D?t:this.resolve(t),o=n||(t instanceof D?t.context:void 0),a=k(e),s=a.type;if(this.strict&&-1===this.events.indexOf(s))throw new Error("Machine '"+this.id+"' does not accept event '"+s+"'");var u=D.from(i,o),c=this._transition(u.value,u,a,o),h=r({},c,{tree:c.tree?c.tree.resolved:void 0});return this.resolveTransition(h,u,a)},t.prototype.resolveTransition=function(e,n,r){var i,o=e.tree?e.tree.value:void 0,s=n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0,u=this.getActions(e,n),h=e.tree?e.tree.getEntryExitStates(this.getStateTree(n.value)):{entry:[],exit:[]},f=e.tree?this.getActivities({entry:new Set(h.entry),exit:new Set(h.exit)},n.activities):{},l=u.filter(function(t){return"object"==typeof t&&(t.type===c||t.type===p)}),y=u.filter(function(t){return"object"!=typeof t||t.type!==c&&t.type!==p&&t.type!==d}),v=u.filter(function(t){return"object"==typeof t&&t.type===d}),g=t.updateContext(n.context,r,v),m=o?this.getStateNodes(o):[];m.some(function(t){return t.transient})&&l.push({type:p});var S,b,w=a([this],m).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),x=o?new D(o,g,s?t.updateHistoryValue(s,o):void 0,e.source?n:void 0,(S=y,b=this.options.actions,S?(Array.isArray(S)?S:[S]).map(function(t){return T(t,b)}):[]),f,w,l,e.tree):void 0;if(!x)return D.inert(n,g);n.history&&delete n.history.history;for(var N=x;l.length;){var E=N.actions,O=l.shift();(i=(N=this.transition(N,O.type===p?H:O.event,N.context)).actions).unshift.apply(i,a(E))}return N},t.updateContext=function(t,n,r){return t?r.reduce(function(t,r){var i=r.assignment,o={};return"function"==typeof i?o=i(t,n||{type:e.Init}):m(i).forEach(function(e){var r=i[e];o[e]="function"==typeof r?r(t,n):r}),Object.assign({},t,o)},t):t},t.prototype.ensureValidPaths=function(t){var e,n,r=this,o=new Map,a=A(t.map(function(t){return r.getRelativeStateNodes(t)}));try{t:for(var s=i(a),u=s.next();!u.done;u=s.next())for(var c=u.value,h=c;h.parent;){if(o.has(h.parent)){if("parallel"===h.parent.type)continue t;throw new Error("State node '"+c.id+"' shares parent '"+h.parent.id+"' with state node '"+o.get(h.parent).map(function(t){return t.id})+"'")}o.get(h.parent)?o.get(h.parent).push(c):o.set(h.parent,[c]),h=h.parent}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}},t.prototype.getStateNode=function(t){if(U(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},t.prototype.getStateNodeById=function(t){var e=U(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},t.prototype.getStateNodeByPath=function(t){for(var e=w(t,this.delimiter),n=this;e.length;){var r=e.shift();n=n.getStateNode(r)}return n},t.prototype.resolve=function(t){var e,n=this;if("string"==typeof t){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return m(t).length?"parallel"===this.type?E(this.initialStateValue,function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Q}):E(t,function(t,e){return t?n.getStateNode(e).resolve(t):Q}):this.initialStateValue||{}},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,n=this.key;return"parallel"===this.type?((t={})[n]=O(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[n]=this.states[this.initial].resolvedStateValue,e):n},enumerable:!0,configurable:!0}),t.prototype.getResolvedPath=function(t){if(U(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return w(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?O(this.states,function(t){return t.initialStateValue||Q},function(t){return!t.history}):"string"==typeof this.resolvedStateValue?void 0:this.resolvedStateValue[this.key];return this.__cache.initialState=t,this.__cache.initialState},enumerable:!0,configurable:!0}),t.prototype.getInitialState=function(e,n){void 0===n&&(n=this.machine.context);var r={},i=[];this.getStateNodes(e).forEach(function(t){t.onEntry&&i.push.apply(i,a(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[b(t)]=!0,i.push(C(t))})});var o=i.filter(function(t){return"object"==typeof t&&t.type===d}),s=t.updateContext(n,void 0,o);return new D(e,s,void 0,void 0,void 0,r,void 0,[])},Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");var e=this.getInitialState(t);return this.resolveTransition({tree:this.getStateTree(t),source:void 0,reentryStates:new Set(this.getStateNodes(t)),actions:[]},e,void 0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var t;if(this.history){var e=this.config;t=e.target&&"string"==typeof e.target&&U(e.target)?N(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),t.prototype.getStates=function(t){var e=this;if("string"==typeof t)return[this.states[t]];var n=[];return m(t).forEach(function(r){n.push.apply(n,a(e.states[r].getStates(t[r])))}),n},t.prototype.getRelativeStateNodes=function(t,e,n){if(void 0===n&&(n=!0),"string"==typeof t&&U(t)){var r=this.getStateNodeById(t);return n?r.history?r.resolveHistory(e):r.initialStateNodes:[r]}var i=w(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return n?A(o.map(function(t){return t.initialStateNodes})):o},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var t=this;if("atomic"===this.type||"final"===this.type)return[this];if("compound"===this.type&&!this.initial)return[this];var e=this.initialStateValue;return A(j(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),t.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var n=o(t),r=n[0],i=n.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+r+"' from node with no states");var a=this.getStateNode(r);if(a.history)return a.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)},t.updateHistoryValue=function(t,e){return{current:e,states:function t(e,n){return E(e.states,function(e,r){if(e){var i=("string"==typeof n?void 0:n[r])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},t.prototype.historyValue=function(t){if(m(this.states).length)return{current:t||this.initialStateValue,states:O(this.states,function(e,n){if(!t)return e.historyValue();var r="string"==typeof t?void 0:t[n];return e.historyValue(r||e.initialStateValue)},function(t){return!t.history})}},t.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var n=this.parent;if(!t)return this.target?A(j(this.target).map(function(t){return n.getFromRelativePath(t)})):this.parent.initialStateNodes;var r,o,a=(r=n.path,o="states",function(t){var e,n,a=t;try{for(var s=i(r),u=s.next();!u.done;u=s.next()){var c=u.value;a=a[o][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"string"==typeof a?[n.getStateNode(a)]:A(j(a).map(function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=A(m(this.states).map(function(e){return t.states[e].stateIds}));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){if(this.__cache.events)return this.__cache.events;var t=this.states,e=new Set(this.ownEvents);return t&&m(t).forEach(function(n){var r,o,a=t[n];if(a.states)try{for(var s=i(a.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}}),this.__cache.events=Array.from(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var t=this,e=new Set(m(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}),t.prototype.formatTransition=function(t,e,n){var i=this,o=!!e&&e.internal;if(void 0===t||""===t)return r({},e,{actions:e?_(e.actions):[],target:void 0,internal:!e||(void 0===e.internal||e.internal),event:n});var a=_(t).map(function(t){var e="string"==typeof t&&t[0]===i.delimiter;return o=o||e,e&&!i.parent?t.slice(1):e?i.key+t:t});return r({},e,{actions:e?_(e.actions):[],target:a,internal:o,event:n})},t.prototype.formatTransitions=function(){var t,e=this,n=this.config.on||Q,i=this.config.onDone?((t={})[R(this.id)]=this.config.onDone,t):void 0,o=this.after,a=E(r({},n,i),function(t,n){return void 0===t?[{target:void 0,event:n,actions:[],internal:!0}]:Array.isArray(t)?t.map(function(t){return e.formatTransition(t.target,t,n)}):"string"==typeof t?[e.formatTransition([t],void 0,n)]:[e.formatTransition(t.target,t,n)]});return o.forEach(function(t){a[t.event]=a[t.event]||[],a[t.event].push(t)}),a},t}();var q=function(){function t(){this.timeouts=new Map,this._now=0,this._id=0}return t.prototype.now=function(){return this._now},t.prototype.getId=function(){return this._id++},t.prototype.setTimeout=function(t,e){var n=this.getId();return this.timeouts.set(n,{start:this.now(),timeout:e,fn:t}),n},t.prototype.clearTimeout=function(t){this.timeouts.delete(t)},t.prototype.set=function(t){if(this._now>t)throw new Error("Unable to travel back in time");this._now=t,this.flushTimeouts()},t.prototype.flushTimeouts=function(){var t=this;this.timeouts.forEach(function(e,n){t.now()-e.start>=e.timeout&&(e.fn.call(null),t.timeouts.delete(n))})},t.prototype.increment=function(t){this._now+=t,this.flushTimeouts()},t}(),K=function(){function t(e,n){void 0===n&&(n=t.defaultOptions);var i=this;this.machine=e,this.eventQueue=[],this.delayedEventsMap={},this.activitiesMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.initialized=!1,this.children=new Set,this.init=this.start,this.send=function(t){var e=k(t);if(!i.initialized)throw new Error('Unable to send event "'+e.type+'" to an uninitialized interpreter (ID: '+i.machine.id+"). Event: "+JSON.stringify(t));var n=i.machine.transition(i.state,e,i.state.context);return i.update(n,t),i.flushEventQueue(),i.forward(e),n};var o=r({},t.defaultOptions,n);this.clock=o.clock,this.logger=o.logger,this.parent=o.parent}return Object.defineProperty(t.prototype,"initialState",{get:function(){return this.machine.initialState},enumerable:!0,configurable:!0}),t.prototype.update=function(t,e){var n=this;this.state=t;var r=this.state.context,i=e?k(e):void 0;this.state.actions.forEach(function(t){n.exec(t,r,i)},r),i&&this.eventListeners.forEach(function(t){return t(i)}),this.listeners.forEach(function(e){return e(t)}),this.contextListeners.forEach(function(t){return t(n.state.context,n.state.history?n.state.history.context:void 0)}),this.state.tree&&this.state.tree.done&&(this.doneListeners.forEach(function(e){return e(t)}),this.stop())},t.prototype.onTransition=function(t){return this.listeners.add(t),this},t.prototype.onEvent=function(t){return this.eventListeners.add(t),this},t.prototype.onChange=function(t){return this.contextListeners.add(t),this},t.prototype.onStop=function(t){return this.stopListeners.add(t),this},t.prototype.onDone=function(t){return this.doneListeners.add(t),this},t.prototype.off=function(t){return this.listeners.delete(t),this},t.prototype.start=function(t){return void 0===t&&(t=this.machine.initialState),this.initialized=!0,this.update(t),this},t.prototype.stop=function(){var t=this;return this.listeners.forEach(function(e){return t.off(e)}),this.stopListeners.forEach(function(e){e(),t.stopListeners.delete(e)}),this.contextListeners.forEach(function(e){return t.contextListeners.delete(e)}),this.doneListeners.forEach(function(e){return t.doneListeners.delete(e)}),this},t.prototype.forward=function(t){this.children.forEach(function(e){return e.send(t)})},t.prototype.defer=function(t){var e=this;return this.clock.setTimeout(function(){return e.send(t.event)},t.delay||0)},t.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},t.prototype.exec=function(t,r,i){var o,a,c,p=this;if(t.exec)return t.exec(r,i);switch(t.type){case h:var d=t;switch(d.target){case n.Parent:this.parent&&this.parent.send(d.event);break;default:d.delay?this.delayedEventsMap[d.id]=this.defer(d):this.eventQueue.push(d.event)}case f:this.cancel(t.sendId);break;case s:if((S=t.activity).type===e.Invoke){var y=this.machine.options.services&&S.src?this.machine.options.services[S.src]:void 0,v=!!S.forward;if(!y)return void console.warn("No service found for invocation '"+S.src+"'");if("string"!=typeof y){var g=this.spawn((o=y,void 0===c&&(c=o.context),new J(o,a,c)),v);g.start(),this.activitiesMap[S.id]=function(){p.children.delete(g),g.stop()}}}else{var m=this.machine.options&&this.machine.options.activities?this.machine.options.activities[S.type]:void 0;if(!m)return void console.warn("No implementation found for activity '"+S.type+"'");this.activitiesMap[S.id]=m(r,S)}break;case u:var S=t.activity,b=this.activitiesMap[S.id];b&&b();break;case l:var w=t.expr?t.expr(r,i):void 0;t.label?this.logger(t.label,w):this.logger(w);break;default:console.warn("No implementation found for action type '"+t.type+"'")}},t.prototype.spawn=function(e,n){void 0===n&&(n=!1);var r=new t(e,{parent:this});return n&&this.children.add(r),r},t.prototype.flushEventQueue=function(){var t=this.eventQueue.shift();t&&this.send(t)},t.defaultOptions={clock:{setTimeout:setTimeout,clearTimeout:clearTimeout},logger:global.console.log.bind(console)},t.interpret=W,t}();function W(t,e){return new K(t,e)}t.SimulatedClock=q,t.Interpreter=K,t.interpret=W,Object.defineProperty(t,"__esModule",{value:!0})});
|