New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

xstate

Package Overview
Dependencies
Maintainers
3
Versions
251
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xstate - npm Package Compare versions

Comparing version 4.27.0 to 4.38.2

es/json.js

2

dist/xstate.interpreter.js

@@ -15,2 +15,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XStateInterpreter={})}(this,(function(t){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */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&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}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(t,e,n){if(n||2===arguments.length)for(var i,r=0,o=e.length;r<o;r++)!i&&r in e||(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}!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",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a={};function u(t){return Object.keys(t)}function c(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:d(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return d(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function h(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 f(t,e,n){var i,o;if(p(t))return t(e,n.data);var s={};try{for(var a=r(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];p(h)?s[c]=h(e,n.data):s[c]=h}}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 l(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function d(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}var y=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function g(t){try{return"__xstatenode"in t}catch(t){return!1}}var m=function(){var t=0;return function(){return(++t).toString(16)}}();function b(t,e){return v(t)||"number"==typeof t?i({type:t},e):t}function x(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=b(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function w(t,e,n){if("object"==typeof t)return t;var i=function(){};return{next:t,error:e||i,complete:n||i}}function S(t){return u(t.states).map((function(e){return t.states[e]}))}function E(t){return s([],o(new Set((e=s([],o(t.map((function(t){return t.ownEvents}))),!1),(n=[]).concat.apply(n,s([],o(e),!1))))),!1);var e,n}function _(t,e){return"compound"===e.type?S(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&&S(e).every((function(e){return _(t,e)}))}var O=e.Start,T=e.Stop,I=(e.Raise,e.Send),L=e.Cancel,k=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),C=e.Init,P=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),j=e.ErrorCustom,N=e.Update,A=(e.Choose,e.Pure,x({type:C}));function D(t,n){var i="".concat(e.DoneInvoke,".").concat(t),r={type:i,data:n,toString:function(){return i}};return r}function M(t,n){var i="".concat(e.ErrorPlatform,".").concat(t),r={type:i,data:n,toString:function(){return i}};return r}var R=function(){function t(t){var e,n,i=this;this.actions=[],this.activities=a,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||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),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,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return E(i.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:A,_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=A;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="."),v(t))return[t];var i=u(t);return i.concat.apply(i,s([],o(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this,e=(t.configuration,t.transitions,t.tags),n=(t.machine,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}(t,["configuration","transitions","tags","machine"]));return i(i({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,i){void 0===i&&(i=".");var r=c(e,i),o=c(n,i);return v(o)?!!v(r)&&o===r:v(r)?r in o:u(r).every((function(e){return e in o&&t(r[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),z={deferEvents:!1},V=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},z),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}(),J=[],q=function(t,e){J.push(t);var n=e(t);return J.pop(),n};var U=new Map,$=0,F=function(){return"x:".concat($++)},X=function(t,e){return U.set(t,e),t},B=function(t){return U.get(t)},G=function(t){U.delete(t)};function H(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function K(t){if(H()){var e=function(){var t=H();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Q(t,e){void 0===e&&(e={});var n,r=t.initialState,o=new Set,s=[],a=!1,u=(n={id:e.id,send:function(e){s.push(e),function(){if(!a){for(a=!0;s.length>0;){var e=s.shift();r=t.transition(r,e,c),o.forEach((function(t){return t.next(r)}))}a=!1}}()},getSnapshot:function(){return r},subscribe:function(t,e,n){var i=w(t,e,n);return o.add(i),i.next(r),{unsubscribe:function(){o.delete(i)}}}},i({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},n)),c={parent:e.parent,self:u,id:e.id||"anonymous",observers:o};return r=t.start?t.start(c):r,u}var W,Y={sync:!1,autoForward:!1};(W=t.InterpreterStatus||(t.InterpreterStatus={}))[W.NotStarted=0]="NotStarted",W[W.Running=1]="Running",W[W.Stopped=2]="Stopped";var Z=function(){function a(e,r){var o=this;void 0===r&&(r=a.defaultOptions),this.machine=e,this.scheduler=new V,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=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(d(e))return o.batch(e),o.state;var i=x(b(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'.concat(i.name,'" was sent to uninitialized service "').concat(o.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(i.data)));return o.scheduler.schedule((function(){o.forward(i);var t=o.nextState(i);o.update(t,i)})),o._state},this.sendTo=function(t,e){var r,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:v(e)?o.children.get(e)||B(e):(r=e)&&"function"==typeof r.send?e:void 0;if(a)"machine"in a?a.send(i(i({},t),{name:t.name===j?"".concat(M(o.id)):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '".concat(e,"' from service '").concat(o.id,"'."))};var s=i(i({},a.defaultOptions),r),u=s.clock,c=s.logger,h=s.parent,f=s.id,l=void 0!==f?f:e.id;this.id=l,this.logger=c,this.clock=u,this.parent=h,this.options=s,this.scheduler=new V({deferEvents:this.options.deferEvents}),this.sessionId=F()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:q(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.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}}},a.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,l=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){l.state.children[t.id]=t})),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 g=r(this.contextListeners),m=g.next();!m.done;m=g.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var b=_(t.configuration||[],this.machine);if(this.state.configuration&&b){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===l.machine})),w=x&&x.doneData?f(x.doneData,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(D(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,i){var r,o=this;if(!e)return{unsubscribe:function(){}};var s=i;return"function"==typeof e?r=e:(r=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(r),this.status===t.InterpreterStatus.Running&&r(this.state),s&&this.onDone(s),{unsubscribe:function(){r&&o.listeners.delete(r),s&&o.doneListeners.delete(s)}}},a.prototype.onEvent=function(t){return this.eventListeners.add(t),this},a.prototype.onSend=function(t){return this.sendListeners.add(t),this},a.prototype.onChange=function(t){return this.contextListeners.add(t),this},a.prototype.onStop=function(t){return this.stopListeners.add(t),this},a.prototype.onDone=function(t){return this.doneListeners.add(t),this},a.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},a.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;X(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:q(this,(function(){return!v(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(R.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,A)})),this},a.prototype.stop=function(){var e,n,i,o,s,a,c,h,f,l,d=this;try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){var g=y.value;this.listeners.delete(g)}}catch(t){e={error:t}}finally{try{y&&!y.done&&(n=v.return)&&n.call(v)}finally{if(e)throw e.error}}try{for(var m=r(this.stopListeners),b=m.next();!b.done;b=m.next()){(g=b.value)(),this.stopListeners.delete(g)}}catch(t){i={error:t}}finally{try{b&&!b.done&&(o=m.return)&&o.call(m)}finally{if(i)throw i.error}}try{for(var x=r(this.contextListeners),w=x.next();!w.done;w=x.next()){g=w.value;this.contextListeners.delete(g)}}catch(t){s={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(s)throw s.error}}try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){g=E.value;this.doneListeners.delete(g)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var s=o.value;d.exec(s,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){p(t.stop)&&t.stop()}));try{for(var _=r(u(this.delayedEventsMap)),O=_.next();!O.done;O=_.next()){var T=O.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,G(this.sessionId),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=x(t);n.forward(e),u=q(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,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}))),!1)),c=c||!!u.changed};try{for(var l=r(e),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(a=l.return)&&a.call(l)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,n.update(u,x(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=x(t);if(0===n.name.indexOf(P)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(P)})))throw n.data.data;return q(this,(function(){return e.machine.transition(e.state,n)}))},a.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 '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(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}}},a.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)},a.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},a.prototype.exec=function(n,i,r){void 0===r&&(r=this.machine.options.actions);var o,s=i.context,a=i._event,u=n.exec||function(t,e){return e&&e[t]||void 0}(n.type,r),c=p(u)?u:u?u.exec:n.exec;if(c)try{return c(s,a.data,{action:n,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case I:var h=n;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to):this.send(h._event);break;case L:this.cancel(n.sendId);break;case O:if(this.status!==t.InterpreterStatus.Running)return;var l=n.activity;if(!this.state.activities[l.id||l.type])break;if(l.type===e.Invoke){var d="string"==typeof(o=l.src)?{type:o}:o,v=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=l.id,m=l.data,b="autoForward"in l?l.autoForward:!!l.forward;if(!v)return;var x=m?f(m,s,a):void 0;if("string"==typeof v)return;var w=p(v)?v(s,a.data,{data:x,src:d,meta:l.meta}):v;if(!w)return;var S=void 0;g(w)&&(w=x?w.withContext(x):w,S={autoForward:b}),this.spawn(w,y,S)}else this.spawnActivity(l);break;case T:this.stopChild(n.activity.id);break;case k:var E=n.label,_=n.value;E?this.logger(E,_):this.logger(_)}},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(l(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(g(t))return this.spawnMachine(t,i(i({},n),{id:e}));if(null!==(r=t)&&"object"==typeof r&&"transition"in r&&"function"==typeof r.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'.concat(e,'" of type "').concat(typeof t,'".'));var r,o},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var r=new a(t,i(i({},this.options),{parent:this,id:e.id||t.id})),o=i(i({},Y),e);o.sync&&r.onTransition((function(t){n.send(N,{state:t,id:r.id})}));var s=r;return this.children.set(r.id,s),o.autoForward&&this.forwardTo.add(r.id),r.onDone((function(t){n.removeChild(r.id),n.send(x(t,{origin:r.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=Q(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,i=this,r=!1;t.then((function(t){r||(n=t,i.removeChild(e),i.send(x(D(e,t),{origin:e})))}),(function(t){if(!r){i.removeChild(e);var n=M(e,t);try{i.send(x(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var o={id:e,send:function(){},subscribe:function(e,n,i){var r=w(e,n,i),o=!1;return t.then((function(t){o||(r.next(t),o||r.complete())}),(function(t){o||r.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,o),o},a.prototype.spawnCallback=function(t,e){var n,i,r=this,o=!1,s=new Set,a=new Set;try{i=t((function(t){n=t,a.forEach((function(e){return e(t)})),o||r.send(x(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(M(e,t))}if(l(i))return this.spawnPromise(i,e);var u={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){o=!0,p(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,u),u},a.prototype.spawnObservable=function(t,e){var n,i=this,r=t.subscribe((function(t){n=t,i.send(x(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(x(M(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(x(D(e),{origin:e}))})),o={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return r.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}};return this.children.set(e,o),o},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.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)}},a.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})},a.prototype.attachDev=function(){var t=H();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:i({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}K(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[y]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),a.interpret=tt,a}();function tt(t,e){return new Z(t,e)}t.Interpreter=Z,t.interpret=tt,t.spawn=function(t,e){var n=function(t){return v(t)?i(i({},Y),{name:t}):i(i(i({},Y),{name:m()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):function(t,e,n){var i=function(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}}}(e);if(i.deferred=!0,g(t)){var r=i.state=q(void 0,(function(){return(n?t.withContext(n):t).initialState}));i.getSnapshot=function(){return r}}return i}(t,n.name)}(J[J.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */var e,n,r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function i(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function s(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}!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",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a={},c=e.Start,u=e.Stop,f=e.Raise,h=e.Send,d=e.Cancel;e.NullEvent;var l=e.Assign;e.After,e.DoneState;var p=e.Log,v=e.Init;e.Invoke,e.ErrorExecution;var y,g=e.ErrorPlatform,m=e.ErrorCustom,x=e.Update,b=e.Choose,S=e.Pure;function w(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:L(t)?_(t):"string"!=typeof t?t:_(function(t,e){try{return L(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function _(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function E(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}function O(t){return void 0===t?[]:function(t){return L(t)?t:[t]}(t)}function I(t,e,n){var r,o;if(k(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),c=a.next();!c.done;c=a.next()){var u=c.value,f=t[u];k(f)?s[u]=f(e,n.data):s[u]=f}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function T(t){return t instanceof Promise||!(null===t||!k(t)&&"object"!=typeof t||!k(t.then))}function A(t,e,n,r){return t?n.reduce((function(t,n){var o,s,a=n.assignment,c={state:r,action:n,_event:e},u={};if(k(a))u=a(t,e.data,c);else try{for(var f=i(Object.keys(a)),h=f.next();!h.done;h=f.next()){var d=h.value,l=a[d];u[d]=k(l)?l(t,e.data,c):l}}catch(t){o={error:t}}finally{try{h&&!h.done&&(s=f.return)&&s.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,u)}),t):t}function L(t){return Array.isArray(t)}function k(t){return"function"==typeof t}function j(t){return"string"==typeof t}var C=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function P(t){return!!t&&"__xstatenode"in t}(y={})[C]=function(){return this},y[Symbol.observable]=function(){return this};var N=function(){var t=0;return function(){return(++t).toString(16)}}();function D(t,e){return j(t)||"number"==typeof t?r({type:t},e):t}function M(t,e){if(!j(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=D(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function R(t,e,n){var r=function(){},i="object"==typeof t,o=i?t:null;return{next:((i?t.next:t)||r).bind(o),error:((i?t.error:e)||r).bind(o),complete:((i?t.complete:n)||r).bind(o)}}var z=M({type:v});function V(t,e){return e&&e[t]||void 0}function J(t,e){var n;if(j(t)||"number"==typeof t)n=k(i=V(t,e))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(k(t))n={type:t.name||t.toString(),exec:t};else{var i;if(k(i=V(t.type,e)))n=r(r({},t),{exec:i});else if(i){var o=i.type||t.type;n=r(r(r({},i),t),{type:o})}else n=t}return n}var q=function(t,e){return t?(L(t)?t:[t]).map((function(t){return J(t,e)})):[]};function U(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function $(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function F(t,a,c,d,v,y,g){void 0===g&&(g=!1);var m=g?[]:function(t){var e,n,r=[];try{for(var o=i(t),s=o.next();!s.done;s=o.next())for(var a=s.value,c=0;c<a.actions.length;)a.actions[c].type!==l?c++:(r.push(a.actions[c]),a.actions.splice(c,1))}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}(v),x=m.length?A(c,d,m,a):c,w=g?[c]:void 0,_=[];function I(i,v){var m;switch(v.type){case f:var E=function(t,e,n,i){var o,s={_event:n},a=M(k(t.event)?t.event(e,n.data,s):t.event);if(j(t.delay)){var c=i&&i[t.delay];o=k(c)?c(e,n.data,s):c}else o=k(t.delay)?t.delay(e,n.data,s):t.delay;return r(r({},t),{type:f,_event:a,delay:o})}(v,x,d,t.options.delays);return y&&"number"==typeof E.delay&&y(E,x,d),E;case h:var I=function(t,e,n,i){var o,s={_event:n},a=M(k(t.event)?t.event(e,n.data,s):t.event);if(j(t.delay)){var c=i&&i[t.delay];o=k(c)?c(e,n.data,s):c}else o=k(t.delay)?t.delay(e,n.data,s):t.delay;var u=k(t.to)?t.to(e,n.data,s):t.to;return r(r({},t),{to:u,_event:a,event:a.data,delay:o})}(v,x,d,t.options.delays);return y&&I.to!==n.Internal&&("entry"===i?_.push(I):y(I,x,d)),I;case p:var T=function(t,e,n){return r(r({},t),{value:j(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})}(v,x,d);return null==y||y(T,x,d),T;case b:if(!(N=null===(m=v.conds.find((function(e){var n=function(t,e){if(t)return j(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:k(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}(e.cond,t.options.guards);return!n||function(t,e,n,r,i){var o=t.options.guards,s={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,s);var a=null==o?void 0:o[e.type];if(!a)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return a(n,r.data,s)}(t,n,x,d,y?void 0:a)})))||void 0===m?void 0:m.actions))return[];var L=o(F(t,a,x,d,[{type:i,actions:q(O(N),t.options.actions)}],y,g),2),C=L[0],P=L[1];return x=P,null==w||w.push(x),C;case S:var N;if(!(N=v.get(x,d.data)))return[];var D=o(F(t,a,x,d,[{type:i,actions:q(O(N),t.options.actions)}],y,g),2),R=D[0],z=D[1];return x=z,null==w||w.push(x),R;case u:T=function(t,n,r){var i=k(t.activity)?t.activity(n,r.data):t.activity,o="string"==typeof i?{id:i}:i;return{type:e.Stop,activity:o}}(v,x,d);return null==y||y(T,c,d),T;case l:x=A(x,d,[v],y?void 0:a),null==w||w.push(x);break;default:var V=J(v,t.options.actions),U=V.exec;if(y)y(V,x,d);else if(U&&w){var $=w.length-1;V=r(r({},V),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];U.apply(void 0,s([w[$]],o(e),!1))}})}return V}}return[E(v.map((function(t){var e,n,r=[];try{for(var o=i(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value,c=I(t.type,a);c&&(r=r.concat(c))}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return _.forEach((function(t){y(t,x,d)})),_.length=0,r}))),x]}var X=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=a,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||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),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,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],o(new Set(E(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(r.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:z,_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 r=z;return new t({value:e.value,context:n,_event:r,_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="."),j(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,r){void 0===r&&(r=".");var i=w(e,r),o=w(n,r);return j(o)?!!j(i)&&o===i:j(i)?i in o:Object.keys(i).every((function(e){return e in o&&t(i[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),Q={deferEvents:!1},B=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},Q),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}(),G=[],H=function(t,e){G.push(t);var n=e(t);return G.pop(),n};function K(t,e,n){var r=function(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[C]=function(){return this},e}(e);if(r.deferred=!0,P(t)){var i=r.state=H(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var W=new Map,Y=0,Z=function(){return"x:".concat(Y++)},tt=function(t,e){return W.set(t,e),t},et=function(t){return W.get(t)},nt=function(t){W.delete(t)};function rt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function it(t){if(rt()){var e=function(){var t=rt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ot(t,e){void 0===e&&(e={});var n=t.initialState,i=new Set,o=[],s=!1,a=function(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[C]=function(){return this},e),t)}({id:e.id,send:function(e){o.push(e),function(){if(!s){for(s=!0;o.length>0;){var e=o.shift();n=t.transition(n,e,c),i.forEach((function(t){return t.next(n)}))}s=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=R(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),c={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(c):n,a}var st,at={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(st=t.InterpreterStatus||(t.InterpreterStatus={}))[st.NotStarted=0]="NotStarted",st[st.Running=1]="Running",st[st.Stopped=2]="Stopped";var ct=function(){function a(i,o){void 0===o&&(o=a.defaultOptions);var s=this;this.machine=i,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=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(e,n){if(L(e))return s.batch(e),s.state;var r=M(D(e,n));if(s.status===t.InterpreterStatus.Stopped)return s.state;if(s.status!==t.InterpreterStatus.Running&&!s.options.deferEvents)throw new Error('Event "'.concat(r.name,'" was sent to uninitialized service "').concat(s.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(r.data)));return s.scheduler.schedule((function(){s.forward(r);var t=s._nextState(r);s.update(t,r)})),s._state},this.sendTo=function(e,i,o){var a,c=s.parent&&(i===n.Parent||s.parent.id===i),u=c?s.parent:j(i)?i===n.Internal?s:s.children.get(i)||et(i):(a=i)&&"function"==typeof a.send?i:void 0;if(u)if("machine"in u){if(s.status!==t.InterpreterStatus.Stopped||s.parent!==u||s.state.done){var f=r(r({},e),{name:e.name===m?"".concat($(s.id)):e.name,origin:s.sessionId});!o&&s.machine.config.predictableActionArguments?s._outgoingQueue.push([u,f]):u.send(f)}}else!o&&s.machine.config.predictableActionArguments?s._outgoingQueue.push([u,e.data]):u.send(e.data);else if(!c)throw new Error("Unable to send event to child '".concat(i,"' from service '").concat(s.id,"'."))},this._exec=function(n,r,i,o){void 0===o&&(o=s.machine.options.actions);var a,l=n.exec||V(n.type,o),v=k(l)?l:l?l.exec:n.exec;if(v)try{return v(r,i.data,s.machine.config.predictableActionArguments?{action:n,_event:i}:{action:n,state:s.state,_event:i})}catch(t){throw s.parent&&s.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case f:var y=n;s.defer(y);break;case h:var g=n;if("number"==typeof g.delay)return void s.defer(g);g.to?s.sendTo(g._event,g.to,i===z):s.send(g._event);break;case d:s.cancel(n.sendId);break;case c:if(s.status!==t.InterpreterStatus.Running)return;var m=n.activity;if(!s.machine.config.predictableActionArguments&&!s.state.activities[m.id||m.type])break;if(m.type===e.Invoke){var x="string"==typeof(a=m.src)?{type:a}:a,b=s.machine.options.services?s.machine.options.services[x.type]:void 0,S=m.id,w=m.data,_="autoForward"in m?m.autoForward:!!m.forward;if(!b)return;var E=w?I(w,r,i):void 0;if("string"==typeof b)return;var O=k(b)?b(r,i.data,{data:E,src:x,meta:m.meta}):b;if(!O)return;var T=void 0;P(O)&&(O=E?O.withContext(E):O,T={autoForward:_}),s.spawn(O,S,T)}else s.spawnActivity(m);break;case u:s.stopChild(n.activity.id);break;case p:var A=n,L=A.label,j=A.value;L?s.logger(L,j):s.logger(j)}};var l=r(r({},a.defaultOptions),o),v=l.clock,y=l.logger,g=l.parent,x=l.id,b=void 0!==x?x:i.id;this.id=b,this.logger=y,this.clock=v,this.parent=g,this.options=l,this.scheduler=new B({deferEvents:this.options.deferEvents}),this.sessionId=Z()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:H(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,r;try{for(var o=i(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&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},a.prototype.update=function(t,e){var n,r,o,s,a,c,u,f,h=this;if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==z||!this.options.execute)for(var d=void 0;d=this._outgoingQueue.shift();)d[0].send(d[1]);else this.execute(this.state);if(this.children.forEach((function(t){h.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=i(this.eventListeners),p=l.next();!p.done;p=l.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var v=i(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 g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(c=g.return)&&c.call(g)}finally{if(a)throw a.error}}if(this.state.done){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===h.machine})),b=x&&x.doneData?I(x.doneData,t.context,e):void 0;this._doneEvent=U(this.id,b);try{for(var S=i(this.doneListeners),w=S.next();!w.done;w=S.next()){(0,w.value)(this._doneEvent)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(f=S.return)&&f.call(S)}finally{if(u)throw u.error}}this._stop(),this._stopChildren(),nt(this.sessionId)}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,r){var i=this,o=R(e,n,r);this.listeners.add(o.next),this.status!==t.InterpreterStatus.NotStarted&&o.next(this.state);var s=function(){i.doneListeners.delete(s),i.stopListeners.delete(s),o.complete()};return this.status===t.InterpreterStatus.Stopped?o.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:function(){i.listeners.delete(o.next),i.doneListeners.delete(s),i.stopListeners.delete(s)}}},a.prototype.onEvent=function(t){return this.eventListeners.add(t),this},a.prototype.onSend=function(t){return this.sendListeners.add(t),this},a.prototype.onChange=function(t){return this.contextListeners.add(t),this},a.prototype.onStop=function(t){return this.stopListeners.add(t),this},a.prototype.onDone=function(e){return this.status===t.InterpreterStatus.Stopped&&this._doneEvent?e(this._doneEvent):this.doneListeners.add(e),this},a.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},a.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),tt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:H(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(X.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,z)})),this},a.prototype._stopChildren=function(){this.children.forEach((function(t){k(t.stop)&&t.stop()})),this.children.clear()},a.prototype._stop=function(){var e,n,r,o,s,a,c,u,f,h;try{for(var d=i(this.listeners),l=d.next();!l.done;l=d.next()){var p=l.value;this.listeners.delete(p)}}catch(t){e={error:t}}finally{try{l&&!l.done&&(n=d.return)&&n.call(d)}finally{if(e)throw e.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){r={error:t}}finally{try{y&&!y.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.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){s={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(s)throw s.error}}try{for(var x=i(this.doneListeners),b=x.next();!b.done;b=x.next()){p=b.value;this.doneListeners.delete(p)}}catch(t){c={error:t}}finally{try{b&&!b.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0;try{for(var S=i(Object.keys(this.delayedEventsMap)),w=S.next();!w.done;w=S.next()){var _=w.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){f={error:t}}finally{try{w&&!w.done&&(h=S.return)&&h.call(S)}finally{if(f)throw f.error}}this.scheduler.clear(),this.scheduler=new B({deferEvents:this.options.deferEvents})},a.prototype.stop=function(){var t=this,e=this.scheduler;return this._stop(),e.schedule((function(){var e=M({type:"xstate.stop"}),r=H(t,(function(){var r=E(s([],o(t.state.configuration),!1).sort((function(t,e){return e.order-t.order})).map((function(e){return q(e.onExit,t.machine.options.actions)}))),i=o(F(t.machine,t.state,t.state.context,e,[{type:"exit",actions:r}],t.machine.config.predictableActionArguments?t._exec:void 0,t.machine.config.predictableActionArguments||t.machine.config.preserveActionOrder),2),a=i[0],c=i[1],u=new X({value:t.state.value,context:c,_event:e,_sessionid:t.sessionId,historyValue:void 0,history:t.state,actions:a.filter((function(t){return!function(t){return(t.type===f||t.type===h&&t.to===n.Internal)&&"number"!=typeof t.delay}(t)})),activities:{},events:[],configuration:[],transitions:[],children:{},done:t.state.done,tags:t.state.tags,machine:t.machine});return u.changed=!0,u}));t.update(r,e),t._stopChildren(),nt(t.sessionId)})),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var a=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule((function(){var t,c,u=n.state,f=!1,h=[],d=function(t){var e=M(t);n.forward(e),u=H(n,(function(){return n.machine.transition(u,e,void 0,a||void 0)})),h.push.apply(h,s([],o(n.machine.config.predictableActionArguments?u.actions:u.actions.map((function(t){return function(t,e){var n=t.exec;return r(r({},t),{exec:void 0!==n?function(){return n(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0})}(t,u)}))),!1)),f=f||!!u.changed};try{for(var l=i(e),p=l.next();!p.done;p=l.next()){d(p.value)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(c=l.return)&&c.call(l)}finally{if(t)throw t.error}}u.changed=f,u.actions=h,n.update(u,M(e[e.length-1]))}))}},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype._nextState=function(t,e){var n=this;void 0===e&&(e=!!this.machine.config.predictableActionArguments&&this._exec);var r=M(t);if(0===r.name.indexOf(g)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(g)})))throw r.data.data;return H(this,(function(){return n.machine.transition(n.state,r,void 0,e||void 0)}))},a.prototype.nextState=function(t){return this._nextState(t,!1)},a.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(s,"'."));a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},a.prototype.defer=function(t){var e=this,n=this.clock.setTimeout((function(){"to"in t&&t.to?e.sendTo(t._event,t.to,!0):e.send(t._event)}),t.delay);t.id&&(this.delayedEventsMap[t.id]=n)},a.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},a.prototype.exec=function(t,e,n){void 0===n&&(n=this.machine.options.actions),this._exec(t,e.context,e._event,n)},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),k(e.stop)&&e.stop())},a.prototype.spawn=function(e,n,i){if(this.status!==t.InterpreterStatus.Running)return K(e,n);if(T(e))return this.spawnPromise(Promise.resolve(e),n);if(k(e))return this.spawnCallback(e,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=e)&&"id"in s)return this.spawnActor(e,n);if(function(t){try{return"subscribe"in t&&k(t.subscribe)}catch(t){return!1}}(e))return this.spawnObservable(e,n);if(P(e))return this.spawnMachine(e,r(r({},i),{id:n}));if(null!==(o=e)&&"object"==typeof o&&"transition"in o&&"function"==typeof o.transition)return this.spawnBehavior(e,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof e,'".'));var o,s},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var i=new a(t,r(r({},this.options),{parent:this,id:e.id||t.id})),o=r(r({},at),e);o.sync&&i.onTransition((function(t){n.send(x,{state:t,id:i.id})}));var s=i;return this.children.set(i.id,s),o.autoForward&&this.forwardTo.add(i.id),i.onDone((function(t){n.removeChild(i.id),n.send(M(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=ot(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(M(U(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=$(e,t);try{i.send(M(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=R(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[C]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,r,i,o=this,s=!1,a=new Set,c=new Set;try{i=t((function(t){r=t,c.forEach((function(e){return e(t)})),s||o.send(M(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send($(e,t))}if(T(i))return this.spawnPromise(i,e);var u=((n={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){var e=R(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){s=!0,k(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[C]=function(){return this},n);return this.children.set(e,u),u},a.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(M(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(M($(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(M(U(e),{origin:e}))})),s=((n={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return r},toJSON:function(){return{id:e}}})[C]=function(){return this},n);return this.children.set(e,s),s},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.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)}},a.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[C]=function(){return this},n))},a.prototype.attachDev=function(){var t=rt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(r(r({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:r({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}it(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[C]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},a.interpret=ut,a}();function ut(t,e){return new ct(t,e)}t.Interpreter=ct,t.interpret=ut,t.spawn=function(t,e){var n=function(t){return j(t)?r(r({},at),{name:t}):r(r(r({},at),{name:N()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):K(t,n.name)}(G[G.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -15,2 +15,2 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).XState={})}(this,(function(t){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function o(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}var a={};function s(t){return Object.keys(t)}function c(t,e,n){void 0===n&&(n=".");var r=f(t,n),i=f(e,n);return A(i)?!!A(r)&&i===r:A(r)?r in i:s(r).every((function(t){return t in i&&c(r[t],i[t])}))}function u(t){try{return A(t)||"number"==typeof t?"".concat(t):t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function h(t,e){try{return E(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function f(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:E(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function p(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}return a}var v=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function y(t){return t?A(t)?[[t]]:g(s(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?y(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function g(t){var e;return(e=[]).concat.apply(e,o([],i(t),!1))}function m(t){return E(t)?t:[t]}function S(t){return void 0===t?[]:m(t)}function x(t,e,n){var i,o;if(N(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];N(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function w(t){return t instanceof Promise||!(null===t||!N(t)&&"object"!=typeof t||!N(t.then))}function b(t,e){var n,o,a=i([[],[]],2),s=a[0],c=a[1];try{for(var u=r(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 _(t,e){return d(t.states,(function(t,n){if(t){var r=(A(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function T(t,e,n,i){return t?n.reduce((function(t,n){var o,a,c=n.assignment,u={state:i,action:n,_event:e},h={};if(N(c))h=c(t,e.data,u);else try{for(var f=r(s(c)),l=f.next();!l.done;l=f.next()){var d=l.value,p=c[d];h[d]=N(p)?p(t,e.data,u):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,h)}),t):t}function E(t){return Array.isArray(t)}function N(t){return"function"==typeof t}function A(t){return"string"==typeof t}function O(t,e){if(t)return A(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:N(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var P=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C=function(){var t=0;return function(){return(++t).toString(16)}}();function V(t,n){return A(t)||"number"==typeof t?e({type:t},n):t}function D(t,n){if(!A(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=V(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function L(t,n){return m(n).map((function(n){return void 0===n||"string"==typeof n||k(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function R(t,e,n,r,i){var o=t.options.guards,a={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,a);var s=o[e.type];if(!s)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return s(n,r.data,a)}function M(t){return"string"==typeof t?{type:t}:t}function z(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(I=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",I.Stop="xstate.stop",I.Raise="xstate.raise",I.Send="xstate.send",I.Cancel="xstate.cancel",I.NullEvent="",I.Assign="xstate.assign",I.After="xstate.after",I.DoneState="done.state",I.DoneInvoke="done.invoke",I.Log="xstate.log",I.Init="xstate.init",I.Invoke="xstate.invoke",I.ErrorExecution="error.execution",I.ErrorCommunication="error.communication",I.ErrorPlatform="error.platform",I.ErrorCustom="xstate.error",I.Update="xstate.update",I.Pure="xstate.pure",I.Choose="xstate.choose",(j=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",j.Internal="#_internal";var F=function(t){return"atomic"===t.type||"final"===t.type};function U(t){return s(t.states).map((function(e){return t.states[e]}))}function B(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(B)))}function J(t,e){var n,i,o,a,s,c,u,h,f=q(new Set(t)),l=new Set(e);try{for(var d=r(l),p=d.next();!p.done;p=d.next())for(var v=(T=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=q(l);try{for(var g=r(l),m=g.next();!m.done;m=g.next()){if("compound"!==(T=m.value).type||y.get(T)&&y.get(T).length){if("parallel"===T.type)try{for(var S=(s=void 0,r(U(T))),x=S.next();!x.done;x=S.next()){var w=x.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{x&&!x.done&&(c=S.return)&&c.call(S)}finally{if(s)throw s.error}}}else f.get(T)?f.get(T).forEach((function(t){return l.add(t)})):T.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=r(l),_=b.next();!_.done;_=b.next()){var T;for(v=(T=_.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 q(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.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 i}function $(t,e){return function t(e,n){var r=n.get(e);if(!r)return{};if("compound"===e.type){var i=r[0];if(!i)return{};if(F(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,q(J([t],e)))}function X(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?U(e).some((function(e){return"final"===e.type&&X(t,e)})):"parallel"===e.type&&U(e).every((function(e){return H(t,e)}))}function G(t){return new Set(g(t.map((function(t){return t.tags}))))}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),rt=t.ActionTypes.Init,it=t.ActionTypes.Invoke,ot=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),at=t.ActionTypes.ErrorCustom,st=t.ActionTypes.Update,ct=t.ActionTypes.Choose,ut=t.ActionTypes.Pure,ht=D({type:rt});function ft(t,e){return e&&e[t]||void 0}function lt(t,n){var r;if(A(t)||"number"==typeof t)r=N(i=ft(t,n))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(N(t))r={type:t.name||t.toString(),exec:t};else{var i;if(N(i=ft(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return r}var dt=function(t,e){return t?(E(t)?t:[t]).map((function(t){return lt(t,e)})):[]};function pt(t){var n=lt(t);return e(e({id:A(t)?t:n.id},n),{type:n.type})}function vt(e){return A(e)?{type:W,event:e}:yt(e,{to:t.SpecialTargets.Internal})}function yt(t,e){return{to:e?e.to:void 0,type:Y,event:N(t)?t:V(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:N(t)?t.name:u(t)}}function gt(n,r){return yt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function mt(){return gt(st)}var St=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Z,sendId:t}};function wt(e){var n=pt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function bt(e){var n=N(e)?e:pt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var _t=function(t){return{type:et,assignment:t}};function Tt(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Et(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Nt(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function At(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Ot(t,n){return yt((function(t,e){return e}),e(e({},n),{to:t}))}function Pt(n,r,a,s,c,u){void 0===u&&(u=!1);var h=i(u?[[],c]:b(c,(function(t){return t.type===et})),2),f=h[0],l=h[1],d=f.length?T(a,s,f,r):a,p=u?[a]:void 0;return[g(l.map((function(a){var c;switch(a.type){case W:return{type:W,_event:D(a.event)};case Y:return function(t,n,r,i){var o,a={_event:r},s=D(N(t.event)?t.event(n,r.data,a):t.event);if(A(t.delay)){var c=i&&i[t.delay];o=N(c)?c(n,r.data,a):c}else o=N(t.delay)?t.delay(n,r.data,a):t.delay;var u=N(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(a,d,s,n.options.delays);case nt:return function(t,n,r){return e(e({},t),{value:A(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(a,d,s);case ct:if(!(v=null===(c=a.conds.find((function(t){var e=O(t.cond,n.options.guards);return!e||R(n,e,d,s,r)})))||void 0===c?void 0:c.actions))return[];var h=i(Pt(n,r,d,s,dt(S(v),n.options.actions),u),2),f=h[0],l=h[1];return d=l,null==p||p.push(d),f;case ut:var v;if(!(v=a.get(d,s.data)))return[];var y=i(Pt(n,r,d,s,dt(S(v),n.options.actions),u),2),g=y[0],m=y[1];return d=m,null==p||p.push(d),g;case Q:return function(e,n,r){var i=N(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(a,d,s);case et:d=T(d,s,[a],r),null==p||p.push(d);break;default:var x=lt(a,n.options.actions),w=x.exec;if(w&&p){var b=p.length-1;x=e(e({},x),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];w.apply(void 0,o([p[b]],i(e),!1))}})}return x}})).filter((function(t){return!!t}))),d]}var kt=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=a,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||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),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,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return o([],i(new Set(g(o([],i(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(r.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:ht,_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 r=ht;return new t({value:e.value,context:n,_event:r,_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 r=s(t);return r.concat.apply(r,o([],i(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this,r=(t.configuration,t.transitions,t.tags),i=(t.machine,n(t,["configuration","transitions","tags","machine"]));return e(e({},i),{tags:Array.from(r)})},t.prototype.matches=function(t){return c(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),It=[],jt=function(t,e){It.push(t);var n=e(t);return It.pop(),n};function Ct(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}}}function Vt(t,e,n){var r=Ct(e);if(r.deferred=!0,k(t)){var i=r.state=jt(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Dt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Lt(t){return e(e({type:it},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:it,src:Dt(t.src)})}})}var Rt={},Mt=function(t){return"#"===t[0]},zt=function(){function a(t,n,c){var u,h=this;void 0===c&&(c="context"in t?t.context:void 0),this.config=t,this._context=c,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.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},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:"."),this.id=this.config.id||o([this.machine.key],i(this.path),!1).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&&s(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(function(t,n){var r,i=new a(t,{_parent:h,_key:n});return Object.assign(h.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Rt;var f=0;!function t(e){var n,i;e.order=f++;try{for(var o=r(U(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=S(this.config.entry||this.config.onEntry).map((function(t){return lt(t)})),this.onExit=S(this.config.exit||this.config.onExit).map((function(t){return lt(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=S(this.config.invoke).map((function(t,n){var r,i;if(k(t))return h.machine.options.services=e(((r={})[t.id]=t,r),h.machine.options.services),Lt({src:t.id,id:t.id});if(A(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||N(t.src)){var o="".concat(h.id,":invocation[").concat(n,"]");return h.machine.options.services=e(((i={})[o]=t.src,i),h.machine.options.services),Lt(e(e({id:o},t),{src:o}))}var a=t.src;return Lt(e(e({id:a.type},t),{src:a}))})),this.activities=S(this.config.activities).concat(this.invoke).map((function(t){return pt(t)})),this.transition=this.transition.bind(this),this.tags=S(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||B(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){var r=this.options,i=r.actions,o=r.activities,s=r.guards,c=r.services,u=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},null!=n?n:this.context)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"context",{get:function(){return N(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(a.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:d(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.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.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:!1,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var r=n.eventType===t;return e?r:r||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=Tt(N(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(yt(r,{delay:e})),t.onExit.push(xt(r)),r};return(E(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=A(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return S(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof kt?t.value:f(t,this.delimiter);if(A(r)){var a=this.getStateNode(r).initial;return void 0!==a?this.getStateNodes(((e={})[r]=a,e)):[this,this.states[r]]}var c=s(r),u=[this];return u.push.apply(u,o([],i(g(c.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),u},a.prototype.handles=function(t){var e=u(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(J([],this.getStateNodes(t.value)));return new kt(e(e({},t),{value:this.resolve(t.value),configuration:n,done:H(n,this),tags:G(n)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=s(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}var d=s(a).map((function(t){return a[t]})),p=g(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=g(d.map((function(t){return t.entrySet}))),y=g(s(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:g(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:g(s(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return A(t)?this.transitionLeafNode(t,e,n):1===s(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,D(e))},a.prototype.next=function(t,e){var n,a,s,u=this,h=e.name,l=[],d=[];try{for(var p=r(this.getCandidates(h)),y=p.next();!y.done;y=p.next()){var m=y.value,S=m.cond,x=m.in,w=t.context,b=!x||(A(x)&&Mt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):c(f(x,this.delimiter),v(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||R(this.machine,S,w,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(S.name||S.type,"' in transition for event '").concat(h,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(_&&b){void 0!==m.target&&(d=m.target),l.push.apply(l,o([],i(m.actions),!1)),s=m;break}}}catch(t){n={error:t}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}if(s){if(!d.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:l};var T=g(d.map((function(e){return u.getRelativeStateNodes(e,t.historyValue)}))),E=!!s.internal;return{transitions:[s],entrySet:E?[]:g(T.map((function(t){return u.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:T,source:t,actions:l}}},a.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},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=J([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?J(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){X(f,m=p.value)||t.entrySet.push(m)}}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=r(f),y=v.next();!y.done;y=v.next()){var m;X(l,m=y.value)&&!X(t.exitSet,m.parent)||t.exitSet.push(m)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}var S=g(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Et(r.id,r.doneData),Et(o.id,r.doneData?x(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&U(a).every((function(e){return H(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var w=new Set(t.entrySet),b=new Set(t.exitSet),_=i([g(Array.from(w).map((function(t){return o(o([],i(t.activities.map((function(t){return wt(t)}))),!1),i(t.onEntry),!1)}))).concat(S.map(vt)),g(Array.from(b).map((function(t){return o(o([],i(t.onExit),!1),i(t.activities.map((function(t){return bt(t)}))),!1)})))],2),T=_[0],E=_[1];return dt(E.concat(t.actions).concat(T),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,a,s=D(e);if(t instanceof kt)r=void 0===n?t:this.resolveState(kt.from(t,n));else{var c=A(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(kt.from(c,u))}if(this.strict&&!this.events.includes(s.name)&&(a=s.name,!/^(done|error)\./.test(a)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(s.name,"'"));var h=this._transition(r.value,r,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=J([],this.getStateNodes(r.value)),d=h.configuration.length?J(f,h.configuration):f;return h.configuration=o([],i(d),!1),this.resolveTransition(h,r,s)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,a=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o([],i(a),!1)),t},a.prototype.resolveTransition=function(n,o,a,c){var u,h,f=this;void 0===a&&(a=ht),void 0===c&&(c=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0,p=d?$(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=o?o.context:c,g=this.getActions(n,y,a,o),m=o?e({},o.activities):{};try{for(var S=r(g),w=S.next();!w.done;w=S.next()){var T=w.value;T.type===K?m[T.activity.id||T.activity.type]=T:T.type===Q&&(m[T.activity.id||T.activity.type]=!1)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=S.return)&&h.call(S)}finally{if(u)throw u.error}}var E,N,O=i(Pt(this,o,y,a,g,this.machine.config.preserveActionOrder),2),P=O[0],k=O[1],I=i(b(P,(function(e){return e.type===W||e.type===Y&&e.to===t.SpecialTargets.Internal})),2),j=I[0],C=I[1],V=P.filter((function(t){var e;return t.type===K&&(null===(e=t.activity)||void 0===e?void 0:e.type)===it})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=M(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?x(t.data,n,r):void 0,c=a?Vt(a,t.id,s):Ct(t.id);return c.meta=t,c}(e.activity,f.machine,k,a),t}),o?e({},o.children):{}),D=p?n.configuration:o?o.configuration:[],L=H(D,this),R=new kt({value:p||o.value,context:k,_event:a,_sessionid:o?o._sessionid:null,historyValue:p?v?(E=v,N=p,{current:N,states:_(E,N)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?C:[],activities:p?m:o?o.activities:{},events:[],configuration:D,transitions:n.transitions,children:V,done:L,tags:null==o?void 0:o.tags,machine:this}),z=y!==k;R.changed=a.name===st||z;var F=R.history;F&&delete F.history;var U=!L&&(this._transient||l.some((function(t){return t._transient})));if(!(d||U&&""!==a.name))return R;var B=R;if(!L)for(U&&(B=this.resolveRaisedTransition(B,{type:tt},a));j.length;){var J=j.shift();B=this.resolveRaisedTransition(B,J._event,a)}var q=B.changed||(F?!!B.actions.length||z||typeof F.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 r=s(e),i=s(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(B.value,F.value):void 0);return B.changed=q,B.history=F,B.tags=G(B.configuration),B},a.prototype.getStateNode=function(t){if(Mt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '".concat(t,"' from '").concat(this.id,"'; no child states exist."));var e=this.states[t];if(!e)throw new Error("Child state '".concat(t,"' does not exist on '").concat(this.id,"'"));return e},a.prototype.getStateNodeById=function(t){var e=Mt(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 '#".concat(e,"' does not exist on machine '").concat(this.id,"'"));return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Mt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Rt;switch(this.type){case"parallel":return d(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Rt}));case"compound":if(A(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return s(t).length?d(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Rt})):this.initialStateValue||{};default:return t||Rt}},a.prototype.getResolvedPath=function(t){if(Mt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '".concat(t,"'"));return e.path}return h(t,this.delimiter)},Object.defineProperty(a.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=p(this.states,(function(t){return t.initialStateValue||Rt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));e=F(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),a.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(a.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=A(e.target)&&Mt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(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 '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(r)},a.prototype.historyValue=function(t){if(s(this.states).length)return{current:t||this.initialStateValue,states:p(this.states,(function(e,n){if(!t)return e.historyValue();var r=A(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?g(y(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),c=s.next();!c.done;c=s.next()){var u=c.value;i=i[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 i})(t).current;return A(s)?[n.getStateNode(s)]:g(y(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=g(s(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var c=r(s(o)),u=c.next();!u.done;u=c.next()){var h=o[u.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add("".concat(d))}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(a.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:!1,configurable:!0}),a.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 r=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(r);try{return e.parent.getStateNodeByPath(r)}catch(t){throw new Error("Invalid transition definition for state node '".concat(e.id,"':\n").concat(t.message))}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return S(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return A(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:dt(S(t.actions)),cond:O(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(n.id)})}});return s},a.prototype.formatTransitions=function(){var t,e,a,c=this;if(this.config.on)if(Array.isArray(this.config.on))a=this.config.on;else{var u=this.config.on,h=u["*"],f=void 0===h?[]:h,l=n(u,["*"]);a=g(s(l).map((function(t){return L(t,l[t])})).concat(L("*",f)))}else a=[];var d=this.config.always?L("",this.config.always):[],p=this.config.onDone?L(String(Et(this.id)),this.config.onDone):[],v=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(L(String(Nt(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,o([],i(L(String(At(t.id)),t.onError)),!1)),e}))),y=this.after,m=g(o(o(o(o([],i(p),!1),i(v),!1),i(a),!1),i(d),!1).map((function(t){return S(t).map((function(t){return c.formatTransition(t)}))})));try{for(var x=r(y),w=x.next();!w.done;w=x.next()){var b=w.value;m.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=x.return)&&e.call(x)}finally{if(t)throw t.error}}return m},a}();var Ft={deferEvents:!1},Ut=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Ft),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}(),Bt=new Map,Jt=0,qt=function(){return"x:".concat(Jt++)},$t=function(t,e){return Bt.set(t,e),t},Xt=function(t){return Bt.get(t)},Ht=function(t){Bt.delete(t)};function Gt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Kt(t){if(Gt()){var e=function(){var t=Gt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Qt(t,n){void 0===n&&(n={});var r,i=t.initialState,o=new Set,a=[],s=!1,c=(r={id:n.id,send:function(e){a.push(e),function(){if(!s){for(s=!0;a.length>0;){var e=a.shift();i=t.transition(i,e,u),o.forEach((function(t){return t.next(i)}))}s=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=z(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},e({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},r)),u={parent:n.parent,self:c,id:n.id||"anonymous",observers:o};return i=t.start?t.start(u):i,c}var Wt,Yt={sync:!1,autoForward:!1};(Wt=t.InterpreterStatus||(t.InterpreterStatus={}))[Wt.NotStarted=0]="NotStarted",Wt[Wt.Running=1]="Running",Wt[Wt.Stopped=2]="Stopped";var Zt=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new Ut,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=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(E(e))return o.batch(e),o.state;var r=D(V(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'.concat(r.name,'" was sent to uninitialized service "').concat(o.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(r.data)));return o.scheduler.schedule((function(){o.forward(r);var t=o.nextState(r);o.update(t,r)})),o._state},this.sendTo=function(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:A(r)?o.children.get(r)||Xt(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===at?"".concat(At(o.id)):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '".concat(r,"' from service '").concat(o.id,"'."))};var a=e(e({},n.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Ut({deferEvents:this.options.deferEvents}),this.sessionId=qt()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:jt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(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&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(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&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var p=r(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=r(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 S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=S&&S.doneData?x(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Nt(this.id,w))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},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(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;$t(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:jt(this,(function(){return!A(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(kt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,ht)})),this},n.prototype.stop=function(){var e,n,i,o,a,c,u,h,f,l,d=this;try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){var y=v.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{v&&!v.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var g=r(this.stopListeners),m=g.next();!m.done;m=g.next()){(y=m.value)(),this.stopListeners.delete(y)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}try{for(var S=r(this.contextListeners),x=S.next();!x.done;x=S.next()){y=x.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(c=S.return)&&c.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.doneListeners),b=w.next();!b.done;b=w.next()){y=b.value;this.doneListeners.delete(y)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;d.exec(a,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){N(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),T=_.next();!T.done;T=_.next()){var E=T.value;this.clock.clearTimeout(this.delayedEventsMap[E])}}catch(t){f={error:t}}finally{try{T&&!T.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Ht(this.sessionId),this},n.prototype.batch=function(n){var a=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(n.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,s,c=a.state,u=!1,h=[],f=function(t){var n=D(t);a.forward(n),c=jt(a,(function(){return a.machine.transition(c,n)})),h.push.apply(h,o([],i(c.actions.map((function(t){return r=c,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i}))),!1)),u=u||!!c.changed};try{for(var l=r(n),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(t)throw t.error}}c.changed=u,c.actions=h,a.update(c,D(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=D(t);if(0===n.name.indexOf(ot)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ot)})))throw n.data.data;return jt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}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,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||ft(e.type,r),s=N(a)?a:a?a.exec:e.exec;if(s)try{return s(i,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:if(this.status!==t.InterpreterStatus.Running)return;var u=e.activity;if(!this.state.activities[u.id||u.type])break;if(u.type===t.ActionTypes.Invoke){var h=M(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,p="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var v=d?x(d,i,o):void 0;if("string"==typeof f)return;var y=N(f)?f(i,o.data,{data:v,src:h,meta:u.meta}):f;if(!y)return;var g=void 0;k(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(u);break;case Q:this.stopChild(e.activity.id);break;case nt:var m=e.label,S=e.value;m?this.logger(m,S):this.logger(S)}},n.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),N(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(N(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,n);if(function(t){try{return"subscribe"in t&&N(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof t,'".'));var i,o},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},Yt),r);a.sync&&o.onTransition((function(t){i.send(st,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(D(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=Qt(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,e){var n,r=this,i=!1;t.then((function(t){i||(n=t,r.removeChild(e),r.send(D(Nt(e,t),{origin:e})))}),(function(t){if(!i){r.removeChild(e);var n=At(e,t);try{r.send(D(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var o={id:e,send:function(){},subscribe:function(e,n,r){var i=z(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,o),o},n.prototype.spawnCallback=function(t,e){var n,r,i=this,o=!1,a=new Set,s=new Set;try{r=t((function(t){n=t,s.forEach((function(e){return e(t)})),o||i.send(D(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(At(e,t))}if(w(r))return this.spawnPromise(r,e);var c={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){o=!0,N(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,c),c},n.prototype.spawnObservable=function(t,e){var n,r=this,i=t.subscribe((function(t){n=t,r.send(D(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(D(At(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(D(Nt(e),{origin:e}))})),o={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return i.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}};return this.children.set(e,o),o},n.prototype.spawnActor=function(t,e){return this.children.set(e,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,getSnapshot:function(){},toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){var t=Gt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Kt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[P]=function(){return this},n.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=te,n}();function te(t,e){return new Zt(t,e)}var ee={raise:vt,send:yt,sendParent:gt,sendUpdate:mt,log:function(t,e){return void 0===t&&(t=St),{type:nt,label:e,expr:t}},cancel:xt,start:wt,stop:bt,assign:_t,after:Tt,done:Et,respond:function(t,n){return yt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,r){return gt((function(t,e,r){return{type:at,data:N(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=Zt,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new zt(t,e,n)},t.State=kt,t.StateNode=zt,t.actions=ee,t.assign=_t,t.createMachine=function(t,e){return new zt(t,e)},t.createSchema=function(t){return t},t.doneInvoke=Nt,t.forwardTo=Ot,t.interpret=te,t.mapState=function(t,e){var n,i,o;try{for(var a=r(s(t)),u=a.next();!u.done;u=a.next()){var h=u.value;c(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=kt.from(t,t instanceof kt?t.context:void 0);try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var h=i(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=c,t.send=yt,t.sendParent=gt,t.sendUpdate=mt,t.spawn=function(t,n){var r=function(t){return A(t)?e(e({},Yt),{name:t}):e(e(e({},Yt),{name:C()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Vt(t,r.name)}(It[It.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
***************************************************************************** */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,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 o(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(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 s(t,e,n){if(n||2===arguments.length)for(var i,r=0,o=e.length;r<o;r++)!i&&r in e||(i||(i=Array.prototype.slice.call(e,0,r)),i[r]=e[r]);return t.concat(i||Array.prototype.slice.call(e))}t.ActionTypes=void 0,(e=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Update="xstate.update",e.Pure="xstate.pure",e.Choose="xstate.choose",t.SpecialTargets=void 0,(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var c,u=t.ActionTypes.Start,h=t.ActionTypes.Stop,f=t.ActionTypes.Raise,l=t.ActionTypes.Send,d=t.ActionTypes.Cancel,p=t.ActionTypes.NullEvent,v=t.ActionTypes.Assign,y=t.ActionTypes.After,g=t.ActionTypes.DoneState,m=t.ActionTypes.Log,x=t.ActionTypes.Init,S=t.ActionTypes.Invoke,b=t.ActionTypes.ErrorExecution,w=t.ActionTypes.ErrorPlatform,_=t.ActionTypes.ErrorCustom,E=t.ActionTypes.Update,T=t.ActionTypes.Choose,A=t.ActionTypes.Pure,O=Object.freeze({__proto__:null,start:u,stop:h,raise:f,send:l,cancel:d,nullEvent:p,assign:v,after:y,doneState:g,log:m,init:x,invoke:S,errorExecution:b,errorPlatform:w,error:_,update:E,choose:T,pure:A}),k={};function j(t,e,n){void 0===n&&(n=".");var i=P(t,n),r=P(e,n);return Q(r)?!!Q(i)&&r===i:Q(i)?i in r:Object.keys(i).every((function(t){return t in r&&j(i[t],r[t])}))}function N(t){try{return Q(t)||"number"==typeof t?"".concat(t):t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function I(t,e){try{return X(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(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:X(t)?C(t):"string"!=typeof t?t:C(I(t,e));var n}function C(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){for(var n={},i=Object.keys(t),r=0;r<i.length;r++){var o=i[r];n[o]=e(t[o],o,t,r)}return n}function V(t,e,n){var i,r,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];n(h)&&(a[u]=e(h,u,t))}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(i)throw i.error}}return a}var D=function(t){return function(e){var n,i,r=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){r=r[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return r}};function R(t){return t?Q(t)?[[t]]:M(Object.keys(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?R(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function M(t){var e;return(e=[]).concat.apply(e,s([],a(t),!1))}function z(t){return X(t)?t:[t]}function B(t){return void 0===t?[]:z(t)}function U(t,e,n){var i,r;if($(t))return t(e,n.data);var a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];$(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(i)throw i.error}}return a}function F(t){return t instanceof Promise||!(null===t||!$(t)&&"object"!=typeof t||!$(t.then))}function J(t,e){return L(t.states,(function(t,n){if(t){var i=(Q(e)?void 0:e[n])||(t?t.current:void 0);if(i)return{current:i,states:J(t,i)}}}))}function q(t,e,n,i){return t?n.reduce((function(t,n){var r,a,s=n.assignment,c={state:i,action:n,_event:e},u={};if($(s))u=s(t,e.data,c);else try{for(var h=o(Object.keys(s)),f=h.next();!f.done;f=h.next()){var l=f.value,d=s[l];u[l]=$(d)?d(t,e.data,c):d}}catch(t){r={error:t}}finally{try{f&&!f.done&&(a=h.return)&&a.call(h)}finally{if(r)throw r.error}}return Object.assign({},t,u)}),t):t}function X(t){return Array.isArray(t)}function $(t){return"function"==typeof t}function Q(t){return"string"==typeof t}function H(t,e){if(t)return Q(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:$(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var G=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function K(t){return!!t&&"__xstatenode"in t}(c={})[G]=function(){return this},c[Symbol.observable]=function(){return this};var W=function(){var t=0;return function(){return(++t).toString(16)}}();function Y(t,e){return Q(t)||"number"==typeof t?i({type:t},e):t}function Z(t,e){if(!Q(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=Y(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function tt(t,e){return z(e).map((function(e){return void 0===e||"string"==typeof e||K(e)?{target:e,event:t}:i(i({},e),{event:t})}))}function et(t,e,n,i,r){var o=t.options.guards,a={state:r,cond:e,_event:i};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,i.data,a);var s=null==o?void 0:o[e.type];if(!s)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return s(n,i.data,a)}function nt(t){return"string"==typeof t?{type:t}:t}function it(t,e,n){var i=function(){},r="object"==typeof t,o=r?t:null;return{next:((r?t.next:t)||i).bind(o),error:((r?t.error:e)||i).bind(o),complete:((r?t.complete:n)||i).bind(o)}}function rt(t,e){return"".concat(t,":invocation[").concat(e,"]")}function ot(e){return(e.type===f||e.type===l&&e.to===t.SpecialTargets.Internal)&&"number"!=typeof e.delay}var at=Z({type:x});function st(t,e){return e&&e[t]||void 0}function ct(t,e){var n;if(Q(t)||"number"==typeof t)n=$(r=st(t,e))?{type:t,exec:r}:r||{type:t,exec:void 0};else if($(t))n={type:t.name||t.toString(),exec:t};else{var r;if($(r=st(t.type,e)))n=i(i({},t),{exec:r});else if(r){var o=r.type||t.type;n=i(i(i({},r),t),{type:o})}else n=t}return n}var ut=function(t,e){return t?(X(t)?t:[t]).map((function(t){return ct(t,e)})):[]};function ht(t){var e=ct(t);return i(i({id:Q(t)?t:e.id},e),{type:e.type})}function ft(t,e){return{type:f,event:"function"==typeof t?t:Y(t),delay:e?e.delay:void 0,id:null==e?void 0:e.id}}function lt(t,e,n,r){var o,a={_event:n},s=Z($(t.event)?t.event(e,n.data,a):t.event);if(Q(t.delay)){var c=r&&r[t.delay];o=$(c)?c(e,n.data,a):c}else o=$(t.delay)?t.delay(e,n.data,a):t.delay;return i(i({},t),{type:f,_event:s,delay:o})}function dt(t,e){return{to:e?e.to:void 0,type:l,event:$(t)?t:Y(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:$(t)?t.name:N(t)}}function pt(t,e,n,r){var o,a={_event:n},s=Z($(t.event)?t.event(e,n.data,a):t.event);if(Q(t.delay)){var c=r&&r[t.delay];o=$(c)?c(e,n.data,a):c}else o=$(t.delay)?t.delay(e,n.data,a):t.delay;var u=$(t.to)?t.to(e,n.data,a):t.to;return i(i({},t),{to:u,_event:s,event:s.data,delay:o})}function vt(e,n){return dt(e,i(i({},n),{to:t.SpecialTargets.Parent}))}function yt(t,e,n){return dt(e,i(i({},n),{to:t}))}function gt(){return vt(E)}var mt=function(t,e){return{context:t,event:e}};function xt(t,e){return void 0===t&&(t=mt),{type:m,label:e,expr:t}}var St=function(t,e,n){return i(i({},t),{value:Q(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})},bt=function(t){return{type:d,sendId:t}};function wt(e){var n=ht(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function _t(e){var n=$(e)?e:ht(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function Et(e,n,i){var r=$(e.activity)?e.activity(n,i.data):e.activity,o="string"==typeof r?{id:r}:r;return{type:t.ActionTypes.Stop,activity:o}}var Tt=function(t){return{type:v,assignment:t}};function At(e,n){var i=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(i)}function Ot(e,n){var i="".concat(t.ActionTypes.DoneState,".").concat(e),r={type:i,data:n,toString:function(){return i}};return r}function kt(e,n){var i="".concat(t.ActionTypes.DoneInvoke,".").concat(e),r={type:i,data:n,toString:function(){return i}};return r}function jt(e,n){var i="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),r={type:i,data:n,toString:function(){return i}};return r}function Nt(e){return{type:t.ActionTypes.Pure,get:e}}function It(t,e){return dt((function(t,e){return e}),i(i({},e),{to:t}))}function Pt(e){return{type:t.ActionTypes.Choose,conds:e}}function Ct(e,n,r,c,u,d,p){void 0===p&&(p=!1);var y=p?[]:function(t){var e,n,i=[];try{for(var r=o(t),a=r.next();!a.done;a=r.next())for(var s=a.value,c=0;c<s.actions.length;)s.actions[c].type!==v?c++:(i.push(s.actions[c]),s.actions.splice(c,1))}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return i}(u),g=y.length?q(r,c,y,n):r,x=p?[r]:void 0,S=[];function b(o,u){var y;switch(u.type){case f:var b=lt(u,g,c,e.options.delays);return d&&"number"==typeof b.delay&&d(b,g,c),b;case l:var w=pt(u,g,c,e.options.delays);return d&&w.to!==t.SpecialTargets.Internal&&("entry"===o?S.push(w):d(w,g,c)),w;case m:var _=St(u,g,c);return null==d||d(_,g,c),_;case T:if(!(j=null===(y=u.conds.find((function(t){var i=H(t.cond,e.options.guards);return!i||et(e,i,g,c,d?void 0:n)})))||void 0===y?void 0:y.actions))return[];var E=a(Ct(e,n,g,c,[{type:o,actions:ut(B(j),e.options.actions)}],d,p),2),O=E[0],k=E[1];return g=k,null==x||x.push(g),O;case A:var j;if(!(j=u.get(g,c.data)))return[];var N=a(Ct(e,n,g,c,[{type:o,actions:ut(B(j),e.options.actions)}],d,p),2),I=N[0],P=N[1];return g=P,null==x||x.push(g),I;case h:_=Et(u,g,c);return null==d||d(_,r,c),_;case v:g=q(g,c,[u],d?void 0:n),null==x||x.push(g);break;default:var C=ct(u,e.options.actions),L=C.exec;if(d)d(C,g,c);else if(L&&x){var V=x.length-1;C=i(i({},C),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];L.apply(void 0,s([x[V]],a(e),!1))}})}return C}}return[M(u.map((function(t){var e,n,i=[];try{for(var r=o(t.actions),a=r.next();!a.done;a=r.next()){var s=a.value,u=b(t.type,s);u&&(i=i.concat(u))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return S.forEach((function(t){d(t,g,c)})),S.length=0,i}))),g]}var Lt=Object.freeze({__proto__:null,actionTypes:O,initEvent:at,getActionFunction:st,toActionObject:ct,toActionObjects:ut,toActivityDefinition:ht,raise:ft,resolveRaise:lt,send:dt,resolveSend:pt,sendParent:vt,sendTo:yt,sendUpdate:gt,respond:function(t,e){return dt(t,i(i({},e),{to:function(t,e,n){return n._event.origin}}))},log:xt,resolveLog:St,cancel:bt,start:wt,stop:_t,resolveStop:Et,assign:Tt,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:At,done:Ot,doneInvoke:kt,error:jt,pure:Nt,forwardTo:It,escalate:function(e,n){return vt((function(t,n,i){return{type:_,data:$(e)?e(t,n,i):e}}),i(i({},n),{to:t.SpecialTargets.Parent}))},choose:Pt,resolveActions:Ct}),Vt=[],Dt=function(t,e){Vt.push(t);var n=e(t);return Vt.pop(),n};function Rt(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[G]=function(){return this},e}function Mt(t,e,n){var i=Rt(e);if(i.deferred=!0,K(t)){var r=i.state=Dt(void 0,(function(){return(n?t.withContext(n):t).initialState}));i.getSnapshot=function(){return r}}return i}function zt(t){var e;return i(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[G]=function(){return this},e),t)}var Bt=function(t){return"atomic"===t.type||"final"===t.type};function Ut(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function Ft(t){return Ut(t).filter((function(t){return"history"!==t.type}))}function Jt(t){var e=[t];return Bt(t)?e:e.concat(M(Ft(t).map(Jt)))}function qt(t,e){var n,i,r,a,s,c,u,h,f=Xt(new Set(t)),l=new Set(e);try{for(var d=o(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&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=Xt(l);try{for(var g=o(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,o(Ft(E))),S=x.next();!S.done;S=x.next()){var b=S.value;l.has(b)||(l.add(b),f.get(b)?f.get(b).forEach((function(t){return l.add(t)})):b.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){r={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(r)throw r.error}}try{for(var w=o(l),_=w.next();!_.done;_=w.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=w.return)&&h.call(w)}finally{if(u)throw u.error}}return l}function Xt(t){var e,n,i=new Map;try{for(var r=o(t),a=r.next();!a.done;a=r.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}return i}function $t(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(Bt(r))return r.key}var o={};return i.forEach((function(e){o[e.key]=t(e,n)})),o}(t,Xt(qt([t],e)))}function Qt(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function Ht(t,e){return"compound"===e.type?Ft(e).some((function(e){return"final"===e.type&&Qt(t,e)})):"parallel"===e.type&&Ft(e).every((function(e){return Ht(t,e)}))}function Gt(t){return new Set(M(t.map((function(t){return t.tags}))))}var Kt=function(){function t(t){var e,n,i=this;this.actions=[],this.activities=k,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||k,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),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,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],a(new Set(M(s([],a(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(i.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:at,_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=at;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="."),Q(t))return[t];var i=Object.keys(t);return i.concat.apply(i,s([],a(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=r(t,["configuration","transitions","tags","machine"]);return i(i({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return j(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),Wt={deferEvents:!1},Yt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},Wt),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}(),Zt=new Map,te=0,ee=function(){return"x:".concat(te++)},ne=function(t,e){return Zt.set(t,e),t},ie=function(t){return Zt.get(t)},re=function(t){Zt.delete(t)};function oe(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function ae(t){if(oe()){var e=function(){var t=oe();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function se(t,e){void 0===e&&(e={});var n=t.initialState,i=new Set,r=[],o=!1,a=zt({id:e.id,send:function(e){r.push(e),function(){if(!o){for(o=!0;r.length>0;){var e=r.shift();n=t.transition(n,e,s),i.forEach((function(t){return t.next(n)}))}o=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=it(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),s={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(s):n,a}var ce,ue={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(ce=t.InterpreterStatus||(t.InterpreterStatus={}))[ce.NotStarted=0]="NotStarted",ce[ce.Running=1]="Running",ce[ce.Stopped=2]="Stopped";var he=function(){function e(n,r){void 0===r&&(r=e.defaultOptions);var o=this;this.machine=n,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=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(e,n){if(X(e))return o.batch(e),o.state;var i=Z(Y(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'.concat(i.name,'" was sent to uninitialized service "').concat(o.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ').concat(JSON.stringify(i.data)));return o.scheduler.schedule((function(){o.forward(i);var t=o._nextState(i);o.update(t,i)})),o._state},this.sendTo=function(e,n,r){var a,s=o.parent&&(n===t.SpecialTargets.Parent||o.parent.id===n),c=s?o.parent:Q(n)?n===t.SpecialTargets.Internal?o:o.children.get(n)||ie(n):(a=n)&&"function"==typeof a.send?n:void 0;if(c)if("machine"in c){if(o.status!==t.InterpreterStatus.Stopped||o.parent!==c||o.state.done){var u=i(i({},e),{name:e.name===_?"".concat(jt(o.id)):e.name,origin:o.sessionId});!r&&o.machine.config.predictableActionArguments?o._outgoingQueue.push([c,u]):c.send(u)}}else!r&&o.machine.config.predictableActionArguments?o._outgoingQueue.push([c,e.data]):c.send(e.data);else if(!s)throw new Error("Unable to send event to child '".concat(n,"' from service '").concat(o.id,"'."))},this._exec=function(e,n,i,r){void 0===r&&(r=o.machine.options.actions);var a=e.exec||st(e.type,r),s=$(a)?a:a?a.exec:e.exec;if(s)try{return s(n,i.data,o.machine.config.predictableActionArguments?{action:e,_event:i}:{action:e,state:o.state,_event:i})}catch(t){throw o.parent&&o.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case f:var c=e;o.defer(c);break;case l:var p=e;if("number"==typeof p.delay)return void o.defer(p);p.to?o.sendTo(p._event,p.to,i===at):o.send(p._event);break;case d:o.cancel(e.sendId);break;case u:if(o.status!==t.InterpreterStatus.Running)return;var v=e.activity;if(!o.machine.config.predictableActionArguments&&!o.state.activities[v.id||v.type])break;if(v.type===t.ActionTypes.Invoke){var y=nt(v.src),g=o.machine.options.services?o.machine.options.services[y.type]:void 0,x=v.id,S=v.data,b="autoForward"in v?v.autoForward:!!v.forward;if(!g)return;var w=S?U(S,n,i):void 0;if("string"==typeof g)return;var _=$(g)?g(n,i.data,{data:w,src:y,meta:v.meta}):g;if(!_)return;var E=void 0;K(_)&&(_=w?_.withContext(w):_,E={autoForward:b}),o.spawn(_,x,E)}else o.spawnActivity(v);break;case h:o.stopChild(e.activity.id);break;case m:var T=e,A=T.label,O=T.value;A?o.logger(A,O):o.logger(O)}};var a=i(i({},e.defaultOptions),r),s=a.clock,c=a.logger,p=a.parent,v=a.id,y=void 0!==v?v:n.id;this.id=y,this.logger=c,this.clock=s,this.parent=p,this.options=a,this.scheduler=new Yt({deferEvents:this.options.deferEvents}),this.sessionId=ee()}return Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Dt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),e.prototype.execute=function(t,e){var n,i;try{for(var r=o(t.actions),a=r.next();!a.done;a=r.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,i,r,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.machine.config.predictableActionArguments&&e!==at||!this.options.execute)for(var l=void 0;l=this._outgoingQueue.shift();)l[0].send(l[1]);else this.execute(this.state);if(this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=o(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=o(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){r={error:t}}finally{try{y&&!y.done&&(a=v.return)&&a.call(v)}finally{if(r)throw r.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{m&&!m.done&&(c=g.return)&&c.call(g)}finally{if(s)throw s.error}}if(this.state.done){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),S=x&&x.doneData?U(x.doneData,t.context,e):void 0;this._doneEvent=kt(this.id,S);try{for(var b=o(this.doneListeners),w=b.next();!w.done;w=b.next()){(0,w.value)(this._doneEvent)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this._stop(),this._stopChildren(),re(this.sessionId)}},e.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},e.prototype.subscribe=function(e,n,i){var r=this,o=it(e,n,i);this.listeners.add(o.next),this.status!==t.InterpreterStatus.NotStarted&&o.next(this.state);var a=function(){r.doneListeners.delete(a),r.stopListeners.delete(a),o.complete()};return this.status===t.InterpreterStatus.Stopped?o.complete():(this.onDone(a),this.onStop(a)),{unsubscribe:function(){r.listeners.delete(o.next),r.doneListeners.delete(a),r.stopListeners.delete(a)}}},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(e){return this.status===t.InterpreterStatus.Stopped&&this._doneEvent?e(this._doneEvent):this.doneListeners.add(e),this},e.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},e.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),ne(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:Dt(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(Kt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,at)})),this},e.prototype._stopChildren=function(){this.children.forEach((function(t){$(t.stop)&&t.stop()})),this.children.clear()},e.prototype._stop=function(){var e,n,i,r,a,s,c,u,h,f;try{for(var l=o(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(t){e={error:t}}finally{try{d&&!d.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}try{for(var v=o(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){i={error:t}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(i)throw i.error}}try{for(var g=o(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(s=g.return)&&s.call(g)}finally{if(a)throw a.error}}try{for(var x=o(this.doneListeners),S=x.next();!S.done;S=x.next()){p=S.value;this.doneListeners.delete(p)}}catch(t){c={error:t}}finally{try{S&&!S.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.initialized=!1,this.status=t.InterpreterStatus.Stopped,this._initialState=void 0;try{for(var b=o(Object.keys(this.delayedEventsMap)),w=b.next();!w.done;w=b.next()){var _=w.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{w&&!w.done&&(f=b.return)&&f.call(b)}finally{if(h)throw h.error}}this.scheduler.clear(),this.scheduler=new Yt({deferEvents:this.options.deferEvents})},e.prototype.stop=function(){var t=this,e=this.scheduler;return this._stop(),e.schedule((function(){var e=Z({type:"xstate.stop"}),n=Dt(t,(function(){var n=M(s([],a(t.state.configuration),!1).sort((function(t,e){return e.order-t.order})).map((function(e){return ut(e.onExit,t.machine.options.actions)}))),i=a(Ct(t.machine,t.state,t.state.context,e,[{type:"exit",actions:n}],t.machine.config.predictableActionArguments?t._exec:void 0,t.machine.config.predictableActionArguments||t.machine.config.preserveActionOrder),2),r=i[0],o=i[1],c=new Kt({value:t.state.value,context:o,_event:e,_sessionid:t.sessionId,historyValue:void 0,history:t.state,actions:r.filter((function(t){return!ot(t)})),activities:{},events:[],configuration:[],transitions:[],children:{},done:t.state.done,tags:t.state.tags,machine:t.machine});return c.changed=!0,c}));t.update(n,e),t._stopChildren(),re(t.sessionId)})),this},e.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));if(e.length){var r=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule((function(){var t,c,u=n.state,h=!1,f=[],l=function(t){var e=Z(t);n.forward(e),u=Dt(n,(function(){return n.machine.transition(u,e,void 0,r||void 0)})),f.push.apply(f,s([],a(n.machine.config.predictableActionArguments?u.actions:u.actions.map((function(t){return function(t,e){var n=t.exec;return i(i({},t),{exec:void 0!==n?function(){return n(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0})}(t,u)}))),!1)),h=h||!!u.changed};try{for(var d=o(e),p=d.next();!p.done;p=d.next()){l(p.value)}}catch(e){t={error:e}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(t)throw t.error}}u.changed=h,u.actions=f,n.update(u,Z(e[e.length-1]))}))}},e.prototype.sender=function(t){return this.send.bind(this,t)},e.prototype._nextState=function(t,e){var n=this;void 0===e&&(e=!!this.machine.config.predictableActionArguments&&this._exec);var i=Z(t);if(0===i.name.indexOf(w)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(w)})))throw i.data.data;return Dt(this,(function(){return n.machine.transition(n.state,i,void 0,e||void 0)}))},e.prototype.nextState=function(t){return this._nextState(t,!1)},e.prototype.forward=function(t){var e,n;try{for(var i=o(this.forwardTo),r=i.next();!r.done;r=i.next()){var a=r.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));s.send(t)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},e.prototype.defer=function(t){var e=this,n=this.clock.setTimeout((function(){"to"in t&&t.to?e.sendTo(t._event,t.to,!0):e.send(t._event)}),t.delay);t.id&&(this.delayedEventsMap[t.id]=n)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(t,e,n){void 0===n&&(n=this.machine.options.actions),this._exec(t,e.context,e._event,n)},e.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),$(e.stop)&&e.stop())},e.prototype.spawn=function(e,n,r){if(this.status!==t.InterpreterStatus.Running)return Mt(e,n);if(F(e))return this.spawnPromise(Promise.resolve(e),n);if($(e))return this.spawnCallback(e,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(a=e)&&"id"in a)return this.spawnActor(e,n);if(function(t){try{return"subscribe"in t&&$(t.subscribe)}catch(t){return!1}}(e))return this.spawnObservable(e,n);if(K(e))return this.spawnMachine(e,i(i({},r),{id:n}));if(null!==(o=e)&&"object"==typeof o&&"transition"in o&&"function"==typeof o.transition)return this.spawnBehavior(e,n);throw new Error('Unable to spawn entity "'.concat(n,'" of type "').concat(typeof e,'".'));var o,a},e.prototype.spawnMachine=function(t,n){var r=this;void 0===n&&(n={});var o=new e(t,i(i({},this.options),{parent:this,id:n.id||t.id})),a=i(i({},ue),n);a.sync&&o.onTransition((function(t){r.send(E,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){r.removeChild(o.id),r.send(Z(t,{origin:o.id}))})).start(),s},e.prototype.spawnBehavior=function(t,e){var n=se(t,{id:e,parent:this});return this.children.set(e,n),n},e.prototype.spawnPromise=function(t,e){var n,i,r=this,o=!1;t.then((function(t){o||(i=t,r.removeChild(e),r.send(Z(kt(e,t),{origin:e})))}),(function(t){if(!o){r.removeChild(e);var n=jt(e,t);try{r.send(Z(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var a=((n={id:e,send:function(){},subscribe:function(e,n,i){var r=it(e,n,i),o=!1;return t.then((function(t){o||(r.next(t),o||r.complete())}),(function(t){o||r.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){o=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return i}})[G]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnCallback=function(t,e){var n,i,r,o=this,a=!1,s=new Set,c=new Set;try{r=t((function(t){i=t,c.forEach((function(e){return e(t)})),a||o.send(Z(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(jt(e,t))}if(F(r))return this.spawnPromise(r,e);var u=((n={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){var e=it(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){a=!0,$(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return i}})[G]=function(){return this},n);return this.children.set(e,u),u},e.prototype.spawnObservable=function(t,e){var n,i,r=this,o=t.subscribe((function(t){i=t,r.send(Z(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(Z(jt(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(Z(kt(e),{origin:e}))})),a=((n={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return i},toJSON:function(){return{id:e}}})[G]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},e.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)}},e.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[G]=function(){return this},n))},e.prototype.attachDev=function(){var t=oe();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:i({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}ae(this)}},e.prototype.toJSON=function(){return{id:this.id}},e.prototype[G]=function(){return this},e.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},e.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},e.interpret=fe,e}();function fe(t,e){return new he(t,e)}function le(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function de(t){return i(i({type:S},t),{toJSON:function(){t.onDone,t.onError;var e=r(t,["onDone","onError"]);return i(i({},e),{type:S,src:le(t.src)})}})}var pe={},ve=function(t){return"#"===t[0]},ye=function(){function t(e,n,r,c){void 0===r&&(r="context"in e?e.context:void 0);var u,h=this;this.config=e,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.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==c?void 0:c.parent,this.key=this.config.key||(null==c?void 0:c.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:"."),this.id=this.config.id||s([this.machine.key],a(this.path),!1).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&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?L(this.config.states,(function(e,n){var r,o=new t(e,{},void 0,{parent:h,key:n});return Object.assign(h.idMap,i(((r={})[o.id]=o,r),o.idMap)),o})):pe;var f=0;!function t(e){var n,i;e.order=f++;try{for(var r=o(Ut(e)),a=r.next();!a.done;a=r.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=r.return)&&i.call(r)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=B(this.config.entry||this.config.onEntry).map((function(t){return ct(t)})),this.onExit=B(this.config.exit||this.config.onExit).map((function(t){return ct(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=B(this.config.invoke).map((function(t,e){var n,r;if(K(t)){var o=rt(h.id,e);return h.machine.options.services=i(((n={})[o]=t,n),h.machine.options.services),de({src:o,id:o})}if(Q(t.src)){o=t.id||rt(h.id,e);return de(i(i({},t),{id:o,src:t.src}))}if(K(t.src)||$(t.src)){o=t.id||rt(h.id,e);return h.machine.options.services=i(((r={})[o]=t.src,r),h.machine.options.services),de(i(i({id:o},t),{src:o}))}var a=t.src;return de(i(i({id:rt(h.id,e)},t),{src:a}))})),this.activities=B(this.config.activities).concat(this.invoke).map((function(t){return ht(t)})),this.transition=this.transition.bind(this),this.tags=B(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Jt(this).forEach((function(t){return t.on}))},t.prototype.withConfig=function(e,n){var r=this.options,o=r.actions,a=r.activities,s=r.guards,c=r.services,u=r.delays;return new t(this.config,{actions:i(i({},o),e.actions),activities:i(i({},a),e.activities),guards:i(i({},s),e.guards),services:i(i({},c),e.services),delays:i(i({},u),e.delays)},null!=n?n:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return $(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.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:L(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.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.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:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var i=n.eventType===t;return e?i:i||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},t.prototype.getDelayedTransitions=function(){var t=this,e=this.config.after;if(!e)return[];var n=function(e,n){var i=At($(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(dt(i,{delay:e})),t.onExit.push(bt(i)),i};return(X(e)?e.map((function(t,e){var r=n(t.delay,e);return i(i({},t),{event:r})})):M(Object.keys(e).map((function(t,r){var o=e[t],a=Q(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=n(s,r);return B(a).map((function(t){return i(i({},t),{event:c,delay:s})}))})))).map((function(e){var n=e.delay;return i(i({},t.formatTransition(e)),{delay:n})}))},t.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var i=t instanceof Kt?t.value:P(t,this.delimiter);if(Q(i)){var r=this.getStateNode(i).initial;return void 0!==r?this.getStateNodes(((e={})[i]=r,e)):[this,this.states[i]]}var o=Object.keys(i),c=[this];return c.push.apply(c,s([],a(M(o.map((function(t){return n.getStateNode(t).getStateNodes(i[t])})))),!1)),c},t.prototype.handles=function(t){var e=N(t);return this.events.includes(e)},t.prototype.resolveState=function(t){var e=t instanceof Kt?t:Kt.create(t),n=Array.from(qt([],this.getStateNodes(e.value)));return new Kt(i(i({},e),{value:this.resolve(e.value),configuration:n,done:Ht(n,this),tags:Gt(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(t,e,n){var i=this.getStateNode(t).next(e,n);return i&&i.transitions.length?i:this.next(e,n)},t.prototype.transitionCompoundNode=function(t,e,n){var i=Object.keys(t),r=this.getStateNode(i[0])._transition(t[i[0]],e,n);return r&&r.transitions.length?r:this.next(e,n)},t.prototype.transitionParallelNode=function(t,e,n){var i,r,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];if(h){var f=this.getStateNode(u)._transition(h,e,n);f&&(a[u]=f)}}}catch(t){i={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(i)throw i.error}}var l=Object.keys(a).map((function(t){return a[t]})),d=M(l.map((function(t){return t.transitions})));if(!l.some((function(t){return t.transitions.length>0})))return this.next(e,n);var p=M(Object.keys(a).map((function(t){return a[t].configuration})));return{transitions:d,exitSet:M(l.map((function(t){return t.exitSet}))),configuration:p,source:e,actions:M(Object.keys(a).map((function(t){return a[t].actions})))}},t.prototype._transition=function(t,e,n){return Q(t)?this.transitionLeafNode(t,e,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},t.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,Z(e))},t.prototype.next=function(t,e){var n,i,r,c=this,u=e.name,h=[],f=[];try{for(var l=o(this.getCandidates(u)),d=l.next();!d.done;d=l.next()){var p=d.value,v=p.cond,y=p.in,g=t.context,m=!y||(Q(y)&&ve(y)?t.matches(P(this.getStateNodeById(y).path,this.delimiter)):j(P(y,this.delimiter),D(this.path.slice(0,-2))(t.value))),x=!1;try{x=!v||et(this.machine,v,g,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(v.name||v.type,"' in transition for event '").concat(u,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(x&&m){void 0!==p.target&&(f=p.target),h.push.apply(h,s([],a(p.actions),!1)),r=p;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}if(r){if(!f.length)return{transitions:[r],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var S=M(f.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)})));return{transitions:[r],exitSet:!!r.internal?[]:M(f.map((function(t){return c.getPotentiallyReenteringNodes(t)}))),configuration:S,source:t,actions:h}}},t.prototype.getPotentiallyReenteringNodes=function(t){if(this.order<t.order)return[this];for(var e=[],n=this,i=t;n&&n!==i;)e.push(n),n=n.parent;return n!==i?[]:(e.push(i),e)},t.prototype.getActions=function(t,e,n,i,r,c,u){var h,f,l,d,p=this,v=c?qt([],this.getStateNodes(c.value)):[],y=new Set;try{for(var g=o(Array.from(t).sort((function(t,e){return t.order-e.order}))),m=g.next();!m.done;m=g.next()){(!Qt(v,b=m.value)||Qt(n.exitSet,b)||b.parent&&y.has(b.parent))&&y.add(b)}}catch(t){h={error:t}}finally{try{m&&!m.done&&(f=g.return)&&f.call(g)}finally{if(h)throw h.error}}try{for(var x=o(v),S=x.next();!S.done;S=x.next()){var b;Qt(t,b=S.value)&&!Qt(n.exitSet,b.parent)||n.exitSet.push(b)}}catch(t){l={error:t}}finally{try{S&&!S.done&&(d=x.return)&&d.call(x)}finally{if(l)throw l.error}}n.exitSet.sort((function(t,e){return e.order-t.order}));var w=Array.from(y).sort((function(t,e){return t.order-e.order})),_=new Set(n.exitSet),E=M(w.map((function(t){var e=[];if("final"!==t.type)return e;var o=t.parent;if(!o.parent)return e;e.push(Ot(t.id,t.doneData),Ot(o.id,t.doneData?U(t.doneData,i,r):void 0));var a=o.parent;return"parallel"===a.type&&Ft(a).every((function(t){return Ht(n.configuration,t)}))&&e.push(Ot(a.id)),e}))),T=w.map((function(t){var e=t.onEntry,n=t.activities.map((function(t){return wt(t)}));return{type:"entry",actions:ut(u?s(s([],a(e),!1),a(n),!1):s(s([],a(n),!1),a(e),!1),p.machine.options.actions)}})).concat({type:"state_done",actions:E.map((function(t){return ft(t)}))}),A=Array.from(_).map((function(t){return{type:"exit",actions:ut(s(s([],a(t.onExit),!1),a(t.activities.map((function(t){return _t(t)}))),!1),p.machine.options.actions)}})).concat({type:"transition",actions:ut(n.actions,this.machine.options.actions)}).concat(T);if(e){var O=ut(M(s([],a(t),!1).sort((function(t,e){return e.order-t.order})).map((function(t){return t.onExit}))),this.machine.options.actions).filter((function(t){return!ot(t)}));return A.concat({type:"stop",actions:O})}return A},t.prototype.transition=function(t,e,n,i){void 0===t&&(t=this.initialState);var r,o,c=Z(e);if(t instanceof Kt)r=void 0===n?t:this.resolveState(Kt.from(t,n));else{var u=Q(t)?this.resolve(C(this.getResolvedPath(t))):this.resolve(t),h=null!=n?n:this.machine.context;r=this.resolveState(Kt.from(u,h))}if(this.strict&&!this.events.includes(c.name)&&(o=c.name,!/^(done|error)\./.test(o)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(c.name,"'"));var f=this._transition(r.value,r,c)||{transitions:[],configuration:[],exitSet:[],source:r,actions:[]},l=qt([],this.getStateNodes(r.value)),d=f.configuration.length?qt(l,f.configuration):l;return f.configuration=s([],a(d),!1),this.resolveTransition(f,r,r.context,i,c)},t.prototype.resolveRaisedTransition=function(t,e,n,i){var r,o=t.actions;return(t=this.transition(t,e,void 0,i))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,s([],a(o),!1)),t},t.prototype.resolveTransition=function(t,e,n,r,s){var c,f,l,d,v=this;void 0===s&&(s=at);var y=t.configuration,g=!e||t.transitions.length>0,m=g?t.configuration:e?e.configuration:[],x=Ht(m,this),b=g?$t(this.machine,y):void 0,w=e?e.historyValue?e.historyValue:t.source?this.machine.historyValue(e.value):void 0:void 0,_=this.getActions(new Set(m),x,t,n,s,e,r),T=e?i({},e.activities):{};try{for(var A=o(_),O=A.next();!O.done;O=A.next()){var k=O.value;try{for(var j=(l=void 0,o(k.actions)),N=j.next();!N.done;N=j.next()){var I=N.value;I.type===u?T[I.activity.id||I.activity.type]=I:I.type===h&&(T[I.activity.id||I.activity.type]=!1)}}catch(t){l={error:t}}finally{try{N&&!N.done&&(d=j.return)&&d.call(j)}finally{if(l)throw l.error}}}}catch(t){c={error:t}}finally{try{O&&!O.done&&(f=A.return)&&f.call(A)}finally{if(c)throw c.error}}var P,C,L=a(Ct(this,e,n,s,_,r,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),V=L[0],D=L[1],R=a(function(t,e){var n,i,r=a([[],[]],2),s=r[0],c=r[1];try{for(var u=o(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&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}return[s,c]}(V,ot),2),M=R[0],z=R[1],B=V.filter((function(t){var e;return t.type===u&&(null===(e=t.activity)||void 0===e?void 0:e.type)===S})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,i){var r,o=nt(t.src),a=null===(r=null==e?void 0:e.options.services)||void 0===r?void 0:r[o.type],s=t.data?U(t.data,n,i):void 0,c=a?Mt(a,t.id,s):Rt(t.id);return c.meta=t,c}(e.activity,v.machine,D,s),t}),e?i({},e.children):{}),F=new Kt({value:b||e.value,context:D,_event:s,_sessionid:e?e._sessionid:null,historyValue:b?w?(P=w,C=b,{current:C,states:J(P,C)}):void 0:e?e.historyValue:void 0,history:!b||t.source?e:void 0,actions:b?z:[],activities:b?T:e?e.activities:{},events:[],configuration:m,transitions:t.transitions,children:B,done:x,tags:Gt(m),machine:this}),q=n!==D;F.changed=s.name===E||q;var X=F.history;X&&delete X.history;var $=!x&&(this._transient||y.some((function(t){return t._transient})));if(!(g||$&&""!==s.name))return F;var H=F;if(!x)for($&&(H=this.resolveRaisedTransition(H,{type:p},s,r));M.length;){var G=M.shift();H=this.resolveRaisedTransition(H,G._event,s,r)}var K=H.changed||(X?!!H.actions.length||q||typeof X.value!=typeof H.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(Q(e)||Q(n))return e===n;var i=Object.keys(e),r=Object.keys(n);return i.length===r.length&&i.every((function(i){return t(e[i],n[i])}))}(H.value,X.value):void 0);return H.changed=K,H.history=X,H},t.prototype.getStateNode=function(t){if(ve(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '".concat(t,"' from '").concat(this.id,"'; no child states exist."));var e=this.states[t];if(!e)throw new Error("Child state '".concat(t,"' does not exist on '").concat(this.id,"'"));return e},t.prototype.getStateNodeById=function(t){var e=ve(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 '#".concat(e,"' does not exist on machine '").concat(this.id,"'"));return n},t.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&ve(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=I(t,this.delimiter).slice(),n=this;e.length;){var i=e.shift();if(!i.length)break;n=n.getStateNode(i)}return n},t.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||pe;switch(this.type){case"parallel":return L(this.initialStateValue,(function(e,i){return e?n.getStateNode(i).resolve(t[i]||e):pe}));case"compound":if(Q(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((e={})[t]=i.initialStateValue,e):t}return Object.keys(t).length?L(t,(function(t,e){return t?n.getStateNode(e).resolve(t):pe})):this.initialStateValue||{};default:return t||pe}},t.prototype.getResolvedPath=function(t){if(ve(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '".concat(t,"'"));return e.path}return I(t,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=V(this.states,(function(t){return t.initialStateValue||pe}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));e=Bt(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(t,e){this._init();var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)},Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=Q(e.target)&&ve(e.target)?C(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var t=this;return Bt(this)?[this]:"compound"!==this.type||this.initial?M(R(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=a(t),n=e[0],i=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var r=this.getStateNode(n);if("history"===r.type)return r.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(i)},t.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:V(this.states,(function(e,n){if(!t)return e.historyValue();var i=Q(t)?void 0:t[n];return e.historyValue(i||e.initialStateValue)}),(function(t){return!t.history}))}},t.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?M(R(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var r,a,s=(r=n.path,a="states",function(t){var e,n,i=t;try{for(var s=o(r),c=s.next();!c.done;c=s.next()){var u=c.value;i=i[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 i})(t).current;return Q(s)?[n.getStateNode(s)]:M(R(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var t=this,e=M(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var r=this.states,a=new Set(this.ownEvents);if(r)try{for(var s=o(Object.keys(r)),c=s.next();!c.done;c=s.next()){var u=r[c.value];if(u.states)try{for(var h=(n=void 0,o(u.events)),f=h.next();!f.done;f=h.next()){var l=f.value;a.add("".concat(l))}}catch(t){n={error:t}}finally{try{f&&!f.done&&(i=h.return)&&i.call(h)}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:!1,configurable:!0}),Object.defineProperty(t.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:!1,configurable:!0}),t.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!Q(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 '".concat(e.id,"':\n").concat(t.message))}}))},t.prototype.formatTransition=function(t){var e=this,n=function(t){if(void 0!==t&&""!==t)return B(t)}(t.target),r="internal"in t?t.internal:!n||n.some((function(t){return Q(t)&&t[0]===e.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(n),s=i(i({},t),{actions:ut(B(t.actions)),cond:H(t.cond,o),target:a,source:this,internal:r,eventType:t.event,toJSON:function(){return i(i({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(e.id)})}});return s},t.prototype.formatTransitions=function(){var t,e,n,i=this;if(this.config.on)if(Array.isArray(this.config.on))n=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=r(c,["*"]);n=M(Object.keys(f).map((function(t){return tt(t,f[t])})).concat(tt("*",h)))}else n=[];var l=this.config.always?tt("",this.config.always):[],d=this.config.onDone?tt(String(Ot(this.id)),this.config.onDone):[],p=M(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,s([],a(tt(String(kt(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,s([],a(tt(String(jt(t.id)),t.onError)),!1)),e}))),v=this.after,y=M(s(s(s(s([],a(d),!1),a(p),!1),a(n),!1),a(l),!1).map((function(t){return B(t).map((function(t){return i.formatTransition(t)}))})));try{for(var g=o(v),m=g.next();!m.done;m=g.next()){var x=m.value;y.push(x)}}catch(e){t={error:e}}finally{try{m&&!m.done&&(e=g.return)&&e.call(g)}finally{if(t)throw t.error}}return y},t}();function ge(t){return t}var me=ge,xe=Tt,Se=bt,be=dt,we=yt,_e=vt,Ee=gt,Te=It,Ae=kt,Oe=ft,ke=xt,je=Nt,Ne=Pt,Ie=_t;t.Interpreter=he,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new ye(t,e,n)},t.State=Kt,t.StateNode=ye,t.actions=Lt,t.assign=xe,t.cancel=Se,t.choose=Ne,t.createMachine=function(t,e){return new ye(t,e)},t.createSchema=ge,t.doneInvoke=Ae,t.forwardTo=Te,t.interpret=fe,t.log=ke,t.mapState=function(t,e){var n,i,r;try{for(var a=o(Object.keys(t)),s=a.next();!s.done;s=a.next()){var c=s.value;j(c,e)&&(!r||e.length>r.length)&&(r=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[r]},t.matchState=function(t,e,n){var i,r,s=Kt.from(t,t instanceof Kt?t.context:void 0);try{for(var c=o(e),u=c.next();!u.done;u=c.next()){var h=a(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){i={error:t}}finally{try{u&&!u.done&&(r=c.return)&&r.call(c)}finally{if(i)throw i.error}}return n(s)},t.matchesState=j,t.pure=je,t.raise=Oe,t.send=be,t.sendParent=_e,t.sendTo=we,t.sendUpdate=Ee,t.spawn=function(t,e){var n=function(t){return Q(t)?i(i({},ue),{name:t}):i(i(i({},ue),{name:W()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):Mt(t,n.name)}(Vt[Vt.length-1])},t.spawnBehavior=se,t.stop=Ie,t.t=me,t.toActorRef=zt,t.toEventObject=Y,t.toObserver=it,t.toSCXMLEvent=Z,Object.defineProperty(t,"__esModule",{value:!0})}));

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

const t={};function e(t){return Object.keys(t)}function i(t,n,s="."){const r=o(t,s),a=o(n,s);return w(a)?!!w(r)&&a===r:w(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return w(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 s(t,e){try{return b(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function o(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(b(t))return r(t);if("string"!=typeof t)return t;return r(s(t,e))}function r(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 a(t,i){const n={},s=e(t);for(let e=0;e<s.length;e++){const o=s[e];n[o]=i(t[o],o,t,e)}return n}function c(t,i,n){const s={};for(const o of e(t)){const e=t[o];n(e)&&(s[o]=i(e,o,t))}return s}const h=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function d(t){if(!t)return[[]];if(w(t))return[[t]];return u(e(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?d(t[e]).map(t=>[e].concat(t)):[[e]]}))}function u(t){return[].concat(...t)}function l(t){return b(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(S(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];S(o)?n[s]=o(e,i.data):n[s]=o}return n}function g(t){return t instanceof Promise||!(null===t||!S(t)&&"object"!=typeof t||!S(t.then))}function v(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function y(t,e){return a(t.states,(t,i)=>{if(!t)return;const n=(w(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:y(t,n)}:void 0})}function m(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(S(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=S(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}function b(t){return Array.isArray(t)}function S(t){return"function"==typeof t}function w(t){return"string"==typeof t}function x(t,e){if(t)return w(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:S(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const O=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function _(t){try{return"__xstatenode"in t}catch(t){return!1}}const j=(()=>{let t=0;return()=>(t++,t.toString(16))})();function E(t,e){return w(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!w(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=E(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function T(t,e){return l(e).map(e=>void 0===e||"string"==typeof e||_(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function $(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function k(t){return"string"==typeof t?{type:t}:t}function C(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}function P(t,n){let s;for(const o of e(t))i(o,n)&&(!s||n.length>s.length)&&(s=o);return t[s]}
var t,e;!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",t.Choose="xstate.choose"}(t||(t={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(e||(e={}));const i=t.Start,n=t.Stop,s=t.Raise,o=t.Send,r=t.Cancel,a=t.NullEvent,c=t.Assign,h=t.After,d=t.DoneState,u=t.Log,l=t.Init,f=t.Invoke,p=t.ErrorExecution,g=t.ErrorPlatform,v=t.ErrorCustom,y=t.Update,m=t.Choose,b=t.Pure;var S=Object.freeze({__proto__:null,start:i,stop:n,raise:s,send:o,cancel:r,nullEvent:a,assign:c,after:h,doneState:d,log:u,init:l,invoke:f,errorExecution:p,errorPlatform:g,error:v,update:y,choose:m,pure:b});const O={};function _(t,e,i="."){const n=j(t,i),s=j(e,i);return z(s)?!!z(n)&&s===n:z(n)?n in s:Object.keys(n).every(t=>t in s&&_(n[t],s[t]))}function x(t){try{return z(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 w(t,e){try{return R(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function j(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(R(t))return E(t);if("string"!=typeof t)return t;return E(w(t,e))}function E(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 k(t,e){const i={},n=Object.keys(t);for(let s=0;s<n.length;s++){const o=n[s];i[o]=e(t[o],o,t,s)}return i}function N(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];i(o)&&(n[s]=e(o,s,t))}return n}const T=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function A(t){if(!t)return[[]];if(z(t))return[[t]];return $(Object.keys(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?A(t[e]).map(t=>[e].concat(t)):[[e]]}))}function $(t){return[].concat(...t)}function P(t){return R(t)?t:[t]}function I(t){return void 0===t?[]:P(t)}function C(t,e,i){if(M(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];M(o)?n[s]=o(e,i.data):n[s]=o}return n}function V(t){return t instanceof Promise||!(null===t||!M(t)&&"object"!=typeof t||!M(t.then))}function L(t,e){return k(t.states,(t,i)=>{if(!t)return;const n=(z(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:L(t,n)}:void 0})}function D(t,e,i,n){return t?i.reduce((t,i)=>{const{assignment:s}=i,o={state:n,action:i,_event:e};let r={};if(M(s))r=s(t,e.data,o);else for(const i of Object.keys(s)){const n=s[i];r[i]=M(n)?n(t,e.data,o):n}return Object.assign({},t,r)},t):t}function R(t){return Array.isArray(t)}function M(t){return"function"==typeof t}function z(t){return"string"==typeof t}function U(t,e){if(t)return z(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:M(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const B=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function F(t){return!!t&&"__xstatenode"in t}const J=(()=>{let t=0;return()=>(t++,t.toString(16))})();function q(t,e){return z(t)||"number"==typeof t?Object.assign({type:t},e):t}function Q(t,e){if(!z(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=q(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function X(t,e){return P(e).map(e=>void 0===e||"string"==typeof e||F(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function H(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=null==o?void 0:o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function G(t){return"string"==typeof t?{type:t}:t}function K(t,e,i){const n=()=>{},s="object"==typeof t,o=s?t:null;return{next:((s?t.next:t)||n).bind(o),error:((s?t.error:e)||n).bind(o),complete:((s?t.complete:i)||n).bind(o)}}function W(t,e){return`${t}:invocation[${e}]`}function Y(t){return(t.type===s||t.type===o&&t.to===e.Internal)&&"number"!=typeof t.delay}const Z=Q({type:l});function tt(t,e){return e&&e[t]||void 0}function et(t,e){let i;if(z(t)||"number"==typeof t){const n=tt(t,e);i=M(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(M(t))i={type:t.name||t.toString(),exec:t};else{const n=tt(t.type,e);if(M(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const it=(t,e)=>{if(!t)return[];return(R(t)?t:[t]).map(t=>et(t,e))};function nt(t){const e=et(t);return Object.assign(Object.assign({id:z(t)?t:e.id},e),{type:e.type})}function st(t,e){return{type:s,event:"function"==typeof t?t:q(t),delay:e?e.delay:void 0,id:null==e?void 0:e.id}}function ot(t,e,i,n){const o={_event:i},r=Q(M(t.event)?t.event(e,i.data,o):t.event);let a;if(z(t.delay)){const s=n&&n[t.delay];a=M(s)?s(e,i.data,o):s}else a=M(t.delay)?t.delay(e,i.data,o):t.delay;return Object.assign(Object.assign({},t),{type:s,_event:r,delay:a})}function rt(t,e){return{to:e?e.to:void 0,type:o,event:M(t)?t:q(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:M(t)?t.name:x(t)}}function at(t,e,i,n){const s={_event:i},o=Q(M(t.event)?t.event(e,i.data,s):t.event);let r;if(z(t.delay)){const o=n&&n[t.delay];r=M(o)?o(e,i.data,s):o}else r=M(t.delay)?t.delay(e,i.data,s):t.delay;const a=M(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}function ct(t,i){return rt(t,Object.assign(Object.assign({},i),{to:e.Parent}))}const ht=(t,e)=>({context:t,event:e});const dt=(t,e,i)=>Object.assign(Object.assign({},t),{value:z(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),ut=t=>({type:r,sendId:t});function lt(e){const i=nt(e);return{type:t.Start,activity:i,exec:void 0}}function ft(e){const i=M(e)?e:nt(e);return{type:t.Stop,activity:i,exec:void 0}}function pt(e,i,n){const s=M(e.activity)?e.activity(i,n.data):e.activity,o="string"==typeof s?{id:s}:s;return{type:t.Stop,activity:o}}function gt(e,i){const n=i?"#"+i:"";return`${t.After}(${e})${n}`}function vt(e,i){const n=`${t.DoneState}.${e}`,s={type:n,data:i,toString:()=>n};return s}function yt(e,i){const n=`${t.DoneInvoke}.${e}`,s={type:n,data:i,toString:()=>n};return s}function mt(e,i){const n=`${t.ErrorPlatform}.${e}`,s={type:n,data:i,toString:()=>n};return s}function bt(t,i,r,a,h,d,l=!1){const f=l?[]:(t=>{const e=[];for(const i of t){let t=0;for(;t<i.actions.length;)i.actions[t].type!==c?t++:(e.push(i.actions[t]),i.actions.splice(t,1))}return e})(h);let p=f.length?D(r,a,f,i):r;const g=l?[r]:void 0,v=[];function y(h,f){var y;switch(f.type){case s:{const e=ot(f,p,a,t.options.delays);return d&&"number"==typeof e.delay&&d(e,p,a),e}case o:const S=at(f,p,a,t.options.delays);return d&&S.to!==e.Internal&&("entry"===h?v.push(S):d(S,p,a)),S;case u:{const t=dt(f,p,a);return null==d||d(t,p,a),t}case m:{const e=null===(y=f.conds.find(e=>{const n=U(e.cond,t.options.guards);return!n||H(t,n,p,a,d?void 0:i)}))||void 0===y?void 0:y.actions;if(!e)return[];const[n,s]=bt(t,i,p,a,[{type:h,actions:it(I(e),t.options.actions)}],d,l);return p=s,null==g||g.push(p),n}case b:{const e=f.get(p,a.data);if(!e)return[];const[n,s]=bt(t,i,p,a,[{type:h,actions:it(I(e),t.options.actions)}],d,l);return p=s,null==g||g.push(p),n}case n:{const t=pt(f,p,a);return null==d||d(t,r,a),t}case c:p=D(p,a,[f],d?void 0:i),null==g||g.push(p);break;default:let O=et(f,t.options.actions);const{exec:_}=O;if(d)d(O,p,a);else if(_&&g){const t=g.length-1;O=Object.assign(Object.assign({},O),{exec:(e,...i)=>{_(g[t],...i)}})}return O}}return[$(h.map((function(t){let e=[];for(const i of t.actions){const n=y(t.type,i);n&&(e=e.concat(n))}return v.forEach(t=>{d(t,p,a)}),v.length=0,e}))),p]}var St=Object.freeze({__proto__:null,actionTypes:S,initEvent:Z,getActionFunction:tt,toActionObject:et,toActionObjects:it,toActivityDefinition:nt,raise:st,resolveRaise:ot,send:rt,resolveSend:at,sendParent:ct,sendTo:function(t,e,i){return rt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return ct(y)},respond:function(t,e){return rt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=ht,e){return{type:u,label:e,expr:t}},resolveLog:dt,cancel:ut,start:lt,stop:ft,resolveStop:pt,assign:t=>({type:c,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:gt,done:vt,doneInvoke:yt,error:mt,pure:function(e){return{type:t.Pure,get:e}},forwardTo:function(t,e){return rt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,i){return ct((e,i,n)=>({type:v,data:M(t)?t(e,i,n):t}),Object.assign(Object.assign({},i),{to:e.Parent}))},choose:function(e){return{type:t.Choose,conds:e}},resolveActions:bt});const Ot=[],_t=(t,e)=>{Ot.push(t);const i=e(t);return Ot.pop(),i};function xt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}}}function wt(t,e,i){const n=xt(e);if(n.deferred=!0,F(t)){const e=n.state=_t(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function jt(t){return Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{},[B]:function(){return this}},t)}
/*! *****************************************************************************

@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function V(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}var I,L;!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",t.Choose="xstate.choose"}(I||(I={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(L||(L={}));const D=t=>"atomic"===t.type||"final"===t.type;function A(t){return e(t.states).map(e=>t.states[e])}function R(t){const e=[t];return D(t)?e:e.concat(u(A(t).map(R)))}function M(t,e){const i=z(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=z(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of A(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function z(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 F(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(D(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,z(M([t],e)))}function B(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?A(e).some(e=>"final"===e.type&&B(t,e)):"parallel"===e.type&&A(e).every(e=>J(t,e))}function U(t){return new Set(u(t.map(t=>t.tags)))}const q=I.Start,X=I.Stop,H=I.Raise,G=I.Send,K=I.Cancel,Q=I.NullEvent,W=I.Assign,Y=(I.After,I.DoneState,I.Log),Z=I.Init,tt=I.Invoke,et=(I.ErrorExecution,I.ErrorPlatform),it=I.ErrorCustom,nt=I.Update,st=I.Choose,ot=I.Pure,rt=N({type:Z});function at(t,e){return e&&e[t]||void 0}function ct(t,e){let i;if(w(t)||"number"==typeof t){const n=at(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=at(t.type,e);if(S(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const ht=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>ct(t,e))};function dt(t){const e=ct(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function ut(t){return w(t)?{type:H,event:t}:lt(t,{to:L.Internal})}function lt(t,e){return{to:e?e.to:void 0,type:G,event:S(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function ft(t,e){return lt(t,Object.assign(Object.assign({},e),{to:L.Parent}))}function pt(){return ft(nt)}const gt=(t,e)=>({context:t,event:e});const vt=t=>({type:K,sendId:t});function yt(t){const e=dt(t);return{type:I.Start,activity:e,exec:void 0}}function mt(t){const e=S(t)?t:dt(t);return{type:I.Stop,activity:e,exec:void 0}}const bt=t=>({type:W,assignment:t});function St(t,e){const i=e?"#"+e:"";return`${I.After}(${t})${i}`}function wt(t,e){const i=`${I.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){const i=`${I.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Ot(t,e){const i=`${I.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function _t(t,e){return lt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function jt(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===W);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[u(a.map(i=>{var s;switch(i.type){case H:return{type:H,_event:N(i.event)};case G:return function(t,e,i,n){const s={_event:i},o=N(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(i,c,n,t.options.delays);case Y:return((t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(i,c,n);case st:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||$(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,d]=jt(t,e,c,n,ht(f(r),t.options.actions),o);return c=d,null==h||h.push(c),a}case ot:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=jt(t,e,c,n,ht(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case X:return function(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:I.Stop,activity:s}}(i,c,n);case W:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=ct(i,t.options.actions);const{exec:a}=r;if(a&&h){const t=h.length-1;r=Object.assign(Object.assign({},r),{exec:(e,...i)=>{a(h[t],...i)}})}return r}}).filter(t=>!!t)),c]}function Et(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 Nt{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(u([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Nt)return t.context!==e?new Nt({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 Nt({value:t,context:e,_event:rt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Nt(t)}static inert(t,e){if(t instanceof Nt){if(!t.actions.length)return t;const i=rt;return new Nt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Nt.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=V(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Tt=[],$t=(t,e)=>{Tt.push(t);const i=e(t);return Tt.pop(),i};function kt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})}}function Ct(t,e,i){const n=kt(e);if(n.deferred=!0,_(t)){const e=n.state=$t(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function Pt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Vt(t){return Object.assign(Object.assign({type:tt},t),{toJSON(){const e=V(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:tt,src:Pt(t.src)})}})}const It={},Lt=t=>"#"===t[0];class Dt{constructor(t,i,n=("context"in t?t.context:void 0)){var s;this.config=t,this._context=n,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.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},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:"."),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&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new Dt(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):It;let o=0;!function t(e){e.order=o++;for(const i of A(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>ct(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ct(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Vt({src:t.id,id:t.id});if(w(t.src))return Vt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||S(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Vt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Vt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>dt(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||R(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Dt(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new Dt(this.config,this.options,t)}get context(){return S(this._context)?this._context():this._context}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:a(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.doneData,invoke:this.invoke,description:this.description,tags:this.tags}}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,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=St(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(lt(i,{delay:t})),this.onExit.push(vt(i)),i};return(b(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):u(e(t).map((e,n)=>{const s=t[e],o=w(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(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 i=t instanceof Nt?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=[this];return s.push(...u(n.map(t=>this.getStateNode(t).getStateNodes(i[t])))),s}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(M([],this.getStateNodes(t.value)));return new Nt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this),tags:U(e)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=u(o.map(t=>t.entrySet)),c=u(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}getTransitionData(t,e){return this._transition(t.value,t,N(e))}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:d,in:u}=c,l=t.context,f=!u||(w(u)&&Lt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,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}getActions(t,e,i,n){const s=M([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?M(s,t.configuration):s;for(const e of o)B(s,e)||t.entrySet.push(e);for(const e of s)B(o,e)&&!B(t.exitSet,e.parent)||t.exitSet.push(e);const r=u(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(wt(n.id,n.doneData),wt(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&A(r).every(e=>J(t.configuration,e))&&s.push(wt(r.id)),s}));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]=[u(Array.from(a).map(t=>[...t.activities.map(t=>yt(t)),...t.onEntry])).concat(r.map(ut)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>mt(t))]))];return ht(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=N(e);let s;if(t instanceof Nt)s=void 0===i?t:this.resolveState(Nt.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Nt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=M([],this.getStateNodes(s.value)),h=a.configuration.length?M(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=rt,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?F(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=i?i.context:s,d=this.getActions(t,h,n,i),u=i?Object.assign({},i.activities):{};for(const t of d)t.type===q?u[t.activity.id||t.activity.type]=t:t.type===X&&(u[t.activity.id||t.activity.type]=!1);const[l,f]=jt(this,i,h,n,d,this.machine.config.preserveActionOrder),[g,m]=v(l,t=>t.type===H||t.type===G&&t.to===L.Internal),b=l.filter(t=>{var e;return t.type===q&&(null===(e=t.activity)||void 0===e?void 0:e.type)===tt}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?Ct(r,t.id,a):kt(t.id);return c.meta=t,c}(e.activity,this.machine,f,n),t),i?Object.assign({},i.children):{}),S=a?t.configuration:i?i.configuration:[],x=J(S,this),O=new Nt({value:a||i.value,context:f,_event:n,_sessionid:i?i._sessionid:null,historyValue:a?c?(_=c,j=a,{current:j,states:y(_,j)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?m:[],activities:a?u:i?i.activities:{},events:[],configuration:S,transitions:t.transitions,children:b,done:x,tags:null==i?void 0:i.tags,machine:this});var _,j;const E=h!==f;O.changed=n.name===nt||E;const{history:N}=O;N&&delete N.history;const T=!x&&(this._transient||o.some(t=>t._transient));if(!(r||T&&""!==n.name))return O;let $=O;if(!x)for(T&&($=this.resolveRaisedTransition($,{type:Q},n));g.length;){const t=g.shift();$=this.resolveRaisedTransition($,t._event,n)}const C=$.changed||(N?!!$.actions.length||E||typeof N.value!=typeof $.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}($.value,N.value):void 0);return $.changed=C,$.history=N,$.tags=U($.configuration),$}getStateNode(t){if(Lt(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=Lt(t)?t.slice("#".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&&Lt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(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||It;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):It);case"compound":if(w(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):It):this.initialStateValue||{};default:return t||It}}getResolvedPath(t){if(Lt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||It,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=D(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};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=w(e.target)&&Lt(e.target)?r(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(D(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(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 n=this.getStateNode(e);if("history"===n.type)return n.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(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=w(t)?void 0:t[i];return e.historyValue(n||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?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return w(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(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,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}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(!w(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)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:ht(f(t.actions)),cond:x(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=V(i,[n+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],n=this.config.onDone?T(String(wt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(xt(t.id)),t.onDone)),t.onError&&e.push(...T(String(Ot(t.id)),t.onError)),e})),o=this.after,r=u([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function At(t,e,i=t.context){return new Dt(t,e,i)}function Rt(t,e){return new Dt(t,e)}const Mt={deferEvents:!1};class zt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Mt),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 Ft=new Map;let Bt=0;const Jt={bookId:()=>"x:"+Bt++,register:(t,e)=>(Ft.set(t,e),t),get:t=>Ft.get(t),free(t){Ft.delete(t)}};function Ut(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function qt(t){if(!Ut())return;const e=function(){const t=Ut();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function Xt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=C(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const Ht={sync:!1,autoForward:!1};var Gt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Gt||(Gt={}));class Kt{constructor(t,e=Kt.defaultOptions){this.machine=t,this.scheduler=new zt,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=Gt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(b(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===Gt.Stopped)return this.state;if(this.status!==Gt.Running&&!this.options.deferEvents)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===L.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||Jt.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===it?""+Ot(this.id):t.name,origin:this.sessionId})):n.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({},Kt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new zt({deferEvents:this.options.deferEvents}),this.sessionId=Jt.bookId()}get initialState(){return this._initialState?this._initialState:$t(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.children.forEach(t=>{this.state.children[t.id]=t}),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),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(xt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Gt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Gt.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}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===Gt.Running)return this;Jt.register(this.sessionId,this),this.initialized=!0,this.status=Gt.Running;const e=void 0===t?this.initialState:$t(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Nt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,rt)}),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);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Gt.Stopped,Jt.free(this.sessionId),this}batch(t){if(this.status===Gt.NotStarted&&this.options.deferEvents);else if(this.status!==Gt.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 n=[];for(const s of t){const t=N(s);this.forward(t),e=$t(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Et(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(et)&&!this.state.nextEvents.some(t=>0===t.indexOf(et)))throw e.data.data;return $t(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=this.machine.options.actions){const{context:n,_event:s}=e,o=t.exec||at(t.type,i),r=S(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}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 K:this.cancel(t.sendId);break;case q:{if(this.status!==Gt.Running)return;const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===I.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;if("string"==typeof i)return;let h,d=S(i)?i(n,s.data,{data:c,src:t,meta:e.meta}):i;if(!d)return;_(d)&&(d=c?d.withContext(c):d,h={autoForward:a}),this.spawn(d,o,h)}else this.spawnActivity(e);break}case X:this.stopChild(t.activity.id);break;case Y:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Kt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Ht),e);n.sync&&i.onTransition(t=>{this.send(nt,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=Xt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(N(xt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=Ot(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=C(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(Ot(e,t))}if(g(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(Ot(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(xt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,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:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})})}attachDev(){const t=Ut();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}qt(this)}}toJSON(){return{id:this.id}}[O](){return this}getSnapshot(){return this.status===Gt.NotStarted?this.initialState:this._state}}Kt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Kt.interpret=Wt;function Qt(t,e){const i=(t=>w(t)?Object.assign(Object.assign({},Ht),{name:t}):Object.assign(Object.assign(Object.assign({},Ht),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):Ct(t,i.name))(Tt[Tt.length-1])}function Wt(t,e){return new Kt(t,e)}function Yt(t,e,i){const n=Nt.from(t,t instanceof Nt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function Zt(t){return t}const te={raise:ut,send:lt,sendParent:ft,sendUpdate:pt,log:function(t=gt,e){return{type:Y,label:e,expr:t}},cancel:vt,start:yt,stop:mt,assign:bt,after:St,done:wt,respond:function(t,e){return lt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:_t,escalate:function(t,e){return ft((e,i,n)=>({type:it,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:L.Parent}))},choose:function(t){return{type:I.Choose,conds:t}},pure:function(t){return{type:I.Pure,get:t}}};export{I as ActionTypes,Kt as Interpreter,Gt as InterpreterStatus,At as Machine,L as SpecialTargets,Nt as State,Dt as StateNode,te as actions,bt as assign,Rt as createMachine,Zt as createSchema,xt as doneInvoke,_t as forwardTo,Wt as interpret,P as mapState,Yt as matchState,i as matchesState,lt as send,ft as sendParent,pt as sendUpdate,Qt as spawn};
***************************************************************************** */function Et(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const kt=t=>"atomic"===t.type||"final"===t.type;function Nt(t){return Object.keys(t.states).map(e=>t.states[e])}function Tt(t){return Nt(t).filter(t=>"history"!==t.type)}function At(t){const e=[t];return kt(t)?e:e.concat($(Tt(t).map(At)))}function $t(t,e){const i=Pt(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=Pt(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Tt(t))n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t)))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function Pt(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 It(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(kt(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,Pt($t([t],e)))}function Ct(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Vt(t,e){return"compound"===e.type?Tt(e).some(e=>"final"===e.type&&Ct(t,e)):"parallel"===e.type&&Tt(e).every(e=>Vt(t,e))}function Lt(t){return new Set($(t.map(t=>t.tags)))}function Dt(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 Rt{constructor(t){var e;this.actions=[],this.activities=O,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||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),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,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set($([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Rt)return t.context!==e?new Rt({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 Rt({value:t,context:e,_event:Z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Rt(t)}static inert(t,e){if(t instanceof Rt){if(!t.actions.length)return t;const i=Z;return new Rt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Rt.from(t,e)}toStrings(t=this.value,e="."){if(z(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=Et(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return _(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Mt={deferEvents:!1};class zt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Mt),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 Ut=new Map;let Bt=0;const Ft={bookId:()=>"x:"+Bt++,register:(t,e)=>(Ut.set(t,e),t),get:t=>Ut.get(t),free(t){Ut.delete(t)}};function Jt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function qt(t){if(!Jt())return;const e=function(){const t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function Qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=jt({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=K(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Xt={sync:!1,autoForward:!1};var Ht;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ht||(Ht={}));class Gt{constructor(a,c=Gt.defaultOptions){this.machine=a,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=Ht.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=(t,e)=>{if(R(t))return this.batch(t),this.state;const i=Q(q(t,e));if(this.status===Ht.Stopped)return this.state;if(this.status!==Ht.Running&&!this.options.deferEvents)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,i,n)=>{const s=this.parent&&(i===e.Parent||this.parent.id===i),o=s?this.parent:z(i)?i===e.Internal?this:this.children.get(i)||Ft.get(i):(r=i)&&"function"==typeof r.send?i:void 0;var r;if(o)if("machine"in o){if(this.status!==Ht.Stopped||this.parent!==o||this.state.done){const e=Object.assign(Object.assign({},t),{name:t.name===v?""+mt(this.id):t.name,origin:this.sessionId});!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,e]):o.send(e)}}else!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,t.data]):o.send(t.data);else if(!s)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)},this._exec=(e,a,c,h=this.machine.options.actions)=>{const d=e.exec||tt(e.type,h),l=M(d)?d:d?d.exec:e.exec;if(l)try{return l(a,c.data,this.machine.config.predictableActionArguments?{action:e,_event:c}:{action:e,state:this.state,_event:c})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case s:{const t=e;this.defer(t);break}case o:const h=e;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to,c===Z):this.send(h._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Ht.Running)return;const i=e.activity;if(!this.machine.config.predictableActionArguments&&!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=G(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:s}=i,o="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const r=s?C(s,a,c):void 0;if("string"==typeof e)return;let h,d=M(e)?e(a,c.data,{data:r,src:t,meta:i.meta}):e;if(!d)return;F(d)&&(d=r?d.withContext(r):d,h={autoForward:o}),this.spawn(d,n,h)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case u:const{label:d,value:l}=e;d?this.logger(d,l):this.logger(l)}};const h=Object.assign(Object.assign({},Gt.defaultOptions),c),{clock:d,logger:l,parent:f,id:p}=h,g=void 0!==p?p:a.id;this.id=g,this.logger=l,this.clock=d,this.parent=f,this.options=h,this.scheduler=new zt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:_t(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.machine.config.predictableActionArguments&&e!==Z||!this.options.execute){let t;for(;t=this._outgoingQueue.shift();)t[0].send(t[1])}else this.execute(this.state);if(this.children.forEach(t=>{this.state.children[t.id]=t}),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);if(this.state.done){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?C(i.doneData,t.context,e):void 0;this._doneEvent=yt(this.id,n);for(const t of this.doneListeners)t(this._doneEvent);this._stop(),this._stopChildren(),Ft.free(this.sessionId)}}onTransition(t){return this.listeners.add(t),this.status===Ht.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){const n=K(t,e,i);this.listeners.add(n.next),this.status!==Ht.NotStarted&&n.next(this.state);const s=()=>{this.doneListeners.delete(s),this.stopListeners.delete(s),n.complete()};return this.status===Ht.Stopped?n.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:()=>{this.listeners.delete(n.next),this.doneListeners.delete(s),this.stopListeners.delete(s)}}}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.status===Ht.Stopped&&this._doneEvent?t(this._doneEvent):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===Ht.Running)return this;this.machine._init(),Ft.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:_t(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Rt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Z)}),this}_stopChildren(){this.children.forEach(t=>{M(t.stop)&&t.stop()}),this.children.clear()}_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);if(!this.initialized)return this;this.initialized=!1,this.status=Ht.Stopped,this._initialState=void 0;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);this.scheduler.clear(),this.scheduler=new zt({deferEvents:this.options.deferEvents})}stop(){const t=this.scheduler;return this._stop(),t.schedule(()=>{const t=Q({type:"xstate.stop"}),e=_t(this,()=>{const e=$([...this.state.configuration].sort((t,e)=>e.order-t.order).map(t=>it(t.onExit,this.machine.options.actions))),[i,n]=bt(this.machine,this.state,this.state.context,t,[{type:"exit",actions:e}],this.machine.config.predictableActionArguments?this._exec:void 0,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),s=new Rt({value:this.state.value,context:n,_event:t,_sessionid:this.sessionId,historyValue:void 0,history:this.state,actions:i.filter(t=>!Y(t)),activities:{},events:[],configuration:[],transitions:[],children:{},done:this.state.done,tags:this.state.tags,machine:this.machine});return s.changed=!0,s});this.update(e,t),this._stopChildren(),Ft.free(this.sessionId)}),this}batch(t){if(this.status===Ht.NotStarted&&this.options.deferEvents);else if(this.status!==Ht.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.`);if(!t.length)return;const e=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(()=>{let i=this.state,n=!1;const s=[];for(const o of t){const t=Q(o);this.forward(t),i=_t(this,()=>this.machine.transition(i,t,void 0,e||void 0)),s.push(...this.machine.config.predictableActionArguments?i.actions:i.actions.map(t=>Dt(t,i))),n=n||!!i.changed}i.changed=n,i.actions=s,this.update(i,Q(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}_nextState(t,e=!!this.machine.config.predictableActionArguments&&this._exec){const i=Q(t);if(0===i.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw i.data.data;return _t(this,()=>this.machine.transition(this.state,i,void 0,e||void 0))}nextState(t){return this._nextState(t,!1)}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){const e=this.clock.setTimeout(()=>{"to"in t&&t.to?this.sendTo(t._event,t.to,!0):this.send(t._event)},t.delay);t.id&&(this.delayedEventsMap[t.id]=e)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){this._exec(t,e.context,e._event,i)}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),M(e.stop)&&e.stop())}spawn(t,e,i){if(this.status!==Ht.Running)return wt(t,e);if(V(t))return this.spawnPromise(Promise.resolve(t),e);if(M(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&M(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(F(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Gt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Xt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(Q(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=Qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(Q(yt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=mt(e,t);try{this.send(Q(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=K(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(Q(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(mt(e,t))}if(V(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=K(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,M(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(Q(t,{origin:e}))},t=>{this.removeChild(e),this.send(Q(mt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(Q(yt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,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:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Jt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}qt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Ht.NotStarted?this.initialState:this._state}}Gt.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1},Gt.interpret=Wt;function Kt(t,e){const i=(t=>z(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:J()}),t))(e);return(e=>e?e.spawn(t,i.name,i):wt(t,i.name))(Ot[Ot.length-1])}function Wt(t,e){return new Gt(t,e)}function Yt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Zt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=Et(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Yt(t.src)})}})}const te={},ee=t=>"#"===t[0];class ie{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;this.config=t,this._context=i,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.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.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:"."),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&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ie(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):te;let o=0;!function t(e){e.order=o++;for(const i of Nt(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=I(this.config.entry||this.config.onEntry).map(t=>et(t)),this.onExit=I(this.config.exit||this.config.onExit).map(t=>et(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=I(this.config.invoke).map((t,e)=>{if(F(t)){const i=W(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Zt({src:i,id:i})}if(z(t.src)){const i=t.id||W(this.id,e);return Zt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(F(t.src)||M(t.src)){const i=t.id||W(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Zt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Zt(Object.assign(Object.assign({id:W(this.id,e)},t),{src:i}))}}),this.activities=I(this.config.activities).concat(this.invoke).map(t=>nt(t)),this.transition=this.transition.bind(this),this.tags=I(this.config.tags)}_init(){this.__cache.transitions||At(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ie(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ie(this.config,this.options,t)}get context(){return M(this._context)?this._context():this._context}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:k(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.doneData,invoke:this.invoke,description:this.description,tags:this.tags}}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,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=gt(M(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(rt(i,{delay:t})),this.onExit.push(ut(i)),i};return(R(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):$(Object.keys(t).map((i,n)=>{const s=t[i],o=z(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return I(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 Rt?t.value:j(t,this.delimiter);if(z(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...$(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=x(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Rt?t:Rt.create(t),i=Array.from($t([],this.getStateNodes(e.value)));return new Rt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Vt(i,this),tags:Lt(i),machine:this.machine}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=$(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=$(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,exitSet:$(s.map(t=>t.exitSet)),configuration:r,source:e,actions:$(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return z(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,Q(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,d=!c||(z(c)&&ee(c)?t.matches(j(this.getStateNodeById(c).path,this.delimiter)):_(j(c,this.delimiter),T(this.path.slice(0,-2))(t.value)));let u=!1;try{u=!a||H(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(u&&d){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=$(o.map(e=>this.getRelativeStateNodes(e,t.historyValue)));return{transitions:[s],exitSet:!!s.internal?[]:$(o.map(t=>this.getPotentiallyReenteringNodes(t))),configuration:r,source:t,actions:n}}getPotentiallyReenteringNodes(t){if(this.order<t.order)return[this];const e=[];let i=this,n=t;for(;i&&i!==n;)e.push(i),i=i.parent;return i!==n?[]:(e.push(n),e)}getActions(t,e,i,n,s,o,r){const a=o?$t([],this.getStateNodes(o.value)):[],c=new Set;for(const e of Array.from(t).sort((t,e)=>t.order-e.order))(!Ct(a,e)||Ct(i.exitSet,e)||e.parent&&c.has(e.parent))&&c.add(e);for(const e of a)Ct(t,e)&&!Ct(i.exitSet,e.parent)||i.exitSet.push(e);i.exitSet.sort((t,e)=>e.order-t.order);const h=Array.from(c).sort((t,e)=>t.order-e.order),d=new Set(i.exitSet),u=$(h.map(t=>{const e=[];if("final"!==t.type)return e;const o=t.parent;if(!o.parent)return e;e.push(vt(t.id,t.doneData),vt(o.id,t.doneData?C(t.doneData,n,s):void 0));const r=o.parent;return"parallel"===r.type&&Tt(r).every(t=>Vt(i.configuration,t))&&e.push(vt(r.id)),e})),l=h.map(t=>{const e=t.onEntry,i=t.activities.map(t=>lt(t));return{type:"entry",actions:it(r?[...e,...i]:[...i,...e],this.machine.options.actions)}}).concat({type:"state_done",actions:u.map(t=>st(t))}),f=Array.from(d).map(t=>({type:"exit",actions:it([...t.onExit,...t.activities.map(t=>ft(t))],this.machine.options.actions)})).concat({type:"transition",actions:it(i.actions,this.machine.options.actions)}).concat(l);if(e){const e=it($([...t].sort((t,e)=>e.order-t.order).map(t=>t.onExit)),this.machine.options.actions).filter(t=>!Y(t));return f.concat({type:"stop",actions:e})}return f}transition(t=this.initialState,e,i,n){const s=Q(e);let o;if(t instanceof Rt)o=void 0===i?t:this.resolveState(Rt.from(t,i));else{const e=z(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;o=this.resolveState(Rt.from(e,n))}if(this.strict&&!this.events.includes(s.name)&&(r=s.name,!/^(done|error)\./.test(r)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var r;const a=this._transition(o.value,o,s)||{transitions:[],configuration:[],exitSet:[],source:o,actions:[]},c=$t([],this.getStateNodes(o.value)),h=a.configuration.length?$t(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,o,o.context,n,s)}resolveRaisedTransition(t,e,i,n){const s=t.actions;return(t=this.transition(t,e,void 0,n))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,e,s,o,r=Z){const{configuration:c}=t,h=!e||t.transitions.length>0,d=h?t.configuration:e?e.configuration:[],u=Vt(d,this),l=h?It(this.machine,c):void 0,p=e?e.historyValue?e.historyValue:t.source?this.machine.historyValue(e.value):void 0:void 0,g=this.getActions(new Set(d),u,t,s,r,e,o),v=e?Object.assign({},e.activities):{};for(const t of g)for(const e of t.actions)e.type===i?v[e.activity.id||e.activity.type]=e:e.type===n&&(v[e.activity.id||e.activity.type]=!1);const[m,b]=bt(this,e,s,r,g,o,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),[S,O]=function(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}(m,Y),_=m.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=G(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?C(t.data,i,n):void 0,c=r?wt(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,b,r),t),e?Object.assign({},e.children):{}),x=new Rt({value:l||e.value,context:b,_event:r,_sessionid:e?e._sessionid:null,historyValue:l?p?(w=p,j=l,{current:j,states:L(w,j)}):void 0:e?e.historyValue:void 0,history:!l||t.source?e:void 0,actions:l?O:[],activities:l?v:e?e.activities:{},events:[],configuration:d,transitions:t.transitions,children:_,done:u,tags:Lt(d),machine:this});var w,j;const E=s!==b;x.changed=r.name===y||E;const{history:k}=x;k&&delete k.history;const N=!u&&(this._transient||c.some(t=>t._transient));if(!(h||N&&""!==r.name))return x;let T=x;if(!u)for(N&&(T=this.resolveRaisedTransition(T,{type:a},r,o));S.length;){const t=S.shift();T=this.resolveRaisedTransition(T,t._event,r,o)}const A=T.changed||(k?!!T.actions.length||E||typeof k.value!=typeof T.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(z(e)||z(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(T.value,k.value):void 0);return T.changed=A,T.history=k,T}getStateNode(t){if(ee(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=ee(t)?t.slice("#".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&&ee(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=w(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||te;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):te);case"compound":if(z(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):te):this.initialStateValue||{};default:return t||te}}getResolvedPath(t){if(ee(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return w(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=N(this.states,t=>t.initialStateValue||te,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=kt(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){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=z(e.target)&&ee(e.target)?E(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(kt(this))return[this];if("compound"===this.type&&!this.initial)return[this];return $(A(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 n=this.getStateNode(e);if("history"===n.type)return n.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(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:N(this.states,(e,i)=>{if(!t)return e.historyValue();const n=z(t)?void 0:t[i];return e.historyValue(n||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?$(A(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return z(i)?[e.getStateNode(i)]:$(A(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=$(Object.keys(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 Object.keys(t)){const n=t[i];if(n.states)for(const t of n.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(!z(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)return I(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>z(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:it(I(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=Et(e,[i+""]);t=$(Object.keys(o).map(t=>X(t,o[t])).concat(X("*",s)))}else t=[];const e=this.config.always?X("",this.config.always):[],i=this.config.onDone?X(String(vt(this.id)),this.config.onDone):[],n=$(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...X(String(yt(t.id)),t.onDone)),t.onError&&e.push(...X(String(mt(t.id)),t.onError)),e})),s=this.after,o=$([...i,...n,...t,...e].map(t=>I(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ne(t,e,i=t.context){return new ie(t,e,i)}function se(t,e){return new ie(t,e)}function oe(t,e){let i;for(const n of Object.keys(t))_(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function re(t,e,i){const n=Rt.from(t,t instanceof Rt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function ae(t){return t}const ce=ae,{assign:he,cancel:de,send:ue,sendTo:le,sendParent:fe,sendUpdate:pe,forwardTo:ge,doneInvoke:ve,raise:ye,log:me,pure:be,choose:Se,stop:Oe}=St;export{t as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,ne as Machine,e as SpecialTargets,Rt as State,ie as StateNode,St as actions,he as assign,de as cancel,Se as choose,se as createMachine,ae as createSchema,ve as doneInvoke,ge as forwardTo,Wt as interpret,me as log,oe as mapState,re as matchState,_ as matchesState,be as pure,ye as raise,ue as send,fe as sendParent,le as sendTo,pe as sendUpdate,Kt as spawn,Qt as spawnBehavior,Oe as stop,ce as t,jt as toActorRef,q as toEventObject,K as toObserver,Q as toSCXMLEvent};

@@ -1,6 +0,5 @@

import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject, Cast, EventFrom, AnyActorRef, PredictableActionArgumentsExec, RaiseActionOptions, NoInfer, BaseActionObject, LowInfer } from './types';
import * as actionTypes from './actionTypes';
import { State } from './State';
import { StateNode } from './StateNode';
import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
export { actionTypes };

@@ -12,3 +11,3 @@ export declare const initEvent: SCXML.Event<{

export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, BaseActionObject> | undefined) => ActionObject<TContext, TEvent, TEvent, BaseActionObject>[];
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;

@@ -21,4 +20,4 @@ /**

*/
export declare function raise<TContext, TEvent extends EventObject>(event: Event<TEvent>): RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>;
export declare function resolveRaise<TEvent extends EventObject>(action: RaiseAction<TEvent>): RaiseActionObject<TEvent>;
export declare function raise<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(event: NoInfer<Event<TEvent>> | SendExpr<TContext, TExpressionEvent, TEvent>, options?: RaiseActionOptions<TContext, TExpressionEvent>): RaiseAction<TContext, TExpressionEvent, TEvent>;
export declare function resolveRaise<TContext, TEvent extends EventObject, TExpressionEvent extends EventObject>(action: RaiseAction<TContext, TExpressionEvent, TEvent>, ctx: TContext, _event: SCXML.Event<TExpressionEvent>, delaysMap?: DelayFunctionMap<TContext, TEvent>): RaiseActionObject<TContext, TExpressionEvent, TEvent>;
/**

@@ -28,2 +27,4 @@ * Sends an event. This returns an action that will be read by an interpreter to

*
* @deprecated Use the `sendTo(...)` action creator instead.
*
* @param event The event to send.

@@ -35,3 +36,3 @@ * @param options Options to pass into the send event:

*/
export declare function send<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
export declare function send<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<AnyEventObject> | SendExpr<TContext, TEvent, AnyEventObject>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
export declare function resolveSend<TContext, TEvent extends EventObject, TSentEvent extends EventObject>(action: SendAction<TContext, TEvent, TSentEvent>, ctx: TContext, _event: SCXML.Event<TEvent>, delaysMap?: DelayFunctionMap<TContext, TEvent>): SendActionObject<TContext, TEvent, TSentEvent>;

@@ -44,3 +45,3 @@ /**

*/
export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<AnyEventObject> | SendExpr<TContext, TEvent, AnyEventObject>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
declare type InferEvent<E extends EventObject> = {

@@ -61,9 +62,7 @@ [T in E['type']]: {

*/
export declare function sendTo<TContext, TEvent extends EventObject, TActor extends ActorRef<EventObject>>(actor: (ctx: TContext) => TActor, event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
export declare function sendTo<TContext, TEvent extends EventObject, TActor extends AnyActorRef>(actor: string | TActor | ((ctx: TContext, event: TEvent) => TActor), event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
/**
* Sends an update event to this machine's parent.
*/
export declare function sendUpdate<TContext, TEvent extends EventObject>(): SendAction<TContext, TEvent, {
type: ActionTypes.Update;
}>;
export declare function sendUpdate<TContext, TEvent extends EventObject>(): SendAction<TContext, TEvent, any>;
/**

@@ -84,4 +83,4 @@ * Sends an event back to the sender of the original event.

*/
export declare function log<TContext, TEvent extends EventObject>(expr?: string | LogExpr<TContext, TEvent>, label?: string): LogAction<TContext, TEvent>;
export declare const resolveLog: <TContext, TEvent extends EventObject>(action: LogAction<TContext, TEvent>, ctx: TContext, _event: SCXML.Event<TEvent>) => LogActionObject<TContext, TEvent>;
export declare function log<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(expr?: string | LogExpr<TContext, TExpressionEvent>, label?: string): LogAction<TContext, TExpressionEvent, TEvent>;
export declare const resolveLog: <TContext, TEvent extends EventObject>(action: LogAction<TContext, TEvent, TEvent>, ctx: TContext, _event: SCXML.Event<TEvent>) => LogActionObject<TContext, TEvent>;
/**

@@ -94,3 +93,3 @@ * Cancels an in-flight `send(...)` action. A canceled sent action will not

*/
export declare const cancel: (sendId: string | number) => CancelAction;
export declare const cancel: <TContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(sendId: string | number) => CancelAction<TContext, TExpressionEvent, TEvent>;
/**

@@ -107,5 +106,5 @@ * Starts an activity.

*/
export declare function stop<TContext, TEvent extends EventObject>(actorRef: string | ActivityDefinition<TContext, TEvent> | Expr<TContext, TEvent, string | {
export declare function stop<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(actorRef: string | Expr<TContext, TExpressionEvent, string | {
id: string;
}>): StopAction<TContext, TEvent>;
}>): StopAction<TContext, TExpressionEvent, TEvent>;
export declare function resolveStop<TContext, TEvent extends EventObject>(action: StopAction<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>): StopActionObject;

@@ -117,3 +116,3 @@ /**

*/
export declare const assign: <TContext, TEvent extends EventObject = EventObject>(assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>) => AssignAction<TContext, TEvent>;
export declare const assign: <TContext, TExpressionEvent extends EventObject = EventObject, TEvent extends EventObject = TExpressionEvent>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent>) => AssignAction<TContext, TExpressionEvent, TEvent>;
export declare function isActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>): action is ActionObject<TContext, TEvent>;

@@ -147,3 +146,3 @@ /**

export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
export declare function pure<TContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined): PureAction<TContext, TEvent>;
export declare function pure<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(getActions: (context: TContext, event: TExpressionEvent) => SingleOrArray<BaseActionObject | BaseActionObject['type'] | ActionObject<TContext, TExpressionEvent, TEvent> | ActionFunction<TContext, TExpressionEvent>> | undefined): PureAction<TContext, TExpressionEvent, TEvent>;
/**

@@ -155,3 +154,3 @@ * Forwards (sends) an event to a specified service.

*/
export declare function forwardTo<TContext, TEvent extends EventObject>(target: Required<SendActionOptions<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
export declare function forwardTo<TContext, TEvent extends EventObject>(target: Required<SendActionOptions<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
/**

@@ -164,5 +163,8 @@ * Escalates an error by sending it as an event to this machine's parent.

*/
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
export declare function choose<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(conds: Array<ChooseCondition<TContext, TExpressionEvent, TEvent>>): ChooseAction<TContext, TExpressionEvent, TEvent>;
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<{
type: string;
actions: Array<ActionObject<TContext, TEvent>>;
}>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
//# sourceMappingURL=actions.d.ts.map

@@ -1,6 +0,8 @@

import { __assign, __read, __spreadArray } from './_virtual/_tslib.js';
import { __assign, __spreadArray, __read, __values } from './_virtual/_tslib.js';
import { SpecialTargets, ActionTypes } from './types.js';
import { init, raise as raise$1, send as send$1, update, log as log$1, cancel as cancel$1, assign as assign$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1 } from './actionTypes.js';
import * as actionTypes from './actionTypes.js';
export { actionTypes };
import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType, updateContext, flatten, isArray, toArray, toGuard, evaluateGuard, warn } from './utils.js';
import { IS_PRODUCTION } from './environment.js';
import { isFunction, toEventObject, getEventType, toSCXMLEvent, isString, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
import { SpecialTargets, ActionTypes } from './types.js';
import { send as send$1, update, assign as assign$1, init, raise as raise$1, log as log$1, cancel as cancel$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1 } from './actionTypes.js';

@@ -82,19 +84,29 @@ var initEvent = /*#__PURE__*/toSCXMLEvent({

function raise(event) {
if (!isString(event)) {
return send(event, {
to: SpecialTargets.Internal
});
}
function raise(event, options) {
return {
type: raise$1,
event: event
event: typeof event === 'function' ? event : toEventObject(event),
delay: options ? options.delay : undefined,
id: options === null || options === void 0 ? void 0 : options.id
};
}
function resolveRaise(action) {
return {
function resolveRaise(action, ctx, _event, delaysMap) {
var meta = {
_event: _event
};
var resolvedEvent = toSCXMLEvent(isFunction(action.event) ? action.event(ctx, _event.data, meta) : action.event);
var resolvedDelay;
if (isString(action.delay)) {
var configDelay = delaysMap && delaysMap[action.delay];
resolvedDelay = isFunction(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
} else {
resolvedDelay = isFunction(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
}
return __assign(__assign({}, action), {
type: raise$1,
_event: toSCXMLEvent(action.event)
};
_event: resolvedEvent,
delay: resolvedDelay
});
}

@@ -105,2 +117,4 @@ /**

*
* @deprecated Use the `sendTo(...)` action creator instead.
*
* @param event The event to send.

@@ -119,2 +133,4 @@ * @param options Options to pass into the send event:

delay: options ? options.delay : undefined,
// TODO: don't auto-generate IDs here like that
// there is too big chance of the ID collision
id: options && options.id !== undefined ? options.id : isFunction(event) ? event.name : getEventType(event)

@@ -159,2 +175,16 @@ };

/**
* Sends an event to an actor.
*
* @param actor The `ActorRef` to send the event to.
* @param event The event to send, or an expression that evaluates to the event to send
* @param options Send action options
* @returns An XState send action object
*/
function sendTo(actor, event, options) {
return send(event, __assign(__assign({}, options), {
to: actor
}));
}
/**
* Sends an update event to this machine's parent.

@@ -281,2 +311,5 @@ */

};
function isActionObject(action) {
return typeof action === 'object' && 'type' in action;
}
/**

@@ -365,2 +398,22 @@ * Returns an event type that represents an implicit event that

function forwardTo(target, options) {
if (!IS_PRODUCTION && (!target || typeof target === 'function')) {
var originalTarget_1 = target;
target = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var resolvedTarget = typeof originalTarget_1 === 'function' ? originalTarget_1.apply(void 0, __spreadArray([], __read(args), false)) : originalTarget_1;
if (!resolvedTarget) {
throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");
}
return resolvedTarget;
};
}
return send(function (_, event) {

@@ -396,3 +449,39 @@ return event;

}
function resolveActions(machine, currentState, currentContext, _event, actions, preserveActionOrder) {
var pluckAssigns = function (actionBlocks) {
var e_1, _a;
var assignActions = [];
try {
for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
var block = actionBlocks_1_1.value;
var i = 0;
while (i < block.actions.length) {
if (block.actions[i].type === assign$1) {
assignActions.push(block.actions[i]);
block.actions.splice(i, 1);
continue;
}
i++;
}
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
} finally {
if (e_1) throw e_1.error;
}
}
return assignActions;
};
function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
if (preserveActionOrder === void 0) {

@@ -402,11 +491,8 @@ preserveActionOrder = false;

var _a = __read(preserveActionOrder ? [[], actions] : partition(actions, function (action) {
return action.type === assign$1;
}), 2),
assignActions = _a[0],
otherActions = _a[1];
var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
var updatedContext = assignActions.length ? updateContext(currentContext, _event, assignActions, currentState) : currentContext;
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
var resolvedActions = flatten(otherActions.map(function (actionObject) {
var deferredToBlockEnd = [];
function handleAction(blockType, actionObject) {
var _a;

@@ -416,4 +502,12 @@

case raise$1:
return resolveRaise(actionObject);
{
var raisedAction = resolveRaise(actionObject, updatedContext, _event, machine.options.delays);
if (predictableExec && typeof raisedAction.delay === 'number') {
predictableExec(raisedAction, updatedContext, _event);
}
return raisedAction;
}
case send$1:

@@ -423,11 +517,24 @@ var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init

if (!IS_PRODUCTION) {
// warn after resolving as we can create better contextual message here
warn(!isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
var configuredDelay = actionObject.delay; // warn after resolving as we can create better contextual message here
warn(!isString(configuredDelay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
"No delay reference for delay expression '".concat(configuredDelay, "' was found on machine '").concat(machine.id, "'"));
}
if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
if (blockType === 'entry') {
deferredToBlockEnd.push(sendAction);
} else {
predictableExec(sendAction, updatedContext, _event);
}
}
return sendAction;
case log$1:
return resolveLog(actionObject, updatedContext, _event);
{
var resolved = resolveLog(actionObject, updatedContext, _event);
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
return resolved;
}

@@ -439,3 +546,3 @@ case choose$1:

var guard = toGuard(condition.cond, machine.options.guards);
return !guard || evaluateGuard(machine, guard, updatedContext, _event, currentState);
return !guard || evaluateGuard(machine, guard, updatedContext, _event, !predictableExec ? currentState : undefined);
})) === null || _a === void 0 ? void 0 : _a.actions;

@@ -447,3 +554,6 @@

var _b = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [{
type: blockType,
actions: toActionObjects(toArray(matchedActions), machine.options.actions)
}], predictableExec, preserveActionOrder), 2),
resolvedActionsFromChoose = _b[0],

@@ -465,3 +575,6 @@ resolvedContextFromChoose = _b[1];

var _c = __read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [{
type: blockType,
actions: toActionObjects(toArray(matchedActions), machine.options.actions)
}], predictableExec, preserveActionOrder), 2),
resolvedActionsFromPure = _c[0],

@@ -477,3 +590,5 @@ resolvedContext = _c[1];

{
return resolveStop(actionObject, updatedContext, _event);
var resolved = resolveStop(actionObject, updatedContext, _event);
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
return resolved;
}

@@ -483,3 +598,3 @@

{
updatedContext = updateContext(updatedContext, _event, [actionObject], currentState);
updatedContext = updateContext(updatedContext, _event, [actionObject], !predictableExec ? currentState : undefined);
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);

@@ -493,5 +608,8 @@ break;

if (exec_1 && preservedContexts) {
if (predictableExec) {
predictableExec(resolvedActionObject, updatedContext, _event);
} else if (exec_1 && preservedContexts) {
var contextIndex_1 = preservedContexts.length - 1;
resolvedActionObject = __assign(__assign({}, resolvedActionObject), {
var wrapped = __assign(__assign({}, resolvedActionObject), {
exec: function (_ctx) {

@@ -507,2 +625,4 @@ var args = [];

});
resolvedActionObject = wrapped;
}

@@ -512,8 +632,41 @@

}
}).filter(function (a) {
return !!a;
}));
}
function processBlock(block) {
var e_2, _a;
var resolvedActions = [];
try {
for (var _b = __values(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
var action = _c.value;
var resolved = handleAction(block.type, action);
if (resolved) {
resolvedActions = resolvedActions.concat(resolved);
}
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_2) throw e_2.error;
}
}
deferredToBlockEnd.forEach(function (action) {
predictableExec(action, updatedContext, _event);
});
deferredToBlockEnd.length = 0;
return resolvedActions;
}
var resolvedActions = flatten(actionBlocks.map(processBlock));
return [resolvedActions, updatedContext];
}
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };
export { after, assign, cancel, choose, done, doneInvoke, error, escalate, forwardTo, getActionFunction, initEvent, isActionObject, log, pure, raise, resolveActions, resolveLog, resolveRaise, resolveSend, resolveStop, respond, send, sendParent, sendTo, sendUpdate, start, stop, toActionObject, toActionObjects, toActivityDefinition };

@@ -1,3 +0,2 @@

import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
import { ActorRef, BaseActorRef } from '.';
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML, ActorRef, BaseActorRef } from './types';
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {

@@ -25,3 +24,3 @@ id: string;

export declare function isSpawnedActor(item: any): item is ActorRef<any>;
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted>;
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
//# sourceMappingURL=Actor.d.ts.map
import { __assign } from './_virtual/_tslib.js';
import { toInvokeSource, mapContext, isMachine } from './utils.js';
import { symbolObservable, toInvokeSource, mapContext, isMachine } from './utils.js';
import { provide } from './serviceScope.js';
function createNullActor(id) {
return {
var _a;
return _a = {
id: id,

@@ -26,3 +28,5 @@ send: function () {

}
};
}, _a[symbolObservable] = function () {
return this;
}, _a;
}

@@ -74,5 +78,8 @@ /**

return isActor(item) && 'id' in item;
}
} // TODO: refactor the return type, this could be written in a better way but it's best to avoid unneccessary breaking changes now
function toActorRef(actorRefLike) {
return __assign({
var _a;
return __assign((_a = {
subscribe: function () {

@@ -89,5 +96,7 @@ return {

}
}, actorRefLike);
}, _a[symbolObservable] = function () {
return this;
}, _a), actorRefLike);
}
export { createDeferredActor, createInvocableActor, createNullActor, isActor, isSpawnedActor, toActorRef };

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

import { ActorContext, ActorRef, Behavior, EventObject } from '.';
import { ActorContext, ActorRef, Behavior, EventObject } from './types';
/**

@@ -3,0 +3,0 @@ * Returns an actor behavior from a reducer and its initial state.

@@ -1,7 +0,73 @@

import './environment.js';
import { error, doneInvoke } from './actions.js';
import { toActorRef } from './Actor.js';
import { toObserver } from './utils.js';
import './types.js';
import './actionTypes.js';
import { toActorRef } from './Actor.js';
/**
* Returns an actor behavior from a reducer and its initial state.
*
* @param transition The pure reducer that returns the next state given the current state and event.
* @param initialState The initial state of the reducer.
* @returns An actor behavior
*/
function fromReducer(transition, initialState) {
return {
transition: transition,
initialState: initialState
};
}
function fromPromise(promiseFn) {
var initialState = {
error: undefined,
data: undefined,
status: 'pending'
};
return {
transition: function (state, event, _a) {
var parent = _a.parent,
id = _a.id,
observers = _a.observers;
switch (event.type) {
case 'fulfill':
parent === null || parent === void 0 ? void 0 : parent.send(doneInvoke(id, event.data));
return {
error: undefined,
data: event.data,
status: 'fulfilled'
};
case 'reject':
parent === null || parent === void 0 ? void 0 : parent.send(error(id, event.error));
observers.forEach(function (observer) {
observer.error(event.error);
});
return {
error: event.error,
data: undefined,
status: 'rejected'
};
default:
return state;
}
},
initialState: initialState,
start: function (_a) {
var self = _a.self;
promiseFn().then(function (data) {
self.send({
type: 'fulfill',
data: data
});
}, function (reason) {
self.send({
type: 'reject',
error: reason
});
});
return initialState;
}
};
}
function spawnBehavior(behavior, options) {

@@ -65,2 +131,2 @@ if (options === void 0) {

export { spawnBehavior };
export { fromPromise, fromReducer, spawnBehavior };

@@ -1,11 +0,10 @@

import { Interpreter } from '.';
import { AnyInterpreter } from './types';
declare type ServiceListener = (service: AnyInterpreter) => void;
export interface XStateDevInterface {
register: (service: Interpreter<any>) => void;
unregister: (service: Interpreter<any>) => void;
register: (service: AnyInterpreter) => void;
unregister: (service: AnyInterpreter) => void;
onRegister: (listener: ServiceListener) => {
unsubscribe: () => void;
};
services: Set<Interpreter<any>>;
services: Set<AnyInterpreter>;
}

@@ -12,0 +11,0 @@ export declare function getGlobal(): typeof globalThis | undefined;

@@ -1,2 +0,3 @@

// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
import { IS_PRODUCTION } from './environment.js';
function getGlobal() {

@@ -19,3 +20,5 @@ if (typeof globalThis !== 'undefined') {

return undefined;
if (!IS_PRODUCTION) {
console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
}
}

@@ -22,0 +25,0 @@

@@ -1,31 +0,22 @@

import { matchesState } from './utils';
import * as actions from './actions';
import { Actor, toActorRef } from './Actor';
import { interpret, Interpreter, InterpreterStatus, spawn } from './interpreter';
import { createMachine, Machine } from './Machine';
import { mapState } from './mapState';
import { matchState } from './match';
import { createSchema, t } from './schema';
import { State } from './State';
import { StateNode } from './StateNode';
import { State } from './State';
import { Machine, createMachine } from './Machine';
import { Actor } from './Actor';
import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
import { matchState } from './match';
import { createSchema } from './schema';
declare const actions: {
raise: typeof raise;
send: typeof send;
sendParent: typeof sendParent;
sendUpdate: typeof sendUpdate;
log: typeof log;
cancel: (sendId: string | number) => import("./types").CancelAction;
start: typeof start;
stop: typeof stop;
assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
after: typeof after;
done: typeof done;
respond: typeof respond;
forwardTo: typeof forwardTo;
escalate: typeof escalate;
choose: typeof choose;
pure: typeof pure;
};
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
export { spawnBehavior } from './behaviors';
export { XStateDevInterface } from './devTools';
export * from './typegenTypes';
export * from './types';
export { matchesState, toEventObject, toObserver, toSCXMLEvent } from './utils';
export { Actor, toActorRef, Machine, StateNode, State, mapState, actions, assign, cancel, send, sendTo, sendParent, sendUpdate, raise, log, pure, choose, stop, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
declare const assign: <TContext, TExpressionEvent extends import("./types").EventObject = import("./types").EventObject, TEvent extends import("./types").EventObject = TExpressionEvent>(assignment: import("./types").Assigner<import("./types").LowInfer<TContext>, TExpressionEvent> | import("./types").PropertyAssigner<import("./types").LowInfer<TContext>, TExpressionEvent>) => import("./types").AssignAction<TContext, TExpressionEvent, TEvent>, cancel: <TContext, TExpressionEvent extends import("./types").EventObject, TEvent extends import("./types").EventObject>(sendId: string | number) => import("./types").CancelAction<TContext, TExpressionEvent, TEvent>, send: typeof actions.send, sendTo: typeof actions.sendTo, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke, raise: typeof actions.raise, log: typeof actions.log, pure: typeof actions.pure, choose: typeof actions.choose, stop: typeof actions.stop;
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
//# sourceMappingURL=index.d.ts.map

@@ -1,32 +0,30 @@

export { matchesState } from './utils.js';
import { assign as assign$1, cancel as cancel$1, send as send$1, sendTo as sendTo$1, sendParent as sendParent$1, sendUpdate as sendUpdate$1, forwardTo as forwardTo$1, doneInvoke as doneInvoke$1, raise as raise$1, log as log$1, pure as pure$1, choose as choose$1, stop as stop$1 } from './actions.js';
import * as actions from './actions.js';
export { actions };
export { toActorRef } from './Actor.js';
export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
export { Machine, createMachine } from './Machine.js';
export { mapState } from './mapState.js';
export { ActionTypes, SpecialTargets } from './types.js';
import { raise, send, sendParent, sendUpdate, log, cancel, start, stop, assign, after, done, respond, forwardTo, escalate, choose, pure } from './actions.js';
export { assign, doneInvoke, forwardTo, send, sendParent, sendUpdate } from './actions.js';
export { matchState } from './match.js';
export { createSchema, t } from './schema.js';
export { State } from './State.js';
export { StateNode } from './StateNode.js';
export { Machine, createMachine } from './Machine.js';
export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
export { matchState } from './match.js';
export { createSchema } from './schema.js';
export { spawnBehavior } from './behaviors.js';
export { ActionTypes, SpecialTargets } from './types.js';
export { matchesState, toEventObject, toObserver, toSCXMLEvent } from './utils.js';
var actions = {
raise: raise,
send: send,
sendParent: sendParent,
sendUpdate: sendUpdate,
log: log,
cancel: cancel,
start: start,
stop: stop,
assign: assign,
after: after,
done: done,
respond: respond,
forwardTo: forwardTo,
escalate: escalate,
choose: choose,
pure: pure
};
var assign = assign$1,
cancel = cancel$1,
send = send$1,
sendTo = sendTo$1,
sendParent = sendParent$1,
sendUpdate = sendUpdate$1,
forwardTo = forwardTo$1,
doneInvoke = doneInvoke$1,
raise = raise$1,
log = log$1,
pure = pure$1,
choose = choose$1,
stop = stop$1;
export { actions };
export { assign, cancel, choose, doneInvoke, forwardTo, log, pure, raise, send, sendParent, sendTo, sendUpdate, stop };

@@ -1,7 +0,9 @@

import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription, StateConfig, InteropSubscribable } from './types';
import { State } from './State';
import { symbolObservable } from './utils';
import { AreAllImplementationsAssumedToBeProvided, MissingImplementationsError, TypegenDisabled } from './typegenTypes';
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
}, TResolvedTypesMeta = TypegenDisabled> = (state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, event: TEvent) => void;
export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;

@@ -24,12 +26,7 @@ export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;

}
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
}, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>> {
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>;
/**

@@ -41,3 +38,9 @@ * The default interpreter options:

*/
static defaultOptions: InterpreterOptions;
static defaultOptions: {
execute: boolean;
deferEvents: boolean;
clock: Clock;
logger: any;
devTools: boolean;
};
/**

@@ -75,3 +78,5 @@ * The current state of the interpreted machine.

private forwardTo;
private _outgoingQueue;
private devTools?;
private _doneEvent?;
/**

@@ -83,5 +88,8 @@ * Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.

*/
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>, options?: InterpreterOptions);
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
/**
* @deprecated Use `.getSnapshot()` instead.
*/
get state(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
static interpret: typeof interpret;

@@ -94,7 +102,7 @@ /**

*/
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
execute(state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
private update;
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
subscribe(observer: Partial<Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>>): Subscription;
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
/**

@@ -104,3 +112,3 @@ * Adds an event listener that is notified whenever an event is sent to the running interpreter.

*/
onEvent(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onEvent(listener: EventListener): this;
/**

@@ -110,3 +118,3 @@ * Adds an event listener that is notified whenever a `send` event occurs.

*/
onSend(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onSend(listener: EventListener): this;
/**

@@ -116,3 +124,3 @@ * Adds a context listener that is notified whenever the state context changes.

*/
onChange(listener: ContextListener<TContext>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onChange(listener: ContextListener<TContext>): this;
/**

@@ -122,3 +130,3 @@ * Adds a listener that is notified when the machine is stopped.

*/
onStop(listener: Listener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onStop(listener: Listener): this;
/**

@@ -128,3 +136,3 @@ * Adds a state listener that is notified when the statechart has reached its final state.

*/
onDone(listener: EventListener<DoneEvent>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onDone(listener: EventListener<DoneEvent>): this;
/**

@@ -134,7 +142,7 @@ * Removes a listener.

*/
off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
off(listener: (...args: any[]) => void): this;
/**
* Alias for Interpreter.prototype.start
*/
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
init: (initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue) => this;
/**

@@ -144,3 +152,5 @@ * Starts the interpreter from the given state, or the initial state.

*/
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
private _stopChildren;
private _stop;
/**

@@ -151,3 +161,3 @@ * Stops the interpreter and unsubscribe all listeners.

*/
stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
stop(): this;
/**

@@ -162,3 +172,3 @@ * Sends an event to the running interpreter to trigger a transition.

*/
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData) => State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private batch;

@@ -172,2 +182,3 @@ /**

private sendTo;
private _nextState;
/**

@@ -180,6 +191,7 @@ * Returns the next state given the interpreter's current state and the event.

*/
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private forward;
private defer;
private cancel;
private _exec;
private exec;

@@ -189,3 +201,3 @@ private removeChild;

spawn(entity: Spawnable, name: string, options?: SpawnOptions): ActorRef<any>;
spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
spawnMachine<TChildContext, TChildStateSchema extends StateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
id?: string;

@@ -206,7 +218,7 @@ autoForward?: boolean;

};
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
[Symbol.observable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
}
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE, any, any, any, any>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE, any, any, any, any>>;
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;

@@ -222,4 +234,4 @@ /**

context: TContext;
}>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
}, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta> : MissingImplementationsError<TResolvedTypesMeta>, options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
export {};
//# sourceMappingURL=interpreter.d.ts.map

@@ -1,14 +0,13 @@

import { __values, __assign, __spreadArray, __read } from './_virtual/_tslib.js';
import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
import { SpecialTargets, ActionTypes } from './types.js';
import { isStateConfig, State, bindActionToState } from './State.js';
import { errorPlatform, update, error as error$1, log, stop, start, cancel, send, raise } from './actionTypes.js';
import { initEvent, doneInvoke, toActionObjects, resolveActions, error, getActionFunction } from './actions.js';
import { IS_PRODUCTION } from './environment.js';
import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
import { ActionTypes, SpecialTargets } from './types.js';
import { isInFinalState } from './stateUtils.js';
import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
import { isState, State, bindActionToState } from './State.js';
import { provide, consume } from './serviceScope.js';
import { isSpawnedActor, createDeferredActor } from './Actor.js';
import { warn, mapContext, toObserver, isFunction, toSCXMLEvent, flatten, isRaisableAction, isPromiseLike, isObservable, isMachine, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, toInvokeSource, uniqueId } from './utils.js';
import { Scheduler } from './scheduler.js';
import { createDeferredActor, isSpawnedActor } from './Actor.js';
import { registry } from './registry.js';
import { registerService, getGlobal } from './devTools.js';
import { getGlobal, registerService } from './devTools.js';
import { provide, consume } from './serviceScope.js';
import { spawnBehavior } from './behaviors.js';

@@ -40,4 +39,2 @@

function Interpreter(machine, options) {
var _this = this;
if (options === void 0) {

@@ -47,4 +44,5 @@ options = Interpreter.defaultOptions;

var _this = this;
this.machine = machine;
this.scheduler = new Scheduler();
this.delayedEventsMap = {};

@@ -65,2 +63,3 @@ this.listeners = new Set();

this.forwardTo = new Set();
this._outgoingQueue = [];
/**

@@ -108,3 +107,3 @@ * Alias for Interpreter.prototype.start

var nextState = _this.nextState(_event);
var nextState = _this._nextState(_event);

@@ -118,5 +117,5 @@ _this.update(nextState, _event);

this.sendTo = function (event, to) {
this.sendTo = function (event, to, immediate) {
var isParent = _this.parent && (to === SpecialTargets.Parent || _this.parent.id === to);
var target = isParent ? _this.parent : isString(to) ? _this.children.get(to) || registry.get(to) : isActor(to) ? to : undefined;
var target = isParent ? _this.parent : isString(to) ? to === SpecialTargets.Internal ? _this : _this.children.get(to) || registry.get(to) : isActor(to) ? to : undefined;

@@ -137,13 +136,193 @@ if (!target) {

if ('machine' in target) {
// Send SCXML events to machines
target.send(__assign(__assign({}, event), {
name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
origin: _this.sessionId
}));
// perhaps those events should be rejected in the parent
// but atm it doesn't have easy access to all of the information that is required to do it reliably
if (_this.status !== InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
_this.state.done) {
// Send SCXML events to machines
var scxmlEvent = __assign(__assign({}, event), {
name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
origin: _this.sessionId
});
if (!immediate && _this.machine.config.predictableActionArguments) {
_this._outgoingQueue.push([target, scxmlEvent]);
} else {
target.send(scxmlEvent);
}
}
} else {
// Send normal events to other targets
target.send(event.data);
if (!immediate && _this.machine.config.predictableActionArguments) {
_this._outgoingQueue.push([target, event.data]);
} else {
target.send(event.data);
}
}
};
this._exec = function (action, context, _event, actionFunctionMap) {
if (actionFunctionMap === void 0) {
actionFunctionMap = _this.machine.options.actions;
}
var actionOrExec = action.exec || getActionFunction(action.type, actionFunctionMap);
var exec = isFunction(actionOrExec) ? actionOrExec : actionOrExec ? actionOrExec.exec : action.exec;
if (exec) {
try {
return exec(context, _event.data, !_this.machine.config.predictableActionArguments ? {
action: action,
state: _this.state,
_event: _event
} : {
action: action,
_event: _event
});
} catch (err) {
if (_this.parent) {
_this.parent.send({
type: 'xstate.error',
data: err
});
}
throw err;
}
}
switch (action.type) {
case raise:
{
// if raise action reached the interpreter then it's a delayed one
var sendAction_1 = action;
_this.defer(sendAction_1);
break;
}
case send:
var sendAction = action;
if (typeof sendAction.delay === 'number') {
_this.defer(sendAction);
return;
} else {
if (sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to, _event === initEvent);
} else {
_this.send(sendAction._event);
}
}
break;
case cancel:
_this.cancel(action.sendId);
break;
case start:
{
if (_this.status !== InterpreterStatus.Running) {
return;
}
var activity = action.activity; // If the activity will be stopped right after it's started
// (such as in transient states)
// don't bother starting the activity.
if ( // in v4 with `predictableActionArguments` invokes are called eagerly when the `this.state` still points to the previous state
!_this.machine.config.predictableActionArguments && !_this.state.activities[activity.id || activity.type]) {
break;
} // Invoked services
if (activity.type === ActionTypes.Invoke) {
var invokeSource = toInvokeSource(activity.src);
var serviceCreator = _this.machine.options.services ? _this.machine.options.services[invokeSource.type] : undefined;
var id = activity.id,
data = activity.data;
if (!IS_PRODUCTION) {
warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(_this.machine.id, "'). ") + "Please use `autoForward` instead.");
}
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
if (!serviceCreator) {
// tslint:disable-next-line:no-console
if (!IS_PRODUCTION) {
warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(_this.machine.id, "'."));
}
return;
}
var resolvedData = data ? mapContext(data, context, _event) : undefined;
if (typeof serviceCreator === 'string') {
// TODO: warn
return;
}
var source = isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
data: resolvedData,
src: invokeSource,
meta: activity.meta
}) : serviceCreator;
if (!source) {
// TODO: warn?
return;
}
var options = void 0;
if (isMachine(source)) {
source = resolvedData ? source.withContext(resolvedData) : source;
options = {
autoForward: autoForward
};
}
_this.spawn(source, id, options);
} else {
_this.spawnActivity(activity);
}
break;
}
case stop:
{
_this.stopChild(action.activity.id);
break;
}
case log:
var _a = action,
label = _a.label,
value = _a.value;
if (label) {
_this.logger(label, value);
} else {
_this.logger(value);
}
break;
default:
if (!IS_PRODUCTION) {
warn(false, "No implementation found for action type '".concat(action.type, "'"));
}
break;
}
};
var resolvedOptions = __assign(__assign({}, Interpreter.defaultOptions), options);

@@ -184,2 +363,5 @@

Object.defineProperty(Interpreter.prototype, "state", {
/**
* @deprecated Use `.getSnapshot()` instead.
*/
get: function () {

@@ -233,4 +415,12 @@ if (!IS_PRODUCTION) {

if (this.options.execute) {
if ((!this.machine.config.predictableActionArguments || // this is currently required to execute initial actions as the `initialState` gets cached
// we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
_event === initEvent) && this.options.execute) {
this.execute(this.state);
} else {
var item = void 0;
while (item = this._outgoingQueue.shift()) {
item[0].send(item[1]);
}
} // Update children

@@ -301,5 +491,3 @@

var isDone = isInFinalState(state.configuration || [], this.machine);
if (this.state.configuration && isDone) {
if (this.state.done) {
// get final child state node

@@ -310,2 +498,3 @@ var finalChildStateNode = state.configuration.find(function (sn) {

var doneData = finalChildStateNode && finalChildStateNode.doneData ? mapContext(finalChildStateNode.doneData, state.context, _event) : undefined;
this._doneEvent = doneInvoke(this.id, doneData);

@@ -315,3 +504,3 @@ try {

var listener = _m.value;
listener(doneInvoke(this.id, doneData));
listener(this._doneEvent);
}

@@ -330,3 +519,7 @@ } catch (e_5_1) {

this.stop();
this._stop();
this._stopChildren();
registry.free(this.sessionId);
}

@@ -356,34 +549,31 @@ };

if (!nextListenerOrObserver) {
return {
unsubscribe: function () {
return void 0;
}
};
var observer = toObserver(nextListenerOrObserver, _, completeListener);
this.listeners.add(observer.next); // Send current state to listener
if (this.status !== InterpreterStatus.NotStarted) {
observer.next(this.state);
}
var listener;
var resolvedCompleteListener = completeListener;
var completeOnce = function () {
_this.doneListeners.delete(completeOnce);
if (typeof nextListenerOrObserver === 'function') {
listener = nextListenerOrObserver;
} else {
listener = nextListenerOrObserver.next.bind(nextListenerOrObserver);
resolvedCompleteListener = nextListenerOrObserver.complete.bind(nextListenerOrObserver);
}
_this.stopListeners.delete(completeOnce);
this.listeners.add(listener); // Send current state to listener
observer.complete();
};
if (this.status === InterpreterStatus.Running) {
listener(this.state);
if (this.status === InterpreterStatus.Stopped) {
observer.complete();
} else {
this.onDone(completeOnce);
this.onStop(completeOnce);
}
if (resolvedCompleteListener) {
this.onDone(resolvedCompleteListener);
}
return {
unsubscribe: function () {
listener && _this.listeners.delete(listener);
resolvedCompleteListener && _this.doneListeners.delete(resolvedCompleteListener);
_this.listeners.delete(observer.next);
_this.doneListeners.delete(completeOnce);
_this.stopListeners.delete(completeOnce);
}

@@ -439,3 +629,8 @@ };

Interpreter.prototype.onDone = function (listener) {
this.doneListeners.add(listener);
if (this.status === InterpreterStatus.Stopped && this._doneEvent) {
listener(this._doneEvent);
} else {
this.doneListeners.add(listener);
}
return this;

@@ -470,4 +665,10 @@ };

return this;
}
} // yes, it's a hack but we need the related cache to be populated for some things to work (like delayed transitions)
// this is usually called by `machine.getInitialState` but if we rehydrate from a state we might bypass this call
// we also don't want to call this method here as it resolves the full initial state which might involve calling assign actions
// and that could potentially lead to some unwanted side-effects (even such as creating some rogue actors)
this.machine._init();
registry.register(this.sessionId, this);

@@ -477,3 +678,3 @@ this.initialized = true;

var resolvedState = initialState === undefined ? this.initialState : provide(this, function () {
return isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
return isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.from(initialState, _this.machine.context));
});

@@ -490,14 +691,16 @@

};
/**
* Stops the interpreter and unsubscribe all listeners.
*
* This will also notify the `onStop` listeners.
*/
Interpreter.prototype._stopChildren = function () {
// TODO: think about converting those to actions
this.children.forEach(function (child) {
if (isFunction(child.stop)) {
child.stop();
}
});
this.children.clear();
};
Interpreter.prototype.stop = function () {
Interpreter.prototype._stop = function () {
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
var _this = this;
try {

@@ -578,33 +781,10 @@ for (var _f = __values(this.listeners), _g = _f.next(); !_g.done; _g = _f.next()) {

this.state.configuration.forEach(function (stateNode) {
var e_11, _a;
this.initialized = false;
this.status = InterpreterStatus.Stopped;
this._initialState = undefined;
try {
for (var _b = __values(stateNode.definition.exit), _c = _b.next(); !_c.done; _c = _b.next()) {
var action = _c.value;
_this.exec(action, _this.state);
}
} catch (e_11_1) {
e_11 = {
error: e_11_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_11) throw e_11.error;
}
}
}); // Stop all children
this.children.forEach(function (child) {
if (isFunction(child.stop)) {
child.stop();
}
});
try {
// Cancel all delayed events
for (var _p = __values(keys(this.delayedEventsMap)), _q = _p.next(); !_q.done; _q = _p.next()) {
// we are going to stop within the current sync frame
// so we can safely just cancel this here as nothing async should be fired anyway
for (var _p = __values(Object.keys(this.delayedEventsMap)), _q = _p.next(); !_q.done; _q = _p.next()) {
var key = _q.value;

@@ -623,8 +803,76 @@ this.clock.clearTimeout(this.delayedEventsMap[key]);

}
}
} // clear everything that might be enqueued
this.scheduler.clear();
this.initialized = false;
this.status = InterpreterStatus.Stopped;
registry.free(this.sessionId);
this.scheduler = new Scheduler({
deferEvents: this.options.deferEvents
});
};
/**
* Stops the interpreter and unsubscribe all listeners.
*
* This will also notify the `onStop` listeners.
*/
Interpreter.prototype.stop = function () {
// TODO: add warning for stopping non-root interpreters
var _this = this; // grab the current scheduler as it will be replaced in _stop
var scheduler = this.scheduler;
this._stop(); // let what is currently processed to be finished
scheduler.schedule(function () {
// it feels weird to handle this here but we need to handle this even slightly "out of band"
var _event = toSCXMLEvent({
type: 'xstate.stop'
});
var nextState = provide(_this, function () {
var exitActions = flatten(__spreadArray([], __read(_this.state.configuration), false).sort(function (a, b) {
return b.order - a.order;
}).map(function (stateNode) {
return toActionObjects(stateNode.onExit, _this.machine.options.actions);
}));
var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [{
type: 'exit',
actions: exitActions
}], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
resolvedActions = _a[0],
updatedContext = _a[1];
var newState = new State({
value: _this.state.value,
context: updatedContext,
_event: _event,
_sessionid: _this.sessionId,
historyValue: undefined,
history: _this.state,
actions: resolvedActions.filter(function (action) {
return !isRaisableAction(action);
}),
activities: {},
events: [],
configuration: [],
transitions: [],
children: {},
done: _this.state.done,
tags: _this.state.tags,
machine: _this.machine
});
newState.changed = true;
return newState;
});
_this.update(nextState, _event);
_this._stopChildren();
registry.free(_this.sessionId);
});
return this;

@@ -646,4 +894,9 @@ };

if (!events.length) {
return;
}
var exec = !!this.machine.config.predictableActionArguments && this._exec;
this.scheduler.schedule(function () {
var e_12, _a;
var e_11, _a;

@@ -660,5 +913,5 @@ var nextState = _this.state;

nextState = provide(_this, function () {
return _this.machine.transition(nextState, _event);
return _this.machine.transition(nextState, _event, undefined, exec || undefined);
});
batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
batchedActions.push.apply(batchedActions, __spreadArray([], __read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
return bindActionToState(a, nextState);

@@ -675,5 +928,5 @@ })), false));

}
} catch (e_12_1) {
e_12 = {
error: e_12_1
} catch (e_11_1) {
e_11 = {
error: e_11_1
};

@@ -684,3 +937,3 @@ } finally {

} finally {
if (e_12) throw e_12.error;
if (e_11) throw e_11.error;
}

@@ -705,14 +958,10 @@ }

};
/**
* Returns the next state given the interpreter's current state and the event.
*
* This is a pure method that does _not_ update the interpreter's state.
*
* @param event The event to determine the next state
*/
Interpreter.prototype.nextState = function (event) {
Interpreter.prototype._nextState = function (event, exec) {
var _this = this;
if (exec === void 0) {
exec = !!this.machine.config.predictableActionArguments && this._exec;
}
var _event = toSCXMLEvent(event);

@@ -727,9 +976,21 @@

var nextState = provide(this, function () {
return _this.machine.transition(_this.state, _event);
return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
});
return nextState;
};
/**
* Returns the next state given the interpreter's current state and the event.
*
* This is a pure method that does _not_ update the interpreter's state.
*
* @param event The event to determine the next state
*/
Interpreter.prototype.nextState = function (event) {
return this._nextState(event, false);
};
Interpreter.prototype.forward = function (event) {
var e_13, _a;
var e_12, _a;

@@ -747,5 +1008,5 @@ try {

}
} catch (e_13_1) {
e_13 = {
error: e_13_1
} catch (e_12_1) {
e_12 = {
error: e_12_1
};

@@ -756,3 +1017,3 @@ } finally {

} finally {
if (e_13) throw e_13.error;
if (e_12) throw e_12.error;
}

@@ -765,5 +1026,5 @@ }

this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
if (sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to);
var timerId = this.clock.setTimeout(function () {
if ('to' in sendAction && sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to, true);
} else {

@@ -773,2 +1034,6 @@ _this.send(sendAction._event);

}, sendAction.delay);
if (sendAction.id) {
this.delayedEventsMap[sendAction.id] = timerId;
}
};

@@ -786,146 +1051,3 @@

var context = state.context,
_event = state._event;
var actionOrExec = action.exec || getActionFunction(action.type, actionFunctionMap);
var exec = isFunction(actionOrExec) ? actionOrExec : actionOrExec ? actionOrExec.exec : action.exec;
if (exec) {
try {
return exec(context, _event.data, {
action: action,
state: this.state,
_event: _event
});
} catch (err) {
if (this.parent) {
this.parent.send({
type: 'xstate.error',
data: err
});
}
throw err;
}
}
switch (action.type) {
case send:
var sendAction = action;
if (typeof sendAction.delay === 'number') {
this.defer(sendAction);
return;
} else {
if (sendAction.to) {
this.sendTo(sendAction._event, sendAction.to);
} else {
this.send(sendAction._event);
}
}
break;
case cancel:
this.cancel(action.sendId);
break;
case start:
{
if (this.status !== InterpreterStatus.Running) {
return;
}
var activity = action.activity; // If the activity will be stopped right after it's started
// (such as in transient states)
// don't bother starting the activity.
if (!this.state.activities[activity.id || activity.type]) {
break;
} // Invoked services
if (activity.type === ActionTypes.Invoke) {
var invokeSource = toInvokeSource(activity.src);
var serviceCreator = this.machine.options.services ? this.machine.options.services[invokeSource.type] : undefined;
var id = activity.id,
data = activity.data;
if (!IS_PRODUCTION) {
warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
}
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
if (!serviceCreator) {
// tslint:disable-next-line:no-console
if (!IS_PRODUCTION) {
warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
}
return;
}
var resolvedData = data ? mapContext(data, context, _event) : undefined;
if (typeof serviceCreator === 'string') {
// TODO: warn
return;
}
var source = isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
data: resolvedData,
src: invokeSource,
meta: activity.meta
}) : serviceCreator;
if (!source) {
// TODO: warn?
return;
}
var options = void 0;
if (isMachine(source)) {
source = resolvedData ? source.withContext(resolvedData) : source;
options = {
autoForward: autoForward
};
}
this.spawn(source, id, options);
} else {
this.spawnActivity(activity);
}
break;
}
case stop:
{
this.stopChild(action.activity.id);
break;
}
case log:
var label = action.label,
value = action.value;
if (label) {
this.logger(label, value);
} else {
this.logger(value);
}
break;
default:
if (!IS_PRODUCTION) {
warn(false, "No implementation found for action type '".concat(action.type, "'"));
}
break;
}
return undefined;
this._exec(action, state.context, state._event, actionFunctionMap);
};

@@ -958,2 +1080,6 @@

Interpreter.prototype.spawn = function (entity, name, options) {
if (this.status !== InterpreterStatus.Running) {
return createDeferredActor(entity, name);
}
if (isPromiseLike(entity)) {

@@ -1028,2 +1154,4 @@ return this.spawnPromise(Promise.resolve(entity), name);

Interpreter.prototype.spawnPromise = function (promise, id) {
var _a;
var _this = this;

@@ -1071,3 +1199,3 @@

});
var actor = {
var actor = (_a = {
id: id,

@@ -1116,3 +1244,5 @@ send: function () {

}
};
}, _a[symbolObservable] = function () {
return this;
}, _a);
this.children.set(id, actor);

@@ -1123,2 +1253,4 @@ return actor;

Interpreter.prototype.spawnCallback = function (callback, id) {
var _a;
var _this = this;

@@ -1162,3 +1294,3 @@

var actor = {
var actor = (_a = {
id: id,

@@ -1171,6 +1303,7 @@ send: function (event) {

subscribe: function (next) {
listeners.add(next);
var observer = toObserver(next);
listeners.add(observer.next);
return {
unsubscribe: function () {
listeners.delete(next);
listeners.delete(observer.next);
}

@@ -1194,3 +1327,5 @@ };

}
};
}, _a[symbolObservable] = function () {
return this;
}, _a);
this.children.set(id, actor);

@@ -1201,2 +1336,4 @@ return actor;

Interpreter.prototype.spawnObservable = function (source, id) {
var _a;
var _this = this;

@@ -1224,3 +1361,3 @@

});
var actor = {
var actor = (_a = {
id: id,

@@ -1244,3 +1381,5 @@ send: function () {

}
};
}, _a[symbolObservable] = function () {
return this;
}, _a);
this.children.set(id, actor);

@@ -1273,3 +1412,5 @@ return actor;

Interpreter.prototype.spawnEffect = function (id, dispose) {
this.children.set(id, {
var _a;
this.children.set(id, (_a = {
id: id,

@@ -1295,3 +1436,5 @@ send: function () {

}
});
}, _a[symbolObservable] = function () {
return this;
}, _a));
};

@@ -1337,6 +1480,4 @@

return this;
}; // this gets stripped by Babel to avoid having "undefined" property in environments without this non-standard Symbol
// it has to be here to be included in the generated .d.ts
};
Interpreter.prototype.getSnapshot = function () {

@@ -1357,19 +1498,16 @@ if (this.status === InterpreterStatus.NotStarted) {

Interpreter.defaultOptions = /*#__PURE__*/function (global) {
return {
execute: true,
deferEvents: true,
clock: {
setTimeout: function (fn, ms) {
return setTimeout(fn, ms);
},
clearTimeout: function (id) {
return clearTimeout(id);
}
Interpreter.defaultOptions = {
execute: true,
deferEvents: true,
clock: {
setTimeout: function (fn, ms) {
return setTimeout(fn, ms);
},
logger: global.console.log.bind(console),
devTools: false
};
}(typeof self !== 'undefined' ? self : global);
clearTimeout: function (id) {
return clearTimeout(id);
}
},
logger: /*#__PURE__*/console.log.bind(console),
devTools: false
};
Interpreter.interpret = interpret;

@@ -1376,0 +1514,0 @@ return Interpreter;

import { __assign, __rest } from './_virtual/_tslib.js';
import './environment.js';
import './utils.js';
import './types.js';
import { invoke } from './actionTypes.js';
import './utils.js';
import './environment.js';

@@ -28,5 +28,5 @@ function toInvokeSource(src) {

toJSON: function () {
var onDone = invokeConfig.onDone,
onError = invokeConfig.onError,
invokeDef = __rest(invokeConfig, ["onDone", "onError"]);
invokeConfig.onDone;
invokeConfig.onError;
var invokeDef = __rest(invokeConfig, ["onDone", "onError"]);

@@ -33,0 +33,0 @@ return __assign(__assign({}, invokeDef), {

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

import { Model } from './model.types';
import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, InternalMachineOptions, StateMachine, StateSchema, Typestate, ServiceMap } from './types';
import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
/**
* @deprecated Use `createMachine(...)` instead.
*/
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, any, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>;
//# sourceMappingURL=Machine.d.ts.map
import { StateNode } from './StateNode.js';
import { IS_PRODUCTION } from './environment.js';
var warned = false;
function Machine(config, options, initialContext) {

@@ -11,2 +13,7 @@ if (initialContext === void 0) {

function createMachine(config, options) {
if (!IS_PRODUCTION && !('predictableActionArguments' in config) && !warned) {
warned = true;
console.warn('It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html');
}
return new StateNode(config, options);

@@ -13,0 +20,0 @@ }

import { __values } from './_virtual/_tslib.js';
import { keys, matchesState } from './utils.js';
import { matchesState } from './utils.js';

@@ -10,3 +10,3 @@ function mapState(stateMap, stateId) {

try {
for (var _b = __values(keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = __values(Object.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
var mappedStateId = _c.value;

@@ -13,0 +13,0 @@

@@ -1,5 +0,8 @@

import type { EventObject, BaseActionObject } from './types';
import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
/**
* @deprecated Use [Typegen](https://stately.ai/blog/introducing-typescript-typegen-for-xstate) instead.
*/
export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
//# sourceMappingURL=model.d.ts.map

@@ -1,16 +0,18 @@

import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine, BaseActionObject } from './types';
export declare type AnyFunction = (...args: any[]) => any;
export declare type IsNever<T> = [T] extends [never] ? true : false;
export declare type Cast<T extends any, TCastType extends any> = T extends TCastType ? T : TCastType;
export declare type Compute<A extends any> = {
[K in keyof A]: A[K];
} & unknown;
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
declare type SimplisticExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
type: TEventType;
} ? TEvent : never;
export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
initialContext: TContext;
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, SimplisticExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, SimplisticExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, SimplisticExtractEvent<TEvent, TEventType>, TEvent>;
events: Prop<TModelCreators, 'events'>;
actions: Prop<TModelCreators, 'actions'>;
reset: () => AssignAction<TContext, any>;
createMachine: (config: MachineConfig<TContext, any, TEvent, TAction>, implementations?: Partial<MachineOptions<TContext, TEvent, TAction>>) => StateMachine<TContext, any, TEvent>;
createMachine: {
<TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
value: any;
context: TContext;
}, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
};
}

@@ -53,2 +55,3 @@ export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;

}[keyof TCreators];
export {};
//# sourceMappingURL=model.types.d.ts.map
export declare function createSchema<T>(schema?: any): T;
export declare const t: typeof createSchema;
//# sourceMappingURL=schema.d.ts.map
function createSchema(schema) {
return schema;
}
var t = createSchema;
export { createSchema };
export { createSchema, t };

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

import { StateNode } from './index';
import { AnyStateMachine } from './index';
export interface ScxmlToMachineOptions {
delimiter?: string;
}
export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
export declare function toMachine(xml: string, options: ScxmlToMachineOptions): AnyStateMachine;
//# sourceMappingURL=scxml.d.ts.map

@@ -1,17 +0,20 @@

import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
import { StateNode } from './StateNode';
import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
import { BaseActionObject, Prop } from './types';
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
/**
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
*/
export declare const isState: typeof isStateConfig;
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> {
}, TResolvedTypesMeta = TypegenDisabled> {
value: StateValue;
context: TContext;
historyValue?: HistoryValue | undefined;
history?: State<TContext, TEvent, TStateSchema, TTypestate>;
history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
actions: Array<ActionObject<TContext, TEvent>>;

@@ -40,7 +43,7 @@ activities: ActivityMap;

*/
configuration: Array<StateNode<TContext, any, TEvent, any>>;
configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
/**
* The next events that will cause a transition from the current state.
*/
nextEvents: EventType[];
nextEvents: Array<TEvent['type']>;
/**

@@ -55,3 +58,3 @@ * The transition definitions that resulted in this state.

tags: Set<string>;
machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, any, TResolvedTypesMeta> | undefined;
/**

@@ -62,3 +65,3 @@ * Creates a new State instance for the given `stateValue` and `context`.

*/
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
/**

@@ -68,3 +71,3 @@ * Creates a new State instance for the given `config`.

*/
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any, any, any>;
/**

@@ -75,3 +78,3 @@ * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).

*/
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context: TC): State<TC, TE>;
/**

@@ -96,3 +99,3 @@ * Creates a new State instance.

toStrings(stateValue?: StateValue, delimiter?: string): string[];
toJSON(): Omit<this, "machine" | "tags" | "transitions" | "configuration"> & {
toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine" | "toStrings" | "toJSON" | "matches" | "hasTag" | "can"> & {
tags: string[];

@@ -104,6 +107,7 @@ };

*/
matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : never>(parentStateValue: TSV): boolean;
matches<TSV extends TResolvedTypesMeta extends TypegenDisabled ? TTypestate['value'] : never>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
value: TSV;
context: any;
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
value: TSV;

@@ -115,3 +119,3 @@ };

*/
hasTag(tag: string): boolean;
hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'tags'> : string): boolean;
/**

@@ -118,0 +122,0 @@ * Determines whether sending the `event` will cause a non-forbidden transition

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

import { __spreadArray, __read, __rest, __assign } from './_virtual/_tslib.js';
import { __assign, __spreadArray, __read, __rest } from './_virtual/_tslib.js';
import { EMPTY_ACTIVITY_MAP } from './constants.js';
import { IS_PRODUCTION } from './environment.js';
import { isString, matchesState, warn, keys } from './utils.js';
import { isString, matchesState, warn } from './utils.js';
import { getMeta, nextEvents } from './stateUtils.js';
import { initEvent } from './actions.js';
import { IS_PRODUCTION } from './environment.js';

@@ -21,4 +21,4 @@ function stateValuesEqual(a, b) {

var aKeys = keys(a);
var bKeys = keys(b);
var aKeys = Object.keys(a);
var bKeys = Object.keys(b);
return aKeys.length === bKeys.length && aKeys.every(function (key) {

@@ -28,9 +28,14 @@ return stateValuesEqual(a[key], b[key]);

}
function isState(state) {
if (isString(state)) {
function isStateConfig(state) {
if (typeof state !== 'object' || state === null) {
return false;
}
return 'value' in state && 'history' in state;
return 'value' in state && '_event' in state;
}
/**
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
*/
var isState = isStateConfig;
function bindActionToState(action, state) {

@@ -211,3 +216,3 @@ var exec = action.exec;

var valueKeys = keys(stateValue);
var valueKeys = Object.keys(stateValue);
return valueKeys.concat.apply(valueKeys, __spreadArray([], __read(valueKeys.map(function (key) {

@@ -221,8 +226,8 @@ return _this.toStrings(stateValue[key], delimiter).map(function (s) {

State.prototype.toJSON = function () {
var _a = this,
configuration = _a.configuration,
transitions = _a.transitions,
tags = _a.tags,
machine = _a.machine,
jsonValues = __rest(_a, ["configuration", "transitions", "tags", "machine"]);
var _a = this;
_a.configuration;
_a.transitions;
var tags = _a.tags;
_a.machine;
var jsonValues = __rest(_a, ["configuration", "transitions", "tags", "machine"]);

@@ -233,8 +238,3 @@ return __assign(__assign({}, jsonValues), {

};
/**
* Whether the current state value is a subset of the given parent state value.
* @param parentStateValue
*/
State.prototype.matches = function (parentStateValue) {

@@ -279,2 +279,2 @@ return matchesState(parentStateValue, this.value);

export { State, bindActionToState, isState, stateValuesEqual };
export { State, bindActionToState, isState, isStateConfig, stateValuesEqual };

@@ -1,7 +0,8 @@

import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig, PredictableActionArgumentsExec } from './types';
import { State } from './State';
import { TypegenDisabled } from './typegenTypes';
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> {
}, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = TypegenDisabled> {
/**

@@ -84,3 +85,3 @@ * The raw config used to create the machine.

*/
parent?: StateNode<TContext, any, TEvent, any>;
parent?: StateNode<TContext, any, TEvent, any, any, any>;
/**

@@ -123,7 +124,11 @@ * The root machine node.

*/
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>,
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>,
/**
* The initial extended state
*/
_context?: Readonly<TContext> | (() => Readonly<TContext>));
_context?: Readonly<TContext> | (() => Readonly<TContext>), // TODO: this is unsafe, but we're removing it in v5 anyway
_stateInfo?: {
parent: StateNode<any, any, any, any, any, any>;
key: string;
});
private _init;

@@ -136,3 +141,3 @@ /**

*/
withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
/**

@@ -169,3 +174,3 @@ * Clones this state machine with custom context.

*/
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>): Array<StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>>;
/**

@@ -184,3 +189,3 @@ * Returns `true` if this state node explicitly handles the given event.

*/
resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private transitionLeafNode;

@@ -190,10 +195,5 @@ private transitionCompoundNode;

private _transition;
getTransitionData(state: State<TContext, TEvent, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
getTransitionData(state: State<TContext, TEvent, any, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
private next;
private nodesFromChild;
/**
* Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
* this state node, it does not escape.
*/
private escapes;
private getPotentiallyReenteringNodes;
private getActions;

@@ -207,3 +207,3 @@ /**

*/
transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
transition(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext, exec?: PredictableActionArgumentsExec): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private resolveRaisedTransition;

@@ -214,3 +214,3 @@ private resolveTransition;

*/
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
/**

@@ -221,3 +221,3 @@ * Returns the state node with the given `stateId`, or throws.

*/
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TServiceMap, TResolvedTypesMeta>;
/**

@@ -228,3 +228,3 @@ * Returns the relative state node from the given `statePath`, or throws.

*/
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any, any>;
/**

@@ -238,3 +238,3 @@ * Resolves a partial state value with its full representation in this machine.

private get initialStateValue();
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
/**

@@ -244,3 +244,3 @@ * The initial State instance, which includes all actions to be executed from

*/
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
/**

@@ -259,3 +259,3 @@ * The target state value of the history state node, if it exists. This represents the

getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any, any, any>>;
/**

@@ -267,3 +267,3 @@ * Retrieves state nodes from a relative path to this state node.

*/
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any, any>>;
private historyValue;

@@ -270,0 +270,0 @@ /**

import { __assign, __spreadArray, __read, __values, __rest } from './_virtual/_tslib.js';
import { isFunction, mapValues, isArray, flatten, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, isRaisableAction, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine, createInvokeId } from './utils.js';
import { State, stateValuesEqual } from './State.js';
import { start as start$1, stop as stop$1, invoke, update, nullEvent } from './actionTypes.js';
import { done, start, toActionObjects, raise, stop, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send, cancel, initEvent } from './actions.js';
import { IS_PRODUCTION } from './environment.js';
import { STATE_DELIMITER } from './constants.js';
import { IS_PRODUCTION } from './environment.js';
import { isFunction, mapValues, isArray, flatten, keys, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine } from './utils.js';
import { SpecialTargets } from './types.js';
import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
import { done, start, raise, stop, toActionObjects, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send, cancel, initEvent } from './actions.js';
import { State, stateValuesEqual } from './State.js';
import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode, getAllChildren } from './stateUtils.js';
import { createInvocableActor } from './Actor.js';

@@ -53,6 +52,4 @@ import { toInvokeDefinition } from './invokeUtils.js';

*/
_context // TODO: this is unsafe, but we're removing it in v5 anyway
) {
var _this = this;
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
_stateInfo) {
if (_context === void 0) {

@@ -62,2 +59,4 @@ _context = 'context' in config ? config.context : undefined;

var _this = this;
var _a;

@@ -86,4 +85,4 @@

this.options = Object.assign(createDefaultOptions(), options);
this.parent = this.options._parent;
this.key = this.config.key || this.options._key || this.config.id || '(machine)';
this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
this.machine = this.parent ? this.parent.machine : this;

@@ -94,3 +93,3 @@ this.path = this.parent ? this.parent.path.concat(this.key) : [];

this.version = this.parent ? this.parent.version : this.config.version;
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};

@@ -107,5 +106,5 @@ this.description = this.config.description;

var stateNode = new StateNode(stateConfig, {
_parent: _this,
_key: key
var stateNode = new StateNode(stateConfig, {}, undefined, {
parent: _this,
key: key
});

@@ -124,3 +123,3 @@ Object.assign(_this.idMap, __assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));

try {
for (var _b = __values(getChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = __values(getAllChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
var child = _c.value;

@@ -164,20 +163,21 @@ dfs(child);

if (isMachine(invokeConfig)) {
_this.machine.options.services = __assign((_a = {}, _a[invokeConfig.id] = invokeConfig, _a), _this.machine.options.services);
var invokeId = createInvokeId(_this.id, i);
_this.machine.options.services = __assign((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
return toInvokeDefinition({
src: invokeConfig.id,
id: invokeConfig.id
src: invokeId,
id: invokeId
});
} else if (isString(invokeConfig.src)) {
var invokeId = invokeConfig.id || createInvokeId(_this.id, i);
return toInvokeDefinition(__assign(__assign({}, invokeConfig), {
id: invokeConfig.id || invokeConfig.src,
id: invokeId,
src: invokeConfig.src
}));
} else if (isMachine(invokeConfig.src) || isFunction(invokeConfig.src)) {
var invokeSrc = "".concat(_this.id, ":invocation[").concat(i, "]"); // TODO: util function
_this.machine.options.services = __assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
var invokeId = invokeConfig.id || createInvokeId(_this.id, i);
_this.machine.options.services = __assign((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
return toInvokeDefinition(__assign(__assign({
id: invokeSrc
id: invokeId
}, invokeConfig), {
src: invokeSrc
src: invokeId
}));

@@ -187,3 +187,3 @@ } else {

return toInvokeDefinition(__assign(__assign({
id: invokeSource.type
id: createInvokeId(_this.id, i)
}, invokeConfig), {

@@ -375,3 +375,3 @@ src: invokeSource

});
}) : flatten(keys(afterConfig).map(function (delay, i) {
}) : flatten(Object.keys(afterConfig).map(function (delay, i) {
var configTransition = afterConfig[delay];

@@ -420,3 +420,3 @@ var resolvedTransition = isString(configTransition) ? {

var subStateKeys = keys(stateValue);
var subStateKeys = Object.keys(stateValue);
var subStateNodes = [this];

@@ -449,8 +449,10 @@ subStateNodes.push.apply(subStateNodes, __spreadArray([], __read(flatten(subStateKeys.map(function (subStateKey) {

StateNode.prototype.resolveState = function (state) {
var configuration = Array.from(getConfiguration([], this.getStateNodes(state.value)));
return new State(__assign(__assign({}, state), {
value: this.resolve(state.value),
var stateFromConfig = state instanceof State ? state : State.create(state);
var configuration = Array.from(getConfiguration([], this.getStateNodes(stateFromConfig.value)));
return new State(__assign(__assign({}, stateFromConfig), {
value: this.resolve(stateFromConfig.value),
configuration: configuration,
done: isInFinalState(configuration, this),
tags: getTagsFromConfiguration(configuration)
tags: getTagsFromConfiguration(configuration),
machine: this.machine
}));

@@ -471,3 +473,3 @@ };

StateNode.prototype.transitionCompoundNode = function (stateValue, state, _event) {
var subStateKeys = keys(stateValue);
var subStateKeys = Object.keys(stateValue);
var stateNode = this.getStateNode(subStateKeys[0]);

@@ -490,3 +492,3 @@

try {
for (var _b = __values(keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = __values(Object.keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
var subStateKey = _c.value;

@@ -519,3 +521,3 @@ var subStateValue = stateValue[subStateKey];

var stateTransitions = keys(transitionMap).map(function (key) {
var stateTransitions = Object.keys(transitionMap).map(function (key) {
return transitionMap[key];

@@ -534,6 +536,3 @@ });

var entryNodes = flatten(stateTransitions.map(function (t) {
return t.entrySet;
}));
var configuration = flatten(keys(transitionMap).map(function (key) {
var configuration = flatten(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].configuration;

@@ -543,3 +542,2 @@ }));

transitions: enabledTransitions,
entrySet: entryNodes,
exitSet: flatten(stateTransitions.map(function (t) {

@@ -550,3 +548,3 @@ return t.exitSet;

source: state,
actions: flatten(keys(transitionMap).map(function (key) {
actions: flatten(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].actions;

@@ -564,3 +562,3 @@ }))

if (keys(stateValue).length === 1) {
if (Object.keys(stateValue).length === 1) {
return this.transitionCompoundNode(stateValue, state, _event);

@@ -633,3 +631,2 @@ } // orthogonal node

transitions: [selectedTransition],
entrySet: [],
exitSet: [],

@@ -646,9 +643,7 @@ configuration: state.value ? [this] : [],

var isInternal = !!selectedTransition.internal;
var reentryNodes = isInternal ? [] : flatten(allNextStateNodes.map(function (n) {
return _this.nodesFromChild(n);
}));
return {
transitions: [selectedTransition],
entrySet: reentryNodes,
exitSet: isInternal ? [] : [this],
exitSet: isInternal ? [] : flatten(nextStateNodes.map(function (targetNode) {
return _this.getPotentiallyReenteringNodes(targetNode);
})),
configuration: allNextStateNodes,

@@ -658,13 +653,17 @@ source: state,

};
};
}; // even though the name of this function mentions reentry nodes
// we are pushing its result into `exitSet`
// that's because what we exit might be reentered (it's an invariant of reentrancy)
StateNode.prototype.nodesFromChild = function (childStateNode) {
if (childStateNode.escapes(this)) {
return [];
StateNode.prototype.getPotentiallyReenteringNodes = function (targetNode) {
if (this.order < targetNode.order) {
return [this];
}
var nodes = [];
var marker = childStateNode;
var marker = this;
var possibleAncestor = targetNode;
while (marker && marker !== this) {
while (marker && marker !== possibleAncestor) {
nodes.push(marker);

@@ -674,42 +673,28 @@ marker = marker.parent;

nodes.push(this); // inclusive
if (marker !== possibleAncestor) {
// we never got to `possibleAncestor`, therefore the initial `marker` "escapes" it
// it's in a different part of the tree so no states will be reentered for such an external transition
return [];
}
nodes.push(possibleAncestor);
return nodes;
};
/**
* Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
* this state node, it does not escape.
*/
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
var e_4, _a, e_5, _b;
StateNode.prototype.escapes = function (stateNode) {
if (this === stateNode) {
return false;
}
var _this = this;
var parent = this.parent;
var prevConfig = prevState ? getConfiguration([], this.getStateNodes(prevState.value)) : [];
var entrySet = new Set();
while (parent) {
if (parent === stateNode) {
return false;
}
parent = parent.parent;
}
return true;
};
StateNode.prototype.getActions = function (transition, currentContext, _event, prevState) {
var e_4, _a, e_5, _b;
var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
var resolvedConfig = transition.configuration.length ? getConfiguration(prevConfig, transition.configuration) : prevConfig;
try {
for (var resolvedConfig_1 = __values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
var sn = resolvedConfig_1_1.value;
for (var _c = __values(Array.from(resolvedConfig).sort(function (a, b) {
return a.order - b.order;
})), _d = _c.next(); !_d.done; _d = _c.next()) {
var sn = _d.value;
if (!has(prevConfig, sn)) {
transition.entrySet.push(sn);
if (!has(prevConfig, sn) || has(transition.exitSet, sn) || sn.parent && entrySet.has(sn.parent)) {
entrySet.add(sn);
}

@@ -723,3 +708,3 @@ }

try {
if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
} finally {

@@ -750,3 +735,10 @@ if (e_4) throw e_4.error;

var doneEvents = flatten(transition.entrySet.map(function (sn) {
transition.exitSet.sort(function (a, b) {
return b.order - a.order;
});
var entryStates = Array.from(entrySet).sort(function (a, b) {
return a.order - b.order;
});
var exitStates = new Set(transition.exitSet);
var doneEvents = flatten(entryStates.map(function (sn) {
var events = [];

@@ -778,24 +770,44 @@

}));
transition.exitSet.sort(function (a, b) {
return b.order - a.order;
var entryActions = entryStates.map(function (stateNode) {
var entryActions = stateNode.onEntry;
var invokeActions = stateNode.activities.map(function (activity) {
return start(activity);
});
return {
type: 'entry',
actions: toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions)
};
}).concat({
type: 'state_done',
actions: doneEvents.map(function (event) {
return raise(event);
})
});
transition.entrySet.sort(function (a, b) {
return a.order - b.order;
var exitActions = Array.from(exitStates).map(function (stateNode) {
return {
type: 'exit',
actions: toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
return stop(activity);
})), false), _this.machine.options.actions)
};
});
var entryStates = new Set(transition.entrySet);
var exitStates = new Set(transition.exitSet);
var actions = exitActions.concat({
type: 'transition',
actions: toActionObjects(transition.actions, this.machine.options.actions)
}).concat(entryActions);
var _c = __read([flatten(Array.from(entryStates).map(function (stateNode) {
return __spreadArray(__spreadArray([], __read(stateNode.activities.map(function (activity) {
return start(activity);
})), false), __read(stateNode.onEntry), false);
})).concat(doneEvents.map(raise)), flatten(Array.from(exitStates).map(function (stateNode) {
return __spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
return stop(activity);
})), false);
}))], 2),
entryActions = _c[0],
exitActions = _c[1];
if (isDone) {
var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
return b.order - a.order;
}).map(function (stateNode) {
return stateNode.onExit;
})), this.machine.options.actions).filter(function (action) {
return !isRaisableAction(action);
});
return actions.concat({
type: 'stop',
actions: stopActions
});
}
var actions = toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
return actions;

@@ -812,3 +824,3 @@ };

StateNode.prototype.transition = function (state, event, context) {
StateNode.prototype.transition = function (state, event, context, exec) {
if (state === void 0) {

@@ -843,3 +855,2 @@ state = this.initialState;

configuration: [],
entrySet: [],
exitSet: [],

@@ -852,10 +863,10 @@ source: currentState,

stateTransition.configuration = __spreadArray([], __read(resolvedConfig), false);
return this.resolveTransition(stateTransition, currentState, _event);
return this.resolveTransition(stateTransition, currentState, currentState.context, exec, _event);
};
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent, predictableExec) {
var _a;
var currentActions = state.actions;
state = this.transition(state, _event); // Save original event to state
state = this.transition(state, _event, undefined, predictableExec); // Save original event to state
// TODO: this should be the raised event! Delete in V5 (breaking)

@@ -871,4 +882,4 @@

StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
var e_6, _a;
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
var e_6, _a, e_7, _b;

@@ -881,6 +892,2 @@ var _this = this;

if (context === void 0) {
context = this.machine.context;
}
var configuration = stateTransition.configuration; // Transition will "apply" if:

@@ -891,16 +898,33 @@ // - this is the initial state (there is no current state)

var willTransition = !currentState || stateTransition.transitions.length > 0;
var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
var isDone = isInFinalState(resolvedConfiguration, this);
var resolvedStateValue = willTransition ? getValue(this.machine, configuration) : undefined;
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
var currentContext = currentState ? currentState.context : context;
var actions = this.getActions(stateTransition, currentContext, _event, currentState);
var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
var activities = currentState ? __assign({}, currentState.activities) : {};
try {
for (var actions_1 = __values(actions), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
var action = actions_1_1.value;
for (var actionBlocks_1 = __values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
var block = actionBlocks_1_1.value;
if (action.type === start$1) {
activities[action.activity.id || action.activity.type] = action;
} else if (action.type === stop$1) {
activities[action.activity.id || action.activity.type] = false;
try {
for (var _c = (e_7 = void 0, __values(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
var action = _d.value;
if (action.type === start$1) {
activities[action.activity.id || action.activity.type] = action;
} else if (action.type === stop$1) {
activities[action.activity.id || action.activity.type] = false;
}
}
} catch (e_7_1) {
e_7 = {
error: e_7_1
};
} finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
} finally {
if (e_7) throw e_7.error;
}
}

@@ -914,3 +938,3 @@ }

try {
if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
} finally {

@@ -921,11 +945,9 @@ if (e_6) throw e_6.error;

var _b = __read(resolveActions(this, currentState, currentContext, _event, actions, this.machine.config.preserveActionOrder), 2),
resolvedActions = _b[0],
updatedContext = _b[1];
var _e = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
resolvedActions = _e[0],
updatedContext = _e[1];
var _c = __read(partition(resolvedActions, function (action) {
return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
}), 2),
raisedEvents = _c[0],
nonRaisedActions = _c[1];
var _f = __read(partition(resolvedActions, isRaisableAction), 2),
raisedEvents = _f[0],
nonRaisedActions = _f[1];

@@ -941,4 +963,2 @@ var invokeActions = resolvedActions.filter(function (action) {

}, currentState ? __assign({}, currentState.children) : {});
var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
var isDone = isInFinalState(resolvedConfiguration, this);
var nextState = new State({

@@ -959,6 +979,6 @@ value: resolvedStateValue || currentState.value,

done: isDone,
tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
tags: getTagsFromConfiguration(resolvedConfiguration),
machine: this
});
var didUpdateContext = currentContext !== updatedContext;
var didUpdateContext = context !== updatedContext;
nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks

@@ -974,3 +994,3 @@

var isTransient = !isDone && (this._transient || configuration.some(function (stateNode) {
var hasAlwaysTransitions = !isDone && (this._transient || configuration.some(function (stateNode) {
return stateNode._transient;

@@ -982,8 +1002,7 @@ })); // If there are no enabled transitions, check if there are transient transitions.

//
// If we're already working on an transient transition (by checking
// if the event is a NULL_EVENT), then stop to prevent an infinite loop.
// If we're already working on an transient transition then stop to prevent an infinite loop.
//
// Otherwise, if there are no enabled nor transient transitions, we are done.
if (!willTransition && (!isTransient || _event.name === NULL_EVENT)) {
if (!willTransition && (!hasAlwaysTransitions || _event.name === NULL_EVENT)) {
return nextState;

@@ -995,6 +1014,6 @@ }

if (!isDone) {
if (isTransient) {
if (hasAlwaysTransitions) {
maybeNextState = this.resolveRaisedTransition(maybeNextState, {
type: nullEvent
}, _event);
}, _event, predictableExec);
}

@@ -1004,3 +1023,3 @@

var raisedEvent = raisedEvents.shift();
maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event);
maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event, predictableExec);
}

@@ -1014,3 +1033,2 @@ } // Detect if state changed

maybeNextState.history = history;
maybeNextState.tags = getTagsFromConfiguration(maybeNextState.configuration);
return maybeNextState;

@@ -1126,3 +1144,3 @@ };

if (!keys(stateValue).length) {
if (!Object.keys(stateValue).length) {
return this.initialStateValue || {};

@@ -1189,6 +1207,8 @@ }

StateNode.prototype.getInitialState = function (stateValue, context) {
this._init(); // TODO: this should be in the constructor (see note in constructor)
var configuration = this.getStateNodes(stateValue);
return this.resolveTransition({
configuration: configuration,
entrySet: configuration,
exitSet: [],

@@ -1198,3 +1218,3 @@ transitions: [],

actions: []
}, undefined, undefined, context);
}, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
};

@@ -1208,5 +1228,2 @@

get: function () {
this._init(); // TODO: this should be in the constructor (see note in constructor)
var initialStateValue = this.initialStateValue;

@@ -1321,3 +1338,3 @@

StateNode.prototype.historyValue = function (relativeStateValue) {
if (!keys(this.states).length) {
if (!Object.keys(this.states).length) {
return undefined;

@@ -1382,3 +1399,3 @@ }

var childStateIds = flatten(keys(this.states).map(function (stateKey) {
var childStateIds = flatten(Object.keys(this.states).map(function (stateKey) {
return _this.states[stateKey].stateIds;

@@ -1396,3 +1413,3 @@ }));

get: function () {
var e_7, _a, e_8, _b;
var e_8, _a, e_9, _b;

@@ -1408,3 +1425,3 @@ if (this.__cache.events) {

try {
for (var _c = __values(keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
for (var _c = __values(Object.keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
var stateId = _d.value;

@@ -1415,9 +1432,9 @@ var state = states[stateId];

try {
for (var _e = (e_8 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
for (var _e = (e_9 = void 0, __values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
var event_1 = _f.value;
events.add("".concat(event_1));
}
} catch (e_8_1) {
e_8 = {
error: e_8_1
} catch (e_9_1) {
e_9 = {
error: e_9_1
};

@@ -1428,3 +1445,3 @@ } finally {

} finally {
if (e_8) throw e_8.error;
if (e_9) throw e_9.error;
}

@@ -1434,5 +1451,5 @@ }

}
} catch (e_7_1) {
e_7 = {
error: e_7_1
} catch (e_8_1) {
e_8 = {
error: e_8_1
};

@@ -1443,3 +1460,3 @@ } finally {

} finally {
if (e_7) throw e_7.error;
if (e_8) throw e_8.error;
}

@@ -1539,3 +1556,3 @@ }

StateNode.prototype.formatTransitions = function () {
var e_9, _a;
var e_10, _a;

@@ -1557,3 +1574,3 @@ var _this = this;

onConfig = flatten(keys(strictTransitionConfigs_1).map(function (key) {
onConfig = flatten(Object.keys(strictTransitionConfigs_1).map(function (key) {
if (!IS_PRODUCTION && key === NULL_EVENT) {

@@ -1605,5 +1622,5 @@ warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " + "Please check the `on` configuration for \"#".concat(_this.id, "\"."));

}
} catch (e_9_1) {
e_9 = {
error: e_9_1
} catch (e_10_1) {
e_10 = {
error: e_10_1
};

@@ -1614,3 +1631,3 @@ } finally {

} finally {
if (e_9) throw e_9.error;
if (e_10) throw e_10.error;
}

@@ -1617,0 +1634,0 @@ }

@@ -1,8 +0,10 @@

import { EventObject, StateNode, StateValue } from '.';
import { EventObject, StateValue } from './types';
import { StateNode } from './StateNode';
declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any, any>) => boolean;
export declare function getAllChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Set<StateNode<TC, any, TE, any>>;
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any, any>): Array<StateNode<TC, any, TE, any, any, any>>;
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>): Set<StateNode<TC, any, TE, any, any, any>>;
export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;

@@ -12,3 +14,3 @@ export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;

export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any, any>>, stateNode: StateNode<TC, any, TE, any, any, any>): boolean;
export declare function getMeta(configuration?: StateNode[]): Record<string, any>;

@@ -15,0 +17,0 @@ export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;

import { __values, __spreadArray, __read } from './_virtual/_tslib.js';
import { flatten, keys } from './utils.js';
import { flatten } from './utils.js';

@@ -7,7 +7,12 @@ var isLeafNode = function (stateNode) {

};
function getChildren(stateNode) {
return keys(stateNode.states).map(function (key) {
function getAllChildren(stateNode) {
return Object.keys(stateNode.states).map(function (key) {
return stateNode.states[key];
});
}
function getChildren(stateNode) {
return getAllChildren(stateNode).filter(function (sn) {
return sn.type !== 'history';
});
}
function getAllStateNodes(stateNode) {

@@ -75,6 +80,2 @@ var stateNodes = [stateNode];

if (child.type === 'history') {
continue;
}
if (!configuration.has(child)) {

@@ -263,2 +264,2 @@ configuration.add(child);

export { getAdjList, getAllStateNodes, getChildren, getConfiguration, getMeta, getTagsFromConfiguration, getValue, has, isInFinalState, isLeafNode, nextEvents };
export { getAdjList, getAllChildren, getAllStateNodes, getChildren, getConfiguration, getMeta, getTagsFromConfiguration, getValue, has, isInFinalState, isLeafNode, nextEvents };

@@ -0,8 +1,25 @@

import { Clock, Interpreter } from './interpreter';
import { Model } from './model.types';
import { State } from './State';
import { StateNode } from './StateNode';
import { State } from './State';
import { Interpreter, Clock } from './interpreter';
import { IsNever, Model, Prop } from './model.types';
declare type AnyFunction = (...args: any[]) => any;
import { MarkAllImplementationsAsProvided, TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, AreAllImplementationsAssumedToBeProvided, TypegenEnabled } from './typegenTypes';
export declare type AnyFunction = (...args: any[]) => any;
declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
export declare type IsNever<T> = [T] extends [never] ? true : false;
export declare type Compute<A extends any> = {
[K in keyof A]: A[K];
} & unknown;
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
export declare type Values<T> = T[keyof T];
export declare type Merge<M, N> = Omit<M, keyof N> & N;
export declare type IndexByType<T extends {
type: string;
}> = {
[K in T['type']]: T extends any ? (K extends T['type'] ? T : never) : never;
};
export declare type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
export declare type IsAny<T> = Equals<T, any>;
export declare type Cast<A, B> = A extends B ? A : B;
export declare type NoInfer<T> = [T][T extends any ? 0 : any];
export declare type LowInfer<T> = T & {};
export declare type EventType = string;

@@ -29,2 +46,3 @@ export declare type ActionType = string;

[other: string]: any;
[notAnArrayLike: number]: never;
}

@@ -35,7 +53,10 @@ /**

*/
export interface ActionObject<TContext, TEvent extends EventObject> extends BaseActionObject {
export interface ActionObject<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TAction extends BaseActionObject = BaseActionObject> {
type: string;
/**
* The implementation for executing the action.
*/
exec?: ActionFunction<TContext, TEvent> | undefined;
exec?: ActionFunction<TContext, TExpressionEvent, BaseActionObject, TEvent> | undefined;
/** @deprecated an internal signature that doesn't exist at runtime. Its existence helps TS to choose a better code path in the inference algorithm */
(arg: TContext, ev: TExpressionEvent, meta: ActionMeta<TContext, TEvent, TAction>): void;
}

@@ -50,3 +71,3 @@ export declare type DefaultContext = Record<string, any> | undefined;

export declare type Event<TEvent extends EventObject> = TEvent['type'] | TEvent;
export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateMeta<TContext, TEvent> {
export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> extends StateMeta<TContext, TEvent> {
action: TAction;

@@ -60,8 +81,10 @@ _event: SCXML.Event<TEvent>;

}
export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent, TAction>) => void;
export interface ChooseCondition<TContext, TEvent extends EventObject> {
cond?: Condition<TContext, TEvent>;
actions: Actions<TContext, TEvent>;
export declare type ActionFunction<TContext, TExpressionEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TEvent extends EventObject = TExpressionEvent> = {
bivarianceHack(context: TContext, event: TExpressionEvent, meta: ActionMeta<TContext, TEvent, TAction>): void;
}['bivarianceHack'];
export interface ChooseCondition<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
cond?: Condition<TContext, TExpressionEvent>;
actions: Actions<TContext, TExpressionEvent, TEvent>;
}
export declare type Action<TContext, TEvent extends EventObject> = ActionType | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>;
export declare type Action<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = ActionType | BaseActionObject | ActionObject<TContext, TExpressionEvent, TEvent> | ActionFunction<TContext, TExpressionEvent, BaseActionObject, TEvent>;
/**

@@ -75,6 +98,6 @@ * Extracts action objects that have no extra properties.

export declare type SimpleEventsOf<TEvent extends EventObject> = ExtractWithSimpleSupport<TEvent>;
export declare type BaseAction<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SimpleActionsOf<TAction>['type'] | TAction | RaiseAction<any> | SendAction<TContext, TEvent, any> | AssignAction<TContext, TEvent> | LogAction<TContext, TEvent> | CancelAction | StopAction<TContext, TEvent> | ChooseAction<TContext, TEvent> | ActionFunction<TContext, TEvent>;
export declare type BaseActions<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SingleOrArray<BaseAction<TContext, TEvent, TAction>>;
export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
export declare type StateKey = string | State<any>;
export declare type BaseAction<TContext, TExpressionEvent extends EventObject, TAction extends BaseActionObject, TEvent extends EventObject = TExpressionEvent> = SimpleActionsOf<TAction>['type'] | TAction | RaiseAction<TContext, TExpressionEvent, TEvent> | SendAction<TContext, TExpressionEvent, TEvent> | AssignAction<TContext, TExpressionEvent, TEvent> | LogAction<TContext, TExpressionEvent, TEvent> | CancelAction<TContext, TExpressionEvent, TEvent> | StopAction<TContext, TExpressionEvent, TEvent> | ChooseAction<TContext, TExpressionEvent, TEvent> | PureAction<TContext, TExpressionEvent, TEvent> | ActionFunction<TContext, TExpressionEvent, TAction, TEvent>;
export declare type BaseActions<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TAction extends BaseActionObject> = SingleOrArray<BaseAction<TContext, TExpressionEvent, TAction, TEvent>>;
export declare type Actions<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent>>;
export declare type StateKey = string | AnyState;
export interface StateValueMap {

@@ -110,5 +133,5 @@ [key: string]: StateValue;

export declare type TransitionTargets<TContext> = Array<string | StateNode<TContext, any>>;
export interface TransitionConfig<TContext, TEvent extends EventObject> {
cond?: Condition<TContext, TEvent>;
actions?: Actions<TContext, TEvent>;
export interface TransitionConfig<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
cond?: Condition<TContext, TExpressionEvent>;
actions?: BaseActions<TContext, TExpressionEvent, TEvent, BaseActionObject>;
in?: StateValue;

@@ -155,3 +178,5 @@ internal?: boolean;

}
export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
export declare type Receiver<TEvent extends EventObject> = (listener: {
bivarianceHack(event: TEvent): void;
}['bivarianceHack']) => void;
export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (callback: Sender<TSentEvent>, onReceive: Receiver<TEvent>) => (() => void) | Promise<any> | void;

@@ -176,3 +201,4 @@ export interface InvokeMeta {

*/
export declare type InvokeCreator<TContext, TEvent extends EventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<any, TEvent> | Behavior<any>;
export declare type InvokeCreator<TContext, TSourceEvent extends EventObject, TFinalContext = any, TInputEvent extends EventObject = any, // keeping a slot for it here, but it's actually not used right now to ensure that the communication contract between actors is satisfied
TOutputEvent extends EventObject = TSourceEvent> = (context: TContext, event: TSourceEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any, any, any, any, any> | Subscribable<EventObject> | InvokeCallback<TInputEvent, TOutputEvent> | Behavior<any>;
export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {

@@ -217,20 +243,14 @@ /**

export declare type StateNodesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
[K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K], TEvent>;
[K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K] & {}, TEvent>;
};
export declare type StatesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
[K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K], TEvent, TAction>;
[K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K] & {}, TEvent, TAction>;
};
export declare type StatesDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
[K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K], TEvent>;
[K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K] & {}, TEvent>;
};
export declare type TransitionConfigTarget<TContext, TEvent extends EventObject> = string | undefined | StateNode<TContext, any, TEvent>;
export declare type TransitionConfigOrTarget<TContext, TEvent extends EventObject> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TEvent>>;
export declare type TransitionConfigOrTarget<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TExpressionEvent, TEvent>>;
export declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
[K in TEvent['type']]?: TransitionConfigOrTarget<TContext, TEvent extends {
type: K;
} ? TEvent : never>;
} & {
''?: TransitionConfigOrTarget<TContext, TEvent>;
} & {
'*'?: TransitionConfigOrTarget<TContext, TEvent>;
[K in TEvent['type'] | '' | '*']?: K extends '' | '*' ? TransitionConfigOrTarget<TContext, TEvent> : TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent>;
};

@@ -258,3 +278,3 @@ declare type TransitionsConfigArray<TContext, TEvent extends EventObject> = Array<(TEvent extends EventObject ? TransitionConfig<TContext, TEvent> & {

*/
src: string | InvokeSourceDefinition | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent, any>;
src: string | InvokeSourceDefinition | AnyStateMachine | InvokeCreator<TContext, TEvent, any>;
/**

@@ -282,7 +302,7 @@ * If `true`, events sent to the parent service will be forwarded to the invoked service.

*/
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
/**
* The transition to take upon the invoked child machine sending an error event.
*/
onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
/**

@@ -330,3 +350,3 @@ * Meta data related to this invocation

*/
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent> | StateMachine<any, any, any>>;
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent> | AnyStateMachine>;
/**

@@ -345,3 +365,3 @@ * The mapping of event types to their potential transition(s).

*/
entry?: BaseActions<TContext, TEvent, TAction>;
entry?: BaseActions<TContext, TEvent, TEvent, TAction>;
/**

@@ -356,3 +376,3 @@ * The action(s) to be executed upon exiting the state node.

*/
exit?: BaseActions<TContext, TEvent, TAction>;
exit?: BaseActions<TContext, TEvent, TEvent, TAction>;
/**

@@ -424,2 +444,8 @@ * The potential transition(s) to be taken upon reaching a final child state node.

/**
* Whether XState calls actions with the event directly responsible for the related transition.
*
* @default false
*/
predictableActionArguments?: boolean;
/**
* A text description of the state node

@@ -454,2 +480,4 @@ */

export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
export declare type AnyState = State<any, any, any, any, any>;
export declare type AnyStateMachine = StateMachine<any, any, any, any, any, any, any>;
export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {

@@ -474,3 +502,3 @@ initial?: undefined;

export declare type SimpleOrStateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TStateSchema, TEvent>;
export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = {
export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
[K in TAction['type']]?: ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent, TAction extends {

@@ -481,27 +509,46 @@ type: K;

export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | AnyStateMachine | InvokeCreator<TContext, TEvent>;
export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
export interface MachineOptions<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> {
guards: Record<string, ConditionPredicate<TContext, TEvent>>;
actions: ActionFunctionMap<TContext, TEvent, TAction>;
declare type MachineOptionsActions<TContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>> = {
[K in keyof TEventsCausingActions]?: ActionObject<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>> | ActionFunction<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
};
declare type MachineOptionsDelays<TContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingDelays'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>> = {
[K in keyof TEventsCausingDelays]?: DelayConfig<TContext, Cast<Prop<TIndexedEvents, TEventsCausingDelays[K]>, EventObject>>;
};
declare type MachineOptionsGuards<TContext, TResolvedTypesMeta, TEventsCausingGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingGuards'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>> = {
[K in keyof TEventsCausingGuards]?: ConditionPredicate<TContext, Cast<Prop<TIndexedEvents, TEventsCausingGuards[K]>, EventObject>>;
};
declare type MachineOptionsServices<TContext, TResolvedTypesMeta, TEventsCausingServices = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingServices'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
[K in keyof TEventsCausingServices]?: AnyStateMachine | InvokeCreator<TContext, Cast<Prop<TIndexedEvents, TEventsCausingServices[K]>, EventObject>, Prop<Prop<TIndexedEvents, Prop<TInvokeSrcNameMap, K>>, 'data'>, EventObject, Cast<TIndexedEvents[keyof TIndexedEvents], EventObject>>;
};
declare type MakeKeysRequired<T extends string> = {
[K in T]: unknown;
};
declare type MaybeMakeMissingImplementationsRequired<TImplementationType, TMissingImplementationsForType, TRequireMissingImplementations> = TRequireMissingImplementations extends true ? IsNever<TMissingImplementationsForType> extends true ? {} : {
[K in Cast<TImplementationType, string>]: MakeKeysRequired<Cast<TMissingImplementationsForType, string>>;
} : {};
declare type GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
actions?: MachineOptionsActions<TContext, TResolvedTypesMeta>;
};
declare type GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'delays', Prop<TMissingImplementations, 'delays'>, TRequireMissingImplementations> & {
delays?: MachineOptionsDelays<TContext, TResolvedTypesMeta>;
};
declare type GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
guards?: MachineOptionsGuards<TContext, TResolvedTypesMeta>;
};
declare type GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'services', Prop<TMissingImplementations, 'services'>, TRequireMissingImplementations> & {
services?: MachineOptionsServices<TContext, TResolvedTypesMeta>;
};
export declare type InternalMachineOptions<TContext, TEvent extends EventObject, TResolvedTypesMeta, TRequireMissingImplementations extends boolean = false, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & {
/**
* @deprecated Use `services` instead.
*/
activities: Record<string, ActivityConfig<TContext, TEvent>>;
services: Record<string, ServiceConfig<TContext, TEvent>>;
delays: DelayFunctionMap<TContext, TEvent>;
activities?: Record<string, ActivityConfig<TContext, TEvent>>;
};
export declare type MachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta = TypegenDisabled> extends StateNodeConfig<NoInfer<TContext>, TStateSchema, NoInfer<TEvent>, TAction> {
/**
* @private
*/
_parent?: StateNode<TContext, any, TEvent, any>;
/**
* @private
*/
_key?: string;
}
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = ActionObject<TContext, TEvent>> extends StateNodeConfig<TContext, TStateSchema, TEvent, TAction> {
/**
* The initial context (extended state)
*/
context?: TContext | (() => TContext);
context?: LowInfer<TContext | (() => TContext)>;
/**

@@ -511,5 +558,9 @@ * The machine's own version.

version?: string;
schema?: MachineSchema<TContext, TEvent>;
schema?: MachineSchema<TContext, TEvent, TServiceMap>;
tsTypes?: TTypesMeta;
}
export interface MachineSchema<TContext, TEvent extends EventObject> {
export declare type ServiceMap = Record<string, {
data: any;
}>;
export interface MachineSchema<TContext, TEvent extends EventObject, TServiceMap extends ServiceMap = ServiceMap> {
context?: TContext;

@@ -525,6 +576,3 @@ events?: TEvent;

};
services?: {
type: string;
[key: string]: any;
};
services?: TServiceMap;
}

@@ -545,12 +593,27 @@ export interface StandardMachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {

}
/** @ts-ignore TS complains about withConfig & withContext not being compatible here when extending StateNode */
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}, _TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TServiceMap>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta> {
id: string;
states: StateNode<TContext, TStateSchema, TEvent>['states'];
withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, TResolvedTypesMeta>;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TContext: TContext;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TStateSchema: TStateSchema;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TEvent: TEvent;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TTypestate: TTypestate;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TAction: TAction;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TServiceMap: TServiceMap;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TResolvedTypesMeta: TResolvedTypesMeta;
}
export declare type StateFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
export declare type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? ReturnType<T['transition']> : T extends (...args: any[]) => AnyStateMachine ? ReturnType<ReturnType<T>['transition']> : never;
export interface ActionMap<TContext, TEvent extends EventObject> {

@@ -574,9 +637,8 @@ onEntry: Array<Action<TContext, TEvent>>;

transitions: Array<TransitionDefinition<TContext, TEvent>>;
configuration: Array<StateNode<TContext, any, TEvent, any>>;
entrySet: Array<StateNode<TContext, any, TEvent, any>>;
exitSet: Array<StateNode<TContext, any, TEvent, any>>;
configuration: Array<StateNode<TContext, any, TEvent, any, any, any>>;
exitSet: Array<StateNode<TContext, any, TEvent, any, any, any>>;
/**
* The source state that preceded the transition.
*/
source: State<TContext, any, any, any> | undefined;
source: State<TContext, any, any, any, any> | undefined;
actions: Array<ActionObject<TContext, TEvent>>;

@@ -611,9 +673,13 @@ }

}
export interface RaiseAction<TEvent extends EventObject> {
export interface RaiseAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Raise;
event: TEvent['type'];
event: TEvent | SendExpr<TContext, TExpressionEvent, TEvent>;
delay: number | string | undefined | DelayExpr<TContext, TExpressionEvent>;
id: string | number | undefined;
}
export interface RaiseActionObject<TEvent extends EventObject> {
export interface RaiseActionObject<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends RaiseAction<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Raise;
_event: SCXML.Event<TEvent>;
delay: number | undefined;
id: string | number | undefined;
}

@@ -637,3 +703,3 @@ export interface DoneInvokeEvent<TData> extends EventObject {

id: string | number;
state: State<any, any>;
state: AnyState;
}

@@ -654,5 +720,6 @@ export declare type DoneEvent = DoneEventObject & string;

export declare type LogExpr<TContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, any>;
export interface LogAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface LogAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Log;
label: string | undefined;
expr: string | LogExpr<TContext, TEvent>;
expr: string | LogExpr<TContext, TExpressionEvent>;
}

@@ -662,3 +729,4 @@ export interface LogActionObject<TContext, TEvent extends EventObject> extends LogAction<TContext, TEvent> {

}
export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent, TSentEvent> {
type: ActionTypes.Send;
to: string | number | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>> | undefined;

@@ -676,7 +744,7 @@ event: TSentEvent | SendExpr<TContext, TEvent, TSentEvent>;

}
export interface StopAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface StopAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Stop;
activity: string | {
id: string;
} | Expr<TContext, TEvent, string | {
} | Expr<TContext, TExpressionEvent, string | {
id: string;

@@ -698,8 +766,11 @@ }>;

}
export interface SendActionOptions<TContext, TEvent extends EventObject> {
export interface SendActionOptions<TContext, TEvent extends EventObject> extends RaiseActionOptions<TContext, TEvent> {
to?: string | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | ActorRef<any>>;
}
export interface RaiseActionOptions<TContext, TEvent extends EventObject> {
id?: string | number;
delay?: number | string | DelayExpr<TContext, TEvent>;
to?: string | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>>;
}
export interface CancelAction extends ActionObject<any, any> {
export interface CancelAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Cancel;
sendId: string | number;

@@ -720,15 +791,15 @@ }

}
export interface AssignAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface AssignAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Assign;
assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>;
assignment: Assigner<TContext, TExpressionEvent> | PropertyAssigner<TContext, TExpressionEvent>;
}
export interface PureAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface PureAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Pure;
get: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined;
get: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent> | ActionObject<TContext, TEvent>['type'] | ActionFunction<TContext, TEvent>> | undefined;
}
export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface ChooseAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Choose;
conds: Array<ChooseCondition<TContext, TEvent>>;
}
export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
export interface TransitionDefinition<TContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, any>, 'actions'> {
target: Array<StateNode<TContext, any, TEvent>> | undefined;

@@ -809,3 +880,3 @@ source: StateNode<TContext, any, TEvent>;

export interface StateMeta<TContext, TEvent extends EventObject> {
state: State<TContext, TEvent, any, any>;
state: State<TContext, TEvent, any, any, any>;
_event: SCXML.Event<TEvent>;

@@ -829,3 +900,3 @@ }

historyValue?: HistoryValue | undefined;
history?: State<TContext, TEvent>;
history?: State<TContext, TEvent, any, any, any>;
actions?: Array<ActionObject<TContext, TEvent>>;

@@ -837,2 +908,5 @@ /**

meta?: any;
/**
* @deprecated
*/
events?: TEvent[];

@@ -844,4 +918,5 @@ configuration: Array<StateNode<TContext, any, TEvent>>;

tags?: Set<string>;
machine?: StateMachine<TContext, any, TEvent, any>;
machine?: StateMachine<TContext, any, TEvent, any, any, any, any>;
}
export declare type AnyStateConfig = StateConfig<any, AnyEventObject>;
export interface StateSchema<TC = any> {

@@ -858,5 +933,5 @@ meta?: any;

*/
execute: boolean;
clock: Clock;
logger: (...args: any[]) => void;
execute?: boolean;
clock?: Clock;
logger?: (...args: any[]) => void;
parent?: AnyInterpreter;

@@ -870,3 +945,3 @@ /**

*/
deferEvents: boolean;
deferEvents?: boolean;
/**

@@ -881,4 +956,3 @@ * The custom `id` for referencing this service.

*/
devTools: boolean | object;
[option: string]: any;
devTools?: boolean | object;
}

@@ -955,14 +1029,18 @@ export declare namespace SCXML {

}
export interface Subscribable<T> {
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
export interface InteropObservable<T> {
[Symbol.observable]: () => InteropSubscribable<T>;
}
export interface InteropSubscribable<T> {
subscribe(observer: Observer<T>): Subscription;
}
export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
type: TEventType;
} ? TEvent : never;
export interface Subscribable<T> extends InteropSubscribable<T> {
subscribe(observer: Observer<T>): Subscription;
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
}
export declare type Spawnable = AnyStateMachine | PromiseLike<any> | InvokeCallback | InteropObservable<any> | Subscribable<any> | Behavior<any>;
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends any ? TEventType extends TEvent['type'] ? TEvent : never : never;
export interface BaseActorRef<TEvent extends EventObject> {
send: (event: TEvent) => void;
}
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted>, InteropObservable<TEmitted> {
send: Sender<TEvent>;

@@ -974,2 +1052,3 @@ id: string;

}
export declare type AnyActorRef = ActorRef<any, any>;
/**

@@ -979,11 +1058,13 @@ * @deprecated Use `ActorRef` instead.

export declare type SpawnedActorRef<TEvent extends EventObject, TEmitted = any> = ActorRef<TEvent, TEmitted>;
export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext>> = ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext>, TResolvedTypesMeta = TypegenDisabled> = ActorRef<TEvent, State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>> & {
/**
* @deprecated Use `.getSnapshot()` instead.
*/
state: State<TContext, TEvent, any, TTypestate>;
state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>;
};
export declare type ActorRefFrom<T> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : T extends (...args: any[]) => Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
export declare type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : R extends Promise<infer U> ? ActorRef<never, U> : R extends Behavior<infer TEvent, infer TEmitted> ? ActorRef<TEvent, TEmitted> : never : never;
export declare type AnyInterpreter = Interpreter<any, any, any, any, any>;
export declare type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never;
export declare type MachineOptionsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, any, infer TEvent, any, any, any, infer TResolvedTypesMeta> ? InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, TRequireMissingImplementations> : never;
export declare type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
export interface ActorContext<TEvent extends EventObject, TEmitted> {

@@ -1000,9 +1081,14 @@ parent?: ActorRef<any, any>;

}
export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : Extract<TEvent, {
type: K;
}>;
export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____, infer ______, infer _______> ? R['initialState'] : R extends Interpreter<infer _, infer __, infer ___, infer ____, infer _____> ? R['initialState'] : R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ___, infer ____, infer _____, infer ______> ? TEvent : R extends Model<infer _, infer TEvent, infer __, infer ___> ? TEvent : R extends State<infer _, infer TEvent, infer __, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ___, infer ____> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____, infer _____, infer ______> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : never : never;
declare type Matches<TypegenEnabledArg, TypegenDisabledArg> = {
(stateValue: TypegenEnabledArg): any;
(stateValue: TypegenDisabledArg): any;
};
export declare type StateValueFrom<TMachine extends AnyStateMachine> = StateFrom<TMachine>['matches'] extends Matches<infer TypegenEnabledArg, infer TypegenDisabledArg> ? TMachine['__TResolvedTypesMeta'] extends TypegenEnabled ? TypegenEnabledArg : TypegenDisabledArg : never;
export declare type PredictableActionArgumentsExec = (action: ActionObject<unknown, EventObject>, context: unknown, _event: SCXML.Event<EventObject>) => void;
export declare type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
export {};
//# sourceMappingURL=types.d.ts.map

@@ -1,5 +0,6 @@

import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior } from './types';
import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior, RaiseActionObject, SendActionObject } from './types';
import { StateNode } from './StateNode';
import { State } from './State';
import { Actor } from './Actor';
import { ActionObject, AnyStateMachine } from '.';
export declare function keys<T extends object>(value: T): Array<keyof T & string>;

@@ -13,5 +14,3 @@ export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;

export declare function pathToStateValue(statePath: string[]): StateValue;
export declare function mapValues<T, P, O extends {
[key: string]: T;
}>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
[key in keyof O]: P;

@@ -56,4 +55,7 @@ };

export declare function isObservable<T>(value: any): value is Subscribable<T>;
export declare const symbolObservable: any;
export declare function isMachine(value: any): value is StateMachine<any, any, any>;
export declare const symbolObservable: typeof Symbol.observable;
export declare const interopSymbols: {
[Symbol.observable]: () => any;
};
export declare function isMachine(value: any): value is AnyStateMachine;
export declare function isActor(value: any): value is Actor;

@@ -68,5 +70,7 @@ export declare const uniqueId: () => string;

export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
export declare function toObserver<T>(nextHandler?: Partial<Observer<T>> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
export declare function createInvokeId(stateNodeId: string, index: number): string;
export declare function isRaisableAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(action: ActionObject<TContext, TExpressionEvent, TEvent>): action is RaiseActionObject<TContext, TExpressionEvent, TEvent> | SendActionObject<TContext, TExpressionEvent, TEvent>;
//# sourceMappingURL=utils.d.ts.map

@@ -1,5 +0,8 @@

import { __spreadArray, __read, __values, __assign } from './_virtual/_tslib.js';
import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
import { SpecialTargets } from './types.js';
import { raise, send } from './actionTypes.js';
import { DEFAULT_GUARD_TYPE, TARGETLESS_KEY, STATE_DELIMITER } from './constants.js';
import { IS_PRODUCTION } from './environment.js';
var _a;
function keys(value) {

@@ -29,3 +32,3 @@ return Object.keys(value);

return keys(parentStateValue).every(function (key) {
return Object.keys(parentStateValue).every(function (key) {
if (!(key in childStateValue)) {

@@ -45,2 +48,9 @@ return false;

}
function getActionType(action) {
try {
return isString(action) || typeof action === 'number' ? "".concat(action) : isFunction(action) ? action.name : action.type;
} catch (e) {
throw new Error('Actions must be strings or objects with a string action.type property.');
}
}
function toStatePath(stateId, delimiter) {

@@ -97,3 +107,3 @@ try {

var result = {};
var collectionKeys = keys(collection);
var collectionKeys = Object.keys(collection);

@@ -113,3 +123,3 @@ for (var i = 0; i < collectionKeys.length; i++) {

try {
for (var _b = __values(keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = __values(Object.keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;

@@ -209,3 +219,3 @@ var item = collection[key];

var result = flatten(keys(stateValue).map(function (key) {
var result = flatten(Object.keys(stateValue).map(function (key) {
var subStateValue = stateValue[key];

@@ -223,2 +233,42 @@

}
function pathsToStateValue(paths) {
var e_4, _a;
var result = {};
if (paths && paths.length === 1 && paths[0].length === 1) {
return paths[0][0];
}
try {
for (var paths_1 = __values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
var currentPath = paths_1_1.value;
var marker = result; // tslint:disable-next-line:prefer-for-of
for (var i = 0; i < currentPath.length; i++) {
var subPath = currentPath[i];
if (i === currentPath.length - 2) {
marker[subPath] = currentPath[i + 1];
break;
}
marker[subPath] = marker[subPath] || {};
marker = marker[subPath];
}
}
} catch (e_4_1) {
e_4 = {
error: e_4_1
};
} finally {
try {
if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
} finally {
if (e_4) throw e_4.error;
}
}
return result;
}
function flatten(array) {

@@ -370,3 +420,3 @@ var _a;

try {
for (var _b = __values(keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = __values(Object.keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;

@@ -425,14 +475,3 @@ var propAssignment = assignment[key];

return typeof value === 'string';
} // export function memoizedGetter<T, TP extends { prototype: object }>(
// o: TP,
// property: string,
// getter: () => T
// ): void {
// Object.defineProperty(o.prototype, property, {
// get: getter,
// enumerable: false,
// configurable: false
// });
// }
}
function toGuard(condition, guardMap) {

@@ -470,9 +509,11 @@ if (!condition) {

return typeof Symbol === 'function' && Symbol.observable || '@@observable';
}();
}(); // TODO: to be removed in v5, left it out just to minimize the scope of the change and maintain compatibility with older versions of integration paackages
var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
return this;
}, _a[Symbol.observable] = function () {
return this;
}, _a);
function isMachine(value) {
try {
return '__xstatenode' in value;
} catch (e) {
return false;
}
return !!value && '__xstatenode' in value;
}

@@ -560,3 +601,3 @@ function isActor(value) {

var condFn = guards[guard.type];
var condFn = guards === null || guards === void 0 ? void 0 : guards[guard.type];

@@ -579,17 +620,19 @@ if (!condFn) {

function toObserver(nextHandler, errorHandler, completionHandler) {
if (typeof nextHandler === 'object') {
return nextHandler;
}
var noop = function () {};
var noop = function () {
return void 0;
};
var isObserver = typeof nextHandler === 'object';
var self = isObserver ? nextHandler : null;
return {
next: nextHandler,
error: errorHandler || noop,
complete: completionHandler || noop
next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self),
error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self),
complete: ((isObserver ? nextHandler.complete : completionHandler) || noop).bind(self)
};
}
function createInvokeId(stateNodeId, index) {
return "".concat(stateNodeId, ":invocation[").concat(index, "]");
}
function isRaisableAction(action) {
return (action.type === raise || action.type === send && action.to === SpecialTargets.Internal) && typeof action.delay !== 'number';
}
export { evaluateGuard, flatten, getEventType, isActor, isArray, isBehavior, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };
export { createInvokeId, evaluateGuard, flatten, getActionType, getEventType, interopSymbols, isActor, isArray, isBehavior, isBuiltInEvent, isFunction, isMachine, isObservable, isPromiseLike, isRaisableAction, isStateLike, isString, keys, mapContext, mapFilterValues, mapValues, matchesState, nestedPath, normalizeTarget, partition, path, pathToStateValue, pathsToStateValue, reportUnhandledExceptionOnInvocation, symbolObservable, toArray, toArrayStrict, toEventObject, toGuard, toInvokeSource, toObserver, toSCXMLEvent, toStatePath, toStatePaths, toStateValue, toTransitionConfigArray, uniqueId, updateContext, updateHistoryStates, updateHistoryValue, warn };

@@ -1,6 +0,5 @@

import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, Cast } from './types';
import { Action, Event, EventObject, SingleOrArray, SendAction, SendActionOptions, CancelAction, ActionObject, ActionType, Assigner, PropertyAssigner, AssignAction, ActionFunction, ActionFunctionMap, ActivityActionObject, ActionTypes, ActivityDefinition, RaiseAction, RaiseActionObject, DoneEvent, ErrorPlatformEvent, DoneEventObject, SendExpr, SendActionObject, PureAction, LogExpr, LogAction, LogActionObject, DelayFunctionMap, SCXML, ExprWithMeta, ChooseCondition, ChooseAction, AnyEventObject, Expr, StopAction, StopActionObject, Cast, EventFrom, AnyActorRef, PredictableActionArgumentsExec, RaiseActionOptions, NoInfer, BaseActionObject, LowInfer } from './types';
import * as actionTypes from './actionTypes';
import { State } from './State';
import { StateNode } from './StateNode';
import { ActorRef, EventFrom, StopAction, StopActionObject } from '.';
export { actionTypes };

@@ -12,3 +11,3 @@ export declare const initEvent: SCXML.Event<{

export declare function toActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): ActionObject<TContext, TEvent>;
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, ActionObject<TContext, TEvent>> | undefined) => ActionObject<TContext, TEvent>[];
export declare const toActionObjects: <TContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, BaseActionObject> | undefined) => ActionObject<TContext, TEvent, TEvent, BaseActionObject>[];
export declare function toActivityDefinition<TContext, TEvent extends EventObject>(action: string | ActivityDefinition<TContext, TEvent>): ActivityDefinition<TContext, TEvent>;

@@ -21,4 +20,4 @@ /**

*/
export declare function raise<TContext, TEvent extends EventObject>(event: Event<TEvent>): RaiseAction<TEvent> | SendAction<TContext, AnyEventObject, TEvent>;
export declare function resolveRaise<TEvent extends EventObject>(action: RaiseAction<TEvent>): RaiseActionObject<TEvent>;
export declare function raise<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(event: NoInfer<Event<TEvent>> | SendExpr<TContext, TExpressionEvent, TEvent>, options?: RaiseActionOptions<TContext, TExpressionEvent>): RaiseAction<TContext, TExpressionEvent, TEvent>;
export declare function resolveRaise<TContext, TEvent extends EventObject, TExpressionEvent extends EventObject>(action: RaiseAction<TContext, TExpressionEvent, TEvent>, ctx: TContext, _event: SCXML.Event<TExpressionEvent>, delaysMap?: DelayFunctionMap<TContext, TEvent>): RaiseActionObject<TContext, TExpressionEvent, TEvent>;
/**

@@ -28,2 +27,4 @@ * Sends an event. This returns an action that will be read by an interpreter to

*
* @deprecated Use the `sendTo(...)` action creator instead.
*
* @param event The event to send.

@@ -35,3 +36,3 @@ * @param options Options to pass into the send event:

*/
export declare function send<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
export declare function send<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<AnyEventObject> | SendExpr<TContext, TEvent, AnyEventObject>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
export declare function resolveSend<TContext, TEvent extends EventObject, TSentEvent extends EventObject>(action: SendAction<TContext, TEvent, TSentEvent>, ctx: TContext, _event: SCXML.Event<TEvent>, delaysMap?: DelayFunctionMap<TContext, TEvent>): SendActionObject<TContext, TEvent, TSentEvent>;

@@ -44,3 +45,3 @@ /**

*/
export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
export declare function sendParent<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<AnyEventObject> | SendExpr<TContext, TEvent, AnyEventObject>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, TSentEvent>;
declare type InferEvent<E extends EventObject> = {

@@ -61,9 +62,7 @@ [T in E['type']]: {

*/
export declare function sendTo<TContext, TEvent extends EventObject, TActor extends ActorRef<EventObject>>(actor: (ctx: TContext) => TActor, event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
export declare function sendTo<TContext, TEvent extends EventObject, TActor extends AnyActorRef>(actor: string | TActor | ((ctx: TContext, event: TEvent) => TActor), event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
/**
* Sends an update event to this machine's parent.
*/
export declare function sendUpdate<TContext, TEvent extends EventObject>(): SendAction<TContext, TEvent, {
type: ActionTypes.Update;
}>;
export declare function sendUpdate<TContext, TEvent extends EventObject>(): SendAction<TContext, TEvent, any>;
/**

@@ -84,4 +83,4 @@ * Sends an event back to the sender of the original event.

*/
export declare function log<TContext, TEvent extends EventObject>(expr?: string | LogExpr<TContext, TEvent>, label?: string): LogAction<TContext, TEvent>;
export declare const resolveLog: <TContext, TEvent extends EventObject>(action: LogAction<TContext, TEvent>, ctx: TContext, _event: SCXML.Event<TEvent>) => LogActionObject<TContext, TEvent>;
export declare function log<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(expr?: string | LogExpr<TContext, TExpressionEvent>, label?: string): LogAction<TContext, TExpressionEvent, TEvent>;
export declare const resolveLog: <TContext, TEvent extends EventObject>(action: LogAction<TContext, TEvent, TEvent>, ctx: TContext, _event: SCXML.Event<TEvent>) => LogActionObject<TContext, TEvent>;
/**

@@ -94,3 +93,3 @@ * Cancels an in-flight `send(...)` action. A canceled sent action will not

*/
export declare const cancel: (sendId: string | number) => CancelAction;
export declare const cancel: <TContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(sendId: string | number) => CancelAction<TContext, TExpressionEvent, TEvent>;
/**

@@ -107,5 +106,5 @@ * Starts an activity.

*/
export declare function stop<TContext, TEvent extends EventObject>(actorRef: string | ActivityDefinition<TContext, TEvent> | Expr<TContext, TEvent, string | {
export declare function stop<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(actorRef: string | Expr<TContext, TExpressionEvent, string | {
id: string;
}>): StopAction<TContext, TEvent>;
}>): StopAction<TContext, TExpressionEvent, TEvent>;
export declare function resolveStop<TContext, TEvent extends EventObject>(action: StopAction<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>): StopActionObject;

@@ -117,3 +116,3 @@ /**

*/
export declare const assign: <TContext, TEvent extends EventObject = EventObject>(assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>) => AssignAction<TContext, TEvent>;
export declare const assign: <TContext, TExpressionEvent extends EventObject = EventObject, TEvent extends EventObject = TExpressionEvent>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent>) => AssignAction<TContext, TExpressionEvent, TEvent>;
export declare function isActionObject<TContext, TEvent extends EventObject>(action: Action<TContext, TEvent>): action is ActionObject<TContext, TEvent>;

@@ -147,3 +146,3 @@ /**

export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
export declare function pure<TContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined): PureAction<TContext, TEvent>;
export declare function pure<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(getActions: (context: TContext, event: TExpressionEvent) => SingleOrArray<BaseActionObject | BaseActionObject['type'] | ActionObject<TContext, TExpressionEvent, TEvent> | ActionFunction<TContext, TExpressionEvent>> | undefined): PureAction<TContext, TExpressionEvent, TEvent>;
/**

@@ -155,3 +154,3 @@ * Forwards (sends) an event to a specified service.

*/
export declare function forwardTo<TContext, TEvent extends EventObject>(target: Required<SendActionOptions<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
export declare function forwardTo<TContext, TEvent extends EventObject>(target: Required<SendActionOptions<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
/**

@@ -164,5 +163,8 @@ * Escalates an error by sending it as an event to this machine's parent.

*/
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, currentState: State<TContext, TEvent> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actions: Array<ActionObject<TContext, TEvent>>, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, any>;
export declare function choose<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(conds: Array<ChooseCondition<TContext, TExpressionEvent, TEvent>>): ChooseAction<TContext, TExpressionEvent, TEvent>;
export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<{
type: string;
actions: Array<ActionObject<TContext, TEvent>>;
}>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
//# sourceMappingURL=actions.d.ts.map

@@ -6,6 +6,6 @@ 'use strict';

var _tslib = require('./_virtual/_tslib.js');
var environment = require('./environment.js');
var utils = require('./utils.js');
var types = require('./types.js');
var actionTypes = require('./actionTypes.js');
var utils = require('./utils.js');
var environment = require('./environment.js');

@@ -87,19 +87,29 @@ var initEvent = /*#__PURE__*/utils.toSCXMLEvent({

function raise(event) {
if (!utils.isString(event)) {
return send(event, {
to: types.SpecialTargets.Internal
});
}
function raise(event, options) {
return {
type: actionTypes.raise,
event: event
event: typeof event === 'function' ? event : utils.toEventObject(event),
delay: options ? options.delay : undefined,
id: options === null || options === void 0 ? void 0 : options.id
};
}
function resolveRaise(action) {
return {
function resolveRaise(action, ctx, _event, delaysMap) {
var meta = {
_event: _event
};
var resolvedEvent = utils.toSCXMLEvent(utils.isFunction(action.event) ? action.event(ctx, _event.data, meta) : action.event);
var resolvedDelay;
if (utils.isString(action.delay)) {
var configDelay = delaysMap && delaysMap[action.delay];
resolvedDelay = utils.isFunction(configDelay) ? configDelay(ctx, _event.data, meta) : configDelay;
} else {
resolvedDelay = utils.isFunction(action.delay) ? action.delay(ctx, _event.data, meta) : action.delay;
}
return _tslib.__assign(_tslib.__assign({}, action), {
type: actionTypes.raise,
_event: utils.toSCXMLEvent(action.event)
};
_event: resolvedEvent,
delay: resolvedDelay
});
}

@@ -110,2 +120,4 @@ /**

*
* @deprecated Use the `sendTo(...)` action creator instead.
*
* @param event The event to send.

@@ -124,2 +136,4 @@ * @param options Options to pass into the send event:

delay: options ? options.delay : undefined,
// TODO: don't auto-generate IDs here like that
// there is too big chance of the ID collision
id: options && options.id !== undefined ? options.id : utils.isFunction(event) ? event.name : utils.getEventType(event)

@@ -164,2 +178,16 @@ };

/**
* Sends an event to an actor.
*
* @param actor The `ActorRef` to send the event to.
* @param event The event to send, or an expression that evaluates to the event to send
* @param options Send action options
* @returns An XState send action object
*/
function sendTo(actor, event, options) {
return send(event, _tslib.__assign(_tslib.__assign({}, options), {
to: actor
}));
}
/**
* Sends an update event to this machine's parent.

@@ -286,2 +314,5 @@ */

};
function isActionObject(action) {
return typeof action === 'object' && 'type' in action;
}
/**

@@ -370,2 +401,22 @@ * Returns an event type that represents an implicit event that

function forwardTo(target, options) {
if (!environment.IS_PRODUCTION && (!target || typeof target === 'function')) {
var originalTarget_1 = target;
target = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var resolvedTarget = typeof originalTarget_1 === 'function' ? originalTarget_1.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false)) : originalTarget_1;
if (!resolvedTarget) {
throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");
}
return resolvedTarget;
};
}
return send(function (_, event) {

@@ -401,3 +452,39 @@ return event;

}
function resolveActions(machine, currentState, currentContext, _event, actions, preserveActionOrder) {
var pluckAssigns = function (actionBlocks) {
var e_1, _a;
var assignActions = [];
try {
for (var actionBlocks_1 = _tslib.__values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
var block = actionBlocks_1_1.value;
var i = 0;
while (i < block.actions.length) {
if (block.actions[i].type === actionTypes.assign) {
assignActions.push(block.actions[i]);
block.actions.splice(i, 1);
continue;
}
i++;
}
}
} catch (e_1_1) {
e_1 = {
error: e_1_1
};
} finally {
try {
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
} finally {
if (e_1) throw e_1.error;
}
}
return assignActions;
};
function resolveActions(machine, currentState, currentContext, _event, actionBlocks, predictableExec, preserveActionOrder) {
if (preserveActionOrder === void 0) {

@@ -407,11 +494,8 @@ preserveActionOrder = false;

var _a = _tslib.__read(preserveActionOrder ? [[], actions] : utils.partition(actions, function (action) {
return action.type === actionTypes.assign;
}), 2),
assignActions = _a[0],
otherActions = _a[1];
var assignActions = preserveActionOrder ? [] : pluckAssigns(actionBlocks);
var updatedContext = assignActions.length ? utils.updateContext(currentContext, _event, assignActions, currentState) : currentContext;
var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
var resolvedActions = utils.flatten(otherActions.map(function (actionObject) {
var deferredToBlockEnd = [];
function handleAction(blockType, actionObject) {
var _a;

@@ -421,4 +505,12 @@

case actionTypes.raise:
return resolveRaise(actionObject);
{
var raisedAction = resolveRaise(actionObject, updatedContext, _event, machine.options.delays);
if (predictableExec && typeof raisedAction.delay === 'number') {
predictableExec(raisedAction, updatedContext, _event);
}
return raisedAction;
}
case actionTypes.send:

@@ -428,11 +520,24 @@ var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init

if (!environment.IS_PRODUCTION) {
// warn after resolving as we can create better contextual message here
utils.warn(!utils.isString(actionObject.delay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
"No delay reference for delay expression '".concat(actionObject.delay, "' was found on machine '").concat(machine.id, "'"));
var configuredDelay = actionObject.delay; // warn after resolving as we can create better contextual message here
utils.warn(!utils.isString(configuredDelay) || typeof sendAction.delay === 'number', // tslint:disable-next-line:max-line-length
"No delay reference for delay expression '".concat(configuredDelay, "' was found on machine '").concat(machine.id, "'"));
}
if (predictableExec && sendAction.to !== types.SpecialTargets.Internal) {
if (blockType === 'entry') {
deferredToBlockEnd.push(sendAction);
} else {
predictableExec(sendAction, updatedContext, _event);
}
}
return sendAction;
case actionTypes.log:
return resolveLog(actionObject, updatedContext, _event);
{
var resolved = resolveLog(actionObject, updatedContext, _event);
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, updatedContext, _event);
return resolved;
}

@@ -444,3 +549,3 @@ case actionTypes.choose:

var guard = utils.toGuard(condition.cond, machine.options.guards);
return !guard || utils.evaluateGuard(machine, guard, updatedContext, _event, currentState);
return !guard || utils.evaluateGuard(machine, guard, updatedContext, _event, !predictableExec ? currentState : undefined);
})) === null || _a === void 0 ? void 0 : _a.actions;

@@ -452,3 +557,6 @@

var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
var _b = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [{
type: blockType,
actions: toActionObjects(utils.toArray(matchedActions), machine.options.actions)
}], predictableExec, preserveActionOrder), 2),
resolvedActionsFromChoose = _b[0],

@@ -470,3 +578,6 @@ resolvedContextFromChoose = _b[1];

var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, toActionObjects(utils.toArray(matchedActions), machine.options.actions), preserveActionOrder), 2),
var _c = _tslib.__read(resolveActions(machine, currentState, updatedContext, _event, [{
type: blockType,
actions: toActionObjects(utils.toArray(matchedActions), machine.options.actions)
}], predictableExec, preserveActionOrder), 2),
resolvedActionsFromPure = _c[0],

@@ -482,3 +593,5 @@ resolvedContext = _c[1];

{
return resolveStop(actionObject, updatedContext, _event);
var resolved = resolveStop(actionObject, updatedContext, _event);
predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(resolved, currentContext, _event);
return resolved;
}

@@ -488,3 +601,3 @@

{
updatedContext = utils.updateContext(updatedContext, _event, [actionObject], currentState);
updatedContext = utils.updateContext(updatedContext, _event, [actionObject], !predictableExec ? currentState : undefined);
preservedContexts === null || preservedContexts === void 0 ? void 0 : preservedContexts.push(updatedContext);

@@ -498,5 +611,8 @@ break;

if (exec_1 && preservedContexts) {
if (predictableExec) {
predictableExec(resolvedActionObject, updatedContext, _event);
} else if (exec_1 && preservedContexts) {
var contextIndex_1 = preservedContexts.length - 1;
resolvedActionObject = _tslib.__assign(_tslib.__assign({}, resolvedActionObject), {
var wrapped = _tslib.__assign(_tslib.__assign({}, resolvedActionObject), {
exec: function (_ctx) {

@@ -512,2 +628,4 @@ var args = [];

});
resolvedActionObject = wrapped;
}

@@ -517,8 +635,42 @@

}
}).filter(function (a) {
return !!a;
}));
}
function processBlock(block) {
var e_2, _a;
var resolvedActions = [];
try {
for (var _b = _tslib.__values(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
var action = _c.value;
var resolved = handleAction(block.type, action);
if (resolved) {
resolvedActions = resolvedActions.concat(resolved);
}
}
} catch (e_2_1) {
e_2 = {
error: e_2_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_2) throw e_2.error;
}
}
deferredToBlockEnd.forEach(function (action) {
predictableExec(action, updatedContext, _event);
});
deferredToBlockEnd.length = 0;
return resolvedActions;
}
var resolvedActions = utils.flatten(actionBlocks.map(processBlock));
return [resolvedActions, updatedContext];
}
exports.actionTypes = actionTypes;
exports.after = after;

@@ -535,2 +687,3 @@ exports.assign = assign;

exports.initEvent = initEvent;
exports.isActionObject = isActionObject;
exports.log = log;

@@ -547,2 +700,3 @@ exports.pure = pure;

exports.sendParent = sendParent;
exports.sendTo = sendTo;
exports.sendUpdate = sendUpdate;

@@ -549,0 +703,0 @@ exports.start = start;

@@ -1,3 +0,2 @@

import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML } from './types';
import { ActorRef, BaseActorRef } from '.';
import { EventObject, Subscribable, InvokeDefinition, AnyEventObject, StateMachine, Spawnable, SCXML, ActorRef, BaseActorRef } from './types';
export interface Actor<TContext = any, TEvent extends EventObject = AnyEventObject> extends Subscribable<TContext> {

@@ -25,3 +24,3 @@ id: string;

export declare function isSpawnedActor(item: any): item is ActorRef<any>;
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted>;
export declare function toActorRef<TEvent extends EventObject, TEmitted = any, TActorRefLike extends BaseActorRef<TEvent> = BaseActorRef<TEvent>>(actorRefLike: TActorRefLike): ActorRef<TEvent, TEmitted> & Omit<TActorRefLike, keyof ActorRef<any, any>>;
//# sourceMappingURL=Actor.d.ts.map

@@ -10,3 +10,5 @@ 'use strict';

function createNullActor(id) {
return {
var _a;
return _a = {
id: id,

@@ -31,3 +33,5 @@ send: function () {

}
};
}, _a[utils.symbolObservable] = function () {
return this;
}, _a;
}

@@ -79,5 +83,8 @@ /**

return isActor(item) && 'id' in item;
}
} // TODO: refactor the return type, this could be written in a better way but it's best to avoid unneccessary breaking changes now
function toActorRef(actorRefLike) {
return _tslib.__assign({
var _a;
return _tslib.__assign((_a = {
subscribe: function () {

@@ -94,3 +101,5 @@ return {

}
}, actorRefLike);
}, _a[utils.symbolObservable] = function () {
return this;
}, _a), actorRefLike);
}

@@ -97,0 +106,0 @@

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

import { ActorContext, ActorRef, Behavior, EventObject } from '.';
import { ActorContext, ActorRef, Behavior, EventObject } from './types';
/**

@@ -3,0 +3,0 @@ * Returns an actor behavior from a reducer and its initial state.

@@ -5,8 +5,74 @@ 'use strict';

require('./environment.js');
var actions = require('./actions.js');
var Actor = require('./Actor.js');
var utils = require('./utils.js');
require('./types.js');
require('./actionTypes.js');
var Actor = require('./Actor.js');
/**
* Returns an actor behavior from a reducer and its initial state.
*
* @param transition The pure reducer that returns the next state given the current state and event.
* @param initialState The initial state of the reducer.
* @returns An actor behavior
*/
function fromReducer(transition, initialState) {
return {
transition: transition,
initialState: initialState
};
}
function fromPromise(promiseFn) {
var initialState = {
error: undefined,
data: undefined,
status: 'pending'
};
return {
transition: function (state, event, _a) {
var parent = _a.parent,
id = _a.id,
observers = _a.observers;
switch (event.type) {
case 'fulfill':
parent === null || parent === void 0 ? void 0 : parent.send(actions.doneInvoke(id, event.data));
return {
error: undefined,
data: event.data,
status: 'fulfilled'
};
case 'reject':
parent === null || parent === void 0 ? void 0 : parent.send(actions.error(id, event.error));
observers.forEach(function (observer) {
observer.error(event.error);
});
return {
error: event.error,
data: undefined,
status: 'rejected'
};
default:
return state;
}
},
initialState: initialState,
start: function (_a) {
var self = _a.self;
promiseFn().then(function (data) {
self.send({
type: 'fulfill',
data: data
});
}, function (reason) {
self.send({
type: 'reject',
error: reason
});
});
return initialState;
}
};
}
function spawnBehavior(behavior, options) {

@@ -70,2 +136,4 @@ if (options === void 0) {

exports.fromPromise = fromPromise;
exports.fromReducer = fromReducer;
exports.spawnBehavior = spawnBehavior;

@@ -1,11 +0,10 @@

import { Interpreter } from '.';
import { AnyInterpreter } from './types';
declare type ServiceListener = (service: AnyInterpreter) => void;
export interface XStateDevInterface {
register: (service: Interpreter<any>) => void;
unregister: (service: Interpreter<any>) => void;
register: (service: AnyInterpreter) => void;
unregister: (service: AnyInterpreter) => void;
onRegister: (listener: ServiceListener) => {
unsubscribe: () => void;
};
services: Set<Interpreter<any>>;
services: Set<AnyInterpreter>;
}

@@ -12,0 +11,0 @@ export declare function getGlobal(): typeof globalThis | undefined;

@@ -5,3 +5,4 @@ 'use strict';

// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
var environment = require('./environment.js');
function getGlobal() {

@@ -24,3 +25,5 @@ if (typeof globalThis !== 'undefined') {

return undefined;
if (!environment.IS_PRODUCTION) {
console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
}
}

@@ -27,0 +30,0 @@

@@ -1,31 +0,22 @@

import { matchesState } from './utils';
import * as actions from './actions';
import { Actor, toActorRef } from './Actor';
import { interpret, Interpreter, InterpreterStatus, spawn } from './interpreter';
import { createMachine, Machine } from './Machine';
import { mapState } from './mapState';
import { matchState } from './match';
import { createSchema, t } from './schema';
import { State } from './State';
import { StateNode } from './StateNode';
import { State } from './State';
import { Machine, createMachine } from './Machine';
import { Actor } from './Actor';
import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
import { interpret, Interpreter, spawn, InterpreterStatus } from './interpreter';
import { matchState } from './match';
import { createSchema } from './schema';
declare const actions: {
raise: typeof raise;
send: typeof send;
sendParent: typeof sendParent;
sendUpdate: typeof sendUpdate;
log: typeof log;
cancel: (sendId: string | number) => import("./types").CancelAction;
start: typeof start;
stop: typeof stop;
assign: <TContext, TEvent extends import("./types").EventObject = import("./types").EventObject>(assignment: import("./types").Assigner<TContext, TEvent> | import("./types").PropertyAssigner<TContext, TEvent>) => import("./types").AssignAction<TContext, TEvent>;
after: typeof after;
done: typeof done;
respond: typeof respond;
forwardTo: typeof forwardTo;
escalate: typeof escalate;
choose: typeof choose;
pure: typeof pure;
};
export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema };
export { spawnBehavior } from './behaviors';
export { XStateDevInterface } from './devTools';
export * from './typegenTypes';
export * from './types';
export { matchesState, toEventObject, toObserver, toSCXMLEvent } from './utils';
export { Actor, toActorRef, Machine, StateNode, State, mapState, actions, assign, cancel, send, sendTo, sendParent, sendUpdate, raise, log, pure, choose, stop, forwardTo, interpret, Interpreter, InterpreterStatus, matchState, spawn, doneInvoke, createMachine, createSchema, t };
declare const assign: <TContext, TExpressionEvent extends import("./types").EventObject = import("./types").EventObject, TEvent extends import("./types").EventObject = TExpressionEvent>(assignment: import("./types").Assigner<import("./types").LowInfer<TContext>, TExpressionEvent> | import("./types").PropertyAssigner<import("./types").LowInfer<TContext>, TExpressionEvent>) => import("./types").AssignAction<TContext, TExpressionEvent, TEvent>, cancel: <TContext, TExpressionEvent extends import("./types").EventObject, TEvent extends import("./types").EventObject>(sendId: string | number) => import("./types").CancelAction<TContext, TExpressionEvent, TEvent>, send: typeof actions.send, sendTo: typeof actions.sendTo, sendParent: typeof actions.sendParent, sendUpdate: typeof actions.sendUpdate, forwardTo: typeof actions.forwardTo, doneInvoke: typeof actions.doneInvoke, raise: typeof actions.raise, log: typeof actions.log, pure: typeof actions.pure, choose: typeof actions.choose, stop: typeof actions.stop;
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
//# sourceMappingURL=index.d.ts.map

@@ -5,67 +5,71 @@ 'use strict';

var utils = require('./utils.js');
var actions = require('./actions.js');
var Actor = require('./Actor.js');
var interpreter = require('./interpreter.js');
var Machine = require('./Machine.js');
var mapState = require('./mapState.js');
var types = require('./types.js');
var actions$1 = require('./actions.js');
var match = require('./match.js');
var schema = require('./schema.js');
var State = require('./State.js');
var StateNode = require('./StateNode.js');
var Machine = require('./Machine.js');
var interpreter = require('./interpreter.js');
var match = require('./match.js');
var schema = require('./schema.js');
var behaviors = require('./behaviors.js');
var types = require('./types.js');
var utils = require('./utils.js');
var actions = {
raise: actions$1.raise,
send: actions$1.send,
sendParent: actions$1.sendParent,
sendUpdate: actions$1.sendUpdate,
log: actions$1.log,
cancel: actions$1.cancel,
start: actions$1.start,
stop: actions$1.stop,
assign: actions$1.assign,
after: actions$1.after,
done: actions$1.done,
respond: actions$1.respond,
forwardTo: actions$1.forwardTo,
escalate: actions$1.escalate,
choose: actions$1.choose,
pure: actions$1.pure
};
var assign = actions.assign,
cancel = actions.cancel,
send = actions.send,
sendTo = actions.sendTo,
sendParent = actions.sendParent,
sendUpdate = actions.sendUpdate,
forwardTo = actions.forwardTo,
doneInvoke = actions.doneInvoke,
raise = actions.raise,
log = actions.log,
pure = actions.pure,
choose = actions.choose,
stop = actions.stop;
exports.matchesState = utils.matchesState;
exports.mapState = mapState.mapState;
Object.defineProperty(exports, 'ActionTypes', {
enumerable: true,
get: function () {
return types.ActionTypes;
}
});
Object.defineProperty(exports, 'SpecialTargets', {
enumerable: true,
get: function () {
return types.SpecialTargets;
}
});
exports.assign = actions$1.assign;
exports.doneInvoke = actions$1.doneInvoke;
exports.forwardTo = actions$1.forwardTo;
exports.send = actions$1.send;
exports.sendParent = actions$1.sendParent;
exports.sendUpdate = actions$1.sendUpdate;
exports.State = State.State;
exports.StateNode = StateNode.StateNode;
exports.Machine = Machine.Machine;
exports.createMachine = Machine.createMachine;
exports.actions = actions;
exports.toActorRef = Actor.toActorRef;
exports.Interpreter = interpreter.Interpreter;
Object.defineProperty(exports, 'InterpreterStatus', {
enumerable: true,
get: function () {
return interpreter.InterpreterStatus;
}
get: function () { return interpreter.InterpreterStatus; }
});
exports.interpret = interpreter.interpret;
exports.spawn = interpreter.spawn;
exports.Machine = Machine.Machine;
exports.createMachine = Machine.createMachine;
exports.mapState = mapState.mapState;
exports.matchState = match.matchState;
exports.createSchema = schema.createSchema;
exports.actions = actions;
exports.t = schema.t;
exports.State = State.State;
exports.StateNode = StateNode.StateNode;
exports.spawnBehavior = behaviors.spawnBehavior;
Object.defineProperty(exports, 'ActionTypes', {
enumerable: true,
get: function () { return types.ActionTypes; }
});
Object.defineProperty(exports, 'SpecialTargets', {
enumerable: true,
get: function () { return types.SpecialTargets; }
});
exports.matchesState = utils.matchesState;
exports.toEventObject = utils.toEventObject;
exports.toObserver = utils.toObserver;
exports.toSCXMLEvent = utils.toSCXMLEvent;
exports.assign = assign;
exports.cancel = cancel;
exports.choose = choose;
exports.doneInvoke = doneInvoke;
exports.forwardTo = forwardTo;
exports.log = log;
exports.pure = pure;
exports.raise = raise;
exports.send = send;
exports.sendParent = sendParent;
exports.sendTo = sendTo;
exports.sendUpdate = sendUpdate;
exports.stop = stop;

@@ -1,7 +0,9 @@

import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription, StateConfig, InteropSubscribable } from './types';
import { State } from './State';
import { symbolObservable } from './utils';
import { AreAllImplementationsAssumedToBeProvided, MissingImplementationsError, TypegenDisabled } from './typegenTypes';
export declare type StateListener<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> = (state: State<TContext, TEvent, TStateSchema, TTypestate>, event: TEvent) => void;
}, TResolvedTypesMeta = TypegenDisabled> = (state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, event: TEvent) => void;
export declare type ContextListener<TContext = DefaultContext> = (context: TContext, prevContext: TContext | undefined) => void;

@@ -24,12 +26,7 @@ export declare type EventListener<TEvent extends EventObject = EventObject> = (event: TEvent) => void;

}
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate>> {
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
}, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>> {
machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>;
/**

@@ -41,3 +38,9 @@ * The default interpreter options:

*/
static defaultOptions: InterpreterOptions;
static defaultOptions: {
execute: boolean;
deferEvents: boolean;
clock: Clock;
logger: any;
devTools: boolean;
};
/**

@@ -75,3 +78,5 @@ * The current state of the interpreted machine.

private forwardTo;
private _outgoingQueue;
private devTools?;
private _doneEvent?;
/**

@@ -83,5 +88,8 @@ * Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.

*/
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
get state(): State<TContext, TEvent, TStateSchema, TTypestate>;
constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>, options?: InterpreterOptions);
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
/**
* @deprecated Use `.getSnapshot()` instead.
*/
get state(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
static interpret: typeof interpret;

@@ -94,7 +102,7 @@ /**

*/
execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
execute(state: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>, actionsConfig?: MachineOptions<TContext, TEvent>['actions']): void;
private update;
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this;
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription;
onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>): this;
subscribe(observer: Partial<Observer<State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>>>): Subscription;
subscribe(nextListener?: (state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
/**

@@ -104,3 +112,3 @@ * Adds an event listener that is notified whenever an event is sent to the running interpreter.

*/
onEvent(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onEvent(listener: EventListener): this;
/**

@@ -110,3 +118,3 @@ * Adds an event listener that is notified whenever a `send` event occurs.

*/
onSend(listener: EventListener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onSend(listener: EventListener): this;
/**

@@ -116,3 +124,3 @@ * Adds a context listener that is notified whenever the state context changes.

*/
onChange(listener: ContextListener<TContext>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onChange(listener: ContextListener<TContext>): this;
/**

@@ -122,3 +130,3 @@ * Adds a listener that is notified when the machine is stopped.

*/
onStop(listener: Listener): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onStop(listener: Listener): this;
/**

@@ -128,3 +136,3 @@ * Adds a state listener that is notified when the statechart has reached its final state.

*/
onDone(listener: EventListener<DoneEvent>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
onDone(listener: EventListener<DoneEvent>): this;
/**

@@ -134,7 +142,7 @@ * Removes a listener.

*/
off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
off(listener: (...args: any[]) => void): this;
/**
* Alias for Interpreter.prototype.start
*/
init: (initialState?: StateValue | State<TContext, TEvent, TStateSchema, TTypestate> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
init: (initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue) => this;
/**

@@ -144,3 +152,5 @@ * Starts the interpreter from the given state, or the initial state.

*/
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> | StateConfig<TContext, TEvent> | StateValue): this;
private _stopChildren;
private _stop;
/**

@@ -151,3 +161,3 @@ * Stops the interpreter and unsubscribe all listeners.

*/
stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
stop(): this;
/**

@@ -162,3 +172,3 @@ * Sends an event to the running interpreter to trigger a transition.

*/
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData | undefined) => State<TContext, TEvent, TStateSchema, TTypestate>;
send: (event: SingleOrArray<Event<TEvent>> | SCXML.Event<TEvent>, payload?: EventData) => State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private batch;

@@ -172,2 +182,3 @@ /**

private sendTo;
private _nextState;
/**

@@ -180,6 +191,7 @@ * Returns the next state given the interpreter's current state and the event.

*/
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>;
nextState(event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private forward;
private defer;
private cancel;
private _exec;
private exec;

@@ -189,3 +201,3 @@ private removeChild;

spawn(entity: Spawnable, name: string, options?: SpawnOptions): ActorRef<any>;
spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
spawnMachine<TChildContext, TChildStateSchema extends StateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
id?: string;

@@ -206,7 +218,7 @@ autoForward?: boolean;

};
[Symbol.observable](): Subscribable<State<TContext, TEvent, TStateSchema, TTypestate>>;
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate>;
[Symbol.observable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
}
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE, any, any, any, any>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE, any, any, any, any>>;
export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;

@@ -222,4 +234,4 @@ /**

context: TContext;
}>(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
}, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta> : MissingImplementationsError<TResolvedTypesMeta>, options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
export {};
//# sourceMappingURL=interpreter.d.ts.map

@@ -6,14 +6,13 @@ 'use strict';

var _tslib = require('./_virtual/_tslib.js');
var environment = require('./environment.js');
var utils = require('./utils.js');
var types = require('./types.js');
var stateUtils = require('./stateUtils.js');
var State = require('./State.js');
var actionTypes = require('./actionTypes.js');
var actions = require('./actions.js');
var State = require('./State.js');
var serviceScope = require('./serviceScope.js');
var environment = require('./environment.js');
var utils = require('./utils.js');
var scheduler = require('./scheduler.js');
var Actor = require('./Actor.js');
var scheduler = require('./scheduler.js');
var registry = require('./registry.js');
var devTools = require('./devTools.js');
var serviceScope = require('./serviceScope.js');
var behaviors = require('./behaviors.js');

@@ -25,2 +24,3 @@

};
exports.InterpreterStatus = void 0;

@@ -45,4 +45,2 @@ (function (InterpreterStatus) {

function Interpreter(machine, options) {
var _this = this;
if (options === void 0) {

@@ -52,4 +50,5 @@ options = Interpreter.defaultOptions;

var _this = this;
this.machine = machine;
this.scheduler = new scheduler.Scheduler();
this.delayedEventsMap = {};

@@ -70,2 +69,3 @@ this.listeners = new Set();

this.forwardTo = new Set();
this._outgoingQueue = [];
/**

@@ -113,3 +113,3 @@ * Alias for Interpreter.prototype.start

var nextState = _this.nextState(_event);
var nextState = _this._nextState(_event);

@@ -123,5 +123,5 @@ _this.update(nextState, _event);

this.sendTo = function (event, to) {
this.sendTo = function (event, to, immediate) {
var isParent = _this.parent && (to === types.SpecialTargets.Parent || _this.parent.id === to);
var target = isParent ? _this.parent : utils.isString(to) ? _this.children.get(to) || registry.registry.get(to) : utils.isActor(to) ? to : undefined;
var target = isParent ? _this.parent : utils.isString(to) ? to === types.SpecialTargets.Internal ? _this : _this.children.get(to) || registry.registry.get(to) : utils.isActor(to) ? to : undefined;

@@ -142,13 +142,193 @@ if (!target) {

if ('machine' in target) {
// Send SCXML events to machines
target.send(_tslib.__assign(_tslib.__assign({}, event), {
name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
origin: _this.sessionId
}));
// perhaps those events should be rejected in the parent
// but atm it doesn't have easy access to all of the information that is required to do it reliably
if (_this.status !== exports.InterpreterStatus.Stopped || _this.parent !== target || // we need to send events to the parent from exit handlers of a machine that reached its final state
_this.state.done) {
// Send SCXML events to machines
var scxmlEvent = _tslib.__assign(_tslib.__assign({}, event), {
name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
origin: _this.sessionId
});
if (!immediate && _this.machine.config.predictableActionArguments) {
_this._outgoingQueue.push([target, scxmlEvent]);
} else {
target.send(scxmlEvent);
}
}
} else {
// Send normal events to other targets
target.send(event.data);
if (!immediate && _this.machine.config.predictableActionArguments) {
_this._outgoingQueue.push([target, event.data]);
} else {
target.send(event.data);
}
}
};
this._exec = function (action, context, _event, actionFunctionMap) {
if (actionFunctionMap === void 0) {
actionFunctionMap = _this.machine.options.actions;
}
var actionOrExec = action.exec || actions.getActionFunction(action.type, actionFunctionMap);
var exec = utils.isFunction(actionOrExec) ? actionOrExec : actionOrExec ? actionOrExec.exec : action.exec;
if (exec) {
try {
return exec(context, _event.data, !_this.machine.config.predictableActionArguments ? {
action: action,
state: _this.state,
_event: _event
} : {
action: action,
_event: _event
});
} catch (err) {
if (_this.parent) {
_this.parent.send({
type: 'xstate.error',
data: err
});
}
throw err;
}
}
switch (action.type) {
case actionTypes.raise:
{
// if raise action reached the interpreter then it's a delayed one
var sendAction_1 = action;
_this.defer(sendAction_1);
break;
}
case actionTypes.send:
var sendAction = action;
if (typeof sendAction.delay === 'number') {
_this.defer(sendAction);
return;
} else {
if (sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to, _event === actions.initEvent);
} else {
_this.send(sendAction._event);
}
}
break;
case actionTypes.cancel:
_this.cancel(action.sendId);
break;
case actionTypes.start:
{
if (_this.status !== exports.InterpreterStatus.Running) {
return;
}
var activity = action.activity; // If the activity will be stopped right after it's started
// (such as in transient states)
// don't bother starting the activity.
if ( // in v4 with `predictableActionArguments` invokes are called eagerly when the `this.state` still points to the previous state
!_this.machine.config.predictableActionArguments && !_this.state.activities[activity.id || activity.type]) {
break;
} // Invoked services
if (activity.type === types.ActionTypes.Invoke) {
var invokeSource = utils.toInvokeSource(activity.src);
var serviceCreator = _this.machine.options.services ? _this.machine.options.services[invokeSource.type] : undefined;
var id = activity.id,
data = activity.data;
if (!environment.IS_PRODUCTION) {
utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(_this.machine.id, "'). ") + "Please use `autoForward` instead.");
}
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
if (!serviceCreator) {
// tslint:disable-next-line:no-console
if (!environment.IS_PRODUCTION) {
utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(_this.machine.id, "'."));
}
return;
}
var resolvedData = data ? utils.mapContext(data, context, _event) : undefined;
if (typeof serviceCreator === 'string') {
// TODO: warn
return;
}
var source = utils.isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
data: resolvedData,
src: invokeSource,
meta: activity.meta
}) : serviceCreator;
if (!source) {
// TODO: warn?
return;
}
var options = void 0;
if (utils.isMachine(source)) {
source = resolvedData ? source.withContext(resolvedData) : source;
options = {
autoForward: autoForward
};
}
_this.spawn(source, id, options);
} else {
_this.spawnActivity(activity);
}
break;
}
case actionTypes.stop:
{
_this.stopChild(action.activity.id);
break;
}
case actionTypes.log:
var _a = action,
label = _a.label,
value = _a.value;
if (label) {
_this.logger(label, value);
} else {
_this.logger(value);
}
break;
default:
if (!environment.IS_PRODUCTION) {
utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
}
break;
}
};
var resolvedOptions = _tslib.__assign(_tslib.__assign({}, Interpreter.defaultOptions), options);

@@ -189,2 +369,5 @@

Object.defineProperty(Interpreter.prototype, "state", {
/**
* @deprecated Use `.getSnapshot()` instead.
*/
get: function () {

@@ -238,4 +421,12 @@ if (!environment.IS_PRODUCTION) {

if (this.options.execute) {
if ((!this.machine.config.predictableActionArguments || // this is currently required to execute initial actions as the `initialState` gets cached
// we can't just recompute it (and execute actions while doing so) because we try to preserve identity of actors created within initial assigns
_event === actions.initEvent) && this.options.execute) {
this.execute(this.state);
} else {
var item = void 0;
while (item = this._outgoingQueue.shift()) {
item[0].send(item[1]);
}
} // Update children

@@ -306,5 +497,3 @@

var isDone = stateUtils.isInFinalState(state.configuration || [], this.machine);
if (this.state.configuration && isDone) {
if (this.state.done) {
// get final child state node

@@ -315,2 +504,3 @@ var finalChildStateNode = state.configuration.find(function (sn) {

var doneData = finalChildStateNode && finalChildStateNode.doneData ? utils.mapContext(finalChildStateNode.doneData, state.context, _event) : undefined;
this._doneEvent = actions.doneInvoke(this.id, doneData);

@@ -320,3 +510,3 @@ try {

var listener = _m.value;
listener(actions.doneInvoke(this.id, doneData));
listener(this._doneEvent);
}

@@ -335,3 +525,7 @@ } catch (e_5_1) {

this.stop();
this._stop();
this._stopChildren();
registry.registry.free(this.sessionId);
}

@@ -361,34 +555,31 @@ };

if (!nextListenerOrObserver) {
return {
unsubscribe: function () {
return void 0;
}
};
var observer = utils.toObserver(nextListenerOrObserver, _, completeListener);
this.listeners.add(observer.next); // Send current state to listener
if (this.status !== exports.InterpreterStatus.NotStarted) {
observer.next(this.state);
}
var listener;
var resolvedCompleteListener = completeListener;
var completeOnce = function () {
_this.doneListeners.delete(completeOnce);
if (typeof nextListenerOrObserver === 'function') {
listener = nextListenerOrObserver;
} else {
listener = nextListenerOrObserver.next.bind(nextListenerOrObserver);
resolvedCompleteListener = nextListenerOrObserver.complete.bind(nextListenerOrObserver);
}
_this.stopListeners.delete(completeOnce);
this.listeners.add(listener); // Send current state to listener
observer.complete();
};
if (this.status === exports.InterpreterStatus.Running) {
listener(this.state);
if (this.status === exports.InterpreterStatus.Stopped) {
observer.complete();
} else {
this.onDone(completeOnce);
this.onStop(completeOnce);
}
if (resolvedCompleteListener) {
this.onDone(resolvedCompleteListener);
}
return {
unsubscribe: function () {
listener && _this.listeners.delete(listener);
resolvedCompleteListener && _this.doneListeners.delete(resolvedCompleteListener);
_this.listeners.delete(observer.next);
_this.doneListeners.delete(completeOnce);
_this.stopListeners.delete(completeOnce);
}

@@ -444,3 +635,8 @@ };

Interpreter.prototype.onDone = function (listener) {
this.doneListeners.add(listener);
if (this.status === exports.InterpreterStatus.Stopped && this._doneEvent) {
listener(this._doneEvent);
} else {
this.doneListeners.add(listener);
}
return this;

@@ -475,4 +671,10 @@ };

return this;
}
} // yes, it's a hack but we need the related cache to be populated for some things to work (like delayed transitions)
// this is usually called by `machine.getInitialState` but if we rehydrate from a state we might bypass this call
// we also don't want to call this method here as it resolves the full initial state which might involve calling assign actions
// and that could potentially lead to some unwanted side-effects (even such as creating some rogue actors)
this.machine._init();
registry.registry.register(this.sessionId, this);

@@ -482,3 +684,3 @@ this.initialized = true;

var resolvedState = initialState === undefined ? this.initialState : serviceScope.provide(this, function () {
return State.isState(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.State.from(initialState, _this.machine.context));
return State.isStateConfig(initialState) ? _this.machine.resolveState(initialState) : _this.machine.resolveState(State.State.from(initialState, _this.machine.context));
});

@@ -495,14 +697,16 @@

};
/**
* Stops the interpreter and unsubscribe all listeners.
*
* This will also notify the `onStop` listeners.
*/
Interpreter.prototype._stopChildren = function () {
// TODO: think about converting those to actions
this.children.forEach(function (child) {
if (utils.isFunction(child.stop)) {
child.stop();
}
});
this.children.clear();
};
Interpreter.prototype.stop = function () {
Interpreter.prototype._stop = function () {
var e_6, _a, e_7, _b, e_8, _c, e_9, _d, e_10, _e;
var _this = this;
try {

@@ -583,33 +787,10 @@ for (var _f = _tslib.__values(this.listeners), _g = _f.next(); !_g.done; _g = _f.next()) {

this.state.configuration.forEach(function (stateNode) {
var e_11, _a;
this.initialized = false;
this.status = exports.InterpreterStatus.Stopped;
this._initialState = undefined;
try {
for (var _b = _tslib.__values(stateNode.definition.exit), _c = _b.next(); !_c.done; _c = _b.next()) {
var action = _c.value;
_this.exec(action, _this.state);
}
} catch (e_11_1) {
e_11 = {
error: e_11_1
};
} finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
} finally {
if (e_11) throw e_11.error;
}
}
}); // Stop all children
this.children.forEach(function (child) {
if (utils.isFunction(child.stop)) {
child.stop();
}
});
try {
// Cancel all delayed events
for (var _p = _tslib.__values(utils.keys(this.delayedEventsMap)), _q = _p.next(); !_q.done; _q = _p.next()) {
// we are going to stop within the current sync frame
// so we can safely just cancel this here as nothing async should be fired anyway
for (var _p = _tslib.__values(Object.keys(this.delayedEventsMap)), _q = _p.next(); !_q.done; _q = _p.next()) {
var key = _q.value;

@@ -628,8 +809,76 @@ this.clock.clearTimeout(this.delayedEventsMap[key]);

}
}
} // clear everything that might be enqueued
this.scheduler.clear();
this.initialized = false;
this.status = exports.InterpreterStatus.Stopped;
registry.registry.free(this.sessionId);
this.scheduler = new scheduler.Scheduler({
deferEvents: this.options.deferEvents
});
};
/**
* Stops the interpreter and unsubscribe all listeners.
*
* This will also notify the `onStop` listeners.
*/
Interpreter.prototype.stop = function () {
// TODO: add warning for stopping non-root interpreters
var _this = this; // grab the current scheduler as it will be replaced in _stop
var scheduler = this.scheduler;
this._stop(); // let what is currently processed to be finished
scheduler.schedule(function () {
// it feels weird to handle this here but we need to handle this even slightly "out of band"
var _event = utils.toSCXMLEvent({
type: 'xstate.stop'
});
var nextState = serviceScope.provide(_this, function () {
var exitActions = utils.flatten(_tslib.__spreadArray([], _tslib.__read(_this.state.configuration), false).sort(function (a, b) {
return b.order - a.order;
}).map(function (stateNode) {
return actions.toActionObjects(stateNode.onExit, _this.machine.options.actions);
}));
var _a = _tslib.__read(actions.resolveActions(_this.machine, _this.state, _this.state.context, _event, [{
type: 'exit',
actions: exitActions
}], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
resolvedActions = _a[0],
updatedContext = _a[1];
var newState = new State.State({
value: _this.state.value,
context: updatedContext,
_event: _event,
_sessionid: _this.sessionId,
historyValue: undefined,
history: _this.state,
actions: resolvedActions.filter(function (action) {
return !utils.isRaisableAction(action);
}),
activities: {},
events: [],
configuration: [],
transitions: [],
children: {},
done: _this.state.done,
tags: _this.state.tags,
machine: _this.machine
});
newState.changed = true;
return newState;
});
_this.update(nextState, _event);
_this._stopChildren();
registry.registry.free(_this.sessionId);
});
return this;

@@ -651,4 +900,9 @@ };

if (!events.length) {
return;
}
var exec = !!this.machine.config.predictableActionArguments && this._exec;
this.scheduler.schedule(function () {
var e_12, _a;
var e_11, _a;

@@ -665,5 +919,5 @@ var nextState = _this.state;

nextState = serviceScope.provide(_this, function () {
return _this.machine.transition(nextState, _event);
return _this.machine.transition(nextState, _event, undefined, exec || undefined);
});
batchedActions.push.apply(batchedActions, _tslib.__spreadArray([], _tslib.__read(nextState.actions.map(function (a) {
batchedActions.push.apply(batchedActions, _tslib.__spreadArray([], _tslib.__read(_this.machine.config.predictableActionArguments ? nextState.actions : nextState.actions.map(function (a) {
return State.bindActionToState(a, nextState);

@@ -680,5 +934,5 @@ })), false));

}
} catch (e_12_1) {
e_12 = {
error: e_12_1
} catch (e_11_1) {
e_11 = {
error: e_11_1
};

@@ -689,3 +943,3 @@ } finally {

} finally {
if (e_12) throw e_12.error;
if (e_11) throw e_11.error;
}

@@ -710,14 +964,10 @@ }

};
/**
* Returns the next state given the interpreter's current state and the event.
*
* This is a pure method that does _not_ update the interpreter's state.
*
* @param event The event to determine the next state
*/
Interpreter.prototype.nextState = function (event) {
Interpreter.prototype._nextState = function (event, exec) {
var _this = this;
if (exec === void 0) {
exec = !!this.machine.config.predictableActionArguments && this._exec;
}
var _event = utils.toSCXMLEvent(event);

@@ -732,9 +982,21 @@

var nextState = serviceScope.provide(this, function () {
return _this.machine.transition(_this.state, _event);
return _this.machine.transition(_this.state, _event, undefined, exec || undefined);
});
return nextState;
};
/**
* Returns the next state given the interpreter's current state and the event.
*
* This is a pure method that does _not_ update the interpreter's state.
*
* @param event The event to determine the next state
*/
Interpreter.prototype.nextState = function (event) {
return this._nextState(event, false);
};
Interpreter.prototype.forward = function (event) {
var e_13, _a;
var e_12, _a;

@@ -752,5 +1014,5 @@ try {

}
} catch (e_13_1) {
e_13 = {
error: e_13_1
} catch (e_12_1) {
e_12 = {
error: e_12_1
};

@@ -761,3 +1023,3 @@ } finally {

} finally {
if (e_13) throw e_13.error;
if (e_12) throw e_12.error;
}

@@ -770,5 +1032,5 @@ }

this.delayedEventsMap[sendAction.id] = this.clock.setTimeout(function () {
if (sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to);
var timerId = this.clock.setTimeout(function () {
if ('to' in sendAction && sendAction.to) {
_this.sendTo(sendAction._event, sendAction.to, true);
} else {

@@ -778,2 +1040,6 @@ _this.send(sendAction._event);

}, sendAction.delay);
if (sendAction.id) {
this.delayedEventsMap[sendAction.id] = timerId;
}
};

@@ -791,146 +1057,3 @@

var context = state.context,
_event = state._event;
var actionOrExec = action.exec || actions.getActionFunction(action.type, actionFunctionMap);
var exec = utils.isFunction(actionOrExec) ? actionOrExec : actionOrExec ? actionOrExec.exec : action.exec;
if (exec) {
try {
return exec(context, _event.data, {
action: action,
state: this.state,
_event: _event
});
} catch (err) {
if (this.parent) {
this.parent.send({
type: 'xstate.error',
data: err
});
}
throw err;
}
}
switch (action.type) {
case actionTypes.send:
var sendAction = action;
if (typeof sendAction.delay === 'number') {
this.defer(sendAction);
return;
} else {
if (sendAction.to) {
this.sendTo(sendAction._event, sendAction.to);
} else {
this.send(sendAction._event);
}
}
break;
case actionTypes.cancel:
this.cancel(action.sendId);
break;
case actionTypes.start:
{
if (this.status !== exports.InterpreterStatus.Running) {
return;
}
var activity = action.activity; // If the activity will be stopped right after it's started
// (such as in transient states)
// don't bother starting the activity.
if (!this.state.activities[activity.id || activity.type]) {
break;
} // Invoked services
if (activity.type === types.ActionTypes.Invoke) {
var invokeSource = utils.toInvokeSource(activity.src);
var serviceCreator = this.machine.options.services ? this.machine.options.services[invokeSource.type] : undefined;
var id = activity.id,
data = activity.data;
if (!environment.IS_PRODUCTION) {
utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
"`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
}
var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
if (!serviceCreator) {
// tslint:disable-next-line:no-console
if (!environment.IS_PRODUCTION) {
utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
}
return;
}
var resolvedData = data ? utils.mapContext(data, context, _event) : undefined;
if (typeof serviceCreator === 'string') {
// TODO: warn
return;
}
var source = utils.isFunction(serviceCreator) ? serviceCreator(context, _event.data, {
data: resolvedData,
src: invokeSource,
meta: activity.meta
}) : serviceCreator;
if (!source) {
// TODO: warn?
return;
}
var options = void 0;
if (utils.isMachine(source)) {
source = resolvedData ? source.withContext(resolvedData) : source;
options = {
autoForward: autoForward
};
}
this.spawn(source, id, options);
} else {
this.spawnActivity(activity);
}
break;
}
case actionTypes.stop:
{
this.stopChild(action.activity.id);
break;
}
case actionTypes.log:
var label = action.label,
value = action.value;
if (label) {
this.logger(label, value);
} else {
this.logger(value);
}
break;
default:
if (!environment.IS_PRODUCTION) {
utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
}
break;
}
return undefined;
this._exec(action, state.context, state._event, actionFunctionMap);
};

@@ -963,2 +1086,6 @@

Interpreter.prototype.spawn = function (entity, name, options) {
if (this.status !== exports.InterpreterStatus.Running) {
return Actor.createDeferredActor(entity, name);
}
if (utils.isPromiseLike(entity)) {

@@ -1033,2 +1160,4 @@ return this.spawnPromise(Promise.resolve(entity), name);

Interpreter.prototype.spawnPromise = function (promise, id) {
var _a;
var _this = this;

@@ -1076,3 +1205,3 @@

});
var actor = {
var actor = (_a = {
id: id,

@@ -1121,3 +1250,5 @@ send: function () {

}
};
}, _a[utils.symbolObservable] = function () {
return this;
}, _a);
this.children.set(id, actor);

@@ -1128,2 +1259,4 @@ return actor;

Interpreter.prototype.spawnCallback = function (callback, id) {
var _a;
var _this = this;

@@ -1167,3 +1300,3 @@

var actor = {
var actor = (_a = {
id: id,

@@ -1176,6 +1309,7 @@ send: function (event) {

subscribe: function (next) {
listeners.add(next);
var observer = utils.toObserver(next);
listeners.add(observer.next);
return {
unsubscribe: function () {
listeners.delete(next);
listeners.delete(observer.next);
}

@@ -1199,3 +1333,5 @@ };

}
};
}, _a[utils.symbolObservable] = function () {
return this;
}, _a);
this.children.set(id, actor);

@@ -1206,2 +1342,4 @@ return actor;

Interpreter.prototype.spawnObservable = function (source, id) {
var _a;
var _this = this;

@@ -1229,3 +1367,3 @@

});
var actor = {
var actor = (_a = {
id: id,

@@ -1249,3 +1387,5 @@ send: function () {

}
};
}, _a[utils.symbolObservable] = function () {
return this;
}, _a);
this.children.set(id, actor);

@@ -1278,3 +1418,5 @@ return actor;

Interpreter.prototype.spawnEffect = function (id, dispose) {
this.children.set(id, {
var _a;
this.children.set(id, (_a = {
id: id,

@@ -1300,3 +1442,5 @@ send: function () {

}
});
}, _a[utils.symbolObservable] = function () {
return this;
}, _a));
};

@@ -1342,6 +1486,4 @@

return this;
}; // this gets stripped by Babel to avoid having "undefined" property in environments without this non-standard Symbol
// it has to be here to be included in the generated .d.ts
};
Interpreter.prototype.getSnapshot = function () {

@@ -1362,19 +1504,16 @@ if (this.status === exports.InterpreterStatus.NotStarted) {

Interpreter.defaultOptions = /*#__PURE__*/function (global) {
return {
execute: true,
deferEvents: true,
clock: {
setTimeout: function (fn, ms) {
return setTimeout(fn, ms);
},
clearTimeout: function (id) {
return clearTimeout(id);
}
Interpreter.defaultOptions = {
execute: true,
deferEvents: true,
clock: {
setTimeout: function (fn, ms) {
return setTimeout(fn, ms);
},
logger: global.console.log.bind(console),
devTools: false
};
}(typeof self !== 'undefined' ? self : global);
clearTimeout: function (id) {
return clearTimeout(id);
}
},
logger: /*#__PURE__*/console.log.bind(console),
devTools: false
};
Interpreter.interpret = interpret;

@@ -1381,0 +1520,0 @@ return Interpreter;

@@ -6,6 +6,6 @@ 'use strict';

var _tslib = require('./_virtual/_tslib.js');
require('./environment.js');
require('./utils.js');
require('./types.js');
var actionTypes = require('./actionTypes.js');
require('./utils.js');
require('./environment.js');

@@ -33,5 +33,5 @@ function toInvokeSource(src) {

toJSON: function () {
var onDone = invokeConfig.onDone,
onError = invokeConfig.onError,
invokeDef = _tslib.__rest(invokeConfig, ["onDone", "onError"]);
invokeConfig.onDone;
invokeConfig.onError;
var invokeDef = _tslib.__rest(invokeConfig, ["onDone", "onError"]);

@@ -38,0 +38,0 @@ return _tslib.__assign(_tslib.__assign({}, invokeDef), {

@@ -1,85 +0,94 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonify = exports.parse = exports.stringify = exports.machineToJSON = exports.stringifyFunction = void 0;
var utils_1 = require("./utils");
// tslint:disable-next-line:ban-types
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var utils = require('./utils.js');
function stringifyFunction(fn) {
return {
$function: fn.toString()
};
return {
$function: fn.toString()
};
}
exports.stringifyFunction = stringifyFunction;
function getStateNodeId(stateNode) {
return "#".concat(stateNode.id);
}
// derive config from machine
return "#".concat(stateNode.id);
} // derive config from machine
function machineToJSON(stateNode) {
var config = {
type: stateNode.type,
initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
id: stateNode.id,
key: stateNode.key,
entry: stateNode.onEntry,
exit: stateNode.onExit,
on: (0, utils_1.mapValues)(stateNode.on, function (transition) {
return transition.map(function (t) {
return {
target: t.target ? t.target.map(getStateNodeId) : [],
source: getStateNodeId(t.source),
actions: t.actions,
cond: t.cond,
eventType: t.eventType
};
});
}),
invoke: stateNode.invoke,
states: {}
};
Object.values(stateNode.states).forEach(function (sn) {
config.states[sn.key] = machineToJSON(sn);
});
return config;
var config = {
type: stateNode.type,
initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
id: stateNode.id,
key: stateNode.key,
entry: stateNode.onEntry,
exit: stateNode.onExit,
on: utils.mapValues(stateNode.on, function (transition) {
return transition.map(function (t) {
return {
target: t.target ? t.target.map(getStateNodeId) : [],
source: getStateNodeId(t.source),
actions: t.actions,
cond: t.cond,
eventType: t.eventType
};
});
}),
invoke: stateNode.invoke,
states: {}
};
Object.values(stateNode.states).forEach(function (sn) {
config.states[sn.key] = machineToJSON(sn);
});
return config;
}
exports.machineToJSON = machineToJSON;
function stringify(machine) {
return JSON.stringify(machineToJSON(machine), function (_, value) {
if ((0, utils_1.isFunction)(value)) {
return { $function: value.toString() };
}
return value;
});
return JSON.stringify(machineToJSON(machine), function (_, value) {
if (utils.isFunction(value)) {
return {
$function: value.toString()
};
}
return value;
});
}
exports.stringify = stringify;
function parse(machineString) {
var config = JSON.parse(machineString, function (_, value) {
if (typeof value === 'object' && '$function' in value) {
return new Function(value.value);
}
return value;
});
return config;
var config = JSON.parse(machineString, function (_, value) {
if (typeof value === 'object' && '$function' in value) {
return new Function(value.value);
}
return value;
});
return config;
}
exports.parse = parse;
function jsonify(value) {
Object.defineProperty(value, 'toJSON', {
value: function () {
return (0, utils_1.mapValues)(value, function (subValue) {
if ((0, utils_1.isFunction)(subValue)) {
return stringifyFunction(subValue);
}
else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
// mostly for assignments
return (0, utils_1.mapValues)(subValue, function (subSubValue) {
if ((0, utils_1.isFunction)(subSubValue)) {
return stringifyFunction(subSubValue);
}
return subSubValue;
});
}
return subValue;
});
Object.defineProperty(value, 'toJSON', {
value: function () {
return utils.mapValues(value, function (subValue) {
if (utils.isFunction(subValue)) {
return stringifyFunction(subValue);
} else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
// mostly for assignments
return utils.mapValues(subValue, function (subSubValue) {
if (utils.isFunction(subSubValue)) {
return stringifyFunction(subSubValue);
}
return subSubValue;
});
}
});
return value;
return subValue;
});
}
});
return value;
}
exports.jsonify = jsonify;
exports.machineToJSON = machineToJSON;
exports.parse = parse;
exports.stringify = stringify;
exports.stringifyFunction = stringifyFunction;

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

import { Model } from './model.types';
import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
import { AnyEventObject, BaseActionObject, DefaultContext, EventObject, MachineConfig, InternalMachineOptions, StateMachine, StateSchema, Typestate, ServiceMap } from './types';
import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
/**
* @deprecated Use `createMachine(...)` instead.
*/
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, any, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent, any, BaseActionObject, ServiceMap, ResolveTypegenMeta<TypegenDisabled, TEvent, BaseActionObject, ServiceMap>>;
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
}, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, BaseActionObject, TServiceMap, TTypesMeta>, options?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>): StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TServiceMap>>;
//# sourceMappingURL=Machine.d.ts.map

@@ -6,3 +6,5 @@ 'use strict';

var StateNode = require('./StateNode.js');
var environment = require('./environment.js');
var warned = false;
function Machine(config, options, initialContext) {

@@ -16,2 +18,7 @@ if (initialContext === void 0) {

function createMachine(config, options) {
if (!environment.IS_PRODUCTION && !('predictableActionArguments' in config) && !warned) {
warned = true;
console.warn('It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html');
}
return new StateNode.StateNode(config, options);

@@ -18,0 +25,0 @@ }

@@ -14,3 +14,3 @@ 'use strict';

try {
for (var _b = _tslib.__values(utils.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = _tslib.__values(Object.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
var mappedStateId = _c.value;

@@ -17,0 +17,0 @@

@@ -1,5 +0,8 @@

import type { EventObject, BaseActionObject } from './types';
import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
/**
* @deprecated Use [Typegen](https://stately.ai/blog/introducing-typescript-typegen-for-xstate) instead.
*/
export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
//# sourceMappingURL=model.d.ts.map

@@ -1,74 +0,54 @@

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _tslib = require('./_virtual/_tslib.js');
var actions = require('./actions.js');
var Machine = require('./Machine.js');
var utils = require('./utils.js');
function createModel(initialContext, creators) {
var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
var model = {
initialContext: initialContext,
assign: actions.assign,
events: eventCreators ? utils.mapValues(eventCreators, function (fn, eventType) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
return _tslib.__assign(_tslib.__assign({}, fn.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false))), {
type: eventType
});
};
}) : undefined,
actions: actionCreators ? utils.mapValues(actionCreators, function (fn, actionType) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
finally { if (e) throw e.error; }
return _tslib.__assign(_tslib.__assign({}, fn.apply(void 0, _tslib.__spreadArray([], _tslib.__read(args), false))), {
type: actionType
});
};
}) : undefined,
reset: function () {
return actions.assign(initialContext);
},
createMachine: function (config, implementations) {
return Machine.createMachine('context' in config ? config : _tslib.__assign(_tslib.__assign({}, config), {
context: initialContext
}), implementations);
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createModel = void 0;
var actions_1 = require("./actions");
var Machine_1 = require("./Machine");
var utils_1 = require("./utils");
function createModel(initialContext, creators) {
var eventCreators = creators === null || creators === void 0 ? void 0 : creators.events;
var actionCreators = creators === null || creators === void 0 ? void 0 : creators.actions;
var model = {
initialContext: initialContext,
assign: actions_1.assign,
events: (eventCreators
? (0, utils_1.mapValues)(eventCreators, function (fn, eventType) { return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: eventType }));
}; })
: undefined),
actions: actionCreators
? (0, utils_1.mapValues)(actionCreators, function (fn, actionType) { return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: actionType }));
}; })
: undefined,
reset: function () { return (0, actions_1.assign)(initialContext); },
createMachine: function (config, implementations) {
return (0, Machine_1.createMachine)('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
}
};
return model;
};
return model;
}
exports.createModel = createModel;

@@ -1,16 +0,18 @@

import { EventObject, Assigner, ExtractEvent, PropertyAssigner, AssignAction, MachineConfig, MachineOptions, StateMachine, BaseActionObject } from './types';
export declare type AnyFunction = (...args: any[]) => any;
export declare type IsNever<T> = [T] extends [never] ? true : false;
export declare type Cast<T extends any, TCastType extends any> = T extends TCastType ? T : TCastType;
export declare type Compute<A extends any> = {
[K in keyof A]: A[K];
} & unknown;
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
declare type SimplisticExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
type: TEventType;
} ? TEvent : never;
export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
initialContext: TContext;
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, SimplisticExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, SimplisticExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, SimplisticExtractEvent<TEvent, TEventType>, TEvent>;
events: Prop<TModelCreators, 'events'>;
actions: Prop<TModelCreators, 'actions'>;
reset: () => AssignAction<TContext, any>;
createMachine: (config: MachineConfig<TContext, any, TEvent, TAction>, implementations?: Partial<MachineOptions<TContext, TEvent, TAction>>) => StateMachine<TContext, any, TEvent>;
createMachine: {
<TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
value: any;
context: TContext;
}, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
};
}

@@ -53,2 +55,3 @@ export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;

}[keyof TCreators];
export {};
//# sourceMappingURL=model.types.d.ts.map

@@ -1,61 +0,53 @@

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sequence = exports.toggle = void 0;
var utils_1 = require("./utils");
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _tslib = require('./_virtual/_tslib.js');
var utils = require('./utils.js');
function toggle(onState, offState, eventType) {
var _a, _b, _c;
return _a = {},
_a[onState] = {
on: (_b = {}, _b[eventType] = offState, _b)
},
_a[offState] = {
on: (_c = {}, _c[eventType] = onState, _c)
},
_a;
var _a, _b, _c;
return _a = {}, _a[onState] = {
on: (_b = {}, _b[eventType] = offState, _b)
}, _a[offState] = {
on: (_c = {}, _c[eventType] = onState, _c)
}, _a;
}
exports.toggle = toggle;
var defaultSequencePatternOptions = {
nextEvent: 'NEXT',
prevEvent: 'PREV'
nextEvent: 'NEXT',
prevEvent: 'PREV'
};
function sequence(items, options) {
var resolvedOptions = __assign(__assign({}, defaultSequencePatternOptions), options);
var states = {};
var nextEventObject = resolvedOptions.nextEvent === undefined
? undefined
: (0, utils_1.toEventObject)(resolvedOptions.nextEvent);
var prevEventObject = resolvedOptions.prevEvent === undefined
? undefined
: (0, utils_1.toEventObject)(resolvedOptions.prevEvent);
items.forEach(function (item, i) {
var state = {
on: {}
};
if (i + 1 === items.length) {
state.type = 'final';
}
if (nextEventObject && i + 1 < items.length) {
state.on[nextEventObject.type] = items[i + 1];
}
if (prevEventObject && i > 0) {
state.on[prevEventObject.type] = items[i - 1];
}
states[item] = state;
});
return {
initial: items[0],
states: states
var resolvedOptions = _tslib.__assign(_tslib.__assign({}, defaultSequencePatternOptions), options);
var states = {};
var nextEventObject = resolvedOptions.nextEvent === undefined ? undefined : utils.toEventObject(resolvedOptions.nextEvent);
var prevEventObject = resolvedOptions.prevEvent === undefined ? undefined : utils.toEventObject(resolvedOptions.prevEvent);
items.forEach(function (item, i) {
var state = {
on: {}
};
if (i + 1 === items.length) {
state.type = 'final';
}
if (nextEventObject && i + 1 < items.length) {
state.on[nextEventObject.type] = items[i + 1];
}
if (prevEventObject && i > 0) {
state.on[prevEventObject.type] = items[i - 1];
}
states[item] = state;
});
return {
initial: items[0],
states: states
};
}
exports.sequence = sequence;
exports.toggle = toggle;
export declare function createSchema<T>(schema?: any): T;
export declare const t: typeof createSchema;
//# sourceMappingURL=schema.d.ts.map

@@ -8,3 +8,5 @@ 'use strict';

}
var t = createSchema;
exports.createSchema = createSchema;
exports.t = t;

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

import { StateNode } from './index';
import { AnyStateMachine } from './index';
export interface ScxmlToMachineOptions {
delimiter?: string;
}
export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateNode;
export declare function toMachine(xml: string, options: ScxmlToMachineOptions): AnyStateMachine;
//# sourceMappingURL=scxml.d.ts.map

@@ -111,3 +111,3 @@ "use strict";

var datamodel = context
? (0, utils_1.keys)(context)
? Object.keys(context)
.map(function (key) { return "const ".concat(key, " = context['").concat(key, "'];"); })

@@ -114,0 +114,0 @@ .join('\n')

@@ -1,83 +0,85 @@

"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _tslib = require('./_virtual/_tslib.js');
var SimulatedClock =
/*#__PURE__*/
/** @class */
function () {
function SimulatedClock() {
this.timeouts = new Map();
this._now = 0;
this._id = 0;
}
SimulatedClock.prototype.now = function () {
return this._now;
};
SimulatedClock.prototype.getId = function () {
return this._id++;
};
SimulatedClock.prototype.setTimeout = function (fn, timeout) {
var id = this.getId();
this.timeouts.set(id, {
start: this.now(),
timeout: timeout,
fn: fn
});
return id;
};
SimulatedClock.prototype.clearTimeout = function (id) {
this.timeouts.delete(id);
};
SimulatedClock.prototype.set = function (time) {
if (this._now > time) {
throw new Error('Unable to travel back in time');
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimulatedClock = void 0;
var SimulatedClock = /** @class */ (function () {
function SimulatedClock() {
this.timeouts = new Map();
this._now = 0;
this._id = 0;
}
SimulatedClock.prototype.now = function () {
return this._now;
};
SimulatedClock.prototype.getId = function () {
return this._id++;
};
SimulatedClock.prototype.setTimeout = function (fn, timeout) {
var id = this.getId();
this.timeouts.set(id, {
start: this.now(),
timeout: timeout,
fn: fn
});
return id;
};
SimulatedClock.prototype.clearTimeout = function (id) {
this.timeouts.delete(id);
};
SimulatedClock.prototype.set = function (time) {
if (this._now > time) {
throw new Error('Unable to travel back in time');
}
this._now = time;
this.flushTimeouts();
};
SimulatedClock.prototype.flushTimeouts = function () {
var _this = this;
__spreadArray([], __read(this.timeouts), false).sort(function (_a, _b) {
var _c = __read(_a, 2), _idA = _c[0], timeoutA = _c[1];
var _d = __read(_b, 2), _idB = _d[0], timeoutB = _d[1];
var endA = timeoutA.start + timeoutA.timeout;
var endB = timeoutB.start + timeoutB.timeout;
return endB > endA ? -1 : 1;
})
.forEach(function (_a) {
var _b = __read(_a, 2), id = _b[0], timeout = _b[1];
if (_this.now() - timeout.start >= timeout.timeout) {
_this.timeouts.delete(id);
timeout.fn.call(null);
}
});
};
SimulatedClock.prototype.increment = function (ms) {
this._now += ms;
this.flushTimeouts();
};
return SimulatedClock;
}());
this._now = time;
this.flushTimeouts();
};
SimulatedClock.prototype.flushTimeouts = function () {
var _this = this;
_tslib.__spreadArray([], _tslib.__read(this.timeouts), false).sort(function (_a, _b) {
var _c = _tslib.__read(_a, 2);
_c[0];
var timeoutA = _c[1];
var _d = _tslib.__read(_b, 2);
_d[0];
var timeoutB = _d[1];
var endA = timeoutA.start + timeoutA.timeout;
var endB = timeoutB.start + timeoutB.timeout;
return endB > endA ? -1 : 1;
}).forEach(function (_a) {
var _b = _tslib.__read(_a, 2),
id = _b[0],
timeout = _b[1];
if (_this.now() - timeout.start >= timeout.timeout) {
_this.timeouts.delete(id);
timeout.fn.call(null);
}
});
};
SimulatedClock.prototype.increment = function (ms) {
this._now += ms;
this.flushTimeouts();
};
return SimulatedClock;
}();
exports.SimulatedClock = SimulatedClock;

@@ -1,17 +0,20 @@

import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
import { StateNode } from './StateNode';
import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
import { BaseActionObject, Prop } from './types';
export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}>(state: object | string): state is State<TContext, TEvent, TStateSchema, TTypestate>;
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any>): ActionObject<TC, TE>;
export declare function isStateConfig<TContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
/**
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
*/
export declare const isState: typeof isStateConfig;
export declare function bindActionToState<TC, TE extends EventObject>(action: ActionObject<TC, TE>, state: State<TC, TE, any, any, any>): ActionObject<TC, TE>;
export declare class State<TContext, TEvent extends EventObject = EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> {
}, TResolvedTypesMeta = TypegenDisabled> {
value: StateValue;
context: TContext;
historyValue?: HistoryValue | undefined;
history?: State<TContext, TEvent, TStateSchema, TTypestate>;
history?: State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
actions: Array<ActionObject<TContext, TEvent>>;

@@ -40,7 +43,7 @@ activities: ActivityMap;

*/
configuration: Array<StateNode<TContext, any, TEvent, any>>;
configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
/**
* The next events that will cause a transition from the current state.
*/
nextEvents: EventType[];
nextEvents: Array<TEvent['type']>;
/**

@@ -55,3 +58,3 @@ * The transition definitions that resulted in this state.

tags: Set<string>;
machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
machine: StateMachine<TContext, any, TEvent, TTypestate, BaseActionObject, any, TResolvedTypesMeta> | undefined;
/**

@@ -62,3 +65,3 @@ * Creates a new State instance for the given `stateValue` and `context`.

*/
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any>;
static from<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context?: TC | undefined): State<TC, TE, any, any, any>;
/**

@@ -68,3 +71,3 @@ * Creates a new State instance for the given `config`.

*/
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE>;
static create<TC, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any, any, any>;
/**

@@ -75,3 +78,3 @@ * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).

*/
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE> | StateValue, context: TC): State<TC, TE>;
static inert<TC, TE extends EventObject = EventObject>(stateValue: State<TC, TE, any, any, any> | StateValue, context: TC): State<TC, TE>;
/**

@@ -96,3 +99,3 @@ * Creates a new State instance.

toStrings(stateValue?: StateValue, delimiter?: string): string[];
toJSON(): Omit<this, "machine" | "tags" | "transitions" | "configuration"> & {
toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine" | "toStrings" | "toJSON" | "matches" | "hasTag" | "can"> & {
tags: string[];

@@ -104,6 +107,7 @@ };

*/
matches<TSV extends TTypestate['value']>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : never>(parentStateValue: TSV): boolean;
matches<TSV extends TResolvedTypesMeta extends TypegenDisabled ? TTypestate['value'] : never>(parentStateValue: TSV): this is State<(TTypestate extends any ? {
value: TSV;
context: any;
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate, TResolvedTypesMeta> & {
value: TSV;

@@ -115,3 +119,3 @@ };

*/
hasTag(tag: string): boolean;
hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'tags'> : string): boolean;
/**

@@ -118,0 +122,0 @@ * Determines whether sending the `event` will cause a non-forbidden transition

@@ -7,6 +7,6 @@ 'use strict';

var constants = require('./constants.js');
var environment = require('./environment.js');
var utils = require('./utils.js');
var stateUtils = require('./stateUtils.js');
var actions = require('./actions.js');
var environment = require('./environment.js');

@@ -26,4 +26,4 @@ function stateValuesEqual(a, b) {

var aKeys = utils.keys(a);
var bKeys = utils.keys(b);
var aKeys = Object.keys(a);
var bKeys = Object.keys(b);
return aKeys.length === bKeys.length && aKeys.every(function (key) {

@@ -33,9 +33,14 @@ return stateValuesEqual(a[key], b[key]);

}
function isState(state) {
if (utils.isString(state)) {
function isStateConfig(state) {
if (typeof state !== 'object' || state === null) {
return false;
}
return 'value' in state && 'history' in state;
return 'value' in state && '_event' in state;
}
/**
* @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
*/
var isState = isStateConfig;
function bindActionToState(action, state) {

@@ -216,3 +221,3 @@ var exec = action.exec;

var valueKeys = utils.keys(stateValue);
var valueKeys = Object.keys(stateValue);
return valueKeys.concat.apply(valueKeys, _tslib.__spreadArray([], _tslib.__read(valueKeys.map(function (key) {

@@ -226,8 +231,8 @@ return _this.toStrings(stateValue[key], delimiter).map(function (s) {

State.prototype.toJSON = function () {
var _a = this,
configuration = _a.configuration,
transitions = _a.transitions,
tags = _a.tags,
machine = _a.machine,
jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags", "machine"]);
var _a = this;
_a.configuration;
_a.transitions;
var tags = _a.tags;
_a.machine;
var jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags", "machine"]);

@@ -238,8 +243,3 @@ return _tslib.__assign(_tslib.__assign({}, jsonValues), {

};
/**
* Whether the current state value is a subset of the given parent state value.
* @param parentStateValue
*/
State.prototype.matches = function (parentStateValue) {

@@ -287,2 +287,3 @@ return utils.matchesState(parentStateValue, this.value);

exports.isState = isState;
exports.isStateConfig = isStateConfig;
exports.stateValuesEqual = stateValuesEqual;

@@ -1,7 +0,8 @@

import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema } from './types';
import { Event, StateValue, StateTransition, MachineOptions, EventObject, HistoryValue, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, ActivityDefinition, StateNodeConfig, StateSchema, StateNodesConfig, InvokeDefinition, ActionObject, Mapper, PropertyMapper, SCXML, Typestate, TransitionDefinitionMap, MachineSchema, InternalMachineOptions, ServiceMap, StateConfig, PredictableActionArgumentsExec } from './types';
import { State } from './State';
import { TypegenDisabled } from './typegenTypes';
declare class StateNode<TContext = any, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}> {
}, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = TypegenDisabled> {
/**

@@ -84,3 +85,3 @@ * The raw config used to create the machine.

*/
parent?: StateNode<TContext, any, TEvent, any>;
parent?: StateNode<TContext, any, TEvent, any, any, any>;
/**

@@ -123,7 +124,11 @@ * The root machine node.

*/
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>,
config: StateNodeConfig<TContext, TStateSchema, TEvent>, options?: MachineOptions<TContext, TEvent>,
/**
* The initial extended state
*/
_context?: Readonly<TContext> | (() => Readonly<TContext>));
_context?: Readonly<TContext> | (() => Readonly<TContext>), // TODO: this is unsafe, but we're removing it in v5 anyway
_stateInfo?: {
parent: StateNode<any, any, any, any, any, any>;
key: string;
});
private _init;

@@ -136,3 +141,3 @@ /**

*/
withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate>;
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
/**

@@ -169,3 +174,3 @@ * Clones this state machine with custom context.

*/
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate>): Array<StateNode<TContext, any, TEvent, TTypestate>>;
getStateNodes(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>): Array<StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>>;
/**

@@ -184,3 +189,3 @@ * Returns `true` if this state node explicitly handles the given event.

*/
resolveState(state: State<TContext, TEvent, any, any>): State<TContext, TEvent, TStateSchema, TTypestate>;
resolveState(state: State<TContext, TEvent, any, any> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private transitionLeafNode;

@@ -190,10 +195,5 @@ private transitionCompoundNode;

private _transition;
getTransitionData(state: State<TContext, TEvent, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
getTransitionData(state: State<TContext, TEvent, any, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
private next;
private nodesFromChild;
/**
* Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
* this state node, it does not escape.
*/
private escapes;
private getPotentiallyReenteringNodes;
private getActions;

@@ -207,3 +207,3 @@ /**

*/
transition(state: StateValue | State<TContext, TEvent, any, TTypestate> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
transition(state: StateValue | State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>, context?: TContext, exec?: PredictableActionArgumentsExec): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
private resolveRaisedTransition;

@@ -214,3 +214,3 @@ private resolveTransition;

*/
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate>;
getStateNode(stateKey: string): StateNode<TContext, any, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>;
/**

@@ -221,3 +221,3 @@ * Returns the state node with the given `stateId`, or throws.

*/
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any>;
getStateNodeById(stateId: string): StateNode<TContext, any, TEvent, any, TServiceMap, TResolvedTypesMeta>;
/**

@@ -228,3 +228,3 @@ * Returns the relative state node from the given `statePath`, or throws.

*/
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any>;
getStateNodeByPath(statePath: string | string[]): StateNode<TContext, any, TEvent, any, any, any>;
/**

@@ -238,3 +238,3 @@ * Resolves a partial state value with its full representation in this machine.

private get initialStateValue();
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate>;
getInitialState(stateValue: StateValue, context?: TContext): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
/**

@@ -244,3 +244,3 @@ * The initial State instance, which includes all actions to be executed from

*/
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>;
get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
/**

@@ -259,3 +259,3 @@ * The target state value of the history state node, if it exists. This represents the

getRelativeStateNodes(relativeStateId: StateNode<TContext, any, TEvent>, historyValue?: HistoryValue, resolve?: boolean): Array<StateNode<TContext, any, TEvent>>;
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any>>;
get initialStateNodes(): Array<StateNode<TContext, any, TEvent, any, any, any>>;
/**

@@ -267,3 +267,3 @@ * Retrieves state nodes from a relative path to this state node.

*/
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any>>;
getFromRelativePath(relativePath: string[]): Array<StateNode<TContext, any, TEvent, any, any, any>>;
private historyValue;

@@ -270,0 +270,0 @@ /**

@@ -6,10 +6,9 @@ 'use strict';

var _tslib = require('./_virtual/_tslib.js');
var constants = require('./constants.js');
var environment = require('./environment.js');
var utils = require('./utils.js');
var types = require('./types.js');
var stateUtils = require('./stateUtils.js');
var State = require('./State.js');
var actionTypes = require('./actionTypes.js');
var actions = require('./actions.js');
var State = require('./State.js');
var environment = require('./environment.js');
var constants = require('./constants.js');
var stateUtils = require('./stateUtils.js');
var Actor = require('./Actor.js');

@@ -58,6 +57,4 @@ var invokeUtils = require('./invokeUtils.js');

*/
_context // TODO: this is unsafe, but we're removing it in v5 anyway
) {
var _this = this;
_context, // TODO: this is unsafe, but we're removing it in v5 anyway
_stateInfo) {
if (_context === void 0) {

@@ -67,2 +64,4 @@ _context = 'context' in config ? config.context : undefined;

var _this = this;
var _a;

@@ -91,4 +90,4 @@

this.options = Object.assign(createDefaultOptions(), options);
this.parent = this.options._parent;
this.key = this.config.key || this.options._key || this.config.id || '(machine)';
this.parent = _stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.parent;
this.key = this.config.key || (_stateInfo === null || _stateInfo === void 0 ? void 0 : _stateInfo.key) || this.config.id || '(machine)';
this.machine = this.parent ? this.parent.machine : this;

@@ -99,3 +98,3 @@ this.path = this.parent ? this.parent.path.concat(this.key) : [];

this.version = this.parent ? this.parent.version : this.config.version;
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && utils.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
this.type = this.config.type || (this.config.parallel ? 'parallel' : this.config.states && Object.keys(this.config.states).length ? 'compound' : this.config.history ? 'history' : 'atomic');
this.schema = this.parent ? this.machine.schema : (_a = this.config.schema) !== null && _a !== void 0 ? _a : {};

@@ -112,5 +111,5 @@ this.description = this.config.description;

var stateNode = new StateNode(stateConfig, {
_parent: _this,
_key: key
var stateNode = new StateNode(stateConfig, {}, undefined, {
parent: _this,
key: key
});

@@ -129,3 +128,3 @@ Object.assign(_this.idMap, _tslib.__assign((_a = {}, _a[stateNode.id] = stateNode, _a), stateNode.idMap));

try {
for (var _b = _tslib.__values(stateUtils.getChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = _tslib.__values(stateUtils.getAllChildren(stateNode)), _c = _b.next(); !_c.done; _c = _b.next()) {
var child = _c.value;

@@ -169,20 +168,21 @@ dfs(child);

if (utils.isMachine(invokeConfig)) {
_this.machine.options.services = _tslib.__assign((_a = {}, _a[invokeConfig.id] = invokeConfig, _a), _this.machine.options.services);
var invokeId = utils.createInvokeId(_this.id, i);
_this.machine.options.services = _tslib.__assign((_a = {}, _a[invokeId] = invokeConfig, _a), _this.machine.options.services);
return invokeUtils.toInvokeDefinition({
src: invokeConfig.id,
id: invokeConfig.id
src: invokeId,
id: invokeId
});
} else if (utils.isString(invokeConfig.src)) {
var invokeId = invokeConfig.id || utils.createInvokeId(_this.id, i);
return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({}, invokeConfig), {
id: invokeConfig.id || invokeConfig.src,
id: invokeId,
src: invokeConfig.src
}));
} else if (utils.isMachine(invokeConfig.src) || utils.isFunction(invokeConfig.src)) {
var invokeSrc = "".concat(_this.id, ":invocation[").concat(i, "]"); // TODO: util function
_this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeSrc] = invokeConfig.src, _b), _this.machine.options.services);
var invokeId = invokeConfig.id || utils.createInvokeId(_this.id, i);
_this.machine.options.services = _tslib.__assign((_b = {}, _b[invokeId] = invokeConfig.src, _b), _this.machine.options.services);
return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
id: invokeSrc
id: invokeId
}, invokeConfig), {
src: invokeSrc
src: invokeId
}));

@@ -192,3 +192,3 @@ } else {

return invokeUtils.toInvokeDefinition(_tslib.__assign(_tslib.__assign({
id: invokeSource.type
id: utils.createInvokeId(_this.id, i)
}, invokeConfig), {

@@ -380,3 +380,3 @@ src: invokeSource

});
}) : utils.flatten(utils.keys(afterConfig).map(function (delay, i) {
}) : utils.flatten(Object.keys(afterConfig).map(function (delay, i) {
var configTransition = afterConfig[delay];

@@ -425,3 +425,3 @@ var resolvedTransition = utils.isString(configTransition) ? {

var subStateKeys = utils.keys(stateValue);
var subStateKeys = Object.keys(stateValue);
var subStateNodes = [this];

@@ -454,8 +454,10 @@ subStateNodes.push.apply(subStateNodes, _tslib.__spreadArray([], _tslib.__read(utils.flatten(subStateKeys.map(function (subStateKey) {

StateNode.prototype.resolveState = function (state) {
var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(state.value)));
return new State.State(_tslib.__assign(_tslib.__assign({}, state), {
value: this.resolve(state.value),
var stateFromConfig = state instanceof State.State ? state : State.State.create(state);
var configuration = Array.from(stateUtils.getConfiguration([], this.getStateNodes(stateFromConfig.value)));
return new State.State(_tslib.__assign(_tslib.__assign({}, stateFromConfig), {
value: this.resolve(stateFromConfig.value),
configuration: configuration,
done: stateUtils.isInFinalState(configuration, this),
tags: stateUtils.getTagsFromConfiguration(configuration)
tags: stateUtils.getTagsFromConfiguration(configuration),
machine: this.machine
}));

@@ -476,3 +478,3 @@ };

StateNode.prototype.transitionCompoundNode = function (stateValue, state, _event) {
var subStateKeys = utils.keys(stateValue);
var subStateKeys = Object.keys(stateValue);
var stateNode = this.getStateNode(subStateKeys[0]);

@@ -495,3 +497,3 @@

try {
for (var _b = _tslib.__values(utils.keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = _tslib.__values(Object.keys(stateValue)), _c = _b.next(); !_c.done; _c = _b.next()) {
var subStateKey = _c.value;

@@ -524,3 +526,3 @@ var subStateValue = stateValue[subStateKey];

var stateTransitions = utils.keys(transitionMap).map(function (key) {
var stateTransitions = Object.keys(transitionMap).map(function (key) {
return transitionMap[key];

@@ -539,6 +541,3 @@ });

var entryNodes = utils.flatten(stateTransitions.map(function (t) {
return t.entrySet;
}));
var configuration = utils.flatten(utils.keys(transitionMap).map(function (key) {
var configuration = utils.flatten(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].configuration;

@@ -548,3 +547,2 @@ }));

transitions: enabledTransitions,
entrySet: entryNodes,
exitSet: utils.flatten(stateTransitions.map(function (t) {

@@ -555,3 +553,3 @@ return t.exitSet;

source: state,
actions: utils.flatten(utils.keys(transitionMap).map(function (key) {
actions: utils.flatten(Object.keys(transitionMap).map(function (key) {
return transitionMap[key].actions;

@@ -569,3 +567,3 @@ }))

if (utils.keys(stateValue).length === 1) {
if (Object.keys(stateValue).length === 1) {
return this.transitionCompoundNode(stateValue, state, _event);

@@ -638,3 +636,2 @@ } // orthogonal node

transitions: [selectedTransition],
entrySet: [],
exitSet: [],

@@ -651,9 +648,7 @@ configuration: state.value ? [this] : [],

var isInternal = !!selectedTransition.internal;
var reentryNodes = isInternal ? [] : utils.flatten(allNextStateNodes.map(function (n) {
return _this.nodesFromChild(n);
}));
return {
transitions: [selectedTransition],
entrySet: reentryNodes,
exitSet: isInternal ? [] : [this],
exitSet: isInternal ? [] : utils.flatten(nextStateNodes.map(function (targetNode) {
return _this.getPotentiallyReenteringNodes(targetNode);
})),
configuration: allNextStateNodes,

@@ -663,13 +658,17 @@ source: state,

};
};
}; // even though the name of this function mentions reentry nodes
// we are pushing its result into `exitSet`
// that's because what we exit might be reentered (it's an invariant of reentrancy)
StateNode.prototype.nodesFromChild = function (childStateNode) {
if (childStateNode.escapes(this)) {
return [];
StateNode.prototype.getPotentiallyReenteringNodes = function (targetNode) {
if (this.order < targetNode.order) {
return [this];
}
var nodes = [];
var marker = childStateNode;
var marker = this;
var possibleAncestor = targetNode;
while (marker && marker !== this) {
while (marker && marker !== possibleAncestor) {
nodes.push(marker);

@@ -679,42 +678,28 @@ marker = marker.parent;

nodes.push(this); // inclusive
if (marker !== possibleAncestor) {
// we never got to `possibleAncestor`, therefore the initial `marker` "escapes" it
// it's in a different part of the tree so no states will be reentered for such an external transition
return [];
}
nodes.push(possibleAncestor);
return nodes;
};
/**
* Whether the given state node "escapes" this state node. If the `stateNode` is equal to or the parent of
* this state node, it does not escape.
*/
StateNode.prototype.getActions = function (resolvedConfig, isDone, transition, currentContext, _event, prevState, predictableExec) {
var e_4, _a, e_5, _b;
StateNode.prototype.escapes = function (stateNode) {
if (this === stateNode) {
return false;
}
var _this = this;
var parent = this.parent;
var prevConfig = prevState ? stateUtils.getConfiguration([], this.getStateNodes(prevState.value)) : [];
var entrySet = new Set();
while (parent) {
if (parent === stateNode) {
return false;
}
parent = parent.parent;
}
return true;
};
StateNode.prototype.getActions = function (transition, currentContext, _event, prevState) {
var e_4, _a, e_5, _b;
var prevConfig = stateUtils.getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
var resolvedConfig = transition.configuration.length ? stateUtils.getConfiguration(prevConfig, transition.configuration) : prevConfig;
try {
for (var resolvedConfig_1 = _tslib.__values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
var sn = resolvedConfig_1_1.value;
for (var _c = _tslib.__values(Array.from(resolvedConfig).sort(function (a, b) {
return a.order - b.order;
})), _d = _c.next(); !_d.done; _d = _c.next()) {
var sn = _d.value;
if (!stateUtils.has(prevConfig, sn)) {
transition.entrySet.push(sn);
if (!stateUtils.has(prevConfig, sn) || stateUtils.has(transition.exitSet, sn) || sn.parent && entrySet.has(sn.parent)) {
entrySet.add(sn);
}

@@ -728,3 +713,3 @@ }

try {
if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
} finally {

@@ -755,3 +740,10 @@ if (e_4) throw e_4.error;

var doneEvents = utils.flatten(transition.entrySet.map(function (sn) {
transition.exitSet.sort(function (a, b) {
return b.order - a.order;
});
var entryStates = Array.from(entrySet).sort(function (a, b) {
return a.order - b.order;
});
var exitStates = new Set(transition.exitSet);
var doneEvents = utils.flatten(entryStates.map(function (sn) {
var events = [];

@@ -783,24 +775,44 @@

}));
transition.exitSet.sort(function (a, b) {
return b.order - a.order;
var entryActions = entryStates.map(function (stateNode) {
var entryActions = stateNode.onEntry;
var invokeActions = stateNode.activities.map(function (activity) {
return actions.start(activity);
});
return {
type: 'entry',
actions: actions.toActionObjects(predictableExec ? _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(entryActions), false), _tslib.__read(invokeActions), false) : _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(invokeActions), false), _tslib.__read(entryActions), false), _this.machine.options.actions)
};
}).concat({
type: 'state_done',
actions: doneEvents.map(function (event) {
return actions.raise(event);
})
});
transition.entrySet.sort(function (a, b) {
return a.order - b.order;
var exitActions = Array.from(exitStates).map(function (stateNode) {
return {
type: 'exit',
actions: actions.toActionObjects(_tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
return actions.stop(activity);
})), false), _this.machine.options.actions)
};
});
var entryStates = new Set(transition.entrySet);
var exitStates = new Set(transition.exitSet);
var actions$1 = exitActions.concat({
type: 'transition',
actions: actions.toActionObjects(transition.actions, this.machine.options.actions)
}).concat(entryActions);
var _c = _tslib.__read([utils.flatten(Array.from(entryStates).map(function (stateNode) {
return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.activities.map(function (activity) {
return actions.start(activity);
})), false), _tslib.__read(stateNode.onEntry), false);
})).concat(doneEvents.map(actions.raise)), utils.flatten(Array.from(exitStates).map(function (stateNode) {
return _tslib.__spreadArray(_tslib.__spreadArray([], _tslib.__read(stateNode.onExit), false), _tslib.__read(stateNode.activities.map(function (activity) {
return actions.stop(activity);
})), false);
}))], 2),
entryActions = _c[0],
exitActions = _c[1];
if (isDone) {
var stopActions = actions.toActionObjects(utils.flatten(_tslib.__spreadArray([], _tslib.__read(resolvedConfig), false).sort(function (a, b) {
return b.order - a.order;
}).map(function (stateNode) {
return stateNode.onExit;
})), this.machine.options.actions).filter(function (action) {
return !utils.isRaisableAction(action);
});
return actions$1.concat({
type: 'stop',
actions: stopActions
});
}
var actions$1 = actions.toActionObjects(exitActions.concat(transition.actions).concat(entryActions), this.machine.options.actions);
return actions$1;

@@ -817,3 +829,3 @@ };

StateNode.prototype.transition = function (state, event, context) {
StateNode.prototype.transition = function (state, event, context, exec) {
if (state === void 0) {

@@ -848,3 +860,2 @@ state = this.initialState;

configuration: [],
entrySet: [],
exitSet: [],

@@ -857,10 +868,10 @@ source: currentState,

stateTransition.configuration = _tslib.__spreadArray([], _tslib.__read(resolvedConfig), false);
return this.resolveTransition(stateTransition, currentState, _event);
return this.resolveTransition(stateTransition, currentState, currentState.context, exec, _event);
};
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent) {
StateNode.prototype.resolveRaisedTransition = function (state, _event, originalEvent, predictableExec) {
var _a;
var currentActions = state.actions;
state = this.transition(state, _event); // Save original event to state
state = this.transition(state, _event, undefined, predictableExec); // Save original event to state
// TODO: this should be the raised event! Delete in V5 (breaking)

@@ -876,4 +887,4 @@

StateNode.prototype.resolveTransition = function (stateTransition, currentState, _event, context) {
var e_6, _a;
StateNode.prototype.resolveTransition = function (stateTransition, currentState, context, predictableExec, _event) {
var e_6, _a, e_7, _b;

@@ -886,6 +897,2 @@ var _this = this;

if (context === void 0) {
context = this.machine.context;
}
var configuration = stateTransition.configuration; // Transition will "apply" if:

@@ -896,16 +903,33 @@ // - this is the initial state (there is no current state)

var willTransition = !currentState || stateTransition.transitions.length > 0;
var resolvedConfiguration = willTransition ? stateTransition.configuration : currentState ? currentState.configuration : [];
var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
var resolvedStateValue = willTransition ? stateUtils.getValue(this.machine, configuration) : undefined;
var historyValue = currentState ? currentState.historyValue ? currentState.historyValue : stateTransition.source ? this.machine.historyValue(currentState.value) : undefined : undefined;
var currentContext = currentState ? currentState.context : context;
var actions$1 = this.getActions(stateTransition, currentContext, _event, currentState);
var actionBlocks = this.getActions(new Set(resolvedConfiguration), isDone, stateTransition, context, _event, currentState, predictableExec);
var activities = currentState ? _tslib.__assign({}, currentState.activities) : {};
try {
for (var actions_1 = _tslib.__values(actions$1), actions_1_1 = actions_1.next(); !actions_1_1.done; actions_1_1 = actions_1.next()) {
var action = actions_1_1.value;
for (var actionBlocks_1 = _tslib.__values(actionBlocks), actionBlocks_1_1 = actionBlocks_1.next(); !actionBlocks_1_1.done; actionBlocks_1_1 = actionBlocks_1.next()) {
var block = actionBlocks_1_1.value;
if (action.type === actionTypes.start) {
activities[action.activity.id || action.activity.type] = action;
} else if (action.type === actionTypes.stop) {
activities[action.activity.id || action.activity.type] = false;
try {
for (var _c = (e_7 = void 0, _tslib.__values(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
var action = _d.value;
if (action.type === actionTypes.start) {
activities[action.activity.id || action.activity.type] = action;
} else if (action.type === actionTypes.stop) {
activities[action.activity.id || action.activity.type] = false;
}
}
} catch (e_7_1) {
e_7 = {
error: e_7_1
};
} finally {
try {
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
} finally {
if (e_7) throw e_7.error;
}
}

@@ -919,3 +943,3 @@ }

try {
if (actions_1_1 && !actions_1_1.done && (_a = actions_1.return)) _a.call(actions_1);
if (actionBlocks_1_1 && !actionBlocks_1_1.done && (_a = actionBlocks_1.return)) _a.call(actionBlocks_1);
} finally {

@@ -926,11 +950,9 @@ if (e_6) throw e_6.error;

var _b = _tslib.__read(actions.resolveActions(this, currentState, currentContext, _event, actions$1, this.machine.config.preserveActionOrder), 2),
resolvedActions = _b[0],
updatedContext = _b[1];
var _e = _tslib.__read(actions.resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
resolvedActions = _e[0],
updatedContext = _e[1];
var _c = _tslib.__read(utils.partition(resolvedActions, function (action) {
return action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal;
}), 2),
raisedEvents = _c[0],
nonRaisedActions = _c[1];
var _f = _tslib.__read(utils.partition(resolvedActions, utils.isRaisableAction), 2),
raisedEvents = _f[0],
nonRaisedActions = _f[1];

@@ -946,4 +968,2 @@ var invokeActions = resolvedActions.filter(function (action) {

}, currentState ? _tslib.__assign({}, currentState.children) : {});
var resolvedConfiguration = resolvedStateValue ? stateTransition.configuration : currentState ? currentState.configuration : [];
var isDone = stateUtils.isInFinalState(resolvedConfiguration, this);
var nextState = new State.State({

@@ -964,6 +984,6 @@ value: resolvedStateValue || currentState.value,

done: isDone,
tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
tags: stateUtils.getTagsFromConfiguration(resolvedConfiguration),
machine: this
});
var didUpdateContext = currentContext !== updatedContext;
var didUpdateContext = context !== updatedContext;
nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks

@@ -979,3 +999,3 @@

var isTransient = !isDone && (this._transient || configuration.some(function (stateNode) {
var hasAlwaysTransitions = !isDone && (this._transient || configuration.some(function (stateNode) {
return stateNode._transient;

@@ -987,8 +1007,7 @@ })); // If there are no enabled transitions, check if there are transient transitions.

//
// If we're already working on an transient transition (by checking
// if the event is a NULL_EVENT), then stop to prevent an infinite loop.
// If we're already working on an transient transition then stop to prevent an infinite loop.
//
// Otherwise, if there are no enabled nor transient transitions, we are done.
if (!willTransition && (!isTransient || _event.name === NULL_EVENT)) {
if (!willTransition && (!hasAlwaysTransitions || _event.name === NULL_EVENT)) {
return nextState;

@@ -1000,6 +1019,6 @@ }

if (!isDone) {
if (isTransient) {
if (hasAlwaysTransitions) {
maybeNextState = this.resolveRaisedTransition(maybeNextState, {
type: actionTypes.nullEvent
}, _event);
}, _event, predictableExec);
}

@@ -1009,3 +1028,3 @@

var raisedEvent = raisedEvents.shift();
maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event);
maybeNextState = this.resolveRaisedTransition(maybeNextState, raisedEvent._event, _event, predictableExec);
}

@@ -1019,3 +1038,2 @@ } // Detect if state changed

maybeNextState.history = history;
maybeNextState.tags = stateUtils.getTagsFromConfiguration(maybeNextState.configuration);
return maybeNextState;

@@ -1131,3 +1149,3 @@ };

if (!utils.keys(stateValue).length) {
if (!Object.keys(stateValue).length) {
return this.initialStateValue || {};

@@ -1194,6 +1212,8 @@ }

StateNode.prototype.getInitialState = function (stateValue, context) {
this._init(); // TODO: this should be in the constructor (see note in constructor)
var configuration = this.getStateNodes(stateValue);
return this.resolveTransition({
configuration: configuration,
entrySet: configuration,
exitSet: [],

@@ -1203,3 +1223,3 @@ transitions: [],

actions: []
}, undefined, undefined, context);
}, undefined, context !== null && context !== void 0 ? context : this.machine.context, undefined);
};

@@ -1213,5 +1233,2 @@

get: function () {
this._init(); // TODO: this should be in the constructor (see note in constructor)
var initialStateValue = this.initialStateValue;

@@ -1326,3 +1343,3 @@

StateNode.prototype.historyValue = function (relativeStateValue) {
if (!utils.keys(this.states).length) {
if (!Object.keys(this.states).length) {
return undefined;

@@ -1387,3 +1404,3 @@ }

var childStateIds = utils.flatten(utils.keys(this.states).map(function (stateKey) {
var childStateIds = utils.flatten(Object.keys(this.states).map(function (stateKey) {
return _this.states[stateKey].stateIds;

@@ -1401,3 +1418,3 @@ }));

get: function () {
var e_7, _a, e_8, _b;
var e_8, _a, e_9, _b;

@@ -1413,3 +1430,3 @@ if (this.__cache.events) {

try {
for (var _c = _tslib.__values(utils.keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
for (var _c = _tslib.__values(Object.keys(states)), _d = _c.next(); !_d.done; _d = _c.next()) {
var stateId = _d.value;

@@ -1420,9 +1437,9 @@ var state = states[stateId];

try {
for (var _e = (e_8 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
for (var _e = (e_9 = void 0, _tslib.__values(state.events)), _f = _e.next(); !_f.done; _f = _e.next()) {
var event_1 = _f.value;
events.add("".concat(event_1));
}
} catch (e_8_1) {
e_8 = {
error: e_8_1
} catch (e_9_1) {
e_9 = {
error: e_9_1
};

@@ -1433,3 +1450,3 @@ } finally {

} finally {
if (e_8) throw e_8.error;
if (e_9) throw e_9.error;
}

@@ -1439,5 +1456,5 @@ }

}
} catch (e_7_1) {
e_7 = {
error: e_7_1
} catch (e_8_1) {
e_8 = {
error: e_8_1
};

@@ -1448,3 +1465,3 @@ } finally {

} finally {
if (e_7) throw e_7.error;
if (e_8) throw e_8.error;
}

@@ -1544,3 +1561,3 @@ }

StateNode.prototype.formatTransitions = function () {
var e_9, _a;
var e_10, _a;

@@ -1562,3 +1579,3 @@ var _this = this;

onConfig = utils.flatten(utils.keys(strictTransitionConfigs_1).map(function (key) {
onConfig = utils.flatten(Object.keys(strictTransitionConfigs_1).map(function (key) {
if (!environment.IS_PRODUCTION && key === NULL_EVENT) {

@@ -1610,5 +1627,5 @@ utils.warn(false, "Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. " + "Please check the `on` configuration for \"#".concat(_this.id, "\"."));

}
} catch (e_9_1) {
e_9 = {
error: e_9_1
} catch (e_10_1) {
e_10 = {
error: e_10_1
};

@@ -1619,3 +1636,3 @@ } finally {

} finally {
if (e_9) throw e_9.error;
if (e_10) throw e_10.error;
}

@@ -1622,0 +1639,0 @@ }

@@ -1,8 +0,10 @@

import { EventObject, StateNode, StateValue } from '.';
import { EventObject, StateValue } from './types';
import { StateNode } from './StateNode';
declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any, any>) => boolean;
export declare function getAllChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Set<StateNode<TC, any, TE, any>>;
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any, any>): Array<StateNode<TC, any, TE, any, any, any>>;
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>): Set<StateNode<TC, any, TE, any, any, any>>;
export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;

@@ -12,3 +14,3 @@ export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;

export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any, any>>, stateNode: StateNode<TC, any, TE, any, any, any>): boolean;
export declare function getMeta(configuration?: StateNode[]): Record<string, any>;

@@ -15,0 +17,0 @@ export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;

@@ -11,7 +11,12 @@ 'use strict';

};
function getChildren(stateNode) {
return utils.keys(stateNode.states).map(function (key) {
function getAllChildren(stateNode) {
return Object.keys(stateNode.states).map(function (key) {
return stateNode.states[key];
});
}
function getChildren(stateNode) {
return getAllChildren(stateNode).filter(function (sn) {
return sn.type !== 'history';
});
}
function getAllStateNodes(stateNode) {

@@ -79,6 +84,2 @@ var stateNodes = [stateNode];

if (child.type === 'history') {
continue;
}
if (!configuration.has(child)) {

@@ -268,2 +269,3 @@ configuration.add(child);

exports.getAdjList = getAdjList;
exports.getAllChildren = getAllChildren;
exports.getAllStateNodes = getAllStateNodes;

@@ -270,0 +272,0 @@ exports.getChildren = getChildren;

@@ -0,8 +1,25 @@

import { Clock, Interpreter } from './interpreter';
import { Model } from './model.types';
import { State } from './State';
import { StateNode } from './StateNode';
import { State } from './State';
import { Interpreter, Clock } from './interpreter';
import { IsNever, Model, Prop } from './model.types';
declare type AnyFunction = (...args: any[]) => any;
import { MarkAllImplementationsAsProvided, TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, AreAllImplementationsAssumedToBeProvided, TypegenEnabled } from './typegenTypes';
export declare type AnyFunction = (...args: any[]) => any;
declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
export declare type IsNever<T> = [T] extends [never] ? true : false;
export declare type Compute<A extends any> = {
[K in keyof A]: A[K];
} & unknown;
export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
export declare type Values<T> = T[keyof T];
export declare type Merge<M, N> = Omit<M, keyof N> & N;
export declare type IndexByType<T extends {
type: string;
}> = {
[K in T['type']]: T extends any ? (K extends T['type'] ? T : never) : never;
};
export declare type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
export declare type IsAny<T> = Equals<T, any>;
export declare type Cast<A, B> = A extends B ? A : B;
export declare type NoInfer<T> = [T][T extends any ? 0 : any];
export declare type LowInfer<T> = T & {};
export declare type EventType = string;

@@ -29,2 +46,3 @@ export declare type ActionType = string;

[other: string]: any;
[notAnArrayLike: number]: never;
}

@@ -35,7 +53,10 @@ /**

*/
export interface ActionObject<TContext, TEvent extends EventObject> extends BaseActionObject {
export interface ActionObject<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TAction extends BaseActionObject = BaseActionObject> {
type: string;
/**
* The implementation for executing the action.
*/
exec?: ActionFunction<TContext, TEvent> | undefined;
exec?: ActionFunction<TContext, TExpressionEvent, BaseActionObject, TEvent> | undefined;
/** @deprecated an internal signature that doesn't exist at runtime. Its existence helps TS to choose a better code path in the inference algorithm */
(arg: TContext, ev: TExpressionEvent, meta: ActionMeta<TContext, TEvent, TAction>): void;
}

@@ -50,3 +71,3 @@ export declare type DefaultContext = Record<string, any> | undefined;

export declare type Event<TEvent extends EventObject> = TEvent['type'] | TEvent;
export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateMeta<TContext, TEvent> {
export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> extends StateMeta<TContext, TEvent> {
action: TAction;

@@ -60,8 +81,10 @@ _event: SCXML.Event<TEvent>;

}
export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent, TAction>) => void;
export interface ChooseCondition<TContext, TEvent extends EventObject> {
cond?: Condition<TContext, TEvent>;
actions: Actions<TContext, TEvent>;
export declare type ActionFunction<TContext, TExpressionEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TEvent extends EventObject = TExpressionEvent> = {
bivarianceHack(context: TContext, event: TExpressionEvent, meta: ActionMeta<TContext, TEvent, TAction>): void;
}['bivarianceHack'];
export interface ChooseCondition<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
cond?: Condition<TContext, TExpressionEvent>;
actions: Actions<TContext, TExpressionEvent, TEvent>;
}
export declare type Action<TContext, TEvent extends EventObject> = ActionType | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>;
export declare type Action<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = ActionType | BaseActionObject | ActionObject<TContext, TExpressionEvent, TEvent> | ActionFunction<TContext, TExpressionEvent, BaseActionObject, TEvent>;
/**

@@ -75,6 +98,6 @@ * Extracts action objects that have no extra properties.

export declare type SimpleEventsOf<TEvent extends EventObject> = ExtractWithSimpleSupport<TEvent>;
export declare type BaseAction<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SimpleActionsOf<TAction>['type'] | TAction | RaiseAction<any> | SendAction<TContext, TEvent, any> | AssignAction<TContext, TEvent> | LogAction<TContext, TEvent> | CancelAction | StopAction<TContext, TEvent> | ChooseAction<TContext, TEvent> | ActionFunction<TContext, TEvent>;
export declare type BaseActions<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SingleOrArray<BaseAction<TContext, TEvent, TAction>>;
export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
export declare type StateKey = string | State<any>;
export declare type BaseAction<TContext, TExpressionEvent extends EventObject, TAction extends BaseActionObject, TEvent extends EventObject = TExpressionEvent> = SimpleActionsOf<TAction>['type'] | TAction | RaiseAction<TContext, TExpressionEvent, TEvent> | SendAction<TContext, TExpressionEvent, TEvent> | AssignAction<TContext, TExpressionEvent, TEvent> | LogAction<TContext, TExpressionEvent, TEvent> | CancelAction<TContext, TExpressionEvent, TEvent> | StopAction<TContext, TExpressionEvent, TEvent> | ChooseAction<TContext, TExpressionEvent, TEvent> | PureAction<TContext, TExpressionEvent, TEvent> | ActionFunction<TContext, TExpressionEvent, TAction, TEvent>;
export declare type BaseActions<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TAction extends BaseActionObject> = SingleOrArray<BaseAction<TContext, TExpressionEvent, TAction, TEvent>>;
export declare type Actions<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent>>;
export declare type StateKey = string | AnyState;
export interface StateValueMap {

@@ -110,5 +133,5 @@ [key: string]: StateValue;

export declare type TransitionTargets<TContext> = Array<string | StateNode<TContext, any>>;
export interface TransitionConfig<TContext, TEvent extends EventObject> {
cond?: Condition<TContext, TEvent>;
actions?: Actions<TContext, TEvent>;
export interface TransitionConfig<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
cond?: Condition<TContext, TExpressionEvent>;
actions?: BaseActions<TContext, TExpressionEvent, TEvent, BaseActionObject>;
in?: StateValue;

@@ -155,3 +178,5 @@ internal?: boolean;

}
export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
export declare type Receiver<TEvent extends EventObject> = (listener: {
bivarianceHack(event: TEvent): void;
}['bivarianceHack']) => void;
export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (callback: Sender<TSentEvent>, onReceive: Receiver<TEvent>) => (() => void) | Promise<any> | void;

@@ -176,3 +201,4 @@ export interface InvokeMeta {

*/
export declare type InvokeCreator<TContext, TEvent extends EventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<any, TEvent> | Behavior<any>;
export declare type InvokeCreator<TContext, TSourceEvent extends EventObject, TFinalContext = any, TInputEvent extends EventObject = any, // keeping a slot for it here, but it's actually not used right now to ensure that the communication contract between actors is satisfied
TOutputEvent extends EventObject = TSourceEvent> = (context: TContext, event: TSourceEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any, any, any, any, any> | Subscribable<EventObject> | InvokeCallback<TInputEvent, TOutputEvent> | Behavior<any>;
export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {

@@ -217,20 +243,14 @@ /**

export declare type StateNodesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
[K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K], TEvent>;
[K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K] & {}, TEvent>;
};
export declare type StatesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
[K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K], TEvent, TAction>;
[K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K] & {}, TEvent, TAction>;
};
export declare type StatesDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
[K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K], TEvent>;
[K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K] & {}, TEvent>;
};
export declare type TransitionConfigTarget<TContext, TEvent extends EventObject> = string | undefined | StateNode<TContext, any, TEvent>;
export declare type TransitionConfigOrTarget<TContext, TEvent extends EventObject> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TEvent>>;
export declare type TransitionConfigOrTarget<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TExpressionEvent, TEvent>>;
export declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
[K in TEvent['type']]?: TransitionConfigOrTarget<TContext, TEvent extends {
type: K;
} ? TEvent : never>;
} & {
''?: TransitionConfigOrTarget<TContext, TEvent>;
} & {
'*'?: TransitionConfigOrTarget<TContext, TEvent>;
[K in TEvent['type'] | '' | '*']?: K extends '' | '*' ? TransitionConfigOrTarget<TContext, TEvent> : TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent>;
};

@@ -258,3 +278,3 @@ declare type TransitionsConfigArray<TContext, TEvent extends EventObject> = Array<(TEvent extends EventObject ? TransitionConfig<TContext, TEvent> & {

*/
src: string | InvokeSourceDefinition | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent, any>;
src: string | InvokeSourceDefinition | AnyStateMachine | InvokeCreator<TContext, TEvent, any>;
/**

@@ -282,7 +302,7 @@ * If `true`, events sent to the parent service will be forwarded to the invoked service.

*/
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
/**
* The transition to take upon the invoked child machine sending an error event.
*/
onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneInvokeEvent<any>>>;
/**

@@ -330,3 +350,3 @@ * Meta data related to this invocation

*/
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent> | StateMachine<any, any, any>>;
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent> | AnyStateMachine>;
/**

@@ -345,3 +365,3 @@ * The mapping of event types to their potential transition(s).

*/
entry?: BaseActions<TContext, TEvent, TAction>;
entry?: BaseActions<TContext, TEvent, TEvent, TAction>;
/**

@@ -356,3 +376,3 @@ * The action(s) to be executed upon exiting the state node.

*/
exit?: BaseActions<TContext, TEvent, TAction>;
exit?: BaseActions<TContext, TEvent, TEvent, TAction>;
/**

@@ -424,2 +444,8 @@ * The potential transition(s) to be taken upon reaching a final child state node.

/**
* Whether XState calls actions with the event directly responsible for the related transition.
*
* @default false
*/
predictableActionArguments?: boolean;
/**
* A text description of the state node

@@ -454,2 +480,4 @@ */

export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
export declare type AnyState = State<any, any, any, any, any>;
export declare type AnyStateMachine = StateMachine<any, any, any, any, any, any, any>;
export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {

@@ -474,3 +502,3 @@ initial?: undefined;

export declare type SimpleOrStateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TStateSchema, TEvent>;
export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = {
export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
[K in TAction['type']]?: ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent, TAction extends {

@@ -481,27 +509,46 @@ type: K;

export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | AnyStateMachine | InvokeCreator<TContext, TEvent>;
export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
export interface MachineOptions<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> {
guards: Record<string, ConditionPredicate<TContext, TEvent>>;
actions: ActionFunctionMap<TContext, TEvent, TAction>;
declare type MachineOptionsActions<TContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>> = {
[K in keyof TEventsCausingActions]?: ActionObject<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>> | ActionFunction<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
};
declare type MachineOptionsDelays<TContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingDelays'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>> = {
[K in keyof TEventsCausingDelays]?: DelayConfig<TContext, Cast<Prop<TIndexedEvents, TEventsCausingDelays[K]>, EventObject>>;
};
declare type MachineOptionsGuards<TContext, TResolvedTypesMeta, TEventsCausingGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingGuards'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>> = {
[K in keyof TEventsCausingGuards]?: ConditionPredicate<TContext, Cast<Prop<TIndexedEvents, TEventsCausingGuards[K]>, EventObject>>;
};
declare type MachineOptionsServices<TContext, TResolvedTypesMeta, TEventsCausingServices = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingServices'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
[K in keyof TEventsCausingServices]?: AnyStateMachine | InvokeCreator<TContext, Cast<Prop<TIndexedEvents, TEventsCausingServices[K]>, EventObject>, Prop<Prop<TIndexedEvents, Prop<TInvokeSrcNameMap, K>>, 'data'>, EventObject, Cast<TIndexedEvents[keyof TIndexedEvents], EventObject>>;
};
declare type MakeKeysRequired<T extends string> = {
[K in T]: unknown;
};
declare type MaybeMakeMissingImplementationsRequired<TImplementationType, TMissingImplementationsForType, TRequireMissingImplementations> = TRequireMissingImplementations extends true ? IsNever<TMissingImplementationsForType> extends true ? {} : {
[K in Cast<TImplementationType, string>]: MakeKeysRequired<Cast<TMissingImplementationsForType, string>>;
} : {};
declare type GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
actions?: MachineOptionsActions<TContext, TResolvedTypesMeta>;
};
declare type GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'delays', Prop<TMissingImplementations, 'delays'>, TRequireMissingImplementations> & {
delays?: MachineOptionsDelays<TContext, TResolvedTypesMeta>;
};
declare type GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
guards?: MachineOptionsGuards<TContext, TResolvedTypesMeta>;
};
declare type GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'services', Prop<TMissingImplementations, 'services'>, TRequireMissingImplementations> & {
services?: MachineOptionsServices<TContext, TResolvedTypesMeta>;
};
export declare type InternalMachineOptions<TContext, TEvent extends EventObject, TResolvedTypesMeta, TRequireMissingImplementations extends boolean = false, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & {
/**
* @deprecated Use `services` instead.
*/
activities: Record<string, ActivityConfig<TContext, TEvent>>;
services: Record<string, ServiceConfig<TContext, TEvent>>;
delays: DelayFunctionMap<TContext, TEvent>;
activities?: Record<string, ActivityConfig<TContext, TEvent>>;
};
export declare type MachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta = TypegenDisabled> extends StateNodeConfig<NoInfer<TContext>, TStateSchema, NoInfer<TEvent>, TAction> {
/**
* @private
*/
_parent?: StateNode<TContext, any, TEvent, any>;
/**
* @private
*/
_key?: string;
}
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = ActionObject<TContext, TEvent>> extends StateNodeConfig<TContext, TStateSchema, TEvent, TAction> {
/**
* The initial context (extended state)
*/
context?: TContext | (() => TContext);
context?: LowInfer<TContext | (() => TContext)>;
/**

@@ -511,5 +558,9 @@ * The machine's own version.

version?: string;
schema?: MachineSchema<TContext, TEvent>;
schema?: MachineSchema<TContext, TEvent, TServiceMap>;
tsTypes?: TTypesMeta;
}
export interface MachineSchema<TContext, TEvent extends EventObject> {
export declare type ServiceMap = Record<string, {
data: any;
}>;
export interface MachineSchema<TContext, TEvent extends EventObject, TServiceMap extends ServiceMap = ServiceMap> {
context?: TContext;

@@ -525,6 +576,3 @@ events?: TEvent;

};
services?: {
type: string;
[key: string]: any;
};
services?: TServiceMap;
}

@@ -545,12 +593,27 @@ export interface StandardMachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {

}
/** @ts-ignore TS complains about withConfig & withContext not being compatible here when extending StateNode */
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
value: any;
context: TContext;
}, _TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TServiceMap>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta> {
id: string;
states: StateNode<TContext, TStateSchema, TEvent>['states'];
withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, TResolvedTypesMeta>;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TContext: TContext;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TStateSchema: TStateSchema;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TEvent: TEvent;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TTypestate: TTypestate;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TAction: TAction;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TServiceMap: TServiceMap;
/** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
__TResolvedTypesMeta: TResolvedTypesMeta;
}
export declare type StateFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
export declare type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? ReturnType<T['transition']> : T extends (...args: any[]) => AnyStateMachine ? ReturnType<ReturnType<T>['transition']> : never;
export interface ActionMap<TContext, TEvent extends EventObject> {

@@ -574,9 +637,8 @@ onEntry: Array<Action<TContext, TEvent>>;

transitions: Array<TransitionDefinition<TContext, TEvent>>;
configuration: Array<StateNode<TContext, any, TEvent, any>>;
entrySet: Array<StateNode<TContext, any, TEvent, any>>;
exitSet: Array<StateNode<TContext, any, TEvent, any>>;
configuration: Array<StateNode<TContext, any, TEvent, any, any, any>>;
exitSet: Array<StateNode<TContext, any, TEvent, any, any, any>>;
/**
* The source state that preceded the transition.
*/
source: State<TContext, any, any, any> | undefined;
source: State<TContext, any, any, any, any> | undefined;
actions: Array<ActionObject<TContext, TEvent>>;

@@ -611,9 +673,13 @@ }

}
export interface RaiseAction<TEvent extends EventObject> {
export interface RaiseAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Raise;
event: TEvent['type'];
event: TEvent | SendExpr<TContext, TExpressionEvent, TEvent>;
delay: number | string | undefined | DelayExpr<TContext, TExpressionEvent>;
id: string | number | undefined;
}
export interface RaiseActionObject<TEvent extends EventObject> {
export interface RaiseActionObject<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends RaiseAction<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Raise;
_event: SCXML.Event<TEvent>;
delay: number | undefined;
id: string | number | undefined;
}

@@ -637,3 +703,3 @@ export interface DoneInvokeEvent<TData> extends EventObject {

id: string | number;
state: State<any, any>;
state: AnyState;
}

@@ -654,5 +720,6 @@ export declare type DoneEvent = DoneEventObject & string;

export declare type LogExpr<TContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, any>;
export interface LogAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface LogAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Log;
label: string | undefined;
expr: string | LogExpr<TContext, TEvent>;
expr: string | LogExpr<TContext, TExpressionEvent>;
}

@@ -662,3 +729,4 @@ export interface LogActionObject<TContext, TEvent extends EventObject> extends LogAction<TContext, TEvent> {

}
export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent, TSentEvent> {
type: ActionTypes.Send;
to: string | number | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>> | undefined;

@@ -676,7 +744,7 @@ event: TSentEvent | SendExpr<TContext, TEvent, TSentEvent>;

}
export interface StopAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface StopAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Stop;
activity: string | {
id: string;
} | Expr<TContext, TEvent, string | {
} | Expr<TContext, TExpressionEvent, string | {
id: string;

@@ -698,8 +766,11 @@ }>;

}
export interface SendActionOptions<TContext, TEvent extends EventObject> {
export interface SendActionOptions<TContext, TEvent extends EventObject> extends RaiseActionOptions<TContext, TEvent> {
to?: string | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | ActorRef<any>>;
}
export interface RaiseActionOptions<TContext, TEvent extends EventObject> {
id?: string | number;
delay?: number | string | DelayExpr<TContext, TEvent>;
to?: string | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>>;
}
export interface CancelAction extends ActionObject<any, any> {
export interface CancelAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Cancel;
sendId: string | number;

@@ -720,15 +791,15 @@ }

}
export interface AssignAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface AssignAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Assign;
assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>;
assignment: Assigner<TContext, TExpressionEvent> | PropertyAssigner<TContext, TExpressionEvent>;
}
export interface PureAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface PureAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Pure;
get: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined;
get: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent> | ActionObject<TContext, TEvent>['type'] | ActionFunction<TContext, TEvent>> | undefined;
}
export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
export interface ChooseAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> extends ActionObject<TContext, TExpressionEvent, TEvent> {
type: ActionTypes.Choose;
conds: Array<ChooseCondition<TContext, TEvent>>;
}
export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
export interface TransitionDefinition<TContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, any>, 'actions'> {
target: Array<StateNode<TContext, any, TEvent>> | undefined;

@@ -809,3 +880,3 @@ source: StateNode<TContext, any, TEvent>;

export interface StateMeta<TContext, TEvent extends EventObject> {
state: State<TContext, TEvent, any, any>;
state: State<TContext, TEvent, any, any, any>;
_event: SCXML.Event<TEvent>;

@@ -829,3 +900,3 @@ }

historyValue?: HistoryValue | undefined;
history?: State<TContext, TEvent>;
history?: State<TContext, TEvent, any, any, any>;
actions?: Array<ActionObject<TContext, TEvent>>;

@@ -837,2 +908,5 @@ /**

meta?: any;
/**
* @deprecated
*/
events?: TEvent[];

@@ -844,4 +918,5 @@ configuration: Array<StateNode<TContext, any, TEvent>>;

tags?: Set<string>;
machine?: StateMachine<TContext, any, TEvent, any>;
machine?: StateMachine<TContext, any, TEvent, any, any, any, any>;
}
export declare type AnyStateConfig = StateConfig<any, AnyEventObject>;
export interface StateSchema<TC = any> {

@@ -858,5 +933,5 @@ meta?: any;

*/
execute: boolean;
clock: Clock;
logger: (...args: any[]) => void;
execute?: boolean;
clock?: Clock;
logger?: (...args: any[]) => void;
parent?: AnyInterpreter;

@@ -870,3 +945,3 @@ /**

*/
deferEvents: boolean;
deferEvents?: boolean;
/**

@@ -881,4 +956,3 @@ * The custom `id` for referencing this service.

*/
devTools: boolean | object;
[option: string]: any;
devTools?: boolean | object;
}

@@ -955,14 +1029,18 @@ export declare namespace SCXML {

}
export interface Subscribable<T> {
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
export interface InteropObservable<T> {
[Symbol.observable]: () => InteropSubscribable<T>;
}
export interface InteropSubscribable<T> {
subscribe(observer: Observer<T>): Subscription;
}
export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
type: TEventType;
} ? TEvent : never;
export interface Subscribable<T> extends InteropSubscribable<T> {
subscribe(observer: Observer<T>): Subscription;
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
}
export declare type Spawnable = AnyStateMachine | PromiseLike<any> | InvokeCallback | InteropObservable<any> | Subscribable<any> | Behavior<any>;
export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends any ? TEventType extends TEvent['type'] ? TEvent : never : never;
export interface BaseActorRef<TEvent extends EventObject> {
send: (event: TEvent) => void;
}
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted>, InteropObservable<TEmitted> {
send: Sender<TEvent>;

@@ -974,2 +1052,3 @@ id: string;

}
export declare type AnyActorRef = ActorRef<any, any>;
/**

@@ -979,11 +1058,13 @@ * @deprecated Use `ActorRef` instead.

export declare type SpawnedActorRef<TEvent extends EventObject, TEmitted = any> = ActorRef<TEvent, TEmitted>;
export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext>> = ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventObject, TTypestate extends Typestate<TContext>, TResolvedTypesMeta = TypegenDisabled> = ActorRef<TEvent, State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>> & {
/**
* @deprecated Use `.getSnapshot()` instead.
*/
state: State<TContext, TEvent, any, TTypestate>;
state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>;
};
export declare type ActorRefFrom<T> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : T extends (...args: any[]) => Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
export declare type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : R extends Promise<infer U> ? ActorRef<never, U> : R extends Behavior<infer TEvent, infer TEmitted> ? ActorRef<TEvent, TEmitted> : never : never;
export declare type AnyInterpreter = Interpreter<any, any, any, any, any>;
export declare type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta> : never;
export declare type MachineOptionsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, any, infer TEvent, any, any, any, infer TResolvedTypesMeta> ? InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, TRequireMissingImplementations> : never;
export declare type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
export interface ActorContext<TEvent extends EventObject, TEmitted> {

@@ -1000,9 +1081,14 @@ parent?: ActorRef<any, any>;

}
export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : Extract<TEvent, {
type: K;
}>;
export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer ___, infer ____, infer _____, infer ______, infer _______> ? R['initialState'] : R extends Interpreter<infer _, infer __, infer ___, infer ____, infer _____> ? R['initialState'] : R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ___, infer ____, infer _____, infer ______> ? TEvent : R extends Model<infer _, infer TEvent, infer __, infer ___> ? TEvent : R extends State<infer _, infer TEvent, infer __, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ___, infer ____> ? TEvent : R extends ActorRef<infer TEvent, infer _> ? TEvent : never : never;
export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___, infer ____, infer _____, infer ______> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___, infer ____> ? TContext : never : never;
declare type Matches<TypegenEnabledArg, TypegenDisabledArg> = {
(stateValue: TypegenEnabledArg): any;
(stateValue: TypegenDisabledArg): any;
};
export declare type StateValueFrom<TMachine extends AnyStateMachine> = StateFrom<TMachine>['matches'] extends Matches<infer TypegenEnabledArg, infer TypegenDisabledArg> ? TMachine['__TResolvedTypesMeta'] extends TypegenEnabled ? TypegenEnabledArg : TypegenDisabledArg : never;
export declare type PredictableActionArgumentsExec = (action: ActionObject<unknown, EventObject>, context: unknown, _event: SCXML.Event<EventObject>) => void;
export declare type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
export {};
//# sourceMappingURL=types.d.ts.map

@@ -5,2 +5,4 @@ 'use strict';

exports.ActionTypes = void 0;
(function (ActionTypes) {

@@ -29,2 +31,4 @@ ActionTypes["Start"] = "xstate.start";

exports.SpecialTargets = void 0;
(function (SpecialTargets) {

@@ -31,0 +35,0 @@ SpecialTargets["Parent"] = "#_parent";

@@ -1,5 +0,6 @@

import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, StateMachine, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior } from './types';
import { Event, StateValue, ActionType, Action, EventObject, PropertyMapper, Mapper, EventType, HistoryValue, AssignAction, Condition, Subscribable, ConditionPredicate, SCXML, StateLike, EventData, TransitionConfig, TransitionConfigTarget, NullEvent, SingleOrArray, Guard, InvokeSourceDefinition, Observer, Behavior, RaiseActionObject, SendActionObject } from './types';
import { StateNode } from './StateNode';
import { State } from './State';
import { Actor } from './Actor';
import { ActionObject, AnyStateMachine } from '.';
export declare function keys<T extends object>(value: T): Array<keyof T & string>;

@@ -13,5 +14,3 @@ export declare function matchesState(parentStateId: StateValue, childStateId: StateValue, delimiter?: string): boolean;

export declare function pathToStateValue(statePath: string[]): StateValue;
export declare function mapValues<T, P, O extends {
[key: string]: T;
}>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
[key in keyof O]: P;

@@ -56,4 +55,7 @@ };

export declare function isObservable<T>(value: any): value is Subscribable<T>;
export declare const symbolObservable: any;
export declare function isMachine(value: any): value is StateMachine<any, any, any>;
export declare const symbolObservable: typeof Symbol.observable;
export declare const interopSymbols: {
[Symbol.observable]: () => any;
};
export declare function isMachine(value: any): value is AnyStateMachine;
export declare function isActor(value: any): value is Actor;

@@ -68,5 +70,7 @@ export declare const uniqueId: () => string;

export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
export declare function toObserver<T>(nextHandler?: Partial<Observer<T>> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
export declare function createInvokeId(stateNodeId: string, index: number): string;
export declare function isRaisableAction<TContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(action: ActionObject<TContext, TExpressionEvent, TEvent>): action is RaiseActionObject<TContext, TExpressionEvent, TEvent> | SendActionObject<TContext, TExpressionEvent, TEvent>;
//# sourceMappingURL=utils.d.ts.map

@@ -6,5 +6,8 @@ 'use strict';

var _tslib = require('./_virtual/_tslib.js');
var types = require('./types.js');
var actionTypes = require('./actionTypes.js');
var constants = require('./constants.js');
var environment = require('./environment.js');
var _a;
function keys(value) {

@@ -34,3 +37,3 @@ return Object.keys(value);

return keys(parentStateValue).every(function (key) {
return Object.keys(parentStateValue).every(function (key) {
if (!(key in childStateValue)) {

@@ -50,2 +53,9 @@ return false;

}
function getActionType(action) {
try {
return isString(action) || typeof action === 'number' ? "".concat(action) : isFunction(action) ? action.name : action.type;
} catch (e) {
throw new Error('Actions must be strings or objects with a string action.type property.');
}
}
function toStatePath(stateId, delimiter) {

@@ -102,3 +112,3 @@ try {

var result = {};
var collectionKeys = keys(collection);
var collectionKeys = Object.keys(collection);

@@ -118,3 +128,3 @@ for (var i = 0; i < collectionKeys.length; i++) {

try {
for (var _b = _tslib.__values(keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = _tslib.__values(Object.keys(collection)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;

@@ -214,3 +224,3 @@ var item = collection[key];

var result = flatten(keys(stateValue).map(function (key) {
var result = flatten(Object.keys(stateValue).map(function (key) {
var subStateValue = stateValue[key];

@@ -228,2 +238,42 @@

}
function pathsToStateValue(paths) {
var e_4, _a;
var result = {};
if (paths && paths.length === 1 && paths[0].length === 1) {
return paths[0][0];
}
try {
for (var paths_1 = _tslib.__values(paths), paths_1_1 = paths_1.next(); !paths_1_1.done; paths_1_1 = paths_1.next()) {
var currentPath = paths_1_1.value;
var marker = result; // tslint:disable-next-line:prefer-for-of
for (var i = 0; i < currentPath.length; i++) {
var subPath = currentPath[i];
if (i === currentPath.length - 2) {
marker[subPath] = currentPath[i + 1];
break;
}
marker[subPath] = marker[subPath] || {};
marker = marker[subPath];
}
}
} catch (e_4_1) {
e_4 = {
error: e_4_1
};
} finally {
try {
if (paths_1_1 && !paths_1_1.done && (_a = paths_1.return)) _a.call(paths_1);
} finally {
if (e_4) throw e_4.error;
}
}
return result;
}
function flatten(array) {

@@ -375,3 +425,3 @@ var _a;

try {
for (var _b = _tslib.__values(keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
for (var _b = _tslib.__values(Object.keys(assignment)), _c = _b.next(); !_c.done; _c = _b.next()) {
var key = _c.value;

@@ -430,14 +480,3 @@ var propAssignment = assignment[key];

return typeof value === 'string';
} // export function memoizedGetter<T, TP extends { prototype: object }>(
// o: TP,
// property: string,
// getter: () => T
// ): void {
// Object.defineProperty(o.prototype, property, {
// get: getter,
// enumerable: false,
// configurable: false
// });
// }
}
function toGuard(condition, guardMap) {

@@ -475,9 +514,11 @@ if (!condition) {

return typeof Symbol === 'function' && Symbol.observable || '@@observable';
}();
}(); // TODO: to be removed in v5, left it out just to minimize the scope of the change and maintain compatibility with older versions of integration paackages
var interopSymbols = (_a = {}, _a[symbolObservable] = function () {
return this;
}, _a[Symbol.observable] = function () {
return this;
}, _a);
function isMachine(value) {
try {
return '__xstatenode' in value;
} catch (e) {
return false;
}
return !!value && '__xstatenode' in value;
}

@@ -565,3 +606,3 @@ function isActor(value) {

var condFn = guards[guard.type];
var condFn = guards === null || guards === void 0 ? void 0 : guards[guard.type];

@@ -584,20 +625,25 @@ if (!condFn) {

function toObserver(nextHandler, errorHandler, completionHandler) {
if (typeof nextHandler === 'object') {
return nextHandler;
}
var noop = function () {};
var noop = function () {
return void 0;
};
var isObserver = typeof nextHandler === 'object';
var self = isObserver ? nextHandler : null;
return {
next: nextHandler,
error: errorHandler || noop,
complete: completionHandler || noop
next: ((isObserver ? nextHandler.next : nextHandler) || noop).bind(self),
error: ((isObserver ? nextHandler.error : errorHandler) || noop).bind(self),
complete: ((isObserver ? nextHandler.complete : completionHandler) || noop).bind(self)
};
}
function createInvokeId(stateNodeId, index) {
return "".concat(stateNodeId, ":invocation[").concat(index, "]");
}
function isRaisableAction(action) {
return (action.type === actionTypes.raise || action.type === actionTypes.send && action.to === types.SpecialTargets.Internal) && typeof action.delay !== 'number';
}
exports.createInvokeId = createInvokeId;
exports.evaluateGuard = evaluateGuard;
exports.flatten = flatten;
exports.getActionType = getActionType;
exports.getEventType = getEventType;
exports.interopSymbols = interopSymbols;
exports.isActor = isActor;

@@ -611,2 +657,3 @@ exports.isArray = isArray;

exports.isPromiseLike = isPromiseLike;
exports.isRaisableAction = isRaisableAction;
exports.isStateLike = isStateLike;

@@ -624,2 +671,3 @@ exports.isString = isString;

exports.pathToStateValue = pathToStateValue;
exports.pathsToStateValue = pathsToStateValue;
exports.reportUnhandledExceptionOnInvocation = reportUnhandledExceptionOnInvocation;

@@ -626,0 +674,0 @@ exports.symbolObservable = symbolObservable;

{
"name": "xstate",
"version": "4.27.0",
"version": "4.38.2",
"description": "Finite State Machines and Statecharts for the Modern Web.",

@@ -33,7 +33,7 @@ "main": "lib/index.js",

"build": "rollup -c",
"prepublishOnly": "npm run build"
"prepare": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/davidkpiano/xstate.git"
"url": "git+https://github.com/statelyai/xstate.git"
},

@@ -43,5 +43,5 @@ "author": "David Khourshid <davidkpiano@gmail.com>",

"bugs": {
"url": "https://github.com/davidkpiano/xstate/issues"
"url": "https://github.com/statelyai/xstate/issues"
},
"homepage": "https://github.com/davidkpiano/xstate/tree/main/packages/core#readme",
"homepage": "https://github.com/statelyai/xstate/tree/main/packages/core#readme",
"devDependencies": {

@@ -53,2 +53,3 @@ "@babel/cli": "^7.10.5",

"babel-plugin-annotate-pure-calls": "^0.4.0",
"fast-glob": "^3.2.11",
"jest": "^26.6.3",

@@ -59,3 +60,3 @@ "jsdom": "^14.0.0",

"pkg-up": "^3.1.0",
"rollup": "^2.35.1",
"rollup": "^2.69.0",
"rollup-plugin-filesize": "^6.2.1",

@@ -69,5 +70,5 @@ "rollup-plugin-replace": "^2.2.0",

"tslib": "^2.3.1",
"typescript": "^4.5.2",
"typescript": "^4.8.4",
"xml-js": "^1.6.11"
}
}

@@ -24,6 +24,6 @@ <p align="center">

- 🤖 `xstate` - Core finite state machine and statecharts library + interpreter
- [🔬 `@xstate/fsm`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-fsm) - Minimal finite state machine library
- [📉 `@xstate/graph`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-graph) - Graph traversal utilities for XState
- [⚛️ `@xstate/react`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-react) - React hooks and utilities for using XState in React applications
- [✅ `@xstate/test`](https://github.com/davidkpiano/xstate/tree/main/packages/xstate-test) - Model-based testing utilities for XState
- [🔬 `@xstate/fsm`](https://github.com/statelyai/xstate/tree/main/packages/xstate-fsm) - Minimal finite state machine library
- [📉 `@xstate/graph`](https://github.com/statelyai/xstate/tree/main/packages/xstate-graph) - Graph traversal utilities for XState
- [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/main/packages/xstate-react) - React hooks and utilities for using XState in React applications
- [✅ `@xstate/test`](https://github.com/statelyai/xstate/tree/main/packages/xstate-test) - Model-based testing utilities for XState

@@ -67,3 +67,3 @@ ## Super quick start

- [Finite State Machines](#finite-state-machines)
- [Hierarchical (Nested) State Machines](#hierarchical-nested-state-machines)
- [Hierarchical (Nested) State Machines](#hierarchical--nested--state-machines)
- [Parallel State Machines](#parallel-state-machines)

@@ -88,3 +88,4 @@ - [History States](#history-states)

- [Pure UI Control](https://medium.com/@asolove/pure-ui-control-ac8d1be97a8d) by Adam Solove
- [Spectrum - Statecharts Community](https://spectrum.chat/statecharts) (For XState specific questions, please use the [GitHub Discussions](https://github.com/davidkpiano/xstate/discussions))
- [Stately Discord](https://discord.gg/xstate) chat about anything related to statecharts and XState
- [GitHub Discussions](https://github.com/statelyai/xstate/discussions)

@@ -91,0 +92,0 @@ ## Finite State Machines

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc