xstate 4.7.8 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # xstate
2
2
 
3
+ ## 4.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`55aa589`](https://github.com/davidkpiano/xstate/commit/55aa589648a9afbd153e8b8e74cbf2e0ebf573fb) [#960](https://github.com/davidkpiano/xstate/pull/960) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The machine can now be safely JSON-serialized, using `JSON.stringify(machine)`. The shape of this serialization is defined in `machine.schema.json` and reflected in `machine.definition`.
8
+
9
+ Note that `onEntry` and `onExit` have been deprecated in the definition in favor of `entry` and `exit`.
10
+
11
+ ### Patch Changes
12
+
13
+ - [`1ae31c1`](https://github.com/davidkpiano/xstate/commit/1ae31c17dc81fb63e699b4b9bf1cf4ead023001d) [#1023](https://github.com/davidkpiano/xstate/pull/1023) Thanks [@Andarist](https://github.com/Andarist)! - Fixed memory leak - `State` objects had been retained in closures.
14
+
3
15
  ## 4.7.8
4
16
 
5
17
  ### Patch Changes
@@ -12,4 +12,4 @@
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */var e,n,i=function(){return(i=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a=".",u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}(t,e));var n}function f(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function l(t,e,n){var i,o;if(v(t))return t(e,n.data);var s={};try{for(var a=r(c(t)),u=a.next();!u.done;u=a.next()){var h=u.value,f=t[h];v(f)?s[h]=f(e,n.data):s[h]=f}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}function w(t){try{return"subscribe"in t&&v(t.subscribe)}catch(t){return!1}}var b="function"==typeof Symbol&&Symbol.observable||"@@observable";function x(t){try{return"__xstatenode"in t}catch(t){return!1}}var m,g=(m=0,function(){return(++m).toString(16)});function S(t,e){return y(t)||"number"==typeof t?i({type:t},e):t}function E(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=S(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function _(t){return c(t.states).map((function(e){return t.states[e]}))}function O(t){return e=s(new Set(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s(e));var e,n}function T(t,e){return"compound"===e.type?_(e).some((function(e){return"final"===e.type&&(n=t,i=e,Array.isArray(n)?n.some((function(t){return t===i})):n instanceof Set&&n.has(i));var n,i})):"parallel"===e.type&&_(e).every((function(e){return T(t,e)}))}var L=e.Start,k=e.Stop,P=(e.Raise,e.Send),I=e.Cancel,N=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),j=e.Init,M=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),D=e.ErrorCustom,A=e.Update,C=(e.Pure,E({type:j}));function R(t,n){var i=e.DoneInvoke+"."+t,r={type:i,data:n,toString:function(){return i}};return r}function z(t,n){var i=e.ErrorPlatform+"."+t,r={type:i,data:n,toString:function(){return i}};return r}var V=function(){function t(t){this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return O(t.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:C,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=C;return new t({value:e.value,context:n,_event:i,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),y(t))return[t];var i=c(t);return i.concat.apply(i,s(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;return function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(this,["configuration","transitions"])},t.prototype.matches=function(t){return function t(e,n,i){void 0===i&&(i=a);var r=h(e,i),o=h(n,i);return y(o)?!!y(r)&&o===r:y(r)?r in o:c(r).every((function(e){return e in o&&t(r[e],o[e])}))}(t,this.value)},t}(),J={deferEvents:!1},q=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},J),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}();function U(t){try{return"function"==typeof t.send}catch(t){return!1}}var $,F,X=new Map,B=0,G={bookId:function(){return"x:"+B++},register:function(t,e){return X.set(t,e),t},get:function(t){return X.get(t)},free:function(t){X.delete(t)}},H={sync:!1,autoForward:!1},K=($=[],function(t,e){t&&$.push(t);var n=e(t||$[$.length-1]);return t&&$.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(F||(F={}));var Q=function(){function t(e,r){var o=this;void 0===r&&(r=t.defaultOptions),this.machine=e,this.scheduler=new q,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=F.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(p(t))return o.batch(t),o.state;var n=E(S(t,e));if(o._status===F.Stopped)return o.state;if(o._status===F.NotStarted&&o.options.deferEvents);else if(o._status!==F.Running)throw new Error('Event "'+n.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(t,e){var r=o.parent&&(e===n.Parent||o.parent.id===e),s=r?o.parent:U(e)?e:o.children.get(e)||G.get(e);if(s)"machine"in s?s.send(i(i({},t),{name:t.name===D?""+z(o.id):t.name,origin:o.sessionId})):s.send(t.data);else if(!r)throw new Error("Unable to send event to child '"+e+"' from service '"+o.id+"'.")};var s=i(i({},t.defaultOptions),r),a=s.clock,u=s.logger,c=s.parent,h=s.id,f=void 0!==h?h:e.id;this.id=f,this.logger=u,this.clock=a,this.parent=c,this.options=s,this.scheduler=new q({deferEvents:this.options.deferEvents}),this.sessionId=G.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:K(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),t.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value;this.exec(a,t,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},t.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=r(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var w=r(this.contextListeners),b=w.next();!b.done;b=w.next()){(0,b.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{b&&!b.done&&(u=w.return)&&u.call(w)}finally{if(a)throw a.error}}var x=T(t.configuration||[],this.machine);if(this.state.configuration&&x){var m=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),g=m&&m.data?l(m.data,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(R(this.id,g))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},t.prototype.onTransition=function(t){return this.listeners.add(t),this._status===F.Running&&t(this.state,this.state.event),this},t.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===F.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},t.prototype.onEvent=function(t){return this.eventListeners.add(t),this},t.prototype.onSend=function(t){return this.sendListeners.add(t),this},t.prototype.onChange=function(t){return this.contextListeners.add(t),this},t.prototype.onStop=function(t){return this.stopListeners.add(t),this},t.prototype.onDone=function(t){return this.doneListeners.add(t),this},t.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},t.prototype.start=function(t){var e=this;if(this._status===F.Running)return this;G.register(this.sessionId,this),this.initialized=!0,this._status=F.Running;var n=void 0===t?this.initialState:K(this,(function(){return!y(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(V.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,C)})),this},t.prototype.stop=function(){var t,e,n,i,o,s,a,u,h,f;try{for(var l=r(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var y=r(this.stopListeners),w=y.next();!w.done;w=y.next()){(p=w.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{w&&!w.done&&(i=y.return)&&i.call(y)}finally{if(n)throw n.error}}try{for(var b=r(this.contextListeners),x=b.next();!x.done;x=b.next()){p=x.value;this.contextListeners.delete(p)}}catch(t){o={error:t}}finally{try{x&&!x.done&&(s=b.return)&&s.call(b)}finally{if(o)throw o.error}}try{for(var m=r(this.doneListeners),g=m.next();!g.done;g=m.next()){p=g.value;this.doneListeners.delete(p)}}catch(t){a={error:t}}finally{try{g&&!g.done&&(u=m.return)&&u.call(m)}finally{if(a)throw a.error}}this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var S=r(c(this.delayedEventsMap)),E=S.next();!E.done;E=S.next()){var _=E.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{E&&!E.done&&(f=S.return)&&f.call(S)}finally{if(h)throw h.error}}return this.scheduler.clear(),this.initialized=!1,this._status=F.Stopped,G.free(this.sessionId),this},t.prototype.batch=function(t){var e=this;if(this._status===F.NotStarted&&this.options.deferEvents);else if(this._status!==F.Running)throw new Error(t.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var n,o,a=e.state,u=!1,c=[],h=function(t){var n=E(t);e.forward(n),a=K(e,(function(){return e.machine.transition(a,n)})),c.push.apply(c,s(a.actions.map((function(t){return n=a,r=(e=t).exec,i(i({},e),{exec:void 0!==r?function(){return r(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,r})))),u=u||!!a.changed};try{for(var f=r(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}a.changed=u,a.actions=c,e.update(a,E(t[t.length-1]))}))},t.prototype.sender=function(t){return this.send.bind(this,t)},t.prototype.nextState=function(t){var e=this,n=E(t);if(0===n.name.indexOf(M)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(M)})))throw n.data.data;return K(this,(function(){return e.machine.transition(e.state,n)}))},t.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+s+"'.");a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},t.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},t.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},t.prototype.exec=function(t,n,i){var r=n.context,o=n._event,s=function(t,e){return e&&e[t]||void 0}(t.type,i)||t.exec,a=v(s)?s:s?s.exec:t.exec;if(a)try{return a(r,o.data,{action:t,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case P:var u=t;if("number"==typeof u.delay)return void this.defer(u);u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case I:this.cancel(t.sendId);break;case L:var c=t.activity;if(!this.state.activities[c.type])break;if(c.type===e.Invoke){var h=this.machine.options.services?this.machine.options.services[c.src]:void 0,f=c.id,p=c.data,y="autoForward"in c?c.autoForward:!!c.forward;if(!h)return;var b=v(h)?h(r,o.data):h;d(b)?this.state.children[f]=this.spawnPromise(Promise.resolve(b),f):v(b)?this.state.children[f]=this.spawnCallback(b,f):w(b)?this.state.children[f]=this.spawnObservable(b,f):x(b)&&(this.state.children[f]=this.spawnMachine(p?b.withContext(l(p,r,o)):b,{id:f,autoForward:y}))}else this.spawnActivity(c);break;case k:this.stopChild(t.activity.id);break;case N:var m=t.label,g=t.value;m?this.logger(m,g):this.logger(g)}},t.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],v(e.stop)&&e.stop())},t.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(U(t))return this.spawnActor(t);if(w(t))return this.spawnObservable(t,e);if(x(t))return this.spawnMachine(t,i(i({},n),{id:e}));throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".')},t.prototype.spawnMachine=function(e,n){var r=this;void 0===n&&(n={});var o=new t(e,i(i({},this.options),{parent:this,id:n.id||e.id})),s=i(i({},H),n);s.sync&&o.onTransition((function(t){r.send(A,{state:t,id:o.id})})),o.onDone((function(t){r.send(E(t,{origin:o.id}))})).start();var a=o;return this.children.set(o.id,a),s.autoForward&&this.forwardTo.add(o.id),a},t.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||n.send(E(R(e,t),{origin:e}))}),(function(t){if(!i){var r=z(e,t);try{n.send(E(r,{origin:e}))}catch(t){n.devTools&&n.devTools.send(r,n.state),n.machine.strict&&n.stop()}}}));var r={id:e,send:function(){},subscribe:function(e,n,i){var r=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},t.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,s=new Set;try{n=t((function(t){s.forEach((function(e){return e(t)})),r||i.send(t)}),(function(t){o.add(t)}))}catch(t){this.send(z(e,t))}if(d(n))return this.spawnPromise(n,e);var a={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){r=!0,v(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,a),a},t.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(E(t,{origin:e}))}),(function(t){n.send(E(z(e,t),{origin:e}))}),(function(){n.send(E(R(e),{origin:e}))})),r={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},t.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},t.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},t.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},t.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:i({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[b]=function(){return this},t.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),t.interpret=Z,t}(),W=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},Y=function(t){return y(t)?i(i({},H),{name:t}):i(i(i({},H),{name:g()}),t)};function Z(t,e){return new Q(t,e)}t.Interpreter=Q,t.interpret=Z,t.spawn=function(t,e){var n=Y(e);return K(void 0,(function(e){return e?e.spawn(t,n.name,n):W(n.name)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var e,n,i=function(){return(i=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a=".",u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}(t,e));var n}function f(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function l(t,e,n){var i,o;if(v(t))return t(e,n.data);var s={};try{for(var a=r(c(t)),u=a.next();!u.done;u=a.next()){var h=u.value,f=t[h];v(f)?s[h]=f(e,n.data):s[h]=f}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}function w(t){try{return"subscribe"in t&&v(t.subscribe)}catch(t){return!1}}var b="function"==typeof Symbol&&Symbol.observable||"@@observable";function x(t){try{return"__xstatenode"in t}catch(t){return!1}}var m,g=(m=0,function(){return(++m).toString(16)});function S(t,e){return y(t)||"number"==typeof t?i({type:t},e):t}function E(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=S(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function _(t){return c(t.states).map((function(e){return t.states[e]}))}function O(t){return e=s(new Set(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s(e));var e,n}function T(t,e){return"compound"===e.type?_(e).some((function(e){return"final"===e.type&&(n=t,i=e,Array.isArray(n)?n.some((function(t){return t===i})):n instanceof Set&&n.has(i));var n,i})):"parallel"===e.type&&_(e).every((function(e){return T(t,e)}))}var L=e.Start,k=e.Stop,P=(e.Raise,e.Send),I=e.Cancel,N=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),j=e.Init,M=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),D=e.ErrorCustom,A=e.Update,C=(e.Pure,E({type:j}));function R(t,n){var i=e.DoneInvoke+"."+t,r={type:i,data:n,toString:function(){return i}};return r}function z(t,n){var i=e.ErrorPlatform+"."+t,r={type:i,data:n,toString:function(){return i}};return r}var V=function(){function t(t){var e=this;this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return O(e.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:C,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=C;return new t({value:e.value,context:n,_event:i,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),y(t))return[t];var i=c(t);return i.concat.apply(i,s(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;return function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(this,["configuration","transitions"])},t.prototype.matches=function(t){return function t(e,n,i){void 0===i&&(i=a);var r=h(e,i),o=h(n,i);return y(o)?!!y(r)&&o===r:y(r)?r in o:c(r).every((function(e){return e in o&&t(r[e],o[e])}))}(t,this.value)},t}(),J={deferEvents:!1},q=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},J),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}();function U(t){try{return"function"==typeof t.send}catch(t){return!1}}var $,F,X=new Map,B=0,G={bookId:function(){return"x:"+B++},register:function(t,e){return X.set(t,e),t},get:function(t){return X.get(t)},free:function(t){X.delete(t)}},H={sync:!1,autoForward:!1},K=($=[],function(t,e){t&&$.push(t);var n=e(t||$[$.length-1]);return t&&$.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(F||(F={}));var Q=function(){function t(e,r){var o=this;void 0===r&&(r=t.defaultOptions),this.machine=e,this.scheduler=new q,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=F.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(p(t))return o.batch(t),o.state;var n=E(S(t,e));if(o._status===F.Stopped)return o.state;if(o._status===F.NotStarted&&o.options.deferEvents);else if(o._status!==F.Running)throw new Error('Event "'+n.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(t,e){var r=o.parent&&(e===n.Parent||o.parent.id===e),s=r?o.parent:U(e)?e:o.children.get(e)||G.get(e);if(s)"machine"in s?s.send(i(i({},t),{name:t.name===D?""+z(o.id):t.name,origin:o.sessionId})):s.send(t.data);else if(!r)throw new Error("Unable to send event to child '"+e+"' from service '"+o.id+"'.")};var s=i(i({},t.defaultOptions),r),a=s.clock,u=s.logger,c=s.parent,h=s.id,f=void 0!==h?h:e.id;this.id=f,this.logger=u,this.clock=a,this.parent=c,this.options=s,this.scheduler=new q({deferEvents:this.options.deferEvents}),this.sessionId=G.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:K(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),t.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value;this.exec(a,t,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},t.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=r(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var w=r(this.contextListeners),b=w.next();!b.done;b=w.next()){(0,b.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{b&&!b.done&&(u=w.return)&&u.call(w)}finally{if(a)throw a.error}}var x=T(t.configuration||[],this.machine);if(this.state.configuration&&x){var m=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),g=m&&m.data?l(m.data,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(R(this.id,g))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},t.prototype.onTransition=function(t){return this.listeners.add(t),this._status===F.Running&&t(this.state,this.state.event),this},t.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===F.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},t.prototype.onEvent=function(t){return this.eventListeners.add(t),this},t.prototype.onSend=function(t){return this.sendListeners.add(t),this},t.prototype.onChange=function(t){return this.contextListeners.add(t),this},t.prototype.onStop=function(t){return this.stopListeners.add(t),this},t.prototype.onDone=function(t){return this.doneListeners.add(t),this},t.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},t.prototype.start=function(t){var e=this;if(this._status===F.Running)return this;G.register(this.sessionId,this),this.initialized=!0,this._status=F.Running;var n=void 0===t?this.initialState:K(this,(function(){return!y(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(V.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,C)})),this},t.prototype.stop=function(){var t,e,n,i,o,s,a,u,h,f;try{for(var l=r(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var y=r(this.stopListeners),w=y.next();!w.done;w=y.next()){(p=w.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{w&&!w.done&&(i=y.return)&&i.call(y)}finally{if(n)throw n.error}}try{for(var b=r(this.contextListeners),x=b.next();!x.done;x=b.next()){p=x.value;this.contextListeners.delete(p)}}catch(t){o={error:t}}finally{try{x&&!x.done&&(s=b.return)&&s.call(b)}finally{if(o)throw o.error}}try{for(var m=r(this.doneListeners),g=m.next();!g.done;g=m.next()){p=g.value;this.doneListeners.delete(p)}}catch(t){a={error:t}}finally{try{g&&!g.done&&(u=m.return)&&u.call(m)}finally{if(a)throw a.error}}this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var S=r(c(this.delayedEventsMap)),E=S.next();!E.done;E=S.next()){var _=E.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{E&&!E.done&&(f=S.return)&&f.call(S)}finally{if(h)throw h.error}}return this.scheduler.clear(),this.initialized=!1,this._status=F.Stopped,G.free(this.sessionId),this},t.prototype.batch=function(t){var e=this;if(this._status===F.NotStarted&&this.options.deferEvents);else if(this._status!==F.Running)throw new Error(t.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var n,o,a=e.state,u=!1,c=[],h=function(t){var n=E(t);e.forward(n),a=K(e,(function(){return e.machine.transition(a,n)})),c.push.apply(c,s(a.actions.map((function(t){return n=a,r=(e=t).exec,i(i({},e),{exec:void 0!==r?function(){return r(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,r})))),u=u||!!a.changed};try{for(var f=r(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}a.changed=u,a.actions=c,e.update(a,E(t[t.length-1]))}))},t.prototype.sender=function(t){return this.send.bind(this,t)},t.prototype.nextState=function(t){var e=this,n=E(t);if(0===n.name.indexOf(M)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(M)})))throw n.data.data;return K(this,(function(){return e.machine.transition(e.state,n)}))},t.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+s+"'.");a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},t.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},t.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},t.prototype.exec=function(t,n,i){var r=n.context,o=n._event,s=function(t,e){return e&&e[t]||void 0}(t.type,i)||t.exec,a=v(s)?s:s?s.exec:t.exec;if(a)try{return a(r,o.data,{action:t,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case P:var u=t;if("number"==typeof u.delay)return void this.defer(u);u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case I:this.cancel(t.sendId);break;case L:var c=t.activity;if(!this.state.activities[c.type])break;if(c.type===e.Invoke){var h=this.machine.options.services?this.machine.options.services[c.src]:void 0,f=c.id,p=c.data,y="autoForward"in c?c.autoForward:!!c.forward;if(!h)return;var b=v(h)?h(r,o.data):h;d(b)?this.state.children[f]=this.spawnPromise(Promise.resolve(b),f):v(b)?this.state.children[f]=this.spawnCallback(b,f):w(b)?this.state.children[f]=this.spawnObservable(b,f):x(b)&&(this.state.children[f]=this.spawnMachine(p?b.withContext(l(p,r,o)):b,{id:f,autoForward:y}))}else this.spawnActivity(c);break;case k:this.stopChild(t.activity.id);break;case N:var m=t.label,g=t.value;m?this.logger(m,g):this.logger(g)}},t.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],v(e.stop)&&e.stop())},t.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(U(t))return this.spawnActor(t);if(w(t))return this.spawnObservable(t,e);if(x(t))return this.spawnMachine(t,i(i({},n),{id:e}));throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".')},t.prototype.spawnMachine=function(e,n){var r=this;void 0===n&&(n={});var o=new t(e,i(i({},this.options),{parent:this,id:n.id||e.id})),s=i(i({},H),n);s.sync&&o.onTransition((function(t){r.send(A,{state:t,id:o.id})})),o.onDone((function(t){r.send(E(t,{origin:o.id}))})).start();var a=o;return this.children.set(o.id,a),s.autoForward&&this.forwardTo.add(o.id),a},t.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||n.send(E(R(e,t),{origin:e}))}),(function(t){if(!i){var r=z(e,t);try{n.send(E(r,{origin:e}))}catch(t){n.devTools&&n.devTools.send(r,n.state),n.machine.strict&&n.stop()}}}));var r={id:e,send:function(){},subscribe:function(e,n,i){var r=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},t.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,s=new Set;try{n=t((function(t){s.forEach((function(e){return e(t)})),r||i.send(t)}),(function(t){o.add(t)}))}catch(t){this.send(z(e,t))}if(d(n))return this.spawnPromise(n,e);var a={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){r=!0,v(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,a),a},t.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(E(t,{origin:e}))}),(function(t){n.send(E(z(e,t),{origin:e}))}),(function(){n.send(E(R(e),{origin:e}))})),r={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},t.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},t.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},t.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},t.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:i({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[b]=function(){return this},t.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),t.interpret=Z,t}(),W=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},Y=function(t){return y(t)?i(i({},H),{name:t}):i(i(i({},H),{name:g()}),t)};function Z(t,e){return new Q(t,e)}t.Interpreter=Q,t.interpret=Z,t.spawn=function(t,e){var n=Y(e);return K(void 0,(function(e){return e?e.spawn(t,n.name,n):W(n.name)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
package/dist/xstate.js CHANGED
@@ -12,4 +12,4 @@
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}var a=".",s={},c="xstate.guard",u="";function h(t){return Object.keys(t)}function f(t,e,n){void 0===n&&(n=a);var i=p(t,n),r=p(e,n);return A(r)?!!A(i)&&r===i:A(i)?i in r:h(i).every((function(t){return t in r&&f(i[t],r[t])}))}function l(t){try{return A(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 d(t,e){try{return O(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function p(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:O(t)?v(t):"string"!=typeof t?t:v(d(t,e));var n}function v(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function y(t,e){for(var n={},i=h(t),r=0;r<i.length;r++){var o=i[r];n[o]=e(t[o],o,t,r)}return n}function g(t,e,n){var r,o,a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];n(f)&&(a[u]=e(f,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a}var m=function(t){return function(e){var n,r,o=e;try{for(var a=i(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return o}};function x(t){return t?A(t)?[[t]]:S(h(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?x(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function S(t){var e;return(e=[]).concat.apply(e,o(t))}function w(t){return O(t)?t:[t]}function b(t){return void 0===t?[]:w(t)}function _(t,e,n){var r,o;if(P(t))return t(e,n.data);var a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];P(f)?a[u]=f(e,n.data):a[u]=f}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a}function E(t){return t instanceof Promise||!(null===t||!P(t)&&"object"!=typeof t||!P(t.then))}function T(t,e){var n,o,a=r([[],[]],2),s=a[0],c=a[1];try{for(var u=i(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function N(t,e){return y(t.states,(function(t,n){if(t){var i=(A(e)?void 0:e[n])||(t?t.current:void 0);if(i)return{current:i,states:N(t,i)}}}))}function O(t){return Array.isArray(t)}function P(t){return"function"==typeof t}function A(t){return"string"==typeof t}function k(t,e){if(t)return A(t)?{type:c,name:t,predicate:e?e[t]:void 0}:P(t)?{type:c,name:t.name,predicate:t}:t}function V(t){try{return"subscribe"in t&&P(t.subscribe)}catch(t){return!1}}var I="function"==typeof Symbol&&Symbol.observable||"@@observable";function j(t){try{return"__xstatenode"in t}catch(t){return!1}}var L,C,M,R=(L=0,function(){return(++L).toString(16)});function D(t,n){return A(t)||"number"==typeof t?e({type:t},n):t}function F(t,n){if(!A(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var i=D(t);return e({name:i.type,data:i,$$type:"scxml",type:"external"},n)}function U(t,n){return w(n).map((function(n){return void 0===n||"string"==typeof n||j(n)?{target:n,event:t}:e(e({},n),{event:t})}))}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",(M=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",M.Internal="#_internal";var z=function(t){return"atomic"===t.type||"final"===t.type};function J(t){return h(t.states).map((function(e){return t.states[e]}))}function B(t){var e=[t];return z(t)?e:e.concat(S(J(t).map(B)))}function q(t,e){var n,r,o,a,s,c,u,h,f=$(new Set(t)),l=new Set(e);try{for(var d=i(l),p=d.next();!p.done;p=d.next())for(var v=(E=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=$(l);try{for(var g=i(l),m=g.next();!m.done;m=g.next()){if("compound"!==(E=m.value).type||y.get(E)&&y.get(E).length){if("parallel"===E.type)try{for(var x=(s=void 0,i(J(E))),S=x.next();!S.done;S=x.next()){var w=S.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=i(l),_=b.next();!_.done;_=b.next()){var E;for(v=(E=_.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function $(t){var e,n,r=new Map;try{for(var o=i(t),a=o.next();!a.done;a=o.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}function X(t,e){return function t(e,n){var i=n.get(e);if(!i)return{};if("compound"===e.type){var r=i[0];if(!r)return{};if(z(r))return r.key}var o={};return i.forEach((function(e){o[e.key]=t(e,n)})),o}(t,$(q([t],e)))}function G(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function H(t,e){return"compound"===e.type?J(e).some((function(e){return"final"===e.type&&G(t,e)})):"parallel"===e.type&&J(e).every((function(e){return H(t,e)}))}var K=t.ActionTypes.Start,Q=t.ActionTypes.Stop,W=t.ActionTypes.Raise,Y=t.ActionTypes.Send,Z=t.ActionTypes.Cancel,tt=t.ActionTypes.NullEvent,et=t.ActionTypes.Assign,nt=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),it=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,ot=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),at=t.ActionTypes.ErrorCustom,st=t.ActionTypes.Update,ct=t.ActionTypes.Pure,ut=F({type:it});function ht(t,e){return e&&e[t]||void 0}function ft(t,i){var r;if(A(t)||"number"==typeof t){var o=ht(t,i);r=P(o)?{type:t,exec:o}:o||{type:t,exec:void 0}}else if(P(t))r={type:t.name||t.toString(),exec:t};else{if(P(o=ht(t.type,i)))r=e(e({},t),{exec:o});else if(o){var a=t.type,s=n(t,["type"]);r=e(e({type:a},o),s)}else r=t}return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var lt=function(t,e){return t?(O(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:A(t)?t:n.id},n),{type:n.type})}function pt(e){return A(e)?{type:W,event:e}:vt(e,{to:t.SpecialTargets.Internal})}function vt(t,e){return{to:e?e.to:void 0,type:Y,event:P(t)?t:D(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:P(t)?t.name:l(t)}}function yt(n,i){return vt(n,e(e({},i),{to:t.SpecialTargets.Parent}))}function gt(){return yt(st)}var mt=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Z,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:et,assignment:t}};function _t(e,n){var i=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+i}function Et(e,n){var i=t.ActionTypes.DoneState+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Tt(e,n){var i=t.ActionTypes.DoneInvoke+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Nt(e,n){var i=t.ActionTypes.ErrorPlatform+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Ot(t,n){return vt((function(t,e){return e}),e(e({},n),{to:t}))}var Pt=function(){function t(t){this.actions=[],this.activities=s,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||s,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return e=t.configuration,S(o(new Set(e.map((function(t){return t.ownEvents})))));var e}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=ut;return new t({value:e.value,context:n,_event:i,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),A(t))return[t];var i=h(t);return i.concat.apply(i,o(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;return n(this,["configuration","transitions"])},t.prototype.matches=function(t){return f(t,this.value)},t}();function At(t){try{return"function"==typeof t.send}catch(t){return!1}}var kt="",Vt={},It=function(t){return"#"===t[0]},jt=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Lt=function(){function s(t,n,r){var c=this;this.config=t,this.context=r,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign(jt(),n),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:a),this.id=this.config.id||o([this.machine.key],this.path).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&h(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?y(this.config.states,(function(t,n){var i,r=new s(t,{_parent:c,_key:n});return Object.assign(c.idMap,e(((i={})[r.id]=r,i),r.idMap)),r})):Vt;var u=0;!function t(e){var n,r;e.order=u++;try{for(var o=i(J(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return t.event===kt})):kt in this.config.on),this.strict=!!this.config.strict,this.onEntry=b(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=b(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=b(this.config.invoke).map((function(t,n){var i,r;if(j(t))return c.machine.options.services=e(((i={})[t.id]=t,i),c.machine.options.services),{type:rt,src:t.id,id:t.id};if("string"!=typeof t.src){var o=c.id+":invocation["+n+"]";return c.machine.options.services=e(((r={})[o]=t.src,r),c.machine.options.services),e(e({type:rt,id:o},t),{src:o})}return e(e({},t),{type:rt,id:t.id||t.src,src:t.src})})),this.activities=b(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this)}return s.prototype._init=function(){this.__cache.transitions||B(this).forEach((function(t){return t.on}))},s.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var i=this.options,r=i.actions,o=i.activities,a=i.guards,c=i.services,u=i.delays;return new s(this.config,{actions:e(e({},r),t.actions),activities:e(e({},o),t.activities),guards:e(e({},a),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},n)},s.prototype.withContext=function(t){return new s(this.config,this.options,t)},Object.defineProperty(s.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,type:this.type,initial:this.initial,history:this.history,states:y(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,onEntry:this.onEntry,onExit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}},enumerable:!0,configurable:!0}),s.prototype.toJSON=function(){return this.definition},Object.defineProperty(s.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!0,configurable:!0}),s.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=t===kt,n=this.transitions.filter((function(n){var i=n.eventType===t;return e?i:i||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},s.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var i=function(e,n){var i=_t(P(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(i,{delay:e})),t.onExit.push(xt(i)),i};return(O(n)?n.map((function(t,n){var r=i(t.delay,n);return e(e({},t),{event:r})})):S(h(n).map((function(t,r){var o=n[t],a=A(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=i(s,r);return b(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var i=n.delay;return e(e({},t.formatTransition(n)),{delay:i})}))},s.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var i=t instanceof Pt?t.value:p(t,this.delimiter);if(A(i)){var r=this.getStateNode(i).initial;return void 0!==r?this.getStateNodes(((e={})[i]=r,e)):[this.states[i]]}var o=h(i);return o.map((function(t){return n.getStateNode(t)})).concat(o.reduce((function(t,e){var r=n.getStateNode(e).getStateNodes(i[e]);return t.concat(r)}),[]))},s.prototype.handles=function(t){var e=l(t);return this.events.includes(e)},s.prototype.resolveState=function(t){var n=Array.from(q([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n}))},s.prototype.transitionLeafNode=function(t,e,n){var i=this.getStateNode(t).next(e,n);return i&&i.transitions.length?i:this.next(e,n)},s.prototype.transitionCompoundNode=function(t,e,n){var i=h(t),r=this.getStateNode(i[0])._transition(t[i[0]],e,n);return r&&r.transitions.length?r:this.next(e,n)},s.prototype.transitionParallelNode=function(t,e,n){var r,o,a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];if(f){var l=this.getStateNode(u)._transition(f,e,n);l&&(a[u]=l)}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}var d=h(a).map((function(t){return a[t]})),p=S(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=S(d.map((function(t){return t.entrySet}))),y=S(h(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:S(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:S(h(a).map((function(t){return a[t].actions})))}},s.prototype._transition=function(t,e,n){return A(t)?this.transitionLeafNode(t,e,n):1===h(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},s.prototype.next=function(t,e){var n,r,a,s=this,c=e.name,u=[],h=[];try{for(var l=i(this.getCandidates(c)),d=l.next();!d.done;d=l.next()){var v=d.value,y=v.cond,g=v.in,x=t.context,w=!g||(A(g)&&It(g)?t.matches(p(this.getStateNodeById(g).path,this.delimiter)):f(p(g,this.delimiter),m(this.path.slice(0,-2))(t.value))),b=!1;try{b=!y||this.evaluateGuard(y,x,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(y.name||y.type)+"' in transition for event '"+c+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==v.target&&(h=v.target),u.push.apply(u,o(v.actions)),a=v;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(a){if(!h.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:u};var _=S(h.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:S(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:u}}},s.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},s.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},s.prototype.evaluateGuard=function(t,e,n,i){var r=this.machine.options.guards,o={state:i,cond:t,_event:n};if(t.type===c)return t.predicate(e,n.data,o);var a=r[t.type];if(!a)throw new Error("Guard '"+t.type+"' is not implemented on machine '"+this.machine.id+"'.");return a(e,n.data,o)},s.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=q([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?q(f,t.configuration):f;try{for(var d=i(l),p=d.next();!p.done;p=d.next()){G(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=i(f),y=v.next();!y.done;y=v.next()){var g;G(l,g=y.value)&&!G(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var m=S(t.entrySet.map((function(i){var r=[];if("final"!==i.type)return r;var o=i.parent;if(r.push(Et(i.id,i.data),Et(o.id,i.data?_(i.data,e,n):void 0)),o.parent){var a=o.parent;"parallel"===a.type&&J(a).every((function(e){return H(t.configuration,e)}))&&r.push(Et(a.id,a.data))}return r})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var x=new Set(t.entrySet),w=new Set(t.exitSet),b=r([S(Array.from(x).map((function(t){return o(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(m.map(pt)),S(Array.from(w).map((function(t){return o(t.onExit,t.activities.map((function(t){return wt(t)})))})))],2),E=b[0],T=b[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},s.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var i,r,a=F(e);if(t instanceof Pt)i=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=A(t)?this.resolve(v(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;i=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(r=a.name,!/^(done|error)\./.test(r)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(i.value,i,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:i,actions:[]},h=q([],this.getStateNodes(i.value)),f=u.configuration.length?q(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,i,a)},s.prototype.resolveRaisedTransition=function(t,e,n){var i,r=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(i=t.actions).unshift.apply(i,o(r)),t},s.prototype.resolveTransition=function(n,o,a,s){var c,u,f=this;void 0===a&&(a=ut),void 0===s&&(s=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0?X(this.machine,l):void 0,p=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,v=o?o.context:s,y=this.getActions(n,v,a,o),g=o?e({},o.activities):{};try{for(var m=i(y),x=m.next();!x.done;x=m.next()){var w=x.value;w.type===K?g[w.activity.type]=w:w.type===Q&&(g[w.activity.type]=!1)}}catch(t){c={error:t}}finally{try{x&&!x.done&&(u=m.return)&&u.call(m)}finally{if(c)throw c.error}}var b,_,E=r(T(y,(function(t){return t.type===et})),2),O=E[0],k=E[1],V=O.length?function(t,e,n,r){return t?n.reduce((function(t,n){var o,a,s=n.assignment,c={state:r,action:n,_event:e},u={};if(P(s))u=s(t,e.data,c);else try{for(var f=i(h(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[d];u[d]=P(p)?p(t,e.data,c):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,u)}),t):t}(v,a,O,o):v,I=S(k.map((function(t){switch(t.type){case W:return function(t){return{type:W,_event:F(t.event)}}(t);case Y:return function(t,n,i,r){var o,a={_event:i},s=F(P(t.event)?t.event(n,i.data,a):t.event);if(A(t.delay)){var c=r&&r[t.delay];o=P(c)?c(n,i.data,a):c}else o=P(t.delay)?t.delay(n,i.data,a):t.delay;var u=P(t.to)?t.to(n,i.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(t,V,a,f.machine.options.delays);case nt:return function(t,n,i){return e(e({},t),{value:A(t.expr)?t.expr:t.expr(n,i.data,{_event:i})})}(t,V,a);case ct:return t.get(V,a.data)||[];default:return ft(t,f.options.actions)}}))),j=r(T(I,(function(e){return e.type===W||e.type===Y&&e.to===t.SpecialTargets.Internal})),2),L=j[0],C=j[1],M=I.filter((function(t){return t.type===K&&t.activity.type===rt})).reduce((function(t,e){var n,i,r;return t[e.activity.id]=(n=e.activity,(r={id:i=n.id,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:i}}}).meta=n,r),t}),o?e({},o.children):{}),R=d?n.configuration:o?o.configuration:[],D=R.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),U=H(R,this),z=new Pt({value:d||o.value,context:V,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?p?(b=p,_=d,{current:_,states:N(b,_)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?C:[],activities:d?g:o?o.activities:{},meta:d?D:o?o.meta:void 0,events:[],configuration:R,transitions:n.transitions,children:M,done:U});z.changed=a.name===st||!!O.length;var J=z.history;if(J&&delete J.history,!d)return z;var B=z;if(!U)for((this._transient||l.some((function(t){return t._transient})))&&(B=this.resolveRaisedTransition(B,{type:tt},a));L.length;){var q=L.shift();B=this.resolveRaisedTransition(B,q._event,a)}var $=B.changed||(J?!!B.actions.length||!!O.length||typeof J.value!=typeof B.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(A(e)||A(n))return e===n;var i=h(e),r=h(n);return i.length===r.length&&i.every((function(i){return t(e[i],n[i])}))}(B.value,J.value):void 0);return B.changed=$,B.historyValue=z.historyValue,B.history=J,B},s.prototype.getStateNode=function(t){if(It(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},s.prototype.getStateNodeById=function(t){var e=It(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},s.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&It(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=d(t,this.delimiter).slice(),n=this;e.length;){var i=e.shift();if(!i.length)break;n=n.getStateNode(i)}return n},s.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Vt;switch(this.type){case"parallel":return y(this.initialStateValue,(function(e,i){return e?n.getStateNode(i).resolve(t[i]||e):Vt}));case"compound":if(A(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((e={})[t]=i.initialStateValue,e):t}return h(t).length?y(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Vt})):this.initialStateValue||{};default:return t||Vt}},s.prototype.getResolvedPath=function(t){if(It(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return d(t,this.delimiter)},Object.defineProperty(s.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=g(this.states,(function(t){return t.initialStateValue||Vt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");e=z(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!0,configurable:!0}),s.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(s.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=A(e.target)&&It(e.target)?v(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),s.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(s.prototype,"initialStateNodes",{get:function(){var t=this;return z(this)?[this]:"compound"!==this.type||this.initial?S(x(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!0,configurable:!0}),s.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=r(t),n=e[0],i=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if("history"===o.type)return o.resolveHistory();if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(i)},s.prototype.historyValue=function(t){if(h(this.states).length)return{current:t||this.initialStateValue,states:g(this.states,(function(e,n){if(!t)return e.historyValue();var i=A(t)?void 0:t[n];return e.historyValue(i||e.initialStateValue)}),(function(t){return!t.history}))}},s.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var r=this.target;return r?S(x(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,r=t;try{for(var s=i(o),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return A(s)?[n.getStateNode(s)]:S(x(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(s.prototype,"stateIds",{get:function(){var t=this,e=S(h(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var s=i(h(o)),c=s.next();!c.done;c=s.next()){var u=o[c.value];if(u.states)try{for(var f=(n=void 0,i(u.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!0,configurable:!0}),s.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!A(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var i=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(i);try{return e.parent.getStateNodeByPath(i)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},s.prototype.formatTransition=function(t){var n=this,i=function(t){if(void 0!==t&&t!==u)return b(t)}(t.target),r="internal"in t?t.internal:!i||i.some((function(t){return A(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(i);return e(e({},t),{actions:lt(b(t.actions)),cond:k(t.cond,o),target:a,source:this,internal:r,eventType:t.event})},s.prototype.formatTransitions=function(){var t,e,r,a=this;if(this.config.on)if(Array.isArray(this.config.on))r=this.config.on;else{var s=this.config.on,c=s["*"],u=void 0===c?[]:c,f=n(s,["*"]);r=S(h(f).map((function(t){return U(t,f[t])})).concat(U("*",u)))}else r=[];var l=this.config.onDone?U(String(Et(this.id)),this.config.onDone):[],d=S(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(U(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(U(String(Nt(t.id)),t.onError))),e}))),p=this.after,v=S(o(l,d,r).map((function(t){return b(t).map((function(t){return a.formatTransition(t)}))})));try{for(var y=i(p),g=y.next();!g.done;g=y.next()){var m=g.value;v.push(m)}}catch(e){t={error:e}}finally{try{g&&!g.done&&(e=y.return)&&e.call(y)}finally{if(t)throw t.error}}return v},s}();var Ct,Mt,Rt={deferEvents:!1},Dt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Rt),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Ft=new Map,Ut=0,zt={bookId:function(){return"x:"+Ut++},register:function(t,e){return Ft.set(t,e),t},get:function(t){return Ft.get(t)},free:function(t){Ft.delete(t)}},Jt={sync:!1,autoForward:!1},Bt=(Ct=[],function(t,e){t&&Ct.push(t);var n=e(t||Ct[Ct.length-1]);return t&&Ct.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Mt||(Mt={}));var qt=function(){function n(i,r){var o=this;void 0===r&&(r=n.defaultOptions),this.machine=i,this.scheduler=new Dt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=Mt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(O(t))return o.batch(t),o.state;var n=F(D(t,e));if(o._status===Mt.Stopped)return o.state;if(o._status===Mt.NotStarted&&o.options.deferEvents);else if(o._status!==Mt.Running)throw new Error('Event "'+n.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(n,i){var r=o.parent&&(i===t.SpecialTargets.Parent||o.parent.id===i),a=r?o.parent:At(i)?i:o.children.get(i)||zt.get(i);if(a)"machine"in a?a.send(e(e({},n),{name:n.name===at?""+Nt(o.id):n.name,origin:o.sessionId})):a.send(n.data);else if(!r)throw new Error("Unable to send event to child '"+i+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),r),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:i.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Dt({deferEvents:this.options.deferEvents}),this.sessionId=zt.bookId()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Bt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),n.prototype.execute=function(t,e){var n,r;try{for(var o=i(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,r,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=i(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var p=i(this.listeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t,t.event)}}catch(t){o={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}try{for(var y=i(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=H(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),S=x&&x.data?_(x.data,t.context,e):void 0;try{for(var w=i(this.doneListeners),b=w.next();!b.done;b=w.next()){(0,b.value)(Tt(this.id,S))}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(t){return this.listeners.add(t),this._status===Mt.Running&&t(this.state,this.state.event),this},n.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===Mt.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},n.prototype.start=function(t){var e=this;if(this._status===Mt.Running)return this;zt.register(this.sessionId,this),this.initialized=!0,this._status=Mt.Running;var n=void 0===t?this.initialState:Bt(this,(function(){return!A(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(Pt.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,ut)})),this},n.prototype.stop=function(){var t,e,n,r,o,a,s,c,u,f;try{for(var l=i(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var v=i(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(n)throw n.error}}try{for(var g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var x=i(this.doneListeners),S=x.next();!S.done;S=x.next()){p=S.value;this.doneListeners.delete(p)}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}this.children.forEach((function(t){P(t.stop)&&t.stop()}));try{for(var w=i(h(this.delayedEventsMap)),b=w.next();!b.done;b=w.next()){var _=b.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){u={error:t}}finally{try{b&&!b.done&&(f=w.return)&&f.call(w)}finally{if(u)throw u.error}}return this.scheduler.clear(),this.initialized=!1,this._status=Mt.Stopped,zt.free(this.sessionId),this},n.prototype.batch=function(t){var n=this;if(this._status===Mt.NotStarted&&this.options.deferEvents);else if(this._status!==Mt.Running)throw new Error(t.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var r,a,s=n.state,c=!1,u=[],h=function(t){var i=F(t);n.forward(i),s=Bt(n,(function(){return n.machine.transition(s,i)})),u.push.apply(u,o(s.actions.map((function(t){return i=s,r=(n=t).exec,e(e({},n),{exec:void 0!==r?function(){return r(i.context,i.event,{action:n,state:i,_event:i._event})}:void 0});var n,i,r})))),c=c||!!s.changed};try{for(var f=i(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){r={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(r)throw r.error}}s.changed=c,s.actions=u,n.update(s,F(t[t.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=F(t);if(0===n.name.indexOf(ot)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ot)})))throw n.data.data;return Bt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,i){var r=n.context,o=n._event,a=ht(e.type,i)||e.exec,s=P(a)?a:a?a.exec:e.exec;if(s)try{return s(r,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case Y:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case Z:this.cancel(e.sendId);break;case K:var u=e.activity;if(!this.state.activities[u.type])break;if(u.type===t.ActionTypes.Invoke){var h=this.machine.options.services?this.machine.options.services[u.src]:void 0,f=u.id,l=u.data,d="autoForward"in u?u.autoForward:!!u.forward;if(!h)return;var p=P(h)?h(r,o.data):h;E(p)?this.state.children[f]=this.spawnPromise(Promise.resolve(p),f):P(p)?this.state.children[f]=this.spawnCallback(p,f):V(p)?this.state.children[f]=this.spawnObservable(p,f):j(p)&&(this.state.children[f]=this.spawnMachine(l?p.withContext(_(l,r,o)):p,{id:f,autoForward:d}))}else this.spawnActivity(u);break;case Q:this.stopChild(e.activity.id);break;case nt:var v=e.label,y=e.value;v?this.logger(v,y):this.logger(y)}},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],P(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,i){if(E(t))return this.spawnPromise(Promise.resolve(t),n);if(P(t))return this.spawnCallback(t,n);if(At(t))return this.spawnActor(t);if(V(t))return this.spawnObservable(t,n);if(j(t))return this.spawnMachine(t,e(e({},i),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".')},n.prototype.spawnMachine=function(t,i){var r=this;void 0===i&&(i={});var o=new n(t,e(e({},this.options),{parent:this,id:i.id||t.id})),a=e(e({},Jt),i);a.sync&&o.onTransition((function(t){r.send(st,{state:t,id:o.id})})),o.onDone((function(t){r.send(F(t,{origin:o.id}))})).start();var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),s},n.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||n.send(F(Tt(e,t),{origin:e}))}),(function(t){if(!i){var r=Nt(e,t);try{n.send(F(r,{origin:e}))}catch(t){n.devTools&&n.devTools.send(r,n.state),n.machine.strict&&n.stop()}}}));var r={id:e,send:function(){},subscribe:function(e,n,i){var r=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},n.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),r||i.send(t)}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(E(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){r=!0,P(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(F(t,{origin:e}))}),(function(t){n.send(F(Nt(e,t),{origin:e}))}),(function(){n.send(F(Tt(e),{origin:e}))})),r={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},n.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:e({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[I]=function(){return this},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),n.interpret=Gt,n}(),$t=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},Xt=function(t){return A(t)?e(e({},Jt),{name:t}):e(e(e({},Jt),{name:R()}),t)};function Gt(t,e){return new qt(t,e)}var Ht={raise:pt,send:vt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:nt,label:e,expr:t}},cancel:xt,start:St,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return vt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,i){return yt((function(t,e,i){return{type:at,data:P(n)?n(t,e,i):n}}),e(e({},i),{to:t.SpecialTargets.Parent}))}};t.Interpreter=qt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var i="function"==typeof n?n():n;return new Lt(t,e,i)},t.State=Pt,t.StateNode=Lt,t.actions=Ht,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Lt(t,e,n)},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Gt,t.mapState=function(t,e){var n,r,o;try{for(var a=i(h(t)),s=a.next();!s.done;s=a.next()){var c=s.value;f(c,e)&&(!o||e.length>o.length)&&(o=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Pt.from(t,t instanceof Pt?t.context:void 0);try{for(var c=i(e),u=c.next();!u.done;u=c.next()){var h=r(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=f,t.send=vt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,e){var n=Xt(e);return Bt(void 0,(function(e){return e?e.spawn(t,n.name,n):$t(n.name)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}var a=".",s={},c="xstate.guard",u="";function h(t){return Object.keys(t)}function f(t,e,n){void 0===n&&(n=a);var i=p(t,n),r=p(e,n);return A(r)?!!A(i)&&r===i:A(i)?i in r:h(i).every((function(t){return t in r&&f(i[t],r[t])}))}function l(t){try{return A(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 d(t,e){try{return O(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function p(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:O(t)?v(t):"string"!=typeof t?t:v(d(t,e));var n}function v(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function y(t,e){for(var n={},i=h(t),r=0;r<i.length;r++){var o=i[r];n[o]=e(t[o],o,t,r)}return n}function g(t,e,n){var r,o,a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];n(f)&&(a[u]=e(f,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a}var m=function(t){return function(e){var n,r,o=e;try{for(var a=i(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return o}};function x(t){return t?A(t)?[[t]]:S(h(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?x(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function S(t){var e;return(e=[]).concat.apply(e,o(t))}function w(t){return O(t)?t:[t]}function b(t){return void 0===t?[]:w(t)}function _(t,e,n){var r,o;if(P(t))return t(e,n.data);var a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];P(f)?a[u]=f(e,n.data):a[u]=f}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a}function E(t){return t instanceof Promise||!(null===t||!P(t)&&"object"!=typeof t||!P(t.then))}function T(t,e){var n,o,a=r([[],[]],2),s=a[0],c=a[1];try{for(var u=i(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function N(t,e){return y(t.states,(function(t,n){if(t){var i=(A(e)?void 0:e[n])||(t?t.current:void 0);if(i)return{current:i,states:N(t,i)}}}))}function O(t){return Array.isArray(t)}function P(t){return"function"==typeof t}function A(t){return"string"==typeof t}function k(t,e){if(t)return A(t)?{type:c,name:t,predicate:e?e[t]:void 0}:P(t)?{type:c,name:t.name,predicate:t}:t}function V(t){try{return"subscribe"in t&&P(t.subscribe)}catch(t){return!1}}var j="function"==typeof Symbol&&Symbol.observable||"@@observable";function I(t){try{return"__xstatenode"in t}catch(t){return!1}}var L,C,M,R=(L=0,function(){return(++L).toString(16)});function D(t,n){return A(t)||"number"==typeof t?e({type:t},n):t}function F(t,n){if(!A(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var i=D(t);return e({name:i.type,data:i,$$type:"scxml",type:"external"},n)}function U(t,n){return w(n).map((function(n){return void 0===n||"string"==typeof n||I(n)?{target:n,event:t}:e(e({},n),{event:t})}))}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",(M=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",M.Internal="#_internal";var z=function(t){return"atomic"===t.type||"final"===t.type};function J(t){return h(t.states).map((function(e){return t.states[e]}))}function B(t){var e=[t];return z(t)?e:e.concat(S(J(t).map(B)))}function q(t,e){var n,r,o,a,s,c,u,h,f=$(new Set(t)),l=new Set(e);try{for(var d=i(l),p=d.next();!p.done;p=d.next())for(var v=(E=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=$(l);try{for(var g=i(l),m=g.next();!m.done;m=g.next()){if("compound"!==(E=m.value).type||y.get(E)&&y.get(E).length){if("parallel"===E.type)try{for(var x=(s=void 0,i(J(E))),S=x.next();!S.done;S=x.next()){var w=S.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=i(l),_=b.next();!_.done;_=b.next()){var E;for(v=(E=_.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function $(t){var e,n,r=new Map;try{for(var o=i(t),a=o.next();!a.done;a=o.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}function X(t,e){return function t(e,n){var i=n.get(e);if(!i)return{};if("compound"===e.type){var r=i[0];if(!r)return{};if(z(r))return r.key}var o={};return i.forEach((function(e){o[e.key]=t(e,n)})),o}(t,$(q([t],e)))}function G(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function H(t,e){return"compound"===e.type?J(e).some((function(e){return"final"===e.type&&G(t,e)})):"parallel"===e.type&&J(e).every((function(e){return H(t,e)}))}var K=t.ActionTypes.Start,Q=t.ActionTypes.Stop,W=t.ActionTypes.Raise,Y=t.ActionTypes.Send,Z=t.ActionTypes.Cancel,tt=t.ActionTypes.NullEvent,et=t.ActionTypes.Assign,nt=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),it=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,ot=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),at=t.ActionTypes.ErrorCustom,st=t.ActionTypes.Update,ct=t.ActionTypes.Pure,ut=F({type:it});function ht(t,e){return e&&e[t]||void 0}function ft(t,i){var r;if(A(t)||"number"==typeof t){var o=ht(t,i);r=P(o)?{type:t,exec:o}:o||{type:t,exec:void 0}}else if(P(t))r={type:t.name||t.toString(),exec:t};else{if(P(o=ht(t.type,i)))r=e(e({},t),{exec:o});else if(o){var a=t.type,s=n(t,["type"]);r=e(e({type:a},o),s)}else r=t}return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var lt=function(t,e){return t?(O(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:A(t)?t:n.id},n),{type:n.type})}function pt(e){return A(e)?{type:W,event:e}:vt(e,{to:t.SpecialTargets.Internal})}function vt(t,e){return{to:e?e.to:void 0,type:Y,event:P(t)?t:D(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:P(t)?t.name:l(t)}}function yt(n,i){return vt(n,e(e({},i),{to:t.SpecialTargets.Parent}))}function gt(){return yt(st)}var mt=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Z,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:et,assignment:t}};function _t(e,n){var i=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+i}function Et(e,n){var i=t.ActionTypes.DoneState+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Tt(e,n){var i=t.ActionTypes.DoneInvoke+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Nt(e,n){var i=t.ActionTypes.ErrorPlatform+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Ot(t,n){return vt((function(t,e){return e}),e(e({},n),{to:t}))}var Pt=function(){function t(t){var e=this;this.actions=[],this.activities=s,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||s,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return t=e.configuration,S(o(new Set(t.map((function(t){return t.ownEvents})))));var t}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=ut;return new t({value:e.value,context:n,_event:i,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),A(t))return[t];var i=h(t);return i.concat.apply(i,o(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;return n(this,["configuration","transitions"])},t.prototype.matches=function(t){return f(t,this.value)},t}();function At(t){try{return"function"==typeof t.send}catch(t){return!1}}var kt="",Vt={},jt=function(t){return"#"===t[0]},It=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Lt=function(){function s(t,n,r){var c=this;this.config=t,this.context=r,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign(It(),n),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:a),this.id=this.config.id||o([this.machine.key],this.path).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&h(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?y(this.config.states,(function(t,n){var i,r=new s(t,{_parent:c,_key:n});return Object.assign(c.idMap,e(((i={})[r.id]=r,i),r.idMap)),r})):Vt;var u=0;!function t(e){var n,r;e.order=u++;try{for(var o=i(J(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return t.event===kt})):kt in this.config.on),this.strict=!!this.config.strict,this.onEntry=b(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=b(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=b(this.config.invoke).map((function(t,n){var i,r;if(I(t))return c.machine.options.services=e(((i={})[t.id]=t,i),c.machine.options.services),{type:rt,src:t.id,id:t.id};if("string"!=typeof t.src){var o=c.id+":invocation["+n+"]";return c.machine.options.services=e(((r={})[o]=t.src,r),c.machine.options.services),e(e({type:rt,id:o},t),{src:o})}return e(e({},t),{type:rt,id:t.id||t.src,src:t.src})})),this.activities=b(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this)}return s.prototype._init=function(){this.__cache.transitions||B(this).forEach((function(t){return t.on}))},s.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var i=this.options,r=i.actions,o=i.activities,a=i.guards,c=i.services,u=i.delays;return new s(this.config,{actions:e(e({},r),t.actions),activities:e(e({},o),t.activities),guards:e(e({},a),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},n)},s.prototype.withContext=function(t){return new s(this.config,this.options,t)},Object.defineProperty(s.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:y(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}},enumerable:!0,configurable:!0}),s.prototype.toJSON=function(){return this.definition},Object.defineProperty(s.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!0,configurable:!0}),s.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=t===kt,n=this.transitions.filter((function(n){var i=n.eventType===t;return e?i:i||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},s.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var i=function(e,n){var i=_t(P(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(i,{delay:e})),t.onExit.push(xt(i)),i};return(O(n)?n.map((function(t,n){var r=i(t.delay,n);return e(e({},t),{event:r})})):S(h(n).map((function(t,r){var o=n[t],a=A(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=i(s,r);return b(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var i=n.delay;return e(e({},t.formatTransition(n)),{delay:i})}))},s.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var i=t instanceof Pt?t.value:p(t,this.delimiter);if(A(i)){var r=this.getStateNode(i).initial;return void 0!==r?this.getStateNodes(((e={})[i]=r,e)):[this.states[i]]}var o=h(i);return o.map((function(t){return n.getStateNode(t)})).concat(o.reduce((function(t,e){var r=n.getStateNode(e).getStateNodes(i[e]);return t.concat(r)}),[]))},s.prototype.handles=function(t){var e=l(t);return this.events.includes(e)},s.prototype.resolveState=function(t){var n=Array.from(q([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n}))},s.prototype.transitionLeafNode=function(t,e,n){var i=this.getStateNode(t).next(e,n);return i&&i.transitions.length?i:this.next(e,n)},s.prototype.transitionCompoundNode=function(t,e,n){var i=h(t),r=this.getStateNode(i[0])._transition(t[i[0]],e,n);return r&&r.transitions.length?r:this.next(e,n)},s.prototype.transitionParallelNode=function(t,e,n){var r,o,a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];if(f){var l=this.getStateNode(u)._transition(f,e,n);l&&(a[u]=l)}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}var d=h(a).map((function(t){return a[t]})),p=S(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=S(d.map((function(t){return t.entrySet}))),y=S(h(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:S(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:S(h(a).map((function(t){return a[t].actions})))}},s.prototype._transition=function(t,e,n){return A(t)?this.transitionLeafNode(t,e,n):1===h(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},s.prototype.next=function(t,e){var n,r,a,s=this,c=e.name,u=[],h=[];try{for(var l=i(this.getCandidates(c)),d=l.next();!d.done;d=l.next()){var v=d.value,y=v.cond,g=v.in,x=t.context,w=!g||(A(g)&&jt(g)?t.matches(p(this.getStateNodeById(g).path,this.delimiter)):f(p(g,this.delimiter),m(this.path.slice(0,-2))(t.value))),b=!1;try{b=!y||this.evaluateGuard(y,x,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(y.name||y.type)+"' in transition for event '"+c+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==v.target&&(h=v.target),u.push.apply(u,o(v.actions)),a=v;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(a){if(!h.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:u};var _=S(h.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:S(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:u}}},s.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},s.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},s.prototype.evaluateGuard=function(t,e,n,i){var r=this.machine.options.guards,o={state:i,cond:t,_event:n};if(t.type===c)return t.predicate(e,n.data,o);var a=r[t.type];if(!a)throw new Error("Guard '"+t.type+"' is not implemented on machine '"+this.machine.id+"'.");return a(e,n.data,o)},s.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=q([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?q(f,t.configuration):f;try{for(var d=i(l),p=d.next();!p.done;p=d.next()){G(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=i(f),y=v.next();!y.done;y=v.next()){var g;G(l,g=y.value)&&!G(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var m=S(t.entrySet.map((function(i){var r=[];if("final"!==i.type)return r;var o=i.parent;if(r.push(Et(i.id,i.data),Et(o.id,i.data?_(i.data,e,n):void 0)),o.parent){var a=o.parent;"parallel"===a.type&&J(a).every((function(e){return H(t.configuration,e)}))&&r.push(Et(a.id,a.data))}return r})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var x=new Set(t.entrySet),w=new Set(t.exitSet),b=r([S(Array.from(x).map((function(t){return o(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(m.map(pt)),S(Array.from(w).map((function(t){return o(t.onExit,t.activities.map((function(t){return wt(t)})))})))],2),E=b[0],T=b[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},s.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var i,r,a=F(e);if(t instanceof Pt)i=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=A(t)?this.resolve(v(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;i=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(r=a.name,!/^(done|error)\./.test(r)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(i.value,i,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:i,actions:[]},h=q([],this.getStateNodes(i.value)),f=u.configuration.length?q(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,i,a)},s.prototype.resolveRaisedTransition=function(t,e,n){var i,r=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(i=t.actions).unshift.apply(i,o(r)),t},s.prototype.resolveTransition=function(n,o,a,s){var c,u,f=this;void 0===a&&(a=ut),void 0===s&&(s=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0?X(this.machine,l):void 0,p=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,v=o?o.context:s,y=this.getActions(n,v,a,o),g=o?e({},o.activities):{};try{for(var m=i(y),x=m.next();!x.done;x=m.next()){var w=x.value;w.type===K?g[w.activity.type]=w:w.type===Q&&(g[w.activity.type]=!1)}}catch(t){c={error:t}}finally{try{x&&!x.done&&(u=m.return)&&u.call(m)}finally{if(c)throw c.error}}var b,_,E=r(T(y,(function(t){return t.type===et})),2),O=E[0],k=E[1],V=O.length?function(t,e,n,r){return t?n.reduce((function(t,n){var o,a,s=n.assignment,c={state:r,action:n,_event:e},u={};if(P(s))u=s(t,e.data,c);else try{for(var f=i(h(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[d];u[d]=P(p)?p(t,e.data,c):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,u)}),t):t}(v,a,O,o):v,j=S(k.map((function(t){switch(t.type){case W:return function(t){return{type:W,_event:F(t.event)}}(t);case Y:return function(t,n,i,r){var o,a={_event:i},s=F(P(t.event)?t.event(n,i.data,a):t.event);if(A(t.delay)){var c=r&&r[t.delay];o=P(c)?c(n,i.data,a):c}else o=P(t.delay)?t.delay(n,i.data,a):t.delay;var u=P(t.to)?t.to(n,i.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(t,V,a,f.machine.options.delays);case nt:return function(t,n,i){return e(e({},t),{value:A(t.expr)?t.expr:t.expr(n,i.data,{_event:i})})}(t,V,a);case ct:return t.get(V,a.data)||[];default:return ft(t,f.options.actions)}}))),I=r(T(j,(function(e){return e.type===W||e.type===Y&&e.to===t.SpecialTargets.Internal})),2),L=I[0],C=I[1],M=j.filter((function(t){return t.type===K&&t.activity.type===rt})).reduce((function(t,e){var n,i,r;return t[e.activity.id]=(n=e.activity,(r={id:i=n.id,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:i}}}).meta=n,r),t}),o?e({},o.children):{}),R=d?n.configuration:o?o.configuration:[],D=R.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),U=H(R,this),z=new Pt({value:d||o.value,context:V,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?p?(b=p,_=d,{current:_,states:N(b,_)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?C:[],activities:d?g:o?o.activities:{},meta:d?D:o?o.meta:void 0,events:[],configuration:R,transitions:n.transitions,children:M,done:U});z.changed=a.name===st||!!O.length;var J=z.history;if(J&&delete J.history,!d)return z;var B=z;if(!U)for((this._transient||l.some((function(t){return t._transient})))&&(B=this.resolveRaisedTransition(B,{type:tt},a));L.length;){var q=L.shift();B=this.resolveRaisedTransition(B,q._event,a)}var $=B.changed||(J?!!B.actions.length||!!O.length||typeof J.value!=typeof B.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(A(e)||A(n))return e===n;var i=h(e),r=h(n);return i.length===r.length&&i.every((function(i){return t(e[i],n[i])}))}(B.value,J.value):void 0);return B.changed=$,B.historyValue=z.historyValue,B.history=J,B},s.prototype.getStateNode=function(t){if(jt(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},s.prototype.getStateNodeById=function(t){var e=jt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},s.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&jt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=d(t,this.delimiter).slice(),n=this;e.length;){var i=e.shift();if(!i.length)break;n=n.getStateNode(i)}return n},s.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Vt;switch(this.type){case"parallel":return y(this.initialStateValue,(function(e,i){return e?n.getStateNode(i).resolve(t[i]||e):Vt}));case"compound":if(A(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((e={})[t]=i.initialStateValue,e):t}return h(t).length?y(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Vt})):this.initialStateValue||{};default:return t||Vt}},s.prototype.getResolvedPath=function(t){if(jt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return d(t,this.delimiter)},Object.defineProperty(s.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=g(this.states,(function(t){return t.initialStateValue||Vt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");e=z(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!0,configurable:!0}),s.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(s.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=A(e.target)&&jt(e.target)?v(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),s.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(s.prototype,"initialStateNodes",{get:function(){var t=this;return z(this)?[this]:"compound"!==this.type||this.initial?S(x(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!0,configurable:!0}),s.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=r(t),n=e[0],i=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if("history"===o.type)return o.resolveHistory();if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(i)},s.prototype.historyValue=function(t){if(h(this.states).length)return{current:t||this.initialStateValue,states:g(this.states,(function(e,n){if(!t)return e.historyValue();var i=A(t)?void 0:t[n];return e.historyValue(i||e.initialStateValue)}),(function(t){return!t.history}))}},s.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var r=this.target;return r?S(x(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,r=t;try{for(var s=i(o),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return A(s)?[n.getStateNode(s)]:S(x(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(s.prototype,"stateIds",{get:function(){var t=this,e=S(h(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var s=i(h(o)),c=s.next();!c.done;c=s.next()){var u=o[c.value];if(u.states)try{for(var f=(n=void 0,i(u.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!0,configurable:!0}),s.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!A(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var i=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(i);try{return e.parent.getStateNodeByPath(i)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},s.prototype.formatTransition=function(t){var n=this,i=function(t){if(void 0!==t&&t!==u)return b(t)}(t.target),r="internal"in t?t.internal:!i||i.some((function(t){return A(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(i),s=e(e({},t),{actions:lt(b(t.actions)),cond:k(t.cond,o),target:a,source:this,internal:r,eventType:t.event});return Object.defineProperty(s,"toJSON",{value:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#{this.id}"})}}),s},s.prototype.formatTransitions=function(){var t,e,r,a=this;if(this.config.on)if(Array.isArray(this.config.on))r=this.config.on;else{var s=this.config.on,c=s["*"],u=void 0===c?[]:c,f=n(s,["*"]);r=S(h(f).map((function(t){return U(t,f[t])})).concat(U("*",u)))}else r=[];var l=this.config.onDone?U(String(Et(this.id)),this.config.onDone):[],d=S(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(U(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(U(String(Nt(t.id)),t.onError))),e}))),p=this.after,v=S(o(l,d,r).map((function(t){return b(t).map((function(t){return a.formatTransition(t)}))})));try{for(var y=i(p),g=y.next();!g.done;g=y.next()){var m=g.value;v.push(m)}}catch(e){t={error:e}}finally{try{g&&!g.done&&(e=y.return)&&e.call(y)}finally{if(t)throw t.error}}return v},s}();var Ct,Mt,Rt={deferEvents:!1},Dt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Rt),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Ft=new Map,Ut=0,zt={bookId:function(){return"x:"+Ut++},register:function(t,e){return Ft.set(t,e),t},get:function(t){return Ft.get(t)},free:function(t){Ft.delete(t)}},Jt={sync:!1,autoForward:!1},Bt=(Ct=[],function(t,e){t&&Ct.push(t);var n=e(t||Ct[Ct.length-1]);return t&&Ct.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Mt||(Mt={}));var qt=function(){function n(i,r){var o=this;void 0===r&&(r=n.defaultOptions),this.machine=i,this.scheduler=new Dt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=Mt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(O(t))return o.batch(t),o.state;var n=F(D(t,e));if(o._status===Mt.Stopped)return o.state;if(o._status===Mt.NotStarted&&o.options.deferEvents);else if(o._status!==Mt.Running)throw new Error('Event "'+n.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(n,i){var r=o.parent&&(i===t.SpecialTargets.Parent||o.parent.id===i),a=r?o.parent:At(i)?i:o.children.get(i)||zt.get(i);if(a)"machine"in a?a.send(e(e({},n),{name:n.name===at?""+Nt(o.id):n.name,origin:o.sessionId})):a.send(n.data);else if(!r)throw new Error("Unable to send event to child '"+i+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),r),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:i.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Dt({deferEvents:this.options.deferEvents}),this.sessionId=zt.bookId()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Bt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),n.prototype.execute=function(t,e){var n,r;try{for(var o=i(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,r,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=i(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var p=i(this.listeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t,t.event)}}catch(t){o={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}try{for(var y=i(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=H(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),S=x&&x.data?_(x.data,t.context,e):void 0;try{for(var w=i(this.doneListeners),b=w.next();!b.done;b=w.next()){(0,b.value)(Tt(this.id,S))}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(t){return this.listeners.add(t),this._status===Mt.Running&&t(this.state,this.state.event),this},n.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===Mt.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},n.prototype.start=function(t){var e=this;if(this._status===Mt.Running)return this;zt.register(this.sessionId,this),this.initialized=!0,this._status=Mt.Running;var n=void 0===t?this.initialState:Bt(this,(function(){return!A(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(Pt.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,ut)})),this},n.prototype.stop=function(){var t,e,n,r,o,a,s,c,u,f;try{for(var l=i(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var v=i(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(n)throw n.error}}try{for(var g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var x=i(this.doneListeners),S=x.next();!S.done;S=x.next()){p=S.value;this.doneListeners.delete(p)}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}this.children.forEach((function(t){P(t.stop)&&t.stop()}));try{for(var w=i(h(this.delayedEventsMap)),b=w.next();!b.done;b=w.next()){var _=b.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){u={error:t}}finally{try{b&&!b.done&&(f=w.return)&&f.call(w)}finally{if(u)throw u.error}}return this.scheduler.clear(),this.initialized=!1,this._status=Mt.Stopped,zt.free(this.sessionId),this},n.prototype.batch=function(t){var n=this;if(this._status===Mt.NotStarted&&this.options.deferEvents);else if(this._status!==Mt.Running)throw new Error(t.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var r,a,s=n.state,c=!1,u=[],h=function(t){var i=F(t);n.forward(i),s=Bt(n,(function(){return n.machine.transition(s,i)})),u.push.apply(u,o(s.actions.map((function(t){return i=s,r=(n=t).exec,e(e({},n),{exec:void 0!==r?function(){return r(i.context,i.event,{action:n,state:i,_event:i._event})}:void 0});var n,i,r})))),c=c||!!s.changed};try{for(var f=i(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){r={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(r)throw r.error}}s.changed=c,s.actions=u,n.update(s,F(t[t.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=F(t);if(0===n.name.indexOf(ot)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ot)})))throw n.data.data;return Bt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,i){var r=n.context,o=n._event,a=ht(e.type,i)||e.exec,s=P(a)?a:a?a.exec:e.exec;if(s)try{return s(r,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case Y:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case Z:this.cancel(e.sendId);break;case K:var u=e.activity;if(!this.state.activities[u.type])break;if(u.type===t.ActionTypes.Invoke){var h=this.machine.options.services?this.machine.options.services[u.src]:void 0,f=u.id,l=u.data,d="autoForward"in u?u.autoForward:!!u.forward;if(!h)return;var p=P(h)?h(r,o.data):h;E(p)?this.state.children[f]=this.spawnPromise(Promise.resolve(p),f):P(p)?this.state.children[f]=this.spawnCallback(p,f):V(p)?this.state.children[f]=this.spawnObservable(p,f):I(p)&&(this.state.children[f]=this.spawnMachine(l?p.withContext(_(l,r,o)):p,{id:f,autoForward:d}))}else this.spawnActivity(u);break;case Q:this.stopChild(e.activity.id);break;case nt:var v=e.label,y=e.value;v?this.logger(v,y):this.logger(y)}},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],P(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,i){if(E(t))return this.spawnPromise(Promise.resolve(t),n);if(P(t))return this.spawnCallback(t,n);if(At(t))return this.spawnActor(t);if(V(t))return this.spawnObservable(t,n);if(I(t))return this.spawnMachine(t,e(e({},i),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".')},n.prototype.spawnMachine=function(t,i){var r=this;void 0===i&&(i={});var o=new n(t,e(e({},this.options),{parent:this,id:i.id||t.id})),a=e(e({},Jt),i);a.sync&&o.onTransition((function(t){r.send(st,{state:t,id:o.id})})),o.onDone((function(t){r.send(F(t,{origin:o.id}))})).start();var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),s},n.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||n.send(F(Tt(e,t),{origin:e}))}),(function(t){if(!i){var r=Nt(e,t);try{n.send(F(r,{origin:e}))}catch(t){n.devTools&&n.devTools.send(r,n.state),n.machine.strict&&n.stop()}}}));var r={id:e,send:function(){},subscribe:function(e,n,i){var r=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},n.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),r||i.send(t)}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(E(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){r=!0,P(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(F(t,{origin:e}))}),(function(t){n.send(F(Nt(e,t),{origin:e}))}),(function(){n.send(F(Tt(e),{origin:e}))})),r={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},n.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:e({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[j]=function(){return this},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),n.interpret=Gt,n}(),$t=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},Xt=function(t){return A(t)?e(e({},Jt),{name:t}):e(e(e({},Jt),{name:R()}),t)};function Gt(t,e){return new qt(t,e)}var Ht={raise:pt,send:vt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:nt,label:e,expr:t}},cancel:xt,start:St,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return vt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,i){return yt((function(t,e,i){return{type:at,data:P(n)?n(t,e,i):n}}),e(e({},i),{to:t.SpecialTargets.Parent}))}};t.Interpreter=qt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var i="function"==typeof n?n():n;return new Lt(t,e,i)},t.State=Pt,t.StateNode=Lt,t.actions=Ht,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Lt(t,e,n)},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Gt,t.mapState=function(t,e){var n,r,o;try{for(var a=i(h(t)),s=a.next();!s.done;s=a.next()){var c=s.value;f(c,e)&&(!o||e.length>o.length)&&(o=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Pt.from(t,t instanceof Pt?t.context:void 0);try{for(var c=i(e),u=c.next();!u.done;u=c.next()){var h=r(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=f,t.send=vt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,e){var n=Xt(e);return Bt(void 0,(function(e){return e?e.spawn(t,n.name,n):$t(n.name)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -1,4 +1,4 @@
1
- const t=".",e={},i="xstate.guard",s="";function n(t){return Object.keys(t)}function o(e,i,s=t){const r=c(e,s),a=c(i,s);return x(a)?!!x(r)&&a===r:x(r)?r in a:n(r).every(t=>t in a&&o(r[t],a[t]))}function r(t){try{return x(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 a(t,e){try{return w(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function c(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(w(t))return h(t);if("string"!=typeof t)return t;return h(a(t,e))}function h(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function d(t,e){const i={},s=n(t);for(let n=0;n<s.length;n++){const o=s[n];i[o]=e(t[o],o,t,n)}return i}function u(t,e,i){const s={};for(const o of n(t)){const n=t[o];i(n)&&(s[o]=e(n,o,t))}return s}const l=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function f(t){if(!t)return[[]];if(x(t))return[[t]];return p(n(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?f(t[e]).map(t=>[e].concat(t)):[[e]]}))}function p(t){return[].concat(...t)}function v(t){return w(t)?t:[t]}function g(t){return void 0===t?[]:v(t)}function y(t,e,i){if(_(t))return t(e,i.data);const s={};for(const o of n(t)){const n=t[o];_(n)?s[o]=n(e,i.data):s[o]=n}return s}function m(t){return t instanceof Promise||!(null===t||!_(t)&&"object"!=typeof t||!_(t.then))}function b(t,e){const[i,s]=[[],[]];for(const n of t)e(n)?i.push(n):s.push(n);return[i,s]}function S(t,e){return d(t.states,(t,i)=>{if(!t)return;const s=(x(e)?void 0:e[i])||(t?t.current:void 0);return s?{current:s,states:S(t,s)}:void 0})}function w(t){return Array.isArray(t)}function _(t){return"function"==typeof t}function x(t){return"string"==typeof t}function O(t,e){if(t)return x(t)?{type:i,name:t,predicate:e?e[t]:void 0}:_(t)?{type:i,name:t.name,predicate:t}:t}function E(t){try{return"subscribe"in t&&_(t.subscribe)}catch(t){return!1}}const j=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function N(t){try{return"__xstatenode"in t}catch(t){return!1}}const $=(()=>{let t=0;return()=>(++t).toString(16)})();function T(t,e){return x(t)||"number"==typeof t?Object.assign({type:t},e):t}function k(t,e){if(!x(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=T(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function P(t,e){return v(e).map(e=>void 0===e||"string"==typeof e||N(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function V(t,e){let i;for(const s of n(t))o(s,e)&&(!i||e.length>i.length)&&(i=s);return t[i]}
1
+ const t=".",e={},i="xstate.guard",s="";function n(t){return Object.keys(t)}function o(e,i,s=t){const r=c(e,s),a=c(i,s);return x(a)?!!x(r)&&a===r:x(r)?r in a:n(r).every(t=>t in a&&o(r[t],a[t]))}function r(t){try{return x(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 a(t,e){try{return w(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function c(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(w(t))return h(t);if("string"!=typeof t)return t;return h(a(t,e))}function h(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function d(t,e){const i={},s=n(t);for(let n=0;n<s.length;n++){const o=s[n];i[o]=e(t[o],o,t,n)}return i}function u(t,e,i){const s={};for(const o of n(t)){const n=t[o];i(n)&&(s[o]=e(n,o,t))}return s}const l=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function f(t){if(!t)return[[]];if(x(t))return[[t]];return p(n(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?f(t[e]).map(t=>[e].concat(t)):[[e]]}))}function p(t){return[].concat(...t)}function g(t){return w(t)?t:[t]}function v(t){return void 0===t?[]:g(t)}function y(t,e,i){if(_(t))return t(e,i.data);const s={};for(const o of n(t)){const n=t[o];_(n)?s[o]=n(e,i.data):s[o]=n}return s}function m(t){return t instanceof Promise||!(null===t||!_(t)&&"object"!=typeof t||!_(t.then))}function b(t,e){const[i,s]=[[],[]];for(const n of t)e(n)?i.push(n):s.push(n);return[i,s]}function S(t,e){return d(t.states,(t,i)=>{if(!t)return;const s=(x(e)?void 0:e[i])||(t?t.current:void 0);return s?{current:s,states:S(t,s)}:void 0})}function w(t){return Array.isArray(t)}function _(t){return"function"==typeof t}function x(t){return"string"==typeof t}function O(t,e){if(t)return x(t)?{type:i,name:t,predicate:e?e[t]:void 0}:_(t)?{type:i,name:t.name,predicate:t}:t}function E(t){try{return"subscribe"in t&&_(t.subscribe)}catch(t){return!1}}const j=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function N(t){try{return"__xstatenode"in t}catch(t){return!1}}const $=(()=>{let t=0;return()=>(++t).toString(16)})();function T(t,e){return x(t)||"number"==typeof t?Object.assign({type:t},e):t}function k(t,e){if(!x(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=T(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function P(t,e){return g(e).map(e=>void 0===e||"string"==typeof e||N(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function V(t,e){let i;for(const s of n(t))o(s,e)&&(!i||e.length>i.length)&&(i=s);return t[i]}
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation. All rights reserved.
4
4
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
12
12
 
13
13
  See the Apache Version 2.0 License for specific language governing permissions
14
14
  and limitations under the License.
15
- ***************************************************************************** */function I(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var L,C;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure"}(L||(L={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(C||(C={}));const A=t=>"atomic"===t.type||"final"===t.type;function R(t){return n(t.states).map(e=>t.states[e])}function M(t){const e=[t];return A(t)?e:e.concat(p(R(t).map(M)))}function D(t,e){const i=F(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=F(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of R(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function F(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(A(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,F(D([t],e)))}function U(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?R(e).some(e=>"final"===e.type&&U(t,e)):"parallel"===e.type&&R(e).every(e=>J(t,e))}const B=L.Start,q=L.Stop,X=L.Raise,G=L.Send,H=L.Cancel,K=L.NullEvent,Q=L.Assign,W=(L.After,L.DoneState,L.Log),Y=L.Init,Z=L.Invoke,tt=(L.ErrorExecution,L.ErrorPlatform),et=L.ErrorCustom,it=L.Update,st=L.Pure,nt=k({type:Y});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(x(t)||"number"==typeof t){const s=ot(t,e);i=_(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(_(t))i={type:t.name||t.toString(),exec:t};else{const s=ot(t.type,e);if(_(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const{type:e}=t,n=I(t,["type"]);i=Object.assign(Object.assign({type:e},s),n)}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(w(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:x(t)?t:e.id},e),{type:e.type})}function ht(t){return x(t)?{type:X,event:t}:dt(t,{to:C.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:G,event:_(t)?t:T(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:_(t)?t.name:r(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:C.Parent}))}function lt(){return ut(it)}const ft=(t,e)=>({context:t,event:e});const pt=(t,e,i)=>Object.assign(Object.assign({},t),{value:x(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),vt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:L.Start,activity:e,exec:void 0}}function yt(t){const e=ct(t);return{type:L.Stop,activity:e,exec:void 0}}const mt=t=>({type:Q,assignment:t});function bt(t,e){const i=e?`#${e}`:"";return`${L.After}(${t})${i}`}function St(t,e){const i=`${L.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){const i=`${L.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function _t(t,e){const i=`${L.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Et{constructor(t){this.actions=[],this.activities=e,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||e,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:()=>(function(t){return p([...new Set(t.map(t=>t.ownEvents))])})(t.configuration)})}static from(t,e){if(t instanceof Et)return t.context!==e?new Et({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Et({value:t,context:e,_event:nt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Et(t)}static inert(t,e){if(t instanceof Et){if(!t.actions.length)return t;const i=nt;return new Et({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Et.from(t,e)}toStrings(t=this.value,e="."){if(x(t))return[t];const i=n(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){return I(this,["configuration","transitions"])}matches(t){return o(t,this.value)}}function jt(t){try{return"function"==typeof t.send}catch(t){return!1}}const Nt="",$t="#",Tt="*",kt={},Pt=t=>t[0]===$t,Vt=()=>({actions:{},guards:{},services:{},activities:{},delays:{}});class It{constructor(e,i,s){this.config=e,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign(Vt(),i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:t),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&n(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):kt;let o=0;!function t(e){e.order=o++;for(const i of R(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>t===Nt):Nt in this.config.on),this.strict=!!this.config.strict,this.onEntry=g(this.config.entry||this.config.onEntry).map(t=>rt(t)),this.onExit=g(this.config.exit||this.config.onExit).map(t=>rt(t)),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=g(this.config.invoke).map((t,e)=>{if(N(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),{type:Z,src:t.id,id:t.id};if("string"!=typeof t.src){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Object.assign(Object.assign({type:Z,id:i},t),{src:i})}return Object.assign(Object.assign({},t),{type:Z,id:t.id||t.src,src:t.src})}),this.activities=g(this.config.activities).concat(this.invoke).map(t=>ct(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||M(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,type:this.type,initial:this.initial,history:this.history,states:d(this.states,t=>t.definition),on:this.on,transitions:this.transitions,onEntry:this.onEntry,onExit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=t===Nt,i=this.transitions.filter(i=>{const s=i.eventType===t;return e?s:s||i.eventType===Tt});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=bt(_(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(vt(i)),i};return(w(t)?t.map((t,i)=>{const s=e(t.delay,i);return Object.assign(Object.assign({},t),{event:s})}):p(n(t).map((i,s)=>{const n=t[i],o=x(n)?{target:n}:n,r=isNaN(+i)?i:+i,a=e(r,s);return g(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const e=t instanceof Et?t.value:c(t,this.delimiter);if(x(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this.states[e]]}const i=n(e);return i.map(t=>this.getStateNode(t)).concat(i.reduce((t,i)=>{const s=this.getStateNode(i).getStateNodes(e[i]);return t.concat(s)},[]))}handles(t){const e=r(t);return this.events.includes(e)}resolveState(t){const e=Array.from(D([],this.getStateNodes(t.value)));return new Et(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,e,i){const s=n(t),o=this.getStateNode(s[0])._transition(t[s[0]],e,i);return o&&o.transitions.length?o:this.next(e,i)}transitionParallelNode(t,e,i){const s={};for(const o of n(t)){const n=t[o];if(!n)continue;const r=this.getStateNode(o)._transition(n,e,i);r&&(s[o]=r)}const o=n(s).map(t=>s[t]),r=p(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(e,i);const a=p(o.map(t=>t.entrySet)),c=p(n(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:p(o.map(t=>t.exitSet)),configuration:c,source:e,actions:p(n(s).map(t=>s[t].actions))}}_transition(t,e,i){return x(t)?this.transitionLeafNode(t,e,i):1===n(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}next(t,e){const i=e.name,s=[];let n,r=[];for(const a of this.getCandidates(i)){const{cond:h,in:d}=a,u=t.context,f=!d||(x(d)&&Pt(d)?t.matches(c(this.getStateNodeById(d).path,this.delimiter)):o(c(d,this.delimiter),l(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!h||this.evaluateGuard(h,u,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${h.name||h.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==a.target&&(r=a.target),s.push(...a.actions),n=a;break}}if(!n)return;if(!r.length)return{transitions:[n],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const a=p(r.map(e=>this.getRelativeStateNodes(e,t.historyValue))),h=!!n.internal;return{transitions:[n],entrySet:h?[]:p(a.map(t=>this.nodesFromChild(t))),exitSet:h?[]:[this],configuration:a,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}evaluateGuard(t,e,s,n){const{guards:o}=this.machine.options,r={state:n,cond:t,_event:s};if(t.type===i)return t.predicate(e,s.data,r);const a=o[t.type];if(!a)throw new Error(`Guard '${t.type}' is not implemented on machine '${this.machine.id}'.`);return a(e,s.data,r)}getActions(t,e,i,s){const n=D([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?D(n,t.configuration):n;for(const e of o)U(n,e)||t.entrySet.push(e);for(const e of n)U(o,e)&&!U(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=p(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(n.push(St(s.id,s.data),St(o.id,s.data?y(s.data,e,i):void 0)),o.parent){const e=o.parent;"parallel"===e.type&&R(e).every(e=>J(t.configuration,e))&&n.push(St(e.id,e.data))}return n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[p(Array.from(a).map(t=>[...t.activities.map(t=>gt(t)),...t.onEntry])).concat(r.map(ht)),p(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>yt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=k(e);let n;if(t instanceof Et)n=void 0===i?t:this.resolveState(Et.from(t,i));else{const e=x(t)?this.resolve(h(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(Et.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const r=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},a=D([],this.getStateNodes(n.value)),c=r.configuration.length?D(a,r.configuration):a;return r.configuration=[...c],this.resolveTransition(r,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,e,i=nt,s=this.machine.context){const{configuration:o}=t,r=!e||t.transitions.length>0?z(this.machine,o):void 0,a=e?e.historyValue?e.historyValue:t.source?this.machine.historyValue(e.value):void 0:void 0,c=e?e.context:s,h=this.getActions(t,c,i,e),d=e?Object.assign({},e.activities):{};for(const t of h)t.type===B?d[t.activity.type]=t:t.type===q&&(d[t.activity.type]=!1);const[u,l]=b(h,t=>t.type===Q),f=u.length?function(t,e,i,s){return t?i.reduce((t,i)=>{const{assignment:o}=i,r={state:s,action:i,_event:e};let a={};if(_(o))a=o(t,e.data,r);else for(const i of n(o)){const s=o[i];a[i]=_(s)?s(t,e.data,r):s}return Object.assign({},t,a)},t):t}(c,i,u,e):c,v=p(l.map(t=>{switch(t.type){case X:return function(t){return{type:X,_event:k(t.event)}}(t);case G:return function(t,e,i,s){const n={_event:i},o=k(_(t.event)?t.event(e,i.data,n):t.event);let r;if(x(t.delay)){const o=s&&s[t.delay];r=_(o)?o(e,i.data,n):o}else r=_(t.delay)?t.delay(e,i.data,n):t.delay;const a=_(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(t,f,i,this.machine.options.delays);case W:return pt(t,f,i);case st:return t.get(f,i.data)||[];default:return rt(t,this.options.actions)}})),[g,y]=b(v,t=>t.type===X||t.type===G&&t.to===C.Internal),m=v.filter(t=>t.type===B&&t.activity.type===Z).reduce((t,e)=>(t[e.activity.id]=function(t){const e={id:i=t.id,send:()=>void 0,subscribe:()=>({unsubscribe:()=>void 0}),toJSON:()=>({id:i})};var i;return e.meta=t,e}(e.activity),t),e?Object.assign({},e.children):{}),w=r?t.configuration:e?e.configuration:[],O=w.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),E=J(w,this),j=new Et({value:r||e.value,context:f,_event:i,_sessionid:e?e._sessionid:null,historyValue:r?a?(N=a,$=r,{current:$,states:S(N,$)}):void 0:e?e.historyValue:void 0,history:!r||t.source?e:void 0,actions:r?y:[],activities:r?d:e?e.activities:{},meta:r?O:e?e.meta:void 0,events:[],configuration:w,transitions:t.transitions,children:m,done:E});var N,$;j.changed=i.name===it||!!u.length;const{history:T}=j;if(T&&delete T.history,!r)return j;let P=j;if(!E){for((this._transient||o.some(t=>t._transient))&&(P=this.resolveRaisedTransition(P,{type:K},i));g.length;){const t=g.shift();P=this.resolveRaisedTransition(P,t._event,i)}}const V=P.changed||(T?!!P.actions.length||!!u.length||typeof T.value!=typeof P.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(x(e)||x(i))return e===i;const s=n(e),o=n(i);return s.length===o.length&&s.every(s=>t(e[s],i[s]))}(P.value,T.value):void 0);return P.changed=V,P.historyValue=j.historyValue,P.history=T,P}getStateNode(t){if(Pt(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.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Pt(t)?t.slice($t.length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Pt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=a(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||kt;switch(this.type){case"parallel":return d(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):kt);case"compound":if(x(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return n(t).length?d(t,(t,e)=>t?this.getStateNode(e).resolve(t):kt):this.initialStateValue||{};default:return t||kt}}getResolvedPath(t){if(Pt(t)){const e=this.machine.idMap[t.slice($t.length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return a(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=u(this.states,t=>t.initialStateValue||kt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=A(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=x(e.target)&&Pt(e.target)?h(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(A(this))return[this];if("compound"===this.type&&!this.initial)return[this];return p(f(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(n(this.states).length)return{current:t||this.initialStateValue,states:u(this.states,(e,i)=>{if(!t)return e.historyValue();const s=x(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?p(f(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return x(i)?[e.getStateNode(i)]:p(f(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=p(n(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const i of n(t)){const s=t[i];if(s.states)for(const t of s.events)e.add(`${t}`)}return this.__cache.events=Array.from(e)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!x(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&t!==s)return g(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>x(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,o=this.resolveTarget(e);return Object.assign(Object.assign({},t),{actions:at(g(t.actions)),cond:O(t.cond,n),target:o,source:this,internal:i,eventType:t.event})}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i=Tt,s=e[i],o=void 0===s?[]:s,r=I(e,[i+""]);t=p(n(r).map(t=>{return P(t,r[t])}).concat(P(Tt,o)))}else t=[];const e=this.config.onDone?P(String(St(this.id)),this.config.onDone):[],i=p(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...P(String(wt(t.id)),t.onDone)),t.onError&&e.push(...P(String(_t(t.id)),t.onError)),e})),s=this.after,o=p([...e,...i,...t].map(t=>g(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function Lt(t,e,i=t.context){const s="function"==typeof i?i():i;return new It(t,e,s)}function Ct(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let Dt=0;const Ft={bookId:()=>`x:${Dt++}`,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}},zt={sync:!1,autoForward:!1},Ut=(()=>{const t=[];return(e,i)=>{e&&t.push(e);const s=i(e||t[t.length-1]);return e&&t.pop(),s}})();var Jt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Jt||(Jt={}));class Bt{constructor(t,e=Bt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=Jt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(w(t))return this.batch(t),this.state;const i=k(T(t,e));if(this._status===Jt.Stopped)return this.state;if(this._status===Jt.NotStarted&&this.options.deferEvents);else if(this._status!==Jt.Running)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===C.Parent||this.parent.id===e),s=i?this.parent:jt(e)?e:this.children.get(e)||Ft.get(e);if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===et?`${_t(this.id)}`:t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Bt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Ut(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),s=i&&i.data?y(i.data,t.context,e):void 0;for(const t of this.doneListeners)t(wt(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this._status===Jt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>void 0};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this._status===Jt.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this._status===Jt.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this._status=Jt.Running;const e=void 0===t?this.initialState:Ut(this,()=>(function(t){return!x(t)&&("value"in t&&"history"in t)})(t)?this.machine.resolveState(t):this.machine.resolveState(Et.from(t,this.machine.context)));return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,nt)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);this.children.forEach(t=>{_(t.stop)&&t.stop()});for(const t of n(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this._status=Jt.Stopped,Ft.free(this.sessionId),this}batch(t){if(this._status===Jt.NotStarted&&this.options.deferEvents);else if(this._status!==Jt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=k(n);this.forward(t),e=Ut(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>Ot(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,this.update(e,k(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=k(t);if(0===e.name.indexOf(tt)&&!this.state.nextEvents.some(t=>0===t.indexOf(tt)))throw e.data.data;return Ut(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i){const{context:s,_event:n}=e,o=ot(t.type,i)||t.exec,r=_(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case G:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case B:{const e=t.activity;if(!this.state.activities[e.type])break;if(e.type===L.Invoke){const t=this.machine.options.services?this.machine.options.services[e.src]:void 0,{id:i,data:o}=e,r="autoForward"in e?e.autoForward:!!e.forward;if(!t)return;const a=_(t)?t(s,n.data):t;m(a)?this.state.children[i]=this.spawnPromise(Promise.resolve(a),i):_(a)?this.state.children[i]=this.spawnCallback(a,i):E(a)?this.state.children[i]=this.spawnObservable(a,i):N(a)&&(this.state.children[i]=this.spawnMachine(o?a.withContext(y(o,s,n)):a,{id:i,autoForward:r}))}else this.spawnActivity(e);break}case q:this.stopChild(t.activity.id);break;case W:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}stopChild(t){const e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],_(e.stop)&&e.stop())}spawn(t,e,i){if(m(t))return this.spawnPromise(Promise.resolve(t),e);if(_(t))return this.spawnCallback(t,e);if(jt(t))return this.spawnActor(t);if(E(t))return this.spawnObservable(t,e);if(N(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`)}spawnMachine(t,e={}){const i=new Bt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},zt),e);s.sync&&i.onTransition(t=>{this.send(it,{state:t,id:i.id})}),i.onDone(t=>{this.send(k(t,{origin:i.id}))}).start();const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||this.send(k(wt(e,t),{origin:e}))},t=>{if(!i){const i=_t(e,t);try{this.send(k(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>void 0,subscribe:(e,i,s)=>{let n=!1;return t.then(t=>{n||(e&&e(t),n||s&&s())},t=>{n||i(t)}),{unsubscribe:()=>n=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(t)};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(_t(e,t))}if(m(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,_(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(k(t,{origin:e}))},t=>{this.send(k(_t(e,t),{origin:e}))},()=>{this.send(k(wt(e),{origin:e}))}),s={id:e,send:()=>void 0,subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>void 0,subscribe:()=>({unsubscribe:()=>void 0}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){const t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},t),{features:Object.assign({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}}toJSON(){return{id:this.id}}[j](){return this}}Bt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(e,i)=>t.setTimeout.call(null,e,i),clearTimeout:e=>t.clearTimeout.call(null,e)},logger:t.console.log.bind(console),devTools:!1}))("undefined"==typeof window?global:window),Bt.interpret=Ht;const qt=(t="null")=>({id:t,send:()=>void 0,subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}),Xt=t=>x(t)?Object.assign(Object.assign({},zt),{name:t}):Object.assign(Object.assign(Object.assign({},zt),{name:$()}),t);function Gt(t,e){const i=Xt(e);return Ut(void 0,e=>e?e.spawn(t,i.name,i):qt(i.name))}function Ht(t,e){return new Bt(t,e)}function Kt(t,e,i){const s=Et.from(t,t instanceof Et?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}const Qt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:W,label:e,expr:t}},cancel:vt,start:gt,stop:yt,assign:mt,after:bt,done:St,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,s)=>({type:et,data:_(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:C.Parent}))}};export{L as ActionTypes,Bt as Interpreter,Lt as Machine,C as SpecialTargets,Et as State,It as StateNode,Qt as actions,mt as assign,Ct as createMachine,wt as doneInvoke,xt as forwardTo,Ht as interpret,V as mapState,Kt as matchState,o as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Gt as spawn};
15
+ ***************************************************************************** */function I(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var L,C;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure"}(L||(L={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(C||(C={}));const A=t=>"atomic"===t.type||"final"===t.type;function R(t){return n(t.states).map(e=>t.states[e])}function M(t){const e=[t];return A(t)?e:e.concat(p(R(t).map(M)))}function D(t,e){const i=F(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=F(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of R(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function F(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(A(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,F(D([t],e)))}function J(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function U(t,e){return"compound"===e.type?R(e).some(e=>"final"===e.type&&J(t,e)):"parallel"===e.type&&R(e).every(e=>U(t,e))}const B=L.Start,q=L.Stop,X=L.Raise,G=L.Send,H=L.Cancel,K=L.NullEvent,Q=L.Assign,W=(L.After,L.DoneState,L.Log),Y=L.Init,Z=L.Invoke,tt=(L.ErrorExecution,L.ErrorPlatform),et=L.ErrorCustom,it=L.Update,st=L.Pure,nt=k({type:Y});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(x(t)||"number"==typeof t){const s=ot(t,e);i=_(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(_(t))i={type:t.name||t.toString(),exec:t};else{const s=ot(t.type,e);if(_(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const{type:e}=t,n=I(t,["type"]);i=Object.assign(Object.assign({type:e},s),n)}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(w(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:x(t)?t:e.id},e),{type:e.type})}function ht(t){return x(t)?{type:X,event:t}:dt(t,{to:C.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:G,event:_(t)?t:T(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:_(t)?t.name:r(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:C.Parent}))}function lt(){return ut(it)}const ft=(t,e)=>({context:t,event:e});const pt=(t,e,i)=>Object.assign(Object.assign({},t),{value:x(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),gt=t=>({type:H,sendId:t});function vt(t){const e=ct(t);return{type:L.Start,activity:e,exec:void 0}}function yt(t){const e=ct(t);return{type:L.Stop,activity:e,exec:void 0}}const mt=t=>({type:Q,assignment:t});function bt(t,e){const i=e?`#${e}`:"";return`${L.After}(${t})${i}`}function St(t,e){const i=`${L.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){const i=`${L.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function _t(t,e){const i=`${L.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Et{constructor(t){this.actions=[],this.activities=e,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||e,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:()=>(function(t){return p([...new Set(t.map(t=>t.ownEvents))])})(this.configuration)})}static from(t,e){if(t instanceof Et)return t.context!==e?new Et({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Et({value:t,context:e,_event:nt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Et(t)}static inert(t,e){if(t instanceof Et){if(!t.actions.length)return t;const i=nt;return new Et({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Et.from(t,e)}toStrings(t=this.value,e="."){if(x(t))return[t];const i=n(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){return I(this,["configuration","transitions"])}matches(t){return o(t,this.value)}}function jt(t){try{return"function"==typeof t.send}catch(t){return!1}}const Nt="",$t="#",Tt="*",kt={},Pt=t=>t[0]===$t,Vt=()=>({actions:{},guards:{},services:{},activities:{},delays:{}});class It{constructor(e,i,s){this.config=e,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign(Vt(),i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:t),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&n(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):kt;let o=0;!function t(e){e.order=o++;for(const i of R(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>t===Nt):Nt in this.config.on),this.strict=!!this.config.strict,this.onEntry=v(this.config.entry||this.config.onEntry).map(t=>rt(t)),this.onExit=v(this.config.exit||this.config.onExit).map(t=>rt(t)),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=v(this.config.invoke).map((t,e)=>{if(N(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),{type:Z,src:t.id,id:t.id};if("string"!=typeof t.src){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Object.assign(Object.assign({type:Z,id:i},t),{src:i})}return Object.assign(Object.assign({},t),{type:Z,id:t.id||t.src,src:t.src})}),this.activities=v(this.config.activities).concat(this.invoke).map(t=>ct(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||M(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:d(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=t===Nt,i=this.transitions.filter(i=>{const s=i.eventType===t;return e?s:s||i.eventType===Tt});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=bt(_(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(gt(i)),i};return(w(t)?t.map((t,i)=>{const s=e(t.delay,i);return Object.assign(Object.assign({},t),{event:s})}):p(n(t).map((i,s)=>{const n=t[i],o=x(n)?{target:n}:n,r=isNaN(+i)?i:+i,a=e(r,s);return v(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const e=t instanceof Et?t.value:c(t,this.delimiter);if(x(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this.states[e]]}const i=n(e);return i.map(t=>this.getStateNode(t)).concat(i.reduce((t,i)=>{const s=this.getStateNode(i).getStateNodes(e[i]);return t.concat(s)},[]))}handles(t){const e=r(t);return this.events.includes(e)}resolveState(t){const e=Array.from(D([],this.getStateNodes(t.value)));return new Et(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,e,i){const s=n(t),o=this.getStateNode(s[0])._transition(t[s[0]],e,i);return o&&o.transitions.length?o:this.next(e,i)}transitionParallelNode(t,e,i){const s={};for(const o of n(t)){const n=t[o];if(!n)continue;const r=this.getStateNode(o)._transition(n,e,i);r&&(s[o]=r)}const o=n(s).map(t=>s[t]),r=p(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(e,i);const a=p(o.map(t=>t.entrySet)),c=p(n(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:p(o.map(t=>t.exitSet)),configuration:c,source:e,actions:p(n(s).map(t=>s[t].actions))}}_transition(t,e,i){return x(t)?this.transitionLeafNode(t,e,i):1===n(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}next(t,e){const i=e.name,s=[];let n,r=[];for(const a of this.getCandidates(i)){const{cond:h,in:d}=a,u=t.context,f=!d||(x(d)&&Pt(d)?t.matches(c(this.getStateNodeById(d).path,this.delimiter)):o(c(d,this.delimiter),l(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!h||this.evaluateGuard(h,u,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${h.name||h.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==a.target&&(r=a.target),s.push(...a.actions),n=a;break}}if(!n)return;if(!r.length)return{transitions:[n],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const a=p(r.map(e=>this.getRelativeStateNodes(e,t.historyValue))),h=!!n.internal;return{transitions:[n],entrySet:h?[]:p(a.map(t=>this.nodesFromChild(t))),exitSet:h?[]:[this],configuration:a,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}evaluateGuard(t,e,s,n){const{guards:o}=this.machine.options,r={state:n,cond:t,_event:s};if(t.type===i)return t.predicate(e,s.data,r);const a=o[t.type];if(!a)throw new Error(`Guard '${t.type}' is not implemented on machine '${this.machine.id}'.`);return a(e,s.data,r)}getActions(t,e,i,s){const n=D([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?D(n,t.configuration):n;for(const e of o)J(n,e)||t.entrySet.push(e);for(const e of n)J(o,e)&&!J(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=p(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(n.push(St(s.id,s.data),St(o.id,s.data?y(s.data,e,i):void 0)),o.parent){const e=o.parent;"parallel"===e.type&&R(e).every(e=>U(t.configuration,e))&&n.push(St(e.id,e.data))}return n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[p(Array.from(a).map(t=>[...t.activities.map(t=>vt(t)),...t.onEntry])).concat(r.map(ht)),p(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>yt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=k(e);let n;if(t instanceof Et)n=void 0===i?t:this.resolveState(Et.from(t,i));else{const e=x(t)?this.resolve(h(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(Et.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const r=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},a=D([],this.getStateNodes(n.value)),c=r.configuration.length?D(a,r.configuration):a;return r.configuration=[...c],this.resolveTransition(r,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,e,i=nt,s=this.machine.context){const{configuration:o}=t,r=!e||t.transitions.length>0?z(this.machine,o):void 0,a=e?e.historyValue?e.historyValue:t.source?this.machine.historyValue(e.value):void 0:void 0,c=e?e.context:s,h=this.getActions(t,c,i,e),d=e?Object.assign({},e.activities):{};for(const t of h)t.type===B?d[t.activity.type]=t:t.type===q&&(d[t.activity.type]=!1);const[u,l]=b(h,t=>t.type===Q),f=u.length?function(t,e,i,s){return t?i.reduce((t,i)=>{const{assignment:o}=i,r={state:s,action:i,_event:e};let a={};if(_(o))a=o(t,e.data,r);else for(const i of n(o)){const s=o[i];a[i]=_(s)?s(t,e.data,r):s}return Object.assign({},t,a)},t):t}(c,i,u,e):c,g=p(l.map(t=>{switch(t.type){case X:return function(t){return{type:X,_event:k(t.event)}}(t);case G:return function(t,e,i,s){const n={_event:i},o=k(_(t.event)?t.event(e,i.data,n):t.event);let r;if(x(t.delay)){const o=s&&s[t.delay];r=_(o)?o(e,i.data,n):o}else r=_(t.delay)?t.delay(e,i.data,n):t.delay;const a=_(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(t,f,i,this.machine.options.delays);case W:return pt(t,f,i);case st:return t.get(f,i.data)||[];default:return rt(t,this.options.actions)}})),[v,y]=b(g,t=>t.type===X||t.type===G&&t.to===C.Internal),m=g.filter(t=>t.type===B&&t.activity.type===Z).reduce((t,e)=>(t[e.activity.id]=function(t){const e={id:i=t.id,send:()=>void 0,subscribe:()=>({unsubscribe:()=>void 0}),toJSON:()=>({id:i})};var i;return e.meta=t,e}(e.activity),t),e?Object.assign({},e.children):{}),w=r?t.configuration:e?e.configuration:[],O=w.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),E=U(w,this),j=new Et({value:r||e.value,context:f,_event:i,_sessionid:e?e._sessionid:null,historyValue:r?a?(N=a,$=r,{current:$,states:S(N,$)}):void 0:e?e.historyValue:void 0,history:!r||t.source?e:void 0,actions:r?y:[],activities:r?d:e?e.activities:{},meta:r?O:e?e.meta:void 0,events:[],configuration:w,transitions:t.transitions,children:m,done:E});var N,$;j.changed=i.name===it||!!u.length;const{history:T}=j;if(T&&delete T.history,!r)return j;let P=j;if(!E){for((this._transient||o.some(t=>t._transient))&&(P=this.resolveRaisedTransition(P,{type:K},i));v.length;){const t=v.shift();P=this.resolveRaisedTransition(P,t._event,i)}}const V=P.changed||(T?!!P.actions.length||!!u.length||typeof T.value!=typeof P.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(x(e)||x(i))return e===i;const s=n(e),o=n(i);return s.length===o.length&&s.every(s=>t(e[s],i[s]))}(P.value,T.value):void 0);return P.changed=V,P.historyValue=j.historyValue,P.history=T,P}getStateNode(t){if(Pt(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.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Pt(t)?t.slice($t.length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Pt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=a(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||kt;switch(this.type){case"parallel":return d(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):kt);case"compound":if(x(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return n(t).length?d(t,(t,e)=>t?this.getStateNode(e).resolve(t):kt):this.initialStateValue||{};default:return t||kt}}getResolvedPath(t){if(Pt(t)){const e=this.machine.idMap[t.slice($t.length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return a(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=u(this.states,t=>t.initialStateValue||kt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=A(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=x(e.target)&&Pt(e.target)?h(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(A(this))return[this];if("compound"===this.type&&!this.initial)return[this];return p(f(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(n(this.states).length)return{current:t||this.initialStateValue,states:u(this.states,(e,i)=>{if(!t)return e.historyValue();const s=x(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?p(f(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return x(i)?[e.getStateNode(i)]:p(f(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=p(n(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const i of n(t)){const s=t[i];if(s.states)for(const t of s.events)e.add(`${t}`)}return this.__cache.events=Array.from(e)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!x(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&t!==s)return v(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>x(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,o=this.resolveTarget(e),r=Object.assign(Object.assign({},t),{actions:at(v(t.actions)),cond:O(t.cond,n),target:o,source:this,internal:i,eventType:t.event});return Object.defineProperty(r,"toJSON",{value:()=>Object.assign(Object.assign({},r),{target:r.target?r.target.map(t=>`#${t.id}`):void 0,source:"#{this.id}"})}),r}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i=Tt,s=e[i],o=void 0===s?[]:s,r=I(e,[i+""]);t=p(n(r).map(t=>{return P(t,r[t])}).concat(P(Tt,o)))}else t=[];const e=this.config.onDone?P(String(St(this.id)),this.config.onDone):[],i=p(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...P(String(wt(t.id)),t.onDone)),t.onError&&e.push(...P(String(_t(t.id)),t.onError)),e})),s=this.after,o=p([...e,...i,...t].map(t=>v(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function Lt(t,e,i=t.context){const s="function"==typeof i?i():i;return new It(t,e,s)}function Ct(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let Dt=0;const Ft={bookId:()=>`x:${Dt++}`,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}},zt={sync:!1,autoForward:!1},Jt=(()=>{const t=[];return(e,i)=>{e&&t.push(e);const s=i(e||t[t.length-1]);return e&&t.pop(),s}})();var Ut;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ut||(Ut={}));class Bt{constructor(t,e=Bt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=Ut.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(w(t))return this.batch(t),this.state;const i=k(T(t,e));if(this._status===Ut.Stopped)return this.state;if(this._status===Ut.NotStarted&&this.options.deferEvents);else if(this._status!==Ut.Running)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===C.Parent||this.parent.id===e),s=i?this.parent:jt(e)?e:this.children.get(e)||Ft.get(e);if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===et?`${_t(this.id)}`:t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Bt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Jt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=U(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),s=i&&i.data?y(i.data,t.context,e):void 0;for(const t of this.doneListeners)t(wt(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this._status===Ut.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>void 0};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this._status===Ut.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this._status===Ut.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this._status=Ut.Running;const e=void 0===t?this.initialState:Jt(this,()=>(function(t){return!x(t)&&("value"in t&&"history"in t)})(t)?this.machine.resolveState(t):this.machine.resolveState(Et.from(t,this.machine.context)));return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,nt)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);this.children.forEach(t=>{_(t.stop)&&t.stop()});for(const t of n(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this._status=Ut.Stopped,Ft.free(this.sessionId),this}batch(t){if(this._status===Ut.NotStarted&&this.options.deferEvents);else if(this._status!==Ut.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=k(n);this.forward(t),e=Jt(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>Ot(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,this.update(e,k(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=k(t);if(0===e.name.indexOf(tt)&&!this.state.nextEvents.some(t=>0===t.indexOf(tt)))throw e.data.data;return Jt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i){const{context:s,_event:n}=e,o=ot(t.type,i)||t.exec,r=_(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case G:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case B:{const e=t.activity;if(!this.state.activities[e.type])break;if(e.type===L.Invoke){const t=this.machine.options.services?this.machine.options.services[e.src]:void 0,{id:i,data:o}=e,r="autoForward"in e?e.autoForward:!!e.forward;if(!t)return;const a=_(t)?t(s,n.data):t;m(a)?this.state.children[i]=this.spawnPromise(Promise.resolve(a),i):_(a)?this.state.children[i]=this.spawnCallback(a,i):E(a)?this.state.children[i]=this.spawnObservable(a,i):N(a)&&(this.state.children[i]=this.spawnMachine(o?a.withContext(y(o,s,n)):a,{id:i,autoForward:r}))}else this.spawnActivity(e);break}case q:this.stopChild(t.activity.id);break;case W:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}stopChild(t){const e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],_(e.stop)&&e.stop())}spawn(t,e,i){if(m(t))return this.spawnPromise(Promise.resolve(t),e);if(_(t))return this.spawnCallback(t,e);if(jt(t))return this.spawnActor(t);if(E(t))return this.spawnObservable(t,e);if(N(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`)}spawnMachine(t,e={}){const i=new Bt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},zt),e);s.sync&&i.onTransition(t=>{this.send(it,{state:t,id:i.id})}),i.onDone(t=>{this.send(k(t,{origin:i.id}))}).start();const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||this.send(k(wt(e,t),{origin:e}))},t=>{if(!i){const i=_t(e,t);try{this.send(k(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>void 0,subscribe:(e,i,s)=>{let n=!1;return t.then(t=>{n||(e&&e(t),n||s&&s())},t=>{n||i(t)}),{unsubscribe:()=>n=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(t)};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(_t(e,t))}if(m(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,_(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(k(t,{origin:e}))},t=>{this.send(k(_t(e,t),{origin:e}))},()=>{this.send(k(wt(e),{origin:e}))}),s={id:e,send:()=>void 0,subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>void 0,subscribe:()=>({unsubscribe:()=>void 0}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){const t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},t),{features:Object.assign({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}}toJSON(){return{id:this.id}}[j](){return this}}Bt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(e,i)=>t.setTimeout.call(null,e,i),clearTimeout:e=>t.clearTimeout.call(null,e)},logger:t.console.log.bind(console),devTools:!1}))("undefined"==typeof window?global:window),Bt.interpret=Ht;const qt=(t="null")=>({id:t,send:()=>void 0,subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}),Xt=t=>x(t)?Object.assign(Object.assign({},zt),{name:t}):Object.assign(Object.assign(Object.assign({},zt),{name:$()}),t);function Gt(t,e){const i=Xt(e);return Jt(void 0,e=>e?e.spawn(t,i.name,i):qt(i.name))}function Ht(t,e){return new Bt(t,e)}function Kt(t,e,i){const s=Et.from(t,t instanceof Et?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}const Qt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:W,label:e,expr:t}},cancel:gt,start:vt,stop:yt,assign:mt,after:bt,done:St,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,s)=>({type:et,data:_(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:C.Parent}))}};export{L as ActionTypes,Bt as Interpreter,Lt as Machine,C as SpecialTargets,Et as State,It as StateNode,Qt as actions,mt as assign,Ct as createMachine,wt as doneInvoke,xt as forwardTo,Ht as interpret,V as mapState,Kt as matchState,o as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Gt as spawn};
package/es/State.js CHANGED
@@ -66,6 +66,8 @@ function () {
66
66
  * @param configuration
67
67
  */
68
68
  function State(config) {
69
+ var _this = this;
70
+
69
71
  this.actions = [];
70
72
  this.activities = EMPTY_ACTIVITY_MAP;
71
73
  this.meta = {};
@@ -89,7 +91,7 @@ function () {
89
91
  this.done = !!config.done;
90
92
  Object.defineProperty(this, 'nextEvents', {
91
93
  get: function () {
92
- return nextEvents(config.configuration);
94
+ return nextEvents(_this.configuration);
93
95
  }
94
96
  });
95
97
  }
package/es/StateNode.js CHANGED
@@ -229,6 +229,7 @@ function () {
229
229
  id: this.id,
230
230
  key: this.key,
231
231
  version: this.version,
232
+ context: this.context,
232
233
  type: this.type,
233
234
  initial: this.initial,
234
235
  history: this.history,
@@ -237,8 +238,8 @@ function () {
237
238
  }),
238
239
  on: this.on,
239
240
  transitions: this.transitions,
240
- onEntry: this.onEntry,
241
- onExit: this.onExit,
241
+ entry: this.onEntry,
242
+ exit: this.onExit,
242
243
  activities: this.activities || [],
243
244
  meta: this.meta,
244
245
  order: this.order || -1,
@@ -1475,7 +1476,8 @@ function () {
1475
1476
  }) : true;
1476
1477
  var guards = this.machine.options.guards;
1477
1478
  var target = this.resolveTarget(normalizedTarget);
1478
- return __assign(__assign({}, transitionConfig), {
1479
+
1480
+ var transition = __assign(__assign({}, transitionConfig), {
1479
1481
  actions: toActionObjects(toArray(transitionConfig.actions)),
1480
1482
  cond: toGuard(transitionConfig.cond, guards),
1481
1483
  target: target,
@@ -1483,6 +1485,18 @@ function () {
1483
1485
  internal: internal,
1484
1486
  eventType: transitionConfig.event
1485
1487
  });
1488
+
1489
+ Object.defineProperty(transition, 'toJSON', {
1490
+ value: function () {
1491
+ return __assign(__assign({}, transition), {
1492
+ target: transition.target ? transition.target.map(function (t) {
1493
+ return "#" + t.id;
1494
+ }) : undefined,
1495
+ source: "#{this.id}"
1496
+ });
1497
+ }
1498
+ });
1499
+ return transition;
1486
1500
  };
1487
1501
 
1488
1502
  StateNode.prototype.formatTransitions = function () {
package/es/json.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
2
+ interface JSONFunction {
3
+ $function: string;
4
+ }
5
+ export declare function stringifyFunction(fn: Function): JSONFunction;
6
+ interface TransitionConfig {
7
+ target: string[];
8
+ source: string;
9
+ actions: Array<ActionObject<any, any>>;
10
+ cond: Guard<any, any> | undefined;
11
+ eventType: string;
12
+ }
13
+ interface StateNodeConfig {
14
+ type: StateNode['type'];
15
+ id: string;
16
+ key: string;
17
+ initial?: string;
18
+ entry: Array<ActionObject<any, any>>;
19
+ exit: Array<ActionObject<any, any>>;
20
+ on: {
21
+ [key: string]: TransitionConfig[];
22
+ };
23
+ invoke: Array<InvokeDefinition<any, any>>;
24
+ states: Record<string, StateNodeConfig>;
25
+ }
26
+ export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
27
+ export declare function stringify(machine: StateNode): string;
28
+ export declare function parse(machineString: string): StateNodeConfig;
29
+ export declare function jsonify<T extends Record<string, any>>(value: T): T;
30
+ export {};
31
+ //# sourceMappingURL=json.d.ts.map
package/es/types.d.ts CHANGED
@@ -345,14 +345,15 @@ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema,
345
345
  id: string;
346
346
  version: string | undefined;
347
347
  key: string;
348
+ context: TContext;
348
349
  type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
349
350
  initial: StateNodeConfig<TContext, TStateSchema, TEvent>['initial'];
350
351
  history: boolean | 'shallow' | 'deep' | undefined;
351
352
  states: StatesDefinition<TContext, TStateSchema, TEvent>;
352
353
  on: TransitionDefinitionMap<TContext, TEvent>;
353
354
  transitions: Array<TransitionDefinition<TContext, TEvent>>;
354
- onEntry: Array<ActionObject<TContext, TEvent>>;
355
- onExit: Array<ActionObject<TContext, TEvent>>;
355
+ entry: Array<ActionObject<TContext, TEvent>>;
356
+ exit: Array<ActionObject<TContext, TEvent>>;
356
357
  activities: Array<ActivityDefinition<TContext, TEvent>>;
357
358
  meta: any;
358
359
  order: number;
package/lib/State.js CHANGED
@@ -97,6 +97,7 @@ var State = /** @class */ (function () {
97
97
  * @param configuration
98
98
  */
99
99
  function State(config) {
100
+ var _this = this;
100
101
  this.actions = [];
101
102
  this.activities = constants_1.EMPTY_ACTIVITY_MAP;
102
103
  this.meta = {};
@@ -120,7 +121,7 @@ var State = /** @class */ (function () {
120
121
  this.done = !!config.done;
121
122
  Object.defineProperty(this, 'nextEvents', {
122
123
  get: function () {
123
- return stateUtils_1.nextEvents(config.configuration);
124
+ return stateUtils_1.nextEvents(_this.configuration);
124
125
  }
125
126
  });
126
127
  }
package/lib/StateNode.js CHANGED
@@ -263,14 +263,15 @@ var StateNode = /** @class */ (function () {
263
263
  id: this.id,
264
264
  key: this.key,
265
265
  version: this.version,
266
+ context: this.context,
266
267
  type: this.type,
267
268
  initial: this.initial,
268
269
  history: this.history,
269
270
  states: utils_1.mapValues(this.states, function (state) { return state.definition; }),
270
271
  on: this.on,
271
272
  transitions: this.transitions,
272
- onEntry: this.onEntry,
273
- onExit: this.onExit,
273
+ entry: this.onEntry,
274
+ exit: this.onExit,
274
275
  activities: this.activities || [],
275
276
  meta: this.meta,
276
277
  order: this.order || -1,
@@ -1326,7 +1327,13 @@ var StateNode = /** @class */ (function () {
1326
1327
  : true;
1327
1328
  var guards = this.machine.options.guards;
1328
1329
  var target = this.resolveTarget(normalizedTarget);
1329
- return __assign(__assign({}, transitionConfig), { actions: actions_1.toActionObjects(utils_1.toArray(transitionConfig.actions)), cond: utils_1.toGuard(transitionConfig.cond, guards), target: target, source: this, internal: internal, eventType: transitionConfig.event });
1330
+ var transition = __assign(__assign({}, transitionConfig), { actions: actions_1.toActionObjects(utils_1.toArray(transitionConfig.actions)), cond: utils_1.toGuard(transitionConfig.cond, guards), target: target, source: this, internal: internal, eventType: transitionConfig.event });
1331
+ Object.defineProperty(transition, 'toJSON', {
1332
+ value: function () { return (__assign(__assign({}, transition), { target: transition.target
1333
+ ? transition.target.map(function (t) { return "#" + t.id; })
1334
+ : undefined, source: "#{this.id}" })); }
1335
+ });
1336
+ return transition;
1330
1337
  };
1331
1338
  StateNode.prototype.formatTransitions = function () {
1332
1339
  var e_9, _a;
package/lib/json.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
2
+ interface JSONFunction {
3
+ $function: string;
4
+ }
5
+ export declare function stringifyFunction(fn: Function): JSONFunction;
6
+ interface TransitionConfig {
7
+ target: string[];
8
+ source: string;
9
+ actions: Array<ActionObject<any, any>>;
10
+ cond: Guard<any, any> | undefined;
11
+ eventType: string;
12
+ }
13
+ interface StateNodeConfig {
14
+ type: StateNode['type'];
15
+ id: string;
16
+ key: string;
17
+ initial?: string;
18
+ entry: Array<ActionObject<any, any>>;
19
+ exit: Array<ActionObject<any, any>>;
20
+ on: {
21
+ [key: string]: TransitionConfig[];
22
+ };
23
+ invoke: Array<InvokeDefinition<any, any>>;
24
+ states: Record<string, StateNodeConfig>;
25
+ }
26
+ export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
27
+ export declare function stringify(machine: StateNode): string;
28
+ export declare function parse(machineString: string): StateNodeConfig;
29
+ export declare function jsonify<T extends Record<string, any>>(value: T): T;
30
+ export {};
31
+ //# sourceMappingURL=json.d.ts.map
package/lib/json.js ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("./utils");
4
+ // tslint:disable-next-line:ban-types
5
+ function stringifyFunction(fn) {
6
+ return {
7
+ $function: fn.toString()
8
+ };
9
+ }
10
+ exports.stringifyFunction = stringifyFunction;
11
+ function getStateNodeId(stateNode) {
12
+ return "#" + stateNode.id;
13
+ }
14
+ // derive config from machine
15
+ function machineToJSON(stateNode) {
16
+ var config = {
17
+ type: stateNode.type,
18
+ initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
19
+ id: stateNode.id,
20
+ key: stateNode.key,
21
+ entry: stateNode.onEntry,
22
+ exit: stateNode.onExit,
23
+ on: utils_1.mapValues(stateNode.on, function (transition) {
24
+ return transition.map(function (t) {
25
+ return {
26
+ target: t.target ? t.target.map(getStateNodeId) : [],
27
+ source: getStateNodeId(t.source),
28
+ actions: t.actions,
29
+ cond: t.cond,
30
+ eventType: t.eventType
31
+ };
32
+ });
33
+ }),
34
+ invoke: stateNode.invoke,
35
+ states: {}
36
+ };
37
+ Object.values(stateNode.states).forEach(function (sn) {
38
+ config.states[sn.key] = machineToJSON(sn);
39
+ });
40
+ return config;
41
+ }
42
+ exports.machineToJSON = machineToJSON;
43
+ function stringify(machine) {
44
+ return JSON.stringify(machineToJSON(machine), function (_, value) {
45
+ if (utils_1.isFunction(value)) {
46
+ return { $function: value.toString() };
47
+ }
48
+ return value;
49
+ });
50
+ }
51
+ exports.stringify = stringify;
52
+ function parse(machineString) {
53
+ var config = JSON.parse(machineString, function (_, value) {
54
+ if (typeof value === 'object' && '$function' in value) {
55
+ return new Function(value.value);
56
+ }
57
+ return value;
58
+ });
59
+ return config;
60
+ }
61
+ exports.parse = parse;
62
+ function jsonify(value) {
63
+ Object.defineProperty(value, 'toJSON', {
64
+ value: function () {
65
+ return utils_1.mapValues(value, function (subValue) {
66
+ if (utils_1.isFunction(subValue)) {
67
+ return stringifyFunction(subValue);
68
+ }
69
+ else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
70
+ // mostly for assignments
71
+ return utils_1.mapValues(subValue, function (subSubValue) {
72
+ if (utils_1.isFunction(subSubValue)) {
73
+ return stringifyFunction(subSubValue);
74
+ }
75
+ return subSubValue;
76
+ });
77
+ }
78
+ return subValue;
79
+ });
80
+ }
81
+ });
82
+ return value;
83
+ }
84
+ exports.jsonify = jsonify;
package/lib/types.d.ts CHANGED
@@ -345,14 +345,15 @@ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema,
345
345
  id: string;
346
346
  version: string | undefined;
347
347
  key: string;
348
+ context: TContext;
348
349
  type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
349
350
  initial: StateNodeConfig<TContext, TStateSchema, TEvent>['initial'];
350
351
  history: boolean | 'shallow' | 'deep' | undefined;
351
352
  states: StatesDefinition<TContext, TStateSchema, TEvent>;
352
353
  on: TransitionDefinitionMap<TContext, TEvent>;
353
354
  transitions: Array<TransitionDefinition<TContext, TEvent>>;
354
- onEntry: Array<ActionObject<TContext, TEvent>>;
355
- onExit: Array<ActionObject<TContext, TEvent>>;
355
+ entry: Array<ActionObject<TContext, TEvent>>;
356
+ exit: Array<ActionObject<TContext, TEvent>>;
356
357
  activities: Array<ActivityDefinition<TContext, TEvent>>;
357
358
  meta: any;
358
359
  order: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.7.8",
3
+ "version": "4.8.0",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -66,7 +66,7 @@
66
66
  "rxjs": "^6.5.1",
67
67
  "ts-jest": "^24.1.9",
68
68
  "tslib": "^1.10.0",
69
- "typescript": "^3.7.2",
69
+ "typescript": "^3.7.5",
70
70
  "xml-js": "^1.6.11"
71
71
  }
72
72
  }