xstate 4.30.5 → 4.30.6
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 +30 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +1 -1
- package/es/StateNode.js +2 -1
- package/es/devTools.js +5 -2
- package/es/interpreter.d.ts +1 -3
- package/es/interpreter.js +21 -22
- package/es/types.d.ts +4 -4
- package/lib/StateNode.js +2 -1
- package/lib/devTools.js +5 -2
- package/lib/interpreter.d.ts +1 -3
- package/lib/interpreter.js +20 -21
- package/lib/types.d.ts +4 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# xstate
|
|
2
2
|
|
|
3
|
+
## 4.30.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3131](https://github.com/statelyai/xstate/pull/3131) [`d9a0bcfc9`](https://github.com/statelyai/xstate/commit/d9a0bcfc9be03e49726d6dc4a6bbce25239913a1) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with event type being inferred from too many places within `createMachine` call and possibly ending up as `any`/`AnyEventObject` for the entire machine.
|
|
8
|
+
|
|
9
|
+
* [#3133](https://github.com/statelyai/xstate/pull/3133) [`4feef9d47`](https://github.com/statelyai/xstate/commit/4feef9d47f81d1b28f2f898431eb4bd1c42d8368) Thanks [@fw6](https://github.com/fw6)! - Fixed compatibility with esoteric [Mini Program](https://developers.weixin.qq.com/miniprogram/en/dev/framework/app-service/) environment where `global` object was available but `global.console` wasn't.
|
|
10
|
+
|
|
11
|
+
- [#3140](https://github.com/statelyai/xstate/pull/3140) [`502ffe91a`](https://github.com/statelyai/xstate/commit/502ffe91a19579f5f747b76ce29d50de81e8b15c) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with interpreters started using a persisted state not being "resolved" in full. This could cause some things, such as `after` transitions, not being executed correctly after starting an interpreter like this.
|
|
12
|
+
|
|
13
|
+
* [#3147](https://github.com/statelyai/xstate/pull/3147) [`155539c85`](https://github.com/statelyai/xstate/commit/155539c8597b2f2783e8419c782922545d7e6424) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a TS inference issue causing some functions to infer the constraint type for the event type even though a `StateMachine` passed to the function was parametrized with a concrete type for the event. More information can be found [here](https://github.com/statelyai/xstate/issues/3141#issuecomment-1063995705).
|
|
14
|
+
|
|
15
|
+
- [#3146](https://github.com/statelyai/xstate/pull/3146) [`4cf89b5f9`](https://github.com/statelyai/xstate/commit/4cf89b5f9cf645f741164d23e3bc35dd7c5706f6) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility of `Interpreter` with older versions of TypeScript. This ensures that our interpreters can correctly be consumed by functions expecting `ActorRef` interface (like for example `useSelector`).
|
|
16
|
+
|
|
17
|
+
* [#3139](https://github.com/statelyai/xstate/pull/3139) [`7b45fda9e`](https://github.com/statelyai/xstate/commit/7b45fda9e1bd544b505c86ddcd6cf1f949007fef) Thanks [@Andarist](https://github.com/Andarist)! - `InterpreterFrom` and `ActorRefFrom` types used on machines with typegen data should now correctly return types with final/resolved typegen data. The "final" type here means a type that already encodes the information that all required implementations have been provided. Before this change this wouldn't typecheck correctly:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const machine = createMachine({
|
|
21
|
+
// this encodes that we still expect `myAction` to be provided
|
|
22
|
+
tsTypes: {} as Typegen0
|
|
23
|
+
});
|
|
24
|
+
const service: InterpreterFrom<typeof machine> = machine.withConfig({
|
|
25
|
+
actions: {
|
|
26
|
+
myAction: () => {}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- [#3097](https://github.com/statelyai/xstate/pull/3097) [`c881c8ca9`](https://github.com/statelyai/xstate/commit/c881c8ca9baaf4928064a04d7034cd775a702bc2) Thanks [@davidkpiano](https://github.com/davidkpiano)! - State that is persisted and restored from `machine.resolveState(state)` will now have the correct `state.machine` value, so that `state.can(...)` and other methods will work as expected. See [#3096](https://github.com/statelyai/xstate/issues/3096) for more details.
|
|
32
|
+
|
|
3
33
|
## 4.30.5
|
|
4
34
|
|
|
5
35
|
### 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,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:d(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return d(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function h(t){if(1===t.length)return t[0];for(var e={},n=e,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 f(t,e,n){var r,o;if(p(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];p(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 l(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function d(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}var y=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function g(t){return!!t&&"__xstatenode"in t}(a={})[y]=function(){return this},a[Symbol.observable]=function(){return this};var b=function(){var t=0;return function(){return(++t).toString(16)}}();function m(t,e){return v(t)||"number"==typeof t?r({type:t},e):t}function x(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=m(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function w(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function S(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function E(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,e){return"compound"===e.type?S(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&&S(e).every((function(e){return _(t,e)}))}var O=e.Start,T=e.Stop;e.Raise;var I=e.Send,L=e.Cancel;e.NullEvent,e.Assign,e.After,e.DoneState;var k=e.Log,j=e.Init;e.Invoke,e.ErrorExecution;var C=e.ErrorPlatform,P=e.ErrorCustom,N=e.Update;e.Choose,e.Pure;var A=x({type:j});function D(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function M(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}var R=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 E(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:A,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=A;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="."),v(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,r){void 0===r&&(r=".");var i=c(e,r),o=c(n,r);return v(o)?!!v(i)&&o===i:v(i)?i in o:Object.keys(i).every((function(e){return e in o&&t(i[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),z={deferEvents:!1},V=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},z),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),J=[],q=function(t,e){J.push(t);var n=e(t);return J.pop(),n};function U(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}}})[y]=function(){return this},e}(e);if(r.deferred=!0,g(t)){var i=r.state=q(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var $=new Map,F=0,X=function(){return"x:".concat(F++)},B=function(t,e){return $.set(t,e),t},G=function(t){return $.get(t)},H=function(t){$.delete(t)};function K(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Q(t){if(K()){var e=function(){var t=K();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function W(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(){}})[y]=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=w(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 Y,Z={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(Y=t.InterpreterStatus||(t.InterpreterStatus={}))[Y.NotStarted=0]="NotStarted",Y[Y.Running=1]="Running",Y[Y.Stopped=2]="Stopped";var tt=function(){function a(e,i){var o=this;void 0===i&&(i=a.defaultOptions),this.machine=e,this.scheduler=new V,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(d(e))return o.batch(e),o.state;var r=x(m(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:v(e)?o.children.get(e)||G(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===P?"".concat(M(o.id)):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '".concat(e,"' from service '").concat(o.id,"'."))};var s=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 V({deferEvents:this.options.deferEvents}),this.sessionId=X()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:q(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,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,l=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){l.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=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),b=g.next();!b.done;b=g.next()){(0,b.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{b&&!b.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var m=_(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===l.machine})),w=x&&x.doneData?f(x.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(D(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,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;B(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:q(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(R.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,A)})),this},a.prototype.stop=function(){var e,n,r,a,u,c,h,f,l,d,v=this;try{for(var y=i(this.listeners),g=y.next();!g.done;g=y.next()){var b=g.value;this.listeners.delete(b)}}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 m=i(this.stopListeners),x=m.next();!x.done;x=m.next()){(b=x.value)(),this.stopListeners.delete(b)}}catch(t){r={error:t}}finally{try{x&&!x.done&&(a=m.return)&&a.call(m)}finally{if(r)throw r.error}}try{for(var w=i(this.contextListeners),S=w.next();!S.done;S=w.next()){b=S.value;this.contextListeners.delete(b)}}catch(t){u={error:t}}finally{try{S&&!S.done&&(c=w.return)&&c.call(w)}finally{if(u)throw u.error}}try{for(var E=i(this.doneListeners),_=E.next();!_.done;_=E.next()){b=_.value;this.doneListeners.delete(b)}}catch(t){h={error:t}}finally{try{_&&!_.done&&(f=E.return)&&f.call(E)}finally{if(h)throw h.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;v.exec(s,v.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){p(t.stop)&&t.stop()}));try{for(var O=i(Object.keys(this.delayedEventsMap)),T=O.next();!T.done;T=O.next()){var I=T.value;this.clock.clearTimeout(this.delayedEventsMap[I])}}catch(t){l={error:t}}finally{try{T&&!T.done&&(d=O.return)&&d.call(O)}finally{if(l)throw l.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,H(this.sessionId),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=x(t);n.forward(e),u=q(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,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,x(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=x(t);if(0===n.name.indexOf(C)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(C)})))throw n.data.data;return q(this,(function(){return e.machine.transition(e.state,n)}))},a.prototype.forward=function(t){var e,n;try{for(var 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=p(u)?u:u?u.exec:n.exec;if(c)try{return c(s,a.data,{action:n,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case I:var h=n;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to):this.send(h._event);break;case L:this.cancel(n.sendId);break;case O:if(this.status!==t.InterpreterStatus.Running)return;var l=n.activity;if(!this.state.activities[l.id||l.type])break;if(l.type===e.Invoke){var d="string"==typeof(o=l.src)?{type:o}:o,v=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=l.id,b=l.data,m="autoForward"in l?l.autoForward:!!l.forward;if(!v)return;var x=b?f(b,s,a):void 0;if("string"==typeof v)return;var w=p(v)?v(s,a.data,{data:x,src:d,meta:l.meta}):v;if(!w)return;var S=void 0;g(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),this.spawn(w,y,S)}else this.spawnActivity(l);break;case T:this.stopChild(n.activity.id);break;case k:var E=n.label,_=n.value;E?this.logger(E,_):this.logger(_)}},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(l(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(g(t))return this.spawnMachine(t,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({},Z),e);o.sync&&i.onTransition((function(t){n.send(N,{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(x(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=W(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(x(D(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=M(e,t);try{i.send(x(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=w(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}})[y]=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(x(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(M(e,t))}if(l(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=w(t);return u.add(e.next),{unsubscribe:function(){u.delete(e.next)}}},stop:function(){s=!0,p(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[y]=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(x(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(x(M(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(x(D(e),{origin:e}))})),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}}})[y]=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}}})[y]=function(){return this},n))},a.prototype.attachDev=function(){var t=K();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)}Q(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[y]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),a.interpret=et,a}();function et(t,e){return new tt(t,e)}t.Interpreter=tt,t.interpret=et,t.spawn=function(t,e){var n=function(t){return v(t)?r(r({},Z),{name:t}):r(r(r({},Z),{name:b()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):U(t,n.name)}(J[J.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,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:d(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return d(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}(t,e));var n}function h(t){if(1===t.length)return t[0];for(var e={},n=e,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 f(t,e,n){var r,o;if(p(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];p(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 l(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function d(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}var y=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function g(t){return!!t&&"__xstatenode"in t}(a={})[y]=function(){return this},a[Symbol.observable]=function(){return this};var b=function(){var t=0;return function(){return(++t).toString(16)}}();function m(t,e){return v(t)||"number"==typeof t?r({type:t},e):t}function x(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=m(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function w(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function S(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function E(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,e){return"compound"===e.type?S(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&&S(e).every((function(e){return _(t,e)}))}var O=e.Start,T=e.Stop;e.Raise;var I=e.Send,L=e.Cancel;e.NullEvent,e.Assign,e.After,e.DoneState;var k=e.Log,j=e.Init;e.Invoke,e.ErrorExecution;var C=e.ErrorPlatform,P=e.ErrorCustom,N=e.Update;e.Choose,e.Pure;var A=x({type:j});function D(t,n){var r="".concat(e.DoneInvoke,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}function M(t,n){var r="".concat(e.ErrorPlatform,".").concat(t),i={type:r,data:n,toString:function(){return r}};return i}var R=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 E(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:A,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=A;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="."),v(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,r){void 0===r&&(r=".");var i=c(e,r),o=c(n,r);return v(o)?!!v(i)&&o===i:v(i)?i in o:Object.keys(i).every((function(e){return e in o&&t(i[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;this.machine;var n=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==n?void 0:n.transitions.length)&&n.transitions.some((function(t){return void 0!==t.target||t.actions.length}))},t}(),z={deferEvents:!1},V=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},z),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),J=[],q=function(t,e){J.push(t);var n=e(t);return J.pop(),n};function U(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}}})[y]=function(){return this},e}(e);if(r.deferred=!0,g(t)){var i=r.state=q(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}var $=new Map,F=0,X=function(){return"x:".concat(F++)},B=function(t,e){return $.set(t,e),t},G=function(t){return $.get(t)},H=function(t){$.delete(t)};function K(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Q(t){if(K()){var e=function(){var t=K();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function W(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(){}})[y]=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=w(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 Y,Z={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(Y=t.InterpreterStatus||(t.InterpreterStatus={}))[Y.NotStarted=0]="NotStarted",Y[Y.Running=1]="Running",Y[Y.Stopped=2]="Stopped";var tt=function(){function a(e,i){var o=this;void 0===i&&(i=a.defaultOptions),this.machine=e,this.scheduler=new V,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(d(e))return o.batch(e),o.state;var r=x(m(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:v(e)?o.children.get(e)||G(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===P?"".concat(M(o.id)):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '".concat(e,"' from service '").concat(o.id,"'."))};var s=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 V({deferEvents:this.options.deferEvents}),this.sessionId=X()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:q(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,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,l=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){l.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=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),b=g.next();!b.done;b=g.next()){(0,b.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{b&&!b.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var m=_(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===l.machine})),w=x&&x.doneData?f(x.doneData,t.context,e):void 0;try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(D(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,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;this.machine._init(),B(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:q(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(R.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,A)})),this},a.prototype.stop=function(){var e,n,r,a,u,c,h,f,l,d,v=this;try{for(var y=i(this.listeners),g=y.next();!g.done;g=y.next()){var b=g.value;this.listeners.delete(b)}}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 m=i(this.stopListeners),x=m.next();!x.done;x=m.next()){(b=x.value)(),this.stopListeners.delete(b)}}catch(t){r={error:t}}finally{try{x&&!x.done&&(a=m.return)&&a.call(m)}finally{if(r)throw r.error}}try{for(var w=i(this.contextListeners),S=w.next();!S.done;S=w.next()){b=S.value;this.contextListeners.delete(b)}}catch(t){u={error:t}}finally{try{S&&!S.done&&(c=w.return)&&c.call(w)}finally{if(u)throw u.error}}try{for(var E=i(this.doneListeners),_=E.next();!_.done;_=E.next()){b=_.value;this.doneListeners.delete(b)}}catch(t){h={error:t}}finally{try{_&&!_.done&&(f=E.return)&&f.call(E)}finally{if(h)throw h.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;v.exec(s,v.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){p(t.stop)&&t.stop()}));try{for(var O=i(Object.keys(this.delayedEventsMap)),T=O.next();!T.done;T=O.next()){var I=T.value;this.clock.clearTimeout(this.delayedEventsMap[I])}}catch(t){l={error:t}}finally{try{T&&!T.done&&(d=O.return)&&d.call(O)}finally{if(l)throw l.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,H(this.sessionId),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=x(t);n.forward(e),u=q(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,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,x(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=x(t);if(0===n.name.indexOf(C)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(C)})))throw n.data.data;return q(this,(function(){return e.machine.transition(e.state,n)}))},a.prototype.forward=function(t){var e,n;try{for(var 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=p(u)?u:u?u.exec:n.exec;if(c)try{return c(s,a.data,{action:n,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(n.type){case I:var h=n;if("number"==typeof h.delay)return void this.defer(h);h.to?this.sendTo(h._event,h.to):this.send(h._event);break;case L:this.cancel(n.sendId);break;case O:if(this.status!==t.InterpreterStatus.Running)return;var l=n.activity;if(!this.state.activities[l.id||l.type])break;if(l.type===e.Invoke){var d="string"==typeof(o=l.src)?{type:o}:o,v=this.machine.options.services?this.machine.options.services[d.type]:void 0,y=l.id,b=l.data,m="autoForward"in l?l.autoForward:!!l.forward;if(!v)return;var x=b?f(b,s,a):void 0;if("string"==typeof v)return;var w=p(v)?v(s,a.data,{data:x,src:d,meta:l.meta}):v;if(!w)return;var S=void 0;g(w)&&(w=x?w.withContext(x):w,S={autoForward:m}),this.spawn(w,y,S)}else this.spawnActivity(l);break;case T:this.stopChild(n.activity.id);break;case k:var E=n.label,_=n.value;E?this.logger(E,_):this.logger(_)}},a.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},a.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},a.prototype.spawn=function(t,e,n){if(l(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(g(t))return this.spawnMachine(t,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({},Z),e);o.sync&&i.onTransition((function(t){n.send(N,{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(x(t,{origin:i.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=W(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(x(D(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=M(e,t);try{i.send(x(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var s=((n={id:e,send:function(){},subscribe:function(e,n,r){var i=w(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}})[y]=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(x(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(M(e,t))}if(l(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=w(t);return u.add(e.next),{unsubscribe:function(){u.delete(e.next)}}},stop:function(){s=!0,p(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[y]=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(x(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(x(M(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(x(D(e),{origin:e}))})),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}}})[y]=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}}})[y]=function(){return this},n))},a.prototype.attachDev=function(){var t=K();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)}Q(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[y]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},a.interpret=et,a}();function et(t,e){return new tt(t,e)}t.Interpreter=tt,t.interpret=et,t.spawn=function(t,e){var n=function(t){return v(t)?r(r({},Z),{name:t}):r(r(r({},Z),{name:b()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):U(t,n.name)}(J[J.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,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,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 o(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 a(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 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))}t.ActionTypes=void 0,(e=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Update="xstate.update",e.Pure="xstate.pure",e.Choose="xstate.choose",t.SpecialTargets=void 0,(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var c,u=t.ActionTypes.Start,h=t.ActionTypes.Stop,f=t.ActionTypes.Raise,l=t.ActionTypes.Send,d=t.ActionTypes.Cancel,v=t.ActionTypes.NullEvent,p=t.ActionTypes.Assign,y=t.ActionTypes.After,g=t.ActionTypes.DoneState,m=t.ActionTypes.Log,S=t.ActionTypes.Init,x=t.ActionTypes.Invoke,b=t.ActionTypes.ErrorExecution,w=t.ActionTypes.ErrorPlatform,_=t.ActionTypes.ErrorCustom,T=t.ActionTypes.Update,E=t.ActionTypes.Choose,O=t.ActionTypes.Pure,k=Object.freeze({__proto__:null,start:u,stop:h,raise:f,send:l,cancel:d,nullEvent:v,assign:p,after:y,doneState:g,log:m,init:S,invoke:x,errorExecution:b,errorPlatform:w,error:_,update:T,choose:E,pure:O}),j={};function A(t,e,n){void 0===n&&(n=".");var r=I(t,n),i=I(e,n);return G(i)?!!G(r)&&i===r:G(r)?r in i:Object.keys(r).every((function(t){return t in i&&A(r[t],i[t])}))}function N(t){try{return G(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 P(t,e){try{return $(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function I(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:$(t)?C(t):"string"!=typeof t?t:C(P(t,e));var n}function C(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function V(t,e){for(var n={},r=Object.keys(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function L(t,e,n){var r,i,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];n(h)&&(a[u]=e(h,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}var D=function(t){return function(e){var n,r,i=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){i=i[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return i}};function R(t){return t?G(t)?[[t]]:M(Object.keys(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?R(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function M(t){var e;return(e=[]).concat.apply(e,s([],a(t),!1))}function z(t){return $(t)?t:[t]}function F(t){return void 0===t?[]:z(t)}function B(t,e,n){var r,i;if(H(t))return t(e,n.data);var a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];H(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}function U(t){return t instanceof Promise||!(null===t||!H(t)&&"object"!=typeof t||!H(t.then))}function J(t,e){var n,r,i=a([[],[]],2),s=i[0],c=i[1];try{for(var u=o(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}return[s,c]}function q(t,e){return V(t.states,(function(t,n){if(t){var r=(G(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:q(t,r)}}}))}function X(t,e,n,r){return t?n.reduce((function(t,n){var i,a,s=n.assignment,c={state:r,action:n,_event:e},u={};if(H(s))u=s(t,e.data,c);else try{for(var h=o(Object.keys(s)),f=h.next();!f.done;f=h.next()){var l=f.value,d=s[l];u[l]=H(d)?d(t,e.data,c):d}}catch(t){i={error:t}}finally{try{f&&!f.done&&(a=h.return)&&a.call(h)}finally{if(i)throw i.error}}return Object.assign({},t,u)}),t):t}function $(t){return Array.isArray(t)}function H(t){return"function"==typeof t}function G(t){return"string"==typeof t}function K(t,e){if(t)return G(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:H(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var Q=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function W(t){return!!t&&"__xstatenode"in t}(c={})[Q]=function(){return this},c[Symbol.observable]=function(){return this};var Y=function(){var t=0;return function(){return(++t).toString(16)}}();function Z(t,e){return G(t)||"number"==typeof t?r({type:t},e):t}function tt(t,e){if(!G(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=Z(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function et(t,e){return z(e).map((function(e){return void 0===e||"string"==typeof e||W(e)?{target:e,event:t}:r(r({},e),{event:t})}))}function nt(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 rt(t){return"string"==typeof t?{type:t}:t}function it(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function ot(t,e){return"".concat(t,":invocation[").concat(e,"]")}var at=tt({type:S});function st(t,e){return e&&e[t]||void 0}function ct(t,e){var n;if(G(t)||"number"==typeof t)n=H(i=st(t,e))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(H(t))n={type:t.name||t.toString(),exec:t};else{var i;if(H(i=st(t.type,e)))n=r(r({},t),{exec:i});else if(i){var o=i.type||t.type;n=r(r(r({},i),t),{type:o})}else n=t}return n}var ut=function(t,e){return t?($(t)?t:[t]).map((function(t){return ct(t,e)})):[]};function ht(t){var e=ct(t);return r(r({id:G(t)?t:e.id},e),{type:e.type})}function ft(e){return G(e)?{type:f,event:e}:dt(e,{to:t.SpecialTargets.Internal})}function lt(t){return{type:f,_event:tt(t.event)}}function dt(t,e){return{to:e?e.to:void 0,type:l,event:H(t)?t:Z(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:H(t)?t.name:N(t)}}function vt(t,e,n,i){var o,a={_event:n},s=tt(H(t.event)?t.event(e,n.data,a):t.event);if(G(t.delay)){var c=i&&i[t.delay];o=H(c)?c(e,n.data,a):c}else o=H(t.delay)?t.delay(e,n.data,a):t.delay;var u=H(t.to)?t.to(e,n.data,a):t.to;return r(r({},t),{to:u,_event:s,event:s.data,delay:o})}function pt(e,n){return dt(e,r(r({},n),{to:t.SpecialTargets.Parent}))}function yt(){return pt(T)}var gt=function(t,e){return{context:t,event:e}};var mt=function(t,e,n){return r(r({},t),{value:G(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})},St=function(t){return{type:d,sendId:t}};function xt(e){var n=ht(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function bt(e){var n=H(e)?e:ht(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function wt(e,n,r){var i=H(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}var _t=function(t){return{type:p,assignment:t}};function Tt(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Et(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Ot(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function kt(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function jt(t,e){return dt((function(t,e){return e}),r(r({},e),{to:t}))}function At(t,e,n,i,o,c){void 0===c&&(c=!1);var u=a(c?[[],o]:J(o,(function(t){return t.type===p})),2),d=u[0],v=u[1],y=d.length?X(n,i,d,e):n,g=c?[n]:void 0;return[M(v.map((function(n){var o;switch(n.type){case f:return lt(n);case l:return vt(n,y,i,t.options.delays);case m:return mt(n,y,i);case E:if(!(S=null===(o=n.conds.find((function(n){var r=K(n.cond,t.options.guards);return!r||nt(t,r,y,i,e)})))||void 0===o?void 0:o.actions))return[];var u=a(At(t,e,y,i,ut(F(S),t.options.actions),c),2),d=u[0],v=u[1];return y=v,null==g||g.push(y),d;case O:var S;if(!(S=n.get(y,i.data)))return[];var x=a(At(t,e,y,i,ut(F(S),t.options.actions),c),2),b=x[0],w=x[1];return y=w,null==g||g.push(y),b;case h:return wt(n,y,i);case p:y=X(y,i,[n],e),null==g||g.push(y);break;default:var _=ct(n,t.options.actions),T=_.exec;if(T&&g){var k=g.length-1;_=r(r({},_),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];T.apply(void 0,s([g[k]],a(e),!1))}})}return _}})).filter((function(t){return!!t}))),y]}var Nt=Object.freeze({__proto__:null,actionTypes:k,initEvent:at,getActionFunction:st,toActionObject:ct,toActionObjects:ut,toActivityDefinition:ht,raise:ft,resolveRaise:lt,send:dt,resolveSend:vt,sendParent:pt,sendTo:function(t,e,n){return dt(e,r(r({},n),{to:t}))},sendUpdate:yt,respond:function(t,e){return dt(t,r(r({},e),{to:function(t,e,n){return n._event.origin}}))},log:function(t,e){return void 0===t&&(t=gt),{type:m,label:e,expr:t}},resolveLog:mt,cancel:St,start:xt,stop:bt,resolveStop:wt,assign:_t,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Tt,done:Et,doneInvoke:Ot,error:kt,pure:function(e){return{type:t.ActionTypes.Pure,get:e}},forwardTo:jt,escalate:function(e,n){return pt((function(t,n,r){return{type:_,data:H(e)?e(t,n,r):e}}),r(r({},n),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},resolveActions:At}),Pt=[],It=function(t,e){Pt.push(t);var n=e(t);return Pt.pop(),n};function Ct(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[Q]=function(){return this},e}function Vt(t,e,n){var r=Ct(e);if(r.deferred=!0,W(t)){var i=r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Lt(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[Q]=function(){return this},e),t)}var Dt=function(t){return"atomic"===t.type||"final"===t.type};function Rt(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function Mt(t){var e=[t];return Dt(t)?e:e.concat(M(Rt(t).map(Mt)))}function zt(t,e){var n,r,i,a,s,c,u,h,f=Ft(new Set(t)),l=new Set(e);try{for(var d=o(l),v=d.next();!v.done;v=d.next())for(var p=(T=v.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}catch(t){n={error:t}}finally{try{v&&!v.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=Ft(l);try{for(var g=o(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,o(Rt(T))),x=S.next();!x.done;x=S.next()){var b=x.value;"history"!==b.type&&(l.has(b)||(l.add(b),f.get(b)?f.get(b).forEach((function(t){return l.add(t)})):b.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{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){i={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(i)throw i.error}}try{for(var w=o(l),_=w.next();!_.done;_=w.next()){var T;for(p=(T=_.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}return l}function Ft(t){var e,n,r=new Map;try{for(var i=o(t),a=i.next();!a.done;a=i.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}function Bt(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(Dt(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,Ft(zt([t],e)))}function Ut(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function Jt(t,e){return"compound"===e.type?Rt(e).some((function(e){return"final"===e.type&&Ut(t,e)})):"parallel"===e.type&&Rt(e).every((function(e){return Jt(t,e)}))}function qt(t){return new Set(M(t.map((function(t){return t.tags}))))}var Xt=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=j,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||j,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],a(new Set(M(s([],a(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(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:at,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=at;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="."),G(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],a(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=i(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return A(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}(),$t={deferEvents:!1},Ht=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},$t),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}(),Gt=new Map,Kt=0,Qt=function(){return"x:".concat(Kt++)},Wt=function(t,e){return Gt.set(t,e),t},Yt=function(t){return Gt.get(t)},Zt=function(t){Gt.delete(t)};function te(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function ee(t){if(te()){var e=function(){var t=te();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ne(t,e){void 0===e&&(e={});var n=t.initialState,r=new Set,i=[],o=!1,a=Lt({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=it(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 re,ie={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(re=t.InterpreterStatus||(t.InterpreterStatus={}))[re.NotStarted=0]="NotStarted",re[re.Running=1]="Running",re[re.Stopped=2]="Stopped";var oe=function(){function e(n,i){var o=this;void 0===i&&(i=e.defaultOptions),this.machine=n,this.scheduler=new Ht,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if($(e))return o.batch(e),o.state;var r=tt(Z(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(e,n){var i,a=o.parent&&(n===t.SpecialTargets.Parent||o.parent.id===n),s=a?o.parent:G(n)?o.children.get(n)||Yt(n):(i=n)&&"function"==typeof i.send?n:void 0;if(s)"machine"in s?s.send(r(r({},e),{name:e.name===_?"".concat(kt(o.id)):e.name,origin:o.sessionId})):s.send(e.data);else if(!a)throw new Error("Unable to send event to child '".concat(n,"' from service '").concat(o.id,"'."))};var a=r(r({},e.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:n.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Ht({deferEvents:this.options.deferEvents}),this.sessionId=Qt()}return Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:It(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),e.prototype.execute=function(t,e){var n,r;try{for(var i=o(t.actions),a=i.next();!a.done;a=i.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,r,i,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=o(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var v=o(this.listeners),p=v.next();!p.done;p=v.next()){(0,p.value)(t,t.event)}}catch(t){i={error:t}}finally{try{p&&!p.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}try{for(var y=o(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=Jt(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?B(S.doneData,t.context,e):void 0;try{for(var b=o(this.doneListeners),w=b.next();!w.done;w=b.next()){(0,w.value)(Ot(this.id,x))}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},e.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},e.prototype.subscribe=function(e,n,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)}}},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(t){return this.doneListeners.add(t),this},e.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},e.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;Wt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:It(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(Xt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,at)})),this},e.prototype.stop=function(){var e,n,r,i,c,u,h,f,l,d,v=this;try{for(var p=o(this.listeners),y=p.next();!y.done;y=p.next()){var g=y.value;this.listeners.delete(g)}}catch(t){e={error:t}}finally{try{y&&!y.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var m=o(this.stopListeners),S=m.next();!S.done;S=m.next()){(g=S.value)(),this.stopListeners.delete(g)}}catch(t){r={error:t}}finally{try{S&&!S.done&&(i=m.return)&&i.call(m)}finally{if(r)throw r.error}}try{for(var x=o(this.contextListeners),b=x.next();!b.done;b=x.next()){g=b.value;this.contextListeners.delete(g)}}catch(t){c={error:t}}finally{try{b&&!b.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}try{for(var w=o(this.doneListeners),_=w.next();!_.done;_=w.next()){g=_.value;this.doneListeners.delete(g)}}catch(t){h={error:t}}finally{try{_&&!_.done&&(f=w.return)&&f.call(w)}finally{if(h)throw h.error}}if(!this.initialized)return this;s([],a(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var r=o(t.definition.exit),i=r.next();!i.done;i=r.next()){var a=i.value;v.exec(a,v.state)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){H(t.stop)&&t.stop()}));try{for(var T=o(Object.keys(this.delayedEventsMap)),E=T.next();!E.done;E=T.next()){var O=E.value;this.clock.clearTimeout(this.delayedEventsMap[O])}}catch(t){l={error:t}}finally{try{E&&!E.done&&(d=T.return)&&d.call(T)}finally{if(l)throw l.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Zt(this.sessionId),this},e.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,i,c=n.state,u=!1,h=[],f=function(t){var e=tt(t);n.forward(e),c=It(n,(function(){return n.machine.transition(c,e)})),h.push.apply(h,s([],a(c.actions.map((function(t){return n=c,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)),u=u||!!c.changed};try{for(var l=o(e),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(t)throw t.error}}c.changed=u,c.actions=h,n.update(c,tt(e[e.length-1]))}))},e.prototype.sender=function(t){return this.send.bind(this,t)},e.prototype.nextState=function(t){var e=this,n=tt(t);if(0===n.name.indexOf(w)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(w)})))throw n.data.data;return It(this,(function(){return e.machine.transition(e.state,n)}))},e.prototype.forward=function(t){var e,n;try{for(var r=o(this.forwardTo),i=r.next();!i.done;i=r.next()){var a=i.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{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},e.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)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||st(e.type,r),s=H(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 l: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 d:this.cancel(e.sendId);break;case u:if(this.status!==t.InterpreterStatus.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===t.ActionTypes.Invoke){var v=rt(f.src),p=this.machine.options.services?this.machine.options.services[v.type]:void 0,y=f.id,g=f.data,S="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var x=g?B(g,i,o):void 0;if("string"==typeof p)return;var b=H(p)?p(i,o.data,{data:x,src:v,meta:f.meta}):p;if(!b)return;var w=void 0;W(b)&&(b=x?b.withContext(x):b,w={autoForward:S}),this.spawn(b,y,w)}else this.spawnActivity(f);break;case h:this.stopChild(e.activity.id);break;case m:var _=e.label,T=e.value;_?this.logger(_,T):this.logger(T)}},e.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),H(e.stop)&&e.stop())},e.prototype.spawn=function(t,e,n){if(U(t))return this.spawnPromise(Promise.resolve(t),e);if(H(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&&H(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(W(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},e.prototype.spawnMachine=function(t,n){var i=this;void 0===n&&(n={});var o=new e(t,r(r({},this.options),{parent:this,id:n.id||t.id})),a=r(r({},ie),n);a.sync&&o.onTransition((function(t){i.send(T,{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(tt(t,{origin:o.id}))})).start(),s},e.prototype.spawnBehavior=function(t,e){var n=ne(t,{id:e,parent:this});return this.children.set(e,n),n},e.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(tt(Ot(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=kt(e,t);try{i.send(tt(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=it(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}})[Q]=function(){return this},n);return this.children.set(e,a),a},e.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(tt(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(kt(e,t))}if(U(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=it(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){a=!0,H(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[Q]=function(){return this},n);return this.children.set(e,u),u},e.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(tt(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(tt(kt(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(tt(Ot(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}}})[Q]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},e.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},e.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[Q]=function(){return this},n))},e.prototype.attachDev=function(){var t=te();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)}ee(this)}},e.prototype.toJSON=function(){return{id:this.id}},e.prototype[Q]=function(){return this},e.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},e.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),e.interpret=ae,e}();function ae(t,e){return new oe(t,e)}function se(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function ce(t){return r(r({type:x},t),{toJSON:function(){t.onDone,t.onError;var e=i(t,["onDone","onError"]);return r(r({},e),{type:x,src:se(t.src)})}})}var ue={},he=function(t){return"#"===t[0]},fe=function(){function e(t,n,i,c){var u,h=this;void 0===i&&(i="context"in t?t.context:void 0),this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==c?void 0:c.parent,this.key=this.config.key||(null==c?void 0:c.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||s([this.machine.key],a(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?V(this.config.states,(function(t,n){var i,o=new e(t,{},void 0,{parent:h,key:n});return Object.assign(h.idMap,r(((i={})[o.id]=o,i),o.idMap)),o})):ue;var f=0;!function t(e){var n,r;e.order=f++;try{for(var i=o(Rt(e)),a=i.next();!a.done;a=i.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}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=F(this.config.entry||this.config.onEntry).map((function(t){return ct(t)})),this.onExit=F(this.config.exit||this.config.onExit).map((function(t){return ct(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=F(this.config.invoke).map((function(t,e){var n,i;if(W(t)){var o=ot(h.id,e);return h.machine.options.services=r(((n={})[o]=t,n),h.machine.options.services),ce({src:o,id:o})}if(G(t.src)){o=t.id||ot(h.id,e);return ce(r(r({},t),{id:o,src:t.src}))}if(W(t.src)||H(t.src)){o=t.id||ot(h.id,e);return h.machine.options.services=r(((i={})[o]=t.src,i),h.machine.options.services),ce(r(r({id:o},t),{src:o}))}var a=t.src;return ce(r(r({id:ot(h.id,e)},t),{src:a}))})),this.activities=F(this.config.activities).concat(this.invoke).map((function(t){return ht(t)})),this.transition=this.transition.bind(this),this.tags=F(this.config.tags)}return e.prototype._init=function(){this.__cache.transitions||Mt(this).forEach((function(t){return t.on}))},e.prototype.withConfig=function(t,n){var i=this.options,o=i.actions,a=i.activities,s=i.guards,c=i.services,u=i.delays;return new e(this.config,{actions:r(r({},o),t.actions),activities:r(r({},a),t.activities),guards:r(r({},s),t.guards),services:r(r({},c),t.services),delays:r(r({},u),t.delays)},null!=n?n:this.context)},e.prototype.withContext=function(t){return new e(this.config,this.options,t)},Object.defineProperty(e.prototype,"context",{get:function(){return H(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(e.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:V(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}),e.prototype.toJSON=function(){return this.definition},Object.defineProperty(e.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(e.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),e.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},e.prototype.getDelayedTransitions=function(){var t=this,e=this.config.after;if(!e)return[];var n=function(e,n){var r=Tt(H(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(dt(r,{delay:e})),t.onExit.push(St(r)),r};return($(e)?e.map((function(t,e){var i=n(t.delay,e);return r(r({},t),{event:i})})):M(Object.keys(e).map((function(t,i){var o=e[t],a=G(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=n(s,i);return F(a).map((function(t){return r(r({},t),{event:c,delay:s})}))})))).map((function(e){var n=e.delay;return r(r({},t.formatTransition(e)),{delay:n})}))},e.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Xt?t.value:I(t,this.delimiter);if(G(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this,this.states[r]]}var o=Object.keys(r),c=[this];return c.push.apply(c,s([],a(M(o.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),c},e.prototype.handles=function(t){var e=N(t);return this.events.includes(e)},e.prototype.resolveState=function(t){var e=t instanceof Xt?t:Xt.create(t),n=Array.from(zt([],this.getStateNodes(e.value)));return new Xt(r(r({},e),{value:this.resolve(e.value),configuration:n,done:Jt(n,this),tags:qt(n)}))},e.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},e.prototype.transitionCompoundNode=function(t,e,n){var r=Object.keys(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},e.prototype.transitionParallelNode=function(t,e,n){var r,i,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];if(h){var f=this.getStateNode(u)._transition(h,e,n);f&&(a[u]=f)}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}var l=Object.keys(a).map((function(t){return a[t]})),d=M(l.map((function(t){return t.transitions})));if(!l.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=M(l.map((function(t){return t.entrySet}))),p=M(Object.keys(a).map((function(t){return a[t].configuration})));return{transitions:d,entrySet:v,exitSet:M(l.map((function(t){return t.exitSet}))),configuration:p,source:e,actions:M(Object.keys(a).map((function(t){return a[t].actions})))}},e.prototype._transition=function(t,e,n){return G(t)?this.transitionLeafNode(t,e,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},e.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,tt(e))},e.prototype.next=function(t,e){var n,r,i,c=this,u=e.name,h=[],f=[];try{for(var l=o(this.getCandidates(u)),d=l.next();!d.done;d=l.next()){var v=d.value,p=v.cond,y=v.in,g=t.context,m=!y||(G(y)&&he(y)?t.matches(I(this.getStateNodeById(y).path,this.delimiter)):A(I(y,this.delimiter),D(this.path.slice(0,-2))(t.value))),S=!1;try{S=!p||nt(this.machine,p,g,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(p.name||p.type,"' in transition for event '").concat(u,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(S&&m){void 0!==v.target&&(f=v.target),h.push.apply(h,s([],a(v.actions),!1)),i=v;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(i){if(!f.length)return{transitions:[i],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var x=M(f.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),b=!!i.internal;return{transitions:[i],entrySet:b?[]:M(x.map((function(t){return c.nodesFromChild(t)}))),exitSet:b?[]:[this],configuration:x,source:t,actions:h}}},e.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},e.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},e.prototype.getActions=function(t,e,n,r){var i,c,u,h,f=zt([],r?this.getStateNodes(r.value):[this]),l=t.configuration.length?zt(f,t.configuration):f;try{for(var d=o(l),v=d.next();!v.done;v=d.next()){Ut(f,g=v.value)||t.entrySet.push(g)}}catch(t){i={error:t}}finally{try{v&&!v.done&&(c=d.return)&&c.call(d)}finally{if(i)throw i.error}}try{for(var p=o(f),y=p.next();!y.done;y=p.next()){var g;Ut(l,g=y.value)&&!Ut(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=p.return)&&h.call(p)}finally{if(u)throw u.error}}var m=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(Et(r.id,r.doneData),Et(o.id,r.doneData?B(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&Rt(a).every((function(e){return Jt(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var S=new Set(t.entrySet),x=new Set(t.exitSet),b=a([M(Array.from(S).map((function(t){return s(s([],a(t.activities.map((function(t){return xt(t)}))),!1),a(t.onEntry),!1)}))).concat(m.map(ft)),M(Array.from(x).map((function(t){return s(s([],a(t.onExit),!1),a(t.activities.map((function(t){return bt(t)}))),!1)})))],2),w=b[0],_=b[1];return ut(_.concat(t.actions).concat(w),this.machine.options.actions)},e.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,i,o=tt(e);if(t instanceof Xt)r=void 0===n?t:this.resolveState(Xt.from(t,n));else{var c=G(t)?this.resolve(C(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Xt.from(c,u))}if(this.strict&&!this.events.includes(o.name)&&(i=o.name,!/^(done|error)\./.test(i)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(o.name,"'"));var h=this._transition(r.value,r,o)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=zt([],this.getStateNodes(r.value)),l=h.configuration.length?zt(f,h.configuration):f;return h.configuration=s([],a(l),!1),this.resolveTransition(h,r,r.context,o)},e.prototype.resolveRaisedTransition=function(t,e,n){var r,i=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,s([],a(i),!1)),t},e.prototype.resolveTransition=function(e,n,i,s){var c,d,p=this;void 0===s&&(s=at);var y=e.configuration,g=!n||e.transitions.length>0,m=g?Bt(this.machine,y):void 0,S=n?n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0:void 0,b=this.getActions(e,i,s,n),w=n?r({},n.activities):{};try{for(var _=o(b),E=_.next();!E.done;E=_.next()){var O=E.value;O.type===u?w[O.activity.id||O.activity.type]=O:O.type===h&&(w[O.activity.id||O.activity.type]=!1)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(d=_.return)&&d.call(_)}finally{if(c)throw c.error}}var k,j,A=a(At(this,n,i,s,b,this.machine.config.preserveActionOrder),2),N=A[0],P=A[1],I=a(J(N,(function(e){return e.type===f||e.type===l&&e.to===t.SpecialTargets.Internal})),2),C=I[0],V=I[1],L=N.filter((function(t){var e;return t.type===u&&(null===(e=t.activity)||void 0===e?void 0:e.type)===x})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=rt(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?B(t.data,n,r):void 0,c=a?Vt(a,t.id,s):Ct(t.id);return c.meta=t,c}(e.activity,p.machine,P,s),t}),n?r({},n.children):{}),D=g?e.configuration:n?n.configuration:[],R=Jt(D,this),M=new Xt({value:m||n.value,context:P,_event:s,_sessionid:n?n._sessionid:null,historyValue:m?S?(k=S,j=m,{current:j,states:q(k,j)}):void 0:n?n.historyValue:void 0,history:!m||e.source?n:void 0,actions:m?V:[],activities:m?w:n?n.activities:{},events:[],configuration:D,transitions:e.transitions,children:L,done:R,tags:null==n?void 0:n.tags,machine:this}),z=i!==P;M.changed=s.name===T||z;var F=M.history;F&&delete F.history;var U=!R&&(this._transient||y.some((function(t){return t._transient})));if(!(g||U&&""!==s.name))return M;var X=M;if(!R)for(U&&(X=this.resolveRaisedTransition(X,{type:v},s));C.length;){var $=C.shift();X=this.resolveRaisedTransition(X,$._event,s)}var H=X.changed||(F?!!X.actions.length||z||typeof F.value!=typeof X.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(G(e)||G(n))return e===n;var r=Object.keys(e),i=Object.keys(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(X.value,F.value):void 0);return X.changed=H,X.history=F,X.tags=qt(X.configuration),X},e.prototype.getStateNode=function(t){if(he(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},e.prototype.getStateNodeById=function(t){var e=he(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},e.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&he(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=P(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},e.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||ue;switch(this.type){case"parallel":return V(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):ue}));case"compound":if(G(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return Object.keys(t).length?V(t,(function(t,e){return t?n.getStateNode(e).resolve(t):ue})):this.initialStateValue||{};default:return t||ue}},e.prototype.getResolvedPath=function(t){if(he(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 P(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=L(this.states,(function(t){return t.initialStateValue||ue}),(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=Dt(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}),e.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(e.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(e.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=G(e.target)&&he(e.target)?C(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),e.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(e.prototype,"initialStateNodes",{get:function(){var t=this;return Dt(this)?[this]:"compound"!==this.type||this.initial?M(R(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),e.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=a(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 i=this.getStateNode(n);if("history"===i.type)return i.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)},e.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:L(this.states,(function(e,n){if(!t)return e.historyValue();var r=G(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},e.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var r=this.target;return r?M(R(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var i,a,s=(i=n.path,a="states",function(t){var e,n,r=t;try{for(var s=o(i),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return G(s)?[n.getStateNode(s)]:M(R(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,e=M(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var i=this.states,a=new Set(this.ownEvents);if(i)try{for(var s=o(Object.keys(i)),c=s.next();!c.done;c=s.next()){var u=i[c.value];if(u.states)try{for(var h=(n=void 0,o(u.events)),f=h.next();!f.done;f=h.next()){var l=f.value;a.add("".concat(l))}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(e.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}),e.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!G(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))}}))},e.prototype.formatTransition=function(t){var e=this,n=function(t){if(void 0!==t&&""!==t)return F(t)}(t.target),i="internal"in t?t.internal:!n||n.some((function(t){return G(t)&&t[0]===e.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(n),s=r(r({},t),{actions:ut(F(t.actions)),cond:K(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return r(r({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(e.id)})}});return s},e.prototype.formatTransitions=function(){var t,e,n,r=this;if(this.config.on)if(Array.isArray(this.config.on))n=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=i(c,["*"]);n=M(Object.keys(f).map((function(t){return et(t,f[t])})).concat(et("*",h)))}else n=[];var l=this.config.always?et("",this.config.always):[],d=this.config.onDone?et(String(Et(this.id)),this.config.onDone):[],v=M(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,s([],a(et(String(Ot(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,s([],a(et(String(kt(t.id)),t.onError)),!1)),e}))),p=this.after,y=M(s(s(s(s([],a(d),!1),a(v),!1),a(n),!1),a(l),!1).map((function(t){return F(t).map((function(t){return r.formatTransition(t)}))})));try{for(var g=o(p),m=g.next();!m.done;m=g.next()){var S=m.value;y.push(S)}}catch(e){t={error:e}}finally{try{m&&!m.done&&(e=g.return)&&e.call(g)}finally{if(t)throw t.error}}return y},e}();function le(t){return t}var de=le,ve=_t,pe=dt,ye=pt,ge=yt,me=jt,Se=Ot;t.Interpreter=oe,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new fe(t,e,n)},t.State=Xt,t.StateNode=fe,t.actions=Nt,t.assign=ve,t.createMachine=function(t,e){return new fe(t,e)},t.createSchema=le,t.doneInvoke=Se,t.forwardTo=me,t.interpret=ae,t.mapState=function(t,e){var n,r,i;try{for(var a=o(Object.keys(t)),s=a.next();!s.done;s=a.next()){var c=s.value;A(c,e)&&(!i||e.length>i.length)&&(i=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[i]},t.matchState=function(t,e,n){var r,i,s=Xt.from(t,t instanceof Xt?t.context:void 0);try{for(var c=o(e),u=c.next();!u.done;u=c.next()){var h=a(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return n(s)},t.matchesState=A,t.send=pe,t.sendParent=ye,t.sendUpdate=ge,t.spawn=function(t,e){var n=function(t){return G(t)?r(r({},ie),{name:t}):r(r(r({},ie),{name:Y()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):Vt(t,n.name)}(Pt[Pt.length-1])},t.spawnBehavior=ne,t.t=de,t.toActorRef=Lt,t.toEventObject=Z,t.toObserver=it,t.toSCXMLEvent=tt,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,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 o(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 a(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 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))}t.ActionTypes=void 0,(e=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Update="xstate.update",e.Pure="xstate.pure",e.Choose="xstate.choose",t.SpecialTargets=void 0,(n=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",n.Internal="#_internal";var c,u=t.ActionTypes.Start,h=t.ActionTypes.Stop,f=t.ActionTypes.Raise,l=t.ActionTypes.Send,d=t.ActionTypes.Cancel,v=t.ActionTypes.NullEvent,p=t.ActionTypes.Assign,y=t.ActionTypes.After,g=t.ActionTypes.DoneState,m=t.ActionTypes.Log,S=t.ActionTypes.Init,x=t.ActionTypes.Invoke,b=t.ActionTypes.ErrorExecution,w=t.ActionTypes.ErrorPlatform,_=t.ActionTypes.ErrorCustom,T=t.ActionTypes.Update,E=t.ActionTypes.Choose,O=t.ActionTypes.Pure,k=Object.freeze({__proto__:null,start:u,stop:h,raise:f,send:l,cancel:d,nullEvent:v,assign:p,after:y,doneState:g,log:m,init:S,invoke:x,errorExecution:b,errorPlatform:w,error:_,update:T,choose:E,pure:O}),j={};function A(t,e,n){void 0===n&&(n=".");var r=I(t,n),i=I(e,n);return G(i)?!!G(r)&&i===r:G(r)?r in i:Object.keys(r).every((function(t){return t in i&&A(r[t],i[t])}))}function N(t){try{return G(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 P(t,e){try{return $(t)?t:t.toString().split(e)}catch(e){throw new Error("'".concat(t,"' is not a valid state path."))}}function I(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:$(t)?C(t):"string"!=typeof t?t:C(P(t,e));var n}function C(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function V(t,e){for(var n={},r=Object.keys(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function L(t,e,n){var r,i,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];n(h)&&(a[u]=e(h,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}var D=function(t){return function(e){var n,r,i=e;try{for(var a=o(t),s=a.next();!s.done;s=a.next()){i=i[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return i}};function R(t){return t?G(t)?[[t]]:M(Object.keys(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?R(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function M(t){var e;return(e=[]).concat.apply(e,s([],a(t),!1))}function z(t){return $(t)?t:[t]}function F(t){return void 0===t?[]:z(t)}function B(t,e,n){var r,i;if(H(t))return t(e,n.data);var a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];H(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return a}function U(t){return t instanceof Promise||!(null===t||!H(t)&&"object"!=typeof t||!H(t.then))}function J(t,e){var n,r,i=a([[],[]],2),s=i[0],c=i[1];try{for(var u=o(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}return[s,c]}function q(t,e){return V(t.states,(function(t,n){if(t){var r=(G(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:q(t,r)}}}))}function X(t,e,n,r){return t?n.reduce((function(t,n){var i,a,s=n.assignment,c={state:r,action:n,_event:e},u={};if(H(s))u=s(t,e.data,c);else try{for(var h=o(Object.keys(s)),f=h.next();!f.done;f=h.next()){var l=f.value,d=s[l];u[l]=H(d)?d(t,e.data,c):d}}catch(t){i={error:t}}finally{try{f&&!f.done&&(a=h.return)&&a.call(h)}finally{if(i)throw i.error}}return Object.assign({},t,u)}),t):t}function $(t){return Array.isArray(t)}function H(t){return"function"==typeof t}function G(t){return"string"==typeof t}function K(t,e){if(t)return G(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:H(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var Q=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function W(t){return!!t&&"__xstatenode"in t}(c={})[Q]=function(){return this},c[Symbol.observable]=function(){return this};var Y=function(){var t=0;return function(){return(++t).toString(16)}}();function Z(t,e){return G(t)||"number"==typeof t?r({type:t},e):t}function tt(t,e){if(!G(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=Z(t);return r({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function et(t,e){return z(e).map((function(e){return void 0===e||"string"==typeof e||W(e)?{target:e,event:t}:r(r({},e),{event:t})}))}function nt(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 rt(t){return"string"==typeof t?{type:t}:t}function it(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}function ot(t,e){return"".concat(t,":invocation[").concat(e,"]")}var at=tt({type:S});function st(t,e){return e&&e[t]||void 0}function ct(t,e){var n;if(G(t)||"number"==typeof t)n=H(i=st(t,e))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(H(t))n={type:t.name||t.toString(),exec:t};else{var i;if(H(i=st(t.type,e)))n=r(r({},t),{exec:i});else if(i){var o=i.type||t.type;n=r(r(r({},i),t),{type:o})}else n=t}return n}var ut=function(t,e){return t?($(t)?t:[t]).map((function(t){return ct(t,e)})):[]};function ht(t){var e=ct(t);return r(r({id:G(t)?t:e.id},e),{type:e.type})}function ft(e){return G(e)?{type:f,event:e}:dt(e,{to:t.SpecialTargets.Internal})}function lt(t){return{type:f,_event:tt(t.event)}}function dt(t,e){return{to:e?e.to:void 0,type:l,event:H(t)?t:Z(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:H(t)?t.name:N(t)}}function vt(t,e,n,i){var o,a={_event:n},s=tt(H(t.event)?t.event(e,n.data,a):t.event);if(G(t.delay)){var c=i&&i[t.delay];o=H(c)?c(e,n.data,a):c}else o=H(t.delay)?t.delay(e,n.data,a):t.delay;var u=H(t.to)?t.to(e,n.data,a):t.to;return r(r({},t),{to:u,_event:s,event:s.data,delay:o})}function pt(e,n){return dt(e,r(r({},n),{to:t.SpecialTargets.Parent}))}function yt(){return pt(T)}var gt=function(t,e){return{context:t,event:e}};var mt=function(t,e,n){return r(r({},t),{value:G(t.expr)?t.expr:t.expr(e,n.data,{_event:n})})},St=function(t){return{type:d,sendId:t}};function xt(e){var n=ht(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function bt(e){var n=H(e)?e:ht(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}function wt(e,n,r){var i=H(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}var _t=function(t){return{type:p,assignment:t}};function Tt(e,n){var r=n?"#".concat(n):"";return"".concat(t.ActionTypes.After,"(").concat(e,")").concat(r)}function Et(e,n){var r="".concat(t.ActionTypes.DoneState,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function Ot(e,n){var r="".concat(t.ActionTypes.DoneInvoke,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function kt(e,n){var r="".concat(t.ActionTypes.ErrorPlatform,".").concat(e),i={type:r,data:n,toString:function(){return r}};return i}function jt(t,e){return dt((function(t,e){return e}),r(r({},e),{to:t}))}function At(t,e,n,i,o,c){void 0===c&&(c=!1);var u=a(c?[[],o]:J(o,(function(t){return t.type===p})),2),d=u[0],v=u[1],y=d.length?X(n,i,d,e):n,g=c?[n]:void 0;return[M(v.map((function(n){var o;switch(n.type){case f:return lt(n);case l:return vt(n,y,i,t.options.delays);case m:return mt(n,y,i);case E:if(!(S=null===(o=n.conds.find((function(n){var r=K(n.cond,t.options.guards);return!r||nt(t,r,y,i,e)})))||void 0===o?void 0:o.actions))return[];var u=a(At(t,e,y,i,ut(F(S),t.options.actions),c),2),d=u[0],v=u[1];return y=v,null==g||g.push(y),d;case O:var S;if(!(S=n.get(y,i.data)))return[];var x=a(At(t,e,y,i,ut(F(S),t.options.actions),c),2),b=x[0],w=x[1];return y=w,null==g||g.push(y),b;case h:return wt(n,y,i);case p:y=X(y,i,[n],e),null==g||g.push(y);break;default:var _=ct(n,t.options.actions),T=_.exec;if(T&&g){var k=g.length-1;_=r(r({},_),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];T.apply(void 0,s([g[k]],a(e),!1))}})}return _}})).filter((function(t){return!!t}))),y]}var Nt=Object.freeze({__proto__:null,actionTypes:k,initEvent:at,getActionFunction:st,toActionObject:ct,toActionObjects:ut,toActivityDefinition:ht,raise:ft,resolveRaise:lt,send:dt,resolveSend:vt,sendParent:pt,sendTo:function(t,e,n){return dt(e,r(r({},n),{to:t}))},sendUpdate:yt,respond:function(t,e){return dt(t,r(r({},e),{to:function(t,e,n){return n._event.origin}}))},log:function(t,e){return void 0===t&&(t=gt),{type:m,label:e,expr:t}},resolveLog:mt,cancel:St,start:xt,stop:bt,resolveStop:wt,assign:_t,isActionObject:function(t){return"object"==typeof t&&"type"in t},after:Tt,done:Et,doneInvoke:Ot,error:kt,pure:function(e){return{type:t.ActionTypes.Pure,get:e}},forwardTo:jt,escalate:function(e,n){return pt((function(t,n,r){return{type:_,data:H(e)?e(t,n,r):e}}),r(r({},n),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},resolveActions:At}),Pt=[],It=function(t,e){Pt.push(t);var n=e(t);return Pt.pop(),n};function Ct(t){var e;return(e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}})[Q]=function(){return this},e}function Vt(t,e,n){var r=Ct(e);if(r.deferred=!0,W(t)){var i=r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Lt(t){var e;return r(((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}})[Q]=function(){return this},e),t)}var Dt=function(t){return"atomic"===t.type||"final"===t.type};function Rt(t){return Object.keys(t.states).map((function(e){return t.states[e]}))}function Mt(t){var e=[t];return Dt(t)?e:e.concat(M(Rt(t).map(Mt)))}function zt(t,e){var n,r,i,a,s,c,u,h,f=Ft(new Set(t)),l=new Set(e);try{for(var d=o(l),v=d.next();!v.done;v=d.next())for(var p=(T=v.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}catch(t){n={error:t}}finally{try{v&&!v.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=Ft(l);try{for(var g=o(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,o(Rt(T))),x=S.next();!x.done;x=S.next()){var b=x.value;"history"!==b.type&&(l.has(b)||(l.add(b),f.get(b)?f.get(b).forEach((function(t){return l.add(t)})):b.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{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){i={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(i)throw i.error}}try{for(var w=o(l),_=w.next();!_.done;_=w.next()){var T;for(p=(T=_.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}return l}function Ft(t){var e,n,r=new Map;try{for(var i=o(t),a=i.next();!a.done;a=i.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}function Bt(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(Dt(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,Ft(zt([t],e)))}function Ut(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function Jt(t,e){return"compound"===e.type?Rt(e).some((function(e){return"final"===e.type&&Ut(t,e)})):"parallel"===e.type&&Rt(e).every((function(e){return Jt(t,e)}))}function qt(t){return new Set(M(t.map((function(t){return t.tags}))))}var Xt=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=j,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||j,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return s([],a(new Set(M(s([],a(t.map((function(t){return t.ownEvents}))),!1)))),!1)}(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:at,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=at;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="."),G(t))return[t];var r=Object.keys(t);return r.concat.apply(r,s([],a(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))),!1))},t.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var e=t.tags;t.machine;var n=i(t,["configuration","transitions","tags","machine"]);return r(r({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return A(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}(),$t={deferEvents:!1},Ht=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},$t),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}(),Gt=new Map,Kt=0,Qt=function(){return"x:".concat(Kt++)},Wt=function(t,e){return Gt.set(t,e),t},Yt=function(t){return Gt.get(t)},Zt=function(t){Gt.delete(t)};function te(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function ee(t){if(te()){var e=function(){var t=te();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function ne(t,e){void 0===e&&(e={});var n=t.initialState,r=new Set,i=[],o=!1,a=Lt({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=it(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 re,ie={sync:!1,autoForward:!1};t.InterpreterStatus=void 0,(re=t.InterpreterStatus||(t.InterpreterStatus={}))[re.NotStarted=0]="NotStarted",re[re.Running=1]="Running",re[re.Stopped=2]="Stopped";var oe=function(){function e(n,i){var o=this;void 0===i&&(i=e.defaultOptions),this.machine=n,this.scheduler=new Ht,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if($(e))return o.batch(e),o.state;var r=tt(Z(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(e,n){var i,a=o.parent&&(n===t.SpecialTargets.Parent||o.parent.id===n),s=a?o.parent:G(n)?o.children.get(n)||Yt(n):(i=n)&&"function"==typeof i.send?n:void 0;if(s)"machine"in s?s.send(r(r({},e),{name:e.name===_?"".concat(kt(o.id)):e.name,origin:o.sessionId})):s.send(e.data);else if(!a)throw new Error("Unable to send event to child '".concat(n,"' from service '").concat(o.id,"'."))};var a=r(r({},e.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:n.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Ht({deferEvents:this.options.deferEvents}),this.sessionId=Qt()}return Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:It(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),e.prototype.execute=function(t,e){var n,r;try{for(var i=o(t.actions),a=i.next();!a.done;a=i.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.update=function(t,e){var n,r,i,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=o(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var v=o(this.listeners),p=v.next();!p.done;p=v.next()){(0,p.value)(t,t.event)}}catch(t){i={error:t}}finally{try{p&&!p.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}try{for(var y=o(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=Jt(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?B(S.doneData,t.context,e):void 0;try{for(var b=o(this.doneListeners),w=b.next();!w.done;w=b.next()){(0,w.value)(Ot(this.id,x))}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},e.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},e.prototype.subscribe=function(e,n,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)}}},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(t){return this.doneListeners.add(t),this},e.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},e.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;this.machine._init(),Wt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:It(this,(function(){return"object"==typeof(t=e)&&null!==t&&"value"in t&&"_event"in t?n.machine.resolveState(e):n.machine.resolveState(Xt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,at)})),this},e.prototype.stop=function(){var e,n,r,i,c,u,h,f,l,d,v=this;try{for(var p=o(this.listeners),y=p.next();!y.done;y=p.next()){var g=y.value;this.listeners.delete(g)}}catch(t){e={error:t}}finally{try{y&&!y.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var m=o(this.stopListeners),S=m.next();!S.done;S=m.next()){(g=S.value)(),this.stopListeners.delete(g)}}catch(t){r={error:t}}finally{try{S&&!S.done&&(i=m.return)&&i.call(m)}finally{if(r)throw r.error}}try{for(var x=o(this.contextListeners),b=x.next();!b.done;b=x.next()){g=b.value;this.contextListeners.delete(g)}}catch(t){c={error:t}}finally{try{b&&!b.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}try{for(var w=o(this.doneListeners),_=w.next();!_.done;_=w.next()){g=_.value;this.doneListeners.delete(g)}}catch(t){h={error:t}}finally{try{_&&!_.done&&(f=w.return)&&f.call(w)}finally{if(h)throw h.error}}if(!this.initialized)return this;s([],a(this.state.configuration),!1).sort((function(t,e){return e.order-t.order})).forEach((function(t){var e,n;try{for(var r=o(t.definition.exit),i=r.next();!i.done;i=r.next()){var a=i.value;v.exec(a,v.state)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){H(t.stop)&&t.stop()}));try{for(var T=o(Object.keys(this.delayedEventsMap)),E=T.next();!E.done;E=T.next()){var O=E.value;this.clock.clearTimeout(this.delayedEventsMap[O])}}catch(t){l={error:t}}finally{try{E&&!E.done&&(d=T.return)&&d.call(T)}finally{if(l)throw l.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Zt(this.sessionId),this},e.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'));this.scheduler.schedule((function(){var t,i,c=n.state,u=!1,h=[],f=function(t){var e=tt(t);n.forward(e),c=It(n,(function(){return n.machine.transition(c,e)})),h.push.apply(h,s([],a(c.actions.map((function(t){return n=c,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)),u=u||!!c.changed};try{for(var l=o(e),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(t)throw t.error}}c.changed=u,c.actions=h,n.update(c,tt(e[e.length-1]))}))},e.prototype.sender=function(t){return this.send.bind(this,t)},e.prototype.nextState=function(t){var e=this,n=tt(t);if(0===n.name.indexOf(w)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(w)})))throw n.data.data;return It(this,(function(){return e.machine.transition(e.state,n)}))},e.prototype.forward=function(t){var e,n;try{for(var r=o(this.forwardTo),i=r.next();!i.done;i=r.next()){var a=i.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{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(e)throw e.error}}},e.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)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||st(e.type,r),s=H(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 l: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 d:this.cancel(e.sendId);break;case u:if(this.status!==t.InterpreterStatus.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===t.ActionTypes.Invoke){var v=rt(f.src),p=this.machine.options.services?this.machine.options.services[v.type]:void 0,y=f.id,g=f.data,S="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var x=g?B(g,i,o):void 0;if("string"==typeof p)return;var b=H(p)?p(i,o.data,{data:x,src:v,meta:f.meta}):p;if(!b)return;var w=void 0;W(b)&&(b=x?b.withContext(x):b,w={autoForward:S}),this.spawn(b,y,w)}else this.spawnActivity(f);break;case h:this.stopChild(e.activity.id);break;case m:var _=e.label,T=e.value;_?this.logger(_,T):this.logger(T)}},e.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},e.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),H(e.stop)&&e.stop())},e.prototype.spawn=function(t,e,n){if(U(t))return this.spawnPromise(Promise.resolve(t),e);if(H(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&&H(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(W(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},e.prototype.spawnMachine=function(t,n){var i=this;void 0===n&&(n={});var o=new e(t,r(r({},this.options),{parent:this,id:n.id||t.id})),a=r(r({},ie),n);a.sync&&o.onTransition((function(t){i.send(T,{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(tt(t,{origin:o.id}))})).start(),s},e.prototype.spawnBehavior=function(t,e){var n=ne(t,{id:e,parent:this});return this.children.set(e,n),n},e.prototype.spawnPromise=function(t,e){var n,r,i=this,o=!1;t.then((function(t){o||(r=t,i.removeChild(e),i.send(tt(Ot(e,t),{origin:e})))}),(function(t){if(!o){i.removeChild(e);var n=kt(e,t);try{i.send(tt(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=it(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}})[Q]=function(){return this},n);return this.children.set(e,a),a},e.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(tt(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(kt(e,t))}if(U(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=it(t);return c.add(e.next),{unsubscribe:function(){c.delete(e.next)}}},stop:function(){a=!0,H(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return r}})[Q]=function(){return this},n);return this.children.set(e,u),u},e.prototype.spawnObservable=function(t,e){var n,r,i=this,o=t.subscribe((function(t){r=t,i.send(tt(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(tt(kt(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(tt(Ot(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}}})[Q]=function(){return this},n);return this.children.set(e,a),a},e.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},e.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},e.prototype.spawnEffect=function(t,e){var n;this.children.set(t,((n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})[Q]=function(){return this},n))},e.prototype.attachDev=function(){var t=te();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)}ee(this)}},e.prototype.toJSON=function(){return{id:this.id}},e.prototype[Q]=function(){return this},e.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},e.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},e.interpret=ae,e}();function ae(t,e){return new oe(t,e)}function se(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function ce(t){return r(r({type:x},t),{toJSON:function(){t.onDone,t.onError;var e=i(t,["onDone","onError"]);return r(r({},e),{type:x,src:se(t.src)})}})}var ue={},he=function(t){return"#"===t[0]},fe=function(){function e(t,n,i,c){var u,h=this;void 0===i&&(i="context"in t?t.context:void 0),this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=null==c?void 0:c.parent,this.key=this.config.key||(null==c?void 0:c.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||s([this.machine.key],a(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?V(this.config.states,(function(t,n){var i,o=new e(t,{},void 0,{parent:h,key:n});return Object.assign(h.idMap,r(((i={})[o.id]=o,i),o.idMap)),o})):ue;var f=0;!function t(e){var n,r;e.order=f++;try{for(var i=o(Rt(e)),a=i.next();!a.done;a=i.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}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=F(this.config.entry||this.config.onEntry).map((function(t){return ct(t)})),this.onExit=F(this.config.exit||this.config.onExit).map((function(t){return ct(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=F(this.config.invoke).map((function(t,e){var n,i;if(W(t)){var o=ot(h.id,e);return h.machine.options.services=r(((n={})[o]=t,n),h.machine.options.services),ce({src:o,id:o})}if(G(t.src)){o=t.id||ot(h.id,e);return ce(r(r({},t),{id:o,src:t.src}))}if(W(t.src)||H(t.src)){o=t.id||ot(h.id,e);return h.machine.options.services=r(((i={})[o]=t.src,i),h.machine.options.services),ce(r(r({id:o},t),{src:o}))}var a=t.src;return ce(r(r({id:ot(h.id,e)},t),{src:a}))})),this.activities=F(this.config.activities).concat(this.invoke).map((function(t){return ht(t)})),this.transition=this.transition.bind(this),this.tags=F(this.config.tags)}return e.prototype._init=function(){this.__cache.transitions||Mt(this).forEach((function(t){return t.on}))},e.prototype.withConfig=function(t,n){var i=this.options,o=i.actions,a=i.activities,s=i.guards,c=i.services,u=i.delays;return new e(this.config,{actions:r(r({},o),t.actions),activities:r(r({},a),t.activities),guards:r(r({},s),t.guards),services:r(r({},c),t.services),delays:r(r({},u),t.delays)},null!=n?n:this.context)},e.prototype.withContext=function(t){return new e(this.config,this.options,t)},Object.defineProperty(e.prototype,"context",{get:function(){return H(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(e.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:V(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}),e.prototype.toJSON=function(){return this.definition},Object.defineProperty(e.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(e.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),e.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},e.prototype.getDelayedTransitions=function(){var t=this,e=this.config.after;if(!e)return[];var n=function(e,n){var r=Tt(H(e)?"".concat(t.id,":delay[").concat(n,"]"):e,t.id);return t.onEntry.push(dt(r,{delay:e})),t.onExit.push(St(r)),r};return($(e)?e.map((function(t,e){var i=n(t.delay,e);return r(r({},t),{event:i})})):M(Object.keys(e).map((function(t,i){var o=e[t],a=G(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=n(s,i);return F(a).map((function(t){return r(r({},t),{event:c,delay:s})}))})))).map((function(e){var n=e.delay;return r(r({},t.formatTransition(e)),{delay:n})}))},e.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Xt?t.value:I(t,this.delimiter);if(G(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this,this.states[r]]}var o=Object.keys(r),c=[this];return c.push.apply(c,s([],a(M(o.map((function(t){return n.getStateNode(t).getStateNodes(r[t])})))),!1)),c},e.prototype.handles=function(t){var e=N(t);return this.events.includes(e)},e.prototype.resolveState=function(t){var e=t instanceof Xt?t:Xt.create(t),n=Array.from(zt([],this.getStateNodes(e.value)));return new Xt(r(r({},e),{value:this.resolve(e.value),configuration:n,done:Jt(n,this),tags:qt(n),machine:this.machine}))},e.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},e.prototype.transitionCompoundNode=function(t,e,n){var r=Object.keys(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},e.prototype.transitionParallelNode=function(t,e,n){var r,i,a={};try{for(var s=o(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];if(h){var f=this.getStateNode(u)._transition(h,e,n);f&&(a[u]=f)}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}var l=Object.keys(a).map((function(t){return a[t]})),d=M(l.map((function(t){return t.transitions})));if(!l.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=M(l.map((function(t){return t.entrySet}))),p=M(Object.keys(a).map((function(t){return a[t].configuration})));return{transitions:d,entrySet:v,exitSet:M(l.map((function(t){return t.exitSet}))),configuration:p,source:e,actions:M(Object.keys(a).map((function(t){return a[t].actions})))}},e.prototype._transition=function(t,e,n){return G(t)?this.transitionLeafNode(t,e,n):1===Object.keys(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},e.prototype.getTransitionData=function(t,e){return this._transition(t.value,t,tt(e))},e.prototype.next=function(t,e){var n,r,i,c=this,u=e.name,h=[],f=[];try{for(var l=o(this.getCandidates(u)),d=l.next();!d.done;d=l.next()){var v=d.value,p=v.cond,y=v.in,g=t.context,m=!y||(G(y)&&he(y)?t.matches(I(this.getStateNodeById(y).path,this.delimiter)):A(I(y,this.delimiter),D(this.path.slice(0,-2))(t.value))),S=!1;try{S=!p||nt(this.machine,p,g,e,t)}catch(t){throw new Error("Unable to evaluate guard '".concat(p.name||p.type,"' in transition for event '").concat(u,"' in state node '").concat(this.id,"':\n").concat(t.message))}if(S&&m){void 0!==v.target&&(f=v.target),h.push.apply(h,s([],a(v.actions),!1)),i=v;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(i){if(!f.length)return{transitions:[i],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var x=M(f.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),b=!!i.internal;return{transitions:[i],entrySet:b?[]:M(x.map((function(t){return c.nodesFromChild(t)}))),exitSet:b?[]:[this],configuration:x,source:t,actions:h}}},e.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},e.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},e.prototype.getActions=function(t,e,n,r){var i,c,u,h,f=zt([],r?this.getStateNodes(r.value):[this]),l=t.configuration.length?zt(f,t.configuration):f;try{for(var d=o(l),v=d.next();!v.done;v=d.next()){Ut(f,g=v.value)||t.entrySet.push(g)}}catch(t){i={error:t}}finally{try{v&&!v.done&&(c=d.return)&&c.call(d)}finally{if(i)throw i.error}}try{for(var p=o(f),y=p.next();!y.done;y=p.next()){var g;Ut(l,g=y.value)&&!Ut(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=p.return)&&h.call(p)}finally{if(u)throw u.error}}var m=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(Et(r.id,r.doneData),Et(o.id,r.doneData?B(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&Rt(a).every((function(e){return Jt(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var S=new Set(t.entrySet),x=new Set(t.exitSet),b=a([M(Array.from(S).map((function(t){return s(s([],a(t.activities.map((function(t){return xt(t)}))),!1),a(t.onEntry),!1)}))).concat(m.map(ft)),M(Array.from(x).map((function(t){return s(s([],a(t.onExit),!1),a(t.activities.map((function(t){return bt(t)}))),!1)})))],2),w=b[0],_=b[1];return ut(_.concat(t.actions).concat(w),this.machine.options.actions)},e.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,i,o=tt(e);if(t instanceof Xt)r=void 0===n?t:this.resolveState(Xt.from(t,n));else{var c=G(t)?this.resolve(C(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Xt.from(c,u))}if(this.strict&&!this.events.includes(o.name)&&(i=o.name,!/^(done|error)\./.test(i)))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(o.name,"'"));var h=this._transition(r.value,r,o)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=zt([],this.getStateNodes(r.value)),l=h.configuration.length?zt(f,h.configuration):f;return h.configuration=s([],a(l),!1),this.resolveTransition(h,r,r.context,o)},e.prototype.resolveRaisedTransition=function(t,e,n){var r,i=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,s([],a(i),!1)),t},e.prototype.resolveTransition=function(e,n,i,s){var c,d,p=this;void 0===s&&(s=at);var y=e.configuration,g=!n||e.transitions.length>0,m=g?Bt(this.machine,y):void 0,S=n?n.historyValue?n.historyValue:e.source?this.machine.historyValue(n.value):void 0:void 0,b=this.getActions(e,i,s,n),w=n?r({},n.activities):{};try{for(var _=o(b),E=_.next();!E.done;E=_.next()){var O=E.value;O.type===u?w[O.activity.id||O.activity.type]=O:O.type===h&&(w[O.activity.id||O.activity.type]=!1)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(d=_.return)&&d.call(_)}finally{if(c)throw c.error}}var k,j,A=a(At(this,n,i,s,b,this.machine.config.preserveActionOrder),2),N=A[0],P=A[1],I=a(J(N,(function(e){return e.type===f||e.type===l&&e.to===t.SpecialTargets.Internal})),2),C=I[0],V=I[1],L=N.filter((function(t){var e;return t.type===u&&(null===(e=t.activity)||void 0===e?void 0:e.type)===x})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=rt(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?B(t.data,n,r):void 0,c=a?Vt(a,t.id,s):Ct(t.id);return c.meta=t,c}(e.activity,p.machine,P,s),t}),n?r({},n.children):{}),D=g?e.configuration:n?n.configuration:[],R=Jt(D,this),M=new Xt({value:m||n.value,context:P,_event:s,_sessionid:n?n._sessionid:null,historyValue:m?S?(k=S,j=m,{current:j,states:q(k,j)}):void 0:n?n.historyValue:void 0,history:!m||e.source?n:void 0,actions:m?V:[],activities:m?w:n?n.activities:{},events:[],configuration:D,transitions:e.transitions,children:L,done:R,tags:null==n?void 0:n.tags,machine:this}),z=i!==P;M.changed=s.name===T||z;var F=M.history;F&&delete F.history;var U=!R&&(this._transient||y.some((function(t){return t._transient})));if(!(g||U&&""!==s.name))return M;var X=M;if(!R)for(U&&(X=this.resolveRaisedTransition(X,{type:v},s));C.length;){var $=C.shift();X=this.resolveRaisedTransition(X,$._event,s)}var H=X.changed||(F?!!X.actions.length||z||typeof F.value!=typeof X.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(G(e)||G(n))return e===n;var r=Object.keys(e),i=Object.keys(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(X.value,F.value):void 0);return X.changed=H,X.history=F,X.tags=qt(X.configuration),X},e.prototype.getStateNode=function(t){if(he(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},e.prototype.getStateNodeById=function(t){var e=he(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},e.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&he(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=P(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},e.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||ue;switch(this.type){case"parallel":return V(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):ue}));case"compound":if(G(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return Object.keys(t).length?V(t,(function(t,e){return t?n.getStateNode(e).resolve(t):ue})):this.initialStateValue||{};default:return t||ue}},e.prototype.getResolvedPath=function(t){if(he(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 P(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=L(this.states,(function(t){return t.initialStateValue||ue}),(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=Dt(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}),e.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(e.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(e.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=G(e.target)&&he(e.target)?C(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),e.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(e.prototype,"initialStateNodes",{get:function(){var t=this;return Dt(this)?[this]:"compound"!==this.type||this.initial?M(R(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),e.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=a(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 i=this.getStateNode(n);if("history"===i.type)return i.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)},e.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:L(this.states,(function(e,n){if(!t)return e.historyValue();var r=G(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},e.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var r=this.target;return r?M(R(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var i,a,s=(i=n.path,a="states",function(t){var e,n,r=t;try{for(var s=o(i),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return G(s)?[n.getStateNode(s)]:M(R(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,e=M(Object.keys(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var i=this.states,a=new Set(this.ownEvents);if(i)try{for(var s=o(Object.keys(i)),c=s.next();!c.done;c=s.next()){var u=i[c.value];if(u.states)try{for(var h=(n=void 0,o(u.events)),f=h.next();!f.done;f=h.next()){var l=f.value;a.add("".concat(l))}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=h.return)&&r.call(h)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(e.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}),e.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!G(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))}}))},e.prototype.formatTransition=function(t){var e=this,n=function(t){if(void 0!==t&&""!==t)return F(t)}(t.target),i="internal"in t?t.internal:!n||n.some((function(t){return G(t)&&t[0]===e.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(n),s=r(r({},t),{actions:ut(F(t.actions)),cond:K(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return r(r({},s),{target:s.target?s.target.map((function(t){return"#".concat(t.id)})):void 0,source:"#".concat(e.id)})}});return s},e.prototype.formatTransitions=function(){var t,e,n,r=this;if(this.config.on)if(Array.isArray(this.config.on))n=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=i(c,["*"]);n=M(Object.keys(f).map((function(t){return et(t,f[t])})).concat(et("*",h)))}else n=[];var l=this.config.always?et("",this.config.always):[],d=this.config.onDone?et(String(Et(this.id)),this.config.onDone):[],v=M(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,s([],a(et(String(Ot(t.id)),t.onDone)),!1)),t.onError&&e.push.apply(e,s([],a(et(String(kt(t.id)),t.onError)),!1)),e}))),p=this.after,y=M(s(s(s(s([],a(d),!1),a(v),!1),a(n),!1),a(l),!1).map((function(t){return F(t).map((function(t){return r.formatTransition(t)}))})));try{for(var g=o(p),m=g.next();!m.done;m=g.next()){var S=m.value;y.push(S)}}catch(e){t={error:e}}finally{try{m&&!m.done&&(e=g.return)&&e.call(g)}finally{if(t)throw t.error}}return y},e}();function le(t){return t}var de=le,ve=_t,pe=dt,ye=pt,ge=yt,me=jt,Se=Ot;t.Interpreter=oe,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new fe(t,e,n)},t.State=Xt,t.StateNode=fe,t.actions=Nt,t.assign=ve,t.createMachine=function(t,e){return new fe(t,e)},t.createSchema=le,t.doneInvoke=Se,t.forwardTo=me,t.interpret=ae,t.mapState=function(t,e){var n,r,i;try{for(var a=o(Object.keys(t)),s=a.next();!s.done;s=a.next()){var c=s.value;A(c,e)&&(!i||e.length>i.length)&&(i=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[i]},t.matchState=function(t,e,n){var r,i,s=Xt.from(t,t instanceof Xt?t.context:void 0);try{for(var c=o(e),u=c.next();!u.done;u=c.next()){var h=a(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=c.return)&&i.call(c)}finally{if(r)throw r.error}}return n(s)},t.matchesState=A,t.send=pe,t.sendParent=ye,t.sendUpdate=ge,t.spawn=function(t,e){var n=function(t){return G(t)?r(r({},ie),{name:t}):r(r(r({},ie),{name:Y()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):Vt(t,n.name)}(Pt[Pt.length-1])},t.spawnBehavior=ne,t.t=de,t.toActorRef=Lt,t.toEventObject=Z,t.toObserver=it,t.toSCXMLEvent=tt,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/xstate.web.js
CHANGED
|
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
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
|
-
***************************************************************************** */function Et(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const kt=t=>"atomic"===t.type||"final"===t.type;function Tt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){const e=[t];return kt(t)?e:e.concat(P(Tt(t).map(Nt)))}function $t(t,e){const i=Pt(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=Pt(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Tt(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function Pt(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function Ct(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(kt(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,Pt($t([t],e)))}function It(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Vt(t,e){return"compound"===e.type?Tt(e).some(e=>"final"===e.type&&It(t,e)):"parallel"===e.type&&Tt(e).every(e=>Vt(t,e))}function At(t){return new Set(P(t.map(t=>t.tags)))}function Lt(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Dt{constructor(t){var e;this.actions=[],this.activities=O,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(P([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Dt)return t.context!==e?new Dt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Dt({value:t,context:e,_event:Z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Dt(t)}static inert(t,e){if(t instanceof Dt){if(!t.actions.length)return t;const i=Z;return new Dt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Dt.from(t,e)}toStrings(t=this.value,e="."){if(F(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=Et(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return w(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const zt=new Map;let Ft=0;const Ut={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Bt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Bt())return;const e=function(){const t=Bt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=_t({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=W(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Xt={sync:!1,autoForward:!1};var Ht;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ht||(Ht={}));class Gt{constructor(t,i=Gt.defaultOptions){this.machine=t,this.scheduler=new Mt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Ht.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(M(t))return this.batch(t),this.state;const i=H(X(t,e));if(this.status===Ht.Stopped)return this.state;if(this.status!==Ht.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,i)=>{const n=this.parent&&(i===e.Parent||this.parent.id===i),s=n?this.parent:F(i)?this.children.get(i)||Ut.get(i):(o=i)&&"function"==typeof o.send?i:void 0;var o;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===v?""+mt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!n)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)};const n=Object.assign(Object.assign({},Gt.defaultOptions),i),{clock:s,logger:o,parent:r,id:a}=n,c=void 0!==a?a:t.id;this.id=c,this.logger=o,this.clock=s,this.parent=r,this.options=n,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Ut.bookId()}get initialState(){return this._initialState?this._initialState:wt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=Vt(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?V(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(yt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Ht.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Ht.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Ht.Running)return this;Ut.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:wt(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Dt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Z)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;[...this.state.configuration].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{z(t.stop)&&t.stop()});for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Ht.Stopped,Ut.free(this.sessionId),this}batch(t){if(this.status===Ht.NotStarted&&this.options.deferEvents);else if(this.status!==Ht.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=H(s);this.forward(t),e=wt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Lt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,H(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=H(t);if(0===e.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw e.data.data;return wt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(e,s,a=this.machine.options.actions){const{context:c,_event:h}=s,u=e.exec||tt(e.type,a),l=z(u)?u:u?u.exec:e.exec;if(l)try{return l(c,h.data,{action:e,state:this.state,_event:h})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const s=e;if("number"==typeof s.delay)return void this.defer(s);s.to?this.sendTo(s._event,s.to):this.send(s._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Ht.Running)return;const i=e.activity;if(!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=Q(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:s}=i,o="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const r=s?V(s,c,h):void 0;if("string"==typeof e)return;let a,u=z(e)?e(c,h.data,{data:r,src:t,meta:i.meta}):e;if(!u)return;J(u)&&(u=r?u.withContext(r):u,a={autoForward:o}),this.spawn(u,n,a)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case d:const{label:a,value:u}=e;a?this.logger(a,u):this.logger(u)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),z(e.stop)&&e.stop())}spawn(t,e,i){if(A(t))return this.spawnPromise(Promise.resolve(t),e);if(z(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&z(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(J(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Gt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Xt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(H(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(H(yt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=mt(e,t);try{this.send(H(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=W(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(H(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(mt(e,t))}if(A(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=W(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,z(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(H(t,{origin:e}))},t=>{this.removeChild(e),this.send(H(mt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(H(yt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Bt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Jt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Ht.NotStarted?this.initialState:this._state}}Gt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Gt.interpret=Qt;function Kt(t,e){const i=(t=>F(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:q()}),t))(e);return(e=>e?e.spawn(t,i.name,i):jt(t,i.name))(Ot[Ot.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Yt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=Et(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Wt(t.src)})}})}const Zt={},te=t=>"#"===t[0];class ee{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ee(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Zt;let o=0;!function t(e){e.order=o++;for(const i of Tt(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=I(this.config.entry||this.config.onEntry).map(t=>et(t)),this.onExit=I(this.config.exit||this.config.onExit).map(t=>et(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=I(this.config.invoke).map((t,e)=>{if(J(t)){const i=Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(F(t.src)){const i=t.id||Y(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(J(t.src)||z(t.src)){const i=t.id||Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Yt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Yt(Object.assign(Object.assign({id:Y(this.id,e)},t),{src:i}))}}),this.activities=I(this.config.activities).concat(this.invoke).map(t=>nt(t)),this.transition=this.transition.bind(this),this.tags=I(this.config.tags)}_init(){this.__cache.transitions||Nt(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ee(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ee(this.config,this.options,t)}get context(){return z(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:k(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=gt(z(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(rt(i,{delay:t})),this.onExit.push(dt(i)),i};return(M(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):P(Object.keys(t).map((i,n)=>{const s=t[i],o=F(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return I(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const e=t instanceof Dt?t.value:_(t,this.delimiter);if(F(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...P(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=x(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from($t([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Vt(i,this),tags:At(i)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=P(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=P(s.map(t=>t.entrySet)),a=P(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,entrySet:r,exitSet:P(s.map(t=>t.exitSet)),configuration:a,source:e,actions:P(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return F(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,H(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,u=!c||(F(c)&&te(c)?t.matches(_(this.getStateNodeById(c).path,this.delimiter)):w(_(c,this.delimiter),N(this.path.slice(0,-2))(t.value)));let d=!1;try{d=!a||K(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(d&&u){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=P(o.map(e=>this.getRelativeStateNodes(e,t.historyValue))),a=!!s.internal;return{transitions:[s],entrySet:a?[]:P(r.map(t=>this.nodesFromChild(t))),exitSet:a?[]:[this],configuration:r,source:t,actions:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=$t([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?$t(s,t.configuration):s;for(const e of o)It(s,e)||t.entrySet.push(e);for(const e of s)It(o,e)&&!It(t.exitSet,e.parent)||t.exitSet.push(e);const r=P(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(vt(n.id,n.doneData),vt(o.id,n.doneData?V(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&Tt(r).every(e=>Vt(t.configuration,e))&&s.push(vt(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,u]=[P(Array.from(a).map(t=>[...t.activities.map(t=>lt(t)),...t.onEntry])).concat(r.map(st)),P(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>ft(t))]))];return it(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=H(e);let s;if(t instanceof Dt)s=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=F(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const r=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},a=$t([],this.getStateNodes(s.value)),c=r.configuration.length?$t(a,r.configuration):a;return r.configuration=[...c],this.resolveTransition(r,s,s.context,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,r,c,h=Z){const{configuration:u}=t,d=!r||t.transitions.length>0,l=d?Ct(this.machine,u):void 0,p=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,g=this.getActions(t,c,h,r),v=r?Object.assign({},r.activities):{};for(const t of g)t.type===i?v[t.activity.id||t.activity.type]=t:t.type===n&&(v[t.activity.id||t.activity.type]=!1);const[m,b]=bt(this,r,c,h,g,this.machine.config.preserveActionOrder),[S,O]=L(m,t=>t.type===s||t.type===o&&t.to===e.Internal),w=m.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=Q(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?V(t.data,i,n):void 0,c=r?jt(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,b,h),t),r?Object.assign({},r.children):{}),x=d?t.configuration:r?r.configuration:[],j=Vt(x,this),_=new Dt({value:l||r.value,context:b,_event:h,_sessionid:r?r._sessionid:null,historyValue:l?p?(E=p,k=l,{current:k,states:D(E,k)}):void 0:r?r.historyValue:void 0,history:!l||t.source?r:void 0,actions:l?O:[],activities:l?v:r?r.activities:{},events:[],configuration:x,transitions:t.transitions,children:w,done:j,tags:null==r?void 0:r.tags,machine:this});var E,k;const T=c!==b;_.changed=h.name===y||T;const{history:N}=_;N&&delete N.history;const $=!j&&(this._transient||u.some(t=>t._transient));if(!(d||$&&""!==h.name))return _;let P=_;if(!j)for($&&(P=this.resolveRaisedTransition(P,{type:a},h));S.length;){const t=S.shift();P=this.resolveRaisedTransition(P,t._event,h)}const C=P.changed||(N?!!P.actions.length||T||typeof N.value!=typeof P.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(F(e)||F(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(P.value,N.value):void 0);return P.changed=C,P.history=N,P.tags=At(P.configuration),P}getStateNode(t){if(te(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=te(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&te(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=j(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Zt;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Zt);case"compound":if(F(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):Zt):this.initialStateValue||{};default:return t||Zt}}getResolvedPath(t){if(te(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return j(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=T(this.states,t=>t.initialStateValue||Zt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=kt(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=F(e.target)&&te(e.target)?E(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(kt(this))return[this];if("compound"===this.type&&!this.initial)return[this];return P($(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:T(this.states,(e,i)=>{if(!t)return e.historyValue();const n=F(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?P($(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return F(i)?[e.getStateNode(i)]:P($(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=P(Object.keys(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const n=t[i];if(n.states)for(const t of n.events)e.add(""+t)}return this.__cache.events=Array.from(e)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!F(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return I(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>F(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:it(I(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=Et(e,[i+""]);t=P(Object.keys(o).map(t=>G(t,o[t])).concat(G("*",s)))}else t=[];const e=this.config.always?G("",this.config.always):[],i=this.config.onDone?G(String(vt(this.id)),this.config.onDone):[],n=P(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...G(String(yt(t.id)),t.onDone)),t.onError&&e.push(...G(String(mt(t.id)),t.onError)),e})),s=this.after,o=P([...i,...n,...t,...e].map(t=>I(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ie(t,e,i=t.context){return new ee(t,e,i)}function ne(t,e){return new ee(t,e)}function se(t,e){let i;for(const n of Object.keys(t))w(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function oe(t,e,i){const n=Dt.from(t,t instanceof Dt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function re(t){return t}const ae=re,{assign:ce,send:he,sendParent:ue,sendUpdate:de,forwardTo:le,doneInvoke:fe}=St;export{t as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,St as actions,ce as assign,ne as createMachine,re as createSchema,fe as doneInvoke,le as forwardTo,Qt as interpret,se as mapState,oe as matchState,w as matchesState,he as send,ue as sendParent,de as sendUpdate,Kt as spawn,qt as spawnBehavior,ae as t,_t as toActorRef,X as toEventObject,W as toObserver,H as toSCXMLEvent};
|
|
15
|
+
***************************************************************************** */function Et(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const kt=t=>"atomic"===t.type||"final"===t.type;function Tt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){const e=[t];return kt(t)?e:e.concat(P(Tt(t).map(Nt)))}function $t(t,e){const i=Pt(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=Pt(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Tt(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function Pt(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function Ct(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(kt(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,Pt($t([t],e)))}function It(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Vt(t,e){return"compound"===e.type?Tt(e).some(e=>"final"===e.type&&It(t,e)):"parallel"===e.type&&Tt(e).every(e=>Vt(t,e))}function At(t){return new Set(P(t.map(t=>t.tags)))}function Lt(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Dt{constructor(t){var e;this.actions=[],this.activities=O,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(P([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Dt)return t.context!==e?new Dt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Dt({value:t,context:e,_event:Z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Dt(t)}static inert(t,e){if(t instanceof Dt){if(!t.actions.length)return t;const i=Z;return new Dt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Dt.from(t,e)}toStrings(t=this.value,e="."){if(F(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=Et(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return w(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const zt=new Map;let Ft=0;const Ut={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Bt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Bt())return;const e=function(){const t=Bt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=_t({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=W(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Xt={sync:!1,autoForward:!1};var Ht;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ht||(Ht={}));class Gt{constructor(t,i=Gt.defaultOptions){this.machine=t,this.scheduler=new Mt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Ht.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(M(t))return this.batch(t),this.state;const i=H(X(t,e));if(this.status===Ht.Stopped)return this.state;if(this.status!==Ht.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,i)=>{const n=this.parent&&(i===e.Parent||this.parent.id===i),s=n?this.parent:F(i)?this.children.get(i)||Ut.get(i):(o=i)&&"function"==typeof o.send?i:void 0;var o;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===v?""+mt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!n)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)};const n=Object.assign(Object.assign({},Gt.defaultOptions),i),{clock:s,logger:o,parent:r,id:a}=n,c=void 0!==a?a:t.id;this.id=c,this.logger=o,this.clock=s,this.parent=r,this.options=n,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Ut.bookId()}get initialState(){return this._initialState?this._initialState:wt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=Vt(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?V(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(yt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Ht.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Ht.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Ht.Running)return this;this.machine._init(),Ut.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:wt(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Dt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Z)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;[...this.state.configuration].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{z(t.stop)&&t.stop()});for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Ht.Stopped,Ut.free(this.sessionId),this}batch(t){if(this.status===Ht.NotStarted&&this.options.deferEvents);else if(this.status!==Ht.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=H(s);this.forward(t),e=wt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Lt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,H(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=H(t);if(0===e.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw e.data.data;return wt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(e,s,a=this.machine.options.actions){const{context:c,_event:h}=s,u=e.exec||tt(e.type,a),l=z(u)?u:u?u.exec:e.exec;if(l)try{return l(c,h.data,{action:e,state:this.state,_event:h})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const s=e;if("number"==typeof s.delay)return void this.defer(s);s.to?this.sendTo(s._event,s.to):this.send(s._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Ht.Running)return;const i=e.activity;if(!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=Q(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:s}=i,o="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const r=s?V(s,c,h):void 0;if("string"==typeof e)return;let a,u=z(e)?e(c,h.data,{data:r,src:t,meta:i.meta}):e;if(!u)return;J(u)&&(u=r?u.withContext(r):u,a={autoForward:o}),this.spawn(u,n,a)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case d:const{label:a,value:u}=e;a?this.logger(a,u):this.logger(u)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),z(e.stop)&&e.stop())}spawn(t,e,i){if(A(t))return this.spawnPromise(Promise.resolve(t),e);if(z(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&z(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(J(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Gt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Xt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(H(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(H(yt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=mt(e,t);try{this.send(H(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=W(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(H(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(mt(e,t))}if(A(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=W(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,z(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(H(t,{origin:e}))},t=>{this.removeChild(e),this.send(H(mt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(H(yt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Bt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Jt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Ht.NotStarted?this.initialState:this._state}}Gt.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1},Gt.interpret=Qt;function Kt(t,e){const i=(t=>F(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:q()}),t))(e);return(e=>e?e.spawn(t,i.name,i):jt(t,i.name))(Ot[Ot.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Yt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=Et(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Wt(t.src)})}})}const Zt={},te=t=>"#"===t[0];class ee{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;this.config=t,this._context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ee(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Zt;let o=0;!function t(e){e.order=o++;for(const i of Tt(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=I(this.config.entry||this.config.onEntry).map(t=>et(t)),this.onExit=I(this.config.exit||this.config.onExit).map(t=>et(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=I(this.config.invoke).map((t,e)=>{if(J(t)){const i=Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(F(t.src)){const i=t.id||Y(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(J(t.src)||z(t.src)){const i=t.id||Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Yt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Yt(Object.assign(Object.assign({id:Y(this.id,e)},t),{src:i}))}}),this.activities=I(this.config.activities).concat(this.invoke).map(t=>nt(t)),this.transition=this.transition.bind(this),this.tags=I(this.config.tags)}_init(){this.__cache.transitions||Nt(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ee(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ee(this.config,this.options,t)}get context(){return z(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:k(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=gt(z(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(rt(i,{delay:t})),this.onExit.push(dt(i)),i};return(M(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):P(Object.keys(t).map((i,n)=>{const s=t[i],o=F(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return I(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const e=t instanceof Dt?t.value:_(t,this.delimiter);if(F(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...P(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=x(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from($t([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Vt(i,this),tags:At(i),machine:this.machine}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=P(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=P(s.map(t=>t.entrySet)),a=P(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,entrySet:r,exitSet:P(s.map(t=>t.exitSet)),configuration:a,source:e,actions:P(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return F(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,H(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,u=!c||(F(c)&&te(c)?t.matches(_(this.getStateNodeById(c).path,this.delimiter)):w(_(c,this.delimiter),N(this.path.slice(0,-2))(t.value)));let d=!1;try{d=!a||K(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(d&&u){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=P(o.map(e=>this.getRelativeStateNodes(e,t.historyValue))),a=!!s.internal;return{transitions:[s],entrySet:a?[]:P(r.map(t=>this.nodesFromChild(t))),exitSet:a?[]:[this],configuration:r,source:t,actions:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=$t([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?$t(s,t.configuration):s;for(const e of o)It(s,e)||t.entrySet.push(e);for(const e of s)It(o,e)&&!It(t.exitSet,e.parent)||t.exitSet.push(e);const r=P(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(vt(n.id,n.doneData),vt(o.id,n.doneData?V(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&Tt(r).every(e=>Vt(t.configuration,e))&&s.push(vt(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,u]=[P(Array.from(a).map(t=>[...t.activities.map(t=>lt(t)),...t.onEntry])).concat(r.map(st)),P(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>ft(t))]))];return it(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=H(e);let s;if(t instanceof Dt)s=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=F(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const r=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},a=$t([],this.getStateNodes(s.value)),c=r.configuration.length?$t(a,r.configuration):a;return r.configuration=[...c],this.resolveTransition(r,s,s.context,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,r,c,h=Z){const{configuration:u}=t,d=!r||t.transitions.length>0,l=d?Ct(this.machine,u):void 0,p=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,g=this.getActions(t,c,h,r),v=r?Object.assign({},r.activities):{};for(const t of g)t.type===i?v[t.activity.id||t.activity.type]=t:t.type===n&&(v[t.activity.id||t.activity.type]=!1);const[m,b]=bt(this,r,c,h,g,this.machine.config.preserveActionOrder),[S,O]=L(m,t=>t.type===s||t.type===o&&t.to===e.Internal),w=m.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=Q(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?V(t.data,i,n):void 0,c=r?jt(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,b,h),t),r?Object.assign({},r.children):{}),x=d?t.configuration:r?r.configuration:[],j=Vt(x,this),_=new Dt({value:l||r.value,context:b,_event:h,_sessionid:r?r._sessionid:null,historyValue:l?p?(E=p,k=l,{current:k,states:D(E,k)}):void 0:r?r.historyValue:void 0,history:!l||t.source?r:void 0,actions:l?O:[],activities:l?v:r?r.activities:{},events:[],configuration:x,transitions:t.transitions,children:w,done:j,tags:null==r?void 0:r.tags,machine:this});var E,k;const T=c!==b;_.changed=h.name===y||T;const{history:N}=_;N&&delete N.history;const $=!j&&(this._transient||u.some(t=>t._transient));if(!(d||$&&""!==h.name))return _;let P=_;if(!j)for($&&(P=this.resolveRaisedTransition(P,{type:a},h));S.length;){const t=S.shift();P=this.resolveRaisedTransition(P,t._event,h)}const C=P.changed||(N?!!P.actions.length||T||typeof N.value!=typeof P.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(F(e)||F(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(P.value,N.value):void 0);return P.changed=C,P.history=N,P.tags=At(P.configuration),P}getStateNode(t){if(te(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=te(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&te(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=j(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Zt;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Zt);case"compound":if(F(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):Zt):this.initialStateValue||{};default:return t||Zt}}getResolvedPath(t){if(te(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return j(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=T(this.states,t=>t.initialStateValue||Zt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=kt(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=F(e.target)&&te(e.target)?E(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(kt(this))return[this];if("compound"===this.type&&!this.initial)return[this];return P($(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:T(this.states,(e,i)=>{if(!t)return e.historyValue();const n=F(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?P($(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return F(i)?[e.getStateNode(i)]:P($(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=P(Object.keys(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,e=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const n=t[i];if(n.states)for(const t of n.events)e.add(""+t)}return this.__cache.events=Array.from(e)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!F(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return I(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>F(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:it(I(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=Et(e,[i+""]);t=P(Object.keys(o).map(t=>G(t,o[t])).concat(G("*",s)))}else t=[];const e=this.config.always?G("",this.config.always):[],i=this.config.onDone?G(String(vt(this.id)),this.config.onDone):[],n=P(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...G(String(yt(t.id)),t.onDone)),t.onError&&e.push(...G(String(mt(t.id)),t.onError)),e})),s=this.after,o=P([...i,...n,...t,...e].map(t=>I(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ie(t,e,i=t.context){return new ee(t,e,i)}function ne(t,e){return new ee(t,e)}function se(t,e){let i;for(const n of Object.keys(t))w(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function oe(t,e,i){const n=Dt.from(t,t instanceof Dt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function re(t){return t}const ae=re,{assign:ce,send:he,sendParent:ue,sendUpdate:de,forwardTo:le,doneInvoke:fe}=St;export{t as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,St as actions,ce as assign,ne as createMachine,re as createSchema,fe as doneInvoke,le as forwardTo,Qt as interpret,se as mapState,oe as matchState,w as matchesState,he as send,ue as sendParent,de as sendUpdate,Kt as spawn,qt as spawnBehavior,ae as t,_t as toActorRef,X as toEventObject,W as toObserver,H as toSCXMLEvent};
|
package/es/StateNode.js
CHANGED
|
@@ -443,7 +443,8 @@ function () {
|
|
|
443
443
|
value: this.resolve(stateFromConfig.value),
|
|
444
444
|
configuration: configuration,
|
|
445
445
|
done: isInFinalState(configuration, this),
|
|
446
|
-
tags: getTagsFromConfiguration(configuration)
|
|
446
|
+
tags: getTagsFromConfiguration(configuration),
|
|
447
|
+
machine: this.machine
|
|
447
448
|
}));
|
|
448
449
|
};
|
|
449
450
|
|
package/es/devTools.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { IS_PRODUCTION } from './environment.js';
|
|
2
|
+
|
|
2
3
|
function getGlobal() {
|
|
3
4
|
if (typeof globalThis !== 'undefined') {
|
|
4
5
|
return globalThis;
|
|
@@ -16,7 +17,9 @@ function getGlobal() {
|
|
|
16
17
|
return global;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
if (!IS_PRODUCTION) {
|
|
21
|
+
console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
function getDevTools() {
|
package/es/interpreter.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export declare enum InterpreterStatus {
|
|
|
23
23
|
Running = 1,
|
|
24
24
|
Stopped = 2
|
|
25
25
|
}
|
|
26
|
-
/** @ts-ignore [symbolObservable] creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
|
|
27
26
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
28
27
|
value: any;
|
|
29
28
|
context: TContext;
|
|
@@ -190,8 +189,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
190
189
|
toJSON(): {
|
|
191
190
|
id: string;
|
|
192
191
|
};
|
|
193
|
-
|
|
194
|
-
[symbolObservable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
192
|
+
[Symbol.observable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
195
193
|
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
196
194
|
}
|
|
197
195
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
package/es/interpreter.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Scheduler } from './scheduler.js';
|
|
|
9
9
|
import { isSpawnedActor, createDeferredActor } from './Actor.js';
|
|
10
10
|
import { isInFinalState } from './stateUtils.js';
|
|
11
11
|
import { registry } from './registry.js';
|
|
12
|
-
import {
|
|
12
|
+
import { getGlobal, registerService } from './devTools.js';
|
|
13
13
|
import { provide, consume } from './serviceScope.js';
|
|
14
14
|
import { spawnBehavior } from './behaviors.js';
|
|
15
15
|
|
|
@@ -24,8 +24,6 @@ var InterpreterStatus;
|
|
|
24
24
|
InterpreterStatus[InterpreterStatus["Running"] = 1] = "Running";
|
|
25
25
|
InterpreterStatus[InterpreterStatus["Stopped"] = 2] = "Stopped";
|
|
26
26
|
})(InterpreterStatus || (InterpreterStatus = {}));
|
|
27
|
-
/** @ts-ignore [symbolObservable] creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
|
|
28
|
-
|
|
29
27
|
|
|
30
28
|
var Interpreter =
|
|
31
29
|
/*#__PURE__*/
|
|
@@ -455,7 +453,13 @@ function () {
|
|
|
455
453
|
if (this.status === InterpreterStatus.Running) {
|
|
456
454
|
// Do not restart the service if it is already started
|
|
457
455
|
return this;
|
|
458
|
-
}
|
|
456
|
+
} // yes, it's a hack but we need the related cache to be populated for some things to work (like delayed transitions)
|
|
457
|
+
// this is usually called by `machine.getInitialState` but if we rehydrate from a state we might bypass this call
|
|
458
|
+
// we also don't want to call this method here as it resolves the full initial state which might involve calling assign actions
|
|
459
|
+
// and that could potentially lead to some unwanted side-effects (even such as creating some rogue actors)
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
this.machine._init();
|
|
459
463
|
|
|
460
464
|
registry.register(this.sessionId, this);
|
|
461
465
|
this.initialized = true;
|
|
@@ -1310,8 +1314,6 @@ function () {
|
|
|
1310
1314
|
id: this.id
|
|
1311
1315
|
};
|
|
1312
1316
|
};
|
|
1313
|
-
/** @ts-ignore this creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
|
|
1314
|
-
|
|
1315
1317
|
|
|
1316
1318
|
Interpreter.prototype[symbolObservable] = function () {
|
|
1317
1319
|
return this;
|
|
@@ -1332,23 +1334,20 @@ function () {
|
|
|
1332
1334
|
*/
|
|
1333
1335
|
|
|
1334
1336
|
|
|
1335
|
-
Interpreter.defaultOptions =
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
setTimeout
|
|
1341
|
-
return setTimeout(fn, ms);
|
|
1342
|
-
},
|
|
1343
|
-
clearTimeout: function (id) {
|
|
1344
|
-
return clearTimeout(id);
|
|
1345
|
-
}
|
|
1337
|
+
Interpreter.defaultOptions = {
|
|
1338
|
+
execute: true,
|
|
1339
|
+
deferEvents: true,
|
|
1340
|
+
clock: {
|
|
1341
|
+
setTimeout: function (fn, ms) {
|
|
1342
|
+
return setTimeout(fn, ms);
|
|
1346
1343
|
},
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1344
|
+
clearTimeout: function (id) {
|
|
1345
|
+
return clearTimeout(id);
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
logger: /*#__PURE__*/console.log.bind(console),
|
|
1349
|
+
devTools: false
|
|
1350
|
+
};
|
|
1352
1351
|
Interpreter.interpret = interpret;
|
|
1353
1352
|
return Interpreter;
|
|
1354
1353
|
}();
|
package/es/types.d.ts
CHANGED
|
@@ -526,7 +526,7 @@ export declare type InternalMachineOptions<TContext, TEvent extends EventObject,
|
|
|
526
526
|
activities?: Record<string, ActivityConfig<TContext, TEvent>>;
|
|
527
527
|
};
|
|
528
528
|
export declare type MachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
|
|
529
|
-
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta = TypegenDisabled> extends StateNodeConfig<NoInfer<TContext>, TStateSchema, TEvent
|
|
529
|
+
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta = TypegenDisabled> extends StateNodeConfig<NoInfer<TContext>, TStateSchema, NoInfer<TEvent>, TAction> {
|
|
530
530
|
/**
|
|
531
531
|
* The initial context (extended state)
|
|
532
532
|
*/
|
|
@@ -572,7 +572,7 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
|
|
|
572
572
|
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
|
|
573
573
|
value: any;
|
|
574
574
|
context: TContext;
|
|
575
|
-
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, TEvent
|
|
575
|
+
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TServiceMap>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta> {
|
|
576
576
|
id: string;
|
|
577
577
|
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
|
|
578
578
|
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
|
|
@@ -1011,9 +1011,9 @@ export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventOb
|
|
|
1011
1011
|
*/
|
|
1012
1012
|
state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>;
|
|
1013
1013
|
};
|
|
1014
|
-
export declare type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, TResolvedTypesMeta
|
|
1014
|
+
export declare type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, MarkAllImplementationsAsProvided<TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRef<never, U> : R extends Behavior<infer TEvent, infer TEmitted> ? ActorRef<TEvent, TEmitted> : never : never;
|
|
1015
1015
|
export declare type AnyInterpreter = Interpreter<any, any, any, any, any>;
|
|
1016
|
-
export declare type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate,
|
|
1016
|
+
export declare type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, MarkAllImplementationsAsProvided<TResolvedTypesMeta>> : never;
|
|
1017
1017
|
export declare type MachineOptionsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, any, infer TEvent, any, any, any, infer TResolvedTypesMeta> ? InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
1018
1018
|
export declare type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
1019
1019
|
export interface ActorContext<TEvent extends EventObject, TEmitted> {
|
package/lib/StateNode.js
CHANGED
|
@@ -447,7 +447,8 @@ function () {
|
|
|
447
447
|
value: this.resolve(stateFromConfig.value),
|
|
448
448
|
configuration: configuration,
|
|
449
449
|
done: stateUtils.isInFinalState(configuration, this),
|
|
450
|
-
tags: stateUtils.getTagsFromConfiguration(configuration)
|
|
450
|
+
tags: stateUtils.getTagsFromConfiguration(configuration),
|
|
451
|
+
machine: this.machine
|
|
451
452
|
}));
|
|
452
453
|
};
|
|
453
454
|
|
package/lib/devTools.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var environment = require('./environment.js');
|
|
6
|
+
|
|
6
7
|
function getGlobal() {
|
|
7
8
|
if (typeof globalThis !== 'undefined') {
|
|
8
9
|
return globalThis;
|
|
@@ -20,7 +21,9 @@ function getGlobal() {
|
|
|
20
21
|
return global;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
if (!environment.IS_PRODUCTION) {
|
|
25
|
+
console.warn('XState could not find a global object in this environment. Please let the maintainers know and raise an issue here: https://github.com/statelyai/xstate/issues');
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
function getDevTools() {
|
package/lib/interpreter.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export declare enum InterpreterStatus {
|
|
|
23
23
|
Running = 1,
|
|
24
24
|
Stopped = 2
|
|
25
25
|
}
|
|
26
|
-
/** @ts-ignore [symbolObservable] creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
|
|
27
26
|
export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
|
|
28
27
|
value: any;
|
|
29
28
|
context: TContext;
|
|
@@ -190,8 +189,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
|
|
|
190
189
|
toJSON(): {
|
|
191
190
|
id: string;
|
|
192
191
|
};
|
|
193
|
-
|
|
194
|
-
[symbolObservable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
192
|
+
[Symbol.observable](): InteropSubscribable<State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>>;
|
|
195
193
|
getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
|
|
196
194
|
}
|
|
197
195
|
export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
|
package/lib/interpreter.js
CHANGED
|
@@ -28,8 +28,6 @@ exports.InterpreterStatus = void 0;
|
|
|
28
28
|
InterpreterStatus[InterpreterStatus["Running"] = 1] = "Running";
|
|
29
29
|
InterpreterStatus[InterpreterStatus["Stopped"] = 2] = "Stopped";
|
|
30
30
|
})(exports.InterpreterStatus || (exports.InterpreterStatus = {}));
|
|
31
|
-
/** @ts-ignore [symbolObservable] creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
|
|
32
|
-
|
|
33
31
|
|
|
34
32
|
var Interpreter =
|
|
35
33
|
/*#__PURE__*/
|
|
@@ -459,7 +457,13 @@ function () {
|
|
|
459
457
|
if (this.status === exports.InterpreterStatus.Running) {
|
|
460
458
|
// Do not restart the service if it is already started
|
|
461
459
|
return this;
|
|
462
|
-
}
|
|
460
|
+
} // yes, it's a hack but we need the related cache to be populated for some things to work (like delayed transitions)
|
|
461
|
+
// this is usually called by `machine.getInitialState` but if we rehydrate from a state we might bypass this call
|
|
462
|
+
// we also don't want to call this method here as it resolves the full initial state which might involve calling assign actions
|
|
463
|
+
// and that could potentially lead to some unwanted side-effects (even such as creating some rogue actors)
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
this.machine._init();
|
|
463
467
|
|
|
464
468
|
registry.registry.register(this.sessionId, this);
|
|
465
469
|
this.initialized = true;
|
|
@@ -1314,8 +1318,6 @@ function () {
|
|
|
1314
1318
|
id: this.id
|
|
1315
1319
|
};
|
|
1316
1320
|
};
|
|
1317
|
-
/** @ts-ignore this creates problems for people without `skipLibCheck` who are on older versions of TS, remove this comment when we drop support for TS@<4.3 */
|
|
1318
|
-
|
|
1319
1321
|
|
|
1320
1322
|
Interpreter.prototype[utils.symbolObservable] = function () {
|
|
1321
1323
|
return this;
|
|
@@ -1336,23 +1338,20 @@ function () {
|
|
|
1336
1338
|
*/
|
|
1337
1339
|
|
|
1338
1340
|
|
|
1339
|
-
Interpreter.defaultOptions =
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
setTimeout
|
|
1345
|
-
return setTimeout(fn, ms);
|
|
1346
|
-
},
|
|
1347
|
-
clearTimeout: function (id) {
|
|
1348
|
-
return clearTimeout(id);
|
|
1349
|
-
}
|
|
1341
|
+
Interpreter.defaultOptions = {
|
|
1342
|
+
execute: true,
|
|
1343
|
+
deferEvents: true,
|
|
1344
|
+
clock: {
|
|
1345
|
+
setTimeout: function (fn, ms) {
|
|
1346
|
+
return setTimeout(fn, ms);
|
|
1350
1347
|
},
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1348
|
+
clearTimeout: function (id) {
|
|
1349
|
+
return clearTimeout(id);
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
logger: /*#__PURE__*/console.log.bind(console),
|
|
1353
|
+
devTools: false
|
|
1354
|
+
};
|
|
1356
1355
|
Interpreter.interpret = interpret;
|
|
1357
1356
|
return Interpreter;
|
|
1358
1357
|
}();
|
package/lib/types.d.ts
CHANGED
|
@@ -526,7 +526,7 @@ export declare type InternalMachineOptions<TContext, TEvent extends EventObject,
|
|
|
526
526
|
activities?: Record<string, ActivityConfig<TContext, TEvent>>;
|
|
527
527
|
};
|
|
528
528
|
export declare type MachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
|
|
529
|
-
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta = TypegenDisabled> extends StateNodeConfig<NoInfer<TContext>, TStateSchema, TEvent
|
|
529
|
+
export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TTypesMeta = TypegenDisabled> extends StateNodeConfig<NoInfer<TContext>, TStateSchema, NoInfer<TEvent>, TAction> {
|
|
530
530
|
/**
|
|
531
531
|
* The initial context (extended state)
|
|
532
532
|
*/
|
|
@@ -572,7 +572,7 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
|
|
|
572
572
|
export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
|
|
573
573
|
value: any;
|
|
574
574
|
context: TContext;
|
|
575
|
-
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, TEvent
|
|
575
|
+
}, TAction extends BaseActionObject = BaseActionObject, TServiceMap extends ServiceMap = ServiceMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TServiceMap>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta> {
|
|
576
576
|
id: string;
|
|
577
577
|
states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TServiceMap, TResolvedTypesMeta>['states'];
|
|
578
578
|
withConfig(options: InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, TServiceMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
|
|
@@ -1011,9 +1011,9 @@ export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventOb
|
|
|
1011
1011
|
*/
|
|
1012
1012
|
state: State<TContext, TEvent, any, TTypestate, TResolvedTypesMeta>;
|
|
1013
1013
|
};
|
|
1014
|
-
export declare type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, TResolvedTypesMeta
|
|
1014
|
+
export declare type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate, MarkAllImplementationsAsProvided<TResolvedTypesMeta>> : R extends Promise<infer U> ? ActorRef<never, U> : R extends Behavior<infer TEvent, infer TEmitted> ? ActorRef<TEvent, TEmitted> : never : never;
|
|
1015
1015
|
export declare type AnyInterpreter = Interpreter<any, any, any, any, any>;
|
|
1016
|
-
export declare type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate,
|
|
1016
|
+
export declare type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate, any, any, infer TResolvedTypesMeta> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate, MarkAllImplementationsAsProvided<TResolvedTypesMeta>> : never;
|
|
1017
1017
|
export declare type MachineOptionsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, any, infer TEvent, any, any, any, infer TResolvedTypesMeta> ? InternalMachineOptions<TContext, TEvent, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
1018
1018
|
export declare type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, any, any, any, any, any, infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
1019
1019
|
export interface ActorContext<TEvent extends EventObject, TEmitted> {
|