All files / xstate/dist xstate.graph.js

0% Statements 0/812
0% Branches 0/772
0% Functions 0/239
0% Lines 0/1

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2   
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.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,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}var a=".",s={};function u(t){return"string"!=typeof t&&("value"in t&&"tree"in t&&"history"in t)}function c(t){return Object.keys(t)}function f(t,e,r){void 0===r&&(r=a);var n=d(t,r),i=d(e,r);return"string"==typeof i?"string"==typeof n&&i===n:"string"==typeof n?n in i:c(n).every(function(t){return t in i&&f(n[t],i[t])})}function h(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 l(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 p(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 d(t,e){return u(t)?t.value:Array.isArray(t)?y(t):"string"==typeof t||u(t)?y(p(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 c(t).forEach(function(n,i){r[n]=e(t[n],n,t,i)}),r}function g(t,e,r){var n={};return c(t).forEach(function(i){var o=t[i];r(o)&&(n[i]=e(o,i,t))}),n}var m=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}};var S,b,x=function(t){return t?"string"==typeof t?[[t]]:N(c(t).map(function(e){return x(t[e]).map(function(t){return[e].concat(t)})})):[[]]};function N(t){var e;return(e=[]).concat.apply(e,o(t))}function w(t){return Array.isArray(t)?t:void 0===t?[]:[t]}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.Null="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke"}(S||(S={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(b||(b={}));var E=function(){function t(t,e,r,n,i,o,a,u,c){void 0===i&&(i=[]),void 0===o&&(o=s),void 0===a&&(a={}),void 0===u&&(u=[]),this.value=t,this.context=e,this.historyValue=r,this.history=n,this.actions=i,this.activities=o,this.data=a,this.events=u,Object.defineProperty(this,"tree",{value:c,enumerable:!1})}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.tree):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,void 0,e.activities,void 0,void 0,e.tree):e:t.from(e,r)},Object.defineProperty(t.prototype,"nextEvents",{get:function(){return this.tree?this.tree.nextEvents:[]},enumerable:!0,configurable:!0}),t.prototype.toStrings=function(t,e){var r=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),"string"==typeof t)return[t];var n=c(t);return n.concat.apply(n,o(n.map(function(n){return r.toStrings(t[n]).map(function(t){return n+e+t})})))},t.prototype.matches=function(t){return f(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=c(e),i=c(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}(),O=(S.Start,S.Stop,S.Raise),P=S.Send,j=S.Cancel,A=S.Null,V=S.Assign;S.After,S.DoneState,S.Log,S.Init,S.Invoke;function _(t){return"string"==typeof t||"number"==typeof t?{type:t}:t}function k(t,e){if(e){var r=e[t];if(r)return"function"==typeof r?r:r.exec}}var C=function(t,r){var n;if("string"==typeof t||"number"==typeof t)n={type:t,exec:k(t,r)};else{if("function"!=typeof t){var i=k(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 I(t){var r=C(t);return e({id:"string"==typeof t?t:r.id},r,{type:r.type})}function J(t){return{type:O,event:t}}function R(t){var e=I(t);return{type:S.Start,activity:e,exec:void 0}}function T(t,e){var r=e?"#"+e:"";return S.After+"("+t+")"+r}function M(t){return S.DoneState+"."+t}var D={resolved:!1},F=function(){function t(r,n,i){var o;void 0===i&&(i=D),this.stateNode=r,this._stateValue=n,this.nodes=n?"string"==typeof n?((o={})[n]=new t(r.getStateNode(n),void 0),o):v(n,function(e,n){return new t(r.getStateNode(n),e)}):{};var a=e({},D,i);this.isResolved=a.resolved}return Object.defineProperty(t.prototype,"done",{get:function(){var t=this;switch(this.stateNode.type){case"final":return!0;case"compound":return"final"===this.nodes[c(this.nodes)[0]].stateNode.type;case"parallel":return c(this.nodes).some(function(e){return t.nodes[e].done});default:return!1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"atomicNodes",{get:function(){var t=this;return"atomic"===this.stateNode.type||"final"===this.stateNode.type?[this.stateNode]:N(c(this.value).map(function(e){return t.value[e].atomicNodes}))},enumerable:!0,configurable:!0}),t.prototype.getDoneEvents=function(t){var e=this;if(!t||!t.size)return[];if(t.has(this.stateNode)&&"final"===this.stateNode.type)return[M(this.stateNode.id)];var r=N(c(this.nodes).map(function(r){return e.nodes[r].getDoneEvents(t)}));if("parallel"===this.stateNode.type){var n=c(this.nodes).every(function(t){return e.nodes[t].done});return r&&n?[M(this.stateNode.id)].concat(r):r}return this.done&&r.length?[M(this.stateNode.id)].concat(r):r},Object.defineProperty(t.prototype,"resolved",{get:function(){return new t(this.stateNode,this.stateNode.resolve(this.value),{resolved:!0})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paths",{get:function(){return x(this.value)},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}),Object.defineProperty(t.prototype,"nextEvents",{get:function(){var t=this,e=this.stateNode.ownEvents,r=N(c(this.nodes).map(function(e){return t.nodes[e].nextEvents}));return o(new Set(r.concat(e)))},enumerable:!0,configurable:!0}),t.prototype.clone=function(){return new t(this.stateNode,this.value)},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(c(this.nodes).length&&c(t.nodes).length){var i=c(this.nodes)[0];return(e={})[i]=this.nodes[i].combine(t.nodes[i]),n=e,(a=this.clone()).nodes=n,a}return n=Object.assign({},this.nodes,t.nodes),(a=this.clone()).nodes=n,a}if("parallel"===this.stateNode.type){var a,s=new Set(o(c(this.nodes),c(t.nodes))),u={};return s.forEach(function(e){r.nodes[e]&&t.nodes[e]?u[e]=r.nodes[e].combine(t.nodes[e]):u[e]=r.nodes[e]||t.nodes[e]}),(a=this.clone()).nodes=u,a}return this},Object.defineProperty(t.prototype,"value",{get:function(){if("atomic"===this.stateNode.type||"final"===this.stateNode.type)return{};if("parallel"===this.stateNode.type)return v(this.nodes,function(t){return t.value});if("compound"===this.stateNode.type){if(0===c(this.nodes).length)return{};var t=this.nodes[c(this.nodes)[0]].stateNode;return"atomic"===t.type||"final"===t.type?t.key:v(this.nodes,function(t){return t.value})}return{}},enumerable:!0,configurable:!0}),t.prototype.matches=function(t){return f(t,this.value)},t.prototype.getEntryExitStates=function(t,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=c(this.nodes)[0],a=c(t.nodes)[0];return i!==a?(n.exit=t.nodes[a].getExitStates(),n.entry=this.nodes[i].getEntryStates()):n=this.nodes[i].getEntryExitStates(t.nodes[a],e),e&&e.has(this.stateNode)&&(n.exit.push(this.stateNode),n.entry.unshift(this.stateNode)),n;case"parallel":var s=c(this.nodes).map(function(n){return r.nodes[n].getEntryExitStates(t.nodes[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.nodes?[this.stateNode].concat(N(c(this.nodes).map(function(e){return t.nodes[e].getEntryStates()}))):[this.stateNode]},t.prototype.getExitStates=function(){var t=this;return this.nodes?N(c(this.nodes).map(function(e){return t.nodes[e].getExitStates()})).concat(this.stateNode):[this.stateNode]},t}(),B=".",H="",L={},z=function(t){return"#"===t[0]},G=function(){return{guards:L}},U=(function(){function t(r,n,i){void 0===n&&(n=G());var a=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&&c(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:B),this.id=r.id||(this.machine?o([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,o){var s,u=new t(e({},r,{key:n,order:void 0===r.order?r.order:o,parent:a}));return Object.assign(a.idMap,e(((s={})[u.id]=u,s),u.idMap)),u}):L,this.history=!0===r.history?"shallow":r.history||!1,this.transient=!(!r.on||!r.on[H]),this.strict=!!r.strict,this.onEntry=w(r.onEntry),this.onExit=w(r.onExit),this.data=r.data,this.activities=w(r.activities).map(function(t){return a.resolveActivity(t)})}t.prototype.withConfig=function(r,n){return new t(this.definition,{actions:e({},this.options.actions,r.actions),activities:e({},this.options.activities,r.activities),guards:e({},this.options.guards,r.guards)},n)},Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,history:this.history,states:v(this.states,function(t){return t.definition}),on:this.on,onEntry:this.onEntry,onExit:this.onExit,after:this.after,activities:this.activities||[],data:this.data,order:this.order||-1}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"config",{get:function(){var t=this._config;t.parent;return 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[];if(Array.isArray(r))return r.map(function(r){return e({event:T(r.delay,t.id)},r,{actions:w(r.actions)})});var n=N(c(r).map(function(n){var i=r[n],o=+n,a=T(o,t.id);return"string"==typeof i?[{target:i,delay:o,event:a,actions:[]}]:w(i).map(function(t){return e({event:a,delay:o},t,{actions:w(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 E?t.value:d(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=c(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=h(t);return-1!==this.events.indexOf(e)},t.prototype.transitionLeafNode=function(t,e,r,n){var i=this.getStateNode(t).next(e,r,n);if(!i.tree){var o=this.next(e,r,n),a=o.reentryStates,s=o.actions;return{tree:o.tree,source:e,reentryStates:a,actions:s}}return i},t.prototype.transitionCompoundNode=function(t,e,r,n){var i=c(t),o=this.getStateNode(i[0])._transition(t[i[0]],e,r,n);if(!o.tree){var a=this.next(e,r,n),s=a.reentryStates,u=a.actions;return{tree:a.tree,source:e,reentryStates:s,actions:u}}return o},t.prototype.transitionParallelNode=function(t,e,r,n){var i=this,a={};if(c(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}}),!c(a).some(function(t){return void 0!==a[t].tree})){var s=this.next(e,r,n),u=s.reentryStates,h=s.actions;return{tree:s.tree,source:e,reentryStates:u,actions:h}}var l=c(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!==l.paths.length||f(d(this.path,this.delimiter),l.value)?{tree:c(a).map(function(t){var r=a[t],n=m(i.path)(r.tree?r.tree.value:e.value||e.value)[t];return new F(i.getStateNode(t),n).absolute}).reduce(function(t,e){return t.combine(e)}),source:e,reentryStates:c(a).reduce(function(t,e){var r=a[e],n=r.tree,i=r.reentryStates;return n&&i?new Set(o(Array.from(t),Array.from(i))):t},new Set),actions:N(c(a).map(function(t){return a[t].actions}))}:{tree:l,source:e,reentryStates:c(a).map(function(t){return a[t].reentryStates}).reduce(function(t,e){return new Set(o(Array.from(t||[]),Array.from(e||[])))},new Set),actions:N(c(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===c(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,c=this.on[u],h=this.transient?[{type:A}]:[];if(!c||!c.length)return{tree:void 0,source:t,reentryStates:void 0,actions:h};var l,p=[];try{for(var y=n(c),v=y.next();!v.done;v=y.next()){var g=v.value,S=g,b=S.cond,x=S.in,E=r||L,O=!x||f(d(x,this.delimiter),m(this.path.slice(0,-2))(t.value));if((!b||this.evaluateGuard(b,E,e,t.value))&&O){p=w(g.target),h.push.apply(h,o(w(g.actions))),l=g;break}}}catch(t){i={error:t}}finally{try{v&&!v.done&&(a=y.return)&&a.call(y)}finally{if(i)throw i.error}}if(l&&0===p.length)return{tree:t.value?this.machine.getStateTree(t.value):void 0,source:t,reentryStates:void 0,actions:h};if(!l&&0===p.length)return{tree:void 0,source:t,reentryStates:void 0,actions:h};var P=N(p.map(function(e){return s.getRelativeStateNodes(e,t.historyValue)})),j=!!l.internal?[]:N(P.map(function(t){return s.nodesFromChild(t)}));return{tree:P.map(function(t){return t.tree}).reduce(function(t,e){return t.combine(e)}),source:t,reentryStates:new Set(j),actions:h}},Object.defineProperty(t.prototype,"tree",{get:function(){var t=d(this.path,this.delimiter);return new F(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 F(this,t)},t.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},t.prototype.evaluateGuard=function(t,e,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,e){var r=this,n=t.tree?t.tree.resolved.getEntryExitStates(this.getStateTree(e.value),t.reentryStates?t.reentryStates:void 0):{entry:[],exit:[]},i=t.tree?t.tree.getDoneEvents(new Set(n.entry)):[];t.source||(n.exit=[]);var a={entry:N(Array.from(new Set(n.entry)).map(function(t){return o(t.onEntry,t.activities.map(function(t){return R(t)}),t.delays.map(function(t){var e,r,n=t.delay,i=t.id;return e=T(n,i),{target:(r={delay:n})?r.target:void 0,type:P,event:_(e),delay:r?r.delay:void 0,id:r&&void 0!==r.id?r.id:h(e)}}))})).concat(i.map(J)),exit:N(Array.from(new Set(n.exit)).map(function(t){return o(t.onExit,t.activities.map(function(t){return function(t){var e=I(t);return{type:S.Stop,activity:e,exec:void 0}}(t)}),t.delays.map(function(t){var e,r=t.delay,n=t.id;return e=T(r,n),{type:j,sendId:e}}))}))};return a.exit.concat(t.actions).concat(a.entry).map(function(t){return"string"==typeof t?r.resolveAction(t):t})},t.prototype.resolveAction=function(t){var e=this.machine.options.actions;return(e?e[t]:t)||t},t.prototype.resolveActivity=function(t){return I(t)},t.prototype.getActivities=function(t,r){if(!t)return L;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 E?t:this.resolve(t),o=n||(t instanceof E?t.context:void 0),a=_(r),s=a.type;if(this.strict&&-1===this.events.indexOf(s))throw new Error("Machine '"+this.id+"' does not accept event '"+s+"'");var u=E.from(i,o),c=this._transition(u.value,u,a,o),f=e({},c,{tree:c.tree?c.tree.resolved:void 0});return this.resolveTransition(f,u,a)},t.prototype.resolveTransition=function(e,r,n){var i,a=e.tree?e.tree.value:void 0,s=r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0,u=this.getActions(e,r),c=e.tree?e.tree.getEntryExitStates(this.getStateTree(r.value)):{entry:[],exit:[]},f=e.tree?this.getActivities({entry:new Set(c.entry),exit:new Set(c.exit)},r.activities):{},h=u.filter(function(t){return"object"==typeof t&&(t.type===O||t.type===A)}),l=u.filter(function(t){return"object"!=typeof t||t.type!==O&&t.type!==A&&t.type!==V}),p=u.filter(function(t){return"object"==typeof t&&t.type===V}),d=t.updateContext(r.context,n,p),y=a?this.getStateNodes(a):[];y.some(function(t){return t.transient})&&h.push({type:A});var v,g,m=o([this],y).reduce(function(t,e){return void 0!==e.data&&(t[e.id]=e.data),t},{}),S=a?new E(a,d,s?t.updateHistoryValue(s,a):void 0,e.source?r:void 0,(v=l,g=this.options.actions,v?(Array.isArray(v)?v:[v]).map(function(t){return C(t,g)}):[]),f,m,h,e.tree):void 0;if(!S)return E.inert(r,d);r.history&&delete r.history.history;for(var b=S;h.length;){var x=b.actions,N=h.shift();(i=(b=this.transition(b,N.type===A?H:N.event,b.context)).actions).unshift.apply(i,o(x))}return b},t.updateContext=function(t,e,r){return t?r.reduce(function(t,r){var n=r.assignment,i={};return"function"==typeof n?i=n(t,e||{type:S.Init}):c(n).forEach(function(r){var o=n[r];i[r]="function"==typeof o?o(t,e):o}),Object.assign({},t,i)},t):t},t.prototype.ensureValidPaths=function(t){var e,r,i=this,o=new Map,a=N(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,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&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}},t.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},t.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},t.prototype.getStateNodeByPath=function(t){for(var e=p(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 c(t).length?"parallel"===this.type?v(this.initialStateValue,function(e,n){return e?r.getStateNode(n).resolve(t[n]||e):L}):v(t,function(t,e){return t?r.getStateNode(e).resolve(t):L}):this.initialStateValue||{}},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,r=this.key;return"parallel"===this.type?((t={})[r]=g(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(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 p(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t="parallel"===this.type?g(this.states,function(t){return t.initialStateValue||L},function(t){return!t.history}):"string"==typeof this.resolvedStateValue?void 0:this.resolvedStateValue[this.key];return this.__cache.initialState=t,this.__cache.initialState},enumerable:!0,configurable:!0}),t.prototype.getInitialState=function(e,r){void 0===r&&(r=this.machine.context);var n={},i=[];this.getStateNodes(e).forEach(function(t){t.onEntry&&i.push.apply(i,o(t.onEntry)),t.activities&&t.activities.forEach(function(t){n[h(t)]=!0,i.push(R(t))})});var a=i.filter(function(t){return"object"==typeof t&&t.type===V}),s=t.updateContext(r,void 0,a);return new E(e,s,void 0,void 0,void 0,n,void 0,[])},Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");var e=this.getInitialState(t);return this.resolveTransition({tree:this.getStateTree(t),source:void 0,reentryStates:new Set(this.getStateNodes(t)),actions:[]},e,void 0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var t;if(this.history){var e=this.config;t=e.target&&"string"==typeof e.target&&z(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 c(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&&z(t)){var n=this.getStateNodeById(t);return r?n.history?n.resolveHistory(e):n.initialStateNodes:[n]}var i=p(t,this.delimiter),o=(this.parent||this).getFromRelativePath(i,e);return r?N(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 N(x(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 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(c(this.states).length)return{current:t||this.initialStateValue,states:g(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?N(x(this.target).map(function(t){return r.getFromRelativePath(t)})):this.parent.initialStateNodes;var i,o,a=(i=r.path,o="states",function(t){var e,r,a=t;try{for(var s=n(i),u=s.next();!u.done;u=s.next()){var c=u.value;a=a[o][c]}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}return a})(t).current;return"string"==typeof a?[r.getStateNode(a)]:N(x(a).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=N(c(this.states).map(function(e){return t.states[e].stateIds}));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){if(this.__cache.events)return this.__cache.events;var t=this.states,e=new Set(this.ownEvents);return t&&c(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}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var t=this,e=new Set(c(this.on).filter(function(e){return t.on[e].some(function(t){return!(!t.target&&!t.actions.length&&t.internal)})}));return Array.from(e)},enumerable:!0,configurable:!0}),t.prototype.formatTransition=function(t,r,n){var i=this,o=!!r&&r.internal;if(void 0===t||""===t)return e({},r,{actions:r?w(r.actions):[],target:void 0,internal:!r||(void 0===r.internal||r.internal),event:n});var a=w(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?w(r.actions):[],target:a,internal:o,event:n})},t.prototype.formatTransitions=function(){var t,r=this,n=this.config.on||L,i=this.config.onDone?((t={})[M(this.id)]=this.config.onDone,t):void 0,o=this.after,a=v(e({},n,i),function(t,e){return void 0===t?[{target:void 0,event:e,actions:[],internal:!0}]:Array.isArray(t)?t.map(function(t){return r.formatTransition(t.target,t,e)}):"string"==typeof t?[r.formatTransition([t],void 0,e)]:[r.formatTransition(t.target,t,e)]});return o.forEach(function(t){a[t.event]=a[t.event]||[],a[t.event].push(t)}),a}}(),{});function q(t,e){return N(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(l):[],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(l):[],cond:r.cond,transition:r}]}))}function K(t,e){var r={},i=t.events;return function o(a){var s,u,c=JSON.stringify(a);if(!r[c]){r[c]={};try{for(var f=n(i),h=f.next();!h.done;h=f.next()){var l=h.value,p=t.transition(a,l,e);r[c][l]={state:p.value},o(p.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 W(t){var e=t.value,r=t.context;return JSON.stringify(e)+" | "+JSON.stringify(r)}function X(t,e){var r=e.events,i=e.filter,o={},a=N(t.events.map(function(t){return r[t]||[t]}));return function e(r){var s,u,c=W(r);if(!o[c]){o[c]={};try{for(var f=n(a),h=f.next();!h.done;h=f.next()){var l=h.value,p=t.transition(r,l);i&&!i(p)||(o[c][Q(l)]={value:p.value,context:p.context},e(p))}}catch(t){s={error:t}}finally{try{h&&!h.done&&(u=f.return)&&u.call(f)}finally{if(s)throw s.error}}}}(t.initialState),o}function Y(t,e){var r;if(!t.states)return U;var i=K(t,e),a=((r={})[JSON.stringify(t.initialState.value)]=[],r),s=new Set;return function e(r){var u,f,h,l,p=JSON.stringify(r);s.add(p);var y=i[p];try{for(var v=n(c(y)),g=v.next();!g.done;g=v.next()){var m=g.value;if(N=y[m].state){var S=JSON.stringify(d(N,t.delimiter));(!a[S]||a[S].length>a[p].length+1)&&(a[S]=o(a[p]||[],[{state:r,event:m}]))}}}catch(t){u={error:t}}finally{try{g&&!g.done&&(f=v.return)&&f.call(v)}finally{if(u)throw u.error}}try{for(var b=n(c(y)),x=b.next();!x.done;x=b.next()){var N;(N=y[x.value].state)&&(S=JSON.stringify(N),s.has(S)||e(N))}}catch(t){h={error:t}}finally{try{x&&!x.done&&(l=b.return)&&l.call(b)}finally{if(h)throw h.error}}return a}(t.initialState.value),a}function Z(t,e){if(!t.states)return U;var r=K(t,e),i=new Set,a=[],s={};var u=JSON.stringify(t.initialState.value);return c(r).forEach(function(t){!function t(e,u){var f,h;if(i.add(e),e===u)s[u]=s[u]||[],s[u].push(o(a));else try{for(var l=n(c(r[e])),p=l.next();!p.done;p=l.next()){var d=p.value,y=r[e][d].state;if(y){var v=JSON.stringify(y);i.has(v)||(a.push({state:JSON.parse(e),event:d}),t(v,u))}}}catch(t){f={error:t}}finally{try{p&&!p.done&&(h=l.return)&&h.call(l)}finally{if(f)throw f.error}}a.pop(),i.delete(e)}(u,t)}),s}t.getNodes=function t(e){var r=e.states;return c(r).reduce(function(e,n){var i=r[n],a=t(r[n]);return e.push.apply(e,o([i],a)),e},[])},t.getEventEdges=q,t.getEdges=function t(e,r){var n=(r||{}).depth,i=void 0===n?null:n,a=[];return e.states&&null===i?c(e.states).forEach(function(r){a.push.apply(a,o(t(e.states[r])))}):i&&i>0&&c(e.states).forEach(function(r){a.push.apply(a,o(t(e.states[r],{depth:i-1})))}),c(e.on).forEach(function(t){a.push.apply(a,o(q(e,t)))}),a},t.getAdjacencyMap=K,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.serializeState=W,t.getValueAdjacencyMap=X,t.getShortestValuePaths=function(t,e){if(!t.states)return U;var r=X(t,e),i={},a=new Set;return function t(e){var s,u,f,h,l=W(e);a.add(l);var p=r[l];try{for(var d=n(c(p)),y=d.next();!y.done;y=d.next()){var v=y.value,g=p[v],m=g.value,S=g.context;if(m){var b=W(P=E.from(m,S));(!i[b]||i[b].length>i[l].length+1)&&(i[b]=o(i[l]||[],[{state:m,event:v}]))}}}catch(t){s={error:t}}finally{try{y&&!y.done&&(u=d.return)&&u.call(d)}finally{if(s)throw s.error}}try{for(var x=n(c(p)),N=x.next();!N.done;N=x.next()){var w=p[N.value],O=(m=w.value,w.context);if(m){var P=E.from(m,O);b=W(E.from(m,O)),a.has(b)||t(P)}}}catch(t){f={error:t}}finally{try{N&&!N.done&&(h=x.return)&&h.call(x)}finally{if(f)throw f.error}}return i}(t.initialState),i},t.getShortestPaths=Y,t.getShortestPathsAsArray=function(t,e){var r=Y(t,e);return c(r).map(function(t){return{state:JSON.parse(t),path:r[t]}})},t.getSimplePaths=Z,t.getSimplePathsAsArray=function(t,e){var r=Z(t,e);return c(r).map(function(t){return{state:JSON.parse(t),paths:r[t]}})},Object.defineProperty(t,"__esModule",{value:!0})});