All files / xstate/dist xstate.js

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