xstate 4.30.1 → 4.30.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/Actor.d.ts +1 -1
- package/es/Actor.js +15 -6
- package/es/State.d.ts +3 -2
- package/es/State.js +0 -5
- package/es/index.d.ts +2 -2
- package/es/index.js +1 -0
- package/es/interpreter.d.ts +4 -3
- package/es/interpreter.js +29 -19
- package/es/types.d.ts +7 -4
- package/es/utils.d.ts +1 -2
- package/es/utils.js +4 -1
- package/lib/Actor.d.ts +1 -1
- package/lib/Actor.js +14 -5
- package/lib/State.d.ts +3 -2
- package/lib/State.js +0 -5
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -0
- package/lib/interpreter.d.ts +4 -3
- package/lib/interpreter.js +28 -18
- package/lib/types.d.ts +7 -4
- package/lib/utils.d.ts +1 -2
- package/lib/utils.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# xstate
|
|
2
2
|
|
|
3
|
+
## 4.30.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3063](https://github.com/statelyai/xstate/pull/3063) [`c826559b4`](https://github.com/statelyai/xstate/commit/c826559b4c495f64c85dd79f1d1262ae9e7d15bf) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a type compatibility with Svelte's readables. It should be possible again to use XState interpreters directly as readables at the type-level.
|
|
8
|
+
|
|
9
|
+
* [#3051](https://github.com/statelyai/xstate/pull/3051) [`04091f29c`](https://github.com/statelyai/xstate/commit/04091f29cb80dd8e6c95e42668bd56f02f775973) Thanks [@Andarist](https://github.com/Andarist)! - Fixed type compatibility with functions accepting machines that were created before typegen was a thing in XState. This should make it possible to use the latest version of XState with `@xstate/vue`, `@xstate/react@^1` and some community packages.
|
|
10
|
+
|
|
11
|
+
Note that this change doesn't make those functions to accept machines that have typegen information on them. For that the signatures of those functions would have to be adjusted.
|
|
12
|
+
|
|
13
|
+
- [#3077](https://github.com/statelyai/xstate/pull/3077) [`2c76ecac5`](https://github.com/statelyai/xstate/commit/2c76ecac5de73fbb3a2376a0f66802480ec9549f) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with nested `state.matches` calls when the typegen was involved. The `state` ended up being `never` and thus not usable.
|
|
14
|
+
|
|
3
15
|
## 4.30.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */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,u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function f(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function l(t,e,n){var r,o;if(v(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];v(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}var g=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}(),m=((a={})[g]=function(){return this},a);function b(t){try{return"__xstatenode"in t}catch(t){return!1}}var x=function(){var t=0;return function(){return(++t).toString(16)}}();function w(t,e){return y(t)||"number"==typeof t?r({type:t},e):t}function S(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=w(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function _(t){return c(t.states).map((function(e){return t.states[e]}))}function O(t){return s([],o(new Set(function(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}function T(t,e){return"compound"===e.type?_(e).some((function(e){return"final"===e.type&&(n=t,r=e,Array.isArray(n)?n.some((function(t){return t===r})):n instanceof Set&&n.has(r));var n,r})):"parallel"===e.type&&_(e).every((function(e){return T(t,e)}))}var I=e.Start,L=e.Stop,k=(e.Raise,e.Send),j=e.Cancel,C=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),P=e.Init,N=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),A=e.ErrorCustom,D=e.Update,M=(e.Choose,e.Pure,S({type:P}));function R(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function z(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}var V=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=(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 O(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:M,_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=M;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="."),y(t))return[t];var r=c(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,e=(t.configuration,t.transitions,t.tags),n=(t.machine,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=h(e,r),o=h(n,r);return y(o)?!!y(i)&&o===i:y(i)?i in o:c(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}(),J={deferEvents:!1},q=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},J),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),U=[],$=function(t,e){U.push(t);var n=e(t);return U.pop(),n};function F(t,e,n){var i=function(t){return r({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},m)}(e);if(i.deferred=!0,b(t)){var o=i.state=$(void 0,(function(){return(n?t.withContext(n):t).initialState}));i.getSnapshot=function(){return o}}return i}var X=new Map,B=0,G=function(){return"x:".concat(B++)},H=function(t,e){return X.set(t,e),t},K=function(t){return X.get(t)},Q=function(t){X.delete(t)};function W(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Y(t){if(W()){var e=function(){var t=W();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Z(t,e){void 0===e&&(e={});var n,i=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();i=t.transition(i,e,c),o.forEach((function(t){return t.next(i)}))}a=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=E(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},r(r({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},m),n)),c={parent:e.parent,self:u,id:e.id||"anonymous",observers:o};return i=t.start?t.start(c):i,u}var tt,et={sync:!1,autoForward:!1};(tt=t.InterpreterStatus||(t.InterpreterStatus={}))[tt.NotStarted=0]="NotStarted",tt[tt.Running=1]="Running",tt[tt.Stopped=2]="Stopped";var nt=function(){function a(e,i){var o=this;void 0===i&&(i=a.defaultOptions),this.machine=e,this.scheduler=new q,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(p(e))return o.batch(e),o.state;var r=S(w(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(t,e){var i,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:y(e)?o.children.get(e)||K(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===A?"".concat(z(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=r(r({},a.defaultOptions),i),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 q({deferEvents:this.options.deferEvents}),this.sessionId=G()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:$(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,u,c,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 d=i(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&&(r=d.return)&&r.call(d)}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&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var b=T(t.configuration||[],this.machine);if(this.state.configuration&&b){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?l(x.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(R(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,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var s=r;return"function"==typeof e?i=e:(i=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),s&&this.onDone(s),{unsubscribe:function(){i&&o.listeners.delete(i),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;H(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:$(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(V.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,M)})),this},a.prototype.stop=function(){var e,n,r,a,u,h,f,l,d,p,y=this;try{for(var g=i(this.listeners),m=g.next();!m.done;m=g.next()){var b=m.value;this.listeners.delete(b)}}catch(t){e={error:t}}finally{try{m&&!m.done&&(n=g.return)&&n.call(g)}finally{if(e)throw e.error}}try{for(var x=i(this.stopListeners),w=x.next();!w.done;w=x.next()){(b=w.value)(),this.stopListeners.delete(b)}}catch(t){r={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(r)throw r.error}}try{for(var S=i(this.contextListeners),E=S.next();!E.done;E=S.next()){b=E.value;this.contextListeners.delete(b)}}catch(t){u={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(u)throw u.error}}try{for(var _=i(this.doneListeners),O=_.next();!O.done;O=_.next()){b=O.value;this.doneListeners.delete(b)}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}if(!this.initialized)return this;s([],o(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var r=i(t.definition.exit),o=r.next();!o.done;o=r.next()){var s=o.value;y.exec(s,y.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var T=i(c(this.delayedEventsMap)),I=T.next();!I.done;I=T.next()){var L=I.value;this.clock.clearTimeout(this.delayedEventsMap[L])}}catch(t){d={error:t}}finally{try{I&&!I.done&&(p=T.return)&&p.call(T)}finally{if(d)throw d.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Q(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=S(t);n.forward(e),u=$(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,i=(e=t).exec,r(r({},e),{exec:void 0!==i?function(){return i(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,i}))),!1)),c=c||!!u.changed};try{for(var l=i(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,S(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=S(t);if(0===n.name.indexOf(N)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(N)})))throw n.data.data;return $(this,(function(){return e.machine.transition(e.state,n)}))},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;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,r,i){void 0===i&&(i=this.machine.options.actions);var o,s=r.context,a=r._event,u=n.exec||function(t,e){return e&&e[t]||void 0}(n.type,i),c=v(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 k: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 j:this.cancel(n.sendId);break;case I:if(this.status!==t.InterpreterStatus.Running)return;var f=n.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===e.Invoke){var d="string"==typeof(o=f.src)?{type:o}:o,p=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=f.id,g=f.data,m="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var x=g?l(g,s,a):void 0;if("string"==typeof p)return;var w=v(p)?p(s,a.data,{data:x,src:d,meta:f.meta}):p;if(!w)return;var S=void 0;b(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),this.spawn(w,y,S)}else this.spawnActivity(f);break;case L:this.stopChild(n.activity.id);break;case C: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),v(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(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&&v(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(b(t))return this.spawnMachine(t,r(r({},n),{id:e}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'.concat(e,'" of type "').concat(typeof t,'".'));var i,o},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({},et),e);o.sync&&i.onTransition((function(t){n.send(D,{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(S(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=Z(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,i=this,o=!1;t.then((function(t){o||(n=t,i.removeChild(e),i.send(S(R(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=z(e,t);try{i.send(S(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=r({id:e,send:function(){},subscribe:function(e,n,r){var i=E(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 n}},m);return this.children.set(e,s),s},a.prototype.spawnCallback=function(t,e){var n,i,o=this,s=!1,a=new Set,u=new Set;try{i=t((function(t){n=t,u.forEach((function(e){return e(t)})),s||o.send(S(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(z(e,t))}if(d(i))return this.spawnPromise(i,e);var c=r({id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){return u.add(t),{unsubscribe:function(){u.delete(t)}}},stop:function(){s=!0,v(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}},m);return this.children.set(e,c),c},a.prototype.spawnObservable=function(t,e){var n,i=this,o=t.subscribe((function(t){n=t,i.send(S(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(S(z(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(S(R(e),{origin:e}))})),s=r({id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}},m);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){this.children.set(t,r({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},m))},a.prototype.attachDev=function(){var t=W();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)}Y(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[g]=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=rt,a}();function rt(t,e){return new nt(t,e)}t.Interpreter=nt,t.interpret=rt,t.spawn=function(t,e){var n=function(t){return y(t)?r(r({},et),{name:t}):r(r(r({},et),{name:x()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):F(t,n.name)}(U[U.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */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,u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function f(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function l(t,e,n){var r,o;if(v(t))return t(e,n.data);var s={};try{for(var a=i(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];v(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}var g=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();(a={})[g]=function(){return this},a[Symbol.observable]=function(){return this};function m(t){try{return"__xstatenode"in t}catch(t){return!1}}var b=function(){var t=0;return function(){return(++t).toString(16)}}();function x(t,e){return y(t)||"number"==typeof t?r({type:t},e):t}function w(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=x(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function S(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function E(t){return c(t.states).map((function(e){return t.states[e]}))}function _(t){return s([],o(new Set(function(t){var e;return(e=[]).concat.apply(e,s([],o(t),!1))}(s([],o(t.map((function(t){return t.ownEvents}))),!1)))),!1)}function O(t,e){return"compound"===e.type?E(e).some((function(e){return"final"===e.type&&(n=t,r=e,Array.isArray(n)?n.some((function(t){return t===r})):n instanceof Set&&n.has(r));var n,r})):"parallel"===e.type&&E(e).every((function(e){return O(t,e)}))}var T=e.Start,I=e.Stop,L=(e.Raise,e.Send),k=e.Cancel,j=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),C=e.Init,P=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),N=e.ErrorCustom,A=e.Update,D=(e.Choose,e.Pure,w({type:C}));function M(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function R(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}var z=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=(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 _(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:D,_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=D;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="."),y(t))return[t];var r=c(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,e=(t.configuration,t.transitions,t.tags),n=(t.machine,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=h(e,r),o=h(n,r);return y(o)?!!y(i)&&o===i:y(i)?i in o:c(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}(),V={deferEvents:!1},J=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},V),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}(),q=[],U=function(t,e){q.push(t);var n=e(t);return q.pop(),n};function $(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}}})[g]=function(){return this},e}(e);if(r.deferred=!0,m(t)){var i=r.state=U(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var F=new Map,X=0,B=function(){return"x:".concat(X++)},G=function(t,e){return F.set(t,e),t},H=function(t){return F.get(t)},K=function(t){F.delete(t)};function Q(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function W(t){if(Q()){var e=function(){var t=Q();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Y(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(){}})[g]=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,u),i.forEach((function(t){return t.next(n)}))}s=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,r){var o=S(t,e,r);return i.add(o),o.next(n),{unsubscribe:function(){i.delete(o)}}}}),u={parent:e.parent,self:a,id:e.id||"anonymous",observers:i};return n=t.start?t.start(u):n,a}var Z,tt={sync:!1,autoForward:!1};(Z=t.InterpreterStatus||(t.InterpreterStatus={}))[Z.NotStarted=0]="NotStarted",Z[Z.Running=1]="Running",Z[Z.Stopped=2]="Stopped";var et=function(){function a(e,i){var o=this;void 0===i&&(i=a.defaultOptions),this.machine=e,this.scheduler=new J,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(p(e))return o.batch(e),o.state;var r=w(x(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(t,e){var i,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:y(e)?o.children.get(e)||H(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===N?"".concat(R(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=r(r({},a.defaultOptions),i),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 J({deferEvents:this.options.deferEvents}),this.sessionId=B()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:U(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,u,c,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 d=i(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&&(r=d.return)&&r.call(d)}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&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var b=O(t.configuration||[],this.machine);if(this.state.configuration&&b){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?l(x.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(M(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,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var s=r;return"function"==typeof e?i=e:(i=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),s&&this.onDone(s),{unsubscribe:function(){i&&o.listeners.delete(i),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;G(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:U(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(z.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,D)})),this},a.prototype.stop=function(){var e,n,r,a,u,h,f,l,d,p,y=this;try{for(var g=i(this.listeners),m=g.next();!m.done;m=g.next()){var b=m.value;this.listeners.delete(b)}}catch(t){e={error:t}}finally{try{m&&!m.done&&(n=g.return)&&n.call(g)}finally{if(e)throw e.error}}try{for(var x=i(this.stopListeners),w=x.next();!w.done;w=x.next()){(b=w.value)(),this.stopListeners.delete(b)}}catch(t){r={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(r)throw r.error}}try{for(var S=i(this.contextListeners),E=S.next();!E.done;E=S.next()){b=E.value;this.contextListeners.delete(b)}}catch(t){u={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(u)throw u.error}}try{for(var _=i(this.doneListeners),O=_.next();!O.done;O=_.next()){b=O.value;this.doneListeners.delete(b)}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}if(!this.initialized)return this;s([],o(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var r=i(t.definition.exit),o=r.next();!o.done;o=r.next()){var s=o.value;y.exec(s,y.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var T=i(c(this.delayedEventsMap)),I=T.next();!I.done;I=T.next()){var L=I.value;this.clock.clearTimeout(this.delayedEventsMap[L])}}catch(t){d={error:t}}finally{try{I&&!I.done&&(p=T.return)&&p.call(T)}finally{if(d)throw d.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,K(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=w(t);n.forward(e),u=U(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,i=(e=t).exec,r(r({},e),{exec:void 0!==i?function(){return i(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,i}))),!1)),c=c||!!u.changed};try{for(var l=i(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,w(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=w(t);if(0===n.name.indexOf(P)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(P)})))throw n.data.data;return U(this,(function(){return e.machine.transition(e.state,n)}))},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;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,r,i){void 0===i&&(i=this.machine.options.actions);var o,s=r.context,a=r._event,u=n.exec||function(t,e){return e&&e[t]||void 0}(n.type,i),c=v(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 L: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 k:this.cancel(n.sendId);break;case T:if(this.status!==t.InterpreterStatus.Running)return;var f=n.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===e.Invoke){var d="string"==typeof(o=f.src)?{type:o}:o,p=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=f.id,g=f.data,b="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var x=g?l(g,s,a):void 0;if("string"==typeof p)return;var w=v(p)?p(s,a.data,{data:x,src:d,meta:f.meta}):p;if(!w)return;var S=void 0;m(w)&&(w=x?w.withContext(x):w,S={autoForward:b}),this.spawn(w,y,S)}else this.spawnActivity(f);break;case I:this.stopChild(n.activity.id);break;case j: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),v(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(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&&v(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(m(t))return this.spawnMachine(t,r(r({},n),{id:e}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'.concat(e,'" of type "').concat(typeof t,'".'));var i,o},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({},tt),e);o.sync&&i.onTransition((function(t){n.send(A,{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(w(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=Y(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(w(M(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=R(e,t);try{i.send(w(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=S(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}})[g]=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,u=new Set;try{i=t((function(t){r=t,u.forEach((function(e){return e(t)})),s||o.send(w(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(R(e,t))}if(d(i))return this.spawnPromise(i,e);var c=((n={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){var e=S(t);return u.add(e.next),{unsubscribe:function(){u.delete(e.next)}}},stop:function(){s=!0,v(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[g]=function(){return this},n);return this.children.set(e,c),c},a.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(w(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(w(R(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(w(M(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}}})[g]=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}}})[g]=function(){return this},n))},a.prototype.attachDev=function(){var t=Q();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)}W(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[g]=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=nt,a}();function nt(t,e){return new et(t,e)}t.Interpreter=et,t.interpret=nt,t.spawn=function(t,e){var n=function(t){return y(t)?r(r({},tt),{name:t}):r(r(r({},tt),{name:b()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):$(t,n.name)}(q[q.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/xstate.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */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,s={};function c(t){return Object.keys(t)}function u(t,e,n){void 0===n&&(n=".");var r=l(t,n),i=l(e,n);return O(i)?!!O(r)&&i===r:O(r)?r in i:c(r).every((function(t){return t in i&&u(r[t],i[t])}))}function h(t){try{return O(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 f(t,e){try{return A(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function l(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:A(t)?d(t):"string"!=typeof t?t:d(f(t,e));var n}function d(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function p(t,e){for(var n={},r=c(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function v(t,e,n){var i,o,a={};try{for(var s=r(c(t)),u=s.next();!u.done;u=s.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=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}var y=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 g(t){return t?O(t)?[[t]]:m(c(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?g(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function m(t){var e;return(e=[]).concat.apply(e,o([],i(t),!1))}function S(t){return A(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(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 b(t){return t instanceof Promise||!(null===t||!N(t)&&"object"!=typeof t||!N(t.then))}function _(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(t,e){return p(t.states,(function(t,n){if(t){var r=(O(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:T(t,r)}}}))}function E(t,e,n,i){return t?n.reduce((function(t,n){var o,a,s=n.assignment,u={state:i,action:n,_event:e},h={};if(N(s))h=s(t,e.data,u);else try{for(var f=r(c(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[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 A(t){return Array.isArray(t)}function N(t){return"function"==typeof t}function O(t){return"string"==typeof t}function P(t,e){if(t)return O(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:N(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var k=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}(),I=((a={})[k]=function(){return this},a);function j(t){try{return"__xstatenode"in t}catch(t){return!1}}var C,V,D=function(){var t=0;return function(){return(++t).toString(16)}}();function L(t,n){return O(t)||"number"==typeof t?e({type:t},n):t}function R(t,n){if(!O(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return S(n).map((function(n){return void 0===n||"string"==typeof n||j(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function z(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=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,r.data,a)}function F(t){return"string"==typeof t?{type:t}:t}function U(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function B(t,e){return"".concat(t,":invocation[").concat(e,"]")}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",C.Choose="xstate.choose",(V=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",V.Internal="#_internal";var J=function(t){return"atomic"===t.type||"final"===t.type};function q(t){return c(t.states).map((function(e){return t.states[e]}))}function $(t){var e=[t];return J(t)?e:e.concat(m(q(t).map($)))}function X(t,e){var n,i,o,a,s,c,u,h,f=H(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=H(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(q(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 H(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 G(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(J(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,H(X([t],e)))}function K(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function Q(t,e){return"compound"===e.type?q(e).some((function(e){return"final"===e.type&&K(t,e)})):"parallel"===e.type&&q(e).every((function(e){return Q(t,e)}))}function W(t){return new Set(m(t.map((function(t){return t.tags}))))}var Y=t.ActionTypes.Start,Z=t.ActionTypes.Stop,tt=t.ActionTypes.Raise,et=t.ActionTypes.Send,nt=t.ActionTypes.Cancel,rt=t.ActionTypes.NullEvent,it=t.ActionTypes.Assign,ot=t.ActionTypes.After,at=t.ActionTypes.DoneState,st=t.ActionTypes.Log,ct=t.ActionTypes.Init,ut=t.ActionTypes.Invoke,ht=t.ActionTypes.ErrorExecution,ft=t.ActionTypes.ErrorPlatform,lt=t.ActionTypes.ErrorCustom,dt=t.ActionTypes.Update,pt=t.ActionTypes.Choose,vt=t.ActionTypes.Pure,yt=Object.freeze({__proto__:null,start:Y,stop:Z,raise:tt,send:et,cancel:nt,nullEvent:rt,assign:it,after:ot,doneState:at,log:st,init:ct,invoke:ut,errorExecution:ht,errorPlatform:ft,error:lt,update:dt,choose:pt,pure:vt}),gt=R({type:ct});function mt(t,e){return e&&e[t]||void 0}function St(t,n){var r;if(O(t)||"number"==typeof t)r=N(i=mt(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=mt(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 xt=function(t,e){return t?(A(t)?t:[t]).map((function(t){return St(t,e)})):[]};function wt(t){var n=St(t);return e(e({id:O(t)?t:n.id},n),{type:n.type})}function bt(e){return O(e)?{type:tt,event:e}:Tt(e,{to:t.SpecialTargets.Internal})}function _t(t){return{type:tt,_event:R(t.event)}}function Tt(t,e){return{to:e?e.to:void 0,type:et,event:N(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:N(t)?t.name:h(t)}}function Et(t,n,r,i){var o,a={_event:r},s=R(N(t.event)?t.event(n,r.data,a):t.event);if(O(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})}function At(n,r){return Tt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function Nt(){return At(dt)}var Ot=function(t,e){return{context:t,event:e}};var Pt=function(t,n,r){return e(e({},t),{value:O(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})},kt=function(t){return{type:nt,sendId:t}};function It(e){var n=wt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function jt(e){var n=N(e)?e:wt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function Ct(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}}var Vt=function(t){return{type:it,assignment:t}};function Dt(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Lt(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Rt(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Mt(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function zt(t,n){return Tt((function(t,e){return e}),e(e({},n),{to:t}))}function Ft(t,n,r,a,s,c){void 0===c&&(c=!1);var u=i(c?[[],s]:_(s,(function(t){return t.type===it})),2),h=u[0],f=u[1],l=h.length?E(r,a,h,n):r,d=c?[r]:void 0;return[m(f.map((function(r){var s;switch(r.type){case tt:return _t(r);case et:return Et(r,l,a,t.options.delays);case st:return Pt(r,l,a);case pt:if(!(p=null===(s=r.conds.find((function(e){var r=P(e.cond,t.options.guards);return!r||z(t,r,l,a,n)})))||void 0===s?void 0:s.actions))return[];var u=i(Ft(t,n,l,a,xt(x(p),t.options.actions),c),2),h=u[0],f=u[1];return l=f,null==d||d.push(l),h;case vt:var p;if(!(p=r.get(l,a.data)))return[];var v=i(Ft(t,n,l,a,xt(x(p),t.options.actions),c),2),y=v[0],g=v[1];return l=g,null==d||d.push(l),y;case Z:return Ct(r,l,a);case it:l=E(l,a,[r],n),null==d||d.push(l);break;default:var m=St(r,t.options.actions),S=m.exec;if(S&&d){var w=d.length-1;m=e(e({},m),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];S.apply(void 0,o([d[w]],i(e),!1))}})}return m}})).filter((function(t){return!!t}))),l]}var Ut=Object.freeze({__proto__:null,actionTypes:yt,initEvent:gt,getActionFunction:mt,toActionObject:St,toActionObjects:xt,toActivityDefinition:wt,raise:bt,resolveRaise:_t,send:Tt,resolveSend:Et,sendParent:At,sendTo:function(t,n,r){return Tt(n,e(e({},r),{to:t}))},sendUpdate:Nt,respond:function(t,n){return Tt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},log:function(t,e){return void 0===t&&(t=Ot),{type:st,label:e,expr:t}},resolveLog:Pt,cancel:kt,start:It,stop:jt,resolveStop:Ct,assign:Vt,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Dt,done:Lt,doneInvoke:Rt,error:Mt,pure:function(e){return{type:t.ActionTypes.Pure,get:e}},forwardTo:zt,escalate:function(n,r){return At((function(t,e,r){return{type:lt,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}},resolveActions:Ft});var Bt=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=s,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||s,this.meta=(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(m(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:gt,_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=gt;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="."),O(t))return[t];var r=c(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 u(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}(),Jt=[],qt=function(t,e){Jt.push(t);var n=e(t);return Jt.pop(),n};function $t(t){return e({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},I)}function Xt(t,e,n){var r=$t(e);if(r.deferred=!0,j(t)){var i=r.state=qt(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Ht(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Gt(t){return e(e({type:ut},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:ut,src:Ht(t.src)})}})}var Kt={},Qt=function(t){return"#"===t[0]},Wt=function(){function a(t,n,s,u){var h,f=this;void 0===s&&(s="context"in t?t.context:void 0),this.config=t,this._context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==u?void 0:u.parent,this.key=this.config.key||(null==u?void 0:u.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&&c(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(h=this.config.schema)&&void 0!==h?h:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?p(this.config.states,(function(t,n){var r,i=new a(t,{},void 0,{parent:f,key:n});return Object.assign(f.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Kt;var l=0;!function t(e){var n,i;e.order=l++;try{for(var o=r(q(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=x(this.config.entry||this.config.onEntry).map((function(t){return St(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return St(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var r,i;if(j(t)){var o=B(f.id,n);return f.machine.options.services=e(((r={})[o]=t,r),f.machine.options.services),Gt({src:o,id:o})}if(O(t.src)){o=t.id||B(f.id,n);return Gt(e(e({},t),{id:o,src:t.src}))}if(j(t.src)||N(t.src)){o=t.id||B(f.id,n);return f.machine.options.services=e(((i={})[o]=t.src,i),f.machine.options.services),Gt(e(e({id:o},t),{src:o}))}var a=t.src;return Gt(e(e({id:B(f.id,n)},t),{src:a}))})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return wt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||$(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:p(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=Dt(N(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(Tt(r,{delay:e})),t.onExit.push(kt(r)),r};return(A(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):m(c(n).map((function(t,i){var o=n[t],a=O(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(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 Bt?t.value:l(t,this.delimiter);if(O(r)){var a=this.getStateNode(r).initial;return void 0!==a?this.getStateNodes(((e={})[r]=a,e)):[this,this.states[r]]}var s=c(r),u=[this];return u.push.apply(u,o([],i(m(s.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),u},a.prototype.handles=function(t){var e=h(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=t instanceof Bt?t:Bt.create(t),r=Array.from(X([],this.getStateNodes(n.value)));return new Bt(e(e({},n),{value:this.resolve(n.value),configuration:r,done:Q(r,this),tags:W(r)}))},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=c(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 s=r(c(t)),u=s.next();!u.done;u=s.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=s.return)&&o.call(s)}finally{if(i)throw i.error}}var d=c(a).map((function(t){return a[t]})),p=m(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=m(d.map((function(t){return t.entrySet}))),y=m(c(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:m(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:m(c(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return O(t)?this.transitionLeafNode(t,e,n):1===c(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,R(e))},a.prototype.next=function(t,e){var n,a,s,c=this,h=e.name,f=[],d=[];try{for(var p=r(this.getCandidates(h)),v=p.next();!v.done;v=p.next()){var g=v.value,S=g.cond,x=g.in,w=t.context,b=!x||(O(x)&&Qt(x)?t.matches(l(this.getStateNodeById(x).path,this.delimiter)):u(l(x,this.delimiter),y(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||z(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!==g.target&&(d=g.target),f.push.apply(f,o([],i(g.actions),!1)),s=g;break}}}catch(t){n={error:t}}finally{try{v&&!v.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:f};var T=m(d.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),E=!!s.internal;return{transitions:[s],entrySet:E?[]:m(T.map((function(t){return c.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:T,source:t,actions:f}}},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=X([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?X(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){K(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=r(f),y=v.next();!y.done;y=v.next()){var g;K(l,g=y.value)&&!K(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}var S=m(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Lt(r.id,r.doneData),Lt(o.id,r.doneData?w(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&q(a).every((function(e){return Q(t.configuration,e)}))&&i.push(Lt(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 x=new Set(t.entrySet),b=new Set(t.exitSet),_=i([m(Array.from(x).map((function(t){return o(o([],i(t.activities.map((function(t){return It(t)}))),!1),i(t.onEntry),!1)}))).concat(S.map(bt)),m(Array.from(b).map((function(t){return o(o([],i(t.onExit),!1),i(t.activities.map((function(t){return jt(t)}))),!1)})))],2),T=_[0],E=_[1];return xt(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=R(e);if(t instanceof Bt)r=void 0===n?t:this.resolveState(Bt.from(t,n));else{var c=O(t)?this.resolve(d(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Bt.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=X([],this.getStateNodes(r.value)),l=h.configuration.length?X(f,h.configuration):f;return h.configuration=o([],i(l),!1),this.resolveTransition(h,r,r.context,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,s){var u,h,f=this;void 0===s&&(s=gt);var l=n.configuration,d=!o||n.transitions.length>0,p=d?G(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=this.getActions(n,a,s,o),g=o?e({},o.activities):{};try{for(var m=r(y),S=m.next();!S.done;S=m.next()){var x=S.value;x.type===Y?g[x.activity.id||x.activity.type]=x:x.type===Z&&(g[x.activity.id||x.activity.type]=!1)}}catch(t){u={error:t}}finally{try{S&&!S.done&&(h=m.return)&&h.call(m)}finally{if(u)throw u.error}}var b,E,A=i(Ft(this,o,a,s,y,this.machine.config.preserveActionOrder),2),N=A[0],P=A[1],k=i(_(N,(function(e){return e.type===tt||e.type===et&&e.to===t.SpecialTargets.Internal})),2),I=k[0],j=k[1],C=N.filter((function(t){var e;return t.type===Y&&(null===(e=t.activity)||void 0===e?void 0:e.type)===ut})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=F(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?w(t.data,n,r):void 0,c=a?Xt(a,t.id,s):$t(t.id);return c.meta=t,c}(e.activity,f.machine,P,s),t}),o?e({},o.children):{}),V=d?n.configuration:o?o.configuration:[],D=Q(V,this),L=new Bt({value:p||o.value,context:P,_event:s,_sessionid:o?o._sessionid:null,historyValue:p?v?(b=v,E=p,{current:E,states:T(b,E)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?j:[],activities:p?g:o?o.activities:{},events:[],configuration:V,transitions:n.transitions,children:C,done:D,tags:null==o?void 0:o.tags,machine:this}),R=a!==P;L.changed=s.name===dt||R;var M=L.history;M&&delete M.history;var z=!D&&(this._transient||l.some((function(t){return t._transient})));if(!(d||z&&""!==s.name))return L;var U=L;if(!D)for(z&&(U=this.resolveRaisedTransition(U,{type:rt},s));I.length;){var B=I.shift();U=this.resolveRaisedTransition(U,B._event,s)}var J=U.changed||(M?!!U.actions.length||R||typeof M.value!=typeof U.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(O(e)||O(n))return e===n;var r=c(e),i=c(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(U.value,M.value):void 0);return U.changed=J,U.history=M,U.tags=W(U.configuration),U},a.prototype.getStateNode=function(t){if(Qt(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=Qt(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&&Qt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=f(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||Kt;switch(this.type){case"parallel":return p(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Kt}));case"compound":if(O(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return c(t).length?p(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Kt})):this.initialStateValue||{};default:return t||Kt}},a.prototype.getResolvedPath=function(t){if(Qt(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 f(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=v(this.states,(function(t){return t.initialStateValue||Kt}),(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=J(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){this._init();var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)},Object.defineProperty(a.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(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=O(e.target)&&Qt(e.target)?d(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 J(this)?[this]:"compound"!==this.type||this.initial?m(g(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(c(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=O(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?m(g(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 O(s)?[n.getStateNode(s)]:m(g(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=m(c(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 s=r(c(o)),u=s.next();!u.done;u=s.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=s.return)&&e.call(s)}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(!O(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 x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return O(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:xt(x(t.actions)),cond:P(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,s=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=m(c(l).map((function(t){return M(t,l[t])})).concat(M("*",f)))}else a=[];var d=this.config.always?M("",this.config.always):[],p=this.config.onDone?M(String(Lt(this.id)),this.config.onDone):[],v=m(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(M(String(Rt(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,o([],i(M(String(Mt(t.id)),t.onError)),!1)),e}))),y=this.after,g=m(o(o(o(o([],i(p),!1),i(v),!1),i(a),!1),i(d),!1).map((function(t){return x(t).map((function(t){return s.formatTransition(t)}))})));try{for(var S=r(y),w=S.next();!w.done;w=S.next()){var b=w.value;g.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=S.return)&&e.call(S)}finally{if(t)throw t.error}}return g},a}();var Yt={deferEvents:!1},Zt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Yt),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}(),te=new Map,ee=0,ne=function(){return"x:".concat(ee++)},re=function(t,e){return te.set(t,e),t},ie=function(t){return te.get(t)},oe=function(t){te.delete(t)};function ae(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function se(t){if(ae()){var e=function(){var t=ae();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ce(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=U(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},e(e({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},I),r)),u={parent:n.parent,self:c,id:n.id||"anonymous",observers:o};return i=t.start?t.start(u):i,c}var ue,he={sync:!1,autoForward:!1};(ue=t.InterpreterStatus||(t.InterpreterStatus={}))[ue.NotStarted=0]="NotStarted",ue[ue.Running=1]="Running",ue[ue.Stopped=2]="Stopped";var fe=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,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=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(A(e))return o.batch(e),o.state;var r=R(L(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:O(r)?o.children.get(r)||ie(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===lt?"".concat(Mt(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 Zt({deferEvents:this.options.deferEvents}),this.sessionId=ne()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:qt(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=Q(t.configuration||[],this.machine);if(this.state.configuration&&m){var S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),x=S&&S.doneData?w(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Rt(this.id,x))}}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;re(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:qt(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(Bt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,gt)})),this},n.prototype.stop=function(){var e,n,a,s,u,h,f,l,d,p,v=this;try{for(var y=r(this.listeners),g=y.next();!g.done;g=y.next()){var m=g.value;this.listeners.delete(m)}}catch(t){e={error:t}}finally{try{g&&!g.done&&(n=y.return)&&n.call(y)}finally{if(e)throw e.error}}try{for(var S=r(this.stopListeners),x=S.next();!x.done;x=S.next()){(m=x.value)(),this.stopListeners.delete(m)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(s=S.return)&&s.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.contextListeners),b=w.next();!b.done;b=w.next()){m=b.value;this.contextListeners.delete(m)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}try{for(var _=r(this.doneListeners),T=_.next();!T.done;T=_.next()){m=T.value;this.doneListeners.delete(m)}}catch(t){f={error:t}}finally{try{T&&!T.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}if(!this.initialized)return this;o([],i(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).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;v.exec(a,v.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 E=r(c(this.delayedEventsMap)),A=E.next();!A.done;A=E.next()){var O=A.value;this.clock.clearTimeout(this.delayedEventsMap[O])}}catch(t){d={error:t}}finally{try{A&&!A.done&&(p=E.return)&&p.call(E)}finally{if(d)throw d.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,oe(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=R(t);a.forward(n),c=qt(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,R(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=R(t);if(0===n.name.indexOf(ft)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ft)})))throw n.data.data;return qt(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||mt(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 et: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 nt:this.cancel(e.sendId);break;case Y: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=F(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?w(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;j(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(u);break;case Z:this.stopChild(e.activity.id);break;case st: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(b(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(j(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({},he),r);a.sync&&o.onTransition((function(t){i.send(dt,{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(R(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=ce(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,n){var r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(n),i.send(R(Rt(n,t),{origin:n})))}),(function(t){if(!o){i.removeChild(n);var e=Mt(n,t);try{i.send(R(e,{origin:n}))}catch(t){i.devTools&&i.devTools.send(e,i.state),i.machine.strict&&i.stop()}}}));var a=e({id:n,send:function(){},subscribe:function(e,n,r){var i=U(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:n}},getSnapshot:function(){return r}},I);return this.children.set(n,a),a},n.prototype.spawnCallback=function(t,n){var r,i,o=this,a=!1,s=new Set,c=new Set;try{i=t((function(t){r=t,c.forEach((function(e){return e(t)})),a||o.send(R(t,{origin:n}))}),(function(t){s.add(t)}))}catch(t){this.send(Mt(n,t))}if(b(i))return this.spawnPromise(i,n);var u=e({id:n,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){return c.add(t),{unsubscribe:function(){c.delete(t)}}},stop:function(){a=!0,N(i)&&i()},toJSON:function(){return{id:n}},getSnapshot:function(){return r}},I);return this.children.set(n,u),u},n.prototype.spawnObservable=function(t,n){var r,i=this,o=t.subscribe((function(t){r=t,i.send(R(t,{origin:n}))}),(function(t){i.removeChild(n),i.send(R(Mt(n,t),{origin:n}))}),(function(){i.removeChild(n),i.send(R(Rt(n),{origin:n}))})),a=e({id:n,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:n}}},I);return this.children.set(n,a),a},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,n){this.children.set(t,e({id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:n||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},I))},n.prototype.attachDev=function(){var t=ae();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)}se(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[k]=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=le,n}();function le(t,e){return new fe(t,e)}function de(t){return t}var pe=de,ve=Vt,ye=Tt,ge=At,me=Nt,Se=zt,xe=Rt;t.Interpreter=fe,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Wt(t,e,n)},t.State=Bt,t.StateNode=Wt,t.actions=Ut,t.assign=ve,t.createMachine=function(t,e){return new Wt(t,e)},t.createSchema=de,t.doneInvoke=xe,t.forwardTo=Se,t.interpret=le,t.mapState=function(t,e){var n,i,o;try{for(var a=r(c(t)),s=a.next();!s.done;s=a.next()){var h=s.value;u(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{s&&!s.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=Bt.from(t,t instanceof Bt?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=u,t.send=ye,t.sendParent=ge,t.sendUpdate=me,t.spawn=function(t,n){var r=function(t){return O(t)?e(e({},he),{name:t}):e(e(e({},he),{name:D()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Xt(t,r.name)}(Jt[Jt.length-1])},t.t=pe,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */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,s={};function c(t){return Object.keys(t)}function u(t,e,n){void 0===n&&(n=".");var r=l(t,n),i=l(e,n);return O(i)?!!O(r)&&i===r:O(r)?r in i:c(r).every((function(t){return t in i&&u(r[t],i[t])}))}function h(t){try{return O(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 f(t,e){try{return A(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function l(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:A(t)?d(t):"string"!=typeof t?t:d(f(t,e));var n}function d(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function p(t,e){for(var n={},r=c(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function v(t,e,n){var i,o,a={};try{for(var s=r(c(t)),u=s.next();!u.done;u=s.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=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}var y=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 g(t){return t?O(t)?[[t]]:m(c(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?g(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function m(t){var e;return(e=[]).concat.apply(e,o([],i(t),!1))}function S(t){return A(t)?t:[t]}function x(t){return void 0===t?[]:S(t)}function w(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 b(t){return t instanceof Promise||!(null===t||!N(t)&&"object"!=typeof t||!N(t.then))}function _(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(t,e){return p(t.states,(function(t,n){if(t){var r=(O(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:T(t,r)}}}))}function E(t,e,n,i){return t?n.reduce((function(t,n){var o,a,s=n.assignment,u={state:i,action:n,_event:e},h={};if(N(s))h=s(t,e.data,u);else try{for(var f=r(c(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[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 A(t){return Array.isArray(t)}function N(t){return"function"==typeof t}function O(t){return"string"==typeof t}function P(t,e){if(t)return O(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:N(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var k=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();(a={})[k]=function(){return this},a[Symbol.observable]=function(){return this};function I(t){try{return"__xstatenode"in t}catch(t){return!1}}var j,C,V=function(){var t=0;return function(){return(++t).toString(16)}}();function D(t,n){return O(t)||"number"==typeof t?e({type:t},n):t}function L(t,n){if(!O(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=D(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function R(t,n){return S(n).map((function(n){return void 0===n||"string"==typeof n||I(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function M(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=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,r.data,a)}function z(t){return"string"==typeof t?{type:t}:t}function F(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function U(t,e){return"".concat(t,":invocation[").concat(e,"]")}(j=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",j.Stop="xstate.stop",j.Raise="xstate.raise",j.Send="xstate.send",j.Cancel="xstate.cancel",j.NullEvent="",j.Assign="xstate.assign",j.After="xstate.after",j.DoneState="done.state",j.DoneInvoke="done.invoke",j.Log="xstate.log",j.Init="xstate.init",j.Invoke="xstate.invoke",j.ErrorExecution="error.execution",j.ErrorCommunication="error.communication",j.ErrorPlatform="error.platform",j.ErrorCustom="xstate.error",j.Update="xstate.update",j.Pure="xstate.pure",j.Choose="xstate.choose",(C=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",C.Internal="#_internal";var B=function(t){return"atomic"===t.type||"final"===t.type};function J(t){return c(t.states).map((function(e){return t.states[e]}))}function q(t){var e=[t];return B(t)?e:e.concat(m(J(t).map(q)))}function $(t,e){var n,i,o,a,s,c,u,h,f=X(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=X(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(J(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 X(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 H(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(B(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,X($([t],e)))}function G(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function K(t,e){return"compound"===e.type?J(e).some((function(e){return"final"===e.type&&G(t,e)})):"parallel"===e.type&&J(e).every((function(e){return K(t,e)}))}function Q(t){return new Set(m(t.map((function(t){return t.tags}))))}var W=t.ActionTypes.Start,Y=t.ActionTypes.Stop,Z=t.ActionTypes.Raise,tt=t.ActionTypes.Send,et=t.ActionTypes.Cancel,nt=t.ActionTypes.NullEvent,rt=t.ActionTypes.Assign,it=t.ActionTypes.After,ot=t.ActionTypes.DoneState,at=t.ActionTypes.Log,st=t.ActionTypes.Init,ct=t.ActionTypes.Invoke,ut=t.ActionTypes.ErrorExecution,ht=t.ActionTypes.ErrorPlatform,ft=t.ActionTypes.ErrorCustom,lt=t.ActionTypes.Update,dt=t.ActionTypes.Choose,pt=t.ActionTypes.Pure,vt=Object.freeze({__proto__:null,start:W,stop:Y,raise:Z,send:tt,cancel:et,nullEvent:nt,assign:rt,after:it,doneState:ot,log:at,init:st,invoke:ct,errorExecution:ut,errorPlatform:ht,error:ft,update:lt,choose:dt,pure:pt}),yt=L({type:st});function gt(t,e){return e&&e[t]||void 0}function mt(t,n){var r;if(O(t)||"number"==typeof t)r=N(i=gt(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=gt(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 St=function(t,e){return t?(A(t)?t:[t]).map((function(t){return mt(t,e)})):[]};function xt(t){var n=mt(t);return e(e({id:O(t)?t:n.id},n),{type:n.type})}function wt(e){return O(e)?{type:Z,event:e}:_t(e,{to:t.SpecialTargets.Internal})}function bt(t){return{type:Z,_event:L(t.event)}}function _t(t,e){return{to:e?e.to:void 0,type:tt,event:N(t)?t:D(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:N(t)?t.name:h(t)}}function Tt(t,n,r,i){var o,a={_event:r},s=L(N(t.event)?t.event(n,r.data,a):t.event);if(O(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})}function Et(n,r){return _t(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function At(){return Et(lt)}var Nt=function(t,e){return{context:t,event:e}};var Ot=function(t,n,r){return e(e({},t),{value:O(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})},Pt=function(t){return{type:et,sendId:t}};function kt(e){var n=xt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function It(e){var n=N(e)?e:xt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function jt(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}}var Ct=function(t){return{type:rt,assignment:t}};function Vt(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Dt(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Lt(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Rt(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Mt(t,n){return _t((function(t,e){return e}),e(e({},n),{to:t}))}function zt(t,n,r,a,s,c){void 0===c&&(c=!1);var u=i(c?[[],s]:_(s,(function(t){return t.type===rt})),2),h=u[0],f=u[1],l=h.length?E(r,a,h,n):r,d=c?[r]:void 0;return[m(f.map((function(r){var s;switch(r.type){case Z:return bt(r);case tt:return Tt(r,l,a,t.options.delays);case at:return Ot(r,l,a);case dt:if(!(p=null===(s=r.conds.find((function(e){var r=P(e.cond,t.options.guards);return!r||M(t,r,l,a,n)})))||void 0===s?void 0:s.actions))return[];var u=i(zt(t,n,l,a,St(x(p),t.options.actions),c),2),h=u[0],f=u[1];return l=f,null==d||d.push(l),h;case pt:var p;if(!(p=r.get(l,a.data)))return[];var v=i(zt(t,n,l,a,St(x(p),t.options.actions),c),2),y=v[0],g=v[1];return l=g,null==d||d.push(l),y;case Y:return jt(r,l,a);case rt:l=E(l,a,[r],n),null==d||d.push(l);break;default:var m=mt(r,t.options.actions),S=m.exec;if(S&&d){var w=d.length-1;m=e(e({},m),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];S.apply(void 0,o([d[w]],i(e),!1))}})}return m}})).filter((function(t){return!!t}))),l]}var Ft=Object.freeze({__proto__:null,actionTypes:vt,initEvent:yt,getActionFunction:gt,toActionObject:mt,toActionObjects:St,toActivityDefinition:xt,raise:wt,resolveRaise:bt,send:_t,resolveSend:Tt,sendParent:Et,sendTo:function(t,n,r){return _t(n,e(e({},r),{to:t}))},sendUpdate:At,respond:function(t,n){return _t(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},log:function(t,e){return void 0===t&&(t=Nt),{type:at,label:e,expr:t}},resolveLog:Ot,cancel:Pt,start:kt,stop:It,resolveStop:jt,assign:Ct,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Vt,done:Dt,doneInvoke:Lt,error:Rt,pure:function(e){return{type:t.ActionTypes.Pure,get:e}},forwardTo:Mt,escalate:function(n,r){return Et((function(t,e,r){return{type:ft,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}},resolveActions:zt});var Ut=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=s,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||s,this.meta=(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(m(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:yt,_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=yt;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="."),O(t))return[t];var r=c(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 u(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}(),Bt=[],Jt=function(t,e){Bt.push(t);var n=e(t);return Bt.pop(),n};function qt(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[k]=function(){return this},e}function $t(t,e,n){var r=qt(e);if(r.deferred=!0,I(t)){var i=r.state=Jt(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Xt(t){var n;return e(((n={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[k]=function(){return this},n),t)}function Ht(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Gt(t){return e(e({type:ct},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:ct,src:Ht(t.src)})}})}var Kt={},Qt=function(t){return"#"===t[0]},Wt=function(){function a(t,n,s,u){var h,f=this;void 0===s&&(s="context"in t?t.context:void 0),this.config=t,this._context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==u?void 0:u.parent,this.key=this.config.key||(null==u?void 0:u.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&&c(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(h=this.config.schema)&&void 0!==h?h:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?p(this.config.states,(function(t,n){var r,i=new a(t,{},void 0,{parent:f,key:n});return Object.assign(f.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Kt;var l=0;!function t(e){var n,i;e.order=l++;try{for(var o=r(J(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=x(this.config.entry||this.config.onEntry).map((function(t){return mt(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return mt(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var r,i;if(I(t)){var o=U(f.id,n);return f.machine.options.services=e(((r={})[o]=t,r),f.machine.options.services),Gt({src:o,id:o})}if(O(t.src)){o=t.id||U(f.id,n);return Gt(e(e({},t),{id:o,src:t.src}))}if(I(t.src)||N(t.src)){o=t.id||U(f.id,n);return f.machine.options.services=e(((i={})[o]=t.src,i),f.machine.options.services),Gt(e(e({id:o},t),{src:o}))}var a=t.src;return Gt(e(e({id:U(f.id,n)},t),{src:a}))})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return xt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||q(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:p(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=Vt(N(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(_t(r,{delay:e})),t.onExit.push(Pt(r)),r};return(A(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):m(c(n).map((function(t,i){var o=n[t],a=O(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(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 Ut?t.value:l(t,this.delimiter);if(O(r)){var a=this.getStateNode(r).initial;return void 0!==a?this.getStateNodes(((e={})[r]=a,e)):[this,this.states[r]]}var s=c(r),u=[this];return u.push.apply(u,o([],i(m(s.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),u},a.prototype.handles=function(t){var e=h(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=t instanceof Ut?t:Ut.create(t),r=Array.from($([],this.getStateNodes(n.value)));return new Ut(e(e({},n),{value:this.resolve(n.value),configuration:r,done:K(r,this),tags:Q(r)}))},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=c(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 s=r(c(t)),u=s.next();!u.done;u=s.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=s.return)&&o.call(s)}finally{if(i)throw i.error}}var d=c(a).map((function(t){return a[t]})),p=m(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=m(d.map((function(t){return t.entrySet}))),y=m(c(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:m(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:m(c(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return O(t)?this.transitionLeafNode(t,e,n):1===c(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,L(e))},a.prototype.next=function(t,e){var n,a,s,c=this,h=e.name,f=[],d=[];try{for(var p=r(this.getCandidates(h)),v=p.next();!v.done;v=p.next()){var g=v.value,S=g.cond,x=g.in,w=t.context,b=!x||(O(x)&&Qt(x)?t.matches(l(this.getStateNodeById(x).path,this.delimiter)):u(l(x,this.delimiter),y(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||M(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!==g.target&&(d=g.target),f.push.apply(f,o([],i(g.actions),!1)),s=g;break}}}catch(t){n={error:t}}finally{try{v&&!v.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:f};var T=m(d.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),E=!!s.internal;return{transitions:[s],entrySet:E?[]:m(T.map((function(t){return c.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:T,source:t,actions:f}}},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=$([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?$(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){G(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=r(f),y=v.next();!y.done;y=v.next()){var g;G(l,g=y.value)&&!G(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}var S=m(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Dt(r.id,r.doneData),Dt(o.id,r.doneData?w(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&J(a).every((function(e){return K(t.configuration,e)}))&&i.push(Dt(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 x=new Set(t.entrySet),b=new Set(t.exitSet),_=i([m(Array.from(x).map((function(t){return o(o([],i(t.activities.map((function(t){return kt(t)}))),!1),i(t.onEntry),!1)}))).concat(S.map(wt)),m(Array.from(b).map((function(t){return o(o([],i(t.onExit),!1),i(t.activities.map((function(t){return It(t)}))),!1)})))],2),T=_[0],E=_[1];return St(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=L(e);if(t instanceof Ut)r=void 0===n?t:this.resolveState(Ut.from(t,n));else{var c=O(t)?this.resolve(d(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Ut.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=$([],this.getStateNodes(r.value)),l=h.configuration.length?$(f,h.configuration):f;return h.configuration=o([],i(l),!1),this.resolveTransition(h,r,r.context,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,s){var u,h,f=this;void 0===s&&(s=yt);var l=n.configuration,d=!o||n.transitions.length>0,p=d?H(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=this.getActions(n,a,s,o),g=o?e({},o.activities):{};try{for(var m=r(y),S=m.next();!S.done;S=m.next()){var x=S.value;x.type===W?g[x.activity.id||x.activity.type]=x:x.type===Y&&(g[x.activity.id||x.activity.type]=!1)}}catch(t){u={error:t}}finally{try{S&&!S.done&&(h=m.return)&&h.call(m)}finally{if(u)throw u.error}}var b,E,A=i(zt(this,o,a,s,y,this.machine.config.preserveActionOrder),2),N=A[0],P=A[1],k=i(_(N,(function(e){return e.type===Z||e.type===tt&&e.to===t.SpecialTargets.Internal})),2),I=k[0],j=k[1],C=N.filter((function(t){var e;return t.type===W&&(null===(e=t.activity)||void 0===e?void 0:e.type)===ct})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=z(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?w(t.data,n,r):void 0,c=a?$t(a,t.id,s):qt(t.id);return c.meta=t,c}(e.activity,f.machine,P,s),t}),o?e({},o.children):{}),V=d?n.configuration:o?o.configuration:[],D=K(V,this),L=new Ut({value:p||o.value,context:P,_event:s,_sessionid:o?o._sessionid:null,historyValue:p?v?(b=v,E=p,{current:E,states:T(b,E)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?j:[],activities:p?g:o?o.activities:{},events:[],configuration:V,transitions:n.transitions,children:C,done:D,tags:null==o?void 0:o.tags,machine:this}),R=a!==P;L.changed=s.name===lt||R;var M=L.history;M&&delete M.history;var F=!D&&(this._transient||l.some((function(t){return t._transient})));if(!(d||F&&""!==s.name))return L;var U=L;if(!D)for(F&&(U=this.resolveRaisedTransition(U,{type:nt},s));I.length;){var B=I.shift();U=this.resolveRaisedTransition(U,B._event,s)}var J=U.changed||(M?!!U.actions.length||R||typeof M.value!=typeof U.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(O(e)||O(n))return e===n;var r=c(e),i=c(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(U.value,M.value):void 0);return U.changed=J,U.history=M,U.tags=Q(U.configuration),U},a.prototype.getStateNode=function(t){if(Qt(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=Qt(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&&Qt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=f(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||Kt;switch(this.type){case"parallel":return p(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Kt}));case"compound":if(O(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return c(t).length?p(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Kt})):this.initialStateValue||{};default:return t||Kt}},a.prototype.getResolvedPath=function(t){if(Qt(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 f(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=v(this.states,(function(t){return t.initialStateValue||Kt}),(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=B(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){this._init();var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)},Object.defineProperty(a.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(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=O(e.target)&&Qt(e.target)?d(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 B(this)?[this]:"compound"!==this.type||this.initial?m(g(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(c(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=O(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?m(g(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 O(s)?[n.getStateNode(s)]:m(g(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=m(c(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 s=r(c(o)),u=s.next();!u.done;u=s.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=s.return)&&e.call(s)}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(!O(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 x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return O(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:St(x(t.actions)),cond:P(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,s=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=m(c(l).map((function(t){return R(t,l[t])})).concat(R("*",f)))}else a=[];var d=this.config.always?R("",this.config.always):[],p=this.config.onDone?R(String(Dt(this.id)),this.config.onDone):[],v=m(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(R(String(Lt(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,o([],i(R(String(Rt(t.id)),t.onError)),!1)),e}))),y=this.after,g=m(o(o(o(o([],i(p),!1),i(v),!1),i(a),!1),i(d),!1).map((function(t){return x(t).map((function(t){return s.formatTransition(t)}))})));try{for(var S=r(y),w=S.next();!w.done;w=S.next()){var b=w.value;g.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=S.return)&&e.call(S)}finally{if(t)throw t.error}}return g},a}();var Yt={deferEvents:!1},Zt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Yt),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}(),te=new Map,ee=0,ne=function(){return"x:".concat(ee++)},re=function(t,e){return te.set(t,e),t},ie=function(t){return te.get(t)},oe=function(t){te.delete(t)};function ae(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function se(t){if(ae()){var e=function(){var t=ae();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ce(t,e){void 0===e&&(e={});var n=t.initialState,r=new Set,i=[],o=!1,a=Xt({id:e.id,send:function(e){i.push(e),function(){if(!o){for(o=!0;i.length>0;){var e=i.shift();n=t.transition(n,e,s),r.forEach((function(t){return t.next(n)}))}o=!1}}()},getSnapshot:function(){return n},subscribe:function(t,e,i){var o=F(t,e,i);return r.add(o),o.next(n),{unsubscribe:function(){r.delete(o)}}}}),s={parent:e.parent,self:a,id:e.id||"anonymous",observers:r};return n=t.start?t.start(s):n,a}var ue,he={sync:!1,autoForward:!1};(ue=t.InterpreterStatus||(t.InterpreterStatus={}))[ue.NotStarted=0]="NotStarted",ue[ue.Running=1]="Running",ue[ue.Stopped=2]="Stopped";var fe=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,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=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(A(e))return o.batch(e),o.state;var r=L(D(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:O(r)?o.children.get(r)||ie(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ft?"".concat(Rt(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 Zt({deferEvents:this.options.deferEvents}),this.sessionId=ne()}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=K(t.configuration||[],this.machine);if(this.state.configuration&&m){var S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),x=S&&S.doneData?w(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Lt(this.id,x))}}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;re(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:Jt(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(Ut.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,yt)})),this},n.prototype.stop=function(){var e,n,a,s,u,h,f,l,d,p,v=this;try{for(var y=r(this.listeners),g=y.next();!g.done;g=y.next()){var m=g.value;this.listeners.delete(m)}}catch(t){e={error:t}}finally{try{g&&!g.done&&(n=y.return)&&n.call(y)}finally{if(e)throw e.error}}try{for(var S=r(this.stopListeners),x=S.next();!x.done;x=S.next()){(m=x.value)(),this.stopListeners.delete(m)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(s=S.return)&&s.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.contextListeners),b=w.next();!b.done;b=w.next()){m=b.value;this.contextListeners.delete(m)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}try{for(var _=r(this.doneListeners),T=_.next();!T.done;T=_.next()){m=T.value;this.doneListeners.delete(m)}}catch(t){f={error:t}}finally{try{T&&!T.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}if(!this.initialized)return this;o([],i(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).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;v.exec(a,v.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 E=r(c(this.delayedEventsMap)),A=E.next();!A.done;A=E.next()){var O=A.value;this.clock.clearTimeout(this.delayedEventsMap[O])}}catch(t){d={error:t}}finally{try{A&&!A.done&&(p=E.return)&&p.call(E)}finally{if(d)throw d.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,oe(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=L(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,L(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=L(t);if(0===n.name.indexOf(ht)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ht)})))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||gt(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 tt: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 et:this.cancel(e.sendId);break;case W: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=z(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?w(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;I(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(u);break;case Y:this.stopChild(e.activity.id);break;case at: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(b(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(I(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({},he),r);a.sync&&o.onTransition((function(t){i.send(lt,{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(L(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=ce(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(L(Lt(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=Rt(e,t);try{i.send(L(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var a=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=F(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}})[k]=function(){return this},n);return this.children.set(e,a),a},n.prototype.spawnCallback=function(t,e){var n,r,i,o=this,a=!1,s=new Set,c=new Set;try{i=t((function(t){r=t,c.forEach((function(e){return e(t)})),a||o.send(L(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(Rt(e,t))}if(b(i))return this.spawnPromise(i,e);var u=((n={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){var e=F(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){a=!0,N(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[k]=function(){return this},n);return this.children.set(e,u),u},n.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(L(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(L(Rt(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(L(Lt(e),{origin:e}))})),a=((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}}})[k]=function(){return this},n);return this.children.set(e,a),a},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){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}}})[k]=function(){return this},n))},n.prototype.attachDev=function(){var t=ae();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)}se(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[k]=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=le,n}();function le(t,e){return new fe(t,e)}function de(t){return t}var pe=de,ve=Ct,ye=_t,ge=Et,me=At,Se=Mt,xe=Lt;t.Interpreter=fe,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Wt(t,e,n)},t.State=Ut,t.StateNode=Wt,t.actions=Ft,t.assign=ve,t.createMachine=function(t,e){return new Wt(t,e)},t.createSchema=de,t.doneInvoke=xe,t.forwardTo=Se,t.interpret=le,t.mapState=function(t,e){var n,i,o;try{for(var a=r(c(t)),s=a.next();!s.done;s=a.next()){var h=s.value;u(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{s&&!s.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=Ut.from(t,t instanceof Ut?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=u,t.send=ye,t.sendParent=ge,t.sendUpdate=me,t.spawn=function(t,n){var r=function(t){return O(t)?e(e({},he),{name:t}):e(e(e({},he),{name:V()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):$t(t,r.name)}(Bt[Bt.length-1])},t.t=pe,t.toActorRef=Xt,Object.defineProperty(t,"__esModule",{value:!0})}));
|