xstate 4.23.3 → 4.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,129 @@
1
1
  # xstate
2
2
 
3
+ ## 4.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2657](https://github.com/statelyai/xstate/pull/2657) [`72155c1b7`](https://github.com/statelyai/xstate/commit/72155c1b7887b94f2d8f7cb73a1af17a591cc74c) Thanks [@mattpocock](https://github.com/mattpocock)! - Removed the ability to pass a model as a generic to `createMachine`, in favour of `model.createMachine`. This lets us cut an overload from the definition of `createMachine`, meaning errors become more targeted and less cryptic.
8
+
9
+ This means that this approach is no longer supported:
10
+
11
+ ```ts
12
+ const model = createModel({});
13
+
14
+ const machine = createMachine<typeof model>();
15
+ ```
16
+
17
+ If you're using this approach, you should use `model.createMachine` instead:
18
+
19
+ ```ts
20
+ const model = createModel({});
21
+
22
+ const machine = model.createMachine();
23
+ ```
24
+
25
+ ### Patch Changes
26
+
27
+ - [#2659](https://github.com/statelyai/xstate/pull/2659) [`7bfeb930d`](https://github.com/statelyai/xstate/commit/7bfeb930d65eb4443c300a2d28aeef3664fcafea) Thanks [@Andarist](https://github.com/Andarist)! - Fixed a regression in the inline actions type inference in models without explicit action creators.
28
+
29
+ ```js
30
+ const model = createModel(
31
+ { foo: 100 },
32
+ {
33
+ events: {
34
+ BAR: () => ({})
35
+ }
36
+ }
37
+ );
38
+
39
+ model.createMachine({
40
+ // `ctx` was of type `any`
41
+ entry: ctx => {},
42
+ exit: assign({
43
+ // `ctx` was of type `unknown`
44
+ foo: ctx => 42
45
+ })
46
+ });
47
+ ```
48
+
49
+ ## 4.24.1
50
+
51
+ ### Patch Changes
52
+
53
+ - [#2649](https://github.com/statelyai/xstate/pull/2649) [`ad611007a`](https://github.com/statelyai/xstate/commit/ad611007a9111e8aefe9d22049ac99072588db9f) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with functions used as inline actions not always receiving the correct arguments when used with `preserveActionOrder`.
54
+
55
+ ## 4.24.0
56
+
57
+ ### Minor Changes
58
+
59
+ - [#2546](https://github.com/statelyai/xstate/pull/2546) [`a4cfce18c`](https://github.com/statelyai/xstate/commit/a4cfce18c0c179faef15adf25a75b08903064e28) Thanks [@davidkpiano](https://github.com/davidkpiano)! - You can now know if an event will cause a state change by using the new `state.can(event)` method, which will return `true` if an interpreted machine will "change" the state when sent the `event`, or `false` otherwise:
60
+
61
+ ```js
62
+ const machine = createMachine({
63
+ initial: 'inactive',
64
+ states: {
65
+ inactive: {
66
+ on: {
67
+ TOGGLE: 'active'
68
+ }
69
+ },
70
+ active: {
71
+ on: {
72
+ DO_SOMETHING: { actions: ['something'] }
73
+ }
74
+ }
75
+ }
76
+ });
77
+
78
+ const state = machine.initialState;
79
+
80
+ state.can('TOGGLE'); // true
81
+ state.can('DO_SOMETHING'); // false
82
+
83
+ // Also takes in full event objects:
84
+ state.can({
85
+ type: 'DO_SOMETHING',
86
+ data: 42
87
+ }); // false
88
+ ```
89
+
90
+ A state is considered "changed" if any of the following are true:
91
+
92
+ - its `state.value` changes
93
+ - there are new `state.actions` to be executed
94
+ - its `state.context` changes
95
+
96
+ See [`state.changed` (documentation)](https://xstate.js.org/docs/guides/states.html#state-changed) for more details.
97
+
98
+ ### Patch Changes
99
+
100
+ - [#2632](https://github.com/statelyai/xstate/pull/2632) [`f8cf5dfe0`](https://github.com/statelyai/xstate/commit/f8cf5dfe0bf20c8545208ed7b1ade619933004f9) Thanks [@davidkpiano](https://github.com/davidkpiano)! - A regression was fixed where actions were being typed as `never` if events were specified in `createModel(...)` but not actions:
101
+
102
+ ```ts
103
+ const model = createModel(
104
+ {},
105
+ {
106
+ events: {}
107
+ }
108
+ );
109
+
110
+ model.createMachine({
111
+ // These actions will cause TS to not compile
112
+ entry: 'someAction',
113
+ exit: { type: 'someObjectAction' }
114
+ });
115
+ ```
116
+
117
+ ## 4.23.4
118
+
119
+ ### Patch Changes
120
+
121
+ - [#2606](https://github.com/statelyai/xstate/pull/2606) [`01e5d7984`](https://github.com/statelyai/xstate/commit/01e5d7984a5441a6980eacdb06d42c2a9398bdff) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The following utility types were previously returning `never` in some unexpected cases, and are now working as expected:
122
+
123
+ - `ContextFrom<T>`
124
+ - `EventFrom<T>`
125
+ - `EmittedFrom<T>`
126
+
3
127
  ## 4.23.3
4
128
 
5
129
  ### Patch Changes
package/README.md CHANGED
@@ -69,9 +69,9 @@ toggleService.send('TOGGLE');
69
69
 
70
70
  ## Visualizer
71
71
 
72
- **[Visualize, simulate, and share your statecharts in XState Viz!](https://xstate.js.org/viz)**
72
+ **[Visualize, simulate, and share your statecharts in XState Viz!](https://stately.ai/viz)**
73
73
 
74
- <a href="https://xstate.js.org/viz" title="xstate visualizer"><img src="https://i.imgur.com/3pEB0B3.png" alt="xstate visualizer" width="300" /></a>
74
+ <a href="https://stately.ai/viz" title="xstate visualizer"><img src="https://i.imgur.com/3pEB0B3.png" alt="xstate visualizer" width="300" /></a>
75
75
 
76
76
  ## Why?
77
77
 
@@ -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){for(var n=0,r=e.length,i=t.length;n<r;n++,i++)t[i]=e[n];return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a={};function u(t){return Object.keys(t)}function c(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:l(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return l(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+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 d(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function l(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}var y=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function g(t){try{return"__xstatenode"in t}catch(t){return!1}}var 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 u(t.states).map((function(e){return t.states[e]}))}function E(t){return s([],o(new Set((e=s([],o(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s([],o(e)))))));var e,n}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,I=(e.Raise,e.Send),L=e.Cancel,k=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),C=e.Init,P=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),j=e.ErrorCustom,N=e.Update,A=(e.Choose,e.Pure,x({type:C}));function D(t,n){var r=e.DoneInvoke+"."+t,i={type:r,data:n,toString:function(){return r}};return i}function M(t,n){var r=e.ErrorPlatform+"."+t,i={type:r,data:n,toString:function(){return r}};return i}var z=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=a,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,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=u(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}))})))))},t.prototype.toJSON=function(){this.configuration,this.transitions;var t=this.tags,e=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}(this,["configuration","transitions","tags"]);return r(r({},e),{tags:Array.from(t)})},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:u(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}(),R={deferEvents:!1},V=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=r(r({},R),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),J=[],q=function(t,e){J.push(t);var n=e(t);return J.pop(),n};var U=new Map,$=0,F=function(){return"x:"+$++},X=function(t,e){return U.set(t,e),t},B=function(t){return U.get(t)},G=function(t){U.delete(t)};function H(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function K(t){if(H()){var e=function(){var t=H();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Q(t,e){void 0===e&&(e={});var n,i=t.initialState,o=new Set,s=[],a=!1,u=(n={id:e.id,send:function(e){s.push(e),function(){if(!a){for(a=!0;s.length>0;){var e=s.shift();i=t.transition(i,e,c),o.forEach((function(t){return t.next(i)}))}a=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=w(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},r({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},n)),c={parent:e.parent,self:u,id:e.id||"anonymous",observers:o};return i=t.start?t.start(c):i,u}var W,Y={sync:!1,autoForward:!1};(W=t.InterpreterStatus||(t.InterpreterStatus={}))[W.NotStarted=0]="NotStarted",W[W.Running=1]="Running",W[W.Stopped=2]="Stopped";var Z=function(){function a(e,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(l(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 "'+r.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(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)||B(e):(i=e)&&"function"==typeof i.send?e:void 0;if(a)"machine"in a?a.send(r(r({},t),{name:t.name===j?""+M(o.id):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '"+e+"' from service '"+o.id+"'.")};var s=r(r({},a.defaultOptions),i),u=s.clock,c=s.logger,h=s.parent,f=s.id,d=void 0!==f?f:e.id;this.id=d,this.logger=c,this.clock=u,this.parent=h,this.options=s,this.scheduler=new V({deferEvents:this.options.deferEvents}),this.sessionId=F()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:q(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,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,d=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){d.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=i(this.eventListeners),p=l.next();!p.done;p=l.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var v=i(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var g=i(this.contextListeners),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===d.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;X(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:q(this,(function(){return!v(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(z.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,o,s,a,c,h,f,d,l=this;try{for(var v=i(this.listeners),y=v.next();!y.done;y=v.next()){var g=y.value;this.listeners.delete(g)}}catch(t){e={error:t}}finally{try{y&&!y.done&&(n=v.return)&&n.call(v)}finally{if(e)throw e.error}}try{for(var b=i(this.stopListeners),m=b.next();!m.done;m=b.next()){(g=m.value)(),this.stopListeners.delete(g)}}catch(t){r={error:t}}finally{try{m&&!m.done&&(o=b.return)&&o.call(b)}finally{if(r)throw r.error}}try{for(var x=i(this.contextListeners),w=x.next();!w.done;w=x.next()){g=w.value;this.contextListeners.delete(g)}}catch(t){s={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(s)throw s.error}}try{for(var S=i(this.doneListeners),E=S.next();!E.done;E=S.next()){g=E.value;this.doneListeners.delete(g)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var r=i(t.definition.exit),o=r.next();!o.done;o=r.next()){var s=o.value;l.exec(s,l.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 _=i(u(this.delayedEventsMap)),O=_.next();!O.done;O=_.next()){var T=O.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{O&&!O.done&&(d=_.return)&&d.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,G(this.sessionId),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error(e.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var 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}))))),c=c||!!u.changed};try{for(var d=i(e),l=d.next();!l.done;l=d.next()){f(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(a=d.return)&&a.call(d)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,n.update(u,x(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=x(t);if(0===n.name.indexOf(P)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(P)})))throw n.data.data;return q(this,(function(){return e.machine.transition(e.state,n)}))},a.prototype.forward=function(t){var e,n;try{for(var 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 '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+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(t,n,r){void 0===r&&(r=this.machine.options.actions);var i,o=n.context,s=n._event,a=t.exec||function(t,e){return e&&e[t]||void 0}(t.type,r),u=p(a)?a:a?a.exec:t.exec;if(u)try{return u(o,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case I:var c=t;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case L:this.cancel(t.sendId);break;case O:var h=t.activity;if(!this.state.activities[h.id||h.type])break;if(h.type===e.Invoke){var d="string"==typeof(i=h.src)?{type:i}:i,l=this.machine.options.services?this.machine.options.services[d.type]:void 0,v=h.id,y=h.data,b="autoForward"in h?h.autoForward:!!h.forward;if(!l)return;var m=y?f(y,o,s):void 0;if("string"==typeof l)return;var x=p(l)?l(o,s.data,{data:m,src:d}):l;if(!x)return;var w=void 0;g(x)&&(x=m?x.withContext(m):x,w={autoForward:b}),this.spawn(x,v,w)}else this.spawnActivity(h);break;case T:this.stopChild(t.activity.id);break;case k:var S=t.label,E=t.value;S?this.logger(S,E):this.logger(E)}},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(d(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 "'+e+'" of type "'+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({},Y),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=Q(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,r=this,i=!1;t.then((function(t){i||(n=t,r.removeChild(e),r.send(x(D(e,t),{origin:e})))}),(function(t){if(!i){r.removeChild(e);var n=M(e,t);try{r.send(x(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var o={id:e,send:function(){},subscribe:function(e,n,r){var i=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(){i=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,o),o},a.prototype.spawnCallback=function(t,e){var n,r,i=this,o=!1,s=new Set,a=new Set;try{r=t((function(t){n=t,a.forEach((function(e){return e(t)})),o||i.send(x(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(M(e,t))}if(d(r))return this.spawnPromise(r,e);var u={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){o=!0,p(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,u),u},a.prototype.spawnObservable=function(t,e){var n,r=this,i=t.subscribe((function(t){n=t,r.send(x(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(x(M(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(x(D(e),{origin:e}))})),o={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return i.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}};return this.children.set(e,o),o},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},a.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})},a.prototype.attachDev=function(){var t=H();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(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)}K(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[y]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),a.interpret=tt,a}();function tt(t,e){return new Z(t,e)}t.Interpreter=Z,t.interpret=tt,t.spawn=function(t,e){var n=function(t){return v(t)?r(r({},Y),{name:t}):r(r(r({},Y),{name:b()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):function(t,e,n){var r=function(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}}}(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}(t,n.name)}(J[J.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var e,n,i=function(){return(i=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)s.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return s}function s(t,e){for(var n=0,i=e.length,r=t.length;n<i;n++,r++)t[r]=e[n];return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a={};function u(t){return Object.keys(t)}function c(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:l(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return l(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}(t,e));var n}function h(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function f(t,e,n){var i,o;if(p(t))return t(e,n.data);var s={};try{for(var a=r(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];p(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function d(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function l(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}var y=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function g(t){try{return"__xstatenode"in t}catch(t){return!1}}var m=function(){var t=0;return function(){return(++t).toString(16)}}();function b(t,e){return v(t)||"number"==typeof t?i({type:t},e):t}function x(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=b(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function w(t,e,n){if("object"==typeof t)return t;var i=function(){};return{next:t,error:e||i,complete:n||i}}function S(t){return u(t.states).map((function(e){return t.states[e]}))}function E(t){return s([],o(new Set((e=s([],o(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s([],o(e)))))));var e,n}function _(t,e){return"compound"===e.type?S(e).some((function(e){return"final"===e.type&&(n=t,i=e,Array.isArray(n)?n.some((function(t){return t===i})):n instanceof Set&&n.has(i));var n,i})):"parallel"===e.type&&S(e).every((function(e){return _(t,e)}))}var O=e.Start,T=e.Stop,I=(e.Raise,e.Send),L=e.Cancel,k=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),C=e.Init,P=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),j=e.ErrorCustom,N=e.Update,A=(e.Choose,e.Pure,x({type:C}));function D(t,n){var i=e.DoneInvoke+"."+t,r={type:i,data:n,toString:function(){return i}};return r}function M(t,n){var i=e.ErrorPlatform+"."+t,r={type:i,data:n,toString:function(){return i}};return r}var z=function(){function t(t){var e,n,i=this;this.actions=[],this.activities=a,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return E(i.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:A,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=A;return new t({value:e.value,context:n,_event:i,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),v(t))return[t];var i=u(t);return i.concat.apply(i,s([],o(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))})))))},t.prototype.toJSON=function(){var t=this,e=(t.configuration,t.transitions,t.tags),n=(t.machine,function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(t,["configuration","transitions","tags","machine"]));return i(i({},n),{tags:Array.from(e)})},t.prototype.matches=function(t){return function t(e,n,i){void 0===i&&(i=".");var r=c(e,i),o=c(n,i);return v(o)?!!v(r)&&o===r:v(r)?r in o:u(r).every((function(e){return e in o&&t(r[e],o[e])}))}(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;return this.machine,!!(null===(e=this.machine)||void 0===e?void 0:e.transition(this,t).changed)},t}(),R={deferEvents:!1},V=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},R),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),J=[],q=function(t,e){J.push(t);var n=e(t);return J.pop(),n};var U=new Map,$=0,F=function(){return"x:"+$++},X=function(t,e){return U.set(t,e),t},B=function(t){return U.get(t)},G=function(t){U.delete(t)};function H(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function K(t){if(H()){var e=function(){var t=H();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Q(t,e){void 0===e&&(e={});var n,r=t.initialState,o=new Set,s=[],a=!1,u=(n={id:e.id,send:function(e){s.push(e),function(){if(!a){for(a=!0;s.length>0;){var e=s.shift();r=t.transition(r,e,c),o.forEach((function(t){return t.next(r)}))}a=!1}}()},getSnapshot:function(){return r},subscribe:function(t,e,n){var i=w(t,e,n);return o.add(i),i.next(r),{unsubscribe:function(){o.delete(i)}}}},i({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},n)),c={parent:e.parent,self:u,id:e.id||"anonymous",observers:o};return r=t.start?t.start(c):r,u}var W,Y={sync:!1,autoForward:!1};(W=t.InterpreterStatus||(t.InterpreterStatus={}))[W.NotStarted=0]="NotStarted",W[W.Running=1]="Running",W[W.Stopped=2]="Stopped";var Z=function(){function a(e,r){var o=this;void 0===r&&(r=a.defaultOptions),this.machine=e,this.scheduler=new V,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(l(e))return o.batch(e),o.state;var i=x(b(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+i.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(i.data));return o.scheduler.schedule((function(){o.forward(i);var t=o.nextState(i);o.update(t,i)})),o._state},this.sendTo=function(t,e){var r,s=o.parent&&(e===n.Parent||o.parent.id===e),a=s?o.parent:v(e)?o.children.get(e)||B(e):(r=e)&&"function"==typeof r.send?e:void 0;if(a)"machine"in a?a.send(i(i({},t),{name:t.name===j?""+M(o.id):t.name,origin:o.sessionId})):a.send(t.data);else if(!s)throw new Error("Unable to send event to child '"+e+"' from service '"+o.id+"'.")};var s=i(i({},a.defaultOptions),r),u=s.clock,c=s.logger,h=s.parent,f=s.id,d=void 0!==f?f:e.id;this.id=d,this.logger=c,this.clock=u,this.parent=h,this.options=s,this.scheduler=new V({deferEvents:this.options.deferEvents}),this.sessionId=F()}return Object.defineProperty(a.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:q(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),a.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),s=o.next();!s.done;s=o.next()){var a=s.value;this.exec(a,t,e)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},a.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,d=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){d.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),p=l.next();!p.done;p=l.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var g=r(this.contextListeners),m=g.next();!m.done;m=g.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(u=g.return)&&u.call(g)}finally{if(a)throw a.error}}var b=_(t.configuration||[],this.machine);if(this.state.configuration&&b){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===d.machine})),w=x&&x.doneData?f(x.doneData,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(D(this.id,w))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},a.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},a.prototype.subscribe=function(e,n,i){var r,o=this;if(!e)return{unsubscribe:function(){}};var s=i;return"function"==typeof e?r=e:(r=e.next.bind(e),s=e.complete.bind(e)),this.listeners.add(r),this.status===t.InterpreterStatus.Running&&r(this.state),s&&this.onDone(s),{unsubscribe:function(){r&&o.listeners.delete(r),s&&o.doneListeners.delete(s)}}},a.prototype.onEvent=function(t){return this.eventListeners.add(t),this},a.prototype.onSend=function(t){return this.sendListeners.add(t),this},a.prototype.onChange=function(t){return this.contextListeners.add(t),this},a.prototype.onStop=function(t){return this.stopListeners.add(t),this},a.prototype.onDone=function(t){return this.doneListeners.add(t),this},a.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},a.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;X(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:q(this,(function(){return!v(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(z.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,A)})),this},a.prototype.stop=function(){var e,n,i,o,s,a,c,h,f,d,l=this;try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){var g=y.value;this.listeners.delete(g)}}catch(t){e={error:t}}finally{try{y&&!y.done&&(n=v.return)&&n.call(v)}finally{if(e)throw e.error}}try{for(var m=r(this.stopListeners),b=m.next();!b.done;b=m.next()){(g=b.value)(),this.stopListeners.delete(g)}}catch(t){i={error:t}}finally{try{b&&!b.done&&(o=m.return)&&o.call(m)}finally{if(i)throw i.error}}try{for(var x=r(this.contextListeners),w=x.next();!w.done;w=x.next()){g=w.value;this.contextListeners.delete(g)}}catch(t){s={error:t}}finally{try{w&&!w.done&&(a=x.return)&&a.call(x)}finally{if(s)throw s.error}}try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){g=E.value;this.doneListeners.delete(g)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var s=o.value;l.exec(s,l.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){p(t.stop)&&t.stop()}));try{for(var _=r(u(this.delayedEventsMap)),O=_.next();!O.done;O=_.next()){var T=O.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{O&&!O.done&&(d=_.return)&&d.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,G(this.sessionId),this},a.prototype.batch=function(e){var n=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error(e.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var t,a,u=n.state,c=!1,h=[],f=function(t){var e=x(t);n.forward(e),u=q(n,(function(){return n.machine.transition(u,e)})),h.push.apply(h,s([],o(u.actions.map((function(t){return n=u,r=(e=t).exec,i(i({},e),{exec:void 0!==r?function(){return r(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,r}))))),c=c||!!u.changed};try{for(var d=r(e),l=d.next();!l.done;l=d.next()){f(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(a=d.return)&&a.call(d)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,n.update(u,x(e[e.length-1]))}))},a.prototype.sender=function(t){return this.send.bind(this,t)},a.prototype.nextState=function(t){var e=this,n=x(t);if(0===n.name.indexOf(P)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(P)})))throw n.data.data;return q(this,(function(){return e.machine.transition(e.state,n)}))},a.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var s=o.value,a=this.children.get(s);if(!a)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+s+"'.");a.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},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(t,n,i){void 0===i&&(i=this.machine.options.actions);var r,o=n.context,s=n._event,a=t.exec||function(t,e){return e&&e[t]||void 0}(t.type,i),u=p(a)?a:a?a.exec:t.exec;if(u)try{return u(o,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case I:var c=t;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case L:this.cancel(t.sendId);break;case O:var h=t.activity;if(!this.state.activities[h.id||h.type])break;if(h.type===e.Invoke){var d="string"==typeof(r=h.src)?{type:r}:r,l=this.machine.options.services?this.machine.options.services[d.type]:void 0,v=h.id,y=h.data,m="autoForward"in h?h.autoForward:!!h.forward;if(!l)return;var b=y?f(y,o,s):void 0;if("string"==typeof l)return;var x=p(l)?l(o,s.data,{data:b,src:d}):l;if(!x)return;var w=void 0;g(x)&&(x=b?x.withContext(b):x,w={autoForward:m}),this.spawn(x,v,w)}else this.spawnActivity(h);break;case T:this.stopChild(t.activity.id);break;case k:var S=t.label,E=t.value;S?this.logger(S,E):this.logger(E)}},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(d(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(g(t))return this.spawnMachine(t,i(i({},n),{id:e}));if(null!==(r=t)&&"object"==typeof r&&"transition"in r&&"function"==typeof r.transition)return this.spawnBehavior(t,e);throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".');var r,o},a.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var r=new a(t,i(i({},this.options),{parent:this,id:e.id||t.id})),o=i(i({},Y),e);o.sync&&r.onTransition((function(t){n.send(N,{state:t,id:r.id})}));var s=r;return this.children.set(r.id,s),o.autoForward&&this.forwardTo.add(r.id),r.onDone((function(t){n.removeChild(r.id),n.send(x(t,{origin:r.id}))})).start(),s},a.prototype.spawnBehavior=function(t,e){var n=Q(t,{id:e,parent:this});return this.children.set(e,n),n},a.prototype.spawnPromise=function(t,e){var n,i=this,r=!1;t.then((function(t){r||(n=t,i.removeChild(e),i.send(x(D(e,t),{origin:e})))}),(function(t){if(!r){i.removeChild(e);var n=M(e,t);try{i.send(x(n,{origin:e}))}catch(t){i.devTools&&i.devTools.send(n,i.state),i.machine.strict&&i.stop()}}}));var o={id:e,send:function(){},subscribe:function(e,n,i){var r=w(e,n,i),o=!1;return t.then((function(t){o||(r.next(t),o||r.complete())}),(function(t){o||r.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,o),o},a.prototype.spawnCallback=function(t,e){var n,i,r=this,o=!1,s=new Set,a=new Set;try{i=t((function(t){n=t,a.forEach((function(e){return e(t)})),o||r.send(x(t,{origin:e}))}),(function(t){s.add(t)}))}catch(t){this.send(M(e,t))}if(d(i))return this.spawnPromise(i,e);var u={id:e,send:function(t){return s.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){o=!0,p(i)&&i()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,u),u},a.prototype.spawnObservable=function(t,e){var n,i=this,r=t.subscribe((function(t){n=t,i.send(x(t,{origin:e}))}),(function(t){i.removeChild(e),i.send(x(M(e,t),{origin:e}))}),(function(){i.removeChild(e),i.send(x(D(e),{origin:e}))})),o={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return r.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}};return this.children.set(e,o),o},a.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},a.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},a.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})},a.prototype.attachDev=function(){var t=H();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},e),{features:i({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}K(this)}},a.prototype.toJSON=function(){return{id:this.id}},a.prototype[y]=function(){return this},a.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},a.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),a.interpret=tt,a}();function tt(t,e){return new Z(t,e)}t.Interpreter=Z,t.interpret=tt,t.spawn=function(t,e){var n=function(t){return v(t)?i(i({},Y),{name:t}):i(i(i({},Y),{name:m()}),t)}(e);return function(e){return e?e.spawn(t,n.name,n):function(t,e,n){var i=function(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}}}(e);if(i.deferred=!0,g(t)){var r=i.state=q(void 0,(function(){return(n?t.withContext(n):t).initialState}));i.getSnapshot=function(){return r}}return i}(t,n.name)}(J[J.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
package/dist/xstate.js CHANGED
@@ -12,4 +12,4 @@
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function o(t,e){for(var n=0,r=e.length,i=t.length;n<r;n++,i++)t[i]=e[n];return t}var a={};function s(t){return Object.keys(t)}function u(t,e,n){void 0===n&&(n=".");var r=f(t,n),i=f(e,n);return O(i)?!!O(r)&&i===r:O(r)?r in i:s(r).every((function(t){return t in i&&u(r[t],i[t])}))}function c(t){try{return O(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function h(t,e){try{return T(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function f(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:T(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function p(t,e,n){var i,o,a={};try{for(var u=r(s(t)),c=u.next();!c.done;c=u.next()){var h=c.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(i)throw i.error}}return a}var v=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function y(t){return t?O(t)?[[t]]:g(s(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?y(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function g(t){var e;return(e=[]).concat.apply(e,o([],i(t)))}function m(t){return T(t)?t:[t]}function S(t){return void 0===t?[]:m(t)}function x(t,e,n){var i,o;if(N(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),u=s.next();!u.done;u=s.next()){var c=u.value,h=t[c];N(h)?a[c]=h(e,n.data):a[c]=h}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function w(t){return t instanceof Promise||!(null===t||!N(t)&&"object"!=typeof t||!N(t.then))}function b(t,e){var n,o,a=i([[],[]],2),s=a[0],u=a[1];try{for(var c=r(t),h=c.next();!h.done;h=c.next()){var f=h.value;e(f)?s.push(f):u.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(o=c.return)&&o.call(c)}finally{if(n)throw n.error}}return[s,u]}function _(t,e){return d(t.states,(function(t,n){if(t){var r=(O(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function E(t,e,n,i){return t?n.reduce((function(t,n){var o,a,u=n.assignment,c={state:i,action:n,_event:e},h={};if(N(u))h=u(t,e.data,c);else try{for(var f=r(s(u)),l=f.next();!l.done;l=f.next()){var d=l.value,p=u[d];h[d]=N(p)?p(t,e.data,c):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,h)}),t):t}function T(t){return Array.isArray(t)}function N(t){return"function"==typeof t}function O(t){return"string"==typeof t}function A(t,e){if(t)return O(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:N(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var P=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C=function(){var t=0;return function(){return(++t).toString(16)}}();function V(t,n){return O(t)||"number"==typeof t?e({type:t},n):t}function L(t,n){if(!O(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=V(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function D(t,n){return m(n).map((function(n){return void 0===n||"string"==typeof n||k(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function R(t,e,n,r,i){var o=t.options.guards,a={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,a);var s=o[e.type];if(!s)throw new Error("Guard '"+e.type+"' is not implemented on machine '"+t.id+"'.");return s(n,r.data,a)}function M(t){return"string"==typeof t?{type:t}:t}function z(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(I=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",I.Stop="xstate.stop",I.Raise="xstate.raise",I.Send="xstate.send",I.Cancel="xstate.cancel",I.NullEvent="",I.Assign="xstate.assign",I.After="xstate.after",I.DoneState="done.state",I.DoneInvoke="done.invoke",I.Log="xstate.log",I.Init="xstate.init",I.Invoke="xstate.invoke",I.ErrorExecution="error.execution",I.ErrorCommunication="error.communication",I.ErrorPlatform="error.platform",I.ErrorCustom="xstate.error",I.Update="xstate.update",I.Pure="xstate.pure",I.Choose="xstate.choose",(j=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",j.Internal="#_internal";var F=function(t){return"atomic"===t.type||"final"===t.type};function U(t){return s(t.states).map((function(e){return t.states[e]}))}function B(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(B)))}function J(t,e){var n,i,o,a,s,u,c,h,f=q(new Set(t)),l=new Set(e);try{for(var d=r(l),p=d.next();!p.done;p=d.next())for(var v=(E=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=q(l);try{for(var g=r(l),m=g.next();!m.done;m=g.next()){if("compound"!==(E=m.value).type||y.get(E)&&y.get(E).length){if("parallel"===E.type)try{for(var S=(s=void 0,r(U(E))),x=S.next();!x.done;x=S.next()){var w=x.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{x&&!x.done&&(u=S.return)&&u.call(S)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.next()){var E;for(v=(E=_.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}}catch(t){c={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(c)throw c.error}}return l}function q(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i}function $(t,e){return function t(e,n){var r=n.get(e);if(!r)return{};if("compound"===e.type){var i=r[0];if(!i)return{};if(F(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,q(J([t],e)))}function X(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function H(t,e){return"compound"===e.type?U(e).some((function(e){return"final"===e.type&&X(t,e)})):"parallel"===e.type&&U(e).every((function(e){return H(t,e)}))}var G=t.ActionTypes.Start,K=t.ActionTypes.Stop,Q=t.ActionTypes.Raise,W=t.ActionTypes.Send,Y=t.ActionTypes.Cancel,Z=t.ActionTypes.NullEvent,tt=t.ActionTypes.Assign,et=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),nt=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,it=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),ot=t.ActionTypes.ErrorCustom,at=t.ActionTypes.Update,st=t.ActionTypes.Choose,ut=t.ActionTypes.Pure,ct=L({type:nt});function ht(t,e){return e&&e[t]||void 0}function ft(t,n){var r;if(O(t)||"number"==typeof t)r=N(i=ht(t,n))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(N(t))r={type:t.name||t.toString(),exec:t};else{var i;if(N(i=ht(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return r}var lt=function(t,e){return t?(T(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:O(t)?t:n.id},n),{type:n.type})}function pt(e){return O(e)?{type:Q,event:e}:vt(e,{to:t.SpecialTargets.Internal})}function vt(t,e){return{to:e?e.to:void 0,type:W,event:N(t)?t:V(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:N(t)?t.name:c(t)}}function yt(n,r){return vt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function gt(){return yt(at)}var mt=function(t,e){return{context:t,event:e}};var St=function(t){return{type:Y,sendId:t}};function xt(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=N(e)?e:dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:tt,assignment:t}};function _t(e,n){var r=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+r}function Et(e,n){var r=t.ActionTypes.DoneState+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Tt(e,n){var r=t.ActionTypes.DoneInvoke+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Nt(e,n){var r=t.ActionTypes.ErrorPlatform+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Ot(t,n){return vt((function(t,e){return e}),e(e({},n),{to:t}))}function At(n,r,a,s,u,c){void 0===c&&(c=!1);var h=i(c?[[],u]:b(u,(function(t){return t.type===tt})),2),f=h[0],l=h[1],d=f.length?E(a,s,f,r):a,p=c?[a]:void 0;return[g(l.map((function(a){var u;switch(a.type){case Q:return{type:Q,_event:L(a.event)};case W:return function(t,n,r,i){var o,a={_event:r},s=L(N(t.event)?t.event(n,r.data,a):t.event);if(O(t.delay)){var u=i&&i[t.delay];o=N(u)?u(n,r.data,a):u}else o=N(t.delay)?t.delay(n,r.data,a):t.delay;var c=N(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:c,_event:s,event:s.data,delay:o})}(a,d,s,n.options.delays);case et:return function(t,n,r){return e(e({},t),{value:O(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(a,d,s);case st:if(!(v=null===(u=a.conds.find((function(t){var e=A(t.cond,n.options.guards);return!e||R(n,e,d,s,r)})))||void 0===u?void 0:u.actions))return[];var h=i(At(n,r,d,s,lt(S(v),n.options.actions),c),2),f=h[0],l=h[1];return d=l,null==p||p.push(d),f;case ut:var v;if(!(v=a.get(d,s.data)))return[];var y=i(At(n,r,d,s,lt(S(v),n.options.actions),c),2),g=y[0],m=y[1];return d=m,null==p||p.push(d),g;case K:return function(e,n,r){var i=N(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(a,d,s);case tt:d=E(d,s,[a],r),null==p||p.push(d);break;default:var x=ft(a,n.options.actions),w=x.exec;if(w&&p){var b=p.length-1;x.exec=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];null==w||w.apply(void 0,o([p[b]],i(e)))}}return x}})).filter((function(t){return!!t}))),d]}var Pt=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=a,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return o([],i(new Set(g(o([],i(t.map((function(t){return t.ownEvents}))))))))}(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:ct,_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=ct;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),O(t))return[t];var r=s(t);return r.concat.apply(r,o([],i(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))})))))},t.prototype.toJSON=function(){this.configuration,this.transitions;var t=this.tags,r=n(this,["configuration","transitions","tags"]);return e(e({},r),{tags:Array.from(t)})},t.prototype.matches=function(t){return u(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t}(),kt=[],It=function(t,e){kt.push(t);var n=e(t);return kt.pop(),n};function jt(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}}}function Ct(t,e,n){var r=jt(e);if(r.deferred=!0,k(t)){var i=r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Vt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Lt(t){return e(e({type:rt},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:rt,src:Vt(t.src)})}})}var Dt={},Rt=function(t){return"#"===t[0]},Mt=function(){function a(t,n,u){var c,h=this;void 0===u&&(u="context"in t?t.context:void 0),this.config=t,this._context=u,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||o([this.machine.key],i(this.path)).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&s(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(c=this.config.schema)&&void 0!==c?c:{},this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(function(t,n){var r,i=new a(t,{_parent:h,_key:n});return Object.assign(h.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Dt;var f=0;!function t(e){var n,i;e.order=f++;try{for(var o=r(U(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=S(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=S(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=S(this.config.invoke).map((function(t,n){var r,i;if(k(t))return h.machine.options.services=e(((r={})[t.id]=t,r),h.machine.options.services),Lt({src:t.id,id:t.id});if(O(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||N(t.src)){var o=h.id+":invocation["+n+"]";return h.machine.options.services=e(((i={})[o]=t.src,i),h.machine.options.services),Lt(e(e({id:o},t),{src:o}))}var a=t.src;return Lt(e(e({id:a.type},t),{src:a}))})),this.activities=S(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this),this.tags=S(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||B(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){var r=this.options,i=r.actions,o=r.activities,s=r.guards,u=r.services,c=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},u),t.services),delays:e(e({},c),t.delays)},null!=n?n:this.context)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"context",{get:function(){return N(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:d(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}},enumerable:!1,configurable:!0}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var r=n.eventType===t;return e?r:r||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=_t(N(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(r,{delay:e})),t.onExit.push(St(r)),r};return(T(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=O(o)?{target:o}:o,s=isNaN(+t)?t:+t,u=r(s,i);return S(a).map((function(t){return e(e({},t),{event:u,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Pt?t.value:f(t,this.delimiter);if(O(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this,this.states[r]]}var o=s(r),a=o.map((function(t){return n.getStateNode(t)}));return a.push(this),a.concat(o.reduce((function(t,e){var i=n.getStateNode(e).getStateNodes(r[e]);return t.concat(i)}),[]))},a.prototype.handles=function(t){var e=c(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(J([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n,done:H(n,this)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=s(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var u=r(s(t)),c=u.next();!c.done;c=u.next()){var h=c.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=u.return)&&o.call(u)}finally{if(i)throw i.error}}var d=s(a).map((function(t){return a[t]})),p=g(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=g(d.map((function(t){return t.entrySet}))),y=g(s(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:g(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:g(s(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return O(t)?this.transitionLeafNode(t,e,n):1===s(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.next=function(t,e){var n,a,s,c=this,h=e.name,l=[],d=[];try{for(var p=r(this.getCandidates(h)),y=p.next();!y.done;y=p.next()){var m=y.value,S=m.cond,x=m.in,w=t.context,b=!x||(O(x)&&Rt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):u(f(x,this.delimiter),v(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||R(this.machine,S,w,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(S.name||S.type)+"' in transition for event '"+h+"' in state node '"+this.id+"':\n"+t.message)}if(_&&b){void 0!==m.target&&(d=m.target),l.push.apply(l,o([],i(m.actions))),s=m;break}}}catch(t){n={error:t}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}if(s){if(!d.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:l};var E=g(d.map((function(e){return c.getRelativeStateNodes(e,t.historyValue)}))),T=!!s.internal;return{transitions:[s],entrySet:T?[]:g(E.map((function(t){return c.nodesFromChild(t)}))),exitSet:T?[]:[this],configuration:E,source:t,actions:l}}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],n=t;n&&n!==this;)e.push(n),n=n.parent;return e.push(this),e},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,u,c,h,f=J([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?J(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){X(f,m=p.value)||t.entrySet.push(m)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(u=d.return)&&u.call(d)}finally{if(s)throw s.error}}try{for(var v=r(f),y=v.next();!y.done;y=v.next()){var m;X(l,m=y.value)&&!X(t.exitSet,m.parent)||t.exitSet.push(m)}}catch(t){c={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(c)throw c.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var S=g(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Et(r.id,r.doneData),Et(o.id,r.doneData?x(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&U(a).every((function(e){return H(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var w=new Set(t.entrySet),b=new Set(t.exitSet),_=i([g(Array.from(w).map((function(t){return o(o([],i(t.activities.map((function(t){return xt(t)})))),i(t.onEntry))}))).concat(S.map(pt)),g(Array.from(b).map((function(t){return o(o([],i(t.onExit)),i(t.activities.map((function(t){return wt(t)}))))})))],2),E=_[0],T=_[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,a,s=L(e);if(t instanceof Pt)r=void 0===n?t:this.resolveState(Pt.from(t,n));else{var u=O(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),c=null!=n?n:this.machine.context;r=this.resolveState(Pt.from(u,c))}if(this.strict&&!this.events.includes(s.name)&&(a=s.name,!/^(done|error)\./.test(a)))throw new Error("Machine '"+this.id+"' does not accept event '"+s.name+"'");var h=this._transition(r.value,r,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=J([],this.getStateNodes(r.value)),d=h.configuration.length?J(f,h.configuration):f;return h.configuration=o([],i(d)),this.resolveTransition(h,r,s)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,a=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o([],i(a))),t},a.prototype.resolveTransition=function(n,o,a,u){var c,h,f=this;void 0===a&&(a=ct),void 0===u&&(u=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0,p=d?$(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=o?o.context:u,m=this.getActions(n,y,a,o),S=o?e({},o.activities):{};try{for(var w=r(m),E=w.next();!E.done;E=w.next()){var T=E.value;T.type===G?S[T.activity.id||T.activity.type]=T:T.type===K&&(S[T.activity.id||T.activity.type]=!1)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=w.return)&&h.call(w)}finally{if(c)throw c.error}}var N,A,P=i(At(this,o,y,a,m,this.machine.config.preserveActionOrder),2),k=P[0],I=P[1],j=i(b(k,(function(e){return e.type===Q||e.type===W&&e.to===t.SpecialTargets.Internal})),2),C=j[0],V=j[1],L=k.filter((function(t){var e;return t.type===G&&(null===(e=t.activity)||void 0===e?void 0:e.type)===rt})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=M(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?x(t.data,n,r):void 0,u=a?Ct(a,t.id,s):jt(t.id);return u.meta=t,u}(e.activity,f.machine,I,a),t}),o?e({},o.children):{}),D=p?n.configuration:o?o.configuration:[],R=H(D,this),z=new Pt({value:p||o.value,context:I,_event:a,_sessionid:o?o._sessionid:null,historyValue:p?v?(N=v,A=p,{current:A,states:_(N,A)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?V:[],activities:p?S:o?o.activities:{},events:[],configuration:D,transitions:n.transitions,children:L,done:R,tags:null==o?void 0:o.tags}),F=y!==I;z.changed=a.name===at||F;var U=z.history;U&&delete U.history;var B=!R&&(this._transient||l.some((function(t){return t._transient})));if(!(d||B&&""!==a.name))return z;var J=z;if(!R)for(B&&(J=this.resolveRaisedTransition(J,{type:Z},a));C.length;){var q=C.shift();J=this.resolveRaisedTransition(J,q._event,a)}var X=J.changed||(U?!!J.actions.length||F||typeof U.value!=typeof J.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(O(e)||O(n))return e===n;var r=s(e),i=s(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(J.value,U.value):void 0);return J.changed=X,J.history=U,J.tags=new Set(g(J.configuration.map((function(t){return t.tags})))),J},a.prototype.getStateNode=function(t){if(Rt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '"+t+"' from '"+this.id+"'; no child states exist.");var e=this.states[t];if(!e)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return e},a.prototype.getStateNodeById=function(t){var e=Rt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Rt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Dt;switch(this.type){case"parallel":return d(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Dt}));case"compound":if(O(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return s(t).length?d(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Dt})):this.initialStateValue||{};default:return t||Dt}},a.prototype.getResolvedPath=function(t){if(Rt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return h(t,this.delimiter)},Object.defineProperty(a.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=p(this.states,(function(t){return t.initialStateValue||Dt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");e=F(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),a.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(a.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=O(e.target)&&Rt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if("history"===o.type)return o.resolveHistory();if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(r)},a.prototype.historyValue=function(t){if(s(this.states).length)return{current:t||this.initialStateValue,states:p(this.states,(function(e,n){if(!t)return e.historyValue();var r=O(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?g(y(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),u=s.next();!u.done;u=s.next()){var c=u.value;i=i[a][c]}}catch(t){e={error:t}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return i})(t).current;return O(s)?[n.getStateNode(s)]:g(y(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=g(s(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var u=r(s(o)),c=u.next();!c.done;c=u.next()){var h=o[c.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=u.return)&&e.call(u)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),a.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!O(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var r=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(r);try{return e.parent.getStateNodeByPath(r)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return S(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return O(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:lt(S(t.actions)),cond:A(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return s},a.prototype.formatTransitions=function(){var t,e,a,u=this;if(this.config.on)if(Array.isArray(this.config.on))a=this.config.on;else{var c=this.config.on,h=c["*"],f=void 0===h?[]:h,l=n(c,["*"]);a=g(s(l).map((function(t){return D(t,l[t])})).concat(D("*",f)))}else a=[];var d=this.config.always?D("",this.config.always):[],p=this.config.onDone?D(String(Et(this.id)),this.config.onDone):[],v=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(D(String(Tt(t.id)),t.onDone)))),t.onError&&e.push.apply(e,o([],i(D(String(Nt(t.id)),t.onError)))),e}))),y=this.after,m=g(o(o(o(o([],i(p)),i(v)),i(a)),i(d)).map((function(t){return S(t).map((function(t){return u.formatTransition(t)}))})));try{for(var x=r(y),w=x.next();!w.done;w=x.next()){var b=w.value;m.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=x.return)&&e.call(x)}finally{if(t)throw t.error}}return m},a}();var zt={deferEvents:!1},Ft=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},zt),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}(),Ut=new Map,Bt=0,Jt=function(){return"x:"+Bt++},qt=function(t,e){return Ut.set(t,e),t},$t=function(t){return Ut.get(t)},Xt=function(t){Ut.delete(t)};function Ht(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Gt(t){if(Ht()){var e=function(){var t=Ht();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Kt(t,n){void 0===n&&(n={});var r,i=t.initialState,o=new Set,a=[],s=!1,u=(r={id:n.id,send:function(e){a.push(e),function(){if(!s){for(s=!0;a.length>0;){var e=a.shift();i=t.transition(i,e,c),o.forEach((function(t){return t.next(i)}))}s=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=z(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},e({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},r)),c={parent:n.parent,self:u,id:n.id||"anonymous",observers:o};return i=t.start?t.start(c):i,u}var Qt,Wt={sync:!1,autoForward:!1};(Qt=t.InterpreterStatus||(t.InterpreterStatus={}))[Qt.NotStarted=0]="NotStarted",Qt[Qt.Running=1]="Running",Qt[Qt.Stopped=2]="Stopped";var Yt=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new Ft,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(T(e))return o.batch(e),o.state;var r=L(V(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+r.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(r.data));return o.scheduler.schedule((function(){o.forward(r);var t=o.nextState(r);o.update(t,r)})),o._state},this.sendTo=function(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:O(r)?o.children.get(r)||$t(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ot?""+Nt(o.id):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '"+r+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),i),s=a.clock,u=a.logger,c=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=u,this.clock=s,this.parent=c,this.options=a,this.scheduler=new Ft({deferEvents:this.options.deferEvents}),this.sessionId=Jt()}return Object.defineProperty(n.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(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,u,c,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t,t.event)}}catch(t){o={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}try{for(var y=r(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(u=y.return)&&u.call(y)}finally{if(s)throw s.error}}var m=H(t.configuration||[],this.machine);if(this.state.configuration&&m){var S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=S&&S.doneData?x(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Tt(this.id,w))}}catch(t){c={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(c)throw c.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},n.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;qt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:It(this,(function(){return!O(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(Pt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,ct)})),this},n.prototype.stop=function(){var e,n,i,o,a,u,c,h,f,l,d=this;try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){var y=v.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{v&&!v.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var g=r(this.stopListeners),m=g.next();!m.done;m=g.next()){(y=m.value)(),this.stopListeners.delete(y)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}try{for(var S=r(this.contextListeners),x=S.next();!x.done;x=S.next()){y=x.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(u=S.return)&&u.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.doneListeners),b=w.next();!b.done;b=w.next()){y=b.value;this.doneListeners.delete(y)}}catch(t){c={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;d.exec(a,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){N(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),E=_.next();!E.done;E=_.next()){var T=E.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{E&&!E.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Xt(this.sessionId),this},n.prototype.batch=function(n){var a=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error(n.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var t,s,u=a.state,c=!1,h=[],f=function(t){var n=L(t);a.forward(n),u=It(a,(function(){return a.machine.transition(u,n)})),h.push.apply(h,o([],i(u.actions.map((function(t){return r=u,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i}))))),c=c||!!u.changed};try{for(var l=r(n),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(t)throw t.error}}u.changed=c,u.actions=h,a.update(u,L(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=L(t);if(0===n.name.indexOf(it)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(it)})))throw n.data.data;return It(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||ht(e.type,r),s=N(a)?a:a?a.exec:e.exec;if(s)try{return s(i,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case W:var u=e;if("number"==typeof u.delay)return void this.defer(u);u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case Y:this.cancel(e.sendId);break;case G:var c=e.activity;if(!this.state.activities[c.id||c.type])break;if(c.type===t.ActionTypes.Invoke){var h=M(c.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=c.id,d=c.data,p="autoForward"in c?c.autoForward:!!c.forward;if(!f)return;var v=d?x(d,i,o):void 0;if("string"==typeof f)return;var y=N(f)?f(i,o.data,{data:v,src:h}):f;if(!y)return;var g=void 0;k(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(c);break;case K:this.stopChild(e.activity.id);break;case et:var m=e.label,S=e.value;m?this.logger(m,S):this.logger(S)}},n.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),N(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(N(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,n);if(function(t){try{return"subscribe"in t&&N(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,n);throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i,o},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},Wt),r);a.sync&&o.onTransition((function(t){i.send(at,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(L(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=Kt(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,e){var n,r=this,i=!1;t.then((function(t){i||(n=t,r.removeChild(e),r.send(L(Tt(e,t),{origin:e})))}),(function(t){if(!i){r.removeChild(e);var n=Nt(e,t);try{r.send(L(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var o={id:e,send:function(){},subscribe:function(e,n,r){var i=z(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,o),o},n.prototype.spawnCallback=function(t,e){var n,r,i=this,o=!1,a=new Set,s=new Set;try{r=t((function(t){n=t,s.forEach((function(e){return e(t)})),o||i.send(L(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(Nt(e,t))}if(w(r))return this.spawnPromise(r,e);var u={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){o=!0,N(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,u),u},n.prototype.spawnObservable=function(t,e){var n,r=this,i=t.subscribe((function(t){n=t,r.send(L(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(L(Nt(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(L(Tt(e),{origin:e}))})),o={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return i.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}};return this.children.set(e,o),o},n.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){var t=Ht();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Gt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[P]=function(){return this},n.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=Zt,n}();function Zt(t,e){return new Yt(t,e)}var te={raise:pt,send:vt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:et,label:e,expr:t}},cancel:St,start:xt,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return vt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,r){return yt((function(t,e,r){return{type:ot,data:N(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=Yt,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Mt(t,e,n)},t.State=Pt,t.StateNode=Mt,t.actions=te,t.assign=bt,t.createMachine=function(t,e){return new Mt(t,e)},t.createSchema=function(t){return t},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Zt,t.mapState=function(t,e){var n,i,o;try{for(var a=r(s(t)),c=a.next();!c.done;c=a.next()){var h=c.value;u(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{c&&!c.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Pt.from(t,t instanceof Pt?t.context:void 0);try{for(var u=r(e),c=u.next();!c.done;c=u.next()){var h=i(c.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{c&&!c.done&&(a=u.return)&&a.call(u)}finally{if(o)throw o.error}}return n(s)},t.matchesState=u,t.send=vt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,n){var r=function(t){return O(t)?e(e({},Wt),{name:t}):e(e(e({},Wt),{name:C()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Ct(t,r.name)}(kt[kt.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function o(t,e){for(var n=0,r=e.length,i=t.length;n<r;n++,i++)t[i]=e[n];return t}var a={};function s(t){return Object.keys(t)}function c(t,e,n){void 0===n&&(n=".");var r=f(t,n),i=f(e,n);return O(i)?!!O(r)&&i===r:O(r)?r in i:s(r).every((function(t){return t in i&&c(r[t],i[t])}))}function u(t){try{return O(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function h(t,e){try{return T(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function f(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:T(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function p(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}return a}var v=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function y(t){return t?O(t)?[[t]]:g(s(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?y(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function g(t){var e;return(e=[]).concat.apply(e,o([],i(t)))}function m(t){return T(t)?t:[t]}function S(t){return void 0===t?[]:m(t)}function x(t,e,n){var i,o;if(N(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];N(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function w(t){return t instanceof Promise||!(null===t||!N(t)&&"object"!=typeof t||!N(t.then))}function b(t,e){var n,o,a=i([[],[]],2),s=a[0],c=a[1];try{for(var u=r(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function _(t,e){return d(t.states,(function(t,n){if(t){var r=(O(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function E(t,e,n,i){return t?n.reduce((function(t,n){var o,a,c=n.assignment,u={state:i,action:n,_event:e},h={};if(N(c))h=c(t,e.data,u);else try{for(var f=r(s(c)),l=f.next();!l.done;l=f.next()){var d=l.value,p=c[d];h[d]=N(p)?p(t,e.data,u):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,h)}),t):t}function T(t){return Array.isArray(t)}function N(t){return"function"==typeof t}function O(t){return"string"==typeof t}function A(t,e){if(t)return O(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:N(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}var P=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C=function(){var t=0;return function(){return(++t).toString(16)}}();function V(t,n){return O(t)||"number"==typeof t?e({type:t},n):t}function L(t,n){if(!O(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=V(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function D(t,n){return m(n).map((function(n){return void 0===n||"string"==typeof n||k(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function R(t,e,n,r,i){var o=t.options.guards,a={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(n,r.data,a);var s=o[e.type];if(!s)throw new Error("Guard '"+e.type+"' is not implemented on machine '"+t.id+"'.");return s(n,r.data,a)}function M(t){return"string"==typeof t?{type:t}:t}function z(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(I=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",I.Stop="xstate.stop",I.Raise="xstate.raise",I.Send="xstate.send",I.Cancel="xstate.cancel",I.NullEvent="",I.Assign="xstate.assign",I.After="xstate.after",I.DoneState="done.state",I.DoneInvoke="done.invoke",I.Log="xstate.log",I.Init="xstate.init",I.Invoke="xstate.invoke",I.ErrorExecution="error.execution",I.ErrorCommunication="error.communication",I.ErrorPlatform="error.platform",I.ErrorCustom="xstate.error",I.Update="xstate.update",I.Pure="xstate.pure",I.Choose="xstate.choose",(j=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",j.Internal="#_internal";var F=function(t){return"atomic"===t.type||"final"===t.type};function U(t){return s(t.states).map((function(e){return t.states[e]}))}function B(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(B)))}function J(t,e){var n,i,o,a,s,c,u,h,f=q(new Set(t)),l=new Set(e);try{for(var d=r(l),p=d.next();!p.done;p=d.next())for(var v=(E=p.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=q(l);try{for(var g=r(l),m=g.next();!m.done;m=g.next()){if("compound"!==(E=m.value).type||y.get(E)&&y.get(E).length){if("parallel"===E.type)try{for(var S=(s=void 0,r(U(E))),x=S.next();!x.done;x=S.next()){var w=x.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{x&&!x.done&&(c=S.return)&&c.call(S)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.next()){var E;for(v=(E=_.value).parent;v&&!l.has(v);)l.add(v),v=v.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function q(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i}function $(t,e){return function t(e,n){var r=n.get(e);if(!r)return{};if("compound"===e.type){var i=r[0];if(!i)return{};if(F(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,q(J([t],e)))}function X(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function H(t,e){return"compound"===e.type?U(e).some((function(e){return"final"===e.type&&X(t,e)})):"parallel"===e.type&&U(e).every((function(e){return H(t,e)}))}var G=t.ActionTypes.Start,K=t.ActionTypes.Stop,Q=t.ActionTypes.Raise,W=t.ActionTypes.Send,Y=t.ActionTypes.Cancel,Z=t.ActionTypes.NullEvent,tt=t.ActionTypes.Assign,et=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),nt=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,it=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),ot=t.ActionTypes.ErrorCustom,at=t.ActionTypes.Update,st=t.ActionTypes.Choose,ct=t.ActionTypes.Pure,ut=L({type:nt});function ht(t,e){return e&&e[t]||void 0}function ft(t,n){var r;if(O(t)||"number"==typeof t)r=N(i=ht(t,n))?{type:t,exec:i}:i||{type:t,exec:void 0};else if(N(t))r={type:t.name||t.toString(),exec:t};else{var i;if(N(i=ht(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return r}var lt=function(t,e){return t?(T(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:O(t)?t:n.id},n),{type:n.type})}function pt(e){return O(e)?{type:Q,event:e}:vt(e,{to:t.SpecialTargets.Internal})}function vt(t,e){return{to:e?e.to:void 0,type:W,event:N(t)?t:V(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:N(t)?t.name:u(t)}}function yt(n,r){return vt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function gt(){return yt(at)}var mt=function(t,e){return{context:t,event:e}};var St=function(t){return{type:Y,sendId:t}};function xt(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=N(e)?e:dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:tt,assignment:t}};function _t(e,n){var r=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+r}function Et(e,n){var r=t.ActionTypes.DoneState+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Tt(e,n){var r=t.ActionTypes.DoneInvoke+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Nt(e,n){var r=t.ActionTypes.ErrorPlatform+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Ot(t,n){return vt((function(t,e){return e}),e(e({},n),{to:t}))}function At(n,r,a,s,c,u){void 0===u&&(u=!1);var h=i(u?[[],c]:b(c,(function(t){return t.type===tt})),2),f=h[0],l=h[1],d=f.length?E(a,s,f,r):a,p=u?[a]:void 0;return[g(l.map((function(a){var c;switch(a.type){case Q:return{type:Q,_event:L(a.event)};case W:return function(t,n,r,i){var o,a={_event:r},s=L(N(t.event)?t.event(n,r.data,a):t.event);if(O(t.delay)){var c=i&&i[t.delay];o=N(c)?c(n,r.data,a):c}else o=N(t.delay)?t.delay(n,r.data,a):t.delay;var u=N(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(a,d,s,n.options.delays);case et:return function(t,n,r){return e(e({},t),{value:O(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(a,d,s);case st:if(!(v=null===(c=a.conds.find((function(t){var e=A(t.cond,n.options.guards);return!e||R(n,e,d,s,r)})))||void 0===c?void 0:c.actions))return[];var h=i(At(n,r,d,s,lt(S(v),n.options.actions),u),2),f=h[0],l=h[1];return d=l,null==p||p.push(d),f;case ct:var v;if(!(v=a.get(d,s.data)))return[];var y=i(At(n,r,d,s,lt(S(v),n.options.actions),u),2),g=y[0],m=y[1];return d=m,null==p||p.push(d),g;case K:return function(e,n,r){var i=N(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(a,d,s);case tt:d=E(d,s,[a],r),null==p||p.push(d);break;default:var x=ft(a,n.options.actions),w=x.exec;if(w&&p){var b=p.length-1;x=e(e({},x),{exec:function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];w.apply(void 0,o([p[b]],i(e)))}})}return x}})).filter((function(t){return!!t}))),d]}var Pt=function(){function t(t){var e,n,r=this;this.actions=[],this.activities=a,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||a,this.meta=(void 0===(n=t.configuration)&&(n=[]),n.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{})),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return function(t){return o([],i(new Set(g(o([],i(t.map((function(t){return t.ownEvents}))))))))}(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:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=ut;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),O(t))return[t];var r=s(t);return r.concat.apply(r,o([],i(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))})))))},t.prototype.toJSON=function(){var t=this,r=(t.configuration,t.transitions,t.tags),i=(t.machine,n(t,["configuration","transitions","tags","machine"]));return e(e({},i),{tags:Array.from(r)})},t.prototype.matches=function(t){return c(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t.prototype.can=function(t){var e;return this.machine,!!(null===(e=this.machine)||void 0===e?void 0:e.transition(this,t).changed)},t}(),kt=[],It=function(t,e){kt.push(t);var n=e(t);return kt.pop(),n};function jt(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}}}function Ct(t,e,n){var r=jt(e);if(r.deferred=!0,k(t)){var i=r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}));r.getSnapshot=function(){return i}}return r}function Vt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Lt(t){return e(e({type:rt},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:rt,src:Vt(t.src)})}})}var Dt={},Rt=function(t){return"#"===t[0]},Mt=function(){function a(t,n,c){var u,h=this;void 0===c&&(c="context"in t?t.context:void 0),this.config=t,this._context=c,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||o([this.machine.key],i(this.path)).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&s(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(u=this.config.schema)&&void 0!==u?u:{},this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(function(t,n){var r,i=new a(t,{_parent:h,_key:n});return Object.assign(h.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Dt;var f=0;!function t(e){var n,i;e.order=f++;try{for(var o=r(U(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=S(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=S(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=S(this.config.invoke).map((function(t,n){var r,i;if(k(t))return h.machine.options.services=e(((r={})[t.id]=t,r),h.machine.options.services),Lt({src:t.id,id:t.id});if(O(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||N(t.src)){var o=h.id+":invocation["+n+"]";return h.machine.options.services=e(((i={})[o]=t.src,i),h.machine.options.services),Lt(e(e({id:o},t),{src:o}))}var a=t.src;return Lt(e(e({id:a.type},t),{src:a}))})),this.activities=S(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this),this.tags=S(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||B(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){var r=this.options,i=r.actions,o=r.activities,s=r.guards,c=r.services,u=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},null!=n?n:this.context)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"context",{get:function(){return N(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:d(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}},enumerable:!1,configurable:!0}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var r=n.eventType===t;return e?r:r||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=_t(N(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(r,{delay:e})),t.onExit.push(St(r)),r};return(T(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=O(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return S(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Pt?t.value:f(t,this.delimiter);if(O(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this,this.states[r]]}var o=s(r),a=o.map((function(t){return n.getStateNode(t)}));return a.push(this),a.concat(o.reduce((function(t,e){var i=n.getStateNode(e).getStateNodes(r[e]);return t.concat(i)}),[]))},a.prototype.handles=function(t){var e=u(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(J([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n,done:H(n,this)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=s(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}var d=s(a).map((function(t){return a[t]})),p=g(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=g(d.map((function(t){return t.entrySet}))),y=g(s(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:g(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:g(s(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return O(t)?this.transitionLeafNode(t,e,n):1===s(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.next=function(t,e){var n,a,s,u=this,h=e.name,l=[],d=[];try{for(var p=r(this.getCandidates(h)),y=p.next();!y.done;y=p.next()){var m=y.value,S=m.cond,x=m.in,w=t.context,b=!x||(O(x)&&Rt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):c(f(x,this.delimiter),v(this.path.slice(0,-2))(t.value))),_=!1;try{_=!S||R(this.machine,S,w,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(S.name||S.type)+"' in transition for event '"+h+"' in state node '"+this.id+"':\n"+t.message)}if(_&&b){void 0!==m.target&&(d=m.target),l.push.apply(l,o([],i(m.actions))),s=m;break}}}catch(t){n={error:t}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}if(s){if(!d.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:l};var E=g(d.map((function(e){return u.getRelativeStateNodes(e,t.historyValue)}))),T=!!s.internal;return{transitions:[s],entrySet:T?[]:g(E.map((function(t){return u.nodesFromChild(t)}))),exitSet:T?[]:[this],configuration:E,source:t,actions:l}}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],n=t;n&&n!==this;)e.push(n),n=n.parent;return e.push(this),e},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=J([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?J(f,t.configuration):f;try{for(var d=r(l),p=d.next();!p.done;p=d.next()){X(f,m=p.value)||t.entrySet.push(m)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=r(f),y=v.next();!y.done;y=v.next()){var m;X(l,m=y.value)&&!X(t.exitSet,m.parent)||t.exitSet.push(m)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var S=g(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Et(r.id,r.doneData),Et(o.id,r.doneData?x(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&U(a).every((function(e){return H(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var w=new Set(t.entrySet),b=new Set(t.exitSet),_=i([g(Array.from(w).map((function(t){return o(o([],i(t.activities.map((function(t){return xt(t)})))),i(t.onEntry))}))).concat(S.map(pt)),g(Array.from(b).map((function(t){return o(o([],i(t.onExit)),i(t.activities.map((function(t){return wt(t)}))))})))],2),E=_[0],T=_[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,a,s=L(e);if(t instanceof Pt)r=void 0===n?t:this.resolveState(Pt.from(t,n));else{var c=O(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),u=null!=n?n:this.machine.context;r=this.resolveState(Pt.from(c,u))}if(this.strict&&!this.events.includes(s.name)&&(a=s.name,!/^(done|error)\./.test(a)))throw new Error("Machine '"+this.id+"' does not accept event '"+s.name+"'");var h=this._transition(r.value,r,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},f=J([],this.getStateNodes(r.value)),d=h.configuration.length?J(f,h.configuration):f;return h.configuration=o([],i(d)),this.resolveTransition(h,r,s)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,a=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o([],i(a))),t},a.prototype.resolveTransition=function(n,o,a,c){var u,h,f=this;void 0===a&&(a=ut),void 0===c&&(c=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0,p=d?$(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,y=o?o.context:c,m=this.getActions(n,y,a,o),S=o?e({},o.activities):{};try{for(var w=r(m),E=w.next();!E.done;E=w.next()){var T=E.value;T.type===G?S[T.activity.id||T.activity.type]=T:T.type===K&&(S[T.activity.id||T.activity.type]=!1)}}catch(t){u={error:t}}finally{try{E&&!E.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}var N,A,P=i(At(this,o,y,a,m,this.machine.config.preserveActionOrder),2),k=P[0],I=P[1],j=i(b(k,(function(e){return e.type===Q||e.type===W&&e.to===t.SpecialTargets.Internal})),2),C=j[0],V=j[1],L=k.filter((function(t){var e;return t.type===G&&(null===(e=t.activity)||void 0===e?void 0:e.type)===rt})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=M(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?x(t.data,n,r):void 0,c=a?Ct(a,t.id,s):jt(t.id);return c.meta=t,c}(e.activity,f.machine,I,a),t}),o?e({},o.children):{}),D=p?n.configuration:o?o.configuration:[],R=H(D,this),z=new Pt({value:p||o.value,context:I,_event:a,_sessionid:o?o._sessionid:null,historyValue:p?v?(N=v,A=p,{current:A,states:_(N,A)}):void 0:o?o.historyValue:void 0,history:!p||n.source?o:void 0,actions:p?V:[],activities:p?S:o?o.activities:{},events:[],configuration:D,transitions:n.transitions,children:L,done:R,tags:null==o?void 0:o.tags,machine:this}),F=y!==I;z.changed=a.name===at||F;var U=z.history;U&&delete U.history;var B=!R&&(this._transient||l.some((function(t){return t._transient})));if(!(d||B&&""!==a.name))return z;var J=z;if(!R)for(B&&(J=this.resolveRaisedTransition(J,{type:Z},a));C.length;){var q=C.shift();J=this.resolveRaisedTransition(J,q._event,a)}var X=J.changed||(U?!!J.actions.length||F||typeof U.value!=typeof J.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(O(e)||O(n))return e===n;var r=s(e),i=s(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(J.value,U.value):void 0);return J.changed=X,J.history=U,J.tags=new Set(g(J.configuration.map((function(t){return t.tags})))),J},a.prototype.getStateNode=function(t){if(Rt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '"+t+"' from '"+this.id+"'; no child states exist.");var e=this.states[t];if(!e)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return e},a.prototype.getStateNodeById=function(t){var e=Rt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Rt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Dt;switch(this.type){case"parallel":return d(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Dt}));case"compound":if(O(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return s(t).length?d(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Dt})):this.initialStateValue||{};default:return t||Dt}},a.prototype.getResolvedPath=function(t){if(Rt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return h(t,this.delimiter)},Object.defineProperty(a.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=p(this.states,(function(t){return t.initialStateValue||Dt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");e=F(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),a.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(a.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=O(e.target)&&Rt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if("history"===o.type)return o.resolveHistory();if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(r)},a.prototype.historyValue=function(t){if(s(this.states).length)return{current:t||this.initialStateValue,states:p(this.states,(function(e,n){if(!t)return e.historyValue();var r=O(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?g(y(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),c=s.next();!c.done;c=s.next()){var u=c.value;i=i[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return i})(t).current;return O(s)?[n.getStateNode(s)]:g(y(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=g(s(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var c=r(s(o)),u=c.next();!u.done;u=c.next()){var h=o[u.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),a.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!O(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var r=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(r);try{return e.parent.getStateNodeByPath(r)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return S(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return O(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:lt(S(t.actions)),cond:A(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return s},a.prototype.formatTransitions=function(){var t,e,a,c=this;if(this.config.on)if(Array.isArray(this.config.on))a=this.config.on;else{var u=this.config.on,h=u["*"],f=void 0===h?[]:h,l=n(u,["*"]);a=g(s(l).map((function(t){return D(t,l[t])})).concat(D("*",f)))}else a=[];var d=this.config.always?D("",this.config.always):[],p=this.config.onDone?D(String(Et(this.id)),this.config.onDone):[],v=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o([],i(D(String(Tt(t.id)),t.onDone)))),t.onError&&e.push.apply(e,o([],i(D(String(Nt(t.id)),t.onError)))),e}))),y=this.after,m=g(o(o(o(o([],i(p)),i(v)),i(a)),i(d)).map((function(t){return S(t).map((function(t){return c.formatTransition(t)}))})));try{for(var x=r(y),w=x.next();!w.done;w=x.next()){var b=w.value;m.push(b)}}catch(e){t={error:e}}finally{try{w&&!w.done&&(e=x.return)&&e.call(x)}finally{if(t)throw t.error}}return m},a}();var zt={deferEvents:!1},Ft=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},zt),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}(),Ut=new Map,Bt=0,Jt=function(){return"x:"+Bt++},qt=function(t,e){return Ut.set(t,e),t},$t=function(t){return Ut.get(t)},Xt=function(t){Ut.delete(t)};function Ht(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Gt(t){if(Ht()){var e=function(){var t=Ht();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}function Kt(t,n){void 0===n&&(n={});var r,i=t.initialState,o=new Set,a=[],s=!1,c=(r={id:n.id,send:function(e){a.push(e),function(){if(!s){for(s=!0;a.length>0;){var e=a.shift();i=t.transition(i,e,u),o.forEach((function(t){return t.next(i)}))}s=!1}}()},getSnapshot:function(){return i},subscribe:function(t,e,n){var r=z(t,e,n);return o.add(r),r.next(i),{unsubscribe:function(){o.delete(r)}}}},e({subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},r)),u={parent:n.parent,self:c,id:n.id||"anonymous",observers:o};return i=t.start?t.start(u):i,c}var Qt,Wt={sync:!1,autoForward:!1};(Qt=t.InterpreterStatus||(t.InterpreterStatus={}))[Qt.NotStarted=0]="NotStarted",Qt[Qt.Running=1]="Running",Qt[Qt.Stopped=2]="Stopped";var Yt=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new Ft,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(T(e))return o.batch(e),o.state;var r=L(V(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+r.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(r.data));return o.scheduler.schedule((function(){o.forward(r);var t=o.nextState(r);o.update(t,r)})),o._state},this.sendTo=function(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:O(r)?o.children.get(r)||$t(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ot?""+Nt(o.id):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '"+r+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Ft({deferEvents:this.options.deferEvents}),this.sessionId=Jt()}return Object.defineProperty(n.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(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){(0,v.value)(t,t.event)}}catch(t){o={error:t}}finally{try{v&&!v.done&&(a=p.return)&&a.call(p)}finally{if(o)throw o.error}}try{for(var y=r(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=H(t.configuration||[],this.machine);if(this.state.configuration&&m){var S=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=S&&S.doneData?x(S.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Tt(this.id,w))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},n.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;qt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:It(this,(function(){return!O(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(Pt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,ut)})),this},n.prototype.stop=function(){var e,n,i,o,a,c,u,h,f,l,d=this;try{for(var p=r(this.listeners),v=p.next();!v.done;v=p.next()){var y=v.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{v&&!v.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}try{for(var g=r(this.stopListeners),m=g.next();!m.done;m=g.next()){(y=m.value)(),this.stopListeners.delete(y)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}try{for(var S=r(this.contextListeners),x=S.next();!x.done;x=S.next()){y=x.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{x&&!x.done&&(c=S.return)&&c.call(S)}finally{if(a)throw a.error}}try{for(var w=r(this.doneListeners),b=w.next();!b.done;b=w.next()){y=b.value;this.doneListeners.delete(y)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;d.exec(a,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){N(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),E=_.next();!E.done;E=_.next()){var T=E.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{E&&!E.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Xt(this.sessionId),this},n.prototype.batch=function(n){var a=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error(n.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var t,s,c=a.state,u=!1,h=[],f=function(t){var n=L(t);a.forward(n),c=It(a,(function(){return a.machine.transition(c,n)})),h.push.apply(h,o([],i(c.actions.map((function(t){return r=c,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i}))))),u=u||!!c.changed};try{for(var l=r(n),d=l.next();!d.done;d=l.next()){f(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(s=l.return)&&s.call(l)}finally{if(t)throw t.error}}c.changed=u,c.actions=h,a.update(c,L(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=L(t);if(0===n.name.indexOf(it)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(it)})))throw n.data.data;return It(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||ht(e.type,r),s=N(a)?a:a?a.exec:e.exec;if(s)try{return s(i,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case W: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 Y:this.cancel(e.sendId);break;case G:var u=e.activity;if(!this.state.activities[u.id||u.type])break;if(u.type===t.ActionTypes.Invoke){var h=M(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,p="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var v=d?x(d,i,o):void 0;if("string"==typeof f)return;var y=N(f)?f(i,o.data,{data:v,src:h}):f;if(!y)return;var g=void 0;k(y)&&(y=v?y.withContext(v):y,g={autoForward:p}),this.spawn(y,l,g)}else this.spawnActivity(u);break;case K:this.stopChild(e.activity.id);break;case et:var m=e.label,S=e.value;m?this.logger(m,S):this.logger(S)}},n.prototype.removeChild=function(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),N(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(N(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(o=t)&&"id"in o)return this.spawnActor(t,n);if(function(t){try{return"subscribe"in t&&N(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));if(null!==(i=t)&&"object"==typeof i&&"transition"in i&&"function"==typeof i.transition)return this.spawnBehavior(t,n);throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i,o},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},Wt),r);a.sync&&o.onTransition((function(t){i.send(at,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(L(t,{origin:o.id}))})).start(),s},n.prototype.spawnBehavior=function(t,e){var n=Kt(t,{id:e,parent:this});return this.children.set(e,n),n},n.prototype.spawnPromise=function(t,e){var n,r=this,i=!1;t.then((function(t){i||(n=t,r.removeChild(e),r.send(L(Tt(e,t),{origin:e})))}),(function(t){if(!i){r.removeChild(e);var n=Nt(e,t);try{r.send(L(n,{origin:e}))}catch(t){r.devTools&&r.devTools.send(n,r.state),r.machine.strict&&r.stop()}}}));var o={id:e,send:function(){},subscribe:function(e,n,r){var i=z(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,o),o},n.prototype.spawnCallback=function(t,e){var n,r,i=this,o=!1,a=new Set,s=new Set;try{r=t((function(t){n=t,s.forEach((function(e){return e(t)})),o||i.send(L(t,{origin:e}))}),(function(t){a.add(t)}))}catch(t){this.send(Nt(e,t))}if(w(r))return this.spawnPromise(r,e);var c={id:e,send:function(t){return a.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){o=!0,N(r)&&r()},toJSON:function(){return{id:e}},getSnapshot:function(){return n}};return this.children.set(e,c),c},n.prototype.spawnObservable=function(t,e){var n,r=this,i=t.subscribe((function(t){n=t,r.send(L(t,{origin:e}))}),(function(t){r.removeChild(e),r.send(L(Nt(e,t),{origin:e}))}),(function(){r.removeChild(e),r.send(L(Tt(e),{origin:e}))})),o={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return i.unsubscribe()},getSnapshot:function(){return n},toJSON:function(){return{id:e}}};return this.children.set(e,o),o},n.prototype.spawnActor=function(t,e){return this.children.set(e,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){var t=Ht();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Gt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[P]=function(){return this},n.prototype.getSnapshot=function(){return this.status===t.InterpreterStatus.NotStarted?this.initialState:this._state},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=Zt,n}();function Zt(t,e){return new Yt(t,e)}var te={raise:pt,send:vt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:et,label:e,expr:t}},cancel:St,start:xt,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return vt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,r){return yt((function(t,e,r){return{type:ot,data:N(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=Yt,t.Machine=function(t,e,n){return void 0===n&&(n=t.context),new Mt(t,e,n)},t.State=Pt,t.StateNode=Mt,t.actions=te,t.assign=bt,t.createMachine=function(t,e){return new Mt(t,e)},t.createSchema=function(t){return t},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Zt,t.mapState=function(t,e){var n,i,o;try{for(var a=r(s(t)),u=a.next();!u.done;u=a.next()){var h=u.value;c(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Pt.from(t,t instanceof Pt?t.context:void 0);try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var h=i(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=c,t.send=vt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,n){var r=function(t){return O(t)?e(e({},Wt),{name:t}):e(e(e({},Wt),{name:C()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Ct(t,r.name)}(kt[kt.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -1,4 +1,4 @@
1
- const t={};function e(t){return Object.keys(t)}function i(t,n,s="."){const r=o(t,s),a=o(n,s);return w(a)?!!w(r)&&a===r:w(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return w(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function s(t,e){try{return b(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function o(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(b(t))return r(t);if("string"!=typeof t)return t;return r(s(t,e))}function r(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function a(t,i){const n={},s=e(t);for(let e=0;e<s.length;e++){const o=s[e];n[o]=i(t[o],o,t,e)}return n}function c(t,i,n){const s={};for(const o of e(t)){const e=t[o];n(e)&&(s[o]=i(e,o,t))}return s}const h=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function u(t){if(!t)return[[]];if(w(t))return[[t]];return d(e(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?u(t[e]).map(t=>[e].concat(t)):[[e]]}))}function d(t){return[].concat(...t)}function l(t){return b(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(S(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];S(o)?n[s]=o(e,i.data):n[s]=o}return n}function g(t){return t instanceof Promise||!(null===t||!S(t)&&"object"!=typeof t||!S(t.then))}function v(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function y(t,e){return a(t.states,(t,i)=>{if(!t)return;const n=(w(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:y(t,n)}:void 0})}function m(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(S(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=S(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}function b(t){return Array.isArray(t)}function S(t){return"function"==typeof t}function w(t){return"string"==typeof t}function x(t,e){if(t)return w(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:S(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const _=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function O(t){try{return"__xstatenode"in t}catch(t){return!1}}const j=(()=>{let t=0;return()=>(t++,t.toString(16))})();function E(t,e){return w(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!w(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=E(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function T(t,e){return l(e).map(e=>void 0===e||"string"==typeof e||O(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function $(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function k(t){return"string"==typeof t?{type:t}:t}function C(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}function P(t,n){let s;for(const o of e(t))i(o,n)&&(!s||n.length>s.length)&&(s=o);return t[s]}
1
+ const t={};function e(t){return Object.keys(t)}function i(t,n,s="."){const r=o(t,s),a=o(n,s);return w(a)?!!w(r)&&a===r:w(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function n(t){try{return w(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function s(t,e){try{return b(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function o(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(b(t))return r(t);if("string"!=typeof t)return t;return r(s(t,e))}function r(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function a(t,i){const n={},s=e(t);for(let e=0;e<s.length;e++){const o=s[e];n[o]=i(t[o],o,t,e)}return n}function c(t,i,n){const s={};for(const o of e(t)){const e=t[o];n(e)&&(s[o]=i(e,o,t))}return s}const h=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function d(t){if(!t)return[[]];if(w(t))return[[t]];return u(e(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?d(t[e]).map(t=>[e].concat(t)):[[e]]}))}function u(t){return[].concat(...t)}function l(t){return b(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(S(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];S(o)?n[s]=o(e,i.data):n[s]=o}return n}function g(t){return t instanceof Promise||!(null===t||!S(t)&&"object"!=typeof t||!S(t.then))}function v(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function y(t,e){return a(t.states,(t,i)=>{if(!t)return;const n=(w(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:y(t,n)}:void 0})}function m(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(S(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=S(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}function b(t){return Array.isArray(t)}function S(t){return"function"==typeof t}function w(t){return"string"==typeof t}function x(t,e){if(t)return w(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:S(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const O=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function _(t){try{return"__xstatenode"in t}catch(t){return!1}}const j=(()=>{let t=0;return()=>(t++,t.toString(16))})();function E(t,e){return w(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!w(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=E(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function T(t,e){return l(e).map(e=>void 0===e||"string"==typeof e||_(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function $(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function k(t){return"string"==typeof t?{type:t}:t}function C(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}function P(t,n){let s;for(const o of e(t))i(o,n)&&(!s||n.length>s.length)&&(s=o);return t[s]}
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -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 V(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}var I,L;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(I||(I={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(L||(L={}));const A=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function R(t){const e=[t];return A(t)?e:e.concat(d(D(t).map(R)))}function M(t,e){const i=z(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=z(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function z(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function F(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(A(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,z(M([t],e)))}function B(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&B(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=I.Start,q=I.Stop,X=I.Raise,H=I.Send,G=I.Cancel,K=I.NullEvent,Q=I.Assign,W=(I.After,I.DoneState,I.Log),Y=I.Init,Z=I.Invoke,tt=(I.ErrorExecution,I.ErrorPlatform),et=I.ErrorCustom,it=I.Update,nt=I.Choose,st=I.Pure,ot=N({type:Y});function rt(t,e){return e&&e[t]||void 0}function at(t,e){let i;if(w(t)||"number"==typeof t){const n=rt(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=rt(t.type,e);if(S(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const ct=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>at(t,e))};function ht(t){const e=at(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function ut(t){return w(t)?{type:X,event:t}:dt(t,{to:L.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:H,event:S(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function lt(t,e){return dt(t,Object.assign(Object.assign({},e),{to:L.Parent}))}function ft(){return lt(it)}const pt=(t,e)=>({context:t,event:e});const gt=t=>({type:G,sendId:t});function vt(t){const e=ht(t);return{type:I.Start,activity:e,exec:void 0}}function yt(t){const e=S(t)?t:ht(t);return{type:I.Stop,activity:e,exec:void 0}}const mt=t=>({type:Q,assignment:t});function bt(t,e){const i=e?"#"+e:"";return`${I.After}(${t})${i}`}function St(t,e){const i=`${I.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function wt(t,e){const i=`${I.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){const i=`${I.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function _t(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Q);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[d(a.map(i=>{var s;switch(i.type){case X:return{type:X,_event:N(i.event)};case H:return function(t,e,i,n){const s={_event:i},o=N(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(i,c,n,t.options.delays);case W:return((t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(i,c,n);case nt:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||$(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,u]=Ot(t,e,c,n,ct(f(r),t.options.actions),o);return c=u,null==h||h.push(c),a}case st:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=Ot(t,e,c,n,ct(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case q:return function(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:I.Stop,activity:s}}(i,c,n);case Q:c=m(c,n,[i],e),null==h||h.push(c);break;default:const r=at(i,t.options.actions),{exec:a}=r;if(a&&h){const t=h.length-1;r.exec=(e,...i)=>{null==a||a(h[t],...i)}}return r}}).filter(t=>!!t)),c]}function jt(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Et{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(d([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Et)return t.context!==e?new Et({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Et({value:t,context:e,_event:ot,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Et(t)}static inert(t,e){if(t instanceof Et){if(!t.actions.length)return t;const i=ot;return new Et({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Et.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i}=this,n=V(this,["configuration","transitions","tags"]);return Object.assign(Object.assign({},n),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}}const Nt=[],Tt=(t,e)=>{Nt.push(t);const i=e(t);return Nt.pop(),i};function $t(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})}}function kt(t,e,i){const n=$t(e);if(n.deferred=!0,O(t)){const e=n.state=Tt(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function Ct(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Z},t),{toJSON(){const e=V(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Z,src:Ct(t.src)})}})}const Vt={},It=t=>"#"===t[0];class Lt{constructor(t,i,n=("context"in t?t.context:void 0)){var s;this.config=t,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new Lt(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Vt;let o=0;!function t(e){e.order=o++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>at(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>at(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(O(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(w(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(O(t.src)||S(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ht(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||R(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Lt(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 Lt(this.config,this.options,t)}get context(){return S(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=bt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(gt(i)),i};return(b(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):d(e(t).map((e,n)=>{const s=t[e],o=w(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof Et?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=n.map(t=>this.getStateNode(t));return s.push(this),s.concat(n.reduce((t,e)=>{const n=this.getStateNode(e).getStateNodes(i[e]);return t.concat(n)},[]))}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(M([],this.getStateNodes(t.value)));return new Et(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=d(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=d(o.map(t=>t.entrySet)),c=d(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:d(o.map(t=>t.exitSet)),configuration:c,source:i,actions:d(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:u,in:d}=c,l=t.context,f=!d||(w(d)&&It(d)?t.matches(o(this.getStateNodeById(d).path,this.delimiter)):i(o(d,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!u||$(this.machine,u,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${u.name||u.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=d(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),u=!!r.internal;return{transitions:[r],entrySet:u?[]:d(c.map(t=>this.nodesFromChild(t))),exitSet:u?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=M([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?M(s,t.configuration):s;for(const e of o)B(s,e)||t.entrySet.push(e);for(const e of s)B(o,e)&&!B(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=d(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(St(n.id,n.doneData),St(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&s.push(St(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]=[d(Array.from(a).map(t=>[...t.activities.map(t=>vt(t)),...t.onEntry])).concat(r.map(ut)),d(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>yt(t))]))];return ct(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=N(e);let s;if(t instanceof Et)s=void 0===i?t:this.resolveState(Et.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Et.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=M([],this.getStateNodes(s.value)),h=a.configuration.length?M(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=ot,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?F(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=i?i.context:s,u=this.getActions(t,h,n,i),l=i?Object.assign({},i.activities):{};for(const t of u)t.type===U?l[t.activity.id||t.activity.type]=t:t.type===q&&(l[t.activity.id||t.activity.type]=!1);const[f,g]=Ot(this,i,h,n,u,this.machine.config.preserveActionOrder),[m,b]=v(f,t=>t.type===X||t.type===H&&t.to===L.Internal),S=f.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Z}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?kt(r,t.id,a):$t(t.id);return c.meta=t,c}(e.activity,this.machine,g,n),t),i?Object.assign({},i.children):{}),x=a?t.configuration:i?i.configuration:[],_=J(x,this),O=new Et({value:a||i.value,context:g,_event:n,_sessionid:i?i._sessionid:null,historyValue:a?c?(j=c,E=a,{current:E,states:y(j,E)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?b:[],activities:a?l:i?i.activities:{},events:[],configuration:x,transitions:t.transitions,children:S,done:_,tags:null==i?void 0:i.tags});var j,E;const N=h!==g;O.changed=n.name===it||N;const{history:T}=O;T&&delete T.history;const $=!_&&(this._transient||o.some(t=>t._transient));if(!(r||$&&""!==n.name))return O;let C=O;if(!_)for($&&(C=this.resolveRaisedTransition(C,{type:K},n));m.length;){const t=m.shift();C=this.resolveRaisedTransition(C,t._event,n)}const P=C.changed||(T?!!C.actions.length||N||typeof T.value!=typeof C.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}(C.value,T.value):void 0);return C.changed=P,C.history=T,C.tags=new Set(d(C.configuration.map(t=>t.tags))),C}getStateNode(t){if(It(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);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=It(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&&It(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Vt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Vt);case"compound":if(w(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Vt):this.initialStateValue||{};default:return t||Vt}}getResolvedPath(t){if(It(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Vt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=A(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=w(e.target)&&It(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(A(this))return[this];if("compound"===this.type&&!this.initial)return[this];return d(u(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=w(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?d(u(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return w(i)?[e.getStateNode(i)]:d(u(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=d(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!w(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:ct(f(t.actions)),cond:x(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=V(i,[n+""]);t=d(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],n=this.config.onDone?T(String(St(this.id)),this.config.onDone):[],s=d(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(wt(t.id)),t.onDone)),t.onError&&e.push(...T(String(xt(t.id)),t.onError)),e})),o=this.after,r=d([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function At(t,e,i=t.context){return new Lt(t,e,i)}function Dt(t,e){return new Lt(t,e)}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 Bt={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ut(t){if(!Jt())return;const e=function(){const t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=C(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const 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,e=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(b(t))return this.batch(t),this.state;const i=N(E(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,e)=>{const i=this.parent&&(e===L.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||Bt.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===et?""+xt(this.id):t.name,origin:this.sessionId})):n.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Gt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Tt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(wt(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;Bt.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:Tt(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Et.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,ot)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Ht.Stopped,Bt.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=N(s);this.forward(t),e=Tt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>jt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(tt)&&!this.state.nextEvents.some(t=>0===t.indexOf(tt)))throw e.data.data;return Tt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:n,_event:s}=e,o=t.exec||rt(t.type,i),r=S(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case H:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case G:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===I.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;if("string"==typeof i)return;let h,u=S(i)?i(n,s.data,{data:c,src:t}):i;if(!u)return;O(u)&&(u=c?u.withContext(c):u,h={autoForward:a}),this.spawn(u,o,h)}else this.spawnActivity(e);break}case q:this.stopChild(t.activity.id);break;case W:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(O(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(it,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=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(N(wt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=xt(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=C(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(xt(e,t))}if(g(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(xt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(wt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Ut(this)}}toJSON(){return{id:this.id}}[_](){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=>w(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):kt(t,i.name))(Nt[Nt.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t,e,i){const n=Et.from(t,t instanceof Et?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function Yt(t){return t}const Zt={raise:ut,send:dt,sendParent:lt,sendUpdate:ft,log:function(t=pt,e){return{type:W,label:e,expr:t}},cancel:gt,start:vt,stop:yt,assign:mt,after:bt,done:St,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:_t,escalate:function(t,e){return lt((e,i,n)=>({type:et,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:L.Parent}))},choose:function(t){return{type:I.Choose,conds:t}},pure:function(t){return{type:I.Pure,get:t}}};export{I as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,At as Machine,L as SpecialTargets,Et as State,Lt as StateNode,Zt as actions,mt as assign,Dt as createMachine,Yt as createSchema,wt as doneInvoke,_t as forwardTo,Qt as interpret,P as mapState,Wt as matchState,i as matchesState,dt as send,lt as sendParent,ft as sendUpdate,Kt as spawn};
15
+ ***************************************************************************** */function V(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}var I,L;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(I||(I={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(L||(L={}));const A=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function R(t){const e=[t];return A(t)?e:e.concat(u(D(t).map(R)))}function M(t,e){const i=z(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=z(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function z(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function F(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(A(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,z(M([t],e)))}function B(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&B(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=I.Start,q=I.Stop,X=I.Raise,H=I.Send,G=I.Cancel,K=I.NullEvent,Q=I.Assign,W=(I.After,I.DoneState,I.Log),Y=I.Init,Z=I.Invoke,tt=(I.ErrorExecution,I.ErrorPlatform),et=I.ErrorCustom,it=I.Update,nt=I.Choose,st=I.Pure,ot=N({type:Y});function rt(t,e){return e&&e[t]||void 0}function at(t,e){let i;if(w(t)||"number"==typeof t){const n=rt(t,e);i=S(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(S(t))i={type:t.name||t.toString(),exec:t};else{const n=rt(t.type,e);if(S(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const ct=(t,e)=>{if(!t)return[];return(b(t)?t:[t]).map(t=>at(t,e))};function ht(t){const e=at(t);return Object.assign(Object.assign({id:w(t)?t:e.id},e),{type:e.type})}function dt(t){return w(t)?{type:X,event:t}:ut(t,{to:L.Internal})}function ut(t,e){return{to:e?e.to:void 0,type:H,event:S(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:S(t)?t.name:n(t)}}function lt(t,e){return ut(t,Object.assign(Object.assign({},e),{to:L.Parent}))}function ft(){return lt(it)}const pt=(t,e)=>({context:t,event:e});const gt=t=>({type:G,sendId:t});function vt(t){const e=ht(t);return{type:I.Start,activity:e,exec:void 0}}function yt(t){const e=S(t)?t:ht(t);return{type:I.Stop,activity:e,exec:void 0}}const mt=t=>({type:Q,assignment:t});function bt(t,e){const i=e?"#"+e:"";return`${I.After}(${t})${i}`}function St(t,e){const i=`${I.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function wt(t,e){const i=`${I.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){const i=`${I.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function Ot(t,e){return ut((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function _t(t,e,i,n,s,o=!1){const[r,a]=o?[[],s]:v(s,t=>t.type===Q);let c=r.length?m(i,n,r,e):i;const h=o?[i]:void 0;return[u(a.map(i=>{var s;switch(i.type){case X:return{type:X,_event:N(i.event)};case H:return function(t,e,i,n){const s={_event:i},o=N(S(t.event)?t.event(e,i.data,s):t.event);let r;if(w(t.delay)){const o=n&&n[t.delay];r=S(o)?o(e,i.data,s):o}else r=S(t.delay)?t.delay(e,i.data,s):t.delay;const a=S(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(i,c,n,t.options.delays);case W:return((t,e,i)=>Object.assign(Object.assign({},t),{value:w(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(i,c,n);case nt:{const r=null===(s=i.conds.find(i=>{const s=x(i.cond,t.options.guards);return!s||$(t,s,c,n,e)}))||void 0===s?void 0:s.actions;if(!r)return[];const[a,d]=_t(t,e,c,n,ct(f(r),t.options.actions),o);return c=d,null==h||h.push(c),a}case st:{const s=i.get(c,n.data);if(!s)return[];const[r,a]=_t(t,e,c,n,ct(f(s),t.options.actions),o);return c=a,null==h||h.push(c),r}case q:return function(t,e,i){const n=S(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:I.Stop,activity:s}}(i,c,n);case Q:c=m(c,n,[i],e),null==h||h.push(c);break;default:let r=at(i,t.options.actions);const{exec:a}=r;if(a&&h){const t=h.length-1;r=Object.assign(Object.assign({},r),{exec:(e,...i)=>{a(h[t],...i)}})}return r}}).filter(t=>!!t)),c]}function jt(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Et{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=Array.isArray(e.tags)?new Set(e.tags):e.tags)&&void 0!==i?i:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(u([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Et)return t.context!==e?new Et({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Et({value:t,context:e,_event:ot,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Et(t)}static inert(t,e){if(t instanceof Et){if(!t.actions.length)return t;const i=ot;return new Et({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Et.from(t,e)}toStrings(t=this.value,i="."){if(w(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=V(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;return this.machine,!!(null===(e=this.machine)||void 0===e?void 0:e.transition(this,t).changed)}}const Nt=[],Tt=(t,e)=>{Nt.push(t);const i=e(t);return Nt.pop(),i};function $t(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t})}}function kt(t,e,i){const n=$t(e);if(n.deferred=!0,_(t)){const e=n.state=Tt(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function Ct(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Z},t),{toJSON(){const e=V(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Z,src:Ct(t.src)})}})}const Vt={},It=t=>"#"===t[0];class Lt{constructor(t,i,n=("context"in t?t.context:void 0)){var s;this.config=t,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new Lt(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Vt;let o=0;!function t(e){e.order=o++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>at(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>at(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(w(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||S(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ht(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||R(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new Lt(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 Lt(this.config,this.options,t)}get context(){return S(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=bt(S(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ut(i,{delay:t})),this.onExit.push(gt(i)),i};return(b(t)?t.map((t,e)=>{const n=i(t.delay,e);return Object.assign(Object.assign({},t),{event:n})}):u(e(t).map((e,n)=>{const s=t[e],o=w(s)?{target:s}:s,r=isNaN(+e)?e:+e,a=i(r,n);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof Et?t.value:o(t,this.delimiter);if(w(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this,this.states[i]]}const n=e(i),s=n.map(t=>this.getStateNode(t));return s.push(this),s.concat(n.reduce((t,e)=>{const n=this.getStateNode(e).getStateNodes(i[e]);return t.concat(n)},[]))}handles(t){const e=n(t);return this.events.includes(e)}resolveState(t){const e=Array.from(M([],this.getStateNodes(t.value)));return new Et(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,i,n){const s=e(t),o=this.getStateNode(s[0])._transition(t[s[0]],i,n);return o&&o.transitions.length?o:this.next(i,n)}transitionParallelNode(t,i,n){const s={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,n);r&&(s[o]=r)}const o=e(s).map(t=>s[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,n);const a=u(o.map(t=>t.entrySet)),c=u(e(s).map(t=>s[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(s).map(t=>s[t].actions))}}_transition(t,i,n){return w(t)?this.transitionLeafNode(t,i,n):1===e(t).length?this.transitionCompoundNode(t,i,n):this.transitionParallelNode(t,i,n)}next(t,e){const n=e.name,s=[];let r,a=[];for(const c of this.getCandidates(n)){const{cond:d,in:u}=c,l=t.context,f=!u||(w(u)&&It(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${n}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),s.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:s};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:s}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,n){const s=M([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?M(s,t.configuration):s;for(const e of o)B(s,e)||t.entrySet.push(e);for(const e of s)B(o,e)&&!B(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(St(n.id,n.doneData),St(o.id,n.doneData?p(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&s.push(St(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>vt(t)),...t.onEntry])).concat(r.map(dt)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>yt(t))]))];return ct(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=N(e);let s;if(t instanceof Et)s=void 0===i?t:this.resolveState(Et.from(t,i));else{const e=w(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Et.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const a=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},c=M([],this.getStateNodes(s.value)),h=a.configuration.length?M(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,s,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,i,n=ot,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0,a=r?F(this.machine,o):void 0,c=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,h=i?i.context:s,d=this.getActions(t,h,n,i),l=i?Object.assign({},i.activities):{};for(const t of d)t.type===U?l[t.activity.id||t.activity.type]=t:t.type===q&&(l[t.activity.id||t.activity.type]=!1);const[f,g]=_t(this,i,h,n,d,this.machine.config.preserveActionOrder),[m,b]=v(f,t=>t.type===X||t.type===H&&t.to===L.Internal),S=f.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Z}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=k(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?p(t.data,i,n):void 0,c=r?kt(r,t.id,a):$t(t.id);return c.meta=t,c}(e.activity,this.machine,g,n),t),i?Object.assign({},i.children):{}),x=a?t.configuration:i?i.configuration:[],O=J(x,this),_=new Et({value:a||i.value,context:g,_event:n,_sessionid:i?i._sessionid:null,historyValue:a?c?(j=c,E=a,{current:E,states:y(j,E)}):void 0:i?i.historyValue:void 0,history:!a||t.source?i:void 0,actions:a?b:[],activities:a?l:i?i.activities:{},events:[],configuration:x,transitions:t.transitions,children:S,done:O,tags:null==i?void 0:i.tags,machine:this});var j,E;const N=h!==g;_.changed=n.name===it||N;const{history:T}=_;T&&delete T.history;const $=!O&&(this._transient||o.some(t=>t._transient));if(!(r||$&&""!==n.name))return _;let C=_;if(!O)for($&&(C=this.resolveRaisedTransition(C,{type:K},n));m.length;){const t=m.shift();C=this.resolveRaisedTransition(C,t._event,n)}const P=C.changed||(T?!!C.actions.length||N||typeof T.value!=typeof C.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(w(i)||w(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}(C.value,T.value):void 0);return C.changed=P,C.history=T,C.tags=new Set(u(C.configuration.map(t=>t.tags))),C}getStateNode(t){if(It(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);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=It(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&&It(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=s(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Vt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Vt);case"compound":if(w(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Vt):this.initialStateValue||{};default:return t||Vt}}getResolvedPath(t){if(It(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return s(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Vt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=A(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=w(e.target)&&It(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(A(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const n=w(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return w(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const n of e(t)){const e=t[n];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!w(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>w(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:ct(f(t.actions)),cond:x(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,n="*",s=i[n],o=void 0===s?[]:s,r=V(i,[n+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],n=this.config.onDone?T(String(St(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(wt(t.id)),t.onDone)),t.onError&&e.push(...T(String(xt(t.id)),t.onError)),e})),o=this.after,r=u([...n,...s,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function At(t,e,i=t.context){return new Lt(t,e,i)}function Dt(t,e){return new Lt(t,e)}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 Bt={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ut(t){if(!Jt())return;const e=function(){const t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=(a={id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,c),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=C(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}},Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{}},a));var a;const c={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(c):i,r}const 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,e=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(b(t))return this.batch(t),this.state;const i=N(E(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,e)=>{const i=this.parent&&(e===L.Parent||this.parent.id===e),n=i?this.parent:w(e)?this.children.get(e)||Bt.get(e):(s=e)&&"function"==typeof s.send?e:void 0;var s;if(n)"machine"in n?n.send(Object.assign(Object.assign({},t),{name:t.name===et?""+xt(this.id):t.name,origin:this.sessionId})):n.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Gt.defaultOptions),e),{clock:n,logger:s,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=s,this.clock=n,this.parent=o,this.options=i,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Tt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(wt(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;Bt.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:Tt(this,()=>{return!w(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Et.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,ot)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{S(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Ht.Stopped,Bt.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=N(s);this.forward(t),e=Tt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>jt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(tt)&&!this.state.nextEvents.some(t=>0===t.indexOf(tt)))throw e.data.data;return Tt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:n,_event:s}=e,o=t.exec||rt(t.type,i),r=S(o)?o:o?o.exec:t.exec;if(r)try{return r(n,s.data,{action:t,state:this.state,_event:s})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case H:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case G:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===I.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,n,s):void 0;if("string"==typeof i)return;let h,d=S(i)?i(n,s.data,{data:c,src:t}):i;if(!d)return;_(d)&&(d=c?d.withContext(c):d,h={autoForward:a}),this.spawn(d,o,h)}else this.spawnActivity(e);break}case q:this.stopChild(t.activity.id);break;case W:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),S(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(S(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&S(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new 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(it,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=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(N(wt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=xt(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=C(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(xt(e,t))}if(g(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,S(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(xt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(wt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Ut(this)}}toJSON(){return{id:this.id}}[O](){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=>w(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):kt(t,i.name))(Nt[Nt.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t,e,i){const n=Et.from(t,t instanceof Et?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function Yt(t){return t}const Zt={raise:dt,send:ut,sendParent:lt,sendUpdate:ft,log:function(t=pt,e){return{type:W,label:e,expr:t}},cancel:gt,start:vt,stop:yt,assign:mt,after:bt,done:St,respond:function(t,e){return ut(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:Ot,escalate:function(t,e){return lt((e,i,n)=>({type:et,data:S(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:L.Parent}))},choose:function(t){return{type:I.Choose,conds:t}},pure:function(t){return{type:I.Pure,get:t}}};export{I as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,At as Machine,L as SpecialTargets,Et as State,Lt as StateNode,Zt as actions,mt as assign,Dt as createMachine,Yt as createSchema,wt as doneInvoke,Ot as forwardTo,Qt as interpret,P as mapState,Wt as matchState,i as matchesState,ut as send,lt as sendParent,ft as sendUpdate,Kt as spawn};
package/es/Machine.d.ts CHANGED
@@ -1,18 +1,12 @@
1
- import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate, EventFrom, BaseActionObject } from './types';
2
- import { Model, ModelContextFrom, ModelActionsFrom } from './model.types';
1
+ import { Model } from './model.types';
2
+ import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
3
3
  /**
4
4
  * @deprecated Use `createMachine(...)` instead.
5
5
  */
6
6
  export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
7
7
  export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
8
- export declare function createMachine<TModel extends Model<any, any, any, any>, TContext = ModelContextFrom<TModel>, TEvent extends EventObject = EventFrom<TModel>, TTypestate extends Typestate<TContext> = {
9
- value: any;
10
- context: TContext;
11
- }, TAction extends BaseActionObject = ModelActionsFrom<TModel>>(config: MachineConfig<TContext, any, TEvent, TAction> & {
12
- context: TContext;
13
- }, options?: Partial<MachineOptions<TContext, TEvent, TAction>>): StateMachine<TContext, any, TEvent, TTypestate>;
14
8
  export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
15
9
  value: any;
16
10
  context: TContext;
17
- }>(config: TContext extends Model<any, any, any, any> ? never : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
11
+ }>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
18
12
  //# sourceMappingURL=Machine.d.ts.map
package/es/State.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef } from './types';
1
+ import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
2
2
  import { StateNode } from './StateNode';
3
3
  export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
4
4
  export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
@@ -51,6 +51,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
51
51
  */
52
52
  children: Record<string, ActorRef<any>>;
53
53
  tags: Set<string>;
54
+ machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
54
55
  /**
55
56
  * Creates a new State instance for the given `stateValue` and `context`.
56
57
  * @param stateValue
@@ -87,7 +88,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
87
88
  * @param delimiter The character(s) that separate each subpath in the string state node path.
88
89
  */
89
90
  toStrings(stateValue?: StateValue, delimiter?: string): string[];
90
- toJSON(): Omit<this, "configuration" | "transitions" | "tags"> & {
91
+ toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine"> & {
91
92
  tags: string[];
92
93
  };
93
94
  /**
@@ -105,5 +106,11 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
105
106
  * @param tag
106
107
  */
107
108
  hasTag(tag: string): boolean;
109
+ /**
110
+ * Determines whether sending the `event` will cause a transition.
111
+ * @param event The event to test
112
+ * @returns Whether the event will cause a transition
113
+ */
114
+ can(event: TEvent | SimpleEventsOf<TEvent>['type']): boolean;
108
115
  }
109
116
  //# sourceMappingURL=State.d.ts.map
package/es/State.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { __spreadArray, __read, __rest, __assign } from './_virtual/_tslib.js';
2
2
  import { EMPTY_ACTIVITY_MAP } from './constants.js';
3
- import { isString, matchesState, keys } from './utils.js';
3
+ import { IS_PRODUCTION } from './environment.js';
4
+ import { isString, matchesState, warn, keys } from './utils.js';
4
5
  import { getMeta, nextEvents } from './stateUtils.js';
5
6
  import { initEvent } from './actions.js';
6
7
 
@@ -90,6 +91,7 @@ function () {
90
91
  this.children = config.children;
91
92
  this.done = !!config.done;
92
93
  this.tags = (_a = Array.isArray(config.tags) ? new Set(config.tags) : config.tags) !== null && _a !== void 0 ? _a : new Set();
94
+ this.machine = config.machine;
93
95
  Object.defineProperty(this, 'nextEvents', {
94
96
  get: function () {
95
97
  return nextEvents(_this.configuration);
@@ -217,7 +219,8 @@ function () {
217
219
  configuration = _a.configuration,
218
220
  transitions = _a.transitions,
219
221
  tags = _a.tags,
220
- jsonValues = __rest(_a, ["configuration", "transitions", "tags"]);
222
+ machine = _a.machine,
223
+ jsonValues = __rest(_a, ["configuration", "transitions", "tags", "machine"]);
221
224
 
222
225
  return __assign(__assign({}, jsonValues), {
223
226
  tags: Array.from(tags)
@@ -241,6 +244,22 @@ function () {
241
244
  State.prototype.hasTag = function (tag) {
242
245
  return this.tags.has(tag);
243
246
  };
247
+ /**
248
+ * Determines whether sending the `event` will cause a transition.
249
+ * @param event The event to test
250
+ * @returns Whether the event will cause a transition
251
+ */
252
+
253
+
254
+ State.prototype.can = function (event) {
255
+ var _a;
256
+
257
+ if (IS_PRODUCTION) {
258
+ warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
259
+ }
260
+
261
+ return !!((_a = this.machine) === null || _a === void 0 ? void 0 : _a.transition(this, event).changed);
262
+ };
244
263
 
245
264
  return State;
246
265
  }();
package/es/StateNode.js CHANGED
@@ -924,7 +924,8 @@ function () {
924
924
  transitions: stateTransition.transitions,
925
925
  children: children,
926
926
  done: isDone,
927
- tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
927
+ tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
928
+ machine: this
928
929
  });
929
930
  var didUpdateContext = currentContext !== updatedContext;
930
931
  nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
package/es/actions.js CHANGED
@@ -477,16 +477,17 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
477
477
 
478
478
  if (exec_1 && preservedContexts) {
479
479
  var contextIndex_1 = preservedContexts.length - 1;
480
+ resolvedActionObject = __assign(__assign({}, resolvedActionObject), {
481
+ exec: function (_ctx) {
482
+ var args = [];
480
483
 
481
- resolvedActionObject.exec = function (_ctx) {
482
- var args = [];
484
+ for (var _i = 1; _i < arguments.length; _i++) {
485
+ args[_i - 1] = arguments[_i];
486
+ }
483
487
 
484
- for (var _i = 1; _i < arguments.length; _i++) {
485
- args[_i - 1] = arguments[_i];
488
+ exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args)));
486
489
  }
487
-
488
- exec_1 === null || exec_1 === void 0 ? void 0 : exec_1.apply(void 0, __spreadArray([preservedContexts[contextIndex_1]], __read(args)));
489
- };
490
+ });
490
491
  }
491
492
 
492
493
  return resolvedActionObject;
package/es/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { EventObject, BaseActionObject } from './types';
2
- import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
2
+ import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
3
3
  export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
- export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = 'events' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['events']> : never, TComputedAction = 'actions' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['actions']> : never>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
4
+ export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
5
  //# sourceMappingURL=model.d.ts.map
package/es/types.d.ts CHANGED
@@ -2,6 +2,8 @@ import { StateNode } from './StateNode';
2
2
  import { State } from './State';
3
3
  import { Interpreter, Clock } from './interpreter';
4
4
  import { Model } from './model.types';
5
+ declare type AnyFunction = (...args: any[]) => any;
6
+ declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
5
7
  export declare type EventType = string;
6
8
  export declare type ActionType = string;
7
9
  export declare type MetaObject = Record<string, any>;
@@ -60,8 +62,12 @@ export declare type Action<TContext, TEvent extends EventObject> = ActionType |
60
62
  /**
61
63
  * Extracts action objects that have no extra properties.
62
64
  */
63
- declare type SimpleActionsFrom<T extends BaseActionObject> = ActionObject<any, any> extends T ? T : ExtractWithSimpleSupport<T>;
64
- export declare type BaseAction<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SimpleActionsFrom<TAction>['type'] | TAction | RaiseAction<any> | SendAction<TContext, TEvent, any> | AssignAction<TContext, TEvent> | LogAction<TContext, TEvent> | CancelAction | StopAction<TContext, TEvent> | ChooseAction<TContext, TEvent> | ActionFunction<TContext, TEvent>;
65
+ declare type SimpleActionsOf<T extends BaseActionObject> = ActionObject<any, any> extends T ? T : ExtractWithSimpleSupport<T>;
66
+ /**
67
+ * Events that do not require payload
68
+ */
69
+ export declare type SimpleEventsOf<TEvent extends EventObject> = ExtractWithSimpleSupport<TEvent>;
70
+ export declare type BaseAction<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SimpleActionsOf<TAction>['type'] | TAction | RaiseAction<any> | SendAction<TContext, TEvent, any> | AssignAction<TContext, TEvent> | LogAction<TContext, TEvent> | CancelAction | StopAction<TContext, TEvent> | ChooseAction<TContext, TEvent> | ActionFunction<TContext, TEvent>;
65
71
  export declare type BaseActions<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SingleOrArray<BaseAction<TContext, TEvent, TAction>>;
66
72
  export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
67
73
  export declare type StateKey = string | State<any>;
@@ -797,6 +803,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
797
803
  children: Record<string, ActorRef<any>>;
798
804
  done?: boolean;
799
805
  tags?: Set<string>;
806
+ machine?: StateMachine<TContext, any, TEvent, any>;
800
807
  }
801
808
  export interface StateSchema<TC = any> {
802
809
  meta?: any;
@@ -945,8 +952,8 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
945
952
  initialState: TEmitted;
946
953
  start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
947
954
  }
948
- export declare type EmittedFrom<T> = T extends ActorRef<any, infer TEmitted> ? TEmitted : T extends (...args: any[]) => ActorRef<any, infer TEmitted> ? TEmitted : T extends Behavior<any, infer TEmitted> ? TEmitted : T extends (...args: any[]) => Behavior<any, infer TEmitted> ? TEmitted : T extends ActorContext<any, infer TEmitted> ? TEmitted : T extends (...args: any[]) => ActorContext<any, infer TEmitted> ? TEmitted : never;
949
- export declare type EventFrom<T> = T extends StateMachine<any, any, infer TEvent, any> ? TEvent : T extends (...args: any[]) => StateMachine<any, any, infer TEvent, any> ? TEvent : T extends Model<any, infer TEvent, any, any> ? TEvent : T extends (...args: any[]) => Model<any, infer TEvent, any, any> ? TEvent : T extends State<any, infer TEvent, any, any> ? TEvent : T extends (...args: any[]) => State<any, infer TEvent, any, any> ? TEvent : T extends Interpreter<any, any, infer TEvent, any> ? TEvent : T extends (...args: any[]) => Interpreter<any, infer TEvent, any, any> ? TEvent : never;
950
- export declare type ContextFrom<T> = T extends StateMachine<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => StateMachine<infer TContext, any, any, any> ? TContext : T extends Model<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => Model<infer TContext, any, any, any> ? TContext : T extends State<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => State<infer TContext, any, any, any> ? TContext : T extends Interpreter<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => Interpreter<infer TContext, any, any, any> ? TContext : never;
955
+ export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
956
+ export declare type EventFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : never : never;
957
+ export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
951
958
  export {};
952
959
  //# sourceMappingURL=types.d.ts.map
package/lib/Machine.d.ts CHANGED
@@ -1,18 +1,12 @@
1
- import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate, EventFrom, BaseActionObject } from './types';
2
- import { Model, ModelContextFrom, ModelActionsFrom } from './model.types';
1
+ import { Model } from './model.types';
2
+ import { AnyEventObject, DefaultContext, EventObject, MachineConfig, MachineOptions, StateMachine, StateSchema, Typestate } from './types';
3
3
  /**
4
4
  * @deprecated Use `createMachine(...)` instead.
5
5
  */
6
6
  export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
7
7
  export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
8
- export declare function createMachine<TModel extends Model<any, any, any, any>, TContext = ModelContextFrom<TModel>, TEvent extends EventObject = EventFrom<TModel>, TTypestate extends Typestate<TContext> = {
9
- value: any;
10
- context: TContext;
11
- }, TAction extends BaseActionObject = ModelActionsFrom<TModel>>(config: MachineConfig<TContext, any, TEvent, TAction> & {
12
- context: TContext;
13
- }, options?: Partial<MachineOptions<TContext, TEvent, TAction>>): StateMachine<TContext, any, TEvent, TTypestate>;
14
8
  export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
15
9
  value: any;
16
10
  context: TContext;
17
- }>(config: TContext extends Model<any, any, any, any> ? never : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
11
+ }>(config: TContext extends Model<any, any, any, any> ? 'Model type no longer supported as generic type. Please use `model.createMachine(...)` instead.' : MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
18
12
  //# sourceMappingURL=Machine.d.ts.map
package/lib/State.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef } from './types';
1
+ import { StateValue, ActivityMap, EventObject, HistoryValue, ActionObject, EventType, StateConfig, SCXML, StateSchema, TransitionDefinition, Typestate, ActorRef, StateMachine, SimpleEventsOf } from './types';
2
2
  import { StateNode } from './StateNode';
3
3
  export declare function stateValuesEqual(a: StateValue | undefined, b: StateValue | undefined): boolean;
4
4
  export declare function isState<TContext, TEvent extends EventObject, TStateSchema extends StateSchema<TContext> = any, TTypestate extends Typestate<TContext> = {
@@ -51,6 +51,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
51
51
  */
52
52
  children: Record<string, ActorRef<any>>;
53
53
  tags: Set<string>;
54
+ machine: StateMachine<TContext, any, TEvent, TTypestate> | undefined;
54
55
  /**
55
56
  * Creates a new State instance for the given `stateValue` and `context`.
56
57
  * @param stateValue
@@ -87,7 +88,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
87
88
  * @param delimiter The character(s) that separate each subpath in the string state node path.
88
89
  */
89
90
  toStrings(stateValue?: StateValue, delimiter?: string): string[];
90
- toJSON(): Omit<this, "configuration" | "transitions" | "tags"> & {
91
+ toJSON(): Omit<this, "configuration" | "transitions" | "tags" | "machine"> & {
91
92
  tags: string[];
92
93
  };
93
94
  /**
@@ -105,5 +106,11 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
105
106
  * @param tag
106
107
  */
107
108
  hasTag(tag: string): boolean;
109
+ /**
110
+ * Determines whether sending the `event` will cause a transition.
111
+ * @param event The event to test
112
+ * @returns Whether the event will cause a transition
113
+ */
114
+ can(event: TEvent | SimpleEventsOf<TEvent>['type']): boolean;
108
115
  }
109
116
  //# sourceMappingURL=State.d.ts.map
package/lib/State.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('./_virtual/_tslib.js');
6
6
  var constants = require('./constants.js');
7
+ var environment = require('./environment.js');
7
8
  var utils = require('./utils.js');
8
9
  var stateUtils = require('./stateUtils.js');
9
10
  var actions = require('./actions.js');
@@ -94,6 +95,7 @@ function () {
94
95
  this.children = config.children;
95
96
  this.done = !!config.done;
96
97
  this.tags = (_a = Array.isArray(config.tags) ? new Set(config.tags) : config.tags) !== null && _a !== void 0 ? _a : new Set();
98
+ this.machine = config.machine;
97
99
  Object.defineProperty(this, 'nextEvents', {
98
100
  get: function () {
99
101
  return stateUtils.nextEvents(_this.configuration);
@@ -221,7 +223,8 @@ function () {
221
223
  configuration = _a.configuration,
222
224
  transitions = _a.transitions,
223
225
  tags = _a.tags,
224
- jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags"]);
226
+ machine = _a.machine,
227
+ jsonValues = _tslib.__rest(_a, ["configuration", "transitions", "tags", "machine"]);
225
228
 
226
229
  return _tslib.__assign(_tslib.__assign({}, jsonValues), {
227
230
  tags: Array.from(tags)
@@ -245,6 +248,22 @@ function () {
245
248
  State.prototype.hasTag = function (tag) {
246
249
  return this.tags.has(tag);
247
250
  };
251
+ /**
252
+ * Determines whether sending the `event` will cause a transition.
253
+ * @param event The event to test
254
+ * @returns Whether the event will cause a transition
255
+ */
256
+
257
+
258
+ State.prototype.can = function (event) {
259
+ var _a;
260
+
261
+ if (environment.IS_PRODUCTION) {
262
+ utils.warn(!!this.machine, "state.can(...) used outside of a machine-created State object; this will always return false.");
263
+ }
264
+
265
+ return !!((_a = this.machine) === null || _a === void 0 ? void 0 : _a.transition(this, event).changed);
266
+ };
248
267
 
249
268
  return State;
250
269
  }();
package/lib/StateNode.js CHANGED
@@ -928,7 +928,8 @@ function () {
928
928
  transitions: stateTransition.transitions,
929
929
  children: children,
930
930
  done: isDone,
931
- tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
931
+ tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags,
932
+ machine: this
932
933
  });
933
934
  var didUpdateContext = currentContext !== updatedContext;
934
935
  nextState.changed = _event.name === actionTypes.update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
package/lib/actions.js CHANGED
@@ -481,16 +481,17 @@ function resolveActions(machine, currentState, currentContext, _event, actions,
481
481
 
482
482
  if (exec_1 && preservedContexts) {
483
483
  var contextIndex_1 = preservedContexts.length - 1;
484
+ resolvedActionObject = _tslib.__assign(_tslib.__assign({}, resolvedActionObject), {
485
+ exec: function (_ctx) {
486
+ var args = [];
484
487
 
485
- resolvedActionObject.exec = function (_ctx) {
486
- var args = [];
488
+ for (var _i = 1; _i < arguments.length; _i++) {
489
+ args[_i - 1] = arguments[_i];
490
+ }
487
491
 
488
- for (var _i = 1; _i < arguments.length; _i++) {
489
- args[_i - 1] = arguments[_i];
492
+ exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args)));
490
493
  }
491
-
492
- exec_1 === null || exec_1 === void 0 ? void 0 : exec_1.apply(void 0, _tslib.__spreadArray([preservedContexts[contextIndex_1]], _tslib.__read(args)));
493
- };
494
+ });
494
495
  }
495
496
 
496
497
  return resolvedActionObject;
package/lib/model.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { EventObject, BaseActionObject } from './types';
2
- import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
2
+ import { Cast, UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators, Prop, IsNever } from './model.types';
3
3
  export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
- export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = 'events' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['events']> : never, TComputedAction = 'actions' extends keyof TFinalModelCreators ? UnionFromCreatorsReturnTypes<TFinalModelCreators['actions']> : never>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
4
+ export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
5
  //# sourceMappingURL=model.d.ts.map
package/lib/types.d.ts CHANGED
@@ -2,6 +2,8 @@ import { StateNode } from './StateNode';
2
2
  import { State } from './State';
3
3
  import { Interpreter, Clock } from './interpreter';
4
4
  import { Model } from './model.types';
5
+ declare type AnyFunction = (...args: any[]) => any;
6
+ declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
5
7
  export declare type EventType = string;
6
8
  export declare type ActionType = string;
7
9
  export declare type MetaObject = Record<string, any>;
@@ -60,8 +62,12 @@ export declare type Action<TContext, TEvent extends EventObject> = ActionType |
60
62
  /**
61
63
  * Extracts action objects that have no extra properties.
62
64
  */
63
- declare type SimpleActionsFrom<T extends BaseActionObject> = ActionObject<any, any> extends T ? T : ExtractWithSimpleSupport<T>;
64
- export declare type BaseAction<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SimpleActionsFrom<TAction>['type'] | TAction | RaiseAction<any> | SendAction<TContext, TEvent, any> | AssignAction<TContext, TEvent> | LogAction<TContext, TEvent> | CancelAction | StopAction<TContext, TEvent> | ChooseAction<TContext, TEvent> | ActionFunction<TContext, TEvent>;
65
+ declare type SimpleActionsOf<T extends BaseActionObject> = ActionObject<any, any> extends T ? T : ExtractWithSimpleSupport<T>;
66
+ /**
67
+ * Events that do not require payload
68
+ */
69
+ export declare type SimpleEventsOf<TEvent extends EventObject> = ExtractWithSimpleSupport<TEvent>;
70
+ export declare type BaseAction<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SimpleActionsOf<TAction>['type'] | TAction | RaiseAction<any> | SendAction<TContext, TEvent, any> | AssignAction<TContext, TEvent> | LogAction<TContext, TEvent> | CancelAction | StopAction<TContext, TEvent> | ChooseAction<TContext, TEvent> | ActionFunction<TContext, TEvent>;
65
71
  export declare type BaseActions<TContext, TEvent extends EventObject, TAction extends BaseActionObject> = SingleOrArray<BaseAction<TContext, TEvent, TAction>>;
66
72
  export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
67
73
  export declare type StateKey = string | State<any>;
@@ -797,6 +803,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
797
803
  children: Record<string, ActorRef<any>>;
798
804
  done?: boolean;
799
805
  tags?: Set<string>;
806
+ machine?: StateMachine<TContext, any, TEvent, any>;
800
807
  }
801
808
  export interface StateSchema<TC = any> {
802
809
  meta?: any;
@@ -945,8 +952,8 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
945
952
  initialState: TEmitted;
946
953
  start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
947
954
  }
948
- export declare type EmittedFrom<T> = T extends ActorRef<any, infer TEmitted> ? TEmitted : T extends (...args: any[]) => ActorRef<any, infer TEmitted> ? TEmitted : T extends Behavior<any, infer TEmitted> ? TEmitted : T extends (...args: any[]) => Behavior<any, infer TEmitted> ? TEmitted : T extends ActorContext<any, infer TEmitted> ? TEmitted : T extends (...args: any[]) => ActorContext<any, infer TEmitted> ? TEmitted : never;
949
- export declare type EventFrom<T> = T extends StateMachine<any, any, infer TEvent, any> ? TEvent : T extends (...args: any[]) => StateMachine<any, any, infer TEvent, any> ? TEvent : T extends Model<any, infer TEvent, any, any> ? TEvent : T extends (...args: any[]) => Model<any, infer TEvent, any, any> ? TEvent : T extends State<any, infer TEvent, any, any> ? TEvent : T extends (...args: any[]) => State<any, infer TEvent, any, any> ? TEvent : T extends Interpreter<any, any, infer TEvent, any> ? TEvent : T extends (...args: any[]) => Interpreter<any, infer TEvent, any, any> ? TEvent : never;
950
- export declare type ContextFrom<T> = T extends StateMachine<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => StateMachine<infer TContext, any, any, any> ? TContext : T extends Model<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => Model<infer TContext, any, any, any> ? TContext : T extends State<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => State<infer TContext, any, any, any> ? TContext : T extends Interpreter<infer TContext, any, any, any> ? TContext : T extends (...args: any[]) => Interpreter<infer TContext, any, any, any> ? TContext : never;
955
+ export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
956
+ export declare type EventFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : never : never;
957
+ export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
951
958
  export {};
952
959
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.23.3",
3
+ "version": "4.25.0",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",