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.xstateUtils={})}(this,function(t){"use strict";var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}var r,i=".",a={};function o(t,e,n){void 0===n&&(n=i);var r=_(t,n),a=_(e,n);return"string"==typeof a?"string"==typeof r&&a===r:"string"==typeof r?r in a:Object.keys(r).every(function(t){return t in a&&o(r[t],a[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="xstate.null",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state"}(r||(r={}));r.Start,r.Stop;var s=r.Raise,u=r.Send,c=r.Cancel,f=r.Null,h=r.Assign,y=(r.After,r.DoneState,function(t,e){if("string"==typeof t||"number"==typeof t){var n={type:t};return void 0!==e&&(n.id=e),n}return t});function p(t,e){if(e){var n=e[t];if(n)return"function"==typeof n?n:n.exec}}var v=function(t,n){var r;if("string"==typeof t||"number"==typeof t)r={type:t,exec:p(t,n)};else{if("function"!=typeof t){var i=p(t.type,n);return i?e({},t,{exec:i}):t}r={type:t.name,exec:t}}return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1}),r};function l(t){return v(t)}var d=function(t,e){return t?(Array.isArray(t)?t:[t]).map(function(t){return v(t,e)}):[]};function g(t){var e=l(t);return{type:r.Start,activity:e.type,action:e}}function m(t,e){var n=e?"#"+e:"";return r.After+"("+t+")"+n}var S=".",b="",x={},O=[],E=function(t){return"#"===t[0]},j=function(){return{guards:x}},w=(function(){function t(n,r,i){void 0===r&&(r=j());var a=this;this._config=n,this.options=r,this.context=i,this.__cache={events:void 0,relativeValue:new Map,initialState:void 0},this.idMap={},this.key=n.key||n.id||"(machine)",this.type=n.type||(n.parallel?"parallel":n.states&&Object.keys(n.states).length?"compound":n.history?"history":"atomic"),this.parent=n.parent,this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=n.delimiter||(this.parent?this.parent.delimiter:S),this.id=n.id||(this.machine?[this.machine.key].concat(this.path).join(this.delimiter):this.key),this.initial=n.initial,this.parallel=!!n.parallel,this.order=n.order||-1,this.states=n.states?V(n.states,function(n,r,i,o){var s,u=new t(e({},n,{key:r,order:void 0===n.order?n.order:o,parent:a}));return Object.assign(a.idMap,e(((s={})[u.id]=u,s),u.idMap)),u}):x,this.history=!0===n.history?"shallow":n.history||!1,this.transient=!(!n.on||!n.on[b]),this.strict=!!n.strict,this.onEntry=n.onEntry?[].concat(n.onEntry):[],this.onExit=n.onExit?[].concat(n.onExit):[],this.data=n.data,this.activities=(n.activities||O).map(function(t){return l(t)})}Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,type:this.type,initial:this.initial,parallel:this.parallel,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||O,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 n(t,["parent"])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"on",{get:function(){return this.formatTransitions()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){var t=this,n=this.config.after;if(!n)return O;if(Array.isArray(n))return n.map(function(n){return e({event:m(n.delay,t.id)},n)});var r=C(Object.keys(n).map(function(r){var i=n[r],a=+r,o=m(a,t.id);return"string"==typeof i?[{target:i,delay:a,event:o}]:(Array.isArray(i)?i:[i]).map(function(t){return e({event:o,delay:a},t)})}));return r.sort(function(t,e){return t.delay-e.delay}),r},enumerable:!0,configurable:!0}),t.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof w?t.value:_(t,this.delimiter);if("string"==typeof r){var i=this.getStateNode(r).initial;return i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var a=Object.keys(r);return a.map(function(t){return n.getStateNode(t)}).concat(a.reduce(function(t,e){var i=n.getStateNode(e).getStateNodes(r[e]);return t.concat(i)},[]))},t.prototype.handles=function(t){var e=N(t);return-1!==this.events.indexOf(e)},t.prototype._transitionLeafNode=function(t,e,n,r){var i=this.getStateNode(t),a=i._next(e,n,r);if(!a.value){var o=this._next(e,n,r),s=o.value,u=o.entryExitStates,c=o.actions,f=o.paths;return{value:s,source:e,entryExitStates:{entry:u?u.entry:new Set,exit:new Set([i].concat(u?Array.from(u.exit):[]))},actions:c,paths:f}}return a},t.prototype._transitionHierarchicalNode=function(t,e,n,r){var i=Object.keys(t),a=this.getStateNode(i[0]),o=a._transition(t[i[0]],e,n,r);if(!o.value){var s=this._next(e,n,r),u=s.value,c=s.entryExitStates,f=s.actions,h=s.paths;return{value:u,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set((o.entryExitStates?Array.from(o.entryExitStates.exit):[]).concat([a],c?Array.from(c.exit):[]))},actions:f,paths:h}}return o},t.prototype._transitionOrthogonalNode=function(t,e,n,r){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,n,r);u.value,a[o]=u}}),!Object.keys(a).some(function(t){return void 0!==a[t].value})){var s=this._next(e,n,r),u=s.value,c=s.entryExitStates,f=s.actions,h=s.paths;return{value:u,source:e,entryExitStates:{entry:c?c.entry:new Set,exit:new Set(Object.keys(this.states).map(function(t){return i.states[t]}).concat(c?Array.from(c.exit):[]))},actions:f,paths:h}}var y=C(Object.keys(a).map(function(t){return a[t].paths}));if(1===y.length&&!o(P(this.path),P(y[0])))return{value:this.machine.resolve(T(y)),source:e,entryExitStates:Object.keys(a).map(function(t){return a[t].entryExitStates}).reduce(function(t,e){var n=e,r=n.entry,i=n.exit;return{entry:new Set(Array.from(t.entry).concat(Array.from(r))),exit:new Set(Array.from(t.exit).concat(Array.from(i)))}},{entry:new Set,exit:new Set}),actions:C(Object.keys(a).map(function(t){return a[t].actions})),paths:y};var p=C(Object.keys(a).map(function(t){var n=a[t].value||e.value;return M(J(i.path)(n)[t]).map(function(e){return i.path.concat(t,e)})})),v=this.machine.resolve(T(p));return{value:v,source:e,entryExitStates:Object.keys(a).reduce(function(t,e){var n=a[e],r=n.value,i=n.entryExitStates;if(!r||!i)return t;var o=i.entry,s=i.exit;return{entry:new Set(Array.from(t.entry).concat(Array.from(o))),exit:new Set(Array.from(t.exit).concat(Array.from(s)))}},{entry:new Set,exit:new Set}),actions:C(Object.keys(a).map(function(t){return a[t].actions})),paths:M(v)}},t.prototype._transition=function(t,e,n,r){return"string"==typeof t?this._transitionLeafNode(t,e,n,r):1===Object.keys(t).length?this._transitionHierarchicalNode(t,e,n,r):this._transitionOrthogonalNode(t,e,n,r)},t.prototype._next=function(t,e,n){var r=this,i=N(e),a=this.on[i],s=this.transient?[{type:f}]:[];if(!a||!a.length)return{value:void 0,source:t,entryExitStates:void 0,actions:s,paths:[]};for(var u,c=[],h=0,p=a;h<p.length;h++){var v=p[h],l=v,d=l.cond,g=l.in,m=n||x,S=y(e),b=!g||o(_(g,this.delimiter),J(this.path.slice(0,-2))(t.value));if((!d||this._evaluateCond(d,m,S,t.value))&&b){c=Array.isArray(v.target)?v.target:v.target?[v.target]:[],s.push.apply(s,v.actions?v.actions:[]),u=v;break}}if(u&&0===c.length)return{value:t.value,source:t,entryExitStates:void 0,actions:s,paths:[]};if(!u&&0===c.length)return{value:void 0,source:t,entryExitStates:void 0,actions:s,paths:[]};var O=C(c.map(function(e){return r.getRelativeStateNodes(e,t.historyValue)})),E=O.map(function(t){return t.path}),j=O.reduce(function(t,e){var n=r._getEntryExitStates(e,!!u.internal),i=n.entry,a=n.exit;return{entry:new Set(Array.from(t.entry).concat(Array.from(i))),exit:new Set(Array.from(t.exit).concat(Array.from(a)))}},{entry:new Set,exit:new Set});return{value:this.machine.resolve(T(C(c.map(function(e){return r.getRelativeStateNodes(e,t.historyValue).map(function(t){return t.path})})))),source:t,entryExitStates:j,actions:s,paths:E}},t.prototype._getEntryExitStates=function(t,e){for(var n={entry:[],exit:[]},r=this.path,i=t.path,a=this.machine,o=0;o<Math.min(r.length,i.length);o++){var s=r[o];if(s!==i[o])break;a=a.getStateNode(s)}for(var u=a.path,c=a,f=0,h=r.slice(u.length);f<h.length;f++){var y=h[f];c=c.getStateNode(y),n.exit.unshift(c)}a===this&&(e||(n.exit.push(this),n.entry.push(this))),c=a;for(var p=0,v=i.slice(u.length);p<v.length;p++){y=v[p];c=c.getStateNode(y),n.entry.push(c)}return{entry:new Set(n.entry),exit:new Set(n.exit)}},t.prototype._evaluateCond=function(t,e,n,r){var i,a=this.machine.options.guards;if("string"==typeof t){if(!a||!a[t])throw new Error("String condition '"+t+"' is not defined on machine '"+this.machine.id+"'");i=a[t]}else i=t;return i(e,n,r)},Object.defineProperty(t.prototype,"delays",{get:function(){var t=this;return Array.from(new Set(this.after.map(function(t){return t.delay}))).map(function(e){return{id:t.id,delay:e}})},enumerable:!0,configurable:!0}),t.prototype._getActions=function(t){var e=this,n={entry:t.entryExitStates?C(Array.from(t.entryExitStates.entry).map(function(t){return t.onEntry.concat(t.activities.map(function(t){return g(t)}),t.delays.map(function(t){var e,n,r=t.delay,i=t.id;return e=m(r,i),n={delay:r},{type:u,event:y(e),delay:n?n.delay:void 0,id:n&&void 0!==n.id?n.id:N(e)}}))})):[],exit:t.entryExitStates?C(Array.from(t.entryExitStates.exit).map(function(t){return t.onExit.concat(t.activities.map(function(t){return function(t){var e=l(t);return{type:r.Stop,activity:e.type,action:e}}(t)}),t.delays.map(function(t){var e,n=t.delay,r=t.id;return e=m(n,r),{type:c,sendId:e}}))})):[]};return n.exit.concat(t.actions).concat(n.entry).map(function(t){return"string"==typeof t?e.resolveAction(t):t})},t.prototype.resolveAction=function(t){var e=this.machine.options.actions;return(e?e[t]:t)||t},t.prototype._getActivities=function(t,n){if(!t)return x;var r=e({},n);return Array.from(t.exit).forEach(function(t){t.activities&&t.activities.forEach(function(t){r[t.type]=!1})}),Array.from(t.entry).forEach(function(t){t.activities&&t.activities.forEach(function(t){r[t.type]=!0})}),r},t.prototype.transition=function(t,e,n){var r="string"==typeof t?this.resolve(P(this.getResolvedPath(t))):t instanceof w?t:this.resolve(t),i=n||(t instanceof w?t.context:void 0),a=y(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=w.from(r,i),u=this._transition(s.value,s,e,i);return this.resolveTransition(u,s,a)},t.prototype.resolveTransition=function(e,n,r){var i,a=n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0;try{this.ensureValidPaths(e.paths)}catch(t){throw new Error("Event '"+(r?r.type:"none")+"' leads to an invalid configuration: "+t.message)}var o=this._getActions(e),u=this._getActivities(e.entryExitStates,n.activities),c=o.filter(function(t){return"object"==typeof t&&(t.type===s||t.type===f)}),y=o.filter(function(t){return"object"!=typeof t||t.type!==s&&t.type!==f&&t.type!==h}),p=o.filter(function(t){return"object"==typeof t&&t.type===h}),v=n.context?p.reduce(function(t,e){var n=e.assignment,i={};return"function"==typeof n?i=n(t,r||{type:"xstate.init"}):Object.keys(n).forEach(function(e){var a=n[e];i[e]="function"==typeof a?a(t,r):a}),Object.assign({},t,i)},n.context):n.context,l=e.value?this.getStateNodes(e.value):[];l.some(function(t){return t.transient})&&c.push({type:f});var g=l.reduce(function(t,e){return t[e.id]=e.data,t},{}),m=e.value?new w(e.value,v,a?t.updateHistoryValue(a,e.value):void 0,e.source?n:void 0,d(y,this.options.actions),u,g,c):void 0;if(!m)return w.inert(n,v);delete n.history;for(var S=m;c.length;){var x=S.actions,O=c.shift();(i=(S=this.transition(S,O.type===f?b:O.event,S.context)).actions).unshift.apply(i,x)}return S},t.prototype.isDone=function(t){var e=this;return t?"string"==typeof t?this.getStateNode(t).isDone():Object.keys(t).every(function(n){return e.getStateNode(n).isDone(t[n])}):"final"===this.type},t.prototype.ensureValidPaths=function(t){var e=this,n=new Map;t:for(var r=0,i=C(t.map(function(t){return e.getRelativeStateNodes(t)}));r<i.length;r++)for(var a=i[r],o=a;o.parent;){if(n.has(o.parent)){if(o.parent.parallel)continue t;throw new Error("State node '"+a.id+"' shares parent '"+o.parent.id+"' with state node '"+n.get(o.parent).map(function(t){return t.id})+"'")}n.get(o.parent)?n.get(o.parent).push(a):n.set(o.parent,[a]),o=o.parent}},t.prototype.getStateNode=function(t){if(E(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=E(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Substate '#"+e+"' does not exist on '"+this.id+"'");return n},t.prototype.getStateNodeByPath=function(t){for(var e=A(t,this.delimiter),n=this;e.length;){var r=e.shift();n=n.getStateNode(r)}return n},t.prototype.resolve=function(t){var e,n=this;if("string"==typeof t){var r=this.getStateNode(t);return r.initial?((e={})[t]=r.initialStateValue,e):t}return this.parallel?V(this.initialStateValue,function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):x}):V(t,function(t,e){return t?n.getStateNode(e).resolve(t):x})},Object.defineProperty(t.prototype,"resolvedStateValue",{get:function(){var t,e,n=this.key;return this.parallel?((t={})[n]=R(this.states,function(t){return t.resolvedStateValue[t.key]},function(t){return!t.history}),t):this.initial?((e={})[n]=this.states[this.initial].resolvedStateValue,e):n},enumerable:!0,configurable:!0}),t.prototype.getResolvedPath=function(t){if(E(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return A(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){if(this.__cache.initialState)return this.__cache.initialState;var t=this.parallel?R(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}),t.prototype.getState=function(t,e){var n=this;void 0===e&&(e=this.machine.context);var r={},i=[];this.getStateNodes(t).forEach(function(t){t.onEntry&&i.push.apply(i,t.onEntry),t.activities&&t.activities.forEach(function(t){r[N(t)]=!0,i.push(g(t))})});var a=i.filter(function(t){return"object"==typeof t&&(t.type===s||t.type===f)}),o=i.filter(function(t){return"object"==typeof t&&t.type===h}),u=e?o.reduce(function(t,e){var n=e.assignment,r={};return"function"==typeof n?r=n(t,{type:"init"}):Object.keys(n).forEach(function(e){var i=n[e];r[e]="function"==typeof i?i(t,{type:"init"}):i}),Object.assign({},t,r)},e):e,c=new w(t,u,void 0,void 0,d(i,this.options.actions),r,void 0,[]);return a.reduce(function(t,e){var r,i=t.actions;return(r=(t=n.transition(t,e.type===f?b:e.event,t.context)).actions).unshift.apply(r,i),t},c)},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:e.value,source:void 0,entryExitStates:{entry:new Set(this.getStateNodes(e.value)),exit:new Set},actions:[],paths:[]},e)},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&&E(e.target)?P(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),t.prototype.getStates=function(t){var e=this;if("string"==typeof t)return[this.states[t]];var n=[];return Object.keys(t).forEach(function(r){n.push.apply(n,e.states[r].getStates(t[r]))}),n},t.prototype.getRelativeStateNodes=function(t,e,n){if(void 0===n&&(n=!0),"string"==typeof t&&E(t)){var r=this.getStateNodeById(t);return n?r.history?r.resolveHistory(e):r.initialStateNodes:[r]}var i=A(t,this.delimiter),a=(this.parent||this).getFromRelativePath(i,e);return n?C(a.map(function(t){return t.initialStateNodes})):a},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var t=this;if("atomic"===this.type)return[this];var e=this.initialStateValue,n=M(e);return C(n.map(function(e){return t.getFromRelativePath(e)}))},enumerable:!0,configurable:!0}),t.prototype.getFromRelativePath=function(t,e){if(!t.length)return[this];var n=t[0],r=t.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var i=this.getStateNode(n);if(i.history)return i.resolveHistory(e);if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(r,e)},t.updateHistoryValue=function(t,e){return{current:e,states:function t(e,n){return V(e.states,function(e,r){if(e){var i=("string"==typeof n?void 0:n[r])||(e?e.current:void 0);if(i)return{current:i,states:t(e,i)}}})}(t,e)}},t.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:R(this.states,function(e,n){if(!t)return e.historyValue();var r="string"==typeof t?void 0:t[n];return e.historyValue(r||e.initialStateValue)},function(t){return!t.history})}},t.prototype.resolveHistory=function(t){var e=this;if(!this.history)return[this];var n=this.parent;if(!t)return this.target?C(M(this.target).map(function(t){return n.getFromRelativePath(t)})):this.parent.initialStateNodes;var r,i,a=(r=n.path,i="states",function(t){for(var e=t,n=0,a=r;n<a.length;n++){var o=a[n];e=e[i][o]}return e})(t).current;return"string"==typeof a?[n.getStateNode(a)]:C(M(a).map(function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=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(n){var r=t[n];if(r.states)for(var i=0,a=r.events;i<a.length;i++){var o=a[i];e.add(""+o)}}),this.__cache.events=Array.from(e)},enumerable:!0,configurable:!0}),t.prototype.formatTransition=function(t,n,r){var i=this,a=!!n&&n.internal;if(void 0===t||""===t)return e({},n,{target:void 0,internal:!n||(void 0===n.internal||n.internal),event:r});var o=(Array.isArray(t)?t:[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({},n,{target:o,internal:a,event:r})},t.prototype.formatTransitions=function(){var t=this,e=this.config.on||x,n=this.after,r=V(e,function(e,n){return void 0===e?[{target:void 0,event:n}]:Array.isArray(e)?e.map(function(e){return t.formatTransition(e.target,e,n)}):"string"==typeof e?[t.formatTransition([e],void 0,n)]:Object.keys(e).map(function(r){return t.formatTransition(r,e[r],n)})});return n.forEach(function(t){r[t.event]=r[t.event]||[],r[t.event].push(t)}),r}}(),function(){function t(t,e,n,r,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=n,this.history=r,this.actions=i,this.activities=o,this.data=s,this.events=u}return t.from=function(e,n){return e instanceof t?e.context!==n?new t(e.value,n,e.historyValue,e.history,[],e.activities,{},[]):e:new t(e,n,void 0,void 0,[],void 0,void 0,[])},t.inert=function(e,n){return e instanceof t?e.actions.length?new t(e.value,n,e.historyValue,e.history,[],e.activities,void 0,[]):e:t.from(e,n)},t.prototype.toStrings=function(t){var e=this;if(void 0===t&&(t=this.value),"string"==typeof t)return[t];var n=Object.keys(t);return n.concat.apply(n,n.map(function(n){return e.toStrings(t[n]).map(function(t){return n+"."+t})}))},t.prototype.matches=function(t){return o(t,this.value)},Object.defineProperty(t.prototype,"changed",{get:function(){return!!this.history&&(!!this.actions.length||typeof this.history.value!==this.value||("string"==typeof this.value?this.value!==this.history.value:function t(e,n){if(e===n)return!0;var r=Object.keys(e);var i=Object.keys(n);return r.length===i.length&&r.every(function(r){return t(e[r],n[r])})}(this.value,this.history.value)))},enumerable:!0,configurable:!0}),t}());function N(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 k(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 A(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 _(t,e){return t instanceof w?t.value:"object"!=typeof t||t instanceof w?P(A(t,e)):t}function P(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function V(t,e){var n={};return Object.keys(t).forEach(function(r,i){n[r]=e(t[r],r,t,i)}),n}function R(t,e,n){var r={};return Object.keys(t).forEach(function(i){var a=t[i];n(a)&&(r[i]=e(a,i,t))}),r}var J=function(t){return function(e){for(var n=e,r=0,i=t;r<i.length;r++){n=n[i[r]]}return n}};var M=function(t){return"string"==typeof t?[[t]]:C(Object.keys(t).map(function(e){return M(t[e]).map(function(t){return[e].concat(t)})}))},T=function(t){var e={};if(t&&1===t.length&&1===t[0].length)return t[0][0];for(var n=0,r=t;n<r.length;n++)for(var i=r[n],a=e,o=0;o<i.length;o++){var s=i[o];if(o===i.length-2){a[s]=i[o+1];break}a[s]=a[s]||{},a=a[s]}return e},C=function(t){var e;return(e=[]).concat.apply(e,t)};var H={};function I(t,e){var n=t.on[e];return C(n.map(function(n){var r=n.target?[].concat(n.target):void 0;return r?r.map(function(r){try{var i=r?t.getRelativeStateNodes(r,void 0,!1)[0]:t;return{source:t,target:i,event:e,actions:n.actions?n.actions.map(k):[],cond:n.cond,transition:n}}catch(e){return void console.warn("Target '"+r+"' not found on '"+t.id+"'")}}).filter(function(t){return void 0!==t}):[{source:t,target:t,event:e,actions:n.actions?n.actions.map(k):[],cond:n.cond,transition:n}]}))}function F(t,e){var n={},r=t.events;return function i(a){var o=JSON.stringify(a);if(!n[o]){n[o]={};for(var s=0,u=r;s<u.length;s++){var c=u[s],f=t.transition(a,c,e);n[o][c]={state:f.value},i(f.value)}}}(t.initialState.value),n}function B(t){if("string"==typeof t||"number"==typeof t)return""+t;var e=t.type,r=n(t,["type"]);return e+" | "+JSON.stringify(r)}function D(t,e){var n;if(!t.states)return H;var r=F(t,e),i=((n={})[JSON.stringify(t.initialState.value)]=[],n),a=new Set;return function e(n){var o=JSON.stringify(n);a.add(o);for(var s=r[o],u=0,c=Object.keys(s);u<c.length;u++){var f=c[u];if(v=s[f].state){var h=JSON.stringify(_(v,t.delimiter));(!i[h]||i[h].length>i[o].length+1)&&(i[h]=(i[o]||[]).concat([{state:n,event:f}]))}}for(var y=0,p=Object.keys(s);y<p.length;y++){var v;(v=s[p[y]].state)&&(h=JSON.stringify(v),a.has(h)||e(v))}return i}(t.initialState.value),i}function U(t,e){if(!t.states)return H;var n=F(t,e),r=new Set,i=[],a={};var o=JSON.stringify(t.initialState.value);return Object.keys(n).forEach(function(t){!function t(e,o){if(r.add(e),e===o)a[o]=a[o]||[],a[o].push(i.slice());else for(var s=0,u=Object.keys(n[e]);s<u.length;s++){var c=u[s],f=n[e][c].state;if(f){var h=JSON.stringify(f);r.has(h)||(i.push({state:JSON.parse(e),event:c}),t(h,o))}}i.pop(),r.delete(e)}(o,t)}),a}t.getNodes=function t(e){var n=e.states;return Object.keys(n).reduce(function(e,r){var i=n[r],a=t(n[r]);return e.push.apply(e,[i].concat(a)),e},[])},t.getEventEdges=I,t.getEdges=function t(e,n){var r=(n||{}).depth,i=void 0===r?null:r,a=[];return e.states&&null===i?Object.keys(e.states).forEach(function(n){a.push.apply(a,t(e.states[n]))}):i&&i>0&&Object.keys(e.states).forEach(function(n){a.push.apply(a,t(e.states[n],{depth:i-1}))}),Object.keys(e.on).forEach(function(t){a.push.apply(a,I(e,t))}),a},t.getAdjacencyMap=F,t.getValueAdjacencyMap=function(t,e){var n={},r=C(t.events.map(function(t){return e[t]||[t]}));return function e(i){var a=i.value,o=i.context,s=JSON.stringify(a)+" | "+JSON.stringify(o);if(!n[s]){n[s]={};for(var u=0,c=r;u<c.length;u++){var f=c[u],h=t.transition(i,f);n[s][B(f)]={state:h.value,ext:h.context},e(h)}}}(t.initialState),n},t.getShortestPaths=D,t.getShortestPathsAsArray=function(t,e){var n=D(t,e);return Object.keys(n).map(function(t){return{state:JSON.parse(t),path:n[t]}})},t.getSimplePaths=U,t.getSimplePathsAsArray=function(t,e){var n=U(t,e);return Object.keys(n).map(function(t){return{state:JSON.parse(t),paths:n[t]}})},Object.defineProperty(t,"__esModule",{value:!0})});
|