Socket
Socket
Sign inDemoInstall

xstate

Package Overview
Dependencies
Maintainers
1
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xstate - npm Package Compare versions

Comparing version 4.0.0-9 to 4.0.0-10

2

dist/xstate.graph.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.xstateGraph={})}(this,function(t){"use strict";var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}function n(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,a=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o}function a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t}var o=".",s={},u=function(){function t(t,e,r,n,i,a,o,u){void 0===i&&(i=[]),void 0===a&&(a=s),void 0===o&&(o={}),void 0===u&&(u=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=a,this.data=o,this.events=u}return t.from=function(e,r){return e instanceof t?e.context!==r?new t(e.value,r,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,r,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,r){return e instanceof t?e.actions.length?new t(e.value,r,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,r)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var r=Object.keys(t);return r.concat.apply(r,a(r.map(function(r){return e.toStrings(t[r]).map(function(t){return r+"."+t})})))},t.prototype.matches=function(t){return w(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,r){if(e===r)return!0;var n=Object.keys(e);var i=Object.keys(r);return n.length===i.length&&n.every(function(n){return t(e[n],r[n])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}();function c(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 f(t){try{return"string"==typeof t||"number"==typeof t?""+t:"function"==typeof t?t.name:t.type}catch(t){throw new Error("Actions must be strings or objects with a string action.type property.")}}function h(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 l(t,e){return t instanceof u?t.value:"object"!=typeof t||t instanceof u?y(h(t,e)):t}function y(t){if(1===t.length)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function v(t,e){var r={};return Object.keys(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function p(t,e,r){var n={};return Object.keys(t).forEach(function(i){var a=t[i];r(a)&&(n[i]=e(a,i,t))}),n}var d=function(t){return function(e){var r,i,a=e;try{for(var o=n(t),s=o.next();!s.done;s=o.next()){a=a[s.value]}}catch(t){r={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return a}};function g(t,e){return function(r){var i,a,o=r;try{for(var s=n(t),u=s.next();!u.done;u=s.next()){var c=u.value;o=o[e][c]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(a=s.return)&&a.call(s)}finally{if(i)throw i.error}}return o}}var m,S=function(t){return"string"==typeof t?[[t]]:b(Object.keys(t).map(function(e){return S(t[e]).map(function(t){return[e].concat(t)})}))},x=function(t){var e,r,i={};if(t&&1===t.length&&1===t[0].length)return t[0][0];try{for(var a=n(t),o=a.next();!o.done;o=a.next())for(var s=o.value,u=i,c=0;c<s.length;c++){var f=s[c];if(c===s.length-2){u[f]=s[c+1];break}u[f]=u[f]||{},u=u[f]}}catch(t){e={error:t}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return i};function b(t){var e;return(e=[]).concat.apply(e,a(t))}function O(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function w(t,e,r){void 0===r&&(r=o);var n=l(t,r),i=l(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:Object.keys(n).every(function(t){return t in i&&w(n[t],i[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"}(m||(m={}));m.Start,m.Stop;var j=m.Raise,E=m.Send,N=m.Cancel,k=m.Null,A=m.Assign;m.After,m.DoneState,m.Log,m.Init;function P(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function V(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var _=function(t,r){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:V(t,r)};else{if("function"!=typeof t){var i=V(t.type,r);return i?e({},t,{exec:i}):t}n={type:t.name,exec:t}}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1}),n};function T(t){var r=_(t);return e({},r,{type:r.type,start:r.start?_(r.start):r.exec?_(r.exec):void 0,stop:r.stop?_(r.stop):void 0})}function J(t){return{type:j,event:t}}function R(t){var e=T(t);return{type:m.Start,activity:e,exec:e.start?e.start.exec:void 0}}function C(t,e){var r=e?"#"+e:"";return m.After+"("+t+")"+r}function M(t){return m.DoneState+"."+t}var I=function(){function t(e,r){var n;if(this.stateNode=e,r)if("string"==typeof r){var i=e.getStateNode(r);this.done="final"===i.type,this.value=((n={})[r]=new t(i,"compound"===i.type||"parallel"===i.type?i.initialState.value:void 0),n)}else{var a=v(r,function(r,n){return new t(e.getStateNode(n),r)});this.value=a,this.done=Object.keys(a).every(function(t){return a[t].done})}else this.done="final"===e.type,this.value=void 0}return Object.defineProperty(t.prototype,"stateValue",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return v(this.value,function(t){return t.stateValue});if("compound"===this.stateNode.type){var t=this.value[Object.keys(this.value)[0]].stateNode;return"atomic"===t.type?t.key:v(this.value,function(t){return t.stateValue})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return w(t,this.stateValue)},t.prototype.getEntryExitStates=function(t,e){var r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var n={exit:[],entry:[]};return Object.keys(this.value)[0]!==Object.keys(t.value)[0]?(n.exit=t.value[Object.keys(t.value)[0]].getExitStates(),n.entry=this.value[Object.keys(this.value)[0]].getEntryStates()):n=this.value[Object.keys(this.value)[0]].getEntryExitStates(t.value[Object.keys(t.value)[0]],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var i=Object.keys(this.value).map(function(n){return r.value[n].getEntryExitStates(t.value[n],e)}),o={exit:[],entry:[]};return i.forEach(function(t){o.exit=a(o.exit,t.exit),o.entry=a(o.entry,t.entry)}),e&&e.has(this.stateNode)&&(o.exit.push(this.stateNode),o.entry.unshift(this.stateNode)),o;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.value?[this.stateNode].concat(b(Object.keys(this.value).map(function(e){return t.value[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.value?b(Object.keys(this.value).map(function(e){return t.value[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),F=".",B="",H={},L=[],D=function(t){return"#"===t[0]},U=function(){return{guards:H}},z=(function(){function t(r,n,i){void 0===n&&(n=U());var o=this;this._config=r,this.options=n,this.context=i,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.key=r.key||r.id||"(machine)",this.type=r.type||(r.parallel?"parallel":r.states&&Object.keys(r.states).length?"compound":r.history?"history":"atomic"),this.parent=r.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=r.delimiter||(this.parent?this.parent.delimiter:F),this.id=r.id||(this.machine?a([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=r.initial,this.order=r.order||-1,this.states=r.states?v(r.states,function(r,n,i,a){var s,u=new t(e({},r,{key:n,order:void 0===r.order?r.order:a,parent:o}));return Object.assign(o.idMap,e(((s={})[u.id]=u,s),u.idMap)),u}):H,this.history=!0===r.history?"shallow":r.history||!1,this.transient=!(!r.on||!r.on[B]),this.strict=!!r.strict,this.onEntry=O(r.onEntry),this.onExit=O(r.onExit),this.data=r.data,this.activities=O(r.activities).map(function(t){return o.resolveActivity(t)})}Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:v(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||L,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 r(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,r=this.config.after;if(!r)return L;if(Array.isArray(r))return r.map(function(r){return e({event:C(r.delay,t.id)},r,{actions:O(r.actions)})});var n=b(Object.keys(r).map(function(n){var i=r[n],a=+n,o=C(a,t.id);return"string"==typeof i?[{target:i,delay:a,event:o,actions:[]}]:O(i).map(function(t){return e({event:o,delay:a},t,{actions:O(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,r=this;if(!t)return[];var n=t instanceof u?t.value:l(t,this.delimiter);if("string"==typeof n){var i=this.getStateNode(n).initial;return i?this.getStateNodes(((e={})[n]=i,e)):[this.states[n]]}var a=Object.keys(n);return a.map(function(t){return r.getStateNode(t)}).concat(a.reduce(function(t,e){var i=r.getStateNode(e).getStateNodes(n[e]);return t.concat(i)},[]))},t.prototype.handles=function(t){var e=c(t);return-1!==this.events.indexOf(e)},t.prototype.transitionLeafNode=function(t,e,r,n){var i=this.getStateNode(t),o=i.next(e,r,n);if(!o.value){var s=this.next(e,r,n),u=s.value,c=s.entryExitStates,f=s.actions,h=s.paths;return{value:u,tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(a([i],c?Array.from(c.exit):[]))},actions:f,paths:h}}return o},t.prototype.transitionCompoundNode=function(t,e,r,n){var i=Object.keys(t),o=this.getStateNode(i[0]),s=o._transition(t[i[0]],e,r,n);if(!s.value){var u=this.next(e,r,n),c=u.value,f=u.entryExitStates,h=u.actions,l=u.paths;return{value:c,tree:c?this.machine.getStateTree(c):void 0,source:e,entryExitStates:{entry:f?f.entry:new Set,exit:new Set(a(s.entryExitStates?Array.from(s.entryExitStates.exit):[],[o],f?Array.from(f.exit):[]))},actions:h,paths:l}}return s},t.prototype.transitionParallelNode=function(t,e,r,n){var i=this,o={};if(Object.keys(t).forEach(function(a){var s=t[a];if(s){var u=i.getStateNode(a)._transition(s,e,r,n);u.value,o[a]=u}}),!Object.keys(o).some(function(t){return void 0!==o[t].value})){var s=this.next(e,r,n),u=s.value,c=s.entryExitStates,f=s.actions,h=s.paths;return{value:u,tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(a(Object.keys(this.states).map(function(t){return i.states[t]}),c?Array.from(c.exit):[]))},actions:f,paths:h}}var l=b(Object.keys(o).map(function(t){return o[t].paths}));if(1===l.length&&!w(y(this.path),y(l[0])))return{value:u=this.machine.resolve(x(l)),tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:Object.keys(o).map(function(t){return o[t].entryExitStates}).reduce(function(t,e){var r=e,n=r.entry,i=r.exit;return{entry:new Set(a(Array.from(t.entry),Array.from(n))),exit:new Set(a(Array.from(t.exit),Array.from(i)))}},{entry:new Set,exit:new Set}),actions:b(Object.keys(o).map(function(t){return o[t].actions})),paths:l};var v=b(Object.keys(o).map(function(t){var r=o[t].value||e.value;return S(d(i.path)(r)[t]).map(function(e){return i.path.concat(t,e)})})),p=this.machine.resolve(x(v));return{value:p,tree:p?this.machine.getStateTree(p):void 0,source:e,entryExitStates:Object.keys(o).reduce(function(t,e){var r=o[e],n=r.value,i=r.entryExitStates;if(!n||!i)return t;var s=i.entry,u=i.exit;return{entry:new Set(a(Array.from(t.entry),Array.from(s))),exit:new Set(a(Array.from(t.exit),Array.from(u)))}},{entry:new Set,exit:new Set}),actions:b(Object.keys(o).map(function(t){return o[t].actions})),paths:S(p)}},t.prototype._transition=function(t,e,r,n){return"string"==typeof t?this.transitionLeafNode(t,e,r,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,r,n):this.transitionParallelNode(t,e,r,n)},t.prototype.next=function(t,e,r){var i,o,s=this,u=e.type,c=this.on[u],f=this.transient?[{type:k}]:[];if(!c||!c.length)return{value:void 0,tree:void 0,source:t,entryExitStates:void 0,actions:f,paths:[]};var h,y=[];try{for(var v=n(c),p=v.next();!p.done;p=v.next()){var g=p.value,m=g,S=m.cond,j=m.in,E=r||H,N=!j||w(l(j,this.delimiter),d(this.path.slice(0,-2))(t.value));if((!S||this.evaluateCond(S,E,e,t.value))&&N){y=O(g.target),f.push.apply(f,a(O(g.actions))),h=g;break}}}catch(t){i={error:t}}finally{try{p&&!p.done&&(o=v.return)&&o.call(v)}finally{if(i)throw i.error}}if(h&&0===y.length)return{value:t.value,tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,entryExitStates:void 0,actions:f,paths:[]};if(!h&&0===y.length)return{value:void 0,tree:void 0,source:t,entryExitStates:void 0,actions:f,paths:[]};var A=b(y.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),P=A.map(function(t){return t.path}),V=!!h.internal?[]:b(A.map(function(t){return s.nodesFromChild(t)})),_={entry:new Set(V),exit:new Set(V)},T=this.machine.resolve(x(b(y.map(function(e){return s.getRelativeStateNodes(e,t.historyValue).map(function(t){return t.path})}))));return{value:T,tree:T?this.machine.getStateTree(T):void 0,source:t,entryExitStates:_,actions:f,paths:P}},t.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],r=t;r&&r!==this;)e.push(r),r=r.parent;return e.push(this),e},t.prototype.getStateTree=function(t){return new I(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.evaluateCond=function(t,e,r,n){var i,a=this.machine.options.guards;if("string"==typeof t){if(!a||!a[t])throw new Error("Condition '"+t+"' is not implemented on machine '"+this.machine.id+"'.");i=a[t]}else i=t;return i(e,r,n)},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,e,r){var n=this;void 0===r&&(r=!1);var i=new Set,o=t.tree?t.tree.getEntryExitStates(this.getStateTree(e.value),t.entryExitStates?t.entryExitStates.entry:void 0):{entry:[],exit:[]};r&&(o.exit=[]);var s={entry:o?b(Array.from(new Set(o.entry)).map(function(e){if("final"===e.type){var r=t.tree;i.add(M(e.id));var n=e.parent?e.parent.parent:void 0;if(n){var o=g(n.path,"value")(r);o.done&&i.add(M(o.stateNode.id))}}return a(e.onEntry,e.activities.map(function(t){return R(t)}),e.delays.map(function(t){var e,r,n=t.delay,i=t.id;return e=C(n,i),r={delay:n},{type:E,event:P(e),delay:r?r.delay:void 0,id:r&&void 0!==r.id?r.id:c(e)}}))})).concat(Array.from(i).map(J)):[],exit:o?b(Array.from(new Set(o.exit)).map(function(t){return a(t.onExit,t.activities.map(function(t){return function(t){var e=T(t);return{type:m.Stop,activity:e,exec:e.stop?e.stop.exec:void 0}}(t)}),t.delays.map(function(t){var e,r=t.delay,n=t.id;return e=C(r,n),{type:N,sendId:e}}))})):[]};return s.exit.concat(t.actions).concat(s.entry).map(function(t){return"string"==typeof t?n.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){var r=this.machine.options.activities;return"string"==typeof t?T(r?e({type:t},r[t]):t):t},t.prototype.getActivities=function(t,r){if(!t)return H;var n=e({},r);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,r){var n="string"==typeof t?this.resolve(y(this.getResolvedPath(t))):t instanceof u?t:this.resolve(t),i=r||(t instanceof u?t.context:void 0),a=P(e),o=a.type;if(this.strict&&-1===this.events.indexOf(o))throw new Error("Machine '"+this.id+"' does not accept event '"+o+"'");var s=u.from(n,i),c=this._transition(s.value,s,a,i);return this.resolveTransition(c,s,a)},t.prototype.resolveTransition=function(e,r,n,i){var o;void 0===i&&(i=!1);var s=r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0,c=this.getActions(e,r,i),f=e.tree?e.tree.getEntryExitStates(this.getStateTree(r.value)):{entry:[],exit:[]},h=e.tree?this.getActivities({entry:new Set(f.entry),exit:new Set(f.exit)},r.activities):{},l=c.filter(function(t){return"object"==typeof t&&(t.type===j||t.type===k)}),y=c.filter(function(t){return"object"!=typeof t||t.type!==j&&t.type!==k&&t.type!==A}),v=c.filter(function(t){return"object"==typeof t&&t.type===A}),p=r.context?v.reduce(function(t,e){var r=e.assignment,i={};return"function"==typeof r?i=r(t,n||{type:m.Init}):Object.keys(r).forEach(function(e){var a=r[e];i[e]="function"==typeof a?a(t,n):a}),Object.assign({},t,i)},r.context):r.context,d=e.value?this.getStateNodes(e.value):[];d.some(function(t){return t.transient})&&l.push({type:k});var g,S,x=a([this],d).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),b=e.value?new u(e.value,p,s?t.updateHistoryValue(s,e.value):void 0,e.source?r:void 0,(g=y,S=this.options.actions,g?(Array.isArray(g)?g:[g]).map(function(t){return _(t,S)}):[]),h,x,l):void 0;if(!b)return u.inert(r,p);r.history&&delete r.history.history;for(var O=b;l.length;){var w=O.actions,E=l.shift();(o=(O=this.transition(O,E.type===k?B:E.event,O.context)).actions).unshift.apply(o,a(w))}return O},t.prototype.ensureValidPaths=function(t){var e,r,i=this,a=new Map,o=b(t.map(function(t){return i.getRelativeStateNodes(t)}));try{t:for(var s=n(o),u=s.next();!u.done;u=s.next())for(var c=u.value,f=c;f.parent;){if(a.has(f.parent)){if("parallel"===f.parent.type)continue t;throw new Error("State node '"+c.id+"' shares parent '"+f.parent.id+"' with state node '"+a.get(f.parent).map(function(t){return t.id})+"'")}a.get(f.parent)?a.get(f.parent).push(c):a.set(f.parent,[c]),f=f.parent}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}},t.prototype.getStateNode=function(t){if(D(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=D(t)?t.slice("#".length):t;if(e===this.id)return this;var r=this.machine.idMap[e];if(!r)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return r},t.prototype.getStateNodeByPath=function(t){for(var e=h(t,this.delimiter),r=this;e.length;){var n=e.shift();r=r.getStateNode(n)}return r},t.prototype.resolve=function(t){var e,r=this;if("string"==typeof t){var n=this.getStateNode(t);return n.initial?((e={})[t]=n.initialStateValue,e):t}return"parallel"===this.type?v(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):H}):v(t,function(t,e){return t?r.getStateNode(e).resolve(t):H})},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=p(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[r]=this.states[this.initial].resolvedStateValue,e):r},enumerable:!0,configurable:!0}),t.prototype.getResolvedPath=function(t){if(D(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return h(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?p(this.states,function(t){return t.initialStateValue||H},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.getState=function(t,e){void 0===e&&(e=this.machine.context);var r={},n=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&n.push.apply(n,a(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[c(t)]=!0,n.push(R(t))})});var i=n.filter(function(t){return"object"==typeof t&&t.type===A}),o=e?i.reduce(function(t,e){var r=e.assignment,n={};return"function"==typeof r?n=r(t,{type:"init"}):Object.keys(r).forEach(function(e){var i=r[e];n[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,n)},e):e;return new u(t,o,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.getState(t);return this.resolveTransition({value:t,tree:this.getStateTree(t),source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(t)),exit:new Set},actions:[],paths:[]},e,void 0,!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&&D(e.target)?y(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 r=[];return Object.keys(t).forEach(function(n){r.push.apply(r,a(e.states[n].getStates(t[n])))}),r},t.prototype.getRelativeStateNodes=function(t,e,r){if(void 0===r&&(r=!0),"string"==typeof t&&D(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=h(t,this.delimiter),a=(this.parent||this).getFromRelativePath(i,e);return r?b(a.map(function(t){return t.initialStateNodes})):a},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 b(S(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),t.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var r=i(t),n=r[0],a=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if(o.history)return o.resolveHistory(e);if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(a,e)},t.updateHistoryValue=function(t,e){return{current:e,states:function t(e,r){return v(e.states,function(e,n){if(e){var i=("string"==typeof r?void 0:r[n])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},t.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:p(this.states,function(e,r){if(!t)return e.historyValue();var n="string"==typeof t?void 0:t[r];return e.historyValue(n||e.initialStateValue)},function(t){return!t.history})}},t.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var r=this.parent;if(!t)return this.target?b(S(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var n=g(r.path,"states")(t).current;return"string"==typeof n?[r.getStateNode(n)]:b(S(n).map(function(t){return"deep"===e.history?r.getFromRelativePath(t):[r.states[t[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=b(Object.keys(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(Object.keys(this.on));return t&&Object.keys(t).forEach(function(r){var i,a,o=t[r];if(o.states)try{for(var s=n(o.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(a=s.return)&&a.call(s)}finally{if(i)throw i.error}}}),this.__cache.events=Array.from(e)},enumerable:!0,configurable:!0}),t.prototype.formatTransition=function(t,r,n){var i=this,a=!!r&&r.internal;if(void 0===t||""===t)return e({},r,{actions:r?O(r.actions):[],target:void 0,internal:!r||(void 0===r.internal||r.internal),event:n});var o=O(t).map(function(t){var e="string"==typeof t&&t[0]===i.delimiter;return a=a||e,e&&!i.parent?t.slice(1):e?i.key+t:t});return e({},r,{actions:r?O(r.actions):[],target:o,internal:a,event:n})},t.prototype.formatTransitions=function(){var t=this,e=this.config.on||H,r=this.after,n=v(e,function(e,r){return void 0===e?[{target:void 0,event:r,actions:[]}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,r)}):"string"==typeof e?[t.formatTransition([e],void 0,r)]:[t.formatTransition(e.target,e,r)]});return r.forEach(function(t){n[t.event]=n[t.event]||[],n[t.event].push(t)}),n}}(),{});function G(t,e){return b(t.definition.on[e].map(function(r){var n=r.target?[].concat(r.target):void 0;return n?n.map(function(n){try{var i=n?t.getRelativeStateNodes(n,void 0,!1)[0]:t;return{source:t,target:i,event:e,actions:r.actions?r.actions.map(f):[],cond:r.cond,transition:r}}catch(e){return void console.warn("Target '"+n+"' not found on '"+t.id+"'")}}).filter(function(t){return void 0!==t}):[{source:t,target:t,event:e,actions:r.actions?r.actions.map(f):[],cond:r.cond,transition:r}]}))}function q(t,e){var r={},i=t.events;return function a(o){var s,u,c=JSON.stringify(o);if(!r[c]){r[c]={};try{for(var f=n(i),h=f.next();!h.done;h=f.next()){var l=h.value,y=t.transition(o,l,e);r[c][l]={state:y.value},a(y.value)}}catch(t){s={error:t}}finally{try{h&&!h.done&&(u=f.return)&&u.call(f)}finally{if(s)throw s.error}}}}(t.initialState.value),r}function K(t){if("string"==typeof t||"number"==typeof t)return""+t;var e=t.type,n=r(t,["type"]);return e+" | "+JSON.stringify(n)}function Q(t){var e=t.value,r=t.context;return JSON.stringify(e)+" | "+JSON.stringify(r)}function W(t,e){var r=e.events,i=e.filter,a={},o=b(t.events.map(function(t){return r[t]||[t]}));return function e(r){var s,u,c=Q(r);if(!a[c]){a[c]={};try{for(var f=n(o),h=f.next();!h.done;h=f.next()){var l=h.value,y=t.transition(r,l);i&&!i(y)||(a[c][K(l)]={value:y.value,context:y.context},e(y))}}catch(t){s={error:t}}finally{try{h&&!h.done&&(u=f.return)&&u.call(f)}finally{if(s)throw s.error}}}}(t.initialState),a}function X(t,e){var r;if(!t.states)return z;var i=q(t,e),o=((r={})[JSON.stringify(t.initialState.value)]=[],r),s=new Set;return function e(r){var u,c,f,h,y=JSON.stringify(r);s.add(y);var v=i[y];try{for(var p=n(Object.keys(v)),d=p.next();!d.done;d=p.next()){var g=d.value;if(b=v[g].state){var m=JSON.stringify(l(b,t.delimiter));(!o[m]||o[m].length>o[y].length+1)&&(o[m]=a(o[y]||[],[{state:r,event:g}]))}}}catch(t){u={error:t}}finally{try{d&&!d.done&&(c=p.return)&&c.call(p)}finally{if(u)throw u.error}}try{for(var S=n(Object.keys(v)),x=S.next();!x.done;x=S.next()){var b;(b=v[x.value].state)&&(m=JSON.stringify(b),s.has(m)||e(b))}}catch(t){f={error:t}}finally{try{x&&!x.done&&(h=S.return)&&h.call(S)}finally{if(f)throw f.error}}return o}(t.initialState.value),o}function Y(t,e){if(!t.states)return z;var r=q(t,e),i=new Set,o=[],s={};var u=JSON.stringify(t.initialState.value);return Object.keys(r).forEach(function(t){!function t(e,u){var c,f;if(i.add(e),e===u)s[u]=s[u]||[],s[u].push(a(o));else try{for(var h=n(Object.keys(r[e])),l=h.next();!l.done;l=h.next()){var y=l.value,v=r[e][y].state;if(v){var p=JSON.stringify(v);i.has(p)||(o.push({state:JSON.parse(e),event:y}),t(p,u))}}}catch(t){c={error:t}}finally{try{l&&!l.done&&(f=h.return)&&f.call(h)}finally{if(c)throw c.error}}o.pop(),i.delete(e)}(u,t)}),s}t.getNodes=function t(e){var r=e.states;return Object.keys(r).reduce(function(e,n){var i=r[n],o=t(r[n]);return e.push.apply(e,a([i],o)),e},[])},t.getEventEdges=G,t.getEdges=function t(e,r){var n=(r||{}).depth,i=void 0===n?null:n,o=[];return e.states&&null===i?Object.keys(e.states).forEach(function(r){o.push.apply(o,a(t(e.states[r])))}):i&&i>0&&Object.keys(e.states).forEach(function(r){o.push.apply(o,a(t(e.states[r],{depth:i-1})))}),Object.keys(e.on).forEach(function(t){o.push.apply(o,a(G(e,t)))}),o},t.getAdjacencyMap=q,t.deserializeStateString=function(t){var e=i(t.split(" | "),2),r=e[0],n=e[1];return{value:JSON.parse(r),context:JSON.parse(n)}},t.getValueAdjacencyMap=W,t.getShortestValuePaths=function(t,e){if(!t.states)return z;var r=W(t,e),i={},o=new Set;return function t(e){var s,c,f,h,l=Q(e);o.add(l);var y=r[l];try{for(var v=n(Object.keys(y)),p=v.next();!p.done;p=v.next()){var d=p.value,g=y[d],m=g.value,S=g.context;if(m){var x=Q(E=u.from(m,S));(!i[x]||i[x].length>i[l].length+1)&&(i[x]=a(i[l]||[],[{state:m,event:d}]))}}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=v.return)&&c.call(v)}finally{if(s)throw s.error}}try{for(var b=n(Object.keys(y)),O=b.next();!O.done;O=b.next()){var w=y[O.value],j=(m=w.value,w.context);if(m){var E=u.from(m,j);x=Q(u.from(m,j)),o.has(x)||t(E)}}}catch(t){f={error:t}}finally{try{O&&!O.done&&(h=b.return)&&h.call(b)}finally{if(f)throw f.error}}return i}(t.initialState),i},t.getShortestPaths=X,t.getShortestPathsAsArray=function(t,e){var r=X(t,e);return Object.keys(r).map(function(t){return{state:JSON.parse(t),path:r[t]}})},t.getSimplePaths=Y,t.getSimplePathsAsArray=function(t,e){var r=Y(t,e);return Object.keys(r).map(function(t){return{state:JSON.parse(t),paths:r[t]}})},Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.xstateGraph={})}(this,function(t){"use strict";var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}function n(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,a=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o}function a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t}var o=".",s={},u=function(){function t(t,e,r,n,i,a,o,u){void 0===i&&(i=[]),void 0===a&&(a=s),void 0===o&&(o={}),void 0===u&&(u=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=a,this.data=o,this.events=u}return t.from=function(e,r){return e instanceof t?e.context!==r?new t(e.value,r,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,r,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,r){return e instanceof t?e.actions.length?new t(e.value,r,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,r)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var r=Object.keys(t);return r.concat.apply(r,a(r.map(function(r){return e.toStrings(t[r]).map(function(t){return r+"."+t})})))},t.prototype.matches=function(t){return O(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,r){if(e===r)return!0;var n=Object.keys(e);var i=Object.keys(r);return n.length===i.length&&n.every(function(n){return t(e[n],r[n])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}();function c(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 f(t){try{return"string"==typeof t||"number"==typeof t?""+t:"function"==typeof t?t.name:t.type}catch(t){throw new Error("Actions must be strings or objects with a string action.type property.")}}function h(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 l(t,e){return t instanceof u?t.value:Array.isArray(t)?y(t):"object"!=typeof t||t instanceof u?y(h(t,e)):t}function y(t){if(1===t.length)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function p(t,e){var r={};return Object.keys(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function v(t,e,r){var n={};return Object.keys(t).forEach(function(i){var a=t[i];r(a)&&(n[i]=e(a,i,t))}),n}var d=function(t){return function(e){var r,i,a=e;try{for(var o=n(t),s=o.next();!s.done;s=o.next()){a=a[s.value]}}catch(t){r={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return a}};function g(t,e){return function(r){var i,a,o=r;try{for(var s=n(t),u=s.next();!u.done;u=s.next()){var c=u.value;o=o[e][c]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(a=s.return)&&a.call(s)}finally{if(i)throw i.error}}return o}}var m,S=function(t){return t?"string"==typeof t?[[t]]:b(Object.keys(t).map(function(e){return S(t[e]).map(function(t){return[e].concat(t)})})):[[]]};function b(t){var e;return(e=[]).concat.apply(e,a(t))}function x(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function O(t,e,r){void 0===r&&(r=o);var n=l(t,r),i=l(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:Object.keys(n).every(function(t){return t in i&&O(n[t],i[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"}(m||(m={}));m.Start,m.Stop;var w=m.Raise,j=m.Send,N=m.Cancel,E=m.Null,k=m.Assign;m.After,m.DoneState,m.Log,m.Init;function A(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function P(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var V=function(t,r){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:P(t,r)};else{if("function"!=typeof t){var i=P(t.type,r);return i?e({},t,{exec:i}):t}n={type:t.name,exec:t}}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1}),n};function _(t){var r=V(t);return e({},r,{type:r.type,start:r.start?V(r.start):r.exec?V(r.exec):void 0,stop:r.stop?V(r.stop):void 0})}function C(t){return{type:w,event:t}}function J(t){var e=_(t);return{type:m.Start,activity:e,exec:e.start?e.start.exec:void 0}}function T(t,e){var r=e?"#"+e:"";return m.After+"("+t+")"+r}function R(t){return m.DoneState+"."+t}var M=function(){function t(e,r){var n;this.stateNode=e,this._stateValue=r,this.value=r?"string"==typeof r?((n={})[r]=new t(e.getStateNode(r),void 0),n):p(r,function(r,n){return new t(e.getStateNode(n),r)}):{}}return Object.defineProperty(t.prototype,"done",{get:function(){var t=this;switch(this.stateNode.type){case"final":return!0;case"compound":return this.value[Object.keys(this.value)[0]].done;case"parallel":return Object.keys(this.value).some(function(e){return t.value[e].done});default:return!1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"resolved",{get:function(){return new t(this.stateNode,this.stateNode.resolve(this.stateValue))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return S(this.stateValue)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absolute",{get:function(){var e=this,r=this._stateValue,n={},i=n;return this.stateNode.path.forEach(function(t,n){n===e.stateNode.path.length-1?i[t]=r:(i[t]={},i=i[t])}),new t(this.stateNode.machine,n)},enumerable:!0,configurable:!0}),t.prototype.clone=function(){return new t(this.stateNode,this.stateValue)},t.prototype.combine=function(t){var e,r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot combine distinct trees");if("compound"===this.stateNode.type){var n=void 0;if(Object.keys(this.value).length&&Object.keys(t.value).length){var i=Object.keys(this.value)[0];return(e={})[i]=this.value[i].combine(t.value[i]),n=e,(o=this.clone()).value=n,o}return n=Object.assign({},this.value,t.value),(o=this.clone()).value=n,o}if("parallel"===this.stateNode.type){var o,s=new Set(a(Object.keys(this.value),Object.keys(t.value))),u={};return s.forEach(function(e){r.value[e]&&t.value[e]?u[e]=r.value[e].combine(t.value[e]):u[e]=r.value[e]||t.value[e]}),(o=this.clone()).value=u,o}return this},Object.defineProperty(t.prototype,"stateValue",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return p(this.value,function(t){return t.stateValue});if("compound"===this.stateNode.type){if(0===Object.keys(this.value).length)return{};var t=this.value[Object.keys(this.value)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:p(this.value,function(t){return t.stateValue})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return O(t,this.stateValue)},t.prototype.getEntryExitStates=function(t,e){var r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var n={exit:[],entry:[]},i=Object.keys(this.value)[0],o=Object.keys(t.value)[0];return i!==o?(n.exit=t.value[o].getExitStates(),n.entry=this.value[i].getEntryStates()):n=this.value[i].getEntryExitStates(t.value[o],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var s=Object.keys(this.value).map(function(n){return r.value[n].getEntryExitStates(t.value[n],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.value?[this.stateNode].concat(b(Object.keys(this.value).map(function(e){return t.value[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.value?b(Object.keys(this.value).map(function(e){return t.value[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),I=".",F="",B={},H=[],L=function(t){return"#"===t[0]},D=function(){return{guards:B}},U=(function(){function t(r,n,i){void 0===n&&(n=D());var o=this;this._config=r,this.options=n,this.context=i,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.key=r.key||r.id||"(machine)",this.type=r.type||(r.parallel?"parallel":r.states&&Object.keys(r.states).length?"compound":r.history?"history":"atomic"),this.parent=r.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=r.delimiter||(this.parent?this.parent.delimiter:I),this.id=r.id||(this.machine?a([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=r.initial,this.order=r.order||-1,this.states=r.states?p(r.states,function(r,n,i,a){var s,u=new t(e({},r,{key:n,order:void 0===r.order?r.order:a,parent:o}));return Object.assign(o.idMap,e(((s={})[u.id]=u,s),u.idMap)),u}):B,this.history=!0===r.history?"shallow":r.history||!1,this.transient=!(!r.on||!r.on[F]),this.strict=!!r.strict,this.onEntry=x(r.onEntry),this.onExit=x(r.onExit),this.data=r.data,this.activities=x(r.activities).map(function(t){return o.resolveActivity(t)})}Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:p(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||H,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 r(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,r=this.config.after;if(!r)return H;if(Array.isArray(r))return r.map(function(r){return e({event:T(r.delay,t.id)},r,{actions:x(r.actions)})});var n=b(Object.keys(r).map(function(n){var i=r[n],a=+n,o=T(a,t.id);return"string"==typeof i?[{target:i,delay:a,event:o,actions:[]}]:x(i).map(function(t){return e({event:o,delay:a},t,{actions:x(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,r=this;if(!t)return[];var n=t instanceof u?t.value:l(t,this.delimiter);if("string"==typeof n){var i=this.getStateNode(n).initial;return i?this.getStateNodes(((e={})[n]=i,e)):[this.states[n]]}var a=Object.keys(n);return a.map(function(t){return r.getStateNode(t)}).concat(a.reduce(function(t,e){var i=r.getStateNode(e).getStateNodes(n[e]);return t.concat(i)},[]))},t.prototype.handles=function(t){var e=c(t);return-1!==this.events.indexOf(e)},t.prototype.transitionLeafNode=function(t,e,r,n){var i=this.getStateNode(t),o=i.next(e,r,n);if(!o.tree){var s=this.next(e,r,n),u=s.entryExitStates,c=s.actions;return{tree:s.tree,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set(a([i],u?Array.from(u.exit):[]))},actions:c}}return o},t.prototype.transitionCompoundNode=function(t,e,r,n){var i=Object.keys(t),o=this.getStateNode(i[0]),s=o._transition(t[i[0]],e,r,n);if(!s.tree){var u=this.next(e,r,n),c=u.entryExitStates,f=u.actions;return{tree:u.tree,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(a(s.entryExitStates?Array.from(s.entryExitStates.exit):[],[o],c?Array.from(c.exit):[]))},actions:f}}return s},t.prototype.transitionParallelNode=function(t,e,r,n){var i=this,o={};if(Object.keys(t).forEach(function(a){var s=t[a];if(s){var u=i.getStateNode(a)._transition(s,e,r,n);u.tree,o[a]=u}}),!Object.keys(o).some(function(t){return void 0!==o[t].tree})){var s=this.next(e,r,n),u=s.entryExitStates,c=s.actions;return{tree:s.tree,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set(a(Object.keys(this.states).map(function(t){return i.states[t]}),u?Array.from(u.exit):[]))},actions:c}}var f=Object.keys(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!==f.paths.length||O(l(this.path,this.delimiter),f.stateValue)?{tree:Object.keys(o).map(function(t){var r=o[t],n=d(i.path)(r.tree?r.tree.stateValue:e.value||e.value)[t];return new M(i.getStateNode(t),n).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,entryExitStates:Object.keys(o).reduce(function(t,e){var r=o[e],n=r.tree,i=r.entryExitStates;if(!n||!i)return t;var s=i.entry,u=i.exit;return{entry:new Set(a(Array.from(t.entry),Array.from(s))),exit:new Set(a(Array.from(t.exit),Array.from(u)))}},{entry:new Set,exit:new Set}),actions:b(Object.keys(o).map(function(t){return o[t].actions}))}:{tree:f,source:e,entryExitStates:Object.keys(o).map(function(t){return o[t].entryExitStates}).reduce(function(t,e){var r=e,n=r.entry,i=r.exit;return{entry:new Set(a(Array.from(t.entry),Array.from(n))),exit:new Set(a(Array.from(t.exit),Array.from(i)))}},{entry:new Set,exit:new Set}),actions:b(Object.keys(o).map(function(t){return o[t].actions}))}},t.prototype._transition=function(t,e,r,n){return"string"==typeof t?this.transitionLeafNode(t,e,r,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,r,n):this.transitionParallelNode(t,e,r,n)},t.prototype.next=function(t,e,r){var i,o,s=this,u=e.type,c=this.on[u],f=this.transient?[{type:E}]:[];if(!c||!c.length)return{tree:void 0,source:t,entryExitStates:void 0,actions:f};var h,y=[];try{for(var p=n(c),v=p.next();!v.done;v=p.next()){var g=v.value,m=g,S=m.cond,w=m.in,j=r||B,N=!w||O(l(w,this.delimiter),d(this.path.slice(0,-2))(t.value));if((!S||this.evaluateCond(S,j,e,t.value))&&N){y=x(g.target),f.push.apply(f,a(x(g.actions))),h=g;break}}}catch(t){i={error:t}}finally{try{v&&!v.done&&(o=p.return)&&o.call(p)}finally{if(i)throw i.error}}if(h&&0===y.length)return{tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,entryExitStates:void 0,actions:f};if(!h&&0===y.length)return{tree:void 0,source:t,entryExitStates:void 0,actions:f};var k=b(y.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),A=!!h.internal?[]:b(k.map(function(t){return s.nodesFromChild(t)})),P={entry:new Set(A),exit:new Set(A)};return{tree:k.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)}),source:t,entryExitStates:P,actions:f}},Object.defineProperty(t.prototype,"tree",{get:function(){var t=l(this.path,this.delimiter);return new M(this.machine,t)},enumerable:!0,configurable:!0}),t.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],r=t;r&&r!==this;)e.push(r),r=r.parent;return e.push(this),e},t.prototype.getStateTree=function(t){return new M(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.evaluateCond=function(t,e,r,n){var i,a=this.machine.options.guards;if("string"==typeof t){if(!a||!a[t])throw new Error("Condition '"+t+"' is not implemented on machine '"+this.machine.id+"'.");i=a[t]}else i=t;return i(e,r,n)},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,e,r){var n=this;void 0===r&&(r=!1);var i=new Set,o=t.tree?t.tree.resolved.getEntryExitStates(this.getStateTree(e.value),t.entryExitStates?t.entryExitStates.entry:void 0):{entry:[],exit:[]};r&&(o.exit=[]);var s={entry:o?b(Array.from(new Set(o.entry)).map(function(e){if("final"===e.type){var r=t.tree;i.add(R(e.id));var n=e.parent?e.parent.parent:void 0;if(n){var o=g(n.path,"value")(r);o.done&&i.add(R(o.stateNode.id))}}return a(e.onEntry,e.activities.map(function(t){return J(t)}),e.delays.map(function(t){var e,r,n=t.delay,i=t.id;return e=T(n,i),r={delay:n},{type:j,event:A(e),delay:r?r.delay:void 0,id:r&&void 0!==r.id?r.id:c(e)}}))})).concat(Array.from(i).map(C)):[],exit:o?b(Array.from(new Set(o.exit)).map(function(t){return a(t.onExit,t.activities.map(function(t){return function(t){var e=_(t);return{type:m.Stop,activity:e,exec:e.stop?e.stop.exec:void 0}}(t)}),t.delays.map(function(t){var e,r=t.delay,n=t.id;return e=T(r,n),{type:N,sendId:e}}))})):[]};return s.exit.concat(t.actions).concat(s.entry).map(function(t){return"string"==typeof t?n.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){var r=this.machine.options.activities;return"string"==typeof t?_(r?e({type:t},r[t]):t):t},t.prototype.getActivities=function(t,r){if(!t)return B;var n=e({},r);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,r,n){var i="string"==typeof t?this.resolve(y(this.getResolvedPath(t))):t instanceof u?t:this.resolve(t),a=n||(t instanceof u?t.context:void 0),o=A(r),s=o.type;if(this.strict&&-1===this.events.indexOf(s))throw new Error("Machine '"+this.id+"' does not accept event '"+s+"'");var c=u.from(i,a),f=this._transition(c.value,c,o,a),h=e({},f,{tree:f.tree?f.tree.resolved:void 0});return this.resolveTransition(h,c,o)},t.prototype.resolveTransition=function(e,r,n,i){var o;void 0===i&&(i=!1);var s=e.tree?e.tree.stateValue:void 0,c=r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0,f=this.getActions(e,r,i),h=e.tree?e.tree.getEntryExitStates(this.getStateTree(r.value)):{entry:[],exit:[]},l=e.tree?this.getActivities({entry:new Set(h.entry),exit:new Set(h.exit)},r.activities):{},y=f.filter(function(t){return"object"==typeof t&&(t.type===w||t.type===E)}),p=f.filter(function(t){return"object"!=typeof t||t.type!==w&&t.type!==E&&t.type!==k}),v=f.filter(function(t){return"object"==typeof t&&t.type===k}),d=r.context?v.reduce(function(t,e){var r=e.assignment,i={};return"function"==typeof r?i=r(t,n||{type:m.Init}):Object.keys(r).forEach(function(e){var a=r[e];i[e]="function"==typeof a?a(t,n):a}),Object.assign({},t,i)},r.context):r.context,g=s?this.getStateNodes(s):[];g.some(function(t){return t.transient})&&y.push({type:E});var S,b,x=a([this],g).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),O=s?new u(s,d,c?t.updateHistoryValue(c,s):void 0,e.source?r:void 0,(S=p,b=this.options.actions,S?(Array.isArray(S)?S:[S]).map(function(t){return V(t,b)}):[]),l,x,y):void 0;if(!O)return u.inert(r,d);r.history&&delete r.history.history;for(var j=O;y.length;){var N=j.actions,A=y.shift();(o=(j=this.transition(j,A.type===E?F:A.event,j.context)).actions).unshift.apply(o,a(N))}return j},t.prototype.ensureValidPaths=function(t){var e,r,i=this,a=new Map,o=b(t.map(function(t){return i.getRelativeStateNodes(t)}));try{t:for(var s=n(o),u=s.next();!u.done;u=s.next())for(var c=u.value,f=c;f.parent;){if(a.has(f.parent)){if("parallel"===f.parent.type)continue t;throw new Error("State node '"+c.id+"' shares parent '"+f.parent.id+"' with state node '"+a.get(f.parent).map(function(t){return t.id})+"'")}a.get(f.parent)?a.get(f.parent).push(c):a.set(f.parent,[c]),f=f.parent}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}},t.prototype.getStateNode=function(t){if(L(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=L(t)?t.slice("#".length):t;if(e===this.id)return this;var r=this.machine.idMap[e];if(!r)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return r},t.prototype.getStateNodeByPath=function(t){for(var e=h(t,this.delimiter),r=this;e.length;){var n=e.shift();r=r.getStateNode(n)}return r},t.prototype.resolve=function(t){var e,r=this;if("string"==typeof t){var n=this.getStateNode(t);return"parallel"===n.type||"compound"===n.type?((e={})[t]=n.initialStateValue,e):t}return Object.keys(t).length?"parallel"===this.type?p(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):B}):p(t,function(t,e){return t?r.getStateNode(e).resolve(t):B}):this.initialStateValue||{}},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=v(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[r]=this.states[this.initial].resolvedStateValue,e):r},enumerable:!0,configurable:!0}),t.prototype.getResolvedPath=function(t){if(L(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return h(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?v(this.states,function(t){return t.initialStateValue||B},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.getState=function(t,e){void 0===e&&(e=this.machine.context);var r={},n=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&n.push.apply(n,a(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[c(t)]=!0,n.push(J(t))})});var i=n.filter(function(t){return"object"==typeof t&&t.type===k}),o=e?i.reduce(function(t,e){var r=e.assignment,n={};return"function"==typeof r?n=r(t,{type:"init"}):Object.keys(r).forEach(function(e){var i=r[e];n[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,n)},e):e;return new u(t,o,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.getState(t);return this.resolveTransition({tree:this.getStateTree(t),source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(t)),exit:new Set},actions:[]},e,void 0,!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&&L(e.target)?y(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 r=[];return Object.keys(t).forEach(function(n){r.push.apply(r,a(e.states[n].getStates(t[n])))}),r},t.prototype.getRelativeStateNodes=function(t,e,r){if(void 0===r&&(r=!0),"string"==typeof t&&L(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=h(t,this.delimiter),a=(this.parent||this).getFromRelativePath(i,e);return r?b(a.map(function(t){return t.initialStateNodes})):a},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 b(S(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),t.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var r=i(t),n=r[0],a=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if(o.history)return o.resolveHistory(e);if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(a,e)},t.updateHistoryValue=function(t,e){return{current:e,states:function t(e,r){return p(e.states,function(e,n){if(e){var i=("string"==typeof r?void 0:r[n])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},t.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,function(e,r){if(!t)return e.historyValue();var n="string"==typeof t?void 0:t[r];return e.historyValue(n||e.initialStateValue)},function(t){return!t.history})}},t.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var r=this.parent;if(!t)return this.target?b(S(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var n=g(r.path,"states")(t).current;return"string"==typeof n?[r.getStateNode(n)]:b(S(n).map(function(t){return"deep"===e.history?r.getFromRelativePath(t):[r.states[t[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=b(Object.keys(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(Object.keys(this.on));return t&&Object.keys(t).forEach(function(r){var i,a,o=t[r];if(o.states)try{for(var s=n(o.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(a=s.return)&&a.call(s)}finally{if(i)throw i.error}}}),this.__cache.events=Array.from(e)},enumerable:!0,configurable:!0}),t.prototype.formatTransition=function(t,r,n){var i=this,a=!!r&&r.internal;if(void 0===t||""===t)return e({},r,{actions:r?x(r.actions):[],target:void 0,internal:!r||(void 0===r.internal||r.internal),event:n});var o=x(t).map(function(t){var e="string"==typeof t&&t[0]===i.delimiter;return a=a||e,e&&!i.parent?t.slice(1):e?i.key+t:t});return e({},r,{actions:r?x(r.actions):[],target:o,internal:a,event:n})},t.prototype.formatTransitions=function(){var t=this,e=this.config.on||B,r=this.after,n=p(e,function(e,r){return void 0===e?[{target:void 0,event:r,actions:[]}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,r)}):"string"==typeof e?[t.formatTransition([e],void 0,r)]:[t.formatTransition(e.target,e,r)]});return r.forEach(function(t){n[t.event]=n[t.event]||[],n[t.event].push(t)}),n}}(),{});function z(t,e){return b(t.definition.on[e].map(function(r){var n=r.target?[].concat(r.target):void 0;return n?n.map(function(n){try{var i=n?t.getRelativeStateNodes(n,void 0,!1)[0]:t;return{source:t,target:i,event:e,actions:r.actions?r.actions.map(f):[],cond:r.cond,transition:r}}catch(e){return void console.warn("Target '"+n+"' not found on '"+t.id+"'")}}).filter(function(t){return void 0!==t}):[{source:t,target:t,event:e,actions:r.actions?r.actions.map(f):[],cond:r.cond,transition:r}]}))}function G(t,e){var r={},i=t.events;return function a(o){var s,u,c=JSON.stringify(o);if(!r[c]){r[c]={};try{for(var f=n(i),h=f.next();!h.done;h=f.next()){var l=h.value,y=t.transition(o,l,e);r[c][l]={state:y.value},a(y.value)}}catch(t){s={error:t}}finally{try{h&&!h.done&&(u=f.return)&&u.call(f)}finally{if(s)throw s.error}}}}(t.initialState.value),r}function q(t){if("string"==typeof t||"number"==typeof t)return""+t;var e=t.type,n=r(t,["type"]);return e+" | "+JSON.stringify(n)}function K(t){var e=t.value,r=t.context;return JSON.stringify(e)+" | "+JSON.stringify(r)}function Q(t,e){var r=e.events,i=e.filter,a={},o=b(t.events.map(function(t){return r[t]||[t]}));return function e(r){var s,u,c=K(r);if(!a[c]){a[c]={};try{for(var f=n(o),h=f.next();!h.done;h=f.next()){var l=h.value,y=t.transition(r,l);i&&!i(y)||(a[c][q(l)]={value:y.value,context:y.context},e(y))}}catch(t){s={error:t}}finally{try{h&&!h.done&&(u=f.return)&&u.call(f)}finally{if(s)throw s.error}}}}(t.initialState),a}function W(t,e){var r;if(!t.states)return U;var i=G(t,e),o=((r={})[JSON.stringify(t.initialState.value)]=[],r),s=new Set;return function e(r){var u,c,f,h,y=JSON.stringify(r);s.add(y);var p=i[y];try{for(var v=n(Object.keys(p)),d=v.next();!d.done;d=v.next()){var g=d.value;if(x=p[g].state){var m=JSON.stringify(l(x,t.delimiter));(!o[m]||o[m].length>o[y].length+1)&&(o[m]=a(o[y]||[],[{state:r,event:g}]))}}}catch(t){u={error:t}}finally{try{d&&!d.done&&(c=v.return)&&c.call(v)}finally{if(u)throw u.error}}try{for(var S=n(Object.keys(p)),b=S.next();!b.done;b=S.next()){var x;(x=p[b.value].state)&&(m=JSON.stringify(x),s.has(m)||e(x))}}catch(t){f={error:t}}finally{try{b&&!b.done&&(h=S.return)&&h.call(S)}finally{if(f)throw f.error}}return o}(t.initialState.value),o}function X(t,e){if(!t.states)return U;var r=G(t,e),i=new Set,o=[],s={};var u=JSON.stringify(t.initialState.value);return Object.keys(r).forEach(function(t){!function t(e,u){var c,f;if(i.add(e),e===u)s[u]=s[u]||[],s[u].push(a(o));else try{for(var h=n(Object.keys(r[e])),l=h.next();!l.done;l=h.next()){var y=l.value,p=r[e][y].state;if(p){var v=JSON.stringify(p);i.has(v)||(o.push({state:JSON.parse(e),event:y}),t(v,u))}}}catch(t){c={error:t}}finally{try{l&&!l.done&&(f=h.return)&&f.call(h)}finally{if(c)throw c.error}}o.pop(),i.delete(e)}(u,t)}),s}t.getNodes=function t(e){var r=e.states;return Object.keys(r).reduce(function(e,n){var i=r[n],o=t(r[n]);return e.push.apply(e,a([i],o)),e},[])},t.getEventEdges=z,t.getEdges=function t(e,r){var n=(r||{}).depth,i=void 0===n?null:n,o=[];return e.states&&null===i?Object.keys(e.states).forEach(function(r){o.push.apply(o,a(t(e.states[r])))}):i&&i>0&&Object.keys(e.states).forEach(function(r){o.push.apply(o,a(t(e.states[r],{depth:i-1})))}),Object.keys(e.on).forEach(function(t){o.push.apply(o,a(z(e,t)))}),o},t.getAdjacencyMap=G,t.deserializeStateString=function(t){var e=i(t.split(" | "),2),r=e[0],n=e[1];return{value:JSON.parse(r),context:JSON.parse(n)}},t.getValueAdjacencyMap=Q,t.getShortestValuePaths=function(t,e){if(!t.states)return U;var r=Q(t,e),i={},o=new Set;return function t(e){var s,c,f,h,l=K(e);o.add(l);var y=r[l];try{for(var p=n(Object.keys(y)),v=p.next();!v.done;v=p.next()){var d=v.value,g=y[d],m=g.value,S=g.context;if(m){var b=K(N=u.from(m,S));(!i[b]||i[b].length>i[l].length+1)&&(i[b]=a(i[l]||[],[{state:m,event:d}]))}}}catch(t){s={error:t}}finally{try{v&&!v.done&&(c=p.return)&&c.call(p)}finally{if(s)throw s.error}}try{for(var x=n(Object.keys(y)),O=x.next();!O.done;O=x.next()){var w=y[O.value],j=(m=w.value,w.context);if(m){var N=u.from(m,j);b=K(u.from(m,j)),o.has(b)||t(N)}}}catch(t){f={error:t}}finally{try{O&&!O.done&&(h=x.return)&&h.call(x)}finally{if(f)throw f.error}}return i}(t.initialState),i},t.getShortestPaths=W,t.getShortestPathsAsArray=function(t,e){var r=W(t,e);return Object.keys(r).map(function(t){return{state:JSON.parse(t),path:r[t]}})},t.getSimplePaths=X,t.getSimplePathsAsArray=function(t,e){var r=X(t,e);return Object.keys(r).map(function(t){return{state:JSON.parse(t),paths:r[t]}})},Object.defineProperty(t,"__esModule",{value:!0})});

@@ -1,1 +0,1 @@

!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,r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(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"}(e||(e={}));e.Start,e.Stop;var a=e.Raise,s=e.Send,u=e.Cancel,c=e.Null,h=e.Assign,f=(e.After,e.DoneState,e.Log),l=(e.Init,"."),p={};function y(t,e,r){void 0===r&&(r=l);var n=j(t,r),i=j(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:Object.keys(n).every(function(t){return t in i&&y(n[t],i[t])})}var v=function(){function t(e,r){var n;if(this.stateNode=e,r)if("string"==typeof r){var i=e.getStateNode(r);this.done="final"===i.type,this.value=((n={})[r]=new t(i,"compound"===i.type||"parallel"===i.type?i.initialState.value:void 0),n)}else{var o=k(r,function(r,n){return new t(e.getStateNode(n),r)});this.value=o,this.done=Object.keys(o).every(function(t){return o[t].done})}else this.done="final"===e.type,this.value=void 0}return Object.defineProperty(t.prototype,"stateValue",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return k(this.value,function(t){return t.stateValue});if("compound"===this.stateNode.type){var t=this.value[Object.keys(this.value)[0]].stateNode;return"atomic"===t.type?t.key:k(this.value,function(t){return t.stateValue})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return y(t,this.stateValue)},t.prototype.getEntryExitStates=function(t,e){var r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var n={exit:[],entry:[]};return Object.keys(this.value)[0]!==Object.keys(t.value)[0]?(n.exit=t.value[Object.keys(t.value)[0]].getExitStates(),n.entry=this.value[Object.keys(this.value)[0]].getEntryStates()):n=this.value[Object.keys(this.value)[0]].getEntryExitStates(t.value[Object.keys(t.value)[0]],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var i=Object.keys(this.value).map(function(n){return r.value[n].getEntryExitStates(t.value[n],e)}),a={exit:[],entry:[]};return i.forEach(function(t){a.exit=o(a.exit,t.exit),a.entry=o(a.entry,t.entry)}),e&&e.has(this.stateNode)&&(a.exit.push(this.stateNode),a.entry.unshift(this.stateNode)),a;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.value?[this.stateNode].concat(C(Object.keys(this.value).map(function(e){return t.value[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.value?C(Object.keys(this.value).map(function(e){return t.value[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),d=".",g="",m={},S=[],x=function(t){return"#"===t[0]},b=function(){return{guards:m}},w=(function(){function t(e,n,i){void 0===n&&(n=b());var a=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&&Object.keys(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:d),this.id=e.id||(this.machine?o([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=e.initial,this.order=e.order||-1,this.states=e.states?k(e.states,function(e,n,i,o){var s,u=new t(r({},e,{key:n,order:void 0===e.order?e.order:o,parent:a}));return Object.assign(a.idMap,r(((s={})[u.id]=u,s),u.idMap)),u}):m,this.history=!0===e.history?"shallow":e.history||!1,this.transient=!(!e.on||!e.on[g]),this.strict=!!e.strict,this.onEntry=I(e.onEntry),this.onExit=I(e.onExit),this.data=e.data,this.activities=I(e.activities).map(function(t){return a.resolveActivity(t)})}Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:k(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||S,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 r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}(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 S;if(Array.isArray(e))return e.map(function(e){return r({event:U(e.delay,t.id)},e,{actions:I(e.actions)})});var n=C(Object.keys(e).map(function(n){var i=e[n],o=+n,a=U(o,t.id);return"string"==typeof i?[{target:i,delay:o,event:a,actions:[]}]:I(i).map(function(t){return r({event:a,delay:o},t,{actions:I(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,r=this;if(!t)return[];var n=t instanceof w?t.value:j(t,this.delimiter);if("string"==typeof n){var i=this.getStateNode(n).initial;return i?this.getStateNodes(((e={})[n]=i,e)):[this.states[n]]}var o=Object.keys(n);return o.map(function(t){return r.getStateNode(t)}).concat(o.reduce(function(t,e){var i=r.getStateNode(e).getStateNodes(n[e]);return t.concat(i)},[]))},t.prototype.handles=function(t){var e=E(t);return-1!==this.events.indexOf(e)},t.prototype.transitionLeafNode=function(t,e,r,n){var i=this.getStateNode(t),a=i.next(e,r,n);if(!a.value){var s=this.next(e,r,n),u=s.value,c=s.entryExitStates,h=s.actions,f=s.paths;return{value:u,tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(o([i],c?Array.from(c.exit):[]))},actions:h,paths:f}}return a},t.prototype.transitionCompoundNode=function(t,e,r,n){var i=Object.keys(t),a=this.getStateNode(i[0]),s=a._transition(t[i[0]],e,r,n);if(!s.value){var u=this.next(e,r,n),c=u.value,h=u.entryExitStates,f=u.actions,l=u.paths;return{value:c,tree:c?this.machine.getStateTree(c):void 0,source:e,entryExitStates:{entry:h?h.entry:new Set,exit:new Set(o(s.entryExitStates?Array.from(s.entryExitStates.exit):[],[a],h?Array.from(h.exit):[]))},actions:f,paths:l}}return s},t.prototype.transitionParallelNode=function(t,e,r,n){var i=this,a={};if(Object.keys(t).forEach(function(o){var s=t[o];if(s){var u=i.getStateNode(o)._transition(s,e,r,n);u.value,a[o]=u}}),!Object.keys(a).some(function(t){return void 0!==a[t].value})){var s=this.next(e,r,n),u=s.value,c=s.entryExitStates,h=s.actions,f=s.paths;return{value:u,tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(o(Object.keys(this.states).map(function(t){return i.states[t]}),c?Array.from(c.exit):[]))},actions:h,paths:f}}var l=C(Object.keys(a).map(function(t){return a[t].paths}));if(1===l.length&&!y(N(this.path),N(l[0])))return{value:u=this.machine.resolve(_(l)),tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:Object.keys(a).map(function(t){return a[t].entryExitStates}).reduce(function(t,e){var r=e,n=r.entry,i=r.exit;return{entry:new Set(o(Array.from(t.entry),Array.from(n))),exit:new Set(o(Array.from(t.exit),Array.from(i)))}},{entry:new Set,exit:new Set}),actions:C(Object.keys(a).map(function(t){return a[t].actions})),paths:l};var p=C(Object.keys(a).map(function(t){var r=a[t].value||e.value;return V(P(i.path)(r)[t]).map(function(e){return i.path.concat(t,e)})})),v=this.machine.resolve(_(p));return{value:v,tree:v?this.machine.getStateTree(v):void 0,source:e,entryExitStates:Object.keys(a).reduce(function(t,e){var r=a[e],n=r.value,i=r.entryExitStates;if(!n||!i)return t;var s=i.entry,u=i.exit;return{entry:new Set(o(Array.from(t.entry),Array.from(s))),exit:new Set(o(Array.from(t.exit),Array.from(u)))}},{entry:new Set,exit:new Set}),actions:C(Object.keys(a).map(function(t){return a[t].actions})),paths:V(v)}},t.prototype._transition=function(t,e,r,n){return"string"==typeof t?this.transitionLeafNode(t,e,r,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,r,n):this.transitionParallelNode(t,e,r,n)},t.prototype.next=function(t,e,r){var i,a,s=this,u=e.type,h=this.on[u],f=this.transient?[{type:c}]:[];if(!h||!h.length)return{value:void 0,tree:void 0,source:t,entryExitStates:void 0,actions:f,paths:[]};var l,p=[];try{for(var v=n(h),d=v.next();!d.done;d=v.next()){var g=d.value,S=g,x=S.cond,b=S.in,w=r||m,E=!b||y(j(b,this.delimiter),P(this.path.slice(0,-2))(t.value));if((!x||this.evaluateCond(x,w,e,t.value))&&E){p=I(g.target),f.push.apply(f,o(I(g.actions))),l=g;break}}}catch(t){i={error:t}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}if(l&&0===p.length)return{value:t.value,tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,entryExitStates:void 0,actions:f,paths:[]};if(!l&&0===p.length)return{value:void 0,tree:void 0,source:t,entryExitStates:void 0,actions:f,paths:[]};var O=C(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),N=O.map(function(t){return t.path}),k=!!l.internal?[]:C(O.map(function(t){return s.nodesFromChild(t)})),A={entry:new Set(k),exit:new Set(k)},T=this.machine.resolve(_(C(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue).map(function(t){return t.path})}))));return{value:T,tree:T?this.machine.getStateTree(T):void 0,source:t,entryExitStates:A,actions:f,paths:N}},t.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],r=t;r&&r!==this;)e.push(r),r=r.parent;return e.push(this),e},t.prototype.getStateTree=function(t){return new v(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.evaluateCond=function(t,e,r,n){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,r,n)},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,r,n){var i=this;void 0===n&&(n=!1);var a=new Set,u=t.tree?t.tree.getEntryExitStates(this.getStateTree(r.value),t.entryExitStates?t.entryExitStates.entry:void 0):{entry:[],exit:[]};n&&(u.exit=[]);var c={entry:u?C(Array.from(new Set(u.entry)).map(function(e){if("final"===e.type){var r=t.tree;a.add(D(e.id));var n=e.parent?e.parent.parent:void 0;if(n){var i=T(n.path,"value")(r);i.done&&a.add(D(i.stateNode.id))}}return o(e.onEntry,e.activities.map(function(t){return z(t)}),e.delays.map(function(t){var e,r,n=t.delay,i=t.id;return e=U(n,i),r={delay:n},{type:s,event:M(e),delay:r?r.delay:void 0,id:r&&void 0!==r.id?r.id:E(e)}}))})).concat(Array.from(a).map(H)):[],exit:u?C(Array.from(new Set(u.exit)).map(function(t){return o(t.onExit,t.activities.map(function(t){return function(t){var r=F(t);return{type:e.Stop,activity:r,exec:r.stop?r.stop.exec:void 0}}(t)}),t.delays.map(function(t){var e=t.delay,r=t.id;return Q(U(e,r))}))})):[]};return c.exit.concat(t.actions).concat(c.entry).map(function(t){return"string"==typeof t?i.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){var e=this.machine.options.activities;return"string"==typeof t?F(e?r({type:t},e[t]):t):t},t.prototype.getActivities=function(t,e){if(!t)return m;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,r){var n="string"==typeof t?this.resolve(N(this.getResolvedPath(t))):t instanceof w?t:this.resolve(t),i=r||(t instanceof w?t.context:void 0),o=M(e),a=o.type;if(this.strict&&-1===this.events.indexOf(a))throw new Error("Machine '"+this.id+"' does not accept event '"+a+"'");var s=w.from(n,i),u=this._transition(s.value,s,o,i);return this.resolveTransition(u,s,o)},t.prototype.resolveTransition=function(r,n,i,s){var u;void 0===s&&(s=!1);var f=n.historyValue?n.historyValue:r.source?this.machine.historyValue(n.value):void 0,l=this.getActions(r,n,s),p=r.tree?r.tree.getEntryExitStates(this.getStateTree(n.value)):{entry:[],exit:[]},y=r.tree?this.getActivities({entry:new Set(p.entry),exit:new Set(p.exit)},n.activities):{},v=l.filter(function(t){return"object"==typeof t&&(t.type===a||t.type===c)}),d=l.filter(function(t){return"object"!=typeof t||t.type!==a&&t.type!==c&&t.type!==h}),m=l.filter(function(t){return"object"==typeof t&&t.type===h}),S=n.context?m.reduce(function(t,r){var n=r.assignment,o={};return"function"==typeof n?o=n(t,i||{type:e.Init}):Object.keys(n).forEach(function(e){var r=n[e];o[e]="function"==typeof r?r(t,i):r}),Object.assign({},t,o)},n.context):n.context,x=r.value?this.getStateNodes(r.value):[];x.some(function(t){return t.transient})&&v.push({type:c});var b=o([this],x).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),E=r.value?new w(r.value,S,f?t.updateHistoryValue(f,r.value):void 0,r.source?n:void 0,B(d,this.options.actions),y,b,v):void 0;if(!E)return w.inert(n,S);n.history&&delete n.history.history;for(var O=E;v.length;){var j=O.actions,N=v.shift();(u=(O=this.transition(O,N.type===c?g:N.event,O.context)).actions).unshift.apply(u,o(j))}return O},t.prototype.ensureValidPaths=function(t){var e,r,i=this,o=new Map,a=C(t.map(function(t){return i.getRelativeStateNodes(t)}));try{t:for(var s=n(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&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}},t.prototype.getStateNode=function(t){if(x(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=x(t)?t.slice("#".length):t;if(e===this.id)return this;var r=this.machine.idMap[e];if(!r)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return r},t.prototype.getStateNodeByPath=function(t){for(var e=O(t,this.delimiter),r=this;e.length;){var n=e.shift();r=r.getStateNode(n)}return r},t.prototype.resolve=function(t){var e,r=this;if("string"==typeof t){var n=this.getStateNode(t);return n.initial?((e={})[t]=n.initialStateValue,e):t}return"parallel"===this.type?k(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):m}):k(t,function(t,e){return t?r.getStateNode(e).resolve(t):m})},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=A(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[r]=this.states[this.initial].resolvedStateValue,e):r},enumerable:!0,configurable:!0}),t.prototype.getResolvedPath=function(t){if(x(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return O(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?A(this.states,function(t){return t.initialStateValue||m},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.getState=function(t,e){void 0===e&&(e=this.machine.context);var r={},n=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&n.push.apply(n,o(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[E(t)]=!0,n.push(z(t))})});var i=n.filter(function(t){return"object"==typeof t&&t.type===h}),a=e?i.reduce(function(t,e){var r=e.assignment,n={};return"function"==typeof r?n=r(t,{type:"init"}):Object.keys(r).forEach(function(e){var i=r[e];n[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,n)},e):e;return new w(t,a,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.getState(t);return this.resolveTransition({value:t,tree:this.getStateTree(t),source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(t)),exit:new Set},actions:[],paths:[]},e,void 0,!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&&x(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 r=[];return Object.keys(t).forEach(function(n){r.push.apply(r,o(e.states[n].getStates(t[n])))}),r},t.prototype.getRelativeStateNodes=function(t,e,r){if(void 0===r&&(r=!0),"string"==typeof t&&x(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=O(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return r?C(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 C(V(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),t.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var r=i(t),n=r[0],o=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var a=this.getStateNode(n);if(a.history)return a.resolveHistory(e);if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(o,e)},t.updateHistoryValue=function(t,e){return{current:e,states:function t(e,r){return k(e.states,function(e,n){if(e){var i=("string"==typeof r?void 0:r[n])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},t.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:A(this.states,function(e,r){if(!t)return e.historyValue();var n="string"==typeof t?void 0:t[r];return e.historyValue(n||e.initialStateValue)},function(t){return!t.history})}},t.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var r=this.parent;if(!t)return this.target?C(V(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var n=T(r.path,"states")(t).current;return"string"==typeof n?[r.getStateNode(n)]:C(V(n).map(function(t){return"deep"===e.history?r.getFromRelativePath(t):[r.states[t[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=C(Object.keys(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(Object.keys(this.on));return t&&Object.keys(t).forEach(function(r){var i,o,a=t[r];if(a.states)try{for(var s=n(a.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}),this.__cache.events=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?I(e.actions):[],target:void 0,internal:!e||(void 0===e.internal||e.internal),event:n});var a=I(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?I(e.actions):[],target:a,internal:o,event:n})},t.prototype.formatTransitions=function(){var t=this,e=this.config.on||m,r=this.after,n=k(e,function(e,r){return void 0===e?[{target:void 0,event:r,actions:[]}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,r)}):"string"==typeof e?[t.formatTransition([e],void 0,r)]:[t.formatTransition(e.target,e,r)]});return r.forEach(function(t){n[t.event]=n[t.event]||[],n[t.event].push(t)}),n}}(),function(){function t(t,e,r,n,i,o,a,s){void 0===i&&(i=[]),void 0===o&&(o=p),void 0===a&&(a={}),void 0===s&&(s=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=o,this.data=a,this.events=s}return t.from=function(e,r){return e instanceof t?e.context!==r?new t(e.value,r,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,r,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,r){return e instanceof t?e.actions.length?new t(e.value,r,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,r)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var r=Object.keys(t);return r.concat.apply(r,o(r.map(function(r){return e.toStrings(t[r]).map(function(t){return r+"."+t})})))},t.prototype.matches=function(t){return y(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,r){if(e===r)return!0;var n=Object.keys(e);var i=Object.keys(r);return n.length===i.length&&n.every(function(n){return t(e[n],r[n])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}());function E(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 O(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 j(t,e){return t instanceof w?t.value:"object"!=typeof t||t instanceof w?N(O(t,e)):t}function N(t){if(1===t.length)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function k(t,e){var r={};return Object.keys(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function A(t,e,r){var n={};return Object.keys(t).forEach(function(i){var o=t[i];r(o)&&(n[i]=e(o,i,t))}),n}var P=function(t){return function(e){var r,i,o=e;try{for(var a=n(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){r={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return o}};function T(t,e){return function(r){var i,o,a=r;try{for(var s=n(t),u=s.next();!u.done;u=s.next()){var c=u.value;a=a[e][c]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}}var V=function(t){return"string"==typeof t?[[t]]:C(Object.keys(t).map(function(e){return V(t[e]).map(function(t){return[e].concat(t)})}))},_=function(t){var e,r,i={};if(t&&1===t.length&&1===t[0].length)return t[0][0];try{for(var o=n(t),a=o.next();!a.done;a=o.next())for(var s=a.value,u=i,c=0;c<s.length;c++){var h=s[c];if(c===s.length-2){u[h]=s[c+1];break}u[h]=u[h]||{},u=u[h]}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return i};function C(t){var e;return(e=[]).concat.apply(e,o(t))}function I(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function M(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function R(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var L=function(t,e){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:R(t,e)};else{if("function"!=typeof t){var i=R(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 F(t){var e=L(t);return r({},e,{type:e.type,start:e.start?L(e.start):e.exec?L(e.exec):void 0,stop:e.stop?L(e.stop):void 0})}var B=function(t,e){return t?(Array.isArray(t)?t:[t]).map(function(t){return L(t,e)}):[]};function H(t){return{type:a,event:t}}var Q=function(t){return{type:u,sendId:t}};function z(t){var r=F(t);return{type:e.Start,activity:r,exec:r.start?r.start.exec:void 0}}function U(t,r){var n=r?"#"+r:"";return e.After+"("+t+")"+n}function D(t){return e.DoneState+"."+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 r=this.getId();return this.timeouts.set(r,{start:this.now(),timeout:e,fn:t}),r},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,r){t.now()-e.start>=e.timeout&&(e.fn.call(null),t.timeouts.delete(r))})},t.prototype.increment=function(t){this._now+=t,this.flushTimeouts()},t}(),G=function(){function t(e,n,i){void 0===i&&(i=t.defaultOptions);var o=this;this.machine=e,this.eventQueue=[],this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.initialized=!1,this.init=this.start,this.send=function(t){var e=M(t);if(!o.initialized)throw new Error('Unable to send event "'+e.type+'" to an uninitialized interpreter.');var r=o.machine.transition(o.state,e,o.extState);return o.update(r,t),o.flushEventQueue(),r},n&&this.onTransition(n);var a=r({},t.defaultOptions,i);this.clock=a.clock,this.logger=a.logger}return t.prototype.update=function(t,e){var r=this;this.state=t;var n=this.state.context;this.state.actions.forEach(function(t){r.exec(t,n,e?M(e):void 0)},n),this.listeners.forEach(function(e){return e(t)}),this.contextListeners.forEach(function(t){return t(r.state.context,r.state.history?r.state.history.context:void 0)})},t.prototype.onTransition=function(t){return this.listeners.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.off=function(t){return this.listeners.delete(t),this},t.prototype.start=function(t){return void 0===t&&(t=this.machine.initialState),this.update(t),this.initialized=!0,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},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,e,r){if(t.exec)return t.exec(e,r);switch(t.type){case s:var n=t;n.delay?this.delayedEventsMap[n.id]=this.defer(n):this.eventQueue.push(n.event);break;case u:this.cancel(t.sendId);break;case f:var i=t.expr?t.expr(e,r):void 0;t.label?this.logger(t.label,i):this.logger(i);break;default:console.warn("No implementation found for action type '"+t.type+"'")}},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=J,t}();function J(t,e,r){return new G(t,e,r)}t.SimulatedClock=q,t.Interpreter=G,t.interpret=J,Object.defineProperty(t,"__esModule",{value:!0})});
!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,r=function(){return(r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(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"}(e||(e={}));e.Start,e.Stop;var a=e.Raise,s=e.Send,u=e.Cancel,c=e.Null,h=e.Assign,f=(e.After,e.DoneState,e.Log),l=(e.Init,"."),p={};function y(t,e,r){void 0===r&&(r=l);var n=j(t,r),i=j(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:Object.keys(n).every(function(t){return t in i&&y(n[t],i[t])})}var v=function(){function t(e,r){var n;this.stateNode=e,this._stateValue=r,this.value=r?"string"==typeof r?((n={})[r]=new t(e.getStateNode(r),void 0),n):k(r,function(r,n){return new t(e.getStateNode(n),r)}):{}}return Object.defineProperty(t.prototype,"done",{get:function(){var t=this;switch(this.stateNode.type){case"final":return!0;case"compound":return this.value[Object.keys(this.value)[0]].done;case"parallel":return Object.keys(this.value).some(function(e){return t.value[e].done});default:return!1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"resolved",{get:function(){return new t(this.stateNode,this.stateNode.resolve(this.stateValue))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return _(this.stateValue)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absolute",{get:function(){var e=this,r=this._stateValue,n={},i=n;return this.stateNode.path.forEach(function(t,n){n===e.stateNode.path.length-1?i[t]=r:(i[t]={},i=i[t])}),new t(this.stateNode.machine,n)},enumerable:!0,configurable:!0}),t.prototype.clone=function(){return new t(this.stateNode,this.stateValue)},t.prototype.combine=function(t){var e,r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot combine distinct trees");if("compound"===this.stateNode.type){var n=void 0;if(Object.keys(this.value).length&&Object.keys(t.value).length){var i=Object.keys(this.value)[0];return(e={})[i]=this.value[i].combine(t.value[i]),n=e,(a=this.clone()).value=n,a}return n=Object.assign({},this.value,t.value),(a=this.clone()).value=n,a}if("parallel"===this.stateNode.type){var a,s=new Set(o(Object.keys(this.value),Object.keys(t.value))),u={};return s.forEach(function(e){r.value[e]&&t.value[e]?u[e]=r.value[e].combine(t.value[e]):u[e]=r.value[e]||t.value[e]}),(a=this.clone()).value=u,a}return this},Object.defineProperty(t.prototype,"stateValue",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return k(this.value,function(t){return t.stateValue});if("compound"===this.stateNode.type){if(0===Object.keys(this.value).length)return{};var t=this.value[Object.keys(this.value)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:k(this.value,function(t){return t.stateValue})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return y(t,this.stateValue)},t.prototype.getEntryExitStates=function(t,e){var r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var n={exit:[],entry:[]},i=Object.keys(this.value)[0],a=Object.keys(t.value)[0];return i!==a?(n.exit=t.value[a].getExitStates(),n.entry=this.value[i].getEntryStates()):n=this.value[i].getEntryExitStates(t.value[a],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var s=Object.keys(this.value).map(function(n){return r.value[n].getEntryExitStates(t.value[n],e)}),u={exit:[],entry:[]};return s.forEach(function(t){u.exit=o(u.exit,t.exit),u.entry=o(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.value?[this.stateNode].concat(T(Object.keys(this.value).map(function(e){return t.value[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.value?T(Object.keys(this.value).map(function(e){return t.value[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),d=".",g="",m={},b=[],S=function(t){return"#"===t[0]},x=function(){return{guards:m}},w=(function(){function t(e,n,i){void 0===n&&(n=x());var a=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&&Object.keys(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:d),this.id=e.id||(this.machine?o([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=e.initial,this.order=e.order||-1,this.states=e.states?k(e.states,function(e,n,i,o){var s,u=new t(r({},e,{key:n,order:void 0===e.order?e.order:o,parent:a}));return Object.assign(a.idMap,r(((s={})[u.id]=u,s),u.idMap)),u}):m,this.history=!0===e.history?"shallow":e.history||!1,this.transient=!(!e.on||!e.on[g]),this.strict=!!e.strict,this.onEntry=C(e.onEntry),this.onExit=C(e.onExit),this.data=e.data,this.activities=C(e.activities).map(function(t){return a.resolveActivity(t)})}Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:k(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||b,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 r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}(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 b;if(Array.isArray(e))return e.map(function(e){return r({event:z(e.delay,t.id)},e,{actions:C(e.actions)})});var n=T(Object.keys(e).map(function(n){var i=e[n],o=+n,a=z(o,t.id);return"string"==typeof i?[{target:i,delay:o,event:a,actions:[]}]:C(i).map(function(t){return r({event:a,delay:o},t,{actions:C(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,r=this;if(!t)return[];var n=t instanceof w?t.value:j(t,this.delimiter);if("string"==typeof n){var i=this.getStateNode(n).initial;return i?this.getStateNodes(((e={})[n]=i,e)):[this.states[n]]}var o=Object.keys(n);return o.map(function(t){return r.getStateNode(t)}).concat(o.reduce(function(t,e){var i=r.getStateNode(e).getStateNodes(n[e]);return t.concat(i)},[]))},t.prototype.handles=function(t){var e=E(t);return-1!==this.events.indexOf(e)},t.prototype.transitionLeafNode=function(t,e,r,n){var i=this.getStateNode(t),a=i.next(e,r,n);if(!a.tree){var s=this.next(e,r,n),u=s.entryExitStates,c=s.actions;return{tree:s.tree,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set(o([i],u?Array.from(u.exit):[]))},actions:c}}return a},t.prototype.transitionCompoundNode=function(t,e,r,n){var i=Object.keys(t),a=this.getStateNode(i[0]),s=a._transition(t[i[0]],e,r,n);if(!s.tree){var u=this.next(e,r,n),c=u.entryExitStates,h=u.actions;return{tree:u.tree,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(o(s.entryExitStates?Array.from(s.entryExitStates.exit):[],[a],c?Array.from(c.exit):[]))},actions:h}}return s},t.prototype.transitionParallelNode=function(t,e,r,n){var i=this,a={};if(Object.keys(t).forEach(function(o){var s=t[o];if(s){var u=i.getStateNode(o)._transition(s,e,r,n);u.tree,a[o]=u}}),!Object.keys(a).some(function(t){return void 0!==a[t].tree})){var s=this.next(e,r,n),u=s.entryExitStates,c=s.actions;return{tree:s.tree,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set(o(Object.keys(this.states).map(function(t){return i.states[t]}),u?Array.from(u.exit):[]))},actions:c}}var h=Object.keys(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!==h.paths.length||y(j(this.path,this.delimiter),h.stateValue)?{tree:Object.keys(a).map(function(t){var r=a[t],n=V(i.path)(r.tree?r.tree.stateValue:e.value||e.value)[t];return new v(i.getStateNode(t),n).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,entryExitStates:Object.keys(a).reduce(function(t,e){var r=a[e],n=r.tree,i=r.entryExitStates;if(!n||!i)return t;var s=i.entry,u=i.exit;return{entry:new Set(o(Array.from(t.entry),Array.from(s))),exit:new Set(o(Array.from(t.exit),Array.from(u)))}},{entry:new Set,exit:new Set}),actions:T(Object.keys(a).map(function(t){return a[t].actions}))}:{tree:h,source:e,entryExitStates:Object.keys(a).map(function(t){return a[t].entryExitStates}).reduce(function(t,e){var r=e,n=r.entry,i=r.exit;return{entry:new Set(o(Array.from(t.entry),Array.from(n))),exit:new Set(o(Array.from(t.exit),Array.from(i)))}},{entry:new Set,exit:new Set}),actions:T(Object.keys(a).map(function(t){return a[t].actions}))}},t.prototype._transition=function(t,e,r,n){return"string"==typeof t?this.transitionLeafNode(t,e,r,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,r,n):this.transitionParallelNode(t,e,r,n)},t.prototype.next=function(t,e,r){var i,a,s=this,u=e.type,h=this.on[u],f=this.transient?[{type:c}]:[];if(!h||!h.length)return{tree:void 0,source:t,entryExitStates:void 0,actions:f};var l,p=[];try{for(var v=n(h),d=v.next();!d.done;d=v.next()){var g=d.value,b=g,S=b.cond,x=b.in,w=r||m,E=!x||y(j(x,this.delimiter),V(this.path.slice(0,-2))(t.value));if((!S||this.evaluateCond(S,w,e,t.value))&&E){p=C(g.target),f.push.apply(f,o(C(g.actions))),l=g;break}}}catch(t){i={error:t}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}if(l&&0===p.length)return{tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,entryExitStates:void 0,actions:f};if(!l&&0===p.length)return{tree:void 0,source:t,entryExitStates:void 0,actions:f};var O=T(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),N=!!l.internal?[]:T(O.map(function(t){return s.nodesFromChild(t)})),k={entry:new Set(N),exit:new Set(N)};return{tree:O.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)}),source:t,entryExitStates:k,actions:f}},Object.defineProperty(t.prototype,"tree",{get:function(){var t=j(this.path,this.delimiter);return new v(this.machine,t)},enumerable:!0,configurable:!0}),t.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],r=t;r&&r!==this;)e.push(r),r=r.parent;return e.push(this),e},t.prototype.getStateTree=function(t){return new v(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.evaluateCond=function(t,e,r,n){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,r,n)},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,r,n){var i=this;void 0===n&&(n=!1);var a=new Set,u=t.tree?t.tree.resolved.getEntryExitStates(this.getStateTree(r.value),t.entryExitStates?t.entryExitStates.entry:void 0):{entry:[],exit:[]};n&&(u.exit=[]);var c={entry:u?T(Array.from(new Set(u.entry)).map(function(e){if("final"===e.type){var r=t.tree;a.add(U(e.id));var n=e.parent?e.parent.parent:void 0;if(n){var i=P(n.path,"value")(r);i.done&&a.add(U(i.stateNode.id))}}return o(e.onEntry,e.activities.map(function(t){return Q(t)}),e.delays.map(function(t){var e,r,n=t.delay,i=t.id;return e=z(n,i),r={delay:n},{type:s,event:I(e),delay:r?r.delay:void 0,id:r&&void 0!==r.id?r.id:E(e)}}))})).concat(Array.from(a).map(B)):[],exit:u?T(Array.from(new Set(u.exit)).map(function(t){return o(t.onExit,t.activities.map(function(t){return function(t){var r=R(t);return{type:e.Stop,activity:r,exec:r.stop?r.stop.exec:void 0}}(t)}),t.delays.map(function(t){var e=t.delay,r=t.id;return H(z(e,r))}))})):[]};return c.exit.concat(t.actions).concat(c.entry).map(function(t){return"string"==typeof t?i.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){var e=this.machine.options.activities;return"string"==typeof t?R(e?r({type:t},e[t]):t):t},t.prototype.getActivities=function(t,e){if(!t)return m;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 w?t:this.resolve(t),o=n||(t instanceof w?t.context:void 0),a=I(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=w.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(r,n,i,s){var u;void 0===s&&(s=!1);var f=r.tree?r.tree.stateValue:void 0,l=n.historyValue?n.historyValue:r.source?this.machine.historyValue(n.value):void 0,p=this.getActions(r,n,s),y=r.tree?r.tree.getEntryExitStates(this.getStateTree(n.value)):{entry:[],exit:[]},v=r.tree?this.getActivities({entry:new Set(y.entry),exit:new Set(y.exit)},n.activities):{},d=p.filter(function(t){return"object"==typeof t&&(t.type===a||t.type===c)}),m=p.filter(function(t){return"object"!=typeof t||t.type!==a&&t.type!==c&&t.type!==h}),b=p.filter(function(t){return"object"==typeof t&&t.type===h}),S=n.context?b.reduce(function(t,r){var n=r.assignment,o={};return"function"==typeof n?o=n(t,i||{type:e.Init}):Object.keys(n).forEach(function(e){var r=n[e];o[e]="function"==typeof r?r(t,i):r}),Object.assign({},t,o)},n.context):n.context,x=f?this.getStateNodes(f):[];x.some(function(t){return t.transient})&&d.push({type:c});var E=o([this],x).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),O=f?new w(f,S,l?t.updateHistoryValue(l,f):void 0,r.source?n:void 0,F(m,this.options.actions),v,E,d):void 0;if(!O)return w.inert(n,S);n.history&&delete n.history.history;for(var j=O;d.length;){var N=j.actions,k=d.shift();(u=(j=this.transition(j,k.type===c?g:k.event,j.context)).actions).unshift.apply(u,o(N))}return j},t.prototype.ensureValidPaths=function(t){var e,r,i=this,o=new Map,a=T(t.map(function(t){return i.getRelativeStateNodes(t)}));try{t:for(var s=n(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&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}},t.prototype.getStateNode=function(t){if(S(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=S(t)?t.slice("#".length):t;if(e===this.id)return this;var r=this.machine.idMap[e];if(!r)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return r},t.prototype.getStateNodeByPath=function(t){for(var e=O(t,this.delimiter),r=this;e.length;){var n=e.shift();r=r.getStateNode(n)}return r},t.prototype.resolve=function(t){var e,r=this;if("string"==typeof t){var n=this.getStateNode(t);return"parallel"===n.type||"compound"===n.type?((e={})[t]=n.initialStateValue,e):t}return Object.keys(t).length?"parallel"===this.type?k(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):m}):k(t,function(t,e){return t?r.getStateNode(e).resolve(t):m}):this.initialStateValue||{}},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=A(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[r]=this.states[this.initial].resolvedStateValue,e):r},enumerable:!0,configurable:!0}),t.prototype.getResolvedPath=function(t){if(S(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return O(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?A(this.states,function(t){return t.initialStateValue||m},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.getState=function(t,e){void 0===e&&(e=this.machine.context);var r={},n=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&n.push.apply(n,o(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[E(t)]=!0,n.push(Q(t))})});var i=n.filter(function(t){return"object"==typeof t&&t.type===h}),a=e?i.reduce(function(t,e){var r=e.assignment,n={};return"function"==typeof r?n=r(t,{type:"init"}):Object.keys(r).forEach(function(e){var i=r[e];n[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,n)},e):e;return new w(t,a,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.getState(t);return this.resolveTransition({tree:this.getStateTree(t),source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(t)),exit:new Set},actions:[]},e,void 0,!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&&S(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 r=[];return Object.keys(t).forEach(function(n){r.push.apply(r,o(e.states[n].getStates(t[n])))}),r},t.prototype.getRelativeStateNodes=function(t,e,r){if(void 0===r&&(r=!0),"string"==typeof t&&S(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=O(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return r?T(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 T(_(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),t.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var r=i(t),n=r[0],o=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var a=this.getStateNode(n);if(a.history)return a.resolveHistory(e);if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(o,e)},t.updateHistoryValue=function(t,e){return{current:e,states:function t(e,r){return k(e.states,function(e,n){if(e){var i=("string"==typeof r?void 0:r[n])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},t.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:A(this.states,function(e,r){if(!t)return e.historyValue();var n="string"==typeof t?void 0:t[r];return e.historyValue(n||e.initialStateValue)},function(t){return!t.history})}},t.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var r=this.parent;if(!t)return this.target?T(_(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var n=P(r.path,"states")(t).current;return"string"==typeof n?[r.getStateNode(n)]:T(_(n).map(function(t){return"deep"===e.history?r.getFromRelativePath(t):[r.states[t[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=T(Object.keys(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(Object.keys(this.on));return t&&Object.keys(t).forEach(function(r){var i,o,a=t[r];if(a.states)try{for(var s=n(a.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}),this.__cache.events=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?C(e.actions):[],target:void 0,internal:!e||(void 0===e.internal||e.internal),event:n});var a=C(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?C(e.actions):[],target:a,internal:o,event:n})},t.prototype.formatTransitions=function(){var t=this,e=this.config.on||m,r=this.after,n=k(e,function(e,r){return void 0===e?[{target:void 0,event:r,actions:[]}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,r)}):"string"==typeof e?[t.formatTransition([e],void 0,r)]:[t.formatTransition(e.target,e,r)]});return r.forEach(function(t){n[t.event]=n[t.event]||[],n[t.event].push(t)}),n}}(),function(){function t(t,e,r,n,i,o,a,s){void 0===i&&(i=[]),void 0===o&&(o=p),void 0===a&&(a={}),void 0===s&&(s=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=o,this.data=a,this.events=s}return t.from=function(e,r){return e instanceof t?e.context!==r?new t(e.value,r,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,r,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,r){return e instanceof t?e.actions.length?new t(e.value,r,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,r)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var r=Object.keys(t);return r.concat.apply(r,o(r.map(function(r){return e.toStrings(t[r]).map(function(t){return r+"."+t})})))},t.prototype.matches=function(t){return y(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,r){if(e===r)return!0;var n=Object.keys(e);var i=Object.keys(r);return n.length===i.length&&n.every(function(n){return t(e[n],r[n])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}());function E(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 O(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 j(t,e){return t instanceof w?t.value:Array.isArray(t)?N(t):"object"!=typeof t||t instanceof w?N(O(t,e)):t}function N(t){if(1===t.length)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function k(t,e){var r={};return Object.keys(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function A(t,e,r){var n={};return Object.keys(t).forEach(function(i){var o=t[i];r(o)&&(n[i]=e(o,i,t))}),n}var V=function(t){return function(e){var r,i,o=e;try{for(var a=n(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){r={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return o}};function P(t,e){return function(r){var i,o,a=r;try{for(var s=n(t),u=s.next();!u.done;u=s.next()){var c=u.value;a=a[e][c]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}}var _=function(t){return t?"string"==typeof t?[[t]]:T(Object.keys(t).map(function(e){return _(t[e]).map(function(t){return[e].concat(t)})})):[[]]};function T(t){var e;return(e=[]).concat.apply(e,o(t))}function C(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function I(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function M(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var L=function(t,e){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:M(t,e)};else{if("function"!=typeof t){var i=M(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 R(t){var e=L(t);return r({},e,{type:e.type,start:e.start?L(e.start):e.exec?L(e.exec):void 0,stop:e.stop?L(e.stop):void 0})}var F=function(t,e){return t?(Array.isArray(t)?t:[t]).map(function(t){return L(t,e)}):[]};function B(t){return{type:a,event:t}}var H=function(t){return{type:u,sendId:t}};function Q(t){var r=R(t);return{type:e.Start,activity:r,exec:r.start?r.start.exec:void 0}}function z(t,r){var n=r?"#"+r:"";return e.After+"("+t+")"+n}function U(t){return e.DoneState+"."+t}var D=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 r=this.getId();return this.timeouts.set(r,{start:this.now(),timeout:e,fn:t}),r},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,r){t.now()-e.start>=e.timeout&&(e.fn.call(null),t.timeouts.delete(r))})},t.prototype.increment=function(t){this._now+=t,this.flushTimeouts()},t}(),q=function(){function t(e,n,i){void 0===i&&(i=t.defaultOptions);var o=this;this.machine=e,this.eventQueue=[],this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.initialized=!1,this.init=this.start,this.send=function(t){var e=I(t);if(!o.initialized)throw new Error('Unable to send event "'+e.type+'" to an uninitialized interpreter.');var r=o.machine.transition(o.state,e,o.extState);return o.update(r,t),o.flushEventQueue(),r},n&&this.onTransition(n);var a=r({},t.defaultOptions,i);this.clock=a.clock,this.logger=a.logger}return t.prototype.update=function(t,e){var r=this;this.state=t;var n=this.state.context;this.state.actions.forEach(function(t){r.exec(t,n,e?I(e):void 0)},n),this.listeners.forEach(function(e){return e(t)}),this.contextListeners.forEach(function(t){return t(r.state.context,r.state.history?r.state.history.context:void 0)})},t.prototype.onTransition=function(t){return this.listeners.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.off=function(t){return this.listeners.delete(t),this},t.prototype.start=function(t){return void 0===t&&(t=this.machine.initialState),this.update(t),this.initialized=!0,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},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,e,r){if(t.exec)return t.exec(e,r);switch(t.type){case s:var n=t;n.delay?this.delayedEventsMap[n.id]=this.defer(n):this.eventQueue.push(n.event);break;case u:this.cancel(t.sendId);break;case f:var i=t.expr?t.expr(e,r):void 0;t.label?this.logger(t.label,i):this.logger(i);break;default:console.warn("No implementation found for action type '"+t.type+"'")}},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=G,t}();function G(t,e,r){return new q(t,e,r)}t.SimulatedClock=D,t.Interpreter=q,t.interpret=G,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.xstate={})}(this,function(t){"use strict";var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function n(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,a=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o}function i(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t}var a=".",o={},s=function(){function t(t,e,r,n,i,a,s,u){void 0===i&&(i=[]),void 0===a&&(a=o),void 0===s&&(s={}),void 0===u&&(u=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=a,this.data=s,this.events=u}return t.from=function(e,r){return e instanceof t?e.context!==r?new t(e.value,r,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,r,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,r){return e instanceof t?e.actions.length?new t(e.value,r,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,r)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var r=Object.keys(t);return r.concat.apply(r,i(r.map(function(r){return e.toStrings(t[r]).map(function(t){return r+"."+t})})))},t.prototype.matches=function(t){return b(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,r){if(e===r)return!0;var n=Object.keys(e);var i=Object.keys(r);return n.length===i.length&&n.every(function(n){return t(e[n],r[n])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}();function u(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 c(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 f(t,e){return t instanceof s?t.value:"object"!=typeof t||t instanceof s?h(c(t,e)):t}function h(t){if(1===t.length)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function y(t,e){var r={};return Object.keys(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function p(t,e,r){var n={};return Object.keys(t).forEach(function(i){var a=t[i];r(a)&&(n[i]=e(a,i,t))}),n}var l=function(t){return function(e){var n,i,a=e;try{for(var o=r(t),s=o.next();!s.done;s=o.next()){a=a[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return a}};function v(t,e){return function(n){var i,a,o=n;try{for(var s=r(t),u=s.next();!u.done;u=s.next()){var c=u.value;o=o[e][c]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(a=s.return)&&a.call(s)}finally{if(i)throw i.error}}return o}}var d,g=function(t){return"string"==typeof t?[[t]]:S(Object.keys(t).map(function(e){return g(t[e]).map(function(t){return[e].concat(t)})}))},m=function(t){var e,n,i={};if(t&&1===t.length&&1===t[0].length)return t[0][0];try{for(var a=r(t),o=a.next();!o.done;o=a.next())for(var s=o.value,u=i,c=0;c<s.length;c++){var f=s[c];if(c===s.length-2){u[f]=s[c+1];break}u[f]=u[f]||{},u=u[f]}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return i};function S(t){var e;return(e=[]).concat.apply(e,i(t))}function x(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function b(t,e,r){void 0===r&&(r=a);var n=f(t,r),i=f(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:Object.keys(n).every(function(t){return t in i&&b(n[t],i[t])})}(d=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",d.Stop="xstate.stop",d.Raise="xstate.raise",d.Send="xstate.send",d.Cancel="xstate.cancel",d.Null="",d.Assign="xstate.assign",d.After="xstate.after",d.DoneState="done.state",d.Log="xstate.log",d.Init="xstate.init";var j=t.ActionTypes.Start,w=t.ActionTypes.Stop,E=t.ActionTypes.Raise,O=t.ActionTypes.Send,N=t.ActionTypes.Cancel,A=t.ActionTypes.Null,k=t.ActionTypes.Assign,T=t.ActionTypes.After,P=t.ActionTypes.DoneState,V=t.ActionTypes.Log,_=t.ActionTypes.Init,C=Object.freeze({start:j,stop:w,raise:E,send:O,cancel:N,_null:A,null:A,assign:k,after:T,doneState:P,log:V,init:_});function R(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function I(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var M=function(t,r){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:I(t,r)};else{if("function"!=typeof t){var i=I(t.type,r);return i?e({},t,{exec:i}):t}n={type:t.name,exec:t}}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1}),n};function F(t){var r=M(t);return e({},r,{type:r.type,start:r.start?M(r.start):r.exec?M(r.exec):void 0,stop:r.stop?M(r.stop):void 0})}var B=function(t,e){return t?(Array.isArray(t)?t:[t]).map(function(t){return M(t,e)}):[]};function H(t){return{type:E,event:t}}function D(t,e){return{type:O,event:R(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:u(t)}}var L=function(t){return{type:N,sendId:t}};function z(e){var r=F(e);return{type:t.ActionTypes.Start,activity:r,exec:r.start?r.start.exec:void 0}}function U(e){var r=F(e);return{type:t.ActionTypes.Stop,activity:r,exec:r.stop?r.stop.exec:void 0}}function q(e,r){var n=r?"#"+r:"";return t.ActionTypes.After+"("+e+")"+n}function G(e){return t.ActionTypes.DoneState+"."+e}var J=Object.freeze({actionTypes:C,toEventObject:R,toActionObject:M,toActivityDefinition:F,toActionObjects:B,raise:H,send:D,log:function(t,e){return{type:V,label:e,expr:t}},cancel:L,start:z,stop:U,assign:function(t){return{type:k,assignment:t}},isActionObject:function(t){return"object"==typeof t&&"type"in t},after:q,done:G}),K=function(){function t(e,r){var n;if(this.stateNode=e,r)if("string"==typeof r){var i=e.getStateNode(r);this.done="final"===i.type,this.value=((n={})[r]=new t(i,"compound"===i.type||"parallel"===i.type?i.initialState.value:void 0),n)}else{var a=y(r,function(r,n){return new t(e.getStateNode(n),r)});this.value=a,this.done=Object.keys(a).every(function(t){return a[t].done})}else this.done="final"===e.type,this.value=void 0}return Object.defineProperty(t.prototype,"stateValue",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return y(this.value,function(t){return t.stateValue});if("compound"===this.stateNode.type){var t=this.value[Object.keys(this.value)[0]].stateNode;return"atomic"===t.type?t.key:y(this.value,function(t){return t.stateValue})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return b(t,this.stateValue)},t.prototype.getEntryExitStates=function(t,e){var r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var n={exit:[],entry:[]};return Object.keys(this.value)[0]!==Object.keys(t.value)[0]?(n.exit=t.value[Object.keys(t.value)[0]].getExitStates(),n.entry=this.value[Object.keys(this.value)[0]].getEntryStates()):n=this.value[Object.keys(this.value)[0]].getEntryExitStates(t.value[Object.keys(t.value)[0]],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var a=Object.keys(this.value).map(function(n){return r.value[n].getEntryExitStates(t.value[n],e)}),o={exit:[],entry:[]};return a.forEach(function(t){o.exit=i(o.exit,t.exit),o.entry=i(o.entry,t.entry)}),e&&e.has(this.stateNode)&&(o.exit.push(this.stateNode),o.entry.unshift(this.stateNode)),o;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.value?[this.stateNode].concat(S(Object.keys(this.value).map(function(e){return t.value[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.value?S(Object.keys(this.value).map(function(e){return t.value[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),Q=".",W="",X={},Y=[],Z=function(t){return"#"===t[0]},$=function(){return{guards:X}},tt=function(){function a(t,r,n){void 0===r&&(r=$());var o=this;this._config=t,this.options=r,this.context=n,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.key=t.key||t.id||"(machine)",this.type=t.type||(t.parallel?"parallel":t.states&&Object.keys(t.states).length?"compound":t.history?"history":"atomic"),this.parent=t.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=t.delimiter||(this.parent?this.parent.delimiter:Q),this.id=t.id||(this.machine?i([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=t.initial,this.order=t.order||-1,this.states=t.states?y(t.states,function(t,r,n,i){var s,u=new a(e({},t,{key:r,order:void 0===t.order?t.order:i,parent:o}));return Object.assign(o.idMap,e(((s={})[u.id]=u,s),u.idMap)),u}):X,this.history=!0===t.history?"shallow":t.history||!1,this.transient=!(!t.on||!t.on[W]),this.strict=!!t.strict,this.onEntry=x(t.onEntry),this.onExit=x(t.onExit),this.data=t.data,this.activities=x(t.activities).map(function(t){return o.resolveActivity(t)})}return Object.defineProperty(a.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:y(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||Y,data:this.data,order:this.order||-1}},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"config",{get:function(){var t=this._config;t.parent;return function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}(t,["parent"])},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"on",{get:function(){return this.formatTransitions()},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){var t=this,r=this.config.after;if(!r)return Y;if(Array.isArray(r))return r.map(function(r){return e({event:q(r.delay,t.id)},r,{actions:x(r.actions)})});var n=S(Object.keys(r).map(function(n){var i=r[n],a=+n,o=q(a,t.id);return"string"==typeof i?[{target:i,delay:a,event:o,actions:[]}]:x(i).map(function(t){return e({event:o,delay:a},t,{actions:x(t.actions)})})}));return n.sort(function(t,e){return t.delay-e.delay}),n},enumerable:!0,configurable:!0}),a.prototype.getStateNodes=function(t){var e,r=this;if(!t)return[];var n=t instanceof s?t.value:f(t,this.delimiter);if("string"==typeof n){var i=this.getStateNode(n).initial;return i?this.getStateNodes(((e={})[n]=i,e)):[this.states[n]]}var a=Object.keys(n);return a.map(function(t){return r.getStateNode(t)}).concat(a.reduce(function(t,e){var i=r.getStateNode(e).getStateNodes(n[e]);return t.concat(i)},[]))},a.prototype.handles=function(t){var e=u(t);return-1!==this.events.indexOf(e)},a.prototype.transitionLeafNode=function(t,e,r,n){var a=this.getStateNode(t),o=a.next(e,r,n);if(!o.value){var s=this.next(e,r,n),u=s.value,c=s.entryExitStates,f=s.actions,h=s.paths;return{value:u,tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(i([a],c?Array.from(c.exit):[]))},actions:f,paths:h}}return o},a.prototype.transitionCompoundNode=function(t,e,r,n){var a=Object.keys(t),o=this.getStateNode(a[0]),s=o._transition(t[a[0]],e,r,n);if(!s.value){var u=this.next(e,r,n),c=u.value,f=u.entryExitStates,h=u.actions,y=u.paths;return{value:c,tree:c?this.machine.getStateTree(c):void 0,source:e,entryExitStates:{entry:f?f.entry:new Set,exit:new Set(i(s.entryExitStates?Array.from(s.entryExitStates.exit):[],[o],f?Array.from(f.exit):[]))},actions:h,paths:y}}return s},a.prototype.transitionParallelNode=function(t,e,r,n){var a=this,o={};if(Object.keys(t).forEach(function(i){var s=t[i];if(s){var u=a.getStateNode(i)._transition(s,e,r,n);u.value,o[i]=u}}),!Object.keys(o).some(function(t){return void 0!==o[t].value})){var s=this.next(e,r,n),u=s.value,c=s.entryExitStates,f=s.actions,y=s.paths;return{value:u,tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(i(Object.keys(this.states).map(function(t){return a.states[t]}),c?Array.from(c.exit):[]))},actions:f,paths:y}}var p=S(Object.keys(o).map(function(t){return o[t].paths}));if(1===p.length&&!b(h(this.path),h(p[0])))return{value:u=this.machine.resolve(m(p)),tree:u?this.machine.getStateTree(u):void 0,source:e,entryExitStates:Object.keys(o).map(function(t){return o[t].entryExitStates}).reduce(function(t,e){var r=e,n=r.entry,a=r.exit;return{entry:new Set(i(Array.from(t.entry),Array.from(n))),exit:new Set(i(Array.from(t.exit),Array.from(a)))}},{entry:new Set,exit:new Set}),actions:S(Object.keys(o).map(function(t){return o[t].actions})),paths:p};var v=S(Object.keys(o).map(function(t){var r=o[t].value||e.value;return g(l(a.path)(r)[t]).map(function(e){return a.path.concat(t,e)})})),d=this.machine.resolve(m(v));return{value:d,tree:d?this.machine.getStateTree(d):void 0,source:e,entryExitStates:Object.keys(o).reduce(function(t,e){var r=o[e],n=r.value,a=r.entryExitStates;if(!n||!a)return t;var s=a.entry,u=a.exit;return{entry:new Set(i(Array.from(t.entry),Array.from(s))),exit:new Set(i(Array.from(t.exit),Array.from(u)))}},{entry:new Set,exit:new Set}),actions:S(Object.keys(o).map(function(t){return o[t].actions})),paths:g(d)}},a.prototype._transition=function(t,e,r,n){return"string"==typeof t?this.transitionLeafNode(t,e,r,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,r,n):this.transitionParallelNode(t,e,r,n)},a.prototype.next=function(t,e,n){var a,o,s=this,u=e.type,c=this.on[u],h=this.transient?[{type:A}]:[];if(!c||!c.length)return{value:void 0,tree:void 0,source:t,entryExitStates:void 0,actions:h,paths:[]};var y,p=[];try{for(var v=r(c),d=v.next();!d.done;d=v.next()){var g=d.value,j=g,w=j.cond,E=j.in,O=n||X,N=!E||b(f(E,this.delimiter),l(this.path.slice(0,-2))(t.value));if((!w||this.evaluateCond(w,O,e,t.value))&&N){p=x(g.target),h.push.apply(h,i(x(g.actions))),y=g;break}}}catch(t){a={error:t}}finally{try{d&&!d.done&&(o=v.return)&&o.call(v)}finally{if(a)throw a.error}}if(y&&0===p.length)return{value:t.value,tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,entryExitStates:void 0,actions:h,paths:[]};if(!y&&0===p.length)return{value:void 0,tree:void 0,source:t,entryExitStates:void 0,actions:h,paths:[]};var k=S(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),T=k.map(function(t){return t.path}),P=!!y.internal?[]:S(k.map(function(t){return s.nodesFromChild(t)})),V={entry:new Set(P),exit:new Set(P)},_=this.machine.resolve(m(S(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue).map(function(t){return t.path})}))));return{value:_,tree:_?this.machine.getStateTree(_):void 0,source:t,entryExitStates:V,actions:h,paths:T}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],r=t;r&&r!==this;)e.push(r),r=r.parent;return e.push(this),e},a.prototype.getStateTree=function(t){return new K(this,t)},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.evaluateCond=function(t,e,r,n){var i,a=this.machine.options.guards;if("string"==typeof t){if(!a||!a[t])throw new Error("Condition '"+t+"' is not implemented on machine '"+this.machine.id+"'.");i=a[t]}else i=t;return i(e,r,n)},Object.defineProperty(a.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}),a.prototype.getActions=function(t,e,r){var n=this;void 0===r&&(r=!1);var a=new Set,o=t.tree?t.tree.getEntryExitStates(this.getStateTree(e.value),t.entryExitStates?t.entryExitStates.entry:void 0):{entry:[],exit:[]};r&&(o.exit=[]);var s={entry:o?S(Array.from(new Set(o.entry)).map(function(e){if("final"===e.type){var r=t.tree;a.add(G(e.id));var n=e.parent?e.parent.parent:void 0;if(n){var o=v(n.path,"value")(r);o.done&&a.add(G(o.stateNode.id))}}return i(e.onEntry,e.activities.map(function(t){return z(t)}),e.delays.map(function(t){var e=t.delay;return D(q(e,t.id),{delay:e})}))})).concat(Array.from(a).map(H)):[],exit:o?S(Array.from(new Set(o.exit)).map(function(t){return i(t.onExit,t.activities.map(function(t){return U(t)}),t.delays.map(function(t){var e=t.delay,r=t.id;return L(q(e,r))}))})):[]};return s.exit.concat(t.actions).concat(s.entry).map(function(t){return"string"==typeof t?n.resolveAction(t):t})},a.prototype.resolveAction=function(t){var e=this.machine.options.actions;return(e?e[t]:t)||t},a.prototype.resolveActivity=function(t){var r=this.machine.options.activities;return"string"==typeof t?F(r?e({type:t},r[t]):t):t},a.prototype.getActivities=function(t,r){if(!t)return X;var n=e({},r);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},a.prototype.transition=function(t,e,r){var n="string"==typeof t?this.resolve(h(this.getResolvedPath(t))):t instanceof s?t:this.resolve(t),i=r||(t instanceof s?t.context:void 0),a=R(e),o=a.type;if(this.strict&&-1===this.events.indexOf(o))throw new Error("Machine '"+this.id+"' does not accept event '"+o+"'");var u=s.from(n,i),c=this._transition(u.value,u,a,i);return this.resolveTransition(c,u,a)},a.prototype.resolveTransition=function(e,r,n,o){var u;void 0===o&&(o=!1);var c=r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0,f=this.getActions(e,r,o),h=e.tree?e.tree.getEntryExitStates(this.getStateTree(r.value)):{entry:[],exit:[]},y=e.tree?this.getActivities({entry:new Set(h.entry),exit:new Set(h.exit)},r.activities):{},p=f.filter(function(t){return"object"==typeof t&&(t.type===E||t.type===A)}),l=f.filter(function(t){return"object"!=typeof t||t.type!==E&&t.type!==A&&t.type!==k}),v=f.filter(function(t){return"object"==typeof t&&t.type===k}),d=r.context?v.reduce(function(e,r){var i=r.assignment,a={};return"function"==typeof i?a=i(e,n||{type:t.ActionTypes.Init}):Object.keys(i).forEach(function(t){var r=i[t];a[t]="function"==typeof r?r(e,n):r}),Object.assign({},e,a)},r.context):r.context,g=e.value?this.getStateNodes(e.value):[];g.some(function(t){return t.transient})&&p.push({type:A});var m=i([this],g).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),S=e.value?new s(e.value,d,c?a.updateHistoryValue(c,e.value):void 0,e.source?r:void 0,B(l,this.options.actions),y,m,p):void 0;if(!S)return s.inert(r,d);r.history&&delete r.history.history;for(var x=S;p.length;){var b=x.actions,j=p.shift();(u=(x=this.transition(x,j.type===A?W:j.event,x.context)).actions).unshift.apply(u,i(b))}return x},a.prototype.ensureValidPaths=function(t){var e,n,i=this,a=new Map,o=S(t.map(function(t){return i.getRelativeStateNodes(t)}));try{t:for(var s=r(o),u=s.next();!u.done;u=s.next())for(var c=u.value,f=c;f.parent;){if(a.has(f.parent)){if("parallel"===f.parent.type)continue t;throw new Error("State node '"+c.id+"' shares parent '"+f.parent.id+"' with state node '"+a.get(f.parent).map(function(t){return t.id})+"'")}a.get(f.parent)?a.get(f.parent).push(c):a.set(f.parent,[c]),f=f.parent}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}},a.prototype.getStateNode=function(t){if(Z(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},a.prototype.getStateNodeById=function(t){var e=Z(t)?t.slice("#".length):t;if(e===this.id)return this;var r=this.machine.idMap[e];if(!r)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return r},a.prototype.getStateNodeByPath=function(t){for(var e=c(t,this.delimiter),r=this;e.length;){var n=e.shift();r=r.getStateNode(n)}return r},a.prototype.resolve=function(t){var e,r=this;if("string"==typeof t){var n=this.getStateNode(t);return n.initial?((e={})[t]=n.initialStateValue,e):t}return"parallel"===this.type?y(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):X}):y(t,function(t,e){return t?r.getStateNode(e).resolve(t):X})},Object.defineProperty(a.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=p(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[r]=this.states[this.initial].resolvedStateValue,e):r},enumerable:!0,configurable:!0}),a.prototype.getResolvedPath=function(t){if(Z(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return c(t,this.delimiter)},Object.defineProperty(a.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?p(this.states,function(t){return t.initialStateValue||X},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}),a.prototype.getState=function(t,e){void 0===e&&(e=this.machine.context);var r={},n=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&n.push.apply(n,i(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[u(t)]=!0,n.push(z(t))})});var a=n.filter(function(t){return"object"==typeof t&&t.type===k}),o=e?a.reduce(function(t,e){var r=e.assignment,n={};return"function"==typeof r?n=r(t,{type:"init"}):Object.keys(r).forEach(function(e){var i=r[e];n[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,n)},e):e;return new s(t,o,void 0,void 0,void 0,r,void 0,[])},Object.defineProperty(a.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.getState(t);return this.resolveTransition({value:t,tree:this.getStateTree(t),source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(t)),exit:new Set},actions:[],paths:[]},e,void 0,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if(this.history){var e=this.config;t=e.target&&"string"==typeof e.target&&Z(e.target)?h(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),a.prototype.getStates=function(t){var e=this;if("string"==typeof t)return[this.states[t]];var r=[];return Object.keys(t).forEach(function(n){r.push.apply(r,i(e.states[n].getStates(t[n])))}),r},a.prototype.getRelativeStateNodes=function(t,e,r){if(void 0===r&&(r=!0),"string"==typeof t&&Z(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=c(t,this.delimiter),a=(this.parent||this).getFromRelativePath(i,e);return r?S(a.map(function(t){return t.initialStateNodes})):a},Object.defineProperty(a.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 S(g(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),a.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var r=n(t),i=r[0],a=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+i+"' from node with no states");var o=this.getStateNode(i);if(o.history)return o.resolveHistory(e);if(!this.states[i])throw new Error("Child state '"+i+"' does not exist on '"+this.id+"'");return this.states[i].getFromRelativePath(a,e)},a.updateHistoryValue=function(t,e){return{current:e,states:function t(e,r){return y(e.states,function(e,n){if(e){var i=("string"==typeof r?void 0:r[n])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},a.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:p(this.states,function(e,r){if(!t)return e.historyValue();var n="string"==typeof t?void 0:t[r];return e.historyValue(n||e.initialStateValue)},function(t){return!t.history})}},a.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var r=this.parent;if(!t)return this.target?S(g(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var n=v(r.path,"states")(t).current;return"string"==typeof n?[r.getStateNode(n)]:S(g(n).map(function(t){return"deep"===e.history?r.getFromRelativePath(t):[r.states[t[0]]]}))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=S(Object.keys(this.states).map(function(e){return t.states[e].stateIds}));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){if(this.__cache.events)return this.__cache.events;var t=this.states,e=new Set(Object.keys(this.on));return t&&Object.keys(t).forEach(function(n){var i,a,o=t[n];if(o.states)try{for(var s=r(o.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(a=s.return)&&a.call(s)}finally{if(i)throw i.error}}}),this.__cache.events=Array.from(e)},enumerable:!0,configurable:!0}),a.prototype.formatTransition=function(t,r,n){var i=this,a=!!r&&r.internal;if(void 0===t||""===t)return e({},r,{actions:r?x(r.actions):[],target:void 0,internal:!r||(void 0===r.internal||r.internal),event:n});var o=x(t).map(function(t){var e="string"==typeof t&&t[0]===i.delimiter;return a=a||e,e&&!i.parent?t.slice(1):e?i.key+t:t});return e({},r,{actions:r?x(r.actions):[],target:o,internal:a,event:n})},a.prototype.formatTransitions=function(){var t=this,e=this.config.on||X,r=this.after,n=y(e,function(e,r){return void 0===e?[{target:void 0,event:r,actions:[]}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,r)}):"string"==typeof e?[t.formatTransition([e],void 0,r)]:[t.formatTransition(e.target,e,r)]});return r.forEach(function(t){n[t.event]=n[t.event]||[],n[t.event].push(t)}),n},a}();t.Machine=function(t,e,r){return new tt(t,e,r)},t.StateNode=tt,t.State=s,t.matchesState=b,t.mapState=function(t,e){var r;return Object.keys(t).forEach(function(t){b(t,e)&&(!r||e.length>r.length)&&(r=t)}),t[r]},t.actions=J,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.xstate={})}(this,function(t){"use strict";var e=function(){return(e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}function n(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}function i(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t}var o=".",a={},s=function(){function t(t,e,r,n,i,o,s,u){void 0===i&&(i=[]),void 0===o&&(o=a),void 0===s&&(s={}),void 0===u&&(u=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=o,this.data=s,this.events=u}return t.from=function(e,r){return e instanceof t?e.context!==r?new t(e.value,r,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,r,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,r){return e instanceof t?e.actions.length?new t(e.value,r,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,r)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var r=Object.keys(t);return r.concat.apply(r,i(r.map(function(r){return e.toStrings(t[r]).map(function(t){return r+"."+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,r){if(e===r)return!0;var n=Object.keys(e);var i=Object.keys(r);return n.length===i.length&&n.every(function(n){return t(e[n],r[n])})}(this.value,this.history.value))},enumerable:!0,configurable:!0}),t}();function u(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 c(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 f(t,e){return t instanceof s?t.value:Array.isArray(t)?h(t):"object"!=typeof t||t instanceof s?h(c(t,e)):t}function h(t){if(1===t.length)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function y(t,e){var r={};return Object.keys(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function p(t,e,r){var n={};return Object.keys(t).forEach(function(i){var o=t[i];r(o)&&(n[i]=e(o,i,t))}),n}var l=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function v(t,e){return function(n){var i,o,a=n;try{for(var s=r(t),u=s.next();!u.done;u=s.next()){var c=u.value;a=a[e][c]}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}}var d,g=function(t){return t?"string"==typeof t?[[t]]:m(Object.keys(t).map(function(e){return g(t[e]).map(function(t){return[e].concat(t)})})):[[]]};function m(t){var e;return(e=[]).concat.apply(e,i(t))}function b(t){return Array.isArray(t)?t:void 0===t?[]:[t]}function S(t,e,r){void 0===r&&(r=o);var n=f(t,r),i=f(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:Object.keys(n).every(function(t){return t in i&&S(n[t],i[t])})}(d=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",d.Stop="xstate.stop",d.Raise="xstate.raise",d.Send="xstate.send",d.Cancel="xstate.cancel",d.Null="",d.Assign="xstate.assign",d.After="xstate.after",d.DoneState="done.state",d.Log="xstate.log",d.Init="xstate.init";var x=t.ActionTypes.Start,j=t.ActionTypes.Stop,O=t.ActionTypes.Raise,w=t.ActionTypes.Send,E=t.ActionTypes.Cancel,N=t.ActionTypes.Null,A=t.ActionTypes.Assign,k=t.ActionTypes.After,V=t.ActionTypes.DoneState,P=t.ActionTypes.Log,T=t.ActionTypes.Init,_=Object.freeze({start:x,stop:j,raise:O,send:w,cancel:E,_null:N,null:N,assign:A,after:k,doneState:V,log:P,init:T});function C(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function R(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var I=function(t,r){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:R(t,r)};else{if("function"!=typeof t){var i=R(t.type,r);return i?e({},t,{exec:i}):t}n={type:t.name,exec:t}}return Object.defineProperty(n,"toString",{value:function(){return n.type},enumerable:!1}),n};function M(t){var r=I(t);return e({},r,{type:r.type,start:r.start?I(r.start):r.exec?I(r.exec):void 0,stop:r.stop?I(r.stop):void 0})}var F=function(t,e){return t?(Array.isArray(t)?t:[t]).map(function(t){return I(t,e)}):[]};function B(t){return{type:O,event:t}}function H(t,e){return{type:w,event:C(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:u(t)}}var D=function(t){return{type:E,sendId:t}};function L(e){var r=M(e);return{type:t.ActionTypes.Start,activity:r,exec:r.start?r.start.exec:void 0}}function z(e){var r=M(e);return{type:t.ActionTypes.Stop,activity:r,exec:r.stop?r.stop.exec:void 0}}function U(e,r){var n=r?"#"+r:"";return t.ActionTypes.After+"("+e+")"+n}function q(e){return t.ActionTypes.DoneState+"."+e}var G=Object.freeze({actionTypes:_,toEventObject:C,toActionObject:I,toActivityDefinition:M,toActionObjects:F,raise:B,send:H,log:function(t,e){return{type:P,label:e,expr:t}},cancel:D,start:L,stop:z,assign:function(t){return{type:A,assignment:t}},isActionObject:function(t){return"object"==typeof t&&"type"in t},after:U,done:q}),J=function(){function t(e,r){var n;this.stateNode=e,this._stateValue=r,this.value=r?"string"==typeof r?((n={})[r]=new t(e.getStateNode(r),void 0),n):y(r,function(r,n){return new t(e.getStateNode(n),r)}):{}}return Object.defineProperty(t.prototype,"done",{get:function(){var t=this;switch(this.stateNode.type){case"final":return!0;case"compound":return this.value[Object.keys(this.value)[0]].done;case"parallel":return Object.keys(this.value).some(function(e){return t.value[e].done});default:return!1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"resolved",{get:function(){return new t(this.stateNode,this.stateNode.resolve(this.stateValue))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return g(this.stateValue)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absolute",{get:function(){var e=this,r=this._stateValue,n={},i=n;return this.stateNode.path.forEach(function(t,n){n===e.stateNode.path.length-1?i[t]=r:(i[t]={},i=i[t])}),new t(this.stateNode.machine,n)},enumerable:!0,configurable:!0}),t.prototype.clone=function(){return new t(this.stateNode,this.stateValue)},t.prototype.combine=function(t){var e,r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot combine distinct trees");if("compound"===this.stateNode.type){var n=void 0;if(Object.keys(this.value).length&&Object.keys(t.value).length){var o=Object.keys(this.value)[0];return(e={})[o]=this.value[o].combine(t.value[o]),n=e,(a=this.clone()).value=n,a}return n=Object.assign({},this.value,t.value),(a=this.clone()).value=n,a}if("parallel"===this.stateNode.type){var a,s=new Set(i(Object.keys(this.value),Object.keys(t.value))),u={};return s.forEach(function(e){r.value[e]&&t.value[e]?u[e]=r.value[e].combine(t.value[e]):u[e]=r.value[e]||t.value[e]}),(a=this.clone()).value=u,a}return this},Object.defineProperty(t.prototype,"stateValue",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return y(this.value,function(t){return t.stateValue});if("compound"===this.stateNode.type){if(0===Object.keys(this.value).length)return{};var t=this.value[Object.keys(this.value)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:y(this.value,function(t){return t.stateValue})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return S(t,this.stateValue)},t.prototype.getEntryExitStates=function(t,e){var r=this;if(t.stateNode!==this.stateNode)throw new Error("Cannot compare distinct trees");switch(this.stateNode.type){case"compound":var n={exit:[],entry:[]},o=Object.keys(this.value)[0],a=Object.keys(t.value)[0];return o!==a?(n.exit=t.value[a].getExitStates(),n.entry=this.value[o].getEntryStates()):n=this.value[o].getEntryExitStates(t.value[a],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var s=Object.keys(this.value).map(function(n){return r.value[n].getEntryExitStates(t.value[n],e)}),u={exit:[],entry:[]};return s.forEach(function(t){u.exit=i(u.exit,t.exit),u.entry=i(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.value?[this.stateNode].concat(m(Object.keys(this.value).map(function(e){return t.value[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.value?m(Object.keys(this.value).map(function(e){return t.value[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),K=".",Q="",W={},X=[],Y=function(t){return"#"===t[0]},Z=function(){return{guards:W}},$=function(){function o(t,r,n){void 0===r&&(r=Z());var a=this;this._config=t,this.options=r,this.context=n,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.key=t.key||t.id||"(machine)",this.type=t.type||(t.parallel?"parallel":t.states&&Object.keys(t.states).length?"compound":t.history?"history":"atomic"),this.parent=t.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=t.delimiter||(this.parent?this.parent.delimiter:K),this.id=t.id||(this.machine?i([this.machine.key],this.path).join(this.delimiter):this.key),this.initial=t.initial,this.order=t.order||-1,this.states=t.states?y(t.states,function(t,r,n,i){var s,u=new o(e({},t,{key:r,order:void 0===t.order?t.order:i,parent:a}));return Object.assign(a.idMap,e(((s={})[u.id]=u,s),u.idMap)),u}):W,this.history=!0===t.history?"shallow":t.history||!1,this.transient=!(!t.on||!t.on[Q]),this.strict=!!t.strict,this.onEntry=b(t.onEntry),this.onExit=b(t.onExit),this.data=t.data,this.activities=b(t.activities).map(function(t){return a.resolveActivity(t)})}return Object.defineProperty(o.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:y(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||X,data:this.data,order:this.order||-1}},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"config",{get:function(){var t=this._config;t.parent;return function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&(r[n[i]]=t[n[i]])}return r}(t,["parent"])},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"on",{get:function(){return this.formatTransitions()},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"after",{get:function(){var t=this,r=this.config.after;if(!r)return X;if(Array.isArray(r))return r.map(function(r){return e({event:U(r.delay,t.id)},r,{actions:b(r.actions)})});var n=m(Object.keys(r).map(function(n){var i=r[n],o=+n,a=U(o,t.id);return"string"==typeof i?[{target:i,delay:o,event:a,actions:[]}]:b(i).map(function(t){return e({event:a,delay:o},t,{actions:b(t.actions)})})}));return n.sort(function(t,e){return t.delay-e.delay}),n},enumerable:!0,configurable:!0}),o.prototype.getStateNodes=function(t){var e,r=this;if(!t)return[];var n=t instanceof s?t.value:f(t,this.delimiter);if("string"==typeof n){var i=this.getStateNode(n).initial;return i?this.getStateNodes(((e={})[n]=i,e)):[this.states[n]]}var o=Object.keys(n);return o.map(function(t){return r.getStateNode(t)}).concat(o.reduce(function(t,e){var i=r.getStateNode(e).getStateNodes(n[e]);return t.concat(i)},[]))},o.prototype.handles=function(t){var e=u(t);return-1!==this.events.indexOf(e)},o.prototype.transitionLeafNode=function(t,e,r,n){var o=this.getStateNode(t),a=o.next(e,r,n);if(!a.tree){var s=this.next(e,r,n),u=s.entryExitStates,c=s.actions;return{tree:s.tree,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set(i([o],u?Array.from(u.exit):[]))},actions:c}}return a},o.prototype.transitionCompoundNode=function(t,e,r,n){var o=Object.keys(t),a=this.getStateNode(o[0]),s=a._transition(t[o[0]],e,r,n);if(!s.tree){var u=this.next(e,r,n),c=u.entryExitStates,f=u.actions;return{tree:u.tree,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(i(s.entryExitStates?Array.from(s.entryExitStates.exit):[],[a],c?Array.from(c.exit):[]))},actions:f}}return s},o.prototype.transitionParallelNode=function(t,e,r,n){var o=this,a={};if(Object.keys(t).forEach(function(i){var s=t[i];if(s){var u=o.getStateNode(i)._transition(s,e,r,n);u.tree,a[i]=u}}),!Object.keys(a).some(function(t){return void 0!==a[t].tree})){var s=this.next(e,r,n),u=s.entryExitStates,c=s.actions;return{tree:s.tree,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set(i(Object.keys(this.states).map(function(t){return o.states[t]}),u?Array.from(u.exit):[]))},actions:c}}var h=Object.keys(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!==h.paths.length||S(f(this.path,this.delimiter),h.stateValue)?{tree:Object.keys(a).map(function(t){var r=a[t],n=l(o.path)(r.tree?r.tree.stateValue:e.value||e.value)[t];return new J(o.getStateNode(t),n).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,entryExitStates:Object.keys(a).reduce(function(t,e){var r=a[e],n=r.tree,o=r.entryExitStates;if(!n||!o)return t;var s=o.entry,u=o.exit;return{entry:new Set(i(Array.from(t.entry),Array.from(s))),exit:new Set(i(Array.from(t.exit),Array.from(u)))}},{entry:new Set,exit:new Set}),actions:m(Object.keys(a).map(function(t){return a[t].actions}))}:{tree:h,source:e,entryExitStates:Object.keys(a).map(function(t){return a[t].entryExitStates}).reduce(function(t,e){var r=e,n=r.entry,o=r.exit;return{entry:new Set(i(Array.from(t.entry),Array.from(n))),exit:new Set(i(Array.from(t.exit),Array.from(o)))}},{entry:new Set,exit:new Set}),actions:m(Object.keys(a).map(function(t){return a[t].actions}))}},o.prototype._transition=function(t,e,r,n){return"string"==typeof t?this.transitionLeafNode(t,e,r,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,r,n):this.transitionParallelNode(t,e,r,n)},o.prototype.next=function(t,e,n){var o,a,s=this,u=e.type,c=this.on[u],h=this.transient?[{type:N}]:[];if(!c||!c.length)return{tree:void 0,source:t,entryExitStates:void 0,actions:h};var y,p=[];try{for(var v=r(c),d=v.next();!d.done;d=v.next()){var g=d.value,x=g,j=x.cond,O=x.in,w=n||W,E=!O||S(f(O,this.delimiter),l(this.path.slice(0,-2))(t.value));if((!j||this.evaluateCond(j,w,e,t.value))&&E){p=b(g.target),h.push.apply(h,i(b(g.actions))),y=g;break}}}catch(t){o={error:t}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(o)throw o.error}}if(y&&0===p.length)return{tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,entryExitStates:void 0,actions:h};if(!y&&0===p.length)return{tree:void 0,source:t,entryExitStates:void 0,actions:h};var A=m(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),k=!!y.internal?[]:m(A.map(function(t){return s.nodesFromChild(t)})),V={entry:new Set(k),exit:new Set(k)};return{tree:A.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)}),source:t,entryExitStates:V,actions:h}},Object.defineProperty(o.prototype,"tree",{get:function(){var t=f(this.path,this.delimiter);return new J(this.machine,t)},enumerable:!0,configurable:!0}),o.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],r=t;r&&r!==this;)e.push(r),r=r.parent;return e.push(this),e},o.prototype.getStateTree=function(t){return new J(this,t)},o.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},o.prototype.evaluateCond=function(t,e,r,n){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,r,n)},Object.defineProperty(o.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}),o.prototype.getActions=function(t,e,r){var n=this;void 0===r&&(r=!1);var o=new Set,a=t.tree?t.tree.resolved.getEntryExitStates(this.getStateTree(e.value),t.entryExitStates?t.entryExitStates.entry:void 0):{entry:[],exit:[]};r&&(a.exit=[]);var s={entry:a?m(Array.from(new Set(a.entry)).map(function(e){if("final"===e.type){var r=t.tree;o.add(q(e.id));var n=e.parent?e.parent.parent:void 0;if(n){var a=v(n.path,"value")(r);a.done&&o.add(q(a.stateNode.id))}}return i(e.onEntry,e.activities.map(function(t){return L(t)}),e.delays.map(function(t){var e=t.delay;return H(U(e,t.id),{delay:e})}))})).concat(Array.from(o).map(B)):[],exit:a?m(Array.from(new Set(a.exit)).map(function(t){return i(t.onExit,t.activities.map(function(t){return z(t)}),t.delays.map(function(t){var e=t.delay,r=t.id;return D(U(e,r))}))})):[]};return s.exit.concat(t.actions).concat(s.entry).map(function(t){return"string"==typeof t?n.resolveAction(t):t})},o.prototype.resolveAction=function(t){var e=this.machine.options.actions;return(e?e[t]:t)||t},o.prototype.resolveActivity=function(t){var r=this.machine.options.activities;return"string"==typeof t?M(r?e({type:t},r[t]):t):t},o.prototype.getActivities=function(t,r){if(!t)return W;var n=e({},r);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},o.prototype.transition=function(t,r,n){var i="string"==typeof t?this.resolve(h(this.getResolvedPath(t))):t instanceof s?t:this.resolve(t),o=n||(t instanceof s?t.context:void 0),a=C(r),u=a.type;if(this.strict&&-1===this.events.indexOf(u))throw new Error("Machine '"+this.id+"' does not accept event '"+u+"'");var c=s.from(i,o),f=this._transition(c.value,c,a,o),y=e({},f,{tree:f.tree?f.tree.resolved:void 0});return this.resolveTransition(y,c,a)},o.prototype.resolveTransition=function(e,r,n,a){var u;void 0===a&&(a=!1);var c=e.tree?e.tree.stateValue:void 0,f=r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0,h=this.getActions(e,r,a),y=e.tree?e.tree.getEntryExitStates(this.getStateTree(r.value)):{entry:[],exit:[]},p=e.tree?this.getActivities({entry:new Set(y.entry),exit:new Set(y.exit)},r.activities):{},l=h.filter(function(t){return"object"==typeof t&&(t.type===O||t.type===N)}),v=h.filter(function(t){return"object"!=typeof t||t.type!==O&&t.type!==N&&t.type!==A}),d=h.filter(function(t){return"object"==typeof t&&t.type===A}),g=r.context?d.reduce(function(e,r){var i=r.assignment,o={};return"function"==typeof i?o=i(e,n||{type:t.ActionTypes.Init}):Object.keys(i).forEach(function(t){var r=i[t];o[t]="function"==typeof r?r(e,n):r}),Object.assign({},e,o)},r.context):r.context,m=c?this.getStateNodes(c):[];m.some(function(t){return t.transient})&&l.push({type:N});var b=i([this],m).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),S=c?new s(c,g,f?o.updateHistoryValue(f,c):void 0,e.source?r:void 0,F(v,this.options.actions),p,b,l):void 0;if(!S)return s.inert(r,g);r.history&&delete r.history.history;for(var x=S;l.length;){var j=x.actions,w=l.shift();(u=(x=this.transition(x,w.type===N?Q:w.event,x.context)).actions).unshift.apply(u,i(j))}return x},o.prototype.ensureValidPaths=function(t){var e,n,i=this,o=new Map,a=m(t.map(function(t){return i.getRelativeStateNodes(t)}));try{t:for(var s=r(a),u=s.next();!u.done;u=s.next())for(var c=u.value,f=c;f.parent;){if(o.has(f.parent)){if("parallel"===f.parent.type)continue t;throw new Error("State node '"+c.id+"' shares parent '"+f.parent.id+"' with state node '"+o.get(f.parent).map(function(t){return t.id})+"'")}o.get(f.parent)?o.get(f.parent).push(c):o.set(f.parent,[c]),f=f.parent}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}},o.prototype.getStateNode=function(t){if(Y(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},o.prototype.getStateNodeById=function(t){var e=Y(t)?t.slice("#".length):t;if(e===this.id)return this;var r=this.machine.idMap[e];if(!r)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return r},o.prototype.getStateNodeByPath=function(t){for(var e=c(t,this.delimiter),r=this;e.length;){var n=e.shift();r=r.getStateNode(n)}return r},o.prototype.resolve=function(t){var e,r=this;if("string"==typeof t){var n=this.getStateNode(t);return"parallel"===n.type||"compound"===n.type?((e={})[t]=n.initialStateValue,e):t}return Object.keys(t).length?"parallel"===this.type?y(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):W}):y(t,function(t,e){return t?r.getStateNode(e).resolve(t):W}):this.initialStateValue||{}},Object.defineProperty(o.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=p(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[r]=this.states[this.initial].resolvedStateValue,e):r},enumerable:!0,configurable:!0}),o.prototype.getResolvedPath=function(t){if(Y(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return c(t,this.delimiter)},Object.defineProperty(o.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?p(this.states,function(t){return t.initialStateValue||W},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}),o.prototype.getState=function(t,e){void 0===e&&(e=this.machine.context);var r={},n=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&n.push.apply(n,i(t.onEntry)),t.activities&&t.activities.forEach(function(t){r[u(t)]=!0,n.push(L(t))})});var o=n.filter(function(t){return"object"==typeof t&&t.type===A}),a=e?o.reduce(function(t,e){var r=e.assignment,n={};return"function"==typeof r?n=r(t,{type:"init"}):Object.keys(r).forEach(function(e){var i=r[e];n[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,n)},e):e;return new s(t,a,void 0,void 0,void 0,r,void 0,[])},Object.defineProperty(o.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.getState(t);return this.resolveTransition({tree:this.getStateTree(t),source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(t)),exit:new Set},actions:[]},e,void 0,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"target",{get:function(){var t;if(this.history){var e=this.config;t=e.target&&"string"==typeof e.target&&Y(e.target)?h(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),o.prototype.getStates=function(t){var e=this;if("string"==typeof t)return[this.states[t]];var r=[];return Object.keys(t).forEach(function(n){r.push.apply(r,i(e.states[n].getStates(t[n])))}),r},o.prototype.getRelativeStateNodes=function(t,e,r){if(void 0===r&&(r=!0),"string"==typeof t&&Y(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=c(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return r?m(o.map(function(t){return t.initialStateNodes})):o},Object.defineProperty(o.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 m(g(e).map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),o.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var r=n(t),i=r[0],o=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+i+"' from node with no states");var a=this.getStateNode(i);if(a.history)return a.resolveHistory(e);if(!this.states[i])throw new Error("Child state '"+i+"' does not exist on '"+this.id+"'");return this.states[i].getFromRelativePath(o,e)},o.updateHistoryValue=function(t,e){return{current:e,states:function t(e,r){return y(e.states,function(e,n){if(e){var i=("string"==typeof r?void 0:r[n])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},o.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:p(this.states,function(e,r){if(!t)return e.historyValue();var n="string"==typeof t?void 0:t[r];return e.historyValue(n||e.initialStateValue)},function(t){return!t.history})}},o.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var r=this.parent;if(!t)return this.target?m(g(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var n=v(r.path,"states")(t).current;return"string"==typeof n?[r.getStateNode(n)]:m(g(n).map(function(t){return"deep"===e.history?r.getFromRelativePath(t):[r.states[t[0]]]}))},Object.defineProperty(o.prototype,"stateIds",{get:function(){var t=this,e=m(Object.keys(this.states).map(function(e){return t.states[e].stateIds}));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"events",{get:function(){if(this.__cache.events)return this.__cache.events;var t=this.states,e=new Set(Object.keys(this.on));return t&&Object.keys(t).forEach(function(n){var i,o,a=t[n];if(a.states)try{for(var s=r(a.events),u=s.next();!u.done;u=s.next()){var c=u.value;e.add(""+c)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}}),this.__cache.events=Array.from(e)},enumerable:!0,configurable:!0}),o.prototype.formatTransition=function(t,r,n){var i=this,o=!!r&&r.internal;if(void 0===t||""===t)return e({},r,{actions:r?b(r.actions):[],target:void 0,internal:!r||(void 0===r.internal||r.internal),event:n});var a=b(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 e({},r,{actions:r?b(r.actions):[],target:a,internal:o,event:n})},o.prototype.formatTransitions=function(){var t=this,e=this.config.on||W,r=this.after,n=y(e,function(e,r){return void 0===e?[{target:void 0,event:r,actions:[]}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,r)}):"string"==typeof e?[t.formatTransition([e],void 0,r)]:[t.formatTransition(e.target,e,r)]});return r.forEach(function(t){n[t.event]=n[t.event]||[],n[t.event].push(t)}),n},o}();t.Machine=function(t,e,r){return new $(t,e,r)},t.StateNode=$,t.State=s,t.matchesState=S,t.mapState=function(t,e){var r;return Object.keys(t).forEach(function(t){S(t,e)&&(!r||e.length>r.length)&&(r=t)}),t[r]},t.actions=G,Object.defineProperty(t,"__esModule",{value:!0})});

@@ -48,2 +48,3 @@ import { Event, StateValue, Action, StateTransition, MachineOptions, EventObject, HistoryValue, DefaultContext, StateNodeDefinition, DelayedTransitionDefinition, ActivityDefinition, Delay, StateTypes, StateNodeConfig, StateSchema, TransitionsDefinition, StateNodesConfig, AnyEvent } from './types';

private next;
private readonly tree;
private nodesFromChild;

@@ -64,3 +65,3 @@ private getStateTree;

getStateNodeByPath(statePath: string | string[]): StateNode<TContext>;
private resolve;
resolve(stateValue: StateValue): StateValue;
private readonly resolvedStateValue;

@@ -67,0 +68,0 @@ private getResolvedPath;

@@ -52,3 +52,3 @@ var __assign = this && this.__assign || function () {

};
import { getEventType, toStatePath, toStateValue, mapValues, path, toStatePaths, pathsToStateValue, pathToStateValue, flatten, mapFilterValues, nestedPath, toArray } from './utils';
import { getEventType, toStatePath, toStateValue, mapValues, path, toStatePaths, pathToStateValue, flatten, mapFilterValues, nestedPath, toArray } from './utils';
import { ActionTypes } from './types';

@@ -224,11 +224,9 @@ import { matchesState } from './matchesState';

var next = stateNode.next(state, eventObject, context);
if (!next.value) {
if (!next.tree) {
var _a = this.next(state, eventObject, context),
value = _a.value,
entryExitStates = _a.entryExitStates,
actions = _a.actions,
paths = _a.paths;
tree = _a.tree;
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: tree,
source: state,

@@ -239,4 +237,3 @@ entryExitStates: {

},
actions: actions,
paths: paths
actions: actions
};

@@ -250,11 +247,9 @@ }

var next = stateNode._transition(stateValue[subStateKeys[0]], state, eventObject, context);
if (!next.value) {
if (!next.tree) {
var _a = this.next(state, eventObject, context),
value = _a.value,
entryExitStates = _a.entryExitStates,
actions = _a.actions,
paths = _a.paths;
tree = _a.tree;
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: tree,
source: state,

@@ -265,4 +260,3 @@ entryExitStates: {

},
actions: actions,
paths: paths
actions: actions
};

@@ -283,3 +277,3 @@ }

var next = subStateNode._transition(subStateValue, state, eventObject, context);
if (!next.value) {
if (!next.tree) {
noTransitionKeys.push(subStateKey);

@@ -290,13 +284,11 @@ }

var willTransition = Object.keys(transitionMap).some(function (key) {
return transitionMap[key].value !== undefined;
return transitionMap[key].tree !== undefined;
});
if (!willTransition) {
var _a = this.next(state, eventObject, context),
value = _a.value,
entryExitStates = _a.entryExitStates,
actions = _a.actions,
paths = _a.paths;
tree = _a.tree;
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: tree,
source: state,

@@ -309,15 +301,18 @@ entryExitStates: {

},
actions: actions,
paths: paths
actions: actions
};
}
var allPaths = flatten(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].paths;
}));
var allTrees = Object.keys(transitionMap).map(function (key) {
return transitionMap[key].tree;
}).filter(function (t) {
return t !== undefined;
});
var combinedTree = allTrees.reduce(function (acc, t) {
return acc.combine(t);
});
var allPaths = combinedTree.paths;
// External transition that escapes orthogonal region
if (allPaths.length === 1 && !matchesState(pathToStateValue(this.path), pathToStateValue(allPaths[0]))) {
var value = this.machine.resolve(pathsToStateValue(allPaths));
if (allPaths.length === 1 && !matchesState(toStateValue(this.path, this.delimiter), combinedTree.stateValue)) {
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: combinedTree,
source: state,

@@ -337,25 +332,23 @@ entryExitStates: Object.keys(transitionMap).map(function (key) {

return transitionMap[key].actions;
})),
paths: allPaths
}))
};
}
var allResolvedPaths = flatten(Object.keys(transitionMap).map(function (key) {
var allResolvedTrees = Object.keys(transitionMap).map(function (key) {
var transition = transitionMap[key];
var value = transition.value || state.value;
return toStatePaths(path(_this.path)(value)[key]).map(function (statePath) {
return _this.path.concat(key, statePath);
});
}));
var nextStateValue = this.machine.resolve(pathsToStateValue(allResolvedPaths));
var subValue = path(_this.path)(transition.tree ? transition.tree.stateValue : state.value || state.value)[key];
return new StateTree(_this.getStateNode(key), subValue).absolute;
});
var finalCombinedTree = allResolvedTrees.reduce(function (acc, t) {
return acc.combine(t);
});
return {
value: nextStateValue,
tree: nextStateValue ? this.machine.getStateTree(nextStateValue) : undefined,
tree: finalCombinedTree,
source: state,
entryExitStates: Object.keys(transitionMap).reduce(function (allEntryExitStates, key) {
var _a = transitionMap[key],
subStateValue = _a.value,
tree = _a.tree,
entryExitStates = _a.entryExitStates;
// If the event was not handled (no subStateValue),
// machine should still be in state without reentry/exit.
if (!subStateValue || !entryExitStates) {
if (!tree || !entryExitStates) {
return allEntryExitStates;

@@ -372,4 +365,3 @@ }

return transitionMap[key].actions;
})),
paths: toStatePaths(nextStateValue)
}))
};

@@ -397,8 +389,6 @@ };

return {
value: undefined,
tree: undefined,
source: state,
entryExitStates: undefined,
actions: actions,
paths: []
actions: actions
};

@@ -436,9 +426,8 @@ }

if (selectedTransition && nextStateStrings.length === 0) {
var tree = state.value ? this.machine.getStateTree(state.value) : undefined;
return {
value: state.value,
tree: state.value ? this.machine.getStateTree(state.value) : undefined,
tree: tree,
source: state,
entryExitStates: undefined,
actions: actions,
paths: []
actions: actions
};

@@ -448,8 +437,6 @@ }

return {
value: undefined,
tree: undefined,
source: state,
entryExitStates: undefined,
actions: actions,
paths: []
actions: actions
};

@@ -460,5 +447,2 @@ }

}));
var nextStatePaths = nextStateNodes.map(function (stateNode) {
return stateNode.path;
});
var isInternal = !!selectedTransition.internal;

@@ -472,16 +456,23 @@ var reentryNodes = isInternal ? [] : flatten(nextStateNodes.map(function (n) {

};
var value = this.machine.resolve(pathsToStateValue(flatten(nextStateStrings.map(function (str) {
return _this.getRelativeStateNodes(str, state.historyValue).map(function (s) {
return s.path;
});
}))));
var trees = nextStateNodes.map(function (stateNode) {
return stateNode.tree;
});
var combinedTree = trees.reduce(function (acc, t) {
return acc.combine(t);
});
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: combinedTree,
source: state,
entryExitStates: entryExitStates,
actions: actions,
paths: nextStatePaths
actions: actions
};
};
Object.defineProperty(StateNode.prototype, "tree", {
get: function () {
var stateValue = toStateValue(this.path, this.delimiter);
return new StateTree(this.machine, stateValue);
},
enumerable: true,
configurable: true
});
StateNode.prototype.nodesFromChild = function (childStateNode) {

@@ -551,3 +542,3 @@ if (childStateNode.escapes(this)) {

var doneEvents = new Set();
var entryExitStates = transition.tree ? transition.tree.getEntryExitStates(this.getStateTree(prevState.value), transition.entryExitStates ? transition.entryExitStates.entry : undefined) : { entry: [], exit: [] };
var entryExitStates = transition.tree ? transition.tree.resolved.getEntryExitStates(this.getStateTree(prevState.value), transition.entryExitStates ? transition.entryExitStates.entry : undefined) : { entry: [], exit: [] };
if (isInitial) {

@@ -639,10 +630,4 @@ entryExitStates.exit = [];

var stateTransition = this._transition(currentState.value, currentState, eventObject, resolvedContext);
// if (stateTransition.tree) {
// const ees = stateTransition.tree.getEntryExitStates(
// this.getStateNodeValueTree(currentState.value)
// );
// console.log('entry', [...ees.entry].map(s => s.id));
// console.log('exit', [...ees.exit].map(s => s.id));
// }
return this.resolveTransition(stateTransition, currentState, eventObject);
var resolvedStateTransition = __assign({}, stateTransition, { tree: stateTransition.tree ? stateTransition.tree.resolved : undefined });
return this.resolveTransition(resolvedStateTransition, currentState, eventObject);
};

@@ -654,6 +639,7 @@ StateNode.prototype.resolveTransition = function (stateTransition, currentState, event, isInitial) {

var _a;
var resolvedStateValue = stateTransition.tree ? stateTransition.tree.stateValue : undefined;
var historyValue = currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined;
if (!IS_PRODUCTION) {
if (!IS_PRODUCTION && stateTransition.tree) {
try {
this.ensureValidPaths(stateTransition.paths);
this.ensureValidPaths(stateTransition.tree.paths); // TODO: ensure code coverage for this
} catch (e) {

@@ -664,6 +650,6 @@ throw new Error("Event '" + (event ? event.type : 'none') + "' leads to an invalid configuration: " + e.message);

var actions = this.getActions(stateTransition, currentState, isInitial);
var ees = stateTransition.tree ? stateTransition.tree.getEntryExitStates(this.getStateTree(currentState.value)) : { entry: [], exit: [] };
var entryExitStates = stateTransition.tree ? stateTransition.tree.getEntryExitStates(this.getStateTree(currentState.value)) : { entry: [], exit: [] };
var activities = stateTransition.tree ? this.getActivities({
entry: new Set(ees.entry),
exit: new Set(ees.exit)
entry: new Set(entryExitStates.entry),
exit: new Set(entryExitStates.exit)
}, currentState.activities) : {};

@@ -692,3 +678,3 @@ var raisedEvents = actions.filter(function (action) {

}, currentState.context) : currentState.context;
var stateNodes = stateTransition.value ? this.getStateNodes(stateTransition.value) : [];
var stateNodes = resolvedStateValue ? this.getStateNodes(resolvedStateValue) : [];
var isTransient = stateNodes.some(function (stateNode) {

@@ -706,3 +692,3 @@ return stateNode.transient;

}, {});
var nextState = stateTransition.value ? new State(stateTransition.value, updatedContext, historyValue ? StateNode.updateHistoryValue(historyValue, stateTransition.value) : undefined, stateTransition.source ? currentState : undefined, toActionObjects(nonEventActions, this.options.actions), activities, data, raisedEvents) : undefined;
var nextState = resolvedStateValue ? new State(resolvedStateValue, updatedContext, historyValue ? StateNode.updateHistoryValue(historyValue, resolvedStateValue) : undefined, stateTransition.source ? currentState : undefined, toActionObjects(nonEventActions, this.options.actions), activities, data, raisedEvents) : undefined;
if (!nextState) {

@@ -801,4 +787,10 @@ // Unchanged state should be returned with no actions

var subStateNode = this.getStateNode(stateValue);
return subStateNode.initial ? (_a = {}, _a[stateValue] = subStateNode.initialStateValue, _a) : stateValue;
if (subStateNode.type === 'parallel' || subStateNode.type === 'compound') {
return _a = {}, _a[stateValue] = subStateNode.initialStateValue, _a;
}
return stateValue;
}
if (!Object.keys(stateValue).length) {
return this.initialStateValue || {};
}
if (this.type === 'parallel') {

@@ -901,12 +893,2 @@ return mapValues(this.initialStateValue, function (subStateValue, subStateKey) {

return initialNextState;
// return raisedEvents.reduce((nextState, raisedEvent) => {
// const currentActions = nextState.actions;
// nextState = this.transition(
// nextState,
// raisedEvent.type === actionTypes.null ? NULL_EVENT : raisedEvent.event,
// nextState.context
// );
// nextState.actions.unshift(...currentActions);
// return nextState;
// }, initialNextState);
};

@@ -921,3 +903,2 @@ Object.defineProperty(StateNode.prototype, "initialState", {

return this.resolveTransition({
value: initialStateValue,
tree: this.getStateTree(initialStateValue),

@@ -929,4 +910,3 @@ source: undefined,

},
actions: [],
paths: []
actions: []
}, state, undefined, true // isInitial

@@ -933,0 +913,0 @@ );

@@ -5,6 +5,12 @@ import { StateNode } from './StateNode';

stateNode: StateNode;
_stateValue: StateValue | undefined;
parent?: StateTree | undefined;
done: boolean;
value: Record<string, StateTree> | undefined;
constructor(stateNode: StateNode, stateValue: StateValue | undefined);
value: Record<string, StateTree>;
constructor(stateNode: StateNode, _stateValue: StateValue | undefined);
readonly done: boolean;
readonly resolved: StateTree;
readonly paths: string[][];
readonly absolute: StateTree;
clone(): StateTree;
combine(tree: StateTree): StateTree;
readonly stateValue: StateValue;

@@ -11,0 +17,0 @@ matches(parentValue: StateValue): boolean;

@@ -25,25 +25,107 @@ var __read = this && this.__read || function (o, n) {

};
import { mapValues, flatten } from './utils';
import { mapValues, flatten, toStatePaths } from './utils';
import { matchesState } from './matchesState';
var StateTree = /** @class */ /*#__PURE__*/function () {
function StateTree(stateNode, stateValue) {
function StateTree(stateNode, _stateValue) {
var _a;
this.stateNode = stateNode;
if (!stateValue) {
this.done = stateNode.type === 'final';
this.value = undefined;
} else if (typeof stateValue === 'string') {
var childStateNode = stateNode.getStateNode(stateValue);
this.done = childStateNode.type === 'final';
this.value = (_a = {}, _a[stateValue] = new StateTree(childStateNode, childStateNode.type === 'compound' || childStateNode.type === 'parallel' ? childStateNode.initialState.value : undefined), _a);
} else {
var value_1 = mapValues(stateValue, function (subValue, key) {
return new StateTree(stateNode.getStateNode(key), subValue);
this._stateValue = _stateValue;
this.value = _stateValue ? typeof _stateValue === 'string' ? (_a = {}, _a[_stateValue] = new StateTree(stateNode.getStateNode(_stateValue), undefined), _a) : mapValues(_stateValue, function (subValue, key) {
return new StateTree(stateNode.getStateNode(key), subValue);
}) : {};
}
Object.defineProperty(StateTree.prototype, "done", {
get: function () {
var _this = this;
switch (this.stateNode.type) {
case 'final':
return true;
case 'compound':
return this.value[Object.keys(this.value)[0]].done;
case 'parallel':
return Object.keys(this.value).some(function (key) {
return _this.value[key].done;
});
default:
return false;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(StateTree.prototype, "resolved", {
get: function () {
return new StateTree(this.stateNode, this.stateNode.resolve(this.stateValue));
},
enumerable: true,
configurable: true
});
Object.defineProperty(StateTree.prototype, "paths", {
get: function () {
return toStatePaths(this.stateValue);
},
enumerable: true,
configurable: true
});
Object.defineProperty(StateTree.prototype, "absolute", {
get: function () {
var _this = this;
var _stateValue = this._stateValue;
var absoluteStateValue = {};
var marker = absoluteStateValue;
this.stateNode.path.forEach(function (key, i) {
if (i === _this.stateNode.path.length - 1) {
marker[key] = _stateValue;
} else {
marker[key] = {};
marker = marker[key];
}
});
this.value = value_1;
this.done = Object.keys(value_1).every(function (key) {
return value_1[key].done;
return new StateTree(this.stateNode.machine, absoluteStateValue);
},
enumerable: true,
configurable: true
});
StateTree.prototype.clone = function () {
return new StateTree(this.stateNode, this.stateValue);
};
StateTree.prototype.combine = function (tree) {
var _this = this;
var _a;
if (tree.stateNode !== this.stateNode) {
throw new Error('Cannot combine distinct trees');
}
if (this.stateNode.type === 'compound') {
// Only combine if no child state is defined
var newValue = void 0;
if (!Object.keys(this.value).length || !Object.keys(tree.value).length) {
newValue = Object.assign({}, this.value, tree.value);
var newTree = this.clone();
newTree.value = newValue;
return newTree;
} else {
var childKey = Object.keys(this.value)[0];
newValue = (_a = {}, _a[childKey] = this.value[childKey].combine(tree.value[childKey]), _a);
var newTree = this.clone();
newTree.value = newValue;
return newTree;
}
}
if (this.stateNode.type === 'parallel') {
var keys = new Set(__spread(Object.keys(this.value), Object.keys(tree.value)));
var newValue_1 = {};
keys.forEach(function (key) {
if (!_this.value[key] || !tree.value[key]) {
newValue_1[key] = _this.value[key] || tree.value[key];
} else {
newValue_1[key] = _this.value[key].combine(tree.value[key]);
}
});
var newTree = this.clone();
newTree.value = newValue_1;
return newTree;
}
}
// nothing to do
return this;
};
Object.defineProperty(StateTree.prototype, "stateValue", {

@@ -60,4 +142,7 @@ get: function () {

if (this.stateNode.type === 'compound') {
if (Object.keys(this.value).length === 0) {
return {};
}
var childStateNode = this.value[Object.keys(this.value)[0]].stateNode;
if (childStateNode.type === 'atomic') {
if (childStateNode.type === 'atomic' || childStateNode.type === 'final') {
return childStateNode.key;

@@ -88,7 +173,9 @@ }

};
if (Object.keys(this.value)[0] !== Object.keys(prevTree.value)[0]) {
r1.exit = prevTree.value[Object.keys(prevTree.value)[0]].getExitStates();
r1.entry = this.value[Object.keys(this.value)[0]].getEntryStates();
var currentChildKey = Object.keys(this.value)[0];
var prevChildKey = Object.keys(prevTree.value)[0];
if (currentChildKey !== prevChildKey) {
r1.exit = prevTree.value[prevChildKey].getExitStates();
r1.entry = this.value[currentChildKey].getEntryStates();
} else {
r1 = this.value[Object.keys(this.value)[0]].getEntryExitStates(prevTree.value[Object.keys(prevTree.value)[0]], externalNodes);
r1 = this.value[currentChildKey].getEntryExitStates(prevTree.value[prevChildKey], externalNodes);
}

@@ -95,0 +182,0 @@ if (externalNodes && externalNodes.has(this.stateNode)) {

@@ -183,3 +183,2 @@ import { StateNode } from './StateNode';

export interface StateTransition<TContext> {
value: StateValue | undefined;
tree: StateTree | undefined;

@@ -189,3 +188,2 @@ source: State<TContext> | undefined;

actions: Array<Action<TContext>>;
paths: string[][];
}

@@ -192,0 +190,0 @@ export interface TransitionData<TContext> {

@@ -6,3 +6,3 @@ import { State } from './State';

export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
export declare function toStateValue(stateValue: State<any> | StateValue, delimiter: string): StateValue;
export declare function toStateValue(stateValue: State<any> | StateValue | string[], delimiter: string): StateValue;
export declare function pathToStateValue(statePath: string[]): StateValue;

@@ -33,3 +33,3 @@ export declare function mapValues<T, P>(collection: {

export declare function nestedPath<T extends Record<string, any>>(props: string[], accessorProp: keyof T): (object: T) => T;
export declare const toStatePaths: (stateValue: StateValue) => string[][];
export declare const toStatePaths: (stateValue: string | import("./types").StateValueMap | undefined) => string[][];
export declare const pathsToStateValue: (paths: string[][]) => StateValue;

@@ -36,0 +36,0 @@ export declare function flatten<T>(array: T[][]): T[];

@@ -65,2 +65,5 @@ var __values = this && this.__values || function (o) {

}
if (Array.isArray(stateValue)) {
return pathToStateValue(stateValue);
}
if (typeof stateValue === 'object' && !(stateValue instanceof State)) {

@@ -157,2 +160,5 @@ return stateValue;

export var toStatePaths = function (stateValue) {
if (!stateValue) {
return [[]];
}
if (typeof stateValue === 'string') {

@@ -159,0 +165,0 @@ return [[stateValue]];

@@ -48,2 +48,3 @@ import { Event, StateValue, Action, StateTransition, MachineOptions, EventObject, HistoryValue, DefaultContext, StateNodeDefinition, DelayedTransitionDefinition, ActivityDefinition, Delay, StateTypes, StateNodeConfig, StateSchema, TransitionsDefinition, StateNodesConfig, AnyEvent } from './types';

private next;
private readonly tree;
private nodesFromChild;

@@ -64,3 +65,3 @@ private getStateTree;

getStateNodeByPath(statePath: string | string[]): StateNode<TContext>;
private resolve;
resolve(stateValue: StateValue): StateValue;
private readonly resolvedStateValue;

@@ -67,0 +68,0 @@ private getResolvedPath;

@@ -224,7 +224,6 @@ "use strict";

var next = stateNode.next(state, eventObject, context);
if (!next.value) {
var _a = this.next(state, eventObject, context), value = _a.value, entryExitStates = _a.entryExitStates, actions = _a.actions, paths = _a.paths;
if (!next.tree) {
var _a = this.next(state, eventObject, context), entryExitStates = _a.entryExitStates, actions = _a.actions, tree = _a.tree;
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: tree,
source: state,

@@ -239,4 +238,3 @@ entryExitStates: {

},
actions: actions,
paths: paths
actions: actions
};

@@ -250,7 +248,6 @@ }

var next = stateNode._transition(stateValue[subStateKeys[0]], state, eventObject, context);
if (!next.value) {
var _a = this.next(state, eventObject, context), value = _a.value, entryExitStates = _a.entryExitStates, actions = _a.actions, paths = _a.paths;
if (!next.tree) {
var _a = this.next(state, eventObject, context), entryExitStates = _a.entryExitStates, actions = _a.actions, tree = _a.tree;
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: tree,
source: state,

@@ -267,4 +264,3 @@ entryExitStates: {

},
actions: actions,
paths: paths
actions: actions
};

@@ -285,3 +281,3 @@ }

var next = subStateNode._transition(subStateValue, state, eventObject, context);
if (!next.value) {
if (!next.tree) {
noTransitionKeys.push(subStateKey);

@@ -291,8 +287,7 @@ }

});
var willTransition = Object.keys(transitionMap).some(function (key) { return transitionMap[key].value !== undefined; });
var willTransition = Object.keys(transitionMap).some(function (key) { return transitionMap[key].tree !== undefined; });
if (!willTransition) {
var _a = this.next(state, eventObject, context), value = _a.value, entryExitStates = _a.entryExitStates, actions = _a.actions, paths = _a.paths;
var _a = this.next(state, eventObject, context), entryExitStates = _a.entryExitStates, actions = _a.actions, tree = _a.tree;
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: tree,
source: state,

@@ -303,14 +298,17 @@ entryExitStates: {

},
actions: actions,
paths: paths
actions: actions
};
}
var allPaths = utils_1.flatten(Object.keys(transitionMap).map(function (key) { return transitionMap[key].paths; }));
var allTrees = Object.keys(transitionMap)
.map(function (key) { return transitionMap[key].tree; })
.filter(function (t) { return t !== undefined; });
var combinedTree = allTrees.reduce(function (acc, t) {
return acc.combine(t);
});
var allPaths = combinedTree.paths;
// External transition that escapes orthogonal region
if (allPaths.length === 1 &&
!matchesState_1.matchesState(utils_1.pathToStateValue(this.path), utils_1.pathToStateValue(allPaths[0]))) {
var value = this.machine.resolve(utils_1.pathsToStateValue(allPaths));
!matchesState_1.matchesState(utils_1.toStateValue(this.path, this.delimiter), combinedTree.stateValue)) {
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: combinedTree,
source: state,

@@ -328,25 +326,23 @@ entryExitStates: Object.keys(transitionMap)

return transitionMap[key].actions;
})),
paths: allPaths
}))
};
}
var allResolvedPaths = utils_1.flatten(Object.keys(transitionMap).map(function (key) {
var allResolvedTrees = Object.keys(transitionMap).map(function (key) {
var transition = transitionMap[key];
var value = transition.value || state.value;
return utils_1.toStatePaths(utils_1.path(_this.path)(value)[key]).map(function (statePath) {
return _this.path.concat(key, statePath);
});
}));
var nextStateValue = this.machine.resolve(utils_1.pathsToStateValue(allResolvedPaths));
var subValue = utils_1.path(_this.path)(transition.tree
? transition.tree.stateValue
: state.value || state.value)[key];
return new StateTree_1.StateTree(_this.getStateNode(key), subValue).absolute;
});
var finalCombinedTree = allResolvedTrees.reduce(function (acc, t) {
return acc.combine(t);
});
return {
value: nextStateValue,
tree: nextStateValue
? this.machine.getStateTree(nextStateValue)
: undefined,
tree: finalCombinedTree,
source: state,
entryExitStates: Object.keys(transitionMap).reduce(function (allEntryExitStates, key) {
var _a = transitionMap[key], subStateValue = _a.value, entryExitStates = _a.entryExitStates;
var _a = transitionMap[key], tree = _a.tree, entryExitStates = _a.entryExitStates;
// If the event was not handled (no subStateValue),
// machine should still be in state without reentry/exit.
if (!subStateValue || !entryExitStates) {
if (!tree || !entryExitStates) {
return allEntryExitStates;

@@ -362,4 +358,3 @@ }

return transitionMap[key].actions;
})),
paths: utils_1.toStatePaths(nextStateValue)
}))
};

@@ -389,8 +384,6 @@ };

return {
value: undefined,
tree: undefined,
source: state,
entryExitStates: undefined,
actions: actions,
paths: []
actions: actions
};

@@ -429,9 +422,10 @@ }

if (selectedTransition && nextStateStrings.length === 0) {
var tree = state.value
? this.machine.getStateTree(state.value)
: undefined;
return {
value: state.value,
tree: state.value ? this.machine.getStateTree(state.value) : undefined,
tree: tree,
source: state,
entryExitStates: undefined,
actions: actions,
paths: []
actions: actions
};

@@ -441,8 +435,6 @@ }

return {
value: undefined,
tree: undefined,
source: state,
entryExitStates: undefined,
actions: actions,
paths: []
actions: actions
};

@@ -453,3 +445,2 @@ }

}));
var nextStatePaths = nextStateNodes.map(function (stateNode) { return stateNode.path; });
var isInternal = !!selectedTransition.internal;

@@ -463,14 +454,21 @@ var reentryNodes = isInternal

};
var value = this.machine.resolve(utils_1.pathsToStateValue(utils_1.flatten(nextStateStrings.map(function (str) {
return _this.getRelativeStateNodes(str, state.historyValue).map(function (s) { return s.path; });
}))));
var trees = nextStateNodes.map(function (stateNode) { return stateNode.tree; });
var combinedTree = trees.reduce(function (acc, t) {
return acc.combine(t);
});
return {
value: value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: combinedTree,
source: state,
entryExitStates: entryExitStates,
actions: actions,
paths: nextStatePaths
actions: actions
};
};
Object.defineProperty(StateNode.prototype, "tree", {
get: function () {
var stateValue = utils_1.toStateValue(this.path, this.delimiter);
return new StateTree_1.StateTree(this.machine, stateValue);
},
enumerable: true,
configurable: true
});
StateNode.prototype.nodesFromChild = function (childStateNode) {

@@ -536,3 +534,3 @@ if (childStateNode.escapes(this)) {

var entryExitStates = transition.tree
? transition.tree.getEntryExitStates(this.getStateTree(prevState.value), transition.entryExitStates
? transition.tree.resolved.getEntryExitStates(this.getStateTree(prevState.value), transition.entryExitStates
? transition.entryExitStates.entry

@@ -633,10 +631,4 @@ : undefined)

var stateTransition = this._transition(currentState.value, currentState, eventObject, resolvedContext);
// if (stateTransition.tree) {
// const ees = stateTransition.tree.getEntryExitStates(
// this.getStateNodeValueTree(currentState.value)
// );
// console.log('entry', [...ees.entry].map(s => s.id));
// console.log('exit', [...ees.exit].map(s => s.id));
// }
return this.resolveTransition(stateTransition, currentState, eventObject);
var resolvedStateTransition = __assign({}, stateTransition, { tree: stateTransition.tree ? stateTransition.tree.resolved : undefined });
return this.resolveTransition(resolvedStateTransition, currentState, eventObject);
};

@@ -646,2 +638,5 @@ StateNode.prototype.resolveTransition = function (stateTransition, currentState, event, isInitial) {

var _a;
var resolvedStateValue = stateTransition.tree
? stateTransition.tree.stateValue
: undefined;
var historyValue = currentState.historyValue

@@ -652,5 +647,5 @@ ? currentState.historyValue

: undefined;
if (!IS_PRODUCTION) {
if (!IS_PRODUCTION && stateTransition.tree) {
try {
this.ensureValidPaths(stateTransition.paths);
this.ensureValidPaths(stateTransition.tree.paths); // TODO: ensure code coverage for this
}

@@ -662,3 +657,3 @@ catch (e) {

var actions = this.getActions(stateTransition, currentState, isInitial);
var ees = stateTransition.tree
var entryExitStates = stateTransition.tree
? stateTransition.tree.getEntryExitStates(this.getStateTree(currentState.value))

@@ -668,4 +663,4 @@ : { entry: [], exit: [] };

? this.getActivities({
entry: new Set(ees.entry),
exit: new Set(ees.exit)
entry: new Set(entryExitStates.entry),
exit: new Set(entryExitStates.exit)
}, currentState.activities)

@@ -703,4 +698,4 @@ : {};

: currentState.context;
var stateNodes = stateTransition.value
? this.getStateNodes(stateTransition.value)
var stateNodes = resolvedStateValue
? this.getStateNodes(resolvedStateValue)
: [];

@@ -717,5 +712,5 @@ var isTransient = stateNodes.some(function (stateNode) { return stateNode.transient; });

}, {});
var nextState = stateTransition.value
? new State_1.State(stateTransition.value, updatedContext, historyValue
? StateNode.updateHistoryValue(historyValue, stateTransition.value)
var nextState = resolvedStateValue
? new State_1.State(resolvedStateValue, updatedContext, historyValue
? StateNode.updateHistoryValue(historyValue, resolvedStateValue)
: undefined, stateTransition.source ? currentState : undefined, actions_1.toActionObjects(nonEventActions, this.options.actions), activities, data, raisedEvents)

@@ -818,5 +813,11 @@ : undefined;

var subStateNode = this.getStateNode(stateValue);
return subStateNode.initial
? (_a = {}, _a[stateValue] = subStateNode.initialStateValue, _a) : stateValue;
if (subStateNode.type === 'parallel' ||
subStateNode.type === 'compound') {
return _a = {}, _a[stateValue] = subStateNode.initialStateValue, _a;
}
return stateValue;
}
if (!Object.keys(stateValue).length) {
return this.initialStateValue || {};
}
if (this.type === 'parallel') {

@@ -924,12 +925,2 @@ return utils_1.mapValues(this.initialStateValue, function (subStateValue, subStateKey) {

return initialNextState;
// return raisedEvents.reduce((nextState, raisedEvent) => {
// const currentActions = nextState.actions;
// nextState = this.transition(
// nextState,
// raisedEvent.type === actionTypes.null ? NULL_EVENT : raisedEvent.event,
// nextState.context
// );
// nextState.actions.unshift(...currentActions);
// return nextState;
// }, initialNextState);
};

@@ -944,3 +935,2 @@ Object.defineProperty(StateNode.prototype, "initialState", {

return this.resolveTransition({
value: initialStateValue,
tree: this.getStateTree(initialStateValue),

@@ -952,4 +942,3 @@ source: undefined,

},
actions: [],
paths: []
actions: []
}, state, undefined, true // isInitial

@@ -956,0 +945,0 @@ );

@@ -5,6 +5,12 @@ import { StateNode } from './StateNode';

stateNode: StateNode;
_stateValue: StateValue | undefined;
parent?: StateTree | undefined;
done: boolean;
value: Record<string, StateTree> | undefined;
constructor(stateNode: StateNode, stateValue: StateValue | undefined);
value: Record<string, StateTree>;
constructor(stateNode: StateNode, _stateValue: StateValue | undefined);
readonly done: boolean;
readonly resolved: StateTree;
readonly paths: string[][];
readonly absolute: StateTree;
clone(): StateTree;
combine(tree: StateTree): StateTree;
readonly stateValue: StateValue;

@@ -11,0 +17,0 @@ matches(parentValue: StateValue): boolean;

@@ -26,27 +26,112 @@ "use strict";

var StateTree = /** @class */ (function () {
function StateTree(stateNode, stateValue) {
function StateTree(stateNode, _stateValue) {
var _a;
this.stateNode = stateNode;
if (!stateValue) {
this.done = stateNode.type === 'final';
this.value = undefined;
this._stateValue = _stateValue;
this.value = _stateValue
? typeof _stateValue === 'string'
? (_a = {},
_a[_stateValue] = new StateTree(stateNode.getStateNode(_stateValue), undefined),
_a) : utils_1.mapValues(_stateValue, function (subValue, key) {
return new StateTree(stateNode.getStateNode(key), subValue);
})
: {};
}
Object.defineProperty(StateTree.prototype, "done", {
get: function () {
var _this = this;
switch (this.stateNode.type) {
case 'final':
return true;
case 'compound':
return this.value[Object.keys(this.value)[0]].done;
case 'parallel':
return Object.keys(this.value).some(function (key) { return _this.value[key].done; });
default:
return false;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(StateTree.prototype, "resolved", {
get: function () {
return new StateTree(this.stateNode, this.stateNode.resolve(this.stateValue));
},
enumerable: true,
configurable: true
});
Object.defineProperty(StateTree.prototype, "paths", {
get: function () {
return utils_1.toStatePaths(this.stateValue);
},
enumerable: true,
configurable: true
});
Object.defineProperty(StateTree.prototype, "absolute", {
get: function () {
var _this = this;
var _stateValue = this._stateValue;
var absoluteStateValue = {};
var marker = absoluteStateValue;
this.stateNode.path.forEach(function (key, i) {
if (i === _this.stateNode.path.length - 1) {
marker[key] = _stateValue;
}
else {
marker[key] = {};
marker = marker[key];
}
});
return new StateTree(this.stateNode.machine, absoluteStateValue);
},
enumerable: true,
configurable: true
});
StateTree.prototype.clone = function () {
return new StateTree(this.stateNode, this.stateValue);
};
StateTree.prototype.combine = function (tree) {
var _this = this;
var _a;
if (tree.stateNode !== this.stateNode) {
throw new Error('Cannot combine distinct trees');
}
else if (typeof stateValue === 'string') {
var childStateNode = stateNode.getStateNode(stateValue);
this.done = childStateNode.type === 'final';
this.value = (_a = {},
_a[stateValue] = new StateTree(childStateNode, childStateNode.type === 'compound' ||
childStateNode.type === 'parallel'
? childStateNode.initialState.value
: undefined),
_a);
if (this.stateNode.type === 'compound') {
// Only combine if no child state is defined
var newValue = void 0;
if (!Object.keys(this.value).length || !Object.keys(tree.value).length) {
newValue = Object.assign({}, this.value, tree.value);
var newTree = this.clone();
newTree.value = newValue;
return newTree;
}
else {
var childKey = Object.keys(this.value)[0];
newValue = (_a = {},
_a[childKey] = this.value[childKey].combine(tree.value[childKey]),
_a);
var newTree = this.clone();
newTree.value = newValue;
return newTree;
}
}
else {
var value_1 = utils_1.mapValues(stateValue, function (subValue, key) {
return new StateTree(stateNode.getStateNode(key), subValue);
if (this.stateNode.type === 'parallel') {
var keys = new Set(__spread(Object.keys(this.value), Object.keys(tree.value)));
var newValue_1 = {};
keys.forEach(function (key) {
if (!_this.value[key] || !tree.value[key]) {
newValue_1[key] = _this.value[key] || tree.value[key];
}
else {
newValue_1[key] = _this.value[key].combine(tree.value[key]);
}
});
this.value = value_1;
this.done = Object.keys(value_1).every(function (key) { return value_1[key].done; });
var newTree = this.clone();
newTree.value = newValue_1;
return newTree;
}
}
// nothing to do
return this;
};
Object.defineProperty(StateTree.prototype, "stateValue", {

@@ -63,4 +148,7 @@ get: function () {

if (this.stateNode.type === 'compound') {
if (Object.keys(this.value).length === 0) {
return {};
}
var childStateNode = this.value[Object.keys(this.value)[0]].stateNode;
if (childStateNode.type === 'atomic') {
if (childStateNode.type === 'atomic' || childStateNode.type === 'final') {
return childStateNode.key;

@@ -91,8 +179,10 @@ }

};
if (Object.keys(this.value)[0] !== Object.keys(prevTree.value)[0]) {
r1.exit = prevTree.value[Object.keys(prevTree.value)[0]].getExitStates();
r1.entry = this.value[Object.keys(this.value)[0]].getEntryStates();
var currentChildKey = Object.keys(this.value)[0];
var prevChildKey = Object.keys(prevTree.value)[0];
if (currentChildKey !== prevChildKey) {
r1.exit = prevTree.value[prevChildKey].getExitStates();
r1.entry = this.value[currentChildKey].getEntryStates();
}
else {
r1 = this.value[Object.keys(this.value)[0]].getEntryExitStates(prevTree.value[Object.keys(prevTree.value)[0]], externalNodes);
r1 = this.value[currentChildKey].getEntryExitStates(prevTree.value[prevChildKey], externalNodes);
}

@@ -99,0 +189,0 @@ if (externalNodes && externalNodes.has(this.stateNode)) {

@@ -183,3 +183,2 @@ import { StateNode } from './StateNode';

export interface StateTransition<TContext> {
value: StateValue | undefined;
tree: StateTree | undefined;

@@ -189,3 +188,2 @@ source: State<TContext> | undefined;

actions: Array<Action<TContext>>;
paths: string[][];
}

@@ -192,0 +190,0 @@ export interface TransitionData<TContext> {

@@ -6,3 +6,3 @@ import { State } from './State';

export declare function toStatePath(stateId: string | string[], delimiter: string): string[];
export declare function toStateValue(stateValue: State<any> | StateValue, delimiter: string): StateValue;
export declare function toStateValue(stateValue: State<any> | StateValue | string[], delimiter: string): StateValue;
export declare function pathToStateValue(statePath: string[]): StateValue;

@@ -33,3 +33,3 @@ export declare function mapValues<T, P>(collection: {

export declare function nestedPath<T extends Record<string, any>>(props: string[], accessorProp: keyof T): (object: T) => T;
export declare const toStatePaths: (stateValue: StateValue) => string[][];
export declare const toStatePaths: (stateValue: string | import("./types").StateValueMap | undefined) => string[][];
export declare const pathsToStateValue: (paths: string[][]) => StateValue;

@@ -36,0 +36,0 @@ export declare function flatten<T>(array: T[][]): T[];

@@ -74,2 +74,5 @@ "use strict";

}
if (Array.isArray(stateValue)) {
return pathToStateValue(stateValue);
}
if (typeof stateValue === 'object' && !(stateValue instanceof State_1.State)) {

@@ -168,2 +171,5 @@ return stateValue;

exports.toStatePaths = function (stateValue) {
if (!stateValue) {
return [[]];
}
if (typeof stateValue === 'string') {

@@ -170,0 +176,0 @@ return [[stateValue]];

{
"name": "xstate",
"version": "4.0.0-9",
"version": "4.0.0-10",
"description": "Simple JavaScript Finite State Machines and Statecharts",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -8,3 +8,2 @@ import {

toStatePaths,
pathsToStateValue,
pathToStateValue,

@@ -310,4 +309,4 @@ flatten,

if (!next.value) {
const { value, entryExitStates, actions, paths } = this.next(
if (!next.tree) {
const { entryExitStates, actions, tree } = this.next(
state,

@@ -319,4 +318,3 @@ eventObject,

return {
value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree,
source: state,

@@ -332,4 +330,3 @@ entryExitStates: {

},
actions,
paths
actions
};

@@ -356,4 +353,4 @@ }

if (!next.value) {
const { value, entryExitStates, actions, paths } = this.next(
if (!next.tree) {
const { entryExitStates, actions, tree } = this.next(
state,

@@ -365,4 +362,3 @@ eventObject,

return {
value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree,
source: state,

@@ -381,4 +377,3 @@ entryExitStates: {

},
actions,
paths
actions
};

@@ -414,3 +409,3 @@ }

if (!next.value) {
if (!next.tree) {
noTransitionKeys.push(subStateKey);

@@ -423,7 +418,7 @@ }

const willTransition = Object.keys(transitionMap).some(
key => transitionMap[key].value !== undefined
key => transitionMap[key].tree !== undefined
);
if (!willTransition) {
const { value, entryExitStates, actions, paths } = this.next(
const { entryExitStates, actions, tree } = this.next(
state,

@@ -435,4 +430,3 @@ eventObject,

return {
value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree,
source: state,

@@ -446,21 +440,26 @@ entryExitStates: {

},
actions,
paths
actions
};
}
const allPaths = flatten(
Object.keys(transitionMap).map(key => transitionMap[key].paths)
);
const allTrees = Object.keys(transitionMap)
.map(key => transitionMap[key].tree)
.filter(t => t !== undefined) as StateTree[];
const combinedTree = allTrees.reduce((acc, t) => {
return acc.combine(t);
});
const allPaths = combinedTree.paths;
// External transition that escapes orthogonal region
if (
allPaths.length === 1 &&
!matchesState(pathToStateValue(this.path), pathToStateValue(allPaths[0]))
!matchesState(
toStateValue(this.path, this.delimiter),
combinedTree.stateValue
)
) {
const value = this.machine.resolve(pathsToStateValue(allPaths));
return {
value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: combinedTree,
source: state,

@@ -490,35 +489,31 @@ entryExitStates: Object.keys(transitionMap)

})
),
paths: allPaths
)
};
}
const allResolvedPaths = flatten(
Object.keys(transitionMap).map(key => {
const transition = transitionMap[key];
const value = transition.value || state.value;
const allResolvedTrees = Object.keys(transitionMap).map(key => {
const transition = transitionMap[key];
const subValue = path(this.path)(
transition.tree
? transition.tree.stateValue
: state.value || state.value
)[key];
return toStatePaths(path(this.path)(value)[key]).map(statePath =>
this.path.concat(key, statePath)
);
})
);
return new StateTree(this.getStateNode(key), subValue).absolute;
});
const nextStateValue = this.machine.resolve(
pathsToStateValue(allResolvedPaths)
);
const finalCombinedTree = allResolvedTrees.reduce((acc, t) => {
return acc.combine(t);
});
return {
value: nextStateValue,
tree: nextStateValue
? this.machine.getStateTree(nextStateValue)
: undefined,
tree: finalCombinedTree,
source: state,
entryExitStates: Object.keys(transitionMap).reduce(
(allEntryExitStates, key) => {
const { value: subStateValue, entryExitStates } = transitionMap[key];
const { tree, entryExitStates } = transitionMap[key];
// If the event was not handled (no subStateValue),
// machine should still be in state without reentry/exit.
if (!subStateValue || !entryExitStates) {
if (!tree || !entryExitStates) {
return allEntryExitStates;

@@ -546,4 +541,3 @@ }

})
),
paths: toStatePaths(nextStateValue)
)
};

@@ -583,8 +577,6 @@ }

return {
value: undefined,
tree: undefined,
source: state,
entryExitStates: undefined,
actions,
paths: []
actions
};

@@ -624,21 +616,20 @@ }

// targetless transition
if (selectedTransition! && nextStateStrings.length === 0) {
if (selectedTransition && nextStateStrings.length === 0) {
const tree = state.value
? this.machine.getStateTree(state.value)
: undefined;
return {
value: state.value,
tree: state.value ? this.machine.getStateTree(state.value) : undefined,
tree,
source: state,
entryExitStates: undefined,
actions,
paths: []
actions
};
}
if (!selectedTransition! && nextStateStrings.length === 0) {
if (!selectedTransition && nextStateStrings.length === 0) {
return {
value: undefined,
tree: undefined,
source: state,
entryExitStates: undefined,
actions,
paths: []
actions
};

@@ -653,3 +644,2 @@ }

const nextStatePaths = nextStateNodes.map(stateNode => stateNode.path);
const isInternal = !!(selectedTransition as TransitionDefinition<

@@ -669,21 +659,19 @@ TContext,

const value = this.machine.resolve(
pathsToStateValue(
flatten(
nextStateStrings.map(str =>
this.getRelativeStateNodes(str, state.historyValue).map(s => s.path)
)
)
)
);
const trees = nextStateNodes.map(stateNode => stateNode.tree);
const combinedTree = trees.reduce((acc, t) => {
return acc.combine(t);
});
return {
value,
tree: value ? this.machine.getStateTree(value) : undefined,
tree: combinedTree,
source: state,
entryExitStates,
actions,
paths: nextStatePaths
actions
};
}
private get tree(): StateTree {
const stateValue = toStateValue(this.path, this.delimiter);
return new StateTree(this.machine, stateValue);
}
private nodesFromChild(

@@ -768,3 +756,3 @@ childStateNode: StateNode<TContext>

const entryExitStates = transition.tree
? transition.tree.getEntryExitStates(
? transition.tree.resolved.getEntryExitStates(
this.getStateTree(prevState.value),

@@ -924,11 +912,12 @@ transition.entryExitStates

// if (stateTransition.tree) {
// const ees = stateTransition.tree.getEntryExitStates(
// this.getStateNodeValueTree(currentState.value)
// );
// console.log('entry', [...ees.entry].map(s => s.id));
// console.log('exit', [...ees.exit].map(s => s.id));
// }
const resolvedStateTransition: StateTransition<TContext> = {
...stateTransition,
tree: stateTransition.tree ? stateTransition.tree.resolved : undefined
};
return this.resolveTransition(stateTransition, currentState, eventObject);
return this.resolveTransition(
resolvedStateTransition,
currentState,
eventObject
);
}

@@ -941,2 +930,5 @@ private resolveTransition(

): State<TContext, TEvents> {
const resolvedStateValue = stateTransition.tree
? stateTransition.tree.stateValue
: undefined;
const historyValue = currentState.historyValue

@@ -948,5 +940,5 @@ ? currentState.historyValue

if (!IS_PRODUCTION) {
if (!IS_PRODUCTION && stateTransition.tree) {
try {
this.ensureValidPaths(stateTransition.paths);
this.ensureValidPaths(stateTransition.tree.paths); // TODO: ensure code coverage for this
} catch (e) {

@@ -962,3 +954,3 @@ throw new Error(

const actions = this.getActions(stateTransition, currentState, isInitial);
const ees = stateTransition.tree
const entryExitStates = stateTransition.tree
? stateTransition.tree.getEntryExitStates(

@@ -971,4 +963,4 @@ this.getStateTree(currentState.value)

{
entry: new Set(ees.entry),
exit: new Set(ees.exit)
entry: new Set(entryExitStates.entry),
exit: new Set(entryExitStates.exit)
},

@@ -1022,4 +1014,4 @@ currentState.activities

const stateNodes = stateTransition.value
? this.getStateNodes(stateTransition.value)
const stateNodes = resolvedStateValue
? this.getStateNodes(resolvedStateValue)
: [];

@@ -1039,8 +1031,8 @@

const nextState = stateTransition.value
const nextState = resolvedStateValue
? new State<TContext, TEvents>(
stateTransition.value,
resolvedStateValue,
updatedContext,
historyValue
? StateNode.updateHistoryValue(historyValue, stateTransition.value)
? StateNode.updateHistoryValue(historyValue, resolvedStateValue)
: undefined,

@@ -1170,9 +1162,17 @@ stateTransition.source ? currentState : undefined,

}
private resolve(stateValue: StateValue): StateValue {
public resolve(stateValue: StateValue): StateValue {
if (typeof stateValue === 'string') {
const subStateNode = this.getStateNode(stateValue);
return subStateNode.initial
? { [stateValue]: subStateNode.initialStateValue! }
: stateValue;
if (
subStateNode.type === 'parallel' ||
subStateNode.type === 'compound'
) {
return { [stateValue]: subStateNode.initialStateValue! };
}
return stateValue;
}
if (!Object.keys(stateValue).length) {
return this.initialStateValue || {};
}

@@ -1320,13 +1320,2 @@ if (this.type === 'parallel') {

return initialNextState;
// return raisedEvents.reduce((nextState, raisedEvent) => {
// const currentActions = nextState.actions;
// nextState = this.transition(
// nextState,
// raisedEvent.type === actionTypes.null ? NULL_EVENT : raisedEvent.event,
// nextState.context
// );
// nextState.actions.unshift(...currentActions);
// return nextState;
// }, initialNextState);
}

@@ -1345,3 +1334,2 @@ public get initialState(): State<TContext, TEvents> {

{
value: initialStateValue,
tree: this.getStateTree(initialStateValue),

@@ -1353,4 +1341,3 @@ source: undefined,

},
actions: [],
paths: []
actions: []
},

@@ -1357,0 +1344,0 @@ state,

import { StateNode } from './StateNode';
import { StateValue, EntryExitStateArrays } from './types';
import { mapValues, flatten } from './utils';
import { mapValues, flatten, toStatePaths } from './utils';
import { matchesState } from './matchesState';
export class StateTree {
public stateNode: StateNode;
public parent?: StateTree | undefined;
public done: boolean;
public value: Record<string, StateTree> | undefined;
public value: Record<string, StateTree>;
constructor(stateNode: StateNode, stateValue: StateValue | undefined) {
this.stateNode = stateNode;
constructor(
public stateNode: StateNode,
public _stateValue: StateValue | undefined
) {
this.value = _stateValue
? typeof _stateValue === 'string'
? {
[_stateValue]: new StateTree(
stateNode.getStateNode(_stateValue),
undefined
)
}
: mapValues(_stateValue, (subValue, key) => {
return new StateTree(stateNode.getStateNode(key), subValue);
})
: {};
}
if (!stateValue) {
this.done = stateNode.type === 'final';
this.value = undefined;
} else if (typeof stateValue === 'string') {
const childStateNode = stateNode.getStateNode(stateValue);
this.done = childStateNode.type === 'final';
this.value = {
[stateValue]: new StateTree(
childStateNode,
childStateNode.type === 'compound' ||
childStateNode.type === 'parallel'
? childStateNode.initialState.value
: undefined
)
};
} else {
const value = mapValues(stateValue, (subValue, key) => {
return new StateTree(stateNode.getStateNode(key), subValue);
public get done(): boolean {
switch (this.stateNode.type) {
case 'final':
return true;
case 'compound':
return this.value[Object.keys(this.value)[0]].done;
case 'parallel':
return Object.keys(this.value).some(key => this.value[key].done);
default:
return false;
}
}
public get resolved(): StateTree {
return new StateTree(
this.stateNode,
this.stateNode.resolve(this.stateValue)
);
}
public get paths(): string[][] {
return toStatePaths(this.stateValue);
}
public get absolute(): StateTree {
const { _stateValue } = this;
const absoluteStateValue = {};
let marker: any = absoluteStateValue;
this.stateNode.path.forEach((key, i) => {
if (i === this.stateNode.path.length - 1) {
marker[key] = _stateValue;
} else {
marker[key] = {};
marker = marker[key];
}
});
return new StateTree(this.stateNode.machine, absoluteStateValue);
}
public clone(): StateTree {
return new StateTree(this.stateNode, this.stateValue);
}
public combine(tree: StateTree): StateTree {
if (tree.stateNode !== this.stateNode) {
throw new Error('Cannot combine distinct trees');
}
if (this.stateNode.type === 'compound') {
// Only combine if no child state is defined
let newValue: Record<string, StateTree>;
if (!Object.keys(this.value).length || !Object.keys(tree.value).length) {
newValue = Object.assign({}, this.value, tree.value);
const newTree = this.clone();
newTree.value = newValue;
return newTree;
} else {
const childKey = Object.keys(this.value)[0];
newValue = {
[childKey]: this.value[childKey].combine(tree.value[childKey])
};
const newTree = this.clone();
newTree.value = newValue;
return newTree;
}
}
if (this.stateNode.type === 'parallel') {
const keys = new Set([
...Object.keys(this.value),
...Object.keys(tree.value)
]);
const newValue: Record<string, StateTree> = {};
keys.forEach(key => {
if (!this.value[key] || !tree.value[key]) {
newValue[key] = this.value[key] || tree.value[key];
} else {
newValue[key] = this.value[key]!.combine(tree.value[key]!);
}
});
this.value = value;
this.done = Object.keys(value).every(key => value[key].done);
const newTree = this.clone();
newTree.value = newValue;
return newTree;
}
// nothing to do
return this;
}

@@ -46,3 +132,3 @@

if (this.stateNode.type === 'parallel') {
return mapValues(this.value!, st => {
return mapValues(this.value, st => {
return st.stateValue;

@@ -53,8 +139,11 @@ });

if (this.stateNode.type === 'compound') {
const childStateNode = this.value![Object.keys(this.value!)[0]].stateNode;
if (childStateNode.type === 'atomic') {
if (Object.keys(this.value).length === 0) {
return {};
}
const childStateNode = this.value[Object.keys(this.value)[0]].stateNode;
if (childStateNode.type === 'atomic' || childStateNode.type === 'final') {
return childStateNode.key;
}
return mapValues(this.value!, st => {
return mapValues(this.value, st => {
return st.stateValue;

@@ -84,10 +173,11 @@ });

if (Object.keys(this.value!)[0]! !== Object.keys(prevTree.value!)[0]!) {
r1.exit = prevTree.value![
Object.keys(prevTree.value!)[0]!
].getExitStates();
r1.entry = this.value![Object.keys(this.value!)[0]!].getEntryStates();
const currentChildKey = Object.keys(this.value)[0];
const prevChildKey = Object.keys(prevTree.value)[0];
if (currentChildKey !== prevChildKey) {
r1.exit = prevTree.value[prevChildKey!].getExitStates();
r1.entry = this.value[currentChildKey!].getEntryStates();
} else {
r1 = this.value![Object.keys(this.value!)[0]!].getEntryExitStates(
prevTree.value![Object.keys(prevTree.value!)[0]!],
r1 = this.value[currentChildKey!].getEntryExitStates(
prevTree.value[prevChildKey!],
externalNodes

@@ -104,5 +194,5 @@ );

case 'parallel':
const all = Object.keys(this.value!).map(key => {
return this.value![key].getEntryExitStates(
prevTree.value![key],
const all = Object.keys(this.value).map(key => {
return this.value[key].getEntryExitStates(
prevTree.value[key],
externalNodes

@@ -152,3 +242,3 @@ );

Object.keys(this.value).map(key => {
return this.value![key].getEntryStates();
return this.value[key].getEntryStates();
})

@@ -166,3 +256,3 @@ )

Object.keys(this.value).map(key => {
return this.value![key].getExitStates();
return this.value[key].getExitStates();
})

@@ -169,0 +259,0 @@ ).concat(this.stateNode);

@@ -330,3 +330,2 @@ import { StateNode } from './StateNode';

export interface StateTransition<TContext> {
value: StateValue | undefined;
tree: StateTree | undefined;

@@ -336,3 +335,2 @@ source: State<TContext> | undefined;

actions: Array<Action<TContext>>;
paths: string[][];
}

@@ -339,0 +337,0 @@

@@ -47,3 +47,3 @@ import { State } from './State';

export function toStateValue(
stateValue: State<any> | StateValue,
stateValue: State<any> | StateValue | string[],
delimiter: string

@@ -55,2 +55,6 @@ ): StateValue {

if (Array.isArray(stateValue)) {
return pathToStateValue(stateValue);
}
if (typeof stateValue === 'object' && !(stateValue instanceof State)) {

@@ -158,3 +162,9 @@ return stateValue;

export const toStatePaths = (stateValue: StateValue): string[][] => {
export const toStatePaths = (
stateValue: StateValue | undefined
): string[][] => {
if (!stateValue) {
return [[]];
}
if (typeof stateValue === 'string') {

@@ -161,0 +171,0 @@ return [[stateValue]];

@@ -83,16 +83,30 @@ import { StateTree } from '../src/StateTree';

describe('StateTree', () => {
it('represents the full value (compound)', () => {
const st = new StateTree(testMachine, 'a');
describe('.resolved', () => {
it('represents the full value (compound)', () => {
const st = new StateTree(testMachine, 'a').resolved;
assert.deepEqual(st.stateValue, { a: 'one' });
assert.deepEqual(st.stateValue, { a: 'one' });
});
it('represents the full value (parallel)', () => {
const st = new StateTree(testMachine, 'b').resolved;
assert.deepEqual(st.stateValue, {
b: {
one: 'foo',
two: { foo: 'x' }
}
});
});
});
it('represents the full value (parallel)', () => {
const st = new StateTree(testMachine, 'b');
describe('.combine', () => {
it('combines two state trees (compound)', () => {
const st_c = new StateTree(testMachine, 'c');
const st_c_two = new StateTree(testMachine, { c: 'two' });
assert.deepEqual(st.stateValue, {
b: {
one: 'foo',
two: { foo: 'x' }
}
const combined = st_c.combine(st_c_two);
assert.deepEqual(combined.stateValue, { c: { two: {} } });
assert.deepEqual(combined.resolved.stateValue, { c: { two: 'aa' } });
});

@@ -113,4 +127,4 @@ });

it('getEntryExitStates() should show correct entry/exit state nodes', () => {
const st_A = new StateTree(testMachine, 'c'); // { c: { one: 'aa' }}
const st_B = new StateTree(testMachine, { c: { one: 'bb' } });
const st_A = new StateTree(testMachine, 'c').resolved; // { c: { one: 'aa' }}
const st_B = new StateTree(testMachine, { c: { one: 'bb' } }).resolved;

@@ -117,0 +131,0 @@ const res = st_B.getEntryExitStates(st_A);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc